Deleted Added
sdiff udiff text old ( 150007 ) new ( 155521 )
full compact
1/*-
2 * PCI specific probe and attach routines for LSI Fusion Adapters
3 * FreeBSD Version.
4 *
5 * Copyright (c) 2000, 2001 by Greg Ansley
6 * Partially derived from Matt Jacob's ISP driver.
7 * Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002 by Matthew Jacob
8 * Feral Software

--- 49 unchanged lines hidden (view full) ---

58 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
59 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
60 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
61 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF THE COPYRIGHT
62 * OWNER OR CONTRIBUTOR IS ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
63 */
64
65#include <sys/cdefs.h>
66__FBSDID("$FreeBSD: head/sys/dev/mpt/mpt_pci.c 150007 2005-09-11 19:58:19Z mjacob $");
67
68#include <dev/mpt/mpt.h>
69#include <dev/mpt/mpt_cam.h>
70#include <dev/mpt/mpt_raid.h>
71
72#if __FreeBSD_version < 500000
73#include <pci/pcireg.h>
74#include <pci/pcivar.h>
75#else
76#include <dev/pci/pcireg.h>
77#include <dev/pci/pcivar.h>
78#endif
79
80#ifndef PCI_VENDOR_LSI
81#define PCI_VENDOR_LSI 0x1000
82#endif
83
84#ifndef PCI_PRODUCT_LSI_FC909
85#define PCI_PRODUCT_LSI_FC909 0x0620
86#endif

--- 13 unchanged lines hidden (view full) ---

100#ifndef PCI_PRODUCT_LSI_FC929X
101#define PCI_PRODUCT_LSI_FC929X 0x0626
102#endif
103
104#ifndef PCI_PRODUCT_LSI_1030
105#define PCI_PRODUCT_LSI_1030 0x0030
106#endif
107
108#ifndef PCIM_CMD_SERRESPEN
109#define PCIM_CMD_SERRESPEN 0x0100
110#endif
111
112
113
114#define MPT_IO_BAR 0
115#define MPT_MEM_BAR 1
116
117static int mpt_pci_probe(device_t);
118static int mpt_pci_attach(device_t);
119static void mpt_free_bus_resources(struct mpt_softc *mpt);
120static int mpt_pci_detach(device_t);
121static int mpt_pci_shutdown(device_t);

--- 40 unchanged lines hidden (view full) ---

162 desc = "LSILogic FC929 FC Adapter";
163 break;
164 case PCI_PRODUCT_LSI_FC929X:
165 desc = "LSILogic FC929X FC Adapter";
166 break;
167 case PCI_PRODUCT_LSI_1030:
168 desc = "LSILogic 1030 Ultra4 Adapter";
169 break;
170 default:
171 return (ENXIO);
172 }
173
174 device_set_desc(dev, desc);
175 return (0);
176}
177

--- 85 unchanged lines hidden (view full) ---

263 bzero(mpt, sizeof(struct mpt_softc));
264 switch ((pci_get_device(dev) & ~1)) {
265 case PCI_PRODUCT_LSI_FC909:
266 case PCI_PRODUCT_LSI_FC909A:
267 case PCI_PRODUCT_LSI_FC919:
268 case PCI_PRODUCT_LSI_FC929:
269 mpt->is_fc = 1;
270 break;
271 default:
272 break;
273 }
274 mpt->dev = dev;
275 mpt->unit = device_get_unit(dev);
276 mpt->raid_resync_rate = MPT_RAID_RESYNC_RATE_DEFAULT;
277 mpt->raid_mwce_setting = MPT_RAID_MWCE_DEFAULT;
278 mpt->raid_queue_depth = MPT_RAID_QUEUE_DEPTH_DEFAULT;
279 mpt_set_options(mpt);
280 mpt->verbose = MPT_PRT_INFO;
281 mpt->verbose += (bootverbose != 0)? 1 : 0;
282
283 /* Make sure memory access decoders are enabled */
284 cmd = pci_read_config(dev, PCIR_COMMAND, 2);
285 if ((cmd & PCIM_CMD_MEMEN) == 0) {
286 device_printf(dev, "Memory accesses disabled");
287 goto bad;
288 }
289
290 /*

--- 17 unchanged lines hidden (view full) ---

308 */
309 if ((pci_get_device(dev) & ~1) == PCI_PRODUCT_LSI_FC929 ||
310 (pci_get_device(dev) & ~1) == PCI_PRODUCT_LSI_1030) {
311 mpt_link_peer(mpt);
312 }
313
314 /*
315 * Set up register access. PIO mode is required for
316 * certain reset operations.
317 */
318 mpt->pci_pio_rid = PCIR_BAR(MPT_IO_BAR);
319 mpt->pci_pio_reg = bus_alloc_resource(dev, SYS_RES_IOPORT,
320 &mpt->pci_pio_rid, 0, ~0, 0, RF_ACTIVE);
321 if (mpt->pci_pio_reg == NULL) {
322 device_printf(dev, "unable to map registers in PIO mode\n");
323 goto bad;
324 }
325 mpt->pci_pio_st = rman_get_bustag(mpt->pci_pio_reg);
326 mpt->pci_pio_sh = rman_get_bushandle(mpt->pci_pio_reg);
327
328 /* Allocate kernel virtual memory for the 9x9's Mem0 region */
329 mpt->pci_mem_rid = PCIR_BAR(MPT_MEM_BAR);
330 mpt->pci_reg = bus_alloc_resource(dev, SYS_RES_MEMORY,
331 &mpt->pci_mem_rid, 0, ~0, 0, RF_ACTIVE);
332 if (mpt->pci_reg == NULL) {
333 device_printf(dev, "Unable to memory map registers.\n");
334 device_printf(dev, "Falling back to PIO mode.\n");
335 mpt->pci_st = mpt->pci_pio_st;
336 mpt->pci_sh = mpt->pci_pio_sh;
337 } else {
338 mpt->pci_st = rman_get_bustag(mpt->pci_reg);
339 mpt->pci_sh = rman_get_bushandle(mpt->pci_reg);
340 }
341

--- 37 unchanged lines hidden (view full) ---

379 * memory accesses (Mem1).
380 *
381 * Using Mem1 is known to make the chip stop responding to
382 * configuration space transfers, so we need to save it now
383 */
384
385 mpt_read_config_regs(mpt);
386
387 /* Initialize the hardware */
388 if (mpt->disabled == 0) {
389 MPT_LOCK(mpt);
390 if (mpt_attach(mpt) != 0) {
391 MPT_UNLOCK(mpt);
392 goto bad;
393 }
394 }
395
396 return (0);

--- 95 unchanged lines hidden (view full) ---

492 if (mpt)
493 return (mpt_shutdown(mpt));
494 return(0);
495}
496
497static int
498mpt_dma_mem_alloc(struct mpt_softc *mpt)
499{
500 int i, error;
501 uint8_t *vptr;
502 uint32_t pptr, end;
503 size_t len;
504 struct mpt_map_info mi;
505 device_t dev = mpt->dev;
506
507 /* Check if we alreay have allocated the reply memory */
508 if (mpt->reply_phys != 0) {

--- 12 unchanged lines hidden (view full) ---

521 mpt->request_pool = (request_t *)malloc(len, M_DEVBUF, M_WAITOK|M_ZERO);
522 if (mpt->request_pool == NULL) {
523 device_printf(dev, "cannot allocate request pool\n");
524 return (1);
525 }
526#endif
527
528 /*
529 * Create a parent dma tag for this device
530 *
531 * Align at byte boundaries, limit to 32-bit addressing
532 * (The chip supports 64-bit addressing, but this driver doesn't)
533 */
534 if (mpt_dma_tag_create(mpt, /*parent*/NULL, /*alignment*/1,
535 /*boundary*/0, /*lowaddr*/BUS_SPACE_MAXADDR_32BIT,
536 /*highaddr*/BUS_SPACE_MAXADDR, /*filter*/NULL, /*filterarg*/NULL,
537 /*maxsize*/BUS_SPACE_MAXSIZE_32BIT,
538 /*nsegments*/BUS_SPACE_MAXSIZE_32BIT,
539 /*maxsegsz*/BUS_SPACE_UNRESTRICTED, /*flags*/0,
540 &mpt->parent_dmat) != 0) {
541 device_printf(dev, "cannot create parent dma tag\n");
542 return (1);
543 }
544
545 /* Create a child tag for reply buffers */
546 if (mpt_dma_tag_create(mpt, mpt->parent_dmat, PAGE_SIZE,
547 0, BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR,
548 NULL, NULL, PAGE_SIZE, 1, BUS_SPACE_MAXSIZE_32BIT, 0,
549 &mpt->reply_dmat) != 0) {
550 device_printf(dev, "cannot create a dma tag for replies\n");
551 return (1);
552 }
553
554 /* Allocate some DMA accessable memory for replies */
555 if (bus_dmamem_alloc(mpt->reply_dmat, (void **)&mpt->reply,
556 BUS_DMA_NOWAIT, &mpt->reply_dmap) != 0) {
557 device_printf(dev, "cannot allocate %lu bytes of reply memory\n",
558 (u_long)PAGE_SIZE);
559 return (1);
560 }
561
562 mi.mpt = mpt;
563 mi.error = 0;
564
565 /* Load and lock it into "bus space" */
566 bus_dmamap_load(mpt->reply_dmat, mpt->reply_dmap, mpt->reply,
567 PAGE_SIZE, mpt_map_rquest, &mi, 0);
568
569 if (mi.error) {
570 device_printf(dev,
571 "error %d loading dma map for DMA reply queue\n", mi.error);
572 return (1);
573 }
574 mpt->reply_phys = mi.phys;
575
576 /* Create a child tag for data buffers */
577 if (mpt_dma_tag_create(mpt, mpt->parent_dmat, 1,
578 0, BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR,
579 NULL, NULL, MAXBSIZE, MPT_SGL_MAX, BUS_SPACE_MAXSIZE_32BIT, 0,
580 &mpt->buffer_dmat) != 0) {
581 device_printf(dev,
582 "cannot create a dma tag for data buffers\n");
583 return (1);
584 }
585
586 /* Create a child tag for request buffers */
587 if (mpt_dma_tag_create(mpt, mpt->parent_dmat, PAGE_SIZE,
588 0, BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR,
589 NULL, NULL, MPT_REQ_MEM_SIZE(mpt), 1, BUS_SPACE_MAXSIZE_32BIT, 0,
590 &mpt->request_dmat) != 0) {
591 device_printf(dev, "cannot create a dma tag for requests\n");
592 return (1);
593 }
594
595 /* Allocate some DMA accessable memory for requests */
596 if (bus_dmamem_alloc(mpt->request_dmat, (void **)&mpt->request,

--- 153 unchanged lines hidden ---