xref: /illumos-gate/usr/src/uts/common/sys/dld_impl.h (revision 605445d5)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5c0192a57Sericheng  * Common Development and Distribution License (the "License").
6c0192a57Sericheng  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
226a0b2badSericheng  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef	_SYS_DLD_IMPL_H
277c478bd9Sstevel@tonic-gate #define	_SYS_DLD_IMPL_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #include <sys/types.h>
327c478bd9Sstevel@tonic-gate #include <sys/ethernet.h>
337c478bd9Sstevel@tonic-gate #include <sys/stream.h>
347c478bd9Sstevel@tonic-gate #include <sys/dlpi.h>
357c478bd9Sstevel@tonic-gate #include <sys/mac.h>
367c478bd9Sstevel@tonic-gate #include <sys/dls.h>
377c478bd9Sstevel@tonic-gate #include <sys/dld.h>
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
407c478bd9Sstevel@tonic-gate extern "C" {
417c478bd9Sstevel@tonic-gate #endif
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate #define	DLD_CONTROL	0x00000001
447c478bd9Sstevel@tonic-gate #define	DLD_DLPI	0x00000002
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate typedef enum {
477c478bd9Sstevel@tonic-gate 	DLD_UNITDATA,
487c478bd9Sstevel@tonic-gate 	DLD_FASTPATH,
497c478bd9Sstevel@tonic-gate 	DLD_RAW
507c478bd9Sstevel@tonic-gate } dld_str_mode_t;
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate typedef enum {
537c478bd9Sstevel@tonic-gate 	DLD_UNINITIALIZED,
547c478bd9Sstevel@tonic-gate 	DLD_PASSIVE,
557c478bd9Sstevel@tonic-gate 	DLD_ACTIVE
567c478bd9Sstevel@tonic-gate } dld_passivestate_t;
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate typedef struct dld_str	dld_str_t;
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate /*
617c478bd9Sstevel@tonic-gate  * dld_str_t object definition.
627c478bd9Sstevel@tonic-gate  */
637c478bd9Sstevel@tonic-gate struct dld_str {
647c478bd9Sstevel@tonic-gate 	/*
65210db224Sericheng 	 * Major number of the device
66210db224Sericheng 	 */
67210db224Sericheng 	major_t			ds_major;
68210db224Sericheng 
69210db224Sericheng 	/*
707c478bd9Sstevel@tonic-gate 	 * Ephemeral minor number for the object.
717c478bd9Sstevel@tonic-gate 	 */
727c478bd9Sstevel@tonic-gate 	minor_t			ds_minor;
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate 	/*
75c0192a57Sericheng 	 * PPA number this stream is attached to.
76c0192a57Sericheng 	 */
77c0192a57Sericheng 	t_uscalar_t		ds_ppa;
78c0192a57Sericheng 
79c0192a57Sericheng 	/*
807c478bd9Sstevel@tonic-gate 	 * Read/write queues for the stream which the object represents.
817c478bd9Sstevel@tonic-gate 	 */
827c478bd9Sstevel@tonic-gate 	queue_t			*ds_rq;
837c478bd9Sstevel@tonic-gate 	queue_t			*ds_wq;
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate 	/*
86210db224Sericheng 	 * Lock to protect this structure.
87210db224Sericheng 	 */
88210db224Sericheng 	krwlock_t		ds_lock;
89210db224Sericheng 
90210db224Sericheng 	/*
917c478bd9Sstevel@tonic-gate 	 * Stream is open to DLD_CONTROL (control node) or
927c478bd9Sstevel@tonic-gate 	 * DLD_DLPI (DLS provider) node.
937c478bd9Sstevel@tonic-gate 	 */
947c478bd9Sstevel@tonic-gate 	uint_t			ds_type;
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate 	/*
977c478bd9Sstevel@tonic-gate 	 * The following fields are only used for DLD_DLPI type objects.
987c478bd9Sstevel@tonic-gate 	 */
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate 	/*
1017c478bd9Sstevel@tonic-gate 	 * Current DLPI state.
1027c478bd9Sstevel@tonic-gate 	 */
1037c478bd9Sstevel@tonic-gate 	t_uscalar_t		ds_dlstate;
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate 	/*
106210db224Sericheng 	 * DLPI style
107210db224Sericheng 	 */
108210db224Sericheng 	t_uscalar_t		ds_style;
109210db224Sericheng 
110210db224Sericheng 	/*
1117c478bd9Sstevel@tonic-gate 	 * Currently bound DLSAP.
1127c478bd9Sstevel@tonic-gate 	 */
1137c478bd9Sstevel@tonic-gate 	uint16_t		ds_sap;
1147c478bd9Sstevel@tonic-gate 
1157c478bd9Sstevel@tonic-gate 	/*
1167c478bd9Sstevel@tonic-gate 	 * Handle of the data-link channel that is used by this object.
1177c478bd9Sstevel@tonic-gate 	 */
1187c478bd9Sstevel@tonic-gate 	dls_channel_t		ds_dc;
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate 	/*
1217c478bd9Sstevel@tonic-gate 	 * Handle of the MAC that is used by the data-link interface.
1227c478bd9Sstevel@tonic-gate 	 */
1237c478bd9Sstevel@tonic-gate 	mac_handle_t		ds_mh;
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate 	/*
1267c478bd9Sstevel@tonic-gate 	 * VLAN identifier of the data-link interface.
1277c478bd9Sstevel@tonic-gate 	 */
1287c478bd9Sstevel@tonic-gate 	uint16_t		ds_vid;
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate 	/*
1317c478bd9Sstevel@tonic-gate 	 * Promiscuity level information.
1327c478bd9Sstevel@tonic-gate 	 */
1337c478bd9Sstevel@tonic-gate 	uint32_t		ds_promisc;
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate 	/*
1367c478bd9Sstevel@tonic-gate 	 * Immutable information of the MAC which the channel is using.
1377c478bd9Sstevel@tonic-gate 	 */
1387c478bd9Sstevel@tonic-gate 	const mac_info_t	*ds_mip;
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate 	/*
1417c478bd9Sstevel@tonic-gate 	 * Current packet priority.
1427c478bd9Sstevel@tonic-gate 	 */
1437c478bd9Sstevel@tonic-gate 	uint_t			ds_pri;
1447c478bd9Sstevel@tonic-gate 
1457c478bd9Sstevel@tonic-gate 	/*
1467c478bd9Sstevel@tonic-gate 	 * Handle of our MAC notification callback.
1477c478bd9Sstevel@tonic-gate 	 */
1487c478bd9Sstevel@tonic-gate 	mac_notify_handle_t	ds_mnh;
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate 	/*
1517c478bd9Sstevel@tonic-gate 	 * Set of enabled DL_NOTE... notifications. (See dlpi.h).
1527c478bd9Sstevel@tonic-gate 	 */
1537c478bd9Sstevel@tonic-gate 	uint32_t		ds_notifications;
1547c478bd9Sstevel@tonic-gate 
1557c478bd9Sstevel@tonic-gate 	/*
1567c478bd9Sstevel@tonic-gate 	 * Cached MAC unicast addresses.
1577c478bd9Sstevel@tonic-gate 	 */
158ba2e4443Sseb 	uint8_t			ds_fact_addr[MAXMACADDRLEN];
159ba2e4443Sseb 	uint8_t			ds_curr_addr[MAXMACADDRLEN];
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate 	/*
1627c478bd9Sstevel@tonic-gate 	 * Mode: unitdata, fast-path or raw.
1637c478bd9Sstevel@tonic-gate 	 */
1647c478bd9Sstevel@tonic-gate 	dld_str_mode_t		ds_mode;
1657c478bd9Sstevel@tonic-gate 
1667c478bd9Sstevel@tonic-gate 	/*
1677c478bd9Sstevel@tonic-gate 	 * IP polling is operational if this flag is set.
1687c478bd9Sstevel@tonic-gate 	 */
1697c478bd9Sstevel@tonic-gate 	boolean_t		ds_polling;
1704b46d1efSkrgopi 	boolean_t		ds_soft_ring;
1717c478bd9Sstevel@tonic-gate 
1727c478bd9Sstevel@tonic-gate 	/*
1737c478bd9Sstevel@tonic-gate 	 * State of DLPI user: may be active (regular network layer),
1747c478bd9Sstevel@tonic-gate 	 * passive (snoop-like monitoring), or unknown (not yet
1757c478bd9Sstevel@tonic-gate 	 * determined).
1767c478bd9Sstevel@tonic-gate 	 */
1777c478bd9Sstevel@tonic-gate 	dld_passivestate_t	ds_passivestate;
1787c478bd9Sstevel@tonic-gate 
1797c478bd9Sstevel@tonic-gate 	/*
180210db224Sericheng 	 * Dummy mblk used for flow-control.
1817c478bd9Sstevel@tonic-gate 	 */
182210db224Sericheng 	mblk_t			*ds_tx_flow_mp;
183210db224Sericheng 
184210db224Sericheng 	/*
185210db224Sericheng 	 * Internal transmit queue and its parameters.
186210db224Sericheng 	 */
187210db224Sericheng 	kmutex_t		ds_tx_list_lock;
188210db224Sericheng 	mblk_t			*ds_tx_list_head;
189210db224Sericheng 	mblk_t			*ds_tx_list_tail;
190210db224Sericheng 	uint_t			ds_tx_cnt;
191210db224Sericheng 	uint_t			ds_tx_msgcnt;
192210db224Sericheng 	boolean_t		ds_tx_qbusy;
193210db224Sericheng 
194210db224Sericheng 	/*
195210db224Sericheng 	 * Number of threads currently in dld.  If there is a pending
1966a0b2badSericheng 	 * request, it is placed in ds_pending_req and the operation
1976a0b2badSericheng 	 * will finish when dld becomes single-threaded.
198210db224Sericheng 	 */
199210db224Sericheng 	kmutex_t		ds_thr_lock;
200210db224Sericheng 	uint_t			ds_thr;
2016a0b2badSericheng 	uint_t			ds_pending_cnt;
2026a0b2badSericheng 	mblk_t			*ds_pending_req;
2036a0b2badSericheng 	task_func_t		*ds_pending_op;
2046a0b2badSericheng 	kcondvar_t		ds_pending_cv;
2057c478bd9Sstevel@tonic-gate } dld_str;
2067c478bd9Sstevel@tonic-gate 
2077c478bd9Sstevel@tonic-gate /*
2087c478bd9Sstevel@tonic-gate  * dld_str.c module.
2097c478bd9Sstevel@tonic-gate  */
2107c478bd9Sstevel@tonic-gate 
2117c478bd9Sstevel@tonic-gate extern void		dld_str_init(void);
2127c478bd9Sstevel@tonic-gate extern int		dld_str_fini(void);
213210db224Sericheng extern dld_str_t	*dld_str_create(queue_t *, uint_t, major_t,
214210db224Sericheng     t_uscalar_t);
2157c478bd9Sstevel@tonic-gate extern void		dld_str_destroy(dld_str_t *);
216210db224Sericheng extern int		dld_str_attach(dld_str_t *, t_uscalar_t);
2177c478bd9Sstevel@tonic-gate extern void		dld_str_detach(dld_str_t *);
2187c478bd9Sstevel@tonic-gate extern void		dld_str_rx_raw(void *, mac_resource_handle_t,
219*605445d5Sdg199075     mblk_t *, mac_header_info_t *);
2207c478bd9Sstevel@tonic-gate extern void		dld_str_rx_fastpath(void *, mac_resource_handle_t,
221*605445d5Sdg199075     mblk_t *, mac_header_info_t *);
2227c478bd9Sstevel@tonic-gate extern void		dld_str_rx_unitdata(void *, mac_resource_handle_t,
223*605445d5Sdg199075     mblk_t *, mac_header_info_t *);
224210db224Sericheng extern void		dld_tx_flush(dld_str_t *);
225210db224Sericheng extern void		dld_tx_enqueue(dld_str_t *, mblk_t *, boolean_t);
2267c478bd9Sstevel@tonic-gate extern void		dld_str_notify_ind(dld_str_t *);
227210db224Sericheng extern void		str_mdata_fastpath_put(dld_str_t *, mblk_t *);
228*605445d5Sdg199075 extern void		dld_tx_single(dld_str_t *, mblk_t *);
229210db224Sericheng 
2307c478bd9Sstevel@tonic-gate /*
2317c478bd9Sstevel@tonic-gate  * dld_proto.c
2327c478bd9Sstevel@tonic-gate  */
2337c478bd9Sstevel@tonic-gate extern void		dld_proto(dld_str_t *, mblk_t *);
234210db224Sericheng extern void		dld_finish_pending_ops(dld_str_t *);
2357c478bd9Sstevel@tonic-gate 
2367c478bd9Sstevel@tonic-gate /*
2377c478bd9Sstevel@tonic-gate  * Options: there should be a separate bit defined here for each
2387c478bd9Sstevel@tonic-gate  *          DLD_PROP... defined in dld.h.
2397c478bd9Sstevel@tonic-gate  */
240210db224Sericheng #define	DLD_OPT_NO_FASTPATH	0x00000001
241210db224Sericheng #define	DLD_OPT_NO_POLL		0x00000002
242210db224Sericheng #define	DLD_OPT_NO_ZEROCOPY	0x00000004
2437c478bd9Sstevel@tonic-gate 
2447c478bd9Sstevel@tonic-gate extern uint32_t		dld_opt;
2457c478bd9Sstevel@tonic-gate 
2467c478bd9Sstevel@tonic-gate /*
2477c478bd9Sstevel@tonic-gate  * Useful macros.
2487c478bd9Sstevel@tonic-gate  */
2497c478bd9Sstevel@tonic-gate 
2507c478bd9Sstevel@tonic-gate #define	IMPLY(p, c)	(!(p) || (c))
2517c478bd9Sstevel@tonic-gate 
252210db224Sericheng #define	DLD_ENTER(dsp) {					\
253210db224Sericheng 	mutex_enter(&dsp->ds_thr_lock);				\
254210db224Sericheng 	++dsp->ds_thr;						\
255210db224Sericheng 	ASSERT(dsp->ds_thr != 0);				\
256210db224Sericheng 	mutex_exit(&dsp->ds_thr_lock);				\
257210db224Sericheng }
258210db224Sericheng 
259210db224Sericheng #define	DLD_EXIT(dsp) {							\
260210db224Sericheng 	mutex_enter(&dsp->ds_thr_lock);					\
261210db224Sericheng 	ASSERT(dsp->ds_thr > 0);					\
2626a0b2badSericheng 	if (--dsp->ds_thr == 0 && dsp->ds_pending_req != NULL)		\
263210db224Sericheng 		dld_finish_pending_ops(dsp);				\
264210db224Sericheng 	else								\
265210db224Sericheng 		mutex_exit(&dsp->ds_thr_lock);				\
266210db224Sericheng }
267210db224Sericheng 
2686a0b2badSericheng #define	DLD_WAKEUP(dsp) {						\
2696a0b2badSericheng 	mutex_enter(&dsp->ds_thr_lock);					\
2706a0b2badSericheng 	ASSERT(dsp->ds_pending_cnt > 0);				\
2716a0b2badSericheng 	if (--dsp->ds_pending_cnt == 0)					\
2726a0b2badSericheng 		cv_signal(&dsp->ds_pending_cv);				\
2736a0b2badSericheng 	mutex_exit(&dsp->ds_thr_lock);					\
2746a0b2badSericheng }
2756a0b2badSericheng 
276210db224Sericheng #ifdef DEBUG
277210db224Sericheng #define	DLD_DBG		cmn_err
278210db224Sericheng #else
279210db224Sericheng #define	DLD_DBG		if (0) cmn_err
280210db224Sericheng #endif
281210db224Sericheng 
2827c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
2837c478bd9Sstevel@tonic-gate }
2847c478bd9Sstevel@tonic-gate #endif
2857c478bd9Sstevel@tonic-gate 
2867c478bd9Sstevel@tonic-gate #endif	/* _SYS_DLD_IMPL_H */
287