fc_encode.h 8.3 KB

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