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_resp {
72 struct fc_ct_hdr ct_hdr;
73 struct fc_gid_pn_resp gid_pn;
74} __packed;
75
76
77
78
79
80
81
82
83
84struct 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;
91};
92
93
94
95
96
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
105
106
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
115
116
117
118
119struct 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];
123};
124
125
126
127
128
129
130
131
132
133struct 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;
139};
140
141
142
143
144
145
146
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
157
158
159
160
161
162
163
164
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
179
180
181
182
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
191
192
193
194
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 if (scsi_get_prot_type(scsi) == SCSI_PROT_DIF_TYPE1)
225 fcp->fc_dl += fcp->fc_dl / scsi->device->sector_size * 8;
226}
227
228
229
230
231
232
233
234static inline
235void zfcp_fc_fcp_tm(struct fcp_cmnd *fcp, struct scsi_device *dev, u8 tm_flags)
236{
237 int_to_scsilun(dev->lun, (struct scsi_lun *) &fcp->fc_lun);
238 fcp->fc_tm_flags |= tm_flags;
239}
240
241
242
243
244
245
246static inline
247void zfcp_fc_eval_fcp_rsp(struct fcp_resp_with_ext *fcp_rsp,
248 struct scsi_cmnd *scsi)
249{
250 struct fcp_resp_rsp_info *rsp_info;
251 char *sense;
252 u32 sense_len, resid;
253 u8 rsp_flags;
254
255 set_msg_byte(scsi, COMMAND_COMPLETE);
256 scsi->result |= fcp_rsp->resp.fr_status;
257
258 rsp_flags = fcp_rsp->resp.fr_flags;
259
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);
264 else {
265 set_host_byte(scsi, DID_ERROR);
266 return;
267 }
268 }
269
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);
277 }
278
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);
286 }
287}
288
289#endif
290