![]() |
|
|||
0001 /* 0002 * Copyright (c) 2006 - 2009 Mellanox Technology Inc. All rights reserved. 0003 * Copyright (C) 2009 - 2010 Bart Van Assche <bvanassche@acm.org>. 0004 * 0005 * This software is available to you under a choice of one of two 0006 * licenses. You may choose to be licensed under the terms of the GNU 0007 * General Public License (GPL) Version 2, available from the file 0008 * COPYING in the main directory of this source tree, or the 0009 * OpenIB.org BSD license below: 0010 * 0011 * Redistribution and use in source and binary forms, with or 0012 * without modification, are permitted provided that the following 0013 * conditions are met: 0014 * 0015 * - Redistributions of source code must retain the above 0016 * copyright notice, this list of conditions and the following 0017 * disclaimer. 0018 * 0019 * - Redistributions in binary form must reproduce the above 0020 * copyright notice, this list of conditions and the following 0021 * disclaimer in the documentation and/or other materials 0022 * provided with the distribution. 0023 * 0024 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 0025 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 0026 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 0027 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 0028 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 0029 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 0030 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 0031 * SOFTWARE. 0032 * 0033 */ 0034 0035 #ifndef IB_SRPT_H 0036 #define IB_SRPT_H 0037 0038 #include <linux/types.h> 0039 #include <linux/list.h> 0040 #include <linux/wait.h> 0041 0042 #include <rdma/ib_verbs.h> 0043 #include <rdma/ib_sa.h> 0044 #include <rdma/ib_cm.h> 0045 #include <rdma/rdma_cm.h> 0046 #include <rdma/rw.h> 0047 0048 #include <scsi/srp.h> 0049 0050 #include "ib_dm_mad.h" 0051 0052 /* 0053 * The prefix the ServiceName field must start with in the device management 0054 * ServiceEntries attribute pair. See also the SRP specification. 0055 */ 0056 #define SRP_SERVICE_NAME_PREFIX "SRP.T10:" 0057 0058 struct srpt_nexus; 0059 0060 enum { 0061 /* 0062 * SRP IOControllerProfile attributes for SRP target ports that have 0063 * not been defined in <scsi/srp.h>. Source: section B.7, table B.7 0064 * in the SRP specification. 0065 */ 0066 SRP_PROTOCOL = 0x0108, 0067 SRP_PROTOCOL_VERSION = 0x0001, 0068 SRP_IO_SUBCLASS = 0x609e, 0069 SRP_SEND_TO_IOC = 0x01, 0070 SRP_SEND_FROM_IOC = 0x02, 0071 SRP_RDMA_READ_FROM_IOC = 0x08, 0072 SRP_RDMA_WRITE_FROM_IOC = 0x20, 0073 0074 /* 0075 * srp_login_cmd.req_flags bitmasks. See also table 9 in the SRP 0076 * specification. 0077 */ 0078 SRP_MTCH_ACTION = 0x03, /* MULTI-CHANNEL ACTION */ 0079 SRP_LOSOLNT = 0x10, /* logout solicited notification */ 0080 SRP_CRSOLNT = 0x20, /* credit request solicited notification */ 0081 SRP_AESOLNT = 0x40, /* asynchronous event solicited notification */ 0082 0083 /* 0084 * srp_cmd.sol_nt / srp_tsk_mgmt.sol_not bitmasks. See also tables 0085 * 18 and 20 in the SRP specification. 0086 */ 0087 SRP_SCSOLNT = 0x02, /* SCSOLNT = successful solicited notification */ 0088 SRP_UCSOLNT = 0x04, /* UCSOLNT = unsuccessful solicited notification */ 0089 0090 /* 0091 * srp_rsp.sol_not / srp_t_logout.sol_not bitmasks. See also tables 0092 * 16 and 22 in the SRP specification. 0093 */ 0094 SRP_SOLNT = 0x01, /* SOLNT = solicited notification */ 0095 0096 /* See also table 24 in the SRP specification. */ 0097 SRP_TSK_MGMT_SUCCESS = 0x00, 0098 SRP_TSK_MGMT_FUNC_NOT_SUPP = 0x04, 0099 SRP_TSK_MGMT_FAILED = 0x05, 0100 0101 /* See also table 21 in the SRP specification. */ 0102 SRP_CMD_SIMPLE_Q = 0x0, 0103 SRP_CMD_HEAD_OF_Q = 0x1, 0104 SRP_CMD_ORDERED_Q = 0x2, 0105 SRP_CMD_ACA = 0x4, 0106 0107 SRPT_DEF_SG_TABLESIZE = 128, 0108 0109 MIN_SRPT_SQ_SIZE = 16, 0110 DEF_SRPT_SQ_SIZE = 4096, 0111 MAX_SRPT_RQ_SIZE = 128, 0112 MIN_SRPT_SRQ_SIZE = 4, 0113 DEFAULT_SRPT_SRQ_SIZE = 4095, 0114 MAX_SRPT_SRQ_SIZE = 65535, 0115 MAX_SRPT_RDMA_SIZE = 1U << 24, 0116 MAX_SRPT_RSP_SIZE = 1024, 0117 0118 SRP_MAX_ADD_CDB_LEN = 16, 0119 SRP_MAX_IMM_DATA_OFFSET = 80, 0120 SRP_MAX_IMM_DATA = 8 * 1024, 0121 MIN_MAX_REQ_SIZE = 996, 0122 DEFAULT_MAX_REQ_SIZE_1 = sizeof(struct srp_cmd)/*48*/ + 0123 SRP_MAX_ADD_CDB_LEN + 0124 sizeof(struct srp_indirect_buf)/*20*/ + 0125 128 * sizeof(struct srp_direct_buf)/*16*/, 0126 DEFAULT_MAX_REQ_SIZE_2 = SRP_MAX_IMM_DATA_OFFSET + 0127 sizeof(struct srp_imm_buf) + SRP_MAX_IMM_DATA, 0128 DEFAULT_MAX_REQ_SIZE = DEFAULT_MAX_REQ_SIZE_1 > DEFAULT_MAX_REQ_SIZE_2 ? 0129 DEFAULT_MAX_REQ_SIZE_1 : DEFAULT_MAX_REQ_SIZE_2, 0130 0131 MIN_MAX_RSP_SIZE = sizeof(struct srp_rsp)/*36*/ + 4, 0132 DEFAULT_MAX_RSP_SIZE = 256, /* leaves 220 bytes for sense data */ 0133 0134 DEFAULT_MAX_RDMA_SIZE = 65536, 0135 }; 0136 0137 /** 0138 * enum srpt_command_state - SCSI command state managed by SRPT 0139 * @SRPT_STATE_NEW: New command arrived and is being processed. 0140 * @SRPT_STATE_NEED_DATA: Processing a write or bidir command and waiting 0141 * for data arrival. 0142 * @SRPT_STATE_DATA_IN: Data for the write or bidir command arrived and is 0143 * being processed. 0144 * @SRPT_STATE_CMD_RSP_SENT: SRP_RSP for SRP_CMD has been sent. 0145 * @SRPT_STATE_MGMT: Processing a SCSI task management command. 0146 * @SRPT_STATE_MGMT_RSP_SENT: SRP_RSP for SRP_TSK_MGMT has been sent. 0147 * @SRPT_STATE_DONE: Command processing finished successfully, command 0148 * processing has been aborted or command processing 0149 * failed. 0150 */ 0151 enum srpt_command_state { 0152 SRPT_STATE_NEW = 0, 0153 SRPT_STATE_NEED_DATA = 1, 0154 SRPT_STATE_DATA_IN = 2, 0155 SRPT_STATE_CMD_RSP_SENT = 3, 0156 SRPT_STATE_MGMT = 4, 0157 SRPT_STATE_MGMT_RSP_SENT = 5, 0158 SRPT_STATE_DONE = 6, 0159 }; 0160 0161 /** 0162 * struct srpt_ioctx - shared SRPT I/O context information 0163 * @cqe: Completion queue element. 0164 * @buf: Pointer to the buffer. 0165 * @dma: DMA address of the buffer. 0166 * @offset: Offset of the first byte in @buf and @dma that is actually used. 0167 * @index: Index of the I/O context in its ioctx_ring array. 0168 */ 0169 struct srpt_ioctx { 0170 struct ib_cqe cqe; 0171 void *buf; 0172 dma_addr_t dma; 0173 uint32_t offset; 0174 uint32_t index; 0175 }; 0176 0177 /** 0178 * struct srpt_recv_ioctx - SRPT receive I/O context 0179 * @ioctx: See above. 0180 * @wait_list: Node for insertion in srpt_rdma_ch.cmd_wait_list. 0181 * @byte_len: Number of bytes in @ioctx.buf. 0182 */ 0183 struct srpt_recv_ioctx { 0184 struct srpt_ioctx ioctx; 0185 struct list_head wait_list; 0186 int byte_len; 0187 }; 0188 0189 struct srpt_rw_ctx { 0190 struct rdma_rw_ctx rw; 0191 struct scatterlist *sg; 0192 unsigned int nents; 0193 }; 0194 0195 /** 0196 * struct srpt_send_ioctx - SRPT send I/O context 0197 * @ioctx: See above. 0198 * @ch: Channel pointer. 0199 * @recv_ioctx: Receive I/O context associated with this send I/O context. 0200 * Only used for processing immediate data. 0201 * @s_rw_ctx: @rw_ctxs points here if only a single rw_ctx is needed. 0202 * @rw_ctxs: RDMA read/write contexts. 0203 * @imm_sg: Scatterlist for immediate data. 0204 * @rdma_cqe: RDMA completion queue element. 0205 * @state: I/O context state. 0206 * @cmd: Target core command data structure. 0207 * @sense_data: SCSI sense data. 0208 * @n_rdma: Number of work requests needed to transfer this ioctx. 0209 * @n_rw_ctx: Size of rw_ctxs array. 0210 * @queue_status_only: Send a SCSI status back to the initiator but no data. 0211 * @sense_data: Sense data to be sent to the initiator. 0212 */ 0213 struct srpt_send_ioctx { 0214 struct srpt_ioctx ioctx; 0215 struct srpt_rdma_ch *ch; 0216 struct srpt_recv_ioctx *recv_ioctx; 0217 0218 struct srpt_rw_ctx s_rw_ctx; 0219 struct srpt_rw_ctx *rw_ctxs; 0220 0221 struct scatterlist imm_sg; 0222 0223 struct ib_cqe rdma_cqe; 0224 enum srpt_command_state state; 0225 struct se_cmd cmd; 0226 u8 n_rdma; 0227 u8 n_rw_ctx; 0228 bool queue_status_only; 0229 u8 sense_data[TRANSPORT_SENSE_BUFFER]; 0230 }; 0231 0232 /** 0233 * enum rdma_ch_state - SRP channel state 0234 * @CH_CONNECTING: QP is in RTR state; waiting for RTU. 0235 * @CH_LIVE: QP is in RTS state. 0236 * @CH_DISCONNECTING: DREQ has been sent and waiting for DREP or DREQ has 0237 * been received. 0238 * @CH_DRAINING: DREP has been received or waiting for DREP timed out 0239 * and last work request has been queued. 0240 * @CH_DISCONNECTED: Last completion has been received. 0241 */ 0242 enum rdma_ch_state { 0243 CH_CONNECTING, 0244 CH_LIVE, 0245 CH_DISCONNECTING, 0246 CH_DRAINING, 0247 CH_DISCONNECTED, 0248 }; 0249 0250 /** 0251 * struct srpt_rdma_ch - RDMA channel 0252 * @nexus: I_T nexus this channel is associated with. 0253 * @qp: IB queue pair used for communicating over this channel. 0254 * @ib_cm: See below. 0255 * @ib_cm.cm_id: IB CM ID associated with the channel. 0256 * @rdma_cm: See below. 0257 * @rdma_cm.cm_id: RDMA CM ID associated with the channel. 0258 * @cq: IB completion queue for this channel. 0259 * @cq_size: Number of CQEs in @cq. 0260 * @zw_cqe: Zero-length write CQE. 0261 * @rcu: RCU head. 0262 * @kref: kref for this channel. 0263 * @closed: Completion object that will be signaled as soon as a new 0264 * channel object with the same identity can be created. 0265 * @rq_size: IB receive queue size. 0266 * @max_rsp_size: Maximum size of an RSP response message in bytes. 0267 * @sq_wr_avail: number of work requests available in the send queue. 0268 * @sport: pointer to the information of the HCA port used by this 0269 * channel. 0270 * @max_ti_iu_len: maximum target-to-initiator information unit length. 0271 * @req_lim: request limit: maximum number of requests that may be sent 0272 * by the initiator without having received a response. 0273 * @req_lim_delta: Number of credits not yet sent back to the initiator. 0274 * @imm_data_offset: Offset from start of SRP_CMD for immediate data. 0275 * @spinlock: Protects free_list and state. 0276 * @state: channel state. See also enum rdma_ch_state. 0277 * @using_rdma_cm: Whether the RDMA/CM or IB/CM is used for this channel. 0278 * @processing_wait_list: Whether or not cmd_wait_list is being processed. 0279 * @rsp_buf_cache: kmem_cache for @ioctx_ring. 0280 * @ioctx_ring: Send ring. 0281 * @req_buf_cache: kmem_cache for @ioctx_recv_ring. 0282 * @ioctx_recv_ring: Receive I/O context ring. 0283 * @list: Node in srpt_nexus.ch_list. 0284 * @cmd_wait_list: List of SCSI commands that arrived before the RTU event. This 0285 * list contains struct srpt_ioctx elements and is protected 0286 * against concurrent modification by the cm_id spinlock. 0287 * @pkey: P_Key of the IB partition for this SRP channel. 0288 * @sess: Session information associated with this SRP channel. 0289 * @sess_name: Session name. 0290 * @release_work: Allows scheduling of srpt_release_channel(). 0291 */ 0292 struct srpt_rdma_ch { 0293 struct srpt_nexus *nexus; 0294 struct ib_qp *qp; 0295 union { 0296 struct { 0297 struct ib_cm_id *cm_id; 0298 } ib_cm; 0299 struct { 0300 struct rdma_cm_id *cm_id; 0301 } rdma_cm; 0302 }; 0303 struct ib_cq *cq; 0304 u32 cq_size; 0305 struct ib_cqe zw_cqe; 0306 struct rcu_head rcu; 0307 struct kref kref; 0308 struct completion *closed; 0309 int rq_size; 0310 u32 max_rsp_size; 0311 atomic_t sq_wr_avail; 0312 struct srpt_port *sport; 0313 int max_ti_iu_len; 0314 atomic_t req_lim; 0315 atomic_t req_lim_delta; 0316 u16 imm_data_offset; 0317 spinlock_t spinlock; 0318 enum rdma_ch_state state; 0319 struct kmem_cache *rsp_buf_cache; 0320 struct srpt_send_ioctx **ioctx_ring; 0321 struct kmem_cache *req_buf_cache; 0322 struct srpt_recv_ioctx **ioctx_recv_ring; 0323 struct list_head list; 0324 struct list_head cmd_wait_list; 0325 uint16_t pkey; 0326 bool using_rdma_cm; 0327 bool processing_wait_list; 0328 struct se_session *sess; 0329 u8 sess_name[40]; 0330 struct work_struct release_work; 0331 }; 0332 0333 /** 0334 * struct srpt_nexus - I_T nexus 0335 * @rcu: RCU head for this data structure. 0336 * @entry: srpt_port.nexus_list list node. 0337 * @ch_list: struct srpt_rdma_ch list. Protected by srpt_port.mutex. 0338 * @i_port_id: 128-bit initiator port identifier copied from SRP_LOGIN_REQ. 0339 * @t_port_id: 128-bit target port identifier copied from SRP_LOGIN_REQ. 0340 */ 0341 struct srpt_nexus { 0342 struct rcu_head rcu; 0343 struct list_head entry; 0344 struct list_head ch_list; 0345 u8 i_port_id[16]; 0346 u8 t_port_id[16]; 0347 }; 0348 0349 /** 0350 * struct srpt_port_attrib - attributes for SRPT port 0351 * @srp_max_rdma_size: Maximum size of SRP RDMA transfers for new connections. 0352 * @srp_max_rsp_size: Maximum size of SRP response messages in bytes. 0353 * @srp_sq_size: Shared receive queue (SRQ) size. 0354 * @use_srq: Whether or not to use SRQ. 0355 */ 0356 struct srpt_port_attrib { 0357 u32 srp_max_rdma_size; 0358 u32 srp_max_rsp_size; 0359 u32 srp_sq_size; 0360 bool use_srq; 0361 }; 0362 0363 /** 0364 * struct srpt_tpg - information about a single "target portal group" 0365 * @entry: Entry in @sport_id->tpg_list. 0366 * @sport_id: Port name this TPG is associated with. 0367 * @tpg: LIO TPG data structure. 0368 * 0369 * Zero or more target portal groups are associated with each port name 0370 * (srpt_port_id). With each TPG an ACL list is associated. 0371 */ 0372 struct srpt_tpg { 0373 struct list_head entry; 0374 struct srpt_port_id *sport_id; 0375 struct se_portal_group tpg; 0376 }; 0377 0378 /** 0379 * struct srpt_port_id - LIO RDMA port information 0380 * @mutex: Protects @tpg_list changes. 0381 * @tpg_list: TPGs associated with the RDMA port name. 0382 * @wwn: WWN associated with the RDMA port name. 0383 * @name: ASCII representation of the port name. 0384 * 0385 * Multiple sysfs directories can be associated with a single RDMA port. This 0386 * data structure represents a single (port, name) pair. 0387 */ 0388 struct srpt_port_id { 0389 struct mutex mutex; 0390 struct list_head tpg_list; 0391 struct se_wwn wwn; 0392 char name[64]; 0393 }; 0394 0395 /** 0396 * struct srpt_port - SRPT RDMA port information 0397 * @sdev: backpointer to the HCA information. 0398 * @mad_agent: per-port management datagram processing information. 0399 * @enabled: Whether or not this target port is enabled. 0400 * @port: one-based port number. 0401 * @sm_lid: cached value of the port's sm_lid. 0402 * @lid: cached value of the port's lid. 0403 * @gid: cached value of the port's gid. 0404 * @work: work structure for refreshing the aforementioned cached values. 0405 * @guid_name: port name in GUID format. 0406 * @guid_id: LIO target port information for the port name in GUID format. 0407 * @gid_name: port name in GID format. 0408 * @gid_id: LIO target port information for the port name in GID format. 0409 * @port_attrib: Port attributes that can be accessed through configfs. 0410 * @refcount: Number of objects associated with this port. 0411 * @freed_channels: Completion that will be signaled once @refcount becomes 0. 0412 * @mutex: Protects nexus_list. 0413 * @nexus_list: Nexus list. See also srpt_nexus.entry. 0414 */ 0415 struct srpt_port { 0416 struct srpt_device *sdev; 0417 struct ib_mad_agent *mad_agent; 0418 bool enabled; 0419 u8 port; 0420 u32 sm_lid; 0421 u32 lid; 0422 union ib_gid gid; 0423 struct work_struct work; 0424 char guid_name[64]; 0425 struct srpt_port_id *guid_id; 0426 char gid_name[64]; 0427 struct srpt_port_id *gid_id; 0428 struct srpt_port_attrib port_attrib; 0429 atomic_t refcount; 0430 struct completion *freed_channels; 0431 struct mutex mutex; 0432 struct list_head nexus_list; 0433 }; 0434 0435 /** 0436 * struct srpt_device - information associated by SRPT with a single HCA 0437 * @refcnt: Reference count for this device. 0438 * @device: Backpointer to the struct ib_device managed by the IB core. 0439 * @pd: IB protection domain. 0440 * @lkey: L_Key (local key) with write access to all local memory. 0441 * @srq: Per-HCA SRQ (shared receive queue). 0442 * @cm_id: Connection identifier. 0443 * @srq_size: SRQ size. 0444 * @sdev_mutex: Serializes use_srq changes. 0445 * @use_srq: Whether or not to use SRQ. 0446 * @req_buf_cache: kmem_cache for @ioctx_ring buffers. 0447 * @ioctx_ring: Per-HCA SRQ. 0448 * @event_handler: Per-HCA asynchronous IB event handler. 0449 * @list: Node in srpt_dev_list. 0450 * @port: Information about the ports owned by this HCA. 0451 */ 0452 struct srpt_device { 0453 struct kref refcnt; 0454 struct ib_device *device; 0455 struct ib_pd *pd; 0456 u32 lkey; 0457 struct ib_srq *srq; 0458 struct ib_cm_id *cm_id; 0459 int srq_size; 0460 struct mutex sdev_mutex; 0461 bool use_srq; 0462 struct kmem_cache *req_buf_cache; 0463 struct srpt_recv_ioctx **ioctx_ring; 0464 struct ib_event_handler event_handler; 0465 struct list_head list; 0466 struct srpt_port port[]; 0467 }; 0468 0469 #endif /* IB_SRPT_H */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |