xref: /titanic_41/usr/src/uts/common/io/mac/mac_hio.c (revision 0dc2366f7b9f9f36e10909b1e95edbf2a261c2ac)
1da14cebeSEric Cheng /*
2da14cebeSEric Cheng  * CDDL HEADER START
3da14cebeSEric Cheng  *
4da14cebeSEric Cheng  * The contents of this file are subject to the terms of the
5da14cebeSEric Cheng  * Common Development and Distribution License (the "License").
6da14cebeSEric Cheng  * You may not use this file except in compliance with the License.
7da14cebeSEric Cheng  *
8da14cebeSEric Cheng  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9da14cebeSEric Cheng  * or http://www.opensolaris.org/os/licensing.
10da14cebeSEric Cheng  * See the License for the specific language governing permissions
11da14cebeSEric Cheng  * and limitations under the License.
12da14cebeSEric Cheng  *
13da14cebeSEric Cheng  * When distributing Covered Code, include this CDDL HEADER in each
14da14cebeSEric Cheng  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15da14cebeSEric Cheng  * If applicable, add the following below this CDDL HEADER, with the
16da14cebeSEric Cheng  * fields enclosed by brackets "[]" replaced with your own identifying
17da14cebeSEric Cheng  * information: Portions Copyright [yyyy] [name of copyright owner]
18da14cebeSEric Cheng  *
19da14cebeSEric Cheng  * CDDL HEADER END
20da14cebeSEric Cheng  */
21da14cebeSEric Cheng /*
22*0dc2366fSVenugopal Iyer  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
23da14cebeSEric Cheng  * Use is subject to license terms.
24da14cebeSEric Cheng  */
25da14cebeSEric Cheng 
26da14cebeSEric Cheng /*
27da14cebeSEric Cheng  * MAC Hybrid I/O related code.
28da14cebeSEric Cheng  */
29da14cebeSEric Cheng 
30da14cebeSEric Cheng #include <sys/types.h>
31da14cebeSEric Cheng #include <sys/sdt.h>
32da14cebeSEric Cheng #include <sys/mac.h>
33da14cebeSEric Cheng #include <sys/mac_impl.h>
34da14cebeSEric Cheng #include <sys/mac_client_impl.h>
35*0dc2366fSVenugopal Iyer #include <sys/mac_client_priv.h>
36da14cebeSEric Cheng #include <sys/mac_soft_ring.h>
37da14cebeSEric Cheng 
38da14cebeSEric Cheng 
39da14cebeSEric Cheng /*
40da14cebeSEric Cheng  * Return the number of shares supported by the specified MAC.
41da14cebeSEric Cheng  */
42da14cebeSEric Cheng int
mac_share_capable(mac_handle_t mh)43da14cebeSEric Cheng mac_share_capable(mac_handle_t mh)
44da14cebeSEric Cheng {
45da14cebeSEric Cheng 	mac_impl_t *mip = (mac_impl_t *)mh;
46da14cebeSEric Cheng 
47da14cebeSEric Cheng 	return (mip->mi_share_capab.ms_snum);
48da14cebeSEric Cheng }
49da14cebeSEric Cheng 
50da14cebeSEric Cheng 
51da14cebeSEric Cheng /*
52da14cebeSEric Cheng  * Allocate a share to the specified MAC client. Invoked when
53da14cebeSEric Cheng  * mac_client_open() is invoked with MAC_OPEN_FLAGS_SHARES_DESIRED set.
54da14cebeSEric Cheng  */
55da14cebeSEric Cheng void
i_mac_share_alloc(mac_client_impl_t * mcip)56da14cebeSEric Cheng i_mac_share_alloc(mac_client_impl_t *mcip)
57da14cebeSEric Cheng {
58da14cebeSEric Cheng 	mac_impl_t *mip = mcip->mci_mip;
59da14cebeSEric Cheng 	int rv;
60da14cebeSEric Cheng 
61da14cebeSEric Cheng 	i_mac_perim_enter(mip);
62da14cebeSEric Cheng 
63da14cebeSEric Cheng 	ASSERT(mcip->mci_share == NULL);
64da14cebeSEric Cheng 
65da14cebeSEric Cheng 	if (mac_share_capable((mac_handle_t)mcip->mci_mip) == 0) {
66da14cebeSEric Cheng 		DTRACE_PROBE1(i__mac__share__alloc__not__sup,
67da14cebeSEric Cheng 		    mac_client_impl_t *, mcip);
68da14cebeSEric Cheng 		i_mac_perim_exit(mip);
69da14cebeSEric Cheng 		return;
70da14cebeSEric Cheng 	}
71da14cebeSEric Cheng 
72da14cebeSEric Cheng 	rv = mip->mi_share_capab.ms_salloc(mip->mi_share_capab.ms_handle,
73da14cebeSEric Cheng 	    &mcip->mci_share);
74da14cebeSEric Cheng 	DTRACE_PROBE3(i__mac__share__alloc, mac_client_impl_t *, mcip,
75da14cebeSEric Cheng 	    int, rv, mac_share_handle_t, mcip->mci_share);
76da14cebeSEric Cheng 
7708ac1c49SNicolas Droux 	mcip->mci_state_flags &= ~MCIS_SHARE_BOUND;
78da14cebeSEric Cheng 
79da14cebeSEric Cheng 	i_mac_perim_exit(mip);
80da14cebeSEric Cheng }
81da14cebeSEric Cheng 
82da14cebeSEric Cheng 
83da14cebeSEric Cheng /*
84da14cebeSEric Cheng  * Free a share previously allocated through i_mac_share_alloc().
85da14cebeSEric Cheng  * Safely handles the case when no shares were allocated to the MAC client.
86da14cebeSEric Cheng  */
87da14cebeSEric Cheng void
i_mac_share_free(mac_client_impl_t * mcip)88da14cebeSEric Cheng i_mac_share_free(mac_client_impl_t *mcip)
89da14cebeSEric Cheng {
90da14cebeSEric Cheng 	mac_impl_t *mip = mcip->mci_mip;
91da14cebeSEric Cheng 
92da14cebeSEric Cheng 	i_mac_perim_enter(mip);
93da14cebeSEric Cheng 
94da14cebeSEric Cheng 	/* MAC clients are required to unbind they shares before freeing them */
9508ac1c49SNicolas Droux 	ASSERT((mcip->mci_state_flags & MCIS_SHARE_BOUND) == 0);
96da14cebeSEric Cheng 
97da14cebeSEric Cheng 	if (mcip->mci_share == NULL) {
98da14cebeSEric Cheng 		i_mac_perim_exit(mip);
99da14cebeSEric Cheng 		return;
100da14cebeSEric Cheng 	}
101da14cebeSEric Cheng 
102da14cebeSEric Cheng 	mip->mi_share_capab.ms_sfree(mcip->mci_share);
103da14cebeSEric Cheng 	i_mac_perim_exit(mip);
104da14cebeSEric Cheng }
105da14cebeSEric Cheng 
106da14cebeSEric Cheng 
107da14cebeSEric Cheng /*
108da14cebeSEric Cheng  * Bind a share. After this operation the rings that were associated
109da14cebeSEric Cheng  * with the MAC client are mapped directly into the corresponding
110da14cebeSEric Cheng  * guest domain.
111da14cebeSEric Cheng  */
112da14cebeSEric Cheng int
mac_share_bind(mac_client_handle_t mch,uint64_t cookie,uint64_t * rcookie)113da14cebeSEric Cheng mac_share_bind(mac_client_handle_t mch, uint64_t cookie, uint64_t *rcookie)
114da14cebeSEric Cheng {
115da14cebeSEric Cheng 	mac_client_impl_t *mcip = (mac_client_impl_t *)mch;
116da14cebeSEric Cheng 	mac_impl_t *mip = mcip->mci_mip;
117da14cebeSEric Cheng 	int rv;
118da14cebeSEric Cheng 
119da14cebeSEric Cheng 	i_mac_perim_enter(mip);
120da14cebeSEric Cheng 
121da14cebeSEric Cheng 	if (mcip->mci_share == NULL) {
122da14cebeSEric Cheng 		i_mac_perim_exit(mip);
123da14cebeSEric Cheng 		return (ENOTSUP);
124da14cebeSEric Cheng 	}
125da14cebeSEric Cheng 
12608ac1c49SNicolas Droux 	ASSERT((mcip->mci_state_flags & MCIS_SHARE_BOUND) == 0);
127da14cebeSEric Cheng 
128da14cebeSEric Cheng 	/*
129da14cebeSEric Cheng 	 * Temporarly suspend the TX traffic for that client to make sure
130da14cebeSEric Cheng 	 * there are no in flight packets through a transmit ring
131da14cebeSEric Cheng 	 * which is being bound to another domain.
132da14cebeSEric Cheng 	 */
133*0dc2366fSVenugopal Iyer 	mac_tx_client_quiesce(mch);
134da14cebeSEric Cheng 
135da14cebeSEric Cheng 	/*
136da14cebeSEric Cheng 	 * For the receive path, no traffic will be sent up through
137da14cebeSEric Cheng 	 * the rings to the IO domain. For TX, we need to ensure
138da14cebeSEric Cheng 	 * that traffic sent by the MAC client are sent through
139da14cebeSEric Cheng 	 * the default ring.
140da14cebeSEric Cheng 	 *
14108ac1c49SNicolas Droux 	 * For the transmit path we ensure that packets are sent through the
14208ac1c49SNicolas Droux 	 * default ring if the share of the MAC client is bound, see MAC_TX().
143da14cebeSEric Cheng 	 */
144da14cebeSEric Cheng 
145da14cebeSEric Cheng 	rv = mip->mi_share_capab.ms_sbind(mcip->mci_share, cookie, rcookie);
146da14cebeSEric Cheng 	if (rv == 0)
14708ac1c49SNicolas Droux 		mcip->mci_state_flags |= MCIS_SHARE_BOUND;
148da14cebeSEric Cheng 
149da14cebeSEric Cheng 	/*
15008ac1c49SNicolas Droux 	 * Resume transmit traffic for the MAC client.
151da14cebeSEric Cheng 	 */
152*0dc2366fSVenugopal Iyer 	mac_tx_client_restart(mch);
153da14cebeSEric Cheng 
154da14cebeSEric Cheng 	i_mac_perim_exit(mip);
155da14cebeSEric Cheng 
156da14cebeSEric Cheng 	return (rv);
157da14cebeSEric Cheng }
158da14cebeSEric Cheng 
159da14cebeSEric Cheng 
160da14cebeSEric Cheng /*
161da14cebeSEric Cheng  * Unbind a share.
162da14cebeSEric Cheng  */
163da14cebeSEric Cheng void
mac_share_unbind(mac_client_handle_t mch)164da14cebeSEric Cheng mac_share_unbind(mac_client_handle_t mch)
165da14cebeSEric Cheng {
166da14cebeSEric Cheng 	mac_client_impl_t *mcip = (mac_client_impl_t *)mch;
167da14cebeSEric Cheng 	mac_impl_t *mip = mcip->mci_mip;
168da14cebeSEric Cheng 
169da14cebeSEric Cheng 	i_mac_perim_enter(mip);
170da14cebeSEric Cheng 
171da14cebeSEric Cheng 	if (mcip->mci_share == NULL) {
172da14cebeSEric Cheng 		i_mac_perim_exit(mip);
173da14cebeSEric Cheng 		return;
174da14cebeSEric Cheng 	}
175da14cebeSEric Cheng 
176da14cebeSEric Cheng 	mip->mi_share_capab.ms_sunbind(mcip->mci_share);
177da14cebeSEric Cheng 
17808ac1c49SNicolas Droux 	mcip->mci_state_flags &= ~MCIS_SHARE_BOUND;
17908ac1c49SNicolas Droux 
18008ac1c49SNicolas Droux 	/*
18108ac1c49SNicolas Droux 	 * If the link state changed while the share was bound, the
18208ac1c49SNicolas Droux 	 * soft rings fanout associated with the client would have not
18308ac1c49SNicolas Droux 	 * been updated by mac_fanout_recompute(). Do the check here
18408ac1c49SNicolas Droux 	 * now that the share has been unbound.
18508ac1c49SNicolas Droux 	 */
186*0dc2366fSVenugopal Iyer 	mac_fanout_recompute_client(mcip, NULL);
187da14cebeSEric Cheng 
188da14cebeSEric Cheng 	i_mac_perim_exit(mip);
189da14cebeSEric Cheng }
190