xref: /onnv-gate/usr/src/uts/common/sys/gldpriv.h (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate /*
28*0Sstevel@tonic-gate  * gldpriv.h - Private interfaces/structures needed by gld.c
29*0Sstevel@tonic-gate  *
30*0Sstevel@tonic-gate  * The definitions in this file are private to GLD and may change at any time.
31*0Sstevel@tonic-gate  * They must not be used by any driver.
32*0Sstevel@tonic-gate  */
33*0Sstevel@tonic-gate 
34*0Sstevel@tonic-gate #ifndef	_SYS_GLDPRIV_H
35*0Sstevel@tonic-gate #define	_SYS_GLDPRIV_H
36*0Sstevel@tonic-gate 
37*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
38*0Sstevel@tonic-gate 
39*0Sstevel@tonic-gate #ifdef	__cplusplus
40*0Sstevel@tonic-gate extern "C" {
41*0Sstevel@tonic-gate #endif
42*0Sstevel@tonic-gate 
43*0Sstevel@tonic-gate #ifdef	DEBUG
44*0Sstevel@tonic-gate #define	GLD_DEBUG 1
45*0Sstevel@tonic-gate #endif
46*0Sstevel@tonic-gate 
47*0Sstevel@tonic-gate /*
48*0Sstevel@tonic-gate  * The version number should not be changed.
49*0Sstevel@tonic-gate  */
50*0Sstevel@tonic-gate #define	GLD_VERSION_200		0x200			/* version 2.0 */
51*0Sstevel@tonic-gate #define	GLD_VERSION		GLD_VERSION_200		/* current version */
52*0Sstevel@tonic-gate #define	GLD_VERSION_STRING	"v2"			/* in modinfo string */
53*0Sstevel@tonic-gate 
54*0Sstevel@tonic-gate /* gld_global_options bits */
55*0Sstevel@tonic-gate #define	GLD_OPT_NO_IPQ		0x00000001	/* don't use IP shortcut */
56*0Sstevel@tonic-gate #define	GLD_OPT_NO_FASTPATH	0x00000002	/* don't implement fastpath */
57*0Sstevel@tonic-gate #define	GLD_OPT_NO_ETHRXSNAP	0x00000008	/* don't interp SNAP on ether */
58*0Sstevel@tonic-gate 
59*0Sstevel@tonic-gate /* gld per instance options */
60*0Sstevel@tonic-gate #define	GLDOPT_FAST_RECV	0x40
61*0Sstevel@tonic-gate #define	GLDOPT_CANONICAL_ADDR	0x08
62*0Sstevel@tonic-gate #define	GLDOPT_MDT		0x100
63*0Sstevel@tonic-gate 
64*0Sstevel@tonic-gate /*
65*0Sstevel@tonic-gate  * This version of GLD allows a "Virtual-LAN-PPA" to be specified in
66*0Sstevel@tonic-gate  * the same manner as Cassini: the virtual PPA number is composed of
67*0Sstevel@tonic-gate  * the VLAN tag number (1-4094), multiplied by 1000(!), plus the real
68*0Sstevel@tonic-gate  * (hardware) PPA.  Thus "bge23001" refers to the "device" which
69*0Sstevel@tonic-gate  * transports packets with tag VLAN "23" over the hardware of "bge1".
70*0Sstevel@tonic-gate  *
71*0Sstevel@tonic-gate  * This scheme limits the number of physical devices of a single type to
72*0Sstevel@tonic-gate  * 1000 e.g. bge0 .. bge999 (since bge1000 would instead be interpreted
73*0Sstevel@tonic-gate  * as VLAN1 over bge0).
74*0Sstevel@tonic-gate  */
75*0Sstevel@tonic-gate #define	GLD_VLAN_SCALE		1000
76*0Sstevel@tonic-gate #define	GLD_MAX_PPA		(GLD_VLAN_SCALE-1)
77*0Sstevel@tonic-gate 
78*0Sstevel@tonic-gate /*
79*0Sstevel@tonic-gate  * Minor numbers:
80*0Sstevel@tonic-gate  *
81*0Sstevel@tonic-gate  * For each device type, GLD creates a single "style 2" node with minor 0.
82*0Sstevel@tonic-gate  * For each instance of that device type, GLD also creates a "style 1"
83*0Sstevel@tonic-gate  * node with minor number one greater than the PPA.  Thus, nodes with
84*0Sstevel@tonic-gate  * minor numbers 0..1000 may exist in the /dev* filesystem.
85*0Sstevel@tonic-gate  *
86*0Sstevel@tonic-gate  * So, on open:
87*0Sstevel@tonic-gate  *
88*0Sstevel@tonic-gate  * Minor 0 implies DLPI "style 2": the STREAM is not intrinsically
89*0Sstevel@tonic-gate  * associated with any particular device/PPA.  The association is set
90*0Sstevel@tonic-gate  * (and may be changed) dynamically, by DLPI_ATTACH/DETACH messages.
91*0Sstevel@tonic-gate  *
92*0Sstevel@tonic-gate  * Minors 1..1000 are "style 1", where the PPA is entirely defined by
93*0Sstevel@tonic-gate  * the minor; GLD defines the mapping as PPA=minor-1 (minor=PPA+1).
94*0Sstevel@tonic-gate  * Note that the upper bound of 1000 is (now) limited by the VLAN
95*0Sstevel@tonic-gate  * mapping scheme set out above.
96*0Sstevel@tonic-gate  *
97*0Sstevel@tonic-gate  * GLD devices are "self-cloning": each new open will cause a new minor
98*0Sstevel@tonic-gate  * number to be allocated; these are selected from the range 1001..0x3ffff.
99*0Sstevel@tonic-gate  * This minor number is only associated with the open stream and doesn't
100*0Sstevel@tonic-gate  * appear in the /dev* filesystem; manually created nodes with minors in
101*0Sstevel@tonic-gate  * this range will be rejected by gld_open().
102*0Sstevel@tonic-gate  */
103*0Sstevel@tonic-gate #define	GLD_USE_STYLE2		0
104*0Sstevel@tonic-gate 
105*0Sstevel@tonic-gate #define	GLD_MIN_STYLE1_MINOR	1
106*0Sstevel@tonic-gate #define	GLD_MAX_STYLE1_MINOR	(GLD_MAX_PPA+1)
107*0Sstevel@tonic-gate 
108*0Sstevel@tonic-gate #define	GLD_STYLE1_MINOR_TO_PPA(minor)	(minor - 1)
109*0Sstevel@tonic-gate #define	GLD_STYLE1_PPA_TO_MINOR(ppa)	(ppa + 1)
110*0Sstevel@tonic-gate 
111*0Sstevel@tonic-gate #define	GLD_MIN_CLONE_MINOR	(GLD_MAX_STYLE1_MINOR+1)
112*0Sstevel@tonic-gate #define	GLD_MAX_CLONE_MINOR	0x3ffff
113*0Sstevel@tonic-gate 
114*0Sstevel@tonic-gate /* gldm_GLD_flags */
115*0Sstevel@tonic-gate #define	GLD_MAC_READY 0x0001	/* this mac has succeeded gld_register */
116*0Sstevel@tonic-gate #define	GLD_INTR_READY 0x0001	/* v0 compat name */
117*0Sstevel@tonic-gate #define	GLD_INTR_WAIT 0x0002	/* v1: waiting for interrupt to do scheduling */
118*0Sstevel@tonic-gate #define	GLD_LOCK_INITED 0x0004	/* maclock is currently initialized */
119*0Sstevel@tonic-gate #define	GLD_UNREGISTERED 0x0008	/* this mac has succeeded gld_unregister */
120*0Sstevel@tonic-gate 
121*0Sstevel@tonic-gate /* This is the largest macaddr currently supported by GLD */
122*0Sstevel@tonic-gate #define	GLD_MAX_ADDRLEN		32	/* Largest mac addr in all media  */
123*0Sstevel@tonic-gate 
124*0Sstevel@tonic-gate #define	GLD_MAX_MULTICAST	64	/* default multicast table size */
125*0Sstevel@tonic-gate 
126*0Sstevel@tonic-gate /* multicast structures */
127*0Sstevel@tonic-gate typedef struct gld_multicast_addr {
128*0Sstevel@tonic-gate 	int		gldm_refcnt;	/* number of streams referring */
129*0Sstevel@tonic-gate 					/* to this per-mac entry */
130*0Sstevel@tonic-gate 	unsigned char	gldm_addr[GLD_MAX_ADDRLEN];
131*0Sstevel@tonic-gate } gld_mcast_t;
132*0Sstevel@tonic-gate 
133*0Sstevel@tonic-gate /* gld_flag bits -- GLD PRIVATE */
134*0Sstevel@tonic-gate #define	GLD_RAW		0x0001	/* lower stream is in RAW mode */
135*0Sstevel@tonic-gate #define	GLD_FAST	0x0002	/* use "fast" path */
136*0Sstevel@tonic-gate #define	GLD_PROM_PHYS	0x0004	/* stream is in physical promiscuous mode */
137*0Sstevel@tonic-gate #define	GLD_PROM_SAP	0x0008
138*0Sstevel@tonic-gate #define	GLD_PROM_MULT	0x0010
139*0Sstevel@tonic-gate #define	GLD_STR_CLOSING	0x0020	/* stream is closing; don't putnext */
140*0Sstevel@tonic-gate 
141*0Sstevel@tonic-gate /*
142*0Sstevel@tonic-gate  * gld structure.  Used to define the per-stream information required to
143*0Sstevel@tonic-gate  * implement DLPI.
144*0Sstevel@tonic-gate  */
145*0Sstevel@tonic-gate typedef struct gld {
146*0Sstevel@tonic-gate 	struct gld	*gld_next, *gld_prev;
147*0Sstevel@tonic-gate 	caddr_t		gld_dummy1;
148*0Sstevel@tonic-gate 	int32_t		gld_state;	/* DL_UNATTACHED, DL_UNBOUND, DL_IDLE */
149*0Sstevel@tonic-gate 	int32_t		gld_style;	/* open style 1 or style 2 */
150*0Sstevel@tonic-gate 	int32_t		gld_minor;	/* cloned minor number */
151*0Sstevel@tonic-gate 	int32_t		gld_type;	/* DL_ETHER, DL_TPR, DL_FDDI, etc */
152*0Sstevel@tonic-gate 	int32_t		gld_sap;	/* Bound SAP */
153*0Sstevel@tonic-gate 	int32_t		gld_flags;	/* flags defined in gldpriv.h */
154*0Sstevel@tonic-gate 	int32_t		gld_multicnt;	/* # of stream multicast addresses */
155*0Sstevel@tonic-gate 	gld_mcast_t	**gld_mcast;	/* multicast table or NULL */
156*0Sstevel@tonic-gate 	queue_t		*gld_qptr;	/* pointer to streams queue */
157*0Sstevel@tonic-gate 	caddr_t		gld_dummy2;
158*0Sstevel@tonic-gate 	caddr_t		gld_dummy3;
159*0Sstevel@tonic-gate 	struct gld_mac_info *gld_mac_info;	/* if not DL_UNATTACHED */
160*0Sstevel@tonic-gate 	caddr_t		gld_dummy4;
161*0Sstevel@tonic-gate 	struct glddevice *gld_device;	/* per-major structure */
162*0Sstevel@tonic-gate 
163*0Sstevel@tonic-gate 	volatile boolean_t gld_xwait;		/* want an xmit qenable */
164*0Sstevel@tonic-gate 	volatile boolean_t gld_sched_ran;	/* gld_sched examined this Q */
165*0Sstevel@tonic-gate 	volatile boolean_t gld_in_unbind;	/* DL_UNBIND in progress */
166*0Sstevel@tonic-gate 	volatile uint32_t gld_wput_count; /* number of threads in wput=>start */
167*0Sstevel@tonic-gate 	volatile boolean_t gld_in_wsrv;	/* Q thread currently running in wsrv */
168*0Sstevel@tonic-gate 
169*0Sstevel@tonic-gate 	boolean_t	gld_ethertype;	/* ethertype/LLC stream */
170*0Sstevel@tonic-gate 	uint32_t	gld_notifications;
171*0Sstevel@tonic-gate 	uint32_t	gld_upri;	/* user priority */
172*0Sstevel@tonic-gate 	void		*gld_vlan;
173*0Sstevel@tonic-gate 	int (*gld_send)();
174*0Sstevel@tonic-gate } gld_t;
175*0Sstevel@tonic-gate 
176*0Sstevel@tonic-gate /*
177*0Sstevel@tonic-gate  * definitions for the per driver class structure
178*0Sstevel@tonic-gate  */
179*0Sstevel@tonic-gate typedef struct glddevice {
180*0Sstevel@tonic-gate 	struct glddevice *gld_next, *gld_prev;
181*0Sstevel@tonic-gate 	int		gld_ndevice;	/* number of mac devices linked */
182*0Sstevel@tonic-gate 	gld_mac_info_t	*gld_mac_next, *gld_mac_prev;	/* the various macs */
183*0Sstevel@tonic-gate 	gld_t		*gld_str_next, *gld_str_prev;	/* open, unattached, */
184*0Sstevel@tonic-gate 							/* style 2 streams */
185*0Sstevel@tonic-gate 	char		gld_name[16];	/* name of device */
186*0Sstevel@tonic-gate 	kmutex_t	gld_devlock;	/* used to serialize read/write locks */
187*0Sstevel@tonic-gate 	int		gld_nextminor;	/* next unused minor number for clone */
188*0Sstevel@tonic-gate 	int		gld_major;	/* device's major number */
189*0Sstevel@tonic-gate 	int		gld_multisize;	/* # of multicast entries to alloc */
190*0Sstevel@tonic-gate 	int		gld_type;	/* for use before attach */
191*0Sstevel@tonic-gate 	int		gld_minsdu;
192*0Sstevel@tonic-gate 	int		gld_maxsdu;
193*0Sstevel@tonic-gate 	int		gld_addrlen;	/* physical address length */
194*0Sstevel@tonic-gate 	int		gld_saplen;	/* sap length, neg appends */
195*0Sstevel@tonic-gate 	unsigned char	*gld_broadcast;	/* pointer to broadcast address */
196*0Sstevel@tonic-gate 	int		gld_styles;	/* provider styles */
197*0Sstevel@tonic-gate } glddev_t;
198*0Sstevel@tonic-gate 
199*0Sstevel@tonic-gate typedef struct pktinfo {
200*0Sstevel@tonic-gate 	uint_t		isBroadcast:1;
201*0Sstevel@tonic-gate 	uint_t		isMulticast:1;
202*0Sstevel@tonic-gate 	uint_t		isLooped:1;
203*0Sstevel@tonic-gate 	uint_t		isForMe:1;
204*0Sstevel@tonic-gate 	uint_t		isLLC:1;
205*0Sstevel@tonic-gate 	uint_t		user_pri:3;
206*0Sstevel@tonic-gate 	uint_t		cfi:1;
207*0Sstevel@tonic-gate 	uint_t		vid:12;
208*0Sstevel@tonic-gate 	uint_t		wasAccepted:1;
209*0Sstevel@tonic-gate 	uint_t		nosource:1;
210*0Sstevel@tonic-gate 	uint_t		macLen;
211*0Sstevel@tonic-gate 	uint_t		hdrLen;
212*0Sstevel@tonic-gate 	uint_t		pktLen;
213*0Sstevel@tonic-gate 	uchar_t		dhost[GLD_MAX_ADDRLEN];
214*0Sstevel@tonic-gate 	uchar_t		shost[GLD_MAX_ADDRLEN];
215*0Sstevel@tonic-gate 	uint_t		ethertype;
216*0Sstevel@tonic-gate } pktinfo_t;
217*0Sstevel@tonic-gate 
218*0Sstevel@tonic-gate /*
219*0Sstevel@tonic-gate  * Flags input to the gld_interpret_*() interpreter routines.
220*0Sstevel@tonic-gate  */
221*0Sstevel@tonic-gate typedef enum packet_flag {
222*0Sstevel@tonic-gate 	GLD_RXQUICK,
223*0Sstevel@tonic-gate 	GLD_RXLOOP,
224*0Sstevel@tonic-gate 	GLD_RX,
225*0Sstevel@tonic-gate 	GLD_TX
226*0Sstevel@tonic-gate } packet_flag_t;
227*0Sstevel@tonic-gate 
228*0Sstevel@tonic-gate /*
229*0Sstevel@tonic-gate  * Flags input to the gld_interpret_mdt_*() interpreter routines.
230*0Sstevel@tonic-gate  */
231*0Sstevel@tonic-gate typedef enum mdt_packet_flag {
232*0Sstevel@tonic-gate 	GLD_MDT_TX,
233*0Sstevel@tonic-gate 	GLD_MDT_TXPKT,
234*0Sstevel@tonic-gate 	GLD_MDT_RXLOOP
235*0Sstevel@tonic-gate } mdt_packet_flag_t;
236*0Sstevel@tonic-gate 
237*0Sstevel@tonic-gate /*
238*0Sstevel@tonic-gate  * Describes characteristics of the Media Access Layer.
239*0Sstevel@tonic-gate  * The mac_type is one of the supported DLPI media types (see <sys/dlpi.h>).
240*0Sstevel@tonic-gate  * The mtu_size is the size of the largest frame.
241*0Sstevel@tonic-gate  * The interpreter is the function that "knows" how to interpret the frame.
242*0Sstevel@tonic-gate  * The interpreter_mdt routine knows how to interpret/format MDT packets.
243*0Sstevel@tonic-gate  * Other routines create and/or add headers to packets.
244*0Sstevel@tonic-gate  */
245*0Sstevel@tonic-gate typedef struct {
246*0Sstevel@tonic-gate 	uint_t	mac_type;
247*0Sstevel@tonic-gate 	uint_t	mtu_size;
248*0Sstevel@tonic-gate 	int	hdr_size;
249*0Sstevel@tonic-gate 	int	(*interpreter)(gld_mac_info_t *, mblk_t *, pktinfo_t *, int);
250*0Sstevel@tonic-gate 	void	(*interpreter_mdt)(gld_mac_info_t *, mblk_t *,
251*0Sstevel@tonic-gate 		    struct pdescinfo_s *, pktinfo_t *, int);
252*0Sstevel@tonic-gate 	mblk_t	*(*mkfastpath)(gld_t *, mblk_t *);
253*0Sstevel@tonic-gate 	mblk_t	*(*mkunitdata)(gld_t *, mblk_t *);
254*0Sstevel@tonic-gate 	void	(*init)(gld_mac_info_t *);
255*0Sstevel@tonic-gate 	void	(*uninit)(gld_mac_info_t *);
256*0Sstevel@tonic-gate 	char	*mac_string;
257*0Sstevel@tonic-gate } gld_interface_t;
258*0Sstevel@tonic-gate 
259*0Sstevel@tonic-gate /*
260*0Sstevel@tonic-gate  * structure for names stat structure usage as required by "netstat"
261*0Sstevel@tonic-gate  */
262*0Sstevel@tonic-gate typedef union media_kstats {
263*0Sstevel@tonic-gate 	struct dot3kstat {
264*0Sstevel@tonic-gate 		kstat_named_t	first_coll;
265*0Sstevel@tonic-gate 		kstat_named_t	multi_coll;
266*0Sstevel@tonic-gate 		kstat_named_t	sqe_error;
267*0Sstevel@tonic-gate 		kstat_named_t	mac_xmt_error;
268*0Sstevel@tonic-gate 		kstat_named_t	frame_too_long;
269*0Sstevel@tonic-gate 		kstat_named_t	mac_rcv_error;
270*0Sstevel@tonic-gate 	} dot3;
271*0Sstevel@tonic-gate 	struct dot5kstat {
272*0Sstevel@tonic-gate 		kstat_named_t	ace_error;
273*0Sstevel@tonic-gate 		kstat_named_t	internal_error;
274*0Sstevel@tonic-gate 		kstat_named_t	lost_frame_error;
275*0Sstevel@tonic-gate 		kstat_named_t	frame_copied_error;
276*0Sstevel@tonic-gate 		kstat_named_t	token_error;
277*0Sstevel@tonic-gate 		kstat_named_t	freq_error;
278*0Sstevel@tonic-gate 	} dot5;
279*0Sstevel@tonic-gate 	struct fddikstat {
280*0Sstevel@tonic-gate 		kstat_named_t	mac_error;
281*0Sstevel@tonic-gate 		kstat_named_t	mac_lost;
282*0Sstevel@tonic-gate 		kstat_named_t	mac_token;
283*0Sstevel@tonic-gate 		kstat_named_t	mac_tvx_expired;
284*0Sstevel@tonic-gate 		kstat_named_t	mac_late;
285*0Sstevel@tonic-gate 		kstat_named_t	mac_ring_op;
286*0Sstevel@tonic-gate 	} fddi;
287*0Sstevel@tonic-gate } media_kstats_t;
288*0Sstevel@tonic-gate 
289*0Sstevel@tonic-gate struct gldkstats {
290*0Sstevel@tonic-gate 	kstat_named_t	glds_pktxmt;
291*0Sstevel@tonic-gate 	kstat_named_t	glds_pktrcv;
292*0Sstevel@tonic-gate 	kstat_named_t	glds_errxmt;
293*0Sstevel@tonic-gate 	kstat_named_t	glds_errrcv;
294*0Sstevel@tonic-gate 	kstat_named_t	glds_collisions;
295*0Sstevel@tonic-gate 	kstat_named_t	glds_bytexmt;
296*0Sstevel@tonic-gate 	kstat_named_t	glds_bytercv;
297*0Sstevel@tonic-gate 	kstat_named_t	glds_multixmt;
298*0Sstevel@tonic-gate 	kstat_named_t	glds_multircv;	/* multicast but not broadcast */
299*0Sstevel@tonic-gate 	kstat_named_t	glds_brdcstxmt;
300*0Sstevel@tonic-gate 	kstat_named_t	glds_brdcstrcv;
301*0Sstevel@tonic-gate 	kstat_named_t	glds_unknowns;
302*0Sstevel@tonic-gate 	kstat_named_t	glds_blocked;	/* discard due to upstream flow */
303*0Sstevel@tonic-gate 					/* control */
304*0Sstevel@tonic-gate 	kstat_named_t	glds_excoll;
305*0Sstevel@tonic-gate 	kstat_named_t	glds_defer;
306*0Sstevel@tonic-gate 	kstat_named_t	glds_frame;
307*0Sstevel@tonic-gate 	kstat_named_t	glds_crc;
308*0Sstevel@tonic-gate 	kstat_named_t	glds_overflow;
309*0Sstevel@tonic-gate 	kstat_named_t	glds_underflow;
310*0Sstevel@tonic-gate 	kstat_named_t	glds_short;
311*0Sstevel@tonic-gate 	kstat_named_t	glds_missed;
312*0Sstevel@tonic-gate 	kstat_named_t	glds_xmtlatecoll;
313*0Sstevel@tonic-gate 	kstat_named_t	glds_nocarrier;
314*0Sstevel@tonic-gate 	kstat_named_t	glds_noxmtbuf;
315*0Sstevel@tonic-gate 	kstat_named_t	glds_norcvbuf;
316*0Sstevel@tonic-gate 	kstat_named_t	glds_xmtbadinterp;
317*0Sstevel@tonic-gate 	kstat_named_t	glds_rcvbadinterp;
318*0Sstevel@tonic-gate 	kstat_named_t	glds_intr;
319*0Sstevel@tonic-gate 	kstat_named_t	glds_xmtretry;
320*0Sstevel@tonic-gate 	kstat_named_t	glds_pktxmt64;
321*0Sstevel@tonic-gate 	kstat_named_t	glds_pktrcv64;
322*0Sstevel@tonic-gate 	kstat_named_t	glds_bytexmt64;
323*0Sstevel@tonic-gate 	kstat_named_t	glds_bytercv64;
324*0Sstevel@tonic-gate 	kstat_named_t	glds_speed;
325*0Sstevel@tonic-gate 	kstat_named_t	glds_duplex;
326*0Sstevel@tonic-gate 	kstat_named_t	glds_media;
327*0Sstevel@tonic-gate 	kstat_named_t	glds_prom;
328*0Sstevel@tonic-gate 	media_kstats_t	glds_media_specific;
329*0Sstevel@tonic-gate };
330*0Sstevel@tonic-gate 
331*0Sstevel@tonic-gate typedef struct gld_mac_pvt gld_mac_pvt_t;
332*0Sstevel@tonic-gate 
333*0Sstevel@tonic-gate typedef struct gld_vlan {
334*0Sstevel@tonic-gate 	struct gld_vlan *gldv_next, *gldv_prev;
335*0Sstevel@tonic-gate 	uint32_t		gldv_id;
336*0Sstevel@tonic-gate 	uint32_t		gldv_ptag;
337*0Sstevel@tonic-gate 	int			gldv_nstreams;
338*0Sstevel@tonic-gate 	gld_mac_info_t		*gldv_mac;
339*0Sstevel@tonic-gate 	queue_t			*gldv_ipq;
340*0Sstevel@tonic-gate 	queue_t			*gldv_ipv6q;
341*0Sstevel@tonic-gate 	uint8_t			gldv_ipq_flags;
342*0Sstevel@tonic-gate 	struct gld		*gldv_str_next;	/* list of attached streams */
343*0Sstevel@tonic-gate 	struct gld		*gldv_str_prev;
344*0Sstevel@tonic-gate 	kstat_t			*gldv_kstatp;
345*0Sstevel@tonic-gate 	struct gld_stats	*gldv_stats;
346*0Sstevel@tonic-gate } gld_vlan_t;
347*0Sstevel@tonic-gate 
348*0Sstevel@tonic-gate #define	IPQ_DISABLED	0x01
349*0Sstevel@tonic-gate #define	IPQ_FORBIDDEN	0x02
350*0Sstevel@tonic-gate 
351*0Sstevel@tonic-gate #define	VLAN_HASHSZ	23
352*0Sstevel@tonic-gate 
353*0Sstevel@tonic-gate /* Per-mac info used by GLD */
354*0Sstevel@tonic-gate struct gld_mac_pvt {
355*0Sstevel@tonic-gate 	gld_interface_t	*interfacep;
356*0Sstevel@tonic-gate 	kmutex_t	datalock;	/* data lock for "data" */
357*0Sstevel@tonic-gate 	caddr_t		data;		/* media specific private data */
358*0Sstevel@tonic-gate 	gld_vlan_t	*vlan_hash[VLAN_HASHSZ];
359*0Sstevel@tonic-gate 	struct gld	*last_sched;	/* last scheduled stream */
360*0Sstevel@tonic-gate 	struct glddevice *major_dev;	/* per-major device struct */
361*0Sstevel@tonic-gate 	int		nvlan;		/* VLANs in use on this mac */
362*0Sstevel@tonic-gate 	int		nprom;		/* num streams in promiscuous mode */
363*0Sstevel@tonic-gate 	int		nprom_multi;	/* streams in promiscuous multicast */
364*0Sstevel@tonic-gate 	gld_mcast_t	*mcast_table;	/* per device multicast table */
365*0Sstevel@tonic-gate 	unsigned char	*curr_macaddr;	/* Currently programmed mac address */
366*0Sstevel@tonic-gate 	kstat_t		*kstatp;
367*0Sstevel@tonic-gate 	struct gld_stats *statistics;	/* The ones the driver updates */
368*0Sstevel@tonic-gate 	int		rde_enabled;	/* RDE (Source Routing) Enabled */
369*0Sstevel@tonic-gate 	int		rde_str_indicator_ste;	/* use STE when no SR info */
370*0Sstevel@tonic-gate 	int		rde_timeout;	/* route link inactivity timeout */
371*0Sstevel@tonic-gate 	uint32_t	notifications;	/* DL_NOTE options supported */
372*0Sstevel@tonic-gate 	boolean_t	started;	/* Has the MAC been started? */
373*0Sstevel@tonic-gate };
374*0Sstevel@tonic-gate 
375*0Sstevel@tonic-gate /* return values from gld_cmds */
376*0Sstevel@tonic-gate #define	GLDE_OK		(-1)	/* internal procedure status is OK */
377*0Sstevel@tonic-gate #define	GLDE_RETRY	0x1002	/* want to retry later */
378*0Sstevel@tonic-gate 
379*0Sstevel@tonic-gate /* caller argument to gld_start */
380*0Sstevel@tonic-gate #define	GLD_WPUT	0
381*0Sstevel@tonic-gate #define	GLD_WSRV	1
382*0Sstevel@tonic-gate 
383*0Sstevel@tonic-gate #define	GLD_MAX_802_SAP	0xff
384*0Sstevel@tonic-gate 
385*0Sstevel@tonic-gate /*
386*0Sstevel@tonic-gate  * definitions for debug tracing
387*0Sstevel@tonic-gate  */
388*0Sstevel@tonic-gate #define	GLDTRACE	0x0001	/* basic procedure level tracing */
389*0Sstevel@tonic-gate #define	GLDERRS		0x0002	/* trace errors */
390*0Sstevel@tonic-gate #define	GLDRECV		0x0004	/* trace receive path */
391*0Sstevel@tonic-gate #define	GLDSEND		0x0008	/* trace send path */
392*0Sstevel@tonic-gate #define	GLDPROT		0x0010	/* trace DLPI protocol */
393*0Sstevel@tonic-gate #define	GLDNOBR		0x0020	/* do not show broadcast messages */
394*0Sstevel@tonic-gate #define	GLDETRACE	0x0040	/* trace "normal case" errors */
395*0Sstevel@tonic-gate #define	GLDRDE		0x0080	/* netstat -k dump routing table */
396*0Sstevel@tonic-gate 
397*0Sstevel@tonic-gate /*
398*0Sstevel@tonic-gate  * Lock manipulation macros for GLDM_LOCK. Conceptually, the
399*0Sstevel@tonic-gate  * GLD layer treats the lock as a rw lock; for v0 binary and
400*0Sstevel@tonic-gate  * semantic compatibility, the underlying implementation still
401*0Sstevel@tonic-gate  * uses a mutex, whereas for v2 drivers, the more scalable rwlock
402*0Sstevel@tonic-gate  * is used instead. See notes in gld.h.
403*0Sstevel@tonic-gate  */
404*0Sstevel@tonic-gate #define	GLDM_LOCK_INIT(macinfo)						\
405*0Sstevel@tonic-gate 	rw_init(&(macinfo)->gldm_lock.gldl_rw_lock, NULL,		\
406*0Sstevel@tonic-gate 	    RW_DRIVER, (macinfo)->gldm_cookie);				\
407*0Sstevel@tonic-gate 	(macinfo)->gldm_GLD_flags |= GLD_LOCK_INITED
408*0Sstevel@tonic-gate 
409*0Sstevel@tonic-gate #define	GLDM_LOCK_INITED(macinfo)					\
410*0Sstevel@tonic-gate 	((macinfo)->gldm_GLD_flags & GLD_LOCK_INITED)
411*0Sstevel@tonic-gate 
412*0Sstevel@tonic-gate #define	GLDM_LOCK_DESTROY(macinfo)					\
413*0Sstevel@tonic-gate 	if ((macinfo)->gldm_GLD_flags & GLD_LOCK_INITED) {		\
414*0Sstevel@tonic-gate 		rw_destroy(&(macinfo)->gldm_lock.gldl_rw_lock);		\
415*0Sstevel@tonic-gate 		(macinfo)->gldm_GLD_flags &= ~GLD_LOCK_INITED;		\
416*0Sstevel@tonic-gate 	}
417*0Sstevel@tonic-gate 
418*0Sstevel@tonic-gate #define	GLDM_LOCK(macinfo, rw)						\
419*0Sstevel@tonic-gate 	rw_enter(&(macinfo)->gldm_lock.gldl_rw_lock, (rw))
420*0Sstevel@tonic-gate 
421*0Sstevel@tonic-gate #define	GLDM_UNLOCK(macinfo)						\
422*0Sstevel@tonic-gate 	rw_exit(&(macinfo)->gldm_lock.gldl_rw_lock)
423*0Sstevel@tonic-gate 
424*0Sstevel@tonic-gate #define	GLDM_TRYLOCK(macinfo, rw)					\
425*0Sstevel@tonic-gate 	rw_tryenter(&(macinfo)->gldm_lock.gldl_rw_lock, (rw))
426*0Sstevel@tonic-gate 
427*0Sstevel@tonic-gate /* lock held in read or write mode? */
428*0Sstevel@tonic-gate #define	GLDM_LOCK_HELD(macinfo)						\
429*0Sstevel@tonic-gate 	rw_lock_held(&(macinfo)->gldm_lock.gldl_rw_lock)
430*0Sstevel@tonic-gate 
431*0Sstevel@tonic-gate /* lock held in write mode? */
432*0Sstevel@tonic-gate #define	GLDM_LOCK_HELD_WRITE(macinfo)					\
433*0Sstevel@tonic-gate 	rw_write_held(&(macinfo)->gldm_lock.gldl_rw_lock)
434*0Sstevel@tonic-gate 
435*0Sstevel@tonic-gate /*
436*0Sstevel@tonic-gate  * Compare/copy two MAC addresses.
437*0Sstevel@tonic-gate  * Note that unlike bcmp, we return zero if they are different.
438*0Sstevel@tonic-gate  */
439*0Sstevel@tonic-gate #define	mac_eq(a, b, l) (bcmp((caddr_t)(a), (caddr_t)(b), (l)) == 0)
440*0Sstevel@tonic-gate #define	mac_copy(a, b, l) (bcopy((caddr_t)(a), (caddr_t)(b), (l)))
441*0Sstevel@tonic-gate /* copy a mac address to/from canonical form */
442*0Sstevel@tonic-gate #define	cmac_copy(a, b, l, macinfo) {					\
443*0Sstevel@tonic-gate 	    if ((macinfo)->gldm_options & GLDOPT_CANONICAL_ADDR)	\
444*0Sstevel@tonic-gate 		gld_bitrevcopy((caddr_t)(a), (caddr_t)(b), (l));	\
445*0Sstevel@tonic-gate 	    else							\
446*0Sstevel@tonic-gate 		mac_copy((a), (b), (l));				\
447*0Sstevel@tonic-gate 	}
448*0Sstevel@tonic-gate 
449*0Sstevel@tonic-gate /*
450*0Sstevel@tonic-gate  * Macros to access possibly-unaligned variables
451*0Sstevel@tonic-gate  */
452*0Sstevel@tonic-gate 
453*0Sstevel@tonic-gate #if	(_ALIGNMENT_REQUIRED == 0)
454*0Sstevel@tonic-gate 
455*0Sstevel@tonic-gate #define	REF_HOST_USHORT(lvalue) (lvalue)
456*0Sstevel@tonic-gate #define	REF_NET_USHORT(lvalue) (ntohs(lvalue))
457*0Sstevel@tonic-gate #define	SET_NET_USHORT(lvalue, val) ((lvalue) = htons(val))
458*0Sstevel@tonic-gate 
459*0Sstevel@tonic-gate #else	/* ALIGNMENT_REQUIRED */
460*0Sstevel@tonic-gate 
461*0Sstevel@tonic-gate #define	REF_NET_USHORT(lvalue) \
462*0Sstevel@tonic-gate 	((ushort_t)((((uchar_t *)(&(lvalue)))[0]<<8) | \
463*0Sstevel@tonic-gate 	((uchar_t *)(&(lvalue)))[1]))
464*0Sstevel@tonic-gate 
465*0Sstevel@tonic-gate #define	SET_NET_USHORT(lvalue, val) { \
466*0Sstevel@tonic-gate 	((uchar_t *)(&(lvalue)))[0] = (uchar_t)((val)>>8); \
467*0Sstevel@tonic-gate 	((uchar_t *)(&(lvalue)))[1] = (uchar_t)(val); \
468*0Sstevel@tonic-gate }
469*0Sstevel@tonic-gate 
470*0Sstevel@tonic-gate #if defined(_LITTLE_ENDIAN)
471*0Sstevel@tonic-gate 
472*0Sstevel@tonic-gate #define	REF_HOST_USHORT(lvalue) \
473*0Sstevel@tonic-gate 	((ushort_t)((((uchar_t *)(&(lvalue)))[1]<<8) | \
474*0Sstevel@tonic-gate 	((uchar_t *)(&(lvalue)))[0]))
475*0Sstevel@tonic-gate 
476*0Sstevel@tonic-gate #elif defined(_BIG_ENDIAN)
477*0Sstevel@tonic-gate 
478*0Sstevel@tonic-gate #define	REF_HOST_USHORT(lvalue) \
479*0Sstevel@tonic-gate 	((ushort_t)((((uchar_t *)(&(lvalue)))[0]<<8) | \
480*0Sstevel@tonic-gate 	((uchar_t *)(&(lvalue)))[1]))
481*0Sstevel@tonic-gate 
482*0Sstevel@tonic-gate #else	/* unknown endian */
483*0Sstevel@tonic-gate #error	"what endian is this machine?"
484*0Sstevel@tonic-gate #endif	/* endian */
485*0Sstevel@tonic-gate 
486*0Sstevel@tonic-gate #endif	/* ALIGNMENT_REQUIRED */
487*0Sstevel@tonic-gate 
488*0Sstevel@tonic-gate /* ================================================================ */
489*0Sstevel@tonic-gate /* Route Determination Entity definitions (IEEE 802.2 1994 edition) */
490*0Sstevel@tonic-gate /* ================================================================ */
491*0Sstevel@tonic-gate 
492*0Sstevel@tonic-gate struct rde_pdu {
493*0Sstevel@tonic-gate 	uchar_t	rde_ver;
494*0Sstevel@tonic-gate 	uchar_t	rde_ptype;
495*0Sstevel@tonic-gate 	uchar_t	rde_target_mac[6];
496*0Sstevel@tonic-gate 	uchar_t	rde_orig_mac[6];
497*0Sstevel@tonic-gate 	uchar_t	rde_target_sap;
498*0Sstevel@tonic-gate 	uchar_t	rde_orig_sap;
499*0Sstevel@tonic-gate };
500*0Sstevel@tonic-gate 
501*0Sstevel@tonic-gate #define	LSAP_RDE	0xa6	/* IEEE 802.2 section 3.3.1.2 */
502*0Sstevel@tonic-gate #define	RDE_RQC		0x01	/* Route Query Command */
503*0Sstevel@tonic-gate #define	RDE_RQR		0x02	/* Route Query Response */
504*0Sstevel@tonic-gate #define	RDE_RS		0x03	/* Route Selected */
505*0Sstevel@tonic-gate 
506*0Sstevel@tonic-gate /* ============================================================= */
507*0Sstevel@tonic-gate /* Source Routing fields and definitions (IEEE 802.2 and 802.1D) */
508*0Sstevel@tonic-gate /* ============================================================= */
509*0Sstevel@tonic-gate 
510*0Sstevel@tonic-gate #define	MAX_RDFLDS	14	/* changed to 14 from 8 as per IEEE */
511*0Sstevel@tonic-gate 
512*0Sstevel@tonic-gate /*
513*0Sstevel@tonic-gate  * Source Routing Route Information field.
514*0Sstevel@tonic-gate  */
515*0Sstevel@tonic-gate struct gld_ri {
516*0Sstevel@tonic-gate #if defined(_BIT_FIELDS_LTOH)
517*0Sstevel@tonic-gate 	uchar_t len:5;			/* length */
518*0Sstevel@tonic-gate 	uchar_t rt:3;			/* routing type */
519*0Sstevel@tonic-gate 	uchar_t res:4;			/* reserved */
520*0Sstevel@tonic-gate 	uchar_t mtu:3;			/* largest frame */
521*0Sstevel@tonic-gate 	uchar_t dir:1;			/* direction bit */
522*0Sstevel@tonic-gate 	struct tr_rd {			/* route designator fields */
523*0Sstevel@tonic-gate 		ushort_t bridge:4;	/* Note: assumes network order... */
524*0Sstevel@tonic-gate 		ushort_t ring:12;	/* ...(Big Endian) -- needs ntohs() */
525*0Sstevel@tonic-gate 	} rd[MAX_RDFLDS];
526*0Sstevel@tonic-gate #elif defined(_BIT_FIELDS_HTOL)
527*0Sstevel@tonic-gate 	uchar_t rt:3;			/* routing type */
528*0Sstevel@tonic-gate 	uchar_t len:5;			/* length */
529*0Sstevel@tonic-gate 	uchar_t dir:1;			/* direction bit */
530*0Sstevel@tonic-gate 	uchar_t mtu:3;			/* largest frame */
531*0Sstevel@tonic-gate 	uchar_t res:4;			/* reserved */
532*0Sstevel@tonic-gate 	struct tr_rd {			/* route designator fields */
533*0Sstevel@tonic-gate 		ushort_t ring:12;
534*0Sstevel@tonic-gate 		ushort_t bridge:4;
535*0Sstevel@tonic-gate 	} rd[MAX_RDFLDS];
536*0Sstevel@tonic-gate #else
537*0Sstevel@tonic-gate #error	"which way do bit fields get allocated?"
538*0Sstevel@tonic-gate #endif
539*0Sstevel@tonic-gate };
540*0Sstevel@tonic-gate 
541*0Sstevel@tonic-gate #define	RT_SRF		0x0		/* 0xx: specifically routed frame */
542*0Sstevel@tonic-gate #define	RT_ARE		0x4		/* 10x: all routes explorer frame */
543*0Sstevel@tonic-gate #define	RT_STE		0x6		/* 11x: spanning tree explorer frame */
544*0Sstevel@tonic-gate 
545*0Sstevel@tonic-gate #define	RT_MTU_MAX	0x7		/* Max MTU field (base only) */
546*0Sstevel@tonic-gate 
547*0Sstevel@tonic-gate /*
548*0Sstevel@tonic-gate  * Source route table info
549*0Sstevel@tonic-gate  */
550*0Sstevel@tonic-gate struct srtab {
551*0Sstevel@tonic-gate 	struct srtab	*sr_next;		/* next in linked list */
552*0Sstevel@tonic-gate 	uchar_t		sr_mac[6];		/* MAC address */
553*0Sstevel@tonic-gate 	struct		gld_ri sr_ri;		/* routing information */
554*0Sstevel@tonic-gate 	clock_t		sr_timer;
555*0Sstevel@tonic-gate };
556*0Sstevel@tonic-gate 
557*0Sstevel@tonic-gate #define	SR_HASH_SIZE	256		/* Number of bins */
558*0Sstevel@tonic-gate 
559*0Sstevel@tonic-gate /* ================================================================= */
560*0Sstevel@tonic-gate /* Media dependent defines for media dependent routines in gldutil.c */
561*0Sstevel@tonic-gate /* ================================================================= */
562*0Sstevel@tonic-gate 
563*0Sstevel@tonic-gate /*
564*0Sstevel@tonic-gate  * Some "semi-generic" defines used by ether, token, and fddi,
565*0Sstevel@tonic-gate  * and probably anything else with addrlen == 6 && saplen == -2.
566*0Sstevel@tonic-gate  */
567*0Sstevel@tonic-gate 
568*0Sstevel@tonic-gate struct gld_dlsap {
569*0Sstevel@tonic-gate 	unsigned char   glda_addr[ETHERADDRL];
570*0Sstevel@tonic-gate 	unsigned short  glda_sap;
571*0Sstevel@tonic-gate };
572*0Sstevel@tonic-gate 
573*0Sstevel@tonic-gate #define	DLSAP(p, offset) ((struct gld_dlsap *)((caddr_t)(p)+offset))
574*0Sstevel@tonic-gate 
575*0Sstevel@tonic-gate typedef uchar_t mac_addr_t[ETHERADDRL];
576*0Sstevel@tonic-gate 
577*0Sstevel@tonic-gate struct llc_snap_hdr {
578*0Sstevel@tonic-gate 	uchar_t  d_lsap;		/* destination service access point */
579*0Sstevel@tonic-gate 	uchar_t  s_lsap;		/* source link service access point */
580*0Sstevel@tonic-gate 	uchar_t  control;		/* short control field */
581*0Sstevel@tonic-gate 	uchar_t  org[3];		/* Ethernet style organization field */
582*0Sstevel@tonic-gate 	ushort_t type;			/* Ethernet style type field */
583*0Sstevel@tonic-gate };
584*0Sstevel@tonic-gate 
585*0Sstevel@tonic-gate #define	LLC_HDR1_LEN		3	/* Length of the LLC1 header */
586*0Sstevel@tonic-gate #define	LLC_SNAP_HDR_LEN	8	/* Full length of SNAP header */
587*0Sstevel@tonic-gate #define	LSAP_SNAP		0xaa	/* SAP for SubNet Access Protocol */
588*0Sstevel@tonic-gate #define	CNTL_LLC_UI		0x03	/* un-numbered information packet */
589*0Sstevel@tonic-gate 
590*0Sstevel@tonic-gate /* ============================ */
591*0Sstevel@tonic-gate /* Ethernet related definitions */
592*0Sstevel@tonic-gate /* ============================ */
593*0Sstevel@tonic-gate 
594*0Sstevel@tonic-gate struct ether_mac_frm {
595*0Sstevel@tonic-gate 	mac_addr_t	ether_dhost;
596*0Sstevel@tonic-gate 	mac_addr_t	ether_shost;
597*0Sstevel@tonic-gate 	ushort_t	ether_type;
598*0Sstevel@tonic-gate };
599*0Sstevel@tonic-gate 
600*0Sstevel@tonic-gate /* ======================== */
601*0Sstevel@tonic-gate /* FDDI related definitions */
602*0Sstevel@tonic-gate /* ======================== */
603*0Sstevel@tonic-gate 
604*0Sstevel@tonic-gate struct	fddi_mac_frm {
605*0Sstevel@tonic-gate 	uchar_t		fddi_fc;
606*0Sstevel@tonic-gate 	mac_addr_t	fddi_dhost;
607*0Sstevel@tonic-gate 	mac_addr_t	fddi_shost;
608*0Sstevel@tonic-gate };
609*0Sstevel@tonic-gate 
610*0Sstevel@tonic-gate /* ============================== */
611*0Sstevel@tonic-gate /* Token Ring related definitions */
612*0Sstevel@tonic-gate /* ============================== */
613*0Sstevel@tonic-gate 
614*0Sstevel@tonic-gate struct tr_mac_frm_nori {
615*0Sstevel@tonic-gate 	uchar_t		tr_ac;
616*0Sstevel@tonic-gate 	uchar_t		tr_fc;
617*0Sstevel@tonic-gate 	mac_addr_t	tr_dhost;
618*0Sstevel@tonic-gate 	mac_addr_t	tr_shost;
619*0Sstevel@tonic-gate };
620*0Sstevel@tonic-gate 
621*0Sstevel@tonic-gate struct tr_mac_frm {
622*0Sstevel@tonic-gate 	uchar_t		tr_ac;
623*0Sstevel@tonic-gate 	uchar_t		tr_fc;
624*0Sstevel@tonic-gate 	mac_addr_t	tr_dhost;
625*0Sstevel@tonic-gate 	mac_addr_t	tr_shost;
626*0Sstevel@tonic-gate 	struct gld_ri	tr_ri;		/* Routing Information Field */
627*0Sstevel@tonic-gate };
628*0Sstevel@tonic-gate 
629*0Sstevel@tonic-gate #ifdef	__cplusplus
630*0Sstevel@tonic-gate }
631*0Sstevel@tonic-gate #endif
632*0Sstevel@tonic-gate 
633*0Sstevel@tonic-gate #endif /* _SYS_GLDPRIV_H */
634