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 | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 9 | |
| 10 | enum isert_desc_type { |
| 11 | ISCSI_TX_CONTROL, |
| 12 | ISCSI_TX_DATAIN |
| 13 | }; |
| 14 | |
| 15 | enum iser_ib_op_code { |
| 16 | ISER_IB_RECV, |
| 17 | ISER_IB_SEND, |
| 18 | ISER_IB_RDMA_WRITE, |
| 19 | ISER_IB_RDMA_READ, |
| 20 | }; |
| 21 | |
| 22 | enum iser_conn_state { |
| 23 | ISER_CONN_INIT, |
| 24 | ISER_CONN_UP, |
| 25 | ISER_CONN_TERMINATING, |
| 26 | ISER_CONN_DOWN, |
| 27 | }; |
| 28 | |
| 29 | struct iser_rx_desc { |
| 30 | struct iser_hdr iser_header; |
| 31 | struct iscsi_hdr iscsi_header; |
| 32 | char data[ISER_RECV_DATA_SEG_LEN]; |
| 33 | u64 dma_addr; |
| 34 | struct ib_sge rx_sg; |
| 35 | char pad[ISER_RX_PAD_SIZE]; |
| 36 | } __packed; |
| 37 | |
| 38 | struct iser_tx_desc { |
| 39 | struct iser_hdr iser_header; |
| 40 | struct iscsi_hdr iscsi_header; |
| 41 | enum isert_desc_type type; |
| 42 | u64 dma_addr; |
| 43 | struct ib_sge tx_sg[2]; |
| 44 | int num_sge; |
| 45 | struct isert_cmd *isert_cmd; |
| 46 | struct ib_send_wr send_wr; |
| 47 | } __packed; |
| 48 | |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame^] | 49 | struct fast_reg_descriptor { |
| 50 | struct list_head list; |
| 51 | struct ib_mr *data_mr; |
| 52 | struct ib_fast_reg_page_list *data_frpl; |
| 53 | bool valid; |
| 54 | }; |
| 55 | |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 56 | struct isert_rdma_wr { |
| 57 | struct list_head wr_list; |
| 58 | struct isert_cmd *isert_cmd; |
| 59 | enum iser_ib_op_code iser_ib_op; |
| 60 | struct ib_sge *ib_sge; |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame^] | 61 | struct ib_sge s_ib_sge; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 62 | int num_sge; |
| 63 | struct scatterlist *sge; |
| 64 | int send_wr_num; |
| 65 | struct ib_send_wr *send_wr; |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame^] | 66 | struct ib_send_wr s_send_wr; |
Vu Pham | 90ecc6e | 2013-08-28 23:23:33 +0300 | [diff] [blame] | 67 | u32 cur_rdma_length; |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame^] | 68 | struct fast_reg_descriptor *fr_desc; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | struct isert_cmd { |
| 72 | uint32_t read_stag; |
| 73 | uint32_t write_stag; |
| 74 | uint64_t read_va; |
| 75 | uint64_t write_va; |
Nicholas Bellinger | dbbc5d1 | 2013-07-03 19:39:37 -0700 | [diff] [blame] | 76 | u64 pdu_buf_dma; |
| 77 | u32 pdu_buf_len; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 78 | u32 read_va_off; |
| 79 | u32 write_va_off; |
| 80 | u32 rdma_wr_num; |
| 81 | struct isert_conn *conn; |
Nicholas Bellinger | d703ce2 | 2013-08-17 14:27:56 -0700 | [diff] [blame] | 82 | struct iscsi_cmd *iscsi_cmd; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 83 | struct iser_tx_desc tx_desc; |
| 84 | struct isert_rdma_wr rdma_wr; |
| 85 | struct work_struct comp_work; |
| 86 | }; |
| 87 | |
| 88 | struct isert_device; |
| 89 | |
| 90 | struct isert_conn { |
| 91 | enum iser_conn_state state; |
| 92 | bool logout_posted; |
| 93 | int post_recv_buf_count; |
| 94 | atomic_t post_send_buf_count; |
| 95 | u32 responder_resources; |
| 96 | u32 initiator_depth; |
| 97 | u32 max_sge; |
| 98 | char *login_buf; |
| 99 | char *login_req_buf; |
| 100 | char *login_rsp_buf; |
| 101 | u64 login_req_dma; |
| 102 | u64 login_rsp_dma; |
| 103 | unsigned int conn_rx_desc_head; |
| 104 | struct iser_rx_desc *conn_rx_descs; |
| 105 | struct ib_recv_wr conn_rx_wr[ISERT_MIN_POSTED_RX]; |
| 106 | struct iscsi_conn *conn; |
| 107 | struct list_head conn_accept_node; |
| 108 | struct completion conn_login_comp; |
| 109 | struct iser_tx_desc conn_login_tx_desc; |
| 110 | struct rdma_cm_id *conn_cm_id; |
| 111 | struct ib_pd *conn_pd; |
| 112 | struct ib_mr *conn_mr; |
| 113 | struct ib_qp *conn_qp; |
| 114 | struct isert_device *conn_device; |
| 115 | struct work_struct conn_logout_work; |
Nicholas Bellinger | b2cb964 | 2013-07-03 03:05:37 -0700 | [diff] [blame] | 116 | struct mutex conn_mutex; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 117 | wait_queue_head_t conn_wait; |
| 118 | wait_queue_head_t conn_wait_comp_err; |
| 119 | struct kref conn_kref; |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame^] | 120 | struct list_head conn_frwr_pool; |
| 121 | int conn_frwr_pool_size; |
| 122 | /* lock to protect frwr_pool */ |
| 123 | spinlock_t conn_lock; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 124 | }; |
| 125 | |
| 126 | #define ISERT_MAX_CQ 64 |
| 127 | |
| 128 | struct isert_cq_desc { |
| 129 | struct isert_device *device; |
| 130 | int cq_index; |
| 131 | struct work_struct cq_rx_work; |
| 132 | struct work_struct cq_tx_work; |
| 133 | }; |
| 134 | |
| 135 | struct isert_device { |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame^] | 136 | int use_frwr; |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 137 | int cqs_used; |
| 138 | int refcount; |
| 139 | int cq_active_qps[ISERT_MAX_CQ]; |
| 140 | struct ib_device *ib_device; |
| 141 | struct ib_pd *dev_pd; |
| 142 | struct ib_mr *dev_mr; |
| 143 | struct ib_cq *dev_rx_cq[ISERT_MAX_CQ]; |
| 144 | struct ib_cq *dev_tx_cq[ISERT_MAX_CQ]; |
| 145 | struct isert_cq_desc *cq_desc; |
| 146 | struct list_head dev_node; |
Vu Pham | 59464ef | 2013-08-28 23:23:35 +0300 | [diff] [blame^] | 147 | struct ib_device_attr dev_attr; |
Vu Pham | d40945d | 2013-08-28 23:23:34 +0300 | [diff] [blame] | 148 | int (*reg_rdma_mem)(struct iscsi_conn *conn, |
| 149 | struct iscsi_cmd *cmd, |
| 150 | struct isert_rdma_wr *wr); |
| 151 | void (*unreg_rdma_mem)(struct isert_cmd *isert_cmd, |
| 152 | struct isert_conn *isert_conn); |
Nicholas Bellinger | b8d26b3 | 2013-03-07 00:56:19 -0800 | [diff] [blame] | 153 | }; |
| 154 | |
| 155 | struct isert_np { |
| 156 | wait_queue_head_t np_accept_wq; |
| 157 | struct rdma_cm_id *np_cm_id; |
| 158 | struct mutex np_accept_mutex; |
| 159 | struct list_head np_accept_list; |
| 160 | struct completion np_login_comp; |
| 161 | }; |