fcbuild.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. /*
  2. * Copyright (c) 2005-2009 Brocade Communications Systems, Inc.
  3. * All rights reserved
  4. * www.brocade.com
  5. *
  6. * Linux driver for Brocade Fibre Channel Host Bus Adapter.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License (GPL) Version 2 as
  10. * published by the Free Software Foundation
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. */
  17. /*
  18. * fcbuild.h - FC link service frame building and parsing routines
  19. */
  20. #ifndef __FCBUILD_H__
  21. #define __FCBUILD_H__
  22. #include <bfa_os_inc.h>
  23. #include <protocol/fc.h>
  24. #include <protocol/fcp.h>
  25. #include <protocol/ct.h>
  26. #include <defs/bfa_defs_port.h>
  27. #include <defs/bfa_defs_pport.h>
  28. /*
  29. * Utility Macros/functions
  30. */
  31. #define fcif_sof_set(_ifhdr, _sof) ((_ifhdr)->sof = FC_ ## _sof)
  32. #define fcif_eof_set(_ifhdr, _eof) ((_ifhdr)->eof = FC_ ## _eof)
  33. #define wwn_is_equal(_wwn1, _wwn2) \
  34. (memcmp(&(_wwn1), &(_wwn2), sizeof(wwn_t)) == 0)
  35. #define fc_roundup(_l, _s) (((_l) + ((_s) - 1)) & ~((_s) - 1))
  36. /*
  37. * Given the fc response length, this routine will return
  38. * the length of the actual payload bytes following the CT header.
  39. *
  40. * Assumes the input response length does not include the crc, eof, etc.
  41. */
  42. static inline u32
  43. fc_get_ctresp_pyld_len(u32 resp_len)
  44. {
  45. return resp_len - sizeof(struct ct_hdr_s);
  46. }
  47. /*
  48. * Convert bfa speed to rpsc speed value.
  49. */
  50. static inline enum bfa_pport_speed
  51. fc_rpsc_operspeed_to_bfa_speed(enum fc_rpsc_op_speed_s speed)
  52. {
  53. switch (speed) {
  54. case RPSC_OP_SPEED_1G:
  55. return BFA_PPORT_SPEED_1GBPS;
  56. case RPSC_OP_SPEED_2G:
  57. return BFA_PPORT_SPEED_2GBPS;
  58. case RPSC_OP_SPEED_4G:
  59. return BFA_PPORT_SPEED_4GBPS;
  60. case RPSC_OP_SPEED_8G:
  61. return BFA_PPORT_SPEED_8GBPS;
  62. case RPSC_OP_SPEED_10G:
  63. return BFA_PPORT_SPEED_10GBPS;
  64. default:
  65. return BFA_PPORT_SPEED_UNKNOWN;
  66. }
  67. }
  68. /*
  69. * Convert RPSC speed to bfa speed value.
  70. */
  71. static inline enum fc_rpsc_op_speed_s
  72. fc_bfa_speed_to_rpsc_operspeed(enum bfa_pport_speed op_speed)
  73. {
  74. switch (op_speed) {
  75. case BFA_PPORT_SPEED_1GBPS:
  76. return RPSC_OP_SPEED_1G;
  77. case BFA_PPORT_SPEED_2GBPS:
  78. return RPSC_OP_SPEED_2G;
  79. case BFA_PPORT_SPEED_4GBPS:
  80. return RPSC_OP_SPEED_4G;
  81. case BFA_PPORT_SPEED_8GBPS:
  82. return RPSC_OP_SPEED_8G;
  83. case BFA_PPORT_SPEED_10GBPS:
  84. return RPSC_OP_SPEED_10G;
  85. default:
  86. return RPSC_OP_SPEED_NOT_EST;
  87. }
  88. }
  89. enum fc_parse_status {
  90. FC_PARSE_OK = 0,
  91. FC_PARSE_FAILURE = 1,
  92. FC_PARSE_BUSY = 2,
  93. FC_PARSE_LEN_INVAL,
  94. FC_PARSE_ACC_INVAL,
  95. FC_PARSE_PWWN_NOT_EQUAL,
  96. FC_PARSE_NWWN_NOT_EQUAL,
  97. FC_PARSE_RXSZ_INVAL,
  98. FC_PARSE_NOT_FCP,
  99. FC_PARSE_OPAFLAG_INVAL,
  100. FC_PARSE_RPAFLAG_INVAL,
  101. FC_PARSE_OPA_INVAL,
  102. FC_PARSE_RPA_INVAL,
  103. };
  104. struct fc_templates_s {
  105. struct fchs_s fc_els_req;
  106. struct fchs_s fc_bls_req;
  107. struct fc_logi_s plogi;
  108. struct fc_rrq_s rrq;
  109. };
  110. void fcbuild_init(void);
  111. u16 fc_flogi_build(struct fchs_s *fchs, struct fc_logi_s *flogi,
  112. u32 s_id, u16 ox_id, wwn_t port_name,
  113. wwn_t node_name, u16 pdu_size, u8 set_npiv,
  114. u8 set_auth, u16 local_bb_credits);
  115. u16 fc_fdisc_build(struct fchs_s *buf, struct fc_logi_s *flogi,
  116. u32 s_id, u16 ox_id, wwn_t port_name,
  117. wwn_t node_name, u16 pdu_size);
  118. u16 fc_flogi_acc_build(struct fchs_s *fchs, struct fc_logi_s *flogi,
  119. u32 s_id, u16 ox_id, wwn_t port_name,
  120. wwn_t node_name, u16 pdu_size,
  121. u16 local_bb_credits);
  122. u16 fc_plogi_build(struct fchs_s *fchs, void *pld, u32 d_id,
  123. u32 s_id, u16 ox_id, wwn_t port_name,
  124. wwn_t node_name, u16 pdu_size);
  125. enum fc_parse_status fc_plogi_parse(struct fchs_s *fchs);
  126. u16 fc_abts_build(struct fchs_s *buf, u32 d_id, u32 s_id,
  127. u16 ox_id);
  128. enum fc_parse_status fc_abts_rsp_parse(struct fchs_s *buf, int len);
  129. u16 fc_rrq_build(struct fchs_s *buf, struct fc_rrq_s *rrq, u32 d_id,
  130. u32 s_id, u16 ox_id, u16 rrq_oxid);
  131. enum fc_parse_status fc_rrq_rsp_parse(struct fchs_s *buf, int len);
  132. u16 fc_rspnid_build(struct fchs_s *fchs, void *pld, u32 s_id,
  133. u16 ox_id, u8 *name);
  134. u16 fc_rftid_build(struct fchs_s *fchs, void *pld, u32 s_id,
  135. u16 ox_id, enum bfa_port_role role);
  136. u16 fc_rftid_build_sol(struct fchs_s *fchs, void *pyld, u32 s_id,
  137. u16 ox_id, u8 *fc4_bitmap,
  138. u32 bitmap_size);
  139. u16 fc_rffid_build(struct fchs_s *fchs, void *pyld, u32 s_id,
  140. u16 ox_id, u8 fc4_type, u8 fc4_ftrs);
  141. u16 fc_gidpn_build(struct fchs_s *fchs, void *pyld, u32 s_id,
  142. u16 ox_id, wwn_t port_name);
  143. u16 fc_gpnid_build(struct fchs_s *fchs, void *pld, u32 s_id,
  144. u16 ox_id, u32 port_id);
  145. u16 fc_scr_build(struct fchs_s *fchs, struct fc_scr_s *scr,
  146. u8 set_br_reg, u32 s_id, u16 ox_id);
  147. u16 fc_plogi_acc_build(struct fchs_s *fchs, void *pld, u32 d_id,
  148. u32 s_id, u16 ox_id,
  149. wwn_t port_name, wwn_t node_name, u16 pdu_size);
  150. u16 fc_adisc_build(struct fchs_s *fchs, struct fc_adisc_s *adisc,
  151. u32 d_id, u32 s_id, u16 ox_id,
  152. wwn_t port_name, wwn_t node_name);
  153. enum fc_parse_status fc_adisc_parse(struct fchs_s *fchs, void *pld,
  154. u32 host_dap,
  155. wwn_t node_name, wwn_t port_name);
  156. enum fc_parse_status fc_adisc_rsp_parse(struct fc_adisc_s *adisc, int len,
  157. wwn_t port_name, wwn_t node_name);
  158. u16 fc_adisc_acc_build(struct fchs_s *fchs, struct fc_adisc_s *adisc,
  159. u32 d_id, u32 s_id, u16 ox_id,
  160. wwn_t port_name, wwn_t node_name);
  161. u16 fc_ls_rjt_build(struct fchs_s *fchs, struct fc_ls_rjt_s *ls_rjt,
  162. u32 d_id, u32 s_id, u16 ox_id,
  163. u8 reason_code, u8 reason_code_expl);
  164. u16 fc_ls_acc_build(struct fchs_s *fchs, struct fc_els_cmd_s *els_cmd,
  165. u32 d_id, u32 s_id, u16 ox_id);
  166. u16 fc_prli_build(struct fchs_s *fchs, void *pld, u32 d_id,
  167. u32 s_id, u16 ox_id);
  168. enum fc_parse_status fc_prli_rsp_parse(struct fc_prli_s *prli, int len);
  169. u16 fc_prli_acc_build(struct fchs_s *fchs, void *pld, u32 d_id,
  170. u32 s_id, u16 ox_id,
  171. enum bfa_port_role role);
  172. u16 fc_rnid_build(struct fchs_s *fchs, struct fc_rnid_cmd_s *rnid,
  173. u32 d_id, u32 s_id, u16 ox_id,
  174. u32 data_format);
  175. u16 fc_rnid_acc_build(struct fchs_s *fchs, struct fc_rnid_acc_s *rnid_acc,
  176. u32 d_id, u32 s_id, u16 ox_id,
  177. u32 data_format,
  178. struct fc_rnid_common_id_data_s *common_id_data,
  179. struct fc_rnid_general_topology_data_s *
  180. gen_topo_data);
  181. u16 fc_rpsc2_build(struct fchs_s *fchs, struct fc_rpsc2_cmd_s *rps2c,
  182. u32 d_id, u32 s_id,
  183. u32 *pid_list, u16 npids);
  184. u16 fc_rpsc_build(struct fchs_s *fchs, struct fc_rpsc_cmd_s *rpsc,
  185. u32 d_id, u32 s_id, u16 ox_id);
  186. u16 fc_rpsc_acc_build(struct fchs_s *fchs, struct fc_rpsc_acc_s *rpsc_acc,
  187. u32 d_id, u32 s_id, u16 ox_id,
  188. struct fc_rpsc_speed_info_s *oper_speed);
  189. u16 fc_gid_ft_build(struct fchs_s *fchs, void *pld, u32 s_id,
  190. u8 fc4_type);
  191. u16 fc_rpnid_build(struct fchs_s *fchs, void *pyld, u32 s_id,
  192. u32 port_id, wwn_t port_name);
  193. u16 fc_rnnid_build(struct fchs_s *fchs, void *pyld, u32 s_id,
  194. u32 port_id, wwn_t node_name);
  195. u16 fc_rcsid_build(struct fchs_s *fchs, void *pyld, u32 s_id,
  196. u32 port_id, u32 cos);
  197. u16 fc_rptid_build(struct fchs_s *fchs, void *pyld, u32 s_id,
  198. u32 port_id, u8 port_type);
  199. u16 fc_ganxt_build(struct fchs_s *fchs, void *pyld, u32 s_id,
  200. u32 port_id);
  201. u16 fc_logo_build(struct fchs_s *fchs, struct fc_logo_s *logo,
  202. u32 d_id, u32 s_id, u16 ox_id,
  203. wwn_t port_name);
  204. u16 fc_logo_acc_build(struct fchs_s *fchs, void *pld, u32 d_id,
  205. u32 s_id, u16 ox_id);
  206. u16 fc_fdmi_reqhdr_build(struct fchs_s *fchs, void *pyld, u32 s_id,
  207. u16 cmd_code);
  208. u16 fc_gmal_req_build(struct fchs_s *fchs, void *pyld, u32 s_id,
  209. wwn_t wwn);
  210. u16 fc_gfn_req_build(struct fchs_s *fchs, void *pyld, u32 s_id,
  211. wwn_t wwn);
  212. void fc_get_fc4type_bitmask(u8 fc4_type, u8 *bit_mask);
  213. void fc_els_req_build(struct fchs_s *fchs, u32 d_id, u32 s_id,
  214. u16 ox_id);
  215. enum fc_parse_status fc_els_rsp_parse(struct fchs_s *fchs, int len);
  216. enum fc_parse_status fc_plogi_rsp_parse(struct fchs_s *fchs, int len,
  217. wwn_t port_name);
  218. enum fc_parse_status fc_prli_parse(struct fc_prli_s *prli);
  219. enum fc_parse_status fc_pdisc_parse(struct fchs_s *fchs, wwn_t node_name,
  220. wwn_t port_name);
  221. u16 fc_ba_acc_build(struct fchs_s *fchs, struct fc_ba_acc_s *ba_acc,
  222. u32 d_id, u32 s_id, u16 ox_id,
  223. u16 rx_id);
  224. int fc_logout_params_pages(struct fchs_s *fc_frame, u8 els_code);
  225. u16 fc_tprlo_acc_build(struct fchs_s *fchs,
  226. struct fc_tprlo_acc_s *tprlo_acc,
  227. u32 d_id, u32 s_id, u16 ox_id,
  228. int num_pages);
  229. u16 fc_prlo_acc_build(struct fchs_s *fchs, struct fc_prlo_acc_s *prlo_acc,
  230. u32 d_id, u32 s_id, u16 ox_id,
  231. int num_pages);
  232. u16 fc_logo_rsp_parse(struct fchs_s *fchs, int len);
  233. u16 fc_pdisc_build(struct fchs_s *fchs, u32 d_id, u32 s_id,
  234. u16 ox_id, wwn_t port_name, wwn_t node_name,
  235. u16 pdu_size);
  236. u16 fc_pdisc_rsp_parse(struct fchs_s *fchs, int len, wwn_t port_name);
  237. u16 fc_prlo_build(struct fchs_s *fchs, u32 d_id, u32 s_id,
  238. u16 ox_id, int num_pages);
  239. u16 fc_prlo_rsp_parse(struct fchs_s *fchs, int len);
  240. u16 fc_tprlo_build(struct fchs_s *fchs, u32 d_id, u32 s_id,
  241. u16 ox_id, int num_pages,
  242. enum fc_tprlo_type tprlo_type, u32 tpr_id);
  243. u16 fc_tprlo_rsp_parse(struct fchs_s *fchs, int len);
  244. u16 fc_ba_rjt_build(struct fchs_s *fchs, u32 d_id, u32 s_id,
  245. u16 ox_id, u32 reason_code,
  246. u32 reason_expl);
  247. u16 fc_gnnid_build(struct fchs_s *fchs, void *pyld, u32 s_id,
  248. u16 ox_id, u32 port_id);
  249. u16 fc_ct_rsp_parse(struct ct_hdr_s *cthdr);
  250. u16 fc_rscn_build(struct fchs_s *fchs, struct fc_rscn_pl_s *rscn,
  251. u32 s_id, u16 ox_id);
  252. #endif