Emulex Logo
OneCoreā„¢ Storage SDK Release 11.2
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ocs_scsi_tgt.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2015, Emulex
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 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  */
32 
33 /**
34  * @file
35  * Declares the target specific structures required by the base driver
36  */
37 
38 #if !defined(__OCS_SCSI_TGT_H__)
39 #define __OCS_SCSI_TGT_H__
40 
41 #define OCS_INCLUDE_RAMD
42 
43 #include "ocs_scsi.h"
44 #include "ocs_ramdisc.h"
45 #include "ocs_ramd_thread.h"
46 
47 /**
48  * @brief target private ocs structure
49  */
50 
51 typedef struct {
52  uint32_t max_sge;
53  uint32_t max_sgl;
54 
55  /*
56  * Variables used to send task set full. We are using a high watermark
57  * method to send task set full. We will reserve a fixed number of IOs
58  * per initiator plus a fudge factor. Once we reach this number,
59  * then the target will start sending task set full/busy responses.
60  */
61  ocs_atomic_t initiator_count; /**< count of initiators */
62  uint32_t enable_task_set_full; /**< enable generation of task set full */
63  ocs_atomic_t io_high_watermark; /**< used to send task set full */
64  ocs_atomic_t watermark_hit; /**< used to track how often IO pool almost empty */
65  int32_t watermark_min; /**< lower limit for watermark */
66  int32_t watermark_max; /**< upper limit for watermark */
67 
68  /* RAM disk */
69  uint8_t use_global_ramd; /**< flag to allocate globally or on sport */
70  ocs_ramdisc_t **rdisc; /**< pointer to array of ramdisc instances, one per LUN */
71  uint32_t rdisc_count; /**< count of ramdisc instances */
72 
73  ocs_list_t port_rdisc_head;
75 
76 /**
77  * @brief target private domain structure
78  */
79 
80 typedef struct {
81  /* ocs_ramd decls */
82  ;
84 
85 /**
86  * @brief target private sport structure
87  */
88 
89 typedef struct {
90  /* ocs_ramd decls - Used when allocating ramdisk on sport instead of globally */
91  ocs_ramdisc_t **rdisc; /**< pointer to array of ramdisc instances, one per LUN */
92  uint32_t rdisc_count; /**< count of ramdisc instances */
94 
95 /**
96  * @brief ocs_ramdisc_ua_t represents a single UNIT ATTENTION condition
97  */
98 
99 typedef struct ocs_ramdisc_ua_s {
100  uint8_t asc;
101  uint8_t ascq;
104 
105 /**
106  * @brief ocs_ramdisc_ua_t is a collection of UNIT ATTENTION conditions
107  *
108  * SAM 5.14 refers to this as a "queue of unit attention conditions of
109  * unspecified order" but there's no reason it needs to be
110  * a queue. In this implementation it will be a list
111  */
112 typedef struct ocs_ramdisc_ua_queue_s {
113  ocs_lock_t ua_queue_lock;
114  uint32_t num_entries;
115  ocs_list_t entry_list;
117 
118 
119 /**
120  * @brief target private node structure
121  *
122  * This structure holds information that relates to a node (I_T nexus)
123  * that is owned and used by the target.
124  *
125  * ua_queues is a dynamically allocated list of ocs_ramdisc_ua_queue_t
126  * The list is allocated by ocs_scsi_new_initiator when a new initiator
127  * is discovered. There is a one ua_queue for each LUN
128  */
129 
130 typedef struct {
131  uint32_t num_ua_queues;
134 
135 /**
136  * @brief target private IO structure
137  */
138 
139 typedef struct {
140  /* save input arguments */
141  uint32_t flags; /**< flags */
142  ocs_dma_t *first_burst_buffers; /**< array of DMA first burst buffers */
143  void *pcmd; /**< pointer to scsi_cmd_table_t */
144  uint8_t has_first_burst; /**< flag indicating that command has first burst */
145  uint8_t cdb[OCS_SCSI_MAX_CDB_LEN]; /**< CDB */
146  uint32_t cdb_len; /**< length of CDB */
147 
148  uint64_t io_lba; /**< The starting LBA */
149  uint32_t first_burst_bytes; /**< Number of bytes in first burst */
150  ocs_scsi_dif_info_t dif_info; /**< DIF information */
151 
152  uint8_t mode_select_opcode; /**< Mode select command opcode */
153 
154  /* Deferred status send when waiting for first burst to complete*/
155  uint8_t send_task_set_full:1, /**< if TRUE, then send task set full status after first burst */
156  send_check_cond:1; /**< if TRUE, then send check condition response after first burst */
157  uint8_t send_sense_key; /**< response sense key if send_check_cond */
158  uint8_t send_asc; /**< response asc if send_check_cond */
159  uint8_t send_ascq; /**< response ascq if send_check_cond */
160 
161  /* target server */
162  uint32_t lun; /**< LUN */
163  ocs_ramdisc_t *ramdisc; /**< Pointer to ramdisc object */
164  uint8_t lun_is_valid; /**< flag indicating that the LUN value is valid */
165 
166  uint8_t is_read; /**< flag to identify reads */
167 
168  /* Block command variables */
169  uint32_t io_block_count; /**< request IO size in blocks */
170  uint32_t acc_block_count; /**< accumulated block count, updated after successful dataphase */
171  uint64_t cur_lba; /**< current dataphase LBA */
172  uint32_t cur_block_count; /**< current dataphase block count */
173  uint32_t sgl_phys:1; /**< if set, then build phys SGL (data+DIF) */
174 
175  ocs_dma_t payload; /**< payload for commands that need it */
176  uint8_t supress_auto_response; /**< disable auto response if true */
177 
178  /* Values saved from the CDB for the FORMAT UNIT commands */
179  uint8_t fmtpinfo; /**< FMTPINFO value */
180 
181  /* Values saved from the CDB for the WRITE SAME commands */
182  uint8_t pbdata; /**< PBDATA flag */
183  uint8_t lbdata; /**< LBDATA flag */
184  uint8_t wrprotect; /**< WRPROTECT value */
185  uint32_t num_blocks; /**< NUMBER OF LOCICAL BLOCKS value */
186 
187  /* Abort Task */
188  ocs_io_t *tmfio; /**< Pointer to the TMF IO object for an abort task */
189 
190  ocs_lock_t sm_lock; /**< SM lock, to serialize execution while in multi-threaded environment */
191  ocs_sm_ctx_t sm; /**< SCSI ramdisc I/O state machine context */
192  uint8_t current_state; /**< current state of IO state machine */
193 
196 
197 #endif /* __OCS_SCSI_TGT_H__ */
uint8_t mode_select_opcode
Definition: ocs_scsi_tgt.h:152
target private IO structure
Definition: ocs_scsi_tgt.h:139
target private ocs structure
Definition: ocs_scsi_tgt.h:51
ocs_list_t ocs_list_link_t
Definition: ocs_list.h:84
ocs_list_link_t link
Definition: ocs_scsi_tgt.h:102
uint32_t acc_block_count
Definition: ocs_scsi_tgt.h:170
T10 DIF information passed to the transport.
Definition: ocs_scsi.h:229
int32_t watermark_max
Definition: ocs_scsi_tgt.h:66
target private node structure
Definition: ocs_scsi_tgt.h:130
ocs_ramdisc_t ** rdisc
Definition: ocs_scsi_tgt.h:70
ocs_ramdisc_ua_t is a collection of UNIT ATTENTION conditions
Definition: ocs_scsi_tgt.h:112
uint32_t io_block_count
Definition: ocs_scsi_tgt.h:169
target private domain structure
Definition: ocs_scsi_tgt.h:80
target private sport structure
Definition: ocs_scsi_tgt.h:89
ocs_io_t * tmfio
Definition: ocs_scsi_tgt.h:188
uint32_t rdisc_count
Definition: ocs_scsi_tgt.h:71
ocs_ramd_thread_t * thr
Definition: ocs_scsi_tgt.h:194
uint8_t has_first_burst
Definition: ocs_scsi_tgt.h:144
#define OCS_SCSI_MAX_CDB_LEN
Definition: ocs_scsi.h:62
ramdisc instance structure
Definition: ocs_ramdisc.h:88
uint32_t enable_task_set_full
Definition: ocs_scsi_tgt.h:62
uint32_t max_sgl
Definition: ocs_scsi_tgt.h:53
uint8_t send_sense_key
Definition: ocs_scsi_tgt.h:157
ocs_ramdisc_t * ramdisc
Definition: ocs_scsi_tgt.h:163
ocs_ramdisc_ua_queue_t * ua_queues
Definition: ocs_scsi_tgt.h:132
uint32_t cur_block_count
Definition: ocs_scsi_tgt.h:172
uint8_t use_global_ramd
Definition: ocs_scsi_tgt.h:69
ocs_sm_ctx_t sm
Definition: ocs_scsi_tgt.h:191
ocs_scsi_dif_info_t dif_info
Definition: ocs_scsi_tgt.h:150
ocs_ramdisc_t ** rdisc
Definition: ocs_scsi_tgt.h:91
ocs_lock_t sm_lock
Definition: ocs_scsi_tgt.h:190
uint32_t max_sge
Definition: ocs_scsi_tgt.h:52
ocs_atomic_t watermark_hit
Definition: ocs_scsi_tgt.h:64
ocs_dma_t * first_burst_buffers
Definition: ocs_scsi_tgt.h:142
ocs_ramdisc_ua_t represents a single UNIT ATTENTION condition
Definition: ocs_scsi_tgt.h:99
uint8_t supress_auto_response
Definition: ocs_scsi_tgt.h:176
ocs_atomic_t io_high_watermark
Definition: ocs_scsi_tgt.h:63
ocs_atomic_t initiator_count
Definition: ocs_scsi_tgt.h:61
ocs_list_t port_rdisc_head
Definition: ocs_scsi_tgt.h:73
uint32_t first_burst_bytes
Definition: ocs_scsi_tgt.h:149
int32_t watermark_min
Definition: ocs_scsi_tgt.h:65