xref: /freebsd-13-stable/sys/dev/etherswitch/etherswitch.h (revision 4b40a16f0d188422227478889b38cc341d50f88f)
1 /*
2  */
3 
4 #ifndef __SYS_DEV_ETHERSWITCH_ETHERSWITCH_H
5 #define __SYS_DEV_ETHERSWITCH_ETHERSWITCH_H
6 
7 #include <sys/ioccom.h>
8 #include <net/ethernet.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 	uint32_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 #define	ETHERSWITCH_CONF_SWITCH_MACADDR	(1 << 3)
51 
52 struct etherswitch_conf {
53 	uint32_t	cmd;		/* What to configure */
54 	uint32_t	vlan_mode;	/* Switch VLAN mode */
55 	struct ether_addr switch_macaddr;	/* Switch MAC address */
56 };
57 typedef struct etherswitch_conf etherswitch_conf_t;
58 
59 #define	ETHERSWITCH_PORT_CPU		(1 << 0)
60 #define	ETHERSWITCH_PORT_STRIPTAG	(1 << 1)
61 #define	ETHERSWITCH_PORT_ADDTAG		(1 << 2)
62 #define	ETHERSWITCH_PORT_FIRSTLOCK	(1 << 3)
63 #define	ETHERSWITCH_PORT_DROPUNTAGGED	(1 << 4)
64 #define	ETHERSWITCH_PORT_DOUBLE_TAG	(1 << 5)
65 #define	ETHERSWITCH_PORT_INGRESS	(1 << 6)
66 #define	ETHERSWITCH_PORT_DROPTAGGED     (1 << 7)
67 #define	ETHERSWITCH_PORT_FLAGS_BITS	\
68 "\020\1CPUPORT\2STRIPTAG\3ADDTAG\4FIRSTLOCK\5DROPUNTAGGED\6QinQ\7INGRESS" \
69 "\10DROPTAGGED"
70 
71 #define ETHERSWITCH_PORT_MAX_LEDS 3
72 
73 enum etherswitch_port_led {
74 	ETHERSWITCH_PORT_LED_DEFAULT,
75 	ETHERSWITCH_PORT_LED_ON,
76 	ETHERSWITCH_PORT_LED_OFF,
77 	ETHERSWITCH_PORT_LED_BLINK,
78 	ETHERSWITCH_PORT_LED_MAX
79 };
80 typedef enum etherswitch_port_led etherswitch_port_led_t;
81 
82 struct etherswitch_port {
83 	int		es_port;
84 	int		es_pvid;
85 	int		es_nleds;
86 	uint32_t	es_flags;
87 	etherswitch_port_led_t es_led[ETHERSWITCH_PORT_MAX_LEDS];
88 	union {
89 		struct ifreq		es_uifr;
90 		struct ifmediareq	es_uifmr;
91 	} es_ifu;
92 #define es_ifr		es_ifu.es_uifr
93 #define es_ifmr		es_ifu.es_uifmr
94 };
95 typedef struct etherswitch_port etherswitch_port_t;
96 
97 struct etherswitch_vlangroup {
98 	int		es_vlangroup;
99 	int		es_vid;
100 	int		es_member_ports;
101 	int		es_untagged_ports;
102 	int		es_fid;
103 };
104 typedef struct etherswitch_vlangroup etherswitch_vlangroup_t;
105 
106 #define ETHERSWITCH_PORTMASK(_port)	(1 << (_port))
107 
108 struct etherswitch_portid {
109 	int es_port;
110 };
111 typedef struct etherswitch_portid etherswitch_portid_t;
112 
113 struct etherswitch_atu_entry {
114 	int id;
115 	int es_portmask;
116 	uint8_t es_macaddr[ETHER_ADDR_LEN];
117 };
118 typedef struct etherswitch_atu_entry etherswitch_atu_entry_t;
119 
120 struct etherswitch_atu_table {
121 	uint32_t es_nitems;
122 };
123 typedef struct etherswitch_atu_table etherswitch_atu_table_t;
124 
125 struct etherswitch_atu_flush_macentry {
126 	uint8_t es_macaddr[ETHER_ADDR_LEN];
127 };
128 typedef struct etherswitch_atu_flush_macentry etherswitch_atu_flush_macentry_t;
129 
130 #define IOETHERSWITCHGETINFO		_IOR('i', 1, etherswitch_info_t)
131 #define IOETHERSWITCHGETREG		_IOWR('i', 2, etherswitch_reg_t)
132 #define IOETHERSWITCHSETREG		_IOW('i', 3, etherswitch_reg_t)
133 #define IOETHERSWITCHGETPORT		_IOWR('i', 4, etherswitch_port_t)
134 #define IOETHERSWITCHSETPORT		_IOW('i', 5, etherswitch_port_t)
135 #define IOETHERSWITCHGETVLANGROUP	_IOWR('i', 6, etherswitch_vlangroup_t)
136 #define IOETHERSWITCHSETVLANGROUP	_IOW('i', 7, etherswitch_vlangroup_t)
137 #define IOETHERSWITCHGETPHYREG		_IOWR('i', 8, etherswitch_phyreg_t)
138 #define IOETHERSWITCHSETPHYREG		_IOW('i', 9, etherswitch_phyreg_t)
139 #define IOETHERSWITCHGETCONF		_IOR('i', 10, etherswitch_conf_t)
140 #define IOETHERSWITCHSETCONF		_IOW('i', 11, etherswitch_conf_t)
141 #define IOETHERSWITCHFLUSHALL		_IOW('i', 12, etherswitch_portid_t)	/* Dummy */
142 #define IOETHERSWITCHFLUSHPORT		_IOW('i', 13, etherswitch_portid_t)
143 #define IOETHERSWITCHFLUSHMAC		_IOW('i', 14, etherswitch_atu_flush_macentry_t)
144 #define IOETHERSWITCHGETTABLE		_IOWR('i', 15, etherswitch_atu_table_t)
145 #define IOETHERSWITCHGETTABLEENTRY	_IOWR('i', 16, etherswitch_atu_entry_t)
146 
147 #endif
148