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))
30 #define ZFCP_FC_CTELS_TMO (2 * FC_DEF_R_A_TOV / 1000)
33 * struct zfcp_fc_gid_pn_req - container for ct header plus gid_pn request
34 * @ct_hdr: FC GS common transport header
35 * @gid_pn: GID_PN request
37 struct zfcp_fc_gid_pn_req
{
38 struct fc_ct_hdr ct_hdr
;
39 struct fc_ns_gid_pn gid_pn
;
43 * struct zfcp_fc_gid_pn_resp - container for ct header plus gid_pn response
44 * @ct_hdr: FC GS common transport header
45 * @gid_pn: GID_PN response
47 struct zfcp_fc_gid_pn_resp
{
48 struct fc_ct_hdr ct_hdr
;
49 struct fc_gid_pn_resp gid_pn
;
53 * struct zfcp_fc_gid_pn - everything required in zfcp for gid_pn request
54 * @ct: data passed to zfcp_fsf for issuing fsf request
55 * @sg_req: scatterlist entry for request data
56 * @sg_resp: scatterlist entry for response data
57 * @gid_pn_req: GID_PN request data
58 * @gid_pn_resp: GID_PN response data
60 struct zfcp_fc_gid_pn
{
61 struct zfcp_fsf_ct_els ct
;
62 struct scatterlist sg_req
;
63 struct scatterlist sg_resp
;
64 struct zfcp_fc_gid_pn_req gid_pn_req
;
65 struct zfcp_fc_gid_pn_resp gid_pn_resp
;
66 struct zfcp_port
*port
;
70 * struct zfcp_fc_gpn_ft - container for ct header plus gpn_ft request
71 * @ct_hdr: FC GS common transport header
72 * @gpn_ft: GPN_FT request
74 struct zfcp_fc_gpn_ft_req
{
75 struct fc_ct_hdr ct_hdr
;
76 struct fc_ns_gid_ft gpn_ft
;
80 * struct zfcp_fc_gpn_ft_resp - container for ct header plus gpn_ft response
81 * @ct_hdr: FC GS common transport header
82 * @gpn_ft: Array of gpn_ft response data to fill one memory page
84 struct zfcp_fc_gpn_ft_resp
{
85 struct fc_ct_hdr ct_hdr
;
86 struct fc_gpn_ft_resp gpn_ft
[ZFCP_FC_GPN_FT_ENT_PAGE
];
90 * struct zfcp_fc_gpn_ft - zfcp data for gpn_ft request
91 * @ct: data passed to zfcp_fsf for issuing fsf request
92 * @sg_req: scatter list entry for gpn_ft request
93 * @sg_resp: scatter list entries for gpn_ft responses (per memory page)
95 struct zfcp_fc_gpn_ft
{
96 struct zfcp_fsf_ct_els ct
;
97 struct scatterlist sg_req
;
98 struct scatterlist sg_resp
[ZFCP_FC_GPN_FT_NUM_BUFS
];
102 * struct zfcp_fc_els_adisc - everything required in zfcp for issuing ELS ADISC
103 * @els: data required for issuing els fsf command
104 * @req: scatterlist entry for ELS ADISC request
105 * @resp: scatterlist entry for ELS ADISC response
106 * @adisc_req: ELS ADISC request data
107 * @adisc_resp: ELS ADISC response data
109 struct zfcp_fc_els_adisc
{
110 struct zfcp_fsf_ct_els els
;
111 struct scatterlist req
;
112 struct scatterlist resp
;
113 struct fc_els_adisc adisc_req
;
114 struct fc_els_adisc adisc_resp
;
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
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
,
132 * struct zfcp_fc_wka_port - representation of well-known-address (WKA) FC port
133 * @adapter: Pointer to adapter structure this WKA port belongs to
134 * @completion_wq: Wait for completion of open/close command
135 * @status: Current status of WKA port
136 * @refcount: Reference count to keep port open as long as it is in use
137 * @d_id: FC destination id or well-known-address
138 * @handle: FSF handle for the open WKA port
139 * @mutex: Mutex used during opening/closing state changes
140 * @work: For delaying the closing of the WKA port
142 struct zfcp_fc_wka_port
{
143 struct zfcp_adapter
*adapter
;
144 wait_queue_head_t completion_wq
;
145 enum zfcp_fc_wka_status status
;
150 struct delayed_work work
;
154 * struct zfcp_fc_wka_ports - Data structures for FC generic services
155 * @ms: FC Management service
156 * @ts: FC time service
157 * @ds: FC directory service
158 * @as: FC alias service
160 struct zfcp_fc_wka_ports
{
161 struct zfcp_fc_wka_port ms
;
162 struct zfcp_fc_wka_port ts
;
163 struct zfcp_fc_wka_port ds
;
164 struct zfcp_fc_wka_port as
;
168 * zfcp_fc_scsi_to_fcp - setup FCP command with data from scsi_cmnd
169 * @fcp: fcp_cmnd to setup
170 * @scsi: scsi_cmnd where to get LUN, task attributes/flags and CDB
173 void zfcp_fc_scsi_to_fcp(struct fcp_cmnd
*fcp
, struct scsi_cmnd
*scsi
)
177 int_to_scsilun(scsi
->device
->lun
, (struct scsi_lun
*) &fcp
->fc_lun
);
179 if (scsi_populate_tag_msg(scsi
, tag
)) {
181 case MSG_ORDERED_TAG
:
182 fcp
->fc_pri_ta
|= FCP_PTA_ORDERED
;
185 fcp
->fc_pri_ta
|= FCP_PTA_SIMPLE
;
189 fcp
->fc_pri_ta
= FCP_PTA_SIMPLE
;
191 if (scsi
->sc_data_direction
== DMA_FROM_DEVICE
)
192 fcp
->fc_flags
|= FCP_CFL_RDDATA
;
193 if (scsi
->sc_data_direction
== DMA_TO_DEVICE
)
194 fcp
->fc_flags
|= FCP_CFL_WRDATA
;
196 memcpy(fcp
->fc_cdb
, scsi
->cmnd
, scsi
->cmd_len
);
198 fcp
->fc_dl
= scsi_bufflen(scsi
);
202 * zfcp_fc_fcp_tm - setup FCP command as task management command
203 * @fcp: fcp_cmnd to setup
204 * @dev: scsi_device where to send the task management command
205 * @tm: task management flags to setup tm command
208 void zfcp_fc_fcp_tm(struct fcp_cmnd
*fcp
, struct scsi_device
*dev
, u8 tm_flags
)
210 int_to_scsilun(dev
->lun
, (struct scsi_lun
*) &fcp
->fc_lun
);
211 fcp
->fc_tm_flags
|= tm_flags
;
215 * zfcp_fc_evap_fcp_rsp - evaluate FCP RSP IU and update scsi_cmnd accordingly
216 * @fcp_rsp: FCP RSP IU to evaluate
217 * @scsi: SCSI command where to update status and sense buffer
220 void zfcp_fc_eval_fcp_rsp(struct fcp_resp_with_ext
*fcp_rsp
,
221 struct scsi_cmnd
*scsi
)
223 struct fcp_resp_rsp_info
*rsp_info
;
225 u32 sense_len
, resid
;
228 set_msg_byte(scsi
, COMMAND_COMPLETE
);
229 scsi
->result
|= fcp_rsp
->resp
.fr_status
;
231 rsp_flags
= fcp_rsp
->resp
.fr_flags
;
233 if (unlikely(rsp_flags
& FCP_RSP_LEN_VAL
)) {
234 rsp_info
= (struct fcp_resp_rsp_info
*) &fcp_rsp
[1];
235 if (rsp_info
->rsp_code
== FCP_TMF_CMPL
)
236 set_host_byte(scsi
, DID_OK
);
238 set_host_byte(scsi
, DID_ERROR
);
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_sns_len
;
247 sense_len
= min(fcp_rsp
->ext
.fr_sns_len
,
248 (u32
) SCSI_SENSE_BUFFERSIZE
);
249 memcpy(scsi
->sense_buffer
, sense
, sense_len
);
252 if (unlikely(rsp_flags
& FCP_RESID_UNDER
)) {
253 resid
= fcp_rsp
->ext
.fr_resid
;
254 scsi_set_resid(scsi
, resid
);
255 if (scsi_bufflen(scsi
) - resid
< scsi
->underflow
&&
256 !(rsp_flags
& FCP_SNS_LEN_VAL
) &&
257 fcp_rsp
->resp
.fr_status
== SAM_STAT_GOOD
)
258 set_host_byte(scsi
, DID_ERROR
);