blob: 6f670d3362affff58af6a2f505410850da9f9155 [file] [log] [blame]
Jing Huang7725ccf2009-09-23 17:46:15 -07001/*
Anil Gurumurthy889d0d42015-11-26 03:54:45 -05002 * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
3 * Copyright (c) 2014- QLogic Corporation.
Jing Huang7725ccf2009-09-23 17:46:15 -07004 * All rights reserved
Anil Gurumurthy889d0d42015-11-26 03:54:45 -05005 * www.qlogic.com
Jing Huang7725ccf2009-09-23 17:46:15 -07006 *
7 * Linux driver for Brocade Fibre Channel Host Bus Adapter.
8 *
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.c - FC link service frame building and parsing routines
20 */
21
Maggie Zhangf16a1752010-12-09 19:12:32 -080022#include "bfad_drv.h"
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070023#include "bfa_fcbuild.h"
Jing Huang7725ccf2009-09-23 17:46:15 -070024
25/*
26 * static build functions
27 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070028static void fc_els_rsp_build(struct fchs_s *fchs, u32 d_id, u32 s_id,
Maggie50444a32010-11-29 18:26:32 -080029 __be16 ox_id);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070030static void fc_bls_rsp_build(struct fchs_s *fchs, u32 d_id, u32 s_id,
Maggie50444a32010-11-29 18:26:32 -080031 __be16 ox_id);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070032static struct fchs_s fc_els_req_tmpl;
33static struct fchs_s fc_els_rsp_tmpl;
34static struct fchs_s fc_bls_req_tmpl;
35static struct fchs_s fc_bls_rsp_tmpl;
Jing Huang7725ccf2009-09-23 17:46:15 -070036static struct fc_ba_acc_s ba_acc_tmpl;
37static struct fc_logi_s plogi_tmpl;
38static struct fc_prli_s prli_tmpl;
39static struct fc_rrq_s rrq_tmpl;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070040static struct fchs_s fcp_fchs_tmpl;
Jing Huang7725ccf2009-09-23 17:46:15 -070041
42void
43fcbuild_init(void)
44{
45 /*
46 * fc_els_req_tmpl
47 */
48 fc_els_req_tmpl.routing = FC_RTG_EXT_LINK;
49 fc_els_req_tmpl.cat_info = FC_CAT_LD_REQUEST;
50 fc_els_req_tmpl.type = FC_TYPE_ELS;
51 fc_els_req_tmpl.f_ctl =
Maggie Zhangf16a1752010-12-09 19:12:32 -080052 bfa_hton3b(FCTL_SEQ_INI | FCTL_FS_EXCH | FCTL_END_SEQ |
Jing Huang7725ccf2009-09-23 17:46:15 -070053 FCTL_SI_XFER);
54 fc_els_req_tmpl.rx_id = FC_RXID_ANY;
55
56 /*
57 * fc_els_rsp_tmpl
58 */
59 fc_els_rsp_tmpl.routing = FC_RTG_EXT_LINK;
60 fc_els_rsp_tmpl.cat_info = FC_CAT_LD_REPLY;
61 fc_els_rsp_tmpl.type = FC_TYPE_ELS;
62 fc_els_rsp_tmpl.f_ctl =
Maggie Zhangf16a1752010-12-09 19:12:32 -080063 bfa_hton3b(FCTL_EC_RESP | FCTL_SEQ_INI | FCTL_LS_EXCH |
Jing Huang7725ccf2009-09-23 17:46:15 -070064 FCTL_END_SEQ | FCTL_SI_XFER);
65 fc_els_rsp_tmpl.rx_id = FC_RXID_ANY;
66
67 /*
68 * fc_bls_req_tmpl
69 */
70 fc_bls_req_tmpl.routing = FC_RTG_BASIC_LINK;
71 fc_bls_req_tmpl.type = FC_TYPE_BLS;
Maggie Zhangf16a1752010-12-09 19:12:32 -080072 fc_bls_req_tmpl.f_ctl = bfa_hton3b(FCTL_END_SEQ | FCTL_SI_XFER);
Jing Huang7725ccf2009-09-23 17:46:15 -070073 fc_bls_req_tmpl.rx_id = FC_RXID_ANY;
74
75 /*
76 * fc_bls_rsp_tmpl
77 */
78 fc_bls_rsp_tmpl.routing = FC_RTG_BASIC_LINK;
79 fc_bls_rsp_tmpl.cat_info = FC_CAT_BA_ACC;
80 fc_bls_rsp_tmpl.type = FC_TYPE_BLS;
81 fc_bls_rsp_tmpl.f_ctl =
Maggie Zhangf16a1752010-12-09 19:12:32 -080082 bfa_hton3b(FCTL_EC_RESP | FCTL_SEQ_INI | FCTL_LS_EXCH |
Jing Huang7725ccf2009-09-23 17:46:15 -070083 FCTL_END_SEQ | FCTL_SI_XFER);
84 fc_bls_rsp_tmpl.rx_id = FC_RXID_ANY;
85
86 /*
87 * ba_acc_tmpl
88 */
89 ba_acc_tmpl.seq_id_valid = 0;
90 ba_acc_tmpl.low_seq_cnt = 0;
91 ba_acc_tmpl.high_seq_cnt = 0xFFFF;
92
93 /*
94 * plogi_tmpl
95 */
96 plogi_tmpl.csp.verhi = FC_PH_VER_PH_3;
97 plogi_tmpl.csp.verlo = FC_PH_VER_4_3;
Jing Huang7725ccf2009-09-23 17:46:15 -070098 plogi_tmpl.csp.ciro = 0x1;
99 plogi_tmpl.csp.cisc = 0x0;
100 plogi_tmpl.csp.altbbcred = 0x0;
Jing Huangba816ea2010-10-18 17:10:50 -0700101 plogi_tmpl.csp.conseq = cpu_to_be16(0x00FF);
102 plogi_tmpl.csp.ro_bitmap = cpu_to_be16(0x0002);
103 plogi_tmpl.csp.e_d_tov = cpu_to_be32(2000);
Jing Huang7725ccf2009-09-23 17:46:15 -0700104
105 plogi_tmpl.class3.class_valid = 1;
106 plogi_tmpl.class3.sequential = 1;
107 plogi_tmpl.class3.conseq = 0xFF;
108 plogi_tmpl.class3.ospx = 1;
109
110 /*
111 * prli_tmpl
112 */
113 prli_tmpl.command = FC_ELS_PRLI;
114 prli_tmpl.pglen = 0x10;
Jing Huangba816ea2010-10-18 17:10:50 -0700115 prli_tmpl.pagebytes = cpu_to_be16(0x0014);
Jing Huang7725ccf2009-09-23 17:46:15 -0700116 prli_tmpl.parampage.type = FC_TYPE_FCP;
117 prli_tmpl.parampage.imagepair = 1;
118 prli_tmpl.parampage.servparams.rxrdisab = 1;
119
120 /*
121 * rrq_tmpl
122 */
123 rrq_tmpl.els_cmd.els_code = FC_ELS_RRQ;
124
125 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700126 * fcp_struct fchs_s mpl
Jing Huang7725ccf2009-09-23 17:46:15 -0700127 */
128 fcp_fchs_tmpl.routing = FC_RTG_FC4_DEV_DATA;
129 fcp_fchs_tmpl.cat_info = FC_CAT_UNSOLICIT_CMD;
130 fcp_fchs_tmpl.type = FC_TYPE_FCP;
131 fcp_fchs_tmpl.f_ctl =
Maggie Zhangf16a1752010-12-09 19:12:32 -0800132 bfa_hton3b(FCTL_FS_EXCH | FCTL_END_SEQ | FCTL_SI_XFER);
Jing Huang7725ccf2009-09-23 17:46:15 -0700133 fcp_fchs_tmpl.seq_id = 1;
134 fcp_fchs_tmpl.rx_id = FC_RXID_ANY;
135}
136
137static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700138fc_gs_fchdr_build(struct fchs_s *fchs, u32 d_id, u32 s_id, u32 ox_id)
Jing Huang7725ccf2009-09-23 17:46:15 -0700139{
Jing Huang6a18b162010-10-18 17:08:54 -0700140 memset(fchs, 0, sizeof(struct fchs_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700141
142 fchs->routing = FC_RTG_FC4_DEV_DATA;
143 fchs->cat_info = FC_CAT_UNSOLICIT_CTRL;
144 fchs->type = FC_TYPE_SERVICES;
145 fchs->f_ctl =
Maggie Zhangf16a1752010-12-09 19:12:32 -0800146 bfa_hton3b(FCTL_SEQ_INI | FCTL_FS_EXCH | FCTL_END_SEQ |
Jing Huang7725ccf2009-09-23 17:46:15 -0700147 FCTL_SI_XFER);
148 fchs->rx_id = FC_RXID_ANY;
149 fchs->d_id = (d_id);
150 fchs->s_id = (s_id);
Jing Huangba816ea2010-10-18 17:10:50 -0700151 fchs->ox_id = cpu_to_be16(ox_id);
Jing Huang7725ccf2009-09-23 17:46:15 -0700152
Jing Huang5fbe25c2010-10-18 17:17:23 -0700153 /*
Jing Huang7725ccf2009-09-23 17:46:15 -0700154 * @todo no need to set ox_id for request
155 * no need to set rx_id for response
156 */
157}
158
Krishna Gudipatid7be54c2011-06-24 20:24:52 -0700159static void
160fc_gsresp_fchdr_build(struct fchs_s *fchs, u32 d_id, u32 s_id, u16 ox_id)
161{
162 memset(fchs, 0, sizeof(struct fchs_s));
163
164 fchs->routing = FC_RTG_FC4_DEV_DATA;
165 fchs->cat_info = FC_CAT_SOLICIT_CTRL;
166 fchs->type = FC_TYPE_SERVICES;
167 fchs->f_ctl =
168 bfa_hton3b(FCTL_EC_RESP | FCTL_SEQ_INI | FCTL_LS_EXCH |
169 FCTL_END_SEQ | FCTL_SI_XFER);
170 fchs->d_id = d_id;
171 fchs->s_id = s_id;
172 fchs->ox_id = ox_id;
173}
174
Jing Huang7725ccf2009-09-23 17:46:15 -0700175void
Maggie50444a32010-11-29 18:26:32 -0800176fc_els_req_build(struct fchs_s *fchs, u32 d_id, u32 s_id, __be16 ox_id)
Jing Huang7725ccf2009-09-23 17:46:15 -0700177{
Jing Huang6a18b162010-10-18 17:08:54 -0700178 memcpy(fchs, &fc_els_req_tmpl, sizeof(struct fchs_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700179 fchs->d_id = (d_id);
180 fchs->s_id = (s_id);
Jing Huangba816ea2010-10-18 17:10:50 -0700181 fchs->ox_id = cpu_to_be16(ox_id);
Jing Huang7725ccf2009-09-23 17:46:15 -0700182}
183
184static void
Maggie50444a32010-11-29 18:26:32 -0800185fc_els_rsp_build(struct fchs_s *fchs, u32 d_id, u32 s_id, __be16 ox_id)
Jing Huang7725ccf2009-09-23 17:46:15 -0700186{
Jing Huang6a18b162010-10-18 17:08:54 -0700187 memcpy(fchs, &fc_els_rsp_tmpl, sizeof(struct fchs_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700188 fchs->d_id = d_id;
189 fchs->s_id = s_id;
190 fchs->ox_id = ox_id;
191}
192
193enum fc_parse_status
194fc_els_rsp_parse(struct fchs_s *fchs, int len)
195{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700196 struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
197 struct fc_ls_rjt_s *ls_rjt = (struct fc_ls_rjt_s *) els_cmd;
Jing Huang7725ccf2009-09-23 17:46:15 -0700198
199 len = len;
200
201 switch (els_cmd->els_code) {
202 case FC_ELS_LS_RJT:
203 if (ls_rjt->reason_code == FC_LS_RJT_RSN_LOGICAL_BUSY)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700204 return FC_PARSE_BUSY;
Jing Huang7725ccf2009-09-23 17:46:15 -0700205 else
Jing Huangf8ceafd2009-09-25 12:29:54 -0700206 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700207
208 case FC_ELS_ACC:
Jing Huangf8ceafd2009-09-25 12:29:54 -0700209 return FC_PARSE_OK;
Jing Huang7725ccf2009-09-23 17:46:15 -0700210 }
Jing Huangf8ceafd2009-09-25 12:29:54 -0700211 return FC_PARSE_OK;
Jing Huang7725ccf2009-09-23 17:46:15 -0700212}
213
214static void
Maggie50444a32010-11-29 18:26:32 -0800215fc_bls_rsp_build(struct fchs_s *fchs, u32 d_id, u32 s_id, __be16 ox_id)
Jing Huang7725ccf2009-09-23 17:46:15 -0700216{
Jing Huang6a18b162010-10-18 17:08:54 -0700217 memcpy(fchs, &fc_bls_rsp_tmpl, sizeof(struct fchs_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700218 fchs->d_id = d_id;
219 fchs->s_id = s_id;
220 fchs->ox_id = ox_id;
221}
222
223static u16
224fc_plogi_x_build(struct fchs_s *fchs, void *pld, u32 d_id, u32 s_id,
Maggie50444a32010-11-29 18:26:32 -0800225 __be16 ox_id, wwn_t port_name, wwn_t node_name,
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700226 u16 pdu_size, u16 bb_cr, u8 els_code)
Jing Huang7725ccf2009-09-23 17:46:15 -0700227{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700228 struct fc_logi_s *plogi = (struct fc_logi_s *) (pld);
Jing Huang7725ccf2009-09-23 17:46:15 -0700229
Jing Huang6a18b162010-10-18 17:08:54 -0700230 memcpy(plogi, &plogi_tmpl, sizeof(struct fc_logi_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700231
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -0700232 /* For FC AL bb_cr is 0 and altbbcred is 1 */
233 if (!bb_cr)
234 plogi->csp.altbbcred = 1;
235
Jing Huang7725ccf2009-09-23 17:46:15 -0700236 plogi->els_cmd.els_code = els_code;
237 if (els_code == FC_ELS_PLOGI)
238 fc_els_req_build(fchs, d_id, s_id, ox_id);
239 else
240 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
241
Jing Huangba816ea2010-10-18 17:10:50 -0700242 plogi->csp.rxsz = plogi->class3.rxsz = cpu_to_be16(pdu_size);
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700243 plogi->csp.bbcred = cpu_to_be16(bb_cr);
Jing Huang7725ccf2009-09-23 17:46:15 -0700244
Jing Huang6a18b162010-10-18 17:08:54 -0700245 memcpy(&plogi->port_name, &port_name, sizeof(wwn_t));
246 memcpy(&plogi->node_name, &node_name, sizeof(wwn_t));
Jing Huang7725ccf2009-09-23 17:46:15 -0700247
Jing Huangf8ceafd2009-09-25 12:29:54 -0700248 return sizeof(struct fc_logi_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700249}
250
251u16
252fc_flogi_build(struct fchs_s *fchs, struct fc_logi_s *flogi, u32 s_id,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700253 u16 ox_id, wwn_t port_name, wwn_t node_name, u16 pdu_size,
254 u8 set_npiv, u8 set_auth, u16 local_bb_credits)
Jing Huang7725ccf2009-09-23 17:46:15 -0700255{
Maggie Zhangf16a1752010-12-09 19:12:32 -0800256 u32 d_id = bfa_hton3b(FC_FABRIC_PORT);
Maggie50444a32010-11-29 18:26:32 -0800257 __be32 *vvl_info;
Jing Huang7725ccf2009-09-23 17:46:15 -0700258
Jing Huang6a18b162010-10-18 17:08:54 -0700259 memcpy(flogi, &plogi_tmpl, sizeof(struct fc_logi_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700260
261 flogi->els_cmd.els_code = FC_ELS_FLOGI;
262 fc_els_req_build(fchs, d_id, s_id, ox_id);
263
Jing Huangba816ea2010-10-18 17:10:50 -0700264 flogi->csp.rxsz = flogi->class3.rxsz = cpu_to_be16(pdu_size);
Jing Huang7725ccf2009-09-23 17:46:15 -0700265 flogi->port_name = port_name;
266 flogi->node_name = node_name;
267
268 /*
269 * Set the NPIV Capability Bit ( word 1, bit 31) of Common
270 * Service Parameters.
271 */
272 flogi->csp.ciro = set_npiv;
273
274 /* set AUTH capability */
275 flogi->csp.security = set_auth;
276
Jing Huangba816ea2010-10-18 17:10:50 -0700277 flogi->csp.bbcred = cpu_to_be16(local_bb_credits);
Jing Huang7725ccf2009-09-23 17:46:15 -0700278
279 /* Set brcd token in VVL */
280 vvl_info = (u32 *)&flogi->vvl[0];
281
282 /* set the flag to indicate the presence of VVL */
283 flogi->csp.npiv_supp = 1; /* @todo. field name is not correct */
Jing Huangba816ea2010-10-18 17:10:50 -0700284 vvl_info[0] = cpu_to_be32(FLOGI_VVL_BRCD);
Jing Huang7725ccf2009-09-23 17:46:15 -0700285
Jing Huangf8ceafd2009-09-25 12:29:54 -0700286 return sizeof(struct fc_logi_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700287}
288
289u16
290fc_flogi_acc_build(struct fchs_s *fchs, struct fc_logi_s *flogi, u32 s_id,
Maggie50444a32010-11-29 18:26:32 -0800291 __be16 ox_id, wwn_t port_name, wwn_t node_name,
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700292 u16 pdu_size, u16 local_bb_credits, u8 bb_scn)
Jing Huang7725ccf2009-09-23 17:46:15 -0700293{
294 u32 d_id = 0;
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700295 u16 bbscn_rxsz = (bb_scn << 12) | pdu_size;
Jing Huang7725ccf2009-09-23 17:46:15 -0700296
Jing Huang6a18b162010-10-18 17:08:54 -0700297 memcpy(flogi, &plogi_tmpl, sizeof(struct fc_logi_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700298 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
299
300 flogi->els_cmd.els_code = FC_ELS_ACC;
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700301 flogi->class3.rxsz = cpu_to_be16(pdu_size);
302 flogi->csp.rxsz = cpu_to_be16(bbscn_rxsz); /* bb_scn/rxsz */
Jing Huang7725ccf2009-09-23 17:46:15 -0700303 flogi->port_name = port_name;
304 flogi->node_name = node_name;
305
Jing Huangba816ea2010-10-18 17:10:50 -0700306 flogi->csp.bbcred = cpu_to_be16(local_bb_credits);
Jing Huang7725ccf2009-09-23 17:46:15 -0700307
Jing Huangf8ceafd2009-09-25 12:29:54 -0700308 return sizeof(struct fc_logi_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700309}
310
311u16
312fc_fdisc_build(struct fchs_s *fchs, struct fc_logi_s *flogi, u32 s_id,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700313 u16 ox_id, wwn_t port_name, wwn_t node_name, u16 pdu_size)
Jing Huang7725ccf2009-09-23 17:46:15 -0700314{
Maggie Zhangf16a1752010-12-09 19:12:32 -0800315 u32 d_id = bfa_hton3b(FC_FABRIC_PORT);
Jing Huang7725ccf2009-09-23 17:46:15 -0700316
Jing Huang6a18b162010-10-18 17:08:54 -0700317 memcpy(flogi, &plogi_tmpl, sizeof(struct fc_logi_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700318
319 flogi->els_cmd.els_code = FC_ELS_FDISC;
320 fc_els_req_build(fchs, d_id, s_id, ox_id);
321
Jing Huangba816ea2010-10-18 17:10:50 -0700322 flogi->csp.rxsz = flogi->class3.rxsz = cpu_to_be16(pdu_size);
Jing Huang7725ccf2009-09-23 17:46:15 -0700323 flogi->port_name = port_name;
324 flogi->node_name = node_name;
325
Jing Huangf8ceafd2009-09-25 12:29:54 -0700326 return sizeof(struct fc_logi_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700327}
328
329u16
330fc_plogi_build(struct fchs_s *fchs, void *pld, u32 d_id, u32 s_id,
331 u16 ox_id, wwn_t port_name, wwn_t node_name,
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700332 u16 pdu_size, u16 bb_cr)
Jing Huang7725ccf2009-09-23 17:46:15 -0700333{
334 return fc_plogi_x_build(fchs, pld, d_id, s_id, ox_id, port_name,
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700335 node_name, pdu_size, bb_cr, FC_ELS_PLOGI);
Jing Huang7725ccf2009-09-23 17:46:15 -0700336}
337
338u16
339fc_plogi_acc_build(struct fchs_s *fchs, void *pld, u32 d_id, u32 s_id,
340 u16 ox_id, wwn_t port_name, wwn_t node_name,
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700341 u16 pdu_size, u16 bb_cr)
Jing Huang7725ccf2009-09-23 17:46:15 -0700342{
343 return fc_plogi_x_build(fchs, pld, d_id, s_id, ox_id, port_name,
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700344 node_name, pdu_size, bb_cr, FC_ELS_ACC);
Jing Huang7725ccf2009-09-23 17:46:15 -0700345}
346
347enum fc_parse_status
348fc_plogi_rsp_parse(struct fchs_s *fchs, int len, wwn_t port_name)
349{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700350 struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
351 struct fc_logi_s *plogi;
352 struct fc_ls_rjt_s *ls_rjt;
Jing Huang7725ccf2009-09-23 17:46:15 -0700353
354 switch (els_cmd->els_code) {
355 case FC_ELS_LS_RJT:
356 ls_rjt = (struct fc_ls_rjt_s *) (fchs + 1);
357 if (ls_rjt->reason_code == FC_LS_RJT_RSN_LOGICAL_BUSY)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700358 return FC_PARSE_BUSY;
Jing Huang7725ccf2009-09-23 17:46:15 -0700359 else
Jing Huangf8ceafd2009-09-25 12:29:54 -0700360 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700361 case FC_ELS_ACC:
362 plogi = (struct fc_logi_s *) (fchs + 1);
363 if (len < sizeof(struct fc_logi_s))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700364 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700365
366 if (!wwn_is_equal(plogi->port_name, port_name))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700367 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700368
369 if (!plogi->class3.class_valid)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700370 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700371
Jing Huangba816ea2010-10-18 17:10:50 -0700372 if (be16_to_cpu(plogi->class3.rxsz) < (FC_MIN_PDUSZ))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700373 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700374
Jing Huangf8ceafd2009-09-25 12:29:54 -0700375 return FC_PARSE_OK;
Jing Huang7725ccf2009-09-23 17:46:15 -0700376 default:
Jing Huangf8ceafd2009-09-25 12:29:54 -0700377 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700378 }
379}
380
381enum fc_parse_status
382fc_plogi_parse(struct fchs_s *fchs)
383{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700384 struct fc_logi_s *plogi = (struct fc_logi_s *) (fchs + 1);
Jing Huang7725ccf2009-09-23 17:46:15 -0700385
386 if (plogi->class3.class_valid != 1)
387 return FC_PARSE_FAILURE;
388
Jing Huangba816ea2010-10-18 17:10:50 -0700389 if ((be16_to_cpu(plogi->class3.rxsz) < FC_MIN_PDUSZ)
390 || (be16_to_cpu(plogi->class3.rxsz) > FC_MAX_PDUSZ)
Jing Huang7725ccf2009-09-23 17:46:15 -0700391 || (plogi->class3.rxsz == 0))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700392 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700393
394 return FC_PARSE_OK;
395}
396
397u16
398fc_prli_build(struct fchs_s *fchs, void *pld, u32 d_id, u32 s_id,
399 u16 ox_id)
400{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700401 struct fc_prli_s *prli = (struct fc_prli_s *) (pld);
Jing Huang7725ccf2009-09-23 17:46:15 -0700402
403 fc_els_req_build(fchs, d_id, s_id, ox_id);
Jing Huang6a18b162010-10-18 17:08:54 -0700404 memcpy(prli, &prli_tmpl, sizeof(struct fc_prli_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700405
406 prli->command = FC_ELS_PRLI;
407 prli->parampage.servparams.initiator = 1;
408 prli->parampage.servparams.retry = 1;
409 prli->parampage.servparams.rec_support = 1;
410 prli->parampage.servparams.task_retry_id = 0;
411 prli->parampage.servparams.confirm = 1;
412
Jing Huangf8ceafd2009-09-25 12:29:54 -0700413 return sizeof(struct fc_prli_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700414}
415
416u16
417fc_prli_acc_build(struct fchs_s *fchs, void *pld, u32 d_id, u32 s_id,
Maggie50444a32010-11-29 18:26:32 -0800418 __be16 ox_id, enum bfa_lport_role role)
Jing Huang7725ccf2009-09-23 17:46:15 -0700419{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700420 struct fc_prli_s *prli = (struct fc_prli_s *) (pld);
Jing Huang7725ccf2009-09-23 17:46:15 -0700421
422 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
Jing Huang6a18b162010-10-18 17:08:54 -0700423 memcpy(prli, &prli_tmpl, sizeof(struct fc_prli_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700424
425 prli->command = FC_ELS_ACC;
426
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700427 prli->parampage.servparams.initiator = 1;
Jing Huang7725ccf2009-09-23 17:46:15 -0700428
429 prli->parampage.rspcode = FC_PRLI_ACC_XQTD;
430
Jing Huangf8ceafd2009-09-25 12:29:54 -0700431 return sizeof(struct fc_prli_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700432}
433
434enum fc_parse_status
435fc_prli_rsp_parse(struct fc_prli_s *prli, int len)
436{
437 if (len < sizeof(struct fc_prli_s))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700438 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700439
440 if (prli->command != FC_ELS_ACC)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700441 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700442
443 if ((prli->parampage.rspcode != FC_PRLI_ACC_XQTD)
444 && (prli->parampage.rspcode != FC_PRLI_ACC_PREDEF_IMG))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700445 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700446
447 if (prli->parampage.servparams.target != 1)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700448 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700449
Jing Huangf8ceafd2009-09-25 12:29:54 -0700450 return FC_PARSE_OK;
Jing Huang7725ccf2009-09-23 17:46:15 -0700451}
452
453enum fc_parse_status
454fc_prli_parse(struct fc_prli_s *prli)
455{
456 if (prli->parampage.type != FC_TYPE_FCP)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700457 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700458
459 if (!prli->parampage.imagepair)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700460 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700461
462 if (!prli->parampage.servparams.initiator)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700463 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700464
Jing Huangf8ceafd2009-09-25 12:29:54 -0700465 return FC_PARSE_OK;
Jing Huang7725ccf2009-09-23 17:46:15 -0700466}
467
468u16
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700469fc_logo_build(struct fchs_s *fchs, struct fc_logo_s *logo, u32 d_id, u32 s_id,
470 u16 ox_id, wwn_t port_name)
Jing Huang7725ccf2009-09-23 17:46:15 -0700471{
472 fc_els_req_build(fchs, d_id, s_id, ox_id);
473
Jing Huang6a18b162010-10-18 17:08:54 -0700474 memset(logo, '\0', sizeof(struct fc_logo_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700475 logo->els_cmd.els_code = FC_ELS_LOGO;
476 logo->nport_id = (s_id);
477 logo->orig_port_name = port_name;
478
Jing Huangf8ceafd2009-09-25 12:29:54 -0700479 return sizeof(struct fc_logo_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700480}
481
Maggie Zhangda99dcc2010-12-09 19:13:20 -0800482static u16
Jing Huang7725ccf2009-09-23 17:46:15 -0700483fc_adisc_x_build(struct fchs_s *fchs, struct fc_adisc_s *adisc, u32 d_id,
Maggie50444a32010-11-29 18:26:32 -0800484 u32 s_id, __be16 ox_id, wwn_t port_name,
Jing Huang7725ccf2009-09-23 17:46:15 -0700485 wwn_t node_name, u8 els_code)
486{
Jing Huang6a18b162010-10-18 17:08:54 -0700487 memset(adisc, '\0', sizeof(struct fc_adisc_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700488
489 adisc->els_cmd.els_code = els_code;
490
491 if (els_code == FC_ELS_ADISC)
492 fc_els_req_build(fchs, d_id, s_id, ox_id);
493 else
494 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
495
496 adisc->orig_HA = 0;
497 adisc->orig_port_name = port_name;
498 adisc->orig_node_name = node_name;
499 adisc->nport_id = (s_id);
500
Jing Huangf8ceafd2009-09-25 12:29:54 -0700501 return sizeof(struct fc_adisc_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700502}
503
504u16
505fc_adisc_build(struct fchs_s *fchs, struct fc_adisc_s *adisc, u32 d_id,
Maggie50444a32010-11-29 18:26:32 -0800506 u32 s_id, __be16 ox_id, wwn_t port_name, wwn_t node_name)
Jing Huang7725ccf2009-09-23 17:46:15 -0700507{
508 return fc_adisc_x_build(fchs, adisc, d_id, s_id, ox_id, port_name,
509 node_name, FC_ELS_ADISC);
510}
511
512u16
513fc_adisc_acc_build(struct fchs_s *fchs, struct fc_adisc_s *adisc, u32 d_id,
Maggie50444a32010-11-29 18:26:32 -0800514 u32 s_id, __be16 ox_id, wwn_t port_name,
Jing Huang7725ccf2009-09-23 17:46:15 -0700515 wwn_t node_name)
516{
517 return fc_adisc_x_build(fchs, adisc, d_id, s_id, ox_id, port_name,
518 node_name, FC_ELS_ACC);
519}
520
521enum fc_parse_status
522fc_adisc_rsp_parse(struct fc_adisc_s *adisc, int len, wwn_t port_name,
523 wwn_t node_name)
524{
525
526 if (len < sizeof(struct fc_adisc_s))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700527 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700528
529 if (adisc->els_cmd.els_code != FC_ELS_ACC)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700530 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700531
532 if (!wwn_is_equal(adisc->orig_port_name, port_name))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700533 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700534
Jing Huangf8ceafd2009-09-25 12:29:54 -0700535 return FC_PARSE_OK;
Jing Huang7725ccf2009-09-23 17:46:15 -0700536}
537
538enum fc_parse_status
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700539fc_adisc_parse(struct fchs_s *fchs, void *pld, u32 host_dap, wwn_t node_name,
540 wwn_t port_name)
Jing Huang7725ccf2009-09-23 17:46:15 -0700541{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700542 struct fc_adisc_s *adisc = (struct fc_adisc_s *) pld;
Jing Huang7725ccf2009-09-23 17:46:15 -0700543
544 if (adisc->els_cmd.els_code != FC_ELS_ACC)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700545 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700546
547 if ((adisc->nport_id == (host_dap))
548 && wwn_is_equal(adisc->orig_port_name, port_name)
549 && wwn_is_equal(adisc->orig_node_name, node_name))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700550 return FC_PARSE_OK;
Jing Huang7725ccf2009-09-23 17:46:15 -0700551
Jing Huangf8ceafd2009-09-25 12:29:54 -0700552 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700553}
554
555enum fc_parse_status
556fc_pdisc_parse(struct fchs_s *fchs, wwn_t node_name, wwn_t port_name)
557{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700558 struct fc_logi_s *pdisc = (struct fc_logi_s *) (fchs + 1);
Jing Huang7725ccf2009-09-23 17:46:15 -0700559
560 if (pdisc->class3.class_valid != 1)
561 return FC_PARSE_FAILURE;
562
Jing Huangba816ea2010-10-18 17:10:50 -0700563 if ((be16_to_cpu(pdisc->class3.rxsz) <
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700564 (FC_MIN_PDUSZ - sizeof(struct fchs_s)))
Jing Huang7725ccf2009-09-23 17:46:15 -0700565 || (pdisc->class3.rxsz == 0))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700566 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700567
568 if (!wwn_is_equal(pdisc->port_name, port_name))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700569 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700570
571 if (!wwn_is_equal(pdisc->node_name, node_name))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700572 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700573
574 return FC_PARSE_OK;
575}
576
577u16
578fc_abts_build(struct fchs_s *fchs, u32 d_id, u32 s_id, u16 ox_id)
579{
Jing Huang6a18b162010-10-18 17:08:54 -0700580 memcpy(fchs, &fc_bls_req_tmpl, sizeof(struct fchs_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700581 fchs->cat_info = FC_CAT_ABTS;
582 fchs->d_id = (d_id);
583 fchs->s_id = (s_id);
Jing Huangba816ea2010-10-18 17:10:50 -0700584 fchs->ox_id = cpu_to_be16(ox_id);
Jing Huang7725ccf2009-09-23 17:46:15 -0700585
Jing Huangf8ceafd2009-09-25 12:29:54 -0700586 return sizeof(struct fchs_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700587}
588
589enum fc_parse_status
590fc_abts_rsp_parse(struct fchs_s *fchs, int len)
591{
592 if ((fchs->cat_info == FC_CAT_BA_ACC)
593 || (fchs->cat_info == FC_CAT_BA_RJT))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700594 return FC_PARSE_OK;
Jing Huang7725ccf2009-09-23 17:46:15 -0700595
Jing Huangf8ceafd2009-09-25 12:29:54 -0700596 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700597}
598
599u16
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700600fc_rrq_build(struct fchs_s *fchs, struct fc_rrq_s *rrq, u32 d_id, u32 s_id,
601 u16 ox_id, u16 rrq_oxid)
Jing Huang7725ccf2009-09-23 17:46:15 -0700602{
603 fc_els_req_build(fchs, d_id, s_id, ox_id);
604
605 /*
606 * build rrq payload
607 */
Jing Huang6a18b162010-10-18 17:08:54 -0700608 memcpy(rrq, &rrq_tmpl, sizeof(struct fc_rrq_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700609 rrq->s_id = (s_id);
Jing Huangba816ea2010-10-18 17:10:50 -0700610 rrq->ox_id = cpu_to_be16(rrq_oxid);
Jing Huang7725ccf2009-09-23 17:46:15 -0700611 rrq->rx_id = FC_RXID_ANY;
612
Jing Huangf8ceafd2009-09-25 12:29:54 -0700613 return sizeof(struct fc_rrq_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700614}
615
616u16
617fc_logo_acc_build(struct fchs_s *fchs, void *pld, u32 d_id, u32 s_id,
Maggie50444a32010-11-29 18:26:32 -0800618 __be16 ox_id)
Jing Huang7725ccf2009-09-23 17:46:15 -0700619{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700620 struct fc_els_cmd_s *acc = pld;
Jing Huang7725ccf2009-09-23 17:46:15 -0700621
622 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
623
Jing Huang6a18b162010-10-18 17:08:54 -0700624 memset(acc, 0, sizeof(struct fc_els_cmd_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700625 acc->els_code = FC_ELS_ACC;
626
Jing Huangf8ceafd2009-09-25 12:29:54 -0700627 return sizeof(struct fc_els_cmd_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700628}
629
630u16
631fc_ls_rjt_build(struct fchs_s *fchs, struct fc_ls_rjt_s *ls_rjt, u32 d_id,
Maggie50444a32010-11-29 18:26:32 -0800632 u32 s_id, __be16 ox_id, u8 reason_code,
Jing Huang7725ccf2009-09-23 17:46:15 -0700633 u8 reason_code_expl)
634{
635 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
Jing Huang6a18b162010-10-18 17:08:54 -0700636 memset(ls_rjt, 0, sizeof(struct fc_ls_rjt_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700637
638 ls_rjt->els_cmd.els_code = FC_ELS_LS_RJT;
639 ls_rjt->reason_code = reason_code;
640 ls_rjt->reason_code_expl = reason_code_expl;
641 ls_rjt->vendor_unique = 0x00;
642
Jing Huangf8ceafd2009-09-25 12:29:54 -0700643 return sizeof(struct fc_ls_rjt_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700644}
645
646u16
647fc_ba_acc_build(struct fchs_s *fchs, struct fc_ba_acc_s *ba_acc, u32 d_id,
Maggie50444a32010-11-29 18:26:32 -0800648 u32 s_id, __be16 ox_id, u16 rx_id)
Jing Huang7725ccf2009-09-23 17:46:15 -0700649{
650 fc_bls_rsp_build(fchs, d_id, s_id, ox_id);
651
Jing Huang6a18b162010-10-18 17:08:54 -0700652 memcpy(ba_acc, &ba_acc_tmpl, sizeof(struct fc_ba_acc_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700653
654 fchs->rx_id = rx_id;
655
656 ba_acc->ox_id = fchs->ox_id;
657 ba_acc->rx_id = fchs->rx_id;
658
Jing Huangf8ceafd2009-09-25 12:29:54 -0700659 return sizeof(struct fc_ba_acc_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700660}
661
662u16
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700663fc_ls_acc_build(struct fchs_s *fchs, struct fc_els_cmd_s *els_cmd, u32 d_id,
Maggie50444a32010-11-29 18:26:32 -0800664 u32 s_id, __be16 ox_id)
Jing Huang7725ccf2009-09-23 17:46:15 -0700665{
666 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
Jing Huang6a18b162010-10-18 17:08:54 -0700667 memset(els_cmd, 0, sizeof(struct fc_els_cmd_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700668 els_cmd->els_code = FC_ELS_ACC;
669
Jing Huangf8ceafd2009-09-25 12:29:54 -0700670 return sizeof(struct fc_els_cmd_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700671}
672
673int
674fc_logout_params_pages(struct fchs_s *fc_frame, u8 els_code)
675{
676 int num_pages = 0;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700677 struct fc_prlo_s *prlo;
678 struct fc_tprlo_s *tprlo;
Jing Huang7725ccf2009-09-23 17:46:15 -0700679
680 if (els_code == FC_ELS_PRLO) {
681 prlo = (struct fc_prlo_s *) (fc_frame + 1);
Jing Huangba816ea2010-10-18 17:10:50 -0700682 num_pages = (be16_to_cpu(prlo->payload_len) - 4) / 16;
Jing Huang7725ccf2009-09-23 17:46:15 -0700683 } else {
684 tprlo = (struct fc_tprlo_s *) (fc_frame + 1);
Jing Huangba816ea2010-10-18 17:10:50 -0700685 num_pages = (be16_to_cpu(tprlo->payload_len) - 4) / 16;
Jing Huang7725ccf2009-09-23 17:46:15 -0700686 }
687 return num_pages;
688}
689
690u16
691fc_tprlo_acc_build(struct fchs_s *fchs, struct fc_tprlo_acc_s *tprlo_acc,
Maggie50444a32010-11-29 18:26:32 -0800692 u32 d_id, u32 s_id, __be16 ox_id, int num_pages)
Jing Huang7725ccf2009-09-23 17:46:15 -0700693{
694 int page;
695
696 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
697
Jing Huang6a18b162010-10-18 17:08:54 -0700698 memset(tprlo_acc, 0, (num_pages * 16) + 4);
Jing Huang7725ccf2009-09-23 17:46:15 -0700699 tprlo_acc->command = FC_ELS_ACC;
700
701 tprlo_acc->page_len = 0x10;
Jing Huangba816ea2010-10-18 17:10:50 -0700702 tprlo_acc->payload_len = cpu_to_be16((num_pages * 16) + 4);
Jing Huang7725ccf2009-09-23 17:46:15 -0700703
704 for (page = 0; page < num_pages; page++) {
705 tprlo_acc->tprlo_acc_params[page].opa_valid = 0;
706 tprlo_acc->tprlo_acc_params[page].rpa_valid = 0;
707 tprlo_acc->tprlo_acc_params[page].fc4type_csp = FC_TYPE_FCP;
708 tprlo_acc->tprlo_acc_params[page].orig_process_assc = 0;
709 tprlo_acc->tprlo_acc_params[page].resp_process_assc = 0;
710 }
Jing Huangba816ea2010-10-18 17:10:50 -0700711 return be16_to_cpu(tprlo_acc->payload_len);
Jing Huang7725ccf2009-09-23 17:46:15 -0700712}
713
714u16
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700715fc_prlo_acc_build(struct fchs_s *fchs, struct fc_prlo_acc_s *prlo_acc, u32 d_id,
Maggie50444a32010-11-29 18:26:32 -0800716 u32 s_id, __be16 ox_id, int num_pages)
Jing Huang7725ccf2009-09-23 17:46:15 -0700717{
718 int page;
719
720 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
721
Jing Huang6a18b162010-10-18 17:08:54 -0700722 memset(prlo_acc, 0, (num_pages * 16) + 4);
Jing Huang7725ccf2009-09-23 17:46:15 -0700723 prlo_acc->command = FC_ELS_ACC;
724 prlo_acc->page_len = 0x10;
Jing Huangba816ea2010-10-18 17:10:50 -0700725 prlo_acc->payload_len = cpu_to_be16((num_pages * 16) + 4);
Jing Huang7725ccf2009-09-23 17:46:15 -0700726
727 for (page = 0; page < num_pages; page++) {
728 prlo_acc->prlo_acc_params[page].opa_valid = 0;
729 prlo_acc->prlo_acc_params[page].rpa_valid = 0;
730 prlo_acc->prlo_acc_params[page].fc4type_csp = FC_TYPE_FCP;
731 prlo_acc->prlo_acc_params[page].orig_process_assc = 0;
732 prlo_acc->prlo_acc_params[page].resp_process_assc = 0;
733 }
734
Jing Huangba816ea2010-10-18 17:10:50 -0700735 return be16_to_cpu(prlo_acc->payload_len);
Jing Huang7725ccf2009-09-23 17:46:15 -0700736}
737
738u16
739fc_rnid_build(struct fchs_s *fchs, struct fc_rnid_cmd_s *rnid, u32 d_id,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700740 u32 s_id, u16 ox_id, u32 data_format)
Jing Huang7725ccf2009-09-23 17:46:15 -0700741{
742 fc_els_req_build(fchs, d_id, s_id, ox_id);
743
Jing Huang6a18b162010-10-18 17:08:54 -0700744 memset(rnid, 0, sizeof(struct fc_rnid_cmd_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700745
746 rnid->els_cmd.els_code = FC_ELS_RNID;
747 rnid->node_id_data_format = data_format;
748
Jing Huangf8ceafd2009-09-25 12:29:54 -0700749 return sizeof(struct fc_rnid_cmd_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700750}
751
752u16
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700753fc_rnid_acc_build(struct fchs_s *fchs, struct fc_rnid_acc_s *rnid_acc, u32 d_id,
Maggie50444a32010-11-29 18:26:32 -0800754 u32 s_id, __be16 ox_id, u32 data_format,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700755 struct fc_rnid_common_id_data_s *common_id_data,
756 struct fc_rnid_general_topology_data_s *gen_topo_data)
Jing Huang7725ccf2009-09-23 17:46:15 -0700757{
Jing Huang6a18b162010-10-18 17:08:54 -0700758 memset(rnid_acc, 0, sizeof(struct fc_rnid_acc_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700759
760 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
761
762 rnid_acc->els_cmd.els_code = FC_ELS_ACC;
763 rnid_acc->node_id_data_format = data_format;
764 rnid_acc->common_id_data_length =
765 sizeof(struct fc_rnid_common_id_data_s);
766 rnid_acc->common_id_data = *common_id_data;
767
768 if (data_format == RNID_NODEID_DATA_FORMAT_DISCOVERY) {
769 rnid_acc->specific_id_data_length =
770 sizeof(struct fc_rnid_general_topology_data_s);
Jing Huang6a18b162010-10-18 17:08:54 -0700771 rnid_acc->gen_topology_data = *gen_topo_data;
Jing Huangf8ceafd2009-09-25 12:29:54 -0700772 return sizeof(struct fc_rnid_acc_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700773 } else {
Jing Huangf8ceafd2009-09-25 12:29:54 -0700774 return sizeof(struct fc_rnid_acc_s) -
775 sizeof(struct fc_rnid_general_topology_data_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700776 }
777
778}
779
780u16
781fc_rpsc_build(struct fchs_s *fchs, struct fc_rpsc_cmd_s *rpsc, u32 d_id,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700782 u32 s_id, u16 ox_id)
Jing Huang7725ccf2009-09-23 17:46:15 -0700783{
784 fc_els_req_build(fchs, d_id, s_id, ox_id);
785
Jing Huang6a18b162010-10-18 17:08:54 -0700786 memset(rpsc, 0, sizeof(struct fc_rpsc_cmd_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700787
788 rpsc->els_cmd.els_code = FC_ELS_RPSC;
Jing Huangf8ceafd2009-09-25 12:29:54 -0700789 return sizeof(struct fc_rpsc_cmd_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700790}
791
792u16
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700793fc_rpsc2_build(struct fchs_s *fchs, struct fc_rpsc2_cmd_s *rpsc2, u32 d_id,
794 u32 s_id, u32 *pid_list, u16 npids)
Jing Huang7725ccf2009-09-23 17:46:15 -0700795{
Maggie Zhangf16a1752010-12-09 19:12:32 -0800796 u32 dctlr_id = FC_DOMAIN_CTRLR(bfa_hton3b(d_id));
Jing Huang7725ccf2009-09-23 17:46:15 -0700797 int i = 0;
798
Maggie Zhangf16a1752010-12-09 19:12:32 -0800799 fc_els_req_build(fchs, bfa_hton3b(dctlr_id), s_id, 0);
Jing Huang7725ccf2009-09-23 17:46:15 -0700800
Jing Huang6a18b162010-10-18 17:08:54 -0700801 memset(rpsc2, 0, sizeof(struct fc_rpsc2_cmd_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700802
803 rpsc2->els_cmd.els_code = FC_ELS_RPSC;
Jing Huangba816ea2010-10-18 17:10:50 -0700804 rpsc2->token = cpu_to_be32(FC_BRCD_TOKEN);
805 rpsc2->num_pids = cpu_to_be16(npids);
Jing Huang7725ccf2009-09-23 17:46:15 -0700806 for (i = 0; i < npids; i++)
807 rpsc2->pid_list[i].pid = pid_list[i];
808
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700809 return sizeof(struct fc_rpsc2_cmd_s) + ((npids - 1) * (sizeof(u32)));
Jing Huang7725ccf2009-09-23 17:46:15 -0700810}
811
812u16
813fc_rpsc_acc_build(struct fchs_s *fchs, struct fc_rpsc_acc_s *rpsc_acc,
Maggie50444a32010-11-29 18:26:32 -0800814 u32 d_id, u32 s_id, __be16 ox_id,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700815 struct fc_rpsc_speed_info_s *oper_speed)
Jing Huang7725ccf2009-09-23 17:46:15 -0700816{
Jing Huang6a18b162010-10-18 17:08:54 -0700817 memset(rpsc_acc, 0, sizeof(struct fc_rpsc_acc_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700818
819 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
820
821 rpsc_acc->command = FC_ELS_ACC;
Jing Huangba816ea2010-10-18 17:10:50 -0700822 rpsc_acc->num_entries = cpu_to_be16(1);
Jing Huang7725ccf2009-09-23 17:46:15 -0700823
824 rpsc_acc->speed_info[0].port_speed_cap =
Jing Huangba816ea2010-10-18 17:10:50 -0700825 cpu_to_be16(oper_speed->port_speed_cap);
Jing Huang7725ccf2009-09-23 17:46:15 -0700826
827 rpsc_acc->speed_info[0].port_op_speed =
Jing Huangba816ea2010-10-18 17:10:50 -0700828 cpu_to_be16(oper_speed->port_op_speed);
Jing Huang7725ccf2009-09-23 17:46:15 -0700829
Jing Huangf8ceafd2009-09-25 12:29:54 -0700830 return sizeof(struct fc_rpsc_acc_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700831}
832
Jing Huang7725ccf2009-09-23 17:46:15 -0700833u16
834fc_logo_rsp_parse(struct fchs_s *fchs, int len)
835{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700836 struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
Jing Huang7725ccf2009-09-23 17:46:15 -0700837
838 len = len;
839 if (els_cmd->els_code != FC_ELS_ACC)
840 return FC_PARSE_FAILURE;
841
842 return FC_PARSE_OK;
843}
844
845u16
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700846fc_pdisc_build(struct fchs_s *fchs, u32 d_id, u32 s_id, u16 ox_id,
847 wwn_t port_name, wwn_t node_name, u16 pdu_size)
Jing Huang7725ccf2009-09-23 17:46:15 -0700848{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700849 struct fc_logi_s *pdisc = (struct fc_logi_s *) (fchs + 1);
Jing Huang7725ccf2009-09-23 17:46:15 -0700850
Jing Huang6a18b162010-10-18 17:08:54 -0700851 memcpy(pdisc, &plogi_tmpl, sizeof(struct fc_logi_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700852
853 pdisc->els_cmd.els_code = FC_ELS_PDISC;
854 fc_els_req_build(fchs, d_id, s_id, ox_id);
855
Jing Huangba816ea2010-10-18 17:10:50 -0700856 pdisc->csp.rxsz = pdisc->class3.rxsz = cpu_to_be16(pdu_size);
Jing Huang7725ccf2009-09-23 17:46:15 -0700857 pdisc->port_name = port_name;
858 pdisc->node_name = node_name;
859
Jing Huangf8ceafd2009-09-25 12:29:54 -0700860 return sizeof(struct fc_logi_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700861}
862
863u16
864fc_pdisc_rsp_parse(struct fchs_s *fchs, int len, wwn_t port_name)
865{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700866 struct fc_logi_s *pdisc = (struct fc_logi_s *) (fchs + 1);
Jing Huang7725ccf2009-09-23 17:46:15 -0700867
868 if (len < sizeof(struct fc_logi_s))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700869 return FC_PARSE_LEN_INVAL;
Jing Huang7725ccf2009-09-23 17:46:15 -0700870
871 if (pdisc->els_cmd.els_code != FC_ELS_ACC)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700872 return FC_PARSE_ACC_INVAL;
Jing Huang7725ccf2009-09-23 17:46:15 -0700873
874 if (!wwn_is_equal(pdisc->port_name, port_name))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700875 return FC_PARSE_PWWN_NOT_EQUAL;
Jing Huang7725ccf2009-09-23 17:46:15 -0700876
877 if (!pdisc->class3.class_valid)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700878 return FC_PARSE_NWWN_NOT_EQUAL;
Jing Huang7725ccf2009-09-23 17:46:15 -0700879
Jing Huangba816ea2010-10-18 17:10:50 -0700880 if (be16_to_cpu(pdisc->class3.rxsz) < (FC_MIN_PDUSZ))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700881 return FC_PARSE_RXSZ_INVAL;
Jing Huang7725ccf2009-09-23 17:46:15 -0700882
Jing Huangf8ceafd2009-09-25 12:29:54 -0700883 return FC_PARSE_OK;
Jing Huang7725ccf2009-09-23 17:46:15 -0700884}
885
886u16
887fc_prlo_build(struct fchs_s *fchs, u32 d_id, u32 s_id, u16 ox_id,
888 int num_pages)
889{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700890 struct fc_prlo_s *prlo = (struct fc_prlo_s *) (fchs + 1);
Jing Huang7725ccf2009-09-23 17:46:15 -0700891 int page;
892
893 fc_els_req_build(fchs, d_id, s_id, ox_id);
Jing Huang6a18b162010-10-18 17:08:54 -0700894 memset(prlo, 0, (num_pages * 16) + 4);
Jing Huang7725ccf2009-09-23 17:46:15 -0700895 prlo->command = FC_ELS_PRLO;
896 prlo->page_len = 0x10;
Jing Huangba816ea2010-10-18 17:10:50 -0700897 prlo->payload_len = cpu_to_be16((num_pages * 16) + 4);
Jing Huang7725ccf2009-09-23 17:46:15 -0700898
899 for (page = 0; page < num_pages; page++) {
900 prlo->prlo_params[page].type = FC_TYPE_FCP;
901 prlo->prlo_params[page].opa_valid = 0;
902 prlo->prlo_params[page].rpa_valid = 0;
903 prlo->prlo_params[page].orig_process_assc = 0;
904 prlo->prlo_params[page].resp_process_assc = 0;
905 }
906
Jing Huangba816ea2010-10-18 17:10:50 -0700907 return be16_to_cpu(prlo->payload_len);
Jing Huang7725ccf2009-09-23 17:46:15 -0700908}
909
910u16
911fc_prlo_rsp_parse(struct fchs_s *fchs, int len)
912{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700913 struct fc_prlo_acc_s *prlo = (struct fc_prlo_acc_s *) (fchs + 1);
Jing Huang7725ccf2009-09-23 17:46:15 -0700914 int num_pages = 0;
915 int page = 0;
916
917 len = len;
918
919 if (prlo->command != FC_ELS_ACC)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700920 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700921
Jing Huangba816ea2010-10-18 17:10:50 -0700922 num_pages = ((be16_to_cpu(prlo->payload_len)) - 4) / 16;
Jing Huang7725ccf2009-09-23 17:46:15 -0700923
924 for (page = 0; page < num_pages; page++) {
925 if (prlo->prlo_acc_params[page].type != FC_TYPE_FCP)
926 return FC_PARSE_FAILURE;
927
928 if (prlo->prlo_acc_params[page].opa_valid != 0)
929 return FC_PARSE_FAILURE;
930
931 if (prlo->prlo_acc_params[page].rpa_valid != 0)
932 return FC_PARSE_FAILURE;
933
934 if (prlo->prlo_acc_params[page].orig_process_assc != 0)
935 return FC_PARSE_FAILURE;
936
937 if (prlo->prlo_acc_params[page].resp_process_assc != 0)
938 return FC_PARSE_FAILURE;
939 }
Jing Huangf8ceafd2009-09-25 12:29:54 -0700940 return FC_PARSE_OK;
Jing Huang7725ccf2009-09-23 17:46:15 -0700941
942}
943
944u16
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700945fc_tprlo_build(struct fchs_s *fchs, u32 d_id, u32 s_id, u16 ox_id,
946 int num_pages, enum fc_tprlo_type tprlo_type, u32 tpr_id)
Jing Huang7725ccf2009-09-23 17:46:15 -0700947{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700948 struct fc_tprlo_s *tprlo = (struct fc_tprlo_s *) (fchs + 1);
Jing Huang7725ccf2009-09-23 17:46:15 -0700949 int page;
950
951 fc_els_req_build(fchs, d_id, s_id, ox_id);
Jing Huang6a18b162010-10-18 17:08:54 -0700952 memset(tprlo, 0, (num_pages * 16) + 4);
Jing Huang7725ccf2009-09-23 17:46:15 -0700953 tprlo->command = FC_ELS_TPRLO;
954 tprlo->page_len = 0x10;
Jing Huangba816ea2010-10-18 17:10:50 -0700955 tprlo->payload_len = cpu_to_be16((num_pages * 16) + 4);
Jing Huang7725ccf2009-09-23 17:46:15 -0700956
957 for (page = 0; page < num_pages; page++) {
958 tprlo->tprlo_params[page].type = FC_TYPE_FCP;
959 tprlo->tprlo_params[page].opa_valid = 0;
960 tprlo->tprlo_params[page].rpa_valid = 0;
961 tprlo->tprlo_params[page].orig_process_assc = 0;
962 tprlo->tprlo_params[page].resp_process_assc = 0;
963 if (tprlo_type == FC_GLOBAL_LOGO) {
964 tprlo->tprlo_params[page].global_process_logout = 1;
965 } else if (tprlo_type == FC_TPR_LOGO) {
966 tprlo->tprlo_params[page].tpo_nport_valid = 1;
967 tprlo->tprlo_params[page].tpo_nport_id = (tpr_id);
968 }
969 }
970
Jing Huangba816ea2010-10-18 17:10:50 -0700971 return be16_to_cpu(tprlo->payload_len);
Jing Huang7725ccf2009-09-23 17:46:15 -0700972}
973
974u16
975fc_tprlo_rsp_parse(struct fchs_s *fchs, int len)
976{
977 struct fc_tprlo_acc_s *tprlo = (struct fc_tprlo_acc_s *) (fchs + 1);
978 int num_pages = 0;
979 int page = 0;
980
981 len = len;
982
983 if (tprlo->command != FC_ELS_ACC)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700984 return FC_PARSE_ACC_INVAL;
Jing Huang7725ccf2009-09-23 17:46:15 -0700985
Jing Huangba816ea2010-10-18 17:10:50 -0700986 num_pages = (be16_to_cpu(tprlo->payload_len) - 4) / 16;
Jing Huang7725ccf2009-09-23 17:46:15 -0700987
988 for (page = 0; page < num_pages; page++) {
989 if (tprlo->tprlo_acc_params[page].type != FC_TYPE_FCP)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700990 return FC_PARSE_NOT_FCP;
Jing Huang7725ccf2009-09-23 17:46:15 -0700991 if (tprlo->tprlo_acc_params[page].opa_valid != 0)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700992 return FC_PARSE_OPAFLAG_INVAL;
Jing Huang7725ccf2009-09-23 17:46:15 -0700993 if (tprlo->tprlo_acc_params[page].rpa_valid != 0)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700994 return FC_PARSE_RPAFLAG_INVAL;
Jing Huang7725ccf2009-09-23 17:46:15 -0700995 if (tprlo->tprlo_acc_params[page].orig_process_assc != 0)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700996 return FC_PARSE_OPA_INVAL;
Jing Huang7725ccf2009-09-23 17:46:15 -0700997 if (tprlo->tprlo_acc_params[page].resp_process_assc != 0)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700998 return FC_PARSE_RPA_INVAL;
Jing Huang7725ccf2009-09-23 17:46:15 -0700999 }
Jing Huangf8ceafd2009-09-25 12:29:54 -07001000 return FC_PARSE_OK;
Jing Huang7725ccf2009-09-23 17:46:15 -07001001}
1002
1003enum fc_parse_status
1004fc_rrq_rsp_parse(struct fchs_s *fchs, int len)
1005{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001006 struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
Jing Huang7725ccf2009-09-23 17:46:15 -07001007
1008 len = len;
1009 if (els_cmd->els_code != FC_ELS_ACC)
1010 return FC_PARSE_FAILURE;
1011
1012 return FC_PARSE_OK;
1013}
1014
1015u16
Maggie50444a32010-11-29 18:26:32 -08001016fc_ba_rjt_build(struct fchs_s *fchs, u32 d_id, u32 s_id, __be16 ox_id,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001017 u32 reason_code, u32 reason_expl)
Jing Huang7725ccf2009-09-23 17:46:15 -07001018{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001019 struct fc_ba_rjt_s *ba_rjt = (struct fc_ba_rjt_s *) (fchs + 1);
Jing Huang7725ccf2009-09-23 17:46:15 -07001020
1021 fc_bls_rsp_build(fchs, d_id, s_id, ox_id);
1022
1023 fchs->cat_info = FC_CAT_BA_RJT;
1024 ba_rjt->reason_code = reason_code;
1025 ba_rjt->reason_expl = reason_expl;
Jing Huangf8ceafd2009-09-25 12:29:54 -07001026 return sizeof(struct fc_ba_rjt_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001027}
1028
1029static void
1030fc_gs_cthdr_build(struct ct_hdr_s *cthdr, u32 s_id, u16 cmd_code)
1031{
Jing Huang6a18b162010-10-18 17:08:54 -07001032 memset(cthdr, 0, sizeof(struct ct_hdr_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001033 cthdr->rev_id = CT_GS3_REVISION;
1034 cthdr->gs_type = CT_GSTYPE_DIRSERVICE;
1035 cthdr->gs_sub_type = CT_GSSUBTYPE_NAMESERVER;
Jing Huangba816ea2010-10-18 17:10:50 -07001036 cthdr->cmd_rsp_code = cpu_to_be16(cmd_code);
Jing Huang7725ccf2009-09-23 17:46:15 -07001037}
1038
1039static void
1040fc_gs_fdmi_cthdr_build(struct ct_hdr_s *cthdr, u32 s_id, u16 cmd_code)
1041{
Jing Huang6a18b162010-10-18 17:08:54 -07001042 memset(cthdr, 0, sizeof(struct ct_hdr_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001043 cthdr->rev_id = CT_GS3_REVISION;
1044 cthdr->gs_type = CT_GSTYPE_MGMTSERVICE;
1045 cthdr->gs_sub_type = CT_GSSUBTYPE_HBA_MGMTSERVER;
Jing Huangba816ea2010-10-18 17:10:50 -07001046 cthdr->cmd_rsp_code = cpu_to_be16(cmd_code);
Jing Huang7725ccf2009-09-23 17:46:15 -07001047}
1048
1049static void
1050fc_gs_ms_cthdr_build(struct ct_hdr_s *cthdr, u32 s_id, u16 cmd_code,
1051 u8 sub_type)
1052{
Jing Huang6a18b162010-10-18 17:08:54 -07001053 memset(cthdr, 0, sizeof(struct ct_hdr_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001054 cthdr->rev_id = CT_GS3_REVISION;
1055 cthdr->gs_type = CT_GSTYPE_MGMTSERVICE;
1056 cthdr->gs_sub_type = sub_type;
Jing Huangba816ea2010-10-18 17:10:50 -07001057 cthdr->cmd_rsp_code = cpu_to_be16(cmd_code);
Jing Huang7725ccf2009-09-23 17:46:15 -07001058}
1059
1060u16
1061fc_gidpn_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
1062 wwn_t port_name)
1063{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001064 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1065 struct fcgs_gidpn_req_s *gidpn = (struct fcgs_gidpn_req_s *)(cthdr + 1);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001066 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001067
1068 fc_gs_fchdr_build(fchs, d_id, s_id, ox_id);
1069 fc_gs_cthdr_build(cthdr, s_id, GS_GID_PN);
1070
Jing Huang6a18b162010-10-18 17:08:54 -07001071 memset(gidpn, 0, sizeof(struct fcgs_gidpn_req_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001072 gidpn->port_name = port_name;
Jing Huangf8ceafd2009-09-25 12:29:54 -07001073 return sizeof(struct fcgs_gidpn_req_s) + sizeof(struct ct_hdr_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001074}
1075
1076u16
1077fc_gpnid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
1078 u32 port_id)
1079{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001080 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
Jing Huang7725ccf2009-09-23 17:46:15 -07001081 fcgs_gpnid_req_t *gpnid = (fcgs_gpnid_req_t *) (cthdr + 1);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001082 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001083
1084 fc_gs_fchdr_build(fchs, d_id, s_id, ox_id);
1085 fc_gs_cthdr_build(cthdr, s_id, GS_GPN_ID);
1086
Jing Huang6a18b162010-10-18 17:08:54 -07001087 memset(gpnid, 0, sizeof(fcgs_gpnid_req_t));
Jing Huang7725ccf2009-09-23 17:46:15 -07001088 gpnid->dap = port_id;
Jing Huangf8ceafd2009-09-25 12:29:54 -07001089 return sizeof(fcgs_gpnid_req_t) + sizeof(struct ct_hdr_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001090}
1091
1092u16
1093fc_gnnid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
1094 u32 port_id)
1095{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001096 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
Jing Huang7725ccf2009-09-23 17:46:15 -07001097 fcgs_gnnid_req_t *gnnid = (fcgs_gnnid_req_t *) (cthdr + 1);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001098 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001099
1100 fc_gs_fchdr_build(fchs, d_id, s_id, ox_id);
1101 fc_gs_cthdr_build(cthdr, s_id, GS_GNN_ID);
1102
Jing Huang6a18b162010-10-18 17:08:54 -07001103 memset(gnnid, 0, sizeof(fcgs_gnnid_req_t));
Jing Huang7725ccf2009-09-23 17:46:15 -07001104 gnnid->dap = port_id;
Jing Huangf8ceafd2009-09-25 12:29:54 -07001105 return sizeof(fcgs_gnnid_req_t) + sizeof(struct ct_hdr_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001106}
1107
1108u16
1109fc_ct_rsp_parse(struct ct_hdr_s *cthdr)
1110{
Jing Huangba816ea2010-10-18 17:10:50 -07001111 if (be16_to_cpu(cthdr->cmd_rsp_code) != CT_RSP_ACCEPT) {
Jing Huang7725ccf2009-09-23 17:46:15 -07001112 if (cthdr->reason_code == CT_RSN_LOGICAL_BUSY)
1113 return FC_PARSE_BUSY;
1114 else
1115 return FC_PARSE_FAILURE;
1116 }
1117
1118 return FC_PARSE_OK;
1119}
1120
1121u16
Krishna Gudipatid7be54c2011-06-24 20:24:52 -07001122fc_gs_rjt_build(struct fchs_s *fchs, struct ct_hdr_s *cthdr,
1123 u32 d_id, u32 s_id, u16 ox_id, u8 reason_code,
1124 u8 reason_code_expl)
1125{
1126 fc_gsresp_fchdr_build(fchs, d_id, s_id, ox_id);
1127
1128 cthdr->cmd_rsp_code = cpu_to_be16(CT_RSP_REJECT);
1129 cthdr->rev_id = CT_GS3_REVISION;
1130
1131 cthdr->reason_code = reason_code;
1132 cthdr->exp_code = reason_code_expl;
1133 return sizeof(struct ct_hdr_s);
1134}
1135
1136u16
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001137fc_scr_build(struct fchs_s *fchs, struct fc_scr_s *scr,
1138 u8 set_br_reg, u32 s_id, u16 ox_id)
Jing Huang7725ccf2009-09-23 17:46:15 -07001139{
Maggie Zhangf16a1752010-12-09 19:12:32 -08001140 u32 d_id = bfa_hton3b(FC_FABRIC_CONTROLLER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001141
1142 fc_els_req_build(fchs, d_id, s_id, ox_id);
1143
Jing Huang6a18b162010-10-18 17:08:54 -07001144 memset(scr, 0, sizeof(struct fc_scr_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001145 scr->command = FC_ELS_SCR;
1146 scr->reg_func = FC_SCR_REG_FUNC_FULL;
1147 if (set_br_reg)
1148 scr->vu_reg_func = FC_VU_SCR_REG_FUNC_FABRIC_NAME_CHANGE;
1149
Jing Huangf8ceafd2009-09-25 12:29:54 -07001150 return sizeof(struct fc_scr_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001151}
1152
1153u16
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001154fc_rscn_build(struct fchs_s *fchs, struct fc_rscn_pl_s *rscn,
1155 u32 s_id, u16 ox_id)
Jing Huang7725ccf2009-09-23 17:46:15 -07001156{
Maggie Zhangf16a1752010-12-09 19:12:32 -08001157 u32 d_id = bfa_hton3b(FC_FABRIC_CONTROLLER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001158 u16 payldlen;
1159
1160 fc_els_req_build(fchs, d_id, s_id, ox_id);
1161 rscn->command = FC_ELS_RSCN;
1162 rscn->pagelen = sizeof(rscn->event[0]);
1163
1164 payldlen = sizeof(u32) + rscn->pagelen;
Jing Huangba816ea2010-10-18 17:10:50 -07001165 rscn->payldlen = cpu_to_be16(payldlen);
Jing Huang7725ccf2009-09-23 17:46:15 -07001166
1167 rscn->event[0].format = FC_RSCN_FORMAT_PORTID;
1168 rscn->event[0].portid = s_id;
1169
Jing Huangf8ceafd2009-09-25 12:29:54 -07001170 return sizeof(struct fc_rscn_pl_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001171}
1172
1173u16
1174fc_rftid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001175 enum bfa_lport_role roles)
Jing Huang7725ccf2009-09-23 17:46:15 -07001176{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001177 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1178 struct fcgs_rftid_req_s *rftid = (struct fcgs_rftid_req_s *)(cthdr + 1);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001179 u32 type_value, d_id = bfa_hton3b(FC_NAME_SERVER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001180 u8 index;
1181
1182 fc_gs_fchdr_build(fchs, d_id, s_id, ox_id);
1183 fc_gs_cthdr_build(cthdr, s_id, GS_RFT_ID);
1184
Jing Huang6a18b162010-10-18 17:08:54 -07001185 memset(rftid, 0, sizeof(struct fcgs_rftid_req_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001186
1187 rftid->dap = s_id;
1188
1189 /* By default, FCP FC4 Type is registered */
1190 index = FC_TYPE_FCP >> 5;
1191 type_value = 1 << (FC_TYPE_FCP % 32);
Jing Huangba816ea2010-10-18 17:10:50 -07001192 rftid->fc4_type[index] = cpu_to_be32(type_value);
Jing Huang7725ccf2009-09-23 17:46:15 -07001193
Jing Huangf8ceafd2009-09-25 12:29:54 -07001194 return sizeof(struct fcgs_rftid_req_s) + sizeof(struct ct_hdr_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001195}
1196
1197u16
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001198fc_rftid_build_sol(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
1199 u8 *fc4_bitmap, u32 bitmap_size)
Jing Huang7725ccf2009-09-23 17:46:15 -07001200{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001201 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1202 struct fcgs_rftid_req_s *rftid = (struct fcgs_rftid_req_s *)(cthdr + 1);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001203 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001204
1205 fc_gs_fchdr_build(fchs, d_id, s_id, ox_id);
1206 fc_gs_cthdr_build(cthdr, s_id, GS_RFT_ID);
1207
Jing Huang6a18b162010-10-18 17:08:54 -07001208 memset(rftid, 0, sizeof(struct fcgs_rftid_req_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001209
1210 rftid->dap = s_id;
Jing Huang6a18b162010-10-18 17:08:54 -07001211 memcpy((void *)rftid->fc4_type, (void *)fc4_bitmap,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001212 (bitmap_size < 32 ? bitmap_size : 32));
Jing Huang7725ccf2009-09-23 17:46:15 -07001213
Jing Huangf8ceafd2009-09-25 12:29:54 -07001214 return sizeof(struct fcgs_rftid_req_s) + sizeof(struct ct_hdr_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001215}
1216
1217u16
1218fc_rffid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
1219 u8 fc4_type, u8 fc4_ftrs)
1220{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001221 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1222 struct fcgs_rffid_req_s *rffid = (struct fcgs_rffid_req_s *)(cthdr + 1);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001223 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001224
1225 fc_gs_fchdr_build(fchs, d_id, s_id, ox_id);
1226 fc_gs_cthdr_build(cthdr, s_id, GS_RFF_ID);
1227
Jing Huang6a18b162010-10-18 17:08:54 -07001228 memset(rffid, 0, sizeof(struct fcgs_rffid_req_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001229
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001230 rffid->dap = s_id;
Jing Huang7725ccf2009-09-23 17:46:15 -07001231 rffid->fc4ftr_bits = fc4_ftrs;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001232 rffid->fc4_type = fc4_type;
Jing Huang7725ccf2009-09-23 17:46:15 -07001233
Jing Huangf8ceafd2009-09-25 12:29:54 -07001234 return sizeof(struct fcgs_rffid_req_s) + sizeof(struct ct_hdr_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001235}
1236
1237u16
1238fc_rspnid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
1239 u8 *name)
1240{
1241
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001242 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
Jing Huang7725ccf2009-09-23 17:46:15 -07001243 struct fcgs_rspnid_req_s *rspnid =
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001244 (struct fcgs_rspnid_req_s *)(cthdr + 1);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001245 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001246
1247 fc_gs_fchdr_build(fchs, d_id, s_id, ox_id);
1248 fc_gs_cthdr_build(cthdr, s_id, GS_RSPN_ID);
1249
Jing Huang6a18b162010-10-18 17:08:54 -07001250 memset(rspnid, 0, sizeof(struct fcgs_rspnid_req_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001251
1252 rspnid->dap = s_id;
1253 rspnid->spn_len = (u8) strlen((char *)name);
1254 strncpy((char *)rspnid->spn, (char *)name, rspnid->spn_len);
1255
Jing Huangf8ceafd2009-09-25 12:29:54 -07001256 return sizeof(struct fcgs_rspnid_req_s) + sizeof(struct ct_hdr_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001257}
1258
1259u16
Krishna Gudipatice7242b2012-08-22 19:52:43 -07001260fc_rsnn_nn_build(struct fchs_s *fchs, void *pyld, u32 s_id,
1261 wwn_t node_name, u8 *name)
1262{
1263 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1264 struct fcgs_rsnn_nn_req_s *rsnn_nn =
1265 (struct fcgs_rsnn_nn_req_s *) (cthdr + 1);
1266 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
1267
1268 fc_gs_fchdr_build(fchs, d_id, s_id, 0);
1269 fc_gs_cthdr_build(cthdr, s_id, GS_RSNN_NN);
1270
1271 memset(rsnn_nn, 0, sizeof(struct fcgs_rsnn_nn_req_s));
1272
1273 rsnn_nn->node_name = node_name;
1274 rsnn_nn->snn_len = (u8) strlen((char *)name);
1275 strncpy((char *)rsnn_nn->snn, (char *)name, rsnn_nn->snn_len);
1276
1277 return sizeof(struct fcgs_rsnn_nn_req_s) + sizeof(struct ct_hdr_s);
1278}
1279
1280u16
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001281fc_gid_ft_build(struct fchs_s *fchs, void *pyld, u32 s_id, u8 fc4_type)
Jing Huang7725ccf2009-09-23 17:46:15 -07001282{
1283
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001284 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1285 struct fcgs_gidft_req_s *gidft = (struct fcgs_gidft_req_s *)(cthdr + 1);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001286 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001287
1288 fc_gs_fchdr_build(fchs, d_id, s_id, 0);
1289
1290 fc_gs_cthdr_build(cthdr, s_id, GS_GID_FT);
1291
Jing Huang6a18b162010-10-18 17:08:54 -07001292 memset(gidft, 0, sizeof(struct fcgs_gidft_req_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001293 gidft->fc4_type = fc4_type;
1294 gidft->domain_id = 0;
1295 gidft->area_id = 0;
1296
Jing Huangf8ceafd2009-09-25 12:29:54 -07001297 return sizeof(struct fcgs_gidft_req_s) + sizeof(struct ct_hdr_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001298}
1299
1300u16
1301fc_rpnid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u32 port_id,
1302 wwn_t port_name)
1303{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001304 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1305 struct fcgs_rpnid_req_s *rpnid = (struct fcgs_rpnid_req_s *)(cthdr + 1);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001306 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001307
1308 fc_gs_fchdr_build(fchs, d_id, s_id, 0);
1309 fc_gs_cthdr_build(cthdr, s_id, GS_RPN_ID);
1310
Jing Huang6a18b162010-10-18 17:08:54 -07001311 memset(rpnid, 0, sizeof(struct fcgs_rpnid_req_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001312 rpnid->port_id = port_id;
1313 rpnid->port_name = port_name;
1314
Jing Huangf8ceafd2009-09-25 12:29:54 -07001315 return sizeof(struct fcgs_rpnid_req_s) + sizeof(struct ct_hdr_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001316}
1317
1318u16
1319fc_rnnid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u32 port_id,
1320 wwn_t node_name)
1321{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001322 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1323 struct fcgs_rnnid_req_s *rnnid = (struct fcgs_rnnid_req_s *)(cthdr + 1);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001324 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001325
1326 fc_gs_fchdr_build(fchs, d_id, s_id, 0);
1327 fc_gs_cthdr_build(cthdr, s_id, GS_RNN_ID);
1328
Jing Huang6a18b162010-10-18 17:08:54 -07001329 memset(rnnid, 0, sizeof(struct fcgs_rnnid_req_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001330 rnnid->port_id = port_id;
1331 rnnid->node_name = node_name;
1332
Jing Huangf8ceafd2009-09-25 12:29:54 -07001333 return sizeof(struct fcgs_rnnid_req_s) + sizeof(struct ct_hdr_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001334}
1335
1336u16
1337fc_rcsid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u32 port_id,
1338 u32 cos)
1339{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001340 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
Jing Huang7725ccf2009-09-23 17:46:15 -07001341 struct fcgs_rcsid_req_s *rcsid =
1342 (struct fcgs_rcsid_req_s *) (cthdr + 1);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001343 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001344
1345 fc_gs_fchdr_build(fchs, d_id, s_id, 0);
1346 fc_gs_cthdr_build(cthdr, s_id, GS_RCS_ID);
1347
Jing Huang6a18b162010-10-18 17:08:54 -07001348 memset(rcsid, 0, sizeof(struct fcgs_rcsid_req_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001349 rcsid->port_id = port_id;
1350 rcsid->cos = cos;
1351
Jing Huangf8ceafd2009-09-25 12:29:54 -07001352 return sizeof(struct fcgs_rcsid_req_s) + sizeof(struct ct_hdr_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001353}
1354
1355u16
1356fc_rptid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u32 port_id,
1357 u8 port_type)
1358{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001359 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1360 struct fcgs_rptid_req_s *rptid = (struct fcgs_rptid_req_s *)(cthdr + 1);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001361 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001362
1363 fc_gs_fchdr_build(fchs, d_id, s_id, 0);
1364 fc_gs_cthdr_build(cthdr, s_id, GS_RPT_ID);
1365
Jing Huang6a18b162010-10-18 17:08:54 -07001366 memset(rptid, 0, sizeof(struct fcgs_rptid_req_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001367 rptid->port_id = port_id;
1368 rptid->port_type = port_type;
1369
Jing Huangf8ceafd2009-09-25 12:29:54 -07001370 return sizeof(struct fcgs_rptid_req_s) + sizeof(struct ct_hdr_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001371}
1372
1373u16
1374fc_ganxt_build(struct fchs_s *fchs, void *pyld, u32 s_id, u32 port_id)
1375{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001376 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1377 struct fcgs_ganxt_req_s *ganxt = (struct fcgs_ganxt_req_s *)(cthdr + 1);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001378 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001379
1380 fc_gs_fchdr_build(fchs, d_id, s_id, 0);
1381 fc_gs_cthdr_build(cthdr, s_id, GS_GA_NXT);
1382
Jing Huang6a18b162010-10-18 17:08:54 -07001383 memset(ganxt, 0, sizeof(struct fcgs_ganxt_req_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001384 ganxt->port_id = port_id;
1385
Jing Huangf8ceafd2009-09-25 12:29:54 -07001386 return sizeof(struct ct_hdr_s) + sizeof(struct fcgs_ganxt_req_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001387}
1388
1389/*
1390 * Builds fc hdr and ct hdr for FDMI requests.
1391 */
1392u16
1393fc_fdmi_reqhdr_build(struct fchs_s *fchs, void *pyld, u32 s_id,
1394 u16 cmd_code)
1395{
1396
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001397 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
Maggie Zhangf16a1752010-12-09 19:12:32 -08001398 u32 d_id = bfa_hton3b(FC_MGMT_SERVER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001399
1400 fc_gs_fchdr_build(fchs, d_id, s_id, 0);
1401 fc_gs_fdmi_cthdr_build(cthdr, s_id, cmd_code);
1402
Jing Huangf8ceafd2009-09-25 12:29:54 -07001403 return sizeof(struct ct_hdr_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001404}
1405
1406/*
1407 * Given a FC4 Type, this function returns a fc4 type bitmask
1408 */
1409void
1410fc_get_fc4type_bitmask(u8 fc4_type, u8 *bit_mask)
1411{
1412 u8 index;
Maggie50444a32010-11-29 18:26:32 -08001413 __be32 *ptr = (__be32 *) bit_mask;
Jing Huang7725ccf2009-09-23 17:46:15 -07001414 u32 type_value;
1415
1416 /*
1417 * @todo : Check for bitmask size
1418 */
1419
1420 index = fc4_type >> 5;
1421 type_value = 1 << (fc4_type % 32);
Jing Huangba816ea2010-10-18 17:10:50 -07001422 ptr[index] = cpu_to_be32(type_value);
Jing Huang7725ccf2009-09-23 17:46:15 -07001423
1424}
1425
1426/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001427 * GMAL Request
Jing Huang7725ccf2009-09-23 17:46:15 -07001428 */
1429u16
1430fc_gmal_req_build(struct fchs_s *fchs, void *pyld, u32 s_id, wwn_t wwn)
1431{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001432 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
Jing Huang7725ccf2009-09-23 17:46:15 -07001433 fcgs_gmal_req_t *gmal = (fcgs_gmal_req_t *) (cthdr + 1);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001434 u32 d_id = bfa_hton3b(FC_MGMT_SERVER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001435
1436 fc_gs_fchdr_build(fchs, d_id, s_id, 0);
1437 fc_gs_ms_cthdr_build(cthdr, s_id, GS_FC_GMAL_CMD,
1438 CT_GSSUBTYPE_CFGSERVER);
1439
Jing Huang6a18b162010-10-18 17:08:54 -07001440 memset(gmal, 0, sizeof(fcgs_gmal_req_t));
Jing Huang7725ccf2009-09-23 17:46:15 -07001441 gmal->wwn = wwn;
1442
Jing Huangf8ceafd2009-09-25 12:29:54 -07001443 return sizeof(struct ct_hdr_s) + sizeof(fcgs_gmal_req_t);
Jing Huang7725ccf2009-09-23 17:46:15 -07001444}
1445
1446/*
1447 * GFN (Get Fabric Name) Request
1448 */
1449u16
1450fc_gfn_req_build(struct fchs_s *fchs, void *pyld, u32 s_id, wwn_t wwn)
1451{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001452 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
Jing Huang7725ccf2009-09-23 17:46:15 -07001453 fcgs_gfn_req_t *gfn = (fcgs_gfn_req_t *) (cthdr + 1);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001454 u32 d_id = bfa_hton3b(FC_MGMT_SERVER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001455
1456 fc_gs_fchdr_build(fchs, d_id, s_id, 0);
1457 fc_gs_ms_cthdr_build(cthdr, s_id, GS_FC_GFN_CMD,
1458 CT_GSSUBTYPE_CFGSERVER);
1459
Jing Huang6a18b162010-10-18 17:08:54 -07001460 memset(gfn, 0, sizeof(fcgs_gfn_req_t));
Jing Huang7725ccf2009-09-23 17:46:15 -07001461 gfn->wwn = wwn;
1462
Jing Huangf8ceafd2009-09-25 12:29:54 -07001463 return sizeof(struct ct_hdr_s) + sizeof(fcgs_gfn_req_t);
Jing Huang7725ccf2009-09-23 17:46:15 -07001464}