hc
2024-05-14 bedbef8ad3e75a304af6361af235302bcc61d06b
kernel/drivers/infiniband/ulp/srpt/ib_srpt.h
....@@ -104,16 +104,7 @@
104104 SRP_CMD_ORDERED_Q = 0x2,
105105 SRP_CMD_ACA = 0x4,
106106
107
- SRP_LOGIN_RSP_MULTICHAN_NO_CHAN = 0x0,
108
- SRP_LOGIN_RSP_MULTICHAN_TERMINATED = 0x1,
109
- SRP_LOGIN_RSP_MULTICHAN_MAINTAINED = 0x2,
110
-
111107 SRPT_DEF_SG_TABLESIZE = 128,
112
- /*
113
- * An experimentally determined value that avoids that QP creation
114
- * fails due to "swiotlb buffer is full" on systems using the swiotlb.
115
- */
116
- SRPT_MAX_SG_PER_WQE = 16,
117108
118109 MIN_SRPT_SQ_SIZE = 16,
119110 DEF_SRPT_SQ_SIZE = 4096,
....@@ -124,11 +115,18 @@
124115 MAX_SRPT_RDMA_SIZE = 1U << 24,
125116 MAX_SRPT_RSP_SIZE = 1024,
126117
118
+ SRP_MAX_ADD_CDB_LEN = 16,
119
+ SRP_MAX_IMM_DATA_OFFSET = 80,
120
+ SRP_MAX_IMM_DATA = 8 * 1024,
127121 MIN_MAX_REQ_SIZE = 996,
128
- DEFAULT_MAX_REQ_SIZE
129
- = sizeof(struct srp_cmd)/*48*/
130
- + sizeof(struct srp_indirect_buf)/*20*/
131
- + 128 * sizeof(struct srp_direct_buf)/*16*/,
122
+ DEFAULT_MAX_REQ_SIZE_1 = sizeof(struct srp_cmd)/*48*/ +
123
+ SRP_MAX_ADD_CDB_LEN +
124
+ sizeof(struct srp_indirect_buf)/*20*/ +
125
+ 128 * sizeof(struct srp_direct_buf)/*16*/,
126
+ DEFAULT_MAX_REQ_SIZE_2 = SRP_MAX_IMM_DATA_OFFSET +
127
+ sizeof(struct srp_imm_buf) + SRP_MAX_IMM_DATA,
128
+ DEFAULT_MAX_REQ_SIZE = DEFAULT_MAX_REQ_SIZE_1 > DEFAULT_MAX_REQ_SIZE_2 ?
129
+ DEFAULT_MAX_REQ_SIZE_1 : DEFAULT_MAX_REQ_SIZE_2,
132130
133131 MIN_MAX_RSP_SIZE = sizeof(struct srp_rsp)/*36*/ + 4,
134132 DEFAULT_MAX_RSP_SIZE = 256, /* leaves 220 bytes for sense data */
....@@ -165,12 +163,14 @@
165163 * @cqe: Completion queue element.
166164 * @buf: Pointer to the buffer.
167165 * @dma: DMA address of the buffer.
166
+ * @offset: Offset of the first byte in @buf and @dma that is actually used.
168167 * @index: Index of the I/O context in its ioctx_ring array.
169168 */
170169 struct srpt_ioctx {
171170 struct ib_cqe cqe;
172171 void *buf;
173172 dma_addr_t dma;
173
+ uint32_t offset;
174174 uint32_t index;
175175 };
176176
....@@ -178,12 +178,14 @@
178178 * struct srpt_recv_ioctx - SRPT receive I/O context
179179 * @ioctx: See above.
180180 * @wait_list: Node for insertion in srpt_rdma_ch.cmd_wait_list.
181
+ * @byte_len: Number of bytes in @ioctx.buf.
181182 */
182183 struct srpt_recv_ioctx {
183184 struct srpt_ioctx ioctx;
184185 struct list_head wait_list;
186
+ int byte_len;
185187 };
186
-
188
+
187189 struct srpt_rw_ctx {
188190 struct rdma_rw_ctx rw;
189191 struct scatterlist *sg;
....@@ -194,10 +196,12 @@
194196 * struct srpt_send_ioctx - SRPT send I/O context
195197 * @ioctx: See above.
196198 * @ch: Channel pointer.
199
+ * @recv_ioctx: Receive I/O context associated with this send I/O context.
200
+ * Only used for processing immediate data.
197201 * @s_rw_ctx: @rw_ctxs points here if only a single rw_ctx is needed.
198202 * @rw_ctxs: RDMA read/write contexts.
203
+ * @imm_sg: Scatterlist for immediate data.
199204 * @rdma_cqe: RDMA completion queue element.
200
- * @free_list: Node in srpt_rdma_ch.free_list.
201205 * @state: I/O context state.
202206 * @cmd: Target core command data structure.
203207 * @sense_data: SCSI sense data.
....@@ -209,12 +213,14 @@
209213 struct srpt_send_ioctx {
210214 struct srpt_ioctx ioctx;
211215 struct srpt_rdma_ch *ch;
216
+ struct srpt_recv_ioctx *recv_ioctx;
212217
213218 struct srpt_rw_ctx s_rw_ctx;
214219 struct srpt_rw_ctx *rw_ctxs;
215220
221
+ struct scatterlist imm_sg;
222
+
216223 struct ib_cqe rdma_cqe;
217
- struct list_head free_list;
218224 enum srpt_command_state state;
219225 struct se_cmd cmd;
220226 u8 n_rdma;
....@@ -245,11 +251,17 @@
245251 * struct srpt_rdma_ch - RDMA channel
246252 * @nexus: I_T nexus this channel is associated with.
247253 * @qp: IB queue pair used for communicating over this channel.
248
- * @cm_id: IB CM ID associated with the channel.
254
+ * @ib_cm: See below.
255
+ * @ib_cm.cm_id: IB CM ID associated with the channel.
256
+ * @rdma_cm: See below.
257
+ * @rdma_cm.cm_id: RDMA CM ID associated with the channel.
249258 * @cq: IB completion queue for this channel.
259
+ * @cq_size: Number of CQEs in @cq.
250260 * @zw_cqe: Zero-length write CQE.
251261 * @rcu: RCU head.
252262 * @kref: kref for this channel.
263
+ * @closed: Completion object that will be signaled as soon as a new
264
+ * channel object with the same identity can be created.
253265 * @rq_size: IB receive queue size.
254266 * @max_rsp_size: Maximum size of an RSP response message in bytes.
255267 * @sq_wr_avail: number of work requests available in the send queue.
....@@ -259,12 +271,14 @@
259271 * @req_lim: request limit: maximum number of requests that may be sent
260272 * by the initiator without having received a response.
261273 * @req_lim_delta: Number of credits not yet sent back to the initiator.
274
+ * @imm_data_offset: Offset from start of SRP_CMD for immediate data.
262275 * @spinlock: Protects free_list and state.
263
- * @free_list: Head of list with free send I/O contexts.
264276 * @state: channel state. See also enum rdma_ch_state.
265277 * @using_rdma_cm: Whether the RDMA/CM or IB/CM is used for this channel.
266278 * @processing_wait_list: Whether or not cmd_wait_list is being processed.
279
+ * @rsp_buf_cache: kmem_cache for @ioctx_ring.
267280 * @ioctx_ring: Send ring.
281
+ * @req_buf_cache: kmem_cache for @ioctx_recv_ring.
268282 * @ioctx_recv_ring: Receive I/O context ring.
269283 * @list: Node in srpt_nexus.ch_list.
270284 * @cmd_wait_list: List of SCSI commands that arrived before the RTU event. This
....@@ -287,9 +301,11 @@
287301 } rdma_cm;
288302 };
289303 struct ib_cq *cq;
304
+ u32 cq_size;
290305 struct ib_cqe zw_cqe;
291306 struct rcu_head rcu;
292307 struct kref kref;
308
+ struct completion *closed;
293309 int rq_size;
294310 u32 max_rsp_size;
295311 atomic_t sq_wr_avail;
....@@ -297,10 +313,12 @@
297313 int max_ti_iu_len;
298314 atomic_t req_lim;
299315 atomic_t req_lim_delta;
316
+ u16 imm_data_offset;
300317 spinlock_t spinlock;
301
- struct list_head free_list;
302318 enum rdma_ch_state state;
319
+ struct kmem_cache *rsp_buf_cache;
303320 struct srpt_send_ioctx **ioctx_ring;
321
+ struct kmem_cache *req_buf_cache;
304322 struct srpt_recv_ioctx **ioctx_recv_ring;
305323 struct list_head list;
306324 struct list_head cmd_wait_list;
....@@ -343,24 +361,54 @@
343361 };
344362
345363 /**
346
- * struct srpt_port - information associated by SRPT with a single IB port
364
+ * struct srpt_tpg - information about a single "target portal group"
365
+ * @entry: Entry in @sport_id->tpg_list.
366
+ * @sport_id: Port name this TPG is associated with.
367
+ * @tpg: LIO TPG data structure.
368
+ *
369
+ * Zero or more target portal groups are associated with each port name
370
+ * (srpt_port_id). With each TPG an ACL list is associated.
371
+ */
372
+struct srpt_tpg {
373
+ struct list_head entry;
374
+ struct srpt_port_id *sport_id;
375
+ struct se_portal_group tpg;
376
+};
377
+
378
+/**
379
+ * struct srpt_port_id - LIO RDMA port information
380
+ * @mutex: Protects @tpg_list changes.
381
+ * @tpg_list: TPGs associated with the RDMA port name.
382
+ * @wwn: WWN associated with the RDMA port name.
383
+ * @name: ASCII representation of the port name.
384
+ *
385
+ * Multiple sysfs directories can be associated with a single RDMA port. This
386
+ * data structure represents a single (port, name) pair.
387
+ */
388
+struct srpt_port_id {
389
+ struct mutex mutex;
390
+ struct list_head tpg_list;
391
+ struct se_wwn wwn;
392
+ char name[64];
393
+};
394
+
395
+/**
396
+ * struct srpt_port - SRPT RDMA port information
347397 * @sdev: backpointer to the HCA information.
348398 * @mad_agent: per-port management datagram processing information.
349399 * @enabled: Whether or not this target port is enabled.
350
- * @port_guid: ASCII representation of Port GUID
351
- * @port_gid: ASCII representation of Port GID
352400 * @port: one-based port number.
353401 * @sm_lid: cached value of the port's sm_lid.
354402 * @lid: cached value of the port's lid.
355403 * @gid: cached value of the port's gid.
356
- * @port_acl_lock spinlock for port_acl_list:
357404 * @work: work structure for refreshing the aforementioned cached values.
358
- * @port_guid_tpg: TPG associated with target port GUID.
359
- * @port_guid_wwn: WWN associated with target port GUID.
360
- * @port_gid_tpg: TPG associated with target port GID.
361
- * @port_gid_wwn: WWN associated with target port GID.
405
+ * @guid_name: port name in GUID format.
406
+ * @guid_id: LIO target port information for the port name in GUID format.
407
+ * @gid_name: port name in GID format.
408
+ * @gid_id: LIO target port information for the port name in GID format.
362409 * @port_attrib: Port attributes that can be accessed through configfs.
363
- * @ch_releaseQ: Enables waiting for removal from nexus_list.
410
+ * @refcount: Number of objects associated with this port.
411
+ * @freed_channels: Completion that will be signaled once @refcount becomes 0.
364412 * @mutex: Protects nexus_list.
365413 * @nexus_list: Nexus list. See also srpt_nexus.entry.
366414 */
....@@ -368,25 +416,25 @@
368416 struct srpt_device *sdev;
369417 struct ib_mad_agent *mad_agent;
370418 bool enabled;
371
- u8 port_guid[24];
372
- u8 port_gid[64];
373419 u8 port;
374420 u32 sm_lid;
375421 u32 lid;
376422 union ib_gid gid;
377423 struct work_struct work;
378
- struct se_portal_group port_guid_tpg;
379
- struct se_wwn port_guid_wwn;
380
- struct se_portal_group port_gid_tpg;
381
- struct se_wwn port_gid_wwn;
424
+ char guid_name[64];
425
+ struct srpt_port_id *guid_id;
426
+ char gid_name[64];
427
+ struct srpt_port_id *gid_id;
382428 struct srpt_port_attrib port_attrib;
383
- wait_queue_head_t ch_releaseQ;
429
+ atomic_t refcount;
430
+ struct completion *freed_channels;
384431 struct mutex mutex;
385432 struct list_head nexus_list;
386433 };
387434
388435 /**
389436 * struct srpt_device - information associated by SRPT with a single HCA
437
+ * @refcnt: Reference count for this device.
390438 * @device: Backpointer to the struct ib_device managed by the IB core.
391439 * @pd: IB protection domain.
392440 * @lkey: L_Key (local key) with write access to all local memory.
....@@ -395,12 +443,14 @@
395443 * @srq_size: SRQ size.
396444 * @sdev_mutex: Serializes use_srq changes.
397445 * @use_srq: Whether or not to use SRQ.
446
+ * @req_buf_cache: kmem_cache for @ioctx_ring buffers.
398447 * @ioctx_ring: Per-HCA SRQ.
399448 * @event_handler: Per-HCA asynchronous IB event handler.
400449 * @list: Node in srpt_dev_list.
401450 * @port: Information about the ports owned by this HCA.
402451 */
403452 struct srpt_device {
453
+ struct kref refcnt;
404454 struct ib_device *device;
405455 struct ib_pd *pd;
406456 u32 lkey;
....@@ -409,6 +459,7 @@
409459 int srq_size;
410460 struct mutex sdev_mutex;
411461 bool use_srq;
462
+ struct kmem_cache *req_buf_cache;
412463 struct srpt_recv_ioctx **ioctx_ring;
413464 struct ib_event_handler event_handler;
414465 struct list_head list;