1/* 2 * Copyright (c) 2015, AVAGO Tech. All rights reserved. Author: Marian Choy 3 * Copyright (c) 2014, LSI Corp. All rights reserved. Author: Marian Choy 4 * Support: freebsdraid@avagotech.com 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are 8 * met: --- 17 unchanged lines hidden (view full) --- 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 * 31 */ 32 33#include <sys/cdefs.h> |
34__FBSDID("$FreeBSD: head/sys/dev/mrsas/mrsas_cam.c 282533 2015-05-06 10:46:28Z kadesai $"); |
35 36#include "dev/mrsas/mrsas.h" 37 38#include <cam/cam.h> 39#include <cam/cam_ccb.h> 40#include <cam/cam_sim.h> 41#include <cam/cam_xpt_sim.h> 42#include <cam/cam_debug.h> --- 10 unchanged lines hidden (view full) --- 53#include <sys/pcpu.h> /* XXX for PCPU_GET */ 54 55#define smp_processor_id() PCPU_GET(cpuid) 56 57/* 58 * Function prototypes 59 */ 60int mrsas_cam_attach(struct mrsas_softc *sc); |
61int mrsas_find_io_type(struct cam_sim *sim, union ccb *ccb); |
62int mrsas_bus_scan(struct mrsas_softc *sc); 63int mrsas_bus_scan_sim(struct mrsas_softc *sc, struct cam_sim *sim); |
64int |
65mrsas_map_request(struct mrsas_softc *sc, 66 struct mrsas_mpt_cmd *cmd, union ccb *ccb); 67int |
68mrsas_build_ldio(struct mrsas_softc *sc, struct mrsas_mpt_cmd *cmd, 69 union ccb *ccb); |
70int |
71mrsas_build_dcdb(struct mrsas_softc *sc, struct mrsas_mpt_cmd *cmd, 72 union ccb *ccb, struct cam_sim *sim); |
73int |
74mrsas_setup_io(struct mrsas_softc *sc, struct mrsas_mpt_cmd *cmd, 75 union ccb *ccb, u_int32_t device_id, 76 MRSAS_RAID_SCSI_IO_REQUEST * io_request); 77void mrsas_xpt_freeze(struct mrsas_softc *sc); 78void mrsas_xpt_release(struct mrsas_softc *sc); 79void mrsas_cam_detach(struct mrsas_softc *sc); 80void mrsas_release_mpt_cmd(struct mrsas_mpt_cmd *cmd); 81void mrsas_unmap_request(struct mrsas_softc *sc, struct mrsas_mpt_cmd *cmd); 82void mrsas_cmd_done(struct mrsas_softc *sc, struct mrsas_mpt_cmd *cmd); |
83void |
84mrsas_fire_cmd(struct mrsas_softc *sc, u_int32_t req_desc_lo, 85 u_int32_t req_desc_hi); |
86void |
87mrsas_set_pd_lba(MRSAS_RAID_SCSI_IO_REQUEST * io_request, 88 u_int8_t cdb_len, struct IO_REQUEST_INFO *io_info, union ccb *ccb, 89 MR_DRV_RAID_MAP_ALL * local_map_ptr, u_int32_t ref_tag, 90 u_int32_t ld_block_size); 91static void mrsas_freeze_simq(struct mrsas_mpt_cmd *cmd, struct cam_sim *sim); 92static void mrsas_cam_poll(struct cam_sim *sim); 93static void mrsas_action(struct cam_sim *sim, union ccb *ccb); 94static void mrsas_scsiio_timeout(void *data); |
95static void |
96mrsas_data_load_cb(void *arg, bus_dma_segment_t *segs, 97 int nseg, int error); |
98static int32_t |
99mrsas_startio(struct mrsas_softc *sc, struct cam_sim *sim, 100 union ccb *ccb); 101struct mrsas_mpt_cmd *mrsas_get_mpt_cmd(struct mrsas_softc *sc); 102MRSAS_REQUEST_DESCRIPTOR_UNION * 103 mrsas_get_request_desc(struct mrsas_softc *sc, u_int16_t index); 104 105extern u_int16_t MR_TargetIdToLdGet(u_int32_t ldTgtId, MR_DRV_RAID_MAP_ALL * map); 106extern u_int32_t 107MR_LdBlockSizeGet(u_int32_t ldTgtId, MR_DRV_RAID_MAP_ALL * map, 108 struct mrsas_softc *sc); 109extern void mrsas_isr(void *arg); 110extern void mrsas_aen_handler(struct mrsas_softc *sc); 111extern u_int8_t 112MR_BuildRaidContext(struct mrsas_softc *sc, 113 struct IO_REQUEST_INFO *io_info, RAID_CONTEXT * pRAID_Context, 114 MR_DRV_RAID_MAP_ALL * map); 115extern u_int16_t 116MR_LdSpanArrayGet(u_int32_t ld, u_int32_t span, 117 MR_DRV_RAID_MAP_ALL * map); |
118extern u_int16_t 119mrsas_get_updated_dev_handle(struct mrsas_softc *sc, 120 PLD_LOAD_BALANCE_INFO lbInfo, struct IO_REQUEST_INFO *io_info); |
121extern u_int8_t 122megasas_get_best_arm(PLD_LOAD_BALANCE_INFO lbInfo, u_int8_t arm, 123 u_int64_t block, u_int32_t count); 124 125 126/* 127 * mrsas_cam_attach: Main entry to CAM subsystem 128 * input: Adapter instance soft state --- 253 unchanged lines hidden (view full) --- 382 /* 383 * Below callout is dummy entry so that it will be cancelled from 384 * mrsas_cmd_done(). Now Controller will go to OCR/Kill Adapter based 385 * on OCR enable/disable property of Controller from ocr_thread 386 * context. 387 */ 388#if (__FreeBSD_version >= 1000510) 389 callout_reset_sbt(&cmd->cm_callout, SBT_1S * 600, 0, |
390 mrsas_scsiio_timeout, cmd, 0); |
391#else 392 callout_reset(&cmd->cm_callout, (600000 * hz) / 1000, |
393 mrsas_scsiio_timeout, cmd); |
394#endif 395 sc->do_timedout_reset = 1; 396 if (sc->ocr_thread_active) 397 wakeup(&sc->ocr_chan); 398} 399 400/* 401 * mrsas_startio: SCSI IO entry point --- 144 unchanged lines hidden (view full) --- 546 req_desc = cmd->request_desc; 547 req_desc->SCSIIO.SMID = cmd->index; 548 549 /* 550 * Start timer for IO timeout. Default timeout value is 90 second. 551 */ 552#if (__FreeBSD_version >= 1000510) 553 callout_reset_sbt(&cmd->cm_callout, SBT_1S * 600, 0, |
554 mrsas_scsiio_timeout, cmd, 0); |
555#else 556 callout_reset(&cmd->cm_callout, (600000 * hz) / 1000, |
557 mrsas_scsiio_timeout, cmd); |
558#endif 559 mrsas_atomic_inc(&sc->fw_outstanding); 560 561 if (mrsas_atomic_read(&sc->fw_outstanding) > sc->io_cmds_highwater) 562 sc->io_cmds_highwater++; 563 564 mrsas_fire_cmd(sc, req_desc->addr.u.low, req_desc->addr.u.high); 565 return (0); --- 5 unchanged lines hidden (view full) --- 571 572/* 573 * mrsas_find_io_type: Determines if IO is read/write or inquiry 574 * input: pointer to CAM Control Block 575 * 576 * This function determines if the IO is read/write or inquiry. It returns a 1 577 * if the IO is read/write and 0 if it is inquiry. 578 */ |
579int 580mrsas_find_io_type(struct cam_sim *sim, union ccb *ccb) |
581{ 582 struct ccb_scsiio *csio = &(ccb->csio); 583 584 switch (csio->cdb_io.cdb_bytes[0]) { 585 case READ_10: 586 case WRITE_10: 587 case READ_12: 588 case WRITE_12: 589 case READ_6: 590 case WRITE_6: 591 case READ_16: 592 case WRITE_16: 593 return (cam_sim_bus(sim) ? |
594 READ_WRITE_SYSPDIO : READ_WRITE_LDIO); |
595 default: 596 return (cam_sim_bus(sim) ? |
597 NON_READ_WRITE_SYSPDIO : NON_READ_WRITE_LDIO); |
598 } 599} 600 601/* 602 * mrsas_get_mpt_cmd: Get a cmd from free command pool 603 * input: Adapter instance soft state 604 * 605 * This function removes an MPT command from the command free list and --- 236 unchanged lines hidden (view full) --- 842 io_request->IoFlags |= MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH; 843 io_request->RaidContext.regLockFlags |= 844 (MR_RL_FLAGS_GRANT_DESTINATION_CUDA | 845 MR_RL_FLAGS_SEQ_NUM_ENABLE); 846 } 847 if ((sc->load_balance_info[device_id].loadBalanceFlag) && 848 (io_info.isRead)) { 849 io_info.devHandle = |
850 mrsas_get_updated_dev_handle(sc, 851 &sc->load_balance_info[device_id], &io_info); |
852 cmd->load_balance = MRSAS_LOAD_BALANCE_FLAG; 853 cmd->pd_r1_lb = io_info.pd_after_lb; 854 } else 855 cmd->load_balance = 0; 856 cmd->request_desc->SCSIIO.DevHandle = io_info.devHandle; 857 io_request->DevHandle = io_info.devHandle; 858 } else { 859 /* Not FP IO */ --- 35 unchanged lines hidden (view full) --- 895 u_int32_t device_id; 896 MR_DRV_RAID_MAP_ALL *map_ptr; 897 MRSAS_RAID_SCSI_IO_REQUEST *io_request; 898 899 io_request = cmd->io_request; 900 device_id = ccb_h->target_id; 901 map_ptr = sc->ld_drv_map[(sc->map_id & 1)]; 902 |
903 /* 904 * Check if this is RW for system PD or 905 * it's a NON RW for sys PD and there is NO secure jbod FW support 906 */ |
907 if (cam_sim_bus(sim) == 1 && |
908 sc->pd_list[device_id].driveState == MR_PD_STATE_SYSTEM) { |
909 910 io_request->DevHandle = |
911 map_ptr->raidMap.devHndlInfo[device_id].curDevHdl; |
912 io_request->RaidContext.RAIDFlags = |
913 MR_RAID_FLAGS_IO_SUB_TYPE_SYSTEM_PD << 914 MR_RAID_CTX_RAID_FLAGS_IO_SUB_TYPE_SHIFT; |
915 cmd->request_desc->SCSIIO.DevHandle = io_request->DevHandle; 916 cmd->request_desc->SCSIIO.MSIxIndex = |
917 sc->msix_vectors ? smp_processor_id() % sc->msix_vectors : 0; |
918 |
919 if (sc->secure_jbod_support && (mrsas_find_io_type(sim, ccb) == NON_READ_WRITE_SYSPDIO)) { |
920 /* system pd firmware path */ |
921 io_request->Function = MRSAS_MPI2_FUNCTION_LD_IO_REQUEST; |
922 cmd->request_desc->SCSIIO.RequestFlags = |
923 (MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO << MRSAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT); |
924 } else { 925 /* system pd fast path */ 926 io_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST; 927 io_request->RaidContext.timeoutValue = map_ptr->raidMap.fpPdIoTimeoutSec; 928 io_request->RaidContext.regLockFlags = 0; 929 io_request->RaidContext.regLockRowLBA = 0; 930 io_request->RaidContext.regLockLength = 0; 931 932 cmd->request_desc->SCSIIO.RequestFlags = |
933 (MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY << 934 MRSAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT); |
935 936 /* 937 * NOTE - For system pd RW cmds only IoFlags will be FAST_PATH 938 * Because the NON RW cmds will now go via FW Queue 939 * and not the Exception queue 940 */ 941 if ((sc->device_id == MRSAS_INVADER) || (sc->device_id == MRSAS_FURY)) 942 io_request->IoFlags |= MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH; |
943 } |
944 } else { |
945 /* FW path for SysPD or LD Non-RW (SCSI management commands) */ 946 io_request->Function = MRSAS_MPI2_FUNCTION_LD_IO_REQUEST; |
947 io_request->DevHandle = device_id; 948 cmd->request_desc->SCSIIO.RequestFlags = |
949 (MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO << 950 MRSAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT); |
951 } 952 953 io_request->RaidContext.VirtualDiskTgtId = device_id; 954 io_request->LUN[1] = ccb_h->target_lun & 0xF; 955 io_request->DataLength = cmd->length; 956 957 if (mrsas_map_request(sc, cmd, ccb) == SUCCESS) { 958 if (cmd->sge_count > sc->max_num_sge) { --- 13 unchanged lines hidden (view full) --- 972 * mrsas_map_request: Map and load data 973 * input: Adapter instance soft state 974 * Pointer to command packet 975 * 976 * For data from OS, map and load the data buffer into bus space. The SG list 977 * is built in the callback. If the bus dmamap load is not successful, 978 * cmd->error_code will contain the error code and a 1 is returned. 979 */ |
980int 981mrsas_map_request(struct mrsas_softc *sc, 982 struct mrsas_mpt_cmd *cmd, union ccb *ccb) |
983{ 984 u_int32_t retcode = 0; 985 struct cam_sim *sim; 986 987 sim = xpt_path_sim(cmd->ccb_ptr->ccb_h.path); 988 989 if (cmd->data != NULL) { 990 /* Map data buffer into bus space */ 991 mtx_lock(&sc->io_lock); 992#if (__FreeBSD_version >= 902001) 993 retcode = bus_dmamap_load_ccb(sc->data_tag, cmd->data_dmamap, ccb, |
994 mrsas_data_load_cb, cmd, 0); |
995#else 996 retcode = bus_dmamap_load(sc->data_tag, cmd->data_dmamap, cmd->data, |
997 cmd->length, mrsas_data_load_cb, cmd, BUS_DMA_NOWAIT); |
998#endif 999 mtx_unlock(&sc->io_lock); 1000 if (retcode) 1001 device_printf(sc->mrsas_dev, "bus_dmamap_load(): retcode = %d\n", retcode); 1002 if (retcode == EINPROGRESS) { 1003 device_printf(sc->mrsas_dev, "request load in progress\n"); 1004 mrsas_freeze_simq(cmd, sim); 1005 } --- 242 unchanged lines hidden --- |