mpt_pci.c revision 209961
1119418Sobrien/*-
2102596Smjacob * PCI specific probe and attach routines for LSI Fusion Adapters
3101704Smjacob * FreeBSD Version.
4101704Smjacob *
5119418Sobrien * Copyright (c) 2000, 2001 by Greg Ansley
6101704Smjacob * Partially derived from Matt Jacob's ISP driver.
7119418Sobrien * Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002 by Matthew Jacob
8119418Sobrien * Feral Software
9119418Sobrien * All rights reserved.
10101704Smjacob *
11101704Smjacob * Redistribution and use in source and binary forms, with or without
12101704Smjacob * modification, are permitted provided that the following conditions
13101704Smjacob * are met:
14101704Smjacob * 1. Redistributions of source code must retain the above copyright
15101704Smjacob *    notice immediately at the beginning of the file, without modification,
16101704Smjacob *    this list of conditions, and the following disclaimer.
17101704Smjacob * 2. The name of the author may not be used to endorse or promote products
18101704Smjacob *    derived from this software without specific prior written permission.
19101704Smjacob *
20101704Smjacob * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21101704Smjacob * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22101704Smjacob * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23101704Smjacob * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
24101704Smjacob * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25101704Smjacob * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26101704Smjacob * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27101704Smjacob * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28101704Smjacob * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29101704Smjacob * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30101704Smjacob * SUCH DAMAGE.
31101704Smjacob */
32156000Smjacob/*-
33156000Smjacob * Copyright (c) 2002, 2006 by Matthew Jacob
34156000Smjacob * All rights reserved.
35156000Smjacob *
36156000Smjacob * Redistribution and use in source and binary forms, with or without
37156000Smjacob * modification, are permitted provided that the following conditions are
38156000Smjacob * met:
39156000Smjacob * 1. Redistributions of source code must retain the above copyright
40156000Smjacob *    notice, this list of conditions and the following disclaimer.
41156000Smjacob * 2. Redistributions in binary form must reproduce at minimum a disclaimer
42156000Smjacob *    substantially similar to the "NO WARRANTY" disclaimer below
43156000Smjacob *    ("Disclaimer") and any redistribution must be conditioned upon including
44156000Smjacob *    a substantially similar Disclaimer requirement for further binary
45156000Smjacob *    redistribution.
46156000Smjacob * 3. Neither the names of the above listed copyright holders nor the names
47156000Smjacob *    of any contributors may be used to endorse or promote products derived
48156000Smjacob *    from this software without specific prior written permission.
49156000Smjacob *
50156000Smjacob * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
51156000Smjacob * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52156000Smjacob * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53156000Smjacob * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
54156000Smjacob * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
55156000Smjacob * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
56156000Smjacob * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
57156000Smjacob * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
58156000Smjacob * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
59156000Smjacob * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF THE COPYRIGHT
60156000Smjacob * OWNER OR CONTRIBUTOR IS ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61156000Smjacob *
62156000Smjacob * Support from Chris Ellsworth in order to make SAS adapters work
63156000Smjacob * is gratefully acknowledged.
64159052Smjacob *
65159052Smjacob * Support from LSI-Logic has also gone a great deal toward making this a
66159052Smjacob * workable subsystem and is gratefully acknowledged.
67156000Smjacob */
68147883Sscottl/*
69147883Sscottl * Copyright (c) 2004, Avid Technology, Inc. and its contributors.
70147883Sscottl * Copyright (c) 2005, WHEEL Sp. z o.o.
71147883Sscottl * Copyright (c) 2004, 2005 Justin T. Gibbs
72147883Sscottl * All rights reserved.
73147883Sscottl *
74147883Sscottl * Redistribution and use in source and binary forms, with or without
75147883Sscottl * modification, are permitted provided that the following conditions are
76147883Sscottl * met:
77147883Sscottl * 1. Redistributions of source code must retain the above copyright
78147883Sscottl *    notice, this list of conditions and the following disclaimer.
79147883Sscottl * 2. Redistributions in binary form must reproduce at minimum a disclaimer
80147883Sscottl *    substantially similar to the "NO WARRANTY" disclaimer below
81147883Sscottl *    ("Disclaimer") and any redistribution must be conditioned upon including
82147883Sscottl *    a substantially similar Disclaimer requirement for further binary
83147883Sscottl *    redistribution.
84148679Sgibbs * 3. Neither the names of the above listed copyright holders nor the names
85148679Sgibbs *    of any contributors may be used to endorse or promote products derived
86148679Sgibbs *    from this software without specific prior written permission.
87147883Sscottl *
88147883Sscottl * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
89147883Sscottl * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
90147883Sscottl * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
91147883Sscottl * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
92147883Sscottl * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
93147883Sscottl * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
94147883Sscottl * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
95147883Sscottl * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
96147883Sscottl * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
97147883Sscottl * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF THE COPYRIGHT
98147883Sscottl * OWNER OR CONTRIBUTOR IS ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
99147883Sscottl */
100101704Smjacob
101119418Sobrien#include <sys/cdefs.h>
102119418Sobrien__FBSDID("$FreeBSD: head/sys/dev/mpt/mpt_pci.c 209961 2010-07-12 23:01:21Z marius $");
103119418Sobrien
104147883Sscottl#include <dev/mpt/mpt.h>
105147883Sscottl#include <dev/mpt/mpt_cam.h>
106147883Sscottl#include <dev/mpt/mpt_raid.h>
107102199Smjacob
108165814Smjacob#if __FreeBSD_version < 700000
109166721Sjhb#define	pci_msix_count(x)	0
110165814Smjacob#define	pci_msi_count(x)	0
111165814Smjacob#define	pci_alloc_msi(x, y)	1
112166721Sjhb#define	pci_alloc_msix(x, y)	1
113165814Smjacob#define	pci_release_msi(x)	do { ; } while (0)
114165814Smjacob#endif
115101704Smjacob
116101704Smjacob#ifndef	PCI_VENDOR_LSI
117101704Smjacob#define	PCI_VENDOR_LSI			0x1000
118101704Smjacob#endif
119101704Smjacob
120101704Smjacob#ifndef	PCI_PRODUCT_LSI_FC909
121101704Smjacob#define	PCI_PRODUCT_LSI_FC909		0x0620
122101704Smjacob#endif
123101704Smjacob
124102596Smjacob#ifndef	PCI_PRODUCT_LSI_FC909A
125102596Smjacob#define	PCI_PRODUCT_LSI_FC909A		0x0621
126102596Smjacob#endif
127102596Smjacob
128103829Smjacob#ifndef	PCI_PRODUCT_LSI_FC919
129103829Smjacob#define	PCI_PRODUCT_LSI_FC919		0x0624
130103829Smjacob#endif
131103829Smjacob
132101704Smjacob#ifndef	PCI_PRODUCT_LSI_FC929
133101704Smjacob#define	PCI_PRODUCT_LSI_FC929		0x0622
134101704Smjacob#endif
135101704Smjacob
136150007Smjacob#ifndef	PCI_PRODUCT_LSI_FC929X
137150007Smjacob#define	PCI_PRODUCT_LSI_FC929X		0x0626
138150007Smjacob#endif
139150007Smjacob
140159494Smjacob#ifndef	PCI_PRODUCT_LSI_FC919X
141159494Smjacob#define	PCI_PRODUCT_LSI_FC919X		0x0628
142159494Smjacob#endif
143159494Smjacob
144158279Smjacob#ifndef	PCI_PRODUCT_LSI_FC7X04X
145158279Smjacob#define	PCI_PRODUCT_LSI_FC7X04X		0x0640
146158279Smjacob#endif
147158279Smjacob
148162140Smjacob#ifndef	PCI_PRODUCT_LSI_FC646
149162140Smjacob#define	PCI_PRODUCT_LSI_FC646		0x0646
150162140Smjacob#endif
151162140Smjacob
152101704Smjacob#ifndef	PCI_PRODUCT_LSI_1030
153101704Smjacob#define	PCI_PRODUCT_LSI_1030		0x0030
154101704Smjacob#endif
155101704Smjacob
156155521Smjacob#ifndef	PCI_PRODUCT_LSI_SAS1064
157155521Smjacob#define PCI_PRODUCT_LSI_SAS1064		0x0050
158155521Smjacob#endif
159155521Smjacob
160155521Smjacob#ifndef PCI_PRODUCT_LSI_SAS1064A
161155521Smjacob#define PCI_PRODUCT_LSI_SAS1064A	0x005C
162155521Smjacob#endif
163155521Smjacob
164155521Smjacob#ifndef PCI_PRODUCT_LSI_SAS1064E
165155521Smjacob#define PCI_PRODUCT_LSI_SAS1064E	0x0056
166155521Smjacob#endif
167155521Smjacob
168155521Smjacob#ifndef PCI_PRODUCT_LSI_SAS1066
169155521Smjacob#define PCI_PRODUCT_LSI_SAS1066		0x005E
170155521Smjacob#endif
171155521Smjacob
172155521Smjacob#ifndef PCI_PRODUCT_LSI_SAS1066E
173155521Smjacob#define PCI_PRODUCT_LSI_SAS1066E	0x005A
174155521Smjacob#endif
175155521Smjacob
176155521Smjacob#ifndef PCI_PRODUCT_LSI_SAS1068
177155521Smjacob#define PCI_PRODUCT_LSI_SAS1068		0x0054
178155521Smjacob#endif
179155521Smjacob
180155521Smjacob#ifndef PCI_PRODUCT_LSI_SAS1068E
181155521Smjacob#define PCI_PRODUCT_LSI_SAS1068E	0x0058
182155521Smjacob#endif
183155521Smjacob
184155521Smjacob#ifndef PCI_PRODUCT_LSI_SAS1078
185172219Sambrisko#define PCI_PRODUCT_LSI_SAS1078		0x0062
186155521Smjacob#endif
187155521Smjacob
188178896Sdelphij#ifndef	PCI_PRODUCT_LSI_SAS1078DE
189178896Sdelphij#define	PCI_PRODUCT_LSI_SAS1078DE	0x007C
190178896Sdelphij#endif
191178896Sdelphij
192102303Smjacob#ifndef	PCIM_CMD_SERRESPEN
193102303Smjacob#define	PCIM_CMD_SERRESPEN	0x0100
194102303Smjacob#endif
195101704Smjacob
196101704Smjacob
197147883Sscottl#define	MPT_IO_BAR	0
198147883Sscottl#define	MPT_MEM_BAR	1
199101704Smjacob
200147883Sscottlstatic int mpt_pci_probe(device_t);
201147883Sscottlstatic int mpt_pci_attach(device_t);
202147883Sscottlstatic void mpt_free_bus_resources(struct mpt_softc *mpt);
203147883Sscottlstatic int mpt_pci_detach(device_t);
204147883Sscottlstatic int mpt_pci_shutdown(device_t);
205147883Sscottlstatic int mpt_dma_mem_alloc(struct mpt_softc *mpt);
206147883Sscottlstatic void mpt_dma_mem_free(struct mpt_softc *mpt);
207147883Sscottlstatic void mpt_read_config_regs(struct mpt_softc *mpt);
208102199Smjacobstatic void mpt_pci_intr(void *);
209101704Smjacob
210101704Smjacobstatic device_method_t mpt_methods[] = {
211101704Smjacob	/* Device interface */
212147883Sscottl	DEVMETHOD(device_probe,		mpt_pci_probe),
213147883Sscottl	DEVMETHOD(device_attach,	mpt_pci_attach),
214147883Sscottl	DEVMETHOD(device_detach,	mpt_pci_detach),
215147883Sscottl	DEVMETHOD(device_shutdown,	mpt_pci_shutdown),
216101704Smjacob	{ 0, 0 }
217101704Smjacob};
218101704Smjacob
219101704Smjacobstatic driver_t mpt_driver = {
220147883Sscottl	"mpt", mpt_methods, sizeof(struct mpt_softc)
221101704Smjacob};
222101704Smjacobstatic devclass_t mpt_devclass;
223101704SmjacobDRIVER_MODULE(mpt, pci, mpt_driver, mpt_devclass, 0, 0);
224165058SmjacobMODULE_DEPEND(mpt, pci, 1, 1, 1);
225101704SmjacobMODULE_VERSION(mpt, 1);
226101704Smjacob
227101704Smjacobstatic int
228147883Sscottlmpt_pci_probe(device_t dev)
229101704Smjacob{
230101704Smjacob	char *desc;
231101704Smjacob
232160290Smjacob	if (pci_get_vendor(dev) != PCI_VENDOR_LSI) {
233101704Smjacob		return (ENXIO);
234160290Smjacob	}
235101704Smjacob
236101704Smjacob	switch ((pci_get_device(dev) & ~1)) {
237101704Smjacob	case PCI_PRODUCT_LSI_FC909:
238101704Smjacob		desc = "LSILogic FC909 FC Adapter";
239101704Smjacob		break;
240102596Smjacob	case PCI_PRODUCT_LSI_FC909A:
241102596Smjacob		desc = "LSILogic FC909A FC Adapter";
242102596Smjacob		break;
243103829Smjacob	case PCI_PRODUCT_LSI_FC919:
244103829Smjacob		desc = "LSILogic FC919 FC Adapter";
245103829Smjacob		break;
246101704Smjacob	case PCI_PRODUCT_LSI_FC929:
247162140Smjacob		desc = "Dual LSILogic FC929 FC Adapter";
248101704Smjacob		break;
249159494Smjacob	case PCI_PRODUCT_LSI_FC919X:
250162140Smjacob		desc = "LSILogic FC919 FC PCI-X Adapter";
251159494Smjacob		break;
252150007Smjacob	case PCI_PRODUCT_LSI_FC929X:
253162140Smjacob		desc = "Dual LSILogic FC929X 2Gb/s FC PCI-X Adapter";
254150007Smjacob		break;
255162140Smjacob	case PCI_PRODUCT_LSI_FC646:
256162140Smjacob		desc = "Dual LSILogic FC7X04X 4Gb/s FC PCI-Express Adapter";
257162140Smjacob		break;
258158279Smjacob	case PCI_PRODUCT_LSI_FC7X04X:
259162140Smjacob		desc = "Dual LSILogic FC7X04X 4Gb/s FC PCI-X Adapter";
260158279Smjacob		break;
261101704Smjacob	case PCI_PRODUCT_LSI_1030:
262101704Smjacob		desc = "LSILogic 1030 Ultra4 Adapter";
263101704Smjacob		break;
264155521Smjacob	case PCI_PRODUCT_LSI_SAS1064:
265155521Smjacob	case PCI_PRODUCT_LSI_SAS1064A:
266155521Smjacob	case PCI_PRODUCT_LSI_SAS1064E:
267155521Smjacob	case PCI_PRODUCT_LSI_SAS1066:
268155521Smjacob	case PCI_PRODUCT_LSI_SAS1066E:
269155521Smjacob	case PCI_PRODUCT_LSI_SAS1068:
270155521Smjacob	case PCI_PRODUCT_LSI_SAS1068E:
271155521Smjacob	case PCI_PRODUCT_LSI_SAS1078:
272178896Sdelphij	case PCI_PRODUCT_LSI_SAS1078DE:
273162140Smjacob		desc = "LSILogic SAS/SATA Adapter";
274155521Smjacob		break;
275101704Smjacob	default:
276101704Smjacob		return (ENXIO);
277101704Smjacob	}
278101704Smjacob
279101704Smjacob	device_set_desc(dev, desc);
280147883Sscottl	return (0);
281101704Smjacob}
282101704Smjacob
283157117Smjacob#if	__FreeBSD_version < 500000
284101704Smjacobstatic void
285147883Sscottlmpt_set_options(struct mpt_softc *mpt)
286101704Smjacob{
287101704Smjacob	int bitmap;
288101704Smjacob
289101704Smjacob	bitmap = 0;
290101704Smjacob	if (getenv_int("mpt_disable", &bitmap)) {
291101704Smjacob		if (bitmap & (1 << mpt->unit)) {
292101704Smjacob			mpt->disabled = 1;
293101704Smjacob		}
294101704Smjacob	}
295101704Smjacob	bitmap = 0;
296101704Smjacob	if (getenv_int("mpt_debug", &bitmap)) {
297101704Smjacob		if (bitmap & (1 << mpt->unit)) {
298147883Sscottl			mpt->verbose = MPT_PRT_DEBUG;
299101704Smjacob		}
300101704Smjacob	}
301157117Smjacob	bitmap = 0;
302157662Smjacob	if (getenv_int("mpt_debug1", &bitmap)) {
303157117Smjacob		if (bitmap & (1 << mpt->unit)) {
304157662Smjacob			mpt->verbose = MPT_PRT_DEBUG1;
305157117Smjacob		}
306157117Smjacob	}
307157117Smjacob	bitmap = 0;
308157662Smjacob	if (getenv_int("mpt_debug2", &bitmap)) {
309157117Smjacob		if (bitmap & (1 << mpt->unit)) {
310157662Smjacob			mpt->verbose = MPT_PRT_DEBUG2;
311157117Smjacob		}
312157117Smjacob	}
313157117Smjacob	bitmap = 0;
314157662Smjacob	if (getenv_int("mpt_debug3", &bitmap)) {
315157117Smjacob		if (bitmap & (1 << mpt->unit)) {
316157662Smjacob			mpt->verbose = MPT_PRT_DEBUG3;
317157117Smjacob		}
318157117Smjacob	}
319160290Smjacob
320160290Smjacob	mpt->cfg_role = MPT_ROLE_DEFAULT;
321160290Smjacob	bitmap = 0;
322160290Smjacob	if (getenv_int("mpt_nil_role", &bitmap)) {
323160290Smjacob		if (bitmap & (1 << mpt->unit)) {
324160290Smjacob			mpt->cfg_role = 0;
325160290Smjacob		}
326160290Smjacob		mpt->do_cfg_role = 1;
327160290Smjacob	}
328160290Smjacob	bitmap = 0;
329160290Smjacob	if (getenv_int("mpt_tgt_role", &bitmap)) {
330160290Smjacob		if (bitmap & (1 << mpt->unit)) {
331160290Smjacob			mpt->cfg_role |= MPT_ROLE_TARGET;
332160290Smjacob		}
333160290Smjacob		mpt->do_cfg_role = 1;
334160290Smjacob	}
335160290Smjacob	bitmap = 0;
336160290Smjacob	if (getenv_int("mpt_ini_role", &bitmap)) {
337160290Smjacob		if (bitmap & (1 << mpt->unit)) {
338160290Smjacob			mpt->cfg_role |= MPT_ROLE_INITIATOR;
339160290Smjacob		}
340160290Smjacob		mpt->do_cfg_role = 1;
341160290Smjacob	}
342164416Smjacob	mpt->msi_enable = 0;
343101704Smjacob}
344101704Smjacob#else
345101704Smjacobstatic void
346147883Sscottlmpt_set_options(struct mpt_softc *mpt)
347101704Smjacob{
348101704Smjacob	int tval;
349101704Smjacob
350101704Smjacob	tval = 0;
351101704Smjacob	if (resource_int_value(device_get_name(mpt->dev),
352101704Smjacob	    device_get_unit(mpt->dev), "disable", &tval) == 0 && tval != 0) {
353101704Smjacob		mpt->disabled = 1;
354101704Smjacob	}
355101704Smjacob	tval = 0;
356101704Smjacob	if (resource_int_value(device_get_name(mpt->dev),
357101704Smjacob	    device_get_unit(mpt->dev), "debug", &tval) == 0 && tval != 0) {
358159041Smjacob		mpt->verbose = tval;
359101704Smjacob	}
360160290Smjacob	tval = -1;
361157117Smjacob	if (resource_int_value(device_get_name(mpt->dev),
362160290Smjacob	    device_get_unit(mpt->dev), "role", &tval) == 0 && tval >= 0 &&
363157117Smjacob	    tval <= 3) {
364160290Smjacob		mpt->cfg_role = tval;
365160290Smjacob		mpt->do_cfg_role = 1;
366157117Smjacob	}
367164416Smjacob
368164416Smjacob	tval = 0;
369164417Smjacob	mpt->msi_enable = 0;
370164416Smjacob	if (resource_int_value(device_get_name(mpt->dev),
371164416Smjacob	    device_get_unit(mpt->dev), "msi_enable", &tval) == 0 && tval == 1) {
372164416Smjacob		mpt->msi_enable = 1;
373164416Smjacob	}
374101704Smjacob}
375101704Smjacob#endif
376101704Smjacob
377101704Smjacob
378102303Smjacobstatic void
379147883Sscottlmpt_link_peer(struct mpt_softc *mpt)
380102303Smjacob{
381147883Sscottl	struct mpt_softc *mpt2;
382102303Smjacob
383157662Smjacob	if (mpt->unit == 0) {
384102303Smjacob		return;
385157662Smjacob	}
386102303Smjacob	/*
387102303Smjacob	 * XXX: depends on probe order
388102303Smjacob	 */
389147883Sscottl	mpt2 = (struct mpt_softc *)devclass_get_softc(mpt_devclass,mpt->unit-1);
390102303Smjacob
391102303Smjacob	if (mpt2 == NULL) {
392102303Smjacob		return;
393102303Smjacob	}
394102303Smjacob	if (pci_get_vendor(mpt2->dev) != pci_get_vendor(mpt->dev)) {
395102303Smjacob		return;
396102303Smjacob	}
397102303Smjacob	if (pci_get_device(mpt2->dev) != pci_get_device(mpt->dev)) {
398102303Smjacob		return;
399102303Smjacob	}
400102303Smjacob	mpt->mpt2 = mpt2;
401102303Smjacob	mpt2->mpt2 = mpt;
402147883Sscottl	if (mpt->verbose >= MPT_PRT_DEBUG) {
403147883Sscottl		mpt_prt(mpt, "linking with peer (mpt%d)\n",
404102303Smjacob		    device_get_unit(mpt2->dev));
405102303Smjacob	}
406102303Smjacob}
407102303Smjacob
408157662Smjacobstatic void
409157662Smjacobmpt_unlink_peer(struct mpt_softc *mpt)
410157662Smjacob{
411157662Smjacob	if (mpt->mpt2) {
412157662Smjacob		mpt->mpt2->mpt2 = NULL;
413157662Smjacob	}
414157662Smjacob}
415102303Smjacob
416157662Smjacob
417101704Smjacobstatic int
418147883Sscottlmpt_pci_attach(device_t dev)
419101704Smjacob{
420147883Sscottl	struct mpt_softc *mpt;
421147883Sscottl	int		  iqd;
422147883Sscottl	uint32_t	  data, cmd;
423101704Smjacob
424101704Smjacob	/* Allocate the softc structure */
425147883Sscottl	mpt  = (struct mpt_softc*)device_get_softc(dev);
426101704Smjacob	if (mpt == NULL) {
427101704Smjacob		device_printf(dev, "cannot allocate softc\n");
428101704Smjacob		return (ENOMEM);
429101704Smjacob	}
430157354Smjacob	memset(mpt, 0, sizeof(struct mpt_softc));
431101704Smjacob	switch ((pci_get_device(dev) & ~1)) {
432101704Smjacob	case PCI_PRODUCT_LSI_FC909:
433102596Smjacob	case PCI_PRODUCT_LSI_FC909A:
434103829Smjacob	case PCI_PRODUCT_LSI_FC919:
435101704Smjacob	case PCI_PRODUCT_LSI_FC929:
436159494Smjacob	case PCI_PRODUCT_LSI_FC919X:
437162140Smjacob	case PCI_PRODUCT_LSI_FC646:
438158279Smjacob	case PCI_PRODUCT_LSI_FC7X04X:
439101704Smjacob		mpt->is_fc = 1;
440101704Smjacob		break;
441155521Smjacob	case PCI_PRODUCT_LSI_SAS1064:
442155521Smjacob	case PCI_PRODUCT_LSI_SAS1064A:
443155521Smjacob	case PCI_PRODUCT_LSI_SAS1064E:
444155521Smjacob	case PCI_PRODUCT_LSI_SAS1066:
445155521Smjacob	case PCI_PRODUCT_LSI_SAS1066E:
446155521Smjacob	case PCI_PRODUCT_LSI_SAS1068:
447155521Smjacob	case PCI_PRODUCT_LSI_SAS1068E:
448155521Smjacob	case PCI_PRODUCT_LSI_SAS1078:
449178896Sdelphij	case PCI_PRODUCT_LSI_SAS1078DE:
450155521Smjacob		mpt->is_sas = 1;
451155521Smjacob		break;
452101704Smjacob	default:
453159178Smjacob		mpt->is_spi = 1;
454101704Smjacob		break;
455101704Smjacob	}
456101704Smjacob	mpt->dev = dev;
457101704Smjacob	mpt->unit = device_get_unit(dev);
458147883Sscottl	mpt->raid_resync_rate = MPT_RAID_RESYNC_RATE_DEFAULT;
459147883Sscottl	mpt->raid_mwce_setting = MPT_RAID_MWCE_DEFAULT;
460147883Sscottl	mpt->raid_queue_depth = MPT_RAID_QUEUE_DEPTH_DEFAULT;
461155521Smjacob	mpt->verbose = MPT_PRT_NONE;
462157662Smjacob	mpt->role = MPT_ROLE_NONE;
463207287Smarius	mpt->mpt_ini_id = MPT_INI_ID_NONE;
464207287Smarius#ifdef __sparc64__
465207287Smarius	if (mpt->is_spi)
466207287Smarius		mpt->mpt_ini_id = OF_getscsinitid(dev);
467207287Smarius#endif
468101704Smjacob	mpt_set_options(mpt);
469155521Smjacob	if (mpt->verbose == MPT_PRT_NONE) {
470155521Smjacob		mpt->verbose = MPT_PRT_WARN;
471155521Smjacob		/* Print INFO level (if any) if bootverbose is set */
472155521Smjacob		mpt->verbose += (bootverbose != 0)? 1 : 0;
473155521Smjacob	}
474101704Smjacob	/* Make sure memory access decoders are enabled */
475101704Smjacob	cmd = pci_read_config(dev, PCIR_COMMAND, 2);
476101704Smjacob	if ((cmd & PCIM_CMD_MEMEN) == 0) {
477101704Smjacob		device_printf(dev, "Memory accesses disabled");
478157662Smjacob		return (ENXIO);
479101704Smjacob	}
480101704Smjacob
481101704Smjacob	/*
482101704Smjacob	 * Make sure that SERR, PERR, WRITE INVALIDATE and BUSMASTER are set.
483101704Smjacob	 */
484101704Smjacob	cmd |=
485101704Smjacob	    PCIM_CMD_SERRESPEN | PCIM_CMD_PERRESPEN |
486101704Smjacob	    PCIM_CMD_BUSMASTEREN | PCIM_CMD_MWRICEN;
487101704Smjacob	pci_write_config(dev, PCIR_COMMAND, cmd, 2);
488101704Smjacob
489101704Smjacob	/*
490101704Smjacob	 * Make sure we've disabled the ROM.
491101704Smjacob	 */
492101704Smjacob	data = pci_read_config(dev, PCIR_BIOS, 4);
493201275Sjhb	data &= ~PCIM_BIOS_ENABLE;
494101704Smjacob	pci_write_config(dev, PCIR_BIOS, data, 4);
495101704Smjacob
496102303Smjacob	/*
497102303Smjacob	 * Is this part a dual?
498102303Smjacob	 * If so, link with our partner (around yet)
499102303Smjacob	 */
500102303Smjacob	if ((pci_get_device(dev) & ~1) == PCI_PRODUCT_LSI_FC929 ||
501162140Smjacob	    (pci_get_device(dev) & ~1) == PCI_PRODUCT_LSI_FC646 ||
502158279Smjacob	    (pci_get_device(dev) & ~1) == PCI_PRODUCT_LSI_FC7X04X ||
503102303Smjacob	    (pci_get_device(dev) & ~1) == PCI_PRODUCT_LSI_1030) {
504102303Smjacob		mpt_link_peer(mpt);
505101704Smjacob	}
506101704Smjacob
507147883Sscottl	/*
508147883Sscottl	 * Set up register access.  PIO mode is required for
509155521Smjacob	 * certain reset operations (but must be disabled for
510155521Smjacob	 * some cards otherwise).
511147883Sscottl	 */
512147883Sscottl	mpt->pci_pio_rid = PCIR_BAR(MPT_IO_BAR);
513147883Sscottl	mpt->pci_pio_reg = bus_alloc_resource(dev, SYS_RES_IOPORT,
514147883Sscottl			    &mpt->pci_pio_rid, 0, ~0, 0, RF_ACTIVE);
515147883Sscottl	if (mpt->pci_pio_reg == NULL) {
516147883Sscottl		device_printf(dev, "unable to map registers in PIO mode\n");
517147883Sscottl		goto bad;
518147883Sscottl	}
519147883Sscottl	mpt->pci_pio_st = rman_get_bustag(mpt->pci_pio_reg);
520147883Sscottl	mpt->pci_pio_sh = rman_get_bushandle(mpt->pci_pio_reg);
521147883Sscottl
522101704Smjacob	/* Allocate kernel virtual memory for the 9x9's Mem0 region */
523147883Sscottl	mpt->pci_mem_rid = PCIR_BAR(MPT_MEM_BAR);
524101704Smjacob	mpt->pci_reg = bus_alloc_resource(dev, SYS_RES_MEMORY,
525147883Sscottl			&mpt->pci_mem_rid, 0, ~0, 0, RF_ACTIVE);
526101704Smjacob	if (mpt->pci_reg == NULL) {
527147883Sscottl		device_printf(dev, "Unable to memory map registers.\n");
528155521Smjacob		if (mpt->is_sas) {
529155521Smjacob			device_printf(dev, "Giving Up.\n");
530155521Smjacob			goto bad;
531155521Smjacob		}
532147883Sscottl		device_printf(dev, "Falling back to PIO mode.\n");
533147883Sscottl		mpt->pci_st = mpt->pci_pio_st;
534147883Sscottl		mpt->pci_sh = mpt->pci_pio_sh;
535147883Sscottl	} else {
536147883Sscottl		mpt->pci_st = rman_get_bustag(mpt->pci_reg);
537147883Sscottl		mpt->pci_sh = rman_get_bushandle(mpt->pci_reg);
538101704Smjacob	}
539101704Smjacob
540101704Smjacob	/* Get a handle to the interrupt */
541101704Smjacob	iqd = 0;
542166721Sjhb	if (mpt->msi_enable) {
543166721Sjhb		/*
544166721Sjhb		 * First try to alloc an MSI-X message.  If that
545166721Sjhb		 * fails, then try to alloc an MSI message instead.
546166721Sjhb		 */
547166721Sjhb		if (pci_msix_count(dev) == 1) {
548166721Sjhb			mpt->pci_msi_count = 1;
549166721Sjhb			if (pci_alloc_msix(dev, &mpt->pci_msi_count) == 0) {
550166721Sjhb				iqd = 1;
551166721Sjhb			} else {
552166721Sjhb				mpt->pci_msi_count = 0;
553166721Sjhb			}
554164416Smjacob		}
555166721Sjhb		if (iqd == 0 && pci_msi_count(dev) == 1) {
556166721Sjhb			mpt->pci_msi_count = 1;
557166721Sjhb			if (pci_alloc_msi(dev, &mpt->pci_msi_count) == 0) {
558166721Sjhb				iqd = 1;
559166721Sjhb			} else {
560166721Sjhb				mpt->pci_msi_count = 0;
561166721Sjhb			}
562166721Sjhb		}
563166721Sjhb	}
564127135Snjl	mpt->pci_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &iqd,
565127135Snjl	    RF_ACTIVE | RF_SHAREABLE);
566101704Smjacob	if (mpt->pci_irq == NULL) {
567101704Smjacob		device_printf(dev, "could not allocate interrupt\n");
568101704Smjacob		goto bad;
569101704Smjacob	}
570101704Smjacob
571147883Sscottl	MPT_LOCK_SETUP(mpt);
572147883Sscottl
573147883Sscottl	/* Disable interrupts at the part */
574147883Sscottl	mpt_disable_ints(mpt);
575147883Sscottl
576101704Smjacob	/* Register the interrupt handler */
577166935Smjacob	if (mpt_setup_intr(dev, mpt->pci_irq, MPT_IFLAGS, NULL, mpt_pci_intr,
578101704Smjacob	    mpt, &mpt->ih)) {
579101704Smjacob		device_printf(dev, "could not setup interrupt\n");
580101704Smjacob		goto bad;
581101704Smjacob	}
582101704Smjacob
583101704Smjacob	/* Allocate dma memory */
584147883Sscottl/* XXX JGibbs -Should really be done based on IOCFacts. */
585101704Smjacob	if (mpt_dma_mem_alloc(mpt)) {
586159091Smjacob		mpt_prt(mpt, "Could not allocate DMA memory\n");
587101704Smjacob		goto bad;
588101704Smjacob	}
589101704Smjacob
590102199Smjacob	/*
591102199Smjacob	 * Save the PCI config register values
592102199Smjacob 	 *
593102199Smjacob	 * Hard resets are known to screw up the BAR for diagnostic
594102199Smjacob	 * memory accesses (Mem1).
595102199Smjacob	 *
596102199Smjacob	 * Using Mem1 is known to make the chip stop responding to
597102199Smjacob	 * configuration space transfers, so we need to save it now
598102199Smjacob	 */
599101704Smjacob
600101704Smjacob	mpt_read_config_regs(mpt);
601101704Smjacob
602155521Smjacob	/*
603155521Smjacob	 * Disable PIO until we need it
604155521Smjacob	 */
605159919Smjacob	if (mpt->is_sas) {
606159919Smjacob		pci_disable_io(dev, SYS_RES_IOPORT);
607159919Smjacob	}
608155521Smjacob
609101704Smjacob	/* Initialize the hardware */
610101704Smjacob	if (mpt->disabled == 0) {
611147883Sscottl		if (mpt_attach(mpt) != 0) {
612101704Smjacob			goto bad;
613102199Smjacob		}
614157117Smjacob	} else {
615157117Smjacob		mpt_prt(mpt, "device disabled at user request\n");
616157117Smjacob		goto bad;
617101704Smjacob	}
618101704Smjacob
619157117Smjacob	mpt->eh = EVENTHANDLER_REGISTER(shutdown_post_sync, mpt_pci_shutdown,
620157117Smjacob	    dev, SHUTDOWN_PRI_DEFAULT);
621157117Smjacob
622157117Smjacob	if (mpt->eh == NULL) {
623157117Smjacob		mpt_prt(mpt, "shutdown event registration failed\n");
624157117Smjacob		(void) mpt_detach(mpt);
625157117Smjacob		goto bad;
626157117Smjacob	}
627101704Smjacob	return (0);
628101704Smjacob
629101704Smjacobbad:
630101704Smjacob	mpt_dma_mem_free(mpt);
631101704Smjacob	mpt_free_bus_resources(mpt);
632157662Smjacob	mpt_unlink_peer(mpt);
633101704Smjacob
634157662Smjacob	MPT_LOCK_DESTROY(mpt);
635157662Smjacob
636101704Smjacob	/*
637101704Smjacob	 * but return zero to preserve unit numbering
638101704Smjacob	 */
639101704Smjacob	return (0);
640101704Smjacob}
641101704Smjacob
642102199Smjacob/*
643101704Smjacob * Free bus resources
644101704Smjacob */
645101704Smjacobstatic void
646147883Sscottlmpt_free_bus_resources(struct mpt_softc *mpt)
647101704Smjacob{
648101704Smjacob	if (mpt->ih) {
649101704Smjacob		bus_teardown_intr(mpt->dev, mpt->pci_irq, mpt->ih);
650101704Smjacob		mpt->ih = 0;
651101704Smjacob	}
652101704Smjacob
653101704Smjacob	if (mpt->pci_irq) {
654164305Sjhb		bus_release_resource(mpt->dev, SYS_RES_IRQ,
655164305Sjhb		    mpt->pci_msi_count ? 1 : 0, mpt->pci_irq);
656101704Smjacob		mpt->pci_irq = 0;
657101704Smjacob	}
658101704Smjacob
659164305Sjhb	if (mpt->pci_msi_count) {
660164305Sjhb		pci_release_msi(mpt->dev);
661164305Sjhb		mpt->pci_msi_count = 0;
662164305Sjhb	}
663164305Sjhb
664147883Sscottl	if (mpt->pci_pio_reg) {
665147883Sscottl		bus_release_resource(mpt->dev, SYS_RES_IOPORT, mpt->pci_pio_rid,
666147883Sscottl			mpt->pci_pio_reg);
667147883Sscottl		mpt->pci_pio_reg = 0;
668147883Sscottl	}
669101704Smjacob	if (mpt->pci_reg) {
670147883Sscottl		bus_release_resource(mpt->dev, SYS_RES_MEMORY, mpt->pci_mem_rid,
671101704Smjacob			mpt->pci_reg);
672101704Smjacob		mpt->pci_reg = 0;
673101704Smjacob	}
674102199Smjacob	MPT_LOCK_DESTROY(mpt);
675101704Smjacob}
676101704Smjacob
677101704Smjacob
678102199Smjacob/*
679101704Smjacob * Disconnect ourselves from the system.
680101704Smjacob */
681101704Smjacobstatic int
682147883Sscottlmpt_pci_detach(device_t dev)
683101704Smjacob{
684147883Sscottl	struct mpt_softc *mpt;
685101704Smjacob
686147883Sscottl	mpt  = (struct mpt_softc*)device_get_softc(dev);
687101704Smjacob
688101704Smjacob	if (mpt) {
689101704Smjacob		mpt_disable_ints(mpt);
690147883Sscottl		mpt_detach(mpt);
691147883Sscottl		mpt_reset(mpt, /*reinit*/FALSE);
692101704Smjacob		mpt_dma_mem_free(mpt);
693101704Smjacob		mpt_free_bus_resources(mpt);
694158982Smjacob		mpt_raid_free_mem(mpt);
695158982Smjacob		if (mpt->eh != NULL) {
696180152Sjhb                        EVENTHANDLER_DEREGISTER(shutdown_post_sync, mpt->eh);
697147883Sscottl		}
698101704Smjacob	}
699101704Smjacob	return(0);
700101704Smjacob}
701101704Smjacob
702101704Smjacob
703102199Smjacob/*
704101704Smjacob * Disable the hardware
705101704Smjacob */
706101704Smjacobstatic int
707147883Sscottlmpt_pci_shutdown(device_t dev)
708101704Smjacob{
709147883Sscottl	struct mpt_softc *mpt;
710101704Smjacob
711147883Sscottl	mpt = (struct mpt_softc *)device_get_softc(dev);
712157117Smjacob	if (mpt) {
713157117Smjacob		int r;
714157117Smjacob		r = mpt_shutdown(mpt);
715157117Smjacob		return (r);
716157117Smjacob	}
717101704Smjacob	return(0);
718101704Smjacob}
719101704Smjacob
720101704Smjacobstatic int
721147883Sscottlmpt_dma_mem_alloc(struct mpt_softc *mpt)
722101704Smjacob{
723103871Smjacob	size_t len;
724147883Sscottl	struct mpt_map_info mi;
725101704Smjacob
726101704Smjacob	/* Check if we alreay have allocated the reply memory */
727123740Speter	if (mpt->reply_phys != 0) {
728101704Smjacob		return 0;
729103871Smjacob	}
730101704Smjacob
731147883Sscottl	len = sizeof (request_t) * MPT_MAX_REQUESTS(mpt);
732103871Smjacob#ifdef	RELENG_4
733147883Sscottl	mpt->request_pool = (request_t *)malloc(len, M_DEVBUF, M_WAITOK);
734103871Smjacob	if (mpt->request_pool == NULL) {
735159091Smjacob		mpt_prt(mpt, "cannot allocate request pool\n");
736103871Smjacob		return (1);
737103871Smjacob	}
738157354Smjacob	memset(mpt->request_pool, 0, len);
739103871Smjacob#else
740147883Sscottl	mpt->request_pool = (request_t *)malloc(len, M_DEVBUF, M_WAITOK|M_ZERO);
741103871Smjacob	if (mpt->request_pool == NULL) {
742159091Smjacob		mpt_prt(mpt, "cannot allocate request pool\n");
743103871Smjacob		return (1);
744103871Smjacob	}
745103871Smjacob#endif
746103871Smjacob
747101704Smjacob	/*
748155521Smjacob	 * Create a parent dma tag for this device.
749101704Smjacob	 *
750159091Smjacob	 * Align at byte boundaries,
751159091Smjacob	 * Limit to 32-bit addressing for request/reply queues.
752101704Smjacob	 */
753164314Sjb	if (mpt_dma_tag_create(mpt, /*parent*/bus_get_dma_tag(mpt->dev),
754164314Sjb	    /*alignment*/1, /*boundary*/0, /*lowaddr*/BUS_SPACE_MAXADDR,
755147883Sscottl	    /*highaddr*/BUS_SPACE_MAXADDR, /*filter*/NULL, /*filterarg*/NULL,
756147883Sscottl	    /*maxsize*/BUS_SPACE_MAXSIZE_32BIT,
757209961Smarius	    /*nsegments*/BUS_SPACE_UNRESTRICTED,
758209961Smarius	    /*maxsegsz*/BUS_SPACE_MAXSIZE_32BIT, /*flags*/0,
759147883Sscottl	    &mpt->parent_dmat) != 0) {
760159091Smjacob		mpt_prt(mpt, "cannot create parent dma tag\n");
761101704Smjacob		return (1);
762101704Smjacob	}
763101704Smjacob
764101704Smjacob	/* Create a child tag for reply buffers */
765159091Smjacob	if (mpt_dma_tag_create(mpt, mpt->parent_dmat, PAGE_SIZE, 0,
766159091Smjacob	    BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR,
767155521Smjacob	    NULL, NULL, 2 * PAGE_SIZE, 1, BUS_SPACE_MAXSIZE_32BIT, 0,
768147883Sscottl	    &mpt->reply_dmat) != 0) {
769159091Smjacob		mpt_prt(mpt, "cannot create a dma tag for replies\n");
770101704Smjacob		return (1);
771101704Smjacob	}
772101704Smjacob
773101704Smjacob	/* Allocate some DMA accessable memory for replies */
774101704Smjacob	if (bus_dmamem_alloc(mpt->reply_dmat, (void **)&mpt->reply,
775101704Smjacob	    BUS_DMA_NOWAIT, &mpt->reply_dmap) != 0) {
776159091Smjacob		mpt_prt(mpt, "cannot allocate %lu bytes of reply memory\n",
777155521Smjacob		    (u_long) (2 * PAGE_SIZE));
778101704Smjacob		return (1);
779101704Smjacob	}
780101704Smjacob
781147883Sscottl	mi.mpt = mpt;
782147883Sscottl	mi.error = 0;
783101704Smjacob
784101704Smjacob	/* Load and lock it into "bus space" */
785101704Smjacob	bus_dmamap_load(mpt->reply_dmat, mpt->reply_dmap, mpt->reply,
786155521Smjacob	    2 * PAGE_SIZE, mpt_map_rquest, &mi, 0);
787101704Smjacob
788147883Sscottl	if (mi.error) {
789159091Smjacob		mpt_prt(mpt, "error %d loading dma map for DMA reply queue\n",
790159091Smjacob		    mi.error);
791101704Smjacob		return (1);
792101704Smjacob	}
793147883Sscottl	mpt->reply_phys = mi.phys;
794101704Smjacob
795101704Smjacob	return (0);
796101704Smjacob}
797101704Smjacob
798101704Smjacob
799101704Smjacob
800101704Smjacob/* Deallocate memory that was allocated by mpt_dma_mem_alloc
801101704Smjacob */
802101704Smjacobstatic void
803147883Sscottlmpt_dma_mem_free(struct mpt_softc *mpt)
804101704Smjacob{
805101704Smjacob
806101704Smjacob        /* Make sure we aren't double destroying */
807101704Smjacob        if (mpt->reply_dmat == 0) {
808159091Smjacob		mpt_lprt(mpt, MPT_PRT_DEBUG, "already released dma memory\n");
809101704Smjacob		return;
810101704Smjacob        }
811101704Smjacob
812101704Smjacob	bus_dmamap_unload(mpt->reply_dmat, mpt->reply_dmap);
813101704Smjacob	bus_dmamem_free(mpt->reply_dmat, mpt->reply, mpt->reply_dmap);
814101704Smjacob	bus_dma_tag_destroy(mpt->reply_dmat);
815101704Smjacob	bus_dma_tag_destroy(mpt->parent_dmat);
816101704Smjacob	mpt->reply_dmat = 0;
817103871Smjacob	free(mpt->request_pool, M_DEVBUF);
818103871Smjacob	mpt->request_pool = 0;
819101704Smjacob
820101704Smjacob}
821101704Smjacob
822101704Smjacob
823101704Smjacob
824101704Smjacob/* Reads modifiable (via PCI transactions) config registers */
825101704Smjacobstatic void
826147883Sscottlmpt_read_config_regs(struct mpt_softc *mpt)
827101704Smjacob{
828101704Smjacob	mpt->pci_cfg.Command = pci_read_config(mpt->dev, PCIR_COMMAND, 2);
829101704Smjacob	mpt->pci_cfg.LatencyTimer_LineSize =
830101704Smjacob	    pci_read_config(mpt->dev, PCIR_CACHELNSZ, 2);
831119690Sjhb	mpt->pci_cfg.IO_BAR = pci_read_config(mpt->dev, PCIR_BAR(0), 4);
832119690Sjhb	mpt->pci_cfg.Mem0_BAR[0] = pci_read_config(mpt->dev, PCIR_BAR(1), 4);
833119690Sjhb	mpt->pci_cfg.Mem0_BAR[1] = pci_read_config(mpt->dev, PCIR_BAR(2), 4);
834119690Sjhb	mpt->pci_cfg.Mem1_BAR[0] = pci_read_config(mpt->dev, PCIR_BAR(3), 4);
835119690Sjhb	mpt->pci_cfg.Mem1_BAR[1] = pci_read_config(mpt->dev, PCIR_BAR(4), 4);
836101704Smjacob	mpt->pci_cfg.ROM_BAR = pci_read_config(mpt->dev, PCIR_BIOS, 4);
837101704Smjacob	mpt->pci_cfg.IntLine = pci_read_config(mpt->dev, PCIR_INTLINE, 1);
838101704Smjacob	mpt->pci_cfg.PMCSR = pci_read_config(mpt->dev, 0x44, 4);
839101704Smjacob}
840101704Smjacob
841101704Smjacob/* Sets modifiable config registers */
842101704Smjacobvoid
843147883Sscottlmpt_set_config_regs(struct mpt_softc *mpt)
844101704Smjacob{
845147883Sscottl	uint32_t val;
846101704Smjacob
847101704Smjacob#define MPT_CHECK(reg, offset, size)					\
848101704Smjacob	val = pci_read_config(mpt->dev, offset, size);			\
849101704Smjacob	if (mpt->pci_cfg.reg != val) {					\
850103914Smjacob		mpt_prt(mpt,						\
851101704Smjacob		    "Restoring " #reg " to 0x%X from 0x%X\n",		\
852101704Smjacob		    mpt->pci_cfg.reg, val);				\
853101704Smjacob	}
854101704Smjacob
855147883Sscottl	if (mpt->verbose >= MPT_PRT_DEBUG) {
856101704Smjacob		MPT_CHECK(Command, PCIR_COMMAND, 2);
857101704Smjacob		MPT_CHECK(LatencyTimer_LineSize, PCIR_CACHELNSZ, 2);
858119690Sjhb		MPT_CHECK(IO_BAR, PCIR_BAR(0), 4);
859119690Sjhb		MPT_CHECK(Mem0_BAR[0], PCIR_BAR(1), 4);
860119690Sjhb		MPT_CHECK(Mem0_BAR[1], PCIR_BAR(2), 4);
861119690Sjhb		MPT_CHECK(Mem1_BAR[0], PCIR_BAR(3), 4);
862119690Sjhb		MPT_CHECK(Mem1_BAR[1], PCIR_BAR(4), 4);
863101704Smjacob		MPT_CHECK(ROM_BAR, PCIR_BIOS, 4);
864101704Smjacob		MPT_CHECK(IntLine, PCIR_INTLINE, 1);
865101704Smjacob		MPT_CHECK(PMCSR, 0x44, 4);
866101704Smjacob	}
867101704Smjacob#undef MPT_CHECK
868101704Smjacob
869101704Smjacob	pci_write_config(mpt->dev, PCIR_COMMAND, mpt->pci_cfg.Command, 2);
870101704Smjacob	pci_write_config(mpt->dev, PCIR_CACHELNSZ,
871101704Smjacob	    mpt->pci_cfg.LatencyTimer_LineSize, 2);
872119690Sjhb	pci_write_config(mpt->dev, PCIR_BAR(0), mpt->pci_cfg.IO_BAR, 4);
873119690Sjhb	pci_write_config(mpt->dev, PCIR_BAR(1), mpt->pci_cfg.Mem0_BAR[0], 4);
874119690Sjhb	pci_write_config(mpt->dev, PCIR_BAR(2), mpt->pci_cfg.Mem0_BAR[1], 4);
875119690Sjhb	pci_write_config(mpt->dev, PCIR_BAR(3), mpt->pci_cfg.Mem1_BAR[0], 4);
876119690Sjhb	pci_write_config(mpt->dev, PCIR_BAR(4), mpt->pci_cfg.Mem1_BAR[1], 4);
877101704Smjacob	pci_write_config(mpt->dev, PCIR_BIOS, mpt->pci_cfg.ROM_BAR, 4);
878101704Smjacob	pci_write_config(mpt->dev, PCIR_INTLINE, mpt->pci_cfg.IntLine, 1);
879101704Smjacob	pci_write_config(mpt->dev, 0x44, mpt->pci_cfg.PMCSR, 4);
880101704Smjacob}
881102199Smjacob
882102199Smjacobstatic void
883102199Smjacobmpt_pci_intr(void *arg)
884102199Smjacob{
885147883Sscottl	struct mpt_softc *mpt;
886147883Sscottl
887147883Sscottl	mpt = (struct mpt_softc *)arg;
888102199Smjacob	MPT_LOCK(mpt);
889147883Sscottl	mpt_intr(mpt);
890102199Smjacob	MPT_UNLOCK(mpt);
891102199Smjacob}
892