9a850676022fca958b1fffcee37395eb561b97df
[openwrt/staging/wigyori.git] /
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
5
6 Reduces indentation in preparation for further changes
7
8 Signed-off-by: Felix Fietkau <nbd@nbd.name>
9 ---
10
11 --- a/net/mac80211/chan.c
12 +++ b/net/mac80211/chan.c
13 @@ -1033,6 +1033,71 @@ int ieee80211_link_unreserve_chanctx(str
14 return 0;
15 }
16
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)
22 +{
23 + struct ieee80211_chanctx *new_ctx, *ctx;
24 +
25 + if (!curr_ctx || (curr_ctx->replace_state ==
26 + IEEE80211_CHANCTX_WILL_BE_REPLACED) ||
27 + !list_empty(&curr_ctx->reserved_links)) {
28 + /*
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.
32 + *
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
36 + * performed.
37 + *
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.
44 + */
45 + list_for_each_entry(ctx, &local->chanctx_list, list) {
46 + if (ctx->replace_state !=
47 + IEEE80211_CHANCTX_REPLACE_NONE)
48 + continue;
49 +
50 + if (!list_empty(&ctx->reserved_links))
51 + continue;
52 +
53 + curr_ctx = ctx;
54 + break;
55 + }
56 + }
57 +
58 + /*
59 + * If that's true then all available contexts already have reservations
60 + * and cannot be used.
61 + */
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);
66 +
67 + new_ctx = ieee80211_alloc_chanctx(local, chanreq, mode, -1);
68 + if (!new_ctx)
69 + return ERR_PTR(-ENOMEM);
70 +
71 + new_ctx->replace_ctx = curr_ctx;
72 + new_ctx->replace_state = IEEE80211_CHANCTX_REPLACES_OTHER;
73 +
74 + curr_ctx->replace_ctx = new_ctx;
75 + curr_ctx->replace_state = IEEE80211_CHANCTX_WILL_BE_REPLACED;
76 +
77 + list_add_rcu(&new_ctx->list, &local->chanctx_list);
78 +
79 + return new_ctx;
80 +}
81 +
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
86 {
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;
91
92 lockdep_assert_wiphy(local->hw.wiphy);
93
94 @@ -1050,75 +1115,13 @@ int ieee80211_link_reserve_chanctx(struc
95
96 new_ctx = ieee80211_find_reservation_chanctx(local, chanreq, mode);
97 if (!new_ctx) {
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);
103 - } else {
104 - if (!curr_ctx ||
105 - (curr_ctx->replace_state ==
106 - IEEE80211_CHANCTX_WILL_BE_REPLACED) ||
107 - !list_empty(&curr_ctx->reserved_links)) {
108 - /*
109 - * Another link already requested this context
110 - * for a reservation. Find another one hoping
111 - * all links assigned to it will also switch
112 - * soon enough.
113 - *
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
118 - * performed.
119 - *
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.
129 - */
130 - list_for_each_entry(ctx, &local->chanctx_list,
131 - list) {
132 - if (ctx->replace_state !=
133 - IEEE80211_CHANCTX_REPLACE_NONE)
134 - continue;
135 -
136 - if (!list_empty(&ctx->reserved_links))
137 - continue;
138 -
139 - curr_ctx = ctx;
140 - break;
141 - }
142 - }
143 -
144 - /*
145 - * If that's true then all available contexts already
146 - * have reservations and cannot be used.
147 - */
148 - if (!curr_ctx ||
149 - (curr_ctx->replace_state ==
150 - IEEE80211_CHANCTX_WILL_BE_REPLACED) ||
151 - !list_empty(&curr_ctx->reserved_links))
152 - return -EBUSY;
153 -
154 - new_ctx = ieee80211_alloc_chanctx(local, chanreq, mode, -1);
155 - if (!new_ctx)
156 - return -ENOMEM;
157 -
158 - new_ctx->replace_ctx = curr_ctx;
159 - new_ctx->replace_state =
160 - IEEE80211_CHANCTX_REPLACES_OTHER;
161 -
162 - curr_ctx->replace_ctx = new_ctx;
163 - curr_ctx->replace_state =
164 - IEEE80211_CHANCTX_WILL_BE_REPLACED;
165 -
166 - list_add_rcu(&new_ctx->list, &local->chanctx_list);
167 - }
168 + else
169 + new_ctx = ieee80211_replace_chanctx(local, chanreq,
170 + mode, curr_ctx);
171 + if (IS_ERR(new_ctx))
172 + return PTR_ERR(new_ctx);
173 }
174
175 list_add(&link->reserved_chanctx_list, &new_ctx->reserved_links);