/drivers/scsi/bfa/bfad_im.h

http://github.com/mirrors/linux · C Header · 211 lines · 157 code · 26 blank · 28 comment · 7 complexity · 7877a7c51954881fa18e144861c50339 MD5 · raw file

  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. struct bfad_itnim_data_s {
  39. struct bfad_itnim_s *itnim;
  40. };
  41. struct bfad_im_port_s {
  42. struct bfad_s *bfad;
  43. struct bfad_port_s *port;
  44. struct work_struct port_delete_work;
  45. int idr_id;
  46. u16 cur_scsi_id;
  47. u16 flags;
  48. struct list_head binding_list;
  49. struct Scsi_Host *shost;
  50. struct list_head itnim_mapped_list;
  51. struct fc_vport *fc_vport;
  52. };
  53. struct bfad_im_port_pointer {
  54. struct bfad_im_port_s *p;
  55. };
  56. static inline struct bfad_im_port_s *bfad_get_im_port(struct Scsi_Host *host)
  57. {
  58. struct bfad_im_port_pointer *im_portp = shost_priv(host);
  59. return im_portp->p;
  60. }
  61. enum bfad_itnim_state {
  62. ITNIM_STATE_NONE,
  63. ITNIM_STATE_ONLINE,
  64. ITNIM_STATE_OFFLINE_PENDING,
  65. ITNIM_STATE_OFFLINE,
  66. ITNIM_STATE_TIMEOUT,
  67. ITNIM_STATE_FREE,
  68. };
  69. /*
  70. * Per itnim data structure
  71. */
  72. struct bfad_itnim_s {
  73. struct list_head list_entry;
  74. struct bfa_fcs_itnim_s fcs_itnim;
  75. struct work_struct itnim_work;
  76. u32 flags;
  77. enum bfad_itnim_state state;
  78. struct bfad_im_s *im;
  79. struct bfad_im_port_s *im_port;
  80. struct bfad_rport_s *drv_rport;
  81. struct fc_rport *fc_rport;
  82. struct bfa_itnim_s *bfa_itnim;
  83. u16 scsi_tgt_id;
  84. u16 channel;
  85. u16 queue_work;
  86. unsigned long last_ramp_up_time;
  87. unsigned long last_queue_full_time;
  88. };
  89. enum bfad_binding_type {
  90. FCP_PWWN_BINDING = 0x1,
  91. FCP_NWWN_BINDING = 0x2,
  92. FCP_FCID_BINDING = 0x3,
  93. };
  94. struct bfad_fcp_binding {
  95. struct list_head list_entry;
  96. enum bfad_binding_type binding_type;
  97. u16 scsi_target_id;
  98. u32 fc_id;
  99. wwn_t nwwn;
  100. wwn_t pwwn;
  101. };
  102. struct bfad_im_s {
  103. struct bfad_s *bfad;
  104. struct workqueue_struct *drv_workq;
  105. char drv_workq_name[KOBJ_NAME_LEN];
  106. struct work_struct aen_im_notify_work;
  107. };
  108. #define bfad_get_aen_entry(_drv, _entry) do { \
  109. unsigned long _flags; \
  110. spin_lock_irqsave(&(_drv)->bfad_aen_spinlock, _flags); \
  111. bfa_q_deq(&(_drv)->free_aen_q, &(_entry)); \
  112. if (_entry) \
  113. list_add_tail(&(_entry)->qe, &(_drv)->active_aen_q); \
  114. spin_unlock_irqrestore(&(_drv)->bfad_aen_spinlock, _flags); \
  115. } while (0)
  116. /* post fc_host vendor event */
  117. static inline void bfad_im_post_vendor_event(struct bfa_aen_entry_s *entry,
  118. struct bfad_s *drv, int cnt,
  119. enum bfa_aen_category cat,
  120. int evt)
  121. {
  122. struct timespec64 ts;
  123. ktime_get_real_ts64(&ts);
  124. /*
  125. * 'unsigned long aen_tv_sec' overflows in y2106 on 32-bit
  126. * architectures, or in 2038 if user space interprets it
  127. * as 'signed'.
  128. */
  129. entry->aen_tv_sec = ts.tv_sec;
  130. entry->aen_tv_usec = ts.tv_nsec / NSEC_PER_USEC;
  131. entry->bfad_num = drv->inst_no;
  132. entry->seq_num = cnt;
  133. entry->aen_category = cat;
  134. entry->aen_type = evt;
  135. if (drv->bfad_flags & BFAD_FC4_PROBE_DONE)
  136. queue_work(drv->im->drv_workq, &drv->im->aen_im_notify_work);
  137. }
  138. struct Scsi_Host *bfad_scsi_host_alloc(struct bfad_im_port_s *im_port,
  139. struct bfad_s *);
  140. bfa_status_t bfad_thread_workq(struct bfad_s *bfad);
  141. void bfad_destroy_workq(struct bfad_im_s *im);
  142. void bfad_fc_host_init(struct bfad_im_port_s *im_port);
  143. void bfad_scsi_host_free(struct bfad_s *bfad,
  144. struct bfad_im_port_s *im_port);
  145. void bfad_ramp_up_qdepth(struct bfad_itnim_s *itnim,
  146. struct scsi_device *sdev);
  147. void bfad_handle_qfull(struct bfad_itnim_s *itnim, struct scsi_device *sdev);
  148. struct bfad_itnim_s *bfad_get_itnim(struct bfad_im_port_s *im_port, int id);
  149. extern struct scsi_host_template bfad_im_scsi_host_template;
  150. extern struct scsi_host_template bfad_im_vport_template;
  151. extern struct fc_function_template bfad_im_fc_function_template;
  152. extern struct fc_function_template bfad_im_vport_fc_function_template;
  153. extern struct scsi_transport_template *bfad_im_scsi_transport_template;
  154. extern struct scsi_transport_template *bfad_im_scsi_vport_transport_template;
  155. extern struct device_attribute *bfad_im_host_attrs[];
  156. extern struct device_attribute *bfad_im_vport_attrs[];
  157. irqreturn_t bfad_intx(int irq, void *dev_id);
  158. int bfad_im_bsg_request(struct bsg_job *job);
  159. int bfad_im_bsg_timeout(struct bsg_job *job);
  160. /*
  161. * Macro to set the SCSI device sdev_bflags - sdev_bflags are used by the
  162. * SCSI mid-layer to choose LUN Scanning mode REPORT_LUNS vs. Sequential Scan
  163. *
  164. * Internally iterate's over all the ITNIM's part of the im_port & set's the
  165. * sdev_bflags for the scsi_device associated with LUN #0.
  166. */
  167. #define bfad_reset_sdev_bflags(__im_port, __lunmask_cfg) do { \
  168. struct scsi_device *__sdev = NULL; \
  169. struct bfad_itnim_s *__itnim = NULL; \
  170. u32 scan_flags = BLIST_NOREPORTLUN | BLIST_SPARSELUN; \
  171. list_for_each_entry(__itnim, &((__im_port)->itnim_mapped_list), \
  172. list_entry) { \
  173. __sdev = scsi_device_lookup((__im_port)->shost, \
  174. __itnim->channel, \
  175. __itnim->scsi_tgt_id, 0); \
  176. if (__sdev) { \
  177. if ((__lunmask_cfg) == BFA_TRUE) \
  178. __sdev->sdev_bflags |= scan_flags; \
  179. else \
  180. __sdev->sdev_bflags &= ~scan_flags; \
  181. scsi_device_put(__sdev); \
  182. } \
  183. } \
  184. } while (0)
  185. #endif