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