isp_netbsd.c revision 1.3 1 /* $NetBSD: isp_netbsd.c,v 1.3 1998/09/08 07:19:58 mjacob Exp $ */
2 /* $Id: isp_netbsd.c,v 1.3 1998/09/08 07:19:58 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 #include <dev/ic/isp_netbsd.h>
51
52 static void ispminphys __P((struct buf *));
53 static int32_t ispcmd __P((ISP_SCSI_XFER_T *));
54
55 static struct scsipi_adapter isp_switch = {
56 ispcmd, ispminphys, 0, 0
57 };
58
59 static struct scsipi_device isp_dev = { NULL, NULL, NULL, NULL };
60 static int isp_poll __P((struct ispsoftc *, ISP_SCSI_XFER_T *, int));
61
62 /*
63 * Complete attachment of hardware, include subdevices.
64 */
65 void
66 isp_attach(isp)
67 struct ispsoftc *isp;
68 {
69 isp->isp_state = ISP_RUNSTATE;
70 isp->isp_osinfo._link.scsipi_scsi.channel = SCSI_CHANNEL_ONLY_ONE;
71 isp->isp_osinfo._link.adapter_softc = isp;
72 isp->isp_osinfo._link.device = &isp_dev;
73 isp->isp_osinfo._link.adapter = &isp_switch;
74
75 if (isp->isp_type & ISP_HA_FC) {
76 isp->isp_osinfo._link.scsipi_scsi.max_target = MAX_FC_TARG-1;
77 isp->isp_osinfo._link.openings =
78 RQUEST_QUEUE_LEN / (MAX_FC_TARG-1);
79 isp->isp_osinfo._link.scsipi_scsi.adapter_target = 0xff;
80 } else {
81 isp->isp_osinfo._link.openings =
82 RQUEST_QUEUE_LEN / (MAX_TARGETS-1);
83 isp->isp_osinfo._link.scsipi_scsi.max_target = MAX_TARGETS-1;
84 isp->isp_osinfo._link.scsipi_scsi.adapter_target =
85 ((sdparam *)isp->isp_param)->isp_initiator_id;
86 }
87 if (isp->isp_osinfo._link.openings < 2)
88 isp->isp_osinfo._link.openings = 2;
89 isp->isp_osinfo._link.type = BUS_SCSI;
90 config_found((void *)isp, &isp->isp_osinfo._link, scsiprint);
91 }
92
93 /*
94 * minphys our xfers
95 *
96 * Unfortunately, the buffer pointer describes the target device- not the
97 * adapter device, so we can't use the pointer to find out what kind of
98 * adapter we are and adjust accordingly.
99 */
100
101 static void
102 ispminphys(bp)
103 struct buf *bp;
104 {
105 /*
106 * XX: Only the 1020 has a 24 bit limit.
107 */
108 if (bp->b_bcount >= (1 << 24)) {
109 bp->b_bcount = (1 << 24);
110 }
111 minphys(bp);
112 }
113
114 static int
115 ispcmd(xs)
116 ISP_SCSI_XFER_T *xs;
117 {
118 struct ispsoftc *isp;
119 int result;
120 ISP_LOCKVAL_DECL;
121
122 isp = XS_ISP(xs);
123 ISP_LOCK(isp);
124 /*
125 * This is less efficient than I would like in that the
126 * majority of cases will have to do some pointer deferences
127 * to find out that things don't need to be updated.
128 */
129 if ((xs->flags & SCSI_AUTOCONF) == 0 && (isp->isp_type & ISP_HA_SCSI)) {
130 sdparam *sdp = isp->isp_param;
131 if (sdp->isp_devparam[XS_TGT(xs)].dev_flags !=
132 sdp->isp_devparam[XS_TGT(xs)].cur_dflags) {
133 u_int16_t f = DPARM_WIDE|DPARM_SYNC|DPARM_TQING;
134 if (xs->sc_link->quirks & SDEV_NOSYNC)
135 f &= ~DPARM_SYNC;
136 if (xs->sc_link->quirks & SDEV_NOWIDE)
137 f &= ~DPARM_WIDE;
138 if (xs->sc_link->quirks & SDEV_NOTAG)
139 f &= ~DPARM_TQING;
140 sdp->isp_devparam[XS_TGT(xs)].dev_flags &=
141 ~(DPARM_WIDE|DPARM_SYNC|DPARM_TQING);
142 sdp->isp_devparam[XS_TGT(xs)].dev_flags |= f;
143 sdp->isp_devparam[XS_TGT(xs)].dev_update = 1;
144 isp->isp_update = 1;
145 }
146 }
147 result = ispscsicmd(xs);
148 if (result != CMD_QUEUED || (xs->flags & SCSI_POLL) == 0) {
149 ISP_UNLOCK(isp);
150 return (result);
151 }
152
153 /*
154 * If we can't use interrupts, poll on completion.
155 */
156 if (isp_poll(isp, xs, XS_TIME(xs))) {
157 /*
158 * If no other error occurred but we didn't finish,
159 * something bad happened.
160 */
161 if (XS_IS_CMD_DONE(xs) == 0) {
162 isp->isp_nactive--;
163 if (isp->isp_nactive < 0)
164 isp->isp_nactive = 0;
165 if (XS_NOERR(xs)) {
166 isp_lostcmd(isp, xs);
167 XS_SETERR(xs, HBA_BOTCH);
168 }
169 }
170 }
171 ISP_UNLOCK(isp);
172 return (CMD_COMPLETE);
173 }
174
175 static int
176 isp_poll(isp, xs, mswait)
177 struct ispsoftc *isp;
178 ISP_SCSI_XFER_T *xs;
179 int mswait;
180 {
181
182 while (mswait) {
183 /* Try the interrupt handling routine */
184 (void)isp_intr((void *)isp);
185
186 /* See if the xs is now done */
187 if (XS_IS_CMD_DONE(xs)) {
188 return (0);
189 }
190 SYS_DELAY(1000); /* wait one millisecond */
191 mswait--;
192 }
193 return (1);
194 }
195