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> |
| 6 | |
| 7 | #define ISERT_RDMA_LISTEN_BACKLOG 10 |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 8 | #define ISCSI_ISER_SG_TABLESIZE 256 |
Nicholas Bellinger | 9bb4ca6 | 2014-02-27 07:02:48 -0800 | [diff] [blame] | 9 | #define ISER_FASTREG_LI_WRID 0xffffffffffffffffULL |
Sagi Grimberg | bdf20e7 | 2014-12-02 16:57:43 +0200 | [diff] [blame] | 10 | #define ISER_BEACON_WRID 0xfffffffffffffffeULL |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 11 | |
| 12 | enum isert_desc_type { |
| 13 | ISCSI_TX_CONTROL, |
| 14 | ISCSI_TX_DATAIN |
| 15 | }; |
| 16 | |
| 17 | enum iser_ib_op_code { |
| 18 | ISER_IB_RECV, |
| 19 | ISER_IB_SEND, |
| 20 | ISER_IB_RDMA_WRITE, |
| 21 | ISER_IB_RDMA_READ, |
| 22 | }; |
| 23 | |
| 24 | enum iser_conn_state { |
| 25 | ISER_CONN_INIT, |
| 26 | ISER_CONN_UP, |
Sagi Grimberg | 128e9cc | 2014-12-02 16:57:20 +0200 | [diff] [blame] | 27 | ISER_CONN_FULL_FEATURE, |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 28 | ISER_CONN_TERMINATING, |
| 29 | ISER_CONN_DOWN, |
| 30 | }; |
| 31 | |
| 32 | struct iser_rx_desc { |
| 33 | struct iser_hdr iser_header; |
| 34 | struct iscsi_hdr iscsi_header; |
| 35 | char data[ISER_RECV_DATA_SEG_LEN]; |
| 36 | u64 dma_addr; |
| 37 | struct ib_sge rx_sg; |
| 38 | char pad[ISER_RX_PAD_SIZE]; |
| 39 | } __packed; |
| 40 | |
| 41 | struct iser_tx_desc { |
| 42 | struct iser_hdr iser_header; |
| 43 | struct iscsi_hdr iscsi_header; |
| 44 | enum isert_desc_type type; |
| 45 | u64 dma_addr; |
| 46 | struct ib_sge tx_sg[2]; |
| 47 | int num_sge; |
| 48 | struct isert_cmd *isert_cmd; |
| 49 | struct ib_send_wr send_wr; |
| 50 | } __packed; |
| 51 | |
Sagi Grimberg | d3e125d | 2014-02-19 17:50:23 +0200 | [diff] [blame] | 52 | enum isert_indicator { |
| 53 | ISERT_PROTECTED = 1 << 0, |
| 54 | ISERT_DATA_KEY_VALID = 1 << 1, |
| 55 | ISERT_PROT_KEY_VALID = 1 << 2, |
| 56 | ISERT_SIG_KEY_VALID = 1 << 3, |
| 57 | }; |
| 58 | |
| 59 | struct pi_context { |
| 60 | struct ib_mr *prot_mr; |
| 61 | struct ib_fast_reg_page_list *prot_frpl; |
| 62 | struct ib_mr *sig_mr; |
| 63 | }; |
| 64 | |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 65 | struct fast_reg_descriptor { |
Sagi Grimberg | d3e125d | 2014-02-19 17:50:23 +0200 | [diff] [blame] | 66 | struct list_head list; |
| 67 | struct ib_mr *data_mr; |
| 68 | struct ib_fast_reg_page_list *data_frpl; |
| 69 | u8 ind; |
| 70 | struct pi_context *pi_ctx; |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 71 | }; |
| 72 | |
Sagi Grimberg | e3d7e4c | 2014-02-19 17:50:22 +0200 | [diff] [blame] | 73 | struct isert_data_buf { |
| 74 | struct scatterlist *sg; |
| 75 | int nents; |
| 76 | u32 sg_off; |
| 77 | u32 len; /* cur_rdma_length */ |
| 78 | u32 offset; |
| 79 | unsigned int dma_nents; |
| 80 | enum dma_data_direction dma_dir; |
| 81 | }; |
| 82 | |
Sagi Grimberg | 570db17 | 2014-12-02 16:57:31 +0200 | [diff] [blame] | 83 | enum { |
| 84 | DATA = 0, |
| 85 | PROT = 1, |
| 86 | SIG = 2, |
| 87 | }; |
| 88 | |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 89 | struct isert_rdma_wr { |
| 90 | struct list_head wr_list; |
| 91 | struct isert_cmd *isert_cmd; |
| 92 | enum iser_ib_op_code iser_ib_op; |
| 93 | struct ib_sge *ib_sge; |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 94 | struct ib_sge s_ib_sge; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 95 | int send_wr_num; |
| 96 | struct ib_send_wr *send_wr; |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 97 | struct ib_send_wr s_send_wr; |
Sagi Grimberg | 570db17 | 2014-12-02 16:57:31 +0200 | [diff] [blame] | 98 | struct ib_sge ib_sg[3]; |
Sagi Grimberg | e3d7e4c | 2014-02-19 17:50:22 +0200 | [diff] [blame] | 99 | struct isert_data_buf data; |
Sagi Grimberg | 9e961ae | 2014-02-19 17:50:25 +0200 | [diff] [blame] | 100 | struct isert_data_buf prot; |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 101 | struct fast_reg_descriptor *fr_desc; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 102 | }; |
| 103 | |
| 104 | struct isert_cmd { |
| 105 | uint32_t read_stag; |
| 106 | uint32_t write_stag; |
| 107 | uint64_t read_va; |
| 108 | uint64_t write_va; |
Nicholas Bellinger | dbbc5d1 | 2013-07-03 19:39:37 -0700 | [diff] [blame] | 109 | u64 pdu_buf_dma; |
| 110 | u32 pdu_buf_len; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 111 | u32 read_va_off; |
| 112 | u32 write_va_off; |
| 113 | u32 rdma_wr_num; |
| 114 | struct isert_conn *conn; |
Nicholas Bellinger | d703ce2 | 2013-08-17 14:27:56 -0700 | [diff] [blame] | 115 | struct iscsi_cmd *iscsi_cmd; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 116 | struct iser_tx_desc tx_desc; |
| 117 | struct isert_rdma_wr rdma_wr; |
| 118 | struct work_struct comp_work; |
| 119 | }; |
| 120 | |
| 121 | struct isert_device; |
| 122 | |
| 123 | struct isert_conn { |
| 124 | enum iser_conn_state state; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 125 | int post_recv_buf_count; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 126 | u32 responder_resources; |
| 127 | u32 initiator_depth; |
Sagi Grimberg | 23a548e | 2014-12-02 16:57:35 +0200 | [diff] [blame] | 128 | bool pi_support; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 129 | u32 max_sge; |
| 130 | char *login_buf; |
| 131 | char *login_req_buf; |
| 132 | char *login_rsp_buf; |
| 133 | u64 login_req_dma; |
Sagi Grimberg | 2371e5d | 2014-12-02 16:57:21 +0200 | [diff] [blame] | 134 | int login_req_len; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 135 | u64 login_rsp_dma; |
| 136 | unsigned int conn_rx_desc_head; |
| 137 | struct iser_rx_desc *conn_rx_descs; |
| 138 | struct ib_recv_wr conn_rx_wr[ISERT_MIN_POSTED_RX]; |
| 139 | struct iscsi_conn *conn; |
| 140 | struct list_head conn_accept_node; |
| 141 | struct completion conn_login_comp; |
Sagi Grimberg | 2371e5d | 2014-12-02 16:57:21 +0200 | [diff] [blame] | 142 | struct completion login_req_comp; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 143 | struct iser_tx_desc conn_login_tx_desc; |
| 144 | struct rdma_cm_id *conn_cm_id; |
| 145 | struct ib_pd *conn_pd; |
| 146 | struct ib_mr *conn_mr; |
| 147 | struct ib_qp *conn_qp; |
| 148 | struct isert_device *conn_device; |
Nicholas Bellinger | b2cb964 | 2013-07-03 03:05:37 -0700 | [diff] [blame] | 149 | struct mutex conn_mutex; |
Nicholas Bellinger | defd884 | 2014-02-03 12:54:39 -0800 | [diff] [blame] | 150 | struct completion conn_wait; |
| 151 | struct completion conn_wait_comp_err; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 152 | struct kref conn_kref; |
Sagi Grimberg | a3a5a82 | 2014-01-09 18:40:50 +0200 | [diff] [blame] | 153 | struct list_head conn_fr_pool; |
| 154 | int conn_fr_pool_size; |
| 155 | /* lock to protect fastreg pool */ |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 156 | spinlock_t conn_lock; |
Sagi Grimberg | b02efbf | 2014-12-02 16:57:29 +0200 | [diff] [blame] | 157 | struct work_struct release_work; |
Sagi Grimberg | bdf20e7 | 2014-12-02 16:57:43 +0200 | [diff] [blame] | 158 | struct ib_recv_wr beacon; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 159 | }; |
| 160 | |
| 161 | #define ISERT_MAX_CQ 64 |
| 162 | |
Sagi Grimberg | 4a295ba | 2014-12-02 16:57:40 +0200 | [diff] [blame] | 163 | /** |
| 164 | * struct isert_comp - iSER completion context |
| 165 | * |
| 166 | * @device: pointer to device handle |
Sagi Grimberg | 6f0fae3 | 2014-12-02 16:57:41 +0200 | [diff] [blame] | 167 | * @cq: completion queue |
Sagi Grimberg | 4a295ba | 2014-12-02 16:57:40 +0200 | [diff] [blame] | 168 | * @active_qps: Number of active QPs attached |
| 169 | * to completion context |
Sagi Grimberg | 6f0fae3 | 2014-12-02 16:57:41 +0200 | [diff] [blame] | 170 | * @work: completion work handle |
Sagi Grimberg | 4a295ba | 2014-12-02 16:57:40 +0200 | [diff] [blame] | 171 | */ |
| 172 | struct isert_comp { |
Sagi Grimberg | 6f0fae3 | 2014-12-02 16:57:41 +0200 | [diff] [blame] | 173 | struct isert_device *device; |
| 174 | struct ib_cq *cq; |
Sagi Grimberg | 4a295ba | 2014-12-02 16:57:40 +0200 | [diff] [blame] | 175 | int active_qps; |
Sagi Grimberg | 6f0fae3 | 2014-12-02 16:57:41 +0200 | [diff] [blame] | 176 | struct work_struct work; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 177 | }; |
| 178 | |
| 179 | struct isert_device { |
Sagi Grimberg | a3a5a82 | 2014-01-09 18:40:50 +0200 | [diff] [blame] | 180 | int use_fastreg; |
Sagi Grimberg | d3e125d | 2014-02-19 17:50:23 +0200 | [diff] [blame] | 181 | bool pi_capable; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 182 | int refcount; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 183 | struct ib_device *ib_device; |
Sagi Grimberg | 4a295ba | 2014-12-02 16:57:40 +0200 | [diff] [blame] | 184 | struct isert_comp *comps; |
| 185 | int comps_used; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 186 | struct list_head dev_node; |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame] | 187 | struct ib_device_attr dev_attr; |
Vu Pham | d40945d | 2013-08-28 23:23:34 +0300 | [diff] [blame] | 188 | int (*reg_rdma_mem)(struct iscsi_conn *conn, |
| 189 | struct iscsi_cmd *cmd, |
| 190 | struct isert_rdma_wr *wr); |
| 191 | void (*unreg_rdma_mem)(struct isert_cmd *isert_cmd, |
| 192 | struct isert_conn *isert_conn); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 193 | }; |
| 194 | |
| 195 | struct isert_np { |
Sagi Grimberg | ca6c1d8 | 2014-12-02 16:57:27 +0200 | [diff] [blame] | 196 | struct iscsi_np *np; |
Sagi Grimberg | 531b7bf | 2014-04-29 13:13:45 +0300 | [diff] [blame] | 197 | struct semaphore np_sem; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 198 | struct rdma_cm_id *np_cm_id; |
| 199 | struct mutex np_accept_mutex; |
| 200 | struct list_head np_accept_list; |
| 201 | struct completion np_login_comp; |
| 202 | }; |