blob: 49e0ee4a733479b71f8faa5ee9b1def8f1d78a5b [file] [log] [blame]
Thomas Gleixner52fa7bf2019-05-29 07:18:06 -07001/* SPDX-License-Identifier: GPL-2.0-only */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002/*
Anil Gurumurthy889d0d42015-11-26 03:54:45 -05003 * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
4 * Copyright (c) 2014- QLogic Corporation.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07005 * All rights reserved
Anil Gurumurthy889d0d42015-11-26 03:54:45 -05006 * www.qlogic.com
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07007 *
Anil Gurumurthy31e1d562015-11-26 03:54:46 -05008 * Linux driver for QLogic BR-series Fibre Channel Host Bus Adapter.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07009 */
10/*
11 * fcbuild.h - FC link service frame building and parsing routines
12 */
13
14#ifndef __FCBUILD_H__
15#define __FCBUILD_H__
16
Maggie Zhangf16a1752010-12-09 19:12:32 -080017#include "bfad_drv.h"
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070018#include "bfa_fc.h"
19#include "bfa_defs_fcs.h"
20
21/*
22 * Utility Macros/functions
23 */
24
25#define wwn_is_equal(_wwn1, _wwn2) \
26 (memcmp(&(_wwn1), &(_wwn2), sizeof(wwn_t)) == 0)
27
28#define fc_roundup(_l, _s) (((_l) + ((_s) - 1)) & ~((_s) - 1))
29
30/*
31 * Given the fc response length, this routine will return
32 * the length of the actual payload bytes following the CT header.
33 *
34 * Assumes the input response length does not include the crc, eof, etc.
35 */
36static inline u32
37fc_get_ctresp_pyld_len(u32 resp_len)
38{
39 return resp_len - sizeof(struct ct_hdr_s);
40}
41
42/*
43 * Convert bfa speed to rpsc speed value.
44 */
45static inline enum bfa_port_speed
46fc_rpsc_operspeed_to_bfa_speed(enum fc_rpsc_op_speed speed)
47{
48 switch (speed) {
49
50 case RPSC_OP_SPEED_1G:
51 return BFA_PORT_SPEED_1GBPS;
52
53 case RPSC_OP_SPEED_2G:
54 return BFA_PORT_SPEED_2GBPS;
55
56 case RPSC_OP_SPEED_4G:
57 return BFA_PORT_SPEED_4GBPS;
58
59 case RPSC_OP_SPEED_8G:
60 return BFA_PORT_SPEED_8GBPS;
61
Krishna Gudipati8b070b42011-06-13 15:52:40 -070062 case RPSC_OP_SPEED_16G:
63 return BFA_PORT_SPEED_16GBPS;
64
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070065 case RPSC_OP_SPEED_10G:
66 return BFA_PORT_SPEED_10GBPS;
67
68 default:
69 return BFA_PORT_SPEED_UNKNOWN;
70 }
71}
72
73/*
74 * Convert RPSC speed to bfa speed value.
75 */
76static inline enum fc_rpsc_op_speed
77fc_bfa_speed_to_rpsc_operspeed(enum bfa_port_speed op_speed)
78{
79 switch (op_speed) {
80
81 case BFA_PORT_SPEED_1GBPS:
82 return RPSC_OP_SPEED_1G;
83
84 case BFA_PORT_SPEED_2GBPS:
85 return RPSC_OP_SPEED_2G;
86
87 case BFA_PORT_SPEED_4GBPS:
88 return RPSC_OP_SPEED_4G;
89
90 case BFA_PORT_SPEED_8GBPS:
91 return RPSC_OP_SPEED_8G;
92
Krishna Gudipati8b070b42011-06-13 15:52:40 -070093 case BFA_PORT_SPEED_16GBPS:
94 return RPSC_OP_SPEED_16G;
95
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070096 case BFA_PORT_SPEED_10GBPS:
97 return RPSC_OP_SPEED_10G;
98
99 default:
100 return RPSC_OP_SPEED_NOT_EST;
101 }
102}
103
104enum fc_parse_status {
105 FC_PARSE_OK = 0,
106 FC_PARSE_FAILURE = 1,
107 FC_PARSE_BUSY = 2,
108 FC_PARSE_LEN_INVAL,
109 FC_PARSE_ACC_INVAL,
110 FC_PARSE_PWWN_NOT_EQUAL,
111 FC_PARSE_NWWN_NOT_EQUAL,
112 FC_PARSE_RXSZ_INVAL,
113 FC_PARSE_NOT_FCP,
114 FC_PARSE_OPAFLAG_INVAL,
115 FC_PARSE_RPAFLAG_INVAL,
116 FC_PARSE_OPA_INVAL,
117 FC_PARSE_RPA_INVAL,
118
119};
120
121struct fc_templates_s {
122 struct fchs_s fc_els_req;
123 struct fchs_s fc_bls_req;
124 struct fc_logi_s plogi;
125 struct fc_rrq_s rrq;
126};
127
128void fcbuild_init(void);
129
130u16 fc_flogi_build(struct fchs_s *fchs, struct fc_logi_s *flogi,
131 u32 s_id, u16 ox_id, wwn_t port_name, wwn_t node_name,
132 u16 pdu_size, u8 set_npiv, u8 set_auth,
133 u16 local_bb_credits);
134
135u16 fc_fdisc_build(struct fchs_s *buf, struct fc_logi_s *flogi, u32 s_id,
136 u16 ox_id, wwn_t port_name, wwn_t node_name,
137 u16 pdu_size);
138
139u16 fc_flogi_acc_build(struct fchs_s *fchs, struct fc_logi_s *flogi,
Maggie50444a32010-11-29 18:26:32 -0800140 u32 s_id, __be16 ox_id,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700141 wwn_t port_name, wwn_t node_name,
142 u16 pdu_size,
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700143 u16 local_bb_credits, u8 bb_scn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700144
145u16 fc_plogi_build(struct fchs_s *fchs, void *pld, u32 d_id,
146 u32 s_id, u16 ox_id, wwn_t port_name,
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700147 wwn_t node_name, u16 pdu_size, u16 bb_cr);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700148
149enum fc_parse_status fc_plogi_parse(struct fchs_s *fchs);
150
151u16 fc_abts_build(struct fchs_s *buf, u32 d_id, u32 s_id,
152 u16 ox_id);
153
154enum fc_parse_status fc_abts_rsp_parse(struct fchs_s *buf, int len);
155
156u16 fc_rrq_build(struct fchs_s *buf, struct fc_rrq_s *rrq, u32 d_id,
157 u32 s_id, u16 ox_id, u16 rrq_oxid);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700158
159u16 fc_rspnid_build(struct fchs_s *fchs, void *pld, u32 s_id,
160 u16 ox_id, u8 *name);
Krishna Gudipatice7242b2012-08-22 19:52:43 -0700161u16 fc_rsnn_nn_build(struct fchs_s *fchs, void *pld, u32 s_id,
162 wwn_t node_name, u8 *name);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700163
164u16 fc_rftid_build(struct fchs_s *fchs, void *pld, u32 s_id,
165 u16 ox_id, enum bfa_lport_role role);
166
167u16 fc_rftid_build_sol(struct fchs_s *fchs, void *pyld, u32 s_id,
168 u16 ox_id, u8 *fc4_bitmap,
169 u32 bitmap_size);
170
171u16 fc_rffid_build(struct fchs_s *fchs, void *pyld, u32 s_id,
172 u16 ox_id, u8 fc4_type, u8 fc4_ftrs);
173
174u16 fc_gidpn_build(struct fchs_s *fchs, void *pyld, u32 s_id,
175 u16 ox_id, wwn_t port_name);
176
177u16 fc_gpnid_build(struct fchs_s *fchs, void *pld, u32 s_id,
178 u16 ox_id, u32 port_id);
179
Krishna Gudipatid7be54c2011-06-24 20:24:52 -0700180u16 fc_gs_rjt_build(struct fchs_s *fchs, struct ct_hdr_s *cthdr,
181 u32 d_id, u32 s_id, u16 ox_id,
182 u8 reason_code, u8 reason_code_expl);
183
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700184u16 fc_scr_build(struct fchs_s *fchs, struct fc_scr_s *scr,
185 u8 set_br_reg, u32 s_id, u16 ox_id);
186
187u16 fc_plogi_acc_build(struct fchs_s *fchs, void *pld, u32 d_id,
188 u32 s_id, u16 ox_id,
189 wwn_t port_name, wwn_t node_name,
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700190 u16 pdu_size, u16 bb_cr);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700191
192u16 fc_adisc_build(struct fchs_s *fchs, struct fc_adisc_s *adisc,
Maggie50444a32010-11-29 18:26:32 -0800193 u32 d_id, u32 s_id, __be16 ox_id, wwn_t port_name,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700194 wwn_t node_name);
195
196enum fc_parse_status fc_adisc_parse(struct fchs_s *fchs, void *pld,
197 u32 host_dap, wwn_t node_name, wwn_t port_name);
198
199enum fc_parse_status fc_adisc_rsp_parse(struct fc_adisc_s *adisc, int len,
200 wwn_t port_name, wwn_t node_name);
201
202u16 fc_adisc_acc_build(struct fchs_s *fchs, struct fc_adisc_s *adisc,
Maggie50444a32010-11-29 18:26:32 -0800203 u32 d_id, u32 s_id, __be16 ox_id,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700204 wwn_t port_name, wwn_t node_name);
205u16 fc_ls_rjt_build(struct fchs_s *fchs, struct fc_ls_rjt_s *ls_rjt,
Maggie50444a32010-11-29 18:26:32 -0800206 u32 d_id, u32 s_id, __be16 ox_id,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700207 u8 reason_code, u8 reason_code_expl);
208u16 fc_ls_acc_build(struct fchs_s *fchs, struct fc_els_cmd_s *els_cmd,
Maggie50444a32010-11-29 18:26:32 -0800209 u32 d_id, u32 s_id, __be16 ox_id);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700210u16 fc_prli_build(struct fchs_s *fchs, void *pld, u32 d_id,
211 u32 s_id, u16 ox_id);
212
213enum fc_parse_status fc_prli_rsp_parse(struct fc_prli_s *prli, int len);
214
215u16 fc_prli_acc_build(struct fchs_s *fchs, void *pld, u32 d_id,
Maggie50444a32010-11-29 18:26:32 -0800216 u32 s_id, __be16 ox_id,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700217 enum bfa_lport_role role);
218
219u16 fc_rnid_build(struct fchs_s *fchs, struct fc_rnid_cmd_s *rnid,
220 u32 d_id, u32 s_id, u16 ox_id,
221 u32 data_format);
222
223u16 fc_rnid_acc_build(struct fchs_s *fchs,
224 struct fc_rnid_acc_s *rnid_acc, u32 d_id, u32 s_id,
Maggie50444a32010-11-29 18:26:32 -0800225 __be16 ox_id, u32 data_format,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700226 struct fc_rnid_common_id_data_s *common_id_data,
227 struct fc_rnid_general_topology_data_s *gen_topo_data);
228
229u16 fc_rpsc2_build(struct fchs_s *fchs, struct fc_rpsc2_cmd_s *rps2c,
230 u32 d_id, u32 s_id, u32 *pid_list, u16 npids);
231u16 fc_rpsc_build(struct fchs_s *fchs, struct fc_rpsc_cmd_s *rpsc,
232 u32 d_id, u32 s_id, u16 ox_id);
233u16 fc_rpsc_acc_build(struct fchs_s *fchs,
234 struct fc_rpsc_acc_s *rpsc_acc, u32 d_id, u32 s_id,
Maggie50444a32010-11-29 18:26:32 -0800235 __be16 ox_id, struct fc_rpsc_speed_info_s *oper_speed);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700236u16 fc_gid_ft_build(struct fchs_s *fchs, void *pld, u32 s_id,
237 u8 fc4_type);
238
239u16 fc_rpnid_build(struct fchs_s *fchs, void *pyld, u32 s_id,
240 u32 port_id, wwn_t port_name);
241
242u16 fc_rnnid_build(struct fchs_s *fchs, void *pyld, u32 s_id,
243 u32 port_id, wwn_t node_name);
244
245u16 fc_rcsid_build(struct fchs_s *fchs, void *pyld, u32 s_id,
246 u32 port_id, u32 cos);
247
248u16 fc_rptid_build(struct fchs_s *fchs, void *pyld, u32 s_id,
249 u32 port_id, u8 port_type);
250
251u16 fc_ganxt_build(struct fchs_s *fchs, void *pyld, u32 s_id,
252 u32 port_id);
253
254u16 fc_logo_build(struct fchs_s *fchs, struct fc_logo_s *logo, u32 d_id,
255 u32 s_id, u16 ox_id, wwn_t port_name);
256
257u16 fc_logo_acc_build(struct fchs_s *fchs, void *pld, u32 d_id,
Maggie50444a32010-11-29 18:26:32 -0800258 u32 s_id, __be16 ox_id);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700259
260u16 fc_fdmi_reqhdr_build(struct fchs_s *fchs, void *pyld, u32 s_id,
261 u16 cmd_code);
262u16 fc_gmal_req_build(struct fchs_s *fchs, void *pyld, u32 s_id, wwn_t wwn);
263u16 fc_gfn_req_build(struct fchs_s *fchs, void *pyld, u32 s_id, wwn_t wwn);
264
265void fc_get_fc4type_bitmask(u8 fc4_type, u8 *bit_mask);
266
267void fc_els_req_build(struct fchs_s *fchs, u32 d_id, u32 s_id,
Maggie50444a32010-11-29 18:26:32 -0800268 __be16 ox_id);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700269
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700270enum fc_parse_status fc_plogi_rsp_parse(struct fchs_s *fchs, int len,
271 wwn_t port_name);
272
273enum fc_parse_status fc_prli_parse(struct fc_prli_s *prli);
274
275enum fc_parse_status fc_pdisc_parse(struct fchs_s *fchs, wwn_t node_name,
276 wwn_t port_name);
277
278u16 fc_ba_acc_build(struct fchs_s *fchs, struct fc_ba_acc_s *ba_acc, u32 d_id,
Maggie50444a32010-11-29 18:26:32 -0800279 u32 s_id, __be16 ox_id, u16 rx_id);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700280
281int fc_logout_params_pages(struct fchs_s *fc_frame, u8 els_code);
282
283u16 fc_tprlo_acc_build(struct fchs_s *fchs, struct fc_tprlo_acc_s *tprlo_acc,
Maggie50444a32010-11-29 18:26:32 -0800284 u32 d_id, u32 s_id, __be16 ox_id, int num_pages);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700285
286u16 fc_prlo_acc_build(struct fchs_s *fchs, struct fc_prlo_acc_s *prlo_acc,
Maggie50444a32010-11-29 18:26:32 -0800287 u32 d_id, u32 s_id, __be16 ox_id, int num_pages);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700288
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700289u16 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,
291 u16 pdu_size);
292
293u16 fc_pdisc_rsp_parse(struct fchs_s *fchs, int len, wwn_t port_name);
294
295u16 fc_prlo_build(struct fchs_s *fchs, u32 d_id, u32 s_id,
296 u16 ox_id, int num_pages);
297
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700298u16 fc_tprlo_build(struct fchs_s *fchs, u32 d_id, u32 s_id,
299 u16 ox_id, int num_pages, enum fc_tprlo_type tprlo_type,
300 u32 tpr_id);
301
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700302u16 fc_ba_rjt_build(struct fchs_s *fchs, u32 d_id, u32 s_id,
Maggie50444a32010-11-29 18:26:32 -0800303 __be16 ox_id, u32 reason_code, u32 reason_expl);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700304
305u16 fc_gnnid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
306 u32 port_id);
307
308u16 fc_ct_rsp_parse(struct ct_hdr_s *cthdr);
309
310u16 fc_rscn_build(struct fchs_s *fchs, struct fc_rscn_pl_s *rscn, u32 s_id,
311 u16 ox_id);
312#endif