bfad_im.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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 __BFAD_IM_H__
  11. #define __BFAD_IM_H__
  12. #include "bfa_fcs.h"
  13. #define FCPI_NAME " fcpim"
  14. #ifndef KOBJ_NAME_LEN
  15. #define KOBJ_NAME_LEN 20
  16. #endif
  17. bfa_status_t bfad_im_module_init(void);
  18. void bfad_im_module_exit(void);
  19. bfa_status_t bfad_im_probe(struct bfad_s *bfad);
  20. void bfad_im_probe_undo(struct bfad_s *bfad);
  21. bfa_status_t bfad_im_port_new(struct bfad_s *bfad, struct bfad_port_s *port);
  22. void bfad_im_port_delete(struct bfad_s *bfad, struct bfad_port_s *port);
  23. void bfad_im_port_clean(struct bfad_im_port_s *im_port);
  24. int bfad_im_scsi_host_alloc(struct bfad_s *bfad,
  25. struct bfad_im_port_s *im_port, struct device *dev);
  26. void bfad_im_scsi_host_free(struct bfad_s *bfad,
  27. struct bfad_im_port_s *im_port);
  28. u32 bfad_im_supported_speeds(struct bfa_s *bfa);
  29. #define MAX_FCP_TARGET 1024
  30. #define MAX_FCP_LUN 16384
  31. #define BFAD_TARGET_RESET_TMO 60
  32. #define BFAD_LUN_RESET_TMO 60
  33. #define BFA_QUEUE_FULL_RAMP_UP_TIME 120
  34. /*
  35. * itnim flags
  36. */
  37. #define IO_DONE_BIT 0
  38. /**
  39. * struct bfad_cmd_priv - private data per SCSI command.
  40. * @status: Lowest bit represents IO_DONE. The next seven bits hold a value of
  41. * type enum bfi_tskim_status.
  42. * @wq: Wait queue used to wait for completion of an operation.
  43. */
  44. struct bfad_cmd_priv {
  45. unsigned long status;
  46. wait_queue_head_t *wq;
  47. };
  48. static inline struct bfad_cmd_priv *bfad_priv(struct scsi_cmnd *cmd)
  49. {
  50. return scsi_cmd_priv(cmd);
  51. }
  52. struct bfad_itnim_data_s {
  53. struct bfad_itnim_s *itnim;
  54. };
  55. struct bfad_im_port_s {
  56. struct bfad_s *bfad;
  57. struct bfad_port_s *port;
  58. struct work_struct port_delete_work;
  59. int idr_id;
  60. u16 cur_scsi_id;
  61. u16 flags;
  62. struct list_head binding_list;
  63. struct Scsi_Host *shost;
  64. struct list_head itnim_mapped_list;
  65. struct fc_vport *fc_vport;
  66. };
  67. struct bfad_im_port_pointer {
  68. struct bfad_im_port_s *p;
  69. };
  70. static inline struct bfad_im_port_s *bfad_get_im_port(struct Scsi_Host *host)
  71. {
  72. struct bfad_im_port_pointer *im_portp = shost_priv(host);
  73. return im_portp->p;
  74. }
  75. enum bfad_itnim_state {
  76. ITNIM_STATE_NONE,
  77. ITNIM_STATE_ONLINE,
  78. ITNIM_STATE_OFFLINE_PENDING,
  79. ITNIM_STATE_OFFLINE,
  80. ITNIM_STATE_TIMEOUT,
  81. ITNIM_STATE_FREE,
  82. };
  83. /*
  84. * Per itnim data structure
  85. */
  86. struct bfad_itnim_s {
  87. struct list_head list_entry;
  88. struct bfa_fcs_itnim_s fcs_itnim;
  89. struct work_struct itnim_work;
  90. u32 flags;
  91. enum bfad_itnim_state state;
  92. struct bfad_im_s *im;
  93. struct bfad_im_port_s *im_port;
  94. struct bfad_rport_s *drv_rport;
  95. struct fc_rport *fc_rport;
  96. struct bfa_itnim_s *bfa_itnim;
  97. u16 scsi_tgt_id;
  98. u16 channel;
  99. u16 queue_work;
  100. unsigned long last_ramp_up_time;
  101. unsigned long last_queue_full_time;
  102. };
  103. enum bfad_binding_type {
  104. FCP_PWWN_BINDING = 0x1,
  105. FCP_NWWN_BINDING = 0x2,
  106. FCP_FCID_BINDING = 0x3,
  107. };
  108. struct bfad_fcp_binding {
  109. struct list_head list_entry;
  110. enum bfad_binding_type binding_type;
  111. u16 scsi_target_id;
  112. u32 fc_id;
  113. wwn_t nwwn;
  114. wwn_t pwwn;
  115. };
  116. struct bfad_im_s {
  117. struct bfad_s *bfad;
  118. struct workqueue_struct *drv_workq;
  119. char drv_workq_name[KOBJ_NAME_LEN];
  120. struct work_struct aen_im_notify_work;
  121. };
  122. #define bfad_get_aen_entry(_drv, _entry) do { \
  123. unsigned long _flags; \
  124. spin_lock_irqsave(&(_drv)->bfad_aen_spinlock, _flags); \
  125. bfa_q_deq(&(_drv)->free_aen_q, &(_entry)); \
  126. if (_entry) \
  127. list_add_tail(&(_entry)->qe, &(_drv)->active_aen_q); \
  128. spin_unlock_irqrestore(&(_drv)->bfad_aen_spinlock, _flags); \
  129. } while (0)
  130. /* post fc_host vendor event */
  131. static inline void bfad_im_post_vendor_event(struct bfa_aen_entry_s *entry,
  132. struct bfad_s *drv, int cnt,
  133. enum bfa_aen_category cat,
  134. int evt)
  135. {
  136. struct timespec64 ts;
  137. ktime_get_real_ts64(&ts);
  138. /*
  139. * 'unsigned long aen_tv_sec' overflows in y2106 on 32-bit
  140. * architectures, or in 2038 if user space interprets it
  141. * as 'signed'.
  142. */
  143. entry->aen_tv_sec = ts.tv_sec;
  144. entry->aen_tv_usec = ts.tv_nsec / NSEC_PER_USEC;
  145. entry->bfad_num = drv->inst_no;
  146. entry->seq_num = cnt;
  147. entry->aen_category = cat;
  148. entry->aen_type = evt;
  149. if (drv->bfad_flags & BFAD_FC4_PROBE_DONE)
  150. queue_work(drv->im->drv_workq, &drv->im->aen_im_notify_work);
  151. }
  152. struct Scsi_Host *bfad_scsi_host_alloc(struct bfad_im_port_s *im_port,
  153. struct bfad_s *);
  154. bfa_status_t bfad_thread_workq(struct bfad_s *bfad);
  155. void bfad_destroy_workq(struct bfad_im_s *im);
  156. void bfad_fc_host_init(struct bfad_im_port_s *im_port);
  157. void bfad_scsi_host_free(struct bfad_s *bfad,
  158. struct bfad_im_port_s *im_port);
  159. void bfad_ramp_up_qdepth(struct bfad_itnim_s *itnim,
  160. struct scsi_device *sdev);
  161. void bfad_handle_qfull(struct bfad_itnim_s *itnim, struct scsi_device *sdev);
  162. struct bfad_itnim_s *bfad_get_itnim(struct bfad_im_port_s *im_port, int id);
  163. extern struct scsi_host_template bfad_im_scsi_host_template;
  164. extern struct scsi_host_template bfad_im_vport_template;
  165. extern struct fc_function_template bfad_im_fc_function_template;
  166. extern struct fc_function_template bfad_im_vport_fc_function_template;
  167. extern struct scsi_transport_template *bfad_im_scsi_transport_template;
  168. extern struct scsi_transport_template *bfad_im_scsi_vport_transport_template;
  169. extern const struct attribute_group *bfad_im_host_groups[];
  170. extern const struct attribute_group *bfad_im_vport_groups[];
  171. irqreturn_t bfad_intx(int irq, void *dev_id);
  172. int bfad_im_bsg_request(struct bsg_job *job);
  173. int bfad_im_bsg_timeout(struct bsg_job *job);
  174. /*
  175. * Macro to set the SCSI device sdev_bflags - sdev_bflags are used by the
  176. * SCSI mid-layer to choose LUN Scanning mode REPORT_LUNS vs. Sequential Scan
  177. *
  178. * Internally iterate's over all the ITNIM's part of the im_port & set's the
  179. * sdev_bflags for the scsi_device associated with LUN #0.
  180. */
  181. #define bfad_reset_sdev_bflags(__im_port, __lunmask_cfg) do { \
  182. struct scsi_device *__sdev = NULL; \
  183. struct bfad_itnim_s *__itnim = NULL; \
  184. u32 scan_flags = BLIST_NOREPORTLUN | BLIST_SPARSELUN; \
  185. list_for_each_entry(__itnim, &((__im_port)->itnim_mapped_list), \
  186. list_entry) { \
  187. __sdev = scsi_device_lookup((__im_port)->shost, \
  188. __itnim->channel, \
  189. __itnim->scsi_tgt_id, 0); \
  190. if (__sdev) { \
  191. if ((__lunmask_cfg) == BFA_TRUE) \
  192. __sdev->sdev_bflags |= scan_flags; \
  193. else \
  194. __sdev->sdev_bflags &= ~scan_flags; \
  195. scsi_device_put(__sdev); \
  196. } \
  197. } \
  198. } while (0)
  199. #endif