Deleted Added
full compact
hpt27xx_osm_bsd.c (269611) hpt27xx_osm_bsd.c (284730)
1/*-
2 * Copyright (c) 2011 HighPoint Technologies, Inc.
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) 2011 HighPoint Technologies, Inc.
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/hpt27xx/hpt27xx_osm_bsd.c 269611 2014-08-05 23:32:53Z jhb $
26 * $FreeBSD: head/sys/dev/hpt27xx/hpt27xx_osm_bsd.c 284730 2015-06-23 17:26:16Z delphij $
27 */
28
29#include <dev/hpt27xx/hpt27xx_config.h>
30
31#include <dev/hpt27xx/os_bsd.h>
32#include <dev/hpt27xx/hptintf.h>
33
34static HIM *hpt_match(device_t dev)

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

369 bus_teardown_intr(hba->pcidev, hba->irq_res, hba->irq_handle);
370
371 hpt_free_mem(vbus_ext);
372
373 while ((hba=vbus_ext->hba_list)) {
374 vbus_ext->hba_list = hba->next;
375 free(hba->ldm_adapter.him_handle, M_DEVBUF);
376 }
27 */
28
29#include <dev/hpt27xx/hpt27xx_config.h>
30
31#include <dev/hpt27xx/os_bsd.h>
32#include <dev/hpt27xx/hptintf.h>
33
34static HIM *hpt_match(device_t dev)

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

369 bus_teardown_intr(hba->pcidev, hba->irq_res, hba->irq_handle);
370
371 hpt_free_mem(vbus_ext);
372
373 while ((hba=vbus_ext->hba_list)) {
374 vbus_ext->hba_list = hba->next;
375 free(hba->ldm_adapter.him_handle, M_DEVBUF);
376 }
377
377#if (__FreeBSD_version >= 1000510)
378 callout_drain(&vbus_ext->timer);
379 mtx_destroy(&vbus_ext->lock);
380#endif
378 free(vbus_ext, M_DEVBUF);
379 KdPrint(("hpt_shutdown_vbus done"));
380}
381
382static void __hpt_do_tasks(PVBUS_EXT vbus_ext)
383{
384 OSM_TASK *tasks;
385

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

432 ldm_reset_vbus((PVBUS)ext->vbus_ext->vbus);
433}
434
435static void os_cmddone(PCOMMAND pCmd)
436{
437 POS_CMDEXT ext = (POS_CMDEXT)pCmd->priv;
438 union ccb *ccb = ext->ccb;
439
381 free(vbus_ext, M_DEVBUF);
382 KdPrint(("hpt_shutdown_vbus done"));
383}
384
385static void __hpt_do_tasks(PVBUS_EXT vbus_ext)
386{
387 OSM_TASK *tasks;
388

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

435 ldm_reset_vbus((PVBUS)ext->vbus_ext->vbus);
436}
437
438static void os_cmddone(PCOMMAND pCmd)
439{
440 POS_CMDEXT ext = (POS_CMDEXT)pCmd->priv;
441 union ccb *ccb = ext->ccb;
442
440 KdPrint(("os_cmddone(%p, %d)", pCmd, pCmd->Result));
441
443 KdPrint(("<8>os_cmddone(%p, %d)", pCmd, pCmd->Result));
444#if (__FreeBSD_version >= 1000510)
442 callout_stop(&ext->timeout);
445 callout_stop(&ext->timeout);
443
446#else
447 untimeout(hpt_timeout, pCmd, ccb->ccb_h.timeout_ch);
448#endif
444 switch(pCmd->Result) {
445 case RETURN_SUCCESS:
446 ccb->ccb_h.status = CAM_REQ_CMP;
447 break;
448 case RETURN_BAD_DEVICE:
449 ccb->ccb_h.status = CAM_DEV_NOT_THERE;
450 break;
451 case RETURN_DEVICE_BUSY:

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

478 ldm_free_cmds(pCmd);
479 xpt_done(ccb);
480}
481
482static int os_buildsgl(PCOMMAND pCmd, PSG pSg, int logical)
483{
484 POS_CMDEXT ext = (POS_CMDEXT)pCmd->priv;
485 union ccb *ccb = ext->ccb;
449 switch(pCmd->Result) {
450 case RETURN_SUCCESS:
451 ccb->ccb_h.status = CAM_REQ_CMP;
452 break;
453 case RETURN_BAD_DEVICE:
454 ccb->ccb_h.status = CAM_DEV_NOT_THERE;
455 break;
456 case RETURN_DEVICE_BUSY:

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

483 ldm_free_cmds(pCmd);
484 xpt_done(ccb);
485}
486
487static int os_buildsgl(PCOMMAND pCmd, PSG pSg, int logical)
488{
489 POS_CMDEXT ext = (POS_CMDEXT)pCmd->priv;
490 union ccb *ccb = ext->ccb;
486
487 if (logical) {
491#if (__FreeBSD_version >= 1000510)
492 if(logical) {
488 os_set_sgptr(pSg, (HPT_U8 *)ccb->csio.data_ptr);
489 pSg->size = ccb->csio.dxfer_len;
490 pSg->eot = 1;
491 return TRUE;
492 }
493 os_set_sgptr(pSg, (HPT_U8 *)ccb->csio.data_ptr);
494 pSg->size = ccb->csio.dxfer_len;
495 pSg->eot = 1;
496 return TRUE;
497 }
498#else
499 bus_dma_segment_t *sgList = (bus_dma_segment_t *)ccb->csio.data_ptr;
500 int idx;
493
501
502 if(logical) {
503 if (ccb->ccb_h.flags & CAM_DATA_PHYS)
504 panic("physical address unsupported");
505
506 if (ccb->ccb_h.flags & CAM_SCATTER_VALID) {
507 if (ccb->ccb_h.flags & CAM_SG_LIST_PHYS)
508 panic("physical address unsupported");
509
510 for (idx = 0; idx < ccb->csio.sglist_cnt; idx++) {
511 os_set_sgptr(&pSg[idx], (HPT_U8 *)(HPT_UPTR)sgList[idx].ds_addr);
512 pSg[idx].size = sgList[idx].ds_len;
513 pSg[idx].eot = (idx==ccb->csio.sglist_cnt-1)? 1 : 0;
514 }
515 }
516 else {
517 os_set_sgptr(pSg, (HPT_U8 *)ccb->csio.data_ptr);
518 pSg->size = ccb->csio.dxfer_len;
519 pSg->eot = 1;
520 }
521 return TRUE;
522 }
523#endif
494 /* since we have provided physical sg, nobody will ask us to build physical sg */
495 HPT_ASSERT(0);
496 return FALSE;
497}
498
499static void hpt_io_dmamap_callback(void *arg, bus_dma_segment_t *segs, int nsegs, int error)
500{
501 PCOMMAND pCmd = (PCOMMAND)arg;

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

522 bus_dmamap_sync(ext->vbus_ext->io_dmat, ext->dma_map,
523 BUS_DMASYNC_PREREAD);
524 }
525 else if (pCmd->flags.data_out) {
526 bus_dmamap_sync(ext->vbus_ext->io_dmat, ext->dma_map,
527 BUS_DMASYNC_PREWRITE);
528 }
529 }
524 /* since we have provided physical sg, nobody will ask us to build physical sg */
525 HPT_ASSERT(0);
526 return FALSE;
527}
528
529static void hpt_io_dmamap_callback(void *arg, bus_dma_segment_t *segs, int nsegs, int error)
530{
531 PCOMMAND pCmd = (PCOMMAND)arg;

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

552 bus_dmamap_sync(ext->vbus_ext->io_dmat, ext->dma_map,
553 BUS_DMASYNC_PREREAD);
554 }
555 else if (pCmd->flags.data_out) {
556 bus_dmamap_sync(ext->vbus_ext->io_dmat, ext->dma_map,
557 BUS_DMASYNC_PREWRITE);
558 }
559 }
560#if (__FreeBSD_version >= 1000510)
530 callout_reset(&ext->timeout, HPT_OSM_TIMEOUT, hpt_timeout, pCmd);
561 callout_reset(&ext->timeout, HPT_OSM_TIMEOUT, hpt_timeout, pCmd);
562#else
563 ext->ccb->ccb_h.timeout_ch = timeout(hpt_timeout, pCmd, HPT_OSM_TIMEOUT);
564#endif
531 ldm_queue_cmd(pCmd);
532}
533
534static void hpt_scsi_io(PVBUS_EXT vbus_ext, union ccb *ccb)
535{
536 PVBUS vbus = (PVBUS)vbus_ext->vbus;
537 PVDEV vd;
538 PCOMMAND pCmd;
539 POS_CMDEXT ext;
540 HPT_U8 *cdb;
541
542 if (ccb->ccb_h.flags & CAM_CDB_POINTER)
543 cdb = ccb->csio.cdb_io.cdb_ptr;
544 else
545 cdb = ccb->csio.cdb_io.cdb_bytes;
546
565 ldm_queue_cmd(pCmd);
566}
567
568static void hpt_scsi_io(PVBUS_EXT vbus_ext, union ccb *ccb)
569{
570 PVBUS vbus = (PVBUS)vbus_ext->vbus;
571 PVDEV vd;
572 PCOMMAND pCmd;
573 POS_CMDEXT ext;
574 HPT_U8 *cdb;
575
576 if (ccb->ccb_h.flags & CAM_CDB_POINTER)
577 cdb = ccb->csio.cdb_io.cdb_ptr;
578 else
579 cdb = ccb->csio.cdb_io.cdb_bytes;
580
547 KdPrint(("hpt_scsi_io: ccb %x id %d lun %d cdb %x-%x-%x",
581 KdPrint(("<8>hpt_scsi_io: ccb %x id %d lun %d cdb %x-%x-%x",
548 ccb,
549 ccb->ccb_h.target_id, ccb->ccb_h.target_lun,
550 *(HPT_U32 *)&cdb[0], *(HPT_U32 *)&cdb[4], *(HPT_U32 *)&cdb[8]
551 ));
552
553 /* ccb->ccb_h.path_id is not our bus id - don't check it */
554 if (ccb->ccb_h.target_lun != 0 ||
555 ccb->ccb_h.target_id >= osm_max_targets ||

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

598 ccb->ccb_h.status = CAM_REQ_CMP;
599 }
600 break;
601
602 case READ_CAPACITY:
603 {
604 HPT_U8 *rbuf = ccb->csio.data_ptr;
605 HPT_U32 cap;
582 ccb,
583 ccb->ccb_h.target_id, ccb->ccb_h.target_lun,
584 *(HPT_U32 *)&cdb[0], *(HPT_U32 *)&cdb[4], *(HPT_U32 *)&cdb[8]
585 ));
586
587 /* ccb->ccb_h.path_id is not our bus id - don't check it */
588 if (ccb->ccb_h.target_lun != 0 ||
589 ccb->ccb_h.target_id >= osm_max_targets ||

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

632 ccb->ccb_h.status = CAM_REQ_CMP;
633 }
634 break;
635
636 case READ_CAPACITY:
637 {
638 HPT_U8 *rbuf = ccb->csio.data_ptr;
639 HPT_U32 cap;
640 HPT_U8 sector_size_shift = 0;
641 HPT_U64 new_cap;
642 HPT_U32 sector_size = 0;
643
644 if (mIsArray(vd->type))
645 sector_size_shift = vd->u.array.sector_size_shift;
646 else{
647 if(vd->type == VD_RAW){
648 sector_size = vd->u.raw.logical_sector_size;
649 }
606
650
607 if (vd->capacity>0xfffffffful)
608 cap = 0xfffffffful;
651 switch (sector_size) {
652 case 0x1000:
653 KdPrint(("set 4k setctor size in READ_CAPACITY"));
654 sector_size_shift = 3;
655 break;
656 default:
657 break;
658 }
659 }
660 new_cap = vd->capacity >> sector_size_shift;
661
662 if (new_cap > 0xfffffffful)
663 cap = 0xffffffff;
609 else
664 else
610 cap = vd->capacity - 1;
611
665 cap = new_cap - 1;
666
612 rbuf[0] = (HPT_U8)(cap>>24);
613 rbuf[1] = (HPT_U8)(cap>>16);
614 rbuf[2] = (HPT_U8)(cap>>8);
615 rbuf[3] = (HPT_U8)cap;
616 rbuf[4] = 0;
617 rbuf[5] = 0;
667 rbuf[0] = (HPT_U8)(cap>>24);
668 rbuf[1] = (HPT_U8)(cap>>16);
669 rbuf[2] = (HPT_U8)(cap>>8);
670 rbuf[3] = (HPT_U8)cap;
671 rbuf[4] = 0;
672 rbuf[5] = 0;
618 rbuf[6] = 2;
673 rbuf[6] = 2 << sector_size_shift;
619 rbuf[7] = 0;
620
621 ccb->ccb_h.status = CAM_REQ_CMP;
622 break;
623 }
674 rbuf[7] = 0;
675
676 ccb->ccb_h.status = CAM_REQ_CMP;
677 break;
678 }
624
679 case REPORT_LUNS:
680 {
681 HPT_U8 *rbuf = ccb->csio.data_ptr;
682 memset(rbuf, 0, 16);
683 rbuf[3] = 8;
684 ccb->ccb_h.status = CAM_REQ_CMP;
685 break;
686 }
625 case SERVICE_ACTION_IN:
626 {
627 HPT_U8 *rbuf = ccb->csio.data_ptr;
687 case SERVICE_ACTION_IN:
688 {
689 HPT_U8 *rbuf = ccb->csio.data_ptr;
628 HPT_U64 cap = vd->capacity - 1;
690 HPT_U64 cap = 0;
691 HPT_U8 sector_size_shift = 0;
692 HPT_U32 sector_size = 0;
693
694 if(mIsArray(vd->type))
695 sector_size_shift = vd->u.array.sector_size_shift;
696 else{
697 if(vd->type == VD_RAW){
698 sector_size = vd->u.raw.logical_sector_size;
699 }
629
700
701 switch (sector_size) {
702 case 0x1000:
703 KdPrint(("set 4k setctor size in SERVICE_ACTION_IN"));
704 sector_size_shift = 3;
705 break;
706 default:
707 break;
708 }
709 }
710 cap = (vd->capacity >> sector_size_shift) - 1;
711
630 rbuf[0] = (HPT_U8)(cap>>56);
631 rbuf[1] = (HPT_U8)(cap>>48);
632 rbuf[2] = (HPT_U8)(cap>>40);
633 rbuf[3] = (HPT_U8)(cap>>32);
634 rbuf[4] = (HPT_U8)(cap>>24);
635 rbuf[5] = (HPT_U8)(cap>>16);
636 rbuf[6] = (HPT_U8)(cap>>8);
637 rbuf[7] = (HPT_U8)cap;
638 rbuf[8] = 0;
639 rbuf[9] = 0;
712 rbuf[0] = (HPT_U8)(cap>>56);
713 rbuf[1] = (HPT_U8)(cap>>48);
714 rbuf[2] = (HPT_U8)(cap>>40);
715 rbuf[3] = (HPT_U8)(cap>>32);
716 rbuf[4] = (HPT_U8)(cap>>24);
717 rbuf[5] = (HPT_U8)(cap>>16);
718 rbuf[6] = (HPT_U8)(cap>>8);
719 rbuf[7] = (HPT_U8)cap;
720 rbuf[8] = 0;
721 rbuf[9] = 0;
640 rbuf[10] = 2;
722 rbuf[10] = 2 << sector_size_shift;
641 rbuf[11] = 0;
642
643 ccb->ccb_h.status = CAM_REQ_CMP;
644 break;
645 }
646
647 case READ_6:
648 case READ_10:
649 case READ_16:
650 case WRITE_6:
651 case WRITE_10:
652 case WRITE_16:
653 case 0x13:
654 case 0x2f:
655 case 0x8f: /* VERIFY_16 */
656 {
723 rbuf[11] = 0;
724
725 ccb->ccb_h.status = CAM_REQ_CMP;
726 break;
727 }
728
729 case READ_6:
730 case READ_10:
731 case READ_16:
732 case WRITE_6:
733 case WRITE_10:
734 case WRITE_16:
735 case 0x13:
736 case 0x2f:
737 case 0x8f: /* VERIFY_16 */
738 {
657 int error;
739 HPT_U8 sector_size_shift = 0;
740 HPT_U32 sector_size = 0;
658 pCmd = ldm_alloc_cmds(vbus, vd->cmds_per_request);
659 if(!pCmd){
660 KdPrint(("Failed to allocate command!"));
661 ccb->ccb_h.status = CAM_BUSY;
662 break;
663 }
664
665 switch (cdb[0]) {

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

687 break;
688 }
689
690 default:
691 pCmd->uCmd.Ide.Lba = (HPT_U32)cdb[5] | ((HPT_U32)cdb[4] << 8) | ((HPT_U32)cdb[3] << 16) | ((HPT_U32)cdb[2] << 24);
692 pCmd->uCmd.Ide.nSectors = (HPT_U16) cdb[8] | ((HPT_U16)cdb[7]<<8);
693 break;
694 }
741 pCmd = ldm_alloc_cmds(vbus, vd->cmds_per_request);
742 if(!pCmd){
743 KdPrint(("Failed to allocate command!"));
744 ccb->ccb_h.status = CAM_BUSY;
745 break;
746 }
747
748 switch (cdb[0]) {

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

770 break;
771 }
772
773 default:
774 pCmd->uCmd.Ide.Lba = (HPT_U32)cdb[5] | ((HPT_U32)cdb[4] << 8) | ((HPT_U32)cdb[3] << 16) | ((HPT_U32)cdb[2] << 24);
775 pCmd->uCmd.Ide.nSectors = (HPT_U16) cdb[8] | ((HPT_U16)cdb[7]<<8);
776 break;
777 }
778
779 if(mIsArray(vd->type)) {
780 sector_size_shift = vd->u.array.sector_size_shift;
781 }
782 else{
783 if(vd->type == VD_RAW){
784 sector_size = vd->u.raw.logical_sector_size;
785 }
786
787 switch (sector_size) {
788 case 0x1000:
789 KdPrint(("<8>resize sector size from 4k to 512"));
790 sector_size_shift = 3;
791 break;
792 default:
793 break;
794 }
795 }
796 pCmd->uCmd.Ide.Lba <<= sector_size_shift;
797 pCmd->uCmd.Ide.nSectors <<= sector_size_shift;
798
695
696 switch (cdb[0]) {
697 case READ_6:
698 case READ_10:
699 case READ_16:
700 pCmd->flags.data_in = 1;
701 break;
702 case WRITE_6:
703 case WRITE_10:
704 case WRITE_16:
705 pCmd->flags.data_out = 1;
706 break;
707 }
708 pCmd->priv = ext = cmdext_get(vbus_ext);
709 HPT_ASSERT(ext);
710 ext->ccb = ccb;
711 pCmd->target = vd;
712 pCmd->done = os_cmddone;
713 pCmd->buildsgl = os_buildsgl;
799
800 switch (cdb[0]) {
801 case READ_6:
802 case READ_10:
803 case READ_16:
804 pCmd->flags.data_in = 1;
805 break;
806 case WRITE_6:
807 case WRITE_10:
808 case WRITE_16:
809 pCmd->flags.data_out = 1;
810 break;
811 }
812 pCmd->priv = ext = cmdext_get(vbus_ext);
813 HPT_ASSERT(ext);
814 ext->ccb = ccb;
815 pCmd->target = vd;
816 pCmd->done = os_cmddone;
817 pCmd->buildsgl = os_buildsgl;
818
714 pCmd->psg = ext->psg;
819 pCmd->psg = ext->psg;
715 pCmd->flags.physical_sg = 1;
716 error = bus_dmamap_load_ccb(vbus_ext->io_dmat,
717 ext->dma_map, ccb,
718 hpt_io_dmamap_callback, pCmd,
820#if (__FreeBSD_version < 1000510)
821 if (ccb->ccb_h.flags & CAM_SCATTER_VALID) {
822 int idx;
823 bus_dma_segment_t *sgList = (bus_dma_segment_t *)ccb->csio.data_ptr;
824
825 if (ccb->ccb_h.flags & CAM_SG_LIST_PHYS)
826 pCmd->flags.physical_sg = 1;
827
828 for (idx = 0; idx < ccb->csio.sglist_cnt; idx++) {
829 pCmd->psg[idx].addr.bus = sgList[idx].ds_addr;
830 pCmd->psg[idx].size = sgList[idx].ds_len;
831 pCmd->psg[idx].eot = (idx==ccb->csio.sglist_cnt-1)? 1 : 0;
832 }
833
834 ccb->ccb_h.timeout_ch = timeout(hpt_timeout, pCmd, HPT_OSM_TIMEOUT);
835 ldm_queue_cmd(pCmd);
836 }
837 else
838#endif
839 {
840 int error;
841 pCmd->flags.physical_sg = 1;
842#if (__FreeBSD_version >= 1000510)
843 error = bus_dmamap_load_ccb(vbus_ext->io_dmat,
844 ext->dma_map, ccb,
845 hpt_io_dmamap_callback, pCmd,
846 BUS_DMA_WAITOK
847 );
848#else
849 error = bus_dmamap_load(vbus_ext->io_dmat,
850 ext->dma_map,
851 ccb->csio.data_ptr, ccb->csio.dxfer_len,
852 hpt_io_dmamap_callback, pCmd,
719 BUS_DMA_WAITOK
720 );
853 BUS_DMA_WAITOK
854 );
721 KdPrint(("bus_dmamap_load return %d", error));
722 if (error && error!=EINPROGRESS) {
723 os_printk("bus_dmamap_load error %d", error);
724 cmdext_put(ext);
725 ldm_free_cmds(pCmd);
726 ccb->ccb_h.status = CAM_REQ_CMP_ERR;
727 xpt_done(ccb);
855#endif
856 KdPrint(("<8>bus_dmamap_load return %d", error));
857 if (error && error!=EINPROGRESS) {
858 os_printk("bus_dmamap_load error %d", error);
859 cmdext_put(ext);
860 ldm_free_cmds(pCmd);
861 ccb->ccb_h.status = CAM_REQ_CMP_ERR;
862 xpt_done(ccb);
863 }
728 }
729 return;
730 }
731
732 default:
733 ccb->ccb_h.status = CAM_REQ_INVALID;
734 break;
735 }
736
737 xpt_done(ccb);
738 return;
739}
740
741static void hpt_action(struct cam_sim *sim, union ccb *ccb)
742{
743 PVBUS_EXT vbus_ext = (PVBUS_EXT)cam_sim_softc(sim);
744
864 }
865 return;
866 }
867
868 default:
869 ccb->ccb_h.status = CAM_REQ_INVALID;
870 break;
871 }
872
873 xpt_done(ccb);
874 return;
875}
876
877static void hpt_action(struct cam_sim *sim, union ccb *ccb)
878{
879 PVBUS_EXT vbus_ext = (PVBUS_EXT)cam_sim_softc(sim);
880
745 KdPrint(("hpt_action(fn=%d, id=%d)", ccb->ccb_h.func_code, ccb->ccb_h.target_id));
881 KdPrint(("<8>hpt_action(fn=%d, id=%d)", ccb->ccb_h.func_code, ccb->ccb_h.target_id));
746
882
883#if (__FreeBSD_version >= 1000510)
747 hpt_assert_vbus_locked(vbus_ext);
884 hpt_assert_vbus_locked(vbus_ext);
885#endif
748 switch (ccb->ccb_h.func_code) {
886 switch (ccb->ccb_h.func_code) {
749
887
888#if (__FreeBSD_version < 1000510)
750 case XPT_SCSI_IO:
889 case XPT_SCSI_IO:
890 hpt_lock_vbus(vbus_ext);
751 hpt_scsi_io(vbus_ext, ccb);
891 hpt_scsi_io(vbus_ext, ccb);
892 hpt_unlock_vbus(vbus_ext);
752 return;
753
754 case XPT_RESET_BUS:
893 return;
894
895 case XPT_RESET_BUS:
896 hpt_lock_vbus(vbus_ext);
755 ldm_reset_vbus((PVBUS)vbus_ext->vbus);
897 ldm_reset_vbus((PVBUS)vbus_ext->vbus);
898 hpt_unlock_vbus(vbus_ext);
756 break;
899 break;
900#else
901 case XPT_SCSI_IO:
902 hpt_scsi_io(vbus_ext, ccb);
903 return;
757
904
905 case XPT_RESET_BUS:
906 ldm_reset_vbus((PVBUS)vbus_ext->vbus);
907 break;
908#endif
758 case XPT_GET_TRAN_SETTINGS:
759 case XPT_SET_TRAN_SETTINGS:
760 ccb->ccb_h.status = CAM_FUNC_NOTAVAIL;
761 break;
762
763 case XPT_CALC_GEOMETRY:
764 ccb->ccg.heads = 255;
765 ccb->ccg.secs_per_track = 63;

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

808 PVBUS_EXT vbus_ext = (PVBUS_EXT)arg;
809 hpt_lock_vbus(vbus_ext);
810 ldm_intr((PVBUS)vbus_ext->vbus);
811 hpt_unlock_vbus(vbus_ext);
812}
813
814static void hpt_poll(struct cam_sim *sim)
815{
909 case XPT_GET_TRAN_SETTINGS:
910 case XPT_SET_TRAN_SETTINGS:
911 ccb->ccb_h.status = CAM_FUNC_NOTAVAIL;
912 break;
913
914 case XPT_CALC_GEOMETRY:
915 ccb->ccg.heads = 255;
916 ccb->ccg.secs_per_track = 63;

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

959 PVBUS_EXT vbus_ext = (PVBUS_EXT)arg;
960 hpt_lock_vbus(vbus_ext);
961 ldm_intr((PVBUS)vbus_ext->vbus);
962 hpt_unlock_vbus(vbus_ext);
963}
964
965static void hpt_poll(struct cam_sim *sim)
966{
967#if (__FreeBSD_version < 1000510)
968 hpt_pci_intr(cam_sim_softc(sim));
969#else
816 PVBUS_EXT vbus_ext = (PVBUS_EXT)cam_sim_softc(sim);
817
818 hpt_assert_vbus_locked(vbus_ext);
819 ldm_intr((PVBUS)vbus_ext->vbus);
970 PVBUS_EXT vbus_ext = (PVBUS_EXT)cam_sim_softc(sim);
971
972 hpt_assert_vbus_locked(vbus_ext);
973 ldm_intr((PVBUS)vbus_ext->vbus);
974#endif
820}
821
822static void hpt_async(void * callback_arg, u_int32_t code, struct cam_path * path, void * arg)
823{
975}
976
977static void hpt_async(void * callback_arg, u_int32_t code, struct cam_path * path, void * arg)
978{
824 KdPrint(("hpt_async"));
979 KdPrint(("<8>hpt_async"));
825}
826
827static int hpt_shutdown(device_t dev)
828{
829 KdPrint(("hpt_shutdown(dev=%p)", dev));
830 return 0;
831}
832

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

862
863 hpt_unlock_vbus(vbus_ext);
864}
865
866static void hpt_do_ioctl(IOCTL_ARG *ioctl_args)
867{
868 PVBUS vbus;
869 PVBUS_EXT vbus_ext;
980}
981
982static int hpt_shutdown(device_t dev)
983{
984 KdPrint(("hpt_shutdown(dev=%p)", dev));
985 return 0;
986}
987

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

1017
1018 hpt_unlock_vbus(vbus_ext);
1019}
1020
1021static void hpt_do_ioctl(IOCTL_ARG *ioctl_args)
1022{
1023 PVBUS vbus;
1024 PVBUS_EXT vbus_ext;
870
1025
871 ldm_for_each_vbus(vbus, vbus_ext) {
872 __hpt_do_ioctl(vbus_ext, ioctl_args);
873 if (ioctl_args->result!=HPT_IOCTL_RESULT_WRONG_VBUS)
874 return;
875 }
876}
877
878#define HPT_DO_IOCTL(code, inbuf, insize, outbuf, outsize) ({\

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

998 os_printk("no controller detected.");
999 return;
1000 }
1001
1002 /* initializing hardware */
1003 ldm_for_each_vbus(vbus, vbus_ext) {
1004 /* make timer available here */
1005 mtx_init(&vbus_ext->lock, "hptsleeplock", NULL, MTX_DEF);
1026 ldm_for_each_vbus(vbus, vbus_ext) {
1027 __hpt_do_ioctl(vbus_ext, ioctl_args);
1028 if (ioctl_args->result!=HPT_IOCTL_RESULT_WRONG_VBUS)
1029 return;
1030 }
1031}
1032
1033#define HPT_DO_IOCTL(code, inbuf, insize, outbuf, outsize) ({\

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

1153 os_printk("no controller detected.");
1154 return;
1155 }
1156
1157 /* initializing hardware */
1158 ldm_for_each_vbus(vbus, vbus_ext) {
1159 /* make timer available here */
1160 mtx_init(&vbus_ext->lock, "hptsleeplock", NULL, MTX_DEF);
1161#if (__FreeBSD_version < 1000510)
1162 callout_handle_init(&vbus_ext->timer);
1163#else
1006 callout_init_mtx(&vbus_ext->timer, &vbus_ext->lock, 0);
1164 callout_init_mtx(&vbus_ext->timer, &vbus_ext->lock, 0);
1165#endif
1007 if (hpt_init_vbus(vbus_ext)) {
1008 os_printk("fail to initialize hardware");
1009 break; /* FIXME */
1010 }
1011 }
1012
1013 /* register CAM interface */
1014 ldm_for_each_vbus(vbus, vbus_ext) {

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

1041 ext->vbus_ext = vbus_ext;
1042 ext->next = vbus_ext->cmdext_list;
1043 vbus_ext->cmdext_list = ext;
1044
1045 if (bus_dmamap_create(vbus_ext->io_dmat, 0, &ext->dma_map)) {
1046 os_printk("Can't create dma map(%d)", i);
1047 return ;
1048 }
1166 if (hpt_init_vbus(vbus_ext)) {
1167 os_printk("fail to initialize hardware");
1168 break; /* FIXME */
1169 }
1170 }
1171
1172 /* register CAM interface */
1173 ldm_for_each_vbus(vbus, vbus_ext) {

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

1200 ext->vbus_ext = vbus_ext;
1201 ext->next = vbus_ext->cmdext_list;
1202 vbus_ext->cmdext_list = ext;
1203
1204 if (bus_dmamap_create(vbus_ext->io_dmat, 0, &ext->dma_map)) {
1205 os_printk("Can't create dma map(%d)", i);
1206 return ;
1207 }
1208#if (__FreeBSD_version >= 1000510)
1049 callout_init_mtx(&ext->timeout, &vbus_ext->lock, 0);
1209 callout_init_mtx(&ext->timeout, &vbus_ext->lock, 0);
1210#endif
1050 }
1051
1052 if ((devq = cam_simq_alloc(os_max_queue_comm)) == NULL) {
1053 os_printk("cam_simq_alloc failed");
1054 return ;
1055 }
1211 }
1212
1213 if ((devq = cam_simq_alloc(os_max_queue_comm)) == NULL) {
1214 os_printk("cam_simq_alloc failed");
1215 return ;
1216 }
1056
1217#if (__FreeBSD_version >= 1000510)
1057 vbus_ext->sim = cam_sim_alloc(hpt_action, hpt_poll, driver_name,
1058 vbus_ext, unit_number, &vbus_ext->lock, os_max_queue_comm, /*tagged*/8, devq);
1218 vbus_ext->sim = cam_sim_alloc(hpt_action, hpt_poll, driver_name,
1219 vbus_ext, unit_number, &vbus_ext->lock, os_max_queue_comm, /*tagged*/8, devq);
1220
1221#else
1222 vbus_ext->sim = cam_sim_alloc(hpt_action, hpt_poll, driver_name,
1223 vbus_ext, unit_number, &Giant, os_max_queue_comm, /*tagged*/8, devq);
1224#endif
1059 unit_number++;
1060 if (!vbus_ext->sim) {
1061 os_printk("cam_sim_alloc failed");
1062 cam_simq_free(devq);
1063 return ;
1064 }
1065
1066 hpt_lock_vbus(vbus_ext);

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

1095 for (hba = vbus_ext->hba_list; hba; hba = hba->next) {
1096 int rid = 0;
1097 if ((hba->irq_res = bus_alloc_resource(hba->pcidev,
1098 SYS_RES_IRQ, &rid, 0, ~0ul, 1, RF_SHAREABLE | RF_ACTIVE)) == NULL)
1099 {
1100 os_printk("can't allocate interrupt");
1101 return ;
1102 }
1225 unit_number++;
1226 if (!vbus_ext->sim) {
1227 os_printk("cam_sim_alloc failed");
1228 cam_simq_free(devq);
1229 return ;
1230 }
1231
1232 hpt_lock_vbus(vbus_ext);

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

1261 for (hba = vbus_ext->hba_list; hba; hba = hba->next) {
1262 int rid = 0;
1263 if ((hba->irq_res = bus_alloc_resource(hba->pcidev,
1264 SYS_RES_IRQ, &rid, 0, ~0ul, 1, RF_SHAREABLE | RF_ACTIVE)) == NULL)
1265 {
1266 os_printk("can't allocate interrupt");
1267 return ;
1268 }
1103
1269#if (__FreeBSD_version >= 1000510)
1104 if (bus_setup_intr(hba->pcidev, hba->irq_res, INTR_TYPE_CAM | INTR_MPSAFE,
1270 if (bus_setup_intr(hba->pcidev, hba->irq_res, INTR_TYPE_CAM | INTR_MPSAFE,
1271#else
1272 if (bus_setup_intr(hba->pcidev, hba->irq_res, INTR_TYPE_CAM,
1273#endif
1105 NULL, hpt_pci_intr, vbus_ext, &hba->irq_handle))
1106 {
1107 os_printk("can't set up interrupt");
1108 return ;
1109 }
1110 hba->ldm_adapter.him->intr_control(hba->ldm_adapter.him_handle, HPT_TRUE);
1111
1112 }

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

1234 PHPT_IOCTL_PARAM piop=(PHPT_IOCTL_PARAM)data;
1235 IOCTL_ARG ioctl_args;
1236 HPT_U32 bytesReturned;
1237
1238 switch (cmd){
1239 case HPT_DO_IOCONTROL:
1240 {
1241 if (piop->Magic == HPT_IOCTL_MAGIC || piop->Magic == HPT_IOCTL_MAGIC32) {
1274 NULL, hpt_pci_intr, vbus_ext, &hba->irq_handle))
1275 {
1276 os_printk("can't set up interrupt");
1277 return ;
1278 }
1279 hba->ldm_adapter.him->intr_control(hba->ldm_adapter.him_handle, HPT_TRUE);
1280
1281 }

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

1403 PHPT_IOCTL_PARAM piop=(PHPT_IOCTL_PARAM)data;
1404 IOCTL_ARG ioctl_args;
1405 HPT_U32 bytesReturned;
1406
1407 switch (cmd){
1408 case HPT_DO_IOCONTROL:
1409 {
1410 if (piop->Magic == HPT_IOCTL_MAGIC || piop->Magic == HPT_IOCTL_MAGIC32) {
1242 KdPrint(("ioctl=%x in=%p len=%d out=%p len=%d\n",
1411 KdPrint(("<8>ioctl=%x in=%p len=%d out=%p len=%d\n",
1243 piop->dwIoControlCode,
1244 piop->lpInBuffer,
1245 piop->nInBufferSize,
1246 piop->lpOutBuffer,
1247 piop->nOutBufferSize));
1248
1249 memset(&ioctl_args, 0, sizeof(ioctl_args));
1250

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

1263 }
1264
1265 if (ioctl_args.nOutBufferSize) {
1266 ioctl_args.lpOutBuffer = malloc(ioctl_args.nOutBufferSize, M_DEVBUF, M_WAITOK);
1267 if (!ioctl_args.lpOutBuffer)
1268 goto invalid;
1269 }
1270
1412 piop->dwIoControlCode,
1413 piop->lpInBuffer,
1414 piop->nInBufferSize,
1415 piop->lpOutBuffer,
1416 piop->nOutBufferSize));
1417
1418 memset(&ioctl_args, 0, sizeof(ioctl_args));
1419

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

1432 }
1433
1434 if (ioctl_args.nOutBufferSize) {
1435 ioctl_args.lpOutBuffer = malloc(ioctl_args.nOutBufferSize, M_DEVBUF, M_WAITOK);
1436 if (!ioctl_args.lpOutBuffer)
1437 goto invalid;
1438 }
1439
1440#if __FreeBSD_version < 1000510
1441 mtx_lock(&Giant);
1442#endif
1443
1271 hpt_do_ioctl(&ioctl_args);
1272
1444 hpt_do_ioctl(&ioctl_args);
1445
1446#if __FreeBSD_version < 1000510
1447 mtx_unlock(&Giant);
1448#endif
1449
1273 if (ioctl_args.result==HPT_IOCTL_RESULT_OK) {
1274 if (piop->nOutBufferSize) {
1275 if (copyout(ioctl_args.lpOutBuffer,
1276 (void*)piop->lpOutBuffer, piop->nOutBufferSize))
1277 goto invalid;
1278 }
1279 if (piop->lpBytesReturned) {
1280 if (copyout(&bytesReturned,

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

1304
1305}
1306
1307static int hpt_rescan_bus(void)
1308{
1309 union ccb *ccb;
1310 PVBUS vbus;
1311 PVBUS_EXT vbus_ext;
1450 if (ioctl_args.result==HPT_IOCTL_RESULT_OK) {
1451 if (piop->nOutBufferSize) {
1452 if (copyout(ioctl_args.lpOutBuffer,
1453 (void*)piop->lpOutBuffer, piop->nOutBufferSize))
1454 goto invalid;
1455 }
1456 if (piop->lpBytesReturned) {
1457 if (copyout(&bytesReturned,

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

1481
1482}
1483
1484static int hpt_rescan_bus(void)
1485{
1486 union ccb *ccb;
1487 PVBUS vbus;
1488 PVBUS_EXT vbus_ext;
1312
1489#if (__FreeBSD_version < 1000510)
1490 mtx_lock(&Giant);
1491#endif
1313 ldm_for_each_vbus(vbus, vbus_ext) {
1314 if ((ccb = xpt_alloc_ccb()) == NULL)
1315 {
1316 return(ENOMEM);
1317 }
1492 ldm_for_each_vbus(vbus, vbus_ext) {
1493 if ((ccb = xpt_alloc_ccb()) == NULL)
1494 {
1495 return(ENOMEM);
1496 }
1497#if (__FreeBSD_version < 1000510)
1498 if (xpt_create_path(&ccb->ccb_h.path, xpt_periph, cam_sim_path(vbus_ext->sim),
1499#else
1318 if (xpt_create_path(&ccb->ccb_h.path, NULL, cam_sim_path(vbus_ext->sim),
1500 if (xpt_create_path(&ccb->ccb_h.path, NULL, cam_sim_path(vbus_ext->sim),
1501#endif
1319 CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD) != CAM_REQ_CMP)
1320 {
1321 xpt_free_ccb(ccb);
1322 return(EIO);
1323 }
1324 xpt_rescan(ccb);
1325 }
1502 CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD) != CAM_REQ_CMP)
1503 {
1504 xpt_free_ccb(ccb);
1505 return(EIO);
1506 }
1507 xpt_rescan(ccb);
1508 }
1326 return(0);
1509#if (__FreeBSD_version < 1000510)
1510 mtx_unlock(&Giant);
1511#endif
1512 return(0);
1327}
1328
1513}
1514