blob: c5a25584a74554179a02f0c3a818ad7350b8e4c4 [file] [log] [blame]
Shad Ansari2f7f9be2017-06-07 13:34:53 -07001/******************************************************************************
2 *
3 * <:copyright-BRCM:2016:DUAL/GPL:standard
4 *
5 * Copyright (c) 2016 Broadcom
6 * All Rights Reserved
7 *
8 * Unless you and Broadcom execute a separate written software license
9 * agreement governing use of this software, this software is licensed
10 * to you under the terms of the GNU General Public License version 2
11 * (the "GPL"), available at http://www.broadcom.com/licenses/GPLv2.php,
12 * with the following added to such license:
13 *
14 * As a special exception, the copyright holders of this software give
15 * you permission to link this software with independent modules, and
16 * to copy and distribute the resulting executable under terms of your
17 * choice, provided that you also meet, for each linked independent
18 * module, the terms and conditions of the license of that module.
19 * An independent module is a module which is not derived from this
20 * software. The special exception does not apply to any modifications
21 * of the software.
22 *
23 * Not withstanding the above, under no circumstances may you combine
24 * this software in any way with any other Broadcom software provided
25 * under a license other than the GPL, without Broadcom's express prior
26 * written consent.
27 *
28 * :>
29 *
30 *****************************************************************************/
31
32/**
33 * @file bal_common.h
34 *
35 * @brief Common include files and miscellaneous macros for the BAL source code.
36 *
37 */
38
39#ifndef BALCOMMON_H
40#define BALCOMMON_H
41
42/*@{*/
43
44/* --- system includes ---*/
45#include <bcmos_system.h>
46
47/* --- project includes ---*/
48
49/**
50 * @brief OUI Identifier
51 *
52 */
53typedef uint8_t oui_val_t[3];
54
55/*
56 * A max/min function
57 */
58#define max(a,b) ((a > b) ? a : b)
59#define min(a,b) ((a > b) ? b : a)
60
61/**
62 * @brief Maximum value for a VLAN ID
63 */
64#define MAX_VLAN_ID 4094
65
66/**
67 * @brief Minimum value for an 802.1ah I-SID
68 *
69 * Notes from IEEE:
70 * 0 - Reserved for use by future amendments to the standard.
71 * 1 - Default value, unassigned ISID.
72 * 2..FF - Reserved for use by future amendments to the standard.
73 */
74#define MIN_8021AH_ISID 0x00000100
75
76/**
77 * @brief Maximum value for an 802.1ah I-SID
78 *
79 * Notes from IEEE:
80 * FFFFFF is reserved by IEEE
81 */
82#define MAX_8021AH_ISID 0x00FFFFFE
83
84/**
85 * @brief VLAN TPID definitions
86 */
87typedef enum vlan_tpid_type
88{
89 VLAN_TPID_TYPE_DEFAULT = 0x0000, /**< Simple Bridge - i.e. VID 0, no tagging */
90 VLAN_TPID_TYPE_8021Q = 0x8100, /**< C-VLAN */
91 VLAN_TPID_TYPE_8021AD = 0x88A8, /**< S-VLAN */
92 VLAN_TPID_TYPE_9100 = 0x9100, /**< Legacy TPID */
93 VLAN_TPID_TYPE_9200 = 0x9200, /**< Legacy TPID */
94 VLAN_TPID_TYPE_9300 = 0x9300, /**< Legacy TPID */
95 VLAN_TPID_TYPE_8021AH_ITAG = 0x88E7 /**< 802.1ah I-Tag TPID */
96} vlan_tpid_type;
97
98/**
99 * @brief VLAN type definitions
100 */
101typedef enum vlan_mode_type
102{
103 VLAN_MODE_NONE, /**< Neither Shared or L2VPN */
104 VLAN_MODE_SHARED, /**< IP-based shared vlan */
105 VLAN_MODE_8021AD_EN, /**< DPoE 802.1ad (or .1q) encapsulation mode */
106 VLAN_MODE_8021AD_TP, /**< DPoE 802.1ad (or .1q) transport mode */
107 VLAN_MODE_8021AH_EN, /**< DPoE 802.1ah encapsulation mode */
108 VLAN_MODE_8021AH_TP, /**< DPoE 802.1ah transport mode */
109 VLAN_MODE_DAC /**< DPoE DEMARC Auto Configuration */
110} vlan_mode;
111
112/**
113 * @brief Macro to test if a VLAN is 802.1ad
114 */
115#define VLAN_IS_8021AD(_vlan_) (((_vlan_)->type == VLAN_MODE_8021AD_EN) || ((_vlan_)->type == VLAN_MODE_8021AD_TP))
116
117/**
118 * @brief Macro to test if a VLAN is 802.1ah
119 */
120#define VLAN_IS_8021AH(_vlan_) (((_vlan_)->type == VLAN_MODE_8021AH_EN) || ((_vlan_)->type == VLAN_MODE_8021AH_TP))
121
122/**
123 * @brief Macro to test if a VLAN is L2VPN (as opposed to 'None' or "Shared')
124 */
125#define VLAN_IS_L2VPN(_vlan_) (VLAN_IS_8021AD(_vlan_) || VLAN_IS_8021AH(_vlan_))
126
127/**
128 * @brief Macro to test if a VLAN is DPoE IP-HSD
129 */
130#define VLAN_IS_DPOE_IPHSD(_vlan_) (((_vlan_)->type == VlanType_None) && ((_vlan_)->dpoeIp.svid != 0) && ((_vlan_)->dpoeIp.cvid != 0))
131
132/**
133 * @brief Macro to test if a VLAN is Legacy IP-HSD
134 */
135#define VLAN_IS_LEGACY_IPHSD(_vlan_) (((_vlan_)->type == VlanType_None) && ((_vlan_)->dpoeIp.svid == 0))
136
137/**
138 * @brief Macro to test if a VLAN is DPoE IP-HSD with PON-NNI style tagging
139 */
140#define VLAN_IS_DPOE_IPHSD_PON_NNI(_vlan_) (VLAN_IS_DPOE_IPHSD(_vlan_) && ((_vlan_)->dot1ad[VLAN_TAG_OUTER].nniTpid != 0))
141
142/**
143 * @brief Macro to test if a VLAN is Shared
144 */
145#define VLAN_IS_SHARED(_vlan_) ((_vlan_)->type == VLAN_MODE_SHARED)
146
147/**
148 * @brief 802.1ad VLAN Tag index
149 *
150 * This enum is used in the VlanT structure to address the outer vs. the inner
151 * 802.1ad tag.
152 */
153typedef enum vlan_tag_index
154{
155 VLAN_TAG_INDEX_OUTER = 0, /**< Outer tag, typically the S-VLAN tag */
156 VLAN_TAG_INDEX_INNER = 1, /**< Inner tag, typically the C-VLAN tag */
157 VLAN_TAG_INDEX_MAX = 2
158} vlan_tag_index;
159
160/**
161 * @brief VlanT structure
162 */
163typedef struct bcmbal_vlan
164{
165 vlan_mode type; /**< Type of VLAN */
166
167 /** Intra-Chassis Tagging */
168 struct
169 {
170 uint16_t tpid; /**< ICT TPID */
171 uint16_t vid; /**< ICT VLAN ID */
172 } ict;
173
174 /** DPoE IP HSD Tagging */
175 struct
176 {
177 uint16_t svid; /**< S-TAG VID */
178 uint16_t cvid; /**< C-TAG VID */
179 } dpoe_ip;
180
181 /** 802.1ad (and 802.1q) tagging */
182 struct
183 {
184 uint16_t nni_tpid; /**< VLAN Tag TPID used on the NNI */
185 uint16_t uni_tpid; /**< VLAN Tag TPID used on the UNI */
186 uint8_t cos; /**< CoS bits used in this VLAN Tag */
187 uint16_t vid; /**< VLAN ID */
188 } dot_1ad[VLAN_TAG_INDEX_MAX];
189
190 /** 802.1ah encapsulation info */
191 struct
192 {
193 /** 802.1ah B-MACs */
194 bcmos_mac_address bda; /**< 802.1ah Destination B-MAC */
195 bcmos_mac_address bsa; /**< 802.1ah Source B-MAC */
196
197 /** 802.1ah B-Tag */
198 struct
199 {
200 uint16_t nni_tpid; /**< B-Tag TPID used on the NNI */
201 uint16_t uni_tpid; /**< B-Tag TPID used on the UNI */
202 uint16_t vid; /**< B-Tag VLAN ID */
203 } btag;
204
205 /** 802.1ah I-Tag */
206 struct
207 {
208 uint16_t nni_tpid; /**< I-Tag TPID used on the NNI */
209 uint16_t uni_tpid; /**< I-Tag TPID used on the UNI */
210 uint32_t isid; /**< I-Tag Service ID */
211 } itag;
212 } dot_1ah;
213
214 /** L2VPN specific VLAN configuration */
215 uint32_t vpn_idx; /**< Index of L2VPN that link is associated with. */
216} bcmbal_vlan;
217
218/**
219 * @brief MAC Address key structure.
220 *
221 * This structure effectively adds a length field to the MacAddressT structure
222 * which helps when handling GetNext requests that don't contain a full MAC
223 * Address.
224 */
225typedef struct mac_address_key
226{
227 bcmos_mac_address mac_addr; /**< The MAC address */
228 uint16_t len; /**< The length of the MAC address in the field above */
229} mac_address_key;
230
231/**
232 * @brief MAC Address length
233 */
234#define MAC_ADDRESS_LEN 6
235
236/**
237 * @brief Converts a MacAddressT structure into a MacAddressKeyT structure.
238 */
239#define MAC_ADDR_TO_KEY(A, K, L) { \
240 (K)->mac_addr = *(A); \
241 (K)->len = (L); \
242 }
243
244/**
245 * @brief Compares the 802.1ad (or q) fields of two VlanT objects
246 *
247 * This macro returns '1' if all fields match, and '0' otherwise.
248 *
249 * Note, this macro looks at the nniTpid only. This macro is used to determine
250 * whether or not an OLT Domain already exists for a given VLAN (which prevents
251 * configuring duplicate/overlapping OLT domain selectors).
252 *
253 */
254#define VLANS_MATCH_AD(_vlan1_, _vlan2_) (((_vlan1_)->dot1ad[VLAN_TAG_OUTER].vid == (_vlan2_)->dot1ad[VLAN_TAG_OUTER].vid) && \
255 ((_vlan1_)->dot1ad[VLAN_TAG_OUTER].nniTpid == (_vlan2_)->dot1ad[VLAN_TAG_OUTER].nniTpid) && \
256 ((_vlan1_)->dot1ad[VLAN_TAG_INNER].vid == (_vlan2_)->dot1ad[VLAN_TAG_INNER].vid) && \
257 ((_vlan1_)->dot1ad[VLAN_TAG_INNER].nniTpid == (_vlan2_)->dot1ad[VLAN_TAG_INNER].nniTpid))
258
259/**
260 * @brief Compares the 802.1ah (mac-in-mac) fields of two VlanT objects
261 *
262 * This macro returns '1' if all fields match, and '0' otherwise.
263 *
264 * Note, this macro looks at the nniTpid's only. This macro is used to
265 * determine whether or not an OLT Domain already exists for a given VLAN
266 * (which prevents configuring duplicate/overlapping OLT domain selectors).
267 *
268 */
269#define VLANS_MATCH_AH(_vlan1_, _vlan2_) (((_vlan1_)->dot1ah.btag.nniTpid == (_vlan2_)->dot1ah.btag.nniTpid) && \
270 ((_vlan1_)->dot1ah.btag.vid == (_vlan2_)->dot1ah.btag.vid) && \
271 ((_vlan1_)->dot1ah.itag.nniTpid == (_vlan2_)->dot1ah.itag.nniTpid) && \
272 ((_vlan1_)->dot1ah.itag.isid == (_vlan2_)->dot1ah.itag.isid))
273
274/**
275 * @brief Compares the ICT fields of two VlanT objects
276 *
277 * This macro returns '1' if all fields match, and '0' otherwise.
278 *
279 * Note, this macro looks at the ICT fields only. This macro is
280 * used to determine whether or not an OLT Domain already
281 * exists for a given VLAN (which prevents configuring
282 * duplicate/overlapping OLT domain selectors).
283 *
284 */
285#define VLANS_MATCH_ICT(_vlan1_, _vlan2_) (((_vlan1_)->ict.tpid == (_vlan2_)->ict.tpid) && \
286 ((_vlan1_)->ict.vid == (_vlan2_)->ict.vid))
287/**
288 * @brief Compares the 802.1ad (or q) and 802.1ah (mac-in-mac)
289 * fields of two VlanT objects
290 *
291 * This macro returns '1' if all fields match, and '0' otherwise.
292 *
293 */
294#define VLANS_MATCH(_vlan1_, _vlan2_) (VLANS_MATCH_AD(_vlan1_, _vlan2_) && VLANS_MATCH_AH(_vlan1_, _vlan2_))
295
296/**
297 * @brief Macros for setting/clearing bits inside of an integer
298 */
299#define SET_BIT(x,n) ((x) |= (1L << (n)))
300#define CLR_BIT(x,n) ((x) &= (~(1L << (n))))
301#define BIT_IS_SET(x,n) (((x) >> (n)) & 1)
302
303
304
305/**
306 * Static compile time assert used to ensure that enums and associated
307 * character arrays are equal.
308 *
309 * Use the BAL_STATIC_ASSERT function in your code to check array sizes
310 */
311#define _BAL_STATIC_ASSERT_HELPER(expr, msg) (sizeof (struct {unsigned int STATIC_ASSERT__##msg: (expr) ? 1 : -1;} ))
312
313#define BAL_STATIC_ASSERT(expr, msg) extern int (*assert_function__##msg(void)) [_BAL_STATIC_ASSERT_HELPER(expr, msg) ]
314
315/*@}*/
316
317#endif /* #ifndef BALCOMMON_H */