blob: 10be55a3185e7280e4eb79482d4ba17ae7650145 [file] [log] [blame]
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001#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
7#define ISERT_RDMA_LISTEN_BACKLOG 10
Vu Pham59464ef2013-08-28 23:23:35 +03008#define ISCSI_ISER_SG_TABLESIZE 256
Nicholas Bellinger9bb4ca62014-02-27 07:02:48 -08009#define ISER_FASTREG_LI_WRID 0xffffffffffffffffULL
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -080010
11enum isert_desc_type {
12 ISCSI_TX_CONTROL,
13 ISCSI_TX_DATAIN
14};
15
16enum iser_ib_op_code {
17 ISER_IB_RECV,
18 ISER_IB_SEND,
19 ISER_IB_RDMA_WRITE,
20 ISER_IB_RDMA_READ,
21};
22
23enum iser_conn_state {
24 ISER_CONN_INIT,
25 ISER_CONN_UP,
26 ISER_CONN_TERMINATING,
27 ISER_CONN_DOWN,
28};
29
30struct iser_rx_desc {
31 struct iser_hdr iser_header;
32 struct iscsi_hdr iscsi_header;
33 char data[ISER_RECV_DATA_SEG_LEN];
34 u64 dma_addr;
35 struct ib_sge rx_sg;
36 char pad[ISER_RX_PAD_SIZE];
37} __packed;
38
39struct iser_tx_desc {
40 struct iser_hdr iser_header;
41 struct iscsi_hdr iscsi_header;
42 enum isert_desc_type type;
43 u64 dma_addr;
44 struct ib_sge tx_sg[2];
45 int num_sge;
46 struct isert_cmd *isert_cmd;
Nicholas Bellinger95b60f02013-11-05 13:16:12 -080047 struct llist_node *comp_llnode_batch;
48 struct llist_node comp_llnode;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -080049 struct ib_send_wr send_wr;
50} __packed;
51
Vu Pham59464ef2013-08-28 23:23:35 +030052struct fast_reg_descriptor {
53 struct list_head list;
54 struct ib_mr *data_mr;
55 struct ib_fast_reg_page_list *data_frpl;
56 bool valid;
57};
58
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -080059struct isert_rdma_wr {
60 struct list_head wr_list;
61 struct isert_cmd *isert_cmd;
62 enum iser_ib_op_code iser_ib_op;
63 struct ib_sge *ib_sge;
Vu Pham59464ef2013-08-28 23:23:35 +030064 struct ib_sge s_ib_sge;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -080065 int num_sge;
66 struct scatterlist *sge;
67 int send_wr_num;
68 struct ib_send_wr *send_wr;
Vu Pham59464ef2013-08-28 23:23:35 +030069 struct ib_send_wr s_send_wr;
Vu Pham90ecc6e2013-08-28 23:23:33 +030070 u32 cur_rdma_length;
Vu Pham59464ef2013-08-28 23:23:35 +030071 struct fast_reg_descriptor *fr_desc;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -080072};
73
74struct isert_cmd {
75 uint32_t read_stag;
76 uint32_t write_stag;
77 uint64_t read_va;
78 uint64_t write_va;
Nicholas Bellingerdbbc5d12013-07-03 19:39:37 -070079 u64 pdu_buf_dma;
80 u32 pdu_buf_len;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -080081 u32 read_va_off;
82 u32 write_va_off;
83 u32 rdma_wr_num;
84 struct isert_conn *conn;
Nicholas Bellingerd703ce22013-08-17 14:27:56 -070085 struct iscsi_cmd *iscsi_cmd;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -080086 struct iser_tx_desc tx_desc;
87 struct isert_rdma_wr rdma_wr;
88 struct work_struct comp_work;
89};
90
91struct isert_device;
92
93struct isert_conn {
94 enum iser_conn_state state;
95 bool logout_posted;
96 int post_recv_buf_count;
97 atomic_t post_send_buf_count;
98 u32 responder_resources;
99 u32 initiator_depth;
100 u32 max_sge;
101 char *login_buf;
102 char *login_req_buf;
103 char *login_rsp_buf;
104 u64 login_req_dma;
105 u64 login_rsp_dma;
106 unsigned int conn_rx_desc_head;
107 struct iser_rx_desc *conn_rx_descs;
108 struct ib_recv_wr conn_rx_wr[ISERT_MIN_POSTED_RX];
109 struct iscsi_conn *conn;
110 struct list_head conn_accept_node;
111 struct completion conn_login_comp;
112 struct iser_tx_desc conn_login_tx_desc;
113 struct rdma_cm_id *conn_cm_id;
114 struct ib_pd *conn_pd;
115 struct ib_mr *conn_mr;
116 struct ib_qp *conn_qp;
117 struct isert_device *conn_device;
118 struct work_struct conn_logout_work;
Nicholas Bellingerb2cb9642013-07-03 03:05:37 -0700119 struct mutex conn_mutex;
Nicholas Bellingerdefd8842014-02-03 12:54:39 -0800120 struct completion conn_wait;
121 struct completion conn_wait_comp_err;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800122 struct kref conn_kref;
Sagi Grimberga3a5a822014-01-09 18:40:50 +0200123 struct list_head conn_fr_pool;
124 int conn_fr_pool_size;
125 /* lock to protect fastreg pool */
Vu Pham59464ef2013-08-28 23:23:35 +0300126 spinlock_t conn_lock;
Nicholas Bellinger95b60f02013-11-05 13:16:12 -0800127#define ISERT_COMP_BATCH_COUNT 8
128 int conn_comp_batch;
129 struct llist_head conn_comp_llist;
130 struct mutex conn_comp_mutex;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800131};
132
133#define ISERT_MAX_CQ 64
134
135struct isert_cq_desc {
136 struct isert_device *device;
137 int cq_index;
138 struct work_struct cq_rx_work;
139 struct work_struct cq_tx_work;
140};
141
142struct isert_device {
Sagi Grimberga3a5a822014-01-09 18:40:50 +0200143 int use_fastreg;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800144 int cqs_used;
145 int refcount;
146 int cq_active_qps[ISERT_MAX_CQ];
147 struct ib_device *ib_device;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800148 struct ib_cq *dev_rx_cq[ISERT_MAX_CQ];
149 struct ib_cq *dev_tx_cq[ISERT_MAX_CQ];
150 struct isert_cq_desc *cq_desc;
151 struct list_head dev_node;
Vu Pham59464ef2013-08-28 23:23:35 +0300152 struct ib_device_attr dev_attr;
Vu Phamd40945d2013-08-28 23:23:34 +0300153 int (*reg_rdma_mem)(struct iscsi_conn *conn,
154 struct iscsi_cmd *cmd,
155 struct isert_rdma_wr *wr);
156 void (*unreg_rdma_mem)(struct isert_cmd *isert_cmd,
157 struct isert_conn *isert_conn);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800158};
159
160struct isert_np {
161 wait_queue_head_t np_accept_wq;
162 struct rdma_cm_id *np_cm_id;
163 struct mutex np_accept_mutex;
164 struct list_head np_accept_list;
165 struct completion np_login_comp;
166};