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