Linux 5.1.15
[linux/fpc-iii.git] / drivers / scsi / bfa / bfa_fcbuild.c
blob2de5d514e99ca1f9a0787179be6d4955d5a2989f
1 /*
2 * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
3 * Copyright (c) 2014- QLogic Corporation.
4 * All rights reserved
5 * www.qlogic.com
7 * Linux driver for QLogic BR-series Fibre Channel Host Bus Adapter.
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License (GPL) Version 2 as
11 * published by the Free Software Foundation
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
19 * fcbuild.c - FC link service frame building and parsing routines
22 #include "bfad_drv.h"
23 #include "bfa_fcbuild.h"
26 * static build functions
28 static void fc_els_rsp_build(struct fchs_s *fchs, u32 d_id, u32 s_id,
29 __be16 ox_id);
30 static void fc_bls_rsp_build(struct fchs_s *fchs, u32 d_id, u32 s_id,
31 __be16 ox_id);
32 static struct fchs_s fc_els_req_tmpl;
33 static struct fchs_s fc_els_rsp_tmpl;
34 static struct fchs_s fc_bls_req_tmpl;
35 static struct fchs_s fc_bls_rsp_tmpl;
36 static struct fc_ba_acc_s ba_acc_tmpl;
37 static struct fc_logi_s plogi_tmpl;
38 static struct fc_prli_s prli_tmpl;
39 static struct fc_rrq_s rrq_tmpl;
40 static struct fchs_s fcp_fchs_tmpl;
42 void
43 fcbuild_init(void)
46 * fc_els_req_tmpl
48 fc_els_req_tmpl.routing = FC_RTG_EXT_LINK;
49 fc_els_req_tmpl.cat_info = FC_CAT_LD_REQUEST;
50 fc_els_req_tmpl.type = FC_TYPE_ELS;
51 fc_els_req_tmpl.f_ctl =
52 bfa_hton3b(FCTL_SEQ_INI | FCTL_FS_EXCH | FCTL_END_SEQ |
53 FCTL_SI_XFER);
54 fc_els_req_tmpl.rx_id = FC_RXID_ANY;
57 * fc_els_rsp_tmpl
59 fc_els_rsp_tmpl.routing = FC_RTG_EXT_LINK;
60 fc_els_rsp_tmpl.cat_info = FC_CAT_LD_REPLY;
61 fc_els_rsp_tmpl.type = FC_TYPE_ELS;
62 fc_els_rsp_tmpl.f_ctl =
63 bfa_hton3b(FCTL_EC_RESP | FCTL_SEQ_INI | FCTL_LS_EXCH |
64 FCTL_END_SEQ | FCTL_SI_XFER);
65 fc_els_rsp_tmpl.rx_id = FC_RXID_ANY;
68 * fc_bls_req_tmpl
70 fc_bls_req_tmpl.routing = FC_RTG_BASIC_LINK;
71 fc_bls_req_tmpl.type = FC_TYPE_BLS;
72 fc_bls_req_tmpl.f_ctl = bfa_hton3b(FCTL_END_SEQ | FCTL_SI_XFER);
73 fc_bls_req_tmpl.rx_id = FC_RXID_ANY;
76 * fc_bls_rsp_tmpl
78 fc_bls_rsp_tmpl.routing = FC_RTG_BASIC_LINK;
79 fc_bls_rsp_tmpl.cat_info = FC_CAT_BA_ACC;
80 fc_bls_rsp_tmpl.type = FC_TYPE_BLS;
81 fc_bls_rsp_tmpl.f_ctl =
82 bfa_hton3b(FCTL_EC_RESP | FCTL_SEQ_INI | FCTL_LS_EXCH |
83 FCTL_END_SEQ | FCTL_SI_XFER);
84 fc_bls_rsp_tmpl.rx_id = FC_RXID_ANY;
87 * ba_acc_tmpl
89 ba_acc_tmpl.seq_id_valid = 0;
90 ba_acc_tmpl.low_seq_cnt = 0;
91 ba_acc_tmpl.high_seq_cnt = 0xFFFF;
94 * plogi_tmpl
96 plogi_tmpl.csp.verhi = FC_PH_VER_PH_3;
97 plogi_tmpl.csp.verlo = FC_PH_VER_4_3;
98 plogi_tmpl.csp.ciro = 0x1;
99 plogi_tmpl.csp.cisc = 0x0;
100 plogi_tmpl.csp.altbbcred = 0x0;
101 plogi_tmpl.csp.conseq = cpu_to_be16(0x00FF);
102 plogi_tmpl.csp.ro_bitmap = cpu_to_be16(0x0002);
103 plogi_tmpl.csp.e_d_tov = cpu_to_be32(2000);
105 plogi_tmpl.class3.class_valid = 1;
106 plogi_tmpl.class3.sequential = 1;
107 plogi_tmpl.class3.conseq = 0xFF;
108 plogi_tmpl.class3.ospx = 1;
111 * prli_tmpl
113 prli_tmpl.command = FC_ELS_PRLI;
114 prli_tmpl.pglen = 0x10;
115 prli_tmpl.pagebytes = cpu_to_be16(0x0014);
116 prli_tmpl.parampage.type = FC_TYPE_FCP;
117 prli_tmpl.parampage.imagepair = 1;
118 prli_tmpl.parampage.servparams.rxrdisab = 1;
121 * rrq_tmpl
123 rrq_tmpl.els_cmd.els_code = FC_ELS_RRQ;
126 * fcp_struct fchs_s mpl
128 fcp_fchs_tmpl.routing = FC_RTG_FC4_DEV_DATA;
129 fcp_fchs_tmpl.cat_info = FC_CAT_UNSOLICIT_CMD;
130 fcp_fchs_tmpl.type = FC_TYPE_FCP;
131 fcp_fchs_tmpl.f_ctl =
132 bfa_hton3b(FCTL_FS_EXCH | FCTL_END_SEQ | FCTL_SI_XFER);
133 fcp_fchs_tmpl.seq_id = 1;
134 fcp_fchs_tmpl.rx_id = FC_RXID_ANY;
137 static void
138 fc_gs_fchdr_build(struct fchs_s *fchs, u32 d_id, u32 s_id, u32 ox_id)
140 memset(fchs, 0, sizeof(struct fchs_s));
142 fchs->routing = FC_RTG_FC4_DEV_DATA;
143 fchs->cat_info = FC_CAT_UNSOLICIT_CTRL;
144 fchs->type = FC_TYPE_SERVICES;
145 fchs->f_ctl =
146 bfa_hton3b(FCTL_SEQ_INI | FCTL_FS_EXCH | FCTL_END_SEQ |
147 FCTL_SI_XFER);
148 fchs->rx_id = FC_RXID_ANY;
149 fchs->d_id = (d_id);
150 fchs->s_id = (s_id);
151 fchs->ox_id = cpu_to_be16(ox_id);
154 * @todo no need to set ox_id for request
155 * no need to set rx_id for response
159 static void
160 fc_gsresp_fchdr_build(struct fchs_s *fchs, u32 d_id, u32 s_id, u16 ox_id)
162 memset(fchs, 0, sizeof(struct fchs_s));
164 fchs->routing = FC_RTG_FC4_DEV_DATA;
165 fchs->cat_info = FC_CAT_SOLICIT_CTRL;
166 fchs->type = FC_TYPE_SERVICES;
167 fchs->f_ctl =
168 bfa_hton3b(FCTL_EC_RESP | FCTL_SEQ_INI | FCTL_LS_EXCH |
169 FCTL_END_SEQ | FCTL_SI_XFER);
170 fchs->d_id = d_id;
171 fchs->s_id = s_id;
172 fchs->ox_id = ox_id;
175 void
176 fc_els_req_build(struct fchs_s *fchs, u32 d_id, u32 s_id, __be16 ox_id)
178 memcpy(fchs, &fc_els_req_tmpl, sizeof(struct fchs_s));
179 fchs->d_id = (d_id);
180 fchs->s_id = (s_id);
181 fchs->ox_id = cpu_to_be16(ox_id);
184 static void
185 fc_els_rsp_build(struct fchs_s *fchs, u32 d_id, u32 s_id, __be16 ox_id)
187 memcpy(fchs, &fc_els_rsp_tmpl, sizeof(struct fchs_s));
188 fchs->d_id = d_id;
189 fchs->s_id = s_id;
190 fchs->ox_id = ox_id;
193 static void
194 fc_bls_rsp_build(struct fchs_s *fchs, u32 d_id, u32 s_id, __be16 ox_id)
196 memcpy(fchs, &fc_bls_rsp_tmpl, sizeof(struct fchs_s));
197 fchs->d_id = d_id;
198 fchs->s_id = s_id;
199 fchs->ox_id = ox_id;
202 static u16
203 fc_plogi_x_build(struct fchs_s *fchs, void *pld, u32 d_id, u32 s_id,
204 __be16 ox_id, wwn_t port_name, wwn_t node_name,
205 u16 pdu_size, u16 bb_cr, u8 els_code)
207 struct fc_logi_s *plogi = (struct fc_logi_s *) (pld);
209 memcpy(plogi, &plogi_tmpl, sizeof(struct fc_logi_s));
211 /* For FC AL bb_cr is 0 and altbbcred is 1 */
212 if (!bb_cr)
213 plogi->csp.altbbcred = 1;
215 plogi->els_cmd.els_code = els_code;
216 if (els_code == FC_ELS_PLOGI)
217 fc_els_req_build(fchs, d_id, s_id, ox_id);
218 else
219 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
221 plogi->csp.rxsz = plogi->class3.rxsz = cpu_to_be16(pdu_size);
222 plogi->csp.bbcred = cpu_to_be16(bb_cr);
224 memcpy(&plogi->port_name, &port_name, sizeof(wwn_t));
225 memcpy(&plogi->node_name, &node_name, sizeof(wwn_t));
227 return sizeof(struct fc_logi_s);
231 fc_flogi_build(struct fchs_s *fchs, struct fc_logi_s *flogi, u32 s_id,
232 u16 ox_id, wwn_t port_name, wwn_t node_name, u16 pdu_size,
233 u8 set_npiv, u8 set_auth, u16 local_bb_credits)
235 u32 d_id = bfa_hton3b(FC_FABRIC_PORT);
236 __be32 *vvl_info;
238 memcpy(flogi, &plogi_tmpl, sizeof(struct fc_logi_s));
240 flogi->els_cmd.els_code = FC_ELS_FLOGI;
241 fc_els_req_build(fchs, d_id, s_id, ox_id);
243 flogi->csp.rxsz = flogi->class3.rxsz = cpu_to_be16(pdu_size);
244 flogi->port_name = port_name;
245 flogi->node_name = node_name;
248 * Set the NPIV Capability Bit ( word 1, bit 31) of Common
249 * Service Parameters.
251 flogi->csp.ciro = set_npiv;
253 /* set AUTH capability */
254 flogi->csp.security = set_auth;
256 flogi->csp.bbcred = cpu_to_be16(local_bb_credits);
258 /* Set brcd token in VVL */
259 vvl_info = (u32 *)&flogi->vvl[0];
261 /* set the flag to indicate the presence of VVL */
262 flogi->csp.npiv_supp = 1; /* @todo. field name is not correct */
263 vvl_info[0] = cpu_to_be32(FLOGI_VVL_BRCD);
265 return sizeof(struct fc_logi_s);
269 fc_flogi_acc_build(struct fchs_s *fchs, struct fc_logi_s *flogi, u32 s_id,
270 __be16 ox_id, wwn_t port_name, wwn_t node_name,
271 u16 pdu_size, u16 local_bb_credits, u8 bb_scn)
273 u32 d_id = 0;
274 u16 bbscn_rxsz = (bb_scn << 12) | pdu_size;
276 memcpy(flogi, &plogi_tmpl, sizeof(struct fc_logi_s));
277 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
279 flogi->els_cmd.els_code = FC_ELS_ACC;
280 flogi->class3.rxsz = cpu_to_be16(pdu_size);
281 flogi->csp.rxsz = cpu_to_be16(bbscn_rxsz); /* bb_scn/rxsz */
282 flogi->port_name = port_name;
283 flogi->node_name = node_name;
285 flogi->csp.bbcred = cpu_to_be16(local_bb_credits);
287 return sizeof(struct fc_logi_s);
291 fc_fdisc_build(struct fchs_s *fchs, struct fc_logi_s *flogi, u32 s_id,
292 u16 ox_id, wwn_t port_name, wwn_t node_name, u16 pdu_size)
294 u32 d_id = bfa_hton3b(FC_FABRIC_PORT);
296 memcpy(flogi, &plogi_tmpl, sizeof(struct fc_logi_s));
298 flogi->els_cmd.els_code = FC_ELS_FDISC;
299 fc_els_req_build(fchs, d_id, s_id, ox_id);
301 flogi->csp.rxsz = flogi->class3.rxsz = cpu_to_be16(pdu_size);
302 flogi->port_name = port_name;
303 flogi->node_name = node_name;
305 return sizeof(struct fc_logi_s);
309 fc_plogi_build(struct fchs_s *fchs, void *pld, u32 d_id, u32 s_id,
310 u16 ox_id, wwn_t port_name, wwn_t node_name,
311 u16 pdu_size, u16 bb_cr)
313 return fc_plogi_x_build(fchs, pld, d_id, s_id, ox_id, port_name,
314 node_name, pdu_size, bb_cr, FC_ELS_PLOGI);
318 fc_plogi_acc_build(struct fchs_s *fchs, void *pld, u32 d_id, u32 s_id,
319 u16 ox_id, wwn_t port_name, wwn_t node_name,
320 u16 pdu_size, u16 bb_cr)
322 return fc_plogi_x_build(fchs, pld, d_id, s_id, ox_id, port_name,
323 node_name, pdu_size, bb_cr, FC_ELS_ACC);
326 enum fc_parse_status
327 fc_plogi_rsp_parse(struct fchs_s *fchs, int len, wwn_t port_name)
329 struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
330 struct fc_logi_s *plogi;
331 struct fc_ls_rjt_s *ls_rjt;
333 switch (els_cmd->els_code) {
334 case FC_ELS_LS_RJT:
335 ls_rjt = (struct fc_ls_rjt_s *) (fchs + 1);
336 if (ls_rjt->reason_code == FC_LS_RJT_RSN_LOGICAL_BUSY)
337 return FC_PARSE_BUSY;
338 else
339 return FC_PARSE_FAILURE;
340 case FC_ELS_ACC:
341 plogi = (struct fc_logi_s *) (fchs + 1);
342 if (len < sizeof(struct fc_logi_s))
343 return FC_PARSE_FAILURE;
345 if (!wwn_is_equal(plogi->port_name, port_name))
346 return FC_PARSE_FAILURE;
348 if (!plogi->class3.class_valid)
349 return FC_PARSE_FAILURE;
351 if (be16_to_cpu(plogi->class3.rxsz) < (FC_MIN_PDUSZ))
352 return FC_PARSE_FAILURE;
354 return FC_PARSE_OK;
355 default:
356 return FC_PARSE_FAILURE;
360 enum fc_parse_status
361 fc_plogi_parse(struct fchs_s *fchs)
363 struct fc_logi_s *plogi = (struct fc_logi_s *) (fchs + 1);
365 if (plogi->class3.class_valid != 1)
366 return FC_PARSE_FAILURE;
368 if ((be16_to_cpu(plogi->class3.rxsz) < FC_MIN_PDUSZ)
369 || (be16_to_cpu(plogi->class3.rxsz) > FC_MAX_PDUSZ)
370 || (plogi->class3.rxsz == 0))
371 return FC_PARSE_FAILURE;
373 return FC_PARSE_OK;
377 fc_prli_build(struct fchs_s *fchs, void *pld, u32 d_id, u32 s_id,
378 u16 ox_id)
380 struct fc_prli_s *prli = (struct fc_prli_s *) (pld);
382 fc_els_req_build(fchs, d_id, s_id, ox_id);
383 memcpy(prli, &prli_tmpl, sizeof(struct fc_prli_s));
385 prli->command = FC_ELS_PRLI;
386 prli->parampage.servparams.initiator = 1;
387 prli->parampage.servparams.retry = 1;
388 prli->parampage.servparams.rec_support = 1;
389 prli->parampage.servparams.task_retry_id = 0;
390 prli->parampage.servparams.confirm = 1;
392 return sizeof(struct fc_prli_s);
396 fc_prli_acc_build(struct fchs_s *fchs, void *pld, u32 d_id, u32 s_id,
397 __be16 ox_id, enum bfa_lport_role role)
399 struct fc_prli_s *prli = (struct fc_prli_s *) (pld);
401 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
402 memcpy(prli, &prli_tmpl, sizeof(struct fc_prli_s));
404 prli->command = FC_ELS_ACC;
406 prli->parampage.servparams.initiator = 1;
408 prli->parampage.rspcode = FC_PRLI_ACC_XQTD;
410 return sizeof(struct fc_prli_s);
413 enum fc_parse_status
414 fc_prli_rsp_parse(struct fc_prli_s *prli, int len)
416 if (len < sizeof(struct fc_prli_s))
417 return FC_PARSE_FAILURE;
419 if (prli->command != FC_ELS_ACC)
420 return FC_PARSE_FAILURE;
422 if ((prli->parampage.rspcode != FC_PRLI_ACC_XQTD)
423 && (prli->parampage.rspcode != FC_PRLI_ACC_PREDEF_IMG))
424 return FC_PARSE_FAILURE;
426 if (prli->parampage.servparams.target != 1)
427 return FC_PARSE_FAILURE;
429 return FC_PARSE_OK;
432 enum fc_parse_status
433 fc_prli_parse(struct fc_prli_s *prli)
435 if (prli->parampage.type != FC_TYPE_FCP)
436 return FC_PARSE_FAILURE;
438 if (!prli->parampage.imagepair)
439 return FC_PARSE_FAILURE;
441 if (!prli->parampage.servparams.initiator)
442 return FC_PARSE_FAILURE;
444 return FC_PARSE_OK;
448 fc_logo_build(struct fchs_s *fchs, struct fc_logo_s *logo, u32 d_id, u32 s_id,
449 u16 ox_id, wwn_t port_name)
451 fc_els_req_build(fchs, d_id, s_id, ox_id);
453 memset(logo, '\0', sizeof(struct fc_logo_s));
454 logo->els_cmd.els_code = FC_ELS_LOGO;
455 logo->nport_id = (s_id);
456 logo->orig_port_name = port_name;
458 return sizeof(struct fc_logo_s);
461 static u16
462 fc_adisc_x_build(struct fchs_s *fchs, struct fc_adisc_s *adisc, u32 d_id,
463 u32 s_id, __be16 ox_id, wwn_t port_name,
464 wwn_t node_name, u8 els_code)
466 memset(adisc, '\0', sizeof(struct fc_adisc_s));
468 adisc->els_cmd.els_code = els_code;
470 if (els_code == FC_ELS_ADISC)
471 fc_els_req_build(fchs, d_id, s_id, ox_id);
472 else
473 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
475 adisc->orig_HA = 0;
476 adisc->orig_port_name = port_name;
477 adisc->orig_node_name = node_name;
478 adisc->nport_id = (s_id);
480 return sizeof(struct fc_adisc_s);
484 fc_adisc_build(struct fchs_s *fchs, struct fc_adisc_s *adisc, u32 d_id,
485 u32 s_id, __be16 ox_id, wwn_t port_name, wwn_t node_name)
487 return fc_adisc_x_build(fchs, adisc, d_id, s_id, ox_id, port_name,
488 node_name, FC_ELS_ADISC);
492 fc_adisc_acc_build(struct fchs_s *fchs, struct fc_adisc_s *adisc, u32 d_id,
493 u32 s_id, __be16 ox_id, wwn_t port_name,
494 wwn_t node_name)
496 return fc_adisc_x_build(fchs, adisc, d_id, s_id, ox_id, port_name,
497 node_name, FC_ELS_ACC);
500 enum fc_parse_status
501 fc_adisc_rsp_parse(struct fc_adisc_s *adisc, int len, wwn_t port_name,
502 wwn_t node_name)
505 if (len < sizeof(struct fc_adisc_s))
506 return FC_PARSE_FAILURE;
508 if (adisc->els_cmd.els_code != FC_ELS_ACC)
509 return FC_PARSE_FAILURE;
511 if (!wwn_is_equal(adisc->orig_port_name, port_name))
512 return FC_PARSE_FAILURE;
514 return FC_PARSE_OK;
517 enum fc_parse_status
518 fc_adisc_parse(struct fchs_s *fchs, void *pld, u32 host_dap, wwn_t node_name,
519 wwn_t port_name)
521 struct fc_adisc_s *adisc = (struct fc_adisc_s *) pld;
523 if (adisc->els_cmd.els_code != FC_ELS_ACC)
524 return FC_PARSE_FAILURE;
526 if ((adisc->nport_id == (host_dap))
527 && wwn_is_equal(adisc->orig_port_name, port_name)
528 && wwn_is_equal(adisc->orig_node_name, node_name))
529 return FC_PARSE_OK;
531 return FC_PARSE_FAILURE;
534 enum fc_parse_status
535 fc_pdisc_parse(struct fchs_s *fchs, wwn_t node_name, wwn_t port_name)
537 struct fc_logi_s *pdisc = (struct fc_logi_s *) (fchs + 1);
539 if (pdisc->class3.class_valid != 1)
540 return FC_PARSE_FAILURE;
542 if ((be16_to_cpu(pdisc->class3.rxsz) <
543 (FC_MIN_PDUSZ - sizeof(struct fchs_s)))
544 || (pdisc->class3.rxsz == 0))
545 return FC_PARSE_FAILURE;
547 if (!wwn_is_equal(pdisc->port_name, port_name))
548 return FC_PARSE_FAILURE;
550 if (!wwn_is_equal(pdisc->node_name, node_name))
551 return FC_PARSE_FAILURE;
553 return FC_PARSE_OK;
557 fc_abts_build(struct fchs_s *fchs, u32 d_id, u32 s_id, u16 ox_id)
559 memcpy(fchs, &fc_bls_req_tmpl, sizeof(struct fchs_s));
560 fchs->cat_info = FC_CAT_ABTS;
561 fchs->d_id = (d_id);
562 fchs->s_id = (s_id);
563 fchs->ox_id = cpu_to_be16(ox_id);
565 return sizeof(struct fchs_s);
568 enum fc_parse_status
569 fc_abts_rsp_parse(struct fchs_s *fchs, int len)
571 if ((fchs->cat_info == FC_CAT_BA_ACC)
572 || (fchs->cat_info == FC_CAT_BA_RJT))
573 return FC_PARSE_OK;
575 return FC_PARSE_FAILURE;
579 fc_rrq_build(struct fchs_s *fchs, struct fc_rrq_s *rrq, u32 d_id, u32 s_id,
580 u16 ox_id, u16 rrq_oxid)
582 fc_els_req_build(fchs, d_id, s_id, ox_id);
585 * build rrq payload
587 memcpy(rrq, &rrq_tmpl, sizeof(struct fc_rrq_s));
588 rrq->s_id = (s_id);
589 rrq->ox_id = cpu_to_be16(rrq_oxid);
590 rrq->rx_id = FC_RXID_ANY;
592 return sizeof(struct fc_rrq_s);
596 fc_logo_acc_build(struct fchs_s *fchs, void *pld, u32 d_id, u32 s_id,
597 __be16 ox_id)
599 struct fc_els_cmd_s *acc = pld;
601 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
603 memset(acc, 0, sizeof(struct fc_els_cmd_s));
604 acc->els_code = FC_ELS_ACC;
606 return sizeof(struct fc_els_cmd_s);
610 fc_ls_rjt_build(struct fchs_s *fchs, struct fc_ls_rjt_s *ls_rjt, u32 d_id,
611 u32 s_id, __be16 ox_id, u8 reason_code,
612 u8 reason_code_expl)
614 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
615 memset(ls_rjt, 0, sizeof(struct fc_ls_rjt_s));
617 ls_rjt->els_cmd.els_code = FC_ELS_LS_RJT;
618 ls_rjt->reason_code = reason_code;
619 ls_rjt->reason_code_expl = reason_code_expl;
620 ls_rjt->vendor_unique = 0x00;
622 return sizeof(struct fc_ls_rjt_s);
626 fc_ba_acc_build(struct fchs_s *fchs, struct fc_ba_acc_s *ba_acc, u32 d_id,
627 u32 s_id, __be16 ox_id, u16 rx_id)
629 fc_bls_rsp_build(fchs, d_id, s_id, ox_id);
631 memcpy(ba_acc, &ba_acc_tmpl, sizeof(struct fc_ba_acc_s));
633 fchs->rx_id = rx_id;
635 ba_acc->ox_id = fchs->ox_id;
636 ba_acc->rx_id = fchs->rx_id;
638 return sizeof(struct fc_ba_acc_s);
642 fc_ls_acc_build(struct fchs_s *fchs, struct fc_els_cmd_s *els_cmd, u32 d_id,
643 u32 s_id, __be16 ox_id)
645 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
646 memset(els_cmd, 0, sizeof(struct fc_els_cmd_s));
647 els_cmd->els_code = FC_ELS_ACC;
649 return sizeof(struct fc_els_cmd_s);
653 fc_logout_params_pages(struct fchs_s *fc_frame, u8 els_code)
655 int num_pages = 0;
656 struct fc_prlo_s *prlo;
657 struct fc_tprlo_s *tprlo;
659 if (els_code == FC_ELS_PRLO) {
660 prlo = (struct fc_prlo_s *) (fc_frame + 1);
661 num_pages = (be16_to_cpu(prlo->payload_len) - 4) / 16;
662 } else {
663 tprlo = (struct fc_tprlo_s *) (fc_frame + 1);
664 num_pages = (be16_to_cpu(tprlo->payload_len) - 4) / 16;
666 return num_pages;
670 fc_tprlo_acc_build(struct fchs_s *fchs, struct fc_tprlo_acc_s *tprlo_acc,
671 u32 d_id, u32 s_id, __be16 ox_id, int num_pages)
673 int page;
675 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
677 memset(tprlo_acc, 0, (num_pages * 16) + 4);
678 tprlo_acc->command = FC_ELS_ACC;
680 tprlo_acc->page_len = 0x10;
681 tprlo_acc->payload_len = cpu_to_be16((num_pages * 16) + 4);
683 for (page = 0; page < num_pages; page++) {
684 tprlo_acc->tprlo_acc_params[page].opa_valid = 0;
685 tprlo_acc->tprlo_acc_params[page].rpa_valid = 0;
686 tprlo_acc->tprlo_acc_params[page].fc4type_csp = FC_TYPE_FCP;
687 tprlo_acc->tprlo_acc_params[page].orig_process_assc = 0;
688 tprlo_acc->tprlo_acc_params[page].resp_process_assc = 0;
690 return be16_to_cpu(tprlo_acc->payload_len);
694 fc_prlo_acc_build(struct fchs_s *fchs, struct fc_prlo_acc_s *prlo_acc, u32 d_id,
695 u32 s_id, __be16 ox_id, int num_pages)
697 int page;
699 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
701 memset(prlo_acc, 0, (num_pages * 16) + 4);
702 prlo_acc->command = FC_ELS_ACC;
703 prlo_acc->page_len = 0x10;
704 prlo_acc->payload_len = cpu_to_be16((num_pages * 16) + 4);
706 for (page = 0; page < num_pages; page++) {
707 prlo_acc->prlo_acc_params[page].opa_valid = 0;
708 prlo_acc->prlo_acc_params[page].rpa_valid = 0;
709 prlo_acc->prlo_acc_params[page].fc4type_csp = FC_TYPE_FCP;
710 prlo_acc->prlo_acc_params[page].orig_process_assc = 0;
711 prlo_acc->prlo_acc_params[page].resp_process_assc = 0;
714 return be16_to_cpu(prlo_acc->payload_len);
718 fc_rnid_build(struct fchs_s *fchs, struct fc_rnid_cmd_s *rnid, u32 d_id,
719 u32 s_id, u16 ox_id, u32 data_format)
721 fc_els_req_build(fchs, d_id, s_id, ox_id);
723 memset(rnid, 0, sizeof(struct fc_rnid_cmd_s));
725 rnid->els_cmd.els_code = FC_ELS_RNID;
726 rnid->node_id_data_format = data_format;
728 return sizeof(struct fc_rnid_cmd_s);
732 fc_rnid_acc_build(struct fchs_s *fchs, struct fc_rnid_acc_s *rnid_acc, u32 d_id,
733 u32 s_id, __be16 ox_id, u32 data_format,
734 struct fc_rnid_common_id_data_s *common_id_data,
735 struct fc_rnid_general_topology_data_s *gen_topo_data)
737 memset(rnid_acc, 0, sizeof(struct fc_rnid_acc_s));
739 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
741 rnid_acc->els_cmd.els_code = FC_ELS_ACC;
742 rnid_acc->node_id_data_format = data_format;
743 rnid_acc->common_id_data_length =
744 sizeof(struct fc_rnid_common_id_data_s);
745 rnid_acc->common_id_data = *common_id_data;
747 if (data_format == RNID_NODEID_DATA_FORMAT_DISCOVERY) {
748 rnid_acc->specific_id_data_length =
749 sizeof(struct fc_rnid_general_topology_data_s);
750 rnid_acc->gen_topology_data = *gen_topo_data;
751 return sizeof(struct fc_rnid_acc_s);
752 } else {
753 return sizeof(struct fc_rnid_acc_s) -
754 sizeof(struct fc_rnid_general_topology_data_s);
760 fc_rpsc_build(struct fchs_s *fchs, struct fc_rpsc_cmd_s *rpsc, u32 d_id,
761 u32 s_id, u16 ox_id)
763 fc_els_req_build(fchs, d_id, s_id, ox_id);
765 memset(rpsc, 0, sizeof(struct fc_rpsc_cmd_s));
767 rpsc->els_cmd.els_code = FC_ELS_RPSC;
768 return sizeof(struct fc_rpsc_cmd_s);
772 fc_rpsc2_build(struct fchs_s *fchs, struct fc_rpsc2_cmd_s *rpsc2, u32 d_id,
773 u32 s_id, u32 *pid_list, u16 npids)
775 u32 dctlr_id = FC_DOMAIN_CTRLR(bfa_hton3b(d_id));
776 int i = 0;
778 fc_els_req_build(fchs, bfa_hton3b(dctlr_id), s_id, 0);
780 memset(rpsc2, 0, sizeof(struct fc_rpsc2_cmd_s));
782 rpsc2->els_cmd.els_code = FC_ELS_RPSC;
783 rpsc2->token = cpu_to_be32(FC_BRCD_TOKEN);
784 rpsc2->num_pids = cpu_to_be16(npids);
785 for (i = 0; i < npids; i++)
786 rpsc2->pid_list[i].pid = pid_list[i];
788 return sizeof(struct fc_rpsc2_cmd_s) + ((npids - 1) * (sizeof(u32)));
792 fc_rpsc_acc_build(struct fchs_s *fchs, struct fc_rpsc_acc_s *rpsc_acc,
793 u32 d_id, u32 s_id, __be16 ox_id,
794 struct fc_rpsc_speed_info_s *oper_speed)
796 memset(rpsc_acc, 0, sizeof(struct fc_rpsc_acc_s));
798 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
800 rpsc_acc->command = FC_ELS_ACC;
801 rpsc_acc->num_entries = cpu_to_be16(1);
803 rpsc_acc->speed_info[0].port_speed_cap =
804 cpu_to_be16(oper_speed->port_speed_cap);
806 rpsc_acc->speed_info[0].port_op_speed =
807 cpu_to_be16(oper_speed->port_op_speed);
809 return sizeof(struct fc_rpsc_acc_s);
813 fc_pdisc_build(struct fchs_s *fchs, u32 d_id, u32 s_id, u16 ox_id,
814 wwn_t port_name, wwn_t node_name, u16 pdu_size)
816 struct fc_logi_s *pdisc = (struct fc_logi_s *) (fchs + 1);
818 memcpy(pdisc, &plogi_tmpl, sizeof(struct fc_logi_s));
820 pdisc->els_cmd.els_code = FC_ELS_PDISC;
821 fc_els_req_build(fchs, d_id, s_id, ox_id);
823 pdisc->csp.rxsz = pdisc->class3.rxsz = cpu_to_be16(pdu_size);
824 pdisc->port_name = port_name;
825 pdisc->node_name = node_name;
827 return sizeof(struct fc_logi_s);
831 fc_pdisc_rsp_parse(struct fchs_s *fchs, int len, wwn_t port_name)
833 struct fc_logi_s *pdisc = (struct fc_logi_s *) (fchs + 1);
835 if (len < sizeof(struct fc_logi_s))
836 return FC_PARSE_LEN_INVAL;
838 if (pdisc->els_cmd.els_code != FC_ELS_ACC)
839 return FC_PARSE_ACC_INVAL;
841 if (!wwn_is_equal(pdisc->port_name, port_name))
842 return FC_PARSE_PWWN_NOT_EQUAL;
844 if (!pdisc->class3.class_valid)
845 return FC_PARSE_NWWN_NOT_EQUAL;
847 if (be16_to_cpu(pdisc->class3.rxsz) < (FC_MIN_PDUSZ))
848 return FC_PARSE_RXSZ_INVAL;
850 return FC_PARSE_OK;
854 fc_prlo_build(struct fchs_s *fchs, u32 d_id, u32 s_id, u16 ox_id,
855 int num_pages)
857 struct fc_prlo_s *prlo = (struct fc_prlo_s *) (fchs + 1);
858 int page;
860 fc_els_req_build(fchs, d_id, s_id, ox_id);
861 memset(prlo, 0, (num_pages * 16) + 4);
862 prlo->command = FC_ELS_PRLO;
863 prlo->page_len = 0x10;
864 prlo->payload_len = cpu_to_be16((num_pages * 16) + 4);
866 for (page = 0; page < num_pages; page++) {
867 prlo->prlo_params[page].type = FC_TYPE_FCP;
868 prlo->prlo_params[page].opa_valid = 0;
869 prlo->prlo_params[page].rpa_valid = 0;
870 prlo->prlo_params[page].orig_process_assc = 0;
871 prlo->prlo_params[page].resp_process_assc = 0;
874 return be16_to_cpu(prlo->payload_len);
878 fc_tprlo_build(struct fchs_s *fchs, u32 d_id, u32 s_id, u16 ox_id,
879 int num_pages, enum fc_tprlo_type tprlo_type, u32 tpr_id)
881 struct fc_tprlo_s *tprlo = (struct fc_tprlo_s *) (fchs + 1);
882 int page;
884 fc_els_req_build(fchs, d_id, s_id, ox_id);
885 memset(tprlo, 0, (num_pages * 16) + 4);
886 tprlo->command = FC_ELS_TPRLO;
887 tprlo->page_len = 0x10;
888 tprlo->payload_len = cpu_to_be16((num_pages * 16) + 4);
890 for (page = 0; page < num_pages; page++) {
891 tprlo->tprlo_params[page].type = FC_TYPE_FCP;
892 tprlo->tprlo_params[page].opa_valid = 0;
893 tprlo->tprlo_params[page].rpa_valid = 0;
894 tprlo->tprlo_params[page].orig_process_assc = 0;
895 tprlo->tprlo_params[page].resp_process_assc = 0;
896 if (tprlo_type == FC_GLOBAL_LOGO) {
897 tprlo->tprlo_params[page].global_process_logout = 1;
898 } else if (tprlo_type == FC_TPR_LOGO) {
899 tprlo->tprlo_params[page].tpo_nport_valid = 1;
900 tprlo->tprlo_params[page].tpo_nport_id = (tpr_id);
904 return be16_to_cpu(tprlo->payload_len);
908 fc_ba_rjt_build(struct fchs_s *fchs, u32 d_id, u32 s_id, __be16 ox_id,
909 u32 reason_code, u32 reason_expl)
911 struct fc_ba_rjt_s *ba_rjt = (struct fc_ba_rjt_s *) (fchs + 1);
913 fc_bls_rsp_build(fchs, d_id, s_id, ox_id);
915 fchs->cat_info = FC_CAT_BA_RJT;
916 ba_rjt->reason_code = reason_code;
917 ba_rjt->reason_expl = reason_expl;
918 return sizeof(struct fc_ba_rjt_s);
921 static void
922 fc_gs_cthdr_build(struct ct_hdr_s *cthdr, u32 s_id, u16 cmd_code)
924 memset(cthdr, 0, sizeof(struct ct_hdr_s));
925 cthdr->rev_id = CT_GS3_REVISION;
926 cthdr->gs_type = CT_GSTYPE_DIRSERVICE;
927 cthdr->gs_sub_type = CT_GSSUBTYPE_NAMESERVER;
928 cthdr->cmd_rsp_code = cpu_to_be16(cmd_code);
931 static void
932 fc_gs_fdmi_cthdr_build(struct ct_hdr_s *cthdr, u32 s_id, u16 cmd_code)
934 memset(cthdr, 0, sizeof(struct ct_hdr_s));
935 cthdr->rev_id = CT_GS3_REVISION;
936 cthdr->gs_type = CT_GSTYPE_MGMTSERVICE;
937 cthdr->gs_sub_type = CT_GSSUBTYPE_HBA_MGMTSERVER;
938 cthdr->cmd_rsp_code = cpu_to_be16(cmd_code);
941 static void
942 fc_gs_ms_cthdr_build(struct ct_hdr_s *cthdr, u32 s_id, u16 cmd_code,
943 u8 sub_type)
945 memset(cthdr, 0, sizeof(struct ct_hdr_s));
946 cthdr->rev_id = CT_GS3_REVISION;
947 cthdr->gs_type = CT_GSTYPE_MGMTSERVICE;
948 cthdr->gs_sub_type = sub_type;
949 cthdr->cmd_rsp_code = cpu_to_be16(cmd_code);
953 fc_gidpn_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
954 wwn_t port_name)
956 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
957 struct fcgs_gidpn_req_s *gidpn = (struct fcgs_gidpn_req_s *)(cthdr + 1);
958 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
960 fc_gs_fchdr_build(fchs, d_id, s_id, ox_id);
961 fc_gs_cthdr_build(cthdr, s_id, GS_GID_PN);
963 memset(gidpn, 0, sizeof(struct fcgs_gidpn_req_s));
964 gidpn->port_name = port_name;
965 return sizeof(struct fcgs_gidpn_req_s) + sizeof(struct ct_hdr_s);
969 fc_gpnid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
970 u32 port_id)
972 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
973 fcgs_gpnid_req_t *gpnid = (fcgs_gpnid_req_t *) (cthdr + 1);
974 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
976 fc_gs_fchdr_build(fchs, d_id, s_id, ox_id);
977 fc_gs_cthdr_build(cthdr, s_id, GS_GPN_ID);
979 memset(gpnid, 0, sizeof(fcgs_gpnid_req_t));
980 gpnid->dap = port_id;
981 return sizeof(fcgs_gpnid_req_t) + sizeof(struct ct_hdr_s);
985 fc_gnnid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
986 u32 port_id)
988 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
989 fcgs_gnnid_req_t *gnnid = (fcgs_gnnid_req_t *) (cthdr + 1);
990 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
992 fc_gs_fchdr_build(fchs, d_id, s_id, ox_id);
993 fc_gs_cthdr_build(cthdr, s_id, GS_GNN_ID);
995 memset(gnnid, 0, sizeof(fcgs_gnnid_req_t));
996 gnnid->dap = port_id;
997 return sizeof(fcgs_gnnid_req_t) + sizeof(struct ct_hdr_s);
1001 fc_ct_rsp_parse(struct ct_hdr_s *cthdr)
1003 if (be16_to_cpu(cthdr->cmd_rsp_code) != CT_RSP_ACCEPT) {
1004 if (cthdr->reason_code == CT_RSN_LOGICAL_BUSY)
1005 return FC_PARSE_BUSY;
1006 else
1007 return FC_PARSE_FAILURE;
1010 return FC_PARSE_OK;
1014 fc_gs_rjt_build(struct fchs_s *fchs, struct ct_hdr_s *cthdr,
1015 u32 d_id, u32 s_id, u16 ox_id, u8 reason_code,
1016 u8 reason_code_expl)
1018 fc_gsresp_fchdr_build(fchs, d_id, s_id, ox_id);
1020 cthdr->cmd_rsp_code = cpu_to_be16(CT_RSP_REJECT);
1021 cthdr->rev_id = CT_GS3_REVISION;
1023 cthdr->reason_code = reason_code;
1024 cthdr->exp_code = reason_code_expl;
1025 return sizeof(struct ct_hdr_s);
1029 fc_scr_build(struct fchs_s *fchs, struct fc_scr_s *scr,
1030 u8 set_br_reg, u32 s_id, u16 ox_id)
1032 u32 d_id = bfa_hton3b(FC_FABRIC_CONTROLLER);
1034 fc_els_req_build(fchs, d_id, s_id, ox_id);
1036 memset(scr, 0, sizeof(struct fc_scr_s));
1037 scr->command = FC_ELS_SCR;
1038 scr->reg_func = FC_SCR_REG_FUNC_FULL;
1039 if (set_br_reg)
1040 scr->vu_reg_func = FC_VU_SCR_REG_FUNC_FABRIC_NAME_CHANGE;
1042 return sizeof(struct fc_scr_s);
1046 fc_rscn_build(struct fchs_s *fchs, struct fc_rscn_pl_s *rscn,
1047 u32 s_id, u16 ox_id)
1049 u32 d_id = bfa_hton3b(FC_FABRIC_CONTROLLER);
1050 u16 payldlen;
1052 fc_els_req_build(fchs, d_id, s_id, ox_id);
1053 rscn->command = FC_ELS_RSCN;
1054 rscn->pagelen = sizeof(rscn->event[0]);
1056 payldlen = sizeof(u32) + rscn->pagelen;
1057 rscn->payldlen = cpu_to_be16(payldlen);
1059 rscn->event[0].format = FC_RSCN_FORMAT_PORTID;
1060 rscn->event[0].portid = s_id;
1062 return sizeof(struct fc_rscn_pl_s);
1066 fc_rftid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
1067 enum bfa_lport_role roles)
1069 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1070 struct fcgs_rftid_req_s *rftid = (struct fcgs_rftid_req_s *)(cthdr + 1);
1071 u32 type_value, d_id = bfa_hton3b(FC_NAME_SERVER);
1072 u8 index;
1074 fc_gs_fchdr_build(fchs, d_id, s_id, ox_id);
1075 fc_gs_cthdr_build(cthdr, s_id, GS_RFT_ID);
1077 memset(rftid, 0, sizeof(struct fcgs_rftid_req_s));
1079 rftid->dap = s_id;
1081 /* By default, FCP FC4 Type is registered */
1082 index = FC_TYPE_FCP >> 5;
1083 type_value = 1 << (FC_TYPE_FCP % 32);
1084 rftid->fc4_type[index] = cpu_to_be32(type_value);
1086 return sizeof(struct fcgs_rftid_req_s) + sizeof(struct ct_hdr_s);
1090 fc_rftid_build_sol(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
1091 u8 *fc4_bitmap, u32 bitmap_size)
1093 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1094 struct fcgs_rftid_req_s *rftid = (struct fcgs_rftid_req_s *)(cthdr + 1);
1095 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
1097 fc_gs_fchdr_build(fchs, d_id, s_id, ox_id);
1098 fc_gs_cthdr_build(cthdr, s_id, GS_RFT_ID);
1100 memset(rftid, 0, sizeof(struct fcgs_rftid_req_s));
1102 rftid->dap = s_id;
1103 memcpy((void *)rftid->fc4_type, (void *)fc4_bitmap,
1104 (bitmap_size < 32 ? bitmap_size : 32));
1106 return sizeof(struct fcgs_rftid_req_s) + sizeof(struct ct_hdr_s);
1110 fc_rffid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
1111 u8 fc4_type, u8 fc4_ftrs)
1113 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1114 struct fcgs_rffid_req_s *rffid = (struct fcgs_rffid_req_s *)(cthdr + 1);
1115 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
1117 fc_gs_fchdr_build(fchs, d_id, s_id, ox_id);
1118 fc_gs_cthdr_build(cthdr, s_id, GS_RFF_ID);
1120 memset(rffid, 0, sizeof(struct fcgs_rffid_req_s));
1122 rffid->dap = s_id;
1123 rffid->fc4ftr_bits = fc4_ftrs;
1124 rffid->fc4_type = fc4_type;
1126 return sizeof(struct fcgs_rffid_req_s) + sizeof(struct ct_hdr_s);
1130 fc_rspnid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
1131 u8 *name)
1134 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1135 struct fcgs_rspnid_req_s *rspnid =
1136 (struct fcgs_rspnid_req_s *)(cthdr + 1);
1137 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
1139 fc_gs_fchdr_build(fchs, d_id, s_id, ox_id);
1140 fc_gs_cthdr_build(cthdr, s_id, GS_RSPN_ID);
1142 memset(rspnid, 0, sizeof(struct fcgs_rspnid_req_s));
1144 rspnid->dap = s_id;
1145 strlcpy(rspnid->spn, name, sizeof(rspnid->spn));
1146 rspnid->spn_len = (u8) strlen(rspnid->spn);
1148 return sizeof(struct fcgs_rspnid_req_s) + sizeof(struct ct_hdr_s);
1152 fc_rsnn_nn_build(struct fchs_s *fchs, void *pyld, u32 s_id,
1153 wwn_t node_name, u8 *name)
1155 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1156 struct fcgs_rsnn_nn_req_s *rsnn_nn =
1157 (struct fcgs_rsnn_nn_req_s *) (cthdr + 1);
1158 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
1160 fc_gs_fchdr_build(fchs, d_id, s_id, 0);
1161 fc_gs_cthdr_build(cthdr, s_id, GS_RSNN_NN);
1163 memset(rsnn_nn, 0, sizeof(struct fcgs_rsnn_nn_req_s));
1165 rsnn_nn->node_name = node_name;
1166 strlcpy(rsnn_nn->snn, name, sizeof(rsnn_nn->snn));
1167 rsnn_nn->snn_len = (u8) strlen(rsnn_nn->snn);
1169 return sizeof(struct fcgs_rsnn_nn_req_s) + sizeof(struct ct_hdr_s);
1173 fc_gid_ft_build(struct fchs_s *fchs, void *pyld, u32 s_id, u8 fc4_type)
1176 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1177 struct fcgs_gidft_req_s *gidft = (struct fcgs_gidft_req_s *)(cthdr + 1);
1178 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
1180 fc_gs_fchdr_build(fchs, d_id, s_id, 0);
1182 fc_gs_cthdr_build(cthdr, s_id, GS_GID_FT);
1184 memset(gidft, 0, sizeof(struct fcgs_gidft_req_s));
1185 gidft->fc4_type = fc4_type;
1186 gidft->domain_id = 0;
1187 gidft->area_id = 0;
1189 return sizeof(struct fcgs_gidft_req_s) + sizeof(struct ct_hdr_s);
1193 fc_rpnid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u32 port_id,
1194 wwn_t port_name)
1196 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1197 struct fcgs_rpnid_req_s *rpnid = (struct fcgs_rpnid_req_s *)(cthdr + 1);
1198 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
1200 fc_gs_fchdr_build(fchs, d_id, s_id, 0);
1201 fc_gs_cthdr_build(cthdr, s_id, GS_RPN_ID);
1203 memset(rpnid, 0, sizeof(struct fcgs_rpnid_req_s));
1204 rpnid->port_id = port_id;
1205 rpnid->port_name = port_name;
1207 return sizeof(struct fcgs_rpnid_req_s) + sizeof(struct ct_hdr_s);
1211 fc_rnnid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u32 port_id,
1212 wwn_t node_name)
1214 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1215 struct fcgs_rnnid_req_s *rnnid = (struct fcgs_rnnid_req_s *)(cthdr + 1);
1216 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
1218 fc_gs_fchdr_build(fchs, d_id, s_id, 0);
1219 fc_gs_cthdr_build(cthdr, s_id, GS_RNN_ID);
1221 memset(rnnid, 0, sizeof(struct fcgs_rnnid_req_s));
1222 rnnid->port_id = port_id;
1223 rnnid->node_name = node_name;
1225 return sizeof(struct fcgs_rnnid_req_s) + sizeof(struct ct_hdr_s);
1229 fc_rcsid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u32 port_id,
1230 u32 cos)
1232 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1233 struct fcgs_rcsid_req_s *rcsid =
1234 (struct fcgs_rcsid_req_s *) (cthdr + 1);
1235 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
1237 fc_gs_fchdr_build(fchs, d_id, s_id, 0);
1238 fc_gs_cthdr_build(cthdr, s_id, GS_RCS_ID);
1240 memset(rcsid, 0, sizeof(struct fcgs_rcsid_req_s));
1241 rcsid->port_id = port_id;
1242 rcsid->cos = cos;
1244 return sizeof(struct fcgs_rcsid_req_s) + sizeof(struct ct_hdr_s);
1248 fc_rptid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u32 port_id,
1249 u8 port_type)
1251 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1252 struct fcgs_rptid_req_s *rptid = (struct fcgs_rptid_req_s *)(cthdr + 1);
1253 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
1255 fc_gs_fchdr_build(fchs, d_id, s_id, 0);
1256 fc_gs_cthdr_build(cthdr, s_id, GS_RPT_ID);
1258 memset(rptid, 0, sizeof(struct fcgs_rptid_req_s));
1259 rptid->port_id = port_id;
1260 rptid->port_type = port_type;
1262 return sizeof(struct fcgs_rptid_req_s) + sizeof(struct ct_hdr_s);
1266 fc_ganxt_build(struct fchs_s *fchs, void *pyld, u32 s_id, u32 port_id)
1268 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1269 struct fcgs_ganxt_req_s *ganxt = (struct fcgs_ganxt_req_s *)(cthdr + 1);
1270 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
1272 fc_gs_fchdr_build(fchs, d_id, s_id, 0);
1273 fc_gs_cthdr_build(cthdr, s_id, GS_GA_NXT);
1275 memset(ganxt, 0, sizeof(struct fcgs_ganxt_req_s));
1276 ganxt->port_id = port_id;
1278 return sizeof(struct ct_hdr_s) + sizeof(struct fcgs_ganxt_req_s);
1282 * Builds fc hdr and ct hdr for FDMI requests.
1285 fc_fdmi_reqhdr_build(struct fchs_s *fchs, void *pyld, u32 s_id,
1286 u16 cmd_code)
1289 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1290 u32 d_id = bfa_hton3b(FC_MGMT_SERVER);
1292 fc_gs_fchdr_build(fchs, d_id, s_id, 0);
1293 fc_gs_fdmi_cthdr_build(cthdr, s_id, cmd_code);
1295 return sizeof(struct ct_hdr_s);
1299 * Given a FC4 Type, this function returns a fc4 type bitmask
1301 void
1302 fc_get_fc4type_bitmask(u8 fc4_type, u8 *bit_mask)
1304 u8 index;
1305 __be32 *ptr = (__be32 *) bit_mask;
1306 u32 type_value;
1309 * @todo : Check for bitmask size
1312 index = fc4_type >> 5;
1313 type_value = 1 << (fc4_type % 32);
1314 ptr[index] = cpu_to_be32(type_value);
1319 * GMAL Request
1322 fc_gmal_req_build(struct fchs_s *fchs, void *pyld, u32 s_id, wwn_t wwn)
1324 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1325 fcgs_gmal_req_t *gmal = (fcgs_gmal_req_t *) (cthdr + 1);
1326 u32 d_id = bfa_hton3b(FC_MGMT_SERVER);
1328 fc_gs_fchdr_build(fchs, d_id, s_id, 0);
1329 fc_gs_ms_cthdr_build(cthdr, s_id, GS_FC_GMAL_CMD,
1330 CT_GSSUBTYPE_CFGSERVER);
1332 memset(gmal, 0, sizeof(fcgs_gmal_req_t));
1333 gmal->wwn = wwn;
1335 return sizeof(struct ct_hdr_s) + sizeof(fcgs_gmal_req_t);
1339 * GFN (Get Fabric Name) Request
1342 fc_gfn_req_build(struct fchs_s *fchs, void *pyld, u32 s_id, wwn_t wwn)
1344 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1345 fcgs_gfn_req_t *gfn = (fcgs_gfn_req_t *) (cthdr + 1);
1346 u32 d_id = bfa_hton3b(FC_MGMT_SERVER);
1348 fc_gs_fchdr_build(fchs, d_id, s_id, 0);
1349 fc_gs_ms_cthdr_build(cthdr, s_id, GS_FC_GFN_CMD,
1350 CT_GSSUBTYPE_CFGSERVER);
1352 memset(gfn, 0, sizeof(fcgs_gfn_req_t));
1353 gfn->wwn = wwn;
1355 return sizeof(struct ct_hdr_s) + sizeof(fcgs_gfn_req_t);