blob: b233ee5e46b0ac67cb735449a7a9ccc87e9d7478 [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
8
9enum isert_desc_type {
10 ISCSI_TX_CONTROL,
11 ISCSI_TX_DATAIN
12};
13
14enum iser_ib_op_code {
15 ISER_IB_RECV,
16 ISER_IB_SEND,
17 ISER_IB_RDMA_WRITE,
18 ISER_IB_RDMA_READ,
19};
20
21enum iser_conn_state {
22 ISER_CONN_INIT,
23 ISER_CONN_UP,
Sagi Grimbergdc0672f2015-01-30 22:17:26 +000024 ISER_CONN_FULL_FEATURE,
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -080025 ISER_CONN_TERMINATING,
26 ISER_CONN_DOWN,
27};
28
29struct iser_rx_desc {
30 struct iser_hdr iser_header;
31 struct iscsi_hdr iscsi_header;
32 char data[ISER_RECV_DATA_SEG_LEN];
33 u64 dma_addr;
34 struct ib_sge rx_sg;
35 char pad[ISER_RX_PAD_SIZE];
36} __packed;
37
38struct iser_tx_desc {
39 struct iser_hdr iser_header;
40 struct iscsi_hdr iscsi_header;
41 enum isert_desc_type type;
42 u64 dma_addr;
43 struct ib_sge tx_sg[2];
44 int num_sge;
45 struct isert_cmd *isert_cmd;
46 struct ib_send_wr send_wr;
47} __packed;
48
49struct isert_rdma_wr {
50 struct list_head wr_list;
51 struct isert_cmd *isert_cmd;
52 enum iser_ib_op_code iser_ib_op;
53 struct ib_sge *ib_sge;
54 int num_sge;
55 struct scatterlist *sge;
56 int send_wr_num;
57 struct ib_send_wr *send_wr;
58};
59
60struct isert_cmd {
61 uint32_t read_stag;
62 uint32_t write_stag;
63 uint64_t read_va;
64 uint64_t write_va;
65 u64 sense_buf_dma;
66 u32 sense_buf_len;
67 u32 read_va_off;
68 u32 write_va_off;
69 u32 rdma_wr_num;
70 struct isert_conn *conn;
71 struct iscsi_cmd iscsi_cmd;
72 struct ib_sge *ib_sge;
73 struct iser_tx_desc tx_desc;
74 struct isert_rdma_wr rdma_wr;
75 struct work_struct comp_work;
76};
77
78struct isert_device;
79
80struct isert_conn {
81 enum iser_conn_state state;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -080082 int post_recv_buf_count;
83 atomic_t post_send_buf_count;
84 u32 responder_resources;
85 u32 initiator_depth;
86 u32 max_sge;
87 char *login_buf;
88 char *login_req_buf;
89 char *login_rsp_buf;
90 u64 login_req_dma;
Sagi Grimberg022ff2f2015-01-30 22:17:27 +000091 int login_req_len;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -080092 u64 login_rsp_dma;
93 unsigned int conn_rx_desc_head;
94 struct iser_rx_desc *conn_rx_descs;
95 struct ib_recv_wr conn_rx_wr[ISERT_MIN_POSTED_RX];
96 struct iscsi_conn *conn;
97 struct list_head conn_accept_node;
98 struct completion conn_login_comp;
Sagi Grimberg022ff2f2015-01-30 22:17:27 +000099 struct completion login_req_comp;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800100 struct iser_tx_desc conn_login_tx_desc;
101 struct rdma_cm_id *conn_cm_id;
102 struct ib_pd *conn_pd;
103 struct ib_mr *conn_mr;
104 struct ib_qp *conn_qp;
105 struct isert_device *conn_device;
Nicholas Bellingerd9e507c2013-07-03 03:05:37 -0700106 struct mutex conn_mutex;
Nicholas Bellingerd8bd97a02014-02-03 12:54:39 -0800107 struct completion conn_wait;
108 struct completion conn_wait_comp_err;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800109 struct kref conn_kref;
Sagi Grimberga3ecefb2015-01-30 22:17:30 +0000110 struct work_struct release_work;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800111};
112
113#define ISERT_MAX_CQ 64
114
115struct isert_cq_desc {
116 struct isert_device *device;
117 int cq_index;
118 struct work_struct cq_rx_work;
119 struct work_struct cq_tx_work;
120};
121
122struct isert_device {
123 int cqs_used;
124 int refcount;
125 int cq_active_qps[ISERT_MAX_CQ];
126 struct ib_device *ib_device;
127 struct ib_pd *dev_pd;
128 struct ib_mr *dev_mr;
129 struct ib_cq *dev_rx_cq[ISERT_MAX_CQ];
130 struct ib_cq *dev_tx_cq[ISERT_MAX_CQ];
131 struct isert_cq_desc *cq_desc;
132 struct list_head dev_node;
133};
134
135struct isert_np {
Sagi Grimbergb80e6c52015-01-30 22:17:29 +0000136 struct iscsi_np *np;
Sagi Grimberg8a2629a2014-04-29 13:13:45 +0300137 struct semaphore np_sem;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800138 struct rdma_cm_id *np_cm_id;
139 struct mutex np_accept_mutex;
140 struct list_head np_accept_list;
141 struct completion np_login_comp;
142};