blob: dce787f6cca2e421169e8f80b4f9a228b0f1bf4f [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
Krishna Gudipatid7be54c2011-06-24 20:24:52 -0700158static void
159fc_gsresp_fchdr_build(struct fchs_s *fchs, u32 d_id, u32 s_id, u16 ox_id)
160{
161 memset(fchs, 0, sizeof(struct fchs_s));
162
163 fchs->routing = FC_RTG_FC4_DEV_DATA;
164 fchs->cat_info = FC_CAT_SOLICIT_CTRL;
165 fchs->type = FC_TYPE_SERVICES;
166 fchs->f_ctl =
167 bfa_hton3b(FCTL_EC_RESP | FCTL_SEQ_INI | FCTL_LS_EXCH |
168 FCTL_END_SEQ | FCTL_SI_XFER);
169 fchs->d_id = d_id;
170 fchs->s_id = s_id;
171 fchs->ox_id = ox_id;
172}
173
Jing Huang7725ccf2009-09-23 17:46:15 -0700174void
Maggie50444a32010-11-29 18:26:32 -0800175fc_els_req_build(struct fchs_s *fchs, u32 d_id, u32 s_id, __be16 ox_id)
Jing Huang7725ccf2009-09-23 17:46:15 -0700176{
Jing Huang6a18b162010-10-18 17:08:54 -0700177 memcpy(fchs, &fc_els_req_tmpl, sizeof(struct fchs_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700178 fchs->d_id = (d_id);
179 fchs->s_id = (s_id);
Jing Huangba816ea2010-10-18 17:10:50 -0700180 fchs->ox_id = cpu_to_be16(ox_id);
Jing Huang7725ccf2009-09-23 17:46:15 -0700181}
182
183static void
Maggie50444a32010-11-29 18:26:32 -0800184fc_els_rsp_build(struct fchs_s *fchs, u32 d_id, u32 s_id, __be16 ox_id)
Jing Huang7725ccf2009-09-23 17:46:15 -0700185{
Jing Huang6a18b162010-10-18 17:08:54 -0700186 memcpy(fchs, &fc_els_rsp_tmpl, sizeof(struct fchs_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700187 fchs->d_id = d_id;
188 fchs->s_id = s_id;
189 fchs->ox_id = ox_id;
190}
191
192enum fc_parse_status
193fc_els_rsp_parse(struct fchs_s *fchs, int len)
194{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700195 struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
196 struct fc_ls_rjt_s *ls_rjt = (struct fc_ls_rjt_s *) els_cmd;
Jing Huang7725ccf2009-09-23 17:46:15 -0700197
198 len = len;
199
200 switch (els_cmd->els_code) {
201 case FC_ELS_LS_RJT:
202 if (ls_rjt->reason_code == FC_LS_RJT_RSN_LOGICAL_BUSY)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700203 return FC_PARSE_BUSY;
Jing Huang7725ccf2009-09-23 17:46:15 -0700204 else
Jing Huangf8ceafd2009-09-25 12:29:54 -0700205 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700206
207 case FC_ELS_ACC:
Jing Huangf8ceafd2009-09-25 12:29:54 -0700208 return FC_PARSE_OK;
Jing Huang7725ccf2009-09-23 17:46:15 -0700209 }
Jing Huangf8ceafd2009-09-25 12:29:54 -0700210 return FC_PARSE_OK;
Jing Huang7725ccf2009-09-23 17:46:15 -0700211}
212
213static void
Maggie50444a32010-11-29 18:26:32 -0800214fc_bls_rsp_build(struct fchs_s *fchs, u32 d_id, u32 s_id, __be16 ox_id)
Jing Huang7725ccf2009-09-23 17:46:15 -0700215{
Jing Huang6a18b162010-10-18 17:08:54 -0700216 memcpy(fchs, &fc_bls_rsp_tmpl, sizeof(struct fchs_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700217 fchs->d_id = d_id;
218 fchs->s_id = s_id;
219 fchs->ox_id = ox_id;
220}
221
222static u16
223fc_plogi_x_build(struct fchs_s *fchs, void *pld, u32 d_id, u32 s_id,
Maggie50444a32010-11-29 18:26:32 -0800224 __be16 ox_id, wwn_t port_name, wwn_t node_name,
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700225 u16 pdu_size, u16 bb_cr, u8 els_code)
Jing Huang7725ccf2009-09-23 17:46:15 -0700226{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700227 struct fc_logi_s *plogi = (struct fc_logi_s *) (pld);
Jing Huang7725ccf2009-09-23 17:46:15 -0700228
Jing Huang6a18b162010-10-18 17:08:54 -0700229 memcpy(plogi, &plogi_tmpl, sizeof(struct fc_logi_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700230
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -0700231 /* For FC AL bb_cr is 0 and altbbcred is 1 */
232 if (!bb_cr)
233 plogi->csp.altbbcred = 1;
234
Jing Huang7725ccf2009-09-23 17:46:15 -0700235 plogi->els_cmd.els_code = els_code;
236 if (els_code == FC_ELS_PLOGI)
237 fc_els_req_build(fchs, d_id, s_id, ox_id);
238 else
239 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
240
Jing Huangba816ea2010-10-18 17:10:50 -0700241 plogi->csp.rxsz = plogi->class3.rxsz = cpu_to_be16(pdu_size);
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700242 plogi->csp.bbcred = cpu_to_be16(bb_cr);
Jing Huang7725ccf2009-09-23 17:46:15 -0700243
Jing Huang6a18b162010-10-18 17:08:54 -0700244 memcpy(&plogi->port_name, &port_name, sizeof(wwn_t));
245 memcpy(&plogi->node_name, &node_name, sizeof(wwn_t));
Jing Huang7725ccf2009-09-23 17:46:15 -0700246
Jing Huangf8ceafd2009-09-25 12:29:54 -0700247 return sizeof(struct fc_logi_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700248}
249
250u16
251fc_flogi_build(struct fchs_s *fchs, struct fc_logi_s *flogi, u32 s_id,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700252 u16 ox_id, wwn_t port_name, wwn_t node_name, u16 pdu_size,
253 u8 set_npiv, u8 set_auth, u16 local_bb_credits)
Jing Huang7725ccf2009-09-23 17:46:15 -0700254{
Maggie Zhangf16a1752010-12-09 19:12:32 -0800255 u32 d_id = bfa_hton3b(FC_FABRIC_PORT);
Maggie50444a32010-11-29 18:26:32 -0800256 __be32 *vvl_info;
Jing Huang7725ccf2009-09-23 17:46:15 -0700257
Jing Huang6a18b162010-10-18 17:08:54 -0700258 memcpy(flogi, &plogi_tmpl, sizeof(struct fc_logi_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700259
260 flogi->els_cmd.els_code = FC_ELS_FLOGI;
261 fc_els_req_build(fchs, d_id, s_id, ox_id);
262
Jing Huangba816ea2010-10-18 17:10:50 -0700263 flogi->csp.rxsz = flogi->class3.rxsz = cpu_to_be16(pdu_size);
Jing Huang7725ccf2009-09-23 17:46:15 -0700264 flogi->port_name = port_name;
265 flogi->node_name = node_name;
266
267 /*
268 * Set the NPIV Capability Bit ( word 1, bit 31) of Common
269 * Service Parameters.
270 */
271 flogi->csp.ciro = set_npiv;
272
273 /* set AUTH capability */
274 flogi->csp.security = set_auth;
275
Jing Huangba816ea2010-10-18 17:10:50 -0700276 flogi->csp.bbcred = cpu_to_be16(local_bb_credits);
Jing Huang7725ccf2009-09-23 17:46:15 -0700277
278 /* Set brcd token in VVL */
279 vvl_info = (u32 *)&flogi->vvl[0];
280
281 /* set the flag to indicate the presence of VVL */
282 flogi->csp.npiv_supp = 1; /* @todo. field name is not correct */
Jing Huangba816ea2010-10-18 17:10:50 -0700283 vvl_info[0] = cpu_to_be32(FLOGI_VVL_BRCD);
Jing Huang7725ccf2009-09-23 17:46:15 -0700284
Jing Huangf8ceafd2009-09-25 12:29:54 -0700285 return sizeof(struct fc_logi_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700286}
287
288u16
289fc_flogi_acc_build(struct fchs_s *fchs, struct fc_logi_s *flogi, u32 s_id,
Maggie50444a32010-11-29 18:26:32 -0800290 __be16 ox_id, wwn_t port_name, wwn_t node_name,
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700291 u16 pdu_size, u16 local_bb_credits, u8 bb_scn)
Jing Huang7725ccf2009-09-23 17:46:15 -0700292{
293 u32 d_id = 0;
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700294 u16 bbscn_rxsz = (bb_scn << 12) | pdu_size;
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 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
298
299 flogi->els_cmd.els_code = FC_ELS_ACC;
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700300 flogi->class3.rxsz = cpu_to_be16(pdu_size);
301 flogi->csp.rxsz = cpu_to_be16(bbscn_rxsz); /* bb_scn/rxsz */
Jing Huang7725ccf2009-09-23 17:46:15 -0700302 flogi->port_name = port_name;
303 flogi->node_name = node_name;
304
Jing Huangba816ea2010-10-18 17:10:50 -0700305 flogi->csp.bbcred = cpu_to_be16(local_bb_credits);
Jing Huang7725ccf2009-09-23 17:46:15 -0700306
Jing Huangf8ceafd2009-09-25 12:29:54 -0700307 return sizeof(struct fc_logi_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700308}
309
310u16
311fc_fdisc_build(struct fchs_s *fchs, struct fc_logi_s *flogi, u32 s_id,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700312 u16 ox_id, wwn_t port_name, wwn_t node_name, u16 pdu_size)
Jing Huang7725ccf2009-09-23 17:46:15 -0700313{
Maggie Zhangf16a1752010-12-09 19:12:32 -0800314 u32 d_id = bfa_hton3b(FC_FABRIC_PORT);
Jing Huang7725ccf2009-09-23 17:46:15 -0700315
Jing Huang6a18b162010-10-18 17:08:54 -0700316 memcpy(flogi, &plogi_tmpl, sizeof(struct fc_logi_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700317
318 flogi->els_cmd.els_code = FC_ELS_FDISC;
319 fc_els_req_build(fchs, d_id, s_id, ox_id);
320
Jing Huangba816ea2010-10-18 17:10:50 -0700321 flogi->csp.rxsz = flogi->class3.rxsz = cpu_to_be16(pdu_size);
Jing Huang7725ccf2009-09-23 17:46:15 -0700322 flogi->port_name = port_name;
323 flogi->node_name = node_name;
324
Jing Huangf8ceafd2009-09-25 12:29:54 -0700325 return sizeof(struct fc_logi_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700326}
327
328u16
329fc_plogi_build(struct fchs_s *fchs, void *pld, u32 d_id, u32 s_id,
330 u16 ox_id, wwn_t port_name, wwn_t node_name,
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700331 u16 pdu_size, u16 bb_cr)
Jing Huang7725ccf2009-09-23 17:46:15 -0700332{
333 return fc_plogi_x_build(fchs, pld, d_id, s_id, ox_id, port_name,
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700334 node_name, pdu_size, bb_cr, FC_ELS_PLOGI);
Jing Huang7725ccf2009-09-23 17:46:15 -0700335}
336
337u16
338fc_plogi_acc_build(struct fchs_s *fchs, void *pld, u32 d_id, u32 s_id,
339 u16 ox_id, wwn_t port_name, wwn_t node_name,
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700340 u16 pdu_size, u16 bb_cr)
Jing Huang7725ccf2009-09-23 17:46:15 -0700341{
342 return fc_plogi_x_build(fchs, pld, d_id, s_id, ox_id, port_name,
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700343 node_name, pdu_size, bb_cr, FC_ELS_ACC);
Jing Huang7725ccf2009-09-23 17:46:15 -0700344}
345
346enum fc_parse_status
347fc_plogi_rsp_parse(struct fchs_s *fchs, int len, wwn_t port_name)
348{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700349 struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
350 struct fc_logi_s *plogi;
351 struct fc_ls_rjt_s *ls_rjt;
Jing Huang7725ccf2009-09-23 17:46:15 -0700352
353 switch (els_cmd->els_code) {
354 case FC_ELS_LS_RJT:
355 ls_rjt = (struct fc_ls_rjt_s *) (fchs + 1);
356 if (ls_rjt->reason_code == FC_LS_RJT_RSN_LOGICAL_BUSY)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700357 return FC_PARSE_BUSY;
Jing Huang7725ccf2009-09-23 17:46:15 -0700358 else
Jing Huangf8ceafd2009-09-25 12:29:54 -0700359 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700360 case FC_ELS_ACC:
361 plogi = (struct fc_logi_s *) (fchs + 1);
362 if (len < sizeof(struct fc_logi_s))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700363 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700364
365 if (!wwn_is_equal(plogi->port_name, port_name))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700366 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700367
368 if (!plogi->class3.class_valid)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700369 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700370
Jing Huangba816ea2010-10-18 17:10:50 -0700371 if (be16_to_cpu(plogi->class3.rxsz) < (FC_MIN_PDUSZ))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700372 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700373
Jing Huangf8ceafd2009-09-25 12:29:54 -0700374 return FC_PARSE_OK;
Jing Huang7725ccf2009-09-23 17:46:15 -0700375 default:
Jing Huangf8ceafd2009-09-25 12:29:54 -0700376 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700377 }
378}
379
380enum fc_parse_status
381fc_plogi_parse(struct fchs_s *fchs)
382{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700383 struct fc_logi_s *plogi = (struct fc_logi_s *) (fchs + 1);
Jing Huang7725ccf2009-09-23 17:46:15 -0700384
385 if (plogi->class3.class_valid != 1)
386 return FC_PARSE_FAILURE;
387
Jing Huangba816ea2010-10-18 17:10:50 -0700388 if ((be16_to_cpu(plogi->class3.rxsz) < FC_MIN_PDUSZ)
389 || (be16_to_cpu(plogi->class3.rxsz) > FC_MAX_PDUSZ)
Jing Huang7725ccf2009-09-23 17:46:15 -0700390 || (plogi->class3.rxsz == 0))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700391 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700392
393 return FC_PARSE_OK;
394}
395
396u16
397fc_prli_build(struct fchs_s *fchs, void *pld, u32 d_id, u32 s_id,
398 u16 ox_id)
399{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700400 struct fc_prli_s *prli = (struct fc_prli_s *) (pld);
Jing Huang7725ccf2009-09-23 17:46:15 -0700401
402 fc_els_req_build(fchs, d_id, s_id, ox_id);
Jing Huang6a18b162010-10-18 17:08:54 -0700403 memcpy(prli, &prli_tmpl, sizeof(struct fc_prli_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700404
405 prli->command = FC_ELS_PRLI;
406 prli->parampage.servparams.initiator = 1;
407 prli->parampage.servparams.retry = 1;
408 prli->parampage.servparams.rec_support = 1;
409 prli->parampage.servparams.task_retry_id = 0;
410 prli->parampage.servparams.confirm = 1;
411
Jing Huangf8ceafd2009-09-25 12:29:54 -0700412 return sizeof(struct fc_prli_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700413}
414
415u16
416fc_prli_acc_build(struct fchs_s *fchs, void *pld, u32 d_id, u32 s_id,
Maggie50444a32010-11-29 18:26:32 -0800417 __be16 ox_id, enum bfa_lport_role role)
Jing Huang7725ccf2009-09-23 17:46:15 -0700418{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700419 struct fc_prli_s *prli = (struct fc_prli_s *) (pld);
Jing Huang7725ccf2009-09-23 17:46:15 -0700420
421 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
Jing Huang6a18b162010-10-18 17:08:54 -0700422 memcpy(prli, &prli_tmpl, sizeof(struct fc_prli_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700423
424 prli->command = FC_ELS_ACC;
425
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700426 prli->parampage.servparams.initiator = 1;
Jing Huang7725ccf2009-09-23 17:46:15 -0700427
428 prli->parampage.rspcode = FC_PRLI_ACC_XQTD;
429
Jing Huangf8ceafd2009-09-25 12:29:54 -0700430 return sizeof(struct fc_prli_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700431}
432
433enum fc_parse_status
434fc_prli_rsp_parse(struct fc_prli_s *prli, int len)
435{
436 if (len < sizeof(struct fc_prli_s))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700437 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700438
439 if (prli->command != FC_ELS_ACC)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700440 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700441
442 if ((prli->parampage.rspcode != FC_PRLI_ACC_XQTD)
443 && (prli->parampage.rspcode != FC_PRLI_ACC_PREDEF_IMG))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700444 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700445
446 if (prli->parampage.servparams.target != 1)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700447 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700448
Jing Huangf8ceafd2009-09-25 12:29:54 -0700449 return FC_PARSE_OK;
Jing Huang7725ccf2009-09-23 17:46:15 -0700450}
451
452enum fc_parse_status
453fc_prli_parse(struct fc_prli_s *prli)
454{
455 if (prli->parampage.type != FC_TYPE_FCP)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700456 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700457
458 if (!prli->parampage.imagepair)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700459 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700460
461 if (!prli->parampage.servparams.initiator)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700462 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700463
Jing Huangf8ceafd2009-09-25 12:29:54 -0700464 return FC_PARSE_OK;
Jing Huang7725ccf2009-09-23 17:46:15 -0700465}
466
467u16
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700468fc_logo_build(struct fchs_s *fchs, struct fc_logo_s *logo, u32 d_id, u32 s_id,
469 u16 ox_id, wwn_t port_name)
Jing Huang7725ccf2009-09-23 17:46:15 -0700470{
471 fc_els_req_build(fchs, d_id, s_id, ox_id);
472
Jing Huang6a18b162010-10-18 17:08:54 -0700473 memset(logo, '\0', sizeof(struct fc_logo_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700474 logo->els_cmd.els_code = FC_ELS_LOGO;
475 logo->nport_id = (s_id);
476 logo->orig_port_name = port_name;
477
Jing Huangf8ceafd2009-09-25 12:29:54 -0700478 return sizeof(struct fc_logo_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700479}
480
Maggie Zhangda99dcc2010-12-09 19:13:20 -0800481static u16
Jing Huang7725ccf2009-09-23 17:46:15 -0700482fc_adisc_x_build(struct fchs_s *fchs, struct fc_adisc_s *adisc, u32 d_id,
Maggie50444a32010-11-29 18:26:32 -0800483 u32 s_id, __be16 ox_id, wwn_t port_name,
Jing Huang7725ccf2009-09-23 17:46:15 -0700484 wwn_t node_name, u8 els_code)
485{
Jing Huang6a18b162010-10-18 17:08:54 -0700486 memset(adisc, '\0', sizeof(struct fc_adisc_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700487
488 adisc->els_cmd.els_code = els_code;
489
490 if (els_code == FC_ELS_ADISC)
491 fc_els_req_build(fchs, d_id, s_id, ox_id);
492 else
493 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
494
495 adisc->orig_HA = 0;
496 adisc->orig_port_name = port_name;
497 adisc->orig_node_name = node_name;
498 adisc->nport_id = (s_id);
499
Jing Huangf8ceafd2009-09-25 12:29:54 -0700500 return sizeof(struct fc_adisc_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700501}
502
503u16
504fc_adisc_build(struct fchs_s *fchs, struct fc_adisc_s *adisc, u32 d_id,
Maggie50444a32010-11-29 18:26:32 -0800505 u32 s_id, __be16 ox_id, wwn_t port_name, wwn_t node_name)
Jing Huang7725ccf2009-09-23 17:46:15 -0700506{
507 return fc_adisc_x_build(fchs, adisc, d_id, s_id, ox_id, port_name,
508 node_name, FC_ELS_ADISC);
509}
510
511u16
512fc_adisc_acc_build(struct fchs_s *fchs, struct fc_adisc_s *adisc, u32 d_id,
Maggie50444a32010-11-29 18:26:32 -0800513 u32 s_id, __be16 ox_id, wwn_t port_name,
Jing Huang7725ccf2009-09-23 17:46:15 -0700514 wwn_t node_name)
515{
516 return fc_adisc_x_build(fchs, adisc, d_id, s_id, ox_id, port_name,
517 node_name, FC_ELS_ACC);
518}
519
520enum fc_parse_status
521fc_adisc_rsp_parse(struct fc_adisc_s *adisc, int len, wwn_t port_name,
522 wwn_t node_name)
523{
524
525 if (len < sizeof(struct fc_adisc_s))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700526 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700527
528 if (adisc->els_cmd.els_code != FC_ELS_ACC)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700529 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700530
531 if (!wwn_is_equal(adisc->orig_port_name, port_name))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700532 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700533
Jing Huangf8ceafd2009-09-25 12:29:54 -0700534 return FC_PARSE_OK;
Jing Huang7725ccf2009-09-23 17:46:15 -0700535}
536
537enum fc_parse_status
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700538fc_adisc_parse(struct fchs_s *fchs, void *pld, u32 host_dap, wwn_t node_name,
539 wwn_t port_name)
Jing Huang7725ccf2009-09-23 17:46:15 -0700540{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700541 struct fc_adisc_s *adisc = (struct fc_adisc_s *) pld;
Jing Huang7725ccf2009-09-23 17:46:15 -0700542
543 if (adisc->els_cmd.els_code != FC_ELS_ACC)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700544 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700545
546 if ((adisc->nport_id == (host_dap))
547 && wwn_is_equal(adisc->orig_port_name, port_name)
548 && wwn_is_equal(adisc->orig_node_name, node_name))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700549 return FC_PARSE_OK;
Jing Huang7725ccf2009-09-23 17:46:15 -0700550
Jing Huangf8ceafd2009-09-25 12:29:54 -0700551 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700552}
553
554enum fc_parse_status
555fc_pdisc_parse(struct fchs_s *fchs, wwn_t node_name, wwn_t port_name)
556{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700557 struct fc_logi_s *pdisc = (struct fc_logi_s *) (fchs + 1);
Jing Huang7725ccf2009-09-23 17:46:15 -0700558
559 if (pdisc->class3.class_valid != 1)
560 return FC_PARSE_FAILURE;
561
Jing Huangba816ea2010-10-18 17:10:50 -0700562 if ((be16_to_cpu(pdisc->class3.rxsz) <
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700563 (FC_MIN_PDUSZ - sizeof(struct fchs_s)))
Jing Huang7725ccf2009-09-23 17:46:15 -0700564 || (pdisc->class3.rxsz == 0))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700565 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700566
567 if (!wwn_is_equal(pdisc->port_name, port_name))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700568 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700569
570 if (!wwn_is_equal(pdisc->node_name, node_name))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700571 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700572
573 return FC_PARSE_OK;
574}
575
576u16
577fc_abts_build(struct fchs_s *fchs, u32 d_id, u32 s_id, u16 ox_id)
578{
Jing Huang6a18b162010-10-18 17:08:54 -0700579 memcpy(fchs, &fc_bls_req_tmpl, sizeof(struct fchs_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700580 fchs->cat_info = FC_CAT_ABTS;
581 fchs->d_id = (d_id);
582 fchs->s_id = (s_id);
Jing Huangba816ea2010-10-18 17:10:50 -0700583 fchs->ox_id = cpu_to_be16(ox_id);
Jing Huang7725ccf2009-09-23 17:46:15 -0700584
Jing Huangf8ceafd2009-09-25 12:29:54 -0700585 return sizeof(struct fchs_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700586}
587
588enum fc_parse_status
589fc_abts_rsp_parse(struct fchs_s *fchs, int len)
590{
591 if ((fchs->cat_info == FC_CAT_BA_ACC)
592 || (fchs->cat_info == FC_CAT_BA_RJT))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700593 return FC_PARSE_OK;
Jing Huang7725ccf2009-09-23 17:46:15 -0700594
Jing Huangf8ceafd2009-09-25 12:29:54 -0700595 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700596}
597
598u16
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700599fc_rrq_build(struct fchs_s *fchs, struct fc_rrq_s *rrq, u32 d_id, u32 s_id,
600 u16 ox_id, u16 rrq_oxid)
Jing Huang7725ccf2009-09-23 17:46:15 -0700601{
602 fc_els_req_build(fchs, d_id, s_id, ox_id);
603
604 /*
605 * build rrq payload
606 */
Jing Huang6a18b162010-10-18 17:08:54 -0700607 memcpy(rrq, &rrq_tmpl, sizeof(struct fc_rrq_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700608 rrq->s_id = (s_id);
Jing Huangba816ea2010-10-18 17:10:50 -0700609 rrq->ox_id = cpu_to_be16(rrq_oxid);
Jing Huang7725ccf2009-09-23 17:46:15 -0700610 rrq->rx_id = FC_RXID_ANY;
611
Jing Huangf8ceafd2009-09-25 12:29:54 -0700612 return sizeof(struct fc_rrq_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700613}
614
615u16
616fc_logo_acc_build(struct fchs_s *fchs, void *pld, u32 d_id, u32 s_id,
Maggie50444a32010-11-29 18:26:32 -0800617 __be16 ox_id)
Jing Huang7725ccf2009-09-23 17:46:15 -0700618{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700619 struct fc_els_cmd_s *acc = pld;
Jing Huang7725ccf2009-09-23 17:46:15 -0700620
621 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
622
Jing Huang6a18b162010-10-18 17:08:54 -0700623 memset(acc, 0, sizeof(struct fc_els_cmd_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700624 acc->els_code = FC_ELS_ACC;
625
Jing Huangf8ceafd2009-09-25 12:29:54 -0700626 return sizeof(struct fc_els_cmd_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700627}
628
629u16
630fc_ls_rjt_build(struct fchs_s *fchs, struct fc_ls_rjt_s *ls_rjt, u32 d_id,
Maggie50444a32010-11-29 18:26:32 -0800631 u32 s_id, __be16 ox_id, u8 reason_code,
Jing Huang7725ccf2009-09-23 17:46:15 -0700632 u8 reason_code_expl)
633{
634 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
Jing Huang6a18b162010-10-18 17:08:54 -0700635 memset(ls_rjt, 0, sizeof(struct fc_ls_rjt_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700636
637 ls_rjt->els_cmd.els_code = FC_ELS_LS_RJT;
638 ls_rjt->reason_code = reason_code;
639 ls_rjt->reason_code_expl = reason_code_expl;
640 ls_rjt->vendor_unique = 0x00;
641
Jing Huangf8ceafd2009-09-25 12:29:54 -0700642 return sizeof(struct fc_ls_rjt_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700643}
644
645u16
646fc_ba_acc_build(struct fchs_s *fchs, struct fc_ba_acc_s *ba_acc, u32 d_id,
Maggie50444a32010-11-29 18:26:32 -0800647 u32 s_id, __be16 ox_id, u16 rx_id)
Jing Huang7725ccf2009-09-23 17:46:15 -0700648{
649 fc_bls_rsp_build(fchs, d_id, s_id, ox_id);
650
Jing Huang6a18b162010-10-18 17:08:54 -0700651 memcpy(ba_acc, &ba_acc_tmpl, sizeof(struct fc_ba_acc_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700652
653 fchs->rx_id = rx_id;
654
655 ba_acc->ox_id = fchs->ox_id;
656 ba_acc->rx_id = fchs->rx_id;
657
Jing Huangf8ceafd2009-09-25 12:29:54 -0700658 return sizeof(struct fc_ba_acc_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700659}
660
661u16
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700662fc_ls_acc_build(struct fchs_s *fchs, struct fc_els_cmd_s *els_cmd, u32 d_id,
Maggie50444a32010-11-29 18:26:32 -0800663 u32 s_id, __be16 ox_id)
Jing Huang7725ccf2009-09-23 17:46:15 -0700664{
665 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
Jing Huang6a18b162010-10-18 17:08:54 -0700666 memset(els_cmd, 0, sizeof(struct fc_els_cmd_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700667 els_cmd->els_code = FC_ELS_ACC;
668
Jing Huangf8ceafd2009-09-25 12:29:54 -0700669 return sizeof(struct fc_els_cmd_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700670}
671
672int
673fc_logout_params_pages(struct fchs_s *fc_frame, u8 els_code)
674{
675 int num_pages = 0;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700676 struct fc_prlo_s *prlo;
677 struct fc_tprlo_s *tprlo;
Jing Huang7725ccf2009-09-23 17:46:15 -0700678
679 if (els_code == FC_ELS_PRLO) {
680 prlo = (struct fc_prlo_s *) (fc_frame + 1);
Jing Huangba816ea2010-10-18 17:10:50 -0700681 num_pages = (be16_to_cpu(prlo->payload_len) - 4) / 16;
Jing Huang7725ccf2009-09-23 17:46:15 -0700682 } else {
683 tprlo = (struct fc_tprlo_s *) (fc_frame + 1);
Jing Huangba816ea2010-10-18 17:10:50 -0700684 num_pages = (be16_to_cpu(tprlo->payload_len) - 4) / 16;
Jing Huang7725ccf2009-09-23 17:46:15 -0700685 }
686 return num_pages;
687}
688
689u16
690fc_tprlo_acc_build(struct fchs_s *fchs, struct fc_tprlo_acc_s *tprlo_acc,
Maggie50444a32010-11-29 18:26:32 -0800691 u32 d_id, u32 s_id, __be16 ox_id, int num_pages)
Jing Huang7725ccf2009-09-23 17:46:15 -0700692{
693 int page;
694
695 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
696
Jing Huang6a18b162010-10-18 17:08:54 -0700697 memset(tprlo_acc, 0, (num_pages * 16) + 4);
Jing Huang7725ccf2009-09-23 17:46:15 -0700698 tprlo_acc->command = FC_ELS_ACC;
699
700 tprlo_acc->page_len = 0x10;
Jing Huangba816ea2010-10-18 17:10:50 -0700701 tprlo_acc->payload_len = cpu_to_be16((num_pages * 16) + 4);
Jing Huang7725ccf2009-09-23 17:46:15 -0700702
703 for (page = 0; page < num_pages; page++) {
704 tprlo_acc->tprlo_acc_params[page].opa_valid = 0;
705 tprlo_acc->tprlo_acc_params[page].rpa_valid = 0;
706 tprlo_acc->tprlo_acc_params[page].fc4type_csp = FC_TYPE_FCP;
707 tprlo_acc->tprlo_acc_params[page].orig_process_assc = 0;
708 tprlo_acc->tprlo_acc_params[page].resp_process_assc = 0;
709 }
Jing Huangba816ea2010-10-18 17:10:50 -0700710 return be16_to_cpu(tprlo_acc->payload_len);
Jing Huang7725ccf2009-09-23 17:46:15 -0700711}
712
713u16
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700714fc_prlo_acc_build(struct fchs_s *fchs, struct fc_prlo_acc_s *prlo_acc, u32 d_id,
Maggie50444a32010-11-29 18:26:32 -0800715 u32 s_id, __be16 ox_id, int num_pages)
Jing Huang7725ccf2009-09-23 17:46:15 -0700716{
717 int page;
718
719 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
720
Jing Huang6a18b162010-10-18 17:08:54 -0700721 memset(prlo_acc, 0, (num_pages * 16) + 4);
Jing Huang7725ccf2009-09-23 17:46:15 -0700722 prlo_acc->command = FC_ELS_ACC;
723 prlo_acc->page_len = 0x10;
Jing Huangba816ea2010-10-18 17:10:50 -0700724 prlo_acc->payload_len = cpu_to_be16((num_pages * 16) + 4);
Jing Huang7725ccf2009-09-23 17:46:15 -0700725
726 for (page = 0; page < num_pages; page++) {
727 prlo_acc->prlo_acc_params[page].opa_valid = 0;
728 prlo_acc->prlo_acc_params[page].rpa_valid = 0;
729 prlo_acc->prlo_acc_params[page].fc4type_csp = FC_TYPE_FCP;
730 prlo_acc->prlo_acc_params[page].orig_process_assc = 0;
731 prlo_acc->prlo_acc_params[page].resp_process_assc = 0;
732 }
733
Jing Huangba816ea2010-10-18 17:10:50 -0700734 return be16_to_cpu(prlo_acc->payload_len);
Jing Huang7725ccf2009-09-23 17:46:15 -0700735}
736
737u16
738fc_rnid_build(struct fchs_s *fchs, struct fc_rnid_cmd_s *rnid, u32 d_id,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700739 u32 s_id, u16 ox_id, u32 data_format)
Jing Huang7725ccf2009-09-23 17:46:15 -0700740{
741 fc_els_req_build(fchs, d_id, s_id, ox_id);
742
Jing Huang6a18b162010-10-18 17:08:54 -0700743 memset(rnid, 0, sizeof(struct fc_rnid_cmd_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700744
745 rnid->els_cmd.els_code = FC_ELS_RNID;
746 rnid->node_id_data_format = data_format;
747
Jing Huangf8ceafd2009-09-25 12:29:54 -0700748 return sizeof(struct fc_rnid_cmd_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700749}
750
751u16
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700752fc_rnid_acc_build(struct fchs_s *fchs, struct fc_rnid_acc_s *rnid_acc, u32 d_id,
Maggie50444a32010-11-29 18:26:32 -0800753 u32 s_id, __be16 ox_id, u32 data_format,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700754 struct fc_rnid_common_id_data_s *common_id_data,
755 struct fc_rnid_general_topology_data_s *gen_topo_data)
Jing Huang7725ccf2009-09-23 17:46:15 -0700756{
Jing Huang6a18b162010-10-18 17:08:54 -0700757 memset(rnid_acc, 0, sizeof(struct fc_rnid_acc_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700758
759 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
760
761 rnid_acc->els_cmd.els_code = FC_ELS_ACC;
762 rnid_acc->node_id_data_format = data_format;
763 rnid_acc->common_id_data_length =
764 sizeof(struct fc_rnid_common_id_data_s);
765 rnid_acc->common_id_data = *common_id_data;
766
767 if (data_format == RNID_NODEID_DATA_FORMAT_DISCOVERY) {
768 rnid_acc->specific_id_data_length =
769 sizeof(struct fc_rnid_general_topology_data_s);
Jing Huang6a18b162010-10-18 17:08:54 -0700770 rnid_acc->gen_topology_data = *gen_topo_data;
Jing Huangf8ceafd2009-09-25 12:29:54 -0700771 return sizeof(struct fc_rnid_acc_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700772 } else {
Jing Huangf8ceafd2009-09-25 12:29:54 -0700773 return sizeof(struct fc_rnid_acc_s) -
774 sizeof(struct fc_rnid_general_topology_data_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700775 }
776
777}
778
779u16
780fc_rpsc_build(struct fchs_s *fchs, struct fc_rpsc_cmd_s *rpsc, u32 d_id,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700781 u32 s_id, u16 ox_id)
Jing Huang7725ccf2009-09-23 17:46:15 -0700782{
783 fc_els_req_build(fchs, d_id, s_id, ox_id);
784
Jing Huang6a18b162010-10-18 17:08:54 -0700785 memset(rpsc, 0, sizeof(struct fc_rpsc_cmd_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700786
787 rpsc->els_cmd.els_code = FC_ELS_RPSC;
Jing Huangf8ceafd2009-09-25 12:29:54 -0700788 return sizeof(struct fc_rpsc_cmd_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700789}
790
791u16
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700792fc_rpsc2_build(struct fchs_s *fchs, struct fc_rpsc2_cmd_s *rpsc2, u32 d_id,
793 u32 s_id, u32 *pid_list, u16 npids)
Jing Huang7725ccf2009-09-23 17:46:15 -0700794{
Maggie Zhangf16a1752010-12-09 19:12:32 -0800795 u32 dctlr_id = FC_DOMAIN_CTRLR(bfa_hton3b(d_id));
Jing Huang7725ccf2009-09-23 17:46:15 -0700796 int i = 0;
797
Maggie Zhangf16a1752010-12-09 19:12:32 -0800798 fc_els_req_build(fchs, bfa_hton3b(dctlr_id), s_id, 0);
Jing Huang7725ccf2009-09-23 17:46:15 -0700799
Jing Huang6a18b162010-10-18 17:08:54 -0700800 memset(rpsc2, 0, sizeof(struct fc_rpsc2_cmd_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700801
802 rpsc2->els_cmd.els_code = FC_ELS_RPSC;
Jing Huangba816ea2010-10-18 17:10:50 -0700803 rpsc2->token = cpu_to_be32(FC_BRCD_TOKEN);
804 rpsc2->num_pids = cpu_to_be16(npids);
Jing Huang7725ccf2009-09-23 17:46:15 -0700805 for (i = 0; i < npids; i++)
806 rpsc2->pid_list[i].pid = pid_list[i];
807
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700808 return sizeof(struct fc_rpsc2_cmd_s) + ((npids - 1) * (sizeof(u32)));
Jing Huang7725ccf2009-09-23 17:46:15 -0700809}
810
811u16
812fc_rpsc_acc_build(struct fchs_s *fchs, struct fc_rpsc_acc_s *rpsc_acc,
Maggie50444a32010-11-29 18:26:32 -0800813 u32 d_id, u32 s_id, __be16 ox_id,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700814 struct fc_rpsc_speed_info_s *oper_speed)
Jing Huang7725ccf2009-09-23 17:46:15 -0700815{
Jing Huang6a18b162010-10-18 17:08:54 -0700816 memset(rpsc_acc, 0, sizeof(struct fc_rpsc_acc_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700817
818 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
819
820 rpsc_acc->command = FC_ELS_ACC;
Jing Huangba816ea2010-10-18 17:10:50 -0700821 rpsc_acc->num_entries = cpu_to_be16(1);
Jing Huang7725ccf2009-09-23 17:46:15 -0700822
823 rpsc_acc->speed_info[0].port_speed_cap =
Jing Huangba816ea2010-10-18 17:10:50 -0700824 cpu_to_be16(oper_speed->port_speed_cap);
Jing Huang7725ccf2009-09-23 17:46:15 -0700825
826 rpsc_acc->speed_info[0].port_op_speed =
Jing Huangba816ea2010-10-18 17:10:50 -0700827 cpu_to_be16(oper_speed->port_op_speed);
Jing Huang7725ccf2009-09-23 17:46:15 -0700828
Jing Huangf8ceafd2009-09-25 12:29:54 -0700829 return sizeof(struct fc_rpsc_acc_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700830}
831
Jing Huang7725ccf2009-09-23 17:46:15 -0700832u16
833fc_logo_rsp_parse(struct fchs_s *fchs, int len)
834{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700835 struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
Jing Huang7725ccf2009-09-23 17:46:15 -0700836
837 len = len;
838 if (els_cmd->els_code != FC_ELS_ACC)
839 return FC_PARSE_FAILURE;
840
841 return FC_PARSE_OK;
842}
843
844u16
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700845fc_pdisc_build(struct fchs_s *fchs, u32 d_id, u32 s_id, u16 ox_id,
846 wwn_t port_name, wwn_t node_name, u16 pdu_size)
Jing Huang7725ccf2009-09-23 17:46:15 -0700847{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700848 struct fc_logi_s *pdisc = (struct fc_logi_s *) (fchs + 1);
Jing Huang7725ccf2009-09-23 17:46:15 -0700849
Jing Huang6a18b162010-10-18 17:08:54 -0700850 memcpy(pdisc, &plogi_tmpl, sizeof(struct fc_logi_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700851
852 pdisc->els_cmd.els_code = FC_ELS_PDISC;
853 fc_els_req_build(fchs, d_id, s_id, ox_id);
854
Jing Huangba816ea2010-10-18 17:10:50 -0700855 pdisc->csp.rxsz = pdisc->class3.rxsz = cpu_to_be16(pdu_size);
Jing Huang7725ccf2009-09-23 17:46:15 -0700856 pdisc->port_name = port_name;
857 pdisc->node_name = node_name;
858
Jing Huangf8ceafd2009-09-25 12:29:54 -0700859 return sizeof(struct fc_logi_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700860}
861
862u16
863fc_pdisc_rsp_parse(struct fchs_s *fchs, int len, wwn_t port_name)
864{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700865 struct fc_logi_s *pdisc = (struct fc_logi_s *) (fchs + 1);
Jing Huang7725ccf2009-09-23 17:46:15 -0700866
867 if (len < sizeof(struct fc_logi_s))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700868 return FC_PARSE_LEN_INVAL;
Jing Huang7725ccf2009-09-23 17:46:15 -0700869
870 if (pdisc->els_cmd.els_code != FC_ELS_ACC)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700871 return FC_PARSE_ACC_INVAL;
Jing Huang7725ccf2009-09-23 17:46:15 -0700872
873 if (!wwn_is_equal(pdisc->port_name, port_name))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700874 return FC_PARSE_PWWN_NOT_EQUAL;
Jing Huang7725ccf2009-09-23 17:46:15 -0700875
876 if (!pdisc->class3.class_valid)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700877 return FC_PARSE_NWWN_NOT_EQUAL;
Jing Huang7725ccf2009-09-23 17:46:15 -0700878
Jing Huangba816ea2010-10-18 17:10:50 -0700879 if (be16_to_cpu(pdisc->class3.rxsz) < (FC_MIN_PDUSZ))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700880 return FC_PARSE_RXSZ_INVAL;
Jing Huang7725ccf2009-09-23 17:46:15 -0700881
Jing Huangf8ceafd2009-09-25 12:29:54 -0700882 return FC_PARSE_OK;
Jing Huang7725ccf2009-09-23 17:46:15 -0700883}
884
885u16
886fc_prlo_build(struct fchs_s *fchs, u32 d_id, u32 s_id, u16 ox_id,
887 int num_pages)
888{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700889 struct fc_prlo_s *prlo = (struct fc_prlo_s *) (fchs + 1);
Jing Huang7725ccf2009-09-23 17:46:15 -0700890 int page;
891
892 fc_els_req_build(fchs, d_id, s_id, ox_id);
Jing Huang6a18b162010-10-18 17:08:54 -0700893 memset(prlo, 0, (num_pages * 16) + 4);
Jing Huang7725ccf2009-09-23 17:46:15 -0700894 prlo->command = FC_ELS_PRLO;
895 prlo->page_len = 0x10;
Jing Huangba816ea2010-10-18 17:10:50 -0700896 prlo->payload_len = cpu_to_be16((num_pages * 16) + 4);
Jing Huang7725ccf2009-09-23 17:46:15 -0700897
898 for (page = 0; page < num_pages; page++) {
899 prlo->prlo_params[page].type = FC_TYPE_FCP;
900 prlo->prlo_params[page].opa_valid = 0;
901 prlo->prlo_params[page].rpa_valid = 0;
902 prlo->prlo_params[page].orig_process_assc = 0;
903 prlo->prlo_params[page].resp_process_assc = 0;
904 }
905
Jing Huangba816ea2010-10-18 17:10:50 -0700906 return be16_to_cpu(prlo->payload_len);
Jing Huang7725ccf2009-09-23 17:46:15 -0700907}
908
909u16
910fc_prlo_rsp_parse(struct fchs_s *fchs, int len)
911{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700912 struct fc_prlo_acc_s *prlo = (struct fc_prlo_acc_s *) (fchs + 1);
Jing Huang7725ccf2009-09-23 17:46:15 -0700913 int num_pages = 0;
914 int page = 0;
915
916 len = len;
917
918 if (prlo->command != FC_ELS_ACC)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700919 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700920
Jing Huangba816ea2010-10-18 17:10:50 -0700921 num_pages = ((be16_to_cpu(prlo->payload_len)) - 4) / 16;
Jing Huang7725ccf2009-09-23 17:46:15 -0700922
923 for (page = 0; page < num_pages; page++) {
924 if (prlo->prlo_acc_params[page].type != FC_TYPE_FCP)
925 return FC_PARSE_FAILURE;
926
927 if (prlo->prlo_acc_params[page].opa_valid != 0)
928 return FC_PARSE_FAILURE;
929
930 if (prlo->prlo_acc_params[page].rpa_valid != 0)
931 return FC_PARSE_FAILURE;
932
933 if (prlo->prlo_acc_params[page].orig_process_assc != 0)
934 return FC_PARSE_FAILURE;
935
936 if (prlo->prlo_acc_params[page].resp_process_assc != 0)
937 return FC_PARSE_FAILURE;
938 }
Jing Huangf8ceafd2009-09-25 12:29:54 -0700939 return FC_PARSE_OK;
Jing Huang7725ccf2009-09-23 17:46:15 -0700940
941}
942
943u16
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700944fc_tprlo_build(struct fchs_s *fchs, u32 d_id, u32 s_id, u16 ox_id,
945 int num_pages, enum fc_tprlo_type tprlo_type, u32 tpr_id)
Jing Huang7725ccf2009-09-23 17:46:15 -0700946{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700947 struct fc_tprlo_s *tprlo = (struct fc_tprlo_s *) (fchs + 1);
Jing Huang7725ccf2009-09-23 17:46:15 -0700948 int page;
949
950 fc_els_req_build(fchs, d_id, s_id, ox_id);
Jing Huang6a18b162010-10-18 17:08:54 -0700951 memset(tprlo, 0, (num_pages * 16) + 4);
Jing Huang7725ccf2009-09-23 17:46:15 -0700952 tprlo->command = FC_ELS_TPRLO;
953 tprlo->page_len = 0x10;
Jing Huangba816ea2010-10-18 17:10:50 -0700954 tprlo->payload_len = cpu_to_be16((num_pages * 16) + 4);
Jing Huang7725ccf2009-09-23 17:46:15 -0700955
956 for (page = 0; page < num_pages; page++) {
957 tprlo->tprlo_params[page].type = FC_TYPE_FCP;
958 tprlo->tprlo_params[page].opa_valid = 0;
959 tprlo->tprlo_params[page].rpa_valid = 0;
960 tprlo->tprlo_params[page].orig_process_assc = 0;
961 tprlo->tprlo_params[page].resp_process_assc = 0;
962 if (tprlo_type == FC_GLOBAL_LOGO) {
963 tprlo->tprlo_params[page].global_process_logout = 1;
964 } else if (tprlo_type == FC_TPR_LOGO) {
965 tprlo->tprlo_params[page].tpo_nport_valid = 1;
966 tprlo->tprlo_params[page].tpo_nport_id = (tpr_id);
967 }
968 }
969
Jing Huangba816ea2010-10-18 17:10:50 -0700970 return be16_to_cpu(tprlo->payload_len);
Jing Huang7725ccf2009-09-23 17:46:15 -0700971}
972
973u16
974fc_tprlo_rsp_parse(struct fchs_s *fchs, int len)
975{
976 struct fc_tprlo_acc_s *tprlo = (struct fc_tprlo_acc_s *) (fchs + 1);
977 int num_pages = 0;
978 int page = 0;
979
980 len = len;
981
982 if (tprlo->command != FC_ELS_ACC)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700983 return FC_PARSE_ACC_INVAL;
Jing Huang7725ccf2009-09-23 17:46:15 -0700984
Jing Huangba816ea2010-10-18 17:10:50 -0700985 num_pages = (be16_to_cpu(tprlo->payload_len) - 4) / 16;
Jing Huang7725ccf2009-09-23 17:46:15 -0700986
987 for (page = 0; page < num_pages; page++) {
988 if (tprlo->tprlo_acc_params[page].type != FC_TYPE_FCP)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700989 return FC_PARSE_NOT_FCP;
Jing Huang7725ccf2009-09-23 17:46:15 -0700990 if (tprlo->tprlo_acc_params[page].opa_valid != 0)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700991 return FC_PARSE_OPAFLAG_INVAL;
Jing Huang7725ccf2009-09-23 17:46:15 -0700992 if (tprlo->tprlo_acc_params[page].rpa_valid != 0)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700993 return FC_PARSE_RPAFLAG_INVAL;
Jing Huang7725ccf2009-09-23 17:46:15 -0700994 if (tprlo->tprlo_acc_params[page].orig_process_assc != 0)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700995 return FC_PARSE_OPA_INVAL;
Jing Huang7725ccf2009-09-23 17:46:15 -0700996 if (tprlo->tprlo_acc_params[page].resp_process_assc != 0)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700997 return FC_PARSE_RPA_INVAL;
Jing Huang7725ccf2009-09-23 17:46:15 -0700998 }
Jing Huangf8ceafd2009-09-25 12:29:54 -0700999 return FC_PARSE_OK;
Jing Huang7725ccf2009-09-23 17:46:15 -07001000}
1001
1002enum fc_parse_status
1003fc_rrq_rsp_parse(struct fchs_s *fchs, int len)
1004{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001005 struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
Jing Huang7725ccf2009-09-23 17:46:15 -07001006
1007 len = len;
1008 if (els_cmd->els_code != FC_ELS_ACC)
1009 return FC_PARSE_FAILURE;
1010
1011 return FC_PARSE_OK;
1012}
1013
1014u16
Maggie50444a32010-11-29 18:26:32 -08001015fc_ba_rjt_build(struct fchs_s *fchs, u32 d_id, u32 s_id, __be16 ox_id,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001016 u32 reason_code, u32 reason_expl)
Jing Huang7725ccf2009-09-23 17:46:15 -07001017{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001018 struct fc_ba_rjt_s *ba_rjt = (struct fc_ba_rjt_s *) (fchs + 1);
Jing Huang7725ccf2009-09-23 17:46:15 -07001019
1020 fc_bls_rsp_build(fchs, d_id, s_id, ox_id);
1021
1022 fchs->cat_info = FC_CAT_BA_RJT;
1023 ba_rjt->reason_code = reason_code;
1024 ba_rjt->reason_expl = reason_expl;
Jing Huangf8ceafd2009-09-25 12:29:54 -07001025 return sizeof(struct fc_ba_rjt_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001026}
1027
1028static void
1029fc_gs_cthdr_build(struct ct_hdr_s *cthdr, u32 s_id, u16 cmd_code)
1030{
Jing Huang6a18b162010-10-18 17:08:54 -07001031 memset(cthdr, 0, sizeof(struct ct_hdr_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001032 cthdr->rev_id = CT_GS3_REVISION;
1033 cthdr->gs_type = CT_GSTYPE_DIRSERVICE;
1034 cthdr->gs_sub_type = CT_GSSUBTYPE_NAMESERVER;
Jing Huangba816ea2010-10-18 17:10:50 -07001035 cthdr->cmd_rsp_code = cpu_to_be16(cmd_code);
Jing Huang7725ccf2009-09-23 17:46:15 -07001036}
1037
1038static void
1039fc_gs_fdmi_cthdr_build(struct ct_hdr_s *cthdr, u32 s_id, u16 cmd_code)
1040{
Jing Huang6a18b162010-10-18 17:08:54 -07001041 memset(cthdr, 0, sizeof(struct ct_hdr_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001042 cthdr->rev_id = CT_GS3_REVISION;
1043 cthdr->gs_type = CT_GSTYPE_MGMTSERVICE;
1044 cthdr->gs_sub_type = CT_GSSUBTYPE_HBA_MGMTSERVER;
Jing Huangba816ea2010-10-18 17:10:50 -07001045 cthdr->cmd_rsp_code = cpu_to_be16(cmd_code);
Jing Huang7725ccf2009-09-23 17:46:15 -07001046}
1047
1048static void
1049fc_gs_ms_cthdr_build(struct ct_hdr_s *cthdr, u32 s_id, u16 cmd_code,
1050 u8 sub_type)
1051{
Jing Huang6a18b162010-10-18 17:08:54 -07001052 memset(cthdr, 0, sizeof(struct ct_hdr_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001053 cthdr->rev_id = CT_GS3_REVISION;
1054 cthdr->gs_type = CT_GSTYPE_MGMTSERVICE;
1055 cthdr->gs_sub_type = sub_type;
Jing Huangba816ea2010-10-18 17:10:50 -07001056 cthdr->cmd_rsp_code = cpu_to_be16(cmd_code);
Jing Huang7725ccf2009-09-23 17:46:15 -07001057}
1058
1059u16
1060fc_gidpn_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
1061 wwn_t port_name)
1062{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001063 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1064 struct fcgs_gidpn_req_s *gidpn = (struct fcgs_gidpn_req_s *)(cthdr + 1);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001065 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001066
1067 fc_gs_fchdr_build(fchs, d_id, s_id, ox_id);
1068 fc_gs_cthdr_build(cthdr, s_id, GS_GID_PN);
1069
Jing Huang6a18b162010-10-18 17:08:54 -07001070 memset(gidpn, 0, sizeof(struct fcgs_gidpn_req_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001071 gidpn->port_name = port_name;
Jing Huangf8ceafd2009-09-25 12:29:54 -07001072 return sizeof(struct fcgs_gidpn_req_s) + sizeof(struct ct_hdr_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001073}
1074
1075u16
1076fc_gpnid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
1077 u32 port_id)
1078{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001079 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
Jing Huang7725ccf2009-09-23 17:46:15 -07001080 fcgs_gpnid_req_t *gpnid = (fcgs_gpnid_req_t *) (cthdr + 1);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001081 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001082
1083 fc_gs_fchdr_build(fchs, d_id, s_id, ox_id);
1084 fc_gs_cthdr_build(cthdr, s_id, GS_GPN_ID);
1085
Jing Huang6a18b162010-10-18 17:08:54 -07001086 memset(gpnid, 0, sizeof(fcgs_gpnid_req_t));
Jing Huang7725ccf2009-09-23 17:46:15 -07001087 gpnid->dap = port_id;
Jing Huangf8ceafd2009-09-25 12:29:54 -07001088 return sizeof(fcgs_gpnid_req_t) + sizeof(struct ct_hdr_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001089}
1090
1091u16
1092fc_gnnid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
1093 u32 port_id)
1094{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001095 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
Jing Huang7725ccf2009-09-23 17:46:15 -07001096 fcgs_gnnid_req_t *gnnid = (fcgs_gnnid_req_t *) (cthdr + 1);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001097 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001098
1099 fc_gs_fchdr_build(fchs, d_id, s_id, ox_id);
1100 fc_gs_cthdr_build(cthdr, s_id, GS_GNN_ID);
1101
Jing Huang6a18b162010-10-18 17:08:54 -07001102 memset(gnnid, 0, sizeof(fcgs_gnnid_req_t));
Jing Huang7725ccf2009-09-23 17:46:15 -07001103 gnnid->dap = port_id;
Jing Huangf8ceafd2009-09-25 12:29:54 -07001104 return sizeof(fcgs_gnnid_req_t) + sizeof(struct ct_hdr_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001105}
1106
1107u16
1108fc_ct_rsp_parse(struct ct_hdr_s *cthdr)
1109{
Jing Huangba816ea2010-10-18 17:10:50 -07001110 if (be16_to_cpu(cthdr->cmd_rsp_code) != CT_RSP_ACCEPT) {
Jing Huang7725ccf2009-09-23 17:46:15 -07001111 if (cthdr->reason_code == CT_RSN_LOGICAL_BUSY)
1112 return FC_PARSE_BUSY;
1113 else
1114 return FC_PARSE_FAILURE;
1115 }
1116
1117 return FC_PARSE_OK;
1118}
1119
1120u16
Krishna Gudipatid7be54c2011-06-24 20:24:52 -07001121fc_gs_rjt_build(struct fchs_s *fchs, struct ct_hdr_s *cthdr,
1122 u32 d_id, u32 s_id, u16 ox_id, u8 reason_code,
1123 u8 reason_code_expl)
1124{
1125 fc_gsresp_fchdr_build(fchs, d_id, s_id, ox_id);
1126
1127 cthdr->cmd_rsp_code = cpu_to_be16(CT_RSP_REJECT);
1128 cthdr->rev_id = CT_GS3_REVISION;
1129
1130 cthdr->reason_code = reason_code;
1131 cthdr->exp_code = reason_code_expl;
1132 return sizeof(struct ct_hdr_s);
1133}
1134
1135u16
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001136fc_scr_build(struct fchs_s *fchs, struct fc_scr_s *scr,
1137 u8 set_br_reg, u32 s_id, u16 ox_id)
Jing Huang7725ccf2009-09-23 17:46:15 -07001138{
Maggie Zhangf16a1752010-12-09 19:12:32 -08001139 u32 d_id = bfa_hton3b(FC_FABRIC_CONTROLLER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001140
1141 fc_els_req_build(fchs, d_id, s_id, ox_id);
1142
Jing Huang6a18b162010-10-18 17:08:54 -07001143 memset(scr, 0, sizeof(struct fc_scr_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001144 scr->command = FC_ELS_SCR;
1145 scr->reg_func = FC_SCR_REG_FUNC_FULL;
1146 if (set_br_reg)
1147 scr->vu_reg_func = FC_VU_SCR_REG_FUNC_FABRIC_NAME_CHANGE;
1148
Jing Huangf8ceafd2009-09-25 12:29:54 -07001149 return sizeof(struct fc_scr_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001150}
1151
1152u16
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001153fc_rscn_build(struct fchs_s *fchs, struct fc_rscn_pl_s *rscn,
1154 u32 s_id, u16 ox_id)
Jing Huang7725ccf2009-09-23 17:46:15 -07001155{
Maggie Zhangf16a1752010-12-09 19:12:32 -08001156 u32 d_id = bfa_hton3b(FC_FABRIC_CONTROLLER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001157 u16 payldlen;
1158
1159 fc_els_req_build(fchs, d_id, s_id, ox_id);
1160 rscn->command = FC_ELS_RSCN;
1161 rscn->pagelen = sizeof(rscn->event[0]);
1162
1163 payldlen = sizeof(u32) + rscn->pagelen;
Jing Huangba816ea2010-10-18 17:10:50 -07001164 rscn->payldlen = cpu_to_be16(payldlen);
Jing Huang7725ccf2009-09-23 17:46:15 -07001165
1166 rscn->event[0].format = FC_RSCN_FORMAT_PORTID;
1167 rscn->event[0].portid = s_id;
1168
Jing Huangf8ceafd2009-09-25 12:29:54 -07001169 return sizeof(struct fc_rscn_pl_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001170}
1171
1172u16
1173fc_rftid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001174 enum bfa_lport_role roles)
Jing Huang7725ccf2009-09-23 17:46:15 -07001175{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001176 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1177 struct fcgs_rftid_req_s *rftid = (struct fcgs_rftid_req_s *)(cthdr + 1);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001178 u32 type_value, d_id = bfa_hton3b(FC_NAME_SERVER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001179 u8 index;
1180
1181 fc_gs_fchdr_build(fchs, d_id, s_id, ox_id);
1182 fc_gs_cthdr_build(cthdr, s_id, GS_RFT_ID);
1183
Jing Huang6a18b162010-10-18 17:08:54 -07001184 memset(rftid, 0, sizeof(struct fcgs_rftid_req_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001185
1186 rftid->dap = s_id;
1187
1188 /* By default, FCP FC4 Type is registered */
1189 index = FC_TYPE_FCP >> 5;
1190 type_value = 1 << (FC_TYPE_FCP % 32);
Jing Huangba816ea2010-10-18 17:10:50 -07001191 rftid->fc4_type[index] = cpu_to_be32(type_value);
Jing Huang7725ccf2009-09-23 17:46:15 -07001192
Jing Huangf8ceafd2009-09-25 12:29:54 -07001193 return sizeof(struct fcgs_rftid_req_s) + sizeof(struct ct_hdr_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001194}
1195
1196u16
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001197fc_rftid_build_sol(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
1198 u8 *fc4_bitmap, u32 bitmap_size)
Jing Huang7725ccf2009-09-23 17:46:15 -07001199{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001200 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1201 struct fcgs_rftid_req_s *rftid = (struct fcgs_rftid_req_s *)(cthdr + 1);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001202 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001203
1204 fc_gs_fchdr_build(fchs, d_id, s_id, ox_id);
1205 fc_gs_cthdr_build(cthdr, s_id, GS_RFT_ID);
1206
Jing Huang6a18b162010-10-18 17:08:54 -07001207 memset(rftid, 0, sizeof(struct fcgs_rftid_req_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001208
1209 rftid->dap = s_id;
Jing Huang6a18b162010-10-18 17:08:54 -07001210 memcpy((void *)rftid->fc4_type, (void *)fc4_bitmap,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001211 (bitmap_size < 32 ? bitmap_size : 32));
Jing Huang7725ccf2009-09-23 17:46:15 -07001212
Jing Huangf8ceafd2009-09-25 12:29:54 -07001213 return sizeof(struct fcgs_rftid_req_s) + sizeof(struct ct_hdr_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001214}
1215
1216u16
1217fc_rffid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
1218 u8 fc4_type, u8 fc4_ftrs)
1219{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001220 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1221 struct fcgs_rffid_req_s *rffid = (struct fcgs_rffid_req_s *)(cthdr + 1);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001222 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001223
1224 fc_gs_fchdr_build(fchs, d_id, s_id, ox_id);
1225 fc_gs_cthdr_build(cthdr, s_id, GS_RFF_ID);
1226
Jing Huang6a18b162010-10-18 17:08:54 -07001227 memset(rffid, 0, sizeof(struct fcgs_rffid_req_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001228
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001229 rffid->dap = s_id;
Jing Huang7725ccf2009-09-23 17:46:15 -07001230 rffid->fc4ftr_bits = fc4_ftrs;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001231 rffid->fc4_type = fc4_type;
Jing Huang7725ccf2009-09-23 17:46:15 -07001232
Jing Huangf8ceafd2009-09-25 12:29:54 -07001233 return sizeof(struct fcgs_rffid_req_s) + sizeof(struct ct_hdr_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001234}
1235
1236u16
1237fc_rspnid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
1238 u8 *name)
1239{
1240
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001241 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
Jing Huang7725ccf2009-09-23 17:46:15 -07001242 struct fcgs_rspnid_req_s *rspnid =
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001243 (struct fcgs_rspnid_req_s *)(cthdr + 1);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001244 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001245
1246 fc_gs_fchdr_build(fchs, d_id, s_id, ox_id);
1247 fc_gs_cthdr_build(cthdr, s_id, GS_RSPN_ID);
1248
Jing Huang6a18b162010-10-18 17:08:54 -07001249 memset(rspnid, 0, sizeof(struct fcgs_rspnid_req_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001250
1251 rspnid->dap = s_id;
1252 rspnid->spn_len = (u8) strlen((char *)name);
1253 strncpy((char *)rspnid->spn, (char *)name, rspnid->spn_len);
1254
Jing Huangf8ceafd2009-09-25 12:29:54 -07001255 return sizeof(struct fcgs_rspnid_req_s) + sizeof(struct ct_hdr_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001256}
1257
1258u16
Krishna Gudipatice7242b2012-08-22 19:52:43 -07001259fc_rsnn_nn_build(struct fchs_s *fchs, void *pyld, u32 s_id,
1260 wwn_t node_name, u8 *name)
1261{
1262 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1263 struct fcgs_rsnn_nn_req_s *rsnn_nn =
1264 (struct fcgs_rsnn_nn_req_s *) (cthdr + 1);
1265 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
1266
1267 fc_gs_fchdr_build(fchs, d_id, s_id, 0);
1268 fc_gs_cthdr_build(cthdr, s_id, GS_RSNN_NN);
1269
1270 memset(rsnn_nn, 0, sizeof(struct fcgs_rsnn_nn_req_s));
1271
1272 rsnn_nn->node_name = node_name;
1273 rsnn_nn->snn_len = (u8) strlen((char *)name);
1274 strncpy((char *)rsnn_nn->snn, (char *)name, rsnn_nn->snn_len);
1275
1276 return sizeof(struct fcgs_rsnn_nn_req_s) + sizeof(struct ct_hdr_s);
1277}
1278
1279u16
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001280fc_gid_ft_build(struct fchs_s *fchs, void *pyld, u32 s_id, u8 fc4_type)
Jing Huang7725ccf2009-09-23 17:46:15 -07001281{
1282
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001283 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1284 struct fcgs_gidft_req_s *gidft = (struct fcgs_gidft_req_s *)(cthdr + 1);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001285 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001286
1287 fc_gs_fchdr_build(fchs, d_id, s_id, 0);
1288
1289 fc_gs_cthdr_build(cthdr, s_id, GS_GID_FT);
1290
Jing Huang6a18b162010-10-18 17:08:54 -07001291 memset(gidft, 0, sizeof(struct fcgs_gidft_req_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001292 gidft->fc4_type = fc4_type;
1293 gidft->domain_id = 0;
1294 gidft->area_id = 0;
1295
Jing Huangf8ceafd2009-09-25 12:29:54 -07001296 return sizeof(struct fcgs_gidft_req_s) + sizeof(struct ct_hdr_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001297}
1298
1299u16
1300fc_rpnid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u32 port_id,
1301 wwn_t port_name)
1302{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001303 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1304 struct fcgs_rpnid_req_s *rpnid = (struct fcgs_rpnid_req_s *)(cthdr + 1);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001305 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001306
1307 fc_gs_fchdr_build(fchs, d_id, s_id, 0);
1308 fc_gs_cthdr_build(cthdr, s_id, GS_RPN_ID);
1309
Jing Huang6a18b162010-10-18 17:08:54 -07001310 memset(rpnid, 0, sizeof(struct fcgs_rpnid_req_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001311 rpnid->port_id = port_id;
1312 rpnid->port_name = port_name;
1313
Jing Huangf8ceafd2009-09-25 12:29:54 -07001314 return sizeof(struct fcgs_rpnid_req_s) + sizeof(struct ct_hdr_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001315}
1316
1317u16
1318fc_rnnid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u32 port_id,
1319 wwn_t node_name)
1320{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001321 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1322 struct fcgs_rnnid_req_s *rnnid = (struct fcgs_rnnid_req_s *)(cthdr + 1);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001323 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001324
1325 fc_gs_fchdr_build(fchs, d_id, s_id, 0);
1326 fc_gs_cthdr_build(cthdr, s_id, GS_RNN_ID);
1327
Jing Huang6a18b162010-10-18 17:08:54 -07001328 memset(rnnid, 0, sizeof(struct fcgs_rnnid_req_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001329 rnnid->port_id = port_id;
1330 rnnid->node_name = node_name;
1331
Jing Huangf8ceafd2009-09-25 12:29:54 -07001332 return sizeof(struct fcgs_rnnid_req_s) + sizeof(struct ct_hdr_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001333}
1334
1335u16
1336fc_rcsid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u32 port_id,
1337 u32 cos)
1338{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001339 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
Jing Huang7725ccf2009-09-23 17:46:15 -07001340 struct fcgs_rcsid_req_s *rcsid =
1341 (struct fcgs_rcsid_req_s *) (cthdr + 1);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001342 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001343
1344 fc_gs_fchdr_build(fchs, d_id, s_id, 0);
1345 fc_gs_cthdr_build(cthdr, s_id, GS_RCS_ID);
1346
Jing Huang6a18b162010-10-18 17:08:54 -07001347 memset(rcsid, 0, sizeof(struct fcgs_rcsid_req_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001348 rcsid->port_id = port_id;
1349 rcsid->cos = cos;
1350
Jing Huangf8ceafd2009-09-25 12:29:54 -07001351 return sizeof(struct fcgs_rcsid_req_s) + sizeof(struct ct_hdr_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001352}
1353
1354u16
1355fc_rptid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u32 port_id,
1356 u8 port_type)
1357{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001358 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1359 struct fcgs_rptid_req_s *rptid = (struct fcgs_rptid_req_s *)(cthdr + 1);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001360 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001361
1362 fc_gs_fchdr_build(fchs, d_id, s_id, 0);
1363 fc_gs_cthdr_build(cthdr, s_id, GS_RPT_ID);
1364
Jing Huang6a18b162010-10-18 17:08:54 -07001365 memset(rptid, 0, sizeof(struct fcgs_rptid_req_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001366 rptid->port_id = port_id;
1367 rptid->port_type = port_type;
1368
Jing Huangf8ceafd2009-09-25 12:29:54 -07001369 return sizeof(struct fcgs_rptid_req_s) + sizeof(struct ct_hdr_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001370}
1371
1372u16
1373fc_ganxt_build(struct fchs_s *fchs, void *pyld, u32 s_id, u32 port_id)
1374{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001375 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1376 struct fcgs_ganxt_req_s *ganxt = (struct fcgs_ganxt_req_s *)(cthdr + 1);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001377 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001378
1379 fc_gs_fchdr_build(fchs, d_id, s_id, 0);
1380 fc_gs_cthdr_build(cthdr, s_id, GS_GA_NXT);
1381
Jing Huang6a18b162010-10-18 17:08:54 -07001382 memset(ganxt, 0, sizeof(struct fcgs_ganxt_req_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001383 ganxt->port_id = port_id;
1384
Jing Huangf8ceafd2009-09-25 12:29:54 -07001385 return sizeof(struct ct_hdr_s) + sizeof(struct fcgs_ganxt_req_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001386}
1387
1388/*
1389 * Builds fc hdr and ct hdr for FDMI requests.
1390 */
1391u16
1392fc_fdmi_reqhdr_build(struct fchs_s *fchs, void *pyld, u32 s_id,
1393 u16 cmd_code)
1394{
1395
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001396 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
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_fdmi_cthdr_build(cthdr, s_id, cmd_code);
1401
Jing Huangf8ceafd2009-09-25 12:29:54 -07001402 return sizeof(struct ct_hdr_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001403}
1404
1405/*
1406 * Given a FC4 Type, this function returns a fc4 type bitmask
1407 */
1408void
1409fc_get_fc4type_bitmask(u8 fc4_type, u8 *bit_mask)
1410{
1411 u8 index;
Maggie50444a32010-11-29 18:26:32 -08001412 __be32 *ptr = (__be32 *) bit_mask;
Jing Huang7725ccf2009-09-23 17:46:15 -07001413 u32 type_value;
1414
1415 /*
1416 * @todo : Check for bitmask size
1417 */
1418
1419 index = fc4_type >> 5;
1420 type_value = 1 << (fc4_type % 32);
Jing Huangba816ea2010-10-18 17:10:50 -07001421 ptr[index] = cpu_to_be32(type_value);
Jing Huang7725ccf2009-09-23 17:46:15 -07001422
1423}
1424
1425/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001426 * GMAL Request
Jing Huang7725ccf2009-09-23 17:46:15 -07001427 */
1428u16
1429fc_gmal_req_build(struct fchs_s *fchs, void *pyld, u32 s_id, wwn_t wwn)
1430{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001431 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
Jing Huang7725ccf2009-09-23 17:46:15 -07001432 fcgs_gmal_req_t *gmal = (fcgs_gmal_req_t *) (cthdr + 1);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001433 u32 d_id = bfa_hton3b(FC_MGMT_SERVER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001434
1435 fc_gs_fchdr_build(fchs, d_id, s_id, 0);
1436 fc_gs_ms_cthdr_build(cthdr, s_id, GS_FC_GMAL_CMD,
1437 CT_GSSUBTYPE_CFGSERVER);
1438
Jing Huang6a18b162010-10-18 17:08:54 -07001439 memset(gmal, 0, sizeof(fcgs_gmal_req_t));
Jing Huang7725ccf2009-09-23 17:46:15 -07001440 gmal->wwn = wwn;
1441
Jing Huangf8ceafd2009-09-25 12:29:54 -07001442 return sizeof(struct ct_hdr_s) + sizeof(fcgs_gmal_req_t);
Jing Huang7725ccf2009-09-23 17:46:15 -07001443}
1444
1445/*
1446 * GFN (Get Fabric Name) Request
1447 */
1448u16
1449fc_gfn_req_build(struct fchs_s *fchs, void *pyld, u32 s_id, wwn_t wwn)
1450{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001451 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
Jing Huang7725ccf2009-09-23 17:46:15 -07001452 fcgs_gfn_req_t *gfn = (fcgs_gfn_req_t *) (cthdr + 1);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001453 u32 d_id = bfa_hton3b(FC_MGMT_SERVER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001454
1455 fc_gs_fchdr_build(fchs, d_id, s_id, 0);
1456 fc_gs_ms_cthdr_build(cthdr, s_id, GS_FC_GFN_CMD,
1457 CT_GSSUBTYPE_CFGSERVER);
1458
Jing Huang6a18b162010-10-18 17:08:54 -07001459 memset(gfn, 0, sizeof(fcgs_gfn_req_t));
Jing Huang7725ccf2009-09-23 17:46:15 -07001460 gfn->wwn = wwn;
1461
Jing Huangf8ceafd2009-09-25 12:29:54 -07001462 return sizeof(struct ct_hdr_s) + sizeof(fcgs_gfn_req_t);
Jing Huang7725ccf2009-09-23 17:46:15 -07001463}