]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - sys/cam/ctl/ctl_io.h
MFC r268808:
[FreeBSD/stable/10.git] / sys / cam / ctl / ctl_io.h
1 /*-
2  * Copyright (c) 2003 Silicon Graphics International Corp.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions, and the following disclaimer,
10  *    without modification.
11  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12  *    substantially similar to the "NO WARRANTY" disclaimer below
13  *    ("Disclaimer") and any redistribution must be conditioned upon
14  *    including a substantially similar Disclaimer requirement for further
15  *    binary redistribution.
16  *
17  * NO WARRANTY
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGES.
29  *
30  * $Id: //depot/users/kenm/FreeBSD-test2/sys/cam/ctl/ctl_io.h#5 $
31  * $FreeBSD$
32  */
33 /*
34  * CAM Target Layer data movement structures/interface.
35  *
36  * Author: Ken Merry <ken@FreeBSD.org>
37  */
38
39 #ifndef _CTL_IO_H_
40 #define _CTL_IO_H_
41
42 #ifdef _CTL_C
43 #define EXTERN(__var,__val) __var = __val
44 #else
45 #define EXTERN(__var,__val) extern __var
46 #endif
47
48 #define CTL_MAX_CDBLEN  32
49 /*
50  * Uncomment this next line to enable printing out times for I/Os
51  * that take longer than CTL_TIME_IO_SECS seconds to get to the datamove
52  * and/or done stage.
53  */
54 #define CTL_TIME_IO
55 #ifdef  CTL_TIME_IO
56 #define CTL_TIME_IO_DEFAULT_SECS        90
57 EXTERN(int ctl_time_io_secs, CTL_TIME_IO_DEFAULT_SECS);
58 #endif
59
60 /*
61  * Uncomment these next two lines to enable the CTL I/O delay feature.  You
62  * can delay I/O at two different points -- datamove and done.  This is
63  * useful for diagnosing abort conditions (for hosts that send an abort on a
64  * timeout), and for determining how long a host's timeout is.
65  */
66 #define CTL_IO_DELAY
67 #define CTL_TIMER_BYTES         sizeof(struct callout)
68
69 typedef 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 conjuction with ctl_cmd_flags.  See comment above ctl_cmd_flags
84  * definition in ctl_private.h.
85  */
86 typedef 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_KDPTR_SGLIST   = 0x00000008,   /* kern_data_ptr is S/G list*/
93         CTL_FLAG_EDPTR_SGLIST   = 0x00000010,   /* ext_data_ptr is S/G list */
94         CTL_FLAG_DO_AUTOSENSE   = 0x00000020,   /* grab sense info */
95         CTL_FLAG_USER_REQ       = 0x00000040,   /* request came from userland */
96         CTL_FLAG_CONTROL_DEV    = 0x00000080,   /* processor device */
97         CTL_FLAG_ALLOCATED      = 0x00000100,   /* data space allocated */
98         CTL_FLAG_BLOCKED        = 0x00000200,   /* on the blocked queue */
99         CTL_FLAG_ABORT_STATUS   = 0x00000400,   /* return TASK ABORTED status */
100         CTL_FLAG_ABORT          = 0x00000800,   /* this I/O should be aborted */
101         CTL_FLAG_DMA_INPROG     = 0x00001000,   /* DMA in progress */
102         CTL_FLAG_NO_DATASYNC    = 0x00002000,   /* don't cache flush data */
103         CTL_FLAG_DELAY_DONE     = 0x00004000,   /* delay injection done */
104         CTL_FLAG_INT_COPY       = 0x00008000,   /* internal copy, no done call*/
105         CTL_FLAG_SENT_2OTHER_SC = 0x00010000,
106         CTL_FLAG_FROM_OTHER_SC  = 0x00020000,
107         CTL_FLAG_IS_WAS_ON_RTR  = 0x00040000,   /* Don't rerun cmd on failover*/
108         CTL_FLAG_BUS_ADDR       = 0x00080000,   /* ctl_sglist contains BUS
109                                                    addresses, not virtual ones*/
110         CTL_FLAG_IO_CONT        = 0x00100000,   /* Continue I/O instead of
111                                                    completing */
112         CTL_FLAG_AUTO_MIRROR    = 0x00200000,   /* Automatically use memory
113                                                    from the RC cache mirrored
114                                                    address area. */
115 #if 0
116         CTL_FLAG_ALREADY_DONE   = 0x00200000    /* I/O already completed */
117 #endif
118         CTL_FLAG_NO_DATAMOVE    = 0x00400000,
119         CTL_FLAG_DMA_QUEUED     = 0x00800000,   /* DMA queued but not started*/
120         CTL_FLAG_STATUS_QUEUED  = 0x01000000,   /* Status queued but not sent*/
121
122         CTL_FLAG_REDIR_DONE     = 0x02000000,   /* Redirection has already
123                                                    been done. */
124         CTL_FLAG_FAILOVER       = 0x04000000,   /* Killed by a failover */
125         CTL_FLAG_IO_ACTIVE      = 0x08000000,   /* I/O active on this SC */
126         CTL_FLAG_RDMA_MASK      = CTL_FLAG_NO_DATASYNC | CTL_FLAG_BUS_ADDR |
127                                   CTL_FLAG_AUTO_MIRROR | CTL_FLAG_REDIR_DONE
128                                                 /* Flags we care about for
129                                                    remote DMA */
130 } ctl_io_flags;
131
132
133 struct ctl_lba_len {
134         uint64_t lba;
135         uint32_t len;
136 };
137
138 struct ctl_lba_len_flags {
139         uint64_t lba;
140         uint32_t len;
141         uint32_t flags;
142 #define CTL_LLF_READ    0x10000000
143 #define CTL_LLF_WRITE   0x20000000
144 #define CTL_LLF_VERIFY  0x40000000
145 #define CTL_LLF_COMPARE 0x80000000
146 };
147
148 struct ctl_ptr_len_flags {
149         uint8_t *ptr;
150         uint32_t len;
151         uint32_t flags;
152 };
153
154 union ctl_priv {
155         uint8_t         bytes[sizeof(uint64_t) * 2];
156         uint64_t        integer;
157         void            *ptr;
158 };
159
160 /*
161  * Number of CTL private areas.
162  */
163 #define CTL_NUM_PRIV    6
164
165 /*
166  * Which private area are we using for a particular piece of data?
167  */
168 #define CTL_PRIV_LUN            0       /* CTL LUN pointer goes here */
169 #define CTL_PRIV_LBA_LEN        1       /* Decoded LBA/len for read/write*/
170 #define CTL_PRIV_MODEPAGE       1       /* Modepage info for config write */
171 #define CTL_PRIV_BACKEND        2       /* Reserved for block, RAIDCore */
172 #define CTL_PRIV_BACKEND_LUN    3       /* Backend LUN pointer */
173 #define CTL_PRIV_FRONTEND       4       /* LSI driver, ioctl front end */
174 #define CTL_PRIV_USER           5       /* Userland use */
175
176 #define CTL_INVALID_PORTNAME 0xFF
177 #define CTL_UNMAPPED_IID     0xFF
178 /*
179  * XXX KDM this size is for the port_priv variable in struct ctl_io_hdr
180  * below.  This should be defined in terms of the size of struct
181  * ctlfe_lun_cmd_info at the moment:
182  * struct ctlfe_lun_cmd_info {
183  *      int cur_transfer_index;
184  *      ctlfe_cmd_flags flags;
185  *      bus_dma_segment_t cam_sglist[32];
186  * };
187  *
188  * This isn't really the way I'd prefer to do it, but it does make some
189  * sense, AS LONG AS we can guarantee that there will always only be one
190  * outstanding DMA request per ctl_io.  If that assumption isn't valid,
191  * then we've got problems.
192  *
193  * At some point it may be nice switch CTL over to using CCBs for
194  * everything.  At that point we can probably use the ATIO/CTIO model, so
195  * that multiple simultaneous DMAs per command will just work.
196  *
197  * Also note that the current size, 600, is appropriate for 64-bit
198  * architectures, but is overkill for 32-bit architectures.  Need a way to
199  * figure out the size at compile time, or just get rid of this altogether.
200  */
201 #define CTL_PORT_PRIV_SIZE      600
202
203 struct ctl_sg_entry {
204         void    *addr;
205         size_t  len;
206 };
207
208 struct ctl_id {
209         uint32_t                id;
210         uint64_t                wwid[2];
211 };
212
213 typedef enum {
214         CTL_IO_NONE,
215         CTL_IO_SCSI,
216         CTL_IO_TASK,
217 } ctl_io_type;
218
219 struct ctl_nexus {
220         struct ctl_id initid;           /* Initiator ID */
221         uint32_t targ_port;             /* Target port, filled in by PORT */
222         struct ctl_id targ_target;      /* Destination target */
223         uint32_t targ_lun;              /* Destination lun */
224         uint32_t targ_mapped_lun;       /* Destination lun CTL-wide */
225 };
226
227 typedef enum {
228         CTL_MSG_SERIALIZE,
229         CTL_MSG_R2R,
230         CTL_MSG_FINISH_IO,
231         CTL_MSG_BAD_JUJU,
232         CTL_MSG_MANAGE_TASKS,
233         CTL_MSG_PERS_ACTION,
234         CTL_MSG_SYNC_FE,
235         CTL_MSG_APS_LOCK,
236         CTL_MSG_DATAMOVE,
237         CTL_MSG_DATAMOVE_DONE
238 } ctl_msg_type;
239
240 struct ctl_scsiio;
241
242 #define CTL_NUM_SG_ENTRIES      9
243
244 struct ctl_io_hdr {
245         uint32_t          version;      /* interface version XXX */
246         ctl_io_type       io_type;      /* task I/O, SCSI I/O, etc. */
247         ctl_msg_type      msg_type;
248         struct ctl_nexus  nexus;        /* Initiator, port, target, lun */
249         uint32_t          iid_indx;     /* the index into the iid mapping */
250         uint32_t          flags;        /* transaction flags */
251         uint32_t          status;       /* transaction status */
252         uint32_t          port_status;  /* trans status, set by PORT, 0 = good*/
253         uint32_t          timeout;      /* timeout in ms */
254         uint32_t          retries;      /* retry count */
255 #ifdef CTL_IO_DELAY
256         uint8_t           timer_bytes[CTL_TIMER_BYTES]; /* timer kludge */
257 #endif /* CTL_IO_DELAY */
258 #ifdef CTL_TIME_IO
259         time_t            start_time;   /* I/O start time */
260         struct bintime    start_bt;     /* Timer start ticks */
261         struct bintime    dma_start_bt; /* DMA start ticks */
262         struct bintime    dma_bt;       /* DMA total ticks */
263         uint32_t          num_dmas;     /* Number of DMAs */
264 #endif /* CTL_TIME_IO */
265         union ctl_io      *original_sc;
266         union ctl_io      *serializing_sc;
267         void              *pool;        /* I/O pool */
268         union ctl_priv    ctl_private[CTL_NUM_PRIV];/* CTL private area */
269         uint8_t           port_priv[CTL_PORT_PRIV_SIZE];/* PORT private area*/
270         struct ctl_sg_entry remote_sglist[CTL_NUM_SG_ENTRIES];
271         struct ctl_sg_entry remote_dma_sglist[CTL_NUM_SG_ENTRIES];
272         struct ctl_sg_entry local_sglist[CTL_NUM_SG_ENTRIES];
273         struct ctl_sg_entry local_dma_sglist[CTL_NUM_SG_ENTRIES];
274         STAILQ_ENTRY(ctl_io_hdr) links; /* linked list pointer */
275         TAILQ_ENTRY(ctl_io_hdr) ooa_links;
276         TAILQ_ENTRY(ctl_io_hdr) blocked_links;
277 };
278
279 typedef enum {
280         CTL_TAG_UNTAGGED,
281         CTL_TAG_SIMPLE,
282         CTL_TAG_ORDERED,
283         CTL_TAG_HEAD_OF_QUEUE,
284         CTL_TAG_ACA
285 } ctl_tag_type;
286
287 union ctl_io;
288
289 /*
290  * SCSI passthrough I/O structure for the CAM Target Layer.  Note
291  * that some of these fields are here for completeness, but they aren't
292  * used in the CTL implementation.  e.g., timeout and retries won't be
293  * used.
294  *
295  * Note:  Make sure the io_hdr is *always* the first element in this
296  * structure.
297  */
298 struct ctl_scsiio {
299         struct ctl_io_hdr io_hdr;       /* common to all I/O types */
300
301         /*
302          * The ext_* fields are generally intended for frontend use; CTL itself
303          * doesn't modify or use them.
304          */
305         uint32_t   ext_sg_entries;      /* 0 = no S/G list, > 0 = num entries */
306         uint8_t    *ext_data_ptr;       /* data buffer or S/G list */
307         uint32_t   ext_data_len;        /* Data transfer length */
308         uint32_t   ext_data_filled;     /* Amount of data filled so far */
309
310         /*
311          * The number of scatter/gather entries in the list pointed to
312          * by kern_data_ptr.  0 means there is no list, just a data pointer.
313          */
314         uint32_t   kern_sg_entries;
315
316         uint32_t   rem_sg_entries;      /* Unused. */
317
318         /*
319          * The data pointer or a pointer to the scatter/gather list.
320          */
321         uint8_t    *kern_data_ptr;
322
323         /*
324          * Length of the data buffer or scatter/gather list.  It's also
325          * the length of this particular piece of the data transfer,
326          * ie. number of bytes expected to be transferred by the current
327          * invocation of frontend's datamove() callback.  It's always
328          * less than or equal to kern_total_len.
329          */
330         uint32_t   kern_data_len;
331
332         /*
333          * Total length of data to be transferred during this particular
334          * SCSI command, as decoded from SCSI CDB.
335          */
336         uint32_t   kern_total_len;
337
338         /*
339          * Amount of data left after the current data transfer.
340          */
341         uint32_t   kern_data_resid;
342
343         /*
344          * Byte offset of this transfer, equal to the amount of data
345          * already transferred for this SCSI command during previous
346          * datamove() invocations.
347          */
348         uint32_t   kern_rel_offset;
349
350         struct     scsi_sense_data sense_data;  /* sense data */
351         uint8_t    sense_len;           /* Returned sense length */
352         uint8_t    scsi_status;         /* SCSI status byte */
353         uint8_t    sense_residual;      /* Unused. */
354         uint32_t   residual;            /* data residual length */
355         uint32_t   tag_num;             /* tag number */
356         ctl_tag_type tag_type;          /* simple, ordered, head of queue,etc.*/
357         uint8_t    cdb_len;             /* CDB length */
358         uint8_t    cdb[CTL_MAX_CDBLEN]; /* CDB */
359         int        (*be_move_done)(union ctl_io *io); /* called by fe */
360         int        (*io_cont)(union ctl_io *io); /* to continue processing */
361 };
362
363 typedef enum {
364         CTL_TASK_ABORT_TASK,
365         CTL_TASK_ABORT_TASK_SET,
366         CTL_TASK_CLEAR_ACA,
367         CTL_TASK_CLEAR_TASK_SET,
368         CTL_TASK_I_T_NEXUS_RESET,
369         CTL_TASK_LUN_RESET,
370         CTL_TASK_TARGET_RESET,
371         CTL_TASK_BUS_RESET,
372         CTL_TASK_PORT_LOGIN,
373         CTL_TASK_PORT_LOGOUT
374 } ctl_task_type;
375
376 /*
377  * Task management I/O structure.  Aborts, bus resets, etc., are sent using
378  * this structure.
379  *
380  * Note:  Make sure the io_hdr is *always* the first element in this
381  * structure.
382  */
383 struct ctl_taskio {
384         struct ctl_io_hdr       io_hdr;      /* common to all I/O types */
385         ctl_task_type           task_action; /* Target Reset, Abort, etc.  */
386         uint32_t                tag_num;     /* tag number */
387         ctl_tag_type            tag_type;    /* simple, ordered, etc. */
388 };
389
390 typedef enum {
391         CTL_PR_REG_KEY,
392         CTL_PR_UNREG_KEY,
393         CTL_PR_PREEMPT,
394         CTL_PR_CLEAR,
395         CTL_PR_RESERVE,
396         CTL_PR_RELEASE
397 } ctl_pr_action;
398
399 /*
400  * The PR info is specifically for sending Persistent Reserve actions
401  * to the other SC which it must also act on.
402  *
403  * Note:  Make sure the io_hdr is *always* the first element in this
404  * structure.
405  */
406 struct ctl_pr_info {
407         ctl_pr_action        action;
408         uint8_t              sa_res_key[8];
409         uint8_t              res_type;
410         uint32_t             residx;
411 };
412
413 struct ctl_ha_msg_hdr {
414         ctl_msg_type            msg_type;
415         union ctl_io            *original_sc;
416         union ctl_io            *serializing_sc;
417         struct ctl_nexus        nexus;       /* Initiator, port, target, lun */
418         uint32_t                status;      /* transaction status */
419         TAILQ_ENTRY(ctl_ha_msg_hdr) links;
420 };
421
422 #define CTL_HA_MAX_SG_ENTRIES   16
423
424 /*
425  * Used for CTL_MSG_APS_LOCK.
426  */
427 struct ctl_ha_msg_aps {
428         struct ctl_ha_msg_hdr   hdr;
429         uint8_t                 lock_flag;
430 };
431
432 /*
433  * Used for CTL_MSG_PERS_ACTION.
434  */
435 struct ctl_ha_msg_pr {
436         struct ctl_ha_msg_hdr   hdr;
437         struct ctl_pr_info      pr_info;
438 };
439
440 /*
441  * The S/G handling here is a little different than the standard ctl_scsiio
442  * structure, because we can't pass data by reference in between controllers.
443  * The S/G list in the ctl_scsiio struct is normally passed in the
444  * kern_data_ptr field.  So kern_sg_entries here will always be non-zero,
445  * even if there is only one entry.
446  *
447  * Used for CTL_MSG_DATAMOVE.
448  */
449 struct ctl_ha_msg_dt {
450         struct ctl_ha_msg_hdr   hdr;
451         ctl_io_flags            flags;  /* Only I/O flags are used here */
452         uint32_t                sg_sequence;     /* S/G portion number  */
453         uint8_t                 sg_last;         /* last S/G batch = 1 */
454         uint32_t                sent_sg_entries; /* previous S/G count */
455         uint32_t                cur_sg_entries;  /* current S/G entries */
456         uint32_t                kern_sg_entries; /* total S/G entries */
457         uint32_t                kern_data_len;   /* Length of this S/G list */
458         uint32_t                kern_total_len;  /* Total length of this
459                                                     transaction */
460         uint32_t                kern_data_resid; /* Length left to transfer
461                                                     after this*/
462         uint32_t                kern_rel_offset; /* Byte Offset of this
463                                                     transfer */
464         struct ctl_sg_entry     sg_list[CTL_HA_MAX_SG_ENTRIES];
465 };
466
467 /*
468  * Used for CTL_MSG_SERIALIZE, CTL_MSG_FINISH_IO, CTL_MSG_BAD_JUJU.
469  */
470 struct ctl_ha_msg_scsi {
471         struct ctl_ha_msg_hdr   hdr;
472         uint8_t                 cdb[CTL_MAX_CDBLEN];    /* CDB */
473         uint32_t                tag_num;     /* tag number */
474         ctl_tag_type            tag_type;    /* simple, ordered, etc. */
475         uint8_t                 scsi_status; /* SCSI status byte */
476         struct scsi_sense_data  sense_data;  /* sense data */
477         uint8_t                 sense_len;   /* Returned sense length */
478         uint8_t                 sense_residual; /* sense residual length */
479         uint32_t                residual;    /* data residual length */
480         uint32_t                fetd_status; /* trans status, set by FETD,
481                                                 0 = good*/
482         struct ctl_lba_len      lbalen;      /* used for stats */
483 };
484
485 /* 
486  * Used for CTL_MSG_MANAGE_TASKS.
487  */
488 struct ctl_ha_msg_task {
489         struct ctl_ha_msg_hdr   hdr;
490         ctl_task_type           task_action; /* Target Reset, Abort, etc.  */
491         uint32_t                tag_num;     /* tag number */
492         ctl_tag_type            tag_type;    /* simple, ordered, etc. */
493 };
494
495 union ctl_ha_msg {
496         struct ctl_ha_msg_hdr   hdr;
497         struct ctl_ha_msg_task  task;
498         struct ctl_ha_msg_scsi  scsi;
499         struct ctl_ha_msg_dt    dt;
500         struct ctl_ha_msg_pr    pr;
501         struct ctl_ha_msg_aps   aps;
502 };
503
504
505 struct ctl_prio {
506         struct ctl_io_hdr  io_hdr;
507         struct ctl_ha_msg_pr pr_msg;
508 };
509
510
511
512 union ctl_io {
513         struct ctl_io_hdr io_hdr;       /* common to all I/O types */
514         struct ctl_scsiio scsiio;       /* Normal SCSI commands */
515         struct ctl_taskio taskio;       /* SCSI task management/reset */
516         struct ctl_prio   presio;       /* update per. res info on other SC */
517 };
518
519 #ifdef _KERNEL
520
521 union ctl_io *ctl_alloc_io(void *pool_ref);
522 void ctl_free_io(union ctl_io *io);
523 void ctl_zero_io(union ctl_io *io);
524 void ctl_copy_io(union ctl_io *src, union ctl_io *dest);
525
526 #endif /* _KERNEL */
527
528 #endif  /* _CTL_IO_H_ */
529
530 /*
531  * vim: ts=8
532  */