1 /* $NetBSD: icp_pci.c,v 1.18 2009/05/12 08:23:00 cegger Exp $ */
4 * Copyright (c) 2002 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 * Copyright (c) 1999, 2000 Niklas Hallqvist. All rights reserved.
35 * Redistribution and use in source and binary forms, with or without
36 * modification, are permitted provided that the following conditions
38 * 1. Redistributions of source code must retain the above copyright
39 * notice, this list of conditions and the following disclaimer.
40 * 2. Redistributions in binary form must reproduce the above copyright
41 * notice, this list of conditions and the following disclaimer in the
42 * documentation and/or other materials provided with the distribution.
43 * 3. All advertising materials mentioning features or use of this software
44 * must display the following acknowledgement:
45 * This product includes software developed by Niklas Hallqvist.
46 * 4. The name of the author may not be used to endorse or promote products
47 * derived from this software without specific prior written permission.
49 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
50 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
51 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
52 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
53 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
54 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
55 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
56 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
57 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
58 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
60 * from OpenBSD: icp_pci.c,v 1.11 2001/06/12 15:40:30 niklas Exp
64 * This driver would not have written if it was not for the hardware donations
65 * from both ICP-Vortex and Öko.neT. I want to thank them for their support.
67 * Re-worked for NetBSD by Andrew Doran. Test hardware kindly supplied by
71 #include <sys/cdefs.h>
72 __KERNEL_RCSID(0, "$NetBSD: icp_pci.c,v 1.18 2009/05/12 08:23:00 cegger Exp $");
74 #include <sys/param.h>
75 #include <sys/systm.h>
76 #include <sys/device.h>
77 #include <sys/kernel.h>
78 #include <sys/queue.h>
80 #include <sys/endian.h>
83 #include <uvm/uvm_extern.h>
87 #include <dev/pci/pcireg.h>
88 #include <dev/pci/pcivar.h>
89 #include <dev/pci/pcidevs.h>
91 #include <dev/ic/icpreg.h>
92 #include <dev/ic/icpvar.h>
94 /* Product numbers for Fibre-Channel are greater than or equal to 0x200 */
95 #define ICP_PCI_PRODUCT_FC 0x200
97 /* Mapping registers for various areas */
98 #define ICP_PCI_DPMEM 0x10
99 #define ICP_PCINEW_IOMEM 0x10
100 #define ICP_PCINEW_IO 0x14
101 #define ICP_PCINEW_DPMEM 0x18
103 /* PCI SRAM structure */
104 #define ICP_MAGIC 0x00 /* u_int32_t, controller ID from BIOS */
105 #define ICP_NEED_DEINIT 0x04 /* u_int16_t, switch between BIOS/driver */
106 #define ICP_SWITCH_SUPPORT 0x06 /* u_int8_t, see ICP_NEED_DEINIT */
107 #define ICP_OS_USED 0x10 /* u_int8_t [16], OS code per service */
108 #define ICP_FW_MAGIC 0x3c /* u_int8_t, controller ID from firmware */
109 #define ICP_SRAM_SZ 0x40
111 /* DPRAM PCI controllers */
112 #define ICP_DPR_IF 0x00 /* interface area */
113 #define ICP_6SR (0xff0 - ICP_SRAM_SZ)
114 #define ICP_SEMA1 0xff1 /* volatile u_int8_t, command semaphore */
115 #define ICP_IRQEN 0xff5 /* u_int8_t, board interrupts enable */
116 #define ICP_EVENT 0xff8 /* u_int8_t, release event */
117 #define ICP_IRQDEL 0xffc /* u_int8_t, acknowledge board interrupt */
118 #define ICP_DPRAM_SZ 0x1000
120 /* PLX register structure (new PCI controllers) */
121 #define ICP_CFG_REG 0x00 /* u_int8_t, DPRAM cfg. (2: < 1MB, 0: any) */
122 #define ICP_SEMA0_REG 0x40 /* volatile u_int8_t, command semaphore */
123 #define ICP_SEMA1_REG 0x41 /* volatile u_int8_t, status semaphore */
124 #define ICP_PLX_STATUS 0x44 /* volatile u_int16_t, command status */
125 #define ICP_PLX_SERVICE 0x46 /* u_int16_t, service */
126 #define ICP_PLX_INFO 0x48 /* u_int32_t [2], additional info */
127 #define ICP_LDOOR_REG 0x60 /* u_int8_t, PCI to local doorbell */
128 #define ICP_EDOOR_REG 0x64 /* volatile u_int8_t, local to PCI doorbell */
129 #define ICP_CONTROL0 0x68 /* u_int8_t, control0 register (unused) */
130 #define ICP_CONTROL1 0x69 /* u_int8_t, board interrupts enable */
131 #define ICP_PLX_SZ 0x80
133 /* DPRAM new PCI controllers */
134 #define ICP_IC 0x00 /* interface */
135 #define ICP_PCINEW_6SR (0x4000 - ICP_SRAM_SZ)
137 #define ICP_PCINEW_SZ 0x4000
139 /* i960 register structure (PCI MPR controllers) */
140 #define ICP_MPR_SEMA0 0x10 /* volatile u_int8_t, command semaphore */
141 #define ICP_MPR_SEMA1 0x12 /* volatile u_int8_t, status semaphore */
142 #define ICP_MPR_STATUS 0x14 /* volatile u_int16_t, command status */
143 #define ICP_MPR_SERVICE 0x16 /* u_int16_t, service */
144 #define ICP_MPR_INFO 0x18 /* u_int32_t [2], additional info */
145 #define ICP_MPR_LDOOR 0x20 /* u_int8_t, PCI to local doorbell */
146 #define ICP_MPR_EDOOR 0x2c /* volatile u_int8_t, locl to PCI doorbell */
147 #define ICP_EDOOR_EN 0x34 /* u_int8_t, board interrupts enable */
148 #define ICP_SEVERITY 0xefc /* u_int8_t, event severity */
149 #define ICP_EVT_BUF 0xf00 /* u_int8_t [256], event buffer */
150 #define ICP_I960_SZ 0x1000
152 /* DPRAM PCI MPR controllers */
153 #define ICP_I960R 0x00 /* 4KB i960 registers */
154 #define ICP_MPR_IC ICP_I960_SZ
156 #define ICP_MPR_6SR (ICP_I960_SZ + 0x3000 - ICP_SRAM_SZ)
158 #define ICP_MPR_SZ 0x4000
160 int icp_pci_match(device_t
, cfdata_t
, void *);
161 void icp_pci_attach(device_t
, device_t
, void *);
162 void icp_pci_enable_intr(struct icp_softc
*);
163 int icp_pci_find_class(struct pci_attach_args
*);
165 void icp_pci_copy_cmd(struct icp_softc
*, struct icp_ccb
*);
166 u_int8_t
icp_pci_get_status(struct icp_softc
*);
167 void icp_pci_intr(struct icp_softc
*, struct icp_intr_ctx
*);
168 void icp_pci_release_event(struct icp_softc
*, struct icp_ccb
*);
169 void icp_pci_set_sema0(struct icp_softc
*);
170 int icp_pci_test_busy(struct icp_softc
*);
172 void icp_pcinew_copy_cmd(struct icp_softc
*, struct icp_ccb
*);
173 u_int8_t
icp_pcinew_get_status(struct icp_softc
*);
174 void icp_pcinew_intr(struct icp_softc
*, struct icp_intr_ctx
*);
175 void icp_pcinew_release_event(struct icp_softc
*, struct icp_ccb
*);
176 void icp_pcinew_set_sema0(struct icp_softc
*);
177 int icp_pcinew_test_busy(struct icp_softc
*);
179 void icp_mpr_copy_cmd(struct icp_softc
*, struct icp_ccb
*);
180 u_int8_t
icp_mpr_get_status(struct icp_softc
*);
181 void icp_mpr_intr(struct icp_softc
*, struct icp_intr_ctx
*);
182 void icp_mpr_release_event(struct icp_softc
*, struct icp_ccb
*);
183 void icp_mpr_set_sema0(struct icp_softc
*);
184 int icp_mpr_test_busy(struct icp_softc
*);
186 CFATTACH_DECL(icp_pci
, sizeof(struct icp_softc
),
187 icp_pci_match
, icp_pci_attach
, NULL
, NULL
);
189 struct icp_pci_ident
{
193 } const icp_pci_ident
[] = {
194 { PCI_VENDOR_VORTEX
, PCI_PRODUCT_VORTEX_GDT_60x0
, ICP_PCI
},
195 { PCI_VENDOR_VORTEX
, PCI_PRODUCT_VORTEX_GDT_6000B
, ICP_PCI
},
197 { PCI_VENDOR_INTEL
, PCI_PRODUCT_INTEL_GDT_RAID1
, ICP_MPR
},
198 { PCI_VENDOR_INTEL
, PCI_PRODUCT_INTEL_GDT_RAID2
, ICP_MPR
},
202 icp_pci_find_class(struct pci_attach_args
*pa
)
204 const struct icp_pci_ident
*gpi
, *maxgpi
;
207 maxgpi
= gpi
+ sizeof(icp_pci_ident
) / sizeof(icp_pci_ident
[0]);
209 for (; gpi
< maxgpi
; gpi
++)
210 if (PCI_VENDOR(pa
->pa_id
) == gpi
->gpi_vendor
&&
211 PCI_PRODUCT(pa
->pa_id
) == gpi
->gpi_product
)
212 return (gpi
->gpi_class
);
215 * ICP-Vortex only make RAID controllers, so we employ a heuristic
216 * to match unlisted boards.
218 if (PCI_VENDOR(pa
->pa_id
) == PCI_VENDOR_VORTEX
)
219 return (PCI_PRODUCT(pa
->pa_id
) < 0x100 ? ICP_PCINEW
: ICP_MPR
);
225 icp_pci_match(device_t parent
, cfdata_t match
, void *aux
)
227 struct pci_attach_args
*pa
;
231 if (PCI_CLASS(pa
->pa_class
) == PCI_CLASS_I2O
)
234 return (icp_pci_find_class(pa
) != -1);
238 icp_pci_attach(device_t parent
, device_t self
, void *aux
)
240 struct pci_attach_args
*pa
;
241 struct icp_softc
*icp
;
242 bus_space_tag_t dpmemt
, iomemt
, iot
;
243 bus_space_handle_t dpmemh
, iomemh
, ioh
;
244 bus_addr_t dpmembase
, iomembase
, iobase
;
245 bus_size_t dpmemsize
, iomemsize
, iosize
;
247 #define DPMEM_MAPPED 1
248 #define IOMEM_MAPPED 2
250 #define INTR_ESTABLISHED 8
253 pci_intr_handle_t ih
;
258 icp
= device_private(self
);
259 icp
->icp_class
= icp_pci_find_class(pa
);
261 aprint_naive(": RAID controller\n");
264 if (PCI_VENDOR(pa
->pa_id
) == PCI_VENDOR_VORTEX
&&
265 PCI_PRODUCT(pa
->pa_id
) >= ICP_PCI_PRODUCT_FC
)
266 icp
->icp_class
|= ICP_FC
;
268 if (pci_mapreg_map(pa
,
269 ICP_CLASS(icp
) == ICP_PCINEW
? ICP_PCINEW_DPMEM
: ICP_PCI_DPMEM
,
270 PCI_MAPREG_TYPE_MEM
| PCI_MAPREG_MEM_TYPE_32BIT
, 0, &dpmemt
,
271 &dpmemh
, &dpmembase
, &dpmemsize
)) {
272 if (pci_mapreg_map(pa
,
273 ICP_CLASS(icp
) == ICP_PCINEW
? ICP_PCINEW_DPMEM
:
275 PCI_MAPREG_TYPE_MEM
| PCI_MAPREG_MEM_TYPE_32BIT_1M
, 0,
276 &dpmemt
, &dpmemh
, &dpmembase
, &dpmemsize
)) {
277 aprint_error("cannot map DPMEM\n");
281 status
|= DPMEM_MAPPED
;
282 icp
->icp_dpmemt
= dpmemt
;
283 icp
->icp_dpmemh
= dpmemh
;
284 icp
->icp_dpmembase
= dpmembase
;
285 icp
->icp_dmat
= pa
->pa_dmat
;
288 * The ICP_PCINEW series also has two other regions to map.
290 if (ICP_CLASS(icp
) == ICP_PCINEW
) {
291 if (pci_mapreg_map(pa
, ICP_PCINEW_IOMEM
, PCI_MAPREG_TYPE_MEM
,
292 0, &iomemt
, &iomemh
, &iomembase
, &iomemsize
)) {
293 aprint_error("cannot map memory mapped I/O ports\n");
296 status
|= IOMEM_MAPPED
;
298 if (pci_mapreg_map(pa
, ICP_PCINEW_IO
, PCI_MAPREG_TYPE_IO
, 0,
299 &iot
, &ioh
, &iobase
, &iosize
)) {
300 aprint_error("cannot map I/O ports\n");
306 icp
->icp_iobase
= iobase
;
309 switch (ICP_CLASS(icp
)) {
311 bus_space_set_region_4(dpmemt
, dpmemh
, 0, 0,
313 if (bus_space_read_1(dpmemt
, dpmemh
, 0) != 0) {
314 aprint_error("cannot write to DPMEM\n");
319 /* disable board interrupts, deinit services */
320 icph_writeb(0xff, &dp6_ptr
->io
.irqdel
);
321 icph_writeb(0x00, &dp6_ptr
->io
.irqen
);
322 icph_writeb(0x00, &dp6_ptr
->u
.ic
.S_Status
);
323 icph_writeb(0x00, &dp6_ptr
->u
.ic
.Cmd_Index
);
325 icph_writel(pcistr
->dpmem
, &dp6_ptr
->u
.ic
.S_Info
[0]);
326 icph_writeb(0xff, &dp6_ptr
->u
.ic
.S_Cmd_Indx
);
327 icph_writeb(0, &dp6_ptr
->io
.event
);
328 retries
= INIT_RETRIES
;
330 while (icph_readb(&dp6_ptr
->u
.ic
.S_Status
) != 0xff) {
331 if (--retries
== 0) {
332 printk("initialization error (DEINIT failed)\n");
333 icph_munmap(ha
->brd
);
338 prot_ver
= (unchar
)icph_readl(&dp6_ptr
->u
.ic
.S_Info
[0]);
339 icph_writeb(0, &dp6_ptr
->u
.ic
.S_Status
);
340 icph_writeb(0xff, &dp6_ptr
->io
.irqdel
);
341 if (prot_ver
!= PROTOCOL_VERSION
) {
342 printk("illegal protocol version\n");
343 icph_munmap(ha
->brd
);
348 ha
->ic_all_size
= sizeof(dp6_ptr
->u
);
350 /* special command to controller BIOS */
351 icph_writel(0x00, &dp6_ptr
->u
.ic
.S_Info
[0]);
352 icph_writel(0x00, &dp6_ptr
->u
.ic
.S_Info
[1]);
353 icph_writel(0x01, &dp6_ptr
->u
.ic
.S_Info
[2]);
354 icph_writel(0x00, &dp6_ptr
->u
.ic
.S_Info
[3]);
355 icph_writeb(0xfe, &dp6_ptr
->u
.ic
.S_Cmd_Indx
);
356 icph_writeb(0, &dp6_ptr
->io
.event
);
357 retries
= INIT_RETRIES
;
359 while (icph_readb(&dp6_ptr
->u
.ic
.S_Status
) != 0xfe) {
360 if (--retries
== 0) {
361 printk("initialization error\n");
362 icph_munmap(ha
->brd
);
367 icph_writeb(0, &dp6_ptr
->u
.ic
.S_Status
);
368 icph_writeb(0xff, &dp6_ptr
->io
.irqdel
);
371 icp
->icp_ic_all_size
= ICP_DPRAM_SZ
;
373 icp
->icp_copy_cmd
= icp_pci_copy_cmd
;
374 icp
->icp_get_status
= icp_pci_get_status
;
375 icp
->icp_intr
= icp_pci_intr
;
376 icp
->icp_release_event
= icp_pci_release_event
;
377 icp
->icp_set_sema0
= icp_pci_set_sema0
;
378 icp
->icp_test_busy
= icp_pci_test_busy
;
383 bus_space_set_region_4(dpmemt
, dpmemh
, 0, 0,
385 if (bus_space_read_1(dpmemt
, dpmemh
, 0) != 0) {
386 aprint_error("cannot write to DPMEM\n");
391 /* disable board interrupts, deinit services */
392 outb(0x00,PTR2USHORT(&ha
->plx
->control1
));
393 outb(0xff,PTR2USHORT(&ha
->plx
->edoor_reg
));
395 icph_writeb(0x00, &dp6c_ptr
->u
.ic
.S_Status
);
396 icph_writeb(0x00, &dp6c_ptr
->u
.ic
.Cmd_Index
);
398 icph_writel(pcistr
->dpmem
, &dp6c_ptr
->u
.ic
.S_Info
[0]);
399 icph_writeb(0xff, &dp6c_ptr
->u
.ic
.S_Cmd_Indx
);
401 outb(1,PTR2USHORT(&ha
->plx
->ldoor_reg
));
403 retries
= INIT_RETRIES
;
405 while (icph_readb(&dp6c_ptr
->u
.ic
.S_Status
) != 0xff) {
406 if (--retries
== 0) {
407 printk("initialization error (DEINIT failed)\n");
408 icph_munmap(ha
->brd
);
413 prot_ver
= (unchar
)icph_readl(&dp6c_ptr
->u
.ic
.S_Info
[0]);
414 icph_writeb(0, &dp6c_ptr
->u
.ic
.Status
);
415 if (prot_ver
!= PROTOCOL_VERSION
) {
416 printk("illegal protocol version\n");
417 icph_munmap(ha
->brd
);
421 ha
->type
= ICP_PCINEW
;
422 ha
->ic_all_size
= sizeof(dp6c_ptr
->u
);
424 /* special command to controller BIOS */
425 icph_writel(0x00, &dp6c_ptr
->u
.ic
.S_Info
[0]);
426 icph_writel(0x00, &dp6c_ptr
->u
.ic
.S_Info
[1]);
427 icph_writel(0x01, &dp6c_ptr
->u
.ic
.S_Info
[2]);
428 icph_writel(0x00, &dp6c_ptr
->u
.ic
.S_Info
[3]);
429 icph_writeb(0xfe, &dp6c_ptr
->u
.ic
.S_Cmd_Indx
);
431 outb(1,PTR2USHORT(&ha
->plx
->ldoor_reg
));
433 retries
= INIT_RETRIES
;
435 while (icph_readb(&dp6c_ptr
->u
.ic
.S_Status
) != 0xfe) {
436 if (--retries
== 0) {
437 printk("initialization error\n");
438 icph_munmap(ha
->brd
);
443 icph_writeb(0, &dp6c_ptr
->u
.ic
.S_Status
);
446 icp
->icp_ic_all_size
= ICP_PCINEW_SZ
;
448 icp
->icp_copy_cmd
= icp_pcinew_copy_cmd
;
449 icp
->icp_get_status
= icp_pcinew_get_status
;
450 icp
->icp_intr
= icp_pcinew_intr
;
451 icp
->icp_release_event
= icp_pcinew_release_event
;
452 icp
->icp_set_sema0
= icp_pcinew_set_sema0
;
453 icp
->icp_test_busy
= icp_pcinew_test_busy
;
458 bus_space_write_4(dpmemt
, dpmemh
, ICP_MPR_IC
, ICP_MPR_MAGIC
);
459 if (bus_space_read_4(dpmemt
, dpmemh
, ICP_MPR_IC
) !=
462 "cannot access DPMEM at 0x%lx (shadowed?)\n",
468 * XXX Here the Linux driver has a weird remapping logic I
469 * don't understand. My controller does not need it, and I
470 * cannot see what purpose it serves, therefore I did not
471 * do anything similar.
474 bus_space_set_region_4(dpmemt
, dpmemh
, ICP_I960_SZ
, 0,
477 /* Disable everything. */
478 bus_space_write_1(dpmemt
, dpmemh
, ICP_EDOOR_EN
,
479 bus_space_read_1(dpmemt
, dpmemh
, ICP_EDOOR_EN
) | 4);
480 bus_space_write_1(dpmemt
, dpmemh
, ICP_MPR_EDOOR
, 0xff);
481 bus_space_write_1(dpmemt
, dpmemh
, ICP_MPR_IC
+ ICP_S_STATUS
,
483 bus_space_write_1(dpmemt
, dpmemh
, ICP_MPR_IC
+ ICP_CMD_INDEX
,
486 bus_space_write_4(dpmemt
, dpmemh
, ICP_MPR_IC
+ ICP_S_INFO
,
488 bus_space_write_1(dpmemt
, dpmemh
, ICP_MPR_IC
+ ICP_S_CMD_INDX
,
490 bus_space_write_1(dpmemt
, dpmemh
, ICP_MPR_LDOOR
, 1);
494 while (bus_space_read_1(dpmemt
, dpmemh
,
495 ICP_MPR_IC
+ ICP_S_STATUS
) != 0xff) {
496 if (--retries
== 0) {
497 aprint_error("DEINIT failed\n");
503 protocol
= (u_int8_t
)bus_space_read_4(dpmemt
, dpmemh
,
504 ICP_MPR_IC
+ ICP_S_INFO
);
505 bus_space_write_1(dpmemt
, dpmemh
, ICP_MPR_IC
+ ICP_S_STATUS
,
507 if (protocol
!= ICP_PROTOCOL_VERSION
) {
508 aprint_error("unsupported protocol %d\n", protocol
);
512 /* special commnd to controller BIOS */
513 bus_space_write_4(dpmemt
, dpmemh
, ICP_MPR_IC
+ ICP_S_INFO
, 0);
514 bus_space_write_4(dpmemt
, dpmemh
,
515 ICP_MPR_IC
+ ICP_S_INFO
+ sizeof(u_int32_t
), 0);
516 bus_space_write_4(dpmemt
, dpmemh
,
517 ICP_MPR_IC
+ ICP_S_INFO
+ 2 * sizeof(u_int32_t
), 1);
518 bus_space_write_4(dpmemt
, dpmemh
,
519 ICP_MPR_IC
+ ICP_S_INFO
+ 3 * sizeof(u_int32_t
), 0);
520 bus_space_write_1(dpmemt
, dpmemh
, ICP_MPR_IC
+ ICP_S_CMD_INDX
,
522 bus_space_write_1(dpmemt
, dpmemh
, ICP_MPR_LDOOR
, 1);
526 while (bus_space_read_1(dpmemt
, dpmemh
,
527 ICP_MPR_IC
+ ICP_S_STATUS
) != 0xfe) {
528 if (--retries
== 0) {
529 aprint_error("initialization error\n");
535 bus_space_write_1(dpmemt
, dpmemh
, ICP_MPR_IC
+ ICP_S_STATUS
,
538 icp
->icp_copy_cmd
= icp_mpr_copy_cmd
;
539 icp
->icp_get_status
= icp_mpr_get_status
;
540 icp
->icp_intr
= icp_mpr_intr
;
541 icp
->icp_release_event
= icp_mpr_release_event
;
542 icp
->icp_set_sema0
= icp_mpr_set_sema0
;
543 icp
->icp_test_busy
= icp_mpr_test_busy
;
547 if (pci_intr_map(pa
, &ih
)) {
548 aprint_error("couldn't map interrupt\n");
551 intrstr
= pci_intr_string(pa
->pa_pc
, ih
);
552 icp
->icp_ih
= pci_intr_establish(pa
->pa_pc
, ih
, IPL_BIO
, icp_intr
, icp
);
553 if (icp
->icp_ih
== NULL
) {
554 aprint_error("couldn't establish interrupt");
556 aprint_error(" at %s", intrstr
);
560 status
|= INTR_ESTABLISHED
;
562 if (PCI_VENDOR(pa
->pa_id
) == PCI_VENDOR_INTEL
)
563 aprint_normal("Intel Storage RAID controller\n");
565 aprint_normal("ICP-Vortex RAID controller\n");
567 icp
->icp_pci_bus
= pa
->pa_bus
;
568 icp
->icp_pci_device
= pa
->pa_device
;
569 icp
->icp_pci_device_id
= PCI_PRODUCT(pa
->pa_id
);
570 icp
->icp_pci_subdevice_id
= pci_conf_read(pa
->pa_pc
, pa
->pa_tag
,
573 if (icp_init(icp
, intrstr
))
576 icp_pci_enable_intr(icp
);
580 if ((status
& DPMEM_MAPPED
) != 0)
581 bus_space_unmap(dpmemt
, dpmemh
, dpmemsize
);
582 if ((status
& IOMEM_MAPPED
) != 0)
583 bus_space_unmap(iomemt
, iomemh
, iomembase
);
584 if ((status
& IO_MAPPED
) != 0)
585 bus_space_unmap(iot
, ioh
, iosize
);
586 if ((status
& INTR_ESTABLISHED
) != 0)
587 pci_intr_disestablish(pa
->pa_pc
, icp
->icp_ih
);
594 icp_pci_enable_intr(struct icp_softc
*icp
)
597 switch (ICP_CLASS(icp
)) {
599 bus_space_write_1(icp
->icp_dpmemt
, icp
->icp_dpmemh
, ICP_IRQDEL
,
601 bus_space_write_1(icp
->icp_dpmemt
, icp
->icp_dpmemh
,
603 bus_space_write_1(icp
->icp_dpmemt
, icp
->icp_dpmemh
, ICP_IRQEN
,
608 bus_space_write_1(icp
->icp_iot
, icp
->icp_ioh
, ICP_EDOOR_REG
,
610 bus_space_write_1(icp
->icp_iot
, icp
->icp_ioh
, ICP_CONTROL1
, 3);
614 bus_space_write_1(icp
->icp_dpmemt
, icp
->icp_dpmemh
,
615 ICP_MPR_EDOOR
, 0xff);
616 bus_space_write_1(icp
->icp_dpmemt
, icp
->icp_dpmemh
, ICP_EDOOR_EN
,
617 bus_space_read_1(icp
->icp_dpmemt
, icp
->icp_dpmemh
,
624 * "Old" PCI controller-specific functions.
628 icp_pci_copy_cmd(struct icp_softc
*icp
, struct icp_ccb
*ccb
)
631 /* XXX Not yet implemented */
635 icp_pci_get_status(struct icp_softc
*icp
)
638 /* XXX Not yet implemented */
643 icp_pci_intr(struct icp_softc
*icp
, struct icp_intr_ctx
*ctx
)
646 /* XXX Not yet implemented */
650 icp_pci_release_event(struct icp_softc
*icp
,
654 /* XXX Not yet implemented */
658 icp_pci_set_sema0(struct icp_softc
*icp
)
661 bus_space_write_1(icp
->icp_dpmemt
, icp
->icp_dpmemh
, ICP_SEMA0
, 1);
665 icp_pci_test_busy(struct icp_softc
*icp
)
668 /* XXX Not yet implemented */
673 * "New" PCI controller-specific functions.
677 icp_pcinew_copy_cmd(struct icp_softc
*icp
,
681 /* XXX Not yet implemented */
685 icp_pcinew_get_status(struct icp_softc
*icp
)
688 /* XXX Not yet implemented */
693 icp_pcinew_intr(struct icp_softc
*icp
,
694 struct icp_intr_ctx
*ctx
)
697 /* XXX Not yet implemented */
701 icp_pcinew_release_event(struct icp_softc
*icp
,
705 /* XXX Not yet implemented */
709 icp_pcinew_set_sema0(struct icp_softc
*icp
)
712 bus_space_write_1(icp
->icp_iot
, icp
->icp_ioh
, ICP_SEMA0_REG
, 1);
716 icp_pcinew_test_busy(struct icp_softc
*icp
)
719 /* XXX Not yet implemented */
724 * MPR PCI controller-specific functions
728 icp_mpr_copy_cmd(struct icp_softc
*icp
, struct icp_ccb
*ic
)
731 bus_space_write_2(icp
->icp_dpmemt
, icp
->icp_dpmemh
,
732 ICP_MPR_IC
+ ICP_COMM_QUEUE
+ 0 * ICP_COMM_Q_SZ
+ ICP_OFFSET
,
734 bus_space_write_2(icp
->icp_dpmemt
, icp
->icp_dpmemh
,
735 ICP_MPR_IC
+ ICP_COMM_QUEUE
+ 0 * ICP_COMM_Q_SZ
+ ICP_SERV_ID
,
737 bus_space_write_region_4(icp
->icp_dpmemt
, icp
->icp_dpmemh
,
738 ICP_MPR_IC
+ ICP_DPR_CMD
, (u_int32_t
*)&ic
->ic_cmd
,
743 icp_mpr_get_status(struct icp_softc
*icp
)
746 return (bus_space_read_1(icp
->icp_dpmemt
, icp
->icp_dpmemh
,
751 icp_mpr_intr(struct icp_softc
*icp
, struct icp_intr_ctx
*ctx
)
754 if ((ctx
->istatus
& 0x80) != 0) { /* error flag */
755 ctx
->istatus
&= ~0x80;
756 ctx
->cmd_status
= bus_space_read_2(icp
->icp_dpmemt
,
757 icp
->icp_dpmemh
, ICP_MPR_STATUS
);
759 ctx
->cmd_status
= ICP_S_OK
;
761 ctx
->service
= bus_space_read_2(icp
->icp_dpmemt
, icp
->icp_dpmemh
,
763 ctx
->info
= bus_space_read_4(icp
->icp_dpmemt
, icp
->icp_dpmemh
,
765 ctx
->info2
= bus_space_read_4(icp
->icp_dpmemt
, icp
->icp_dpmemh
,
766 ICP_MPR_INFO
+ sizeof(u_int32_t
));
768 if (ctx
->istatus
== ICP_ASYNCINDEX
) {
769 if (ctx
->service
!= ICP_SCREENSERVICE
&&
770 (icp
->icp_fw_vers
& 0xff) >= 0x1a) {
773 icp
->icp_evt
.severity
=
774 bus_space_read_1(icp
->icp_dpmemt
,
775 icp
->icp_dpmemh
, ICP_SEVERITY
);
777 i
< sizeof(icp
->icp_evt
.event_string
); i
++) {
778 icp
->icp_evt
.event_string
[i
] =
779 bus_space_read_1(icp
->icp_dpmemt
,
780 icp
->icp_dpmemh
, ICP_EVT_BUF
+ i
);
781 if (icp
->icp_evt
.event_string
[i
] == '\0')
787 bus_space_write_1(icp
->icp_dpmemt
, icp
->icp_dpmemh
, ICP_MPR_EDOOR
,
789 bus_space_write_1(icp
->icp_dpmemt
, icp
->icp_dpmemh
, ICP_MPR_SEMA1
, 0);
793 icp_mpr_release_event(struct icp_softc
*icp
, struct icp_ccb
*ic
)
796 bus_space_write_1(icp
->icp_dpmemt
, icp
->icp_dpmemh
, ICP_MPR_LDOOR
, 1);
800 icp_mpr_set_sema0(struct icp_softc
*icp
)
803 bus_space_write_1(icp
->icp_dpmemt
, icp
->icp_dpmemh
, ICP_MPR_SEMA0
, 1);
807 icp_mpr_test_busy(struct icp_softc
*icp
)
810 return (bus_space_read_1(icp
->icp_dpmemt
, icp
->icp_dpmemh
,