xref: /titanic_44/usr/src/uts/common/sys/mac_flow.h (revision 8de5c4f463386063e184a851437d58080c6c626c)
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 2009 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 /*
43  * MAXFLOWNAMELEN defines the longest possible permitted flow name,
44  * including the terminating NUL.
45  */
46 #define	MAXFLOWNAMELEN		128
47 
48 /* need to use MAXMACADDRLEN from dld.h instead of this one */
49 #define	MAXMACADDR		20
50 
51 /* Bit-mask for the selectors carried in the flow descriptor */
52 typedef	uint64_t		flow_mask_t;
53 
54 #define	FLOW_LINK_DST		0x00000001	/* Destination MAC addr */
55 #define	FLOW_LINK_SRC		0x00000002	/* Source MAC address */
56 #define	FLOW_LINK_VID		0x00000004	/* VLAN ID */
57 #define	FLOW_LINK_SAP		0x00000008	/* SAP value */
58 
59 #define	FLOW_IP_VERSION		0x00000010	/* V4 or V6 */
60 #define	FLOW_IP_PROTOCOL	0x00000020	/* Protocol type */
61 #define	FLOW_IP_LOCAL		0x00000040	/* Local address */
62 #define	FLOW_IP_REMOTE		0x00000080	/* Remote address */
63 #define	FLOW_IP_DSFIELD		0x00000100	/* DSfield value */
64 
65 #define	FLOW_ULP_PORT_LOCAL	0x00001000	/* ULP local port */
66 #define	FLOW_ULP_PORT_REMOTE	0x00002000	/* ULP remote port */
67 
68 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
69 #pragma pack(4)
70 #endif
71 
72 typedef struct flow_desc_s {
73 	flow_mask_t			fd_mask;
74 	uint32_t			fd_mac_len;
75 	uint8_t				fd_dst_mac[MAXMACADDR];
76 	uint8_t				fd_src_mac[MAXMACADDR];
77 	uint16_t			fd_vid;
78 	uint32_t			fd_sap;
79 	uint8_t				fd_ipversion;
80 	uint8_t				fd_protocol;
81 	in6_addr_t			fd_local_addr;
82 	in6_addr_t			fd_local_netmask;
83 	in6_addr_t			fd_remote_addr;
84 	in6_addr_t			fd_remote_netmask;
85 	in_port_t			fd_local_port;
86 	in_port_t			fd_remote_port;
87 	uint8_t				fd_dsfield;
88 	uint8_t				fd_dsfield_mask;
89 } flow_desc_t;
90 
91 #define	MRP_NCPUS	128
92 
93 /*
94  * In MCM_CPUS mode, cpu bindings is user specified. In MCM_FANOUT mode,
95  * user only specifies a fanout count.
96  * mc_fanout_cnt gives the number of CPUs used for fanout soft rings.
97  * mc_fanout_cpus[] array stores the CPUs used for fanout soft rings.
98  */
99 typedef enum {
100 	MCM_FANOUT = 1,
101 	MCM_CPUS
102 } mac_cpu_mode_t;
103 
104 typedef struct mac_cpus_props_s {
105 	uint32_t		mc_ncpus;		/* num of cpus */
106 	uint32_t		mc_cpus[MRP_NCPUS]; 	/* cpu list */
107 	uint32_t		mc_fanout_cnt;		/* soft ring cpu cnt */
108 	uint32_t		mc_fanout_cpus[MRP_NCPUS]; /* SR cpu list */
109 	uint32_t		mc_pollid;		/* poll thr binding */
110 	uint32_t		mc_workerid;		/* worker thr binding */
111 	/*
112 	 * interrupt cpu: mrp_intr_cpu less than 0 implies platform limitation
113 	 * in retargetting the interrupt assignment.
114 	 */
115 	int32_t			mc_intr_cpu;
116 	mac_cpu_mode_t		mc_fanout_mode;		/* fanout mode */
117 } mac_cpus_t;
118 
119 /* Priority values */
120 typedef enum {
121 	MPL_LOW,
122 	MPL_MEDIUM,
123 	MPL_HIGH,
124 	MPL_RESET
125 } mac_priority_level_t;
126 
127 /* Protection types */
128 #define	MPT_MACNOSPOOF		0x00000001
129 #define	MPT_IPNOSPOOF		0x00000002
130 #define	MPT_RESTRICTED		0x00000004
131 #define	MPT_ALL			(MPT_MACNOSPOOF|MPT_IPNOSPOOF|MPT_RESTRICTED)
132 #define	MPT_RESET		0xffffffff
133 #define	MPT_MAXIPADDR		32
134 
135 typedef struct mac_protect_s {
136 	uint32_t	mp_types;
137 	uint32_t	mp_ipaddrcnt;
138 	ipaddr_t	mp_ipaddrs[MPT_MAXIPADDR];
139 } mac_protect_t;
140 
141 
142 /* The default priority for links */
143 #define	MPL_LINK_DEFAULT		MPL_HIGH
144 
145 /* The default priority for flows */
146 #define	MPL_SUBFLOW_DEFAULT		MPL_MEDIUM
147 
148 #define	MRP_MAXBW		0x00000001 	/* Limit set */
149 #define	MRP_CPUS		0x00000002 	/* CPU/fanout set */
150 #define	MRP_CPUS_USERSPEC	0x00000004 	/* CPU/fanout from user */
151 #define	MRP_PRIORITY		0x00000008 	/* Priority set */
152 #define	MRP_PROTECT		0x00000010	/* Protection set */
153 
154 #define	MRP_THROTTLE		MRP_MAXBW
155 
156 /* 3 levels - low, medium, high */
157 #define	MRP_PRIORITY_LEVELS		3
158 
159 /* Special value denoting no bandwidth control */
160 #define	MRP_MAXBW_RESETVAL		-1ULL
161 
162 /*
163  * Until sub-megabit limit is implemented,
164  * reject values lower than 1 MTU per tick or 1.2Mbps
165  */
166 #define	MRP_MAXBW_MINVAL		1200000
167 
168 typedef	struct mac_resource_props_s {
169 	/*
170 	 * Bit-mask for the network resource control types types
171 	 */
172 	uint32_t		mrp_mask;
173 	uint64_t		mrp_maxbw;	/* bandwidth limit in bps */
174 	mac_priority_level_t	mrp_priority;	/* relative flow priority */
175 	mac_cpus_t		mrp_cpus;
176 	mac_protect_t		mrp_protect;
177 } mac_resource_props_t;
178 
179 #define	mrp_ncpus	mrp_cpus.mc_ncpus
180 #define	mrp_cpu		mrp_cpus.mc_cpus
181 #define	mrp_fanout_cnt	mrp_cpus.mc_fanout_cnt
182 #define	mrp_fanout_cpu	mrp_cpus.mc_fanout_cpus
183 #define	mrp_pollid	mrp_cpus.mc_pollid
184 #define	mrp_workerid	mrp_cpus.mc_workerid
185 #define	mrp_intr_cpu	mrp_cpus.mc_intr_cpu
186 #define	mrp_fanout_mode	mrp_cpus.mc_fanout_mode
187 
188 #define	MAC_COPY_CPUS(mrp, fmrp) {					\
189 	int	ncpus;							\
190 	(fmrp)->mrp_ncpus = (mrp)->mrp_ncpus;				\
191 	(fmrp)->mrp_intr_cpu = (mrp)->mrp_intr_cpu;			\
192 	(fmrp)->mrp_fanout_mode = (mrp)->mrp_fanout_mode;		\
193 	if ((mrp)->mrp_ncpus == 0) {					\
194 		(fmrp)->mrp_mask &= ~MRP_CPUS;				\
195 		(fmrp)->mrp_mask &= ~MRP_CPUS_USERSPEC;			\
196 	} else {							\
197 		for (ncpus = 0; ncpus < (fmrp)->mrp_ncpus; ncpus++)	\
198 			(fmrp)->mrp_cpu[ncpus] = (mrp)->mrp_cpu[ncpus];\
199 		(fmrp)->mrp_mask |= MRP_CPUS;				\
200 		if ((mrp)->mrp_mask & MRP_CPUS_USERSPEC)		\
201 			(fmrp)->mrp_mask |= MRP_CPUS_USERSPEC;		\
202 	}								\
203 }
204 
205 typedef struct flow_stats_s {
206 	uint64_t	fs_rbytes;
207 	uint64_t	fs_ipackets;
208 	uint64_t	fs_ierrors;
209 	uint64_t	fs_obytes;
210 	uint64_t	fs_opackets;
211 	uint64_t	fs_oerrors;
212 } flow_stats_t;
213 
214 typedef enum {
215 	FLOW_STAT_RBYTES,
216 	FLOW_STAT_IPACKETS,
217 	FLOW_STAT_IERRORS,
218 	FLOW_STAT_OBYTES,
219 	FLOW_STAT_OPACKETS,
220 	FLOW_STAT_OERRORS
221 } flow_stat_t;
222 
223 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
224 #pragma pack()
225 #endif
226 
227 #ifdef	__cplusplus
228 }
229 #endif
230 
231 #endif	/* _MAC_FLOW_H */
232