csio_scsi.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. /*
  2. * This file is part of the Chelsio FCoE driver for Linux.
  3. *
  4. * Copyright (c) 2008-2012 Chelsio Communications, Inc. All rights reserved.
  5. *
  6. * This software is available to you under a choice of one of two
  7. * licenses. You may choose to be licensed under the terms of the GNU
  8. * General Public License (GPL) Version 2, available from the file
  9. * COPYING in the main directory of this source tree, or the
  10. * OpenIB.org BSD license below:
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above
  17. * copyright notice, this list of conditions and the following
  18. * disclaimer.
  19. *
  20. * - Redistributions in binary form must reproduce the above
  21. * copyright notice, this list of conditions and the following
  22. * disclaimer in the documentation and/or other materials
  23. * provided with the distribution.
  24. *
  25. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  26. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  27. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  28. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  29. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  30. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  31. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  32. * SOFTWARE.
  33. */
  34. #ifndef __CSIO_SCSI_H__
  35. #define __CSIO_SCSI_H__
  36. #include <linux/spinlock_types.h>
  37. #include <linux/completion.h>
  38. #include <scsi/scsi.h>
  39. #include <scsi/scsi_cmnd.h>
  40. #include <scsi/scsi_device.h>
  41. #include <scsi/scsi_host.h>
  42. #include <scsi/scsi_eh.h>
  43. #include <scsi/scsi_tcq.h>
  44. #include <scsi/fc/fc_fcp.h>
  45. #include "csio_defs.h"
  46. #include "csio_wr.h"
  47. extern struct scsi_host_template csio_fcoe_shost_template;
  48. extern struct scsi_host_template csio_fcoe_shost_vport_template;
  49. extern int csio_scsi_eqsize;
  50. extern int csio_scsi_iqlen;
  51. extern int csio_scsi_ioreqs;
  52. extern uint32_t csio_max_scan_tmo;
  53. extern uint32_t csio_delta_scan_tmo;
  54. extern int csio_lun_qdepth;
  55. /*
  56. **************************** NOTE *******************************
  57. * How do we calculate MAX FCoE SCSI SGEs? Here is the math:
  58. * Max Egress WR size = 512 bytes
  59. * One SCSI egress WR has the following fixed no of bytes:
  60. * 48 (sizeof(struct fw_scsi_write[read]_wr)) - FW WR
  61. * + 32 (sizeof(struct fc_fcp_cmnd)) - Immediate FCP_CMD
  62. * ------
  63. * 80
  64. * ------
  65. * That leaves us with 512 - 96 = 432 bytes for data SGE. Using
  66. * struct ulptx_sgl header for the SGE consumes:
  67. * - 4 bytes for cmnd_sge.
  68. * - 12 bytes for the first SGL.
  69. * That leaves us with 416 bytes for the remaining SGE pairs. Which is
  70. * is 416 / 24 (size(struct ulptx_sge_pair)) = 17 SGE pairs,
  71. * or 34 SGEs. Adding the first SGE fetches us 35 SGEs.
  72. */
  73. #define CSIO_SCSI_MAX_SGE 35
  74. #define CSIO_SCSI_ABRT_TMO_MS 60000
  75. #define CSIO_SCSI_LUNRST_TMO_MS 60000
  76. #define CSIO_SCSI_TM_POLL_MS 2000 /* should be less than
  77. * all TM timeouts.
  78. */
  79. #define CSIO_SCSI_IQ_WRSZ 128
  80. #define CSIO_SCSI_IQSIZE (csio_scsi_iqlen * CSIO_SCSI_IQ_WRSZ)
  81. #define CSIO_MAX_SNS_LEN 128
  82. #define CSIO_SCSI_RSP_LEN (FCP_RESP_WITH_EXT + 4 + CSIO_MAX_SNS_LEN)
  83. /* Reference to scsi_cmnd */
  84. #define csio_scsi_cmnd(req) ((req)->scratch1)
  85. struct csio_scsi_stats {
  86. uint64_t n_tot_success; /* Total number of good I/Os */
  87. uint32_t n_rn_nr_error; /* No. of remote-node-not-
  88. * ready errors
  89. */
  90. uint32_t n_hw_nr_error; /* No. of hw-module-not-
  91. * ready errors
  92. */
  93. uint32_t n_dmamap_error; /* No. of DMA map erros */
  94. uint32_t n_unsupp_sge_error; /* No. of too-many-SGes
  95. * errors.
  96. */
  97. uint32_t n_no_req_error; /* No. of Out-of-ioreqs error */
  98. uint32_t n_busy_error; /* No. of -EBUSY errors */
  99. uint32_t n_hosterror; /* No. of FW_HOSTERROR I/O */
  100. uint32_t n_rsperror; /* No. of response errors */
  101. uint32_t n_autosense; /* No. of auto sense replies */
  102. uint32_t n_ovflerror; /* No. of overflow errors */
  103. uint32_t n_unflerror; /* No. of underflow errors */
  104. uint32_t n_rdev_nr_error;/* No. of rdev not
  105. * ready errors
  106. */
  107. uint32_t n_rdev_lost_error;/* No. of rdev lost errors */
  108. uint32_t n_rdev_logo_error;/* No. of rdev logo errors */
  109. uint32_t n_link_down_error;/* No. of link down errors */
  110. uint32_t n_no_xchg_error; /* No. no exchange error */
  111. uint32_t n_unknown_error;/* No. of unhandled errors */
  112. uint32_t n_aborted; /* No. of aborted I/Os */
  113. uint32_t n_abrt_timedout; /* No. of abort timedouts */
  114. uint32_t n_abrt_fail; /* No. of abort failures */
  115. uint32_t n_abrt_dups; /* No. of duplicate aborts */
  116. uint32_t n_abrt_race_comp; /* No. of aborts that raced
  117. * with completions.
  118. */
  119. uint32_t n_abrt_busy_error;/* No. of abort failures
  120. * due to -EBUSY.
  121. */
  122. uint32_t n_closed; /* No. of closed I/Os */
  123. uint32_t n_cls_busy_error; /* No. of close failures
  124. * due to -EBUSY.
  125. */
  126. uint32_t n_active; /* No. of IOs in active_q */
  127. uint32_t n_tm_active; /* No. of TMs in active_q */
  128. uint32_t n_wcbfn; /* No. of I/Os in worker
  129. * cbfn q
  130. */
  131. uint32_t n_free_ioreq; /* No. of freelist entries */
  132. uint32_t n_free_ddp; /* No. of DDP freelist */
  133. uint32_t n_unaligned; /* No. of Unaligned SGls */
  134. uint32_t n_inval_cplop; /* No. invalid CPL op's in IQ */
  135. uint32_t n_inval_scsiop; /* No. invalid scsi op's in IQ*/
  136. };
  137. struct csio_scsim {
  138. struct csio_hw *hw; /* Pointer to HW moduel */
  139. uint8_t max_sge; /* Max SGE */
  140. uint8_t proto_cmd_len; /* Proto specific SCSI
  141. * cmd length
  142. */
  143. uint16_t proto_rsp_len; /* Proto specific SCSI
  144. * response length
  145. */
  146. spinlock_t freelist_lock; /* Lock for ioreq freelist */
  147. struct list_head active_q; /* Outstanding SCSI I/Os */
  148. struct list_head ioreq_freelist; /* Free list of ioreq's */
  149. struct list_head ddp_freelist; /* DDP descriptor freelist */
  150. struct csio_scsi_stats stats; /* This module's statistics */
  151. };
  152. /* State machine defines */
  153. enum csio_scsi_ev {
  154. CSIO_SCSIE_START_IO = 1, /* Start a regular SCSI IO */
  155. CSIO_SCSIE_START_TM, /* Start a TM IO */
  156. CSIO_SCSIE_COMPLETED, /* IO Completed */
  157. CSIO_SCSIE_ABORT, /* Abort IO */
  158. CSIO_SCSIE_ABORTED, /* IO Aborted */
  159. CSIO_SCSIE_CLOSE, /* Close exchange */
  160. CSIO_SCSIE_CLOSED, /* Exchange closed */
  161. CSIO_SCSIE_DRVCLEANUP, /* Driver wants to manually
  162. * cleanup this I/O.
  163. */
  164. };
  165. enum csio_scsi_lev {
  166. CSIO_LEV_ALL = 1,
  167. CSIO_LEV_LNODE,
  168. CSIO_LEV_RNODE,
  169. CSIO_LEV_LUN,
  170. };
  171. struct csio_scsi_level_data {
  172. enum csio_scsi_lev level;
  173. struct csio_rnode *rnode;
  174. struct csio_lnode *lnode;
  175. uint64_t oslun;
  176. };
  177. static inline struct csio_ioreq *
  178. csio_get_scsi_ioreq(struct csio_scsim *scm)
  179. {
  180. struct csio_sm *req;
  181. if (likely(!list_empty(&scm->ioreq_freelist))) {
  182. req = list_first_entry(&scm->ioreq_freelist,
  183. struct csio_sm, sm_list);
  184. list_del_init(&req->sm_list);
  185. CSIO_DEC_STATS(scm, n_free_ioreq);
  186. return (struct csio_ioreq *)req;
  187. } else
  188. return NULL;
  189. }
  190. static inline void
  191. csio_put_scsi_ioreq(struct csio_scsim *scm, struct csio_ioreq *ioreq)
  192. {
  193. list_add_tail(&ioreq->sm.sm_list, &scm->ioreq_freelist);
  194. CSIO_INC_STATS(scm, n_free_ioreq);
  195. }
  196. static inline void
  197. csio_put_scsi_ioreq_list(struct csio_scsim *scm, struct list_head *reqlist,
  198. int n)
  199. {
  200. list_splice_init(reqlist, &scm->ioreq_freelist);
  201. scm->stats.n_free_ioreq += n;
  202. }
  203. static inline struct csio_dma_buf *
  204. csio_get_scsi_ddp(struct csio_scsim *scm)
  205. {
  206. struct csio_dma_buf *ddp;
  207. if (likely(!list_empty(&scm->ddp_freelist))) {
  208. ddp = list_first_entry(&scm->ddp_freelist,
  209. struct csio_dma_buf, list);
  210. list_del_init(&ddp->list);
  211. CSIO_DEC_STATS(scm, n_free_ddp);
  212. return ddp;
  213. } else
  214. return NULL;
  215. }
  216. static inline void
  217. csio_put_scsi_ddp(struct csio_scsim *scm, struct csio_dma_buf *ddp)
  218. {
  219. list_add_tail(&ddp->list, &scm->ddp_freelist);
  220. CSIO_INC_STATS(scm, n_free_ddp);
  221. }
  222. static inline void
  223. csio_put_scsi_ddp_list(struct csio_scsim *scm, struct list_head *reqlist,
  224. int n)
  225. {
  226. list_splice_tail_init(reqlist, &scm->ddp_freelist);
  227. scm->stats.n_free_ddp += n;
  228. }
  229. static inline void
  230. csio_scsi_completed(struct csio_ioreq *ioreq, struct list_head *cbfn_q)
  231. {
  232. csio_post_event(&ioreq->sm, CSIO_SCSIE_COMPLETED);
  233. if (csio_list_deleted(&ioreq->sm.sm_list))
  234. list_add_tail(&ioreq->sm.sm_list, cbfn_q);
  235. }
  236. static inline void
  237. csio_scsi_aborted(struct csio_ioreq *ioreq, struct list_head *cbfn_q)
  238. {
  239. csio_post_event(&ioreq->sm, CSIO_SCSIE_ABORTED);
  240. list_add_tail(&ioreq->sm.sm_list, cbfn_q);
  241. }
  242. static inline void
  243. csio_scsi_closed(struct csio_ioreq *ioreq, struct list_head *cbfn_q)
  244. {
  245. csio_post_event(&ioreq->sm, CSIO_SCSIE_CLOSED);
  246. list_add_tail(&ioreq->sm.sm_list, cbfn_q);
  247. }
  248. static inline void
  249. csio_scsi_drvcleanup(struct csio_ioreq *ioreq)
  250. {
  251. csio_post_event(&ioreq->sm, CSIO_SCSIE_DRVCLEANUP);
  252. }
  253. /*
  254. * csio_scsi_start_io - Kick starts the IO SM.
  255. * @req: io request SM.
  256. *
  257. * needs to be called with lock held.
  258. */
  259. static inline int
  260. csio_scsi_start_io(struct csio_ioreq *ioreq)
  261. {
  262. csio_post_event(&ioreq->sm, CSIO_SCSIE_START_IO);
  263. return ioreq->drv_status;
  264. }
  265. /*
  266. * csio_scsi_start_tm - Kicks off the Task management IO SM.
  267. * @req: io request SM.
  268. *
  269. * needs to be called with lock held.
  270. */
  271. static inline int
  272. csio_scsi_start_tm(struct csio_ioreq *ioreq)
  273. {
  274. csio_post_event(&ioreq->sm, CSIO_SCSIE_START_TM);
  275. return ioreq->drv_status;
  276. }
  277. /*
  278. * csio_scsi_abort - Abort an IO request
  279. * @req: io request SM.
  280. *
  281. * needs to be called with lock held.
  282. */
  283. static inline int
  284. csio_scsi_abort(struct csio_ioreq *ioreq)
  285. {
  286. csio_post_event(&ioreq->sm, CSIO_SCSIE_ABORT);
  287. return ioreq->drv_status;
  288. }
  289. /*
  290. * csio_scsi_close - Close an IO request
  291. * @req: io request SM.
  292. *
  293. * needs to be called with lock held.
  294. */
  295. static inline int
  296. csio_scsi_close(struct csio_ioreq *ioreq)
  297. {
  298. csio_post_event(&ioreq->sm, CSIO_SCSIE_CLOSE);
  299. return ioreq->drv_status;
  300. }
  301. void csio_scsi_cleanup_io_q(struct csio_scsim *, struct list_head *);
  302. int csio_scsim_cleanup_io(struct csio_scsim *, bool abort);
  303. int csio_scsim_cleanup_io_lnode(struct csio_scsim *,
  304. struct csio_lnode *);
  305. struct csio_ioreq *csio_scsi_cmpl_handler(struct csio_hw *, void *, uint32_t,
  306. struct csio_fl_dma_buf *,
  307. void *, uint8_t **);
  308. int csio_scsi_qconfig(struct csio_hw *);
  309. int csio_scsim_init(struct csio_scsim *, struct csio_hw *);
  310. void csio_scsim_exit(struct csio_scsim *);
  311. #endif /* __CSIO_SCSI_H__ */