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