zfcp_fc.h 8.0 KB

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