xref: /freebsd/sys/contrib/ncsw/inc/Peripherals/dpaa_ext.h (revision e0c4386e7e71d93b0edc0c8fa156263fc4a8b0b6)
1 /* Copyright (c) 2008-2012 Freescale Semiconductor, Inc
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *     * Redistributions of source code must retain the above copyright
7  *       notice, this list of conditions and the following disclaimer.
8  *     * Redistributions in binary form must reproduce the above copyright
9  *       notice, this list of conditions and the following disclaimer in the
10  *       documentation and/or other materials provided with the distribution.
11  *     * Neither the name of Freescale Semiconductor nor the
12  *       names of its contributors may be used to endorse or promote products
13  *       derived from this software without specific prior written permission.
14  *
15  *
16  * ALTERNATIVELY, this software may be distributed under the terms of the
17  * GNU General Public License ("GPL") as published by the Free Software
18  * Foundation, either version 2 of that License or (at your option) any
19  * later version.
20  *
21  * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
22  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24  * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
25  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 
34 /**************************************************************************//**
35  @File          dpaa_ext.h
36 
37  @Description   DPAA Application Programming Interface.
38 *//***************************************************************************/
39 #ifndef __DPAA_EXT_H
40 #define __DPAA_EXT_H
41 
42 #include "std_ext.h"
43 #include "error_ext.h"
44 
45 
46 /**************************************************************************//**
47  @Group         DPAA_grp Data Path Acceleration Architecture API
48 
49  @Description   DPAA API functions, definitions and enums.
50 
51  @{
52 *//***************************************************************************/
53 
54 #if defined(__MWERKS__) && !defined(__GNUC__)
55 #pragma pack(push,1)
56 #endif /* defined(__MWERKS__) && ... */
57 
58 #include <machine/endian.h>
59 
60 #ifndef __BYTE_ORDER__
61 #define __BYTE_ORDER__ BYTE_ORDER
62 #endif
63 #ifndef __ORDER_BIG_ENDIAN__
64 #define __ORDER_BIG_ENDIAN__	BIG_ENDIAN
65 #endif
66 
67 /**************************************************************************//**
68  @Description   Frame descriptor
69 *//***************************************************************************/
70 typedef _Packed struct t_DpaaFD {
71 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
72     volatile uint8_t liodn;
73     volatile uint8_t bpid;
74     volatile uint8_t elion;
75     volatile uint8_t addrh;
76     volatile uint32_t addrl;
77 #else
78     volatile uint32_t addrl;
79     volatile uint8_t addrh;
80     volatile uint8_t elion;
81     volatile uint8_t bpid;
82     volatile uint8_t liodn;
83  #endif
84     volatile uint32_t    length;            /**< Frame length */
85     volatile uint32_t    status;            /**< FD status */
86 } _PackedType t_DpaaFD;
87 
88 /**************************************************************************//**
89  @Description   enum for defining frame format
90 *//***************************************************************************/
91 typedef enum e_DpaaFDFormatType {
92     e_DPAA_FD_FORMAT_TYPE_SHORT_SBSF  = 0x0,   /**< Simple frame Single buffer; Offset and
93                                                     small length (9b OFFSET, 20b LENGTH) */
94     e_DPAA_FD_FORMAT_TYPE_LONG_SBSF   = 0x2,   /**< Simple frame, single buffer; big length
95                                                     (29b LENGTH ,No OFFSET) */
96     e_DPAA_FD_FORMAT_TYPE_SHORT_MBSF  = 0x4,   /**< Simple frame, Scatter Gather table; Offset
97                                                     and small length (9b OFFSET, 20b LENGTH) */
98     e_DPAA_FD_FORMAT_TYPE_LONG_MBSF   = 0x6,   /**< Simple frame, Scatter Gather table;
99                                                     big length (29b LENGTH ,No OFFSET) */
100     e_DPAA_FD_FORMAT_TYPE_COMPOUND    = 0x1,   /**< Compound Frame (29b CONGESTION-WEIGHT
101                                                     No LENGTH or OFFSET) */
102     e_DPAA_FD_FORMAT_TYPE_DUMMY
103 } e_DpaaFDFormatType;
104 
105 /**************************************************************************//**
106  @Collection   Frame descriptor macros
107 *//***************************************************************************/
108 #define DPAA_FD_DD_MASK       0xc0000000           /**< FD DD field mask */
109 #define DPAA_FD_PID_MASK      0x3f000000           /**< FD PID field mask */
110 #define DPAA_FD_ELIODN_MASK   0x0000f000           /**< FD ELIODN field mask */
111 #define DPAA_FD_BPID_MASK     0x00ff0000           /**< FD BPID field mask */
112 #define DPAA_FD_ADDRH_MASK    0x000000ff           /**< FD ADDRH field mask */
113 #define DPAA_FD_ADDRL_MASK    0xffffffff           /**< FD ADDRL field mask */
114 #define DPAA_FD_FORMAT_MASK   0xe0000000           /**< FD FORMAT field mask */
115 #define DPAA_FD_OFFSET_MASK   0x1ff00000           /**< FD OFFSET field mask */
116 #define DPAA_FD_LENGTH_MASK   0x000fffff           /**< FD LENGTH field mask */
117 
118 #define DPAA_FD_GET_ADDRH(fd)         ((t_DpaaFD *)fd)->addrh                       /**< Macro to get FD ADDRH field */
119 #define DPAA_FD_GET_ADDRL(fd)         ((t_DpaaFD *)fd)->addrl                                           /**< Macro to get FD ADDRL field */
120 #define DPAA_FD_GET_PHYS_ADDR(fd)     ((physAddress_t)(((uint64_t)DPAA_FD_GET_ADDRH(fd) << 32) | (uint64_t)DPAA_FD_GET_ADDRL(fd))) /**< Macro to get FD ADDR field */
121 #define DPAA_FD_GET_FORMAT(fd)        ((((t_DpaaFD *)fd)->length & DPAA_FD_FORMAT_MASK) >> (31-2))      /**< Macro to get FD FORMAT field */
122 #define DPAA_FD_GET_OFFSET(fd)        ((((t_DpaaFD *)fd)->length & DPAA_FD_OFFSET_MASK) >> (31-11))     /**< Macro to get FD OFFSET field */
123 #define DPAA_FD_GET_LENGTH(fd)        (((t_DpaaFD *)fd)->length & DPAA_FD_LENGTH_MASK)                  /**< Macro to get FD LENGTH field */
124 #define DPAA_FD_GET_STATUS(fd)        ((t_DpaaFD *)fd)->status                                          /**< Macro to get FD STATUS field */
125 #define DPAA_FD_GET_ADDR(fd)          XX_PhysToVirt(DPAA_FD_GET_PHYS_ADDR(fd))                          /**< Macro to get FD ADDR (virtual) */
126 
127 #define DPAA_FD_SET_ADDRH(fd,val)     ((t_DpaaFD *)fd)->addrh = (val)            /**< Macro to set FD ADDRH field */
128 #define DPAA_FD_SET_ADDRL(fd,val)     ((t_DpaaFD *)fd)->addrl = (val)                                   /**< Macro to set FD ADDRL field */
129 #define DPAA_FD_SET_ADDR(fd,val)                            \
130 do {                                                        \
131     uint64_t physAddr = (uint64_t)(XX_VirtToPhys(val));     \
132     DPAA_FD_SET_ADDRH(fd, ((uint32_t)(physAddr >> 32)));    \
133     DPAA_FD_SET_ADDRL(fd, (uint32_t)physAddr);              \
134 } while (0)                                                                                             /**< Macro to set FD ADDR field */
135 #define DPAA_FD_SET_FORMAT(fd,val)    (((t_DpaaFD *)fd)->length = ((((t_DpaaFD *)fd)->length & ~DPAA_FD_FORMAT_MASK) | (((val)  << (31-2))& DPAA_FD_FORMAT_MASK)))  /**< Macro to set FD FORMAT field */
136 #define DPAA_FD_SET_OFFSET(fd,val)    (((t_DpaaFD *)fd)->length = ((((t_DpaaFD *)fd)->length & ~DPAA_FD_OFFSET_MASK) | (((val) << (31-11))& DPAA_FD_OFFSET_MASK) )) /**< Macro to set FD OFFSET field */
137 #define DPAA_FD_SET_LENGTH(fd,val)    (((t_DpaaFD *)fd)->length = (((t_DpaaFD *)fd)->length & ~DPAA_FD_LENGTH_MASK) | ((val) & DPAA_FD_LENGTH_MASK))                /**< Macro to set FD LENGTH field */
138 #define DPAA_FD_SET_STATUS(fd,val)    ((t_DpaaFD *)fd)->status = (val)                                  /**< Macro to set FD STATUS field */
139 /* @} */
140 
141 /**************************************************************************//**
142  @Description   Frame Scatter/Gather Table Entry
143 *//***************************************************************************/
144 typedef _Packed struct t_DpaaSGTE {
145     volatile uint32_t    addrh;        /**< Buffer Address high */
146     volatile uint32_t    addrl;        /**< Buffer Address low */
147     volatile uint32_t    length;       /**< Buffer length */
148     volatile uint32_t    offset;       /**< SGTE offset */
149 } _PackedType t_DpaaSGTE;
150 
151 #define DPAA_NUM_OF_SG_TABLE_ENTRY 16
152 
153 /**************************************************************************//**
154  @Description   Frame Scatter/Gather Table
155 *//***************************************************************************/
156 typedef _Packed struct t_DpaaSGT {
157     t_DpaaSGTE    tableEntry[DPAA_NUM_OF_SG_TABLE_ENTRY];
158                                     /**< Structure that holds information about
159                                          a single S/G entry. */
160 } _PackedType t_DpaaSGT;
161 
162 /**************************************************************************//**
163  @Description   Compound Frame Table
164 *//***************************************************************************/
165 typedef _Packed struct t_DpaaCompTbl {
166     t_DpaaSGTE    outputBuffInfo;   /**< Structure that holds information about
167                                          the compound-frame output buffer;
168                                          NOTE: this may point to a S/G table */
169     t_DpaaSGTE    inputBuffInfo;    /**< Structure that holds information about
170                                          the compound-frame input buffer;
171                                          NOTE: this may point to a S/G table */
172 } _PackedType t_DpaaCompTbl;
173 
174 /**************************************************************************//**
175  @Collection   Frame Scatter/Gather Table Entry macros
176 *//***************************************************************************/
177 #define DPAA_SGTE_ADDRH_MASK    0x000000ff           /**< SGTE ADDRH field mask */
178 #define DPAA_SGTE_ADDRL_MASK    0xffffffff           /**< SGTE ADDRL field mask */
179 #define DPAA_SGTE_E_MASK        0x80000000           /**< SGTE Extension field mask */
180 #define DPAA_SGTE_F_MASK        0x40000000           /**< SGTE Final field mask */
181 #define DPAA_SGTE_LENGTH_MASK   0x3fffffff           /**< SGTE LENGTH field mask */
182 #define DPAA_SGTE_BPID_MASK     0x00ff0000           /**< SGTE BPID field mask */
183 #define DPAA_SGTE_OFFSET_MASK   0x00001fff           /**< SGTE OFFSET field mask */
184 
185 #define DPAA_SGTE_GET_ADDRH(sgte)         (((t_DpaaSGTE *)sgte)->addrh & DPAA_SGTE_ADDRH_MASK)              /**< Macro to get SGTE ADDRH field */
186 #define DPAA_SGTE_GET_ADDRL(sgte)         ((t_DpaaSGTE *)sgte)->addrl                                       /**< Macro to get SGTE ADDRL field */
187 #define DPAA_SGTE_GET_PHYS_ADDR(sgte)     ((physAddress_t)(((uint64_t)DPAA_SGTE_GET_ADDRH(sgte) << 32) | (uint64_t)DPAA_SGTE_GET_ADDRL(sgte))) /**< Macro to get FD ADDR field */
188 #define DPAA_SGTE_GET_EXTENSION(sgte)     ((((t_DpaaSGTE *)sgte)->length & DPAA_SGTE_E_MASK) >> (31-0))     /**< Macro to get SGTE EXTENSION field */
189 #define DPAA_SGTE_GET_FINAL(sgte)         ((((t_DpaaSGTE *)sgte)->length & DPAA_SGTE_F_MASK) >> (31-1))     /**< Macro to get SGTE FINAL field */
190 #define DPAA_SGTE_GET_LENGTH(sgte)        (((t_DpaaSGTE *)sgte)->length & DPAA_SGTE_LENGTH_MASK)            /**< Macro to get SGTE LENGTH field */
191 #define DPAA_SGTE_GET_BPID(sgte)          ((((t_DpaaSGTE *)sgte)->offset & DPAA_SGTE_BPID_MASK) >> (31-15)) /**< Macro to get SGTE BPID field */
192 #define DPAA_SGTE_GET_OFFSET(sgte)        (((t_DpaaSGTE *)sgte)->offset & DPAA_SGTE_OFFSET_MASK)            /**< Macro to get SGTE OFFSET field */
193 #define DPAA_SGTE_GET_ADDR(sgte)          XX_PhysToVirt(DPAA_SGTE_GET_PHYS_ADDR(sgte))
194 
195 #define DPAA_SGTE_SET_ADDRH(sgte,val)     (((t_DpaaSGTE *)sgte)->addrh = ((((t_DpaaSGTE *)sgte)->addrh & ~DPAA_SGTE_ADDRH_MASK) | ((val) & DPAA_SGTE_ADDRH_MASK))) /**< Macro to set SGTE ADDRH field */
196 #define DPAA_SGTE_SET_ADDRL(sgte,val)     ((t_DpaaSGTE *)sgte)->addrl = (val)                                 /**< Macro to set SGTE ADDRL field */
197 #define DPAA_SGTE_SET_ADDR(sgte,val)                            \
198 do {                                                            \
199     uint64_t physAddr = (uint64_t)(XX_VirtToPhys(val));         \
200     DPAA_SGTE_SET_ADDRH(sgte, ((uint32_t)(physAddr >> 32)));    \
201     DPAA_SGTE_SET_ADDRL(sgte, (uint32_t)physAddr);              \
202 } while (0)                                                                                                 /**< Macro to set SGTE ADDR field */
203 #define DPAA_SGTE_SET_EXTENSION(sgte,val) (((t_DpaaSGTE *)sgte)->length = ((((t_DpaaSGTE *)sgte)->length & ~DPAA_SGTE_E_MASK) | (((val)  << (31-0))& DPAA_SGTE_E_MASK)))            /**< Macro to set SGTE EXTENSION field */
204 #define DPAA_SGTE_SET_FINAL(sgte,val)     (((t_DpaaSGTE *)sgte)->length = ((((t_DpaaSGTE *)sgte)->length & ~DPAA_SGTE_F_MASK) | (((val)  << (31-1))& DPAA_SGTE_F_MASK)))            /**< Macro to set SGTE FINAL field */
205 #define DPAA_SGTE_SET_LENGTH(sgte,val)    (((t_DpaaSGTE *)sgte)->length = (((t_DpaaSGTE *)sgte)->length & ~DPAA_SGTE_LENGTH_MASK) | ((val) & DPAA_SGTE_LENGTH_MASK))                /**< Macro to set SGTE LENGTH field */
206 #define DPAA_SGTE_SET_BPID(sgte,val)      (((t_DpaaSGTE *)sgte)->offset = ((((t_DpaaSGTE *)sgte)->offset & ~DPAA_SGTE_BPID_MASK) | (((val)  << (31-15))& DPAA_SGTE_BPID_MASK)))     /**< Macro to set SGTE BPID field */
207 #define DPAA_SGTE_SET_OFFSET(sgte,val)    (((t_DpaaSGTE *)sgte)->offset = ((((t_DpaaSGTE *)sgte)->offset & ~DPAA_SGTE_OFFSET_MASK) | (((val) << (31-31))& DPAA_SGTE_OFFSET_MASK) )) /**< Macro to set SGTE OFFSET field */
208 /* @} */
209 
210 #if defined(__MWERKS__) && !defined(__GNUC__)
211 #pragma pack(pop)
212 #endif /* defined(__MWERKS__) && ... */
213 
214 #define DPAA_LIODN_DONT_OVERRIDE    (-1)
215 
216 /** @} */ /* end of DPAA_grp group */
217 
218 
219 #endif /* __DPAA_EXT_H */
220