bfad_im.h 6.1 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. u32 bfad_im_supported_speeds(struct bfa_s *bfa);
  36. #define MAX_FCP_TARGET 1024
  37. #define MAX_FCP_LUN 16384
  38. #define BFAD_TARGET_RESET_TMO 60
  39. #define BFAD_LUN_RESET_TMO 60
  40. #define ScsiResult(host_code, scsi_code) (((host_code) << 16) | scsi_code)
  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. 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. #define bfad_im_post_vendor_event(_entry, _drv, _cnt, _cat, _evt) do { \
  118. do_gettimeofday(&(_entry)->aen_tv); \
  119. (_entry)->bfad_num = (_drv)->inst_no; \
  120. (_entry)->seq_num = (_cnt); \
  121. (_entry)->aen_category = (_cat); \
  122. (_entry)->aen_type = (_evt); \
  123. if ((_drv)->bfad_flags & BFAD_FC4_PROBE_DONE) \
  124. queue_work((_drv)->im->drv_workq, \
  125. &(_drv)->im->aen_im_notify_work); \
  126. } while (0)
  127. struct Scsi_Host *bfad_scsi_host_alloc(struct bfad_im_port_s *im_port,
  128. struct bfad_s *);
  129. bfa_status_t bfad_thread_workq(struct bfad_s *bfad);
  130. void bfad_destroy_workq(struct bfad_im_s *im);
  131. void bfad_fc_host_init(struct bfad_im_port_s *im_port);
  132. void bfad_scsi_host_free(struct bfad_s *bfad,
  133. struct bfad_im_port_s *im_port);
  134. void bfad_ramp_up_qdepth(struct bfad_itnim_s *itnim,
  135. struct scsi_device *sdev);
  136. void bfad_handle_qfull(struct bfad_itnim_s *itnim, struct scsi_device *sdev);
  137. struct bfad_itnim_s *bfad_get_itnim(struct bfad_im_port_s *im_port, int id);
  138. extern struct scsi_host_template bfad_im_scsi_host_template;
  139. extern struct scsi_host_template bfad_im_vport_template;
  140. extern struct fc_function_template bfad_im_fc_function_template;
  141. extern struct fc_function_template bfad_im_vport_fc_function_template;
  142. extern struct scsi_transport_template *bfad_im_scsi_transport_template;
  143. extern struct scsi_transport_template *bfad_im_scsi_vport_transport_template;
  144. extern struct device_attribute *bfad_im_host_attrs[];
  145. extern struct device_attribute *bfad_im_vport_attrs[];
  146. irqreturn_t bfad_intx(int irq, void *dev_id);
  147. int bfad_im_bsg_request(struct fc_bsg_job *job);
  148. int bfad_im_bsg_timeout(struct fc_bsg_job *job);
  149. /*
  150. * Macro to set the SCSI device sdev_bflags - sdev_bflags are used by the
  151. * SCSI mid-layer to choose LUN Scanning mode REPORT_LUNS vs. Sequential Scan
  152. *
  153. * Internally iterate's over all the ITNIM's part of the im_port & set's the
  154. * sdev_bflags for the scsi_device associated with LUN #0.
  155. */
  156. #define bfad_reset_sdev_bflags(__im_port, __lunmask_cfg) do { \
  157. struct scsi_device *__sdev = NULL; \
  158. struct bfad_itnim_s *__itnim = NULL; \
  159. u32 scan_flags = BLIST_NOREPORTLUN | BLIST_SPARSELUN; \
  160. list_for_each_entry(__itnim, &((__im_port)->itnim_mapped_list), \
  161. list_entry) { \
  162. __sdev = scsi_device_lookup((__im_port)->shost, \
  163. __itnim->channel, \
  164. __itnim->scsi_tgt_id, 0); \
  165. if (__sdev) { \
  166. if ((__lunmask_cfg) == BFA_TRUE) \
  167. __sdev->sdev_bflags |= scan_flags; \
  168. else \
  169. __sdev->sdev_bflags &= ~scan_flags; \
  170. scsi_device_put(__sdev); \
  171. } \
  172. } \
  173. } while (0)
  174. #endif