xref: /freebsd/sys/dev/etherswitch/etherswitch.h (revision 076ad2f836d5f49dc1375f1677335a48fe0d4b82)
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 
10 #ifdef _KERNEL
11 extern devclass_t       etherswitch_devclass;
12 extern driver_t         etherswitch_driver;
13 #endif /* _KERNEL */
14 
15 struct etherswitch_reg {
16 	uint16_t	reg;
17 	uint32_t	val;
18 };
19 typedef struct etherswitch_reg etherswitch_reg_t;
20 
21 struct etherswitch_phyreg {
22 	uint16_t	phy;
23 	uint16_t	reg;
24 	uint16_t	val;
25 };
26 typedef struct etherswitch_phyreg etherswitch_phyreg_t;
27 
28 #define	ETHERSWITCH_NAMEMAX		64
29 #define	ETHERSWITCH_VID_MASK		0xfff
30 #define	ETHERSWITCH_VID_VALID		(1 << 12)
31 #define	ETHERSWITCH_VLAN_ISL		(1 << 0)	/* ISL */
32 #define	ETHERSWITCH_VLAN_PORT		(1 << 1)	/* Port based vlan */
33 #define	ETHERSWITCH_VLAN_DOT1Q		(1 << 2)	/* 802.1q */
34 #define	ETHERSWITCH_VLAN_DOT1Q_4K	(1 << 3)	/* 4k support on 802.1q */
35 #define	ETHERSWITCH_VLAN_DOUBLE_TAG	(1 << 4)	/* Q-in-Q */
36 #define	ETHERSWITCH_VLAN_CAPS_BITS	\
37 "\020\1ISL\2PORT\3DOT1Q\4DOT1Q4K\5QinQ"
38 
39 struct etherswitch_info {
40 	int		es_nports;
41 	int		es_nvlangroups;
42 	char		es_name[ETHERSWITCH_NAMEMAX];
43 	uint32_t	es_vlan_caps;
44 };
45 typedef struct etherswitch_info etherswitch_info_t;
46 
47 #define	ETHERSWITCH_CONF_FLAGS		(1 << 0)
48 #define	ETHERSWITCH_CONF_MIRROR		(1 << 1)
49 #define	ETHERSWITCH_CONF_VLAN_MODE	(1 << 2)
50 
51 struct etherswitch_conf {
52 	uint32_t	cmd;		/* What to configure */
53 	uint32_t	vlan_mode;	/* Switch VLAN mode */
54 };
55 typedef struct etherswitch_conf etherswitch_conf_t;
56 
57 #define	ETHERSWITCH_PORT_CPU		(1 << 0)
58 #define	ETHERSWITCH_PORT_STRIPTAG	(1 << 1)
59 #define	ETHERSWITCH_PORT_ADDTAG		(1 << 2)
60 #define	ETHERSWITCH_PORT_FIRSTLOCK	(1 << 3)
61 #define	ETHERSWITCH_PORT_DROPUNTAGGED	(1 << 4)
62 #define	ETHERSWITCH_PORT_DOUBLE_TAG	(1 << 5)
63 #define	ETHERSWITCH_PORT_INGRESS	(1 << 6)
64 #define	ETHERSWITCH_PORT_FLAGS_BITS	\
65 "\020\1CPUPORT\2STRIPTAG\3ADDTAG\4FIRSTLOCK\5DROPUNTAGGED\6QinQ\7INGRESS"
66 
67 #define ETHERSWITCH_PORT_MAX_LEDS 3
68 
69 enum etherswitch_port_led {
70 	ETHERSWITCH_PORT_LED_DEFAULT,
71 	ETHERSWITCH_PORT_LED_ON,
72 	ETHERSWITCH_PORT_LED_OFF,
73 	ETHERSWITCH_PORT_LED_BLINK,
74 	ETHERSWITCH_PORT_LED_MAX
75 };
76 typedef enum etherswitch_port_led etherswitch_port_led_t;
77 
78 struct etherswitch_port {
79 	int		es_port;
80 	int		es_pvid;
81 	int		es_nleds;
82 	uint32_t	es_flags;
83 	etherswitch_port_led_t es_led[ETHERSWITCH_PORT_MAX_LEDS];
84 	union {
85 		struct ifreq		es_uifr;
86 		struct ifmediareq	es_uifmr;
87 	} es_ifu;
88 #define es_ifr		es_ifu.es_uifr
89 #define es_ifmr		es_ifu.es_uifmr
90 };
91 typedef struct etherswitch_port etherswitch_port_t;
92 
93 struct etherswitch_vlangroup {
94 	int		es_vlangroup;
95 	int		es_vid;
96 	int		es_member_ports;
97 	int		es_untagged_ports;
98 	int		es_fid;
99 };
100 typedef struct etherswitch_vlangroup etherswitch_vlangroup_t;
101 
102 #define ETHERSWITCH_PORTMASK(_port)	(1 << (_port))
103 
104 #define IOETHERSWITCHGETINFO		_IOR('i', 1, etherswitch_info_t)
105 #define IOETHERSWITCHGETREG		_IOWR('i', 2, etherswitch_reg_t)
106 #define IOETHERSWITCHSETREG		_IOW('i', 3, etherswitch_reg_t)
107 #define IOETHERSWITCHGETPORT		_IOWR('i', 4, etherswitch_port_t)
108 #define IOETHERSWITCHSETPORT		_IOW('i', 5, etherswitch_port_t)
109 #define IOETHERSWITCHGETVLANGROUP	_IOWR('i', 6, etherswitch_vlangroup_t)
110 #define IOETHERSWITCHSETVLANGROUP	_IOW('i', 7, etherswitch_vlangroup_t)
111 #define IOETHERSWITCHGETPHYREG		_IOWR('i', 8, etherswitch_phyreg_t)
112 #define IOETHERSWITCHSETPHYREG		_IOW('i', 9, etherswitch_phyreg_t)
113 #define IOETHERSWITCHGETCONF		_IOR('i', 10, etherswitch_conf_t)
114 #define IOETHERSWITCHSETCONF		_IOW('i', 11, etherswitch_conf_t)
115 
116 #endif
117