fc_encode.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  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. FC_DBG("Invalid op code %x \n", op);
  99. return -EINVAL;
  100. }
  101. *r_ctl = FC_RCTL_DD_UNSOL_CTL;
  102. *did = FC_FID_DIR_SERV;
  103. *fh_type = FC_TYPE_CT;
  104. return 0;
  105. }
  106. /**
  107. * fc_plogi_fill - Fill in plogi request frame
  108. */
  109. static inline void fc_plogi_fill(struct fc_lport *lport, struct fc_frame *fp,
  110. unsigned int op)
  111. {
  112. struct fc_els_flogi *plogi;
  113. struct fc_els_csp *csp;
  114. struct fc_els_cssp *cp;
  115. plogi = fc_frame_payload_get(fp, sizeof(*plogi));
  116. memset(plogi, 0, sizeof(*plogi));
  117. plogi->fl_cmd = (u8) op;
  118. put_unaligned_be64(lport->wwpn, &plogi->fl_wwpn);
  119. put_unaligned_be64(lport->wwnn, &plogi->fl_wwnn);
  120. csp = &plogi->fl_csp;
  121. csp->sp_hi_ver = 0x20;
  122. csp->sp_lo_ver = 0x20;
  123. csp->sp_bb_cred = htons(10); /* this gets set by gateway */
  124. csp->sp_bb_data = htons((u16) lport->mfs);
  125. cp = &plogi->fl_cssp[3 - 1]; /* class 3 parameters */
  126. cp->cp_class = htons(FC_CPC_VALID | FC_CPC_SEQ);
  127. csp->sp_features = htons(FC_SP_FT_CIRO);
  128. csp->sp_tot_seq = htons(255); /* seq. we accept */
  129. csp->sp_rel_off = htons(0x1f);
  130. csp->sp_e_d_tov = htonl(lport->e_d_tov);
  131. cp->cp_rdfs = htons((u16) lport->mfs);
  132. cp->cp_con_seq = htons(255);
  133. cp->cp_open_seq = 1;
  134. }
  135. /**
  136. * fc_flogi_fill - Fill in a flogi request frame.
  137. */
  138. static inline void fc_flogi_fill(struct fc_lport *lport, struct fc_frame *fp)
  139. {
  140. struct fc_els_csp *sp;
  141. struct fc_els_cssp *cp;
  142. struct fc_els_flogi *flogi;
  143. flogi = fc_frame_payload_get(fp, sizeof(*flogi));
  144. memset(flogi, 0, sizeof(*flogi));
  145. flogi->fl_cmd = (u8) ELS_FLOGI;
  146. put_unaligned_be64(lport->wwpn, &flogi->fl_wwpn);
  147. put_unaligned_be64(lport->wwnn, &flogi->fl_wwnn);
  148. sp = &flogi->fl_csp;
  149. sp->sp_hi_ver = 0x20;
  150. sp->sp_lo_ver = 0x20;
  151. sp->sp_bb_cred = htons(10); /* this gets set by gateway */
  152. sp->sp_bb_data = htons((u16) lport->mfs);
  153. cp = &flogi->fl_cssp[3 - 1]; /* class 3 parameters */
  154. cp->cp_class = htons(FC_CPC_VALID | FC_CPC_SEQ);
  155. }
  156. /**
  157. * fc_logo_fill - Fill in a logo request frame.
  158. */
  159. static inline void fc_logo_fill(struct fc_lport *lport, struct fc_frame *fp)
  160. {
  161. struct fc_els_logo *logo;
  162. logo = fc_frame_payload_get(fp, sizeof(*logo));
  163. memset(logo, 0, sizeof(*logo));
  164. logo->fl_cmd = ELS_LOGO;
  165. hton24(logo->fl_n_port_id, fc_host_port_id(lport->host));
  166. logo->fl_n_port_wwn = htonll(lport->wwpn);
  167. }
  168. /**
  169. * fc_rtv_fill - Fill in RTV (read timeout value) request frame.
  170. */
  171. static inline void fc_rtv_fill(struct fc_lport *lport, struct fc_frame *fp)
  172. {
  173. struct fc_els_rtv *rtv;
  174. rtv = fc_frame_payload_get(fp, sizeof(*rtv));
  175. memset(rtv, 0, sizeof(*rtv));
  176. rtv->rtv_cmd = ELS_RTV;
  177. }
  178. /**
  179. * fc_rec_fill - Fill in rec request frame
  180. */
  181. static inline void fc_rec_fill(struct fc_lport *lport, struct fc_frame *fp)
  182. {
  183. struct fc_els_rec *rec;
  184. struct fc_exch *ep = fc_seq_exch(fr_seq(fp));
  185. rec = fc_frame_payload_get(fp, sizeof(*rec));
  186. memset(rec, 0, sizeof(*rec));
  187. rec->rec_cmd = ELS_REC;
  188. hton24(rec->rec_s_id, fc_host_port_id(lport->host));
  189. rec->rec_ox_id = htons(ep->oxid);
  190. rec->rec_rx_id = htons(ep->rxid);
  191. }
  192. /**
  193. * fc_prli_fill - Fill in prli request frame
  194. */
  195. static inline void fc_prli_fill(struct fc_lport *lport, struct fc_frame *fp)
  196. {
  197. struct {
  198. struct fc_els_prli prli;
  199. struct fc_els_spp spp;
  200. } *pp;
  201. pp = fc_frame_payload_get(fp, sizeof(*pp));
  202. memset(pp, 0, sizeof(*pp));
  203. pp->prli.prli_cmd = ELS_PRLI;
  204. pp->prli.prli_spp_len = sizeof(struct fc_els_spp);
  205. pp->prli.prli_len = htons(sizeof(*pp));
  206. pp->spp.spp_type = FC_TYPE_FCP;
  207. pp->spp.spp_flags = FC_SPP_EST_IMG_PAIR;
  208. pp->spp.spp_params = htonl(lport->service_params);
  209. }
  210. /**
  211. * fc_scr_fill - Fill in a scr request frame.
  212. */
  213. static inline void fc_scr_fill(struct fc_lport *lport, struct fc_frame *fp)
  214. {
  215. struct fc_els_scr *scr;
  216. scr = fc_frame_payload_get(fp, sizeof(*scr));
  217. memset(scr, 0, sizeof(*scr));
  218. scr->scr_cmd = ELS_SCR;
  219. scr->scr_reg_func = ELS_SCRF_FULL;
  220. }
  221. /**
  222. * fc_els_fill - Fill in an ELS request frame
  223. */
  224. static inline int fc_els_fill(struct fc_lport *lport, struct fc_rport *rport,
  225. struct fc_frame *fp, unsigned int op,
  226. enum fc_rctl *r_ctl, u32 *did, enum fc_fh_type *fh_type)
  227. {
  228. switch (op) {
  229. case ELS_PLOGI:
  230. fc_plogi_fill(lport, fp, ELS_PLOGI);
  231. *did = rport->port_id;
  232. break;
  233. case ELS_FLOGI:
  234. fc_flogi_fill(lport, fp);
  235. *did = FC_FID_FLOGI;
  236. break;
  237. case ELS_LOGO:
  238. fc_logo_fill(lport, fp);
  239. *did = FC_FID_FLOGI;
  240. /*
  241. * if rport is valid then it
  242. * is port logo, therefore
  243. * set did to rport id.
  244. */
  245. if (rport)
  246. *did = rport->port_id;
  247. break;
  248. case ELS_RTV:
  249. fc_rtv_fill(lport, fp);
  250. *did = rport->port_id;
  251. break;
  252. case ELS_REC:
  253. fc_rec_fill(lport, fp);
  254. *did = rport->port_id;
  255. break;
  256. case ELS_PRLI:
  257. fc_prli_fill(lport, fp);
  258. *did = rport->port_id;
  259. break;
  260. case ELS_SCR:
  261. fc_scr_fill(lport, fp);
  262. *did = FC_FID_FCTRL;
  263. break;
  264. default:
  265. FC_DBG("Invalid op code %x \n", op);
  266. return -EINVAL;
  267. }
  268. *r_ctl = FC_RCTL_ELS_REQ;
  269. *fh_type = FC_TYPE_ELS;
  270. return 0;
  271. }
  272. #endif /* _FC_ENCODE_H_ */