fc_encode.h 7.7 KB

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