amr.c (157585) | amr.c (157586) |
---|---|
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> | 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 157585 2006-04-08 02:23:27Z ps $"); | 59__FBSDID("$FreeBSD: head/sys/dev/amr/amr.c 157586 2006-04-08 05:08:17Z 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> --- 310 unchanged lines hidden (view full) --- 378 if( sc->amr_dev_t != (struct cdev *)NULL) 379 destroy_dev(sc->amr_dev_t); 380 381 if (mtx_initialized(&sc->amr_hw_lock)) 382 mtx_destroy(&sc->amr_hw_lock); 383 384 if (mtx_initialized(&sc->amr_list_lock)) 385 mtx_destroy(&sc->amr_list_lock); | 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> --- 310 unchanged lines hidden (view full) --- 378 if( sc->amr_dev_t != (struct cdev *)NULL) 379 destroy_dev(sc->amr_dev_t); 380 381 if (mtx_initialized(&sc->amr_hw_lock)) 382 mtx_destroy(&sc->amr_hw_lock); 383 384 if (mtx_initialized(&sc->amr_list_lock)) 385 mtx_destroy(&sc->amr_list_lock); |
386 387 if (mtx_initialized(&sc->amr_wait_lock)) 388 mtx_destroy(&sc->amr_wait_lock); | |
389} 390 391/******************************************************************************* 392 * Receive a bio structure from a child device and queue it on a particular 393 * disk resource, then poke the disk resource to start as much work as it can. 394 */ 395int 396amr_submit_bio(struct amr_softc *sc, struct bio *bio) --- 199 unchanged lines hidden (view full) --- 596 dp, ap->ap_data_transfer_length); 597 if (error) 598 break; 599 } 600 601 mtx_lock(&sc->amr_list_lock); 602 while ((ac = amr_alloccmd(sc)) == NULL) 603 msleep(sc, &sc->amr_list_lock, PPAUSE, "amrioc", hz); | 386} 387 388/******************************************************************************* 389 * Receive a bio structure from a child device and queue it on a particular 390 * disk resource, then poke the disk resource to start as much work as it can. 391 */ 392int 393amr_submit_bio(struct amr_softc *sc, struct bio *bio) --- 199 unchanged lines hidden (view full) --- 593 dp, ap->ap_data_transfer_length); 594 if (error) 595 break; 596 } 597 598 mtx_lock(&sc->amr_list_lock); 599 while ((ac = amr_alloccmd(sc)) == NULL) 600 msleep(sc, &sc->amr_list_lock, PPAUSE, "amrioc", hz); |
604 mtx_unlock(&sc->amr_list_lock); | |
605 606 ac_flags = AMR_CMD_DATAIN|AMR_CMD_DATAOUT|AMR_CMD_CCB_DATAIN|AMR_CMD_CCB_DATAOUT; 607 bzero(&ac->ac_mailbox, sizeof(ac->ac_mailbox)); 608 ac->ac_mailbox.mb_command = AMR_CMD_PASS; 609 ac->ac_flags = ac_flags; 610 611 ac->ac_data = ap; 612 ac->ac_length = sizeof(struct amr_passthrough); 613 ac->ac_ccb_data = dp; 614 ac->ac_ccb_length = ap->ap_data_transfer_length; 615 temp = (void *)(uintptr_t)ap->ap_data_transfer_address; 616 617 error = amr_wait_command(ac); | 601 602 ac_flags = AMR_CMD_DATAIN|AMR_CMD_DATAOUT|AMR_CMD_CCB_DATAIN|AMR_CMD_CCB_DATAOUT; 603 bzero(&ac->ac_mailbox, sizeof(ac->ac_mailbox)); 604 ac->ac_mailbox.mb_command = AMR_CMD_PASS; 605 ac->ac_flags = ac_flags; 606 607 ac->ac_data = ap; 608 ac->ac_length = sizeof(struct amr_passthrough); 609 ac->ac_ccb_data = dp; 610 ac->ac_ccb_length = ap->ap_data_transfer_length; 611 temp = (void *)(uintptr_t)ap->ap_data_transfer_address; 612 613 error = amr_wait_command(ac); |
614 mtx_unlock(&sc->amr_list_lock); |
|
618 if (error) 619 break; 620 621 status = ac->ac_status; 622 error = copyout(&status, &((struct amr_passthrough *)(uintptr_t)mb->mb_physaddr)->ap_scsi_status, sizeof(status)); 623 if (error) 624 break; 625 --- 24 unchanged lines hidden (view full) --- 650 error = copyin((void *)(uintptr_t)mb->mb_physaddr, dp, len); 651 if (error) 652 break; 653 } 654 655 mtx_lock(&sc->amr_list_lock); 656 while ((ac = amr_alloccmd(sc)) == NULL) 657 msleep(sc, &sc->amr_list_lock, PPAUSE, "amrioc", hz); | 615 if (error) 616 break; 617 618 status = ac->ac_status; 619 error = copyout(&status, &((struct amr_passthrough *)(uintptr_t)mb->mb_physaddr)->ap_scsi_status, sizeof(status)); 620 if (error) 621 break; 622 --- 24 unchanged lines hidden (view full) --- 647 error = copyin((void *)(uintptr_t)mb->mb_physaddr, dp, len); 648 if (error) 649 break; 650 } 651 652 mtx_lock(&sc->amr_list_lock); 653 while ((ac = amr_alloccmd(sc)) == NULL) 654 msleep(sc, &sc->amr_list_lock, PPAUSE, "amrioc", hz); |
658 mtx_unlock(&sc->amr_list_lock); | |
659 660 ac_flags = AMR_CMD_DATAIN|AMR_CMD_DATAOUT; 661 bzero(&ac->ac_mailbox, sizeof(ac->ac_mailbox)); 662 bcopy(&ali.mbox[0], &ac->ac_mailbox, sizeof(ali.mbox)); 663 664 ac->ac_length = len; 665 ac->ac_data = dp; 666 ac->ac_flags = ac_flags; 667 668 error = amr_wait_command(ac); | 655 656 ac_flags = AMR_CMD_DATAIN|AMR_CMD_DATAOUT; 657 bzero(&ac->ac_mailbox, sizeof(ac->ac_mailbox)); 658 bcopy(&ali.mbox[0], &ac->ac_mailbox, sizeof(ali.mbox)); 659 660 ac->ac_length = len; 661 ac->ac_data = dp; 662 ac->ac_flags = ac_flags; 663 664 error = amr_wait_command(ac); |
665 mtx_unlock(&sc->amr_list_lock); |
|
669 if (error) 670 break; 671 672 status = ac->ac_status; 673 error = copyout(&status, &((struct amr_mailbox *)&((struct amr_linux_ioctl *)addr)->mbox[0])->mb_status, sizeof(status)); 674 if (ali.outlen) { 675 error = copyout(dp, (void *)(uintptr_t)mb->mb_physaddr, len); 676 if (error) --- 130 unchanged lines hidden (view full) --- 807 808 /* Allocate this now before the mutex gets held */ 809 if (au_cmd[0] == AMR_CMD_PASS) 810 ap = malloc(sizeof(struct amr_passthrough), M_DEVBUF, M_WAITOK|M_ZERO); 811 812 mtx_lock(&sc->amr_list_lock); 813 while ((ac = amr_alloccmd(sc)) == NULL) 814 msleep(sc, &sc->amr_list_lock, PPAUSE, "amrioc", hz); | 666 if (error) 667 break; 668 669 status = ac->ac_status; 670 error = copyout(&status, &((struct amr_mailbox *)&((struct amr_linux_ioctl *)addr)->mbox[0])->mb_status, sizeof(status)); 671 if (ali.outlen) { 672 error = copyout(dp, (void *)(uintptr_t)mb->mb_physaddr, len); 673 if (error) --- 130 unchanged lines hidden (view full) --- 804 805 /* Allocate this now before the mutex gets held */ 806 if (au_cmd[0] == AMR_CMD_PASS) 807 ap = malloc(sizeof(struct amr_passthrough), M_DEVBUF, M_WAITOK|M_ZERO); 808 809 mtx_lock(&sc->amr_list_lock); 810 while ((ac = amr_alloccmd(sc)) == NULL) 811 msleep(sc, &sc->amr_list_lock, PPAUSE, "amrioc", hz); |
815 mtx_unlock(&sc->amr_list_lock); | |
816 817 /* handle SCSI passthrough command */ 818 if (au_cmd[0] == AMR_CMD_PASS) { 819 int len; 820 821 /* copy cdb */ 822 len = au_cmd[2]; 823 ap->ap_cdb_length = len; --- 34 unchanged lines hidden (view full) --- 858 ac->ac_data = dp; 859 ac->ac_length = au_length; 860 ac_flags = AMR_CMD_DATAIN|AMR_CMD_DATAOUT; 861 } 862 863 ac->ac_flags = ac_flags; 864 865 /* run the command */ | 812 813 /* handle SCSI passthrough command */ 814 if (au_cmd[0] == AMR_CMD_PASS) { 815 int len; 816 817 /* copy cdb */ 818 len = au_cmd[2]; 819 ap->ap_cdb_length = len; --- 34 unchanged lines hidden (view full) --- 854 ac->ac_data = dp; 855 ac->ac_length = au_length; 856 ac_flags = AMR_CMD_DATAIN|AMR_CMD_DATAOUT; 857 } 858 859 ac->ac_flags = ac_flags; 860 861 /* run the command */ |
866 if ((error = amr_wait_command(ac)) != 0) | 862 error = amr_wait_command(ac); 863 mtx_unlock(&sc->amr_list_lock); 864 if (error) |
867 goto out; 868 869 /* copy out data and set status */ 870 if (au_length != 0) { 871 error = copyout(dp, au_buffer, au_length); 872 } 873 debug(2, "copyout %ld bytes from %p -> %p", au_length, dp, au_buffer); 874 if (dp != NULL) --- 455 unchanged lines hidden (view full) --- 1330 debug_called(1); 1331 1332 ac->ac_complete = NULL; 1333 ac->ac_flags |= AMR_CMD_SLEEP; 1334 if ((error = amr_start(ac)) != 0) { 1335 return(error); 1336 } 1337 | 865 goto out; 866 867 /* copy out data and set status */ 868 if (au_length != 0) { 869 error = copyout(dp, au_buffer, au_length); 870 } 871 debug(2, "copyout %ld bytes from %p -> %p", au_length, dp, au_buffer); 872 if (dp != NULL) --- 455 unchanged lines hidden (view full) --- 1328 debug_called(1); 1329 1330 ac->ac_complete = NULL; 1331 ac->ac_flags |= AMR_CMD_SLEEP; 1332 if ((error = amr_start(ac)) != 0) { 1333 return(error); 1334 } 1335 |
1338 mtx_lock(&sc->amr_wait_lock); | |
1339 while ((ac->ac_flags & AMR_CMD_BUSY) && (error != EWOULDBLOCK)) { | 1336 while ((ac->ac_flags & AMR_CMD_BUSY) && (error != EWOULDBLOCK)) { |
1340 error = msleep(ac,&sc->amr_wait_lock, PRIBIO, "amrwcmd", 0); | 1337 error = msleep(ac,&sc->amr_list_lock, PRIBIO, "amrwcmd", 0); |
1341 } | 1338 } |
1342 mtx_unlock(&sc->amr_wait_lock); | |
1343 1344 return(error); 1345} 1346 1347/******************************************************************************** 1348 * Take a command, submit it to the controller and busy-wait for it to return. 1349 * Returns nonzero on error. Can be safely called with interrupts enabled. 1350 */ --- 657 unchanged lines hidden (view full) --- 2008 if (ac->ac_complete != NULL) { 2009 /* unbusy the command */ 2010 ac->ac_flags &= ~AMR_CMD_BUSY; 2011 ac->ac_complete(ac); 2012 2013 /* 2014 * Is someone sleeping on this one? 2015 */ | 1339 1340 return(error); 1341} 1342 1343/******************************************************************************** 1344 * Take a command, submit it to the controller and busy-wait for it to return. 1345 * Returns nonzero on error. Can be safely called with interrupts enabled. 1346 */ --- 657 unchanged lines hidden (view full) --- 2004 if (ac->ac_complete != NULL) { 2005 /* unbusy the command */ 2006 ac->ac_flags &= ~AMR_CMD_BUSY; 2007 ac->ac_complete(ac); 2008 2009 /* 2010 * Is someone sleeping on this one? 2011 */ |
2016 } else if (ac->ac_flags & AMR_CMD_SLEEP) { 2017 mtx_lock(&sc->amr_wait_lock); 2018 /* unbusy the command */ 2019 ac->ac_flags &= ~AMR_CMD_BUSY; 2020 mtx_unlock(&sc->amr_wait_lock); 2021 wakeup(ac); | |
2022 } else { | 2012 } else { |
2023 /* unbusy the command */ | 2013 mtx_lock(&sc->amr_list_lock); |
2024 ac->ac_flags &= ~AMR_CMD_BUSY; | 2014 ac->ac_flags &= ~AMR_CMD_BUSY; |
2025 } | 2015 if (ac->ac_flags & AMR_CMD_SLEEP) { 2016 /* unbusy the command */ 2017 wakeup(ac); 2018 } 2019 mtx_unlock(&sc->amr_list_lock); 2020 } |
2026 2027 if(!sc->amr_busyslots) { 2028 wakeup(sc); 2029 } 2030 } 2031 2032 mtx_lock(&sc->amr_list_lock); 2033 sc->amr_state &= ~AMR_STATE_QUEUE_FRZN; --- 525 unchanged lines hidden --- | 2021 2022 if(!sc->amr_busyslots) { 2023 wakeup(sc); 2024 } 2025 } 2026 2027 mtx_lock(&sc->amr_list_lock); 2028 sc->amr_state &= ~AMR_STATE_QUEUE_FRZN; --- 525 unchanged lines hidden --- |