2 * Copyright (c) 2017 Broadcom. All rights reserved.
3 * The term "Broadcom" refers to Broadcom Limited and/or its subsidiaries.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
15 * 3. Neither the name of the copyright holder nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
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.
36 * OCS Linux SCSI API base driver implementation.
40 * @defgroup scsi_api_base SCSI Base Target/Initiator
46 #if defined(OCS_ENABLE_VPD_SUPPORT)
49 #include "ocs_utils.h"
50 #include "ocs_device.h"
52 #define SCSI_IOFMT "[%04x][i:%0*x t:%0*x h:%04x]"
53 #define SCSI_ITT_SIZE(ocs) ((ocs->ocs_xport == OCS_XPORT_FC) ? 4 : 8)
55 #define SCSI_IOFMT_ARGS(io) io->instance_index, SCSI_ITT_SIZE(io->ocs), io->init_task_tag, SCSI_ITT_SIZE(io->ocs), io->tgt_task_tag, io->hw_tag
57 #define enable_tsend_auto_resp(ocs) ((ocs->ctrlmask & OCS_CTRLMASK_XPORT_DISABLE_AUTORSP_TSEND) == 0)
58 #define enable_treceive_auto_resp(ocs) ((ocs->ctrlmask & OCS_CTRLMASK_XPORT_DISABLE_AUTORSP_TRECEIVE) == 0)
60 #define scsi_io_printf(io, fmt, ...) ocs_log_info(io->ocs, "[%s]" SCSI_IOFMT fmt, \
61 io->node->display_name, SCSI_IOFMT_ARGS(io), ##__VA_ARGS__)
63 #define scsi_io_trace(io, fmt, ...) \
65 if (OCS_LOG_ENABLE_SCSI_TRACE(io->ocs)) \
66 scsi_io_printf(io, fmt, ##__VA_ARGS__); \
69 #define scsi_log(ocs, fmt, ...) \
71 if (OCS_LOG_ENABLE_SCSI_TRACE(ocs)) \
72 ocs_log_info(ocs, fmt, ##__VA_ARGS__); \
75 static int32_t ocs_target_send_bls_resp(ocs_io_t *io, ocs_scsi_io_cb_t cb, void *arg);
76 static int32_t ocs_scsi_abort_io_cb(struct ocs_hw_io_s *hio, ocs_remote_node_t *rnode, uint32_t len, int32_t status,
77 uint32_t ext, void *arg);
79 static void ocs_scsi_io_free_ovfl(ocs_io_t *io);
80 static uint32_t ocs_scsi_count_sgls(ocs_hw_dif_info_t *hw_dif, ocs_scsi_sgl_t *sgl, uint32_t sgl_count);
81 static int ocs_scsi_dif_guard_is_crc(uint8_t direction, ocs_hw_dif_info_t *dif_info);
82 static ocs_scsi_io_status_e ocs_scsi_dif_check_unknown(ocs_io_t *io, uint32_t length, uint32_t check_length, int is_crc);
83 static uint32_t ocs_scsi_dif_check_guard(ocs_hw_dif_info_t *dif_info, ocs_scsi_vaddr_len_t addrlen[],
84 uint32_t addrlen_count, ocs_dif_t *dif, int is_crc);
85 static uint32_t ocs_scsi_dif_check_app_tag(ocs_t *ocs, ocs_hw_dif_info_t *dif_info, uint16_t exp_app_tag, ocs_dif_t *dif);
86 static uint32_t ocs_scsi_dif_check_ref_tag(ocs_t *ocs, ocs_hw_dif_info_t *dif_info, uint32_t exp_ref_tag, ocs_dif_t *dif);
87 static int32_t ocs_scsi_convert_dif_info(ocs_t *ocs, ocs_scsi_dif_info_t *scsi_dif_info,
88 ocs_hw_dif_info_t *hw_dif_info);
89 static int32_t ocs_scsi_io_dispatch_hw_io(ocs_io_t *io, ocs_hw_io_t *hio);
90 static int32_t ocs_scsi_io_dispatch_no_hw_io(ocs_io_t *io);
91 static void _ocs_scsi_io_free(void *arg);
94 * @ingroup scsi_api_base
95 * @brief Returns a big-endian 32-bit value given a pointer.
97 * @param p Pointer to the 32-bit big-endian location.
99 * @return Returns the byte-swapped 32-bit value.
102 static inline uint32_t
103 ocs_fc_getbe32(void *p)
105 return ocs_be32toh(*((uint32_t*)p));
109 * @ingroup scsi_api_base
110 * @brief Enable IO allocation.
113 * The SCSI and Transport IO allocation functions are enabled. If the allocation functions
114 * are not enabled, then calls to ocs_scsi_io_alloc() (and ocs_els_io_alloc() for FC) will
117 * @param node Pointer to node object.
122 ocs_scsi_io_alloc_enable(ocs_node_t *node)
124 ocs_assert(node != NULL);
125 ocs_lock(&node->active_ios_lock);
126 node->io_alloc_enabled = TRUE;
127 ocs_unlock(&node->active_ios_lock);
131 * @ingroup scsi_api_base
132 * @brief Disable IO allocation
135 * The SCSI and Transport IO allocation functions are disabled. If the allocation functions
136 * are not enabled, then calls to ocs_scsi_io_alloc() (and ocs_els_io_alloc() for FC) will
139 * @param node Pointer to node object
144 ocs_scsi_io_alloc_disable(ocs_node_t *node)
146 ocs_assert(node != NULL);
147 ocs_lock(&node->active_ios_lock);
148 node->io_alloc_enabled = FALSE;
149 ocs_unlock(&node->active_ios_lock);
153 * @ingroup scsi_api_base
154 * @brief Allocate a SCSI IO context.
157 * A SCSI IO context is allocated and associated with a @c node. This function
158 * is called by an initiator-client when issuing SCSI commands to remote
159 * target devices. On completion, ocs_scsi_io_free() is called.
161 * The returned ocs_io_t structure has an element of type ocs_scsi_ini_io_t named
162 * "ini_io" that is declared and used by an initiator-client for private information.
164 * @param node Pointer to the associated node structure.
165 * @param role Role for IO (originator/responder).
167 * @return Returns the pointer to the IO context, or NULL.
172 ocs_scsi_io_alloc(ocs_node_t *node, ocs_scsi_io_role_e role)
178 ocs_assert(node, NULL);
179 ocs_assert(node->ocs, NULL);
182 ocs_assert(ocs->xport, NULL);
185 ocs_lock(&node->active_ios_lock);
187 if (!node->io_alloc_enabled) {
188 ocs_unlock(&node->active_ios_lock);
192 io = ocs_io_alloc(ocs);
194 ocs_atomic_add_return(&xport->io_alloc_failed_count, 1);
195 ocs_unlock(&node->active_ios_lock);
199 /* initialize refcount */
200 ocs_ref_init(&io->ref, _ocs_scsi_io_free, io);
202 if (io->hio != NULL) {
203 ocs_log_err(node->ocs, "assertion failed: io->hio is not NULL\n");
204 ocs_io_free(ocs, io);
205 ocs_unlock(&node->active_ios_lock);
209 /* set generic fields */
213 /* set type and name */
214 io->io_type = OCS_IO_TYPE_IO;
215 io->display_name = "scsi_io";
218 case OCS_SCSI_IO_ROLE_ORIGINATOR:
222 case OCS_SCSI_IO_ROLE_RESPONDER:
228 /* Add to node's active_ios list */
229 ocs_list_add_tail(&node->active_ios, io);
231 ocs_unlock(&node->active_ios_lock);
237 * @ingroup scsi_api_base
238 * @brief Free a SCSI IO context (internal).
241 * The IO context previously allocated using ocs_scsi_io_alloc()
242 * is freed. This is called from within the transport layer,
243 * when the reference count goes to zero.
245 * @param arg Pointer to the IO context.
250 _ocs_scsi_io_free(void *arg)
252 ocs_io_t *io = (ocs_io_t *)arg;
253 ocs_t *ocs = io->ocs;
254 ocs_node_t *node = io->node;
255 int send_empty_event;
257 ocs_assert(io != NULL);
259 scsi_io_trace(io, "freeing io 0x%p %s\n", io, io->display_name);
261 ocs_assert(ocs_io_busy(io));
263 ocs_lock(&node->active_ios_lock);
264 ocs_list_remove(&node->active_ios, io);
265 send_empty_event = (!node->io_alloc_enabled) && ocs_list_empty(&node->active_ios);
266 ocs_unlock(&node->active_ios_lock);
268 if (send_empty_event) {
269 ocs_node_post_event(node, OCS_EVT_NODE_ACTIVE_IO_LIST_EMPTY, NULL);
273 ocs_io_free(ocs, io);
278 * @ingroup scsi_api_base
279 * @brief Free a SCSI IO context.
282 * The IO context previously allocated using ocs_scsi_io_alloc() is freed.
284 * @param io Pointer to the IO context.
289 ocs_scsi_io_free(ocs_io_t *io)
291 scsi_io_trace(io, "freeing io 0x%p %s\n", io, io->display_name);
292 ocs_assert(ocs_ref_read_count(&io->ref) > 0);
293 ocs_ref_put(&io->ref); /* ocs_ref_get(): ocs_scsi_io_alloc() */
297 ocs_scsi_send_io(ocs_hw_io_type_e type, ocs_node_t *node, ocs_io_t *io, uint64_t lun,
298 ocs_scsi_tmf_cmd_e tmf, uint8_t *cdb, uint32_t cdb_len,
299 ocs_scsi_dif_info_t *dif_info,
300 ocs_scsi_sgl_t *sgl, uint32_t sgl_count, uint32_t wire_len, uint32_t first_burst,
301 ocs_scsi_rsp_io_cb_t cb, void *arg, uint32_t flags);
304 * @brief Target response completion callback.
307 * Function is called upon the completion of a target IO request.
309 * @param hio Pointer to the HW IO structure.
310 * @param rnode Remote node associated with the IO that is completing.
311 * @param length Length of the response payload.
312 * @param status Completion status.
313 * @param ext_status Extended completion status.
314 * @param app Application-specific data (generally a pointer to the IO context).
320 ocs_target_io_cb(ocs_hw_io_t *hio, ocs_remote_node_t *rnode, uint32_t length,
321 int32_t status, uint32_t ext_status, void *app)
325 ocs_scsi_io_status_e scsi_status = OCS_SCSI_STATUS_GOOD;
326 uint16_t additional_length;
329 ocs_hw_dif_info_t *dif_info = &io->hw_dif;
334 scsi_io_trace(io, "status x%x ext_status x%x\n", status, ext_status);
339 ocs_scsi_io_free_ovfl(io);
341 io->transferred += length;
343 /* Call target server completion */
344 if (io->scsi_tgt_cb) {
345 ocs_scsi_io_cb_t cb = io->scsi_tgt_cb;
348 /* Clear the callback before invoking the callback */
349 io->scsi_tgt_cb = NULL;
351 /* if status was good, and auto-good-response was set, then callback
352 * target-server with IO_CMPL_RSP_SENT, otherwise send IO_CMPL
354 if ((status == 0) && (io->auto_resp))
355 flags |= OCS_SCSI_IO_CMPL_RSP_SENT;
357 flags |= OCS_SCSI_IO_CMPL;
360 case SLI4_FC_WCQE_STATUS_SUCCESS:
361 scsi_status = OCS_SCSI_STATUS_GOOD;
363 case SLI4_FC_WCQE_STATUS_DI_ERROR:
364 if (ext_status & SLI4_FC_DI_ERROR_GE) {
365 scsi_status = OCS_SCSI_STATUS_DIF_GUARD_ERROR;
366 } else if (ext_status & SLI4_FC_DI_ERROR_AE) {
367 scsi_status = OCS_SCSI_STATUS_DIF_APP_TAG_ERROR;
368 } else if (ext_status & SLI4_FC_DI_ERROR_RE) {
369 scsi_status = OCS_SCSI_STATUS_DIF_REF_TAG_ERROR;
371 additional_length = ((ext_status >> 16) & 0xFFFF);
373 /* Capture the EDIR and TDPV bits as 0 or 1 for easier printing. */
374 edir = !!(ext_status & SLI4_FC_DI_ERROR_EDIR);
375 tdpv = !!(ext_status & SLI4_FC_DI_ERROR_TDPV);
377 is_crc = ocs_scsi_dif_guard_is_crc(edir, dif_info);
380 /* For reads, we have everything in memory. Start checking from beginning. */
381 scsi_status = ocs_scsi_dif_check_unknown(io, 0, io->wire_len, is_crc);
383 /* For writes, use the additional length to determine where to look for the error.
384 * The additional_length field is set to 0 if it is not supported.
385 * The additional length field is valid if:
386 * . additional_length is not zero
387 * . Total Data Placed is valid
388 * . Error Direction is RX (1)
389 * . Operation is a pass thru (CRC or CKSUM on IN, and CRC or CHKSUM on OUT) (all pass-thru cases except raw)
391 if ((additional_length != 0) && (tdpv != 0) &&
392 (dif_info->dif == SLI4_DIF_PASS_THROUGH) && (dif_info->dif_oper != OCS_HW_SGE_DIF_OP_IN_RAW_OUT_RAW) ) {
393 scsi_status = ocs_scsi_dif_check_unknown(io, length, additional_length, is_crc);
395 /* If we can't do additional checking, then fall-back to guard error */
396 scsi_status = OCS_SCSI_STATUS_DIF_GUARD_ERROR;
401 case SLI4_FC_WCQE_STATUS_LOCAL_REJECT:
402 switch (ext_status) {
403 case SLI4_FC_LOCAL_REJECT_INVALID_RELOFFSET:
404 case SLI4_FC_LOCAL_REJECT_ABORT_REQUESTED:
405 scsi_status = OCS_SCSI_STATUS_ABORTED;
407 case SLI4_FC_LOCAL_REJECT_INVALID_RPI:
408 scsi_status = OCS_SCSI_STATUS_NEXUS_LOST;
410 case SLI4_FC_LOCAL_REJECT_NO_XRI:
411 scsi_status = OCS_SCSI_STATUS_NO_IO;
414 /* TODO: we have seen 0x0d (TX_DMA_FAILED error) */
415 scsi_status = OCS_SCSI_STATUS_ERROR;
420 case SLI4_FC_WCQE_STATUS_TARGET_WQE_TIMEOUT:
421 /* target IO timed out */
422 scsi_status = OCS_SCSI_STATUS_TIMEDOUT_AND_ABORTED;
425 case SLI4_FC_WCQE_STATUS_SHUTDOWN:
426 /* Target IO cancelled by HW */
427 scsi_status = OCS_SCSI_STATUS_SHUTDOWN;
431 scsi_status = OCS_SCSI_STATUS_ERROR;
435 cb(io, scsi_status, flags, io->scsi_tgt_cb_arg);
437 ocs_scsi_check_pending(ocs);
441 * @brief Determine if an IO is using CRC for DIF guard format.
443 * @param direction IO direction: 1 for write, 0 for read.
444 * @param dif_info Pointer to HW DIF info data.
446 * @return Returns TRUE if using CRC, FALSE if not.
449 ocs_scsi_dif_guard_is_crc(uint8_t direction, ocs_hw_dif_info_t *dif_info)
454 /* For writes, check if operation is "OUT_CRC" or not */
455 switch(dif_info->dif_oper) {
456 case OCS_HW_SGE_DIF_OP_IN_NODIF_OUT_CRC:
457 case OCS_HW_SGE_DIF_OP_IN_CRC_OUT_CRC:
458 case OCS_HW_SGE_DIF_OP_IN_CHKSUM_OUT_CRC:
466 /* For reads, check if operation is "IN_CRC" or not */
467 switch(dif_info->dif_oper) {
468 case OCS_HW_SGE_DIF_OP_IN_CRC_OUT_NODIF:
469 case OCS_HW_SGE_DIF_OP_IN_CRC_OUT_CRC:
470 case OCS_HW_SGE_DIF_OP_IN_CRC_OUT_CHKSUM:
483 * @brief Check a block and DIF data, computing the appropriate SCSI status
486 * This function is used to check blocks and DIF when given an unknown DIF
487 * status using the following logic:
489 * Given the address of the last good block, and a length of bytes that includes
490 * the block with the DIF error, find the bad block. If a block is found with an
491 * app_tag or ref_tag error, then return the appropriate error. No block is expected
492 * to have a block guard error since hardware "fixes" the crc. So if no block in the
493 * range of blocks has an error, then it is presumed to be a BLOCK GUARD error.
495 * @param io Pointer to the IO object.
496 * @param length Length of bytes covering the good blocks.
497 * @param check_length Length of bytes that covers the bad block.
498 * @param is_crc True if guard is using CRC format.
500 * @return Returns SCSI status.
503 static ocs_scsi_io_status_e
504 ocs_scsi_dif_check_unknown(ocs_io_t *io, uint32_t length, uint32_t check_length, int is_crc)
507 ocs_t *ocs = io->ocs;
508 ocs_hw_dif_info_t *dif_info = &io->hw_dif;
509 ocs_scsi_io_status_e scsi_status = OCS_SCSI_STATUS_DIF_GUARD_ERROR;
510 uint32_t blocksize; /* data block size */
511 uint64_t first_check_block; /* first block following total data placed */
512 uint64_t last_check_block; /* last block to check */
513 uint32_t check_count; /* count of blocks to check */
514 ocs_scsi_vaddr_len_t addrlen[4]; /* address-length pairs returned from target */
515 int32_t addrlen_count; /* count of address-length pairs */
516 ocs_dif_t *dif; /* pointer to DIF block returned from target */
517 ocs_scsi_dif_info_t scsi_dif_info = io->scsi_dif_info;
519 blocksize = ocs_hw_dif_mem_blocksize(&io->hw_dif, TRUE);
520 first_check_block = length / blocksize;
521 last_check_block = ((length + check_length) / blocksize);
522 check_count = last_check_block - first_check_block;
524 ocs_log_debug(ocs, "blocksize %d first check_block %" PRId64 " last_check_block %" PRId64 " check_count %d\n",
525 blocksize, first_check_block, last_check_block, check_count);
527 for (i = first_check_block; i < last_check_block; i++) {
528 addrlen_count = ocs_scsi_get_block_vaddr(io, (scsi_dif_info.lba + i), addrlen, ARRAY_SIZE(addrlen), (void**) &dif);
529 if (addrlen_count < 0) {
530 ocs_log_test(ocs, "ocs_scsi_get_block_vaddr() failed: %d\n", addrlen_count);
531 scsi_status = OCS_SCSI_STATUS_DIF_UNKNOWN_ERROR;
535 if (! ocs_scsi_dif_check_guard(dif_info, addrlen, addrlen_count, dif, is_crc)) {
536 ocs_log_debug(ocs, "block guard check error, lba %" PRId64 "\n", scsi_dif_info.lba + i);
537 scsi_status = OCS_SCSI_STATUS_DIF_GUARD_ERROR;
540 if (! ocs_scsi_dif_check_app_tag(ocs, dif_info, scsi_dif_info.app_tag, dif)) {
541 ocs_log_debug(ocs, "app tag check error, lba %" PRId64 "\n", scsi_dif_info.lba + i);
542 scsi_status = OCS_SCSI_STATUS_DIF_APP_TAG_ERROR;
545 if (! ocs_scsi_dif_check_ref_tag(ocs, dif_info, (scsi_dif_info.ref_tag + i), dif)) {
546 ocs_log_debug(ocs, "ref tag check error, lba %" PRId64 "\n", scsi_dif_info.lba + i);
547 scsi_status = OCS_SCSI_STATUS_DIF_REF_TAG_ERROR;
555 * @brief Check the block guard of block data
558 * Using the dif_info for the transfer, check the block guard value.
560 * @param dif_info Pointer to HW DIF info data.
561 * @param addrlen Array of address length pairs.
562 * @param addrlen_count Number of entries in the addrlen[] array.
563 * @param dif Pointer to the DIF data block being checked.
564 * @param is_crc True if guard is using CRC format.
566 * @return Returns TRUE if block guard check is ok.
569 ocs_scsi_dif_check_guard(ocs_hw_dif_info_t *dif_info, ocs_scsi_vaddr_len_t addrlen[], uint32_t addrlen_count,
570 ocs_dif_t *dif, int is_crc)
572 uint16_t crc = dif_info->dif_seed;
576 if ((dif == NULL) || !dif_info->check_guard) {
581 for (i = 0; i < addrlen_count; i++) {
582 crc = ocs_scsi_dif_calc_crc(addrlen[i].vaddr, addrlen[i].length, crc);
584 return (crc == ocs_be16toh(dif->crc));
586 checksum = ocs_scsi_dif_calc_checksum(addrlen, addrlen_count);
588 return (checksum == dif->crc);
593 * @brief Check the app tag of dif data
596 * Using the dif_info for the transfer, check the app tag.
598 * @param ocs Pointer to the ocs structure for logging.
599 * @param dif_info Pointer to HW DIF info data.
600 * @param exp_app_tag The value the app tag is expected to be.
601 * @param dif Pointer to the DIF data block being checked.
603 * @return Returns TRUE if app tag check is ok.
606 ocs_scsi_dif_check_app_tag(ocs_t *ocs, ocs_hw_dif_info_t *dif_info, uint16_t exp_app_tag, ocs_dif_t *dif)
608 if ((dif == NULL) || !dif_info->check_app_tag) {
612 ocs_log_debug(ocs, "expected app tag 0x%x, actual 0x%x\n",
613 exp_app_tag, ocs_be16toh(dif->app_tag));
615 return (exp_app_tag == ocs_be16toh(dif->app_tag));
619 * @brief Check the ref tag of dif data
622 * Using the dif_info for the transfer, check the app tag.
624 * @param ocs Pointer to the ocs structure for logging.
625 * @param dif_info Pointer to HW DIF info data.
626 * @param exp_ref_tag The value the ref tag is expected to be.
627 * @param dif Pointer to the DIF data block being checked.
629 * @return Returns TRUE if ref tag check is ok.
632 ocs_scsi_dif_check_ref_tag(ocs_t *ocs, ocs_hw_dif_info_t *dif_info, uint32_t exp_ref_tag, ocs_dif_t *dif)
634 if ((dif == NULL) || !dif_info->check_ref_tag) {
638 if (exp_ref_tag != ocs_be32toh(dif->ref_tag)) {
639 ocs_log_debug(ocs, "expected ref tag 0x%x, actual 0x%x\n",
640 exp_ref_tag, ocs_be32toh(dif->ref_tag));
648 * @brief Return count of SGE's required for request
651 * An accurate count of SGEs is computed and returned.
653 * @param hw_dif Pointer to HW dif information.
654 * @param sgl Pointer to SGL from back end.
655 * @param sgl_count Count of SGEs in SGL.
657 * @return Count of SGEs.
660 ocs_scsi_count_sgls(ocs_hw_dif_info_t *hw_dif, ocs_scsi_sgl_t *sgl, uint32_t sgl_count)
665 /* Convert DIF Information */
666 if (hw_dif->dif_oper != OCS_HW_DIF_OPER_DISABLED) {
667 /* If we're not DIF separate, then emit a seed SGE */
668 if (!hw_dif->dif_separate) {
672 for (i = 0; i < sgl_count; i++) {
673 /* If DIF is enabled, and DIF is separate, then append a SEED then DIF SGE */
674 if (hw_dif->dif_separate) {
687 ocs_scsi_build_sgls(ocs_hw_t *hw, ocs_hw_io_t *hio, ocs_hw_dif_info_t *hw_dif, ocs_scsi_sgl_t *sgl, uint32_t sgl_count, ocs_hw_io_type_e type)
692 uint32_t blocksize = 0;
697 /* Initialize HW SGL */
698 rc = ocs_hw_io_init_sges(hw, hio, type);
700 ocs_log_err(ocs, "ocs_hw_io_init_sges failed: %d\n", rc);
704 /* Convert DIF Information */
705 if (hw_dif->dif_oper != OCS_HW_DIF_OPER_DISABLED) {
706 /* If we're not DIF separate, then emit a seed SGE */
707 if (!hw_dif->dif_separate) {
708 rc = ocs_hw_io_add_seed_sge(hw, hio, hw_dif);
714 /* if we are doing DIF separate, then figure out the block size so that we
715 * can update the ref tag in the DIF seed SGE. Also verify that the
716 * the sgl lengths are all multiples of the blocksize
718 if (hw_dif->dif_separate) {
719 switch(hw_dif->blk_size) {
720 case OCS_HW_DIF_BK_SIZE_512: blocksize = 512; break;
721 case OCS_HW_DIF_BK_SIZE_1024: blocksize = 1024; break;
722 case OCS_HW_DIF_BK_SIZE_2048: blocksize = 2048; break;
723 case OCS_HW_DIF_BK_SIZE_4096: blocksize = 4096; break;
724 case OCS_HW_DIF_BK_SIZE_520: blocksize = 520; break;
725 case OCS_HW_DIF_BK_SIZE_4104: blocksize = 4104; break;
727 ocs_log_test(hw->os, "Inavlid hw_dif blocksize %d\n", hw_dif->blk_size);
730 for (i = 0; i < sgl_count; i++) {
731 if ((sgl[i].len % blocksize) != 0) {
732 ocs_log_test(hw->os, "sgl[%d] len of %ld is not multiple of blocksize\n",
739 for (i = 0; i < sgl_count; i++) {
740 ocs_assert(sgl[i].addr, -1);
741 ocs_assert(sgl[i].len, -1);
743 /* If DIF is enabled, and DIF is separate, then append a SEED then DIF SGE */
744 if (hw_dif->dif_separate) {
745 rc = ocs_hw_io_add_seed_sge(hw, hio, hw_dif);
749 rc = ocs_hw_io_add_dif_sge(hw, hio, sgl[i].dif_addr);
753 /* Update the ref_tag for the next DIF seed SGE */
754 blockcount = sgl[i].len / blocksize;
755 if (hw_dif->dif_oper == OCS_HW_DIF_OPER_INSERT) {
756 hw_dif->ref_tag_repl += blockcount;
758 hw_dif->ref_tag_cmp += blockcount;
763 rc = ocs_hw_io_add_sge(hw, hio, sgl[i].addr, sgl[i].len);
765 ocs_log_err(ocs, "ocs_hw_io_add_sge failed: count=%d rc=%d\n",
771 for (i = 0; i < sgl_count; i++) {
772 ocs_assert(sgl[i].addr, -1);
773 ocs_assert(sgl[i].len, -1);
776 rc = ocs_hw_io_add_sge(hw, hio, sgl[i].addr, sgl[i].len);
778 ocs_log_err(ocs, "ocs_hw_io_add_sge failed: count=%d rc=%d\n",
788 * @ingroup scsi_api_base
789 * @brief Convert SCSI API T10 DIF information into the FC HW format.
791 * @param ocs Pointer to the ocs structure for logging.
792 * @param scsi_dif_info Pointer to the SCSI API T10 DIF fields.
793 * @param hw_dif_info Pointer to the FC HW API T10 DIF fields.
795 * @return Returns 0 on success, or a negative error code value on failure.
799 ocs_scsi_convert_dif_info(ocs_t *ocs, ocs_scsi_dif_info_t *scsi_dif_info, ocs_hw_dif_info_t *hw_dif_info)
802 ocs_memset(hw_dif_info, 0, sizeof(ocs_hw_dif_info_t));
804 if (scsi_dif_info == NULL) {
805 hw_dif_info->dif_oper = OCS_HW_DIF_OPER_DISABLED;
806 hw_dif_info->blk_size = OCS_HW_DIF_BK_SIZE_NA;
810 /* Convert the DIF operation */
811 switch(scsi_dif_info->dif_oper) {
812 case OCS_SCSI_DIF_OPER_IN_NODIF_OUT_CRC:
813 hw_dif_info->dif_oper = OCS_HW_SGE_DIF_OP_IN_NODIF_OUT_CRC;
814 hw_dif_info->dif = SLI4_DIF_INSERT;
816 case OCS_SCSI_DIF_OPER_IN_CRC_OUT_NODIF:
817 hw_dif_info->dif_oper = OCS_HW_SGE_DIF_OP_IN_CRC_OUT_NODIF;
818 hw_dif_info->dif = SLI4_DIF_STRIP;
820 case OCS_SCSI_DIF_OPER_IN_NODIF_OUT_CHKSUM:
821 hw_dif_info->dif_oper = OCS_HW_SGE_DIF_OP_IN_NODIF_OUT_CHKSUM;
822 hw_dif_info->dif = SLI4_DIF_INSERT;
824 case OCS_SCSI_DIF_OPER_IN_CHKSUM_OUT_NODIF:
825 hw_dif_info->dif_oper = OCS_HW_SGE_DIF_OP_IN_CHKSUM_OUT_NODIF;
826 hw_dif_info->dif = SLI4_DIF_STRIP;
828 case OCS_SCSI_DIF_OPER_IN_CRC_OUT_CRC:
829 hw_dif_info->dif_oper = OCS_HW_SGE_DIF_OP_IN_CRC_OUT_CRC;
830 hw_dif_info->dif = SLI4_DIF_PASS_THROUGH;
832 case OCS_SCSI_DIF_OPER_IN_CHKSUM_OUT_CHKSUM:
833 hw_dif_info->dif_oper = OCS_HW_SGE_DIF_OP_IN_CHKSUM_OUT_CHKSUM;
834 hw_dif_info->dif = SLI4_DIF_PASS_THROUGH;
836 case OCS_SCSI_DIF_OPER_IN_CRC_OUT_CHKSUM:
837 hw_dif_info->dif_oper = OCS_HW_SGE_DIF_OP_IN_CRC_OUT_CHKSUM;
838 hw_dif_info->dif = SLI4_DIF_PASS_THROUGH;
840 case OCS_SCSI_DIF_OPER_IN_CHKSUM_OUT_CRC:
841 hw_dif_info->dif_oper = OCS_HW_SGE_DIF_OP_IN_CHKSUM_OUT_CRC;
842 hw_dif_info->dif = SLI4_DIF_PASS_THROUGH;
844 case OCS_SCSI_DIF_OPER_IN_RAW_OUT_RAW:
845 hw_dif_info->dif_oper = OCS_HW_SGE_DIF_OP_IN_RAW_OUT_RAW;
846 hw_dif_info->dif = SLI4_DIF_PASS_THROUGH;
849 ocs_log_test(ocs, "unhandled SCSI DIF operation %d\n",
850 scsi_dif_info->dif_oper);
854 switch(scsi_dif_info->blk_size) {
855 case OCS_SCSI_DIF_BK_SIZE_512:
856 hw_dif_info->blk_size = OCS_HW_DIF_BK_SIZE_512;
858 case OCS_SCSI_DIF_BK_SIZE_1024:
859 hw_dif_info->blk_size = OCS_HW_DIF_BK_SIZE_1024;
861 case OCS_SCSI_DIF_BK_SIZE_2048:
862 hw_dif_info->blk_size = OCS_HW_DIF_BK_SIZE_2048;
864 case OCS_SCSI_DIF_BK_SIZE_4096:
865 hw_dif_info->blk_size = OCS_HW_DIF_BK_SIZE_4096;
867 case OCS_SCSI_DIF_BK_SIZE_520:
868 hw_dif_info->blk_size = OCS_HW_DIF_BK_SIZE_520;
870 case OCS_SCSI_DIF_BK_SIZE_4104:
871 hw_dif_info->blk_size = OCS_HW_DIF_BK_SIZE_4104;
874 ocs_log_test(ocs, "unhandled SCSI DIF block size %d\n",
875 scsi_dif_info->blk_size);
879 /* If the operation is an INSERT the tags provided are the ones that should be
880 * inserted, otherwise they're the ones to be checked against. */
881 if (hw_dif_info->dif == SLI4_DIF_INSERT ) {
882 hw_dif_info->ref_tag_repl = scsi_dif_info->ref_tag;
883 hw_dif_info->app_tag_repl = scsi_dif_info->app_tag;
885 hw_dif_info->ref_tag_cmp = scsi_dif_info->ref_tag;
886 hw_dif_info->app_tag_cmp = scsi_dif_info->app_tag;
889 hw_dif_info->check_ref_tag = scsi_dif_info->check_ref_tag;
890 hw_dif_info->check_app_tag = scsi_dif_info->check_app_tag;
891 hw_dif_info->check_guard = scsi_dif_info->check_guard;
892 hw_dif_info->auto_incr_ref_tag = 1;
893 hw_dif_info->dif_separate = scsi_dif_info->dif_separate;
894 hw_dif_info->disable_app_ffff = scsi_dif_info->disable_app_ffff;
895 hw_dif_info->disable_app_ref_ffff = scsi_dif_info->disable_app_ref_ffff;
897 ocs_hw_get(&ocs->hw, OCS_HW_DIF_SEED, &dif_seed);
898 hw_dif_info->dif_seed = dif_seed;
904 * @ingroup scsi_api_base
905 * @brief This function logs the SGLs for an IO.
907 * @param io Pointer to the IO context.
909 static void ocs_log_sgl(ocs_io_t *io)
911 ocs_hw_io_t *hio = io->hio;
912 sli4_sge_t *data = NULL;
913 uint32_t *dword = NULL;
917 scsi_io_trace(io, "def_sgl at 0x%x 0x%08x\n",
918 ocs_addr32_hi(hio->def_sgl.phys),
919 ocs_addr32_lo(hio->def_sgl.phys));
920 n_sge = (hio->sgl == &hio->def_sgl ? hio->n_sge : hio->def_sgl_count);
921 for (i = 0, data = hio->def_sgl.virt; i < n_sge; i++, data++) {
922 dword = (uint32_t*)data;
924 scsi_io_trace(io, "SGL %2d 0x%08x 0x%08x 0x%08x 0x%08x\n",
925 i, dword[0], dword[1], dword[2], dword[3]);
927 if (dword[2] & (1U << 31)) {
932 if (hio->ovfl_sgl != NULL &&
933 hio->sgl == hio->ovfl_sgl) {
934 scsi_io_trace(io, "Overflow at 0x%x 0x%08x\n",
935 ocs_addr32_hi(hio->ovfl_sgl->phys),
936 ocs_addr32_lo(hio->ovfl_sgl->phys));
937 for (i = 0, data = hio->ovfl_sgl->virt; i < hio->n_sge; i++, data++) {
938 dword = (uint32_t*)data;
940 scsi_io_trace(io, "SGL %2d 0x%08x 0x%08x 0x%08x 0x%08x\n",
941 i, dword[0], dword[1], dword[2], dword[3]);
942 if (dword[2] & (1U << 31)) {
951 * @brief Check pending error asynchronous callback function.
954 * Invoke the HW callback function for a given IO. This function is called
955 * from the NOP mailbox completion context.
957 * @param hw Pointer to HW object.
958 * @param status Completion status.
959 * @param mqe Mailbox completion queue entry.
960 * @param arg General purpose argument.
965 ocs_scsi_check_pending_async_cb(ocs_hw_t *hw, int32_t status, uint8_t *mqe, void *arg)
970 if (io->hw_cb != NULL) {
971 ocs_hw_done_t cb = io->hw_cb;
974 cb(io->hio, NULL, 0, SLI4_FC_WCQE_STATUS_DISPATCH_ERROR, 0, io);
981 * @brief Check for pending IOs to dispatch.
984 * If there are IOs on the pending list, and a HW IO is available, then
987 * @param ocs Pointer to the OCS structure.
993 ocs_scsi_check_pending(ocs_t *ocs)
995 ocs_xport_t *xport = ocs->xport;
1002 /* Guard against recursion */
1003 if (ocs_atomic_add_return(&xport->io_pending_recursing, 1)) {
1004 /* This function is already running. Decrement and return. */
1005 ocs_atomic_sub_return(&xport->io_pending_recursing, 1);
1010 ocs_lock(&xport->io_pending_lock);
1013 io = ocs_list_remove_head(&xport->io_pending_list);
1015 if (io->io_type == OCS_IO_TYPE_ABORT) {
1018 hio = ocs_hw_io_alloc(&ocs->hw);
1021 * No HW IO available.
1022 * Put IO back on the front of pending list
1024 ocs_list_add_head(&xport->io_pending_list, io);
1027 hio->eq = io->hw_priv;
1031 /* Must drop the lock before dispatching the IO */
1032 ocs_unlock(&xport->io_pending_lock);
1038 * We pulled an IO off the pending list,
1039 * and either got an HW IO or don't need one
1041 ocs_atomic_sub_return(&xport->io_pending_count, 1);
1043 status = ocs_scsi_io_dispatch_no_hw_io(io);
1045 status = ocs_scsi_io_dispatch_hw_io(io, hio);
1049 * Invoke the HW callback, but do so in the separate execution context,
1050 * provided by the NOP mailbox completion processing context by using
1051 * ocs_hw_async_call()
1053 if (ocs_hw_async_call(&ocs->hw, ocs_scsi_check_pending_async_cb, io)) {
1054 ocs_log_test(ocs, "call to ocs_hw_async_call() failed\n");
1058 } while (io != NULL);
1061 * If nothing was removed from the list,
1062 * we might be in a case where we need to abort an
1063 * active IO and the abort is on the pending list.
1064 * Look for an abort we can dispatch.
1069 ocs_lock(&xport->io_pending_lock);
1070 ocs_list_foreach(&xport->io_pending_list, io) {
1071 if (io->io_type == OCS_IO_TYPE_ABORT) {
1072 if (io->io_to_abort->hio != NULL) {
1073 /* This IO has a HW IO, so it is active. Dispatch the abort. */
1076 /* Leave this abort on the pending list and keep looking */
1081 ocs_list_remove(&xport->io_pending_list, io);
1082 ocs_atomic_sub_return(&xport->io_pending_count, 1);
1086 ocs_unlock(&xport->io_pending_lock);
1089 status = ocs_scsi_io_dispatch_no_hw_io(io);
1091 if (ocs_hw_async_call(&ocs->hw, ocs_scsi_check_pending_async_cb, io)) {
1092 ocs_log_test(ocs, "call to ocs_hw_async_call() failed\n");
1098 ocs_atomic_sub_return(&xport->io_pending_recursing, 1);
1103 * @brief Attempt to dispatch a non-abort IO
1106 * An IO is dispatched:
1107 * - if the pending list is not empty, add IO to pending list
1108 * and call a function to process the pending list.
1109 * - if pending list is empty, try to allocate a HW IO. If none
1110 * is available, place this IO at the tail of the pending IO
1112 * - if HW IO is available, attach this IO to the HW IO and
1115 * @param io Pointer to IO structure.
1116 * @param cb Callback function.
1118 * @return Returns 0 on success, a negative error code value on failure.
1122 ocs_scsi_io_dispatch(ocs_io_t *io, void *cb)
1125 ocs_t *ocs = io->ocs;
1126 ocs_xport_t *xport = ocs->xport;
1128 ocs_assert(io->cmd_tgt || io->cmd_ini, -1);
1129 ocs_assert((io->io_type != OCS_IO_TYPE_ABORT), -1);
1133 * if this IO already has a HW IO, then this is either not the first phase of
1134 * the IO. Send it to the HW.
1136 if (io->hio != NULL) {
1137 return ocs_scsi_io_dispatch_hw_io(io, io->hio);
1141 * We don't already have a HW IO associated with the IO. First check
1142 * the pending list. If not empty, add IO to the tail and process the
1145 ocs_lock(&xport->io_pending_lock);
1146 if (!ocs_list_empty(&xport->io_pending_list)) {
1148 * If this is a low latency request, the put at the front of the IO pending
1149 * queue, otherwise put it at the end of the queue.
1151 if (io->low_latency) {
1152 ocs_list_add_head(&xport->io_pending_list, io);
1154 ocs_list_add_tail(&xport->io_pending_list, io);
1156 ocs_unlock(&xport->io_pending_lock);
1157 ocs_atomic_add_return(&xport->io_pending_count, 1);
1158 ocs_atomic_add_return(&xport->io_total_pending, 1);
1160 /* process pending list */
1161 ocs_scsi_check_pending(ocs);
1164 ocs_unlock(&xport->io_pending_lock);
1167 * We don't have a HW IO associated with the IO and there's nothing
1168 * on the pending list. Attempt to allocate a HW IO and dispatch it.
1170 hio = ocs_hw_io_alloc(&io->ocs->hw);
1172 /* Couldn't get a HW IO. Save this IO on the pending list */
1173 ocs_lock(&xport->io_pending_lock);
1174 ocs_list_add_tail(&xport->io_pending_list, io);
1175 ocs_unlock(&xport->io_pending_lock);
1177 ocs_atomic_add_return(&xport->io_total_pending, 1);
1178 ocs_atomic_add_return(&xport->io_pending_count, 1);
1182 /* We successfully allocated a HW IO; dispatch to HW */
1183 return ocs_scsi_io_dispatch_hw_io(io, hio);
1187 * @brief Attempt to dispatch an Abort IO.
1190 * An Abort IO is dispatched:
1191 * - if the pending list is not empty, add IO to pending list
1192 * and call a function to process the pending list.
1193 * - if pending list is empty, send abort to the HW.
1195 * @param io Pointer to IO structure.
1196 * @param cb Callback function.
1198 * @return Returns 0 on success, a negative error code value on failure.
1202 ocs_scsi_io_dispatch_abort(ocs_io_t *io, void *cb)
1204 ocs_t *ocs = io->ocs;
1205 ocs_xport_t *xport = ocs->xport;
1207 ocs_assert((io->io_type == OCS_IO_TYPE_ABORT), -1);
1211 * For aborts, we don't need a HW IO, but we still want to pass through
1212 * the pending list to preserve ordering. Thus, if the pending list is
1213 * not empty, add this abort to the pending list and process the pending list.
1215 ocs_lock(&xport->io_pending_lock);
1216 if (!ocs_list_empty(&xport->io_pending_list)) {
1217 ocs_list_add_tail(&xport->io_pending_list, io);
1218 ocs_unlock(&xport->io_pending_lock);
1219 ocs_atomic_add_return(&xport->io_pending_count, 1);
1220 ocs_atomic_add_return(&xport->io_total_pending, 1);
1222 /* process pending list */
1223 ocs_scsi_check_pending(ocs);
1226 ocs_unlock(&xport->io_pending_lock);
1228 /* nothing on pending list, dispatch abort */
1229 return ocs_scsi_io_dispatch_no_hw_io(io);
1234 * @brief Dispatch IO
1237 * An IO and its associated HW IO is dispatched to the HW.
1239 * @param io Pointer to IO structure.
1240 * @param hio Pointer to HW IO structure from which IO will be
1243 * @return Returns 0 on success, a negative error code value on failure.
1247 ocs_scsi_io_dispatch_hw_io(ocs_io_t *io, ocs_hw_io_t *hio)
1250 ocs_t *ocs = io->ocs;
1252 /* Got a HW IO; update ini/tgt_task_tag with HW IO info and dispatch */
1255 io->tgt_task_tag = hio->indicator;
1256 } else if (io->cmd_ini) {
1257 io->init_task_tag = hio->indicator;
1259 io->hw_tag = hio->reqtag;
1261 hio->eq = io->hw_priv;
1263 /* Copy WQ steering */
1264 switch(io->wq_steering) {
1265 case OCS_SCSI_WQ_STEERING_CLASS >> OCS_SCSI_WQ_STEERING_SHIFT:
1266 hio->wq_steering = OCS_HW_WQ_STEERING_CLASS;
1268 case OCS_SCSI_WQ_STEERING_REQUEST >> OCS_SCSI_WQ_STEERING_SHIFT:
1269 hio->wq_steering = OCS_HW_WQ_STEERING_REQUEST;
1271 case OCS_SCSI_WQ_STEERING_CPU >> OCS_SCSI_WQ_STEERING_SHIFT:
1272 hio->wq_steering = OCS_HW_WQ_STEERING_CPU;
1276 switch (io->io_type) {
1277 case OCS_IO_TYPE_IO: {
1279 uint32_t total_count;
1280 uint32_t host_allocated;
1282 ocs_hw_get(&ocs->hw, OCS_HW_N_SGL, &max_sgl);
1283 ocs_hw_get(&ocs->hw, OCS_HW_SGL_CHAINING_HOST_ALLOCATED, &host_allocated);
1286 * If the requested SGL is larger than the default size, then we can allocate
1289 total_count = ocs_scsi_count_sgls(&io->hw_dif, io->sgl, io->sgl_count);
1292 * Lancer requires us to allocate the chained memory area, but
1293 * Skyhawk must use the SGL list associated with another XRI.
1295 if (host_allocated && total_count > max_sgl) {
1296 /* Compute count needed, the number extra plus 1 for the link sge */
1297 uint32_t count = total_count - max_sgl + 1;
1298 rc = ocs_dma_alloc(ocs, &io->ovfl_sgl, count*sizeof(sli4_sge_t), 64);
1300 ocs_log_err(ocs, "ocs_dma_alloc overflow sgl failed\n");
1303 rc = ocs_hw_io_register_sgl(&ocs->hw, io->hio, &io->ovfl_sgl, count);
1305 ocs_scsi_io_free_ovfl(io);
1306 ocs_log_err(ocs, "ocs_hw_io_register_sgl() failed\n");
1309 /* EVT: update chained_io_count */
1310 io->node->chained_io_count++;
1313 rc = ocs_scsi_build_sgls(&ocs->hw, io->hio, &io->hw_dif, io->sgl, io->sgl_count, io->hio_type);
1315 ocs_scsi_io_free_ovfl(io);
1319 if (OCS_LOG_ENABLE_SCSI_TRACE(ocs)) {
1324 io->iparam.fcp_tgt.app_id = io->app_id;
1327 rc = ocs_hw_io_send(&io->ocs->hw, io->hio_type, io->hio, io->wire_len, &io->iparam, &io->node->rnode,
1331 case OCS_IO_TYPE_ELS:
1332 case OCS_IO_TYPE_CT: {
1333 rc = ocs_hw_srrs_send(&ocs->hw, io->hio_type, io->hio,
1334 &io->els_req, io->wire_len,
1335 &io->els_rsp, &io->node->rnode, &io->iparam,
1339 case OCS_IO_TYPE_CT_RESP: {
1340 rc = ocs_hw_srrs_send(&ocs->hw, io->hio_type, io->hio,
1341 &io->els_rsp, io->wire_len,
1342 NULL, &io->node->rnode, &io->iparam,
1346 case OCS_IO_TYPE_BLS_RESP: {
1347 /* no need to update tgt_task_tag for BLS response since the RX_ID
1348 * will be specified by the payload, not the XRI */
1349 rc = ocs_hw_srrs_send(&ocs->hw, io->hio_type, io->hio,
1350 NULL, 0, NULL, &io->node->rnode, &io->iparam, io->hw_cb, io);
1354 scsi_io_printf(io, "Unknown IO type=%d\n", io->io_type);
1362 * @brief Dispatch IO
1365 * An IO that does require a HW IO is dispatched to the HW.
1367 * @param io Pointer to IO structure.
1369 * @return Returns 0 on success, or a negative error code value on failure.
1373 ocs_scsi_io_dispatch_no_hw_io(ocs_io_t *io)
1377 switch (io->io_type) {
1378 case OCS_IO_TYPE_ABORT: {
1379 ocs_hw_io_t *hio_to_abort = NULL;
1380 ocs_assert(io->io_to_abort, -1);
1381 hio_to_abort = io->io_to_abort->hio;
1383 if (hio_to_abort == NULL) {
1385 * If "IO to abort" does not have an associated HW IO, immediately
1386 * make callback with success. The command must have been sent to
1387 * the backend, but the data phase has not yet started, so we don't
1390 * Note: since the backend shims should be taking a reference
1391 * on io_to_abort, it should not be possible to have been completed
1392 * and freed by the backend before the abort got here.
1394 scsi_io_printf(io, "IO: " SCSI_IOFMT " not active\n",
1395 SCSI_IOFMT_ARGS(io->io_to_abort));
1396 ((ocs_hw_done_t)io->hw_cb)(io->hio, NULL, 0, SLI4_FC_WCQE_STATUS_SUCCESS, 0, io);
1399 /* HW IO is valid, abort it */
1400 scsi_io_printf(io, "aborting " SCSI_IOFMT "\n", SCSI_IOFMT_ARGS(io->io_to_abort));
1401 rc = ocs_hw_io_abort(&io->ocs->hw, hio_to_abort, io->send_abts,
1404 int status = SLI4_FC_WCQE_STATUS_SUCCESS;
1405 if ((rc != OCS_HW_RTN_IO_NOT_ACTIVE) &&
1406 (rc != OCS_HW_RTN_IO_ABORT_IN_PROGRESS)) {
1408 scsi_io_printf(io, "Failed to abort IO: " SCSI_IOFMT " status=%d\n",
1409 SCSI_IOFMT_ARGS(io->io_to_abort), rc);
1411 ((ocs_hw_done_t)io->hw_cb)(io->hio, NULL, 0, status, 0, io);
1419 scsi_io_printf(io, "Unknown IO type=%d\n", io->io_type);
1427 * @ingroup scsi_api_base
1428 * @brief Send read/write data.
1431 * This call is made by a target-server to initiate a SCSI read or write data phase, transferring
1432 * data between the target to the remote initiator. The payload is specified by the
1433 * scatter-gather list @c sgl of length @c sgl_count. The @c wire_len argument
1434 * specifies the payload length (independent of the scatter-gather list cumulative length).
1436 * The @c flags argument has one bit, OCS_SCSI_LAST_DATAPHASE, which is a hint to the base
1437 * driver that it may use auto SCSI response features if the hardware supports it.
1439 * Upon completion, the callback function @b cb is called with flags indicating that the
1440 * IO has completed (OCS_SCSI_IO_COMPL) and another data phase or response may be sent;
1441 * that the IO has completed and no response needs to be sent (OCS_SCSI_IO_COMPL_NO_RSP);
1442 * or that the IO was aborted (OCS_SCSI_IO_ABORTED).
1444 * @param io Pointer to the IO context.
1445 * @param flags Flags controlling the sending of data.
1446 * @param dif_info Pointer to T10 DIF fields, or NULL if no DIF.
1447 * @param sgl Pointer to the payload scatter-gather list.
1448 * @param sgl_count Count of the scatter-gather list elements.
1449 * @param xwire_len Length of the payload on wire, in bytes.
1450 * @param type HW IO type.
1451 * @param enable_ar Enable auto-response if true.
1452 * @param cb Completion callback.
1453 * @param arg Application-supplied callback data.
1455 * @return Returns 0 on success, or a negative error code value on failure.
1458 static inline int32_t
1459 ocs_scsi_xfer_data(ocs_io_t *io, uint32_t flags,
1460 ocs_scsi_dif_info_t *dif_info,
1461 ocs_scsi_sgl_t *sgl, uint32_t sgl_count, uint32_t xwire_len,
1462 ocs_hw_io_type_e type, int enable_ar,
1463 ocs_scsi_io_cb_t cb, void *arg)
1467 uint32_t disable_ar_tgt_dif = FALSE;
1468 size_t residual = 0;
1470 if ((dif_info != NULL) && (dif_info->dif_oper == OCS_SCSI_DIF_OPER_DISABLED)) {
1476 if (dif_info != NULL) {
1477 ocs_hw_get(&io->ocs->hw, OCS_HW_DISABLE_AR_TGT_DIF, &disable_ar_tgt_dif);
1478 if (disable_ar_tgt_dif) {
1483 io->sgl_count = sgl_count;
1485 /* If needed, copy SGL */
1486 if (sgl && (sgl != io->sgl)) {
1487 ocs_assert(sgl_count <= io->sgl_allocated, -1);
1488 ocs_memcpy(io->sgl, sgl, sgl_count*sizeof(*io->sgl));
1492 ocs_assert(ocs, -1);
1493 ocs_assert(io->node, -1);
1495 scsi_io_trace(io, "%s wire_len %d\n", (type == OCS_HW_IO_TARGET_READ) ? "send" : "recv", xwire_len);
1497 ocs_assert(sgl, -1);
1498 ocs_assert(sgl_count > 0, -1);
1499 ocs_assert(io->exp_xfer_len > io->transferred, -1);
1501 io->hio_type = type;
1503 io->scsi_tgt_cb = cb;
1504 io->scsi_tgt_cb_arg = arg;
1506 rc = ocs_scsi_convert_dif_info(ocs, dif_info, &io->hw_dif);
1511 /* If DIF is used, then save lba for error recovery */
1513 io->scsi_dif_info = *dif_info;
1516 io->wire_len = MIN(xwire_len, io->exp_xfer_len - io->transferred);
1517 residual = (xwire_len - io->wire_len);
1519 ocs_memset(&io->iparam, 0, sizeof(io->iparam));
1520 io->iparam.fcp_tgt.ox_id = io->init_task_tag;
1521 io->iparam.fcp_tgt.offset = io->transferred;
1522 io->iparam.fcp_tgt.dif_oper = io->hw_dif.dif;
1523 io->iparam.fcp_tgt.blk_size = io->hw_dif.blk_size;
1524 io->iparam.fcp_tgt.cs_ctl = io->cs_ctl;
1525 io->iparam.fcp_tgt.timeout = io->timeout;
1527 /* if this is the last data phase and there is no residual, enable
1528 * auto-good-response
1530 if (enable_ar && (flags & OCS_SCSI_LAST_DATAPHASE) &&
1531 (residual == 0) && ((io->transferred + io->wire_len) == io->exp_xfer_len) && (!(flags & OCS_SCSI_NO_AUTO_RESPONSE))) {
1532 io->iparam.fcp_tgt.flags |= SLI4_IO_AUTO_GOOD_RESPONSE;
1533 io->auto_resp = TRUE;
1535 io->auto_resp = FALSE;
1538 /* save this transfer length */
1539 io->xfer_req = io->wire_len;
1541 /* Adjust the transferred count to account for overrun
1542 * when the residual is calculated in ocs_scsi_send_resp
1544 io->transferred += residual;
1546 /* Adjust the SGL size if there is overrun */
1549 ocs_scsi_sgl_t *sgl_ptr = &io->sgl[sgl_count-1];
1552 size_t len = sgl_ptr->len;
1553 if ( len > residual) {
1554 sgl_ptr->len = len - residual;
1565 /* Set latency and WQ steering */
1566 io->low_latency = (flags & OCS_SCSI_LOW_LATENCY) != 0;
1567 io->wq_steering = (flags & OCS_SCSI_WQ_STEERING_MASK) >> OCS_SCSI_WQ_STEERING_SHIFT;
1568 io->wq_class = (flags & OCS_SCSI_WQ_CLASS_MASK) >> OCS_SCSI_WQ_CLASS_SHIFT;
1570 return ocs_scsi_io_dispatch(io, ocs_target_io_cb);
1574 ocs_scsi_send_rd_data(ocs_io_t *io, uint32_t flags,
1575 ocs_scsi_dif_info_t *dif_info,
1576 ocs_scsi_sgl_t *sgl, uint32_t sgl_count, uint32_t len,
1577 ocs_scsi_io_cb_t cb, void *arg)
1579 return ocs_scsi_xfer_data(io, flags, dif_info, sgl, sgl_count, len, OCS_HW_IO_TARGET_READ,
1580 enable_tsend_auto_resp(io->ocs), cb, arg);
1584 ocs_scsi_recv_wr_data(ocs_io_t *io, uint32_t flags,
1585 ocs_scsi_dif_info_t *dif_info,
1586 ocs_scsi_sgl_t *sgl, uint32_t sgl_count, uint32_t len,
1587 ocs_scsi_io_cb_t cb, void *arg)
1589 return ocs_scsi_xfer_data(io, flags, dif_info, sgl, sgl_count, len, OCS_HW_IO_TARGET_WRITE,
1590 enable_treceive_auto_resp(io->ocs), cb, arg);
1594 * @ingroup scsi_api_base
1595 * @brief Free overflow SGL.
1598 * Free the overflow SGL if it is present.
1600 * @param io Pointer to IO object.
1605 ocs_scsi_io_free_ovfl(ocs_io_t *io) {
1606 if (io->ovfl_sgl.size) {
1607 ocs_dma_free(io->ocs, &io->ovfl_sgl);
1612 * @ingroup scsi_api_base
1613 * @brief Send response data.
1616 * This function is used by a target-server to send the SCSI response data to a remote
1617 * initiator node. The target-server populates the @c ocs_scsi_cmd_resp_t
1618 * argument with scsi status, status qualifier, sense data, and response data, as
1621 * Upon completion, the callback function @c cb is invoked. The target-server will generally
1622 * clean up its IO context resources and call ocs_scsi_io_complete().
1624 * @param io Pointer to the IO context.
1625 * @param flags Flags to control sending of the SCSI response.
1626 * @param rsp Pointer to the response data populated by the caller.
1627 * @param cb Completion callback.
1628 * @param arg Application-specified completion callback argument.
1630 * @return Returns 0 on success, or a negative error code value on failure.
1633 ocs_scsi_send_resp(ocs_io_t *io, uint32_t flags, ocs_scsi_cmd_resp_t *rsp, ocs_scsi_io_cb_t cb, void *arg)
1637 int auto_resp = TRUE; /* Always try auto resp */
1638 uint8_t scsi_status = 0;
1639 uint16_t scsi_status_qualifier = 0;
1640 uint8_t *sense_data = NULL;
1641 uint32_t sense_data_length = 0;
1646 ocs_assert(ocs, -1);
1648 ocs_assert(io->node, -1);
1650 ocs_scsi_convert_dif_info(ocs, NULL, &io->hw_dif);
1653 scsi_status = rsp->scsi_status;
1654 scsi_status_qualifier = rsp->scsi_status_qualifier;
1655 sense_data = rsp->sense_data;
1656 sense_data_length = rsp->sense_data_length;
1657 residual = rsp->residual;
1659 residual = io->exp_xfer_len - io->transferred;
1663 io->hio_type = OCS_HW_IO_TARGET_RSP;
1665 io->scsi_tgt_cb = cb;
1666 io->scsi_tgt_cb_arg = arg;
1668 ocs_memset(&io->iparam, 0, sizeof(io->iparam));
1669 io->iparam.fcp_tgt.ox_id = io->init_task_tag;
1670 io->iparam.fcp_tgt.offset = 0;
1671 io->iparam.fcp_tgt.cs_ctl = io->cs_ctl;
1672 io->iparam.fcp_tgt.timeout = io->timeout;
1674 /* Set low latency queueing request */
1675 io->low_latency = (flags & OCS_SCSI_LOW_LATENCY) != 0;
1676 io->wq_steering = (flags & OCS_SCSI_WQ_STEERING_MASK) >> OCS_SCSI_WQ_STEERING_SHIFT;
1677 io->wq_class = (flags & OCS_SCSI_WQ_CLASS_MASK) >> OCS_SCSI_WQ_CLASS_SHIFT;
1679 if ((scsi_status != 0) || residual || sense_data_length) {
1680 fcp_rsp_iu_t *fcprsp = io->rspbuf.virt;
1683 ocs_log_err(ocs, "NULL response buffer\n");
1689 ocs_memset(fcprsp, 0, sizeof(*fcprsp));
1691 io->wire_len += (sizeof(*fcprsp) - sizeof(fcprsp->data));
1693 fcprsp->scsi_status = scsi_status;
1694 *((uint16_t*)fcprsp->status_qualifier) = ocs_htobe16(scsi_status_qualifier);
1696 /* set residual status if necessary */
1697 if (residual != 0) {
1698 /* FCP: if data transferred is less than the amount expected, then this is an
1699 * underflow. If data transferred would have been greater than the amount expected
1700 * then this is an overflow
1703 fcprsp->flags |= FCP_RESID_UNDER;
1704 *((uint32_t *)fcprsp->fcp_resid) = ocs_htobe32(residual);
1706 fcprsp->flags |= FCP_RESID_OVER;
1707 *((uint32_t *)fcprsp->fcp_resid) = ocs_htobe32(-residual);
1711 if (sense_data && sense_data_length) {
1712 ocs_assert(sense_data_length <= sizeof(fcprsp->data), -1);
1713 fcprsp->flags |= FCP_SNS_LEN_VALID;
1714 ocs_memcpy(fcprsp->data, sense_data, sense_data_length);
1715 *((uint32_t*)fcprsp->fcp_sns_len) = ocs_htobe32(sense_data_length);
1716 io->wire_len += sense_data_length;
1719 io->sgl[0].addr = io->rspbuf.phys;
1720 io->sgl[0].dif_addr = 0;
1721 io->sgl[0].len = io->wire_len;
1726 io->iparam.fcp_tgt.flags |= SLI4_IO_AUTO_GOOD_RESPONSE;
1729 return ocs_scsi_io_dispatch(io, ocs_target_io_cb);
1733 * @ingroup scsi_api_base
1734 * @brief Send TMF response data.
1737 * This function is used by a target-server to send SCSI TMF response data to a remote
1739 * Upon completion, the callback function @c cb is invoked. The target-server will generally
1740 * clean up its IO context resources and call ocs_scsi_io_complete().
1742 * @param io Pointer to the IO context.
1743 * @param rspcode TMF response code.
1744 * @param addl_rsp_info Additional TMF response information (may be NULL for zero data).
1745 * @param cb Completion callback.
1746 * @param arg Application-specified completion callback argument.
1748 * @return Returns 0 on success, or a negative error code value on failure.
1751 ocs_scsi_send_tmf_resp(ocs_io_t *io, ocs_scsi_tmf_resp_e rspcode, uint8_t addl_rsp_info[3],
1752 ocs_scsi_io_cb_t cb, void *arg)
1756 fcp_rsp_iu_t *fcprsp = NULL;
1757 fcp_rsp_info_t *rspinfo = NULL;
1758 uint8_t fcp_rspcode;
1761 ocs_assert(io->ocs, -1);
1762 ocs_assert(io->node, -1);
1767 ocs_scsi_convert_dif_info(ocs, NULL, &io->hw_dif);
1770 case OCS_SCSI_TMF_FUNCTION_COMPLETE:
1771 fcp_rspcode = FCP_TMF_COMPLETE;
1773 case OCS_SCSI_TMF_FUNCTION_SUCCEEDED:
1774 case OCS_SCSI_TMF_FUNCTION_IO_NOT_FOUND:
1775 fcp_rspcode = FCP_TMF_SUCCEEDED;
1777 case OCS_SCSI_TMF_FUNCTION_REJECTED:
1778 fcp_rspcode = FCP_TMF_REJECTED;
1780 case OCS_SCSI_TMF_INCORRECT_LOGICAL_UNIT_NUMBER:
1781 fcp_rspcode = FCP_TMF_INCORRECT_LUN;
1783 case OCS_SCSI_TMF_SERVICE_DELIVERY:
1784 fcp_rspcode = FCP_TMF_FAILED;
1787 fcp_rspcode = FCP_TMF_REJECTED;
1791 io->hio_type = OCS_HW_IO_TARGET_RSP;
1793 io->scsi_tgt_cb = cb;
1794 io->scsi_tgt_cb_arg = arg;
1796 if (io->tmf_cmd == OCS_SCSI_TMF_ABORT_TASK) {
1797 rc = ocs_target_send_bls_resp(io, cb, arg);
1801 /* populate the FCP TMF response */
1802 fcprsp = io->rspbuf.virt;
1803 ocs_memset(fcprsp, 0, sizeof(*fcprsp));
1805 fcprsp->flags |= FCP_RSP_LEN_VALID;
1807 rspinfo = (fcp_rsp_info_t*) fcprsp->data;
1808 if (addl_rsp_info != NULL) {
1809 ocs_memcpy(rspinfo->addl_rsp_info, addl_rsp_info, sizeof(rspinfo->addl_rsp_info));
1811 rspinfo->rsp_code = fcp_rspcode;
1813 io->wire_len = sizeof(*fcprsp) - sizeof(fcprsp->data) + sizeof(*rspinfo);
1815 *((uint32_t*)fcprsp->fcp_rsp_len) = ocs_htobe32(sizeof(*rspinfo));
1817 io->sgl[0].addr = io->rspbuf.phys;
1818 io->sgl[0].dif_addr = 0;
1819 io->sgl[0].len = io->wire_len;
1822 ocs_memset(&io->iparam, 0, sizeof(io->iparam));
1823 io->iparam.fcp_tgt.ox_id = io->init_task_tag;
1824 io->iparam.fcp_tgt.offset = 0;
1825 io->iparam.fcp_tgt.cs_ctl = io->cs_ctl;
1826 io->iparam.fcp_tgt.timeout = io->timeout;
1828 rc = ocs_scsi_io_dispatch(io, ocs_target_io_cb);
1834 * @brief Process target abort callback.
1837 * Accepts HW abort requests.
1839 * @param hio HW IO context.
1840 * @param rnode Remote node.
1841 * @param length Length of response data.
1842 * @param status Completion status.
1843 * @param ext_status Extended completion status.
1844 * @param app Application-specified callback data.
1846 * @return Returns 0 on success, or a negative error code value on failure.
1850 ocs_target_abort_cb(ocs_hw_io_t *hio, ocs_remote_node_t *rnode, uint32_t length, int32_t status, uint32_t ext_status, void *app)
1854 ocs_scsi_io_status_e scsi_status;
1857 ocs_assert(io->ocs, -1);
1862 ocs_scsi_io_cb_t abort_cb = io->abort_cb;
1863 void *abort_cb_arg = io->abort_cb_arg;
1865 io->abort_cb = NULL;
1866 io->abort_cb_arg = NULL;
1869 case SLI4_FC_WCQE_STATUS_SUCCESS:
1870 scsi_status = OCS_SCSI_STATUS_GOOD;
1872 case SLI4_FC_WCQE_STATUS_LOCAL_REJECT:
1873 switch (ext_status) {
1874 case SLI4_FC_LOCAL_REJECT_NO_XRI:
1875 scsi_status = OCS_SCSI_STATUS_NO_IO;
1877 case SLI4_FC_LOCAL_REJECT_ABORT_IN_PROGRESS:
1878 scsi_status = OCS_SCSI_STATUS_ABORT_IN_PROGRESS;
1881 /* TODO: we have seen 0x15 (abort in progress) */
1882 scsi_status = OCS_SCSI_STATUS_ERROR;
1886 case SLI4_FC_WCQE_STATUS_FCP_RSP_FAILURE:
1887 scsi_status = OCS_SCSI_STATUS_CHECK_RESPONSE;
1890 scsi_status = OCS_SCSI_STATUS_ERROR;
1893 /* invoke callback */
1894 abort_cb(io->io_to_abort, scsi_status, 0, abort_cb_arg);
1897 ocs_assert(io != io->io_to_abort, -1);
1899 /* done with IO to abort */
1900 ocs_ref_put(&io->io_to_abort->ref); /* ocs_ref_get(): ocs_scsi_tgt_abort_io() */
1902 ocs_io_free(ocs, io);
1904 ocs_scsi_check_pending(ocs);
1909 * @ingroup scsi_api_base
1910 * @brief Abort a target IO.
1913 * This routine is called from a SCSI target-server. It initiates an abort of a
1914 * previously-issued target data phase or response request.
1916 * @param io IO context.
1917 * @param cb SCSI target server callback.
1918 * @param arg SCSI target server supplied callback argument.
1920 * @return Returns 0 on success, or a non-zero value on failure.
1923 ocs_scsi_tgt_abort_io(ocs_io_t *io, ocs_scsi_io_cb_t cb, void *arg)
1929 ocs_io_t *abort_io = NULL;
1931 ocs_assert(io->node, -1);
1932 ocs_assert(io->ocs, -1);
1937 /* take a reference on IO being aborted */
1938 if ((ocs_ref_get_unless_zero(&io->ref) == 0)) {
1939 /* command no longer active */
1940 scsi_io_printf(io, "command no longer active\n");
1945 * allocate a new IO to send the abort request. Use ocs_io_alloc() directly, as
1946 * we need an IO object that will not fail allocation due to allocations being
1947 * disabled (in ocs_scsi_io_alloc())
1949 abort_io = ocs_io_alloc(ocs);
1950 if (abort_io == NULL) {
1951 ocs_atomic_add_return(&xport->io_alloc_failed_count, 1);
1952 ocs_ref_put(&io->ref); /* ocs_ref_get(): same function */
1956 /* Save the target server callback and argument */
1957 ocs_assert(abort_io->hio == NULL, -1);
1959 /* set generic fields */
1960 abort_io->cmd_tgt = TRUE;
1961 abort_io->node = io->node;
1963 /* set type and abort-specific fields */
1964 abort_io->io_type = OCS_IO_TYPE_ABORT;
1965 abort_io->display_name = "tgt_abort";
1966 abort_io->io_to_abort = io;
1967 abort_io->send_abts = FALSE;
1968 abort_io->abort_cb = cb;
1969 abort_io->abort_cb_arg = arg;
1971 /* now dispatch IO */
1972 rc = ocs_scsi_io_dispatch_abort(abort_io, ocs_target_abort_cb);
1974 ocs_ref_put(&io->ref); /* ocs_ref_get(): same function */
1980 * @brief Process target BLS response callback.
1983 * Accepts HW abort requests.
1985 * @param hio HW IO context.
1986 * @param rnode Remote node.
1987 * @param length Length of response data.
1988 * @param status Completion status.
1989 * @param ext_status Extended completion status.
1990 * @param app Application-specified callback data.
1992 * @return Returns 0 on success, or a negative error code value on failure.
1996 ocs_target_bls_resp_cb(ocs_hw_io_t *hio, ocs_remote_node_t *rnode, uint32_t length, int32_t status, uint32_t ext_status, void *app)
2000 ocs_scsi_io_status_e bls_status;
2003 ocs_assert(io->ocs, -1);
2007 /* BLS isn't really a "SCSI" concept, but use SCSI status */
2009 io_error_log(io, "s=%#x x=%#x\n", status, ext_status);
2010 bls_status = OCS_SCSI_STATUS_ERROR;
2012 bls_status = OCS_SCSI_STATUS_GOOD;
2016 ocs_scsi_io_cb_t bls_cb = io->bls_cb;
2017 void *bls_cb_arg = io->bls_cb_arg;
2020 io->bls_cb_arg = NULL;
2022 /* invoke callback */
2023 bls_cb(io, bls_status, 0, bls_cb_arg);
2026 ocs_scsi_check_pending(ocs);
2031 * @brief Complete abort request.
2034 * An abort request is completed by posting a BA_ACC for the IO that requested the abort.
2036 * @param io Pointer to the IO context.
2037 * @param cb Callback function to invoke upon completion.
2038 * @param arg Application-specified completion callback argument.
2040 * @return Returns 0 on success, or a negative error code value on failure.
2044 ocs_target_send_bls_resp(ocs_io_t *io, ocs_scsi_io_cb_t cb, void *arg)
2047 fc_ba_acc_payload_t *acc;
2051 /* fill out IO structure with everything needed to send BA_ACC */
2052 ocs_memset(&io->iparam, 0, sizeof(io->iparam));
2053 io->iparam.bls.ox_id = io->init_task_tag;
2054 io->iparam.bls.rx_id = io->abort_rx_id;
2056 acc = (void *)io->iparam.bls.payload;
2058 ocs_memset(io->iparam.bls.payload, 0, sizeof(io->iparam.bls.payload));
2059 acc->ox_id = io->iparam.bls.ox_id;
2060 acc->rx_id = io->iparam.bls.rx_id;
2061 acc->high_seq_cnt = UINT16_MAX;
2063 /* generic io fields have already been populated */
2065 /* set type and BLS-specific fields */
2066 io->io_type = OCS_IO_TYPE_BLS_RESP;
2067 io->display_name = "bls_rsp";
2068 io->hio_type = OCS_HW_BLS_ACC;
2070 io->bls_cb_arg = arg;
2073 rc = ocs_scsi_io_dispatch(io, ocs_target_bls_resp_cb);
2078 * @ingroup scsi_api_base
2079 * @brief Notify the base driver that the IO is complete.
2082 * This function is called by a target-server to notify the base driver that an IO
2083 * has completed, allowing for the base driver to free resources.
2085 * @n @b Note: This function is not called by initiator-clients.
2087 * @param io Pointer to IO context.
2092 ocs_scsi_io_complete(ocs_io_t *io)
2096 if (!ocs_io_busy(io)) {
2097 ocs_log_test(io->ocs, "Got completion for non-busy io with tag 0x%x\n", io->tag);
2101 scsi_io_trace(io, "freeing io 0x%p %s\n", io, io->display_name);
2102 ocs_assert(ocs_ref_read_count(&io->ref) > 0);
2103 ocs_ref_put(&io->ref); /* ocs_ref_get(): ocs_scsi_io_alloc() */
2107 * @brief Handle initiator IO completion.
2110 * This callback is made upon completion of an initiator operation (initiator read/write command).
2112 * @param hio HW IO context.
2113 * @param rnode Remote node.
2114 * @param length Length of completion data.
2115 * @param status Completion status.
2116 * @param ext_status Extended completion status.
2117 * @param app Application-specified callback data.
2123 ocs_initiator_io_cb(ocs_hw_io_t *hio, ocs_remote_node_t *rnode, uint32_t length,
2124 int32_t status, uint32_t ext_status, void *app)
2128 ocs_scsi_io_status_e scsi_status;
2131 ocs_assert(io->scsi_ini_cb);
2133 scsi_io_trace(io, "status x%x ext_status x%x\n", status, ext_status);
2138 ocs_scsi_io_free_ovfl(io);
2140 /* Call target server completion */
2141 if (io->scsi_ini_cb) {
2142 fcp_rsp_iu_t *fcprsp = io->rspbuf.virt;
2143 ocs_scsi_cmd_resp_t rsp;
2144 ocs_scsi_rsp_io_cb_t cb = io->scsi_ini_cb;
2146 uint8_t *pd = fcprsp->data;
2148 /* Clear the callback before invoking the callback */
2149 io->scsi_ini_cb = NULL;
2151 ocs_memset(&rsp, 0, sizeof(rsp));
2153 /* Unless status is FCP_RSP_FAILURE, fcprsp is not filled in */
2155 case SLI4_FC_WCQE_STATUS_SUCCESS:
2156 scsi_status = OCS_SCSI_STATUS_GOOD;
2158 case SLI4_FC_WCQE_STATUS_FCP_RSP_FAILURE:
2159 scsi_status = OCS_SCSI_STATUS_CHECK_RESPONSE;
2160 rsp.scsi_status = fcprsp->scsi_status;
2161 rsp.scsi_status_qualifier = ocs_be16toh(*((uint16_t*)fcprsp->status_qualifier));
2163 if (fcprsp->flags & FCP_RSP_LEN_VALID) {
2164 rsp.response_data = pd;
2165 rsp.response_data_length = ocs_fc_getbe32(fcprsp->fcp_rsp_len);
2166 pd += rsp.response_data_length;
2168 if (fcprsp->flags & FCP_SNS_LEN_VALID) {
2169 uint32_t sns_len = ocs_fc_getbe32(fcprsp->fcp_sns_len);
2170 rsp.sense_data = pd;
2171 rsp.sense_data_length = sns_len;
2175 if (fcprsp->flags & FCP_RESID_OVER) {
2176 rsp.residual = -ocs_fc_getbe32(fcprsp->fcp_resid);
2177 rsp.response_wire_length = length;
2178 } else if (fcprsp->flags & FCP_RESID_UNDER) {
2179 rsp.residual = ocs_fc_getbe32(fcprsp->fcp_resid);
2180 rsp.response_wire_length = length;
2184 * Note: The FCP_RSP_FAILURE can be returned for initiator IOs when the total data
2185 * placed does not match the requested length even if the status is good. If
2186 * the status is all zeroes, then we have to assume that a frame(s) were
2187 * dropped and change the status to LOCAL_REJECT/OUT_OF_ORDER_DATA
2189 if (length != io->wire_len) {
2190 uint32_t rsp_len = ext_status;
2191 uint8_t *rsp_bytes = io->rspbuf.virt;
2193 uint8_t all_zeroes = (rsp_len > 0);
2194 /* Check if the rsp is zero */
2195 for (i = 0; i < rsp_len; i++) {
2196 if (rsp_bytes[i] != 0) {
2202 scsi_status = OCS_SCSI_STATUS_ERROR;
2203 ocs_log_test(io->ocs, "[%s]" SCSI_IOFMT "local reject=0x%02x\n",
2204 io->node->display_name, SCSI_IOFMT_ARGS(io),
2205 SLI4_FC_LOCAL_REJECT_OUT_OF_ORDER_DATA);
2209 case SLI4_FC_WCQE_STATUS_LOCAL_REJECT:
2210 if (ext_status == SLI4_FC_LOCAL_REJECT_SEQUENCE_TIMEOUT) {
2211 scsi_status = OCS_SCSI_STATUS_COMMAND_TIMEOUT;
2213 scsi_status = OCS_SCSI_STATUS_ERROR;
2216 case SLI4_FC_WCQE_STATUS_DI_ERROR:
2217 if (ext_status & 0x01) {
2218 scsi_status = OCS_SCSI_STATUS_DIF_GUARD_ERROR;
2219 } else if (ext_status & 0x02) {
2220 scsi_status = OCS_SCSI_STATUS_DIF_APP_TAG_ERROR;
2221 } else if (ext_status & 0x04) {
2222 scsi_status = OCS_SCSI_STATUS_DIF_REF_TAG_ERROR;
2224 scsi_status = OCS_SCSI_STATUS_DIF_UNKNOWN_ERROR;
2228 scsi_status = OCS_SCSI_STATUS_ERROR;
2232 cb(io, scsi_status, &rsp, flags, io->scsi_ini_cb_arg);
2234 ocs_scsi_check_pending(ocs);
2238 * @ingroup scsi_api_base
2239 * @brief Initiate initiator read IO.
2242 * This call is made by an initiator-client to send a SCSI read command. The payload
2243 * for the command is given by a scatter-gather list @c sgl for @c sgl_count
2246 * Upon completion, the callback @b cb is invoked and passed request status.
2247 * If the command completed successfully, the callback is given SCSI response data.
2249 * @param node Pointer to the node.
2250 * @param io Pointer to the IO context.
2251 * @param lun LUN value.
2252 * @param cdb Pointer to the CDB.
2253 * @param cdb_len Length of the CDB.
2254 * @param dif_info Pointer to the T10 DIF fields, or NULL if no DIF.
2255 * @param sgl Pointer to the scatter-gather list.
2256 * @param sgl_count Count of the scatter-gather list elements.
2257 * @param wire_len Length of the payload.
2258 * @param cb Completion callback.
2259 * @param arg Application-specified completion callback argument.
2261 * @return Returns 0 on success, or a negative error code value on failure.
2264 ocs_scsi_send_rd_io(ocs_node_t *node, ocs_io_t *io, uint64_t lun, void *cdb, uint32_t cdb_len,
2265 ocs_scsi_dif_info_t *dif_info,
2266 ocs_scsi_sgl_t *sgl, uint32_t sgl_count, uint32_t wire_len,
2267 ocs_scsi_rsp_io_cb_t cb, void *arg, uint32_t flags)
2271 rc = ocs_scsi_send_io(OCS_HW_IO_INITIATOR_READ, node, io, lun, 0, cdb, cdb_len, dif_info, sgl, sgl_count,
2272 wire_len, 0, cb, arg, flags);
2278 * @ingroup scsi_api_base
2279 * @brief Initiate initiator write IO.
2282 * This call is made by an initiator-client to send a SCSI write command. The payload
2283 * for the command is given by a scatter-gather list @c sgl for @c sgl_count
2286 * Upon completion, the callback @c cb is invoked and passed request status. If the command
2287 * completed successfully, the callback is given SCSI response data.
2289 * @param node Pointer to the node.
2290 * @param io Pointer to IO context.
2291 * @param lun LUN value.
2292 * @param cdb Pointer to the CDB.
2293 * @param cdb_len Length of the CDB.
2294 * @param dif_info Pointer to the T10 DIF fields, or NULL if no DIF.
2295 * @param sgl Pointer to the scatter-gather list.
2296 * @param sgl_count Count of the scatter-gather list elements.
2297 * @param wire_len Length of the payload.
2298 * @param cb Completion callback.
2299 * @param arg Application-specified completion callback argument.
2301 * @return Returns 0 on success, or a negative error code value on failure.
2303 int32_t ocs_scsi_send_wr_io(ocs_node_t *node, ocs_io_t *io, uint64_t lun, void *cdb, uint32_t cdb_len,
2304 ocs_scsi_dif_info_t *dif_info,
2305 ocs_scsi_sgl_t *sgl, uint32_t sgl_count, uint32_t wire_len,
2306 ocs_scsi_rsp_io_cb_t cb, void *arg, uint32_t flags)
2310 rc = ocs_scsi_send_io(OCS_HW_IO_INITIATOR_WRITE, node, io, lun, 0, cdb, cdb_len, dif_info, sgl, sgl_count,
2311 wire_len, 0, cb, arg, flags);
2317 * @ingroup scsi_api_base
2318 * @brief Initiate initiator write IO.
2321 * This call is made by an initiator-client to send a SCSI write command. The payload
2322 * for the command is given by a scatter-gather list @c sgl for @c sgl_count
2325 * Upon completion, the callback @c cb is invoked and passed request status. If the command
2326 * completed successfully, the callback is given SCSI response data.
2328 * @param node Pointer to the node.
2329 * @param io Pointer to IO context.
2330 * @param lun LUN value.
2331 * @param cdb Pointer to the CDB.
2332 * @param cdb_len Length of the CDB.
2333 * @param dif_info Pointer to the T10 DIF fields, or NULL if no DIF.
2334 * @param sgl Pointer to the scatter-gather list.
2335 * @param sgl_count Count of the scatter-gather list elements.
2336 * @param wire_len Length of the payload.
2337 * @param first_burst Number of first burst bytes to send.
2338 * @param cb Completion callback.
2339 * @param arg Application-specified completion callback argument.
2341 * @return Returns 0 on success, or a negative error code value on failure.
2344 ocs_scsi_send_wr_io_first_burst(ocs_node_t *node, ocs_io_t *io, uint64_t lun, void *cdb, uint32_t cdb_len,
2345 ocs_scsi_dif_info_t *dif_info,
2346 ocs_scsi_sgl_t *sgl, uint32_t sgl_count, uint32_t wire_len, uint32_t first_burst,
2347 ocs_scsi_rsp_io_cb_t cb, void *arg, uint32_t flags)
2351 rc = ocs_scsi_send_io(OCS_HW_IO_INITIATOR_WRITE, node, io, lun, 0, cdb, cdb_len, dif_info, sgl, sgl_count,
2352 wire_len, 0, cb, arg, flags);
2358 * @ingroup scsi_api_base
2359 * @brief Initiate initiator SCSI command with no data.
2362 * This call is made by an initiator-client to send a SCSI command with no data.
2364 * Upon completion, the callback @c cb is invoked and passed request status. If the command
2365 * completed successfully, the callback is given SCSI response data.
2367 * @param node Pointer to the node.
2368 * @param io Pointer to the IO context.
2369 * @param lun LUN value.
2370 * @param cdb Pointer to the CDB.
2371 * @param cdb_len Length of the CDB.
2372 * @param cb Completion callback.
2373 * @param arg Application-specified completion callback argument.
2375 * @return Returns 0 on success, or a negative error code value on failure.
2377 int32_t ocs_scsi_send_nodata_io(ocs_node_t *node, ocs_io_t *io, uint64_t lun, void *cdb, uint32_t cdb_len,
2378 ocs_scsi_rsp_io_cb_t cb, void *arg, uint32_t flags)
2382 rc = ocs_scsi_send_io(OCS_HW_IO_INITIATOR_NODATA, node, io, lun, 0, cdb, cdb_len, NULL, NULL, 0, 0, 0, cb, arg, flags);
2387 * @ingroup scsi_api_base
2388 * @brief Initiate initiator task management operation.
2391 * This command is used to send a SCSI task management function command. If the command
2392 * requires it (QUERY_TASK_SET for example), a payload may be associated with the command.
2393 * If no payload is required, then @c sgl_count may be zero and @c sgl is ignored.
2395 * Upon completion @c cb is invoked with status and SCSI response data.
2397 * @param node Pointer to the node.
2398 * @param io Pointer to the IO context.
2399 * @param io_to_abort Pointer to the IO context to abort in the
2400 * case of OCS_SCSI_TMF_ABORT_TASK. Note: this can point to the
2401 * same the same ocs_io_t as @c io, provided that @c io does not
2402 * have any outstanding work requests.
2403 * @param lun LUN value.
2404 * @param tmf Task management command.
2405 * @param sgl Pointer to the scatter-gather list.
2406 * @param sgl_count Count of the scatter-gather list elements.
2407 * @param len Length of the payload.
2408 * @param cb Completion callback.
2409 * @param arg Application-specified completion callback argument.
2411 * @return Returns 0 on success, or a negative error code value on failure.
2414 ocs_scsi_send_tmf(ocs_node_t *node, ocs_io_t *io, ocs_io_t *io_to_abort, uint64_t lun, ocs_scsi_tmf_cmd_e tmf,
2415 ocs_scsi_sgl_t *sgl, uint32_t sgl_count, uint32_t len, ocs_scsi_rsp_io_cb_t cb, void *arg)
2420 if (tmf == OCS_SCSI_TMF_ABORT_TASK) {
2421 ocs_assert(io_to_abort, -1);
2423 /* take a reference on IO being aborted */
2424 if ((ocs_ref_get_unless_zero(&io_to_abort->ref) == 0)) {
2425 /* command no longer active */
2426 scsi_io_printf(io, "command no longer active\n");
2429 /* generic io fields have already been populated */
2431 /* abort-specific fields */
2432 io->io_type = OCS_IO_TYPE_ABORT;
2433 io->display_name = "abort_task";
2434 io->io_to_abort = io_to_abort;
2435 io->send_abts = TRUE;
2436 io->scsi_ini_cb = cb;
2437 io->scsi_ini_cb_arg = arg;
2439 /* now dispatch IO */
2440 rc = ocs_scsi_io_dispatch_abort(io, ocs_scsi_abort_io_cb);
2442 scsi_io_printf(io, "Failed to dispatch abort\n");
2443 ocs_ref_put(&io->ref); /* ocs_ref_get(): same function */
2446 io->display_name = "tmf";
2447 rc = ocs_scsi_send_io(OCS_HW_IO_INITIATOR_READ, node, io, lun, tmf, NULL, 0, NULL,
2448 sgl, sgl_count, len, 0, cb, arg, 0);
2455 * @ingroup scsi_api_base
2456 * @brief Send an FCP IO.
2459 * An FCP read/write IO command, with optional task management flags, is sent to @c node.
2461 * @param type HW IO type to send.
2462 * @param node Pointer to the node destination of the IO.
2463 * @param io Pointer to the IO context.
2464 * @param lun LUN value.
2465 * @param tmf Task management command.
2466 * @param cdb Pointer to the SCSI CDB.
2467 * @param cdb_len Length of the CDB, in bytes.
2468 * @param dif_info Pointer to the T10 DIF fields, or NULL if no DIF.
2469 * @param sgl Pointer to the scatter-gather list.
2470 * @param sgl_count Number of SGL entries in SGL.
2471 * @param wire_len Payload length, in bytes, of data on wire.
2472 * @param first_burst Number of first burst bytes to send.
2473 * @param cb Completion callback.
2474 * @param arg Application-specified completion callback argument.
2476 * @return Returns 0 on success, or a negative error code value on failure.
2479 /* tc: could elminiate LUN, as it's part of the IO structure */
2481 static int32_t ocs_scsi_send_io(ocs_hw_io_type_e type, ocs_node_t *node, ocs_io_t *io, uint64_t lun,
2482 ocs_scsi_tmf_cmd_e tmf, uint8_t *cdb, uint32_t cdb_len,
2483 ocs_scsi_dif_info_t *dif_info,
2484 ocs_scsi_sgl_t *sgl, uint32_t sgl_count, uint32_t wire_len, uint32_t first_burst,
2485 ocs_scsi_rsp_io_cb_t cb, void *arg, uint32_t flags)
2489 fcp_cmnd_iu_t *cmnd;
2490 uint32_t cmnd_bytes = 0;
2492 uint8_t tmf_flags = 0;
2494 ocs_assert(io->node, -1);
2495 ocs_assert(io->node == node, -1);
2500 io->sgl_count = sgl_count;
2502 /* Copy SGL if needed */
2503 if (sgl != io->sgl) {
2504 ocs_assert(sgl_count <= io->sgl_allocated, -1);
2505 ocs_memcpy(io->sgl, sgl, sizeof(*io->sgl) * sgl_count);
2508 /* save initiator and target task tags for debugging */
2509 io->tgt_task_tag = 0xffff;
2511 io->wire_len = wire_len;
2512 io->hio_type = type;
2514 if (OCS_LOG_ENABLE_SCSI_TRACE(ocs)) {
2516 ocs_textbuf_t txtbuf;
2519 ocs_textbuf_init(ocs, &txtbuf, buf, sizeof(buf));
2521 ocs_textbuf_printf(&txtbuf, "cdb%d: ", cdb_len);
2522 for (i = 0; i < cdb_len; i ++) {
2523 ocs_textbuf_printf(&txtbuf, "%02X%s", cdb[i], (i == (cdb_len-1)) ? "" : " ");
2525 scsi_io_printf(io, "%s len %d, %s\n", (io->hio_type == OCS_HW_IO_INITIATOR_READ) ? "read" :
2526 (io->hio_type == OCS_HW_IO_INITIATOR_WRITE) ? "write" : "", io->wire_len,
2527 ocs_textbuf_get_buffer(&txtbuf));
2530 ocs_assert(io->cmdbuf.virt, -1);
2532 cmnd = io->cmdbuf.virt;
2534 ocs_assert(sizeof(*cmnd) <= io->cmdbuf.size, -1);
2536 ocs_memset(cmnd, 0, sizeof(*cmnd));
2538 /* Default FCP_CMND IU doesn't include additional CDB bytes but does include FCP_DL */
2539 cmnd_bytes = sizeof(fcp_cmnd_iu_t) - sizeof(cmnd->fcp_cdb_and_dl) + sizeof(uint32_t);
2541 fcp_dl = (uint32_t*)(&(cmnd->fcp_cdb_and_dl));
2544 if (cdb_len <= 16) {
2545 ocs_memcpy(cmnd->fcp_cdb, cdb, cdb_len);
2547 uint32_t addl_cdb_bytes;
2549 ocs_memcpy(cmnd->fcp_cdb, cdb, 16);
2550 addl_cdb_bytes = cdb_len - 16;
2551 ocs_memcpy(cmnd->fcp_cdb_and_dl, &(cdb[16]), addl_cdb_bytes);
2552 /* additional_fcp_cdb_length is in words, not bytes */
2553 cmnd->additional_fcp_cdb_length = (addl_cdb_bytes + 3) / 4;
2554 fcp_dl += cmnd->additional_fcp_cdb_length;
2556 /* Round up additional CDB bytes */
2557 cmnd_bytes += (addl_cdb_bytes + 3) & ~0x3;
2561 be64enc(cmnd->fcp_lun, CAM_EXTLUN_BYTE_SWIZZLE(lun));
2563 if (node->fcp2device) {
2564 if(ocs_get_crn(node, &cmnd->command_reference_number,
2569 if (flags & OCS_SCSI_CMD_HEAD_OF_QUEUE)
2570 cmnd->task_attribute = FCP_TASK_ATTR_HEAD_OF_QUEUE;
2571 else if (flags & OCS_SCSI_CMD_ORDERED)
2572 cmnd->task_attribute = FCP_TASK_ATTR_ORDERED;
2573 else if (flags & OCS_SCSI_CMD_UNTAGGED)
2574 cmnd->task_attribute = FCP_TASK_ATTR_UNTAGGED;
2575 else if (flags & OCS_SCSI_CMD_ACA)
2576 cmnd->task_attribute = FCP_TASK_ATTR_ACA;
2578 cmnd->task_attribute = FCP_TASK_ATTR_SIMPLE;
2579 cmnd->command_priority = (flags & OCS_SCSI_PRIORITY_MASK) >>
2580 OCS_SCSI_PRIORITY_SHIFT;
2583 case OCS_SCSI_TMF_QUERY_TASK_SET:
2584 tmf_flags = FCP_QUERY_TASK_SET;
2586 case OCS_SCSI_TMF_ABORT_TASK_SET:
2587 tmf_flags = FCP_ABORT_TASK_SET;
2589 case OCS_SCSI_TMF_CLEAR_TASK_SET:
2590 tmf_flags = FCP_CLEAR_TASK_SET;
2592 case OCS_SCSI_TMF_QUERY_ASYNCHRONOUS_EVENT:
2593 tmf_flags = FCP_QUERY_ASYNCHRONOUS_EVENT;
2595 case OCS_SCSI_TMF_LOGICAL_UNIT_RESET:
2596 tmf_flags = FCP_LOGICAL_UNIT_RESET;
2598 case OCS_SCSI_TMF_CLEAR_ACA:
2599 tmf_flags = FCP_CLEAR_ACA;
2601 case OCS_SCSI_TMF_TARGET_RESET:
2602 tmf_flags = FCP_TARGET_RESET;
2607 cmnd->task_management_flags = tmf_flags;
2609 *fcp_dl = ocs_htobe32(io->wire_len);
2611 switch (io->hio_type) {
2612 case OCS_HW_IO_INITIATOR_READ:
2615 case OCS_HW_IO_INITIATOR_WRITE:
2618 case OCS_HW_IO_INITIATOR_NODATA:
2622 ocs_log_test(ocs, "bad IO type %d\n", io->hio_type);
2626 rc = ocs_scsi_convert_dif_info(ocs, dif_info, &io->hw_dif);
2631 io->scsi_ini_cb = cb;
2632 io->scsi_ini_cb_arg = arg;
2634 /* set command and response buffers in the iparam */
2635 io->iparam.fcp_ini.cmnd = &io->cmdbuf;
2636 io->iparam.fcp_ini.cmnd_size = cmnd_bytes;
2637 io->iparam.fcp_ini.rsp = &io->rspbuf;
2638 io->iparam.fcp_ini.flags = 0;
2639 io->iparam.fcp_ini.dif_oper = io->hw_dif.dif;
2640 io->iparam.fcp_ini.blk_size = io->hw_dif.blk_size;
2641 io->iparam.fcp_ini.timeout = io->timeout;
2642 io->iparam.fcp_ini.first_burst = first_burst;
2644 return ocs_scsi_io_dispatch(io, ocs_initiator_io_cb);
2648 * @ingroup scsi_api_base
2649 * @brief Callback for an aborted IO.
2652 * Callback function invoked upon completion of an IO abort request.
2654 * @param hio HW IO context.
2655 * @param rnode Remote node.
2656 * @param len Response length.
2657 * @param status Completion status.
2658 * @param ext_status Extended completion status.
2659 * @param arg Application-specific callback, usually IO context.
2661 * @return Returns 0 on success, or a negative error code value on failure.
2665 ocs_scsi_abort_io_cb(struct ocs_hw_io_s *hio, ocs_remote_node_t *rnode, uint32_t len, int32_t status,
2666 uint32_t ext_status, void *arg)
2670 ocs_scsi_io_status_e scsi_status = OCS_SCSI_STATUS_GOOD;
2673 ocs_assert(ocs_io_busy(io), -1);
2674 ocs_assert(io->ocs, -1);
2675 ocs_assert(io->io_to_abort, -1);
2678 ocs_log_debug(ocs, "status %d ext %d\n", status, ext_status);
2680 /* done with IO to abort */
2681 ocs_ref_put(&io->io_to_abort->ref); /* ocs_ref_get(): ocs_scsi_send_tmf() */
2683 ocs_scsi_io_free_ovfl(io);
2686 case SLI4_FC_WCQE_STATUS_SUCCESS:
2687 scsi_status = OCS_SCSI_STATUS_GOOD;
2689 case SLI4_FC_WCQE_STATUS_LOCAL_REJECT:
2690 if (ext_status == SLI4_FC_LOCAL_REJECT_ABORT_REQUESTED) {
2691 scsi_status = OCS_SCSI_STATUS_ABORTED;
2692 } else if (ext_status == SLI4_FC_LOCAL_REJECT_NO_XRI) {
2693 scsi_status = OCS_SCSI_STATUS_NO_IO;
2694 } else if (ext_status == SLI4_FC_LOCAL_REJECT_ABORT_IN_PROGRESS) {
2695 scsi_status = OCS_SCSI_STATUS_ABORT_IN_PROGRESS;
2697 ocs_log_test(ocs, "Unhandled local reject 0x%x/0x%x\n", status, ext_status);
2698 scsi_status = OCS_SCSI_STATUS_ERROR;
2702 scsi_status = OCS_SCSI_STATUS_ERROR;
2706 if (io->scsi_ini_cb) {
2707 (*io->scsi_ini_cb)(io, scsi_status, NULL, 0, io->scsi_ini_cb_arg);
2709 ocs_scsi_io_free(io);
2712 ocs_scsi_check_pending(ocs);
2717 * @ingroup scsi_api_base
2718 * @brief Return SCSI API integer valued property.
2721 * This function is called by a target-server or initiator-client to
2722 * retrieve an integer valued property.
2724 * @param ocs Pointer to the ocs.
2725 * @param prop Property value to return.
2727 * @return Returns a value, or 0 if invalid property was requested.
2730 ocs_scsi_get_property(ocs_t *ocs, ocs_scsi_property_e prop)
2732 ocs_xport_t *xport = ocs->xport;
2736 case OCS_SCSI_MAX_SGE:
2737 if (0 == ocs_hw_get(&ocs->hw, OCS_HW_MAX_SGE, &val)) {
2741 case OCS_SCSI_MAX_SGL:
2742 if (ocs->ctrlmask & OCS_CTRLMASK_TEST_CHAINED_SGLS) {
2744 * If chain SGL test-mode is enabled, the number of HW SGEs
2745 * has been limited; report back original max.
2747 return (OCS_FC_MAX_SGL);
2749 if (0 == ocs_hw_get(&ocs->hw, OCS_HW_N_SGL, &val)) {
2753 case OCS_SCSI_MAX_IOS:
2754 return ocs_io_pool_allocated(xport->io_pool);
2755 case OCS_SCSI_DIF_CAPABLE:
2756 if (0 == ocs_hw_get(&ocs->hw, OCS_HW_DIF_CAPABLE, &val)) {
2760 case OCS_SCSI_MAX_FIRST_BURST:
2762 case OCS_SCSI_DIF_MULTI_SEPARATE:
2763 if (ocs_hw_get(&ocs->hw, OCS_HW_DIF_MULTI_SEPARATE, &val) == 0) {
2767 case OCS_SCSI_ENABLE_TASK_SET_FULL:
2768 /* Return FALSE if we are send frame capable */
2769 if (ocs_hw_get(&ocs->hw, OCS_HW_SEND_FRAME_CAPABLE, &val) == 0) {
2777 ocs_log_debug(ocs, "invalid property request %d\n", prop);
2782 * @ingroup scsi_api_base
2783 * @brief Return a property pointer.
2786 * This function is called by a target-server or initiator-client to
2787 * retrieve a pointer to the requested property.
2789 * @param ocs Pointer to the ocs.
2790 * @param prop Property value to return.
2792 * @return Returns pointer to the requested property, or NULL otherwise.
2794 void *ocs_scsi_get_property_ptr(ocs_t *ocs, ocs_scsi_property_e prop)
2800 rc = ocs_hw_get_ptr(&ocs->hw, OCS_HW_WWN_NODE);
2803 rc = ocs_hw_get_ptr(&ocs->hw, OCS_HW_WWN_PORT);
2805 case OCS_SCSI_PORTNUM:
2806 rc = ocs_hw_get_ptr(&ocs->hw, OCS_HW_PORTNUM);
2808 case OCS_SCSI_BIOS_VERSION_STRING:
2809 rc = ocs_hw_get_ptr(&ocs->hw, OCS_HW_BIOS_VERSION_STRING);
2811 #if defined(OCS_ENABLE_VPD_SUPPORT)
2812 case OCS_SCSI_SERIALNUMBER:
2817 if (ocs_hw_get(&ocs->hw, OCS_HW_VPD_LEN, &vpd_len)) {
2818 ocs_log_test(ocs, "Can't get VPD length\n");
2819 rc = "\012sn-unknown";
2823 pvpd = ocs_hw_get_ptr(&ocs->hw, OCS_HW_VPD);
2825 rc = ocs_find_vpd(pvpd, vpd_len, "SN");
2829 ocs_strlen(rc) == 0) {
2830 /* Note: VPD is missing, using wwnn for serial number */
2831 scsi_log(ocs, "Note: VPD is missing, using wwnn for serial number\n");
2832 /* Use the last 32 bits of the WWN */
2833 if ((ocs == NULL) || (ocs->domain == NULL) || (ocs->domain->sport == NULL)) {
2834 rc = "\011(Unknown)";
2836 rc = &ocs->domain->sport->wwnn_str[8];
2841 case OCS_SCSI_PARTNUMBER:
2846 if (ocs_hw_get(&ocs->hw, OCS_HW_VPD_LEN, &vpd_len)) {
2847 ocs_log_test(ocs, "Can't get VPD length\n");
2848 rc = "\012pn-unknown";
2851 pvpd = ocs_hw_get_ptr(&ocs->hw, OCS_HW_VPD);
2853 rc = ocs_find_vpd(pvpd, vpd_len, "PN");
2855 rc = "\012pn-unknown";
2858 rc = "\012pn-unknown";
2868 ocs_log_debug(ocs, "invalid property request %d\n", prop);
2874 * @ingroup scsi_api_base
2875 * @brief Notify that delete initiator is complete.
2878 * Sent by the target-server to notify the base driver that the work started from
2879 * ocs_scsi_del_initiator() is now complete and that it is safe for the node to
2880 * release the rest of its resources.
2882 * @param node Pointer to the node.
2887 ocs_scsi_del_initiator_complete(ocs_node_t *node)
2889 /* Notify the node to resume */
2890 ocs_node_post_event(node, OCS_EVT_NODE_DEL_INI_COMPLETE, NULL);
2894 * @ingroup scsi_api_base
2895 * @brief Notify that delete target is complete.
2898 * Sent by the initiator-client to notify the base driver that the work started from
2899 * ocs_scsi_del_target() is now complete and that it is safe for the node to
2900 * release the rest of its resources.
2902 * @param node Pointer to the node.
2907 ocs_scsi_del_target_complete(ocs_node_t *node)
2909 /* Notify the node to resume */
2910 ocs_node_post_event(node, OCS_EVT_NODE_DEL_TGT_COMPLETE, NULL);
2914 * @brief Update transferred count
2917 * Updates io->transferred, as required when using first burst, when the amount
2918 * of first burst data processed differs from the amount of first burst
2921 * @param io Pointer to the io object.
2922 * @param transferred Number of bytes transferred out of first burst buffers.
2927 ocs_scsi_update_first_burst_transferred(ocs_io_t *io, uint32_t transferred)
2929 io->transferred = transferred;
2933 * @brief Register bounce callback for multi-threading.
2936 * Register the back end bounce function.
2938 * @param ocs Pointer to device object.
2939 * @param fctn Function pointer of bounce function.
2944 ocs_scsi_register_bounce(ocs_t *ocs, void(*fctn)(void(*fctn)(void *arg), void *arg, uint32_t s_id, uint32_t d_id,
2949 rc = ocs_hw_callback(&ocs->hw, OCS_HW_CB_BOUNCE, fctn, NULL);
2951 ocs_log_test(ocs, "ocs_hw_callback(OCS_HW_CB_BOUNCE) failed: %d\n", rc);