This is for B.2, and it also covers Fibocom F.3. An in-flight IRQ can requeue CLDMA work after the queues are stopped, so the worker touches rings that teardown has already freed. Gate the ISR on cldma_irq_enabled. Queue TX/RX work, and let workers re-queue or unmask L2, only while the queue is active, holding cldma_lock for that check. Do not nest that lock around the TX empty handler. Look up pci_irq_vector(pdev, phy_interrupt_id) at stop/reset and synchronize_irq() before cancel_work_sync(). t7xx_cldma_init() runs before MSI-X allocation, so the vector must not be cached there. phy_interrupt_id is already the in-tree MSI-X index; do not apply the vendor PCIe OFFSET. t7xx_cldma_disable_irq() already clears the MAC mask. Skip t7xx_pcie_mac_set_int() at the end of a racing ISR so stop cannot be undone by an empty MSI. Always rebuild rings on switch_cfg: callers use it as reinit, and the first handshake would skip late_init if an unchanged cfg_id returned early. Signed-off-by: Wanquan Zhong <zwq2…@163.com> --- drivers/net/wwan/t7xx/t7xx_hif_cldma.c | 110 +++++++++++++++++++------ drivers/net/wwan/t7xx/t7xx_hif_cldma.h | 2 + 2 files changed, 86 insertions(+), 26 deletions(-) diff --git a/drivers/net/wwan/t7xx/t7xx_hif_cldma.c b/drivers/net/wwan/t7xx/t7xx_hif_cldma.c index 2917cee9b802..622cb8ee0282 100644 --- a/drivers/net/wwan/t7xx/t7xx_hif_cldma.c +++ b/drivers/net/wwan/t7xx/t7xx_hif_cldma.c @@ -24,6 +24,7 @@ #include <linux/dma-mapping.h> #include <linux/dma-direction.h> #include <linux/gfp.h> +#include <linux/interrupt.h> #include <linux/io.h> #include <linux/io-64-nonatomic-lo-hi.h> #include <linux/iopoll.h> @@ -239,17 +240,27 @@ static void t7xx_cldma_rx_done(struct work_struct *work) { struct cldma_queue *queue = container_of(work, struct cldma_queue, cldma_work); struct cldma_ctrl *md_ctrl = queue->md_ctrl; + unsigned long flags; int value; value = t7xx_cldma_gpd_rx_collect(queue, queue->budget); - if (value && md_ctrl->rxq_active & BIT(queue->index)) { - queue_work(queue->worker, &queue->cldma_work); - return; + if (value) { + spin_lock_irqsave(&md_ctrl->cldma_lock, flags); + if (md_ctrl->rxq_active & BIT(queue->index)) { + queue_work(queue->worker, &queue->cldma_work); + spin_unlock_irqrestore(&md_ctrl->cldma_lock, flags); + return; + } + spin_unlock_irqrestore(&md_ctrl->cldma_lock, flags); } - t7xx_cldma_clear_ip_busy(&md_ctrl->hw_info); - t7xx_cldma_hw_irq_en_txrx(&md_ctrl->hw_info, queue->index, MTK_RX); - t7xx_cldma_hw_irq_en_eq(&md_ctrl->hw_info, queue->index, MTK_RX); + spin_lock_irqsave(&md_ctrl->cldma_lock, flags); + if (md_ctrl->rxq_active & BIT(queue->index)) { + t7xx_cldma_clear_ip_busy(&md_ctrl->hw_info); + t7xx_cldma_hw_irq_en_txrx(&md_ctrl->hw_info, queue->index, MTK_RX); + t7xx_cldma_hw_irq_en_eq(&md_ctrl->hw_info, queue->index, MTK_RX); + } + spin_unlock_irqrestore(&md_ctrl->cldma_lock, flags); pm_runtime_put_autosuspend(md_ctrl->dev); } @@ -349,8 +360,13 @@ static void t7xx_cldma_tx_done(struct work_struct *work) if (l2_tx_int & BIT(queue->index)) { t7xx_cldma_hw_tx_done(hw_info, BIT(queue->index)); - queue_work(queue->worker, &queue->cldma_work); - return; + spin_lock_irqsave(&md_ctrl->cldma_lock, flags); + if (md_ctrl->txq_active & BIT(queue->index)) { + queue_work(queue->worker, &queue->cldma_work); + spin_unlock_irqrestore(&md_ctrl->cldma_lock, flags); + return; + } + spin_unlock_irqrestore(&md_ctrl->cldma_lock, flags); } spin_lock_irqsave(&md_ctrl->cldma_lock, flags); @@ -535,20 +551,37 @@ static void t7xx_cldma_txq_init(struct cldma_queue *queue) static void t7xx_cldma_enable_irq(struct cldma_ctrl *md_ctrl) { - t7xx_pcie_mac_set_int(md_ctrl->t7xx_dev, md_ctrl->hw_info.phy_interrupt_id); + if (atomic_cmpxchg(&md_ctrl->cldma_irq_enabled, 0, 1) == 0) + t7xx_pcie_mac_set_int(md_ctrl->t7xx_dev, md_ctrl->hw_info.phy_interrupt_id); } static void t7xx_cldma_disable_irq(struct cldma_ctrl *md_ctrl) { - t7xx_pcie_mac_clear_int(md_ctrl->t7xx_dev, md_ctrl->hw_info.phy_interrupt_id); + if (atomic_cmpxchg(&md_ctrl->cldma_irq_enabled, 1, 0) == 1) + t7xx_pcie_mac_clear_int(md_ctrl->t7xx_dev, md_ctrl->hw_info.phy_interrupt_id); +} + +static void t7xx_cldma_synchronize_irq(struct cldma_ctrl *md_ctrl) +{ + int irq; + + /* Look up after pci_alloc_irq_vectors(); t7xx_cldma_init() runs first. */ + irq = pci_irq_vector(md_ctrl->t7xx_dev->pdev, + md_ctrl->hw_info.phy_interrupt_id); + if (irq >= 0) + synchronize_irq(irq); } static void t7xx_cldma_irq_work_cb(struct cldma_ctrl *md_ctrl) { unsigned long l2_tx_int_msk, l2_rx_int_msk, l2_tx_int, l2_rx_int, val; struct t7xx_cldma_hw *hw_info = &md_ctrl->hw_info; + unsigned long flags; int i; + if (!atomic_read(&md_ctrl->cldma_irq_enabled)) + return; + /* L2 raw interrupt status */ l2_tx_int = ioread32(hw_info->ap_pdn_base + REG_CLDMA_L2TISAR0); l2_rx_int = ioread32(hw_info->ap_pdn_base + REG_CLDMA_L2RISAR0); @@ -570,12 +603,16 @@ static void t7xx_cldma_irq_work_cb(struct cldma_ctrl *md_ctrl) if (l2_tx_int & (TXRX_STATUS_BITMASK | EMPTY_STATUS_BITMASK)) { for_each_set_bit(i, &l2_tx_int, L2_INT_BIT_COUNT) { if (i < CLDMA_TXQ_NUM) { - pm_runtime_get(md_ctrl->dev); - t7xx_cldma_hw_irq_dis_eq(hw_info, i, MTK_TX); - t7xx_cldma_hw_irq_dis_txrx(hw_info, i, MTK_TX); - queue_work(md_ctrl->txq[i].worker, - &md_ctrl->txq[i].cldma_work); - } else { + spin_lock_irqsave(&md_ctrl->cldma_lock, flags); + if (md_ctrl->txq_active & BIT(i)) { + pm_runtime_get(md_ctrl->dev); + t7xx_cldma_hw_irq_dis_eq(hw_info, i, MTK_TX); + t7xx_cldma_hw_irq_dis_txrx(hw_info, i, MTK_TX); + queue_work(md_ctrl->txq[i].worker, + &md_ctrl->txq[i].cldma_work); + } + spin_unlock_irqrestore(&md_ctrl->cldma_lock, flags); + } else if (md_ctrl->txq_active & BIT(i - CLDMA_TXQ_NUM)) { t7xx_cldma_txq_empty_hndl(&md_ctrl->txq[i - CLDMA_TXQ_NUM]); } } @@ -595,10 +632,15 @@ static void t7xx_cldma_irq_work_cb(struct cldma_ctrl *md_ctrl) if (l2_rx_int & (TXRX_STATUS_BITMASK | EMPTY_STATUS_BITMASK)) { l2_rx_int |= l2_rx_int >> CLDMA_RXQ_NUM; for_each_set_bit(i, &l2_rx_int, CLDMA_RXQ_NUM) { - pm_runtime_get(md_ctrl->dev); - t7xx_cldma_hw_irq_dis_eq(hw_info, i, MTK_RX); - t7xx_cldma_hw_irq_dis_txrx(hw_info, i, MTK_RX); - queue_work(md_ctrl->rxq[i].worker, &md_ctrl->rxq[i].cldma_work); + spin_lock_irqsave(&md_ctrl->cldma_lock, flags); + if (md_ctrl->rxq_active & BIT(i)) { + pm_runtime_get(md_ctrl->dev); + t7xx_cldma_hw_irq_dis_eq(hw_info, i, MTK_RX); + t7xx_cldma_hw_irq_dis_txrx(hw_info, i, MTK_RX); + queue_work(md_ctrl->rxq[i].worker, + &md_ctrl->rxq[i].cldma_work); + } + spin_unlock_irqrestore(&md_ctrl->cldma_lock, flags); } } } @@ -633,15 +675,20 @@ static bool t7xx_cldma_qs_are_active(struct cldma_ctrl *md_ctrl) int t7xx_cldma_stop(struct cldma_ctrl *md_ctrl) { struct t7xx_cldma_hw *hw_info = &md_ctrl->hw_info; + unsigned long flags; bool active; int i, ret; + spin_lock_irqsave(&md_ctrl->cldma_lock, flags); md_ctrl->rxq_active = 0; - t7xx_cldma_hw_stop_all_qs(hw_info, MTK_RX); md_ctrl->txq_active = 0; - t7xx_cldma_hw_stop_all_qs(hw_info, MTK_TX); md_ctrl->txq_started = 0; + spin_unlock_irqrestore(&md_ctrl->cldma_lock, flags); + + t7xx_cldma_hw_stop_all_qs(hw_info, MTK_RX); + t7xx_cldma_hw_stop_all_qs(hw_info, MTK_TX); t7xx_cldma_disable_irq(md_ctrl); + t7xx_cldma_synchronize_irq(md_ctrl); t7xx_cldma_hw_stop(hw_info, MTK_RX); t7xx_cldma_hw_stop(hw_info, MTK_TX); t7xx_cldma_hw_tx_done(hw_info, CLDMA_L2TISAR0_ALL_INT_MASK); @@ -649,10 +696,10 @@ int t7xx_cldma_stop(struct cldma_ctrl *md_ctrl) if (md_ctrl->is_late_init) { for (i = 0; i < CLDMA_TXQ_NUM; i++) - flush_work(&md_ctrl->txq[i].cldma_work); + cancel_work_sync(&md_ctrl->txq[i].cldma_work); for (i = 0; i < CLDMA_RXQ_NUM; i++) - flush_work(&md_ctrl->rxq[i].cldma_work); + cancel_work_sync(&md_ctrl->rxq[i].cldma_work); } ret = read_poll_timeout(t7xx_cldma_qs_are_active, active, !active, CHECK_Q_STOP_STEP_US, @@ -689,9 +736,12 @@ void t7xx_cldma_reset(struct cldma_ctrl *md_ctrl) spin_lock_irqsave(&md_ctrl->cldma_lock, flags); md_ctrl->txq_active = 0; md_ctrl->rxq_active = 0; - t7xx_cldma_disable_irq(md_ctrl); + md_ctrl->txq_started = 0; spin_unlock_irqrestore(&md_ctrl->cldma_lock, flags); + t7xx_cldma_disable_irq(md_ctrl); + t7xx_cldma_synchronize_irq(md_ctrl); + for (i = 0; i < CLDMA_TXQ_NUM; i++) { cancel_work_sync(&md_ctrl->txq[i].cldma_work); @@ -1262,7 +1312,8 @@ static irqreturn_t t7xx_cldma_isr_handler(int irq, void *data) t7xx_pcie_mac_clear_int(md_ctrl->t7xx_dev, interrupt); t7xx_cldma_irq_work_cb(md_ctrl); t7xx_pcie_mac_clear_int_status(md_ctrl->t7xx_dev, interrupt); - t7xx_pcie_mac_set_int(md_ctrl->t7xx_dev, interrupt); + if (atomic_read(&md_ctrl->cldma_irq_enabled)) + t7xx_pcie_mac_set_int(md_ctrl->t7xx_dev, interrupt); return IRQ_HANDLED; } @@ -1305,6 +1356,7 @@ int t7xx_cldma_init(struct cldma_ctrl *md_ctrl) md_ctrl->txq_active = 0; md_ctrl->rxq_active = 0; md_ctrl->is_late_init = false; + atomic_set(&md_ctrl->cldma_irq_enabled, 0); ret = t7xx_cldma_pm_init(md_ctrl); if (ret) @@ -1351,6 +1403,12 @@ int t7xx_cldma_init(struct cldma_ctrl *md_ctrl) void t7xx_cldma_switch_cfg(struct cldma_ctrl *md_ctrl, enum cldma_cfg cfg_id) { + if (t7xx_cldma_stop(md_ctrl)) { + dev_err(md_ctrl->dev, "Stop CLDMA%d before switching config failed\n", + md_ctrl->hif_id); + return; + } + t7xx_cldma_late_release(md_ctrl); t7xx_cldma_adjust_config(md_ctrl, cfg_id); t7xx_cldma_late_init(md_ctrl); diff --git a/drivers/net/wwan/t7xx/t7xx_hif_cldma.h b/drivers/net/wwan/t7xx/t7xx_hif_cldma.h index 9d0107e18a7b..d8fc28b1814f 100644 --- a/drivers/net/wwan/t7xx/t7xx_hif_cldma.h +++ b/drivers/net/wwan/t7xx/t7xx_hif_cldma.h @@ -18,6 +18,7 @@ #ifndef __T7XX_HIF_CLDMA_H__ #define __T7XX_HIF_CLDMA_H__ +#include <linux/atomic.h> #include <linux/bits.h> #include <linux/device.h> #include <linux/dmapool.h> @@ -111,6 +112,7 @@ struct cldma_ctrl { struct md_pm_entity *pm_entity; struct t7xx_cldma_hw hw_info; bool is_late_init; + atomic_t cldma_irq_enabled; }; #define CLDMA_Q_IDX_DUMP 1
-- 2.53.0