bfa_fcpim.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. /*
  2. * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
  3. * All rights reserved
  4. * www.brocade.com
  5. *
  6. * Linux driver for Brocade Fibre Channel Host Bus Adapter.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License (GPL) Version 2 as
  10. * published by the Free Software Foundation
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. */
  17. #ifndef __BFA_FCPIM_H__
  18. #define __BFA_FCPIM_H__
  19. #include "bfa.h"
  20. #include "bfa_svc.h"
  21. #include "bfi_ms.h"
  22. #include "bfa_defs_svc.h"
  23. #include "bfa_cs.h"
  24. /* FCP module related definitions */
  25. #define BFA_IO_MAX 2000
  26. #define BFA_FWTIO_MAX 0
  27. struct bfa_fcp_mod_s;
  28. struct bfa_iotag_s {
  29. struct list_head qe; /* queue element */
  30. u16 tag; /* FW IO tag */
  31. };
  32. struct bfa_itn_s {
  33. bfa_isr_func_t isr;
  34. };
  35. void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
  36. void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
  37. void bfa_itn_isr(struct bfa_s *bfa, struct bfi_msg_s *m);
  38. void bfa_iotag_attach(struct bfa_fcp_mod_s *fcp, struct bfa_meminfo_s *minfo);
  39. void bfa_fcp_res_recfg(struct bfa_s *bfa, u16 num_ioim_fw);
  40. #define BFA_FCP_MOD(_hal) (&(_hal)->modules.fcp_mod)
  41. #define BFA_IOTAG_FROM_TAG(_fcp, _tag) \
  42. (&(_fcp)->iotag_arr[(_tag & BFA_IOIM_IOTAG_MASK)])
  43. #define BFA_ITN_FROM_TAG(_fcp, _tag) \
  44. ((_fcp)->itn_arr + ((_tag) & ((_fcp)->num_itns - 1)))
  45. #define BFA_SNSINFO_FROM_TAG(_fcp, _tag) \
  46. (((u8 *)(_fcp)->snsbase.kva) + (_tag * BFI_IOIM_SNSLEN))
  47. #define BFA_ITNIM_MIN 32
  48. #define BFA_ITNIM_MAX 1024
  49. #define BFA_IOIM_MIN 8
  50. #define BFA_IOIM_MAX 2000
  51. #define BFA_TSKIM_MIN 4
  52. #define BFA_TSKIM_MAX 512
  53. #define BFA_FCPIM_PATHTOV_DEF (30 * 1000) /* in millisecs */
  54. #define BFA_FCPIM_PATHTOV_MAX (90 * 1000) /* in millisecs */
  55. #define bfa_itnim_ioprofile_update(__itnim, __index) \
  56. (__itnim->ioprofile.iocomps[__index]++)
  57. #define BFA_IOIM_RETRY_TAG_OFFSET 11
  58. #define BFA_IOIM_IOTAG_MASK 0x07ff /* 2K IOs */
  59. #define BFA_IOIM_RETRY_MAX 7
  60. /* Buckets are are 512 bytes to 2MB */
  61. static inline u32
  62. bfa_ioim_get_index(u32 n) {
  63. int pos = 0;
  64. if (n >= (1UL)<<22)
  65. return BFA_IOBUCKET_MAX - 1;
  66. n >>= 8;
  67. if (n >= (1UL)<<16)
  68. n >>= 16; pos += 16;
  69. if (n >= 1 << 8)
  70. n >>= 8; pos += 8;
  71. if (n >= 1 << 4)
  72. n >>= 4; pos += 4;
  73. if (n >= 1 << 2)
  74. n >>= 2; pos += 2;
  75. if (n >= 1 << 1)
  76. pos += 1;
  77. return (n == 0) ? (0) : pos;
  78. }
  79. /*
  80. * forward declarations
  81. */
  82. struct bfa_ioim_s;
  83. struct bfa_tskim_s;
  84. struct bfad_ioim_s;
  85. struct bfad_tskim_s;
  86. typedef void (*bfa_fcpim_profile_t) (struct bfa_ioim_s *ioim);
  87. struct bfa_fcpim_s {
  88. struct bfa_s *bfa;
  89. struct bfa_fcp_mod_s *fcp;
  90. struct bfa_itnim_s *itnim_arr;
  91. struct bfa_ioim_s *ioim_arr;
  92. struct bfa_ioim_sp_s *ioim_sp_arr;
  93. struct bfa_tskim_s *tskim_arr;
  94. int num_itnims;
  95. int num_tskim_reqs;
  96. u32 path_tov;
  97. u16 q_depth;
  98. u8 reqq; /* Request queue to be used */
  99. u8 rsvd;
  100. struct list_head itnim_q; /* queue of active itnim */
  101. struct list_head ioim_resfree_q; /* IOs waiting for f/w */
  102. struct list_head ioim_comp_q; /* IO global comp Q */
  103. struct list_head tskim_free_q;
  104. struct list_head tskim_unused_q; /* Unused tskim Q */
  105. u32 ios_active; /* current active IOs */
  106. u32 delay_comp;
  107. struct bfa_fcpim_del_itn_stats_s del_itn_stats;
  108. bfa_boolean_t ioredirect;
  109. bfa_boolean_t io_profile;
  110. u32 io_profile_start_time;
  111. bfa_fcpim_profile_t profile_comp;
  112. bfa_fcpim_profile_t profile_start;
  113. };
  114. struct bfa_fcp_mod_s {
  115. struct bfa_s *bfa;
  116. struct list_head iotag_ioim_free_q; /* free IO resources */
  117. struct list_head iotag_tio_free_q; /* free IO resources */
  118. struct list_head iotag_unused_q; /* unused IO resources*/
  119. struct bfa_iotag_s *iotag_arr;
  120. struct bfa_itn_s *itn_arr;
  121. int num_ioim_reqs;
  122. int num_fwtio_reqs;
  123. int num_itns;
  124. struct bfa_dma_s snsbase;
  125. struct bfa_fcpim_s fcpim;
  126. };
  127. /*
  128. * BFA IO (initiator mode)
  129. */
  130. struct bfa_ioim_s {
  131. struct list_head qe; /* queue elememt */
  132. bfa_sm_t sm; /* BFA ioim state machine */
  133. struct bfa_s *bfa; /* BFA module */
  134. struct bfa_fcpim_s *fcpim; /* parent fcpim module */
  135. struct bfa_itnim_s *itnim; /* i-t-n nexus for this IO */
  136. struct bfad_ioim_s *dio; /* driver IO handle */
  137. u16 iotag; /* FWI IO tag */
  138. u16 abort_tag; /* unqiue abort request tag */
  139. u16 nsges; /* number of SG elements */
  140. u16 nsgpgs; /* number of SG pages */
  141. struct bfa_sgpg_s *sgpg; /* first SG page */
  142. struct list_head sgpg_q; /* allocated SG pages */
  143. struct bfa_cb_qe_s hcb_qe; /* bfa callback qelem */
  144. bfa_cb_cbfn_t io_cbfn; /* IO completion handler */
  145. struct bfa_ioim_sp_s *iosp; /* slow-path IO handling */
  146. u8 reqq; /* Request queue for I/O */
  147. u64 start_time; /* IO's Profile start val */
  148. };
  149. struct bfa_ioim_sp_s {
  150. struct bfi_msg_s comp_rspmsg; /* IO comp f/w response */
  151. struct bfa_sgpg_wqe_s sgpg_wqe; /* waitq elem for sgpg */
  152. struct bfa_reqq_wait_s reqq_wait; /* to wait for room in reqq */
  153. bfa_boolean_t abort_explicit; /* aborted by OS */
  154. struct bfa_tskim_s *tskim; /* Relevant TM cmd */
  155. };
  156. /*
  157. * BFA Task management command (initiator mode)
  158. */
  159. struct bfa_tskim_s {
  160. struct list_head qe;
  161. bfa_sm_t sm;
  162. struct bfa_s *bfa; /* BFA module */
  163. struct bfa_fcpim_s *fcpim; /* parent fcpim module */
  164. struct bfa_itnim_s *itnim; /* i-t-n nexus for this IO */
  165. struct bfad_tskim_s *dtsk; /* driver task mgmt cmnd */
  166. bfa_boolean_t notify; /* notify itnim on TM comp */
  167. struct scsi_lun lun; /* lun if applicable */
  168. enum fcp_tm_cmnd tm_cmnd; /* task management command */
  169. u16 tsk_tag; /* FWI IO tag */
  170. u8 tsecs; /* timeout in seconds */
  171. struct bfa_reqq_wait_s reqq_wait; /* to wait for room in reqq */
  172. struct list_head io_q; /* queue of affected IOs */
  173. struct bfa_wc_s wc; /* waiting counter */
  174. struct bfa_cb_qe_s hcb_qe; /* bfa callback qelem */
  175. enum bfi_tskim_status tsk_status; /* TM status */
  176. };
  177. /*
  178. * BFA i-t-n (initiator mode)
  179. */
  180. struct bfa_itnim_s {
  181. struct list_head qe; /* queue element */
  182. bfa_sm_t sm; /* i-t-n im BFA state machine */
  183. struct bfa_s *bfa; /* bfa instance */
  184. struct bfa_rport_s *rport; /* bfa rport */
  185. void *ditn; /* driver i-t-n structure */
  186. struct bfi_mhdr_s mhdr; /* pre-built mhdr */
  187. u8 msg_no; /* itnim/rport firmware handle */
  188. u8 reqq; /* CQ for requests */
  189. struct bfa_cb_qe_s hcb_qe; /* bfa callback qelem */
  190. struct list_head pending_q; /* queue of pending IO requests */
  191. struct list_head io_q; /* queue of active IO requests */
  192. struct list_head io_cleanup_q; /* IO being cleaned up */
  193. struct list_head tsk_q; /* queue of active TM commands */
  194. struct list_head delay_comp_q; /* queue of failed inflight cmds */
  195. bfa_boolean_t seq_rec; /* SQER supported */
  196. bfa_boolean_t is_online; /* itnim is ONLINE for IO */
  197. bfa_boolean_t iotov_active; /* IO TOV timer is active */
  198. struct bfa_wc_s wc; /* waiting counter */
  199. struct bfa_timer_s timer; /* pending IO TOV */
  200. struct bfa_reqq_wait_s reqq_wait; /* to wait for room in reqq */
  201. struct bfa_fcpim_s *fcpim; /* fcpim module */
  202. struct bfa_itnim_iostats_s stats;
  203. struct bfa_itnim_ioprofile_s ioprofile;
  204. };
  205. #define bfa_itnim_is_online(_itnim) ((_itnim)->is_online)
  206. #define BFA_FCPIM(_hal) (&(_hal)->modules.fcp_mod.fcpim)
  207. #define BFA_IOIM_TAG_2_ID(_iotag) ((_iotag) & BFA_IOIM_IOTAG_MASK)
  208. #define BFA_IOIM_FROM_TAG(_fcpim, _iotag) \
  209. (&fcpim->ioim_arr[(_iotag & BFA_IOIM_IOTAG_MASK)])
  210. #define BFA_TSKIM_FROM_TAG(_fcpim, _tmtag) \
  211. (&fcpim->tskim_arr[_tmtag & (fcpim->num_tskim_reqs - 1)])
  212. #define bfa_io_profile_start_time(_bfa) \
  213. ((_bfa)->modules.fcp_mod.fcpim.io_profile_start_time)
  214. #define bfa_fcpim_get_io_profile(_bfa) \
  215. ((_bfa)->modules.fcp_mod.fcpim.io_profile)
  216. #define bfa_ioim_update_iotag(__ioim) do { \
  217. uint16_t k = (__ioim)->iotag >> BFA_IOIM_RETRY_TAG_OFFSET; \
  218. k++; (__ioim)->iotag &= BFA_IOIM_IOTAG_MASK; \
  219. (__ioim)->iotag |= k << BFA_IOIM_RETRY_TAG_OFFSET; \
  220. } while (0)
  221. static inline bfa_boolean_t
  222. bfa_ioim_maxretry_reached(struct bfa_ioim_s *ioim)
  223. {
  224. uint16_t k = ioim->iotag >> BFA_IOIM_RETRY_TAG_OFFSET;
  225. if (k < BFA_IOIM_RETRY_MAX)
  226. return BFA_FALSE;
  227. return BFA_TRUE;
  228. }
  229. /*
  230. * function prototypes
  231. */
  232. void bfa_ioim_attach(struct bfa_fcpim_s *fcpim,
  233. struct bfa_meminfo_s *minfo);
  234. void bfa_ioim_isr(struct bfa_s *bfa, struct bfi_msg_s *msg);
  235. void bfa_ioim_good_comp_isr(struct bfa_s *bfa,
  236. struct bfi_msg_s *msg);
  237. void bfa_ioim_cleanup(struct bfa_ioim_s *ioim);
  238. void bfa_ioim_cleanup_tm(struct bfa_ioim_s *ioim,
  239. struct bfa_tskim_s *tskim);
  240. void bfa_ioim_iocdisable(struct bfa_ioim_s *ioim);
  241. void bfa_ioim_tov(struct bfa_ioim_s *ioim);
  242. void bfa_tskim_attach(struct bfa_fcpim_s *fcpim,
  243. struct bfa_meminfo_s *minfo);
  244. void bfa_tskim_isr(struct bfa_s *bfa, struct bfi_msg_s *msg);
  245. void bfa_tskim_iodone(struct bfa_tskim_s *tskim);
  246. void bfa_tskim_iocdisable(struct bfa_tskim_s *tskim);
  247. void bfa_tskim_cleanup(struct bfa_tskim_s *tskim);
  248. void bfa_tskim_res_recfg(struct bfa_s *bfa, u16 num_tskim_fw);
  249. void bfa_itnim_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *km_len,
  250. u32 *dm_len);
  251. void bfa_itnim_attach(struct bfa_fcpim_s *fcpim,
  252. struct bfa_meminfo_s *minfo);
  253. void bfa_itnim_iocdisable(struct bfa_itnim_s *itnim);
  254. void bfa_itnim_isr(struct bfa_s *bfa, struct bfi_msg_s *msg);
  255. void bfa_itnim_iodone(struct bfa_itnim_s *itnim);
  256. void bfa_itnim_tskdone(struct bfa_itnim_s *itnim);
  257. bfa_boolean_t bfa_itnim_hold_io(struct bfa_itnim_s *itnim);
  258. /*
  259. * bfa fcpim module API functions
  260. */
  261. void bfa_fcpim_path_tov_set(struct bfa_s *bfa, u16 path_tov);
  262. u16 bfa_fcpim_path_tov_get(struct bfa_s *bfa);
  263. u16 bfa_fcpim_qdepth_get(struct bfa_s *bfa);
  264. #define bfa_fcpim_ioredirect_enabled(__bfa) \
  265. (((struct bfa_fcpim_s *)(BFA_FCPIM(__bfa)))->ioredirect)
  266. #define bfa_fcpim_get_next_reqq(__bfa, __qid) \
  267. { \
  268. struct bfa_fcpim_s *__fcpim = BFA_FCPIM(__bfa); \
  269. __fcpim->reqq++; \
  270. __fcpim->reqq &= (BFI_IOC_MAX_CQS - 1); \
  271. *(__qid) = __fcpim->reqq; \
  272. }
  273. #define bfa_iocfc_map_msg_to_qid(__msg, __qid) \
  274. *(__qid) = (u8)((__msg) & (BFI_IOC_MAX_CQS - 1));
  275. /*
  276. * bfa itnim API functions
  277. */
  278. struct bfa_itnim_s *bfa_itnim_create(struct bfa_s *bfa,
  279. struct bfa_rport_s *rport, void *itnim);
  280. void bfa_itnim_delete(struct bfa_itnim_s *itnim);
  281. void bfa_itnim_online(struct bfa_itnim_s *itnim, bfa_boolean_t seq_rec);
  282. void bfa_itnim_offline(struct bfa_itnim_s *itnim);
  283. void bfa_itnim_clear_stats(struct bfa_itnim_s *itnim);
  284. bfa_status_t bfa_itnim_get_ioprofile(struct bfa_itnim_s *itnim,
  285. struct bfa_itnim_ioprofile_s *ioprofile);
  286. #define bfa_itnim_get_reqq(__ioim) (((struct bfa_ioim_s *)__ioim)->itnim->reqq)
  287. /*
  288. * BFA completion callback for bfa_itnim_online().
  289. */
  290. void bfa_cb_itnim_online(void *itnim);
  291. /*
  292. * BFA completion callback for bfa_itnim_offline().
  293. */
  294. void bfa_cb_itnim_offline(void *itnim);
  295. void bfa_cb_itnim_tov_begin(void *itnim);
  296. void bfa_cb_itnim_tov(void *itnim);
  297. /*
  298. * BFA notification to FCS/driver for second level error recovery.
  299. * Atleast one I/O request has timedout and target is unresponsive to
  300. * repeated abort requests. Second level error recovery should be initiated
  301. * by starting implicit logout and recovery procedures.
  302. */
  303. void bfa_cb_itnim_sler(void *itnim);
  304. /*
  305. * bfa ioim API functions
  306. */
  307. struct bfa_ioim_s *bfa_ioim_alloc(struct bfa_s *bfa,
  308. struct bfad_ioim_s *dio,
  309. struct bfa_itnim_s *itnim,
  310. u16 nsgles);
  311. void bfa_ioim_free(struct bfa_ioim_s *ioim);
  312. void bfa_ioim_start(struct bfa_ioim_s *ioim);
  313. bfa_status_t bfa_ioim_abort(struct bfa_ioim_s *ioim);
  314. void bfa_ioim_delayed_comp(struct bfa_ioim_s *ioim,
  315. bfa_boolean_t iotov);
  316. /*
  317. * I/O completion notification.
  318. *
  319. * @param[in] dio driver IO structure
  320. * @param[in] io_status IO completion status
  321. * @param[in] scsi_status SCSI status returned by target
  322. * @param[in] sns_len SCSI sense length, 0 if none
  323. * @param[in] sns_info SCSI sense data, if any
  324. * @param[in] residue Residual length
  325. *
  326. * @return None
  327. */
  328. void bfa_cb_ioim_done(void *bfad, struct bfad_ioim_s *dio,
  329. enum bfi_ioim_status io_status,
  330. u8 scsi_status, int sns_len,
  331. u8 *sns_info, s32 residue);
  332. /*
  333. * I/O good completion notification.
  334. */
  335. void bfa_cb_ioim_good_comp(void *bfad, struct bfad_ioim_s *dio);
  336. /*
  337. * I/O abort completion notification
  338. */
  339. void bfa_cb_ioim_abort(void *bfad, struct bfad_ioim_s *dio);
  340. /*
  341. * bfa tskim API functions
  342. */
  343. struct bfa_tskim_s *bfa_tskim_alloc(struct bfa_s *bfa,
  344. struct bfad_tskim_s *dtsk);
  345. void bfa_tskim_free(struct bfa_tskim_s *tskim);
  346. void bfa_tskim_start(struct bfa_tskim_s *tskim,
  347. struct bfa_itnim_s *itnim, struct scsi_lun lun,
  348. enum fcp_tm_cmnd tm, u8 t_secs);
  349. void bfa_cb_tskim_done(void *bfad, struct bfad_tskim_s *dtsk,
  350. enum bfi_tskim_status tsk_status);
  351. #endif /* __BFA_FCPIM_H__ */