xref: /onnv-gate/usr/src/uts/common/sys/dld_impl.h (revision 4114:030ce6b4ca65)
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 /*
22*4114Sja97890  * Copyright 2007 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 	/*
1673147Sxc151355 	 * Native mode state.
1683147Sxc151355 	 */
1693147Sxc151355 	boolean_t		ds_native;
1703147Sxc151355 
1713147Sxc151355 	/*
1720Sstevel@tonic-gate 	 * IP polling is operational if this flag is set.
1730Sstevel@tonic-gate 	 */
1740Sstevel@tonic-gate 	boolean_t		ds_polling;
1751184Skrgopi 	boolean_t		ds_soft_ring;
1760Sstevel@tonic-gate 
1770Sstevel@tonic-gate 	/*
1783115Syl150051 	 * LSO is enabled if ds_lso is set.
1793115Syl150051 	 */
1803115Syl150051 	boolean_t		ds_lso;
1813115Syl150051 	uint64_t		ds_lso_max;
1823115Syl150051 
1833115Syl150051 	/*
1840Sstevel@tonic-gate 	 * State of DLPI user: may be active (regular network layer),
1850Sstevel@tonic-gate 	 * passive (snoop-like monitoring), or unknown (not yet
1860Sstevel@tonic-gate 	 * determined).
1870Sstevel@tonic-gate 	 */
1880Sstevel@tonic-gate 	dld_passivestate_t	ds_passivestate;
1890Sstevel@tonic-gate 
1900Sstevel@tonic-gate 	/*
191269Sericheng 	 * Dummy mblk used for flow-control.
192269Sericheng 	 */
193269Sericheng 	mblk_t			*ds_tx_flow_mp;
194269Sericheng 
195269Sericheng 	/*
196269Sericheng 	 * Internal transmit queue and its parameters.
1970Sstevel@tonic-gate 	 */
198269Sericheng 	kmutex_t		ds_tx_list_lock;
199269Sericheng 	mblk_t			*ds_tx_list_head;
200269Sericheng 	mblk_t			*ds_tx_list_tail;
201269Sericheng 	uint_t			ds_tx_cnt;
202269Sericheng 	uint_t			ds_tx_msgcnt;
203269Sericheng 	boolean_t		ds_tx_qbusy;
204269Sericheng 
205269Sericheng 	/*
206269Sericheng 	 * Number of threads currently in dld.  If there is a pending
2071353Sericheng 	 * request, it is placed in ds_pending_req and the operation
2081353Sericheng 	 * will finish when dld becomes single-threaded.
209269Sericheng 	 */
210269Sericheng 	kmutex_t		ds_thr_lock;
211269Sericheng 	uint_t			ds_thr;
2121353Sericheng 	uint_t			ds_pending_cnt;
2131353Sericheng 	mblk_t			*ds_pending_req;
2141353Sericheng 	task_func_t		*ds_pending_op;
2151353Sericheng 	kcondvar_t		ds_pending_cv;
2160Sstevel@tonic-gate } dld_str;
2170Sstevel@tonic-gate 
2180Sstevel@tonic-gate /*
2190Sstevel@tonic-gate  * dld_str.c module.
2200Sstevel@tonic-gate  */
2210Sstevel@tonic-gate 
2220Sstevel@tonic-gate extern void		dld_str_init(void);
2230Sstevel@tonic-gate extern int		dld_str_fini(void);
224269Sericheng extern dld_str_t	*dld_str_create(queue_t *, uint_t, major_t,
225269Sericheng     t_uscalar_t);
2260Sstevel@tonic-gate extern void		dld_str_destroy(dld_str_t *);
227269Sericheng extern int		dld_str_attach(dld_str_t *, t_uscalar_t);
2280Sstevel@tonic-gate extern void		dld_str_detach(dld_str_t *);
2290Sstevel@tonic-gate extern void		dld_str_rx_raw(void *, mac_resource_handle_t,
2302760Sdg199075     mblk_t *, mac_header_info_t *);
2310Sstevel@tonic-gate extern void		dld_str_rx_fastpath(void *, mac_resource_handle_t,
2322760Sdg199075     mblk_t *, mac_header_info_t *);
2330Sstevel@tonic-gate extern void		dld_str_rx_unitdata(void *, mac_resource_handle_t,
2342760Sdg199075     mblk_t *, mac_header_info_t *);
235269Sericheng extern void		dld_tx_flush(dld_str_t *);
236269Sericheng extern void		dld_tx_enqueue(dld_str_t *, mblk_t *, boolean_t);
2370Sstevel@tonic-gate extern void		dld_str_notify_ind(dld_str_t *);
238269Sericheng extern void		str_mdata_fastpath_put(dld_str_t *, mblk_t *);
2392760Sdg199075 extern void		dld_tx_single(dld_str_t *, mblk_t *);
240269Sericheng 
2410Sstevel@tonic-gate /*
2420Sstevel@tonic-gate  * dld_proto.c
2430Sstevel@tonic-gate  */
2440Sstevel@tonic-gate extern void		dld_proto(dld_str_t *, mblk_t *);
245269Sericheng extern void		dld_finish_pending_ops(dld_str_t *);
2460Sstevel@tonic-gate 
2470Sstevel@tonic-gate /*
2480Sstevel@tonic-gate  * Options: there should be a separate bit defined here for each
2490Sstevel@tonic-gate  *          DLD_PROP... defined in dld.h.
2500Sstevel@tonic-gate  */
251269Sericheng #define	DLD_OPT_NO_FASTPATH	0x00000001
252269Sericheng #define	DLD_OPT_NO_POLL		0x00000002
253269Sericheng #define	DLD_OPT_NO_ZEROCOPY	0x00000004
254*4114Sja97890 #define	DLD_OPT_NO_SOFTRING	0x00000008
2550Sstevel@tonic-gate 
2560Sstevel@tonic-gate extern uint32_t		dld_opt;
2570Sstevel@tonic-gate 
2580Sstevel@tonic-gate /*
2590Sstevel@tonic-gate  * Useful macros.
2600Sstevel@tonic-gate  */
2610Sstevel@tonic-gate 
2620Sstevel@tonic-gate #define	IMPLY(p, c)	(!(p) || (c))
2630Sstevel@tonic-gate 
264269Sericheng #define	DLD_ENTER(dsp) {					\
265269Sericheng 	mutex_enter(&dsp->ds_thr_lock);				\
266269Sericheng 	++dsp->ds_thr;						\
267269Sericheng 	ASSERT(dsp->ds_thr != 0);				\
268269Sericheng 	mutex_exit(&dsp->ds_thr_lock);				\
269269Sericheng }
270269Sericheng 
271269Sericheng #define	DLD_EXIT(dsp) {							\
272269Sericheng 	mutex_enter(&dsp->ds_thr_lock);					\
273269Sericheng 	ASSERT(dsp->ds_thr > 0);					\
2741353Sericheng 	if (--dsp->ds_thr == 0 && dsp->ds_pending_req != NULL)		\
275269Sericheng 		dld_finish_pending_ops(dsp);				\
276269Sericheng 	else								\
277269Sericheng 		mutex_exit(&dsp->ds_thr_lock);				\
278269Sericheng }
279269Sericheng 
2801353Sericheng #define	DLD_WAKEUP(dsp) {						\
2811353Sericheng 	mutex_enter(&dsp->ds_thr_lock);					\
2821353Sericheng 	ASSERT(dsp->ds_pending_cnt > 0);				\
2831353Sericheng 	if (--dsp->ds_pending_cnt == 0)					\
2841353Sericheng 		cv_signal(&dsp->ds_pending_cv);				\
2851353Sericheng 	mutex_exit(&dsp->ds_thr_lock);					\
2861353Sericheng }
2871353Sericheng 
288269Sericheng #ifdef DEBUG
289269Sericheng #define	DLD_DBG		cmn_err
290269Sericheng #else
291269Sericheng #define	DLD_DBG		if (0) cmn_err
292269Sericheng #endif
293269Sericheng 
2940Sstevel@tonic-gate #ifdef	__cplusplus
2950Sstevel@tonic-gate }
2960Sstevel@tonic-gate #endif
2970Sstevel@tonic-gate 
2980Sstevel@tonic-gate #endif	/* _SYS_DLD_IMPL_H */
299