2 * Copyright (c) 2005-2009 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
24 #include <bfa_os_inc.h>
25 #include <protocol/fc.h>
26 #include <protocol/fcp.h>
27 #include <protocol/ct.h>
28 #include <defs/bfa_defs_port.h>
29 #include <defs/bfa_defs_pport.h>
32 * Utility Macros/functions
35 #define fcif_sof_set(_ifhdr, _sof) ((_ifhdr)->sof = FC_ ## _sof)
36 #define fcif_eof_set(_ifhdr, _eof) ((_ifhdr)->eof = FC_ ## _eof)
38 #define wwn_is_equal(_wwn1, _wwn2) \
39 (memcmp(&(_wwn1), &(_wwn2), sizeof(wwn_t)) == 0)
41 #define fc_roundup(_l, _s) (((_l) + ((_s) - 1)) & ~((_s) - 1))
44 * Given the fc response length, this routine will return
45 * the length of the actual payload bytes following the CT header.
47 * Assumes the input response length does not include the crc, eof, etc.
50 fc_get_ctresp_pyld_len(u32 resp_len
)
52 return resp_len
- sizeof(struct ct_hdr_s
);
56 * Convert bfa speed to rpsc speed value.
58 static inline enum bfa_pport_speed
59 fc_rpsc_operspeed_to_bfa_speed(enum fc_rpsc_op_speed_s speed
)
63 case RPSC_OP_SPEED_1G
:
64 return BFA_PPORT_SPEED_1GBPS
;
66 case RPSC_OP_SPEED_2G
:
67 return BFA_PPORT_SPEED_2GBPS
;
69 case RPSC_OP_SPEED_4G
:
70 return BFA_PPORT_SPEED_4GBPS
;
72 case RPSC_OP_SPEED_8G
:
73 return BFA_PPORT_SPEED_8GBPS
;
75 case RPSC_OP_SPEED_10G
:
76 return BFA_PPORT_SPEED_10GBPS
;
79 return BFA_PPORT_SPEED_UNKNOWN
;
84 * Convert RPSC speed to bfa speed value.
86 static inline enum fc_rpsc_op_speed_s
87 fc_bfa_speed_to_rpsc_operspeed(enum bfa_pport_speed op_speed
)
91 case BFA_PPORT_SPEED_1GBPS
:
92 return RPSC_OP_SPEED_1G
;
94 case BFA_PPORT_SPEED_2GBPS
:
95 return RPSC_OP_SPEED_2G
;
97 case BFA_PPORT_SPEED_4GBPS
:
98 return RPSC_OP_SPEED_4G
;
100 case BFA_PPORT_SPEED_8GBPS
:
101 return RPSC_OP_SPEED_8G
;
103 case BFA_PPORT_SPEED_10GBPS
:
104 return RPSC_OP_SPEED_10G
;
107 return RPSC_OP_SPEED_NOT_EST
;
110 enum fc_parse_status
{
112 FC_PARSE_FAILURE
= 1,
116 FC_PARSE_PWWN_NOT_EQUAL
,
117 FC_PARSE_NWWN_NOT_EQUAL
,
120 FC_PARSE_OPAFLAG_INVAL
,
121 FC_PARSE_RPAFLAG_INVAL
,
127 struct fc_templates_s
{
128 struct fchs_s fc_els_req
;
129 struct fchs_s fc_bls_req
;
130 struct fc_logi_s plogi
;
134 void fcbuild_init(void);
136 u16
fc_flogi_build(struct fchs_s
*fchs
, struct fc_logi_s
*flogi
,
137 u32 s_id
, u16 ox_id
, wwn_t port_name
,
138 wwn_t node_name
, u16 pdu_size
, u8 set_npiv
,
139 u8 set_auth
, u16 local_bb_credits
);
140 u16
fc_fdisc_build(struct fchs_s
*buf
, struct fc_logi_s
*flogi
,
141 u32 s_id
, u16 ox_id
, wwn_t port_name
,
142 wwn_t node_name
, u16 pdu_size
);
143 u16
fc_flogi_acc_build(struct fchs_s
*fchs
, struct fc_logi_s
*flogi
,
144 u32 s_id
, u16 ox_id
, wwn_t port_name
,
145 wwn_t node_name
, u16 pdu_size
,
146 u16 local_bb_credits
);
147 u16
fc_plogi_build(struct fchs_s
*fchs
, void *pld
, u32 d_id
,
148 u32 s_id
, u16 ox_id
, wwn_t port_name
,
149 wwn_t node_name
, u16 pdu_size
);
150 enum fc_parse_status
fc_plogi_parse(struct fchs_s
*fchs
);
151 u16
fc_abts_build(struct fchs_s
*buf
, u32 d_id
, u32 s_id
,
153 enum fc_parse_status
fc_abts_rsp_parse(struct fchs_s
*buf
, int len
);
154 u16
fc_rrq_build(struct fchs_s
*buf
, struct fc_rrq_s
*rrq
, u32 d_id
,
155 u32 s_id
, u16 ox_id
, u16 rrq_oxid
);
156 enum fc_parse_status
fc_rrq_rsp_parse(struct fchs_s
*buf
, int len
);
157 u16
fc_rspnid_build(struct fchs_s
*fchs
, void *pld
, u32 s_id
,
158 u16 ox_id
, u8
*name
);
159 u16
fc_rftid_build(struct fchs_s
*fchs
, void *pld
, u32 s_id
,
160 u16 ox_id
, enum bfa_port_role role
);
161 u16
fc_rftid_build_sol(struct fchs_s
*fchs
, void *pyld
, u32 s_id
,
162 u16 ox_id
, u8
*fc4_bitmap
,
164 u16
fc_rffid_build(struct fchs_s
*fchs
, void *pyld
, u32 s_id
,
165 u16 ox_id
, u8 fc4_type
, u8 fc4_ftrs
);
166 u16
fc_gidpn_build(struct fchs_s
*fchs
, void *pyld
, u32 s_id
,
167 u16 ox_id
, wwn_t port_name
);
168 u16
fc_gpnid_build(struct fchs_s
*fchs
, void *pld
, u32 s_id
,
169 u16 ox_id
, u32 port_id
);
170 u16
fc_scr_build(struct fchs_s
*fchs
, struct fc_scr_s
*scr
,
171 u8 set_br_reg
, u32 s_id
, u16 ox_id
);
172 u16
fc_plogi_acc_build(struct fchs_s
*fchs
, void *pld
, u32 d_id
,
174 wwn_t port_name
, wwn_t node_name
, u16 pdu_size
);
176 u16
fc_adisc_build(struct fchs_s
*fchs
, struct fc_adisc_s
*adisc
,
177 u32 d_id
, u32 s_id
, u16 ox_id
,
178 wwn_t port_name
, wwn_t node_name
);
179 enum fc_parse_status
fc_adisc_parse(struct fchs_s
*fchs
, void *pld
,
181 wwn_t node_name
, wwn_t port_name
);
182 enum fc_parse_status
fc_adisc_rsp_parse(struct fc_adisc_s
*adisc
, int len
,
183 wwn_t port_name
, wwn_t node_name
);
184 u16
fc_adisc_acc_build(struct fchs_s
*fchs
, struct fc_adisc_s
*adisc
,
185 u32 d_id
, u32 s_id
, u16 ox_id
,
186 wwn_t port_name
, wwn_t node_name
);
187 u16
fc_ls_rjt_build(struct fchs_s
*fchs
, struct fc_ls_rjt_s
*ls_rjt
,
188 u32 d_id
, u32 s_id
, u16 ox_id
,
189 u8 reason_code
, u8 reason_code_expl
);
190 u16
fc_ls_acc_build(struct fchs_s
*fchs
, struct fc_els_cmd_s
*els_cmd
,
191 u32 d_id
, u32 s_id
, u16 ox_id
);
192 u16
fc_prli_build(struct fchs_s
*fchs
, void *pld
, u32 d_id
,
193 u32 s_id
, u16 ox_id
);
194 enum fc_parse_status
fc_prli_rsp_parse(struct fc_prli_s
*prli
, int len
);
196 u16
fc_prli_acc_build(struct fchs_s
*fchs
, void *pld
, u32 d_id
,
198 enum bfa_port_role role
);
199 u16
fc_rnid_build(struct fchs_s
*fchs
, struct fc_rnid_cmd_s
*rnid
,
200 u32 d_id
, u32 s_id
, u16 ox_id
,
202 u16
fc_rnid_acc_build(struct fchs_s
*fchs
, struct fc_rnid_acc_s
*rnid_acc
,
203 u32 d_id
, u32 s_id
, u16 ox_id
,
205 struct fc_rnid_common_id_data_s
*common_id_data
,
206 struct fc_rnid_general_topology_data_s
*
208 u16
fc_rpsc2_build(struct fchs_s
*fchs
, struct fc_rpsc2_cmd_s
*rps2c
,
210 u32
*pid_list
, u16 npids
);
211 u16
fc_rpsc_build(struct fchs_s
*fchs
, struct fc_rpsc_cmd_s
*rpsc
,
212 u32 d_id
, u32 s_id
, u16 ox_id
);
213 u16
fc_rpsc_acc_build(struct fchs_s
*fchs
, struct fc_rpsc_acc_s
*rpsc_acc
,
214 u32 d_id
, u32 s_id
, u16 ox_id
,
215 struct fc_rpsc_speed_info_s
*oper_speed
);
216 u16
fc_gid_ft_build(struct fchs_s
*fchs
, void *pld
, u32 s_id
,
218 u16
fc_rpnid_build(struct fchs_s
*fchs
, void *pyld
, u32 s_id
,
219 u32 port_id
, wwn_t port_name
);
220 u16
fc_rnnid_build(struct fchs_s
*fchs
, void *pyld
, u32 s_id
,
221 u32 port_id
, wwn_t node_name
);
222 u16
fc_rcsid_build(struct fchs_s
*fchs
, void *pyld
, u32 s_id
,
223 u32 port_id
, u32 cos
);
224 u16
fc_rptid_build(struct fchs_s
*fchs
, void *pyld
, u32 s_id
,
225 u32 port_id
, u8 port_type
);
226 u16
fc_ganxt_build(struct fchs_s
*fchs
, void *pyld
, u32 s_id
,
228 u16
fc_logo_build(struct fchs_s
*fchs
, struct fc_logo_s
*logo
,
229 u32 d_id
, u32 s_id
, u16 ox_id
,
231 u16
fc_logo_acc_build(struct fchs_s
*fchs
, void *pld
, u32 d_id
,
232 u32 s_id
, u16 ox_id
);
233 u16
fc_fdmi_reqhdr_build(struct fchs_s
*fchs
, void *pyld
, u32 s_id
,
235 u16
fc_gmal_req_build(struct fchs_s
*fchs
, void *pyld
, u32 s_id
,
237 u16
fc_gfn_req_build(struct fchs_s
*fchs
, void *pyld
, u32 s_id
,
239 void fc_get_fc4type_bitmask(u8 fc4_type
, u8
*bit_mask
);
240 void fc_els_req_build(struct fchs_s
*fchs
, u32 d_id
, u32 s_id
,
242 enum fc_parse_status
fc_els_rsp_parse(struct fchs_s
*fchs
, int len
);
243 enum fc_parse_status
fc_plogi_rsp_parse(struct fchs_s
*fchs
, int len
,
245 enum fc_parse_status
fc_prli_parse(struct fc_prli_s
*prli
);
246 enum fc_parse_status
fc_pdisc_parse(struct fchs_s
*fchs
, wwn_t node_name
,
248 u16
fc_ba_acc_build(struct fchs_s
*fchs
, struct fc_ba_acc_s
*ba_acc
,
249 u32 d_id
, u32 s_id
, u16 ox_id
,
251 int fc_logout_params_pages(struct fchs_s
*fc_frame
, u8 els_code
);
252 u16
fc_tprlo_acc_build(struct fchs_s
*fchs
,
253 struct fc_tprlo_acc_s
*tprlo_acc
,
254 u32 d_id
, u32 s_id
, u16 ox_id
,
256 u16
fc_prlo_acc_build(struct fchs_s
*fchs
, struct fc_prlo_acc_s
*prlo_acc
,
257 u32 d_id
, u32 s_id
, u16 ox_id
,
259 u16
fc_logo_rsp_parse(struct fchs_s
*fchs
, int len
);
260 u16
fc_pdisc_build(struct fchs_s
*fchs
, u32 d_id
, u32 s_id
,
261 u16 ox_id
, wwn_t port_name
, wwn_t node_name
,
263 u16
fc_pdisc_rsp_parse(struct fchs_s
*fchs
, int len
, wwn_t port_name
);
264 u16
fc_prlo_build(struct fchs_s
*fchs
, u32 d_id
, u32 s_id
,
265 u16 ox_id
, int num_pages
);
266 u16
fc_prlo_rsp_parse(struct fchs_s
*fchs
, int len
);
267 u16
fc_tprlo_build(struct fchs_s
*fchs
, u32 d_id
, u32 s_id
,
268 u16 ox_id
, int num_pages
,
269 enum fc_tprlo_type tprlo_type
, u32 tpr_id
);
270 u16
fc_tprlo_rsp_parse(struct fchs_s
*fchs
, int len
);
271 u16
fc_ba_rjt_build(struct fchs_s
*fchs
, u32 d_id
, u32 s_id
,
272 u16 ox_id
, u32 reason_code
,
274 u16
fc_gnnid_build(struct fchs_s
*fchs
, void *pyld
, u32 s_id
,
275 u16 ox_id
, u32 port_id
);
276 u16
fc_ct_rsp_parse(struct ct_hdr_s
*cthdr
);
277 u16
fc_rscn_build(struct fchs_s
*fchs
, struct fc_rscn_pl_s
*rscn
,
278 u32 s_id
, u16 ox_id
);