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