0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041 #ifndef __ISCSI_ISER_H__
0042 #define __ISCSI_ISER_H__
0043
0044 #include <linux/types.h>
0045 #include <linux/net.h>
0046 #include <linux/printk.h>
0047 #include <scsi/libiscsi.h>
0048 #include <scsi/scsi_transport_iscsi.h>
0049 #include <scsi/scsi_cmnd.h>
0050 #include <scsi/scsi_device.h>
0051 #include <scsi/iser.h>
0052
0053 #include <linux/interrupt.h>
0054 #include <linux/wait.h>
0055 #include <linux/sched.h>
0056 #include <linux/list.h>
0057 #include <linux/slab.h>
0058 #include <linux/dma-mapping.h>
0059 #include <linux/mutex.h>
0060 #include <linux/mempool.h>
0061 #include <linux/uio.h>
0062
0063 #include <linux/socket.h>
0064 #include <linux/in.h>
0065 #include <linux/in6.h>
0066
0067 #include <rdma/ib_verbs.h>
0068 #include <rdma/rdma_cm.h>
0069
0070 #define DRV_NAME "iser"
0071 #define PFX DRV_NAME ": "
0072 #define DRV_VER "1.6"
0073
0074 #define iser_dbg(fmt, arg...) \
0075 do { \
0076 if (unlikely(iser_debug_level > 2)) \
0077 printk(KERN_DEBUG PFX "%s: " fmt,\
0078 __func__ , ## arg); \
0079 } while (0)
0080
0081 #define iser_warn(fmt, arg...) \
0082 do { \
0083 if (unlikely(iser_debug_level > 0)) \
0084 pr_warn(PFX "%s: " fmt, \
0085 __func__ , ## arg); \
0086 } while (0)
0087
0088 #define iser_info(fmt, arg...) \
0089 do { \
0090 if (unlikely(iser_debug_level > 1)) \
0091 pr_info(PFX "%s: " fmt, \
0092 __func__ , ## arg); \
0093 } while (0)
0094
0095 #define iser_err(fmt, arg...) \
0096 pr_err(PFX "%s: " fmt, __func__ , ## arg)
0097
0098
0099 #define ISER_DEF_MAX_SECTORS 1024
0100 #define ISCSI_ISER_DEF_SG_TABLESIZE \
0101 ((ISER_DEF_MAX_SECTORS * SECTOR_SIZE) >> ilog2(SZ_4K))
0102
0103 #define ISCSI_ISER_MAX_SG_TABLESIZE ((32768 * SECTOR_SIZE) >> ilog2(SZ_4K))
0104
0105 #define ISER_DEF_XMIT_CMDS_DEFAULT 512
0106 #if ISCSI_DEF_XMIT_CMDS_MAX > ISER_DEF_XMIT_CMDS_DEFAULT
0107 #define ISER_DEF_XMIT_CMDS_MAX ISCSI_DEF_XMIT_CMDS_MAX
0108 #else
0109 #define ISER_DEF_XMIT_CMDS_MAX ISER_DEF_XMIT_CMDS_DEFAULT
0110 #endif
0111 #define ISER_DEF_CMD_PER_LUN ISER_DEF_XMIT_CMDS_MAX
0112
0113
0114
0115 #define ISER_MAX_RX_MISC_PDUS 4
0116
0117 #define ISER_MAX_TX_MISC_PDUS 6
0118
0119
0120 #define ISER_QP_MAX_RECV_DTOS (ISER_DEF_XMIT_CMDS_MAX)
0121
0122
0123
0124
0125
0126
0127
0128 #define ISER_INFLIGHT_DATAOUTS 8
0129
0130 #define ISER_QP_MAX_REQ_DTOS (ISER_DEF_XMIT_CMDS_MAX * \
0131 (1 + ISER_INFLIGHT_DATAOUTS) + \
0132 ISER_MAX_TX_MISC_PDUS + \
0133 ISER_MAX_RX_MISC_PDUS)
0134
0135
0136 #define ISER_MAX_REG_WR_PER_CMD 5
0137
0138
0139 #define ISER_QP_SIG_MAX_REQ_DTOS (ISER_DEF_XMIT_CMDS_MAX * \
0140 (1 + ISER_MAX_REG_WR_PER_CMD) + \
0141 ISER_MAX_TX_MISC_PDUS + \
0142 ISER_MAX_RX_MISC_PDUS)
0143
0144 #define ISER_GET_MAX_XMIT_CMDS(send_wr) ((send_wr \
0145 - ISER_MAX_TX_MISC_PDUS \
0146 - ISER_MAX_RX_MISC_PDUS) / \
0147 (1 + ISER_INFLIGHT_DATAOUTS))
0148
0149
0150 #define ISER_HEADERS_LEN (sizeof(struct iser_ctrl) + sizeof(struct iscsi_hdr))
0151
0152 #define ISER_RECV_DATA_SEG_LEN 128
0153 #define ISER_RX_PAYLOAD_SIZE (ISER_HEADERS_LEN + ISER_RECV_DATA_SEG_LEN)
0154 #define ISER_RX_LOGIN_SIZE (ISER_HEADERS_LEN + ISCSI_DEF_MAX_RECV_SEG_LEN)
0155
0156
0157 #define ISER_OBJECT_NAME_SIZE 64
0158
0159 enum iser_conn_state {
0160 ISER_CONN_INIT,
0161 ISER_CONN_PENDING,
0162 ISER_CONN_UP,
0163 ISER_CONN_TERMINATING,
0164 ISER_CONN_DOWN,
0165 ISER_CONN_STATES_NUM
0166 };
0167
0168 enum iser_task_status {
0169 ISER_TASK_STATUS_INIT = 0,
0170 ISER_TASK_STATUS_STARTED,
0171 ISER_TASK_STATUS_COMPLETED
0172 };
0173
0174 enum iser_data_dir {
0175 ISER_DIR_IN = 0,
0176 ISER_DIR_OUT,
0177 ISER_DIRS_NUM
0178 };
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188 struct iser_data_buf {
0189 struct scatterlist *sg;
0190 int size;
0191 unsigned long data_len;
0192 int dma_nents;
0193 };
0194
0195
0196 struct iser_device;
0197 struct iscsi_iser_task;
0198 struct iscsi_endpoint;
0199 struct iser_reg_resources;
0200
0201
0202
0203
0204
0205
0206
0207
0208 struct iser_mem_reg {
0209 struct ib_sge sge;
0210 u32 rkey;
0211 struct iser_fr_desc *desc;
0212 };
0213
0214 enum iser_desc_type {
0215 ISCSI_TX_CONTROL ,
0216 ISCSI_TX_SCSI_COMMAND,
0217 ISCSI_TX_DATAOUT
0218 };
0219
0220
0221
0222
0223
0224
0225
0226
0227
0228
0229
0230
0231
0232
0233
0234
0235
0236
0237 struct iser_tx_desc {
0238 struct iser_ctrl iser_header;
0239 struct iscsi_hdr iscsi_header;
0240 enum iser_desc_type type;
0241 u64 dma_addr;
0242 struct ib_sge tx_sg[2];
0243 int num_sge;
0244 struct ib_cqe cqe;
0245 bool mapped;
0246 struct ib_reg_wr reg_wr;
0247 struct ib_send_wr send_wr;
0248 struct ib_send_wr inv_wr;
0249 };
0250
0251 #define ISER_RX_PAD_SIZE (256 - (ISER_RX_PAYLOAD_SIZE + \
0252 sizeof(u64) + sizeof(struct ib_sge) + \
0253 sizeof(struct ib_cqe)))
0254
0255
0256
0257
0258
0259
0260
0261
0262
0263
0264
0265 struct iser_rx_desc {
0266 struct iser_ctrl iser_header;
0267 struct iscsi_hdr iscsi_header;
0268 char data[ISER_RECV_DATA_SEG_LEN];
0269 u64 dma_addr;
0270 struct ib_sge rx_sg;
0271 struct ib_cqe cqe;
0272 char pad[ISER_RX_PAD_SIZE];
0273 } __packed;
0274
0275
0276
0277
0278
0279
0280
0281
0282
0283
0284
0285 struct iser_login_desc {
0286 void *req;
0287 void *rsp;
0288 u64 req_dma;
0289 u64 rsp_dma;
0290 struct ib_sge sge;
0291 struct ib_cqe cqe;
0292 } __packed;
0293
0294 struct iser_conn;
0295 struct ib_conn;
0296
0297
0298
0299
0300
0301
0302
0303
0304
0305
0306
0307 struct iser_device {
0308 struct ib_device *ib_device;
0309 struct ib_pd *pd;
0310 struct ib_event_handler event_handler;
0311 struct list_head ig_list;
0312 int refcount;
0313 };
0314
0315
0316
0317
0318
0319
0320
0321
0322 struct iser_reg_resources {
0323 struct ib_mr *mr;
0324 struct ib_mr *sig_mr;
0325 u8 mr_valid:1;
0326 };
0327
0328
0329
0330
0331
0332
0333
0334
0335
0336 struct iser_fr_desc {
0337 struct list_head list;
0338 struct iser_reg_resources rsc;
0339 bool sig_protected;
0340 struct list_head all_list;
0341 };
0342
0343
0344
0345
0346
0347
0348
0349
0350
0351 struct iser_fr_pool {
0352 struct list_head list;
0353 spinlock_t lock;
0354 int size;
0355 struct list_head all_list;
0356 };
0357
0358
0359
0360
0361
0362
0363
0364
0365
0366
0367
0368
0369
0370 struct ib_conn {
0371 struct rdma_cm_id *cma_id;
0372 struct ib_qp *qp;
0373 struct ib_cq *cq;
0374 u32 cq_size;
0375 struct iser_device *device;
0376 struct iser_fr_pool fr_pool;
0377 bool pi_support;
0378 struct ib_cqe reg_cqe;
0379 };
0380
0381
0382
0383
0384
0385
0386
0387
0388
0389
0390
0391
0392
0393
0394
0395
0396
0397
0398
0399
0400
0401
0402
0403
0404
0405
0406 struct iser_conn {
0407 struct ib_conn ib_conn;
0408 struct iscsi_conn *iscsi_conn;
0409 struct iscsi_endpoint *ep;
0410 enum iser_conn_state state;
0411 unsigned qp_max_recv_dtos;
0412 u16 max_cmds;
0413 char name[ISER_OBJECT_NAME_SIZE];
0414 struct work_struct release_work;
0415 struct mutex state_mutex;
0416 struct completion stop_completion;
0417 struct completion ib_completion;
0418 struct completion up_completion;
0419 struct list_head conn_list;
0420 struct iser_login_desc login_desc;
0421 struct iser_rx_desc *rx_descs;
0422 u32 num_rx_descs;
0423 unsigned short scsi_sg_tablesize;
0424 unsigned short pages_per_mr;
0425 bool snd_w_inv;
0426 };
0427
0428
0429
0430
0431
0432
0433
0434
0435
0436
0437
0438
0439
0440
0441 struct iscsi_iser_task {
0442 struct iser_tx_desc desc;
0443 struct iser_conn *iser_conn;
0444 enum iser_task_status status;
0445 struct scsi_cmnd *sc;
0446 int command_sent;
0447 int dir[ISER_DIRS_NUM];
0448 struct iser_mem_reg rdma_reg[ISER_DIRS_NUM];
0449 struct iser_data_buf data[ISER_DIRS_NUM];
0450 struct iser_data_buf prot[ISER_DIRS_NUM];
0451 };
0452
0453
0454
0455
0456
0457
0458
0459
0460
0461
0462 struct iser_global {
0463 struct mutex device_list_mutex;
0464 struct list_head device_list;
0465 struct mutex connlist_mutex;
0466 struct list_head connlist;
0467 struct kmem_cache *desc_cache;
0468 };
0469
0470 extern struct iser_global ig;
0471 extern int iser_debug_level;
0472 extern bool iser_pi_enable;
0473 extern unsigned int iser_max_sectors;
0474 extern bool iser_always_reg;
0475
0476 int iser_send_control(struct iscsi_conn *conn,
0477 struct iscsi_task *task);
0478
0479 int iser_send_command(struct iscsi_conn *conn,
0480 struct iscsi_task *task);
0481
0482 int iser_send_data_out(struct iscsi_conn *conn,
0483 struct iscsi_task *task,
0484 struct iscsi_data *hdr);
0485
0486 void iscsi_iser_recv(struct iscsi_conn *conn,
0487 struct iscsi_hdr *hdr,
0488 char *rx_data,
0489 int rx_data_len);
0490
0491 void iser_conn_init(struct iser_conn *iser_conn);
0492
0493 void iser_conn_release(struct iser_conn *iser_conn);
0494
0495 int iser_conn_terminate(struct iser_conn *iser_conn);
0496
0497 void iser_release_work(struct work_struct *work);
0498
0499 void iser_err_comp(struct ib_wc *wc, const char *type);
0500 void iser_login_rsp(struct ib_cq *cq, struct ib_wc *wc);
0501 void iser_task_rsp(struct ib_cq *cq, struct ib_wc *wc);
0502 void iser_cmd_comp(struct ib_cq *cq, struct ib_wc *wc);
0503 void iser_ctrl_comp(struct ib_cq *cq, struct ib_wc *wc);
0504 void iser_dataout_comp(struct ib_cq *cq, struct ib_wc *wc);
0505 void iser_reg_comp(struct ib_cq *cq, struct ib_wc *wc);
0506
0507 void iser_task_rdma_init(struct iscsi_iser_task *task);
0508
0509 void iser_task_rdma_finalize(struct iscsi_iser_task *task);
0510
0511 void iser_free_rx_descriptors(struct iser_conn *iser_conn);
0512
0513 void iser_finalize_rdma_unaligned_sg(struct iscsi_iser_task *iser_task,
0514 struct iser_data_buf *mem,
0515 enum iser_data_dir cmd_dir);
0516
0517 int iser_reg_mem_fastreg(struct iscsi_iser_task *task,
0518 enum iser_data_dir dir,
0519 bool all_imm);
0520 void iser_unreg_mem_fastreg(struct iscsi_iser_task *task,
0521 enum iser_data_dir dir);
0522
0523 int iser_connect(struct iser_conn *iser_conn,
0524 struct sockaddr *src_addr,
0525 struct sockaddr *dst_addr,
0526 int non_blocking);
0527
0528 int iser_post_recvl(struct iser_conn *iser_conn);
0529 int iser_post_recvm(struct iser_conn *iser_conn,
0530 struct iser_rx_desc *rx_desc);
0531 int iser_post_send(struct ib_conn *ib_conn, struct iser_tx_desc *tx_desc);
0532
0533 int iser_dma_map_task_data(struct iscsi_iser_task *iser_task,
0534 enum iser_data_dir iser_dir,
0535 enum dma_data_direction dma_dir);
0536
0537 void iser_dma_unmap_task_data(struct iscsi_iser_task *iser_task,
0538 enum iser_data_dir iser_dir,
0539 enum dma_data_direction dma_dir);
0540
0541 int iser_initialize_task_headers(struct iscsi_task *task,
0542 struct iser_tx_desc *tx_desc);
0543 int iser_alloc_rx_descriptors(struct iser_conn *iser_conn,
0544 struct iscsi_session *session);
0545 int iser_alloc_fastreg_pool(struct ib_conn *ib_conn,
0546 unsigned cmds_max,
0547 unsigned int size);
0548 void iser_free_fastreg_pool(struct ib_conn *ib_conn);
0549 u8 iser_check_task_pi_status(struct iscsi_iser_task *iser_task,
0550 enum iser_data_dir cmd_dir, sector_t *sector);
0551
0552 static inline struct iser_conn *
0553 to_iser_conn(struct ib_conn *ib_conn)
0554 {
0555 return container_of(ib_conn, struct iser_conn, ib_conn);
0556 }
0557
0558 static inline struct iser_rx_desc *
0559 iser_rx(struct ib_cqe *cqe)
0560 {
0561 return container_of(cqe, struct iser_rx_desc, cqe);
0562 }
0563
0564 static inline struct iser_tx_desc *
0565 iser_tx(struct ib_cqe *cqe)
0566 {
0567 return container_of(cqe, struct iser_tx_desc, cqe);
0568 }
0569
0570 static inline struct iser_login_desc *
0571 iser_login(struct ib_cqe *cqe)
0572 {
0573 return container_of(cqe, struct iser_login_desc, cqe);
0574 }
0575
0576 #endif