blob: 273cee90b3b429166ef8259a81a60aad0a865dc4 [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
231 plogi->els_cmd.els_code = els_code;
232 if (els_code == FC_ELS_PLOGI)
233 fc_els_req_build(fchs, d_id, s_id, ox_id);
234 else
235 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
236
Jing Huangba816ea2010-10-18 17:10:50 -0700237 plogi->csp.rxsz = plogi->class3.rxsz = cpu_to_be16(pdu_size);
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700238 plogi->csp.bbcred = cpu_to_be16(bb_cr);
Jing Huang7725ccf2009-09-23 17:46:15 -0700239
Jing Huang6a18b162010-10-18 17:08:54 -0700240 memcpy(&plogi->port_name, &port_name, sizeof(wwn_t));
241 memcpy(&plogi->node_name, &node_name, sizeof(wwn_t));
Jing Huang7725ccf2009-09-23 17:46:15 -0700242
Jing Huangf8ceafd2009-09-25 12:29:54 -0700243 return sizeof(struct fc_logi_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700244}
245
246u16
247fc_flogi_build(struct fchs_s *fchs, struct fc_logi_s *flogi, u32 s_id,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700248 u16 ox_id, wwn_t port_name, wwn_t node_name, u16 pdu_size,
249 u8 set_npiv, u8 set_auth, u16 local_bb_credits)
Jing Huang7725ccf2009-09-23 17:46:15 -0700250{
Maggie Zhangf16a1752010-12-09 19:12:32 -0800251 u32 d_id = bfa_hton3b(FC_FABRIC_PORT);
Maggie50444a32010-11-29 18:26:32 -0800252 __be32 *vvl_info;
Jing Huang7725ccf2009-09-23 17:46:15 -0700253
Jing Huang6a18b162010-10-18 17:08:54 -0700254 memcpy(flogi, &plogi_tmpl, sizeof(struct fc_logi_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700255
256 flogi->els_cmd.els_code = FC_ELS_FLOGI;
257 fc_els_req_build(fchs, d_id, s_id, ox_id);
258
Jing Huangba816ea2010-10-18 17:10:50 -0700259 flogi->csp.rxsz = flogi->class3.rxsz = cpu_to_be16(pdu_size);
Jing Huang7725ccf2009-09-23 17:46:15 -0700260 flogi->port_name = port_name;
261 flogi->node_name = node_name;
262
263 /*
264 * Set the NPIV Capability Bit ( word 1, bit 31) of Common
265 * Service Parameters.
266 */
267 flogi->csp.ciro = set_npiv;
268
269 /* set AUTH capability */
270 flogi->csp.security = set_auth;
271
Jing Huangba816ea2010-10-18 17:10:50 -0700272 flogi->csp.bbcred = cpu_to_be16(local_bb_credits);
Jing Huang7725ccf2009-09-23 17:46:15 -0700273
274 /* Set brcd token in VVL */
275 vvl_info = (u32 *)&flogi->vvl[0];
276
277 /* set the flag to indicate the presence of VVL */
278 flogi->csp.npiv_supp = 1; /* @todo. field name is not correct */
Jing Huangba816ea2010-10-18 17:10:50 -0700279 vvl_info[0] = cpu_to_be32(FLOGI_VVL_BRCD);
Jing Huang7725ccf2009-09-23 17:46:15 -0700280
Jing Huangf8ceafd2009-09-25 12:29:54 -0700281 return sizeof(struct fc_logi_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700282}
283
284u16
285fc_flogi_acc_build(struct fchs_s *fchs, struct fc_logi_s *flogi, u32 s_id,
Maggie50444a32010-11-29 18:26:32 -0800286 __be16 ox_id, wwn_t port_name, wwn_t node_name,
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700287 u16 pdu_size, u16 local_bb_credits, u8 bb_scn)
Jing Huang7725ccf2009-09-23 17:46:15 -0700288{
289 u32 d_id = 0;
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700290 u16 bbscn_rxsz = (bb_scn << 12) | pdu_size;
Jing Huang7725ccf2009-09-23 17:46:15 -0700291
Jing Huang6a18b162010-10-18 17:08:54 -0700292 memcpy(flogi, &plogi_tmpl, sizeof(struct fc_logi_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700293 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
294
295 flogi->els_cmd.els_code = FC_ELS_ACC;
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700296 flogi->class3.rxsz = cpu_to_be16(pdu_size);
297 flogi->csp.rxsz = cpu_to_be16(bbscn_rxsz); /* bb_scn/rxsz */
Jing Huang7725ccf2009-09-23 17:46:15 -0700298 flogi->port_name = port_name;
299 flogi->node_name = node_name;
300
Jing Huangba816ea2010-10-18 17:10:50 -0700301 flogi->csp.bbcred = cpu_to_be16(local_bb_credits);
Jing Huang7725ccf2009-09-23 17:46:15 -0700302
Jing Huangf8ceafd2009-09-25 12:29:54 -0700303 return sizeof(struct fc_logi_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700304}
305
306u16
307fc_fdisc_build(struct fchs_s *fchs, struct fc_logi_s *flogi, u32 s_id,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700308 u16 ox_id, wwn_t port_name, wwn_t node_name, u16 pdu_size)
Jing Huang7725ccf2009-09-23 17:46:15 -0700309{
Maggie Zhangf16a1752010-12-09 19:12:32 -0800310 u32 d_id = bfa_hton3b(FC_FABRIC_PORT);
Jing Huang7725ccf2009-09-23 17:46:15 -0700311
Jing Huang6a18b162010-10-18 17:08:54 -0700312 memcpy(flogi, &plogi_tmpl, sizeof(struct fc_logi_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700313
314 flogi->els_cmd.els_code = FC_ELS_FDISC;
315 fc_els_req_build(fchs, d_id, s_id, ox_id);
316
Jing Huangba816ea2010-10-18 17:10:50 -0700317 flogi->csp.rxsz = flogi->class3.rxsz = cpu_to_be16(pdu_size);
Jing Huang7725ccf2009-09-23 17:46:15 -0700318 flogi->port_name = port_name;
319 flogi->node_name = node_name;
320
Jing Huangf8ceafd2009-09-25 12:29:54 -0700321 return sizeof(struct fc_logi_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700322}
323
324u16
325fc_plogi_build(struct fchs_s *fchs, void *pld, u32 d_id, u32 s_id,
326 u16 ox_id, wwn_t port_name, wwn_t node_name,
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700327 u16 pdu_size, u16 bb_cr)
Jing Huang7725ccf2009-09-23 17:46:15 -0700328{
329 return fc_plogi_x_build(fchs, pld, d_id, s_id, ox_id, port_name,
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700330 node_name, pdu_size, bb_cr, FC_ELS_PLOGI);
Jing Huang7725ccf2009-09-23 17:46:15 -0700331}
332
333u16
334fc_plogi_acc_build(struct fchs_s *fchs, void *pld, u32 d_id, u32 s_id,
335 u16 ox_id, wwn_t port_name, wwn_t node_name,
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700336 u16 pdu_size, u16 bb_cr)
Jing Huang7725ccf2009-09-23 17:46:15 -0700337{
338 return fc_plogi_x_build(fchs, pld, d_id, s_id, ox_id, port_name,
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700339 node_name, pdu_size, bb_cr, FC_ELS_ACC);
Jing Huang7725ccf2009-09-23 17:46:15 -0700340}
341
342enum fc_parse_status
343fc_plogi_rsp_parse(struct fchs_s *fchs, int len, wwn_t port_name)
344{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700345 struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
346 struct fc_logi_s *plogi;
347 struct fc_ls_rjt_s *ls_rjt;
Jing Huang7725ccf2009-09-23 17:46:15 -0700348
349 switch (els_cmd->els_code) {
350 case FC_ELS_LS_RJT:
351 ls_rjt = (struct fc_ls_rjt_s *) (fchs + 1);
352 if (ls_rjt->reason_code == FC_LS_RJT_RSN_LOGICAL_BUSY)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700353 return FC_PARSE_BUSY;
Jing Huang7725ccf2009-09-23 17:46:15 -0700354 else
Jing Huangf8ceafd2009-09-25 12:29:54 -0700355 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700356 case FC_ELS_ACC:
357 plogi = (struct fc_logi_s *) (fchs + 1);
358 if (len < sizeof(struct fc_logi_s))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700359 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700360
361 if (!wwn_is_equal(plogi->port_name, port_name))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700362 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700363
364 if (!plogi->class3.class_valid)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700365 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700366
Jing Huangba816ea2010-10-18 17:10:50 -0700367 if (be16_to_cpu(plogi->class3.rxsz) < (FC_MIN_PDUSZ))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700368 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700369
Jing Huangf8ceafd2009-09-25 12:29:54 -0700370 return FC_PARSE_OK;
Jing Huang7725ccf2009-09-23 17:46:15 -0700371 default:
Jing Huangf8ceafd2009-09-25 12:29:54 -0700372 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700373 }
374}
375
376enum fc_parse_status
377fc_plogi_parse(struct fchs_s *fchs)
378{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700379 struct fc_logi_s *plogi = (struct fc_logi_s *) (fchs + 1);
Jing Huang7725ccf2009-09-23 17:46:15 -0700380
381 if (plogi->class3.class_valid != 1)
382 return FC_PARSE_FAILURE;
383
Jing Huangba816ea2010-10-18 17:10:50 -0700384 if ((be16_to_cpu(plogi->class3.rxsz) < FC_MIN_PDUSZ)
385 || (be16_to_cpu(plogi->class3.rxsz) > FC_MAX_PDUSZ)
Jing Huang7725ccf2009-09-23 17:46:15 -0700386 || (plogi->class3.rxsz == 0))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700387 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700388
389 return FC_PARSE_OK;
390}
391
392u16
393fc_prli_build(struct fchs_s *fchs, void *pld, u32 d_id, u32 s_id,
394 u16 ox_id)
395{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700396 struct fc_prli_s *prli = (struct fc_prli_s *) (pld);
Jing Huang7725ccf2009-09-23 17:46:15 -0700397
398 fc_els_req_build(fchs, d_id, s_id, ox_id);
Jing Huang6a18b162010-10-18 17:08:54 -0700399 memcpy(prli, &prli_tmpl, sizeof(struct fc_prli_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700400
401 prli->command = FC_ELS_PRLI;
402 prli->parampage.servparams.initiator = 1;
403 prli->parampage.servparams.retry = 1;
404 prli->parampage.servparams.rec_support = 1;
405 prli->parampage.servparams.task_retry_id = 0;
406 prli->parampage.servparams.confirm = 1;
407
Jing Huangf8ceafd2009-09-25 12:29:54 -0700408 return sizeof(struct fc_prli_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700409}
410
411u16
412fc_prli_acc_build(struct fchs_s *fchs, void *pld, u32 d_id, u32 s_id,
Maggie50444a32010-11-29 18:26:32 -0800413 __be16 ox_id, enum bfa_lport_role role)
Jing Huang7725ccf2009-09-23 17:46:15 -0700414{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700415 struct fc_prli_s *prli = (struct fc_prli_s *) (pld);
Jing Huang7725ccf2009-09-23 17:46:15 -0700416
417 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
Jing Huang6a18b162010-10-18 17:08:54 -0700418 memcpy(prli, &prli_tmpl, sizeof(struct fc_prli_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700419
420 prli->command = FC_ELS_ACC;
421
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700422 prli->parampage.servparams.initiator = 1;
Jing Huang7725ccf2009-09-23 17:46:15 -0700423
424 prli->parampage.rspcode = FC_PRLI_ACC_XQTD;
425
Jing Huangf8ceafd2009-09-25 12:29:54 -0700426 return sizeof(struct fc_prli_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700427}
428
429enum fc_parse_status
430fc_prli_rsp_parse(struct fc_prli_s *prli, int len)
431{
432 if (len < sizeof(struct fc_prli_s))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700433 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700434
435 if (prli->command != FC_ELS_ACC)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700436 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700437
438 if ((prli->parampage.rspcode != FC_PRLI_ACC_XQTD)
439 && (prli->parampage.rspcode != FC_PRLI_ACC_PREDEF_IMG))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700440 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700441
442 if (prli->parampage.servparams.target != 1)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700443 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700444
Jing Huangf8ceafd2009-09-25 12:29:54 -0700445 return FC_PARSE_OK;
Jing Huang7725ccf2009-09-23 17:46:15 -0700446}
447
448enum fc_parse_status
449fc_prli_parse(struct fc_prli_s *prli)
450{
451 if (prli->parampage.type != FC_TYPE_FCP)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700452 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700453
454 if (!prli->parampage.imagepair)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700455 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700456
457 if (!prli->parampage.servparams.initiator)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700458 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700459
Jing Huangf8ceafd2009-09-25 12:29:54 -0700460 return FC_PARSE_OK;
Jing Huang7725ccf2009-09-23 17:46:15 -0700461}
462
463u16
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700464fc_logo_build(struct fchs_s *fchs, struct fc_logo_s *logo, u32 d_id, u32 s_id,
465 u16 ox_id, wwn_t port_name)
Jing Huang7725ccf2009-09-23 17:46:15 -0700466{
467 fc_els_req_build(fchs, d_id, s_id, ox_id);
468
Jing Huang6a18b162010-10-18 17:08:54 -0700469 memset(logo, '\0', sizeof(struct fc_logo_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700470 logo->els_cmd.els_code = FC_ELS_LOGO;
471 logo->nport_id = (s_id);
472 logo->orig_port_name = port_name;
473
Jing Huangf8ceafd2009-09-25 12:29:54 -0700474 return sizeof(struct fc_logo_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700475}
476
Maggie Zhangda99dcc2010-12-09 19:13:20 -0800477static u16
Jing Huang7725ccf2009-09-23 17:46:15 -0700478fc_adisc_x_build(struct fchs_s *fchs, struct fc_adisc_s *adisc, u32 d_id,
Maggie50444a32010-11-29 18:26:32 -0800479 u32 s_id, __be16 ox_id, wwn_t port_name,
Jing Huang7725ccf2009-09-23 17:46:15 -0700480 wwn_t node_name, u8 els_code)
481{
Jing Huang6a18b162010-10-18 17:08:54 -0700482 memset(adisc, '\0', sizeof(struct fc_adisc_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700483
484 adisc->els_cmd.els_code = els_code;
485
486 if (els_code == FC_ELS_ADISC)
487 fc_els_req_build(fchs, d_id, s_id, ox_id);
488 else
489 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
490
491 adisc->orig_HA = 0;
492 adisc->orig_port_name = port_name;
493 adisc->orig_node_name = node_name;
494 adisc->nport_id = (s_id);
495
Jing Huangf8ceafd2009-09-25 12:29:54 -0700496 return sizeof(struct fc_adisc_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700497}
498
499u16
500fc_adisc_build(struct fchs_s *fchs, struct fc_adisc_s *adisc, u32 d_id,
Maggie50444a32010-11-29 18:26:32 -0800501 u32 s_id, __be16 ox_id, wwn_t port_name, wwn_t node_name)
Jing Huang7725ccf2009-09-23 17:46:15 -0700502{
503 return fc_adisc_x_build(fchs, adisc, d_id, s_id, ox_id, port_name,
504 node_name, FC_ELS_ADISC);
505}
506
507u16
508fc_adisc_acc_build(struct fchs_s *fchs, struct fc_adisc_s *adisc, u32 d_id,
Maggie50444a32010-11-29 18:26:32 -0800509 u32 s_id, __be16 ox_id, wwn_t port_name,
Jing Huang7725ccf2009-09-23 17:46:15 -0700510 wwn_t node_name)
511{
512 return fc_adisc_x_build(fchs, adisc, d_id, s_id, ox_id, port_name,
513 node_name, FC_ELS_ACC);
514}
515
516enum fc_parse_status
517fc_adisc_rsp_parse(struct fc_adisc_s *adisc, int len, wwn_t port_name,
518 wwn_t node_name)
519{
520
521 if (len < sizeof(struct fc_adisc_s))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700522 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700523
524 if (adisc->els_cmd.els_code != FC_ELS_ACC)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700525 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700526
527 if (!wwn_is_equal(adisc->orig_port_name, port_name))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700528 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700529
Jing Huangf8ceafd2009-09-25 12:29:54 -0700530 return FC_PARSE_OK;
Jing Huang7725ccf2009-09-23 17:46:15 -0700531}
532
533enum fc_parse_status
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700534fc_adisc_parse(struct fchs_s *fchs, void *pld, u32 host_dap, wwn_t node_name,
535 wwn_t port_name)
Jing Huang7725ccf2009-09-23 17:46:15 -0700536{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700537 struct fc_adisc_s *adisc = (struct fc_adisc_s *) pld;
Jing Huang7725ccf2009-09-23 17:46:15 -0700538
539 if (adisc->els_cmd.els_code != FC_ELS_ACC)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700540 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700541
542 if ((adisc->nport_id == (host_dap))
543 && wwn_is_equal(adisc->orig_port_name, port_name)
544 && wwn_is_equal(adisc->orig_node_name, node_name))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700545 return FC_PARSE_OK;
Jing Huang7725ccf2009-09-23 17:46:15 -0700546
Jing Huangf8ceafd2009-09-25 12:29:54 -0700547 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700548}
549
550enum fc_parse_status
551fc_pdisc_parse(struct fchs_s *fchs, wwn_t node_name, wwn_t port_name)
552{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700553 struct fc_logi_s *pdisc = (struct fc_logi_s *) (fchs + 1);
Jing Huang7725ccf2009-09-23 17:46:15 -0700554
555 if (pdisc->class3.class_valid != 1)
556 return FC_PARSE_FAILURE;
557
Jing Huangba816ea2010-10-18 17:10:50 -0700558 if ((be16_to_cpu(pdisc->class3.rxsz) <
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700559 (FC_MIN_PDUSZ - sizeof(struct fchs_s)))
Jing Huang7725ccf2009-09-23 17:46:15 -0700560 || (pdisc->class3.rxsz == 0))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700561 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700562
563 if (!wwn_is_equal(pdisc->port_name, port_name))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700564 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700565
566 if (!wwn_is_equal(pdisc->node_name, node_name))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700567 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700568
569 return FC_PARSE_OK;
570}
571
572u16
573fc_abts_build(struct fchs_s *fchs, u32 d_id, u32 s_id, u16 ox_id)
574{
Jing Huang6a18b162010-10-18 17:08:54 -0700575 memcpy(fchs, &fc_bls_req_tmpl, sizeof(struct fchs_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700576 fchs->cat_info = FC_CAT_ABTS;
577 fchs->d_id = (d_id);
578 fchs->s_id = (s_id);
Jing Huangba816ea2010-10-18 17:10:50 -0700579 fchs->ox_id = cpu_to_be16(ox_id);
Jing Huang7725ccf2009-09-23 17:46:15 -0700580
Jing Huangf8ceafd2009-09-25 12:29:54 -0700581 return sizeof(struct fchs_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700582}
583
584enum fc_parse_status
585fc_abts_rsp_parse(struct fchs_s *fchs, int len)
586{
587 if ((fchs->cat_info == FC_CAT_BA_ACC)
588 || (fchs->cat_info == FC_CAT_BA_RJT))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700589 return FC_PARSE_OK;
Jing Huang7725ccf2009-09-23 17:46:15 -0700590
Jing Huangf8ceafd2009-09-25 12:29:54 -0700591 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700592}
593
594u16
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700595fc_rrq_build(struct fchs_s *fchs, struct fc_rrq_s *rrq, u32 d_id, u32 s_id,
596 u16 ox_id, u16 rrq_oxid)
Jing Huang7725ccf2009-09-23 17:46:15 -0700597{
598 fc_els_req_build(fchs, d_id, s_id, ox_id);
599
600 /*
601 * build rrq payload
602 */
Jing Huang6a18b162010-10-18 17:08:54 -0700603 memcpy(rrq, &rrq_tmpl, sizeof(struct fc_rrq_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700604 rrq->s_id = (s_id);
Jing Huangba816ea2010-10-18 17:10:50 -0700605 rrq->ox_id = cpu_to_be16(rrq_oxid);
Jing Huang7725ccf2009-09-23 17:46:15 -0700606 rrq->rx_id = FC_RXID_ANY;
607
Jing Huangf8ceafd2009-09-25 12:29:54 -0700608 return sizeof(struct fc_rrq_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700609}
610
611u16
612fc_logo_acc_build(struct fchs_s *fchs, void *pld, u32 d_id, u32 s_id,
Maggie50444a32010-11-29 18:26:32 -0800613 __be16 ox_id)
Jing Huang7725ccf2009-09-23 17:46:15 -0700614{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700615 struct fc_els_cmd_s *acc = pld;
Jing Huang7725ccf2009-09-23 17:46:15 -0700616
617 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
618
Jing Huang6a18b162010-10-18 17:08:54 -0700619 memset(acc, 0, sizeof(struct fc_els_cmd_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700620 acc->els_code = FC_ELS_ACC;
621
Jing Huangf8ceafd2009-09-25 12:29:54 -0700622 return sizeof(struct fc_els_cmd_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700623}
624
625u16
626fc_ls_rjt_build(struct fchs_s *fchs, struct fc_ls_rjt_s *ls_rjt, u32 d_id,
Maggie50444a32010-11-29 18:26:32 -0800627 u32 s_id, __be16 ox_id, u8 reason_code,
Jing Huang7725ccf2009-09-23 17:46:15 -0700628 u8 reason_code_expl)
629{
630 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
Jing Huang6a18b162010-10-18 17:08:54 -0700631 memset(ls_rjt, 0, sizeof(struct fc_ls_rjt_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700632
633 ls_rjt->els_cmd.els_code = FC_ELS_LS_RJT;
634 ls_rjt->reason_code = reason_code;
635 ls_rjt->reason_code_expl = reason_code_expl;
636 ls_rjt->vendor_unique = 0x00;
637
Jing Huangf8ceafd2009-09-25 12:29:54 -0700638 return sizeof(struct fc_ls_rjt_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700639}
640
641u16
642fc_ba_acc_build(struct fchs_s *fchs, struct fc_ba_acc_s *ba_acc, u32 d_id,
Maggie50444a32010-11-29 18:26:32 -0800643 u32 s_id, __be16 ox_id, u16 rx_id)
Jing Huang7725ccf2009-09-23 17:46:15 -0700644{
645 fc_bls_rsp_build(fchs, d_id, s_id, ox_id);
646
Jing Huang6a18b162010-10-18 17:08:54 -0700647 memcpy(ba_acc, &ba_acc_tmpl, sizeof(struct fc_ba_acc_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700648
649 fchs->rx_id = rx_id;
650
651 ba_acc->ox_id = fchs->ox_id;
652 ba_acc->rx_id = fchs->rx_id;
653
Jing Huangf8ceafd2009-09-25 12:29:54 -0700654 return sizeof(struct fc_ba_acc_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700655}
656
657u16
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700658fc_ls_acc_build(struct fchs_s *fchs, struct fc_els_cmd_s *els_cmd, u32 d_id,
Maggie50444a32010-11-29 18:26:32 -0800659 u32 s_id, __be16 ox_id)
Jing Huang7725ccf2009-09-23 17:46:15 -0700660{
661 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
Jing Huang6a18b162010-10-18 17:08:54 -0700662 memset(els_cmd, 0, sizeof(struct fc_els_cmd_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700663 els_cmd->els_code = FC_ELS_ACC;
664
Jing Huangf8ceafd2009-09-25 12:29:54 -0700665 return sizeof(struct fc_els_cmd_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700666}
667
668int
669fc_logout_params_pages(struct fchs_s *fc_frame, u8 els_code)
670{
671 int num_pages = 0;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700672 struct fc_prlo_s *prlo;
673 struct fc_tprlo_s *tprlo;
Jing Huang7725ccf2009-09-23 17:46:15 -0700674
675 if (els_code == FC_ELS_PRLO) {
676 prlo = (struct fc_prlo_s *) (fc_frame + 1);
Jing Huangba816ea2010-10-18 17:10:50 -0700677 num_pages = (be16_to_cpu(prlo->payload_len) - 4) / 16;
Jing Huang7725ccf2009-09-23 17:46:15 -0700678 } else {
679 tprlo = (struct fc_tprlo_s *) (fc_frame + 1);
Jing Huangba816ea2010-10-18 17:10:50 -0700680 num_pages = (be16_to_cpu(tprlo->payload_len) - 4) / 16;
Jing Huang7725ccf2009-09-23 17:46:15 -0700681 }
682 return num_pages;
683}
684
685u16
686fc_tprlo_acc_build(struct fchs_s *fchs, struct fc_tprlo_acc_s *tprlo_acc,
Maggie50444a32010-11-29 18:26:32 -0800687 u32 d_id, u32 s_id, __be16 ox_id, int num_pages)
Jing Huang7725ccf2009-09-23 17:46:15 -0700688{
689 int page;
690
691 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
692
Jing Huang6a18b162010-10-18 17:08:54 -0700693 memset(tprlo_acc, 0, (num_pages * 16) + 4);
Jing Huang7725ccf2009-09-23 17:46:15 -0700694 tprlo_acc->command = FC_ELS_ACC;
695
696 tprlo_acc->page_len = 0x10;
Jing Huangba816ea2010-10-18 17:10:50 -0700697 tprlo_acc->payload_len = cpu_to_be16((num_pages * 16) + 4);
Jing Huang7725ccf2009-09-23 17:46:15 -0700698
699 for (page = 0; page < num_pages; page++) {
700 tprlo_acc->tprlo_acc_params[page].opa_valid = 0;
701 tprlo_acc->tprlo_acc_params[page].rpa_valid = 0;
702 tprlo_acc->tprlo_acc_params[page].fc4type_csp = FC_TYPE_FCP;
703 tprlo_acc->tprlo_acc_params[page].orig_process_assc = 0;
704 tprlo_acc->tprlo_acc_params[page].resp_process_assc = 0;
705 }
Jing Huangba816ea2010-10-18 17:10:50 -0700706 return be16_to_cpu(tprlo_acc->payload_len);
Jing Huang7725ccf2009-09-23 17:46:15 -0700707}
708
709u16
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700710fc_prlo_acc_build(struct fchs_s *fchs, struct fc_prlo_acc_s *prlo_acc, u32 d_id,
Maggie50444a32010-11-29 18:26:32 -0800711 u32 s_id, __be16 ox_id, int num_pages)
Jing Huang7725ccf2009-09-23 17:46:15 -0700712{
713 int page;
714
715 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
716
Jing Huang6a18b162010-10-18 17:08:54 -0700717 memset(prlo_acc, 0, (num_pages * 16) + 4);
Jing Huang7725ccf2009-09-23 17:46:15 -0700718 prlo_acc->command = FC_ELS_ACC;
719 prlo_acc->page_len = 0x10;
Jing Huangba816ea2010-10-18 17:10:50 -0700720 prlo_acc->payload_len = cpu_to_be16((num_pages * 16) + 4);
Jing Huang7725ccf2009-09-23 17:46:15 -0700721
722 for (page = 0; page < num_pages; page++) {
723 prlo_acc->prlo_acc_params[page].opa_valid = 0;
724 prlo_acc->prlo_acc_params[page].rpa_valid = 0;
725 prlo_acc->prlo_acc_params[page].fc4type_csp = FC_TYPE_FCP;
726 prlo_acc->prlo_acc_params[page].orig_process_assc = 0;
727 prlo_acc->prlo_acc_params[page].resp_process_assc = 0;
728 }
729
Jing Huangba816ea2010-10-18 17:10:50 -0700730 return be16_to_cpu(prlo_acc->payload_len);
Jing Huang7725ccf2009-09-23 17:46:15 -0700731}
732
733u16
734fc_rnid_build(struct fchs_s *fchs, struct fc_rnid_cmd_s *rnid, u32 d_id,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700735 u32 s_id, u16 ox_id, u32 data_format)
Jing Huang7725ccf2009-09-23 17:46:15 -0700736{
737 fc_els_req_build(fchs, d_id, s_id, ox_id);
738
Jing Huang6a18b162010-10-18 17:08:54 -0700739 memset(rnid, 0, sizeof(struct fc_rnid_cmd_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700740
741 rnid->els_cmd.els_code = FC_ELS_RNID;
742 rnid->node_id_data_format = data_format;
743
Jing Huangf8ceafd2009-09-25 12:29:54 -0700744 return sizeof(struct fc_rnid_cmd_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700745}
746
747u16
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700748fc_rnid_acc_build(struct fchs_s *fchs, struct fc_rnid_acc_s *rnid_acc, u32 d_id,
Maggie50444a32010-11-29 18:26:32 -0800749 u32 s_id, __be16 ox_id, u32 data_format,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700750 struct fc_rnid_common_id_data_s *common_id_data,
751 struct fc_rnid_general_topology_data_s *gen_topo_data)
Jing Huang7725ccf2009-09-23 17:46:15 -0700752{
Jing Huang6a18b162010-10-18 17:08:54 -0700753 memset(rnid_acc, 0, sizeof(struct fc_rnid_acc_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700754
755 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
756
757 rnid_acc->els_cmd.els_code = FC_ELS_ACC;
758 rnid_acc->node_id_data_format = data_format;
759 rnid_acc->common_id_data_length =
760 sizeof(struct fc_rnid_common_id_data_s);
761 rnid_acc->common_id_data = *common_id_data;
762
763 if (data_format == RNID_NODEID_DATA_FORMAT_DISCOVERY) {
764 rnid_acc->specific_id_data_length =
765 sizeof(struct fc_rnid_general_topology_data_s);
Jing Huang6a18b162010-10-18 17:08:54 -0700766 rnid_acc->gen_topology_data = *gen_topo_data;
Jing Huangf8ceafd2009-09-25 12:29:54 -0700767 return sizeof(struct fc_rnid_acc_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700768 } else {
Jing Huangf8ceafd2009-09-25 12:29:54 -0700769 return sizeof(struct fc_rnid_acc_s) -
770 sizeof(struct fc_rnid_general_topology_data_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700771 }
772
773}
774
775u16
776fc_rpsc_build(struct fchs_s *fchs, struct fc_rpsc_cmd_s *rpsc, u32 d_id,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700777 u32 s_id, u16 ox_id)
Jing Huang7725ccf2009-09-23 17:46:15 -0700778{
779 fc_els_req_build(fchs, d_id, s_id, ox_id);
780
Jing Huang6a18b162010-10-18 17:08:54 -0700781 memset(rpsc, 0, sizeof(struct fc_rpsc_cmd_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700782
783 rpsc->els_cmd.els_code = FC_ELS_RPSC;
Jing Huangf8ceafd2009-09-25 12:29:54 -0700784 return sizeof(struct fc_rpsc_cmd_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700785}
786
787u16
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700788fc_rpsc2_build(struct fchs_s *fchs, struct fc_rpsc2_cmd_s *rpsc2, u32 d_id,
789 u32 s_id, u32 *pid_list, u16 npids)
Jing Huang7725ccf2009-09-23 17:46:15 -0700790{
Maggie Zhangf16a1752010-12-09 19:12:32 -0800791 u32 dctlr_id = FC_DOMAIN_CTRLR(bfa_hton3b(d_id));
Jing Huang7725ccf2009-09-23 17:46:15 -0700792 int i = 0;
793
Maggie Zhangf16a1752010-12-09 19:12:32 -0800794 fc_els_req_build(fchs, bfa_hton3b(dctlr_id), s_id, 0);
Jing Huang7725ccf2009-09-23 17:46:15 -0700795
Jing Huang6a18b162010-10-18 17:08:54 -0700796 memset(rpsc2, 0, sizeof(struct fc_rpsc2_cmd_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700797
798 rpsc2->els_cmd.els_code = FC_ELS_RPSC;
Jing Huangba816ea2010-10-18 17:10:50 -0700799 rpsc2->token = cpu_to_be32(FC_BRCD_TOKEN);
800 rpsc2->num_pids = cpu_to_be16(npids);
Jing Huang7725ccf2009-09-23 17:46:15 -0700801 for (i = 0; i < npids; i++)
802 rpsc2->pid_list[i].pid = pid_list[i];
803
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700804 return sizeof(struct fc_rpsc2_cmd_s) + ((npids - 1) * (sizeof(u32)));
Jing Huang7725ccf2009-09-23 17:46:15 -0700805}
806
807u16
808fc_rpsc_acc_build(struct fchs_s *fchs, struct fc_rpsc_acc_s *rpsc_acc,
Maggie50444a32010-11-29 18:26:32 -0800809 u32 d_id, u32 s_id, __be16 ox_id,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700810 struct fc_rpsc_speed_info_s *oper_speed)
Jing Huang7725ccf2009-09-23 17:46:15 -0700811{
Jing Huang6a18b162010-10-18 17:08:54 -0700812 memset(rpsc_acc, 0, sizeof(struct fc_rpsc_acc_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700813
814 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
815
816 rpsc_acc->command = FC_ELS_ACC;
Jing Huangba816ea2010-10-18 17:10:50 -0700817 rpsc_acc->num_entries = cpu_to_be16(1);
Jing Huang7725ccf2009-09-23 17:46:15 -0700818
819 rpsc_acc->speed_info[0].port_speed_cap =
Jing Huangba816ea2010-10-18 17:10:50 -0700820 cpu_to_be16(oper_speed->port_speed_cap);
Jing Huang7725ccf2009-09-23 17:46:15 -0700821
822 rpsc_acc->speed_info[0].port_op_speed =
Jing Huangba816ea2010-10-18 17:10:50 -0700823 cpu_to_be16(oper_speed->port_op_speed);
Jing Huang7725ccf2009-09-23 17:46:15 -0700824
Jing Huangf8ceafd2009-09-25 12:29:54 -0700825 return sizeof(struct fc_rpsc_acc_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700826}
827
Jing Huang7725ccf2009-09-23 17:46:15 -0700828u16
829fc_logo_rsp_parse(struct fchs_s *fchs, int len)
830{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700831 struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
Jing Huang7725ccf2009-09-23 17:46:15 -0700832
833 len = len;
834 if (els_cmd->els_code != FC_ELS_ACC)
835 return FC_PARSE_FAILURE;
836
837 return FC_PARSE_OK;
838}
839
840u16
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700841fc_pdisc_build(struct fchs_s *fchs, u32 d_id, u32 s_id, u16 ox_id,
842 wwn_t port_name, wwn_t node_name, u16 pdu_size)
Jing Huang7725ccf2009-09-23 17:46:15 -0700843{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700844 struct fc_logi_s *pdisc = (struct fc_logi_s *) (fchs + 1);
Jing Huang7725ccf2009-09-23 17:46:15 -0700845
Jing Huang6a18b162010-10-18 17:08:54 -0700846 memcpy(pdisc, &plogi_tmpl, sizeof(struct fc_logi_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700847
848 pdisc->els_cmd.els_code = FC_ELS_PDISC;
849 fc_els_req_build(fchs, d_id, s_id, ox_id);
850
Jing Huangba816ea2010-10-18 17:10:50 -0700851 pdisc->csp.rxsz = pdisc->class3.rxsz = cpu_to_be16(pdu_size);
Jing Huang7725ccf2009-09-23 17:46:15 -0700852 pdisc->port_name = port_name;
853 pdisc->node_name = node_name;
854
Jing Huangf8ceafd2009-09-25 12:29:54 -0700855 return sizeof(struct fc_logi_s);
Jing Huang7725ccf2009-09-23 17:46:15 -0700856}
857
858u16
859fc_pdisc_rsp_parse(struct fchs_s *fchs, int len, wwn_t port_name)
860{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700861 struct fc_logi_s *pdisc = (struct fc_logi_s *) (fchs + 1);
Jing Huang7725ccf2009-09-23 17:46:15 -0700862
863 if (len < sizeof(struct fc_logi_s))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700864 return FC_PARSE_LEN_INVAL;
Jing Huang7725ccf2009-09-23 17:46:15 -0700865
866 if (pdisc->els_cmd.els_code != FC_ELS_ACC)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700867 return FC_PARSE_ACC_INVAL;
Jing Huang7725ccf2009-09-23 17:46:15 -0700868
869 if (!wwn_is_equal(pdisc->port_name, port_name))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700870 return FC_PARSE_PWWN_NOT_EQUAL;
Jing Huang7725ccf2009-09-23 17:46:15 -0700871
872 if (!pdisc->class3.class_valid)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700873 return FC_PARSE_NWWN_NOT_EQUAL;
Jing Huang7725ccf2009-09-23 17:46:15 -0700874
Jing Huangba816ea2010-10-18 17:10:50 -0700875 if (be16_to_cpu(pdisc->class3.rxsz) < (FC_MIN_PDUSZ))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700876 return FC_PARSE_RXSZ_INVAL;
Jing Huang7725ccf2009-09-23 17:46:15 -0700877
Jing Huangf8ceafd2009-09-25 12:29:54 -0700878 return FC_PARSE_OK;
Jing Huang7725ccf2009-09-23 17:46:15 -0700879}
880
881u16
882fc_prlo_build(struct fchs_s *fchs, u32 d_id, u32 s_id, u16 ox_id,
883 int num_pages)
884{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700885 struct fc_prlo_s *prlo = (struct fc_prlo_s *) (fchs + 1);
Jing Huang7725ccf2009-09-23 17:46:15 -0700886 int page;
887
888 fc_els_req_build(fchs, d_id, s_id, ox_id);
Jing Huang6a18b162010-10-18 17:08:54 -0700889 memset(prlo, 0, (num_pages * 16) + 4);
Jing Huang7725ccf2009-09-23 17:46:15 -0700890 prlo->command = FC_ELS_PRLO;
891 prlo->page_len = 0x10;
Jing Huangba816ea2010-10-18 17:10:50 -0700892 prlo->payload_len = cpu_to_be16((num_pages * 16) + 4);
Jing Huang7725ccf2009-09-23 17:46:15 -0700893
894 for (page = 0; page < num_pages; page++) {
895 prlo->prlo_params[page].type = FC_TYPE_FCP;
896 prlo->prlo_params[page].opa_valid = 0;
897 prlo->prlo_params[page].rpa_valid = 0;
898 prlo->prlo_params[page].orig_process_assc = 0;
899 prlo->prlo_params[page].resp_process_assc = 0;
900 }
901
Jing Huangba816ea2010-10-18 17:10:50 -0700902 return be16_to_cpu(prlo->payload_len);
Jing Huang7725ccf2009-09-23 17:46:15 -0700903}
904
905u16
906fc_prlo_rsp_parse(struct fchs_s *fchs, int len)
907{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700908 struct fc_prlo_acc_s *prlo = (struct fc_prlo_acc_s *) (fchs + 1);
Jing Huang7725ccf2009-09-23 17:46:15 -0700909 int num_pages = 0;
910 int page = 0;
911
912 len = len;
913
914 if (prlo->command != FC_ELS_ACC)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700915 return FC_PARSE_FAILURE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700916
Jing Huangba816ea2010-10-18 17:10:50 -0700917 num_pages = ((be16_to_cpu(prlo->payload_len)) - 4) / 16;
Jing Huang7725ccf2009-09-23 17:46:15 -0700918
919 for (page = 0; page < num_pages; page++) {
920 if (prlo->prlo_acc_params[page].type != FC_TYPE_FCP)
921 return FC_PARSE_FAILURE;
922
923 if (prlo->prlo_acc_params[page].opa_valid != 0)
924 return FC_PARSE_FAILURE;
925
926 if (prlo->prlo_acc_params[page].rpa_valid != 0)
927 return FC_PARSE_FAILURE;
928
929 if (prlo->prlo_acc_params[page].orig_process_assc != 0)
930 return FC_PARSE_FAILURE;
931
932 if (prlo->prlo_acc_params[page].resp_process_assc != 0)
933 return FC_PARSE_FAILURE;
934 }
Jing Huangf8ceafd2009-09-25 12:29:54 -0700935 return FC_PARSE_OK;
Jing Huang7725ccf2009-09-23 17:46:15 -0700936
937}
938
939u16
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700940fc_tprlo_build(struct fchs_s *fchs, u32 d_id, u32 s_id, u16 ox_id,
941 int num_pages, enum fc_tprlo_type tprlo_type, u32 tpr_id)
Jing Huang7725ccf2009-09-23 17:46:15 -0700942{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700943 struct fc_tprlo_s *tprlo = (struct fc_tprlo_s *) (fchs + 1);
Jing Huang7725ccf2009-09-23 17:46:15 -0700944 int page;
945
946 fc_els_req_build(fchs, d_id, s_id, ox_id);
Jing Huang6a18b162010-10-18 17:08:54 -0700947 memset(tprlo, 0, (num_pages * 16) + 4);
Jing Huang7725ccf2009-09-23 17:46:15 -0700948 tprlo->command = FC_ELS_TPRLO;
949 tprlo->page_len = 0x10;
Jing Huangba816ea2010-10-18 17:10:50 -0700950 tprlo->payload_len = cpu_to_be16((num_pages * 16) + 4);
Jing Huang7725ccf2009-09-23 17:46:15 -0700951
952 for (page = 0; page < num_pages; page++) {
953 tprlo->tprlo_params[page].type = FC_TYPE_FCP;
954 tprlo->tprlo_params[page].opa_valid = 0;
955 tprlo->tprlo_params[page].rpa_valid = 0;
956 tprlo->tprlo_params[page].orig_process_assc = 0;
957 tprlo->tprlo_params[page].resp_process_assc = 0;
958 if (tprlo_type == FC_GLOBAL_LOGO) {
959 tprlo->tprlo_params[page].global_process_logout = 1;
960 } else if (tprlo_type == FC_TPR_LOGO) {
961 tprlo->tprlo_params[page].tpo_nport_valid = 1;
962 tprlo->tprlo_params[page].tpo_nport_id = (tpr_id);
963 }
964 }
965
Jing Huangba816ea2010-10-18 17:10:50 -0700966 return be16_to_cpu(tprlo->payload_len);
Jing Huang7725ccf2009-09-23 17:46:15 -0700967}
968
969u16
970fc_tprlo_rsp_parse(struct fchs_s *fchs, int len)
971{
972 struct fc_tprlo_acc_s *tprlo = (struct fc_tprlo_acc_s *) (fchs + 1);
973 int num_pages = 0;
974 int page = 0;
975
976 len = len;
977
978 if (tprlo->command != FC_ELS_ACC)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700979 return FC_PARSE_ACC_INVAL;
Jing Huang7725ccf2009-09-23 17:46:15 -0700980
Jing Huangba816ea2010-10-18 17:10:50 -0700981 num_pages = (be16_to_cpu(tprlo->payload_len) - 4) / 16;
Jing Huang7725ccf2009-09-23 17:46:15 -0700982
983 for (page = 0; page < num_pages; page++) {
984 if (tprlo->tprlo_acc_params[page].type != FC_TYPE_FCP)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700985 return FC_PARSE_NOT_FCP;
Jing Huang7725ccf2009-09-23 17:46:15 -0700986 if (tprlo->tprlo_acc_params[page].opa_valid != 0)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700987 return FC_PARSE_OPAFLAG_INVAL;
Jing Huang7725ccf2009-09-23 17:46:15 -0700988 if (tprlo->tprlo_acc_params[page].rpa_valid != 0)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700989 return FC_PARSE_RPAFLAG_INVAL;
Jing Huang7725ccf2009-09-23 17:46:15 -0700990 if (tprlo->tprlo_acc_params[page].orig_process_assc != 0)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700991 return FC_PARSE_OPA_INVAL;
Jing Huang7725ccf2009-09-23 17:46:15 -0700992 if (tprlo->tprlo_acc_params[page].resp_process_assc != 0)
Jing Huangf8ceafd2009-09-25 12:29:54 -0700993 return FC_PARSE_RPA_INVAL;
Jing Huang7725ccf2009-09-23 17:46:15 -0700994 }
Jing Huangf8ceafd2009-09-25 12:29:54 -0700995 return FC_PARSE_OK;
Jing Huang7725ccf2009-09-23 17:46:15 -0700996}
997
998enum fc_parse_status
999fc_rrq_rsp_parse(struct fchs_s *fchs, int len)
1000{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001001 struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
Jing Huang7725ccf2009-09-23 17:46:15 -07001002
1003 len = len;
1004 if (els_cmd->els_code != FC_ELS_ACC)
1005 return FC_PARSE_FAILURE;
1006
1007 return FC_PARSE_OK;
1008}
1009
1010u16
Maggie50444a32010-11-29 18:26:32 -08001011fc_ba_rjt_build(struct fchs_s *fchs, u32 d_id, u32 s_id, __be16 ox_id,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001012 u32 reason_code, u32 reason_expl)
Jing Huang7725ccf2009-09-23 17:46:15 -07001013{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001014 struct fc_ba_rjt_s *ba_rjt = (struct fc_ba_rjt_s *) (fchs + 1);
Jing Huang7725ccf2009-09-23 17:46:15 -07001015
1016 fc_bls_rsp_build(fchs, d_id, s_id, ox_id);
1017
1018 fchs->cat_info = FC_CAT_BA_RJT;
1019 ba_rjt->reason_code = reason_code;
1020 ba_rjt->reason_expl = reason_expl;
Jing Huangf8ceafd2009-09-25 12:29:54 -07001021 return sizeof(struct fc_ba_rjt_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001022}
1023
1024static void
1025fc_gs_cthdr_build(struct ct_hdr_s *cthdr, u32 s_id, u16 cmd_code)
1026{
Jing Huang6a18b162010-10-18 17:08:54 -07001027 memset(cthdr, 0, sizeof(struct ct_hdr_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001028 cthdr->rev_id = CT_GS3_REVISION;
1029 cthdr->gs_type = CT_GSTYPE_DIRSERVICE;
1030 cthdr->gs_sub_type = CT_GSSUBTYPE_NAMESERVER;
Jing Huangba816ea2010-10-18 17:10:50 -07001031 cthdr->cmd_rsp_code = cpu_to_be16(cmd_code);
Jing Huang7725ccf2009-09-23 17:46:15 -07001032}
1033
1034static void
1035fc_gs_fdmi_cthdr_build(struct ct_hdr_s *cthdr, u32 s_id, u16 cmd_code)
1036{
Jing Huang6a18b162010-10-18 17:08:54 -07001037 memset(cthdr, 0, sizeof(struct ct_hdr_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001038 cthdr->rev_id = CT_GS3_REVISION;
1039 cthdr->gs_type = CT_GSTYPE_MGMTSERVICE;
1040 cthdr->gs_sub_type = CT_GSSUBTYPE_HBA_MGMTSERVER;
Jing Huangba816ea2010-10-18 17:10:50 -07001041 cthdr->cmd_rsp_code = cpu_to_be16(cmd_code);
Jing Huang7725ccf2009-09-23 17:46:15 -07001042}
1043
1044static void
1045fc_gs_ms_cthdr_build(struct ct_hdr_s *cthdr, u32 s_id, u16 cmd_code,
1046 u8 sub_type)
1047{
Jing Huang6a18b162010-10-18 17:08:54 -07001048 memset(cthdr, 0, sizeof(struct ct_hdr_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001049 cthdr->rev_id = CT_GS3_REVISION;
1050 cthdr->gs_type = CT_GSTYPE_MGMTSERVICE;
1051 cthdr->gs_sub_type = sub_type;
Jing Huangba816ea2010-10-18 17:10:50 -07001052 cthdr->cmd_rsp_code = cpu_to_be16(cmd_code);
Jing Huang7725ccf2009-09-23 17:46:15 -07001053}
1054
1055u16
1056fc_gidpn_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
1057 wwn_t port_name)
1058{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001059 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1060 struct fcgs_gidpn_req_s *gidpn = (struct fcgs_gidpn_req_s *)(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_GID_PN);
1065
Jing Huang6a18b162010-10-18 17:08:54 -07001066 memset(gidpn, 0, sizeof(struct fcgs_gidpn_req_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001067 gidpn->port_name = port_name;
Jing Huangf8ceafd2009-09-25 12:29:54 -07001068 return sizeof(struct fcgs_gidpn_req_s) + sizeof(struct ct_hdr_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001069}
1070
1071u16
1072fc_gpnid_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_gpnid_req_t *gpnid = (fcgs_gpnid_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_GPN_ID);
1081
Jing Huang6a18b162010-10-18 17:08:54 -07001082 memset(gpnid, 0, sizeof(fcgs_gpnid_req_t));
Jing Huang7725ccf2009-09-23 17:46:15 -07001083 gpnid->dap = port_id;
Jing Huangf8ceafd2009-09-25 12:29:54 -07001084 return sizeof(fcgs_gpnid_req_t) + sizeof(struct ct_hdr_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001085}
1086
1087u16
1088fc_gnnid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
1089 u32 port_id)
1090{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001091 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
Jing Huang7725ccf2009-09-23 17:46:15 -07001092 fcgs_gnnid_req_t *gnnid = (fcgs_gnnid_req_t *) (cthdr + 1);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001093 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001094
1095 fc_gs_fchdr_build(fchs, d_id, s_id, ox_id);
1096 fc_gs_cthdr_build(cthdr, s_id, GS_GNN_ID);
1097
Jing Huang6a18b162010-10-18 17:08:54 -07001098 memset(gnnid, 0, sizeof(fcgs_gnnid_req_t));
Jing Huang7725ccf2009-09-23 17:46:15 -07001099 gnnid->dap = port_id;
Jing Huangf8ceafd2009-09-25 12:29:54 -07001100 return sizeof(fcgs_gnnid_req_t) + sizeof(struct ct_hdr_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001101}
1102
1103u16
1104fc_ct_rsp_parse(struct ct_hdr_s *cthdr)
1105{
Jing Huangba816ea2010-10-18 17:10:50 -07001106 if (be16_to_cpu(cthdr->cmd_rsp_code) != CT_RSP_ACCEPT) {
Jing Huang7725ccf2009-09-23 17:46:15 -07001107 if (cthdr->reason_code == CT_RSN_LOGICAL_BUSY)
1108 return FC_PARSE_BUSY;
1109 else
1110 return FC_PARSE_FAILURE;
1111 }
1112
1113 return FC_PARSE_OK;
1114}
1115
1116u16
Krishna Gudipatid7be54c2011-06-24 20:24:52 -07001117fc_gs_rjt_build(struct fchs_s *fchs, struct ct_hdr_s *cthdr,
1118 u32 d_id, u32 s_id, u16 ox_id, u8 reason_code,
1119 u8 reason_code_expl)
1120{
1121 fc_gsresp_fchdr_build(fchs, d_id, s_id, ox_id);
1122
1123 cthdr->cmd_rsp_code = cpu_to_be16(CT_RSP_REJECT);
1124 cthdr->rev_id = CT_GS3_REVISION;
1125
1126 cthdr->reason_code = reason_code;
1127 cthdr->exp_code = reason_code_expl;
1128 return sizeof(struct ct_hdr_s);
1129}
1130
1131u16
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001132fc_scr_build(struct fchs_s *fchs, struct fc_scr_s *scr,
1133 u8 set_br_reg, u32 s_id, u16 ox_id)
Jing Huang7725ccf2009-09-23 17:46:15 -07001134{
Maggie Zhangf16a1752010-12-09 19:12:32 -08001135 u32 d_id = bfa_hton3b(FC_FABRIC_CONTROLLER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001136
1137 fc_els_req_build(fchs, d_id, s_id, ox_id);
1138
Jing Huang6a18b162010-10-18 17:08:54 -07001139 memset(scr, 0, sizeof(struct fc_scr_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001140 scr->command = FC_ELS_SCR;
1141 scr->reg_func = FC_SCR_REG_FUNC_FULL;
1142 if (set_br_reg)
1143 scr->vu_reg_func = FC_VU_SCR_REG_FUNC_FABRIC_NAME_CHANGE;
1144
Jing Huangf8ceafd2009-09-25 12:29:54 -07001145 return sizeof(struct fc_scr_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001146}
1147
1148u16
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001149fc_rscn_build(struct fchs_s *fchs, struct fc_rscn_pl_s *rscn,
1150 u32 s_id, u16 ox_id)
Jing Huang7725ccf2009-09-23 17:46:15 -07001151{
Maggie Zhangf16a1752010-12-09 19:12:32 -08001152 u32 d_id = bfa_hton3b(FC_FABRIC_CONTROLLER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001153 u16 payldlen;
1154
1155 fc_els_req_build(fchs, d_id, s_id, ox_id);
1156 rscn->command = FC_ELS_RSCN;
1157 rscn->pagelen = sizeof(rscn->event[0]);
1158
1159 payldlen = sizeof(u32) + rscn->pagelen;
Jing Huangba816ea2010-10-18 17:10:50 -07001160 rscn->payldlen = cpu_to_be16(payldlen);
Jing Huang7725ccf2009-09-23 17:46:15 -07001161
1162 rscn->event[0].format = FC_RSCN_FORMAT_PORTID;
1163 rscn->event[0].portid = s_id;
1164
Jing Huangf8ceafd2009-09-25 12:29:54 -07001165 return sizeof(struct fc_rscn_pl_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001166}
1167
1168u16
1169fc_rftid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001170 enum bfa_lport_role roles)
Jing Huang7725ccf2009-09-23 17:46:15 -07001171{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001172 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1173 struct fcgs_rftid_req_s *rftid = (struct fcgs_rftid_req_s *)(cthdr + 1);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001174 u32 type_value, d_id = bfa_hton3b(FC_NAME_SERVER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001175 u8 index;
1176
1177 fc_gs_fchdr_build(fchs, d_id, s_id, ox_id);
1178 fc_gs_cthdr_build(cthdr, s_id, GS_RFT_ID);
1179
Jing Huang6a18b162010-10-18 17:08:54 -07001180 memset(rftid, 0, sizeof(struct fcgs_rftid_req_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001181
1182 rftid->dap = s_id;
1183
1184 /* By default, FCP FC4 Type is registered */
1185 index = FC_TYPE_FCP >> 5;
1186 type_value = 1 << (FC_TYPE_FCP % 32);
Jing Huangba816ea2010-10-18 17:10:50 -07001187 rftid->fc4_type[index] = cpu_to_be32(type_value);
Jing Huang7725ccf2009-09-23 17:46:15 -07001188
Jing Huangf8ceafd2009-09-25 12:29:54 -07001189 return sizeof(struct fcgs_rftid_req_s) + sizeof(struct ct_hdr_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001190}
1191
1192u16
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001193fc_rftid_build_sol(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
1194 u8 *fc4_bitmap, u32 bitmap_size)
Jing Huang7725ccf2009-09-23 17:46:15 -07001195{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001196 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1197 struct fcgs_rftid_req_s *rftid = (struct fcgs_rftid_req_s *)(cthdr + 1);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001198 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001199
1200 fc_gs_fchdr_build(fchs, d_id, s_id, ox_id);
1201 fc_gs_cthdr_build(cthdr, s_id, GS_RFT_ID);
1202
Jing Huang6a18b162010-10-18 17:08:54 -07001203 memset(rftid, 0, sizeof(struct fcgs_rftid_req_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001204
1205 rftid->dap = s_id;
Jing Huang6a18b162010-10-18 17:08:54 -07001206 memcpy((void *)rftid->fc4_type, (void *)fc4_bitmap,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001207 (bitmap_size < 32 ? bitmap_size : 32));
Jing Huang7725ccf2009-09-23 17:46:15 -07001208
Jing Huangf8ceafd2009-09-25 12:29:54 -07001209 return sizeof(struct fcgs_rftid_req_s) + sizeof(struct ct_hdr_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001210}
1211
1212u16
1213fc_rffid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
1214 u8 fc4_type, u8 fc4_ftrs)
1215{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001216 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1217 struct fcgs_rffid_req_s *rffid = (struct fcgs_rffid_req_s *)(cthdr + 1);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001218 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001219
1220 fc_gs_fchdr_build(fchs, d_id, s_id, ox_id);
1221 fc_gs_cthdr_build(cthdr, s_id, GS_RFF_ID);
1222
Jing Huang6a18b162010-10-18 17:08:54 -07001223 memset(rffid, 0, sizeof(struct fcgs_rffid_req_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001224
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001225 rffid->dap = s_id;
Jing Huang7725ccf2009-09-23 17:46:15 -07001226 rffid->fc4ftr_bits = fc4_ftrs;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001227 rffid->fc4_type = fc4_type;
Jing Huang7725ccf2009-09-23 17:46:15 -07001228
Jing Huangf8ceafd2009-09-25 12:29:54 -07001229 return sizeof(struct fcgs_rffid_req_s) + sizeof(struct ct_hdr_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001230}
1231
1232u16
1233fc_rspnid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
1234 u8 *name)
1235{
1236
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001237 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
Jing Huang7725ccf2009-09-23 17:46:15 -07001238 struct fcgs_rspnid_req_s *rspnid =
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001239 (struct fcgs_rspnid_req_s *)(cthdr + 1);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001240 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001241
1242 fc_gs_fchdr_build(fchs, d_id, s_id, ox_id);
1243 fc_gs_cthdr_build(cthdr, s_id, GS_RSPN_ID);
1244
Jing Huang6a18b162010-10-18 17:08:54 -07001245 memset(rspnid, 0, sizeof(struct fcgs_rspnid_req_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001246
1247 rspnid->dap = s_id;
1248 rspnid->spn_len = (u8) strlen((char *)name);
1249 strncpy((char *)rspnid->spn, (char *)name, rspnid->spn_len);
1250
Jing Huangf8ceafd2009-09-25 12:29:54 -07001251 return sizeof(struct fcgs_rspnid_req_s) + sizeof(struct ct_hdr_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001252}
1253
1254u16
Krishna Gudipatice7242b2012-08-22 19:52:43 -07001255fc_rsnn_nn_build(struct fchs_s *fchs, void *pyld, u32 s_id,
1256 wwn_t node_name, u8 *name)
1257{
1258 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1259 struct fcgs_rsnn_nn_req_s *rsnn_nn =
1260 (struct fcgs_rsnn_nn_req_s *) (cthdr + 1);
1261 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
1262
1263 fc_gs_fchdr_build(fchs, d_id, s_id, 0);
1264 fc_gs_cthdr_build(cthdr, s_id, GS_RSNN_NN);
1265
1266 memset(rsnn_nn, 0, sizeof(struct fcgs_rsnn_nn_req_s));
1267
1268 rsnn_nn->node_name = node_name;
1269 rsnn_nn->snn_len = (u8) strlen((char *)name);
1270 strncpy((char *)rsnn_nn->snn, (char *)name, rsnn_nn->snn_len);
1271
1272 return sizeof(struct fcgs_rsnn_nn_req_s) + sizeof(struct ct_hdr_s);
1273}
1274
1275u16
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001276fc_gid_ft_build(struct fchs_s *fchs, void *pyld, u32 s_id, u8 fc4_type)
Jing Huang7725ccf2009-09-23 17:46:15 -07001277{
1278
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001279 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1280 struct fcgs_gidft_req_s *gidft = (struct fcgs_gidft_req_s *)(cthdr + 1);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001281 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001282
1283 fc_gs_fchdr_build(fchs, d_id, s_id, 0);
1284
1285 fc_gs_cthdr_build(cthdr, s_id, GS_GID_FT);
1286
Jing Huang6a18b162010-10-18 17:08:54 -07001287 memset(gidft, 0, sizeof(struct fcgs_gidft_req_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001288 gidft->fc4_type = fc4_type;
1289 gidft->domain_id = 0;
1290 gidft->area_id = 0;
1291
Jing Huangf8ceafd2009-09-25 12:29:54 -07001292 return sizeof(struct fcgs_gidft_req_s) + sizeof(struct ct_hdr_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001293}
1294
1295u16
1296fc_rpnid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u32 port_id,
1297 wwn_t port_name)
1298{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001299 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1300 struct fcgs_rpnid_req_s *rpnid = (struct fcgs_rpnid_req_s *)(cthdr + 1);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001301 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001302
1303 fc_gs_fchdr_build(fchs, d_id, s_id, 0);
1304 fc_gs_cthdr_build(cthdr, s_id, GS_RPN_ID);
1305
Jing Huang6a18b162010-10-18 17:08:54 -07001306 memset(rpnid, 0, sizeof(struct fcgs_rpnid_req_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001307 rpnid->port_id = port_id;
1308 rpnid->port_name = port_name;
1309
Jing Huangf8ceafd2009-09-25 12:29:54 -07001310 return sizeof(struct fcgs_rpnid_req_s) + sizeof(struct ct_hdr_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001311}
1312
1313u16
1314fc_rnnid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u32 port_id,
1315 wwn_t node_name)
1316{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001317 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1318 struct fcgs_rnnid_req_s *rnnid = (struct fcgs_rnnid_req_s *)(cthdr + 1);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001319 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001320
1321 fc_gs_fchdr_build(fchs, d_id, s_id, 0);
1322 fc_gs_cthdr_build(cthdr, s_id, GS_RNN_ID);
1323
Jing Huang6a18b162010-10-18 17:08:54 -07001324 memset(rnnid, 0, sizeof(struct fcgs_rnnid_req_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001325 rnnid->port_id = port_id;
1326 rnnid->node_name = node_name;
1327
Jing Huangf8ceafd2009-09-25 12:29:54 -07001328 return sizeof(struct fcgs_rnnid_req_s) + sizeof(struct ct_hdr_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001329}
1330
1331u16
1332fc_rcsid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u32 port_id,
1333 u32 cos)
1334{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001335 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
Jing Huang7725ccf2009-09-23 17:46:15 -07001336 struct fcgs_rcsid_req_s *rcsid =
1337 (struct fcgs_rcsid_req_s *) (cthdr + 1);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001338 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001339
1340 fc_gs_fchdr_build(fchs, d_id, s_id, 0);
1341 fc_gs_cthdr_build(cthdr, s_id, GS_RCS_ID);
1342
Jing Huang6a18b162010-10-18 17:08:54 -07001343 memset(rcsid, 0, sizeof(struct fcgs_rcsid_req_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001344 rcsid->port_id = port_id;
1345 rcsid->cos = cos;
1346
Jing Huangf8ceafd2009-09-25 12:29:54 -07001347 return sizeof(struct fcgs_rcsid_req_s) + sizeof(struct ct_hdr_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001348}
1349
1350u16
1351fc_rptid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u32 port_id,
1352 u8 port_type)
1353{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001354 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1355 struct fcgs_rptid_req_s *rptid = (struct fcgs_rptid_req_s *)(cthdr + 1);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001356 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001357
1358 fc_gs_fchdr_build(fchs, d_id, s_id, 0);
1359 fc_gs_cthdr_build(cthdr, s_id, GS_RPT_ID);
1360
Jing Huang6a18b162010-10-18 17:08:54 -07001361 memset(rptid, 0, sizeof(struct fcgs_rptid_req_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001362 rptid->port_id = port_id;
1363 rptid->port_type = port_type;
1364
Jing Huangf8ceafd2009-09-25 12:29:54 -07001365 return sizeof(struct fcgs_rptid_req_s) + sizeof(struct ct_hdr_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001366}
1367
1368u16
1369fc_ganxt_build(struct fchs_s *fchs, void *pyld, u32 s_id, u32 port_id)
1370{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001371 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1372 struct fcgs_ganxt_req_s *ganxt = (struct fcgs_ganxt_req_s *)(cthdr + 1);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001373 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001374
1375 fc_gs_fchdr_build(fchs, d_id, s_id, 0);
1376 fc_gs_cthdr_build(cthdr, s_id, GS_GA_NXT);
1377
Jing Huang6a18b162010-10-18 17:08:54 -07001378 memset(ganxt, 0, sizeof(struct fcgs_ganxt_req_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001379 ganxt->port_id = port_id;
1380
Jing Huangf8ceafd2009-09-25 12:29:54 -07001381 return sizeof(struct ct_hdr_s) + sizeof(struct fcgs_ganxt_req_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001382}
1383
1384/*
1385 * Builds fc hdr and ct hdr for FDMI requests.
1386 */
1387u16
1388fc_fdmi_reqhdr_build(struct fchs_s *fchs, void *pyld, u32 s_id,
1389 u16 cmd_code)
1390{
1391
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001392 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
Maggie Zhangf16a1752010-12-09 19:12:32 -08001393 u32 d_id = bfa_hton3b(FC_MGMT_SERVER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001394
1395 fc_gs_fchdr_build(fchs, d_id, s_id, 0);
1396 fc_gs_fdmi_cthdr_build(cthdr, s_id, cmd_code);
1397
Jing Huangf8ceafd2009-09-25 12:29:54 -07001398 return sizeof(struct ct_hdr_s);
Jing Huang7725ccf2009-09-23 17:46:15 -07001399}
1400
1401/*
1402 * Given a FC4 Type, this function returns a fc4 type bitmask
1403 */
1404void
1405fc_get_fc4type_bitmask(u8 fc4_type, u8 *bit_mask)
1406{
1407 u8 index;
Maggie50444a32010-11-29 18:26:32 -08001408 __be32 *ptr = (__be32 *) bit_mask;
Jing Huang7725ccf2009-09-23 17:46:15 -07001409 u32 type_value;
1410
1411 /*
1412 * @todo : Check for bitmask size
1413 */
1414
1415 index = fc4_type >> 5;
1416 type_value = 1 << (fc4_type % 32);
Jing Huangba816ea2010-10-18 17:10:50 -07001417 ptr[index] = cpu_to_be32(type_value);
Jing Huang7725ccf2009-09-23 17:46:15 -07001418
1419}
1420
1421/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001422 * GMAL Request
Jing Huang7725ccf2009-09-23 17:46:15 -07001423 */
1424u16
1425fc_gmal_req_build(struct fchs_s *fchs, void *pyld, u32 s_id, wwn_t wwn)
1426{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001427 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
Jing Huang7725ccf2009-09-23 17:46:15 -07001428 fcgs_gmal_req_t *gmal = (fcgs_gmal_req_t *) (cthdr + 1);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001429 u32 d_id = bfa_hton3b(FC_MGMT_SERVER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001430
1431 fc_gs_fchdr_build(fchs, d_id, s_id, 0);
1432 fc_gs_ms_cthdr_build(cthdr, s_id, GS_FC_GMAL_CMD,
1433 CT_GSSUBTYPE_CFGSERVER);
1434
Jing Huang6a18b162010-10-18 17:08:54 -07001435 memset(gmal, 0, sizeof(fcgs_gmal_req_t));
Jing Huang7725ccf2009-09-23 17:46:15 -07001436 gmal->wwn = wwn;
1437
Jing Huangf8ceafd2009-09-25 12:29:54 -07001438 return sizeof(struct ct_hdr_s) + sizeof(fcgs_gmal_req_t);
Jing Huang7725ccf2009-09-23 17:46:15 -07001439}
1440
1441/*
1442 * GFN (Get Fabric Name) Request
1443 */
1444u16
1445fc_gfn_req_build(struct fchs_s *fchs, void *pyld, u32 s_id, wwn_t wwn)
1446{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001447 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
Jing Huang7725ccf2009-09-23 17:46:15 -07001448 fcgs_gfn_req_t *gfn = (fcgs_gfn_req_t *) (cthdr + 1);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001449 u32 d_id = bfa_hton3b(FC_MGMT_SERVER);
Jing Huang7725ccf2009-09-23 17:46:15 -07001450
1451 fc_gs_fchdr_build(fchs, d_id, s_id, 0);
1452 fc_gs_ms_cthdr_build(cthdr, s_id, GS_FC_GFN_CMD,
1453 CT_GSSUBTYPE_CFGSERVER);
1454
Jing Huang6a18b162010-10-18 17:08:54 -07001455 memset(gfn, 0, sizeof(fcgs_gfn_req_t));
Jing Huang7725ccf2009-09-23 17:46:15 -07001456 gfn->wwn = wwn;
1457
Jing Huangf8ceafd2009-09-25 12:29:54 -07001458 return sizeof(struct ct_hdr_s) + sizeof(fcgs_gfn_req_t);
Jing Huang7725ccf2009-09-23 17:46:15 -07001459}