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