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_event - FC HBAAPI event for internal queueing from irq context
36 * @list: list_head for zfcp_fc_events list
38 struct zfcp_fc_event
{
39 enum fc_host_event_code code
;
41 struct list_head list
;
45 * struct zfcp_fc_events - Infrastructure for posting FC events from irq context
46 * @list: List for queueing of events from irq context to workqueue
47 * @list_lock: Lock for event list
48 * @work: work_struct for forwarding events in workqueue
50 struct zfcp_fc_events
{
51 struct list_head list
;
53 struct work_struct work
;
57 * struct zfcp_fc_gid_pn_req - container for ct header plus gid_pn request
58 * @ct_hdr: FC GS common transport header
59 * @gid_pn: GID_PN request
61 struct zfcp_fc_gid_pn_req
{
62 struct fc_ct_hdr ct_hdr
;
63 struct fc_ns_gid_pn gid_pn
;
67 * struct zfcp_fc_gid_pn_resp - container for ct header plus gid_pn response
68 * @ct_hdr: FC GS common transport header
69 * @gid_pn: GID_PN response
71 struct zfcp_fc_gid_pn_resp
{
72 struct fc_ct_hdr ct_hdr
;
73 struct fc_gid_pn_resp gid_pn
;
77 * struct zfcp_fc_gid_pn - everything required in zfcp for gid_pn request
78 * @ct: data passed to zfcp_fsf for issuing fsf request
79 * @sg_req: scatterlist entry for request data
80 * @sg_resp: scatterlist entry for response data
81 * @gid_pn_req: GID_PN request data
82 * @gid_pn_resp: GID_PN response data
84 struct zfcp_fc_gid_pn
{
85 struct zfcp_fsf_ct_els ct
;
86 struct scatterlist sg_req
;
87 struct scatterlist sg_resp
;
88 struct zfcp_fc_gid_pn_req gid_pn_req
;
89 struct zfcp_fc_gid_pn_resp gid_pn_resp
;
90 struct zfcp_port
*port
;
94 * struct zfcp_fc_gpn_ft - container for ct header plus gpn_ft request
95 * @ct_hdr: FC GS common transport header
96 * @gpn_ft: GPN_FT request
98 struct zfcp_fc_gpn_ft_req
{
99 struct fc_ct_hdr ct_hdr
;
100 struct fc_ns_gid_ft gpn_ft
;
104 * struct zfcp_fc_gpn_ft_resp - container for ct header plus gpn_ft response
105 * @ct_hdr: FC GS common transport header
106 * @gpn_ft: Array of gpn_ft response data to fill one memory page
108 struct zfcp_fc_gpn_ft_resp
{
109 struct fc_ct_hdr ct_hdr
;
110 struct fc_gpn_ft_resp gpn_ft
[ZFCP_FC_GPN_FT_ENT_PAGE
];
114 * struct zfcp_fc_gpn_ft - zfcp data for gpn_ft request
115 * @ct: data passed to zfcp_fsf for issuing fsf request
116 * @sg_req: scatter list entry for gpn_ft request
117 * @sg_resp: scatter list entries for gpn_ft responses (per memory page)
119 struct zfcp_fc_gpn_ft
{
120 struct zfcp_fsf_ct_els ct
;
121 struct scatterlist sg_req
;
122 struct scatterlist sg_resp
[ZFCP_FC_GPN_FT_NUM_BUFS
];
126 * struct zfcp_fc_els_adisc - everything required in zfcp for issuing ELS ADISC
127 * @els: data required for issuing els fsf command
128 * @req: scatterlist entry for ELS ADISC request
129 * @resp: scatterlist entry for ELS ADISC response
130 * @adisc_req: ELS ADISC request data
131 * @adisc_resp: ELS ADISC response data
133 struct zfcp_fc_els_adisc
{
134 struct zfcp_fsf_ct_els els
;
135 struct scatterlist req
;
136 struct scatterlist resp
;
137 struct fc_els_adisc adisc_req
;
138 struct fc_els_adisc adisc_resp
;
142 * enum zfcp_fc_wka_status - FC WKA port status in zfcp
143 * @ZFCP_FC_WKA_PORT_OFFLINE: Port is closed and not in use
144 * @ZFCP_FC_WKA_PORT_CLOSING: The FSF "close port" request is pending
145 * @ZFCP_FC_WKA_PORT_OPENING: The FSF "open port" request is pending
146 * @ZFCP_FC_WKA_PORT_ONLINE: The port is open and the port handle is valid
148 enum zfcp_fc_wka_status
{
149 ZFCP_FC_WKA_PORT_OFFLINE
,
150 ZFCP_FC_WKA_PORT_CLOSING
,
151 ZFCP_FC_WKA_PORT_OPENING
,
152 ZFCP_FC_WKA_PORT_ONLINE
,
156 * struct zfcp_fc_wka_port - representation of well-known-address (WKA) FC port
157 * @adapter: Pointer to adapter structure this WKA port belongs to
158 * @completion_wq: Wait for completion of open/close command
159 * @status: Current status of WKA port
160 * @refcount: Reference count to keep port open as long as it is in use
161 * @d_id: FC destination id or well-known-address
162 * @handle: FSF handle for the open WKA port
163 * @mutex: Mutex used during opening/closing state changes
164 * @work: For delaying the closing of the WKA port
166 struct zfcp_fc_wka_port
{
167 struct zfcp_adapter
*adapter
;
168 wait_queue_head_t completion_wq
;
169 enum zfcp_fc_wka_status status
;
174 struct delayed_work work
;
178 * struct zfcp_fc_wka_ports - Data structures for FC generic services
179 * @ms: FC Management service
180 * @ts: FC time service
181 * @ds: FC directory service
182 * @as: FC alias service
184 struct zfcp_fc_wka_ports
{
185 struct zfcp_fc_wka_port ms
;
186 struct zfcp_fc_wka_port ts
;
187 struct zfcp_fc_wka_port ds
;
188 struct zfcp_fc_wka_port as
;
192 * zfcp_fc_scsi_to_fcp - setup FCP command with data from scsi_cmnd
193 * @fcp: fcp_cmnd to setup
194 * @scsi: scsi_cmnd where to get LUN, task attributes/flags and CDB
197 void zfcp_fc_scsi_to_fcp(struct fcp_cmnd
*fcp
, struct scsi_cmnd
*scsi
)
201 int_to_scsilun(scsi
->device
->lun
, (struct scsi_lun
*) &fcp
->fc_lun
);
203 if (scsi_populate_tag_msg(scsi
, tag
)) {
205 case MSG_ORDERED_TAG
:
206 fcp
->fc_pri_ta
|= FCP_PTA_ORDERED
;
209 fcp
->fc_pri_ta
|= FCP_PTA_SIMPLE
;
213 fcp
->fc_pri_ta
= FCP_PTA_SIMPLE
;
215 if (scsi
->sc_data_direction
== DMA_FROM_DEVICE
)
216 fcp
->fc_flags
|= FCP_CFL_RDDATA
;
217 if (scsi
->sc_data_direction
== DMA_TO_DEVICE
)
218 fcp
->fc_flags
|= FCP_CFL_WRDATA
;
220 memcpy(fcp
->fc_cdb
, scsi
->cmnd
, scsi
->cmd_len
);
222 fcp
->fc_dl
= scsi_bufflen(scsi
);
224 if (scsi_get_prot_type(scsi
) == SCSI_PROT_DIF_TYPE1
)
225 fcp
->fc_dl
+= fcp
->fc_dl
/ scsi
->device
->sector_size
* 8;
229 * zfcp_fc_fcp_tm - setup FCP command as task management command
230 * @fcp: fcp_cmnd to setup
231 * @dev: scsi_device where to send the task management command
232 * @tm: task management flags to setup tm command
235 void zfcp_fc_fcp_tm(struct fcp_cmnd
*fcp
, struct scsi_device
*dev
, u8 tm_flags
)
237 int_to_scsilun(dev
->lun
, (struct scsi_lun
*) &fcp
->fc_lun
);
238 fcp
->fc_tm_flags
|= tm_flags
;
242 * zfcp_fc_evap_fcp_rsp - evaluate FCP RSP IU and update scsi_cmnd accordingly
243 * @fcp_rsp: FCP RSP IU to evaluate
244 * @scsi: SCSI command where to update status and sense buffer
247 void zfcp_fc_eval_fcp_rsp(struct fcp_resp_with_ext
*fcp_rsp
,
248 struct scsi_cmnd
*scsi
)
250 struct fcp_resp_rsp_info
*rsp_info
;
252 u32 sense_len
, resid
;
255 set_msg_byte(scsi
, COMMAND_COMPLETE
);
256 scsi
->result
|= fcp_rsp
->resp
.fr_status
;
258 rsp_flags
= fcp_rsp
->resp
.fr_flags
;
260 if (unlikely(rsp_flags
& FCP_RSP_LEN_VAL
)) {
261 rsp_info
= (struct fcp_resp_rsp_info
*) &fcp_rsp
[1];
262 if (rsp_info
->rsp_code
== FCP_TMF_CMPL
)
263 set_host_byte(scsi
, DID_OK
);
265 set_host_byte(scsi
, DID_ERROR
);
270 if (unlikely(rsp_flags
& FCP_SNS_LEN_VAL
)) {
271 sense
= (char *) &fcp_rsp
[1];
272 if (rsp_flags
& FCP_RSP_LEN_VAL
)
273 sense
+= fcp_rsp
->ext
.fr_rsp_len
;
274 sense_len
= min(fcp_rsp
->ext
.fr_sns_len
,
275 (u32
) SCSI_SENSE_BUFFERSIZE
);
276 memcpy(scsi
->sense_buffer
, sense
, sense_len
);
279 if (unlikely(rsp_flags
& FCP_RESID_UNDER
)) {
280 resid
= fcp_rsp
->ext
.fr_resid
;
281 scsi_set_resid(scsi
, resid
);
282 if (scsi_bufflen(scsi
) - resid
< scsi
->underflow
&&
283 !(rsp_flags
& FCP_SNS_LEN_VAL
) &&
284 fcp_rsp
->resp
.fr_status
== SAM_STAT_GOOD
)
285 set_host_byte(scsi
, DID_ERROR
);