xref: /freebsd/sys/dev/etherswitch/etherswitch.h (revision c1d255d3ffdbe447de3ab875bf4e7d7accc5bfc5)
1 /*
2  * $FreeBSD$
3  */
4 
5 #ifndef __SYS_DEV_ETHERSWITCH_ETHERSWITCH_H
6 #define __SYS_DEV_ETHERSWITCH_ETHERSWITCH_H
7 
8 #include <sys/ioccom.h>
9 #include <net/ethernet.h>
10 
11 #ifdef _KERNEL
12 extern devclass_t       etherswitch_devclass;
13 extern driver_t         etherswitch_driver;
14 #endif /* _KERNEL */
15 
16 struct etherswitch_reg {
17 	uint32_t	reg;
18 	uint32_t	val;
19 };
20 typedef struct etherswitch_reg etherswitch_reg_t;
21 
22 struct etherswitch_phyreg {
23 	uint16_t	phy;
24 	uint16_t	reg;
25 	uint16_t	val;
26 };
27 typedef struct etherswitch_phyreg etherswitch_phyreg_t;
28 
29 #define	ETHERSWITCH_NAMEMAX		64
30 #define	ETHERSWITCH_VID_MASK		0xfff
31 #define	ETHERSWITCH_VID_VALID		(1 << 12)
32 #define	ETHERSWITCH_VLAN_ISL		(1 << 0)	/* ISL */
33 #define	ETHERSWITCH_VLAN_PORT		(1 << 1)	/* Port based vlan */
34 #define	ETHERSWITCH_VLAN_DOT1Q		(1 << 2)	/* 802.1q */
35 #define	ETHERSWITCH_VLAN_DOT1Q_4K	(1 << 3)	/* 4k support on 802.1q */
36 #define	ETHERSWITCH_VLAN_DOUBLE_TAG	(1 << 4)	/* Q-in-Q */
37 #define	ETHERSWITCH_VLAN_CAPS_BITS	\
38 "\020\1ISL\2PORT\3DOT1Q\4DOT1Q4K\5QinQ"
39 
40 struct etherswitch_info {
41 	int		es_nports;
42 	int		es_nvlangroups;
43 	char		es_name[ETHERSWITCH_NAMEMAX];
44 	uint32_t	es_vlan_caps;
45 };
46 typedef struct etherswitch_info etherswitch_info_t;
47 
48 #define	ETHERSWITCH_CONF_FLAGS		(1 << 0)
49 #define	ETHERSWITCH_CONF_MIRROR		(1 << 1)
50 #define	ETHERSWITCH_CONF_VLAN_MODE	(1 << 2)
51 #define	ETHERSWITCH_CONF_SWITCH_MACADDR	(1 << 3)
52 
53 struct etherswitch_conf {
54 	uint32_t	cmd;		/* What to configure */
55 	uint32_t	vlan_mode;	/* Switch VLAN mode */
56 	struct ether_addr switch_macaddr;	/* Switch MAC address */
57 };
58 typedef struct etherswitch_conf etherswitch_conf_t;
59 
60 #define	ETHERSWITCH_PORT_CPU			(1 << 0)
61 #define	ETHERSWITCH_PORT_STRIPTAG		(1 << 1)
62 #define	ETHERSWITCH_PORT_ADDTAG			(1 << 2)
63 #define	ETHERSWITCH_PORT_FIRSTLOCK		(1 << 3)
64 #define	ETHERSWITCH_PORT_DROPUNTAGGED		(1 << 4)
65 #define	ETHERSWITCH_PORT_DOUBLE_TAG		(1 << 5)
66 #define	ETHERSWITCH_PORT_INGRESS		(1 << 6)
67 #define	ETHERSWITCH_PORT_DROPTAGGED     	(1 << 7)
68 #define	ETHERSWITCH_PORT_STRIPTAGINGRESS	(1 << 8)
69 #define	ETHERSWITCH_PORT_FLAGS_BITS	\
70 "\020\1CPUPORT\2STRIPTAG\3ADDTAG\4FIRSTLOCK\5DROPUNTAGGED\6QinQ\7INGRESS" \
71 "\10DROPTAGGED\11STRIPTAGINGRESS"
72 
73 #define ETHERSWITCH_PORT_MAX_LEDS 3
74 
75 enum etherswitch_port_led {
76 	ETHERSWITCH_PORT_LED_DEFAULT,
77 	ETHERSWITCH_PORT_LED_ON,
78 	ETHERSWITCH_PORT_LED_OFF,
79 	ETHERSWITCH_PORT_LED_BLINK,
80 	ETHERSWITCH_PORT_LED_MAX
81 };
82 typedef enum etherswitch_port_led etherswitch_port_led_t;
83 
84 struct etherswitch_port {
85 	int		es_port;
86 	int		es_pvid;
87 	int		es_nleds;
88 	uint32_t	es_flags;
89 	etherswitch_port_led_t es_led[ETHERSWITCH_PORT_MAX_LEDS];
90 	union {
91 		struct ifreq		es_uifr;
92 		struct ifmediareq	es_uifmr;
93 	} es_ifu;
94 #define es_ifr		es_ifu.es_uifr
95 #define es_ifmr		es_ifu.es_uifmr
96 };
97 typedef struct etherswitch_port etherswitch_port_t;
98 
99 struct etherswitch_vlangroup {
100 	int		es_vlangroup;
101 	int		es_vid;
102 	int		es_member_ports;
103 	int		es_untagged_ports;
104 	int		es_fid;
105 };
106 typedef struct etherswitch_vlangroup etherswitch_vlangroup_t;
107 
108 #define ETHERSWITCH_PORTMASK(_port)	(1 << (_port))
109 
110 struct etherswitch_portid {
111 	int es_port;
112 };
113 typedef struct etherswitch_portid etherswitch_portid_t;
114 
115 struct etherswitch_atu_entry {
116 	int id;
117 	int es_portmask;
118 	uint8_t es_macaddr[ETHER_ADDR_LEN];
119 };
120 typedef struct etherswitch_atu_entry etherswitch_atu_entry_t;
121 
122 struct etherswitch_atu_table {
123 	uint32_t es_nitems;
124 };
125 typedef struct etherswitch_atu_table etherswitch_atu_table_t;
126 
127 struct etherswitch_atu_flush_macentry {
128 	uint8_t es_macaddr[ETHER_ADDR_LEN];
129 };
130 typedef struct etherswitch_atu_flush_macentry etherswitch_atu_flush_macentry_t;
131 
132 #define IOETHERSWITCHGETINFO		_IOR('i', 1, etherswitch_info_t)
133 #define IOETHERSWITCHGETREG		_IOWR('i', 2, etherswitch_reg_t)
134 #define IOETHERSWITCHSETREG		_IOW('i', 3, etherswitch_reg_t)
135 #define IOETHERSWITCHGETPORT		_IOWR('i', 4, etherswitch_port_t)
136 #define IOETHERSWITCHSETPORT		_IOW('i', 5, etherswitch_port_t)
137 #define IOETHERSWITCHGETVLANGROUP	_IOWR('i', 6, etherswitch_vlangroup_t)
138 #define IOETHERSWITCHSETVLANGROUP	_IOW('i', 7, etherswitch_vlangroup_t)
139 #define IOETHERSWITCHGETPHYREG		_IOWR('i', 8, etherswitch_phyreg_t)
140 #define IOETHERSWITCHSETPHYREG		_IOW('i', 9, etherswitch_phyreg_t)
141 #define IOETHERSWITCHGETCONF		_IOR('i', 10, etherswitch_conf_t)
142 #define IOETHERSWITCHSETCONF		_IOW('i', 11, etherswitch_conf_t)
143 #define IOETHERSWITCHFLUSHALL		_IOW('i', 12, etherswitch_portid_t)	/* Dummy */
144 #define IOETHERSWITCHFLUSHPORT		_IOW('i', 13, etherswitch_portid_t)
145 #define IOETHERSWITCHFLUSHMAC		_IOW('i', 14, etherswitch_atu_flush_macentry_t)
146 #define IOETHERSWITCHGETTABLE		_IOWR('i', 15, etherswitch_atu_table_t)
147 #define IOETHERSWITCHGETTABLEENTRY	_IOWR('i', 16, etherswitch_atu_entry_t)
148 
149 #endif
150