blob: 9d514e06625f7321adcbc7fbcbe48c7e0eb42bf6 [file] [log] [blame]
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001#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>
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -080011
Nicholas Bellingerfa495152011-07-22 08:24:22 +000012#define TARGET_CORE_MOD_VERSION "v4.1.0-rc1-ml"
Christoph Hellwigc4795fb2011-11-16 09:46:48 -050013#define TARGET_CORE_VERSION TARGET_CORE_MOD_VERSION
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -080014
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -080015/* Maximum Number of LUNs per Target Portal Group */
Andy Groverd0229ae2011-07-08 17:04:53 -070016/* Don't raise above 511 or REPORT_LUNS needs to handle >1 page */
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -080017#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
Lucas De Marchi25985ed2011-03-30 22:57:33 -030024 * 32-byte CDBs to because of legacy issues.
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -080025 *
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
Roland Dreier895f3022011-12-13 14:55:33 -080038#define SPC_ADD_SENSE_LEN_OFFSET 7
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -080039#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
Christoph Hellwigc4795fb2011-11-16 09:46:48 -050058/* 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_READ_ONLY 0x00000001
77#define DF_SPC2_RESERVATIONS 0x00000002
78#define DF_SPC2_RESERVATIONS_WITH_ISID 0x00000004
79
80/* struct se_dev_attrib sanity values */
81/* Default max_unmap_lba_count */
82#define DA_MAX_UNMAP_LBA_COUNT 0
83/* Default max_unmap_block_desc_count */
84#define DA_MAX_UNMAP_BLOCK_DESC_COUNT 0
85/* Default unmap_granularity */
86#define DA_UNMAP_GRANULARITY_DEFAULT 0
87/* Default unmap_granularity_alignment */
88#define DA_UNMAP_GRANULARITY_ALIGNMENT_DEFAULT 0
89/* Emulation for Direct Page Out */
90#define DA_EMULATE_DPO 0
91/* Emulation for Forced Unit Access WRITEs */
92#define DA_EMULATE_FUA_WRITE 1
93/* Emulation for Forced Unit Access READs */
94#define DA_EMULATE_FUA_READ 0
95/* Emulation for WriteCache and SYNCHRONIZE_CACHE */
96#define DA_EMULATE_WRITE_CACHE 0
97/* Emulation for UNIT ATTENTION Interlock Control */
98#define DA_EMULATE_UA_INTLLCK_CTRL 0
99/* Emulation for TASK_ABORTED status (TAS) by default */
100#define DA_EMULATE_TAS 1
101/* Emulation for Thin Provisioning UNMAP using block/blk-lib.c:blkdev_issue_discard() */
102#define DA_EMULATE_TPU 0
103/*
104 * Emulation for Thin Provisioning WRITE_SAME w/ UNMAP=1 bit using
105 * block/blk-lib.c:blkdev_issue_discard()
106 */
107#define DA_EMULATE_TPWS 0
108/* No Emulation for PSCSI by default */
109#define DA_EMULATE_RESERVATIONS 0
110/* No Emulation for PSCSI by default */
111#define DA_EMULATE_ALUA 0
112/* Enforce SCSI Initiator Port TransportID with 'ISID' for PR */
113#define DA_ENFORCE_PR_ISIDS 1
114#define DA_STATUS_MAX_SECTORS_MIN 16
115#define DA_STATUS_MAX_SECTORS_MAX 8192
116/* By default don't report non-rotating (solid state) medium */
117#define DA_IS_NONROT 0
118/* Queue Algorithm Modifier default for restricted reordering in control mode page */
119#define DA_EMULATE_REST_REORD 0
120
121#define SE_MODE_PAGE_BUF 512
122
123
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800124/* struct se_hba->hba_flags */
125enum hba_flags_table {
126 HBA_FLAGS_INTERNAL_USE = 0x01,
127 HBA_FLAGS_PSCSI_MODE = 0x02,
128};
129
130/* struct se_lun->lun_status */
131enum transport_lun_status_table {
132 TRANSPORT_LUN_STATUS_FREE = 0,
133 TRANSPORT_LUN_STATUS_ACTIVE = 1,
134};
135
136/* struct se_portal_group->se_tpg_type */
137enum transport_tpg_type_table {
138 TRANSPORT_TPG_TYPE_NORMAL = 0,
139 TRANSPORT_TPG_TYPE_DISCOVERY = 1,
140};
141
Christoph Hellwigef804a82011-11-23 06:53:58 -0500142/* struct se_task->task_flags */
Christoph Hellwig6c76bf92011-10-12 11:07:03 -0400143enum se_task_flags {
144 TF_ACTIVE = (1 << 0),
145 TF_SENT = (1 << 1),
Nicholas Bellinger2e982ab2011-10-23 18:46:36 -0700146 TF_REQUEST_STOP = (1 << 2),
Christoph Hellwigef804a82011-11-23 06:53:58 -0500147 TF_HAS_SENSE = (1 << 3),
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800148};
149
150/* Special transport agnostic struct se_cmd->t_states */
151enum transport_state_table {
152 TRANSPORT_NO_STATE = 0,
153 TRANSPORT_NEW_CMD = 1,
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800154 TRANSPORT_WRITE_PENDING = 3,
155 TRANSPORT_PROCESS_WRITE = 4,
156 TRANSPORT_PROCESSING = 5,
Christoph Hellwig35e0e752011-10-17 13:56:53 -0400157 TRANSPORT_COMPLETE = 6,
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800158 TRANSPORT_PROCESS_TMR = 9,
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800159 TRANSPORT_ISTATE_PROCESSING = 11,
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800160 TRANSPORT_NEW_CMD_MAP = 16,
Nicholas Bellinger07bde792011-06-13 14:46:09 -0700161 TRANSPORT_COMPLETE_QF_WP = 18,
Christoph Hellwige057f532011-10-17 13:56:41 -0400162 TRANSPORT_COMPLETE_QF_OK = 19,
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800163};
164
165/* Used for struct se_cmd->se_cmd_flags */
166enum se_cmd_flags_table {
167 SCF_SUPPORTED_SAM_OPCODE = 0x00000001,
168 SCF_TRANSPORT_TASK_SENSE = 0x00000002,
169 SCF_EMULATED_TASK_SENSE = 0x00000004,
170 SCF_SCSI_DATA_SG_IO_CDB = 0x00000008,
171 SCF_SCSI_CONTROL_SG_IO_CDB = 0x00000010,
Andy Groverc8e31f22012-01-19 13:39:17 -0800172 SCF_SCSI_NON_DATA_CDB = 0x00000020,
173 SCF_SCSI_TMR_CDB = 0x00000040,
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800174 SCF_SCSI_CDB_EXCEPTION = 0x00000080,
175 SCF_SCSI_RESERVATION_CONFLICT = 0x00000100,
Christoph Hellwig2d3a4b52011-11-14 11:36:29 -0500176 SCF_FUA = 0x00000200,
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800177 SCF_SE_LUN_CMD = 0x00000800,
178 SCF_SE_ALLOW_EOO = 0x00001000,
Christoph Hellwig33c3faf2011-11-14 11:36:30 -0500179 SCF_BIDI = 0x00002000,
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800180 SCF_SENT_CHECK_CONDITION = 0x00004000,
181 SCF_OVERFLOW_BIT = 0x00008000,
182 SCF_UNDERFLOW_BIT = 0x00010000,
183 SCF_SENT_DELAYED_TAS = 0x00020000,
184 SCF_ALUA_NON_OPTIMIZED = 0x00040000,
185 SCF_DELAYED_CMD_FROM_SAM_ATTR = 0x00080000,
Andy Grover5951146d2011-07-19 10:26:37 +0000186 SCF_UNUSED = 0x00100000,
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800187 SCF_PASSTHROUGH_SG_TO_MEM_NOALLOC = 0x00400000,
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800188};
189
190/* struct se_dev_entry->lun_flags and struct se_lun->lun_access */
191enum transport_lunflags_table {
192 TRANSPORT_LUNFLAGS_NO_ACCESS = 0x00,
193 TRANSPORT_LUNFLAGS_INITIATOR_ACCESS = 0x01,
194 TRANSPORT_LUNFLAGS_READ_ONLY = 0x02,
195 TRANSPORT_LUNFLAGS_READ_WRITE = 0x04,
196};
197
198/* struct se_device->dev_status */
199enum transport_device_status_table {
200 TRANSPORT_DEVICE_ACTIVATED = 0x01,
201 TRANSPORT_DEVICE_DEACTIVATED = 0x02,
202 TRANSPORT_DEVICE_QUEUE_FULL = 0x04,
203 TRANSPORT_DEVICE_SHUTDOWN = 0x08,
204 TRANSPORT_DEVICE_OFFLINE_ACTIVATED = 0x10,
205 TRANSPORT_DEVICE_OFFLINE_DEACTIVATED = 0x20,
206};
207
208/*
209 * Used by transport_send_check_condition_and_sense() and se_cmd->scsi_sense_reason
210 * to signal which ASC/ASCQ sense payload should be built.
211 */
212enum tcm_sense_reason_table {
213 TCM_NON_EXISTENT_LUN = 0x01,
214 TCM_UNSUPPORTED_SCSI_OPCODE = 0x02,
215 TCM_INCORRECT_AMOUNT_OF_DATA = 0x03,
216 TCM_UNEXPECTED_UNSOLICITED_DATA = 0x04,
217 TCM_SERVICE_CRC_ERROR = 0x05,
218 TCM_SNACK_REJECTED = 0x06,
219 TCM_SECTOR_COUNT_TOO_MANY = 0x07,
220 TCM_INVALID_CDB_FIELD = 0x08,
221 TCM_INVALID_PARAMETER_LIST = 0x09,
222 TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE = 0x0a,
223 TCM_UNKNOWN_MODE_PAGE = 0x0b,
224 TCM_WRITE_PROTECTED = 0x0c,
225 TCM_CHECK_CONDITION_ABORT_CMD = 0x0d,
226 TCM_CHECK_CONDITION_UNIT_ATTENTION = 0x0e,
227 TCM_CHECK_CONDITION_NOT_READY = 0x0f,
Nicholas Bellinger03e98c92011-11-04 02:36:16 -0700228 TCM_RESERVATION_CONFLICT = 0x10,
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800229};
230
Nicholas Bellingera6360782011-11-18 20:36:22 -0800231enum target_sc_flags_table {
232 TARGET_SCF_BIDI_OP = 0x01,
233 TARGET_SCF_ACK_KREF = 0x02,
234};
235
Christoph Hellwigc4795fb2011-11-16 09:46:48 -0500236/* fabric independent task management function values */
237enum tcm_tmreq_table {
238 TMR_ABORT_TASK = 1,
239 TMR_ABORT_TASK_SET = 2,
240 TMR_CLEAR_ACA = 3,
241 TMR_CLEAR_TASK_SET = 4,
242 TMR_LUN_RESET = 5,
243 TMR_TARGET_WARM_RESET = 6,
244 TMR_TARGET_COLD_RESET = 7,
245 TMR_FABRIC_TMR = 255,
246};
247
248/* fabric independent task management response values */
249enum tcm_tmrsp_table {
250 TMR_FUNCTION_COMPLETE = 0,
251 TMR_TASK_DOES_NOT_EXIST = 1,
252 TMR_LUN_DOES_NOT_EXIST = 2,
253 TMR_TASK_STILL_ALLEGIANT = 3,
254 TMR_TASK_FAILOVER_NOT_SUPPORTED = 4,
255 TMR_TASK_MGMT_FUNCTION_NOT_SUPPORTED = 5,
256 TMR_FUNCTION_AUTHORIZATION_FAILED = 6,
257 TMR_FUNCTION_REJECTED = 255,
258};
259
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800260struct se_obj {
261 atomic_t obj_access_count;
Christoph Hellwige0a53e72011-11-29 03:29:38 -0500262};
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800263
264/*
265 * Used by TCM Core internally to signal if ALUA emulation is enabled or
266 * disabled, or running in with TCM/pSCSI passthrough mode
267 */
268typedef enum {
269 SPC_ALUA_PASSTHROUGH,
270 SPC2_ALUA_DISABLED,
271 SPC3_ALUA_EMULATED
272} t10_alua_index_t;
273
274/*
275 * Used by TCM Core internally to signal if SAM Task Attribute emulation
276 * is enabled or disabled, or running in with TCM/pSCSI passthrough mode
277 */
278typedef enum {
279 SAM_TASK_ATTR_PASSTHROUGH,
280 SAM_TASK_ATTR_UNTAGGED,
281 SAM_TASK_ATTR_EMULATED
282} t10_task_attr_index_t;
283
Nicholas Bellingere89d15e2011-02-09 15:35:03 -0800284/*
285 * Used for target SCSI statistics
286 */
287typedef enum {
288 SCSI_INST_INDEX,
289 SCSI_DEVICE_INDEX,
290 SCSI_AUTH_INTR_INDEX,
291 SCSI_INDEX_TYPE_MAX
292} scsi_index_t;
293
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800294struct se_cmd;
295
296struct t10_alua {
297 t10_alua_index_t alua_type;
298 /* ALUA Target Port Group ID */
299 u16 alua_tg_pt_gps_counter;
300 u32 alua_tg_pt_gps_count;
301 spinlock_t tg_pt_gps_lock;
302 struct se_subsystem_dev *t10_sub_dev;
303 /* Used for default ALUA Target Port Group */
304 struct t10_alua_tg_pt_gp *default_tg_pt_gp;
305 /* Used for default ALUA Target Port Group ConfigFS group */
306 struct config_group alua_tg_pt_gps_group;
307 int (*alua_state_check)(struct se_cmd *, unsigned char *, u8 *);
308 struct list_head tg_pt_gps_list;
Christoph Hellwige0a53e72011-11-29 03:29:38 -0500309};
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800310
311struct t10_alua_lu_gp {
312 u16 lu_gp_id;
313 int lu_gp_valid_id;
314 u32 lu_gp_members;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800315 atomic_t lu_gp_ref_cnt;
316 spinlock_t lu_gp_lock;
317 struct config_group lu_gp_group;
Andy Grovere3d6f902011-07-19 08:55:10 +0000318 struct list_head lu_gp_node;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800319 struct list_head lu_gp_mem_list;
Christoph Hellwige0a53e72011-11-29 03:29:38 -0500320};
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800321
322struct t10_alua_lu_gp_member {
Dan Carpenter5dd7ed22011-03-14 04:06:01 -0700323 bool lu_gp_assoc;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800324 atomic_t lu_gp_mem_ref_cnt;
325 spinlock_t lu_gp_mem_lock;
326 struct t10_alua_lu_gp *lu_gp;
327 struct se_device *lu_gp_mem_dev;
328 struct list_head lu_gp_mem_list;
Christoph Hellwige0a53e72011-11-29 03:29:38 -0500329};
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800330
331struct t10_alua_tg_pt_gp {
332 u16 tg_pt_gp_id;
333 int tg_pt_gp_valid_id;
334 int tg_pt_gp_alua_access_status;
335 int tg_pt_gp_alua_access_type;
336 int tg_pt_gp_nonop_delay_msecs;
337 int tg_pt_gp_trans_delay_msecs;
338 int tg_pt_gp_pref;
339 int tg_pt_gp_write_metadata;
340 /* Used by struct t10_alua_tg_pt_gp->tg_pt_gp_md_buf_len */
341#define ALUA_MD_BUF_LEN 1024
342 u32 tg_pt_gp_md_buf_len;
343 u32 tg_pt_gp_members;
344 atomic_t tg_pt_gp_alua_access_state;
345 atomic_t tg_pt_gp_ref_cnt;
346 spinlock_t tg_pt_gp_lock;
347 struct mutex tg_pt_gp_md_mutex;
348 struct se_subsystem_dev *tg_pt_gp_su_dev;
349 struct config_group tg_pt_gp_group;
350 struct list_head tg_pt_gp_list;
351 struct list_head tg_pt_gp_mem_list;
Christoph Hellwige0a53e72011-11-29 03:29:38 -0500352};
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800353
354struct t10_alua_tg_pt_gp_member {
Dan Carpenter5dd7ed22011-03-14 04:06:01 -0700355 bool tg_pt_gp_assoc;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800356 atomic_t tg_pt_gp_mem_ref_cnt;
357 spinlock_t tg_pt_gp_mem_lock;
358 struct t10_alua_tg_pt_gp *tg_pt_gp;
359 struct se_port *tg_pt;
360 struct list_head tg_pt_gp_mem_list;
Christoph Hellwige0a53e72011-11-29 03:29:38 -0500361};
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800362
363struct t10_vpd {
364 unsigned char device_identifier[INQUIRY_VPD_DEVICE_IDENTIFIER_LEN];
365 int protocol_identifier_set;
366 u32 protocol_identifier;
367 u32 device_identifier_code_set;
368 u32 association;
369 u32 device_identifier_type;
370 struct list_head vpd_list;
Christoph Hellwige0a53e72011-11-29 03:29:38 -0500371};
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800372
373struct t10_wwn {
Andy Grovere3d6f902011-07-19 08:55:10 +0000374 char vendor[8];
375 char model[16];
376 char revision[4];
377 char unit_serial[INQUIRY_VPD_SERIAL_LEN];
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800378 spinlock_t t10_vpd_lock;
379 struct se_subsystem_dev *t10_sub_dev;
380 struct config_group t10_wwn_group;
381 struct list_head t10_vpd_list;
Christoph Hellwige0a53e72011-11-29 03:29:38 -0500382};
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800383
384
385/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300386 * Used by TCM Core internally to signal if >= SPC-3 persistent reservations
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800387 * emulation is enabled or disabled, or running in with TCM/pSCSI passthrough
388 * mode
389 */
390typedef enum {
391 SPC_PASSTHROUGH,
392 SPC2_RESERVATIONS,
393 SPC3_PERSISTENT_RESERVATIONS
394} t10_reservations_index_t;
395
396struct t10_pr_registration {
397 /* Used for fabrics that contain WWN+ISID */
398#define PR_REG_ISID_LEN 16
399 /* PR_REG_ISID_LEN + ',i,0x' */
400#define PR_REG_ISID_ID_LEN (PR_REG_ISID_LEN + 5)
401 char pr_reg_isid[PR_REG_ISID_LEN];
402 /* Used during APTPL metadata reading */
403#define PR_APTPL_MAX_IPORT_LEN 256
404 unsigned char pr_iport[PR_APTPL_MAX_IPORT_LEN];
405 /* Used during APTPL metadata reading */
406#define PR_APTPL_MAX_TPORT_LEN 256
407 unsigned char pr_tport[PR_APTPL_MAX_TPORT_LEN];
408 /* For writing out live meta data */
409 unsigned char *pr_aptpl_buf;
410 u16 pr_aptpl_rpti;
411 u16 pr_reg_tpgt;
412 /* Reservation effects all target ports */
413 int pr_reg_all_tg_pt;
414 /* Activate Persistence across Target Power Loss */
415 int pr_reg_aptpl;
416 int pr_res_holder;
417 int pr_res_type;
418 int pr_res_scope;
419 /* Used for fabric initiator WWPNs using a ISID */
Dan Carpenter5dd7ed22011-03-14 04:06:01 -0700420 bool isid_present_at_reg;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800421 u32 pr_res_mapped_lun;
422 u32 pr_aptpl_target_lun;
423 u32 pr_res_generation;
424 u64 pr_reg_bin_isid;
425 u64 pr_res_key;
426 atomic_t pr_res_holders;
427 struct se_node_acl *pr_reg_nacl;
428 struct se_dev_entry *pr_reg_deve;
429 struct se_lun *pr_reg_tg_pt_lun;
430 struct list_head pr_reg_list;
431 struct list_head pr_reg_abort_list;
432 struct list_head pr_reg_aptpl_list;
433 struct list_head pr_reg_atp_list;
434 struct list_head pr_reg_atp_mem_list;
Christoph Hellwige0a53e72011-11-29 03:29:38 -0500435};
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800436
437/*
438 * This set of function pointer ops is set based upon SPC3_PERSISTENT_RESERVATIONS,
439 * SPC2_RESERVATIONS or SPC_PASSTHROUGH in drivers/target/target_core_pr.c:
440 * core_setup_reservations()
441 */
442struct t10_reservation_ops {
443 int (*t10_reservation_check)(struct se_cmd *, u32 *);
444 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
445 int (*t10_pr_register)(struct se_cmd *);
446 int (*t10_pr_clear)(struct se_cmd *);
447};
448
Andy Grovere3d6f902011-07-19 08:55:10 +0000449struct t10_reservation {
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800450 /* Reservation effects all target ports */
451 int pr_all_tg_pt;
452 /* Activate Persistence across Target Power Loss enabled
453 * for SCSI device */
454 int pr_aptpl_active;
Andy Grovere3d6f902011-07-19 08:55:10 +0000455 /* Used by struct t10_reservation->pr_aptpl_buf_len */
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800456#define PR_APTPL_BUF_LEN 8192
457 u32 pr_aptpl_buf_len;
458 u32 pr_generation;
459 t10_reservations_index_t res_type;
460 spinlock_t registration_lock;
461 spinlock_t aptpl_reg_lock;
462 /*
463 * This will always be set by one individual I_T Nexus.
464 * However with all_tg_pt=1, other I_T Nexus from the
465 * same initiator can access PR reg/res info on a different
466 * target port.
467 *
468 * There is also the 'All Registrants' case, where there is
469 * a single *pr_res_holder of the reservation, but all
470 * registrations are considered reservation holders.
471 */
472 struct se_node_acl *pr_res_holder;
473 struct list_head registration_list;
474 struct list_head aptpl_reg_list;
475 struct t10_reservation_ops pr_ops;
Christoph Hellwige0a53e72011-11-29 03:29:38 -0500476};
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800477
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800478struct se_queue_obj {
479 atomic_t queue_cnt;
480 spinlock_t cmd_queue_lock;
481 struct list_head qobj_list;
482 wait_queue_head_t thread_wq;
Christoph Hellwige0a53e72011-11-29 03:29:38 -0500483};
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800484
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800485struct se_task {
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800486 unsigned long long task_lba;
Christoph Hellwig3189b062011-10-12 11:07:07 -0400487 u32 task_sectors;
488 u32 task_size;
489 struct se_cmd *task_se_cmd;
490 struct scatterlist *task_sg;
Christoph Hellwig3189b062011-10-12 11:07:07 -0400491 u32 task_sg_nents;
492 u16 task_flags;
Christoph Hellwig3189b062011-10-12 11:07:07 -0400493 u8 task_scsi_status;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800494 enum dma_data_direction task_data_direction;
Christoph Hellwig3189b062011-10-12 11:07:07 -0400495 struct list_head t_list;
496 struct list_head t_execute_list;
497 struct list_head t_state_list;
Christoph Hellwig1880807a2011-11-23 06:54:36 -0500498 bool t_state_active;
Christoph Hellwig3189b062011-10-12 11:07:07 -0400499 struct completion task_stop_comp;
Christoph Hellwige0a53e72011-11-29 03:29:38 -0500500};
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800501
Andy Groverc8e31f22012-01-19 13:39:17 -0800502struct se_tmr_req {
503 /* Task Management function to be performed */
504 u8 function;
505 /* Task Management response to send */
506 u8 response;
507 int call_transport;
508 /* Reference to ITT that Task Mgmt should be performed */
509 u32 ref_task_tag;
510 /* 64-bit encoded SAM LUN from $FABRIC_MOD TMR header */
511 u64 ref_task_lun;
512 void *fabric_tmr_ptr;
513 struct se_cmd *task_cmd;
514 struct se_cmd *ref_cmd;
515 struct se_device *tmr_dev;
516 struct se_lun *tmr_lun;
517 struct list_head tmr_list;
518};
519
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800520struct se_cmd {
521 /* SAM response code being sent to initiator */
522 u8 scsi_status;
523 u8 scsi_asc;
524 u8 scsi_ascq;
525 u8 scsi_sense_reason;
526 u16 scsi_sense_length;
527 /* Delay for ALUA Active/NonOptimized state access in milliseconds */
528 int alua_nonop_delay;
529 /* See include/linux/dma-mapping.h */
530 enum dma_data_direction data_direction;
531 /* For SAM Task Attribute */
532 int sam_task_attr;
533 /* Transport protocol dependent state, see transport_state_table */
534 enum transport_state_table t_state;
Nicholas Bellingera17f0912011-11-02 21:52:08 -0700535 /* Used to signal cmd->se_tfo->check_release_cmd() usage per cmd */
Bart Van Assche5f655e82011-11-08 20:46:29 +0100536 unsigned check_release:1;
537 unsigned cmd_wait_set:1;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800538 /* See se_cmd_flags_table */
539 u32 se_cmd_flags;
540 u32 se_ordered_id;
541 /* Total size in bytes associated with command */
542 u32 data_length;
543 /* SCSI Presented Data Transfer Length */
544 u32 cmd_spdtl;
545 u32 residual_count;
546 u32 orig_fe_lun;
547 /* Persistent Reservation key */
548 u64 pr_res_key;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800549 /* Used for sense data */
550 void *sense_buffer;
Andy Grover5951146d2011-07-19 10:26:37 +0000551 struct list_head se_delayed_node;
Andy Grover5951146d2011-07-19 10:26:37 +0000552 struct list_head se_lun_node;
Nicholas Bellinger07bde792011-06-13 14:46:09 -0700553 struct list_head se_qf_node;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800554 struct se_device *se_dev;
555 struct se_dev_entry *se_deve;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800556 struct se_lun *se_lun;
557 /* Only used for internal passthrough and legacy TCM fabric modules */
558 struct se_session *se_sess;
559 struct se_tmr_req *se_tmr_req;
Andy Grover5951146d2011-07-19 10:26:37 +0000560 struct list_head se_queue_node;
Nicholas Bellingera17f0912011-11-02 21:52:08 -0700561 struct list_head se_cmd_list;
562 struct completion cmd_wait_comp;
Nicholas Bellinger7481deb2011-11-12 00:32:17 -0800563 struct kref cmd_kref;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800564 struct target_core_fabric_ops *se_tfo;
Christoph Hellwige76a35d2011-11-03 17:50:42 -0400565 int (*execute_task)(struct se_task *);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800566 void (*transport_complete_callback)(struct se_cmd *);
Nicholas Bellinger07bde792011-06-13 14:46:09 -0700567
Andy Grovera1d8b492011-05-02 17:12:10 -0700568 unsigned char *t_task_cdb;
569 unsigned char __t_task_cdb[TCM_MAX_COMMAND_SIZE];
570 unsigned long long t_task_lba;
Andy Grovera1d8b492011-05-02 17:12:10 -0700571 u32 t_tasks_sg_chained_no;
572 atomic_t t_fe_count;
573 atomic_t t_se_count;
574 atomic_t t_task_cdbs_left;
575 atomic_t t_task_cdbs_ex_left;
Andy Grovera1d8b492011-05-02 17:12:10 -0700576 atomic_t t_task_cdbs_sent;
Christoph Hellwig7d680f32011-12-21 14:13:47 -0500577 unsigned int transport_state;
578#define CMD_T_ABORTED (1 << 0)
579#define CMD_T_ACTIVE (1 << 1)
580#define CMD_T_COMPLETE (1 << 2)
581#define CMD_T_QUEUED (1 << 3)
582#define CMD_T_SENT (1 << 4)
583#define CMD_T_STOP (1 << 5)
584#define CMD_T_FAILED (1 << 6)
585#define CMD_T_LUN_STOP (1 << 7)
586#define CMD_T_LUN_FE_STOP (1 << 8)
587#define CMD_T_DEV_ACTIVE (1 << 9)
Andy Grovera1d8b492011-05-02 17:12:10 -0700588 spinlock_t t_state_lock;
589 struct completion t_transport_stop_comp;
590 struct completion transport_lun_fe_stop_comp;
591 struct completion transport_lun_stop_comp;
592 struct scatterlist *t_tasks_sg_chained;
Andy Grover05d1c7c2011-07-20 19:13:28 +0000593
Christoph Hellwig35e0e752011-10-17 13:56:53 -0400594 struct work_struct work;
595
Andy Groverec98f782011-07-20 19:28:46 +0000596 struct scatterlist *t_data_sg;
597 unsigned int t_data_nents;
Andy Grover49493142012-01-16 16:57:08 -0800598 void *t_data_vmap;
Andy Groverec98f782011-07-20 19:28:46 +0000599 struct scatterlist *t_bidi_data_sg;
600 unsigned int t_bidi_data_nents;
601
Andy Grovera1d8b492011-05-02 17:12:10 -0700602 /* Used for BIDI READ */
Andy Grovera1d8b492011-05-02 17:12:10 -0700603 struct list_head t_task_list;
604 u32 t_task_list_num;
605
Christoph Hellwige0a53e72011-11-29 03:29:38 -0500606};
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800607
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800608struct se_ua {
609 u8 ua_asc;
610 u8 ua_ascq;
611 struct se_node_acl *ua_nacl;
612 struct list_head ua_dev_list;
613 struct list_head ua_nacl_list;
Christoph Hellwige0a53e72011-11-29 03:29:38 -0500614};
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800615
616struct se_node_acl {
617 char initiatorname[TRANSPORT_IQN_LEN];
618 /* Used to signal demo mode created ACL, disabled by default */
Dan Carpenter5dd7ed22011-03-14 04:06:01 -0700619 bool dynamic_node_acl;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800620 u32 queue_depth;
621 u32 acl_index;
622 u64 num_cmds;
623 u64 read_bytes;
624 u64 write_bytes;
625 spinlock_t stats_lock;
626 /* Used for PR SPEC_I_PT=1 and REGISTER_AND_MOVE */
627 atomic_t acl_pr_ref_count;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800628 struct se_dev_entry *device_list;
629 struct se_session *nacl_sess;
630 struct se_portal_group *se_tpg;
631 spinlock_t device_list_lock;
632 spinlock_t nacl_sess_lock;
633 struct config_group acl_group;
634 struct config_group acl_attrib_group;
635 struct config_group acl_auth_group;
636 struct config_group acl_param_group;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700637 struct config_group acl_fabric_stat_group;
638 struct config_group *acl_default_groups[5];
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800639 struct list_head acl_list;
640 struct list_head acl_sess_list;
Christoph Hellwige0a53e72011-11-29 03:29:38 -0500641};
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800642
643struct se_session {
Bart Van Assche5f655e82011-11-08 20:46:29 +0100644 unsigned sess_tearing_down:1;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800645 u64 sess_bin_isid;
646 struct se_node_acl *se_node_acl;
647 struct se_portal_group *se_tpg;
648 void *fabric_sess_ptr;
649 struct list_head sess_list;
650 struct list_head sess_acl_list;
Nicholas Bellingera17f0912011-11-02 21:52:08 -0700651 struct list_head sess_cmd_list;
652 struct list_head sess_wait_list;
653 spinlock_t sess_cmd_lock;
Christoph Hellwige0a53e72011-11-29 03:29:38 -0500654};
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800655
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800656struct se_device;
657struct se_transform_info;
658struct scatterlist;
659
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700660struct se_ml_stat_grps {
661 struct config_group stat_group;
662 struct config_group scsi_auth_intr_group;
663 struct config_group scsi_att_intr_port_group;
664};
665
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800666struct se_lun_acl {
667 char initiatorname[TRANSPORT_IQN_LEN];
668 u32 mapped_lun;
669 struct se_node_acl *se_lun_nacl;
670 struct se_lun *se_lun;
671 struct list_head lacl_list;
672 struct config_group se_lun_group;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700673 struct se_ml_stat_grps ml_stat_grps;
Christoph Hellwige0a53e72011-11-29 03:29:38 -0500674};
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800675
676struct se_dev_entry {
Dan Carpenter5dd7ed22011-03-14 04:06:01 -0700677 bool def_pr_registered;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800678 /* See transport_lunflags_table */
679 u32 lun_flags;
680 u32 deve_cmds;
681 u32 mapped_lun;
682 u32 average_bytes;
683 u32 last_byte_count;
684 u32 total_cmds;
685 u32 total_bytes;
686 u64 pr_res_key;
687 u64 creation_time;
688 u32 attach_count;
689 u64 read_bytes;
690 u64 write_bytes;
691 atomic_t ua_count;
692 /* Used for PR SPEC_I_PT=1 and REGISTER_AND_MOVE */
693 atomic_t pr_ref_count;
694 struct se_lun_acl *se_lun_acl;
695 spinlock_t ua_lock;
696 struct se_lun *se_lun;
697 struct list_head alua_port_list;
698 struct list_head ua_list;
Christoph Hellwige0a53e72011-11-29 03:29:38 -0500699};
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800700
701struct se_dev_limits {
702 /* Max supported HW queue depth */
703 u32 hw_queue_depth;
704 /* Max supported virtual queue depth */
705 u32 queue_depth;
706 /* From include/linux/blkdev.h for the other HW/SW limits. */
707 struct queue_limits limits;
Christoph Hellwige0a53e72011-11-29 03:29:38 -0500708};
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800709
710struct se_dev_attrib {
711 int emulate_dpo;
712 int emulate_fua_write;
713 int emulate_fua_read;
714 int emulate_write_cache;
715 int emulate_ua_intlck_ctrl;
716 int emulate_tas;
717 int emulate_tpu;
718 int emulate_tpws;
719 int emulate_reservations;
720 int emulate_alua;
721 int enforce_pr_isids;
Roland Dreiere22a7f02011-07-05 13:34:52 -0700722 int is_nonrot;
Nicholas Bellinger5de619a2011-07-17 02:57:58 -0700723 int emulate_rest_reord;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800724 u32 hw_block_size;
725 u32 block_size;
726 u32 hw_max_sectors;
727 u32 max_sectors;
728 u32 optimal_sectors;
729 u32 hw_queue_depth;
730 u32 queue_depth;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800731 u32 max_unmap_lba_count;
732 u32 max_unmap_block_desc_count;
733 u32 unmap_granularity;
734 u32 unmap_granularity_alignment;
735 struct se_subsystem_dev *da_sub_dev;
736 struct config_group da_group;
Christoph Hellwige0a53e72011-11-29 03:29:38 -0500737};
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800738
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700739struct se_dev_stat_grps {
740 struct config_group stat_group;
741 struct config_group scsi_dev_group;
742 struct config_group scsi_tgt_dev_group;
743 struct config_group scsi_lu_group;
744};
745
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800746struct se_subsystem_dev {
747/* Used for struct se_subsystem_dev-->se_dev_alias, must be less than PAGE_SIZE */
748#define SE_DEV_ALIAS_LEN 512
749 unsigned char se_dev_alias[SE_DEV_ALIAS_LEN];
750/* Used for struct se_subsystem_dev->se_dev_udev_path[], must be less than PAGE_SIZE */
751#define SE_UDEV_PATH_LEN 512
752 unsigned char se_dev_udev_path[SE_UDEV_PATH_LEN];
753 u32 su_dev_flags;
754 struct se_hba *se_dev_hba;
755 struct se_device *se_dev_ptr;
756 struct se_dev_attrib se_dev_attrib;
757 /* T10 Asymmetric Logical Unit Assignment for Target Ports */
758 struct t10_alua t10_alua;
759 /* T10 Inquiry and VPD WWN Information */
760 struct t10_wwn t10_wwn;
761 /* T10 SPC-2 + SPC-3 Reservations */
Andy Grovere3d6f902011-07-19 08:55:10 +0000762 struct t10_reservation t10_pr;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800763 spinlock_t se_dev_lock;
764 void *se_dev_su_ptr;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800765 struct config_group se_dev_group;
766 /* For T10 Reservations */
767 struct config_group se_dev_pr_group;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700768 /* For target_core_stat.c groups */
769 struct se_dev_stat_grps dev_stat_grps;
Christoph Hellwige0a53e72011-11-29 03:29:38 -0500770};
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800771
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800772struct se_device {
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800773 /* RELATIVE TARGET PORT IDENTIFER Counter */
774 u16 dev_rpti_counter;
775 /* Used for SAM Task Attribute ordering */
776 u32 dev_cur_ordered_id;
777 u32 dev_flags;
778 u32 dev_port_count;
779 /* See transport_device_status_table */
780 u32 dev_status;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800781 /* Physical device queue depth */
782 u32 queue_depth;
783 /* Used for SPC-2 reservations enforce of ISIDs */
784 u64 dev_res_bin_isid;
785 t10_task_attr_index_t dev_task_attr_type;
786 /* Pointer to transport specific device structure */
787 void *dev_ptr;
788 u32 dev_index;
789 u64 creation_time;
790 u32 num_resets;
791 u64 num_cmds;
792 u64 read_bytes;
793 u64 write_bytes;
794 spinlock_t stats_lock;
795 /* Active commands on this virtual SE device */
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800796 atomic_t simple_cmds;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800797 atomic_t dev_ordered_id;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800798 atomic_t execute_tasks;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800799 atomic_t dev_ordered_sync;
Nicholas Bellinger07bde792011-06-13 14:46:09 -0700800 atomic_t dev_qf_count;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800801 struct se_obj dev_obj;
802 struct se_obj dev_access_obj;
803 struct se_obj dev_export_obj;
Andy Grovere3d6f902011-07-19 08:55:10 +0000804 struct se_queue_obj dev_queue_obj;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800805 spinlock_t delayed_cmd_lock;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800806 spinlock_t execute_task_lock;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800807 spinlock_t dev_reservation_lock;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800808 spinlock_t dev_status_lock;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800809 spinlock_t se_port_lock;
810 spinlock_t se_tmr_lock;
Nicholas Bellinger07bde792011-06-13 14:46:09 -0700811 spinlock_t qf_cmd_lock;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800812 /* Used for legacy SPC-2 reservationsa */
813 struct se_node_acl *dev_reserved_node_acl;
814 /* Used for ALUA Logical Unit Group membership */
815 struct t10_alua_lu_gp_member *dev_alua_lu_gp_mem;
816 /* Used for SPC-3 Persistent Reservations */
817 struct t10_pr_registration *dev_pr_res_holder;
818 struct list_head dev_sep_list;
819 struct list_head dev_tmr_list;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800820 /* Pointer to descriptor for processing thread */
821 struct task_struct *process_thread;
Nicholas Bellinger07bde792011-06-13 14:46:09 -0700822 struct work_struct qf_work_queue;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800823 struct list_head delayed_cmd_list;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800824 struct list_head execute_task_list;
825 struct list_head state_task_list;
Nicholas Bellinger07bde792011-06-13 14:46:09 -0700826 struct list_head qf_cmd_list;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800827 /* Pointer to associated SE HBA */
828 struct se_hba *se_hba;
829 struct se_subsystem_dev *se_sub_dev;
830 /* Pointer to template of function pointers for transport */
831 struct se_subsystem_api *transport;
832 /* Linked list for struct se_hba struct se_device list */
833 struct list_head dev_list;
Christoph Hellwige0a53e72011-11-29 03:29:38 -0500834};
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800835
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800836struct se_hba {
837 u16 hba_tpgt;
838 u32 hba_id;
839 /* See hba_flags_table */
840 u32 hba_flags;
841 /* Virtual iSCSI devices attached. */
842 u32 dev_count;
843 u32 hba_index;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800844 /* Pointer to transport specific host structure. */
845 void *hba_ptr;
846 /* Linked list for struct se_device */
847 struct list_head hba_dev_list;
Andy Grovere3d6f902011-07-19 08:55:10 +0000848 struct list_head hba_node;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800849 spinlock_t device_lock;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800850 struct config_group hba_group;
851 struct mutex hba_access_mutex;
852 struct se_subsystem_api *transport;
Christoph Hellwige0a53e72011-11-29 03:29:38 -0500853};
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800854
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700855struct se_port_stat_grps {
856 struct config_group stat_group;
857 struct config_group scsi_port_group;
858 struct config_group scsi_tgt_port_group;
859 struct config_group scsi_transport_group;
860};
861
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800862struct se_lun {
863 /* See transport_lun_status_table */
864 enum transport_lun_status_table lun_status;
865 u32 lun_access;
866 u32 lun_flags;
867 u32 unpacked_lun;
868 atomic_t lun_acl_count;
869 spinlock_t lun_acl_lock;
870 spinlock_t lun_cmd_lock;
871 spinlock_t lun_sep_lock;
872 struct completion lun_shutdown_comp;
873 struct list_head lun_cmd_list;
874 struct list_head lun_acl_list;
875 struct se_device *lun_se_dev;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700876 struct se_port *lun_sep;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800877 struct config_group lun_group;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700878 struct se_port_stat_grps port_stat_grps;
Christoph Hellwige0a53e72011-11-29 03:29:38 -0500879};
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800880
Nicholas Bellingere89d15e2011-02-09 15:35:03 -0800881struct scsi_port_stats {
882 u64 cmd_pdus;
883 u64 tx_data_octets;
884 u64 rx_data_octets;
Christoph Hellwige0a53e72011-11-29 03:29:38 -0500885};
Nicholas Bellingere89d15e2011-02-09 15:35:03 -0800886
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800887struct se_port {
888 /* RELATIVE TARGET PORT IDENTIFER */
889 u16 sep_rtpi;
890 int sep_tg_pt_secondary_stat;
891 int sep_tg_pt_secondary_write_md;
892 u32 sep_index;
893 struct scsi_port_stats sep_stats;
894 /* Used for ALUA Target Port Groups membership */
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800895 atomic_t sep_tg_pt_secondary_offline;
896 /* Used for PR ALL_TG_PT=1 */
897 atomic_t sep_tg_pt_ref_cnt;
898 spinlock_t sep_alua_lock;
899 struct mutex sep_tg_pt_md_mutex;
900 struct t10_alua_tg_pt_gp_member *sep_alua_tg_pt_gp_mem;
901 struct se_lun *sep_lun;
902 struct se_portal_group *sep_tpg;
903 struct list_head sep_alua_list;
904 struct list_head sep_list;
Christoph Hellwige0a53e72011-11-29 03:29:38 -0500905};
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800906
907struct se_tpg_np {
Nicholas Bellinger1f6fe7c2011-02-09 15:34:54 -0800908 struct se_portal_group *tpg_np_parent;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800909 struct config_group tpg_np_group;
Christoph Hellwige0a53e72011-11-29 03:29:38 -0500910};
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800911
912struct se_portal_group {
913 /* Type of target portal group, see transport_tpg_type_table */
914 enum transport_tpg_type_table se_tpg_type;
915 /* Number of ACLed Initiator Nodes for this TPG */
916 u32 num_node_acls;
917 /* Used for PR SPEC_I_PT=1 and REGISTER_AND_MOVE */
918 atomic_t tpg_pr_ref_count;
919 /* Spinlock for adding/removing ACLed Nodes */
920 spinlock_t acl_node_lock;
921 /* Spinlock for adding/removing sessions */
922 spinlock_t session_lock;
923 spinlock_t tpg_lun_lock;
924 /* Pointer to $FABRIC_MOD portal group */
925 void *se_tpg_fabric_ptr;
Andy Grovere3d6f902011-07-19 08:55:10 +0000926 struct list_head se_tpg_node;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800927 /* linked list for initiator ACL list */
928 struct list_head acl_node_list;
929 struct se_lun *tpg_lun_list;
930 struct se_lun tpg_virt_lun0;
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300931 /* List of TCM sessions associated wth this TPG */
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800932 struct list_head tpg_sess_list;
933 /* Pointer to $FABRIC_MOD dependent code */
934 struct target_core_fabric_ops *se_tpg_tfo;
935 struct se_wwn *se_tpg_wwn;
936 struct config_group tpg_group;
937 struct config_group *tpg_default_groups[6];
938 struct config_group tpg_lun_group;
939 struct config_group tpg_np_group;
940 struct config_group tpg_acl_group;
941 struct config_group tpg_attrib_group;
942 struct config_group tpg_param_group;
Christoph Hellwige0a53e72011-11-29 03:29:38 -0500943};
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800944
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800945struct se_wwn {
946 struct target_fabric_configfs *wwn_tf;
947 struct config_group wwn_group;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700948 struct config_group *wwn_default_groups[2];
949 struct config_group fabric_stat_group;
Christoph Hellwige0a53e72011-11-29 03:29:38 -0500950};
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800951
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800952#endif /* TARGET_CORE_BASE_H */