Emulex Logo
OneCoreā„¢ Storage SDK Release 11.2
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ocs_io.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2015, Emulex
3  * All rights reserved.
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  */
32 
33 /**
34  * @file
35  * OCS linux driver IO declarations
36  */
37 
38 #if !defined(__OCS_IO_H__)
39 #define __OCS_IO_H__
40 
41 #define io_error_log(io, fmt, ...) \
42  do { \
43  if (OCS_LOG_ENABLE_IO_ERRORS(io->ocs)) \
44  ocs_log_warn(io->ocs, fmt, ##__VA_ARGS__); \
45  } while (0)
46 
47 /**
48  * @brief FCP IO context
49  *
50  * This structure is used for transport and backend IO requests and responses.
51  */
52 
53 #define SCSI_CMD_BUF_LENGTH 48
54 #define SCSI_RSP_BUF_LENGTH sizeof(fcp_rsp_iu_t)
55 
56 /**
57  * @brief OCS IO types
58  */
59 typedef enum {
66 
67  OCS_IO_TYPE_MAX, /**< must be last */
69 
70 typedef struct els_loopback_io_evt_s {
74  ocs_sem_t wait_io_sem;
76 
77 struct ocs_io_s {
78 
79  ocs_t *ocs; /**< pointer back to ocs */
80  uint32_t instance_index; /**< unique instance index value */
81  const char *display_name; /**< display name */
82  ocs_node_t *node; /**< pointer to node */
83  ocs_list_link_t io_alloc_link; /**< (io_pool->io_free_list) free list link */
84  uint32_t init_task_tag; /**< initiator task tag (OX_ID) for back-end and SCSI logging */
85  uint32_t tgt_task_tag; /**< target task tag (RX_ID) - for back-end and SCSI logging */
86  uint32_t hw_tag; /**< HW layer unique IO id - for back-end and SCSI logging */
87  uint32_t tag; /**< unique IO identifier */
88  ocs_scsi_sgl_t *sgl; /**< SGL */
89  uint32_t sgl_allocated; /**< Number of allocated SGEs */
90  uint32_t sgl_count; /**< Number of SGEs in this SGL */
91  ocs_scsi_ini_io_t ini_io; /**< backend initiator private IO data */
92  ocs_scsi_tgt_io_t tgt_io; /**< backend target private IO data */
93  uint32_t exp_xfer_len; /**< expected data transfer length, based on FC or iSCSI header */
95 
96  /* Declarations private to HAL/SLI */
97  void *hal_priv; /**< HAL private context */
98 
99  /* Declarations private to FC Transport */
100  ocs_io_type_e io_type; /**< indicates what this ocs_io_t structure is used for */
101  ocs_ref_t ref; /**< refcount object */
102  void *dslab_item; /**< pointer back to dslab allocation object */
103  ocs_hal_io_t *hio; /**< HAL IO context */
104  size_t transferred; /**< Number of bytes transfered so far */
105  uint32_t auto_resp:1, /**< set if auto_trsp was set */
106  low_latency:1, /**< set if low latency request */
107  wq_steering:4, /**< selected WQ steering request */
108  wq_class:4; /**< selected WQ class if steering is class */
109  uint64_t xfer_req; /**< transfer size for current request */
110  ocs_scsi_rsp_io_cb_t scsi_ini_cb; /**< initiator callback function */
111  void *scsi_ini_cb_arg; /**< initiator callback function argument */
112  ocs_scsi_io_cb_t scsi_tgt_cb; /**< target callback function */
113  void *scsi_tgt_cb_arg; /**< target callback function argument */
114  ocs_scsi_io_cb_t abort_cb; /**< abort callback function */
115  void *abort_cb_arg; /**< abort callback function argument */
116  ocs_scsi_io_cb_t bls_cb; /**< BLS callback function */
117  void *bls_cb_arg; /**< BLS callback function argument */
118  ocs_scsi_tmf_cmd_e tmf_cmd; /**< TMF command being processed */
119  uint16_t abort_rx_id; /**< rx_id from the ABTS that initiated the command abort */
120 
121  uint32_t cmd_tgt:1, /**< True if this is a Target command */
122  send_abts:1, /**< when aborting, indicates ABTS is to be sent */
123  cmd_ini:1, /**< True if this is an Initiator command */
124  seq_init:1; /**< True if local node has sequence initiative */
125  ocs_hal_io_param_t iparam; /**< iparams for hal io send call */
126  ocs_hal_dif_info_t hal_dif; /**< HAL formatted DIF parameters */
127  ocs_scsi_dif_info_t scsi_dif_info; /**< DIF info saved for DIF error recovery */
128  ocs_hal_io_type_e hio_type; /**< HAL IO type */
129  uint64_t wire_len; /**< wire length */
130  void *hal_cb; /**< saved HAL callback */
131  ocs_list_link_t io_pending_link;/**< link list link pending */
132  ocs_list_link_t tmf_abort_link; /**< list to store list of IOs to which
133  abort ABORT_IO_NO_RESP evt needs to be posted */
134  bool tmf_abort; /**< True when io marked for tmf abort */
135 
136  ocs_dma_t ovfl_sgl; /**< Overflow SGL */
137 
138  /* for ELS requests/responses */
139  uint32_t els_pend:1, /**< True if ELS is pending */
140  els_active:1; /**< True if ELS is active */
141  ocs_dma_t els_req; /**< ELS request payload buffer */
142  ocs_dma_t els_rsp; /**< ELS response payload buffer */
143  ocs_sm_ctx_t els_sm; /**< EIO IO state machine context */
144  uint32_t els_evtdepth; /**< current event posting nesting depth */
145  uint32_t els_req_free:1; /**< this els is to be free'd */
146  uint32_t els_retries_remaining; /*<< Retries remaining */
147  void (*els_callback)(ocs_node_t *node, ocs_node_cb_t *cbdata, void *cbarg);
149  uint32_t els_timeout_sec; /**< timeout */
150 
151  ocs_timer_t delay_timer; /**< delay timer */
152 
153  /* for abort handling */
154  ocs_io_t *io_to_abort; /**< pointer to IO to abort */
155 
156  ocs_list_link_t link; /**< linked list link */
157  ocs_dma_t cmdbuf; /**< SCSI Command buffer, used for CDB (initiator) */
158  ocs_dma_t rspbuf; /**< SCSI Response buffer (i+t) */
159  uint32_t timeout; /**< Timeout value in seconds for this IO */
160  uint8_t cs_ctl; /**< CS_CTL priority for this IO */
161  uint8_t io_free; /**< Is io object in freelist > */
162  uint32_t app_id;
163  uint8_t trecv_wqe_timer; /**< Timeout value in seconds for treceive wqe> */
165 };
166 
167 /**
168  * @brief common IO callback argument
169  *
170  * Callback argument used as common I/O callback argument
171  */
172 
173 typedef struct {
174  int32_t status; /**< completion status */
175  int32_t ext_status; /**< extended completion status */
176  void *app; /**< application argument */
178 
179 /**
180  * @brief Test if IO object is busy
181  *
182  * Return True if IO object is busy. Busy is defined as the IO object not being on
183  * the free list
184  *
185  * @param io Pointer to IO object
186  *
187  * @return returns True if IO is busy
188  */
189 
190 static inline int32_t
191 ocs_io_busy(ocs_io_t *io)
192 {
193  return !(io->io_free);
194 }
195 
196 typedef struct ocs_io_pool_s ocs_io_pool_t;
197 
198 extern ocs_io_pool_t *ocs_io_pool_create(ocs_t *ocs, uint32_t num_io, uint32_t num_sgl);
199 extern int32_t ocs_io_pool_free(ocs_io_pool_t *io_pool);
200 extern uint32_t ocs_io_pool_allocated(ocs_io_pool_t *io_pool);
201 
202 extern ocs_io_t *ocs_io_pool_io_alloc(ocs_io_pool_t *io_pool);
203 extern void ocs_io_pool_io_free(ocs_io_pool_t *io_pool, ocs_io_t *io);
204 extern ocs_io_t *ocs_io_find_tgt_io(ocs_t *ocs, ocs_node_t *node, uint16_t ox_id, uint16_t rx_id);
205 extern ocs_io_t *ocs_io_find_init_els_io(ocs_t *ocs, ocs_node_t *node, uint16_t ox_id);
206 extern void ocs_ddump_io(ocs_textbuf_t *textbuf, ocs_io_t *io);
207 
208 #endif // __OCS_IO_H__
209 
210 /* vim: set noexpandtab textwidth=120: */
uint8_t io_free
Definition: ocs_io.h:161
ocs_scsi_io_cb_t bls_cb
Definition: ocs_io.h:116
target private IO structure
Definition: ocs_scsi_tgt.h:139
uint32_t cmd_ini
Definition: ocs_io.h:121
static int32_t ocs_io_busy(ocs_io_t *io)
Test if IO object is busy.
Definition: ocs_io.h:191
ocs_scsi_tmf_cmd_e
Definition: ocs_scsi.h:138
uint32_t cmd_tgt
Definition: ocs_io.h:121
ocs_list_t ocs_list_link_t
Definition: ocs_list.h:84
void * loopback_rx_data
Definition: ocs_io.h:72
ocs_io_pool_t * ocs_io_pool_create(ocs_t *ocs, uint32_t num_io, uint32_t num_sgl)
Create a pool of IO objects.
Definition: ocs_io.c:101
ocs_io_t * ocs_io_pool_io_alloc(ocs_io_pool_t *io_pool)
Allocate an object used to track an IO.
Definition: ocs_io.c:239
int32_t ext_status
Definition: ocs_io.h:175
uint32_t els_evtdepth
Definition: ocs_io.h:144
uint32_t seq_init
Definition: ocs_io.h:121
int32_t status
Definition: ocs_io.h:174
ocs_list_link_t tmf_abort_link
Definition: ocs_io.h:132
common IO callback argument
Definition: ocs_io.h:173
void * hal_priv
Definition: ocs_io.h:97
uint8_t cs_ctl
Definition: ocs_io.h:160
uint32_t sgl_allocated
Definition: ocs_io.h:89
ocs_scsi_io_cb_t abort_cb
Definition: ocs_io.h:114
T10 DIF information passed to the transport.
Definition: ocs_scsi.h:229
ocs_hal_io_param_t iparam
Definition: ocs_io.h:125
ocs_dma_t ovfl_sgl
Definition: ocs_io.h:136
T10 DIF information passed to the transport.
Definition: ocs_hal.h:400
ocs_io_type_e
OCS IO types.
Definition: ocs_io.h:59
void * bls_cb_arg
Definition: ocs_io.h:117
uint32_t els_retries_remaining
Definition: ocs_io.h:146
uint16_t abort_rx_id
Definition: ocs_io.h:119
ocs_scsi_io_cb_t scsi_tgt_cb
Definition: ocs_io.h:112
uint32_t app_id
Definition: ocs_io.h:162
ocs_list_link_t link
Definition: ocs_io.h:156
uint32_t els_req_free
Definition: ocs_io.h:145
const char * display_name
Definition: ocs_io.h:81
els_loopback_io_evt_t loopback_evt_data
Definition: ocs_io.h:164
uint32_t instance_index
Definition: ocs_io.h:80
ocs_hal_dif_info_t hal_dif
Definition: ocs_io.h:126
uint32_t loopback_rx_data_len
Definition: ocs_io.h:73
generic scatter-gather list structure
Definition: ocs_scsi.h:218
uint32_t sgl_count
Definition: ocs_io.h:90
ocs_io_t * ocs_io_find_init_els_io(ocs_t *ocs, ocs_node_t *node, uint16_t ox_id)
Find an els I/O given it&#39;s node and ox_id.
Definition: ocs_io.c:339
int32_t(* ocs_scsi_rsp_io_cb_t)(ocs_io_t *io, ocs_scsi_io_status_e status, ocs_scsi_cmd_resp_t *rsp, uint32_t flags, void *arg)
Definition: ocs_scsi.h:129
uint32_t exp_xfer_len
Definition: ocs_io.h:93
uint8_t trecv_wqe_timer
Definition: ocs_io.h:163
ocs_list_link_t io_pending_link
Definition: ocs_io.h:131
ocs_sem_t wait_io_sem
Definition: ocs_io.h:74
void * hal_cb
Definition: ocs_io.h:130
uint32_t tag
Definition: ocs_io.h:87
ocs_node_t * node
Definition: ocs_io.h:82
ocs_hal_io_type_e
Definition: ocs_hal.h:426
ocs_dma_t cmdbuf
Definition: ocs_io.h:157
uint32_t els_pend
Definition: ocs_io.h:139
void ocs_io_pool_io_free(ocs_io_pool_t *io_pool, ocs_io_t *io)
Free an object used to track an IO.
Definition: ocs_io.c:283
uint32_t ocs_io_pool_allocated(ocs_io_pool_t *io_pool)
Definition: ocs_io.c:225
void * scsi_tgt_cb_arg
Definition: ocs_io.h:113
ocs_scsi_rsp_io_cb_t scsi_ini_cb
Definition: ocs_io.h:110
ocs_timer_t delay_timer
Definition: ocs_io.h:151
ocs_scsi_ini_io_t ini_io
Definition: ocs_io.h:91
ocs_dma_t rspbuf
Definition: ocs_io.h:158
bool is_loopback_frame
Definition: ocs_io.h:71
uint64_t xfer_req
Definition: ocs_io.h:109
ocs_list_link_t io_alloc_link
Definition: ocs_io.h:83
uint64_t wire_len
Definition: ocs_io.h:129
size_t transferred
Definition: ocs_io.h:104
ocs_hal_io_type_e hio_type
Definition: ocs_io.h:128
ocs_scsi_tmf_cmd_e tmf_cmd
Definition: ocs_io.h:118
ocs_hal_io_t * hio
Definition: ocs_io.h:103
int32_t(* ocs_scsi_io_cb_t)(ocs_io_t *io, ocs_scsi_io_status_e status, uint32_t flags, void *arg)
Definition: ocs_scsi.h:125
bool tmf_abort
Definition: ocs_io.h:134
ocs_sm_ctx_t els_sm
Definition: ocs_io.h:143
ocs_scsi_tgt_io_t tgt_io
Definition: ocs_io.h:92
ocs_scsi_sgl_t * sgl
Definition: ocs_io.h:88
ocs_dma_t els_req
Definition: ocs_io.h:141
void * abort_cb_arg
Definition: ocs_io.h:115
ocs_dma_t els_rsp
Definition: ocs_io.h:142
void * scsi_ini_cb_arg
Definition: ocs_io.h:111
uint32_t els_timeout_sec
Definition: ocs_io.h:149
ocs_ref_t ref
Definition: ocs_io.h:101
void ocs_ddump_io(ocs_textbuf_t *textbuf, ocs_io_t *io)
Generate IO context ddump data.
Definition: ocs_io.c:385
void * app
Definition: ocs_io.h:176
uint32_t hw_tag
Definition: ocs_io.h:86
uint32_t tgt_task_tag
Definition: ocs_io.h:85
uint32_t wq_class
Definition: ocs_io.h:105
ocs_scsi_dif_info_t scsi_dif_info
Definition: ocs_io.h:127
void * els_callback_arg
Definition: ocs_io.h:148
int32_t ocs_io_pool_free(ocs_io_pool_t *io_pool)
Free IO objects pool.
Definition: ocs_io.c:185
void * dslab_item
Definition: ocs_io.h:102
uint32_t send_abts
Definition: ocs_io.h:121
ocs_t * ocs
Definition: ocs_io.c:64
uint32_t wq_steering
Definition: ocs_io.h:105
IO pool.
Definition: ocs_io.c:63
ocs_io_type_e io_type
Definition: ocs_io.h:100
ocs_io_t * ocs_io_find_tgt_io(ocs_t *ocs, ocs_node_t *node, uint16_t ox_id, uint16_t rx_id)
Find an I/O given it&#39;s node and ox_id.
Definition: ocs_io.c:316
ocs_io_t * io_to_abort
Definition: ocs_io.h:154
void(* els_callback)(ocs_node_t *node, ocs_node_cb_t *cbdata, void *cbarg)
Definition: ocs_io.h:147
uint32_t auto_resp
Definition: ocs_io.h:105
uint32_t init_task_tag
Definition: ocs_io.h:84
uint32_t low_latency
Definition: ocs_io.h:105
ocs_mgmt_functions_t * mgmt_functions
Definition: ocs_io.h:94
ocs_t * ocs
Definition: ocs_io.h:79
uint32_t timeout
Definition: ocs_io.h:159
uint32_t els_active
Definition: ocs_io.h:139