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