blob: 76565030e4e70b5a3f52dd0a8114e963c4ee7aed [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,
24 ISER_CONN_TERMINATING,
25 ISER_CONN_DOWN,
26};
27
28struct iser_rx_desc {
29 struct iser_hdr iser_header;
30 struct iscsi_hdr iscsi_header;
31 char data[ISER_RECV_DATA_SEG_LEN];
32 u64 dma_addr;
33 struct ib_sge rx_sg;
34 char pad[ISER_RX_PAD_SIZE];
35} __packed;
36
37struct iser_tx_desc {
38 struct iser_hdr iser_header;
39 struct iscsi_hdr iscsi_header;
40 enum isert_desc_type type;
41 u64 dma_addr;
42 struct ib_sge tx_sg[2];
43 int num_sge;
44 struct isert_cmd *isert_cmd;
45 struct ib_send_wr send_wr;
46} __packed;
47
48struct isert_rdma_wr {
49 struct list_head wr_list;
50 struct isert_cmd *isert_cmd;
51 enum iser_ib_op_code iser_ib_op;
52 struct ib_sge *ib_sge;
53 int num_sge;
54 struct scatterlist *sge;
55 int send_wr_num;
56 struct ib_send_wr *send_wr;
Vu Pham90ecc6e2013-08-28 23:23:33 +030057 u32 cur_rdma_length;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -080058};
59
60struct isert_cmd {
61 uint32_t read_stag;
62 uint32_t write_stag;
63 uint64_t read_va;
64 uint64_t write_va;
Nicholas Bellingerdbbc5d12013-07-03 19:39:37 -070065 u64 pdu_buf_dma;
66 u32 pdu_buf_len;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -080067 u32 read_va_off;
68 u32 write_va_off;
69 u32 rdma_wr_num;
70 struct isert_conn *conn;
Nicholas Bellingerd703ce22013-08-17 14:27:56 -070071 struct iscsi_cmd *iscsi_cmd;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -080072 struct iser_tx_desc tx_desc;
73 struct isert_rdma_wr rdma_wr;
74 struct work_struct comp_work;
75};
76
77struct isert_device;
78
79struct isert_conn {
80 enum iser_conn_state state;
81 bool logout_posted;
82 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;
91 u64 login_rsp_dma;
92 unsigned int conn_rx_desc_head;
93 struct iser_rx_desc *conn_rx_descs;
94 struct ib_recv_wr conn_rx_wr[ISERT_MIN_POSTED_RX];
95 struct iscsi_conn *conn;
96 struct list_head conn_accept_node;
97 struct completion conn_login_comp;
98 struct iser_tx_desc conn_login_tx_desc;
99 struct rdma_cm_id *conn_cm_id;
100 struct ib_pd *conn_pd;
101 struct ib_mr *conn_mr;
102 struct ib_qp *conn_qp;
103 struct isert_device *conn_device;
104 struct work_struct conn_logout_work;
Nicholas Bellingerb2cb9642013-07-03 03:05:37 -0700105 struct mutex conn_mutex;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800106 wait_queue_head_t conn_wait;
107 wait_queue_head_t conn_wait_comp_err;
108 struct kref conn_kref;
109};
110
111#define ISERT_MAX_CQ 64
112
113struct isert_cq_desc {
114 struct isert_device *device;
115 int cq_index;
116 struct work_struct cq_rx_work;
117 struct work_struct cq_tx_work;
118};
119
120struct isert_device {
121 int cqs_used;
122 int refcount;
123 int cq_active_qps[ISERT_MAX_CQ];
124 struct ib_device *ib_device;
125 struct ib_pd *dev_pd;
126 struct ib_mr *dev_mr;
127 struct ib_cq *dev_rx_cq[ISERT_MAX_CQ];
128 struct ib_cq *dev_tx_cq[ISERT_MAX_CQ];
129 struct isert_cq_desc *cq_desc;
130 struct list_head dev_node;
Vu Phamd40945d2013-08-28 23:23:34 +0300131 int (*reg_rdma_mem)(struct iscsi_conn *conn,
132 struct iscsi_cmd *cmd,
133 struct isert_rdma_wr *wr);
134 void (*unreg_rdma_mem)(struct isert_cmd *isert_cmd,
135 struct isert_conn *isert_conn);
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800136};
137
138struct isert_np {
139 wait_queue_head_t np_accept_wq;
140 struct rdma_cm_id *np_cm_id;
141 struct mutex np_accept_mutex;
142 struct list_head np_accept_list;
143 struct completion np_login_comp;
144};