Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
target_core_base.h
Go to the documentation of this file.
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.1.0-rc2-ml"
13 #define TARGET_CORE_VERSION TARGET_CORE_MOD_VERSION
14 
15 /* Maximum Number of LUNs per Target Portal Group */
16 /* Don't raise above 511 or REPORT_LUNS needs to handle >1 page */
17 #define TRANSPORT_MAX_LUNS_PER_TPG 256
18 /*
19  * By default we use 32-byte CDBs in TCM Core and subsystem plugin code.
20  *
21  * Note that both include/scsi/scsi_cmnd.h:MAX_COMMAND_SIZE and
22  * include/linux/blkdev.h:BLOCK_MAX_CDB as of v2.6.36-rc4 still use
23  * 16-byte CDBs by default and require an extra allocation for
24  * 32-byte CDBs to because of legacy issues.
25  *
26  * Within TCM Core there are no such legacy limitiations, so we go ahead
27  * use 32-byte CDBs by default and use include/scsi/scsi.h:scsi_command_size()
28  * within all TCM Core and subsystem plugin code.
29  */
30 #define TCM_MAX_COMMAND_SIZE 32
31 /*
32  * From include/scsi/scsi_cmnd.h:SCSI_SENSE_BUFFERSIZE, currently
33  * defined 96, but the real limit is 252 (or 260 including the header)
34  */
35 #define TRANSPORT_SENSE_BUFFER SCSI_SENSE_BUFFERSIZE
36 /* Used by transport_send_check_condition_and_sense() */
37 #define SPC_SENSE_KEY_OFFSET 2
38 #define SPC_ADD_SENSE_LEN_OFFSET 7
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 /* Attempts before moving from SHORT to LONG */
59 #define PYX_TRANSPORT_WINDOW_CLOSED_THRESHOLD 3
60 #define PYX_TRANSPORT_WINDOW_CLOSED_WAIT_SHORT 3 /* In milliseconds */
61 #define PYX_TRANSPORT_WINDOW_CLOSED_WAIT_LONG 10 /* In milliseconds */
62 
63 #define PYX_TRANSPORT_STATUS_INTERVAL 5 /* In seconds */
64 
65 /*
66  * struct se_subsystem_dev->su_dev_flags
67 */
68 #define SDF_FIRMWARE_VPD_UNIT_SERIAL 0x00000001
69 #define SDF_EMULATED_VPD_UNIT_SERIAL 0x00000002
70 #define SDF_USING_UDEV_PATH 0x00000004
71 #define SDF_USING_ALIAS 0x00000008
72 
73 /*
74  * struct se_device->dev_flags
75  */
76 #define DF_SPC2_RESERVATIONS 0x00000001
77 #define DF_SPC2_RESERVATIONS_WITH_ISID 0x00000002
78 
79 /* struct se_dev_attrib sanity values */
80 /* Default max_unmap_lba_count */
81 #define DA_MAX_UNMAP_LBA_COUNT 0
82 /* Default max_unmap_block_desc_count */
83 #define DA_MAX_UNMAP_BLOCK_DESC_COUNT 0
84 /* Default unmap_granularity */
85 #define DA_UNMAP_GRANULARITY_DEFAULT 0
86 /* Default unmap_granularity_alignment */
87 #define DA_UNMAP_GRANULARITY_ALIGNMENT_DEFAULT 0
88 /* Default max transfer length */
89 #define DA_FABRIC_MAX_SECTORS 8192
90 /* Emulation for Direct Page Out */
91 #define DA_EMULATE_DPO 0
92 /* Emulation for Forced Unit Access WRITEs */
93 #define DA_EMULATE_FUA_WRITE 1
94 /* Emulation for Forced Unit Access READs */
95 #define DA_EMULATE_FUA_READ 0
96 /* Emulation for WriteCache and SYNCHRONIZE_CACHE */
97 #define DA_EMULATE_WRITE_CACHE 0
98 /* Emulation for UNIT ATTENTION Interlock Control */
99 #define DA_EMULATE_UA_INTLLCK_CTRL 0
100 /* Emulation for TASK_ABORTED status (TAS) by default */
101 #define DA_EMULATE_TAS 1
102 /* Emulation for Thin Provisioning UNMAP using block/blk-lib.c:blkdev_issue_discard() */
103 #define DA_EMULATE_TPU 0
104 /*
105  * Emulation for Thin Provisioning WRITE_SAME w/ UNMAP=1 bit using
106  * block/blk-lib.c:blkdev_issue_discard()
107  */
108 #define DA_EMULATE_TPWS 0
109 /* No Emulation for PSCSI by default */
110 #define DA_EMULATE_RESERVATIONS 0
111 /* No Emulation for PSCSI by default */
112 #define DA_EMULATE_ALUA 0
113 /* Enforce SCSI Initiator Port TransportID with 'ISID' for PR */
114 #define DA_ENFORCE_PR_ISIDS 1
115 #define DA_STATUS_MAX_SECTORS_MIN 16
116 #define DA_STATUS_MAX_SECTORS_MAX 8192
117 /* By default don't report non-rotating (solid state) medium */
118 #define DA_IS_NONROT 0
119 /* Queue Algorithm Modifier default for restricted reordering in control mode page */
120 #define DA_EMULATE_REST_REORD 0
121 
122 #define SE_INQUIRY_BUF 512
123 #define SE_MODE_PAGE_BUF 512
124 #define SE_SENSE_BUF 96
125 
126 /* struct se_hba->hba_flags */
130 };
131 
132 /* struct se_lun->lun_status */
136 };
137 
138 /* struct se_portal_group->se_tpg_type */
142 };
143 
144 /* Special transport agnostic struct se_cmd->t_states */
154 };
155 
156 /* Used for struct se_cmd->se_cmd_flags */
161  SCF_SCSI_DATA_CDB = 0x00000008,
162  SCF_SCSI_TMR_CDB = 0x00000010,
165  SCF_FUA = 0x00000080,
166  SCF_SE_LUN_CMD = 0x00000100,
167  SCF_BIDI = 0x00000400,
169  SCF_OVERFLOW_BIT = 0x00001000,
170  SCF_UNDERFLOW_BIT = 0x00002000,
171  SCF_SENT_DELAYED_TAS = 0x00004000,
174  SCF_ACK_KREF = 0x00040000,
175 };
176 
177 /* struct se_dev_entry->lun_flags and struct se_lun->lun_access */
183 };
184 
185 /* struct se_device->dev_status */
193 };
194 
195 /*
196  * Used by transport_send_check_condition_and_sense() and se_cmd->scsi_sense_reason
197  * to signal which ASC/ASCQ sense payload should be built.
198  */
217 };
218 
223 };
224 
225 /* fabric independent task management function values */
235 };
236 
237 /* fabric independent task management response values */
247 };
248 
249 struct se_obj {
251 };
252 
253 /*
254  * Used by TCM Core internally to signal if ALUA emulation is enabled or
255  * disabled, or running in with TCM/pSCSI passthrough mode
256  */
257 typedef enum {
262 
263 /*
264  * Used by TCM Core internally to signal if SAM Task Attribute emulation
265  * is enabled or disabled, or running in with TCM/pSCSI passthrough mode
266  */
267 typedef enum {
272 
273 /*
274  * Used for target SCSI statistics
275  */
276 typedef enum {
281 } scsi_index_t;
282 
283 struct se_cmd;
284 
285 struct t10_alua {
287  /* ALUA Target Port Group ID */
292  /* Used for default ALUA Target Port Group */
294  /* Used for default ALUA Target Port Group ConfigFS group */
296  int (*alua_state_check)(struct se_cmd *, unsigned char *, u8 *);
298 };
299 
309 };
310 
318 };
319 
330  /* Used by struct t10_alua_tg_pt_gp->tg_pt_gp_md_buf_len */
331 #define ALUA_MD_BUF_LEN 1024
342 };
343 
349  struct se_port *tg_pt;
351 };
352 
353 struct t10_vpd {
361 };
362 
363 struct t10_wwn {
364  char vendor[8];
365  char model[16];
366  char revision[4];
372 };
373 
374 
375 /*
376  * Used by TCM Core internally to signal if >= SPC-3 persistent reservations
377  * emulation is enabled or disabled, or running in with TCM/pSCSI passthrough
378  * mode
379  */
380 typedef enum {
385 
387  /* Used for fabrics that contain WWN+ISID */
388 #define PR_REG_ISID_LEN 16
389  /* PR_REG_ISID_LEN + ',i,0x' */
390 #define PR_REG_ISID_ID_LEN (PR_REG_ISID_LEN + 5)
392  /* Used during APTPL metadata reading */
393 #define PR_APTPL_MAX_IPORT_LEN 256
395  /* Used during APTPL metadata reading */
396 #define PR_APTPL_MAX_TPORT_LEN 256
398  /* For writing out live meta data */
399  unsigned char *pr_aptpl_buf;
402  /* Reservation effects all target ports */
404  /* Activate Persistence across Target Power Loss */
409  /* Used for fabric initiator WWPNs using a ISID */
425 };
426 
427 /*
428  * This set of function pointer ops is set based upon SPC3_PERSISTENT_RESERVATIONS,
429  * SPC2_RESERVATIONS or SPC_PASSTHROUGH in drivers/target/target_core_pr.c:
430  * core_setup_reservations()
431  */
434  int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
435  int (*t10_pr_register)(struct se_cmd *);
436  int (*t10_pr_clear)(struct se_cmd *);
437 };
438 
440  /* Reservation effects all target ports */
442  /* Activate Persistence across Target Power Loss enabled
443  * for SCSI device */
445  /* Used by struct t10_reservation->pr_aptpl_buf_len */
446 #define PR_APTPL_BUF_LEN 8192
452  /*
453  * This will always be set by one individual I_T Nexus.
454  * However with all_tg_pt=1, other I_T Nexus from the
455  * same initiator can access PR reg/res info on a different
456  * target port.
457  *
458  * There is also the 'All Registrants' case, where there is
459  * a single *pr_res_holder of the reservation, but all
460  * registrations are considered reservation holders.
461  */
466 };
467 
468 struct se_tmr_req {
469  /* Task Management function to be performed */
470  u8 function;
471  /* Task Management response to send */
474  /* Reference to ITT that Task Mgmt should be performed */
477  struct se_cmd *task_cmd;
479  struct se_lun *tmr_lun;
481 };
482 
483 struct se_cmd {
484  /* SAM response code being sent to initiator */
490  /* Delay for ALUA Active/NonOptimized state access in milliseconds */
492  /* See include/linux/dma-mapping.h */
494  /* For SAM Task Attribute */
496  /* Transport protocol dependent state, see transport_state_table */
498  /* Used to signal cmd->se_tfo->check_release_cmd() usage per cmd */
499  unsigned check_release:1;
500  unsigned cmd_wait_set:1;
502  /* See se_cmd_flags_table */
505  /* Total size in bytes associated with command */
509  /* Persistent Reservation key */
511  /* Used for sense data */
516  struct se_device *se_dev;
518  struct se_lun *se_lun;
519  /* Only used for internal passthrough and legacy TCM fabric modules */
524  struct kref cmd_kref;
526  int (*execute_cmd)(struct se_cmd *);
528 
529  unsigned char *t_task_cdb;
531  unsigned long long t_task_lba;
533  unsigned int transport_state;
534 #define CMD_T_ABORTED (1 << 0)
535 #define CMD_T_ACTIVE (1 << 1)
536 #define CMD_T_COMPLETE (1 << 2)
537 #define CMD_T_QUEUED (1 << 3)
538 #define CMD_T_SENT (1 << 4)
539 #define CMD_T_STOP (1 << 5)
540 #define CMD_T_FAILED (1 << 6)
541 #define CMD_T_LUN_STOP (1 << 7)
542 #define CMD_T_LUN_FE_STOP (1 << 8)
543 #define CMD_T_DEV_ACTIVE (1 << 9)
544 #define CMD_T_REQUEST_STOP (1 << 10)
545 #define CMD_T_BUSY (1 << 11)
550 
552 
554  unsigned int t_data_nents;
555  void *t_data_vmap;
557  unsigned int t_bidi_data_nents;
558 
561 
562  /* old task stop completion, consider merging with some of the above */
564 
565  /* backend private data */
566  void *priv;
567 };
568 
569 struct se_ua {
575 };
576 
577 struct se_node_acl {
579  /* Used to signal demo mode created ACL, disabled by default */
581  bool acl_stop:1;
588  /* Used for PR SPEC_I_PT=1 and REGISTER_AND_MOVE */
604  struct kref acl_kref;
605 };
606 
607 struct se_session {
608  unsigned sess_tearing_down:1;
617  struct kref sess_kref;
618 };
619 
620 struct se_device;
621 struct se_transform_info;
622 struct scatterlist;
623 
628 };
629 
630 struct se_lun_acl {
634  struct se_lun *se_lun;
638 };
639 
640 struct se_dev_entry {
642  /* See transport_lunflags_table */
656  /* Used for PR SPEC_I_PT=1 and REGISTER_AND_MOVE */
660  struct se_lun *se_lun;
663 };
664 
666  /* Max supported HW queue depth */
668  /* Max supported virtual queue depth */
670  /* From include/linux/blkdev.h for the other HW/SW limits. */
671  struct queue_limits limits;
672 };
673 
701 };
702 
708 };
709 
711 /* Used for struct se_subsystem_dev-->se_dev_alias, must be less than PAGE_SIZE */
712 #define SE_DEV_ALIAS_LEN 512
714 /* Used for struct se_subsystem_dev->se_dev_udev_path[], must be less than PAGE_SIZE */
715 #define SE_UDEV_PATH_LEN 512
721  /* T10 Asymmetric Logical Unit Assignment for Target Ports */
723  /* T10 Inquiry and VPD WWN Information */
724  struct t10_wwn t10_wwn;
725  /* T10 SPC-2 + SPC-3 Reservations */
730  /* For T10 Reservations */
732  /* For target_core_stat.c groups */
734 };
735 
736 struct se_device {
737  /* RELATIVE TARGET PORT IDENTIFER Counter */
739  /* Used for SAM Task Attribute ordering */
743  /* See transport_device_status_table */
745  /* Physical device queue depth */
747  /* Used for SPC-2 reservations enforce of ISIDs */
750  /* Pointer to transport specific device structure */
751  void *dev_ptr;
759  /* Active commands on this virtual SE device */
764  struct se_obj dev_obj;
774  /* Used for legacy SPC-2 reservationsa */
776  /* Used for ALUA Logical Unit Group membership */
778  /* Used for SPC-3 Persistent Reservations */
787  /* Pointer to associated SE HBA */
788  struct se_hba *se_hba;
790  /* Pointer to template of function pointers for transport */
792  /* Linked list for struct se_hba struct se_device list */
794 };
795 
796 struct se_hba {
799  /* See hba_flags_table */
801  /* Virtual iSCSI devices attached. */
804  /* Pointer to transport specific host structure. */
805  void *hba_ptr;
806  /* Linked list for struct se_device */
813 };
814 
820 };
821 
822 struct se_lun {
823  /* See transport_lun_status_table */
836  struct se_port *lun_sep;
839 };
840 
845 };
846 
847 struct se_port {
848  /* RELATIVE TARGET PORT IDENTIFER */
854  /* Used for ALUA Target Port Groups membership */
856  /* Used for PR ALL_TG_PT=1 */
861  struct se_lun *sep_lun;
865 };
866 
867 struct se_tpg_np {
870 };
871 
873  /* Type of target portal group, see transport_tpg_type_table */
875  /* Number of ACLed Initiator Nodes for this TPG */
877  /* Used for PR SPEC_I_PT=1 and REGISTER_AND_MOVE */
879  /* Spinlock for adding/removing ACLed Nodes */
881  /* Spinlock for adding/removing sessions */
884  /* Pointer to $FABRIC_MOD portal group */
887  /* linked list for initiator ACL list */
891  /* List of TCM sessions associated wth this TPG */
893  /* Pointer to $FABRIC_MOD dependent code */
903 };
904 
905 struct se_wwn {
910 };
911 
912 #endif /* TARGET_CORE_BASE_H */