mvneta_bm.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*
  2. * Driver for Marvell NETA network controller Buffer Manager.
  3. *
  4. * Copyright (C) 2015 Marvell
  5. *
  6. * Marcin Wojtas <mw@semihalf.com>
  7. *
  8. * This file is licensed under the terms of the GNU General Public
  9. * License version 2. This program is licensed "as is" without any
  10. * warranty of any kind, whether express or implied.
  11. */
  12. #ifndef _MVNETA_BM_H_
  13. #define _MVNETA_BM_H_
  14. /* BM Configuration Register */
  15. #define MVNETA_BM_CONFIG_REG 0x0
  16. #define MVNETA_BM_STATUS_MASK 0x30
  17. #define MVNETA_BM_ACTIVE_MASK BIT(4)
  18. #define MVNETA_BM_MAX_IN_BURST_SIZE_MASK 0x60000
  19. #define MVNETA_BM_MAX_IN_BURST_SIZE_16BP BIT(18)
  20. #define MVNETA_BM_EMPTY_LIMIT_MASK BIT(19)
  21. /* BM Activation Register */
  22. #define MVNETA_BM_COMMAND_REG 0x4
  23. #define MVNETA_BM_START_MASK BIT(0)
  24. #define MVNETA_BM_STOP_MASK BIT(1)
  25. #define MVNETA_BM_PAUSE_MASK BIT(2)
  26. /* BM Xbar interface Register */
  27. #define MVNETA_BM_XBAR_01_REG 0x8
  28. #define MVNETA_BM_XBAR_23_REG 0xc
  29. #define MVNETA_BM_XBAR_POOL_REG(pool) \
  30. (((pool) < 2) ? MVNETA_BM_XBAR_01_REG : MVNETA_BM_XBAR_23_REG)
  31. #define MVNETA_BM_TARGET_ID_OFFS(pool) (((pool) & 1) ? 16 : 0)
  32. #define MVNETA_BM_TARGET_ID_MASK(pool) \
  33. (0xf << MVNETA_BM_TARGET_ID_OFFS(pool))
  34. #define MVNETA_BM_TARGET_ID_VAL(pool, id) \
  35. ((id) << MVNETA_BM_TARGET_ID_OFFS(pool))
  36. #define MVNETA_BM_XBAR_ATTR_OFFS(pool) (((pool) & 1) ? 20 : 4)
  37. #define MVNETA_BM_XBAR_ATTR_MASK(pool) \
  38. (0xff << MVNETA_BM_XBAR_ATTR_OFFS(pool))
  39. #define MVNETA_BM_XBAR_ATTR_VAL(pool, attr) \
  40. ((attr) << MVNETA_BM_XBAR_ATTR_OFFS(pool))
  41. /* Address of External Buffer Pointers Pool Register */
  42. #define MVNETA_BM_POOL_BASE_REG(pool) (0x10 + ((pool) << 4))
  43. #define MVNETA_BM_POOL_ENABLE_MASK BIT(0)
  44. /* External Buffer Pointers Pool RD pointer Register */
  45. #define MVNETA_BM_POOL_READ_PTR_REG(pool) (0x14 + ((pool) << 4))
  46. #define MVNETA_BM_POOL_SET_READ_PTR_MASK 0xfffc
  47. #define MVNETA_BM_POOL_GET_READ_PTR_OFFS 16
  48. #define MVNETA_BM_POOL_GET_READ_PTR_MASK 0xfffc0000
  49. /* External Buffer Pointers Pool WR pointer */
  50. #define MVNETA_BM_POOL_WRITE_PTR_REG(pool) (0x18 + ((pool) << 4))
  51. #define MVNETA_BM_POOL_SET_WRITE_PTR_OFFS 0
  52. #define MVNETA_BM_POOL_SET_WRITE_PTR_MASK 0xfffc
  53. #define MVNETA_BM_POOL_GET_WRITE_PTR_OFFS 16
  54. #define MVNETA_BM_POOL_GET_WRITE_PTR_MASK 0xfffc0000
  55. /* External Buffer Pointers Pool Size Register */
  56. #define MVNETA_BM_POOL_SIZE_REG(pool) (0x1c + ((pool) << 4))
  57. #define MVNETA_BM_POOL_SIZE_MASK 0x3fff
  58. /* BM Interrupt Cause Register */
  59. #define MVNETA_BM_INTR_CAUSE_REG (0x50)
  60. /* BM interrupt Mask Register */
  61. #define MVNETA_BM_INTR_MASK_REG (0x54)
  62. /* Other definitions */
  63. #define MVNETA_BM_SHORT_PKT_SIZE 256
  64. #define MVNETA_BM_POOLS_NUM 4
  65. #define MVNETA_BM_POOL_CAP_MIN 128
  66. #define MVNETA_BM_POOL_CAP_DEF 2048
  67. #define MVNETA_BM_POOL_CAP_MAX \
  68. (16 * 1024 - MVNETA_BM_POOL_CAP_ALIGN)
  69. #define MVNETA_BM_POOL_CAP_ALIGN 32
  70. #define MVNETA_BM_POOL_PTR_ALIGN 32
  71. #define MVNETA_BM_POOL_ACCESS_OFFS 8
  72. #define MVNETA_BM_BPPI_SIZE 0x100000
  73. #define MVNETA_RX_BUF_SIZE(pkt_size) ((pkt_size) + NET_SKB_PAD)
  74. enum mvneta_bm_type {
  75. MVNETA_BM_FREE,
  76. MVNETA_BM_LONG,
  77. MVNETA_BM_SHORT
  78. };
  79. struct mvneta_bm {
  80. void __iomem *reg_base;
  81. struct clk *clk;
  82. struct platform_device *pdev;
  83. struct gen_pool *bppi_pool;
  84. /* BPPI virtual base address */
  85. void __iomem *bppi_virt_addr;
  86. /* BPPI physical base address */
  87. dma_addr_t bppi_phys_addr;
  88. /* BM pools */
  89. struct mvneta_bm_pool *bm_pools;
  90. };
  91. struct mvneta_bm_pool {
  92. struct hwbm_pool hwbm_pool;
  93. /* Pool number in the range 0-3 */
  94. u8 id;
  95. enum mvneta_bm_type type;
  96. /* Packet size */
  97. int pkt_size;
  98. /* Size of the buffer acces through DMA*/
  99. u32 buf_size;
  100. /* BPPE virtual base address */
  101. u32 *virt_addr;
  102. /* BPPE physical base address */
  103. dma_addr_t phys_addr;
  104. /* Ports using BM pool */
  105. u8 port_map;
  106. struct mvneta_bm *priv;
  107. };
  108. /* Declarations and definitions */
  109. void *mvneta_frag_alloc(unsigned int frag_size);
  110. void mvneta_frag_free(unsigned int frag_size, void *data);
  111. #if IS_ENABLED(CONFIG_MVNETA_BM)
  112. void mvneta_bm_pool_destroy(struct mvneta_bm *priv,
  113. struct mvneta_bm_pool *bm_pool, u8 port_map);
  114. void mvneta_bm_bufs_free(struct mvneta_bm *priv, struct mvneta_bm_pool *bm_pool,
  115. u8 port_map);
  116. int mvneta_bm_construct(struct hwbm_pool *hwbm_pool, void *buf);
  117. int mvneta_bm_pool_refill(struct mvneta_bm *priv,
  118. struct mvneta_bm_pool *bm_pool);
  119. struct mvneta_bm_pool *mvneta_bm_pool_use(struct mvneta_bm *priv, u8 pool_id,
  120. enum mvneta_bm_type type, u8 port_id,
  121. int pkt_size);
  122. static inline void mvneta_bm_pool_put_bp(struct mvneta_bm *priv,
  123. struct mvneta_bm_pool *bm_pool,
  124. dma_addr_t buf_phys_addr)
  125. {
  126. writel_relaxed(buf_phys_addr, priv->bppi_virt_addr +
  127. (bm_pool->id << MVNETA_BM_POOL_ACCESS_OFFS));
  128. }
  129. static inline u32 mvneta_bm_pool_get_bp(struct mvneta_bm *priv,
  130. struct mvneta_bm_pool *bm_pool)
  131. {
  132. return readl_relaxed(priv->bppi_virt_addr +
  133. (bm_pool->id << MVNETA_BM_POOL_ACCESS_OFFS));
  134. }
  135. #else
  136. void mvneta_bm_pool_destroy(struct mvneta_bm *priv,
  137. struct mvneta_bm_pool *bm_pool, u8 port_map) {}
  138. void mvneta_bm_bufs_free(struct mvneta_bm *priv, struct mvneta_bm_pool *bm_pool,
  139. u8 port_map) {}
  140. int mvneta_bm_construct(struct hwbm_pool *hwbm_pool, void *buf) { return 0; }
  141. int mvneta_bm_pool_refill(struct mvneta_bm *priv,
  142. struct mvneta_bm_pool *bm_pool) {return 0; }
  143. struct mvneta_bm_pool *mvneta_bm_pool_use(struct mvneta_bm *priv, u8 pool_id,
  144. enum mvneta_bm_type type, u8 port_id,
  145. int pkt_size) { return NULL; }
  146. static inline void mvneta_bm_pool_put_bp(struct mvneta_bm *priv,
  147. struct mvneta_bm_pool *bm_pool,
  148. dma_addr_t buf_phys_addr) {}
  149. static inline u32 mvneta_bm_pool_get_bp(struct mvneta_bm *priv,
  150. struct mvneta_bm_pool *bm_pool)
  151. { return 0; }
  152. #endif /* CONFIG_MVNETA_BM */
  153. #endif