xref: /illumos-gate/usr/src/uts/common/sys/mac_flow.h (revision 5f82aa32fbc5dc2c59bca6ff315f44a4c4c9ea86)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  * Copyright 2013 Joyent, Inc.  All rights reserved.
26  */
27 
28 #ifndef	_MAC_FLOW_H
29 #define	_MAC_FLOW_H
30 
31 /*
32  * Main structure describing a flow of packets, for classification use
33  */
34 
35 #ifdef	__cplusplus
36 extern "C" {
37 #endif
38 
39 #include <sys/types.h>
40 #include <sys/param.h>		/* for MAXPATHLEN */
41 #include <netinet/in.h>		/* for IPPROTO_* constants */
42 #include <sys/ethernet.h>
43 
44 #define	MAX_RINGS_PER_GROUP	128
45 
46 /*
47  * MAXFLOWNAMELEN defines the longest possible permitted flow name,
48  * including the terminating NUL.
49  */
50 #define	MAXFLOWNAMELEN		128
51 
52 /* need to use MAXMACADDRLEN from dld.h instead of this one */
53 #define	MAXMACADDR		20
54 
55 /* Bit-mask for the selectors carried in the flow descriptor */
56 typedef	uint64_t		flow_mask_t;
57 
58 #define	FLOW_LINK_DST		0x00000001	/* Destination MAC addr */
59 #define	FLOW_LINK_SRC		0x00000002	/* Source MAC address */
60 #define	FLOW_LINK_VID		0x00000004	/* VLAN ID */
61 #define	FLOW_LINK_SAP		0x00000008	/* SAP value */
62 
63 #define	FLOW_IP_VERSION		0x00000010	/* V4 or V6 */
64 #define	FLOW_IP_PROTOCOL	0x00000020	/* Protocol type */
65 #define	FLOW_IP_LOCAL		0x00000040	/* Local address */
66 #define	FLOW_IP_REMOTE		0x00000080	/* Remote address */
67 #define	FLOW_IP_DSFIELD		0x00000100	/* DSfield value */
68 
69 #define	FLOW_ULP_PORT_LOCAL	0x00001000	/* ULP local port */
70 #define	FLOW_ULP_PORT_REMOTE	0x00002000	/* ULP remote port */
71 
72 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
73 #pragma pack(4)
74 #endif
75 
76 typedef struct flow_desc_s {
77 	flow_mask_t			fd_mask;
78 	uint32_t			fd_mac_len;
79 	uint8_t				fd_dst_mac[MAXMACADDR];
80 	uint8_t				fd_src_mac[MAXMACADDR];
81 	uint16_t			fd_vid;
82 	uint32_t			fd_sap;
83 	uint8_t				fd_ipversion;
84 	uint8_t				fd_protocol;
85 	in6_addr_t			fd_local_addr;
86 	in6_addr_t			fd_local_netmask;
87 	in6_addr_t			fd_remote_addr;
88 	in6_addr_t			fd_remote_netmask;
89 	in_port_t			fd_local_port;
90 	in_port_t			fd_remote_port;
91 	uint8_t				fd_dsfield;
92 	uint8_t				fd_dsfield_mask;
93 } flow_desc_t;
94 
95 #define	MRP_NCPUS	128
96 
97 /*
98  * In MCM_CPUS mode, cpu bindings is user specified. In MCM_FANOUT mode,
99  * user only specifies a fanout count.
100  * mc_rx_fanout_cnt gives the number of CPUs used for fanout soft rings.
101  * mc_rx_fanout_cpus[] array stores the CPUs used for fanout soft rings.
102  */
103 typedef enum {
104 	MCM_FANOUT = 1,
105 	MCM_CPUS
106 } mac_cpu_mode_t;
107 
108 /*
109  * Structure to store the value of the CPUs to be used to re-target
110  * Tx interrupt.
111  */
112 typedef struct mac_tx_intr_cpus_s {
113 	/* cpu value to re-target intr to */
114 	int32_t		mtc_intr_cpu[MRP_NCPUS];
115 	/* re-targeted CPU or -1 if failed */
116 	int32_t		mtc_retargeted_cpu[MRP_NCPUS];
117 } mac_tx_intr_cpu_t;
118 
119 typedef struct mac_cpus_props_s {
120 	uint32_t		mc_ncpus;		/* num of cpus */
121 	uint32_t		mc_cpus[MRP_NCPUS]; 	/* cpu list */
122 	uint32_t		mc_rx_fanout_cnt;	/* soft ring cpu cnt */
123 	uint32_t		mc_rx_fanout_cpus[MRP_NCPUS]; /* SR cpu list */
124 	uint32_t		mc_rx_pollid;		/* poll thr binding */
125 	uint32_t		mc_rx_workerid;		/* worker thr binding */
126 	/*
127 	 * interrupt cpu: mrp_intr_cpu less than 0 implies platform limitation
128 	 * in retargetting the interrupt assignment.
129 	 */
130 	int32_t			mc_rx_intr_cpu;
131 	int32_t			mc_tx_fanout_cpus[MRP_NCPUS];
132 	mac_tx_intr_cpu_t	mc_tx_intr_cpus;
133 	mac_cpu_mode_t		mc_fanout_mode;		/* fanout mode */
134 } mac_cpus_t;
135 
136 #define	mc_tx_intr_cpu		mc_tx_intr_cpus.mtc_intr_cpu
137 #define	mc_tx_retargeted_cpu	mc_tx_intr_cpus.mtc_retargeted_cpu
138 
139 /* Priority values */
140 typedef enum {
141 	MPL_LOW,
142 	MPL_MEDIUM,
143 	MPL_HIGH,
144 	MPL_RESET
145 } mac_priority_level_t;
146 
147 /* Protection types */
148 #define	MPT_MACNOSPOOF		0x00000001
149 #define	MPT_RESTRICTED		0x00000002
150 #define	MPT_IPNOSPOOF		0x00000004
151 #define	MPT_DHCPNOSPOOF		0x00000008
152 #define	MPT_ALL			0x0000000f
153 #define	MPT_RESET		0xffffffff
154 #define	MPT_MAXCNT		32
155 #define	MPT_MAXIPADDR		MPT_MAXCNT
156 #define	MPT_MAXCID		MPT_MAXCNT
157 #define	MPT_MAXCIDLEN		256
158 
159 typedef struct mac_ipaddr_s {
160 	uint32_t	ip_version;
161 	in6_addr_t	ip_addr;
162 	uint8_t		ip_netmask;
163 } mac_ipaddr_t;
164 
165 typedef enum {
166 	CIDFORM_TYPED = 1,
167 	CIDFORM_HEX,
168 	CIDFORM_STR
169 } mac_dhcpcid_form_t;
170 
171 typedef struct mac_dhcpcid_s {
172 	uchar_t			dc_id[MPT_MAXCIDLEN];
173 	uint32_t		dc_len;
174 	mac_dhcpcid_form_t	dc_form;
175 } mac_dhcpcid_t;
176 
177 typedef struct mac_protect_s {
178 	uint32_t	mp_types;
179 	uint32_t	mp_ipaddrcnt;
180 	mac_ipaddr_t	mp_ipaddrs[MPT_MAXIPADDR];
181 	uint32_t	mp_cidcnt;
182 	mac_dhcpcid_t	mp_cids[MPT_MAXCID];
183 } mac_protect_t;
184 
185 /* The default priority for links */
186 #define	MPL_LINK_DEFAULT		MPL_HIGH
187 
188 /* The default priority for flows */
189 #define	MPL_SUBFLOW_DEFAULT		MPL_MEDIUM
190 
191 #define	MRP_MAXBW		0x00000001 	/* Limit set */
192 #define	MRP_CPUS		0x00000002 	/* CPU/fanout set */
193 #define	MRP_CPUS_USERSPEC	0x00000004 	/* CPU/fanout from user */
194 #define	MRP_PRIORITY		0x00000008 	/* Priority set */
195 #define	MRP_PROTECT		0x00000010	/* Protection set */
196 #define	MRP_RX_RINGS		0x00000020	/* Rx rings */
197 #define	MRP_TX_RINGS		0x00000040	/* Tx rings */
198 #define	MRP_RXRINGS_UNSPEC	0x00000080	/* unspecified rings */
199 #define	MRP_TXRINGS_UNSPEC	0x00000100	/* unspecified rings */
200 #define	MRP_RINGS_RESET		0x00000200	/* resetting rings */
201 #define	MRP_POOL		0x00000400	/* CPU pool */
202 
203 #define	MRP_THROTTLE		MRP_MAXBW
204 
205 /* 3 levels - low, medium, high */
206 #define	MRP_PRIORITY_LEVELS		3
207 
208 /* Special value denoting no bandwidth control */
209 #define	MRP_MAXBW_RESETVAL		-1ULL
210 
211 /*
212  * Until sub-megabit limit is implemented,
213  * reject values lower than 1 MTU per tick or 1.2Mbps
214  */
215 #define	MRP_MAXBW_MINVAL		1200000
216 
217 typedef	struct mac_resource_props_s {
218 	/*
219 	 * Bit-mask for the network resource control types types
220 	 */
221 	uint32_t		mrp_mask;
222 	uint64_t		mrp_maxbw;	/* bandwidth limit in bps */
223 	mac_priority_level_t	mrp_priority;	/* relative flow priority */
224 	mac_cpus_t		mrp_cpus;
225 	mac_protect_t		mrp_protect;
226 	uint32_t		mrp_nrxrings;
227 	uint32_t		mrp_ntxrings;
228 	char			mrp_pool[MAXPATHLEN];	/* CPU pool */
229 } mac_resource_props_t;
230 
231 #define	mrp_ncpus		mrp_cpus.mc_ncpus
232 #define	mrp_cpu			mrp_cpus.mc_cpus
233 #define	mrp_rx_fanout_cnt	mrp_cpus.mc_rx_fanout_cnt
234 #define	mrp_rx_pollid		mrp_cpus.mc_rx_pollid
235 #define	mrp_rx_workerid		mrp_cpus.mc_rx_workerid
236 #define	mrp_rx_intr_cpu		mrp_cpus.mc_rx_intr_cpu
237 #define	mrp_fanout_mode		mrp_cpus.mc_fanout_mode
238 
239 #define	MAC_COPY_CPUS(mrp, fmrp) {					\
240 	int	ncpus;							\
241 	(fmrp)->mrp_ncpus = (mrp)->mrp_ncpus;				\
242 	(fmrp)->mrp_rx_fanout_cnt = (mrp)->mrp_rx_fanout_cnt;		\
243 	(fmrp)->mrp_rx_intr_cpu = (mrp)->mrp_rx_intr_cpu;		\
244 	(fmrp)->mrp_fanout_mode = (mrp)->mrp_fanout_mode;		\
245 	if ((mrp)->mrp_ncpus == 0) {					\
246 		(fmrp)->mrp_mask &= ~MRP_CPUS;				\
247 		(fmrp)->mrp_mask &= ~MRP_CPUS_USERSPEC;			\
248 	} else {							\
249 		for (ncpus = 0; ncpus < (fmrp)->mrp_ncpus; ncpus++)	\
250 			(fmrp)->mrp_cpu[ncpus] = (mrp)->mrp_cpu[ncpus];\
251 		(fmrp)->mrp_mask |= MRP_CPUS;				\
252 		if ((mrp)->mrp_mask & MRP_CPUS_USERSPEC)		\
253 			(fmrp)->mrp_mask |= MRP_CPUS_USERSPEC;		\
254 	}								\
255 }
256 
257 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
258 #pragma pack()
259 #endif
260 
261 #ifdef	__cplusplus
262 }
263 #endif
264 
265 #endif	/* _MAC_FLOW_H */
266