zfcp_fc.h 7.5 KB

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