hnd_pktpool.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /*
  2. * HND generic packet pool operation primitives
  3. *
  4. * Portions of this code are copyright (c) 2020 Cypress Semiconductor Corporation
  5. *
  6. * Copyright (C) 1999-2020, Broadcom Corporation
  7. *
  8. * Unless you and Broadcom execute a separate written software license
  9. * agreement governing use of this software, this software is licensed to you
  10. * under the terms of the GNU General Public License version 2 (the "GPL"),
  11. * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  12. * following added to such license:
  13. *
  14. * As a special exception, the copyright holders of this software give you
  15. * permission to link this software with independent modules, and to copy and
  16. * distribute the resulting executable under terms of your choice, provided that
  17. * you also meet, for each linked independent module, the terms and conditions of
  18. * the license of that module. An independent module is a module which is not
  19. * derived from this software. The special exception does not apply to any
  20. * modifications of the software.
  21. *
  22. * Notwithstanding the above, under no circumstances may you combine this
  23. * software in any way with any other Broadcom software provided under a license
  24. * other than the GPL, without Broadcom's express prior written consent.
  25. *
  26. *
  27. * <<Broadcom-WL-IPTag/Open:>>
  28. *
  29. * $Id: hnd_pktpool.h 633941 2016-04-26 07:04:26Z $
  30. */
  31. #ifndef _hnd_pktpool_h_
  32. #define _hnd_pktpool_h_
  33. #include <osl_ext.h>
  34. #ifdef __cplusplus
  35. extern "C" {
  36. #endif // endif
  37. /* mutex macros for thread safe */
  38. #ifdef HND_PKTPOOL_THREAD_SAFE
  39. #define HND_PKTPOOL_MUTEX_DECL(mutex) OSL_EXT_MUTEX_DECL(mutex)
  40. #else
  41. #define HND_PKTPOOL_MUTEX_DECL(mutex)
  42. #endif // endif
  43. #ifdef BCMPKTPOOL
  44. #define POOL_ENAB(pool) ((pool) && (pool)->inited)
  45. #else /* BCMPKTPOOL */
  46. #define POOL_ENAB(bus) 0
  47. #endif /* BCMPKTPOOL */
  48. #ifndef PKTPOOL_LEN_MAX
  49. #define PKTPOOL_LEN_MAX 40
  50. #endif /* PKTPOOL_LEN_MAX */
  51. #define PKTPOOL_CB_MAX 3
  52. #define PKTPOOL_CB_MAX_AVL 4
  53. /* REMOVE_RXCPLID is an arg for pktpool callback function for removing rxcplID
  54. * and host addr associated with the rxfrag or shared pool buffer during pktpool_reclaim().
  55. */
  56. #define REMOVE_RXCPLID 2
  57. /* forward declaration */
  58. struct pktpool;
  59. typedef void (*pktpool_cb_t)(struct pktpool *pool, void *arg);
  60. typedef struct {
  61. pktpool_cb_t cb;
  62. void *arg;
  63. uint8 refcnt;
  64. } pktpool_cbinfo_t;
  65. /** PCIe SPLITRX related: call back fn extension to populate host address in pool pkt */
  66. typedef int (*pktpool_cb_extn_t)(struct pktpool *pool, void *arg1, void* pkt, int arg2);
  67. typedef struct {
  68. pktpool_cb_extn_t cb;
  69. void *arg;
  70. } pktpool_cbextn_info_t;
  71. #ifdef BCMDBG_POOL
  72. /* pkt pool debug states */
  73. #define POOL_IDLE 0
  74. #define POOL_RXFILL 1
  75. #define POOL_RXDH 2
  76. #define POOL_RXD11 3
  77. #define POOL_TXDH 4
  78. #define POOL_TXD11 5
  79. #define POOL_AMPDU 6
  80. #define POOL_TXENQ 7
  81. typedef struct {
  82. void *p;
  83. uint32 cycles;
  84. uint32 dur;
  85. } pktpool_dbg_t;
  86. typedef struct {
  87. uint8 txdh; /* tx to host */
  88. uint8 txd11; /* tx to d11 */
  89. uint8 enq; /* waiting in q */
  90. uint8 rxdh; /* rx from host */
  91. uint8 rxd11; /* rx from d11 */
  92. uint8 rxfill; /* dma_rxfill */
  93. uint8 idle; /* avail in pool */
  94. } pktpool_stats_t;
  95. #endif /* BCMDBG_POOL */
  96. typedef struct pktpool {
  97. bool inited; /**< pktpool_init was successful */
  98. uint8 type; /**< type of lbuf: basic, frag, etc */
  99. uint8 id; /**< pktpool ID: index in registry */
  100. bool istx; /**< direction: transmit or receive data path */
  101. HND_PKTPOOL_MUTEX_DECL(mutex) /**< thread-safe mutex */
  102. void * freelist; /**< free list: see PKTNEXTFREE(), PKTSETNEXTFREE() */
  103. uint16 avail; /**< number of packets in pool's free list */
  104. uint16 n_pkts; /**< number of packets managed by pool */
  105. uint16 maxlen; /**< maximum size of pool <= PKTPOOL_LEN_MAX */
  106. uint16 max_pkt_bytes; /**< size of pkt buffer in [bytes], excluding lbuf|lbuf_frag */
  107. bool empty;
  108. uint8 cbtoggle;
  109. uint8 cbcnt;
  110. uint8 ecbcnt;
  111. uint8 emptycb_disable; /**< Value of type enum pktpool_empty_cb_state */
  112. pktpool_cbinfo_t *availcb_excl;
  113. pktpool_cbinfo_t cbs[PKTPOOL_CB_MAX_AVL];
  114. pktpool_cbinfo_t ecbs[PKTPOOL_CB_MAX];
  115. pktpool_cbextn_info_t cbext; /**< PCIe SPLITRX related */
  116. pktpool_cbextn_info_t rxcplidfn;
  117. #ifdef BCMDBG_POOL
  118. uint8 dbg_cbcnt;
  119. pktpool_cbinfo_t dbg_cbs[PKTPOOL_CB_MAX];
  120. uint16 dbg_qlen;
  121. pktpool_dbg_t dbg_q[PKTPOOL_LEN_MAX + 1];
  122. #endif // endif
  123. pktpool_cbinfo_t dmarxfill;
  124. } pktpool_t;
  125. pktpool_t *get_pktpools_registry(int id);
  126. /* Incarnate a pktpool registry. On success returns total_pools. */
  127. extern int pktpool_attach(osl_t *osh, uint32 total_pools);
  128. extern int pktpool_dettach(osl_t *osh); /* Relinquish registry */
  129. extern int pktpool_init(osl_t *osh, pktpool_t *pktp, int *n_pkts, int max_pkt_bytes, bool istx,
  130. uint8 type);
  131. extern int pktpool_deinit(osl_t *osh, pktpool_t *pktp);
  132. extern int pktpool_fill(osl_t *osh, pktpool_t *pktp, bool minimal);
  133. extern int pktpool_empty(osl_t *osh, pktpool_t *pktp);
  134. extern uint16 pktpool_reclaim(osl_t *osh, pktpool_t *pktp, uint16 free_cnt);
  135. extern void* pktpool_get(pktpool_t *pktp);
  136. extern void pktpool_free(pktpool_t *pktp, void *p);
  137. extern int pktpool_add(pktpool_t *pktp, void *p);
  138. extern int pktpool_avail_notify_normal(osl_t *osh, pktpool_t *pktp);
  139. extern int pktpool_avail_notify_exclusive(osl_t *osh, pktpool_t *pktp, pktpool_cb_t cb);
  140. extern int pktpool_avail_register(pktpool_t *pktp, pktpool_cb_t cb, void *arg);
  141. extern int pktpool_avail_deregister(pktpool_t *pktp, pktpool_cb_t cb, void *arg);
  142. extern int pktpool_empty_register(pktpool_t *pktp, pktpool_cb_t cb, void *arg);
  143. extern int pktpool_setmaxlen(pktpool_t *pktp, uint16 max_pkts);
  144. extern int pktpool_setmaxlen_strict(osl_t *osh, pktpool_t *pktp, uint16 max_pkts);
  145. extern void pktpool_emptycb_disable(pktpool_t *pktp, bool disable);
  146. extern bool pktpool_emptycb_disabled(pktpool_t *pktp);
  147. extern int pktpool_hostaddr_fill_register(pktpool_t *pktp, pktpool_cb_extn_t cb, void *arg1);
  148. extern int pktpool_rxcplid_fill_register(pktpool_t *pktp, pktpool_cb_extn_t cb, void *arg);
  149. extern void pktpool_invoke_dmarxfill(pktpool_t *pktp);
  150. extern int pkpool_haddr_avail_register_cb(pktpool_t *pktp, pktpool_cb_t cb, void *arg);
  151. #define POOLPTR(pp) ((pktpool_t *)(pp))
  152. #define POOLID(pp) (POOLPTR(pp)->id)
  153. #define POOLSETID(pp, ppid) (POOLPTR(pp)->id = (ppid))
  154. #define pktpool_tot_pkts(pp) (POOLPTR(pp)->n_pkts) /**< n_pkts = avail + in_use <= max_pkts */
  155. #define pktpool_avail(pp) (POOLPTR(pp)->avail)
  156. #define pktpool_max_pkt_bytes(pp) (POOLPTR(pp)->max_pkt_bytes)
  157. #define pktpool_max_pkts(pp) (POOLPTR(pp)->maxlen)
  158. /*
  159. * ----------------------------------------------------------------------------
  160. * A pool ID is assigned with a pkt pool during pool initialization. This is
  161. * done by maintaining a registry of all initialized pools, and the registry
  162. * index at which the pool is registered is used as the pool's unique ID.
  163. * ID 0 is reserved and is used to signify an invalid pool ID.
  164. * All packets henceforth allocated from a pool will be tagged with the pool's
  165. * unique ID. Packets allocated from the heap will use the reserved ID = 0.
  166. * Packets with non-zero pool id signify that they were allocated from a pool.
  167. * A maximum of 15 pools are supported, allowing a 4bit pool ID to be used
  168. * in place of a 32bit pool pointer in each packet.
  169. * ----------------------------------------------------------------------------
  170. */
  171. #define PKTPOOL_INVALID_ID (0)
  172. #define PKTPOOL_MAXIMUM_ID (15)
  173. /* Registry of pktpool(s) */
  174. /* Pool ID to/from Pool Pointer converters */
  175. #define PKTPOOL_ID2PTR(id) (get_pktpools_registry(id))
  176. #define PKTPOOL_PTR2ID(pp) (POOLID(pp))
  177. #ifdef BCMDBG_POOL
  178. extern int pktpool_dbg_register(pktpool_t *pktp, pktpool_cb_t cb, void *arg);
  179. extern int pktpool_start_trigger(pktpool_t *pktp, void *p);
  180. extern int pktpool_dbg_dump(pktpool_t *pktp);
  181. extern int pktpool_dbg_notify(pktpool_t *pktp);
  182. extern int pktpool_stats_dump(pktpool_t *pktp, pktpool_stats_t *stats);
  183. #endif /* BCMDBG_POOL */
  184. #ifdef BCMPKTPOOL
  185. #define SHARED_POOL (pktpool_shared)
  186. extern pktpool_t *pktpool_shared;
  187. #ifdef BCMFRAGPOOL
  188. #define SHARED_FRAG_POOL (pktpool_shared_lfrag)
  189. extern pktpool_t *pktpool_shared_lfrag;
  190. #endif // endif
  191. #ifdef BCMRESVFRAGPOOL
  192. #define RESV_FRAG_POOL (pktpool_resv_lfrag)
  193. #define RESV_POOL_INFO (resv_pool_info)
  194. #else
  195. #define RESV_FRAG_POOL ((struct pktpool *)NULL)
  196. #define RESV_POOL_INFO (NULL)
  197. #endif /* BCMRESVFRAGPOOL */
  198. /** PCIe SPLITRX related */
  199. #define SHARED_RXFRAG_POOL (pktpool_shared_rxlfrag)
  200. extern pktpool_t *pktpool_shared_rxlfrag;
  201. int hnd_pktpool_init(osl_t *osh);
  202. int hnd_pktpool_fill(pktpool_t *pktpool, bool minimal);
  203. void hnd_pktpool_refill(bool minimal);
  204. #ifdef BCMRESVFRAGPOOL
  205. extern pktpool_t *pktpool_resv_lfrag;
  206. extern struct resv_info *resv_pool_info;
  207. #endif /* BCMRESVFRAGPOOL */
  208. #else /* BCMPKTPOOL */
  209. #define SHARED_POOL ((struct pktpool *)NULL)
  210. #endif /* BCMPKTPOOL */
  211. #ifdef __cplusplus
  212. }
  213. #endif // endif
  214. #endif /* _hnd_pktpool_h_ */