linux/drivers/infiniband/ulp/srpt/ib_srpt.h

/*
 * Copyright (c) 2006 - 2009 Mellanox Technology Inc.  All rights reserved.
 * Copyright (C) 2009 - 2010 Bart Van Assche <[email protected]>.
 *
 * This software is available to you under a choice of one of two
 * licenses.  You may choose to be licensed under the terms of the GNU
 * General Public License (GPL) Version 2, available from the file
 * COPYING in the main directory of this source tree, or the
 * OpenIB.org BSD license below:
 *
 *     Redistribution and use in source and binary forms, with or
 *     without modification, are permitted provided that the following
 *     conditions are met:
 *
 *      - Redistributions of source code must retain the above
 *        copyright notice, this list of conditions and the following
 *        disclaimer.
 *
 *      - Redistributions in binary form must reproduce the above
 *        copyright notice, this list of conditions and the following
 *        disclaimer in the documentation and/or other materials
 *        provided with the distribution.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 *
 */

#ifndef IB_SRPT_H
#define IB_SRPT_H

#include <linux/types.h>
#include <linux/list.h>
#include <linux/wait.h>

#include <rdma/ib_verbs.h>
#include <rdma/ib_sa.h>
#include <rdma/ib_cm.h>
#include <rdma/rdma_cm.h>
#include <rdma/rw.h>

#include <scsi/srp.h>

#include "ib_dm_mad.h"

/*
 * The prefix the ServiceName field must start with in the device management
 * ServiceEntries attribute pair. See also the SRP specification.
 */
#define SRP_SERVICE_NAME_PREFIX

struct srpt_nexus;

enum {};

/**
 * enum srpt_command_state - SCSI command state managed by SRPT
 * @SRPT_STATE_NEW:           New command arrived and is being processed.
 * @SRPT_STATE_NEED_DATA:     Processing a write or bidir command and waiting
 *                            for data arrival.
 * @SRPT_STATE_DATA_IN:       Data for the write or bidir command arrived and is
 *                            being processed.
 * @SRPT_STATE_CMD_RSP_SENT:  SRP_RSP for SRP_CMD has been sent.
 * @SRPT_STATE_MGMT:          Processing a SCSI task management command.
 * @SRPT_STATE_MGMT_RSP_SENT: SRP_RSP for SRP_TSK_MGMT has been sent.
 * @SRPT_STATE_DONE:          Command processing finished successfully, command
 *                            processing has been aborted or command processing
 *                            failed.
 */
enum srpt_command_state {};

/**
 * struct srpt_ioctx - shared SRPT I/O context information
 * @cqe:   Completion queue element.
 * @buf:   Pointer to the buffer.
 * @dma:   DMA address of the buffer.
 * @offset: Offset of the first byte in @buf and @dma that is actually used.
 * @index: Index of the I/O context in its ioctx_ring array.
 */
struct srpt_ioctx {};

/**
 * struct srpt_recv_ioctx - SRPT receive I/O context
 * @ioctx:     See above.
 * @wait_list: Node for insertion in srpt_rdma_ch.cmd_wait_list.
 * @byte_len:  Number of bytes in @ioctx.buf.
 */
struct srpt_recv_ioctx {};

struct srpt_rw_ctx {};

/**
 * struct srpt_send_ioctx - SRPT send I/O context
 * @ioctx:       See above.
 * @ch:          Channel pointer.
 * @recv_ioctx:  Receive I/O context associated with this send I/O context.
 *		 Only used for processing immediate data.
 * @s_rw_ctx:    @rw_ctxs points here if only a single rw_ctx is needed.
 * @rw_ctxs:     RDMA read/write contexts.
 * @imm_sg:      Scatterlist for immediate data.
 * @rdma_cqe:    RDMA completion queue element.
 * @state:       I/O context state.
 * @cmd:         Target core command data structure.
 * @sense_data:  SCSI sense data.
 * @n_rdma:      Number of work requests needed to transfer this ioctx.
 * @n_rw_ctx:    Size of rw_ctxs array.
 * @queue_status_only: Send a SCSI status back to the initiator but no data.
 * @sense_data:  Sense data to be sent to the initiator.
 */
struct srpt_send_ioctx {};

/**
 * enum rdma_ch_state - SRP channel state
 * @CH_CONNECTING:    QP is in RTR state; waiting for RTU.
 * @CH_LIVE:	      QP is in RTS state.
 * @CH_DISCONNECTING: DREQ has been sent and waiting for DREP or DREQ has
 *                    been received.
 * @CH_DRAINING:      DREP has been received or waiting for DREP timed out
 *                    and last work request has been queued.
 * @CH_DISCONNECTED:  Last completion has been received.
 */
enum rdma_ch_state {};

/**
 * struct srpt_rdma_ch - RDMA channel
 * @nexus:         I_T nexus this channel is associated with.
 * @qp:            IB queue pair used for communicating over this channel.
 * @ib_cm:	   See below.
 * @ib_cm.cm_id:   IB CM ID associated with the channel.
 * @rdma_cm:	   See below.
 * @rdma_cm.cm_id: RDMA CM ID associated with the channel.
 * @cq:            IB completion queue for this channel.
 * @cq_size:	   Number of CQEs in @cq.
 * @zw_cqe:	   Zero-length write CQE.
 * @rcu:           RCU head.
 * @kref:	   kref for this channel.
 * @closed:	   Completion object that will be signaled as soon as a new
 *		   channel object with the same identity can be created.
 * @rq_size:       IB receive queue size.
 * @max_rsp_size:  Maximum size of an RSP response message in bytes.
 * @sq_wr_avail:   number of work requests available in the send queue.
 * @sport:         pointer to the information of the HCA port used by this
 *                 channel.
 * @max_ti_iu_len: maximum target-to-initiator information unit length.
 * @req_lim:       request limit: maximum number of requests that may be sent
 *                 by the initiator without having received a response.
 * @req_lim_delta: Number of credits not yet sent back to the initiator.
 * @imm_data_offset: Offset from start of SRP_CMD for immediate data.
 * @spinlock:      Protects free_list and state.
 * @state:         channel state. See also enum rdma_ch_state.
 * @using_rdma_cm: Whether the RDMA/CM or IB/CM is used for this channel.
 * @processing_wait_list: Whether or not cmd_wait_list is being processed.
 * @rsp_buf_cache: kmem_cache for @ioctx_ring.
 * @ioctx_ring:    Send ring.
 * @req_buf_cache: kmem_cache for @ioctx_recv_ring.
 * @ioctx_recv_ring: Receive I/O context ring.
 * @list:          Node in srpt_nexus.ch_list.
 * @cmd_wait_list: List of SCSI commands that arrived before the RTU event. This
 *                 list contains struct srpt_ioctx elements and is protected
 *                 against concurrent modification by the cm_id spinlock.
 * @pkey:          P_Key of the IB partition for this SRP channel.
 * @sess:          Session information associated with this SRP channel.
 * @sess_name:     Session name.
 * @release_work:  Allows scheduling of srpt_release_channel().
 */
struct srpt_rdma_ch {};

/**
 * struct srpt_nexus - I_T nexus
 * @rcu:       RCU head for this data structure.
 * @entry:     srpt_port.nexus_list list node.
 * @ch_list:   struct srpt_rdma_ch list. Protected by srpt_port.mutex.
 * @i_port_id: 128-bit initiator port identifier copied from SRP_LOGIN_REQ.
 * @t_port_id: 128-bit target port identifier copied from SRP_LOGIN_REQ.
 */
struct srpt_nexus {};

/**
 * struct srpt_port_attrib - attributes for SRPT port
 * @srp_max_rdma_size: Maximum size of SRP RDMA transfers for new connections.
 * @srp_max_rsp_size: Maximum size of SRP response messages in bytes.
 * @srp_sq_size: Shared receive queue (SRQ) size.
 * @use_srq: Whether or not to use SRQ.
 */
struct srpt_port_attrib {};

/**
 * struct srpt_tpg - information about a single "target portal group"
 * @entry:	Entry in @sport_id->tpg_list.
 * @sport_id:	Port name this TPG is associated with.
 * @tpg:	LIO TPG data structure.
 *
 * Zero or more target portal groups are associated with each port name
 * (srpt_port_id). With each TPG an ACL list is associated.
 */
struct srpt_tpg {};

/**
 * struct srpt_port_id - LIO RDMA port information
 * @mutex:	Protects @tpg_list changes.
 * @tpg_list:	TPGs associated with the RDMA port name.
 * @wwn:	WWN associated with the RDMA port name.
 * @name:	ASCII representation of the port name.
 *
 * Multiple sysfs directories can be associated with a single RDMA port. This
 * data structure represents a single (port, name) pair.
 */
struct srpt_port_id {};

/**
 * struct srpt_port - SRPT RDMA port information
 * @sdev:      backpointer to the HCA information.
 * @mad_agent: per-port management datagram processing information.
 * @enabled:   Whether or not this target port is enabled.
 * @port:      one-based port number.
 * @sm_lid:    cached value of the port's sm_lid.
 * @lid:       cached value of the port's lid.
 * @gid:       cached value of the port's gid.
 * @work:      work structure for refreshing the aforementioned cached values.
 * @guid_name: port name in GUID format.
 * @guid_id:   LIO target port information for the port name in GUID format.
 * @gid_name:  port name in GID format.
 * @gid_id:    LIO target port information for the port name in GID format.
 * @port_attrib:   Port attributes that can be accessed through configfs.
 * @refcount:	   Number of objects associated with this port.
 * @freed_channels: Completion that will be signaled once @refcount becomes 0.
 * @mutex:	   Protects nexus_list.
 * @nexus_list:	   Nexus list. See also srpt_nexus.entry.
 */
struct srpt_port {};

/**
 * struct srpt_device - information associated by SRPT with a single HCA
 * @refcnt:	   Reference count for this device.
 * @device:        Backpointer to the struct ib_device managed by the IB core.
 * @pd:            IB protection domain.
 * @lkey:          L_Key (local key) with write access to all local memory.
 * @srq:           Per-HCA SRQ (shared receive queue).
 * @cm_id:         Connection identifier.
 * @srq_size:      SRQ size.
 * @sdev_mutex:	   Serializes use_srq changes.
 * @use_srq:       Whether or not to use SRQ.
 * @req_buf_cache: kmem_cache for @ioctx_ring buffers.
 * @ioctx_ring:    Per-HCA SRQ.
 * @event_handler: Per-HCA asynchronous IB event handler.
 * @list:          Node in srpt_dev_list.
 * @port:          Information about the ports owned by this HCA.
 */
struct srpt_device {};

#endif				/* IB_SRPT_H */