xref: /onnv-gate/usr/src/uts/common/sys/dls_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
52311Sseb  * Common Development and Distribution License (the "License").
62311Sseb  * 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_DLS_IMPL_H
270Sstevel@tonic-gate #define	_SYS_DLS_IMPL_H
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
300Sstevel@tonic-gate 
310Sstevel@tonic-gate #include <sys/stream.h>
320Sstevel@tonic-gate #include <sys/dls.h>
330Sstevel@tonic-gate #include <sys/mac.h>
34269Sericheng #include <sys/modhash.h>
350Sstevel@tonic-gate #include <sys/kstat.h>
360Sstevel@tonic-gate #include <net/if.h>
371184Skrgopi #include <sys/dlpi.h>
381184Skrgopi #include <sys/dls_soft_ring.h>
390Sstevel@tonic-gate 
400Sstevel@tonic-gate #ifdef	__cplusplus
410Sstevel@tonic-gate extern "C" {
420Sstevel@tonic-gate #endif
430Sstevel@tonic-gate 
440Sstevel@tonic-gate typedef struct dls_multicst_addr_s	dls_multicst_addr_t;
450Sstevel@tonic-gate 
460Sstevel@tonic-gate struct dls_multicst_addr_s {
470Sstevel@tonic-gate 	dls_multicst_addr_t	*dma_nextp;
482311Sseb 	uint8_t			dma_addr[MAXMACADDRLEN];
490Sstevel@tonic-gate };
500Sstevel@tonic-gate 
510Sstevel@tonic-gate typedef	struct dls_link_s	dls_link_t;
520Sstevel@tonic-gate 
530Sstevel@tonic-gate struct dls_link_s {
540Sstevel@tonic-gate 	char			dl_name[MAXNAMELEN];
550Sstevel@tonic-gate 	mac_handle_t		dl_mh;
560Sstevel@tonic-gate 	const mac_info_t	*dl_mip;
570Sstevel@tonic-gate 	mac_rx_handle_t		dl_mrh;
580Sstevel@tonic-gate 	mac_txloop_handle_t	dl_mth;
590Sstevel@tonic-gate 	uint_t			dl_ref;
600Sstevel@tonic-gate 	uint_t			dl_macref;
61269Sericheng 	mod_hash_t		*dl_impl_hash;
62269Sericheng 	krwlock_t		dl_impl_lock;
63269Sericheng 	uint_t			dl_impl_count;
6456Smeem 	kmutex_t		dl_promisc_lock;
650Sstevel@tonic-gate 	uint_t			dl_npromisc;
660Sstevel@tonic-gate 	uint_t			dl_nactive;
670Sstevel@tonic-gate 	uint32_t		dl_unknowns;
680Sstevel@tonic-gate 	kmutex_t		dl_lock;
690Sstevel@tonic-gate };
700Sstevel@tonic-gate 
713448Sdh155122 typedef struct dls_impl_s dls_impl_t;
723448Sdh155122 typedef struct dls_head_s dls_head_t;
733448Sdh155122 
74*5895Syz147064 /*
75*5895Syz147064  * The maximum length of an SPA (subnetwork point of attachment).  It is of
76*5895Syz147064  * the form <macname/vid>.
77*5895Syz147064  */
78*5895Syz147064 #define	MAXSPALEN		(MAXNAMELEN + 5)
79*5895Syz147064 
800Sstevel@tonic-gate typedef struct dls_vlan_s {
81*5895Syz147064 	/*
82*5895Syz147064 	 * The following fields will not change after dls_vlan_t creation.
83*5895Syz147064 	 */
840Sstevel@tonic-gate 	dls_link_t		*dv_dlp;
850Sstevel@tonic-gate 	uint16_t		dv_id;
86*5895Syz147064 
87*5895Syz147064 	/*
88*5895Syz147064 	 * Unique SPA (of the form <macname/vid>) identifying a data-link;
89*5895Syz147064 	 * is needed to avoid name collisions between an explicitly and
90*5895Syz147064 	 * implicitly created VLANs.
91*5895Syz147064 	 */
92*5895Syz147064 	char			dv_spa[MAXSPALEN];
93*5895Syz147064 
94*5895Syz147064 	/*
95*5895Syz147064 	 * The ppa value of the associated device. Used to derive this link's
96*5895Syz147064 	 * devfs node name.
97*5895Syz147064 	 */
98*5895Syz147064 	uint_t			dv_ppa;
99*5895Syz147064 
100*5895Syz147064 	/*
101*5895Syz147064 	 * The dev_t used to access this dls_vlan_t.
102*5895Syz147064 	 */
103*5895Syz147064 	dev_t			dv_dev;
104*5895Syz147064 
105*5895Syz147064 	dev_info_t		*dv_dip;
1060Sstevel@tonic-gate 	kstat_t			*dv_ksp;
107*5895Syz147064 	uint32_t		dv_force : 1;
108*5895Syz147064 
109*5895Syz147064 	/*
110*5895Syz147064 	 * The following fields are protected by dv_lock.
111*5895Syz147064 	 */
112*5895Syz147064 	kmutex_t		dv_lock;
113*5895Syz147064 
114*5895Syz147064 	/*
115*5895Syz147064 	 * Reference count of dls_impl_t plus explicit creation of the link
116*5895Syz147064 	 */
117*5895Syz147064 	uint_t			dv_ref;
118*5895Syz147064 
119*5895Syz147064 	/*
120*5895Syz147064 	 * The reference count of this vlan is opened in its own zone.
121*5895Syz147064 	 */
122*5895Syz147064 	uint_t			dv_zone_ref;
1233448Sdh155122 	zoneid_t		dv_zid;
1240Sstevel@tonic-gate } dls_vlan_t;
1250Sstevel@tonic-gate 
1260Sstevel@tonic-gate struct dls_impl_s {
1270Sstevel@tonic-gate 	dls_impl_t			*di_nextp;
128269Sericheng 	dls_head_t			*di_headp;
1290Sstevel@tonic-gate 	dls_vlan_t			*di_dvp;
1300Sstevel@tonic-gate 	mac_handle_t			di_mh;
1310Sstevel@tonic-gate 	mac_notify_handle_t		di_mnh;
1320Sstevel@tonic-gate 	const mac_info_t		*di_mip;
1330Sstevel@tonic-gate 	krwlock_t			di_lock;
1340Sstevel@tonic-gate 	uint16_t			di_sap;
1350Sstevel@tonic-gate 	uint_t				di_promisc;
1360Sstevel@tonic-gate 	dls_multicst_addr_t		*di_dmap;
1370Sstevel@tonic-gate 	dls_rx_t			di_rx;
1380Sstevel@tonic-gate 	void				*di_rx_arg;
1391184Skrgopi 	mac_resource_add_t		di_ring_add;
14056Smeem 	const mac_txinfo_t		*di_txinfo;
141*5895Syz147064 	uint_t				di_bound : 1,
142*5895Syz147064 					di_removing : 1,
143*5895Syz147064 					di_active : 1,
144*5895Syz147064 					di_local : 1;
145*5895Syz147064 
1462311Sseb 	uint8_t				di_unicst_addr[MAXMACADDRLEN];
1471184Skrgopi 	soft_ring_t			**di_soft_ring_list;
1481184Skrgopi 	uint_t				di_soft_ring_size;
149*5895Syz147064 	dls_dl_handle_t			di_ddh;
1500Sstevel@tonic-gate };
1510Sstevel@tonic-gate 
152269Sericheng struct dls_head_s {
153269Sericheng 	dls_impl_t			*dh_list;
154269Sericheng 	uint_t				dh_ref;
155269Sericheng 	mod_hash_key_t			dh_key;
156269Sericheng };
157269Sericheng 
1580Sstevel@tonic-gate extern void		dls_link_init(void);
1590Sstevel@tonic-gate extern int		dls_link_fini(void);
1605733Syz147064 extern int		dls_link_hold(const char *, dls_link_t **);
1610Sstevel@tonic-gate extern void		dls_link_rele(dls_link_t *);
1620Sstevel@tonic-gate extern void		dls_link_add(dls_link_t *, uint32_t, dls_impl_t *);
1630Sstevel@tonic-gate extern void		dls_link_remove(dls_link_t *, dls_impl_t *);
1642311Sseb extern int		dls_link_header_info(dls_link_t *, mblk_t *,
165*5895Syz147064 			    mac_header_info_t *);
1660Sstevel@tonic-gate extern int		dls_mac_hold(dls_link_t *);
1670Sstevel@tonic-gate extern void		dls_mac_rele(dls_link_t *);
168*5895Syz147064 extern boolean_t	dls_mac_active_set(dls_link_t *);
169*5895Syz147064 extern void		dls_mac_active_clear(dls_link_t *);
1700Sstevel@tonic-gate 
1711184Skrgopi extern void		dls_mac_stat_create(dls_vlan_t *);
1721184Skrgopi extern void		dls_mac_stat_destroy(dls_vlan_t *);
1730Sstevel@tonic-gate 
1740Sstevel@tonic-gate extern void		dls_vlan_init(void);
1750Sstevel@tonic-gate extern int		dls_vlan_fini(void);
176*5895Syz147064 extern int		dls_vlan_hold(const char *, uint16_t, dls_vlan_t **,
177*5895Syz147064 			    boolean_t, boolean_t);
178*5895Syz147064 extern int		dls_vlan_hold_by_dev(dev_t, dls_vlan_t **);
1790Sstevel@tonic-gate extern void		dls_vlan_rele(dls_vlan_t *);
180*5895Syz147064 extern int		dls_vlan_destroy(const char *, uint16_t);
181*5895Syz147064 extern int		dls_vlan_create(const char *, uint16_t, boolean_t);
182*5895Syz147064 extern int		dls_vlan_setzid(const char *, uint16_t, zoneid_t);
183*5895Syz147064 extern int		dls_stat_update(kstat_t *, dls_vlan_t *, int);
184*5895Syz147064 extern int		dls_stat_create(const char *, int, const char *,
185*5895Syz147064 			    int (*)(struct kstat *, int), void *, kstat_t **);
186*5895Syz147064 
187*5895Syz147064 extern int		dls_devnet_open_by_dev(dev_t, dls_vlan_t **,
188*5895Syz147064 			    dls_dl_handle_t *);
1890Sstevel@tonic-gate 
1900Sstevel@tonic-gate extern void		dls_init(void);
1910Sstevel@tonic-gate extern int		dls_fini(void);
1925733Syz147064 extern void		dls_link_txloop(void *, mblk_t *);
1932311Sseb extern boolean_t	dls_accept(dls_impl_t *, mac_header_info_t *,
194*5895Syz147064 			    dls_rx_t *, void **);
1952760Sdg199075 extern boolean_t	dls_accept_loopback(dls_impl_t *, mac_header_info_t *,
196*5895Syz147064 			    dls_rx_t *, void **);
197*5895Syz147064 
198*5895Syz147064 extern void		dls_mgmt_init(void);
199*5895Syz147064 extern void		dls_mgmt_fini(void);
200*5895Syz147064 
201*5895Syz147064 extern int		dls_mgmt_get_phydev(datalink_id_t, dev_t *);
2020Sstevel@tonic-gate 
2030Sstevel@tonic-gate #ifdef	__cplusplus
2040Sstevel@tonic-gate }
2050Sstevel@tonic-gate #endif
2060Sstevel@tonic-gate 
2070Sstevel@tonic-gate #endif	/* _SYS_DLS_IMPL_H */
208