mirror of
https://github.com/outbackdingo/mt76.git
synced 2026-10-24 13:26:48 +00:00
Disabling tasklets on stopping rx/tx is wrong. If blocked tasklet
is scheduled and we remove device we will get 100% cpu usage:
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
9 root 20 0 0 0 0 R 93.8 0.0 1:47.19 ksoftirqd/0
by infinite loop in tasklet_action_common() and eventuall crash on next
mt76usb module load:
[ 2068.591964] RIP: 0010:tasklet_action_common.isra.17+0x66/0x100
[ 2068.591966] Code: 41 89 f5 eb 25 f0 48 0f ba 33 00 0f 83 b1 00 00 00 48 8b 7a 20 48 8b 42 18 e8 56 a3 b5 00 f0 80 23 fd 48 89 ea 48 85 ed 74 53 <48> 8b 2a 48 8d 5a 08 f0 48 0f ba 6a 08 01 72 0b 8b 42 10 85 c0 74
[ 2068.591968] RSP: 0018:ffff98758c34be58 EFLAGS: 00010206
[ 2068.591969] RAX: ffff98758e6966d0 RBX: ffff98756e69aef8 RCX: 0000000000000006
[ 2068.591970] RDX: 01060a053d060305 RSI: 0000000000000006 RDI: ffff98758e6966d0
[ 2068.591971] RBP: 01060a053d060305 R08: 0000000000000000 R09: 00000000000203c0
[ 2068.591971] R10: 000003ff65b34f08 R11: 0000000000000001 R12: ffff98758e6966d0
[ 2068.591972] R13: 0000000000000006 R14: 0000000000000040 R15: 0000000000000006
[ 2068.591974] FS: 0000000000000000(0000) GS:ffff98758e680000(0000) knlGS:0000000000000000
[ 2068.591975] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 2068.591975] CR2: 00002c5f73a6cc20 CR3: 00000002f920a001 CR4: 00000000003606e0
[ 2068.591977] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
[ 2068.591978] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
[ 2068.591978] Call Trace:
[ 2068.591985] __do_softirq+0xe3/0x30a
[ 2068.591989] ? sort_range+0x20/0x20
[ 2068.591990] run_ksoftirqd+0x26/0x40
[ 2068.591992] smpboot_thread_fn+0xc5/0x160
[ 2068.591995] kthread+0x112/0x130
[ 2068.591997] ? kthread_create_on_node+0x40/0x40
[ 2068.591998] ret_from_fork+0x35/0x40
[ 2068.591999] Modules linked in: ccm arc4 fuse rfcomm cmac bnep sunrpc snd_hda_codec_hdmi snd_soc_skl snd_soc_core snd_soc_acpi_intel_match snd_hda_codec_realtek snd_soc_acpi snd_hda_codec_generic snd_soc_skl_ipc snd_soc_sst_ipc snd_soc_sst_dsp snd_hda_ext_core iTCO_wdt snd_hda_intel intel_rapl iTCO_vendor_support x86_pkg_temp_thermal intel_powerclamp btusb mei_wdt coretemp btrtl snd_hda_codec btbcm btintel intel_cstate snd_hwdep intel_uncore uvcvideo snd_hda_core videobuf2_vmalloc videobuf2_memops intel_rapl_perf wmi_bmof videobuf2_v4l2 intel_wmi_thunderbolt snd_seq bluetooth joydev videobuf2_common snd_seq_device snd_pcm videodev media i2c_i801 snd_timer idma64 ecdh_generic intel_lpss_pci intel_lpss mei_me mei ucsi_acpi typec_ucsi processor_thermal_device intel_soc_dts_iosf intel_pch_thermal typec thinkpad_acpi wmi snd soundcore rfkill int3403_thermal int340x_thermal_zone int3400_thermal acpi_thermal_rel acpi_pad pcc_cpufreq uas usb_storage crc32c_intel i915 i2c_algo_bit nvme serio_raw
[ 2068.592033] drm_kms_helper e1000e nvme_core drm video ipv6 [last unloaded: cfg80211]
Fortunate thing is that this not happen frequently, as scheduling
tasklet on blocked state is very exceptional, though might happen.
Due to different RX/TX tasklet processing fix is different for those.
For RX we have to assure rx_tasklet do fail to resubmit buffers
by poisoning urb's and kill the tasklet.
For TX we need to handle all stop cases properly (suspend, module
unload, device removal).
Signed-off-by: Stanislaw Gruszka <[email protected]>
258 lines
6.3 KiB
C
258 lines
6.3 KiB
C
/*
|
|
* Copyright (C) 2018 Lorenzo Bianconi <[email protected]>
|
|
*
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
* copyright notice and this permission notice appear in all copies.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
*/
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include "mt76x2u.h"
|
|
#include "eeprom.h"
|
|
#include "../mt76x02_phy.h"
|
|
#include "../mt76x02_usb.h"
|
|
|
|
static void mt76x2u_init_dma(struct mt76x02_dev *dev)
|
|
{
|
|
u32 val = mt76_rr(dev, MT_VEND_ADDR(CFG, MT_USB_U3DMA_CFG));
|
|
|
|
val |= MT_USB_DMA_CFG_RX_DROP_OR_PAD |
|
|
MT_USB_DMA_CFG_RX_BULK_EN |
|
|
MT_USB_DMA_CFG_TX_BULK_EN;
|
|
|
|
/* disable AGGR_BULK_RX in order to receive one
|
|
* frame in each rx urb and avoid copies
|
|
*/
|
|
val &= ~MT_USB_DMA_CFG_RX_BULK_AGG_EN;
|
|
mt76_wr(dev, MT_VEND_ADDR(CFG, MT_USB_U3DMA_CFG), val);
|
|
}
|
|
|
|
static void mt76x2u_power_on_rf_patch(struct mt76x02_dev *dev)
|
|
{
|
|
mt76_set(dev, MT_VEND_ADDR(CFG, 0x130), BIT(0) | BIT(16));
|
|
udelay(1);
|
|
|
|
mt76_clear(dev, MT_VEND_ADDR(CFG, 0x1c), 0xff);
|
|
mt76_set(dev, MT_VEND_ADDR(CFG, 0x1c), 0x30);
|
|
|
|
mt76_wr(dev, MT_VEND_ADDR(CFG, 0x14), 0x484f);
|
|
udelay(1);
|
|
|
|
mt76_set(dev, MT_VEND_ADDR(CFG, 0x130), BIT(17));
|
|
usleep_range(150, 200);
|
|
|
|
mt76_clear(dev, MT_VEND_ADDR(CFG, 0x130), BIT(16));
|
|
usleep_range(50, 100);
|
|
|
|
mt76_set(dev, MT_VEND_ADDR(CFG, 0x14c), BIT(19) | BIT(20));
|
|
}
|
|
|
|
static void mt76x2u_power_on_rf(struct mt76x02_dev *dev, int unit)
|
|
{
|
|
int shift = unit ? 8 : 0;
|
|
u32 val = (BIT(1) | BIT(3) | BIT(4) | BIT(5)) << shift;
|
|
|
|
/* Enable RF BG */
|
|
mt76_set(dev, MT_VEND_ADDR(CFG, 0x130), BIT(0) << shift);
|
|
usleep_range(10, 20);
|
|
|
|
/* Enable RFDIG LDO/AFE/ABB/ADDA */
|
|
mt76_set(dev, MT_VEND_ADDR(CFG, 0x130), val);
|
|
usleep_range(10, 20);
|
|
|
|
/* Switch RFDIG power to internal LDO */
|
|
mt76_clear(dev, MT_VEND_ADDR(CFG, 0x130), BIT(2) << shift);
|
|
usleep_range(10, 20);
|
|
|
|
mt76x2u_power_on_rf_patch(dev);
|
|
|
|
mt76_set(dev, 0x530, 0xf);
|
|
}
|
|
|
|
static void mt76x2u_power_on(struct mt76x02_dev *dev)
|
|
{
|
|
u32 val;
|
|
|
|
/* Turn on WL MTCMOS */
|
|
mt76_set(dev, MT_VEND_ADDR(CFG, 0x148),
|
|
MT_WLAN_MTC_CTRL_MTCMOS_PWR_UP);
|
|
|
|
val = MT_WLAN_MTC_CTRL_STATE_UP |
|
|
MT_WLAN_MTC_CTRL_PWR_ACK |
|
|
MT_WLAN_MTC_CTRL_PWR_ACK_S;
|
|
|
|
mt76_poll(dev, MT_VEND_ADDR(CFG, 0x148), val, val, 1000);
|
|
|
|
mt76_clear(dev, MT_VEND_ADDR(CFG, 0x148), 0x7f << 16);
|
|
usleep_range(10, 20);
|
|
|
|
mt76_clear(dev, MT_VEND_ADDR(CFG, 0x148), 0xf << 24);
|
|
usleep_range(10, 20);
|
|
|
|
mt76_set(dev, MT_VEND_ADDR(CFG, 0x148), 0xf << 24);
|
|
mt76_clear(dev, MT_VEND_ADDR(CFG, 0x148), 0xfff);
|
|
|
|
/* Turn on AD/DA power down */
|
|
mt76_clear(dev, MT_VEND_ADDR(CFG, 0x1204), BIT(3));
|
|
|
|
/* WLAN function enable */
|
|
mt76_set(dev, MT_VEND_ADDR(CFG, 0x80), BIT(0));
|
|
|
|
/* Release BBP software reset */
|
|
mt76_clear(dev, MT_VEND_ADDR(CFG, 0x64), BIT(18));
|
|
|
|
mt76x2u_power_on_rf(dev, 0);
|
|
mt76x2u_power_on_rf(dev, 1);
|
|
}
|
|
|
|
static int mt76x2u_init_eeprom(struct mt76x02_dev *dev)
|
|
{
|
|
u32 val, i;
|
|
|
|
dev->mt76.eeprom.data = devm_kzalloc(dev->mt76.dev,
|
|
MT7612U_EEPROM_SIZE,
|
|
GFP_KERNEL);
|
|
dev->mt76.eeprom.size = MT7612U_EEPROM_SIZE;
|
|
if (!dev->mt76.eeprom.data)
|
|
return -ENOMEM;
|
|
|
|
for (i = 0; i + 4 <= MT7612U_EEPROM_SIZE; i += 4) {
|
|
val = mt76_rr(dev, MT_VEND_ADDR(EEPROM, i));
|
|
put_unaligned_le32(val, dev->mt76.eeprom.data + i);
|
|
}
|
|
|
|
mt76x02_eeprom_parse_hw_cap(dev);
|
|
return 0;
|
|
}
|
|
|
|
int mt76x2u_init_hardware(struct mt76x02_dev *dev)
|
|
{
|
|
int i, k, err;
|
|
|
|
mt76x2_reset_wlan(dev, true);
|
|
mt76x2u_power_on(dev);
|
|
|
|
if (!mt76x02_wait_for_mac(&dev->mt76))
|
|
return -ETIMEDOUT;
|
|
|
|
err = mt76x2u_mcu_fw_init(dev);
|
|
if (err < 0)
|
|
return err;
|
|
|
|
if (!mt76_poll_msec(dev, MT_WPDMA_GLO_CFG,
|
|
MT_WPDMA_GLO_CFG_TX_DMA_BUSY |
|
|
MT_WPDMA_GLO_CFG_RX_DMA_BUSY, 0, 100))
|
|
return -EIO;
|
|
|
|
/* wait for asic ready after fw load. */
|
|
if (!mt76x02_wait_for_mac(&dev->mt76))
|
|
return -ETIMEDOUT;
|
|
|
|
mt76x2u_init_dma(dev);
|
|
|
|
err = mt76x2u_mcu_init(dev);
|
|
if (err < 0)
|
|
return err;
|
|
|
|
err = mt76x2u_mac_reset(dev);
|
|
if (err < 0)
|
|
return err;
|
|
|
|
mt76x02_mac_setaddr(dev, dev->mt76.eeprom.data + MT_EE_MAC_ADDR);
|
|
dev->mt76.rxfilter = mt76_rr(dev, MT_RX_FILTR_CFG);
|
|
|
|
if (!mt76x02_wait_for_txrx_idle(&dev->mt76))
|
|
return -ETIMEDOUT;
|
|
|
|
/* reset wcid table */
|
|
for (i = 0; i < 256; i++)
|
|
mt76x02_mac_wcid_setup(dev, i, 0, NULL);
|
|
|
|
/* reset shared key table and pairwise key table */
|
|
for (i = 0; i < 16; i++) {
|
|
for (k = 0; k < 4; k++)
|
|
mt76x02_mac_shared_key_setup(dev, i, k, NULL);
|
|
}
|
|
|
|
mt76x02u_init_beacon_config(dev);
|
|
|
|
mt76_rmw(dev, MT_US_CYC_CFG, MT_US_CYC_CNT, 0x1e);
|
|
mt76_wr(dev, MT_TXOP_CTRL_CFG, 0x583f);
|
|
|
|
err = mt76x2_mcu_load_cr(dev, MT_RF_BBP_CR, 0, 0);
|
|
if (err < 0)
|
|
return err;
|
|
|
|
mt76x02_phy_set_rxpath(dev);
|
|
mt76x02_phy_set_txdac(dev);
|
|
|
|
return mt76x2u_mac_stop(dev);
|
|
}
|
|
|
|
int mt76x2u_register_device(struct mt76x02_dev *dev)
|
|
{
|
|
struct ieee80211_hw *hw = mt76_hw(dev);
|
|
int err;
|
|
|
|
INIT_DELAYED_WORK(&dev->cal_work, mt76x2u_phy_calibrate);
|
|
mt76x02_init_device(dev);
|
|
|
|
err = mt76x2u_init_eeprom(dev);
|
|
if (err < 0)
|
|
return err;
|
|
|
|
err = mt76u_alloc_queues(&dev->mt76);
|
|
if (err < 0)
|
|
goto fail;
|
|
|
|
err = mt76x2u_init_hardware(dev);
|
|
if (err < 0)
|
|
goto fail;
|
|
|
|
err = mt76_register_device(&dev->mt76, true, mt76x02_rates,
|
|
ARRAY_SIZE(mt76x02_rates));
|
|
if (err)
|
|
goto fail;
|
|
|
|
/* check hw sg support in order to enable AMSDU */
|
|
if (dev->mt76.usb.sg_en)
|
|
hw->max_tx_fragments = MT_SG_MAX_SIZE;
|
|
else
|
|
hw->max_tx_fragments = 1;
|
|
|
|
set_bit(MT76_STATE_INITIALIZED, &dev->mt76.state);
|
|
|
|
mt76x02_init_debugfs(dev);
|
|
mt76x2_init_txpower(dev, &dev->mt76.sband_2g.sband);
|
|
mt76x2_init_txpower(dev, &dev->mt76.sband_5g.sband);
|
|
|
|
return 0;
|
|
|
|
fail:
|
|
mt76x2u_cleanup(dev);
|
|
return err;
|
|
}
|
|
|
|
void mt76x2u_stop_hw(struct mt76x02_dev *dev)
|
|
{
|
|
cancel_delayed_work_sync(&dev->cal_work);
|
|
cancel_delayed_work_sync(&dev->mt76.mac_work);
|
|
mt76x2u_mac_stop(dev);
|
|
}
|
|
|
|
void mt76x2u_cleanup(struct mt76x02_dev *dev)
|
|
{
|
|
mt76x02_mcu_set_radio_state(dev, false);
|
|
mt76x2u_stop_hw(dev);
|
|
mt76u_queues_deinit(&dev->mt76);
|
|
}
|