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
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
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
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.
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
36 #include "dev/mrsas/mrsas.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>
46 #include <cam/scsi/scsi_all.h>
47 #include <cam/scsi/scsi_message.h>
48 #include <sys/taskqueue.h>
49 #include <sys/kernel.h>
52 #include <sys/time.h> /* XXX for pcpu.h */
53 #include <sys/pcpu.h> /* XXX for PCPU_GET */
55 #define smp_processor_id() PCPU_GET(cpuid)
60 int mrsas_cam_attach(struct mrsas_softc *sc);
61 int mrsas_find_io_type(struct cam_sim *sim, union ccb *ccb);
62 int mrsas_bus_scan(struct mrsas_softc *sc);
63 int mrsas_bus_scan_sim(struct mrsas_softc *sc, struct cam_sim *sim);
65 mrsas_map_request(struct mrsas_softc *sc,
66 struct mrsas_mpt_cmd *cmd, union ccb *ccb);
68 mrsas_build_ldio(struct mrsas_softc *sc, struct mrsas_mpt_cmd *cmd,
71 mrsas_build_dcdb(struct mrsas_softc *sc, struct mrsas_mpt_cmd *cmd,
72 union ccb *ccb, struct cam_sim *sim);
74 mrsas_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);
77 void mrsas_xpt_freeze(struct mrsas_softc *sc);
78 void mrsas_xpt_release(struct mrsas_softc *sc);
79 void mrsas_cam_detach(struct mrsas_softc *sc);
80 void mrsas_release_mpt_cmd(struct mrsas_mpt_cmd *cmd);
81 void mrsas_unmap_request(struct mrsas_softc *sc, struct mrsas_mpt_cmd *cmd);
82 void mrsas_cmd_done(struct mrsas_softc *sc, struct mrsas_mpt_cmd *cmd);
84 mrsas_fire_cmd(struct mrsas_softc *sc, u_int32_t req_desc_lo,
85 u_int32_t req_desc_hi);
87 mrsas_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);
91 static void mrsas_freeze_simq(struct mrsas_mpt_cmd *cmd, struct cam_sim *sim);
92 static void mrsas_cam_poll(struct cam_sim *sim);
93 static void mrsas_action(struct cam_sim *sim, union ccb *ccb);
94 static void mrsas_scsiio_timeout(void *data);
96 mrsas_data_load_cb(void *arg, bus_dma_segment_t *segs,
99 mrsas_startio(struct mrsas_softc *sc, struct cam_sim *sim,
101 struct mrsas_mpt_cmd *mrsas_get_mpt_cmd(struct mrsas_softc *sc);
102 MRSAS_REQUEST_DESCRIPTOR_UNION *
103 mrsas_get_request_desc(struct mrsas_softc *sc, u_int16_t index);
105 extern u_int16_t MR_TargetIdToLdGet(u_int32_t ldTgtId, MR_DRV_RAID_MAP_ALL * map);
107 MR_LdBlockSizeGet(u_int32_t ldTgtId, MR_DRV_RAID_MAP_ALL * map,
108 struct mrsas_softc *sc);
109 extern void mrsas_isr(void *arg);
110 extern void mrsas_aen_handler(struct mrsas_softc *sc);
112 MR_BuildRaidContext(struct mrsas_softc *sc,
113 struct IO_REQUEST_INFO *io_info, RAID_CONTEXT * pRAID_Context,
114 MR_DRV_RAID_MAP_ALL * map);
116 MR_LdSpanArrayGet(u_int32_t ld, u_int32_t span,
117 MR_DRV_RAID_MAP_ALL * map);
119 mrsas_get_updated_dev_handle(struct mrsas_softc *sc,
120 PLD_LOAD_BALANCE_INFO lbInfo, struct IO_REQUEST_INFO *io_info);
122 megasas_get_best_arm(PLD_LOAD_BALANCE_INFO lbInfo, u_int8_t arm,
123 u_int64_t block, u_int32_t count);
127 * mrsas_cam_attach: Main entry to CAM subsystem
128 * input: Adapter instance soft state
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.
135 mrsas_cam_attach(struct mrsas_softc *sc)
137 struct cam_devq *devq;
140 mrsas_cam_depth = sc->max_fw_cmds - MRSAS_INTERNAL_CMDS;
142 if ((devq = cam_simq_alloc(mrsas_cam_depth)) == NULL) {
143 device_printf(sc->mrsas_dev, "Cannot allocate SIM queue\n");
147 * Create SIM for bus 0 and register, also create path
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) {
154 device_printf(sc->mrsas_dev, "Cannot register SIM\n");
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);
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);
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
176 mtx_unlock(&sc->sim_lock);
179 mtx_unlock(&sc->sim_lock);
182 * Create SIM for bus 1 and register, also create path
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) {
189 device_printf(sc->mrsas_dev, "Cannot register SIM\n");
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);
198 if (xpt_create_path(&sc->path_1, NULL, cam_sim_path(sc->sim_1),
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);
206 mtx_unlock(&sc->sim_lock);
208 #if (__FreeBSD_version <= 704000)
209 if (mrsas_bus_scan(sc)) {
210 device_printf(sc->mrsas_dev, "Error in bus scan.\n");
218 * mrsas_cam_detach: De-allocates and teardown CAM
219 * input: Adapter instance soft state
221 * De-registers and frees the paths and SIMs.
224 mrsas_cam_detach(struct mrsas_softc *sc)
226 if (sc->ev_tq != NULL)
227 taskqueue_free(sc->ev_tq);
228 mtx_lock(&sc->sim_lock);
230 xpt_free_path(sc->path_0);
232 xpt_bus_deregister(cam_sim_path(sc->sim_0));
233 cam_sim_free(sc->sim_0, FALSE);
236 xpt_free_path(sc->path_1);
238 xpt_bus_deregister(cam_sim_path(sc->sim_1));
239 cam_sim_free(sc->sim_1, TRUE);
241 mtx_unlock(&sc->sim_lock);
245 * mrsas_action: SIM callback entry point
246 * input: pointer to SIM pointer to CAM Control Block
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.
253 mrsas_action(struct cam_sim *sim, union ccb *ccb)
255 struct mrsas_softc *sc = (struct mrsas_softc *)cam_sim_softc(sim);
256 struct ccb_hdr *ccb_h = &(ccb->ccb_h);
259 switch (ccb->ccb_h.func_code) {
262 device_id = ccb_h->target_id;
265 * bus 0 is LD, bus 1 is for system-PD
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;
272 if (mrsas_startio(sc, sim, ccb)) {
273 ccb->ccb_h.status |= CAM_REQ_INVALID;
281 ccb->ccb_h.status = CAM_UA_ABORT;
290 case XPT_GET_TRAN_SETTINGS:
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;
304 case XPT_SET_TRAN_SETTINGS:
306 ccb->ccb_h.status = CAM_FUNC_NOTAVAIL;
310 case XPT_CALC_GEOMETRY:
312 cam_calc_geometry(&ccb->ccg, 1);
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;
324 ccb->cpi.hba_misc = 0;
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;
342 ccb->cpi.max_target = MRSAS_MAX_LD_IDS - 1;
343 #if (__FreeBSD_version > 704000)
344 ccb->cpi.maxio = MRSAS_MAX_IO_SIZE;
346 ccb->ccb_h.status = CAM_REQ_CMP;
352 ccb->ccb_h.status = CAM_REQ_INVALID;
360 * mrsas_scsiio_timeout: Callback function for IO timed out
361 * input: mpt command context
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 * coming 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.
370 mrsas_scsiio_timeout(void *data)
372 struct mrsas_mpt_cmd *cmd;
373 struct mrsas_softc *sc;
375 cmd = (struct mrsas_mpt_cmd *)data;
378 if (cmd->ccb_ptr == NULL) {
379 printf("command timeout with NULL ccb\n");
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
388 #if (__FreeBSD_version >= 1000510)
389 callout_reset_sbt(&cmd->cm_callout, SBT_1S * 600, 0,
390 mrsas_scsiio_timeout, cmd, 0);
392 callout_reset(&cmd->cm_callout, (600000 * hz) / 1000,
393 mrsas_scsiio_timeout, cmd);
395 sc->do_timedout_reset = 1;
396 if (sc->ocr_thread_active)
397 wakeup(&sc->ocr_chan);
401 * mrsas_startio: SCSI IO entry point
402 * input: Adapter instance soft state
403 * pointer to CAM Control Block
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.
411 mrsas_startio(struct mrsas_softc *sc, struct cam_sim *sim,
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;
419 if ((csio->cdb_io.cdb_bytes[0]) == SYNCHRONIZE_CACHE) {
420 ccb->ccb_h.status = CAM_REQ_CMP;
424 ccb_h->status |= CAM_SIM_QUEUED;
425 cmd = mrsas_get_mpt_cmd(sc);
428 ccb_h->status |= CAM_REQUEUE_REQ;
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;
438 cmd->flags = MRSAS_DIR_NONE; /* no data */
440 /* For FreeBSD 9.2 and higher */
441 #if (__FreeBSD_version >= 902001)
443 * XXX We don't yet support physical addresses here.
445 switch ((ccb->ccb_h.flags & CAM_DATA_MASK)) {
447 case CAM_DATA_SG_PADDR:
448 device_printf(sc->mrsas_dev, "%s: physical addresses not supported\n",
450 mrsas_release_mpt_cmd(cmd);
451 ccb_h->status = CAM_REQ_INVALID;
452 ccb_h->status &= ~CAM_SIM_QUEUED;
455 device_printf(sc->mrsas_dev, "%s: scatter gather is not supported\n",
457 mrsas_release_mpt_cmd(cmd);
458 ccb_h->status = CAM_REQ_INVALID;
461 if (csio->dxfer_len > MRSAS_MAX_IO_SIZE) {
462 mrsas_release_mpt_cmd(cmd);
463 ccb_h->status = CAM_REQ_TOO_BIG;
466 cmd->length = csio->dxfer_len;
468 cmd->data = csio->data_ptr;
471 cmd->length = csio->dxfer_len;
473 cmd->data = csio->data_ptr;
476 ccb->ccb_h.status = CAM_REQ_INVALID;
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;
487 cmd->length = csio->dxfer_len;
489 cmd->data = csio->data_ptr;
491 mrsas_release_mpt_cmd(cmd);
492 ccb_h->status = CAM_REQ_INVALID;
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;
505 req_desc = mrsas_get_request_desc(sc, (cmd->index) - 1);
507 device_printf(sc->mrsas_dev, "Cannot get request_descriptor.\n");
510 memset(req_desc, 0, sizeof(MRSAS_REQUEST_DESCRIPTOR_UNION));
511 cmd->request_desc = req_desc;
513 if (ccb_h->flags & CAM_CDB_POINTER)
514 bcopy(csio->cdb_io.cdb_ptr, cmd->io_request->CDB.CDB32, csio->cdb_len);
516 bcopy(csio->cdb_io.cdb_bytes, cmd->io_request->CDB.CDB32, csio->cdb_len);
517 mtx_lock(&sc->raidmap_lock);
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);
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);
534 mtx_unlock(&sc->raidmap_lock);
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;
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;
546 req_desc = cmd->request_desc;
547 req_desc->SCSIIO.SMID = cmd->index;
550 * Start timer for IO timeout. Default timeout value is 90 second.
552 #if (__FreeBSD_version >= 1000510)
553 callout_reset_sbt(&cmd->cm_callout, SBT_1S * 600, 0,
554 mrsas_scsiio_timeout, cmd, 0);
556 callout_reset(&cmd->cm_callout, (600000 * hz) / 1000,
557 mrsas_scsiio_timeout, cmd);
559 mrsas_atomic_inc(&sc->fw_outstanding);
561 if (mrsas_atomic_read(&sc->fw_outstanding) > sc->io_cmds_highwater)
562 sc->io_cmds_highwater++;
564 mrsas_fire_cmd(sc, req_desc->addr.u.low, req_desc->addr.u.high);
573 * mrsas_find_io_type: Determines if IO is read/write or inquiry
574 * input: pointer to CAM Control Block
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.
580 mrsas_find_io_type(struct cam_sim *sim, union ccb *ccb)
582 struct ccb_scsiio *csio = &(ccb->csio);
584 switch (csio->cdb_io.cdb_bytes[0]) {
593 return (cam_sim_bus(sim) ?
594 READ_WRITE_SYSPDIO : READ_WRITE_LDIO);
596 return (cam_sim_bus(sim) ?
597 NON_READ_WRITE_SYSPDIO : NON_READ_WRITE_LDIO);
602 * mrsas_get_mpt_cmd: Get a cmd from free command pool
603 * input: Adapter instance soft state
605 * This function removes an MPT command from the command free list and
608 struct mrsas_mpt_cmd *
609 mrsas_get_mpt_cmd(struct mrsas_softc *sc)
611 struct mrsas_mpt_cmd *cmd = NULL;
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);
618 memset((uint8_t *)cmd->io_request, 0, MRSAS_MPI2_RAID_DEFAULT_IO_FRAME_SIZE);
623 cmd->load_balance = 0;
625 mtx_unlock(&sc->mpt_cmd_pool_lock);
631 * mrsas_release_mpt_cmd: Return a cmd to free command pool
632 * input: Command packet for return to free command pool
634 * This function returns an MPT command to the free command list.
637 mrsas_release_mpt_cmd(struct mrsas_mpt_cmd *cmd)
639 struct mrsas_softc *sc = cmd->sc;
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);
650 * mrsas_get_request_desc: Get request descriptor from array
651 * input: Adapter instance soft state
654 * This function returns a pointer to the request descriptor.
656 MRSAS_REQUEST_DESCRIPTOR_UNION *
657 mrsas_get_request_desc(struct mrsas_softc *sc, u_int16_t index)
661 if (index >= sc->max_fw_cmds) {
662 device_printf(sc->mrsas_dev, "Invalid SMID (0x%x)request for desc\n", index);
665 p = sc->req_desc + sizeof(MRSAS_REQUEST_DESCRIPTOR_UNION) * index;
667 return (MRSAS_REQUEST_DESCRIPTOR_UNION *) p;
671 * mrsas_build_ldio: Builds an LDIO command
672 * input: Adapter instance soft state
673 * Pointer to command packet
676 * This function builds the LDIO command packet. It returns 0 if the command is
677 * built successfully, otherwise it returns a 1.
680 mrsas_build_ldio(struct mrsas_softc *sc, struct mrsas_mpt_cmd *cmd,
683 struct ccb_hdr *ccb_h = &(ccb->ccb_h);
684 struct ccb_scsiio *csio = &(ccb->csio);
686 MRSAS_RAID_SCSI_IO_REQUEST *io_request;
688 device_id = ccb_h->target_id;
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;
695 /* just the cdb len, other flags zero, and ORed-in later for FP */
696 io_request->IoFlags = csio->cdb_len;
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");
701 io_request->DataLength = cmd->length;
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);
709 io_request->RaidContext.numSGE = cmd->sge_count;
711 device_printf(sc->mrsas_dev, "Data map/load failed.\n");
718 * mrsas_setup_io: Set up data including Fast Path I/O
719 * input: Adapter instance soft state
720 * Pointer to command packet
723 * This function builds the DCDB inquiry command. It returns 0 if the command
724 * is built successfully, otherwise it returns a 1.
727 mrsas_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)
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;
744 * READ_6 (0x08) or WRITE_6 (0x0A) cdb
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;
754 * READ_10 (0x28) or WRITE_6 (0x2A) cdb
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]);
765 * READ_12 (0xA8) or WRITE_12 (0xAA) cdb
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]);
778 * READ_16 (0x88) or WRITE_16 (0xx8A) cdb
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]);
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;
799 switch (ccb_h->flags & CAM_DIR_MASK) {
808 mrsas_dprint(sc, MRSAS_TRACE, "From %s : DMA Flag is %d \n", __func__, ccb_h->flags & CAM_DIR_MASK);
812 map_ptr = sc->ld_drv_map[(sc->map_id & 1)];
813 ld_block_size = MR_LdBlockSizeGet(device_id, map_ptr, sc);
815 if ((MR_TargetIdToLdGet(device_id, map_ptr) >= MAX_LOGICAL_DRIVES_EXT) ||
816 (!sc->fast_path_io)) {
817 io_request->RaidContext.regLockFlags = 0;
820 if (MR_BuildRaidContext(sc, &io_info, &io_request->RaidContext, map_ptr))
821 fp_possible = io_info.fpOkForIo;
824 cmd->request_desc->SCSIIO.MSIxIndex =
825 sc->msix_vectors ? smp_processor_id() % sc->msix_vectors : 0;
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);
847 if ((sc->load_balance_info[device_id].loadBalanceFlag) &&
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;
855 cmd->load_balance = 0;
856 cmd->request_desc->SCSIIO.DevHandle = io_info.devHandle;
857 io_request->DevHandle = io_info.devHandle;
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;
875 io_request->Function = MRSAS_MPI2_FUNCTION_LD_IO_REQUEST;
876 io_request->DevHandle = device_id;
882 * mrsas_build_dcdb: Builds an DCDB command
883 * input: Adapter instance soft state
884 * Pointer to command packet
887 * This function builds the DCDB inquiry command. It returns 0 if the command
888 * is built successfully, otherwise it returns a 1.
891 mrsas_build_dcdb(struct mrsas_softc *sc, struct mrsas_mpt_cmd *cmd,
892 union ccb *ccb, struct cam_sim *sim)
894 struct ccb_hdr *ccb_h = &(ccb->ccb_h);
896 MR_DRV_RAID_MAP_ALL *map_ptr;
897 MRSAS_RAID_SCSI_IO_REQUEST *io_request;
899 io_request = cmd->io_request;
900 device_id = ccb_h->target_id;
901 map_ptr = sc->ld_drv_map[(sc->map_id & 1)];
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
907 if (cam_sim_bus(sim) == 1 &&
908 sc->pd_list[device_id].driveState == MR_PD_STATE_SYSTEM) {
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;
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);
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;
932 cmd->request_desc->SCSIIO.RequestFlags =
933 (MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY <<
934 MRSAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
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
941 if ((sc->device_id == MRSAS_INVADER) || (sc->device_id == MRSAS_FURY))
942 io_request->IoFlags |= MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH;
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);
953 io_request->RaidContext.VirtualDiskTgtId = device_id;
954 io_request->LUN[1] = ccb_h->target_lun & 0xF;
955 io_request->DataLength = cmd->length;
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);
963 io_request->RaidContext.numSGE = cmd->sge_count;
965 device_printf(sc->mrsas_dev, "Data map/load failed.\n");
972 * mrsas_map_request: Map and load data
973 * input: Adapter instance soft state
974 * Pointer to command packet
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.
981 mrsas_map_request(struct mrsas_softc *sc,
982 struct mrsas_mpt_cmd *cmd, union ccb *ccb)
984 u_int32_t retcode = 0;
987 sim = xpt_path_sim(cmd->ccb_ptr->ccb_h.path);
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);
996 retcode = bus_dmamap_load(sc->data_tag, cmd->data_dmamap, cmd->data,
997 cmd->length, mrsas_data_load_cb, cmd, BUS_DMA_NOWAIT);
999 mtx_unlock(&sc->io_lock);
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);
1007 if (cmd->error_code)
1013 * mrsas_unmap_request: Unmap and unload data
1014 * input: Adapter instance soft state
1015 * Pointer to command packet
1017 * This function unmaps and unloads data from OS.
1020 mrsas_unmap_request(struct mrsas_softc *sc, struct mrsas_mpt_cmd *cmd)
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);
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
1039 * This is the callback function of the bus dma map load. It builds the SG
1043 mrsas_data_load_cb(void *arg, bus_dma_segment_t *segs, int nseg, int error)
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;
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;
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");
1069 io_request = cmd->io_request;
1070 sgl_ptr = (pMpi25IeeeSgeChain64_t)&io_request->SGL;
1072 if ((sc->device_id == MRSAS_INVADER) || (sc->device_id == MRSAS_FURY)) {
1073 pMpi25IeeeSgeChain64_t sgl_ptr_end = sgl_ptr;
1075 sgl_ptr_end += sc->max_sge_in_main_msg - 1;
1076 sgl_ptr_end->Flags = 0;
1079 for (i = 0; i < nseg; i++) {
1080 sgl_ptr->Address = segs[i].ds_addr;
1081 sgl_ptr->Length = segs[i].ds_len;
1083 if ((sc->device_id == MRSAS_INVADER) || (sc->device_id == MRSAS_FURY)) {
1085 sgl_ptr->Flags = IEEE_SGE_FLAGS_END_OF_LIST;
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;
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;
1098 cmd->io_request->ChainOffset = 0;
1100 cmd->io_request->ChainOffset = sc->chain_offset_io_request;
1102 if ((sc->device_id == MRSAS_INVADER) || (sc->device_id == MRSAS_FURY))
1103 sg_chain->Flags = IEEE_SGE_FLAGS_CHAIN_ELEMENT;
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;
1112 cmd->sge_count = nseg;
1116 * mrsas_freeze_simq: Freeze SIM queue
1117 * input: Pointer to command packet
1120 * This function freezes the sim queue.
1123 mrsas_freeze_simq(struct mrsas_mpt_cmd *cmd, struct cam_sim *sim)
1125 union ccb *ccb = (union ccb *)(cmd->ccb_ptr);
1127 xpt_freeze_simq(sim, 1);
1128 ccb->ccb_h.status |= CAM_RELEASE_SIMQ;
1129 ccb->ccb_h.status |= CAM_REQUEUE_REQ;
1133 mrsas_xpt_freeze(struct mrsas_softc *sc)
1135 xpt_freeze_simq(sc->sim_0, 1);
1136 xpt_freeze_simq(sc->sim_1, 1);
1140 mrsas_xpt_release(struct mrsas_softc *sc)
1142 xpt_release_simq(sc->sim_0, 1);
1143 xpt_release_simq(sc->sim_1, 1);
1147 * mrsas_cmd_done: Perform remaining command completion
1148 * input: Adapter instance soft state Pointer to command packet
1150 * This function calls ummap request and releases the MPT command.
1153 mrsas_cmd_done(struct mrsas_softc *sc, struct mrsas_mpt_cmd *cmd)
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);
1165 * mrsas_cam_poll: Polling entry point
1166 * input: Pointer to SIM
1168 * This is currently a stub function.
1171 mrsas_cam_poll(struct cam_sim *sim)
1173 struct mrsas_softc *sc = (struct mrsas_softc *)cam_sim_softc(sim);
1175 mrsas_isr((void *)sc);
1179 * mrsas_bus_scan: Perform bus scan
1180 * input: Adapter instance soft state
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
1187 mrsas_bus_scan(struct mrsas_softc *sc)
1192 if ((ccb_0 = xpt_alloc_ccb()) == NULL) {
1195 if ((ccb_1 = xpt_alloc_ccb()) == NULL) {
1196 xpt_free_ccb(ccb_0);
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);
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);
1214 mtx_unlock(&sc->sim_lock);
1222 * mrsas_bus_scan_sim: Perform bus scan per SIM
1223 * input: adapter instance soft state
1225 * This function will be called from Event handler on LD creation/deletion,
1229 mrsas_bus_scan_sim(struct mrsas_softc *sc, struct cam_sim *sim)
1233 if ((ccb = xpt_alloc_ccb()) == NULL) {
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) {
1240 mtx_unlock(&sc->sim_lock);
1243 mtx_unlock(&sc->sim_lock);