OSDN Git Service

2a0721f1f5dfb5c577d885bb808055e42da04d0a
[android-x86/kernel.git] / drivers / infiniband / ulp / isert / ib_isert.h
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 #define ISCSI_ISER_SG_TABLESIZE         256
9 #define ISER_FASTREG_LI_WRID            0xffffffffffffffffULL
10 #define ISER_BEACON_WRID               0xfffffffffffffffeULL
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,
27         ISER_CONN_FULL_FEATURE,
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
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
65 struct fast_reg_descriptor {
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;
71 };
72
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
83 enum {
84         DATA = 0,
85         PROT = 1,
86         SIG = 2,
87 };
88
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;
94         struct ib_sge           s_ib_sge;
95         int                     send_wr_num;
96         struct ib_send_wr       *send_wr;
97         struct ib_send_wr       s_send_wr;
98         struct ib_sge           ib_sg[3];
99         struct isert_data_buf   data;
100         struct isert_data_buf   prot;
101         struct fast_reg_descriptor *fr_desc;
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;
109         u64                     pdu_buf_dma;
110         u32                     pdu_buf_len;
111         u32                     read_va_off;
112         u32                     write_va_off;
113         u32                     rdma_wr_num;
114         struct isert_conn       *conn;
115         struct iscsi_cmd        *iscsi_cmd;
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;
125         int                     post_recv_buf_count;
126         u32                     responder_resources;
127         u32                     initiator_depth;
128         bool                    pi_support;
129         u32                     max_sge;
130         char                    *login_buf;
131         char                    *login_req_buf;
132         char                    *login_rsp_buf;
133         u64                     login_req_dma;
134         int                     login_req_len;
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;
142         struct completion       login_req_comp;
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;
149         struct mutex            conn_mutex;
150         struct completion       conn_wait;
151         struct completion       conn_wait_comp_err;
152         struct kref             conn_kref;
153         struct list_head        conn_fr_pool;
154         int                     conn_fr_pool_size;
155         /* lock to protect fastreg pool */
156         spinlock_t              conn_lock;
157         struct work_struct      release_work;
158         struct ib_recv_wr       beacon;
159 };
160
161 #define ISERT_MAX_CQ 64
162
163 /**
164  * struct isert_comp - iSER completion context
165  *
166  * @device:     pointer to device handle
167  * @cq:         completion queue
168  * @wcs:        work completion array
169  * @active_qps: Number of active QPs attached
170  *              to completion context
171  * @work:       completion work handle
172  */
173 struct isert_comp {
174         struct isert_device     *device;
175         struct ib_cq            *cq;
176         struct ib_wc             wcs[16];
177         int                      active_qps;
178         struct work_struct       work;
179 };
180
181 struct isert_device {
182         int                     use_fastreg;
183         bool                    pi_capable;
184         int                     refcount;
185         struct ib_device        *ib_device;
186         struct isert_comp       *comps;
187         int                     comps_used;
188         struct list_head        dev_node;
189         struct ib_device_attr   dev_attr;
190         int                     (*reg_rdma_mem)(struct iscsi_conn *conn,
191                                                     struct iscsi_cmd *cmd,
192                                                     struct isert_rdma_wr *wr);
193         void                    (*unreg_rdma_mem)(struct isert_cmd *isert_cmd,
194                                                   struct isert_conn *isert_conn);
195 };
196
197 struct isert_np {
198         struct iscsi_np         *np;
199         struct semaphore        np_sem;
200         struct rdma_cm_id       *np_cm_id;
201         struct mutex            np_accept_mutex;
202         struct list_head        np_accept_list;
203         struct completion       np_login_comp;
204 };