4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <sys/dada/dada.h>
33 * Utility DADA routines
38 * Polling support routines
41 extern uintptr_t dcd_callback_id
;
45 static int dcd_poll_busycnt
= DCD_POLL_TIMEOUT
;
50 * Common buffer for dcd_lod
53 extern kmutex_t dcd_log_mutex
;
54 static char dcd_log_buffer
[256];
57 #define A_TO_TRAN(ap) (ap->a_hba_tran)
58 #define P_TO_TRAN(pkt) ((pkt)->pkt_address.a_hba_tran)
59 #define P_TO_ADDR(pkt) (&((pkt)->pkt_address))
64 dcd_poll(struct dcd_pkt
*pkt
)
67 register busy_count
, rval
= -1, savef
;
75 savef
= pkt
->pkt_flags
;
76 savec
= pkt
->pkt_comp
;
77 savet
= pkt
->pkt_time
;
79 pkt
->pkt_flags
|= FLAG_NOINTR
;
83 * Set the Pkt_comp to NULL
89 * Set the Pkt time for the polled command
91 if (pkt
->pkt_time
== 0) {
92 pkt
->pkt_time
= DCD_POLL_TIMEOUT
;
96 /* Now transport the command */
97 for (busy_count
= 0; busy_count
< dcd_poll_busycnt
; busy_count
++) {
98 if (dcd_transport(pkt
) != TRAN_ACCEPT
) {
101 if (pkt
->pkt_reason
== CMD_INCOMPLETE
&& pkt
->pkt_state
== 0) {
102 drv_usecwait(1000000);
103 } else if (pkt
->pkt_reason
!= CMD_CMPLT
) {
105 } else if (((*pkt
->pkt_scbp
) & STATUS_ATA_MASK
)
106 == STATUS_ATA_BUSY
) {
107 drv_usecwait(1000000);
114 pkt
->pkt_flags
= savef
;
115 pkt
->pkt_comp
= savec
;
116 pkt
->pkt_time
= savet
;
124 dcd_log(dev_info_t
*dev
, char *label
, uint_t level
, const char *fmt
, ...)
131 int console_only
= 0;
134 mutex_enter(&dcd_log_mutex
);
139 if (level
== CE_PANIC
|| level
== CE_WARN
) {
140 (void) sprintf(name
, "%s (%s%d):\n",
141 ddi_pathname(dev
, dcd_log_buffer
), label
,
142 ddi_get_instance(dev
));
143 } else if (level
== CE_NOTE
||
144 level
>= (uint_t
)DCD_DEBUG
) {
145 (void) sprintf(name
, "%s%d:", label
,
146 ddi_get_instance(dev
));
147 } else if (level
== CE_CONT
) {
151 (void) sprintf(name
, "%s:", label
);
156 (void) vsprintf(dcd_log_buffer
, fmt
, ap
);
160 switch (dcd_log_buffer
[0]) {
181 cmn_err(level
, "?%s\t%s", name
,
183 } else if (console_only
) {
184 cmn_err(level
, "^%s\t%s", name
,
186 } else if (log_only
) {
187 cmn_err(level
, "!%s\t%s", name
,
190 cmn_err(level
, "%s\t%s", name
,
194 case (uint_t
)DCD_DEBUG
:
196 cmn_err(CE_CONT
, "^DEBUG: %s\t%s\n", name
,
201 mutex_exit(&dcd_log_mutex
);