1 /*- 2 * Copyright (c) 2017 Broadcom. All rights reserved. 3 * The term "Broadcom" refers to Broadcom Limited and/or its subsidiaries. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, 9 * this list of conditions and the following disclaimer. 10 * 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. 14 * 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. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 * 31 * $FreeBSD$ 32 */ 33 34 /** 35 * @file 36 * OCS linux driver IO declarations 37 */ 38 39 #if !defined(__OCS_IO_H__) 40 #define __OCS_IO_H__ 41 42 #define io_error_log(io, fmt, ...) \ 43 do { \ 44 if (OCS_LOG_ENABLE_IO_ERRORS(io->ocs)) \ 45 ocs_log_warn(io->ocs, fmt, ##__VA_ARGS__); \ 46 } while (0) 47 48 /** 49 * @brief FCP IO context 50 * 51 * This structure is used for transport and backend IO requests and responses. 52 */ 53 54 #define SCSI_CMD_BUF_LENGTH 48 55 #define SCSI_RSP_BUF_LENGTH sizeof(fcp_rsp_iu_t) 56 57 /** 58 * @brief OCS IO types 59 */ 60 typedef enum { 61 OCS_IO_TYPE_IO = 0, 62 OCS_IO_TYPE_ELS, 63 OCS_IO_TYPE_CT, 64 OCS_IO_TYPE_CT_RESP, 65 OCS_IO_TYPE_BLS_RESP, 66 OCS_IO_TYPE_ABORT, 67 68 OCS_IO_TYPE_MAX, /**< must be last */ 69 } ocs_io_type_e; 70 71 struct ocs_io_s { 72 73 ocs_t *ocs; /**< pointer back to ocs */ 74 uint32_t instance_index; /**< unique instance index value */ 75 const char *display_name; /**< display name */ 76 ocs_node_t *node; /**< pointer to node */ 77 ocs_list_link_t io_alloc_link; /**< (io_pool->io_free_list) free list link */ 78 uint32_t init_task_tag; /**< initiator task tag (OX_ID) for back-end and SCSI logging */ 79 uint32_t tgt_task_tag; /**< target task tag (RX_ID) - for back-end and SCSI logging */ 80 uint32_t hw_tag; /**< HW layer unique IO id - for back-end and SCSI logging */ 81 uint32_t tag; /**< unique IO identifier */ 82 ocs_scsi_sgl_t *sgl; /**< SGL */ 83 uint32_t sgl_allocated; /**< Number of allocated SGEs */ 84 uint32_t sgl_count; /**< Number of SGEs in this SGL */ 85 ocs_scsi_ini_io_t ini_io; /**< backend initiator private IO data */ 86 ocs_scsi_tgt_io_t tgt_io; /**< backend target private IO data */ 87 uint32_t exp_xfer_len; /**< expected data transfer length, based on FC or iSCSI header */ 88 ocs_mgmt_functions_t *mgmt_functions; 89 90 /* Declarations private to HW/SLI */ 91 void *hw_priv; /**< HW private context */ 92 93 /* Declarations private to FC Transport */ 94 ocs_io_type_e io_type; /**< indicates what this ocs_io_t structure is used for */ 95 ocs_ref_t ref; /**< refcount object */ 96 void *dslab_item; /**< pointer back to dslab allocation object */ 97 ocs_hw_io_t *hio; /**< HW IO context */ 98 size_t transferred; /**< Number of bytes transferred so far */ 99 uint32_t auto_resp:1, /**< set if auto_trsp was set */ 100 low_latency:1, /**< set if low latency request */ 101 wq_steering:4, /**< selected WQ steering request */ 102 wq_class:4; /**< selected WQ class if steering is class */ 103 uint32_t xfer_req; /**< transfer size for current request */ 104 ocs_scsi_rsp_io_cb_t scsi_ini_cb; /**< initiator callback function */ 105 void *scsi_ini_cb_arg; /**< initiator callback function argument */ 106 ocs_scsi_io_cb_t scsi_tgt_cb; /**< target callback function */ 107 void *scsi_tgt_cb_arg; /**< target callback function argument */ 108 ocs_scsi_io_cb_t abort_cb; /**< abort callback function */ 109 void *abort_cb_arg; /**< abort callback function argument */ 110 ocs_scsi_io_cb_t bls_cb; /**< BLS callback function */ 111 void *bls_cb_arg; /**< BLS callback function argument */ 112 ocs_scsi_tmf_cmd_e tmf_cmd; /**< TMF command being processed */ 113 uint16_t abort_rx_id; /**< rx_id from the ABTS that initiated the command abort */ 114 115 uint32_t cmd_tgt:1, /**< True if this is a Target command */ 116 send_abts:1, /**< when aborting, indicates ABTS is to be sent */ 117 cmd_ini:1, /**< True if this is an Initiator command */ 118 seq_init:1; /**< True if local node has sequence initiative */ 119 ocs_hw_io_param_t iparam; /**< iparams for hw io send call */ 120 ocs_hw_dif_info_t hw_dif; /**< HW formatted DIF parameters */ 121 ocs_scsi_dif_info_t scsi_dif_info; /**< DIF info saved for DIF error recovery */ 122 ocs_hw_io_type_e hio_type; /**< HW IO type */ 123 uint32_t wire_len; /**< wire length */ 124 void *hw_cb; /**< saved HW callback */ 125 ocs_list_link_t io_pending_link;/**< link list link pending */ 126 127 ocs_dma_t ovfl_sgl; /**< Overflow SGL */ 128 129 /* for ELS requests/responses */ 130 uint32_t els_pend:1, /**< True if ELS is pending */ 131 els_active:1; /**< True if ELS is active */ 132 ocs_dma_t els_req; /**< ELS request payload buffer */ 133 ocs_dma_t els_rsp; /**< ELS response payload buffer */ 134 ocs_sm_ctx_t els_sm; /**< EIO IO state machine context */ 135 uint32_t els_evtdepth; /**< current event posting nesting depth */ 136 uint32_t els_req_free:1; /**< this els is to be free'd */ 137 uint32_t els_retries_remaining; /*<< Retries remaining */ 138 void (*els_callback)(ocs_node_t *node, ocs_node_cb_t *cbdata, void *cbarg); 139 void *els_callback_arg; 140 uint32_t els_timeout_sec; /**< timeout */ 141 142 ocs_timer_t delay_timer; /**< delay timer */ 143 144 /* for abort handling */ 145 ocs_io_t *io_to_abort; /**< pointer to IO to abort */ 146 147 ocs_list_link_t link; /**< linked list link */ 148 ocs_dma_t cmdbuf; /**< SCSI Command buffer, used for CDB (initiator) */ 149 ocs_dma_t rspbuf; /**< SCSI Response buffer (i+t) */ 150 uint32_t timeout; /**< Timeout value in seconds for this IO */ 151 uint8_t cs_ctl; /**< CS_CTL priority for this IO */ 152 uint8_t io_free; /**< Is io object in freelist > */ 153 uint32_t app_id; 154 }; 155 156 /** 157 * @brief common IO callback argument 158 * 159 * Callback argument used as common I/O callback argument 160 */ 161 162 typedef struct { 163 int32_t status; /**< completion status */ 164 int32_t ext_status; /**< extended completion status */ 165 void *app; /**< application argument */ 166 } ocs_io_cb_arg_t; 167 168 /** 169 * @brief Test if IO object is busy 170 * 171 * Return True if IO object is busy. Busy is defined as the IO object not being on 172 * the free list 173 * 174 * @param io Pointer to IO object 175 * 176 * @return returns True if IO is busy 177 */ 178 179 static inline int32_t 180 ocs_io_busy(ocs_io_t *io) 181 { 182 return !(io->io_free); 183 } 184 185 typedef struct ocs_io_pool_s ocs_io_pool_t; 186 187 extern ocs_io_pool_t *ocs_io_pool_create(ocs_t *ocs, uint32_t num_io, uint32_t num_sgl); 188 extern int32_t ocs_io_pool_free(ocs_io_pool_t *io_pool); 189 extern uint32_t ocs_io_pool_allocated(ocs_io_pool_t *io_pool); 190 191 extern ocs_io_t *ocs_io_pool_io_alloc(ocs_io_pool_t *io_pool); 192 extern void ocs_io_pool_io_free(ocs_io_pool_t *io_pool, ocs_io_t *io); 193 extern ocs_io_t *ocs_io_find_tgt_io(ocs_t *ocs, ocs_node_t *node, uint16_t ox_id, uint16_t rx_id); 194 extern void ocs_ddump_io(ocs_textbuf_t *textbuf, ocs_io_t *io); 195 196 #endif 197