Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #include <linux/socket.h>
0003 #include <linux/in.h>
0004 #include <linux/in6.h>
0005 #include <rdma/ib_verbs.h>
0006 #include <rdma/rdma_cm.h>
0007 #include <rdma/rw.h>
0008 #include <scsi/iser.h>
0009 
0010 
0011 #define DRV_NAME    "isert"
0012 #define PFX     DRV_NAME ": "
0013 
0014 #define isert_dbg(fmt, arg...)               \
0015     do {                         \
0016         if (unlikely(isert_debug_level > 2))     \
0017             printk(KERN_DEBUG PFX "%s: " fmt,\
0018                 __func__ , ## arg);  \
0019     } while (0)
0020 
0021 #define isert_warn(fmt, arg...)             \
0022     do {                        \
0023         if (unlikely(isert_debug_level > 0))    \
0024             pr_warn(PFX "%s: " fmt,         \
0025                 __func__ , ## arg); \
0026     } while (0)
0027 
0028 #define isert_info(fmt, arg...)             \
0029     do {                        \
0030         if (unlikely(isert_debug_level > 1))    \
0031             pr_info(PFX "%s: " fmt,         \
0032                 __func__ , ## arg); \
0033     } while (0)
0034 
0035 #define isert_err(fmt, arg...) \
0036     pr_err(PFX "%s: " fmt, __func__ , ## arg)
0037 
0038 /* Constant PDU lengths calculations */
0039 #define ISER_HEADERS_LEN    (sizeof(struct iser_ctrl) + \
0040                  sizeof(struct iscsi_hdr))
0041 #define ISER_RX_PAYLOAD_SIZE    (ISER_HEADERS_LEN + ISCSI_DEF_MAX_RECV_SEG_LEN)
0042 
0043 /* QP settings */
0044 /* Maximal bounds on received asynchronous PDUs */
0045 #define ISERT_MAX_TX_MISC_PDUS  4 /* NOOP_IN(2) , ASYNC_EVENT(2)   */
0046 
0047 #define ISERT_MAX_RX_MISC_PDUS  6 /*
0048                    * NOOP_OUT(2), TEXT(1),
0049                    * SCSI_TMFUNC(2), LOGOUT(1)
0050                    */
0051 
0052 #define ISCSI_DEF_XMIT_CMDS_MAX 128 /* from libiscsi.h, must be power of 2 */
0053 
0054 #define ISERT_QP_MAX_RECV_DTOS  (ISCSI_DEF_XMIT_CMDS_MAX)
0055 
0056 #define ISERT_MIN_POSTED_RX (ISCSI_DEF_XMIT_CMDS_MAX >> 2)
0057 
0058 #define ISERT_QP_MAX_REQ_DTOS   (ISCSI_DEF_XMIT_CMDS_MAX +    \
0059                 ISERT_MAX_TX_MISC_PDUS  + \
0060                 ISERT_MAX_RX_MISC_PDUS)
0061 
0062 /*
0063  * RX size is default of 8k plus headers, but data needs to align to
0064  * 512 boundary, so use 1024 to have the extra space for alignment.
0065  */
0066 #define ISER_RX_SIZE        (ISCSI_DEF_MAX_RECV_SEG_LEN + 1024)
0067 
0068 /* Minimum I/O size is 512KB */
0069 #define ISCSI_ISER_MIN_SG_TABLESIZE 128
0070 
0071 /* Maximum support is 16MB I/O size */
0072 #define ISCSI_ISER_MAX_SG_TABLESIZE 4096
0073 
0074 enum isert_desc_type {
0075     ISCSI_TX_CONTROL,
0076     ISCSI_TX_DATAIN
0077 };
0078 
0079 enum iser_conn_state {
0080     ISER_CONN_INIT,
0081     ISER_CONN_UP,
0082     ISER_CONN_BOUND,
0083     ISER_CONN_FULL_FEATURE,
0084     ISER_CONN_TERMINATING,
0085     ISER_CONN_DOWN,
0086 };
0087 
0088 struct iser_rx_desc {
0089     char        buf[ISER_RX_SIZE];
0090     u64     dma_addr;
0091     struct ib_sge   rx_sg;
0092     struct ib_cqe   rx_cqe;
0093     bool        in_use;
0094 };
0095 
0096 static inline struct iser_rx_desc *cqe_to_rx_desc(struct ib_cqe *cqe)
0097 {
0098     return container_of(cqe, struct iser_rx_desc, rx_cqe);
0099 }
0100 
0101 static void *isert_get_iser_hdr(struct iser_rx_desc *desc)
0102 {
0103     return PTR_ALIGN(desc->buf + ISER_HEADERS_LEN, 512) - ISER_HEADERS_LEN;
0104 }
0105 
0106 static size_t isert_get_hdr_offset(struct iser_rx_desc *desc)
0107 {
0108     return isert_get_iser_hdr(desc) - (void *)desc->buf;
0109 }
0110 
0111 static void *isert_get_iscsi_hdr(struct iser_rx_desc *desc)
0112 {
0113     return isert_get_iser_hdr(desc) + sizeof(struct iser_ctrl);
0114 }
0115 
0116 static void *isert_get_data(struct iser_rx_desc *desc)
0117 {
0118     void *data = isert_get_iser_hdr(desc) + ISER_HEADERS_LEN;
0119 
0120     WARN_ON((uintptr_t)data & 511);
0121     return data;
0122 }
0123 
0124 struct iser_tx_desc {
0125     struct iser_ctrl iser_header;
0126     struct iscsi_hdr iscsi_header;
0127     enum isert_desc_type type;
0128     u64     dma_addr;
0129     struct ib_sge   tx_sg[2];
0130     struct ib_cqe   tx_cqe;
0131     int     num_sge;
0132     struct ib_send_wr send_wr;
0133 } __packed;
0134 
0135 static inline struct iser_tx_desc *cqe_to_tx_desc(struct ib_cqe *cqe)
0136 {
0137     return container_of(cqe, struct iser_tx_desc, tx_cqe);
0138 }
0139 
0140 struct isert_cmd {
0141     uint32_t        read_stag;
0142     uint32_t        write_stag;
0143     uint64_t        read_va;
0144     uint64_t        write_va;
0145     uint32_t        inv_rkey;
0146     u64         pdu_buf_dma;
0147     u32         pdu_buf_len;
0148     struct isert_conn   *conn;
0149     struct iscsit_cmd   *iscsit_cmd;
0150     struct iser_tx_desc tx_desc;
0151     struct iser_rx_desc *rx_desc;
0152     struct rdma_rw_ctx  rw;
0153     struct work_struct  comp_work;
0154     struct scatterlist  sg;
0155     bool            ctx_init_done;
0156 };
0157 
0158 static inline struct isert_cmd *tx_desc_to_cmd(struct iser_tx_desc *desc)
0159 {
0160     return container_of(desc, struct isert_cmd, tx_desc);
0161 }
0162 
0163 struct isert_device;
0164 
0165 struct isert_conn {
0166     enum iser_conn_state    state;
0167     u32         responder_resources;
0168     u32         initiator_depth;
0169     bool            pi_support;
0170     struct iser_rx_desc *login_desc;
0171     char            *login_rsp_buf;
0172     int         login_req_len;
0173     u64         login_rsp_dma;
0174     struct iser_rx_desc *rx_descs;
0175     struct ib_recv_wr   rx_wr[ISERT_QP_MAX_RECV_DTOS];
0176     struct iscsit_conn  *conn;
0177     struct list_head    node;
0178     struct completion   login_comp;
0179     struct completion   login_req_comp;
0180     struct iser_tx_desc login_tx_desc;
0181     struct rdma_cm_id   *cm_id;
0182     struct ib_qp        *qp;
0183     struct ib_cq        *cq;
0184     u32         cq_size;
0185     struct isert_device *device;
0186     struct mutex        mutex;
0187     struct kref     kref;
0188     struct work_struct  release_work;
0189     bool                    logout_posted;
0190     bool                    snd_w_inv;
0191     wait_queue_head_t   rem_wait;
0192     bool            dev_removed;
0193 };
0194 
0195 struct isert_device {
0196     bool            pi_capable;
0197     int         refcount;
0198     struct ib_device    *ib_device;
0199     struct ib_pd        *pd;
0200     struct isert_comp   *comps;
0201     int                     comps_used;
0202     struct list_head    dev_node;
0203 };
0204 
0205 struct isert_np {
0206     struct iscsi_np         *np;
0207     struct semaphore    sem;
0208     struct rdma_cm_id   *cm_id;
0209     struct mutex        mutex;
0210     struct list_head    accepted;
0211     struct list_head    pending;
0212 };