1
2
3
4
5
6
7
8
9
10
11#ifndef ZFCP_FC_H
12#define ZFCP_FC_H
13
14#include <scsi/fc/fc_els.h>
15#include <scsi/fc/fc_fcp.h>
16#include <scsi/fc/fc_ns.h>
17#include <scsi/scsi_cmnd.h>
18#include <scsi/scsi_tcq.h>
19#include "zfcp_fsf.h"
20
21#define ZFCP_FC_CT_SIZE_PAGE (PAGE_SIZE - sizeof(struct fc_ct_hdr))
22#define ZFCP_FC_GPN_FT_ENT_PAGE (ZFCP_FC_CT_SIZE_PAGE \
23 / sizeof(struct fc_gpn_ft_resp))
24#define ZFCP_FC_GPN_FT_NUM_BUFS 4
25
26#define ZFCP_FC_GPN_FT_MAX_SIZE (ZFCP_FC_GPN_FT_NUM_BUFS * PAGE_SIZE \
27 - sizeof(struct fc_ct_hdr))
28#define ZFCP_FC_GPN_FT_MAX_ENT (ZFCP_FC_GPN_FT_NUM_BUFS * \
29 (ZFCP_FC_GPN_FT_ENT_PAGE + 1))
30
31#define ZFCP_FC_CTELS_TMO (2 * FC_DEF_R_A_TOV / 1000)
32
33
34
35
36
37
38
39struct zfcp_fc_event {
40 enum fc_host_event_code code;
41 u32 data;
42 struct list_head list;
43};
44
45
46
47
48
49
50
51struct zfcp_fc_events {
52 struct list_head list;
53 spinlock_t list_lock;
54 struct work_struct work;
55};
56
57
58
59
60
61
62struct zfcp_fc_gid_pn_req {
63 struct fc_ct_hdr ct_hdr;
64 struct fc_ns_gid_pn gid_pn;
65} __packed;
66
67
68
69
70
71
72struct zfcp_fc_gid_pn_rsp {
73 struct fc_ct_hdr ct_hdr;
74 struct fc_gid_pn_resp gid_pn;
75} __packed;
76
77
78
79
80
81
82struct zfcp_fc_gpn_ft_req {
83 struct fc_ct_hdr ct_hdr;
84 struct fc_ns_gid_ft gpn_ft;
85} __packed;
86
87
88
89
90
91
92struct zfcp_fc_gspn_req {
93 struct fc_ct_hdr ct_hdr;
94 struct fc_gid_pn_resp gspn;
95} __packed;
96
97
98
99
100
101
102
103struct zfcp_fc_gspn_rsp {
104 struct fc_ct_hdr ct_hdr;
105 struct fc_gspn_resp gspn;
106 char name[FC_SYMBOLIC_NAME_SIZE];
107} __packed;
108
109
110
111
112
113
114
115struct zfcp_fc_rspn_req {
116 struct fc_ct_hdr ct_hdr;
117 struct fc_ns_rspn rspn;
118 char name[FC_SYMBOLIC_NAME_SIZE];
119} __packed;
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143struct zfcp_fc_req {
144 struct zfcp_fsf_ct_els ct_els;
145 struct scatterlist sg_req;
146 struct scatterlist sg_rsp;
147 union {
148 struct {
149 struct fc_els_adisc req;
150 struct fc_els_adisc rsp;
151 } adisc;
152 struct {
153 struct zfcp_fc_gid_pn_req req;
154 struct zfcp_fc_gid_pn_rsp rsp;
155 } gid_pn;
156 struct {
157 struct scatterlist sg_rsp2[ZFCP_FC_GPN_FT_NUM_BUFS - 1];
158 struct zfcp_fc_gpn_ft_req req;
159 } gpn_ft;
160 struct {
161 struct zfcp_fc_gspn_req req;
162 struct zfcp_fc_gspn_rsp rsp;
163 } gspn;
164 struct {
165 struct zfcp_fc_rspn_req req;
166 struct fc_ct_hdr rsp;
167 } rspn;
168 } u;
169};
170
171
172
173
174
175
176
177
178enum zfcp_fc_wka_status {
179 ZFCP_FC_WKA_PORT_OFFLINE,
180 ZFCP_FC_WKA_PORT_CLOSING,
181 ZFCP_FC_WKA_PORT_OPENING,
182 ZFCP_FC_WKA_PORT_ONLINE,
183};
184
185
186
187
188
189
190
191
192
193
194
195
196struct zfcp_fc_wka_port {
197 struct zfcp_adapter *adapter;
198 wait_queue_head_t completion_wq;
199 enum zfcp_fc_wka_status status;
200 atomic_t refcount;
201 u32 d_id;
202 u32 handle;
203 struct mutex mutex;
204 struct delayed_work work;
205};
206
207
208
209
210
211
212
213
214struct zfcp_fc_wka_ports {
215 struct zfcp_fc_wka_port ms;
216 struct zfcp_fc_wka_port ts;
217 struct zfcp_fc_wka_port ds;
218 struct zfcp_fc_wka_port as;
219};
220
221
222
223
224
225
226static inline
227void zfcp_fc_scsi_to_fcp(struct fcp_cmnd *fcp, struct scsi_cmnd *scsi)
228{
229 u32 datalen;
230
231 int_to_scsilun(scsi->device->lun, (struct scsi_lun *) &fcp->fc_lun);
232
233 fcp->fc_pri_ta = FCP_PTA_SIMPLE;
234
235 if (scsi->sc_data_direction == DMA_FROM_DEVICE)
236 fcp->fc_flags |= FCP_CFL_RDDATA;
237 if (scsi->sc_data_direction == DMA_TO_DEVICE)
238 fcp->fc_flags |= FCP_CFL_WRDATA;
239
240 memcpy(fcp->fc_cdb, scsi->cmnd, scsi->cmd_len);
241
242 datalen = scsi_bufflen(scsi);
243 fcp->fc_dl = cpu_to_be32(datalen);
244
245 if (scsi_get_prot_type(scsi) == SCSI_PROT_DIF_TYPE1) {
246 datalen += datalen / scsi->device->sector_size * 8;
247 fcp->fc_dl = cpu_to_be32(datalen);
248 }
249}
250
251
252
253
254
255
256
257static inline
258void zfcp_fc_fcp_tm(struct fcp_cmnd *fcp, struct scsi_device *dev, u8 tm_flags)
259{
260 int_to_scsilun(dev->lun, (struct scsi_lun *) &fcp->fc_lun);
261 fcp->fc_tm_flags = tm_flags;
262}
263
264
265
266
267
268
269static inline
270void zfcp_fc_eval_fcp_rsp(struct fcp_resp_with_ext *fcp_rsp,
271 struct scsi_cmnd *scsi)
272{
273 struct fcp_resp_rsp_info *rsp_info;
274 char *sense;
275 u32 sense_len, resid;
276 u8 rsp_flags;
277
278 scsi->result |= fcp_rsp->resp.fr_status;
279
280 rsp_flags = fcp_rsp->resp.fr_flags;
281
282 if (unlikely(rsp_flags & FCP_RSP_LEN_VAL)) {
283 rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1];
284 if (rsp_info->rsp_code == FCP_TMF_CMPL)
285 set_host_byte(scsi, DID_OK);
286 else {
287 set_host_byte(scsi, DID_ERROR);
288 return;
289 }
290 }
291
292 if (unlikely(rsp_flags & FCP_SNS_LEN_VAL)) {
293 sense = (char *) &fcp_rsp[1];
294 if (rsp_flags & FCP_RSP_LEN_VAL)
295 sense += be32_to_cpu(fcp_rsp->ext.fr_rsp_len);
296 sense_len = min_t(u32, be32_to_cpu(fcp_rsp->ext.fr_sns_len),
297 SCSI_SENSE_BUFFERSIZE);
298 memcpy(scsi->sense_buffer, sense, sense_len);
299 }
300
301 if (unlikely(rsp_flags & FCP_RESID_UNDER)) {
302 resid = be32_to_cpu(fcp_rsp->ext.fr_resid);
303 scsi_set_resid(scsi, resid);
304 if (scsi_bufflen(scsi) - resid < scsi->underflow &&
305 !(rsp_flags & FCP_SNS_LEN_VAL) &&
306 fcp_rsp->resp.fr_status == SAM_STAT_GOOD)
307 set_host_byte(scsi, DID_ERROR);
308 } else if (unlikely(rsp_flags & FCP_RESID_OVER)) {
309
310 if (fcp_rsp->resp.fr_status == SAM_STAT_GOOD)
311 set_host_byte(scsi, DID_ERROR);
312 }
313}
314
315#endif
316