mwl8k: ->add_interface() is not called for monitor interfaces
[wandboard.git] / include / scsi / fc_encode.h
bloba0ff61c3e935f4a18b32221b39b924e9e6fefb04
1 /*
2 * Copyright(c) 2008 Intel Corporation. All rights reserved.
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.
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.
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.
17 * Maintained at www.Open-FCoE.org
20 #ifndef _FC_ENCODE_H_
21 #define _FC_ENCODE_H_
22 #include <asm/unaligned.h>
24 struct fc_ns_rft {
25 struct fc_ns_fid fid; /* port ID object */
26 struct fc_ns_fts fts; /* FC4-types object */
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;
38 /**
39 * fill FC header fields in specified fc_frame
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)
45 struct fc_frame_header *fh;
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);
59 /**
60 * fc_ct_hdr_fill- fills ct header and reset ct payload
61 * returns pointer to ct request.
63 static inline struct fc_ct_req *fc_ct_hdr_fill(const struct fc_frame *fp,
64 unsigned int op, size_t req_size)
66 struct fc_ct_req *ct;
67 size_t ct_plen;
69 ct_plen = sizeof(struct fc_ct_hdr) + req_size;
70 ct = fc_frame_payload_get(fp, ct_plen);
71 memset(ct, 0, ct_plen);
72 ct->hdr.ct_rev = FC_CT_REV;
73 ct->hdr.ct_fs_type = FC_FST_DIR;
74 ct->hdr.ct_fs_subtype = FC_NS_SUBTYPE;
75 ct->hdr.ct_cmd = htons((u16) op);
76 return ct;
79 /**
80 * fc_ct_fill - Fill in a name service request frame
82 static inline int fc_ct_fill(struct fc_lport *lport, struct fc_frame *fp,
83 unsigned int op, enum fc_rctl *r_ctl, u32 *did,
84 enum fc_fh_type *fh_type)
86 struct fc_ct_req *ct;
88 switch (op) {
89 case FC_NS_GPN_FT:
90 ct = fc_ct_hdr_fill(fp, op, sizeof(struct fc_ns_gid_ft));
91 ct->payload.gid.fn_fc4_type = FC_TYPE_FCP;
92 break;
94 case FC_NS_RFT_ID:
95 ct = fc_ct_hdr_fill(fp, op, sizeof(struct fc_ns_rft));
96 hton24(ct->payload.rft.fid.fp_fid,
97 fc_host_port_id(lport->host));
98 ct->payload.rft.fts = lport->fcts;
99 break;
101 case FC_NS_RPN_ID:
102 ct = fc_ct_hdr_fill(fp, op, sizeof(struct fc_ns_rn_id));
103 hton24(ct->payload.rn.fr_fid.fp_fid,
104 fc_host_port_id(lport->host));
105 ct->payload.rft.fts = lport->fcts;
106 put_unaligned_be64(lport->wwpn, &ct->payload.rn.fr_wwn);
107 break;
109 default:
110 return -EINVAL;
112 *r_ctl = FC_RCTL_DD_UNSOL_CTL;
113 *did = FC_FID_DIR_SERV;
114 *fh_type = FC_TYPE_CT;
115 return 0;
119 * fc_plogi_fill - Fill in plogi request frame
121 static inline void fc_plogi_fill(struct fc_lport *lport, struct fc_frame *fp,
122 unsigned int op)
124 struct fc_els_flogi *plogi;
125 struct fc_els_csp *csp;
126 struct fc_els_cssp *cp;
128 plogi = fc_frame_payload_get(fp, sizeof(*plogi));
129 memset(plogi, 0, sizeof(*plogi));
130 plogi->fl_cmd = (u8) op;
131 put_unaligned_be64(lport->wwpn, &plogi->fl_wwpn);
132 put_unaligned_be64(lport->wwnn, &plogi->fl_wwnn);
134 csp = &plogi->fl_csp;
135 csp->sp_hi_ver = 0x20;
136 csp->sp_lo_ver = 0x20;
137 csp->sp_bb_cred = htons(10); /* this gets set by gateway */
138 csp->sp_bb_data = htons((u16) lport->mfs);
139 cp = &plogi->fl_cssp[3 - 1]; /* class 3 parameters */
140 cp->cp_class = htons(FC_CPC_VALID | FC_CPC_SEQ);
141 csp->sp_features = htons(FC_SP_FT_CIRO);
142 csp->sp_tot_seq = htons(255); /* seq. we accept */
143 csp->sp_rel_off = htons(0x1f);
144 csp->sp_e_d_tov = htonl(lport->e_d_tov);
146 cp->cp_rdfs = htons((u16) lport->mfs);
147 cp->cp_con_seq = htons(255);
148 cp->cp_open_seq = 1;
152 * fc_flogi_fill - Fill in a flogi request frame.
154 static inline void fc_flogi_fill(struct fc_lport *lport, struct fc_frame *fp)
156 struct fc_els_csp *sp;
157 struct fc_els_cssp *cp;
158 struct fc_els_flogi *flogi;
160 flogi = fc_frame_payload_get(fp, sizeof(*flogi));
161 memset(flogi, 0, sizeof(*flogi));
162 flogi->fl_cmd = (u8) ELS_FLOGI;
163 put_unaligned_be64(lport->wwpn, &flogi->fl_wwpn);
164 put_unaligned_be64(lport->wwnn, &flogi->fl_wwnn);
165 sp = &flogi->fl_csp;
166 sp->sp_hi_ver = 0x20;
167 sp->sp_lo_ver = 0x20;
168 sp->sp_bb_cred = htons(10); /* this gets set by gateway */
169 sp->sp_bb_data = htons((u16) lport->mfs);
170 cp = &flogi->fl_cssp[3 - 1]; /* class 3 parameters */
171 cp->cp_class = htons(FC_CPC_VALID | FC_CPC_SEQ);
175 * fc_logo_fill - Fill in a logo request frame.
177 static inline void fc_logo_fill(struct fc_lport *lport, struct fc_frame *fp)
179 struct fc_els_logo *logo;
181 logo = fc_frame_payload_get(fp, sizeof(*logo));
182 memset(logo, 0, sizeof(*logo));
183 logo->fl_cmd = ELS_LOGO;
184 hton24(logo->fl_n_port_id, fc_host_port_id(lport->host));
185 logo->fl_n_port_wwn = htonll(lport->wwpn);
189 * fc_rtv_fill - Fill in RTV (read timeout value) request frame.
191 static inline void fc_rtv_fill(struct fc_lport *lport, struct fc_frame *fp)
193 struct fc_els_rtv *rtv;
195 rtv = fc_frame_payload_get(fp, sizeof(*rtv));
196 memset(rtv, 0, sizeof(*rtv));
197 rtv->rtv_cmd = ELS_RTV;
201 * fc_rec_fill - Fill in rec request frame
203 static inline void fc_rec_fill(struct fc_lport *lport, struct fc_frame *fp)
205 struct fc_els_rec *rec;
206 struct fc_exch *ep = fc_seq_exch(fr_seq(fp));
208 rec = fc_frame_payload_get(fp, sizeof(*rec));
209 memset(rec, 0, sizeof(*rec));
210 rec->rec_cmd = ELS_REC;
211 hton24(rec->rec_s_id, fc_host_port_id(lport->host));
212 rec->rec_ox_id = htons(ep->oxid);
213 rec->rec_rx_id = htons(ep->rxid);
217 * fc_prli_fill - Fill in prli request frame
219 static inline void fc_prli_fill(struct fc_lport *lport, struct fc_frame *fp)
221 struct {
222 struct fc_els_prli prli;
223 struct fc_els_spp spp;
224 } *pp;
226 pp = fc_frame_payload_get(fp, sizeof(*pp));
227 memset(pp, 0, sizeof(*pp));
228 pp->prli.prli_cmd = ELS_PRLI;
229 pp->prli.prli_spp_len = sizeof(struct fc_els_spp);
230 pp->prli.prli_len = htons(sizeof(*pp));
231 pp->spp.spp_type = FC_TYPE_FCP;
232 pp->spp.spp_flags = FC_SPP_EST_IMG_PAIR;
233 pp->spp.spp_params = htonl(lport->service_params);
237 * fc_scr_fill - Fill in a scr request frame.
239 static inline void fc_scr_fill(struct fc_lport *lport, struct fc_frame *fp)
241 struct fc_els_scr *scr;
243 scr = fc_frame_payload_get(fp, sizeof(*scr));
244 memset(scr, 0, sizeof(*scr));
245 scr->scr_cmd = ELS_SCR;
246 scr->scr_reg_func = ELS_SCRF_FULL;
250 * fc_els_fill - Fill in an ELS request frame
252 static inline int fc_els_fill(struct fc_lport *lport, struct fc_rport *rport,
253 struct fc_frame *fp, unsigned int op,
254 enum fc_rctl *r_ctl, u32 *did, enum fc_fh_type *fh_type)
256 switch (op) {
257 case ELS_PLOGI:
258 fc_plogi_fill(lport, fp, ELS_PLOGI);
259 *did = rport->port_id;
260 break;
262 case ELS_FLOGI:
263 fc_flogi_fill(lport, fp);
264 *did = FC_FID_FLOGI;
265 break;
267 case ELS_LOGO:
268 fc_logo_fill(lport, fp);
269 *did = FC_FID_FLOGI;
271 * if rport is valid then it
272 * is port logo, therefore
273 * set did to rport id.
275 if (rport)
276 *did = rport->port_id;
277 break;
279 case ELS_RTV:
280 fc_rtv_fill(lport, fp);
281 *did = rport->port_id;
282 break;
284 case ELS_REC:
285 fc_rec_fill(lport, fp);
286 *did = rport->port_id;
287 break;
289 case ELS_PRLI:
290 fc_prli_fill(lport, fp);
291 *did = rport->port_id;
292 break;
294 case ELS_SCR:
295 fc_scr_fill(lport, fp);
296 *did = FC_FID_FCTRL;
297 break;
299 default:
300 return -EINVAL;
303 *r_ctl = FC_RCTL_ELS_REQ;
304 *fh_type = FC_TYPE_ELS;
305 return 0;
307 #endif /* _FC_ENCODE_H_ */