From: Stanislaw Gruszka Date: Mon, 19 Dec 2016 10:52:57 +0000 (+0100) Subject: rt2x00: add mutex to synchronize config and link tuner X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=c7d1c77781f468c639867d324d4e490139cd4c7f;p=GitHub%2FLineageOS%2Fandroid_kernel_motorola_exynos9610.git rt2x00: add mutex to synchronize config and link tuner Do not perform mac80211 config and link_tuner at the same time, this can possibly result in wrong RF or BBP configuration. Signed-off-by: Stanislaw Gruszka Signed-off-by: Kalle Valo --- diff --git a/drivers/net/wireless/ralink/rt2x00/rt2x00.h b/drivers/net/wireless/ralink/rt2x00/rt2x00.h index 92bb8be9f319..034a07273038 100644 --- a/drivers/net/wireless/ralink/rt2x00/rt2x00.h +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00.h @@ -833,6 +833,10 @@ struct rt2x00_dev { */ struct mutex csr_mutex; + /* + * Mutex to synchronize config and link tuner. + */ + struct mutex conf_mutex; /* * Current packet filter configuration for the device. * This contains all currently active FIF_* flags send diff --git a/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c b/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c index 6afd21542c7d..8fcbc8dc94c1 100644 --- a/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c @@ -1313,6 +1313,7 @@ int rt2x00lib_probe_dev(struct rt2x00_dev *rt2x00dev) spin_lock_init(&rt2x00dev->irqmask_lock); mutex_init(&rt2x00dev->csr_mutex); + mutex_init(&rt2x00dev->conf_mutex); INIT_LIST_HEAD(&rt2x00dev->bar_list); spin_lock_init(&rt2x00dev->bar_list_lock); diff --git a/drivers/net/wireless/ralink/rt2x00/rt2x00link.c b/drivers/net/wireless/ralink/rt2x00/rt2x00link.c index 73cbf23b17ef..2010a7715f21 100644 --- a/drivers/net/wireless/ralink/rt2x00/rt2x00link.c +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00link.c @@ -363,6 +363,9 @@ static void rt2x00link_tuner(struct work_struct *work) test_bit(DEVICE_STATE_SCANNING, &rt2x00dev->flags)) return; + /* Do not race with rt2x00mac_config(). */ + mutex_lock(&rt2x00dev->conf_mutex); + if (rt2x00dev->intf_sta_count) rt2x00link_tuner_sta(rt2x00dev, link); @@ -375,6 +378,8 @@ static void rt2x00link_tuner(struct work_struct *work) (link->count % (VCO_SECONDS / LINK_TUNE_SECONDS)) == 0) rt2x00dev->ops->lib->vco_calibration(rt2x00dev); + mutex_unlock(&rt2x00dev->conf_mutex); + /* * Increase tuner counter, and reschedule the next link tuner run. */ diff --git a/drivers/net/wireless/ralink/rt2x00/rt2x00mac.c b/drivers/net/wireless/ralink/rt2x00/rt2x00mac.c index d4b50fb948ee..3cc1384ed2fc 100644 --- a/drivers/net/wireless/ralink/rt2x00/rt2x00mac.c +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00mac.c @@ -320,6 +320,9 @@ int rt2x00mac_config(struct ieee80211_hw *hw, u32 changed) */ rt2x00queue_stop_queue(rt2x00dev->rx); + /* Do not race with with link tuner. */ + mutex_lock(&rt2x00dev->conf_mutex); + /* * When we've just turned on the radio, we want to reprogram * everything to ensure a consistent state @@ -335,6 +338,8 @@ int rt2x00mac_config(struct ieee80211_hw *hw, u32 changed) */ rt2x00lib_config_antenna(rt2x00dev, rt2x00dev->default_ant); + mutex_unlock(&rt2x00dev->conf_mutex); + /* Turn RX back on */ rt2x00queue_start_queue(rt2x00dev->rx);