1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* ISSUES
*/
#include <sys/scsi/scsi.h>
#include <sys/note.h>
#include <sys/scsi/adapters/fasreg.h>
#include <sys/scsi/adapters/fasvar.h>
#include <sys/scsi/adapters/fascmd.h>
#include <sys/vtrace.h>
#ifdef FASDEBUG
extern int fasdebug;
extern int fasdebug_instance; /* debug all instances */
#endif /* FASDEBUG */
void fas_complete_arq_pkt(struct scsi_pkt *pkt);
void fas_call_pkt_comp(register struct fas *fas,
register struct fas_cmd *sp);
void fas_empty_callbackQ(struct fas *fas);
int fas_init_callbacks(struct fas *fas);
void fas_destroy_callbacks(struct fas *fas);
void fas_printf(struct fas *fas, const char *fmt, ...);
int
fas_init_callbacks(struct fas *fas)
{
mutex_init(&fas->f_c_mutex, NULL, MUTEX_DRIVER, fas->f_iblock);
return (0);
}
void
fas_destroy_callbacks(struct fas *fas)
{
mutex_destroy(&fas->f_c_mutex);
}
void
fas_empty_callbackQ(struct fas *fas)
{
register struct fas_cmd *sp;
TRACE_0(TR_FAC_SCSI, TR_FAS_EMPTY_CALLBACKQ_START,
"fas_empty_callbackQ_start");
mutex_enter(&fas->f_c_mutex);
/*
* don't recurse into calling back: the target driver
* may call scsi_transport() again which may call
* fas_empty_callbackQ again
*/
if (fas->f_c_in_callback) {
goto done;
}
fas->f_c_in_callback = 1;
while (fas->f_c_qf) {
register struct fas_cmd *qf = fas->f_c_qf;
fas->f_c_qf = fas->f_c_qb = NULL;
mutex_exit(&fas->f_c_mutex);
while (qf) {
sp = qf;
qf = sp->cmd_forw;
(*sp->cmd_pkt->pkt_comp)(sp->cmd_pkt);
}
mutex_enter(&fas->f_c_mutex);
}
fas->f_c_in_callback = 0;
done:
mutex_exit(&fas->f_c_mutex);
TRACE_0(TR_FAC_SCSI, TR_FAS_EMPTY_CALLBACKQ_END,
"fas_empty_callbackQ_end");
}
/*
* fas_call_pkt_comp does sanity checking to ensure that we don't
* call completion twice on the same packet or a packet that has been freed.
* if there is a completion function specified, the packet is queued
* up and it is left to the fas_callback thread to empty the queue at
* a lower priority; note that there is one callback queue per fas
*
* we use a separate thread for calling back into the target driver
* this thread unqueues packets from the callback queue
*/
void
fas_call_pkt_comp(register struct fas *fas, register struct fas_cmd *sp)
{
TRACE_0(TR_FAC_SCSI, TR_FAS_CALL_PKT_COMP_START,
"fas_call_pkt_comp_start");
ASSERT(sp != 0);
ASSERT((sp->cmd_flags & CFLAG_COMPLETED) == 0);
ASSERT((sp->cmd_flags & CFLAG_FREE) == 0);
ASSERT(sp->cmd_flags & CFLAG_FINISHED);
ASSERT(fas->f_ncmds >= fas->f_ndisc);
ASSERT((sp->cmd_flags & CFLAG_CMDDISC) == 0);
ASSERT(sp != fas->f_current_sp);
ASSERT(sp != fas->f_active[sp->cmd_slot]->f_slot[sp->cmd_tag[1]]);
sp->cmd_flags &= ~CFLAG_IN_TRANSPORT;
sp->cmd_flags |= CFLAG_COMPLETED;
sp->cmd_qfull_retries = 0;
/*
* if this was an auto request sense, complete immediately to free
* the arq pkt
*/
if (sp->cmd_pkt->pkt_comp && !(sp->cmd_flags & CFLAG_CMDARQ)) {
if (sp->cmd_pkt->pkt_reason != CMD_CMPLT) {
IPRINTF6("completion for %d.%d, sp=0x%p, "
"reason=%s, stats=%x, state=%x\n",
Tgt(sp), Lun(sp), (void *)sp,
scsi_rname(sp->cmd_pkt->pkt_reason),
sp->cmd_pkt->pkt_statistics,
sp->cmd_pkt->pkt_state);
} else {
EPRINTF2("completion queued for %d.%dn",
Tgt(sp), Lun(sp));
}
/*
* append the packet or start a new queue
*/
mutex_enter(&fas->f_c_mutex);
if (fas->f_c_qf) {
/*
* add to tail
*/
register struct fas_cmd *dp = fas->f_c_qb;
ASSERT(dp != NULL);
fas->f_c_qb = sp;
sp->cmd_forw = NULL;
dp->cmd_forw = sp;
} else {
/*
* start new queue
*/
fas->f_c_qf = fas->f_c_qb = sp;
sp->cmd_forw = NULL;
}
mutex_exit(&fas->f_c_mutex);
} else if ((sp->cmd_flags & CFLAG_CMDARQ) && sp->cmd_pkt->pkt_comp) {
/*
* pkt_comp may be NULL when we are aborting/resetting but then
* the callback will be redone later
*/
fas_complete_arq_pkt(sp->cmd_pkt);
} else {
EPRINTF2("No completion routine for 0x%p reason %x\n",
(void *)sp, sp->cmd_pkt->pkt_reason);
}
TRACE_0(TR_FAC_SCSI, TR_FAS_CALL_PKT_COMP_END,
"fas_call_pkt_comp_end");
}
|