4 * Fibre Channel related definitions and inline functions for the zfcp
7 * Copyright IBM Corporation 2009
13 #include <scsi/fc/fc_els.h>
14 #include <scsi/fc/fc_fcp.h>
15 #include <scsi/fc/fc_ns.h>
16 #include <scsi/scsi_cmnd.h>
17 #include <scsi/scsi_tcq.h>
20 #define ZFCP_FC_CT_SIZE_PAGE (PAGE_SIZE - sizeof(struct fc_ct_hdr))
21 #define ZFCP_FC_GPN_FT_ENT_PAGE (ZFCP_FC_CT_SIZE_PAGE \
22 / sizeof(struct fc_gpn_ft_resp))
23 #define ZFCP_FC_GPN_FT_NUM_BUFS 4 /* memory pages */
25 #define ZFCP_FC_GPN_FT_MAX_SIZE (ZFCP_FC_GPN_FT_NUM_BUFS * PAGE_SIZE \
26 - sizeof(struct fc_ct_hdr))
27 #define ZFCP_FC_GPN_FT_MAX_ENT (ZFCP_FC_GPN_FT_NUM_BUFS * \
28 (ZFCP_FC_GPN_FT_ENT_PAGE + 1))
31 * struct zfcp_fc_gid_pn_req - container for ct header plus gid_pn request
32 * @ct_hdr: FC GS common transport header
33 * @gid_pn: GID_PN request
35 struct zfcp_fc_gid_pn_req {
36 struct fc_ct_hdr ct_hdr;
37 struct fc_ns_gid_pn gid_pn;
41 * struct zfcp_fc_gid_pn_resp - container for ct header plus gid_pn response
42 * @ct_hdr: FC GS common transport header
43 * @gid_pn: GID_PN response
45 struct zfcp_fc_gid_pn_resp {
46 struct fc_ct_hdr ct_hdr;
47 struct fc_gid_pn_resp gid_pn;
51 * struct zfcp_fc_gid_pn - everything required in zfcp for gid_pn request
52 * @ct: data passed to zfcp_fsf for issuing fsf request
53 * @sg_req: scatterlist entry for request data
54 * @sg_resp: scatterlist entry for response data
55 * @gid_pn_req: GID_PN request data
56 * @gid_pn_resp: GID_PN response data
58 struct zfcp_fc_gid_pn {
59 struct zfcp_fsf_ct_els ct;
60 struct scatterlist sg_req;
61 struct scatterlist sg_resp;
62 struct zfcp_fc_gid_pn_req gid_pn_req;
63 struct zfcp_fc_gid_pn_resp gid_pn_resp;
64 struct zfcp_port *port;
68 * struct zfcp_fc_gpn_ft - container for ct header plus gpn_ft request
69 * @ct_hdr: FC GS common transport header
70 * @gpn_ft: GPN_FT request
72 struct zfcp_fc_gpn_ft_req {
73 struct fc_ct_hdr ct_hdr;
74 struct fc_ns_gid_ft gpn_ft;
78 * struct zfcp_fc_gpn_ft_resp - container for ct header plus gpn_ft response
79 * @ct_hdr: FC GS common transport header
80 * @gpn_ft: Array of gpn_ft response data to fill one memory page
82 struct zfcp_fc_gpn_ft_resp {
83 struct fc_ct_hdr ct_hdr;
84 struct fc_gpn_ft_resp gpn_ft[ZFCP_FC_GPN_FT_ENT_PAGE];
88 * struct zfcp_fc_gpn_ft - zfcp data for gpn_ft request
89 * @ct: data passed to zfcp_fsf for issuing fsf request
90 * @sg_req: scatter list entry for gpn_ft request
91 * @sg_resp: scatter list entries for gpn_ft responses (per memory page)
93 struct zfcp_fc_gpn_ft {
94 struct zfcp_fsf_ct_els ct;
95 struct scatterlist sg_req;
96 struct scatterlist sg_resp[ZFCP_FC_GPN_FT_NUM_BUFS];
100 * struct zfcp_fc_els_adisc - everything required in zfcp for issuing ELS ADISC
101 * @els: data required for issuing els fsf command
102 * @req: scatterlist entry for ELS ADISC request
103 * @resp: scatterlist entry for ELS ADISC response
104 * @adisc_req: ELS ADISC request data
105 * @adisc_resp: ELS ADISC response data
107 struct zfcp_fc_els_adisc {
108 struct zfcp_fsf_ct_els els;
109 struct scatterlist req;
110 struct scatterlist resp;
111 struct fc_els_adisc adisc_req;
112 struct fc_els_adisc adisc_resp;
116 * enum zfcp_fc_wka_status - FC WKA port status in zfcp
117 * @ZFCP_FC_WKA_PORT_OFFLINE: Port is closed and not in use
118 * @ZFCP_FC_WKA_PORT_CLOSING: The FSF "close port" request is pending
119 * @ZFCP_FC_WKA_PORT_OPENING: The FSF "open port" request is pending
120 * @ZFCP_FC_WKA_PORT_ONLINE: The port is open and the port handle is valid
122 enum zfcp_fc_wka_status {
123 ZFCP_FC_WKA_PORT_OFFLINE,
124 ZFCP_FC_WKA_PORT_CLOSING,
125 ZFCP_FC_WKA_PORT_OPENING,
126 ZFCP_FC_WKA_PORT_ONLINE,
130 * struct zfcp_fc_wka_port - representation of well-known-address (WKA) FC port
131 * @adapter: Pointer to adapter structure this WKA port belongs to
132 * @completion_wq: Wait for completion of open/close command
133 * @status: Current status of WKA port
134 * @refcount: Reference count to keep port open as long as it is in use
135 * @d_id: FC destination id or well-known-address
136 * @handle: FSF handle for the open WKA port
137 * @mutex: Mutex used during opening/closing state changes
138 * @work: For delaying the closing of the WKA port
140 struct zfcp_fc_wka_port {
141 struct zfcp_adapter *adapter;
142 wait_queue_head_t completion_wq;
143 enum zfcp_fc_wka_status status;
148 struct delayed_work work;
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
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;
166 * zfcp_fc_scsi_to_fcp - setup FCP command with data from scsi_cmnd
167 * @fcp: fcp_cmnd to setup
168 * @scsi: scsi_cmnd where to get LUN, task attributes/flags and CDB
171 void zfcp_fc_scsi_to_fcp(struct fcp_cmnd *fcp, struct scsi_cmnd *scsi)
175 int_to_scsilun(scsi->device->lun, (struct scsi_lun *) &fcp->fc_lun);
177 if (scsi_populate_tag_msg(scsi, tag)) {
179 case MSG_ORDERED_TAG:
180 fcp->fc_pri_ta |= FCP_PTA_ORDERED;
183 fcp->fc_pri_ta |= FCP_PTA_SIMPLE;
187 fcp->fc_pri_ta = FCP_PTA_SIMPLE;
189 if (scsi->sc_data_direction == DMA_FROM_DEVICE)
190 fcp->fc_flags |= FCP_CFL_RDDATA;
191 if (scsi->sc_data_direction == DMA_TO_DEVICE)
192 fcp->fc_flags |= FCP_CFL_WRDATA;
194 memcpy(fcp->fc_cdb, scsi->cmnd, scsi->cmd_len);
196 fcp->fc_dl = scsi_bufflen(scsi);
200 * zfcp_fc_fcp_tm - setup FCP command as task management command
201 * @fcp: fcp_cmnd to setup
202 * @dev: scsi_device where to send the task management command
203 * @tm: task management flags to setup tm command
206 void zfcp_fc_fcp_tm(struct fcp_cmnd *fcp, struct scsi_device *dev, u8 tm_flags)
208 int_to_scsilun(dev->lun, (struct scsi_lun *) &fcp->fc_lun);
209 fcp->fc_tm_flags |= tm_flags;
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
218 void zfcp_fc_eval_fcp_rsp(struct fcp_resp_with_ext *fcp_rsp,
219 struct scsi_cmnd *scsi)
221 struct fcp_resp_rsp_info *rsp_info;
223 u32 sense_len, resid;
226 set_msg_byte(scsi, COMMAND_COMPLETE);
227 scsi->result |= fcp_rsp->resp.fr_status;
229 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);
236 set_host_byte(scsi, DID_ERROR);
241 if (unlikely(rsp_flags & FCP_SNS_LEN_VAL)) {
242 sense = (char *) &fcp_rsp[1];
243 if (rsp_flags & FCP_RSP_LEN_VAL)
244 sense += fcp_rsp->ext.fr_sns_len;
245 sense_len = min(fcp_rsp->ext.fr_sns_len,
246 (u32) SCSI_SENSE_BUFFERSIZE);
247 memcpy(scsi->sense_buffer, sense, sense_len);
250 if (unlikely(rsp_flags & FCP_RESID_UNDER)) {
251 resid = fcp_rsp->ext.fr_resid;
252 scsi_set_resid(scsi, resid);
253 if (scsi_bufflen(scsi) - resid < scsi->underflow &&
254 !(rsp_flags & FCP_SNS_LEN_VAL) &&
255 fcp_rsp->resp.fr_status == SAM_STAT_GOOD)
256 set_host_byte(scsi, DID_ERROR);