Deleted Added
full compact
aac.c (177463) aac.c (177557)
1/*-
2 * Copyright (c) 2000 Michael Smith
3 * Copyright (c) 2001 Scott Long
4 * Copyright (c) 2000 BSDi
5 * Copyright (c) 2001 Adaptec, Inc.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without

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

23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2000 Michael Smith
3 * Copyright (c) 2001 Scott Long
4 * Copyright (c) 2000 BSDi
5 * Copyright (c) 2001 Adaptec, Inc.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without

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

23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30#include <sys/cdefs.h>
31__FBSDID("$FreeBSD: head/sys/dev/aac/aac.c 177463 2008-03-20 20:33:48Z emaste $");
31__FBSDID("$FreeBSD: head/sys/dev/aac/aac.c 177557 2008-03-24 16:38:47Z emaste $");
32
33/*
34 * Driver for the Adaptec 'FSA' family of PCI/SCSI RAID adapters.
35 */
36#define AAC_DRIVER_VERSION 0x02000000
37#define AAC_DRIVERNAME "aac"
38
39#include "opt_aac.h"

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

85 int nseg, int error);
86static void aac_map_command_helper(void *arg, bus_dma_segment_t *segs,
87 int nseg, int error);
88static int aac_alloc_commands(struct aac_softc *sc);
89static void aac_free_commands(struct aac_softc *sc);
90static void aac_unmap_command(struct aac_command *cm);
91
92/* Hardware Interface */
32
33/*
34 * Driver for the Adaptec 'FSA' family of PCI/SCSI RAID adapters.
35 */
36#define AAC_DRIVER_VERSION 0x02000000
37#define AAC_DRIVERNAME "aac"
38
39#include "opt_aac.h"

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

85 int nseg, int error);
86static void aac_map_command_helper(void *arg, bus_dma_segment_t *segs,
87 int nseg, int error);
88static int aac_alloc_commands(struct aac_softc *sc);
89static void aac_free_commands(struct aac_softc *sc);
90static void aac_unmap_command(struct aac_command *cm);
91
92/* Hardware Interface */
93static int aac_alloc(struct aac_softc *sc);
93static void aac_common_map(void *arg, bus_dma_segment_t *segs, int nseg,
94 int error);
95static int aac_check_firmware(struct aac_softc *sc);
96static int aac_init(struct aac_softc *sc);
97static int aac_sync_command(struct aac_softc *sc, u_int32_t command,
98 u_int32_t arg0, u_int32_t arg1, u_int32_t arg2,
99 u_int32_t arg3, u_int32_t *sp);
94static void aac_common_map(void *arg, bus_dma_segment_t *segs, int nseg,
95 int error);
96static int aac_check_firmware(struct aac_softc *sc);
97static int aac_init(struct aac_softc *sc);
98static int aac_sync_command(struct aac_softc *sc, u_int32_t command,
99 u_int32_t arg0, u_int32_t arg1, u_int32_t arg2,
100 u_int32_t arg3, u_int32_t *sp);
101static int aac_setup_intr(struct aac_softc *sc);
100static int aac_enqueue_fib(struct aac_softc *sc, int queue,
101 struct aac_command *cm);
102static int aac_dequeue_fib(struct aac_softc *sc, int queue,
103 u_int32_t *fib_size, struct aac_fib **fib_addr);
104static int aac_enqueue_response(struct aac_softc *sc, int queue,
105 struct aac_fib *fib);
106
107/* Falcon/PPC interface */

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

221static int aac_close_aif(struct aac_softc *sc, caddr_t arg);
222static int aac_getnext_aif(struct aac_softc *sc, caddr_t arg);
223static int aac_return_aif(struct aac_softc *sc,
224 struct aac_fib_context *ctx, caddr_t uptr);
225static int aac_query_disk(struct aac_softc *sc, caddr_t uptr);
226static int aac_get_pci_info(struct aac_softc *sc, caddr_t uptr);
227static void aac_ioctl_event(struct aac_softc *sc,
228 struct aac_event *event, void *arg);
102static int aac_enqueue_fib(struct aac_softc *sc, int queue,
103 struct aac_command *cm);
104static int aac_dequeue_fib(struct aac_softc *sc, int queue,
105 u_int32_t *fib_size, struct aac_fib **fib_addr);
106static int aac_enqueue_response(struct aac_softc *sc, int queue,
107 struct aac_fib *fib);
108
109/* Falcon/PPC interface */

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

223static int aac_close_aif(struct aac_softc *sc, caddr_t arg);
224static int aac_getnext_aif(struct aac_softc *sc, caddr_t arg);
225static int aac_return_aif(struct aac_softc *sc,
226 struct aac_fib_context *ctx, caddr_t uptr);
227static int aac_query_disk(struct aac_softc *sc, caddr_t uptr);
228static int aac_get_pci_info(struct aac_softc *sc, caddr_t uptr);
229static void aac_ioctl_event(struct aac_softc *sc,
230 struct aac_event *event, void *arg);
231static struct aac_mntinforesp *
232 aac_get_container_info(struct aac_softc *sc, struct aac_fib *fib, int cid);
229
230static struct cdevsw aac_cdevsw = {
231 .d_version = D_VERSION,
232 .d_flags = D_NEEDGIANT,
233 .d_open = aac_open,
234 .d_close = aac_close,
235 .d_ioctl = aac_ioctl,
236 .d_poll = aac_poll,

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

285 mtx_init(&sc->aac_io_lock, "AAC I/O lock", NULL, MTX_DEF);
286 mtx_init(&sc->aac_container_lock, "AAC container lock", NULL, MTX_DEF);
287 TAILQ_INIT(&sc->aac_container_tqh);
288 TAILQ_INIT(&sc->aac_ev_cmfree);
289
290 /*
291 * Initialize the adapter.
292 */
233
234static struct cdevsw aac_cdevsw = {
235 .d_version = D_VERSION,
236 .d_flags = D_NEEDGIANT,
237 .d_open = aac_open,
238 .d_close = aac_close,
239 .d_ioctl = aac_ioctl,
240 .d_poll = aac_poll,

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

289 mtx_init(&sc->aac_io_lock, "AAC I/O lock", NULL, MTX_DEF);
290 mtx_init(&sc->aac_container_lock, "AAC container lock", NULL, MTX_DEF);
291 TAILQ_INIT(&sc->aac_container_tqh);
292 TAILQ_INIT(&sc->aac_ev_cmfree);
293
294 /*
295 * Initialize the adapter.
296 */
297 if ((error = aac_alloc(sc)) != 0)
298 return(error);
293 if ((error = aac_init(sc)) != 0)
294 return(error);
295
296 /*
297 * Allocate and connect our interrupt.
298 */
299 if ((error = aac_init(sc)) != 0)
300 return(error);
301
302 /*
303 * Allocate and connect our interrupt.
304 */
299 sc->aac_irq_rid = 0;
300 if ((sc->aac_irq = bus_alloc_resource_any(sc->aac_dev, SYS_RES_IRQ,
301 &sc->aac_irq_rid,
302 RF_SHAREABLE |
303 RF_ACTIVE)) == NULL) {
304 device_printf(sc->aac_dev, "can't allocate interrupt\n");
305 return (EINVAL);
306 }
307 if (sc->flags & AAC_FLAGS_NEW_COMM) {
308 if (bus_setup_intr(sc->aac_dev, sc->aac_irq,
309 INTR_MPSAFE|INTR_TYPE_BIO, NULL,
310 aac_new_intr, sc, &sc->aac_intr)) {
311 device_printf(sc->aac_dev, "can't set up interrupt\n");
312 return (EINVAL);
313 }
314 } else {
315 if (bus_setup_intr(sc->aac_dev, sc->aac_irq,
316 INTR_TYPE_BIO, aac_fast_intr, NULL,
317 sc, &sc->aac_intr)) {
318 device_printf(sc->aac_dev,
319 "can't set up FAST interrupt\n");
320 if (bus_setup_intr(sc->aac_dev, sc->aac_irq,
321 INTR_MPSAFE|INTR_TYPE_BIO,
322 NULL, (driver_intr_t *)aac_fast_intr,
323 sc, &sc->aac_intr)) {
324 device_printf(sc->aac_dev,
325 "can't set up MPSAFE interrupt\n");
326 return (EINVAL);
327 }
328 }
329 }
305 if ((error = aac_setup_intr(sc)) != 0)
306 return(error);
330
331 /*
332 * Print a little information about the controller.
333 */
334 aac_describe_controller(sc);
335
336 /*
337 * Register to probe our containers later.

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

387 event->ev_type);
388 break;
389 }
390
391 return;
392}
393
394/*
307
308 /*
309 * Print a little information about the controller.
310 */
311 aac_describe_controller(sc);
312
313 /*
314 * Register to probe our containers later.

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

364 event->ev_type);
365 break;
366 }
367
368 return;
369}
370
371/*
372 * Request information of container #cid
373 */
374static struct aac_mntinforesp *
375aac_get_container_info(struct aac_softc *sc, struct aac_fib *fib, int cid)
376{
377 struct aac_mntinfo *mi;
378
379 mi = (struct aac_mntinfo *)&fib->data[0];
380 mi->Command = VM_NameServe;
381 mi->MntType = FT_FILESYS;
382 mi->MntCount = cid;
383
384 if (aac_sync_fib(sc, ContainerCommand, 0, fib,
385 sizeof(struct aac_mntinfo))) {
386 printf("error probing container %d", cid);
387 return (NULL);
388 }
389
390 return ((struct aac_mntinforesp *)&fib->data[0]);
391}
392
393/*
395 * Probe for containers, create disks.
396 */
397static void
398aac_startup(void *arg)
399{
400 struct aac_softc *sc;
401 struct aac_fib *fib;
394 * Probe for containers, create disks.
395 */
396static void
397aac_startup(void *arg)
398{
399 struct aac_softc *sc;
400 struct aac_fib *fib;
402 struct aac_mntinfo *mi;
403 struct aac_mntinforesp *mir = NULL;
401 struct aac_mntinforesp *mir;
404 int count = 0, i = 0;
405
406 debug_called(1);
407
408 sc = (struct aac_softc *)arg;
409
410 /* disconnect ourselves from the intrhook chain */
411 config_intrhook_disestablish(&sc->aac_ich);
412
413 mtx_lock(&sc->aac_io_lock);
414 aac_alloc_sync_fib(sc, &fib);
402 int count = 0, i = 0;
403
404 debug_called(1);
405
406 sc = (struct aac_softc *)arg;
407
408 /* disconnect ourselves from the intrhook chain */
409 config_intrhook_disestablish(&sc->aac_ich);
410
411 mtx_lock(&sc->aac_io_lock);
412 aac_alloc_sync_fib(sc, &fib);
415 mi = (struct aac_mntinfo *)&fib->data[0];
416
417 /* loop over possible containers */
418 do {
413
414 /* loop over possible containers */
415 do {
419 /* request information on this container */
420 bzero(mi, sizeof(struct aac_mntinfo));
421 mi->Command = VM_NameServe;
422 mi->MntType = FT_FILESYS;
423 mi->MntCount = i;
424 if (aac_sync_fib(sc, ContainerCommand, 0, fib,
425 sizeof(struct aac_mntinfo))) {
426 printf("error probing container %d", i);
416 if ((mir = aac_get_container_info(sc, fib, i)) == NULL)
427 continue;
417 continue;
428 }
429
430 mir = (struct aac_mntinforesp *)&fib->data[0];
431 /* XXX Need to check if count changed */
432 count = mir->MntRespCount;
418 if (i == 0)
419 count = mir->MntRespCount;
433 aac_add_container(sc, mir, 0);
434 i++;
435 } while ((i < count) && (i < AAC_MAX_CONTAINERS));
436
437 aac_release_sync_fib(sc);
438 mtx_unlock(&sc->aac_io_lock);
439
440 /* poke the bus to actually attach the child devices */

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

483 sizeof(struct aac_mntobj));
484 mtx_lock(&sc->aac_container_lock);
485 TAILQ_INSERT_TAIL(&sc->aac_container_tqh, co, co_link);
486 mtx_unlock(&sc->aac_container_lock);
487 }
488}
489
490/*
420 aac_add_container(sc, mir, 0);
421 i++;
422 } while ((i < count) && (i < AAC_MAX_CONTAINERS));
423
424 aac_release_sync_fib(sc);
425 mtx_unlock(&sc->aac_io_lock);
426
427 /* poke the bus to actually attach the child devices */

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

470 sizeof(struct aac_mntobj));
471 mtx_lock(&sc->aac_container_lock);
472 TAILQ_INSERT_TAIL(&sc->aac_container_tqh, co, co_link);
473 mtx_unlock(&sc->aac_container_lock);
474 }
475}
476
477/*
478 * Allocate resources associated with (sc)
479 */
480static int
481aac_alloc(struct aac_softc *sc)
482{
483 /*
484 * Create DMA tag for mapping buffers into controller-addressable space.
485 */
486 if (bus_dma_tag_create(sc->aac_parent_dmat, /* parent */
487 1, 0, /* algnmnt, boundary */
488 (sc->flags & AAC_FLAGS_SG_64BIT) ?
489 BUS_SPACE_MAXADDR :
490 BUS_SPACE_MAXADDR_32BIT, /* lowaddr */
491 BUS_SPACE_MAXADDR, /* highaddr */
492 NULL, NULL, /* filter, filterarg */
493 MAXBSIZE, /* maxsize */
494 sc->aac_sg_tablesize, /* nsegments */
495 MAXBSIZE, /* maxsegsize */
496 BUS_DMA_ALLOCNOW, /* flags */
497 busdma_lock_mutex, /* lockfunc */
498 &sc->aac_io_lock, /* lockfuncarg */
499 &sc->aac_buffer_dmat)) {
500 device_printf(sc->aac_dev, "can't allocate buffer DMA tag\n");
501 return (ENOMEM);
502 }
503
504 /*
505 * Create DMA tag for mapping FIBs into controller-addressable space..
506 */
507 if (bus_dma_tag_create(sc->aac_parent_dmat, /* parent */
508 1, 0, /* algnmnt, boundary */
509 (sc->flags & AAC_FLAGS_4GB_WINDOW) ?
510 BUS_SPACE_MAXADDR_32BIT :
511 0x7fffffff, /* lowaddr */
512 BUS_SPACE_MAXADDR, /* highaddr */
513 NULL, NULL, /* filter, filterarg */
514 sc->aac_max_fibs_alloc *
515 sc->aac_max_fib_size, /* maxsize */
516 1, /* nsegments */
517 sc->aac_max_fibs_alloc *
518 sc->aac_max_fib_size, /* maxsize */
519 0, /* flags */
520 NULL, NULL, /* No locking needed */
521 &sc->aac_fib_dmat)) {
522 device_printf(sc->aac_dev, "can't allocate FIB DMA tag\n");;
523 return (ENOMEM);
524 }
525
526 /*
527 * Create DMA tag for the common structure and allocate it.
528 */
529 if (bus_dma_tag_create(sc->aac_parent_dmat, /* parent */
530 1, 0, /* algnmnt, boundary */
531 (sc->flags & AAC_FLAGS_4GB_WINDOW) ?
532 BUS_SPACE_MAXADDR_32BIT :
533 0x7fffffff, /* lowaddr */
534 BUS_SPACE_MAXADDR, /* highaddr */
535 NULL, NULL, /* filter, filterarg */
536 8192 + sizeof(struct aac_common), /* maxsize */
537 1, /* nsegments */
538 BUS_SPACE_MAXSIZE_32BIT, /* maxsegsize */
539 0, /* flags */
540 NULL, NULL, /* No locking needed */
541 &sc->aac_common_dmat)) {
542 device_printf(sc->aac_dev,
543 "can't allocate common structure DMA tag\n");
544 return (ENOMEM);
545 }
546 if (bus_dmamem_alloc(sc->aac_common_dmat, (void **)&sc->aac_common,
547 BUS_DMA_NOWAIT, &sc->aac_common_dmamap)) {
548 device_printf(sc->aac_dev, "can't allocate common structure\n");
549 return (ENOMEM);
550 }
551
552 /*
553 * Work around a bug in the 2120 and 2200 that cannot DMA commands
554 * below address 8192 in physical memory.
555 * XXX If the padding is not needed, can it be put to use instead
556 * of ignored?
557 */
558 (void)bus_dmamap_load(sc->aac_common_dmat, sc->aac_common_dmamap,
559 sc->aac_common, 8192 + sizeof(*sc->aac_common),
560 aac_common_map, sc, 0);
561
562 if (sc->aac_common_busaddr < 8192) {
563 sc->aac_common = (struct aac_common *)
564 ((uint8_t *)sc->aac_common + 8192);
565 sc->aac_common_busaddr += 8192;
566 }
567 bzero(sc->aac_common, sizeof(*sc->aac_common));
568
569 /* Allocate some FIBs and associated command structs */
570 TAILQ_INIT(&sc->aac_fibmap_tqh);
571 sc->aac_commands = malloc(sc->aac_max_fibs * sizeof(struct aac_command),
572 M_AACBUF, M_WAITOK|M_ZERO);
573 while (sc->total_fibs < AAC_PREALLOCATE_FIBS) {
574 if (aac_alloc_commands(sc) != 0)
575 break;
576 }
577 if (sc->total_fibs == 0)
578 return (ENOMEM);
579
580 return (0);
581}
582
583/*
491 * Free all of the resources associated with (sc)
492 *
493 * Should not be called if the controller is active.
494 */
495void
496aac_free(struct aac_softc *sc)
497{
498

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

1575 sc = (struct aac_softc *)arg;
1576
1577 sc->aac_common_busaddr = segs[0].ds_addr;
1578}
1579
1580static int
1581aac_check_firmware(struct aac_softc *sc)
1582{
584 * Free all of the resources associated with (sc)
585 *
586 * Should not be called if the controller is active.
587 */
588void
589aac_free(struct aac_softc *sc)
590{
591

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

1668 sc = (struct aac_softc *)arg;
1669
1670 sc->aac_common_busaddr = segs[0].ds_addr;
1671}
1672
1673static int
1674aac_check_firmware(struct aac_softc *sc)
1675{
1583 u_int32_t major, minor, options = 0, atu_size = 0;
1676 u_int32_t code, major, minor, options = 0, atu_size = 0;
1584 int status;
1677 int status;
1678 time_t then;
1585
1586 debug_called(1);
1679
1680 debug_called(1);
1681 /*
1682 * Wait for the adapter to come ready.
1683 */
1684 then = time_uptime;
1685 do {
1686 code = AAC_GET_FWSTATUS(sc);
1687 if (code & AAC_SELF_TEST_FAILED) {
1688 device_printf(sc->aac_dev, "FATAL: selftest failed\n");
1689 return(ENXIO);
1690 }
1691 if (code & AAC_KERNEL_PANIC) {
1692 device_printf(sc->aac_dev,
1693 "FATAL: controller kernel panic\n");
1694 return(ENXIO);
1695 }
1696 if (time_uptime > (then + AAC_BOOT_TIMEOUT)) {
1697 device_printf(sc->aac_dev,
1698 "FATAL: controller not coming ready, "
1699 "status %x\n", code);
1700 return(ENXIO);
1701 }
1702 } while (!(code & AAC_UP_AND_RUNNING));
1587
1588 /*
1589 * Retrieve the firmware version numbers. Dell PERC2/QC cards with
1590 * firmware version 1.x are not compatible with this driver.
1591 */
1592 if (sc->flags & AAC_FLAGS_PERC2QC) {
1593 if (aac_sync_command(sc, AAC_MONKER_GETKERNVER, 0, 0, 0, 0,
1594 NULL)) {

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

1701
1702 return (0);
1703}
1704
1705static int
1706aac_init(struct aac_softc *sc)
1707{
1708 struct aac_adapter_init *ip;
1703
1704 /*
1705 * Retrieve the firmware version numbers. Dell PERC2/QC cards with
1706 * firmware version 1.x are not compatible with this driver.
1707 */
1708 if (sc->flags & AAC_FLAGS_PERC2QC) {
1709 if (aac_sync_command(sc, AAC_MONKER_GETKERNVER, 0, 0, 0, 0,
1710 NULL)) {

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

1817
1818 return (0);
1819}
1820
1821static int
1822aac_init(struct aac_softc *sc)
1823{
1824 struct aac_adapter_init *ip;
1709 time_t then;
1710 u_int32_t code, qoffset;
1825 u_int32_t qoffset;
1711 int error;
1712
1713 debug_called(1);
1714
1826 int error;
1827
1828 debug_called(1);
1829
1715 /*
1716 * First wait for the adapter to come ready.
1717 */
1718 then = time_uptime;
1719 do {
1720 code = AAC_GET_FWSTATUS(sc);
1721 if (code & AAC_SELF_TEST_FAILED) {
1722 device_printf(sc->aac_dev, "FATAL: selftest failed\n");
1723 return(ENXIO);
1724 }
1725 if (code & AAC_KERNEL_PANIC) {
1726 device_printf(sc->aac_dev,
1727 "FATAL: controller kernel panic\n");
1728 return(ENXIO);
1729 }
1730 if (time_uptime > (then + AAC_BOOT_TIMEOUT)) {
1731 device_printf(sc->aac_dev,
1732 "FATAL: controller not coming ready, "
1733 "status %x\n", code);
1734 return(ENXIO);
1735 }
1736 } while (!(code & AAC_UP_AND_RUNNING));
1737
1830
1738 error = ENOMEM;
1739 /*
1831 /*
1740 * Create DMA tag for mapping buffers into controller-addressable space.
1741 */
1742 if (bus_dma_tag_create(sc->aac_parent_dmat, /* parent */
1743 1, 0, /* algnmnt, boundary */
1744 (sc->flags & AAC_FLAGS_SG_64BIT) ?
1745 BUS_SPACE_MAXADDR :
1746 BUS_SPACE_MAXADDR_32BIT, /* lowaddr */
1747 BUS_SPACE_MAXADDR, /* highaddr */
1748 NULL, NULL, /* filter, filterarg */
1749 MAXBSIZE, /* maxsize */
1750 sc->aac_sg_tablesize, /* nsegments */
1751 MAXBSIZE, /* maxsegsize */
1752 BUS_DMA_ALLOCNOW, /* flags */
1753 busdma_lock_mutex, /* lockfunc */
1754 &sc->aac_io_lock, /* lockfuncarg */
1755 &sc->aac_buffer_dmat)) {
1756 device_printf(sc->aac_dev, "can't allocate buffer DMA tag\n");
1757 goto out;
1758 }
1759
1760 /*
1761 * Create DMA tag for mapping FIBs into controller-addressable space..
1762 */
1763 if (bus_dma_tag_create(sc->aac_parent_dmat, /* parent */
1764 1, 0, /* algnmnt, boundary */
1765 (sc->flags & AAC_FLAGS_4GB_WINDOW) ?
1766 BUS_SPACE_MAXADDR_32BIT :
1767 0x7fffffff, /* lowaddr */
1768 BUS_SPACE_MAXADDR, /* highaddr */
1769 NULL, NULL, /* filter, filterarg */
1770 sc->aac_max_fibs_alloc *
1771 sc->aac_max_fib_size, /* maxsize */
1772 1, /* nsegments */
1773 sc->aac_max_fibs_alloc *
1774 sc->aac_max_fib_size, /* maxsegsize */
1775 0, /* flags */
1776 NULL, NULL, /* No locking needed */
1777 &sc->aac_fib_dmat)) {
1778 device_printf(sc->aac_dev, "can't allocate FIB DMA tag\n");;
1779 goto out;
1780 }
1781
1782 /*
1783 * Create DMA tag for the common structure and allocate it.
1784 */
1785 if (bus_dma_tag_create(sc->aac_parent_dmat, /* parent */
1786 1, 0, /* algnmnt, boundary */
1787 (sc->flags & AAC_FLAGS_4GB_WINDOW) ?
1788 BUS_SPACE_MAXADDR_32BIT :
1789 0x7fffffff, /* lowaddr */
1790 BUS_SPACE_MAXADDR, /* highaddr */
1791 NULL, NULL, /* filter, filterarg */
1792 8192 + sizeof(struct aac_common), /* maxsize */
1793 1, /* nsegments */
1794 BUS_SPACE_MAXSIZE_32BIT, /* maxsegsize */
1795 0, /* flags */
1796 NULL, NULL, /* No locking needed */
1797 &sc->aac_common_dmat)) {
1798 device_printf(sc->aac_dev,
1799 "can't allocate common structure DMA tag\n");
1800 goto out;
1801 }
1802 if (bus_dmamem_alloc(sc->aac_common_dmat, (void **)&sc->aac_common,
1803 BUS_DMA_NOWAIT, &sc->aac_common_dmamap)) {
1804 device_printf(sc->aac_dev, "can't allocate common structure\n");
1805 goto out;
1806 }
1807
1808 /*
1809 * Work around a bug in the 2120 and 2200 that cannot DMA commands
1810 * below address 8192 in physical memory.
1811 * XXX If the padding is not needed, can it be put to use instead
1812 * of ignored?
1813 */
1814 (void)bus_dmamap_load(sc->aac_common_dmat, sc->aac_common_dmamap,
1815 sc->aac_common, 8192 + sizeof(*sc->aac_common),
1816 aac_common_map, sc, 0);
1817
1818 if (sc->aac_common_busaddr < 8192) {
1819 sc->aac_common = (struct aac_common *)
1820 ((uint8_t *)sc->aac_common + 8192);
1821 sc->aac_common_busaddr += 8192;
1822 }
1823 bzero(sc->aac_common, sizeof(*sc->aac_common));
1824
1825 /* Allocate some FIBs and associated command structs */
1826 TAILQ_INIT(&sc->aac_fibmap_tqh);
1827 sc->aac_commands = malloc(sc->aac_max_fibs * sizeof(struct aac_command),
1828 M_AACBUF, M_WAITOK|M_ZERO);
1829 while (sc->total_fibs < AAC_PREALLOCATE_FIBS) {
1830 if (aac_alloc_commands(sc) != 0)
1831 break;
1832 }
1833 if (sc->total_fibs == 0)
1834 goto out;
1835
1836 /*
1837 * Fill in the init structure. This tells the adapter about the
1838 * physical location of various important shared data structures.
1839 */
1840 ip = &sc->aac_common->ac_init;
1841 ip->InitStructRevision = AAC_INIT_STRUCT_REVISION;
1842 if (sc->aac_max_fib_size > sizeof(struct aac_fib)) {
1843 ip->InitStructRevision = AAC_INIT_STRUCT_REVISION_4;
1844 sc->flags |= AAC_FLAGS_RAW_IO;

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

1976 goto out;
1977 }
1978
1979 error = 0;
1980out:
1981 return(error);
1982}
1983
1832 * Fill in the init structure. This tells the adapter about the
1833 * physical location of various important shared data structures.
1834 */
1835 ip = &sc->aac_common->ac_init;
1836 ip->InitStructRevision = AAC_INIT_STRUCT_REVISION;
1837 if (sc->aac_max_fib_size > sizeof(struct aac_fib)) {
1838 ip->InitStructRevision = AAC_INIT_STRUCT_REVISION_4;
1839 sc->flags |= AAC_FLAGS_RAW_IO;

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

1971 goto out;
1972 }
1973
1974 error = 0;
1975out:
1976 return(error);
1977}
1978
1979static int
1980aac_setup_intr(struct aac_softc *sc)
1981{
1982 sc->aac_irq_rid = 0;
1983 if ((sc->aac_irq = bus_alloc_resource_any(sc->aac_dev, SYS_RES_IRQ,
1984 &sc->aac_irq_rid,
1985 RF_SHAREABLE |
1986 RF_ACTIVE)) == NULL) {
1987 device_printf(sc->aac_dev, "can't allocate interrupt\n");
1988 return (EINVAL);
1989 }
1990 if (sc->flags & AAC_FLAGS_NEW_COMM) {
1991 if (bus_setup_intr(sc->aac_dev, sc->aac_irq,
1992 INTR_MPSAFE|INTR_TYPE_BIO, NULL,
1993 aac_new_intr, sc, &sc->aac_intr)) {
1994 device_printf(sc->aac_dev, "can't set up interrupt\n");
1995 return (EINVAL);
1996 }
1997 } else {
1998 if (bus_setup_intr(sc->aac_dev, sc->aac_irq,
1999 INTR_TYPE_BIO, aac_fast_intr, NULL,
2000 sc, &sc->aac_intr)) {
2001 device_printf(sc->aac_dev,
2002 "can't set up FAST interrupt\n");
2003 if (bus_setup_intr(sc->aac_dev, sc->aac_irq,
2004 INTR_MPSAFE|INTR_TYPE_BIO,
2005 NULL, (driver_intr_t *)aac_fast_intr,
2006 sc, &sc->aac_intr)) {
2007 device_printf(sc->aac_dev,
2008 "can't set up MPSAFE interrupt\n");
2009 return (EINVAL);
2010 }
2011 }
2012 }
2013 return (0);
2014}
2015
1984/*
1985 * Send a synchronous command to the controller and wait for a result.
1986 * Indicate if the controller completed the command with an error status.
1987 */
1988static int
1989aac_sync_command(struct aac_softc *sc, u_int32_t command,
1990 u_int32_t arg0, u_int32_t arg1, u_int32_t arg2, u_int32_t arg3,
1991 u_int32_t *sp)

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

3105 * If the queue fills up, then drop the older entries.
3106 */
3107static void
3108aac_handle_aif(struct aac_softc *sc, struct aac_fib *fib)
3109{
3110 struct aac_aif_command *aif;
3111 struct aac_container *co, *co_next;
3112 struct aac_fib_context *ctx;
2016/*
2017 * Send a synchronous command to the controller and wait for a result.
2018 * Indicate if the controller completed the command with an error status.
2019 */
2020static int
2021aac_sync_command(struct aac_softc *sc, u_int32_t command,
2022 u_int32_t arg0, u_int32_t arg1, u_int32_t arg2, u_int32_t arg3,
2023 u_int32_t *sp)

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

3137 * If the queue fills up, then drop the older entries.
3138 */
3139static void
3140aac_handle_aif(struct aac_softc *sc, struct aac_fib *fib)
3141{
3142 struct aac_aif_command *aif;
3143 struct aac_container *co, *co_next;
3144 struct aac_fib_context *ctx;
3113 struct aac_mntinfo *mi;
3114 struct aac_mntinforesp *mir = NULL;
3115 u_int16_t rsize;
3145 struct aac_mntinforesp *mir;
3116 int next, current, found;
3117 int count = 0, added = 0, i = 0;
3118
3119 debug_called(2);
3120
3121 aif = (struct aac_aif_command*)&fib->data[0];
3122 aac_print_aif(sc, aif);
3123

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

3128 case AifEnAddContainer:
3129 case AifEnDeleteContainer:
3130 /*
3131 * A container was added or deleted, but the message
3132 * doesn't tell us anything else! Re-enumerate the
3133 * containers and sort things out.
3134 */
3135 aac_alloc_sync_fib(sc, &fib);
3146 int next, current, found;
3147 int count = 0, added = 0, i = 0;
3148
3149 debug_called(2);
3150
3151 aif = (struct aac_aif_command*)&fib->data[0];
3152 aac_print_aif(sc, aif);
3153

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

3158 case AifEnAddContainer:
3159 case AifEnDeleteContainer:
3160 /*
3161 * A container was added or deleted, but the message
3162 * doesn't tell us anything else! Re-enumerate the
3163 * containers and sort things out.
3164 */
3165 aac_alloc_sync_fib(sc, &fib);
3136 mi = (struct aac_mntinfo *)&fib->data[0];
3137 do {
3138 /*
3139 * Ask the controller for its containers one at
3140 * a time.
3141 * XXX What if the controller's list changes
3142 * midway through this enumaration?
3143 * XXX This should be done async.
3144 */
3166 do {
3167 /*
3168 * Ask the controller for its containers one at
3169 * a time.
3170 * XXX What if the controller's list changes
3171 * midway through this enumaration?
3172 * XXX This should be done async.
3173 */
3145 bzero(mi, sizeof(struct aac_mntinfo));
3146 mi->Command = VM_NameServe;
3147 mi->MntType = FT_FILESYS;
3148 mi->MntCount = i;
3149 rsize = sizeof(mir);
3150 if (aac_sync_fib(sc, ContainerCommand, 0, fib,
3151 sizeof(struct aac_mntinfo))) {
3152 printf("Error probing container %d\n",
3153 i);
3174 if ((mir = aac_get_container_info(sc, fib, i)) == NULL)
3154 continue;
3175 continue;
3155 }
3156 mir = (struct aac_mntinforesp *)&fib->data[0];
3157 /* XXX Need to check if count changed */
3158 count = mir->MntRespCount;
3176 if (i == 0)
3177 count = mir->MntRespCount;
3159 /*
3160 * Check the container against our list.
3161 * co->co_found was already set to 0 in a
3162 * previous run.
3163 */
3164 if ((mir->Status == ST_OK) &&
3165 (mir->MntTable[0].VolType != CT_NONE)) {
3166 found = 0;

--- 477 unchanged lines hidden ---
3178 /*
3179 * Check the container against our list.
3180 * co->co_found was already set to 0 in a
3181 * previous run.
3182 */
3183 if ((mir->Status == ST_OK) &&
3184 (mir->MntTable[0].VolType != CT_NONE)) {
3185 found = 0;

--- 477 unchanged lines hidden ---