Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright (c) 2005 Cisco Systems.  All rights reserved.
0003  *
0004  * This software is available to you under a choice of one of two
0005  * licenses.  You may choose to be licensed under the terms of the GNU
0006  * General Public License (GPL) Version 2, available from the file
0007  * COPYING in the main directory of this source tree, or the
0008  * OpenIB.org BSD license below:
0009  *
0010  *     Redistribution and use in source and binary forms, with or
0011  *     without modification, are permitted provided that the following
0012  *     conditions are met:
0013  *
0014  *      - Redistributions of source code must retain the above
0015  *        copyright notice, this list of conditions and the following
0016  *        disclaimer.
0017  *
0018  *      - Redistributions in binary form must reproduce the above
0019  *        copyright notice, this list of conditions and the following
0020  *        disclaimer in the documentation and/or other materials
0021  *        provided with the distribution.
0022  *
0023  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
0024  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
0025  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
0026  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
0027  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
0028  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
0029  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
0030  * SOFTWARE.
0031  */
0032 
0033 #ifndef IB_SRP_H
0034 #define IB_SRP_H
0035 
0036 #include <linux/types.h>
0037 #include <linux/list.h>
0038 #include <linux/mutex.h>
0039 #include <linux/scatterlist.h>
0040 
0041 #include <scsi/scsi_host.h>
0042 #include <scsi/scsi_cmnd.h>
0043 
0044 #include <rdma/ib_verbs.h>
0045 #include <rdma/ib_sa.h>
0046 #include <rdma/ib_cm.h>
0047 #include <rdma/rdma_cm.h>
0048 
0049 enum {
0050     SRP_PATH_REC_TIMEOUT_MS = 1000,
0051     SRP_ABORT_TIMEOUT_MS    = 5000,
0052 
0053     SRP_PORT_REDIRECT   = 1,
0054     SRP_DLID_REDIRECT   = 2,
0055     SRP_STALE_CONN      = 3,
0056 
0057     SRP_DEF_SG_TABLESIZE    = 12,
0058 
0059     SRP_DEFAULT_QUEUE_SIZE  = 1 << 6,
0060     SRP_RSP_SQ_SIZE     = 1,
0061     SRP_TSK_MGMT_SQ_SIZE    = 1,
0062     SRP_DEFAULT_CMD_SQ_SIZE = SRP_DEFAULT_QUEUE_SIZE - SRP_RSP_SQ_SIZE -
0063                   SRP_TSK_MGMT_SQ_SIZE,
0064 
0065     SRP_TAG_NO_REQ      = ~0U,
0066     SRP_TAG_TSK_MGMT    = 1U << 31,
0067 
0068     SRP_MAX_PAGES_PER_MR    = 512,
0069 
0070     SRP_MAX_ADD_CDB_LEN = 16,
0071 
0072     SRP_MAX_IMM_SGE     = 2,
0073     SRP_MAX_SGE     = SRP_MAX_IMM_SGE + 1,
0074     /*
0075      * Choose the immediate data offset such that a 32 byte CDB still fits.
0076      */
0077     SRP_IMM_DATA_OFFSET = sizeof(struct srp_cmd) +
0078                   SRP_MAX_ADD_CDB_LEN +
0079                   sizeof(struct srp_imm_buf),
0080 };
0081 
0082 enum srp_target_state {
0083     SRP_TARGET_SCANNING,
0084     SRP_TARGET_LIVE,
0085     SRP_TARGET_REMOVED,
0086 };
0087 
0088 enum srp_iu_type {
0089     SRP_IU_CMD,
0090     SRP_IU_TSK_MGMT,
0091     SRP_IU_RSP,
0092 };
0093 
0094 /*
0095  * RDMA adapter in the initiator system.
0096  *
0097  * @dev_list: List of RDMA ports associated with this RDMA adapter (srp_host).
0098  * @mr_page_mask: HCA memory registration page mask.
0099  * @mr_page_size: HCA memory registration page size.
0100  * @mr_max_size: Maximum size in bytes of a single FR registration request.
0101  */
0102 struct srp_device {
0103     struct list_head    dev_list;
0104     struct ib_device       *dev;
0105     struct ib_pd           *pd;
0106     u32         global_rkey;
0107     u64         mr_page_mask;
0108     int         mr_page_size;
0109     int         mr_max_size;
0110     int         max_pages_per_mr;
0111     bool            has_fr;
0112     bool            use_fast_reg;
0113 };
0114 
0115 /*
0116  * One port of an RDMA adapter in the initiator system.
0117  *
0118  * @target_list: List of connected target ports (struct srp_target_port).
0119  * @target_lock: Protects @target_list.
0120  */
0121 struct srp_host {
0122     struct srp_device      *srp_dev;
0123     u8          port;
0124     struct device       dev;
0125     struct list_head    target_list;
0126     spinlock_t      target_lock;
0127     struct completion   released;
0128     struct list_head    list;
0129     struct mutex        add_target_mutex;
0130 };
0131 
0132 struct srp_request {
0133     struct scsi_cmnd       *scmnd;
0134     struct srp_iu          *cmd;
0135     struct srp_fr_desc     **fr_list;
0136     struct srp_direct_buf  *indirect_desc;
0137     dma_addr_t      indirect_dma_addr;
0138     short           nmdesc;
0139     struct ib_cqe       reg_cqe;
0140 };
0141 
0142 /**
0143  * struct srp_rdma_ch
0144  * @comp_vector: Completion vector used by this RDMA channel.
0145  * @max_it_iu_len: Maximum initiator-to-target information unit length.
0146  * @max_ti_iu_len: Maximum target-to-initiator information unit length.
0147  */
0148 struct srp_rdma_ch {
0149     /* These are RW in the hot path, and commonly used together */
0150     struct list_head    free_tx;
0151     spinlock_t      lock;
0152     s32         req_lim;
0153 
0154     /* These are read-only in the hot path */
0155     struct srp_target_port *target ____cacheline_aligned_in_smp;
0156     struct ib_cq           *send_cq;
0157     struct ib_cq           *recv_cq;
0158     struct ib_qp           *qp;
0159     struct srp_fr_pool     *fr_pool;
0160     uint32_t        max_it_iu_len;
0161     uint32_t        max_ti_iu_len;
0162     u8          max_imm_sge;
0163     bool            use_imm_data;
0164 
0165     /* Everything above this point is used in the hot path of
0166      * command processing. Try to keep them packed into cachelines.
0167      */
0168 
0169     struct completion   done;
0170     int         status;
0171 
0172     union {
0173         struct ib_cm {
0174             struct sa_path_rec  path;
0175             struct ib_sa_query  *path_query;
0176             int         path_query_id;
0177             struct ib_cm_id     *cm_id;
0178         } ib_cm;
0179         struct rdma_cm {
0180             struct rdma_cm_id   *cm_id;
0181         } rdma_cm;
0182     };
0183 
0184     struct srp_iu         **tx_ring;
0185     struct srp_iu         **rx_ring;
0186     int         comp_vector;
0187 
0188     u64         tsk_mgmt_tag;
0189     struct completion   tsk_mgmt_done;
0190     u8          tsk_mgmt_status;
0191     bool            connected;
0192 };
0193 
0194 /**
0195  * struct srp_target_port - RDMA port in the SRP target system
0196  * @comp_vector: Completion vector used by the first RDMA channel created for
0197  *   this target port.
0198  */
0199 struct srp_target_port {
0200     /* read and written in the hot path */
0201     spinlock_t      lock;
0202 
0203     /* read only in the hot path */
0204     u32         global_rkey;
0205     struct srp_rdma_ch  *ch;
0206     struct net      *net;
0207     u32         ch_count;
0208     u32         lkey;
0209     enum srp_target_state   state;
0210     uint32_t        max_it_iu_size;
0211     unsigned int        cmd_sg_cnt;
0212     unsigned int        indirect_size;
0213     bool            allow_ext_sg;
0214 
0215     /* other member variables */
0216     union ib_gid        sgid;
0217     __be64          id_ext;
0218     __be64          ioc_guid;
0219     __be64          initiator_ext;
0220     u16         io_class;
0221     struct srp_host        *srp_host;
0222     struct Scsi_Host       *scsi_host;
0223     struct srp_rport       *rport;
0224     char            target_name[32];
0225     unsigned int        scsi_id;
0226     unsigned int        sg_tablesize;
0227     unsigned int        target_can_queue;
0228     int         mr_pool_size;
0229     int         mr_per_cmd;
0230     int         queue_size;
0231     int         comp_vector;
0232     int         tl_retry_count;
0233 
0234     bool            using_rdma_cm;
0235 
0236     union {
0237         struct {
0238             __be64          service_id;
0239             union ib_gid        orig_dgid;
0240             __be16          pkey;
0241         } ib_cm;
0242         struct {
0243             union {
0244                 struct sockaddr_in  ip4;
0245                 struct sockaddr_in6 ip6;
0246                 struct sockaddr     sa;
0247                 struct sockaddr_storage ss;
0248             } src;
0249             union {
0250                 struct sockaddr_in  ip4;
0251                 struct sockaddr_in6 ip6;
0252                 struct sockaddr     sa;
0253                 struct sockaddr_storage ss;
0254             } dst;
0255             bool src_specified;
0256         } rdma_cm;
0257     };
0258 
0259     u32         rq_tmo_jiffies;
0260 
0261     int         zero_req_lim;
0262 
0263     struct work_struct  tl_err_work;
0264     struct work_struct  remove_work;
0265 
0266     struct list_head    list;
0267     bool            qp_in_error;
0268 };
0269 
0270 struct srp_iu {
0271     struct list_head    list;
0272     u64         dma;
0273     void               *buf;
0274     size_t          size;
0275     enum dma_data_direction direction;
0276     u32         num_sge;
0277     struct ib_sge       sge[SRP_MAX_SGE];
0278     struct ib_cqe       cqe;
0279 };
0280 
0281 /**
0282  * struct srp_fr_desc - fast registration work request arguments
0283  * @entry: Entry in srp_fr_pool.free_list.
0284  * @mr:    Memory region.
0285  * @frpl:  Fast registration page list.
0286  */
0287 struct srp_fr_desc {
0288     struct list_head        entry;
0289     struct ib_mr            *mr;
0290 };
0291 
0292 /**
0293  * struct srp_fr_pool - pool of fast registration descriptors
0294  *
0295  * An entry is available for allocation if and only if it occurs in @free_list.
0296  *
0297  * @size:      Number of descriptors in this pool.
0298  * @max_page_list_len: Maximum fast registration work request page list length.
0299  * @lock:      Protects free_list.
0300  * @free_list: List of free descriptors.
0301  * @desc:      Fast registration descriptor pool.
0302  */
0303 struct srp_fr_pool {
0304     int         size;
0305     int         max_page_list_len;
0306     spinlock_t      lock;
0307     struct list_head    free_list;
0308     struct srp_fr_desc  desc[];
0309 };
0310 
0311 /**
0312  * struct srp_map_state - per-request DMA memory mapping state
0313  * @desc:       Pointer to the element of the SRP buffer descriptor array
0314  *          that is being filled in.
0315  * @pages:      Array with DMA addresses of pages being considered for
0316  *          memory registration.
0317  * @base_dma_addr:  DMA address of the first page that has not yet been mapped.
0318  * @dma_len:        Number of bytes that will be registered with the next FR
0319  *                  memory registration call.
0320  * @total_len:      Total number of bytes in the sg-list being mapped.
0321  * @npages:     Number of page addresses in the pages[] array.
0322  * @nmdesc:     Number of FR memory descriptors used for mapping.
0323  * @ndesc:      Number of SRP buffer descriptors that have been filled in.
0324  */
0325 struct srp_map_state {
0326     union {
0327         struct {
0328             struct srp_fr_desc **next;
0329             struct srp_fr_desc **end;
0330         } fr;
0331         struct {
0332             void           **next;
0333             void           **end;
0334         } gen;
0335     };
0336     struct srp_direct_buf  *desc;
0337     union {
0338         u64         *pages;
0339         struct scatterlist  *sg;
0340     };
0341     dma_addr_t      base_dma_addr;
0342     u32         dma_len;
0343     u32         total_len;
0344     unsigned int        npages;
0345     unsigned int        nmdesc;
0346     unsigned int        ndesc;
0347 };
0348 
0349 #endif /* IB_SRP_H */