1 /* $OpenBSD: twe_pci.c,v 1.16 2024/05/24 06:02:58 jsg Exp $ */
2
3 /*
4 * Copyright (c) 2000 Michael Shalayeff
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
20 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
25 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
26 * THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #include <sys/param.h>
30 #include <sys/systm.h>
31 #include <sys/device.h>
32
33 #include <dev/pci/pcidevs.h>
34 #include <dev/pci/pcivar.h>
35
36 #include <machine/bus.h>
37
38 #include <scsi/scsi_all.h>
39 #include <scsi/scsi_disk.h>
40 #include <scsi/scsiconf.h>
41
42 #include <dev/ic/twereg.h>
43 #include <dev/ic/twevar.h>
44
45 #define TWE_BAR 0x10
46
47 int twe_pci_match(struct device *, void *, void *);
48 void twe_pci_attach(struct device *, struct device *, void *);
49
50 const struct cfattach twe_pci_ca = {
51 sizeof(struct twe_softc), twe_pci_match, twe_pci_attach
52 };
53
54 const struct pci_matchid twe_pci_devices[] = {
55 { PCI_VENDOR_3WARE, PCI_PRODUCT_3WARE_ESCALADE },
56 { PCI_VENDOR_3WARE, PCI_PRODUCT_3WARE_ESCALADE_ASIC }
57 };
58
59 int
twe_pci_match(struct device * parent,void * match,void * aux)60 twe_pci_match(struct device *parent, void *match, void *aux)
61 {
62 return (pci_matchbyid((struct pci_attach_args *)aux, twe_pci_devices,
63 nitems(twe_pci_devices)));
64 }
65
66 void
twe_pci_attach(struct device * parent,struct device * self,void * aux)67 twe_pci_attach(struct device *parent, struct device *self, void *aux)
68 {
69 struct twe_softc *sc = (struct twe_softc *)self;
70 struct pci_attach_args *pa = aux;
71 pci_intr_handle_t ih;
72 const char *intrstr;
73 bus_size_t size;
74
75 if (pci_mapreg_map(pa, TWE_BAR, PCI_MAPREG_TYPE_IO, 0,
76 &sc->iot, &sc->ioh, NULL, &size, 0)) {
77 printf(": can't map controller i/o space\n");
78 return;
79 }
80 sc->dmat = pa->pa_dmat;
81
82 if (pci_intr_map(pa, &ih)) {
83 printf(": can't map interrupt\n");
84 bus_space_unmap(sc->iot, sc->ioh, size);
85 return;
86 }
87 intrstr = pci_intr_string(pa->pa_pc, ih);
88 sc->sc_ih = pci_intr_establish(pa->pa_pc, ih, IPL_BIO, twe_intr, sc,
89 sc->sc_dev.dv_xname);
90 if (!sc->sc_ih) {
91 printf(": can't establish interrupt");
92 if (intrstr)
93 printf(" at %s", intrstr);
94 printf("\n");
95 bus_space_unmap(sc->iot, sc->ioh, size);
96 return;
97 }
98
99 printf(": %s\n%s", intrstr, sc->sc_dev.dv_xname);
100
101 if (twe_attach(sc)) {
102 pci_intr_disestablish(pa->pa_pc, sc->sc_ih);
103 sc->sc_ih = NULL;
104 bus_space_unmap(sc->iot, sc->ioh, size);
105 }
106 }
107