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