xref: /onnv-gate/usr/src/uts/common/sys/dld_impl.h (revision 7408:eff7960d93cd)
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 /*
225895Syz147064  * Copyright 2008 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 #include <sys/types.h>
305895Syz147064 #include <sys/conf.h>
310Sstevel@tonic-gate #include <sys/ethernet.h>
320Sstevel@tonic-gate #include <sys/stream.h>
330Sstevel@tonic-gate #include <sys/dlpi.h>
340Sstevel@tonic-gate #include <sys/mac.h>
350Sstevel@tonic-gate #include <sys/dls.h>
360Sstevel@tonic-gate #include <sys/dld.h>
370Sstevel@tonic-gate 
380Sstevel@tonic-gate #ifdef	__cplusplus
390Sstevel@tonic-gate extern "C" {
400Sstevel@tonic-gate #endif
410Sstevel@tonic-gate 
42*7408SSebastien.Roy@Sun.COM #define	DLD_CONTROL_MINOR_NAME	"ctl"
43*7408SSebastien.Roy@Sun.COM #define	DLD_CONTROL_MINOR	0
44*7408SSebastien.Roy@Sun.COM 
450Sstevel@tonic-gate #define	DLD_CONTROL	0x00000001
460Sstevel@tonic-gate #define	DLD_DLPI	0x00000002
470Sstevel@tonic-gate 
480Sstevel@tonic-gate typedef enum {
490Sstevel@tonic-gate 	DLD_UNITDATA,
500Sstevel@tonic-gate 	DLD_FASTPATH,
510Sstevel@tonic-gate 	DLD_RAW
520Sstevel@tonic-gate } dld_str_mode_t;
530Sstevel@tonic-gate 
540Sstevel@tonic-gate typedef enum {
550Sstevel@tonic-gate 	DLD_UNINITIALIZED,
560Sstevel@tonic-gate 	DLD_PASSIVE,
570Sstevel@tonic-gate 	DLD_ACTIVE
580Sstevel@tonic-gate } dld_passivestate_t;
590Sstevel@tonic-gate 
600Sstevel@tonic-gate typedef struct dld_str	dld_str_t;
615895Syz147064 typedef void		(*dld_tx_t)(struct dld_str *, mblk_t *);
620Sstevel@tonic-gate 
630Sstevel@tonic-gate /*
640Sstevel@tonic-gate  * dld_str_t object definition.
650Sstevel@tonic-gate  */
660Sstevel@tonic-gate struct dld_str {
670Sstevel@tonic-gate 	/*
68269Sericheng 	 * Major number of the device
69269Sericheng 	 */
70269Sericheng 	major_t			ds_major;
71269Sericheng 
72269Sericheng 	/*
730Sstevel@tonic-gate 	 * Ephemeral minor number for the object.
740Sstevel@tonic-gate 	 */
750Sstevel@tonic-gate 	minor_t			ds_minor;
760Sstevel@tonic-gate 
770Sstevel@tonic-gate 	/*
780Sstevel@tonic-gate 	 * Read/write queues for the stream which the object represents.
790Sstevel@tonic-gate 	 */
800Sstevel@tonic-gate 	queue_t			*ds_rq;
810Sstevel@tonic-gate 	queue_t			*ds_wq;
820Sstevel@tonic-gate 
830Sstevel@tonic-gate 	/*
84269Sericheng 	 * Lock to protect this structure.
85269Sericheng 	 */
86269Sericheng 	krwlock_t		ds_lock;
87269Sericheng 
88269Sericheng 	/*
890Sstevel@tonic-gate 	 * Stream is open to DLD_CONTROL (control node) or
900Sstevel@tonic-gate 	 * DLD_DLPI (DLS provider) node.
910Sstevel@tonic-gate 	 */
920Sstevel@tonic-gate 	uint_t			ds_type;
930Sstevel@tonic-gate 
940Sstevel@tonic-gate 	/*
950Sstevel@tonic-gate 	 * The following fields are only used for DLD_DLPI type objects.
960Sstevel@tonic-gate 	 */
970Sstevel@tonic-gate 
980Sstevel@tonic-gate 	/*
990Sstevel@tonic-gate 	 * Current DLPI state.
1000Sstevel@tonic-gate 	 */
1010Sstevel@tonic-gate 	t_uscalar_t		ds_dlstate;
1020Sstevel@tonic-gate 
1030Sstevel@tonic-gate 	/*
104269Sericheng 	 * DLPI style
105269Sericheng 	 */
106269Sericheng 	t_uscalar_t		ds_style;
107269Sericheng 
108269Sericheng 	/*
1090Sstevel@tonic-gate 	 * Currently bound DLSAP.
1100Sstevel@tonic-gate 	 */
1110Sstevel@tonic-gate 	uint16_t		ds_sap;
1120Sstevel@tonic-gate 
1130Sstevel@tonic-gate 	/*
1140Sstevel@tonic-gate 	 * Handle of the data-link channel that is used by this object.
1150Sstevel@tonic-gate 	 */
1160Sstevel@tonic-gate 	dls_channel_t		ds_dc;
1170Sstevel@tonic-gate 
1180Sstevel@tonic-gate 	/*
1190Sstevel@tonic-gate 	 * Handle of the MAC that is used by the data-link interface.
1200Sstevel@tonic-gate 	 */
1210Sstevel@tonic-gate 	mac_handle_t		ds_mh;
1220Sstevel@tonic-gate 
1230Sstevel@tonic-gate 	/*
1240Sstevel@tonic-gate 	 * VLAN identifier of the data-link interface.
1250Sstevel@tonic-gate 	 */
1260Sstevel@tonic-gate 	uint16_t		ds_vid;
1270Sstevel@tonic-gate 
1280Sstevel@tonic-gate 	/*
1290Sstevel@tonic-gate 	 * Promiscuity level information.
1300Sstevel@tonic-gate 	 */
1310Sstevel@tonic-gate 	uint32_t		ds_promisc;
1320Sstevel@tonic-gate 
1330Sstevel@tonic-gate 	/*
1340Sstevel@tonic-gate 	 * Immutable information of the MAC which the channel is using.
1350Sstevel@tonic-gate 	 */
1360Sstevel@tonic-gate 	const mac_info_t	*ds_mip;
1370Sstevel@tonic-gate 
1380Sstevel@tonic-gate 	/*
1390Sstevel@tonic-gate 	 * Current packet priority.
1400Sstevel@tonic-gate 	 */
1410Sstevel@tonic-gate 	uint_t			ds_pri;
1420Sstevel@tonic-gate 
1430Sstevel@tonic-gate 	/*
1440Sstevel@tonic-gate 	 * Handle of our MAC notification callback.
1450Sstevel@tonic-gate 	 */
1460Sstevel@tonic-gate 	mac_notify_handle_t	ds_mnh;
1470Sstevel@tonic-gate 
1480Sstevel@tonic-gate 	/*
1490Sstevel@tonic-gate 	 * Set of enabled DL_NOTE... notifications. (See dlpi.h).
1500Sstevel@tonic-gate 	 */
1510Sstevel@tonic-gate 	uint32_t		ds_notifications;
1520Sstevel@tonic-gate 
1530Sstevel@tonic-gate 	/*
1540Sstevel@tonic-gate 	 * Cached MAC unicast addresses.
1550Sstevel@tonic-gate 	 */
1562311Sseb 	uint8_t			ds_fact_addr[MAXMACADDRLEN];
1572311Sseb 	uint8_t			ds_curr_addr[MAXMACADDRLEN];
1580Sstevel@tonic-gate 
1590Sstevel@tonic-gate 	/*
1600Sstevel@tonic-gate 	 * Mode: unitdata, fast-path or raw.
1610Sstevel@tonic-gate 	 */
1620Sstevel@tonic-gate 	dld_str_mode_t		ds_mode;
1630Sstevel@tonic-gate 
1640Sstevel@tonic-gate 	/*
1653147Sxc151355 	 * Native mode state.
1663147Sxc151355 	 */
1673147Sxc151355 	boolean_t		ds_native;
1683147Sxc151355 
1693147Sxc151355 	/*
1700Sstevel@tonic-gate 	 * IP polling is operational if this flag is set.
1710Sstevel@tonic-gate 	 */
1720Sstevel@tonic-gate 	boolean_t		ds_polling;
1731184Skrgopi 	boolean_t		ds_soft_ring;
1740Sstevel@tonic-gate 
1750Sstevel@tonic-gate 	/*
1763115Syl150051 	 * LSO is enabled if ds_lso is set.
1773115Syl150051 	 */
1783115Syl150051 	boolean_t		ds_lso;
1793115Syl150051 	uint64_t		ds_lso_max;
1803115Syl150051 
1813115Syl150051 	/*
1820Sstevel@tonic-gate 	 * State of DLPI user: may be active (regular network layer),
1830Sstevel@tonic-gate 	 * passive (snoop-like monitoring), or unknown (not yet
1840Sstevel@tonic-gate 	 * determined).
1850Sstevel@tonic-gate 	 */
1860Sstevel@tonic-gate 	dld_passivestate_t	ds_passivestate;
1870Sstevel@tonic-gate 
1880Sstevel@tonic-gate 	/*
189269Sericheng 	 * Dummy mblk used for flow-control.
190269Sericheng 	 */
191269Sericheng 	mblk_t			*ds_tx_flow_mp;
192269Sericheng 
193269Sericheng 	/*
194269Sericheng 	 * Internal transmit queue and its parameters.
1950Sstevel@tonic-gate 	 */
196269Sericheng 	kmutex_t		ds_tx_list_lock;
197269Sericheng 	mblk_t			*ds_tx_list_head;
198269Sericheng 	mblk_t			*ds_tx_list_tail;
199269Sericheng 	uint_t			ds_tx_cnt;
200269Sericheng 	uint_t			ds_tx_msgcnt;
2015895Syz147064 	timeout_id_t		ds_tx_qdepth_tid;
202269Sericheng 	boolean_t		ds_tx_qbusy;
203269Sericheng 
2045895Syz147064 	dld_tx_t		ds_tx;
2055895Syz147064 	dld_tx_t		ds_unitdata_tx;
2065895Syz147064 	kmutex_t		ds_tx_lock;
2075895Syz147064 	kcondvar_t		ds_tx_cv;
2085895Syz147064 	uint32_t		ds_intx_cnt;
2095895Syz147064 	boolean_t		ds_detaching;
2105895Syz147064 
2115895Syz147064 	/*
2125895Syz147064 	 * Pending control messages to be processed.
2135895Syz147064 	 */
2145895Syz147064 	mblk_t			*ds_pending_head;
2155895Syz147064 	mblk_t			*ds_pending_tail;
2165895Syz147064 
2175895Syz147064 	taskqid_t		ds_tid;
2185895Syz147064 	kmutex_t		ds_disp_lock;
2195895Syz147064 	kcondvar_t		ds_disp_cv;
2205895Syz147064 	boolean_t		ds_closing;
2215895Syz147064 
222269Sericheng 	/*
2235895Syz147064 	 * Used to process ioctl message for control node. See comments
2245895Syz147064 	 * above dld_ioctl().
225269Sericheng 	 */
2265895Syz147064 	void			(*ds_ioctl)(queue_t *, mblk_t *);
2277378SShuguo.Yang@Sun.COM };
2280Sstevel@tonic-gate 
2295895Syz147064 #define	DLD_TX_ENTER(dsp) {					\
2305895Syz147064 	mutex_enter(&(dsp)->ds_tx_lock);			\
2315895Syz147064 	(dsp)->ds_intx_cnt++;					\
2325895Syz147064 	mutex_exit(&(dsp)->ds_tx_lock);				\
2335895Syz147064 }
2345895Syz147064 
2355895Syz147064 #define	DLD_TX_EXIT(dsp) {					\
2365895Syz147064 	mutex_enter(&(dsp)->ds_tx_lock);			\
2375895Syz147064 	if ((--(dsp)->ds_intx_cnt == 0) && (dsp)->ds_detaching)	\
2385895Syz147064 		cv_signal(&(dsp)->ds_tx_cv);			\
2395895Syz147064 	mutex_exit(&(dsp)->ds_tx_lock);				\
2405895Syz147064 }
2415895Syz147064 
2425895Syz147064 /*
2435895Syz147064  * Quiesce the traffic.
2445895Syz147064  */
2455895Syz147064 #define	DLD_TX_QUIESCE(dsp) {						\
2465895Syz147064 	mutex_enter(&(dsp)->ds_tx_lock);				\
2475895Syz147064 	(dsp)->ds_tx = (dsp)->ds_unitdata_tx = NULL;			\
2485895Syz147064 	(dsp)->ds_detaching = B_TRUE;					\
2495895Syz147064 	while ((dsp)->ds_intx_cnt != 0)					\
2505895Syz147064 		cv_wait(&(dsp)->ds_tx_cv, &(dsp)->ds_tx_lock);		\
2515895Syz147064 	(dsp)->ds_detaching = B_FALSE;					\
2525895Syz147064 	mutex_exit(&(dsp)->ds_tx_lock);					\
2535895Syz147064 }
2545895Syz147064 
2550Sstevel@tonic-gate /*
2560Sstevel@tonic-gate  * dld_str.c module.
2570Sstevel@tonic-gate  */
2580Sstevel@tonic-gate 
2590Sstevel@tonic-gate extern void		dld_str_init(void);
2600Sstevel@tonic-gate extern int		dld_str_fini(void);
261269Sericheng extern dld_str_t	*dld_str_create(queue_t *, uint_t, major_t,
262269Sericheng     t_uscalar_t);
2630Sstevel@tonic-gate extern void		dld_str_destroy(dld_str_t *);
264269Sericheng extern int		dld_str_attach(dld_str_t *, t_uscalar_t);
2650Sstevel@tonic-gate extern void		dld_str_detach(dld_str_t *);
2660Sstevel@tonic-gate extern void		dld_str_rx_raw(void *, mac_resource_handle_t,
2672760Sdg199075     mblk_t *, mac_header_info_t *);
2680Sstevel@tonic-gate extern void		dld_str_rx_fastpath(void *, mac_resource_handle_t,
2692760Sdg199075     mblk_t *, mac_header_info_t *);
2700Sstevel@tonic-gate extern void		dld_str_rx_unitdata(void *, mac_resource_handle_t,
2712760Sdg199075     mblk_t *, mac_header_info_t *);
2725895Syz147064 
273269Sericheng extern void		dld_tx_flush(dld_str_t *);
2740Sstevel@tonic-gate extern void		dld_str_notify_ind(dld_str_t *);
2755895Syz147064 extern void		dld_tx_single(dld_str_t *, mblk_t *);
276269Sericheng extern void		str_mdata_fastpath_put(dld_str_t *, mblk_t *);
2775895Syz147064 extern void		str_mdata_raw_put(dld_str_t *, mblk_t *);
2785895Syz147064 
2795895Syz147064 extern void		dld_ioctl(queue_t *, mblk_t *);
2805895Syz147064 extern void		dld_finish_pending_task(dld_str_t *);
281269Sericheng 
2820Sstevel@tonic-gate /*
2830Sstevel@tonic-gate  * dld_proto.c
2840Sstevel@tonic-gate  */
2855895Syz147064 extern void		dld_wput_proto_nondata(dld_str_t *, mblk_t *);
2865895Syz147064 extern void		dld_wput_proto_data(dld_str_t *, mblk_t *);
2875113Syz147064 extern void		dld_capabilities_disable(dld_str_t *);
2880Sstevel@tonic-gate 
2890Sstevel@tonic-gate /*
2900Sstevel@tonic-gate  * Options: there should be a separate bit defined here for each
2915895Syz147064  *	  DLD_PROP... defined in dld.h.
2920Sstevel@tonic-gate  */
293269Sericheng #define	DLD_OPT_NO_FASTPATH	0x00000001
294269Sericheng #define	DLD_OPT_NO_POLL		0x00000002
295269Sericheng #define	DLD_OPT_NO_ZEROCOPY	0x00000004
2964114Sja97890 #define	DLD_OPT_NO_SOFTRING	0x00000008
2970Sstevel@tonic-gate 
2980Sstevel@tonic-gate extern uint32_t		dld_opt;
2990Sstevel@tonic-gate 
3000Sstevel@tonic-gate /*
3015895Syz147064  * autopush information
3025895Syz147064  */
3035895Syz147064 typedef struct dld_ap {
3045895Syz147064 	datalink_id_t		da_linkid;
3055895Syz147064 	struct dlautopush	da_ap;
3065895Syz147064 
3075895Syz147064 #define	da_anchor		da_ap.dap_anchor
3085895Syz147064 #define	da_npush		da_ap.dap_npush
3095895Syz147064 #define	da_aplist		da_ap.dap_aplist
3105895Syz147064 
3115895Syz147064 } dld_ap_t;
3125895Syz147064 
3135895Syz147064 /*
3140Sstevel@tonic-gate  * Useful macros.
3150Sstevel@tonic-gate  */
3160Sstevel@tonic-gate 
3170Sstevel@tonic-gate #define	IMPLY(p, c)	(!(p) || (c))
3180Sstevel@tonic-gate 
319269Sericheng #ifdef DEBUG
320269Sericheng #define	DLD_DBG		cmn_err
321269Sericheng #else
322269Sericheng #define	DLD_DBG		if (0) cmn_err
323269Sericheng #endif
324269Sericheng 
3250Sstevel@tonic-gate #ifdef	__cplusplus
3260Sstevel@tonic-gate }
3270Sstevel@tonic-gate #endif
3280Sstevel@tonic-gate 
3290Sstevel@tonic-gate #endif	/* _SYS_DLD_IMPL_H */
330