Skip to content

Commit 2c33360

Browse files
jhpark1013Kalle Valo
authored andcommitted
wfx: use container_of() to get vif
Currently, upon virtual interface creation, wfx_add_interface() stores a reference to the corresponding struct ieee80211_vif in private data, for later usage. This is not needed when using the container_of construct. This construct already has all the info it needs to retrieve the reference to the corresponding struct from the offset that is already available, inherent in container_of(), between its type and member inputs (struct ieee80211_vif and drv_priv, respectively). Remove vif (which was previously storing the reference to the struct ieee80211_vif) from the struct wfx_vif, define a function wvif_to_vif(wvif) for container_of(), and replace all wvif->vif with the newly defined container_of construct. Signed-off-by: Jaehee Park <[email protected]> Signed-off-by: Kalle Valo <[email protected]> Link: https://lore.kernel.org/r/20220506170046.GA1297231@jaehee-ThinkPad-X1-Extreme
1 parent dadb208 commit 2c33360

File tree

7 files changed

+68
-40
lines changed

7 files changed

+68
-40
lines changed

drivers/net/wireless/silabs/wfx/data_rx.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
static void wfx_rx_handle_ba(struct wfx_vif *wvif, struct ieee80211_mgmt *mgmt)
1717
{
18+
struct ieee80211_vif *vif = wvif_to_vif(wvif);
1819
int params, tid;
1920

2021
if (wfx_api_older_than(wvif->wdev, 3, 6))
@@ -24,12 +25,12 @@ static void wfx_rx_handle_ba(struct wfx_vif *wvif, struct ieee80211_mgmt *mgmt)
2425
case WLAN_ACTION_ADDBA_REQ:
2526
params = le16_to_cpu(mgmt->u.action.u.addba_req.capab);
2627
tid = (params & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
27-
ieee80211_start_rx_ba_session_offl(wvif->vif, mgmt->sa, tid);
28+
ieee80211_start_rx_ba_session_offl(vif, mgmt->sa, tid);
2829
break;
2930
case WLAN_ACTION_DELBA:
3031
params = le16_to_cpu(mgmt->u.action.u.delba.params);
3132
tid = (params & IEEE80211_DELBA_PARAM_TID_MASK) >> 12;
32-
ieee80211_stop_rx_ba_session_offl(wvif->vif, mgmt->sa, tid);
33+
ieee80211_stop_rx_ba_session_offl(vif, mgmt->sa, tid);
3334
break;
3435
}
3536
}

drivers/net/wireless/silabs/wfx/data_tx.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,12 @@ static u8 wfx_tx_get_link_id(struct wfx_vif *wvif, struct ieee80211_sta *sta,
212212
struct ieee80211_hdr *hdr)
213213
{
214214
struct wfx_sta_priv *sta_priv = sta ? (struct wfx_sta_priv *)&sta->drv_priv : NULL;
215+
struct ieee80211_vif *vif = wvif_to_vif(wvif);
215216
const u8 *da = ieee80211_get_DA(hdr);
216217

217218
if (sta_priv && sta_priv->link_id)
218219
return sta_priv->link_id;
219-
if (wvif->vif->type != NL80211_IFTYPE_AP)
220+
if (vif->type != NL80211_IFTYPE_AP)
220221
return 0;
221222
if (is_multicast_ether_addr(da))
222223
return 0;

drivers/net/wireless/silabs/wfx/key.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ static int wfx_add_key(struct wfx_vif *wvif, struct ieee80211_sta *sta,
156156
struct wfx_dev *wdev = wvif->wdev;
157157
int idx = wfx_alloc_key(wvif->wdev);
158158
bool pairwise = key->flags & IEEE80211_KEY_FLAG_PAIRWISE;
159+
struct ieee80211_vif *vif = wvif_to_vif(wvif);
159160

160161
WARN(key->flags & IEEE80211_KEY_FLAG_PAIRWISE && !sta, "inconsistent data");
161162
ieee80211_get_key_rx_seq(key, 0, &seq);
@@ -174,7 +175,7 @@ static int wfx_add_key(struct wfx_vif *wvif, struct ieee80211_sta *sta,
174175
k.type = fill_tkip_pair(&k.key.tkip_pairwise_key, key, sta->addr);
175176
else
176177
k.type = fill_tkip_group(&k.key.tkip_group_key, key, &seq,
177-
wvif->vif->type);
178+
vif->type);
178179
} else if (key->cipher == WLAN_CIPHER_SUITE_CCMP) {
179180
if (pairwise)
180181
k.type = fill_ccmp_pair(&k.key.aes_pairwise_key, key, sta->addr);
@@ -224,4 +225,3 @@ int wfx_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, struct ieee80211_
224225
mutex_unlock(&wvif->wdev->conf_mutex);
225226
return ret;
226227
}
227-

drivers/net/wireless/silabs/wfx/queue.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,10 @@ unsigned int wfx_pending_get_pkt_us_delay(struct wfx_dev *wdev, struct sk_buff *
205205

206206
bool wfx_tx_queues_has_cab(struct wfx_vif *wvif)
207207
{
208+
struct ieee80211_vif *vif = wvif_to_vif(wvif);
208209
int i;
209210

210-
if (wvif->vif->type != NL80211_IFTYPE_AP)
211+
if (vif->type != NL80211_IFTYPE_AP)
211212
return false;
212213
for (i = 0; i < IEEE80211_NUM_ACS; ++i)
213214
/* Note: since only AP can have mcast frames in queue and only one vif can be AP,

drivers/net/wireless/silabs/wfx/scan.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ static void wfx_ieee80211_scan_completed_compat(struct ieee80211_hw *hw, bool ab
2323

2424
static int update_probe_tmpl(struct wfx_vif *wvif, struct cfg80211_scan_request *req)
2525
{
26+
struct ieee80211_vif *vif = wvif_to_vif(wvif);
2627
struct sk_buff *skb;
2728

28-
skb = ieee80211_probereq_get(wvif->wdev->hw, wvif->vif->addr, NULL, 0, req->ie_len);
29+
skb = ieee80211_probereq_get(wvif->wdev->hw, vif->addr, NULL, 0,
30+
req->ie_len);
2931
if (!skb)
3032
return -ENOMEM;
3133

@@ -37,8 +39,9 @@ static int update_probe_tmpl(struct wfx_vif *wvif, struct cfg80211_scan_request
3739

3840
static int send_scan_req(struct wfx_vif *wvif, struct cfg80211_scan_request *req, int start_idx)
3941
{
40-
int i, ret;
42+
struct ieee80211_vif *vif = wvif_to_vif(wvif);
4143
struct ieee80211_channel *ch_start, *ch_cur;
44+
int i, ret;
4245

4346
for (i = start_idx; i < req->n_channels; i++) {
4447
ch_start = req->channels[start_idx];
@@ -75,8 +78,8 @@ static int send_scan_req(struct wfx_vif *wvif, struct cfg80211_scan_request *req
7578
} else {
7679
ret = wvif->scan_nb_chan_done;
7780
}
78-
if (req->channels[start_idx]->max_power != wvif->vif->bss_conf.txpower)
79-
wfx_hif_set_output_power(wvif, wvif->vif->bss_conf.txpower);
81+
if (req->channels[start_idx]->max_power != vif->bss_conf.txpower)
82+
wfx_hif_set_output_power(wvif, vif->bss_conf.txpower);
8083
wfx_tx_unlock(wvif->wdev);
8184
return ret;
8285
}

drivers/net/wireless/silabs/wfx/sta.c

Lines changed: 47 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,10 @@ static void wfx_filter_beacon(struct wfx_vif *wvif, bool filter_beacon)
9898
void wfx_configure_filter(struct ieee80211_hw *hw, unsigned int changed_flags,
9999
unsigned int *total_flags, u64 unused)
100100
{
101-
struct wfx_vif *wvif = NULL;
102-
struct wfx_dev *wdev = hw->priv;
103101
bool filter_bssid, filter_prbreq, filter_beacon;
102+
struct ieee80211_vif *vif = NULL;
103+
struct wfx_dev *wdev = hw->priv;
104+
struct wfx_vif *wvif = NULL;
104105

105106
/* Notes:
106107
* - Probe responses (FIF_BCN_PRBRESP_PROMISC) are never filtered
@@ -131,8 +132,9 @@ void wfx_configure_filter(struct ieee80211_hw *hw, unsigned int changed_flags,
131132
else
132133
filter_bssid = true;
133134

135+
vif = wvif_to_vif(wvif);
134136
/* In AP mode, chip can reply to probe request itself */
135-
if (*total_flags & FIF_PROBE_REQ && wvif->vif->type == NL80211_IFTYPE_AP) {
137+
if (*total_flags & FIF_PROBE_REQ && vif->type == NL80211_IFTYPE_AP) {
136138
dev_dbg(wdev->dev, "do not forward probe request in AP mode\n");
137139
*total_flags &= ~FIF_PROBE_REQ;
138140
}
@@ -152,19 +154,28 @@ static int wfx_get_ps_timeout(struct wfx_vif *wvif, bool *enable_ps)
152154
{
153155
struct ieee80211_channel *chan0 = NULL, *chan1 = NULL;
154156
struct ieee80211_conf *conf = &wvif->wdev->hw->conf;
157+
struct ieee80211_vif *vif = wvif_to_vif(wvif);
155158

156-
WARN(!wvif->vif->bss_conf.assoc && enable_ps,
159+
WARN(!vif->bss_conf.assoc && enable_ps,
157160
"enable_ps is reliable only if associated");
158-
if (wdev_to_wvif(wvif->wdev, 0))
159-
chan0 = wdev_to_wvif(wvif->wdev, 0)->vif->bss_conf.chandef.chan;
160-
if (wdev_to_wvif(wvif->wdev, 1))
161-
chan1 = wdev_to_wvif(wvif->wdev, 1)->vif->bss_conf.chandef.chan;
162-
if (chan0 && chan1 && wvif->vif->type != NL80211_IFTYPE_AP) {
161+
if (wdev_to_wvif(wvif->wdev, 0)) {
162+
struct wfx_vif *wvif_ch0 = wdev_to_wvif(wvif->wdev, 0);
163+
struct ieee80211_vif *vif_ch0 = wvif_to_vif(wvif_ch0);
164+
165+
chan0 = vif_ch0->bss_conf.chandef.chan;
166+
}
167+
if (wdev_to_wvif(wvif->wdev, 1)) {
168+
struct wfx_vif *wvif_ch1 = wdev_to_wvif(wvif->wdev, 1);
169+
struct ieee80211_vif *vif_ch1 = wvif_to_vif(wvif_ch1);
170+
171+
chan1 = vif_ch1->bss_conf.chandef.chan;
172+
}
173+
if (chan0 && chan1 && vif->type != NL80211_IFTYPE_AP) {
163174
if (chan0->hw_value == chan1->hw_value) {
164175
/* It is useless to enable PS if channels are the same. */
165176
if (enable_ps)
166177
*enable_ps = false;
167-
if (wvif->vif->bss_conf.assoc && wvif->vif->bss_conf.ps)
178+
if (vif->bss_conf.assoc && vif->bss_conf.ps)
168179
dev_info(wvif->wdev->dev, "ignoring requested PS mode");
169180
return -1;
170181
}
@@ -177,19 +188,20 @@ static int wfx_get_ps_timeout(struct wfx_vif *wvif, bool *enable_ps)
177188
return 30;
178189
}
179190
if (enable_ps)
180-
*enable_ps = wvif->vif->bss_conf.ps;
181-
if (wvif->vif->bss_conf.assoc && wvif->vif->bss_conf.ps)
191+
*enable_ps = vif->bss_conf.ps;
192+
if (vif->bss_conf.assoc && vif->bss_conf.ps)
182193
return conf->dynamic_ps_timeout;
183194
else
184195
return -1;
185196
}
186197

187198
int wfx_update_pm(struct wfx_vif *wvif)
188199
{
200+
struct ieee80211_vif *vif = wvif_to_vif(wvif);
189201
int ps_timeout;
190202
bool ps;
191203

192-
if (!wvif->vif->bss_conf.assoc)
204+
if (!vif->bss_conf.assoc)
193205
return 0;
194206
ps_timeout = wfx_get_ps_timeout(wvif, &ps);
195207
if (!ps)
@@ -215,7 +227,8 @@ int wfx_conf_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
215227
mutex_lock(&wdev->conf_mutex);
216228
assign_bit(queue, &wvif->uapsd_mask, params->uapsd);
217229
wfx_hif_set_edca_queue_params(wvif, queue, params);
218-
if (wvif->vif->type == NL80211_IFTYPE_STATION && old_uapsd != wvif->uapsd_mask) {
230+
if (vif->type == NL80211_IFTYPE_STATION &&
231+
old_uapsd != wvif->uapsd_mask) {
219232
wfx_hif_set_uapsd_info(wvif, wvif->uapsd_mask);
220233
wfx_update_pm(wvif);
221234
}
@@ -238,24 +251,26 @@ void wfx_event_report_rssi(struct wfx_vif *wvif, u8 raw_rcpi_rssi)
238251
/* RSSI: signed Q8.0, RCPI: unsigned Q7.1
239252
* RSSI = RCPI / 2 - 110
240253
*/
254+
struct ieee80211_vif *vif = wvif_to_vif(wvif);
241255
int rcpi_rssi;
242256
int cqm_evt;
243257

244258
rcpi_rssi = raw_rcpi_rssi / 2 - 110;
245-
if (rcpi_rssi <= wvif->vif->bss_conf.cqm_rssi_thold)
259+
if (rcpi_rssi <= vif->bss_conf.cqm_rssi_thold)
246260
cqm_evt = NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW;
247261
else
248262
cqm_evt = NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH;
249-
ieee80211_cqm_rssi_notify(wvif->vif, cqm_evt, rcpi_rssi, GFP_KERNEL);
263+
ieee80211_cqm_rssi_notify(vif, cqm_evt, rcpi_rssi, GFP_KERNEL);
250264
}
251265

252266
static void wfx_beacon_loss_work(struct work_struct *work)
253267
{
254268
struct wfx_vif *wvif = container_of(to_delayed_work(work), struct wfx_vif,
255269
beacon_loss_work);
256-
struct ieee80211_bss_conf *bss_conf = &wvif->vif->bss_conf;
270+
struct ieee80211_vif *vif = wvif_to_vif(wvif);
271+
struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
257272

258-
ieee80211_beacon_loss(wvif->vif);
273+
ieee80211_beacon_loss(vif);
259274
schedule_delayed_work(to_delayed_work(work), msecs_to_jiffies(bss_conf->beacon_int));
260275
}
261276

@@ -321,15 +336,16 @@ int wfx_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif, struct ie
321336

322337
static int wfx_upload_ap_templates(struct wfx_vif *wvif)
323338
{
339+
struct ieee80211_vif *vif = wvif_to_vif(wvif);
324340
struct sk_buff *skb;
325341

326-
skb = ieee80211_beacon_get(wvif->wdev->hw, wvif->vif);
342+
skb = ieee80211_beacon_get(wvif->wdev->hw, vif);
327343
if (!skb)
328344
return -ENOMEM;
329345
wfx_hif_set_template_frame(wvif, skb, HIF_TMPLT_BCN, API_RATE_INDEX_B_1MBPS);
330346
dev_kfree_skb(skb);
331347

332-
skb = ieee80211_proberesp_get(wvif->wdev->hw, wvif->vif);
348+
skb = ieee80211_proberesp_get(wvif->wdev->hw, vif);
333349
if (!skb)
334350
return -ENOMEM;
335351
wfx_hif_set_template_frame(wvif, skb, HIF_TMPLT_PRBRES, API_RATE_INDEX_B_1MBPS);
@@ -339,7 +355,8 @@ static int wfx_upload_ap_templates(struct wfx_vif *wvif)
339355

340356
static void wfx_set_mfp_ap(struct wfx_vif *wvif)
341357
{
342-
struct sk_buff *skb = ieee80211_beacon_get(wvif->wdev->hw, wvif->vif);
358+
struct ieee80211_vif *vif = wvif_to_vif(wvif);
359+
struct sk_buff *skb = ieee80211_beacon_get(wvif->wdev->hw, vif);
343360
const int ieoffset = offsetof(struct ieee80211_mgmt, u.beacon.variable);
344361
const u16 *ptr = (u16 *)cfg80211_find_ie(WLAN_EID_RSN, skb->data + ieoffset,
345362
skb->len - ieoffset);
@@ -388,12 +405,13 @@ void wfx_stop_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
388405

389406
static void wfx_join(struct wfx_vif *wvif)
390407
{
391-
int ret;
392-
struct ieee80211_bss_conf *conf = &wvif->vif->bss_conf;
408+
struct ieee80211_vif *vif = wvif_to_vif(wvif);
409+
struct ieee80211_bss_conf *conf = &vif->bss_conf;
393410
struct cfg80211_bss *bss = NULL;
394411
u8 ssid[IEEE80211_MAX_SSID_LEN];
395412
const u8 *ssidie = NULL;
396413
int ssidlen = 0;
414+
int ret;
397415

398416
wfx_tx_lock_flush(wvif->wdev);
399417

@@ -420,7 +438,7 @@ static void wfx_join(struct wfx_vif *wvif)
420438
wvif->join_in_progress = true;
421439
ret = wfx_hif_join(wvif, conf, wvif->channel, ssid, ssidlen);
422440
if (ret) {
423-
ieee80211_connection_loss(wvif->vif);
441+
ieee80211_connection_loss(vif);
424442
wfx_reset(wvif);
425443
} else {
426444
/* Due to beacon filtering it is possible that the AP's beacon is not known for the
@@ -434,13 +452,14 @@ static void wfx_join(struct wfx_vif *wvif)
434452

435453
static void wfx_join_finalize(struct wfx_vif *wvif, struct ieee80211_bss_conf *info)
436454
{
455+
struct ieee80211_vif *vif = wvif_to_vif(wvif);
437456
struct ieee80211_sta *sta = NULL;
438457
int ampdu_density = 0;
439458
bool greenfield = false;
440459

441460
rcu_read_lock(); /* protect sta */
442461
if (info->bssid && !info->ibss_joined)
443-
sta = ieee80211_find_sta(wvif->vif, info->bssid);
462+
sta = ieee80211_find_sta(vif, info->bssid);
444463
if (sta && sta->deflink.ht_cap.ht_supported)
445464
ampdu_density = sta->deflink.ht_cap.ampdu_density;
446465
if (sta && sta->deflink.ht_cap.ht_supported &&
@@ -561,11 +580,13 @@ void wfx_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
561580

562581
static int wfx_update_tim(struct wfx_vif *wvif)
563582
{
583+
struct ieee80211_vif *vif = wvif_to_vif(wvif);
564584
struct sk_buff *skb;
565585
u16 tim_offset, tim_length;
566586
u8 *tim_ptr;
567587

568-
skb = ieee80211_beacon_get_tim(wvif->wdev->hw, wvif->vif, &tim_offset, &tim_length);
588+
skb = ieee80211_beacon_get_tim(wvif->wdev->hw, vif, &tim_offset,
589+
&tim_length);
569590
if (!skb)
570591
return -ENOENT;
571592
tim_ptr = skb->data + tim_offset;
@@ -707,8 +728,6 @@ int wfx_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
707728
return -EOPNOTSUPP;
708729
}
709730

710-
/* FIXME: prefer use of container_of() to get vif */
711-
wvif->vif = vif;
712731
wvif->wdev = wdev;
713732

714733
wvif->link_id_map = 1; /* link-id 0 is reserved for multicast */
@@ -767,7 +786,6 @@ void wfx_remove_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
767786

768787
cancel_delayed_work_sync(&wvif->beacon_loss_work);
769788
wdev->vif[wvif->id] = NULL;
770-
wvif->vif = NULL;
771789

772790
mutex_unlock(&wdev->conf_mutex);
773791

drivers/net/wireless/silabs/wfx/wfx.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ struct wfx_dev {
6262

6363
struct wfx_vif {
6464
struct wfx_dev *wdev;
65-
struct ieee80211_vif *vif;
6665
struct ieee80211_channel *channel;
6766
int id;
6867

@@ -92,6 +91,11 @@ struct wfx_vif {
9291
struct completion set_pm_mode_complete;
9392
};
9493

94+
static inline struct ieee80211_vif *wvif_to_vif(struct wfx_vif *wvif)
95+
{
96+
return container_of((void *)wvif, struct ieee80211_vif, drv_priv);
97+
}
98+
9599
static inline struct wfx_vif *wdev_to_wvif(struct wfx_dev *wdev, int vif_id)
96100
{
97101
if (vif_id >= ARRAY_SIZE(wdev->vif)) {

0 commit comments

Comments
 (0)