blob: b109a8813401a6cb4ec0346d0c3f0aae25519b6e [file] [log] [blame]
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001/*
Anil Gurumurthy889d0d42015-11-26 03:54:45 -05002 * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
3 * Copyright (c) 2014- QLogic Corporation.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07004 * All rights reserved
Anil Gurumurthy889d0d42015-11-26 03:54:45 -05005 * www.qlogic.com
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07006 *
Anil Gurumurthy31e1d562015-11-26 03:54:46 -05007 * Linux driver for QLogic BR-series Fibre Channel Host Bus Adapter.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07008 *
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
12 *
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.
17 */
18/*
19 * fcbuild.h - FC link service frame building and parsing routines
20 */
21
22#ifndef __FCBUILD_H__
23#define __FCBUILD_H__
24
Maggie Zhangf16a1752010-12-09 19:12:32 -080025#include "bfad_drv.h"
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070026#include "bfa_fc.h"
27#include "bfa_defs_fcs.h"
28
29/*
30 * Utility Macros/functions
31 */
32
33#define wwn_is_equal(_wwn1, _wwn2) \
34 (memcmp(&(_wwn1), &(_wwn2), sizeof(wwn_t)) == 0)
35
36#define fc_roundup(_l, _s) (((_l) + ((_s) - 1)) & ~((_s) - 1))
37
38/*
39 * Given the fc response length, this routine will return
40 * the length of the actual payload bytes following the CT header.
41 *
42 * Assumes the input response length does not include the crc, eof, etc.
43 */
44static inline u32
45fc_get_ctresp_pyld_len(u32 resp_len)
46{
47 return resp_len - sizeof(struct ct_hdr_s);
48}
49
50/*
51 * Convert bfa speed to rpsc speed value.
52 */
53static inline enum bfa_port_speed
54fc_rpsc_operspeed_to_bfa_speed(enum fc_rpsc_op_speed speed)
55{
56 switch (speed) {
57
58 case RPSC_OP_SPEED_1G:
59 return BFA_PORT_SPEED_1GBPS;
60
61 case RPSC_OP_SPEED_2G:
62 return BFA_PORT_SPEED_2GBPS;
63
64 case RPSC_OP_SPEED_4G:
65 return BFA_PORT_SPEED_4GBPS;
66
67 case RPSC_OP_SPEED_8G:
68 return BFA_PORT_SPEED_8GBPS;
69
Krishna Gudipati8b070b42011-06-13 15:52:40 -070070 case RPSC_OP_SPEED_16G:
71 return BFA_PORT_SPEED_16GBPS;
72
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070073 case RPSC_OP_SPEED_10G:
74 return BFA_PORT_SPEED_10GBPS;
75
76 default:
77 return BFA_PORT_SPEED_UNKNOWN;
78 }
79}
80
81/*
82 * Convert RPSC speed to bfa speed value.
83 */
84static inline enum fc_rpsc_op_speed
85fc_bfa_speed_to_rpsc_operspeed(enum bfa_port_speed op_speed)
86{
87 switch (op_speed) {
88
89 case BFA_PORT_SPEED_1GBPS:
90 return RPSC_OP_SPEED_1G;
91
92 case BFA_PORT_SPEED_2GBPS:
93 return RPSC_OP_SPEED_2G;
94
95 case BFA_PORT_SPEED_4GBPS:
96 return RPSC_OP_SPEED_4G;
97
98 case BFA_PORT_SPEED_8GBPS:
99 return RPSC_OP_SPEED_8G;
100
Krishna Gudipati8b070b42011-06-13 15:52:40 -0700101 case BFA_PORT_SPEED_16GBPS:
102 return RPSC_OP_SPEED_16G;
103
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700104 case BFA_PORT_SPEED_10GBPS:
105 return RPSC_OP_SPEED_10G;
106
107 default:
108 return RPSC_OP_SPEED_NOT_EST;
109 }
110}
111
112enum fc_parse_status {
113 FC_PARSE_OK = 0,
114 FC_PARSE_FAILURE = 1,
115 FC_PARSE_BUSY = 2,
116 FC_PARSE_LEN_INVAL,
117 FC_PARSE_ACC_INVAL,
118 FC_PARSE_PWWN_NOT_EQUAL,
119 FC_PARSE_NWWN_NOT_EQUAL,
120 FC_PARSE_RXSZ_INVAL,
121 FC_PARSE_NOT_FCP,
122 FC_PARSE_OPAFLAG_INVAL,
123 FC_PARSE_RPAFLAG_INVAL,
124 FC_PARSE_OPA_INVAL,
125 FC_PARSE_RPA_INVAL,
126
127};
128
129struct fc_templates_s {
130 struct fchs_s fc_els_req;
131 struct fchs_s fc_bls_req;
132 struct fc_logi_s plogi;
133 struct fc_rrq_s rrq;
134};
135
136void fcbuild_init(void);
137
138u16 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);
142
143u16 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,
145 u16 pdu_size);
146
147u16 fc_flogi_acc_build(struct fchs_s *fchs, struct fc_logi_s *flogi,
Maggie50444a32010-11-29 18:26:32 -0800148 u32 s_id, __be16 ox_id,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700149 wwn_t port_name, wwn_t node_name,
150 u16 pdu_size,
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700151 u16 local_bb_credits, u8 bb_scn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700152
153u16 fc_plogi_build(struct fchs_s *fchs, void *pld, u32 d_id,
154 u32 s_id, u16 ox_id, wwn_t port_name,
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700155 wwn_t node_name, u16 pdu_size, u16 bb_cr);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700156
157enum fc_parse_status fc_plogi_parse(struct fchs_s *fchs);
158
159u16 fc_abts_build(struct fchs_s *buf, u32 d_id, u32 s_id,
160 u16 ox_id);
161
162enum fc_parse_status fc_abts_rsp_parse(struct fchs_s *buf, int len);
163
164u16 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);
166enum fc_parse_status fc_rrq_rsp_parse(struct fchs_s *buf, int len);
167
168u16 fc_rspnid_build(struct fchs_s *fchs, void *pld, u32 s_id,
169 u16 ox_id, u8 *name);
Krishna Gudipatice7242b2012-08-22 19:52:43 -0700170u16 fc_rsnn_nn_build(struct fchs_s *fchs, void *pld, u32 s_id,
171 wwn_t node_name, u8 *name);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700172
173u16 fc_rftid_build(struct fchs_s *fchs, void *pld, u32 s_id,
174 u16 ox_id, enum bfa_lport_role role);
175
176u16 fc_rftid_build_sol(struct fchs_s *fchs, void *pyld, u32 s_id,
177 u16 ox_id, u8 *fc4_bitmap,
178 u32 bitmap_size);
179
180u16 fc_rffid_build(struct fchs_s *fchs, void *pyld, u32 s_id,
181 u16 ox_id, u8 fc4_type, u8 fc4_ftrs);
182
183u16 fc_gidpn_build(struct fchs_s *fchs, void *pyld, u32 s_id,
184 u16 ox_id, wwn_t port_name);
185
186u16 fc_gpnid_build(struct fchs_s *fchs, void *pld, u32 s_id,
187 u16 ox_id, u32 port_id);
188
Krishna Gudipatid7be54c2011-06-24 20:24:52 -0700189u16 fc_gs_rjt_build(struct fchs_s *fchs, struct ct_hdr_s *cthdr,
190 u32 d_id, u32 s_id, u16 ox_id,
191 u8 reason_code, u8 reason_code_expl);
192
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700193u16 fc_scr_build(struct fchs_s *fchs, struct fc_scr_s *scr,
194 u8 set_br_reg, u32 s_id, u16 ox_id);
195
196u16 fc_plogi_acc_build(struct fchs_s *fchs, void *pld, u32 d_id,
197 u32 s_id, u16 ox_id,
198 wwn_t port_name, wwn_t node_name,
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700199 u16 pdu_size, u16 bb_cr);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700200
201u16 fc_adisc_build(struct fchs_s *fchs, struct fc_adisc_s *adisc,
Maggie50444a32010-11-29 18:26:32 -0800202 u32 d_id, u32 s_id, __be16 ox_id, wwn_t port_name,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700203 wwn_t node_name);
204
205enum fc_parse_status fc_adisc_parse(struct fchs_s *fchs, void *pld,
206 u32 host_dap, wwn_t node_name, wwn_t port_name);
207
208enum fc_parse_status fc_adisc_rsp_parse(struct fc_adisc_s *adisc, int len,
209 wwn_t port_name, wwn_t node_name);
210
211u16 fc_adisc_acc_build(struct fchs_s *fchs, struct fc_adisc_s *adisc,
Maggie50444a32010-11-29 18:26:32 -0800212 u32 d_id, u32 s_id, __be16 ox_id,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700213 wwn_t port_name, wwn_t node_name);
214u16 fc_ls_rjt_build(struct fchs_s *fchs, struct fc_ls_rjt_s *ls_rjt,
Maggie50444a32010-11-29 18:26:32 -0800215 u32 d_id, u32 s_id, __be16 ox_id,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700216 u8 reason_code, u8 reason_code_expl);
217u16 fc_ls_acc_build(struct fchs_s *fchs, struct fc_els_cmd_s *els_cmd,
Maggie50444a32010-11-29 18:26:32 -0800218 u32 d_id, u32 s_id, __be16 ox_id);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700219u16 fc_prli_build(struct fchs_s *fchs, void *pld, u32 d_id,
220 u32 s_id, u16 ox_id);
221
222enum fc_parse_status fc_prli_rsp_parse(struct fc_prli_s *prli, int len);
223
224u16 fc_prli_acc_build(struct fchs_s *fchs, void *pld, u32 d_id,
Maggie50444a32010-11-29 18:26:32 -0800225 u32 s_id, __be16 ox_id,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700226 enum bfa_lport_role role);
227
228u16 fc_rnid_build(struct fchs_s *fchs, struct fc_rnid_cmd_s *rnid,
229 u32 d_id, u32 s_id, u16 ox_id,
230 u32 data_format);
231
232u16 fc_rnid_acc_build(struct fchs_s *fchs,
233 struct fc_rnid_acc_s *rnid_acc, u32 d_id, u32 s_id,
Maggie50444a32010-11-29 18:26:32 -0800234 __be16 ox_id, u32 data_format,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700235 struct fc_rnid_common_id_data_s *common_id_data,
236 struct fc_rnid_general_topology_data_s *gen_topo_data);
237
238u16 fc_rpsc2_build(struct fchs_s *fchs, struct fc_rpsc2_cmd_s *rps2c,
239 u32 d_id, u32 s_id, u32 *pid_list, u16 npids);
240u16 fc_rpsc_build(struct fchs_s *fchs, struct fc_rpsc_cmd_s *rpsc,
241 u32 d_id, u32 s_id, u16 ox_id);
242u16 fc_rpsc_acc_build(struct fchs_s *fchs,
243 struct fc_rpsc_acc_s *rpsc_acc, u32 d_id, u32 s_id,
Maggie50444a32010-11-29 18:26:32 -0800244 __be16 ox_id, struct fc_rpsc_speed_info_s *oper_speed);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700245u16 fc_gid_ft_build(struct fchs_s *fchs, void *pld, u32 s_id,
246 u8 fc4_type);
247
248u16 fc_rpnid_build(struct fchs_s *fchs, void *pyld, u32 s_id,
249 u32 port_id, wwn_t port_name);
250
251u16 fc_rnnid_build(struct fchs_s *fchs, void *pyld, u32 s_id,
252 u32 port_id, wwn_t node_name);
253
254u16 fc_rcsid_build(struct fchs_s *fchs, void *pyld, u32 s_id,
255 u32 port_id, u32 cos);
256
257u16 fc_rptid_build(struct fchs_s *fchs, void *pyld, u32 s_id,
258 u32 port_id, u8 port_type);
259
260u16 fc_ganxt_build(struct fchs_s *fchs, void *pyld, u32 s_id,
261 u32 port_id);
262
263u16 fc_logo_build(struct fchs_s *fchs, struct fc_logo_s *logo, u32 d_id,
264 u32 s_id, u16 ox_id, wwn_t port_name);
265
266u16 fc_logo_acc_build(struct fchs_s *fchs, void *pld, u32 d_id,
Maggie50444a32010-11-29 18:26:32 -0800267 u32 s_id, __be16 ox_id);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700268
269u16 fc_fdmi_reqhdr_build(struct fchs_s *fchs, void *pyld, u32 s_id,
270 u16 cmd_code);
271u16 fc_gmal_req_build(struct fchs_s *fchs, void *pyld, u32 s_id, wwn_t wwn);
272u16 fc_gfn_req_build(struct fchs_s *fchs, void *pyld, u32 s_id, wwn_t wwn);
273
274void fc_get_fc4type_bitmask(u8 fc4_type, u8 *bit_mask);
275
276void fc_els_req_build(struct fchs_s *fchs, u32 d_id, u32 s_id,
Maggie50444a32010-11-29 18:26:32 -0800277 __be16 ox_id);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700278
279enum fc_parse_status fc_els_rsp_parse(struct fchs_s *fchs, int len);
280
281enum fc_parse_status fc_plogi_rsp_parse(struct fchs_s *fchs, int len,
282 wwn_t port_name);
283
284enum fc_parse_status fc_prli_parse(struct fc_prli_s *prli);
285
286enum fc_parse_status fc_pdisc_parse(struct fchs_s *fchs, wwn_t node_name,
287 wwn_t port_name);
288
289u16 fc_ba_acc_build(struct fchs_s *fchs, struct fc_ba_acc_s *ba_acc, u32 d_id,
Maggie50444a32010-11-29 18:26:32 -0800290 u32 s_id, __be16 ox_id, u16 rx_id);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700291
292int fc_logout_params_pages(struct fchs_s *fc_frame, u8 els_code);
293
294u16 fc_tprlo_acc_build(struct fchs_s *fchs, struct fc_tprlo_acc_s *tprlo_acc,
Maggie50444a32010-11-29 18:26:32 -0800295 u32 d_id, u32 s_id, __be16 ox_id, int num_pages);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700296
297u16 fc_prlo_acc_build(struct fchs_s *fchs, struct fc_prlo_acc_s *prlo_acc,
Maggie50444a32010-11-29 18:26:32 -0800298 u32 d_id, u32 s_id, __be16 ox_id, int num_pages);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700299
300u16 fc_logo_rsp_parse(struct fchs_s *fchs, int len);
301
302u16 fc_pdisc_build(struct fchs_s *fchs, u32 d_id, u32 s_id,
303 u16 ox_id, wwn_t port_name, wwn_t node_name,
304 u16 pdu_size);
305
306u16 fc_pdisc_rsp_parse(struct fchs_s *fchs, int len, wwn_t port_name);
307
308u16 fc_prlo_build(struct fchs_s *fchs, u32 d_id, u32 s_id,
309 u16 ox_id, int num_pages);
310
311u16 fc_prlo_rsp_parse(struct fchs_s *fchs, int len);
312
313u16 fc_tprlo_build(struct fchs_s *fchs, u32 d_id, u32 s_id,
314 u16 ox_id, int num_pages, enum fc_tprlo_type tprlo_type,
315 u32 tpr_id);
316
317u16 fc_tprlo_rsp_parse(struct fchs_s *fchs, int len);
318
319u16 fc_ba_rjt_build(struct fchs_s *fchs, u32 d_id, u32 s_id,
Maggie50444a32010-11-29 18:26:32 -0800320 __be16 ox_id, u32 reason_code, u32 reason_expl);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700321
322u16 fc_gnnid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
323 u32 port_id);
324
325u16 fc_ct_rsp_parse(struct ct_hdr_s *cthdr);
326
327u16 fc_rscn_build(struct fchs_s *fchs, struct fc_rscn_pl_s *rscn, u32 s_id,
328 u16 ox_id);
329#endif