bfad_im.h 6.0 KB

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