mtk_wed.h 2.6 KB

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