xref: /illumos-gate/usr/src/uts/common/sys/gld.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 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  *
25  * Copyright 2022 Garrett D'Amore
26  */
27 
28 /*
29  * gld - Generic LAN Driver support system for DLPI drivers.
30  */
31 
32 #ifndef	_SYS_GLD_H
33 #define	_SYS_GLD_H
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	gldm_margin;			/* SET BY DRIVER */
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 } gld_mac_info_t;
219 
220 /* flags for physical promiscuous state */
221 #define	GLD_MAC_PROMISC_NOOP	-1	/* leave mode unchanged		 */
222 #define	GLD_MAC_PROMISC_NONE	0	/* promiscuous mode(s) OFF	 */
223 #define	GLD_MAC_PROMISC_PHYS	1	/* receive all packets		 */
224 #define	GLD_MAC_PROMISC_MULTI	2	/* receive all multicast packets */
225 
226 #define	GLD_MULTI_ENABLE	1
227 #define	GLD_MULTI_DISABLE	0
228 
229 /* flags for gldm_capabilities */
230 #define	GLD_CAP_LINKSTATE	0x00000001 /* will call gld_linkstate() */
231 #define	GLD_CAP_CKSUM_IPHDR	0x00000008 /* IP checksum offload	*/
232 #define	GLD_CAP_CKSUM_PARTIAL	0x00000010 /* TCP/UDP partial		*/
233 #define	GLD_CAP_CKSUM_FULL_V4	0x00000020 /* TCP/UDP full for IPv4	*/
234 #define	GLD_CAP_ZEROCOPY	0x00000040 /* zerocopy */
235 #define	GLD_CAP_CKSUM_FULL_V6	0x00000080 /* TCP/UDP full for IPv6	*/
236 #define	GLD_CAP_CKSUM_ANY				\
237 	(GLD_CAP_CKSUM_IPHDR|GLD_CAP_CKSUM_PARTIAL|	\
238 	GLD_CAP_CKSUM_FULL_V4|GLD_CAP_CKSUM_FULL_V6)
239 
240 /* values of gldm_linkstate, as passed to gld_linkstate() */
241 #define	GLD_LINKSTATE_DOWN	-1
242 #define	GLD_LINKSTATE_UNKNOWN	0
243 #define	GLD_LINKSTATE_UP	1
244 
245 /*
246  * media type: this identifies the media/connector currently used by the
247  * driver.  Possible types will be defined for each DLPI type defined in
248  * gldm_type.  The below definitions should be used by the device dependent
249  * drivers to set glds_media.
250  */
251 
252 /* if driver cannot determine media/connector type  */
253 #define	GLDM_UNKNOWN	0
254 
255 #define	GLDM_AUI	1
256 #define	GLDM_BNC	2
257 #define	GLDM_TP		3
258 #define	GLDM_FIBER	4
259 #define	GLDM_100BT	5
260 #define	GLDM_VGANYLAN	6
261 #define	GLDM_10BT	7
262 #define	GLDM_RING4	8
263 #define	GLDM_RING16	9
264 #define	GLDM_PHYMII	10
265 #define	GLDM_100BTX	11
266 #define	GLDM_100BT4	12
267 #define	GLDM_IB		14
268 
269 /* defines for possible duplex states (glds_duplex) */
270 #define	GLD_DUPLEX_UNKNOWN	0
271 #define	GLD_DUPLEX_HALF		1
272 #define	GLD_DUPLEX_FULL		2
273 
274 /* Values returned from driver entry points */
275 #define	GLD_SUCCESS		0
276 #define	GLD_NORESOURCES		1
277 #define	GLD_NOTSUPPORTED	2
278 #define	GLD_BADARG		3
279 #define	GLD_NOLINK		4
280 #define	GLD_RETRY		5
281 #define	GLD_FAILURE		(-1)
282 
283 #if defined(_KERNEL)
284 /* Functions exported to drivers */
285 extern gld_mac_info_t *gld_mac_alloc(dev_info_t *);
286 extern void gld_mac_free(gld_mac_info_t *);
287 extern int gld_register(dev_info_t *, char *, gld_mac_info_t *);
288 extern int gld_unregister(gld_mac_info_t *);
289 extern void gld_recv(gld_mac_info_t *, mblk_t *);
290 extern void gld_recv_tagged(gld_mac_info_t *, mblk_t *, uint32_t);
291 extern void gld_linkstate(gld_mac_info_t *, int32_t);
292 extern void gld_sched(gld_mac_info_t *);
293 extern uint_t gld_intr();
294 
295 extern int gld_getinfo(dev_info_t *, ddi_info_cmd_t, void *, void **);
296 extern int gld_open(queue_t *, dev_t *, int, int, cred_t *);
297 extern int gld_close(queue_t *, int, cred_t *);
298 extern int gld_wput(queue_t *, mblk_t *);
299 extern int gld_wsrv(queue_t *);
300 extern int gld_rsrv(queue_t *);
301 #endif
302 
303 /*
304  * VLAN tag macros
305  *
306  * Per IEEE802.1Q, a VLAN tag is made up of a 2-byte Tagged Protocol
307  * Identifier (TPID) and two bytes of Tag/Control information (TCI).
308  * All fields should be treated as unsigned, and so a VTAG is held as
309  * a 'uint32_t'
310  */
311 #define	VTAG_SIZE	4		/* bytes (octets)		*/
312 
313 #define	VLAN_TPID_MASK	0xffff0000u
314 #define	VLAN_TPID_SHIFT	16
315 #define	VLAN_TCI_MASK	0x0000ffffu
316 #define	VLAN_TCI_SHIFT	0
317 
318 #define	VLAN_PRI_MASK	0x0000e000u
319 #define	VLAN_PRI_SHIFT	13
320 #define	VLAN_CFI_MASK	0x00001000u
321 #define	VLAN_CFI_SHIFT	12
322 #define	VLAN_VID_MASK	0x00000fffu
323 #define	VLAN_VID_SHIFT	0
324 
325 #define	VLAN_TPID	0x8100u		/* Per IEEE 802.1Q standard	*/
326 #define	VLAN_CFI_ETHER	0		/* CFI on Ethernet must be 0	*/
327 #define	VLAN_PRI_DFLT	0
328 #define	VLAN_PRI_MAX	7
329 #define	VLAN_VID_NONE	0		/* Not a valid VID		*/
330 #define	VLAN_VID_MIN	1
331 #define	VLAN_VID_MAX	4094		/* IEEE std; 4095 is reserved	*/
332 
333 #define	VLAN_VTAG_NONE	0		/* Special case: "untagged"	*/
334 
335 /*
336  * Macros to construct a TCI or VTAG.  The user must ensure values are in
337  * range.  Note that in the special case of priority tag, VLAN_VID_NONE
338  * is also a valid argument to these constructor macros.
339  */
340 #define	GLD_MAKE_TCI(pri, cfi, vid)    (((pri) << VLAN_PRI_SHIFT) |	\
341 					((cfi) << VLAN_CFI_SHIFT) |	\
342 					((vid) << VLAN_VID_SHIFT))
343 
344 #define	GLD_MAKE_VTAG(pri, cfi, vid)				\
345 	(((uint32_t)ETHERTYPE_VLAN << VLAN_TPID_SHIFT) |	\
346 	((pri) << VLAN_PRI_SHIFT) |				\
347 	((cfi) << VLAN_CFI_SHIFT) |				\
348 	((vid) << VLAN_VID_SHIFT))
349 
350 #define	GLD_TCI2VTAG(tci)	\
351 	(((uint32_t)ETHERTYPE_VLAN << VLAN_TPID_SHIFT) | (tci))
352 
353 /*
354  * Macros to construct a prototype TCI/VTAG and then convert it to a real one
355  */
356 #define	GLD_MK_PTCI(cfi, vid)	GLD_MAKE_TCI(VLAN_PRI_MAX, cfi, vid)
357 #define	GLD_MK_PTAG(cfi, vid)	GLD_MAKE_VTAG(VLAN_PRI_MAX, cfi, vid)
358 #define	GLD_MK_PMSK(pri)	(((pri) << VLAN_PRI_SHIFT) | ~VLAN_PRI_MASK)
359 #define	GLD_MK_VTAG(ptag, pri)	((ptag) & GLD_MK_PMSK(pri))
360 
361 /*
362  * Deconstruct a VTAG ...
363  */
364 #define	GLD_VTAG_TPID(vtag)	(((vtag) & VLAN_TPID_MASK) >> VLAN_TPID_SHIFT)
365 #define	GLD_VTAG_TCI(vtag)	(((vtag) & VLAN_TCI_MASK) >> VLAN_TCI_SHIFT)
366 
367 #define	GLD_VTAG_PRI(vtag)	(((vtag) & VLAN_PRI_MASK) >> VLAN_PRI_SHIFT)
368 #define	GLD_VTAG_CFI(vtag)	(((vtag) & VLAN_CFI_MASK) >> VLAN_CFI_SHIFT)
369 #define	GLD_VTAG_VID(vtag)	(((vtag) & VLAN_VID_MASK) >> VLAN_VID_SHIFT)
370 
371 #ifdef	__cplusplus
372 }
373 #endif
374 
375 #endif /* _SYS_GLD_H */
376