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