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 2004 Sun Microsystems, Inc. All rights reserved.
24*0Sstevel@tonic-gate * Use is subject to license terms.
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 #include <sys/dada/dada.h>
30*0Sstevel@tonic-gate
31*0Sstevel@tonic-gate
32*0Sstevel@tonic-gate /*
33*0Sstevel@tonic-gate * Utility DADA routines
34*0Sstevel@tonic-gate */
35*0Sstevel@tonic-gate
36*0Sstevel@tonic-gate
37*0Sstevel@tonic-gate /*
38*0Sstevel@tonic-gate * Polling support routines
39*0Sstevel@tonic-gate */
40*0Sstevel@tonic-gate
41*0Sstevel@tonic-gate extern uintptr_t dcd_callback_id;
42*0Sstevel@tonic-gate
43*0Sstevel@tonic-gate
44*0Sstevel@tonic-gate #ifdef NOT_NEEDED
45*0Sstevel@tonic-gate static int dcd_poll_busycnt = DCD_POLL_TIMEOUT;
46*0Sstevel@tonic-gate #endif
47*0Sstevel@tonic-gate
48*0Sstevel@tonic-gate
49*0Sstevel@tonic-gate /*
50*0Sstevel@tonic-gate * Common buffer for dcd_lod
51*0Sstevel@tonic-gate */
52*0Sstevel@tonic-gate
53*0Sstevel@tonic-gate extern kmutex_t dcd_log_mutex;
54*0Sstevel@tonic-gate static char dcd_log_buffer[256];
55*0Sstevel@tonic-gate
56*0Sstevel@tonic-gate
57*0Sstevel@tonic-gate #define A_TO_TRAN(ap) (ap->a_hba_tran)
58*0Sstevel@tonic-gate #define P_TO_TRAN(pkt) ((pkt)->pkt_address.a_hba_tran)
59*0Sstevel@tonic-gate #define P_TO_ADDR(pkt) (&((pkt)->pkt_address))
60*0Sstevel@tonic-gate
61*0Sstevel@tonic-gate
62*0Sstevel@tonic-gate #ifdef NOT_NEEDED
63*0Sstevel@tonic-gate int
dcd_poll(struct dcd_pkt * pkt)64*0Sstevel@tonic-gate dcd_poll(struct dcd_pkt *pkt)
65*0Sstevel@tonic-gate {
66*0Sstevel@tonic-gate
67*0Sstevel@tonic-gate register busy_count, rval = -1, savef;
68*0Sstevel@tonic-gate clock_t savet;
69*0Sstevel@tonic-gate void (*savec)();
70*0Sstevel@tonic-gate
71*0Sstevel@tonic-gate
72*0Sstevel@tonic-gate /*
73*0Sstevel@tonic-gate * Save old flags
74*0Sstevel@tonic-gate */
75*0Sstevel@tonic-gate savef = pkt->pkt_flags;
76*0Sstevel@tonic-gate savec = pkt->pkt_comp;
77*0Sstevel@tonic-gate savet = pkt->pkt_time;
78*0Sstevel@tonic-gate
79*0Sstevel@tonic-gate pkt->pkt_flags |= FLAG_NOINTR;
80*0Sstevel@tonic-gate
81*0Sstevel@tonic-gate
82*0Sstevel@tonic-gate /*
83*0Sstevel@tonic-gate * Set the Pkt_comp to NULL
84*0Sstevel@tonic-gate */
85*0Sstevel@tonic-gate
86*0Sstevel@tonic-gate pkt->pkt_comp = 0;
87*0Sstevel@tonic-gate
88*0Sstevel@tonic-gate /*
89*0Sstevel@tonic-gate * Set the Pkt time for the polled command
90*0Sstevel@tonic-gate */
91*0Sstevel@tonic-gate if (pkt->pkt_time == 0) {
92*0Sstevel@tonic-gate pkt->pkt_time = DCD_POLL_TIMEOUT;
93*0Sstevel@tonic-gate }
94*0Sstevel@tonic-gate
95*0Sstevel@tonic-gate
96*0Sstevel@tonic-gate /* Now transport the command */
97*0Sstevel@tonic-gate for (busy_count = 0; busy_count < dcd_poll_busycnt; busy_count++) {
98*0Sstevel@tonic-gate if (dcd_transport(pkt) != TRAN_ACCEPT) {
99*0Sstevel@tonic-gate break;
100*0Sstevel@tonic-gate }
101*0Sstevel@tonic-gate if (pkt->pkt_reason == CMD_INCOMPLETE && pkt->pkt_state == 0) {
102*0Sstevel@tonic-gate drv_usecwait(1000000);
103*0Sstevel@tonic-gate } else if (pkt->pkt_reason != CMD_CMPLT) {
104*0Sstevel@tonic-gate break;
105*0Sstevel@tonic-gate } else if (((*pkt->pkt_scbp) & STATUS_ATA_MASK)
106*0Sstevel@tonic-gate == STATUS_ATA_BUSY) {
107*0Sstevel@tonic-gate drv_usecwait(1000000);
108*0Sstevel@tonic-gate } else {
109*0Sstevel@tonic-gate rval = 0;
110*0Sstevel@tonic-gate break;
111*0Sstevel@tonic-gate }
112*0Sstevel@tonic-gate }
113*0Sstevel@tonic-gate
114*0Sstevel@tonic-gate pkt->pkt_flags = savef;
115*0Sstevel@tonic-gate pkt->pkt_comp = savec;
116*0Sstevel@tonic-gate pkt->pkt_time = savet;
117*0Sstevel@tonic-gate return (rval);
118*0Sstevel@tonic-gate }
119*0Sstevel@tonic-gate #endif
120*0Sstevel@tonic-gate
121*0Sstevel@tonic-gate
122*0Sstevel@tonic-gate /*PRINTFLIKE4*/
123*0Sstevel@tonic-gate void
dcd_log(dev_info_t * dev,char * label,uint_t level,const char * fmt,...)124*0Sstevel@tonic-gate dcd_log(dev_info_t *dev, char *label, uint_t level, const char *fmt, ...)
125*0Sstevel@tonic-gate {
126*0Sstevel@tonic-gate
127*0Sstevel@tonic-gate auto char name[256];
128*0Sstevel@tonic-gate va_list ap;
129*0Sstevel@tonic-gate int log_only = 0;
130*0Sstevel@tonic-gate int boot_only = 0;
131*0Sstevel@tonic-gate int console_only = 0;
132*0Sstevel@tonic-gate
133*0Sstevel@tonic-gate
134*0Sstevel@tonic-gate mutex_enter(&dcd_log_mutex);
135*0Sstevel@tonic-gate
136*0Sstevel@tonic-gate
137*0Sstevel@tonic-gate if (dev) {
138*0Sstevel@tonic-gate
139*0Sstevel@tonic-gate if (level == CE_PANIC || level == CE_WARN) {
140*0Sstevel@tonic-gate (void) sprintf(name, "%s (%s%d):\n",
141*0Sstevel@tonic-gate ddi_pathname(dev, dcd_log_buffer), label,
142*0Sstevel@tonic-gate ddi_get_instance(dev));
143*0Sstevel@tonic-gate } else if (level == CE_NOTE ||
144*0Sstevel@tonic-gate level >= (uint_t)DCD_DEBUG) {
145*0Sstevel@tonic-gate (void) sprintf(name, "%s%d:", label,
146*0Sstevel@tonic-gate ddi_get_instance(dev));
147*0Sstevel@tonic-gate } else if (level == CE_CONT) {
148*0Sstevel@tonic-gate name[0] = '\0';
149*0Sstevel@tonic-gate }
150*0Sstevel@tonic-gate } else {
151*0Sstevel@tonic-gate (void) sprintf(name, "%s:", label);
152*0Sstevel@tonic-gate }
153*0Sstevel@tonic-gate
154*0Sstevel@tonic-gate
155*0Sstevel@tonic-gate va_start(ap, fmt);
156*0Sstevel@tonic-gate (void) vsprintf(dcd_log_buffer, fmt, ap);
157*0Sstevel@tonic-gate va_end(ap);
158*0Sstevel@tonic-gate
159*0Sstevel@tonic-gate
160*0Sstevel@tonic-gate switch (dcd_log_buffer[0]) {
161*0Sstevel@tonic-gate case '!':
162*0Sstevel@tonic-gate log_only = 1;
163*0Sstevel@tonic-gate break;
164*0Sstevel@tonic-gate case '?':
165*0Sstevel@tonic-gate boot_only = 1;
166*0Sstevel@tonic-gate break;
167*0Sstevel@tonic-gate case '^':
168*0Sstevel@tonic-gate console_only = 1;
169*0Sstevel@tonic-gate break;
170*0Sstevel@tonic-gate }
171*0Sstevel@tonic-gate
172*0Sstevel@tonic-gate switch (level) {
173*0Sstevel@tonic-gate
174*0Sstevel@tonic-gate case CE_NOTE:
175*0Sstevel@tonic-gate level = CE_CONT;
176*0Sstevel@tonic-gate /* FALLTHROUGH */
177*0Sstevel@tonic-gate case CE_CONT:
178*0Sstevel@tonic-gate case CE_WARN:
179*0Sstevel@tonic-gate case CE_PANIC:
180*0Sstevel@tonic-gate if (boot_only) {
181*0Sstevel@tonic-gate cmn_err(level, "?%s\t%s", name,
182*0Sstevel@tonic-gate &dcd_log_buffer[1]);
183*0Sstevel@tonic-gate } else if (console_only) {
184*0Sstevel@tonic-gate cmn_err(level, "^%s\t%s", name,
185*0Sstevel@tonic-gate &dcd_log_buffer[1]);
186*0Sstevel@tonic-gate } else if (log_only) {
187*0Sstevel@tonic-gate cmn_err(level, "!%s\t%s", name,
188*0Sstevel@tonic-gate &dcd_log_buffer[1]);
189*0Sstevel@tonic-gate } else {
190*0Sstevel@tonic-gate cmn_err(level, "%s\t%s", name,
191*0Sstevel@tonic-gate dcd_log_buffer);
192*0Sstevel@tonic-gate }
193*0Sstevel@tonic-gate break;
194*0Sstevel@tonic-gate case (uint_t)DCD_DEBUG:
195*0Sstevel@tonic-gate default:
196*0Sstevel@tonic-gate cmn_err(CE_CONT, "^DEBUG: %s\t%s\n", name,
197*0Sstevel@tonic-gate dcd_log_buffer);
198*0Sstevel@tonic-gate break;
199*0Sstevel@tonic-gate }
200*0Sstevel@tonic-gate
201*0Sstevel@tonic-gate mutex_exit(&dcd_log_mutex);
202*0Sstevel@tonic-gate }
203