blob: 981d98d542b90ece26acd3dcf5a634f4bedc699a [file] [log] [blame]
Jing Huang7725ccf2009-09-23 17:46:15 -07001/*
2 * Copyright (c) 2005-2009 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
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>
30
31/*
32 * Utility Macros/functions
33 */
34
Jing Huangf8ceafd2009-09-25 12:29:54 -070035#define fcif_sof_set(_ifhdr, _sof) ((_ifhdr)->sof = FC_ ## _sof)
36#define fcif_eof_set(_ifhdr, _eof) ((_ifhdr)->eof = FC_ ## _eof)
Jing Huang7725ccf2009-09-23 17:46:15 -070037
38#define wwn_is_equal(_wwn1, _wwn2) \
39 (memcmp(&(_wwn1), &(_wwn2), sizeof(wwn_t)) == 0)
40
41#define fc_roundup(_l, _s) (((_l) + ((_s) - 1)) & ~((_s) - 1))
42
43/*
44 * Given the fc response length, this routine will return
45 * the length of the actual payload bytes following the CT header.
46 *
47 * Assumes the input response length does not include the crc, eof, etc.
48 */
49static inline u32
50fc_get_ctresp_pyld_len(u32 resp_len)
51{
Jing Huangf8ceafd2009-09-25 12:29:54 -070052 return resp_len - sizeof(struct ct_hdr_s);
Jing Huang7725ccf2009-09-23 17:46:15 -070053}
54
55/*
56 * Convert bfa speed to rpsc speed value.
57 */
58static inline enum bfa_pport_speed
59fc_rpsc_operspeed_to_bfa_speed(enum fc_rpsc_op_speed_s speed)
60{
61 switch (speed) {
62
63 case RPSC_OP_SPEED_1G:
64 return BFA_PPORT_SPEED_1GBPS;
65
66 case RPSC_OP_SPEED_2G:
67 return BFA_PPORT_SPEED_2GBPS;
68
69 case RPSC_OP_SPEED_4G:
70 return BFA_PPORT_SPEED_4GBPS;
71
72 case RPSC_OP_SPEED_8G:
73 return BFA_PPORT_SPEED_8GBPS;
74
Krishna Gudipati25e29342010-03-05 19:38:17 -080075 case RPSC_OP_SPEED_10G:
76 return BFA_PPORT_SPEED_10GBPS;
77
Jing Huang7725ccf2009-09-23 17:46:15 -070078 default:
79 return BFA_PPORT_SPEED_UNKNOWN;
80 }
81}
82
83/*
84 * Convert RPSC speed to bfa speed value.
85 */
86static inline enum fc_rpsc_op_speed_s
87fc_bfa_speed_to_rpsc_operspeed(enum bfa_pport_speed op_speed)
88{
89 switch (op_speed) {
90
91 case BFA_PPORT_SPEED_1GBPS:
92 return RPSC_OP_SPEED_1G;
93
94 case BFA_PPORT_SPEED_2GBPS:
95 return RPSC_OP_SPEED_2G;
96
97 case BFA_PPORT_SPEED_4GBPS:
98 return RPSC_OP_SPEED_4G;
99
100 case BFA_PPORT_SPEED_8GBPS:
101 return RPSC_OP_SPEED_8G;
102
Krishna Gudipati25e29342010-03-05 19:38:17 -0800103 case BFA_PPORT_SPEED_10GBPS:
104 return RPSC_OP_SPEED_10G;
105
Jing Huang7725ccf2009-09-23 17:46:15 -0700106 default:
107 return RPSC_OP_SPEED_NOT_EST;
108 }
109}
110enum fc_parse_status {
111 FC_PARSE_OK = 0,
112 FC_PARSE_FAILURE = 1,
113 FC_PARSE_BUSY = 2,
114 FC_PARSE_LEN_INVAL,
115 FC_PARSE_ACC_INVAL,
116 FC_PARSE_PWWN_NOT_EQUAL,
117 FC_PARSE_NWWN_NOT_EQUAL,
118 FC_PARSE_RXSZ_INVAL,
119 FC_PARSE_NOT_FCP,
120 FC_PARSE_OPAFLAG_INVAL,
121 FC_PARSE_RPAFLAG_INVAL,
122 FC_PARSE_OPA_INVAL,
123 FC_PARSE_RPA_INVAL,
124
125};
126
127struct fc_templates_s {
128 struct fchs_s fc_els_req;
129 struct fchs_s fc_bls_req;
130 struct fc_logi_s plogi;
131 struct fc_rrq_s rrq;
132};
133
134void fcbuild_init(void);
135
136u16 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);
140u16 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);
143u16 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);
147u16 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);
150enum fc_parse_status fc_plogi_parse(struct fchs_s *fchs);
151u16 fc_abts_build(struct fchs_s *buf, u32 d_id, u32 s_id,
152 u16 ox_id);
153enum fc_parse_status fc_abts_rsp_parse(struct fchs_s *buf, int len);
154u16 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);
156enum fc_parse_status fc_rrq_rsp_parse(struct fchs_s *buf, int len);
157u16 fc_rspnid_build(struct fchs_s *fchs, void *pld, u32 s_id,
158 u16 ox_id, u8 *name);
159u16 fc_rftid_build(struct fchs_s *fchs, void *pld, u32 s_id,
160 u16 ox_id, enum bfa_port_role role);
161u16 fc_rftid_build_sol(struct fchs_s *fchs, void *pyld, u32 s_id,
162 u16 ox_id, u8 *fc4_bitmap,
163 u32 bitmap_size);
164u16 fc_rffid_build(struct fchs_s *fchs, void *pyld, u32 s_id,
165 u16 ox_id, u8 fc4_type, u8 fc4_ftrs);
166u16 fc_gidpn_build(struct fchs_s *fchs, void *pyld, u32 s_id,
167 u16 ox_id, wwn_t port_name);
168u16 fc_gpnid_build(struct fchs_s *fchs, void *pld, u32 s_id,
169 u16 ox_id, u32 port_id);
170u16 fc_scr_build(struct fchs_s *fchs, struct fc_scr_s *scr,
171 u8 set_br_reg, u32 s_id, u16 ox_id);
172u16 fc_plogi_acc_build(struct fchs_s *fchs, void *pld, u32 d_id,
173 u32 s_id, u16 ox_id,
174 wwn_t port_name, wwn_t node_name, u16 pdu_size);
175
176u16 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);
179enum fc_parse_status fc_adisc_parse(struct fchs_s *fchs, void *pld,
180 u32 host_dap,
181 wwn_t node_name, wwn_t port_name);
182enum fc_parse_status fc_adisc_rsp_parse(struct fc_adisc_s *adisc, int len,
183 wwn_t port_name, wwn_t node_name);
184u16 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);
187u16 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);
190u16 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);
192u16 fc_prli_build(struct fchs_s *fchs, void *pld, u32 d_id,
193 u32 s_id, u16 ox_id);
194enum fc_parse_status fc_prli_rsp_parse(struct fc_prli_s *prli, int len);
195
196u16 fc_prli_acc_build(struct fchs_s *fchs, void *pld, u32 d_id,
197 u32 s_id, u16 ox_id,
198 enum bfa_port_role role);
199u16 fc_rnid_build(struct fchs_s *fchs, struct fc_rnid_cmd_s *rnid,
200 u32 d_id, u32 s_id, u16 ox_id,
201 u32 data_format);
202u16 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,
204 u32 data_format,
205 struct fc_rnid_common_id_data_s *common_id_data,
206 struct fc_rnid_general_topology_data_s *
207 gen_topo_data);
208u16 fc_rpsc2_build(struct fchs_s *fchs, struct fc_rpsc2_cmd_s *rps2c,
209 u32 d_id, u32 s_id,
210 u32 *pid_list, u16 npids);
211u16 fc_rpsc_build(struct fchs_s *fchs, struct fc_rpsc_cmd_s *rpsc,
212 u32 d_id, u32 s_id, u16 ox_id);
213u16 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);
216u16 fc_gid_ft_build(struct fchs_s *fchs, void *pld, u32 s_id,
217 u8 fc4_type);
218u16 fc_rpnid_build(struct fchs_s *fchs, void *pyld, u32 s_id,
219 u32 port_id, wwn_t port_name);
220u16 fc_rnnid_build(struct fchs_s *fchs, void *pyld, u32 s_id,
221 u32 port_id, wwn_t node_name);
222u16 fc_rcsid_build(struct fchs_s *fchs, void *pyld, u32 s_id,
223 u32 port_id, u32 cos);
224u16 fc_rptid_build(struct fchs_s *fchs, void *pyld, u32 s_id,
225 u32 port_id, u8 port_type);
226u16 fc_ganxt_build(struct fchs_s *fchs, void *pyld, u32 s_id,
227 u32 port_id);
228u16 fc_logo_build(struct fchs_s *fchs, struct fc_logo_s *logo,
229 u32 d_id, u32 s_id, u16 ox_id,
230 wwn_t port_name);
231u16 fc_logo_acc_build(struct fchs_s *fchs, void *pld, u32 d_id,
232 u32 s_id, u16 ox_id);
233u16 fc_fdmi_reqhdr_build(struct fchs_s *fchs, void *pyld, u32 s_id,
234 u16 cmd_code);
235u16 fc_gmal_req_build(struct fchs_s *fchs, void *pyld, u32 s_id,
236 wwn_t wwn);
237u16 fc_gfn_req_build(struct fchs_s *fchs, void *pyld, u32 s_id,
238 wwn_t wwn);
239void fc_get_fc4type_bitmask(u8 fc4_type, u8 *bit_mask);
240void fc_els_req_build(struct fchs_s *fchs, u32 d_id, u32 s_id,
241 u16 ox_id);
242enum fc_parse_status fc_els_rsp_parse(struct fchs_s *fchs, int len);
243enum fc_parse_status fc_plogi_rsp_parse(struct fchs_s *fchs, int len,
244 wwn_t port_name);
245enum fc_parse_status fc_prli_parse(struct fc_prli_s *prli);
246enum fc_parse_status fc_pdisc_parse(struct fchs_s *fchs, wwn_t node_name,
247 wwn_t port_name);
248u16 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,
250 u16 rx_id);
251int fc_logout_params_pages(struct fchs_s *fc_frame, u8 els_code);
252u16 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,
255 int num_pages);
256u16 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,
258 int num_pages);
259u16 fc_logo_rsp_parse(struct fchs_s *fchs, int len);
260u16 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,
262 u16 pdu_size);
263u16 fc_pdisc_rsp_parse(struct fchs_s *fchs, int len, wwn_t port_name);
264u16 fc_prlo_build(struct fchs_s *fchs, u32 d_id, u32 s_id,
265 u16 ox_id, int num_pages);
266u16 fc_prlo_rsp_parse(struct fchs_s *fchs, int len);
267u16 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);
270u16 fc_tprlo_rsp_parse(struct fchs_s *fchs, int len);
271u16 fc_ba_rjt_build(struct fchs_s *fchs, u32 d_id, u32 s_id,
272 u16 ox_id, u32 reason_code,
273 u32 reason_expl);
274u16 fc_gnnid_build(struct fchs_s *fchs, void *pyld, u32 s_id,
275 u16 ox_id, u32 port_id);
276u16 fc_ct_rsp_parse(struct ct_hdr_s *cthdr);
277u16 fc_rscn_build(struct fchs_s *fchs, struct fc_rscn_pl_s *rscn,
278 u32 s_id, u16 ox_id);
279#endif