xref: /freebsd/sys/contrib/ncsw/inc/Peripherals/dpaa_ext.h (revision 406a584d7e80c2617dc035ede0d922215a12141c)
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 #define __BYTE_ORDER__ BYTE_ORDER
61 #define __ORDER_BIG_ENDIAN__	BIG_ENDIAN
62 
63 /**************************************************************************//**
64  @Description   Frame descriptor
65 *//***************************************************************************/
66 typedef _Packed struct t_DpaaFD {
67 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
68     volatile uint8_t liodn;
69     volatile uint8_t bpid;
70     volatile uint8_t elion;
71     volatile uint8_t addrh;
72     volatile uint32_t addrl;
73 #else
74     volatile uint32_t addrl;
75     volatile uint8_t addrh;
76     volatile uint8_t elion;
77     volatile uint8_t bpid;
78     volatile uint8_t liodn;
79  #endif
80     volatile uint32_t    length;            /**< Frame length */
81     volatile uint32_t    status;            /**< FD status */
82 } _PackedType t_DpaaFD;
83 
84 /**************************************************************************//**
85  @Description   enum for defining frame format
86 *//***************************************************************************/
87 typedef enum e_DpaaFDFormatType {
88     e_DPAA_FD_FORMAT_TYPE_SHORT_SBSF  = 0x0,   /**< Simple frame Single buffer; Offset and
89                                                     small length (9b OFFSET, 20b LENGTH) */
90     e_DPAA_FD_FORMAT_TYPE_LONG_SBSF   = 0x2,   /**< Simple frame, single buffer; big length
91                                                     (29b LENGTH ,No OFFSET) */
92     e_DPAA_FD_FORMAT_TYPE_SHORT_MBSF  = 0x4,   /**< Simple frame, Scatter Gather table; Offset
93                                                     and small length (9b OFFSET, 20b LENGTH) */
94     e_DPAA_FD_FORMAT_TYPE_LONG_MBSF   = 0x6,   /**< Simple frame, Scatter Gather table;
95                                                     big length (29b LENGTH ,No OFFSET) */
96     e_DPAA_FD_FORMAT_TYPE_COMPOUND    = 0x1,   /**< Compound Frame (29b CONGESTION-WEIGHT
97                                                     No LENGTH or OFFSET) */
98     e_DPAA_FD_FORMAT_TYPE_DUMMY
99 } e_DpaaFDFormatType;
100 
101 /**************************************************************************//**
102  @Collection   Frame descriptor macros
103 *//***************************************************************************/
104 #define DPAA_FD_DD_MASK       0xc0000000           /**< FD DD field mask */
105 #define DPAA_FD_PID_MASK      0x3f000000           /**< FD PID field mask */
106 #define DPAA_FD_ELIODN_MASK   0x0000f000           /**< FD ELIODN field mask */
107 #define DPAA_FD_BPID_MASK     0x00ff0000           /**< FD BPID field mask */
108 #define DPAA_FD_ADDRH_MASK    0x000000ff           /**< FD ADDRH field mask */
109 #define DPAA_FD_ADDRL_MASK    0xffffffff           /**< FD ADDRL field mask */
110 #define DPAA_FD_FORMAT_MASK   0xe0000000           /**< FD FORMAT field mask */
111 #define DPAA_FD_OFFSET_MASK   0x1ff00000           /**< FD OFFSET field mask */
112 #define DPAA_FD_LENGTH_MASK   0x000fffff           /**< FD LENGTH field mask */
113 
114 #define DPAA_FD_GET_ADDRH(fd)         ((t_DpaaFD *)fd)->addrh                       /**< Macro to get FD ADDRH field */
115 #define DPAA_FD_GET_ADDRL(fd)         ((t_DpaaFD *)fd)->addrl                                           /**< Macro to get FD ADDRL field */
116 #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 */
117 #define DPAA_FD_GET_FORMAT(fd)        ((((t_DpaaFD *)fd)->length & DPAA_FD_FORMAT_MASK) >> (31-2))      /**< Macro to get FD FORMAT field */
118 #define DPAA_FD_GET_OFFSET(fd)        ((((t_DpaaFD *)fd)->length & DPAA_FD_OFFSET_MASK) >> (31-11))     /**< Macro to get FD OFFSET field */
119 #define DPAA_FD_GET_LENGTH(fd)        (((t_DpaaFD *)fd)->length & DPAA_FD_LENGTH_MASK)                  /**< Macro to get FD LENGTH field */
120 #define DPAA_FD_GET_STATUS(fd)        ((t_DpaaFD *)fd)->status                                          /**< Macro to get FD STATUS field */
121 #define DPAA_FD_GET_ADDR(fd)          XX_PhysToVirt(DPAA_FD_GET_PHYS_ADDR(fd))                          /**< Macro to get FD ADDR (virtual) */
122 
123 #define DPAA_FD_SET_ADDRH(fd,val)     ((t_DpaaFD *)fd)->addrh = (val)            /**< Macro to set FD ADDRH field */
124 #define DPAA_FD_SET_ADDRL(fd,val)     ((t_DpaaFD *)fd)->addrl = (val)                                   /**< Macro to set FD ADDRL field */
125 #define DPAA_FD_SET_ADDR(fd,val)                            \
126 do {                                                        \
127     uint64_t physAddr = (uint64_t)(XX_VirtToPhys(val));     \
128     DPAA_FD_SET_ADDRH(fd, ((uint32_t)(physAddr >> 32)));    \
129     DPAA_FD_SET_ADDRL(fd, (uint32_t)physAddr);              \
130 } while (0)                                                                                             /**< Macro to set FD ADDR field */
131 #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 */
132 #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 */
133 #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 */
134 #define DPAA_FD_SET_STATUS(fd,val)    ((t_DpaaFD *)fd)->status = (val)                                  /**< Macro to set FD STATUS field */
135 /* @} */
136 
137 /**************************************************************************//**
138  @Description   Frame Scatter/Gather Table Entry
139 *//***************************************************************************/
140 typedef _Packed struct t_DpaaSGTE {
141     volatile uint32_t    addrh;        /**< Buffer Address high */
142     volatile uint32_t    addrl;        /**< Buffer Address low */
143     volatile uint32_t    length;       /**< Buffer length */
144     volatile uint32_t    offset;       /**< SGTE offset */
145 } _PackedType t_DpaaSGTE;
146 
147 #define DPAA_NUM_OF_SG_TABLE_ENTRY 16
148 
149 /**************************************************************************//**
150  @Description   Frame Scatter/Gather Table
151 *//***************************************************************************/
152 typedef _Packed struct t_DpaaSGT {
153     t_DpaaSGTE    tableEntry[DPAA_NUM_OF_SG_TABLE_ENTRY];
154                                     /**< Structure that holds information about
155                                          a single S/G entry. */
156 } _PackedType t_DpaaSGT;
157 
158 /**************************************************************************//**
159  @Description   Compound Frame Table
160 *//***************************************************************************/
161 typedef _Packed struct t_DpaaCompTbl {
162     t_DpaaSGTE    outputBuffInfo;   /**< Structure that holds information about
163                                          the compound-frame output buffer;
164                                          NOTE: this may point to a S/G table */
165     t_DpaaSGTE    inputBuffInfo;    /**< Structure that holds information about
166                                          the compound-frame input buffer;
167                                          NOTE: this may point to a S/G table */
168 } _PackedType t_DpaaCompTbl;
169 
170 /**************************************************************************//**
171  @Collection   Frame Scatter/Gather Table Entry macros
172 *//***************************************************************************/
173 #define DPAA_SGTE_ADDRH_MASK    0x000000ff           /**< SGTE ADDRH field mask */
174 #define DPAA_SGTE_ADDRL_MASK    0xffffffff           /**< SGTE ADDRL field mask */
175 #define DPAA_SGTE_E_MASK        0x80000000           /**< SGTE Extension field mask */
176 #define DPAA_SGTE_F_MASK        0x40000000           /**< SGTE Final field mask */
177 #define DPAA_SGTE_LENGTH_MASK   0x3fffffff           /**< SGTE LENGTH field mask */
178 #define DPAA_SGTE_BPID_MASK     0x00ff0000           /**< SGTE BPID field mask */
179 #define DPAA_SGTE_OFFSET_MASK   0x00001fff           /**< SGTE OFFSET field mask */
180 
181 #define DPAA_SGTE_GET_ADDRH(sgte)         (((t_DpaaSGTE *)sgte)->addrh & DPAA_SGTE_ADDRH_MASK)              /**< Macro to get SGTE ADDRH field */
182 #define DPAA_SGTE_GET_ADDRL(sgte)         ((t_DpaaSGTE *)sgte)->addrl                                       /**< Macro to get SGTE ADDRL field */
183 #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 */
184 #define DPAA_SGTE_GET_EXTENSION(sgte)     ((((t_DpaaSGTE *)sgte)->length & DPAA_SGTE_E_MASK) >> (31-0))     /**< Macro to get SGTE EXTENSION field */
185 #define DPAA_SGTE_GET_FINAL(sgte)         ((((t_DpaaSGTE *)sgte)->length & DPAA_SGTE_F_MASK) >> (31-1))     /**< Macro to get SGTE FINAL field */
186 #define DPAA_SGTE_GET_LENGTH(sgte)        (((t_DpaaSGTE *)sgte)->length & DPAA_SGTE_LENGTH_MASK)            /**< Macro to get SGTE LENGTH field */
187 #define DPAA_SGTE_GET_BPID(sgte)          ((((t_DpaaSGTE *)sgte)->offset & DPAA_SGTE_BPID_MASK) >> (31-15)) /**< Macro to get SGTE BPID field */
188 #define DPAA_SGTE_GET_OFFSET(sgte)        (((t_DpaaSGTE *)sgte)->offset & DPAA_SGTE_OFFSET_MASK)            /**< Macro to get SGTE OFFSET field */
189 #define DPAA_SGTE_GET_ADDR(sgte)          XX_PhysToVirt(DPAA_SGTE_GET_PHYS_ADDR(sgte))
190 
191 #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 */
192 #define DPAA_SGTE_SET_ADDRL(sgte,val)     ((t_DpaaSGTE *)sgte)->addrl = (val)                                 /**< Macro to set SGTE ADDRL field */
193 #define DPAA_SGTE_SET_ADDR(sgte,val)                            \
194 do {                                                            \
195     uint64_t physAddr = (uint64_t)(XX_VirtToPhys(val));         \
196     DPAA_SGTE_SET_ADDRH(sgte, ((uint32_t)(physAddr >> 32)));    \
197     DPAA_SGTE_SET_ADDRL(sgte, (uint32_t)physAddr);              \
198 } while (0)                                                                                                 /**< Macro to set SGTE ADDR field */
199 #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 */
200 #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 */
201 #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 */
202 #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 */
203 #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 */
204 /* @} */
205 
206 #if defined(__MWERKS__) && !defined(__GNUC__)
207 #pragma pack(pop)
208 #endif /* defined(__MWERKS__) && ... */
209 
210 #define DPAA_LIODN_DONT_OVERRIDE    (-1)
211 
212 /** @} */ /* end of DPAA_grp group */
213 
214 
215 #endif /* __DPAA_EXT_H */
216