1/*
2 * 802.1Q VLAN protocol definitions
3 *
4 * Copyright (C) 2010, Broadcom Corporation. All Rights Reserved.
5 *
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
13 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
15 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
16 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 *
18 * $Id: vlan.h,v 9.7 2009/03/13 01:11:50 Exp $
19 */
20
21#ifndef _vlan_h_
22#define _vlan_h_
23
24#ifndef _TYPEDEFS_H_
25#include <typedefs.h>
26#endif
27
28/* This marks the start of a packed structure section. */
29#include <packed_section_start.h>
30
31#define VLAN_VID_MASK		0xfff	/* low 12 bits are vlan id */
32#define	VLAN_CFI_SHIFT		12	/* canonical format indicator bit */
33#define VLAN_PRI_SHIFT		13	/* user priority */
34
35#define VLAN_PRI_MASK		7	/* 3 bits of priority */
36
37#define	VLAN_TAG_LEN		4
38#define	VLAN_TAG_OFFSET		(2 * ETHER_ADDR_LEN)	/* offset in Ethernet II packet only */
39
40#define VLAN_TPID		0x8100	/* VLAN ethertype/Tag Protocol ID */
41
42struct ethervlan_header {
43	uint8	ether_dhost[ETHER_ADDR_LEN];
44	uint8	ether_shost[ETHER_ADDR_LEN];
45	uint16	vlan_type;		/* 0x8100 */
46	uint16	vlan_tag;		/* priority, cfi and vid */
47	uint16	ether_type;
48};
49
50#define	ETHERVLAN_HDR_LEN	(ETHER_HDR_LEN + VLAN_TAG_LEN)
51
52
53/* This marks the end of a packed structure section. */
54#include <packed_section_end.h>
55
56#define ETHERVLAN_MOVE_HDR(d, s) \
57do { \
58	struct ethervlan_header t; \
59	t = *(struct ethervlan_header *)(s); \
60	*(struct ethervlan_header *)(d) = t; \
61} while (0)
62
63#endif /* _vlan_h_ */
64