10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*2760Sdg199075 * Common Development and Distribution License (the "License"). 6*2760Sdg199075 * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*2760Sdg199075 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate /* 270Sstevel@tonic-gate * gldpriv.h - Private interfaces/structures needed by gld.c 280Sstevel@tonic-gate * 290Sstevel@tonic-gate * The definitions in this file are private to GLD and may change at any time. 300Sstevel@tonic-gate * They must not be used by any driver. 310Sstevel@tonic-gate */ 320Sstevel@tonic-gate 330Sstevel@tonic-gate #ifndef _SYS_GLDPRIV_H 340Sstevel@tonic-gate #define _SYS_GLDPRIV_H 350Sstevel@tonic-gate 360Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 370Sstevel@tonic-gate 380Sstevel@tonic-gate #ifdef __cplusplus 390Sstevel@tonic-gate extern "C" { 400Sstevel@tonic-gate #endif 410Sstevel@tonic-gate 420Sstevel@tonic-gate #ifdef DEBUG 430Sstevel@tonic-gate #define GLD_DEBUG 1 440Sstevel@tonic-gate #endif 450Sstevel@tonic-gate 460Sstevel@tonic-gate /* 470Sstevel@tonic-gate * The version number should not be changed. 480Sstevel@tonic-gate */ 490Sstevel@tonic-gate #define GLD_VERSION_200 0x200 /* version 2.0 */ 500Sstevel@tonic-gate #define GLD_VERSION GLD_VERSION_200 /* current version */ 510Sstevel@tonic-gate #define GLD_VERSION_STRING "v2" /* in modinfo string */ 520Sstevel@tonic-gate 530Sstevel@tonic-gate /* gld_global_options bits */ 540Sstevel@tonic-gate #define GLD_OPT_NO_IPQ 0x00000001 /* don't use IP shortcut */ 550Sstevel@tonic-gate #define GLD_OPT_NO_FASTPATH 0x00000002 /* don't implement fastpath */ 560Sstevel@tonic-gate #define GLD_OPT_NO_ETHRXSNAP 0x00000008 /* don't interp SNAP on ether */ 570Sstevel@tonic-gate 580Sstevel@tonic-gate /* gld per instance options */ 590Sstevel@tonic-gate #define GLDOPT_FAST_RECV 0x40 600Sstevel@tonic-gate #define GLDOPT_CANONICAL_ADDR 0x08 610Sstevel@tonic-gate #define GLDOPT_MDT 0x100 620Sstevel@tonic-gate 630Sstevel@tonic-gate /* 640Sstevel@tonic-gate * This version of GLD allows a "Virtual-LAN-PPA" to be specified in 650Sstevel@tonic-gate * the same manner as Cassini: the virtual PPA number is composed of 660Sstevel@tonic-gate * the VLAN tag number (1-4094), multiplied by 1000(!), plus the real 670Sstevel@tonic-gate * (hardware) PPA. Thus "bge23001" refers to the "device" which 680Sstevel@tonic-gate * transports packets with tag VLAN "23" over the hardware of "bge1". 690Sstevel@tonic-gate * 700Sstevel@tonic-gate * This scheme limits the number of physical devices of a single type to 710Sstevel@tonic-gate * 1000 e.g. bge0 .. bge999 (since bge1000 would instead be interpreted 720Sstevel@tonic-gate * as VLAN1 over bge0). 730Sstevel@tonic-gate */ 740Sstevel@tonic-gate #define GLD_VLAN_SCALE 1000 750Sstevel@tonic-gate #define GLD_MAX_PPA (GLD_VLAN_SCALE-1) 760Sstevel@tonic-gate 770Sstevel@tonic-gate /* 780Sstevel@tonic-gate * Minor numbers: 790Sstevel@tonic-gate * 800Sstevel@tonic-gate * For each device type, GLD creates a single "style 2" node with minor 0. 810Sstevel@tonic-gate * For each instance of that device type, GLD also creates a "style 1" 820Sstevel@tonic-gate * node with minor number one greater than the PPA. Thus, nodes with 830Sstevel@tonic-gate * minor numbers 0..1000 may exist in the /dev* filesystem. 840Sstevel@tonic-gate * 850Sstevel@tonic-gate * So, on open: 860Sstevel@tonic-gate * 870Sstevel@tonic-gate * Minor 0 implies DLPI "style 2": the STREAM is not intrinsically 880Sstevel@tonic-gate * associated with any particular device/PPA. The association is set 890Sstevel@tonic-gate * (and may be changed) dynamically, by DLPI_ATTACH/DETACH messages. 900Sstevel@tonic-gate * 910Sstevel@tonic-gate * Minors 1..1000 are "style 1", where the PPA is entirely defined by 920Sstevel@tonic-gate * the minor; GLD defines the mapping as PPA=minor-1 (minor=PPA+1). 930Sstevel@tonic-gate * Note that the upper bound of 1000 is (now) limited by the VLAN 940Sstevel@tonic-gate * mapping scheme set out above. 950Sstevel@tonic-gate * 960Sstevel@tonic-gate * GLD devices are "self-cloning": each new open will cause a new minor 970Sstevel@tonic-gate * number to be allocated; these are selected from the range 1001..0x3ffff. 980Sstevel@tonic-gate * This minor number is only associated with the open stream and doesn't 990Sstevel@tonic-gate * appear in the /dev* filesystem; manually created nodes with minors in 1000Sstevel@tonic-gate * this range will be rejected by gld_open(). 1010Sstevel@tonic-gate */ 1020Sstevel@tonic-gate #define GLD_USE_STYLE2 0 1030Sstevel@tonic-gate 1040Sstevel@tonic-gate #define GLD_MIN_STYLE1_MINOR 1 1050Sstevel@tonic-gate #define GLD_MAX_STYLE1_MINOR (GLD_MAX_PPA+1) 1060Sstevel@tonic-gate 1070Sstevel@tonic-gate #define GLD_STYLE1_MINOR_TO_PPA(minor) (minor - 1) 1080Sstevel@tonic-gate #define GLD_STYLE1_PPA_TO_MINOR(ppa) (ppa + 1) 1090Sstevel@tonic-gate 1100Sstevel@tonic-gate #define GLD_MIN_CLONE_MINOR (GLD_MAX_STYLE1_MINOR+1) 1110Sstevel@tonic-gate #define GLD_MAX_CLONE_MINOR 0x3ffff 1120Sstevel@tonic-gate 1130Sstevel@tonic-gate /* gldm_GLD_flags */ 1140Sstevel@tonic-gate #define GLD_MAC_READY 0x0001 /* this mac has succeeded gld_register */ 1150Sstevel@tonic-gate #define GLD_INTR_READY 0x0001 /* v0 compat name */ 1160Sstevel@tonic-gate #define GLD_INTR_WAIT 0x0002 /* v1: waiting for interrupt to do scheduling */ 1170Sstevel@tonic-gate #define GLD_LOCK_INITED 0x0004 /* maclock is currently initialized */ 1180Sstevel@tonic-gate #define GLD_UNREGISTERED 0x0008 /* this mac has succeeded gld_unregister */ 1190Sstevel@tonic-gate 1200Sstevel@tonic-gate /* This is the largest macaddr currently supported by GLD */ 1210Sstevel@tonic-gate #define GLD_MAX_ADDRLEN 32 /* Largest mac addr in all media */ 1220Sstevel@tonic-gate 1230Sstevel@tonic-gate #define GLD_MAX_MULTICAST 64 /* default multicast table size */ 1240Sstevel@tonic-gate 1250Sstevel@tonic-gate /* multicast structures */ 1260Sstevel@tonic-gate typedef struct gld_multicast_addr { 1270Sstevel@tonic-gate int gldm_refcnt; /* number of streams referring */ 1280Sstevel@tonic-gate /* to this per-mac entry */ 1290Sstevel@tonic-gate unsigned char gldm_addr[GLD_MAX_ADDRLEN]; 1300Sstevel@tonic-gate } gld_mcast_t; 1310Sstevel@tonic-gate 1320Sstevel@tonic-gate /* gld_flag bits -- GLD PRIVATE */ 1330Sstevel@tonic-gate #define GLD_RAW 0x0001 /* lower stream is in RAW mode */ 1340Sstevel@tonic-gate #define GLD_FAST 0x0002 /* use "fast" path */ 1350Sstevel@tonic-gate #define GLD_PROM_PHYS 0x0004 /* stream is in physical promiscuous mode */ 1360Sstevel@tonic-gate #define GLD_PROM_SAP 0x0008 1370Sstevel@tonic-gate #define GLD_PROM_MULT 0x0010 1380Sstevel@tonic-gate #define GLD_STR_CLOSING 0x0020 /* stream is closing; don't putnext */ 1390Sstevel@tonic-gate 1400Sstevel@tonic-gate /* 1410Sstevel@tonic-gate * gld structure. Used to define the per-stream information required to 1420Sstevel@tonic-gate * implement DLPI. 1430Sstevel@tonic-gate */ 1440Sstevel@tonic-gate typedef struct gld { 1450Sstevel@tonic-gate struct gld *gld_next, *gld_prev; 1460Sstevel@tonic-gate caddr_t gld_dummy1; 1470Sstevel@tonic-gate int32_t gld_state; /* DL_UNATTACHED, DL_UNBOUND, DL_IDLE */ 1480Sstevel@tonic-gate int32_t gld_style; /* open style 1 or style 2 */ 1490Sstevel@tonic-gate int32_t gld_minor; /* cloned minor number */ 1500Sstevel@tonic-gate int32_t gld_type; /* DL_ETHER, DL_TPR, DL_FDDI, etc */ 1510Sstevel@tonic-gate int32_t gld_sap; /* Bound SAP */ 1520Sstevel@tonic-gate int32_t gld_flags; /* flags defined in gldpriv.h */ 1530Sstevel@tonic-gate int32_t gld_multicnt; /* # of stream multicast addresses */ 1540Sstevel@tonic-gate gld_mcast_t **gld_mcast; /* multicast table or NULL */ 1550Sstevel@tonic-gate queue_t *gld_qptr; /* pointer to streams queue */ 1560Sstevel@tonic-gate caddr_t gld_dummy2; 1570Sstevel@tonic-gate caddr_t gld_dummy3; 1580Sstevel@tonic-gate struct gld_mac_info *gld_mac_info; /* if not DL_UNATTACHED */ 1590Sstevel@tonic-gate caddr_t gld_dummy4; 1600Sstevel@tonic-gate struct glddevice *gld_device; /* per-major structure */ 1610Sstevel@tonic-gate 1620Sstevel@tonic-gate volatile boolean_t gld_xwait; /* want an xmit qenable */ 1630Sstevel@tonic-gate volatile boolean_t gld_sched_ran; /* gld_sched examined this Q */ 1640Sstevel@tonic-gate volatile boolean_t gld_in_unbind; /* DL_UNBIND in progress */ 1650Sstevel@tonic-gate volatile uint32_t gld_wput_count; /* number of threads in wput=>start */ 1660Sstevel@tonic-gate volatile boolean_t gld_in_wsrv; /* Q thread currently running in wsrv */ 1670Sstevel@tonic-gate 1680Sstevel@tonic-gate boolean_t gld_ethertype; /* ethertype/LLC stream */ 1690Sstevel@tonic-gate uint32_t gld_notifications; 1700Sstevel@tonic-gate uint32_t gld_upri; /* user priority */ 1710Sstevel@tonic-gate void *gld_vlan; 1720Sstevel@tonic-gate int (*gld_send)(); 1730Sstevel@tonic-gate } gld_t; 1740Sstevel@tonic-gate 1750Sstevel@tonic-gate /* 1760Sstevel@tonic-gate * definitions for the per driver class structure 1770Sstevel@tonic-gate */ 1780Sstevel@tonic-gate typedef struct glddevice { 1790Sstevel@tonic-gate struct glddevice *gld_next, *gld_prev; 1800Sstevel@tonic-gate int gld_ndevice; /* number of mac devices linked */ 1810Sstevel@tonic-gate gld_mac_info_t *gld_mac_next, *gld_mac_prev; /* the various macs */ 1820Sstevel@tonic-gate gld_t *gld_str_next, *gld_str_prev; /* open, unattached, */ 1830Sstevel@tonic-gate /* style 2 streams */ 1840Sstevel@tonic-gate char gld_name[16]; /* name of device */ 1850Sstevel@tonic-gate kmutex_t gld_devlock; /* used to serialize read/write locks */ 1860Sstevel@tonic-gate int gld_nextminor; /* next unused minor number for clone */ 1870Sstevel@tonic-gate int gld_major; /* device's major number */ 1880Sstevel@tonic-gate int gld_multisize; /* # of multicast entries to alloc */ 1890Sstevel@tonic-gate int gld_type; /* for use before attach */ 1900Sstevel@tonic-gate int gld_minsdu; 1910Sstevel@tonic-gate int gld_maxsdu; 1920Sstevel@tonic-gate int gld_addrlen; /* physical address length */ 1930Sstevel@tonic-gate int gld_saplen; /* sap length, neg appends */ 1940Sstevel@tonic-gate unsigned char *gld_broadcast; /* pointer to broadcast address */ 1950Sstevel@tonic-gate int gld_styles; /* provider styles */ 1960Sstevel@tonic-gate } glddev_t; 1970Sstevel@tonic-gate 1980Sstevel@tonic-gate typedef struct pktinfo { 1990Sstevel@tonic-gate uint_t isBroadcast:1; 2000Sstevel@tonic-gate uint_t isMulticast:1; 2010Sstevel@tonic-gate uint_t isLooped:1; 2020Sstevel@tonic-gate uint_t isForMe:1; 2030Sstevel@tonic-gate uint_t isLLC:1; 2040Sstevel@tonic-gate uint_t user_pri:3; 2050Sstevel@tonic-gate uint_t cfi:1; 2060Sstevel@tonic-gate uint_t vid:12; 2070Sstevel@tonic-gate uint_t wasAccepted:1; 2080Sstevel@tonic-gate uint_t nosource:1; 209*2760Sdg199075 uint_t isTagged:1; 2100Sstevel@tonic-gate uint_t macLen; 2110Sstevel@tonic-gate uint_t hdrLen; 2120Sstevel@tonic-gate uint_t pktLen; 2130Sstevel@tonic-gate uchar_t dhost[GLD_MAX_ADDRLEN]; 2140Sstevel@tonic-gate uchar_t shost[GLD_MAX_ADDRLEN]; 2150Sstevel@tonic-gate uint_t ethertype; 2160Sstevel@tonic-gate } pktinfo_t; 2170Sstevel@tonic-gate 2180Sstevel@tonic-gate /* 2190Sstevel@tonic-gate * Flags input to the gld_interpret_*() interpreter routines. 2200Sstevel@tonic-gate */ 2210Sstevel@tonic-gate typedef enum packet_flag { 2220Sstevel@tonic-gate GLD_RXQUICK, 2230Sstevel@tonic-gate GLD_RXLOOP, 2240Sstevel@tonic-gate GLD_RX, 2250Sstevel@tonic-gate GLD_TX 2260Sstevel@tonic-gate } packet_flag_t; 2270Sstevel@tonic-gate 2280Sstevel@tonic-gate /* 2290Sstevel@tonic-gate * Flags input to the gld_interpret_mdt_*() interpreter routines. 2300Sstevel@tonic-gate */ 2310Sstevel@tonic-gate typedef enum mdt_packet_flag { 2320Sstevel@tonic-gate GLD_MDT_TX, 2330Sstevel@tonic-gate GLD_MDT_TXPKT, 2340Sstevel@tonic-gate GLD_MDT_RXLOOP 2350Sstevel@tonic-gate } mdt_packet_flag_t; 2360Sstevel@tonic-gate 2370Sstevel@tonic-gate /* 2380Sstevel@tonic-gate * Describes characteristics of the Media Access Layer. 2390Sstevel@tonic-gate * The mac_type is one of the supported DLPI media types (see <sys/dlpi.h>). 2400Sstevel@tonic-gate * The mtu_size is the size of the largest frame. 2410Sstevel@tonic-gate * The interpreter is the function that "knows" how to interpret the frame. 2420Sstevel@tonic-gate * The interpreter_mdt routine knows how to interpret/format MDT packets. 2430Sstevel@tonic-gate * Other routines create and/or add headers to packets. 2440Sstevel@tonic-gate */ 2450Sstevel@tonic-gate typedef struct { 2460Sstevel@tonic-gate uint_t mac_type; 2470Sstevel@tonic-gate uint_t mtu_size; 2480Sstevel@tonic-gate int hdr_size; 249*2760Sdg199075 int (*interpreter)(gld_mac_info_t *, mblk_t *, pktinfo_t *, 250*2760Sdg199075 packet_flag_t); 2510Sstevel@tonic-gate void (*interpreter_mdt)(gld_mac_info_t *, mblk_t *, 252*2760Sdg199075 struct pdescinfo_s *, pktinfo_t *, mdt_packet_flag_t); 2530Sstevel@tonic-gate mblk_t *(*mkfastpath)(gld_t *, mblk_t *); 2540Sstevel@tonic-gate mblk_t *(*mkunitdata)(gld_t *, mblk_t *); 2550Sstevel@tonic-gate void (*init)(gld_mac_info_t *); 2560Sstevel@tonic-gate void (*uninit)(gld_mac_info_t *); 2570Sstevel@tonic-gate char *mac_string; 2580Sstevel@tonic-gate } gld_interface_t; 2590Sstevel@tonic-gate 2600Sstevel@tonic-gate /* 2610Sstevel@tonic-gate * structure for names stat structure usage as required by "netstat" 2620Sstevel@tonic-gate */ 2630Sstevel@tonic-gate typedef union media_kstats { 2640Sstevel@tonic-gate struct dot3kstat { 2650Sstevel@tonic-gate kstat_named_t first_coll; 2660Sstevel@tonic-gate kstat_named_t multi_coll; 2670Sstevel@tonic-gate kstat_named_t sqe_error; 2680Sstevel@tonic-gate kstat_named_t mac_xmt_error; 2690Sstevel@tonic-gate kstat_named_t frame_too_long; 2700Sstevel@tonic-gate kstat_named_t mac_rcv_error; 2710Sstevel@tonic-gate } dot3; 2720Sstevel@tonic-gate struct dot5kstat { 2730Sstevel@tonic-gate kstat_named_t ace_error; 2740Sstevel@tonic-gate kstat_named_t internal_error; 2750Sstevel@tonic-gate kstat_named_t lost_frame_error; 2760Sstevel@tonic-gate kstat_named_t frame_copied_error; 2770Sstevel@tonic-gate kstat_named_t token_error; 2780Sstevel@tonic-gate kstat_named_t freq_error; 2790Sstevel@tonic-gate } dot5; 2800Sstevel@tonic-gate struct fddikstat { 2810Sstevel@tonic-gate kstat_named_t mac_error; 2820Sstevel@tonic-gate kstat_named_t mac_lost; 2830Sstevel@tonic-gate kstat_named_t mac_token; 2840Sstevel@tonic-gate kstat_named_t mac_tvx_expired; 2850Sstevel@tonic-gate kstat_named_t mac_late; 2860Sstevel@tonic-gate kstat_named_t mac_ring_op; 2870Sstevel@tonic-gate } fddi; 2880Sstevel@tonic-gate } media_kstats_t; 2890Sstevel@tonic-gate 2900Sstevel@tonic-gate struct gldkstats { 2910Sstevel@tonic-gate kstat_named_t glds_pktxmt; 2920Sstevel@tonic-gate kstat_named_t glds_pktrcv; 2930Sstevel@tonic-gate kstat_named_t glds_errxmt; 2940Sstevel@tonic-gate kstat_named_t glds_errrcv; 2950Sstevel@tonic-gate kstat_named_t glds_collisions; 2960Sstevel@tonic-gate kstat_named_t glds_bytexmt; 2970Sstevel@tonic-gate kstat_named_t glds_bytercv; 2980Sstevel@tonic-gate kstat_named_t glds_multixmt; 2990Sstevel@tonic-gate kstat_named_t glds_multircv; /* multicast but not broadcast */ 3000Sstevel@tonic-gate kstat_named_t glds_brdcstxmt; 3010Sstevel@tonic-gate kstat_named_t glds_brdcstrcv; 3020Sstevel@tonic-gate kstat_named_t glds_unknowns; 3030Sstevel@tonic-gate kstat_named_t glds_blocked; /* discard due to upstream flow */ 3040Sstevel@tonic-gate /* control */ 3050Sstevel@tonic-gate kstat_named_t glds_excoll; 3060Sstevel@tonic-gate kstat_named_t glds_defer; 3070Sstevel@tonic-gate kstat_named_t glds_frame; 3080Sstevel@tonic-gate kstat_named_t glds_crc; 3090Sstevel@tonic-gate kstat_named_t glds_overflow; 3100Sstevel@tonic-gate kstat_named_t glds_underflow; 3110Sstevel@tonic-gate kstat_named_t glds_short; 3120Sstevel@tonic-gate kstat_named_t glds_missed; 3130Sstevel@tonic-gate kstat_named_t glds_xmtlatecoll; 3140Sstevel@tonic-gate kstat_named_t glds_nocarrier; 3150Sstevel@tonic-gate kstat_named_t glds_noxmtbuf; 3160Sstevel@tonic-gate kstat_named_t glds_norcvbuf; 3170Sstevel@tonic-gate kstat_named_t glds_xmtbadinterp; 3180Sstevel@tonic-gate kstat_named_t glds_rcvbadinterp; 3190Sstevel@tonic-gate kstat_named_t glds_intr; 3200Sstevel@tonic-gate kstat_named_t glds_xmtretry; 3210Sstevel@tonic-gate kstat_named_t glds_pktxmt64; 3220Sstevel@tonic-gate kstat_named_t glds_pktrcv64; 3230Sstevel@tonic-gate kstat_named_t glds_bytexmt64; 3240Sstevel@tonic-gate kstat_named_t glds_bytercv64; 3250Sstevel@tonic-gate kstat_named_t glds_speed; 3260Sstevel@tonic-gate kstat_named_t glds_duplex; 3270Sstevel@tonic-gate kstat_named_t glds_media; 3280Sstevel@tonic-gate kstat_named_t glds_prom; 3290Sstevel@tonic-gate media_kstats_t glds_media_specific; 3300Sstevel@tonic-gate }; 3310Sstevel@tonic-gate 3320Sstevel@tonic-gate typedef struct gld_mac_pvt gld_mac_pvt_t; 3330Sstevel@tonic-gate 3340Sstevel@tonic-gate typedef struct gld_vlan { 3350Sstevel@tonic-gate struct gld_vlan *gldv_next, *gldv_prev; 3360Sstevel@tonic-gate uint32_t gldv_id; 3370Sstevel@tonic-gate uint32_t gldv_ptag; 3380Sstevel@tonic-gate int gldv_nstreams; 3390Sstevel@tonic-gate gld_mac_info_t *gldv_mac; 3400Sstevel@tonic-gate queue_t *gldv_ipq; 3410Sstevel@tonic-gate queue_t *gldv_ipv6q; 3420Sstevel@tonic-gate struct gld *gldv_str_next; /* list of attached streams */ 3430Sstevel@tonic-gate struct gld *gldv_str_prev; 3440Sstevel@tonic-gate kstat_t *gldv_kstatp; 3450Sstevel@tonic-gate struct gld_stats *gldv_stats; 346*2760Sdg199075 /* The number of streams that are in promiscous mode */ 347*2760Sdg199075 uint_t gldv_nprom; 348*2760Sdg199075 /* The number of streams that are interested in VLAN tagged packets. */ 349*2760Sdg199075 uint_t gldv_nvlan_sap; 3500Sstevel@tonic-gate } gld_vlan_t; 3510Sstevel@tonic-gate 3520Sstevel@tonic-gate #define VLAN_HASHSZ 23 3530Sstevel@tonic-gate 3540Sstevel@tonic-gate /* Per-mac info used by GLD */ 3550Sstevel@tonic-gate struct gld_mac_pvt { 3560Sstevel@tonic-gate gld_interface_t *interfacep; 3570Sstevel@tonic-gate kmutex_t datalock; /* data lock for "data" */ 3580Sstevel@tonic-gate caddr_t data; /* media specific private data */ 3590Sstevel@tonic-gate gld_vlan_t *vlan_hash[VLAN_HASHSZ]; 3600Sstevel@tonic-gate struct gld *last_sched; /* last scheduled stream */ 3610Sstevel@tonic-gate struct glddevice *major_dev; /* per-major device struct */ 3620Sstevel@tonic-gate int nvlan; /* VLANs in use on this mac */ 3630Sstevel@tonic-gate int nprom; /* num streams in promiscuous mode */ 3640Sstevel@tonic-gate int nprom_multi; /* streams in promiscuous multicast */ 3650Sstevel@tonic-gate gld_mcast_t *mcast_table; /* per device multicast table */ 3660Sstevel@tonic-gate unsigned char *curr_macaddr; /* Currently programmed mac address */ 3670Sstevel@tonic-gate kstat_t *kstatp; 3680Sstevel@tonic-gate struct gld_stats *statistics; /* The ones the driver updates */ 3690Sstevel@tonic-gate int rde_enabled; /* RDE (Source Routing) Enabled */ 3700Sstevel@tonic-gate int rde_str_indicator_ste; /* use STE when no SR info */ 3710Sstevel@tonic-gate int rde_timeout; /* route link inactivity timeout */ 3720Sstevel@tonic-gate uint32_t notifications; /* DL_NOTE options supported */ 3730Sstevel@tonic-gate boolean_t started; /* Has the MAC been started? */ 3740Sstevel@tonic-gate }; 3750Sstevel@tonic-gate 3760Sstevel@tonic-gate /* return values from gld_cmds */ 3770Sstevel@tonic-gate #define GLDE_OK (-1) /* internal procedure status is OK */ 3780Sstevel@tonic-gate #define GLDE_RETRY 0x1002 /* want to retry later */ 3790Sstevel@tonic-gate 3800Sstevel@tonic-gate /* caller argument to gld_start */ 3810Sstevel@tonic-gate #define GLD_WPUT 0 3820Sstevel@tonic-gate #define GLD_WSRV 1 3830Sstevel@tonic-gate 3840Sstevel@tonic-gate #define GLD_MAX_802_SAP 0xff 3850Sstevel@tonic-gate 3860Sstevel@tonic-gate /* 3870Sstevel@tonic-gate * definitions for debug tracing 3880Sstevel@tonic-gate */ 3890Sstevel@tonic-gate #define GLDTRACE 0x0001 /* basic procedure level tracing */ 3900Sstevel@tonic-gate #define GLDERRS 0x0002 /* trace errors */ 3910Sstevel@tonic-gate #define GLDRECV 0x0004 /* trace receive path */ 3920Sstevel@tonic-gate #define GLDSEND 0x0008 /* trace send path */ 3930Sstevel@tonic-gate #define GLDPROT 0x0010 /* trace DLPI protocol */ 3940Sstevel@tonic-gate #define GLDNOBR 0x0020 /* do not show broadcast messages */ 3950Sstevel@tonic-gate #define GLDETRACE 0x0040 /* trace "normal case" errors */ 3960Sstevel@tonic-gate #define GLDRDE 0x0080 /* netstat -k dump routing table */ 3970Sstevel@tonic-gate 3980Sstevel@tonic-gate /* 3990Sstevel@tonic-gate * Lock manipulation macros for GLDM_LOCK. Conceptually, the 4000Sstevel@tonic-gate * GLD layer treats the lock as a rw lock; for v0 binary and 4010Sstevel@tonic-gate * semantic compatibility, the underlying implementation still 4020Sstevel@tonic-gate * uses a mutex, whereas for v2 drivers, the more scalable rwlock 4030Sstevel@tonic-gate * is used instead. See notes in gld.h. 4040Sstevel@tonic-gate */ 4050Sstevel@tonic-gate #define GLDM_LOCK_INIT(macinfo) \ 4060Sstevel@tonic-gate rw_init(&(macinfo)->gldm_lock.gldl_rw_lock, NULL, \ 4070Sstevel@tonic-gate RW_DRIVER, (macinfo)->gldm_cookie); \ 4080Sstevel@tonic-gate (macinfo)->gldm_GLD_flags |= GLD_LOCK_INITED 4090Sstevel@tonic-gate 4100Sstevel@tonic-gate #define GLDM_LOCK_INITED(macinfo) \ 4110Sstevel@tonic-gate ((macinfo)->gldm_GLD_flags & GLD_LOCK_INITED) 4120Sstevel@tonic-gate 4130Sstevel@tonic-gate #define GLDM_LOCK_DESTROY(macinfo) \ 4140Sstevel@tonic-gate if ((macinfo)->gldm_GLD_flags & GLD_LOCK_INITED) { \ 4150Sstevel@tonic-gate rw_destroy(&(macinfo)->gldm_lock.gldl_rw_lock); \ 4160Sstevel@tonic-gate (macinfo)->gldm_GLD_flags &= ~GLD_LOCK_INITED; \ 4170Sstevel@tonic-gate } 4180Sstevel@tonic-gate 4190Sstevel@tonic-gate #define GLDM_LOCK(macinfo, rw) \ 4200Sstevel@tonic-gate rw_enter(&(macinfo)->gldm_lock.gldl_rw_lock, (rw)) 4210Sstevel@tonic-gate 4220Sstevel@tonic-gate #define GLDM_UNLOCK(macinfo) \ 4230Sstevel@tonic-gate rw_exit(&(macinfo)->gldm_lock.gldl_rw_lock) 4240Sstevel@tonic-gate 4250Sstevel@tonic-gate #define GLDM_TRYLOCK(macinfo, rw) \ 4260Sstevel@tonic-gate rw_tryenter(&(macinfo)->gldm_lock.gldl_rw_lock, (rw)) 4270Sstevel@tonic-gate 4280Sstevel@tonic-gate /* lock held in read or write mode? */ 4290Sstevel@tonic-gate #define GLDM_LOCK_HELD(macinfo) \ 4300Sstevel@tonic-gate rw_lock_held(&(macinfo)->gldm_lock.gldl_rw_lock) 4310Sstevel@tonic-gate 4320Sstevel@tonic-gate /* lock held in write mode? */ 4330Sstevel@tonic-gate #define GLDM_LOCK_HELD_WRITE(macinfo) \ 4340Sstevel@tonic-gate rw_write_held(&(macinfo)->gldm_lock.gldl_rw_lock) 4350Sstevel@tonic-gate 4360Sstevel@tonic-gate /* 4370Sstevel@tonic-gate * Compare/copy two MAC addresses. 4380Sstevel@tonic-gate * Note that unlike bcmp, we return zero if they are different. 4390Sstevel@tonic-gate */ 4400Sstevel@tonic-gate #define mac_eq(a, b, l) (bcmp((caddr_t)(a), (caddr_t)(b), (l)) == 0) 4410Sstevel@tonic-gate #define mac_copy(a, b, l) (bcopy((caddr_t)(a), (caddr_t)(b), (l))) 4420Sstevel@tonic-gate /* copy a mac address to/from canonical form */ 4430Sstevel@tonic-gate #define cmac_copy(a, b, l, macinfo) { \ 4440Sstevel@tonic-gate if ((macinfo)->gldm_options & GLDOPT_CANONICAL_ADDR) \ 4450Sstevel@tonic-gate gld_bitrevcopy((caddr_t)(a), (caddr_t)(b), (l)); \ 4460Sstevel@tonic-gate else \ 4470Sstevel@tonic-gate mac_copy((a), (b), (l)); \ 4480Sstevel@tonic-gate } 4490Sstevel@tonic-gate 4500Sstevel@tonic-gate /* 4510Sstevel@tonic-gate * Macros to access possibly-unaligned variables 4520Sstevel@tonic-gate */ 4530Sstevel@tonic-gate 4540Sstevel@tonic-gate #if (_ALIGNMENT_REQUIRED == 0) 4550Sstevel@tonic-gate 4560Sstevel@tonic-gate #define REF_HOST_USHORT(lvalue) (lvalue) 4570Sstevel@tonic-gate #define REF_NET_USHORT(lvalue) (ntohs(lvalue)) 4580Sstevel@tonic-gate #define SET_NET_USHORT(lvalue, val) ((lvalue) = htons(val)) 4590Sstevel@tonic-gate 4600Sstevel@tonic-gate #else /* ALIGNMENT_REQUIRED */ 4610Sstevel@tonic-gate 4620Sstevel@tonic-gate #define REF_NET_USHORT(lvalue) \ 4630Sstevel@tonic-gate ((ushort_t)((((uchar_t *)(&(lvalue)))[0]<<8) | \ 4640Sstevel@tonic-gate ((uchar_t *)(&(lvalue)))[1])) 4650Sstevel@tonic-gate 4660Sstevel@tonic-gate #define SET_NET_USHORT(lvalue, val) { \ 4670Sstevel@tonic-gate ((uchar_t *)(&(lvalue)))[0] = (uchar_t)((val)>>8); \ 4680Sstevel@tonic-gate ((uchar_t *)(&(lvalue)))[1] = (uchar_t)(val); \ 4690Sstevel@tonic-gate } 4700Sstevel@tonic-gate 4710Sstevel@tonic-gate #if defined(_LITTLE_ENDIAN) 4720Sstevel@tonic-gate 4730Sstevel@tonic-gate #define REF_HOST_USHORT(lvalue) \ 4740Sstevel@tonic-gate ((ushort_t)((((uchar_t *)(&(lvalue)))[1]<<8) | \ 4750Sstevel@tonic-gate ((uchar_t *)(&(lvalue)))[0])) 4760Sstevel@tonic-gate 4770Sstevel@tonic-gate #elif defined(_BIG_ENDIAN) 4780Sstevel@tonic-gate 4790Sstevel@tonic-gate #define REF_HOST_USHORT(lvalue) \ 4800Sstevel@tonic-gate ((ushort_t)((((uchar_t *)(&(lvalue)))[0]<<8) | \ 4810Sstevel@tonic-gate ((uchar_t *)(&(lvalue)))[1])) 4820Sstevel@tonic-gate 4830Sstevel@tonic-gate #else /* unknown endian */ 4840Sstevel@tonic-gate #error "what endian is this machine?" 4850Sstevel@tonic-gate #endif /* endian */ 4860Sstevel@tonic-gate 4870Sstevel@tonic-gate #endif /* ALIGNMENT_REQUIRED */ 4880Sstevel@tonic-gate 4890Sstevel@tonic-gate /* ================================================================ */ 4900Sstevel@tonic-gate /* Route Determination Entity definitions (IEEE 802.2 1994 edition) */ 4910Sstevel@tonic-gate /* ================================================================ */ 4920Sstevel@tonic-gate 4930Sstevel@tonic-gate struct rde_pdu { 4940Sstevel@tonic-gate uchar_t rde_ver; 4950Sstevel@tonic-gate uchar_t rde_ptype; 4960Sstevel@tonic-gate uchar_t rde_target_mac[6]; 4970Sstevel@tonic-gate uchar_t rde_orig_mac[6]; 4980Sstevel@tonic-gate uchar_t rde_target_sap; 4990Sstevel@tonic-gate uchar_t rde_orig_sap; 5000Sstevel@tonic-gate }; 5010Sstevel@tonic-gate 5020Sstevel@tonic-gate #define LSAP_RDE 0xa6 /* IEEE 802.2 section 3.3.1.2 */ 5030Sstevel@tonic-gate #define RDE_RQC 0x01 /* Route Query Command */ 5040Sstevel@tonic-gate #define RDE_RQR 0x02 /* Route Query Response */ 5050Sstevel@tonic-gate #define RDE_RS 0x03 /* Route Selected */ 5060Sstevel@tonic-gate 5070Sstevel@tonic-gate /* ============================================================= */ 5080Sstevel@tonic-gate /* Source Routing fields and definitions (IEEE 802.2 and 802.1D) */ 5090Sstevel@tonic-gate /* ============================================================= */ 5100Sstevel@tonic-gate 5110Sstevel@tonic-gate #define MAX_RDFLDS 14 /* changed to 14 from 8 as per IEEE */ 5120Sstevel@tonic-gate 5130Sstevel@tonic-gate /* 5140Sstevel@tonic-gate * Source Routing Route Information field. 5150Sstevel@tonic-gate */ 5160Sstevel@tonic-gate struct gld_ri { 5170Sstevel@tonic-gate #if defined(_BIT_FIELDS_LTOH) 5180Sstevel@tonic-gate uchar_t len:5; /* length */ 5190Sstevel@tonic-gate uchar_t rt:3; /* routing type */ 5200Sstevel@tonic-gate uchar_t res:4; /* reserved */ 5210Sstevel@tonic-gate uchar_t mtu:3; /* largest frame */ 5220Sstevel@tonic-gate uchar_t dir:1; /* direction bit */ 5230Sstevel@tonic-gate struct tr_rd { /* route designator fields */ 5240Sstevel@tonic-gate ushort_t bridge:4; /* Note: assumes network order... */ 5250Sstevel@tonic-gate ushort_t ring:12; /* ...(Big Endian) -- needs ntohs() */ 5260Sstevel@tonic-gate } rd[MAX_RDFLDS]; 5270Sstevel@tonic-gate #elif defined(_BIT_FIELDS_HTOL) 5280Sstevel@tonic-gate uchar_t rt:3; /* routing type */ 5290Sstevel@tonic-gate uchar_t len:5; /* length */ 5300Sstevel@tonic-gate uchar_t dir:1; /* direction bit */ 5310Sstevel@tonic-gate uchar_t mtu:3; /* largest frame */ 5320Sstevel@tonic-gate uchar_t res:4; /* reserved */ 5330Sstevel@tonic-gate struct tr_rd { /* route designator fields */ 5340Sstevel@tonic-gate ushort_t ring:12; 5350Sstevel@tonic-gate ushort_t bridge:4; 5360Sstevel@tonic-gate } rd[MAX_RDFLDS]; 5370Sstevel@tonic-gate #else 5380Sstevel@tonic-gate #error "which way do bit fields get allocated?" 5390Sstevel@tonic-gate #endif 5400Sstevel@tonic-gate }; 5410Sstevel@tonic-gate 5420Sstevel@tonic-gate #define RT_SRF 0x0 /* 0xx: specifically routed frame */ 5430Sstevel@tonic-gate #define RT_ARE 0x4 /* 10x: all routes explorer frame */ 5440Sstevel@tonic-gate #define RT_STE 0x6 /* 11x: spanning tree explorer frame */ 5450Sstevel@tonic-gate 5460Sstevel@tonic-gate #define RT_MTU_MAX 0x7 /* Max MTU field (base only) */ 5470Sstevel@tonic-gate 5480Sstevel@tonic-gate /* 5490Sstevel@tonic-gate * Source route table info 5500Sstevel@tonic-gate */ 5510Sstevel@tonic-gate struct srtab { 5520Sstevel@tonic-gate struct srtab *sr_next; /* next in linked list */ 5530Sstevel@tonic-gate uchar_t sr_mac[6]; /* MAC address */ 5540Sstevel@tonic-gate struct gld_ri sr_ri; /* routing information */ 5550Sstevel@tonic-gate clock_t sr_timer; 5560Sstevel@tonic-gate }; 5570Sstevel@tonic-gate 5580Sstevel@tonic-gate #define SR_HASH_SIZE 256 /* Number of bins */ 5590Sstevel@tonic-gate 5600Sstevel@tonic-gate /* ================================================================= */ 5610Sstevel@tonic-gate /* Media dependent defines for media dependent routines in gldutil.c */ 5620Sstevel@tonic-gate /* ================================================================= */ 5630Sstevel@tonic-gate 5640Sstevel@tonic-gate /* 5650Sstevel@tonic-gate * Some "semi-generic" defines used by ether, token, and fddi, 5660Sstevel@tonic-gate * and probably anything else with addrlen == 6 && saplen == -2. 5670Sstevel@tonic-gate */ 5680Sstevel@tonic-gate 5690Sstevel@tonic-gate struct gld_dlsap { 5700Sstevel@tonic-gate unsigned char glda_addr[ETHERADDRL]; 5710Sstevel@tonic-gate unsigned short glda_sap; 5720Sstevel@tonic-gate }; 5730Sstevel@tonic-gate 5740Sstevel@tonic-gate #define DLSAP(p, offset) ((struct gld_dlsap *)((caddr_t)(p)+offset)) 5750Sstevel@tonic-gate 5760Sstevel@tonic-gate typedef uchar_t mac_addr_t[ETHERADDRL]; 5770Sstevel@tonic-gate 5780Sstevel@tonic-gate struct llc_snap_hdr { 5790Sstevel@tonic-gate uchar_t d_lsap; /* destination service access point */ 5800Sstevel@tonic-gate uchar_t s_lsap; /* source link service access point */ 5810Sstevel@tonic-gate uchar_t control; /* short control field */ 5820Sstevel@tonic-gate uchar_t org[3]; /* Ethernet style organization field */ 5830Sstevel@tonic-gate ushort_t type; /* Ethernet style type field */ 5840Sstevel@tonic-gate }; 5850Sstevel@tonic-gate 5860Sstevel@tonic-gate #define LLC_HDR1_LEN 3 /* Length of the LLC1 header */ 5870Sstevel@tonic-gate #define LLC_SNAP_HDR_LEN 8 /* Full length of SNAP header */ 5880Sstevel@tonic-gate #define LSAP_SNAP 0xaa /* SAP for SubNet Access Protocol */ 5890Sstevel@tonic-gate #define CNTL_LLC_UI 0x03 /* un-numbered information packet */ 5900Sstevel@tonic-gate 5910Sstevel@tonic-gate /* ======================== */ 5920Sstevel@tonic-gate /* FDDI related definitions */ 5930Sstevel@tonic-gate /* ======================== */ 5940Sstevel@tonic-gate 5950Sstevel@tonic-gate struct fddi_mac_frm { 5960Sstevel@tonic-gate uchar_t fddi_fc; 5970Sstevel@tonic-gate mac_addr_t fddi_dhost; 5980Sstevel@tonic-gate mac_addr_t fddi_shost; 5990Sstevel@tonic-gate }; 6000Sstevel@tonic-gate 6010Sstevel@tonic-gate /* ============================== */ 6020Sstevel@tonic-gate /* Token Ring related definitions */ 6030Sstevel@tonic-gate /* ============================== */ 6040Sstevel@tonic-gate 6050Sstevel@tonic-gate struct tr_mac_frm_nori { 6060Sstevel@tonic-gate uchar_t tr_ac; 6070Sstevel@tonic-gate uchar_t tr_fc; 6080Sstevel@tonic-gate mac_addr_t tr_dhost; 6090Sstevel@tonic-gate mac_addr_t tr_shost; 6100Sstevel@tonic-gate }; 6110Sstevel@tonic-gate 6120Sstevel@tonic-gate struct tr_mac_frm { 6130Sstevel@tonic-gate uchar_t tr_ac; 6140Sstevel@tonic-gate uchar_t tr_fc; 6150Sstevel@tonic-gate mac_addr_t tr_dhost; 6160Sstevel@tonic-gate mac_addr_t tr_shost; 6170Sstevel@tonic-gate struct gld_ri tr_ri; /* Routing Information Field */ 6180Sstevel@tonic-gate }; 6190Sstevel@tonic-gate 620*2760Sdg199075 /* 621*2760Sdg199075 * Note that the pad field is used to save the value of tci. 622*2760Sdg199075 */ 623*2760Sdg199075 #define GLD_SAVE_MBLK_VTAG(mp, vtag) (DB_TCI(mp) = GLD_VTAG_TCI(vtag)) 624*2760Sdg199075 #define GLD_CLEAR_MBLK_VTAG(mp) GLD_SAVE_MBLK_VTAG(mp, 0) 625*2760Sdg199075 #define GLD_GET_MBLK_VTAG(mp) GLD_TCI2VTAG(DB_TCI(mp)) 626*2760Sdg199075 627*2760Sdg199075 int gld_interpret_ether(gld_mac_info_t *, mblk_t *, pktinfo_t *, packet_flag_t); 628*2760Sdg199075 int gld_interpret_fddi(gld_mac_info_t *, mblk_t *, pktinfo_t *, packet_flag_t); 629*2760Sdg199075 int gld_interpret_tr(gld_mac_info_t *, mblk_t *, pktinfo_t *, packet_flag_t); 630*2760Sdg199075 int gld_interpret_ib(gld_mac_info_t *, mblk_t *, pktinfo_t *, packet_flag_t); 631*2760Sdg199075 void gld_interpret_mdt_ib(gld_mac_info_t *, mblk_t *, pdescinfo_t *, 632*2760Sdg199075 pktinfo_t *, mdt_packet_flag_t); 633*2760Sdg199075 634*2760Sdg199075 mblk_t *gld_fastpath_ether(gld_t *, mblk_t *); 635*2760Sdg199075 mblk_t *gld_fastpath_fddi(gld_t *, mblk_t *); 636*2760Sdg199075 mblk_t *gld_fastpath_tr(gld_t *, mblk_t *); 637*2760Sdg199075 mblk_t *gld_fastpath_ib(gld_t *, mblk_t *); 638*2760Sdg199075 639*2760Sdg199075 mblk_t *gld_insert_vtag_ether(mblk_t *, uint32_t); 640*2760Sdg199075 641*2760Sdg199075 mblk_t *gld_unitdata_ether(gld_t *, mblk_t *); 642*2760Sdg199075 mblk_t *gld_unitdata_fddi(gld_t *, mblk_t *); 643*2760Sdg199075 mblk_t *gld_unitdata_tr(gld_t *, mblk_t *); 644*2760Sdg199075 mblk_t *gld_unitdata_ib(gld_t *, mblk_t *); 645*2760Sdg199075 646*2760Sdg199075 void gld_init_ether(gld_mac_info_t *); 647*2760Sdg199075 void gld_init_fddi(gld_mac_info_t *); 648*2760Sdg199075 void gld_init_tr(gld_mac_info_t *); 649*2760Sdg199075 void gld_init_ib(gld_mac_info_t *); 650*2760Sdg199075 651*2760Sdg199075 void gld_uninit_ether(gld_mac_info_t *); 652*2760Sdg199075 void gld_uninit_fddi(gld_mac_info_t *); 653*2760Sdg199075 void gld_uninit_tr(gld_mac_info_t *); 654*2760Sdg199075 void gld_uninit_ib(gld_mac_info_t *); 655*2760Sdg199075 6560Sstevel@tonic-gate #ifdef __cplusplus 6570Sstevel@tonic-gate } 6580Sstevel@tonic-gate #endif 6590Sstevel@tonic-gate 6600Sstevel@tonic-gate #endif /* _SYS_GLDPRIV_H */ 661