bfa_fcbuild.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
  4. * Copyright (c) 2014- QLogic Corporation.
  5. * All rights reserved
  6. * www.qlogic.com
  7. *
  8. * Linux driver for QLogic BR-series Fibre Channel Host Bus Adapter.
  9. */
  10. /*
  11. * fcbuild.h - FC link service frame building and parsing routines
  12. */
  13. #ifndef __FCBUILD_H__
  14. #define __FCBUILD_H__
  15. #include "bfad_drv.h"
  16. #include "bfa_fc.h"
  17. #include "bfa_defs_fcs.h"
  18. /*
  19. * Utility Macros/functions
  20. */
  21. #define wwn_is_equal(_wwn1, _wwn2) \
  22. (memcmp(&(_wwn1), &(_wwn2), sizeof(wwn_t)) == 0)
  23. #define fc_roundup(_l, _s) (((_l) + ((_s) - 1)) & ~((_s) - 1))
  24. /*
  25. * Given the fc response length, this routine will return
  26. * the length of the actual payload bytes following the CT header.
  27. *
  28. * Assumes the input response length does not include the crc, eof, etc.
  29. */
  30. static inline u32
  31. fc_get_ctresp_pyld_len(u32 resp_len)
  32. {
  33. return resp_len - sizeof(struct ct_hdr_s);
  34. }
  35. /*
  36. * Convert bfa speed to rpsc speed value.
  37. */
  38. static inline enum bfa_port_speed
  39. fc_rpsc_operspeed_to_bfa_speed(enum fc_rpsc_op_speed speed)
  40. {
  41. switch (speed) {
  42. case RPSC_OP_SPEED_1G:
  43. return BFA_PORT_SPEED_1GBPS;
  44. case RPSC_OP_SPEED_2G:
  45. return BFA_PORT_SPEED_2GBPS;
  46. case RPSC_OP_SPEED_4G:
  47. return BFA_PORT_SPEED_4GBPS;
  48. case RPSC_OP_SPEED_8G:
  49. return BFA_PORT_SPEED_8GBPS;
  50. case RPSC_OP_SPEED_16G:
  51. return BFA_PORT_SPEED_16GBPS;
  52. case RPSC_OP_SPEED_10G:
  53. return BFA_PORT_SPEED_10GBPS;
  54. default:
  55. return BFA_PORT_SPEED_UNKNOWN;
  56. }
  57. }
  58. /*
  59. * Convert RPSC speed to bfa speed value.
  60. */
  61. static inline enum fc_rpsc_op_speed
  62. fc_bfa_speed_to_rpsc_operspeed(enum bfa_port_speed op_speed)
  63. {
  64. switch (op_speed) {
  65. case BFA_PORT_SPEED_1GBPS:
  66. return RPSC_OP_SPEED_1G;
  67. case BFA_PORT_SPEED_2GBPS:
  68. return RPSC_OP_SPEED_2G;
  69. case BFA_PORT_SPEED_4GBPS:
  70. return RPSC_OP_SPEED_4G;
  71. case BFA_PORT_SPEED_8GBPS:
  72. return RPSC_OP_SPEED_8G;
  73. case BFA_PORT_SPEED_16GBPS:
  74. return RPSC_OP_SPEED_16G;
  75. case BFA_PORT_SPEED_10GBPS:
  76. return RPSC_OP_SPEED_10G;
  77. default:
  78. return RPSC_OP_SPEED_NOT_EST;
  79. }
  80. }
  81. enum fc_parse_status {
  82. FC_PARSE_OK = 0,
  83. FC_PARSE_FAILURE = 1,
  84. FC_PARSE_BUSY = 2,
  85. FC_PARSE_LEN_INVAL,
  86. FC_PARSE_ACC_INVAL,
  87. FC_PARSE_PWWN_NOT_EQUAL,
  88. FC_PARSE_NWWN_NOT_EQUAL,
  89. FC_PARSE_RXSZ_INVAL,
  90. FC_PARSE_NOT_FCP,
  91. FC_PARSE_OPAFLAG_INVAL,
  92. FC_PARSE_RPAFLAG_INVAL,
  93. FC_PARSE_OPA_INVAL,
  94. FC_PARSE_RPA_INVAL,
  95. };
  96. struct fc_templates_s {
  97. struct fchs_s fc_els_req;
  98. struct fchs_s fc_bls_req;
  99. struct fc_logi_s plogi;
  100. struct fc_rrq_s rrq;
  101. };
  102. void fcbuild_init(void);
  103. u16 fc_flogi_acc_build(struct fchs_s *fchs, struct fc_logi_s *flogi,
  104. u32 s_id, __be16 ox_id,
  105. wwn_t port_name, wwn_t node_name,
  106. u16 pdu_size,
  107. u16 local_bb_credits, u8 bb_scn);
  108. u16 fc_plogi_build(struct fchs_s *fchs, void *pld, u32 d_id,
  109. u32 s_id, u16 ox_id, wwn_t port_name,
  110. wwn_t node_name, u16 pdu_size, u16 bb_cr);
  111. enum fc_parse_status fc_plogi_parse(struct fchs_s *fchs);
  112. u16 fc_rspnid_build(struct fchs_s *fchs, void *pld, u32 s_id,
  113. u16 ox_id, u8 *name);
  114. u16 fc_rsnn_nn_build(struct fchs_s *fchs, void *pld, u32 s_id,
  115. wwn_t node_name, u8 *name);
  116. u16 fc_rftid_build(struct fchs_s *fchs, void *pld, u32 s_id,
  117. u16 ox_id, enum bfa_lport_role role);
  118. u16 fc_rffid_build(struct fchs_s *fchs, void *pyld, u32 s_id,
  119. u16 ox_id, u8 fc4_type, u8 fc4_ftrs);
  120. u16 fc_gidpn_build(struct fchs_s *fchs, void *pyld, u32 s_id,
  121. u16 ox_id, wwn_t port_name);
  122. u16 fc_gpnid_build(struct fchs_s *fchs, void *pld, u32 s_id,
  123. u16 ox_id, u32 port_id);
  124. u16 fc_gs_rjt_build(struct fchs_s *fchs, struct ct_hdr_s *cthdr,
  125. u32 d_id, u32 s_id, u16 ox_id,
  126. u8 reason_code, u8 reason_code_expl);
  127. u16 fc_scr_build(struct fchs_s *fchs, struct fc_scr_s *scr,
  128. u8 set_br_reg, u32 s_id, u16 ox_id);
  129. u16 fc_plogi_acc_build(struct fchs_s *fchs, void *pld, u32 d_id,
  130. u32 s_id, u16 ox_id,
  131. wwn_t port_name, wwn_t node_name,
  132. u16 pdu_size, u16 bb_cr);
  133. u16 fc_adisc_build(struct fchs_s *fchs, struct fc_adisc_s *adisc,
  134. u32 d_id, u32 s_id, __be16 ox_id, wwn_t port_name,
  135. wwn_t node_name);
  136. enum fc_parse_status fc_adisc_rsp_parse(struct fc_adisc_s *adisc, int len,
  137. wwn_t port_name, wwn_t node_name);
  138. u16 fc_adisc_acc_build(struct fchs_s *fchs, struct fc_adisc_s *adisc,
  139. u32 d_id, u32 s_id, __be16 ox_id,
  140. wwn_t port_name, wwn_t node_name);
  141. u16 fc_ls_rjt_build(struct fchs_s *fchs, struct fc_ls_rjt_s *ls_rjt,
  142. u32 d_id, u32 s_id, __be16 ox_id,
  143. u8 reason_code, u8 reason_code_expl);
  144. u16 fc_ls_acc_build(struct fchs_s *fchs, struct fc_els_cmd_s *els_cmd,
  145. u32 d_id, u32 s_id, __be16 ox_id);
  146. u16 fc_prli_build(struct fchs_s *fchs, void *pld, u32 d_id,
  147. u32 s_id, u16 ox_id);
  148. enum fc_parse_status fc_prli_rsp_parse(struct fc_prli_s *prli, int len);
  149. u16 fc_prli_acc_build(struct fchs_s *fchs, void *pld, u32 d_id,
  150. u32 s_id, __be16 ox_id,
  151. enum bfa_lport_role role);
  152. u16 fc_rnid_acc_build(struct fchs_s *fchs,
  153. struct fc_rnid_acc_s *rnid_acc, u32 d_id, u32 s_id,
  154. __be16 ox_id, u32 data_format,
  155. struct fc_rnid_common_id_data_s *common_id_data,
  156. struct fc_rnid_general_topology_data_s *gen_topo_data);
  157. u16 fc_rpsc2_build(struct fchs_s *fchs, struct fc_rpsc2_cmd_s *rps2c,
  158. u32 d_id, u32 s_id, u32 *pid_list, u16 npids);
  159. u16 fc_rpsc_acc_build(struct fchs_s *fchs,
  160. struct fc_rpsc_acc_s *rpsc_acc, u32 d_id, u32 s_id,
  161. __be16 ox_id, struct fc_rpsc_speed_info_s *oper_speed);
  162. u16 fc_gid_ft_build(struct fchs_s *fchs, void *pld, u32 s_id,
  163. u8 fc4_type);
  164. u16 fc_rnnid_build(struct fchs_s *fchs, void *pyld, u32 s_id,
  165. u32 port_id, wwn_t node_name);
  166. u16 fc_logo_build(struct fchs_s *fchs, struct fc_logo_s *logo, u32 d_id,
  167. u32 s_id, u16 ox_id, wwn_t port_name);
  168. u16 fc_logo_acc_build(struct fchs_s *fchs, void *pld, u32 d_id,
  169. u32 s_id, __be16 ox_id);
  170. u16 fc_fdmi_reqhdr_build(struct fchs_s *fchs, void *pyld, u32 s_id,
  171. u16 cmd_code);
  172. u16 fc_gmal_req_build(struct fchs_s *fchs, void *pyld, u32 s_id, wwn_t wwn);
  173. u16 fc_gfn_req_build(struct fchs_s *fchs, void *pyld, u32 s_id, wwn_t wwn);
  174. void fc_get_fc4type_bitmask(u8 fc4_type, u8 *bit_mask);
  175. void fc_els_req_build(struct fchs_s *fchs, u32 d_id, u32 s_id,
  176. __be16 ox_id);
  177. u16 fc_ba_acc_build(struct fchs_s *fchs, struct fc_ba_acc_s *ba_acc, u32 d_id,
  178. u32 s_id, __be16 ox_id, u16 rx_id);
  179. int fc_logout_params_pages(struct fchs_s *fc_frame, u8 els_code);
  180. u16 fc_prlo_acc_build(struct fchs_s *fchs, struct fc_prlo_acc_s *prlo_acc,
  181. u32 d_id, u32 s_id, __be16 ox_id, int num_pages);
  182. u16 fc_tprlo_build(struct fchs_s *fchs, u32 d_id, u32 s_id,
  183. u16 ox_id, int num_pages, enum fc_tprlo_type tprlo_type,
  184. u32 tpr_id);
  185. #endif