[SCSI] zfcp: Enable data division support for FCP devices
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / s390 / scsi / zfcp_fc.h
CommitLineData
4318e08c
CS
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
10#ifndef ZFCP_FC_H
11#define ZFCP_FC_H
12
9d05ce2c 13#include <scsi/fc/fc_els.h>
4318e08c 14#include <scsi/fc/fc_fcp.h>
dbf5dfe9 15#include <scsi/fc/fc_ns.h>
4318e08c
CS
16#include <scsi/scsi_cmnd.h>
17#include <scsi/scsi_tcq.h>
7c7dc196 18#include "zfcp_fsf.h"
4318e08c 19
dbf5dfe9
CS
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 */
24
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))
29
51375ee8
SS
30#define ZFCP_FC_CTELS_TMO (2 * FC_DEF_R_A_TOV / 1000)
31
2d1e547f
SS
32/**
33 * struct zfcp_fc_event - FC HBAAPI event for internal queueing from irq context
34 * @code: Event code
35 * @data: Event data
36 * @list: list_head for zfcp_fc_events list
37 */
38struct zfcp_fc_event {
39 enum fc_host_event_code code;
40 u32 data;
41 struct list_head list;
42};
43
44/**
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
49*/
50struct zfcp_fc_events {
51 struct list_head list;
52 spinlock_t list_lock;
53 struct work_struct work;
54};
55
dbf5dfe9
CS
56/**
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
60 */
61struct zfcp_fc_gid_pn_req {
62 struct fc_ct_hdr ct_hdr;
63 struct fc_ns_gid_pn gid_pn;
64} __packed;
65
66/**
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
70 */
71struct zfcp_fc_gid_pn_resp {
72 struct fc_ct_hdr ct_hdr;
73 struct fc_gid_pn_resp gid_pn;
74} __packed;
75
76/**
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
83 */
84struct zfcp_fc_gid_pn {
7c7dc196 85 struct zfcp_fsf_ct_els ct;
dbf5dfe9
CS
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;
91};
92
93/**
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
97 */
98struct zfcp_fc_gpn_ft_req {
99 struct fc_ct_hdr ct_hdr;
100 struct fc_ns_gid_ft gpn_ft;
101} __packed;
102
103/**
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
107 */
108struct 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];
111} __packed;
112
113/**
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)
118 */
119struct zfcp_fc_gpn_ft {
7c7dc196 120 struct zfcp_fsf_ct_els ct;
dbf5dfe9
CS
121 struct scatterlist sg_req;
122 struct scatterlist sg_resp[ZFCP_FC_GPN_FT_NUM_BUFS];
123};
124
9d05ce2c
CS
125/**
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
132 */
133struct zfcp_fc_els_adisc {
7c7dc196 134 struct zfcp_fsf_ct_els els;
9d05ce2c
CS
135 struct scatterlist req;
136 struct scatterlist resp;
137 struct fc_els_adisc adisc_req;
138 struct fc_els_adisc adisc_resp;
139};
140
bd0072ec
CS
141/**
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
147 */
148enum 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,
153};
154
155/**
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
165 */
166struct zfcp_fc_wka_port {
167 struct zfcp_adapter *adapter;
168 wait_queue_head_t completion_wq;
169 enum zfcp_fc_wka_status status;
170 atomic_t refcount;
171 u32 d_id;
172 u32 handle;
173 struct mutex mutex;
174 struct delayed_work work;
175};
176
177/**
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
183 */
184struct 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;
189};
190
4318e08c
CS
191/**
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
195 */
196static inline
197void zfcp_fc_scsi_to_fcp(struct fcp_cmnd *fcp, struct scsi_cmnd *scsi)
198{
199 char tag[2];
200
201 int_to_scsilun(scsi->device->lun, (struct scsi_lun *) &fcp->fc_lun);
202
203 if (scsi_populate_tag_msg(scsi, tag)) {
204 switch (tag[0]) {
205 case MSG_ORDERED_TAG:
206 fcp->fc_pri_ta |= FCP_PTA_ORDERED;
207 break;
208 case MSG_SIMPLE_TAG:
209 fcp->fc_pri_ta |= FCP_PTA_SIMPLE;
210 break;
211 };
212 } else
213 fcp->fc_pri_ta = FCP_PTA_SIMPLE;
214
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;
219
220 memcpy(fcp->fc_cdb, scsi->cmnd, scsi->cmd_len);
221
222 fcp->fc_dl = scsi_bufflen(scsi);
223}
224
225/**
226 * zfcp_fc_fcp_tm - setup FCP command as task management command
227 * @fcp: fcp_cmnd to setup
228 * @dev: scsi_device where to send the task management command
229 * @tm: task management flags to setup tm command
230 */
231static inline
232void zfcp_fc_fcp_tm(struct fcp_cmnd *fcp, struct scsi_device *dev, u8 tm_flags)
233{
234 int_to_scsilun(dev->lun, (struct scsi_lun *) &fcp->fc_lun);
235 fcp->fc_tm_flags |= tm_flags;
236}
237
238/**
239 * zfcp_fc_evap_fcp_rsp - evaluate FCP RSP IU and update scsi_cmnd accordingly
240 * @fcp_rsp: FCP RSP IU to evaluate
241 * @scsi: SCSI command where to update status and sense buffer
242 */
243static inline
244void zfcp_fc_eval_fcp_rsp(struct fcp_resp_with_ext *fcp_rsp,
245 struct scsi_cmnd *scsi)
246{
247 struct fcp_resp_rsp_info *rsp_info;
248 char *sense;
249 u32 sense_len, resid;
250 u8 rsp_flags;
251
252 set_msg_byte(scsi, COMMAND_COMPLETE);
253 scsi->result |= fcp_rsp->resp.fr_status;
254
255 rsp_flags = fcp_rsp->resp.fr_flags;
256
257 if (unlikely(rsp_flags & FCP_RSP_LEN_VAL)) {
258 rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1];
259 if (rsp_info->rsp_code == FCP_TMF_CMPL)
260 set_host_byte(scsi, DID_OK);
261 else {
262 set_host_byte(scsi, DID_ERROR);
263 return;
264 }
265 }
266
267 if (unlikely(rsp_flags & FCP_SNS_LEN_VAL)) {
268 sense = (char *) &fcp_rsp[1];
269 if (rsp_flags & FCP_RSP_LEN_VAL)
270 sense += fcp_rsp->ext.fr_sns_len;
271 sense_len = min(fcp_rsp->ext.fr_sns_len,
272 (u32) SCSI_SENSE_BUFFERSIZE);
273 memcpy(scsi->sense_buffer, sense, sense_len);
274 }
275
276 if (unlikely(rsp_flags & FCP_RESID_UNDER)) {
277 resid = fcp_rsp->ext.fr_resid;
278 scsi_set_resid(scsi, resid);
279 if (scsi_bufflen(scsi) - resid < scsi->underflow &&
280 !(rsp_flags & FCP_SNS_LEN_VAL) &&
281 fcp_rsp->resp.fr_status == SAM_STAT_GOOD)
282 set_host_byte(scsi, DID_ERROR);
283 }
284}
285
286#endif