isp_netbsd.c revision 1.1 1 /* $NetBSD: isp_netbsd.c,v 1.1 1998/07/15 19:44:04 mjacob Exp $ */
2 /* $Id: isp_netbsd.c,v 1.1 1998/07/15 19:44:04 mjacob Exp $ */
3 /*
4 * Platform (NetBSD) dependent common attachment code for Qlogic adapters.
5 *
6 *---------------------------------------
7 * Copyright (c) 1997, 1998 by Matthew Jacob
8 * NASA/Ames Research Center
9 * All rights reserved.
10 *---------------------------------------
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice immediately at the beginning of the file, without modification,
17 * this list of conditions, and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. The name of the author may not be used to endorse or promote products
22 * derived from this software without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
28 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * The author may be reached via electronic communications at
37 *
38 * mjacob (at) nas.nasa.gov
39 * mjacob (at) feral.com
40 *
41 * or, via United States Postal Address
42 *
43 * Matthew Jacob
44 * Feral Software
45 * 2339 3rd Street
46 * Suite 24
47 * San Francisco, CA, 94107
48 */
49 /*
50 * $Log: isp_netbsd.c,v $
51 * Revision 1.1 1998/07/15 19:44:04 mjacob
52 * NetBSD OS specific routines and definitions.
53 *
54 * Revision 1.5 1998/07/15 19:35:35 mjacob
55 * checkpoint
56 *
57 * Revision 1.4 1998/06/12 19:48:24 mjacob
58 * checkpoint
59 *
60 * Revision 1.3 1998/04/15 17:40:25 mjacob
61 * oops
62 *
63 * Revision 1.2 1998/04/14 17:31:49 mjacob
64 * fix headers
65 *
66 */
67
68 #include <dev/ic/isp_netbsd.h>
69
70 static void ispminphys __P((struct buf *));
71 static int32_t ispcmd __P((ISP_SCSI_XFER_T *));
72
73 static struct scsipi_adapter isp_switch = {
74 ispcmd, ispminphys, 0, 0
75 };
76
77 static struct scsipi_device isp_dev = { NULL, NULL, NULL, NULL };
78 static int isp_poll __P((struct ispsoftc *, ISP_SCSI_XFER_T *, int));
79
80 /*
81 * Complete attachment of hardware, include subdevices.
82 */
83 void
84 isp_attach(isp)
85 struct ispsoftc *isp;
86 {
87 isp->isp_state = ISP_RUNSTATE;
88 isp->isp_osinfo._link.scsipi_scsi.channel = SCSI_CHANNEL_ONLY_ONE;
89 isp->isp_osinfo._link.adapter_softc = isp;
90 isp->isp_osinfo._link.device = &isp_dev;
91 isp->isp_osinfo._link.adapter = &isp_switch;
92
93 if (isp->isp_type & ISP_HA_FC) {
94 isp->isp_osinfo._link.scsipi_scsi.max_target = MAX_FC_TARG-1;
95 isp->isp_osinfo._link.openings =
96 RQUEST_QUEUE_LEN / (MAX_FC_TARG-1);
97 isp->isp_osinfo._link.scsipi_scsi.adapter_target = 0xff;
98 } else {
99 isp->isp_osinfo._link.openings =
100 RQUEST_QUEUE_LEN / (MAX_TARGETS-1);
101 isp->isp_osinfo._link.scsipi_scsi.max_target = MAX_TARGETS-1;
102 isp->isp_osinfo._link.scsipi_scsi.adapter_target =
103 ((sdparam *)isp->isp_param)->isp_initiator_id;
104 }
105 if (isp->isp_osinfo._link.openings < 2)
106 isp->isp_osinfo._link.openings = 2;
107 isp->isp_osinfo._link.type = BUS_SCSI;
108 config_found((void *)isp, &isp->isp_osinfo._link, scsiprint);
109 }
110
111 /*
112 * minphys our xfers
113 *
114 * Unfortunately, the buffer pointer describes the target device- not the
115 * adapter device, so we can't use the pointer to find out what kind of
116 * adapter we are and adjust accordingly.
117 */
118
119 static void
120 ispminphys(bp)
121 struct buf *bp;
122 {
123 /*
124 * XX: Only the 1020 has a 24 bit limit.
125 */
126 if (bp->b_bcount >= (1 << 24)) {
127 bp->b_bcount = (1 << 24);
128 }
129 minphys(bp);
130 }
131
132 static int
133 ispcmd(xs)
134 ISP_SCSI_XFER_T *xs;
135 {
136 struct ispsoftc *isp;
137 int r;
138 ISP_LOCKVAL_DECL;
139
140 isp = XS_ISP(xs);
141 ISP_LOCK(isp);
142 r = ispscsicmd(xs);
143 if (r != CMD_QUEUED || (xs->flags & SCSI_POLL) == 0) {
144 ISP_UNLOCK(isp);
145 return (r);
146 }
147
148 /*
149 * If we can't use interrupts, poll on completion.
150 */
151 if (isp_poll(isp, xs, XS_TIME(xs))) {
152 /*
153 * If no other error occurred but we didn't finish,
154 * something bad happened.
155 */
156 if (XS_IS_CMD_DONE(xs) == 0) {
157 isp->isp_nactive--;
158 if (isp->isp_nactive < 0)
159 isp->isp_nactive = 0;
160 if (XS_NOERR(xs)) {
161 isp_lostcmd(isp, xs);
162 XS_SETERR(xs, HBA_BOTCH);
163 }
164 }
165 }
166 ISP_UNLOCK(isp);
167 return (CMD_COMPLETE);
168 }
169
170 static int
171 isp_poll(isp, xs, mswait)
172 struct ispsoftc *isp;
173 ISP_SCSI_XFER_T *xs;
174 int mswait;
175 {
176
177 while (mswait) {
178 /* Try the interrupt handling routine */
179 (void)isp_intr((void *)isp);
180
181 /* See if the xs is now done */
182 if (XS_IS_CMD_DONE(xs)) {
183 return (0);
184 }
185 SYS_DELAY(1000); /* wait one millisecond */
186 mswait--;
187 }
188 return (1);
189 }
190