2 * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
6 * Linux driver for Brocade Fibre Channel Host Bus Adapter.
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
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.
18 * fcbuild.h - FC link service frame building and parsing routines
26 #include "bfa_defs_fcs.h"
29 * Utility Macros/functions
32 #define wwn_is_equal(_wwn1, _wwn2) \
33 (memcmp(&(_wwn1), &(_wwn2), sizeof(wwn_t)) == 0)
35 #define fc_roundup(_l, _s) (((_l) + ((_s) - 1)) & ~((_s) - 1))
38 * Given the fc response length, this routine will return
39 * the length of the actual payload bytes following the CT header.
41 * Assumes the input response length does not include the crc, eof, etc.
44 fc_get_ctresp_pyld_len(u32 resp_len
)
46 return resp_len
- sizeof(struct ct_hdr_s
);
50 * Convert bfa speed to rpsc speed value.
52 static inline enum bfa_port_speed
53 fc_rpsc_operspeed_to_bfa_speed(enum fc_rpsc_op_speed speed
)
57 case RPSC_OP_SPEED_1G
:
58 return BFA_PORT_SPEED_1GBPS
;
60 case RPSC_OP_SPEED_2G
:
61 return BFA_PORT_SPEED_2GBPS
;
63 case RPSC_OP_SPEED_4G
:
64 return BFA_PORT_SPEED_4GBPS
;
66 case RPSC_OP_SPEED_8G
:
67 return BFA_PORT_SPEED_8GBPS
;
69 case RPSC_OP_SPEED_10G
:
70 return BFA_PORT_SPEED_10GBPS
;
73 return BFA_PORT_SPEED_UNKNOWN
;
78 * Convert RPSC speed to bfa speed value.
80 static inline enum fc_rpsc_op_speed
81 fc_bfa_speed_to_rpsc_operspeed(enum bfa_port_speed op_speed
)
85 case BFA_PORT_SPEED_1GBPS
:
86 return RPSC_OP_SPEED_1G
;
88 case BFA_PORT_SPEED_2GBPS
:
89 return RPSC_OP_SPEED_2G
;
91 case BFA_PORT_SPEED_4GBPS
:
92 return RPSC_OP_SPEED_4G
;
94 case BFA_PORT_SPEED_8GBPS
:
95 return RPSC_OP_SPEED_8G
;
97 case BFA_PORT_SPEED_10GBPS
:
98 return RPSC_OP_SPEED_10G
;
101 return RPSC_OP_SPEED_NOT_EST
;
105 enum fc_parse_status
{
107 FC_PARSE_FAILURE
= 1,
111 FC_PARSE_PWWN_NOT_EQUAL
,
112 FC_PARSE_NWWN_NOT_EQUAL
,
115 FC_PARSE_OPAFLAG_INVAL
,
116 FC_PARSE_RPAFLAG_INVAL
,
122 struct fc_templates_s
{
123 struct fchs_s fc_els_req
;
124 struct fchs_s fc_bls_req
;
125 struct fc_logi_s plogi
;
129 void fcbuild_init(void);
131 u16
fc_flogi_build(struct fchs_s
*fchs
, struct fc_logi_s
*flogi
,
132 u32 s_id
, u16 ox_id
, wwn_t port_name
, wwn_t node_name
,
133 u16 pdu_size
, u8 set_npiv
, u8 set_auth
,
134 u16 local_bb_credits
);
136 u16
fc_fdisc_build(struct fchs_s
*buf
, struct fc_logi_s
*flogi
, u32 s_id
,
137 u16 ox_id
, wwn_t port_name
, wwn_t node_name
,
140 u16
fc_flogi_acc_build(struct fchs_s
*fchs
, struct fc_logi_s
*flogi
,
141 u32 s_id
, __be16 ox_id
,
142 wwn_t port_name
, wwn_t node_name
,
144 u16 local_bb_credits
);
146 u16
fc_plogi_build(struct fchs_s
*fchs
, void *pld
, u32 d_id
,
147 u32 s_id
, u16 ox_id
, wwn_t port_name
,
148 wwn_t node_name
, u16 pdu_size
);
150 enum fc_parse_status
fc_plogi_parse(struct fchs_s
*fchs
);
152 u16
fc_abts_build(struct fchs_s
*buf
, u32 d_id
, u32 s_id
,
155 enum fc_parse_status
fc_abts_rsp_parse(struct fchs_s
*buf
, int len
);
157 u16
fc_rrq_build(struct fchs_s
*buf
, struct fc_rrq_s
*rrq
, u32 d_id
,
158 u32 s_id
, u16 ox_id
, u16 rrq_oxid
);
159 enum fc_parse_status
fc_rrq_rsp_parse(struct fchs_s
*buf
, int len
);
161 u16
fc_rspnid_build(struct fchs_s
*fchs
, void *pld
, u32 s_id
,
162 u16 ox_id
, u8
*name
);
164 u16
fc_rftid_build(struct fchs_s
*fchs
, void *pld
, u32 s_id
,
165 u16 ox_id
, enum bfa_lport_role role
);
167 u16
fc_rftid_build_sol(struct fchs_s
*fchs
, void *pyld
, u32 s_id
,
168 u16 ox_id
, u8
*fc4_bitmap
,
171 u16
fc_rffid_build(struct fchs_s
*fchs
, void *pyld
, u32 s_id
,
172 u16 ox_id
, u8 fc4_type
, u8 fc4_ftrs
);
174 u16
fc_gidpn_build(struct fchs_s
*fchs
, void *pyld
, u32 s_id
,
175 u16 ox_id
, wwn_t port_name
);
177 u16
fc_gpnid_build(struct fchs_s
*fchs
, void *pld
, u32 s_id
,
178 u16 ox_id
, u32 port_id
);
180 u16
fc_scr_build(struct fchs_s
*fchs
, struct fc_scr_s
*scr
,
181 u8 set_br_reg
, u32 s_id
, u16 ox_id
);
183 u16
fc_plogi_acc_build(struct fchs_s
*fchs
, void *pld
, u32 d_id
,
185 wwn_t port_name
, wwn_t node_name
,
188 u16
fc_adisc_build(struct fchs_s
*fchs
, struct fc_adisc_s
*adisc
,
189 u32 d_id
, u32 s_id
, __be16 ox_id
, wwn_t port_name
,
192 enum fc_parse_status
fc_adisc_parse(struct fchs_s
*fchs
, void *pld
,
193 u32 host_dap
, wwn_t node_name
, wwn_t port_name
);
195 enum fc_parse_status
fc_adisc_rsp_parse(struct fc_adisc_s
*adisc
, int len
,
196 wwn_t port_name
, wwn_t node_name
);
198 u16
fc_adisc_acc_build(struct fchs_s
*fchs
, struct fc_adisc_s
*adisc
,
199 u32 d_id
, u32 s_id
, __be16 ox_id
,
200 wwn_t port_name
, wwn_t node_name
);
201 u16
fc_ls_rjt_build(struct fchs_s
*fchs
, struct fc_ls_rjt_s
*ls_rjt
,
202 u32 d_id
, u32 s_id
, __be16 ox_id
,
203 u8 reason_code
, u8 reason_code_expl
);
204 u16
fc_ls_acc_build(struct fchs_s
*fchs
, struct fc_els_cmd_s
*els_cmd
,
205 u32 d_id
, u32 s_id
, __be16 ox_id
);
206 u16
fc_prli_build(struct fchs_s
*fchs
, void *pld
, u32 d_id
,
207 u32 s_id
, u16 ox_id
);
209 enum fc_parse_status
fc_prli_rsp_parse(struct fc_prli_s
*prli
, int len
);
211 u16
fc_prli_acc_build(struct fchs_s
*fchs
, void *pld
, u32 d_id
,
212 u32 s_id
, __be16 ox_id
,
213 enum bfa_lport_role role
);
215 u16
fc_rnid_build(struct fchs_s
*fchs
, struct fc_rnid_cmd_s
*rnid
,
216 u32 d_id
, u32 s_id
, u16 ox_id
,
219 u16
fc_rnid_acc_build(struct fchs_s
*fchs
,
220 struct fc_rnid_acc_s
*rnid_acc
, u32 d_id
, u32 s_id
,
221 __be16 ox_id
, u32 data_format
,
222 struct fc_rnid_common_id_data_s
*common_id_data
,
223 struct fc_rnid_general_topology_data_s
*gen_topo_data
);
225 u16
fc_rpsc2_build(struct fchs_s
*fchs
, struct fc_rpsc2_cmd_s
*rps2c
,
226 u32 d_id
, u32 s_id
, u32
*pid_list
, u16 npids
);
227 u16
fc_rpsc_build(struct fchs_s
*fchs
, struct fc_rpsc_cmd_s
*rpsc
,
228 u32 d_id
, u32 s_id
, u16 ox_id
);
229 u16
fc_rpsc_acc_build(struct fchs_s
*fchs
,
230 struct fc_rpsc_acc_s
*rpsc_acc
, u32 d_id
, u32 s_id
,
231 __be16 ox_id
, struct fc_rpsc_speed_info_s
*oper_speed
);
232 u16
fc_gid_ft_build(struct fchs_s
*fchs
, void *pld
, u32 s_id
,
235 u16
fc_rpnid_build(struct fchs_s
*fchs
, void *pyld
, u32 s_id
,
236 u32 port_id
, wwn_t port_name
);
238 u16
fc_rnnid_build(struct fchs_s
*fchs
, void *pyld
, u32 s_id
,
239 u32 port_id
, wwn_t node_name
);
241 u16
fc_rcsid_build(struct fchs_s
*fchs
, void *pyld
, u32 s_id
,
242 u32 port_id
, u32 cos
);
244 u16
fc_rptid_build(struct fchs_s
*fchs
, void *pyld
, u32 s_id
,
245 u32 port_id
, u8 port_type
);
247 u16
fc_ganxt_build(struct fchs_s
*fchs
, void *pyld
, u32 s_id
,
250 u16
fc_logo_build(struct fchs_s
*fchs
, struct fc_logo_s
*logo
, u32 d_id
,
251 u32 s_id
, u16 ox_id
, wwn_t port_name
);
253 u16
fc_logo_acc_build(struct fchs_s
*fchs
, void *pld
, u32 d_id
,
254 u32 s_id
, __be16 ox_id
);
256 u16
fc_fdmi_reqhdr_build(struct fchs_s
*fchs
, void *pyld
, u32 s_id
,
258 u16
fc_gmal_req_build(struct fchs_s
*fchs
, void *pyld
, u32 s_id
, wwn_t wwn
);
259 u16
fc_gfn_req_build(struct fchs_s
*fchs
, void *pyld
, u32 s_id
, wwn_t wwn
);
261 void fc_get_fc4type_bitmask(u8 fc4_type
, u8
*bit_mask
);
263 void fc_els_req_build(struct fchs_s
*fchs
, u32 d_id
, u32 s_id
,
266 enum fc_parse_status
fc_els_rsp_parse(struct fchs_s
*fchs
, int len
);
268 enum fc_parse_status
fc_plogi_rsp_parse(struct fchs_s
*fchs
, int len
,
271 enum fc_parse_status
fc_prli_parse(struct fc_prli_s
*prli
);
273 enum fc_parse_status
fc_pdisc_parse(struct fchs_s
*fchs
, wwn_t node_name
,
276 u16
fc_ba_acc_build(struct fchs_s
*fchs
, struct fc_ba_acc_s
*ba_acc
, u32 d_id
,
277 u32 s_id
, __be16 ox_id
, u16 rx_id
);
279 int fc_logout_params_pages(struct fchs_s
*fc_frame
, u8 els_code
);
281 u16
fc_tprlo_acc_build(struct fchs_s
*fchs
, struct fc_tprlo_acc_s
*tprlo_acc
,
282 u32 d_id
, u32 s_id
, __be16 ox_id
, int num_pages
);
284 u16
fc_prlo_acc_build(struct fchs_s
*fchs
, struct fc_prlo_acc_s
*prlo_acc
,
285 u32 d_id
, u32 s_id
, __be16 ox_id
, int num_pages
);
287 u16
fc_logo_rsp_parse(struct fchs_s
*fchs
, int len
);
289 u16
fc_pdisc_build(struct fchs_s
*fchs
, u32 d_id
, u32 s_id
,
290 u16 ox_id
, wwn_t port_name
, wwn_t node_name
,
293 u16
fc_pdisc_rsp_parse(struct fchs_s
*fchs
, int len
, wwn_t port_name
);
295 u16
fc_prlo_build(struct fchs_s
*fchs
, u32 d_id
, u32 s_id
,
296 u16 ox_id
, int num_pages
);
298 u16
fc_prlo_rsp_parse(struct fchs_s
*fchs
, int len
);
300 u16
fc_tprlo_build(struct fchs_s
*fchs
, u32 d_id
, u32 s_id
,
301 u16 ox_id
, int num_pages
, enum fc_tprlo_type tprlo_type
,
304 u16
fc_tprlo_rsp_parse(struct fchs_s
*fchs
, int len
);
306 u16
fc_ba_rjt_build(struct fchs_s
*fchs
, u32 d_id
, u32 s_id
,
307 __be16 ox_id
, u32 reason_code
, u32 reason_expl
);
309 u16
fc_gnnid_build(struct fchs_s
*fchs
, void *pyld
, u32 s_id
, u16 ox_id
,
312 u16
fc_ct_rsp_parse(struct ct_hdr_s
*cthdr
);
314 u16
fc_rscn_build(struct fchs_s
*fchs
, struct fc_rscn_pl_s
*rscn
, u32 s_id
,