xref: /linux/drivers/net/ethernet/mediatek/mtk_wed.h (revision 2da68a77)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /* Copyright (C) 2021 Felix Fietkau <nbd@nbd.name> */
3 
4 #ifndef __MTK_WED_PRIV_H
5 #define __MTK_WED_PRIV_H
6 
7 #include <linux/soc/mediatek/mtk_wed.h>
8 #include <linux/debugfs.h>
9 #include <linux/regmap.h>
10 #include <linux/netdevice.h>
11 
12 struct mtk_eth;
13 
14 struct mtk_wed_hw {
15 	struct device_node *node;
16 	struct mtk_eth *eth;
17 	struct regmap *regs;
18 	struct regmap *hifsys;
19 	struct device *dev;
20 	void __iomem *wdma;
21 	phys_addr_t wdma_phy;
22 	struct regmap *mirror;
23 	struct dentry *debugfs_dir;
24 	struct mtk_wed_device *wed_dev;
25 	u32 debugfs_reg;
26 	u32 num_flows;
27 	u8 version;
28 	char dirname[5];
29 	int irq;
30 	int index;
31 };
32 
33 struct mtk_wdma_info {
34 	u8 wdma_idx;
35 	u8 queue;
36 	u16 wcid;
37 	u8 bss;
38 };
39 
40 #ifdef CONFIG_NET_MEDIATEK_SOC_WED
41 static inline void
42 wed_w32(struct mtk_wed_device *dev, u32 reg, u32 val)
43 {
44 	regmap_write(dev->hw->regs, reg, val);
45 }
46 
47 static inline u32
48 wed_r32(struct mtk_wed_device *dev, u32 reg)
49 {
50 	unsigned int val;
51 
52 	regmap_read(dev->hw->regs, reg, &val);
53 
54 	return val;
55 }
56 
57 static inline void
58 wdma_w32(struct mtk_wed_device *dev, u32 reg, u32 val)
59 {
60 	writel(val, dev->hw->wdma + reg);
61 }
62 
63 static inline u32
64 wdma_r32(struct mtk_wed_device *dev, u32 reg)
65 {
66 	return readl(dev->hw->wdma + reg);
67 }
68 
69 static inline u32
70 wpdma_tx_r32(struct mtk_wed_device *dev, int ring, u32 reg)
71 {
72 	if (!dev->tx_ring[ring].wpdma)
73 		return 0;
74 
75 	return readl(dev->tx_ring[ring].wpdma + reg);
76 }
77 
78 static inline void
79 wpdma_tx_w32(struct mtk_wed_device *dev, int ring, u32 reg, u32 val)
80 {
81 	if (!dev->tx_ring[ring].wpdma)
82 		return;
83 
84 	writel(val, dev->tx_ring[ring].wpdma + reg);
85 }
86 
87 static inline u32
88 wpdma_txfree_r32(struct mtk_wed_device *dev, u32 reg)
89 {
90 	if (!dev->txfree_ring.wpdma)
91 		return 0;
92 
93 	return readl(dev->txfree_ring.wpdma + reg);
94 }
95 
96 static inline void
97 wpdma_txfree_w32(struct mtk_wed_device *dev, u32 reg, u32 val)
98 {
99 	if (!dev->txfree_ring.wpdma)
100 		return;
101 
102 	writel(val, dev->txfree_ring.wpdma + reg);
103 }
104 
105 void mtk_wed_add_hw(struct device_node *np, struct mtk_eth *eth,
106 		    void __iomem *wdma, phys_addr_t wdma_phy,
107 		    int index);
108 void mtk_wed_exit(void);
109 int mtk_wed_flow_add(int index);
110 void mtk_wed_flow_remove(int index);
111 #else
112 static inline void
113 mtk_wed_add_hw(struct device_node *np, struct mtk_eth *eth,
114 	       void __iomem *wdma, phys_addr_t wdma_phy,
115 	       int index)
116 {
117 }
118 static inline void
119 mtk_wed_exit(void)
120 {
121 }
122 static inline int mtk_wed_flow_add(int index)
123 {
124 	return -EINVAL;
125 }
126 static inline void mtk_wed_flow_remove(int index)
127 {
128 }
129 #endif
130 
131 #ifdef CONFIG_DEBUG_FS
132 void mtk_wed_hw_add_debugfs(struct mtk_wed_hw *hw);
133 #else
134 static inline void mtk_wed_hw_add_debugfs(struct mtk_wed_hw *hw)
135 {
136 }
137 #endif
138 
139 #endif
140