[SCSI] bfa: Brocade BFA FC SCSI driver
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / scsi / bfa / fcbuild.h
1 /*
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
35 #define fcif_sof_set(_ifhdr, _sof) (_ifhdr)->sof = FC_ ## _sof
36 #define fcif_eof_set(_ifhdr, _eof) (_ifhdr)->eof = FC_ ## _eof
37
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 */
49 static inline u32
50 fc_get_ctresp_pyld_len(u32 resp_len)
51 {
52 return (resp_len - sizeof(struct ct_hdr_s));
53 }
54
55 /*
56 * Convert bfa speed to rpsc speed value.
57 */
58 static inline enum bfa_pport_speed
59 fc_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
75 default:
76 return BFA_PPORT_SPEED_UNKNOWN;
77 }
78 }
79
80 /*
81 * Convert RPSC speed to bfa speed value.
82 */
83 static inline enum fc_rpsc_op_speed_s
84 fc_bfa_speed_to_rpsc_operspeed(enum bfa_pport_speed op_speed)
85 {
86 switch (op_speed) {
87
88 case BFA_PPORT_SPEED_1GBPS:
89 return RPSC_OP_SPEED_1G;
90
91 case BFA_PPORT_SPEED_2GBPS:
92 return RPSC_OP_SPEED_2G;
93
94 case BFA_PPORT_SPEED_4GBPS:
95 return RPSC_OP_SPEED_4G;
96
97 case BFA_PPORT_SPEED_8GBPS:
98 return RPSC_OP_SPEED_8G;
99
100 default:
101 return RPSC_OP_SPEED_NOT_EST;
102 }
103 }
104 enum 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
121 struct 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
128 void fcbuild_init(void);
129
130 u16 fc_flogi_build(struct fchs_s *fchs, struct fc_logi_s *flogi,
131 u32 s_id, u16 ox_id, wwn_t port_name,
132 wwn_t node_name, u16 pdu_size, u8 set_npiv,
133 u8 set_auth, u16 local_bb_credits);
134 u16 fc_fdisc_build(struct fchs_s *buf, struct fc_logi_s *flogi,
135 u32 s_id, u16 ox_id, wwn_t port_name,
136 wwn_t node_name, u16 pdu_size);
137 u16 fc_flogi_acc_build(struct fchs_s *fchs, struct fc_logi_s *flogi,
138 u32 s_id, u16 ox_id, wwn_t port_name,
139 wwn_t node_name, u16 pdu_size,
140 u16 local_bb_credits);
141 u16 fc_plogi_build(struct fchs_s *fchs, void *pld, u32 d_id,
142 u32 s_id, u16 ox_id, wwn_t port_name,
143 wwn_t node_name, u16 pdu_size);
144 enum fc_parse_status fc_plogi_parse(struct fchs_s *fchs);
145 u16 fc_abts_build(struct fchs_s *buf, u32 d_id, u32 s_id,
146 u16 ox_id);
147 enum fc_parse_status fc_abts_rsp_parse(struct fchs_s *buf, int len);
148 u16 fc_rrq_build(struct fchs_s *buf, struct fc_rrq_s *rrq, u32 d_id,
149 u32 s_id, u16 ox_id, u16 rrq_oxid);
150 enum fc_parse_status fc_rrq_rsp_parse(struct fchs_s *buf, int len);
151 u16 fc_rspnid_build(struct fchs_s *fchs, void *pld, u32 s_id,
152 u16 ox_id, u8 *name);
153 u16 fc_rftid_build(struct fchs_s *fchs, void *pld, u32 s_id,
154 u16 ox_id, enum bfa_port_role role);
155 u16 fc_rftid_build_sol(struct fchs_s *fchs, void *pyld, u32 s_id,
156 u16 ox_id, u8 *fc4_bitmap,
157 u32 bitmap_size);
158 u16 fc_rffid_build(struct fchs_s *fchs, void *pyld, u32 s_id,
159 u16 ox_id, u8 fc4_type, u8 fc4_ftrs);
160 u16 fc_gidpn_build(struct fchs_s *fchs, void *pyld, u32 s_id,
161 u16 ox_id, wwn_t port_name);
162 u16 fc_gpnid_build(struct fchs_s *fchs, void *pld, u32 s_id,
163 u16 ox_id, u32 port_id);
164 u16 fc_scr_build(struct fchs_s *fchs, struct fc_scr_s *scr,
165 u8 set_br_reg, u32 s_id, u16 ox_id);
166 u16 fc_plogi_acc_build(struct fchs_s *fchs, void *pld, u32 d_id,
167 u32 s_id, u16 ox_id,
168 wwn_t port_name, wwn_t node_name, u16 pdu_size);
169
170 u16 fc_adisc_build(struct fchs_s *fchs, struct fc_adisc_s *adisc,
171 u32 d_id, u32 s_id, u16 ox_id,
172 wwn_t port_name, wwn_t node_name);
173 enum fc_parse_status fc_adisc_parse(struct fchs_s *fchs, void *pld,
174 u32 host_dap,
175 wwn_t node_name, wwn_t port_name);
176 enum fc_parse_status fc_adisc_rsp_parse(struct fc_adisc_s *adisc, int len,
177 wwn_t port_name, wwn_t node_name);
178 u16 fc_adisc_acc_build(struct fchs_s *fchs, struct fc_adisc_s *adisc,
179 u32 d_id, u32 s_id, u16 ox_id,
180 wwn_t port_name, wwn_t node_name);
181 u16 fc_ls_rjt_build(struct fchs_s *fchs, struct fc_ls_rjt_s *ls_rjt,
182 u32 d_id, u32 s_id, u16 ox_id,
183 u8 reason_code, u8 reason_code_expl);
184 u16 fc_ls_acc_build(struct fchs_s *fchs, struct fc_els_cmd_s *els_cmd,
185 u32 d_id, u32 s_id, u16 ox_id);
186 u16 fc_prli_build(struct fchs_s *fchs, void *pld, u32 d_id,
187 u32 s_id, u16 ox_id);
188 enum fc_parse_status fc_prli_rsp_parse(struct fc_prli_s *prli, int len);
189
190 u16 fc_prli_acc_build(struct fchs_s *fchs, void *pld, u32 d_id,
191 u32 s_id, u16 ox_id,
192 enum bfa_port_role role);
193 u16 fc_rnid_build(struct fchs_s *fchs, struct fc_rnid_cmd_s *rnid,
194 u32 d_id, u32 s_id, u16 ox_id,
195 u32 data_format);
196 u16 fc_rnid_acc_build(struct fchs_s *fchs, struct fc_rnid_acc_s *rnid_acc,
197 u32 d_id, u32 s_id, u16 ox_id,
198 u32 data_format,
199 struct fc_rnid_common_id_data_s *common_id_data,
200 struct fc_rnid_general_topology_data_s *
201 gen_topo_data);
202 u16 fc_rpsc2_build(struct fchs_s *fchs, struct fc_rpsc2_cmd_s *rps2c,
203 u32 d_id, u32 s_id,
204 u32 *pid_list, u16 npids);
205 u16 fc_rpsc_build(struct fchs_s *fchs, struct fc_rpsc_cmd_s *rpsc,
206 u32 d_id, u32 s_id, u16 ox_id);
207 u16 fc_rpsc_acc_build(struct fchs_s *fchs, struct fc_rpsc_acc_s *rpsc_acc,
208 u32 d_id, u32 s_id, u16 ox_id,
209 struct fc_rpsc_speed_info_s *oper_speed);
210 u16 fc_gid_ft_build(struct fchs_s *fchs, void *pld, u32 s_id,
211 u8 fc4_type);
212 u16 fc_rpnid_build(struct fchs_s *fchs, void *pyld, u32 s_id,
213 u32 port_id, wwn_t port_name);
214 u16 fc_rnnid_build(struct fchs_s *fchs, void *pyld, u32 s_id,
215 u32 port_id, wwn_t node_name);
216 u16 fc_rcsid_build(struct fchs_s *fchs, void *pyld, u32 s_id,
217 u32 port_id, u32 cos);
218 u16 fc_rptid_build(struct fchs_s *fchs, void *pyld, u32 s_id,
219 u32 port_id, u8 port_type);
220 u16 fc_ganxt_build(struct fchs_s *fchs, void *pyld, u32 s_id,
221 u32 port_id);
222 u16 fc_logo_build(struct fchs_s *fchs, struct fc_logo_s *logo,
223 u32 d_id, u32 s_id, u16 ox_id,
224 wwn_t port_name);
225 u16 fc_logo_acc_build(struct fchs_s *fchs, void *pld, u32 d_id,
226 u32 s_id, u16 ox_id);
227 u16 fc_fdmi_reqhdr_build(struct fchs_s *fchs, void *pyld, u32 s_id,
228 u16 cmd_code);
229 u16 fc_gmal_req_build(struct fchs_s *fchs, void *pyld, u32 s_id,
230 wwn_t wwn);
231 u16 fc_gfn_req_build(struct fchs_s *fchs, void *pyld, u32 s_id,
232 wwn_t wwn);
233 void fc_get_fc4type_bitmask(u8 fc4_type, u8 *bit_mask);
234 void fc_els_req_build(struct fchs_s *fchs, u32 d_id, u32 s_id,
235 u16 ox_id);
236 enum fc_parse_status fc_els_rsp_parse(struct fchs_s *fchs, int len);
237 enum fc_parse_status fc_plogi_rsp_parse(struct fchs_s *fchs, int len,
238 wwn_t port_name);
239 enum fc_parse_status fc_prli_parse(struct fc_prli_s *prli);
240 enum fc_parse_status fc_pdisc_parse(struct fchs_s *fchs, wwn_t node_name,
241 wwn_t port_name);
242 u16 fc_ba_acc_build(struct fchs_s *fchs, struct fc_ba_acc_s *ba_acc,
243 u32 d_id, u32 s_id, u16 ox_id,
244 u16 rx_id);
245 int fc_logout_params_pages(struct fchs_s *fc_frame, u8 els_code);
246 u16 fc_tprlo_acc_build(struct fchs_s *fchs,
247 struct fc_tprlo_acc_s *tprlo_acc,
248 u32 d_id, u32 s_id, u16 ox_id,
249 int num_pages);
250 u16 fc_prlo_acc_build(struct fchs_s *fchs, struct fc_prlo_acc_s *prlo_acc,
251 u32 d_id, u32 s_id, u16 ox_id,
252 int num_pages);
253 u16 fc_logo_rsp_parse(struct fchs_s *fchs, int len);
254 u16 fc_pdisc_build(struct fchs_s *fchs, u32 d_id, u32 s_id,
255 u16 ox_id, wwn_t port_name, wwn_t node_name,
256 u16 pdu_size);
257 u16 fc_pdisc_rsp_parse(struct fchs_s *fchs, int len, wwn_t port_name);
258 u16 fc_prlo_build(struct fchs_s *fchs, u32 d_id, u32 s_id,
259 u16 ox_id, int num_pages);
260 u16 fc_prlo_rsp_parse(struct fchs_s *fchs, int len);
261 u16 fc_tprlo_build(struct fchs_s *fchs, u32 d_id, u32 s_id,
262 u16 ox_id, int num_pages,
263 enum fc_tprlo_type tprlo_type, u32 tpr_id);
264 u16 fc_tprlo_rsp_parse(struct fchs_s *fchs, int len);
265 u16 fc_ba_rjt_build(struct fchs_s *fchs, u32 d_id, u32 s_id,
266 u16 ox_id, u32 reason_code,
267 u32 reason_expl);
268 u16 fc_gnnid_build(struct fchs_s *fchs, void *pyld, u32 s_id,
269 u16 ox_id, u32 port_id);
270 u16 fc_ct_rsp_parse(struct ct_hdr_s *cthdr);
271 u16 fc_rscn_build(struct fchs_s *fchs, struct fc_rscn_pl_s *rscn,
272 u32 s_id, u16 ox_id);
273 #endif