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: 9 * 10 * 1. Redistributions of source code must retain the above copyright notice, 11 * this list of conditions and the following disclaimer. 2. Redistributions 12 * in binary form must reproduce the above copyright notice, this list of 13 * conditions and the following disclaimer in the documentation and/or other 14 * materials provided with the distribution. 3. Neither the name of the 15 * <ORGANIZATION> nor the names of its contributors may be used to endorse or 16 * promote products derived from this software without specific prior written 17 * permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 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>
| 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: 9 * 10 * 1. Redistributions of source code must retain the above copyright notice, 11 * this list of conditions and the following disclaimer. 2. Redistributions 12 * in binary form must reproduce the above copyright notice, this list of 13 * conditions and the following disclaimer in the documentation and/or other 14 * materials provided with the distribution. 3. Neither the name of the 15 * <ORGANIZATION> nor the names of its contributors may be used to endorse or 16 * promote products derived from this software without specific prior written 17 * permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 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 282532 2015-05-06 10:45:56Z kadesai $");
| 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> 43#include <cam/cam_periph.h> 44#include <cam/cam_xpt_periph.h> 45 46#include <cam/scsi/scsi_all.h> 47#include <cam/scsi/scsi_message.h> 48#include <sys/taskqueue.h> 49#include <sys/kernel.h> 50 51 52#include <sys/time.h> /* XXX for pcpu.h */ 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);
| 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> 43#include <cam/cam_periph.h> 44#include <cam/cam_xpt_periph.h> 45 46#include <cam/scsi/scsi_all.h> 47#include <cam/scsi/scsi_message.h> 48#include <sys/taskqueue.h> 49#include <sys/kernel.h> 50 51 52#include <sys/time.h> /* XXX for pcpu.h */ 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);
| 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);
| 62int mrsas_bus_scan(struct mrsas_softc *sc); 63int mrsas_bus_scan_sim(struct mrsas_softc *sc, struct cam_sim *sim);
|
64int mrsas_map_request(struct mrsas_softc *sc, 65 struct mrsas_mpt_cmd *cmd, union ccb *ccb);
| |
66int
| 64int
|
| 65mrsas_map_request(struct mrsas_softc *sc, 66 struct mrsas_mpt_cmd *cmd, union ccb *ccb); 67int
|
67mrsas_build_ldio(struct mrsas_softc *sc, struct mrsas_mpt_cmd *cmd, 68 union ccb *ccb);
| 68mrsas_build_ldio(struct mrsas_softc *sc, struct mrsas_mpt_cmd *cmd, 69 union ccb *ccb);
|
69int
| 70int
|
70mrsas_build_dcdb(struct mrsas_softc *sc, struct mrsas_mpt_cmd *cmd, 71 union ccb *ccb, struct cam_sim *sim);
| 71mrsas_build_dcdb(struct mrsas_softc *sc, struct mrsas_mpt_cmd *cmd, 72 union ccb *ccb, struct cam_sim *sim);
|
72int
| 73int
|
73mrsas_setup_io(struct mrsas_softc *sc, struct mrsas_mpt_cmd *cmd, 74 union ccb *ccb, u_int32_t device_id, 75 MRSAS_RAID_SCSI_IO_REQUEST * io_request); 76void mrsas_xpt_freeze(struct mrsas_softc *sc); 77void mrsas_xpt_release(struct mrsas_softc *sc); 78void mrsas_cam_detach(struct mrsas_softc *sc); 79void mrsas_release_mpt_cmd(struct mrsas_mpt_cmd *cmd); 80void mrsas_unmap_request(struct mrsas_softc *sc, struct mrsas_mpt_cmd *cmd); 81void mrsas_cmd_done(struct mrsas_softc *sc, struct mrsas_mpt_cmd *cmd);
| 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);
|
82void
| 83void
|
83mrsas_fire_cmd(struct mrsas_softc *sc, u_int32_t req_desc_lo, 84 u_int32_t req_desc_hi);
| 84mrsas_fire_cmd(struct mrsas_softc *sc, u_int32_t req_desc_lo, 85 u_int32_t req_desc_hi);
|
85void
| 86void
|
86mrsas_set_pd_lba(MRSAS_RAID_SCSI_IO_REQUEST * io_request, 87 u_int8_t cdb_len, struct IO_REQUEST_INFO *io_info, union ccb *ccb, 88 MR_DRV_RAID_MAP_ALL * local_map_ptr, u_int32_t ref_tag, 89 u_int32_t ld_block_size); 90static void mrsas_freeze_simq(struct mrsas_mpt_cmd *cmd, struct cam_sim *sim); 91static void mrsas_cam_poll(struct cam_sim *sim); 92static void mrsas_action(struct cam_sim *sim, union ccb *ccb); 93static void mrsas_scsiio_timeout(void *data);
| 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);
|
94static void
| 95static void
|
95mrsas_data_load_cb(void *arg, bus_dma_segment_t *segs, 96 int nseg, int error);
| 96mrsas_data_load_cb(void *arg, bus_dma_segment_t *segs, 97 int nseg, int error);
|
97static int32_t
| 98static int32_t
|
98mrsas_startio(struct mrsas_softc *sc, struct cam_sim *sim, 99 union ccb *ccb); 100struct mrsas_mpt_cmd *mrsas_get_mpt_cmd(struct mrsas_softc *sc); 101MRSAS_REQUEST_DESCRIPTOR_UNION * 102 mrsas_get_request_desc(struct mrsas_softc *sc, u_int16_t index); 103 104extern u_int16_t MR_TargetIdToLdGet(u_int32_t ldTgtId, MR_DRV_RAID_MAP_ALL * map); 105extern u_int32_t 106MR_LdBlockSizeGet(u_int32_t ldTgtId, MR_DRV_RAID_MAP_ALL * map, 107 struct mrsas_softc *sc); 108extern void mrsas_isr(void *arg); 109extern void mrsas_aen_handler(struct mrsas_softc *sc); 110extern u_int8_t 111MR_BuildRaidContext(struct mrsas_softc *sc, 112 struct IO_REQUEST_INFO *io_info, RAID_CONTEXT * pRAID_Context, 113 MR_DRV_RAID_MAP_ALL * map); 114extern u_int16_t 115MR_LdSpanArrayGet(u_int32_t ld, u_int32_t span, 116 MR_DRV_RAID_MAP_ALL * map);
| 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);
|
117extern u_int16_t mrsas_get_updated_dev_handle(struct mrsas_softc *sc, 118 PLD_LOAD_BALANCE_INFO lbInfo, struct IO_REQUEST_INFO *io_info);
| 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);
|
119extern u_int8_t 120megasas_get_best_arm(PLD_LOAD_BALANCE_INFO lbInfo, u_int8_t arm, 121 u_int64_t block, u_int32_t count); 122 123 124/* 125 * mrsas_cam_attach: Main entry to CAM subsystem 126 * input: Adapter instance soft state 127 * 128 * This function is called from mrsas_attach() during initialization to perform 129 * SIM allocations and XPT bus registration. If the kernel version is 7.4 or 130 * earlier, it would also initiate a bus scan. 131 */ 132int 133mrsas_cam_attach(struct mrsas_softc *sc) 134{ 135 struct cam_devq *devq; 136 int mrsas_cam_depth; 137 138 mrsas_cam_depth = sc->max_fw_cmds - MRSAS_INTERNAL_CMDS; 139 140 if ((devq = cam_simq_alloc(mrsas_cam_depth)) == NULL) { 141 device_printf(sc->mrsas_dev, "Cannot allocate SIM queue\n"); 142 return (ENOMEM); 143 } 144 /* 145 * Create SIM for bus 0 and register, also create path 146 */ 147 sc->sim_0 = cam_sim_alloc(mrsas_action, mrsas_cam_poll, "mrsas", sc, 148 device_get_unit(sc->mrsas_dev), &sc->sim_lock, mrsas_cam_depth, 149 mrsas_cam_depth, devq); 150 if (sc->sim_0 == NULL) { 151 cam_simq_free(devq); 152 device_printf(sc->mrsas_dev, "Cannot register SIM\n"); 153 return (ENXIO); 154 } 155 /* Initialize taskqueue for Event Handling */ 156 TASK_INIT(&sc->ev_task, 0, (void *)mrsas_aen_handler, sc); 157 sc->ev_tq = taskqueue_create("mrsas_taskq", M_NOWAIT | M_ZERO, 158 taskqueue_thread_enqueue, &sc->ev_tq); 159 160 /* Run the task queue with lowest priority */ 161 taskqueue_start_threads(&sc->ev_tq, 1, 255, "%s taskq", 162 device_get_nameunit(sc->mrsas_dev)); 163 mtx_lock(&sc->sim_lock); 164 if (xpt_bus_register(sc->sim_0, sc->mrsas_dev, 0) != CAM_SUCCESS) { 165 cam_sim_free(sc->sim_0, TRUE); /* passing true frees the devq */ 166 mtx_unlock(&sc->sim_lock); 167 return (ENXIO); 168 } 169 if (xpt_create_path(&sc->path_0, NULL, cam_sim_path(sc->sim_0), 170 CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD) != CAM_REQ_CMP) { 171 xpt_bus_deregister(cam_sim_path(sc->sim_0)); 172 cam_sim_free(sc->sim_0, TRUE); /* passing true will free the 173 * devq */ 174 mtx_unlock(&sc->sim_lock); 175 return (ENXIO); 176 } 177 mtx_unlock(&sc->sim_lock); 178 179 /* 180 * Create SIM for bus 1 and register, also create path 181 */ 182 sc->sim_1 = cam_sim_alloc(mrsas_action, mrsas_cam_poll, "mrsas", sc, 183 device_get_unit(sc->mrsas_dev), &sc->sim_lock, mrsas_cam_depth, 184 mrsas_cam_depth, devq); 185 if (sc->sim_1 == NULL) { 186 cam_simq_free(devq); 187 device_printf(sc->mrsas_dev, "Cannot register SIM\n"); 188 return (ENXIO); 189 } 190 mtx_lock(&sc->sim_lock); 191 if (xpt_bus_register(sc->sim_1, sc->mrsas_dev, 1) != CAM_SUCCESS) { 192 cam_sim_free(sc->sim_1, TRUE); /* passing true frees the devq */ 193 mtx_unlock(&sc->sim_lock); 194 return (ENXIO); 195 } 196 if (xpt_create_path(&sc->path_1, NULL, cam_sim_path(sc->sim_1), 197 CAM_TARGET_WILDCARD, 198 CAM_LUN_WILDCARD) != CAM_REQ_CMP) { 199 xpt_bus_deregister(cam_sim_path(sc->sim_1)); 200 cam_sim_free(sc->sim_1, TRUE); 201 mtx_unlock(&sc->sim_lock); 202 return (ENXIO); 203 } 204 mtx_unlock(&sc->sim_lock); 205 206#if (__FreeBSD_version <= 704000) 207 if (mrsas_bus_scan(sc)) { 208 device_printf(sc->mrsas_dev, "Error in bus scan.\n"); 209 return (1); 210 } 211#endif 212 return (0); 213} 214 215/* 216 * mrsas_cam_detach: De-allocates and teardown CAM 217 * input: Adapter instance soft state 218 * 219 * De-registers and frees the paths and SIMs. 220 */ 221void 222mrsas_cam_detach(struct mrsas_softc *sc) 223{ 224 if (sc->ev_tq != NULL) 225 taskqueue_free(sc->ev_tq); 226 mtx_lock(&sc->sim_lock); 227 if (sc->path_0) 228 xpt_free_path(sc->path_0); 229 if (sc->sim_0) { 230 xpt_bus_deregister(cam_sim_path(sc->sim_0)); 231 cam_sim_free(sc->sim_0, FALSE); 232 } 233 if (sc->path_1) 234 xpt_free_path(sc->path_1); 235 if (sc->sim_1) { 236 xpt_bus_deregister(cam_sim_path(sc->sim_1)); 237 cam_sim_free(sc->sim_1, TRUE); 238 } 239 mtx_unlock(&sc->sim_lock); 240} 241 242/* 243 * mrsas_action: SIM callback entry point 244 * input: pointer to SIM pointer to CAM Control Block 245 * 246 * This function processes CAM subsystem requests. The type of request is stored 247 * in ccb->ccb_h.func_code. The preprocessor #ifdef is necessary because 248 * ccb->cpi.maxio is not supported for FreeBSD version 7.4 or earlier. 249 */ 250static void 251mrsas_action(struct cam_sim *sim, union ccb *ccb) 252{ 253 struct mrsas_softc *sc = (struct mrsas_softc *)cam_sim_softc(sim); 254 struct ccb_hdr *ccb_h = &(ccb->ccb_h); 255 u_int32_t device_id; 256 257 switch (ccb->ccb_h.func_code) { 258 case XPT_SCSI_IO: 259 { 260 device_id = ccb_h->target_id; 261 262 /* 263 * bus 0 is LD, bus 1 is for system-PD 264 */ 265 if (cam_sim_bus(sim) == 1 && 266 sc->pd_list[device_id].driveState != MR_PD_STATE_SYSTEM) { 267 ccb->ccb_h.status |= CAM_DEV_NOT_THERE; 268 xpt_done(ccb); 269 } else { 270 if (mrsas_startio(sc, sim, ccb)) { 271 ccb->ccb_h.status |= CAM_REQ_INVALID; 272 xpt_done(ccb); 273 } 274 } 275 break; 276 } 277 case XPT_ABORT: 278 { 279 ccb->ccb_h.status = CAM_UA_ABORT; 280 xpt_done(ccb); 281 break; 282 } 283 case XPT_RESET_BUS: 284 { 285 xpt_done(ccb); 286 break; 287 } 288 case XPT_GET_TRAN_SETTINGS: 289 { 290 ccb->cts.protocol = PROTO_SCSI; 291 ccb->cts.protocol_version = SCSI_REV_2; 292 ccb->cts.transport = XPORT_SPI; 293 ccb->cts.transport_version = 2; 294 ccb->cts.xport_specific.spi.valid = CTS_SPI_VALID_DISC; 295 ccb->cts.xport_specific.spi.flags = CTS_SPI_FLAGS_DISC_ENB; 296 ccb->cts.proto_specific.scsi.valid = CTS_SCSI_VALID_TQ; 297 ccb->cts.proto_specific.scsi.flags = CTS_SCSI_FLAGS_TAG_ENB; 298 ccb->ccb_h.status = CAM_REQ_CMP; 299 xpt_done(ccb); 300 break; 301 } 302 case XPT_SET_TRAN_SETTINGS: 303 { 304 ccb->ccb_h.status = CAM_FUNC_NOTAVAIL; 305 xpt_done(ccb); 306 break; 307 } 308 case XPT_CALC_GEOMETRY: 309 { 310 cam_calc_geometry(&ccb->ccg, 1); 311 xpt_done(ccb); 312 break; 313 } 314 case XPT_PATH_INQ: 315 { 316 ccb->cpi.version_num = 1; 317 ccb->cpi.hba_inquiry = 0; 318 ccb->cpi.target_sprt = 0; 319#if (__FreeBSD_version >= 902001) 320 ccb->cpi.hba_misc = PIM_UNMAPPED; 321#else 322 ccb->cpi.hba_misc = 0; 323#endif 324 ccb->cpi.hba_eng_cnt = 0; 325 ccb->cpi.max_lun = MRSAS_SCSI_MAX_LUNS; 326 ccb->cpi.unit_number = cam_sim_unit(sim); 327 ccb->cpi.bus_id = cam_sim_bus(sim); 328 ccb->cpi.initiator_id = MRSAS_SCSI_INITIATOR_ID; 329 ccb->cpi.base_transfer_speed = 150000; 330 strncpy(ccb->cpi.sim_vid, "FreeBSD", SIM_IDLEN); 331 strncpy(ccb->cpi.hba_vid, "AVAGO", HBA_IDLEN); 332 strncpy(ccb->cpi.dev_name, cam_sim_name(sim), DEV_IDLEN); 333 ccb->cpi.transport = XPORT_SPI; 334 ccb->cpi.transport_version = 2; 335 ccb->cpi.protocol = PROTO_SCSI; 336 ccb->cpi.protocol_version = SCSI_REV_2; 337 if (ccb->cpi.bus_id == 0) 338 ccb->cpi.max_target = MRSAS_MAX_PD - 1; 339 else 340 ccb->cpi.max_target = MRSAS_MAX_LD_IDS - 1; 341#if (__FreeBSD_version > 704000) 342 ccb->cpi.maxio = MRSAS_MAX_IO_SIZE; 343#endif 344 ccb->ccb_h.status = CAM_REQ_CMP; 345 xpt_done(ccb); 346 break; 347 } 348 default: 349 { 350 ccb->ccb_h.status = CAM_REQ_INVALID; 351 xpt_done(ccb); 352 break; 353 } 354 } 355} 356 357/* 358 * mrsas_scsiio_timeout: Callback function for IO timed out 359 * input: mpt command context 360 * 361 * This function will execute after timeout value provided by ccb header from 362 * CAM layer, if timer expires. Driver will run timer for all DCDM and LDIO 363 * comming from CAM layer. This function is callback function for IO timeout 364 * and it runs in no-sleep context. Set do_timedout_reset in Adapter context 365 * so that it will execute OCR/Kill adpter from ocr_thread context. 366 */ 367static void 368mrsas_scsiio_timeout(void *data) 369{ 370 struct mrsas_mpt_cmd *cmd; 371 struct mrsas_softc *sc; 372 373 cmd = (struct mrsas_mpt_cmd *)data; 374 sc = cmd->sc; 375 376 if (cmd->ccb_ptr == NULL) { 377 printf("command timeout with NULL ccb\n"); 378 return; 379 } 380 /* 381 * Below callout is dummy entry so that it will be cancelled from 382 * mrsas_cmd_done(). Now Controller will go to OCR/Kill Adapter based 383 * on OCR enable/disable property of Controller from ocr_thread 384 * context. 385 */ 386#if (__FreeBSD_version >= 1000510) 387 callout_reset_sbt(&cmd->cm_callout, SBT_1S * 600, 0,
| 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 129 * 130 * This function is called from mrsas_attach() during initialization to perform 131 * SIM allocations and XPT bus registration. If the kernel version is 7.4 or 132 * earlier, it would also initiate a bus scan. 133 */ 134int 135mrsas_cam_attach(struct mrsas_softc *sc) 136{ 137 struct cam_devq *devq; 138 int mrsas_cam_depth; 139 140 mrsas_cam_depth = sc->max_fw_cmds - MRSAS_INTERNAL_CMDS; 141 142 if ((devq = cam_simq_alloc(mrsas_cam_depth)) == NULL) { 143 device_printf(sc->mrsas_dev, "Cannot allocate SIM queue\n"); 144 return (ENOMEM); 145 } 146 /* 147 * Create SIM for bus 0 and register, also create path 148 */ 149 sc->sim_0 = cam_sim_alloc(mrsas_action, mrsas_cam_poll, "mrsas", sc, 150 device_get_unit(sc->mrsas_dev), &sc->sim_lock, mrsas_cam_depth, 151 mrsas_cam_depth, devq); 152 if (sc->sim_0 == NULL) { 153 cam_simq_free(devq); 154 device_printf(sc->mrsas_dev, "Cannot register SIM\n"); 155 return (ENXIO); 156 } 157 /* Initialize taskqueue for Event Handling */ 158 TASK_INIT(&sc->ev_task, 0, (void *)mrsas_aen_handler, sc); 159 sc->ev_tq = taskqueue_create("mrsas_taskq", M_NOWAIT | M_ZERO, 160 taskqueue_thread_enqueue, &sc->ev_tq); 161 162 /* Run the task queue with lowest priority */ 163 taskqueue_start_threads(&sc->ev_tq, 1, 255, "%s taskq", 164 device_get_nameunit(sc->mrsas_dev)); 165 mtx_lock(&sc->sim_lock); 166 if (xpt_bus_register(sc->sim_0, sc->mrsas_dev, 0) != CAM_SUCCESS) { 167 cam_sim_free(sc->sim_0, TRUE); /* passing true frees the devq */ 168 mtx_unlock(&sc->sim_lock); 169 return (ENXIO); 170 } 171 if (xpt_create_path(&sc->path_0, NULL, cam_sim_path(sc->sim_0), 172 CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD) != CAM_REQ_CMP) { 173 xpt_bus_deregister(cam_sim_path(sc->sim_0)); 174 cam_sim_free(sc->sim_0, TRUE); /* passing true will free the 175 * devq */ 176 mtx_unlock(&sc->sim_lock); 177 return (ENXIO); 178 } 179 mtx_unlock(&sc->sim_lock); 180 181 /* 182 * Create SIM for bus 1 and register, also create path 183 */ 184 sc->sim_1 = cam_sim_alloc(mrsas_action, mrsas_cam_poll, "mrsas", sc, 185 device_get_unit(sc->mrsas_dev), &sc->sim_lock, mrsas_cam_depth, 186 mrsas_cam_depth, devq); 187 if (sc->sim_1 == NULL) { 188 cam_simq_free(devq); 189 device_printf(sc->mrsas_dev, "Cannot register SIM\n"); 190 return (ENXIO); 191 } 192 mtx_lock(&sc->sim_lock); 193 if (xpt_bus_register(sc->sim_1, sc->mrsas_dev, 1) != CAM_SUCCESS) { 194 cam_sim_free(sc->sim_1, TRUE); /* passing true frees the devq */ 195 mtx_unlock(&sc->sim_lock); 196 return (ENXIO); 197 } 198 if (xpt_create_path(&sc->path_1, NULL, cam_sim_path(sc->sim_1), 199 CAM_TARGET_WILDCARD, 200 CAM_LUN_WILDCARD) != CAM_REQ_CMP) { 201 xpt_bus_deregister(cam_sim_path(sc->sim_1)); 202 cam_sim_free(sc->sim_1, TRUE); 203 mtx_unlock(&sc->sim_lock); 204 return (ENXIO); 205 } 206 mtx_unlock(&sc->sim_lock); 207 208#if (__FreeBSD_version <= 704000) 209 if (mrsas_bus_scan(sc)) { 210 device_printf(sc->mrsas_dev, "Error in bus scan.\n"); 211 return (1); 212 } 213#endif 214 return (0); 215} 216 217/* 218 * mrsas_cam_detach: De-allocates and teardown CAM 219 * input: Adapter instance soft state 220 * 221 * De-registers and frees the paths and SIMs. 222 */ 223void 224mrsas_cam_detach(struct mrsas_softc *sc) 225{ 226 if (sc->ev_tq != NULL) 227 taskqueue_free(sc->ev_tq); 228 mtx_lock(&sc->sim_lock); 229 if (sc->path_0) 230 xpt_free_path(sc->path_0); 231 if (sc->sim_0) { 232 xpt_bus_deregister(cam_sim_path(sc->sim_0)); 233 cam_sim_free(sc->sim_0, FALSE); 234 } 235 if (sc->path_1) 236 xpt_free_path(sc->path_1); 237 if (sc->sim_1) { 238 xpt_bus_deregister(cam_sim_path(sc->sim_1)); 239 cam_sim_free(sc->sim_1, TRUE); 240 } 241 mtx_unlock(&sc->sim_lock); 242} 243 244/* 245 * mrsas_action: SIM callback entry point 246 * input: pointer to SIM pointer to CAM Control Block 247 * 248 * This function processes CAM subsystem requests. The type of request is stored 249 * in ccb->ccb_h.func_code. The preprocessor #ifdef is necessary because 250 * ccb->cpi.maxio is not supported for FreeBSD version 7.4 or earlier. 251 */ 252static void 253mrsas_action(struct cam_sim *sim, union ccb *ccb) 254{ 255 struct mrsas_softc *sc = (struct mrsas_softc *)cam_sim_softc(sim); 256 struct ccb_hdr *ccb_h = &(ccb->ccb_h); 257 u_int32_t device_id; 258 259 switch (ccb->ccb_h.func_code) { 260 case XPT_SCSI_IO: 261 { 262 device_id = ccb_h->target_id; 263 264 /* 265 * bus 0 is LD, bus 1 is for system-PD 266 */ 267 if (cam_sim_bus(sim) == 1 && 268 sc->pd_list[device_id].driveState != MR_PD_STATE_SYSTEM) { 269 ccb->ccb_h.status |= CAM_DEV_NOT_THERE; 270 xpt_done(ccb); 271 } else { 272 if (mrsas_startio(sc, sim, ccb)) { 273 ccb->ccb_h.status |= CAM_REQ_INVALID; 274 xpt_done(ccb); 275 } 276 } 277 break; 278 } 279 case XPT_ABORT: 280 { 281 ccb->ccb_h.status = CAM_UA_ABORT; 282 xpt_done(ccb); 283 break; 284 } 285 case XPT_RESET_BUS: 286 { 287 xpt_done(ccb); 288 break; 289 } 290 case XPT_GET_TRAN_SETTINGS: 291 { 292 ccb->cts.protocol = PROTO_SCSI; 293 ccb->cts.protocol_version = SCSI_REV_2; 294 ccb->cts.transport = XPORT_SPI; 295 ccb->cts.transport_version = 2; 296 ccb->cts.xport_specific.spi.valid = CTS_SPI_VALID_DISC; 297 ccb->cts.xport_specific.spi.flags = CTS_SPI_FLAGS_DISC_ENB; 298 ccb->cts.proto_specific.scsi.valid = CTS_SCSI_VALID_TQ; 299 ccb->cts.proto_specific.scsi.flags = CTS_SCSI_FLAGS_TAG_ENB; 300 ccb->ccb_h.status = CAM_REQ_CMP; 301 xpt_done(ccb); 302 break; 303 } 304 case XPT_SET_TRAN_SETTINGS: 305 { 306 ccb->ccb_h.status = CAM_FUNC_NOTAVAIL; 307 xpt_done(ccb); 308 break; 309 } 310 case XPT_CALC_GEOMETRY: 311 { 312 cam_calc_geometry(&ccb->ccg, 1); 313 xpt_done(ccb); 314 break; 315 } 316 case XPT_PATH_INQ: 317 { 318 ccb->cpi.version_num = 1; 319 ccb->cpi.hba_inquiry = 0; 320 ccb->cpi.target_sprt = 0; 321#if (__FreeBSD_version >= 902001) 322 ccb->cpi.hba_misc = PIM_UNMAPPED; 323#else 324 ccb->cpi.hba_misc = 0; 325#endif 326 ccb->cpi.hba_eng_cnt = 0; 327 ccb->cpi.max_lun = MRSAS_SCSI_MAX_LUNS; 328 ccb->cpi.unit_number = cam_sim_unit(sim); 329 ccb->cpi.bus_id = cam_sim_bus(sim); 330 ccb->cpi.initiator_id = MRSAS_SCSI_INITIATOR_ID; 331 ccb->cpi.base_transfer_speed = 150000; 332 strncpy(ccb->cpi.sim_vid, "FreeBSD", SIM_IDLEN); 333 strncpy(ccb->cpi.hba_vid, "AVAGO", HBA_IDLEN); 334 strncpy(ccb->cpi.dev_name, cam_sim_name(sim), DEV_IDLEN); 335 ccb->cpi.transport = XPORT_SPI; 336 ccb->cpi.transport_version = 2; 337 ccb->cpi.protocol = PROTO_SCSI; 338 ccb->cpi.protocol_version = SCSI_REV_2; 339 if (ccb->cpi.bus_id == 0) 340 ccb->cpi.max_target = MRSAS_MAX_PD - 1; 341 else 342 ccb->cpi.max_target = MRSAS_MAX_LD_IDS - 1; 343#if (__FreeBSD_version > 704000) 344 ccb->cpi.maxio = MRSAS_MAX_IO_SIZE; 345#endif 346 ccb->ccb_h.status = CAM_REQ_CMP; 347 xpt_done(ccb); 348 break; 349 } 350 default: 351 { 352 ccb->ccb_h.status = CAM_REQ_INVALID; 353 xpt_done(ccb); 354 break; 355 } 356 } 357} 358 359/* 360 * mrsas_scsiio_timeout: Callback function for IO timed out 361 * input: mpt command context 362 * 363 * This function will execute after timeout value provided by ccb header from 364 * CAM layer, if timer expires. Driver will run timer for all DCDM and LDIO 365 * comming from CAM layer. This function is callback function for IO timeout 366 * and it runs in no-sleep context. Set do_timedout_reset in Adapter context 367 * so that it will execute OCR/Kill adpter from ocr_thread context. 368 */ 369static void 370mrsas_scsiio_timeout(void *data) 371{ 372 struct mrsas_mpt_cmd *cmd; 373 struct mrsas_softc *sc; 374 375 cmd = (struct mrsas_mpt_cmd *)data; 376 sc = cmd->sc; 377 378 if (cmd->ccb_ptr == NULL) { 379 printf("command timeout with NULL ccb\n"); 380 return; 381 } 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,
|
388 mrsas_scsiio_timeout, cmd, 0);
| 390 mrsas_scsiio_timeout, cmd, 0);
|
389#else 390 callout_reset(&cmd->cm_callout, (600000 * hz) / 1000,
| 391#else 392 callout_reset(&cmd->cm_callout, (600000 * hz) / 1000,
|
391 mrsas_scsiio_timeout, cmd);
| 393 mrsas_scsiio_timeout, cmd);
|
392#endif 393 sc->do_timedout_reset = 1; 394 if (sc->ocr_thread_active) 395 wakeup(&sc->ocr_chan); 396} 397 398/* 399 * mrsas_startio: SCSI IO entry point 400 * input: Adapter instance soft state 401 * pointer to CAM Control Block 402 * 403 * This function is the SCSI IO entry point and it initiates IO processing. It 404 * copies the IO and depending if the IO is read/write or inquiry, it would 405 * call mrsas_build_ldio() or mrsas_build_dcdb(), respectively. It returns 0 406 * if the command is sent to firmware successfully, otherwise it returns 1. 407 */ 408static int32_t 409mrsas_startio(struct mrsas_softc *sc, struct cam_sim *sim, 410 union ccb *ccb) 411{ 412 struct mrsas_mpt_cmd *cmd; 413 struct ccb_hdr *ccb_h = &(ccb->ccb_h); 414 struct ccb_scsiio *csio = &(ccb->csio); 415 MRSAS_REQUEST_DESCRIPTOR_UNION *req_desc; 416 417 if ((csio->cdb_io.cdb_bytes[0]) == SYNCHRONIZE_CACHE) { 418 ccb->ccb_h.status = CAM_REQ_CMP; 419 xpt_done(ccb); 420 return (0); 421 } 422 ccb_h->status |= CAM_SIM_QUEUED; 423 cmd = mrsas_get_mpt_cmd(sc); 424 425 if (!cmd) { 426 ccb_h->status |= CAM_REQUEUE_REQ; 427 xpt_done(ccb); 428 return (0); 429 } 430 if ((ccb_h->flags & CAM_DIR_MASK) != CAM_DIR_NONE) { 431 if (ccb_h->flags & CAM_DIR_IN) 432 cmd->flags |= MRSAS_DIR_IN; 433 if (ccb_h->flags & CAM_DIR_OUT) 434 cmd->flags |= MRSAS_DIR_OUT; 435 } else 436 cmd->flags = MRSAS_DIR_NONE; /* no data */ 437 438/* For FreeBSD 9.2 and higher */ 439#if (__FreeBSD_version >= 902001) 440 /* 441 * XXX We don't yet support physical addresses here. 442 */ 443 switch ((ccb->ccb_h.flags & CAM_DATA_MASK)) { 444 case CAM_DATA_PADDR: 445 case CAM_DATA_SG_PADDR: 446 device_printf(sc->mrsas_dev, "%s: physical addresses not supported\n", 447 __func__); 448 mrsas_release_mpt_cmd(cmd); 449 ccb_h->status = CAM_REQ_INVALID; 450 ccb_h->status &= ~CAM_SIM_QUEUED; 451 goto done; 452 case CAM_DATA_SG: 453 device_printf(sc->mrsas_dev, "%s: scatter gather is not supported\n", 454 __func__); 455 mrsas_release_mpt_cmd(cmd); 456 ccb_h->status = CAM_REQ_INVALID; 457 goto done; 458 case CAM_DATA_VADDR: 459 if (csio->dxfer_len > MRSAS_MAX_IO_SIZE) { 460 mrsas_release_mpt_cmd(cmd); 461 ccb_h->status = CAM_REQ_TOO_BIG; 462 goto done; 463 } 464 cmd->length = csio->dxfer_len; 465 if (cmd->length) 466 cmd->data = csio->data_ptr; 467 break; 468 case CAM_DATA_BIO: 469 cmd->length = csio->dxfer_len; 470 if (cmd->length) 471 cmd->data = csio->data_ptr; 472 break; 473 default: 474 ccb->ccb_h.status = CAM_REQ_INVALID; 475 goto done; 476 } 477#else 478 if (!(ccb_h->flags & CAM_DATA_PHYS)) { /* Virtual data address */ 479 if (!(ccb_h->flags & CAM_SCATTER_VALID)) { 480 if (csio->dxfer_len > MRSAS_MAX_IO_SIZE) { 481 mrsas_release_mpt_cmd(cmd); 482 ccb_h->status = CAM_REQ_TOO_BIG; 483 goto done; 484 } 485 cmd->length = csio->dxfer_len; 486 if (cmd->length) 487 cmd->data = csio->data_ptr; 488 } else { 489 mrsas_release_mpt_cmd(cmd); 490 ccb_h->status = CAM_REQ_INVALID; 491 goto done; 492 } 493 } else { /* Data addresses are physical. */ 494 mrsas_release_mpt_cmd(cmd); 495 ccb_h->status = CAM_REQ_INVALID; 496 ccb_h->status &= ~CAM_SIM_QUEUED; 497 goto done; 498 } 499#endif 500 /* save ccb ptr */ 501 cmd->ccb_ptr = ccb; 502 503 req_desc = mrsas_get_request_desc(sc, (cmd->index) - 1); 504 if (!req_desc) { 505 device_printf(sc->mrsas_dev, "Cannot get request_descriptor.\n"); 506 return (FAIL); 507 } 508 memset(req_desc, 0, sizeof(MRSAS_REQUEST_DESCRIPTOR_UNION)); 509 cmd->request_desc = req_desc; 510 511 if (ccb_h->flags & CAM_CDB_POINTER) 512 bcopy(csio->cdb_io.cdb_ptr, cmd->io_request->CDB.CDB32, csio->cdb_len); 513 else 514 bcopy(csio->cdb_io.cdb_bytes, cmd->io_request->CDB.CDB32, csio->cdb_len); 515 mtx_lock(&sc->raidmap_lock); 516 517 /* Check for IO type READ-WRITE targeted for Logical Volume */ 518 if (mrsas_find_io_type(sim, ccb) == READ_WRITE_LDIO) { 519 /* Build READ-WRITE IO for Logical Volume */ 520 if (mrsas_build_ldio(sc, cmd, ccb)) { 521 device_printf(sc->mrsas_dev, "Build LDIO failed.\n"); 522 mtx_unlock(&sc->raidmap_lock); 523 return (1); 524 } 525 } else { 526 if (mrsas_build_dcdb(sc, cmd, ccb, sim)) { 527 device_printf(sc->mrsas_dev, "Build DCDB failed.\n"); 528 mtx_unlock(&sc->raidmap_lock); 529 return (1); 530 } 531 } 532 mtx_unlock(&sc->raidmap_lock); 533 534 if (cmd->flags == MRSAS_DIR_IN) /* from device */ 535 cmd->io_request->Control |= MPI2_SCSIIO_CONTROL_READ; 536 else if (cmd->flags == MRSAS_DIR_OUT) /* to device */ 537 cmd->io_request->Control |= MPI2_SCSIIO_CONTROL_WRITE; 538 539 cmd->io_request->SGLFlags = MPI2_SGE_FLAGS_64_BIT_ADDRESSING; 540 cmd->io_request->SGLOffset0 = offsetof(MRSAS_RAID_SCSI_IO_REQUEST, SGL) / 4; 541 cmd->io_request->SenseBufferLowAddress = cmd->sense_phys_addr; 542 cmd->io_request->SenseBufferLength = MRSAS_SCSI_SENSE_BUFFERSIZE; 543 544 req_desc = cmd->request_desc; 545 req_desc->SCSIIO.SMID = cmd->index; 546 547 /* 548 * Start timer for IO timeout. Default timeout value is 90 second. 549 */ 550#if (__FreeBSD_version >= 1000510) 551 callout_reset_sbt(&cmd->cm_callout, SBT_1S * 600, 0,
| 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 402 * input: Adapter instance soft state 403 * pointer to CAM Control Block 404 * 405 * This function is the SCSI IO entry point and it initiates IO processing. It 406 * copies the IO and depending if the IO is read/write or inquiry, it would 407 * call mrsas_build_ldio() or mrsas_build_dcdb(), respectively. It returns 0 408 * if the command is sent to firmware successfully, otherwise it returns 1. 409 */ 410static int32_t 411mrsas_startio(struct mrsas_softc *sc, struct cam_sim *sim, 412 union ccb *ccb) 413{ 414 struct mrsas_mpt_cmd *cmd; 415 struct ccb_hdr *ccb_h = &(ccb->ccb_h); 416 struct ccb_scsiio *csio = &(ccb->csio); 417 MRSAS_REQUEST_DESCRIPTOR_UNION *req_desc; 418 419 if ((csio->cdb_io.cdb_bytes[0]) == SYNCHRONIZE_CACHE) { 420 ccb->ccb_h.status = CAM_REQ_CMP; 421 xpt_done(ccb); 422 return (0); 423 } 424 ccb_h->status |= CAM_SIM_QUEUED; 425 cmd = mrsas_get_mpt_cmd(sc); 426 427 if (!cmd) { 428 ccb_h->status |= CAM_REQUEUE_REQ; 429 xpt_done(ccb); 430 return (0); 431 } 432 if ((ccb_h->flags & CAM_DIR_MASK) != CAM_DIR_NONE) { 433 if (ccb_h->flags & CAM_DIR_IN) 434 cmd->flags |= MRSAS_DIR_IN; 435 if (ccb_h->flags & CAM_DIR_OUT) 436 cmd->flags |= MRSAS_DIR_OUT; 437 } else 438 cmd->flags = MRSAS_DIR_NONE; /* no data */ 439 440/* For FreeBSD 9.2 and higher */ 441#if (__FreeBSD_version >= 902001) 442 /* 443 * XXX We don't yet support physical addresses here. 444 */ 445 switch ((ccb->ccb_h.flags & CAM_DATA_MASK)) { 446 case CAM_DATA_PADDR: 447 case CAM_DATA_SG_PADDR: 448 device_printf(sc->mrsas_dev, "%s: physical addresses not supported\n", 449 __func__); 450 mrsas_release_mpt_cmd(cmd); 451 ccb_h->status = CAM_REQ_INVALID; 452 ccb_h->status &= ~CAM_SIM_QUEUED; 453 goto done; 454 case CAM_DATA_SG: 455 device_printf(sc->mrsas_dev, "%s: scatter gather is not supported\n", 456 __func__); 457 mrsas_release_mpt_cmd(cmd); 458 ccb_h->status = CAM_REQ_INVALID; 459 goto done; 460 case CAM_DATA_VADDR: 461 if (csio->dxfer_len > MRSAS_MAX_IO_SIZE) { 462 mrsas_release_mpt_cmd(cmd); 463 ccb_h->status = CAM_REQ_TOO_BIG; 464 goto done; 465 } 466 cmd->length = csio->dxfer_len; 467 if (cmd->length) 468 cmd->data = csio->data_ptr; 469 break; 470 case CAM_DATA_BIO: 471 cmd->length = csio->dxfer_len; 472 if (cmd->length) 473 cmd->data = csio->data_ptr; 474 break; 475 default: 476 ccb->ccb_h.status = CAM_REQ_INVALID; 477 goto done; 478 } 479#else 480 if (!(ccb_h->flags & CAM_DATA_PHYS)) { /* Virtual data address */ 481 if (!(ccb_h->flags & CAM_SCATTER_VALID)) { 482 if (csio->dxfer_len > MRSAS_MAX_IO_SIZE) { 483 mrsas_release_mpt_cmd(cmd); 484 ccb_h->status = CAM_REQ_TOO_BIG; 485 goto done; 486 } 487 cmd->length = csio->dxfer_len; 488 if (cmd->length) 489 cmd->data = csio->data_ptr; 490 } else { 491 mrsas_release_mpt_cmd(cmd); 492 ccb_h->status = CAM_REQ_INVALID; 493 goto done; 494 } 495 } else { /* Data addresses are physical. */ 496 mrsas_release_mpt_cmd(cmd); 497 ccb_h->status = CAM_REQ_INVALID; 498 ccb_h->status &= ~CAM_SIM_QUEUED; 499 goto done; 500 } 501#endif 502 /* save ccb ptr */ 503 cmd->ccb_ptr = ccb; 504 505 req_desc = mrsas_get_request_desc(sc, (cmd->index) - 1); 506 if (!req_desc) { 507 device_printf(sc->mrsas_dev, "Cannot get request_descriptor.\n"); 508 return (FAIL); 509 } 510 memset(req_desc, 0, sizeof(MRSAS_REQUEST_DESCRIPTOR_UNION)); 511 cmd->request_desc = req_desc; 512 513 if (ccb_h->flags & CAM_CDB_POINTER) 514 bcopy(csio->cdb_io.cdb_ptr, cmd->io_request->CDB.CDB32, csio->cdb_len); 515 else 516 bcopy(csio->cdb_io.cdb_bytes, cmd->io_request->CDB.CDB32, csio->cdb_len); 517 mtx_lock(&sc->raidmap_lock); 518 519 /* Check for IO type READ-WRITE targeted for Logical Volume */ 520 if (mrsas_find_io_type(sim, ccb) == READ_WRITE_LDIO) { 521 /* Build READ-WRITE IO for Logical Volume */ 522 if (mrsas_build_ldio(sc, cmd, ccb)) { 523 device_printf(sc->mrsas_dev, "Build LDIO failed.\n"); 524 mtx_unlock(&sc->raidmap_lock); 525 return (1); 526 } 527 } else { 528 if (mrsas_build_dcdb(sc, cmd, ccb, sim)) { 529 device_printf(sc->mrsas_dev, "Build DCDB failed.\n"); 530 mtx_unlock(&sc->raidmap_lock); 531 return (1); 532 } 533 } 534 mtx_unlock(&sc->raidmap_lock); 535 536 if (cmd->flags == MRSAS_DIR_IN) /* from device */ 537 cmd->io_request->Control |= MPI2_SCSIIO_CONTROL_READ; 538 else if (cmd->flags == MRSAS_DIR_OUT) /* to device */ 539 cmd->io_request->Control |= MPI2_SCSIIO_CONTROL_WRITE; 540 541 cmd->io_request->SGLFlags = MPI2_SGE_FLAGS_64_BIT_ADDRESSING; 542 cmd->io_request->SGLOffset0 = offsetof(MRSAS_RAID_SCSI_IO_REQUEST, SGL) / 4; 543 cmd->io_request->SenseBufferLowAddress = cmd->sense_phys_addr; 544 cmd->io_request->SenseBufferLength = MRSAS_SCSI_SENSE_BUFFERSIZE; 545 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,
|
552 mrsas_scsiio_timeout, cmd, 0);
| 554 mrsas_scsiio_timeout, cmd, 0);
|
553#else 554 callout_reset(&cmd->cm_callout, (600000 * hz) / 1000,
| 555#else 556 callout_reset(&cmd->cm_callout, (600000 * hz) / 1000,
|
555 mrsas_scsiio_timeout, cmd);
| 557 mrsas_scsiio_timeout, cmd);
|
556#endif 557 mrsas_atomic_inc(&sc->fw_outstanding); 558 559 if (mrsas_atomic_read(&sc->fw_outstanding) > sc->io_cmds_highwater) 560 sc->io_cmds_highwater++; 561 562 mrsas_fire_cmd(sc, req_desc->addr.u.low, req_desc->addr.u.high); 563 return (0); 564 565done: 566 xpt_done(ccb); 567 return (0); 568} 569 570/* 571 * mrsas_find_io_type: Determines if IO is read/write or inquiry 572 * input: pointer to CAM Control Block 573 * 574 * This function determines if the IO is read/write or inquiry. It returns a 1 575 * if the IO is read/write and 0 if it is inquiry. 576 */
| 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); 566 567done: 568 xpt_done(ccb); 569 return (0); 570} 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 */
|
577int mrsas_find_io_type(struct cam_sim *sim, union ccb *ccb)
| 579int 580mrsas_find_io_type(struct cam_sim *sim, union ccb *ccb)
|
578{ 579 struct ccb_scsiio *csio = &(ccb->csio); 580 581 switch (csio->cdb_io.cdb_bytes[0]) { 582 case READ_10: 583 case WRITE_10: 584 case READ_12: 585 case WRITE_12: 586 case READ_6: 587 case WRITE_6: 588 case READ_16: 589 case WRITE_16: 590 return (cam_sim_bus(sim) ?
| 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) ?
|
591 READ_WRITE_SYSPDIO : READ_WRITE_LDIO);
| 594 READ_WRITE_SYSPDIO : READ_WRITE_LDIO);
|
592 default: 593 return (cam_sim_bus(sim) ?
| 595 default: 596 return (cam_sim_bus(sim) ?
|
594 NON_READ_WRITE_SYSPDIO : NON_READ_WRITE_LDIO);
| 597 NON_READ_WRITE_SYSPDIO : NON_READ_WRITE_LDIO);
|
595 } 596} 597 598/* 599 * mrsas_get_mpt_cmd: Get a cmd from free command pool 600 * input: Adapter instance soft state 601 * 602 * This function removes an MPT command from the command free list and 603 * initializes it. 604 */ 605struct mrsas_mpt_cmd * 606mrsas_get_mpt_cmd(struct mrsas_softc *sc) 607{ 608 struct mrsas_mpt_cmd *cmd = NULL; 609 610 mtx_lock(&sc->mpt_cmd_pool_lock); 611 if (!TAILQ_EMPTY(&sc->mrsas_mpt_cmd_list_head)) { 612 cmd = TAILQ_FIRST(&sc->mrsas_mpt_cmd_list_head); 613 TAILQ_REMOVE(&sc->mrsas_mpt_cmd_list_head, cmd, next); 614 } 615 memset((uint8_t *)cmd->io_request, 0, MRSAS_MPI2_RAID_DEFAULT_IO_FRAME_SIZE); 616 cmd->data = NULL; 617 cmd->length = 0; 618 cmd->flags = 0; 619 cmd->error_code = 0; 620 cmd->load_balance = 0; 621 cmd->ccb_ptr = NULL; 622 mtx_unlock(&sc->mpt_cmd_pool_lock); 623 624 return cmd; 625} 626 627/* 628 * mrsas_release_mpt_cmd: Return a cmd to free command pool 629 * input: Command packet for return to free command pool 630 * 631 * This function returns an MPT command to the free command list. 632 */ 633void 634mrsas_release_mpt_cmd(struct mrsas_mpt_cmd *cmd) 635{ 636 struct mrsas_softc *sc = cmd->sc; 637 638 mtx_lock(&sc->mpt_cmd_pool_lock); 639 cmd->sync_cmd_idx = (u_int32_t)MRSAS_ULONG_MAX; 640 TAILQ_INSERT_TAIL(&(sc->mrsas_mpt_cmd_list_head), cmd, next); 641 mtx_unlock(&sc->mpt_cmd_pool_lock); 642 643 return; 644} 645 646/* 647 * mrsas_get_request_desc: Get request descriptor from array 648 * input: Adapter instance soft state 649 * SMID index 650 * 651 * This function returns a pointer to the request descriptor. 652 */ 653MRSAS_REQUEST_DESCRIPTOR_UNION * 654mrsas_get_request_desc(struct mrsas_softc *sc, u_int16_t index) 655{ 656 u_int8_t *p; 657 658 if (index >= sc->max_fw_cmds) { 659 device_printf(sc->mrsas_dev, "Invalid SMID (0x%x)request for desc\n", index); 660 return NULL; 661 } 662 p = sc->req_desc + sizeof(MRSAS_REQUEST_DESCRIPTOR_UNION) * index; 663 664 return (MRSAS_REQUEST_DESCRIPTOR_UNION *) p; 665} 666 667/* 668 * mrsas_build_ldio: Builds an LDIO command 669 * input: Adapter instance soft state 670 * Pointer to command packet 671 * Pointer to CCB 672 * 673 * This function builds the LDIO command packet. It returns 0 if the command is 674 * built successfully, otherwise it returns a 1. 675 */ 676int 677mrsas_build_ldio(struct mrsas_softc *sc, struct mrsas_mpt_cmd *cmd, 678 union ccb *ccb) 679{ 680 struct ccb_hdr *ccb_h = &(ccb->ccb_h); 681 struct ccb_scsiio *csio = &(ccb->csio); 682 u_int32_t device_id; 683 MRSAS_RAID_SCSI_IO_REQUEST *io_request; 684 685 device_id = ccb_h->target_id; 686 687 io_request = cmd->io_request; 688 io_request->RaidContext.VirtualDiskTgtId = device_id; 689 io_request->RaidContext.status = 0; 690 io_request->RaidContext.exStatus = 0; 691 692 /* just the cdb len, other flags zero, and ORed-in later for FP */ 693 io_request->IoFlags = csio->cdb_len; 694 695 if (mrsas_setup_io(sc, cmd, ccb, device_id, io_request) != SUCCESS) 696 device_printf(sc->mrsas_dev, "Build ldio or fpio error\n"); 697 698 io_request->DataLength = cmd->length; 699 700 if (mrsas_map_request(sc, cmd, ccb) == SUCCESS) { 701 if (cmd->sge_count > MRSAS_MAX_SGL) { 702 device_printf(sc->mrsas_dev, "Error: sge_count (0x%x) exceeds" 703 "max (0x%x) allowed\n", cmd->sge_count, sc->max_num_sge); 704 return (FAIL); 705 } 706 io_request->RaidContext.numSGE = cmd->sge_count; 707 } else { 708 device_printf(sc->mrsas_dev, "Data map/load failed.\n"); 709 return (FAIL); 710 } 711 return (0); 712} 713 714/* 715 * mrsas_setup_io: Set up data including Fast Path I/O 716 * input: Adapter instance soft state 717 * Pointer to command packet 718 * Pointer to CCB 719 * 720 * This function builds the DCDB inquiry command. It returns 0 if the command 721 * is built successfully, otherwise it returns a 1. 722 */ 723int 724mrsas_setup_io(struct mrsas_softc *sc, struct mrsas_mpt_cmd *cmd, 725 union ccb *ccb, u_int32_t device_id, 726 MRSAS_RAID_SCSI_IO_REQUEST * io_request) 727{ 728 struct ccb_hdr *ccb_h = &(ccb->ccb_h); 729 struct ccb_scsiio *csio = &(ccb->csio); 730 struct IO_REQUEST_INFO io_info; 731 MR_DRV_RAID_MAP_ALL *map_ptr; 732 u_int8_t fp_possible; 733 u_int32_t start_lba_hi, start_lba_lo, ld_block_size; 734 u_int32_t datalength = 0; 735 736 start_lba_lo = 0; 737 start_lba_hi = 0; 738 fp_possible = 0; 739 740 /* 741 * READ_6 (0x08) or WRITE_6 (0x0A) cdb 742 */ 743 if (csio->cdb_len == 6) { 744 datalength = (u_int32_t)csio->cdb_io.cdb_bytes[4]; 745 start_lba_lo = ((u_int32_t)csio->cdb_io.cdb_bytes[1] << 16) | 746 ((u_int32_t)csio->cdb_io.cdb_bytes[2] << 8) | 747 (u_int32_t)csio->cdb_io.cdb_bytes[3]; 748 start_lba_lo &= 0x1FFFFF; 749 } 750 /* 751 * READ_10 (0x28) or WRITE_6 (0x2A) cdb 752 */ 753 else if (csio->cdb_len == 10) { 754 datalength = (u_int32_t)csio->cdb_io.cdb_bytes[8] | 755 ((u_int32_t)csio->cdb_io.cdb_bytes[7] << 8); 756 start_lba_lo = ((u_int32_t)csio->cdb_io.cdb_bytes[2] << 24) | 757 ((u_int32_t)csio->cdb_io.cdb_bytes[3] << 16) | 758 (u_int32_t)csio->cdb_io.cdb_bytes[4] << 8 | 759 ((u_int32_t)csio->cdb_io.cdb_bytes[5]); 760 } 761 /* 762 * READ_12 (0xA8) or WRITE_12 (0xAA) cdb 763 */ 764 else if (csio->cdb_len == 12) { 765 datalength = (u_int32_t)csio->cdb_io.cdb_bytes[6] << 24 | 766 ((u_int32_t)csio->cdb_io.cdb_bytes[7] << 16) | 767 ((u_int32_t)csio->cdb_io.cdb_bytes[8] << 8) | 768 ((u_int32_t)csio->cdb_io.cdb_bytes[9]); 769 start_lba_lo = ((u_int32_t)csio->cdb_io.cdb_bytes[2] << 24) | 770 ((u_int32_t)csio->cdb_io.cdb_bytes[3] << 16) | 771 (u_int32_t)csio->cdb_io.cdb_bytes[4] << 8 | 772 ((u_int32_t)csio->cdb_io.cdb_bytes[5]); 773 } 774 /* 775 * READ_16 (0x88) or WRITE_16 (0xx8A) cdb 776 */ 777 else if (csio->cdb_len == 16) { 778 datalength = (u_int32_t)csio->cdb_io.cdb_bytes[10] << 24 | 779 ((u_int32_t)csio->cdb_io.cdb_bytes[11] << 16) | 780 ((u_int32_t)csio->cdb_io.cdb_bytes[12] << 8) | 781 ((u_int32_t)csio->cdb_io.cdb_bytes[13]); 782 start_lba_lo = ((u_int32_t)csio->cdb_io.cdb_bytes[6] << 24) | 783 ((u_int32_t)csio->cdb_io.cdb_bytes[7] << 16) | 784 (u_int32_t)csio->cdb_io.cdb_bytes[8] << 8 | 785 ((u_int32_t)csio->cdb_io.cdb_bytes[9]); 786 start_lba_hi = ((u_int32_t)csio->cdb_io.cdb_bytes[2] << 24) | 787 ((u_int32_t)csio->cdb_io.cdb_bytes[3] << 16) | 788 (u_int32_t)csio->cdb_io.cdb_bytes[4] << 8 | 789 ((u_int32_t)csio->cdb_io.cdb_bytes[5]); 790 } 791 memset(&io_info, 0, sizeof(struct IO_REQUEST_INFO)); 792 io_info.ldStartBlock = ((u_int64_t)start_lba_hi << 32) | start_lba_lo; 793 io_info.numBlocks = datalength; 794 io_info.ldTgtId = device_id; 795 796 switch (ccb_h->flags & CAM_DIR_MASK) { 797 case CAM_DIR_IN: 798 io_info.isRead = 1; 799 break; 800 case CAM_DIR_OUT: 801 io_info.isRead = 0; 802 break; 803 case CAM_DIR_NONE: 804 default: 805 mrsas_dprint(sc, MRSAS_TRACE, "From %s : DMA Flag is %d \n", __func__, ccb_h->flags & CAM_DIR_MASK); 806 break; 807 } 808 809 map_ptr = sc->ld_drv_map[(sc->map_id & 1)]; 810 ld_block_size = MR_LdBlockSizeGet(device_id, map_ptr, sc); 811 812 if ((MR_TargetIdToLdGet(device_id, map_ptr) >= MAX_LOGICAL_DRIVES_EXT) || 813 (!sc->fast_path_io)) { 814 io_request->RaidContext.regLockFlags = 0; 815 fp_possible = 0; 816 } else { 817 if (MR_BuildRaidContext(sc, &io_info, &io_request->RaidContext, map_ptr)) 818 fp_possible = io_info.fpOkForIo; 819 } 820 821 cmd->request_desc->SCSIIO.MSIxIndex = 822 sc->msix_vectors ? smp_processor_id() % sc->msix_vectors : 0; 823 824 825 if (fp_possible) { 826 mrsas_set_pd_lba(io_request, csio->cdb_len, &io_info, ccb, map_ptr, 827 start_lba_lo, ld_block_size); 828 io_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST; 829 cmd->request_desc->SCSIIO.RequestFlags = 830 (MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY << 831 MRSAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT); 832 if ((sc->device_id == MRSAS_INVADER) || (sc->device_id == MRSAS_FURY)) { 833 if (io_request->RaidContext.regLockFlags == REGION_TYPE_UNUSED) 834 cmd->request_desc->SCSIIO.RequestFlags = 835 (MRSAS_REQ_DESCRIPT_FLAGS_NO_LOCK << 836 MRSAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT); 837 io_request->RaidContext.Type = MPI2_TYPE_CUDA; 838 io_request->RaidContext.nseg = 0x1; 839 io_request->IoFlags |= MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH; 840 io_request->RaidContext.regLockFlags |= 841 (MR_RL_FLAGS_GRANT_DESTINATION_CUDA | 842 MR_RL_FLAGS_SEQ_NUM_ENABLE); 843 } 844 if ((sc->load_balance_info[device_id].loadBalanceFlag) && 845 (io_info.isRead)) { 846 io_info.devHandle =
| 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 606 * initializes it. 607 */ 608struct mrsas_mpt_cmd * 609mrsas_get_mpt_cmd(struct mrsas_softc *sc) 610{ 611 struct mrsas_mpt_cmd *cmd = NULL; 612 613 mtx_lock(&sc->mpt_cmd_pool_lock); 614 if (!TAILQ_EMPTY(&sc->mrsas_mpt_cmd_list_head)) { 615 cmd = TAILQ_FIRST(&sc->mrsas_mpt_cmd_list_head); 616 TAILQ_REMOVE(&sc->mrsas_mpt_cmd_list_head, cmd, next); 617 } 618 memset((uint8_t *)cmd->io_request, 0, MRSAS_MPI2_RAID_DEFAULT_IO_FRAME_SIZE); 619 cmd->data = NULL; 620 cmd->length = 0; 621 cmd->flags = 0; 622 cmd->error_code = 0; 623 cmd->load_balance = 0; 624 cmd->ccb_ptr = NULL; 625 mtx_unlock(&sc->mpt_cmd_pool_lock); 626 627 return cmd; 628} 629 630/* 631 * mrsas_release_mpt_cmd: Return a cmd to free command pool 632 * input: Command packet for return to free command pool 633 * 634 * This function returns an MPT command to the free command list. 635 */ 636void 637mrsas_release_mpt_cmd(struct mrsas_mpt_cmd *cmd) 638{ 639 struct mrsas_softc *sc = cmd->sc; 640 641 mtx_lock(&sc->mpt_cmd_pool_lock); 642 cmd->sync_cmd_idx = (u_int32_t)MRSAS_ULONG_MAX; 643 TAILQ_INSERT_TAIL(&(sc->mrsas_mpt_cmd_list_head), cmd, next); 644 mtx_unlock(&sc->mpt_cmd_pool_lock); 645 646 return; 647} 648 649/* 650 * mrsas_get_request_desc: Get request descriptor from array 651 * input: Adapter instance soft state 652 * SMID index 653 * 654 * This function returns a pointer to the request descriptor. 655 */ 656MRSAS_REQUEST_DESCRIPTOR_UNION * 657mrsas_get_request_desc(struct mrsas_softc *sc, u_int16_t index) 658{ 659 u_int8_t *p; 660 661 if (index >= sc->max_fw_cmds) { 662 device_printf(sc->mrsas_dev, "Invalid SMID (0x%x)request for desc\n", index); 663 return NULL; 664 } 665 p = sc->req_desc + sizeof(MRSAS_REQUEST_DESCRIPTOR_UNION) * index; 666 667 return (MRSAS_REQUEST_DESCRIPTOR_UNION *) p; 668} 669 670/* 671 * mrsas_build_ldio: Builds an LDIO command 672 * input: Adapter instance soft state 673 * Pointer to command packet 674 * Pointer to CCB 675 * 676 * This function builds the LDIO command packet. It returns 0 if the command is 677 * built successfully, otherwise it returns a 1. 678 */ 679int 680mrsas_build_ldio(struct mrsas_softc *sc, struct mrsas_mpt_cmd *cmd, 681 union ccb *ccb) 682{ 683 struct ccb_hdr *ccb_h = &(ccb->ccb_h); 684 struct ccb_scsiio *csio = &(ccb->csio); 685 u_int32_t device_id; 686 MRSAS_RAID_SCSI_IO_REQUEST *io_request; 687 688 device_id = ccb_h->target_id; 689 690 io_request = cmd->io_request; 691 io_request->RaidContext.VirtualDiskTgtId = device_id; 692 io_request->RaidContext.status = 0; 693 io_request->RaidContext.exStatus = 0; 694 695 /* just the cdb len, other flags zero, and ORed-in later for FP */ 696 io_request->IoFlags = csio->cdb_len; 697 698 if (mrsas_setup_io(sc, cmd, ccb, device_id, io_request) != SUCCESS) 699 device_printf(sc->mrsas_dev, "Build ldio or fpio error\n"); 700 701 io_request->DataLength = cmd->length; 702 703 if (mrsas_map_request(sc, cmd, ccb) == SUCCESS) { 704 if (cmd->sge_count > MRSAS_MAX_SGL) { 705 device_printf(sc->mrsas_dev, "Error: sge_count (0x%x) exceeds" 706 "max (0x%x) allowed\n", cmd->sge_count, sc->max_num_sge); 707 return (FAIL); 708 } 709 io_request->RaidContext.numSGE = cmd->sge_count; 710 } else { 711 device_printf(sc->mrsas_dev, "Data map/load failed.\n"); 712 return (FAIL); 713 } 714 return (0); 715} 716 717/* 718 * mrsas_setup_io: Set up data including Fast Path I/O 719 * input: Adapter instance soft state 720 * Pointer to command packet 721 * Pointer to CCB 722 * 723 * This function builds the DCDB inquiry command. It returns 0 if the command 724 * is built successfully, otherwise it returns a 1. 725 */ 726int 727mrsas_setup_io(struct mrsas_softc *sc, struct mrsas_mpt_cmd *cmd, 728 union ccb *ccb, u_int32_t device_id, 729 MRSAS_RAID_SCSI_IO_REQUEST * io_request) 730{ 731 struct ccb_hdr *ccb_h = &(ccb->ccb_h); 732 struct ccb_scsiio *csio = &(ccb->csio); 733 struct IO_REQUEST_INFO io_info; 734 MR_DRV_RAID_MAP_ALL *map_ptr; 735 u_int8_t fp_possible; 736 u_int32_t start_lba_hi, start_lba_lo, ld_block_size; 737 u_int32_t datalength = 0; 738 739 start_lba_lo = 0; 740 start_lba_hi = 0; 741 fp_possible = 0; 742 743 /* 744 * READ_6 (0x08) or WRITE_6 (0x0A) cdb 745 */ 746 if (csio->cdb_len == 6) { 747 datalength = (u_int32_t)csio->cdb_io.cdb_bytes[4]; 748 start_lba_lo = ((u_int32_t)csio->cdb_io.cdb_bytes[1] << 16) | 749 ((u_int32_t)csio->cdb_io.cdb_bytes[2] << 8) | 750 (u_int32_t)csio->cdb_io.cdb_bytes[3]; 751 start_lba_lo &= 0x1FFFFF; 752 } 753 /* 754 * READ_10 (0x28) or WRITE_6 (0x2A) cdb 755 */ 756 else if (csio->cdb_len == 10) { 757 datalength = (u_int32_t)csio->cdb_io.cdb_bytes[8] | 758 ((u_int32_t)csio->cdb_io.cdb_bytes[7] << 8); 759 start_lba_lo = ((u_int32_t)csio->cdb_io.cdb_bytes[2] << 24) | 760 ((u_int32_t)csio->cdb_io.cdb_bytes[3] << 16) | 761 (u_int32_t)csio->cdb_io.cdb_bytes[4] << 8 | 762 ((u_int32_t)csio->cdb_io.cdb_bytes[5]); 763 } 764 /* 765 * READ_12 (0xA8) or WRITE_12 (0xAA) cdb 766 */ 767 else if (csio->cdb_len == 12) { 768 datalength = (u_int32_t)csio->cdb_io.cdb_bytes[6] << 24 | 769 ((u_int32_t)csio->cdb_io.cdb_bytes[7] << 16) | 770 ((u_int32_t)csio->cdb_io.cdb_bytes[8] << 8) | 771 ((u_int32_t)csio->cdb_io.cdb_bytes[9]); 772 start_lba_lo = ((u_int32_t)csio->cdb_io.cdb_bytes[2] << 24) | 773 ((u_int32_t)csio->cdb_io.cdb_bytes[3] << 16) | 774 (u_int32_t)csio->cdb_io.cdb_bytes[4] << 8 | 775 ((u_int32_t)csio->cdb_io.cdb_bytes[5]); 776 } 777 /* 778 * READ_16 (0x88) or WRITE_16 (0xx8A) cdb 779 */ 780 else if (csio->cdb_len == 16) { 781 datalength = (u_int32_t)csio->cdb_io.cdb_bytes[10] << 24 | 782 ((u_int32_t)csio->cdb_io.cdb_bytes[11] << 16) | 783 ((u_int32_t)csio->cdb_io.cdb_bytes[12] << 8) | 784 ((u_int32_t)csio->cdb_io.cdb_bytes[13]); 785 start_lba_lo = ((u_int32_t)csio->cdb_io.cdb_bytes[6] << 24) | 786 ((u_int32_t)csio->cdb_io.cdb_bytes[7] << 16) | 787 (u_int32_t)csio->cdb_io.cdb_bytes[8] << 8 | 788 ((u_int32_t)csio->cdb_io.cdb_bytes[9]); 789 start_lba_hi = ((u_int32_t)csio->cdb_io.cdb_bytes[2] << 24) | 790 ((u_int32_t)csio->cdb_io.cdb_bytes[3] << 16) | 791 (u_int32_t)csio->cdb_io.cdb_bytes[4] << 8 | 792 ((u_int32_t)csio->cdb_io.cdb_bytes[5]); 793 } 794 memset(&io_info, 0, sizeof(struct IO_REQUEST_INFO)); 795 io_info.ldStartBlock = ((u_int64_t)start_lba_hi << 32) | start_lba_lo; 796 io_info.numBlocks = datalength; 797 io_info.ldTgtId = device_id; 798 799 switch (ccb_h->flags & CAM_DIR_MASK) { 800 case CAM_DIR_IN: 801 io_info.isRead = 1; 802 break; 803 case CAM_DIR_OUT: 804 io_info.isRead = 0; 805 break; 806 case CAM_DIR_NONE: 807 default: 808 mrsas_dprint(sc, MRSAS_TRACE, "From %s : DMA Flag is %d \n", __func__, ccb_h->flags & CAM_DIR_MASK); 809 break; 810 } 811 812 map_ptr = sc->ld_drv_map[(sc->map_id & 1)]; 813 ld_block_size = MR_LdBlockSizeGet(device_id, map_ptr, sc); 814 815 if ((MR_TargetIdToLdGet(device_id, map_ptr) >= MAX_LOGICAL_DRIVES_EXT) || 816 (!sc->fast_path_io)) { 817 io_request->RaidContext.regLockFlags = 0; 818 fp_possible = 0; 819 } else { 820 if (MR_BuildRaidContext(sc, &io_info, &io_request->RaidContext, map_ptr)) 821 fp_possible = io_info.fpOkForIo; 822 } 823 824 cmd->request_desc->SCSIIO.MSIxIndex = 825 sc->msix_vectors ? smp_processor_id() % sc->msix_vectors : 0; 826 827 828 if (fp_possible) { 829 mrsas_set_pd_lba(io_request, csio->cdb_len, &io_info, ccb, map_ptr, 830 start_lba_lo, ld_block_size); 831 io_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST; 832 cmd->request_desc->SCSIIO.RequestFlags = 833 (MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY << 834 MRSAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT); 835 if ((sc->device_id == MRSAS_INVADER) || (sc->device_id == MRSAS_FURY)) { 836 if (io_request->RaidContext.regLockFlags == REGION_TYPE_UNUSED) 837 cmd->request_desc->SCSIIO.RequestFlags = 838 (MRSAS_REQ_DESCRIPT_FLAGS_NO_LOCK << 839 MRSAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT); 840 io_request->RaidContext.Type = MPI2_TYPE_CUDA; 841 io_request->RaidContext.nseg = 0x1; 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 =
|
847 mrsas_get_updated_dev_handle(sc, 848 &sc->load_balance_info[device_id], &io_info);
| 850 mrsas_get_updated_dev_handle(sc, 851 &sc->load_balance_info[device_id], &io_info);
|
849 cmd->load_balance = MRSAS_LOAD_BALANCE_FLAG; 850 cmd->pd_r1_lb = io_info.pd_after_lb; 851 } else 852 cmd->load_balance = 0; 853 cmd->request_desc->SCSIIO.DevHandle = io_info.devHandle; 854 io_request->DevHandle = io_info.devHandle; 855 } else { 856 /* Not FP IO */ 857 io_request->RaidContext.timeoutValue = map_ptr->raidMap.fpPdIoTimeoutSec; 858 cmd->request_desc->SCSIIO.RequestFlags = 859 (MRSAS_REQ_DESCRIPT_FLAGS_LD_IO << 860 MRSAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT); 861 if ((sc->device_id == MRSAS_INVADER) || (sc->device_id == MRSAS_FURY)) { 862 if (io_request->RaidContext.regLockFlags == REGION_TYPE_UNUSED) 863 cmd->request_desc->SCSIIO.RequestFlags = 864 (MRSAS_REQ_DESCRIPT_FLAGS_NO_LOCK << 865 MRSAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT); 866 io_request->RaidContext.Type = MPI2_TYPE_CUDA; 867 io_request->RaidContext.regLockFlags |= 868 (MR_RL_FLAGS_GRANT_DESTINATION_CPU0 | 869 MR_RL_FLAGS_SEQ_NUM_ENABLE); 870 io_request->RaidContext.nseg = 0x1; 871 } 872 io_request->Function = MRSAS_MPI2_FUNCTION_LD_IO_REQUEST; 873 io_request->DevHandle = device_id; 874 } 875 return (0); 876} 877 878/* 879 * mrsas_build_dcdb: Builds an DCDB command 880 * input: Adapter instance soft state 881 * Pointer to command packet 882 * Pointer to CCB 883 * 884 * This function builds the DCDB inquiry command. It returns 0 if the command 885 * is built successfully, otherwise it returns a 1. 886 */ 887int 888mrsas_build_dcdb(struct mrsas_softc *sc, struct mrsas_mpt_cmd *cmd, 889 union ccb *ccb, struct cam_sim *sim) 890{ 891 struct ccb_hdr *ccb_h = &(ccb->ccb_h); 892 u_int32_t device_id; 893 MR_DRV_RAID_MAP_ALL *map_ptr; 894 MRSAS_RAID_SCSI_IO_REQUEST *io_request; 895 896 io_request = cmd->io_request; 897 device_id = ccb_h->target_id; 898 map_ptr = sc->ld_drv_map[(sc->map_id & 1)]; 899
| 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 */ 860 io_request->RaidContext.timeoutValue = map_ptr->raidMap.fpPdIoTimeoutSec; 861 cmd->request_desc->SCSIIO.RequestFlags = 862 (MRSAS_REQ_DESCRIPT_FLAGS_LD_IO << 863 MRSAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT); 864 if ((sc->device_id == MRSAS_INVADER) || (sc->device_id == MRSAS_FURY)) { 865 if (io_request->RaidContext.regLockFlags == REGION_TYPE_UNUSED) 866 cmd->request_desc->SCSIIO.RequestFlags = 867 (MRSAS_REQ_DESCRIPT_FLAGS_NO_LOCK << 868 MRSAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT); 869 io_request->RaidContext.Type = MPI2_TYPE_CUDA; 870 io_request->RaidContext.regLockFlags |= 871 (MR_RL_FLAGS_GRANT_DESTINATION_CPU0 | 872 MR_RL_FLAGS_SEQ_NUM_ENABLE); 873 io_request->RaidContext.nseg = 0x1; 874 } 875 io_request->Function = MRSAS_MPI2_FUNCTION_LD_IO_REQUEST; 876 io_request->DevHandle = device_id; 877 } 878 return (0); 879} 880 881/* 882 * mrsas_build_dcdb: Builds an DCDB command 883 * input: Adapter instance soft state 884 * Pointer to command packet 885 * Pointer to CCB 886 * 887 * This function builds the DCDB inquiry command. It returns 0 if the command 888 * is built successfully, otherwise it returns a 1. 889 */ 890int 891mrsas_build_dcdb(struct mrsas_softc *sc, struct mrsas_mpt_cmd *cmd, 892 union ccb *ccb, struct cam_sim *sim) 893{ 894 struct ccb_hdr *ccb_h = &(ccb->ccb_h); 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
|
900 /* 901 * Check if this is RW for system PD or 902 * it's a NON RW for sys PD and there is NO secure jbod FW support 903 */
| 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 */
|
904 if (cam_sim_bus(sim) == 1 &&
| 907 if (cam_sim_bus(sim) == 1 &&
|
905 sc->pd_list[device_id].driveState == MR_PD_STATE_SYSTEM){
| 908 sc->pd_list[device_id].driveState == MR_PD_STATE_SYSTEM) {
|
906 907 io_request->DevHandle =
| 909 910 io_request->DevHandle =
|
908 map_ptr->raidMap.devHndlInfo[device_id].curDevHdl;
| 911 map_ptr->raidMap.devHndlInfo[device_id].curDevHdl;
|
909 io_request->RaidContext.RAIDFlags =
| 912 io_request->RaidContext.RAIDFlags =
|
910 MR_RAID_FLAGS_IO_SUB_TYPE_SYSTEM_PD << 911 MR_RAID_CTX_RAID_FLAGS_IO_SUB_TYPE_SHIFT;
| 913 MR_RAID_FLAGS_IO_SUB_TYPE_SYSTEM_PD << 914 MR_RAID_CTX_RAID_FLAGS_IO_SUB_TYPE_SHIFT;
|
912 cmd->request_desc->SCSIIO.DevHandle = io_request->DevHandle; 913 cmd->request_desc->SCSIIO.MSIxIndex =
| 915 cmd->request_desc->SCSIIO.DevHandle = io_request->DevHandle; 916 cmd->request_desc->SCSIIO.MSIxIndex =
|
914 sc->msix_vectors ? smp_processor_id() % sc->msix_vectors : 0;
| 917 sc->msix_vectors ? smp_processor_id() % sc->msix_vectors : 0;
|
915
| 918
|
916 if(sc->secure_jbod_support && (mrsas_find_io_type(sim, ccb) == NON_READ_WRITE_SYSPDIO)) {
| 919 if (sc->secure_jbod_support && (mrsas_find_io_type(sim, ccb) == NON_READ_WRITE_SYSPDIO)) {
|
917 /* system pd firmware path */
| 920 /* system pd firmware path */
|
918 io_request->Function = MRSAS_MPI2_FUNCTION_LD_IO_REQUEST;
| 921 io_request->Function = MRSAS_MPI2_FUNCTION_LD_IO_REQUEST;
|
919 cmd->request_desc->SCSIIO.RequestFlags =
| 922 cmd->request_desc->SCSIIO.RequestFlags =
|
920 (MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO << MRSAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
| 923 (MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO << MRSAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
|
921 } else { 922 /* system pd fast path */ 923 io_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST; 924 io_request->RaidContext.timeoutValue = map_ptr->raidMap.fpPdIoTimeoutSec; 925 io_request->RaidContext.regLockFlags = 0; 926 io_request->RaidContext.regLockRowLBA = 0; 927 io_request->RaidContext.regLockLength = 0; 928 929 cmd->request_desc->SCSIIO.RequestFlags =
| 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 =
|
930 (MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY << 931 MRSAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
| 933 (MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY << 934 MRSAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
|
932 933 /* 934 * NOTE - For system pd RW cmds only IoFlags will be FAST_PATH 935 * Because the NON RW cmds will now go via FW Queue 936 * and not the Exception queue 937 */ 938 if ((sc->device_id == MRSAS_INVADER) || (sc->device_id == MRSAS_FURY)) 939 io_request->IoFlags |= MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH;
| 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;
|
940 }
| 943 }
|
941 } else {
| 944 } else {
|
942 /* FW path for SysPD or LD Non-RW (SCSI management commands)*/ 943 io_request->Function = MRSAS_MPI2_FUNCTION_LD_IO_REQUEST;
| 945 /* FW path for SysPD or LD Non-RW (SCSI management commands) */ 946 io_request->Function = MRSAS_MPI2_FUNCTION_LD_IO_REQUEST;
|
944 io_request->DevHandle = device_id; 945 cmd->request_desc->SCSIIO.RequestFlags =
| 947 io_request->DevHandle = device_id; 948 cmd->request_desc->SCSIIO.RequestFlags =
|
946 (MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO << 947 MRSAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
| 949 (MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO << 950 MRSAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
|
948 } 949 950 io_request->RaidContext.VirtualDiskTgtId = device_id; 951 io_request->LUN[1] = ccb_h->target_lun & 0xF; 952 io_request->DataLength = cmd->length; 953 954 if (mrsas_map_request(sc, cmd, ccb) == SUCCESS) { 955 if (cmd->sge_count > sc->max_num_sge) { 956 device_printf(sc->mrsas_dev, "Error: sge_count (0x%x) exceeds" 957 "max (0x%x) allowed\n", cmd->sge_count, sc->max_num_sge); 958 return (1); 959 } 960 io_request->RaidContext.numSGE = cmd->sge_count; 961 } else { 962 device_printf(sc->mrsas_dev, "Data map/load failed.\n"); 963 return (1); 964 } 965 return (0); 966} 967 968/* 969 * mrsas_map_request: Map and load data 970 * input: Adapter instance soft state 971 * Pointer to command packet 972 * 973 * For data from OS, map and load the data buffer into bus space. The SG list 974 * is built in the callback. If the bus dmamap load is not successful, 975 * cmd->error_code will contain the error code and a 1 is returned. 976 */
| 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) { 959 device_printf(sc->mrsas_dev, "Error: sge_count (0x%x) exceeds" 960 "max (0x%x) allowed\n", cmd->sge_count, sc->max_num_sge); 961 return (1); 962 } 963 io_request->RaidContext.numSGE = cmd->sge_count; 964 } else { 965 device_printf(sc->mrsas_dev, "Data map/load failed.\n"); 966 return (1); 967 } 968 return (0); 969} 970 971/* 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 */
|
977int mrsas_map_request(struct mrsas_softc *sc, 978 struct mrsas_mpt_cmd *cmd, union ccb *ccb)
| 980int 981mrsas_map_request(struct mrsas_softc *sc, 982 struct mrsas_mpt_cmd *cmd, union ccb *ccb)
|
979{ 980 u_int32_t retcode = 0; 981 struct cam_sim *sim; 982 983 sim = xpt_path_sim(cmd->ccb_ptr->ccb_h.path); 984 985 if (cmd->data != NULL) { 986 /* Map data buffer into bus space */ 987 mtx_lock(&sc->io_lock); 988#if (__FreeBSD_version >= 902001) 989 retcode = bus_dmamap_load_ccb(sc->data_tag, cmd->data_dmamap, 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,
|
990 mrsas_data_load_cb, cmd, 0);
| 994 mrsas_data_load_cb, cmd, 0);
|
991#else 992 retcode = bus_dmamap_load(sc->data_tag, cmd->data_dmamap, cmd->data,
| 995#else 996 retcode = bus_dmamap_load(sc->data_tag, cmd->data_dmamap, cmd->data,
|
993 cmd->length, mrsas_data_load_cb, cmd, BUS_DMA_NOWAIT);
| 997 cmd->length, mrsas_data_load_cb, cmd, BUS_DMA_NOWAIT);
|
994#endif 995 mtx_unlock(&sc->io_lock); 996 if (retcode) 997 device_printf(sc->mrsas_dev, "bus_dmamap_load(): retcode = %d\n", retcode); 998 if (retcode == EINPROGRESS) { 999 device_printf(sc->mrsas_dev, "request load in progress\n"); 1000 mrsas_freeze_simq(cmd, sim); 1001 } 1002 } 1003 if (cmd->error_code) 1004 return (1); 1005 return (retcode); 1006} 1007 1008/* 1009 * mrsas_unmap_request: Unmap and unload data 1010 * input: Adapter instance soft state 1011 * Pointer to command packet 1012 * 1013 * This function unmaps and unloads data from OS. 1014 */ 1015void 1016mrsas_unmap_request(struct mrsas_softc *sc, struct mrsas_mpt_cmd *cmd) 1017{ 1018 if (cmd->data != NULL) { 1019 if (cmd->flags & MRSAS_DIR_IN) 1020 bus_dmamap_sync(sc->data_tag, cmd->data_dmamap, BUS_DMASYNC_POSTREAD); 1021 if (cmd->flags & MRSAS_DIR_OUT) 1022 bus_dmamap_sync(sc->data_tag, cmd->data_dmamap, BUS_DMASYNC_POSTWRITE); 1023 mtx_lock(&sc->io_lock); 1024 bus_dmamap_unload(sc->data_tag, cmd->data_dmamap); 1025 mtx_unlock(&sc->io_lock); 1026 } 1027} 1028 1029/* 1030 * mrsas_data_load_cb: Callback entry point 1031 * input: Pointer to command packet as argument 1032 * Pointer to segment 1033 * Number of segments Error 1034 * 1035 * This is the callback function of the bus dma map load. It builds the SG 1036 * list. 1037 */ 1038static void 1039mrsas_data_load_cb(void *arg, bus_dma_segment_t *segs, int nseg, int error) 1040{ 1041 struct mrsas_mpt_cmd *cmd = (struct mrsas_mpt_cmd *)arg; 1042 struct mrsas_softc *sc = cmd->sc; 1043 MRSAS_RAID_SCSI_IO_REQUEST *io_request; 1044 pMpi25IeeeSgeChain64_t sgl_ptr; 1045 int i = 0, sg_processed = 0; 1046 1047 if (error) { 1048 cmd->error_code = error; 1049 device_printf(sc->mrsas_dev, "mrsas_data_load_cb: error=%d\n", error); 1050 if (error == EFBIG) { 1051 cmd->ccb_ptr->ccb_h.status = CAM_REQ_TOO_BIG; 1052 return; 1053 } 1054 } 1055 if (cmd->flags & MRSAS_DIR_IN) 1056 bus_dmamap_sync(cmd->sc->data_tag, cmd->data_dmamap, 1057 BUS_DMASYNC_PREREAD); 1058 if (cmd->flags & MRSAS_DIR_OUT) 1059 bus_dmamap_sync(cmd->sc->data_tag, cmd->data_dmamap, 1060 BUS_DMASYNC_PREWRITE); 1061 if (nseg > sc->max_num_sge) { 1062 device_printf(sc->mrsas_dev, "SGE count is too large or 0.\n"); 1063 return; 1064 } 1065 io_request = cmd->io_request; 1066 sgl_ptr = (pMpi25IeeeSgeChain64_t)&io_request->SGL; 1067 1068 if ((sc->device_id == MRSAS_INVADER) || (sc->device_id == MRSAS_FURY)) { 1069 pMpi25IeeeSgeChain64_t sgl_ptr_end = sgl_ptr; 1070 1071 sgl_ptr_end += sc->max_sge_in_main_msg - 1; 1072 sgl_ptr_end->Flags = 0; 1073 } 1074 if (nseg != 0) { 1075 for (i = 0; i < nseg; i++) { 1076 sgl_ptr->Address = segs[i].ds_addr; 1077 sgl_ptr->Length = segs[i].ds_len; 1078 sgl_ptr->Flags = 0; 1079 if ((sc->device_id == MRSAS_INVADER) || (sc->device_id == MRSAS_FURY)) { 1080 if (i == nseg - 1) 1081 sgl_ptr->Flags = IEEE_SGE_FLAGS_END_OF_LIST; 1082 } 1083 sgl_ptr++; 1084 sg_processed = i + 1; 1085 if ((sg_processed == (sc->max_sge_in_main_msg - 1)) && 1086 (nseg > sc->max_sge_in_main_msg)) { 1087 pMpi25IeeeSgeChain64_t sg_chain; 1088 1089 if ((sc->device_id == MRSAS_INVADER) || (sc->device_id == MRSAS_FURY)) { 1090 if ((cmd->io_request->IoFlags & MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH) 1091 != MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH) 1092 cmd->io_request->ChainOffset = sc->chain_offset_io_request; 1093 else 1094 cmd->io_request->ChainOffset = 0; 1095 } else 1096 cmd->io_request->ChainOffset = sc->chain_offset_io_request; 1097 sg_chain = sgl_ptr; 1098 if ((sc->device_id == MRSAS_INVADER) || (sc->device_id == MRSAS_FURY)) 1099 sg_chain->Flags = IEEE_SGE_FLAGS_CHAIN_ELEMENT; 1100 else 1101 sg_chain->Flags = (IEEE_SGE_FLAGS_CHAIN_ELEMENT | MPI2_IEEE_SGE_FLAGS_IOCPLBNTA_ADDR); 1102 sg_chain->Length = (sizeof(MPI2_SGE_IO_UNION) * (nseg - sg_processed)); 1103 sg_chain->Address = cmd->chain_frame_phys_addr; 1104 sgl_ptr = (pMpi25IeeeSgeChain64_t)cmd->chain_frame; 1105 } 1106 } 1107 } 1108 cmd->sge_count = nseg; 1109} 1110 1111/* 1112 * mrsas_freeze_simq: Freeze SIM queue 1113 * input: Pointer to command packet 1114 * Pointer to SIM 1115 * 1116 * This function freezes the sim queue. 1117 */ 1118static void 1119mrsas_freeze_simq(struct mrsas_mpt_cmd *cmd, struct cam_sim *sim) 1120{ 1121 union ccb *ccb = (union ccb *)(cmd->ccb_ptr); 1122 1123 xpt_freeze_simq(sim, 1); 1124 ccb->ccb_h.status |= CAM_RELEASE_SIMQ; 1125 ccb->ccb_h.status |= CAM_REQUEUE_REQ; 1126} 1127 1128void 1129mrsas_xpt_freeze(struct mrsas_softc *sc) 1130{ 1131 xpt_freeze_simq(sc->sim_0, 1); 1132 xpt_freeze_simq(sc->sim_1, 1); 1133} 1134 1135void 1136mrsas_xpt_release(struct mrsas_softc *sc) 1137{ 1138 xpt_release_simq(sc->sim_0, 1); 1139 xpt_release_simq(sc->sim_1, 1); 1140} 1141 1142/* 1143 * mrsas_cmd_done: Perform remaining command completion 1144 * input: Adapter instance soft state Pointer to command packet 1145 * 1146 * This function calls ummap request and releases the MPT command. 1147 */ 1148void 1149mrsas_cmd_done(struct mrsas_softc *sc, struct mrsas_mpt_cmd *cmd) 1150{ 1151 callout_stop(&cmd->cm_callout); 1152 mrsas_unmap_request(sc, cmd); 1153 mtx_lock(&sc->sim_lock); 1154 xpt_done(cmd->ccb_ptr); 1155 cmd->ccb_ptr = NULL; 1156 mtx_unlock(&sc->sim_lock); 1157 mrsas_release_mpt_cmd(cmd); 1158} 1159 1160/* 1161 * mrsas_cam_poll: Polling entry point 1162 * input: Pointer to SIM 1163 * 1164 * This is currently a stub function. 1165 */ 1166static void 1167mrsas_cam_poll(struct cam_sim *sim) 1168{ 1169 struct mrsas_softc *sc = (struct mrsas_softc *)cam_sim_softc(sim); 1170 1171 mrsas_isr((void *)sc); 1172} 1173 1174/* 1175 * mrsas_bus_scan: Perform bus scan 1176 * input: Adapter instance soft state 1177 * 1178 * This mrsas_bus_scan function is needed for FreeBSD 7.x. Also, it should not 1179 * be called in FreeBSD 8.x and later versions, where the bus scan is 1180 * automatic. 1181 */ 1182int 1183mrsas_bus_scan(struct mrsas_softc *sc) 1184{ 1185 union ccb *ccb_0; 1186 union ccb *ccb_1; 1187 1188 if ((ccb_0 = xpt_alloc_ccb()) == NULL) { 1189 return (ENOMEM); 1190 } 1191 if ((ccb_1 = xpt_alloc_ccb()) == NULL) { 1192 xpt_free_ccb(ccb_0); 1193 return (ENOMEM); 1194 } 1195 mtx_lock(&sc->sim_lock); 1196 if (xpt_create_path(&ccb_0->ccb_h.path, xpt_periph, cam_sim_path(sc->sim_0), 1197 CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD) != CAM_REQ_CMP) { 1198 xpt_free_ccb(ccb_0); 1199 xpt_free_ccb(ccb_1); 1200 mtx_unlock(&sc->sim_lock); 1201 return (EIO); 1202 } 1203 if (xpt_create_path(&ccb_1->ccb_h.path, xpt_periph, cam_sim_path(sc->sim_1), 1204 CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD) != CAM_REQ_CMP) { 1205 xpt_free_ccb(ccb_0); 1206 xpt_free_ccb(ccb_1); 1207 mtx_unlock(&sc->sim_lock); 1208 return (EIO); 1209 } 1210 mtx_unlock(&sc->sim_lock); 1211 xpt_rescan(ccb_0); 1212 xpt_rescan(ccb_1); 1213 1214 return (0); 1215} 1216 1217/* 1218 * mrsas_bus_scan_sim: Perform bus scan per SIM 1219 * input: adapter instance soft state 1220 * 1221 * This function will be called from Event handler on LD creation/deletion, 1222 * JBOD on/off. 1223 */ 1224int 1225mrsas_bus_scan_sim(struct mrsas_softc *sc, struct cam_sim *sim) 1226{ 1227 union ccb *ccb; 1228 1229 if ((ccb = xpt_alloc_ccb()) == NULL) { 1230 return (ENOMEM); 1231 } 1232 mtx_lock(&sc->sim_lock); 1233 if (xpt_create_path(&ccb->ccb_h.path, xpt_periph, cam_sim_path(sim), 1234 CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD) != CAM_REQ_CMP) { 1235 xpt_free_ccb(ccb); 1236 mtx_unlock(&sc->sim_lock); 1237 return (EIO); 1238 } 1239 mtx_unlock(&sc->sim_lock); 1240 xpt_rescan(ccb); 1241 1242 return (0); 1243}
| 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 } 1006 } 1007 if (cmd->error_code) 1008 return (1); 1009 return (retcode); 1010} 1011 1012/* 1013 * mrsas_unmap_request: Unmap and unload data 1014 * input: Adapter instance soft state 1015 * Pointer to command packet 1016 * 1017 * This function unmaps and unloads data from OS. 1018 */ 1019void 1020mrsas_unmap_request(struct mrsas_softc *sc, struct mrsas_mpt_cmd *cmd) 1021{ 1022 if (cmd->data != NULL) { 1023 if (cmd->flags & MRSAS_DIR_IN) 1024 bus_dmamap_sync(sc->data_tag, cmd->data_dmamap, BUS_DMASYNC_POSTREAD); 1025 if (cmd->flags & MRSAS_DIR_OUT) 1026 bus_dmamap_sync(sc->data_tag, cmd->data_dmamap, BUS_DMASYNC_POSTWRITE); 1027 mtx_lock(&sc->io_lock); 1028 bus_dmamap_unload(sc->data_tag, cmd->data_dmamap); 1029 mtx_unlock(&sc->io_lock); 1030 } 1031} 1032 1033/* 1034 * mrsas_data_load_cb: Callback entry point 1035 * input: Pointer to command packet as argument 1036 * Pointer to segment 1037 * Number of segments Error 1038 * 1039 * This is the callback function of the bus dma map load. It builds the SG 1040 * list. 1041 */ 1042static void 1043mrsas_data_load_cb(void *arg, bus_dma_segment_t *segs, int nseg, int error) 1044{ 1045 struct mrsas_mpt_cmd *cmd = (struct mrsas_mpt_cmd *)arg; 1046 struct mrsas_softc *sc = cmd->sc; 1047 MRSAS_RAID_SCSI_IO_REQUEST *io_request; 1048 pMpi25IeeeSgeChain64_t sgl_ptr; 1049 int i = 0, sg_processed = 0; 1050 1051 if (error) { 1052 cmd->error_code = error; 1053 device_printf(sc->mrsas_dev, "mrsas_data_load_cb: error=%d\n", error); 1054 if (error == EFBIG) { 1055 cmd->ccb_ptr->ccb_h.status = CAM_REQ_TOO_BIG; 1056 return; 1057 } 1058 } 1059 if (cmd->flags & MRSAS_DIR_IN) 1060 bus_dmamap_sync(cmd->sc->data_tag, cmd->data_dmamap, 1061 BUS_DMASYNC_PREREAD); 1062 if (cmd->flags & MRSAS_DIR_OUT) 1063 bus_dmamap_sync(cmd->sc->data_tag, cmd->data_dmamap, 1064 BUS_DMASYNC_PREWRITE); 1065 if (nseg > sc->max_num_sge) { 1066 device_printf(sc->mrsas_dev, "SGE count is too large or 0.\n"); 1067 return; 1068 } 1069 io_request = cmd->io_request; 1070 sgl_ptr = (pMpi25IeeeSgeChain64_t)&io_request->SGL; 1071 1072 if ((sc->device_id == MRSAS_INVADER) || (sc->device_id == MRSAS_FURY)) { 1073 pMpi25IeeeSgeChain64_t sgl_ptr_end = sgl_ptr; 1074 1075 sgl_ptr_end += sc->max_sge_in_main_msg - 1; 1076 sgl_ptr_end->Flags = 0; 1077 } 1078 if (nseg != 0) { 1079 for (i = 0; i < nseg; i++) { 1080 sgl_ptr->Address = segs[i].ds_addr; 1081 sgl_ptr->Length = segs[i].ds_len; 1082 sgl_ptr->Flags = 0; 1083 if ((sc->device_id == MRSAS_INVADER) || (sc->device_id == MRSAS_FURY)) { 1084 if (i == nseg - 1) 1085 sgl_ptr->Flags = IEEE_SGE_FLAGS_END_OF_LIST; 1086 } 1087 sgl_ptr++; 1088 sg_processed = i + 1; 1089 if ((sg_processed == (sc->max_sge_in_main_msg - 1)) && 1090 (nseg > sc->max_sge_in_main_msg)) { 1091 pMpi25IeeeSgeChain64_t sg_chain; 1092 1093 if ((sc->device_id == MRSAS_INVADER) || (sc->device_id == MRSAS_FURY)) { 1094 if ((cmd->io_request->IoFlags & MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH) 1095 != MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH) 1096 cmd->io_request->ChainOffset = sc->chain_offset_io_request; 1097 else 1098 cmd->io_request->ChainOffset = 0; 1099 } else 1100 cmd->io_request->ChainOffset = sc->chain_offset_io_request; 1101 sg_chain = sgl_ptr; 1102 if ((sc->device_id == MRSAS_INVADER) || (sc->device_id == MRSAS_FURY)) 1103 sg_chain->Flags = IEEE_SGE_FLAGS_CHAIN_ELEMENT; 1104 else 1105 sg_chain->Flags = (IEEE_SGE_FLAGS_CHAIN_ELEMENT | MPI2_IEEE_SGE_FLAGS_IOCPLBNTA_ADDR); 1106 sg_chain->Length = (sizeof(MPI2_SGE_IO_UNION) * (nseg - sg_processed)); 1107 sg_chain->Address = cmd->chain_frame_phys_addr; 1108 sgl_ptr = (pMpi25IeeeSgeChain64_t)cmd->chain_frame; 1109 } 1110 } 1111 } 1112 cmd->sge_count = nseg; 1113} 1114 1115/* 1116 * mrsas_freeze_simq: Freeze SIM queue 1117 * input: Pointer to command packet 1118 * Pointer to SIM 1119 * 1120 * This function freezes the sim queue. 1121 */ 1122static void 1123mrsas_freeze_simq(struct mrsas_mpt_cmd *cmd, struct cam_sim *sim) 1124{ 1125 union ccb *ccb = (union ccb *)(cmd->ccb_ptr); 1126 1127 xpt_freeze_simq(sim, 1); 1128 ccb->ccb_h.status |= CAM_RELEASE_SIMQ; 1129 ccb->ccb_h.status |= CAM_REQUEUE_REQ; 1130} 1131 1132void 1133mrsas_xpt_freeze(struct mrsas_softc *sc) 1134{ 1135 xpt_freeze_simq(sc->sim_0, 1); 1136 xpt_freeze_simq(sc->sim_1, 1); 1137} 1138 1139void 1140mrsas_xpt_release(struct mrsas_softc *sc) 1141{ 1142 xpt_release_simq(sc->sim_0, 1); 1143 xpt_release_simq(sc->sim_1, 1); 1144} 1145 1146/* 1147 * mrsas_cmd_done: Perform remaining command completion 1148 * input: Adapter instance soft state Pointer to command packet 1149 * 1150 * This function calls ummap request and releases the MPT command. 1151 */ 1152void 1153mrsas_cmd_done(struct mrsas_softc *sc, struct mrsas_mpt_cmd *cmd) 1154{ 1155 callout_stop(&cmd->cm_callout); 1156 mrsas_unmap_request(sc, cmd); 1157 mtx_lock(&sc->sim_lock); 1158 xpt_done(cmd->ccb_ptr); 1159 cmd->ccb_ptr = NULL; 1160 mtx_unlock(&sc->sim_lock); 1161 mrsas_release_mpt_cmd(cmd); 1162} 1163 1164/* 1165 * mrsas_cam_poll: Polling entry point 1166 * input: Pointer to SIM 1167 * 1168 * This is currently a stub function. 1169 */ 1170static void 1171mrsas_cam_poll(struct cam_sim *sim) 1172{ 1173 struct mrsas_softc *sc = (struct mrsas_softc *)cam_sim_softc(sim); 1174 1175 mrsas_isr((void *)sc); 1176} 1177 1178/* 1179 * mrsas_bus_scan: Perform bus scan 1180 * input: Adapter instance soft state 1181 * 1182 * This mrsas_bus_scan function is needed for FreeBSD 7.x. Also, it should not 1183 * be called in FreeBSD 8.x and later versions, where the bus scan is 1184 * automatic. 1185 */ 1186int 1187mrsas_bus_scan(struct mrsas_softc *sc) 1188{ 1189 union ccb *ccb_0; 1190 union ccb *ccb_1; 1191 1192 if ((ccb_0 = xpt_alloc_ccb()) == NULL) { 1193 return (ENOMEM); 1194 } 1195 if ((ccb_1 = xpt_alloc_ccb()) == NULL) { 1196 xpt_free_ccb(ccb_0); 1197 return (ENOMEM); 1198 } 1199 mtx_lock(&sc->sim_lock); 1200 if (xpt_create_path(&ccb_0->ccb_h.path, xpt_periph, cam_sim_path(sc->sim_0), 1201 CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD) != CAM_REQ_CMP) { 1202 xpt_free_ccb(ccb_0); 1203 xpt_free_ccb(ccb_1); 1204 mtx_unlock(&sc->sim_lock); 1205 return (EIO); 1206 } 1207 if (xpt_create_path(&ccb_1->ccb_h.path, xpt_periph, cam_sim_path(sc->sim_1), 1208 CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD) != CAM_REQ_CMP) { 1209 xpt_free_ccb(ccb_0); 1210 xpt_free_ccb(ccb_1); 1211 mtx_unlock(&sc->sim_lock); 1212 return (EIO); 1213 } 1214 mtx_unlock(&sc->sim_lock); 1215 xpt_rescan(ccb_0); 1216 xpt_rescan(ccb_1); 1217 1218 return (0); 1219} 1220 1221/* 1222 * mrsas_bus_scan_sim: Perform bus scan per SIM 1223 * input: adapter instance soft state 1224 * 1225 * This function will be called from Event handler on LD creation/deletion, 1226 * JBOD on/off. 1227 */ 1228int 1229mrsas_bus_scan_sim(struct mrsas_softc *sc, struct cam_sim *sim) 1230{ 1231 union ccb *ccb; 1232 1233 if ((ccb = xpt_alloc_ccb()) == NULL) { 1234 return (ENOMEM); 1235 } 1236 mtx_lock(&sc->sim_lock); 1237 if (xpt_create_path(&ccb->ccb_h.path, xpt_periph, cam_sim_path(sim), 1238 CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD) != CAM_REQ_CMP) { 1239 xpt_free_ccb(ccb); 1240 mtx_unlock(&sc->sim_lock); 1241 return (EIO); 1242 } 1243 mtx_unlock(&sc->sim_lock); 1244 xpt_rescan(ccb); 1245 1246 return (0); 1247}
|