xref: /titanic_41/usr/src/uts/common/sys/mac_flow.h (revision bda1f129971950880940a17bab0bf096d5744b0c)
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 /* The default priority for links */
128 #define	MPL_LINK_DEFAULT		MPL_HIGH
129 
130 /* The default priority for flows */
131 #define	MPL_SUBFLOW_DEFAULT		MPL_MEDIUM
132 
133 #define	MRP_MAXBW		0x00000001 	/* Limit set */
134 #define	MRP_CPUS		0x00000002 	/* CPU/fanout set */
135 #define	MRP_CPUS_USERSPEC	0x00000004 	/* CPU/fanout from user */
136 #define	MRP_PRIORITY		0x00000008 	/* Priority set */
137 
138 #define	MRP_THROTTLE		MRP_MAXBW
139 
140 /* 3 levels - low, medium, high */
141 #define	MRP_PRIORITY_LEVELS		3
142 
143 /* Special value denoting no bandwidth control */
144 #define	MRP_MAXBW_RESETVAL		-1ULL
145 
146 /*
147  * Until sub-megabit limit is implemented,
148  * reject values lower than 1 MTU per tick or 1.2Mbps
149  */
150 #define	MRP_MAXBW_MINVAL		1200000
151 
152 typedef	struct mac_resource_props_s {
153 	/*
154 	 * Bit-mask for the network resource control types types
155 	 */
156 	uint32_t		mrp_mask;
157 	uint64_t		mrp_maxbw;	/* bandwidth limit in bps */
158 	mac_priority_level_t	mrp_priority;	/* relative flow priority */
159 	mac_cpus_t		mrp_cpus;
160 } mac_resource_props_t;
161 
162 #define	mrp_ncpus	mrp_cpus.mc_ncpus
163 #define	mrp_cpu		mrp_cpus.mc_cpus
164 #define	mrp_fanout_cnt	mrp_cpus.mc_fanout_cnt
165 #define	mrp_fanout_cpu	mrp_cpus.mc_fanout_cpus
166 #define	mrp_pollid	mrp_cpus.mc_pollid
167 #define	mrp_workerid	mrp_cpus.mc_workerid
168 #define	mrp_intr_cpu	mrp_cpus.mc_intr_cpu
169 #define	mrp_fanout_mode	mrp_cpus.mc_fanout_mode
170 
171 #define	MAC_COPY_CPUS(mrp, fmrp) {					\
172 	int	ncpus;							\
173 	(fmrp)->mrp_ncpus = (mrp)->mrp_ncpus;				\
174 	(fmrp)->mrp_intr_cpu = (mrp)->mrp_intr_cpu;			\
175 	(fmrp)->mrp_fanout_mode = (mrp)->mrp_fanout_mode;		\
176 	if ((mrp)->mrp_ncpus == 0) {					\
177 		(fmrp)->mrp_mask &= ~MRP_CPUS;				\
178 		(fmrp)->mrp_mask &= ~MRP_CPUS_USERSPEC;			\
179 	} else {							\
180 		for (ncpus = 0; ncpus < (fmrp)->mrp_ncpus; ncpus++)	\
181 			(fmrp)->mrp_cpu[ncpus] = (mrp)->mrp_cpu[ncpus];\
182 		(fmrp)->mrp_mask |= MRP_CPUS;				\
183 		if ((mrp)->mrp_mask & MRP_CPUS_USERSPEC)		\
184 			(fmrp)->mrp_mask |= MRP_CPUS_USERSPEC;		\
185 	}								\
186 }
187 
188 typedef struct flow_stats_s {
189 	uint64_t	fs_rbytes;
190 	uint64_t	fs_ipackets;
191 	uint64_t	fs_ierrors;
192 	uint64_t	fs_obytes;
193 	uint64_t	fs_opackets;
194 	uint64_t	fs_oerrors;
195 } flow_stats_t;
196 
197 typedef enum {
198 	FLOW_STAT_RBYTES,
199 	FLOW_STAT_IPACKETS,
200 	FLOW_STAT_IERRORS,
201 	FLOW_STAT_OBYTES,
202 	FLOW_STAT_OPACKETS,
203 	FLOW_STAT_OERRORS
204 } flow_stat_t;
205 
206 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
207 #pragma pack()
208 #endif
209 
210 #ifdef	__cplusplus
211 }
212 #endif
213 
214 #endif	/* _MAC_FLOW_H */
215