isp_pci.c revision 1.38.2.2 1 1.38.2.2 he /* $NetBSD: isp_pci.c,v 1.38.2.2 2000/05/13 17:05:50 he Exp $ */
2 1.1 cgd /*
3 1.1 cgd * PCI specific probe and attach routines for Qlogic ISP SCSI adapters.
4 1.38.2.1 he * Matthew Jacob (mjacob (at) nas.nasa.gov)
5 1.38.2.1 he */
6 1.38.2.1 he /*
7 1.38.2.1 he * Copyright (C) 1997, 1998, 1999 National Aeronautics & Space Administration
8 1.1 cgd * All rights reserved.
9 1.1 cgd *
10 1.1 cgd * Redistribution and use in source and binary forms, with or without
11 1.1 cgd * modification, are permitted provided that the following conditions
12 1.1 cgd * are met:
13 1.1 cgd * 1. Redistributions of source code must retain the above copyright
14 1.38.2.1 he * notice, this list of conditions and the following disclaimer.
15 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 cgd * notice, this list of conditions and the following disclaimer in the
17 1.1 cgd * documentation and/or other materials provided with the distribution.
18 1.1 cgd * 3. The name of the author may not be used to endorse or promote products
19 1.38.2.1 he * derived from this software without specific prior written permission
20 1.21 mjacob *
21 1.38.2.1 he * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 1.38.2.1 he * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 1.38.2.1 he * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 1.38.2.1 he * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 1.38.2.1 he * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 1.38.2.1 he * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 1.38.2.1 he * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 1.38.2.1 he * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 1.38.2.1 he * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 1.38.2.1 he * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 1.1 cgd */
32 1.1 cgd
33 1.21 mjacob #include <dev/ic/isp_netbsd.h>
34 1.21 mjacob #include <dev/microcode/isp/asm_pci.h>
35 1.21 mjacob
36 1.1 cgd #include <dev/pci/pcireg.h>
37 1.1 cgd #include <dev/pci/pcivar.h>
38 1.1 cgd #include <dev/pci/pcidevs.h>
39 1.3 cgd
40 1.1 cgd static u_int16_t isp_pci_rd_reg __P((struct ispsoftc *, int));
41 1.1 cgd static void isp_pci_wr_reg __P((struct ispsoftc *, int, u_int16_t));
42 1.36 mjacob #ifndef ISP_DISABLE_1080_SUPPORT
43 1.36 mjacob static u_int16_t isp_pci_rd_reg_1080 __P((struct ispsoftc *, int));
44 1.36 mjacob static void isp_pci_wr_reg_1080 __P((struct ispsoftc *, int, u_int16_t));
45 1.36 mjacob #endif
46 1.13 thorpej static int isp_pci_mbxdma __P((struct ispsoftc *));
47 1.16 bouyer static int isp_pci_dmasetup __P((struct ispsoftc *, struct scsipi_xfer *,
48 1.38.2.1 he ispreq_t *, u_int16_t *, u_int16_t));
49 1.16 bouyer static void isp_pci_dmateardown __P((struct ispsoftc *, struct scsipi_xfer *,
50 1.13 thorpej u_int32_t));
51 1.1 cgd static void isp_pci_reset1 __P((struct ispsoftc *));
52 1.15 mjacob static void isp_pci_dumpregs __P((struct ispsoftc *));
53 1.26 mjacob static int isp_pci_intr __P((void *));
54 1.1 cgd
55 1.38.2.1 he #ifndef ISP_CODE_ORG
56 1.38.2.1 he #define ISP_CODE_ORG 0x1000
57 1.38.2.1 he #endif
58 1.38.2.1 he #ifndef ISP_1040_RISC_CODE
59 1.38.2.1 he #define ISP_1040_RISC_CODE NULL
60 1.38.2.1 he #endif
61 1.38.2.1 he #ifndef ISP_1080_RISC_CODE
62 1.38.2.1 he #define ISP_1080_RISC_CODE NULL
63 1.38.2.1 he #endif
64 1.38.2.1 he #ifndef ISP_2100_RISC_CODE
65 1.38.2.1 he #define ISP_2100_RISC_CODE NULL
66 1.38.2.1 he #endif
67 1.38.2.1 he #ifndef ISP_2200_RISC_CODE
68 1.38.2.1 he #define ISP_2200_RISC_CODE NULL
69 1.38.2.1 he #endif
70 1.38.2.1 he
71 1.36 mjacob #ifndef ISP_DISABLE_1020_SUPPORT
72 1.1 cgd static struct ispmdvec mdvec = {
73 1.1 cgd isp_pci_rd_reg,
74 1.1 cgd isp_pci_wr_reg,
75 1.1 cgd isp_pci_mbxdma,
76 1.1 cgd isp_pci_dmasetup,
77 1.13 thorpej isp_pci_dmateardown,
78 1.1 cgd NULL,
79 1.1 cgd isp_pci_reset1,
80 1.15 mjacob isp_pci_dumpregs,
81 1.38.2.1 he ISP_1040_RISC_CODE,
82 1.38.2.1 he 0,
83 1.1 cgd ISP_CODE_ORG,
84 1.38.2.1 he 0,
85 1.33 mjacob BIU_BURST_ENABLE|BIU_PCI_CONF1_FIFO_64,
86 1.29 mjacob 0
87 1.15 mjacob };
88 1.36 mjacob #endif
89 1.36 mjacob
90 1.36 mjacob #ifndef ISP_DISABLE_1080_SUPPORT
91 1.36 mjacob static struct ispmdvec mdvec_1080 = {
92 1.36 mjacob isp_pci_rd_reg_1080,
93 1.36 mjacob isp_pci_wr_reg_1080,
94 1.36 mjacob isp_pci_mbxdma,
95 1.36 mjacob isp_pci_dmasetup,
96 1.36 mjacob isp_pci_dmateardown,
97 1.36 mjacob NULL,
98 1.36 mjacob isp_pci_reset1,
99 1.36 mjacob isp_pci_dumpregs,
100 1.38.2.1 he ISP_1080_RISC_CODE,
101 1.38.2.1 he 0,
102 1.38.2.1 he ISP_CODE_ORG,
103 1.38.2.1 he 0,
104 1.36 mjacob BIU_BURST_ENABLE|BIU_PCI_CONF1_FIFO_64,
105 1.36 mjacob 0
106 1.36 mjacob };
107 1.36 mjacob #endif
108 1.15 mjacob
109 1.36 mjacob #ifndef ISP_DISABLE_2100_SUPPORT
110 1.15 mjacob static struct ispmdvec mdvec_2100 = {
111 1.15 mjacob isp_pci_rd_reg,
112 1.15 mjacob isp_pci_wr_reg,
113 1.15 mjacob isp_pci_mbxdma,
114 1.15 mjacob isp_pci_dmasetup,
115 1.15 mjacob isp_pci_dmateardown,
116 1.15 mjacob NULL,
117 1.15 mjacob isp_pci_reset1,
118 1.15 mjacob isp_pci_dumpregs,
119 1.38.2.1 he ISP_2100_RISC_CODE,
120 1.38.2.1 he 0,
121 1.38.2.1 he ISP_CODE_ORG,
122 1.38.2.1 he 0,
123 1.38.2.1 he 0,
124 1.38.2.1 he 0
125 1.38.2.1 he };
126 1.38.2.1 he #endif
127 1.38.2.1 he
128 1.38.2.1 he #ifndef ISP_DISABLE_2200_SUPPORT
129 1.38.2.1 he static struct ispmdvec mdvec_2200 = {
130 1.38.2.1 he isp_pci_rd_reg,
131 1.38.2.1 he isp_pci_wr_reg,
132 1.38.2.1 he isp_pci_mbxdma,
133 1.38.2.1 he isp_pci_dmasetup,
134 1.38.2.1 he isp_pci_dmateardown,
135 1.38.2.1 he NULL,
136 1.38.2.1 he isp_pci_reset1,
137 1.38.2.1 he isp_pci_dumpregs,
138 1.38.2.1 he ISP_2200_RISC_CODE,
139 1.38.2.1 he 0,
140 1.38.2.1 he ISP_CODE_ORG,
141 1.38.2.1 he 0,
142 1.38.2.1 he 0,
143 1.33 mjacob 0
144 1.1 cgd };
145 1.36 mjacob #endif
146 1.1 cgd
147 1.36 mjacob #ifndef PCI_VENDOR_QLOGIC
148 1.36 mjacob #define PCI_VENDOR_QLOGIC 0x1077
149 1.36 mjacob #endif
150 1.36 mjacob
151 1.36 mjacob #ifndef PCI_PRODUCT_QLOGIC_ISP1020
152 1.36 mjacob #define PCI_PRODUCT_QLOGIC_ISP1020 0x1020
153 1.36 mjacob #endif
154 1.36 mjacob
155 1.36 mjacob #ifndef PCI_PRODUCT_QLOGIC_ISP1080
156 1.36 mjacob #define PCI_PRODUCT_QLOGIC_ISP1080 0x1080
157 1.36 mjacob #endif
158 1.36 mjacob
159 1.36 mjacob #ifndef PCI_PRODUCT_QLOGIC_ISP1240
160 1.36 mjacob #define PCI_PRODUCT_QLOGIC_ISP1240 0x1240
161 1.36 mjacob #endif
162 1.1 cgd
163 1.38.2.1 he #ifndef PCI_PRODUCT_QLOGIC_ISP1280
164 1.38.2.1 he #define PCI_PRODUCT_QLOGIC_ISP1280 0x1280
165 1.38.2.1 he #endif
166 1.38.2.1 he
167 1.15 mjacob #ifndef PCI_PRODUCT_QLOGIC_ISP2100
168 1.15 mjacob #define PCI_PRODUCT_QLOGIC_ISP2100 0x2100
169 1.15 mjacob #endif
170 1.36 mjacob
171 1.38.2.1 he #ifndef PCI_PRODUCT_QLOGIC_ISP2200
172 1.38.2.1 he #define PCI_PRODUCT_QLOGIC_ISP2200 0x2200
173 1.38.2.1 he #endif
174 1.38.2.1 he
175 1.36 mjacob #define PCI_QLOGIC_ISP ((PCI_PRODUCT_QLOGIC_ISP1020 << 16) | PCI_VENDOR_QLOGIC)
176 1.36 mjacob
177 1.36 mjacob #define PCI_QLOGIC_ISP1080 \
178 1.36 mjacob ((PCI_PRODUCT_QLOGIC_ISP1080 << 16) | PCI_VENDOR_QLOGIC)
179 1.36 mjacob
180 1.36 mjacob #define PCI_QLOGIC_ISP1240 \
181 1.36 mjacob ((PCI_PRODUCT_QLOGIC_ISP1240 << 16) | PCI_VENDOR_QLOGIC)
182 1.36 mjacob
183 1.38.2.1 he #define PCI_QLOGIC_ISP1280 \
184 1.38.2.1 he ((PCI_PRODUCT_QLOGIC_ISP1280 << 16) | PCI_VENDOR_QLOGIC)
185 1.38.2.1 he
186 1.15 mjacob #define PCI_QLOGIC_ISP2100 \
187 1.15 mjacob ((PCI_PRODUCT_QLOGIC_ISP2100 << 16) | PCI_VENDOR_QLOGIC)
188 1.15 mjacob
189 1.38.2.1 he #define PCI_QLOGIC_ISP2200 \
190 1.38.2.1 he ((PCI_PRODUCT_QLOGIC_ISP2200 << 16) | PCI_VENDOR_QLOGIC)
191 1.38.2.1 he
192 1.38.2.1 he #define IO_MAP_REG 0x10
193 1.38.2.1 he #define MEM_MAP_REG 0x14
194 1.38.2.1 he #define PCIR_ROMADDR 0x30
195 1.38.2.1 he
196 1.38.2.1 he #define PCI_DFLT_LTNCY 0x40
197 1.38.2.1 he #define PCI_DFLT_LNSZ 0x10
198 1.6 cgd
199 1.1 cgd
200 1.1 cgd static int isp_pci_probe __P((struct device *, struct cfdata *, void *));
201 1.1 cgd static void isp_pci_attach __P((struct device *, struct device *, void *));
202 1.1 cgd
203 1.1 cgd struct isp_pcisoftc {
204 1.1 cgd struct ispsoftc pci_isp;
205 1.15 mjacob pci_chipset_tag_t pci_pc;
206 1.15 mjacob pcitag_t pci_tag;
207 1.6 cgd bus_space_tag_t pci_st;
208 1.6 cgd bus_space_handle_t pci_sh;
209 1.13 thorpej bus_dma_tag_t pci_dmat;
210 1.15 mjacob bus_dmamap_t pci_scratch_dmap; /* for fcp only */
211 1.13 thorpej bus_dmamap_t pci_rquest_dmap;
212 1.13 thorpej bus_dmamap_t pci_result_dmap;
213 1.38.2.1 he bus_dmamap_t *pci_xfer_dmap;
214 1.1 cgd void * pci_ih;
215 1.36 mjacob int16_t pci_poff[_NREG_BLKS];
216 1.1 cgd };
217 1.1 cgd
218 1.1 cgd struct cfattach isp_pci_ca = {
219 1.1 cgd sizeof (struct isp_pcisoftc), isp_pci_probe, isp_pci_attach
220 1.1 cgd };
221 1.1 cgd
222 1.1 cgd static int
223 1.1 cgd isp_pci_probe(parent, match, aux)
224 1.38.2.1 he struct device *parent;
225 1.38.2.1 he struct cfdata *match;
226 1.38.2.1 he void *aux;
227 1.38.2.1 he {
228 1.38.2.1 he struct pci_attach_args *pa = aux;
229 1.38.2.1 he switch (pa->pa_id) {
230 1.36 mjacob #ifndef ISP_DISABLE_1020_SUPPORT
231 1.36 mjacob case PCI_QLOGIC_ISP:
232 1.36 mjacob return (1);
233 1.36 mjacob #endif
234 1.36 mjacob #ifndef ISP_DISABLE_1080_SUPPORT
235 1.36 mjacob case PCI_QLOGIC_ISP1080:
236 1.38.2.1 he case PCI_QLOGIC_ISP1240:
237 1.38.2.1 he case PCI_QLOGIC_ISP1280:
238 1.36 mjacob return (1);
239 1.36 mjacob #endif
240 1.36 mjacob #ifndef ISP_DISABLE_2100_SUPPORT
241 1.36 mjacob case PCI_QLOGIC_ISP2100:
242 1.1 cgd return (1);
243 1.36 mjacob #endif
244 1.38.2.1 he #ifndef ISP_DISABLE_2200_SUPPORT
245 1.38.2.1 he case PCI_QLOGIC_ISP2200:
246 1.38.2.1 he return (1);
247 1.38.2.1 he #endif
248 1.36 mjacob default:
249 1.1 cgd return (0);
250 1.1 cgd }
251 1.1 cgd }
252 1.1 cgd
253 1.1 cgd
254 1.38.2.1 he static void
255 1.1 cgd isp_pci_attach(parent, self, aux)
256 1.38.2.1 he struct device *parent, *self;
257 1.38.2.1 he void *aux;
258 1.1 cgd {
259 1.29 mjacob #ifdef DEBUG
260 1.27 thorpej static char oneshot = 1;
261 1.27 thorpej #endif
262 1.38.2.1 he static char *nomem = "%s: no mem for sdparam table\n";
263 1.38.2.1 he u_int32_t data, rev, linesz = PCI_DFLT_LNSZ;
264 1.1 cgd struct pci_attach_args *pa = aux;
265 1.1 cgd struct isp_pcisoftc *pcs = (struct isp_pcisoftc *) self;
266 1.21 mjacob struct ispsoftc *isp = &pcs->pci_isp;
267 1.11 cgd bus_space_tag_t st, iot, memt;
268 1.11 cgd bus_space_handle_t sh, ioh, memh;
269 1.1 cgd pci_intr_handle_t ih;
270 1.1 cgd const char *intrstr;
271 1.15 mjacob int ioh_valid, memh_valid, i;
272 1.22 mjacob ISP_LOCKVAL_DECL;
273 1.1 cgd
274 1.12 cgd ioh_valid = (pci_mapreg_map(pa, IO_MAP_REG,
275 1.11 cgd PCI_MAPREG_TYPE_IO, 0,
276 1.11 cgd &iot, &ioh, NULL, NULL) == 0);
277 1.12 cgd memh_valid = (pci_mapreg_map(pa, MEM_MAP_REG,
278 1.11 cgd PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT, 0,
279 1.11 cgd &memt, &memh, NULL, NULL) == 0);
280 1.11 cgd
281 1.11 cgd if (memh_valid) {
282 1.11 cgd st = memt;
283 1.11 cgd sh = memh;
284 1.11 cgd } else if (ioh_valid) {
285 1.11 cgd st = iot;
286 1.11 cgd sh = ioh;
287 1.6 cgd } else {
288 1.11 cgd printf(": unable to map device registers\n");
289 1.9 cgd return;
290 1.1 cgd }
291 1.1 cgd printf("\n");
292 1.1 cgd
293 1.6 cgd pcs->pci_st = st;
294 1.6 cgd pcs->pci_sh = sh;
295 1.13 thorpej pcs->pci_dmat = pa->pa_dmat;
296 1.15 mjacob pcs->pci_pc = pa->pa_pc;
297 1.15 mjacob pcs->pci_tag = pa->pa_tag;
298 1.36 mjacob pcs->pci_poff[BIU_BLOCK >> _BLK_REG_SHFT] = BIU_REGS_OFF;
299 1.36 mjacob pcs->pci_poff[MBOX_BLOCK >> _BLK_REG_SHFT] = PCI_MBOX_REGS_OFF;
300 1.36 mjacob pcs->pci_poff[SXP_BLOCK >> _BLK_REG_SHFT] = PCI_SXP_REGS_OFF;
301 1.36 mjacob pcs->pci_poff[RISC_BLOCK >> _BLK_REG_SHFT] = PCI_RISC_REGS_OFF;
302 1.36 mjacob pcs->pci_poff[DMA_BLOCK >> _BLK_REG_SHFT] = DMA_REGS_OFF;
303 1.38.2.1 he rev = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_CLASS_REG) & 0xff;
304 1.36 mjacob
305 1.36 mjacob #ifndef ISP_DISABLE_1020_SUPPORT
306 1.15 mjacob if (pa->pa_id == PCI_QLOGIC_ISP) {
307 1.21 mjacob isp->isp_mdvec = &mdvec;
308 1.21 mjacob isp->isp_type = ISP_HA_SCSI_UNKNOWN;
309 1.21 mjacob isp->isp_param = malloc(sizeof (sdparam), M_DEVBUF, M_NOWAIT);
310 1.21 mjacob if (isp->isp_param == NULL) {
311 1.38.2.1 he printf(nomem, isp->isp_name);
312 1.21 mjacob return;
313 1.15 mjacob }
314 1.21 mjacob bzero(isp->isp_param, sizeof (sdparam));
315 1.36 mjacob }
316 1.36 mjacob #endif
317 1.36 mjacob #ifndef ISP_DISABLE_1080_SUPPORT
318 1.36 mjacob if (pa->pa_id == PCI_QLOGIC_ISP1080) {
319 1.36 mjacob isp->isp_mdvec = &mdvec_1080;
320 1.36 mjacob isp->isp_type = ISP_HA_SCSI_1080;
321 1.36 mjacob isp->isp_param = malloc(sizeof (sdparam), M_DEVBUF, M_NOWAIT);
322 1.36 mjacob if (isp->isp_param == NULL) {
323 1.38.2.1 he printf(nomem, isp->isp_name);
324 1.36 mjacob return;
325 1.36 mjacob }
326 1.36 mjacob bzero(isp->isp_param, sizeof (sdparam));
327 1.36 mjacob pcs->pci_poff[DMA_BLOCK >> _BLK_REG_SHFT] =
328 1.36 mjacob ISP1080_DMA_REGS_OFF;
329 1.36 mjacob }
330 1.38.2.1 he if (pa->pa_id == PCI_QLOGIC_ISP1240) {
331 1.38.2.1 he isp->isp_mdvec = &mdvec_1080;
332 1.38.2.1 he isp->isp_type = ISP_HA_SCSI_1240;
333 1.38.2.1 he isp->isp_param =
334 1.38.2.1 he malloc(2 * sizeof (sdparam), M_DEVBUF, M_NOWAIT);
335 1.38.2.1 he if (isp->isp_param == NULL) {
336 1.38.2.1 he printf(nomem, isp->isp_name);
337 1.38.2.1 he return;
338 1.38.2.1 he }
339 1.38.2.1 he bzero(isp->isp_param, 2 * sizeof (sdparam));
340 1.38.2.1 he pcs->pci_poff[DMA_BLOCK >> _BLK_REG_SHFT] =
341 1.38.2.1 he ISP1080_DMA_REGS_OFF;
342 1.38.2.1 he }
343 1.38.2.1 he if (pa->pa_id == PCI_QLOGIC_ISP1280) {
344 1.38.2.1 he isp->isp_mdvec = &mdvec_1080;
345 1.38.2.1 he isp->isp_type = ISP_HA_SCSI_1280;
346 1.38.2.1 he isp->isp_param =
347 1.38.2.1 he malloc(2 * sizeof (sdparam), M_DEVBUF, M_NOWAIT);
348 1.38.2.1 he if (isp->isp_param == NULL) {
349 1.38.2.1 he printf(nomem, isp->isp_name);
350 1.38.2.1 he return;
351 1.38.2.1 he }
352 1.38.2.1 he bzero(isp->isp_param, 2 * sizeof (sdparam));
353 1.38.2.1 he pcs->pci_poff[DMA_BLOCK >> _BLK_REG_SHFT] =
354 1.38.2.1 he ISP1080_DMA_REGS_OFF;
355 1.38.2.1 he }
356 1.36 mjacob #endif
357 1.36 mjacob #ifndef ISP_DISABLE_2100_SUPPORT
358 1.36 mjacob if (pa->pa_id == PCI_QLOGIC_ISP2100) {
359 1.21 mjacob isp->isp_mdvec = &mdvec_2100;
360 1.21 mjacob isp->isp_type = ISP_HA_FC_2100;
361 1.21 mjacob isp->isp_param = malloc(sizeof (fcparam), M_DEVBUF, M_NOWAIT);
362 1.21 mjacob if (isp->isp_param == NULL) {
363 1.38.2.1 he printf(nomem, isp->isp_name);
364 1.21 mjacob return;
365 1.15 mjacob }
366 1.21 mjacob bzero(isp->isp_param, sizeof (fcparam));
367 1.36 mjacob pcs->pci_poff[MBOX_BLOCK >> _BLK_REG_SHFT] =
368 1.36 mjacob PCI_MBOX_REGS2100_OFF;
369 1.38.2.1 he if (rev < 3) {
370 1.38.2.1 he /*
371 1.38.2.1 he * XXX: Need to get the actual revision
372 1.38.2.1 he * XXX: number of the 2100 FB. At any rate,
373 1.38.2.1 he * XXX: lower cache line size for early revision
374 1.38.2.1 he * XXX; boards.
375 1.38.2.1 he */
376 1.38.2.1 he linesz = 1;
377 1.38.2.1 he }
378 1.15 mjacob }
379 1.36 mjacob #endif
380 1.38.2.1 he #ifndef ISP_DISABLE_2200_SUPPORT
381 1.38.2.1 he if (pa->pa_id == PCI_QLOGIC_ISP2200) {
382 1.38.2.1 he isp->isp_mdvec = &mdvec_2200;
383 1.38.2.1 he isp->isp_type = ISP_HA_FC_2200;
384 1.38.2.1 he isp->isp_param = malloc(sizeof (fcparam), M_DEVBUF, M_NOWAIT);
385 1.38.2.1 he if (isp->isp_param == NULL) {
386 1.38.2.1 he printf(nomem, isp->isp_name);
387 1.38.2.1 he return;
388 1.38.2.1 he }
389 1.38.2.1 he bzero(isp->isp_param, sizeof (fcparam));
390 1.38.2.1 he pcs->pci_poff[MBOX_BLOCK >> _BLK_REG_SHFT] =
391 1.38.2.1 he PCI_MBOX_REGS2100_OFF;
392 1.38.2.1 he data = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_CLASS_REG);
393 1.38.2.1 he }
394 1.38.2.1 he #endif
395 1.38.2.1 he isp->isp_revision = rev;
396 1.36 mjacob
397 1.35 mjacob /*
398 1.35 mjacob * Make sure that command register set sanely.
399 1.35 mjacob */
400 1.35 mjacob data = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
401 1.35 mjacob data |= PCI_COMMAND_MASTER_ENABLE | PCI_COMMAND_INVALIDATE_ENABLE;
402 1.36 mjacob
403 1.35 mjacob /*
404 1.35 mjacob * Not so sure about these- but I think it's important that they get
405 1.35 mjacob * enabled......
406 1.35 mjacob */
407 1.35 mjacob data |= PCI_COMMAND_PARITY_ENABLE | PCI_COMMAND_SERR_ENABLE;
408 1.35 mjacob pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG, data);
409 1.36 mjacob
410 1.35 mjacob /*
411 1.38.2.1 he * Make sure that the latency timer, cache line size,
412 1.38.2.1 he * and ROM is disabled.
413 1.35 mjacob */
414 1.35 mjacob data = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_BHLC_REG);
415 1.35 mjacob data &= ~(PCI_LATTIMER_MASK << PCI_LATTIMER_SHIFT);
416 1.35 mjacob data &= ~(PCI_CACHELINE_MASK << PCI_CACHELINE_SHIFT);
417 1.38.2.1 he data |= (PCI_DFLT_LTNCY << PCI_LATTIMER_SHIFT);
418 1.38.2.1 he data |= (linesz << PCI_CACHELINE_SHIFT);
419 1.35 mjacob pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_BHLC_REG, data);
420 1.35 mjacob
421 1.38.2.1 he data = pci_conf_read(pa->pa_pc, pa->pa_tag, PCIR_ROMADDR);
422 1.38.2.1 he data &= ~1;
423 1.38.2.1 he pci_conf_write(pa->pa_pc, pa->pa_tag, PCIR_ROMADDR, data);
424 1.38.2.1 he
425 1.27 thorpej #ifdef DEBUG
426 1.27 thorpej if (oneshot) {
427 1.27 thorpej oneshot = 0;
428 1.28 mjacob printf("Qlogic ISP Driver, NetBSD (pci) Platform Version "
429 1.27 thorpej "%d.%d Core Version %d.%d\n",
430 1.27 thorpej ISP_PLATFORM_VERSION_MAJOR, ISP_PLATFORM_VERSION_MINOR,
431 1.27 thorpej ISP_CORE_VERSION_MAJOR, ISP_CORE_VERSION_MINOR);
432 1.27 thorpej }
433 1.27 thorpej #endif
434 1.1 cgd if (pci_intr_map(pa->pa_pc, pa->pa_intrtag, pa->pa_intrpin,
435 1.36 mjacob pa->pa_intrline, &ih)) {
436 1.21 mjacob printf("%s: couldn't map interrupt\n", isp->isp_name);
437 1.21 mjacob free(isp->isp_param, M_DEVBUF);
438 1.1 cgd return;
439 1.1 cgd }
440 1.1 cgd intrstr = pci_intr_string(pa->pa_pc, ih);
441 1.1 cgd if (intrstr == NULL)
442 1.1 cgd intrstr = "<I dunno>";
443 1.38.2.1 he pcs->pci_ih = pci_intr_establish(pa->pa_pc, ih, IPL_BIO,
444 1.38.2.1 he isp_pci_intr, isp);
445 1.1 cgd if (pcs->pci_ih == NULL) {
446 1.1 cgd printf("%s: couldn't establish interrupt at %s\n",
447 1.21 mjacob isp->isp_name, intrstr);
448 1.36 mjacob free(isp->isp_param, M_DEVBUF);
449 1.36 mjacob return;
450 1.36 mjacob }
451 1.36 mjacob printf("%s: interrupting at %s\n", isp->isp_name, intrstr);
452 1.36 mjacob
453 1.38.2.1 he if (IS_FC(isp)) {
454 1.38.2.1 he long foo;
455 1.38.2.1 he /*
456 1.38.2.1 he * This isn't very random, but it's the best we can do for
457 1.38.2.1 he * the real edge case of cards that don't have WWNs.
458 1.38.2.1 he */
459 1.38.2.1 he foo = (long) isp;
460 1.38.2.1 he foo >>= 4;
461 1.38.2.1 he foo &= 0x7;
462 1.38.2.1 he while (version[foo])
463 1.38.2.1 he isp->isp_osinfo.seed += (int) version[foo++];
464 1.38.2.1 he isp->isp_osinfo.seed <<= 8;
465 1.38.2.1 he isp->isp_osinfo.seed += (isp->isp_osinfo._dev.dv_unit + 1);
466 1.38.2.1 he }
467 1.38.2.1 he
468 1.38.2.1 he isp->isp_confopts = self->dv_cfdata->cf_flags;
469 1.36 mjacob ISP_LOCK(isp);
470 1.36 mjacob isp_reset(isp);
471 1.36 mjacob if (isp->isp_state != ISP_RESETSTATE) {
472 1.36 mjacob ISP_UNLOCK(isp);
473 1.36 mjacob free(isp->isp_param, M_DEVBUF);
474 1.36 mjacob return;
475 1.36 mjacob }
476 1.36 mjacob isp_init(isp);
477 1.36 mjacob if (isp->isp_state != ISP_INITSTATE) {
478 1.21 mjacob isp_uninit(isp);
479 1.22 mjacob ISP_UNLOCK(isp);
480 1.21 mjacob free(isp->isp_param, M_DEVBUF);
481 1.1 cgd return;
482 1.1 cgd }
483 1.36 mjacob
484 1.1 cgd /*
485 1.13 thorpej * Create the DMA maps for the data transfers.
486 1.13 thorpej */
487 1.38.2.1 he for (i = 0; i < isp->isp_maxcmds; i++) {
488 1.13 thorpej if (bus_dmamap_create(pcs->pci_dmat, MAXPHYS,
489 1.13 thorpej (MAXPHYS / NBPG) + 1, MAXPHYS, 0, BUS_DMA_NOWAIT,
490 1.13 thorpej &pcs->pci_xfer_dmap[i])) {
491 1.13 thorpej printf("%s: can't create dma maps\n",
492 1.21 mjacob isp->isp_name);
493 1.21 mjacob isp_uninit(isp);
494 1.22 mjacob ISP_UNLOCK(isp);
495 1.13 thorpej return;
496 1.13 thorpej }
497 1.13 thorpej }
498 1.13 thorpej /*
499 1.1 cgd * Do Generic attach now.
500 1.1 cgd */
501 1.21 mjacob isp_attach(isp);
502 1.21 mjacob if (isp->isp_state != ISP_RUNSTATE) {
503 1.21 mjacob isp_uninit(isp);
504 1.21 mjacob free(isp->isp_param, M_DEVBUF);
505 1.1 cgd }
506 1.22 mjacob ISP_UNLOCK(isp);
507 1.1 cgd }
508 1.1 cgd
509 1.1 cgd static u_int16_t
510 1.1 cgd isp_pci_rd_reg(isp, regoff)
511 1.1 cgd struct ispsoftc *isp;
512 1.1 cgd int regoff;
513 1.1 cgd {
514 1.15 mjacob u_int16_t rv;
515 1.1 cgd struct isp_pcisoftc *pcs = (struct isp_pcisoftc *) isp;
516 1.36 mjacob int offset, oldconf = 0;
517 1.15 mjacob
518 1.36 mjacob if ((regoff & _BLK_REG_MASK) == SXP_BLOCK) {
519 1.1 cgd /*
520 1.15 mjacob * We will assume that someone has paused the RISC processor.
521 1.1 cgd */
522 1.36 mjacob oldconf = isp_pci_rd_reg(isp, BIU_CONF1);
523 1.36 mjacob isp_pci_wr_reg(isp, BIU_CONF1, oldconf | BIU_PCI_CONF1_SXP);
524 1.38.2.1 he delay(250);
525 1.1 cgd }
526 1.36 mjacob offset = pcs->pci_poff[(regoff & _BLK_REG_MASK) >> _BLK_REG_SHFT];
527 1.36 mjacob offset += (regoff & 0xff);
528 1.15 mjacob rv = bus_space_read_2(pcs->pci_st, pcs->pci_sh, offset);
529 1.36 mjacob if ((regoff & _BLK_REG_MASK) == SXP_BLOCK) {
530 1.36 mjacob isp_pci_wr_reg(isp, BIU_CONF1, oldconf);
531 1.38.2.1 he delay(250);
532 1.15 mjacob }
533 1.15 mjacob return (rv);
534 1.1 cgd }
535 1.1 cgd
536 1.1 cgd static void
537 1.1 cgd isp_pci_wr_reg(isp, regoff, val)
538 1.1 cgd struct ispsoftc *isp;
539 1.1 cgd int regoff;
540 1.1 cgd u_int16_t val;
541 1.1 cgd {
542 1.1 cgd struct isp_pcisoftc *pcs = (struct isp_pcisoftc *) isp;
543 1.36 mjacob int offset, oldconf = 0;
544 1.36 mjacob
545 1.36 mjacob if ((regoff & _BLK_REG_MASK) == SXP_BLOCK) {
546 1.1 cgd /*
547 1.15 mjacob * We will assume that someone has paused the RISC processor.
548 1.1 cgd */
549 1.36 mjacob oldconf = isp_pci_rd_reg(isp, BIU_CONF1);
550 1.36 mjacob isp_pci_wr_reg(isp, BIU_CONF1, oldconf | BIU_PCI_CONF1_SXP);
551 1.38.2.1 he delay(250);
552 1.36 mjacob }
553 1.36 mjacob offset = pcs->pci_poff[(regoff & _BLK_REG_MASK) >> _BLK_REG_SHFT];
554 1.36 mjacob offset += (regoff & 0xff);
555 1.36 mjacob bus_space_write_2(pcs->pci_st, pcs->pci_sh, offset, val);
556 1.36 mjacob if ((regoff & _BLK_REG_MASK) == SXP_BLOCK) {
557 1.36 mjacob isp_pci_wr_reg(isp, BIU_CONF1, oldconf);
558 1.38.2.1 he delay(250);
559 1.36 mjacob }
560 1.36 mjacob }
561 1.36 mjacob
562 1.36 mjacob #ifndef ISP_DISABLE_1080_SUPPORT
563 1.36 mjacob static u_int16_t
564 1.36 mjacob isp_pci_rd_reg_1080(isp, regoff)
565 1.36 mjacob struct ispsoftc *isp;
566 1.36 mjacob int regoff;
567 1.36 mjacob {
568 1.38.2.1 he u_int16_t rv, oc = 0;
569 1.36 mjacob struct isp_pcisoftc *pcs = (struct isp_pcisoftc *) isp;
570 1.38.2.1 he int offset;
571 1.36 mjacob
572 1.36 mjacob if ((regoff & _BLK_REG_MASK) == SXP_BLOCK) {
573 1.38.2.1 he u_int16_t tc;
574 1.36 mjacob /*
575 1.36 mjacob * We will assume that someone has paused the RISC processor.
576 1.36 mjacob */
577 1.36 mjacob oc = isp_pci_rd_reg(isp, BIU_CONF1);
578 1.38.2.1 he tc = oc & ~BIU_PCI1080_CONF1_DMA;
579 1.38.2.1 he if (IS_1280(isp)) {
580 1.38.2.1 he if (regoff & SXP_BANK1_SELECT)
581 1.38.2.1 he tc |= BIU_PCI1080_CONF1_SXP0;
582 1.38.2.1 he else
583 1.38.2.1 he tc |= BIU_PCI1080_CONF1_SXP1;
584 1.38.2.1 he } else {
585 1.38.2.1 he tc |= BIU_PCI1080_CONF1_SXP0;
586 1.38.2.1 he }
587 1.38.2.1 he isp_pci_wr_reg(isp, BIU_CONF1, tc);
588 1.38.2.1 he delay(250);
589 1.36 mjacob } else if ((regoff & _BLK_REG_MASK) == DMA_BLOCK) {
590 1.36 mjacob oc = isp_pci_rd_reg(isp, BIU_CONF1);
591 1.36 mjacob isp_pci_wr_reg(isp, BIU_CONF1, oc | BIU_PCI1080_CONF1_DMA);
592 1.38.2.1 he delay(250);
593 1.36 mjacob }
594 1.36 mjacob offset = pcs->pci_poff[(regoff & _BLK_REG_MASK) >> _BLK_REG_SHFT];
595 1.36 mjacob offset += (regoff & 0xff);
596 1.36 mjacob rv = bus_space_read_2(pcs->pci_st, pcs->pci_sh, offset);
597 1.38.2.1 he /*
598 1.38.2.1 he * Okay, because BIU_CONF1 is always nonzero
599 1.38.2.1 he */
600 1.38.2.1 he if (oc) {
601 1.36 mjacob isp_pci_wr_reg(isp, BIU_CONF1, oc);
602 1.38.2.1 he delay(250);
603 1.36 mjacob }
604 1.36 mjacob return (rv);
605 1.36 mjacob }
606 1.36 mjacob
607 1.36 mjacob static void
608 1.36 mjacob isp_pci_wr_reg_1080(isp, regoff, val)
609 1.36 mjacob struct ispsoftc *isp;
610 1.36 mjacob int regoff;
611 1.36 mjacob u_int16_t val;
612 1.36 mjacob {
613 1.38.2.1 he u_int16_t oc = 0;
614 1.36 mjacob struct isp_pcisoftc *pcs = (struct isp_pcisoftc *) isp;
615 1.38.2.1 he int offset;
616 1.36 mjacob
617 1.36 mjacob if ((regoff & _BLK_REG_MASK) == SXP_BLOCK) {
618 1.38.2.1 he u_int16_t tc;
619 1.36 mjacob /*
620 1.36 mjacob * We will assume that someone has paused the RISC processor.
621 1.36 mjacob */
622 1.36 mjacob oc = isp_pci_rd_reg(isp, BIU_CONF1);
623 1.38.2.1 he tc = oc & ~BIU_PCI1080_CONF1_DMA;
624 1.38.2.1 he if (IS_1280(isp)) {
625 1.38.2.1 he if (regoff & SXP_BANK1_SELECT)
626 1.38.2.1 he tc |= BIU_PCI1080_CONF1_SXP0;
627 1.38.2.1 he else
628 1.38.2.1 he tc |= BIU_PCI1080_CONF1_SXP1;
629 1.38.2.1 he } else {
630 1.38.2.1 he tc |= BIU_PCI1080_CONF1_SXP0;
631 1.38.2.1 he }
632 1.38.2.1 he isp_pci_wr_reg(isp, BIU_CONF1, tc);
633 1.38.2.1 he delay(250);
634 1.36 mjacob } else if ((regoff & _BLK_REG_MASK) == DMA_BLOCK) {
635 1.36 mjacob oc = isp_pci_rd_reg(isp, BIU_CONF1);
636 1.36 mjacob isp_pci_wr_reg(isp, BIU_CONF1, oc | BIU_PCI1080_CONF1_DMA);
637 1.38.2.1 he delay(250);
638 1.1 cgd }
639 1.36 mjacob offset = pcs->pci_poff[(regoff & _BLK_REG_MASK) >> _BLK_REG_SHFT];
640 1.36 mjacob offset += (regoff & 0xff);
641 1.6 cgd bus_space_write_2(pcs->pci_st, pcs->pci_sh, offset, val);
642 1.38.2.1 he /*
643 1.38.2.1 he * Okay, because BIU_CONF1 is always nonzero
644 1.38.2.1 he */
645 1.38.2.1 he if (oc) {
646 1.36 mjacob isp_pci_wr_reg(isp, BIU_CONF1, oc);
647 1.38.2.1 he delay(250);
648 1.15 mjacob }
649 1.1 cgd }
650 1.36 mjacob #endif
651 1.1 cgd
652 1.13 thorpej static int
653 1.13 thorpej isp_pci_mbxdma(isp)
654 1.1 cgd struct ispsoftc *isp;
655 1.1 cgd {
656 1.13 thorpej struct isp_pcisoftc *pci = (struct isp_pcisoftc *)isp;
657 1.13 thorpej bus_dma_segment_t seg;
658 1.13 thorpej bus_size_t len;
659 1.15 mjacob fcparam *fcp;
660 1.13 thorpej int rseg;
661 1.13 thorpej
662 1.38.2.1 he if (isp->isp_rquest_dma) /* been here before? */
663 1.38.2.1 he return (0);
664 1.38.2.1 he
665 1.38.2.1 he len = isp->isp_maxcmds * sizeof (ISP_SCSI_XFER_T);
666 1.38.2.1 he isp->isp_xflist = (ISP_SCSI_XFER_T **) malloc(len, M_DEVBUF, M_WAITOK);
667 1.38.2.1 he if (isp->isp_xflist == NULL) {
668 1.38.2.1 he printf("%s: cannot malloc xflist array\n", isp->isp_name);
669 1.38.2.1 he return (1);
670 1.38.2.1 he }
671 1.38.2.1 he bzero(isp->isp_xflist, len);
672 1.38.2.1 he len = isp->isp_maxcmds * sizeof (bus_dmamap_t);
673 1.38.2.1 he pci->pci_xfer_dmap = (bus_dmamap_t *) malloc(len, M_DEVBUF, M_WAITOK);
674 1.38.2.1 he if (pci->pci_xfer_dmap == NULL) {
675 1.38.2.1 he printf("%s: cannot malloc xflist array\n", isp->isp_name);
676 1.38.2.1 he return (1);
677 1.38.2.1 he }
678 1.38.2.1 he
679 1.13 thorpej /*
680 1.13 thorpej * Allocate and map the request queue.
681 1.13 thorpej */
682 1.21 mjacob len = ISP_QUEUE_SIZE(RQUEST_QUEUE_LEN);
683 1.13 thorpej if (bus_dmamem_alloc(pci->pci_dmat, len, NBPG, 0, &seg, 1, &rseg,
684 1.38.2.1 he BUS_DMA_NOWAIT) || bus_dmamem_map(pci->pci_dmat, &seg, rseg, len,
685 1.38.2.1 he (caddr_t *)&isp->isp_rquest, BUS_DMA_NOWAIT|BUS_DMA_COHERENT))
686 1.13 thorpej return (1);
687 1.13 thorpej if (bus_dmamap_create(pci->pci_dmat, len, 1, len, 0, BUS_DMA_NOWAIT,
688 1.38.2.1 he &pci->pci_rquest_dmap) || bus_dmamap_load(pci->pci_dmat,
689 1.38.2.1 he pci->pci_rquest_dmap, (caddr_t)isp->isp_rquest, len, NULL,
690 1.38.2.1 he BUS_DMA_NOWAIT))
691 1.13 thorpej return (1);
692 1.13 thorpej
693 1.13 thorpej isp->isp_rquest_dma = pci->pci_rquest_dmap->dm_segs[0].ds_addr;
694 1.13 thorpej
695 1.13 thorpej /*
696 1.13 thorpej * Allocate and map the result queue.
697 1.13 thorpej */
698 1.21 mjacob len = ISP_QUEUE_SIZE(RESULT_QUEUE_LEN);
699 1.13 thorpej if (bus_dmamem_alloc(pci->pci_dmat, len, NBPG, 0, &seg, 1, &rseg,
700 1.38.2.1 he BUS_DMA_NOWAIT) || bus_dmamem_map(pci->pci_dmat, &seg, rseg, len,
701 1.38.2.1 he (caddr_t *)&isp->isp_result, BUS_DMA_NOWAIT|BUS_DMA_COHERENT))
702 1.13 thorpej return (1);
703 1.13 thorpej if (bus_dmamap_create(pci->pci_dmat, len, 1, len, 0, BUS_DMA_NOWAIT,
704 1.38.2.1 he &pci->pci_result_dmap) || bus_dmamap_load(pci->pci_dmat,
705 1.38.2.1 he pci->pci_result_dmap, (caddr_t)isp->isp_result, len, NULL,
706 1.38.2.1 he BUS_DMA_NOWAIT))
707 1.13 thorpej return (1);
708 1.15 mjacob isp->isp_result_dma = pci->pci_result_dmap->dm_segs[0].ds_addr;
709 1.1 cgd
710 1.38.2.1 he if (IS_SCSI(isp)) {
711 1.15 mjacob return (0);
712 1.15 mjacob }
713 1.1 cgd
714 1.15 mjacob fcp = isp->isp_param;
715 1.15 mjacob len = ISP2100_SCRLEN;
716 1.15 mjacob if (bus_dmamem_alloc(pci->pci_dmat, len, NBPG, 0, &seg, 1, &rseg,
717 1.38.2.1 he BUS_DMA_NOWAIT) || bus_dmamem_map(pci->pci_dmat, &seg, rseg, len,
718 1.38.2.1 he (caddr_t *)&fcp->isp_scratch, BUS_DMA_NOWAIT|BUS_DMA_COHERENT))
719 1.15 mjacob return (1);
720 1.15 mjacob if (bus_dmamap_create(pci->pci_dmat, len, 1, len, 0, BUS_DMA_NOWAIT,
721 1.38.2.1 he &pci->pci_scratch_dmap) || bus_dmamap_load(pci->pci_dmat,
722 1.38.2.1 he pci->pci_scratch_dmap, (caddr_t)fcp->isp_scratch, len, NULL,
723 1.38.2.1 he BUS_DMA_NOWAIT))
724 1.15 mjacob return (1);
725 1.15 mjacob fcp->isp_scdma = pci->pci_scratch_dmap->dm_segs[0].ds_addr;
726 1.13 thorpej return (0);
727 1.1 cgd }
728 1.1 cgd
729 1.1 cgd static int
730 1.1 cgd isp_pci_dmasetup(isp, xs, rq, iptrp, optr)
731 1.1 cgd struct ispsoftc *isp;
732 1.16 bouyer struct scsipi_xfer *xs;
733 1.1 cgd ispreq_t *rq;
734 1.38.2.1 he u_int16_t *iptrp;
735 1.38.2.1 he u_int16_t optr;
736 1.1 cgd {
737 1.13 thorpej struct isp_pcisoftc *pci = (struct isp_pcisoftc *)isp;
738 1.15 mjacob bus_dmamap_t dmap = pci->pci_xfer_dmap[rq->req_handle - 1];
739 1.1 cgd ispcontreq_t *crq;
740 1.17 mjacob int segcnt, seg, error, ovseg, seglim, drq;
741 1.1 cgd
742 1.1 cgd if (xs->datalen == 0) {
743 1.1 cgd rq->req_seg_count = 1;
744 1.26 mjacob goto mbxsync;
745 1.1 cgd }
746 1.38.2.1 he assert(rq->req_handle != 0 && rq->req_handle <= isp->isp_maxcmds);
747 1.1 cgd if (xs->flags & SCSI_DATA_IN) {
748 1.17 mjacob drq = REQFLAG_DATA_IN;
749 1.1 cgd } else {
750 1.17 mjacob drq = REQFLAG_DATA_OUT;
751 1.1 cgd }
752 1.1 cgd
753 1.38.2.1 he if (IS_FC(isp)) {
754 1.15 mjacob seglim = ISP_RQDSEG_T2;
755 1.15 mjacob ((ispreqt2_t *)rq)->req_totalcnt = xs->datalen;
756 1.17 mjacob ((ispreqt2_t *)rq)->req_flags |= drq;
757 1.15 mjacob } else {
758 1.38.2.2 he rq->req_flags |= drq;
759 1.38.2.2 he if (XS_CDBLEN(xs) > 12) {
760 1.38.2.2 he seglim = 0;
761 1.38.2.2 he } else {
762 1.38.2.2 he seglim = ISP_RQDSEG;
763 1.38.2.2 he }
764 1.15 mjacob }
765 1.13 thorpej error = bus_dmamap_load(pci->pci_dmat, dmap, xs->data, xs->datalen,
766 1.13 thorpej NULL, xs->flags & SCSI_NOSLEEP ? BUS_DMA_NOWAIT : BUS_DMA_WAITOK);
767 1.21 mjacob if (error) {
768 1.21 mjacob XS_SETERR(xs, HBA_BOTCH);
769 1.30 mjacob return (CMD_COMPLETE);
770 1.21 mjacob }
771 1.13 thorpej
772 1.13 thorpej segcnt = dmap->dm_nsegs;
773 1.13 thorpej
774 1.13 thorpej for (seg = 0, rq->req_seg_count = 0;
775 1.38.2.1 he seg < segcnt && rq->req_seg_count < seglim;
776 1.38.2.1 he seg++, rq->req_seg_count++) {
777 1.38.2.1 he if (IS_FC(isp)) {
778 1.15 mjacob ispreqt2_t *rq2 = (ispreqt2_t *)rq;
779 1.15 mjacob rq2->req_dataseg[rq2->req_seg_count].ds_count =
780 1.15 mjacob dmap->dm_segs[seg].ds_len;
781 1.15 mjacob rq2->req_dataseg[rq2->req_seg_count].ds_base =
782 1.15 mjacob dmap->dm_segs[seg].ds_addr;
783 1.15 mjacob } else {
784 1.15 mjacob rq->req_dataseg[rq->req_seg_count].ds_count =
785 1.15 mjacob dmap->dm_segs[seg].ds_len;
786 1.15 mjacob rq->req_dataseg[rq->req_seg_count].ds_base =
787 1.15 mjacob dmap->dm_segs[seg].ds_addr;
788 1.15 mjacob }
789 1.1 cgd }
790 1.1 cgd
791 1.13 thorpej if (seg == segcnt)
792 1.26 mjacob goto dmasync;
793 1.1 cgd
794 1.1 cgd do {
795 1.15 mjacob crq = (ispcontreq_t *)
796 1.15 mjacob ISP_QUEUE_ENTRY(isp->isp_rquest, *iptrp);
797 1.21 mjacob *iptrp = (*iptrp + 1) & (RQUEST_QUEUE_LEN - 1);
798 1.1 cgd if (*iptrp == optr) {
799 1.38.2.1 he printf("%s: Request Queue Overflow++\n", isp->isp_name);
800 1.13 thorpej bus_dmamap_unload(pci->pci_dmat, dmap);
801 1.21 mjacob XS_SETERR(xs, HBA_BOTCH);
802 1.30 mjacob return (CMD_COMPLETE);
803 1.1 cgd }
804 1.1 cgd rq->req_header.rqs_entry_count++;
805 1.1 cgd bzero((void *)crq, sizeof (*crq));
806 1.1 cgd crq->req_header.rqs_entry_count = 1;
807 1.1 cgd crq->req_header.rqs_entry_type = RQSTYPE_DATASEG;
808 1.13 thorpej
809 1.13 thorpej for (ovseg = 0; seg < segcnt && ovseg < ISP_CDSEG;
810 1.13 thorpej rq->req_seg_count++, seg++, ovseg++) {
811 1.13 thorpej crq->req_dataseg[ovseg].ds_count =
812 1.13 thorpej dmap->dm_segs[seg].ds_len;
813 1.13 thorpej crq->req_dataseg[ovseg].ds_base =
814 1.13 thorpej dmap->dm_segs[seg].ds_addr;
815 1.1 cgd }
816 1.13 thorpej } while (seg < segcnt);
817 1.13 thorpej
818 1.26 mjacob dmasync:
819 1.19 thorpej bus_dmamap_sync(pci->pci_dmat, dmap, 0, dmap->dm_mapsize,
820 1.30 mjacob (xs->flags & SCSI_DATA_IN) ? BUS_DMASYNC_PREREAD :
821 1.30 mjacob BUS_DMASYNC_PREWRITE);
822 1.26 mjacob
823 1.26 mjacob mbxsync:
824 1.38.2.1 he ISP_SWIZZLE_REQUEST(isp, rq);
825 1.26 mjacob bus_dmamap_sync(pci->pci_dmat, pci->pci_rquest_dmap, 0,
826 1.26 mjacob pci->pci_rquest_dmap->dm_mapsize, BUS_DMASYNC_PREWRITE);
827 1.30 mjacob return (CMD_QUEUED);
828 1.26 mjacob }
829 1.26 mjacob
830 1.26 mjacob static int
831 1.26 mjacob isp_pci_intr(arg)
832 1.26 mjacob void *arg;
833 1.26 mjacob {
834 1.26 mjacob struct isp_pcisoftc *pci = (struct isp_pcisoftc *)arg;
835 1.26 mjacob bus_dmamap_sync(pci->pci_dmat, pci->pci_result_dmap, 0,
836 1.26 mjacob pci->pci_result_dmap->dm_mapsize, BUS_DMASYNC_POSTREAD);
837 1.26 mjacob return (isp_intr(arg));
838 1.13 thorpej }
839 1.13 thorpej
840 1.13 thorpej static void
841 1.13 thorpej isp_pci_dmateardown(isp, xs, handle)
842 1.13 thorpej struct ispsoftc *isp;
843 1.16 bouyer struct scsipi_xfer *xs;
844 1.13 thorpej u_int32_t handle;
845 1.13 thorpej {
846 1.13 thorpej struct isp_pcisoftc *pci = (struct isp_pcisoftc *)isp;
847 1.38.2.1 he bus_dmamap_t dmap;
848 1.38.2.1 he assert(handle != 0 && handle <= isp->isp_maxcmds);
849 1.38.2.1 he dmap = pci->pci_xfer_dmap[handle-1];
850 1.19 thorpej bus_dmamap_sync(pci->pci_dmat, dmap, 0, dmap->dm_mapsize,
851 1.19 thorpej xs->flags & SCSI_DATA_IN ?
852 1.13 thorpej BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE);
853 1.13 thorpej bus_dmamap_unload(pci->pci_dmat, dmap);
854 1.1 cgd }
855 1.1 cgd
856 1.1 cgd static void
857 1.1 cgd isp_pci_reset1(isp)
858 1.1 cgd struct ispsoftc *isp;
859 1.1 cgd {
860 1.1 cgd /* Make sure the BIOS is disabled */
861 1.1 cgd isp_pci_wr_reg(isp, HCCR, PCI_HCCR_CMD_BIOS);
862 1.15 mjacob }
863 1.15 mjacob
864 1.15 mjacob static void
865 1.15 mjacob isp_pci_dumpregs(isp)
866 1.15 mjacob struct ispsoftc *isp;
867 1.15 mjacob {
868 1.15 mjacob struct isp_pcisoftc *pci = (struct isp_pcisoftc *)isp;
869 1.15 mjacob printf("%s: PCI Status Command/Status=%x\n", pci->pci_isp.isp_name,
870 1.15 mjacob pci_conf_read(pci->pci_pc, pci->pci_tag, PCI_COMMAND_STATUS_REG));
871 1.1 cgd }
872