bfad_im.h 6.1 KB

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