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