2 * HND generic packet pool operation primitives
4 * Copyright (C) 1999-2016, Broadcom Corporation
6 * Unless you and Broadcom execute a separate written software license
7 * agreement governing use of this software, this software is licensed to you
8 * under the terms of the GNU General Public License version 2 (the "GPL"),
9 * available at http://www.broadcom.com/licenses/GPLv2.php, with the
10 * following added to such license:
12 * As a special exception, the copyright holders of this software give you
13 * permission to link this software with independent modules, and to copy and
14 * distribute the resulting executable under terms of your choice, provided that
15 * you also meet, for each linked independent module, the terms and conditions of
16 * the license of that module. An independent module is a module which is not
17 * derived from this software. The special exception does not apply to any
18 * modifications of the software.
20 * Notwithstanding the above, under no circumstances may you combine this
21 * software in any way with any other Broadcom software provided under a license
22 * other than the GPL, without Broadcom's express prior written consent.
25 * <<Broadcom-WL-IPTag/Open:>>
27 * $Id: hnd_pktpool.h 591285 2015-10-07 11:56:29Z $
30 #ifndef _hnd_pktpool_h_
31 #define _hnd_pktpool_h_
39 /* mutex macros for thread safe */
40 #ifdef HND_PKTPOOL_THREAD_SAFE
41 #define HND_PKTPOOL_MUTEX_DECL(mutex) OSL_EXT_MUTEX_DECL(mutex)
43 #define HND_PKTPOOL_MUTEX_DECL(mutex)
47 #define POOL_ENAB(pool) ((pool) && (pool)->inited)
48 #else /* BCMPKTPOOL */
49 #define POOL_ENAB(bus) 0
50 #endif /* BCMPKTPOOL */
52 #ifndef PKTPOOL_LEN_MAX
53 #define PKTPOOL_LEN_MAX 40
54 #endif /* PKTPOOL_LEN_MAX */
55 #define PKTPOOL_CB_MAX 3
56 #define PKTPOOL_CB_MAX_AVL 4
59 /* forward declaration */
62 typedef void (*pktpool_cb_t)(struct pktpool *pool, void *arg);
68 /** PCIe SPLITRX related: call back fn extension to populate host address in pool pkt */
69 typedef int (*pktpool_cb_extn_t)(struct pktpool *pool, void *arg1, void* pkt, bool arg2);
73 } pktpool_cbextn_info_t;
77 /* pkt pool debug states */
94 uint8 txdh; /* tx to host */
95 uint8 txd11; /* tx to d11 */
96 uint8 enq; /* waiting in q */
97 uint8 rxdh; /* rx from host */
98 uint8 rxd11; /* rx from d11 */
99 uint8 rxfill; /* dma_rxfill */
100 uint8 idle; /* avail in pool */
102 #endif /* BCMDBG_POOL */
104 typedef struct pktpool {
105 bool inited; /**< pktpool_init was successful */
106 uint8 type; /**< type of lbuf: basic, frag, etc */
107 uint8 id; /**< pktpool ID: index in registry */
108 bool istx; /**< direction: transmit or receive data path */
109 HND_PKTPOOL_MUTEX_DECL(mutex) /**< thread-safe mutex */
111 void * freelist; /**< free list: see PKTNEXTFREE(), PKTSETNEXTFREE() */
112 uint16 avail; /**< number of packets in pool's free list */
113 uint16 len; /**< number of packets managed by pool */
114 uint16 maxlen; /**< maximum size of pool <= PKTPOOL_LEN_MAX */
115 uint16 plen; /**< size of pkt buffer, excluding lbuf|lbuf_frag */
121 uint8 emptycb_disable; /**< Value of type enum pktpool_empty_cb_state */
122 pktpool_cbinfo_t *availcb_excl;
123 pktpool_cbinfo_t cbs[PKTPOOL_CB_MAX_AVL];
124 pktpool_cbinfo_t ecbs[PKTPOOL_CB_MAX];
125 pktpool_cbextn_info_t cbext; /**< PCIe SPLITRX related */
126 pktpool_cbextn_info_t rxcplidfn;
129 pktpool_cbinfo_t dbg_cbs[PKTPOOL_CB_MAX];
131 pktpool_dbg_t dbg_q[PKTPOOL_LEN_MAX + 1];
133 pktpool_cbinfo_t dmarxfill;
137 pktpool_t *get_pktpools_registry(int id);
139 /* Incarnate a pktpool registry. On success returns total_pools. */
140 extern int pktpool_attach(osl_t *osh, uint32 total_pools);
141 extern int pktpool_dettach(osl_t *osh); /* Relinquish registry */
143 extern int pktpool_init(osl_t *osh, pktpool_t *pktp, int *pktplen, int plen, bool istx, uint8 type);
144 extern int pktpool_deinit(osl_t *osh, pktpool_t *pktp);
145 extern int pktpool_fill(osl_t *osh, pktpool_t *pktp, bool minimal);
146 extern void* pktpool_get(pktpool_t *pktp);
147 extern void pktpool_free(pktpool_t *pktp, void *p);
148 extern int pktpool_add(pktpool_t *pktp, void *p);
149 extern int pktpool_avail_notify_normal(osl_t *osh, pktpool_t *pktp);
150 extern int pktpool_avail_notify_exclusive(osl_t *osh, pktpool_t *pktp, pktpool_cb_t cb);
151 extern int pktpool_avail_register(pktpool_t *pktp, pktpool_cb_t cb, void *arg);
152 extern int pktpool_empty_register(pktpool_t *pktp, pktpool_cb_t cb, void *arg);
153 extern int pktpool_setmaxlen(pktpool_t *pktp, uint16 maxlen);
154 extern int pktpool_setmaxlen_strict(osl_t *osh, pktpool_t *pktp, uint16 maxlen);
155 extern void pktpool_emptycb_disable(pktpool_t *pktp, bool disable);
156 extern bool pktpool_emptycb_disabled(pktpool_t *pktp);
157 extern int pktpool_hostaddr_fill_register(pktpool_t *pktp, pktpool_cb_extn_t cb, void *arg1);
158 extern int pktpool_rxcplid_fill_register(pktpool_t *pktp, pktpool_cb_extn_t cb, void *arg);
159 extern void pktpool_invoke_dmarxfill(pktpool_t *pktp);
160 extern int pkpool_haddr_avail_register_cb(pktpool_t *pktp, pktpool_cb_t cb, void *arg);
162 #define POOLPTR(pp) ((pktpool_t *)(pp))
163 #define POOLID(pp) (POOLPTR(pp)->id)
165 #define POOLSETID(pp, ppid) (POOLPTR(pp)->id = (ppid))
167 #define pktpool_len(pp) (POOLPTR(pp)->len)
168 #define pktpool_avail(pp) (POOLPTR(pp)->avail)
169 #define pktpool_plen(pp) (POOLPTR(pp)->plen)
170 #define pktpool_maxlen(pp) (POOLPTR(pp)->maxlen)
174 * ----------------------------------------------------------------------------
175 * A pool ID is assigned with a pkt pool during pool initialization. This is
176 * done by maintaining a registry of all initialized pools, and the registry
177 * index at which the pool is registered is used as the pool's unique ID.
178 * ID 0 is reserved and is used to signify an invalid pool ID.
179 * All packets henceforth allocated from a pool will be tagged with the pool's
180 * unique ID. Packets allocated from the heap will use the reserved ID = 0.
181 * Packets with non-zero pool id signify that they were allocated from a pool.
182 * A maximum of 15 pools are supported, allowing a 4bit pool ID to be used
183 * in place of a 32bit pool pointer in each packet.
184 * ----------------------------------------------------------------------------
186 #define PKTPOOL_INVALID_ID (0)
187 #define PKTPOOL_MAXIMUM_ID (15)
189 /* Registry of pktpool(s) */
190 /* Pool ID to/from Pool Pointer converters */
191 #define PKTPOOL_ID2PTR(id) (get_pktpools_registry(id))
192 #define PKTPOOL_PTR2ID(pp) (POOLID(pp))
195 extern int pktpool_dbg_register(pktpool_t *pktp, pktpool_cb_t cb, void *arg);
196 extern int pktpool_start_trigger(pktpool_t *pktp, void *p);
197 extern int pktpool_dbg_dump(pktpool_t *pktp);
198 extern int pktpool_dbg_notify(pktpool_t *pktp);
199 extern int pktpool_stats_dump(pktpool_t *pktp, pktpool_stats_t *stats);
200 #endif /* BCMDBG_POOL */
203 #define SHARED_POOL (pktpool_shared)
204 extern pktpool_t *pktpool_shared;
206 #define SHARED_FRAG_POOL (pktpool_shared_lfrag)
207 extern pktpool_t *pktpool_shared_lfrag;
210 /** PCIe SPLITRX related */
211 #define SHARED_RXFRAG_POOL (pktpool_shared_rxlfrag)
212 extern pktpool_t *pktpool_shared_rxlfrag;
214 void hnd_pktpool_init(osl_t *osh);
215 void hnd_pktpool_fill(pktpool_t *pktpool, bool minimal);
216 void hnd_pktpool_refill(bool minimal);
217 #else /* BCMPKTPOOL */
218 #define SHARED_POOL ((struct pktpool *)NULL)
219 #endif /* BCMPKTPOOL */
225 #endif /* _hnd_pktpool_h_ */