3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright (c) 2013 by Delphix. All rights reserved.
24 */
25 #ifndef _STMF_IMPL_H
26 #define _STMF_IMPL_H
27
28 #include <sys/stmf_defines.h>
29 #include <sys/stmf_ioctl.h>
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34
35 typedef uint32_t stmf_event_handle_t;
36 #define STMF_MAX_NUM_EVENTS (sizeof (stmf_event_handle_t) * 8)
37 #define STMF_EVENT_ADD(h, e) (atomic_or_32(&(h), \
38 ((uint32_t)1) << (e)))
39 #define STMF_EVENT_REMOVE(h, e) (atomic_and_32(&(h), \
40 ~(((uint32_t)1) << (e))))
41 #define STMF_EVENT_ENABLED(h, e) (((h) & ((uint32_t)1) << (e)) != 0)
42 #define STMF_EVENT_CLEAR_ALL(h) ((h) = 0)
72 stmf_lu_t *ilu_lu;
73 uint32_t ilu_alloc_size;
74 uint32_t ilu_flags;
75 uint32_t ilu_ref_cnt;
76 uint8_t ilu_state;
77 uint8_t ilu_prev_state;
78 uint8_t ilu_access;
79 uint8_t ilu_alua;
80 stmf_event_handle_t ilu_event_hdl;
81 struct stmf_i_lu *ilu_next;
82 struct stmf_i_lu *ilu_prev;
83 char *ilu_alias;
84 char ilu_ascii_hex_guid[STMF_GUID_INPUT + 1];
85 kmutex_t ilu_task_lock;
86 uint32_t ilu_task_cntr1;
87 uint32_t ilu_task_cntr2;
88 uint32_t *ilu_cur_task_cntr;
89 uint32_t ilu_ntasks; /* # of tasks in the ilu_task list */
90 uint32_t ilu_ntasks_free; /* # of tasks that are free */
91 uint32_t ilu_ntasks_min_free; /* # minimal free tasks */
92 uint32_t rsvd1;
93 uint32_t ilu_proxy_registered;
94 uint64_t ilu_reg_msgid;
95 struct stmf_i_scsi_task *ilu_tasks;
96 struct stmf_i_scsi_task *ilu_free_tasks;
97 struct stmf_itl_data *ilu_itl_list;
98 kstat_t *ilu_kstat_info;
99 kstat_t *ilu_kstat_io;
100 kmutex_t ilu_kstat_lock;
101 kcondvar_t ilu_offline_pending_cv;
102
103 /* point to the luid entry in stmf_state.stmf_luid_list */
104 void *ilu_luid;
105 } stmf_i_lu_t;
106
107 /*
108 * ilu_flags
109 */
110 #define ILU_STALL_DEREGISTER 0x0001
111 #define ILU_RESET_ACTIVE 0x0002
112
147 kstat_t *ilport_kstat_info;
148 kstat_t *ilport_kstat_io;
149 kmutex_t ilport_kstat_lock;
150 char ilport_kstat_tgt_name[STMF_TGT_NAME_LEN];
151 /* which target group this port belongs to in stmf_state.stmf_tg_list */
152 void *ilport_tg;
153 id_t ilport_instance;
154 /* XXX Need something to track all the remote ports also */
155 } stmf_i_local_port_t;
156
157 #define STMF_AVG_ONLINE_INTERVAL (30 * drv_usectohz(1000000))
158
159 #define MAX_IRPORT 0x10000
160
161 typedef struct stmf_i_remote_port {
162 struct scsi_devid_desc *irport_id;
163 kmutex_t irport_mutex;
164 int irport_refcnt;
165 id_t irport_instance;
166 avl_node_t irport_ln;
167 } stmf_i_remote_port_t;
168
169 /*
170 * ilport flags
171 */
172 #define ILPORT_FORCED_OFFLINE 0x01
173 #define ILPORT_SS_GOT_INITIAL_LUNS 0x02
174
175 typedef struct stmf_i_scsi_session {
176 stmf_scsi_session_t *iss_ss;
177 uint32_t iss_alloc_size;
178 uint32_t iss_flags;
179 stmf_i_remote_port_t *iss_irport;
180 struct stmf_i_scsi_session *iss_next;
181 /*
182 * Ideally we should maintain 2 maps. One would indicate a new map
183 * which will become available only upon receipt of a REPORT LUN
184 * cmd.
185 */
186 struct stmf_lun_map *iss_sm;
220 TE_TASK_LPORT_ABORTED,
221 TE_TASK_LU_ABORTED,
222 TE_PROCESS_CMD
223 } task_audit_event_t;
224
225 #define CMD_OR_IOF_NA 0xffffffff
226
227 typedef struct stmf_task_audit_rec {
228 task_audit_event_t ta_event;
229 uint32_t ta_cmd_or_iof;
230 uint32_t ta_itask_flags;
231 stmf_data_buf_t *ta_dbuf;
232 timespec_t ta_timestamp;
233 } stmf_task_audit_rec_t;
234
235 struct stmf_worker;
236 typedef struct stmf_i_scsi_task {
237 scsi_task_t *itask_task;
238 uint32_t itask_alloc_size;
239 uint32_t itask_flags;
240 uint64_t itask_proxy_msg_id;
241 stmf_data_buf_t *itask_proxy_dbuf;
242 struct stmf_worker *itask_worker;
243 uint32_t *itask_ilu_task_cntr;
244 struct stmf_i_scsi_task *itask_worker_next;
245 struct stmf_i_scsi_task *itask_lu_next;
246 struct stmf_i_scsi_task *itask_lu_prev;
247 struct stmf_i_scsi_task *itask_lu_free_next;
248 struct stmf_i_scsi_task *itask_abort_next;
249 struct stmf_itl_data *itask_itl_datap;
250 clock_t itask_start_time; /* abort and normal */
251 /* For now we only support 4 parallel buffers. Should be enough. */
252 stmf_data_buf_t *itask_dbufs[4];
253 clock_t itask_poll_timeout;
254 uint8_t itask_cmd_stack[ITASK_MAX_NCMDS];
255 uint8_t itask_ncmds;
256 uint8_t itask_allocated_buf_map;
257 uint16_t itask_cdb_buf_size;
258
259 /* Task profile data */
260 hrtime_t itask_start_timestamp;
261 hrtime_t itask_done_timestamp;
262 hrtime_t itask_waitq_enter_timestamp;
263 hrtime_t itask_waitq_time;
264 hrtime_t itask_lu_read_time;
265 hrtime_t itask_lu_write_time;
266 hrtime_t itask_lport_read_time;
267 hrtime_t itask_lport_write_time;
268 uint64_t itask_read_xfer;
269 uint64_t itask_write_xfer;
270 kmutex_t itask_audit_mutex;
271 uint8_t itask_audit_index;
272 stmf_task_audit_rec_t itask_audit_records[ITASK_TASK_AUDIT_DEPTH];
273 } stmf_i_scsi_task_t;
274
275 #define ITASK_DEFAULT_ABORT_TIMEOUT 5
276
277 /*
278 * itask_flags
279 */
280 #define ITASK_IN_FREE_LIST 0x0001
281 #define ITASK_IN_TRANSITION 0x0002
282 #define ITASK_IN_WORKER_QUEUE 0x0004
283 #define ITASK_BEING_ABORTED 0x0008
284 #define ITASK_BEING_COMPLETED 0x0010
285 #define ITASK_KNOWN_TO_TGT_PORT 0x0020
286 #define ITASK_KNOWN_TO_LU 0x0040
287 #define ITASK_LU_ABORT_CALLED 0x0080
288 #define ITASK_TGT_PORT_ABORT_CALLED 0x0100
289 #define ITASK_DEFAULT_HANDLING 0x0200
290 #define ITASK_CAUSING_LU_RESET 0x0400
291 #define ITASK_CAUSING_TARGET_RESET 0x0800
292 #define ITASK_KSTAT_IN_RUNQ 0x1000
293 #define ITASK_PROXY_TASK 0x2000
294
295 /*
296 * itask cmds.
297 */
|
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
23 *
24 * Copyright 2016 Nexenta Systems, Inc. All rights reserved.
25 * Copyright (c) 2013 by Delphix. All rights reserved.
26 */
27 #ifndef _STMF_IMPL_H
28 #define _STMF_IMPL_H
29
30 #include <sys/stmf_defines.h>
31 #include <sys/stmf_ioctl.h>
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37 typedef uint32_t stmf_event_handle_t;
38 #define STMF_MAX_NUM_EVENTS (sizeof (stmf_event_handle_t) * 8)
39 #define STMF_EVENT_ADD(h, e) (atomic_or_32(&(h), \
40 ((uint32_t)1) << (e)))
41 #define STMF_EVENT_REMOVE(h, e) (atomic_and_32(&(h), \
42 ~(((uint32_t)1) << (e))))
43 #define STMF_EVENT_ENABLED(h, e) (((h) & ((uint32_t)1) << (e)) != 0)
44 #define STMF_EVENT_CLEAR_ALL(h) ((h) = 0)
74 stmf_lu_t *ilu_lu;
75 uint32_t ilu_alloc_size;
76 uint32_t ilu_flags;
77 uint32_t ilu_ref_cnt;
78 uint8_t ilu_state;
79 uint8_t ilu_prev_state;
80 uint8_t ilu_access;
81 uint8_t ilu_alua;
82 stmf_event_handle_t ilu_event_hdl;
83 struct stmf_i_lu *ilu_next;
84 struct stmf_i_lu *ilu_prev;
85 char *ilu_alias;
86 char ilu_ascii_hex_guid[STMF_GUID_INPUT + 1];
87 kmutex_t ilu_task_lock;
88 uint32_t ilu_task_cntr1;
89 uint32_t ilu_task_cntr2;
90 uint32_t *ilu_cur_task_cntr;
91 uint32_t ilu_ntasks; /* # of tasks in the ilu_task list */
92 uint32_t ilu_ntasks_free; /* # of tasks that are free */
93 uint32_t ilu_ntasks_min_free; /* # minimal free tasks */
94 uint32_t ilu_additional_ref;
95 uint32_t ilu_proxy_registered;
96 uint64_t ilu_reg_msgid;
97 struct stmf_i_scsi_task *ilu_tasks;
98 struct stmf_i_scsi_task *ilu_free_tasks;
99 struct stmf_itl_data *ilu_itl_list;
100 kstat_t *ilu_kstat_info;
101 kstat_t *ilu_kstat_io;
102 kmutex_t ilu_kstat_lock;
103 kcondvar_t ilu_offline_pending_cv;
104
105 /* point to the luid entry in stmf_state.stmf_luid_list */
106 void *ilu_luid;
107 } stmf_i_lu_t;
108
109 /*
110 * ilu_flags
111 */
112 #define ILU_STALL_DEREGISTER 0x0001
113 #define ILU_RESET_ACTIVE 0x0002
114
149 kstat_t *ilport_kstat_info;
150 kstat_t *ilport_kstat_io;
151 kmutex_t ilport_kstat_lock;
152 char ilport_kstat_tgt_name[STMF_TGT_NAME_LEN];
153 /* which target group this port belongs to in stmf_state.stmf_tg_list */
154 void *ilport_tg;
155 id_t ilport_instance;
156 /* XXX Need something to track all the remote ports also */
157 } stmf_i_local_port_t;
158
159 #define STMF_AVG_ONLINE_INTERVAL (30 * drv_usectohz(1000000))
160
161 #define MAX_IRPORT 0x10000
162
163 typedef struct stmf_i_remote_port {
164 struct scsi_devid_desc *irport_id;
165 kmutex_t irport_mutex;
166 int irport_refcnt;
167 id_t irport_instance;
168 avl_node_t irport_ln;
169 /* number of active read tasks */
170 uint32_t irport_nread_tasks;
171 /* number of active write tasks */
172 uint32_t irport_nwrite_tasks;
173 hrtime_t irport_rdstart_timestamp;
174 hrtime_t irport_rddone_timestamp;
175 hrtime_t irport_wrstart_timestamp;
176 hrtime_t irport_wrdone_timestamp;
177 kstat_t *irport_kstat_info;
178 kstat_t *irport_kstat_io;
179 kstat_t *irport_kstat_estat; /* extended stats */
180 boolean_t irport_info_dirty;
181 } stmf_i_remote_port_t;
182
183 /*
184 * ilport flags
185 */
186 #define ILPORT_FORCED_OFFLINE 0x01
187 #define ILPORT_SS_GOT_INITIAL_LUNS 0x02
188
189 typedef struct stmf_i_scsi_session {
190 stmf_scsi_session_t *iss_ss;
191 uint32_t iss_alloc_size;
192 uint32_t iss_flags;
193 stmf_i_remote_port_t *iss_irport;
194 struct stmf_i_scsi_session *iss_next;
195 /*
196 * Ideally we should maintain 2 maps. One would indicate a new map
197 * which will become available only upon receipt of a REPORT LUN
198 * cmd.
199 */
200 struct stmf_lun_map *iss_sm;
234 TE_TASK_LPORT_ABORTED,
235 TE_TASK_LU_ABORTED,
236 TE_PROCESS_CMD
237 } task_audit_event_t;
238
239 #define CMD_OR_IOF_NA 0xffffffff
240
241 typedef struct stmf_task_audit_rec {
242 task_audit_event_t ta_event;
243 uint32_t ta_cmd_or_iof;
244 uint32_t ta_itask_flags;
245 stmf_data_buf_t *ta_dbuf;
246 timespec_t ta_timestamp;
247 } stmf_task_audit_rec_t;
248
249 struct stmf_worker;
250 typedef struct stmf_i_scsi_task {
251 scsi_task_t *itask_task;
252 uint32_t itask_alloc_size;
253 uint32_t itask_flags;
254 kmutex_t itask_mutex; /* protects flags and lists */
255 uint64_t itask_proxy_msg_id;
256 stmf_data_buf_t *itask_proxy_dbuf;
257 struct stmf_worker *itask_worker;
258 uint32_t *itask_ilu_task_cntr;
259 struct stmf_i_scsi_task *itask_worker_next;
260 struct stmf_i_scsi_task *itask_lu_next;
261 struct stmf_i_scsi_task *itask_lu_prev;
262 struct stmf_i_scsi_task *itask_lu_free_next;
263 struct stmf_itl_data *itask_itl_datap;
264 clock_t itask_start_time; /* abort and normal */
265 /* For now we only support 4 parallel buffers. Should be enough. */
266 stmf_data_buf_t *itask_dbufs[4];
267 clock_t itask_poll_timeout;
268 uint8_t itask_cmd_stack[ITASK_MAX_NCMDS];
269 uint8_t itask_ncmds;
270 uint8_t itask_allocated_buf_map;
271 uint16_t itask_cdb_buf_size;
272
273 /* Task profile data */
274 hrtime_t itask_start_timestamp;
275 hrtime_t itask_done_timestamp;
276 hrtime_t itask_xfer_done_timestamp;
277 hrtime_t itask_waitq_enter_timestamp;
278 hrtime_t itask_waitq_time;
279 hrtime_t itask_lu_read_time;
280 hrtime_t itask_lu_write_time;
281 hrtime_t itask_lport_read_time;
282 hrtime_t itask_lport_write_time;
283 uint64_t itask_read_xfer;
284 uint64_t itask_write_xfer;
285 kmutex_t itask_audit_mutex;
286 uint8_t itask_audit_index;
287 stmf_task_audit_rec_t itask_audit_records[ITASK_TASK_AUDIT_DEPTH];
288 } stmf_i_scsi_task_t;
289
290 #define ITASK_DEFAULT_ABORT_TIMEOUT 5
291
292 /*
293 * Common code to encode an itask onto the worker_task queue is placed
294 * in this macro to simplify future maintenace activity.
295 */
296 #define STMF_ENQUEUE_ITASK(w, i) \
297 ASSERT((itask->itask_flags & ITASK_IN_FREE_LIST) == 0); \
298 ASSERT(mutex_owned(&itask->itask_mutex)); \
299 ASSERT(mutex_owned(&w->worker_lock)); \
300 i->itask_worker_next = NULL; \
301 if (w->worker_task_tail) { \
302 w->worker_task_tail->itask_worker_next = i; \
303 } else { \
304 w->worker_task_head = i; \
305 } \
306 w->worker_task_tail = i; \
307 if (++(w->worker_queue_depth) > w->worker_max_qdepth_pu) { \
308 w->worker_max_qdepth_pu = w->worker_queue_depth; \
309 } \
310 atomic_inc_32(&w->worker_ref_count); \
311 atomic_or_32(&itask->itask_flags, ITASK_IN_WORKER_QUEUE); \
312 i->itask_waitq_enter_timestamp = gethrtime(); \
313 if ((w->worker_flags & STMF_WORKER_ACTIVE) == 0) \
314 cv_signal(&w->worker_cv);
315
316 #define STMF_DEQUEUE_ITASK(w, itask) \
317 ASSERT(mutex_owned(&w->worker_lock)); \
318 if ((itask = w->worker_task_head) != NULL) { \
319 w->worker_task_head = itask->itask_worker_next; \
320 if (w->worker_task_head == NULL) { \
321 w->worker_task_tail = NULL; \
322 } \
323 } else { \
324 w->worker_task_tail = NULL; \
325 }
326
327 /*
328 * itask_flags
329 */
330 #define ITASK_IN_FREE_LIST 0x0001
331 #define ITASK_IN_TRANSITION 0x0002
332 #define ITASK_IN_WORKER_QUEUE 0x0004
333 #define ITASK_BEING_ABORTED 0x0008
334 #define ITASK_BEING_COMPLETED 0x0010
335 #define ITASK_KNOWN_TO_TGT_PORT 0x0020
336 #define ITASK_KNOWN_TO_LU 0x0040
337 #define ITASK_LU_ABORT_CALLED 0x0080
338 #define ITASK_TGT_PORT_ABORT_CALLED 0x0100
339 #define ITASK_DEFAULT_HANDLING 0x0200
340 #define ITASK_CAUSING_LU_RESET 0x0400
341 #define ITASK_CAUSING_TARGET_RESET 0x0800
342 #define ITASK_KSTAT_IN_RUNQ 0x1000
343 #define ITASK_PROXY_TASK 0x2000
344
345 /*
346 * itask cmds.
347 */
|