xref: /onnv-gate/usr/src/uts/common/sys/dld_impl.h (revision 5895:f251acdd9bdc)
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*5895Syz147064  * 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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
300Sstevel@tonic-gate 
310Sstevel@tonic-gate #include <sys/types.h>
32*5895Syz147064 #include <sys/conf.h>
330Sstevel@tonic-gate #include <sys/ethernet.h>
340Sstevel@tonic-gate #include <sys/stream.h>
350Sstevel@tonic-gate #include <sys/dlpi.h>
360Sstevel@tonic-gate #include <sys/mac.h>
370Sstevel@tonic-gate #include <sys/dls.h>
380Sstevel@tonic-gate #include <sys/dld.h>
390Sstevel@tonic-gate 
400Sstevel@tonic-gate #ifdef	__cplusplus
410Sstevel@tonic-gate extern "C" {
420Sstevel@tonic-gate #endif
430Sstevel@tonic-gate 
440Sstevel@tonic-gate #define	DLD_CONTROL	0x00000001
450Sstevel@tonic-gate #define	DLD_DLPI	0x00000002
460Sstevel@tonic-gate 
470Sstevel@tonic-gate typedef enum {
480Sstevel@tonic-gate 	DLD_UNITDATA,
490Sstevel@tonic-gate 	DLD_FASTPATH,
500Sstevel@tonic-gate 	DLD_RAW
510Sstevel@tonic-gate } dld_str_mode_t;
520Sstevel@tonic-gate 
530Sstevel@tonic-gate typedef enum {
540Sstevel@tonic-gate 	DLD_UNINITIALIZED,
550Sstevel@tonic-gate 	DLD_PASSIVE,
560Sstevel@tonic-gate 	DLD_ACTIVE
570Sstevel@tonic-gate } dld_passivestate_t;
580Sstevel@tonic-gate 
590Sstevel@tonic-gate typedef struct dld_str	dld_str_t;
60*5895Syz147064 typedef void		(*dld_tx_t)(struct dld_str *, mblk_t *);
610Sstevel@tonic-gate 
620Sstevel@tonic-gate /*
630Sstevel@tonic-gate  * dld_str_t object definition.
640Sstevel@tonic-gate  */
650Sstevel@tonic-gate struct dld_str {
660Sstevel@tonic-gate 	/*
67269Sericheng 	 * Major number of the device
68269Sericheng 	 */
69269Sericheng 	major_t			ds_major;
70269Sericheng 
71269Sericheng 	/*
720Sstevel@tonic-gate 	 * Ephemeral minor number for the object.
730Sstevel@tonic-gate 	 */
740Sstevel@tonic-gate 	minor_t			ds_minor;
750Sstevel@tonic-gate 
760Sstevel@tonic-gate 	/*
770Sstevel@tonic-gate 	 * Read/write queues for the stream which the object represents.
780Sstevel@tonic-gate 	 */
790Sstevel@tonic-gate 	queue_t			*ds_rq;
800Sstevel@tonic-gate 	queue_t			*ds_wq;
810Sstevel@tonic-gate 
820Sstevel@tonic-gate 	/*
83269Sericheng 	 * Lock to protect this structure.
84269Sericheng 	 */
85269Sericheng 	krwlock_t		ds_lock;
86269Sericheng 
87269Sericheng 	/*
880Sstevel@tonic-gate 	 * Stream is open to DLD_CONTROL (control node) or
890Sstevel@tonic-gate 	 * DLD_DLPI (DLS provider) node.
900Sstevel@tonic-gate 	 */
910Sstevel@tonic-gate 	uint_t			ds_type;
920Sstevel@tonic-gate 
930Sstevel@tonic-gate 	/*
940Sstevel@tonic-gate 	 * The following fields are only used for DLD_DLPI type objects.
950Sstevel@tonic-gate 	 */
960Sstevel@tonic-gate 
970Sstevel@tonic-gate 	/*
980Sstevel@tonic-gate 	 * Current DLPI state.
990Sstevel@tonic-gate 	 */
1000Sstevel@tonic-gate 	t_uscalar_t		ds_dlstate;
1010Sstevel@tonic-gate 
1020Sstevel@tonic-gate 	/*
103269Sericheng 	 * DLPI style
104269Sericheng 	 */
105269Sericheng 	t_uscalar_t		ds_style;
106269Sericheng 
107269Sericheng 	/*
1080Sstevel@tonic-gate 	 * Currently bound DLSAP.
1090Sstevel@tonic-gate 	 */
1100Sstevel@tonic-gate 	uint16_t		ds_sap;
1110Sstevel@tonic-gate 
1120Sstevel@tonic-gate 	/*
1130Sstevel@tonic-gate 	 * Handle of the data-link channel that is used by this object.
1140Sstevel@tonic-gate 	 */
1150Sstevel@tonic-gate 	dls_channel_t		ds_dc;
1160Sstevel@tonic-gate 
1170Sstevel@tonic-gate 	/*
1180Sstevel@tonic-gate 	 * Handle of the MAC that is used by the data-link interface.
1190Sstevel@tonic-gate 	 */
1200Sstevel@tonic-gate 	mac_handle_t		ds_mh;
1210Sstevel@tonic-gate 
1220Sstevel@tonic-gate 	/*
1230Sstevel@tonic-gate 	 * VLAN identifier of the data-link interface.
1240Sstevel@tonic-gate 	 */
1250Sstevel@tonic-gate 	uint16_t		ds_vid;
1260Sstevel@tonic-gate 
1270Sstevel@tonic-gate 	/*
1280Sstevel@tonic-gate 	 * Promiscuity level information.
1290Sstevel@tonic-gate 	 */
1300Sstevel@tonic-gate 	uint32_t		ds_promisc;
1310Sstevel@tonic-gate 
1320Sstevel@tonic-gate 	/*
1330Sstevel@tonic-gate 	 * Immutable information of the MAC which the channel is using.
1340Sstevel@tonic-gate 	 */
1350Sstevel@tonic-gate 	const mac_info_t	*ds_mip;
1360Sstevel@tonic-gate 
1370Sstevel@tonic-gate 	/*
1380Sstevel@tonic-gate 	 * Current packet priority.
1390Sstevel@tonic-gate 	 */
1400Sstevel@tonic-gate 	uint_t			ds_pri;
1410Sstevel@tonic-gate 
1420Sstevel@tonic-gate 	/*
1430Sstevel@tonic-gate 	 * Handle of our MAC notification callback.
1440Sstevel@tonic-gate 	 */
1450Sstevel@tonic-gate 	mac_notify_handle_t	ds_mnh;
1460Sstevel@tonic-gate 
1470Sstevel@tonic-gate 	/*
1480Sstevel@tonic-gate 	 * Set of enabled DL_NOTE... notifications. (See dlpi.h).
1490Sstevel@tonic-gate 	 */
1500Sstevel@tonic-gate 	uint32_t		ds_notifications;
1510Sstevel@tonic-gate 
1520Sstevel@tonic-gate 	/*
1530Sstevel@tonic-gate 	 * Cached MAC unicast addresses.
1540Sstevel@tonic-gate 	 */
1552311Sseb 	uint8_t			ds_fact_addr[MAXMACADDRLEN];
1562311Sseb 	uint8_t			ds_curr_addr[MAXMACADDRLEN];
1570Sstevel@tonic-gate 
1580Sstevel@tonic-gate 	/*
1590Sstevel@tonic-gate 	 * Mode: unitdata, fast-path or raw.
1600Sstevel@tonic-gate 	 */
1610Sstevel@tonic-gate 	dld_str_mode_t		ds_mode;
1620Sstevel@tonic-gate 
1630Sstevel@tonic-gate 	/*
1643147Sxc151355 	 * Native mode state.
1653147Sxc151355 	 */
1663147Sxc151355 	boolean_t		ds_native;
1673147Sxc151355 
1683147Sxc151355 	/*
1690Sstevel@tonic-gate 	 * IP polling is operational if this flag is set.
1700Sstevel@tonic-gate 	 */
1710Sstevel@tonic-gate 	boolean_t		ds_polling;
1721184Skrgopi 	boolean_t		ds_soft_ring;
1730Sstevel@tonic-gate 
1740Sstevel@tonic-gate 	/*
1753115Syl150051 	 * LSO is enabled if ds_lso is set.
1763115Syl150051 	 */
1773115Syl150051 	boolean_t		ds_lso;
1783115Syl150051 	uint64_t		ds_lso_max;
1793115Syl150051 
1803115Syl150051 	/*
1810Sstevel@tonic-gate 	 * State of DLPI user: may be active (regular network layer),
1820Sstevel@tonic-gate 	 * passive (snoop-like monitoring), or unknown (not yet
1830Sstevel@tonic-gate 	 * determined).
1840Sstevel@tonic-gate 	 */
1850Sstevel@tonic-gate 	dld_passivestate_t	ds_passivestate;
1860Sstevel@tonic-gate 
1870Sstevel@tonic-gate 	/*
188269Sericheng 	 * Dummy mblk used for flow-control.
189269Sericheng 	 */
190269Sericheng 	mblk_t			*ds_tx_flow_mp;
191269Sericheng 
192269Sericheng 	/*
193269Sericheng 	 * Internal transmit queue and its parameters.
1940Sstevel@tonic-gate 	 */
195269Sericheng 	kmutex_t		ds_tx_list_lock;
196269Sericheng 	mblk_t			*ds_tx_list_head;
197269Sericheng 	mblk_t			*ds_tx_list_tail;
198269Sericheng 	uint_t			ds_tx_cnt;
199269Sericheng 	uint_t			ds_tx_msgcnt;
200*5895Syz147064 	timeout_id_t		ds_tx_qdepth_tid;
201269Sericheng 	boolean_t		ds_tx_qbusy;
202269Sericheng 
203*5895Syz147064 	dld_tx_t		ds_tx;
204*5895Syz147064 	dld_tx_t		ds_unitdata_tx;
205*5895Syz147064 	kmutex_t		ds_tx_lock;
206*5895Syz147064 	kcondvar_t		ds_tx_cv;
207*5895Syz147064 	uint32_t		ds_intx_cnt;
208*5895Syz147064 	boolean_t		ds_detaching;
209*5895Syz147064 
210*5895Syz147064 	/*
211*5895Syz147064 	 * Pending control messages to be processed.
212*5895Syz147064 	 */
213*5895Syz147064 	mblk_t			*ds_pending_head;
214*5895Syz147064 	mblk_t			*ds_pending_tail;
215*5895Syz147064 
216*5895Syz147064 	taskqid_t		ds_tid;
217*5895Syz147064 	kmutex_t		ds_disp_lock;
218*5895Syz147064 	kcondvar_t		ds_disp_cv;
219*5895Syz147064 	boolean_t		ds_closing;
220*5895Syz147064 
221269Sericheng 	/*
222*5895Syz147064 	 * Used to process ioctl message for control node. See comments
223*5895Syz147064 	 * above dld_ioctl().
224269Sericheng 	 */
225*5895Syz147064 	void			(*ds_ioctl)(queue_t *, mblk_t *);
2260Sstevel@tonic-gate } dld_str;
2270Sstevel@tonic-gate 
228*5895Syz147064 #define	DLD_TX_ENTER(dsp) {					\
229*5895Syz147064 	mutex_enter(&(dsp)->ds_tx_lock);			\
230*5895Syz147064 	(dsp)->ds_intx_cnt++;					\
231*5895Syz147064 	mutex_exit(&(dsp)->ds_tx_lock);				\
232*5895Syz147064 }
233*5895Syz147064 
234*5895Syz147064 #define	DLD_TX_EXIT(dsp) {					\
235*5895Syz147064 	mutex_enter(&(dsp)->ds_tx_lock);			\
236*5895Syz147064 	if ((--(dsp)->ds_intx_cnt == 0) && (dsp)->ds_detaching)	\
237*5895Syz147064 		cv_signal(&(dsp)->ds_tx_cv);			\
238*5895Syz147064 	mutex_exit(&(dsp)->ds_tx_lock);				\
239*5895Syz147064 }
240*5895Syz147064 
241*5895Syz147064 /*
242*5895Syz147064  * Quiesce the traffic.
243*5895Syz147064  */
244*5895Syz147064 #define	DLD_TX_QUIESCE(dsp) {						\
245*5895Syz147064 	mutex_enter(&(dsp)->ds_tx_lock);				\
246*5895Syz147064 	(dsp)->ds_tx = (dsp)->ds_unitdata_tx = NULL;			\
247*5895Syz147064 	(dsp)->ds_detaching = B_TRUE;					\
248*5895Syz147064 	while ((dsp)->ds_intx_cnt != 0)					\
249*5895Syz147064 		cv_wait(&(dsp)->ds_tx_cv, &(dsp)->ds_tx_lock);		\
250*5895Syz147064 	(dsp)->ds_detaching = B_FALSE;					\
251*5895Syz147064 	mutex_exit(&(dsp)->ds_tx_lock);					\
252*5895Syz147064 }
253*5895Syz147064 
2540Sstevel@tonic-gate /*
2550Sstevel@tonic-gate  * dld_str.c module.
2560Sstevel@tonic-gate  */
2570Sstevel@tonic-gate 
2580Sstevel@tonic-gate extern void		dld_str_init(void);
2590Sstevel@tonic-gate extern int		dld_str_fini(void);
260269Sericheng extern dld_str_t	*dld_str_create(queue_t *, uint_t, major_t,
261269Sericheng     t_uscalar_t);
2620Sstevel@tonic-gate extern void		dld_str_destroy(dld_str_t *);
263269Sericheng extern int		dld_str_attach(dld_str_t *, t_uscalar_t);
2640Sstevel@tonic-gate extern void		dld_str_detach(dld_str_t *);
2650Sstevel@tonic-gate extern void		dld_str_rx_raw(void *, mac_resource_handle_t,
2662760Sdg199075     mblk_t *, mac_header_info_t *);
2670Sstevel@tonic-gate extern void		dld_str_rx_fastpath(void *, mac_resource_handle_t,
2682760Sdg199075     mblk_t *, mac_header_info_t *);
2690Sstevel@tonic-gate extern void		dld_str_rx_unitdata(void *, mac_resource_handle_t,
2702760Sdg199075     mblk_t *, mac_header_info_t *);
271*5895Syz147064 
272269Sericheng extern void		dld_tx_flush(dld_str_t *);
2730Sstevel@tonic-gate extern void		dld_str_notify_ind(dld_str_t *);
274*5895Syz147064 extern void		dld_tx_single(dld_str_t *, mblk_t *);
275269Sericheng extern void		str_mdata_fastpath_put(dld_str_t *, mblk_t *);
276*5895Syz147064 extern void		str_mdata_raw_put(dld_str_t *, mblk_t *);
277*5895Syz147064 
278*5895Syz147064 extern void		dld_ioctl(queue_t *, mblk_t *);
279*5895Syz147064 extern void		dld_finish_pending_task(dld_str_t *);
280269Sericheng 
2810Sstevel@tonic-gate /*
2820Sstevel@tonic-gate  * dld_proto.c
2830Sstevel@tonic-gate  */
284*5895Syz147064 extern void		dld_wput_proto_nondata(dld_str_t *, mblk_t *);
285*5895Syz147064 extern void		dld_wput_proto_data(dld_str_t *, mblk_t *);
2865113Syz147064 extern void		dld_capabilities_disable(dld_str_t *);
2870Sstevel@tonic-gate 
2880Sstevel@tonic-gate /*
2890Sstevel@tonic-gate  * Options: there should be a separate bit defined here for each
290*5895Syz147064  *	  DLD_PROP... defined in dld.h.
2910Sstevel@tonic-gate  */
292269Sericheng #define	DLD_OPT_NO_FASTPATH	0x00000001
293269Sericheng #define	DLD_OPT_NO_POLL		0x00000002
294269Sericheng #define	DLD_OPT_NO_ZEROCOPY	0x00000004
2954114Sja97890 #define	DLD_OPT_NO_SOFTRING	0x00000008
2960Sstevel@tonic-gate 
2970Sstevel@tonic-gate extern uint32_t		dld_opt;
2980Sstevel@tonic-gate 
2990Sstevel@tonic-gate /*
300*5895Syz147064  * autopush information
301*5895Syz147064  */
302*5895Syz147064 typedef struct dld_ap {
303*5895Syz147064 	datalink_id_t		da_linkid;
304*5895Syz147064 	struct dlautopush	da_ap;
305*5895Syz147064 
306*5895Syz147064 #define	da_anchor		da_ap.dap_anchor
307*5895Syz147064 #define	da_npush		da_ap.dap_npush
308*5895Syz147064 #define	da_aplist		da_ap.dap_aplist
309*5895Syz147064 
310*5895Syz147064 } dld_ap_t;
311*5895Syz147064 
312*5895Syz147064 /*
3130Sstevel@tonic-gate  * Useful macros.
3140Sstevel@tonic-gate  */
3150Sstevel@tonic-gate 
3160Sstevel@tonic-gate #define	IMPLY(p, c)	(!(p) || (c))
3170Sstevel@tonic-gate 
318269Sericheng #ifdef DEBUG
319269Sericheng #define	DLD_DBG		cmn_err
320269Sericheng #else
321269Sericheng #define	DLD_DBG		if (0) cmn_err
322269Sericheng #endif
323269Sericheng 
3240Sstevel@tonic-gate #ifdef	__cplusplus
3250Sstevel@tonic-gate }
3260Sstevel@tonic-gate #endif
3270Sstevel@tonic-gate 
3280Sstevel@tonic-gate #endif	/* _SYS_DLD_IMPL_H */
329