Skip to content

Commit

Permalink
wifi: wilc1000: convert list management to RCU
Browse files Browse the repository at this point in the history
wilc1000 driver currently uses SRCU API to manage vif list. There is no
real reason to use SRCU API here, and it makes things slightly more
complicated (we need to handle a SRCU index as well as a srcu_struct) than
classical RCU.

Switch SRCU APIs to RCU APIs.

Signed-off-by: Alexis Lothoré <alexis.lothore@bootlin.com>
Signed-off-by: Kalle Valo <kvalo@kernel.org>
Link: https://msgid.link/20240410-wilc_srcu_to_rcu-v1-2-a9ff5b10feaa@bootlin.com
  • Loading branch information
Alexis Lothoré authored and Kalle Valo committed Apr 16, 2024
1 parent 35aee01 commit f236464
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 64 deletions.
41 changes: 17 additions & 24 deletions drivers/net/wireless/microchip/wilc1000/cfg80211.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,11 @@ static int set_channel(struct wiphy *wiphy,
struct wilc_vif *vif;
u32 channelnum;
int result;
int srcu_idx;

srcu_idx = srcu_read_lock(&wl->srcu);
rcu_read_lock();
vif = wilc_get_wl_to_vif(wl);
if (IS_ERR(vif)) {
srcu_read_unlock(&wl->srcu, srcu_idx);
rcu_read_unlock();
return PTR_ERR(vif);
}

Expand All @@ -253,7 +252,7 @@ static int set_channel(struct wiphy *wiphy,
if (result)
netdev_err(vif->ndev, "Error in setting channel\n");

srcu_read_unlock(&wl->srcu, srcu_idx);
rcu_read_unlock();
return result;
}

Expand Down Expand Up @@ -806,9 +805,8 @@ static int set_wiphy_params(struct wiphy *wiphy, u32 changed)
struct wilc *wl = wiphy_priv(wiphy);
struct wilc_vif *vif;
struct wilc_priv *priv;
int srcu_idx;

srcu_idx = srcu_read_lock(&wl->srcu);
rcu_read_lock();
vif = wilc_get_wl_to_vif(wl);
if (IS_ERR(vif))
goto out;
Expand Down Expand Up @@ -863,7 +861,7 @@ static int set_wiphy_params(struct wiphy *wiphy, u32 changed)
netdev_err(priv->dev, "Error in setting WIPHY PARAMS\n");

out:
srcu_read_unlock(&wl->srcu, srcu_idx);
rcu_read_unlock();
return ret;
}

Expand Down Expand Up @@ -1539,33 +1537,32 @@ static struct wireless_dev *add_virtual_intf(struct wiphy *wiphy,

if (type == NL80211_IFTYPE_MONITOR) {
struct net_device *ndev;
int srcu_idx;

srcu_idx = srcu_read_lock(&wl->srcu);
rcu_read_lock();
vif = wilc_get_vif_from_type(wl, WILC_AP_MODE);
if (!vif) {
vif = wilc_get_vif_from_type(wl, WILC_GO_MODE);
if (!vif) {
srcu_read_unlock(&wl->srcu, srcu_idx);
rcu_read_unlock();
goto validate_interface;
}
}

if (vif->monitor_flag) {
srcu_read_unlock(&wl->srcu, srcu_idx);
rcu_read_unlock();
goto validate_interface;
}

ndev = wilc_wfi_init_mon_interface(wl, name, vif->ndev);
if (ndev) {
vif->monitor_flag = 1;
} else {
srcu_read_unlock(&wl->srcu, srcu_idx);
rcu_read_unlock();
return ERR_PTR(-EINVAL);
}

wdev = &vif->priv.wdev;
srcu_read_unlock(&wl->srcu, srcu_idx);
rcu_read_unlock();
return wdev;
}

Expand Down Expand Up @@ -1613,7 +1610,7 @@ static int del_virtual_intf(struct wiphy *wiphy, struct wireless_dev *wdev)
list_del_rcu(&vif->list);
wl->vif_num--;
mutex_unlock(&wl->vif_mutex);
synchronize_srcu(&wl->srcu);
synchronize_rcu();
return 0;
}

Expand All @@ -1638,36 +1635,34 @@ static void wilc_set_wakeup(struct wiphy *wiphy, bool enabled)
{
struct wilc *wl = wiphy_priv(wiphy);
struct wilc_vif *vif;
int srcu_idx;

srcu_idx = srcu_read_lock(&wl->srcu);
rcu_read_lock();
vif = wilc_get_wl_to_vif(wl);
if (IS_ERR(vif)) {
srcu_read_unlock(&wl->srcu, srcu_idx);
rcu_read_unlock();
return;
}

netdev_info(vif->ndev, "cfg set wake up = %d\n", enabled);
wilc_set_wowlan_trigger(vif, enabled);
srcu_read_unlock(&wl->srcu, srcu_idx);
rcu_read_unlock();
}

static int set_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev,
enum nl80211_tx_power_setting type, int mbm)
{
int ret;
int srcu_idx;
s32 tx_power = MBM_TO_DBM(mbm);
struct wilc *wl = wiphy_priv(wiphy);
struct wilc_vif *vif;

if (!wl->initialized)
return -EIO;

srcu_idx = srcu_read_lock(&wl->srcu);
rcu_read_lock();
vif = wilc_get_wl_to_vif(wl);
if (IS_ERR(vif)) {
srcu_read_unlock(&wl->srcu, srcu_idx);
rcu_read_unlock();
return -EINVAL;
}

Expand All @@ -1679,7 +1674,7 @@ static int set_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev,
ret = wilc_set_tx_power(vif, tx_power);
if (ret)
netdev_err(vif->ndev, "Failed to set tx power\n");
srcu_read_unlock(&wl->srcu, srcu_idx);
rcu_read_unlock();

return ret;
}
Expand Down Expand Up @@ -1762,7 +1757,6 @@ static void wlan_init_locks(struct wilc *wl)
init_completion(&wl->cfg_event);
init_completion(&wl->sync_event);
init_completion(&wl->txq_thread_started);
init_srcu_struct(&wl->srcu);
}

void wlan_deinit_locks(struct wilc *wilc)
Expand All @@ -1773,7 +1767,6 @@ void wlan_deinit_locks(struct wilc *wilc)
mutex_destroy(&wilc->txq_add_to_head_cs);
mutex_destroy(&wilc->vif_mutex);
mutex_destroy(&wilc->deinit_lock);
cleanup_srcu_struct(&wilc->srcu);
}

int wilc_cfg80211_init(struct wilc **wilc, struct device *dev, int io_type,
Expand Down
15 changes: 6 additions & 9 deletions drivers/net/wireless/microchip/wilc1000/hif.c
Original file line number Diff line number Diff line change
Expand Up @@ -1570,12 +1570,11 @@ void wilc_network_info_received(struct wilc *wilc, u8 *buffer, u32 length)
struct host_if_drv *hif_drv;
struct host_if_msg *msg;
struct wilc_vif *vif;
int srcu_idx;
int result;
int id;

id = get_unaligned_le32(&buffer[length - 4]);
srcu_idx = srcu_read_lock(&wilc->srcu);
rcu_read_lock();
vif = wilc_get_vif_from_idx(wilc, id);
if (!vif)
goto out;
Expand Down Expand Up @@ -1607,22 +1606,21 @@ void wilc_network_info_received(struct wilc *wilc, u8 *buffer, u32 length)
kfree(msg);
}
out:
srcu_read_unlock(&wilc->srcu, srcu_idx);
rcu_read_unlock();
}

void wilc_gnrl_async_info_received(struct wilc *wilc, u8 *buffer, u32 length)
{
struct host_if_drv *hif_drv;
struct host_if_msg *msg;
struct wilc_vif *vif;
int srcu_idx;
int result;
int id;

mutex_lock(&wilc->deinit_lock);

id = get_unaligned_le32(&buffer[length - 4]);
srcu_idx = srcu_read_lock(&wilc->srcu);
rcu_read_lock();
vif = wilc_get_vif_from_idx(wilc, id);
if (!vif)
goto out;
Expand All @@ -1649,20 +1647,19 @@ void wilc_gnrl_async_info_received(struct wilc *wilc, u8 *buffer, u32 length)
kfree(msg);
}
out:
srcu_read_unlock(&wilc->srcu, srcu_idx);
rcu_read_unlock();
mutex_unlock(&wilc->deinit_lock);
}

void wilc_scan_complete_received(struct wilc *wilc, u8 *buffer, u32 length)
{
struct host_if_drv *hif_drv;
struct wilc_vif *vif;
int srcu_idx;
int result;
int id;

id = get_unaligned_le32(&buffer[length - 4]);
srcu_idx = srcu_read_lock(&wilc->srcu);
rcu_read_lock();
vif = wilc_get_vif_from_idx(wilc, id);
if (!vif)
goto out;
Expand All @@ -1687,7 +1684,7 @@ void wilc_scan_complete_received(struct wilc *wilc, u8 *buffer, u32 length)
}
}
out:
srcu_read_unlock(&wilc->srcu, srcu_idx);
rcu_read_unlock();
}

int wilc_remain_on_channel(struct wilc_vif *vif, u64 cookie, u16 chan,
Expand Down
43 changes: 18 additions & 25 deletions drivers/net/wireless/microchip/wilc1000/netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,30 +127,28 @@ void wilc_wlan_set_bssid(struct net_device *wilc_netdev, const u8 *bssid,

int wilc_wlan_get_num_conn_ifcs(struct wilc *wilc)
{
int srcu_idx;
u8 ret_val = 0;
struct wilc_vif *vif;

srcu_idx = srcu_read_lock(&wilc->srcu);
rcu_read_lock();
wilc_for_each_vif(wilc, vif) {
if (!is_zero_ether_addr(vif->bssid))
ret_val++;
}
srcu_read_unlock(&wilc->srcu, srcu_idx);
rcu_read_unlock();
return ret_val;
}

static void wilc_wake_tx_queues(struct wilc *wl)
{
int srcu_idx;
struct wilc_vif *ifc;

srcu_idx = srcu_read_lock(&wl->srcu);
rcu_read_lock();
wilc_for_each_vif(wl, ifc) {
if (ifc->mac_opened && netif_queue_stopped(ifc->ndev))
netif_wake_queue(ifc->ndev);
}
srcu_read_unlock(&wl->srcu, srcu_idx);
rcu_read_unlock();
}

static int wilc_txq_task(void *vp)
Expand Down Expand Up @@ -655,7 +653,6 @@ static int wilc_set_mac_addr(struct net_device *dev, void *p)
struct sockaddr *addr = (struct sockaddr *)p;
unsigned char mac_addr[ETH_ALEN];
struct wilc_vif *tmp_vif;
int srcu_idx;

if (!is_valid_ether_addr(addr->sa_data))
return -EADDRNOTAVAIL;
Expand All @@ -667,19 +664,19 @@ static int wilc_set_mac_addr(struct net_device *dev, void *p)

/* Verify MAC Address is not already in use: */

srcu_idx = srcu_read_lock(&wilc->srcu);
rcu_read_lock();
wilc_for_each_vif(wilc, tmp_vif) {
wilc_get_mac_address(tmp_vif, mac_addr);
if (ether_addr_equal(addr->sa_data, mac_addr)) {
if (vif != tmp_vif) {
srcu_read_unlock(&wilc->srcu, srcu_idx);
rcu_read_unlock();
return -EADDRNOTAVAIL;
}
srcu_read_unlock(&wilc->srcu, srcu_idx);
rcu_read_unlock();
return 0;
}
}
srcu_read_unlock(&wilc->srcu, srcu_idx);
rcu_read_unlock();

result = wilc_set_mac_address(vif, (u8 *)addr->sa_data);
if (result)
Expand Down Expand Up @@ -767,15 +764,14 @@ netdev_tx_t wilc_mac_xmit(struct sk_buff *skb, struct net_device *ndev)
wilc_tx_complete);

if (queue_count > FLOW_CONTROL_UPPER_THRESHOLD) {
int srcu_idx;
struct wilc_vif *vif;

srcu_idx = srcu_read_lock(&wilc->srcu);
rcu_read_lock();
wilc_for_each_vif(wilc, vif) {
if (vif->mac_opened)
netif_stop_queue(vif->ndev);
}
srcu_read_unlock(&wilc->srcu, srcu_idx);
rcu_read_unlock();
}

return NETDEV_TX_OK;
Expand Down Expand Up @@ -819,13 +815,12 @@ void wilc_frmw_to_host(struct wilc *wilc, u8 *buff, u32 size,
unsigned int frame_len = 0;
struct wilc_vif *vif;
struct sk_buff *skb;
int srcu_idx;
int stats;

if (!wilc)
return;

srcu_idx = srcu_read_lock(&wilc->srcu);
rcu_read_lock();
wilc_netdev = get_if_handler(wilc, buff);
if (!wilc_netdev)
goto out;
Expand Down Expand Up @@ -853,15 +848,14 @@ void wilc_frmw_to_host(struct wilc *wilc, u8 *buff, u32 size,
netdev_dbg(wilc_netdev, "netif_rx ret value is: %d\n", stats);
}
out:
srcu_read_unlock(&wilc->srcu, srcu_idx);
rcu_read_unlock();
}

void wilc_wfi_mgmt_rx(struct wilc *wilc, u8 *buff, u32 size, bool is_auth)
{
int srcu_idx;
struct wilc_vif *vif;

srcu_idx = srcu_read_lock(&wilc->srcu);
rcu_read_lock();
wilc_for_each_vif(wilc, vif) {
struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buff;
u16 type = le16_to_cpup((__le16 *)buff);
Expand All @@ -882,7 +876,7 @@ void wilc_wfi_mgmt_rx(struct wilc *wilc, u8 *buff, u32 size, bool is_auth)
if (vif->monitor_flag)
wilc_wfi_monitor_rx(wilc->monitor_dev, buff, size);
}
srcu_read_unlock(&wilc->srcu, srcu_idx);
rcu_read_unlock();
}

static const struct net_device_ops wilc_netdev_ops = {
Expand Down Expand Up @@ -912,7 +906,7 @@ void wilc_netdev_cleanup(struct wilc *wilc)
list_del_rcu(&vif->list);
wilc->vif_num--;
mutex_unlock(&wilc->vif_mutex);
synchronize_srcu(&wilc->srcu);
synchronize_rcu();
if (vif->ndev)
unregister_netdev(vif->ndev);
}
Expand All @@ -931,16 +925,15 @@ static u8 wilc_get_available_idx(struct wilc *wl)
{
int idx = 0;
struct wilc_vif *vif;
int srcu_idx;

srcu_idx = srcu_read_lock(&wl->srcu);
rcu_read_lock();
wilc_for_each_vif(wl, vif) {
if (vif->idx == 0)
idx = 1;
else
idx = 0;
}
srcu_read_unlock(&wl->srcu, srcu_idx);
rcu_read_unlock();
return idx;
}

Expand Down Expand Up @@ -990,7 +983,7 @@ struct wilc_vif *wilc_netdev_ifc_init(struct wilc *wl, const char *name,
list_add_tail_rcu(&vif->list, &wl->vif_list);
wl->vif_num += 1;
mutex_unlock(&wl->vif_mutex);
synchronize_srcu(&wl->srcu);
synchronize_rcu();

return vif;

Expand Down
Loading

0 comments on commit f236464

Please sign in to comment.