[S390] Remove error checking from copy_oldmem_page()
[linux/fpc-iii.git] / drivers / scsi / bfa / bfa_fcbuild.c
blob17b59b8b564425fc0a8bc38dcf25f2af08f780a9
1 /*
2 * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
3 * All rights reserved
4 * www.brocade.com
6 * Linux driver for Brocade Fibre Channel Host Bus Adapter.
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
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.
18 * fcbuild.c - FC link service frame building and parsing routines
21 #include "bfad_drv.h"
22 #include "bfa_fcbuild.h"
25 * static build functions
27 static void fc_els_rsp_build(struct fchs_s *fchs, u32 d_id, u32 s_id,
28 __be16 ox_id);
29 static void fc_bls_rsp_build(struct fchs_s *fchs, u32 d_id, u32 s_id,
30 __be16 ox_id);
31 static struct fchs_s fc_els_req_tmpl;
32 static struct fchs_s fc_els_rsp_tmpl;
33 static struct fchs_s fc_bls_req_tmpl;
34 static struct fchs_s fc_bls_rsp_tmpl;
35 static struct fc_ba_acc_s ba_acc_tmpl;
36 static struct fc_logi_s plogi_tmpl;
37 static struct fc_prli_s prli_tmpl;
38 static struct fc_rrq_s rrq_tmpl;
39 static struct fchs_s fcp_fchs_tmpl;
41 void
42 fcbuild_init(void)
45 * fc_els_req_tmpl
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 =
51 bfa_hton3b(FCTL_SEQ_INI | FCTL_FS_EXCH | FCTL_END_SEQ |
52 FCTL_SI_XFER);
53 fc_els_req_tmpl.rx_id = FC_RXID_ANY;
56 * fc_els_rsp_tmpl
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 =
62 bfa_hton3b(FCTL_EC_RESP | FCTL_SEQ_INI | FCTL_LS_EXCH |
63 FCTL_END_SEQ | FCTL_SI_XFER);
64 fc_els_rsp_tmpl.rx_id = FC_RXID_ANY;
67 * fc_bls_req_tmpl
69 fc_bls_req_tmpl.routing = FC_RTG_BASIC_LINK;
70 fc_bls_req_tmpl.type = FC_TYPE_BLS;
71 fc_bls_req_tmpl.f_ctl = bfa_hton3b(FCTL_END_SEQ | FCTL_SI_XFER);
72 fc_bls_req_tmpl.rx_id = FC_RXID_ANY;
75 * fc_bls_rsp_tmpl
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 =
81 bfa_hton3b(FCTL_EC_RESP | FCTL_SEQ_INI | FCTL_LS_EXCH |
82 FCTL_END_SEQ | FCTL_SI_XFER);
83 fc_bls_rsp_tmpl.rx_id = FC_RXID_ANY;
86 * ba_acc_tmpl
88 ba_acc_tmpl.seq_id_valid = 0;
89 ba_acc_tmpl.low_seq_cnt = 0;
90 ba_acc_tmpl.high_seq_cnt = 0xFFFF;
93 * plogi_tmpl
95 plogi_tmpl.csp.verhi = FC_PH_VER_PH_3;
96 plogi_tmpl.csp.verlo = FC_PH_VER_4_3;
97 plogi_tmpl.csp.ciro = 0x1;
98 plogi_tmpl.csp.cisc = 0x0;
99 plogi_tmpl.csp.altbbcred = 0x0;
100 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);
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;
110 * prli_tmpl
112 prli_tmpl.command = FC_ELS_PRLI;
113 prli_tmpl.pglen = 0x10;
114 prli_tmpl.pagebytes = cpu_to_be16(0x0014);
115 prli_tmpl.parampage.type = FC_TYPE_FCP;
116 prli_tmpl.parampage.imagepair = 1;
117 prli_tmpl.parampage.servparams.rxrdisab = 1;
120 * rrq_tmpl
122 rrq_tmpl.els_cmd.els_code = FC_ELS_RRQ;
125 * fcp_struct fchs_s mpl
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 =
131 bfa_hton3b(FCTL_FS_EXCH | FCTL_END_SEQ | FCTL_SI_XFER);
132 fcp_fchs_tmpl.seq_id = 1;
133 fcp_fchs_tmpl.rx_id = FC_RXID_ANY;
136 static void
137 fc_gs_fchdr_build(struct fchs_s *fchs, u32 d_id, u32 s_id, u32 ox_id)
139 memset(fchs, 0, sizeof(struct fchs_s));
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 =
145 bfa_hton3b(FCTL_SEQ_INI | FCTL_FS_EXCH | FCTL_END_SEQ |
146 FCTL_SI_XFER);
147 fchs->rx_id = FC_RXID_ANY;
148 fchs->d_id = (d_id);
149 fchs->s_id = (s_id);
150 fchs->ox_id = cpu_to_be16(ox_id);
153 * @todo no need to set ox_id for request
154 * no need to set rx_id for response
158 static void
159 fc_gsresp_fchdr_build(struct fchs_s *fchs, u32 d_id, u32 s_id, u16 ox_id)
161 memset(fchs, 0, sizeof(struct fchs_s));
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;
174 void
175 fc_els_req_build(struct fchs_s *fchs, u32 d_id, u32 s_id, __be16 ox_id)
177 memcpy(fchs, &fc_els_req_tmpl, sizeof(struct fchs_s));
178 fchs->d_id = (d_id);
179 fchs->s_id = (s_id);
180 fchs->ox_id = cpu_to_be16(ox_id);
183 static void
184 fc_els_rsp_build(struct fchs_s *fchs, u32 d_id, u32 s_id, __be16 ox_id)
186 memcpy(fchs, &fc_els_rsp_tmpl, sizeof(struct fchs_s));
187 fchs->d_id = d_id;
188 fchs->s_id = s_id;
189 fchs->ox_id = ox_id;
192 enum fc_parse_status
193 fc_els_rsp_parse(struct fchs_s *fchs, int len)
195 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;
198 len = len;
200 switch (els_cmd->els_code) {
201 case FC_ELS_LS_RJT:
202 if (ls_rjt->reason_code == FC_LS_RJT_RSN_LOGICAL_BUSY)
203 return FC_PARSE_BUSY;
204 else
205 return FC_PARSE_FAILURE;
207 case FC_ELS_ACC:
208 return FC_PARSE_OK;
210 return FC_PARSE_OK;
213 static void
214 fc_bls_rsp_build(struct fchs_s *fchs, u32 d_id, u32 s_id, __be16 ox_id)
216 memcpy(fchs, &fc_bls_rsp_tmpl, sizeof(struct fchs_s));
217 fchs->d_id = d_id;
218 fchs->s_id = s_id;
219 fchs->ox_id = ox_id;
222 static u16
223 fc_plogi_x_build(struct fchs_s *fchs, void *pld, u32 d_id, u32 s_id,
224 __be16 ox_id, wwn_t port_name, wwn_t node_name,
225 u16 pdu_size, u16 bb_cr, u8 els_code)
227 struct fc_logi_s *plogi = (struct fc_logi_s *) (pld);
229 memcpy(plogi, &plogi_tmpl, sizeof(struct fc_logi_s));
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);
237 plogi->csp.rxsz = plogi->class3.rxsz = cpu_to_be16(pdu_size);
238 plogi->csp.bbcred = cpu_to_be16(bb_cr);
240 memcpy(&plogi->port_name, &port_name, sizeof(wwn_t));
241 memcpy(&plogi->node_name, &node_name, sizeof(wwn_t));
243 return sizeof(struct fc_logi_s);
247 fc_flogi_build(struct fchs_s *fchs, struct fc_logi_s *flogi, u32 s_id,
248 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)
251 u32 d_id = bfa_hton3b(FC_FABRIC_PORT);
252 __be32 *vvl_info;
254 memcpy(flogi, &plogi_tmpl, sizeof(struct fc_logi_s));
256 flogi->els_cmd.els_code = FC_ELS_FLOGI;
257 fc_els_req_build(fchs, d_id, s_id, ox_id);
259 flogi->csp.rxsz = flogi->class3.rxsz = cpu_to_be16(pdu_size);
260 flogi->port_name = port_name;
261 flogi->node_name = node_name;
264 * Set the NPIV Capability Bit ( word 1, bit 31) of Common
265 * Service Parameters.
267 flogi->csp.ciro = set_npiv;
269 /* set AUTH capability */
270 flogi->csp.security = set_auth;
272 flogi->csp.bbcred = cpu_to_be16(local_bb_credits);
274 /* Set brcd token in VVL */
275 vvl_info = (u32 *)&flogi->vvl[0];
277 /* set the flag to indicate the presence of VVL */
278 flogi->csp.npiv_supp = 1; /* @todo. field name is not correct */
279 vvl_info[0] = cpu_to_be32(FLOGI_VVL_BRCD);
281 return sizeof(struct fc_logi_s);
285 fc_flogi_acc_build(struct fchs_s *fchs, struct fc_logi_s *flogi, u32 s_id,
286 __be16 ox_id, wwn_t port_name, wwn_t node_name,
287 u16 pdu_size, u16 local_bb_credits, u8 bb_scn)
289 u32 d_id = 0;
290 u16 bbscn_rxsz = (bb_scn << 12) | pdu_size;
292 memcpy(flogi, &plogi_tmpl, sizeof(struct fc_logi_s));
293 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
295 flogi->els_cmd.els_code = FC_ELS_ACC;
296 flogi->class3.rxsz = cpu_to_be16(pdu_size);
297 flogi->csp.rxsz = cpu_to_be16(bbscn_rxsz); /* bb_scn/rxsz */
298 flogi->port_name = port_name;
299 flogi->node_name = node_name;
301 flogi->csp.bbcred = cpu_to_be16(local_bb_credits);
303 return sizeof(struct fc_logi_s);
307 fc_fdisc_build(struct fchs_s *fchs, struct fc_logi_s *flogi, u32 s_id,
308 u16 ox_id, wwn_t port_name, wwn_t node_name, u16 pdu_size)
310 u32 d_id = bfa_hton3b(FC_FABRIC_PORT);
312 memcpy(flogi, &plogi_tmpl, sizeof(struct fc_logi_s));
314 flogi->els_cmd.els_code = FC_ELS_FDISC;
315 fc_els_req_build(fchs, d_id, s_id, ox_id);
317 flogi->csp.rxsz = flogi->class3.rxsz = cpu_to_be16(pdu_size);
318 flogi->port_name = port_name;
319 flogi->node_name = node_name;
321 return sizeof(struct fc_logi_s);
325 fc_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,
327 u16 pdu_size, u16 bb_cr)
329 return fc_plogi_x_build(fchs, pld, d_id, s_id, ox_id, port_name,
330 node_name, pdu_size, bb_cr, FC_ELS_PLOGI);
334 fc_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,
336 u16 pdu_size, u16 bb_cr)
338 return fc_plogi_x_build(fchs, pld, d_id, s_id, ox_id, port_name,
339 node_name, pdu_size, bb_cr, FC_ELS_ACC);
342 enum fc_parse_status
343 fc_plogi_rsp_parse(struct fchs_s *fchs, int len, wwn_t port_name)
345 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;
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)
353 return FC_PARSE_BUSY;
354 else
355 return FC_PARSE_FAILURE;
356 case FC_ELS_ACC:
357 plogi = (struct fc_logi_s *) (fchs + 1);
358 if (len < sizeof(struct fc_logi_s))
359 return FC_PARSE_FAILURE;
361 if (!wwn_is_equal(plogi->port_name, port_name))
362 return FC_PARSE_FAILURE;
364 if (!plogi->class3.class_valid)
365 return FC_PARSE_FAILURE;
367 if (be16_to_cpu(plogi->class3.rxsz) < (FC_MIN_PDUSZ))
368 return FC_PARSE_FAILURE;
370 return FC_PARSE_OK;
371 default:
372 return FC_PARSE_FAILURE;
376 enum fc_parse_status
377 fc_plogi_parse(struct fchs_s *fchs)
379 struct fc_logi_s *plogi = (struct fc_logi_s *) (fchs + 1);
381 if (plogi->class3.class_valid != 1)
382 return FC_PARSE_FAILURE;
384 if ((be16_to_cpu(plogi->class3.rxsz) < FC_MIN_PDUSZ)
385 || (be16_to_cpu(plogi->class3.rxsz) > FC_MAX_PDUSZ)
386 || (plogi->class3.rxsz == 0))
387 return FC_PARSE_FAILURE;
389 return FC_PARSE_OK;
393 fc_prli_build(struct fchs_s *fchs, void *pld, u32 d_id, u32 s_id,
394 u16 ox_id)
396 struct fc_prli_s *prli = (struct fc_prli_s *) (pld);
398 fc_els_req_build(fchs, d_id, s_id, ox_id);
399 memcpy(prli, &prli_tmpl, sizeof(struct fc_prli_s));
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;
408 return sizeof(struct fc_prli_s);
412 fc_prli_acc_build(struct fchs_s *fchs, void *pld, u32 d_id, u32 s_id,
413 __be16 ox_id, enum bfa_lport_role role)
415 struct fc_prli_s *prli = (struct fc_prli_s *) (pld);
417 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
418 memcpy(prli, &prli_tmpl, sizeof(struct fc_prli_s));
420 prli->command = FC_ELS_ACC;
422 prli->parampage.servparams.initiator = 1;
424 prli->parampage.rspcode = FC_PRLI_ACC_XQTD;
426 return sizeof(struct fc_prli_s);
429 enum fc_parse_status
430 fc_prli_rsp_parse(struct fc_prli_s *prli, int len)
432 if (len < sizeof(struct fc_prli_s))
433 return FC_PARSE_FAILURE;
435 if (prli->command != FC_ELS_ACC)
436 return FC_PARSE_FAILURE;
438 if ((prli->parampage.rspcode != FC_PRLI_ACC_XQTD)
439 && (prli->parampage.rspcode != FC_PRLI_ACC_PREDEF_IMG))
440 return FC_PARSE_FAILURE;
442 if (prli->parampage.servparams.target != 1)
443 return FC_PARSE_FAILURE;
445 return FC_PARSE_OK;
448 enum fc_parse_status
449 fc_prli_parse(struct fc_prli_s *prli)
451 if (prli->parampage.type != FC_TYPE_FCP)
452 return FC_PARSE_FAILURE;
454 if (!prli->parampage.imagepair)
455 return FC_PARSE_FAILURE;
457 if (!prli->parampage.servparams.initiator)
458 return FC_PARSE_FAILURE;
460 return FC_PARSE_OK;
464 fc_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)
467 fc_els_req_build(fchs, d_id, s_id, ox_id);
469 memset(logo, '\0', sizeof(struct fc_logo_s));
470 logo->els_cmd.els_code = FC_ELS_LOGO;
471 logo->nport_id = (s_id);
472 logo->orig_port_name = port_name;
474 return sizeof(struct fc_logo_s);
477 static u16
478 fc_adisc_x_build(struct fchs_s *fchs, struct fc_adisc_s *adisc, u32 d_id,
479 u32 s_id, __be16 ox_id, wwn_t port_name,
480 wwn_t node_name, u8 els_code)
482 memset(adisc, '\0', sizeof(struct fc_adisc_s));
484 adisc->els_cmd.els_code = els_code;
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);
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);
496 return sizeof(struct fc_adisc_s);
500 fc_adisc_build(struct fchs_s *fchs, struct fc_adisc_s *adisc, u32 d_id,
501 u32 s_id, __be16 ox_id, wwn_t port_name, wwn_t node_name)
503 return fc_adisc_x_build(fchs, adisc, d_id, s_id, ox_id, port_name,
504 node_name, FC_ELS_ADISC);
508 fc_adisc_acc_build(struct fchs_s *fchs, struct fc_adisc_s *adisc, u32 d_id,
509 u32 s_id, __be16 ox_id, wwn_t port_name,
510 wwn_t node_name)
512 return fc_adisc_x_build(fchs, adisc, d_id, s_id, ox_id, port_name,
513 node_name, FC_ELS_ACC);
516 enum fc_parse_status
517 fc_adisc_rsp_parse(struct fc_adisc_s *adisc, int len, wwn_t port_name,
518 wwn_t node_name)
521 if (len < sizeof(struct fc_adisc_s))
522 return FC_PARSE_FAILURE;
524 if (adisc->els_cmd.els_code != FC_ELS_ACC)
525 return FC_PARSE_FAILURE;
527 if (!wwn_is_equal(adisc->orig_port_name, port_name))
528 return FC_PARSE_FAILURE;
530 return FC_PARSE_OK;
533 enum fc_parse_status
534 fc_adisc_parse(struct fchs_s *fchs, void *pld, u32 host_dap, wwn_t node_name,
535 wwn_t port_name)
537 struct fc_adisc_s *adisc = (struct fc_adisc_s *) pld;
539 if (adisc->els_cmd.els_code != FC_ELS_ACC)
540 return FC_PARSE_FAILURE;
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))
545 return FC_PARSE_OK;
547 return FC_PARSE_FAILURE;
550 enum fc_parse_status
551 fc_pdisc_parse(struct fchs_s *fchs, wwn_t node_name, wwn_t port_name)
553 struct fc_logi_s *pdisc = (struct fc_logi_s *) (fchs + 1);
555 if (pdisc->class3.class_valid != 1)
556 return FC_PARSE_FAILURE;
558 if ((be16_to_cpu(pdisc->class3.rxsz) <
559 (FC_MIN_PDUSZ - sizeof(struct fchs_s)))
560 || (pdisc->class3.rxsz == 0))
561 return FC_PARSE_FAILURE;
563 if (!wwn_is_equal(pdisc->port_name, port_name))
564 return FC_PARSE_FAILURE;
566 if (!wwn_is_equal(pdisc->node_name, node_name))
567 return FC_PARSE_FAILURE;
569 return FC_PARSE_OK;
573 fc_abts_build(struct fchs_s *fchs, u32 d_id, u32 s_id, u16 ox_id)
575 memcpy(fchs, &fc_bls_req_tmpl, sizeof(struct fchs_s));
576 fchs->cat_info = FC_CAT_ABTS;
577 fchs->d_id = (d_id);
578 fchs->s_id = (s_id);
579 fchs->ox_id = cpu_to_be16(ox_id);
581 return sizeof(struct fchs_s);
584 enum fc_parse_status
585 fc_abts_rsp_parse(struct fchs_s *fchs, int len)
587 if ((fchs->cat_info == FC_CAT_BA_ACC)
588 || (fchs->cat_info == FC_CAT_BA_RJT))
589 return FC_PARSE_OK;
591 return FC_PARSE_FAILURE;
595 fc_rrq_build(struct fchs_s *fchs, struct fc_rrq_s *rrq, u32 d_id, u32 s_id,
596 u16 ox_id, u16 rrq_oxid)
598 fc_els_req_build(fchs, d_id, s_id, ox_id);
601 * build rrq payload
603 memcpy(rrq, &rrq_tmpl, sizeof(struct fc_rrq_s));
604 rrq->s_id = (s_id);
605 rrq->ox_id = cpu_to_be16(rrq_oxid);
606 rrq->rx_id = FC_RXID_ANY;
608 return sizeof(struct fc_rrq_s);
612 fc_logo_acc_build(struct fchs_s *fchs, void *pld, u32 d_id, u32 s_id,
613 __be16 ox_id)
615 struct fc_els_cmd_s *acc = pld;
617 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
619 memset(acc, 0, sizeof(struct fc_els_cmd_s));
620 acc->els_code = FC_ELS_ACC;
622 return sizeof(struct fc_els_cmd_s);
626 fc_ls_rjt_build(struct fchs_s *fchs, struct fc_ls_rjt_s *ls_rjt, u32 d_id,
627 u32 s_id, __be16 ox_id, u8 reason_code,
628 u8 reason_code_expl)
630 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
631 memset(ls_rjt, 0, sizeof(struct fc_ls_rjt_s));
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;
638 return sizeof(struct fc_ls_rjt_s);
642 fc_ba_acc_build(struct fchs_s *fchs, struct fc_ba_acc_s *ba_acc, u32 d_id,
643 u32 s_id, __be16 ox_id, u16 rx_id)
645 fc_bls_rsp_build(fchs, d_id, s_id, ox_id);
647 memcpy(ba_acc, &ba_acc_tmpl, sizeof(struct fc_ba_acc_s));
649 fchs->rx_id = rx_id;
651 ba_acc->ox_id = fchs->ox_id;
652 ba_acc->rx_id = fchs->rx_id;
654 return sizeof(struct fc_ba_acc_s);
658 fc_ls_acc_build(struct fchs_s *fchs, struct fc_els_cmd_s *els_cmd, u32 d_id,
659 u32 s_id, __be16 ox_id)
661 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
662 memset(els_cmd, 0, sizeof(struct fc_els_cmd_s));
663 els_cmd->els_code = FC_ELS_ACC;
665 return sizeof(struct fc_els_cmd_s);
669 fc_logout_params_pages(struct fchs_s *fc_frame, u8 els_code)
671 int num_pages = 0;
672 struct fc_prlo_s *prlo;
673 struct fc_tprlo_s *tprlo;
675 if (els_code == FC_ELS_PRLO) {
676 prlo = (struct fc_prlo_s *) (fc_frame + 1);
677 num_pages = (be16_to_cpu(prlo->payload_len) - 4) / 16;
678 } else {
679 tprlo = (struct fc_tprlo_s *) (fc_frame + 1);
680 num_pages = (be16_to_cpu(tprlo->payload_len) - 4) / 16;
682 return num_pages;
686 fc_tprlo_acc_build(struct fchs_s *fchs, struct fc_tprlo_acc_s *tprlo_acc,
687 u32 d_id, u32 s_id, __be16 ox_id, int num_pages)
689 int page;
691 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
693 memset(tprlo_acc, 0, (num_pages * 16) + 4);
694 tprlo_acc->command = FC_ELS_ACC;
696 tprlo_acc->page_len = 0x10;
697 tprlo_acc->payload_len = cpu_to_be16((num_pages * 16) + 4);
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;
706 return be16_to_cpu(tprlo_acc->payload_len);
710 fc_prlo_acc_build(struct fchs_s *fchs, struct fc_prlo_acc_s *prlo_acc, u32 d_id,
711 u32 s_id, __be16 ox_id, int num_pages)
713 int page;
715 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
717 memset(prlo_acc, 0, (num_pages * 16) + 4);
718 prlo_acc->command = FC_ELS_ACC;
719 prlo_acc->page_len = 0x10;
720 prlo_acc->payload_len = cpu_to_be16((num_pages * 16) + 4);
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;
730 return be16_to_cpu(prlo_acc->payload_len);
734 fc_rnid_build(struct fchs_s *fchs, struct fc_rnid_cmd_s *rnid, u32 d_id,
735 u32 s_id, u16 ox_id, u32 data_format)
737 fc_els_req_build(fchs, d_id, s_id, ox_id);
739 memset(rnid, 0, sizeof(struct fc_rnid_cmd_s));
741 rnid->els_cmd.els_code = FC_ELS_RNID;
742 rnid->node_id_data_format = data_format;
744 return sizeof(struct fc_rnid_cmd_s);
748 fc_rnid_acc_build(struct fchs_s *fchs, struct fc_rnid_acc_s *rnid_acc, u32 d_id,
749 u32 s_id, __be16 ox_id, u32 data_format,
750 struct fc_rnid_common_id_data_s *common_id_data,
751 struct fc_rnid_general_topology_data_s *gen_topo_data)
753 memset(rnid_acc, 0, sizeof(struct fc_rnid_acc_s));
755 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
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;
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);
766 rnid_acc->gen_topology_data = *gen_topo_data;
767 return sizeof(struct fc_rnid_acc_s);
768 } else {
769 return sizeof(struct fc_rnid_acc_s) -
770 sizeof(struct fc_rnid_general_topology_data_s);
776 fc_rpsc_build(struct fchs_s *fchs, struct fc_rpsc_cmd_s *rpsc, u32 d_id,
777 u32 s_id, u16 ox_id)
779 fc_els_req_build(fchs, d_id, s_id, ox_id);
781 memset(rpsc, 0, sizeof(struct fc_rpsc_cmd_s));
783 rpsc->els_cmd.els_code = FC_ELS_RPSC;
784 return sizeof(struct fc_rpsc_cmd_s);
788 fc_rpsc2_build(struct fchs_s *fchs, struct fc_rpsc2_cmd_s *rpsc2, u32 d_id,
789 u32 s_id, u32 *pid_list, u16 npids)
791 u32 dctlr_id = FC_DOMAIN_CTRLR(bfa_hton3b(d_id));
792 int i = 0;
794 fc_els_req_build(fchs, bfa_hton3b(dctlr_id), s_id, 0);
796 memset(rpsc2, 0, sizeof(struct fc_rpsc2_cmd_s));
798 rpsc2->els_cmd.els_code = FC_ELS_RPSC;
799 rpsc2->token = cpu_to_be32(FC_BRCD_TOKEN);
800 rpsc2->num_pids = cpu_to_be16(npids);
801 for (i = 0; i < npids; i++)
802 rpsc2->pid_list[i].pid = pid_list[i];
804 return sizeof(struct fc_rpsc2_cmd_s) + ((npids - 1) * (sizeof(u32)));
808 fc_rpsc_acc_build(struct fchs_s *fchs, struct fc_rpsc_acc_s *rpsc_acc,
809 u32 d_id, u32 s_id, __be16 ox_id,
810 struct fc_rpsc_speed_info_s *oper_speed)
812 memset(rpsc_acc, 0, sizeof(struct fc_rpsc_acc_s));
814 fc_els_rsp_build(fchs, d_id, s_id, ox_id);
816 rpsc_acc->command = FC_ELS_ACC;
817 rpsc_acc->num_entries = cpu_to_be16(1);
819 rpsc_acc->speed_info[0].port_speed_cap =
820 cpu_to_be16(oper_speed->port_speed_cap);
822 rpsc_acc->speed_info[0].port_op_speed =
823 cpu_to_be16(oper_speed->port_op_speed);
825 return sizeof(struct fc_rpsc_acc_s);
829 fc_logo_rsp_parse(struct fchs_s *fchs, int len)
831 struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
833 len = len;
834 if (els_cmd->els_code != FC_ELS_ACC)
835 return FC_PARSE_FAILURE;
837 return FC_PARSE_OK;
841 fc_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)
844 struct fc_logi_s *pdisc = (struct fc_logi_s *) (fchs + 1);
846 memcpy(pdisc, &plogi_tmpl, sizeof(struct fc_logi_s));
848 pdisc->els_cmd.els_code = FC_ELS_PDISC;
849 fc_els_req_build(fchs, d_id, s_id, ox_id);
851 pdisc->csp.rxsz = pdisc->class3.rxsz = cpu_to_be16(pdu_size);
852 pdisc->port_name = port_name;
853 pdisc->node_name = node_name;
855 return sizeof(struct fc_logi_s);
859 fc_pdisc_rsp_parse(struct fchs_s *fchs, int len, wwn_t port_name)
861 struct fc_logi_s *pdisc = (struct fc_logi_s *) (fchs + 1);
863 if (len < sizeof(struct fc_logi_s))
864 return FC_PARSE_LEN_INVAL;
866 if (pdisc->els_cmd.els_code != FC_ELS_ACC)
867 return FC_PARSE_ACC_INVAL;
869 if (!wwn_is_equal(pdisc->port_name, port_name))
870 return FC_PARSE_PWWN_NOT_EQUAL;
872 if (!pdisc->class3.class_valid)
873 return FC_PARSE_NWWN_NOT_EQUAL;
875 if (be16_to_cpu(pdisc->class3.rxsz) < (FC_MIN_PDUSZ))
876 return FC_PARSE_RXSZ_INVAL;
878 return FC_PARSE_OK;
882 fc_prlo_build(struct fchs_s *fchs, u32 d_id, u32 s_id, u16 ox_id,
883 int num_pages)
885 struct fc_prlo_s *prlo = (struct fc_prlo_s *) (fchs + 1);
886 int page;
888 fc_els_req_build(fchs, d_id, s_id, ox_id);
889 memset(prlo, 0, (num_pages * 16) + 4);
890 prlo->command = FC_ELS_PRLO;
891 prlo->page_len = 0x10;
892 prlo->payload_len = cpu_to_be16((num_pages * 16) + 4);
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;
902 return be16_to_cpu(prlo->payload_len);
906 fc_prlo_rsp_parse(struct fchs_s *fchs, int len)
908 struct fc_prlo_acc_s *prlo = (struct fc_prlo_acc_s *) (fchs + 1);
909 int num_pages = 0;
910 int page = 0;
912 len = len;
914 if (prlo->command != FC_ELS_ACC)
915 return FC_PARSE_FAILURE;
917 num_pages = ((be16_to_cpu(prlo->payload_len)) - 4) / 16;
919 for (page = 0; page < num_pages; page++) {
920 if (prlo->prlo_acc_params[page].type != FC_TYPE_FCP)
921 return FC_PARSE_FAILURE;
923 if (prlo->prlo_acc_params[page].opa_valid != 0)
924 return FC_PARSE_FAILURE;
926 if (prlo->prlo_acc_params[page].rpa_valid != 0)
927 return FC_PARSE_FAILURE;
929 if (prlo->prlo_acc_params[page].orig_process_assc != 0)
930 return FC_PARSE_FAILURE;
932 if (prlo->prlo_acc_params[page].resp_process_assc != 0)
933 return FC_PARSE_FAILURE;
935 return FC_PARSE_OK;
940 fc_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)
943 struct fc_tprlo_s *tprlo = (struct fc_tprlo_s *) (fchs + 1);
944 int page;
946 fc_els_req_build(fchs, d_id, s_id, ox_id);
947 memset(tprlo, 0, (num_pages * 16) + 4);
948 tprlo->command = FC_ELS_TPRLO;
949 tprlo->page_len = 0x10;
950 tprlo->payload_len = cpu_to_be16((num_pages * 16) + 4);
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);
966 return be16_to_cpu(tprlo->payload_len);
970 fc_tprlo_rsp_parse(struct fchs_s *fchs, int len)
972 struct fc_tprlo_acc_s *tprlo = (struct fc_tprlo_acc_s *) (fchs + 1);
973 int num_pages = 0;
974 int page = 0;
976 len = len;
978 if (tprlo->command != FC_ELS_ACC)
979 return FC_PARSE_ACC_INVAL;
981 num_pages = (be16_to_cpu(tprlo->payload_len) - 4) / 16;
983 for (page = 0; page < num_pages; page++) {
984 if (tprlo->tprlo_acc_params[page].type != FC_TYPE_FCP)
985 return FC_PARSE_NOT_FCP;
986 if (tprlo->tprlo_acc_params[page].opa_valid != 0)
987 return FC_PARSE_OPAFLAG_INVAL;
988 if (tprlo->tprlo_acc_params[page].rpa_valid != 0)
989 return FC_PARSE_RPAFLAG_INVAL;
990 if (tprlo->tprlo_acc_params[page].orig_process_assc != 0)
991 return FC_PARSE_OPA_INVAL;
992 if (tprlo->tprlo_acc_params[page].resp_process_assc != 0)
993 return FC_PARSE_RPA_INVAL;
995 return FC_PARSE_OK;
998 enum fc_parse_status
999 fc_rrq_rsp_parse(struct fchs_s *fchs, int len)
1001 struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
1003 len = len;
1004 if (els_cmd->els_code != FC_ELS_ACC)
1005 return FC_PARSE_FAILURE;
1007 return FC_PARSE_OK;
1011 fc_ba_rjt_build(struct fchs_s *fchs, u32 d_id, u32 s_id, __be16 ox_id,
1012 u32 reason_code, u32 reason_expl)
1014 struct fc_ba_rjt_s *ba_rjt = (struct fc_ba_rjt_s *) (fchs + 1);
1016 fc_bls_rsp_build(fchs, d_id, s_id, ox_id);
1018 fchs->cat_info = FC_CAT_BA_RJT;
1019 ba_rjt->reason_code = reason_code;
1020 ba_rjt->reason_expl = reason_expl;
1021 return sizeof(struct fc_ba_rjt_s);
1024 static void
1025 fc_gs_cthdr_build(struct ct_hdr_s *cthdr, u32 s_id, u16 cmd_code)
1027 memset(cthdr, 0, sizeof(struct ct_hdr_s));
1028 cthdr->rev_id = CT_GS3_REVISION;
1029 cthdr->gs_type = CT_GSTYPE_DIRSERVICE;
1030 cthdr->gs_sub_type = CT_GSSUBTYPE_NAMESERVER;
1031 cthdr->cmd_rsp_code = cpu_to_be16(cmd_code);
1034 static void
1035 fc_gs_fdmi_cthdr_build(struct ct_hdr_s *cthdr, u32 s_id, u16 cmd_code)
1037 memset(cthdr, 0, sizeof(struct ct_hdr_s));
1038 cthdr->rev_id = CT_GS3_REVISION;
1039 cthdr->gs_type = CT_GSTYPE_MGMTSERVICE;
1040 cthdr->gs_sub_type = CT_GSSUBTYPE_HBA_MGMTSERVER;
1041 cthdr->cmd_rsp_code = cpu_to_be16(cmd_code);
1044 static void
1045 fc_gs_ms_cthdr_build(struct ct_hdr_s *cthdr, u32 s_id, u16 cmd_code,
1046 u8 sub_type)
1048 memset(cthdr, 0, sizeof(struct ct_hdr_s));
1049 cthdr->rev_id = CT_GS3_REVISION;
1050 cthdr->gs_type = CT_GSTYPE_MGMTSERVICE;
1051 cthdr->gs_sub_type = sub_type;
1052 cthdr->cmd_rsp_code = cpu_to_be16(cmd_code);
1056 fc_gidpn_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
1057 wwn_t port_name)
1059 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1060 struct fcgs_gidpn_req_s *gidpn = (struct fcgs_gidpn_req_s *)(cthdr + 1);
1061 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
1063 fc_gs_fchdr_build(fchs, d_id, s_id, ox_id);
1064 fc_gs_cthdr_build(cthdr, s_id, GS_GID_PN);
1066 memset(gidpn, 0, sizeof(struct fcgs_gidpn_req_s));
1067 gidpn->port_name = port_name;
1068 return sizeof(struct fcgs_gidpn_req_s) + sizeof(struct ct_hdr_s);
1072 fc_gpnid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
1073 u32 port_id)
1075 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1076 fcgs_gpnid_req_t *gpnid = (fcgs_gpnid_req_t *) (cthdr + 1);
1077 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
1079 fc_gs_fchdr_build(fchs, d_id, s_id, ox_id);
1080 fc_gs_cthdr_build(cthdr, s_id, GS_GPN_ID);
1082 memset(gpnid, 0, sizeof(fcgs_gpnid_req_t));
1083 gpnid->dap = port_id;
1084 return sizeof(fcgs_gpnid_req_t) + sizeof(struct ct_hdr_s);
1088 fc_gnnid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
1089 u32 port_id)
1091 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1092 fcgs_gnnid_req_t *gnnid = (fcgs_gnnid_req_t *) (cthdr + 1);
1093 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
1095 fc_gs_fchdr_build(fchs, d_id, s_id, ox_id);
1096 fc_gs_cthdr_build(cthdr, s_id, GS_GNN_ID);
1098 memset(gnnid, 0, sizeof(fcgs_gnnid_req_t));
1099 gnnid->dap = port_id;
1100 return sizeof(fcgs_gnnid_req_t) + sizeof(struct ct_hdr_s);
1104 fc_ct_rsp_parse(struct ct_hdr_s *cthdr)
1106 if (be16_to_cpu(cthdr->cmd_rsp_code) != CT_RSP_ACCEPT) {
1107 if (cthdr->reason_code == CT_RSN_LOGICAL_BUSY)
1108 return FC_PARSE_BUSY;
1109 else
1110 return FC_PARSE_FAILURE;
1113 return FC_PARSE_OK;
1117 fc_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)
1121 fc_gsresp_fchdr_build(fchs, d_id, s_id, ox_id);
1123 cthdr->cmd_rsp_code = cpu_to_be16(CT_RSP_REJECT);
1124 cthdr->rev_id = CT_GS3_REVISION;
1126 cthdr->reason_code = reason_code;
1127 cthdr->exp_code = reason_code_expl;
1128 return sizeof(struct ct_hdr_s);
1132 fc_scr_build(struct fchs_s *fchs, struct fc_scr_s *scr,
1133 u8 set_br_reg, u32 s_id, u16 ox_id)
1135 u32 d_id = bfa_hton3b(FC_FABRIC_CONTROLLER);
1137 fc_els_req_build(fchs, d_id, s_id, ox_id);
1139 memset(scr, 0, sizeof(struct fc_scr_s));
1140 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;
1145 return sizeof(struct fc_scr_s);
1149 fc_rscn_build(struct fchs_s *fchs, struct fc_rscn_pl_s *rscn,
1150 u32 s_id, u16 ox_id)
1152 u32 d_id = bfa_hton3b(FC_FABRIC_CONTROLLER);
1153 u16 payldlen;
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]);
1159 payldlen = sizeof(u32) + rscn->pagelen;
1160 rscn->payldlen = cpu_to_be16(payldlen);
1162 rscn->event[0].format = FC_RSCN_FORMAT_PORTID;
1163 rscn->event[0].portid = s_id;
1165 return sizeof(struct fc_rscn_pl_s);
1169 fc_rftid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
1170 enum bfa_lport_role roles)
1172 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1173 struct fcgs_rftid_req_s *rftid = (struct fcgs_rftid_req_s *)(cthdr + 1);
1174 u32 type_value, d_id = bfa_hton3b(FC_NAME_SERVER);
1175 u8 index;
1177 fc_gs_fchdr_build(fchs, d_id, s_id, ox_id);
1178 fc_gs_cthdr_build(cthdr, s_id, GS_RFT_ID);
1180 memset(rftid, 0, sizeof(struct fcgs_rftid_req_s));
1182 rftid->dap = s_id;
1184 /* By default, FCP FC4 Type is registered */
1185 index = FC_TYPE_FCP >> 5;
1186 type_value = 1 << (FC_TYPE_FCP % 32);
1187 rftid->fc4_type[index] = cpu_to_be32(type_value);
1189 return sizeof(struct fcgs_rftid_req_s) + sizeof(struct ct_hdr_s);
1193 fc_rftid_build_sol(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
1194 u8 *fc4_bitmap, u32 bitmap_size)
1196 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1197 struct fcgs_rftid_req_s *rftid = (struct fcgs_rftid_req_s *)(cthdr + 1);
1198 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
1200 fc_gs_fchdr_build(fchs, d_id, s_id, ox_id);
1201 fc_gs_cthdr_build(cthdr, s_id, GS_RFT_ID);
1203 memset(rftid, 0, sizeof(struct fcgs_rftid_req_s));
1205 rftid->dap = s_id;
1206 memcpy((void *)rftid->fc4_type, (void *)fc4_bitmap,
1207 (bitmap_size < 32 ? bitmap_size : 32));
1209 return sizeof(struct fcgs_rftid_req_s) + sizeof(struct ct_hdr_s);
1213 fc_rffid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
1214 u8 fc4_type, u8 fc4_ftrs)
1216 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1217 struct fcgs_rffid_req_s *rffid = (struct fcgs_rffid_req_s *)(cthdr + 1);
1218 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
1220 fc_gs_fchdr_build(fchs, d_id, s_id, ox_id);
1221 fc_gs_cthdr_build(cthdr, s_id, GS_RFF_ID);
1223 memset(rffid, 0, sizeof(struct fcgs_rffid_req_s));
1225 rffid->dap = s_id;
1226 rffid->fc4ftr_bits = fc4_ftrs;
1227 rffid->fc4_type = fc4_type;
1229 return sizeof(struct fcgs_rffid_req_s) + sizeof(struct ct_hdr_s);
1233 fc_rspnid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
1234 u8 *name)
1237 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1238 struct fcgs_rspnid_req_s *rspnid =
1239 (struct fcgs_rspnid_req_s *)(cthdr + 1);
1240 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
1242 fc_gs_fchdr_build(fchs, d_id, s_id, ox_id);
1243 fc_gs_cthdr_build(cthdr, s_id, GS_RSPN_ID);
1245 memset(rspnid, 0, sizeof(struct fcgs_rspnid_req_s));
1247 rspnid->dap = s_id;
1248 rspnid->spn_len = (u8) strlen((char *)name);
1249 strncpy((char *)rspnid->spn, (char *)name, rspnid->spn_len);
1251 return sizeof(struct fcgs_rspnid_req_s) + sizeof(struct ct_hdr_s);
1255 fc_gid_ft_build(struct fchs_s *fchs, void *pyld, u32 s_id, u8 fc4_type)
1258 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1259 struct fcgs_gidft_req_s *gidft = (struct fcgs_gidft_req_s *)(cthdr + 1);
1260 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
1262 fc_gs_fchdr_build(fchs, d_id, s_id, 0);
1264 fc_gs_cthdr_build(cthdr, s_id, GS_GID_FT);
1266 memset(gidft, 0, sizeof(struct fcgs_gidft_req_s));
1267 gidft->fc4_type = fc4_type;
1268 gidft->domain_id = 0;
1269 gidft->area_id = 0;
1271 return sizeof(struct fcgs_gidft_req_s) + sizeof(struct ct_hdr_s);
1275 fc_rpnid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u32 port_id,
1276 wwn_t port_name)
1278 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1279 struct fcgs_rpnid_req_s *rpnid = (struct fcgs_rpnid_req_s *)(cthdr + 1);
1280 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
1282 fc_gs_fchdr_build(fchs, d_id, s_id, 0);
1283 fc_gs_cthdr_build(cthdr, s_id, GS_RPN_ID);
1285 memset(rpnid, 0, sizeof(struct fcgs_rpnid_req_s));
1286 rpnid->port_id = port_id;
1287 rpnid->port_name = port_name;
1289 return sizeof(struct fcgs_rpnid_req_s) + sizeof(struct ct_hdr_s);
1293 fc_rnnid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u32 port_id,
1294 wwn_t node_name)
1296 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1297 struct fcgs_rnnid_req_s *rnnid = (struct fcgs_rnnid_req_s *)(cthdr + 1);
1298 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
1300 fc_gs_fchdr_build(fchs, d_id, s_id, 0);
1301 fc_gs_cthdr_build(cthdr, s_id, GS_RNN_ID);
1303 memset(rnnid, 0, sizeof(struct fcgs_rnnid_req_s));
1304 rnnid->port_id = port_id;
1305 rnnid->node_name = node_name;
1307 return sizeof(struct fcgs_rnnid_req_s) + sizeof(struct ct_hdr_s);
1311 fc_rcsid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u32 port_id,
1312 u32 cos)
1314 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1315 struct fcgs_rcsid_req_s *rcsid =
1316 (struct fcgs_rcsid_req_s *) (cthdr + 1);
1317 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
1319 fc_gs_fchdr_build(fchs, d_id, s_id, 0);
1320 fc_gs_cthdr_build(cthdr, s_id, GS_RCS_ID);
1322 memset(rcsid, 0, sizeof(struct fcgs_rcsid_req_s));
1323 rcsid->port_id = port_id;
1324 rcsid->cos = cos;
1326 return sizeof(struct fcgs_rcsid_req_s) + sizeof(struct ct_hdr_s);
1330 fc_rptid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u32 port_id,
1331 u8 port_type)
1333 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1334 struct fcgs_rptid_req_s *rptid = (struct fcgs_rptid_req_s *)(cthdr + 1);
1335 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
1337 fc_gs_fchdr_build(fchs, d_id, s_id, 0);
1338 fc_gs_cthdr_build(cthdr, s_id, GS_RPT_ID);
1340 memset(rptid, 0, sizeof(struct fcgs_rptid_req_s));
1341 rptid->port_id = port_id;
1342 rptid->port_type = port_type;
1344 return sizeof(struct fcgs_rptid_req_s) + sizeof(struct ct_hdr_s);
1348 fc_ganxt_build(struct fchs_s *fchs, void *pyld, u32 s_id, u32 port_id)
1350 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1351 struct fcgs_ganxt_req_s *ganxt = (struct fcgs_ganxt_req_s *)(cthdr + 1);
1352 u32 d_id = bfa_hton3b(FC_NAME_SERVER);
1354 fc_gs_fchdr_build(fchs, d_id, s_id, 0);
1355 fc_gs_cthdr_build(cthdr, s_id, GS_GA_NXT);
1357 memset(ganxt, 0, sizeof(struct fcgs_ganxt_req_s));
1358 ganxt->port_id = port_id;
1360 return sizeof(struct ct_hdr_s) + sizeof(struct fcgs_ganxt_req_s);
1364 * Builds fc hdr and ct hdr for FDMI requests.
1367 fc_fdmi_reqhdr_build(struct fchs_s *fchs, void *pyld, u32 s_id,
1368 u16 cmd_code)
1371 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1372 u32 d_id = bfa_hton3b(FC_MGMT_SERVER);
1374 fc_gs_fchdr_build(fchs, d_id, s_id, 0);
1375 fc_gs_fdmi_cthdr_build(cthdr, s_id, cmd_code);
1377 return sizeof(struct ct_hdr_s);
1381 * Given a FC4 Type, this function returns a fc4 type bitmask
1383 void
1384 fc_get_fc4type_bitmask(u8 fc4_type, u8 *bit_mask)
1386 u8 index;
1387 __be32 *ptr = (__be32 *) bit_mask;
1388 u32 type_value;
1391 * @todo : Check for bitmask size
1394 index = fc4_type >> 5;
1395 type_value = 1 << (fc4_type % 32);
1396 ptr[index] = cpu_to_be32(type_value);
1401 * GMAL Request
1404 fc_gmal_req_build(struct fchs_s *fchs, void *pyld, u32 s_id, wwn_t wwn)
1406 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1407 fcgs_gmal_req_t *gmal = (fcgs_gmal_req_t *) (cthdr + 1);
1408 u32 d_id = bfa_hton3b(FC_MGMT_SERVER);
1410 fc_gs_fchdr_build(fchs, d_id, s_id, 0);
1411 fc_gs_ms_cthdr_build(cthdr, s_id, GS_FC_GMAL_CMD,
1412 CT_GSSUBTYPE_CFGSERVER);
1414 memset(gmal, 0, sizeof(fcgs_gmal_req_t));
1415 gmal->wwn = wwn;
1417 return sizeof(struct ct_hdr_s) + sizeof(fcgs_gmal_req_t);
1421 * GFN (Get Fabric Name) Request
1424 fc_gfn_req_build(struct fchs_s *fchs, void *pyld, u32 s_id, wwn_t wwn)
1426 struct ct_hdr_s *cthdr = (struct ct_hdr_s *) pyld;
1427 fcgs_gfn_req_t *gfn = (fcgs_gfn_req_t *) (cthdr + 1);
1428 u32 d_id = bfa_hton3b(FC_MGMT_SERVER);
1430 fc_gs_fchdr_build(fchs, d_id, s_id, 0);
1431 fc_gs_ms_cthdr_build(cthdr, s_id, GS_FC_GFN_CMD,
1432 CT_GSSUBTYPE_CFGSERVER);
1434 memset(gfn, 0, sizeof(fcgs_gfn_req_t));
1435 gfn->wwn = wwn;
1437 return sizeof(struct ct_hdr_s) + sizeof(fcgs_gfn_req_t);