From f7bbb80f22166387248b26353336a8300f05e555 Mon Sep 17 00:00:00 2001 From: Lorenzo Bianconi Date: Sun, 9 Sep 2018 23:57:57 +0200 Subject: [PATCH] mt76: introduce mmio data structure in mt76_dev Introduce mt76_mmio data structure in mt76_dev and move mt76x2_mcu in mt76_mmio. This is a preliminary patch to unify mcu code between mt76x02{e,u} drivers Signed-off-by: Lorenzo Bianconi Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mmio.c | 4 ++++ drivers/net/wireless/mediatek/mt76/mt76.h | 16 +++++++++++++++- drivers/net/wireless/mediatek/mt76/mt76x2.h | 10 ---------- drivers/net/wireless/mediatek/mt76/mt76x2_common.c | 5 +++-- drivers/net/wireless/mediatek/mt76/mt76x2_dma.c | 3 --- drivers/net/wireless/mediatek/mt76/mt76x2_mcu.c | 17 ++++++++--------- 6 files changed, 30 insertions(+), 25 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mmio.c b/drivers/net/wireless/mediatek/mt76/mmio.c index 09a14de..11a74c3 100644 --- a/drivers/net/wireless/mediatek/mt76/mmio.c +++ b/drivers/net/wireless/mediatek/mt76/mmio.c @@ -57,5 +57,9 @@ void mt76_mmio_init(struct mt76_dev *dev, void __iomem *regs) dev->bus = &mt76_mmio_ops; dev->regs = regs; + + skb_queue_head_init(&dev->mmio.mcu.res_q); + init_waitqueue_head(&dev->mmio.mcu.wait); + mutex_init(&dev->mmio.mcu.mutex); } EXPORT_SYMBOL_GPL(mt76_mmio_init); diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h b/drivers/net/wireless/mediatek/mt76/mt76.h index 34d111a..8c9b78d 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76.h +++ b/drivers/net/wireless/mediatek/mt76/mt76.h @@ -338,6 +338,17 @@ struct mt76_usb { } mcu; }; +struct mt76_mmio { + struct mt76e_mcu { + struct mutex mutex; + + wait_queue_head_t wait; + struct sk_buff_head res_q; + + u32 msg_seq; + } mcu; +}; + struct mt76_dev { struct ieee80211_hw *hw; struct cfg80211_chan_def chandef; @@ -392,7 +403,10 @@ struct mt76_dev { u32 rxfilter; - struct mt76_usb usb; + union { + struct mt76_mmio mmio; + struct mt76_usb usb; + }; }; enum mt76_phy_type { diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2.h b/drivers/net/wireless/mediatek/mt76/mt76x2.h index 5449d38..07400d9 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x2.h @@ -47,15 +47,6 @@ #include "mt76x2_mac.h" #include "mt76x2_dfs.h" -struct mt76x2_mcu { - struct mutex mutex; - - wait_queue_head_t wait; - struct sk_buff_head res_q; - - u32 msg_seq; -}; - struct mt76x2_rx_freq_cal { s8 high_gain[MT_MAX_CHAINS]; s8 rssi_offset[MT_MAX_CHAINS]; @@ -97,7 +88,6 @@ struct mt76x2_dev { u8 txdone_seq; DECLARE_KFIFO_PTR(txstatus_fifo, struct mt76x02_tx_status); - struct mt76x2_mcu mcu; struct sk_buff *rx_head; struct tasklet_struct tx_tasklet; diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2_common.c b/drivers/net/wireless/mediatek/mt76/mt76x2_common.c index 0f7f731..3e667d8 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2_common.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2_common.c @@ -25,8 +25,9 @@ void mt76x2_queue_rx_skb(struct mt76_dev *mdev, enum mt76_rxq_id q, void *rxwi = skb->data; if (q == MT_RXQ_MCU) { - skb_queue_tail(&dev->mcu.res_q, skb); - wake_up(&dev->mcu.wait); + /* this is used just by mmio code */ + skb_queue_tail(&mdev->mmio.mcu.res_q, skb); + wake_up(&mdev->mmio.mcu.wait); return; } diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2_dma.c b/drivers/net/wireless/mediatek/mt76/mt76x2_dma.c index 9198c3d..3c6bbb7 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2_dma.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2_dma.c @@ -112,9 +112,6 @@ int mt76x2_dma_init(struct mt76x2_dev *dev) mt76_dma_attach(&dev->mt76); - init_waitqueue_head(&dev->mcu.wait); - skb_queue_head_init(&dev->mcu.res_q); - tasklet_init(&dev->tx_tasklet, mt76x2_tx_tasklet, (unsigned long) dev); mt76_wr(dev, MT_WPDMA_RST_IDX, ~0); diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2_mcu.c b/drivers/net/wireless/mediatek/mt76/mt76x2_mcu.c index 27b2d7b..fc1c080 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2_mcu.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2_mcu.c @@ -44,9 +44,10 @@ mt76x2_mcu_get_response(struct mt76x2_dev *dev, unsigned long expires) return NULL; timeout = expires - jiffies; - wait_event_timeout(dev->mcu.wait, !skb_queue_empty(&dev->mcu.res_q), + wait_event_timeout(dev->mt76.mmio.mcu.wait, + !skb_queue_empty(&dev->mt76.mmio.mcu.res_q), timeout); - return skb_dequeue(&dev->mcu.res_q); + return skb_dequeue(&dev->mt76.mmio.mcu.res_q); } static int @@ -60,11 +61,11 @@ mt76x2_mcu_msg_send(struct mt76x2_dev *dev, struct sk_buff *skb, if (!skb) return -EINVAL; - mutex_lock(&dev->mcu.mutex); + mutex_lock(&dev->mt76.mmio.mcu.mutex); - seq = ++dev->mcu.msg_seq & 0xf; + seq = ++dev->mt76.mmio.mcu.msg_seq & 0xf; if (!seq) - seq = ++dev->mcu.msg_seq & 0xf; + seq = ++dev->mt76.mmio.mcu.msg_seq & 0xf; ret = mt76x2_tx_queue_mcu(&dev->mt76, MT_TXQ_MCU, skb, cmd, seq); if (ret) @@ -94,7 +95,7 @@ mt76x2_mcu_msg_send(struct mt76x2_dev *dev, struct sk_buff *skb, } out: - mutex_unlock(&dev->mcu.mutex); + mutex_unlock(&dev->mt76.mmio.mcu.mutex); return ret; } @@ -399,8 +400,6 @@ int mt76x2_mcu_init(struct mt76x2_dev *dev) { int ret; - mutex_init(&dev->mcu.mutex); - ret = mt76pci_load_rom_patch(dev); if (ret) return ret; @@ -420,7 +419,7 @@ int mt76x2_mcu_cleanup(struct mt76x2_dev *dev) mt76_wr(dev, MT_MCU_INT_LEVEL, 1); usleep_range(20000, 30000); - while ((skb = skb_dequeue(&dev->mcu.res_q)) != NULL) + while ((skb = skb_dequeue(&dev->mt76.mmio.mcu.res_q)) != NULL) dev_kfree_skb(skb); return 0; -- 2.7.4