amr.c (58934) | amr.c (59249) |
---|---|
1/*- 2 * Copyright (c) 1999 Michael Smith 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * | 1/*- 2 * Copyright (c) 1999 Michael Smith 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * |
26 * $FreeBSD: head/sys/dev/amr/amr.c 58934 2000-04-02 15:24:56Z phk $ | 26 * $FreeBSD: head/sys/dev/amr/amr.c 59249 2000-04-15 05:54:02Z phk $ |
27 */ 28 29/* 30 * Driver for the AMI MegaRaid family of controllers 31 */ 32 33#include <sys/param.h> 34#include <sys/systm.h> --- 297 unchanged lines hidden (view full) --- 332{ 333 int rid, error; 334 335 /* 336 * Initialise per-controller queues. 337 */ 338 TAILQ_INIT(&sc->amr_work); 339 TAILQ_INIT(&sc->amr_freecmds); | 27 */ 28 29/* 30 * Driver for the AMI MegaRaid family of controllers 31 */ 32 33#include <sys/param.h> 34#include <sys/systm.h> --- 297 unchanged lines hidden (view full) --- 332{ 333 int rid, error; 334 335 /* 336 * Initialise per-controller queues. 337 */ 338 TAILQ_INIT(&sc->amr_work); 339 TAILQ_INIT(&sc->amr_freecmds); |
340 bufq_init(&sc->amr_bufq); | 340 bioq_init(&sc->amr_bioq); |
341 342 /* 343 * Configure for this controller type. 344 */ 345 if (sc->amr_type == AMR_TYPE_QUARTZ) { 346 sc->amr_submit_command = amr_quartz_submit_command; 347 sc->amr_get_work = amr_quartz_get_work; 348 sc->amr_attach_mailbox = amr_quartz_attach_mailbox; --- 149 unchanged lines hidden (view full) --- 498 499/******************************************************************************** 500 * Bring the controller down to a dormant state and detach all child devices. 501 * 502 * This function is called before detach, system shutdown, or before performing 503 * an operation which may add or delete system disks. (Call amr_startup to 504 * resume normal operation.) 505 * | 341 342 /* 343 * Configure for this controller type. 344 */ 345 if (sc->amr_type == AMR_TYPE_QUARTZ) { 346 sc->amr_submit_command = amr_quartz_submit_command; 347 sc->amr_get_work = amr_quartz_get_work; 348 sc->amr_attach_mailbox = amr_quartz_attach_mailbox; --- 149 unchanged lines hidden (view full) --- 498 499/******************************************************************************** 500 * Bring the controller down to a dormant state and detach all child devices. 501 * 502 * This function is called before detach, system shutdown, or before performing 503 * an operation which may add or delete system disks. (Call amr_startup to 504 * resume normal operation.) 505 * |
506 * Note that we can assume that the bufq on the controller is empty, as we won't | 506 * Note that we can assume that the bioq on the controller is empty, as we won't |
507 * allow shutdown if any device is open. 508 */ 509int 510amr_shutdown(device_t dev) 511{ 512 struct amr_softc *sc = device_get_softc(dev); 513 struct amrd_softc *ad; 514 int i, s, error; --- 88 unchanged lines hidden (view full) --- 603 amr_done(sc); 604}; 605 606/******************************************************************************* 607 * Receive a buf structure from a child device and queue it on a particular 608 * disk resource, then poke the disk resource to start as much work as it can. 609 */ 610int | 507 * allow shutdown if any device is open. 508 */ 509int 510amr_shutdown(device_t dev) 511{ 512 struct amr_softc *sc = device_get_softc(dev); 513 struct amrd_softc *ad; 514 int i, s, error; --- 88 unchanged lines hidden (view full) --- 603 amr_done(sc); 604}; 605 606/******************************************************************************* 607 * Receive a buf structure from a child device and queue it on a particular 608 * disk resource, then poke the disk resource to start as much work as it can. 609 */ 610int |
611amr_submit_buf(struct amr_softc *sc, struct buf *bp) | 611amr_submit_buf(struct amr_softc *sc, struct bio *bp) |
612{ 613 int s; 614 615 debug("called"); 616 617 s = splbio(); | 612{ 613 int s; 614 615 debug("called"); 616 617 s = splbio(); |
618 bufq_insert_tail(&sc->amr_bufq, bp); | 618 bioq_insert_tail(&sc->amr_bioq, bp); |
619 splx(s); 620 sc->amr_waitbufs++; 621 amr_startio(sc); 622 return(0); 623} 624 625/******************************************************************************** 626 * Accept an open operation on the control device. --- 252 unchanged lines hidden (view full) --- 879 * 880 * We avoid running at splbio() whenever possible. 881 */ 882static void 883amr_startio(struct amr_softc *sc) 884{ 885 struct amr_command *ac; 886 struct amrd_softc *amrd; | 619 splx(s); 620 sc->amr_waitbufs++; 621 amr_startio(sc); 622 return(0); 623} 624 625/******************************************************************************** 626 * Accept an open operation on the control device. --- 252 unchanged lines hidden (view full) --- 879 * 880 * We avoid running at splbio() whenever possible. 881 */ 882static void 883amr_startio(struct amr_softc *sc) 884{ 885 struct amr_command *ac; 886 struct amrd_softc *amrd; |
887 struct buf *bp; | 887 struct bio *bp; |
888 int blkcount; 889 int driveno; 890 int cmd; 891 int s; 892 893 /* avoid reentrancy */ 894 if (amr_lock_tas(sc, AMR_LOCK_STARTING)) 895 return; 896 897 /* spin until something prevents us from doing any work */ 898 s = splbio(); 899 for (;;) { 900 901 /* see if there's work to be done */ | 888 int blkcount; 889 int driveno; 890 int cmd; 891 int s; 892 893 /* avoid reentrancy */ 894 if (amr_lock_tas(sc, AMR_LOCK_STARTING)) 895 return; 896 897 /* spin until something prevents us from doing any work */ 898 s = splbio(); 899 for (;;) { 900 901 /* see if there's work to be done */ |
902 if ((bp = bufq_first(&sc->amr_bufq)) == NULL) | 902 if ((bp = bioq_first(&sc->amr_bioq)) == NULL) |
903 break; 904 /* get a command */ 905 if ((ac = amr_alloccmd(sc)) == NULL) 906 break; 907 /* get a slot for the command */ 908 if (amr_getslot(ac) != 0) { 909 amr_releasecmd(ac); 910 break; 911 } 912 /* get the buf containing our work */ | 903 break; 904 /* get a command */ 905 if ((ac = amr_alloccmd(sc)) == NULL) 906 break; 907 /* get a slot for the command */ 908 if (amr_getslot(ac) != 0) { 909 amr_releasecmd(ac); 910 break; 911 } 912 /* get the buf containing our work */ |
913 bufq_remove(&sc->amr_bufq, bp); | 913 bioq_remove(&sc->amr_bioq, bp); |
914 sc->amr_waitbufs--; 915 splx(s); 916 917 /* connect the buf to the command */ 918 ac->ac_complete = amr_completeio; 919 ac->ac_private = bp; | 914 sc->amr_waitbufs--; 915 splx(s); 916 917 /* connect the buf to the command */ 918 ac->ac_complete = amr_completeio; 919 ac->ac_private = bp; |
920 ac->ac_data = bp->b_data; 921 ac->ac_length = bp->b_bcount; 922 if (bp->b_iocmd == BIO_READ) { | 920 ac->ac_data = bp->bio_data; 921 ac->ac_length = bp->bio_bcount; 922 if (bp->bio_cmd == BIO_READ) { |
923 ac->ac_flags |= AMR_CMD_DATAIN; 924 cmd = AMR_CMD_LREAD; 925 } else { 926 ac->ac_flags |= AMR_CMD_DATAOUT; 927 cmd = AMR_CMD_LWRITE; 928 } 929 930 /* map the command so the controller can work with it */ 931 amr_mapcmd(ac); 932 933 /* build a suitable I/O command (assumes 512-byte rounded transfers) */ | 923 ac->ac_flags |= AMR_CMD_DATAIN; 924 cmd = AMR_CMD_LREAD; 925 } else { 926 ac->ac_flags |= AMR_CMD_DATAOUT; 927 cmd = AMR_CMD_LWRITE; 928 } 929 930 /* map the command so the controller can work with it */ 931 amr_mapcmd(ac); 932 933 /* build a suitable I/O command (assumes 512-byte rounded transfers) */ |
934 amrd = (struct amrd_softc *)bp->b_dev->si_drv1; | 934 amrd = (struct amrd_softc *)bp->bio_dev->si_drv1; |
935 driveno = amrd->amrd_drive - sc->amr_drive; | 935 driveno = amrd->amrd_drive - sc->amr_drive; |
936 blkcount = (bp->b_bcount + AMR_BLKSIZE - 1) / AMR_BLKSIZE; | 936 blkcount = (bp->bio_bcount + AMR_BLKSIZE - 1) / AMR_BLKSIZE; |
937 | 937 |
938 if ((bp->b_pblkno + blkcount) > sc->amr_drive[driveno].al_size) | 938 if ((bp->bio_pblkno + blkcount) > sc->amr_drive[driveno].al_size) |
939 device_printf(sc->amr_dev, "I/O beyond end of unit (%u,%d > %u)\n", | 939 device_printf(sc->amr_dev, "I/O beyond end of unit (%u,%d > %u)\n", |
940 bp->b_pblkno, blkcount, sc->amr_drive[driveno].al_size); | 940 bp->bio_pblkno, blkcount, sc->amr_drive[driveno].al_size); |
941 942 /* 943 * Build the I/O command. 944 */ 945 ac->ac_mailbox.mb_command = cmd; 946 ac->ac_mailbox.mb_blkcount = blkcount; | 941 942 /* 943 * Build the I/O command. 944 */ 945 ac->ac_mailbox.mb_command = cmd; 946 ac->ac_mailbox.mb_blkcount = blkcount; |
947 ac->ac_mailbox.mb_lba = bp->b_pblkno; | 947 ac->ac_mailbox.mb_lba = bp->bio_pblkno; |
948 ac->ac_mailbox.mb_physaddr = ac->ac_sgphys; 949 ac->ac_mailbox.mb_drive = driveno; 950 ac->ac_mailbox.mb_nsgelem = ac->ac_nsgent; 951 952 /* try to give command to controller */ 953 if (amr_start(ac) != 0) { 954 /* fail the command */ 955 ac->ac_status = AMR_STATUS_WEDGED; --- 7 unchanged lines hidden (view full) --- 963 964/******************************************************************************** 965 * Handle completion of an I/O command. 966 */ 967static void 968amr_completeio(struct amr_command *ac) 969{ 970 struct amr_softc *sc = ac->ac_sc; | 948 ac->ac_mailbox.mb_physaddr = ac->ac_sgphys; 949 ac->ac_mailbox.mb_drive = driveno; 950 ac->ac_mailbox.mb_nsgelem = ac->ac_nsgent; 951 952 /* try to give command to controller */ 953 if (amr_start(ac) != 0) { 954 /* fail the command */ 955 ac->ac_status = AMR_STATUS_WEDGED; --- 7 unchanged lines hidden (view full) --- 963 964/******************************************************************************** 965 * Handle completion of an I/O command. 966 */ 967static void 968amr_completeio(struct amr_command *ac) 969{ 970 struct amr_softc *sc = ac->ac_sc; |
971 struct buf *bp = (struct buf *)ac->ac_private; | 971 struct bio *bp = (struct bio *)ac->ac_private; |
972 int notify, release; 973 974 notify = 1; 975 release = 1; 976 977 if (ac->ac_status != AMR_STATUS_SUCCESS) { /* could be more verbose here? */ | 972 int notify, release; 973 974 notify = 1; 975 release = 1; 976 977 if (ac->ac_status != AMR_STATUS_SUCCESS) { /* could be more verbose here? */ |
978 bp->b_error = EIO; 979 bp->b_ioflags |= BIO_ERROR; | 978 bp->bio_error = EIO; 979 bp->bio_flags |= BIO_ERROR; |
980 981 switch(ac->ac_status) { 982 /* XXX need more information on I/O error reasons */ 983 case AMR_STATUS_LATE: 984 notify = 0; /* we've already notified the parent */ 985 break; 986 987 case AMR_STATUS_WEDGED: --- 642 unchanged lines hidden --- | 980 981 switch(ac->ac_status) { 982 /* XXX need more information on I/O error reasons */ 983 case AMR_STATUS_LATE: 984 notify = 0; /* we've already notified the parent */ 985 break; 986 987 case AMR_STATUS_WEDGED: --- 642 unchanged lines hidden --- |