Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /* Copyright (C) 2021 Felix Fietkau <nbd@nbd.name> */
0003 
0004 #ifndef __MTK_WED_PRIV_H
0005 #define __MTK_WED_PRIV_H
0006 
0007 #include <linux/soc/mediatek/mtk_wed.h>
0008 #include <linux/debugfs.h>
0009 #include <linux/regmap.h>
0010 #include <linux/netdevice.h>
0011 
0012 struct mtk_eth;
0013 
0014 struct mtk_wed_hw {
0015     struct device_node *node;
0016     struct mtk_eth *eth;
0017     struct regmap *regs;
0018     struct regmap *hifsys;
0019     struct device *dev;
0020     void __iomem *wdma;
0021     struct regmap *mirror;
0022     struct dentry *debugfs_dir;
0023     struct mtk_wed_device *wed_dev;
0024     u32 debugfs_reg;
0025     u32 num_flows;
0026     char dirname[5];
0027     int irq;
0028     int index;
0029 };
0030 
0031 struct mtk_wdma_info {
0032     u8 wdma_idx;
0033     u8 queue;
0034     u16 wcid;
0035     u8 bss;
0036 };
0037 
0038 #ifdef CONFIG_NET_MEDIATEK_SOC_WED
0039 static inline void
0040 wed_w32(struct mtk_wed_device *dev, u32 reg, u32 val)
0041 {
0042     regmap_write(dev->hw->regs, reg, val);
0043 }
0044 
0045 static inline u32
0046 wed_r32(struct mtk_wed_device *dev, u32 reg)
0047 {
0048     unsigned int val;
0049 
0050     regmap_read(dev->hw->regs, reg, &val);
0051 
0052     return val;
0053 }
0054 
0055 static inline void
0056 wdma_w32(struct mtk_wed_device *dev, u32 reg, u32 val)
0057 {
0058     writel(val, dev->hw->wdma + reg);
0059 }
0060 
0061 static inline u32
0062 wdma_r32(struct mtk_wed_device *dev, u32 reg)
0063 {
0064     return readl(dev->hw->wdma + reg);
0065 }
0066 
0067 static inline u32
0068 wpdma_tx_r32(struct mtk_wed_device *dev, int ring, u32 reg)
0069 {
0070     if (!dev->tx_ring[ring].wpdma)
0071         return 0;
0072 
0073     return readl(dev->tx_ring[ring].wpdma + reg);
0074 }
0075 
0076 static inline void
0077 wpdma_tx_w32(struct mtk_wed_device *dev, int ring, u32 reg, u32 val)
0078 {
0079     if (!dev->tx_ring[ring].wpdma)
0080         return;
0081 
0082     writel(val, dev->tx_ring[ring].wpdma + reg);
0083 }
0084 
0085 static inline u32
0086 wpdma_txfree_r32(struct mtk_wed_device *dev, u32 reg)
0087 {
0088     if (!dev->txfree_ring.wpdma)
0089         return 0;
0090 
0091     return readl(dev->txfree_ring.wpdma + reg);
0092 }
0093 
0094 static inline void
0095 wpdma_txfree_w32(struct mtk_wed_device *dev, u32 reg, u32 val)
0096 {
0097     if (!dev->txfree_ring.wpdma)
0098         return;
0099 
0100     writel(val, dev->txfree_ring.wpdma + reg);
0101 }
0102 
0103 void mtk_wed_add_hw(struct device_node *np, struct mtk_eth *eth,
0104             void __iomem *wdma, int index);
0105 void mtk_wed_exit(void);
0106 int mtk_wed_flow_add(int index);
0107 void mtk_wed_flow_remove(int index);
0108 #else
0109 static inline void
0110 mtk_wed_add_hw(struct device_node *np, struct mtk_eth *eth,
0111            void __iomem *wdma, int index)
0112 {
0113 }
0114 static inline void
0115 mtk_wed_exit(void)
0116 {
0117 }
0118 static inline int mtk_wed_flow_add(int index)
0119 {
0120     return -EINVAL;
0121 }
0122 static inline void mtk_wed_flow_remove(int index)
0123 {
0124 }
0125 #endif
0126 
0127 #ifdef CONFIG_DEBUG_FS
0128 void mtk_wed_hw_add_debugfs(struct mtk_wed_hw *hw);
0129 #else
0130 static inline void mtk_wed_hw_add_debugfs(struct mtk_wed_hw *hw)
0131 {
0132 }
0133 #endif
0134 
0135 #endif