bfad_im.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /*
  2. * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
  3. * Copyright (c) 2014- QLogic Corporation.
  4. * All rights reserved
  5. * www.qlogic.com
  6. *
  7. * Linux driver for QLogic BR-series Fibre Channel Host Bus Adapter.
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License (GPL) Version 2 as
  11. * published by the Free Software Foundation
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. */
  18. #ifndef __BFAD_IM_H__
  19. #define __BFAD_IM_H__
  20. #include "bfa_fcs.h"
  21. #define FCPI_NAME " fcpim"
  22. #ifndef KOBJ_NAME_LEN
  23. #define KOBJ_NAME_LEN 20
  24. #endif
  25. bfa_status_t bfad_im_module_init(void);
  26. void bfad_im_module_exit(void);
  27. bfa_status_t bfad_im_probe(struct bfad_s *bfad);
  28. void bfad_im_probe_undo(struct bfad_s *bfad);
  29. bfa_status_t bfad_im_port_new(struct bfad_s *bfad, struct bfad_port_s *port);
  30. void bfad_im_port_delete(struct bfad_s *bfad, struct bfad_port_s *port);
  31. void bfad_im_port_clean(struct bfad_im_port_s *im_port);
  32. int bfad_im_scsi_host_alloc(struct bfad_s *bfad,
  33. struct bfad_im_port_s *im_port, struct device *dev);
  34. void bfad_im_scsi_host_free(struct bfad_s *bfad,
  35. struct bfad_im_port_s *im_port);
  36. u32 bfad_im_supported_speeds(struct bfa_s *bfa);
  37. #define MAX_FCP_TARGET 1024
  38. #define MAX_FCP_LUN 16384
  39. #define BFAD_TARGET_RESET_TMO 60
  40. #define BFAD_LUN_RESET_TMO 60
  41. #define BFA_QUEUE_FULL_RAMP_UP_TIME 120
  42. /*
  43. * itnim flags
  44. */
  45. #define IO_DONE_BIT 0
  46. struct bfad_itnim_data_s {
  47. struct bfad_itnim_s *itnim;
  48. };
  49. struct bfad_im_port_s {
  50. struct bfad_s *bfad;
  51. struct bfad_port_s *port;
  52. struct work_struct port_delete_work;
  53. int idr_id;
  54. u16 cur_scsi_id;
  55. u16 flags;
  56. struct list_head binding_list;
  57. struct Scsi_Host *shost;
  58. struct list_head itnim_mapped_list;
  59. struct fc_vport *fc_vport;
  60. };
  61. struct bfad_im_port_pointer {
  62. struct bfad_im_port_s *p;
  63. };
  64. static inline struct bfad_im_port_s *bfad_get_im_port(struct Scsi_Host *host)
  65. {
  66. struct bfad_im_port_pointer *im_portp = shost_priv(host);
  67. return im_portp->p;
  68. }
  69. enum bfad_itnim_state {
  70. ITNIM_STATE_NONE,
  71. ITNIM_STATE_ONLINE,
  72. ITNIM_STATE_OFFLINE_PENDING,
  73. ITNIM_STATE_OFFLINE,
  74. ITNIM_STATE_TIMEOUT,
  75. ITNIM_STATE_FREE,
  76. };
  77. /*
  78. * Per itnim data structure
  79. */
  80. struct bfad_itnim_s {
  81. struct list_head list_entry;
  82. struct bfa_fcs_itnim_s fcs_itnim;
  83. struct work_struct itnim_work;
  84. u32 flags;
  85. enum bfad_itnim_state state;
  86. struct bfad_im_s *im;
  87. struct bfad_im_port_s *im_port;
  88. struct bfad_rport_s *drv_rport;
  89. struct fc_rport *fc_rport;
  90. struct bfa_itnim_s *bfa_itnim;
  91. u16 scsi_tgt_id;
  92. u16 channel;
  93. u16 queue_work;
  94. unsigned long last_ramp_up_time;
  95. unsigned long last_queue_full_time;
  96. };
  97. enum bfad_binding_type {
  98. FCP_PWWN_BINDING = 0x1,
  99. FCP_NWWN_BINDING = 0x2,
  100. FCP_FCID_BINDING = 0x3,
  101. };
  102. struct bfad_fcp_binding {
  103. struct list_head list_entry;
  104. enum bfad_binding_type binding_type;
  105. u16 scsi_target_id;
  106. u32 fc_id;
  107. wwn_t nwwn;
  108. wwn_t pwwn;
  109. };
  110. struct bfad_im_s {
  111. struct bfad_s *bfad;
  112. struct workqueue_struct *drv_workq;
  113. char drv_workq_name[KOBJ_NAME_LEN];
  114. struct work_struct aen_im_notify_work;
  115. };
  116. #define bfad_get_aen_entry(_drv, _entry) do { \
  117. unsigned long _flags; \
  118. spin_lock_irqsave(&(_drv)->bfad_aen_spinlock, _flags); \
  119. bfa_q_deq(&(_drv)->free_aen_q, &(_entry)); \
  120. if (_entry) \
  121. list_add_tail(&(_entry)->qe, &(_drv)->active_aen_q); \
  122. spin_unlock_irqrestore(&(_drv)->bfad_aen_spinlock, _flags); \
  123. } while (0)
  124. /* post fc_host vendor event */
  125. static inline void bfad_im_post_vendor_event(struct bfa_aen_entry_s *entry,
  126. struct bfad_s *drv, int cnt,
  127. enum bfa_aen_category cat,
  128. int evt)
  129. {
  130. struct timespec64 ts;
  131. ktime_get_real_ts64(&ts);
  132. /*
  133. * 'unsigned long aen_tv_sec' overflows in y2106 on 32-bit
  134. * architectures, or in 2038 if user space interprets it
  135. * as 'signed'.
  136. */
  137. entry->aen_tv_sec = ts.tv_sec;
  138. entry->aen_tv_usec = ts.tv_nsec / NSEC_PER_USEC;
  139. entry->bfad_num = drv->inst_no;
  140. entry->seq_num = cnt;
  141. entry->aen_category = cat;
  142. entry->aen_type = evt;
  143. if (drv->bfad_flags & BFAD_FC4_PROBE_DONE)
  144. queue_work(drv->im->drv_workq, &drv->im->aen_im_notify_work);
  145. }
  146. struct Scsi_Host *bfad_scsi_host_alloc(struct bfad_im_port_s *im_port,
  147. struct bfad_s *);
  148. bfa_status_t bfad_thread_workq(struct bfad_s *bfad);
  149. void bfad_destroy_workq(struct bfad_im_s *im);
  150. void bfad_fc_host_init(struct bfad_im_port_s *im_port);
  151. void bfad_scsi_host_free(struct bfad_s *bfad,
  152. struct bfad_im_port_s *im_port);
  153. void bfad_ramp_up_qdepth(struct bfad_itnim_s *itnim,
  154. struct scsi_device *sdev);
  155. void bfad_handle_qfull(struct bfad_itnim_s *itnim, struct scsi_device *sdev);
  156. struct bfad_itnim_s *bfad_get_itnim(struct bfad_im_port_s *im_port, int id);
  157. extern struct scsi_host_template bfad_im_scsi_host_template;
  158. extern struct scsi_host_template bfad_im_vport_template;
  159. extern struct fc_function_template bfad_im_fc_function_template;
  160. extern struct fc_function_template bfad_im_vport_fc_function_template;
  161. extern struct scsi_transport_template *bfad_im_scsi_transport_template;
  162. extern struct scsi_transport_template *bfad_im_scsi_vport_transport_template;
  163. extern struct device_attribute *bfad_im_host_attrs[];
  164. extern struct device_attribute *bfad_im_vport_attrs[];
  165. irqreturn_t bfad_intx(int irq, void *dev_id);
  166. int bfad_im_bsg_request(struct bsg_job *job);
  167. int bfad_im_bsg_timeout(struct bsg_job *job);
  168. /*
  169. * Macro to set the SCSI device sdev_bflags - sdev_bflags are used by the
  170. * SCSI mid-layer to choose LUN Scanning mode REPORT_LUNS vs. Sequential Scan
  171. *
  172. * Internally iterate's over all the ITNIM's part of the im_port & set's the
  173. * sdev_bflags for the scsi_device associated with LUN #0.
  174. */
  175. #define bfad_reset_sdev_bflags(__im_port, __lunmask_cfg) do { \
  176. struct scsi_device *__sdev = NULL; \
  177. struct bfad_itnim_s *__itnim = NULL; \
  178. u32 scan_flags = BLIST_NOREPORTLUN | BLIST_SPARSELUN; \
  179. list_for_each_entry(__itnim, &((__im_port)->itnim_mapped_list), \
  180. list_entry) { \
  181. __sdev = scsi_device_lookup((__im_port)->shost, \
  182. __itnim->channel, \
  183. __itnim->scsi_tgt_id, 0); \
  184. if (__sdev) { \
  185. if ((__lunmask_cfg) == BFA_TRUE) \
  186. __sdev->sdev_bflags |= scan_flags; \
  187. else \
  188. __sdev->sdev_bflags &= ~scan_flags; \
  189. scsi_device_put(__sdev); \
  190. } \
  191. } \
  192. } while (0)
  193. #endif