blob: 03c753d1e548949573a785463f203c685e1936b4 [file] [log] [blame]
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001/*
2 * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
3 * All rights reserved
4 * www.brocade.com
5 *
6 * Linux driver for Brocade Fibre Channel Host Bus Adapter.
7 *
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
11 *
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.
16 */
17/*
18 * fcbuild.h - FC link service frame building and parsing routines
19 */
20
21#ifndef __FCBUILD_H__
22#define __FCBUILD_H__
23
Maggie Zhangf16a1752010-12-09 19:12:32 -080024#include "bfad_drv.h"
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070025#include "bfa_fc.h"
26#include "bfa_defs_fcs.h"
27
28/*
29 * Utility Macros/functions
30 */
31
32#define wwn_is_equal(_wwn1, _wwn2) \
33 (memcmp(&(_wwn1), &(_wwn2), sizeof(wwn_t)) == 0)
34
35#define fc_roundup(_l, _s) (((_l) + ((_s) - 1)) & ~((_s) - 1))
36
37/*
38 * Given the fc response length, this routine will return
39 * the length of the actual payload bytes following the CT header.
40 *
41 * Assumes the input response length does not include the crc, eof, etc.
42 */
43static inline u32
44fc_get_ctresp_pyld_len(u32 resp_len)
45{
46 return resp_len - sizeof(struct ct_hdr_s);
47}
48
49/*
50 * Convert bfa speed to rpsc speed value.
51 */
52static inline enum bfa_port_speed
53fc_rpsc_operspeed_to_bfa_speed(enum fc_rpsc_op_speed speed)
54{
55 switch (speed) {
56
57 case RPSC_OP_SPEED_1G:
58 return BFA_PORT_SPEED_1GBPS;
59
60 case RPSC_OP_SPEED_2G:
61 return BFA_PORT_SPEED_2GBPS;
62
63 case RPSC_OP_SPEED_4G:
64 return BFA_PORT_SPEED_4GBPS;
65
66 case RPSC_OP_SPEED_8G:
67 return BFA_PORT_SPEED_8GBPS;
68
Krishna Gudipati8b070b42011-06-13 15:52:40 -070069 case RPSC_OP_SPEED_16G:
70 return BFA_PORT_SPEED_16GBPS;
71
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070072 case RPSC_OP_SPEED_10G:
73 return BFA_PORT_SPEED_10GBPS;
74
75 default:
76 return BFA_PORT_SPEED_UNKNOWN;
77 }
78}
79
80/*
81 * Convert RPSC speed to bfa speed value.
82 */
83static inline enum fc_rpsc_op_speed
84fc_bfa_speed_to_rpsc_operspeed(enum bfa_port_speed op_speed)
85{
86 switch (op_speed) {
87
88 case BFA_PORT_SPEED_1GBPS:
89 return RPSC_OP_SPEED_1G;
90
91 case BFA_PORT_SPEED_2GBPS:
92 return RPSC_OP_SPEED_2G;
93
94 case BFA_PORT_SPEED_4GBPS:
95 return RPSC_OP_SPEED_4G;
96
97 case BFA_PORT_SPEED_8GBPS:
98 return RPSC_OP_SPEED_8G;
99
Krishna Gudipati8b070b42011-06-13 15:52:40 -0700100 case BFA_PORT_SPEED_16GBPS:
101 return RPSC_OP_SPEED_16G;
102
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700103 case BFA_PORT_SPEED_10GBPS:
104 return RPSC_OP_SPEED_10G;
105
106 default:
107 return RPSC_OP_SPEED_NOT_EST;
108 }
109}
110
111enum fc_parse_status {
112 FC_PARSE_OK = 0,
113 FC_PARSE_FAILURE = 1,
114 FC_PARSE_BUSY = 2,
115 FC_PARSE_LEN_INVAL,
116 FC_PARSE_ACC_INVAL,
117 FC_PARSE_PWWN_NOT_EQUAL,
118 FC_PARSE_NWWN_NOT_EQUAL,
119 FC_PARSE_RXSZ_INVAL,
120 FC_PARSE_NOT_FCP,
121 FC_PARSE_OPAFLAG_INVAL,
122 FC_PARSE_RPAFLAG_INVAL,
123 FC_PARSE_OPA_INVAL,
124 FC_PARSE_RPA_INVAL,
125
126};
127
128struct fc_templates_s {
129 struct fchs_s fc_els_req;
130 struct fchs_s fc_bls_req;
131 struct fc_logi_s plogi;
132 struct fc_rrq_s rrq;
133};
134
135void fcbuild_init(void);
136
137u16 fc_flogi_build(struct fchs_s *fchs, struct fc_logi_s *flogi,
138 u32 s_id, u16 ox_id, wwn_t port_name, wwn_t node_name,
139 u16 pdu_size, u8 set_npiv, u8 set_auth,
140 u16 local_bb_credits);
141
142u16 fc_fdisc_build(struct fchs_s *buf, struct fc_logi_s *flogi, u32 s_id,
143 u16 ox_id, wwn_t port_name, wwn_t node_name,
144 u16 pdu_size);
145
146u16 fc_flogi_acc_build(struct fchs_s *fchs, struct fc_logi_s *flogi,
Maggie50444a32010-11-29 18:26:32 -0800147 u32 s_id, __be16 ox_id,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700148 wwn_t port_name, wwn_t node_name,
149 u16 pdu_size,
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700150 u16 local_bb_credits, u8 bb_scn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700151
152u16 fc_plogi_build(struct fchs_s *fchs, void *pld, u32 d_id,
153 u32 s_id, u16 ox_id, wwn_t port_name,
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700154 wwn_t node_name, u16 pdu_size, u16 bb_cr);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700155
156enum fc_parse_status fc_plogi_parse(struct fchs_s *fchs);
157
158u16 fc_abts_build(struct fchs_s *buf, u32 d_id, u32 s_id,
159 u16 ox_id);
160
161enum fc_parse_status fc_abts_rsp_parse(struct fchs_s *buf, int len);
162
163u16 fc_rrq_build(struct fchs_s *buf, struct fc_rrq_s *rrq, u32 d_id,
164 u32 s_id, u16 ox_id, u16 rrq_oxid);
165enum fc_parse_status fc_rrq_rsp_parse(struct fchs_s *buf, int len);
166
167u16 fc_rspnid_build(struct fchs_s *fchs, void *pld, u32 s_id,
168 u16 ox_id, u8 *name);
Krishna Gudipatice7242b2012-08-22 19:52:43 -0700169u16 fc_rsnn_nn_build(struct fchs_s *fchs, void *pld, u32 s_id,
170 wwn_t node_name, u8 *name);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700171
172u16 fc_rftid_build(struct fchs_s *fchs, void *pld, u32 s_id,
173 u16 ox_id, enum bfa_lport_role role);
174
175u16 fc_rftid_build_sol(struct fchs_s *fchs, void *pyld, u32 s_id,
176 u16 ox_id, u8 *fc4_bitmap,
177 u32 bitmap_size);
178
179u16 fc_rffid_build(struct fchs_s *fchs, void *pyld, u32 s_id,
180 u16 ox_id, u8 fc4_type, u8 fc4_ftrs);
181
182u16 fc_gidpn_build(struct fchs_s *fchs, void *pyld, u32 s_id,
183 u16 ox_id, wwn_t port_name);
184
185u16 fc_gpnid_build(struct fchs_s *fchs, void *pld, u32 s_id,
186 u16 ox_id, u32 port_id);
187
Krishna Gudipatid7be54c2011-06-24 20:24:52 -0700188u16 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);
191
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700192u16 fc_scr_build(struct fchs_s *fchs, struct fc_scr_s *scr,
193 u8 set_br_reg, u32 s_id, u16 ox_id);
194
195u16 fc_plogi_acc_build(struct fchs_s *fchs, void *pld, u32 d_id,
196 u32 s_id, u16 ox_id,
197 wwn_t port_name, wwn_t node_name,
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700198 u16 pdu_size, u16 bb_cr);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700199
200u16 fc_adisc_build(struct fchs_s *fchs, struct fc_adisc_s *adisc,
Maggie50444a32010-11-29 18:26:32 -0800201 u32 d_id, u32 s_id, __be16 ox_id, wwn_t port_name,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700202 wwn_t node_name);
203
204enum fc_parse_status fc_adisc_parse(struct fchs_s *fchs, void *pld,
205 u32 host_dap, wwn_t node_name, wwn_t port_name);
206
207enum fc_parse_status fc_adisc_rsp_parse(struct fc_adisc_s *adisc, int len,
208 wwn_t port_name, wwn_t node_name);
209
210u16 fc_adisc_acc_build(struct fchs_s *fchs, struct fc_adisc_s *adisc,
Maggie50444a32010-11-29 18:26:32 -0800211 u32 d_id, u32 s_id, __be16 ox_id,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700212 wwn_t port_name, wwn_t node_name);
213u16 fc_ls_rjt_build(struct fchs_s *fchs, struct fc_ls_rjt_s *ls_rjt,
Maggie50444a32010-11-29 18:26:32 -0800214 u32 d_id, u32 s_id, __be16 ox_id,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700215 u8 reason_code, u8 reason_code_expl);
216u16 fc_ls_acc_build(struct fchs_s *fchs, struct fc_els_cmd_s *els_cmd,
Maggie50444a32010-11-29 18:26:32 -0800217 u32 d_id, u32 s_id, __be16 ox_id);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700218u16 fc_prli_build(struct fchs_s *fchs, void *pld, u32 d_id,
219 u32 s_id, u16 ox_id);
220
221enum fc_parse_status fc_prli_rsp_parse(struct fc_prli_s *prli, int len);
222
223u16 fc_prli_acc_build(struct fchs_s *fchs, void *pld, u32 d_id,
Maggie50444a32010-11-29 18:26:32 -0800224 u32 s_id, __be16 ox_id,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700225 enum bfa_lport_role role);
226
227u16 fc_rnid_build(struct fchs_s *fchs, struct fc_rnid_cmd_s *rnid,
228 u32 d_id, u32 s_id, u16 ox_id,
229 u32 data_format);
230
231u16 fc_rnid_acc_build(struct fchs_s *fchs,
232 struct fc_rnid_acc_s *rnid_acc, u32 d_id, u32 s_id,
Maggie50444a32010-11-29 18:26:32 -0800233 __be16 ox_id, u32 data_format,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700234 struct fc_rnid_common_id_data_s *common_id_data,
235 struct fc_rnid_general_topology_data_s *gen_topo_data);
236
237u16 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);
239u16 fc_rpsc_build(struct fchs_s *fchs, struct fc_rpsc_cmd_s *rpsc,
240 u32 d_id, u32 s_id, u16 ox_id);
241u16 fc_rpsc_acc_build(struct fchs_s *fchs,
242 struct fc_rpsc_acc_s *rpsc_acc, u32 d_id, u32 s_id,
Maggie50444a32010-11-29 18:26:32 -0800243 __be16 ox_id, struct fc_rpsc_speed_info_s *oper_speed);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700244u16 fc_gid_ft_build(struct fchs_s *fchs, void *pld, u32 s_id,
245 u8 fc4_type);
246
247u16 fc_rpnid_build(struct fchs_s *fchs, void *pyld, u32 s_id,
248 u32 port_id, wwn_t port_name);
249
250u16 fc_rnnid_build(struct fchs_s *fchs, void *pyld, u32 s_id,
251 u32 port_id, wwn_t node_name);
252
253u16 fc_rcsid_build(struct fchs_s *fchs, void *pyld, u32 s_id,
254 u32 port_id, u32 cos);
255
256u16 fc_rptid_build(struct fchs_s *fchs, void *pyld, u32 s_id,
257 u32 port_id, u8 port_type);
258
259u16 fc_ganxt_build(struct fchs_s *fchs, void *pyld, u32 s_id,
260 u32 port_id);
261
262u16 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);
264
265u16 fc_logo_acc_build(struct fchs_s *fchs, void *pld, u32 d_id,
Maggie50444a32010-11-29 18:26:32 -0800266 u32 s_id, __be16 ox_id);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700267
268u16 fc_fdmi_reqhdr_build(struct fchs_s *fchs, void *pyld, u32 s_id,
269 u16 cmd_code);
270u16 fc_gmal_req_build(struct fchs_s *fchs, void *pyld, u32 s_id, wwn_t wwn);
271u16 fc_gfn_req_build(struct fchs_s *fchs, void *pyld, u32 s_id, wwn_t wwn);
272
273void fc_get_fc4type_bitmask(u8 fc4_type, u8 *bit_mask);
274
275void fc_els_req_build(struct fchs_s *fchs, u32 d_id, u32 s_id,
Maggie50444a32010-11-29 18:26:32 -0800276 __be16 ox_id);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700277
278enum fc_parse_status fc_els_rsp_parse(struct fchs_s *fchs, int len);
279
280enum fc_parse_status fc_plogi_rsp_parse(struct fchs_s *fchs, int len,
281 wwn_t port_name);
282
283enum fc_parse_status fc_prli_parse(struct fc_prli_s *prli);
284
285enum fc_parse_status fc_pdisc_parse(struct fchs_s *fchs, wwn_t node_name,
286 wwn_t port_name);
287
288u16 fc_ba_acc_build(struct fchs_s *fchs, struct fc_ba_acc_s *ba_acc, u32 d_id,
Maggie50444a32010-11-29 18:26:32 -0800289 u32 s_id, __be16 ox_id, u16 rx_id);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700290
291int fc_logout_params_pages(struct fchs_s *fc_frame, u8 els_code);
292
293u16 fc_tprlo_acc_build(struct fchs_s *fchs, struct fc_tprlo_acc_s *tprlo_acc,
Maggie50444a32010-11-29 18:26:32 -0800294 u32 d_id, u32 s_id, __be16 ox_id, int num_pages);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700295
296u16 fc_prlo_acc_build(struct fchs_s *fchs, struct fc_prlo_acc_s *prlo_acc,
Maggie50444a32010-11-29 18:26:32 -0800297 u32 d_id, u32 s_id, __be16 ox_id, int num_pages);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700298
299u16 fc_logo_rsp_parse(struct fchs_s *fchs, int len);
300
301u16 fc_pdisc_build(struct fchs_s *fchs, u32 d_id, u32 s_id,
302 u16 ox_id, wwn_t port_name, wwn_t node_name,
303 u16 pdu_size);
304
305u16 fc_pdisc_rsp_parse(struct fchs_s *fchs, int len, wwn_t port_name);
306
307u16 fc_prlo_build(struct fchs_s *fchs, u32 d_id, u32 s_id,
308 u16 ox_id, int num_pages);
309
310u16 fc_prlo_rsp_parse(struct fchs_s *fchs, int len);
311
312u16 fc_tprlo_build(struct fchs_s *fchs, u32 d_id, u32 s_id,
313 u16 ox_id, int num_pages, enum fc_tprlo_type tprlo_type,
314 u32 tpr_id);
315
316u16 fc_tprlo_rsp_parse(struct fchs_s *fchs, int len);
317
318u16 fc_ba_rjt_build(struct fchs_s *fchs, u32 d_id, u32 s_id,
Maggie50444a32010-11-29 18:26:32 -0800319 __be16 ox_id, u32 reason_code, u32 reason_expl);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700320
321u16 fc_gnnid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
322 u32 port_id);
323
324u16 fc_ct_rsp_parse(struct ct_hdr_s *cthdr);
325
326u16 fc_rscn_build(struct fchs_s *fchs, struct fc_rscn_pl_s *rscn, u32 s_id,
327 u16 ox_id);
328#endif