1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate * CDDL HEADER START
3*0Sstevel@tonic-gate *
4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*0Sstevel@tonic-gate * with the License.
8*0Sstevel@tonic-gate *
9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate * and limitations under the License.
13*0Sstevel@tonic-gate *
14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate *
20*0Sstevel@tonic-gate * CDDL HEADER END
21*0Sstevel@tonic-gate */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate * Copyright (c) 1996,1999-2000 by Sun Microsystems, Inc.
24*0Sstevel@tonic-gate * All rights reserved.
25*0Sstevel@tonic-gate */
26*0Sstevel@tonic-gate
27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
28*0Sstevel@tonic-gate
29*0Sstevel@tonic-gate /*
30*0Sstevel@tonic-gate * Main Transport Routine for DADA.
31*0Sstevel@tonic-gate *
32*0Sstevel@tonic-gate */
33*0Sstevel@tonic-gate
34*0Sstevel@tonic-gate #include <sys/dada/dada.h>
35*0Sstevel@tonic-gate #include <sys/thread.h>
36*0Sstevel@tonic-gate
37*0Sstevel@tonic-gate
38*0Sstevel@tonic-gate #define A_TO_TRAN(ap) ((ap)->a_hba_tran)
39*0Sstevel@tonic-gate #define P_TO_TRAN(pkt) ((pkt)->pkt_address.a_hba_tran)
40*0Sstevel@tonic-gate #define P_TO_ADDR(pkt) (&((pkt)->pkt_address))
41*0Sstevel@tonic-gate
42*0Sstevel@tonic-gate
43*0Sstevel@tonic-gate extern kmutex_t dcd_flag_nointr_mutex;
44*0Sstevel@tonic-gate extern kcondvar_t dcd_flag_nointr_cv;
45*0Sstevel@tonic-gate
46*0Sstevel@tonic-gate static void
dcd_flag_nointr_comp(struct dcd_pkt * pkt)47*0Sstevel@tonic-gate dcd_flag_nointr_comp(struct dcd_pkt *pkt)
48*0Sstevel@tonic-gate {
49*0Sstevel@tonic-gate
50*0Sstevel@tonic-gate mutex_enter(&dcd_flag_nointr_mutex);
51*0Sstevel@tonic-gate
52*0Sstevel@tonic-gate pkt->pkt_comp = NULL;
53*0Sstevel@tonic-gate
54*0Sstevel@tonic-gate /*
55*0Sstevel@tonic-gate * We need cv_broadcast, because there can be more than
56*0Sstevel@tonic-gate * one thread sleeping on the cv. We will wake all of them.
57*0Sstevel@tonic-gate * The correct one will continue and the reset will again go to
58*0Sstevel@tonic-gate * sleep.
59*0Sstevel@tonic-gate */
60*0Sstevel@tonic-gate cv_broadcast(&dcd_flag_nointr_cv);
61*0Sstevel@tonic-gate mutex_exit(&dcd_flag_nointr_mutex);
62*0Sstevel@tonic-gate }
63*0Sstevel@tonic-gate
64*0Sstevel@tonic-gate
65*0Sstevel@tonic-gate int
dcd_transport(struct dcd_pkt * pkt)66*0Sstevel@tonic-gate dcd_transport(struct dcd_pkt *pkt)
67*0Sstevel@tonic-gate {
68*0Sstevel@tonic-gate
69*0Sstevel@tonic-gate struct dcd_address *ap = P_TO_ADDR(pkt);
70*0Sstevel@tonic-gate extern int do_polled_io;
71*0Sstevel@tonic-gate int rval;
72*0Sstevel@tonic-gate
73*0Sstevel@tonic-gate /*
74*0Sstevel@tonic-gate * Check if we are required to do polled I/O. We can
75*0Sstevel@tonic-gate * get dcd_pkts that don't have the FLAG_NOINTR bit
76*0Sstevel@tonic-gate * set in the pkt_flags. When do_polled_io is set
77*0Sstevel@tonic-gate * we will probably be at a high IPL and not get any
78*0Sstevel@tonic-gate * command completion interrupts. We force polled I/Os
79*0Sstevel@tonic-gate * for such packets and do a callback of the completion
80*0Sstevel@tonic-gate * routine ourselves.
81*0Sstevel@tonic-gate */
82*0Sstevel@tonic-gate if (!do_polled_io && ((pkt->pkt_flags & FLAG_NOINTR) == 0)) {
83*0Sstevel@tonic-gate return ((*A_TO_TRAN(ap)->tran_start)(ap, pkt));
84*0Sstevel@tonic-gate } else if ((curthread->t_flag & T_INTR_THREAD) || (do_polled_io) ||
85*0Sstevel@tonic-gate (pkt->pkt_flags & FLAG_FORCENOINTR)) {
86*0Sstevel@tonic-gate
87*0Sstevel@tonic-gate if (pkt->pkt_flags & FLAG_FORCENOINTR) {
88*0Sstevel@tonic-gate /*
89*0Sstevel@tonic-gate * FLAG_FORCENOINTR means we do not want to rely on
90*0Sstevel@tonic-gate * device interrupts. Set the FLAG_NOINTR
91*0Sstevel@tonic-gate * so the command gets completed in polled mode.
92*0Sstevel@tonic-gate */
93*0Sstevel@tonic-gate pkt->pkt_flags &= ~FLAG_FORCENOINTR;
94*0Sstevel@tonic-gate pkt->pkt_flags |= FLAG_NOINTR;
95*0Sstevel@tonic-gate }
96*0Sstevel@tonic-gate
97*0Sstevel@tonic-gate /*
98*0Sstevel@tonic-gate * If its an interrupt thread or we already have the
99*0Sstevel@tonic-gate * the FLAG_NOINTR flag set, we go ahead and call the
100*0Sstevel@tonic-gate * the hba's start routine directly. We force polling
101*0Sstevel@tonic-gate * only if we have do_polled_io set and FLAG_NOINTR
102*0Sstevel@tonic-gate * not set.
103*0Sstevel@tonic-gate */
104*0Sstevel@tonic-gate if (!do_polled_io || (pkt->pkt_flags & FLAG_NOINTR)) {
105*0Sstevel@tonic-gate return ((*A_TO_TRAN(ap)->tran_start)(ap, pkt));
106*0Sstevel@tonic-gate } else {
107*0Sstevel@tonic-gate uint_t savef;
108*0Sstevel@tonic-gate void (*savec)();
109*0Sstevel@tonic-gate /*
110*0Sstevel@tonic-gate * save the completion routine and pkt_flags
111*0Sstevel@tonic-gate */
112*0Sstevel@tonic-gate savef = pkt->pkt_flags;
113*0Sstevel@tonic-gate savec = pkt->pkt_comp;
114*0Sstevel@tonic-gate pkt->pkt_flags |= FLAG_NOINTR;
115*0Sstevel@tonic-gate pkt->pkt_comp = 0;
116*0Sstevel@tonic-gate
117*0Sstevel@tonic-gate rval = (*A_TO_TRAN(ap)->tran_start)(ap, pkt);
118*0Sstevel@tonic-gate
119*0Sstevel@tonic-gate /*
120*0Sstevel@tonic-gate * Restore the pkt_completion routine
121*0Sstevel@tonic-gate * and pkt flags and call the completion
122*0Sstevel@tonic-gate * routine.
123*0Sstevel@tonic-gate */
124*0Sstevel@tonic-gate pkt->pkt_comp = savec;
125*0Sstevel@tonic-gate pkt->pkt_flags = savef;
126*0Sstevel@tonic-gate (*pkt->pkt_comp)(pkt);
127*0Sstevel@tonic-gate return (rval);
128*0Sstevel@tonic-gate }
129*0Sstevel@tonic-gate } else {
130*0Sstevel@tonic-gate uint_t savef;
131*0Sstevel@tonic-gate void (*savec)();
132*0Sstevel@tonic-gate int status;
133*0Sstevel@tonic-gate
134*0Sstevel@tonic-gate savef = pkt->pkt_flags;
135*0Sstevel@tonic-gate savec = pkt->pkt_comp;
136*0Sstevel@tonic-gate
137*0Sstevel@tonic-gate pkt->pkt_comp = dcd_flag_nointr_comp;
138*0Sstevel@tonic-gate pkt->pkt_flags &= ~FLAG_NOINTR;
139*0Sstevel@tonic-gate pkt->pkt_flags |= FLAG_IMMEDIATE_CB;
140*0Sstevel@tonic-gate
141*0Sstevel@tonic-gate if ((status = (*A_TO_TRAN(ap)->tran_start)(ap, pkt)) ==
142*0Sstevel@tonic-gate TRAN_ACCEPT) {
143*0Sstevel@tonic-gate mutex_enter(& dcd_flag_nointr_mutex);
144*0Sstevel@tonic-gate while (pkt->pkt_comp != NULL) {
145*0Sstevel@tonic-gate cv_wait(&dcd_flag_nointr_cv,
146*0Sstevel@tonic-gate &dcd_flag_nointr_mutex);
147*0Sstevel@tonic-gate }
148*0Sstevel@tonic-gate mutex_exit(&dcd_flag_nointr_mutex);
149*0Sstevel@tonic-gate }
150*0Sstevel@tonic-gate pkt->pkt_flags = savef;
151*0Sstevel@tonic-gate pkt->pkt_comp = savec;
152*0Sstevel@tonic-gate return (status);
153*0Sstevel@tonic-gate }
154*0Sstevel@tonic-gate }
155