xref: /freebsd/sys/dev/ocs_fc/ocs_io.h (revision aa1a8ff2d6dbc51ef058f46f3db5a8bb77967145)
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 
32 /**
33  * @file
34  * OCS linux driver IO declarations
35  */
36 
37 #if !defined(__OCS_IO_H__)
38 #define __OCS_IO_H__
39 
40 #define io_error_log(io, fmt, ...)  \
41 	do { \
42 		if (OCS_LOG_ENABLE_IO_ERRORS(io->ocs)) \
43 			ocs_log_warn(io->ocs, fmt, ##__VA_ARGS__); \
44 	} while (0)
45 
46 /**
47  * @brief FCP IO context
48  *
49  * This structure is used for transport and backend IO requests and responses.
50  */
51 
52 #define SCSI_CMD_BUF_LENGTH		48
53 #define SCSI_RSP_BUF_LENGTH		sizeof(fcp_rsp_iu_t)
54 
55 /**
56  * @brief OCS IO types
57  */
58 typedef enum {
59 	OCS_IO_TYPE_IO = 0,
60 	OCS_IO_TYPE_ELS,
61 	OCS_IO_TYPE_CT,
62 	OCS_IO_TYPE_CT_RESP,
63 	OCS_IO_TYPE_BLS_RESP,
64 	OCS_IO_TYPE_ABORT,
65 
66 	OCS_IO_TYPE_MAX,		/**< must be last */
67 } ocs_io_type_e;
68 
69 struct ocs_io_s {
70 	ocs_t *ocs;			/**< pointer back to ocs */
71 	uint32_t instance_index;	/**< unique instance index value */
72 	const char *display_name;	/**< display name */
73 	ocs_node_t *node;		/**< pointer to node */
74 	ocs_list_link_t io_alloc_link;	/**< (io_pool->io_free_list) free list link */
75 	uint32_t init_task_tag;		/**< initiator task tag (OX_ID) for back-end and SCSI logging */
76 	uint32_t tgt_task_tag;		/**< target task tag (RX_ID) - for back-end and SCSI logging */
77 	uint32_t hw_tag;		/**< HW layer unique IO id - for back-end and SCSI logging */
78 	uint32_t tag;			/**< unique IO identifier */
79 	ocs_scsi_sgl_t *sgl;		/**< SGL */
80 	uint32_t sgl_allocated;		/**< Number of allocated SGEs */
81 	uint32_t sgl_count;		/**< Number of SGEs in this SGL */
82 	ocs_scsi_ini_io_t ini_io;	/**< backend initiator private IO data */
83 	ocs_scsi_tgt_io_t tgt_io;	/**< backend target private IO data */
84 	uint32_t exp_xfer_len;		/**< expected data transfer length, based on FC or iSCSI header */
85 	ocs_mgmt_functions_t *mgmt_functions;
86 
87 	/* Declarations private to HW/SLI */
88 	void *hw_priv;			/**< HW private context */
89 
90 	/* Declarations private to FC Transport */
91 	ocs_io_type_e io_type;		/**< indicates what this ocs_io_t structure is used for */
92 	ocs_ref_t ref;			/**< refcount object */
93 	void *dslab_item;		/**< pointer back to dslab allocation object */
94 	ocs_hw_io_t *hio;		/**< HW IO context */
95 	size_t transferred;		/**< Number of bytes transferred so far */
96 	uint32_t auto_resp:1,		/**< set if auto_trsp was set */
97 		 low_latency:1,		/**< set if low latency request */
98 		 wq_steering:4,		/**< selected WQ steering request */
99 		 wq_class:4;		/**< selected WQ class if steering is class */
100 	uint32_t xfer_req;		/**< transfer size for current request */
101 	ocs_scsi_rsp_io_cb_t scsi_ini_cb; /**< initiator callback function */
102 	void *scsi_ini_cb_arg;		/**< initiator callback function argument */
103 	ocs_scsi_io_cb_t scsi_tgt_cb;	/**< target callback function */
104 	void *scsi_tgt_cb_arg;		/**< target callback function argument */
105 	ocs_scsi_io_cb_t abort_cb;	/**< abort callback function */
106 	void *abort_cb_arg;		/**< abort callback function argument */
107 	ocs_scsi_io_cb_t bls_cb;	/**< BLS callback function */
108 	void *bls_cb_arg;		/**< BLS callback function argument */
109 	ocs_scsi_tmf_cmd_e tmf_cmd;	/**< TMF command being processed */
110 	uint16_t abort_rx_id;		/**< rx_id from the ABTS that initiated the command abort */
111 
112 	uint32_t cmd_tgt:1,		/**< True if this is a Target command */
113 		 send_abts:1,		/**< when aborting, indicates ABTS is to be sent */
114 		 cmd_ini:1,		/**< True if this is an Initiator command */
115 		 seq_init:1;		/**< True if local node has sequence initiative */
116 	ocs_hw_io_param_t iparam;	/**< iparams for hw io send call */
117 	ocs_hw_dif_info_t hw_dif;	/**< HW formatted DIF parameters */
118 	ocs_scsi_dif_info_t scsi_dif_info;	/**< DIF info saved for DIF error recovery */
119 	ocs_hw_io_type_e hio_type;	/**< HW IO type */
120 	uint32_t wire_len;		/**< wire length */
121 	void *hw_cb;			/**< saved HW callback */
122 	ocs_list_link_t io_pending_link;/**< link list link pending */
123 
124 	ocs_dma_t ovfl_sgl;		/**< Overflow SGL */
125 
126 	/* for ELS requests/responses */
127 	uint32_t els_pend:1,		/**< True if ELS is pending */
128 		els_active:1;		/**< True if ELS is active */
129 	ocs_dma_t els_req;		/**< ELS request payload buffer */
130 	ocs_dma_t els_rsp;		/**< ELS response payload buffer */
131 	ocs_sm_ctx_t els_sm;		/**< EIO IO state machine context */
132 	uint32_t els_evtdepth;		/**< current event posting nesting depth */
133 	uint32_t els_req_free:1;	/**< this els is to be free'd */
134 	uint32_t els_retries_remaining;	/*<< Retries remaining */
135 	void (*els_callback)(ocs_node_t *node, ocs_node_cb_t *cbdata, void *cbarg);
136 	void *els_callback_arg;
137 	uint32_t els_timeout_sec;	/**< timeout */
138 
139 	ocs_timer_t delay_timer;	/**< delay timer */
140 
141 	/* for abort handling */
142 	ocs_io_t *io_to_abort;		/**< pointer to IO to abort */
143 
144 	ocs_list_link_t link;		/**< linked list link */
145 	ocs_dma_t cmdbuf;		/**< SCSI Command buffer, used for CDB (initiator) */
146 	ocs_dma_t rspbuf;		/**< SCSI Response buffer (i+t) */
147 	uint32_t  timeout;		/**< Timeout value in seconds for this IO */
148 	uint8_t   cs_ctl;		/**< CS_CTL priority for this IO */
149 	uint8_t	  io_free;		/**< Is io object in freelist > */
150 	uint32_t  app_id;
151 };
152 
153 /**
154  * @brief common IO callback argument
155  *
156  * Callback argument used as common I/O callback argument
157  */
158 
159 typedef struct {
160 	int32_t status;				/**< completion status */
161 	int32_t ext_status;			/**< extended completion status */
162 	void *app;				/**< application argument */
163 } ocs_io_cb_arg_t;
164 
165 /**
166  * @brief Test if IO object is busy
167  *
168  * Return True if IO object is busy.   Busy is defined as the IO object not being on
169  * the free list
170  *
171  * @param io Pointer to IO object
172  *
173  * @return returns True if IO is busy
174  */
175 
176 static inline int32_t
177 ocs_io_busy(ocs_io_t *io)
178 {
179 	return !(io->io_free);
180 }
181 
182 typedef struct ocs_io_pool_s ocs_io_pool_t;
183 
184 extern ocs_io_pool_t *ocs_io_pool_create(ocs_t *ocs, uint32_t num_io, uint32_t num_sgl);
185 extern int32_t ocs_io_pool_free(ocs_io_pool_t *io_pool);
186 extern uint32_t ocs_io_pool_allocated(ocs_io_pool_t *io_pool);
187 
188 extern ocs_io_t *ocs_io_pool_io_alloc(ocs_io_pool_t *io_pool);
189 extern void ocs_io_pool_io_free(ocs_io_pool_t *io_pool, ocs_io_t *io);
190 extern ocs_io_t *ocs_io_find_tgt_io(ocs_t *ocs, ocs_node_t *node, uint16_t ox_id, uint16_t rx_id);
191 extern void ocs_ddump_io(ocs_textbuf_t *textbuf, ocs_io_t *io);
192 
193 #endif
194