xref: /dragonfly/sys/dev/disk/mpt/mpt_pci.c (revision 6b5c5d0d)
1 /* $FreeBSD: src/sys/dev/mpt/mpt_pci.c,v 1.3.2.3 2002/09/24 21:37:25 mjacob Exp $ */
2 /* $DragonFly: src/sys/dev/disk/mpt/mpt_pci.c,v 1.11 2008/01/06 16:55:49 swildner Exp $ */
3 /*
4  * PCI specific probe and attach routines for LSI '909 FC  adapters.
5  * FreeBSD Version.
6  *
7  * Copyright (c)  2000, 2001 by Greg Ansley
8  * Partially derived from Matt Jacob's ISP driver.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice immediately at the beginning of the file, without modification,
15  *    this list of conditions, and the following disclaimer.
16  * 2. The name of the author may not be used to endorse or promote products
17  *    derived from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
23  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29  * SUCH DAMAGE.
30  */
31 /*
32  * Additional Copyright (c) 2002 by Matthew Jacob under same license.
33  */
34 
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/kernel.h>
38 #include <sys/module.h>
39 #include <sys/bus.h>
40 #include <sys/rman.h>
41 #include <sys/malloc.h>
42 
43 #include <bus/pci/pcidevs.h>
44 #include <bus/pci/pcireg.h>
45 #include <bus/pci/pcivar.h>
46 
47 #include "mpt_freebsd.h"
48 
49 #ifndef	PCIM_CMD_SERRESPEN
50 #define	PCIM_CMD_SERRESPEN	0x0100
51 #endif
52 
53 
54 
55 #define	MEM_MAP_REG	0x14
56 #define	MEM_MAP_SRAM	0x1C
57 
58 static int mpt_probe(device_t);
59 static int mpt_attach(device_t);
60 static void mpt_free_bus_resources(mpt_softc_t *mpt);
61 static int mpt_detach(device_t);
62 static int mpt_shutdown(device_t);
63 static int mpt_dma_mem_alloc(mpt_softc_t *mpt);
64 static void mpt_dma_mem_free(mpt_softc_t *mpt);
65 static void mpt_read_config_regs(mpt_softc_t *mpt);
66 static void mpt_pci_intr(void *);
67 
68 static device_method_t mpt_methods[] = {
69 	/* Device interface */
70 	DEVMETHOD(device_probe,		mpt_probe),
71 	DEVMETHOD(device_attach,	mpt_attach),
72 	DEVMETHOD(device_detach,	mpt_detach),
73 	DEVMETHOD(device_shutdown,	mpt_shutdown),
74 	{ 0, 0 }
75 };
76 
77 static driver_t mpt_driver = {
78 	"mpt", mpt_methods, sizeof (mpt_softc_t)
79 };
80 static devclass_t mpt_devclass;
81 DRIVER_MODULE(mpt, pci, mpt_driver, mpt_devclass, 0, 0);
82 MODULE_VERSION(mpt, 1);
83 
84 int
85 mpt_intr(void *dummy)
86 {
87 	int nrepl = 0;
88 	u_int32_t reply;
89 	mpt_softc_t *mpt = (mpt_softc_t *)dummy;
90 
91 	if ((mpt_read(mpt, MPT_OFFSET_INTR_STATUS) & MPT_INTR_REPLY_READY) == 0)
92 		return (0);
93 	reply = mpt_pop_reply_queue(mpt);
94 	while (reply != MPT_REPLY_EMPTY) {
95 		nrepl++;
96 		if (mpt->verbose > 1) {
97 			if ((reply & MPT_CONTEXT_REPLY) != 0)  {
98 				/* Address reply; IOC has something to say */
99 				mpt_print_reply(MPT_REPLY_PTOV(mpt, reply));
100 			} else {
101 				/* Context reply ; all went well */
102 				device_printf(mpt->dev,
103 				    "context %u reply OK\n", reply);
104 			}
105 		}
106 		mpt_done(mpt, reply);
107 		reply = mpt_pop_reply_queue(mpt);
108 	}
109 	return (nrepl != 0);
110 }
111 
112 static int
113 mpt_probe(device_t dev)
114 {
115 	char *desc;
116 
117 	if (pci_get_vendor(dev) != PCI_VENDOR_SYMBIOS)
118 		return (ENXIO);
119 
120 	switch ((pci_get_device(dev) & ~1)) {
121 	case PCI_PRODUCT_SYMBIOS_FC909:
122 		desc = "LSILogic FC909 FC Adapter";
123 		break;
124 	case PCI_PRODUCT_SYMBIOS_FC909A:
125 		desc = "LSILogic FC909A FC Adapter";
126 		break;
127 	case PCI_PRODUCT_SYMBIOS_FC919:
128 		desc = "LSILogic FC919 FC Adapter";
129 		break;
130 	case PCI_PRODUCT_SYMBIOS_FC929:
131 		desc = "LSILogic FC929 FC Adapter";
132 		break;
133 	case PCI_PRODUCT_SYMBIOS_1030:
134 		desc = "LSILogic 1030 Ultra4 Adapter";
135 		break;
136 	default:
137 		return (ENXIO);
138 	}
139 
140 	device_set_desc(dev, desc);
141 	return (0);
142 }
143 
144 static void
145 mpt_set_options(mpt_softc_t *mpt)
146 {
147 	int bitmap;
148 
149 	bitmap = 0;
150 	if (kgetenv_int("mpt_disable", &bitmap)) {
151 		if (bitmap & (1 << mpt->unit)) {
152 			mpt->disabled = 1;
153 		}
154 	}
155 
156 	bitmap = 0;
157 	if (kgetenv_int("mpt_debug", &bitmap)) {
158 		if (bitmap & (1 << mpt->unit)) {
159 			mpt->verbose = 2;
160 		}
161 	}
162 
163 }
164 
165 static void
166 mpt_link_peer(mpt_softc_t *mpt)
167 {
168 	mpt_softc_t *mpt2;
169 
170 	if (mpt->unit == 0) {
171 		return;
172 	}
173 
174 	/*
175 	 * XXX: depends on probe order
176 	 */
177 	mpt2 = (mpt_softc_t *) devclass_get_softc(mpt_devclass, mpt->unit-1);
178 
179 	if (mpt2 == NULL) {
180 		return;
181 	}
182 	if (pci_get_vendor(mpt2->dev) != pci_get_vendor(mpt->dev)) {
183 		return;
184 	}
185 	if (pci_get_device(mpt2->dev) != pci_get_device(mpt->dev)) {
186 		return;
187 	}
188 	mpt->mpt2 = mpt2;
189 	mpt2->mpt2 = mpt;
190 	if (mpt->verbose) {
191 		device_printf(mpt->dev, "linking with peer (mpt%d)\n",
192 		    device_get_unit(mpt2->dev));
193 	}
194 }
195 
196 
197 static int
198 mpt_attach(device_t dev)
199 {
200 	int iqd;
201 	u_int32_t data, cmd;
202 	mpt_softc_t *mpt;
203 
204 	/* Allocate the softc structure */
205 	mpt  = (mpt_softc_t*) device_get_softc(dev);
206 	if (mpt == NULL) {
207 		device_printf(dev, "cannot allocate softc\n");
208 		return (ENOMEM);
209 	}
210 	bzero(mpt, sizeof (mpt_softc_t));
211 	switch ((pci_get_device(dev) & ~1)) {
212 	case PCI_PRODUCT_SYMBIOS_FC909:
213 	case PCI_PRODUCT_SYMBIOS_FC909A:
214 	case PCI_PRODUCT_SYMBIOS_FC919:
215 	case PCI_PRODUCT_SYMBIOS_FC929:
216 		mpt->is_fc = 1;
217 		break;
218 	default:
219 		break;
220 	}
221 	mpt->dev = dev;
222 	mpt->unit = device_get_unit(dev);
223 	mpt_set_options(mpt);
224 	mpt->verbose += (bootverbose != 0)? 1 : 0;
225 
226 	/* Make sure memory access decoders are enabled */
227 	cmd = pci_read_config(dev, PCIR_COMMAND, 2);
228 	if ((cmd & PCIM_CMD_MEMEN) == 0) {
229 		device_printf(dev, "Memory accesses disabled");
230 		goto bad;
231 	}
232 
233 	/*
234 	 * Make sure that SERR, PERR, WRITE INVALIDATE and BUSMASTER are set.
235 	 */
236 	cmd |=
237 	    PCIM_CMD_SERRESPEN | PCIM_CMD_PERRESPEN |
238 	    PCIM_CMD_BUSMASTEREN | PCIM_CMD_MWRICEN;
239 	pci_write_config(dev, PCIR_COMMAND, cmd, 2);
240 
241 	/*
242 	 * Make sure we've disabled the ROM.
243 	 */
244 	data = pci_read_config(dev, PCIR_BIOS, 4);
245 	data &= ~1;
246 	pci_write_config(dev, PCIR_BIOS, data, 4);
247 
248 
249 	/*
250 	 * Is this part a dual?
251 	 * If so, link with our partner (around yet)
252 	 */
253 	if ((pci_get_device(dev) & ~1) == PCI_PRODUCT_SYMBIOS_FC929 ||
254 	    (pci_get_device(dev) & ~1) == PCI_PRODUCT_SYMBIOS_1030) {
255 		mpt_link_peer(mpt);
256 	}
257 
258 	/* Set up the memory regions */
259 	/* Allocate kernel virtual memory for the 9x9's Mem0 region */
260 	mpt->pci_reg_id = MEM_MAP_REG;
261 	mpt->pci_reg = bus_alloc_resource(dev, SYS_RES_MEMORY,
262 			&mpt->pci_reg_id, 0, ~0, 0, RF_ACTIVE);
263 	if (mpt->pci_reg == NULL) {
264 		device_printf(dev, "unable to map any ports\n");
265 		goto bad;
266 	}
267 	mpt->pci_st = rman_get_bustag(mpt->pci_reg);
268 	mpt->pci_sh = rman_get_bushandle(mpt->pci_reg);
269 	/*   Get the Physical Address */
270 	mpt->pci_pa = rman_get_start(mpt->pci_reg);
271 
272 	/* Get a handle to the interrupt */
273 	iqd = 0;
274 	mpt->pci_irq = bus_alloc_resource(dev, SYS_RES_IRQ, &iqd, 0, ~0,
275 	    1, RF_ACTIVE | RF_SHAREABLE);
276 	if (mpt->pci_irq == NULL) {
277 		device_printf(dev, "could not allocate interrupt\n");
278 		goto bad;
279 	}
280 
281 	/* Register the interrupt handler */
282 	if (bus_setup_intr(dev, mpt->pci_irq, MPT_IFLAGS, mpt_pci_intr,
283 			   mpt, &mpt->ih, NULL)) {
284 		device_printf(dev, "could not setup interrupt\n");
285 		goto bad;
286 	}
287 
288 	MPT_LOCK_SETUP(mpt);
289 
290 	/* Disable interrupts at the part */
291 	mpt_disable_ints(mpt);
292 
293 	/* Allocate dma memory */
294 	if (mpt_dma_mem_alloc(mpt)) {
295 		device_printf(dev, "Could not allocate DMA memory\n");
296 		goto bad;
297 	}
298 
299 	/*
300 	 * Save the PCI config register values
301  	 *
302 	 * Hard resets are known to screw up the BAR for diagnostic
303 	 * memory accesses (Mem1).
304 	 *
305 	 * Using Mem1 is known to make the chip stop responding to
306 	 * configuration space transfers, so we need to save it now
307 	 */
308 
309 	mpt_read_config_regs(mpt);
310 
311 	/* Initialize the hardware */
312 	if (mpt->disabled == 0) {
313 		MPT_LOCK(mpt);
314 		if (mpt_init(mpt, MPT_DB_INIT_HOST) != 0) {
315 			MPT_UNLOCK(mpt);
316 			goto bad;
317 		}
318 
319 		/*
320 		 *  Attach to CAM
321 		 */
322 		mpt_cam_attach(mpt);
323 		MPT_UNLOCK(mpt);
324 	}
325 
326 	return (0);
327 
328 bad:
329 	mpt_dma_mem_free(mpt);
330 	mpt_free_bus_resources(mpt);
331 
332 	/*
333 	 * but return zero to preserve unit numbering
334 	 */
335 	return (0);
336 }
337 
338 /*
339  * Free bus resources
340  */
341 static void
342 mpt_free_bus_resources(mpt_softc_t *mpt)
343 {
344 	if (mpt->ih) {
345 		bus_teardown_intr(mpt->dev, mpt->pci_irq, mpt->ih);
346 		mpt->ih = 0;
347 	}
348 
349 	if (mpt->pci_irq) {
350 		bus_release_resource(mpt->dev, SYS_RES_IRQ, 0, mpt->pci_irq);
351 		mpt->pci_irq = 0;
352 	}
353 
354 	if (mpt->pci_reg) {
355 		bus_release_resource(mpt->dev, SYS_RES_MEMORY, mpt->pci_reg_id,
356 			mpt->pci_reg);
357 		mpt->pci_reg = 0;
358 	}
359 	MPT_LOCK_DESTROY(mpt);
360 }
361 
362 
363 /*
364  * Disconnect ourselves from the system.
365  */
366 static int
367 mpt_detach(device_t dev)
368 {
369 	mpt_softc_t *mpt;
370 	mpt  = (mpt_softc_t*) device_get_softc(dev);
371 
372 	device_printf(mpt->dev,"mpt_detach!\n");
373 
374 	if (mpt) {
375 		mpt_disable_ints(mpt);
376 		mpt_cam_detach(mpt);
377 		mpt_reset(mpt);
378 		mpt_dma_mem_free(mpt);
379 		mpt_free_bus_resources(mpt);
380 	}
381 	return(0);
382 }
383 
384 
385 /*
386  * Disable the hardware
387  */
388 static int
389 mpt_shutdown(device_t dev)
390 {
391 	mpt_softc_t *mpt;
392 	mpt  = (mpt_softc_t*) device_get_softc(dev);
393 
394 	if (mpt) {
395 		mpt_reset(mpt);
396 	}
397 	return(0);
398 }
399 
400 
401 struct imush {
402 	mpt_softc_t *mpt;
403 	int error;
404 	u_int32_t phys;
405 };
406 
407 static void
408 mpt_map_rquest(void *arg, bus_dma_segment_t *segs, int nseg, int error)
409 {
410 	struct imush *imushp = (struct imush *) arg;
411 	imushp->error = error;
412 	imushp->phys = segs->ds_addr;
413 }
414 
415 
416 static int
417 mpt_dma_mem_alloc(mpt_softc_t *mpt)
418 {
419 	int i, error;
420 	u_char *vptr;
421 	u_int32_t pptr, end;
422 	size_t len;
423 	struct imush im;
424 	device_t dev = mpt->dev;
425 
426 	/* Check if we alreay have allocated the reply memory */
427 	if (mpt->reply_phys != NULL) {
428 		return 0;
429 	}
430 
431 	len = sizeof (request_t *) * MPT_REQ_MEM_SIZE(mpt);
432 	mpt->request_pool = (request_t *) kmalloc(len, M_DEVBUF, M_WAITOK);
433 	bzero(mpt->request_pool, len);
434 
435 	/*
436 	 * Create a dma tag for this device
437 	 *
438 	 * Align at page boundaries, limit to 32-bit addressing
439 	 * (The chip supports 64-bit addressing, but this driver doesn't)
440 	 */
441 	if (bus_dma_tag_create(NULL, PAGE_SIZE, 0, BUS_SPACE_MAXADDR_32BIT,
442 	    BUS_SPACE_MAXADDR, NULL, NULL, BUS_SPACE_MAXSIZE_32BIT,
443 	    BUS_SPACE_MAXSIZE_32BIT, BUS_SPACE_UNRESTRICTED, 0,
444 	    &mpt->parent_dmat) != 0) {
445 		device_printf(dev, "cannot create parent dma tag\n");
446 		return (1);
447 	}
448 
449 	/* Create a child tag for reply buffers */
450 	if (bus_dma_tag_create(mpt->parent_dmat, PAGE_SIZE,
451 	    0, BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR,
452 	    NULL, NULL, PAGE_SIZE, 1, BUS_SPACE_MAXSIZE_32BIT, 0,
453 	    &mpt->reply_dmat) != 0) {
454 		device_printf(dev, "cannot create a dma tag for replies\n");
455 		return (1);
456 	}
457 
458 	/* Allocate some DMA accessable memory for replies */
459 	if (bus_dmamem_alloc(mpt->reply_dmat, (void **)&mpt->reply,
460 	    BUS_DMA_NOWAIT, &mpt->reply_dmap) != 0) {
461 		device_printf(dev, "cannot allocate %d bytes of reply memory\n",
462 		     PAGE_SIZE);
463 		return (1);
464 	}
465 
466 	im.mpt = mpt;
467 	im.error = 0;
468 
469 	/* Load and lock it into "bus space" */
470 	bus_dmamap_load(mpt->reply_dmat, mpt->reply_dmap, mpt->reply,
471 	    PAGE_SIZE, mpt_map_rquest, &im, 0);
472 
473 	if (im.error) {
474 		device_printf(dev,
475 		    "error %d loading dma map for DMA reply queue\n", im.error);
476 		return (1);
477 	}
478 	mpt->reply_phys = im.phys;
479 
480 	/* Create a child tag for data buffers */
481 	if (bus_dma_tag_create(mpt->parent_dmat, PAGE_SIZE,
482 	    0, BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR,
483 	    NULL, NULL, MAXBSIZE, MPT_SGL_MAX, BUS_SPACE_MAXSIZE_32BIT, 0,
484 	    &mpt->buffer_dmat) != 0) {
485 		device_printf(dev,
486 		    "cannot create a dma tag for data buffers\n");
487 		return (1);
488 	}
489 
490 	/* Create a child tag for request buffers */
491 	if (bus_dma_tag_create(mpt->parent_dmat, PAGE_SIZE,
492 	    0, BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR,
493 	    NULL, NULL, MPT_REQ_MEM_SIZE(mpt), 1, BUS_SPACE_MAXSIZE_32BIT, 0,
494 	    &mpt->request_dmat) != 0) {
495 		device_printf(dev, "cannot create a dma tag for requests\n");
496 		return (1);
497 	}
498 
499 	/* Allocate some DMA accessable memory for requests */
500 	if (bus_dmamem_alloc(mpt->request_dmat, (void **)&mpt->request,
501 	    BUS_DMA_NOWAIT, &mpt->request_dmap) != 0) {
502 		device_printf(dev,
503 		    "cannot allocate %d bytes of request memory\n",
504 		    MPT_REQ_MEM_SIZE(mpt));
505 		return (1);
506 	}
507 
508 	im.mpt = mpt;
509 	im.error = 0;
510 
511 	/* Load and lock it into "bus space" */
512         bus_dmamap_load(mpt->request_dmat, mpt->request_dmap, mpt->request,
513 	    MPT_REQ_MEM_SIZE(mpt), mpt_map_rquest, &im, 0);
514 
515 	if (im.error) {
516 		device_printf(dev,
517 		    "error %d loading dma map for DMA request queue\n",
518 		    im.error);
519 		return (1);
520 	}
521 	mpt->request_phys = im.phys;
522 
523 	i = 0;
524 	pptr =  mpt->request_phys;
525 	vptr =  mpt->request;
526 	end = pptr + MPT_REQ_MEM_SIZE(mpt);
527 	while(pptr < end) {
528 		request_t *req = &mpt->request_pool[i];
529 		req->index = i++;
530 
531 		/* Store location of Request Data */
532 		req->req_pbuf = pptr;
533 		req->req_vbuf = vptr;
534 
535 		pptr += MPT_REQUEST_AREA;
536 		vptr += MPT_REQUEST_AREA;
537 
538 		req->sense_pbuf = (pptr - MPT_SENSE_SIZE);
539 		req->sense_vbuf = (vptr - MPT_SENSE_SIZE);
540 
541 		error = bus_dmamap_create(mpt->buffer_dmat, 0, &req->dmap);
542 		if (error) {
543 			device_printf(dev,
544 			     "error %d creating per-cmd DMA maps\n", error);
545 			return (1);
546 		}
547 	}
548 	return (0);
549 }
550 
551 
552 
553 /* Deallocate memory that was allocated by mpt_dma_mem_alloc
554  */
555 static void
556 mpt_dma_mem_free(mpt_softc_t *mpt)
557 {
558 	int i;
559 
560         /* Make sure we aren't double destroying */
561         if (mpt->reply_dmat == 0) {
562 		if (mpt->verbose)
563 			device_printf(mpt->dev,"Already released dma memory\n");
564 		return;
565         }
566 
567 	for (i = 0; i < MPT_MAX_REQUESTS(mpt); i++) {
568 		bus_dmamap_destroy(mpt->buffer_dmat, mpt->request_pool[i].dmap);
569 	}
570 	bus_dmamap_unload(mpt->request_dmat, mpt->request_dmap);
571 	bus_dmamem_free(mpt->request_dmat, mpt->request, mpt->request_dmap);
572 	bus_dma_tag_destroy(mpt->request_dmat);
573 	bus_dma_tag_destroy(mpt->buffer_dmat);
574 	bus_dmamap_unload(mpt->reply_dmat, mpt->reply_dmap);
575 	bus_dmamem_free(mpt->reply_dmat, mpt->reply, mpt->reply_dmap);
576 	bus_dma_tag_destroy(mpt->reply_dmat);
577 	bus_dma_tag_destroy(mpt->parent_dmat);
578 	mpt->reply_dmat = 0;
579 	kfree(mpt->request_pool, M_DEVBUF);
580 	mpt->request_pool = 0;
581 
582 }
583 
584 
585 
586 /* Reads modifiable (via PCI transactions) config registers */
587 static void
588 mpt_read_config_regs(mpt_softc_t *mpt)
589 {
590 	mpt->pci_cfg.Command = pci_read_config(mpt->dev, PCIR_COMMAND, 2);
591 	mpt->pci_cfg.LatencyTimer_LineSize =
592 	    pci_read_config(mpt->dev, PCIR_CACHELNSZ, 2);
593 	mpt->pci_cfg.IO_BAR = pci_read_config(mpt->dev, PCIR_MAPS, 4);
594 	mpt->pci_cfg.Mem0_BAR[0] = pci_read_config(mpt->dev, PCIR_MAPS+0x4, 4);
595 	mpt->pci_cfg.Mem0_BAR[1] = pci_read_config(mpt->dev, PCIR_MAPS+0x8, 4);
596 	mpt->pci_cfg.Mem1_BAR[0] = pci_read_config(mpt->dev, PCIR_MAPS+0xC, 4);
597 	mpt->pci_cfg.Mem1_BAR[1] = pci_read_config(mpt->dev, PCIR_MAPS+0x10, 4);
598 	mpt->pci_cfg.ROM_BAR = pci_read_config(mpt->dev, PCIR_BIOS, 4);
599 	mpt->pci_cfg.IntLine = pci_read_config(mpt->dev, PCIR_INTLINE, 1);
600 	mpt->pci_cfg.PMCSR = pci_read_config(mpt->dev, 0x44, 4);
601 }
602 
603 /* Sets modifiable config registers */
604 void
605 mpt_set_config_regs(mpt_softc_t *mpt)
606 {
607 	u_int32_t val;
608 
609 #define MPT_CHECK(reg, offset, size)					\
610 	val = pci_read_config(mpt->dev, offset, size);			\
611 	if (mpt->pci_cfg.reg != val) {					\
612 		device_printf(mpt->dev,					\
613 		    "Restoring " #reg " to 0x%X from 0x%X\n",		\
614 		    mpt->pci_cfg.reg, val);				\
615 	}
616 
617 	if (mpt->verbose) {
618 		MPT_CHECK(Command, PCIR_COMMAND, 2);
619 		MPT_CHECK(LatencyTimer_LineSize, PCIR_CACHELNSZ, 2);
620 		MPT_CHECK(IO_BAR, PCIR_MAPS, 4);
621 		MPT_CHECK(Mem0_BAR[0], PCIR_MAPS+0x4, 4);
622 		MPT_CHECK(Mem0_BAR[1], PCIR_MAPS+0x8, 4);
623 		MPT_CHECK(Mem1_BAR[0], PCIR_MAPS+0xC, 4);
624 		MPT_CHECK(Mem1_BAR[1], PCIR_MAPS+0x10, 4);
625 		MPT_CHECK(ROM_BAR, PCIR_BIOS, 4);
626 		MPT_CHECK(IntLine, PCIR_INTLINE, 1);
627 		MPT_CHECK(PMCSR, 0x44, 4);
628 	}
629 #undef MPT_CHECK
630 
631 	pci_write_config(mpt->dev, PCIR_COMMAND, mpt->pci_cfg.Command, 2);
632 	pci_write_config(mpt->dev, PCIR_CACHELNSZ,
633 	    mpt->pci_cfg.LatencyTimer_LineSize, 2);
634 	pci_write_config(mpt->dev, PCIR_MAPS, mpt->pci_cfg.IO_BAR, 4);
635 	pci_write_config(mpt->dev, PCIR_MAPS+0x4, mpt->pci_cfg.Mem0_BAR[0], 4);
636 	pci_write_config(mpt->dev, PCIR_MAPS+0x8, mpt->pci_cfg.Mem0_BAR[1], 4);
637 	pci_write_config(mpt->dev, PCIR_MAPS+0xC, mpt->pci_cfg.Mem1_BAR[0], 4);
638 	pci_write_config(mpt->dev, PCIR_MAPS+0x10, mpt->pci_cfg.Mem1_BAR[1], 4);
639 	pci_write_config(mpt->dev, PCIR_BIOS, mpt->pci_cfg.ROM_BAR, 4);
640 	pci_write_config(mpt->dev, PCIR_INTLINE, mpt->pci_cfg.IntLine, 1);
641 	pci_write_config(mpt->dev, 0x44, mpt->pci_cfg.PMCSR, 4);
642 }
643 
644 static void
645 mpt_pci_intr(void *arg)
646 {
647 	mpt_softc_t *mpt = arg;
648 	MPT_LOCK(mpt);
649 	(void) mpt_intr(mpt);
650 	MPT_UNLOCK(mpt);
651 }
652