blob: fc1d3232f89636c03ddb6aa73c6c9111a0dd33d9 [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
Sagi Grimbergbdf20e72014-12-02 16:57:43 +020010#define ISER_BEACON_WRID 0xfffffffffffffffeULL
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -080011
12enum isert_desc_type {
13 ISCSI_TX_CONTROL,
14 ISCSI_TX_DATAIN
15};
16
17enum iser_ib_op_code {
18 ISER_IB_RECV,
19 ISER_IB_SEND,
20 ISER_IB_RDMA_WRITE,
21 ISER_IB_RDMA_READ,
22};
23
24enum iser_conn_state {
25 ISER_CONN_INIT,
26 ISER_CONN_UP,
Sagi Grimberg128e9cc2014-12-02 16:57:20 +020027 ISER_CONN_FULL_FEATURE,
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -080028 ISER_CONN_TERMINATING,
29 ISER_CONN_DOWN,
30};
31
32struct iser_rx_desc {
33 struct iser_hdr iser_header;
34 struct iscsi_hdr iscsi_header;
35 char data[ISER_RECV_DATA_SEG_LEN];
36 u64 dma_addr;
37 struct ib_sge rx_sg;
38 char pad[ISER_RX_PAD_SIZE];
39} __packed;
40
41struct iser_tx_desc {
42 struct iser_hdr iser_header;
43 struct iscsi_hdr iscsi_header;
44 enum isert_desc_type type;
45 u64 dma_addr;
46 struct ib_sge tx_sg[2];
47 int num_sge;
48 struct isert_cmd *isert_cmd;
49 struct ib_send_wr send_wr;
50} __packed;
51
Sagi Grimbergd3e125d2014-02-19 17:50:23 +020052enum isert_indicator {
53 ISERT_PROTECTED = 1 << 0,
54 ISERT_DATA_KEY_VALID = 1 << 1,
55 ISERT_PROT_KEY_VALID = 1 << 2,
56 ISERT_SIG_KEY_VALID = 1 << 3,
57};
58
59struct pi_context {
60 struct ib_mr *prot_mr;
61 struct ib_fast_reg_page_list *prot_frpl;
62 struct ib_mr *sig_mr;
63};
64
Vu Pham59464ef2013-08-28 23:23:35 +030065struct fast_reg_descriptor {
Sagi Grimbergd3e125d2014-02-19 17:50:23 +020066 struct list_head list;
67 struct ib_mr *data_mr;
68 struct ib_fast_reg_page_list *data_frpl;
69 u8 ind;
70 struct pi_context *pi_ctx;
Vu Pham59464ef2013-08-28 23:23:35 +030071};
72
Sagi Grimberge3d7e4c2014-02-19 17:50:22 +020073struct isert_data_buf {
74 struct scatterlist *sg;
75 int nents;
76 u32 sg_off;
77 u32 len; /* cur_rdma_length */
78 u32 offset;
79 unsigned int dma_nents;
80 enum dma_data_direction dma_dir;
81};
82
Sagi Grimberg570db172014-12-02 16:57:31 +020083enum {
84 DATA = 0,
85 PROT = 1,
86 SIG = 2,
87};
88
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -080089struct isert_rdma_wr {
90 struct list_head wr_list;
91 struct isert_cmd *isert_cmd;
92 enum iser_ib_op_code iser_ib_op;
93 struct ib_sge *ib_sge;
Vu Pham59464ef2013-08-28 23:23:35 +030094 struct ib_sge s_ib_sge;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -080095 int send_wr_num;
96 struct ib_send_wr *send_wr;
Vu Pham59464ef2013-08-28 23:23:35 +030097 struct ib_send_wr s_send_wr;
Sagi Grimberg570db172014-12-02 16:57:31 +020098 struct ib_sge ib_sg[3];
Sagi Grimberge3d7e4c2014-02-19 17:50:22 +020099 struct isert_data_buf data;
Sagi Grimberg9e961ae2014-02-19 17:50:25 +0200100 struct isert_data_buf prot;
Vu Pham59464ef2013-08-28 23:23:35 +0300101 struct fast_reg_descriptor *fr_desc;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800102};
103
104struct isert_cmd {
105 uint32_t read_stag;
106 uint32_t write_stag;
107 uint64_t read_va;
108 uint64_t write_va;
Nicholas Bellingerdbbc5d12013-07-03 19:39:37 -0700109 u64 pdu_buf_dma;
110 u32 pdu_buf_len;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800111 u32 read_va_off;
112 u32 write_va_off;
113 u32 rdma_wr_num;
114 struct isert_conn *conn;
Nicholas Bellingerd703ce22013-08-17 14:27:56 -0700115 struct iscsi_cmd *iscsi_cmd;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800116 struct iser_tx_desc tx_desc;
117 struct isert_rdma_wr rdma_wr;
118 struct work_struct comp_work;
119};
120
121struct isert_device;
122
123struct isert_conn {
124 enum iser_conn_state state;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800125 int post_recv_buf_count;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800126 u32 responder_resources;
127 u32 initiator_depth;
Sagi Grimberg23a548e2014-12-02 16:57:35 +0200128 bool pi_support;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800129 u32 max_sge;
130 char *login_buf;
131 char *login_req_buf;
132 char *login_rsp_buf;
133 u64 login_req_dma;
Sagi Grimberg2371e5d2014-12-02 16:57:21 +0200134 int login_req_len;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800135 u64 login_rsp_dma;
136 unsigned int conn_rx_desc_head;
137 struct iser_rx_desc *conn_rx_descs;
138 struct ib_recv_wr conn_rx_wr[ISERT_MIN_POSTED_RX];
139 struct iscsi_conn *conn;
140 struct list_head conn_accept_node;
141 struct completion conn_login_comp;
Sagi Grimberg2371e5d2014-12-02 16:57:21 +0200142 struct completion login_req_comp;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800143 struct iser_tx_desc conn_login_tx_desc;
144 struct rdma_cm_id *conn_cm_id;
145 struct ib_pd *conn_pd;
146 struct ib_mr *conn_mr;
147 struct ib_qp *conn_qp;
148 struct isert_device *conn_device;
Nicholas Bellingerb2cb9642013-07-03 03:05:37 -0700149 struct mutex conn_mutex;
Nicholas Bellingerdefd8842014-02-03 12:54:39 -0800150 struct completion conn_wait;
151 struct completion conn_wait_comp_err;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800152 struct kref conn_kref;
Sagi Grimberga3a5a822014-01-09 18:40:50 +0200153 struct list_head conn_fr_pool;
154 int conn_fr_pool_size;
155 /* lock to protect fastreg pool */
Vu Pham59464ef2013-08-28 23:23:35 +0300156 spinlock_t conn_lock;
Sagi Grimbergb02efbf2014-12-02 16:57:29 +0200157 struct work_struct release_work;
Sagi Grimbergbdf20e72014-12-02 16:57:43 +0200158 struct ib_recv_wr beacon;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800159};
160
161#define ISERT_MAX_CQ 64
162
Sagi Grimberg4a295ba2014-12-02 16:57:40 +0200163/**
164 * struct isert_comp - iSER completion context
165 *
166 * @device: pointer to device handle
Sagi Grimberg6f0fae32014-12-02 16:57:41 +0200167 * @cq: completion queue
Sagi Grimberg4a295ba2014-12-02 16:57:40 +0200168 * @active_qps: Number of active QPs attached
169 * to completion context
Sagi Grimberg6f0fae32014-12-02 16:57:41 +0200170 * @work: completion work handle
Sagi Grimberg4a295ba2014-12-02 16:57:40 +0200171 */
172struct isert_comp {
Sagi Grimberg6f0fae32014-12-02 16:57:41 +0200173 struct isert_device *device;
174 struct ib_cq *cq;
Sagi Grimberg4a295ba2014-12-02 16:57:40 +0200175 int active_qps;
Sagi Grimberg6f0fae32014-12-02 16:57:41 +0200176 struct work_struct work;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800177};
178
179struct isert_device {
Sagi Grimberga3a5a822014-01-09 18:40:50 +0200180 int use_fastreg;
Sagi Grimbergd3e125d2014-02-19 17:50:23 +0200181 bool pi_capable;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800182 int refcount;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800183 struct ib_device *ib_device;
Sagi Grimberg4a295ba2014-12-02 16:57:40 +0200184 struct isert_comp *comps;
185 int comps_used;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800186 struct list_head dev_node;
Vu Pham59464ef2013-08-28 23:23:35 +0300187 struct ib_device_attr dev_attr;
Vu Phamd40945d2013-08-28 23:23:34 +0300188 int (*reg_rdma_mem)(struct iscsi_conn *conn,
189 struct iscsi_cmd *cmd,
190 struct isert_rdma_wr *wr);
191 void (*unreg_rdma_mem)(struct isert_cmd *isert_cmd,
192 struct isert_conn *isert_conn);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800193};
194
195struct isert_np {
Sagi Grimbergca6c1d82014-12-02 16:57:27 +0200196 struct iscsi_np *np;
Sagi Grimberg531b7bf2014-04-29 13:13:45 +0300197 struct semaphore np_sem;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800198 struct rdma_cm_id *np_cm_id;
199 struct mutex np_accept_mutex;
200 struct list_head np_accept_list;
201 struct completion np_login_comp;
202};