mpt_pci.c revision 1.11.8.2 1 1.11.8.2 tron /* $NetBSD: mpt_pci.c,v 1.11.8.2 2007/07/27 13:06:52 tron Exp $ */
2 1.11.8.2 tron
3 1.11.8.2 tron /*
4 1.11.8.2 tron * Copyright (c) 2003 Wasabi Systems, Inc.
5 1.11.8.2 tron * All rights reserved.
6 1.11.8.2 tron *
7 1.11.8.2 tron * Written by Jason R. Thorpe for Wasabi Systems, Inc.
8 1.11.8.2 tron *
9 1.11.8.2 tron * Redistribution and use in source and binary forms, with or without
10 1.11.8.2 tron * modification, are permitted provided that the following conditions
11 1.11.8.2 tron * are met:
12 1.11.8.2 tron * 1. Redistributions of source code must retain the above copyright
13 1.11.8.2 tron * notice, this list of conditions and the following disclaimer.
14 1.11.8.2 tron * 2. Redistributions in binary form must reproduce the above copyright
15 1.11.8.2 tron * notice, this list of conditions and the following disclaimer in the
16 1.11.8.2 tron * documentation and/or other materials provided with the distribution.
17 1.11.8.2 tron * 3. All advertising materials mentioning features or use of this software
18 1.11.8.2 tron * must display the following acknowledgement:
19 1.11.8.2 tron * This product includes software developed for the NetBSD Project by
20 1.11.8.2 tron * Wasabi Systems, Inc.
21 1.11.8.2 tron * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 1.11.8.2 tron * or promote products derived from this software without specific prior
23 1.11.8.2 tron * written permission.
24 1.11.8.2 tron *
25 1.11.8.2 tron * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 1.11.8.2 tron * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 1.11.8.2 tron * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 1.11.8.2 tron * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 1.11.8.2 tron * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 1.11.8.2 tron * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 1.11.8.2 tron * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 1.11.8.2 tron * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 1.11.8.2 tron * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 1.11.8.2 tron * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 1.11.8.2 tron * POSSIBILITY OF SUCH DAMAGE.
36 1.11.8.2 tron */
37 1.11.8.2 tron
38 1.11.8.2 tron /*
39 1.11.8.2 tron * Additional contributions by Garrett D'Amore on behalf of TELES AG.
40 1.11.8.2 tron */
41 1.11.8.2 tron
42 1.11.8.2 tron /*
43 1.11.8.2 tron * mpt_pci.c:
44 1.11.8.2 tron *
45 1.11.8.2 tron * NetBSD PCI-specific routines for LSI Fusion adapters.
46 1.11.8.2 tron */
47 1.11.8.2 tron
48 1.11.8.2 tron #include <sys/cdefs.h>
49 1.11.8.2 tron __KERNEL_RCSID(0, "$NetBSD: mpt_pci.c,v 1.11.8.2 2007/07/27 13:06:52 tron Exp $");
50 1.11.8.2 tron
51 1.11.8.2 tron #include <dev/ic/mpt.h> /* pulls in all headers */
52 1.11.8.2 tron
53 1.11.8.2 tron #include <dev/pci/pcireg.h>
54 1.11.8.2 tron #include <dev/pci/pcivar.h>
55 1.11.8.2 tron #include <dev/pci/pcidevs.h>
56 1.11.8.2 tron
57 1.11.8.2 tron #define MPT_PCI_MMBA (PCI_MAPREG_START+0x04)
58 1.11.8.2 tron
59 1.11.8.2 tron struct mpt_pci_softc {
60 1.11.8.2 tron mpt_softc_t sc_mpt;
61 1.11.8.2 tron
62 1.11.8.2 tron pci_chipset_tag_t sc_pc;
63 1.11.8.2 tron pcitag_t sc_tag;
64 1.11.8.2 tron
65 1.11.8.2 tron void *sc_ih;
66 1.11.8.2 tron
67 1.11.8.2 tron /* Saved volatile PCI configuration registers. */
68 1.11.8.2 tron pcireg_t sc_pci_csr;
69 1.11.8.2 tron pcireg_t sc_pci_bhlc;
70 1.11.8.2 tron pcireg_t sc_pci_io_bar;
71 1.11.8.2 tron pcireg_t sc_pci_mem0_bar[2];
72 1.11.8.2 tron pcireg_t sc_pci_mem1_bar[2];
73 1.11.8.2 tron pcireg_t sc_pci_rom_bar;
74 1.11.8.2 tron pcireg_t sc_pci_int;
75 1.11.8.2 tron pcireg_t sc_pci_pmcsr;
76 1.11.8.2 tron };
77 1.11.8.2 tron
78 1.11.8.2 tron #define MPP_F_FC 0x01 /* Fibre Channel adapter */
79 1.11.8.2 tron #define MPP_F_DUAL 0x02 /* Dual port adapter */
80 1.11.8.2 tron
81 1.11.8.2 tron static const struct mpt_pci_product {
82 1.11.8.2 tron pci_vendor_id_t mpp_vendor;
83 1.11.8.2 tron pci_product_id_t mpp_product;
84 1.11.8.2 tron } mpt_pci_products[] = {
85 1.11.8.2 tron { PCI_VENDOR_SYMBIOS, PCI_PRODUCT_SYMBIOS_1030 },
86 1.11.8.2 tron { PCI_VENDOR_SYMBIOS, PCI_PRODUCT_SYMBIOS_FC909 },
87 1.11.8.2 tron { PCI_VENDOR_SYMBIOS, PCI_PRODUCT_SYMBIOS_FC909A },
88 1.11.8.2 tron { PCI_VENDOR_SYMBIOS, PCI_PRODUCT_SYMBIOS_FC929 },
89 1.11.8.2 tron { PCI_VENDOR_SYMBIOS, PCI_PRODUCT_SYMBIOS_FC929_1 },
90 1.11.8.2 tron { PCI_VENDOR_SYMBIOS, PCI_PRODUCT_SYMBIOS_FC919 },
91 1.11.8.2 tron { PCI_VENDOR_SYMBIOS, PCI_PRODUCT_SYMBIOS_FC919_1},
92 1.11.8.2 tron { PCI_VENDOR_SYMBIOS, PCI_PRODUCT_SYMBIOS_FC929X },
93 1.11.8.2 tron { PCI_VENDOR_SYMBIOS, PCI_PRODUCT_SYMBIOS_FC919X },
94 1.11.8.2 tron { PCI_VENDOR_SYMBIOS, PCI_PRODUCT_SYMBIOS_FC929X },
95 1.11.8.2 tron { PCI_VENDOR_SYMBIOS, PCI_PRODUCT_SYMBIOS_FC939X },
96 1.11.8.2 tron { PCI_VENDOR_SYMBIOS, PCI_PRODUCT_SYMBIOS_FC949X },
97 1.11.8.2 tron { PCI_VENDOR_SYMBIOS, PCI_PRODUCT_SYMBIOS_SAS1064 },
98 1.11.8.2 tron { PCI_VENDOR_SYMBIOS, PCI_PRODUCT_SYMBIOS_SAS1064A },
99 1.11.8.2 tron { PCI_VENDOR_SYMBIOS, PCI_PRODUCT_SYMBIOS_SAS1064E },
100 1.11.8.2 tron { PCI_VENDOR_SYMBIOS, PCI_PRODUCT_SYMBIOS_SAS1066 },
101 1.11.8.2 tron { PCI_VENDOR_SYMBIOS, PCI_PRODUCT_SYMBIOS_SAS1066E },
102 1.11.8.2 tron { PCI_VENDOR_SYMBIOS, PCI_PRODUCT_SYMBIOS_SAS1068 },
103 1.11.8.2 tron { PCI_VENDOR_SYMBIOS, PCI_PRODUCT_SYMBIOS_SAS1078 },
104 1.11.8.2 tron { PCI_VENDOR_SYMBIOS, PCI_PRODUCT_SYMBIOS_SAS1068E },
105 1.11.8.2 tron { 0, 0 }
106 1.11.8.2 tron };
107 1.11.8.2 tron
108 1.11.8.2 tron static int
109 1.11.8.2 tron mpt_pci_match(struct device *parent, struct cfdata *cf, void *aux)
110 1.11.8.2 tron {
111 1.11.8.2 tron struct pci_attach_args *pa = aux;
112 1.11.8.2 tron const struct mpt_pci_product *mpp;
113 1.11.8.2 tron
114 1.11.8.2 tron for (mpp = mpt_pci_products; mpp->mpp_vendor != 0; mpp++) {
115 1.11.8.2 tron if (PCI_VENDOR(pa->pa_id) == mpp->mpp_vendor &&
116 1.11.8.2 tron PCI_PRODUCT(pa->pa_id) == mpp->mpp_product)
117 1.11.8.2 tron return (1);
118 1.11.8.2 tron }
119 1.11.8.2 tron
120 1.11.8.2 tron return (0);
121 1.11.8.2 tron }
122 1.11.8.2 tron
123 1.11.8.2 tron static void
124 1.11.8.2 tron mpt_pci_attach(struct device *parent, struct device *self, void *aux)
125 1.11.8.2 tron {
126 1.11.8.2 tron struct mpt_pci_softc *psc = (void *) self;
127 1.11.8.2 tron mpt_softc_t *mpt = &psc->sc_mpt;
128 1.11.8.2 tron struct pci_attach_args *pa = aux;
129 1.11.8.2 tron pci_intr_handle_t ih;
130 1.11.8.2 tron const char *intrstr;
131 1.11.8.2 tron pcireg_t reg, memtype;
132 1.11.8.2 tron bus_space_tag_t memt;
133 1.11.8.2 tron bus_space_handle_t memh;
134 1.11.8.2 tron int memh_valid;
135 1.11.8.2 tron char devinfo[200];
136 1.11.8.2 tron
137 1.11.8.2 tron pci_devinfo(pa->pa_id, 0, 0, devinfo, sizeof (devinfo));
138 1.11.8.2 tron
139 1.11.8.2 tron aprint_naive("\n");
140 1.11.8.2 tron aprint_normal(": %s\n", devinfo);
141 1.11.8.2 tron
142 1.11.8.2 tron psc->sc_pc = pa->pa_pc;
143 1.11.8.2 tron psc->sc_tag = pa->pa_tag;
144 1.11.8.2 tron
145 1.11.8.2 tron mpt->sc_dmat = pa->pa_dmat;
146 1.11.8.2 tron
147 1.11.8.2 tron /*
148 1.11.8.2 tron * Map the device.
149 1.11.8.2 tron */
150 1.11.8.2 tron memtype = pci_mapreg_type(pa->pa_pc, pa->pa_tag, MPT_PCI_MMBA);
151 1.11.8.2 tron switch (memtype) {
152 1.11.8.2 tron case PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT:
153 1.11.8.2 tron case PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_64BIT:
154 1.11.8.2 tron memh_valid = (pci_mapreg_map(pa, MPT_PCI_MMBA,
155 1.11.8.2 tron memtype, 0, &memt, &memh, NULL, NULL) == 0);
156 1.11.8.2 tron break;
157 1.11.8.2 tron
158 1.11.8.2 tron default:
159 1.11.8.2 tron memh_valid = 0;
160 1.11.8.2 tron }
161 1.11.8.2 tron
162 1.11.8.2 tron if (memh_valid) {
163 1.11.8.2 tron mpt->sc_st = memt;
164 1.11.8.2 tron mpt->sc_sh = memh;
165 1.11.8.2 tron } else {
166 1.11.8.2 tron aprint_error("%s: unable to map device registers\n",
167 1.11.8.2 tron mpt->sc_dev.dv_xname);
168 1.11.8.2 tron return;
169 1.11.8.2 tron }
170 1.11.8.2 tron
171 1.11.8.2 tron /*
172 1.11.8.2 tron * Make sure the PCI command register is properly configured.
173 1.11.8.2 tron */
174 1.11.8.2 tron reg = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
175 1.11.8.2 tron reg |= PCI_COMMAND_MASTER_ENABLE;
176 1.11.8.2 tron /* XXX PCI_COMMAND_INVALIDATE_ENABLE */
177 1.11.8.2 tron /* XXX PCI_COMMAND_PARITY_ENABLE */
178 1.11.8.2 tron /* XXX PCI_COMMAND_SERR_ENABLE */
179 1.11.8.2 tron pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG, reg);
180 1.11.8.2 tron
181 1.11.8.2 tron /*
182 1.11.8.2 tron * Ensure that the ROM is diabled.
183 1.11.8.2 tron */
184 1.11.8.2 tron reg = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_MAPREG_ROM);
185 1.11.8.2 tron reg &= ~1;
186 1.11.8.2 tron pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_MAPREG_ROM, reg);
187 1.11.8.2 tron
188 1.11.8.2 tron /*
189 1.11.8.2 tron * Map and establish our interrupt.
190 1.11.8.2 tron */
191 1.11.8.2 tron if (pci_intr_map(pa, &ih) != 0) {
192 1.11.8.2 tron aprint_error("%s: unable to map interrupt\n",
193 1.11.8.2 tron mpt->sc_dev.dv_xname);
194 1.11.8.2 tron return;
195 1.11.8.2 tron }
196 1.11.8.2 tron intrstr = pci_intr_string(pa->pa_pc, ih);
197 1.11.8.2 tron psc->sc_ih = pci_intr_establish(pa->pa_pc, ih, IPL_BIO, mpt_intr, mpt);
198 1.11.8.2 tron if (psc->sc_ih == NULL) {
199 1.11.8.2 tron aprint_error("%s: unable to establish interrupt",
200 1.11.8.2 tron mpt->sc_dev.dv_xname);
201 1.11.8.2 tron if (intrstr != NULL)
202 1.11.8.2 tron aprint_normal(" at %s", intrstr);
203 1.11.8.2 tron aprint_normal("\n");
204 1.11.8.2 tron return;
205 1.11.8.2 tron }
206 1.11.8.2 tron aprint_normal("%s: interrupting at %s\n", mpt->sc_dev.dv_xname,
207 1.11.8.2 tron intrstr);
208 1.11.8.2 tron
209 1.11.8.2 tron /* Disable interrupts on the part. */
210 1.11.8.2 tron mpt_disable_ints(mpt);
211 1.11.8.2 tron
212 1.11.8.2 tron /* Allocate DMA memory. */
213 1.11.8.2 tron if (mpt_dma_mem_alloc(mpt) != 0) {
214 1.11.8.2 tron aprint_error("%s: unable to allocate DMA memory\n",
215 1.11.8.2 tron mpt->sc_dev.dv_xname);
216 1.11.8.2 tron return;
217 1.11.8.2 tron }
218 1.11.8.2 tron
219 1.11.8.2 tron /* Initialize the hardware. */
220 1.11.8.2 tron if (mpt_init(mpt, MPT_DB_INIT_HOST) != 0) {
221 1.11.8.2 tron /* Error message already printed. */
222 1.11.8.2 tron return;
223 1.11.8.2 tron }
224 1.11.8.2 tron
225 1.11.8.2 tron /* Attach to scsipi. */
226 1.11.8.2 tron mpt_scsipi_attach(mpt);
227 1.11.8.2 tron }
228 1.11.8.2 tron
229 1.11.8.2 tron CFATTACH_DECL(mpt_pci, sizeof(struct mpt_pci_softc),
230 1.11.8.2 tron mpt_pci_match, mpt_pci_attach, NULL, NULL);
231 1.11.8.2 tron
232