Merge tag 'tpm-fixes-for-4.2-rc2' of https://github.com/PeterHuewe/linux-tpmdd into...
[firefly-linux-kernel-4.4.55.git] / include / target / target_core_base.h
index ee7abdd6b7a2fd265dc1322729b7209a2f572962..17ae2d6a4891e57245c16fbeb4e2a8a6462d32d0 100644 (file)
@@ -6,34 +6,21 @@
 #include <linux/dma-mapping.h>
 #include <linux/blkdev.h>
 #include <linux/percpu_ida.h>
-#include <scsi/scsi_cmnd.h>
 #include <net/sock.h>
 #include <net/tcp.h>
 
-#define TARGET_CORE_MOD_VERSION                "v4.1.0"
-#define TARGET_CORE_VERSION            TARGET_CORE_MOD_VERSION
+#define TARGET_CORE_VERSION            "v5.0"
 
-/* Maximum Number of LUNs per Target Portal Group */
-/* Don't raise above 511 or REPORT_LUNS needs to handle >1 page */
-#define TRANSPORT_MAX_LUNS_PER_TPG             256
 /*
- * By default we use 32-byte CDBs in TCM Core and subsystem plugin code.
- *
- * Note that both include/scsi/scsi_cmnd.h:MAX_COMMAND_SIZE and
- * include/linux/blkdev.h:BLOCK_MAX_CDB as of v2.6.36-rc4 still use
- * 16-byte CDBs by default and require an extra allocation for
- * 32-byte CDBs to because of legacy issues.
- *
- * Within TCM Core there are no such legacy limitiations, so we go ahead
- * use 32-byte CDBs by default and use include/scsi/scsi.h:scsi_command_size()
- * within all TCM Core and subsystem plugin code.
+ * Maximum size of a CDB that can be stored in se_cmd without allocating
+ * memory dynamically for the CDB.
  */
 #define TCM_MAX_COMMAND_SIZE                   32
 /*
  * From include/scsi/scsi_cmnd.h:SCSI_SENSE_BUFFERSIZE, currently
  * defined 96, but the real limit is 252 (or 260 including the header)
  */
-#define TRANSPORT_SENSE_BUFFER                 SCSI_SENSE_BUFFERSIZE
+#define TRANSPORT_SENSE_BUFFER                 96
 /* Used by transport_send_check_condition_and_sense() */
 #define SPC_SENSE_KEY_OFFSET                   2
 #define SPC_ADD_SENSE_LEN_OFFSET               7
@@ -304,22 +291,13 @@ struct t10_alua_tg_pt_gp {
        struct se_device *tg_pt_gp_dev;
        struct config_group tg_pt_gp_group;
        struct list_head tg_pt_gp_list;
-       struct list_head tg_pt_gp_mem_list;
-       struct se_port *tg_pt_gp_alua_port;
+       struct list_head tg_pt_gp_lun_list;
+       struct se_lun *tg_pt_gp_alua_lun;
        struct se_node_acl *tg_pt_gp_alua_nacl;
        struct delayed_work tg_pt_gp_transition_work;
        struct completion *tg_pt_gp_transition_complete;
 };
 
-struct t10_alua_tg_pt_gp_member {
-       bool tg_pt_gp_assoc;
-       atomic_t tg_pt_gp_mem_ref_cnt;
-       spinlock_t tg_pt_gp_mem_lock;
-       struct t10_alua_tg_pt_gp *tg_pt_gp;
-       struct se_port *tg_pt;
-       struct list_head tg_pt_gp_mem_list;
-};
-
 struct t10_vpd {
        unsigned char device_identifier[INQUIRY_VPD_DEVICE_IDENTIFIER_LEN];
        int protocol_identifier_set;
@@ -364,8 +342,8 @@ struct t10_pr_registration {
        int pr_res_scope;
        /* Used for fabric initiator WWPNs using a ISID */
        bool isid_present_at_reg;
-       u32 pr_res_mapped_lun;
-       u32 pr_aptpl_target_lun;
+       u64 pr_res_mapped_lun;
+       u64 pr_aptpl_target_lun;
        u16 tg_pt_sep_rtpi;
        u32 pr_res_generation;
        u64 pr_reg_bin_isid;
@@ -485,7 +463,7 @@ struct se_cmd {
        /* Total size in bytes associated with command */
        u32                     data_length;
        u32                     residual_count;
-       u32                     orig_fe_lun;
+       u64                     orig_fe_lun;
        /* Persistent Reservation key */
        u64                     pr_res_key;
        /* Used for sense data */
@@ -502,9 +480,8 @@ struct se_cmd {
        struct kref             cmd_kref;
        const struct target_core_fabric_ops *se_tfo;
        sense_reason_t          (*execute_cmd)(struct se_cmd *);
-       sense_reason_t          (*execute_rw)(struct se_cmd *, struct scatterlist *,
-                                             u32, enum dma_data_direction);
        sense_reason_t (*transport_complete_callback)(struct se_cmd *, bool);
+       void                    *protocol_data;
 
        unsigned char           *t_task_cdb;
        unsigned char           __t_task_cdb[TCM_MAX_COMMAND_SIZE];
@@ -560,7 +537,6 @@ struct se_cmd {
 struct se_ua {
        u8                      ua_asc;
        u8                      ua_ascq;
-       struct se_node_acl      *ua_nacl;
        struct list_head        ua_nacl_list;
 };
 
@@ -623,7 +599,7 @@ struct se_ml_stat_grps {
 
 struct se_lun_acl {
        char                    initiatorname[TRANSPORT_IQN_LEN];
-       u32                     mapped_lun;
+       u64                     mapped_lun;
        struct se_node_acl      *se_lun_nacl;
        struct se_lun           *se_lun;
        struct config_group     se_lun_group;
@@ -632,10 +608,10 @@ struct se_lun_acl {
 
 struct se_dev_entry {
        /* See transport_lunflags_table */
-       u32                     lun_flags;
-       u32                     mapped_lun;
+       u64                     mapped_lun;
        u64                     pr_res_key;
        u64                     creation_time;
+       u32                     lun_flags;
        u32                     attach_count;
        atomic_long_t           total_cmds;
        atomic_long_t           read_bytes;
@@ -650,6 +626,7 @@ struct se_dev_entry {
 #define DEF_PR_REG_ACTIVE              1
        unsigned long           deve_flags;
        struct list_head        alua_port_list;
+       struct list_head        lun_link;
        struct list_head        ua_list;
        struct hlist_node       link;
        struct rcu_head         rcu_head;
@@ -697,22 +674,46 @@ struct se_port_stat_grps {
        struct config_group scsi_transport_group;
 };
 
+struct scsi_port_stats {
+       atomic_long_t   cmd_pdus;
+       atomic_long_t   tx_data_octets;
+       atomic_long_t   rx_data_octets;
+};
+
 struct se_lun {
-       u16                     lun_rtpi;
+       u64                     unpacked_lun;
 #define SE_LUN_LINK_MAGIC                      0xffff7771
        u32                     lun_link_magic;
        u32                     lun_access;
        u32                     lun_flags;
-       u32                     unpacked_lun;
        u32                     lun_index;
+
+       /* RELATIVE TARGET PORT IDENTIFER */
+       u16                     lun_rtpi;
        atomic_t                lun_acl_count;
-       spinlock_t              lun_sep_lock;
-       struct se_device        *lun_se_dev;
-       struct se_port          *lun_sep;
+       struct se_device __rcu  *lun_se_dev;
+
+       struct list_head        lun_deve_list;
+       spinlock_t              lun_deve_lock;
+
+       /* ALUA state */
+       int                     lun_tg_pt_secondary_stat;
+       int                     lun_tg_pt_secondary_write_md;
+       atomic_t                lun_tg_pt_secondary_offline;
+       struct mutex            lun_tg_pt_md_mutex;
+
+       /* ALUA target port group linkage */
+       struct list_head        lun_tg_pt_gp_link;
+       struct t10_alua_tg_pt_gp *lun_tg_pt_gp;
+       spinlock_t              lun_tg_pt_gp_lock;
+
+       struct se_portal_group  *lun_tpg;
+       struct scsi_port_stats  lun_stats;
        struct config_group     lun_group;
        struct se_port_stat_grps port_stat_grps;
        struct completion       lun_ref_comp;
        struct percpu_ref       lun_ref;
+       struct list_head        lun_dev_link;
        struct hlist_node       link;
        struct rcu_head         rcu_head;
 };
@@ -737,7 +738,6 @@ struct se_device {
 #define DF_EMULATED_VPD_UNIT_SERIAL            0x00000004
 #define DF_USING_UDEV_PATH                     0x00000008
 #define DF_USING_ALIAS                         0x00000010
-       u32                     dev_port_count;
        /* Physical device queue depth */
        u32                     queue_depth;
        /* Used for SPC-2 reservations enforce of ISIDs */
@@ -754,7 +754,7 @@ struct se_device {
        atomic_t                dev_ordered_id;
        atomic_t                dev_ordered_sync;
        atomic_t                dev_qf_count;
-       int                     export_count;
+       u32                     export_count;
        spinlock_t              delayed_cmd_lock;
        spinlock_t              execute_task_lock;
        spinlock_t              dev_reservation_lock;
@@ -802,6 +802,9 @@ struct se_device {
        struct se_lun           xcopy_lun;
        /* Protection Information */
        int                     prot_length;
+       /* For se_lun->lun_se_dev RCU read-side critical access */
+       u32                     hba_index;
+       struct rcu_head         rcu_head;
 };
 
 struct se_hba {
@@ -821,32 +824,6 @@ struct se_hba {
        struct target_backend   *backend;
 };
 
-struct scsi_port_stats {
-       u64     cmd_pdus;
-       u64     tx_data_octets;
-       u64     rx_data_octets;
-};
-
-struct se_port {
-       /* RELATIVE TARGET PORT IDENTIFER */
-       u16             sep_rtpi;
-       int             sep_tg_pt_secondary_stat;
-       int             sep_tg_pt_secondary_write_md;
-       u32             sep_index;
-       struct scsi_port_stats sep_stats;
-       /* Used for ALUA Target Port Groups membership */
-       atomic_t        sep_tg_pt_secondary_offline;
-       /* Used for PR ALL_TG_PT=1 */
-       atomic_t        sep_tg_pt_ref_cnt;
-       spinlock_t      sep_alua_lock;
-       struct mutex    sep_tg_pt_md_mutex;
-       struct t10_alua_tg_pt_gp_member *sep_alua_tg_pt_gp_mem;
-       struct se_lun *sep_lun;
-       struct se_portal_group *sep_tpg;
-       struct list_head sep_alua_list;
-       struct list_head sep_list;
-};
-
 struct se_tpg_np {
        struct se_portal_group *tpg_np_parent;
        struct config_group     tpg_np_group;
@@ -872,7 +849,7 @@ struct se_portal_group {
        /* linked list for initiator ACL list */
        struct list_head        acl_node_list;
        struct hlist_head       tpg_lun_hlist;
-       struct se_lun           tpg_virt_lun0;
+       struct se_lun           *tpg_virt_lun0;
        /* List of TCM sessions associated wth this TPG */
        struct list_head        tpg_sess_list;
        /* Pointer to $FABRIC_MOD dependent code */