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