Linux Audio

Check our new training course

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