These changes are the raw update to linux-4.4.6-rt14. Kernel sources
[kvmfornfv.git] / kernel / drivers / infiniband / ulp / iser / iscsi_iser.h
index d2b6caf..8a5998e 100644 (file)
 #define SHIFT_4K       12
 #define SIZE_4K        (1ULL << SHIFT_4K)
 #define MASK_4K        (~(SIZE_4K-1))
-                                       /* support up to 512KB in one RDMA */
-#define ISCSI_ISER_SG_TABLESIZE         (0x80000 >> SHIFT_4K)
+
+/* Default support is 512KB I/O size */
+#define ISER_DEF_MAX_SECTORS           1024
+#define ISCSI_ISER_DEF_SG_TABLESIZE    ((ISER_DEF_MAX_SECTORS * 512) >> SHIFT_4K)
+/* Maximum support is 8MB I/O size */
+#define ISCSI_ISER_MAX_SG_TABLESIZE    ((16384 * 512) >> SHIFT_4K)
+
 #define ISER_DEF_XMIT_CMDS_DEFAULT             512
 #if ISCSI_DEF_XMIT_CMDS_MAX > ISER_DEF_XMIT_CMDS_DEFAULT
        #define ISER_DEF_XMIT_CMDS_MAX          ISCSI_DEF_XMIT_CMDS_MAX
@@ -222,23 +227,19 @@ enum iser_data_dir {
  * @size:         num entries of this sg
  * @data_len:     total beffer byte len
  * @dma_nents:    returned by dma_map_sg
- * @orig_sg:      pointer to the original sg list (in case
- *                we used a copy)
- * @orig_size:    num entris of orig sg list
  */
 struct iser_data_buf {
        struct scatterlist *sg;
-       unsigned int       size;
+       int                size;
        unsigned long      data_len;
        unsigned int       dma_nents;
-       struct scatterlist *orig_sg;
-       unsigned int       orig_size;
-  };
+};
 
 /* fwd declarations */
 struct iser_device;
 struct iscsi_iser_task;
 struct iscsi_endpoint;
+struct iser_reg_resources;
 
 /**
  * struct iser_mem_reg - iSER memory registration info
@@ -259,6 +260,14 @@ enum iser_desc_type {
        ISCSI_TX_DATAOUT
 };
 
+/* Maximum number of work requests per task:
+ * Data memory region local invalidate + fast registration
+ * Protection memory region local invalidate + fast registration
+ * Signature memory region local invalidate + fast registration
+ * PDU send
+ */
+#define ISER_MAX_WRS 7
+
 /**
  * struct iser_tx_desc - iSER TX descriptor (for send wr_id)
  *
@@ -271,6 +280,11 @@ enum iser_desc_type {
  *                 unsolicited data-out or control
  * @num_sge:       number sges used on this TX task
  * @mapped:        Is the task header mapped
+ * @wr_idx:        Current WR index
+ * @wrs:           Array of WRs per task
+ * @data_reg:      Data buffer registration details
+ * @prot_reg:      Protection buffer registration details
+ * @sig_attrs:     Signature attributes
  */
 struct iser_tx_desc {
        struct iser_hdr              iser_header;
@@ -280,6 +294,15 @@ struct iser_tx_desc {
        struct ib_sge                tx_sg[2];
        int                          num_sge;
        bool                         mapped;
+       u8                           wr_idx;
+       union iser_wr {
+               struct ib_send_wr               send;
+               struct ib_reg_wr                fast_reg;
+               struct ib_sig_handover_wr       sig;
+       } wrs[ISER_MAX_WRS];
+       struct iser_mem_reg          data_reg;
+       struct iser_mem_reg          prot_reg;
+       struct ib_sig_attrs          sig_attrs;
 };
 
 #define ISER_RX_PAD_SIZE       (256 - (ISER_RX_PAYLOAD_SIZE + \
@@ -325,6 +348,33 @@ struct iser_comp {
        int                      active_qps;
 };
 
+/**
+ * struct iser_device - Memory registration operations
+ *     per-device registration schemes
+ *
+ * @alloc_reg_res:     Allocate registration resources
+ * @free_reg_res:      Free registration resources
+ * @fast_reg_mem:      Register memory buffers
+ * @unreg_mem:         Un-register memory buffers
+ * @reg_desc_get:      Get a registration descriptor for pool
+ * @reg_desc_put:      Get a registration descriptor to pool
+ */
+struct iser_reg_ops {
+       int            (*alloc_reg_res)(struct ib_conn *ib_conn,
+                                       unsigned cmds_max,
+                                       unsigned int size);
+       void           (*free_reg_res)(struct ib_conn *ib_conn);
+       int            (*reg_mem)(struct iscsi_iser_task *iser_task,
+                                 struct iser_data_buf *mem,
+                                 struct iser_reg_resources *rsc,
+                                 struct iser_mem_reg *reg);
+       void           (*unreg_mem)(struct iscsi_iser_task *iser_task,
+                                   enum iser_data_dir cmd_dir);
+       struct iser_fr_desc * (*reg_desc_get)(struct ib_conn *ib_conn);
+       void           (*reg_desc_put)(struct ib_conn *ib_conn,
+                                      struct iser_fr_desc *desc);
+};
+
 /**
  * struct iser_device - iSER device handle
  *
@@ -338,11 +388,7 @@ struct iser_comp {
  * @comps_used:    Number of completion contexts used, Min between online
  *                 cpus and device max completion vectors
  * @comps:         Dinamically allocated array of completion handlers
- * Memory registration pool Function pointers (FMR or Fastreg):
- *     @iser_alloc_rdma_reg_res: Allocation of memory regions pool
- *     @iser_free_rdma_reg_res:  Free of memory regions pool
- *     @iser_reg_rdma_mem:       Memory registration routine
- *     @iser_unreg_rdma_mem:     Memory deregistration routine
+ * @reg_ops:       Registration ops
  */
 struct iser_device {
        struct ib_device             *ib_device;
@@ -354,54 +400,69 @@ struct iser_device {
        int                          refcount;
        int                          comps_used;
        struct iser_comp             *comps;
-       int                          (*iser_alloc_rdma_reg_res)(struct ib_conn *ib_conn,
-                                                               unsigned cmds_max);
-       void                         (*iser_free_rdma_reg_res)(struct ib_conn *ib_conn);
-       int                          (*iser_reg_rdma_mem)(struct iscsi_iser_task *iser_task,
-                                                         enum iser_data_dir cmd_dir);
-       void                         (*iser_unreg_rdma_mem)(struct iscsi_iser_task *iser_task,
-                                                           enum iser_data_dir cmd_dir);
+       struct iser_reg_ops          *reg_ops;
 };
 
 #define ISER_CHECK_GUARD       0xc0
 #define ISER_CHECK_REFTAG      0x0f
 #define ISER_CHECK_APPTAG      0x30
 
-enum iser_reg_indicator {
-       ISER_DATA_KEY_VALID     = 1 << 0,
-       ISER_PROT_KEY_VALID     = 1 << 1,
-       ISER_SIG_KEY_VALID      = 1 << 2,
-       ISER_FASTREG_PROTECTED  = 1 << 3,
+/**
+ * struct iser_reg_resources - Fast registration recources
+ *
+ * @mr:         memory region
+ * @fmr_pool:   pool of fmrs
+ * @page_vec:   fast reg page list used by fmr pool
+ * @mr_valid:   is mr valid indicator
+ */
+struct iser_reg_resources {
+       union {
+               struct ib_mr             *mr;
+               struct ib_fmr_pool       *fmr_pool;
+       };
+       struct iser_page_vec             *page_vec;
+       u8                                mr_valid:1;
 };
 
 /**
  * struct iser_pi_context - Protection information context
  *
- * @prot_mr:        protection memory region
- * @prot_frpl:      protection fastreg page list
- * @sig_mr:         signature feature enabled memory region
+ * @rsc:             protection buffer registration resources
+ * @sig_mr:          signature enable memory region
+ * @sig_mr_valid:    is sig_mr valid indicator
+ * @sig_protected:   is region protected indicator
  */
 struct iser_pi_context {
-       struct ib_mr                   *prot_mr;
-       struct ib_fast_reg_page_list   *prot_frpl;
+       struct iser_reg_resources       rsc;
        struct ib_mr                   *sig_mr;
+       u8                              sig_mr_valid:1;
+       u8                              sig_protected:1;
 };
 
 /**
- * struct fast_reg_descriptor - Fast registration descriptor
+ * struct iser_fr_desc - Fast registration descriptor
  *
  * @list:           entry in connection fastreg pool
- * @data_mr:        data memory region
- * @data_frpl:      data fastreg page list
+ * @rsc:            data buffer registration resources
  * @pi_ctx:         protection information context
- * @reg_indicators: fast registration indicators
  */
-struct fast_reg_descriptor {
+struct iser_fr_desc {
        struct list_head                  list;
-       struct ib_mr                     *data_mr;
-       struct ib_fast_reg_page_list     *data_frpl;
+       struct iser_reg_resources         rsc;
        struct iser_pi_context           *pi_ctx;
-       u8                                reg_indicators;
+};
+
+/**
+ * struct iser_fr_pool: connection fast registration pool
+ *
+ * @list:                list of fastreg descriptors
+ * @lock:                protects fmr/fastreg pool
+ * @size:                size of the pool
+ */
+struct iser_fr_pool {
+       struct list_head        list;
+       spinlock_t              lock;
+       int                     size;
 };
 
 /**
@@ -417,15 +478,7 @@ struct fast_reg_descriptor {
  * @pi_support:          Indicate device T10-PI support
  * @beacon:              beacon send wr to signal all flush errors were drained
  * @flush_comp:          completes when all connection completions consumed
- * @lock:                protects fmr/fastreg pool
- * @union.fmr:
- *     @pool:            FMR pool for fast registrations
- *     @page_vec:        page vector to hold mapped commands pages
- *                       used for registration
- * @union.fastreg:
- *     @pool:            Fast registration descriptors pool for fast
- *                       registrations
- *     @pool_size:       Size of pool
+ * @fr_pool:             connection fast registration poool
  */
 struct ib_conn {
        struct rdma_cm_id           *cma_id;
@@ -438,17 +491,7 @@ struct ib_conn {
        bool                         pi_support;
        struct ib_send_wr            beacon;
        struct completion            flush_comp;
-       spinlock_t                   lock;
-       union {
-               struct {
-                       struct ib_fmr_pool      *pool;
-                       struct iser_page_vec    *page_vec;
-               } fmr;
-               struct {
-                       struct list_head         pool;
-                       int                      pool_size;
-               } fastreg;
-       };
+       struct iser_fr_pool          fr_pool;
 };
 
 /**
@@ -479,6 +522,8 @@ struct ib_conn {
  * @rx_desc_head:     head of rx_descs cyclic buffer
  * @rx_descs:         rx buffers array (cyclic buffer)
  * @num_rx_descs:     number of rx descriptors
+ * @scsi_sg_tablesize: scsi host sg_tablesize
+ * @scsi_max_sectors: scsi host max sectors
  */
 struct iser_conn {
        struct ib_conn               ib_conn;
@@ -503,6 +548,8 @@ struct iser_conn {
        unsigned int                 rx_desc_head;
        struct iser_rx_desc          *rx_descs;
        u32                          num_rx_descs;
+       unsigned short               scsi_sg_tablesize;
+       unsigned int                 scsi_max_sectors;
 };
 
 /**
@@ -558,6 +605,10 @@ extern struct iser_global ig;
 extern int iser_debug_level;
 extern bool iser_pi_enable;
 extern int iser_pi_guard;
+extern unsigned int iser_max_sectors;
+extern bool iser_always_reg;
+
+int iser_assign_reg_ops(struct iser_device *device);
 
 int iser_send_control(struct iscsi_conn *conn,
                      struct iscsi_task *task);
@@ -599,10 +650,10 @@ void iser_finalize_rdma_unaligned_sg(struct iscsi_iser_task *iser_task,
                                     struct iser_data_buf *mem,
                                     enum iser_data_dir cmd_dir);
 
-int  iser_reg_rdma_mem_fmr(struct iscsi_iser_task *task,
-                          enum iser_data_dir cmd_dir);
-int  iser_reg_rdma_mem_fastreg(struct iscsi_iser_task *task,
-                              enum iser_data_dir cmd_dir);
+int iser_reg_rdma_mem(struct iscsi_iser_task *task,
+                     enum iser_data_dir dir);
+void iser_unreg_rdma_mem(struct iscsi_iser_task *task,
+                        enum iser_data_dir dir);
 
 int  iser_connect(struct iser_conn *iser_conn,
                  struct sockaddr *src_addr,
@@ -632,15 +683,40 @@ int  iser_initialize_task_headers(struct iscsi_task *task,
                        struct iser_tx_desc *tx_desc);
 int iser_alloc_rx_descriptors(struct iser_conn *iser_conn,
                              struct iscsi_session *session);
-int iser_create_fmr_pool(struct ib_conn *ib_conn, unsigned cmds_max);
+int iser_alloc_fmr_pool(struct ib_conn *ib_conn,
+                       unsigned cmds_max,
+                       unsigned int size);
 void iser_free_fmr_pool(struct ib_conn *ib_conn);
-int iser_create_fastreg_pool(struct ib_conn *ib_conn, unsigned cmds_max);
+int iser_alloc_fastreg_pool(struct ib_conn *ib_conn,
+                           unsigned cmds_max,
+                           unsigned int size);
 void iser_free_fastreg_pool(struct ib_conn *ib_conn);
 u8 iser_check_task_pi_status(struct iscsi_iser_task *iser_task,
                             enum iser_data_dir cmd_dir, sector_t *sector);
-struct fast_reg_descriptor *
-iser_reg_desc_get(struct ib_conn *ib_conn);
+struct iser_fr_desc *
+iser_reg_desc_get_fr(struct ib_conn *ib_conn);
 void
-iser_reg_desc_put(struct ib_conn *ib_conn,
-                 struct fast_reg_descriptor *desc);
+iser_reg_desc_put_fr(struct ib_conn *ib_conn,
+                    struct iser_fr_desc *desc);
+struct iser_fr_desc *
+iser_reg_desc_get_fmr(struct ib_conn *ib_conn);
+void
+iser_reg_desc_put_fmr(struct ib_conn *ib_conn,
+                     struct iser_fr_desc *desc);
+
+static inline struct ib_send_wr *
+iser_tx_next_wr(struct iser_tx_desc *tx_desc)
+{
+       struct ib_send_wr *cur_wr = &tx_desc->wrs[tx_desc->wr_idx].send;
+       struct ib_send_wr *last_wr;
+
+       if (tx_desc->wr_idx) {
+               last_wr = &tx_desc->wrs[tx_desc->wr_idx - 1].send;
+               last_wr->next = cur_wr;
+       }
+       tx_desc->wr_idx++;
+
+       return cur_wr;
+}
+
 #endif