xref: /onnv-gate/usr/src/uts/common/sys/dld_impl.h (revision 2760:38f12e308f6d)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
51804Sericheng  * Common Development and Distribution License (the "License").
61804Sericheng  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
221353Sericheng  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #ifndef	_SYS_DLD_IMPL_H
270Sstevel@tonic-gate #define	_SYS_DLD_IMPL_H
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
300Sstevel@tonic-gate 
310Sstevel@tonic-gate #include <sys/types.h>
320Sstevel@tonic-gate #include <sys/ethernet.h>
330Sstevel@tonic-gate #include <sys/stream.h>
340Sstevel@tonic-gate #include <sys/dlpi.h>
350Sstevel@tonic-gate #include <sys/mac.h>
360Sstevel@tonic-gate #include <sys/dls.h>
370Sstevel@tonic-gate #include <sys/dld.h>
380Sstevel@tonic-gate 
390Sstevel@tonic-gate #ifdef	__cplusplus
400Sstevel@tonic-gate extern "C" {
410Sstevel@tonic-gate #endif
420Sstevel@tonic-gate 
430Sstevel@tonic-gate #define	DLD_CONTROL	0x00000001
440Sstevel@tonic-gate #define	DLD_DLPI	0x00000002
450Sstevel@tonic-gate 
460Sstevel@tonic-gate typedef enum {
470Sstevel@tonic-gate 	DLD_UNITDATA,
480Sstevel@tonic-gate 	DLD_FASTPATH,
490Sstevel@tonic-gate 	DLD_RAW
500Sstevel@tonic-gate } dld_str_mode_t;
510Sstevel@tonic-gate 
520Sstevel@tonic-gate typedef enum {
530Sstevel@tonic-gate 	DLD_UNINITIALIZED,
540Sstevel@tonic-gate 	DLD_PASSIVE,
550Sstevel@tonic-gate 	DLD_ACTIVE
560Sstevel@tonic-gate } dld_passivestate_t;
570Sstevel@tonic-gate 
580Sstevel@tonic-gate typedef struct dld_str	dld_str_t;
590Sstevel@tonic-gate 
600Sstevel@tonic-gate /*
610Sstevel@tonic-gate  * dld_str_t object definition.
620Sstevel@tonic-gate  */
630Sstevel@tonic-gate struct dld_str {
640Sstevel@tonic-gate 	/*
65269Sericheng 	 * Major number of the device
66269Sericheng 	 */
67269Sericheng 	major_t			ds_major;
68269Sericheng 
69269Sericheng 	/*
700Sstevel@tonic-gate 	 * Ephemeral minor number for the object.
710Sstevel@tonic-gate 	 */
720Sstevel@tonic-gate 	minor_t			ds_minor;
730Sstevel@tonic-gate 
740Sstevel@tonic-gate 	/*
751804Sericheng 	 * PPA number this stream is attached to.
761804Sericheng 	 */
771804Sericheng 	t_uscalar_t		ds_ppa;
781804Sericheng 
791804Sericheng 	/*
800Sstevel@tonic-gate 	 * Read/write queues for the stream which the object represents.
810Sstevel@tonic-gate 	 */
820Sstevel@tonic-gate 	queue_t			*ds_rq;
830Sstevel@tonic-gate 	queue_t			*ds_wq;
840Sstevel@tonic-gate 
850Sstevel@tonic-gate 	/*
86269Sericheng 	 * Lock to protect this structure.
87269Sericheng 	 */
88269Sericheng 	krwlock_t		ds_lock;
89269Sericheng 
90269Sericheng 	/*
910Sstevel@tonic-gate 	 * Stream is open to DLD_CONTROL (control node) or
920Sstevel@tonic-gate 	 * DLD_DLPI (DLS provider) node.
930Sstevel@tonic-gate 	 */
940Sstevel@tonic-gate 	uint_t			ds_type;
950Sstevel@tonic-gate 
960Sstevel@tonic-gate 	/*
970Sstevel@tonic-gate 	 * The following fields are only used for DLD_DLPI type objects.
980Sstevel@tonic-gate 	 */
990Sstevel@tonic-gate 
1000Sstevel@tonic-gate 	/*
1010Sstevel@tonic-gate 	 * Current DLPI state.
1020Sstevel@tonic-gate 	 */
1030Sstevel@tonic-gate 	t_uscalar_t		ds_dlstate;
1040Sstevel@tonic-gate 
1050Sstevel@tonic-gate 	/*
106269Sericheng 	 * DLPI style
107269Sericheng 	 */
108269Sericheng 	t_uscalar_t		ds_style;
109269Sericheng 
110269Sericheng 	/*
1110Sstevel@tonic-gate 	 * Currently bound DLSAP.
1120Sstevel@tonic-gate 	 */
1130Sstevel@tonic-gate 	uint16_t		ds_sap;
1140Sstevel@tonic-gate 
1150Sstevel@tonic-gate 	/*
1160Sstevel@tonic-gate 	 * Handle of the data-link channel that is used by this object.
1170Sstevel@tonic-gate 	 */
1180Sstevel@tonic-gate 	dls_channel_t		ds_dc;
1190Sstevel@tonic-gate 
1200Sstevel@tonic-gate 	/*
1210Sstevel@tonic-gate 	 * Handle of the MAC that is used by the data-link interface.
1220Sstevel@tonic-gate 	 */
1230Sstevel@tonic-gate 	mac_handle_t		ds_mh;
1240Sstevel@tonic-gate 
1250Sstevel@tonic-gate 	/*
1260Sstevel@tonic-gate 	 * VLAN identifier of the data-link interface.
1270Sstevel@tonic-gate 	 */
1280Sstevel@tonic-gate 	uint16_t		ds_vid;
1290Sstevel@tonic-gate 
1300Sstevel@tonic-gate 	/*
1310Sstevel@tonic-gate 	 * Promiscuity level information.
1320Sstevel@tonic-gate 	 */
1330Sstevel@tonic-gate 	uint32_t		ds_promisc;
1340Sstevel@tonic-gate 
1350Sstevel@tonic-gate 	/*
1360Sstevel@tonic-gate 	 * Immutable information of the MAC which the channel is using.
1370Sstevel@tonic-gate 	 */
1380Sstevel@tonic-gate 	const mac_info_t	*ds_mip;
1390Sstevel@tonic-gate 
1400Sstevel@tonic-gate 	/*
1410Sstevel@tonic-gate 	 * Current packet priority.
1420Sstevel@tonic-gate 	 */
1430Sstevel@tonic-gate 	uint_t			ds_pri;
1440Sstevel@tonic-gate 
1450Sstevel@tonic-gate 	/*
1460Sstevel@tonic-gate 	 * Handle of our MAC notification callback.
1470Sstevel@tonic-gate 	 */
1480Sstevel@tonic-gate 	mac_notify_handle_t	ds_mnh;
1490Sstevel@tonic-gate 
1500Sstevel@tonic-gate 	/*
1510Sstevel@tonic-gate 	 * Set of enabled DL_NOTE... notifications. (See dlpi.h).
1520Sstevel@tonic-gate 	 */
1530Sstevel@tonic-gate 	uint32_t		ds_notifications;
1540Sstevel@tonic-gate 
1550Sstevel@tonic-gate 	/*
1560Sstevel@tonic-gate 	 * Cached MAC unicast addresses.
1570Sstevel@tonic-gate 	 */
1582311Sseb 	uint8_t			ds_fact_addr[MAXMACADDRLEN];
1592311Sseb 	uint8_t			ds_curr_addr[MAXMACADDRLEN];
1600Sstevel@tonic-gate 
1610Sstevel@tonic-gate 	/*
1620Sstevel@tonic-gate 	 * Mode: unitdata, fast-path or raw.
1630Sstevel@tonic-gate 	 */
1640Sstevel@tonic-gate 	dld_str_mode_t		ds_mode;
1650Sstevel@tonic-gate 
1660Sstevel@tonic-gate 	/*
1670Sstevel@tonic-gate 	 * IP polling is operational if this flag is set.
1680Sstevel@tonic-gate 	 */
1690Sstevel@tonic-gate 	boolean_t		ds_polling;
1701184Skrgopi 	boolean_t		ds_soft_ring;
1710Sstevel@tonic-gate 
1720Sstevel@tonic-gate 	/*
1730Sstevel@tonic-gate 	 * State of DLPI user: may be active (regular network layer),
1740Sstevel@tonic-gate 	 * passive (snoop-like monitoring), or unknown (not yet
1750Sstevel@tonic-gate 	 * determined).
1760Sstevel@tonic-gate 	 */
1770Sstevel@tonic-gate 	dld_passivestate_t	ds_passivestate;
1780Sstevel@tonic-gate 
1790Sstevel@tonic-gate 	/*
180269Sericheng 	 * Dummy mblk used for flow-control.
181269Sericheng 	 */
182269Sericheng 	mblk_t			*ds_tx_flow_mp;
183269Sericheng 
184269Sericheng 	/*
185269Sericheng 	 * Internal transmit queue and its parameters.
1860Sstevel@tonic-gate 	 */
187269Sericheng 	kmutex_t		ds_tx_list_lock;
188269Sericheng 	mblk_t			*ds_tx_list_head;
189269Sericheng 	mblk_t			*ds_tx_list_tail;
190269Sericheng 	uint_t			ds_tx_cnt;
191269Sericheng 	uint_t			ds_tx_msgcnt;
192269Sericheng 	boolean_t		ds_tx_qbusy;
193269Sericheng 
194269Sericheng 	/*
195269Sericheng 	 * Number of threads currently in dld.  If there is a pending
1961353Sericheng 	 * request, it is placed in ds_pending_req and the operation
1971353Sericheng 	 * will finish when dld becomes single-threaded.
198269Sericheng 	 */
199269Sericheng 	kmutex_t		ds_thr_lock;
200269Sericheng 	uint_t			ds_thr;
2011353Sericheng 	uint_t			ds_pending_cnt;
2021353Sericheng 	mblk_t			*ds_pending_req;
2031353Sericheng 	task_func_t		*ds_pending_op;
2041353Sericheng 	kcondvar_t		ds_pending_cv;
2050Sstevel@tonic-gate } dld_str;
2060Sstevel@tonic-gate 
2070Sstevel@tonic-gate /*
2080Sstevel@tonic-gate  * dld_str.c module.
2090Sstevel@tonic-gate  */
2100Sstevel@tonic-gate 
2110Sstevel@tonic-gate extern void		dld_str_init(void);
2120Sstevel@tonic-gate extern int		dld_str_fini(void);
213269Sericheng extern dld_str_t	*dld_str_create(queue_t *, uint_t, major_t,
214269Sericheng     t_uscalar_t);
2150Sstevel@tonic-gate extern void		dld_str_destroy(dld_str_t *);
216269Sericheng extern int		dld_str_attach(dld_str_t *, t_uscalar_t);
2170Sstevel@tonic-gate extern void		dld_str_detach(dld_str_t *);
2180Sstevel@tonic-gate extern void		dld_str_rx_raw(void *, mac_resource_handle_t,
219*2760Sdg199075     mblk_t *, mac_header_info_t *);
2200Sstevel@tonic-gate extern void		dld_str_rx_fastpath(void *, mac_resource_handle_t,
221*2760Sdg199075     mblk_t *, mac_header_info_t *);
2220Sstevel@tonic-gate extern void		dld_str_rx_unitdata(void *, mac_resource_handle_t,
223*2760Sdg199075     mblk_t *, mac_header_info_t *);
224269Sericheng extern void		dld_tx_flush(dld_str_t *);
225269Sericheng extern void		dld_tx_enqueue(dld_str_t *, mblk_t *, boolean_t);
2260Sstevel@tonic-gate extern void		dld_str_notify_ind(dld_str_t *);
227269Sericheng extern void		str_mdata_fastpath_put(dld_str_t *, mblk_t *);
228*2760Sdg199075 extern void		dld_tx_single(dld_str_t *, mblk_t *);
229269Sericheng 
2300Sstevel@tonic-gate /*
2310Sstevel@tonic-gate  * dld_proto.c
2320Sstevel@tonic-gate  */
2330Sstevel@tonic-gate extern void		dld_proto(dld_str_t *, mblk_t *);
234269Sericheng extern void		dld_finish_pending_ops(dld_str_t *);
2350Sstevel@tonic-gate 
2360Sstevel@tonic-gate /*
2370Sstevel@tonic-gate  * Options: there should be a separate bit defined here for each
2380Sstevel@tonic-gate  *          DLD_PROP... defined in dld.h.
2390Sstevel@tonic-gate  */
240269Sericheng #define	DLD_OPT_NO_FASTPATH	0x00000001
241269Sericheng #define	DLD_OPT_NO_POLL		0x00000002
242269Sericheng #define	DLD_OPT_NO_ZEROCOPY	0x00000004
2430Sstevel@tonic-gate 
2440Sstevel@tonic-gate extern uint32_t		dld_opt;
2450Sstevel@tonic-gate 
2460Sstevel@tonic-gate /*
2470Sstevel@tonic-gate  * Useful macros.
2480Sstevel@tonic-gate  */
2490Sstevel@tonic-gate 
2500Sstevel@tonic-gate #define	IMPLY(p, c)	(!(p) || (c))
2510Sstevel@tonic-gate 
252269Sericheng #define	DLD_ENTER(dsp) {					\
253269Sericheng 	mutex_enter(&dsp->ds_thr_lock);				\
254269Sericheng 	++dsp->ds_thr;						\
255269Sericheng 	ASSERT(dsp->ds_thr != 0);				\
256269Sericheng 	mutex_exit(&dsp->ds_thr_lock);				\
257269Sericheng }
258269Sericheng 
259269Sericheng #define	DLD_EXIT(dsp) {							\
260269Sericheng 	mutex_enter(&dsp->ds_thr_lock);					\
261269Sericheng 	ASSERT(dsp->ds_thr > 0);					\
2621353Sericheng 	if (--dsp->ds_thr == 0 && dsp->ds_pending_req != NULL)		\
263269Sericheng 		dld_finish_pending_ops(dsp);				\
264269Sericheng 	else								\
265269Sericheng 		mutex_exit(&dsp->ds_thr_lock);				\
266269Sericheng }
267269Sericheng 
2681353Sericheng #define	DLD_WAKEUP(dsp) {						\
2691353Sericheng 	mutex_enter(&dsp->ds_thr_lock);					\
2701353Sericheng 	ASSERT(dsp->ds_pending_cnt > 0);				\
2711353Sericheng 	if (--dsp->ds_pending_cnt == 0)					\
2721353Sericheng 		cv_signal(&dsp->ds_pending_cv);				\
2731353Sericheng 	mutex_exit(&dsp->ds_thr_lock);					\
2741353Sericheng }
2751353Sericheng 
276269Sericheng #ifdef DEBUG
277269Sericheng #define	DLD_DBG		cmn_err
278269Sericheng #else
279269Sericheng #define	DLD_DBG		if (0) cmn_err
280269Sericheng #endif
281269Sericheng 
2820Sstevel@tonic-gate #ifdef	__cplusplus
2830Sstevel@tonic-gate }
2840Sstevel@tonic-gate #endif
2850Sstevel@tonic-gate 
2860Sstevel@tonic-gate #endif	/* _SYS_DLD_IMPL_H */
287