Commit | Line | Data |
---|---|---|
42e9a92f RL |
1 | /* |
2 | * Copyright(c) 2008 Intel Corporation. All rights reserved. | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or modify it | |
5 | * under the terms and conditions of the GNU General Public License, | |
6 | * version 2, as published by the Free Software Foundation. | |
7 | * | |
8 | * This program is distributed in the hope it will be useful, but WITHOUT | |
9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
11 | * more details. | |
12 | * | |
13 | * You should have received a copy of the GNU General Public License along with | |
14 | * this program; if not, write to the Free Software Foundation, Inc., | |
15 | * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | |
16 | * | |
17 | * Maintained at www.Open-FCoE.org | |
18 | */ | |
19 | ||
20 | #ifndef _FC_ENCODE_H_ | |
21 | #define _FC_ENCODE_H_ | |
22 | #include <asm/unaligned.h> | |
23 | ||
24f089e2 JE |
24 | /* |
25 | * F_CTL values for simple requests and responses. | |
26 | */ | |
27 | #define FC_FCTL_REQ (FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT) | |
28 | #define FC_FCTL_RESP (FC_FC_EX_CTX | FC_FC_LAST_SEQ | \ | |
29 | FC_FC_END_SEQ | FC_FC_SEQ_INIT) | |
30 | ||
42e9a92f RL |
31 | struct fc_ns_rft { |
32 | struct fc_ns_fid fid; /* port ID object */ | |
33 | struct fc_ns_fts fts; /* FC4-types object */ | |
34 | }; | |
35 | ||
36 | struct fc_ct_req { | |
37 | struct fc_ct_hdr hdr; | |
38 | union { | |
39 | struct fc_ns_gid_ft gid; | |
40 | struct fc_ns_rn_id rn; | |
41 | struct fc_ns_rft rft; | |
ab593b18 | 42 | struct fc_ns_rff_id rff; |
2ab7e1ec | 43 | struct fc_ns_fid fid; |
5baa17c3 | 44 | struct fc_ns_rsnn snn; |
c9866a54 | 45 | struct fc_ns_rspn spn; |
42e9a92f RL |
46 | } payload; |
47 | }; | |
48 | ||
49 | /** | |
50 | * fill FC header fields in specified fc_frame | |
51 | */ | |
52 | static inline void fc_fill_fc_hdr(struct fc_frame *fp, enum fc_rctl r_ctl, | |
53 | u32 did, u32 sid, enum fc_fh_type type, | |
54 | u32 f_ctl, u32 parm_offset) | |
55 | { | |
56 | struct fc_frame_header *fh; | |
57 | ||
58 | fh = fc_frame_header_get(fp); | |
59 | WARN_ON(r_ctl == 0); | |
60 | fh->fh_r_ctl = r_ctl; | |
61 | hton24(fh->fh_d_id, did); | |
62 | hton24(fh->fh_s_id, sid); | |
63 | fh->fh_type = type; | |
64 | hton24(fh->fh_f_ctl, f_ctl); | |
65 | fh->fh_cs_ctl = 0; | |
66 | fh->fh_df_ctl = 0; | |
67 | fh->fh_parm_offset = htonl(parm_offset); | |
68 | } | |
69 | ||
370c3bd0 JE |
70 | /** |
71 | * fc_adisc_fill() - Fill in adisc request frame | |
72 | * @lport: local port. | |
73 | * @fp: fc frame where payload will be placed. | |
74 | */ | |
75 | static inline void fc_adisc_fill(struct fc_lport *lport, struct fc_frame *fp) | |
76 | { | |
77 | struct fc_els_adisc *adisc; | |
78 | ||
79 | adisc = fc_frame_payload_get(fp, sizeof(*adisc)); | |
80 | memset(adisc, 0, sizeof(*adisc)); | |
81 | adisc->adisc_cmd = ELS_ADISC; | |
82 | put_unaligned_be64(lport->wwpn, &adisc->adisc_wwpn); | |
83 | put_unaligned_be64(lport->wwnn, &adisc->adisc_wwnn); | |
7b2787ec | 84 | hton24(adisc->adisc_port_id, lport->port_id); |
370c3bd0 JE |
85 | } |
86 | ||
42e9a92f RL |
87 | /** |
88 | * fc_ct_hdr_fill- fills ct header and reset ct payload | |
89 | * returns pointer to ct request. | |
90 | */ | |
91 | static inline struct fc_ct_req *fc_ct_hdr_fill(const struct fc_frame *fp, | |
92 | unsigned int op, size_t req_size) | |
93 | { | |
94 | struct fc_ct_req *ct; | |
95 | size_t ct_plen; | |
96 | ||
97 | ct_plen = sizeof(struct fc_ct_hdr) + req_size; | |
98 | ct = fc_frame_payload_get(fp, ct_plen); | |
99 | memset(ct, 0, ct_plen); | |
100 | ct->hdr.ct_rev = FC_CT_REV; | |
101 | ct->hdr.ct_fs_type = FC_FST_DIR; | |
102 | ct->hdr.ct_fs_subtype = FC_NS_SUBTYPE; | |
103 | ct->hdr.ct_cmd = htons((u16) op); | |
104 | return ct; | |
105 | } | |
106 | ||
107 | /** | |
2ab7e1ec JE |
108 | * fc_ct_fill() - Fill in a name service request frame |
109 | * @lport: local port. | |
110 | * @fc_id: FC_ID of non-destination rport for GPN_ID and similar inquiries. | |
111 | * @fp: frame to contain payload. | |
112 | * @op: CT opcode. | |
113 | * @r_ctl: pointer to FC header R_CTL. | |
114 | * @fh_type: pointer to FC-4 type. | |
42e9a92f | 115 | */ |
a46f327a | 116 | static inline int fc_ct_fill(struct fc_lport *lport, |
2ab7e1ec | 117 | u32 fc_id, struct fc_frame *fp, |
a46f327a | 118 | unsigned int op, enum fc_rctl *r_ctl, |
42e9a92f RL |
119 | enum fc_fh_type *fh_type) |
120 | { | |
121 | struct fc_ct_req *ct; | |
5f9a056d | 122 | size_t len; |
42e9a92f RL |
123 | |
124 | switch (op) { | |
125 | case FC_NS_GPN_FT: | |
126 | ct = fc_ct_hdr_fill(fp, op, sizeof(struct fc_ns_gid_ft)); | |
127 | ct->payload.gid.fn_fc4_type = FC_TYPE_FCP; | |
128 | break; | |
129 | ||
2ab7e1ec JE |
130 | case FC_NS_GPN_ID: |
131 | ct = fc_ct_hdr_fill(fp, op, sizeof(struct fc_ns_fid)); | |
132 | hton24(ct->payload.fid.fp_fid, fc_id); | |
133 | break; | |
134 | ||
42e9a92f RL |
135 | case FC_NS_RFT_ID: |
136 | ct = fc_ct_hdr_fill(fp, op, sizeof(struct fc_ns_rft)); | |
7b2787ec | 137 | hton24(ct->payload.rft.fid.fp_fid, lport->port_id); |
42e9a92f RL |
138 | ct->payload.rft.fts = lport->fcts; |
139 | break; | |
140 | ||
ab593b18 JE |
141 | case FC_NS_RFF_ID: |
142 | ct = fc_ct_hdr_fill(fp, op, sizeof(struct fc_ns_rff_id)); | |
7b2787ec | 143 | hton24(ct->payload.rff.fr_fid.fp_fid, lport->port_id); |
ab593b18 JE |
144 | ct->payload.rff.fr_type = FC_TYPE_FCP; |
145 | if (lport->service_params & FCP_SPPF_INIT_FCN) | |
146 | ct->payload.rff.fr_feat = FCP_FEAT_INIT; | |
147 | if (lport->service_params & FCP_SPPF_TARG_FCN) | |
148 | ct->payload.rff.fr_feat |= FCP_FEAT_TARG; | |
149 | break; | |
150 | ||
c9c7bd7a | 151 | case FC_NS_RNN_ID: |
42e9a92f | 152 | ct = fc_ct_hdr_fill(fp, op, sizeof(struct fc_ns_rn_id)); |
7b2787ec | 153 | hton24(ct->payload.rn.fr_fid.fp_fid, lport->port_id); |
c9c7bd7a | 154 | put_unaligned_be64(lport->wwnn, &ct->payload.rn.fr_wwn); |
42e9a92f RL |
155 | break; |
156 | ||
c9866a54 | 157 | case FC_NS_RSPN_ID: |
5f9a056d JE |
158 | len = strnlen(fc_host_symbolic_name(lport->host), 255); |
159 | ct = fc_ct_hdr_fill(fp, op, sizeof(struct fc_ns_rspn) + len); | |
7b2787ec | 160 | hton24(ct->payload.spn.fr_fid.fp_fid, lport->port_id); |
c9866a54 | 161 | strncpy(ct->payload.spn.fr_name, |
5f9a056d JE |
162 | fc_host_symbolic_name(lport->host), len); |
163 | ct->payload.spn.fr_name_len = len; | |
c9866a54 CL |
164 | break; |
165 | ||
5baa17c3 | 166 | case FC_NS_RSNN_NN: |
5f9a056d JE |
167 | len = strnlen(fc_host_symbolic_name(lport->host), 255); |
168 | ct = fc_ct_hdr_fill(fp, op, sizeof(struct fc_ns_rsnn) + len); | |
5baa17c3 CL |
169 | put_unaligned_be64(lport->wwnn, &ct->payload.snn.fr_wwn); |
170 | strncpy(ct->payload.snn.fr_name, | |
5f9a056d JE |
171 | fc_host_symbolic_name(lport->host), len); |
172 | ct->payload.snn.fr_name_len = len; | |
5baa17c3 CL |
173 | break; |
174 | ||
42e9a92f | 175 | default: |
42e9a92f RL |
176 | return -EINVAL; |
177 | } | |
178 | *r_ctl = FC_RCTL_DD_UNSOL_CTL; | |
42e9a92f RL |
179 | *fh_type = FC_TYPE_CT; |
180 | return 0; | |
181 | } | |
182 | ||
183 | /** | |
184 | * fc_plogi_fill - Fill in plogi request frame | |
185 | */ | |
186 | static inline void fc_plogi_fill(struct fc_lport *lport, struct fc_frame *fp, | |
187 | unsigned int op) | |
188 | { | |
189 | struct fc_els_flogi *plogi; | |
190 | struct fc_els_csp *csp; | |
191 | struct fc_els_cssp *cp; | |
192 | ||
193 | plogi = fc_frame_payload_get(fp, sizeof(*plogi)); | |
194 | memset(plogi, 0, sizeof(*plogi)); | |
195 | plogi->fl_cmd = (u8) op; | |
196 | put_unaligned_be64(lport->wwpn, &plogi->fl_wwpn); | |
197 | put_unaligned_be64(lport->wwnn, &plogi->fl_wwnn); | |
198 | ||
199 | csp = &plogi->fl_csp; | |
200 | csp->sp_hi_ver = 0x20; | |
201 | csp->sp_lo_ver = 0x20; | |
202 | csp->sp_bb_cred = htons(10); /* this gets set by gateway */ | |
203 | csp->sp_bb_data = htons((u16) lport->mfs); | |
204 | cp = &plogi->fl_cssp[3 - 1]; /* class 3 parameters */ | |
205 | cp->cp_class = htons(FC_CPC_VALID | FC_CPC_SEQ); | |
206 | csp->sp_features = htons(FC_SP_FT_CIRO); | |
207 | csp->sp_tot_seq = htons(255); /* seq. we accept */ | |
208 | csp->sp_rel_off = htons(0x1f); | |
209 | csp->sp_e_d_tov = htonl(lport->e_d_tov); | |
210 | ||
211 | cp->cp_rdfs = htons((u16) lport->mfs); | |
212 | cp->cp_con_seq = htons(255); | |
213 | cp->cp_open_seq = 1; | |
214 | } | |
215 | ||
216 | /** | |
217 | * fc_flogi_fill - Fill in a flogi request frame. | |
218 | */ | |
219 | static inline void fc_flogi_fill(struct fc_lport *lport, struct fc_frame *fp) | |
220 | { | |
221 | struct fc_els_csp *sp; | |
222 | struct fc_els_cssp *cp; | |
223 | struct fc_els_flogi *flogi; | |
224 | ||
225 | flogi = fc_frame_payload_get(fp, sizeof(*flogi)); | |
226 | memset(flogi, 0, sizeof(*flogi)); | |
227 | flogi->fl_cmd = (u8) ELS_FLOGI; | |
228 | put_unaligned_be64(lport->wwpn, &flogi->fl_wwpn); | |
229 | put_unaligned_be64(lport->wwnn, &flogi->fl_wwnn); | |
230 | sp = &flogi->fl_csp; | |
231 | sp->sp_hi_ver = 0x20; | |
232 | sp->sp_lo_ver = 0x20; | |
233 | sp->sp_bb_cred = htons(10); /* this gets set by gateway */ | |
234 | sp->sp_bb_data = htons((u16) lport->mfs); | |
235 | cp = &flogi->fl_cssp[3 - 1]; /* class 3 parameters */ | |
236 | cp->cp_class = htons(FC_CPC_VALID | FC_CPC_SEQ); | |
db36c06c CL |
237 | if (lport->does_npiv) |
238 | sp->sp_features = htons(FC_SP_FT_NPIV); | |
239 | } | |
240 | ||
241 | /** | |
242 | * fc_fdisc_fill - Fill in a fdisc request frame. | |
243 | */ | |
244 | static inline void fc_fdisc_fill(struct fc_lport *lport, struct fc_frame *fp) | |
245 | { | |
246 | struct fc_els_csp *sp; | |
247 | struct fc_els_cssp *cp; | |
248 | struct fc_els_flogi *fdisc; | |
249 | ||
250 | fdisc = fc_frame_payload_get(fp, sizeof(*fdisc)); | |
251 | memset(fdisc, 0, sizeof(*fdisc)); | |
252 | fdisc->fl_cmd = (u8) ELS_FDISC; | |
253 | put_unaligned_be64(lport->wwpn, &fdisc->fl_wwpn); | |
254 | put_unaligned_be64(lport->wwnn, &fdisc->fl_wwnn); | |
255 | sp = &fdisc->fl_csp; | |
256 | sp->sp_hi_ver = 0x20; | |
257 | sp->sp_lo_ver = 0x20; | |
258 | sp->sp_bb_cred = htons(10); /* this gets set by gateway */ | |
259 | sp->sp_bb_data = htons((u16) lport->mfs); | |
260 | cp = &fdisc->fl_cssp[3 - 1]; /* class 3 parameters */ | |
261 | cp->cp_class = htons(FC_CPC_VALID | FC_CPC_SEQ); | |
42e9a92f RL |
262 | } |
263 | ||
264 | /** | |
265 | * fc_logo_fill - Fill in a logo request frame. | |
266 | */ | |
267 | static inline void fc_logo_fill(struct fc_lport *lport, struct fc_frame *fp) | |
268 | { | |
269 | struct fc_els_logo *logo; | |
270 | ||
271 | logo = fc_frame_payload_get(fp, sizeof(*logo)); | |
272 | memset(logo, 0, sizeof(*logo)); | |
273 | logo->fl_cmd = ELS_LOGO; | |
7b2787ec | 274 | hton24(logo->fl_n_port_id, lport->port_id); |
42e9a92f RL |
275 | logo->fl_n_port_wwn = htonll(lport->wwpn); |
276 | } | |
277 | ||
278 | /** | |
279 | * fc_rtv_fill - Fill in RTV (read timeout value) request frame. | |
280 | */ | |
281 | static inline void fc_rtv_fill(struct fc_lport *lport, struct fc_frame *fp) | |
282 | { | |
283 | struct fc_els_rtv *rtv; | |
284 | ||
285 | rtv = fc_frame_payload_get(fp, sizeof(*rtv)); | |
286 | memset(rtv, 0, sizeof(*rtv)); | |
287 | rtv->rtv_cmd = ELS_RTV; | |
288 | } | |
289 | ||
290 | /** | |
291 | * fc_rec_fill - Fill in rec request frame | |
292 | */ | |
293 | static inline void fc_rec_fill(struct fc_lport *lport, struct fc_frame *fp) | |
294 | { | |
295 | struct fc_els_rec *rec; | |
296 | struct fc_exch *ep = fc_seq_exch(fr_seq(fp)); | |
297 | ||
298 | rec = fc_frame_payload_get(fp, sizeof(*rec)); | |
299 | memset(rec, 0, sizeof(*rec)); | |
300 | rec->rec_cmd = ELS_REC; | |
7b2787ec | 301 | hton24(rec->rec_s_id, lport->port_id); |
42e9a92f RL |
302 | rec->rec_ox_id = htons(ep->oxid); |
303 | rec->rec_rx_id = htons(ep->rxid); | |
304 | } | |
305 | ||
306 | /** | |
307 | * fc_prli_fill - Fill in prli request frame | |
308 | */ | |
309 | static inline void fc_prli_fill(struct fc_lport *lport, struct fc_frame *fp) | |
310 | { | |
311 | struct { | |
312 | struct fc_els_prli prli; | |
313 | struct fc_els_spp spp; | |
314 | } *pp; | |
315 | ||
316 | pp = fc_frame_payload_get(fp, sizeof(*pp)); | |
317 | memset(pp, 0, sizeof(*pp)); | |
318 | pp->prli.prli_cmd = ELS_PRLI; | |
319 | pp->prli.prli_spp_len = sizeof(struct fc_els_spp); | |
320 | pp->prli.prli_len = htons(sizeof(*pp)); | |
321 | pp->spp.spp_type = FC_TYPE_FCP; | |
322 | pp->spp.spp_flags = FC_SPP_EST_IMG_PAIR; | |
323 | pp->spp.spp_params = htonl(lport->service_params); | |
324 | } | |
325 | ||
326 | /** | |
327 | * fc_scr_fill - Fill in a scr request frame. | |
328 | */ | |
329 | static inline void fc_scr_fill(struct fc_lport *lport, struct fc_frame *fp) | |
330 | { | |
331 | struct fc_els_scr *scr; | |
332 | ||
333 | scr = fc_frame_payload_get(fp, sizeof(*scr)); | |
334 | memset(scr, 0, sizeof(*scr)); | |
335 | scr->scr_cmd = ELS_SCR; | |
336 | scr->scr_reg_func = ELS_SCRF_FULL; | |
337 | } | |
338 | ||
339 | /** | |
340 | * fc_els_fill - Fill in an ELS request frame | |
341 | */ | |
9fb9d328 | 342 | static inline int fc_els_fill(struct fc_lport *lport, |
a46f327a | 343 | u32 did, |
42e9a92f | 344 | struct fc_frame *fp, unsigned int op, |
a46f327a | 345 | enum fc_rctl *r_ctl, enum fc_fh_type *fh_type) |
42e9a92f RL |
346 | { |
347 | switch (op) { | |
370c3bd0 JE |
348 | case ELS_ADISC: |
349 | fc_adisc_fill(lport, fp); | |
350 | break; | |
351 | ||
42e9a92f RL |
352 | case ELS_PLOGI: |
353 | fc_plogi_fill(lport, fp, ELS_PLOGI); | |
42e9a92f RL |
354 | break; |
355 | ||
356 | case ELS_FLOGI: | |
357 | fc_flogi_fill(lport, fp); | |
42e9a92f RL |
358 | break; |
359 | ||
db36c06c CL |
360 | case ELS_FDISC: |
361 | fc_fdisc_fill(lport, fp); | |
362 | break; | |
363 | ||
42e9a92f RL |
364 | case ELS_LOGO: |
365 | fc_logo_fill(lport, fp); | |
42e9a92f RL |
366 | break; |
367 | ||
368 | case ELS_RTV: | |
369 | fc_rtv_fill(lport, fp); | |
42e9a92f RL |
370 | break; |
371 | ||
372 | case ELS_REC: | |
373 | fc_rec_fill(lport, fp); | |
42e9a92f RL |
374 | break; |
375 | ||
376 | case ELS_PRLI: | |
377 | fc_prli_fill(lport, fp); | |
42e9a92f RL |
378 | break; |
379 | ||
380 | case ELS_SCR: | |
381 | fc_scr_fill(lport, fp); | |
42e9a92f RL |
382 | break; |
383 | ||
384 | default: | |
42e9a92f RL |
385 | return -EINVAL; |
386 | } | |
387 | ||
388 | *r_ctl = FC_RCTL_ELS_REQ; | |
389 | *fh_type = FC_TYPE_ELS; | |
390 | return 0; | |
391 | } | |
392 | #endif /* _FC_ENCODE_H_ */ |