Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
0004  * Copyright (c) 2014- QLogic Corporation.
0005  * All rights reserved
0006  * www.qlogic.com
0007  *
0008  * Linux driver for QLogic BR-series Fibre Channel Host Bus Adapter.
0009  */
0010 /*
0011  * fcbuild.h - FC link service frame building and parsing routines
0012  */
0013 
0014 #ifndef __FCBUILD_H__
0015 #define __FCBUILD_H__
0016 
0017 #include "bfad_drv.h"
0018 #include "bfa_fc.h"
0019 #include "bfa_defs_fcs.h"
0020 
0021 /*
0022  * Utility Macros/functions
0023  */
0024 
0025 #define wwn_is_equal(_wwn1, _wwn2)      \
0026     (memcmp(&(_wwn1), &(_wwn2), sizeof(wwn_t)) == 0)
0027 
0028 #define fc_roundup(_l, _s) (((_l) + ((_s) - 1)) & ~((_s) - 1))
0029 
0030 /*
0031  * Given the fc response length, this routine will return
0032  * the length of the actual payload bytes following the CT header.
0033  *
0034  * Assumes the input response length does not include the crc, eof, etc.
0035  */
0036 static inline   u32
0037 fc_get_ctresp_pyld_len(u32 resp_len)
0038 {
0039     return resp_len - sizeof(struct ct_hdr_s);
0040 }
0041 
0042 /*
0043  * Convert bfa speed to rpsc speed value.
0044  */
0045 static inline  enum bfa_port_speed
0046 fc_rpsc_operspeed_to_bfa_speed(enum fc_rpsc_op_speed speed)
0047 {
0048     switch (speed) {
0049 
0050     case RPSC_OP_SPEED_1G:
0051         return BFA_PORT_SPEED_1GBPS;
0052 
0053     case RPSC_OP_SPEED_2G:
0054         return BFA_PORT_SPEED_2GBPS;
0055 
0056     case RPSC_OP_SPEED_4G:
0057         return BFA_PORT_SPEED_4GBPS;
0058 
0059     case RPSC_OP_SPEED_8G:
0060         return BFA_PORT_SPEED_8GBPS;
0061 
0062     case RPSC_OP_SPEED_16G:
0063         return BFA_PORT_SPEED_16GBPS;
0064 
0065     case RPSC_OP_SPEED_10G:
0066         return BFA_PORT_SPEED_10GBPS;
0067 
0068     default:
0069         return BFA_PORT_SPEED_UNKNOWN;
0070     }
0071 }
0072 
0073 /*
0074  * Convert RPSC speed to bfa speed value.
0075  */
0076 static inline   enum fc_rpsc_op_speed
0077 fc_bfa_speed_to_rpsc_operspeed(enum bfa_port_speed op_speed)
0078 {
0079     switch (op_speed) {
0080 
0081     case BFA_PORT_SPEED_1GBPS:
0082         return RPSC_OP_SPEED_1G;
0083 
0084     case BFA_PORT_SPEED_2GBPS:
0085         return RPSC_OP_SPEED_2G;
0086 
0087     case BFA_PORT_SPEED_4GBPS:
0088         return RPSC_OP_SPEED_4G;
0089 
0090     case BFA_PORT_SPEED_8GBPS:
0091         return RPSC_OP_SPEED_8G;
0092 
0093     case BFA_PORT_SPEED_16GBPS:
0094         return RPSC_OP_SPEED_16G;
0095 
0096     case BFA_PORT_SPEED_10GBPS:
0097         return RPSC_OP_SPEED_10G;
0098 
0099     default:
0100         return RPSC_OP_SPEED_NOT_EST;
0101     }
0102 }
0103 
0104 enum fc_parse_status {
0105     FC_PARSE_OK = 0,
0106     FC_PARSE_FAILURE = 1,
0107     FC_PARSE_BUSY = 2,
0108     FC_PARSE_LEN_INVAL,
0109     FC_PARSE_ACC_INVAL,
0110     FC_PARSE_PWWN_NOT_EQUAL,
0111     FC_PARSE_NWWN_NOT_EQUAL,
0112     FC_PARSE_RXSZ_INVAL,
0113     FC_PARSE_NOT_FCP,
0114     FC_PARSE_OPAFLAG_INVAL,
0115     FC_PARSE_RPAFLAG_INVAL,
0116     FC_PARSE_OPA_INVAL,
0117     FC_PARSE_RPA_INVAL,
0118 
0119 };
0120 
0121 struct fc_templates_s {
0122     struct fchs_s fc_els_req;
0123     struct fchs_s fc_bls_req;
0124     struct fc_logi_s plogi;
0125     struct fc_rrq_s rrq;
0126 };
0127 
0128 void            fcbuild_init(void);
0129 
0130 u16        fc_flogi_build(struct fchs_s *fchs, struct fc_logi_s *flogi,
0131             u32 s_id, u16 ox_id, wwn_t port_name, wwn_t node_name,
0132                    u16 pdu_size, u8 set_npiv, u8 set_auth,
0133                    u16 local_bb_credits);
0134 
0135 u16        fc_fdisc_build(struct fchs_s *buf, struct fc_logi_s *flogi, u32 s_id,
0136                    u16 ox_id, wwn_t port_name, wwn_t node_name,
0137                    u16 pdu_size);
0138 
0139 u16        fc_flogi_acc_build(struct fchs_s *fchs, struct fc_logi_s *flogi,
0140                    u32 s_id, __be16 ox_id,
0141                    wwn_t port_name, wwn_t node_name,
0142                    u16 pdu_size,
0143                    u16 local_bb_credits, u8 bb_scn);
0144 
0145 u16        fc_plogi_build(struct fchs_s *fchs, void *pld, u32 d_id,
0146                    u32 s_id, u16 ox_id, wwn_t port_name,
0147                    wwn_t node_name, u16 pdu_size, u16 bb_cr);
0148 
0149 enum fc_parse_status fc_plogi_parse(struct fchs_s *fchs);
0150 
0151 u16        fc_abts_build(struct fchs_s *buf, u32 d_id, u32 s_id,
0152                   u16 ox_id);
0153 
0154 enum fc_parse_status fc_abts_rsp_parse(struct fchs_s *buf, int len);
0155 
0156 u16        fc_rrq_build(struct fchs_s *buf, struct fc_rrq_s *rrq, u32 d_id,
0157                  u32 s_id, u16 ox_id, u16 rrq_oxid);
0158 
0159 u16        fc_rspnid_build(struct fchs_s *fchs, void *pld, u32 s_id,
0160                 u16 ox_id, u8 *name);
0161 u16 fc_rsnn_nn_build(struct fchs_s *fchs, void *pld, u32 s_id,
0162                 wwn_t node_name, u8 *name);
0163 
0164 u16        fc_rftid_build(struct fchs_s *fchs, void *pld, u32 s_id,
0165                    u16 ox_id, enum bfa_lport_role role);
0166 
0167 u16       fc_rftid_build_sol(struct fchs_s *fchs, void *pyld, u32 s_id,
0168                    u16 ox_id, u8 *fc4_bitmap,
0169                    u32 bitmap_size);
0170 
0171 u16 fc_rffid_build(struct fchs_s *fchs, void *pyld, u32 s_id,
0172             u16 ox_id, u8 fc4_type, u8 fc4_ftrs);
0173 
0174 u16        fc_gidpn_build(struct fchs_s *fchs, void *pyld, u32 s_id,
0175                    u16 ox_id, wwn_t port_name);
0176 
0177 u16        fc_gpnid_build(struct fchs_s *fchs, void *pld, u32 s_id,
0178                    u16 ox_id, u32 port_id);
0179 
0180 u16 fc_gs_rjt_build(struct fchs_s *fchs, struct ct_hdr_s *cthdr,
0181             u32 d_id, u32 s_id, u16 ox_id,
0182             u8 reason_code, u8 reason_code_expl);
0183 
0184 u16        fc_scr_build(struct fchs_s *fchs, struct fc_scr_s *scr,
0185             u8 set_br_reg, u32 s_id, u16 ox_id);
0186 
0187 u16        fc_plogi_acc_build(struct fchs_s *fchs, void *pld, u32 d_id,
0188                    u32 s_id, u16 ox_id,
0189                    wwn_t port_name, wwn_t node_name,
0190                    u16 pdu_size, u16 bb_cr);
0191 
0192 u16        fc_adisc_build(struct fchs_s *fchs, struct fc_adisc_s *adisc,
0193             u32 d_id, u32 s_id, __be16 ox_id, wwn_t port_name,
0194                    wwn_t node_name);
0195 
0196 enum fc_parse_status fc_adisc_parse(struct fchs_s *fchs, void *pld,
0197             u32 host_dap, wwn_t node_name, wwn_t port_name);
0198 
0199 enum fc_parse_status fc_adisc_rsp_parse(struct fc_adisc_s *adisc, int len,
0200                  wwn_t port_name, wwn_t node_name);
0201 
0202 u16        fc_adisc_acc_build(struct fchs_s *fchs, struct fc_adisc_s *adisc,
0203                    u32 d_id, u32 s_id, __be16 ox_id,
0204                    wwn_t port_name, wwn_t node_name);
0205 u16        fc_ls_rjt_build(struct fchs_s *fchs, struct fc_ls_rjt_s *ls_rjt,
0206                 u32 d_id, u32 s_id, __be16 ox_id,
0207                 u8 reason_code, u8 reason_code_expl);
0208 u16        fc_ls_acc_build(struct fchs_s *fchs, struct fc_els_cmd_s *els_cmd,
0209                 u32 d_id, u32 s_id, __be16 ox_id);
0210 u16        fc_prli_build(struct fchs_s *fchs, void *pld, u32 d_id,
0211                   u32 s_id, u16 ox_id);
0212 
0213 enum fc_parse_status fc_prli_rsp_parse(struct fc_prli_s *prli, int len);
0214 
0215 u16        fc_prli_acc_build(struct fchs_s *fchs, void *pld, u32 d_id,
0216                   u32 s_id, __be16 ox_id,
0217                   enum bfa_lport_role role);
0218 
0219 u16        fc_rnid_build(struct fchs_s *fchs, struct fc_rnid_cmd_s *rnid,
0220                   u32 d_id, u32 s_id, u16 ox_id,
0221                   u32 data_format);
0222 
0223 u16        fc_rnid_acc_build(struct fchs_s *fchs,
0224             struct fc_rnid_acc_s *rnid_acc, u32 d_id, u32 s_id,
0225             __be16 ox_id, u32 data_format,
0226             struct fc_rnid_common_id_data_s *common_id_data,
0227             struct fc_rnid_general_topology_data_s *gen_topo_data);
0228 
0229 u16 fc_rpsc2_build(struct fchs_s *fchs, struct fc_rpsc2_cmd_s *rps2c,
0230             u32 d_id, u32 s_id, u32 *pid_list, u16 npids);
0231 u16        fc_rpsc_build(struct fchs_s *fchs, struct fc_rpsc_cmd_s *rpsc,
0232                   u32 d_id, u32 s_id, u16 ox_id);
0233 u16        fc_rpsc_acc_build(struct fchs_s *fchs,
0234             struct fc_rpsc_acc_s *rpsc_acc, u32 d_id, u32 s_id,
0235             __be16 ox_id, struct fc_rpsc_speed_info_s *oper_speed);
0236 u16        fc_gid_ft_build(struct fchs_s *fchs, void *pld, u32 s_id,
0237                 u8 fc4_type);
0238 
0239 u16        fc_rpnid_build(struct fchs_s *fchs, void *pyld, u32 s_id,
0240                    u32 port_id, wwn_t port_name);
0241 
0242 u16        fc_rnnid_build(struct fchs_s *fchs, void *pyld, u32 s_id,
0243                    u32 port_id, wwn_t node_name);
0244 
0245 u16        fc_rcsid_build(struct fchs_s *fchs, void *pyld, u32 s_id,
0246                    u32 port_id, u32 cos);
0247 
0248 u16        fc_rptid_build(struct fchs_s *fchs, void *pyld, u32 s_id,
0249                    u32 port_id, u8 port_type);
0250 
0251 u16        fc_ganxt_build(struct fchs_s *fchs, void *pyld, u32 s_id,
0252                    u32 port_id);
0253 
0254 u16        fc_logo_build(struct fchs_s *fchs, struct fc_logo_s *logo, u32 d_id,
0255                   u32 s_id, u16 ox_id, wwn_t port_name);
0256 
0257 u16        fc_logo_acc_build(struct fchs_s *fchs, void *pld, u32 d_id,
0258                   u32 s_id, __be16 ox_id);
0259 
0260 u16        fc_fdmi_reqhdr_build(struct fchs_s *fchs, void *pyld, u32 s_id,
0261                      u16 cmd_code);
0262 u16 fc_gmal_req_build(struct fchs_s *fchs, void *pyld, u32 s_id, wwn_t wwn);
0263 u16 fc_gfn_req_build(struct fchs_s *fchs, void *pyld, u32 s_id, wwn_t wwn);
0264 
0265 void        fc_get_fc4type_bitmask(u8 fc4_type, u8 *bit_mask);
0266 
0267 void        fc_els_req_build(struct fchs_s *fchs, u32 d_id, u32 s_id,
0268                      __be16 ox_id);
0269 
0270 enum fc_parse_status    fc_plogi_rsp_parse(struct fchs_s *fchs, int len,
0271                     wwn_t port_name);
0272 
0273 enum fc_parse_status    fc_prli_parse(struct fc_prli_s *prli);
0274 
0275 enum fc_parse_status    fc_pdisc_parse(struct fchs_s *fchs, wwn_t node_name,
0276                     wwn_t port_name);
0277 
0278 u16 fc_ba_acc_build(struct fchs_s *fchs, struct fc_ba_acc_s *ba_acc, u32 d_id,
0279         u32 s_id, __be16 ox_id, u16 rx_id);
0280 
0281 int fc_logout_params_pages(struct fchs_s *fc_frame, u8 els_code);
0282 
0283 u16 fc_tprlo_acc_build(struct fchs_s *fchs, struct fc_tprlo_acc_s *tprlo_acc,
0284         u32 d_id, u32 s_id, __be16 ox_id, int num_pages);
0285 
0286 u16 fc_prlo_acc_build(struct fchs_s *fchs, struct fc_prlo_acc_s *prlo_acc,
0287         u32 d_id, u32 s_id, __be16 ox_id, int num_pages);
0288 
0289 u16 fc_pdisc_build(struct fchs_s *fchs, u32 d_id, u32 s_id,
0290         u16 ox_id, wwn_t port_name, wwn_t node_name,
0291         u16 pdu_size);
0292 
0293 u16 fc_pdisc_rsp_parse(struct fchs_s *fchs, int len, wwn_t port_name);
0294 
0295 u16 fc_prlo_build(struct fchs_s *fchs, u32 d_id, u32 s_id,
0296         u16 ox_id, int num_pages);
0297 
0298 u16 fc_tprlo_build(struct fchs_s *fchs, u32 d_id, u32 s_id,
0299         u16 ox_id, int num_pages, enum fc_tprlo_type tprlo_type,
0300         u32 tpr_id);
0301 
0302 u16 fc_ba_rjt_build(struct fchs_s *fchs, u32 d_id, u32 s_id,
0303         __be16 ox_id, u32 reason_code, u32 reason_expl);
0304 
0305 u16 fc_gnnid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
0306         u32 port_id);
0307 
0308 u16 fc_ct_rsp_parse(struct ct_hdr_s *cthdr);
0309 
0310 u16 fc_rscn_build(struct fchs_s *fchs, struct fc_rscn_pl_s *rscn, u32 s_id,
0311         u16 ox_id);
0312 #endif