linux/drivers/infiniband/ulp/isert/ib_isert.h
<<
>>
Prefs
   1#include <linux/socket.h>
   2#include <linux/in.h>
   3#include <linux/in6.h>
   4#include <rdma/ib_verbs.h>
   5#include <rdma/rdma_cm.h>
   6#include <scsi/iser.h>
   7
   8
   9#define DRV_NAME        "isert"
  10#define PFX             DRV_NAME ": "
  11
  12#define isert_dbg(fmt, arg...)                           \
  13        do {                                             \
  14                if (unlikely(isert_debug_level > 2))     \
  15                        printk(KERN_DEBUG PFX "%s: " fmt,\
  16                                __func__ , ## arg);      \
  17        } while (0)
  18
  19#define isert_warn(fmt, arg...)                         \
  20        do {                                            \
  21                if (unlikely(isert_debug_level > 0))    \
  22                        pr_warn(PFX "%s: " fmt,         \
  23                                __func__ , ## arg);     \
  24        } while (0)
  25
  26#define isert_info(fmt, arg...)                         \
  27        do {                                            \
  28                if (unlikely(isert_debug_level > 1))    \
  29                        pr_info(PFX "%s: " fmt,         \
  30                                __func__ , ## arg);     \
  31        } while (0)
  32
  33#define isert_err(fmt, arg...) \
  34        pr_err(PFX "%s: " fmt, __func__ , ## arg)
  35
  36/* Constant PDU lengths calculations */
  37#define ISER_HEADERS_LEN        (sizeof(struct iser_ctrl) + \
  38                                 sizeof(struct iscsi_hdr))
  39#define ISER_RX_PAYLOAD_SIZE    (ISER_HEADERS_LEN + ISCSI_DEF_MAX_RECV_SEG_LEN)
  40
  41/* QP settings */
  42/* Maximal bounds on received asynchronous PDUs */
  43#define ISERT_MAX_TX_MISC_PDUS  4 /* NOOP_IN(2) , ASYNC_EVENT(2)   */
  44
  45#define ISERT_MAX_RX_MISC_PDUS  6 /*
  46                                   * NOOP_OUT(2), TEXT(1),
  47                                   * SCSI_TMFUNC(2), LOGOUT(1)
  48                                   */
  49
  50#define ISCSI_DEF_XMIT_CMDS_MAX 128 /* from libiscsi.h, must be power of 2 */
  51
  52#define ISERT_QP_MAX_RECV_DTOS  (ISCSI_DEF_XMIT_CMDS_MAX)
  53
  54#define ISERT_MIN_POSTED_RX     (ISCSI_DEF_XMIT_CMDS_MAX >> 2)
  55
  56#define ISERT_INFLIGHT_DATAOUTS 8
  57
  58#define ISERT_QP_MAX_REQ_DTOS   (ISCSI_DEF_XMIT_CMDS_MAX *    \
  59                                (1 + ISERT_INFLIGHT_DATAOUTS) + \
  60                                ISERT_MAX_TX_MISC_PDUS  + \
  61                                ISERT_MAX_RX_MISC_PDUS)
  62
  63#define ISER_RX_PAD_SIZE        (ISCSI_DEF_MAX_RECV_SEG_LEN + 4096 - \
  64                (ISER_RX_PAYLOAD_SIZE + sizeof(u64) + sizeof(struct ib_sge) + \
  65                 sizeof(struct ib_cqe)))
  66
  67#define ISCSI_ISER_SG_TABLESIZE         256
  68
  69enum isert_desc_type {
  70        ISCSI_TX_CONTROL,
  71        ISCSI_TX_DATAIN
  72};
  73
  74enum iser_ib_op_code {
  75        ISER_IB_RECV,
  76        ISER_IB_SEND,
  77        ISER_IB_RDMA_WRITE,
  78        ISER_IB_RDMA_READ,
  79};
  80
  81enum iser_conn_state {
  82        ISER_CONN_INIT,
  83        ISER_CONN_UP,
  84        ISER_CONN_BOUND,
  85        ISER_CONN_FULL_FEATURE,
  86        ISER_CONN_TERMINATING,
  87        ISER_CONN_DOWN,
  88};
  89
  90struct iser_rx_desc {
  91        struct iser_ctrl iser_header;
  92        struct iscsi_hdr iscsi_header;
  93        char            data[ISCSI_DEF_MAX_RECV_SEG_LEN];
  94        u64             dma_addr;
  95        struct ib_sge   rx_sg;
  96        struct ib_cqe   rx_cqe;
  97        char            pad[ISER_RX_PAD_SIZE];
  98} __packed;
  99
 100static inline struct iser_rx_desc *cqe_to_rx_desc(struct ib_cqe *cqe)
 101{
 102        return container_of(cqe, struct iser_rx_desc, rx_cqe);
 103}
 104
 105struct iser_tx_desc {
 106        struct iser_ctrl iser_header;
 107        struct iscsi_hdr iscsi_header;
 108        enum isert_desc_type type;
 109        u64             dma_addr;
 110        struct ib_sge   tx_sg[2];
 111        struct ib_cqe   tx_cqe;
 112        int             num_sge;
 113        struct ib_send_wr send_wr;
 114} __packed;
 115
 116static inline struct iser_tx_desc *cqe_to_tx_desc(struct ib_cqe *cqe)
 117{
 118        return container_of(cqe, struct iser_tx_desc, tx_cqe);
 119}
 120
 121
 122enum isert_indicator {
 123        ISERT_PROTECTED         = 1 << 0,
 124        ISERT_DATA_KEY_VALID    = 1 << 1,
 125        ISERT_PROT_KEY_VALID    = 1 << 2,
 126        ISERT_SIG_KEY_VALID     = 1 << 3,
 127};
 128
 129struct pi_context {
 130        struct ib_mr                   *prot_mr;
 131        struct ib_mr                   *sig_mr;
 132};
 133
 134struct fast_reg_descriptor {
 135        struct list_head                list;
 136        struct ib_mr                   *data_mr;
 137        u8                              ind;
 138        struct pi_context              *pi_ctx;
 139};
 140
 141struct isert_data_buf {
 142        struct scatterlist     *sg;
 143        int                     nents;
 144        u32                     sg_off;
 145        u32                     len; /* cur_rdma_length */
 146        u32                     offset;
 147        unsigned int            dma_nents;
 148        enum dma_data_direction dma_dir;
 149};
 150
 151enum {
 152        DATA = 0,
 153        PROT = 1,
 154        SIG = 2,
 155};
 156
 157struct isert_cmd {
 158        uint32_t                read_stag;
 159        uint32_t                write_stag;
 160        uint64_t                read_va;
 161        uint64_t                write_va;
 162        uint32_t                inv_rkey;
 163        u64                     pdu_buf_dma;
 164        u32                     pdu_buf_len;
 165        struct isert_conn       *conn;
 166        struct iscsi_cmd        *iscsi_cmd;
 167        struct iser_tx_desc     tx_desc;
 168        struct iser_rx_desc     *rx_desc;
 169        enum iser_ib_op_code    iser_ib_op;
 170        struct ib_sge           *ib_sge;
 171        struct ib_sge           s_ib_sge;
 172        int                     rdma_wr_num;
 173        struct ib_rdma_wr       *rdma_wr;
 174        struct ib_rdma_wr       s_rdma_wr;
 175        struct ib_sge           ib_sg[3];
 176        struct isert_data_buf   data;
 177        struct isert_data_buf   prot;
 178        struct fast_reg_descriptor *fr_desc;
 179        struct work_struct      comp_work;
 180        struct scatterlist      sg;
 181};
 182
 183static inline struct isert_cmd *tx_desc_to_cmd(struct iser_tx_desc *desc)
 184{
 185        return container_of(desc, struct isert_cmd, tx_desc);
 186}
 187
 188struct isert_device;
 189
 190struct isert_conn {
 191        enum iser_conn_state    state;
 192        u32                     responder_resources;
 193        u32                     initiator_depth;
 194        bool                    pi_support;
 195        u32                     max_sge;
 196        struct iser_rx_desc     *login_req_buf;
 197        char                    *login_rsp_buf;
 198        u64                     login_req_dma;
 199        int                     login_req_len;
 200        u64                     login_rsp_dma;
 201        struct iser_rx_desc     *rx_descs;
 202        struct ib_recv_wr       rx_wr[ISERT_QP_MAX_RECV_DTOS];
 203        struct iscsi_conn       *conn;
 204        struct list_head        node;
 205        struct completion       login_comp;
 206        struct completion       login_req_comp;
 207        struct iser_tx_desc     login_tx_desc;
 208        struct rdma_cm_id       *cm_id;
 209        struct ib_qp            *qp;
 210        struct isert_device     *device;
 211        struct mutex            mutex;
 212        struct kref             kref;
 213        struct list_head        fr_pool;
 214        int                     fr_pool_size;
 215        /* lock to protect fastreg pool */
 216        spinlock_t              pool_lock;
 217        struct work_struct      release_work;
 218        bool                    logout_posted;
 219        bool                    snd_w_inv;
 220};
 221
 222#define ISERT_MAX_CQ 64
 223
 224/**
 225 * struct isert_comp - iSER completion context
 226 *
 227 * @device:     pointer to device handle
 228 * @cq:         completion queue
 229 * @active_qps: Number of active QPs attached
 230 *              to completion context
 231 */
 232struct isert_comp {
 233        struct isert_device     *device;
 234        struct ib_cq            *cq;
 235        int                      active_qps;
 236};
 237
 238struct isert_device {
 239        int                     use_fastreg;
 240        bool                    pi_capable;
 241        int                     refcount;
 242        struct ib_device        *ib_device;
 243        struct ib_pd            *pd;
 244        struct isert_comp       *comps;
 245        int                     comps_used;
 246        struct list_head        dev_node;
 247        int                     (*reg_rdma_mem)(struct isert_cmd *isert_cmd,
 248                                                struct iscsi_conn *conn);
 249        void                    (*unreg_rdma_mem)(struct isert_cmd *isert_cmd,
 250                                                  struct isert_conn *isert_conn);
 251};
 252
 253struct isert_np {
 254        struct iscsi_np         *np;
 255        struct semaphore        sem;
 256        struct rdma_cm_id       *cm_id;
 257        struct mutex            mutex;
 258        struct list_head        accepted;
 259        struct list_head        pending;
 260};
 261