blob: 08fba370cf4fad1f5db80b48463fea002acc0a6f [file] [log] [blame]
Jing Huang7725ccf2009-09-23 17:46:15 -07001/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002 * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
Jing Huang7725ccf2009-09-23 17:46:15 -07003 * 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.c - FC link service frame building and parsing routines
19 */
20
Maggie Zhangf16a1752010-12-09 19:12:32 -080021#include "bfad_drv.h"
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070022#include "bfa_fcbuild.h"
Jing Huang7725ccf2009-09-23 17:46:15 -070023
24/*
25 * static build functions
26 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070027static void fc_els_rsp_build(struct fchs_s *fchs, u32 d_id, u32 s_id,
Maggie50444a32010-11-29 18:26:32 -080028 __be16 ox_id);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070029static void fc_bls_rsp_build(struct fchs_s *fchs, u32 d_id, u32 s_id,
Maggie50444a32010-11-29 18:26:32 -080030 __be16 ox_id);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070031static struct fchs_s fc_els_req_tmpl;
32static struct fchs_s fc_els_rsp_tmpl;
33static struct fchs_s fc_bls_req_tmpl;
34static struct fchs_s fc_bls_rsp_tmpl;
Jing Huang7725ccf2009-09-23 17:46:15 -070035static struct fc_ba_acc_s ba_acc_tmpl;
36static struct fc_logi_s plogi_tmpl;
37static struct fc_prli_s prli_tmpl;
38static struct fc_rrq_s rrq_tmpl;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070039static struct fchs_s fcp_fchs_tmpl;
Jing Huang7725ccf2009-09-23 17:46:15 -070040
41void
42fcbuild_init(void)
43{
44 /*
45 * fc_els_req_tmpl
46 */
47 fc_els_req_tmpl.routing = FC_RTG_EXT_LINK;
48 fc_els_req_tmpl.cat_info = FC_CAT_LD_REQUEST;
49 fc_els_req_tmpl.type = FC_TYPE_ELS;
50 fc_els_req_tmpl.f_ctl =
Maggie Zhangf16a1752010-12-09 19:12:32 -080051 bfa_hton3b(FCTL_SEQ_INI | FCTL_FS_EXCH | FCTL_END_SEQ |
Jing Huang7725ccf2009-09-23 17:46:15 -070052 FCTL_SI_XFER);
53 fc_els_req_tmpl.rx_id = FC_RXID_ANY;
54
55 /*
56 * fc_els_rsp_tmpl
57 */
58 fc_els_rsp_tmpl.routing = FC_RTG_EXT_LINK;
59 fc_els_rsp_tmpl.cat_info = FC_CAT_LD_REPLY;
60 fc_els_rsp_tmpl.type = FC_TYPE_ELS;
61 fc_els_rsp_tmpl.f_ctl =
Maggie Zhangf16a1752010-12-09 19:12:32 -080062 bfa_hton3b(FCTL_EC_RESP | FCTL_SEQ_INI | FCTL_LS_EXCH |
Jing Huang7725ccf2009-09-23 17:46:15 -070063 FCTL_END_SEQ | FCTL_SI_XFER);
64 fc_els_rsp_tmpl.rx_id = FC_RXID_ANY;
65
66 /*
67 * fc_bls_req_tmpl
68 */
69 fc_bls_req_tmpl.routing = FC_RTG_BASIC_LINK;
70 fc_bls_req_tmpl.type = FC_TYPE_BLS;
Maggie Zhangf16a1752010-12-09 19:12:32 -080071 fc_bls_req_tmpl.f_ctl = bfa_hton3b(FCTL_END_SEQ | FCTL_SI_XFER);
Jing Huang7725ccf2009-09-23 17:46:15 -070072 fc_bls_req_tmpl.rx_id = FC_RXID_ANY;
73
74 /*
75 * fc_bls_rsp_tmpl
76 */
77 fc_bls_rsp_tmpl.routing = FC_RTG_BASIC_LINK;
78 fc_bls_rsp_tmpl.cat_info = FC_CAT_BA_ACC;
79 fc_bls_rsp_tmpl.type = FC_TYPE_BLS;
80 fc_bls_rsp_tmpl.f_ctl =
Maggie Zhangf16a1752010-12-09 19:12:32 -080081 bfa_hton3b(FCTL_EC_RESP | FCTL_SEQ_INI | FCTL_LS_EXCH |
Jing Huang7725ccf2009-09-23 17:46:15 -070082 FCTL_END_SEQ | FCTL_SI_XFER);
83 fc_bls_rsp_tmpl.rx_id = FC_RXID_ANY;
84
85 /*
86 * ba_acc_tmpl
87 */
88 ba_acc_tmpl.seq_id_valid = 0;
89 ba_acc_tmpl.low_seq_cnt = 0;
90 ba_acc_tmpl.high_seq_cnt = 0xFFFF;
91
92 /*
93 * plogi_tmpl
94 */
95 plogi_tmpl.csp.verhi = FC_PH_VER_PH_3;
96 plogi_tmpl.csp.verlo = FC_PH_VER_4_3;
Jing Huang7725ccf2009-09-23 17:46:15 -070097 plogi_tmpl.csp.ciro = 0x1;
98 plogi_tmpl.csp.cisc = 0x0;
99 plogi_tmpl.csp.altbbcred = 0x0;
Jing Huangba816ea2010-10-18 17:10:50 -0700100 plogi_tmpl.csp.conseq = cpu_to_be16(0x00FF);
101 plogi_tmpl.csp.ro_bitmap = cpu_to_be16(0x0002);
102 plogi_tmpl.csp.e_d_tov = cpu_to_be32(2000);
Jing Huang7725ccf2009-09-23 17:46:15 -0700103
104 plogi_tmpl.class3.class_valid = 1;
105 plogi_tmpl.class3.sequential = 1;
106 plogi_tmpl.class3.conseq = 0xFF;
107 plogi_tmpl.class3.ospx = 1;
108
109 /*
110 * prli_tmpl
111 */
112 prli_tmpl.command = FC_ELS_PRLI;
113 prli_tmpl.pglen = 0x10;
Jing Huangba816ea2010-10-18 17:10:50 -0700114 prli_tmpl.pagebytes = cpu_to_be16(0x0014);
Jing Huang7725ccf2009-09-23 17:46:15 -0700115 prli_tmpl.parampage.type = FC_TYPE_FCP;
116 prli_tmpl.parampage.imagepair = 1;
117 prli_tmpl.parampage.servparams.rxrdisab = 1;
118
119 /*
120 * rrq_tmpl
121 */
122 rrq_tmpl.els_cmd.els_code = FC_ELS_RRQ;
123
124 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700125 * fcp_struct fchs_s mpl
Jing Huang7725ccf2009-09-23 17:46:15 -0700126 */
127 fcp_fchs_tmpl.routing = FC_RTG_FC4_DEV_DATA;
128 fcp_fchs_tmpl.cat_info = FC_CAT_UNSOLICIT_CMD;
129 fcp_fchs_tmpl.type = FC_TYPE_FCP;
130 fcp_fchs_tmpl.f_ctl =
Maggie Zhangf16a1752010-12-09 19:12:32 -0800131 bfa_hton3b(FCTL_FS_EXCH | FCTL_END_SEQ | FCTL_SI_XFER);
Jing Huang7725ccf2009-09-23 17:46:15 -0700132 fcp_fchs_tmpl.seq_id = 1;
133 fcp_fchs_tmpl.rx_id = FC_RXID_ANY;
134}
135
136static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700137fc_gs_fchdr_build(struct fchs_s *fchs, u32 d_id, u32 s_id, u32 ox_id)
Jing Huang7725ccf2009-09-23 17:46:15 -0700138{
Jing Huang6a18b162010-10-18 17:08:54 -0700139 memset(fchs, 0, sizeof(struct fchs_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700140
141 fchs->routing = FC_RTG_FC4_DEV_DATA;
142 fchs->cat_info = FC_CAT_UNSOLICIT_CTRL;
143 fchs->type = FC_TYPE_SERVICES;
144 fchs->f_ctl =
Maggie Zhangf16a1752010-12-09 19:12:32 -0800145 bfa_hton3b(FCTL_SEQ_INI | FCTL_FS_EXCH | FCTL_END_SEQ |
Jing Huang7725ccf2009-09-23 17:46:15 -0700146 FCTL_SI_XFER);
147 fchs->rx_id = FC_RXID_ANY;
148 fchs->d_id = (d_id);
149 fchs->s_id = (s_id);
Jing Huangba816ea2010-10-18 17:10:50 -0700150 fchs->ox_id = cpu_to_be16(ox_id);
Jing Huang7725ccf2009-09-23 17:46:15 -0700151
Jing Huang5fbe25c2010-10-18 17:17:23 -0700152 /*
Jing Huang7725ccf2009-09-23 17:46:15 -0700153 * @todo no need to set ox_id for request
154 * no need to set rx_id for response
155 */
156}
157
158void
Maggie50444a32010-11-29 18:26:32 -0800159fc_els_req_build(struct fchs_s *fchs, u32 d_id, u32 s_id, __be16 ox_id)
Jing Huang7725ccf2009-09-23 17:46:15 -0700160{
Jing Huang6a18b162010-10-18 17:08:54 -0700161 memcpy(fchs, &fc_els_req_tmpl, sizeof(struct fchs_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700162 fchs->d_id = (d_id);
163 fchs->s_id = (s_id);
Jing Huangba816ea2010-10-18 17:10:50 -0700164 fchs->ox_id = cpu_to_be16(ox_id);
Jing Huang7725ccf2009-09-23 17:46:15 -0700165}
166
167static void
Maggie50444a32010-11-29 18:26:32 -0800168fc_els_rsp_build(struct fchs_s *fchs, u32 d_id, u32 s_id, __be16 ox_id)
Jing Huang7725ccf2009-09-23 17:46:15 -0700169{
Jing Huang6a18b162010-10-18 17:08:54 -0700170 memcpy(fchs, &fc_els_rsp_tmpl, sizeof(struct fchs_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700171 fchs->d_id = d_id;
172 fchs->s_id = s_id;
173 fchs->ox_id = ox_id;
174}
175
176enum fc_parse_status
177fc_els_rsp_parse(struct fchs_s *fchs, int len)
178{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700179 struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
180 struct fc_ls_rjt_s *ls_rjt = (struct fc_ls_rjt_s *) els_cmd;
Jing Huang7725ccf2009-09-23 17:46:15 -0700181
182 len = len;
183
184 switch (els_cmd->els_code) {
185 case FC_ELS_LS_RJT:
186 if (ls_rjt->reason_code == FC_LS_RJT_RSN_LOGICAL_BUSY)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700187 return FC_PARSE_BUSY;
Jing Huang7725ccf2009-09-23 17:46:15 -0700188 else
Jing Huangf8ceafd2009-09-25 12:29:54 -0700189 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700190
191 case FC_ELS_ACC:
Jing Huangf8ceafd2009-09-25 12:29:54 -0700192 return FC_PARSE_OK;
Jing Huang7725ccf2009-09-23 17:46:15 -0700193 }
Jing Huangf8ceafd2009-09-25 12:29:54 -0700194 return FC_PARSE_OK;
Jing Huang7725ccf2009-09-23 17:46:15 -0700195}
196
197static void
Maggie50444a32010-11-29 18:26:32 -0800198fc_bls_rsp_build(struct fchs_s *fchs, u32 d_id, u32 s_id, __be16 ox_id)
Jing Huang7725ccf2009-09-23 17:46:15 -0700199{
Jing Huang6a18b162010-10-18 17:08:54 -0700200 memcpy(fchs, &fc_bls_rsp_tmpl, sizeof(struct fchs_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700201 fchs->d_id = d_id;
202 fchs->s_id = s_id;
203 fchs->ox_id = ox_id;
204}
205
206static u16
207fc_plogi_x_build(struct fchs_s *fchs, void *pld, u32 d_id, u32 s_id,
Maggie50444a32010-11-29 18:26:32 -0800208 __be16 ox_id, wwn_t port_name, wwn_t node_name,
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700209 u16 pdu_size, u16 bb_cr, u8 els_code)
Jing Huang7725ccf2009-09-23 17:46:15 -0700210{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700211 struct fc_logi_s *plogi = (struct fc_logi_s *) (pld);
Jing Huang7725ccf2009-09-23 17:46:15 -0700212
Jing Huang6a18b162010-10-18 17:08:54 -0700213 memcpy(plogi, &plogi_tmpl, sizeof(struct fc_logi_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700214
215 plogi->els_cmd.els_code = els_code;
216 if (els_code == FC_ELS_PLOGI)
217 fc_els_req_build(fchs, d_id, s_id, ox_id);
218 else
219 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
220
Jing Huangba816ea2010-10-18 17:10:50 -0700221 plogi->csp.rxsz = plogi->class3.rxsz = cpu_to_be16(pdu_size);
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700222 plogi->csp.bbcred = cpu_to_be16(bb_cr);
Jing Huang7725ccf2009-09-23 17:46:15 -0700223
Jing Huang6a18b162010-10-18 17:08:54 -0700224 memcpy(&plogi->port_name, &port_name, sizeof(wwn_t));
225 memcpy(&plogi->node_name, &node_name, sizeof(wwn_t));
Jing Huang7725ccf2009-09-23 17:46:15 -0700226
Jing Huangf8ceafd2009-09-25 12:29:54 -0700227 return sizeof(struct fc_logi_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700228}
229
230u16
231fc_flogi_build(struct fchs_s *fchs, struct fc_logi_s *flogi, u32 s_id,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700232 u16 ox_id, wwn_t port_name, wwn_t node_name, u16 pdu_size,
233 u8 set_npiv, u8 set_auth, u16 local_bb_credits)
Jing Huang7725ccf2009-09-23 17:46:15 -0700234{
Maggie Zhangf16a1752010-12-09 19:12:32 -0800235 u32 d_id = bfa_hton3b(FC_FABRIC_PORT);
Maggie50444a32010-11-29 18:26:32 -0800236 __be32 *vvl_info;
Jing Huang7725ccf2009-09-23 17:46:15 -0700237
Jing Huang6a18b162010-10-18 17:08:54 -0700238 memcpy(flogi, &plogi_tmpl, sizeof(struct fc_logi_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700239
240 flogi->els_cmd.els_code = FC_ELS_FLOGI;
241 fc_els_req_build(fchs, d_id, s_id, ox_id);
242
Jing Huangba816ea2010-10-18 17:10:50 -0700243 flogi->csp.rxsz = flogi->class3.rxsz = cpu_to_be16(pdu_size);
Jing Huang7725ccf2009-09-23 17:46:15 -0700244 flogi->port_name = port_name;
245 flogi->node_name = node_name;
246
247 /*
248 * Set the NPIV Capability Bit ( word 1, bit 31) of Common
249 * Service Parameters.
250 */
251 flogi->csp.ciro = set_npiv;
252
253 /* set AUTH capability */
254 flogi->csp.security = set_auth;
255
Jing Huangba816ea2010-10-18 17:10:50 -0700256 flogi->csp.bbcred = cpu_to_be16(local_bb_credits);
Jing Huang7725ccf2009-09-23 17:46:15 -0700257
258 /* Set brcd token in VVL */
259 vvl_info = (u32 *)&flogi->vvl[0];
260
261 /* set the flag to indicate the presence of VVL */
262 flogi->csp.npiv_supp = 1; /* @todo. field name is not correct */
Jing Huangba816ea2010-10-18 17:10:50 -0700263 vvl_info[0] = cpu_to_be32(FLOGI_VVL_BRCD);
Jing Huang7725ccf2009-09-23 17:46:15 -0700264
Jing Huangf8ceafd2009-09-25 12:29:54 -0700265 return sizeof(struct fc_logi_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700266}
267
268u16
269fc_flogi_acc_build(struct fchs_s *fchs, struct fc_logi_s *flogi, u32 s_id,
Maggie50444a32010-11-29 18:26:32 -0800270 __be16 ox_id, wwn_t port_name, wwn_t node_name,
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700271 u16 pdu_size, u16 local_bb_credits, u8 bb_scn)
Jing Huang7725ccf2009-09-23 17:46:15 -0700272{
273 u32 d_id = 0;
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700274 u16 bbscn_rxsz = (bb_scn << 12) | pdu_size;
Jing Huang7725ccf2009-09-23 17:46:15 -0700275
Jing Huang6a18b162010-10-18 17:08:54 -0700276 memcpy(flogi, &plogi_tmpl, sizeof(struct fc_logi_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700277 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
278
279 flogi->els_cmd.els_code = FC_ELS_ACC;
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700280 flogi->class3.rxsz = cpu_to_be16(pdu_size);
281 flogi->csp.rxsz = cpu_to_be16(bbscn_rxsz); /* bb_scn/rxsz */
Jing Huang7725ccf2009-09-23 17:46:15 -0700282 flogi->port_name = port_name;
283 flogi->node_name = node_name;
284
Jing Huangba816ea2010-10-18 17:10:50 -0700285 flogi->csp.bbcred = cpu_to_be16(local_bb_credits);
Jing Huang7725ccf2009-09-23 17:46:15 -0700286
Jing Huangf8ceafd2009-09-25 12:29:54 -0700287 return sizeof(struct fc_logi_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700288}
289
290u16
291fc_fdisc_build(struct fchs_s *fchs, struct fc_logi_s *flogi, u32 s_id,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700292 u16 ox_id, wwn_t port_name, wwn_t node_name, u16 pdu_size)
Jing Huang7725ccf2009-09-23 17:46:15 -0700293{
Maggie Zhangf16a1752010-12-09 19:12:32 -0800294 u32 d_id = bfa_hton3b(FC_FABRIC_PORT);
Jing Huang7725ccf2009-09-23 17:46:15 -0700295
Jing Huang6a18b162010-10-18 17:08:54 -0700296 memcpy(flogi, &plogi_tmpl, sizeof(struct fc_logi_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700297
298 flogi->els_cmd.els_code = FC_ELS_FDISC;
299 fc_els_req_build(fchs, d_id, s_id, ox_id);
300
Jing Huangba816ea2010-10-18 17:10:50 -0700301 flogi->csp.rxsz = flogi->class3.rxsz = cpu_to_be16(pdu_size);
Jing Huang7725ccf2009-09-23 17:46:15 -0700302 flogi->port_name = port_name;
303 flogi->node_name = node_name;
304
Jing Huangf8ceafd2009-09-25 12:29:54 -0700305 return sizeof(struct fc_logi_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700306}
307
308u16
309fc_plogi_build(struct fchs_s *fchs, void *pld, u32 d_id, u32 s_id,
310 u16 ox_id, wwn_t port_name, wwn_t node_name,
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700311 u16 pdu_size, u16 bb_cr)
Jing Huang7725ccf2009-09-23 17:46:15 -0700312{
313 return fc_plogi_x_build(fchs, pld, d_id, s_id, ox_id, port_name,
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700314 node_name, pdu_size, bb_cr, FC_ELS_PLOGI);
Jing Huang7725ccf2009-09-23 17:46:15 -0700315}
316
317u16
318fc_plogi_acc_build(struct fchs_s *fchs, void *pld, u32 d_id, u32 s_id,
319 u16 ox_id, wwn_t port_name, wwn_t node_name,
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700320 u16 pdu_size, u16 bb_cr)
Jing Huang7725ccf2009-09-23 17:46:15 -0700321{
322 return fc_plogi_x_build(fchs, pld, d_id, s_id, ox_id, port_name,
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700323 node_name, pdu_size, bb_cr, FC_ELS_ACC);
Jing Huang7725ccf2009-09-23 17:46:15 -0700324}
325
326enum fc_parse_status
327fc_plogi_rsp_parse(struct fchs_s *fchs, int len, wwn_t port_name)
328{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700329 struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
330 struct fc_logi_s *plogi;
331 struct fc_ls_rjt_s *ls_rjt;
Jing Huang7725ccf2009-09-23 17:46:15 -0700332
333 switch (els_cmd->els_code) {
334 case FC_ELS_LS_RJT:
335 ls_rjt = (struct fc_ls_rjt_s *) (fchs + 1);
336 if (ls_rjt->reason_code == FC_LS_RJT_RSN_LOGICAL_BUSY)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700337 return FC_PARSE_BUSY;
Jing Huang7725ccf2009-09-23 17:46:15 -0700338 else
Jing Huangf8ceafd2009-09-25 12:29:54 -0700339 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700340 case FC_ELS_ACC:
341 plogi = (struct fc_logi_s *) (fchs + 1);
342 if (len < sizeof(struct fc_logi_s))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700343 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700344
345 if (!wwn_is_equal(plogi->port_name, port_name))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700346 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700347
348 if (!plogi->class3.class_valid)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700349 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700350
Jing Huangba816ea2010-10-18 17:10:50 -0700351 if (be16_to_cpu(plogi->class3.rxsz) < (FC_MIN_PDUSZ))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700352 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700353
Jing Huangf8ceafd2009-09-25 12:29:54 -0700354 return FC_PARSE_OK;
Jing Huang7725ccf2009-09-23 17:46:15 -0700355 default:
Jing Huangf8ceafd2009-09-25 12:29:54 -0700356 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700357 }
358}
359
360enum fc_parse_status
361fc_plogi_parse(struct fchs_s *fchs)
362{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700363 struct fc_logi_s *plogi = (struct fc_logi_s *) (fchs + 1);
Jing Huang7725ccf2009-09-23 17:46:15 -0700364
365 if (plogi->class3.class_valid != 1)
366 return FC_PARSE_FAILURE;
367
Jing Huangba816ea2010-10-18 17:10:50 -0700368 if ((be16_to_cpu(plogi->class3.rxsz) < FC_MIN_PDUSZ)
369 || (be16_to_cpu(plogi->class3.rxsz) > FC_MAX_PDUSZ)
Jing Huang7725ccf2009-09-23 17:46:15 -0700370 || (plogi->class3.rxsz == 0))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700371 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700372
373 return FC_PARSE_OK;
374}
375
376u16
377fc_prli_build(struct fchs_s *fchs, void *pld, u32 d_id, u32 s_id,
378 u16 ox_id)
379{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700380 struct fc_prli_s *prli = (struct fc_prli_s *) (pld);
Jing Huang7725ccf2009-09-23 17:46:15 -0700381
382 fc_els_req_build(fchs, d_id, s_id, ox_id);
Jing Huang6a18b162010-10-18 17:08:54 -0700383 memcpy(prli, &prli_tmpl, sizeof(struct fc_prli_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700384
385 prli->command = FC_ELS_PRLI;
386 prli->parampage.servparams.initiator = 1;
387 prli->parampage.servparams.retry = 1;
388 prli->parampage.servparams.rec_support = 1;
389 prli->parampage.servparams.task_retry_id = 0;
390 prli->parampage.servparams.confirm = 1;
391
Jing Huangf8ceafd2009-09-25 12:29:54 -0700392 return sizeof(struct fc_prli_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700393}
394
395u16
396fc_prli_acc_build(struct fchs_s *fchs, void *pld, u32 d_id, u32 s_id,
Maggie50444a32010-11-29 18:26:32 -0800397 __be16 ox_id, enum bfa_lport_role role)
Jing Huang7725ccf2009-09-23 17:46:15 -0700398{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700399 struct fc_prli_s *prli = (struct fc_prli_s *) (pld);
Jing Huang7725ccf2009-09-23 17:46:15 -0700400
401 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
Jing Huang6a18b162010-10-18 17:08:54 -0700402 memcpy(prli, &prli_tmpl, sizeof(struct fc_prli_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700403
404 prli->command = FC_ELS_ACC;
405
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700406 prli->parampage.servparams.initiator = 1;
Jing Huang7725ccf2009-09-23 17:46:15 -0700407
408 prli->parampage.rspcode = FC_PRLI_ACC_XQTD;
409
Jing Huangf8ceafd2009-09-25 12:29:54 -0700410 return sizeof(struct fc_prli_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700411}
412
413enum fc_parse_status
414fc_prli_rsp_parse(struct fc_prli_s *prli, int len)
415{
416 if (len < sizeof(struct fc_prli_s))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700417 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700418
419 if (prli->command != FC_ELS_ACC)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700420 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700421
422 if ((prli->parampage.rspcode != FC_PRLI_ACC_XQTD)
423 && (prli->parampage.rspcode != FC_PRLI_ACC_PREDEF_IMG))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700424 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700425
426 if (prli->parampage.servparams.target != 1)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700427 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700428
Jing Huangf8ceafd2009-09-25 12:29:54 -0700429 return FC_PARSE_OK;
Jing Huang7725ccf2009-09-23 17:46:15 -0700430}
431
432enum fc_parse_status
433fc_prli_parse(struct fc_prli_s *prli)
434{
435 if (prli->parampage.type != FC_TYPE_FCP)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700436 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700437
438 if (!prli->parampage.imagepair)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700439 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700440
441 if (!prli->parampage.servparams.initiator)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700442 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700443
Jing Huangf8ceafd2009-09-25 12:29:54 -0700444 return FC_PARSE_OK;
Jing Huang7725ccf2009-09-23 17:46:15 -0700445}
446
447u16
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700448fc_logo_build(struct fchs_s *fchs, struct fc_logo_s *logo, u32 d_id, u32 s_id,
449 u16 ox_id, wwn_t port_name)
Jing Huang7725ccf2009-09-23 17:46:15 -0700450{
451 fc_els_req_build(fchs, d_id, s_id, ox_id);
452
Jing Huang6a18b162010-10-18 17:08:54 -0700453 memset(logo, '\0', sizeof(struct fc_logo_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700454 logo->els_cmd.els_code = FC_ELS_LOGO;
455 logo->nport_id = (s_id);
456 logo->orig_port_name = port_name;
457
Jing Huangf8ceafd2009-09-25 12:29:54 -0700458 return sizeof(struct fc_logo_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700459}
460
Maggie Zhangda99dcc2010-12-09 19:13:20 -0800461static u16
Jing Huang7725ccf2009-09-23 17:46:15 -0700462fc_adisc_x_build(struct fchs_s *fchs, struct fc_adisc_s *adisc, u32 d_id,
Maggie50444a32010-11-29 18:26:32 -0800463 u32 s_id, __be16 ox_id, wwn_t port_name,
Jing Huang7725ccf2009-09-23 17:46:15 -0700464 wwn_t node_name, u8 els_code)
465{
Jing Huang6a18b162010-10-18 17:08:54 -0700466 memset(adisc, '\0', sizeof(struct fc_adisc_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700467
468 adisc->els_cmd.els_code = els_code;
469
470 if (els_code == FC_ELS_ADISC)
471 fc_els_req_build(fchs, d_id, s_id, ox_id);
472 else
473 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
474
475 adisc->orig_HA = 0;
476 adisc->orig_port_name = port_name;
477 adisc->orig_node_name = node_name;
478 adisc->nport_id = (s_id);
479
Jing Huangf8ceafd2009-09-25 12:29:54 -0700480 return sizeof(struct fc_adisc_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700481}
482
483u16
484fc_adisc_build(struct fchs_s *fchs, struct fc_adisc_s *adisc, u32 d_id,
Maggie50444a32010-11-29 18:26:32 -0800485 u32 s_id, __be16 ox_id, wwn_t port_name, wwn_t node_name)
Jing Huang7725ccf2009-09-23 17:46:15 -0700486{
487 return fc_adisc_x_build(fchs, adisc, d_id, s_id, ox_id, port_name,
488 node_name, FC_ELS_ADISC);
489}
490
491u16
492fc_adisc_acc_build(struct fchs_s *fchs, struct fc_adisc_s *adisc, u32 d_id,
Maggie50444a32010-11-29 18:26:32 -0800493 u32 s_id, __be16 ox_id, wwn_t port_name,
Jing Huang7725ccf2009-09-23 17:46:15 -0700494 wwn_t node_name)
495{
496 return fc_adisc_x_build(fchs, adisc, d_id, s_id, ox_id, port_name,
497 node_name, FC_ELS_ACC);
498}
499
500enum fc_parse_status
501fc_adisc_rsp_parse(struct fc_adisc_s *adisc, int len, wwn_t port_name,
502 wwn_t node_name)
503{
504
505 if (len < sizeof(struct fc_adisc_s))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700506 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700507
508 if (adisc->els_cmd.els_code != FC_ELS_ACC)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700509 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700510
511 if (!wwn_is_equal(adisc->orig_port_name, port_name))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700512 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700513
Jing Huangf8ceafd2009-09-25 12:29:54 -0700514 return FC_PARSE_OK;
Jing Huang7725ccf2009-09-23 17:46:15 -0700515}
516
517enum fc_parse_status
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700518fc_adisc_parse(struct fchs_s *fchs, void *pld, u32 host_dap, wwn_t node_name,
519 wwn_t port_name)
Jing Huang7725ccf2009-09-23 17:46:15 -0700520{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700521 struct fc_adisc_s *adisc = (struct fc_adisc_s *) pld;
Jing Huang7725ccf2009-09-23 17:46:15 -0700522
523 if (adisc->els_cmd.els_code != FC_ELS_ACC)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700524 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700525
526 if ((adisc->nport_id == (host_dap))
527 && wwn_is_equal(adisc->orig_port_name, port_name)
528 && wwn_is_equal(adisc->orig_node_name, node_name))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700529 return FC_PARSE_OK;
Jing Huang7725ccf2009-09-23 17:46:15 -0700530
Jing Huangf8ceafd2009-09-25 12:29:54 -0700531 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700532}
533
534enum fc_parse_status
535fc_pdisc_parse(struct fchs_s *fchs, wwn_t node_name, wwn_t port_name)
536{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700537 struct fc_logi_s *pdisc = (struct fc_logi_s *) (fchs + 1);
Jing Huang7725ccf2009-09-23 17:46:15 -0700538
539 if (pdisc->class3.class_valid != 1)
540 return FC_PARSE_FAILURE;
541
Jing Huangba816ea2010-10-18 17:10:50 -0700542 if ((be16_to_cpu(pdisc->class3.rxsz) <
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700543 (FC_MIN_PDUSZ - sizeof(struct fchs_s)))
Jing Huang7725ccf2009-09-23 17:46:15 -0700544 || (pdisc->class3.rxsz == 0))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700545 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700546
547 if (!wwn_is_equal(pdisc->port_name, port_name))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700548 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700549
550 if (!wwn_is_equal(pdisc->node_name, node_name))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700551 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700552
553 return FC_PARSE_OK;
554}
555
556u16
557fc_abts_build(struct fchs_s *fchs, u32 d_id, u32 s_id, u16 ox_id)
558{
Jing Huang6a18b162010-10-18 17:08:54 -0700559 memcpy(fchs, &fc_bls_req_tmpl, sizeof(struct fchs_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700560 fchs->cat_info = FC_CAT_ABTS;
561 fchs->d_id = (d_id);
562 fchs->s_id = (s_id);
Jing Huangba816ea2010-10-18 17:10:50 -0700563 fchs->ox_id = cpu_to_be16(ox_id);
Jing Huang7725ccf2009-09-23 17:46:15 -0700564
Jing Huangf8ceafd2009-09-25 12:29:54 -0700565 return sizeof(struct fchs_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700566}
567
568enum fc_parse_status
569fc_abts_rsp_parse(struct fchs_s *fchs, int len)
570{
571 if ((fchs->cat_info == FC_CAT_BA_ACC)
572 || (fchs->cat_info == FC_CAT_BA_RJT))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700573 return FC_PARSE_OK;
Jing Huang7725ccf2009-09-23 17:46:15 -0700574
Jing Huangf8ceafd2009-09-25 12:29:54 -0700575 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700576}
577
578u16
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700579fc_rrq_build(struct fchs_s *fchs, struct fc_rrq_s *rrq, u32 d_id, u32 s_id,
580 u16 ox_id, u16 rrq_oxid)
Jing Huang7725ccf2009-09-23 17:46:15 -0700581{
582 fc_els_req_build(fchs, d_id, s_id, ox_id);
583
584 /*
585 * build rrq payload
586 */
Jing Huang6a18b162010-10-18 17:08:54 -0700587 memcpy(rrq, &rrq_tmpl, sizeof(struct fc_rrq_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700588 rrq->s_id = (s_id);
Jing Huangba816ea2010-10-18 17:10:50 -0700589 rrq->ox_id = cpu_to_be16(rrq_oxid);
Jing Huang7725ccf2009-09-23 17:46:15 -0700590 rrq->rx_id = FC_RXID_ANY;
591
Jing Huangf8ceafd2009-09-25 12:29:54 -0700592 return sizeof(struct fc_rrq_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700593}
594
595u16
596fc_logo_acc_build(struct fchs_s *fchs, void *pld, u32 d_id, u32 s_id,
Maggie50444a32010-11-29 18:26:32 -0800597 __be16 ox_id)
Jing Huang7725ccf2009-09-23 17:46:15 -0700598{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700599 struct fc_els_cmd_s *acc = pld;
Jing Huang7725ccf2009-09-23 17:46:15 -0700600
601 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
602
Jing Huang6a18b162010-10-18 17:08:54 -0700603 memset(acc, 0, sizeof(struct fc_els_cmd_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700604 acc->els_code = FC_ELS_ACC;
605
Jing Huangf8ceafd2009-09-25 12:29:54 -0700606 return sizeof(struct fc_els_cmd_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700607}
608
609u16
610fc_ls_rjt_build(struct fchs_s *fchs, struct fc_ls_rjt_s *ls_rjt, u32 d_id,
Maggie50444a32010-11-29 18:26:32 -0800611 u32 s_id, __be16 ox_id, u8 reason_code,
Jing Huang7725ccf2009-09-23 17:46:15 -0700612 u8 reason_code_expl)
613{
614 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
Jing Huang6a18b162010-10-18 17:08:54 -0700615 memset(ls_rjt, 0, sizeof(struct fc_ls_rjt_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700616
617 ls_rjt->els_cmd.els_code = FC_ELS_LS_RJT;
618 ls_rjt->reason_code = reason_code;
619 ls_rjt->reason_code_expl = reason_code_expl;
620 ls_rjt->vendor_unique = 0x00;
621
Jing Huangf8ceafd2009-09-25 12:29:54 -0700622 return sizeof(struct fc_ls_rjt_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700623}
624
625u16
626fc_ba_acc_build(struct fchs_s *fchs, struct fc_ba_acc_s *ba_acc, u32 d_id,
Maggie50444a32010-11-29 18:26:32 -0800627 u32 s_id, __be16 ox_id, u16 rx_id)
Jing Huang7725ccf2009-09-23 17:46:15 -0700628{
629 fc_bls_rsp_build(fchs, d_id, s_id, ox_id);
630
Jing Huang6a18b162010-10-18 17:08:54 -0700631 memcpy(ba_acc, &ba_acc_tmpl, sizeof(struct fc_ba_acc_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700632
633 fchs->rx_id = rx_id;
634
635 ba_acc->ox_id = fchs->ox_id;
636 ba_acc->rx_id = fchs->rx_id;
637
Jing Huangf8ceafd2009-09-25 12:29:54 -0700638 return sizeof(struct fc_ba_acc_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700639}
640
641u16
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700642fc_ls_acc_build(struct fchs_s *fchs, struct fc_els_cmd_s *els_cmd, u32 d_id,
Maggie50444a32010-11-29 18:26:32 -0800643 u32 s_id, __be16 ox_id)
Jing Huang7725ccf2009-09-23 17:46:15 -0700644{
645 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
Jing Huang6a18b162010-10-18 17:08:54 -0700646 memset(els_cmd, 0, sizeof(struct fc_els_cmd_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700647 els_cmd->els_code = FC_ELS_ACC;
648
Jing Huangf8ceafd2009-09-25 12:29:54 -0700649 return sizeof(struct fc_els_cmd_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700650}
651
652int
653fc_logout_params_pages(struct fchs_s *fc_frame, u8 els_code)
654{
655 int num_pages = 0;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700656 struct fc_prlo_s *prlo;
657 struct fc_tprlo_s *tprlo;
Jing Huang7725ccf2009-09-23 17:46:15 -0700658
659 if (els_code == FC_ELS_PRLO) {
660 prlo = (struct fc_prlo_s *) (fc_frame + 1);
Jing Huangba816ea2010-10-18 17:10:50 -0700661 num_pages = (be16_to_cpu(prlo->payload_len) - 4) / 16;
Jing Huang7725ccf2009-09-23 17:46:15 -0700662 } else {
663 tprlo = (struct fc_tprlo_s *) (fc_frame + 1);
Jing Huangba816ea2010-10-18 17:10:50 -0700664 num_pages = (be16_to_cpu(tprlo->payload_len) - 4) / 16;
Jing Huang7725ccf2009-09-23 17:46:15 -0700665 }
666 return num_pages;
667}
668
669u16
670fc_tprlo_acc_build(struct fchs_s *fchs, struct fc_tprlo_acc_s *tprlo_acc,
Maggie50444a32010-11-29 18:26:32 -0800671 u32 d_id, u32 s_id, __be16 ox_id, int num_pages)
Jing Huang7725ccf2009-09-23 17:46:15 -0700672{
673 int page;
674
675 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
676
Jing Huang6a18b162010-10-18 17:08:54 -0700677 memset(tprlo_acc, 0, (num_pages * 16) + 4);
Jing Huang7725ccf2009-09-23 17:46:15 -0700678 tprlo_acc->command = FC_ELS_ACC;
679
680 tprlo_acc->page_len = 0x10;
Jing Huangba816ea2010-10-18 17:10:50 -0700681 tprlo_acc->payload_len = cpu_to_be16((num_pages * 16) + 4);
Jing Huang7725ccf2009-09-23 17:46:15 -0700682
683 for (page = 0; page < num_pages; page++) {
684 tprlo_acc->tprlo_acc_params[page].opa_valid = 0;
685 tprlo_acc->tprlo_acc_params[page].rpa_valid = 0;
686 tprlo_acc->tprlo_acc_params[page].fc4type_csp = FC_TYPE_FCP;
687 tprlo_acc->tprlo_acc_params[page].orig_process_assc = 0;
688 tprlo_acc->tprlo_acc_params[page].resp_process_assc = 0;
689 }
Jing Huangba816ea2010-10-18 17:10:50 -0700690 return be16_to_cpu(tprlo_acc->payload_len);
Jing Huang7725ccf2009-09-23 17:46:15 -0700691}
692
693u16
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700694fc_prlo_acc_build(struct fchs_s *fchs, struct fc_prlo_acc_s *prlo_acc, u32 d_id,
Maggie50444a32010-11-29 18:26:32 -0800695 u32 s_id, __be16 ox_id, int num_pages)
Jing Huang7725ccf2009-09-23 17:46:15 -0700696{
697 int page;
698
699 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
700
Jing Huang6a18b162010-10-18 17:08:54 -0700701 memset(prlo_acc, 0, (num_pages * 16) + 4);
Jing Huang7725ccf2009-09-23 17:46:15 -0700702 prlo_acc->command = FC_ELS_ACC;
703 prlo_acc->page_len = 0x10;
Jing Huangba816ea2010-10-18 17:10:50 -0700704 prlo_acc->payload_len = cpu_to_be16((num_pages * 16) + 4);
Jing Huang7725ccf2009-09-23 17:46:15 -0700705
706 for (page = 0; page < num_pages; page++) {
707 prlo_acc->prlo_acc_params[page].opa_valid = 0;
708 prlo_acc->prlo_acc_params[page].rpa_valid = 0;
709 prlo_acc->prlo_acc_params[page].fc4type_csp = FC_TYPE_FCP;
710 prlo_acc->prlo_acc_params[page].orig_process_assc = 0;
711 prlo_acc->prlo_acc_params[page].resp_process_assc = 0;
712 }
713
Jing Huangba816ea2010-10-18 17:10:50 -0700714 return be16_to_cpu(prlo_acc->payload_len);
Jing Huang7725ccf2009-09-23 17:46:15 -0700715}
716
717u16
718fc_rnid_build(struct fchs_s *fchs, struct fc_rnid_cmd_s *rnid, u32 d_id,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700719 u32 s_id, u16 ox_id, u32 data_format)
Jing Huang7725ccf2009-09-23 17:46:15 -0700720{
721 fc_els_req_build(fchs, d_id, s_id, ox_id);
722
Jing Huang6a18b162010-10-18 17:08:54 -0700723 memset(rnid, 0, sizeof(struct fc_rnid_cmd_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700724
725 rnid->els_cmd.els_code = FC_ELS_RNID;
726 rnid->node_id_data_format = data_format;
727
Jing Huangf8ceafd2009-09-25 12:29:54 -0700728 return sizeof(struct fc_rnid_cmd_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700729}
730
731u16
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700732fc_rnid_acc_build(struct fchs_s *fchs, struct fc_rnid_acc_s *rnid_acc, u32 d_id,
Maggie50444a32010-11-29 18:26:32 -0800733 u32 s_id, __be16 ox_id, u32 data_format,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700734 struct fc_rnid_common_id_data_s *common_id_data,
735 struct fc_rnid_general_topology_data_s *gen_topo_data)
Jing Huang7725ccf2009-09-23 17:46:15 -0700736{
Jing Huang6a18b162010-10-18 17:08:54 -0700737 memset(rnid_acc, 0, sizeof(struct fc_rnid_acc_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700738
739 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
740
741 rnid_acc->els_cmd.els_code = FC_ELS_ACC;
742 rnid_acc->node_id_data_format = data_format;
743 rnid_acc->common_id_data_length =
744 sizeof(struct fc_rnid_common_id_data_s);
745 rnid_acc->common_id_data = *common_id_data;
746
747 if (data_format == RNID_NODEID_DATA_FORMAT_DISCOVERY) {
748 rnid_acc->specific_id_data_length =
749 sizeof(struct fc_rnid_general_topology_data_s);
Jing Huang6a18b162010-10-18 17:08:54 -0700750 rnid_acc->gen_topology_data = *gen_topo_data;
Jing Huangf8ceafd2009-09-25 12:29:54 -0700751 return sizeof(struct fc_rnid_acc_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700752 } else {
Jing Huangf8ceafd2009-09-25 12:29:54 -0700753 return sizeof(struct fc_rnid_acc_s) -
754 sizeof(struct fc_rnid_general_topology_data_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700755 }
756
757}
758
759u16
760fc_rpsc_build(struct fchs_s *fchs, struct fc_rpsc_cmd_s *rpsc, u32 d_id,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700761 u32 s_id, u16 ox_id)
Jing Huang7725ccf2009-09-23 17:46:15 -0700762{
763 fc_els_req_build(fchs, d_id, s_id, ox_id);
764
Jing Huang6a18b162010-10-18 17:08:54 -0700765 memset(rpsc, 0, sizeof(struct fc_rpsc_cmd_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700766
767 rpsc->els_cmd.els_code = FC_ELS_RPSC;
Jing Huangf8ceafd2009-09-25 12:29:54 -0700768 return sizeof(struct fc_rpsc_cmd_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700769}
770
771u16
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700772fc_rpsc2_build(struct fchs_s *fchs, struct fc_rpsc2_cmd_s *rpsc2, u32 d_id,
773 u32 s_id, u32 *pid_list, u16 npids)
Jing Huang7725ccf2009-09-23 17:46:15 -0700774{
Maggie Zhangf16a1752010-12-09 19:12:32 -0800775 u32 dctlr_id = FC_DOMAIN_CTRLR(bfa_hton3b(d_id));
Jing Huang7725ccf2009-09-23 17:46:15 -0700776 int i = 0;
777
Maggie Zhangf16a1752010-12-09 19:12:32 -0800778 fc_els_req_build(fchs, bfa_hton3b(dctlr_id), s_id, 0);
Jing Huang7725ccf2009-09-23 17:46:15 -0700779
Jing Huang6a18b162010-10-18 17:08:54 -0700780 memset(rpsc2, 0, sizeof(struct fc_rpsc2_cmd_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700781
782 rpsc2->els_cmd.els_code = FC_ELS_RPSC;
Jing Huangba816ea2010-10-18 17:10:50 -0700783 rpsc2->token = cpu_to_be32(FC_BRCD_TOKEN);
784 rpsc2->num_pids = cpu_to_be16(npids);
Jing Huang7725ccf2009-09-23 17:46:15 -0700785 for (i = 0; i < npids; i++)
786 rpsc2->pid_list[i].pid = pid_list[i];
787
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700788 return sizeof(struct fc_rpsc2_cmd_s) + ((npids - 1) * (sizeof(u32)));
Jing Huang7725ccf2009-09-23 17:46:15 -0700789}
790
791u16
792fc_rpsc_acc_build(struct fchs_s *fchs, struct fc_rpsc_acc_s *rpsc_acc,
Maggie50444a32010-11-29 18:26:32 -0800793 u32 d_id, u32 s_id, __be16 ox_id,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700794 struct fc_rpsc_speed_info_s *oper_speed)
Jing Huang7725ccf2009-09-23 17:46:15 -0700795{
Jing Huang6a18b162010-10-18 17:08:54 -0700796 memset(rpsc_acc, 0, sizeof(struct fc_rpsc_acc_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700797
798 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
799
800 rpsc_acc->command = FC_ELS_ACC;
Jing Huangba816ea2010-10-18 17:10:50 -0700801 rpsc_acc->num_entries = cpu_to_be16(1);
Jing Huang7725ccf2009-09-23 17:46:15 -0700802
803 rpsc_acc->speed_info[0].port_speed_cap =
Jing Huangba816ea2010-10-18 17:10:50 -0700804 cpu_to_be16(oper_speed->port_speed_cap);
Jing Huang7725ccf2009-09-23 17:46:15 -0700805
806 rpsc_acc->speed_info[0].port_op_speed =
Jing Huangba816ea2010-10-18 17:10:50 -0700807 cpu_to_be16(oper_speed->port_op_speed);
Jing Huang7725ccf2009-09-23 17:46:15 -0700808
Jing Huangf8ceafd2009-09-25 12:29:54 -0700809 return sizeof(struct fc_rpsc_acc_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700810}
811
Jing Huang7725ccf2009-09-23 17:46:15 -0700812u16
813fc_logo_rsp_parse(struct fchs_s *fchs, int len)
814{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700815 struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
Jing Huang7725ccf2009-09-23 17:46:15 -0700816
817 len = len;
818 if (els_cmd->els_code != FC_ELS_ACC)
819 return FC_PARSE_FAILURE;
820
821 return FC_PARSE_OK;
822}
823
824u16
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700825fc_pdisc_build(struct fchs_s *fchs, u32 d_id, u32 s_id, u16 ox_id,
826 wwn_t port_name, wwn_t node_name, u16 pdu_size)
Jing Huang7725ccf2009-09-23 17:46:15 -0700827{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700828 struct fc_logi_s *pdisc = (struct fc_logi_s *) (fchs + 1);
Jing Huang7725ccf2009-09-23 17:46:15 -0700829
Jing Huang6a18b162010-10-18 17:08:54 -0700830 memcpy(pdisc, &plogi_tmpl, sizeof(struct fc_logi_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700831
832 pdisc->els_cmd.els_code = FC_ELS_PDISC;
833 fc_els_req_build(fchs, d_id, s_id, ox_id);
834
Jing Huangba816ea2010-10-18 17:10:50 -0700835 pdisc->csp.rxsz = pdisc->class3.rxsz = cpu_to_be16(pdu_size);
Jing Huang7725ccf2009-09-23 17:46:15 -0700836 pdisc->port_name = port_name;
837 pdisc->node_name = node_name;
838
Jing Huangf8ceafd2009-09-25 12:29:54 -0700839 return sizeof(struct fc_logi_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700840}
841
842u16
843fc_pdisc_rsp_parse(struct fchs_s *fchs, int len, wwn_t port_name)
844{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700845 struct fc_logi_s *pdisc = (struct fc_logi_s *) (fchs + 1);
Jing Huang7725ccf2009-09-23 17:46:15 -0700846
847 if (len < sizeof(struct fc_logi_s))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700848 return FC_PARSE_LEN_INVAL;
Jing Huang7725ccf2009-09-23 17:46:15 -0700849
850 if (pdisc->els_cmd.els_code != FC_ELS_ACC)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700851 return FC_PARSE_ACC_INVAL;
Jing Huang7725ccf2009-09-23 17:46:15 -0700852
853 if (!wwn_is_equal(pdisc->port_name, port_name))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700854 return FC_PARSE_PWWN_NOT_EQUAL;
Jing Huang7725ccf2009-09-23 17:46:15 -0700855
856 if (!pdisc->class3.class_valid)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700857 return FC_PARSE_NWWN_NOT_EQUAL;
Jing Huang7725ccf2009-09-23 17:46:15 -0700858
Jing Huangba816ea2010-10-18 17:10:50 -0700859 if (be16_to_cpu(pdisc->class3.rxsz) < (FC_MIN_PDUSZ))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700860 return FC_PARSE_RXSZ_INVAL;
Jing Huang7725ccf2009-09-23 17:46:15 -0700861
Jing Huangf8ceafd2009-09-25 12:29:54 -0700862 return FC_PARSE_OK;
Jing Huang7725ccf2009-09-23 17:46:15 -0700863}
864
865u16
866fc_prlo_build(struct fchs_s *fchs, u32 d_id, u32 s_id, u16 ox_id,
867 int num_pages)
868{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700869 struct fc_prlo_s *prlo = (struct fc_prlo_s *) (fchs + 1);
Jing Huang7725ccf2009-09-23 17:46:15 -0700870 int page;
871
872 fc_els_req_build(fchs, d_id, s_id, ox_id);
Jing Huang6a18b162010-10-18 17:08:54 -0700873 memset(prlo, 0, (num_pages * 16) + 4);
Jing Huang7725ccf2009-09-23 17:46:15 -0700874 prlo->command = FC_ELS_PRLO;
875 prlo->page_len = 0x10;
Jing Huangba816ea2010-10-18 17:10:50 -0700876 prlo->payload_len = cpu_to_be16((num_pages * 16) + 4);
Jing Huang7725ccf2009-09-23 17:46:15 -0700877
878 for (page = 0; page < num_pages; page++) {
879 prlo->prlo_params[page].type = FC_TYPE_FCP;
880 prlo->prlo_params[page].opa_valid = 0;
881 prlo->prlo_params[page].rpa_valid = 0;
882 prlo->prlo_params[page].orig_process_assc = 0;
883 prlo->prlo_params[page].resp_process_assc = 0;
884 }
885
Jing Huangba816ea2010-10-18 17:10:50 -0700886 return be16_to_cpu(prlo->payload_len);
Jing Huang7725ccf2009-09-23 17:46:15 -0700887}
888
889u16
890fc_prlo_rsp_parse(struct fchs_s *fchs, int len)
891{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700892 struct fc_prlo_acc_s *prlo = (struct fc_prlo_acc_s *) (fchs + 1);
Jing Huang7725ccf2009-09-23 17:46:15 -0700893 int num_pages = 0;
894 int page = 0;
895
896 len = len;
897
898 if (prlo->command != FC_ELS_ACC)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700899 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700900
Jing Huangba816ea2010-10-18 17:10:50 -0700901 num_pages = ((be16_to_cpu(prlo->payload_len)) - 4) / 16;
Jing Huang7725ccf2009-09-23 17:46:15 -0700902
903 for (page = 0; page < num_pages; page++) {
904 if (prlo->prlo_acc_params[page].type != FC_TYPE_FCP)
905 return FC_PARSE_FAILURE;
906
907 if (prlo->prlo_acc_params[page].opa_valid != 0)
908 return FC_PARSE_FAILURE;
909
910 if (prlo->prlo_acc_params[page].rpa_valid != 0)
911 return FC_PARSE_FAILURE;
912
913 if (prlo->prlo_acc_params[page].orig_process_assc != 0)
914 return FC_PARSE_FAILURE;
915
916 if (prlo->prlo_acc_params[page].resp_process_assc != 0)
917 return FC_PARSE_FAILURE;
918 }
Jing Huangf8ceafd2009-09-25 12:29:54 -0700919 return FC_PARSE_OK;
Jing Huang7725ccf2009-09-23 17:46:15 -0700920
921}
922
923u16
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700924fc_tprlo_build(struct fchs_s *fchs, u32 d_id, u32 s_id, u16 ox_id,
925 int num_pages, enum fc_tprlo_type tprlo_type, u32 tpr_id)
Jing Huang7725ccf2009-09-23 17:46:15 -0700926{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700927 struct fc_tprlo_s *tprlo = (struct fc_tprlo_s *) (fchs + 1);
Jing Huang7725ccf2009-09-23 17:46:15 -0700928 int page;
929
930 fc_els_req_build(fchs, d_id, s_id, ox_id);
Jing Huang6a18b162010-10-18 17:08:54 -0700931 memset(tprlo, 0, (num_pages * 16) + 4);
Jing Huang7725ccf2009-09-23 17:46:15 -0700932 tprlo->command = FC_ELS_TPRLO;
933 tprlo->page_len = 0x10;
Jing Huangba816ea2010-10-18 17:10:50 -0700934 tprlo->payload_len = cpu_to_be16((num_pages * 16) + 4);
Jing Huang7725ccf2009-09-23 17:46:15 -0700935
936 for (page = 0; page < num_pages; page++) {
937 tprlo->tprlo_params[page].type = FC_TYPE_FCP;
938 tprlo->tprlo_params[page].opa_valid = 0;
939 tprlo->tprlo_params[page].rpa_valid = 0;
940 tprlo->tprlo_params[page].orig_process_assc = 0;
941 tprlo->tprlo_params[page].resp_process_assc = 0;
942 if (tprlo_type == FC_GLOBAL_LOGO) {
943 tprlo->tprlo_params[page].global_process_logout = 1;
944 } else if (tprlo_type == FC_TPR_LOGO) {
945 tprlo->tprlo_params[page].tpo_nport_valid = 1;
946 tprlo->tprlo_params[page].tpo_nport_id = (tpr_id);
947 }
948 }
949
Jing Huangba816ea2010-10-18 17:10:50 -0700950 return be16_to_cpu(tprlo->payload_len);
Jing Huang7725ccf2009-09-23 17:46:15 -0700951}
952
953u16
954fc_tprlo_rsp_parse(struct fchs_s *fchs, int len)
955{
956 struct fc_tprlo_acc_s *tprlo = (struct fc_tprlo_acc_s *) (fchs + 1);
957 int num_pages = 0;
958 int page = 0;
959
960 len = len;
961
962 if (tprlo->command != FC_ELS_ACC)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700963 return FC_PARSE_ACC_INVAL;
Jing Huang7725ccf2009-09-23 17:46:15 -0700964
Jing Huangba816ea2010-10-18 17:10:50 -0700965 num_pages = (be16_to_cpu(tprlo->payload_len) - 4) / 16;
Jing Huang7725ccf2009-09-23 17:46:15 -0700966
967 for (page = 0; page < num_pages; page++) {
968 if (tprlo->tprlo_acc_params[page].type != FC_TYPE_FCP)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700969 return FC_PARSE_NOT_FCP;
Jing Huang7725ccf2009-09-23 17:46:15 -0700970 if (tprlo->tprlo_acc_params[page].opa_valid != 0)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700971 return FC_PARSE_OPAFLAG_INVAL;
Jing Huang7725ccf2009-09-23 17:46:15 -0700972 if (tprlo->tprlo_acc_params[page].rpa_valid != 0)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700973 return FC_PARSE_RPAFLAG_INVAL;
Jing Huang7725ccf2009-09-23 17:46:15 -0700974 if (tprlo->tprlo_acc_params[page].orig_process_assc != 0)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700975 return FC_PARSE_OPA_INVAL;
Jing Huang7725ccf2009-09-23 17:46:15 -0700976 if (tprlo->tprlo_acc_params[page].resp_process_assc != 0)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700977 return FC_PARSE_RPA_INVAL;
Jing Huang7725ccf2009-09-23 17:46:15 -0700978 }
Jing Huangf8ceafd2009-09-25 12:29:54 -0700979 return FC_PARSE_OK;
Jing Huang7725ccf2009-09-23 17:46:15 -0700980}
981
982enum fc_parse_status
983fc_rrq_rsp_parse(struct fchs_s *fchs, int len)
984{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700985 struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
Jing Huang7725ccf2009-09-23 17:46:15 -0700986
987 len = len;
988 if (els_cmd->els_code != FC_ELS_ACC)
989 return FC_PARSE_FAILURE;
990
991 return FC_PARSE_OK;
992}
993
994u16
Maggie50444a32010-11-29 18:26:32 -0800995fc_ba_rjt_build(struct fchs_s *fchs, u32 d_id, u32 s_id, __be16 ox_id,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700996 u32 reason_code, u32 reason_expl)
Jing Huang7725ccf2009-09-23 17:46:15 -0700997{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700998 struct fc_ba_rjt_s *ba_rjt = (struct fc_ba_rjt_s *) (fchs + 1);
Jing Huang7725ccf2009-09-23 17:46:15 -0700999
1000 fc_bls_rsp_build(fchs, d_id, s_id, ox_id);
1001
1002 fchs->cat_info = FC_CAT_BA_RJT;
1003 ba_rjt->reason_code = reason_code;
1004 ba_rjt->reason_expl = reason_expl;
Jing Huangf8ceafd2009-09-25 12:29:54 -07001005 return sizeof(struct fc_ba_rjt_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001006}
1007
1008static void
1009fc_gs_cthdr_build(struct ct_hdr_s *cthdr, u32 s_id, u16 cmd_code)
1010{
Jing Huang6a18b162010-10-18 17:08:54 -07001011 memset(cthdr, 0, sizeof(struct ct_hdr_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001012 cthdr->rev_id = CT_GS3_REVISION;
1013 cthdr->gs_type = CT_GSTYPE_DIRSERVICE;
1014 cthdr->gs_sub_type = CT_GSSUBTYPE_NAMESERVER;
Jing Huangba816ea2010-10-18 17:10:50 -07001015 cthdr->cmd_rsp_code = cpu_to_be16(cmd_code);
Jing Huang7725ccf2009-09-23 17:46:15 -07001016}
1017
1018static void
1019fc_gs_fdmi_cthdr_build(struct ct_hdr_s *cthdr, u32 s_id, u16 cmd_code)
1020{
Jing Huang6a18b162010-10-18 17:08:54 -07001021 memset(cthdr, 0, sizeof(struct ct_hdr_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001022 cthdr->rev_id = CT_GS3_REVISION;
1023 cthdr->gs_type = CT_GSTYPE_MGMTSERVICE;
1024 cthdr->gs_sub_type = CT_GSSUBTYPE_HBA_MGMTSERVER;
Jing Huangba816ea2010-10-18 17:10:50 -07001025 cthdr->cmd_rsp_code = cpu_to_be16(cmd_code);
Jing Huang7725ccf2009-09-23 17:46:15 -07001026}
1027
1028static void
1029fc_gs_ms_cthdr_build(struct ct_hdr_s *cthdr, u32 s_id, u16 cmd_code,
1030 u8 sub_type)
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_MGMTSERVICE;
1035 cthdr->gs_sub_type = sub_type;
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
1039u16
1040fc_gidpn_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
1041 wwn_t port_name)
1042{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001043 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1044 struct fcgs_gidpn_req_s *gidpn = (struct fcgs_gidpn_req_s *)(cthdr + 1);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001045 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001046
1047 fc_gs_fchdr_build(fchs, d_id, s_id, ox_id);
1048 fc_gs_cthdr_build(cthdr, s_id, GS_GID_PN);
1049
Jing Huang6a18b162010-10-18 17:08:54 -07001050 memset(gidpn, 0, sizeof(struct fcgs_gidpn_req_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001051 gidpn->port_name = port_name;
Jing Huangf8ceafd2009-09-25 12:29:54 -07001052 return sizeof(struct fcgs_gidpn_req_s) + sizeof(struct ct_hdr_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001053}
1054
1055u16
1056fc_gpnid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
1057 u32 port_id)
1058{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001059 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
Jing Huang7725ccf2009-09-23 17:46:15 -07001060 fcgs_gpnid_req_t *gpnid = (fcgs_gpnid_req_t *) (cthdr + 1);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001061 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001062
1063 fc_gs_fchdr_build(fchs, d_id, s_id, ox_id);
1064 fc_gs_cthdr_build(cthdr, s_id, GS_GPN_ID);
1065
Jing Huang6a18b162010-10-18 17:08:54 -07001066 memset(gpnid, 0, sizeof(fcgs_gpnid_req_t));
Jing Huang7725ccf2009-09-23 17:46:15 -07001067 gpnid->dap = port_id;
Jing Huangf8ceafd2009-09-25 12:29:54 -07001068 return sizeof(fcgs_gpnid_req_t) + sizeof(struct ct_hdr_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001069}
1070
1071u16
1072fc_gnnid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
1073 u32 port_id)
1074{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001075 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
Jing Huang7725ccf2009-09-23 17:46:15 -07001076 fcgs_gnnid_req_t *gnnid = (fcgs_gnnid_req_t *) (cthdr + 1);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001077 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001078
1079 fc_gs_fchdr_build(fchs, d_id, s_id, ox_id);
1080 fc_gs_cthdr_build(cthdr, s_id, GS_GNN_ID);
1081
Jing Huang6a18b162010-10-18 17:08:54 -07001082 memset(gnnid, 0, sizeof(fcgs_gnnid_req_t));
Jing Huang7725ccf2009-09-23 17:46:15 -07001083 gnnid->dap = port_id;
Jing Huangf8ceafd2009-09-25 12:29:54 -07001084 return sizeof(fcgs_gnnid_req_t) + sizeof(struct ct_hdr_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001085}
1086
1087u16
1088fc_ct_rsp_parse(struct ct_hdr_s *cthdr)
1089{
Jing Huangba816ea2010-10-18 17:10:50 -07001090 if (be16_to_cpu(cthdr->cmd_rsp_code) != CT_RSP_ACCEPT) {
Jing Huang7725ccf2009-09-23 17:46:15 -07001091 if (cthdr->reason_code == CT_RSN_LOGICAL_BUSY)
1092 return FC_PARSE_BUSY;
1093 else
1094 return FC_PARSE_FAILURE;
1095 }
1096
1097 return FC_PARSE_OK;
1098}
1099
1100u16
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001101fc_scr_build(struct fchs_s *fchs, struct fc_scr_s *scr,
1102 u8 set_br_reg, u32 s_id, u16 ox_id)
Jing Huang7725ccf2009-09-23 17:46:15 -07001103{
Maggie Zhangf16a1752010-12-09 19:12:32 -08001104 u32 d_id = bfa_hton3b(FC_FABRIC_CONTROLLER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001105
1106 fc_els_req_build(fchs, d_id, s_id, ox_id);
1107
Jing Huang6a18b162010-10-18 17:08:54 -07001108 memset(scr, 0, sizeof(struct fc_scr_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001109 scr->command = FC_ELS_SCR;
1110 scr->reg_func = FC_SCR_REG_FUNC_FULL;
1111 if (set_br_reg)
1112 scr->vu_reg_func = FC_VU_SCR_REG_FUNC_FABRIC_NAME_CHANGE;
1113
Jing Huangf8ceafd2009-09-25 12:29:54 -07001114 return sizeof(struct fc_scr_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001115}
1116
1117u16
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001118fc_rscn_build(struct fchs_s *fchs, struct fc_rscn_pl_s *rscn,
1119 u32 s_id, u16 ox_id)
Jing Huang7725ccf2009-09-23 17:46:15 -07001120{
Maggie Zhangf16a1752010-12-09 19:12:32 -08001121 u32 d_id = bfa_hton3b(FC_FABRIC_CONTROLLER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001122 u16 payldlen;
1123
1124 fc_els_req_build(fchs, d_id, s_id, ox_id);
1125 rscn->command = FC_ELS_RSCN;
1126 rscn->pagelen = sizeof(rscn->event[0]);
1127
1128 payldlen = sizeof(u32) + rscn->pagelen;
Jing Huangba816ea2010-10-18 17:10:50 -07001129 rscn->payldlen = cpu_to_be16(payldlen);
Jing Huang7725ccf2009-09-23 17:46:15 -07001130
1131 rscn->event[0].format = FC_RSCN_FORMAT_PORTID;
1132 rscn->event[0].portid = s_id;
1133
Jing Huangf8ceafd2009-09-25 12:29:54 -07001134 return sizeof(struct fc_rscn_pl_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001135}
1136
1137u16
1138fc_rftid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001139 enum bfa_lport_role roles)
Jing Huang7725ccf2009-09-23 17:46:15 -07001140{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001141 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1142 struct fcgs_rftid_req_s *rftid = (struct fcgs_rftid_req_s *)(cthdr + 1);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001143 u32 type_value, d_id = bfa_hton3b(FC_NAME_SERVER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001144 u8 index;
1145
1146 fc_gs_fchdr_build(fchs, d_id, s_id, ox_id);
1147 fc_gs_cthdr_build(cthdr, s_id, GS_RFT_ID);
1148
Jing Huang6a18b162010-10-18 17:08:54 -07001149 memset(rftid, 0, sizeof(struct fcgs_rftid_req_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001150
1151 rftid->dap = s_id;
1152
1153 /* By default, FCP FC4 Type is registered */
1154 index = FC_TYPE_FCP >> 5;
1155 type_value = 1 << (FC_TYPE_FCP % 32);
Jing Huangba816ea2010-10-18 17:10:50 -07001156 rftid->fc4_type[index] = cpu_to_be32(type_value);
Jing Huang7725ccf2009-09-23 17:46:15 -07001157
Jing Huangf8ceafd2009-09-25 12:29:54 -07001158 return sizeof(struct fcgs_rftid_req_s) + sizeof(struct ct_hdr_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001159}
1160
1161u16
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001162fc_rftid_build_sol(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
1163 u8 *fc4_bitmap, u32 bitmap_size)
Jing Huang7725ccf2009-09-23 17:46:15 -07001164{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001165 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1166 struct fcgs_rftid_req_s *rftid = (struct fcgs_rftid_req_s *)(cthdr + 1);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001167 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001168
1169 fc_gs_fchdr_build(fchs, d_id, s_id, ox_id);
1170 fc_gs_cthdr_build(cthdr, s_id, GS_RFT_ID);
1171
Jing Huang6a18b162010-10-18 17:08:54 -07001172 memset(rftid, 0, sizeof(struct fcgs_rftid_req_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001173
1174 rftid->dap = s_id;
Jing Huang6a18b162010-10-18 17:08:54 -07001175 memcpy((void *)rftid->fc4_type, (void *)fc4_bitmap,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001176 (bitmap_size < 32 ? bitmap_size : 32));
Jing Huang7725ccf2009-09-23 17:46:15 -07001177
Jing Huangf8ceafd2009-09-25 12:29:54 -07001178 return sizeof(struct fcgs_rftid_req_s) + sizeof(struct ct_hdr_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001179}
1180
1181u16
1182fc_rffid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
1183 u8 fc4_type, u8 fc4_ftrs)
1184{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001185 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1186 struct fcgs_rffid_req_s *rffid = (struct fcgs_rffid_req_s *)(cthdr + 1);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001187 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001188
1189 fc_gs_fchdr_build(fchs, d_id, s_id, ox_id);
1190 fc_gs_cthdr_build(cthdr, s_id, GS_RFF_ID);
1191
Jing Huang6a18b162010-10-18 17:08:54 -07001192 memset(rffid, 0, sizeof(struct fcgs_rffid_req_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001193
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001194 rffid->dap = s_id;
Jing Huang7725ccf2009-09-23 17:46:15 -07001195 rffid->fc4ftr_bits = fc4_ftrs;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001196 rffid->fc4_type = fc4_type;
Jing Huang7725ccf2009-09-23 17:46:15 -07001197
Jing Huangf8ceafd2009-09-25 12:29:54 -07001198 return sizeof(struct fcgs_rffid_req_s) + sizeof(struct ct_hdr_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001199}
1200
1201u16
1202fc_rspnid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
1203 u8 *name)
1204{
1205
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001206 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
Jing Huang7725ccf2009-09-23 17:46:15 -07001207 struct fcgs_rspnid_req_s *rspnid =
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001208 (struct fcgs_rspnid_req_s *)(cthdr + 1);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001209 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001210
1211 fc_gs_fchdr_build(fchs, d_id, s_id, ox_id);
1212 fc_gs_cthdr_build(cthdr, s_id, GS_RSPN_ID);
1213
Jing Huang6a18b162010-10-18 17:08:54 -07001214 memset(rspnid, 0, sizeof(struct fcgs_rspnid_req_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001215
1216 rspnid->dap = s_id;
1217 rspnid->spn_len = (u8) strlen((char *)name);
1218 strncpy((char *)rspnid->spn, (char *)name, rspnid->spn_len);
1219
Jing Huangf8ceafd2009-09-25 12:29:54 -07001220 return sizeof(struct fcgs_rspnid_req_s) + sizeof(struct ct_hdr_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001221}
1222
1223u16
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001224fc_gid_ft_build(struct fchs_s *fchs, void *pyld, u32 s_id, u8 fc4_type)
Jing Huang7725ccf2009-09-23 17:46:15 -07001225{
1226
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001227 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1228 struct fcgs_gidft_req_s *gidft = (struct fcgs_gidft_req_s *)(cthdr + 1);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001229 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001230
1231 fc_gs_fchdr_build(fchs, d_id, s_id, 0);
1232
1233 fc_gs_cthdr_build(cthdr, s_id, GS_GID_FT);
1234
Jing Huang6a18b162010-10-18 17:08:54 -07001235 memset(gidft, 0, sizeof(struct fcgs_gidft_req_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001236 gidft->fc4_type = fc4_type;
1237 gidft->domain_id = 0;
1238 gidft->area_id = 0;
1239
Jing Huangf8ceafd2009-09-25 12:29:54 -07001240 return sizeof(struct fcgs_gidft_req_s) + sizeof(struct ct_hdr_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001241}
1242
1243u16
1244fc_rpnid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u32 port_id,
1245 wwn_t port_name)
1246{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001247 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1248 struct fcgs_rpnid_req_s *rpnid = (struct fcgs_rpnid_req_s *)(cthdr + 1);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001249 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001250
1251 fc_gs_fchdr_build(fchs, d_id, s_id, 0);
1252 fc_gs_cthdr_build(cthdr, s_id, GS_RPN_ID);
1253
Jing Huang6a18b162010-10-18 17:08:54 -07001254 memset(rpnid, 0, sizeof(struct fcgs_rpnid_req_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001255 rpnid->port_id = port_id;
1256 rpnid->port_name = port_name;
1257
Jing Huangf8ceafd2009-09-25 12:29:54 -07001258 return sizeof(struct fcgs_rpnid_req_s) + sizeof(struct ct_hdr_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001259}
1260
1261u16
1262fc_rnnid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u32 port_id,
1263 wwn_t node_name)
1264{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001265 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1266 struct fcgs_rnnid_req_s *rnnid = (struct fcgs_rnnid_req_s *)(cthdr + 1);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001267 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001268
1269 fc_gs_fchdr_build(fchs, d_id, s_id, 0);
1270 fc_gs_cthdr_build(cthdr, s_id, GS_RNN_ID);
1271
Jing Huang6a18b162010-10-18 17:08:54 -07001272 memset(rnnid, 0, sizeof(struct fcgs_rnnid_req_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001273 rnnid->port_id = port_id;
1274 rnnid->node_name = node_name;
1275
Jing Huangf8ceafd2009-09-25 12:29:54 -07001276 return sizeof(struct fcgs_rnnid_req_s) + sizeof(struct ct_hdr_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001277}
1278
1279u16
1280fc_rcsid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u32 port_id,
1281 u32 cos)
1282{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001283 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
Jing Huang7725ccf2009-09-23 17:46:15 -07001284 struct fcgs_rcsid_req_s *rcsid =
1285 (struct fcgs_rcsid_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 fc_gs_cthdr_build(cthdr, s_id, GS_RCS_ID);
1290
Jing Huang6a18b162010-10-18 17:08:54 -07001291 memset(rcsid, 0, sizeof(struct fcgs_rcsid_req_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001292 rcsid->port_id = port_id;
1293 rcsid->cos = cos;
1294
Jing Huangf8ceafd2009-09-25 12:29:54 -07001295 return sizeof(struct fcgs_rcsid_req_s) + sizeof(struct ct_hdr_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001296}
1297
1298u16
1299fc_rptid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u32 port_id,
1300 u8 port_type)
1301{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001302 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1303 struct fcgs_rptid_req_s *rptid = (struct fcgs_rptid_req_s *)(cthdr + 1);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001304 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001305
1306 fc_gs_fchdr_build(fchs, d_id, s_id, 0);
1307 fc_gs_cthdr_build(cthdr, s_id, GS_RPT_ID);
1308
Jing Huang6a18b162010-10-18 17:08:54 -07001309 memset(rptid, 0, sizeof(struct fcgs_rptid_req_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001310 rptid->port_id = port_id;
1311 rptid->port_type = port_type;
1312
Jing Huangf8ceafd2009-09-25 12:29:54 -07001313 return sizeof(struct fcgs_rptid_req_s) + sizeof(struct ct_hdr_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001314}
1315
1316u16
1317fc_ganxt_build(struct fchs_s *fchs, void *pyld, u32 s_id, u32 port_id)
1318{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001319 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1320 struct fcgs_ganxt_req_s *ganxt = (struct fcgs_ganxt_req_s *)(cthdr + 1);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001321 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001322
1323 fc_gs_fchdr_build(fchs, d_id, s_id, 0);
1324 fc_gs_cthdr_build(cthdr, s_id, GS_GA_NXT);
1325
Jing Huang6a18b162010-10-18 17:08:54 -07001326 memset(ganxt, 0, sizeof(struct fcgs_ganxt_req_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001327 ganxt->port_id = port_id;
1328
Jing Huangf8ceafd2009-09-25 12:29:54 -07001329 return sizeof(struct ct_hdr_s) + sizeof(struct fcgs_ganxt_req_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001330}
1331
1332/*
1333 * Builds fc hdr and ct hdr for FDMI requests.
1334 */
1335u16
1336fc_fdmi_reqhdr_build(struct fchs_s *fchs, void *pyld, u32 s_id,
1337 u16 cmd_code)
1338{
1339
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001340 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
Maggie Zhangf16a1752010-12-09 19:12:32 -08001341 u32 d_id = bfa_hton3b(FC_MGMT_SERVER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001342
1343 fc_gs_fchdr_build(fchs, d_id, s_id, 0);
1344 fc_gs_fdmi_cthdr_build(cthdr, s_id, cmd_code);
1345
Jing Huangf8ceafd2009-09-25 12:29:54 -07001346 return sizeof(struct ct_hdr_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001347}
1348
1349/*
1350 * Given a FC4 Type, this function returns a fc4 type bitmask
1351 */
1352void
1353fc_get_fc4type_bitmask(u8 fc4_type, u8 *bit_mask)
1354{
1355 u8 index;
Maggie50444a32010-11-29 18:26:32 -08001356 __be32 *ptr = (__be32 *) bit_mask;
Jing Huang7725ccf2009-09-23 17:46:15 -07001357 u32 type_value;
1358
1359 /*
1360 * @todo : Check for bitmask size
1361 */
1362
1363 index = fc4_type >> 5;
1364 type_value = 1 << (fc4_type % 32);
Jing Huangba816ea2010-10-18 17:10:50 -07001365 ptr[index] = cpu_to_be32(type_value);
Jing Huang7725ccf2009-09-23 17:46:15 -07001366
1367}
1368
1369/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001370 * GMAL Request
Jing Huang7725ccf2009-09-23 17:46:15 -07001371 */
1372u16
1373fc_gmal_req_build(struct fchs_s *fchs, void *pyld, u32 s_id, wwn_t wwn)
1374{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001375 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
Jing Huang7725ccf2009-09-23 17:46:15 -07001376 fcgs_gmal_req_t *gmal = (fcgs_gmal_req_t *) (cthdr + 1);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001377 u32 d_id = bfa_hton3b(FC_MGMT_SERVER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001378
1379 fc_gs_fchdr_build(fchs, d_id, s_id, 0);
1380 fc_gs_ms_cthdr_build(cthdr, s_id, GS_FC_GMAL_CMD,
1381 CT_GSSUBTYPE_CFGSERVER);
1382
Jing Huang6a18b162010-10-18 17:08:54 -07001383 memset(gmal, 0, sizeof(fcgs_gmal_req_t));
Jing Huang7725ccf2009-09-23 17:46:15 -07001384 gmal->wwn = wwn;
1385
Jing Huangf8ceafd2009-09-25 12:29:54 -07001386 return sizeof(struct ct_hdr_s) + sizeof(fcgs_gmal_req_t);
Jing Huang7725ccf2009-09-23 17:46:15 -07001387}
1388
1389/*
1390 * GFN (Get Fabric Name) Request
1391 */
1392u16
1393fc_gfn_req_build(struct fchs_s *fchs, void *pyld, u32 s_id, wwn_t wwn)
1394{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001395 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
Jing Huang7725ccf2009-09-23 17:46:15 -07001396 fcgs_gfn_req_t *gfn = (fcgs_gfn_req_t *) (cthdr + 1);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001397 u32 d_id = bfa_hton3b(FC_MGMT_SERVER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001398
1399 fc_gs_fchdr_build(fchs, d_id, s_id, 0);
1400 fc_gs_ms_cthdr_build(cthdr, s_id, GS_FC_GFN_CMD,
1401 CT_GSSUBTYPE_CFGSERVER);
1402
Jing Huang6a18b162010-10-18 17:08:54 -07001403 memset(gfn, 0, sizeof(fcgs_gfn_req_t));
Jing Huang7725ccf2009-09-23 17:46:15 -07001404 gfn->wwn = wwn;
1405
Jing Huangf8ceafd2009-09-25 12:29:54 -07001406 return sizeof(struct ct_hdr_s) + sizeof(fcgs_gfn_req_t);
Jing Huang7725ccf2009-09-23 17:46:15 -07001407}