xref: /titanic_51/usr/src/uts/common/sys/gld.h (revision 1d8c40254918b6a58c4b2132dafb3e012ccd66f0)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*
28  * gld - Generic LAN Driver support system for DLPI drivers.
29  */
30 
31 #ifndef	_SYS_GLD_H
32 #define	_SYS_GLD_H
33 
34 #pragma ident	"%Z%%M%	%I%	%E% SMI"
35 
36 #include <sys/ethernet.h>
37 
38 #ifdef	__cplusplus
39 extern "C" {
40 #endif
41 
42 /*
43  * Media specific MIB-II counters/statistics
44  *
45  * This only includes those that aren't in the legacy counters.
46  */
47 
48 typedef union media_stats {
49 	struct dot3stat {
50 		/* Ethernet: RFC1643 Dot3Stats (subset) */
51 		uint32_t	first_coll;	/* SingleCollisionFrames */
52 		uint32_t	multi_coll;	/* MultipleCollisionFrames */
53 		uint32_t	sqe_error;	/* SQETestErrors */
54 		uint32_t	mac_xmt_error;	/* InternalMacTransmitErrors */
55 		uint32_t	frame_too_long;	/* FrameTooLongs */
56 		uint32_t	mac_rcv_error;	/* InternalMacReceiveErrors */
57 	} dot3;
58 	struct dot5stat {
59 		/* Token Ring: RFC1748 Dot5Stats (subset) */
60 		uint32_t	ace_error;
61 		uint32_t	internal_error;
62 		uint32_t	lost_frame_error;
63 		uint32_t	frame_copied_error;
64 		uint32_t	token_error;
65 		uint32_t	freq_error;
66 	} dot5;
67 	struct fddistat {
68 		/* FDDI: RFC1512 (subset) */
69 		uint32_t	mac_error;
70 		uint32_t	mac_lost;
71 		uint32_t	mac_token;
72 		uint32_t	mac_tvx_expired;
73 		uint32_t	mac_late;
74 		uint32_t	mac_ring_op;
75 	} fddi;
76 	uint32_t		pad[16];
77 } media_stats_t;
78 
79 #define	glds_dot3_first_coll		glds_media_specific.dot3.first_coll
80 #define	glds_dot3_multi_coll		glds_media_specific.dot3.multi_coll
81 #define	glds_dot3_sqe_error		glds_media_specific.dot3.sqe_error
82 #define	glds_dot3_mac_xmt_error		glds_media_specific.dot3.mac_xmt_error
83 #define	glds_dot3_mac_rcv_error		glds_media_specific.dot3.mac_rcv_error
84 #define	glds_dot3_frame_too_long	glds_media_specific.dot3.frame_too_long
85 
86 #define	glds_dot5_line_error		glds_crc
87 #define	glds_dot5_burst_error		glds_frame
88 #define	glds_dot5_ace_error		glds_media_specific.dot5.ace_error
89 #define	glds_dot5_internal_error	glds_media_specific.dot5.internal_error
90 #define	glds_dot5_lost_frame_error   glds_media_specific.dot5.lost_frame_error
91 #define	glds_dot5_frame_copied_error glds_media_specific.dot5.frame_copied_error
92 #define	glds_dot5_token_error		glds_media_specific.dot5.token_error
93 #define	glds_dot5_signal_loss		glds_nocarrier
94 #define	glds_dot5_freq_error		glds_media_specific.dot5.freq_error
95 
96 #define	glds_fddi_mac_error		glds_media_specific.fddi.mac_error
97 #define	glds_fddi_mac_lost		glds_media_specific.fddi.mac_lost
98 #define	glds_fddi_mac_token		glds_media_specific.fddi.mac_token
99 #define	glds_fddi_mac_tvx_expired	glds_media_specific.fddi.mac_tvx_expired
100 #define	glds_fddi_mac_late		glds_media_specific.fddi.mac_late
101 #define	glds_fddi_mac_ring_op		glds_media_specific.fddi.mac_ring_op
102 
103 /*
104  * structure for driver statistics
105  */
106 struct gld_stats {
107 	ulong_t		glds_multixmt;	/* (G) ifOutMulticastPkts */
108 	ulong_t		glds_multircv;	/* (G) ifInMulticastPkts */
109 	ulong_t		glds_brdcstxmt;	/* (G) ifOutBroadcastPkts */
110 	ulong_t		glds_brdcstrcv;	/* (G) ifInBroadcastPkts */
111 	uint32_t	glds_blocked;	/* (G) discard: upstream flow cntrl */
112 	uint32_t	glds_reserved1;
113 	uint32_t	glds_reserved2;
114 	uint32_t	glds_reserved3;
115 	uint32_t	glds_reserved4;
116 	uint32_t	glds_errxmt;	/* (D) ifOutErrors */
117 	uint32_t	glds_errrcv;	/* (D) ifInErrors */
118 	uint32_t	glds_collisions; /* (e) Sun MIB's rsIfCollisions */
119 	uint32_t	glds_excoll;	/* (e) dot3StatsExcessiveCollisions */
120 	uint32_t	glds_defer;	/* (e) dot3StatsDeferredTransmissions */
121 	uint32_t	glds_frame;	/* (e) dot3StatsAlignErrors */
122 	uint32_t	glds_crc;	/* (e) dot3StatsFCSErrors */
123 	uint32_t	glds_overflow;	/* (D) */
124 	uint32_t	glds_underflow;	/* (D) */
125 	uint32_t	glds_short;	/* (e) */
126 	uint32_t	glds_missed;	/* (D) */
127 	uint32_t	glds_xmtlatecoll; /* (e) dot3StatsLateCollisions */
128 	uint32_t	glds_nocarrier; /* (e) dot3StatsCarrierSenseErrors */
129 	uint32_t	glds_noxmtbuf;	/* (G) ifOutDiscards */
130 	uint32_t	glds_norcvbuf;	/* (D) ifInDiscards */
131 	uint32_t	glds_intr;	/* (D) */
132 	uint32_t	glds_xmtretry;	/* (G) */
133 	uint64_t	glds_pktxmt64;	/* (G) 64-bit rsIfOutPackets */
134 	uint64_t	glds_pktrcv64;	/* (G) 64-bit rsIfInPackets */
135 	uint64_t	glds_bytexmt64;	/* (G) ifHCOutOctets */
136 	uint64_t	glds_bytercv64;	/* (G) ifHCInOctets */
137 	uint64_t	glds_speed;	/* (D) ifSpeed */
138 	uint32_t	glds_duplex;	/* (e) Invented for GLD */
139 	uint32_t	glds_media;	/* (D) Invented for GLD */
140 	uint32_t	glds_unknowns;	/* (G) ifInUnknownProtos */
141 	uint32_t	reserved[19];
142 	media_stats_t	glds_media_specific;
143 	uint32_t	glds_xmtbadinterp; /* (G) bad packet len/format */
144 	uint32_t	glds_rcvbadinterp; /* (G) bad packet len/format */
145 	uint32_t	glds_gldnorcvbuf;  /* (G) norcvbuf from inside GLD */
146 };
147 
148 /*
149  * gld_mac_info structure.  Used to define the per-board data for all
150  * drivers.
151  *
152  * The below definition of gld_mac_info contains GLD PRIVATE entries that must
153  * not be used by the device driver. Only entries marked SET BY DRIVER should
154  * be modified.
155  */
156 
157 #define	GLD_STATS_SIZE_ORIG	(sizeof (uint32_t) * 26) /* don't change */
158 #define	GLD_KSTAT_SIZE_ORIG (sizeof (kstat_named_t) * 26) /* don't change */
159 #define	GLD_PAD  ((int)GLD_KSTAT_SIZE_ORIG + (int)GLD_STATS_SIZE_ORIG)
160 
161 typedef union gld_lock {
162 	kmutex_t	reserved;
163 	krwlock_t	gldl_rw_lock;
164 } gld_lock_t;
165 
166 typedef struct gld_mac_info {
167 	struct gld_mac_info *gldm_next;			/* GLD PRIVATE */
168 	struct gld_mac_info *gldm_prev;			/* GLD PRIVATE */
169 	caddr_t		reserved1;			/* GLD PRIVATE */
170 	caddr_t		reserved2;			/* GLD PRIVATE */
171 	uint16_t	gldm_driver_version;		/* GLD PRIVATE */
172 	uint16_t	gldm_GLD_version;		/* GLD PRIVATE */
173 	uint16_t	gldm_GLD_flags;			/* GLD PRIVATE */
174 	uint16_t	gldm_options;			/* GLD_PRIVATE */
175 	dev_info_t	*gldm_devinfo;			/* SET BY DRIVER */
176 	uchar_t		*gldm_vendor_addr;		/* SET BY DRIVER */
177 	uchar_t		*gldm_broadcast_addr;		/* SET BY DRIVER */
178 	gld_lock_t	gldm_lock;			/* GLD PRIVATE */
179 	ddi_iblock_cookie_t gldm_cookie;		/* SET BY DRIVER */
180 	uint32_t	reserved3;			/* GLD PRIVATE */
181 	uint32_t	reserved4;			/* GLD PRIVATE */
182 	uint32_t	gldm_maxpkt;			/* SET BY DRIVER */
183 	uint32_t	gldm_minpkt;			/* SET BY DRIVER */
184 	char		*gldm_ident;			/* SET BY DRIVER */
185 	uint32_t	gldm_type;			/* SET BY DRIVER */
186 	uint32_t	reserved5;			/* GLD PRIVATE */
187 	uint32_t	gldm_addrlen;			/* SET BY DRIVER */
188 	int32_t		gldm_saplen;			/* SET BY DRIVER */
189 							/* NOTE: MUST BE -2 */
190 	unsigned char	reserved7[ETHERADDRL];		/* GLD PRIVATE */
191 	unsigned char	reserved8[ETHERADDRL];		/* GLD PRIVATE */
192 	unsigned char	reserved9[ETHERADDRL];		/* GLD PRIVATE */
193 	t_uscalar_t	gldm_ppa;			/* SET BY DRIVER */
194 	int32_t		reserved10;			/* GLD PRIVATE */
195 	uint32_t	gldm_capabilities; 		/* SET BY DRIVER */
196 	int32_t		gldm_linkstate;			/* GLD PRIVATE */
197 	uint32_t	reserved11;			/* GLD PRIVATE */
198 	caddr_t		reserved12;			/* GLD PRIVATE */
199 	int32_t		reserved13;			/* GLD PRIVATE */
200 	uint32_t	reserved14;			/* GLD PRIVATE */
201 	int32_t		reserved15;			/* GLD PRIVATE */
202 	caddr_t		gldm_mac_pvt;			/* GLD PRIVATE */
203 	caddr_t		reserved16;			/* GLD PRIVATE */
204 	char		reserved17[GLD_PAD];		/* GLD PRIVATE */
205 	caddr_t		reserved18;			/* GLD PRIVATE */
206 	caddr_t		gldm_private;			/* GLD PRIVATE */
207 	int		(*gldm_reset)();		/* SET BY DRIVER */
208 	int		(*gldm_start)();		/* SET BY DRIVER */
209 	int		(*gldm_stop)();			/* SET BY DRIVER */
210 	int		(*gldm_set_mac_addr)();		/* SET BY DRIVER */
211 	int		(*gldm_send)();			/* SET BY DRIVER */
212 	int		(*gldm_set_promiscuous)();	/* SET BY DRIVER */
213 	int		(*gldm_get_stats)();		/* SET BY DRIVER */
214 	int		(*gldm_ioctl)();		/* SET BY DRIVER */
215 	int		(*gldm_set_multicast)(); 	/* SET BY DRIVER */
216 	uint_t		(*gldm_intr)();			/* SET BY DRIVER */
217 	int		(*gldm_mctl)();			/* SET BY DRIVER */
218 	int		(*gldm_send_tagged)();		/* SET BY DRIVER */
219 	/*
220 	 * The following MDT related entry points are Sun private,
221 	 * meant only for use by Sun's IPoIB (ibd) driver.
222 	 */
223 	int		(*gldm_mdt_pre)();		/* SET BY DRIVER */
224 	void		(*gldm_mdt_send)();		/* SET BY DRIVER */
225 	void		(*gldm_mdt_post)();		/* SET BY DRIVER */
226 	int		gldm_mdt_sgl;			/* SET BY DRIVER */
227 	int		gldm_mdt_segs;			/* SET BY DRIVER */
228 } gld_mac_info_t;
229 
230 /* flags for physical promiscuous state */
231 #define	GLD_MAC_PROMISC_NOOP	-1	/* leave mode unchanged		 */
232 #define	GLD_MAC_PROMISC_NONE	0	/* promiscuous mode(s) OFF	 */
233 #define	GLD_MAC_PROMISC_PHYS	1	/* receive all packets		 */
234 #define	GLD_MAC_PROMISC_MULTI	2	/* receive all multicast packets */
235 
236 #define	GLD_MULTI_ENABLE	1
237 #define	GLD_MULTI_DISABLE	0
238 
239 /* flags for gldm_capabilities */
240 #define	GLD_CAP_LINKSTATE	0x00000001 /* will call gld_linkstate() */
241 #define	GLD_CAP_CKSUM_IPHDR	0x00000008 /* IP checksum offload	*/
242 #define	GLD_CAP_CKSUM_PARTIAL	0x00000010 /* TCP/UDP partial		*/
243 #define	GLD_CAP_CKSUM_FULL_V4	0x00000020 /* TCP/UDP full for IPv4	*/
244 #define	GLD_CAP_ZEROCOPY	0x00000040 /* zerocopy */
245 #define	GLD_CAP_CKSUM_FULL_V6	0x00000080 /* TCP/UDP full for IPv6	*/
246 #define	GLD_CAP_CKSUM_ANY				\
247 	(GLD_CAP_CKSUM_IPHDR|GLD_CAP_CKSUM_PARTIAL|	\
248 	GLD_CAP_CKSUM_FULL_V4|GLD_CAP_CKSUM_FULL_V6)
249 
250 /* values of gldm_linkstate, as passed to gld_linkstate() */
251 #define	GLD_LINKSTATE_DOWN	-1
252 #define	GLD_LINKSTATE_UNKNOWN	0
253 #define	GLD_LINKSTATE_UP	1
254 
255 /*
256  * media type: this identifies the media/connector currently used by the
257  * driver.  Possible types will be defined for each DLPI type defined in
258  * gldm_type.  The below definitions should be used by the device dependent
259  * drivers to set glds_media.
260  */
261 
262 /* if driver cannot determine media/connector type  */
263 #define	GLDM_UNKNOWN	0
264 
265 #define	GLDM_AUI	1
266 #define	GLDM_BNC	2
267 #define	GLDM_TP		3
268 #define	GLDM_FIBER	4
269 #define	GLDM_100BT	5
270 #define	GLDM_VGANYLAN	6
271 #define	GLDM_10BT	7
272 #define	GLDM_RING4	8
273 #define	GLDM_RING16	9
274 #define	GLDM_PHYMII	10
275 #define	GLDM_100BTX	11
276 #define	GLDM_100BT4	12
277 #define	GLDM_IB		14
278 
279 /* defines for possible duplex states (glds_duplex) */
280 #define	GLD_DUPLEX_UNKNOWN	0
281 #define	GLD_DUPLEX_HALF		1
282 #define	GLD_DUPLEX_FULL		2
283 
284 /* Values returned from driver entry points */
285 #define	GLD_SUCCESS		0
286 #define	GLD_NORESOURCES		1
287 #define	GLD_NOTSUPPORTED	2
288 #define	GLD_BADARG		3
289 #define	GLD_NOLINK		4
290 #define	GLD_RETRY		5
291 #define	GLD_FAILURE		(-1)
292 
293 #if defined(_KERNEL)
294 /* Functions exported to drivers */
295 extern gld_mac_info_t *gld_mac_alloc(dev_info_t *);
296 extern void gld_mac_free(gld_mac_info_t *);
297 extern int gld_register(dev_info_t *, char *, gld_mac_info_t *);
298 extern int gld_unregister(gld_mac_info_t *);
299 extern void gld_recv(gld_mac_info_t *, mblk_t *);
300 extern void gld_recv_tagged(gld_mac_info_t *, mblk_t *, uint32_t);
301 extern void gld_linkstate(gld_mac_info_t *, int32_t);
302 extern void gld_sched(gld_mac_info_t *);
303 extern uint_t gld_intr();
304 
305 extern int gld_getinfo(dev_info_t *, ddi_info_cmd_t, void *, void **);
306 extern int gld_open(queue_t *, dev_t *, int, int, cred_t *);
307 extern int gld_close(queue_t *, int, cred_t *);
308 extern int gld_wput(queue_t *, mblk_t *);
309 extern int gld_wsrv(queue_t *);
310 extern int gld_rsrv(queue_t *);
311 #endif
312 
313 /*
314  * VLAN tag macros
315  *
316  * Per IEEE802.1Q, a VLAN tag is made up of a 2-byte Tagged Protocol
317  * Identifier (TPID) and two bytes of Tag/Control information (TCI).
318  * All fields should be treated as unsigned, and so a VTAG is held as
319  * a 'uint32_t'
320  */
321 #define	VTAG_SIZE	4		/* bytes (octets)		*/
322 
323 #define	VLAN_TPID_MASK	0xffff0000u
324 #define	VLAN_TPID_SHIFT	16
325 #define	VLAN_TCI_MASK	0x0000ffffu
326 #define	VLAN_TCI_SHIFT	0
327 
328 #define	VLAN_PRI_MASK	0x0000e000u
329 #define	VLAN_PRI_SHIFT	13
330 #define	VLAN_CFI_MASK	0x00001000u
331 #define	VLAN_CFI_SHIFT	12
332 #define	VLAN_VID_MASK	0x00000fffu
333 #define	VLAN_VID_SHIFT	0
334 
335 #define	VLAN_TPID	0x8100u		/* Per IEEE 802.1Q standard	*/
336 #define	VLAN_CFI_ETHER	0		/* CFI on Ethernet must be 0	*/
337 #define	VLAN_PRI_DFLT	0
338 #define	VLAN_PRI_MAX	7
339 #define	VLAN_VID_NONE	0		/* Not a valid VID		*/
340 #define	VLAN_VID_MIN	1
341 #define	VLAN_VID_MAX	4094		/* IEEE std; 4095 is reserved	*/
342 
343 #define	VLAN_VTAG_NONE	0		/* Special case: "untagged"	*/
344 
345 /*
346  * Macros to construct a TCI or VTAG.  The user must ensure values are in
347  * range.  In particular, VID 0 is not a valid argument to these constructor
348  * macros; when the VID is 0 (VLAN_VID_NONE), the whole VTAG should be 0
349  * (VLAN_VTAG_NONE), not 0x81000000.
350  */
351 #define	GLD_MAKE_TCI(pri, cfi, vid)    (((pri) << VLAN_PRI_SHIFT) |	\
352 					((cfi) << VLAN_CFI_SHIFT) |	\
353 					((vid) << VLAN_VID_SHIFT))
354 
355 #define	GLD_MAKE_VTAG(tci)	((VLAN_TPID << VLAN_TPID_SHIFT) | (tci))
356 
357 /*
358  * Macros to construct a prototype TCI/VTAG and then convert it to a real one
359  */
360 #define	GLD_MK_PTCI(cfi, vid)	GLD_MAKE_TCI(VLAN_PRI_MAX, cfi, vid)
361 #define	GLD_MK_PTAG(cfi, vid)	GLD_MAKE_VTAG(GLD_MK_PTCI(cfi, vid))
362 #define	GLD_MK_PMSK(pri)	(((pri) << VLAN_PRI_SHIFT) | ~VLAN_PRI_MASK)
363 #define	GLD_MK_VTAG(ptag, pri)	((ptag) & GLD_MK_PMSK(pri))
364 
365 /*
366  * Deconstruct a VTAG ...
367  */
368 #define	GLD_VTAG_TPID(vtag)	(((vtag) & VLAN_TPID_MASK) >> VLAN_TPID_SHIFT)
369 #define	GLD_VTAG_TCI(vtag)	(((vtag) & VLAN_TCI_MASK) >> VLAN_TCI_SHIFT)
370 
371 #define	GLD_VTAG_PRI(vtag)	(((vtag) & VLAN_PRI_MASK) >> VLAN_PRI_SHIFT)
372 #define	GLD_VTAG_CFI(vtag)	(((vtag) & VLAN_CFI_MASK) >> VLAN_CFI_SHIFT)
373 #define	GLD_VTAG_VID(vtag)	(((vtag) & VLAN_VID_MASK) >> VLAN_VID_SHIFT)
374 
375 #ifdef	__cplusplus
376 }
377 #endif
378 
379 #endif /* _SYS_GLD_H */
380