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