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