zfcp_fc.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. /*
  2. * zfcp device driver
  3. *
  4. * Fibre Channel related definitions and inline functions for the zfcp
  5. * device driver
  6. *
  7. * Copyright IBM Corporation 2009
  8. */
  9. #ifndef ZFCP_FC_H
  10. #define ZFCP_FC_H
  11. #include <scsi/fc/fc_els.h>
  12. #include <scsi/fc/fc_fcp.h>
  13. #include <scsi/fc/fc_ns.h>
  14. #include <scsi/scsi_cmnd.h>
  15. #include <scsi/scsi_tcq.h>
  16. #include "zfcp_fsf.h"
  17. #define ZFCP_FC_CT_SIZE_PAGE (PAGE_SIZE - sizeof(struct fc_ct_hdr))
  18. #define ZFCP_FC_GPN_FT_ENT_PAGE (ZFCP_FC_CT_SIZE_PAGE \
  19. / sizeof(struct fc_gpn_ft_resp))
  20. #define ZFCP_FC_GPN_FT_NUM_BUFS 4 /* memory pages */
  21. #define ZFCP_FC_GPN_FT_MAX_SIZE (ZFCP_FC_GPN_FT_NUM_BUFS * PAGE_SIZE \
  22. - sizeof(struct fc_ct_hdr))
  23. #define ZFCP_FC_GPN_FT_MAX_ENT (ZFCP_FC_GPN_FT_NUM_BUFS * \
  24. (ZFCP_FC_GPN_FT_ENT_PAGE + 1))
  25. #define ZFCP_FC_CTELS_TMO (2 * FC_DEF_R_A_TOV / 1000)
  26. /**
  27. * struct zfcp_fc_gid_pn_req - container for ct header plus gid_pn request
  28. * @ct_hdr: FC GS common transport header
  29. * @gid_pn: GID_PN request
  30. */
  31. struct zfcp_fc_gid_pn_req {
  32. struct fc_ct_hdr ct_hdr;
  33. struct fc_ns_gid_pn gid_pn;
  34. } __packed;
  35. /**
  36. * struct zfcp_fc_gid_pn_resp - container for ct header plus gid_pn response
  37. * @ct_hdr: FC GS common transport header
  38. * @gid_pn: GID_PN response
  39. */
  40. struct zfcp_fc_gid_pn_resp {
  41. struct fc_ct_hdr ct_hdr;
  42. struct fc_gid_pn_resp gid_pn;
  43. } __packed;
  44. /**
  45. * struct zfcp_fc_gid_pn - everything required in zfcp for gid_pn request
  46. * @ct: data passed to zfcp_fsf for issuing fsf request
  47. * @sg_req: scatterlist entry for request data
  48. * @sg_resp: scatterlist entry for response data
  49. * @gid_pn_req: GID_PN request data
  50. * @gid_pn_resp: GID_PN response data
  51. */
  52. struct zfcp_fc_gid_pn {
  53. struct zfcp_fsf_ct_els ct;
  54. struct scatterlist sg_req;
  55. struct scatterlist sg_resp;
  56. struct zfcp_fc_gid_pn_req gid_pn_req;
  57. struct zfcp_fc_gid_pn_resp gid_pn_resp;
  58. struct zfcp_port *port;
  59. };
  60. /**
  61. * struct zfcp_fc_gpn_ft - container for ct header plus gpn_ft request
  62. * @ct_hdr: FC GS common transport header
  63. * @gpn_ft: GPN_FT request
  64. */
  65. struct zfcp_fc_gpn_ft_req {
  66. struct fc_ct_hdr ct_hdr;
  67. struct fc_ns_gid_ft gpn_ft;
  68. } __packed;
  69. /**
  70. * struct zfcp_fc_gpn_ft_resp - container for ct header plus gpn_ft response
  71. * @ct_hdr: FC GS common transport header
  72. * @gpn_ft: Array of gpn_ft response data to fill one memory page
  73. */
  74. struct zfcp_fc_gpn_ft_resp {
  75. struct fc_ct_hdr ct_hdr;
  76. struct fc_gpn_ft_resp gpn_ft[ZFCP_FC_GPN_FT_ENT_PAGE];
  77. } __packed;
  78. /**
  79. * struct zfcp_fc_gpn_ft - zfcp data for gpn_ft request
  80. * @ct: data passed to zfcp_fsf for issuing fsf request
  81. * @sg_req: scatter list entry for gpn_ft request
  82. * @sg_resp: scatter list entries for gpn_ft responses (per memory page)
  83. */
  84. struct zfcp_fc_gpn_ft {
  85. struct zfcp_fsf_ct_els ct;
  86. struct scatterlist sg_req;
  87. struct scatterlist sg_resp[ZFCP_FC_GPN_FT_NUM_BUFS];
  88. };
  89. /**
  90. * struct zfcp_fc_els_adisc - everything required in zfcp for issuing ELS ADISC
  91. * @els: data required for issuing els fsf command
  92. * @req: scatterlist entry for ELS ADISC request
  93. * @resp: scatterlist entry for ELS ADISC response
  94. * @adisc_req: ELS ADISC request data
  95. * @adisc_resp: ELS ADISC response data
  96. */
  97. struct zfcp_fc_els_adisc {
  98. struct zfcp_fsf_ct_els els;
  99. struct scatterlist req;
  100. struct scatterlist resp;
  101. struct fc_els_adisc adisc_req;
  102. struct fc_els_adisc adisc_resp;
  103. };
  104. /**
  105. * enum zfcp_fc_wka_status - FC WKA port status in zfcp
  106. * @ZFCP_FC_WKA_PORT_OFFLINE: Port is closed and not in use
  107. * @ZFCP_FC_WKA_PORT_CLOSING: The FSF "close port" request is pending
  108. * @ZFCP_FC_WKA_PORT_OPENING: The FSF "open port" request is pending
  109. * @ZFCP_FC_WKA_PORT_ONLINE: The port is open and the port handle is valid
  110. */
  111. enum zfcp_fc_wka_status {
  112. ZFCP_FC_WKA_PORT_OFFLINE,
  113. ZFCP_FC_WKA_PORT_CLOSING,
  114. ZFCP_FC_WKA_PORT_OPENING,
  115. ZFCP_FC_WKA_PORT_ONLINE,
  116. };
  117. /**
  118. * struct zfcp_fc_wka_port - representation of well-known-address (WKA) FC port
  119. * @adapter: Pointer to adapter structure this WKA port belongs to
  120. * @completion_wq: Wait for completion of open/close command
  121. * @status: Current status of WKA port
  122. * @refcount: Reference count to keep port open as long as it is in use
  123. * @d_id: FC destination id or well-known-address
  124. * @handle: FSF handle for the open WKA port
  125. * @mutex: Mutex used during opening/closing state changes
  126. * @work: For delaying the closing of the WKA port
  127. */
  128. struct zfcp_fc_wka_port {
  129. struct zfcp_adapter *adapter;
  130. wait_queue_head_t completion_wq;
  131. enum zfcp_fc_wka_status status;
  132. atomic_t refcount;
  133. u32 d_id;
  134. u32 handle;
  135. struct mutex mutex;
  136. struct delayed_work work;
  137. };
  138. /**
  139. * struct zfcp_fc_wka_ports - Data structures for FC generic services
  140. * @ms: FC Management service
  141. * @ts: FC time service
  142. * @ds: FC directory service
  143. * @as: FC alias service
  144. */
  145. struct zfcp_fc_wka_ports {
  146. struct zfcp_fc_wka_port ms;
  147. struct zfcp_fc_wka_port ts;
  148. struct zfcp_fc_wka_port ds;
  149. struct zfcp_fc_wka_port as;
  150. };
  151. /**
  152. * zfcp_fc_scsi_to_fcp - setup FCP command with data from scsi_cmnd
  153. * @fcp: fcp_cmnd to setup
  154. * @scsi: scsi_cmnd where to get LUN, task attributes/flags and CDB
  155. */
  156. static inline
  157. void zfcp_fc_scsi_to_fcp(struct fcp_cmnd *fcp, struct scsi_cmnd *scsi)
  158. {
  159. char tag[2];
  160. int_to_scsilun(scsi->device->lun, (struct scsi_lun *) &fcp->fc_lun);
  161. if (scsi_populate_tag_msg(scsi, tag)) {
  162. switch (tag[0]) {
  163. case MSG_ORDERED_TAG:
  164. fcp->fc_pri_ta |= FCP_PTA_ORDERED;
  165. break;
  166. case MSG_SIMPLE_TAG:
  167. fcp->fc_pri_ta |= FCP_PTA_SIMPLE;
  168. break;
  169. };
  170. } else
  171. fcp->fc_pri_ta = FCP_PTA_SIMPLE;
  172. if (scsi->sc_data_direction == DMA_FROM_DEVICE)
  173. fcp->fc_flags |= FCP_CFL_RDDATA;
  174. if (scsi->sc_data_direction == DMA_TO_DEVICE)
  175. fcp->fc_flags |= FCP_CFL_WRDATA;
  176. memcpy(fcp->fc_cdb, scsi->cmnd, scsi->cmd_len);
  177. fcp->fc_dl = scsi_bufflen(scsi);
  178. }
  179. /**
  180. * zfcp_fc_fcp_tm - setup FCP command as task management command
  181. * @fcp: fcp_cmnd to setup
  182. * @dev: scsi_device where to send the task management command
  183. * @tm: task management flags to setup tm command
  184. */
  185. static inline
  186. void zfcp_fc_fcp_tm(struct fcp_cmnd *fcp, struct scsi_device *dev, u8 tm_flags)
  187. {
  188. int_to_scsilun(dev->lun, (struct scsi_lun *) &fcp->fc_lun);
  189. fcp->fc_tm_flags |= tm_flags;
  190. }
  191. /**
  192. * zfcp_fc_evap_fcp_rsp - evaluate FCP RSP IU and update scsi_cmnd accordingly
  193. * @fcp_rsp: FCP RSP IU to evaluate
  194. * @scsi: SCSI command where to update status and sense buffer
  195. */
  196. static inline
  197. void zfcp_fc_eval_fcp_rsp(struct fcp_resp_with_ext *fcp_rsp,
  198. struct scsi_cmnd *scsi)
  199. {
  200. struct fcp_resp_rsp_info *rsp_info;
  201. char *sense;
  202. u32 sense_len, resid;
  203. u8 rsp_flags;
  204. set_msg_byte(scsi, COMMAND_COMPLETE);
  205. scsi->result |= fcp_rsp->resp.fr_status;
  206. rsp_flags = fcp_rsp->resp.fr_flags;
  207. if (unlikely(rsp_flags & FCP_RSP_LEN_VAL)) {
  208. rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1];
  209. if (rsp_info->rsp_code == FCP_TMF_CMPL)
  210. set_host_byte(scsi, DID_OK);
  211. else {
  212. set_host_byte(scsi, DID_ERROR);
  213. return;
  214. }
  215. }
  216. if (unlikely(rsp_flags & FCP_SNS_LEN_VAL)) {
  217. sense = (char *) &fcp_rsp[1];
  218. if (rsp_flags & FCP_RSP_LEN_VAL)
  219. sense += fcp_rsp->ext.fr_sns_len;
  220. sense_len = min(fcp_rsp->ext.fr_sns_len,
  221. (u32) SCSI_SENSE_BUFFERSIZE);
  222. memcpy(scsi->sense_buffer, sense, sense_len);
  223. }
  224. if (unlikely(rsp_flags & FCP_RESID_UNDER)) {
  225. resid = fcp_rsp->ext.fr_resid;
  226. scsi_set_resid(scsi, resid);
  227. if (scsi_bufflen(scsi) - resid < scsi->underflow &&
  228. !(rsp_flags & FCP_SNS_LEN_VAL) &&
  229. fcp_rsp->resp.fr_status == SAM_STAT_GOOD)
  230. set_host_byte(scsi, DID_ERROR);
  231. }
  232. }
  233. #endif