Message ID | 9c4dded2b7a35a8e44b255a74e776a703359797b.1669020847.git.lorenzo@kernel.org (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | refactor mtk_wed code to introduce SER support | expand |
On Mon, 21 Nov 2022 09:59:25 +0100 Lorenzo Bianconi wrote: > +#define mtk_wed_device_tx_ring_setup(_dev, _ring, _regs, _reset) \ > + (_dev)->ops->tx_ring_setup(_dev, _ring, _regs, _reset) FWIW I find the "op macros" quite painful when trying to read a driver I'm not familiar with. stmmac does this, too. Just letting you know, it is what it is.
> On Mon, 21 Nov 2022 09:59:25 +0100 Lorenzo Bianconi wrote: > > +#define mtk_wed_device_tx_ring_setup(_dev, _ring, _regs, _reset) \ > > + (_dev)->ops->tx_ring_setup(_dev, _ring, _regs, _reset) > > FWIW I find the "op macros" quite painful when trying to read a driver > I'm not familiar with. stmmac does this, too. Just letting you know, > it is what it is. ack, fine. I maintained the approach currently used in the driver. Do you prefer to run the function pointer directly? Regards, Lorenzo
On Mon, 21 Nov 2022 22:18:33 +0100 Lorenzo Bianconi wrote: > > On Mon, 21 Nov 2022 09:59:25 +0100 Lorenzo Bianconi wrote: > > > +#define mtk_wed_device_tx_ring_setup(_dev, _ring, _regs, _reset) \ > > > + (_dev)->ops->tx_ring_setup(_dev, _ring, _regs, _reset) > > > > FWIW I find the "op macros" quite painful when trying to read a driver > > I'm not familiar with. stmmac does this, too. Just letting you know, > > it is what it is. > > ack, fine. I maintained the approach currently used in the driver. > Do you prefer to run the function pointer directly? That's a tiny bit better, yes, saves the reader one lookup. Are the ops here serving as a HAL or a way of breaking the dependency between the SoC/Eth and the WiFi drivers?
On 22.11.22 05:19, Jakub Kicinski wrote: > On Mon, 21 Nov 2022 22:18:33 +0100 Lorenzo Bianconi wrote: >> > On Mon, 21 Nov 2022 09:59:25 +0100 Lorenzo Bianconi wrote: >> > > +#define mtk_wed_device_tx_ring_setup(_dev, _ring, _regs, _reset) \ >> > > + (_dev)->ops->tx_ring_setup(_dev, _ring, _regs, _reset) >> > >> > FWIW I find the "op macros" quite painful when trying to read a driver >> > I'm not familiar with. stmmac does this, too. Just letting you know, >> > it is what it is. >> >> ack, fine. I maintained the approach currently used in the driver. >> Do you prefer to run the function pointer directly? > > That's a tiny bit better, yes, saves the reader one lookup. > > Are the ops here serving as a HAL or a way of breaking the dependency > between the SoC/Eth and the WiFi drivers? The latter. For a multi-platform kernel it's important that the wifi driver does not depend on mtk_eth_soc directly, even when support for WED is enabled. - Felix
On Tue, 22 Nov 2022 10:41:28 +0100 Felix Fietkau wrote: > > That's a tiny bit better, yes, saves the reader one lookup. > > > > Are the ops here serving as a HAL or a way of breaking the dependency > > between the SoC/Eth and the WiFi drivers? > The latter. For a multi-platform kernel it's important that the wifi > driver does not depend on mtk_eth_soc directly, even when support for > WED is enabled. Ah, I see, that's more legit. In the stmmac case it was just a poorly designed abstraction. I'll try to remember not to complain again.
diff --git a/drivers/net/ethernet/mediatek/mtk_wed.c b/drivers/net/ethernet/mediatek/mtk_wed.c index 07261aeacc56..927a74e4f51d 100644 --- a/drivers/net/ethernet/mediatek/mtk_wed.c +++ b/drivers/net/ethernet/mediatek/mtk_wed.c @@ -1181,7 +1181,8 @@ mtk_wed_ring_alloc(struct mtk_wed_device *dev, struct mtk_wed_ring *ring, } static int -mtk_wed_wdma_rx_ring_setup(struct mtk_wed_device *dev, int idx, int size) +mtk_wed_wdma_rx_ring_setup(struct mtk_wed_device *dev, int idx, int size, + bool reset) { u32 desc_size = sizeof(struct mtk_wdma_desc) * dev->hw->version; struct mtk_wed_ring *wdma; @@ -1190,8 +1191,8 @@ mtk_wed_wdma_rx_ring_setup(struct mtk_wed_device *dev, int idx, int size) return -EINVAL; wdma = &dev->rx_wdma[idx]; - if (mtk_wed_ring_alloc(dev, wdma, MTK_WED_WDMA_RING_SIZE, desc_size, - true)) + if (!reset && mtk_wed_ring_alloc(dev, wdma, MTK_WED_WDMA_RING_SIZE, + desc_size, true)) return -ENOMEM; wdma_w32(dev, MTK_WDMA_RING_RX(idx) + MTK_WED_RING_OFS_BASE, @@ -1389,7 +1390,7 @@ mtk_wed_start(struct mtk_wed_device *dev, u32 irq_mask) for (i = 0; i < ARRAY_SIZE(dev->rx_wdma); i++) if (!dev->rx_wdma[i].desc) - mtk_wed_wdma_rx_ring_setup(dev, i, 16); + mtk_wed_wdma_rx_ring_setup(dev, i, 16, false); mtk_wed_hw_init(dev); mtk_wed_configure_irq(dev, irq_mask); @@ -1495,7 +1496,8 @@ mtk_wed_attach(struct mtk_wed_device *dev) } static int -mtk_wed_tx_ring_setup(struct mtk_wed_device *dev, int idx, void __iomem *regs) +mtk_wed_tx_ring_setup(struct mtk_wed_device *dev, int idx, void __iomem *regs, + bool reset) { struct mtk_wed_ring *ring = &dev->tx_ring[idx]; @@ -1514,11 +1516,12 @@ mtk_wed_tx_ring_setup(struct mtk_wed_device *dev, int idx, void __iomem *regs) if (WARN_ON(idx >= ARRAY_SIZE(dev->tx_ring))) return -EINVAL; - if (mtk_wed_ring_alloc(dev, ring, MTK_WED_TX_RING_SIZE, - sizeof(*ring->desc), true)) + if (!reset && mtk_wed_ring_alloc(dev, ring, MTK_WED_TX_RING_SIZE, + sizeof(*ring->desc), true)) return -ENOMEM; - if (mtk_wed_wdma_rx_ring_setup(dev, idx, MTK_WED_WDMA_RING_SIZE)) + if (mtk_wed_wdma_rx_ring_setup(dev, idx, MTK_WED_WDMA_RING_SIZE, + reset)) return -ENOMEM; ring->reg_base = MTK_WED_RING_TX(idx); diff --git a/drivers/net/wireless/mediatek/mt76/dma.c b/drivers/net/wireless/mediatek/mt76/dma.c index 8dca8d2447b7..3f8c0845fcca 100644 --- a/drivers/net/wireless/mediatek/mt76/dma.c +++ b/drivers/net/wireless/mediatek/mt76/dma.c @@ -632,7 +632,7 @@ mt76_dma_wed_setup(struct mt76_dev *dev, struct mt76_queue *q) switch (type) { case MT76_WED_Q_TX: - ret = mtk_wed_device_tx_ring_setup(wed, ring, q->regs); + ret = mtk_wed_device_tx_ring_setup(wed, ring, q->regs, false); if (!ret) q->wed_regs = wed->tx_ring[ring].reg_base; break; diff --git a/include/linux/soc/mediatek/mtk_wed.h b/include/linux/soc/mediatek/mtk_wed.h index 0bbba50cf929..32d87c701333 100644 --- a/include/linux/soc/mediatek/mtk_wed.h +++ b/include/linux/soc/mediatek/mtk_wed.h @@ -155,7 +155,7 @@ struct mtk_wed_device { struct mtk_wed_ops { int (*attach)(struct mtk_wed_device *dev); int (*tx_ring_setup)(struct mtk_wed_device *dev, int ring, - void __iomem *regs); + void __iomem *regs, bool reset); int (*rx_ring_setup)(struct mtk_wed_device *dev, int ring, void __iomem *regs); int (*txfree_ring_setup)(struct mtk_wed_device *dev, @@ -213,8 +213,8 @@ mtk_wed_get_rx_capa(struct mtk_wed_device *dev) #define mtk_wed_device_active(_dev) !!(_dev)->ops #define mtk_wed_device_detach(_dev) (_dev)->ops->detach(_dev) #define mtk_wed_device_start(_dev, _mask) (_dev)->ops->start(_dev, _mask) -#define mtk_wed_device_tx_ring_setup(_dev, _ring, _regs) \ - (_dev)->ops->tx_ring_setup(_dev, _ring, _regs) +#define mtk_wed_device_tx_ring_setup(_dev, _ring, _regs, _reset) \ + (_dev)->ops->tx_ring_setup(_dev, _ring, _regs, _reset) #define mtk_wed_device_txfree_ring_setup(_dev, _regs) \ (_dev)->ops->txfree_ring_setup(_dev, _regs) #define mtk_wed_device_reg_read(_dev, _reg) \ @@ -240,7 +240,7 @@ static inline bool mtk_wed_device_active(struct mtk_wed_device *dev) } #define mtk_wed_device_detach(_dev) do {} while (0) #define mtk_wed_device_start(_dev, _mask) do {} while (0) -#define mtk_wed_device_tx_ring_setup(_dev, _ring, _regs) -ENODEV +#define mtk_wed_device_tx_ring_setup(_dev, _ring, _regs, _reset) -ENODEV #define mtk_wed_device_txfree_ring_setup(_dev, _ring, _regs) -ENODEV #define mtk_wed_device_reg_read(_dev, _reg) 0 #define mtk_wed_device_reg_write(_dev, _reg, _val) do {} while (0)