target: Core cleanups from AGrover (round 1)
[pandora-kernel.git] / include / target / target_core_base.h
1 #ifndef TARGET_CORE_BASE_H
2 #define TARGET_CORE_BASE_H
3
4 #include <linux/in.h>
5 #include <linux/configfs.h>
6 #include <linux/dma-mapping.h>
7 #include <linux/blkdev.h>
8 #include <scsi/scsi_cmnd.h>
9 #include <net/sock.h>
10 #include <net/tcp.h>
11
12 #define TARGET_CORE_MOD_VERSION         "v4.0.0-rc7-ml"
13 #define SHUTDOWN_SIGS   (sigmask(SIGKILL)|sigmask(SIGINT)|sigmask(SIGABRT))
14
15 /* Used by transport_generic_allocate_iovecs() */
16 #define TRANSPORT_IOV_DATA_BUFFER               5
17 /* Maximum Number of LUNs per Target Portal Group */
18 #define TRANSPORT_MAX_LUNS_PER_TPG              256
19 /*
20  * By default we use 32-byte CDBs in TCM Core and subsystem plugin code.
21  *
22  * Note that both include/scsi/scsi_cmnd.h:MAX_COMMAND_SIZE and
23  * include/linux/blkdev.h:BLOCK_MAX_CDB as of v2.6.36-rc4 still use
24  * 16-byte CDBs by default and require an extra allocation for
25  * 32-byte CDBs to because of legacy issues.
26  *
27  * Within TCM Core there are no such legacy limitiations, so we go ahead
28  * use 32-byte CDBs by default and use include/scsi/scsi.h:scsi_command_size()
29  * within all TCM Core and subsystem plugin code.
30  */
31 #define TCM_MAX_COMMAND_SIZE                    32
32 /*
33  * From include/scsi/scsi_cmnd.h:SCSI_SENSE_BUFFERSIZE, currently
34  * defined 96, but the real limit is 252 (or 260 including the header)
35  */
36 #define TRANSPORT_SENSE_BUFFER                  SCSI_SENSE_BUFFERSIZE
37 /* Used by transport_send_check_condition_and_sense() */
38 #define SPC_SENSE_KEY_OFFSET                    2
39 #define SPC_ASC_KEY_OFFSET                      12
40 #define SPC_ASCQ_KEY_OFFSET                     13
41 #define TRANSPORT_IQN_LEN                       224
42 /* Used by target_core_store_alua_lu_gp() and target_core_alua_lu_gp_show_attr_members() */
43 #define LU_GROUP_NAME_BUF                       256
44 /* Used by core_alua_store_tg_pt_gp_info() and target_core_alua_tg_pt_gp_show_attr_members() */
45 #define TG_PT_GROUP_NAME_BUF                    256
46 /* Used to parse VPD into struct t10_vpd */
47 #define VPD_TMP_BUF_SIZE                        128
48 /* Used by transport_generic_cmd_sequencer() */
49 #define READ_BLOCK_LEN                          6
50 #define READ_CAP_LEN                            8
51 #define READ_POSITION_LEN                       20
52 #define INQUIRY_LEN                             36
53 /* Used by transport_get_inquiry_vpd_serial() */
54 #define INQUIRY_VPD_SERIAL_LEN                  254
55 /* Used by transport_get_inquiry_vpd_device_ident() */
56 #define INQUIRY_VPD_DEVICE_IDENTIFIER_LEN       254
57
58 /* struct se_hba->hba_flags */
59 enum hba_flags_table {
60         HBA_FLAGS_INTERNAL_USE  = 0x01,
61         HBA_FLAGS_PSCSI_MODE    = 0x02,
62 };
63
64 /* struct se_lun->lun_status */
65 enum transport_lun_status_table {
66         TRANSPORT_LUN_STATUS_FREE = 0,
67         TRANSPORT_LUN_STATUS_ACTIVE = 1,
68 };
69
70 /* struct se_portal_group->se_tpg_type */
71 enum transport_tpg_type_table {
72         TRANSPORT_TPG_TYPE_NORMAL = 0,
73         TRANSPORT_TPG_TYPE_DISCOVERY = 1,
74 };
75
76 /* Used for generate timer flags */
77 enum timer_flags_table {
78         TF_RUNNING      = 0x01,
79         TF_STOP         = 0x02,
80 };
81
82 /* Special transport agnostic struct se_cmd->t_states */
83 enum transport_state_table {
84         TRANSPORT_NO_STATE      = 0,
85         TRANSPORT_NEW_CMD       = 1,
86         TRANSPORT_DEFERRED_CMD  = 2,
87         TRANSPORT_WRITE_PENDING = 3,
88         TRANSPORT_PROCESS_WRITE = 4,
89         TRANSPORT_PROCESSING    = 5,
90         TRANSPORT_COMPLETE_OK   = 6,
91         TRANSPORT_COMPLETE_FAILURE = 7,
92         TRANSPORT_COMPLETE_TIMEOUT = 8,
93         TRANSPORT_PROCESS_TMR   = 9,
94         TRANSPORT_TMR_COMPLETE  = 10,
95         TRANSPORT_ISTATE_PROCESSING = 11,
96         TRANSPORT_ISTATE_PROCESSED = 12,
97         TRANSPORT_KILL          = 13,
98         TRANSPORT_REMOVE        = 14,
99         TRANSPORT_FREE          = 15,
100         TRANSPORT_NEW_CMD_MAP   = 16,
101         TRANSPORT_FREE_CMD_INTR = 17,
102 };
103
104 /* Used for struct se_cmd->se_cmd_flags */
105 enum se_cmd_flags_table {
106         SCF_SUPPORTED_SAM_OPCODE        = 0x00000001,
107         SCF_TRANSPORT_TASK_SENSE        = 0x00000002,
108         SCF_EMULATED_TASK_SENSE         = 0x00000004,
109         SCF_SCSI_DATA_SG_IO_CDB         = 0x00000008,
110         SCF_SCSI_CONTROL_SG_IO_CDB      = 0x00000010,
111         SCF_SCSI_CONTROL_NONSG_IO_CDB   = 0x00000020,
112         SCF_SCSI_NON_DATA_CDB           = 0x00000040,
113         SCF_SCSI_CDB_EXCEPTION          = 0x00000080,
114         SCF_SCSI_RESERVATION_CONFLICT   = 0x00000100,
115         SCF_CMD_PASSTHROUGH_NOALLOC     = 0x00000200,
116         SCF_SE_CMD_FAILED               = 0x00000400,
117         SCF_SE_LUN_CMD                  = 0x00000800,
118         SCF_SE_ALLOW_EOO                = 0x00001000,
119         SCF_SE_DISABLE_ONLINE_CHECK     = 0x00002000,
120         SCF_SENT_CHECK_CONDITION        = 0x00004000,
121         SCF_OVERFLOW_BIT                = 0x00008000,
122         SCF_UNDERFLOW_BIT               = 0x00010000,
123         SCF_SENT_DELAYED_TAS            = 0x00020000,
124         SCF_ALUA_NON_OPTIMIZED          = 0x00040000,
125         SCF_DELAYED_CMD_FROM_SAM_ATTR   = 0x00080000,
126         SCF_PASSTHROUGH_SG_TO_MEM       = 0x00100000,
127         SCF_PASSTHROUGH_CONTIG_TO_SG    = 0x00200000,
128         SCF_PASSTHROUGH_SG_TO_MEM_NOALLOC = 0x00400000,
129         SCF_EMULATE_SYNC_CACHE          = 0x00800000,
130         SCF_EMULATE_CDB_ASYNC           = 0x01000000,
131         SCF_EMULATE_SYNC_UNMAP          = 0x02000000
132 };
133
134 /* struct se_dev_entry->lun_flags and struct se_lun->lun_access */
135 enum transport_lunflags_table {
136         TRANSPORT_LUNFLAGS_NO_ACCESS            = 0x00,
137         TRANSPORT_LUNFLAGS_INITIATOR_ACCESS     = 0x01,
138         TRANSPORT_LUNFLAGS_READ_ONLY            = 0x02,
139         TRANSPORT_LUNFLAGS_READ_WRITE           = 0x04,
140 };
141
142 /* struct se_device->dev_status */
143 enum transport_device_status_table {
144         TRANSPORT_DEVICE_ACTIVATED              = 0x01,
145         TRANSPORT_DEVICE_DEACTIVATED            = 0x02,
146         TRANSPORT_DEVICE_QUEUE_FULL             = 0x04,
147         TRANSPORT_DEVICE_SHUTDOWN               = 0x08,
148         TRANSPORT_DEVICE_OFFLINE_ACTIVATED      = 0x10,
149         TRANSPORT_DEVICE_OFFLINE_DEACTIVATED    = 0x20,
150 };
151
152 /*
153  * Used by transport_send_check_condition_and_sense() and se_cmd->scsi_sense_reason
154  * to signal which ASC/ASCQ sense payload should be built.
155  */
156 enum tcm_sense_reason_table {
157         TCM_NON_EXISTENT_LUN                    = 0x01,
158         TCM_UNSUPPORTED_SCSI_OPCODE             = 0x02,
159         TCM_INCORRECT_AMOUNT_OF_DATA            = 0x03,
160         TCM_UNEXPECTED_UNSOLICITED_DATA         = 0x04,
161         TCM_SERVICE_CRC_ERROR                   = 0x05,
162         TCM_SNACK_REJECTED                      = 0x06,
163         TCM_SECTOR_COUNT_TOO_MANY               = 0x07,
164         TCM_INVALID_CDB_FIELD                   = 0x08,
165         TCM_INVALID_PARAMETER_LIST              = 0x09,
166         TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE  = 0x0a,
167         TCM_UNKNOWN_MODE_PAGE                   = 0x0b,
168         TCM_WRITE_PROTECTED                     = 0x0c,
169         TCM_CHECK_CONDITION_ABORT_CMD           = 0x0d,
170         TCM_CHECK_CONDITION_UNIT_ATTENTION      = 0x0e,
171         TCM_CHECK_CONDITION_NOT_READY           = 0x0f,
172 };
173
174 struct se_obj {
175         atomic_t obj_access_count;
176 } ____cacheline_aligned;
177
178 /*
179  * Used by TCM Core internally to signal if ALUA emulation is enabled or
180  * disabled, or running in with TCM/pSCSI passthrough mode
181  */
182 typedef enum {
183         SPC_ALUA_PASSTHROUGH,
184         SPC2_ALUA_DISABLED,
185         SPC3_ALUA_EMULATED
186 } t10_alua_index_t;
187
188 /*
189  * Used by TCM Core internally to signal if SAM Task Attribute emulation
190  * is enabled or disabled, or running in with TCM/pSCSI passthrough mode
191  */
192 typedef enum {
193         SAM_TASK_ATTR_PASSTHROUGH,
194         SAM_TASK_ATTR_UNTAGGED,
195         SAM_TASK_ATTR_EMULATED
196 } t10_task_attr_index_t;
197
198 /*
199  * Used for target SCSI statistics
200  */
201 typedef enum {
202         SCSI_INST_INDEX,
203         SCSI_DEVICE_INDEX,
204         SCSI_AUTH_INTR_INDEX,
205         SCSI_INDEX_TYPE_MAX
206 } scsi_index_t;
207
208 struct se_cmd;
209
210 struct t10_alua {
211         t10_alua_index_t alua_type;
212         /* ALUA Target Port Group ID */
213         u16     alua_tg_pt_gps_counter;
214         u32     alua_tg_pt_gps_count;
215         spinlock_t tg_pt_gps_lock;
216         struct se_subsystem_dev *t10_sub_dev;
217         /* Used for default ALUA Target Port Group */
218         struct t10_alua_tg_pt_gp *default_tg_pt_gp;
219         /* Used for default ALUA Target Port Group ConfigFS group */
220         struct config_group alua_tg_pt_gps_group;
221         int (*alua_state_check)(struct se_cmd *, unsigned char *, u8 *);
222         struct list_head tg_pt_gps_list;
223 } ____cacheline_aligned;
224
225 struct t10_alua_lu_gp {
226         u16     lu_gp_id;
227         int     lu_gp_valid_id;
228         u32     lu_gp_members;
229         atomic_t lu_gp_shutdown;
230         atomic_t lu_gp_ref_cnt;
231         spinlock_t lu_gp_lock;
232         struct config_group lu_gp_group;
233         struct list_head lu_gp_node;
234         struct list_head lu_gp_mem_list;
235 } ____cacheline_aligned;
236
237 struct t10_alua_lu_gp_member {
238         bool lu_gp_assoc;
239         atomic_t lu_gp_mem_ref_cnt;
240         spinlock_t lu_gp_mem_lock;
241         struct t10_alua_lu_gp *lu_gp;
242         struct se_device *lu_gp_mem_dev;
243         struct list_head lu_gp_mem_list;
244 } ____cacheline_aligned;
245
246 struct t10_alua_tg_pt_gp {
247         u16     tg_pt_gp_id;
248         int     tg_pt_gp_valid_id;
249         int     tg_pt_gp_alua_access_status;
250         int     tg_pt_gp_alua_access_type;
251         int     tg_pt_gp_nonop_delay_msecs;
252         int     tg_pt_gp_trans_delay_msecs;
253         int     tg_pt_gp_pref;
254         int     tg_pt_gp_write_metadata;
255         /* Used by struct t10_alua_tg_pt_gp->tg_pt_gp_md_buf_len */
256 #define ALUA_MD_BUF_LEN                         1024
257         u32     tg_pt_gp_md_buf_len;
258         u32     tg_pt_gp_members;
259         atomic_t tg_pt_gp_alua_access_state;
260         atomic_t tg_pt_gp_ref_cnt;
261         spinlock_t tg_pt_gp_lock;
262         struct mutex tg_pt_gp_md_mutex;
263         struct se_subsystem_dev *tg_pt_gp_su_dev;
264         struct config_group tg_pt_gp_group;
265         struct list_head tg_pt_gp_list;
266         struct list_head tg_pt_gp_mem_list;
267 } ____cacheline_aligned;
268
269 struct t10_alua_tg_pt_gp_member {
270         bool tg_pt_gp_assoc;
271         atomic_t tg_pt_gp_mem_ref_cnt;
272         spinlock_t tg_pt_gp_mem_lock;
273         struct t10_alua_tg_pt_gp *tg_pt_gp;
274         struct se_port *tg_pt;
275         struct list_head tg_pt_gp_mem_list;
276 } ____cacheline_aligned;
277
278 struct t10_vpd {
279         unsigned char device_identifier[INQUIRY_VPD_DEVICE_IDENTIFIER_LEN];
280         int protocol_identifier_set;
281         u32 protocol_identifier;
282         u32 device_identifier_code_set;
283         u32 association;
284         u32 device_identifier_type;
285         struct list_head vpd_list;
286 } ____cacheline_aligned;
287
288 struct t10_wwn {
289         char vendor[8];
290         char model[16];
291         char revision[4];
292         char unit_serial[INQUIRY_VPD_SERIAL_LEN];
293         spinlock_t t10_vpd_lock;
294         struct se_subsystem_dev *t10_sub_dev;
295         struct config_group t10_wwn_group;
296         struct list_head t10_vpd_list;
297 } ____cacheline_aligned;
298
299
300 /*
301  * Used by TCM Core internally to signal if >= SPC-3 persistent reservations
302  * emulation is enabled or disabled, or running in with TCM/pSCSI passthrough
303  * mode
304  */
305 typedef enum {
306         SPC_PASSTHROUGH,
307         SPC2_RESERVATIONS,
308         SPC3_PERSISTENT_RESERVATIONS
309 } t10_reservations_index_t;
310
311 struct t10_pr_registration {
312         /* Used for fabrics that contain WWN+ISID */
313 #define PR_REG_ISID_LEN                         16
314         /* PR_REG_ISID_LEN + ',i,0x' */
315 #define PR_REG_ISID_ID_LEN                      (PR_REG_ISID_LEN + 5)
316         char pr_reg_isid[PR_REG_ISID_LEN];
317         /* Used during APTPL metadata reading */
318 #define PR_APTPL_MAX_IPORT_LEN                  256
319         unsigned char pr_iport[PR_APTPL_MAX_IPORT_LEN];
320         /* Used during APTPL metadata reading */
321 #define PR_APTPL_MAX_TPORT_LEN                  256
322         unsigned char pr_tport[PR_APTPL_MAX_TPORT_LEN];
323         /* For writing out live meta data */
324         unsigned char *pr_aptpl_buf;
325         u16 pr_aptpl_rpti;
326         u16 pr_reg_tpgt;
327         /* Reservation effects all target ports */
328         int pr_reg_all_tg_pt;
329         /* Activate Persistence across Target Power Loss */
330         int pr_reg_aptpl;
331         int pr_res_holder;
332         int pr_res_type;
333         int pr_res_scope;
334         /* Used for fabric initiator WWPNs using a ISID */
335         bool isid_present_at_reg;
336         u32 pr_res_mapped_lun;
337         u32 pr_aptpl_target_lun;
338         u32 pr_res_generation;
339         u64 pr_reg_bin_isid;
340         u64 pr_res_key;
341         atomic_t pr_res_holders;
342         struct se_node_acl *pr_reg_nacl;
343         struct se_dev_entry *pr_reg_deve;
344         struct se_lun *pr_reg_tg_pt_lun;
345         struct list_head pr_reg_list;
346         struct list_head pr_reg_abort_list;
347         struct list_head pr_reg_aptpl_list;
348         struct list_head pr_reg_atp_list;
349         struct list_head pr_reg_atp_mem_list;
350 } ____cacheline_aligned;
351
352 /*
353  * This set of function pointer ops is set based upon SPC3_PERSISTENT_RESERVATIONS,
354  * SPC2_RESERVATIONS or SPC_PASSTHROUGH in drivers/target/target_core_pr.c:
355  * core_setup_reservations()
356  */
357 struct t10_reservation_ops {
358         int (*t10_reservation_check)(struct se_cmd *, u32 *);
359         int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
360         int (*t10_pr_register)(struct se_cmd *);
361         int (*t10_pr_clear)(struct se_cmd *);
362 };
363
364 struct t10_reservation {
365         /* Reservation effects all target ports */
366         int pr_all_tg_pt;
367         /* Activate Persistence across Target Power Loss enabled
368          * for SCSI device */
369         int pr_aptpl_active;
370         /* Used by struct t10_reservation->pr_aptpl_buf_len */
371 #define PR_APTPL_BUF_LEN                        8192
372         u32 pr_aptpl_buf_len;
373         u32 pr_generation;
374         t10_reservations_index_t res_type;
375         spinlock_t registration_lock;
376         spinlock_t aptpl_reg_lock;
377         /*
378          * This will always be set by one individual I_T Nexus.
379          * However with all_tg_pt=1, other I_T Nexus from the
380          * same initiator can access PR reg/res info on a different
381          * target port.
382          *
383          * There is also the 'All Registrants' case, where there is
384          * a single *pr_res_holder of the reservation, but all
385          * registrations are considered reservation holders.
386          */
387         struct se_node_acl *pr_res_holder;
388         struct list_head registration_list;
389         struct list_head aptpl_reg_list;
390         struct t10_reservation_ops pr_ops;
391 } ____cacheline_aligned;
392
393 struct se_queue_req {
394         int                     state;
395         struct se_cmd           *cmd;
396         struct list_head        qr_list;
397 } ____cacheline_aligned;
398
399 struct se_queue_obj {
400         atomic_t                queue_cnt;
401         spinlock_t              cmd_queue_lock;
402         struct list_head        qobj_list;
403         wait_queue_head_t       thread_wq;
404 } ____cacheline_aligned;
405
406 /*
407  * Used one per struct se_cmd to hold all extra struct se_task
408  * metadata.  This structure is setup and allocated in
409  * drivers/target/target_core_transport.c:__transport_alloc_se_cmd()
410  */
411 struct se_transport_task {
412         unsigned char           *t_task_cdb;
413         unsigned char           __t_task_cdb[TCM_MAX_COMMAND_SIZE];
414         unsigned long long      t_task_lba;
415         int                     t_tasks_failed;
416         int                     t_tasks_fua;
417         bool                    t_tasks_bidi;
418         u32                     t_task_cdbs;
419         u32                     t_tasks_check;
420         u32                     t_tasks_no;
421         u32                     t_tasks_sectors;
422         u32                     t_tasks_se_num;
423         u32                     t_tasks_se_bidi_num;
424         u32                     t_tasks_sg_chained_no;
425         atomic_t                t_fe_count;
426         atomic_t                t_se_count;
427         atomic_t                t_task_cdbs_left;
428         atomic_t                t_task_cdbs_ex_left;
429         atomic_t                t_task_cdbs_timeout_left;
430         atomic_t                t_task_cdbs_sent;
431         atomic_t                t_transport_aborted;
432         atomic_t                t_transport_active;
433         atomic_t                t_transport_complete;
434         atomic_t                t_transport_queue_active;
435         atomic_t                t_transport_sent;
436         atomic_t                t_transport_stop;
437         atomic_t                t_transport_timeout;
438         atomic_t                transport_dev_active;
439         atomic_t                transport_lun_active;
440         atomic_t                transport_lun_fe_stop;
441         atomic_t                transport_lun_stop;
442         spinlock_t              t_state_lock;
443         struct completion       t_transport_stop_comp;
444         struct completion       transport_lun_fe_stop_comp;
445         struct completion       transport_lun_stop_comp;
446         struct scatterlist      *t_tasks_sg_chained;
447         struct scatterlist      t_tasks_sg_bounce;
448         void                    *t_task_buf;
449         /*
450          * Used for pre-registered fabric SGL passthrough WRITE and READ
451          * with the special SCF_PASSTHROUGH_CONTIG_TO_SG case for TCM_Loop
452          * and other HW target mode fabric modules.
453          */
454         struct scatterlist      *t_task_pt_sgl;
455         struct list_head        *t_mem_list;
456         /* Used for BIDI READ */
457         struct list_head        *t_mem_bidi_list;
458         struct list_head        t_task_list;
459 } ____cacheline_aligned;
460
461 struct se_task {
462         unsigned char   task_sense;
463         struct scatterlist *task_sg;
464         struct scatterlist *task_sg_bidi;
465         u8              task_scsi_status;
466         u8              task_flags;
467         int             task_error_status;
468         int             task_state_flags;
469         bool            task_padded_sg;
470         unsigned long long      task_lba;
471         u32             task_no;
472         u32             task_sectors;
473         u32             task_size;
474         u32             task_sg_num;
475         u32             task_sg_offset;
476         enum dma_data_direction task_data_direction;
477         struct se_cmd *task_se_cmd;
478         struct se_device        *se_dev;
479         struct completion       task_stop_comp;
480         atomic_t        task_active;
481         atomic_t        task_execute_queue;
482         atomic_t        task_timeout;
483         atomic_t        task_sent;
484         atomic_t        task_stop;
485         atomic_t        task_state_active;
486         struct timer_list       task_timer;
487         struct se_device *se_obj_ptr;
488         struct list_head t_list;
489         struct list_head t_execute_list;
490         struct list_head t_state_list;
491 } ____cacheline_aligned;
492
493 struct se_cmd {
494         /* SAM response code being sent to initiator */
495         u8                      scsi_status;
496         u8                      scsi_asc;
497         u8                      scsi_ascq;
498         u8                      scsi_sense_reason;
499         u16                     scsi_sense_length;
500         /* Delay for ALUA Active/NonOptimized state access in milliseconds */
501         int                     alua_nonop_delay;
502         /* See include/linux/dma-mapping.h */
503         enum dma_data_direction data_direction;
504         /* For SAM Task Attribute */
505         int                     sam_task_attr;
506         /* Transport protocol dependent state, see transport_state_table */
507         enum transport_state_table t_state;
508         /* Transport protocol dependent state for out of order CmdSNs */
509         int                     deferred_t_state;
510         /* Transport specific error status */
511         int                     transport_error_status;
512         /* See se_cmd_flags_table */
513         u32                     se_cmd_flags;
514         u32                     se_ordered_id;
515         /* Total size in bytes associated with command */
516         u32                     data_length;
517         /* SCSI Presented Data Transfer Length */
518         u32                     cmd_spdtl;
519         u32                     residual_count;
520         u32                     orig_fe_lun;
521         /* Persistent Reservation key */
522         u64                     pr_res_key;
523         atomic_t                transport_sent;
524         /* Used for sense data */
525         void                    *sense_buffer;
526         struct list_head        se_delayed_list;
527         struct list_head        se_ordered_list;
528         struct list_head        se_lun_list;
529         struct se_device      *se_dev;
530         struct se_dev_entry   *se_deve;
531         struct se_device        *se_obj_ptr;
532         struct se_device        *se_orig_obj_ptr;
533         struct se_lun           *se_lun;
534         /* Only used for internal passthrough and legacy TCM fabric modules */
535         struct se_session       *se_sess;
536         struct se_tmr_req       *se_tmr_req;
537         /* t_task is setup to t_task_backstore in transport_init_se_cmd() */
538         struct se_transport_task *t_task;
539         struct se_transport_task t_task_backstore;
540         struct target_core_fabric_ops *se_tfo;
541         int (*transport_emulate_cdb)(struct se_cmd *);
542         void (*transport_split_cdb)(unsigned long long, u32 *, unsigned char *);
543         void (*transport_wait_for_tasks)(struct se_cmd *, int, int);
544         void (*transport_complete_callback)(struct se_cmd *);
545 } ____cacheline_aligned;
546
547 struct se_tmr_req {
548         /* Task Management function to be preformed */
549         u8                      function;
550         /* Task Management response to send */
551         u8                      response;
552         int                     call_transport;
553         /* Reference to ITT that Task Mgmt should be preformed */
554         u32                     ref_task_tag;
555         /* 64-bit encoded SAM LUN from $FABRIC_MOD TMR header */
556         u64                     ref_task_lun;
557         void                    *fabric_tmr_ptr;
558         struct se_cmd           *task_cmd;
559         struct se_cmd           *ref_cmd;
560         struct se_device        *tmr_dev;
561         struct se_lun           *tmr_lun;
562         struct list_head        tmr_list;
563 } ____cacheline_aligned;
564
565 struct se_ua {
566         u8                      ua_asc;
567         u8                      ua_ascq;
568         struct se_node_acl      *ua_nacl;
569         struct list_head        ua_dev_list;
570         struct list_head        ua_nacl_list;
571 } ____cacheline_aligned;
572
573 struct se_node_acl {
574         char                    initiatorname[TRANSPORT_IQN_LEN];
575         /* Used to signal demo mode created ACL, disabled by default */
576         bool                    dynamic_node_acl;
577         u32                     queue_depth;
578         u32                     acl_index;
579         u64                     num_cmds;
580         u64                     read_bytes;
581         u64                     write_bytes;
582         spinlock_t              stats_lock;
583         /* Used for PR SPEC_I_PT=1 and REGISTER_AND_MOVE */
584         atomic_t                acl_pr_ref_count;
585         struct se_dev_entry     *device_list;
586         struct se_session       *nacl_sess;
587         struct se_portal_group *se_tpg;
588         spinlock_t              device_list_lock;
589         spinlock_t              nacl_sess_lock;
590         struct config_group     acl_group;
591         struct config_group     acl_attrib_group;
592         struct config_group     acl_auth_group;
593         struct config_group     acl_param_group;
594         struct config_group     acl_fabric_stat_group;
595         struct config_group     *acl_default_groups[5];
596         struct list_head        acl_list;
597         struct list_head        acl_sess_list;
598 } ____cacheline_aligned;
599
600 struct se_session {
601         u64                     sess_bin_isid;
602         struct se_node_acl      *se_node_acl;
603         struct se_portal_group *se_tpg;
604         void                    *fabric_sess_ptr;
605         struct list_head        sess_list;
606         struct list_head        sess_acl_list;
607 } ____cacheline_aligned;
608
609 struct se_device;
610 struct se_transform_info;
611 struct scatterlist;
612
613 struct se_ml_stat_grps {
614         struct config_group     stat_group;
615         struct config_group     scsi_auth_intr_group;
616         struct config_group     scsi_att_intr_port_group;
617 };
618
619 struct se_lun_acl {
620         char                    initiatorname[TRANSPORT_IQN_LEN];
621         u32                     mapped_lun;
622         struct se_node_acl      *se_lun_nacl;
623         struct se_lun           *se_lun;
624         struct list_head        lacl_list;
625         struct config_group     se_lun_group;
626         struct se_ml_stat_grps  ml_stat_grps;
627 }  ____cacheline_aligned;
628
629 struct se_dev_entry {
630         bool                    def_pr_registered;
631         /* See transport_lunflags_table */
632         u32                     lun_flags;
633         u32                     deve_cmds;
634         u32                     mapped_lun;
635         u32                     average_bytes;
636         u32                     last_byte_count;
637         u32                     total_cmds;
638         u32                     total_bytes;
639         u64                     pr_res_key;
640         u64                     creation_time;
641         u32                     attach_count;
642         u64                     read_bytes;
643         u64                     write_bytes;
644         atomic_t                ua_count;
645         /* Used for PR SPEC_I_PT=1 and REGISTER_AND_MOVE */
646         atomic_t                pr_ref_count;
647         struct se_lun_acl       *se_lun_acl;
648         spinlock_t              ua_lock;
649         struct se_lun           *se_lun;
650         struct list_head        alua_port_list;
651         struct list_head        ua_list;
652 }  ____cacheline_aligned;
653
654 struct se_dev_limits {
655         /* Max supported HW queue depth */
656         u32             hw_queue_depth;
657         /* Max supported virtual queue depth */
658         u32             queue_depth;
659         /* From include/linux/blkdev.h for the other HW/SW limits. */
660         struct queue_limits limits;
661 } ____cacheline_aligned;
662
663 struct se_dev_attrib {
664         int             emulate_dpo;
665         int             emulate_fua_write;
666         int             emulate_fua_read;
667         int             emulate_write_cache;
668         int             emulate_ua_intlck_ctrl;
669         int             emulate_tas;
670         int             emulate_tpu;
671         int             emulate_tpws;
672         int             emulate_reservations;
673         int             emulate_alua;
674         int             enforce_pr_isids;
675         u32             hw_block_size;
676         u32             block_size;
677         u32             hw_max_sectors;
678         u32             max_sectors;
679         u32             optimal_sectors;
680         u32             hw_queue_depth;
681         u32             queue_depth;
682         u32             task_timeout;
683         u32             max_unmap_lba_count;
684         u32             max_unmap_block_desc_count;
685         u32             unmap_granularity;
686         u32             unmap_granularity_alignment;
687         struct se_subsystem_dev *da_sub_dev;
688         struct config_group da_group;
689 } ____cacheline_aligned;
690
691 struct se_dev_stat_grps {
692         struct config_group stat_group;
693         struct config_group scsi_dev_group;
694         struct config_group scsi_tgt_dev_group;
695         struct config_group scsi_lu_group;
696 };
697
698 struct se_subsystem_dev {
699 /* Used for struct se_subsystem_dev-->se_dev_alias, must be less than PAGE_SIZE */
700 #define SE_DEV_ALIAS_LEN                512
701         unsigned char   se_dev_alias[SE_DEV_ALIAS_LEN];
702 /* Used for struct se_subsystem_dev->se_dev_udev_path[], must be less than PAGE_SIZE */
703 #define SE_UDEV_PATH_LEN                512
704         unsigned char   se_dev_udev_path[SE_UDEV_PATH_LEN];
705         u32             su_dev_flags;
706         struct se_hba *se_dev_hba;
707         struct se_device *se_dev_ptr;
708         struct se_dev_attrib se_dev_attrib;
709         /* T10 Asymmetric Logical Unit Assignment for Target Ports */
710         struct t10_alua t10_alua;
711         /* T10 Inquiry and VPD WWN Information */
712         struct t10_wwn  t10_wwn;
713         /* T10 SPC-2 + SPC-3 Reservations */
714         struct t10_reservation t10_pr;
715         spinlock_t      se_dev_lock;
716         void            *se_dev_su_ptr;
717         struct list_head se_dev_node;
718         struct config_group se_dev_group;
719         /* For T10 Reservations */
720         struct config_group se_dev_pr_group;
721         /* For target_core_stat.c groups */
722         struct se_dev_stat_grps dev_stat_grps;
723 } ____cacheline_aligned;
724
725 struct se_device {
726         /* Set to 1 if thread is NOT sleeping on thread_sem */
727         u8                      thread_active;
728         u8                      dev_status_timer_flags;
729         /* RELATIVE TARGET PORT IDENTIFER Counter */
730         u16                     dev_rpti_counter;
731         /* Used for SAM Task Attribute ordering */
732         u32                     dev_cur_ordered_id;
733         u32                     dev_flags;
734         u32                     dev_port_count;
735         /* See transport_device_status_table */
736         u32                     dev_status;
737         u32                     dev_tcq_window_closed;
738         /* Physical device queue depth */
739         u32                     queue_depth;
740         /* Used for SPC-2 reservations enforce of ISIDs */
741         u64                     dev_res_bin_isid;
742         t10_task_attr_index_t   dev_task_attr_type;
743         /* Pointer to transport specific device structure */
744         void                    *dev_ptr;
745         u32                     dev_index;
746         u64                     creation_time;
747         u32                     num_resets;
748         u64                     num_cmds;
749         u64                     read_bytes;
750         u64                     write_bytes;
751         spinlock_t              stats_lock;
752         /* Active commands on this virtual SE device */
753         atomic_t                active_cmds;
754         atomic_t                simple_cmds;
755         atomic_t                depth_left;
756         atomic_t                dev_ordered_id;
757         atomic_t                dev_tur_active;
758         atomic_t                execute_tasks;
759         atomic_t                dev_status_thr_count;
760         atomic_t                dev_hoq_count;
761         atomic_t                dev_ordered_sync;
762         struct se_obj           dev_obj;
763         struct se_obj           dev_access_obj;
764         struct se_obj           dev_export_obj;
765         struct se_queue_obj     dev_queue_obj;
766         spinlock_t              delayed_cmd_lock;
767         spinlock_t              ordered_cmd_lock;
768         spinlock_t              execute_task_lock;
769         spinlock_t              state_task_lock;
770         spinlock_t              dev_alua_lock;
771         spinlock_t              dev_reservation_lock;
772         spinlock_t              dev_state_lock;
773         spinlock_t              dev_status_lock;
774         spinlock_t              dev_status_thr_lock;
775         spinlock_t              se_port_lock;
776         spinlock_t              se_tmr_lock;
777         /* Used for legacy SPC-2 reservationsa */
778         struct se_node_acl      *dev_reserved_node_acl;
779         /* Used for ALUA Logical Unit Group membership */
780         struct t10_alua_lu_gp_member *dev_alua_lu_gp_mem;
781         /* Used for SPC-3 Persistent Reservations */
782         struct t10_pr_registration *dev_pr_res_holder;
783         struct list_head        dev_sep_list;
784         struct list_head        dev_tmr_list;
785         struct timer_list       dev_status_timer;
786         /* Pointer to descriptor for processing thread */
787         struct task_struct      *process_thread;
788         pid_t                   process_thread_pid;
789         struct task_struct              *dev_mgmt_thread;
790         struct list_head        delayed_cmd_list;
791         struct list_head        ordered_cmd_list;
792         struct list_head        execute_task_list;
793         struct list_head        state_task_list;
794         /* Pointer to associated SE HBA */
795         struct se_hba           *se_hba;
796         struct se_subsystem_dev *se_sub_dev;
797         /* Pointer to template of function pointers for transport */
798         struct se_subsystem_api *transport;
799         /* Linked list for struct se_hba struct se_device list */
800         struct list_head        dev_list;
801         /* Linked list for struct se_global->g_se_dev_list */
802         struct list_head        g_se_dev_list;
803 }  ____cacheline_aligned;
804
805 struct se_hba {
806         u16                     hba_tpgt;
807         u32                     hba_id;
808         /* See hba_flags_table */
809         u32                     hba_flags;
810         /* Virtual iSCSI devices attached. */
811         u32                     dev_count;
812         u32                     hba_index;
813         /* Pointer to transport specific host structure. */
814         void                    *hba_ptr;
815         /* Linked list for struct se_device */
816         struct list_head        hba_dev_list;
817         struct list_head        hba_node;
818         spinlock_t              device_lock;
819         struct config_group     hba_group;
820         struct mutex            hba_access_mutex;
821         struct se_subsystem_api *transport;
822 }  ____cacheline_aligned;
823
824 struct se_port_stat_grps {
825         struct config_group stat_group;
826         struct config_group scsi_port_group;
827         struct config_group scsi_tgt_port_group;
828         struct config_group scsi_transport_group;
829 };
830
831 struct se_lun {
832         /* See transport_lun_status_table */
833         enum transport_lun_status_table lun_status;
834         u32                     lun_access;
835         u32                     lun_flags;
836         u32                     unpacked_lun;
837         atomic_t                lun_acl_count;
838         spinlock_t              lun_acl_lock;
839         spinlock_t              lun_cmd_lock;
840         spinlock_t              lun_sep_lock;
841         struct completion       lun_shutdown_comp;
842         struct list_head        lun_cmd_list;
843         struct list_head        lun_acl_list;
844         struct se_device        *lun_se_dev;
845         struct se_port          *lun_sep;
846         struct config_group     lun_group;
847         struct se_port_stat_grps port_stat_grps;
848 } ____cacheline_aligned;
849
850 struct scsi_port_stats {
851        u64     cmd_pdus;
852        u64     tx_data_octets;
853        u64     rx_data_octets;
854 } ____cacheline_aligned;
855
856 struct se_port {
857         /* RELATIVE TARGET PORT IDENTIFER */
858         u16             sep_rtpi;
859         int             sep_tg_pt_secondary_stat;
860         int             sep_tg_pt_secondary_write_md;
861         u32             sep_index;
862         struct scsi_port_stats sep_stats;
863         /* Used for ALUA Target Port Groups membership */
864         atomic_t        sep_tg_pt_gp_active;
865         atomic_t        sep_tg_pt_secondary_offline;
866         /* Used for PR ALL_TG_PT=1 */
867         atomic_t        sep_tg_pt_ref_cnt;
868         spinlock_t      sep_alua_lock;
869         struct mutex    sep_tg_pt_md_mutex;
870         struct t10_alua_tg_pt_gp_member *sep_alua_tg_pt_gp_mem;
871         struct se_lun *sep_lun;
872         struct se_portal_group *sep_tpg;
873         struct list_head sep_alua_list;
874         struct list_head sep_list;
875 } ____cacheline_aligned;
876
877 struct se_tpg_np {
878         struct se_portal_group *tpg_np_parent;
879         struct config_group     tpg_np_group;
880 } ____cacheline_aligned;
881
882 struct se_portal_group {
883         /* Type of target portal group, see transport_tpg_type_table */
884         enum transport_tpg_type_table se_tpg_type;
885         /* Number of ACLed Initiator Nodes for this TPG */
886         u32                     num_node_acls;
887         /* Used for PR SPEC_I_PT=1 and REGISTER_AND_MOVE */
888         atomic_t                tpg_pr_ref_count;
889         /* Spinlock for adding/removing ACLed Nodes */
890         spinlock_t              acl_node_lock;
891         /* Spinlock for adding/removing sessions */
892         spinlock_t              session_lock;
893         spinlock_t              tpg_lun_lock;
894         /* Pointer to $FABRIC_MOD portal group */
895         void                    *se_tpg_fabric_ptr;
896         struct list_head        se_tpg_node;
897         /* linked list for initiator ACL list */
898         struct list_head        acl_node_list;
899         struct se_lun           *tpg_lun_list;
900         struct se_lun           tpg_virt_lun0;
901         /* List of TCM sessions associated wth this TPG */
902         struct list_head        tpg_sess_list;
903         /* Pointer to $FABRIC_MOD dependent code */
904         struct target_core_fabric_ops *se_tpg_tfo;
905         struct se_wwn           *se_tpg_wwn;
906         struct config_group     tpg_group;
907         struct config_group     *tpg_default_groups[6];
908         struct config_group     tpg_lun_group;
909         struct config_group     tpg_np_group;
910         struct config_group     tpg_acl_group;
911         struct config_group     tpg_attrib_group;
912         struct config_group     tpg_param_group;
913 } ____cacheline_aligned;
914
915 struct se_wwn {
916         struct target_fabric_configfs *wwn_tf;
917         struct config_group     wwn_group;
918         struct config_group     *wwn_default_groups[2];
919         struct config_group     fabric_stat_group;
920 } ____cacheline_aligned;
921
922 #endif /* TARGET_CORE_BASE_H */