lpfc_nvme.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2017-2022 Broadcom. All Rights Reserved. The term *
  5. * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
  6. * Copyright (C) 2004-2016 Emulex. All rights reserved. *
  7. * EMULEX and SLI are trademarks of Emulex. *
  8. * www.broadcom.com *
  9. * Portions Copyright (C) 2004-2005 Christoph Hellwig *
  10. * *
  11. * This program is free software; you can redistribute it and/or *
  12. * modify it under the terms of version 2 of the GNU General *
  13. * Public License as published by the Free Software Foundation. *
  14. * This program is distributed in the hope that it will be useful. *
  15. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  16. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  17. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  18. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  19. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  20. * more details, a copy of which can be found in the file COPYING *
  21. * included with this package. *
  22. ********************************************************************/
  23. #include <linux/nvme.h>
  24. #include <linux/nvme-fc-driver.h>
  25. #include <linux/nvme-fc.h>
  26. #define LPFC_NVME_DEFAULT_SEGS (64 + 1) /* 256K IOs */
  27. #define LPFC_NVME_ERSP_LEN 0x20
  28. #define LPFC_NVME_WAIT_TMO 10
  29. #define LPFC_NVME_EXPEDITE_XRICNT 8
  30. #define LPFC_NVME_FB_SHIFT 9
  31. #define LPFC_NVME_MAX_FB (1 << 20) /* 1M */
  32. #define lpfc_ndlp_get_nrport(ndlp) \
  33. ((!ndlp->nrport || (ndlp->fc4_xpt_flags & NVME_XPT_UNREG_WAIT))\
  34. ? NULL : ndlp->nrport)
  35. struct lpfc_nvme_qhandle {
  36. uint32_t index; /* WQ index to use */
  37. uint32_t qidx; /* queue index passed to create */
  38. uint32_t cpu_id; /* current cpu id at time of create */
  39. };
  40. /* Declare nvme-based local and remote port definitions. */
  41. struct lpfc_nvme_lport {
  42. struct lpfc_vport *vport;
  43. struct completion *lport_unreg_cmp;
  44. /* Add stats counters here */
  45. atomic_t fc4NvmeLsRequests;
  46. atomic_t fc4NvmeLsCmpls;
  47. atomic_t xmt_fcp_noxri;
  48. atomic_t xmt_fcp_bad_ndlp;
  49. atomic_t xmt_fcp_qdepth;
  50. atomic_t xmt_fcp_wqerr;
  51. atomic_t xmt_fcp_err;
  52. atomic_t xmt_fcp_abort;
  53. atomic_t xmt_ls_abort;
  54. atomic_t xmt_ls_err;
  55. atomic_t cmpl_fcp_xb;
  56. atomic_t cmpl_fcp_err;
  57. atomic_t cmpl_ls_xb;
  58. atomic_t cmpl_ls_err;
  59. };
  60. struct lpfc_nvme_rport {
  61. struct lpfc_nvme_lport *lport;
  62. struct nvme_fc_remote_port *remoteport;
  63. struct lpfc_nodelist *ndlp;
  64. struct completion rport_unreg_done;
  65. };
  66. struct lpfc_nvme_fcpreq_priv {
  67. struct lpfc_io_buf *nvme_buf;
  68. };
  69. /*
  70. * set NVME LS request timeouts to 30s. It is larger than the 2*R_A_TOV
  71. * set by the spec, which appears to have issues with some devices.
  72. */
  73. #define LPFC_NVME_LS_TIMEOUT 30
  74. #define LPFC_NVMET_DEFAULT_SEGS (64 + 1) /* 256K IOs */
  75. #define LPFC_NVMET_RQE_MIN_POST 128
  76. #define LPFC_NVMET_RQE_DEF_POST 512
  77. #define LPFC_NVMET_RQE_DEF_COUNT 2048
  78. #define LPFC_NVMET_SUCCESS_LEN 12
  79. #define LPFC_NVMET_MRQ_AUTO 0
  80. #define LPFC_NVMET_MRQ_MAX 16
  81. #define LPFC_NVMET_WAIT_TMO (5 * MSEC_PER_SEC)
  82. /* Used for NVME Target */
  83. #define LPFC_NVMET_INV_HOST_ACTIVE 1
  84. struct lpfc_nvmet_tgtport {
  85. struct lpfc_hba *phba;
  86. struct completion *tport_unreg_cmp;
  87. atomic_t state; /* tracks nvmet hosthandle invalidation */
  88. /* Stats counters - lpfc_nvmet_unsol_ls_buffer */
  89. atomic_t rcv_ls_req_in;
  90. atomic_t rcv_ls_req_out;
  91. atomic_t rcv_ls_req_drop;
  92. atomic_t xmt_ls_abort;
  93. atomic_t xmt_ls_abort_cmpl;
  94. /* Stats counters - lpfc_nvmet_xmt_ls_rsp */
  95. atomic_t xmt_ls_rsp;
  96. atomic_t xmt_ls_drop;
  97. /* Stats counters - lpfc_nvmet_xmt_ls_rsp_cmp */
  98. atomic_t xmt_ls_rsp_error;
  99. atomic_t xmt_ls_rsp_aborted;
  100. atomic_t xmt_ls_rsp_xb_set;
  101. atomic_t xmt_ls_rsp_cmpl;
  102. /* Stats counters - lpfc_nvmet_unsol_fcp_buffer */
  103. atomic_t rcv_fcp_cmd_in;
  104. atomic_t rcv_fcp_cmd_out;
  105. atomic_t rcv_fcp_cmd_drop;
  106. atomic_t rcv_fcp_cmd_defer;
  107. atomic_t xmt_fcp_release;
  108. /* Stats counters - lpfc_nvmet_xmt_fcp_op */
  109. atomic_t xmt_fcp_drop;
  110. atomic_t xmt_fcp_read_rsp;
  111. atomic_t xmt_fcp_read;
  112. atomic_t xmt_fcp_write;
  113. atomic_t xmt_fcp_rsp;
  114. /* Stats counters - lpfc_nvmet_xmt_fcp_op_cmp */
  115. atomic_t xmt_fcp_rsp_xb_set;
  116. atomic_t xmt_fcp_rsp_cmpl;
  117. atomic_t xmt_fcp_rsp_error;
  118. atomic_t xmt_fcp_rsp_aborted;
  119. atomic_t xmt_fcp_rsp_drop;
  120. /* Stats counters - lpfc_nvmet_xmt_fcp_abort */
  121. atomic_t xmt_fcp_xri_abort_cqe;
  122. atomic_t xmt_fcp_abort;
  123. atomic_t xmt_fcp_abort_cmpl;
  124. atomic_t xmt_abort_sol;
  125. atomic_t xmt_abort_unsol;
  126. atomic_t xmt_abort_rsp;
  127. atomic_t xmt_abort_rsp_error;
  128. /* Stats counters - defer IO */
  129. atomic_t defer_ctx;
  130. atomic_t defer_fod;
  131. atomic_t defer_wqfull;
  132. };
  133. struct lpfc_nvmet_ctx_info {
  134. struct list_head nvmet_ctx_list;
  135. spinlock_t nvmet_ctx_list_lock; /* lock per CPU */
  136. struct lpfc_nvmet_ctx_info *nvmet_ctx_next_cpu;
  137. struct lpfc_nvmet_ctx_info *nvmet_ctx_start_cpu;
  138. uint16_t nvmet_ctx_list_cnt;
  139. char pad[16]; /* pad to a cache-line */
  140. };
  141. /* This retrieves the context info associated with the specified cpu / mrq */
  142. #define lpfc_get_ctx_list(phba, cpu, mrq) \
  143. (phba->sli4_hba.nvmet_ctx_info + ((cpu * phba->cfg_nvmet_mrq) + mrq))
  144. /* Values for state field of struct lpfc_async_xchg_ctx */
  145. #define LPFC_NVME_STE_LS_RCV 1
  146. #define LPFC_NVME_STE_LS_ABORT 2
  147. #define LPFC_NVME_STE_LS_RSP 3
  148. #define LPFC_NVME_STE_RCV 4
  149. #define LPFC_NVME_STE_DATA 5
  150. #define LPFC_NVME_STE_ABORT 6
  151. #define LPFC_NVME_STE_DONE 7
  152. #define LPFC_NVME_STE_FREE 0xff
  153. /* Values for flag field of struct lpfc_async_xchg_ctx */
  154. #define LPFC_NVME_IO_INP 0x1 /* IO is in progress on exchange */
  155. #define LPFC_NVME_ABORT_OP 0x2 /* Abort WQE issued on exchange */
  156. #define LPFC_NVME_XBUSY 0x4 /* XB bit set on IO cmpl */
  157. #define LPFC_NVME_CTX_RLS 0x8 /* ctx free requested */
  158. #define LPFC_NVME_ABTS_RCV 0x10 /* ABTS received on exchange */
  159. #define LPFC_NVME_CTX_REUSE_WQ 0x20 /* ctx reused via WQ */
  160. #define LPFC_NVME_DEFER_WQFULL 0x40 /* Waiting on a free WQE */
  161. #define LPFC_NVME_TNOTIFY 0x80 /* notify transport of abts */
  162. struct lpfc_async_xchg_ctx {
  163. union {
  164. struct nvmefc_tgt_fcp_req fcp_req;
  165. } hdlrctx;
  166. struct list_head list;
  167. struct lpfc_hba *phba;
  168. struct lpfc_nodelist *ndlp;
  169. struct nvmefc_ls_req *ls_req;
  170. struct nvmefc_ls_rsp ls_rsp;
  171. struct lpfc_iocbq *wqeq;
  172. struct lpfc_iocbq *abort_wqeq;
  173. spinlock_t ctxlock; /* protect flag access */
  174. uint32_t sid;
  175. uint32_t offset;
  176. uint16_t oxid;
  177. uint16_t size;
  178. uint16_t entry_cnt;
  179. uint16_t cpu;
  180. uint16_t idx;
  181. uint16_t state;
  182. uint16_t flag;
  183. void *payload;
  184. struct rqb_dmabuf *rqb_buffer;
  185. struct lpfc_nvmet_ctxbuf *ctxbuf;
  186. struct lpfc_sli4_hdw_queue *hdwq;
  187. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  188. uint64_t ts_isr_cmd;
  189. uint64_t ts_cmd_nvme;
  190. uint64_t ts_nvme_data;
  191. uint64_t ts_data_wqput;
  192. uint64_t ts_isr_data;
  193. uint64_t ts_data_nvme;
  194. uint64_t ts_nvme_status;
  195. uint64_t ts_status_wqput;
  196. uint64_t ts_isr_status;
  197. uint64_t ts_status_nvme;
  198. #endif
  199. };
  200. /* routines found in lpfc_nvme.c */
  201. int __lpfc_nvme_ls_req(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  202. struct nvmefc_ls_req *pnvme_lsreq,
  203. void (*gen_req_cmp)(struct lpfc_hba *phba,
  204. struct lpfc_iocbq *cmdwqe,
  205. struct lpfc_iocbq *rspwqe));
  206. void __lpfc_nvme_ls_req_cmp(struct lpfc_hba *phba, struct lpfc_vport *vport,
  207. struct lpfc_iocbq *cmdwqe, struct lpfc_wcqe_complete *wcqe);
  208. int __lpfc_nvme_ls_abort(struct lpfc_vport *vport,
  209. struct lpfc_nodelist *ndlp, struct nvmefc_ls_req *pnvme_lsreq);
  210. /* routines found in lpfc_nvmet.c */
  211. int lpfc_nvme_unsol_ls_issue_abort(struct lpfc_hba *phba,
  212. struct lpfc_async_xchg_ctx *ctxp, uint32_t sid,
  213. uint16_t xri);
  214. int __lpfc_nvme_xmt_ls_rsp(struct lpfc_async_xchg_ctx *axchg,
  215. struct nvmefc_ls_rsp *ls_rsp,
  216. void (*xmt_ls_rsp_cmp)(struct lpfc_hba *phba,
  217. struct lpfc_iocbq *cmdwqe,
  218. struct lpfc_iocbq *rspwqe));
  219. void __lpfc_nvme_xmt_ls_rsp_cmp(struct lpfc_hba *phba,
  220. struct lpfc_iocbq *cmdwqe, struct lpfc_iocbq *rspwqe);