1 From: Felix Fietkau <nbd@nbd.name>
2 Date: Wed, 5 Jun 2024 10:49:22 +0200
3 Subject: [PATCH] wifi: mac80211: move code in
4 ieee80211_link_reserve_chanctx to a helper
6 Reduces indentation in preparation for further changes
8 Signed-off-by: Felix Fietkau <nbd@nbd.name>
11 --- a/net/mac80211/chan.c
12 +++ b/net/mac80211/chan.c
13 @@ -1033,6 +1033,71 @@ int ieee80211_link_unreserve_chanctx(str
17 +static struct ieee80211_chanctx *
18 +ieee80211_replace_chanctx(struct ieee80211_local *local,
19 + const struct ieee80211_chan_req *chanreq,
20 + enum ieee80211_chanctx_mode mode,
21 + struct ieee80211_chanctx *curr_ctx)
23 + struct ieee80211_chanctx *new_ctx, *ctx;
25 + if (!curr_ctx || (curr_ctx->replace_state ==
26 + IEEE80211_CHANCTX_WILL_BE_REPLACED) ||
27 + !list_empty(&curr_ctx->reserved_links)) {
29 + * Another link already requested this context for a
30 + * reservation. Find another one hoping all links assigned
31 + * to it will also switch soon enough.
33 + * TODO: This needs a little more work as some cases
34 + * (more than 2 chanctx capable devices) may fail which could
35 + * otherwise succeed provided some channel context juggling was
38 + * Consider ctx1..3, link1..6, each ctx has 2 links. link1 and
39 + * link2 from ctx1 request new different chandefs starting 2
40 + * in-place reserations with ctx4 and ctx5 replacing ctx1 and
41 + * ctx2 respectively. Next link5 and link6 from ctx3 reserve
42 + * ctx4. If link3 and link4 remain on ctx2 as they are then this
43 + * fails unless `replace_ctx` from ctx5 is replaced with ctx3.
45 + list_for_each_entry(ctx, &local->chanctx_list, list) {
46 + if (ctx->replace_state !=
47 + IEEE80211_CHANCTX_REPLACE_NONE)
50 + if (!list_empty(&ctx->reserved_links))
59 + * If that's true then all available contexts already have reservations
60 + * and cannot be used.
62 + if (!curr_ctx || (curr_ctx->replace_state ==
63 + IEEE80211_CHANCTX_WILL_BE_REPLACED) ||
64 + !list_empty(&curr_ctx->reserved_links))
65 + return ERR_PTR(-EBUSY);
67 + new_ctx = ieee80211_alloc_chanctx(local, chanreq, mode, -1);
69 + return ERR_PTR(-ENOMEM);
71 + new_ctx->replace_ctx = curr_ctx;
72 + new_ctx->replace_state = IEEE80211_CHANCTX_REPLACES_OTHER;
74 + curr_ctx->replace_ctx = new_ctx;
75 + curr_ctx->replace_state = IEEE80211_CHANCTX_WILL_BE_REPLACED;
77 + list_add_rcu(&new_ctx->list, &local->chanctx_list);
82 int ieee80211_link_reserve_chanctx(struct ieee80211_link_data *link,
83 const struct ieee80211_chan_req *chanreq,
84 enum ieee80211_chanctx_mode mode,
85 @@ -1040,7 +1105,7 @@ int ieee80211_link_reserve_chanctx(struc
87 struct ieee80211_sub_if_data *sdata = link->sdata;
88 struct ieee80211_local *local = sdata->local;
89 - struct ieee80211_chanctx *new_ctx, *curr_ctx, *ctx;
90 + struct ieee80211_chanctx *new_ctx, *curr_ctx;
92 lockdep_assert_wiphy(local->hw.wiphy);
94 @@ -1050,75 +1115,13 @@ int ieee80211_link_reserve_chanctx(struc
96 new_ctx = ieee80211_find_reservation_chanctx(local, chanreq, mode);
98 - if (ieee80211_can_create_new_chanctx(local, -1)) {
99 + if (ieee80211_can_create_new_chanctx(local, -1))
100 new_ctx = ieee80211_new_chanctx(local, chanreq, mode);
101 - if (IS_ERR(new_ctx))
102 - return PTR_ERR(new_ctx);
105 - (curr_ctx->replace_state ==
106 - IEEE80211_CHANCTX_WILL_BE_REPLACED) ||
107 - !list_empty(&curr_ctx->reserved_links)) {
109 - * Another link already requested this context
110 - * for a reservation. Find another one hoping
111 - * all links assigned to it will also switch
114 - * TODO: This needs a little more work as some
115 - * cases (more than 2 chanctx capable devices)
116 - * may fail which could otherwise succeed
117 - * provided some channel context juggling was
120 - * Consider ctx1..3, link1..6, each ctx has 2
121 - * links. link1 and link2 from ctx1 request new
122 - * different chandefs starting 2 in-place
123 - * reserations with ctx4 and ctx5 replacing
124 - * ctx1 and ctx2 respectively. Next link5 and
125 - * link6 from ctx3 reserve ctx4. If link3 and
126 - * link4 remain on ctx2 as they are then this
127 - * fails unless `replace_ctx` from ctx5 is
128 - * replaced with ctx3.
130 - list_for_each_entry(ctx, &local->chanctx_list,
132 - if (ctx->replace_state !=
133 - IEEE80211_CHANCTX_REPLACE_NONE)
136 - if (!list_empty(&ctx->reserved_links))
145 - * If that's true then all available contexts already
146 - * have reservations and cannot be used.
149 - (curr_ctx->replace_state ==
150 - IEEE80211_CHANCTX_WILL_BE_REPLACED) ||
151 - !list_empty(&curr_ctx->reserved_links))
154 - new_ctx = ieee80211_alloc_chanctx(local, chanreq, mode, -1);
158 - new_ctx->replace_ctx = curr_ctx;
159 - new_ctx->replace_state =
160 - IEEE80211_CHANCTX_REPLACES_OTHER;
162 - curr_ctx->replace_ctx = new_ctx;
163 - curr_ctx->replace_state =
164 - IEEE80211_CHANCTX_WILL_BE_REPLACED;
166 - list_add_rcu(&new_ctx->list, &local->chanctx_list);
169 + new_ctx = ieee80211_replace_chanctx(local, chanreq,
171 + if (IS_ERR(new_ctx))
172 + return PTR_ERR(new_ctx);
175 list_add(&link->reserved_chanctx_list, &new_ctx->reserved_links);