]>
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; | |
35 | } payload; | |
36 | }; | |
37 | ||
38 | /** | |
39 | * fill FC header fields in specified fc_frame | |
40 | */ | |
41 | static inline void fc_fill_fc_hdr(struct fc_frame *fp, enum fc_rctl r_ctl, | |
42 | u32 did, u32 sid, enum fc_fh_type type, | |
43 | u32 f_ctl, u32 parm_offset) | |
44 | { | |
45 | struct fc_frame_header *fh; | |
46 | ||
47 | fh = fc_frame_header_get(fp); | |
48 | WARN_ON(r_ctl == 0); | |
49 | fh->fh_r_ctl = r_ctl; | |
50 | hton24(fh->fh_d_id, did); | |
51 | hton24(fh->fh_s_id, sid); | |
52 | fh->fh_type = type; | |
53 | hton24(fh->fh_f_ctl, f_ctl); | |
54 | fh->fh_cs_ctl = 0; | |
55 | fh->fh_df_ctl = 0; | |
56 | fh->fh_parm_offset = htonl(parm_offset); | |
57 | } | |
58 | ||
370c3bd0 JE |
59 | /** |
60 | * fc_adisc_fill() - Fill in adisc request frame | |
61 | * @lport: local port. | |
62 | * @fp: fc frame where payload will be placed. | |
63 | */ | |
64 | static inline void fc_adisc_fill(struct fc_lport *lport, struct fc_frame *fp) | |
65 | { | |
66 | struct fc_els_adisc *adisc; | |
67 | ||
68 | adisc = fc_frame_payload_get(fp, sizeof(*adisc)); | |
69 | memset(adisc, 0, sizeof(*adisc)); | |
70 | adisc->adisc_cmd = ELS_ADISC; | |
71 | put_unaligned_be64(lport->wwpn, &adisc->adisc_wwpn); | |
72 | put_unaligned_be64(lport->wwnn, &adisc->adisc_wwnn); | |
73 | hton24(adisc->adisc_port_id, fc_host_port_id(lport->host)); | |
74 | } | |
75 | ||
42e9a92f RL |
76 | /** |
77 | * fc_ct_hdr_fill- fills ct header and reset ct payload | |
78 | * returns pointer to ct request. | |
79 | */ | |
80 | static inline struct fc_ct_req *fc_ct_hdr_fill(const struct fc_frame *fp, | |
81 | unsigned int op, size_t req_size) | |
82 | { | |
83 | struct fc_ct_req *ct; | |
84 | size_t ct_plen; | |
85 | ||
86 | ct_plen = sizeof(struct fc_ct_hdr) + req_size; | |
87 | ct = fc_frame_payload_get(fp, ct_plen); | |
88 | memset(ct, 0, ct_plen); | |
89 | ct->hdr.ct_rev = FC_CT_REV; | |
90 | ct->hdr.ct_fs_type = FC_FST_DIR; | |
91 | ct->hdr.ct_fs_subtype = FC_NS_SUBTYPE; | |
92 | ct->hdr.ct_cmd = htons((u16) op); | |
93 | return ct; | |
94 | } | |
95 | ||
96 | /** | |
97 | * fc_ct_fill - Fill in a name service request frame | |
98 | */ | |
a46f327a JE |
99 | static inline int fc_ct_fill(struct fc_lport *lport, |
100 | struct fc_frame *fp, | |
101 | unsigned int op, enum fc_rctl *r_ctl, | |
42e9a92f RL |
102 | enum fc_fh_type *fh_type) |
103 | { | |
104 | struct fc_ct_req *ct; | |
105 | ||
106 | switch (op) { | |
107 | case FC_NS_GPN_FT: | |
108 | ct = fc_ct_hdr_fill(fp, op, sizeof(struct fc_ns_gid_ft)); | |
109 | ct->payload.gid.fn_fc4_type = FC_TYPE_FCP; | |
110 | break; | |
111 | ||
112 | case FC_NS_RFT_ID: | |
113 | ct = fc_ct_hdr_fill(fp, op, sizeof(struct fc_ns_rft)); | |
114 | hton24(ct->payload.rft.fid.fp_fid, | |
115 | fc_host_port_id(lport->host)); | |
116 | ct->payload.rft.fts = lport->fcts; | |
117 | break; | |
118 | ||
119 | case FC_NS_RPN_ID: | |
120 | ct = fc_ct_hdr_fill(fp, op, sizeof(struct fc_ns_rn_id)); | |
121 | hton24(ct->payload.rn.fr_fid.fp_fid, | |
122 | fc_host_port_id(lport->host)); | |
123 | ct->payload.rft.fts = lport->fcts; | |
124 | put_unaligned_be64(lport->wwpn, &ct->payload.rn.fr_wwn); | |
125 | break; | |
126 | ||
127 | default: | |
42e9a92f RL |
128 | return -EINVAL; |
129 | } | |
130 | *r_ctl = FC_RCTL_DD_UNSOL_CTL; | |
42e9a92f RL |
131 | *fh_type = FC_TYPE_CT; |
132 | return 0; | |
133 | } | |
134 | ||
135 | /** | |
136 | * fc_plogi_fill - Fill in plogi request frame | |
137 | */ | |
138 | static inline void fc_plogi_fill(struct fc_lport *lport, struct fc_frame *fp, | |
139 | unsigned int op) | |
140 | { | |
141 | struct fc_els_flogi *plogi; | |
142 | struct fc_els_csp *csp; | |
143 | struct fc_els_cssp *cp; | |
144 | ||
145 | plogi = fc_frame_payload_get(fp, sizeof(*plogi)); | |
146 | memset(plogi, 0, sizeof(*plogi)); | |
147 | plogi->fl_cmd = (u8) op; | |
148 | put_unaligned_be64(lport->wwpn, &plogi->fl_wwpn); | |
149 | put_unaligned_be64(lport->wwnn, &plogi->fl_wwnn); | |
150 | ||
151 | csp = &plogi->fl_csp; | |
152 | csp->sp_hi_ver = 0x20; | |
153 | csp->sp_lo_ver = 0x20; | |
154 | csp->sp_bb_cred = htons(10); /* this gets set by gateway */ | |
155 | csp->sp_bb_data = htons((u16) lport->mfs); | |
156 | cp = &plogi->fl_cssp[3 - 1]; /* class 3 parameters */ | |
157 | cp->cp_class = htons(FC_CPC_VALID | FC_CPC_SEQ); | |
158 | csp->sp_features = htons(FC_SP_FT_CIRO); | |
159 | csp->sp_tot_seq = htons(255); /* seq. we accept */ | |
160 | csp->sp_rel_off = htons(0x1f); | |
161 | csp->sp_e_d_tov = htonl(lport->e_d_tov); | |
162 | ||
163 | cp->cp_rdfs = htons((u16) lport->mfs); | |
164 | cp->cp_con_seq = htons(255); | |
165 | cp->cp_open_seq = 1; | |
166 | } | |
167 | ||
168 | /** | |
169 | * fc_flogi_fill - Fill in a flogi request frame. | |
170 | */ | |
171 | static inline void fc_flogi_fill(struct fc_lport *lport, struct fc_frame *fp) | |
172 | { | |
173 | struct fc_els_csp *sp; | |
174 | struct fc_els_cssp *cp; | |
175 | struct fc_els_flogi *flogi; | |
176 | ||
177 | flogi = fc_frame_payload_get(fp, sizeof(*flogi)); | |
178 | memset(flogi, 0, sizeof(*flogi)); | |
179 | flogi->fl_cmd = (u8) ELS_FLOGI; | |
180 | put_unaligned_be64(lport->wwpn, &flogi->fl_wwpn); | |
181 | put_unaligned_be64(lport->wwnn, &flogi->fl_wwnn); | |
182 | sp = &flogi->fl_csp; | |
183 | sp->sp_hi_ver = 0x20; | |
184 | sp->sp_lo_ver = 0x20; | |
185 | sp->sp_bb_cred = htons(10); /* this gets set by gateway */ | |
186 | sp->sp_bb_data = htons((u16) lport->mfs); | |
187 | cp = &flogi->fl_cssp[3 - 1]; /* class 3 parameters */ | |
188 | cp->cp_class = htons(FC_CPC_VALID | FC_CPC_SEQ); | |
189 | } | |
190 | ||
191 | /** | |
192 | * fc_logo_fill - Fill in a logo request frame. | |
193 | */ | |
194 | static inline void fc_logo_fill(struct fc_lport *lport, struct fc_frame *fp) | |
195 | { | |
196 | struct fc_els_logo *logo; | |
197 | ||
198 | logo = fc_frame_payload_get(fp, sizeof(*logo)); | |
199 | memset(logo, 0, sizeof(*logo)); | |
200 | logo->fl_cmd = ELS_LOGO; | |
201 | hton24(logo->fl_n_port_id, fc_host_port_id(lport->host)); | |
202 | logo->fl_n_port_wwn = htonll(lport->wwpn); | |
203 | } | |
204 | ||
205 | /** | |
206 | * fc_rtv_fill - Fill in RTV (read timeout value) request frame. | |
207 | */ | |
208 | static inline void fc_rtv_fill(struct fc_lport *lport, struct fc_frame *fp) | |
209 | { | |
210 | struct fc_els_rtv *rtv; | |
211 | ||
212 | rtv = fc_frame_payload_get(fp, sizeof(*rtv)); | |
213 | memset(rtv, 0, sizeof(*rtv)); | |
214 | rtv->rtv_cmd = ELS_RTV; | |
215 | } | |
216 | ||
217 | /** | |
218 | * fc_rec_fill - Fill in rec request frame | |
219 | */ | |
220 | static inline void fc_rec_fill(struct fc_lport *lport, struct fc_frame *fp) | |
221 | { | |
222 | struct fc_els_rec *rec; | |
223 | struct fc_exch *ep = fc_seq_exch(fr_seq(fp)); | |
224 | ||
225 | rec = fc_frame_payload_get(fp, sizeof(*rec)); | |
226 | memset(rec, 0, sizeof(*rec)); | |
227 | rec->rec_cmd = ELS_REC; | |
228 | hton24(rec->rec_s_id, fc_host_port_id(lport->host)); | |
229 | rec->rec_ox_id = htons(ep->oxid); | |
230 | rec->rec_rx_id = htons(ep->rxid); | |
231 | } | |
232 | ||
233 | /** | |
234 | * fc_prli_fill - Fill in prli request frame | |
235 | */ | |
236 | static inline void fc_prli_fill(struct fc_lport *lport, struct fc_frame *fp) | |
237 | { | |
238 | struct { | |
239 | struct fc_els_prli prli; | |
240 | struct fc_els_spp spp; | |
241 | } *pp; | |
242 | ||
243 | pp = fc_frame_payload_get(fp, sizeof(*pp)); | |
244 | memset(pp, 0, sizeof(*pp)); | |
245 | pp->prli.prli_cmd = ELS_PRLI; | |
246 | pp->prli.prli_spp_len = sizeof(struct fc_els_spp); | |
247 | pp->prli.prli_len = htons(sizeof(*pp)); | |
248 | pp->spp.spp_type = FC_TYPE_FCP; | |
249 | pp->spp.spp_flags = FC_SPP_EST_IMG_PAIR; | |
250 | pp->spp.spp_params = htonl(lport->service_params); | |
251 | } | |
252 | ||
253 | /** | |
254 | * fc_scr_fill - Fill in a scr request frame. | |
255 | */ | |
256 | static inline void fc_scr_fill(struct fc_lport *lport, struct fc_frame *fp) | |
257 | { | |
258 | struct fc_els_scr *scr; | |
259 | ||
260 | scr = fc_frame_payload_get(fp, sizeof(*scr)); | |
261 | memset(scr, 0, sizeof(*scr)); | |
262 | scr->scr_cmd = ELS_SCR; | |
263 | scr->scr_reg_func = ELS_SCRF_FULL; | |
264 | } | |
265 | ||
266 | /** | |
267 | * fc_els_fill - Fill in an ELS request frame | |
268 | */ | |
9fb9d328 | 269 | static inline int fc_els_fill(struct fc_lport *lport, |
a46f327a | 270 | u32 did, |
42e9a92f | 271 | struct fc_frame *fp, unsigned int op, |
a46f327a | 272 | enum fc_rctl *r_ctl, enum fc_fh_type *fh_type) |
42e9a92f RL |
273 | { |
274 | switch (op) { | |
370c3bd0 JE |
275 | case ELS_ADISC: |
276 | fc_adisc_fill(lport, fp); | |
277 | break; | |
278 | ||
42e9a92f RL |
279 | case ELS_PLOGI: |
280 | fc_plogi_fill(lport, fp, ELS_PLOGI); | |
42e9a92f RL |
281 | break; |
282 | ||
283 | case ELS_FLOGI: | |
284 | fc_flogi_fill(lport, fp); | |
42e9a92f RL |
285 | break; |
286 | ||
287 | case ELS_LOGO: | |
288 | fc_logo_fill(lport, fp); | |
42e9a92f RL |
289 | break; |
290 | ||
291 | case ELS_RTV: | |
292 | fc_rtv_fill(lport, fp); | |
42e9a92f RL |
293 | break; |
294 | ||
295 | case ELS_REC: | |
296 | fc_rec_fill(lport, fp); | |
42e9a92f RL |
297 | break; |
298 | ||
299 | case ELS_PRLI: | |
300 | fc_prli_fill(lport, fp); | |
42e9a92f RL |
301 | break; |
302 | ||
303 | case ELS_SCR: | |
304 | fc_scr_fill(lport, fp); | |
42e9a92f RL |
305 | break; |
306 | ||
307 | default: | |
42e9a92f RL |
308 | return -EINVAL; |
309 | } | |
310 | ||
311 | *r_ctl = FC_RCTL_ELS_REQ; | |
312 | *fh_type = FC_TYPE_ELS; | |
313 | return 0; | |
314 | } | |
315 | #endif /* _FC_ENCODE_H_ */ |