2 * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
3 * Copyright (c) 2014- QLogic Corporation.
7 * Linux driver for QLogic BR-series Fibre Channel Host Bus Adapter.
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License (GPL) Version 2 as
11 * published by the Free Software Foundation
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
19 * fcbuild.h - FC link service frame building and parsing routines
27 #include "bfa_defs_fcs.h"
30 * Utility Macros/functions
33 #define wwn_is_equal(_wwn1, _wwn2) \
34 (memcmp(&(_wwn1), &(_wwn2), sizeof(wwn_t)) == 0)
36 #define fc_roundup(_l, _s) (((_l) + ((_s) - 1)) & ~((_s) - 1))
39 * Given the fc response length, this routine will return
40 * the length of the actual payload bytes following the CT header.
42 * Assumes the input response length does not include the crc, eof, etc.
45 fc_get_ctresp_pyld_len(u32 resp_len)
47 return resp_len - sizeof(struct ct_hdr_s);
51 * Convert bfa speed to rpsc speed value.
53 static inline enum bfa_port_speed
54 fc_rpsc_operspeed_to_bfa_speed(enum fc_rpsc_op_speed speed)
58 case RPSC_OP_SPEED_1G:
59 return BFA_PORT_SPEED_1GBPS;
61 case RPSC_OP_SPEED_2G:
62 return BFA_PORT_SPEED_2GBPS;
64 case RPSC_OP_SPEED_4G:
65 return BFA_PORT_SPEED_4GBPS;
67 case RPSC_OP_SPEED_8G:
68 return BFA_PORT_SPEED_8GBPS;
70 case RPSC_OP_SPEED_16G:
71 return BFA_PORT_SPEED_16GBPS;
73 case RPSC_OP_SPEED_10G:
74 return BFA_PORT_SPEED_10GBPS;
77 return BFA_PORT_SPEED_UNKNOWN;
82 * Convert RPSC speed to bfa speed value.
84 static inline enum fc_rpsc_op_speed
85 fc_bfa_speed_to_rpsc_operspeed(enum bfa_port_speed op_speed)
89 case BFA_PORT_SPEED_1GBPS:
90 return RPSC_OP_SPEED_1G;
92 case BFA_PORT_SPEED_2GBPS:
93 return RPSC_OP_SPEED_2G;
95 case BFA_PORT_SPEED_4GBPS:
96 return RPSC_OP_SPEED_4G;
98 case BFA_PORT_SPEED_8GBPS:
99 return RPSC_OP_SPEED_8G;
101 case BFA_PORT_SPEED_16GBPS:
102 return RPSC_OP_SPEED_16G;
104 case BFA_PORT_SPEED_10GBPS:
105 return RPSC_OP_SPEED_10G;
108 return RPSC_OP_SPEED_NOT_EST;
112 enum fc_parse_status {
114 FC_PARSE_FAILURE = 1,
118 FC_PARSE_PWWN_NOT_EQUAL,
119 FC_PARSE_NWWN_NOT_EQUAL,
122 FC_PARSE_OPAFLAG_INVAL,
123 FC_PARSE_RPAFLAG_INVAL,
129 struct fc_templates_s {
130 struct fchs_s fc_els_req;
131 struct fchs_s fc_bls_req;
132 struct fc_logi_s plogi;
136 void fcbuild_init(void);
138 u16 fc_flogi_build(struct fchs_s *fchs, struct fc_logi_s *flogi,
139 u32 s_id, u16 ox_id, wwn_t port_name, wwn_t node_name,
140 u16 pdu_size, u8 set_npiv, u8 set_auth,
141 u16 local_bb_credits);
143 u16 fc_fdisc_build(struct fchs_s *buf, struct fc_logi_s *flogi, u32 s_id,
144 u16 ox_id, wwn_t port_name, wwn_t node_name,
147 u16 fc_flogi_acc_build(struct fchs_s *fchs, struct fc_logi_s *flogi,
148 u32 s_id, __be16 ox_id,
149 wwn_t port_name, wwn_t node_name,
151 u16 local_bb_credits, u8 bb_scn);
153 u16 fc_plogi_build(struct fchs_s *fchs, void *pld, u32 d_id,
154 u32 s_id, u16 ox_id, wwn_t port_name,
155 wwn_t node_name, u16 pdu_size, u16 bb_cr);
157 enum fc_parse_status fc_plogi_parse(struct fchs_s *fchs);
159 u16 fc_abts_build(struct fchs_s *buf, u32 d_id, u32 s_id,
162 enum fc_parse_status fc_abts_rsp_parse(struct fchs_s *buf, int len);
164 u16 fc_rrq_build(struct fchs_s *buf, struct fc_rrq_s *rrq, u32 d_id,
165 u32 s_id, u16 ox_id, u16 rrq_oxid);
167 u16 fc_rspnid_build(struct fchs_s *fchs, void *pld, u32 s_id,
168 u16 ox_id, u8 *name);
169 u16 fc_rsnn_nn_build(struct fchs_s *fchs, void *pld, u32 s_id,
170 wwn_t node_name, u8 *name);
172 u16 fc_rftid_build(struct fchs_s *fchs, void *pld, u32 s_id,
173 u16 ox_id, enum bfa_lport_role role);
175 u16 fc_rftid_build_sol(struct fchs_s *fchs, void *pyld, u32 s_id,
176 u16 ox_id, u8 *fc4_bitmap,
179 u16 fc_rffid_build(struct fchs_s *fchs, void *pyld, u32 s_id,
180 u16 ox_id, u8 fc4_type, u8 fc4_ftrs);
182 u16 fc_gidpn_build(struct fchs_s *fchs, void *pyld, u32 s_id,
183 u16 ox_id, wwn_t port_name);
185 u16 fc_gpnid_build(struct fchs_s *fchs, void *pld, u32 s_id,
186 u16 ox_id, u32 port_id);
188 u16 fc_gs_rjt_build(struct fchs_s *fchs, struct ct_hdr_s *cthdr,
189 u32 d_id, u32 s_id, u16 ox_id,
190 u8 reason_code, u8 reason_code_expl);
192 u16 fc_scr_build(struct fchs_s *fchs, struct fc_scr_s *scr,
193 u8 set_br_reg, u32 s_id, u16 ox_id);
195 u16 fc_plogi_acc_build(struct fchs_s *fchs, void *pld, u32 d_id,
197 wwn_t port_name, wwn_t node_name,
198 u16 pdu_size, u16 bb_cr);
200 u16 fc_adisc_build(struct fchs_s *fchs, struct fc_adisc_s *adisc,
201 u32 d_id, u32 s_id, __be16 ox_id, wwn_t port_name,
204 enum fc_parse_status fc_adisc_parse(struct fchs_s *fchs, void *pld,
205 u32 host_dap, wwn_t node_name, wwn_t port_name);
207 enum fc_parse_status fc_adisc_rsp_parse(struct fc_adisc_s *adisc, int len,
208 wwn_t port_name, wwn_t node_name);
210 u16 fc_adisc_acc_build(struct fchs_s *fchs, struct fc_adisc_s *adisc,
211 u32 d_id, u32 s_id, __be16 ox_id,
212 wwn_t port_name, wwn_t node_name);
213 u16 fc_ls_rjt_build(struct fchs_s *fchs, struct fc_ls_rjt_s *ls_rjt,
214 u32 d_id, u32 s_id, __be16 ox_id,
215 u8 reason_code, u8 reason_code_expl);
216 u16 fc_ls_acc_build(struct fchs_s *fchs, struct fc_els_cmd_s *els_cmd,
217 u32 d_id, u32 s_id, __be16 ox_id);
218 u16 fc_prli_build(struct fchs_s *fchs, void *pld, u32 d_id,
219 u32 s_id, u16 ox_id);
221 enum fc_parse_status fc_prli_rsp_parse(struct fc_prli_s *prli, int len);
223 u16 fc_prli_acc_build(struct fchs_s *fchs, void *pld, u32 d_id,
224 u32 s_id, __be16 ox_id,
225 enum bfa_lport_role role);
227 u16 fc_rnid_build(struct fchs_s *fchs, struct fc_rnid_cmd_s *rnid,
228 u32 d_id, u32 s_id, u16 ox_id,
231 u16 fc_rnid_acc_build(struct fchs_s *fchs,
232 struct fc_rnid_acc_s *rnid_acc, u32 d_id, u32 s_id,
233 __be16 ox_id, u32 data_format,
234 struct fc_rnid_common_id_data_s *common_id_data,
235 struct fc_rnid_general_topology_data_s *gen_topo_data);
237 u16 fc_rpsc2_build(struct fchs_s *fchs, struct fc_rpsc2_cmd_s *rps2c,
238 u32 d_id, u32 s_id, u32 *pid_list, u16 npids);
239 u16 fc_rpsc_build(struct fchs_s *fchs, struct fc_rpsc_cmd_s *rpsc,
240 u32 d_id, u32 s_id, u16 ox_id);
241 u16 fc_rpsc_acc_build(struct fchs_s *fchs,
242 struct fc_rpsc_acc_s *rpsc_acc, u32 d_id, u32 s_id,
243 __be16 ox_id, struct fc_rpsc_speed_info_s *oper_speed);
244 u16 fc_gid_ft_build(struct fchs_s *fchs, void *pld, u32 s_id,
247 u16 fc_rpnid_build(struct fchs_s *fchs, void *pyld, u32 s_id,
248 u32 port_id, wwn_t port_name);
250 u16 fc_rnnid_build(struct fchs_s *fchs, void *pyld, u32 s_id,
251 u32 port_id, wwn_t node_name);
253 u16 fc_rcsid_build(struct fchs_s *fchs, void *pyld, u32 s_id,
254 u32 port_id, u32 cos);
256 u16 fc_rptid_build(struct fchs_s *fchs, void *pyld, u32 s_id,
257 u32 port_id, u8 port_type);
259 u16 fc_ganxt_build(struct fchs_s *fchs, void *pyld, u32 s_id,
262 u16 fc_logo_build(struct fchs_s *fchs, struct fc_logo_s *logo, u32 d_id,
263 u32 s_id, u16 ox_id, wwn_t port_name);
265 u16 fc_logo_acc_build(struct fchs_s *fchs, void *pld, u32 d_id,
266 u32 s_id, __be16 ox_id);
268 u16 fc_fdmi_reqhdr_build(struct fchs_s *fchs, void *pyld, u32 s_id,
270 u16 fc_gmal_req_build(struct fchs_s *fchs, void *pyld, u32 s_id, wwn_t wwn);
271 u16 fc_gfn_req_build(struct fchs_s *fchs, void *pyld, u32 s_id, wwn_t wwn);
273 void fc_get_fc4type_bitmask(u8 fc4_type, u8 *bit_mask);
275 void fc_els_req_build(struct fchs_s *fchs, u32 d_id, u32 s_id,
278 enum fc_parse_status fc_plogi_rsp_parse(struct fchs_s *fchs, int len,
281 enum fc_parse_status fc_prli_parse(struct fc_prli_s *prli);
283 enum fc_parse_status fc_pdisc_parse(struct fchs_s *fchs, wwn_t node_name,
286 u16 fc_ba_acc_build(struct fchs_s *fchs, struct fc_ba_acc_s *ba_acc, u32 d_id,
287 u32 s_id, __be16 ox_id, u16 rx_id);
289 int fc_logout_params_pages(struct fchs_s *fc_frame, u8 els_code);
291 u16 fc_tprlo_acc_build(struct fchs_s *fchs, struct fc_tprlo_acc_s *tprlo_acc,
292 u32 d_id, u32 s_id, __be16 ox_id, int num_pages);
294 u16 fc_prlo_acc_build(struct fchs_s *fchs, struct fc_prlo_acc_s *prlo_acc,
295 u32 d_id, u32 s_id, __be16 ox_id, int num_pages);
297 u16 fc_pdisc_build(struct fchs_s *fchs, u32 d_id, u32 s_id,
298 u16 ox_id, wwn_t port_name, wwn_t node_name,
301 u16 fc_pdisc_rsp_parse(struct fchs_s *fchs, int len, wwn_t port_name);
303 u16 fc_prlo_build(struct fchs_s *fchs, u32 d_id, u32 s_id,
304 u16 ox_id, int num_pages);
306 u16 fc_tprlo_build(struct fchs_s *fchs, u32 d_id, u32 s_id,
307 u16 ox_id, int num_pages, enum fc_tprlo_type tprlo_type,
310 u16 fc_ba_rjt_build(struct fchs_s *fchs, u32 d_id, u32 s_id,
311 __be16 ox_id, u32 reason_code, u32 reason_expl);
313 u16 fc_gnnid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
316 u16 fc_ct_rsp_parse(struct ct_hdr_s *cthdr);
318 u16 fc_rscn_build(struct fchs_s *fchs, struct fc_rscn_pl_s *rscn, u32 s_id,