1 /******************************************************************************
2
3 � 1995-2003, 2004, 2005-2011 Freescale Semiconductor, Inc.
4 All rights reserved.
5
6 This is proprietary source code of Freescale Semiconductor Inc.,
7 and its use is subject to the NetComm Device Drivers EULA.
8 The copyright notice above does not evidence any actual or intended
9 publication of such source code.
10
11 ALTERNATIVELY, redistribution and use in source and binary forms, with
12 or without modification, are permitted provided that the following
13 conditions are met:
14 * Redistributions of source code must retain the above copyright
15 notice, this list of conditions and the following disclaimer.
16 * Redistributions in binary form must reproduce the above copyright
17 notice, this list of conditions and the following disclaimer in the
18 documentation and/or other materials provided with the distribution.
19 * Neither the name of Freescale Semiconductor nor the
20 names of its contributors may be used to endorse or promote products
21 derived from this software without specific prior written permission.
22
23 THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
24 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
27 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 *
34
35 **************************************************************************/
36 /******************************************************************************
37 @File fsl_bman.h
38
39 @Description BM header
40 *//***************************************************************************/
41 #ifndef __FSL_BMAN_H
42 #define __FSL_BMAN_H
43
44 #include "std_ext.h"
45
46
47 /*************************************************/
48 /* BMan s/w corenet portal, low-level i/face */
49 /*************************************************/
50 typedef enum {
51 e_BmPortalPCI = 0, /* PI index, cache-inhibited */
52 e_BmPortalPCE, /* PI index, cache-enabled */
53 e_BmPortalPVB /* valid-bit */
54 } e_BmPortalProduceMode;
55
56 typedef enum {
57 e_BmPortalRcrCCI = 0, /* CI index, cache-inhibited */
58 e_BmPortalRcrCCE /* CI index, cache-enabled */
59 } e_BmPortalRcrConsumeMode;
60
61 /* Portal constants */
62 #define BM_RCR_SIZE 8
63
64 /* Hardware constants */
65 enum bm_isr_reg {
66 bm_isr_status = 0,
67 bm_isr_enable = 1,
68 bm_isr_disable = 2,
69 bm_isr_inhibit = 3
70 };
71
72 /* Represents s/w corenet portal mapped data structures */
73 struct bm_rcr_entry; /* RCR (Release Command Ring) entries */
74 struct bm_mc_command; /* MC (Management Command) command */
75 struct bm_mc_result; /* MC result */
76
77 /* This type represents a s/w corenet portal space, and is used for creating the
78 * portal objects within it (RCR, etc) */
79 struct bm_portal;
80
81 /* This wrapper represents a bit-array for the depletion state of the 64 Bman
82 * buffer pools. */
83 struct bman_depletion {
84 uint32_t __state[2];
85 };
86 #define __bmdep_word(x) ((x) >> 5)
87 #define __bmdep_shift(x) ((x) & 0x1f)
88 #define __bmdep_bit(x) (0x80000000 >> __bmdep_shift(x))
bman_depletion_init(struct bman_depletion * c)89 static __inline__ void bman_depletion_init(struct bman_depletion *c)
90 {
91 c->__state[0] = c->__state[1] = 0;
92 }
bman_depletion_fill(struct bman_depletion * c)93 static __inline__ void bman_depletion_fill(struct bman_depletion *c)
94 {
95 c->__state[0] = c->__state[1] = (uint32_t)~0;
96 }
bman_depletion_get(const struct bman_depletion * c,uint8_t bpid)97 static __inline__ int bman_depletion_get(const struct bman_depletion *c, uint8_t bpid)
98 {
99 return (int)(c->__state[__bmdep_word(bpid)] & __bmdep_bit(bpid));
100 }
bman_depletion_set(struct bman_depletion * c,uint8_t bpid)101 static __inline__ void bman_depletion_set(struct bman_depletion *c, uint8_t bpid)
102 {
103 c->__state[__bmdep_word(bpid)] |= __bmdep_bit(bpid);
104 }
bman_depletion_unset(struct bman_depletion * c,uint8_t bpid)105 static __inline__ void bman_depletion_unset(struct bman_depletion *c, uint8_t bpid)
106 {
107 c->__state[__bmdep_word(bpid)] &= ~__bmdep_bit(bpid);
108 }
109
110 /* ------------------------------ */
111 /* --- Portal enumeration API --- */
112
113 /* ------------------------------ */
114 /* --- Buffer pool allocation --- */
115 #define BM_POOL_THRESH_SW_ENTER 0
116 #define BM_POOL_THRESH_SW_EXIT 1
117 #define BM_POOL_THRESH_HW_ENTER 2
118 #define BM_POOL_THRESH_HW_EXIT 3
119
120 /* --------------- */
121 /* --- RCR API --- */
122
123 /* Create/destroy */
124 t_Error bm_rcr_init(struct bm_portal *portal,
125 e_BmPortalProduceMode pmode,
126 e_BmPortalRcrConsumeMode cmode);
127 void bm_rcr_finish(struct bm_portal *portal);
128
129 /* Start/abort RCR entry */
130 struct bm_rcr_entry *bm_rcr_start(struct bm_portal *portal);
131 void bm_rcr_abort(struct bm_portal *portal);
132
133 /* For PI modes only. This presumes a started but uncommitted RCR entry. If
134 * there's no more room in the RCR, this function returns NULL. Otherwise it
135 * returns the next RCR entry and increments an internal PI counter without
136 * flushing it to h/w. */
137 struct bm_rcr_entry *bm_rcr_pend_and_next(struct bm_portal *portal, uint8_t myverb);
138
139 /* Commit RCR entries, including pending ones (aka "write PI") */
140 void bm_rcr_pci_commit(struct bm_portal *portal, uint8_t myverb);
141 void bm_rcr_pce_prefetch(struct bm_portal *portal);
142 void bm_rcr_pce_commit(struct bm_portal *portal, uint8_t myverb);
143 void bm_rcr_pvb_commit(struct bm_portal *portal, uint8_t myverb);
144
145 /* Track h/w consumption. Returns non-zero if h/w had consumed previously
146 * unconsumed RCR entries. */
147 uint8_t bm_rcr_cci_update(struct bm_portal *portal);
148 void bm_rcr_cce_prefetch(struct bm_portal *portal);
149 uint8_t bm_rcr_cce_update(struct bm_portal *portal);
150 /* Returns the number of available RCR entries */
151 uint8_t bm_rcr_get_avail(struct bm_portal *portal);
152 /* Returns the number of unconsumed RCR entries */
153 uint8_t bm_rcr_get_fill(struct bm_portal *portal);
154
155 /* Read/write the RCR interrupt threshold */
156 uint8_t bm_rcr_get_ithresh(struct bm_portal *portal);
157 void bm_rcr_set_ithresh(struct bm_portal *portal, uint8_t ithresh);
158
159
160 /* ------------------------------ */
161 /* --- Management command API --- */
162
163 /* Create/destroy */
164 t_Error bm_mc_init(struct bm_portal *portal);
165 void bm_mc_finish(struct bm_portal *portal);
166
167 /* Start/abort mgmt command */
168 struct bm_mc_command *bm_mc_start(struct bm_portal *portal);
169 void bm_mc_abort(struct bm_portal *portal);
170
171 /* Writes 'verb' with appropriate 'vbit'. Invalidates and pre-fetches the
172 * response. */
173 void bm_mc_commit(struct bm_portal *portal, uint8_t myverb);
174
175 /* Poll for result. If NULL, invalidates and prefetches for the next call. */
176 struct bm_mc_result *bm_mc_result(struct bm_portal *portal);
177
178
179 /* ------------------------------------- */
180 /* --- Portal interrupt register API --- */
181
182 /* For a quick explanation of the Bman interrupt model, see the comments in the
183 * equivalent section of the qman_portal.h header.
184 */
185
186 /* Create/destroy */
187 t_Error bm_isr_init(struct bm_portal *portal);
188 void bm_isr_finish(struct bm_portal *portal);
189
190 /* BSCN masking is a per-portal configuration */
191 void bm_isr_bscn_mask(struct bm_portal *portal, uint8_t bpid, int enable);
192
193 /* Used by all portal interrupt registers except 'inhibit' */
194 #define BM_PIRQ_RCRI 0x00000002 /* RCR Ring (below threshold) */
195 #define BM_PIRQ_BSCN 0x00000001 /* Buffer depletion State Change */
196
197 /* These are bm_<reg>_<verb>(). So for example, bm_disable_write() means "write
198 * the disable register" rather than "disable the ability to write". */
199 #define bm_isr_status_read(bm) __bm_isr_read(bm, bm_isr_status)
200 #define bm_isr_status_clear(bm, m) __bm_isr_write(bm, bm_isr_status, m)
201 #define bm_isr_enable_read(bm) __bm_isr_read(bm, bm_isr_enable)
202 #define bm_isr_enable_write(bm, v) __bm_isr_write(bm, bm_isr_enable, v)
203 #define bm_isr_disable_read(bm) __bm_isr_read(bm, bm_isr_disable)
204 #define bm_isr_disable_write(bm, v) __bm_isr_write(bm, bm_isr_disable, v)
205 #define bm_isr_inhibit(bm) __bm_isr_write(bm, bm_isr_inhibit, 1)
206 #define bm_isr_uninhibit(bm) __bm_isr_write(bm, bm_isr_inhibit, 0)
207
208 /* Don't use these, use the wrappers above*/
209 uint32_t __bm_isr_read(struct bm_portal *portal, enum bm_isr_reg n);
210 void __bm_isr_write(struct bm_portal *portal, enum bm_isr_reg n, uint32_t val);
211
212 /* ------------------------------------------------------- */
213 /* --- Bman data structures (and associated constants) --- */
214 /* Code-reduction, define a wrapper for 48-bit buffers. In cases where a buffer
215 * pool id specific to this buffer is needed (BM_RCR_VERB_CMD_BPID_MULTI,
216 * BM_MCC_VERB_ACQUIRE), the 'bpid' field is used. */
217
218 #define BM_RCR_VERB_VBIT 0x80
219 #define BM_RCR_VERB_CMD_MASK 0x70 /* one of two values; */
220 #define BM_RCR_VERB_CMD_BPID_SINGLE 0x20
221 #define BM_RCR_VERB_CMD_BPID_MULTI 0x30
222 #define BM_RCR_VERB_BUFCOUNT_MASK 0x0f /* values 1..8 */
223
224 #define BM_MCC_VERB_VBIT 0x80
225 #define BM_MCC_VERB_CMD_MASK 0x70 /* where the verb contains; */
226 #define BM_MCC_VERB_CMD_ACQUIRE 0x10
227 #define BM_MCC_VERB_CMD_QUERY 0x40
228 #define BM_MCC_VERB_ACQUIRE_BUFCOUNT 0x0f /* values 1..8 go here */
229
230
231 #if defined(__MWERKS__) && !defined(__GNUC__)
232 #pragma pack(push,1)
233 #endif /* defined(__MWERKS__) && ... */
234 #define MEM_MAP_START
235
236 _Packed struct bm_buffer {
237 volatile uint8_t reserved1;
238 volatile uint8_t bpid;
239 volatile uint16_t hi; /* High 16-bits of 48-bit address */
240 volatile uint32_t lo; /* Low 32-bits of 48-bit address */
241 } _PackedType;
242
243 /* See 1.5.3.5.4: "Release Command" */
244 _Packed struct bm_rcr_entry {
245 _Packed union {
246 _Packed struct {
247 volatile uint8_t __dont_write_directly__verb;
248 volatile uint8_t bpid; /* used with BM_RCR_VERB_CMD_BPID_SINGLE */
249 volatile uint8_t reserved1[62];
250 } _PackedType;
251 volatile struct bm_buffer bufs[8];
252 } _PackedType;
253 } _PackedType;
254
255 /* See 1.5.3.1: "Acquire Command" */
256 /* See 1.5.3.2: "Query Command" */
257 _Packed struct bm_mc_command {
258 volatile uint8_t __dont_write_directly__verb;
259 _Packed union {
260 _Packed struct bm_mcc_acquire {
261 volatile uint8_t bpid;
262 volatile uint8_t reserved1[62];
263 } _PackedType acquire;
264 _Packed struct bm_mcc_query {
265 volatile uint8_t reserved1[63];
266 } _PackedType query;
267 } _PackedType;
268 } _PackedType;
269
270 /* See 1.5.3.3: "Acquire Reponse" */
271 /* See 1.5.3.4: "Query Reponse" */
272 _Packed struct bm_mc_result {
273 _Packed union {
274 _Packed struct {
275 volatile uint8_t verb;
276 volatile uint8_t reserved1[63];
277 } _PackedType;
278 _Packed union {
279 _Packed struct {
280 volatile uint8_t reserved1;
281 volatile uint8_t bpid;
282 volatile uint8_t reserved2[62];
283 } _PackedType;
284 volatile struct bm_buffer bufs[8];
285 } _PackedType acquire;
286 _Packed struct {
287 volatile uint8_t reserved1[32];
288 /* "availability state" and "depletion state" */
289 _Packed struct {
290 volatile uint8_t reserved1[8];
291 /* Access using bman_depletion_***() */
292 volatile struct bman_depletion state;
293 } _PackedType as, ds;
294 } _PackedType query;
295 } _PackedType;
296 } _PackedType;
297
298 #define MEM_MAP_END
299 #if defined(__MWERKS__) && !defined(__GNUC__)
300 #pragma pack(pop)
301 #endif /* defined(__MWERKS__) && ... */
302
303
304 #define BM_MCR_VERB_VBIT 0x80
305 #define BM_MCR_VERB_CMD_MASK BM_MCC_VERB_CMD_MASK
306 #define BM_MCR_VERB_CMD_ACQUIRE BM_MCC_VERB_CMD_ACQUIRE
307 #define BM_MCR_VERB_CMD_QUERY BM_MCC_VERB_CMD_QUERY
308 #define BM_MCR_VERB_CMD_ERR_INVALID 0x60
309 #define BM_MCR_VERB_CMD_ERR_ECC 0x70
310 #define BM_MCR_VERB_ACQUIRE_BUFCOUNT BM_MCC_VERB_ACQUIRE_BUFCOUNT /* 0..8 */
311 /* Determine the "availability state" of pool 'p' from a query result 'r' */
312 #define BM_MCR_QUERY_AVAILABILITY(r,p) bman_depletion_get(&r->query.as.state,p)
313 /* Determine the "depletion state" of pool 'p' from a query result 'r' */
314 #define BM_MCR_QUERY_DEPLETION(r,p) bman_depletion_get(&r->query.ds.state,p)
315
316
317 /* Portal and Buffer Pools */
318 /* ----------------------- */
319
320 /* Flags to bman_create_portal() */
321 #define BMAN_PORTAL_FLAG_IRQ 0x00000001 /* use interrupt handler */
322 #define BMAN_PORTAL_FLAG_IRQ_FAST 0x00000002 /* ... for fast-path too! */
323 #define BMAN_PORTAL_FLAG_COMPACT 0x00000004 /* use compaction algorithm */
324 #define BMAN_PORTAL_FLAG_RECOVER 0x00000008 /* recovery mode */
325 #define BMAN_PORTAL_FLAG_WAIT 0x00000010 /* wait if RCR is full */
326 #define BMAN_PORTAL_FLAG_WAIT_INT 0x00000020 /* if wait, interruptible? */
327 #define BMAN_PORTAL_FLAG_CACHE 0x00000400 /* use cache-able area for rings */
328
329 /* Flags to bman_new_pool() */
330 #define BMAN_POOL_FLAG_NO_RELEASE 0x00000001 /* can't release to pool */
331 #define BMAN_POOL_FLAG_ONLY_RELEASE 0x00000002 /* can only release to pool */
332 #define BMAN_POOL_FLAG_DEPLETION 0x00000004 /* track depletion entry/exit */
333 #define BMAN_POOL_FLAG_DYNAMIC_BPID 0x00000008 /* (de)allocate bpid */
334 #define BMAN_POOL_FLAG_THRESH 0x00000010 /* set depletion thresholds */
335 #define BMAN_POOL_FLAG_STOCKPILE 0x00000020 /* stockpile to reduce hw ops */
336
337 /* Flags to bman_release() */
338 #define BMAN_RELEASE_FLAG_WAIT 0x00000001 /* wait if RCR is full */
339 #define BMAN_RELEASE_FLAG_WAIT_INT 0x00000002 /* if we wait, interruptible? */
340 #define BMAN_RELEASE_FLAG_WAIT_SYNC 0x00000004 /* if wait, until consumed? */
341 #define BMAN_RELEASE_FLAG_NOW 0x00000008 /* issue immediate release */
342
343 /* Flags to bman_acquire() */
344 #define BMAN_ACQUIRE_FLAG_STOCKPILE 0x00000001 /* no hw op, stockpile only */
345
346
347 #endif /* __FSL_BMAN_H */
348