Skip to content

Commit b2abb6e

Browse files
jmberg-intellinvjw
authored andcommitted
mac80211: sync driver before TX
In P2P client mode, the GO (AP) to connect to might have periods of time where it is not available due to powersave. To allow the driver to sync with it and send frames to the GO only when it is available add a new callback tx_sync (and the corresponding finish_tx_sync). These callbacks can sleep unlike the actual TX. Signed-off-by: Johannes Berg <johannes.berg@intel.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
1 parent e0d687b commit b2abb6e

6 files changed

Lines changed: 164 additions & 3 deletions

File tree

‎include/net/mac80211.h‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1585,6 +1585,20 @@ enum ieee80211_ampdu_mlme_action {
15851585
IEEE80211_AMPDU_TX_OPERATIONAL,
15861586
};
15871587

1588+
/**
1589+
* enum ieee80211_tx_sync_type - TX sync type
1590+
* @IEEE80211_TX_SYNC_AUTH: sync TX for authentication
1591+
* (and possibly also before direct probe)
1592+
* @IEEE80211_TX_SYNC_ASSOC: sync TX for association
1593+
* @IEEE80211_TX_SYNC_ACTION: sync TX for action frame
1594+
* (not implemented yet)
1595+
*/
1596+
enum ieee80211_tx_sync_type {
1597+
IEEE80211_TX_SYNC_AUTH,
1598+
IEEE80211_TX_SYNC_ASSOC,
1599+
IEEE80211_TX_SYNC_ACTION,
1600+
};
1601+
15881602
/**
15891603
* struct ieee80211_ops - callbacks from mac80211 to the driver
15901604
*
@@ -1674,6 +1688,26 @@ enum ieee80211_ampdu_mlme_action {
16741688
* of the bss parameters has changed when a call is made. The callback
16751689
* can sleep.
16761690
*
1691+
* @tx_sync: Called before a frame is sent to an AP/GO. In the GO case, the
1692+
* driver should sync with the GO's powersaving so the device doesn't
1693+
* transmit the frame while the GO is asleep. In the regular AP case
1694+
* it may be used by drivers for devices implementing other restrictions
1695+
* on talking to APs, e.g. due to regulatory enforcement or just HW
1696+
* restrictions.
1697+
* This function is called for every authentication, association and
1698+
* action frame separately since applications might attempt to auth
1699+
* with multiple APs before chosing one to associate to. If it returns
1700+
* an error, the corresponding authentication, association or frame
1701+
* transmission is aborted and reported as having failed. It is always
1702+
* called after tuning to the correct channel.
1703+
* The callback might be called multiple times before @finish_tx_sync
1704+
* (but @finish_tx_sync will be called once for each) but in practice
1705+
* this is unlikely to happen. It can also refuse in that case if the
1706+
* driver cannot handle that situation.
1707+
* This callback can sleep.
1708+
* @finish_tx_sync: Called as a counterpart to @tx_sync, unless that returned
1709+
* an error. This callback can sleep.
1710+
*
16771711
* @prepare_multicast: Prepare for multicast filter configuration.
16781712
* This callback is optional, and its return value is passed
16791713
* to configure_filter(). This callback must be atomic.
@@ -1901,6 +1935,14 @@ struct ieee80211_ops {
19011935
struct ieee80211_vif *vif,
19021936
struct ieee80211_bss_conf *info,
19031937
u32 changed);
1938+
1939+
int (*tx_sync)(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1940+
const u8 *bssid, enum ieee80211_tx_sync_type type);
1941+
void (*finish_tx_sync)(struct ieee80211_hw *hw,
1942+
struct ieee80211_vif *vif,
1943+
const u8 *bssid,
1944+
enum ieee80211_tx_sync_type type);
1945+
19041946
u64 (*prepare_multicast)(struct ieee80211_hw *hw,
19051947
struct netdev_hw_addr_list *mc_list);
19061948
void (*configure_filter)(struct ieee80211_hw *hw,

‎net/mac80211/driver-ops.h‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,37 @@ static inline void drv_bss_info_changed(struct ieee80211_local *local,
130130
trace_drv_return_void(local);
131131
}
132132

133+
static inline int drv_tx_sync(struct ieee80211_local *local,
134+
struct ieee80211_sub_if_data *sdata,
135+
const u8 *bssid,
136+
enum ieee80211_tx_sync_type type)
137+
{
138+
int ret = 0;
139+
140+
might_sleep();
141+
142+
trace_drv_tx_sync(local, sdata, bssid, type);
143+
if (local->ops->tx_sync)
144+
ret = local->ops->tx_sync(&local->hw, &sdata->vif,
145+
bssid, type);
146+
trace_drv_return_int(local, ret);
147+
return ret;
148+
}
149+
150+
static inline void drv_finish_tx_sync(struct ieee80211_local *local,
151+
struct ieee80211_sub_if_data *sdata,
152+
const u8 *bssid,
153+
enum ieee80211_tx_sync_type type)
154+
{
155+
might_sleep();
156+
157+
trace_drv_finish_tx_sync(local, sdata, bssid, type);
158+
if (local->ops->finish_tx_sync)
159+
local->ops->finish_tx_sync(&local->hw, &sdata->vif,
160+
bssid, type);
161+
trace_drv_return_void(local);
162+
}
163+
133164
static inline u64 drv_prepare_multicast(struct ieee80211_local *local,
134165
struct netdev_hw_addr_list *mc_list)
135166
{

‎net/mac80211/driver-trace.h‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,49 @@ TRACE_EVENT(drv_bss_info_changed,
319319
)
320320
);
321321

322+
DECLARE_EVENT_CLASS(tx_sync_evt,
323+
TP_PROTO(struct ieee80211_local *local,
324+
struct ieee80211_sub_if_data *sdata,
325+
const u8 *bssid,
326+
enum ieee80211_tx_sync_type type),
327+
TP_ARGS(local, sdata, bssid, type),
328+
329+
TP_STRUCT__entry(
330+
LOCAL_ENTRY
331+
VIF_ENTRY
332+
__array(char, bssid, ETH_ALEN)
333+
__field(u32, sync_type)
334+
),
335+
336+
TP_fast_assign(
337+
LOCAL_ASSIGN;
338+
VIF_ASSIGN;
339+
memcpy(__entry->bssid, bssid, ETH_ALEN);
340+
__entry->sync_type = type;
341+
),
342+
343+
TP_printk(
344+
LOCAL_PR_FMT VIF_PR_FMT " bssid:%pM type:%d",
345+
LOCAL_PR_ARG, VIF_PR_ARG, __entry->bssid, __entry->sync_type
346+
)
347+
);
348+
349+
DEFINE_EVENT(tx_sync_evt, drv_tx_sync,
350+
TP_PROTO(struct ieee80211_local *local,
351+
struct ieee80211_sub_if_data *sdata,
352+
const u8 *bssid,
353+
enum ieee80211_tx_sync_type type),
354+
TP_ARGS(local, sdata, bssid, type)
355+
);
356+
357+
DEFINE_EVENT(tx_sync_evt, drv_finish_tx_sync,
358+
TP_PROTO(struct ieee80211_local *local,
359+
struct ieee80211_sub_if_data *sdata,
360+
const u8 *bssid,
361+
enum ieee80211_tx_sync_type type),
362+
TP_ARGS(local, sdata, bssid, type)
363+
);
364+
322365
TRACE_EVENT(drv_prepare_multicast,
323366
TP_PROTO(struct ieee80211_local *local, int mc_count),
324367

‎net/mac80211/ieee80211_i.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ struct ieee80211_work {
323323
u8 key[WLAN_KEY_LEN_WEP104];
324324
u8 key_len, key_idx;
325325
bool privacy;
326+
bool synced;
326327
} probe_auth;
327328
struct {
328329
struct cfg80211_bss *bss;
@@ -336,6 +337,7 @@ struct ieee80211_work {
336337
u8 ssid_len;
337338
u8 supp_rates_len;
338339
bool wmm_used, use_11n, uapsd_used;
340+
bool synced;
339341
} assoc;
340342
struct {
341343
u32 duration;

‎net/mac80211/mlme.c‎

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2335,14 +2335,16 @@ static enum work_done_result
23352335
ieee80211_probe_auth_done(struct ieee80211_work *wk,
23362336
struct sk_buff *skb)
23372337
{
2338+
struct ieee80211_local *local = wk->sdata->local;
2339+
23382340
if (!skb) {
23392341
cfg80211_send_auth_timeout(wk->sdata->dev, wk->filter_ta);
2340-
return WORK_DONE_DESTROY;
2342+
goto destroy;
23412343
}
23422344

23432345
if (wk->type == IEEE80211_WORK_AUTH) {
23442346
cfg80211_send_rx_auth(wk->sdata->dev, skb->data, skb->len);
2345-
return WORK_DONE_DESTROY;
2347+
goto destroy;
23462348
}
23472349

23482350
mutex_lock(&wk->sdata->u.mgd.mtx);
@@ -2352,6 +2354,12 @@ ieee80211_probe_auth_done(struct ieee80211_work *wk,
23522354
wk->type = IEEE80211_WORK_AUTH;
23532355
wk->probe_auth.tries = 0;
23542356
return WORK_DONE_REQUEUE;
2357+
destroy:
2358+
if (wk->probe_auth.synced)
2359+
drv_finish_tx_sync(local, wk->sdata, wk->filter_ta,
2360+
IEEE80211_TX_SYNC_AUTH);
2361+
2362+
return WORK_DONE_DESTROY;
23552363
}
23562364

23572365
int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
@@ -2424,14 +2432,15 @@ int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
24242432
static enum work_done_result ieee80211_assoc_done(struct ieee80211_work *wk,
24252433
struct sk_buff *skb)
24262434
{
2435+
struct ieee80211_local *local = wk->sdata->local;
24272436
struct ieee80211_mgmt *mgmt;
24282437
struct ieee80211_rx_status *rx_status;
24292438
struct ieee802_11_elems elems;
24302439
u16 status;
24312440

24322441
if (!skb) {
24332442
cfg80211_send_assoc_timeout(wk->sdata->dev, wk->filter_ta);
2434-
return WORK_DONE_DESTROY;
2443+
goto destroy;
24352444
}
24362445

24372446
if (wk->type == IEEE80211_WORK_ASSOC_BEACON_WAIT) {
@@ -2451,6 +2460,10 @@ static enum work_done_result ieee80211_assoc_done(struct ieee80211_work *wk,
24512460
status = le16_to_cpu(mgmt->u.assoc_resp.status_code);
24522461

24532462
if (status == WLAN_STATUS_SUCCESS) {
2463+
if (wk->assoc.synced)
2464+
drv_finish_tx_sync(local, wk->sdata, wk->filter_ta,
2465+
IEEE80211_TX_SYNC_ASSOC);
2466+
24542467
mutex_lock(&wk->sdata->u.mgd.mtx);
24552468
if (!ieee80211_assoc_success(wk, mgmt, skb->len)) {
24562469
mutex_unlock(&wk->sdata->u.mgd.mtx);
@@ -2464,6 +2477,11 @@ static enum work_done_result ieee80211_assoc_done(struct ieee80211_work *wk,
24642477
}
24652478

24662479
cfg80211_send_rx_assoc(wk->sdata->dev, skb->data, skb->len);
2480+
destroy:
2481+
if (wk->assoc.synced)
2482+
drv_finish_tx_sync(local, wk->sdata, wk->filter_ta,
2483+
IEEE80211_TX_SYNC_ASSOC);
2484+
24672485
return WORK_DONE_DESTROY;
24682486
}
24692487

‎net/mac80211/work.c‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#include "ieee80211_i.h"
2727
#include "rate.h"
28+
#include "driver-ops.h"
2829

2930
#define IEEE80211_AUTH_TIMEOUT (HZ / 5)
3031
#define IEEE80211_AUTH_MAX_TRIES 3
@@ -427,6 +428,14 @@ ieee80211_direct_probe(struct ieee80211_work *wk)
427428
struct ieee80211_sub_if_data *sdata = wk->sdata;
428429
struct ieee80211_local *local = sdata->local;
429430

431+
if (!wk->probe_auth.synced) {
432+
int ret = drv_tx_sync(local, sdata, wk->filter_ta,
433+
IEEE80211_TX_SYNC_AUTH);
434+
if (ret)
435+
return WORK_ACT_TIMEOUT;
436+
}
437+
wk->probe_auth.synced = true;
438+
430439
wk->probe_auth.tries++;
431440
if (wk->probe_auth.tries > IEEE80211_AUTH_MAX_TRIES) {
432441
printk(KERN_DEBUG "%s: direct probe to %pM timed out\n",
@@ -466,6 +475,14 @@ ieee80211_authenticate(struct ieee80211_work *wk)
466475
struct ieee80211_sub_if_data *sdata = wk->sdata;
467476
struct ieee80211_local *local = sdata->local;
468477

478+
if (!wk->probe_auth.synced) {
479+
int ret = drv_tx_sync(local, sdata, wk->filter_ta,
480+
IEEE80211_TX_SYNC_AUTH);
481+
if (ret)
482+
return WORK_ACT_TIMEOUT;
483+
}
484+
wk->probe_auth.synced = true;
485+
469486
wk->probe_auth.tries++;
470487
if (wk->probe_auth.tries > IEEE80211_AUTH_MAX_TRIES) {
471488
printk(KERN_DEBUG "%s: authentication with %pM"
@@ -499,6 +516,14 @@ ieee80211_associate(struct ieee80211_work *wk)
499516
struct ieee80211_sub_if_data *sdata = wk->sdata;
500517
struct ieee80211_local *local = sdata->local;
501518

519+
if (!wk->assoc.synced) {
520+
int ret = drv_tx_sync(local, sdata, wk->filter_ta,
521+
IEEE80211_TX_SYNC_ASSOC);
522+
if (ret)
523+
return WORK_ACT_TIMEOUT;
524+
}
525+
wk->assoc.synced = true;
526+
502527
wk->assoc.tries++;
503528
if (wk->assoc.tries > IEEE80211_ASSOC_MAX_TRIES) {
504529
printk(KERN_DEBUG "%s: association with %pM"

0 commit comments

Comments
 (0)