]>
Commit | Line | Data |
---|---|---|
b8d26b3b NB |
1 | #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> | |
38a2d0d4 | 6 | #include <rdma/rw.h> |
d3cf81f9 SG |
7 | #include <scsi/iser.h> |
8 | ||
b8d26b3b | 9 | |
24f412dd SG |
10 | #define DRV_NAME "isert" |
11 | #define PFX DRV_NAME ": " | |
12 | ||
13 | #define isert_dbg(fmt, arg...) \ | |
14 | do { \ | |
15 | if (unlikely(isert_debug_level > 2)) \ | |
16 | printk(KERN_DEBUG PFX "%s: " fmt,\ | |
17 | __func__ , ## arg); \ | |
18 | } while (0) | |
19 | ||
20 | #define isert_warn(fmt, arg...) \ | |
21 | do { \ | |
22 | if (unlikely(isert_debug_level > 0)) \ | |
23 | pr_warn(PFX "%s: " fmt, \ | |
24 | __func__ , ## arg); \ | |
25 | } while (0) | |
26 | ||
27 | #define isert_info(fmt, arg...) \ | |
28 | do { \ | |
29 | if (unlikely(isert_debug_level > 1)) \ | |
30 | pr_info(PFX "%s: " fmt, \ | |
31 | __func__ , ## arg); \ | |
32 | } while (0) | |
33 | ||
34 | #define isert_err(fmt, arg...) \ | |
35 | pr_err(PFX "%s: " fmt, __func__ , ## arg) | |
36 | ||
c6494153 SG |
37 | /* Constant PDU lengths calculations */ |
38 | #define ISER_HEADERS_LEN (sizeof(struct iser_ctrl) + \ | |
39 | sizeof(struct iscsi_hdr)) | |
ed1083b2 | 40 | #define ISER_RX_PAYLOAD_SIZE (ISER_HEADERS_LEN + ISCSI_DEF_MAX_RECV_SEG_LEN) |
c6494153 SG |
41 | |
42 | /* QP settings */ | |
43 | /* Maximal bounds on received asynchronous PDUs */ | |
44 | #define ISERT_MAX_TX_MISC_PDUS 4 /* NOOP_IN(2) , ASYNC_EVENT(2) */ | |
45 | ||
46 | #define ISERT_MAX_RX_MISC_PDUS 6 /* | |
47 | * NOOP_OUT(2), TEXT(1), | |
48 | * SCSI_TMFUNC(2), LOGOUT(1) | |
49 | */ | |
50 | ||
51 | #define ISCSI_DEF_XMIT_CMDS_MAX 128 /* from libiscsi.h, must be power of 2 */ | |
52 | ||
53 | #define ISERT_QP_MAX_RECV_DTOS (ISCSI_DEF_XMIT_CMDS_MAX) | |
54 | ||
55 | #define ISERT_MIN_POSTED_RX (ISCSI_DEF_XMIT_CMDS_MAX >> 2) | |
56 | ||
38a2d0d4 | 57 | #define ISERT_QP_MAX_REQ_DTOS (ISCSI_DEF_XMIT_CMDS_MAX + \ |
c6494153 SG |
58 | ISERT_MAX_TX_MISC_PDUS + \ |
59 | ISERT_MAX_RX_MISC_PDUS) | |
60 | ||
ed1083b2 | 61 | #define ISER_RX_PAD_SIZE (ISCSI_DEF_MAX_RECV_SEG_LEN + 4096 - \ |
9679cc51 | 62 | (ISER_RX_PAYLOAD_SIZE + sizeof(u64) + sizeof(struct ib_sge) + \ |
7a56dc88 | 63 | sizeof(struct ib_cqe) + sizeof(bool))) |
c6494153 | 64 | |
59464ef4 | 65 | #define ISCSI_ISER_SG_TABLESIZE 256 |
b8d26b3b NB |
66 | |
67 | enum isert_desc_type { | |
68 | ISCSI_TX_CONTROL, | |
69 | ISCSI_TX_DATAIN | |
70 | }; | |
71 | ||
b8d26b3b NB |
72 | enum iser_conn_state { |
73 | ISER_CONN_INIT, | |
74 | ISER_CONN_UP, | |
aea92980 | 75 | ISER_CONN_BOUND, |
128e9cc8 | 76 | ISER_CONN_FULL_FEATURE, |
b8d26b3b NB |
77 | ISER_CONN_TERMINATING, |
78 | ISER_CONN_DOWN, | |
79 | }; | |
80 | ||
81 | struct iser_rx_desc { | |
d3cf81f9 | 82 | struct iser_ctrl iser_header; |
b8d26b3b | 83 | struct iscsi_hdr iscsi_header; |
ed1083b2 | 84 | char data[ISCSI_DEF_MAX_RECV_SEG_LEN]; |
b8d26b3b NB |
85 | u64 dma_addr; |
86 | struct ib_sge rx_sg; | |
9679cc51 | 87 | struct ib_cqe rx_cqe; |
7a56dc88 | 88 | bool in_use; |
b8d26b3b NB |
89 | char pad[ISER_RX_PAD_SIZE]; |
90 | } __packed; | |
91 | ||
9679cc51 CH |
92 | static inline struct iser_rx_desc *cqe_to_rx_desc(struct ib_cqe *cqe) |
93 | { | |
94 | return container_of(cqe, struct iser_rx_desc, rx_cqe); | |
95 | } | |
96 | ||
b8d26b3b | 97 | struct iser_tx_desc { |
d3cf81f9 | 98 | struct iser_ctrl iser_header; |
b8d26b3b NB |
99 | struct iscsi_hdr iscsi_header; |
100 | enum isert_desc_type type; | |
101 | u64 dma_addr; | |
102 | struct ib_sge tx_sg[2]; | |
9679cc51 | 103 | struct ib_cqe tx_cqe; |
b8d26b3b | 104 | int num_sge; |
b8d26b3b NB |
105 | struct ib_send_wr send_wr; |
106 | } __packed; | |
107 | ||
9679cc51 CH |
108 | static inline struct iser_tx_desc *cqe_to_tx_desc(struct ib_cqe *cqe) |
109 | { | |
110 | return container_of(cqe, struct iser_tx_desc, tx_cqe); | |
111 | } | |
112 | ||
b8d26b3b NB |
113 | struct isert_cmd { |
114 | uint32_t read_stag; | |
115 | uint32_t write_stag; | |
116 | uint64_t read_va; | |
117 | uint64_t write_va; | |
422bd0ac | 118 | uint32_t inv_rkey; |
dbbc5d11 NB |
119 | u64 pdu_buf_dma; |
120 | u32 pdu_buf_len; | |
b8d26b3b | 121 | struct isert_conn *conn; |
d703ce2f | 122 | struct iscsi_cmd *iscsi_cmd; |
b8d26b3b | 123 | struct iser_tx_desc tx_desc; |
4366b19c | 124 | struct iser_rx_desc *rx_desc; |
38a2d0d4 | 125 | struct rdma_rw_ctx rw; |
b8d26b3b | 126 | struct work_struct comp_work; |
9fd60088 | 127 | struct scatterlist sg; |
b8d26b3b NB |
128 | }; |
129 | ||
e3416ab2 CH |
130 | static inline struct isert_cmd *tx_desc_to_cmd(struct iser_tx_desc *desc) |
131 | { | |
132 | return container_of(desc, struct isert_cmd, tx_desc); | |
133 | } | |
134 | ||
b8d26b3b NB |
135 | struct isert_device; |
136 | ||
137 | struct isert_conn { | |
138 | enum iser_conn_state state; | |
b8d26b3b NB |
139 | u32 responder_resources; |
140 | u32 initiator_depth; | |
23a548ee | 141 | bool pi_support; |
5adabdd1 | 142 | struct iser_rx_desc *login_req_buf; |
b8d26b3b NB |
143 | char *login_rsp_buf; |
144 | u64 login_req_dma; | |
2371e5da | 145 | int login_req_len; |
b8d26b3b | 146 | u64 login_rsp_dma; |
dac6ab30 | 147 | struct iser_rx_desc *rx_descs; |
4366b19c | 148 | struct ib_recv_wr rx_wr[ISERT_QP_MAX_RECV_DTOS]; |
b8d26b3b | 149 | struct iscsi_conn *conn; |
bd379220 | 150 | struct list_head node; |
dac6ab30 | 151 | struct completion login_comp; |
2371e5da | 152 | struct completion login_req_comp; |
dac6ab30 SG |
153 | struct iser_tx_desc login_tx_desc; |
154 | struct rdma_cm_id *cm_id; | |
155 | struct ib_qp *qp; | |
156 | struct isert_device *device; | |
157 | struct mutex mutex; | |
dac6ab30 | 158 | struct kref kref; |
b02efbfc | 159 | struct work_struct release_work; |
991bb764 | 160 | bool logout_posted; |
422bd0ac | 161 | bool snd_w_inv; |
63b268d2 RR |
162 | wait_queue_head_t rem_wait; |
163 | bool dev_removed; | |
b8d26b3b NB |
164 | }; |
165 | ||
166 | #define ISERT_MAX_CQ 64 | |
167 | ||
4a295bae SG |
168 | /** |
169 | * struct isert_comp - iSER completion context | |
170 | * | |
171 | * @device: pointer to device handle | |
6f0fae3d | 172 | * @cq: completion queue |
4a295bae SG |
173 | * @active_qps: Number of active QPs attached |
174 | * to completion context | |
4a295bae SG |
175 | */ |
176 | struct isert_comp { | |
6f0fae3d SG |
177 | struct isert_device *device; |
178 | struct ib_cq *cq; | |
4a295bae | 179 | int active_qps; |
b8d26b3b NB |
180 | }; |
181 | ||
182 | struct isert_device { | |
d3e125da | 183 | bool pi_capable; |
b8d26b3b | 184 | int refcount; |
b8d26b3b | 185 | struct ib_device *ib_device; |
67cb3949 | 186 | struct ib_pd *pd; |
4a295bae SG |
187 | struct isert_comp *comps; |
188 | int comps_used; | |
b8d26b3b NB |
189 | struct list_head dev_node; |
190 | }; | |
191 | ||
192 | struct isert_np { | |
ca6c1d82 | 193 | struct iscsi_np *np; |
ed8cb0a4 JD |
194 | struct semaphore sem; |
195 | struct rdma_cm_id *cm_id; | |
196 | struct mutex mutex; | |
bd379220 JD |
197 | struct list_head accepted; |
198 | struct list_head pending; | |
b8d26b3b | 199 | }; |