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