Back to home page

OSCL-LXR

 
 

    


0001 /*******************************************************************
0002  * This file is part of the Emulex Linux Device Driver for         *
0003  * Fibre Channel Host Bus Adapters.                                *
0004  * Copyright (C) 2017-2022 Broadcom. All Rights Reserved. The term *
0005  * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.  *
0006  * Copyright (C) 2004-2016 Emulex.  All rights reserved.           *
0007  * EMULEX and SLI are trademarks of Emulex.                        *
0008  * www.broadcom.com                                                *
0009  * Portions Copyright (C) 2004-2005 Christoph Hellwig              *
0010  *                                                                 *
0011  * This program is free software; you can redistribute it and/or   *
0012  * modify it under the terms of version 2 of the GNU General       *
0013  * Public License as published by the Free Software Foundation.    *
0014  * This program is distributed in the hope that it will be useful. *
0015  * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND          *
0016  * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,  *
0017  * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE      *
0018  * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
0019  * TO BE LEGALLY INVALID.  See the GNU General Public License for  *
0020  * more details, a copy of which can be found in the file COPYING  *
0021  * included with this package.                                     *
0022  ********************************************************************/
0023 
0024 #include <linux/nvme.h>
0025 #include <linux/nvme-fc-driver.h>
0026 #include <linux/nvme-fc.h>
0027 
0028 #define LPFC_NVME_DEFAULT_SEGS      (64 + 1)    /* 256K IOs */
0029 
0030 #define LPFC_NVME_ERSP_LEN      0x20
0031 
0032 #define LPFC_NVME_WAIT_TMO              10
0033 #define LPFC_NVME_EXPEDITE_XRICNT   8
0034 #define LPFC_NVME_FB_SHIFT      9
0035 #define LPFC_NVME_MAX_FB        (1 << 20)   /* 1M */
0036 
0037 #define lpfc_ndlp_get_nrport(ndlp)              \
0038     ((!ndlp->nrport || (ndlp->fc4_xpt_flags & NVME_XPT_UNREG_WAIT))\
0039     ? NULL : ndlp->nrport)
0040 
0041 struct lpfc_nvme_qhandle {
0042     uint32_t index;     /* WQ index to use */
0043     uint32_t qidx;      /* queue index passed to create */
0044     uint32_t cpu_id;    /* current cpu id at time of create */
0045 };
0046 
0047 /* Declare nvme-based local and remote port definitions. */
0048 struct lpfc_nvme_lport {
0049     struct lpfc_vport *vport;
0050     struct completion *lport_unreg_cmp;
0051     /* Add stats counters here */
0052     atomic_t fc4NvmeLsRequests;
0053     atomic_t fc4NvmeLsCmpls;
0054     atomic_t xmt_fcp_noxri;
0055     atomic_t xmt_fcp_bad_ndlp;
0056     atomic_t xmt_fcp_qdepth;
0057     atomic_t xmt_fcp_wqerr;
0058     atomic_t xmt_fcp_err;
0059     atomic_t xmt_fcp_abort;
0060     atomic_t xmt_ls_abort;
0061     atomic_t xmt_ls_err;
0062     atomic_t cmpl_fcp_xb;
0063     atomic_t cmpl_fcp_err;
0064     atomic_t cmpl_ls_xb;
0065     atomic_t cmpl_ls_err;
0066 };
0067 
0068 struct lpfc_nvme_rport {
0069     struct lpfc_nvme_lport *lport;
0070     struct nvme_fc_remote_port *remoteport;
0071     struct lpfc_nodelist *ndlp;
0072     struct completion rport_unreg_done;
0073 };
0074 
0075 struct lpfc_nvme_fcpreq_priv {
0076     struct lpfc_io_buf *nvme_buf;
0077 };
0078 
0079 /*
0080  * set NVME LS request timeouts to 30s. It is larger than the 2*R_A_TOV
0081  * set by the spec, which appears to have issues with some devices.
0082  */
0083 #define LPFC_NVME_LS_TIMEOUT        30
0084 
0085 
0086 #define LPFC_NVMET_DEFAULT_SEGS     (64 + 1)    /* 256K IOs */
0087 #define LPFC_NVMET_RQE_MIN_POST     128
0088 #define LPFC_NVMET_RQE_DEF_POST     512
0089 #define LPFC_NVMET_RQE_DEF_COUNT    2048
0090 #define LPFC_NVMET_SUCCESS_LEN      12
0091 
0092 #define LPFC_NVMET_MRQ_AUTO     0
0093 #define LPFC_NVMET_MRQ_MAX      16
0094 
0095 #define LPFC_NVMET_WAIT_TMO     (5 * MSEC_PER_SEC)
0096 
0097 /* Used for NVME Target */
0098 #define LPFC_NVMET_INV_HOST_ACTIVE      1
0099 
0100 struct lpfc_nvmet_tgtport {
0101     struct lpfc_hba *phba;
0102     struct completion *tport_unreg_cmp;
0103     atomic_t state;     /* tracks nvmet hosthandle invalidation */
0104 
0105     /* Stats counters - lpfc_nvmet_unsol_ls_buffer */
0106     atomic_t rcv_ls_req_in;
0107     atomic_t rcv_ls_req_out;
0108     atomic_t rcv_ls_req_drop;
0109     atomic_t xmt_ls_abort;
0110     atomic_t xmt_ls_abort_cmpl;
0111 
0112     /* Stats counters - lpfc_nvmet_xmt_ls_rsp */
0113     atomic_t xmt_ls_rsp;
0114     atomic_t xmt_ls_drop;
0115 
0116     /* Stats counters - lpfc_nvmet_xmt_ls_rsp_cmp */
0117     atomic_t xmt_ls_rsp_error;
0118     atomic_t xmt_ls_rsp_aborted;
0119     atomic_t xmt_ls_rsp_xb_set;
0120     atomic_t xmt_ls_rsp_cmpl;
0121 
0122     /* Stats counters - lpfc_nvmet_unsol_fcp_buffer */
0123     atomic_t rcv_fcp_cmd_in;
0124     atomic_t rcv_fcp_cmd_out;
0125     atomic_t rcv_fcp_cmd_drop;
0126     atomic_t rcv_fcp_cmd_defer;
0127     atomic_t xmt_fcp_release;
0128 
0129     /* Stats counters - lpfc_nvmet_xmt_fcp_op */
0130     atomic_t xmt_fcp_drop;
0131     atomic_t xmt_fcp_read_rsp;
0132     atomic_t xmt_fcp_read;
0133     atomic_t xmt_fcp_write;
0134     atomic_t xmt_fcp_rsp;
0135 
0136     /* Stats counters - lpfc_nvmet_xmt_fcp_op_cmp */
0137     atomic_t xmt_fcp_rsp_xb_set;
0138     atomic_t xmt_fcp_rsp_cmpl;
0139     atomic_t xmt_fcp_rsp_error;
0140     atomic_t xmt_fcp_rsp_aborted;
0141     atomic_t xmt_fcp_rsp_drop;
0142 
0143     /* Stats counters - lpfc_nvmet_xmt_fcp_abort */
0144     atomic_t xmt_fcp_xri_abort_cqe;
0145     atomic_t xmt_fcp_abort;
0146     atomic_t xmt_fcp_abort_cmpl;
0147     atomic_t xmt_abort_sol;
0148     atomic_t xmt_abort_unsol;
0149     atomic_t xmt_abort_rsp;
0150     atomic_t xmt_abort_rsp_error;
0151 
0152     /* Stats counters - defer IO */
0153     atomic_t defer_ctx;
0154     atomic_t defer_fod;
0155     atomic_t defer_wqfull;
0156 };
0157 
0158 struct lpfc_nvmet_ctx_info {
0159     struct list_head nvmet_ctx_list;
0160     spinlock_t  nvmet_ctx_list_lock; /* lock per CPU */
0161     struct lpfc_nvmet_ctx_info *nvmet_ctx_next_cpu;
0162     struct lpfc_nvmet_ctx_info *nvmet_ctx_start_cpu;
0163     uint16_t    nvmet_ctx_list_cnt;
0164     char pad[16];  /* pad to a cache-line */
0165 };
0166 
0167 /* This retrieves the context info associated with the specified cpu / mrq */
0168 #define lpfc_get_ctx_list(phba, cpu, mrq)  \
0169     (phba->sli4_hba.nvmet_ctx_info + ((cpu * phba->cfg_nvmet_mrq) + mrq))
0170 
0171 /* Values for state field of struct lpfc_async_xchg_ctx */
0172 #define LPFC_NVME_STE_LS_RCV        1
0173 #define LPFC_NVME_STE_LS_ABORT      2
0174 #define LPFC_NVME_STE_LS_RSP        3
0175 #define LPFC_NVME_STE_RCV       4
0176 #define LPFC_NVME_STE_DATA      5
0177 #define LPFC_NVME_STE_ABORT     6
0178 #define LPFC_NVME_STE_DONE      7
0179 #define LPFC_NVME_STE_FREE      0xff
0180 
0181 /* Values for flag field of struct lpfc_async_xchg_ctx */
0182 #define LPFC_NVME_IO_INP        0x1  /* IO is in progress on exchange */
0183 #define LPFC_NVME_ABORT_OP      0x2  /* Abort WQE issued on exchange */
0184 #define LPFC_NVME_XBUSY         0x4  /* XB bit set on IO cmpl */
0185 #define LPFC_NVME_CTX_RLS       0x8  /* ctx free requested */
0186 #define LPFC_NVME_ABTS_RCV      0x10  /* ABTS received on exchange */
0187 #define LPFC_NVME_CTX_REUSE_WQ      0x20  /* ctx reused via WQ */
0188 #define LPFC_NVME_DEFER_WQFULL      0x40  /* Waiting on a free WQE */
0189 #define LPFC_NVME_TNOTIFY       0x80  /* notify transport of abts */
0190 
0191 struct lpfc_async_xchg_ctx {
0192     union {
0193         struct nvmefc_tgt_fcp_req fcp_req;
0194     } hdlrctx;
0195     struct list_head list;
0196     struct lpfc_hba *phba;
0197     struct lpfc_nodelist *ndlp;
0198     struct nvmefc_ls_req *ls_req;
0199     struct nvmefc_ls_rsp ls_rsp;
0200     struct lpfc_iocbq *wqeq;
0201     struct lpfc_iocbq *abort_wqeq;
0202     spinlock_t ctxlock; /* protect flag access */
0203     uint32_t sid;
0204     uint32_t offset;
0205     uint16_t oxid;
0206     uint16_t size;
0207     uint16_t entry_cnt;
0208     uint16_t cpu;
0209     uint16_t idx;
0210     uint16_t state;
0211     uint16_t flag;
0212     void *payload;
0213     struct rqb_dmabuf *rqb_buffer;
0214     struct lpfc_nvmet_ctxbuf *ctxbuf;
0215     struct lpfc_sli4_hdw_queue *hdwq;
0216 
0217 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
0218     uint64_t ts_isr_cmd;
0219     uint64_t ts_cmd_nvme;
0220     uint64_t ts_nvme_data;
0221     uint64_t ts_data_wqput;
0222     uint64_t ts_isr_data;
0223     uint64_t ts_data_nvme;
0224     uint64_t ts_nvme_status;
0225     uint64_t ts_status_wqput;
0226     uint64_t ts_isr_status;
0227     uint64_t ts_status_nvme;
0228 #endif
0229 };
0230 
0231 
0232 /* routines found in lpfc_nvme.c */
0233 int __lpfc_nvme_ls_req(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
0234         struct nvmefc_ls_req *pnvme_lsreq,
0235         void (*gen_req_cmp)(struct lpfc_hba *phba,
0236                 struct lpfc_iocbq *cmdwqe,
0237                 struct lpfc_iocbq *rspwqe));
0238 void __lpfc_nvme_ls_req_cmp(struct lpfc_hba *phba,  struct lpfc_vport *vport,
0239         struct lpfc_iocbq *cmdwqe, struct lpfc_wcqe_complete *wcqe);
0240 int __lpfc_nvme_ls_abort(struct lpfc_vport *vport,
0241         struct lpfc_nodelist *ndlp, struct nvmefc_ls_req *pnvme_lsreq);
0242 
0243 /* routines found in lpfc_nvmet.c */
0244 int lpfc_nvme_unsol_ls_issue_abort(struct lpfc_hba *phba,
0245             struct lpfc_async_xchg_ctx *ctxp, uint32_t sid,
0246             uint16_t xri);
0247 int __lpfc_nvme_xmt_ls_rsp(struct lpfc_async_xchg_ctx *axchg,
0248             struct nvmefc_ls_rsp *ls_rsp,
0249             void (*xmt_ls_rsp_cmp)(struct lpfc_hba *phba,
0250                 struct lpfc_iocbq *cmdwqe,
0251                 struct lpfc_iocbq *rspwqe));
0252 void __lpfc_nvme_xmt_ls_rsp_cmp(struct lpfc_hba *phba,
0253         struct lpfc_iocbq *cmdwqe, struct lpfc_iocbq *rspwqe);