bfa_fcpim.h 14 KB

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