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