blob: fc791efe3a108178f1949f386548ed84ae81ebc8 [file] [log] [blame]
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08001#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>
Christoph Hellwig38a2d0d42016-05-03 18:01:13 +02006#include <rdma/rw.h>
Sagi Grimbergd3cf81f2015-12-09 14:12:03 +02007#include <scsi/iser.h>
8
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -08009
Sagi Grimberg24f412d2014-12-07 13:12:02 +020010#define DRV_NAME "isert"
11#define PFX DRV_NAME ": "
12
13#define isert_dbg(fmt, arg...) \
14 do { \
15 if (unlikely(isert_debug_level > 2)) \
16 printk(KERN_DEBUG PFX "%s: " fmt,\
17 __func__ , ## arg); \
18 } while (0)
19
20#define isert_warn(fmt, arg...) \
21 do { \
22 if (unlikely(isert_debug_level > 0)) \
23 pr_warn(PFX "%s: " fmt, \
24 __func__ , ## arg); \
25 } while (0)
26
27#define isert_info(fmt, arg...) \
28 do { \
29 if (unlikely(isert_debug_level > 1)) \
30 pr_info(PFX "%s: " fmt, \
31 __func__ , ## arg); \
32 } while (0)
33
34#define isert_err(fmt, arg...) \
35 pr_err(PFX "%s: " fmt, __func__ , ## arg)
36
Sagi Grimbergc6494152015-12-09 14:12:04 +020037/* Constant PDU lengths calculations */
38#define ISER_HEADERS_LEN (sizeof(struct iser_ctrl) + \
39 sizeof(struct iscsi_hdr))
Christoph Hellwiged1083b2016-02-24 19:24:04 +020040#define ISER_RX_PAYLOAD_SIZE (ISER_HEADERS_LEN + ISCSI_DEF_MAX_RECV_SEG_LEN)
Sagi Grimbergc6494152015-12-09 14:12:04 +020041
42/* QP settings */
43/* Maximal bounds on received asynchronous PDUs */
44#define ISERT_MAX_TX_MISC_PDUS 4 /* NOOP_IN(2) , ASYNC_EVENT(2) */
45
46#define ISERT_MAX_RX_MISC_PDUS 6 /*
47 * NOOP_OUT(2), TEXT(1),
48 * SCSI_TMFUNC(2), LOGOUT(1)
49 */
50
51#define ISCSI_DEF_XMIT_CMDS_MAX 128 /* from libiscsi.h, must be power of 2 */
52
53#define ISERT_QP_MAX_RECV_DTOS (ISCSI_DEF_XMIT_CMDS_MAX)
54
55#define ISERT_MIN_POSTED_RX (ISCSI_DEF_XMIT_CMDS_MAX >> 2)
56
Christoph Hellwig38a2d0d42016-05-03 18:01:13 +020057#define ISERT_QP_MAX_REQ_DTOS (ISCSI_DEF_XMIT_CMDS_MAX + \
Sagi Grimbergc6494152015-12-09 14:12:04 +020058 ISERT_MAX_TX_MISC_PDUS + \
59 ISERT_MAX_RX_MISC_PDUS)
60
Christoph Hellwiged1083b2016-02-24 19:24:04 +020061#define ISER_RX_PAD_SIZE (ISCSI_DEF_MAX_RECV_SEG_LEN + 4096 - \
Christoph Hellwig9679cc52016-02-24 19:24:06 +020062 (ISER_RX_PAYLOAD_SIZE + sizeof(u64) + sizeof(struct ib_sge) + \
63 sizeof(struct ib_cqe)))
Sagi Grimbergc6494152015-12-09 14:12:04 +020064
Vu Pham59464ef2013-08-28 23:23:35 +030065#define ISCSI_ISER_SG_TABLESIZE 256
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -080066
67enum isert_desc_type {
68 ISCSI_TX_CONTROL,
69 ISCSI_TX_DATAIN
70};
71
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -080072enum iser_conn_state {
73 ISER_CONN_INIT,
74 ISER_CONN_UP,
Jenny Derzhavetzaea92982016-02-24 19:23:59 +020075 ISER_CONN_BOUND,
Sagi Grimberg128e9cc2014-12-02 16:57:20 +020076 ISER_CONN_FULL_FEATURE,
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -080077 ISER_CONN_TERMINATING,
78 ISER_CONN_DOWN,
79};
80
81struct iser_rx_desc {
Sagi Grimbergd3cf81f2015-12-09 14:12:03 +020082 struct iser_ctrl iser_header;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -080083 struct iscsi_hdr iscsi_header;
Christoph Hellwiged1083b2016-02-24 19:24:04 +020084 char data[ISCSI_DEF_MAX_RECV_SEG_LEN];
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -080085 u64 dma_addr;
86 struct ib_sge rx_sg;
Christoph Hellwig9679cc52016-02-24 19:24:06 +020087 struct ib_cqe rx_cqe;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -080088 char pad[ISER_RX_PAD_SIZE];
89} __packed;
90
Christoph Hellwig9679cc52016-02-24 19:24:06 +020091static inline struct iser_rx_desc *cqe_to_rx_desc(struct ib_cqe *cqe)
92{
93 return container_of(cqe, struct iser_rx_desc, rx_cqe);
94}
95
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -080096struct iser_tx_desc {
Sagi Grimbergd3cf81f2015-12-09 14:12:03 +020097 struct iser_ctrl iser_header;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -080098 struct iscsi_hdr iscsi_header;
99 enum isert_desc_type type;
100 u64 dma_addr;
101 struct ib_sge tx_sg[2];
Christoph Hellwig9679cc52016-02-24 19:24:06 +0200102 struct ib_cqe tx_cqe;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800103 int num_sge;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800104 struct ib_send_wr send_wr;
105} __packed;
106
Christoph Hellwig9679cc52016-02-24 19:24:06 +0200107static inline struct iser_tx_desc *cqe_to_tx_desc(struct ib_cqe *cqe)
108{
109 return container_of(cqe, struct iser_tx_desc, tx_cqe);
110}
111
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800112struct isert_cmd {
113 uint32_t read_stag;
114 uint32_t write_stag;
115 uint64_t read_va;
116 uint64_t write_va;
Jenny Derzhavetz422bd0a2015-12-09 14:12:06 +0200117 uint32_t inv_rkey;
Nicholas Bellingerdbbc5d12013-07-03 19:39:37 -0700118 u64 pdu_buf_dma;
119 u32 pdu_buf_len;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800120 struct isert_conn *conn;
Nicholas Bellingerd703ce22013-08-17 14:27:56 -0700121 struct iscsi_cmd *iscsi_cmd;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800122 struct iser_tx_desc tx_desc;
Jenny Derzhavetz4366b192015-09-06 14:52:25 +0300123 struct iser_rx_desc *rx_desc;
Christoph Hellwig38a2d0d42016-05-03 18:01:13 +0200124 struct rdma_rw_ctx rw;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800125 struct work_struct comp_work;
Jenny Derzhavetz9fd60082015-09-06 14:52:26 +0300126 struct scatterlist sg;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800127};
128
Christoph Hellwige3416ab2016-02-24 19:24:08 +0200129static inline struct isert_cmd *tx_desc_to_cmd(struct iser_tx_desc *desc)
130{
131 return container_of(desc, struct isert_cmd, tx_desc);
132}
133
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800134struct isert_device;
135
136struct isert_conn {
137 enum iser_conn_state state;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800138 u32 responder_resources;
139 u32 initiator_depth;
Sagi Grimberg23a548e2014-12-02 16:57:35 +0200140 bool pi_support;
Christoph Hellwig5adabdd2016-02-24 19:24:05 +0200141 struct iser_rx_desc *login_req_buf;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800142 char *login_rsp_buf;
143 u64 login_req_dma;
Sagi Grimberg2371e5d2014-12-02 16:57:21 +0200144 int login_req_len;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800145 u64 login_rsp_dma;
Sagi Grimbergdac6ab32015-03-29 15:52:19 +0300146 struct iser_rx_desc *rx_descs;
Jenny Derzhavetz4366b192015-09-06 14:52:25 +0300147 struct ib_recv_wr rx_wr[ISERT_QP_MAX_RECV_DTOS];
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800148 struct iscsi_conn *conn;
Jenny Derzhavetzbd379222015-09-06 14:52:24 +0300149 struct list_head node;
Sagi Grimbergdac6ab32015-03-29 15:52:19 +0300150 struct completion login_comp;
Sagi Grimberg2371e5d2014-12-02 16:57:21 +0200151 struct completion login_req_comp;
Sagi Grimbergdac6ab32015-03-29 15:52:19 +0300152 struct iser_tx_desc login_tx_desc;
153 struct rdma_cm_id *cm_id;
154 struct ib_qp *qp;
155 struct isert_device *device;
156 struct mutex mutex;
Sagi Grimbergdac6ab32015-03-29 15:52:19 +0300157 struct kref kref;
Sagi Grimbergb02efbf2014-12-02 16:57:29 +0200158 struct work_struct release_work;
Sagi Grimberg991bb762014-12-07 13:12:01 +0200159 bool logout_posted;
Jenny Derzhavetz422bd0a2015-12-09 14:12:06 +0200160 bool snd_w_inv;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800161};
162
163#define ISERT_MAX_CQ 64
164
Sagi Grimberg4a295ba2014-12-02 16:57:40 +0200165/**
166 * struct isert_comp - iSER completion context
167 *
168 * @device: pointer to device handle
Sagi Grimberg6f0fae32014-12-02 16:57:41 +0200169 * @cq: completion queue
Sagi Grimberg4a295ba2014-12-02 16:57:40 +0200170 * @active_qps: Number of active QPs attached
171 * to completion context
Sagi Grimberg4a295ba2014-12-02 16:57:40 +0200172 */
173struct isert_comp {
Sagi Grimberg6f0fae32014-12-02 16:57:41 +0200174 struct isert_device *device;
175 struct ib_cq *cq;
Sagi Grimberg4a295ba2014-12-02 16:57:40 +0200176 int active_qps;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800177};
178
179struct isert_device {
Sagi Grimbergd3e125d2014-02-19 17:50:23 +0200180 bool pi_capable;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800181 int refcount;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800182 struct ib_device *ib_device;
Sagi Grimberg67cb3942015-03-29 15:52:05 +0300183 struct ib_pd *pd;
Sagi Grimberg4a295ba2014-12-02 16:57:40 +0200184 struct isert_comp *comps;
185 int comps_used;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800186 struct list_head dev_node;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800187};
188
189struct isert_np {
Sagi Grimbergca6c1d82014-12-02 16:57:27 +0200190 struct iscsi_np *np;
Jenny Derzhavetzed8cb0a2015-09-06 14:52:23 +0300191 struct semaphore sem;
192 struct rdma_cm_id *cm_id;
193 struct mutex mutex;
Jenny Derzhavetzbd379222015-09-06 14:52:24 +0300194 struct list_head accepted;
195 struct list_head pending;
Nicholas Bellingerb8d26b32013-03-07 00:56:19 -0800196};