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