blob: b104f4c2cd3852979521d02b514c6b7fa2a198fb [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;
57};
58
59struct isert_cmd {
60 uint32_t read_stag;
61 uint32_t write_stag;
62 uint64_t read_va;
63 uint64_t write_va;
64 u64 sense_buf_dma;
65 u32 sense_buf_len;
66 u32 read_va_off;
67 u32 write_va_off;
68 u32 rdma_wr_num;
69 struct isert_conn *conn;
70 struct iscsi_cmd iscsi_cmd;
71 struct ib_sge *ib_sge;
72 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;
105 wait_queue_head_t conn_wait;
106 wait_queue_head_t conn_wait_comp_err;
107 struct kref conn_kref;
108};
109
110#define ISERT_MAX_CQ 64
111
112struct isert_cq_desc {
113 struct isert_device *device;
114 int cq_index;
115 struct work_struct cq_rx_work;
116 struct work_struct cq_tx_work;
117};
118
119struct isert_device {
120 int cqs_used;
121 int refcount;
122 int cq_active_qps[ISERT_MAX_CQ];
123 struct ib_device *ib_device;
124 struct ib_pd *dev_pd;
125 struct ib_mr *dev_mr;
126 struct ib_cq *dev_rx_cq[ISERT_MAX_CQ];
127 struct ib_cq *dev_tx_cq[ISERT_MAX_CQ];
128 struct isert_cq_desc *cq_desc;
129 struct list_head dev_node;
130};
131
132struct isert_np {
133 wait_queue_head_t np_accept_wq;
134 struct rdma_cm_id *np_cm_id;
135 struct mutex np_accept_mutex;
136 struct list_head np_accept_list;
137 struct completion np_login_comp;
138};