Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 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> |
Sagi Grimberg | d3cf81f | 2015-12-09 14:12:03 +0200 | [diff] [blame] | 6 | #include <scsi/iser.h> |
| 7 | |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 8 | |
Sagi Grimberg | 24f412d | 2014-12-07 13:12:02 +0200 | [diff] [blame] | 9 | #define DRV_NAME "isert" |
| 10 | #define PFX DRV_NAME ": " |
| 11 | |
| 12 | #define isert_dbg(fmt, arg...) \ |
| 13 | do { \ |
| 14 | if (unlikely(isert_debug_level > 2)) \ |
| 15 | printk(KERN_DEBUG PFX "%s: " fmt,\ |
| 16 | __func__ , ## arg); \ |
| 17 | } while (0) |
| 18 | |
| 19 | #define isert_warn(fmt, arg...) \ |
| 20 | do { \ |
| 21 | if (unlikely(isert_debug_level > 0)) \ |
| 22 | pr_warn(PFX "%s: " fmt, \ |
| 23 | __func__ , ## arg); \ |
| 24 | } while (0) |
| 25 | |
| 26 | #define isert_info(fmt, arg...) \ |
| 27 | do { \ |
| 28 | if (unlikely(isert_debug_level > 1)) \ |
| 29 | pr_info(PFX "%s: " fmt, \ |
| 30 | __func__ , ## arg); \ |
| 31 | } while (0) |
| 32 | |
| 33 | #define isert_err(fmt, arg...) \ |
| 34 | pr_err(PFX "%s: " fmt, __func__ , ## arg) |
| 35 | |
Sagi Grimberg | c649415 | 2015-12-09 14:12:04 +0200 | [diff] [blame] | 36 | /* Constant PDU lengths calculations */ |
| 37 | #define ISER_HEADERS_LEN (sizeof(struct iser_ctrl) + \ |
| 38 | sizeof(struct iscsi_hdr)) |
Christoph Hellwig | ed1083b | 2016-02-24 19:24:04 +0200 | [diff] [blame] | 39 | #define ISER_RX_PAYLOAD_SIZE (ISER_HEADERS_LEN + ISCSI_DEF_MAX_RECV_SEG_LEN) |
Sagi Grimberg | c649415 | 2015-12-09 14:12:04 +0200 | [diff] [blame] | 40 | |
| 41 | /* QP settings */ |
| 42 | /* Maximal bounds on received asynchronous PDUs */ |
| 43 | #define ISERT_MAX_TX_MISC_PDUS 4 /* NOOP_IN(2) , ASYNC_EVENT(2) */ |
| 44 | |
| 45 | #define ISERT_MAX_RX_MISC_PDUS 6 /* |
| 46 | * NOOP_OUT(2), TEXT(1), |
| 47 | * SCSI_TMFUNC(2), LOGOUT(1) |
| 48 | */ |
| 49 | |
| 50 | #define ISCSI_DEF_XMIT_CMDS_MAX 128 /* from libiscsi.h, must be power of 2 */ |
| 51 | |
| 52 | #define ISERT_QP_MAX_RECV_DTOS (ISCSI_DEF_XMIT_CMDS_MAX) |
| 53 | |
| 54 | #define ISERT_MIN_POSTED_RX (ISCSI_DEF_XMIT_CMDS_MAX >> 2) |
| 55 | |
| 56 | #define ISERT_INFLIGHT_DATAOUTS 8 |
| 57 | |
| 58 | #define ISERT_QP_MAX_REQ_DTOS (ISCSI_DEF_XMIT_CMDS_MAX * \ |
| 59 | (1 + ISERT_INFLIGHT_DATAOUTS) + \ |
| 60 | ISERT_MAX_TX_MISC_PDUS + \ |
| 61 | ISERT_MAX_RX_MISC_PDUS) |
| 62 | |
Christoph Hellwig | ed1083b | 2016-02-24 19:24:04 +0200 | [diff] [blame] | 63 | #define ISER_RX_PAD_SIZE (ISCSI_DEF_MAX_RECV_SEG_LEN + 4096 - \ |
Christoph Hellwig | 9679cc5 | 2016-02-24 19:24:06 +0200 | [diff] [blame] | 64 | (ISER_RX_PAYLOAD_SIZE + sizeof(u64) + sizeof(struct ib_sge) + \ |
| 65 | sizeof(struct ib_cqe))) |
Sagi Grimberg | c649415 | 2015-12-09 14:12:04 +0200 | [diff] [blame] | 66 | |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 67 | #define ISCSI_ISER_SG_TABLESIZE 256 |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 68 | |
| 69 | enum isert_desc_type { |
| 70 | ISCSI_TX_CONTROL, |
| 71 | ISCSI_TX_DATAIN |
| 72 | }; |
| 73 | |
| 74 | enum iser_ib_op_code { |
| 75 | ISER_IB_RECV, |
| 76 | ISER_IB_SEND, |
| 77 | ISER_IB_RDMA_WRITE, |
| 78 | ISER_IB_RDMA_READ, |
| 79 | }; |
| 80 | |
| 81 | enum iser_conn_state { |
| 82 | ISER_CONN_INIT, |
| 83 | ISER_CONN_UP, |
Jenny Derzhavetz | aea9298 | 2016-02-24 19:23:59 +0200 | [diff] [blame] | 84 | ISER_CONN_BOUND, |
Sagi Grimberg | 128e9cc | 2014-12-02 16:57:20 +0200 | [diff] [blame] | 85 | ISER_CONN_FULL_FEATURE, |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 86 | ISER_CONN_TERMINATING, |
| 87 | ISER_CONN_DOWN, |
| 88 | }; |
| 89 | |
| 90 | struct iser_rx_desc { |
Sagi Grimberg | d3cf81f | 2015-12-09 14:12:03 +0200 | [diff] [blame] | 91 | struct iser_ctrl iser_header; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 92 | struct iscsi_hdr iscsi_header; |
Christoph Hellwig | ed1083b | 2016-02-24 19:24:04 +0200 | [diff] [blame] | 93 | char data[ISCSI_DEF_MAX_RECV_SEG_LEN]; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 94 | u64 dma_addr; |
| 95 | struct ib_sge rx_sg; |
Christoph Hellwig | 9679cc5 | 2016-02-24 19:24:06 +0200 | [diff] [blame] | 96 | struct ib_cqe rx_cqe; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 97 | char pad[ISER_RX_PAD_SIZE]; |
| 98 | } __packed; |
| 99 | |
Christoph Hellwig | 9679cc5 | 2016-02-24 19:24:06 +0200 | [diff] [blame] | 100 | static inline struct iser_rx_desc *cqe_to_rx_desc(struct ib_cqe *cqe) |
| 101 | { |
| 102 | return container_of(cqe, struct iser_rx_desc, rx_cqe); |
| 103 | } |
| 104 | |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 105 | struct iser_tx_desc { |
Sagi Grimberg | d3cf81f | 2015-12-09 14:12:03 +0200 | [diff] [blame] | 106 | struct iser_ctrl iser_header; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 107 | struct iscsi_hdr iscsi_header; |
| 108 | enum isert_desc_type type; |
| 109 | u64 dma_addr; |
| 110 | struct ib_sge tx_sg[2]; |
Christoph Hellwig | 9679cc5 | 2016-02-24 19:24:06 +0200 | [diff] [blame] | 111 | struct ib_cqe tx_cqe; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 112 | int num_sge; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 113 | struct ib_send_wr send_wr; |
| 114 | } __packed; |
| 115 | |
Christoph Hellwig | 9679cc5 | 2016-02-24 19:24:06 +0200 | [diff] [blame] | 116 | static inline struct iser_tx_desc *cqe_to_tx_desc(struct ib_cqe *cqe) |
| 117 | { |
| 118 | return container_of(cqe, struct iser_tx_desc, tx_cqe); |
| 119 | } |
| 120 | |
| 121 | |
Sagi Grimberg | d3e125d | 2014-02-19 17:50:23 +0200 | [diff] [blame] | 122 | enum isert_indicator { |
| 123 | ISERT_PROTECTED = 1 << 0, |
| 124 | ISERT_DATA_KEY_VALID = 1 << 1, |
| 125 | ISERT_PROT_KEY_VALID = 1 << 2, |
| 126 | ISERT_SIG_KEY_VALID = 1 << 3, |
| 127 | }; |
| 128 | |
| 129 | struct pi_context { |
| 130 | struct ib_mr *prot_mr; |
Sagi Grimberg | d3e125d | 2014-02-19 17:50:23 +0200 | [diff] [blame] | 131 | struct ib_mr *sig_mr; |
| 132 | }; |
| 133 | |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 134 | struct fast_reg_descriptor { |
Sagi Grimberg | d3e125d | 2014-02-19 17:50:23 +0200 | [diff] [blame] | 135 | struct list_head list; |
| 136 | struct ib_mr *data_mr; |
Sagi Grimberg | d3e125d | 2014-02-19 17:50:23 +0200 | [diff] [blame] | 137 | u8 ind; |
| 138 | struct pi_context *pi_ctx; |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 139 | }; |
| 140 | |
Sagi Grimberg | e3d7e4c | 2014-02-19 17:50:22 +0200 | [diff] [blame] | 141 | struct isert_data_buf { |
| 142 | struct scatterlist *sg; |
| 143 | int nents; |
| 144 | u32 sg_off; |
| 145 | u32 len; /* cur_rdma_length */ |
| 146 | u32 offset; |
| 147 | unsigned int dma_nents; |
| 148 | enum dma_data_direction dma_dir; |
| 149 | }; |
| 150 | |
Sagi Grimberg | 570db17 | 2014-12-02 16:57:31 +0200 | [diff] [blame] | 151 | enum { |
| 152 | DATA = 0, |
| 153 | PROT = 1, |
| 154 | SIG = 2, |
| 155 | }; |
| 156 | |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 157 | struct isert_cmd { |
| 158 | uint32_t read_stag; |
| 159 | uint32_t write_stag; |
| 160 | uint64_t read_va; |
| 161 | uint64_t write_va; |
Jenny Derzhavetz | 422bd0a | 2015-12-09 14:12:06 +0200 | [diff] [blame] | 162 | uint32_t inv_rkey; |
Nicholas Bellinger | dbbc5d1 | 2013-07-03 19:39:37 -0700 | [diff] [blame] | 163 | u64 pdu_buf_dma; |
| 164 | u32 pdu_buf_len; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 165 | struct isert_conn *conn; |
Nicholas Bellinger | d703ce2 | 2013-08-17 14:27:56 -0700 | [diff] [blame] | 166 | struct iscsi_cmd *iscsi_cmd; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 167 | struct iser_tx_desc tx_desc; |
Jenny Derzhavetz | 4366b19 | 2015-09-06 14:52:25 +0300 | [diff] [blame] | 168 | struct iser_rx_desc *rx_desc; |
Christoph Hellwig | d1ca2ed | 2016-02-24 19:24:07 +0200 | [diff] [blame] | 169 | enum iser_ib_op_code iser_ib_op; |
| 170 | struct ib_sge *ib_sge; |
| 171 | struct ib_sge s_ib_sge; |
| 172 | int rdma_wr_num; |
| 173 | struct ib_rdma_wr *rdma_wr; |
| 174 | struct ib_rdma_wr s_rdma_wr; |
| 175 | struct ib_sge ib_sg[3]; |
| 176 | struct isert_data_buf data; |
| 177 | struct isert_data_buf prot; |
| 178 | struct fast_reg_descriptor *fr_desc; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 179 | struct work_struct comp_work; |
Jenny Derzhavetz | 9fd6008 | 2015-09-06 14:52:26 +0300 | [diff] [blame] | 180 | struct scatterlist sg; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 181 | }; |
| 182 | |
Christoph Hellwig | e3416ab | 2016-02-24 19:24:08 +0200 | [diff] [blame] | 183 | static inline struct isert_cmd *tx_desc_to_cmd(struct iser_tx_desc *desc) |
| 184 | { |
| 185 | return container_of(desc, struct isert_cmd, tx_desc); |
| 186 | } |
| 187 | |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 188 | struct isert_device; |
| 189 | |
| 190 | struct isert_conn { |
| 191 | enum iser_conn_state state; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 192 | u32 responder_resources; |
| 193 | u32 initiator_depth; |
Sagi Grimberg | 23a548e | 2014-12-02 16:57:35 +0200 | [diff] [blame] | 194 | bool pi_support; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 195 | u32 max_sge; |
Christoph Hellwig | 5adabdd | 2016-02-24 19:24:05 +0200 | [diff] [blame] | 196 | struct iser_rx_desc *login_req_buf; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 197 | char *login_rsp_buf; |
| 198 | u64 login_req_dma; |
Sagi Grimberg | 2371e5d | 2014-12-02 16:57:21 +0200 | [diff] [blame] | 199 | int login_req_len; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 200 | u64 login_rsp_dma; |
Sagi Grimberg | dac6ab3 | 2015-03-29 15:52:19 +0300 | [diff] [blame] | 201 | struct iser_rx_desc *rx_descs; |
Jenny Derzhavetz | 4366b19 | 2015-09-06 14:52:25 +0300 | [diff] [blame] | 202 | struct ib_recv_wr rx_wr[ISERT_QP_MAX_RECV_DTOS]; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 203 | struct iscsi_conn *conn; |
Jenny Derzhavetz | bd37922 | 2015-09-06 14:52:24 +0300 | [diff] [blame] | 204 | struct list_head node; |
Sagi Grimberg | dac6ab3 | 2015-03-29 15:52:19 +0300 | [diff] [blame] | 205 | struct completion login_comp; |
Sagi Grimberg | 2371e5d | 2014-12-02 16:57:21 +0200 | [diff] [blame] | 206 | struct completion login_req_comp; |
Sagi Grimberg | dac6ab3 | 2015-03-29 15:52:19 +0300 | [diff] [blame] | 207 | struct iser_tx_desc login_tx_desc; |
| 208 | struct rdma_cm_id *cm_id; |
| 209 | struct ib_qp *qp; |
| 210 | struct isert_device *device; |
| 211 | struct mutex mutex; |
Sagi Grimberg | dac6ab3 | 2015-03-29 15:52:19 +0300 | [diff] [blame] | 212 | struct kref kref; |
| 213 | struct list_head fr_pool; |
| 214 | int fr_pool_size; |
Sagi Grimberg | a3a5a82 | 2014-01-09 18:40:50 +0200 | [diff] [blame] | 215 | /* lock to protect fastreg pool */ |
Sagi Grimberg | dac6ab3 | 2015-03-29 15:52:19 +0300 | [diff] [blame] | 216 | spinlock_t pool_lock; |
Sagi Grimberg | b02efbf | 2014-12-02 16:57:29 +0200 | [diff] [blame] | 217 | struct work_struct release_work; |
Sagi Grimberg | 991bb76 | 2014-12-07 13:12:01 +0200 | [diff] [blame] | 218 | bool logout_posted; |
Jenny Derzhavetz | 422bd0a | 2015-12-09 14:12:06 +0200 | [diff] [blame] | 219 | bool snd_w_inv; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 220 | }; |
| 221 | |
| 222 | #define ISERT_MAX_CQ 64 |
| 223 | |
Sagi Grimberg | 4a295ba | 2014-12-02 16:57:40 +0200 | [diff] [blame] | 224 | /** |
| 225 | * struct isert_comp - iSER completion context |
| 226 | * |
| 227 | * @device: pointer to device handle |
Sagi Grimberg | 6f0fae3 | 2014-12-02 16:57:41 +0200 | [diff] [blame] | 228 | * @cq: completion queue |
Sagi Grimberg | 4a295ba | 2014-12-02 16:57:40 +0200 | [diff] [blame] | 229 | * @active_qps: Number of active QPs attached |
| 230 | * to completion context |
Sagi Grimberg | 4a295ba | 2014-12-02 16:57:40 +0200 | [diff] [blame] | 231 | */ |
| 232 | struct isert_comp { |
Sagi Grimberg | 6f0fae3 | 2014-12-02 16:57:41 +0200 | [diff] [blame] | 233 | struct isert_device *device; |
| 234 | struct ib_cq *cq; |
Sagi Grimberg | 4a295ba | 2014-12-02 16:57:40 +0200 | [diff] [blame] | 235 | int active_qps; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 236 | }; |
| 237 | |
| 238 | struct isert_device { |
Sagi Grimberg | a3a5a82 | 2014-01-09 18:40:50 +0200 | [diff] [blame] | 239 | int use_fastreg; |
Sagi Grimberg | d3e125d | 2014-02-19 17:50:23 +0200 | [diff] [blame] | 240 | bool pi_capable; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 241 | int refcount; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 242 | struct ib_device *ib_device; |
Sagi Grimberg | 67cb394 | 2015-03-29 15:52:05 +0300 | [diff] [blame] | 243 | struct ib_pd *pd; |
Sagi Grimberg | 4a295ba | 2014-12-02 16:57:40 +0200 | [diff] [blame] | 244 | struct isert_comp *comps; |
| 245 | int comps_used; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 246 | struct list_head dev_node; |
Christoph Hellwig | d1ca2ed | 2016-02-24 19:24:07 +0200 | [diff] [blame] | 247 | int (*reg_rdma_mem)(struct isert_cmd *isert_cmd, |
| 248 | struct iscsi_conn *conn); |
Vu Pham | d40945d | 2013-08-28 23:23:34 +0300 | [diff] [blame] | 249 | void (*unreg_rdma_mem)(struct isert_cmd *isert_cmd, |
| 250 | struct isert_conn *isert_conn); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 251 | }; |
| 252 | |
| 253 | struct isert_np { |
Sagi Grimberg | ca6c1d8 | 2014-12-02 16:57:27 +0200 | [diff] [blame] | 254 | struct iscsi_np *np; |
Jenny Derzhavetz | ed8cb0a | 2015-09-06 14:52:23 +0300 | [diff] [blame] | 255 | struct semaphore sem; |
| 256 | struct rdma_cm_id *cm_id; |
| 257 | struct mutex mutex; |
Jenny Derzhavetz | bd37922 | 2015-09-06 14:52:24 +0300 | [diff] [blame] | 258 | struct list_head accepted; |
| 259 | struct list_head pending; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 260 | }; |