xref: /onnv-gate/usr/src/uts/common/sys/dld_impl.h (revision 7378:679fb1086e51)
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 
420Sstevel@tonic-gate #define	DLD_CONTROL	0x00000001
430Sstevel@tonic-gate #define	DLD_DLPI	0x00000002
440Sstevel@tonic-gate 
450Sstevel@tonic-gate typedef enum {
460Sstevel@tonic-gate 	DLD_UNITDATA,
470Sstevel@tonic-gate 	DLD_FASTPATH,
480Sstevel@tonic-gate 	DLD_RAW
490Sstevel@tonic-gate } dld_str_mode_t;
500Sstevel@tonic-gate 
510Sstevel@tonic-gate typedef enum {
520Sstevel@tonic-gate 	DLD_UNINITIALIZED,
530Sstevel@tonic-gate 	DLD_PASSIVE,
540Sstevel@tonic-gate 	DLD_ACTIVE
550Sstevel@tonic-gate } dld_passivestate_t;
560Sstevel@tonic-gate 
570Sstevel@tonic-gate typedef struct dld_str	dld_str_t;
585895Syz147064 typedef void		(*dld_tx_t)(struct dld_str *, mblk_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 	/*
750Sstevel@tonic-gate 	 * Read/write queues for the stream which the object represents.
760Sstevel@tonic-gate 	 */
770Sstevel@tonic-gate 	queue_t			*ds_rq;
780Sstevel@tonic-gate 	queue_t			*ds_wq;
790Sstevel@tonic-gate 
800Sstevel@tonic-gate 	/*
81269Sericheng 	 * Lock to protect this structure.
82269Sericheng 	 */
83269Sericheng 	krwlock_t		ds_lock;
84269Sericheng 
85269Sericheng 	/*
860Sstevel@tonic-gate 	 * Stream is open to DLD_CONTROL (control node) or
870Sstevel@tonic-gate 	 * DLD_DLPI (DLS provider) node.
880Sstevel@tonic-gate 	 */
890Sstevel@tonic-gate 	uint_t			ds_type;
900Sstevel@tonic-gate 
910Sstevel@tonic-gate 	/*
920Sstevel@tonic-gate 	 * The following fields are only used for DLD_DLPI type objects.
930Sstevel@tonic-gate 	 */
940Sstevel@tonic-gate 
950Sstevel@tonic-gate 	/*
960Sstevel@tonic-gate 	 * Current DLPI state.
970Sstevel@tonic-gate 	 */
980Sstevel@tonic-gate 	t_uscalar_t		ds_dlstate;
990Sstevel@tonic-gate 
1000Sstevel@tonic-gate 	/*
101269Sericheng 	 * DLPI style
102269Sericheng 	 */
103269Sericheng 	t_uscalar_t		ds_style;
104269Sericheng 
105269Sericheng 	/*
1060Sstevel@tonic-gate 	 * Currently bound DLSAP.
1070Sstevel@tonic-gate 	 */
1080Sstevel@tonic-gate 	uint16_t		ds_sap;
1090Sstevel@tonic-gate 
1100Sstevel@tonic-gate 	/*
1110Sstevel@tonic-gate 	 * Handle of the data-link channel that is used by this object.
1120Sstevel@tonic-gate 	 */
1130Sstevel@tonic-gate 	dls_channel_t		ds_dc;
1140Sstevel@tonic-gate 
1150Sstevel@tonic-gate 	/*
1160Sstevel@tonic-gate 	 * Handle of the MAC that is used by the data-link interface.
1170Sstevel@tonic-gate 	 */
1180Sstevel@tonic-gate 	mac_handle_t		ds_mh;
1190Sstevel@tonic-gate 
1200Sstevel@tonic-gate 	/*
1210Sstevel@tonic-gate 	 * VLAN identifier of the data-link interface.
1220Sstevel@tonic-gate 	 */
1230Sstevel@tonic-gate 	uint16_t		ds_vid;
1240Sstevel@tonic-gate 
1250Sstevel@tonic-gate 	/*
1260Sstevel@tonic-gate 	 * Promiscuity level information.
1270Sstevel@tonic-gate 	 */
1280Sstevel@tonic-gate 	uint32_t		ds_promisc;
1290Sstevel@tonic-gate 
1300Sstevel@tonic-gate 	/*
1310Sstevel@tonic-gate 	 * Immutable information of the MAC which the channel is using.
1320Sstevel@tonic-gate 	 */
1330Sstevel@tonic-gate 	const mac_info_t	*ds_mip;
1340Sstevel@tonic-gate 
1350Sstevel@tonic-gate 	/*
1360Sstevel@tonic-gate 	 * Current packet priority.
1370Sstevel@tonic-gate 	 */
1380Sstevel@tonic-gate 	uint_t			ds_pri;
1390Sstevel@tonic-gate 
1400Sstevel@tonic-gate 	/*
1410Sstevel@tonic-gate 	 * Handle of our MAC notification callback.
1420Sstevel@tonic-gate 	 */
1430Sstevel@tonic-gate 	mac_notify_handle_t	ds_mnh;
1440Sstevel@tonic-gate 
1450Sstevel@tonic-gate 	/*
1460Sstevel@tonic-gate 	 * Set of enabled DL_NOTE... notifications. (See dlpi.h).
1470Sstevel@tonic-gate 	 */
1480Sstevel@tonic-gate 	uint32_t		ds_notifications;
1490Sstevel@tonic-gate 
1500Sstevel@tonic-gate 	/*
1510Sstevel@tonic-gate 	 * Cached MAC unicast addresses.
1520Sstevel@tonic-gate 	 */
1532311Sseb 	uint8_t			ds_fact_addr[MAXMACADDRLEN];
1542311Sseb 	uint8_t			ds_curr_addr[MAXMACADDRLEN];
1550Sstevel@tonic-gate 
1560Sstevel@tonic-gate 	/*
1570Sstevel@tonic-gate 	 * Mode: unitdata, fast-path or raw.
1580Sstevel@tonic-gate 	 */
1590Sstevel@tonic-gate 	dld_str_mode_t		ds_mode;
1600Sstevel@tonic-gate 
1610Sstevel@tonic-gate 	/*
1623147Sxc151355 	 * Native mode state.
1633147Sxc151355 	 */
1643147Sxc151355 	boolean_t		ds_native;
1653147Sxc151355 
1663147Sxc151355 	/*
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 	/*
1733115Syl150051 	 * LSO is enabled if ds_lso is set.
1743115Syl150051 	 */
1753115Syl150051 	boolean_t		ds_lso;
1763115Syl150051 	uint64_t		ds_lso_max;
1773115Syl150051 
1783115Syl150051 	/*
1790Sstevel@tonic-gate 	 * State of DLPI user: may be active (regular network layer),
1800Sstevel@tonic-gate 	 * passive (snoop-like monitoring), or unknown (not yet
1810Sstevel@tonic-gate 	 * determined).
1820Sstevel@tonic-gate 	 */
1830Sstevel@tonic-gate 	dld_passivestate_t	ds_passivestate;
1840Sstevel@tonic-gate 
1850Sstevel@tonic-gate 	/*
186269Sericheng 	 * Dummy mblk used for flow-control.
187269Sericheng 	 */
188269Sericheng 	mblk_t			*ds_tx_flow_mp;
189269Sericheng 
190269Sericheng 	/*
191269Sericheng 	 * Internal transmit queue and its parameters.
1920Sstevel@tonic-gate 	 */
193269Sericheng 	kmutex_t		ds_tx_list_lock;
194269Sericheng 	mblk_t			*ds_tx_list_head;
195269Sericheng 	mblk_t			*ds_tx_list_tail;
196269Sericheng 	uint_t			ds_tx_cnt;
197269Sericheng 	uint_t			ds_tx_msgcnt;
1985895Syz147064 	timeout_id_t		ds_tx_qdepth_tid;
199269Sericheng 	boolean_t		ds_tx_qbusy;
200269Sericheng 
2015895Syz147064 	dld_tx_t		ds_tx;
2025895Syz147064 	dld_tx_t		ds_unitdata_tx;
2035895Syz147064 	kmutex_t		ds_tx_lock;
2045895Syz147064 	kcondvar_t		ds_tx_cv;
2055895Syz147064 	uint32_t		ds_intx_cnt;
2065895Syz147064 	boolean_t		ds_detaching;
2075895Syz147064 
2085895Syz147064 	/*
2095895Syz147064 	 * Pending control messages to be processed.
2105895Syz147064 	 */
2115895Syz147064 	mblk_t			*ds_pending_head;
2125895Syz147064 	mblk_t			*ds_pending_tail;
2135895Syz147064 
2145895Syz147064 	taskqid_t		ds_tid;
2155895Syz147064 	kmutex_t		ds_disp_lock;
2165895Syz147064 	kcondvar_t		ds_disp_cv;
2175895Syz147064 	boolean_t		ds_closing;
2185895Syz147064 
219269Sericheng 	/*
2205895Syz147064 	 * Used to process ioctl message for control node. See comments
2215895Syz147064 	 * above dld_ioctl().
222269Sericheng 	 */
2235895Syz147064 	void			(*ds_ioctl)(queue_t *, mblk_t *);
224*7378SShuguo.Yang@Sun.COM };
2250Sstevel@tonic-gate 
2265895Syz147064 #define	DLD_TX_ENTER(dsp) {					\
2275895Syz147064 	mutex_enter(&(dsp)->ds_tx_lock);			\
2285895Syz147064 	(dsp)->ds_intx_cnt++;					\
2295895Syz147064 	mutex_exit(&(dsp)->ds_tx_lock);				\
2305895Syz147064 }
2315895Syz147064 
2325895Syz147064 #define	DLD_TX_EXIT(dsp) {					\
2335895Syz147064 	mutex_enter(&(dsp)->ds_tx_lock);			\
2345895Syz147064 	if ((--(dsp)->ds_intx_cnt == 0) && (dsp)->ds_detaching)	\
2355895Syz147064 		cv_signal(&(dsp)->ds_tx_cv);			\
2365895Syz147064 	mutex_exit(&(dsp)->ds_tx_lock);				\
2375895Syz147064 }
2385895Syz147064 
2395895Syz147064 /*
2405895Syz147064  * Quiesce the traffic.
2415895Syz147064  */
2425895Syz147064 #define	DLD_TX_QUIESCE(dsp) {						\
2435895Syz147064 	mutex_enter(&(dsp)->ds_tx_lock);				\
2445895Syz147064 	(dsp)->ds_tx = (dsp)->ds_unitdata_tx = NULL;			\
2455895Syz147064 	(dsp)->ds_detaching = B_TRUE;					\
2465895Syz147064 	while ((dsp)->ds_intx_cnt != 0)					\
2475895Syz147064 		cv_wait(&(dsp)->ds_tx_cv, &(dsp)->ds_tx_lock);		\
2485895Syz147064 	(dsp)->ds_detaching = B_FALSE;					\
2495895Syz147064 	mutex_exit(&(dsp)->ds_tx_lock);					\
2505895Syz147064 }
2515895Syz147064 
2520Sstevel@tonic-gate /*
2530Sstevel@tonic-gate  * dld_str.c module.
2540Sstevel@tonic-gate  */
2550Sstevel@tonic-gate 
2560Sstevel@tonic-gate extern void		dld_str_init(void);
2570Sstevel@tonic-gate extern int		dld_str_fini(void);
258269Sericheng extern dld_str_t	*dld_str_create(queue_t *, uint_t, major_t,
259269Sericheng     t_uscalar_t);
2600Sstevel@tonic-gate extern void		dld_str_destroy(dld_str_t *);
261269Sericheng extern int		dld_str_attach(dld_str_t *, t_uscalar_t);
2620Sstevel@tonic-gate extern void		dld_str_detach(dld_str_t *);
2630Sstevel@tonic-gate extern void		dld_str_rx_raw(void *, mac_resource_handle_t,
2642760Sdg199075     mblk_t *, mac_header_info_t *);
2650Sstevel@tonic-gate extern void		dld_str_rx_fastpath(void *, mac_resource_handle_t,
2662760Sdg199075     mblk_t *, mac_header_info_t *);
2670Sstevel@tonic-gate extern void		dld_str_rx_unitdata(void *, mac_resource_handle_t,
2682760Sdg199075     mblk_t *, mac_header_info_t *);
2695895Syz147064 
270269Sericheng extern void		dld_tx_flush(dld_str_t *);
2710Sstevel@tonic-gate extern void		dld_str_notify_ind(dld_str_t *);
2725895Syz147064 extern void		dld_tx_single(dld_str_t *, mblk_t *);
273269Sericheng extern void		str_mdata_fastpath_put(dld_str_t *, mblk_t *);
2745895Syz147064 extern void		str_mdata_raw_put(dld_str_t *, mblk_t *);
2755895Syz147064 
2765895Syz147064 extern void		dld_ioctl(queue_t *, mblk_t *);
2775895Syz147064 extern void		dld_finish_pending_task(dld_str_t *);
278269Sericheng 
2790Sstevel@tonic-gate /*
2800Sstevel@tonic-gate  * dld_proto.c
2810Sstevel@tonic-gate  */
2825895Syz147064 extern void		dld_wput_proto_nondata(dld_str_t *, mblk_t *);
2835895Syz147064 extern void		dld_wput_proto_data(dld_str_t *, mblk_t *);
2845113Syz147064 extern void		dld_capabilities_disable(dld_str_t *);
2850Sstevel@tonic-gate 
2860Sstevel@tonic-gate /*
2870Sstevel@tonic-gate  * Options: there should be a separate bit defined here for each
2885895Syz147064  *	  DLD_PROP... defined in dld.h.
2890Sstevel@tonic-gate  */
290269Sericheng #define	DLD_OPT_NO_FASTPATH	0x00000001
291269Sericheng #define	DLD_OPT_NO_POLL		0x00000002
292269Sericheng #define	DLD_OPT_NO_ZEROCOPY	0x00000004
2934114Sja97890 #define	DLD_OPT_NO_SOFTRING	0x00000008
2940Sstevel@tonic-gate 
2950Sstevel@tonic-gate extern uint32_t		dld_opt;
2960Sstevel@tonic-gate 
2970Sstevel@tonic-gate /*
2985895Syz147064  * autopush information
2995895Syz147064  */
3005895Syz147064 typedef struct dld_ap {
3015895Syz147064 	datalink_id_t		da_linkid;
3025895Syz147064 	struct dlautopush	da_ap;
3035895Syz147064 
3045895Syz147064 #define	da_anchor		da_ap.dap_anchor
3055895Syz147064 #define	da_npush		da_ap.dap_npush
3065895Syz147064 #define	da_aplist		da_ap.dap_aplist
3075895Syz147064 
3085895Syz147064 } dld_ap_t;
3095895Syz147064 
3105895Syz147064 /*
3110Sstevel@tonic-gate  * Useful macros.
3120Sstevel@tonic-gate  */
3130Sstevel@tonic-gate 
3140Sstevel@tonic-gate #define	IMPLY(p, c)	(!(p) || (c))
3150Sstevel@tonic-gate 
316269Sericheng #ifdef DEBUG
317269Sericheng #define	DLD_DBG		cmn_err
318269Sericheng #else
319269Sericheng #define	DLD_DBG		if (0) cmn_err
320269Sericheng #endif
321269Sericheng 
3220Sstevel@tonic-gate #ifdef	__cplusplus
3230Sstevel@tonic-gate }
3240Sstevel@tonic-gate #endif
3250Sstevel@tonic-gate 
3260Sstevel@tonic-gate #endif	/* _SYS_DLD_IMPL_H */
327