bfa_fcbuild.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. /*
  2. * Copyright (c) 2005-2010 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 "bfad_drv.h"
  23. #include "bfa_fc.h"
  24. #include "bfa_defs_fcs.h"
  25. /*
  26. * Utility Macros/functions
  27. */
  28. #define wwn_is_equal(_wwn1, _wwn2) \
  29. (memcmp(&(_wwn1), &(_wwn2), sizeof(wwn_t)) == 0)
  30. #define fc_roundup(_l, _s) (((_l) + ((_s) - 1)) & ~((_s) - 1))
  31. /*
  32. * Given the fc response length, this routine will return
  33. * the length of the actual payload bytes following the CT header.
  34. *
  35. * Assumes the input response length does not include the crc, eof, etc.
  36. */
  37. static inline u32
  38. fc_get_ctresp_pyld_len(u32 resp_len)
  39. {
  40. return resp_len - sizeof(struct ct_hdr_s);
  41. }
  42. /*
  43. * Convert bfa speed to rpsc speed value.
  44. */
  45. static inline enum bfa_port_speed
  46. fc_rpsc_operspeed_to_bfa_speed(enum fc_rpsc_op_speed speed)
  47. {
  48. switch (speed) {
  49. case RPSC_OP_SPEED_1G:
  50. return BFA_PORT_SPEED_1GBPS;
  51. case RPSC_OP_SPEED_2G:
  52. return BFA_PORT_SPEED_2GBPS;
  53. case RPSC_OP_SPEED_4G:
  54. return BFA_PORT_SPEED_4GBPS;
  55. case RPSC_OP_SPEED_8G:
  56. return BFA_PORT_SPEED_8GBPS;
  57. case RPSC_OP_SPEED_10G:
  58. return BFA_PORT_SPEED_10GBPS;
  59. default:
  60. return BFA_PORT_SPEED_UNKNOWN;
  61. }
  62. }
  63. /*
  64. * Convert RPSC speed to bfa speed value.
  65. */
  66. static inline enum fc_rpsc_op_speed
  67. fc_bfa_speed_to_rpsc_operspeed(enum bfa_port_speed op_speed)
  68. {
  69. switch (op_speed) {
  70. case BFA_PORT_SPEED_1GBPS:
  71. return RPSC_OP_SPEED_1G;
  72. case BFA_PORT_SPEED_2GBPS:
  73. return RPSC_OP_SPEED_2G;
  74. case BFA_PORT_SPEED_4GBPS:
  75. return RPSC_OP_SPEED_4G;
  76. case BFA_PORT_SPEED_8GBPS:
  77. return RPSC_OP_SPEED_8G;
  78. case BFA_PORT_SPEED_10GBPS:
  79. return RPSC_OP_SPEED_10G;
  80. default:
  81. return RPSC_OP_SPEED_NOT_EST;
  82. }
  83. }
  84. enum fc_parse_status {
  85. FC_PARSE_OK = 0,
  86. FC_PARSE_FAILURE = 1,
  87. FC_PARSE_BUSY = 2,
  88. FC_PARSE_LEN_INVAL,
  89. FC_PARSE_ACC_INVAL,
  90. FC_PARSE_PWWN_NOT_EQUAL,
  91. FC_PARSE_NWWN_NOT_EQUAL,
  92. FC_PARSE_RXSZ_INVAL,
  93. FC_PARSE_NOT_FCP,
  94. FC_PARSE_OPAFLAG_INVAL,
  95. FC_PARSE_RPAFLAG_INVAL,
  96. FC_PARSE_OPA_INVAL,
  97. FC_PARSE_RPA_INVAL,
  98. };
  99. struct fc_templates_s {
  100. struct fchs_s fc_els_req;
  101. struct fchs_s fc_bls_req;
  102. struct fc_logi_s plogi;
  103. struct fc_rrq_s rrq;
  104. };
  105. void fcbuild_init(void);
  106. u16 fc_flogi_build(struct fchs_s *fchs, struct fc_logi_s *flogi,
  107. u32 s_id, u16 ox_id, wwn_t port_name, wwn_t node_name,
  108. u16 pdu_size, u8 set_npiv, u8 set_auth,
  109. u16 local_bb_credits);
  110. u16 fc_fdisc_build(struct fchs_s *buf, struct fc_logi_s *flogi, u32 s_id,
  111. u16 ox_id, wwn_t port_name, wwn_t node_name,
  112. u16 pdu_size);
  113. u16 fc_flogi_acc_build(struct fchs_s *fchs, struct fc_logi_s *flogi,
  114. u32 s_id, __be16 ox_id,
  115. wwn_t port_name, wwn_t node_name,
  116. u16 pdu_size,
  117. u16 local_bb_credits);
  118. u16 fc_plogi_build(struct fchs_s *fchs, void *pld, u32 d_id,
  119. u32 s_id, u16 ox_id, wwn_t port_name,
  120. wwn_t node_name, u16 pdu_size);
  121. enum fc_parse_status fc_plogi_parse(struct fchs_s *fchs);
  122. u16 fc_abts_build(struct fchs_s *buf, u32 d_id, u32 s_id,
  123. u16 ox_id);
  124. enum fc_parse_status fc_abts_rsp_parse(struct fchs_s *buf, int len);
  125. u16 fc_rrq_build(struct fchs_s *buf, struct fc_rrq_s *rrq, u32 d_id,
  126. u32 s_id, u16 ox_id, u16 rrq_oxid);
  127. enum fc_parse_status fc_rrq_rsp_parse(struct fchs_s *buf, int len);
  128. u16 fc_rspnid_build(struct fchs_s *fchs, void *pld, u32 s_id,
  129. u16 ox_id, u8 *name);
  130. u16 fc_rftid_build(struct fchs_s *fchs, void *pld, u32 s_id,
  131. u16 ox_id, enum bfa_lport_role role);
  132. u16 fc_rftid_build_sol(struct fchs_s *fchs, void *pyld, u32 s_id,
  133. u16 ox_id, u8 *fc4_bitmap,
  134. u32 bitmap_size);
  135. u16 fc_rffid_build(struct fchs_s *fchs, void *pyld, u32 s_id,
  136. u16 ox_id, u8 fc4_type, u8 fc4_ftrs);
  137. u16 fc_gidpn_build(struct fchs_s *fchs, void *pyld, u32 s_id,
  138. u16 ox_id, wwn_t port_name);
  139. u16 fc_gpnid_build(struct fchs_s *fchs, void *pld, u32 s_id,
  140. u16 ox_id, u32 port_id);
  141. u16 fc_scr_build(struct fchs_s *fchs, struct fc_scr_s *scr,
  142. u8 set_br_reg, u32 s_id, u16 ox_id);
  143. u16 fc_plogi_acc_build(struct fchs_s *fchs, void *pld, u32 d_id,
  144. u32 s_id, u16 ox_id,
  145. wwn_t port_name, wwn_t node_name,
  146. u16 pdu_size);
  147. u16 fc_adisc_build(struct fchs_s *fchs, struct fc_adisc_s *adisc,
  148. u32 d_id, u32 s_id, __be16 ox_id, wwn_t port_name,
  149. wwn_t node_name);
  150. enum fc_parse_status fc_adisc_parse(struct fchs_s *fchs, void *pld,
  151. u32 host_dap, wwn_t node_name, wwn_t port_name);
  152. enum fc_parse_status fc_adisc_rsp_parse(struct fc_adisc_s *adisc, int len,
  153. wwn_t port_name, wwn_t node_name);
  154. u16 fc_adisc_acc_build(struct fchs_s *fchs, struct fc_adisc_s *adisc,
  155. u32 d_id, u32 s_id, __be16 ox_id,
  156. wwn_t port_name, wwn_t node_name);
  157. u16 fc_ls_rjt_build(struct fchs_s *fchs, struct fc_ls_rjt_s *ls_rjt,
  158. u32 d_id, u32 s_id, __be16 ox_id,
  159. u8 reason_code, u8 reason_code_expl);
  160. u16 fc_ls_acc_build(struct fchs_s *fchs, struct fc_els_cmd_s *els_cmd,
  161. u32 d_id, u32 s_id, __be16 ox_id);
  162. u16 fc_prli_build(struct fchs_s *fchs, void *pld, u32 d_id,
  163. u32 s_id, u16 ox_id);
  164. enum fc_parse_status fc_prli_rsp_parse(struct fc_prli_s *prli, int len);
  165. u16 fc_prli_acc_build(struct fchs_s *fchs, void *pld, u32 d_id,
  166. u32 s_id, __be16 ox_id,
  167. enum bfa_lport_role role);
  168. u16 fc_rnid_build(struct fchs_s *fchs, struct fc_rnid_cmd_s *rnid,
  169. u32 d_id, u32 s_id, u16 ox_id,
  170. u32 data_format);
  171. u16 fc_rnid_acc_build(struct fchs_s *fchs,
  172. struct fc_rnid_acc_s *rnid_acc, u32 d_id, u32 s_id,
  173. __be16 ox_id, u32 data_format,
  174. struct fc_rnid_common_id_data_s *common_id_data,
  175. struct fc_rnid_general_topology_data_s *gen_topo_data);
  176. u16 fc_rpsc2_build(struct fchs_s *fchs, struct fc_rpsc2_cmd_s *rps2c,
  177. u32 d_id, u32 s_id, u32 *pid_list, u16 npids);
  178. u16 fc_rpsc_build(struct fchs_s *fchs, struct fc_rpsc_cmd_s *rpsc,
  179. u32 d_id, u32 s_id, u16 ox_id);
  180. u16 fc_rpsc_acc_build(struct fchs_s *fchs,
  181. struct fc_rpsc_acc_s *rpsc_acc, u32 d_id, u32 s_id,
  182. __be16 ox_id, struct fc_rpsc_speed_info_s *oper_speed);
  183. u16 fc_gid_ft_build(struct fchs_s *fchs, void *pld, u32 s_id,
  184. u8 fc4_type);
  185. u16 fc_rpnid_build(struct fchs_s *fchs, void *pyld, u32 s_id,
  186. u32 port_id, wwn_t port_name);
  187. u16 fc_rnnid_build(struct fchs_s *fchs, void *pyld, u32 s_id,
  188. u32 port_id, wwn_t node_name);
  189. u16 fc_rcsid_build(struct fchs_s *fchs, void *pyld, u32 s_id,
  190. u32 port_id, u32 cos);
  191. u16 fc_rptid_build(struct fchs_s *fchs, void *pyld, u32 s_id,
  192. u32 port_id, u8 port_type);
  193. u16 fc_ganxt_build(struct fchs_s *fchs, void *pyld, u32 s_id,
  194. u32 port_id);
  195. u16 fc_logo_build(struct fchs_s *fchs, struct fc_logo_s *logo, u32 d_id,
  196. u32 s_id, u16 ox_id, wwn_t port_name);
  197. u16 fc_logo_acc_build(struct fchs_s *fchs, void *pld, u32 d_id,
  198. u32 s_id, __be16 ox_id);
  199. u16 fc_fdmi_reqhdr_build(struct fchs_s *fchs, void *pyld, u32 s_id,
  200. u16 cmd_code);
  201. u16 fc_gmal_req_build(struct fchs_s *fchs, void *pyld, u32 s_id, wwn_t wwn);
  202. u16 fc_gfn_req_build(struct fchs_s *fchs, void *pyld, u32 s_id, wwn_t wwn);
  203. void fc_get_fc4type_bitmask(u8 fc4_type, u8 *bit_mask);
  204. void fc_els_req_build(struct fchs_s *fchs, u32 d_id, u32 s_id,
  205. __be16 ox_id);
  206. enum fc_parse_status fc_els_rsp_parse(struct fchs_s *fchs, int len);
  207. enum fc_parse_status fc_plogi_rsp_parse(struct fchs_s *fchs, int len,
  208. wwn_t port_name);
  209. enum fc_parse_status fc_prli_parse(struct fc_prli_s *prli);
  210. enum fc_parse_status fc_pdisc_parse(struct fchs_s *fchs, wwn_t node_name,
  211. wwn_t port_name);
  212. u16 fc_ba_acc_build(struct fchs_s *fchs, struct fc_ba_acc_s *ba_acc, u32 d_id,
  213. u32 s_id, __be16 ox_id, u16 rx_id);
  214. int fc_logout_params_pages(struct fchs_s *fc_frame, u8 els_code);
  215. u16 fc_tprlo_acc_build(struct fchs_s *fchs, struct fc_tprlo_acc_s *tprlo_acc,
  216. u32 d_id, u32 s_id, __be16 ox_id, int num_pages);
  217. u16 fc_prlo_acc_build(struct fchs_s *fchs, struct fc_prlo_acc_s *prlo_acc,
  218. u32 d_id, u32 s_id, __be16 ox_id, int num_pages);
  219. u16 fc_logo_rsp_parse(struct fchs_s *fchs, int len);
  220. u16 fc_pdisc_build(struct fchs_s *fchs, u32 d_id, u32 s_id,
  221. u16 ox_id, wwn_t port_name, wwn_t node_name,
  222. u16 pdu_size);
  223. u16 fc_pdisc_rsp_parse(struct fchs_s *fchs, int len, wwn_t port_name);
  224. u16 fc_prlo_build(struct fchs_s *fchs, u32 d_id, u32 s_id,
  225. u16 ox_id, int num_pages);
  226. u16 fc_prlo_rsp_parse(struct fchs_s *fchs, int len);
  227. u16 fc_tprlo_build(struct fchs_s *fchs, u32 d_id, u32 s_id,
  228. u16 ox_id, int num_pages, enum fc_tprlo_type tprlo_type,
  229. u32 tpr_id);
  230. u16 fc_tprlo_rsp_parse(struct fchs_s *fchs, int len);
  231. u16 fc_ba_rjt_build(struct fchs_s *fchs, u32 d_id, u32 s_id,
  232. __be16 ox_id, u32 reason_code, u32 reason_expl);
  233. u16 fc_gnnid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
  234. u32 port_id);
  235. u16 fc_ct_rsp_parse(struct ct_hdr_s *cthdr);
  236. u16 fc_rscn_build(struct fchs_s *fchs, struct fc_rscn_pl_s *rscn, u32 s_id,
  237. u16 ox_id);
  238. #endif