zfcp_fc.h 7.2 KB

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