Deleted Added
full compact
ctl_io.h (312584) ctl_io.h (312834)
1/*-
2 * Copyright (c) 2003 Silicon Graphics International Corp.
3 * Copyright (c) 2014-2015 Alexander Motin <mav@FreeBSD.org>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
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.
17 *
18 * NO WARRANTY
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.
30 *
31 * $Id: //depot/users/kenm/FreeBSD-test2/sys/cam/ctl/ctl_io.h#5 $
1/*-
2 * Copyright (c) 2003 Silicon Graphics International Corp.
3 * Copyright (c) 2014-2015 Alexander Motin <mav@FreeBSD.org>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
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.
17 *
18 * NO WARRANTY
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.
30 *
31 * $Id: //depot/users/kenm/FreeBSD-test2/sys/cam/ctl/ctl_io.h#5 $
32 * $FreeBSD: stable/11/sys/cam/ctl/ctl_io.h 312584 2017-01-21 08:40:30Z mav $
32 * $FreeBSD: stable/11/sys/cam/ctl/ctl_io.h 312834 2017-01-26 20:49:19Z mav $
33 */
34/*
35 * CAM Target Layer data movement structures/interface.
36 *
37 * Author: Ken Merry <ken@FreeBSD.org>
38 */
39
40#ifndef _CTL_IO_H_
41#define _CTL_IO_H_
42
43#ifdef _CTL_C
44#define EXTERN(__var,__val) __var = __val
45#else
46#define EXTERN(__var,__val) extern __var
47#endif
48
49#define CTL_MAX_CDBLEN 32
50/*
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
53 * and/or done stage.
54 */
55#define CTL_TIME_IO
56#ifdef CTL_TIME_IO
57#define CTL_TIME_IO_DEFAULT_SECS 90
58EXTERN(int ctl_time_io_secs, CTL_TIME_IO_DEFAULT_SECS);
59#endif
60
61/*
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.
66 */
67//#define CTL_IO_DELAY
68
69typedef enum {
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 */
79} ctl_io_status;
80
81/*
82 * WARNING: Keep the data in/out/none flags where they are. They're used
83 * in conjunction with ctl_cmd_flags. See comment above ctl_cmd_flags
84 * definition in ctl_private.h.
85 */
86typedef enum {
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
107 completing */
108#if 0
109 CTL_FLAG_ALREADY_DONE = 0x00200000 /* I/O already completed */
110#endif
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*/
114
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 */
119} ctl_io_flags;
120
121
122struct ctl_lba_len {
123 uint64_t lba;
124 uint32_t len;
125};
126
127struct ctl_lba_len_flags {
128 uint64_t lba;
129 uint32_t len;
130 uint32_t 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
137};
138
139struct ctl_ptr_len_flags {
140 uint8_t *ptr;
141 uint32_t len;
142 uint32_t flags;
143};
144
145union ctl_priv {
146 uint8_t bytes[sizeof(uint64_t) * 2];
147 uint64_t integer;
148 uint64_t integers[2];
149 void *ptr;
150 void *ptrs[2];
151};
152
153/*
154 * Number of CTL private areas.
155 */
156#define CTL_NUM_PRIV 6
157
158/*
159 * Which private area are we using for a particular piece of data?
160 */
161#define CTL_PRIV_LUN 0 /* CTL LUN pointer goes here */
162#define CTL_PRIV_LBA_LEN 1 /* Decoded LBA/len for read/write*/
163#define CTL_PRIV_MODEPAGE 1 /* Modepage info for config write */
164#define CTL_PRIV_BACKEND 2 /* Reserved for block, RAIDCore */
165#define CTL_PRIV_BACKEND_LUN 3 /* Backend LUN pointer */
166#define CTL_PRIV_FRONTEND 4 /* Frontend storage */
167#define CTL_PRIV_FRONTEND2 5 /* Another frontend storage */
168
33 */
34/*
35 * CAM Target Layer data movement structures/interface.
36 *
37 * Author: Ken Merry <ken@FreeBSD.org>
38 */
39
40#ifndef _CTL_IO_H_
41#define _CTL_IO_H_
42
43#ifdef _CTL_C
44#define EXTERN(__var,__val) __var = __val
45#else
46#define EXTERN(__var,__val) extern __var
47#endif
48
49#define CTL_MAX_CDBLEN 32
50/*
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
53 * and/or done stage.
54 */
55#define CTL_TIME_IO
56#ifdef CTL_TIME_IO
57#define CTL_TIME_IO_DEFAULT_SECS 90
58EXTERN(int ctl_time_io_secs, CTL_TIME_IO_DEFAULT_SECS);
59#endif
60
61/*
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.
66 */
67//#define CTL_IO_DELAY
68
69typedef enum {
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 */
79} ctl_io_status;
80
81/*
82 * WARNING: Keep the data in/out/none flags where they are. They're used
83 * in conjunction with ctl_cmd_flags. See comment above ctl_cmd_flags
84 * definition in ctl_private.h.
85 */
86typedef enum {
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
107 completing */
108#if 0
109 CTL_FLAG_ALREADY_DONE = 0x00200000 /* I/O already completed */
110#endif
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*/
114
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 */
119} ctl_io_flags;
120
121
122struct ctl_lba_len {
123 uint64_t lba;
124 uint32_t len;
125};
126
127struct ctl_lba_len_flags {
128 uint64_t lba;
129 uint32_t len;
130 uint32_t 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
137};
138
139struct ctl_ptr_len_flags {
140 uint8_t *ptr;
141 uint32_t len;
142 uint32_t flags;
143};
144
145union ctl_priv {
146 uint8_t bytes[sizeof(uint64_t) * 2];
147 uint64_t integer;
148 uint64_t integers[2];
149 void *ptr;
150 void *ptrs[2];
151};
152
153/*
154 * Number of CTL private areas.
155 */
156#define CTL_NUM_PRIV 6
157
158/*
159 * Which private area are we using for a particular piece of data?
160 */
161#define CTL_PRIV_LUN 0 /* CTL LUN pointer goes here */
162#define CTL_PRIV_LBA_LEN 1 /* Decoded LBA/len for read/write*/
163#define CTL_PRIV_MODEPAGE 1 /* Modepage info for config write */
164#define CTL_PRIV_BACKEND 2 /* Reserved for block, RAIDCore */
165#define CTL_PRIV_BACKEND_LUN 3 /* Backend LUN pointer */
166#define CTL_PRIV_FRONTEND 4 /* Frontend storage */
167#define CTL_PRIV_FRONTEND2 5 /* Another frontend storage */
168
169#define CTL_LUN(io) ((io)->io_hdr.ctl_private[CTL_PRIV_LUN].ptrs[0])
170#define CTL_SOFTC(io) ((io)->io_hdr.ctl_private[CTL_PRIV_LUN].ptrs[1])
171#define CTL_BACKEND_LUN(io) ((io)->io_hdr.ctl_private[CTL_PRIV_BACKEND_LUN].ptrs[0])
172#define CTL_PORT(io) (((struct ctl_softc *)CTL_SOFTC(io))-> \
173 ctl_ports[(io)->io_hdr.nexus.targ_port])
174
169#define CTL_INVALID_PORTNAME 0xFF
170#define CTL_UNMAPPED_IID 0xFF
171
172struct ctl_sg_entry {
173 void *addr;
174 size_t len;
175};
176
177typedef enum {
178 CTL_IO_NONE,
179 CTL_IO_SCSI,
180 CTL_IO_TASK,
181} ctl_io_type;
182
183struct ctl_nexus {
184 uint32_t initid; /* Initiator ID */
185 uint32_t targ_port; /* Target port, filled in by PORT */
186 uint32_t targ_lun; /* Destination lun */
187 uint32_t targ_mapped_lun; /* Destination lun CTL-wide */
188};
189
190typedef enum {
191 CTL_MSG_SERIALIZE,
192 CTL_MSG_R2R,
193 CTL_MSG_FINISH_IO,
194 CTL_MSG_BAD_JUJU,
195 CTL_MSG_MANAGE_TASKS,
196 CTL_MSG_PERS_ACTION,
197 CTL_MSG_DATAMOVE,
198 CTL_MSG_DATAMOVE_DONE,
199 CTL_MSG_UA, /* Set/clear UA on secondary. */
200 CTL_MSG_PORT_SYNC, /* Information about port. */
201 CTL_MSG_LUN_SYNC, /* Information about LUN. */
202 CTL_MSG_IID_SYNC, /* Information about initiator. */
203 CTL_MSG_LOGIN, /* Information about HA peer. */
204 CTL_MSG_MODE_SYNC, /* Mode page current content. */
205 CTL_MSG_FAILOVER /* Fake, never sent though the wire */
206} ctl_msg_type;
207
208struct ctl_scsiio;
209
210struct ctl_io_hdr {
211 uint32_t version; /* interface version XXX */
212 ctl_io_type io_type; /* task I/O, SCSI I/O, etc. */
213 ctl_msg_type msg_type;
214 struct ctl_nexus nexus; /* Initiator, port, target, lun */
215 uint32_t iid_indx; /* the index into the iid mapping */
216 uint32_t flags; /* transaction flags */
217 uint32_t status; /* transaction status */
218 uint32_t port_status; /* trans status, set by PORT, 0 = good*/
219 uint32_t timeout; /* timeout in ms */
220 uint32_t retries; /* retry count */
221#ifdef CTL_IO_DELAY
222 struct callout delay_callout;
223#endif /* CTL_IO_DELAY */
224#ifdef CTL_TIME_IO
225 time_t start_time; /* I/O start time */
226 struct bintime start_bt; /* Timer start ticks */
227 struct bintime dma_start_bt; /* DMA start ticks */
228 struct bintime dma_bt; /* DMA total ticks */
229#endif /* CTL_TIME_IO */
230 uint32_t num_dmas; /* Number of DMAs */
231 union ctl_io *original_sc;
232 union ctl_io *serializing_sc;
233 void *pool; /* I/O pool */
234 union ctl_priv ctl_private[CTL_NUM_PRIV];/* CTL private area */
235 struct ctl_sg_entry *remote_sglist;
236 struct ctl_sg_entry *local_sglist;
237 STAILQ_ENTRY(ctl_io_hdr) links; /* linked list pointer */
238 TAILQ_ENTRY(ctl_io_hdr) ooa_links;
239 TAILQ_ENTRY(ctl_io_hdr) blocked_links;
240};
241
242typedef enum {
243 CTL_TAG_UNTAGGED,
244 CTL_TAG_SIMPLE,
245 CTL_TAG_ORDERED,
246 CTL_TAG_HEAD_OF_QUEUE,
247 CTL_TAG_ACA
248} ctl_tag_type;
249
250union ctl_io;
251
252/*
253 * SCSI passthrough I/O structure for the CAM Target Layer. Note
254 * that some of these fields are here for completeness, but they aren't
255 * used in the CTL implementation. e.g., timeout and retries won't be
256 * used.
257 *
258 * Note: Make sure the io_hdr is *always* the first element in this
259 * structure.
260 */
261struct ctl_scsiio {
262 struct ctl_io_hdr io_hdr; /* common to all I/O types */
263
264 /*
265 * The ext_* fields are generally intended for frontend use; CTL itself
266 * doesn't modify or use them.
267 */
268 uint32_t ext_sg_entries; /* 0 = no S/G list, > 0 = num entries */
269 uint8_t *ext_data_ptr; /* data buffer or S/G list */
270 uint32_t ext_data_len; /* Data transfer length */
271 uint32_t ext_data_filled; /* Amount of data filled so far */
272
273 /*
274 * The number of scatter/gather entries in the list pointed to
275 * by kern_data_ptr. 0 means there is no list, just a data pointer.
276 */
277 uint32_t kern_sg_entries;
278
279 uint32_t rem_sg_entries; /* Unused. */
280
281 /*
282 * The data pointer or a pointer to the scatter/gather list.
283 */
284 uint8_t *kern_data_ptr;
285
286 /*
287 * Length of the data buffer or scatter/gather list. It's also
288 * the length of this particular piece of the data transfer,
289 * ie. number of bytes expected to be transferred by the current
290 * invocation of frontend's datamove() callback. It's always
291 * less than or equal to kern_total_len.
292 */
293 uint32_t kern_data_len;
294
295 /*
296 * Total length of data to be transferred during this particular
297 * SCSI command, as decoded from SCSI CDB.
298 */
299 uint32_t kern_total_len;
300
301 /*
302 * Amount of data left after the current data transfer.
303 */
304 uint32_t kern_data_resid;
305
306 /*
307 * Byte offset of this transfer, equal to the amount of data
308 * already transferred for this SCSI command during previous
309 * datamove() invocations.
310 */
311 uint32_t kern_rel_offset;
312
313 struct scsi_sense_data sense_data; /* sense data */
314 uint8_t sense_len; /* Returned sense length */
315 uint8_t scsi_status; /* SCSI status byte */
316 uint8_t sense_residual; /* Unused. */
317 uint32_t residual; /* data residual length */
318 uint32_t tag_num; /* tag number */
319 ctl_tag_type tag_type; /* simple, ordered, head of queue,etc.*/
320 uint8_t cdb_len; /* CDB length */
321 uint8_t cdb[CTL_MAX_CDBLEN]; /* CDB */
322 int (*be_move_done)(union ctl_io *io); /* called by fe */
323 int (*io_cont)(union ctl_io *io); /* to continue processing */
324};
325
326typedef enum {
327 CTL_TASK_ABORT_TASK,
328 CTL_TASK_ABORT_TASK_SET,
329 CTL_TASK_CLEAR_ACA,
330 CTL_TASK_CLEAR_TASK_SET,
331 CTL_TASK_I_T_NEXUS_RESET,
332 CTL_TASK_LUN_RESET,
333 CTL_TASK_TARGET_RESET,
334 CTL_TASK_BUS_RESET,
335 CTL_TASK_PORT_LOGIN,
336 CTL_TASK_PORT_LOGOUT,
337 CTL_TASK_QUERY_TASK,
338 CTL_TASK_QUERY_TASK_SET,
339 CTL_TASK_QUERY_ASYNC_EVENT
340} ctl_task_type;
341
342typedef enum {
343 CTL_TASK_FUNCTION_COMPLETE,
344 CTL_TASK_FUNCTION_SUCCEEDED,
345 CTL_TASK_FUNCTION_REJECTED,
346 CTL_TASK_LUN_DOES_NOT_EXIST,
347 CTL_TASK_FUNCTION_NOT_SUPPORTED
348} ctl_task_status;
349
350/*
351 * Task management I/O structure. Aborts, bus resets, etc., are sent using
352 * this structure.
353 *
354 * Note: Make sure the io_hdr is *always* the first element in this
355 * structure.
356 */
357struct ctl_taskio {
358 struct ctl_io_hdr io_hdr; /* common to all I/O types */
359 ctl_task_type task_action; /* Target Reset, Abort, etc. */
360 uint32_t tag_num; /* tag number */
361 ctl_tag_type tag_type; /* simple, ordered, etc. */
362 uint8_t task_status; /* Complete, Succeeded, etc. */
363 uint8_t task_resp[3];/* Response information */
364};
365
366
367/*
368 * HA link messages.
369 */
370#define CTL_HA_VERSION 2
371
372/*
373 * Used for CTL_MSG_LOGIN.
374 */
375struct ctl_ha_msg_login {
376 ctl_msg_type msg_type;
377 int version;
378 int ha_mode;
379 int ha_id;
380 int max_luns;
381 int max_ports;
382 int max_init_per_port;
383};
384
385typedef enum {
386 CTL_PR_REG_KEY,
387 CTL_PR_UNREG_KEY,
388 CTL_PR_PREEMPT,
389 CTL_PR_CLEAR,
390 CTL_PR_RESERVE,
391 CTL_PR_RELEASE
392} ctl_pr_action;
393
394/*
395 * The PR info is specifically for sending Persistent Reserve actions
396 * to the other SC which it must also act on.
397 *
398 * Note: Make sure the io_hdr is *always* the first element in this
399 * structure.
400 */
401struct ctl_pr_info {
402 ctl_pr_action action;
403 uint8_t sa_res_key[8];
404 uint8_t res_type;
405 uint32_t residx;
406};
407
408struct ctl_ha_msg_hdr {
409 ctl_msg_type msg_type;
410 uint32_t status; /* transaction status */
411 union ctl_io *original_sc;
412 union ctl_io *serializing_sc;
413 struct ctl_nexus nexus; /* Initiator, port, target, lun */
414};
415
416#define CTL_HA_MAX_SG_ENTRIES 16
417#define CTL_HA_DATAMOVE_SEGMENT 131072
418
419/*
420 * Used for CTL_MSG_PERS_ACTION.
421 */
422struct ctl_ha_msg_pr {
423 struct ctl_ha_msg_hdr hdr;
424 struct ctl_pr_info pr_info;
425};
426
427/*
428 * Used for CTL_MSG_UA.
429 */
430struct ctl_ha_msg_ua {
431 struct ctl_ha_msg_hdr hdr;
432 int ua_all;
433 int ua_set;
434 int ua_type;
435 uint8_t ua_info[8];
436};
437
438/*
439 * The S/G handling here is a little different than the standard ctl_scsiio
440 * structure, because we can't pass data by reference in between controllers.
441 * The S/G list in the ctl_scsiio struct is normally passed in the
442 * kern_data_ptr field. So kern_sg_entries here will always be non-zero,
443 * even if there is only one entry.
444 *
445 * Used for CTL_MSG_DATAMOVE.
446 */
447struct ctl_ha_msg_dt {
448 struct ctl_ha_msg_hdr hdr;
449 ctl_io_flags flags; /* Only I/O flags are used here */
450 uint32_t sg_sequence; /* S/G portion number */
451 uint8_t sg_last; /* last S/G batch = 1 */
452 uint32_t sent_sg_entries; /* previous S/G count */
453 uint32_t cur_sg_entries; /* current S/G entries */
454 uint32_t kern_sg_entries; /* total S/G entries */
455 uint32_t kern_data_len; /* Length of this S/G list */
456 uint32_t kern_total_len; /* Total length of this
457 transaction */
458 uint32_t kern_data_resid; /* Length left to transfer
459 after this*/
460 uint32_t kern_rel_offset; /* Byte Offset of this
461 transfer */
462 struct ctl_sg_entry sg_list[CTL_HA_MAX_SG_ENTRIES];
463};
464
465/*
466 * Used for CTL_MSG_SERIALIZE, CTL_MSG_FINISH_IO, CTL_MSG_BAD_JUJU.
467 */
468struct ctl_ha_msg_scsi {
469 struct ctl_ha_msg_hdr hdr;
470 uint32_t tag_num; /* tag number */
471 ctl_tag_type tag_type; /* simple, ordered, etc. */
472 uint8_t cdb[CTL_MAX_CDBLEN]; /* CDB */
473 uint8_t cdb_len; /* CDB length */
474 uint8_t scsi_status; /* SCSI status byte */
475 uint8_t sense_len; /* Returned sense length */
476 uint8_t sense_residual; /* sense residual length */
477 uint32_t residual; /* data residual length */
478 uint32_t fetd_status; /* trans status, set by FETD,
479 0 = good*/
480 struct scsi_sense_data sense_data; /* sense data */
481};
482
483/*
484 * Used for CTL_MSG_MANAGE_TASKS.
485 */
486struct ctl_ha_msg_task {
487 struct ctl_ha_msg_hdr hdr;
488 ctl_task_type task_action; /* Target Reset, Abort, etc. */
489 uint32_t tag_num; /* tag number */
490 ctl_tag_type tag_type; /* simple, ordered, etc. */
491};
492
493/*
494 * Used for CTL_MSG_PORT_SYNC.
495 */
496struct ctl_ha_msg_port {
497 struct ctl_ha_msg_hdr hdr;
498 int port_type;
499 int physical_port;
500 int virtual_port;
501 int status;
502 int name_len;
503 int lun_map_len;
504 int port_devid_len;
505 int target_devid_len;
506 int init_devid_len;
507 uint8_t data[];
508};
509
510/*
511 * Used for CTL_MSG_LUN_SYNC.
512 */
513struct ctl_ha_msg_lun {
514 struct ctl_ha_msg_hdr hdr;
515 int flags;
516 unsigned int pr_generation;
517 uint32_t pr_res_idx;
518 uint8_t pr_res_type;
519 int lun_devid_len;
520 int pr_key_count;
521 uint8_t data[];
522};
523
524struct ctl_ha_msg_lun_pr_key {
525 uint32_t pr_iid;
526 uint64_t pr_key;
527};
528
529/*
530 * Used for CTL_MSG_IID_SYNC.
531 */
532struct ctl_ha_msg_iid {
533 struct ctl_ha_msg_hdr hdr;
534 int in_use;
535 int name_len;
536 uint64_t wwpn;
537 uint8_t data[];
538};
539
540/*
541 * Used for CTL_MSG_MODE_SYNC.
542 */
543struct ctl_ha_msg_mode {
544 struct ctl_ha_msg_hdr hdr;
545 uint8_t page_code;
546 uint8_t subpage;
547 uint16_t page_len;
548 uint8_t data[];
549};
550
551union ctl_ha_msg {
552 struct ctl_ha_msg_hdr hdr;
553 struct ctl_ha_msg_task task;
554 struct ctl_ha_msg_scsi scsi;
555 struct ctl_ha_msg_dt dt;
556 struct ctl_ha_msg_pr pr;
557 struct ctl_ha_msg_ua ua;
558 struct ctl_ha_msg_port port;
559 struct ctl_ha_msg_lun lun;
560 struct ctl_ha_msg_iid iid;
561 struct ctl_ha_msg_login login;
562 struct ctl_ha_msg_mode mode;
563};
564
565struct ctl_prio {
566 struct ctl_io_hdr io_hdr;
567 struct ctl_ha_msg_pr pr_msg;
568};
569
570union ctl_io {
571 struct ctl_io_hdr io_hdr; /* common to all I/O types */
572 struct ctl_scsiio scsiio; /* Normal SCSI commands */
573 struct ctl_taskio taskio; /* SCSI task management/reset */
574 struct ctl_prio presio; /* update per. res info on other SC */
575};
576
577#ifdef _KERNEL
578
579union ctl_io *ctl_alloc_io(void *pool_ref);
580union ctl_io *ctl_alloc_io_nowait(void *pool_ref);
581void ctl_free_io(union ctl_io *io);
582void ctl_zero_io(union ctl_io *io);
583
584#endif /* _KERNEL */
585
586#endif /* _CTL_IO_H_ */
587
588/*
589 * vim: ts=8
590 */
175#define CTL_INVALID_PORTNAME 0xFF
176#define CTL_UNMAPPED_IID 0xFF
177
178struct ctl_sg_entry {
179 void *addr;
180 size_t len;
181};
182
183typedef enum {
184 CTL_IO_NONE,
185 CTL_IO_SCSI,
186 CTL_IO_TASK,
187} ctl_io_type;
188
189struct ctl_nexus {
190 uint32_t initid; /* Initiator ID */
191 uint32_t targ_port; /* Target port, filled in by PORT */
192 uint32_t targ_lun; /* Destination lun */
193 uint32_t targ_mapped_lun; /* Destination lun CTL-wide */
194};
195
196typedef enum {
197 CTL_MSG_SERIALIZE,
198 CTL_MSG_R2R,
199 CTL_MSG_FINISH_IO,
200 CTL_MSG_BAD_JUJU,
201 CTL_MSG_MANAGE_TASKS,
202 CTL_MSG_PERS_ACTION,
203 CTL_MSG_DATAMOVE,
204 CTL_MSG_DATAMOVE_DONE,
205 CTL_MSG_UA, /* Set/clear UA on secondary. */
206 CTL_MSG_PORT_SYNC, /* Information about port. */
207 CTL_MSG_LUN_SYNC, /* Information about LUN. */
208 CTL_MSG_IID_SYNC, /* Information about initiator. */
209 CTL_MSG_LOGIN, /* Information about HA peer. */
210 CTL_MSG_MODE_SYNC, /* Mode page current content. */
211 CTL_MSG_FAILOVER /* Fake, never sent though the wire */
212} ctl_msg_type;
213
214struct ctl_scsiio;
215
216struct ctl_io_hdr {
217 uint32_t version; /* interface version XXX */
218 ctl_io_type io_type; /* task I/O, SCSI I/O, etc. */
219 ctl_msg_type msg_type;
220 struct ctl_nexus nexus; /* Initiator, port, target, lun */
221 uint32_t iid_indx; /* the index into the iid mapping */
222 uint32_t flags; /* transaction flags */
223 uint32_t status; /* transaction status */
224 uint32_t port_status; /* trans status, set by PORT, 0 = good*/
225 uint32_t timeout; /* timeout in ms */
226 uint32_t retries; /* retry count */
227#ifdef CTL_IO_DELAY
228 struct callout delay_callout;
229#endif /* CTL_IO_DELAY */
230#ifdef CTL_TIME_IO
231 time_t start_time; /* I/O start time */
232 struct bintime start_bt; /* Timer start ticks */
233 struct bintime dma_start_bt; /* DMA start ticks */
234 struct bintime dma_bt; /* DMA total ticks */
235#endif /* CTL_TIME_IO */
236 uint32_t num_dmas; /* Number of DMAs */
237 union ctl_io *original_sc;
238 union ctl_io *serializing_sc;
239 void *pool; /* I/O pool */
240 union ctl_priv ctl_private[CTL_NUM_PRIV];/* CTL private area */
241 struct ctl_sg_entry *remote_sglist;
242 struct ctl_sg_entry *local_sglist;
243 STAILQ_ENTRY(ctl_io_hdr) links; /* linked list pointer */
244 TAILQ_ENTRY(ctl_io_hdr) ooa_links;
245 TAILQ_ENTRY(ctl_io_hdr) blocked_links;
246};
247
248typedef enum {
249 CTL_TAG_UNTAGGED,
250 CTL_TAG_SIMPLE,
251 CTL_TAG_ORDERED,
252 CTL_TAG_HEAD_OF_QUEUE,
253 CTL_TAG_ACA
254} ctl_tag_type;
255
256union ctl_io;
257
258/*
259 * SCSI passthrough I/O structure for the CAM Target Layer. Note
260 * that some of these fields are here for completeness, but they aren't
261 * used in the CTL implementation. e.g., timeout and retries won't be
262 * used.
263 *
264 * Note: Make sure the io_hdr is *always* the first element in this
265 * structure.
266 */
267struct ctl_scsiio {
268 struct ctl_io_hdr io_hdr; /* common to all I/O types */
269
270 /*
271 * The ext_* fields are generally intended for frontend use; CTL itself
272 * doesn't modify or use them.
273 */
274 uint32_t ext_sg_entries; /* 0 = no S/G list, > 0 = num entries */
275 uint8_t *ext_data_ptr; /* data buffer or S/G list */
276 uint32_t ext_data_len; /* Data transfer length */
277 uint32_t ext_data_filled; /* Amount of data filled so far */
278
279 /*
280 * The number of scatter/gather entries in the list pointed to
281 * by kern_data_ptr. 0 means there is no list, just a data pointer.
282 */
283 uint32_t kern_sg_entries;
284
285 uint32_t rem_sg_entries; /* Unused. */
286
287 /*
288 * The data pointer or a pointer to the scatter/gather list.
289 */
290 uint8_t *kern_data_ptr;
291
292 /*
293 * Length of the data buffer or scatter/gather list. It's also
294 * the length of this particular piece of the data transfer,
295 * ie. number of bytes expected to be transferred by the current
296 * invocation of frontend's datamove() callback. It's always
297 * less than or equal to kern_total_len.
298 */
299 uint32_t kern_data_len;
300
301 /*
302 * Total length of data to be transferred during this particular
303 * SCSI command, as decoded from SCSI CDB.
304 */
305 uint32_t kern_total_len;
306
307 /*
308 * Amount of data left after the current data transfer.
309 */
310 uint32_t kern_data_resid;
311
312 /*
313 * Byte offset of this transfer, equal to the amount of data
314 * already transferred for this SCSI command during previous
315 * datamove() invocations.
316 */
317 uint32_t kern_rel_offset;
318
319 struct scsi_sense_data sense_data; /* sense data */
320 uint8_t sense_len; /* Returned sense length */
321 uint8_t scsi_status; /* SCSI status byte */
322 uint8_t sense_residual; /* Unused. */
323 uint32_t residual; /* data residual length */
324 uint32_t tag_num; /* tag number */
325 ctl_tag_type tag_type; /* simple, ordered, head of queue,etc.*/
326 uint8_t cdb_len; /* CDB length */
327 uint8_t cdb[CTL_MAX_CDBLEN]; /* CDB */
328 int (*be_move_done)(union ctl_io *io); /* called by fe */
329 int (*io_cont)(union ctl_io *io); /* to continue processing */
330};
331
332typedef enum {
333 CTL_TASK_ABORT_TASK,
334 CTL_TASK_ABORT_TASK_SET,
335 CTL_TASK_CLEAR_ACA,
336 CTL_TASK_CLEAR_TASK_SET,
337 CTL_TASK_I_T_NEXUS_RESET,
338 CTL_TASK_LUN_RESET,
339 CTL_TASK_TARGET_RESET,
340 CTL_TASK_BUS_RESET,
341 CTL_TASK_PORT_LOGIN,
342 CTL_TASK_PORT_LOGOUT,
343 CTL_TASK_QUERY_TASK,
344 CTL_TASK_QUERY_TASK_SET,
345 CTL_TASK_QUERY_ASYNC_EVENT
346} ctl_task_type;
347
348typedef enum {
349 CTL_TASK_FUNCTION_COMPLETE,
350 CTL_TASK_FUNCTION_SUCCEEDED,
351 CTL_TASK_FUNCTION_REJECTED,
352 CTL_TASK_LUN_DOES_NOT_EXIST,
353 CTL_TASK_FUNCTION_NOT_SUPPORTED
354} ctl_task_status;
355
356/*
357 * Task management I/O structure. Aborts, bus resets, etc., are sent using
358 * this structure.
359 *
360 * Note: Make sure the io_hdr is *always* the first element in this
361 * structure.
362 */
363struct ctl_taskio {
364 struct ctl_io_hdr io_hdr; /* common to all I/O types */
365 ctl_task_type task_action; /* Target Reset, Abort, etc. */
366 uint32_t tag_num; /* tag number */
367 ctl_tag_type tag_type; /* simple, ordered, etc. */
368 uint8_t task_status; /* Complete, Succeeded, etc. */
369 uint8_t task_resp[3];/* Response information */
370};
371
372
373/*
374 * HA link messages.
375 */
376#define CTL_HA_VERSION 2
377
378/*
379 * Used for CTL_MSG_LOGIN.
380 */
381struct ctl_ha_msg_login {
382 ctl_msg_type msg_type;
383 int version;
384 int ha_mode;
385 int ha_id;
386 int max_luns;
387 int max_ports;
388 int max_init_per_port;
389};
390
391typedef enum {
392 CTL_PR_REG_KEY,
393 CTL_PR_UNREG_KEY,
394 CTL_PR_PREEMPT,
395 CTL_PR_CLEAR,
396 CTL_PR_RESERVE,
397 CTL_PR_RELEASE
398} ctl_pr_action;
399
400/*
401 * The PR info is specifically for sending Persistent Reserve actions
402 * to the other SC which it must also act on.
403 *
404 * Note: Make sure the io_hdr is *always* the first element in this
405 * structure.
406 */
407struct ctl_pr_info {
408 ctl_pr_action action;
409 uint8_t sa_res_key[8];
410 uint8_t res_type;
411 uint32_t residx;
412};
413
414struct ctl_ha_msg_hdr {
415 ctl_msg_type msg_type;
416 uint32_t status; /* transaction status */
417 union ctl_io *original_sc;
418 union ctl_io *serializing_sc;
419 struct ctl_nexus nexus; /* Initiator, port, target, lun */
420};
421
422#define CTL_HA_MAX_SG_ENTRIES 16
423#define CTL_HA_DATAMOVE_SEGMENT 131072
424
425/*
426 * Used for CTL_MSG_PERS_ACTION.
427 */
428struct ctl_ha_msg_pr {
429 struct ctl_ha_msg_hdr hdr;
430 struct ctl_pr_info pr_info;
431};
432
433/*
434 * Used for CTL_MSG_UA.
435 */
436struct ctl_ha_msg_ua {
437 struct ctl_ha_msg_hdr hdr;
438 int ua_all;
439 int ua_set;
440 int ua_type;
441 uint8_t ua_info[8];
442};
443
444/*
445 * The S/G handling here is a little different than the standard ctl_scsiio
446 * structure, because we can't pass data by reference in between controllers.
447 * The S/G list in the ctl_scsiio struct is normally passed in the
448 * kern_data_ptr field. So kern_sg_entries here will always be non-zero,
449 * even if there is only one entry.
450 *
451 * Used for CTL_MSG_DATAMOVE.
452 */
453struct ctl_ha_msg_dt {
454 struct ctl_ha_msg_hdr hdr;
455 ctl_io_flags flags; /* Only I/O flags are used here */
456 uint32_t sg_sequence; /* S/G portion number */
457 uint8_t sg_last; /* last S/G batch = 1 */
458 uint32_t sent_sg_entries; /* previous S/G count */
459 uint32_t cur_sg_entries; /* current S/G entries */
460 uint32_t kern_sg_entries; /* total S/G entries */
461 uint32_t kern_data_len; /* Length of this S/G list */
462 uint32_t kern_total_len; /* Total length of this
463 transaction */
464 uint32_t kern_data_resid; /* Length left to transfer
465 after this*/
466 uint32_t kern_rel_offset; /* Byte Offset of this
467 transfer */
468 struct ctl_sg_entry sg_list[CTL_HA_MAX_SG_ENTRIES];
469};
470
471/*
472 * Used for CTL_MSG_SERIALIZE, CTL_MSG_FINISH_IO, CTL_MSG_BAD_JUJU.
473 */
474struct ctl_ha_msg_scsi {
475 struct ctl_ha_msg_hdr hdr;
476 uint32_t tag_num; /* tag number */
477 ctl_tag_type tag_type; /* simple, ordered, etc. */
478 uint8_t cdb[CTL_MAX_CDBLEN]; /* CDB */
479 uint8_t cdb_len; /* CDB length */
480 uint8_t scsi_status; /* SCSI status byte */
481 uint8_t sense_len; /* Returned sense length */
482 uint8_t sense_residual; /* sense residual length */
483 uint32_t residual; /* data residual length */
484 uint32_t fetd_status; /* trans status, set by FETD,
485 0 = good*/
486 struct scsi_sense_data sense_data; /* sense data */
487};
488
489/*
490 * Used for CTL_MSG_MANAGE_TASKS.
491 */
492struct ctl_ha_msg_task {
493 struct ctl_ha_msg_hdr hdr;
494 ctl_task_type task_action; /* Target Reset, Abort, etc. */
495 uint32_t tag_num; /* tag number */
496 ctl_tag_type tag_type; /* simple, ordered, etc. */
497};
498
499/*
500 * Used for CTL_MSG_PORT_SYNC.
501 */
502struct ctl_ha_msg_port {
503 struct ctl_ha_msg_hdr hdr;
504 int port_type;
505 int physical_port;
506 int virtual_port;
507 int status;
508 int name_len;
509 int lun_map_len;
510 int port_devid_len;
511 int target_devid_len;
512 int init_devid_len;
513 uint8_t data[];
514};
515
516/*
517 * Used for CTL_MSG_LUN_SYNC.
518 */
519struct ctl_ha_msg_lun {
520 struct ctl_ha_msg_hdr hdr;
521 int flags;
522 unsigned int pr_generation;
523 uint32_t pr_res_idx;
524 uint8_t pr_res_type;
525 int lun_devid_len;
526 int pr_key_count;
527 uint8_t data[];
528};
529
530struct ctl_ha_msg_lun_pr_key {
531 uint32_t pr_iid;
532 uint64_t pr_key;
533};
534
535/*
536 * Used for CTL_MSG_IID_SYNC.
537 */
538struct ctl_ha_msg_iid {
539 struct ctl_ha_msg_hdr hdr;
540 int in_use;
541 int name_len;
542 uint64_t wwpn;
543 uint8_t data[];
544};
545
546/*
547 * Used for CTL_MSG_MODE_SYNC.
548 */
549struct ctl_ha_msg_mode {
550 struct ctl_ha_msg_hdr hdr;
551 uint8_t page_code;
552 uint8_t subpage;
553 uint16_t page_len;
554 uint8_t data[];
555};
556
557union ctl_ha_msg {
558 struct ctl_ha_msg_hdr hdr;
559 struct ctl_ha_msg_task task;
560 struct ctl_ha_msg_scsi scsi;
561 struct ctl_ha_msg_dt dt;
562 struct ctl_ha_msg_pr pr;
563 struct ctl_ha_msg_ua ua;
564 struct ctl_ha_msg_port port;
565 struct ctl_ha_msg_lun lun;
566 struct ctl_ha_msg_iid iid;
567 struct ctl_ha_msg_login login;
568 struct ctl_ha_msg_mode mode;
569};
570
571struct ctl_prio {
572 struct ctl_io_hdr io_hdr;
573 struct ctl_ha_msg_pr pr_msg;
574};
575
576union ctl_io {
577 struct ctl_io_hdr io_hdr; /* common to all I/O types */
578 struct ctl_scsiio scsiio; /* Normal SCSI commands */
579 struct ctl_taskio taskio; /* SCSI task management/reset */
580 struct ctl_prio presio; /* update per. res info on other SC */
581};
582
583#ifdef _KERNEL
584
585union ctl_io *ctl_alloc_io(void *pool_ref);
586union ctl_io *ctl_alloc_io_nowait(void *pool_ref);
587void ctl_free_io(union ctl_io *io);
588void ctl_zero_io(union ctl_io *io);
589
590#endif /* _KERNEL */
591
592#endif /* _CTL_IO_H_ */
593
594/*
595 * vim: ts=8
596 */