mtk_wed.h (2550B)
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 12struct mtk_eth; 13 14struct 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 struct regmap *mirror; 22 struct dentry *debugfs_dir; 23 struct mtk_wed_device *wed_dev; 24 u32 debugfs_reg; 25 u32 num_flows; 26 char dirname[5]; 27 int irq; 28 int index; 29}; 30 31struct mtk_wdma_info { 32 u8 wdma_idx; 33 u8 queue; 34 u16 wcid; 35 u8 bss; 36}; 37 38#ifdef CONFIG_NET_MEDIATEK_SOC_WED 39static inline void 40wed_w32(struct mtk_wed_device *dev, u32 reg, u32 val) 41{ 42 regmap_write(dev->hw->regs, reg, val); 43} 44 45static inline u32 46wed_r32(struct mtk_wed_device *dev, u32 reg) 47{ 48 unsigned int val; 49 50 regmap_read(dev->hw->regs, reg, &val); 51 52 return val; 53} 54 55static inline void 56wdma_w32(struct mtk_wed_device *dev, u32 reg, u32 val) 57{ 58 writel(val, dev->hw->wdma + reg); 59} 60 61static inline u32 62wdma_r32(struct mtk_wed_device *dev, u32 reg) 63{ 64 return readl(dev->hw->wdma + reg); 65} 66 67static inline u32 68wpdma_tx_r32(struct mtk_wed_device *dev, int ring, u32 reg) 69{ 70 if (!dev->tx_ring[ring].wpdma) 71 return 0; 72 73 return readl(dev->tx_ring[ring].wpdma + reg); 74} 75 76static inline void 77wpdma_tx_w32(struct mtk_wed_device *dev, int ring, u32 reg, u32 val) 78{ 79 if (!dev->tx_ring[ring].wpdma) 80 return; 81 82 writel(val, dev->tx_ring[ring].wpdma + reg); 83} 84 85static inline u32 86wpdma_txfree_r32(struct mtk_wed_device *dev, u32 reg) 87{ 88 if (!dev->txfree_ring.wpdma) 89 return 0; 90 91 return readl(dev->txfree_ring.wpdma + reg); 92} 93 94static inline void 95wpdma_txfree_w32(struct mtk_wed_device *dev, u32 reg, u32 val) 96{ 97 if (!dev->txfree_ring.wpdma) 98 return; 99 100 writel(val, dev->txfree_ring.wpdma + reg); 101} 102 103void mtk_wed_add_hw(struct device_node *np, struct mtk_eth *eth, 104 void __iomem *wdma, int index); 105void mtk_wed_exit(void); 106int mtk_wed_flow_add(int index); 107void mtk_wed_flow_remove(int index); 108#else 109static inline void 110mtk_wed_add_hw(struct device_node *np, struct mtk_eth *eth, 111 void __iomem *wdma, int index) 112{ 113} 114static inline void 115mtk_wed_exit(void) 116{ 117} 118static inline int mtk_wed_flow_add(int index) 119{ 120 return -EINVAL; 121} 122static inline void mtk_wed_flow_remove(int index) 123{ 124} 125#endif 126 127#ifdef CONFIG_DEBUG_FS 128void mtk_wed_hw_add_debugfs(struct mtk_wed_hw *hw); 129#else 130static inline void mtk_wed_hw_add_debugfs(struct mtk_wed_hw *hw) 131{ 132} 133#endif 134 135#endif