2 * Copyright (c) 2003 Silicon Graphics International Corp.
3 * Copyright (c) 2014-2015 Alexander Motin <mav@FreeBSD.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions, and the following disclaimer,
11 * without modification.
12 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
13 * substantially similar to the "NO WARRANTY" disclaimer below
14 * ("Disclaimer") and any redistribution must be conditioned upon
15 * including a substantially similar Disclaimer requirement for further
16 * binary redistribution.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
28 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGES.
31 * $Id: //depot/users/kenm/FreeBSD-test2/sys/cam/ctl/ctl_io.h#5 $
35 * CAM Target Layer data movement structures/interface.
37 * Author: Ken Merry <ken@FreeBSD.org>
44 #define EXTERN(__var,__val) __var = __val
46 #define EXTERN(__var,__val) extern __var
49 #define CTL_MAX_CDBLEN 32
51 * Uncomment this next line to enable printing out times for I/Os
52 * that take longer than CTL_TIME_IO_SECS seconds to get to the datamove
57 #define CTL_TIME_IO_DEFAULT_SECS 90
58 EXTERN(int ctl_time_io_secs, CTL_TIME_IO_DEFAULT_SECS);
62 * Uncomment this next line to enable the CTL I/O delay feature. You
63 * can delay I/O at two different points -- datamove and done. This is
64 * useful for diagnosing abort conditions (for hosts that send an abort on a
65 * timeout), and for determining how long a host's timeout is.
67 //#define CTL_IO_DELAY
70 CTL_STATUS_NONE, /* No status */
71 CTL_SUCCESS, /* Transaction completed successfully */
72 CTL_CMD_TIMEOUT, /* Command timed out, shouldn't happen here */
73 CTL_SEL_TIMEOUT, /* Selection timeout, shouldn't happen here */
74 CTL_ERROR, /* General CTL error XXX expand on this? */
75 CTL_SCSI_ERROR, /* SCSI error, look at status byte/sense data */
76 CTL_CMD_ABORTED, /* Command aborted, don't return status */
77 CTL_STATUS_MASK = 0xfff,/* Mask off any status flags */
78 CTL_AUTOSENSE = 0x1000 /* Autosense performed */
82 * WARNING: Keep the data in/out/none flags where they are. They're used
83 * in conjuction with ctl_cmd_flags. See comment above ctl_cmd_flags
84 * definition in ctl_private.h.
87 CTL_FLAG_NONE = 0x00000000, /* no flags */
88 CTL_FLAG_DATA_IN = 0x00000001, /* DATA IN */
89 CTL_FLAG_DATA_OUT = 0x00000002, /* DATA OUT */
90 CTL_FLAG_DATA_NONE = 0x00000003, /* no data */
91 CTL_FLAG_DATA_MASK = 0x00000003,
92 CTL_FLAG_DO_AUTOSENSE = 0x00000020, /* grab sense info */
93 CTL_FLAG_USER_REQ = 0x00000040, /* request came from userland */
94 CTL_FLAG_ALLOCATED = 0x00000100, /* data space allocated */
95 CTL_FLAG_BLOCKED = 0x00000200, /* on the blocked queue */
96 CTL_FLAG_ABORT_STATUS = 0x00000400, /* return TASK ABORTED status */
97 CTL_FLAG_ABORT = 0x00000800, /* this I/O should be aborted */
98 CTL_FLAG_DMA_INPROG = 0x00001000, /* DMA in progress */
99 CTL_FLAG_DELAY_DONE = 0x00004000, /* delay injection done */
100 CTL_FLAG_INT_COPY = 0x00008000, /* internal copy, no done call*/
101 CTL_FLAG_SENT_2OTHER_SC = 0x00010000,
102 CTL_FLAG_FROM_OTHER_SC = 0x00020000,
103 CTL_FLAG_IS_WAS_ON_RTR = 0x00040000, /* Don't rerun cmd on failover*/
104 CTL_FLAG_BUS_ADDR = 0x00080000, /* ctl_sglist contains BUS
105 addresses, not virtual ones*/
106 CTL_FLAG_IO_CONT = 0x00100000, /* Continue I/O instead of
109 CTL_FLAG_ALREADY_DONE = 0x00200000 /* I/O already completed */
111 CTL_FLAG_NO_DATAMOVE = 0x00400000,
112 CTL_FLAG_DMA_QUEUED = 0x00800000, /* DMA queued but not started*/
113 CTL_FLAG_STATUS_QUEUED = 0x01000000, /* Status queued but not sent*/
115 CTL_FLAG_FAILOVER = 0x04000000, /* Killed by a failover */
116 CTL_FLAG_IO_ACTIVE = 0x08000000, /* I/O active on this SC */
117 CTL_FLAG_STATUS_SENT = 0x10000000, /* Status sent by datamove */
118 CTL_FLAG_SERSEQ_DONE = 0x20000000 /* All storage I/O started */
127 struct ctl_lba_len_flags {
131 #define CTL_LLF_FUA 0x04000000
132 #define CTL_LLF_DPO 0x08000000
133 #define CTL_LLF_READ 0x10000000
134 #define CTL_LLF_WRITE 0x20000000
135 #define CTL_LLF_VERIFY 0x40000000
136 #define CTL_LLF_COMPARE 0x80000000
139 struct ctl_ptr_len_flags {
146 uint8_t bytes[sizeof(uint64_t) * 2];
152 * Number of CTL private areas.
154 #define CTL_NUM_PRIV 6
157 * Which private area are we using for a particular piece of data?
159 #define CTL_PRIV_LUN 0 /* CTL LUN pointer goes here */
160 #define CTL_PRIV_LBA_LEN 1 /* Decoded LBA/len for read/write*/
161 #define CTL_PRIV_MODEPAGE 1 /* Modepage info for config write */
162 #define CTL_PRIV_BACKEND 2 /* Reserved for block, RAIDCore */
163 #define CTL_PRIV_BACKEND_LUN 3 /* Backend LUN pointer */
164 #define CTL_PRIV_FRONTEND 4 /* Frontend storage */
165 #define CTL_PRIV_FRONTEND2 5 /* Another frontend storage */
167 #define CTL_INVALID_PORTNAME 0xFF
168 #define CTL_UNMAPPED_IID 0xFF
170 struct ctl_sg_entry {
182 uint32_t initid; /* Initiator ID */
183 uint32_t targ_port; /* Target port, filled in by PORT */
184 uint32_t targ_lun; /* Destination lun */
185 uint32_t targ_mapped_lun; /* Destination lun CTL-wide */
193 CTL_MSG_MANAGE_TASKS,
196 CTL_MSG_DATAMOVE_DONE,
197 CTL_MSG_UA, /* Set/clear UA on secondary. */
198 CTL_MSG_PORT_SYNC, /* Information about port. */
199 CTL_MSG_LUN_SYNC, /* Information about LUN. */
200 CTL_MSG_IID_SYNC, /* Information about initiator. */
201 CTL_MSG_LOGIN, /* Information about HA peer. */
202 CTL_MSG_MODE_SYNC, /* Mode page current content. */
203 CTL_MSG_FAILOVER /* Fake, never sent though the wire */
209 uint32_t version; /* interface version XXX */
210 ctl_io_type io_type; /* task I/O, SCSI I/O, etc. */
211 ctl_msg_type msg_type;
212 struct ctl_nexus nexus; /* Initiator, port, target, lun */
213 uint32_t iid_indx; /* the index into the iid mapping */
214 uint32_t flags; /* transaction flags */
215 uint32_t status; /* transaction status */
216 uint32_t port_status; /* trans status, set by PORT, 0 = good*/
217 uint32_t timeout; /* timeout in ms */
218 uint32_t retries; /* retry count */
220 struct callout delay_callout;
221 #endif /* CTL_IO_DELAY */
223 time_t start_time; /* I/O start time */
224 struct bintime start_bt; /* Timer start ticks */
225 struct bintime dma_start_bt; /* DMA start ticks */
226 struct bintime dma_bt; /* DMA total ticks */
227 #endif /* CTL_TIME_IO */
228 uint32_t num_dmas; /* Number of DMAs */
229 union ctl_io *original_sc;
230 union ctl_io *serializing_sc;
231 void *pool; /* I/O pool */
232 union ctl_priv ctl_private[CTL_NUM_PRIV];/* CTL private area */
233 struct ctl_sg_entry *remote_sglist;
234 struct ctl_sg_entry *local_sglist;
235 STAILQ_ENTRY(ctl_io_hdr) links; /* linked list pointer */
236 TAILQ_ENTRY(ctl_io_hdr) ooa_links;
237 TAILQ_ENTRY(ctl_io_hdr) blocked_links;
244 CTL_TAG_HEAD_OF_QUEUE,
251 * SCSI passthrough I/O structure for the CAM Target Layer. Note
252 * that some of these fields are here for completeness, but they aren't
253 * used in the CTL implementation. e.g., timeout and retries won't be
256 * Note: Make sure the io_hdr is *always* the first element in this
260 struct ctl_io_hdr io_hdr; /* common to all I/O types */
263 * The ext_* fields are generally intended for frontend use; CTL itself
264 * doesn't modify or use them.
266 uint32_t ext_sg_entries; /* 0 = no S/G list, > 0 = num entries */
267 uint8_t *ext_data_ptr; /* data buffer or S/G list */
268 uint32_t ext_data_len; /* Data transfer length */
269 uint32_t ext_data_filled; /* Amount of data filled so far */
272 * The number of scatter/gather entries in the list pointed to
273 * by kern_data_ptr. 0 means there is no list, just a data pointer.
275 uint32_t kern_sg_entries;
277 uint32_t rem_sg_entries; /* Unused. */
280 * The data pointer or a pointer to the scatter/gather list.
282 uint8_t *kern_data_ptr;
285 * Length of the data buffer or scatter/gather list. It's also
286 * the length of this particular piece of the data transfer,
287 * ie. number of bytes expected to be transferred by the current
288 * invocation of frontend's datamove() callback. It's always
289 * less than or equal to kern_total_len.
291 uint32_t kern_data_len;
294 * Total length of data to be transferred during this particular
295 * SCSI command, as decoded from SCSI CDB.
297 uint32_t kern_total_len;
300 * Amount of data left after the current data transfer.
302 uint32_t kern_data_resid;
305 * Byte offset of this transfer, equal to the amount of data
306 * already transferred for this SCSI command during previous
307 * datamove() invocations.
309 uint32_t kern_rel_offset;
311 struct scsi_sense_data sense_data; /* sense data */
312 uint8_t sense_len; /* Returned sense length */
313 uint8_t scsi_status; /* SCSI status byte */
314 uint8_t sense_residual; /* Unused. */
315 uint32_t residual; /* data residual length */
316 uint32_t tag_num; /* tag number */
317 ctl_tag_type tag_type; /* simple, ordered, head of queue,etc.*/
318 uint8_t cdb_len; /* CDB length */
319 uint8_t cdb[CTL_MAX_CDBLEN]; /* CDB */
320 int (*be_move_done)(union ctl_io *io); /* called by fe */
321 int (*io_cont)(union ctl_io *io); /* to continue processing */
326 CTL_TASK_ABORT_TASK_SET,
328 CTL_TASK_CLEAR_TASK_SET,
329 CTL_TASK_I_T_NEXUS_RESET,
331 CTL_TASK_TARGET_RESET,
334 CTL_TASK_PORT_LOGOUT,
336 CTL_TASK_QUERY_TASK_SET,
337 CTL_TASK_QUERY_ASYNC_EVENT
341 CTL_TASK_FUNCTION_COMPLETE,
342 CTL_TASK_FUNCTION_SUCCEEDED,
343 CTL_TASK_FUNCTION_REJECTED,
344 CTL_TASK_LUN_DOES_NOT_EXIST,
345 CTL_TASK_FUNCTION_NOT_SUPPORTED
349 * Task management I/O structure. Aborts, bus resets, etc., are sent using
352 * Note: Make sure the io_hdr is *always* the first element in this
356 struct ctl_io_hdr io_hdr; /* common to all I/O types */
357 ctl_task_type task_action; /* Target Reset, Abort, etc. */
358 uint32_t tag_num; /* tag number */
359 ctl_tag_type tag_type; /* simple, ordered, etc. */
360 uint8_t task_status; /* Complete, Succeeded, etc. */
361 uint8_t task_resp[3];/* Response information */
368 #define CTL_HA_VERSION 1
371 * Used for CTL_MSG_LOGIN.
373 struct ctl_ha_msg_login {
374 ctl_msg_type msg_type;
380 int max_init_per_port;
393 * The PR info is specifically for sending Persistent Reserve actions
394 * to the other SC which it must also act on.
396 * Note: Make sure the io_hdr is *always* the first element in this
400 ctl_pr_action action;
401 uint8_t sa_res_key[8];
406 struct ctl_ha_msg_hdr {
407 ctl_msg_type msg_type;
408 uint32_t status; /* transaction status */
409 union ctl_io *original_sc;
410 union ctl_io *serializing_sc;
411 struct ctl_nexus nexus; /* Initiator, port, target, lun */
414 #define CTL_HA_MAX_SG_ENTRIES 16
415 #define CTL_HA_DATAMOVE_SEGMENT 131072
418 * Used for CTL_MSG_PERS_ACTION.
420 struct ctl_ha_msg_pr {
421 struct ctl_ha_msg_hdr hdr;
422 struct ctl_pr_info pr_info;
426 * Used for CTL_MSG_UA.
428 struct ctl_ha_msg_ua {
429 struct ctl_ha_msg_hdr hdr;
437 * The S/G handling here is a little different than the standard ctl_scsiio
438 * structure, because we can't pass data by reference in between controllers.
439 * The S/G list in the ctl_scsiio struct is normally passed in the
440 * kern_data_ptr field. So kern_sg_entries here will always be non-zero,
441 * even if there is only one entry.
443 * Used for CTL_MSG_DATAMOVE.
445 struct ctl_ha_msg_dt {
446 struct ctl_ha_msg_hdr hdr;
447 ctl_io_flags flags; /* Only I/O flags are used here */
448 uint32_t sg_sequence; /* S/G portion number */
449 uint8_t sg_last; /* last S/G batch = 1 */
450 uint32_t sent_sg_entries; /* previous S/G count */
451 uint32_t cur_sg_entries; /* current S/G entries */
452 uint32_t kern_sg_entries; /* total S/G entries */
453 uint32_t kern_data_len; /* Length of this S/G list */
454 uint32_t kern_total_len; /* Total length of this
456 uint32_t kern_data_resid; /* Length left to transfer
458 uint32_t kern_rel_offset; /* Byte Offset of this
460 struct ctl_sg_entry sg_list[CTL_HA_MAX_SG_ENTRIES];
464 * Used for CTL_MSG_SERIALIZE, CTL_MSG_FINISH_IO, CTL_MSG_BAD_JUJU.
466 struct ctl_ha_msg_scsi {
467 struct ctl_ha_msg_hdr hdr;
468 uint32_t tag_num; /* tag number */
469 ctl_tag_type tag_type; /* simple, ordered, etc. */
470 uint8_t cdb[CTL_MAX_CDBLEN]; /* CDB */
471 uint8_t cdb_len; /* CDB length */
472 uint8_t scsi_status; /* SCSI status byte */
473 uint8_t sense_len; /* Returned sense length */
474 uint8_t sense_residual; /* sense residual length */
475 uint32_t residual; /* data residual length */
476 uint32_t fetd_status; /* trans status, set by FETD,
478 struct scsi_sense_data sense_data; /* sense data */
482 * Used for CTL_MSG_MANAGE_TASKS.
484 struct ctl_ha_msg_task {
485 struct ctl_ha_msg_hdr hdr;
486 ctl_task_type task_action; /* Target Reset, Abort, etc. */
487 uint32_t tag_num; /* tag number */
488 ctl_tag_type tag_type; /* simple, ordered, etc. */
492 * Used for CTL_MSG_PORT_SYNC.
494 struct ctl_ha_msg_port {
495 struct ctl_ha_msg_hdr hdr;
503 int target_devid_len;
509 * Used for CTL_MSG_LUN_SYNC.
511 struct ctl_ha_msg_lun {
512 struct ctl_ha_msg_hdr hdr;
514 unsigned int pr_generation;
522 struct ctl_ha_msg_lun_pr_key {
528 * Used for CTL_MSG_IID_SYNC.
530 struct ctl_ha_msg_iid {
531 struct ctl_ha_msg_hdr hdr;
539 * Used for CTL_MSG_MODE_SYNC.
541 struct ctl_ha_msg_mode {
542 struct ctl_ha_msg_hdr hdr;
550 struct ctl_ha_msg_hdr hdr;
551 struct ctl_ha_msg_task task;
552 struct ctl_ha_msg_scsi scsi;
553 struct ctl_ha_msg_dt dt;
554 struct ctl_ha_msg_pr pr;
555 struct ctl_ha_msg_ua ua;
556 struct ctl_ha_msg_port port;
557 struct ctl_ha_msg_lun lun;
558 struct ctl_ha_msg_iid iid;
559 struct ctl_ha_msg_login login;
560 struct ctl_ha_msg_mode mode;
564 struct ctl_io_hdr io_hdr;
565 struct ctl_ha_msg_pr pr_msg;
569 struct ctl_io_hdr io_hdr; /* common to all I/O types */
570 struct ctl_scsiio scsiio; /* Normal SCSI commands */
571 struct ctl_taskio taskio; /* SCSI task management/reset */
572 struct ctl_prio presio; /* update per. res info on other SC */
577 union ctl_io *ctl_alloc_io(void *pool_ref);
578 union ctl_io *ctl_alloc_io_nowait(void *pool_ref);
579 void ctl_free_io(union ctl_io *io);
580 void ctl_zero_io(union ctl_io *io);
584 #endif /* _CTL_IO_H_ */