Deleted Added
sdiff udiff text old ( 152817 ) new ( 153409 )
full compact
1/*-
2 * Copyright (c) 1999,2000 Michael Smith
3 * Copyright (c) 2000 BSDi
4 * Copyright (c) 2005 Scott Long
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

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

51 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
53 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
54 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
55 * SUCH DAMAGE.
56 */
57
58#include <sys/cdefs.h>
59__FBSDID("$FreeBSD: head/sys/dev/amr/amr.c 152817 2005-11-26 07:30:09Z scottl $");
60
61/*
62 * Driver for the AMI MegaRaid family of controllers.
63 */
64
65#include <sys/param.h>
66#include <sys/systm.h>
67#include <sys/malloc.h>
68#include <sys/kernel.h>
69
70#include <sys/bio.h>
71#include <sys/bus.h>
72#include <sys/conf.h>
73#include <sys/stat.h>
74
75#include <machine/bus.h>
76#include <machine/resource.h>
77#include <sys/rman.h>
78
79#include <dev/pci/pcireg.h>
80#include <dev/pci/pcivar.h>
81
82#include <dev/amr/amrio.h>
83#include <dev/amr/amrreg.h>
84#include <dev/amr/amrvar.h>
85#define AMR_DEFINE_TABLES
86#include <dev/amr/amr_tables.h>
87
88/*
89 * The CAM interface appears to be completely broken. Disable it.
90 */
91#ifndef AMR_ENABLE_CAM
92#define AMR_ENABLE_CAM 0
93#endif
94
95static d_open_t amr_open;
96static d_close_t amr_close;
97static d_ioctl_t amr_ioctl;
98
99static struct cdevsw amr_cdevsw = {
100 .d_version = D_VERSION,
101 .d_flags = D_NEEDGIANT,
102 .d_open = amr_open,

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

110 */
111static void amr_startup(void *arg);
112
113/*
114 * Command wrappers
115 */
116static int amr_query_controller(struct amr_softc *sc);
117static void *amr_enquiry(struct amr_softc *sc, size_t bufsize,
118 u_int8_t cmd, u_int8_t cmdsub, u_int8_t cmdqual);
119static void amr_completeio(struct amr_command *ac);
120static int amr_support_ext_cdb(struct amr_softc *sc);
121
122/*
123 * Command buffer allocation.
124 */
125static void amr_alloccmd_cluster(struct amr_softc *sc);
126static void amr_freecmd_cluster(struct amr_command_cluster *acc);
127
128/*
129 * Command processing.
130 */
131static int amr_bio_command(struct amr_softc *sc, struct amr_command **acp);
132static int amr_wait_command(struct amr_command *ac) __unused;
133static int amr_getslot(struct amr_command *ac);
134static int amr_mapcmd(struct amr_command *ac);
135static void amr_unmapcmd(struct amr_command *ac);
136static int amr_start(struct amr_command *ac);
137static int amr_start1(struct amr_softc *sc, struct amr_command *ac);
138static void amr_complete(void *context, int pending);
139static void amr_setup_dmamap(void *arg, bus_dma_segment_t *segs, int nsegments, int error);
140static void amr_setup_data_dmamap(void *arg, bus_dma_segment_t *segs, int nsegments, int error);
141
142/*
143 * Status monitoring
144 */
145static void amr_periodic(void *data);
146
147/*

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

167 */
168static void amr_describe_controller(struct amr_softc *sc);
169#ifdef AMR_DEBUG
170#if 0
171static void amr_printcommand(struct amr_command *ac);
172#endif
173#endif
174
175/********************************************************************************
176 ********************************************************************************
177 Inline Glue
178 ********************************************************************************
179 ********************************************************************************/
180
181/********************************************************************************
182 ********************************************************************************

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

227 /*
228 * Quiz controller for features and limits.
229 */
230 if (amr_query_controller(sc))
231 return(ENXIO);
232
233 debug(2, "controller query complete");
234
235#if AMR_ENABLE_CAM != 0
236 /*
237 * Attach our 'real' SCSI channels to CAM.
238 */
239 if (amr_cam_attach(sc))
240 return(ENXIO);
241 debug(2, "CAM attach done");
242#endif

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

277{
278 struct amr_softc *sc = (struct amr_softc *)arg;
279 struct amr_logdrive *dr;
280 int i, error;
281
282 debug_called(1);
283
284 /* pull ourselves off the intrhook chain */
285 config_intrhook_disestablish(&sc->amr_ich);
286
287 /* get up-to-date drive information */
288 if (amr_query_controller(sc)) {
289 device_printf(sc->amr_dev, "can't scan controller for drives\n");
290 return;
291 }
292
293 /* iterate over available drives */

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

323 /*
324 * Start the timeout routine.
325 */
326/* sc->amr_timeout = timeout(amr_periodic, sc, hz);*/
327
328 return;
329}
330
331/*******************************************************************************
332 * Free resources associated with a controller instance
333 */
334void
335amr_free(struct amr_softc *sc)
336{
337 struct amr_command_cluster *acc;
338

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

349 TAILQ_REMOVE(&sc->amr_cmd_clusters, acc, acc_link);
350 amr_freecmd_cluster(acc);
351 }
352
353 /* destroy control device */
354 if( sc->amr_dev_t != (struct cdev *)NULL)
355 destroy_dev(sc->amr_dev_t);
356
357 if (mtx_initialized(&sc->amr_io_lock))
358 mtx_destroy(&sc->amr_io_lock);
359}
360
361/*******************************************************************************
362 * Receive a bio structure from a child device and queue it on a particular
363 * disk resource, then poke the disk resource to start as much work as it can.
364 */
365int
366amr_submit_bio(struct amr_softc *sc, struct bio *bio)
367{
368 debug_called(2);
369
370 mtx_lock(&sc->amr_io_lock);
371 amr_enqueue_bio(sc, bio);
372 amr_startio(sc);
373 mtx_unlock(&sc->amr_io_lock);
374 return(0);
375}
376
377/********************************************************************************
378 * Accept an open operation on the control device.
379 */
380static int
381amr_open(struct cdev *dev, int flags, int fmt, d_thread_t *td)
382{
383 int unit = minor(dev);
384 struct amr_softc *sc = devclass_get_softc(devclass_find("amr"), unit);
385
386 debug_called(1);
387
388 sc->amr_state |= AMR_STATE_OPEN;
389 return(0);
390}
391
392/********************************************************************************
393 * Accept the last close on the control device.
394 */
395static int
396amr_close(struct cdev *dev, int flags, int fmt, d_thread_t *td)
397{
398 int unit = minor(dev);
399 struct amr_softc *sc = devclass_get_softc(devclass_find("amr"), unit);
400
401 debug_called(1);
402
403 sc->amr_state &= ~AMR_STATE_OPEN;
404 return (0);
405}
406
407/********************************************************************************
408 * Handle controller-specific control operations.
409 */
410static int
411amr_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int32_t flag, d_thread_t *td)
412{
413 struct amr_softc *sc = (struct amr_softc *)dev->si_drv1;
414 union {
415 void *_p;
416 struct amr_user_ioctl *au;
417#ifdef AMR_IO_COMMAND32
418 struct amr_user_ioctl32 *au32;
419#endif
420 int *result;
421 } arg;
422 struct amr_command *ac;
423 struct amr_mailbox_ioctl *mbi;
424 void *dp, *au_buffer;
425 unsigned long au_length;
426 unsigned char *au_cmd;
427 int *au_statusp, au_direction;
428 int error;
429 struct amr_passthrough *ap; /* 60 bytes */
430
431 debug_called(1);
432
433 arg._p = (void *)addr;
434
435 switch(cmd) {
436
437 case AMR_IO_VERSION:
438 debug(1, "AMR_IO_VERSION");
439 *arg.result = AMR_IO_VERSION_NUMBER;
440 return(0);
441
442#ifdef AMR_IO_COMMAND32

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

459 debug(1, "AMR_IO_COMMAND 0x%x", arg.au->au_cmd[0]);
460 au_cmd = arg.au->au_cmd;
461 au_buffer = (void *)arg.au->au_buffer;
462 au_length = arg.au->au_length;
463 au_direction = arg.au->au_direction;
464 au_statusp = &arg.au->au_status;
465 break;
466
467 default:
468 debug(1, "unknown ioctl 0x%lx", cmd);
469 return(ENOIOCTL);
470 }
471
472 error = 0;
473 dp = NULL;
474 ac = NULL;
475 ap = NULL;
476
477 /* Logical Drive not supported by the driver */
478 if (au_cmd[0] == 0xa4 && au_cmd[1] == 0x1c)
479 return (ENOIOCTL);
480
481 /* handle inbound data buffer */
482 if (au_length != 0 && au_cmd[0] != 0x06) {
483 dp = malloc(au_length, M_DEVBUF, M_WAITOK|M_ZERO);
484
485 if ((error = copyin(au_buffer, dp, au_length)) != 0) {
486 free(dp, M_DEVBUF);
487 return (error);
488 }
489 debug(2, "copyin %ld bytes from %p -> %p", au_length, au_buffer, dp);
490 }
491
492 /* Allocate this now before the mutex gets held */
493 if (au_cmd[0] == AMR_CMD_PASS)
494 ap = malloc(sizeof(struct amr_passthrough), M_DEVBUF, M_WAITOK|M_ZERO);
495
496 mtx_lock(&sc->amr_io_lock);
497 if ((ac = amr_alloccmd(sc)) == NULL) {
498 error = ENOMEM;
499 goto out;
500 }
501
502 /* handle SCSI passthrough command */
503 if (au_cmd[0] == AMR_CMD_PASS) {
504 int len;
505
506 /* copy cdb */
507 len = au_cmd[2];
508 ap->ap_cdb_length = len;

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

517 ap->ap_scsi_id = au_cmd[len + 6];
518 ap->ap_request_sense_length = 14;
519 ap->ap_data_transfer_length = au_length;
520 /* XXX what about the request-sense area? does the caller want it? */
521
522 /* build command */
523 ac->ac_data = ap;
524 ac->ac_length = sizeof(struct amr_passthrough);
525 ac->ac_flags |= AMR_CMD_DATAOUT;
526 ac->ac_ccb_data = dp;
527 ac->ac_ccb_length = au_length;
528 if (au_direction & AMR_IO_READ)
529 ac->ac_flags |= AMR_CMD_CCB_DATAIN;
530 if (au_direction & AMR_IO_WRITE)
531 ac->ac_flags |= AMR_CMD_CCB_DATAOUT;
532
533 ac->ac_mailbox.mb_command = AMR_CMD_PASS;
534
535 } else {
536 /* direct command to controller */
537 mbi = (struct amr_mailbox_ioctl *)&ac->ac_mailbox;
538
539 /* copy pertinent mailbox items */
540 mbi->mb_command = au_cmd[0];
541 mbi->mb_channel = au_cmd[1];
542 mbi->mb_param = au_cmd[2];
543 mbi->mb_pad[0] = au_cmd[3];
544 mbi->mb_drive = au_cmd[4];
545
546 /* build the command */
547 ac->ac_data = dp;
548 ac->ac_length = au_length;
549 if (au_direction & AMR_IO_READ)
550 ac->ac_flags |= AMR_CMD_DATAIN;
551 if (au_direction & AMR_IO_WRITE)
552 ac->ac_flags |= AMR_CMD_DATAOUT;
553 }
554
555 /* run the command */
556 if ((error = amr_wait_command(ac)) != 0)
557 goto out;
558
559 /* copy out data and set status */
560 if (au_length != 0) {
561 mtx_unlock(&sc->amr_io_lock);
562 error = copyout(dp, au_buffer, au_length);
563 mtx_lock(&sc->amr_io_lock);
564 }
565 debug(2, "copyout %ld bytes from %p -> %p", au_length, dp, au_buffer);
566 if (dp != NULL)
567 debug(2, "%16d", (int)dp);
568 *au_statusp = ac->ac_status;
569
570out:
571 /*
572 * At this point, we know that there is a lock held and that these
573 * objects have been allocated.
574 */
575 if (ac != NULL)
576 amr_releasecmd(ac);
577 mtx_unlock(&sc->amr_io_lock);
578 if (dp != NULL)
579 free(dp, M_DEVBUF);
580 if (ap != NULL)
581 free(ap, M_DEVBUF);
582 return(error);
583}
584
585/********************************************************************************
586 ********************************************************************************
587 Status Monitoring
588 ********************************************************************************
589 ********************************************************************************/

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

618 */
619static int
620amr_query_controller(struct amr_softc *sc)
621{
622 struct amr_enquiry3 *aex;
623 struct amr_prodinfo *ap;
624 struct amr_enquiry *ae;
625 int ldrv;
626
627 mtx_lock(&sc->amr_io_lock);
628
629 /*
630 * If we haven't found the real limit yet, let us have a couple of commands in
631 * order to be able to probe.
632 */
633 if (sc->amr_maxio == 0)
634 sc->amr_maxio = 2;
635
636 /*

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

641 if(sc->support_ext_cdb) {
642 debug(2,"supports extended CDBs.");
643 }
644
645 /*
646 * Try to issue an ENQUIRY3 command
647 */
648 if ((aex = amr_enquiry(sc, 2048, AMR_CMD_CONFIG, AMR_CONFIG_ENQ3,
649 AMR_CONFIG_ENQ3_SOLICITED_FULL)) != NULL) {
650
651 /*
652 * Fetch current state of logical drives.
653 */
654 for (ldrv = 0; ldrv < aex->ae_numldrives; ldrv++) {
655 sc->amr_drive[ldrv].al_size = aex->ae_drivesize[ldrv];
656 sc->amr_drive[ldrv].al_state = aex->ae_drivestate[ldrv];
657 sc->amr_drive[ldrv].al_properties = aex->ae_driveprop[ldrv];
658 debug(2, " drive %d: %d state %x properties %x\n", ldrv, sc->amr_drive[ldrv].al_size,
659 sc->amr_drive[ldrv].al_state, sc->amr_drive[ldrv].al_properties);
660 }
661 free(aex, M_DEVBUF);
662
663 /*
664 * Get product info for channel count.
665 */
666 if ((ap = amr_enquiry(sc, 2048, AMR_CMD_CONFIG, AMR_CONFIG_PRODUCT_INFO, 0)) == NULL) {
667 device_printf(sc->amr_dev, "can't obtain product data from controller\n");
668 mtx_unlock(&sc->amr_io_lock);
669 return(1);
670 }
671 sc->amr_maxdrives = 40;
672 sc->amr_maxchan = ap->ap_nschan;
673 sc->amr_maxio = ap->ap_maxio;
674 sc->amr_type |= AMR_TYPE_40LD;
675 free(ap, M_DEVBUF);
676
677 } else {
678
679 /* failed, try the 8LD ENQUIRY commands */
680 if ((ae = (struct amr_enquiry *)amr_enquiry(sc, 2048, AMR_CMD_EXT_ENQUIRY2, 0, 0)) == NULL) {
681 if ((ae = (struct amr_enquiry *)amr_enquiry(sc, 2048, AMR_CMD_ENQUIRY, 0, 0)) == NULL) {
682 device_printf(sc->amr_dev, "can't obtain configuration data from controller\n");
683 mtx_unlock(&sc->amr_io_lock);
684 return(1);
685 }
686 ae->ae_signature = 0;
687 }
688
689 /*
690 * Fetch current state of logical drives.
691 */

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

710 sc->amr_drive[ldrv].al_size = 0xffffffff;
711
712 /*
713 * Cap the maximum number of outstanding I/Os. AMI's Linux driver doesn't trust
714 * the controller's reported value, and lockups have been seen when we do.
715 */
716 sc->amr_maxio = imin(sc->amr_maxio, AMR_LIMITCMD);
717
718 mtx_unlock(&sc->amr_io_lock);
719 return(0);
720}
721
722/********************************************************************************
723 * Run a generic enquiry-style command.
724 */
725static void *
726amr_enquiry(struct amr_softc *sc, size_t bufsize, u_int8_t cmd, u_int8_t cmdsub, u_int8_t cmdqual)
727{
728 struct amr_command *ac;
729 void *result;
730 u_int8_t *mbox;
731 int error;
732
733 debug_called(1);
734
735 error = 1;
736 result = NULL;
737
738 /* get ourselves a command buffer */
739 if ((ac = amr_alloccmd(sc)) == NULL)
740 goto out;
741 /* allocate the response structure */
742 if ((result = malloc(bufsize, M_DEVBUF, M_ZERO|M_NOWAIT)) == NULL)
743 goto out;
744 /* set command flags */
745
746 ac->ac_flags |= AMR_CMD_PRIORITY | AMR_CMD_DATAIN;
747
748 /* point the command at our data */
749 ac->ac_data = result;
750 ac->ac_length = bufsize;
751
752 /* build the command proper */
753 mbox = (u_int8_t *)&ac->ac_mailbox; /* XXX want a real structure for this? */
754 mbox[0] = cmd;
755 mbox[2] = cmdsub;
756 mbox[3] = cmdqual;
757
758 /* can't assume that interrupts are going to work here, so play it safe */
759 if (sc->amr_poll_command(ac))
760 goto out;
761 error = ac->ac_status;
762
763 out:
764 if (ac != NULL)
765 amr_releasecmd(ac);
766 if ((error != 0) && (result != NULL)) {
767 free(result, M_DEVBUF);
768 result = NULL;
769 }
770 return(result);
771}
772
773/********************************************************************************
774 * Flush the controller's internal cache, return status.
775 */
776int
777amr_flush(struct amr_softc *sc)
778{
779 struct amr_command *ac;
780 int error;
781
782 /* get ourselves a command buffer */
783 error = 1;
784 mtx_lock(&sc->amr_io_lock);
785 if ((ac = amr_alloccmd(sc)) == NULL)
786 goto out;
787 /* set command flags */
788 ac->ac_flags |= AMR_CMD_PRIORITY | AMR_CMD_DATAOUT;
789
790 /* build the command proper */
791 ac->ac_mailbox.mb_command = AMR_CMD_FLUSH;
792
793 /* we have to poll, as the system may be going down or otherwise damaged */
794 if (sc->amr_poll_command(ac))
795 goto out;
796 error = ac->ac_status;
797
798 out:
799 if (ac != NULL)
800 amr_releasecmd(ac);
801 mtx_unlock(&sc->amr_io_lock);
802 return(error);
803}
804
805/********************************************************************************
806 * Detect extented cdb >> greater than 10 byte cdb support
807 * returns '1' means this support exist
808 * returns '0' means this support doesn't exist
809 */
810static int
811amr_support_ext_cdb(struct amr_softc *sc)
812{
813 struct amr_command *ac;
814 u_int8_t *mbox;
815 int error;
816
817 /* get ourselves a command buffer */
818 error = 0;
819 if ((ac = amr_alloccmd(sc)) == NULL)
820 goto out;
821 /* set command flags */
822 ac->ac_flags |= AMR_CMD_PRIORITY | AMR_CMD_DATAOUT;
823
824 /* build the command proper */
825 mbox = (u_int8_t *)&ac->ac_mailbox; /* XXX want a real structure for this? */
826 mbox[0] = 0xA4;
827 mbox[2] = 0x16;
828
829
830 /* we have to poll, as the system may be going down or otherwise damaged */
831 if (sc->amr_poll_command(ac))
832 goto out;
833 if( ac->ac_status == AMR_STATUS_SUCCESS ) {
834 error = 1;
835 }
836
837out:
838 if (ac != NULL)
839 amr_releasecmd(ac);
840 return(error);
841}
842
843/********************************************************************************
844 * Try to find I/O work for the controller from one or more of the work queues.
845 *
846 * We make the assumption that if the controller is not ready to take a command
847 * at some given time, it will generate an interrupt at some later time when

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

886}
887
888/********************************************************************************
889 * Handle completion of an I/O command.
890 */
891static void
892amr_completeio(struct amr_command *ac)
893{
894 struct amrd_softc *sc = ac->ac_bio->bio_disk->d_drv1;
895
896 if (ac->ac_status != AMR_STATUS_SUCCESS) { /* could be more verbose here? */
897 ac->ac_bio->bio_error = EIO;
898 ac->ac_bio->bio_flags |= BIO_ERROR;
899
900 device_printf(sc->amrd_dev, "I/O error - 0x%x\n", ac->ac_status);
901/* amr_printcommand(ac);*/
902 }
903 amrd_intr(ac->ac_bio);
904 amr_releasecmd(ac);
905}
906
907/********************************************************************************
908 ********************************************************************************
909 Command Processing
910 ********************************************************************************
911 ********************************************************************************/
912

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

939
940 /* connect the bio to the command */
941 ac->ac_complete = amr_completeio;
942 ac->ac_bio = bio;
943 ac->ac_data = bio->bio_data;
944 ac->ac_length = bio->bio_bcount;
945 if (bio->bio_cmd == BIO_READ) {
946 ac->ac_flags |= AMR_CMD_DATAIN;
947 cmd = AMR_CMD_LREAD;
948 } else {
949 ac->ac_flags |= AMR_CMD_DATAOUT;
950 cmd = AMR_CMD_LWRITE;
951 }
952 amrd = (struct amrd_softc *)bio->bio_disk->d_drv1;
953 driveno = amrd->amrd_drive - sc->amr_drive;
954 blkcount = (bio->bio_bcount + AMR_BLKSIZE - 1) / AMR_BLKSIZE;
955
956 ac->ac_mailbox.mb_command = cmd;
957 ac->ac_mailbox.mb_blkcount = blkcount;
958 ac->ac_mailbox.mb_lba = bio->bio_pblkno;
959 ac->ac_mailbox.mb_drive = driveno;
960 /* we fill in the s/g related data when the command is mapped */
961
962 if ((bio->bio_pblkno + blkcount) > sc->amr_drive[driveno].al_size)
963 device_printf(sc->amr_dev, "I/O beyond end of unit (%lld,%d > %lu)\n",
964 (long long)bio->bio_pblkno, blkcount,
965 (u_long)sc->amr_drive[driveno].al_size);
966
967 *acp = ac;

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

976amr_wait_command(struct amr_command *ac)
977{
978 int error = 0;
979
980 debug_called(1);
981
982 ac->ac_complete = NULL;
983 ac->ac_flags |= AMR_CMD_SLEEP;
984 if ((error = amr_start(ac)) != 0)
985 return(error);
986
987 while ((ac->ac_flags & AMR_CMD_BUSY) && (error != EWOULDBLOCK)) {
988 error = msleep(ac, &ac->ac_sc->amr_io_lock, PRIBIO, "amrwcmd", 0);
989 }
990 return(error);
991}
992
993/********************************************************************************
994 * Take a command, submit it to the controller and busy-wait for it to return.
995 * Returns nonzero on error. Can be safely called with interrupts enabled.
996 */

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

1025 return(error);
1026}
1027
1028static void
1029amr_setup_polled_dmamap(void *arg, bus_dma_segment_t *segs, int nsegs, int err)
1030{
1031 struct amr_command *ac = arg;
1032 struct amr_softc *sc = ac->ac_sc;
1033
1034 amr_setup_dmamap(arg, segs, nsegs, err);
1035 if (ac->ac_flags & AMR_CMD_DATAIN) {
1036 bus_dmamap_sync(sc->amr_buffer_dmat,ac->ac_dmamap,
1037 BUS_DMASYNC_PREREAD);
1038 }
1039 if (ac->ac_flags & AMR_CMD_DATAOUT) {
1040 bus_dmamap_sync(sc->amr_buffer_dmat,ac->ac_dmamap,
1041 BUS_DMASYNC_PREWRITE);
1042 }
1043 sc->amr_poll_command1(sc, ac);
1044}
1045
1046/********************************************************************************
1047 * Take a command, submit it to the controller and busy-wait for it to return.
1048 * Returns nonzero on error. Can be safely called with interrupts enabled.
1049 */
1050static int
1051amr_quartz_poll_command(struct amr_command *ac)
1052{
1053 struct amr_softc *sc = ac->ac_sc;
1054 int error;
1055
1056 debug_called(2);
1057
1058 error = 0;
1059
1060 /* now we have a slot, we can map the command (unmapped in amr_complete) */
1061 if (ac->ac_data != 0) {
1062 if (bus_dmamap_load(sc->amr_buffer_dmat, ac->ac_dmamap, ac->ac_data,
1063 ac->ac_length, amr_setup_polled_dmamap, ac, BUS_DMA_NOWAIT) != 0) {
1064 error = 1;
1065 }
1066 } else {
1067 error = amr_quartz_poll_command1(sc, ac);
1068 }
1069
1070 return (error);
1071}
1072
1073static int
1074amr_quartz_poll_command1(struct amr_softc *sc, struct amr_command *ac)
1075{
1076 int count, error;
1077
1078 if ((sc->amr_state & AMR_STATE_INTEN) == 0) {
1079 count=0;
1080 while (sc->amr_busyslots) {
1081 msleep(sc, &sc->amr_io_lock, PRIBIO | PCATCH, "amrpoll", hz);
1082 if(count++>10) {
1083 break;
1084 }
1085 }
1086
1087 if(sc->amr_busyslots) {
1088 device_printf(sc->amr_dev, "adapter is busy\n");
1089 if (ac->ac_data != NULL)
1090 bus_dmamap_unload(sc->amr_buffer_dmat, ac->ac_dmamap);
1091 ac->ac_status=0;
1092 return(1);
1093 }
1094 }
1095
1096 bcopy(&ac->ac_mailbox, (void *)(uintptr_t)(volatile void *)sc->amr_mailbox, AMR_MBOX_CMDSIZE);
1097
1098 /* clear the poll/ack fields in the mailbox */

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

1111 error = (ac->ac_status !=AMR_STATUS_SUCCESS) ? 1:0;
1112 while(sc->amr_mailbox->mb_poll != 0x77);
1113 sc->amr_mailbox->mb_poll = 0;
1114 sc->amr_mailbox->mb_ack = 0x77;
1115
1116 /* acknowledge that we have the commands */
1117 AMR_QPUT_IDB(sc, sc->amr_mailboxphys | AMR_QIDB_ACK);
1118 while(AMR_QGET_IDB(sc) & AMR_QIDB_ACK);
1119
1120 /* unmap the command's data buffer */
1121 if (ac->ac_flags & AMR_CMD_DATAIN) {
1122 bus_dmamap_sync(sc->amr_buffer_dmat,ac->ac_dmamap,
1123 BUS_DMASYNC_POSTREAD);
1124 }
1125 if (ac->ac_flags & AMR_CMD_DATAOUT) {
1126 bus_dmamap_sync(sc->amr_buffer_dmat,ac->ac_dmamap,
1127 BUS_DMASYNC_POSTWRITE);
1128 }
1129 bus_dmamap_unload(sc->amr_buffer_dmat, ac->ac_dmamap);
1130
1131 return(error);
1132}
1133
1134/********************************************************************************
1135 * Get a free command slot for a command if it doesn't already have one.
1136 *
1137 * May be safely called multiple times for a given command.
1138 */
1139static int
1140amr_getslot(struct amr_command *ac)
1141{
1142 struct amr_softc *sc = ac->ac_sc;
1143 int slot;
1144
1145 debug_called(3);
1146
1147 slot = ac->ac_slot;
1148 if (sc->amr_busycmd[slot] != NULL)
1149 panic("amr: slot %d busy?\n", slot);
1150
1151 sc->amr_busycmd[slot] = ac;
1152 sc->amr_busyslots++;
1153
1154 return (0);
1155}
1156
1157/********************************************************************************
1158 * Map/unmap (ac)'s data in the controller's addressable space as required.
1159 *
1160 * These functions may be safely called multiple times on a given command.
1161 */
1162static void
1163amr_setup_dmamap(void *arg, bus_dma_segment_t *segs, int nsegments, int error)
1164{
1165 struct amr_command *ac = (struct amr_command *)arg;
1166 struct amr_softc *sc = ac->ac_sc;
1167 struct amr_sgentry *sg;
1168 int i;
1169 u_int8_t *sgc;
1170
1171 debug_called(3);
1172
1173 /* get base address of s/g table */
1174 sg = sc->amr_sgtable + (ac->ac_slot * AMR_NSEG);
1175
1176 /* save data physical address */
1177 ac->ac_dataphys = segs[0].ds_addr;
1178
1179 /* for AMR_CMD_CONFIG the s/g count goes elsewhere */
1180 if (ac->ac_mailbox.mb_command == AMR_CMD_CONFIG) {
1181 sgc = &(((struct amr_mailbox_ioctl *)&ac->ac_mailbox)->mb_param);
1182 } else {
1183 sgc = &ac->ac_mailbox.mb_nsgelem;
1184 }
1185
1186 /* decide whether we need to populate the s/g table */
1187 if (nsegments < 2) {
1188 *sgc = 0;
1189 ac->ac_mailbox.mb_nsgelem = 0;
1190 ac->ac_mailbox.mb_physaddr = ac->ac_dataphys;
1191 } else {
1192 ac->ac_mailbox.mb_nsgelem = nsegments;
1193 *sgc = nsegments;
1194 ac->ac_mailbox.mb_physaddr = sc->amr_sgbusaddr +
1195 (ac->ac_slot * AMR_NSEG * sizeof(struct amr_sgentry));
1196 for (i = 0; i < nsegments; i++, sg++) {
1197 sg->sg_addr = segs[i].ds_addr;
1198 sg->sg_count = segs[i].ds_len;
1199 }
1200 }
1201
1202}
1203
1204static void
1205amr_setup_ccbmap(void *arg, bus_dma_segment_t *segs, int nsegments, int error)
1206{
1207 struct amr_command *ac = (struct amr_command *)arg;
1208 struct amr_softc *sc = ac->ac_sc;
1209 struct amr_sgentry *sg;
1210 struct amr_passthrough *ap = (struct amr_passthrough *)ac->ac_data;
1211 struct amr_ext_passthrough *aep = (struct amr_ext_passthrough *)ac->ac_data;
1212 int i;
1213
1214 /* get base address of s/g table */
1215 sg = sc->amr_sgtable + (ac->ac_slot * AMR_NSEG);
1216
1217 /* decide whether we need to populate the s/g table */
1218 if( ac->ac_mailbox.mb_command == AMR_CMD_EXTPASS ) {
1219 if (nsegments < 2) {
1220 aep->ap_no_sg_elements = 0;
1221 aep->ap_data_transfer_address = segs[0].ds_addr;
1222 } else {
1223 /* save s/g table information in passthrough */
1224 aep->ap_no_sg_elements = nsegments;
1225 aep->ap_data_transfer_address = sc->amr_sgbusaddr +
1226 (ac->ac_slot * AMR_NSEG * sizeof(struct amr_sgentry));
1227 /*
1228 * populate s/g table (overwrites previous call which mapped the
1229 * passthrough)
1230 */
1231 for (i = 0; i < nsegments; i++, sg++) {
1232 sg->sg_addr = segs[i].ds_addr;
1233 sg->sg_count = segs[i].ds_len;
1234 debug(3, " %d: 0x%x/%d", i, sg->sg_addr, sg->sg_count);
1235 }
1236 }
1237 debug(3, "slot %d %d segments at 0x%x, passthrough at 0x%x\n",
1238 ac->ac_slot, aep->ap_no_sg_elements, aep->ap_data_transfer_address,
1239 ac->ac_dataphys);
1240 } else {
1241 if (nsegments < 2) {
1242 ap->ap_no_sg_elements = 0;
1243 ap->ap_data_transfer_address = segs[0].ds_addr;
1244 } else {
1245 /* save s/g table information in passthrough */
1246 ap->ap_no_sg_elements = nsegments;
1247 ap->ap_data_transfer_address = sc->amr_sgbusaddr +
1248 (ac->ac_slot * AMR_NSEG * sizeof(struct amr_sgentry));
1249 /*
1250 * populate s/g table (overwrites previous call which mapped the
1251 * passthrough)
1252 */
1253 for (i = 0; i < nsegments; i++, sg++) {
1254 sg->sg_addr = segs[i].ds_addr;
1255 sg->sg_count = segs[i].ds_len;
1256 debug(3, " %d: 0x%x/%d", i, sg->sg_addr, sg->sg_count);
1257 }
1258 }
1259 debug(3, "slot %d %d segments at 0x%x, passthrough at 0x%x",
1260 ac->ac_slot, ap->ap_no_sg_elements, ap->ap_data_transfer_address,
1261 ac->ac_dataphys);
1262 }
1263 if (ac->ac_flags & AMR_CMD_CCB_DATAIN)
1264 bus_dmamap_sync(sc->amr_buffer_dmat, ac->ac_ccb_dmamap,
1265 BUS_DMASYNC_PREREAD);
1266 if (ac->ac_flags & AMR_CMD_CCB_DATAOUT)
1267 bus_dmamap_sync(sc->amr_buffer_dmat, ac->ac_ccb_dmamap,
1268 BUS_DMASYNC_PREWRITE);
1269 if ((ac->ac_flags & (AMR_CMD_CCB_DATAIN | AMR_CMD_CCB_DATAOUT)) == 0)
1270 panic("no direction for ccb?\n");
1271
1272 if (ac->ac_flags & AMR_CMD_DATAIN)
1273 bus_dmamap_sync(sc->amr_buffer_dmat,ac->ac_dmamap,BUS_DMASYNC_PREREAD);
1274 if (ac->ac_flags & AMR_CMD_DATAOUT)
1275 bus_dmamap_sync(sc->amr_buffer_dmat,ac->ac_dmamap,BUS_DMASYNC_PREWRITE);
1276
1277 ac->ac_flags |= AMR_CMD_MAPPED;
1278
1279 amr_start1(sc, ac);
1280}
1281
1282static int
1283amr_mapcmd(struct amr_command *ac)
1284{
1285 struct amr_softc *sc = ac->ac_sc;
1286
1287 debug_called(3);
1288
1289 /* if the command involves data at all, and hasn't been mapped */
1290 if ((ac->ac_flags & AMR_CMD_MAPPED) == 0 && (ac->ac_data != NULL)) {
1291 if (ac->ac_ccb_data == NULL) {
1292 /* map the data buffers into bus space and build the s/g list */
1293 if (bus_dmamap_load(sc->amr_buffer_dmat, ac->ac_dmamap, ac->ac_data,
1294 ac->ac_length, amr_setup_data_dmamap, ac, 0) == EINPROGRESS) {
1295 sc->amr_state |= AMR_STATE_QUEUE_FRZN;
1296 }
1297 } else {
1298 if (bus_dmamap_load(sc->amr_buffer_dmat, ac->ac_dmamap, ac->ac_data,
1299 ac->ac_length, amr_setup_dmamap, ac, BUS_DMA_NOWAIT) != 0){
1300 return (ENOMEM);
1301 }
1302 if (bus_dmamap_load(sc->amr_buffer_dmat, ac->ac_ccb_dmamap,
1303 ac->ac_ccb_data, ac->ac_ccb_length, amr_setup_ccbmap, ac,
1304 0) == EINPROGRESS) {
1305 sc->amr_state |= AMR_STATE_QUEUE_FRZN;
1306 }
1307 }
1308 } else if ((ac->ac_flags & AMR_CMD_MAPPED) == 0) {
1309 amr_start1(sc, ac);
1310 }
1311
1312 return (0);
1313}
1314
1315static void
1316amr_unmapcmd(struct amr_command *ac)
1317{
1318 struct amr_softc *sc = ac->ac_sc;
1319
1320 debug_called(3);
1321
1322 /* if the command involved data at all and was mapped */
1323 if (ac->ac_flags & AMR_CMD_MAPPED) {
1324
1325 if (ac->ac_data != NULL) {
1326 if (ac->ac_flags & AMR_CMD_DATAIN)
1327 bus_dmamap_sync(sc->amr_buffer_dmat, ac->ac_dmamap,
1328 BUS_DMASYNC_POSTREAD);
1329 if (ac->ac_flags & AMR_CMD_DATAOUT)
1330 bus_dmamap_sync(sc->amr_buffer_dmat, ac->ac_dmamap,
1331 BUS_DMASYNC_POSTWRITE);
1332 bus_dmamap_unload(sc->amr_buffer_dmat, ac->ac_dmamap);
1333 }
1334
1335 if (ac->ac_ccb_data != NULL) {
1336 if (ac->ac_flags & AMR_CMD_CCB_DATAIN)
1337 bus_dmamap_sync(sc->amr_buffer_dmat, ac->ac_ccb_dmamap,
1338 BUS_DMASYNC_POSTREAD);
1339 if (ac->ac_flags & AMR_CMD_CCB_DATAOUT)
1340 bus_dmamap_sync(sc->amr_buffer_dmat, ac->ac_ccb_dmamap,
1341 BUS_DMASYNC_POSTWRITE);
1342 bus_dmamap_unload(sc->amr_buffer_dmat, ac->ac_ccb_dmamap);
1343 }
1344 ac->ac_flags &= ~AMR_CMD_MAPPED;
1345 }
1346}
1347
1348static void
1349amr_setup_data_dmamap(void *arg, bus_dma_segment_t *segs, int nsegs, int err)
1350{
1351 struct amr_command *ac = arg;
1352 struct amr_softc *sc = ac->ac_sc;
1353
1354 amr_setup_dmamap(arg, segs, nsegs, err);
1355
1356 if (ac->ac_flags & AMR_CMD_DATAIN)
1357 bus_dmamap_sync(sc->amr_buffer_dmat,ac->ac_dmamap,BUS_DMASYNC_PREREAD);
1358 if (ac->ac_flags & AMR_CMD_DATAOUT)
1359 bus_dmamap_sync(sc->amr_buffer_dmat,ac->ac_dmamap,BUS_DMASYNC_PREWRITE);
1360 ac->ac_flags |= AMR_CMD_MAPPED;
1361
1362 amr_start1(sc, ac);
1363}
1364
1365/********************************************************************************
1366 * Take a command and give it to the controller, returns 0 if successful, or
1367 * EBUSY if the command should be retried later.
1368 */
1369static int
1370amr_start(struct amr_command *ac)
1371{
1372 struct amr_softc *sc;
1373 int error = 0;
1374
1375 debug_called(3);
1376
1377 /* mark command as busy so that polling consumer can tell */
1378 sc = ac->ac_sc;
1379 ac->ac_flags |= AMR_CMD_BUSY;
1380
1381 /* get a command slot (freed in amr_done) */
1382 if (amr_getslot(ac)) {
1383 return(EBUSY);
1384 }
1385
1386 /* Now we have a slot, we can map the command (unmapped in amr_complete). */
1387 if ((error = amr_mapcmd(ac)) == ENOMEM) {
1388 /*
1389 * Memroy resources are short, so free the slot and let this be tried
1390 * later.
1391 */
1392 sc->amr_busycmd[ac->ac_slot] = NULL;
1393 sc->amr_busyslots--;
1394 }
1395
1396 return (error);
1397}
1398
1399
1400static int
1401amr_start1(struct amr_softc *sc, struct amr_command *ac)
1402{
1403 int done, i;
1404
1405 /* mark the new mailbox we are going to copy in as busy */
1406 ac->ac_mailbox.mb_busy = 1;
1407
1408 /* clear the poll/ack fields in the mailbox */
1409 sc->amr_mailbox->mb_poll = 0;
1410 sc->amr_mailbox->mb_ack = 0;
1411
1412 /*
1413 * Save the slot number so that we can locate this command when complete.
1414 * Note that ident = 0 seems to be special, so we don't use it.
1415 */
1416 ac->ac_mailbox.mb_ident = ac->ac_slot + 1;
1417
1418 /*
1419 * Spin waiting for the mailbox, give up after ~1 second. We expect the
1420 * controller to be able to handle our I/O.
1421 *
1422 * XXX perhaps we should wait for less time, and count on the deferred command
1423 * handling to deal with retries?
1424 */
1425 debug(4, "wait for mailbox");
1426 for (i = 10000, done = 0; (i > 0) && !done; i--) {
1427
1428 /* is the mailbox free? */
1429 if (sc->amr_mailbox->mb_busy == 0) {
1430 debug(4, "got mailbox");
1431 sc->amr_mailbox64->mb64_segment = 0;
1432 bcopy(&ac->ac_mailbox, (void *)(uintptr_t)(volatile void *)sc->amr_mailbox, AMR_MBOX_CMDSIZE);
1433 done = 1;
1434
1435 /* not free, spin waiting */
1436 } else {
1437 debug(4, "busy flag %x\n", sc->amr_mailbox->mb_busy);
1438 /* this is somewhat ugly */
1439 DELAY(100);
1440 }
1441 }
1442
1443 /*
1444 * Now give the command to the controller
1445 */
1446 if (done) {
1447 if (sc->amr_submit_command(sc)) {
1448 /* the controller wasn't ready to take the command, forget that we tried to post it */
1449 sc->amr_mailbox->mb_busy = 0;
1450 return(EBUSY);
1451 }
1452 debug(3, "posted command");
1453 return(0);
1454 }
1455
1456 /*
1457 * The controller wouldn't take the command. Return the command as busy
1458 * so that it is retried later.
1459 */
1460 return(EBUSY);
1461}
1462
1463/********************************************************************************
1464 * Extract one or more completed commands from the controller (sc)
1465 *
1466 * Returns nonzero if any commands on the work queue were marked as completed.
1467 */
1468

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

1489 /* get pointer to busy command */
1490 idx = mbox.mb_completed[i] - 1;
1491 ac = sc->amr_busycmd[idx];
1492
1493 /* really a busy command? */
1494 if (ac != NULL) {
1495
1496 /* pull the command from the busy index */
1497 sc->amr_busycmd[idx] = NULL;
1498 sc->amr_busyslots--;
1499
1500 /* save status for later use */
1501 ac->ac_status = mbox.mb_status;
1502 amr_enqueue_completed(ac);
1503 debug(3, "completed command with status %x", mbox.mb_status);
1504 } else {
1505 device_printf(sc->amr_dev, "bad slot %d completed\n", idx);
1506 }
1507 }
1508 } else {
1509 break; /* no work */
1510 }
1511 }
1512
1513 /* handle completion and timeouts */
1514 amr_complete(sc, 0);
1515
1516 return(result);
1517}
1518

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

1553 wakeup(ac);
1554 }
1555
1556 if(!sc->amr_busyslots) {
1557 wakeup(sc);
1558 }
1559 }
1560
1561 sc->amr_state &= ~AMR_STATE_QUEUE_FRZN;
1562 amr_startio(sc);
1563}
1564
1565/********************************************************************************
1566 ********************************************************************************
1567 Command Buffer Management
1568 ********************************************************************************
1569 ********************************************************************************/
1570

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

1629 acc = malloc(AMR_CMD_CLUSTERSIZE, M_DEVBUF, M_NOWAIT | M_ZERO);
1630 if (acc != NULL) {
1631 nextslot = sc->amr_nextslot;
1632 TAILQ_INSERT_TAIL(&sc->amr_cmd_clusters, acc, acc_link);
1633 for (i = 0; i < AMR_CMD_CLUSTERCOUNT; i++) {
1634 ac = &acc->acc_command[i];
1635 ac->ac_sc = sc;
1636 ac->ac_slot = nextslot;
1637 if (!bus_dmamap_create(sc->amr_buffer_dmat, 0, &ac->ac_dmamap) &&
1638 !bus_dmamap_create(sc->amr_buffer_dmat, 0, &ac->ac_ccb_dmamap))
1639 amr_releasecmd(ac);
1640 if (++nextslot > sc->amr_maxio)
1641 break;
1642 }
1643 sc->amr_nextslot = nextslot;
1644 }
1645}
1646
1647/********************************************************************************
1648 * Free a command cluster
1649 */
1650static void
1651amr_freecmd_cluster(struct amr_command_cluster *acc)
1652{
1653 struct amr_softc *sc = acc->acc_command[0].ac_sc;
1654 int i;
1655
1656 for (i = 0; i < AMR_CMD_CLUSTERCOUNT; i++)
1657 bus_dmamap_destroy(sc->amr_buffer_dmat, acc->acc_command[i].ac_dmamap);
1658 free(acc, M_DEVBUF);
1659}
1660
1661/********************************************************************************
1662 ********************************************************************************
1663 Interface-specific Shims
1664 ********************************************************************************
1665 ********************************************************************************/
1666
1667/********************************************************************************
1668 * Tell the controller that the mailbox contains a valid command
1669 */
1670static int
1671amr_quartz_submit_command(struct amr_softc *sc)
1672{
1673 debug_called(3);
1674
1675 if (AMR_QGET_IDB(sc) & AMR_QIDB_SUBMIT)
1676 return(EBUSY);
1677 AMR_QPUT_IDB(sc, sc->amr_mailboxphys | AMR_QIDB_SUBMIT);
1678 return(0);
1679}
1680
1681static int
1682amr_std_submit_command(struct amr_softc *sc)
1683{
1684 debug_called(3);

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

1691
1692/********************************************************************************
1693 * Claim any work that the controller has completed; acknowledge completion,
1694 * save details of the completion in (mbsave)
1695 */
1696static int
1697amr_quartz_get_work(struct amr_softc *sc, struct amr_mailbox *mbsave)
1698{
1699 int worked;
1700 u_int32_t outd;
1701 u_int8_t nstatus;
1702
1703 debug_called(3);
1704
1705 worked = 0;
1706
1707 /* work waiting for us? */
1708 if ((outd = AMR_QGET_ODB(sc)) == AMR_QODB_READY) {
1709
1710 /* acknowledge interrupt */
1711 AMR_QPUT_ODB(sc, AMR_QODB_READY);
1712
1713 while ((nstatus = sc->amr_mailbox->mb_nstatus) == 0xff)
1714 ;
1715 sc->amr_mailbox->mb_nstatus = 0xff;
1716
1717 /* save mailbox, which contains a list of completed commands */
1718 bcopy((void *)(uintptr_t)(volatile void *)sc->amr_mailbox, mbsave, sizeof(*mbsave));
1719 mbsave->mb_nstatus = nstatus;
1720
1721 /* acknowledge that we have the commands */
1722 AMR_QPUT_IDB(sc, AMR_QIDB_ACK);
1723
1724#ifndef AMR_QUARTZ_GOFASTER
1725 /*
1726 * This waits for the controller to notice that we've taken the
1727 * command from it. It's very inefficient, and we shouldn't do it,
1728 * but if we remove this code, we stop completing commands under
1729 * load.
1730 *
1731 * Peter J says we shouldn't do this. The documentation says we
1732 * should. Who is right?
1733 */
1734 while(AMR_QGET_IDB(sc) & AMR_QIDB_ACK)
1735 ; /* XXX aiee! what if it dies? */
1736#endif
1737
1738 worked = 1; /* got some work */
1739 }
1740
1741 return(worked);
1742}
1743
1744static int

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

1854 * Identify the controller and print some information about it.
1855 */
1856static void
1857amr_describe_controller(struct amr_softc *sc)
1858{
1859 struct amr_prodinfo *ap;
1860 struct amr_enquiry *ae;
1861 char *prod;
1862
1863 mtx_lock(&sc->amr_io_lock);
1864 /*
1865 * Try to get 40LD product info, which tells us what the card is labelled as.
1866 */
1867 if ((ap = amr_enquiry(sc, 2048, AMR_CMD_CONFIG, AMR_CONFIG_PRODUCT_INFO, 0)) != NULL) {
1868 device_printf(sc->amr_dev, "<LSILogic %.80s> Firmware %.16s, BIOS %.16s, %dMB RAM\n",
1869 ap->ap_product, ap->ap_firmware, ap->ap_bios,
1870 ap->ap_memsize);
1871
1872 free(ap, M_DEVBUF);
1873 mtx_unlock(&sc->amr_io_lock);
1874 return;
1875 }
1876
1877 /*
1878 * Try 8LD extended ENQUIRY to get controller signature, and use lookup table.
1879 */
1880 if ((ae = (struct amr_enquiry *)amr_enquiry(sc, 2048, AMR_CMD_EXT_ENQUIRY2, 0, 0)) != NULL) {
1881 prod = amr_describe_code(amr_table_adaptertype, ae->ae_signature);
1882
1883 } else if ((ae = (struct amr_enquiry *)amr_enquiry(sc, 2048, AMR_CMD_ENQUIRY, 0, 0)) != NULL) {
1884
1885 /*
1886 * Try to work it out based on the PCI signatures.
1887 */
1888 switch (pci_get_device(sc->amr_dev)) {
1889 case 0x9010:
1890 prod = "Series 428";
1891 break;
1892 case 0x9060:
1893 prod = "Series 434";
1894 break;
1895 default:
1896 prod = "unknown controller";
1897 break;
1898 }
1899 } else {
1900 device_printf(sc->amr_dev, "<unsupported controller>\n");
1901 mtx_unlock(&sc->amr_io_lock);
1902 return;
1903 }
1904
1905 /*
1906 * HP NetRaid controllers have a special encoding of the firmware and
1907 * BIOS versions. The AMI version seems to have it as strings whereas
1908 * the HP version does it with a leading uppercase character and two
1909 * binary numbers.

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

1934 ae->ae_adapter.aa_bios[0],
1935 ae->ae_adapter.aa_memorysize);
1936 } else {
1937 device_printf(sc->amr_dev, "<%s> Firmware %.4s, BIOS %.4s, %dMB RAM\n",
1938 prod, ae->ae_adapter.aa_firmware, ae->ae_adapter.aa_bios,
1939 ae->ae_adapter.aa_memorysize);
1940 }
1941 free(ae, M_DEVBUF);
1942 mtx_unlock(&sc->amr_io_lock);
1943}
1944
1945int
1946amr_dump_blocks(struct amr_softc *sc, int unit, u_int32_t lba, void *data, int blks)
1947{
1948 struct amr_command *ac;
1949 int error = EIO;
1950

--- 63 unchanged lines hidden ---