Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
194 changes: 194 additions & 0 deletions drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
/* Toplevel file. Relies on dhd_linux.c to send commands to the dongle. */

#include <linux/kernel.h>
#include <linux/smp.h>
#include <linux/etherdevice.h>
#include <linux/inetdevice.h>
#include <linux/module.h>
Expand Down Expand Up @@ -90,6 +91,12 @@

#define BRCMF_ND_INFO_TIMEOUT msecs_to_jiffies(2000)

/*
* Bound wiphy-lock hold while waiting for firmware's terminal event
* after BRCMF_C_DISASSOC cancels an in-flight offloaded join.
*/
#define BRCMF_JOIN_CANCEL_TIMEOUT msecs_to_jiffies(1000)

#define BRCMF_PS_MAX_TIMEOUT_MS 2000

#define BRCMF_LPAS_UNICAST_FILTER_ID 100
Expand Down Expand Up @@ -2476,6 +2483,114 @@ static void brcmf_connect_set_target(struct brcmf_cfg80211_profile *profile,
eth_zero_addr(profile->bssid);
}

static bool brcmf_join_canceling(struct brcmf_cfg80211_vif *vif)
{
/* Pairs with brcmf_set_join_canceling(): observe completion setup. */
return smp_load_acquire(&vif->join_canceling);
}

static void brcmf_set_join_canceling(struct brcmf_cfg80211_vif *vif,
bool pending)
{
/* Publish preceding setup/teardown before callbacks observe the flag. */
smp_store_release(&vif->join_canceling, pending);
}

/* Reset the station firmware, which ends any join, keeping its power mode. */
static int brcmf_station_reset(struct brcmf_if *ifp)
{
u32 pm_mode;
int err;

err = brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_PM, &pm_mode);
if (!err)
err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_DOWN, 1);
if (!err)
err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 1);
if (!err)
err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM, pm_mode);
return err;
}

/*
* A replacement must not inherit completion of the cancelled firmware join.
* Keep the old profile until its terminal event. The callback signals this
* waiter without taking the wiphy lock held by the connect operation.
*
* A first cancel that times out fails the old host request and returns -EBUSY,
* still ignoring the old join's events. The next connect cancels again. If that
* also sees no terminal event, the station firmware is reset with the flag
* still set, which ends the join for certain, and the connect is refused once
* more. A later connect admits a replacement only once no firmware event is
* still queued, so no event of the old join can reach it.
*/
static int brcmf_cancel_pending_join(struct brcmf_if *ifp)
{
struct brcmf_cfg80211_vif *vif = ifp->vif;
struct brcmf_scb_val_le scb = {
.val = cpu_to_le32(WLAN_REASON_DEAUTH_LEAVING),
};
struct cfg80211_connect_resp_params failed = {
.status = WLAN_STATUS_AUTH_TIMEOUT,
};
bool retry = brcmf_join_canceling(vif);
int err;

if (retry && vif->join_reset) {
if (!brcmf_fweh_idle(ifp->drvr))
return -EBUSY;
vif->join_reset = false;
goto cancelled;
}
reinit_completion(&vif->join_cancel_done);
brcmf_set_join_canceling(vif, true);
/*
* Order the flag before the CONNECTING test. brcmf_notify_connect_status()
* tests the flag before it ends a join and clears CONNECTING, so one of
* the two sees the other.
*/
smp_mb();
if (!retry && !test_bit(BRCMF_VIF_STATUS_CONNECTING, &vif->sme_state))
goto ended;
memcpy(scb.ea, vif->profile.bssid, ETH_ALEN);
err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_DISASSOC, &scb, sizeof(scb));
if (err) {
if (!retry)
brcmf_set_join_canceling(vif, false);
return -EBUSY;
}
if (!wait_for_completion_timeout(&vif->join_cancel_done,
BRCMF_JOIN_CANCEL_TIMEOUT)) {
/* The old join ended through the normal path just before the flag. */
if (!retry &&
!test_bit(BRCMF_VIF_STATUS_CONNECTING, &vif->sme_state))
goto ended;
if (!retry) {
/* Fail the old host request once; keep ignoring its events. */
if (test_and_clear_bit(BRCMF_VIF_STATUS_CONNECTING,
&vif->sme_state))
cfg80211_connect_done(ifp->ndev, &failed, GFP_KERNEL);
return -EBUSY;
}
brcmf_dbg(CONN, "cancelled join sent no terminal event twice: resetting the station\n");
if (!brcmf_station_reset(ifp))
vif->join_reset = true;
return -EBUSY;
}
cancelled:
clear_bit(BRCMF_VIF_STATUS_CONNECTING, &vif->sme_state);
clear_bit(BRCMF_VIF_STATUS_CONNECTED, &vif->sme_state);
clear_bit(BRCMF_VIF_STATUS_EAP_SUCCESS, &vif->sme_state);
clear_bit(BRCMF_VIF_STATUS_ASSOC_SUCCESS, &vif->sme_state);
brcmf_set_join_canceling(vif, false);
return 0;

ended:
/* Nothing left to cancel; a join that succeeded keeps the link. */
brcmf_set_join_canceling(vif, false);
return test_bit(BRCMF_VIF_STATUS_CONNECTED, &vif->sme_state) ? -EBUSY : 0;
}

static s32
brcmf_cfg80211_connect(struct wiphy *wiphy, struct net_device *ndev,
struct cfg80211_connect_params *params)
Expand All @@ -2496,6 +2611,20 @@ brcmf_cfg80211_connect(struct wiphy *wiphy, struct net_device *ndev,
s32 err = 0;

brcmf_dbg(TRACE, "Enter\n");
if (ifp->vif->wdev.iftype == NL80211_IFTYPE_STATION &&
(test_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state) ||
brcmf_join_canceling(ifp->vif))) {
/* Only a firmware-supplicant join is cancelled; a reset one is fenced for all. */
if (ifp->vif->wdev.connected ||
(!ifp->vif->join_reset &&
profile->use_fwsup != BRCMF_PROFILE_FWSUP_SAE &&
profile->use_fwsup != BRCMF_PROFILE_FWSUP_PSK))
return -EBUSY;
err = brcmf_cancel_pending_join(ifp);
if (err)
return err;
}

if (!check_vif_up(ifp->vif))
return -EIO;

Expand Down Expand Up @@ -5100,6 +5229,51 @@ static s32 brcmf_cfg80211_resume(struct wiphy *wiphy)
brcmf_notify_sched_scan_results);
cfg->wowl.nd_enabled = false;
}
} else if (ifp->vif &&
ifp->vif->wdev.iftype == NL80211_IFTYPE_STATION &&
test_bit(BRCMF_VIF_STATUS_READY, &ifp->vif->sme_state)) {
u32 pm_mode;
bool pending, was_canceling;

/* Keep the configured power mode across wireless reinitialization. */
err = brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_PM, &pm_mode);
if (err)
goto out;
/*
* DOWN ends any firmware join. Ignore that join's events from here,
* and let the next connect admit a replacement only once none is
* still queued (brcmf_cancel_pending_join()).
*/
pending = test_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state);
was_canceling = brcmf_join_canceling(ifp->vif);
if (pending || was_canceling) {
reinit_completion(&ifp->vif->join_cancel_done);
brcmf_set_join_canceling(ifp->vif, true);
}
err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_DOWN, 1);
if (err) {
/* No DOWN, so the join was not ended: stop ignoring its events. */
if (!was_canceling)
brcmf_set_join_canceling(ifp->vif, false);
goto out;
}
if (brcmf_join_canceling(ifp->vif))
ifp->vif->join_reset = true;
if (pending &&
test_and_clear_bit(BRCMF_VIF_STATUS_CONNECTING,
&ifp->vif->sme_state)) {
struct cfg80211_connect_resp_params failed = {
.status = WLAN_STATUS_AUTH_TIMEOUT,
};

cfg80211_connect_done(ifp->ndev, &failed, GFP_KERNEL);
}
err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 1);
if (err)
goto out;
err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM, pm_mode);
brcmf_dbg(CONN, "wireless reinit pm=%u result=%d\n", pm_mode,
err);
}
out:
cfg->suspended = false;
Expand Down Expand Up @@ -7125,6 +7299,7 @@ struct brcmf_cfg80211_vif *brcmf_alloc_vif(struct brcmf_cfg80211_info *cfg,
vif->wdev.iftype = type;
init_completion(&vif->mgmt_tx);
init_completion(&vif->link_down);
init_completion(&vif->join_cancel_done);

brcmf_init_prof(&vif->profile);

Expand Down Expand Up @@ -7775,6 +7950,20 @@ brcmf_notify_connect_status(struct brcmf_if *ifp,
brcmf_proto_delete_peer(ifp->drvr, ifp->ifidx, (u8 *)e->addr);
}

if (brcmf_join_canceling(ifp->vif)) {
bool terminal =
(e->event_code == BRCMF_E_SET_SSID &&
e->status != BRCMF_E_STATUS_SUCCESS) ||
(e->event_code == BRCMF_E_LINK && !e->flags) ||
e->event_code == BRCMF_E_DEAUTH ||
e->event_code == BRCMF_E_DEAUTH_IND ||
e->event_code == BRCMF_E_DISASSOC_IND;

if (terminal)
complete(&ifp->vif->join_cancel_done);
return 0;
}

if (brcmf_is_apmode(ifp->vif)) {
err = brcmf_notify_connect_status_ap(cfg, ndev, e, data);
} else if (brcmf_is_linkup(ifp->vif, e)) {
Expand Down Expand Up @@ -7835,6 +8024,9 @@ brcmf_notify_roaming_status(struct brcmf_if *ifp,
u32 event = e->event_code;
u32 status = e->status;

if (brcmf_join_canceling(ifp->vif))
return 0;

if (event == BRCMF_E_ROAM && status == BRCMF_E_STATUS_SUCCESS) {
if (test_bit(BRCMF_VIF_STATUS_CONNECTED,
&ifp->vif->sme_state)) {
Expand Down Expand Up @@ -9343,6 +9535,8 @@ static s32 __brcmf_cfg80211_down(struct brcmf_if *ifp)

brcmf_abort_scanning(cfg);
clear_bit(BRCMF_VIF_STATUS_READY, &ifp->vif->sme_state);
ifp->vif->join_reset = false;
brcmf_set_join_canceling(ifp->vif, false);

return 0;
}
Expand Down
7 changes: 7 additions & 0 deletions drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@ struct vif_saved_ie {
* @list: linked list.
* @mgmt_tx: completion for management frame transmit.
* @link_down: completion for the link down event a disconnect before a suspend waits for.
* @join_cancel_done: completion signaled when a cancelled join ends.
* @join_canceling: true while waiting for a cancelled join to end.
* @join_reset: the firmware was reset during that wait; the next connect
* admits a replacement once no firmware event is still queued.
* @mgmt_tx_status: status of last management frame sent to firmware.
* @mgmt_tx_id:
* @mgmt_rx_reg: registered rx mgmt frame types.
Expand All @@ -253,6 +257,9 @@ struct brcmf_cfg80211_vif {
struct list_head list;
struct completion mgmt_tx;
struct completion link_down;
struct completion join_cancel_done;
bool join_canceling;
bool join_reset;
unsigned long mgmt_tx_status;
u32 mgmt_tx_id;
u16 mgmt_rx_reg;
Expand Down
17 changes: 17 additions & 0 deletions drivers/net/wireless/broadcom/brcm80211/brcmfmac/fweh.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,23 @@ brcmf_fweh_dequeue_event(struct brcmf_fweh_info *fweh)
return event;
}

/**
* brcmf_fweh_idle() - no firmware event is queued or being handled.
*
* @drvr: driver information object.
*/
bool brcmf_fweh_idle(struct brcmf_pub *drvr)
{
struct brcmf_fweh_info *fweh = drvr->fweh;
unsigned long flags;
bool empty;

spin_lock_irqsave(&fweh->evt_q_lock, flags);
empty = list_empty(&fweh->event_q);
spin_unlock_irqrestore(&fweh->evt_q_lock, flags);
return empty && !work_busy(&fweh->event_work);
}

/**
* brcmf_fweh_event_worker() - firmware event worker.
*
Expand Down
1 change: 1 addition & 0 deletions drivers/net/wireless/broadcom/brcm80211/brcmfmac/fweh.h
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ int brcmf_fweh_register(struct brcmf_pub *drvr, enum brcmf_fweh_event_code code,
void brcmf_fweh_unregister(struct brcmf_pub *drvr,
enum brcmf_fweh_event_code code);
int brcmf_fweh_init_events(struct brcmf_if *ifp);
bool brcmf_fweh_idle(struct brcmf_pub *drvr);
int brcmf_fweh_activate_events(struct brcmf_if *ifp);
void brcmf_fweh_process_event(struct brcmf_pub *drvr,
struct brcmf_event *event_packet,
Expand Down
8 changes: 6 additions & 2 deletions net/wireless/sme.c
Original file line number Diff line number Diff line change
Expand Up @@ -1442,6 +1442,7 @@ int cfg80211_connect(struct cfg80211_registered_device *rdev,
{
struct wireless_dev *wdev = dev->ieee80211_ptr;
int err;
u8 old_ssid_len = wdev->u.client.ssid_len;

lockdep_assert_wiphy(wdev->wiphy);

Expand Down Expand Up @@ -1533,9 +1534,12 @@ int cfg80211_connect(struct cfg80211_registered_device *rdev,
wdev->connect_keys = NULL;
/*
* This could be reassoc getting refused, don't clear
* ssid_len in that case.
* ssid_len in that case. A busy driver may also still be
* completing the earlier join; the SSID equality check above
* guarantees this request did not change that join's SSID, so
* preserve its lookup key when the replacement is refused.
*/
if (!wdev->connected)
if (!wdev->connected && !(err == -EBUSY && old_ssid_len))
wdev->u.client.ssid_len = 0;
return err;
}
Expand Down
Loading
Loading