1da14cebeSEric Cheng /* 2da14cebeSEric Cheng * CDDL HEADER START 3da14cebeSEric Cheng * 4da14cebeSEric Cheng * The contents of this file are subject to the terms of the 5da14cebeSEric Cheng * Common Development and Distribution License (the "License"). 6da14cebeSEric Cheng * You may not use this file except in compliance with the License. 7da14cebeSEric Cheng * 8da14cebeSEric Cheng * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9da14cebeSEric Cheng * or http://www.opensolaris.org/os/licensing. 10da14cebeSEric Cheng * See the License for the specific language governing permissions 11da14cebeSEric Cheng * and limitations under the License. 12da14cebeSEric Cheng * 13da14cebeSEric Cheng * When distributing Covered Code, include this CDDL HEADER in each 14da14cebeSEric Cheng * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15da14cebeSEric Cheng * If applicable, add the following below this CDDL HEADER, with the 16da14cebeSEric Cheng * fields enclosed by brackets "[]" replaced with your own identifying 17da14cebeSEric Cheng * information: Portions Copyright [yyyy] [name of copyright owner] 18da14cebeSEric Cheng * 19da14cebeSEric Cheng * CDDL HEADER END 20da14cebeSEric Cheng */ 21da14cebeSEric Cheng 22da14cebeSEric Cheng /* 230dc2366fSVenugopal Iyer * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 24da14cebeSEric Cheng * Use is subject to license terms. 25*e03914f9SRobert Mustacchi * Copyright 2013 Joyent, Inc. All rights reserved. 26da14cebeSEric Cheng */ 27da14cebeSEric Cheng 28da14cebeSEric Cheng #ifndef _MAC_FLOW_H 29da14cebeSEric Cheng #define _MAC_FLOW_H 30da14cebeSEric Cheng 31da14cebeSEric Cheng /* 32da14cebeSEric Cheng * Main structure describing a flow of packets, for classification use 33da14cebeSEric Cheng */ 34da14cebeSEric Cheng 35da14cebeSEric Cheng #ifdef __cplusplus 36da14cebeSEric Cheng extern "C" { 37da14cebeSEric Cheng #endif 38da14cebeSEric Cheng 39da14cebeSEric Cheng #include <sys/types.h> 40da14cebeSEric Cheng #include <netinet/in.h> /* for IPPROTO_* constants */ 41da14cebeSEric Cheng #include <sys/ethernet.h> 42da14cebeSEric Cheng 430dc2366fSVenugopal Iyer #define MAX_RINGS_PER_GROUP 128 440dc2366fSVenugopal Iyer 45da000602SGirish Moodalbail /* 46da000602SGirish Moodalbail * MAXFLOWNAMELEN defines the longest possible permitted flow name, 47da000602SGirish Moodalbail * including the terminating NUL. 48da000602SGirish Moodalbail */ 49da000602SGirish Moodalbail #define MAXFLOWNAMELEN 128 50da14cebeSEric Cheng 51da14cebeSEric Cheng /* need to use MAXMACADDRLEN from dld.h instead of this one */ 52da14cebeSEric Cheng #define MAXMACADDR 20 53da14cebeSEric Cheng 54da14cebeSEric Cheng /* Bit-mask for the selectors carried in the flow descriptor */ 55da14cebeSEric Cheng typedef uint64_t flow_mask_t; 56da14cebeSEric Cheng 57da14cebeSEric Cheng #define FLOW_LINK_DST 0x00000001 /* Destination MAC addr */ 58da14cebeSEric Cheng #define FLOW_LINK_SRC 0x00000002 /* Source MAC address */ 59da14cebeSEric Cheng #define FLOW_LINK_VID 0x00000004 /* VLAN ID */ 60da14cebeSEric Cheng #define FLOW_LINK_SAP 0x00000008 /* SAP value */ 61da14cebeSEric Cheng 62da14cebeSEric Cheng #define FLOW_IP_VERSION 0x00000010 /* V4 or V6 */ 63da14cebeSEric Cheng #define FLOW_IP_PROTOCOL 0x00000020 /* Protocol type */ 64da14cebeSEric Cheng #define FLOW_IP_LOCAL 0x00000040 /* Local address */ 65da14cebeSEric Cheng #define FLOW_IP_REMOTE 0x00000080 /* Remote address */ 66da14cebeSEric Cheng #define FLOW_IP_DSFIELD 0x00000100 /* DSfield value */ 67da14cebeSEric Cheng 68da14cebeSEric Cheng #define FLOW_ULP_PORT_LOCAL 0x00001000 /* ULP local port */ 69da14cebeSEric Cheng #define FLOW_ULP_PORT_REMOTE 0x00002000 /* ULP remote port */ 70da14cebeSEric Cheng 71da14cebeSEric Cheng #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4 72da14cebeSEric Cheng #pragma pack(4) 73da14cebeSEric Cheng #endif 74da14cebeSEric Cheng 75da14cebeSEric Cheng typedef struct flow_desc_s { 76da14cebeSEric Cheng flow_mask_t fd_mask; 77da14cebeSEric Cheng uint32_t fd_mac_len; 78da14cebeSEric Cheng uint8_t fd_dst_mac[MAXMACADDR]; 79da14cebeSEric Cheng uint8_t fd_src_mac[MAXMACADDR]; 80da14cebeSEric Cheng uint16_t fd_vid; 81da14cebeSEric Cheng uint32_t fd_sap; 82da14cebeSEric Cheng uint8_t fd_ipversion; 83da14cebeSEric Cheng uint8_t fd_protocol; 84da14cebeSEric Cheng in6_addr_t fd_local_addr; 85da14cebeSEric Cheng in6_addr_t fd_local_netmask; 86da14cebeSEric Cheng in6_addr_t fd_remote_addr; 87da14cebeSEric Cheng in6_addr_t fd_remote_netmask; 88da14cebeSEric Cheng in_port_t fd_local_port; 89da14cebeSEric Cheng in_port_t fd_remote_port; 90da14cebeSEric Cheng uint8_t fd_dsfield; 91da14cebeSEric Cheng uint8_t fd_dsfield_mask; 92da14cebeSEric Cheng } flow_desc_t; 93da14cebeSEric Cheng 94da14cebeSEric Cheng #define MRP_NCPUS 128 95da14cebeSEric Cheng 96da14cebeSEric Cheng /* 97da14cebeSEric Cheng * In MCM_CPUS mode, cpu bindings is user specified. In MCM_FANOUT mode, 98da14cebeSEric Cheng * user only specifies a fanout count. 990dc2366fSVenugopal Iyer * mc_rx_fanout_cnt gives the number of CPUs used for fanout soft rings. 1000dc2366fSVenugopal Iyer * mc_rx_fanout_cpus[] array stores the CPUs used for fanout soft rings. 101da14cebeSEric Cheng */ 102da14cebeSEric Cheng typedef enum { 103da14cebeSEric Cheng MCM_FANOUT = 1, 104da14cebeSEric Cheng MCM_CPUS 105da14cebeSEric Cheng } mac_cpu_mode_t; 106da14cebeSEric Cheng 1070dc2366fSVenugopal Iyer /* 1080dc2366fSVenugopal Iyer * Structure to store the value of the CPUs to be used to re-target 1090dc2366fSVenugopal Iyer * Tx interrupt. 1100dc2366fSVenugopal Iyer */ 1110dc2366fSVenugopal Iyer typedef struct mac_tx_intr_cpus_s { 1120dc2366fSVenugopal Iyer /* cpu value to re-target intr to */ 1130dc2366fSVenugopal Iyer int32_t mtc_intr_cpu[MRP_NCPUS]; 1140dc2366fSVenugopal Iyer /* re-targeted CPU or -1 if failed */ 1150dc2366fSVenugopal Iyer int32_t mtc_retargeted_cpu[MRP_NCPUS]; 1160dc2366fSVenugopal Iyer } mac_tx_intr_cpu_t; 1170dc2366fSVenugopal Iyer 118da14cebeSEric Cheng typedef struct mac_cpus_props_s { 119da14cebeSEric Cheng uint32_t mc_ncpus; /* num of cpus */ 120da14cebeSEric Cheng uint32_t mc_cpus[MRP_NCPUS]; /* cpu list */ 1210dc2366fSVenugopal Iyer uint32_t mc_rx_fanout_cnt; /* soft ring cpu cnt */ 1220dc2366fSVenugopal Iyer uint32_t mc_rx_fanout_cpus[MRP_NCPUS]; /* SR cpu list */ 1230dc2366fSVenugopal Iyer uint32_t mc_rx_pollid; /* poll thr binding */ 1240dc2366fSVenugopal Iyer uint32_t mc_rx_workerid; /* worker thr binding */ 125da14cebeSEric Cheng /* 126da14cebeSEric Cheng * interrupt cpu: mrp_intr_cpu less than 0 implies platform limitation 127da14cebeSEric Cheng * in retargetting the interrupt assignment. 128da14cebeSEric Cheng */ 1290dc2366fSVenugopal Iyer int32_t mc_rx_intr_cpu; 1300dc2366fSVenugopal Iyer int32_t mc_tx_fanout_cpus[MRP_NCPUS]; 1310dc2366fSVenugopal Iyer mac_tx_intr_cpu_t mc_tx_intr_cpus; 132da14cebeSEric Cheng mac_cpu_mode_t mc_fanout_mode; /* fanout mode */ 133da14cebeSEric Cheng } mac_cpus_t; 134da14cebeSEric Cheng 1350dc2366fSVenugopal Iyer #define mc_tx_intr_cpu mc_tx_intr_cpus.mtc_intr_cpu 1360dc2366fSVenugopal Iyer #define mc_tx_retargeted_cpu mc_tx_intr_cpus.mtc_retargeted_cpu 1370dc2366fSVenugopal Iyer 138da14cebeSEric Cheng /* Priority values */ 139da14cebeSEric Cheng typedef enum { 140da14cebeSEric Cheng MPL_LOW, 141da14cebeSEric Cheng MPL_MEDIUM, 142da14cebeSEric Cheng MPL_HIGH, 143da14cebeSEric Cheng MPL_RESET 144da14cebeSEric Cheng } mac_priority_level_t; 145da14cebeSEric Cheng 14625ec3e3dSEric Cheng /* Protection types */ 14725ec3e3dSEric Cheng #define MPT_MACNOSPOOF 0x00000001 1480dc2366fSVenugopal Iyer #define MPT_RESTRICTED 0x00000002 1490dc2366fSVenugopal Iyer #define MPT_IPNOSPOOF 0x00000004 1500dc2366fSVenugopal Iyer #define MPT_DHCPNOSPOOF 0x00000008 1510dc2366fSVenugopal Iyer #define MPT_ALL 0x0000000f 15225ec3e3dSEric Cheng #define MPT_RESET 0xffffffff 1530dc2366fSVenugopal Iyer #define MPT_MAXCNT 32 1540dc2366fSVenugopal Iyer #define MPT_MAXIPADDR MPT_MAXCNT 1550dc2366fSVenugopal Iyer #define MPT_MAXCID MPT_MAXCNT 1560dc2366fSVenugopal Iyer #define MPT_MAXCIDLEN 256 1570dc2366fSVenugopal Iyer 1580dc2366fSVenugopal Iyer typedef struct mac_ipaddr_s { 1590dc2366fSVenugopal Iyer uint32_t ip_version; 1600dc2366fSVenugopal Iyer in6_addr_t ip_addr; 161*e03914f9SRobert Mustacchi uint8_t ip_netmask; 1620dc2366fSVenugopal Iyer } mac_ipaddr_t; 1630dc2366fSVenugopal Iyer 1640dc2366fSVenugopal Iyer typedef enum { 1650dc2366fSVenugopal Iyer CIDFORM_TYPED = 1, 1660dc2366fSVenugopal Iyer CIDFORM_HEX, 1670dc2366fSVenugopal Iyer CIDFORM_STR 1680dc2366fSVenugopal Iyer } mac_dhcpcid_form_t; 1690dc2366fSVenugopal Iyer 1700dc2366fSVenugopal Iyer typedef struct mac_dhcpcid_s { 1710dc2366fSVenugopal Iyer uchar_t dc_id[MPT_MAXCIDLEN]; 1720dc2366fSVenugopal Iyer uint32_t dc_len; 1730dc2366fSVenugopal Iyer mac_dhcpcid_form_t dc_form; 1740dc2366fSVenugopal Iyer } mac_dhcpcid_t; 17525ec3e3dSEric Cheng 17625ec3e3dSEric Cheng typedef struct mac_protect_s { 17725ec3e3dSEric Cheng uint32_t mp_types; 17825ec3e3dSEric Cheng uint32_t mp_ipaddrcnt; 1790dc2366fSVenugopal Iyer mac_ipaddr_t mp_ipaddrs[MPT_MAXIPADDR]; 1800dc2366fSVenugopal Iyer uint32_t mp_cidcnt; 1810dc2366fSVenugopal Iyer mac_dhcpcid_t mp_cids[MPT_MAXCID]; 18225ec3e3dSEric Cheng } mac_protect_t; 18325ec3e3dSEric Cheng 184da14cebeSEric Cheng /* The default priority for links */ 185da14cebeSEric Cheng #define MPL_LINK_DEFAULT MPL_HIGH 186da14cebeSEric Cheng 187da14cebeSEric Cheng /* The default priority for flows */ 188da14cebeSEric Cheng #define MPL_SUBFLOW_DEFAULT MPL_MEDIUM 189da14cebeSEric Cheng 190da14cebeSEric Cheng #define MRP_MAXBW 0x00000001 /* Limit set */ 191da14cebeSEric Cheng #define MRP_CPUS 0x00000002 /* CPU/fanout set */ 192da14cebeSEric Cheng #define MRP_CPUS_USERSPEC 0x00000004 /* CPU/fanout from user */ 193da14cebeSEric Cheng #define MRP_PRIORITY 0x00000008 /* Priority set */ 19425ec3e3dSEric Cheng #define MRP_PROTECT 0x00000010 /* Protection set */ 1950dc2366fSVenugopal Iyer #define MRP_RX_RINGS 0x00000020 /* Rx rings */ 1960dc2366fSVenugopal Iyer #define MRP_TX_RINGS 0x00000040 /* Tx rings */ 1970dc2366fSVenugopal Iyer #define MRP_RXRINGS_UNSPEC 0x00000080 /* unspecified rings */ 1980dc2366fSVenugopal Iyer #define MRP_TXRINGS_UNSPEC 0x00000100 /* unspecified rings */ 1990dc2366fSVenugopal Iyer #define MRP_RINGS_RESET 0x00000200 /* resetting rings */ 2000dc2366fSVenugopal Iyer #define MRP_POOL 0x00000400 /* CPU pool */ 201da14cebeSEric Cheng 202da14cebeSEric Cheng #define MRP_THROTTLE MRP_MAXBW 203da14cebeSEric Cheng 204da14cebeSEric Cheng /* 3 levels - low, medium, high */ 205da14cebeSEric Cheng #define MRP_PRIORITY_LEVELS 3 206da14cebeSEric Cheng 207da14cebeSEric Cheng /* Special value denoting no bandwidth control */ 208da14cebeSEric Cheng #define MRP_MAXBW_RESETVAL -1ULL 209da14cebeSEric Cheng 210da14cebeSEric Cheng /* 211da14cebeSEric Cheng * Until sub-megabit limit is implemented, 212da14cebeSEric Cheng * reject values lower than 1 MTU per tick or 1.2Mbps 213da14cebeSEric Cheng */ 214da14cebeSEric Cheng #define MRP_MAXBW_MINVAL 1200000 215da14cebeSEric Cheng 216da14cebeSEric Cheng typedef struct mac_resource_props_s { 217da14cebeSEric Cheng /* 218da14cebeSEric Cheng * Bit-mask for the network resource control types types 219da14cebeSEric Cheng */ 220da14cebeSEric Cheng uint32_t mrp_mask; 221da14cebeSEric Cheng uint64_t mrp_maxbw; /* bandwidth limit in bps */ 222da14cebeSEric Cheng mac_priority_level_t mrp_priority; /* relative flow priority */ 223da14cebeSEric Cheng mac_cpus_t mrp_cpus; 22425ec3e3dSEric Cheng mac_protect_t mrp_protect; 2250dc2366fSVenugopal Iyer uint32_t mrp_nrxrings; 2260dc2366fSVenugopal Iyer uint32_t mrp_ntxrings; 2270dc2366fSVenugopal Iyer char mrp_pool[MAXPATHLEN]; /* CPU pool */ 228da14cebeSEric Cheng } mac_resource_props_t; 229da14cebeSEric Cheng 230da14cebeSEric Cheng #define mrp_ncpus mrp_cpus.mc_ncpus 231da14cebeSEric Cheng #define mrp_cpu mrp_cpus.mc_cpus 2320dc2366fSVenugopal Iyer #define mrp_rx_fanout_cnt mrp_cpus.mc_rx_fanout_cnt 2330dc2366fSVenugopal Iyer #define mrp_rx_pollid mrp_cpus.mc_rx_pollid 2340dc2366fSVenugopal Iyer #define mrp_rx_workerid mrp_cpus.mc_rx_workerid 2350dc2366fSVenugopal Iyer #define mrp_rx_intr_cpu mrp_cpus.mc_rx_intr_cpu 236da14cebeSEric Cheng #define mrp_fanout_mode mrp_cpus.mc_fanout_mode 237da14cebeSEric Cheng 238da14cebeSEric Cheng #define MAC_COPY_CPUS(mrp, fmrp) { \ 239da14cebeSEric Cheng int ncpus; \ 240da14cebeSEric Cheng (fmrp)->mrp_ncpus = (mrp)->mrp_ncpus; \ 2410dc2366fSVenugopal Iyer (fmrp)->mrp_rx_fanout_cnt = (mrp)->mrp_rx_fanout_cnt; \ 2420dc2366fSVenugopal Iyer (fmrp)->mrp_rx_intr_cpu = (mrp)->mrp_rx_intr_cpu; \ 243da14cebeSEric Cheng (fmrp)->mrp_fanout_mode = (mrp)->mrp_fanout_mode; \ 244da14cebeSEric Cheng if ((mrp)->mrp_ncpus == 0) { \ 245da14cebeSEric Cheng (fmrp)->mrp_mask &= ~MRP_CPUS; \ 246da14cebeSEric Cheng (fmrp)->mrp_mask &= ~MRP_CPUS_USERSPEC; \ 247da14cebeSEric Cheng } else { \ 248da14cebeSEric Cheng for (ncpus = 0; ncpus < (fmrp)->mrp_ncpus; ncpus++) \ 249da14cebeSEric Cheng (fmrp)->mrp_cpu[ncpus] = (mrp)->mrp_cpu[ncpus];\ 250da14cebeSEric Cheng (fmrp)->mrp_mask |= MRP_CPUS; \ 251da14cebeSEric Cheng if ((mrp)->mrp_mask & MRP_CPUS_USERSPEC) \ 252da14cebeSEric Cheng (fmrp)->mrp_mask |= MRP_CPUS_USERSPEC; \ 253da14cebeSEric Cheng } \ 254da14cebeSEric Cheng } 255da14cebeSEric Cheng 256da14cebeSEric Cheng #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4 257da14cebeSEric Cheng #pragma pack() 258da14cebeSEric Cheng #endif 259da14cebeSEric Cheng 260da14cebeSEric Cheng #ifdef __cplusplus 261da14cebeSEric Cheng } 262da14cebeSEric Cheng #endif 263da14cebeSEric Cheng 264da14cebeSEric Cheng #endif /* _MAC_FLOW_H */ 265