OpenNSL API Guide and Reference Manual
types.h
Go to the documentation of this file.
1 /*********************************************************************
2  *
3  * (C) Copyright Broadcom Corporation 2013-2016
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *********************************************************************
18  * File: types.h
19  * Details: Type definitions
20  ********************************************************************/
21 
22 #ifndef _SAL_TYPES_H
23 #define _SAL_TYPES_H
24 
25 #include <sal/compiler.h>
26 
27 /*
28  * Define platform-independent types
29  */
30 
31 #ifndef TRUE
32 #define TRUE 1
33 #endif
34 
35 #ifndef FALSE
36 #define FALSE 0
37 #endif
38 
39 #ifndef NULL
40 #define NULL 0
41 #endif
42 
43 #ifndef DONT_CARE
44 #define DONT_CARE 0
45 #endif
46 
47 #define VOL volatile
48 
49 /*
50  * Define unsigned and signed integers with guaranteed sizes.
51  * Adjust if your compiler uses different sizes for short or int.
52  */
53 
54 typedef unsigned char uint8; /* 8-bit quantity */
55 typedef unsigned short uint16; /* 16-bit quantity */
56 typedef unsigned int uint32; /* 32-bit quantity */
57 typedef COMPILER_UINT64 uint64; /* 64-bit quantity */
58 
59 typedef signed char int8; /* 8-bit quantity */
60 typedef signed short int16; /* 16-bit quantity */
61 typedef signed int int32; /* 32-bit quantity */
62 typedef COMPILER_INT64 int64; /* 64-bit quantity */
63 
64 #define BITS2BYTES(x) (((x) + 7) / 8)
65 #define BITS2WORDS(x) (((x) + 31) / 32)
66 
67 #define BYTES2BITS(x) ((x) * 8)
68 #define BYTES2WORDS(x) (((x) + 3) / 4)
69 
70 #define WORDS2BITS(x) ((x) * 32)
71 #define WORDS2BYTES(x) ((x) * 4)
72 
73 #define COUNTOF(ary) ((int) (sizeof (ary) / sizeof ((ary)[0])))
74 
75 typedef uint32 sal_paddr_t; /* Physical address (PCI address) */
76 
77 #ifdef PTRS_ARE_64BITS
78 typedef uint64 sal_vaddr_t; /* Virtual address (Host address) */
79 #define PTR_TO_INT(x) ((uint32)(((sal_vaddr_t)(x))&0xFFFFFFFF))
80 #define PTR_HI_TO_INT(x) ((uint32)((((sal_vaddr_t)(x))>>32)&0xFFFFFFFF))
81 
82 #else
83 typedef uint32 sal_vaddr_t; /* Virtual address (Host address) */
84 #define PTR_TO_INT(x) ((uint32)(x))
85 #define PTR_HI_TO_INT(x) (0)
86 #endif
87 
88 #define INT_TO_PTR(x) ((void *)((sal_vaddr_t)(x)))
89 
90 #define PTR_TO_UINTPTR(x) ((sal_vaddr_t)(x))
91 #define UINTPTR_TO_PTR(x) ((void *)(x))
92 
93 typedef union
94 {
101  void *ptr;
102 } any_t;
103 /* __doxy_func_body_end__ */
104 
105 typedef uint8 sal_mac_addr_t[6]; /* MAC address */
106 typedef uint32 sal_ip_addr_t; /* IP Address */
107 
108 /* sal_mac_addr_t mac; Just generate a list of the macs for display */
109 #define SAL_MAC_ADDR_LIST(mac) \
110  mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]
111 
112 #define SAL_MACADDR_STR_LEN 18 /* Formatted MAC address */
113 #define SAL_IPADDR_STR_LEN 16 /* Formatted IP address */
114 
115 
116 /* Adjust justification for uint32 writes to fields */
117 /* dst is an array name of type uint32 [] */
118 #define SAL_MAC_ADDR_TO_UINT32(mac, dst) do {\
119  (dst)[0] = (((uint32)(mac)[2]) << 24 | \
120  ((uint32)(mac)[3]) << 16 | \
121  ((uint32)(mac)[4]) << 8 | \
122  ((uint32)(mac)[5])); \
123  (dst)[1] = (((uint32)(mac)[0]) << 8 | \
124  ((uint32)(mac)[1])); \
125  } while (0)
126 /* __doxy_func_body_end__ */
127 
128 /* Adjust justification for uint32 writes to fields */
129 /* src is an array name of type uint32 [] */
130 #define SAL_MAC_ADDR_FROM_UINT32(mac, src) do {\
131  (mac)[0] = (uint8) ((src)[1] >> 8 & 0xff); \
132  (mac)[1] = (uint8) ((src)[1] & 0xff); \
133  (mac)[2] = (uint8) ((src)[0] >> 24); \
134  (mac)[3] = (uint8) ((src)[0] >> 16 & 0xff); \
135  (mac)[4] = (uint8) ((src)[0] >> 8 & 0xff); \
136  (mac)[5] = (uint8) ((src)[0] & 0xff); \
137  } while (0)
138 /* __doxy_func_body_end__ */
139 
140 
141 /* dst is a uint64 */
142 #define SAL_MAC_ADDR_TO_UINT64(mac, dst) do { \
143  uint32 _val[2]; \
144  SAL_MAC_ADDR_TO_UINT32(mac, _val); \
145  COMPILER_64_SET(dst, _val[1], _val[0]); \
146  } while (0)
147 /* __doxy_func_body_end__ */
148 
149 /* src is a uint64 */
150 #define SAL_MAC_ADDR_FROM_UINT64(mac, src) do { \
151  uint32 _val[2]; \
152  COMPILER_64_TO_32_LO(_val[0], src); \
153  COMPILER_64_TO_32_HI(_val[1], src); \
154  SAL_MAC_ADDR_FROM_UINT32(mac, _val); \
155  } while (0)
156 /* __doxy_func_body_end__ */
157 
158 
159 /* Adjust IP6 justification for uint32 field accesses */
160 /*
161  * These macros are used on IP6 "half addresses", being
162  * either the "upper" 64 bits or the "lower" 64 bits of
163  * an IPv6 address.
164  */
165 
166 /* dst is an array name of type uint32 [] */
167 #define SAL_IP6_ADDR_HALF_TO_UINT32(ip6, dst) do {\
168  (dst)[1] = (((uint32)(ip6)[0]) << 24 | \
169  ((uint32)(ip6)[1]) << 16 | \
170  ((uint32)(ip6)[2]) << 8 | \
171  ((uint32)(ip6)[3])); \
172  (dst)[0] = (((uint32)(ip6)[4]) << 24 | \
173  ((uint32)(ip6)[5]) << 16 | \
174  ((uint32)(ip6)[6]) << 8 | \
175  ((uint32)(ip6)[7])); \
176  } while (0)
177 /* __doxy_func_body_end__ */
178 
179 /* src is an array name of type uint32 [] */
180 #define SAL_IP6_ADDR_HALF_FROM_UINT32(ip6, src) do {\
181  (ip6)[0] = (uint8) ((src)[1] >> 24); \
182  (ip6)[1] = (uint8) ((src)[1] >> 16 & 0xff); \
183  (ip6)[2] = (uint8) ((src)[1] >> 8 & 0xff); \
184  (ip6)[3] = (uint8) ((src)[1] & 0xff); \
185  (ip6)[4] = (uint8) ((src)[0] >> 24); \
186  (ip6)[5] = (uint8) ((src)[0] >> 16 & 0xff); \
187  (ip6)[6] = (uint8) ((src)[0] >> 8 & 0xff); \
188  (ip6)[7] = (uint8) ((src)[0] & 0xff); \
189  } while (0)
190 /* __doxy_func_body_end__ */
191 
192 /*
193  * These macros are used on full 128-bit IP6 addresses.
194  */
195 
196 /* dst is an array name of type uint32 [] */
197 #define SAL_IP6_ADDR_TO_UINT32(ip6, dst) do {\
198  SAL_IP6_ADDR_HALF_TO_UINT32(&((ip6)[8]), (dst)); \
199  SAL_IP6_ADDR_HALF_TO_UINT32((ip6), &((dst)[2])); \
200  } while (0)
201 /* __doxy_func_body_end__ */
202 
203 /* src is an array name of type uint32 [] */
204 #define SAL_IP6_ADDR_FROM_UINT32(ip6, src) do {\
205  SAL_IP6_ADDR_HALF_FROM_UINT32(&((ip6)[8]), (src)); \
206  SAL_IP6_ADDR_HALF_FROM_UINT32((ip6), &((src)[2])); \
207  } while (0)
208 /* __doxy_func_body_end__ */
209 
210 
211 /* Device bus types */
212 #define SAL_PCI_DEV_TYPE 0x00001 /* PCI device */
213 #define SAL_SPI_DEV_TYPE 0x00002 /* SPI device */
214 #define SAL_EB_DEV_TYPE 0x00004 /* EB device */
215 #define SAL_ICS_DEV_TYPE 0x00008 /* ICS device */
216 #define SAL_MII_DEV_TYPE 0x00010 /* MII device */
217 #define SAL_RCPU_DEV_TYPE 0x00020 /* RCPU device */
218 #define SAL_I2C_DEV_TYPE 0x00040 /* I2C device */
219 #define SAL_AXI_DEV_TYPE 0x00080 /* AXI device */
220 #define SAL_EMMI_DEV_TYPE 0x10000 /* EMMI device */
221 #define SAL_DEV_BUS_TYPE_MASK 0xf00ff /* Odd for historical reasons */
222 
223 /* Device types */
224 #define SAL_SWITCH_DEV_TYPE 0x00100 /* Switch device */
225 #define SAL_ETHER_DEV_TYPE 0x00200 /* Ethernet device */
226 #define SAL_CPU_DEV_TYPE 0x00400 /* CPU device */
227 #define SAL_DEV_TYPE_MASK 0x00f00
228 
229 /* Access types */
230 #define SAL_DEV_BUS_RD_16BIT 0x01000 /* 16 bit reads on bus */
231 #define SAL_DEV_BUS_WR_16BIT 0x02000 /* 16 bit writes on bus */
232 #define SAL_DEV_BUS_ALT 0x04000 /* Alternate access */
233 #define SAL_DEV_BUS_MSI 0x08000 /* Message-signaled interrupts */
234 #define SAL_DEV_FLAG_MASK 0x0f000
235 
236 /* BDE reserved mask (cannot be used by SAL) */
237 #define SAL_DEV_BDE_MASK 0xff000000
238 
239 /* Backward compatibility */
240 #define SAL_ET_DEV_TYPE SAL_MII_DEV_TYPE
241 
242 /* Special access addresses */
243 #define SAL_DEV_OP_EMMI_INIT 0x0fff1000
244 
245 #endif /* !_SAL_TYPES_H */