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