1 #ifndef __MTK_WED_H 2 #define __MTK_WED_H 3 4 #include <linux/kernel.h> 5 #include <linux/rcupdate.h> 6 #include <linux/regmap.h> 7 #include <linux/pci.h> 8 #include <linux/skbuff.h> 9 10 #define MTK_WED_TX_QUEUES 2 11 #define MTK_WED_RX_QUEUES 2 12 13 #define WED_WO_STA_REC 0x6 14 15 struct mtk_wed_hw; 16 struct mtk_wdma_desc; 17 18 enum mtk_wed_wo_cmd { 19 MTK_WED_WO_CMD_WED_CFG, 20 MTK_WED_WO_CMD_WED_RX_STAT, 21 MTK_WED_WO_CMD_RRO_SER, 22 MTK_WED_WO_CMD_DBG_INFO, 23 MTK_WED_WO_CMD_DEV_INFO, 24 MTK_WED_WO_CMD_BSS_INFO, 25 MTK_WED_WO_CMD_STA_REC, 26 MTK_WED_WO_CMD_DEV_INFO_DUMP, 27 MTK_WED_WO_CMD_BSS_INFO_DUMP, 28 MTK_WED_WO_CMD_STA_REC_DUMP, 29 MTK_WED_WO_CMD_BA_INFO_DUMP, 30 MTK_WED_WO_CMD_FBCMD_Q_DUMP, 31 MTK_WED_WO_CMD_FW_LOG_CTRL, 32 MTK_WED_WO_CMD_LOG_FLUSH, 33 MTK_WED_WO_CMD_CHANGE_STATE, 34 MTK_WED_WO_CMD_CPU_STATS_ENABLE, 35 MTK_WED_WO_CMD_CPU_STATS_DUMP, 36 MTK_WED_WO_CMD_EXCEPTION_INIT, 37 MTK_WED_WO_CMD_PROF_CTRL, 38 MTK_WED_WO_CMD_STA_BA_DUMP, 39 MTK_WED_WO_CMD_BA_CTRL_DUMP, 40 MTK_WED_WO_CMD_RXCNT_CTRL, 41 MTK_WED_WO_CMD_RXCNT_INFO, 42 MTK_WED_WO_CMD_SET_CAP, 43 MTK_WED_WO_CMD_CCIF_RING_DUMP, 44 MTK_WED_WO_CMD_WED_END 45 }; 46 47 struct mtk_rxbm_desc { 48 __le32 buf0; 49 __le32 token; 50 } __packed __aligned(4); 51 52 enum mtk_wed_bus_tye { 53 MTK_WED_BUS_PCIE, 54 MTK_WED_BUS_AXI, 55 }; 56 57 #define MTK_WED_RING_CONFIGURED BIT(0) 58 struct mtk_wed_ring { 59 struct mtk_wdma_desc *desc; 60 dma_addr_t desc_phys; 61 u32 desc_size; 62 int size; 63 u32 flags; 64 65 u32 reg_base; 66 void __iomem *wpdma; 67 }; 68 69 struct mtk_wed_wo_rx_stats { 70 __le16 wlan_idx; 71 __le16 tid; 72 __le32 rx_pkt_cnt; 73 __le32 rx_byte_cnt; 74 __le32 rx_err_cnt; 75 __le32 rx_drop_cnt; 76 }; 77 78 struct mtk_wed_device { 79 #ifdef CONFIG_NET_MEDIATEK_SOC_WED 80 const struct mtk_wed_ops *ops; 81 struct device *dev; 82 struct mtk_wed_hw *hw; 83 bool init_done, running; 84 int wdma_idx; 85 int irq; 86 u8 version; 87 88 /* used by wlan driver */ 89 u32 rev_id; 90 91 struct mtk_wed_ring tx_ring[MTK_WED_TX_QUEUES]; 92 struct mtk_wed_ring rx_ring[MTK_WED_RX_QUEUES]; 93 struct mtk_wed_ring txfree_ring; 94 struct mtk_wed_ring tx_wdma[MTK_WED_TX_QUEUES]; 95 struct mtk_wed_ring rx_wdma[MTK_WED_RX_QUEUES]; 96 97 struct { 98 int size; 99 void **pages; 100 struct mtk_wdma_desc *desc; 101 dma_addr_t desc_phys; 102 } tx_buf_ring; 103 104 struct { 105 int size; 106 struct mtk_rxbm_desc *desc; 107 dma_addr_t desc_phys; 108 } rx_buf_ring; 109 110 struct { 111 struct mtk_wed_ring ring; 112 dma_addr_t miod_phys; 113 dma_addr_t fdbk_phys; 114 } rro; 115 116 /* filled by driver: */ 117 struct { 118 union { 119 struct platform_device *platform_dev; 120 struct pci_dev *pci_dev; 121 }; 122 enum mtk_wed_bus_tye bus_type; 123 void __iomem *base; 124 u32 phy_base; 125 126 u32 wpdma_phys; 127 u32 wpdma_int; 128 u32 wpdma_mask; 129 u32 wpdma_tx; 130 u32 wpdma_txfree; 131 u32 wpdma_rx_glo; 132 u32 wpdma_rx; 133 134 bool wcid_512; 135 136 u16 token_start; 137 unsigned int nbuf; 138 unsigned int rx_nbuf; 139 unsigned int rx_npkt; 140 unsigned int rx_size; 141 142 u8 tx_tbit[MTK_WED_TX_QUEUES]; 143 u8 rx_tbit[MTK_WED_RX_QUEUES]; 144 u8 txfree_tbit; 145 146 u32 (*init_buf)(void *ptr, dma_addr_t phys, int token_id); 147 int (*offload_enable)(struct mtk_wed_device *wed); 148 void (*offload_disable)(struct mtk_wed_device *wed); 149 u32 (*init_rx_buf)(struct mtk_wed_device *wed, int size); 150 void (*release_rx_buf)(struct mtk_wed_device *wed); 151 void (*update_wo_rx_stats)(struct mtk_wed_device *wed, 152 struct mtk_wed_wo_rx_stats *stats); 153 int (*reset)(struct mtk_wed_device *wed); 154 void (*reset_complete)(struct mtk_wed_device *wed); 155 } wlan; 156 #endif 157 }; 158 159 struct mtk_wed_ops { 160 int (*attach)(struct mtk_wed_device *dev); 161 int (*tx_ring_setup)(struct mtk_wed_device *dev, int ring, 162 void __iomem *regs, bool reset); 163 int (*rx_ring_setup)(struct mtk_wed_device *dev, int ring, 164 void __iomem *regs, bool reset); 165 int (*txfree_ring_setup)(struct mtk_wed_device *dev, 166 void __iomem *regs); 167 int (*msg_update)(struct mtk_wed_device *dev, int cmd_id, 168 void *data, int len); 169 void (*detach)(struct mtk_wed_device *dev); 170 void (*ppe_check)(struct mtk_wed_device *dev, struct sk_buff *skb, 171 u32 reason, u32 hash); 172 173 void (*stop)(struct mtk_wed_device *dev); 174 void (*start)(struct mtk_wed_device *dev, u32 irq_mask); 175 void (*reset_dma)(struct mtk_wed_device *dev); 176 177 u32 (*reg_read)(struct mtk_wed_device *dev, u32 reg); 178 void (*reg_write)(struct mtk_wed_device *dev, u32 reg, u32 val); 179 180 u32 (*irq_get)(struct mtk_wed_device *dev, u32 mask); 181 void (*irq_set_mask)(struct mtk_wed_device *dev, u32 mask); 182 }; 183 184 extern const struct mtk_wed_ops __rcu *mtk_soc_wed_ops; 185 186 static inline int 187 mtk_wed_device_attach(struct mtk_wed_device *dev) 188 { 189 int ret = -ENODEV; 190 191 #ifdef CONFIG_NET_MEDIATEK_SOC_WED 192 rcu_read_lock(); 193 dev->ops = rcu_dereference(mtk_soc_wed_ops); 194 if (dev->ops) 195 ret = dev->ops->attach(dev); 196 else 197 rcu_read_unlock(); 198 199 if (ret) 200 dev->ops = NULL; 201 #endif 202 203 return ret; 204 } 205 206 static inline bool 207 mtk_wed_get_rx_capa(struct mtk_wed_device *dev) 208 { 209 #ifdef CONFIG_NET_MEDIATEK_SOC_WED 210 return dev->version != 1; 211 #else 212 return false; 213 #endif 214 } 215 216 #ifdef CONFIG_NET_MEDIATEK_SOC_WED 217 #define mtk_wed_device_active(_dev) !!(_dev)->ops 218 #define mtk_wed_device_detach(_dev) (_dev)->ops->detach(_dev) 219 #define mtk_wed_device_start(_dev, _mask) (_dev)->ops->start(_dev, _mask) 220 #define mtk_wed_device_tx_ring_setup(_dev, _ring, _regs, _reset) \ 221 (_dev)->ops->tx_ring_setup(_dev, _ring, _regs, _reset) 222 #define mtk_wed_device_txfree_ring_setup(_dev, _regs) \ 223 (_dev)->ops->txfree_ring_setup(_dev, _regs) 224 #define mtk_wed_device_reg_read(_dev, _reg) \ 225 (_dev)->ops->reg_read(_dev, _reg) 226 #define mtk_wed_device_reg_write(_dev, _reg, _val) \ 227 (_dev)->ops->reg_write(_dev, _reg, _val) 228 #define mtk_wed_device_irq_get(_dev, _mask) \ 229 (_dev)->ops->irq_get(_dev, _mask) 230 #define mtk_wed_device_irq_set_mask(_dev, _mask) \ 231 (_dev)->ops->irq_set_mask(_dev, _mask) 232 #define mtk_wed_device_rx_ring_setup(_dev, _ring, _regs, _reset) \ 233 (_dev)->ops->rx_ring_setup(_dev, _ring, _regs, _reset) 234 #define mtk_wed_device_ppe_check(_dev, _skb, _reason, _hash) \ 235 (_dev)->ops->ppe_check(_dev, _skb, _reason, _hash) 236 #define mtk_wed_device_update_msg(_dev, _id, _msg, _len) \ 237 (_dev)->ops->msg_update(_dev, _id, _msg, _len) 238 #define mtk_wed_device_stop(_dev) (_dev)->ops->stop(_dev) 239 #define mtk_wed_device_dma_reset(_dev) (_dev)->ops->reset_dma(_dev) 240 #else 241 static inline bool mtk_wed_device_active(struct mtk_wed_device *dev) 242 { 243 return false; 244 } 245 #define mtk_wed_device_detach(_dev) do {} while (0) 246 #define mtk_wed_device_start(_dev, _mask) do {} while (0) 247 #define mtk_wed_device_tx_ring_setup(_dev, _ring, _regs, _reset) -ENODEV 248 #define mtk_wed_device_txfree_ring_setup(_dev, _ring, _regs) -ENODEV 249 #define mtk_wed_device_reg_read(_dev, _reg) 0 250 #define mtk_wed_device_reg_write(_dev, _reg, _val) do {} while (0) 251 #define mtk_wed_device_irq_get(_dev, _mask) 0 252 #define mtk_wed_device_irq_set_mask(_dev, _mask) do {} while (0) 253 #define mtk_wed_device_rx_ring_setup(_dev, _ring, _regs, _reset) -ENODEV 254 #define mtk_wed_device_ppe_check(_dev, _skb, _reason, _hash) do {} while (0) 255 #define mtk_wed_device_update_msg(_dev, _id, _msg, _len) -ENODEV 256 #define mtk_wed_device_stop(_dev) do {} while (0) 257 #define mtk_wed_device_dma_reset(_dev) do {} while (0) 258 #endif 259 260 #endif 261