zfcp_fc.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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_req - Container for FC ELS and CT requests sent from zfcp
  113. * @ct_els: data required for issuing fsf command
  114. * @sg_req: scatterlist entry for request data
  115. * @sg_rsp: scatterlist entry for response data
  116. * @u: request specific data
  117. */
  118. struct zfcp_fc_req {
  119. struct zfcp_fsf_ct_els ct_els;
  120. struct scatterlist sg_req;
  121. struct scatterlist sg_rsp;
  122. union {
  123. struct {
  124. struct fc_els_adisc req;
  125. struct fc_els_adisc rsp;
  126. } adisc;
  127. } u;
  128. };
  129. /**
  130. * enum zfcp_fc_wka_status - FC WKA port status in zfcp
  131. * @ZFCP_FC_WKA_PORT_OFFLINE: Port is closed and not in use
  132. * @ZFCP_FC_WKA_PORT_CLOSING: The FSF "close port" request is pending
  133. * @ZFCP_FC_WKA_PORT_OPENING: The FSF "open port" request is pending
  134. * @ZFCP_FC_WKA_PORT_ONLINE: The port is open and the port handle is valid
  135. */
  136. enum zfcp_fc_wka_status {
  137. ZFCP_FC_WKA_PORT_OFFLINE,
  138. ZFCP_FC_WKA_PORT_CLOSING,
  139. ZFCP_FC_WKA_PORT_OPENING,
  140. ZFCP_FC_WKA_PORT_ONLINE,
  141. };
  142. /**
  143. * struct zfcp_fc_wka_port - representation of well-known-address (WKA) FC port
  144. * @adapter: Pointer to adapter structure this WKA port belongs to
  145. * @completion_wq: Wait for completion of open/close command
  146. * @status: Current status of WKA port
  147. * @refcount: Reference count to keep port open as long as it is in use
  148. * @d_id: FC destination id or well-known-address
  149. * @handle: FSF handle for the open WKA port
  150. * @mutex: Mutex used during opening/closing state changes
  151. * @work: For delaying the closing of the WKA port
  152. */
  153. struct zfcp_fc_wka_port {
  154. struct zfcp_adapter *adapter;
  155. wait_queue_head_t completion_wq;
  156. enum zfcp_fc_wka_status status;
  157. atomic_t refcount;
  158. u32 d_id;
  159. u32 handle;
  160. struct mutex mutex;
  161. struct delayed_work work;
  162. };
  163. /**
  164. * struct zfcp_fc_wka_ports - Data structures for FC generic services
  165. * @ms: FC Management service
  166. * @ts: FC time service
  167. * @ds: FC directory service
  168. * @as: FC alias service
  169. */
  170. struct zfcp_fc_wka_ports {
  171. struct zfcp_fc_wka_port ms;
  172. struct zfcp_fc_wka_port ts;
  173. struct zfcp_fc_wka_port ds;
  174. struct zfcp_fc_wka_port as;
  175. };
  176. /**
  177. * zfcp_fc_scsi_to_fcp - setup FCP command with data from scsi_cmnd
  178. * @fcp: fcp_cmnd to setup
  179. * @scsi: scsi_cmnd where to get LUN, task attributes/flags and CDB
  180. */
  181. static inline
  182. void zfcp_fc_scsi_to_fcp(struct fcp_cmnd *fcp, struct scsi_cmnd *scsi)
  183. {
  184. char tag[2];
  185. int_to_scsilun(scsi->device->lun, (struct scsi_lun *) &fcp->fc_lun);
  186. if (scsi_populate_tag_msg(scsi, tag)) {
  187. switch (tag[0]) {
  188. case MSG_ORDERED_TAG:
  189. fcp->fc_pri_ta |= FCP_PTA_ORDERED;
  190. break;
  191. case MSG_SIMPLE_TAG:
  192. fcp->fc_pri_ta |= FCP_PTA_SIMPLE;
  193. break;
  194. };
  195. } else
  196. fcp->fc_pri_ta = FCP_PTA_SIMPLE;
  197. if (scsi->sc_data_direction == DMA_FROM_DEVICE)
  198. fcp->fc_flags |= FCP_CFL_RDDATA;
  199. if (scsi->sc_data_direction == DMA_TO_DEVICE)
  200. fcp->fc_flags |= FCP_CFL_WRDATA;
  201. memcpy(fcp->fc_cdb, scsi->cmnd, scsi->cmd_len);
  202. fcp->fc_dl = scsi_bufflen(scsi);
  203. if (scsi_get_prot_type(scsi) == SCSI_PROT_DIF_TYPE1)
  204. fcp->fc_dl += fcp->fc_dl / scsi->device->sector_size * 8;
  205. }
  206. /**
  207. * zfcp_fc_fcp_tm - setup FCP command as task management command
  208. * @fcp: fcp_cmnd to setup
  209. * @dev: scsi_device where to send the task management command
  210. * @tm: task management flags to setup tm command
  211. */
  212. static inline
  213. void zfcp_fc_fcp_tm(struct fcp_cmnd *fcp, struct scsi_device *dev, u8 tm_flags)
  214. {
  215. int_to_scsilun(dev->lun, (struct scsi_lun *) &fcp->fc_lun);
  216. fcp->fc_tm_flags |= tm_flags;
  217. }
  218. /**
  219. * zfcp_fc_evap_fcp_rsp - evaluate FCP RSP IU and update scsi_cmnd accordingly
  220. * @fcp_rsp: FCP RSP IU to evaluate
  221. * @scsi: SCSI command where to update status and sense buffer
  222. */
  223. static inline
  224. void zfcp_fc_eval_fcp_rsp(struct fcp_resp_with_ext *fcp_rsp,
  225. struct scsi_cmnd *scsi)
  226. {
  227. struct fcp_resp_rsp_info *rsp_info;
  228. char *sense;
  229. u32 sense_len, resid;
  230. u8 rsp_flags;
  231. set_msg_byte(scsi, COMMAND_COMPLETE);
  232. scsi->result |= fcp_rsp->resp.fr_status;
  233. rsp_flags = fcp_rsp->resp.fr_flags;
  234. if (unlikely(rsp_flags & FCP_RSP_LEN_VAL)) {
  235. rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1];
  236. if (rsp_info->rsp_code == FCP_TMF_CMPL)
  237. set_host_byte(scsi, DID_OK);
  238. else {
  239. set_host_byte(scsi, DID_ERROR);
  240. return;
  241. }
  242. }
  243. if (unlikely(rsp_flags & FCP_SNS_LEN_VAL)) {
  244. sense = (char *) &fcp_rsp[1];
  245. if (rsp_flags & FCP_RSP_LEN_VAL)
  246. sense += fcp_rsp->ext.fr_rsp_len;
  247. sense_len = min(fcp_rsp->ext.fr_sns_len,
  248. (u32) SCSI_SENSE_BUFFERSIZE);
  249. memcpy(scsi->sense_buffer, sense, sense_len);
  250. }
  251. if (unlikely(rsp_flags & FCP_RESID_UNDER)) {
  252. resid = fcp_rsp->ext.fr_resid;
  253. scsi_set_resid(scsi, resid);
  254. if (scsi_bufflen(scsi) - resid < scsi->underflow &&
  255. !(rsp_flags & FCP_SNS_LEN_VAL) &&
  256. fcp_rsp->resp.fr_status == SAM_STAT_GOOD)
  257. set_host_byte(scsi, DID_ERROR);
  258. }
  259. }
  260. #endif