2 * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
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.
19 #include "bfa_fcbuild.h"
23 BFA_TRC_FILE(FCS
, PORT
);
25 static void bfa_fcs_lport_send_ls_rjt(struct bfa_fcs_lport_s
*port
,
26 struct fchs_s
*rx_fchs
, u8 reason_code
,
28 static void bfa_fcs_lport_plogi(struct bfa_fcs_lport_s
*port
,
29 struct fchs_s
*rx_fchs
, struct fc_logi_s
*plogi
);
30 static void bfa_fcs_lport_online_actions(struct bfa_fcs_lport_s
*port
);
31 static void bfa_fcs_lport_offline_actions(struct bfa_fcs_lport_s
*port
);
32 static void bfa_fcs_lport_unknown_init(struct bfa_fcs_lport_s
*port
);
33 static void bfa_fcs_lport_unknown_online(struct bfa_fcs_lport_s
*port
);
34 static void bfa_fcs_lport_unknown_offline(struct bfa_fcs_lport_s
*port
);
35 static void bfa_fcs_lport_deleted(struct bfa_fcs_lport_s
*port
);
36 static void bfa_fcs_lport_echo(struct bfa_fcs_lport_s
*port
,
37 struct fchs_s
*rx_fchs
,
38 struct fc_echo_s
*echo
, u16 len
);
39 static void bfa_fcs_lport_rnid(struct bfa_fcs_lport_s
*port
,
40 struct fchs_s
*rx_fchs
,
41 struct fc_rnid_cmd_s
*rnid
, u16 len
);
42 static void bfa_fs_port_get_gen_topo_data(struct bfa_fcs_lport_s
*port
,
43 struct fc_rnid_general_topology_data_s
*gen_topo_data
);
45 static void bfa_fcs_lport_fab_init(struct bfa_fcs_lport_s
*port
);
46 static void bfa_fcs_lport_fab_online(struct bfa_fcs_lport_s
*port
);
47 static void bfa_fcs_lport_fab_offline(struct bfa_fcs_lport_s
*port
);
49 static void bfa_fcs_lport_n2n_init(struct bfa_fcs_lport_s
*port
);
50 static void bfa_fcs_lport_n2n_online(struct bfa_fcs_lport_s
*port
);
51 static void bfa_fcs_lport_n2n_offline(struct bfa_fcs_lport_s
*port
);
54 void (*init
) (struct bfa_fcs_lport_s
*port
);
55 void (*online
) (struct bfa_fcs_lport_s
*port
);
56 void (*offline
) (struct bfa_fcs_lport_s
*port
);
59 bfa_fcs_lport_unknown_init
, bfa_fcs_lport_unknown_online
,
60 bfa_fcs_lport_unknown_offline
}, {
61 bfa_fcs_lport_fab_init
, bfa_fcs_lport_fab_online
,
62 bfa_fcs_lport_fab_offline
}, {
63 bfa_fcs_lport_n2n_init
, bfa_fcs_lport_n2n_online
,
64 bfa_fcs_lport_n2n_offline
},
68 * fcs_port_sm FCS logical port state machine
71 enum bfa_fcs_lport_event
{
72 BFA_FCS_PORT_SM_CREATE
= 1,
73 BFA_FCS_PORT_SM_ONLINE
= 2,
74 BFA_FCS_PORT_SM_OFFLINE
= 3,
75 BFA_FCS_PORT_SM_DELETE
= 4,
76 BFA_FCS_PORT_SM_DELRPORT
= 5,
79 static void bfa_fcs_lport_sm_uninit(struct bfa_fcs_lport_s
*port
,
80 enum bfa_fcs_lport_event event
);
81 static void bfa_fcs_lport_sm_init(struct bfa_fcs_lport_s
*port
,
82 enum bfa_fcs_lport_event event
);
83 static void bfa_fcs_lport_sm_online(struct bfa_fcs_lport_s
*port
,
84 enum bfa_fcs_lport_event event
);
85 static void bfa_fcs_lport_sm_offline(struct bfa_fcs_lport_s
*port
,
86 enum bfa_fcs_lport_event event
);
87 static void bfa_fcs_lport_sm_deleting(struct bfa_fcs_lport_s
*port
,
88 enum bfa_fcs_lport_event event
);
91 bfa_fcs_lport_sm_uninit(
92 struct bfa_fcs_lport_s
*port
,
93 enum bfa_fcs_lport_event event
)
95 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
96 bfa_trc(port
->fcs
, event
);
99 case BFA_FCS_PORT_SM_CREATE
:
100 bfa_sm_set_state(port
, bfa_fcs_lport_sm_init
);
104 bfa_sm_fault(port
->fcs
, event
);
109 bfa_fcs_lport_sm_init(struct bfa_fcs_lport_s
*port
,
110 enum bfa_fcs_lport_event event
)
112 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
113 bfa_trc(port
->fcs
, event
);
116 case BFA_FCS_PORT_SM_ONLINE
:
117 bfa_sm_set_state(port
, bfa_fcs_lport_sm_online
);
118 bfa_fcs_lport_online_actions(port
);
121 case BFA_FCS_PORT_SM_DELETE
:
122 bfa_sm_set_state(port
, bfa_fcs_lport_sm_uninit
);
123 bfa_fcs_lport_deleted(port
);
126 case BFA_FCS_PORT_SM_OFFLINE
:
130 bfa_sm_fault(port
->fcs
, event
);
135 bfa_fcs_lport_sm_online(
136 struct bfa_fcs_lport_s
*port
,
137 enum bfa_fcs_lport_event event
)
139 struct bfa_fcs_rport_s
*rport
;
140 struct list_head
*qe
, *qen
;
142 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
143 bfa_trc(port
->fcs
, event
);
146 case BFA_FCS_PORT_SM_OFFLINE
:
147 bfa_sm_set_state(port
, bfa_fcs_lport_sm_offline
);
148 bfa_fcs_lport_offline_actions(port
);
151 case BFA_FCS_PORT_SM_DELETE
:
153 __port_action
[port
->fabric
->fab_type
].offline(port
);
155 if (port
->num_rports
== 0) {
156 bfa_sm_set_state(port
, bfa_fcs_lport_sm_uninit
);
157 bfa_fcs_lport_deleted(port
);
159 bfa_sm_set_state(port
, bfa_fcs_lport_sm_deleting
);
160 list_for_each_safe(qe
, qen
, &port
->rport_q
) {
161 rport
= (struct bfa_fcs_rport_s
*) qe
;
162 bfa_fcs_rport_delete(rport
);
167 case BFA_FCS_PORT_SM_DELRPORT
:
171 bfa_sm_fault(port
->fcs
, event
);
176 bfa_fcs_lport_sm_offline(
177 struct bfa_fcs_lport_s
*port
,
178 enum bfa_fcs_lport_event event
)
180 struct bfa_fcs_rport_s
*rport
;
181 struct list_head
*qe
, *qen
;
183 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
184 bfa_trc(port
->fcs
, event
);
187 case BFA_FCS_PORT_SM_ONLINE
:
188 bfa_sm_set_state(port
, bfa_fcs_lport_sm_online
);
189 bfa_fcs_lport_online_actions(port
);
192 case BFA_FCS_PORT_SM_DELETE
:
193 if (port
->num_rports
== 0) {
194 bfa_sm_set_state(port
, bfa_fcs_lport_sm_uninit
);
195 bfa_fcs_lport_deleted(port
);
197 bfa_sm_set_state(port
, bfa_fcs_lport_sm_deleting
);
198 list_for_each_safe(qe
, qen
, &port
->rport_q
) {
199 rport
= (struct bfa_fcs_rport_s
*) qe
;
200 bfa_fcs_rport_delete(rport
);
205 case BFA_FCS_PORT_SM_DELRPORT
:
206 case BFA_FCS_PORT_SM_OFFLINE
:
210 bfa_sm_fault(port
->fcs
, event
);
215 bfa_fcs_lport_sm_deleting(
216 struct bfa_fcs_lport_s
*port
,
217 enum bfa_fcs_lport_event event
)
219 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
220 bfa_trc(port
->fcs
, event
);
223 case BFA_FCS_PORT_SM_DELRPORT
:
224 if (port
->num_rports
== 0) {
225 bfa_sm_set_state(port
, bfa_fcs_lport_sm_uninit
);
226 bfa_fcs_lport_deleted(port
);
231 bfa_sm_fault(port
->fcs
, event
);
243 bfa_fcs_lport_send_ls_rjt(struct bfa_fcs_lport_s
*port
, struct fchs_s
*rx_fchs
,
244 u8 reason_code
, u8 reason_code_expl
)
247 struct bfa_fcxp_s
*fcxp
;
248 struct bfa_rport_s
*bfa_rport
= NULL
;
251 bfa_trc(port
->fcs
, rx_fchs
->d_id
);
252 bfa_trc(port
->fcs
, rx_fchs
->s_id
);
254 fcxp
= bfa_fcs_fcxp_alloc(port
->fcs
);
258 len
= fc_ls_rjt_build(&fchs
, bfa_fcxp_get_reqbuf(fcxp
),
259 rx_fchs
->s_id
, bfa_fcs_lport_get_fcid(port
),
260 rx_fchs
->ox_id
, reason_code
, reason_code_expl
);
262 bfa_fcxp_send(fcxp
, bfa_rport
, port
->fabric
->vf_id
, port
->lp_tag
,
263 BFA_FALSE
, FC_CLASS_3
, len
, &fchs
, NULL
, NULL
,
268 * Process incoming plogi from a remote port.
271 bfa_fcs_lport_plogi(struct bfa_fcs_lport_s
*port
,
272 struct fchs_s
*rx_fchs
, struct fc_logi_s
*plogi
)
274 struct bfa_fcs_rport_s
*rport
;
276 bfa_trc(port
->fcs
, rx_fchs
->d_id
);
277 bfa_trc(port
->fcs
, rx_fchs
->s_id
);
280 * If min cfg mode is enabled, drop any incoming PLOGIs
282 if (__fcs_min_cfg(port
->fcs
)) {
283 bfa_trc(port
->fcs
, rx_fchs
->s_id
);
287 if (fc_plogi_parse(rx_fchs
) != FC_PARSE_OK
) {
288 bfa_trc(port
->fcs
, rx_fchs
->s_id
);
292 bfa_fcs_lport_send_ls_rjt(port
, rx_fchs
,
293 FC_LS_RJT_RSN_PROTOCOL_ERROR
,
294 FC_LS_RJT_EXP_SPARMS_ERR_OPTIONS
);
299 * Direct Attach P2P mode : verify address assigned by the r-port.
301 if ((!bfa_fcs_fabric_is_switched(port
->fabric
)) &&
302 (memcmp((void *)&bfa_fcs_lport_get_pwwn(port
),
303 (void *)&plogi
->port_name
, sizeof(wwn_t
)) < 0)) {
304 if (BFA_FCS_PID_IS_WKA(rx_fchs
->d_id
)) {
305 /* Address assigned to us cannot be a WKA */
306 bfa_fcs_lport_send_ls_rjt(port
, rx_fchs
,
307 FC_LS_RJT_RSN_PROTOCOL_ERROR
,
308 FC_LS_RJT_EXP_INVALID_NPORT_ID
);
311 port
->pid
= rx_fchs
->d_id
;
315 * First, check if we know the device by pwwn.
317 rport
= bfa_fcs_lport_get_rport_by_pwwn(port
, plogi
->port_name
);
320 * Direct Attach P2P mode : handle address assigned by r-port.
322 if ((!bfa_fcs_fabric_is_switched(port
->fabric
)) &&
323 (memcmp((void *)&bfa_fcs_lport_get_pwwn(port
),
324 (void *)&plogi
->port_name
, sizeof(wwn_t
)) < 0)) {
325 port
->pid
= rx_fchs
->d_id
;
326 rport
->pid
= rx_fchs
->s_id
;
328 bfa_fcs_rport_plogi(rport
, rx_fchs
, plogi
);
333 * Next, lookup rport by PID.
335 rport
= bfa_fcs_lport_get_rport_by_pid(port
, rx_fchs
->s_id
);
338 * Inbound PLOGI from a new device.
340 bfa_fcs_rport_plogi_create(port
, rx_fchs
, plogi
);
345 * Rport is known only by PID.
349 * This is a different device with the same pid. Old device
350 * disappeared. Send implicit LOGO to old device.
352 bfa_assert(rport
->pwwn
!= plogi
->port_name
);
353 bfa_fcs_rport_logo_imp(rport
);
356 * Inbound PLOGI from a new device (with old PID).
358 bfa_fcs_rport_plogi_create(port
, rx_fchs
, plogi
);
363 * PLOGI crossing each other.
365 bfa_assert(rport
->pwwn
== WWN_NULL
);
366 bfa_fcs_rport_plogi(rport
, rx_fchs
, plogi
);
370 * Process incoming ECHO.
371 * Since it does not require a login, it is processed here.
374 bfa_fcs_lport_echo(struct bfa_fcs_lport_s
*port
, struct fchs_s
*rx_fchs
,
375 struct fc_echo_s
*echo
, u16 rx_len
)
378 struct bfa_fcxp_s
*fcxp
;
379 struct bfa_rport_s
*bfa_rport
= NULL
;
382 bfa_trc(port
->fcs
, rx_fchs
->s_id
);
383 bfa_trc(port
->fcs
, rx_fchs
->d_id
);
385 fcxp
= bfa_fcs_fcxp_alloc(port
->fcs
);
389 len
= fc_ls_acc_build(&fchs
, bfa_fcxp_get_reqbuf(fcxp
),
390 rx_fchs
->s_id
, bfa_fcs_lport_get_fcid(port
),
394 * Copy the payload (if any) from the echo frame
396 pyld_len
= rx_len
- sizeof(struct fchs_s
);
397 bfa_trc(port
->fcs
, rx_len
);
398 bfa_trc(port
->fcs
, pyld_len
);
401 memcpy(((u8
*) bfa_fcxp_get_reqbuf(fcxp
)) +
402 sizeof(struct fc_echo_s
), (echo
+ 1),
403 (pyld_len
- sizeof(struct fc_echo_s
)));
405 bfa_fcxp_send(fcxp
, bfa_rport
, port
->fabric
->vf_id
, port
->lp_tag
,
406 BFA_FALSE
, FC_CLASS_3
, pyld_len
, &fchs
, NULL
, NULL
,
411 * Process incoming RNID.
412 * Since it does not require a login, it is processed here.
415 bfa_fcs_lport_rnid(struct bfa_fcs_lport_s
*port
, struct fchs_s
*rx_fchs
,
416 struct fc_rnid_cmd_s
*rnid
, u16 rx_len
)
418 struct fc_rnid_common_id_data_s common_id_data
;
419 struct fc_rnid_general_topology_data_s gen_topo_data
;
421 struct bfa_fcxp_s
*fcxp
;
422 struct bfa_rport_s
*bfa_rport
= NULL
;
426 bfa_trc(port
->fcs
, rx_fchs
->s_id
);
427 bfa_trc(port
->fcs
, rx_fchs
->d_id
);
428 bfa_trc(port
->fcs
, rx_len
);
430 fcxp
= bfa_fcs_fcxp_alloc(port
->fcs
);
435 * Check Node Indentification Data Format
436 * We only support General Topology Discovery Format.
437 * For any other requested Data Formats, we return Common Node Id Data
438 * only, as per FC-LS.
440 bfa_trc(port
->fcs
, rnid
->node_id_data_format
);
441 if (rnid
->node_id_data_format
== RNID_NODEID_DATA_FORMAT_DISCOVERY
) {
442 data_format
= RNID_NODEID_DATA_FORMAT_DISCOVERY
;
444 * Get General topology data for this port
446 bfa_fs_port_get_gen_topo_data(port
, &gen_topo_data
);
448 data_format
= RNID_NODEID_DATA_FORMAT_COMMON
;
452 * Copy the Node Id Info
454 common_id_data
.port_name
= bfa_fcs_lport_get_pwwn(port
);
455 common_id_data
.node_name
= bfa_fcs_lport_get_nwwn(port
);
457 len
= fc_rnid_acc_build(&fchs
, bfa_fcxp_get_reqbuf(fcxp
),
458 rx_fchs
->s_id
, bfa_fcs_lport_get_fcid(port
),
459 rx_fchs
->ox_id
, data_format
, &common_id_data
,
462 bfa_fcxp_send(fcxp
, bfa_rport
, port
->fabric
->vf_id
, port
->lp_tag
,
463 BFA_FALSE
, FC_CLASS_3
, len
, &fchs
, NULL
, NULL
,
468 * Fill out General Topolpgy Discovery Data for RNID ELS.
471 bfa_fs_port_get_gen_topo_data(struct bfa_fcs_lport_s
*port
,
472 struct fc_rnid_general_topology_data_s
*gen_topo_data
)
474 memset(gen_topo_data
, 0,
475 sizeof(struct fc_rnid_general_topology_data_s
));
477 gen_topo_data
->asso_type
= cpu_to_be32(RNID_ASSOCIATED_TYPE_HOST
);
478 gen_topo_data
->phy_port_num
= 0; /* @todo */
479 gen_topo_data
->num_attached_nodes
= cpu_to_be32(1);
483 bfa_fcs_lport_online_actions(struct bfa_fcs_lport_s
*port
)
485 struct bfad_s
*bfad
= (struct bfad_s
*)port
->fcs
->bfad
;
486 char lpwwn_buf
[BFA_STRING_32
];
488 bfa_trc(port
->fcs
, port
->fabric
->oper_type
);
490 __port_action
[port
->fabric
->fab_type
].init(port
);
491 __port_action
[port
->fabric
->fab_type
].online(port
);
493 wwn2str(lpwwn_buf
, bfa_fcs_lport_get_pwwn(port
));
494 BFA_LOG(KERN_INFO
, bfad
, log_level
,
495 "Logical port online: WWN = %s Role = %s\n",
496 lpwwn_buf
, "Initiator");
498 bfad
->bfad_flags
|= BFAD_PORT_ONLINE
;
502 bfa_fcs_lport_offline_actions(struct bfa_fcs_lport_s
*port
)
504 struct list_head
*qe
, *qen
;
505 struct bfa_fcs_rport_s
*rport
;
506 struct bfad_s
*bfad
= (struct bfad_s
*)port
->fcs
->bfad
;
507 char lpwwn_buf
[BFA_STRING_32
];
509 bfa_trc(port
->fcs
, port
->fabric
->oper_type
);
511 __port_action
[port
->fabric
->fab_type
].offline(port
);
513 wwn2str(lpwwn_buf
, bfa_fcs_lport_get_pwwn(port
));
514 if (bfa_fcs_fabric_is_online(port
->fabric
) == BFA_TRUE
)
515 BFA_LOG(KERN_ERR
, bfad
, log_level
,
516 "Logical port lost fabric connectivity: WWN = %s Role = %s\n",
517 lpwwn_buf
, "Initiator");
519 BFA_LOG(KERN_INFO
, bfad
, log_level
,
520 "Logical port taken offline: WWN = %s Role = %s\n",
521 lpwwn_buf
, "Initiator");
523 list_for_each_safe(qe
, qen
, &port
->rport_q
) {
524 rport
= (struct bfa_fcs_rport_s
*) qe
;
525 bfa_fcs_rport_offline(rport
);
530 bfa_fcs_lport_unknown_init(struct bfa_fcs_lport_s
*port
)
536 bfa_fcs_lport_unknown_online(struct bfa_fcs_lport_s
*port
)
542 bfa_fcs_lport_unknown_offline(struct bfa_fcs_lport_s
*port
)
548 bfa_fcs_lport_abts_acc(struct bfa_fcs_lport_s
*port
, struct fchs_s
*rx_fchs
)
551 struct bfa_fcxp_s
*fcxp
;
554 bfa_trc(port
->fcs
, rx_fchs
->d_id
);
555 bfa_trc(port
->fcs
, rx_fchs
->s_id
);
557 fcxp
= bfa_fcs_fcxp_alloc(port
->fcs
);
561 len
= fc_ba_acc_build(&fchs
, bfa_fcxp_get_reqbuf(fcxp
),
562 rx_fchs
->s_id
, bfa_fcs_lport_get_fcid(port
),
565 bfa_fcxp_send(fcxp
, NULL
, port
->fabric
->vf_id
, port
->lp_tag
,
566 BFA_FALSE
, FC_CLASS_3
, len
, &fchs
, NULL
, NULL
,
570 bfa_fcs_lport_deleted(struct bfa_fcs_lport_s
*port
)
572 struct bfad_s
*bfad
= (struct bfad_s
*)port
->fcs
->bfad
;
573 char lpwwn_buf
[BFA_STRING_32
];
575 wwn2str(lpwwn_buf
, bfa_fcs_lport_get_pwwn(port
));
576 BFA_LOG(KERN_INFO
, bfad
, log_level
,
577 "Logical port deleted: WWN = %s Role = %s\n",
578 lpwwn_buf
, "Initiator");
580 /* Base port will be deleted by the OS driver */
582 bfa_fcb_lport_delete(port
->fcs
->bfad
, port
->port_cfg
.roles
,
583 port
->fabric
->vf_drv
,
584 port
->vport
? port
->vport
->vport_drv
: NULL
);
585 bfa_fcs_vport_delete_comp(port
->vport
);
587 bfa_fcs_fabric_port_delete_comp(port
->fabric
);
594 * fcs_lport_api BFA FCS port API
597 * Module initialization
600 bfa_fcs_lport_modinit(struct bfa_fcs_s
*fcs
)
609 bfa_fcs_lport_modexit(struct bfa_fcs_s
*fcs
)
611 bfa_fcs_modexit_comp(fcs
);
615 * Unsolicited frame receive handling.
618 bfa_fcs_lport_uf_recv(struct bfa_fcs_lport_s
*lport
,
619 struct fchs_s
*fchs
, u16 len
)
621 u32 pid
= fchs
->s_id
;
622 struct bfa_fcs_rport_s
*rport
= NULL
;
623 struct fc_els_cmd_s
*els_cmd
= (struct fc_els_cmd_s
*) (fchs
+ 1);
625 bfa_stats(lport
, uf_recvs
);
627 if (!bfa_fcs_lport_is_online(lport
)) {
628 bfa_stats(lport
, uf_recv_drops
);
633 * First, handle ELSs that donot require a login.
638 if ((fchs
->type
== FC_TYPE_ELS
) &&
639 (els_cmd
->els_code
== FC_ELS_PLOGI
)) {
640 bfa_fcs_lport_plogi(lport
, fchs
, (struct fc_logi_s
*) els_cmd
);
645 * Handle ECHO separately.
647 if ((fchs
->type
== FC_TYPE_ELS
) && (els_cmd
->els_code
== FC_ELS_ECHO
)) {
648 bfa_fcs_lport_echo(lport
, fchs
,
649 (struct fc_echo_s
*)els_cmd
, len
);
654 * Handle RNID separately.
656 if ((fchs
->type
== FC_TYPE_ELS
) && (els_cmd
->els_code
== FC_ELS_RNID
)) {
657 bfa_fcs_lport_rnid(lport
, fchs
,
658 (struct fc_rnid_cmd_s
*) els_cmd
, len
);
662 if (fchs
->type
== FC_TYPE_BLS
) {
663 if ((fchs
->routing
== FC_RTG_BASIC_LINK
) &&
664 (fchs
->cat_info
== FC_CAT_ABTS
))
665 bfa_fcs_lport_abts_acc(lport
, fchs
);
669 * look for a matching remote port ID
671 rport
= bfa_fcs_lport_get_rport_by_pid(lport
, pid
);
673 bfa_trc(rport
->fcs
, fchs
->s_id
);
674 bfa_trc(rport
->fcs
, fchs
->d_id
);
675 bfa_trc(rport
->fcs
, fchs
->type
);
677 bfa_fcs_rport_uf_recv(rport
, fchs
, len
);
682 * Only handles ELS frames for now.
684 if (fchs
->type
!= FC_TYPE_ELS
) {
685 bfa_trc(lport
->fcs
, fchs
->type
);
690 bfa_trc(lport
->fcs
, els_cmd
->els_code
);
691 if (els_cmd
->els_code
== FC_ELS_RSCN
) {
692 bfa_fcs_lport_scn_process_rscn(lport
, fchs
, len
);
696 if (els_cmd
->els_code
== FC_ELS_LOGO
) {
698 * @todo Handle LOGO frames received.
703 if (els_cmd
->els_code
== FC_ELS_PRLI
) {
705 * @todo Handle PRLI frames received.
711 * Unhandled ELS frames. Send a LS_RJT.
713 bfa_fcs_lport_send_ls_rjt(lport
, fchs
, FC_LS_RJT_RSN_CMD_NOT_SUPP
,
714 FC_LS_RJT_EXP_NO_ADDL_INFO
);
719 * PID based Lookup for a R-Port in the Port R-Port Queue
721 struct bfa_fcs_rport_s
*
722 bfa_fcs_lport_get_rport_by_pid(struct bfa_fcs_lport_s
*port
, u32 pid
)
724 struct bfa_fcs_rport_s
*rport
;
725 struct list_head
*qe
;
727 list_for_each(qe
, &port
->rport_q
) {
728 rport
= (struct bfa_fcs_rport_s
*) qe
;
729 if (rport
->pid
== pid
)
733 bfa_trc(port
->fcs
, pid
);
738 * PWWN based Lookup for a R-Port in the Port R-Port Queue
740 struct bfa_fcs_rport_s
*
741 bfa_fcs_lport_get_rport_by_pwwn(struct bfa_fcs_lport_s
*port
, wwn_t pwwn
)
743 struct bfa_fcs_rport_s
*rport
;
744 struct list_head
*qe
;
746 list_for_each(qe
, &port
->rport_q
) {
747 rport
= (struct bfa_fcs_rport_s
*) qe
;
748 if (wwn_is_equal(rport
->pwwn
, pwwn
))
752 bfa_trc(port
->fcs
, pwwn
);
757 * NWWN based Lookup for a R-Port in the Port R-Port Queue
759 struct bfa_fcs_rport_s
*
760 bfa_fcs_lport_get_rport_by_nwwn(struct bfa_fcs_lport_s
*port
, wwn_t nwwn
)
762 struct bfa_fcs_rport_s
*rport
;
763 struct list_head
*qe
;
765 list_for_each(qe
, &port
->rport_q
) {
766 rport
= (struct bfa_fcs_rport_s
*) qe
;
767 if (wwn_is_equal(rport
->nwwn
, nwwn
))
771 bfa_trc(port
->fcs
, nwwn
);
776 * Called by rport module when new rports are discovered.
779 bfa_fcs_lport_add_rport(
780 struct bfa_fcs_lport_s
*port
,
781 struct bfa_fcs_rport_s
*rport
)
783 list_add_tail(&rport
->qe
, &port
->rport_q
);
788 * Called by rport module to when rports are deleted.
791 bfa_fcs_lport_del_rport(
792 struct bfa_fcs_lport_s
*port
,
793 struct bfa_fcs_rport_s
*rport
)
795 bfa_assert(bfa_q_is_on_q(&port
->rport_q
, rport
));
796 list_del(&rport
->qe
);
799 bfa_sm_send_event(port
, BFA_FCS_PORT_SM_DELRPORT
);
803 * Called by fabric for base port when fabric login is complete.
804 * Called by vport for virtual ports when FDISC is complete.
807 bfa_fcs_lport_online(struct bfa_fcs_lport_s
*port
)
809 bfa_sm_send_event(port
, BFA_FCS_PORT_SM_ONLINE
);
813 * Called by fabric for base port when fabric goes offline.
814 * Called by vport for virtual ports when virtual port becomes offline.
817 bfa_fcs_lport_offline(struct bfa_fcs_lport_s
*port
)
819 bfa_sm_send_event(port
, BFA_FCS_PORT_SM_OFFLINE
);
823 * Called by fabric to delete base lport and associated resources.
825 * Called by vport to delete lport and associated resources. Should call
826 * bfa_fcs_vport_delete_comp() for vports on completion.
829 bfa_fcs_lport_delete(struct bfa_fcs_lport_s
*port
)
831 bfa_sm_send_event(port
, BFA_FCS_PORT_SM_DELETE
);
835 * Return TRUE if port is online, else return FALSE
838 bfa_fcs_lport_is_online(struct bfa_fcs_lport_s
*port
)
840 return bfa_sm_cmp_state(port
, bfa_fcs_lport_sm_online
);
844 * Attach time initialization of logical ports.
847 bfa_fcs_lport_attach(struct bfa_fcs_lport_s
*lport
, struct bfa_fcs_s
*fcs
,
848 u16 vf_id
, struct bfa_fcs_vport_s
*vport
)
851 lport
->fabric
= bfa_fcs_vf_lookup(fcs
, vf_id
);
852 lport
->vport
= vport
;
853 lport
->lp_tag
= (vport
) ? bfa_lps_get_tag(vport
->lps
) :
854 bfa_lps_get_tag(lport
->fabric
->lps
);
856 INIT_LIST_HEAD(&lport
->rport_q
);
857 lport
->num_rports
= 0;
861 * Logical port initialization of base or virtual port.
862 * Called by fabric for base port or by vport for virtual ports.
866 bfa_fcs_lport_init(struct bfa_fcs_lport_s
*lport
,
867 struct bfa_lport_cfg_s
*port_cfg
)
869 struct bfa_fcs_vport_s
*vport
= lport
->vport
;
870 struct bfad_s
*bfad
= (struct bfad_s
*)lport
->fcs
->bfad
;
871 char lpwwn_buf
[BFA_STRING_32
];
873 lport
->port_cfg
= *port_cfg
;
875 lport
->bfad_port
= bfa_fcb_lport_new(lport
->fcs
->bfad
, lport
,
876 lport
->port_cfg
.roles
,
877 lport
->fabric
->vf_drv
,
878 vport
? vport
->vport_drv
: NULL
);
880 wwn2str(lpwwn_buf
, bfa_fcs_lport_get_pwwn(lport
));
881 BFA_LOG(KERN_INFO
, bfad
, log_level
,
882 "New logical port created: WWN = %s Role = %s\n",
883 lpwwn_buf
, "Initiator");
885 bfa_sm_set_state(lport
, bfa_fcs_lport_sm_uninit
);
886 bfa_sm_send_event(lport
, BFA_FCS_PORT_SM_CREATE
);
894 bfa_fcs_lport_get_attr(
895 struct bfa_fcs_lport_s
*port
,
896 struct bfa_lport_attr_s
*port_attr
)
898 if (bfa_sm_cmp_state(port
, bfa_fcs_lport_sm_online
))
899 port_attr
->pid
= port
->pid
;
903 port_attr
->port_cfg
= port
->port_cfg
;
906 port_attr
->port_type
= bfa_fcs_fabric_port_type(port
->fabric
);
907 port_attr
->loopback
= bfa_fcs_fabric_is_loopback(port
->fabric
);
908 port_attr
->authfail
=
909 bfa_fcs_fabric_is_auth_failed(port
->fabric
);
910 port_attr
->fabric_name
= bfa_fcs_lport_get_fabric_name(port
);
911 memcpy(port_attr
->fabric_ip_addr
,
912 bfa_fcs_lport_get_fabric_ipaddr(port
),
913 BFA_FCS_FABRIC_IPADDR_SZ
);
915 if (port
->vport
!= NULL
) {
916 port_attr
->port_type
= BFA_PORT_TYPE_VPORT
;
917 port_attr
->fpma_mac
=
918 bfa_lps_get_lp_mac(port
->vport
->lps
);
920 port_attr
->fpma_mac
=
921 bfa_lps_get_lp_mac(port
->fabric
->lps
);
924 port_attr
->port_type
= BFA_PORT_TYPE_UNKNOWN
;
925 port_attr
->state
= BFA_LPORT_UNINIT
;
930 * bfa_fcs_lport_fab port fab functions
934 * Called by port to initialize fabric services of the base port.
937 bfa_fcs_lport_fab_init(struct bfa_fcs_lport_s
*port
)
939 bfa_fcs_lport_ns_init(port
);
940 bfa_fcs_lport_scn_init(port
);
941 bfa_fcs_lport_ms_init(port
);
945 * Called by port to notify transition to online state.
948 bfa_fcs_lport_fab_online(struct bfa_fcs_lport_s
*port
)
950 bfa_fcs_lport_ns_online(port
);
951 bfa_fcs_lport_scn_online(port
);
955 * Called by port to notify transition to offline state.
958 bfa_fcs_lport_fab_offline(struct bfa_fcs_lport_s
*port
)
960 bfa_fcs_lport_ns_offline(port
);
961 bfa_fcs_lport_scn_offline(port
);
962 bfa_fcs_lport_ms_offline(port
);
966 * bfa_fcs_lport_n2n functions
970 * Called by fcs/port to initialize N2N topology.
973 bfa_fcs_lport_n2n_init(struct bfa_fcs_lport_s
*port
)
978 * Called by fcs/port to notify transition to online state.
981 bfa_fcs_lport_n2n_online(struct bfa_fcs_lport_s
*port
)
983 struct bfa_fcs_lport_n2n_s
*n2n_port
= &port
->port_topo
.pn2n
;
984 struct bfa_lport_cfg_s
*pcfg
= &port
->port_cfg
;
985 struct bfa_fcs_rport_s
*rport
;
987 bfa_trc(port
->fcs
, pcfg
->pwwn
);
990 * If our PWWN is > than that of the r-port, we have to initiate PLOGI
991 * and assign an Address. if not, we need to wait for its PLOGI.
993 * If our PWWN is < than that of the remote port, it will send a PLOGI
994 * with the PIDs assigned. The rport state machine take care of this
998 ((void *)&pcfg
->pwwn
, (void *)&n2n_port
->rem_port_wwn
,
999 sizeof(wwn_t
)) > 0) {
1000 port
->pid
= N2N_LOCAL_PID
;
1002 * First, check if we know the device by pwwn.
1004 rport
= bfa_fcs_lport_get_rport_by_pwwn(port
,
1005 n2n_port
->rem_port_wwn
);
1007 bfa_trc(port
->fcs
, rport
->pid
);
1008 bfa_trc(port
->fcs
, rport
->pwwn
);
1009 rport
->pid
= N2N_REMOTE_PID
;
1010 bfa_fcs_rport_online(rport
);
1015 * In n2n there can be only one rport. Delete the old one
1016 * whose pid should be zero, because it is offline.
1018 if (port
->num_rports
> 0) {
1019 rport
= bfa_fcs_lport_get_rport_by_pid(port
, 0);
1020 bfa_assert(rport
!= NULL
);
1022 bfa_trc(port
->fcs
, rport
->pwwn
);
1023 bfa_fcs_rport_delete(rport
);
1026 bfa_fcs_rport_create(port
, N2N_REMOTE_PID
);
1031 * Called by fcs/port to notify transition to offline state.
1034 bfa_fcs_lport_n2n_offline(struct bfa_fcs_lport_s
*port
)
1036 struct bfa_fcs_lport_n2n_s
*n2n_port
= &port
->port_topo
.pn2n
;
1038 bfa_trc(port
->fcs
, port
->pid
);
1040 n2n_port
->rem_port_wwn
= 0;
1041 n2n_port
->reply_oxid
= 0;
1044 #define BFA_FCS_FDMI_CMD_MAX_RETRIES 2
1047 * forward declarations
1049 static void bfa_fcs_lport_fdmi_send_rhba(void *fdmi_cbarg
,
1050 struct bfa_fcxp_s
*fcxp_alloced
);
1051 static void bfa_fcs_lport_fdmi_send_rprt(void *fdmi_cbarg
,
1052 struct bfa_fcxp_s
*fcxp_alloced
);
1053 static void bfa_fcs_lport_fdmi_send_rpa(void *fdmi_cbarg
,
1054 struct bfa_fcxp_s
*fcxp_alloced
);
1055 static void bfa_fcs_lport_fdmi_rhba_response(void *fcsarg
,
1056 struct bfa_fcxp_s
*fcxp
,
1058 bfa_status_t req_status
,
1061 struct fchs_s
*rsp_fchs
);
1062 static void bfa_fcs_lport_fdmi_rprt_response(void *fcsarg
,
1063 struct bfa_fcxp_s
*fcxp
,
1065 bfa_status_t req_status
,
1068 struct fchs_s
*rsp_fchs
);
1069 static void bfa_fcs_lport_fdmi_rpa_response(void *fcsarg
,
1070 struct bfa_fcxp_s
*fcxp
,
1072 bfa_status_t req_status
,
1075 struct fchs_s
*rsp_fchs
);
1076 static void bfa_fcs_lport_fdmi_timeout(void *arg
);
1077 static u16
bfa_fcs_lport_fdmi_build_rhba_pyld(struct bfa_fcs_lport_fdmi_s
*fdmi
,
1079 static u16
bfa_fcs_lport_fdmi_build_rprt_pyld(struct bfa_fcs_lport_fdmi_s
*fdmi
,
1081 static u16
bfa_fcs_lport_fdmi_build_rpa_pyld(struct bfa_fcs_lport_fdmi_s
*fdmi
,
1083 static u16
bfa_fcs_lport_fdmi_build_portattr_block(struct bfa_fcs_lport_fdmi_s
*
1085 static void bfa_fcs_fdmi_get_hbaattr(struct bfa_fcs_lport_fdmi_s
*fdmi
,
1086 struct bfa_fcs_fdmi_hba_attr_s
*hba_attr
);
1087 static void bfa_fcs_fdmi_get_portattr(struct bfa_fcs_lport_fdmi_s
*fdmi
,
1088 struct bfa_fcs_fdmi_port_attr_s
*port_attr
);
1090 * fcs_fdmi_sm FCS FDMI state machine
1094 * FDMI State Machine events
1096 enum port_fdmi_event
{
1097 FDMISM_EVENT_PORT_ONLINE
= 1,
1098 FDMISM_EVENT_PORT_OFFLINE
= 2,
1099 FDMISM_EVENT_RSP_OK
= 4,
1100 FDMISM_EVENT_RSP_ERROR
= 5,
1101 FDMISM_EVENT_TIMEOUT
= 6,
1102 FDMISM_EVENT_RHBA_SENT
= 7,
1103 FDMISM_EVENT_RPRT_SENT
= 8,
1104 FDMISM_EVENT_RPA_SENT
= 9,
1107 static void bfa_fcs_lport_fdmi_sm_offline(struct bfa_fcs_lport_fdmi_s
*fdmi
,
1108 enum port_fdmi_event event
);
1109 static void bfa_fcs_lport_fdmi_sm_sending_rhba(
1110 struct bfa_fcs_lport_fdmi_s
*fdmi
,
1111 enum port_fdmi_event event
);
1112 static void bfa_fcs_lport_fdmi_sm_rhba(struct bfa_fcs_lport_fdmi_s
*fdmi
,
1113 enum port_fdmi_event event
);
1114 static void bfa_fcs_lport_fdmi_sm_rhba_retry(
1115 struct bfa_fcs_lport_fdmi_s
*fdmi
,
1116 enum port_fdmi_event event
);
1117 static void bfa_fcs_lport_fdmi_sm_sending_rprt(
1118 struct bfa_fcs_lport_fdmi_s
*fdmi
,
1119 enum port_fdmi_event event
);
1120 static void bfa_fcs_lport_fdmi_sm_rprt(struct bfa_fcs_lport_fdmi_s
*fdmi
,
1121 enum port_fdmi_event event
);
1122 static void bfa_fcs_lport_fdmi_sm_rprt_retry(
1123 struct bfa_fcs_lport_fdmi_s
*fdmi
,
1124 enum port_fdmi_event event
);
1125 static void bfa_fcs_lport_fdmi_sm_sending_rpa(
1126 struct bfa_fcs_lport_fdmi_s
*fdmi
,
1127 enum port_fdmi_event event
);
1128 static void bfa_fcs_lport_fdmi_sm_rpa(struct bfa_fcs_lport_fdmi_s
*fdmi
,
1129 enum port_fdmi_event event
);
1130 static void bfa_fcs_lport_fdmi_sm_rpa_retry(
1131 struct bfa_fcs_lport_fdmi_s
*fdmi
,
1132 enum port_fdmi_event event
);
1133 static void bfa_fcs_lport_fdmi_sm_online(struct bfa_fcs_lport_fdmi_s
*fdmi
,
1134 enum port_fdmi_event event
);
1135 static void bfa_fcs_lport_fdmi_sm_disabled(
1136 struct bfa_fcs_lport_fdmi_s
*fdmi
,
1137 enum port_fdmi_event event
);
1139 * Start in offline state - awaiting MS to send start.
1142 bfa_fcs_lport_fdmi_sm_offline(struct bfa_fcs_lport_fdmi_s
*fdmi
,
1143 enum port_fdmi_event event
)
1145 struct bfa_fcs_lport_s
*port
= fdmi
->ms
->port
;
1147 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
1148 bfa_trc(port
->fcs
, event
);
1150 fdmi
->retry_cnt
= 0;
1153 case FDMISM_EVENT_PORT_ONLINE
:
1156 * For Vports, register a new port.
1158 bfa_sm_set_state(fdmi
,
1159 bfa_fcs_lport_fdmi_sm_sending_rprt
);
1160 bfa_fcs_lport_fdmi_send_rprt(fdmi
, NULL
);
1163 * For a base port, we should first register the HBA
1164 * atribute. The HBA attribute also contains the base
1165 * port registration.
1167 bfa_sm_set_state(fdmi
,
1168 bfa_fcs_lport_fdmi_sm_sending_rhba
);
1169 bfa_fcs_lport_fdmi_send_rhba(fdmi
, NULL
);
1173 case FDMISM_EVENT_PORT_OFFLINE
:
1177 bfa_sm_fault(port
->fcs
, event
);
1182 bfa_fcs_lport_fdmi_sm_sending_rhba(struct bfa_fcs_lport_fdmi_s
*fdmi
,
1183 enum port_fdmi_event event
)
1185 struct bfa_fcs_lport_s
*port
= fdmi
->ms
->port
;
1187 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
1188 bfa_trc(port
->fcs
, event
);
1191 case FDMISM_EVENT_RHBA_SENT
:
1192 bfa_sm_set_state(fdmi
, bfa_fcs_lport_fdmi_sm_rhba
);
1195 case FDMISM_EVENT_PORT_OFFLINE
:
1196 bfa_sm_set_state(fdmi
, bfa_fcs_lport_fdmi_sm_offline
);
1197 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(port
),
1202 bfa_sm_fault(port
->fcs
, event
);
1207 bfa_fcs_lport_fdmi_sm_rhba(struct bfa_fcs_lport_fdmi_s
*fdmi
,
1208 enum port_fdmi_event event
)
1210 struct bfa_fcs_lport_s
*port
= fdmi
->ms
->port
;
1212 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
1213 bfa_trc(port
->fcs
, event
);
1216 case FDMISM_EVENT_RSP_ERROR
:
1218 * if max retries have not been reached, start timer for a
1221 if (fdmi
->retry_cnt
++ < BFA_FCS_FDMI_CMD_MAX_RETRIES
) {
1222 bfa_sm_set_state(fdmi
,
1223 bfa_fcs_lport_fdmi_sm_rhba_retry
);
1224 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(port
),
1226 bfa_fcs_lport_fdmi_timeout
, fdmi
,
1227 BFA_FCS_RETRY_TIMEOUT
);
1230 * set state to offline
1232 bfa_sm_set_state(fdmi
, bfa_fcs_lport_fdmi_sm_offline
);
1236 case FDMISM_EVENT_RSP_OK
:
1238 * Initiate Register Port Attributes
1240 bfa_sm_set_state(fdmi
, bfa_fcs_lport_fdmi_sm_sending_rpa
);
1241 fdmi
->retry_cnt
= 0;
1242 bfa_fcs_lport_fdmi_send_rpa(fdmi
, NULL
);
1245 case FDMISM_EVENT_PORT_OFFLINE
:
1246 bfa_fcxp_discard(fdmi
->fcxp
);
1247 bfa_sm_set_state(fdmi
, bfa_fcs_lport_fdmi_sm_offline
);
1251 bfa_sm_fault(port
->fcs
, event
);
1256 bfa_fcs_lport_fdmi_sm_rhba_retry(struct bfa_fcs_lport_fdmi_s
*fdmi
,
1257 enum port_fdmi_event event
)
1259 struct bfa_fcs_lport_s
*port
= fdmi
->ms
->port
;
1261 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
1262 bfa_trc(port
->fcs
, event
);
1265 case FDMISM_EVENT_TIMEOUT
:
1267 * Retry Timer Expired. Re-send
1269 bfa_sm_set_state(fdmi
, bfa_fcs_lport_fdmi_sm_sending_rhba
);
1270 bfa_fcs_lport_fdmi_send_rhba(fdmi
, NULL
);
1273 case FDMISM_EVENT_PORT_OFFLINE
:
1274 bfa_sm_set_state(fdmi
, bfa_fcs_lport_fdmi_sm_offline
);
1275 bfa_timer_stop(&fdmi
->timer
);
1279 bfa_sm_fault(port
->fcs
, event
);
1284 * RPRT : Register Port
1287 bfa_fcs_lport_fdmi_sm_sending_rprt(struct bfa_fcs_lport_fdmi_s
*fdmi
,
1288 enum port_fdmi_event event
)
1290 struct bfa_fcs_lport_s
*port
= fdmi
->ms
->port
;
1292 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
1293 bfa_trc(port
->fcs
, event
);
1296 case FDMISM_EVENT_RPRT_SENT
:
1297 bfa_sm_set_state(fdmi
, bfa_fcs_lport_fdmi_sm_rprt
);
1300 case FDMISM_EVENT_PORT_OFFLINE
:
1301 bfa_sm_set_state(fdmi
, bfa_fcs_lport_fdmi_sm_offline
);
1302 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(port
),
1307 bfa_sm_fault(port
->fcs
, event
);
1312 bfa_fcs_lport_fdmi_sm_rprt(struct bfa_fcs_lport_fdmi_s
*fdmi
,
1313 enum port_fdmi_event event
)
1315 struct bfa_fcs_lport_s
*port
= fdmi
->ms
->port
;
1317 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
1318 bfa_trc(port
->fcs
, event
);
1321 case FDMISM_EVENT_RSP_ERROR
:
1323 * if max retries have not been reached, start timer for a
1326 if (fdmi
->retry_cnt
++ < BFA_FCS_FDMI_CMD_MAX_RETRIES
) {
1327 bfa_sm_set_state(fdmi
,
1328 bfa_fcs_lport_fdmi_sm_rprt_retry
);
1329 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(port
),
1331 bfa_fcs_lport_fdmi_timeout
, fdmi
,
1332 BFA_FCS_RETRY_TIMEOUT
);
1336 * set state to offline
1338 bfa_sm_set_state(fdmi
, bfa_fcs_lport_fdmi_sm_offline
);
1339 fdmi
->retry_cnt
= 0;
1343 case FDMISM_EVENT_RSP_OK
:
1344 fdmi
->retry_cnt
= 0;
1345 bfa_sm_set_state(fdmi
, bfa_fcs_lport_fdmi_sm_online
);
1348 case FDMISM_EVENT_PORT_OFFLINE
:
1349 bfa_fcxp_discard(fdmi
->fcxp
);
1350 bfa_sm_set_state(fdmi
, bfa_fcs_lport_fdmi_sm_offline
);
1354 bfa_sm_fault(port
->fcs
, event
);
1359 bfa_fcs_lport_fdmi_sm_rprt_retry(struct bfa_fcs_lport_fdmi_s
*fdmi
,
1360 enum port_fdmi_event event
)
1362 struct bfa_fcs_lport_s
*port
= fdmi
->ms
->port
;
1364 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
1365 bfa_trc(port
->fcs
, event
);
1368 case FDMISM_EVENT_TIMEOUT
:
1370 * Retry Timer Expired. Re-send
1372 bfa_sm_set_state(fdmi
, bfa_fcs_lport_fdmi_sm_sending_rprt
);
1373 bfa_fcs_lport_fdmi_send_rprt(fdmi
, NULL
);
1376 case FDMISM_EVENT_PORT_OFFLINE
:
1377 bfa_sm_set_state(fdmi
, bfa_fcs_lport_fdmi_sm_offline
);
1378 bfa_timer_stop(&fdmi
->timer
);
1382 bfa_sm_fault(port
->fcs
, event
);
1387 * Register Port Attributes
1390 bfa_fcs_lport_fdmi_sm_sending_rpa(struct bfa_fcs_lport_fdmi_s
*fdmi
,
1391 enum port_fdmi_event event
)
1393 struct bfa_fcs_lport_s
*port
= fdmi
->ms
->port
;
1395 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
1396 bfa_trc(port
->fcs
, event
);
1399 case FDMISM_EVENT_RPA_SENT
:
1400 bfa_sm_set_state(fdmi
, bfa_fcs_lport_fdmi_sm_rpa
);
1403 case FDMISM_EVENT_PORT_OFFLINE
:
1404 bfa_sm_set_state(fdmi
, bfa_fcs_lport_fdmi_sm_offline
);
1405 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(port
),
1410 bfa_sm_fault(port
->fcs
, event
);
1415 bfa_fcs_lport_fdmi_sm_rpa(struct bfa_fcs_lport_fdmi_s
*fdmi
,
1416 enum port_fdmi_event event
)
1418 struct bfa_fcs_lport_s
*port
= fdmi
->ms
->port
;
1420 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
1421 bfa_trc(port
->fcs
, event
);
1424 case FDMISM_EVENT_RSP_ERROR
:
1426 * if max retries have not been reached, start timer for a
1429 if (fdmi
->retry_cnt
++ < BFA_FCS_FDMI_CMD_MAX_RETRIES
) {
1430 bfa_sm_set_state(fdmi
, bfa_fcs_lport_fdmi_sm_rpa_retry
);
1431 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(port
),
1433 bfa_fcs_lport_fdmi_timeout
, fdmi
,
1434 BFA_FCS_RETRY_TIMEOUT
);
1437 * set state to offline
1439 bfa_sm_set_state(fdmi
, bfa_fcs_lport_fdmi_sm_offline
);
1440 fdmi
->retry_cnt
= 0;
1444 case FDMISM_EVENT_RSP_OK
:
1445 bfa_sm_set_state(fdmi
, bfa_fcs_lport_fdmi_sm_online
);
1446 fdmi
->retry_cnt
= 0;
1449 case FDMISM_EVENT_PORT_OFFLINE
:
1450 bfa_fcxp_discard(fdmi
->fcxp
);
1451 bfa_sm_set_state(fdmi
, bfa_fcs_lport_fdmi_sm_offline
);
1455 bfa_sm_fault(port
->fcs
, event
);
1460 bfa_fcs_lport_fdmi_sm_rpa_retry(struct bfa_fcs_lport_fdmi_s
*fdmi
,
1461 enum port_fdmi_event event
)
1463 struct bfa_fcs_lport_s
*port
= fdmi
->ms
->port
;
1465 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
1466 bfa_trc(port
->fcs
, event
);
1469 case FDMISM_EVENT_TIMEOUT
:
1471 * Retry Timer Expired. Re-send
1473 bfa_sm_set_state(fdmi
, bfa_fcs_lport_fdmi_sm_sending_rpa
);
1474 bfa_fcs_lport_fdmi_send_rpa(fdmi
, NULL
);
1477 case FDMISM_EVENT_PORT_OFFLINE
:
1478 bfa_sm_set_state(fdmi
, bfa_fcs_lport_fdmi_sm_offline
);
1479 bfa_timer_stop(&fdmi
->timer
);
1483 bfa_sm_fault(port
->fcs
, event
);
1488 bfa_fcs_lport_fdmi_sm_online(struct bfa_fcs_lport_fdmi_s
*fdmi
,
1489 enum port_fdmi_event event
)
1491 struct bfa_fcs_lport_s
*port
= fdmi
->ms
->port
;
1493 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
1494 bfa_trc(port
->fcs
, event
);
1497 case FDMISM_EVENT_PORT_OFFLINE
:
1498 bfa_sm_set_state(fdmi
, bfa_fcs_lport_fdmi_sm_offline
);
1502 bfa_sm_fault(port
->fcs
, event
);
1506 * FDMI is disabled state.
1509 bfa_fcs_lport_fdmi_sm_disabled(struct bfa_fcs_lport_fdmi_s
*fdmi
,
1510 enum port_fdmi_event event
)
1512 struct bfa_fcs_lport_s
*port
= fdmi
->ms
->port
;
1514 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
1515 bfa_trc(port
->fcs
, event
);
1517 /* No op State. It can only be enabled at Driver Init. */
1521 * RHBA : Register HBA Attributes.
1524 bfa_fcs_lport_fdmi_send_rhba(void *fdmi_cbarg
, struct bfa_fcxp_s
*fcxp_alloced
)
1526 struct bfa_fcs_lport_fdmi_s
*fdmi
= fdmi_cbarg
;
1527 struct bfa_fcs_lport_s
*port
= fdmi
->ms
->port
;
1530 struct bfa_fcxp_s
*fcxp
;
1533 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
1535 fcxp
= fcxp_alloced
? fcxp_alloced
: bfa_fcs_fcxp_alloc(port
->fcs
);
1537 bfa_fcs_fcxp_alloc_wait(port
->fcs
->bfa
, &fdmi
->fcxp_wqe
,
1538 bfa_fcs_lport_fdmi_send_rhba
, fdmi
);
1543 pyld
= bfa_fcxp_get_reqbuf(fcxp
);
1544 memset(pyld
, 0, FC_MAX_PDUSZ
);
1546 len
= fc_fdmi_reqhdr_build(&fchs
, pyld
, bfa_fcs_lport_get_fcid(port
),
1550 bfa_fcs_lport_fdmi_build_rhba_pyld(fdmi
,
1551 (u8
*) ((struct ct_hdr_s
*) pyld
1554 bfa_fcxp_send(fcxp
, NULL
, port
->fabric
->vf_id
, port
->lp_tag
, BFA_FALSE
,
1555 FC_CLASS_3
, (len
+ attr_len
), &fchs
,
1556 bfa_fcs_lport_fdmi_rhba_response
, (void *)fdmi
,
1557 FC_MAX_PDUSZ
, FC_FCCT_TOV
);
1559 bfa_sm_send_event(fdmi
, FDMISM_EVENT_RHBA_SENT
);
1563 bfa_fcs_lport_fdmi_build_rhba_pyld(struct bfa_fcs_lport_fdmi_s
*fdmi
, u8
*pyld
)
1565 struct bfa_fcs_lport_s
*port
= fdmi
->ms
->port
;
1566 struct bfa_fcs_fdmi_hba_attr_s hba_attr
;
1567 struct bfa_fcs_fdmi_hba_attr_s
*fcs_hba_attr
= &hba_attr
;
1568 struct fdmi_rhba_s
*rhba
= (struct fdmi_rhba_s
*) pyld
;
1569 struct fdmi_attr_s
*attr
;
1574 * get hba attributes
1576 bfa_fcs_fdmi_get_hbaattr(fdmi
, fcs_hba_attr
);
1578 rhba
->hba_id
= bfa_fcs_lport_get_pwwn(port
);
1579 rhba
->port_list
.num_ports
= cpu_to_be32(1);
1580 rhba
->port_list
.port_entry
= bfa_fcs_lport_get_pwwn(port
);
1582 len
= sizeof(rhba
->hba_id
) + sizeof(rhba
->port_list
);
1585 len
+= sizeof(rhba
->hba_attr_blk
.attr_count
);
1588 * fill out the invididual entries of the HBA attrib Block
1590 curr_ptr
= (u8
*) &rhba
->hba_attr_blk
.hba_attr
;
1595 attr
= (struct fdmi_attr_s
*) curr_ptr
;
1596 attr
->type
= cpu_to_be16(FDMI_HBA_ATTRIB_NODENAME
);
1597 attr
->len
= sizeof(wwn_t
);
1598 memcpy(attr
->value
, &bfa_fcs_lport_get_nwwn(port
), attr
->len
);
1599 curr_ptr
+= sizeof(attr
->type
) + sizeof(attr
->len
) + attr
->len
;
1602 attr
->len
= cpu_to_be16(attr
->len
+ sizeof(attr
->type
) +
1608 attr
= (struct fdmi_attr_s
*) curr_ptr
;
1609 attr
->type
= cpu_to_be16(FDMI_HBA_ATTRIB_MANUFACTURER
);
1610 attr
->len
= (u16
) strlen(fcs_hba_attr
->manufacturer
);
1611 memcpy(attr
->value
, fcs_hba_attr
->manufacturer
, attr
->len
);
1612 attr
->len
= fc_roundup(attr
->len
, sizeof(u32
));
1613 curr_ptr
+= sizeof(attr
->type
) + sizeof(attr
->len
) + attr
->len
;
1616 attr
->len
= cpu_to_be16(attr
->len
+ sizeof(attr
->type
) +
1622 attr
= (struct fdmi_attr_s
*) curr_ptr
;
1623 attr
->type
= cpu_to_be16(FDMI_HBA_ATTRIB_SERIALNUM
);
1624 attr
->len
= (u16
) strlen(fcs_hba_attr
->serial_num
);
1625 memcpy(attr
->value
, fcs_hba_attr
->serial_num
, attr
->len
);
1626 attr
->len
= fc_roundup(attr
->len
, sizeof(u32
));
1627 curr_ptr
+= sizeof(attr
->type
) + sizeof(attr
->len
) + attr
->len
;
1630 attr
->len
= cpu_to_be16(attr
->len
+ sizeof(attr
->type
) +
1636 attr
= (struct fdmi_attr_s
*) curr_ptr
;
1637 attr
->type
= cpu_to_be16(FDMI_HBA_ATTRIB_MODEL
);
1638 attr
->len
= (u16
) strlen(fcs_hba_attr
->model
);
1639 memcpy(attr
->value
, fcs_hba_attr
->model
, attr
->len
);
1640 attr
->len
= fc_roundup(attr
->len
, sizeof(u32
));
1641 curr_ptr
+= sizeof(attr
->type
) + sizeof(attr
->len
) + attr
->len
;
1644 attr
->len
= cpu_to_be16(attr
->len
+ sizeof(attr
->type
) +
1650 attr
= (struct fdmi_attr_s
*) curr_ptr
;
1651 attr
->type
= cpu_to_be16(FDMI_HBA_ATTRIB_MODEL_DESC
);
1652 attr
->len
= (u16
) strlen(fcs_hba_attr
->model_desc
);
1653 memcpy(attr
->value
, fcs_hba_attr
->model_desc
, attr
->len
);
1654 attr
->len
= fc_roundup(attr
->len
, sizeof(u32
));
1655 curr_ptr
+= sizeof(attr
->type
) + sizeof(attr
->len
) + attr
->len
;
1658 attr
->len
= cpu_to_be16(attr
->len
+ sizeof(attr
->type
) +
1664 if (fcs_hba_attr
->hw_version
[0] != '\0') {
1665 attr
= (struct fdmi_attr_s
*) curr_ptr
;
1666 attr
->type
= cpu_to_be16(FDMI_HBA_ATTRIB_HW_VERSION
);
1667 attr
->len
= (u16
) strlen(fcs_hba_attr
->hw_version
);
1668 memcpy(attr
->value
, fcs_hba_attr
->hw_version
, attr
->len
);
1669 attr
->len
= fc_roundup(attr
->len
, sizeof(u32
));
1670 curr_ptr
+= sizeof(attr
->type
) + sizeof(attr
->len
) + attr
->len
;
1673 attr
->len
= cpu_to_be16(attr
->len
+ sizeof(attr
->type
) +
1680 attr
= (struct fdmi_attr_s
*) curr_ptr
;
1681 attr
->type
= cpu_to_be16(FDMI_HBA_ATTRIB_DRIVER_VERSION
);
1682 attr
->len
= (u16
) strlen(fcs_hba_attr
->driver_version
);
1683 memcpy(attr
->value
, fcs_hba_attr
->driver_version
, attr
->len
);
1684 attr
->len
= fc_roundup(attr
->len
, sizeof(u32
));
1685 curr_ptr
+= sizeof(attr
->type
) + sizeof(attr
->len
) + attr
->len
;
1688 attr
->len
= cpu_to_be16(attr
->len
+ sizeof(attr
->type
) +
1692 * Option Rom Version
1694 if (fcs_hba_attr
->option_rom_ver
[0] != '\0') {
1695 attr
= (struct fdmi_attr_s
*) curr_ptr
;
1696 attr
->type
= cpu_to_be16(FDMI_HBA_ATTRIB_ROM_VERSION
);
1697 attr
->len
= (u16
) strlen(fcs_hba_attr
->option_rom_ver
);
1698 memcpy(attr
->value
, fcs_hba_attr
->option_rom_ver
, attr
->len
);
1699 attr
->len
= fc_roundup(attr
->len
, sizeof(u32
));
1700 curr_ptr
+= sizeof(attr
->type
) + sizeof(attr
->len
) + attr
->len
;
1703 attr
->len
= cpu_to_be16(attr
->len
+ sizeof(attr
->type
) +
1708 * f/w Version = driver version
1710 attr
= (struct fdmi_attr_s
*) curr_ptr
;
1711 attr
->type
= cpu_to_be16(FDMI_HBA_ATTRIB_FW_VERSION
);
1712 attr
->len
= (u16
) strlen(fcs_hba_attr
->driver_version
);
1713 memcpy(attr
->value
, fcs_hba_attr
->driver_version
, attr
->len
);
1714 attr
->len
= fc_roundup(attr
->len
, sizeof(u32
));
1715 curr_ptr
+= sizeof(attr
->type
) + sizeof(attr
->len
) + attr
->len
;
1718 attr
->len
= cpu_to_be16(attr
->len
+ sizeof(attr
->type
) +
1724 if (fcs_hba_attr
->os_name
[0] != '\0') {
1725 attr
= (struct fdmi_attr_s
*) curr_ptr
;
1726 attr
->type
= cpu_to_be16(FDMI_HBA_ATTRIB_OS_NAME
);
1727 attr
->len
= (u16
) strlen(fcs_hba_attr
->os_name
);
1728 memcpy(attr
->value
, fcs_hba_attr
->os_name
, attr
->len
);
1729 attr
->len
= fc_roundup(attr
->len
, sizeof(u32
));
1730 curr_ptr
+= sizeof(attr
->type
) + sizeof(attr
->len
) + attr
->len
;
1733 attr
->len
= cpu_to_be16(attr
->len
+ sizeof(attr
->type
) +
1740 attr
= (struct fdmi_attr_s
*) curr_ptr
;
1741 attr
->type
= cpu_to_be16(FDMI_HBA_ATTRIB_MAX_CT
);
1742 attr
->len
= sizeof(fcs_hba_attr
->max_ct_pyld
);
1743 memcpy(attr
->value
, &fcs_hba_attr
->max_ct_pyld
, attr
->len
);
1746 attr
->len
= cpu_to_be16(attr
->len
+ sizeof(attr
->type
) +
1750 * Update size of payload
1752 len
+= ((sizeof(attr
->type
) + sizeof(attr
->len
)) * count
);
1754 rhba
->hba_attr_blk
.attr_count
= cpu_to_be32(count
);
1759 bfa_fcs_lport_fdmi_rhba_response(void *fcsarg
, struct bfa_fcxp_s
*fcxp
,
1760 void *cbarg
, bfa_status_t req_status
,
1761 u32 rsp_len
, u32 resid_len
,
1762 struct fchs_s
*rsp_fchs
)
1764 struct bfa_fcs_lport_fdmi_s
*fdmi
=
1765 (struct bfa_fcs_lport_fdmi_s
*) cbarg
;
1766 struct bfa_fcs_lport_s
*port
= fdmi
->ms
->port
;
1767 struct ct_hdr_s
*cthdr
= NULL
;
1769 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
1774 if (req_status
!= BFA_STATUS_OK
) {
1775 bfa_trc(port
->fcs
, req_status
);
1776 bfa_sm_send_event(fdmi
, FDMISM_EVENT_RSP_ERROR
);
1780 cthdr
= (struct ct_hdr_s
*) BFA_FCXP_RSP_PLD(fcxp
);
1781 cthdr
->cmd_rsp_code
= be16_to_cpu(cthdr
->cmd_rsp_code
);
1783 if (cthdr
->cmd_rsp_code
== CT_RSP_ACCEPT
) {
1784 bfa_sm_send_event(fdmi
, FDMISM_EVENT_RSP_OK
);
1788 bfa_trc(port
->fcs
, cthdr
->reason_code
);
1789 bfa_trc(port
->fcs
, cthdr
->exp_code
);
1790 bfa_sm_send_event(fdmi
, FDMISM_EVENT_RSP_ERROR
);
1794 * RPRT : Register Port
1797 bfa_fcs_lport_fdmi_send_rprt(void *fdmi_cbarg
, struct bfa_fcxp_s
*fcxp_alloced
)
1799 struct bfa_fcs_lport_fdmi_s
*fdmi
= fdmi_cbarg
;
1800 struct bfa_fcs_lport_s
*port
= fdmi
->ms
->port
;
1803 struct bfa_fcxp_s
*fcxp
;
1806 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
1808 fcxp
= fcxp_alloced
? fcxp_alloced
: bfa_fcs_fcxp_alloc(port
->fcs
);
1810 bfa_fcs_fcxp_alloc_wait(port
->fcs
->bfa
, &fdmi
->fcxp_wqe
,
1811 bfa_fcs_lport_fdmi_send_rprt
, fdmi
);
1816 pyld
= bfa_fcxp_get_reqbuf(fcxp
);
1817 memset(pyld
, 0, FC_MAX_PDUSZ
);
1819 len
= fc_fdmi_reqhdr_build(&fchs
, pyld
, bfa_fcs_lport_get_fcid(port
),
1823 bfa_fcs_lport_fdmi_build_rprt_pyld(fdmi
,
1824 (u8
*) ((struct ct_hdr_s
*) pyld
1827 bfa_fcxp_send(fcxp
, NULL
, port
->fabric
->vf_id
, port
->lp_tag
, BFA_FALSE
,
1828 FC_CLASS_3
, len
+ attr_len
, &fchs
,
1829 bfa_fcs_lport_fdmi_rprt_response
, (void *)fdmi
,
1830 FC_MAX_PDUSZ
, FC_FCCT_TOV
);
1832 bfa_sm_send_event(fdmi
, FDMISM_EVENT_RPRT_SENT
);
1836 * This routine builds Port Attribute Block that used in RPA, RPRT commands.
1839 bfa_fcs_lport_fdmi_build_portattr_block(struct bfa_fcs_lport_fdmi_s
*fdmi
,
1842 struct bfa_fcs_fdmi_port_attr_s fcs_port_attr
;
1843 struct fdmi_port_attr_s
*port_attrib
= (struct fdmi_port_attr_s
*) pyld
;
1844 struct fdmi_attr_s
*attr
;
1850 * get port attributes
1852 bfa_fcs_fdmi_get_portattr(fdmi
, &fcs_port_attr
);
1854 len
= sizeof(port_attrib
->attr_count
);
1857 * fill out the invididual entries
1859 curr_ptr
= (u8
*) &port_attrib
->port_attr
;
1864 attr
= (struct fdmi_attr_s
*) curr_ptr
;
1865 attr
->type
= cpu_to_be16(FDMI_PORT_ATTRIB_FC4_TYPES
);
1866 attr
->len
= sizeof(fcs_port_attr
.supp_fc4_types
);
1867 memcpy(attr
->value
, fcs_port_attr
.supp_fc4_types
, attr
->len
);
1868 curr_ptr
+= sizeof(attr
->type
) + sizeof(attr
->len
) + attr
->len
;
1872 cpu_to_be16(attr
->len
+ sizeof(attr
->type
) +
1878 attr
= (struct fdmi_attr_s
*) curr_ptr
;
1879 attr
->type
= cpu_to_be16(FDMI_PORT_ATTRIB_SUPP_SPEED
);
1880 attr
->len
= sizeof(fcs_port_attr
.supp_speed
);
1881 memcpy(attr
->value
, &fcs_port_attr
.supp_speed
, attr
->len
);
1882 curr_ptr
+= sizeof(attr
->type
) + sizeof(attr
->len
) + attr
->len
;
1886 cpu_to_be16(attr
->len
+ sizeof(attr
->type
) +
1890 * current Port Speed
1892 attr
= (struct fdmi_attr_s
*) curr_ptr
;
1893 attr
->type
= cpu_to_be16(FDMI_PORT_ATTRIB_PORT_SPEED
);
1894 attr
->len
= sizeof(fcs_port_attr
.curr_speed
);
1895 memcpy(attr
->value
, &fcs_port_attr
.curr_speed
, attr
->len
);
1896 curr_ptr
+= sizeof(attr
->type
) + sizeof(attr
->len
) + attr
->len
;
1899 attr
->len
= cpu_to_be16(attr
->len
+ sizeof(attr
->type
) +
1905 attr
= (struct fdmi_attr_s
*) curr_ptr
;
1906 attr
->type
= cpu_to_be16(FDMI_PORT_ATTRIB_FRAME_SIZE
);
1907 attr
->len
= sizeof(fcs_port_attr
.max_frm_size
);
1908 memcpy(attr
->value
, &fcs_port_attr
.max_frm_size
, attr
->len
);
1909 curr_ptr
+= sizeof(attr
->type
) + sizeof(attr
->len
) + attr
->len
;
1912 attr
->len
= cpu_to_be16(attr
->len
+ sizeof(attr
->type
) +
1918 if (fcs_port_attr
.os_device_name
[0] != '\0') {
1919 attr
= (struct fdmi_attr_s
*) curr_ptr
;
1920 attr
->type
= cpu_to_be16(FDMI_PORT_ATTRIB_DEV_NAME
);
1921 attr
->len
= (u16
) strlen(fcs_port_attr
.os_device_name
);
1922 memcpy(attr
->value
, fcs_port_attr
.os_device_name
, attr
->len
);
1923 attr
->len
= fc_roundup(attr
->len
, sizeof(u32
));
1924 curr_ptr
+= sizeof(attr
->type
) + sizeof(attr
->len
) + attr
->len
;
1927 attr
->len
= cpu_to_be16(attr
->len
+ sizeof(attr
->type
) +
1933 if (fcs_port_attr
.host_name
[0] != '\0') {
1934 attr
= (struct fdmi_attr_s
*) curr_ptr
;
1935 attr
->type
= cpu_to_be16(FDMI_PORT_ATTRIB_HOST_NAME
);
1936 attr
->len
= (u16
) strlen(fcs_port_attr
.host_name
);
1937 memcpy(attr
->value
, fcs_port_attr
.host_name
, attr
->len
);
1938 attr
->len
= fc_roundup(attr
->len
, sizeof(u32
));
1939 curr_ptr
+= sizeof(attr
->type
) + sizeof(attr
->len
) + attr
->len
;
1942 attr
->len
= cpu_to_be16(attr
->len
+ sizeof(attr
->type
) +
1947 * Update size of payload
1949 port_attrib
->attr_count
= cpu_to_be32(count
);
1950 len
+= ((sizeof(attr
->type
) + sizeof(attr
->len
)) * count
);
1955 bfa_fcs_lport_fdmi_build_rprt_pyld(struct bfa_fcs_lport_fdmi_s
*fdmi
, u8
*pyld
)
1957 struct bfa_fcs_lport_s
*port
= fdmi
->ms
->port
;
1958 struct fdmi_rprt_s
*rprt
= (struct fdmi_rprt_s
*) pyld
;
1961 rprt
->hba_id
= bfa_fcs_lport_get_pwwn(bfa_fcs_get_base_port(port
->fcs
));
1962 rprt
->port_name
= bfa_fcs_lport_get_pwwn(port
);
1964 len
= bfa_fcs_lport_fdmi_build_portattr_block(fdmi
,
1965 (u8
*) &rprt
->port_attr_blk
);
1967 len
+= sizeof(rprt
->hba_id
) + sizeof(rprt
->port_name
);
1973 bfa_fcs_lport_fdmi_rprt_response(void *fcsarg
, struct bfa_fcxp_s
*fcxp
,
1974 void *cbarg
, bfa_status_t req_status
,
1975 u32 rsp_len
, u32 resid_len
,
1976 struct fchs_s
*rsp_fchs
)
1978 struct bfa_fcs_lport_fdmi_s
*fdmi
=
1979 (struct bfa_fcs_lport_fdmi_s
*) cbarg
;
1980 struct bfa_fcs_lport_s
*port
= fdmi
->ms
->port
;
1981 struct ct_hdr_s
*cthdr
= NULL
;
1983 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
1988 if (req_status
!= BFA_STATUS_OK
) {
1989 bfa_trc(port
->fcs
, req_status
);
1990 bfa_sm_send_event(fdmi
, FDMISM_EVENT_RSP_ERROR
);
1994 cthdr
= (struct ct_hdr_s
*) BFA_FCXP_RSP_PLD(fcxp
);
1995 cthdr
->cmd_rsp_code
= be16_to_cpu(cthdr
->cmd_rsp_code
);
1997 if (cthdr
->cmd_rsp_code
== CT_RSP_ACCEPT
) {
1998 bfa_sm_send_event(fdmi
, FDMISM_EVENT_RSP_OK
);
2002 bfa_trc(port
->fcs
, cthdr
->reason_code
);
2003 bfa_trc(port
->fcs
, cthdr
->exp_code
);
2004 bfa_sm_send_event(fdmi
, FDMISM_EVENT_RSP_ERROR
);
2008 * RPA : Register Port Attributes.
2011 bfa_fcs_lport_fdmi_send_rpa(void *fdmi_cbarg
, struct bfa_fcxp_s
*fcxp_alloced
)
2013 struct bfa_fcs_lport_fdmi_s
*fdmi
= fdmi_cbarg
;
2014 struct bfa_fcs_lport_s
*port
= fdmi
->ms
->port
;
2017 struct bfa_fcxp_s
*fcxp
;
2020 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
2022 fcxp
= fcxp_alloced
? fcxp_alloced
: bfa_fcs_fcxp_alloc(port
->fcs
);
2024 bfa_fcs_fcxp_alloc_wait(port
->fcs
->bfa
, &fdmi
->fcxp_wqe
,
2025 bfa_fcs_lport_fdmi_send_rpa
, fdmi
);
2030 pyld
= bfa_fcxp_get_reqbuf(fcxp
);
2031 memset(pyld
, 0, FC_MAX_PDUSZ
);
2033 len
= fc_fdmi_reqhdr_build(&fchs
, pyld
, bfa_fcs_lport_get_fcid(port
),
2036 attr_len
= bfa_fcs_lport_fdmi_build_rpa_pyld(fdmi
,
2037 (u8
*) ((struct ct_hdr_s
*) pyld
+ 1));
2039 bfa_fcxp_send(fcxp
, NULL
, port
->fabric
->vf_id
, port
->lp_tag
, BFA_FALSE
,
2040 FC_CLASS_3
, len
+ attr_len
, &fchs
,
2041 bfa_fcs_lport_fdmi_rpa_response
, (void *)fdmi
,
2042 FC_MAX_PDUSZ
, FC_FCCT_TOV
);
2044 bfa_sm_send_event(fdmi
, FDMISM_EVENT_RPA_SENT
);
2048 bfa_fcs_lport_fdmi_build_rpa_pyld(struct bfa_fcs_lport_fdmi_s
*fdmi
, u8
*pyld
)
2050 struct bfa_fcs_lport_s
*port
= fdmi
->ms
->port
;
2051 struct fdmi_rpa_s
*rpa
= (struct fdmi_rpa_s
*) pyld
;
2054 rpa
->port_name
= bfa_fcs_lport_get_pwwn(port
);
2056 len
= bfa_fcs_lport_fdmi_build_portattr_block(fdmi
,
2057 (u8
*) &rpa
->port_attr_blk
);
2059 len
+= sizeof(rpa
->port_name
);
2065 bfa_fcs_lport_fdmi_rpa_response(void *fcsarg
, struct bfa_fcxp_s
*fcxp
,
2066 void *cbarg
, bfa_status_t req_status
, u32 rsp_len
,
2067 u32 resid_len
, struct fchs_s
*rsp_fchs
)
2069 struct bfa_fcs_lport_fdmi_s
*fdmi
=
2070 (struct bfa_fcs_lport_fdmi_s
*) cbarg
;
2071 struct bfa_fcs_lport_s
*port
= fdmi
->ms
->port
;
2072 struct ct_hdr_s
*cthdr
= NULL
;
2074 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
2079 if (req_status
!= BFA_STATUS_OK
) {
2080 bfa_trc(port
->fcs
, req_status
);
2081 bfa_sm_send_event(fdmi
, FDMISM_EVENT_RSP_ERROR
);
2085 cthdr
= (struct ct_hdr_s
*) BFA_FCXP_RSP_PLD(fcxp
);
2086 cthdr
->cmd_rsp_code
= be16_to_cpu(cthdr
->cmd_rsp_code
);
2088 if (cthdr
->cmd_rsp_code
== CT_RSP_ACCEPT
) {
2089 bfa_sm_send_event(fdmi
, FDMISM_EVENT_RSP_OK
);
2093 bfa_trc(port
->fcs
, cthdr
->reason_code
);
2094 bfa_trc(port
->fcs
, cthdr
->exp_code
);
2095 bfa_sm_send_event(fdmi
, FDMISM_EVENT_RSP_ERROR
);
2099 bfa_fcs_lport_fdmi_timeout(void *arg
)
2101 struct bfa_fcs_lport_fdmi_s
*fdmi
= (struct bfa_fcs_lport_fdmi_s
*) arg
;
2103 bfa_sm_send_event(fdmi
, FDMISM_EVENT_TIMEOUT
);
2107 bfa_fcs_fdmi_get_hbaattr(struct bfa_fcs_lport_fdmi_s
*fdmi
,
2108 struct bfa_fcs_fdmi_hba_attr_s
*hba_attr
)
2110 struct bfa_fcs_lport_s
*port
= fdmi
->ms
->port
;
2111 struct bfa_fcs_driver_info_s
*driver_info
= &port
->fcs
->driver_info
;
2113 memset(hba_attr
, 0, sizeof(struct bfa_fcs_fdmi_hba_attr_s
));
2115 bfa_ioc_get_adapter_manufacturer(&port
->fcs
->bfa
->ioc
,
2116 hba_attr
->manufacturer
);
2117 bfa_ioc_get_adapter_serial_num(&port
->fcs
->bfa
->ioc
,
2118 hba_attr
->serial_num
);
2119 bfa_ioc_get_adapter_model(&port
->fcs
->bfa
->ioc
,
2121 bfa_ioc_get_adapter_model(&port
->fcs
->bfa
->ioc
,
2122 hba_attr
->model_desc
);
2123 bfa_ioc_get_pci_chip_rev(&port
->fcs
->bfa
->ioc
,
2124 hba_attr
->hw_version
);
2125 bfa_ioc_get_adapter_optrom_ver(&port
->fcs
->bfa
->ioc
,
2126 hba_attr
->option_rom_ver
);
2127 bfa_ioc_get_adapter_fw_ver(&port
->fcs
->bfa
->ioc
,
2128 hba_attr
->fw_version
);
2130 strncpy(hba_attr
->driver_version
, (char *)driver_info
->version
,
2131 sizeof(hba_attr
->driver_version
));
2133 strncpy(hba_attr
->os_name
, driver_info
->host_os_name
,
2134 sizeof(hba_attr
->os_name
));
2137 * If there is a patch level, append it
2138 * to the os name along with a separator
2140 if (driver_info
->host_os_patch
[0] != '\0') {
2141 strncat(hba_attr
->os_name
, BFA_FCS_PORT_SYMBNAME_SEPARATOR
,
2142 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR
));
2143 strncat(hba_attr
->os_name
, driver_info
->host_os_patch
,
2144 sizeof(driver_info
->host_os_patch
));
2147 hba_attr
->max_ct_pyld
= cpu_to_be32(FC_MAX_PDUSZ
);
2151 bfa_fcs_fdmi_get_portattr(struct bfa_fcs_lport_fdmi_s
*fdmi
,
2152 struct bfa_fcs_fdmi_port_attr_s
*port_attr
)
2154 struct bfa_fcs_lport_s
*port
= fdmi
->ms
->port
;
2155 struct bfa_fcs_driver_info_s
*driver_info
= &port
->fcs
->driver_info
;
2156 struct bfa_port_attr_s pport_attr
;
2158 memset(port_attr
, 0, sizeof(struct bfa_fcs_fdmi_port_attr_s
));
2161 * get pport attributes from hal
2163 bfa_fcport_get_attr(port
->fcs
->bfa
, &pport_attr
);
2166 * get FC4 type Bitmask
2168 fc_get_fc4type_bitmask(FC_TYPE_FCP
, port_attr
->supp_fc4_types
);
2173 port_attr
->supp_speed
= cpu_to_be32(BFA_FCS_FDMI_SUPORTED_SPEEDS
);
2178 port_attr
->curr_speed
= cpu_to_be32(pport_attr
.speed
);
2183 port_attr
->max_frm_size
= cpu_to_be32(FC_MAX_PDUSZ
);
2188 strncpy(port_attr
->os_device_name
, (char *)driver_info
->os_device_name
,
2189 sizeof(port_attr
->os_device_name
));
2194 strncpy(port_attr
->host_name
, (char *)driver_info
->host_machine_name
,
2195 sizeof(port_attr
->host_name
));
2201 bfa_fcs_lport_fdmi_init(struct bfa_fcs_lport_ms_s
*ms
)
2203 struct bfa_fcs_lport_fdmi_s
*fdmi
= &ms
->fdmi
;
2206 if (ms
->port
->fcs
->fdmi_enabled
)
2207 bfa_sm_set_state(fdmi
, bfa_fcs_lport_fdmi_sm_offline
);
2209 bfa_sm_set_state(fdmi
, bfa_fcs_lport_fdmi_sm_disabled
);
2213 bfa_fcs_lport_fdmi_offline(struct bfa_fcs_lport_ms_s
*ms
)
2215 struct bfa_fcs_lport_fdmi_s
*fdmi
= &ms
->fdmi
;
2218 bfa_sm_send_event(fdmi
, FDMISM_EVENT_PORT_OFFLINE
);
2222 bfa_fcs_lport_fdmi_online(struct bfa_fcs_lport_ms_s
*ms
)
2224 struct bfa_fcs_lport_fdmi_s
*fdmi
= &ms
->fdmi
;
2227 bfa_sm_send_event(fdmi
, FDMISM_EVENT_PORT_ONLINE
);
2230 #define BFA_FCS_MS_CMD_MAX_RETRIES 2
2233 * forward declarations
2235 static void bfa_fcs_lport_ms_send_plogi(void *ms_cbarg
,
2236 struct bfa_fcxp_s
*fcxp_alloced
);
2237 static void bfa_fcs_lport_ms_timeout(void *arg
);
2238 static void bfa_fcs_lport_ms_plogi_response(void *fcsarg
,
2239 struct bfa_fcxp_s
*fcxp
,
2241 bfa_status_t req_status
,
2244 struct fchs_s
*rsp_fchs
);
2246 static void bfa_fcs_lport_ms_send_gmal(void *ms_cbarg
,
2247 struct bfa_fcxp_s
*fcxp_alloced
);
2248 static void bfa_fcs_lport_ms_gmal_response(void *fcsarg
,
2249 struct bfa_fcxp_s
*fcxp
,
2251 bfa_status_t req_status
,
2254 struct fchs_s
*rsp_fchs
);
2255 static void bfa_fcs_lport_ms_send_gfn(void *ms_cbarg
,
2256 struct bfa_fcxp_s
*fcxp_alloced
);
2257 static void bfa_fcs_lport_ms_gfn_response(void *fcsarg
,
2258 struct bfa_fcxp_s
*fcxp
,
2260 bfa_status_t req_status
,
2263 struct fchs_s
*rsp_fchs
);
2265 * fcs_ms_sm FCS MS state machine
2269 * MS State Machine events
2271 enum port_ms_event
{
2272 MSSM_EVENT_PORT_ONLINE
= 1,
2273 MSSM_EVENT_PORT_OFFLINE
= 2,
2274 MSSM_EVENT_RSP_OK
= 3,
2275 MSSM_EVENT_RSP_ERROR
= 4,
2276 MSSM_EVENT_TIMEOUT
= 5,
2277 MSSM_EVENT_FCXP_SENT
= 6,
2278 MSSM_EVENT_PORT_FABRIC_RSCN
= 7
2281 static void bfa_fcs_lport_ms_sm_offline(struct bfa_fcs_lport_ms_s
*ms
,
2282 enum port_ms_event event
);
2283 static void bfa_fcs_lport_ms_sm_plogi_sending(struct bfa_fcs_lport_ms_s
*ms
,
2284 enum port_ms_event event
);
2285 static void bfa_fcs_lport_ms_sm_plogi(struct bfa_fcs_lport_ms_s
*ms
,
2286 enum port_ms_event event
);
2287 static void bfa_fcs_lport_ms_sm_plogi_retry(struct bfa_fcs_lport_ms_s
*ms
,
2288 enum port_ms_event event
);
2289 static void bfa_fcs_lport_ms_sm_gmal_sending(struct bfa_fcs_lport_ms_s
*ms
,
2290 enum port_ms_event event
);
2291 static void bfa_fcs_lport_ms_sm_gmal(struct bfa_fcs_lport_ms_s
*ms
,
2292 enum port_ms_event event
);
2293 static void bfa_fcs_lport_ms_sm_gmal_retry(struct bfa_fcs_lport_ms_s
*ms
,
2294 enum port_ms_event event
);
2295 static void bfa_fcs_lport_ms_sm_gfn_sending(struct bfa_fcs_lport_ms_s
*ms
,
2296 enum port_ms_event event
);
2297 static void bfa_fcs_lport_ms_sm_gfn(struct bfa_fcs_lport_ms_s
*ms
,
2298 enum port_ms_event event
);
2299 static void bfa_fcs_lport_ms_sm_gfn_retry(struct bfa_fcs_lport_ms_s
*ms
,
2300 enum port_ms_event event
);
2301 static void bfa_fcs_lport_ms_sm_online(struct bfa_fcs_lport_ms_s
*ms
,
2302 enum port_ms_event event
);
2304 * Start in offline state - awaiting NS to send start.
2307 bfa_fcs_lport_ms_sm_offline(struct bfa_fcs_lport_ms_s
*ms
,
2308 enum port_ms_event event
)
2310 bfa_trc(ms
->port
->fcs
, ms
->port
->port_cfg
.pwwn
);
2311 bfa_trc(ms
->port
->fcs
, event
);
2314 case MSSM_EVENT_PORT_ONLINE
:
2315 bfa_sm_set_state(ms
, bfa_fcs_lport_ms_sm_plogi_sending
);
2316 bfa_fcs_lport_ms_send_plogi(ms
, NULL
);
2319 case MSSM_EVENT_PORT_OFFLINE
:
2323 bfa_sm_fault(ms
->port
->fcs
, event
);
2328 bfa_fcs_lport_ms_sm_plogi_sending(struct bfa_fcs_lport_ms_s
*ms
,
2329 enum port_ms_event event
)
2331 bfa_trc(ms
->port
->fcs
, ms
->port
->port_cfg
.pwwn
);
2332 bfa_trc(ms
->port
->fcs
, event
);
2335 case MSSM_EVENT_FCXP_SENT
:
2336 bfa_sm_set_state(ms
, bfa_fcs_lport_ms_sm_plogi
);
2339 case MSSM_EVENT_PORT_OFFLINE
:
2340 bfa_sm_set_state(ms
, bfa_fcs_lport_ms_sm_offline
);
2341 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ms
->port
),
2346 bfa_sm_fault(ms
->port
->fcs
, event
);
2351 bfa_fcs_lport_ms_sm_plogi(struct bfa_fcs_lport_ms_s
*ms
,
2352 enum port_ms_event event
)
2354 bfa_trc(ms
->port
->fcs
, ms
->port
->port_cfg
.pwwn
);
2355 bfa_trc(ms
->port
->fcs
, event
);
2358 case MSSM_EVENT_RSP_ERROR
:
2360 * Start timer for a delayed retry
2362 bfa_sm_set_state(ms
, bfa_fcs_lport_ms_sm_plogi_retry
);
2363 ms
->port
->stats
.ms_retries
++;
2364 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ms
->port
),
2365 &ms
->timer
, bfa_fcs_lport_ms_timeout
, ms
,
2366 BFA_FCS_RETRY_TIMEOUT
);
2369 case MSSM_EVENT_RSP_OK
:
2371 * since plogi is done, now invoke MS related sub-modules
2373 bfa_fcs_lport_fdmi_online(ms
);
2376 * if this is a Vport, go to online state.
2378 if (ms
->port
->vport
) {
2379 bfa_sm_set_state(ms
, bfa_fcs_lport_ms_sm_online
);
2384 * For a base port we need to get the
2385 * switch's IP address.
2387 bfa_sm_set_state(ms
, bfa_fcs_lport_ms_sm_gmal_sending
);
2388 bfa_fcs_lport_ms_send_gmal(ms
, NULL
);
2391 case MSSM_EVENT_PORT_OFFLINE
:
2392 bfa_sm_set_state(ms
, bfa_fcs_lport_ms_sm_offline
);
2393 bfa_fcxp_discard(ms
->fcxp
);
2397 bfa_sm_fault(ms
->port
->fcs
, event
);
2402 bfa_fcs_lport_ms_sm_plogi_retry(struct bfa_fcs_lport_ms_s
*ms
,
2403 enum port_ms_event event
)
2405 bfa_trc(ms
->port
->fcs
, ms
->port
->port_cfg
.pwwn
);
2406 bfa_trc(ms
->port
->fcs
, event
);
2409 case MSSM_EVENT_TIMEOUT
:
2411 * Retry Timer Expired. Re-send
2413 bfa_sm_set_state(ms
, bfa_fcs_lport_ms_sm_plogi_sending
);
2414 bfa_fcs_lport_ms_send_plogi(ms
, NULL
);
2417 case MSSM_EVENT_PORT_OFFLINE
:
2418 bfa_sm_set_state(ms
, bfa_fcs_lport_ms_sm_offline
);
2419 bfa_timer_stop(&ms
->timer
);
2423 bfa_sm_fault(ms
->port
->fcs
, event
);
2428 bfa_fcs_lport_ms_sm_online(struct bfa_fcs_lport_ms_s
*ms
,
2429 enum port_ms_event event
)
2431 bfa_trc(ms
->port
->fcs
, ms
->port
->port_cfg
.pwwn
);
2432 bfa_trc(ms
->port
->fcs
, event
);
2435 case MSSM_EVENT_PORT_OFFLINE
:
2436 bfa_sm_set_state(ms
, bfa_fcs_lport_ms_sm_offline
);
2439 case MSSM_EVENT_PORT_FABRIC_RSCN
:
2440 bfa_sm_set_state(ms
, bfa_fcs_lport_ms_sm_gfn_sending
);
2442 bfa_fcs_lport_ms_send_gfn(ms
, NULL
);
2446 bfa_sm_fault(ms
->port
->fcs
, event
);
2451 bfa_fcs_lport_ms_sm_gmal_sending(struct bfa_fcs_lport_ms_s
*ms
,
2452 enum port_ms_event event
)
2454 bfa_trc(ms
->port
->fcs
, ms
->port
->port_cfg
.pwwn
);
2455 bfa_trc(ms
->port
->fcs
, event
);
2458 case MSSM_EVENT_FCXP_SENT
:
2459 bfa_sm_set_state(ms
, bfa_fcs_lport_ms_sm_gmal
);
2462 case MSSM_EVENT_PORT_OFFLINE
:
2463 bfa_sm_set_state(ms
, bfa_fcs_lport_ms_sm_offline
);
2464 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ms
->port
),
2469 bfa_sm_fault(ms
->port
->fcs
, event
);
2474 bfa_fcs_lport_ms_sm_gmal(struct bfa_fcs_lport_ms_s
*ms
,
2475 enum port_ms_event event
)
2477 bfa_trc(ms
->port
->fcs
, ms
->port
->port_cfg
.pwwn
);
2478 bfa_trc(ms
->port
->fcs
, event
);
2481 case MSSM_EVENT_RSP_ERROR
:
2483 * Start timer for a delayed retry
2485 if (ms
->retry_cnt
++ < BFA_FCS_MS_CMD_MAX_RETRIES
) {
2486 bfa_sm_set_state(ms
, bfa_fcs_lport_ms_sm_gmal_retry
);
2487 ms
->port
->stats
.ms_retries
++;
2488 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ms
->port
),
2489 &ms
->timer
, bfa_fcs_lport_ms_timeout
, ms
,
2490 BFA_FCS_RETRY_TIMEOUT
);
2492 bfa_sm_set_state(ms
, bfa_fcs_lport_ms_sm_gfn_sending
);
2493 bfa_fcs_lport_ms_send_gfn(ms
, NULL
);
2498 case MSSM_EVENT_RSP_OK
:
2499 bfa_sm_set_state(ms
, bfa_fcs_lport_ms_sm_gfn_sending
);
2500 bfa_fcs_lport_ms_send_gfn(ms
, NULL
);
2503 case MSSM_EVENT_PORT_OFFLINE
:
2504 bfa_sm_set_state(ms
, bfa_fcs_lport_ms_sm_offline
);
2505 bfa_fcxp_discard(ms
->fcxp
);
2509 bfa_sm_fault(ms
->port
->fcs
, event
);
2514 bfa_fcs_lport_ms_sm_gmal_retry(struct bfa_fcs_lport_ms_s
*ms
,
2515 enum port_ms_event event
)
2517 bfa_trc(ms
->port
->fcs
, ms
->port
->port_cfg
.pwwn
);
2518 bfa_trc(ms
->port
->fcs
, event
);
2521 case MSSM_EVENT_TIMEOUT
:
2523 * Retry Timer Expired. Re-send
2525 bfa_sm_set_state(ms
, bfa_fcs_lport_ms_sm_gmal_sending
);
2526 bfa_fcs_lport_ms_send_gmal(ms
, NULL
);
2529 case MSSM_EVENT_PORT_OFFLINE
:
2530 bfa_sm_set_state(ms
, bfa_fcs_lport_ms_sm_offline
);
2531 bfa_timer_stop(&ms
->timer
);
2535 bfa_sm_fault(ms
->port
->fcs
, event
);
2539 * ms_pvt MS local functions
2543 bfa_fcs_lport_ms_send_gmal(void *ms_cbarg
, struct bfa_fcxp_s
*fcxp_alloced
)
2545 struct bfa_fcs_lport_ms_s
*ms
= ms_cbarg
;
2546 bfa_fcs_lport_t
*port
= ms
->port
;
2549 struct bfa_fcxp_s
*fcxp
;
2551 bfa_trc(port
->fcs
, port
->pid
);
2553 fcxp
= fcxp_alloced
? fcxp_alloced
: bfa_fcs_fcxp_alloc(port
->fcs
);
2555 bfa_fcs_fcxp_alloc_wait(port
->fcs
->bfa
, &ms
->fcxp_wqe
,
2556 bfa_fcs_lport_ms_send_gmal
, ms
);
2561 len
= fc_gmal_req_build(&fchs
, bfa_fcxp_get_reqbuf(fcxp
),
2562 bfa_fcs_lport_get_fcid(port
),
2563 bfa_lps_get_peer_nwwn(port
->fabric
->lps
));
2565 bfa_fcxp_send(fcxp
, NULL
, port
->fabric
->vf_id
, port
->lp_tag
, BFA_FALSE
,
2566 FC_CLASS_3
, len
, &fchs
,
2567 bfa_fcs_lport_ms_gmal_response
, (void *)ms
,
2568 FC_MAX_PDUSZ
, FC_FCCT_TOV
);
2570 bfa_sm_send_event(ms
, MSSM_EVENT_FCXP_SENT
);
2574 bfa_fcs_lport_ms_gmal_response(void *fcsarg
, struct bfa_fcxp_s
*fcxp
,
2575 void *cbarg
, bfa_status_t req_status
,
2576 u32 rsp_len
, u32 resid_len
,
2577 struct fchs_s
*rsp_fchs
)
2579 struct bfa_fcs_lport_ms_s
*ms
= (struct bfa_fcs_lport_ms_s
*) cbarg
;
2580 bfa_fcs_lport_t
*port
= ms
->port
;
2581 struct ct_hdr_s
*cthdr
= NULL
;
2582 struct fcgs_gmal_resp_s
*gmal_resp
;
2583 struct fcgs_gmal_entry_s
*gmal_entry
;
2587 bfa_trc(port
->fcs
, req_status
);
2588 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
2593 if (req_status
!= BFA_STATUS_OK
) {
2594 bfa_trc(port
->fcs
, req_status
);
2595 bfa_sm_send_event(ms
, MSSM_EVENT_RSP_ERROR
);
2599 cthdr
= (struct ct_hdr_s
*) BFA_FCXP_RSP_PLD(fcxp
);
2600 cthdr
->cmd_rsp_code
= be16_to_cpu(cthdr
->cmd_rsp_code
);
2602 if (cthdr
->cmd_rsp_code
== CT_RSP_ACCEPT
) {
2603 gmal_resp
= (struct fcgs_gmal_resp_s
*)(cthdr
+ 1);
2605 num_entries
= be32_to_cpu(gmal_resp
->ms_len
);
2606 if (num_entries
== 0) {
2607 bfa_sm_send_event(ms
, MSSM_EVENT_RSP_ERROR
);
2611 * The response could contain multiple Entries.
2612 * Entries for SNMP interface, etc.
2613 * We look for the entry with a telnet prefix.
2614 * First "http://" entry refers to IP addr
2617 gmal_entry
= (struct fcgs_gmal_entry_s
*)gmal_resp
->ms_ma
;
2618 while (num_entries
> 0) {
2619 if (strncmp(gmal_entry
->prefix
,
2620 CT_GMAL_RESP_PREFIX_HTTP
,
2621 sizeof(gmal_entry
->prefix
)) == 0) {
2624 * if the IP address is terminating with a '/',
2626 * Byte 0 consists of the length of the string.
2628 rsp_str
= &(gmal_entry
->prefix
[0]);
2629 if (rsp_str
[gmal_entry
->len
-1] == '/')
2630 rsp_str
[gmal_entry
->len
-1] = 0;
2632 /* copy IP Address to fabric */
2633 strncpy(bfa_fcs_lport_get_fabric_ipaddr(port
),
2634 gmal_entry
->ip_addr
,
2635 BFA_FCS_FABRIC_IPADDR_SZ
);
2643 bfa_sm_send_event(ms
, MSSM_EVENT_RSP_OK
);
2647 bfa_trc(port
->fcs
, cthdr
->reason_code
);
2648 bfa_trc(port
->fcs
, cthdr
->exp_code
);
2649 bfa_sm_send_event(ms
, MSSM_EVENT_RSP_ERROR
);
2653 bfa_fcs_lport_ms_sm_gfn_sending(struct bfa_fcs_lport_ms_s
*ms
,
2654 enum port_ms_event event
)
2656 bfa_trc(ms
->port
->fcs
, ms
->port
->port_cfg
.pwwn
);
2657 bfa_trc(ms
->port
->fcs
, event
);
2660 case MSSM_EVENT_FCXP_SENT
:
2661 bfa_sm_set_state(ms
, bfa_fcs_lport_ms_sm_gfn
);
2664 case MSSM_EVENT_PORT_OFFLINE
:
2665 bfa_sm_set_state(ms
, bfa_fcs_lport_ms_sm_offline
);
2666 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ms
->port
),
2671 bfa_sm_fault(ms
->port
->fcs
, event
);
2676 bfa_fcs_lport_ms_sm_gfn(struct bfa_fcs_lport_ms_s
*ms
,
2677 enum port_ms_event event
)
2679 bfa_trc(ms
->port
->fcs
, ms
->port
->port_cfg
.pwwn
);
2680 bfa_trc(ms
->port
->fcs
, event
);
2683 case MSSM_EVENT_RSP_ERROR
:
2685 * Start timer for a delayed retry
2687 if (ms
->retry_cnt
++ < BFA_FCS_MS_CMD_MAX_RETRIES
) {
2688 bfa_sm_set_state(ms
, bfa_fcs_lport_ms_sm_gfn_retry
);
2689 ms
->port
->stats
.ms_retries
++;
2690 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ms
->port
),
2691 &ms
->timer
, bfa_fcs_lport_ms_timeout
, ms
,
2692 BFA_FCS_RETRY_TIMEOUT
);
2694 bfa_sm_set_state(ms
, bfa_fcs_lport_ms_sm_online
);
2699 case MSSM_EVENT_RSP_OK
:
2700 bfa_sm_set_state(ms
, bfa_fcs_lport_ms_sm_online
);
2703 case MSSM_EVENT_PORT_OFFLINE
:
2704 bfa_sm_set_state(ms
, bfa_fcs_lport_ms_sm_offline
);
2705 bfa_fcxp_discard(ms
->fcxp
);
2709 bfa_sm_fault(ms
->port
->fcs
, event
);
2714 bfa_fcs_lport_ms_sm_gfn_retry(struct bfa_fcs_lport_ms_s
*ms
,
2715 enum port_ms_event event
)
2717 bfa_trc(ms
->port
->fcs
, ms
->port
->port_cfg
.pwwn
);
2718 bfa_trc(ms
->port
->fcs
, event
);
2721 case MSSM_EVENT_TIMEOUT
:
2723 * Retry Timer Expired. Re-send
2725 bfa_sm_set_state(ms
, bfa_fcs_lport_ms_sm_gfn_sending
);
2726 bfa_fcs_lport_ms_send_gfn(ms
, NULL
);
2729 case MSSM_EVENT_PORT_OFFLINE
:
2730 bfa_sm_set_state(ms
, bfa_fcs_lport_ms_sm_offline
);
2731 bfa_timer_stop(&ms
->timer
);
2735 bfa_sm_fault(ms
->port
->fcs
, event
);
2739 * ms_pvt MS local functions
2743 bfa_fcs_lport_ms_send_gfn(void *ms_cbarg
, struct bfa_fcxp_s
*fcxp_alloced
)
2745 struct bfa_fcs_lport_ms_s
*ms
= ms_cbarg
;
2746 bfa_fcs_lport_t
*port
= ms
->port
;
2749 struct bfa_fcxp_s
*fcxp
;
2751 bfa_trc(port
->fcs
, port
->pid
);
2753 fcxp
= fcxp_alloced
? fcxp_alloced
: bfa_fcs_fcxp_alloc(port
->fcs
);
2755 bfa_fcs_fcxp_alloc_wait(port
->fcs
->bfa
, &ms
->fcxp_wqe
,
2756 bfa_fcs_lport_ms_send_gfn
, ms
);
2761 len
= fc_gfn_req_build(&fchs
, bfa_fcxp_get_reqbuf(fcxp
),
2762 bfa_fcs_lport_get_fcid(port
),
2763 bfa_lps_get_peer_nwwn(port
->fabric
->lps
));
2765 bfa_fcxp_send(fcxp
, NULL
, port
->fabric
->vf_id
, port
->lp_tag
, BFA_FALSE
,
2766 FC_CLASS_3
, len
, &fchs
,
2767 bfa_fcs_lport_ms_gfn_response
, (void *)ms
,
2768 FC_MAX_PDUSZ
, FC_FCCT_TOV
);
2770 bfa_sm_send_event(ms
, MSSM_EVENT_FCXP_SENT
);
2774 bfa_fcs_lport_ms_gfn_response(void *fcsarg
, struct bfa_fcxp_s
*fcxp
,
2775 void *cbarg
, bfa_status_t req_status
, u32 rsp_len
,
2776 u32 resid_len
, struct fchs_s
*rsp_fchs
)
2778 struct bfa_fcs_lport_ms_s
*ms
= (struct bfa_fcs_lport_ms_s
*) cbarg
;
2779 bfa_fcs_lport_t
*port
= ms
->port
;
2780 struct ct_hdr_s
*cthdr
= NULL
;
2783 bfa_trc(port
->fcs
, req_status
);
2784 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
2789 if (req_status
!= BFA_STATUS_OK
) {
2790 bfa_trc(port
->fcs
, req_status
);
2791 bfa_sm_send_event(ms
, MSSM_EVENT_RSP_ERROR
);
2795 cthdr
= (struct ct_hdr_s
*) BFA_FCXP_RSP_PLD(fcxp
);
2796 cthdr
->cmd_rsp_code
= be16_to_cpu(cthdr
->cmd_rsp_code
);
2798 if (cthdr
->cmd_rsp_code
== CT_RSP_ACCEPT
) {
2799 gfn_resp
= (wwn_t
*)(cthdr
+ 1);
2800 /* check if it has actually changed */
2801 if ((memcmp((void *)&bfa_fcs_lport_get_fabric_name(port
),
2802 gfn_resp
, sizeof(wwn_t
)) != 0)) {
2803 bfa_fcs_fabric_set_fabric_name(port
->fabric
, *gfn_resp
);
2805 bfa_sm_send_event(ms
, MSSM_EVENT_RSP_OK
);
2809 bfa_trc(port
->fcs
, cthdr
->reason_code
);
2810 bfa_trc(port
->fcs
, cthdr
->exp_code
);
2811 bfa_sm_send_event(ms
, MSSM_EVENT_RSP_ERROR
);
2815 * ms_pvt MS local functions
2819 bfa_fcs_lport_ms_send_plogi(void *ms_cbarg
, struct bfa_fcxp_s
*fcxp_alloced
)
2821 struct bfa_fcs_lport_ms_s
*ms
= ms_cbarg
;
2822 struct bfa_fcs_lport_s
*port
= ms
->port
;
2825 struct bfa_fcxp_s
*fcxp
;
2827 bfa_trc(port
->fcs
, port
->pid
);
2829 fcxp
= fcxp_alloced
? fcxp_alloced
: bfa_fcs_fcxp_alloc(port
->fcs
);
2831 port
->stats
.ms_plogi_alloc_wait
++;
2832 bfa_fcs_fcxp_alloc_wait(port
->fcs
->bfa
, &ms
->fcxp_wqe
,
2833 bfa_fcs_lport_ms_send_plogi
, ms
);
2838 len
= fc_plogi_build(&fchs
, bfa_fcxp_get_reqbuf(fcxp
),
2839 bfa_os_hton3b(FC_MGMT_SERVER
),
2840 bfa_fcs_lport_get_fcid(port
), 0,
2841 port
->port_cfg
.pwwn
, port
->port_cfg
.nwwn
,
2842 bfa_fcport_get_maxfrsize(port
->fcs
->bfa
));
2844 bfa_fcxp_send(fcxp
, NULL
, port
->fabric
->vf_id
, port
->lp_tag
, BFA_FALSE
,
2845 FC_CLASS_3
, len
, &fchs
,
2846 bfa_fcs_lport_ms_plogi_response
, (void *)ms
,
2847 FC_MAX_PDUSZ
, FC_ELS_TOV
);
2849 port
->stats
.ms_plogi_sent
++;
2850 bfa_sm_send_event(ms
, MSSM_EVENT_FCXP_SENT
);
2854 bfa_fcs_lport_ms_plogi_response(void *fcsarg
, struct bfa_fcxp_s
*fcxp
,
2855 void *cbarg
, bfa_status_t req_status
,
2856 u32 rsp_len
, u32 resid_len
, struct fchs_s
*rsp_fchs
)
2858 struct bfa_fcs_lport_ms_s
*ms
= (struct bfa_fcs_lport_ms_s
*) cbarg
;
2859 struct bfa_fcs_lport_s
*port
= ms
->port
;
2860 struct fc_els_cmd_s
*els_cmd
;
2861 struct fc_ls_rjt_s
*ls_rjt
;
2863 bfa_trc(port
->fcs
, req_status
);
2864 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
2869 if (req_status
!= BFA_STATUS_OK
) {
2870 port
->stats
.ms_plogi_rsp_err
++;
2871 bfa_trc(port
->fcs
, req_status
);
2872 bfa_sm_send_event(ms
, MSSM_EVENT_RSP_ERROR
);
2876 els_cmd
= (struct fc_els_cmd_s
*) BFA_FCXP_RSP_PLD(fcxp
);
2878 switch (els_cmd
->els_code
) {
2881 if (rsp_len
< sizeof(struct fc_logi_s
)) {
2882 bfa_trc(port
->fcs
, rsp_len
);
2883 port
->stats
.ms_plogi_acc_err
++;
2884 bfa_sm_send_event(ms
, MSSM_EVENT_RSP_ERROR
);
2887 port
->stats
.ms_plogi_accepts
++;
2888 bfa_sm_send_event(ms
, MSSM_EVENT_RSP_OK
);
2892 ls_rjt
= (struct fc_ls_rjt_s
*) BFA_FCXP_RSP_PLD(fcxp
);
2894 bfa_trc(port
->fcs
, ls_rjt
->reason_code
);
2895 bfa_trc(port
->fcs
, ls_rjt
->reason_code_expl
);
2897 port
->stats
.ms_rejects
++;
2898 bfa_sm_send_event(ms
, MSSM_EVENT_RSP_ERROR
);
2902 port
->stats
.ms_plogi_unknown_rsp
++;
2903 bfa_trc(port
->fcs
, els_cmd
->els_code
);
2904 bfa_sm_send_event(ms
, MSSM_EVENT_RSP_ERROR
);
2909 bfa_fcs_lport_ms_timeout(void *arg
)
2911 struct bfa_fcs_lport_ms_s
*ms
= (struct bfa_fcs_lport_ms_s
*) arg
;
2913 ms
->port
->stats
.ms_timeouts
++;
2914 bfa_sm_send_event(ms
, MSSM_EVENT_TIMEOUT
);
2919 bfa_fcs_lport_ms_init(struct bfa_fcs_lport_s
*port
)
2921 struct bfa_fcs_lport_ms_s
*ms
= BFA_FCS_GET_MS_FROM_PORT(port
);
2924 bfa_sm_set_state(ms
, bfa_fcs_lport_ms_sm_offline
);
2927 * Invoke init routines of sub modules.
2929 bfa_fcs_lport_fdmi_init(ms
);
2933 bfa_fcs_lport_ms_offline(struct bfa_fcs_lport_s
*port
)
2935 struct bfa_fcs_lport_ms_s
*ms
= BFA_FCS_GET_MS_FROM_PORT(port
);
2938 bfa_sm_send_event(ms
, MSSM_EVENT_PORT_OFFLINE
);
2939 bfa_fcs_lport_fdmi_offline(ms
);
2943 bfa_fcs_lport_ms_online(struct bfa_fcs_lport_s
*port
)
2945 struct bfa_fcs_lport_ms_s
*ms
= BFA_FCS_GET_MS_FROM_PORT(port
);
2948 bfa_sm_send_event(ms
, MSSM_EVENT_PORT_ONLINE
);
2951 bfa_fcs_lport_ms_fabric_rscn(struct bfa_fcs_lport_s
*port
)
2953 struct bfa_fcs_lport_ms_s
*ms
= BFA_FCS_GET_MS_FROM_PORT(port
);
2955 /* todo. Handle this only when in Online state */
2956 if (bfa_sm_cmp_state(ms
, bfa_fcs_lport_ms_sm_online
))
2957 bfa_sm_send_event(ms
, MSSM_EVENT_PORT_FABRIC_RSCN
);
2961 * @page ns_sm_info VPORT NS State Machine
2963 * @section ns_sm_interactions VPORT NS State Machine Interactions
2965 * @section ns_sm VPORT NS State Machine
2970 * forward declarations
2972 static void bfa_fcs_lport_ns_send_plogi(void *ns_cbarg
,
2973 struct bfa_fcxp_s
*fcxp_alloced
);
2974 static void bfa_fcs_lport_ns_send_rspn_id(void *ns_cbarg
,
2975 struct bfa_fcxp_s
*fcxp_alloced
);
2976 static void bfa_fcs_lport_ns_send_rft_id(void *ns_cbarg
,
2977 struct bfa_fcxp_s
*fcxp_alloced
);
2978 static void bfa_fcs_lport_ns_send_rff_id(void *ns_cbarg
,
2979 struct bfa_fcxp_s
*fcxp_alloced
);
2980 static void bfa_fcs_lport_ns_send_gid_ft(void *ns_cbarg
,
2981 struct bfa_fcxp_s
*fcxp_alloced
);
2982 static void bfa_fcs_lport_ns_timeout(void *arg
);
2983 static void bfa_fcs_lport_ns_plogi_response(void *fcsarg
,
2984 struct bfa_fcxp_s
*fcxp
,
2986 bfa_status_t req_status
,
2989 struct fchs_s
*rsp_fchs
);
2990 static void bfa_fcs_lport_ns_rspn_id_response(void *fcsarg
,
2991 struct bfa_fcxp_s
*fcxp
,
2993 bfa_status_t req_status
,
2996 struct fchs_s
*rsp_fchs
);
2997 static void bfa_fcs_lport_ns_rft_id_response(void *fcsarg
,
2998 struct bfa_fcxp_s
*fcxp
,
3000 bfa_status_t req_status
,
3003 struct fchs_s
*rsp_fchs
);
3004 static void bfa_fcs_lport_ns_rff_id_response(void *fcsarg
,
3005 struct bfa_fcxp_s
*fcxp
,
3007 bfa_status_t req_status
,
3010 struct fchs_s
*rsp_fchs
);
3011 static void bfa_fcs_lport_ns_gid_ft_response(void *fcsarg
,
3012 struct bfa_fcxp_s
*fcxp
,
3014 bfa_status_t req_status
,
3017 struct fchs_s
*rsp_fchs
);
3018 static void bfa_fcs_lport_ns_process_gidft_pids(
3019 struct bfa_fcs_lport_s
*port
,
3020 u32
*pid_buf
, u32 n_pids
);
3022 static void bfa_fcs_lport_ns_boot_target_disc(bfa_fcs_lport_t
*port
);
3024 * fcs_ns_sm FCS nameserver interface state machine
3028 * VPort NS State Machine events
3030 enum vport_ns_event
{
3031 NSSM_EVENT_PORT_ONLINE
= 1,
3032 NSSM_EVENT_PORT_OFFLINE
= 2,
3033 NSSM_EVENT_PLOGI_SENT
= 3,
3034 NSSM_EVENT_RSP_OK
= 4,
3035 NSSM_EVENT_RSP_ERROR
= 5,
3036 NSSM_EVENT_TIMEOUT
= 6,
3037 NSSM_EVENT_NS_QUERY
= 7,
3038 NSSM_EVENT_RSPNID_SENT
= 8,
3039 NSSM_EVENT_RFTID_SENT
= 9,
3040 NSSM_EVENT_RFFID_SENT
= 10,
3041 NSSM_EVENT_GIDFT_SENT
= 11,
3044 static void bfa_fcs_lport_ns_sm_offline(struct bfa_fcs_lport_ns_s
*ns
,
3045 enum vport_ns_event event
);
3046 static void bfa_fcs_lport_ns_sm_plogi_sending(struct bfa_fcs_lport_ns_s
*ns
,
3047 enum vport_ns_event event
);
3048 static void bfa_fcs_lport_ns_sm_plogi(struct bfa_fcs_lport_ns_s
*ns
,
3049 enum vport_ns_event event
);
3050 static void bfa_fcs_lport_ns_sm_plogi_retry(struct bfa_fcs_lport_ns_s
*ns
,
3051 enum vport_ns_event event
);
3052 static void bfa_fcs_lport_ns_sm_sending_rspn_id(
3053 struct bfa_fcs_lport_ns_s
*ns
,
3054 enum vport_ns_event event
);
3055 static void bfa_fcs_lport_ns_sm_rspn_id(struct bfa_fcs_lport_ns_s
*ns
,
3056 enum vport_ns_event event
);
3057 static void bfa_fcs_lport_ns_sm_rspn_id_retry(struct bfa_fcs_lport_ns_s
*ns
,
3058 enum vport_ns_event event
);
3059 static void bfa_fcs_lport_ns_sm_sending_rft_id(
3060 struct bfa_fcs_lport_ns_s
*ns
,
3061 enum vport_ns_event event
);
3062 static void bfa_fcs_lport_ns_sm_rft_id_retry(struct bfa_fcs_lport_ns_s
*ns
,
3063 enum vport_ns_event event
);
3064 static void bfa_fcs_lport_ns_sm_rft_id(struct bfa_fcs_lport_ns_s
*ns
,
3065 enum vport_ns_event event
);
3066 static void bfa_fcs_lport_ns_sm_sending_rff_id(
3067 struct bfa_fcs_lport_ns_s
*ns
,
3068 enum vport_ns_event event
);
3069 static void bfa_fcs_lport_ns_sm_rff_id_retry(struct bfa_fcs_lport_ns_s
*ns
,
3070 enum vport_ns_event event
);
3071 static void bfa_fcs_lport_ns_sm_rff_id(struct bfa_fcs_lport_ns_s
*ns
,
3072 enum vport_ns_event event
);
3073 static void bfa_fcs_lport_ns_sm_sending_gid_ft(
3074 struct bfa_fcs_lport_ns_s
*ns
,
3075 enum vport_ns_event event
);
3076 static void bfa_fcs_lport_ns_sm_gid_ft(struct bfa_fcs_lport_ns_s
*ns
,
3077 enum vport_ns_event event
);
3078 static void bfa_fcs_lport_ns_sm_gid_ft_retry(struct bfa_fcs_lport_ns_s
*ns
,
3079 enum vport_ns_event event
);
3080 static void bfa_fcs_lport_ns_sm_online(struct bfa_fcs_lport_ns_s
*ns
,
3081 enum vport_ns_event event
);
3083 * Start in offline state - awaiting linkup
3086 bfa_fcs_lport_ns_sm_offline(struct bfa_fcs_lport_ns_s
*ns
,
3087 enum vport_ns_event event
)
3089 bfa_trc(ns
->port
->fcs
, ns
->port
->port_cfg
.pwwn
);
3090 bfa_trc(ns
->port
->fcs
, event
);
3093 case NSSM_EVENT_PORT_ONLINE
:
3094 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_plogi_sending
);
3095 bfa_fcs_lport_ns_send_plogi(ns
, NULL
);
3098 case NSSM_EVENT_PORT_OFFLINE
:
3102 bfa_sm_fault(ns
->port
->fcs
, event
);
3107 bfa_fcs_lport_ns_sm_plogi_sending(struct bfa_fcs_lport_ns_s
*ns
,
3108 enum vport_ns_event event
)
3110 bfa_trc(ns
->port
->fcs
, ns
->port
->port_cfg
.pwwn
);
3111 bfa_trc(ns
->port
->fcs
, event
);
3114 case NSSM_EVENT_PLOGI_SENT
:
3115 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_plogi
);
3118 case NSSM_EVENT_PORT_OFFLINE
:
3119 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_offline
);
3120 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns
->port
),
3125 bfa_sm_fault(ns
->port
->fcs
, event
);
3130 bfa_fcs_lport_ns_sm_plogi(struct bfa_fcs_lport_ns_s
*ns
,
3131 enum vport_ns_event event
)
3133 bfa_trc(ns
->port
->fcs
, ns
->port
->port_cfg
.pwwn
);
3134 bfa_trc(ns
->port
->fcs
, event
);
3137 case NSSM_EVENT_RSP_ERROR
:
3139 * Start timer for a delayed retry
3141 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_plogi_retry
);
3142 ns
->port
->stats
.ns_retries
++;
3143 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns
->port
),
3144 &ns
->timer
, bfa_fcs_lport_ns_timeout
, ns
,
3145 BFA_FCS_RETRY_TIMEOUT
);
3148 case NSSM_EVENT_RSP_OK
:
3149 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_sending_rspn_id
);
3150 bfa_fcs_lport_ns_send_rspn_id(ns
, NULL
);
3153 case NSSM_EVENT_PORT_OFFLINE
:
3154 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_offline
);
3155 bfa_fcxp_discard(ns
->fcxp
);
3159 bfa_sm_fault(ns
->port
->fcs
, event
);
3164 bfa_fcs_lport_ns_sm_plogi_retry(struct bfa_fcs_lport_ns_s
*ns
,
3165 enum vport_ns_event event
)
3167 bfa_trc(ns
->port
->fcs
, ns
->port
->port_cfg
.pwwn
);
3168 bfa_trc(ns
->port
->fcs
, event
);
3171 case NSSM_EVENT_TIMEOUT
:
3173 * Retry Timer Expired. Re-send
3175 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_plogi_sending
);
3176 bfa_fcs_lport_ns_send_plogi(ns
, NULL
);
3179 case NSSM_EVENT_PORT_OFFLINE
:
3180 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_offline
);
3181 bfa_timer_stop(&ns
->timer
);
3185 bfa_sm_fault(ns
->port
->fcs
, event
);
3190 bfa_fcs_lport_ns_sm_sending_rspn_id(struct bfa_fcs_lport_ns_s
*ns
,
3191 enum vport_ns_event event
)
3193 bfa_trc(ns
->port
->fcs
, ns
->port
->port_cfg
.pwwn
);
3194 bfa_trc(ns
->port
->fcs
, event
);
3197 case NSSM_EVENT_RSPNID_SENT
:
3198 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_rspn_id
);
3201 case NSSM_EVENT_PORT_OFFLINE
:
3202 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_offline
);
3203 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns
->port
),
3208 bfa_sm_fault(ns
->port
->fcs
, event
);
3213 bfa_fcs_lport_ns_sm_rspn_id(struct bfa_fcs_lport_ns_s
*ns
,
3214 enum vport_ns_event event
)
3216 bfa_trc(ns
->port
->fcs
, ns
->port
->port_cfg
.pwwn
);
3217 bfa_trc(ns
->port
->fcs
, event
);
3220 case NSSM_EVENT_RSP_ERROR
:
3222 * Start timer for a delayed retry
3224 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_rspn_id_retry
);
3225 ns
->port
->stats
.ns_retries
++;
3226 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns
->port
),
3227 &ns
->timer
, bfa_fcs_lport_ns_timeout
, ns
,
3228 BFA_FCS_RETRY_TIMEOUT
);
3231 case NSSM_EVENT_RSP_OK
:
3232 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_sending_rft_id
);
3233 bfa_fcs_lport_ns_send_rft_id(ns
, NULL
);
3236 case NSSM_EVENT_PORT_OFFLINE
:
3237 bfa_fcxp_discard(ns
->fcxp
);
3238 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_offline
);
3242 bfa_sm_fault(ns
->port
->fcs
, event
);
3247 bfa_fcs_lport_ns_sm_rspn_id_retry(struct bfa_fcs_lport_ns_s
*ns
,
3248 enum vport_ns_event event
)
3250 bfa_trc(ns
->port
->fcs
, ns
->port
->port_cfg
.pwwn
);
3251 bfa_trc(ns
->port
->fcs
, event
);
3254 case NSSM_EVENT_TIMEOUT
:
3256 * Retry Timer Expired. Re-send
3258 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_sending_rspn_id
);
3259 bfa_fcs_lport_ns_send_rspn_id(ns
, NULL
);
3262 case NSSM_EVENT_PORT_OFFLINE
:
3263 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_offline
);
3264 bfa_timer_stop(&ns
->timer
);
3268 bfa_sm_fault(ns
->port
->fcs
, event
);
3273 bfa_fcs_lport_ns_sm_sending_rft_id(struct bfa_fcs_lport_ns_s
*ns
,
3274 enum vport_ns_event event
)
3276 bfa_trc(ns
->port
->fcs
, ns
->port
->port_cfg
.pwwn
);
3277 bfa_trc(ns
->port
->fcs
, event
);
3280 case NSSM_EVENT_RFTID_SENT
:
3281 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_rft_id
);
3284 case NSSM_EVENT_PORT_OFFLINE
:
3285 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_offline
);
3286 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns
->port
),
3291 bfa_sm_fault(ns
->port
->fcs
, event
);
3296 bfa_fcs_lport_ns_sm_rft_id(struct bfa_fcs_lport_ns_s
*ns
,
3297 enum vport_ns_event event
)
3299 bfa_trc(ns
->port
->fcs
, ns
->port
->port_cfg
.pwwn
);
3300 bfa_trc(ns
->port
->fcs
, event
);
3303 case NSSM_EVENT_RSP_OK
:
3304 /* Now move to register FC4 Features */
3305 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_sending_rff_id
);
3306 bfa_fcs_lport_ns_send_rff_id(ns
, NULL
);
3309 case NSSM_EVENT_RSP_ERROR
:
3311 * Start timer for a delayed retry
3313 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_rft_id_retry
);
3314 ns
->port
->stats
.ns_retries
++;
3315 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns
->port
),
3316 &ns
->timer
, bfa_fcs_lport_ns_timeout
, ns
,
3317 BFA_FCS_RETRY_TIMEOUT
);
3320 case NSSM_EVENT_PORT_OFFLINE
:
3321 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_offline
);
3322 bfa_fcxp_discard(ns
->fcxp
);
3326 bfa_sm_fault(ns
->port
->fcs
, event
);
3331 bfa_fcs_lport_ns_sm_rft_id_retry(struct bfa_fcs_lport_ns_s
*ns
,
3332 enum vport_ns_event event
)
3334 bfa_trc(ns
->port
->fcs
, ns
->port
->port_cfg
.pwwn
);
3335 bfa_trc(ns
->port
->fcs
, event
);
3338 case NSSM_EVENT_TIMEOUT
:
3339 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_sending_rft_id
);
3340 bfa_fcs_lport_ns_send_rft_id(ns
, NULL
);
3343 case NSSM_EVENT_PORT_OFFLINE
:
3344 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_offline
);
3345 bfa_timer_stop(&ns
->timer
);
3349 bfa_sm_fault(ns
->port
->fcs
, event
);
3354 bfa_fcs_lport_ns_sm_sending_rff_id(struct bfa_fcs_lport_ns_s
*ns
,
3355 enum vport_ns_event event
)
3357 bfa_trc(ns
->port
->fcs
, ns
->port
->port_cfg
.pwwn
);
3358 bfa_trc(ns
->port
->fcs
, event
);
3361 case NSSM_EVENT_RFFID_SENT
:
3362 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_rff_id
);
3365 case NSSM_EVENT_PORT_OFFLINE
:
3366 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_offline
);
3367 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns
->port
),
3372 bfa_sm_fault(ns
->port
->fcs
, event
);
3377 bfa_fcs_lport_ns_sm_rff_id(struct bfa_fcs_lport_ns_s
*ns
,
3378 enum vport_ns_event event
)
3380 bfa_trc(ns
->port
->fcs
, ns
->port
->port_cfg
.pwwn
);
3381 bfa_trc(ns
->port
->fcs
, event
);
3384 case NSSM_EVENT_RSP_OK
:
3387 * If min cfg mode is enabled, we donot initiate rport
3388 * discovery with the fabric. Instead, we will retrieve the
3389 * boot targets from HAL/FW.
3391 if (__fcs_min_cfg(ns
->port
->fcs
)) {
3392 bfa_fcs_lport_ns_boot_target_disc(ns
->port
);
3393 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_online
);
3398 * If the port role is Initiator Mode issue NS query.
3399 * If it is Target Mode, skip this and go to online.
3401 if (BFA_FCS_VPORT_IS_INITIATOR_MODE(ns
->port
)) {
3402 bfa_sm_set_state(ns
,
3403 bfa_fcs_lport_ns_sm_sending_gid_ft
);
3404 bfa_fcs_lport_ns_send_gid_ft(ns
, NULL
);
3407 * kick off mgmt srvr state machine
3409 bfa_fcs_lport_ms_online(ns
->port
);
3412 case NSSM_EVENT_RSP_ERROR
:
3414 * Start timer for a delayed retry
3416 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_rff_id_retry
);
3417 ns
->port
->stats
.ns_retries
++;
3418 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns
->port
),
3419 &ns
->timer
, bfa_fcs_lport_ns_timeout
, ns
,
3420 BFA_FCS_RETRY_TIMEOUT
);
3423 case NSSM_EVENT_PORT_OFFLINE
:
3424 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_offline
);
3425 bfa_fcxp_discard(ns
->fcxp
);
3429 bfa_sm_fault(ns
->port
->fcs
, event
);
3434 bfa_fcs_lport_ns_sm_rff_id_retry(struct bfa_fcs_lport_ns_s
*ns
,
3435 enum vport_ns_event event
)
3437 bfa_trc(ns
->port
->fcs
, ns
->port
->port_cfg
.pwwn
);
3438 bfa_trc(ns
->port
->fcs
, event
);
3441 case NSSM_EVENT_TIMEOUT
:
3442 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_sending_rff_id
);
3443 bfa_fcs_lport_ns_send_rff_id(ns
, NULL
);
3446 case NSSM_EVENT_PORT_OFFLINE
:
3447 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_offline
);
3448 bfa_timer_stop(&ns
->timer
);
3452 bfa_sm_fault(ns
->port
->fcs
, event
);
3456 bfa_fcs_lport_ns_sm_sending_gid_ft(struct bfa_fcs_lport_ns_s
*ns
,
3457 enum vport_ns_event event
)
3459 bfa_trc(ns
->port
->fcs
, ns
->port
->port_cfg
.pwwn
);
3460 bfa_trc(ns
->port
->fcs
, event
);
3463 case NSSM_EVENT_GIDFT_SENT
:
3464 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_gid_ft
);
3467 case NSSM_EVENT_PORT_OFFLINE
:
3468 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_offline
);
3469 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns
->port
),
3474 bfa_sm_fault(ns
->port
->fcs
, event
);
3479 bfa_fcs_lport_ns_sm_gid_ft(struct bfa_fcs_lport_ns_s
*ns
,
3480 enum vport_ns_event event
)
3482 bfa_trc(ns
->port
->fcs
, ns
->port
->port_cfg
.pwwn
);
3483 bfa_trc(ns
->port
->fcs
, event
);
3486 case NSSM_EVENT_RSP_OK
:
3487 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_online
);
3490 case NSSM_EVENT_RSP_ERROR
:
3492 * TBD: for certain reject codes, we don't need to retry
3495 * Start timer for a delayed retry
3497 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_gid_ft_retry
);
3498 ns
->port
->stats
.ns_retries
++;
3499 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns
->port
),
3500 &ns
->timer
, bfa_fcs_lport_ns_timeout
, ns
,
3501 BFA_FCS_RETRY_TIMEOUT
);
3504 case NSSM_EVENT_PORT_OFFLINE
:
3505 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_offline
);
3506 bfa_fcxp_discard(ns
->fcxp
);
3509 case NSSM_EVENT_NS_QUERY
:
3513 bfa_sm_fault(ns
->port
->fcs
, event
);
3518 bfa_fcs_lport_ns_sm_gid_ft_retry(struct bfa_fcs_lport_ns_s
*ns
,
3519 enum vport_ns_event event
)
3521 bfa_trc(ns
->port
->fcs
, ns
->port
->port_cfg
.pwwn
);
3522 bfa_trc(ns
->port
->fcs
, event
);
3525 case NSSM_EVENT_TIMEOUT
:
3526 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_sending_gid_ft
);
3527 bfa_fcs_lport_ns_send_gid_ft(ns
, NULL
);
3530 case NSSM_EVENT_PORT_OFFLINE
:
3531 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_offline
);
3532 bfa_timer_stop(&ns
->timer
);
3536 bfa_sm_fault(ns
->port
->fcs
, event
);
3541 bfa_fcs_lport_ns_sm_online(struct bfa_fcs_lport_ns_s
*ns
,
3542 enum vport_ns_event event
)
3544 bfa_trc(ns
->port
->fcs
, ns
->port
->port_cfg
.pwwn
);
3545 bfa_trc(ns
->port
->fcs
, event
);
3548 case NSSM_EVENT_PORT_OFFLINE
:
3549 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_offline
);
3552 case NSSM_EVENT_NS_QUERY
:
3554 * If the port role is Initiator Mode issue NS query.
3555 * If it is Target Mode, skip this and go to online.
3557 if (BFA_FCS_VPORT_IS_INITIATOR_MODE(ns
->port
)) {
3558 bfa_sm_set_state(ns
,
3559 bfa_fcs_lport_ns_sm_sending_gid_ft
);
3560 bfa_fcs_lport_ns_send_gid_ft(ns
, NULL
);
3565 bfa_sm_fault(ns
->port
->fcs
, event
);
3572 * ns_pvt Nameserver local functions
3576 bfa_fcs_lport_ns_send_plogi(void *ns_cbarg
, struct bfa_fcxp_s
*fcxp_alloced
)
3578 struct bfa_fcs_lport_ns_s
*ns
= ns_cbarg
;
3579 struct bfa_fcs_lport_s
*port
= ns
->port
;
3582 struct bfa_fcxp_s
*fcxp
;
3584 bfa_trc(port
->fcs
, port
->pid
);
3586 fcxp
= fcxp_alloced
? fcxp_alloced
: bfa_fcs_fcxp_alloc(port
->fcs
);
3588 port
->stats
.ns_plogi_alloc_wait
++;
3589 bfa_fcs_fcxp_alloc_wait(port
->fcs
->bfa
, &ns
->fcxp_wqe
,
3590 bfa_fcs_lport_ns_send_plogi
, ns
);
3595 len
= fc_plogi_build(&fchs
, bfa_fcxp_get_reqbuf(fcxp
),
3596 bfa_os_hton3b(FC_NAME_SERVER
),
3597 bfa_fcs_lport_get_fcid(port
), 0,
3598 port
->port_cfg
.pwwn
, port
->port_cfg
.nwwn
,
3599 bfa_fcport_get_maxfrsize(port
->fcs
->bfa
));
3601 bfa_fcxp_send(fcxp
, NULL
, port
->fabric
->vf_id
, port
->lp_tag
, BFA_FALSE
,
3602 FC_CLASS_3
, len
, &fchs
,
3603 bfa_fcs_lport_ns_plogi_response
, (void *)ns
,
3604 FC_MAX_PDUSZ
, FC_ELS_TOV
);
3605 port
->stats
.ns_plogi_sent
++;
3607 bfa_sm_send_event(ns
, NSSM_EVENT_PLOGI_SENT
);
3611 bfa_fcs_lport_ns_plogi_response(void *fcsarg
, struct bfa_fcxp_s
*fcxp
,
3612 void *cbarg
, bfa_status_t req_status
, u32 rsp_len
,
3613 u32 resid_len
, struct fchs_s
*rsp_fchs
)
3615 struct bfa_fcs_lport_ns_s
*ns
= (struct bfa_fcs_lport_ns_s
*) cbarg
;
3616 struct bfa_fcs_lport_s
*port
= ns
->port
;
3617 /* struct fc_logi_s *plogi_resp; */
3618 struct fc_els_cmd_s
*els_cmd
;
3619 struct fc_ls_rjt_s
*ls_rjt
;
3621 bfa_trc(port
->fcs
, req_status
);
3622 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
3627 if (req_status
!= BFA_STATUS_OK
) {
3628 bfa_trc(port
->fcs
, req_status
);
3629 port
->stats
.ns_plogi_rsp_err
++;
3630 bfa_sm_send_event(ns
, NSSM_EVENT_RSP_ERROR
);
3634 els_cmd
= (struct fc_els_cmd_s
*) BFA_FCXP_RSP_PLD(fcxp
);
3636 switch (els_cmd
->els_code
) {
3639 if (rsp_len
< sizeof(struct fc_logi_s
)) {
3640 bfa_trc(port
->fcs
, rsp_len
);
3641 port
->stats
.ns_plogi_acc_err
++;
3642 bfa_sm_send_event(ns
, NSSM_EVENT_RSP_ERROR
);
3645 port
->stats
.ns_plogi_accepts
++;
3646 bfa_sm_send_event(ns
, NSSM_EVENT_RSP_OK
);
3650 ls_rjt
= (struct fc_ls_rjt_s
*) BFA_FCXP_RSP_PLD(fcxp
);
3652 bfa_trc(port
->fcs
, ls_rjt
->reason_code
);
3653 bfa_trc(port
->fcs
, ls_rjt
->reason_code_expl
);
3655 port
->stats
.ns_rejects
++;
3657 bfa_sm_send_event(ns
, NSSM_EVENT_RSP_ERROR
);
3661 port
->stats
.ns_plogi_unknown_rsp
++;
3662 bfa_trc(port
->fcs
, els_cmd
->els_code
);
3663 bfa_sm_send_event(ns
, NSSM_EVENT_RSP_ERROR
);
3668 * Register the symbolic port name.
3671 bfa_fcs_lport_ns_send_rspn_id(void *ns_cbarg
, struct bfa_fcxp_s
*fcxp_alloced
)
3673 struct bfa_fcs_lport_ns_s
*ns
= ns_cbarg
;
3674 struct bfa_fcs_lport_s
*port
= ns
->port
;
3677 struct bfa_fcxp_s
*fcxp
;
3679 u8
*psymbl
= &symbl
[0];
3681 memset(symbl
, 0, sizeof(symbl
));
3683 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
3685 fcxp
= fcxp_alloced
? fcxp_alloced
: bfa_fcs_fcxp_alloc(port
->fcs
);
3687 port
->stats
.ns_rspnid_alloc_wait
++;
3688 bfa_fcs_fcxp_alloc_wait(port
->fcs
->bfa
, &ns
->fcxp_wqe
,
3689 bfa_fcs_lport_ns_send_rspn_id
, ns
);
3695 * for V-Port, form a Port Symbolic Name
3699 * For Vports, we append the vport's port symbolic name
3700 * to that of the base port.
3703 strncpy((char *)psymbl
,
3705 (bfa_fcs_lport_get_psym_name
3706 (bfa_fcs_get_base_port(port
->fcs
))),
3708 bfa_fcs_lport_get_psym_name(bfa_fcs_get_base_port
3711 /* Ensure we have a null terminating string. */
3712 ((char *)psymbl
)[strlen((char *) &
3713 bfa_fcs_lport_get_psym_name(bfa_fcs_get_base_port
3715 strncat((char *)psymbl
,
3716 (char *) &(bfa_fcs_lport_get_psym_name(port
)),
3717 strlen((char *) &bfa_fcs_lport_get_psym_name(port
)));
3719 psymbl
= (u8
*) &(bfa_fcs_lport_get_psym_name(port
));
3722 len
= fc_rspnid_build(&fchs
, bfa_fcxp_get_reqbuf(fcxp
),
3723 bfa_fcs_lport_get_fcid(port
), 0, psymbl
);
3725 bfa_fcxp_send(fcxp
, NULL
, port
->fabric
->vf_id
, port
->lp_tag
, BFA_FALSE
,
3726 FC_CLASS_3
, len
, &fchs
,
3727 bfa_fcs_lport_ns_rspn_id_response
, (void *)ns
,
3728 FC_MAX_PDUSZ
, FC_FCCT_TOV
);
3730 port
->stats
.ns_rspnid_sent
++;
3732 bfa_sm_send_event(ns
, NSSM_EVENT_RSPNID_SENT
);
3736 bfa_fcs_lport_ns_rspn_id_response(void *fcsarg
, struct bfa_fcxp_s
*fcxp
,
3737 void *cbarg
, bfa_status_t req_status
,
3738 u32 rsp_len
, u32 resid_len
,
3739 struct fchs_s
*rsp_fchs
)
3741 struct bfa_fcs_lport_ns_s
*ns
= (struct bfa_fcs_lport_ns_s
*) cbarg
;
3742 struct bfa_fcs_lport_s
*port
= ns
->port
;
3743 struct ct_hdr_s
*cthdr
= NULL
;
3745 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
3750 if (req_status
!= BFA_STATUS_OK
) {
3751 bfa_trc(port
->fcs
, req_status
);
3752 port
->stats
.ns_rspnid_rsp_err
++;
3753 bfa_sm_send_event(ns
, NSSM_EVENT_RSP_ERROR
);
3757 cthdr
= (struct ct_hdr_s
*) BFA_FCXP_RSP_PLD(fcxp
);
3758 cthdr
->cmd_rsp_code
= be16_to_cpu(cthdr
->cmd_rsp_code
);
3760 if (cthdr
->cmd_rsp_code
== CT_RSP_ACCEPT
) {
3761 port
->stats
.ns_rspnid_accepts
++;
3762 bfa_sm_send_event(ns
, NSSM_EVENT_RSP_OK
);
3766 port
->stats
.ns_rspnid_rejects
++;
3767 bfa_trc(port
->fcs
, cthdr
->reason_code
);
3768 bfa_trc(port
->fcs
, cthdr
->exp_code
);
3769 bfa_sm_send_event(ns
, NSSM_EVENT_RSP_ERROR
);
3773 * Register FC4-Types
3776 bfa_fcs_lport_ns_send_rft_id(void *ns_cbarg
, struct bfa_fcxp_s
*fcxp_alloced
)
3778 struct bfa_fcs_lport_ns_s
*ns
= ns_cbarg
;
3779 struct bfa_fcs_lport_s
*port
= ns
->port
;
3782 struct bfa_fcxp_s
*fcxp
;
3784 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
3786 fcxp
= fcxp_alloced
? fcxp_alloced
: bfa_fcs_fcxp_alloc(port
->fcs
);
3788 port
->stats
.ns_rftid_alloc_wait
++;
3789 bfa_fcs_fcxp_alloc_wait(port
->fcs
->bfa
, &ns
->fcxp_wqe
,
3790 bfa_fcs_lport_ns_send_rft_id
, ns
);
3795 len
= fc_rftid_build(&fchs
, bfa_fcxp_get_reqbuf(fcxp
),
3796 bfa_fcs_lport_get_fcid(port
), 0, port
->port_cfg
.roles
);
3798 bfa_fcxp_send(fcxp
, NULL
, port
->fabric
->vf_id
, port
->lp_tag
, BFA_FALSE
,
3799 FC_CLASS_3
, len
, &fchs
,
3800 bfa_fcs_lport_ns_rft_id_response
, (void *)ns
,
3801 FC_MAX_PDUSZ
, FC_FCCT_TOV
);
3803 port
->stats
.ns_rftid_sent
++;
3804 bfa_sm_send_event(ns
, NSSM_EVENT_RFTID_SENT
);
3808 bfa_fcs_lport_ns_rft_id_response(void *fcsarg
, struct bfa_fcxp_s
*fcxp
,
3809 void *cbarg
, bfa_status_t req_status
,
3810 u32 rsp_len
, u32 resid_len
,
3811 struct fchs_s
*rsp_fchs
)
3813 struct bfa_fcs_lport_ns_s
*ns
= (struct bfa_fcs_lport_ns_s
*) cbarg
;
3814 struct bfa_fcs_lport_s
*port
= ns
->port
;
3815 struct ct_hdr_s
*cthdr
= NULL
;
3817 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
3822 if (req_status
!= BFA_STATUS_OK
) {
3823 bfa_trc(port
->fcs
, req_status
);
3824 port
->stats
.ns_rftid_rsp_err
++;
3825 bfa_sm_send_event(ns
, NSSM_EVENT_RSP_ERROR
);
3829 cthdr
= (struct ct_hdr_s
*) BFA_FCXP_RSP_PLD(fcxp
);
3830 cthdr
->cmd_rsp_code
= be16_to_cpu(cthdr
->cmd_rsp_code
);
3832 if (cthdr
->cmd_rsp_code
== CT_RSP_ACCEPT
) {
3833 port
->stats
.ns_rftid_accepts
++;
3834 bfa_sm_send_event(ns
, NSSM_EVENT_RSP_OK
);
3838 port
->stats
.ns_rftid_rejects
++;
3839 bfa_trc(port
->fcs
, cthdr
->reason_code
);
3840 bfa_trc(port
->fcs
, cthdr
->exp_code
);
3841 bfa_sm_send_event(ns
, NSSM_EVENT_RSP_ERROR
);
3845 * Register FC4-Features : Should be done after RFT_ID
3848 bfa_fcs_lport_ns_send_rff_id(void *ns_cbarg
, struct bfa_fcxp_s
*fcxp_alloced
)
3850 struct bfa_fcs_lport_ns_s
*ns
= ns_cbarg
;
3851 struct bfa_fcs_lport_s
*port
= ns
->port
;
3854 struct bfa_fcxp_s
*fcxp
;
3857 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
3859 fcxp
= fcxp_alloced
? fcxp_alloced
: bfa_fcs_fcxp_alloc(port
->fcs
);
3861 port
->stats
.ns_rffid_alloc_wait
++;
3862 bfa_fcs_fcxp_alloc_wait(port
->fcs
->bfa
, &ns
->fcxp_wqe
,
3863 bfa_fcs_lport_ns_send_rff_id
, ns
);
3868 if (BFA_FCS_VPORT_IS_INITIATOR_MODE(ns
->port
))
3869 fc4_ftrs
= FC_GS_FCP_FC4_FEATURE_INITIATOR
;
3871 len
= fc_rffid_build(&fchs
, bfa_fcxp_get_reqbuf(fcxp
),
3872 bfa_fcs_lport_get_fcid(port
), 0,
3873 FC_TYPE_FCP
, fc4_ftrs
);
3875 bfa_fcxp_send(fcxp
, NULL
, port
->fabric
->vf_id
, port
->lp_tag
, BFA_FALSE
,
3876 FC_CLASS_3
, len
, &fchs
,
3877 bfa_fcs_lport_ns_rff_id_response
, (void *)ns
,
3878 FC_MAX_PDUSZ
, FC_FCCT_TOV
);
3880 port
->stats
.ns_rffid_sent
++;
3881 bfa_sm_send_event(ns
, NSSM_EVENT_RFFID_SENT
);
3885 bfa_fcs_lport_ns_rff_id_response(void *fcsarg
, struct bfa_fcxp_s
*fcxp
,
3886 void *cbarg
, bfa_status_t req_status
,
3887 u32 rsp_len
, u32 resid_len
,
3888 struct fchs_s
*rsp_fchs
)
3890 struct bfa_fcs_lport_ns_s
*ns
= (struct bfa_fcs_lport_ns_s
*) cbarg
;
3891 struct bfa_fcs_lport_s
*port
= ns
->port
;
3892 struct ct_hdr_s
*cthdr
= NULL
;
3894 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
3899 if (req_status
!= BFA_STATUS_OK
) {
3900 bfa_trc(port
->fcs
, req_status
);
3901 port
->stats
.ns_rffid_rsp_err
++;
3902 bfa_sm_send_event(ns
, NSSM_EVENT_RSP_ERROR
);
3906 cthdr
= (struct ct_hdr_s
*) BFA_FCXP_RSP_PLD(fcxp
);
3907 cthdr
->cmd_rsp_code
= be16_to_cpu(cthdr
->cmd_rsp_code
);
3909 if (cthdr
->cmd_rsp_code
== CT_RSP_ACCEPT
) {
3910 port
->stats
.ns_rffid_accepts
++;
3911 bfa_sm_send_event(ns
, NSSM_EVENT_RSP_OK
);
3915 port
->stats
.ns_rffid_rejects
++;
3916 bfa_trc(port
->fcs
, cthdr
->reason_code
);
3917 bfa_trc(port
->fcs
, cthdr
->exp_code
);
3919 if (cthdr
->reason_code
== CT_RSN_NOT_SUPP
) {
3920 /* if this command is not supported, we don't retry */
3921 bfa_sm_send_event(ns
, NSSM_EVENT_RSP_OK
);
3923 bfa_sm_send_event(ns
, NSSM_EVENT_RSP_ERROR
);
3926 * Query Fabric for FC4-Types Devices.
3928 * TBD : Need to use a local (FCS private) response buffer, since the response
3929 * can be larger than 2K.
3932 bfa_fcs_lport_ns_send_gid_ft(void *ns_cbarg
, struct bfa_fcxp_s
*fcxp_alloced
)
3934 struct bfa_fcs_lport_ns_s
*ns
= ns_cbarg
;
3935 struct bfa_fcs_lport_s
*port
= ns
->port
;
3938 struct bfa_fcxp_s
*fcxp
;
3940 bfa_trc(port
->fcs
, port
->pid
);
3942 fcxp
= fcxp_alloced
? fcxp_alloced
: bfa_fcs_fcxp_alloc(port
->fcs
);
3944 port
->stats
.ns_gidft_alloc_wait
++;
3945 bfa_fcs_fcxp_alloc_wait(port
->fcs
->bfa
, &ns
->fcxp_wqe
,
3946 bfa_fcs_lport_ns_send_gid_ft
, ns
);
3952 * This query is only initiated for FCP initiator mode.
3954 len
= fc_gid_ft_build(&fchs
, bfa_fcxp_get_reqbuf(fcxp
),
3955 ns
->port
->pid
, FC_TYPE_FCP
);
3957 bfa_fcxp_send(fcxp
, NULL
, port
->fabric
->vf_id
, port
->lp_tag
, BFA_FALSE
,
3958 FC_CLASS_3
, len
, &fchs
,
3959 bfa_fcs_lport_ns_gid_ft_response
, (void *)ns
,
3960 bfa_fcxp_get_maxrsp(port
->fcs
->bfa
), FC_FCCT_TOV
);
3962 port
->stats
.ns_gidft_sent
++;
3964 bfa_sm_send_event(ns
, NSSM_EVENT_GIDFT_SENT
);
3968 bfa_fcs_lport_ns_gid_ft_response(void *fcsarg
, struct bfa_fcxp_s
*fcxp
,
3969 void *cbarg
, bfa_status_t req_status
,
3970 u32 rsp_len
, u32 resid_len
,
3971 struct fchs_s
*rsp_fchs
)
3973 struct bfa_fcs_lport_ns_s
*ns
= (struct bfa_fcs_lport_ns_s
*) cbarg
;
3974 struct bfa_fcs_lport_s
*port
= ns
->port
;
3975 struct ct_hdr_s
*cthdr
= NULL
;
3978 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
3983 if (req_status
!= BFA_STATUS_OK
) {
3984 bfa_trc(port
->fcs
, req_status
);
3985 port
->stats
.ns_gidft_rsp_err
++;
3986 bfa_sm_send_event(ns
, NSSM_EVENT_RSP_ERROR
);
3990 if (resid_len
!= 0) {
3992 * TBD : we will need to allocate a larger buffer & retry the
3995 bfa_trc(port
->fcs
, rsp_len
);
3996 bfa_trc(port
->fcs
, resid_len
);
4000 cthdr
= (struct ct_hdr_s
*) BFA_FCXP_RSP_PLD(fcxp
);
4001 cthdr
->cmd_rsp_code
= be16_to_cpu(cthdr
->cmd_rsp_code
);
4003 switch (cthdr
->cmd_rsp_code
) {
4007 port
->stats
.ns_gidft_accepts
++;
4008 n_pids
= (fc_get_ctresp_pyld_len(rsp_len
) / sizeof(u32
));
4009 bfa_trc(port
->fcs
, n_pids
);
4010 bfa_fcs_lport_ns_process_gidft_pids(port
,
4011 (u32
*) (cthdr
+ 1),
4013 bfa_sm_send_event(ns
, NSSM_EVENT_RSP_OK
);
4019 * Check the reason code & explanation.
4020 * There may not have been any FC4 devices in the fabric
4022 port
->stats
.ns_gidft_rejects
++;
4023 bfa_trc(port
->fcs
, cthdr
->reason_code
);
4024 bfa_trc(port
->fcs
, cthdr
->exp_code
);
4026 if ((cthdr
->reason_code
== CT_RSN_UNABLE_TO_PERF
)
4027 && (cthdr
->exp_code
== CT_NS_EXP_FT_NOT_REG
)) {
4029 bfa_sm_send_event(ns
, NSSM_EVENT_RSP_OK
);
4032 * for all other errors, retry
4034 bfa_sm_send_event(ns
, NSSM_EVENT_RSP_ERROR
);
4039 port
->stats
.ns_gidft_unknown_rsp
++;
4040 bfa_trc(port
->fcs
, cthdr
->cmd_rsp_code
);
4041 bfa_sm_send_event(ns
, NSSM_EVENT_RSP_ERROR
);
4046 * This routine will be called by bfa_timer on timer timeouts.
4048 * param[in] port - pointer to bfa_fcs_lport_t.
4053 * Special Considerations:
4058 bfa_fcs_lport_ns_timeout(void *arg
)
4060 struct bfa_fcs_lport_ns_s
*ns
= (struct bfa_fcs_lport_ns_s
*) arg
;
4062 ns
->port
->stats
.ns_timeouts
++;
4063 bfa_sm_send_event(ns
, NSSM_EVENT_TIMEOUT
);
4067 * Process the PID list in GID_FT response
4070 bfa_fcs_lport_ns_process_gidft_pids(struct bfa_fcs_lport_s
*port
, u32
*pid_buf
,
4073 struct fcgs_gidft_resp_s
*gidft_entry
;
4074 struct bfa_fcs_rport_s
*rport
;
4077 for (ii
= 0; ii
< n_pids
; ii
++) {
4078 gidft_entry
= (struct fcgs_gidft_resp_s
*) &pid_buf
[ii
];
4080 if (gidft_entry
->pid
== port
->pid
)
4084 * Check if this rport already exists
4086 rport
= bfa_fcs_lport_get_rport_by_pid(port
, gidft_entry
->pid
);
4087 if (rport
== NULL
) {
4089 * this is a new device. create rport
4091 rport
= bfa_fcs_rport_create(port
, gidft_entry
->pid
);
4094 * this rport already exists
4096 bfa_fcs_rport_scn(rport
);
4099 bfa_trc(port
->fcs
, gidft_entry
->pid
);
4102 * if the last entry bit is set, bail out.
4104 if (gidft_entry
->last
)
4110 * fcs_ns_public FCS nameserver public interfaces
4114 * Functions called by port/fab.
4115 * These will send relevant Events to the ns state machine.
4118 bfa_fcs_lport_ns_init(struct bfa_fcs_lport_s
*port
)
4120 struct bfa_fcs_lport_ns_s
*ns
= BFA_FCS_GET_NS_FROM_PORT(port
);
4123 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_offline
);
4127 bfa_fcs_lport_ns_offline(struct bfa_fcs_lport_s
*port
)
4129 struct bfa_fcs_lport_ns_s
*ns
= BFA_FCS_GET_NS_FROM_PORT(port
);
4132 bfa_sm_send_event(ns
, NSSM_EVENT_PORT_OFFLINE
);
4136 bfa_fcs_lport_ns_online(struct bfa_fcs_lport_s
*port
)
4138 struct bfa_fcs_lport_ns_s
*ns
= BFA_FCS_GET_NS_FROM_PORT(port
);
4141 bfa_sm_send_event(ns
, NSSM_EVENT_PORT_ONLINE
);
4145 bfa_fcs_lport_ns_query(struct bfa_fcs_lport_s
*port
)
4147 struct bfa_fcs_lport_ns_s
*ns
= BFA_FCS_GET_NS_FROM_PORT(port
);
4149 bfa_trc(port
->fcs
, port
->pid
);
4150 bfa_sm_send_event(ns
, NSSM_EVENT_NS_QUERY
);
4154 bfa_fcs_lport_ns_boot_target_disc(bfa_fcs_lport_t
*port
)
4157 struct bfa_fcs_rport_s
*rport
;
4159 wwn_t wwns
[BFA_PREBOOT_BOOTLUN_MAX
];
4162 bfa_iocfc_get_bootwwns(port
->fcs
->bfa
, &nwwns
, wwns
);
4164 for (ii
= 0 ; ii
< nwwns
; ++ii
) {
4165 rport
= bfa_fcs_rport_create_by_wwn(port
, wwns
[ii
]);
4174 #define FC_QOS_RSCN_EVENT 0x0c
4175 #define FC_FABRIC_NAME_RSCN_EVENT 0x0d
4178 * forward declarations
4180 static void bfa_fcs_lport_scn_send_scr(void *scn_cbarg
,
4181 struct bfa_fcxp_s
*fcxp_alloced
);
4182 static void bfa_fcs_lport_scn_scr_response(void *fcsarg
,
4183 struct bfa_fcxp_s
*fcxp
,
4185 bfa_status_t req_status
,
4188 struct fchs_s
*rsp_fchs
);
4189 static void bfa_fcs_lport_scn_send_ls_acc(struct bfa_fcs_lport_s
*port
,
4190 struct fchs_s
*rx_fchs
);
4191 static void bfa_fcs_lport_scn_timeout(void *arg
);
4194 * fcs_scm_sm FCS SCN state machine
4198 * VPort SCN State Machine events
4200 enum port_scn_event
{
4201 SCNSM_EVENT_PORT_ONLINE
= 1,
4202 SCNSM_EVENT_PORT_OFFLINE
= 2,
4203 SCNSM_EVENT_RSP_OK
= 3,
4204 SCNSM_EVENT_RSP_ERROR
= 4,
4205 SCNSM_EVENT_TIMEOUT
= 5,
4206 SCNSM_EVENT_SCR_SENT
= 6,
4209 static void bfa_fcs_lport_scn_sm_offline(struct bfa_fcs_lport_scn_s
*scn
,
4210 enum port_scn_event event
);
4211 static void bfa_fcs_lport_scn_sm_sending_scr(
4212 struct bfa_fcs_lport_scn_s
*scn
,
4213 enum port_scn_event event
);
4214 static void bfa_fcs_lport_scn_sm_scr(struct bfa_fcs_lport_scn_s
*scn
,
4215 enum port_scn_event event
);
4216 static void bfa_fcs_lport_scn_sm_scr_retry(struct bfa_fcs_lport_scn_s
*scn
,
4217 enum port_scn_event event
);
4218 static void bfa_fcs_lport_scn_sm_online(struct bfa_fcs_lport_scn_s
*scn
,
4219 enum port_scn_event event
);
4222 * Starting state - awaiting link up.
4225 bfa_fcs_lport_scn_sm_offline(struct bfa_fcs_lport_scn_s
*scn
,
4226 enum port_scn_event event
)
4229 case SCNSM_EVENT_PORT_ONLINE
:
4230 bfa_sm_set_state(scn
, bfa_fcs_lport_scn_sm_sending_scr
);
4231 bfa_fcs_lport_scn_send_scr(scn
, NULL
);
4234 case SCNSM_EVENT_PORT_OFFLINE
:
4238 bfa_sm_fault(scn
->port
->fcs
, event
);
4243 bfa_fcs_lport_scn_sm_sending_scr(struct bfa_fcs_lport_scn_s
*scn
,
4244 enum port_scn_event event
)
4247 case SCNSM_EVENT_SCR_SENT
:
4248 bfa_sm_set_state(scn
, bfa_fcs_lport_scn_sm_scr
);
4251 case SCNSM_EVENT_PORT_OFFLINE
:
4252 bfa_sm_set_state(scn
, bfa_fcs_lport_scn_sm_offline
);
4253 bfa_fcxp_walloc_cancel(scn
->port
->fcs
->bfa
, &scn
->fcxp_wqe
);
4257 bfa_sm_fault(scn
->port
->fcs
, event
);
4262 bfa_fcs_lport_scn_sm_scr(struct bfa_fcs_lport_scn_s
*scn
,
4263 enum port_scn_event event
)
4265 struct bfa_fcs_lport_s
*port
= scn
->port
;
4268 case SCNSM_EVENT_RSP_OK
:
4269 bfa_sm_set_state(scn
, bfa_fcs_lport_scn_sm_online
);
4272 case SCNSM_EVENT_RSP_ERROR
:
4273 bfa_sm_set_state(scn
, bfa_fcs_lport_scn_sm_scr_retry
);
4274 bfa_timer_start(port
->fcs
->bfa
, &scn
->timer
,
4275 bfa_fcs_lport_scn_timeout
, scn
,
4276 BFA_FCS_RETRY_TIMEOUT
);
4279 case SCNSM_EVENT_PORT_OFFLINE
:
4280 bfa_sm_set_state(scn
, bfa_fcs_lport_scn_sm_offline
);
4281 bfa_fcxp_discard(scn
->fcxp
);
4285 bfa_sm_fault(port
->fcs
, event
);
4290 bfa_fcs_lport_scn_sm_scr_retry(struct bfa_fcs_lport_scn_s
*scn
,
4291 enum port_scn_event event
)
4294 case SCNSM_EVENT_TIMEOUT
:
4295 bfa_sm_set_state(scn
, bfa_fcs_lport_scn_sm_sending_scr
);
4296 bfa_fcs_lport_scn_send_scr(scn
, NULL
);
4299 case SCNSM_EVENT_PORT_OFFLINE
:
4300 bfa_sm_set_state(scn
, bfa_fcs_lport_scn_sm_offline
);
4301 bfa_timer_stop(&scn
->timer
);
4305 bfa_sm_fault(scn
->port
->fcs
, event
);
4310 bfa_fcs_lport_scn_sm_online(struct bfa_fcs_lport_scn_s
*scn
,
4311 enum port_scn_event event
)
4314 case SCNSM_EVENT_PORT_OFFLINE
:
4315 bfa_sm_set_state(scn
, bfa_fcs_lport_scn_sm_offline
);
4319 bfa_sm_fault(scn
->port
->fcs
, event
);
4326 * fcs_scn_private FCS SCN private functions
4330 * This routine will be called to send a SCR command.
4333 bfa_fcs_lport_scn_send_scr(void *scn_cbarg
, struct bfa_fcxp_s
*fcxp_alloced
)
4335 struct bfa_fcs_lport_scn_s
*scn
= scn_cbarg
;
4336 struct bfa_fcs_lport_s
*port
= scn
->port
;
4339 struct bfa_fcxp_s
*fcxp
;
4341 bfa_trc(port
->fcs
, port
->pid
);
4342 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
4344 fcxp
= fcxp_alloced
? fcxp_alloced
: bfa_fcs_fcxp_alloc(port
->fcs
);
4346 bfa_fcs_fcxp_alloc_wait(port
->fcs
->bfa
, &scn
->fcxp_wqe
,
4347 bfa_fcs_lport_scn_send_scr
, scn
);
4352 /* Handle VU registrations for Base port only */
4353 if ((!port
->vport
) && bfa_ioc_get_fcmode(&port
->fcs
->bfa
->ioc
)) {
4354 len
= fc_scr_build(&fchs
, bfa_fcxp_get_reqbuf(fcxp
),
4355 bfa_lps_is_brcd_fabric(port
->fabric
->lps
),
4358 len
= fc_scr_build(&fchs
, bfa_fcxp_get_reqbuf(fcxp
),
4363 bfa_fcxp_send(fcxp
, NULL
, port
->fabric
->vf_id
, port
->lp_tag
, BFA_FALSE
,
4364 FC_CLASS_3
, len
, &fchs
,
4365 bfa_fcs_lport_scn_scr_response
,
4366 (void *)scn
, FC_MAX_PDUSZ
, FC_ELS_TOV
);
4368 bfa_sm_send_event(scn
, SCNSM_EVENT_SCR_SENT
);
4372 bfa_fcs_lport_scn_scr_response(void *fcsarg
, struct bfa_fcxp_s
*fcxp
,
4373 void *cbarg
, bfa_status_t req_status
, u32 rsp_len
,
4374 u32 resid_len
, struct fchs_s
*rsp_fchs
)
4376 struct bfa_fcs_lport_scn_s
*scn
= (struct bfa_fcs_lport_scn_s
*) cbarg
;
4377 struct bfa_fcs_lport_s
*port
= scn
->port
;
4378 struct fc_els_cmd_s
*els_cmd
;
4379 struct fc_ls_rjt_s
*ls_rjt
;
4381 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
4386 if (req_status
!= BFA_STATUS_OK
) {
4387 bfa_trc(port
->fcs
, req_status
);
4388 bfa_sm_send_event(scn
, SCNSM_EVENT_RSP_ERROR
);
4392 els_cmd
= (struct fc_els_cmd_s
*) BFA_FCXP_RSP_PLD(fcxp
);
4394 switch (els_cmd
->els_code
) {
4397 bfa_sm_send_event(scn
, SCNSM_EVENT_RSP_OK
);
4402 ls_rjt
= (struct fc_ls_rjt_s
*) BFA_FCXP_RSP_PLD(fcxp
);
4404 bfa_trc(port
->fcs
, ls_rjt
->reason_code
);
4405 bfa_trc(port
->fcs
, ls_rjt
->reason_code_expl
);
4407 bfa_sm_send_event(scn
, SCNSM_EVENT_RSP_ERROR
);
4411 bfa_sm_send_event(scn
, SCNSM_EVENT_RSP_ERROR
);
4419 bfa_fcs_lport_scn_send_ls_acc(struct bfa_fcs_lport_s
*port
,
4420 struct fchs_s
*rx_fchs
)
4423 struct bfa_fcxp_s
*fcxp
;
4424 struct bfa_rport_s
*bfa_rport
= NULL
;
4427 bfa_trc(port
->fcs
, rx_fchs
->s_id
);
4429 fcxp
= bfa_fcs_fcxp_alloc(port
->fcs
);
4433 len
= fc_ls_acc_build(&fchs
, bfa_fcxp_get_reqbuf(fcxp
),
4434 rx_fchs
->s_id
, bfa_fcs_lport_get_fcid(port
),
4437 bfa_fcxp_send(fcxp
, bfa_rport
, port
->fabric
->vf_id
, port
->lp_tag
,
4438 BFA_FALSE
, FC_CLASS_3
, len
, &fchs
, NULL
, NULL
,
4443 * This routine will be called by bfa_timer on timer timeouts.
4445 * param[in] vport - pointer to bfa_fcs_lport_t.
4446 * param[out] vport_status - pointer to return vport status in
4451 * Special Considerations:
4456 bfa_fcs_lport_scn_timeout(void *arg
)
4458 struct bfa_fcs_lport_scn_s
*scn
= (struct bfa_fcs_lport_scn_s
*) arg
;
4460 bfa_sm_send_event(scn
, SCNSM_EVENT_TIMEOUT
);
4466 * fcs_scn_public FCS state change notification public interfaces
4470 * Functions called by port/fab
4473 bfa_fcs_lport_scn_init(struct bfa_fcs_lport_s
*port
)
4475 struct bfa_fcs_lport_scn_s
*scn
= BFA_FCS_GET_SCN_FROM_PORT(port
);
4478 bfa_sm_set_state(scn
, bfa_fcs_lport_scn_sm_offline
);
4482 bfa_fcs_lport_scn_offline(struct bfa_fcs_lport_s
*port
)
4484 struct bfa_fcs_lport_scn_s
*scn
= BFA_FCS_GET_SCN_FROM_PORT(port
);
4487 bfa_sm_send_event(scn
, SCNSM_EVENT_PORT_OFFLINE
);
4491 bfa_fcs_lport_scn_online(struct bfa_fcs_lport_s
*port
)
4493 struct bfa_fcs_lport_scn_s
*scn
= BFA_FCS_GET_SCN_FROM_PORT(port
);
4496 bfa_sm_send_event(scn
, SCNSM_EVENT_PORT_ONLINE
);
4500 bfa_fcs_lport_scn_portid_rscn(struct bfa_fcs_lport_s
*port
, u32 rpid
)
4502 struct bfa_fcs_rport_s
*rport
;
4504 bfa_trc(port
->fcs
, rpid
);
4507 * If this is an unknown device, then it just came online.
4508 * Otherwise let rport handle the RSCN event.
4510 rport
= bfa_fcs_lport_get_rport_by_pid(port
, rpid
);
4511 if (rport
== NULL
) {
4513 * If min cfg mode is enabled, we donot need to
4514 * discover any new rports.
4516 if (!__fcs_min_cfg(port
->fcs
))
4517 rport
= bfa_fcs_rport_create(port
, rpid
);
4519 bfa_fcs_rport_scn(rport
);
4523 * rscn format based PID comparison
4525 #define __fc_pid_match(__c0, __c1, __fmt) \
4526 (((__fmt) == FC_RSCN_FORMAT_FABRIC) || \
4527 (((__fmt) == FC_RSCN_FORMAT_DOMAIN) && \
4528 ((__c0)[0] == (__c1)[0])) || \
4529 (((__fmt) == FC_RSCN_FORMAT_AREA) && \
4530 ((__c0)[0] == (__c1)[0]) && \
4531 ((__c0)[1] == (__c1)[1])))
4534 bfa_fcs_lport_scn_multiport_rscn(struct bfa_fcs_lport_s
*port
,
4535 enum fc_rscn_format format
,
4538 struct bfa_fcs_rport_s
*rport
;
4539 struct list_head
*qe
, *qe_next
;
4542 bfa_trc(port
->fcs
, format
);
4543 bfa_trc(port
->fcs
, rscn_pid
);
4545 c0
= (u8
*) &rscn_pid
;
4547 list_for_each_safe(qe
, qe_next
, &port
->rport_q
) {
4548 rport
= (struct bfa_fcs_rport_s
*) qe
;
4549 c1
= (u8
*) &rport
->pid
;
4550 if (__fc_pid_match(c0
, c1
, format
))
4551 bfa_fcs_rport_scn(rport
);
4557 bfa_fcs_lport_scn_process_rscn(struct bfa_fcs_lport_s
*port
,
4558 struct fchs_s
*fchs
, u32 len
)
4560 struct fc_rscn_pl_s
*rscn
= (struct fc_rscn_pl_s
*) (fchs
+ 1);
4563 bfa_boolean_t nsquery
= BFA_FALSE
, found
;
4567 (be16_to_cpu(rscn
->payldlen
) -
4568 sizeof(u32
)) / sizeof(rscn
->event
[0]);
4570 bfa_trc(port
->fcs
, num_entries
);
4572 port
->stats
.num_rscn
++;
4574 bfa_fcs_lport_scn_send_ls_acc(port
, fchs
);
4576 for (i
= 0; i
< num_entries
; i
++) {
4577 rscn_pid
= rscn
->event
[i
].portid
;
4579 bfa_trc(port
->fcs
, rscn
->event
[i
].format
);
4580 bfa_trc(port
->fcs
, rscn_pid
);
4582 /* check for duplicate entries in the list */
4584 for (j
= 0; j
< i
; j
++) {
4585 if (rscn
->event
[j
].portid
== rscn_pid
) {
4591 /* if found in down the list, pid has been already processed */
4593 bfa_trc(port
->fcs
, rscn_pid
);
4597 switch (rscn
->event
[i
].format
) {
4598 case FC_RSCN_FORMAT_PORTID
:
4599 if (rscn
->event
[i
].qualifier
== FC_QOS_RSCN_EVENT
) {
4601 * Ignore this event.
4602 * f/w would have processed it
4604 bfa_trc(port
->fcs
, rscn_pid
);
4606 port
->stats
.num_portid_rscn
++;
4607 bfa_fcs_lport_scn_portid_rscn(port
, rscn_pid
);
4611 case FC_RSCN_FORMAT_FABRIC
:
4612 if (rscn
->event
[i
].qualifier
==
4613 FC_FABRIC_NAME_RSCN_EVENT
) {
4614 bfa_fcs_lport_ms_fabric_rscn(port
);
4617 /* !!!!!!!!! Fall Through !!!!!!!!!!!!! */
4619 case FC_RSCN_FORMAT_AREA
:
4620 case FC_RSCN_FORMAT_DOMAIN
:
4622 bfa_fcs_lport_scn_multiport_rscn(port
,
4623 rscn
->event
[i
].format
,
4635 * If any of area, domain or fabric RSCN is received, do a fresh
4636 * discovery to find new devices.
4639 bfa_fcs_lport_ns_query(port
);
4646 * fcs_port_api BFA FCS port API
4648 struct bfa_fcs_lport_s
*
4649 bfa_fcs_get_base_port(struct bfa_fcs_s
*fcs
)
4651 return &fcs
->fabric
.bport
;
4655 bfa_fcs_lport_get_rport(struct bfa_fcs_lport_s
*port
, wwn_t wwn
, int index
,
4656 int nrports
, bfa_boolean_t bwwn
)
4658 struct list_head
*qh
, *qe
;
4659 struct bfa_fcs_rport_s
*rport
= NULL
;
4661 struct bfa_fcs_s
*fcs
;
4663 if (port
== NULL
|| nrports
== 0)
4667 bfa_trc(fcs
, (u32
) nrports
);
4670 qh
= &port
->rport_q
;
4671 qe
= bfa_q_first(qh
);
4673 while ((qe
!= qh
) && (i
< nrports
)) {
4674 rport
= (struct bfa_fcs_rport_s
*) qe
;
4675 if (bfa_os_ntoh3b(rport
->pid
) > 0xFFF000) {
4676 qe
= bfa_q_next(qe
);
4677 bfa_trc(fcs
, (u32
) rport
->pwwn
);
4678 bfa_trc(fcs
, rport
->pid
);
4684 if (!memcmp(&wwn
, &rport
->pwwn
, 8))
4692 qe
= bfa_q_next(qe
);
4703 bfa_fcs_lport_get_rports(struct bfa_fcs_lport_s
*port
,
4704 wwn_t rport_wwns
[], int *nrports
)
4706 struct list_head
*qh
, *qe
;
4707 struct bfa_fcs_rport_s
*rport
= NULL
;
4709 struct bfa_fcs_s
*fcs
;
4711 if (port
== NULL
|| rport_wwns
== NULL
|| *nrports
== 0)
4715 bfa_trc(fcs
, (u32
) *nrports
);
4718 qh
= &port
->rport_q
;
4719 qe
= bfa_q_first(qh
);
4721 while ((qe
!= qh
) && (i
< *nrports
)) {
4722 rport
= (struct bfa_fcs_rport_s
*) qe
;
4723 if (bfa_os_ntoh3b(rport
->pid
) > 0xFFF000) {
4724 qe
= bfa_q_next(qe
);
4725 bfa_trc(fcs
, (u32
) rport
->pwwn
);
4726 bfa_trc(fcs
, rport
->pid
);
4731 rport_wwns
[i
] = rport
->pwwn
;
4734 qe
= bfa_q_next(qe
);
4742 * Iterate's through all the rport's in the given port to
4743 * determine the maximum operating speed.
4745 * !!!! To be used in TRL Functionality only !!!!
4748 bfa_fcs_lport_get_rport_max_speed(bfa_fcs_lport_t
*port
)
4750 struct list_head
*qh
, *qe
;
4751 struct bfa_fcs_rport_s
*rport
= NULL
;
4752 struct bfa_fcs_s
*fcs
;
4753 bfa_port_speed_t max_speed
= 0;
4754 struct bfa_port_attr_s port_attr
;
4755 bfa_port_speed_t port_speed
, rport_speed
;
4756 bfa_boolean_t trl_enabled
= bfa_fcport_is_ratelim(port
->fcs
->bfa
);
4764 /* Get Physical port's current speed */
4765 bfa_fcport_get_attr(port
->fcs
->bfa
, &port_attr
);
4766 port_speed
= port_attr
.speed
;
4767 bfa_trc(fcs
, port_speed
);
4769 qh
= &port
->rport_q
;
4770 qe
= bfa_q_first(qh
);
4773 rport
= (struct bfa_fcs_rport_s
*) qe
;
4774 if ((bfa_os_ntoh3b(rport
->pid
) > 0xFFF000) ||
4775 (bfa_fcs_rport_get_state(rport
) ==
4776 BFA_RPORT_OFFLINE
)) {
4777 qe
= bfa_q_next(qe
);
4781 rport_speed
= rport
->rpf
.rpsc_speed
;
4782 if ((trl_enabled
) && (rport_speed
==
4783 BFA_PORT_SPEED_UNKNOWN
)) {
4784 /* Use default ratelim speed setting */
4786 bfa_fcport_get_ratelim_speed(port
->fcs
->bfa
);
4789 if ((rport_speed
== BFA_PORT_SPEED_8GBPS
) ||
4790 (rport_speed
> port_speed
)) {
4791 max_speed
= rport_speed
;
4793 } else if (rport_speed
> max_speed
) {
4794 max_speed
= rport_speed
;
4797 qe
= bfa_q_next(qe
);
4800 bfa_trc(fcs
, max_speed
);
4804 struct bfa_fcs_lport_s
*
4805 bfa_fcs_lookup_port(struct bfa_fcs_s
*fcs
, u16 vf_id
, wwn_t lpwwn
)
4807 struct bfa_fcs_vport_s
*vport
;
4810 bfa_assert(fcs
!= NULL
);
4812 vf
= bfa_fcs_vf_lookup(fcs
, vf_id
);
4814 bfa_trc(fcs
, vf_id
);
4818 if (!lpwwn
|| (vf
->bport
.port_cfg
.pwwn
== lpwwn
))
4821 vport
= bfa_fcs_fabric_vport_lookup(vf
, lpwwn
);
4823 return &vport
->lport
;
4829 * API corresponding to NPIV_VPORT_GETINFO.
4832 bfa_fcs_lport_get_info(struct bfa_fcs_lport_s
*port
,
4833 struct bfa_lport_info_s
*port_info
)
4836 bfa_trc(port
->fcs
, port
->fabric
->fabric_name
);
4838 if (port
->vport
== NULL
) {
4840 * This is a Physical port
4842 port_info
->port_type
= BFA_LPORT_TYPE_PHYSICAL
;
4845 * @todo : need to fix the state & reason
4847 port_info
->port_state
= 0;
4848 port_info
->offline_reason
= 0;
4850 port_info
->port_wwn
= bfa_fcs_lport_get_pwwn(port
);
4851 port_info
->node_wwn
= bfa_fcs_lport_get_nwwn(port
);
4853 port_info
->max_vports_supp
=
4854 bfa_lps_get_max_vport(port
->fcs
->bfa
);
4855 port_info
->num_vports_inuse
=
4856 bfa_fcs_fabric_vport_count(port
->fabric
);
4857 port_info
->max_rports_supp
= BFA_FCS_MAX_RPORTS_SUPP
;
4858 port_info
->num_rports_inuse
= port
->num_rports
;
4861 * This is a virtual port
4863 port_info
->port_type
= BFA_LPORT_TYPE_VIRTUAL
;
4866 * @todo : need to fix the state & reason
4868 port_info
->port_state
= 0;
4869 port_info
->offline_reason
= 0;
4871 port_info
->port_wwn
= bfa_fcs_lport_get_pwwn(port
);
4872 port_info
->node_wwn
= bfa_fcs_lport_get_nwwn(port
);
4877 bfa_fcs_lport_get_stats(struct bfa_fcs_lport_s
*fcs_port
,
4878 struct bfa_lport_stats_s
*port_stats
)
4880 *port_stats
= fcs_port
->stats
;
4884 bfa_fcs_lport_clear_stats(struct bfa_fcs_lport_s
*fcs_port
)
4886 memset(&fcs_port
->stats
, 0, sizeof(struct bfa_lport_stats_s
));
4890 * FCS virtual port state machine
4893 #define __vport_fcs(__vp) ((__vp)->lport.fcs)
4894 #define __vport_pwwn(__vp) ((__vp)->lport.port_cfg.pwwn)
4895 #define __vport_nwwn(__vp) ((__vp)->lport.port_cfg.nwwn)
4896 #define __vport_bfa(__vp) ((__vp)->lport.fcs->bfa)
4897 #define __vport_fcid(__vp) ((__vp)->lport.pid)
4898 #define __vport_fabric(__vp) ((__vp)->lport.fabric)
4899 #define __vport_vfid(__vp) ((__vp)->lport.fabric->vf_id)
4901 #define BFA_FCS_VPORT_MAX_RETRIES 5
4903 * Forward declarations
4905 static void bfa_fcs_vport_do_fdisc(struct bfa_fcs_vport_s
*vport
);
4906 static void bfa_fcs_vport_timeout(void *vport_arg
);
4907 static void bfa_fcs_vport_do_logo(struct bfa_fcs_vport_s
*vport
);
4908 static void bfa_fcs_vport_free(struct bfa_fcs_vport_s
*vport
);
4911 * fcs_vport_sm FCS virtual port state machine
4915 * VPort State Machine events
4917 enum bfa_fcs_vport_event
{
4918 BFA_FCS_VPORT_SM_CREATE
= 1, /* vport create event */
4919 BFA_FCS_VPORT_SM_DELETE
= 2, /* vport delete event */
4920 BFA_FCS_VPORT_SM_START
= 3, /* vport start request */
4921 BFA_FCS_VPORT_SM_STOP
= 4, /* stop: unsupported */
4922 BFA_FCS_VPORT_SM_ONLINE
= 5, /* fabric online */
4923 BFA_FCS_VPORT_SM_OFFLINE
= 6, /* fabric offline event */
4924 BFA_FCS_VPORT_SM_FRMSENT
= 7, /* fdisc/logo sent events */
4925 BFA_FCS_VPORT_SM_RSP_OK
= 8, /* good response */
4926 BFA_FCS_VPORT_SM_RSP_ERROR
= 9, /* error/bad response */
4927 BFA_FCS_VPORT_SM_TIMEOUT
= 10, /* delay timer event */
4928 BFA_FCS_VPORT_SM_DELCOMP
= 11, /* lport delete completion */
4929 BFA_FCS_VPORT_SM_RSP_DUP_WWN
= 12, /* Dup wnn error*/
4930 BFA_FCS_VPORT_SM_RSP_FAILED
= 13, /* non-retryable failure */
4933 static void bfa_fcs_vport_sm_uninit(struct bfa_fcs_vport_s
*vport
,
4934 enum bfa_fcs_vport_event event
);
4935 static void bfa_fcs_vport_sm_created(struct bfa_fcs_vport_s
*vport
,
4936 enum bfa_fcs_vport_event event
);
4937 static void bfa_fcs_vport_sm_offline(struct bfa_fcs_vport_s
*vport
,
4938 enum bfa_fcs_vport_event event
);
4939 static void bfa_fcs_vport_sm_fdisc(struct bfa_fcs_vport_s
*vport
,
4940 enum bfa_fcs_vport_event event
);
4941 static void bfa_fcs_vport_sm_fdisc_retry(struct bfa_fcs_vport_s
*vport
,
4942 enum bfa_fcs_vport_event event
);
4943 static void bfa_fcs_vport_sm_online(struct bfa_fcs_vport_s
*vport
,
4944 enum bfa_fcs_vport_event event
);
4945 static void bfa_fcs_vport_sm_deleting(struct bfa_fcs_vport_s
*vport
,
4946 enum bfa_fcs_vport_event event
);
4947 static void bfa_fcs_vport_sm_cleanup(struct bfa_fcs_vport_s
*vport
,
4948 enum bfa_fcs_vport_event event
);
4949 static void bfa_fcs_vport_sm_logo(struct bfa_fcs_vport_s
*vport
,
4950 enum bfa_fcs_vport_event event
);
4951 static void bfa_fcs_vport_sm_error(struct bfa_fcs_vport_s
*vport
,
4952 enum bfa_fcs_vport_event event
);
4954 static struct bfa_sm_table_s vport_sm_table
[] = {
4955 {BFA_SM(bfa_fcs_vport_sm_uninit
), BFA_FCS_VPORT_UNINIT
},
4956 {BFA_SM(bfa_fcs_vport_sm_created
), BFA_FCS_VPORT_CREATED
},
4957 {BFA_SM(bfa_fcs_vport_sm_offline
), BFA_FCS_VPORT_OFFLINE
},
4958 {BFA_SM(bfa_fcs_vport_sm_fdisc
), BFA_FCS_VPORT_FDISC
},
4959 {BFA_SM(bfa_fcs_vport_sm_fdisc_retry
), BFA_FCS_VPORT_FDISC_RETRY
},
4960 {BFA_SM(bfa_fcs_vport_sm_online
), BFA_FCS_VPORT_ONLINE
},
4961 {BFA_SM(bfa_fcs_vport_sm_deleting
), BFA_FCS_VPORT_DELETING
},
4962 {BFA_SM(bfa_fcs_vport_sm_cleanup
), BFA_FCS_VPORT_CLEANUP
},
4963 {BFA_SM(bfa_fcs_vport_sm_logo
), BFA_FCS_VPORT_LOGO
},
4964 {BFA_SM(bfa_fcs_vport_sm_error
), BFA_FCS_VPORT_ERROR
}
4971 bfa_fcs_vport_sm_uninit(struct bfa_fcs_vport_s
*vport
,
4972 enum bfa_fcs_vport_event event
)
4974 bfa_trc(__vport_fcs(vport
), __vport_pwwn(vport
));
4975 bfa_trc(__vport_fcs(vport
), event
);
4978 case BFA_FCS_VPORT_SM_CREATE
:
4979 bfa_sm_set_state(vport
, bfa_fcs_vport_sm_created
);
4980 bfa_fcs_fabric_addvport(__vport_fabric(vport
), vport
);
4984 bfa_sm_fault(__vport_fcs(vport
), event
);
4989 * Created state - a start event is required to start up the state machine.
4992 bfa_fcs_vport_sm_created(struct bfa_fcs_vport_s
*vport
,
4993 enum bfa_fcs_vport_event event
)
4995 bfa_trc(__vport_fcs(vport
), __vport_pwwn(vport
));
4996 bfa_trc(__vport_fcs(vport
), event
);
4999 case BFA_FCS_VPORT_SM_START
:
5000 if (bfa_fcs_fabric_is_online(__vport_fabric(vport
))
5001 && bfa_fcs_fabric_npiv_capable(__vport_fabric(vport
))) {
5002 bfa_sm_set_state(vport
, bfa_fcs_vport_sm_fdisc
);
5003 bfa_fcs_vport_do_fdisc(vport
);
5006 * Fabric is offline or not NPIV capable, stay in
5009 vport
->vport_stats
.fab_no_npiv
++;
5010 bfa_sm_set_state(vport
, bfa_fcs_vport_sm_offline
);
5014 case BFA_FCS_VPORT_SM_DELETE
:
5015 bfa_sm_set_state(vport
, bfa_fcs_vport_sm_cleanup
);
5016 bfa_fcs_lport_delete(&vport
->lport
);
5019 case BFA_FCS_VPORT_SM_ONLINE
:
5020 case BFA_FCS_VPORT_SM_OFFLINE
:
5022 * Ignore ONLINE/OFFLINE events from fabric
5023 * till vport is started.
5028 bfa_sm_fault(__vport_fcs(vport
), event
);
5033 * Offline state - awaiting ONLINE event from fabric SM.
5036 bfa_fcs_vport_sm_offline(struct bfa_fcs_vport_s
*vport
,
5037 enum bfa_fcs_vport_event event
)
5039 bfa_trc(__vport_fcs(vport
), __vport_pwwn(vport
));
5040 bfa_trc(__vport_fcs(vport
), event
);
5043 case BFA_FCS_VPORT_SM_DELETE
:
5044 bfa_sm_set_state(vport
, bfa_fcs_vport_sm_cleanup
);
5045 bfa_fcs_lport_delete(&vport
->lport
);
5048 case BFA_FCS_VPORT_SM_ONLINE
:
5049 bfa_sm_set_state(vport
, bfa_fcs_vport_sm_fdisc
);
5050 vport
->fdisc_retries
= 0;
5051 bfa_fcs_vport_do_fdisc(vport
);
5054 case BFA_FCS_VPORT_SM_OFFLINE
:
5056 * This can happen if the vport couldn't be initialzied
5057 * due the fact that the npiv was not enabled on the switch.
5058 * In that case we will put the vport in offline state.
5059 * However, the link can go down and cause the this event to
5060 * be sent when we are already offline. Ignore it.
5065 bfa_sm_fault(__vport_fcs(vport
), event
);
5071 * FDISC is sent and awaiting reply from fabric.
5074 bfa_fcs_vport_sm_fdisc(struct bfa_fcs_vport_s
*vport
,
5075 enum bfa_fcs_vport_event event
)
5077 bfa_trc(__vport_fcs(vport
), __vport_pwwn(vport
));
5078 bfa_trc(__vport_fcs(vport
), event
);
5081 case BFA_FCS_VPORT_SM_DELETE
:
5082 bfa_sm_set_state(vport
, bfa_fcs_vport_sm_cleanup
);
5083 bfa_lps_discard(vport
->lps
);
5084 bfa_fcs_lport_delete(&vport
->lport
);
5087 case BFA_FCS_VPORT_SM_OFFLINE
:
5088 bfa_sm_set_state(vport
, bfa_fcs_vport_sm_offline
);
5089 bfa_lps_discard(vport
->lps
);
5092 case BFA_FCS_VPORT_SM_RSP_OK
:
5093 bfa_sm_set_state(vport
, bfa_fcs_vport_sm_online
);
5094 bfa_fcs_lport_online(&vport
->lport
);
5097 case BFA_FCS_VPORT_SM_RSP_ERROR
:
5098 bfa_sm_set_state(vport
, bfa_fcs_vport_sm_fdisc_retry
);
5099 bfa_timer_start(__vport_bfa(vport
), &vport
->timer
,
5100 bfa_fcs_vport_timeout
, vport
,
5101 BFA_FCS_RETRY_TIMEOUT
);
5104 case BFA_FCS_VPORT_SM_RSP_FAILED
:
5105 bfa_sm_set_state(vport
, bfa_fcs_vport_sm_offline
);
5108 case BFA_FCS_VPORT_SM_RSP_DUP_WWN
:
5109 bfa_sm_set_state(vport
, bfa_fcs_vport_sm_error
);
5113 bfa_sm_fault(__vport_fcs(vport
), event
);
5118 * FDISC attempt failed - a timer is active to retry FDISC.
5121 bfa_fcs_vport_sm_fdisc_retry(struct bfa_fcs_vport_s
*vport
,
5122 enum bfa_fcs_vport_event event
)
5124 bfa_trc(__vport_fcs(vport
), __vport_pwwn(vport
));
5125 bfa_trc(__vport_fcs(vport
), event
);
5128 case BFA_FCS_VPORT_SM_DELETE
:
5129 bfa_sm_set_state(vport
, bfa_fcs_vport_sm_cleanup
);
5130 bfa_timer_stop(&vport
->timer
);
5131 bfa_fcs_lport_delete(&vport
->lport
);
5134 case BFA_FCS_VPORT_SM_OFFLINE
:
5135 bfa_sm_set_state(vport
, bfa_fcs_vport_sm_offline
);
5136 bfa_timer_stop(&vport
->timer
);
5139 case BFA_FCS_VPORT_SM_TIMEOUT
:
5140 bfa_sm_set_state(vport
, bfa_fcs_vport_sm_fdisc
);
5141 vport
->vport_stats
.fdisc_retries
++;
5142 vport
->fdisc_retries
++;
5143 bfa_fcs_vport_do_fdisc(vport
);
5147 bfa_sm_fault(__vport_fcs(vport
), event
);
5152 * Vport is online (FDISC is complete).
5155 bfa_fcs_vport_sm_online(struct bfa_fcs_vport_s
*vport
,
5156 enum bfa_fcs_vport_event event
)
5158 bfa_trc(__vport_fcs(vport
), __vport_pwwn(vport
));
5159 bfa_trc(__vport_fcs(vport
), event
);
5162 case BFA_FCS_VPORT_SM_DELETE
:
5163 bfa_sm_set_state(vport
, bfa_fcs_vport_sm_deleting
);
5164 bfa_fcs_lport_delete(&vport
->lport
);
5167 case BFA_FCS_VPORT_SM_OFFLINE
:
5168 bfa_sm_set_state(vport
, bfa_fcs_vport_sm_offline
);
5169 bfa_lps_discard(vport
->lps
);
5170 bfa_fcs_lport_offline(&vport
->lport
);
5174 bfa_sm_fault(__vport_fcs(vport
), event
);
5179 * Vport is being deleted - awaiting lport delete completion to send
5183 bfa_fcs_vport_sm_deleting(struct bfa_fcs_vport_s
*vport
,
5184 enum bfa_fcs_vport_event event
)
5186 bfa_trc(__vport_fcs(vport
), __vport_pwwn(vport
));
5187 bfa_trc(__vport_fcs(vport
), event
);
5190 case BFA_FCS_VPORT_SM_DELETE
:
5193 case BFA_FCS_VPORT_SM_DELCOMP
:
5194 bfa_sm_set_state(vport
, bfa_fcs_vport_sm_logo
);
5195 bfa_fcs_vport_do_logo(vport
);
5198 case BFA_FCS_VPORT_SM_OFFLINE
:
5199 bfa_sm_set_state(vport
, bfa_fcs_vport_sm_cleanup
);
5203 bfa_sm_fault(__vport_fcs(vport
), event
);
5209 * This state will be set when the Vport Creation fails due
5210 * to errors like Dup WWN. In this state only operation allowed
5211 * is a Vport Delete.
5214 bfa_fcs_vport_sm_error(struct bfa_fcs_vport_s
*vport
,
5215 enum bfa_fcs_vport_event event
)
5217 bfa_trc(__vport_fcs(vport
), __vport_pwwn(vport
));
5218 bfa_trc(__vport_fcs(vport
), event
);
5221 case BFA_FCS_VPORT_SM_DELETE
:
5222 bfa_sm_set_state(vport
, bfa_fcs_vport_sm_cleanup
);
5223 bfa_fcs_lport_delete(&vport
->lport
);
5227 bfa_trc(__vport_fcs(vport
), event
);
5232 * Lport cleanup is in progress since vport is being deleted. Fabric is
5233 * offline, so no LOGO is needed to complete vport deletion.
5236 bfa_fcs_vport_sm_cleanup(struct bfa_fcs_vport_s
*vport
,
5237 enum bfa_fcs_vport_event event
)
5239 bfa_trc(__vport_fcs(vport
), __vport_pwwn(vport
));
5240 bfa_trc(__vport_fcs(vport
), event
);
5243 case BFA_FCS_VPORT_SM_DELCOMP
:
5244 bfa_sm_set_state(vport
, bfa_fcs_vport_sm_uninit
);
5245 bfa_fcs_vport_free(vport
);
5248 case BFA_FCS_VPORT_SM_DELETE
:
5252 bfa_sm_fault(__vport_fcs(vport
), event
);
5257 * LOGO is sent to fabric. Vport delete is in progress. Lport delete cleanup
5261 bfa_fcs_vport_sm_logo(struct bfa_fcs_vport_s
*vport
,
5262 enum bfa_fcs_vport_event event
)
5264 bfa_trc(__vport_fcs(vport
), __vport_pwwn(vport
));
5265 bfa_trc(__vport_fcs(vport
), event
);
5268 case BFA_FCS_VPORT_SM_OFFLINE
:
5269 bfa_lps_discard(vport
->lps
);
5271 * !!! fall through !!!
5274 case BFA_FCS_VPORT_SM_RSP_OK
:
5275 case BFA_FCS_VPORT_SM_RSP_ERROR
:
5276 bfa_sm_set_state(vport
, bfa_fcs_vport_sm_uninit
);
5277 bfa_fcs_vport_free(vport
);
5280 case BFA_FCS_VPORT_SM_DELETE
:
5284 bfa_sm_fault(__vport_fcs(vport
), event
);
5291 * fcs_vport_private FCS virtual port private functions
5294 * This routine will be called to send a FDISC command.
5297 bfa_fcs_vport_do_fdisc(struct bfa_fcs_vport_s
*vport
)
5299 bfa_lps_fdisc(vport
->lps
, vport
,
5300 bfa_fcport_get_maxfrsize(__vport_bfa(vport
)),
5301 __vport_pwwn(vport
), __vport_nwwn(vport
));
5302 vport
->vport_stats
.fdisc_sent
++;
5306 bfa_fcs_vport_fdisc_rejected(struct bfa_fcs_vport_s
*vport
)
5308 u8 lsrjt_rsn
= bfa_lps_get_lsrjt_rsn(vport
->lps
);
5309 u8 lsrjt_expl
= bfa_lps_get_lsrjt_expl(vport
->lps
);
5311 bfa_trc(__vport_fcs(vport
), lsrjt_rsn
);
5312 bfa_trc(__vport_fcs(vport
), lsrjt_expl
);
5314 /* For certain reason codes, we don't want to retry. */
5315 switch (bfa_lps_get_lsrjt_expl(vport
->lps
)) {
5316 case FC_LS_RJT_EXP_INV_PORT_NAME
: /* by brocade */
5317 case FC_LS_RJT_EXP_INVALID_NPORT_ID
: /* by Cisco */
5318 if (vport
->fdisc_retries
< BFA_FCS_VPORT_MAX_RETRIES
)
5319 bfa_sm_send_event(vport
, BFA_FCS_VPORT_SM_RSP_ERROR
);
5321 bfa_sm_send_event(vport
, BFA_FCS_VPORT_SM_RSP_DUP_WWN
);
5324 case FC_LS_RJT_EXP_INSUFF_RES
:
5326 * This means max logins per port/switch setting on the
5327 * switch was exceeded.
5329 if (vport
->fdisc_retries
< BFA_FCS_VPORT_MAX_RETRIES
)
5330 bfa_sm_send_event(vport
, BFA_FCS_VPORT_SM_RSP_ERROR
);
5332 bfa_sm_send_event(vport
, BFA_FCS_VPORT_SM_RSP_FAILED
);
5336 bfa_sm_send_event(vport
, BFA_FCS_VPORT_SM_RSP_ERROR
);
5341 * Called to send a logout to the fabric. Used when a V-Port is
5345 bfa_fcs_vport_do_logo(struct bfa_fcs_vport_s
*vport
)
5347 bfa_trc(__vport_fcs(vport
), __vport_pwwn(vport
));
5349 vport
->vport_stats
.logo_sent
++;
5350 bfa_lps_fdisclogo(vport
->lps
);
5355 * This routine will be called by bfa_timer on timer timeouts.
5357 * param[in] vport - pointer to bfa_fcs_vport_t.
5358 * param[out] vport_status - pointer to return vport status in
5363 * Special Considerations:
5368 bfa_fcs_vport_timeout(void *vport_arg
)
5370 struct bfa_fcs_vport_s
*vport
= (struct bfa_fcs_vport_s
*) vport_arg
;
5372 vport
->vport_stats
.fdisc_timeouts
++;
5373 bfa_sm_send_event(vport
, BFA_FCS_VPORT_SM_TIMEOUT
);
5377 bfa_fcs_vport_free(struct bfa_fcs_vport_s
*vport
)
5379 struct bfad_vport_s
*vport_drv
=
5380 (struct bfad_vport_s
*)vport
->vport_drv
;
5382 bfa_fcs_fabric_delvport(__vport_fabric(vport
), vport
);
5384 if (vport_drv
->comp_del
)
5385 complete(vport_drv
->comp_del
);
5387 bfa_lps_delete(vport
->lps
);
5393 * fcs_vport_public FCS virtual port public interfaces
5397 * Online notification from fabric SM.
5400 bfa_fcs_vport_online(struct bfa_fcs_vport_s
*vport
)
5402 vport
->vport_stats
.fab_online
++;
5403 bfa_sm_send_event(vport
, BFA_FCS_VPORT_SM_ONLINE
);
5407 * Offline notification from fabric SM.
5410 bfa_fcs_vport_offline(struct bfa_fcs_vport_s
*vport
)
5412 vport
->vport_stats
.fab_offline
++;
5413 bfa_sm_send_event(vport
, BFA_FCS_VPORT_SM_OFFLINE
);
5417 * Cleanup notification from fabric SM on link timer expiry.
5420 bfa_fcs_vport_cleanup(struct bfa_fcs_vport_s
*vport
)
5422 vport
->vport_stats
.fab_cleanup
++;
5425 * delete notification from fabric SM. To be invoked from within FCS.
5428 bfa_fcs_vport_fcs_delete(struct bfa_fcs_vport_s
*vport
)
5430 bfa_sm_send_event(vport
, BFA_FCS_VPORT_SM_DELETE
);
5434 * Delete completion callback from associated lport
5437 bfa_fcs_vport_delete_comp(struct bfa_fcs_vport_s
*vport
)
5439 bfa_sm_send_event(vport
, BFA_FCS_VPORT_SM_DELCOMP
);
5445 * fcs_vport_api Virtual port API
5449 * Use this function to instantiate a new FCS vport object. This
5450 * function will not trigger any HW initialization process (which will be
5451 * done in vport_start() call)
5453 * param[in] vport - pointer to bfa_fcs_vport_t. This space
5454 * needs to be allocated by the driver.
5455 * param[in] fcs - FCS instance
5456 * param[in] vport_cfg - vport configuration
5457 * param[in] vf_id - VF_ID if vport is created within a VF.
5458 * FC_VF_ID_NULL to specify base fabric.
5459 * param[in] vport_drv - Opaque handle back to the driver's vport
5462 * retval BFA_STATUS_OK - on success.
5463 * retval BFA_STATUS_FAILED - on failure.
5466 bfa_fcs_vport_create(struct bfa_fcs_vport_s
*vport
, struct bfa_fcs_s
*fcs
,
5467 u16 vf_id
, struct bfa_lport_cfg_s
*vport_cfg
,
5468 struct bfad_vport_s
*vport_drv
)
5470 if (vport_cfg
->pwwn
== 0)
5471 return BFA_STATUS_INVALID_WWN
;
5473 if (bfa_fcs_lport_get_pwwn(&fcs
->fabric
.bport
) == vport_cfg
->pwwn
)
5474 return BFA_STATUS_VPORT_WWN_BP
;
5476 if (bfa_fcs_vport_lookup(fcs
, vf_id
, vport_cfg
->pwwn
) != NULL
)
5477 return BFA_STATUS_VPORT_EXISTS
;
5479 if (bfa_fcs_fabric_vport_count(&fcs
->fabric
) ==
5480 bfa_lps_get_max_vport(fcs
->bfa
))
5481 return BFA_STATUS_VPORT_MAX
;
5483 vport
->lps
= bfa_lps_alloc(fcs
->bfa
);
5485 return BFA_STATUS_VPORT_MAX
;
5487 vport
->vport_drv
= vport_drv
;
5488 vport_cfg
->preboot_vp
= BFA_FALSE
;
5490 bfa_sm_set_state(vport
, bfa_fcs_vport_sm_uninit
);
5491 bfa_fcs_lport_attach(&vport
->lport
, fcs
, vf_id
, vport
);
5492 bfa_fcs_lport_init(&vport
->lport
, vport_cfg
);
5493 bfa_sm_send_event(vport
, BFA_FCS_VPORT_SM_CREATE
);
5495 return BFA_STATUS_OK
;
5499 * Use this function to instantiate a new FCS PBC vport object. This
5500 * function will not trigger any HW initialization process (which will be
5501 * done in vport_start() call)
5503 * param[in] vport - pointer to bfa_fcs_vport_t. This space
5504 * needs to be allocated by the driver.
5505 * param[in] fcs - FCS instance
5506 * param[in] vport_cfg - vport configuration
5507 * param[in] vf_id - VF_ID if vport is created within a VF.
5508 * FC_VF_ID_NULL to specify base fabric.
5509 * param[in] vport_drv - Opaque handle back to the driver's vport
5512 * retval BFA_STATUS_OK - on success.
5513 * retval BFA_STATUS_FAILED - on failure.
5516 bfa_fcs_pbc_vport_create(struct bfa_fcs_vport_s
*vport
, struct bfa_fcs_s
*fcs
,
5517 u16 vf_id
, struct bfa_lport_cfg_s
*vport_cfg
,
5518 struct bfad_vport_s
*vport_drv
)
5522 rc
= bfa_fcs_vport_create(vport
, fcs
, vf_id
, vport_cfg
, vport_drv
);
5523 vport
->lport
.port_cfg
.preboot_vp
= BFA_TRUE
;
5529 * Use this function to findout if this is a pbc vport or not.
5531 * @param[in] vport - pointer to bfa_fcs_vport_t.
5536 bfa_fcs_is_pbc_vport(struct bfa_fcs_vport_s
*vport
)
5539 if (vport
&& (vport
->lport
.port_cfg
.preboot_vp
== BFA_TRUE
))
5547 * Use this function initialize the vport.
5549 * @param[in] vport - pointer to bfa_fcs_vport_t.
5554 bfa_fcs_vport_start(struct bfa_fcs_vport_s
*vport
)
5556 bfa_sm_send_event(vport
, BFA_FCS_VPORT_SM_START
);
5558 return BFA_STATUS_OK
;
5562 * Use this function quiese the vport object. This function will return
5563 * immediately, when the vport is actually stopped, the
5564 * bfa_drv_vport_stop_cb() will be called.
5566 * param[in] vport - pointer to bfa_fcs_vport_t.
5571 bfa_fcs_vport_stop(struct bfa_fcs_vport_s
*vport
)
5573 bfa_sm_send_event(vport
, BFA_FCS_VPORT_SM_STOP
);
5575 return BFA_STATUS_OK
;
5579 * Use this function to delete a vport object. Fabric object should
5580 * be stopped before this function call.
5582 * !!!!!!! Donot invoke this from within FCS !!!!!!!
5584 * param[in] vport - pointer to bfa_fcs_vport_t.
5589 bfa_fcs_vport_delete(struct bfa_fcs_vport_s
*vport
)
5592 if (vport
->lport
.port_cfg
.preboot_vp
)
5593 return BFA_STATUS_PBC
;
5595 bfa_sm_send_event(vport
, BFA_FCS_VPORT_SM_DELETE
);
5597 return BFA_STATUS_OK
;
5601 * Use this function to get vport's current status info.
5603 * param[in] vport pointer to bfa_fcs_vport_t.
5604 * param[out] attr pointer to return vport attributes
5609 bfa_fcs_vport_get_attr(struct bfa_fcs_vport_s
*vport
,
5610 struct bfa_vport_attr_s
*attr
)
5612 if (vport
== NULL
|| attr
== NULL
)
5615 memset(attr
, 0, sizeof(struct bfa_vport_attr_s
));
5617 bfa_fcs_lport_get_attr(&vport
->lport
, &attr
->port_attr
);
5618 attr
->vport_state
= bfa_sm_to_state(vport_sm_table
, vport
->sm
);
5622 * Use this function to get vport's statistics.
5624 * param[in] vport pointer to bfa_fcs_vport_t.
5625 * param[out] stats pointer to return vport statistics in
5630 bfa_fcs_vport_get_stats(struct bfa_fcs_vport_s
*vport
,
5631 struct bfa_vport_stats_s
*stats
)
5633 *stats
= vport
->vport_stats
;
5637 * Use this function to clear vport's statistics.
5639 * param[in] vport pointer to bfa_fcs_vport_t.
5644 bfa_fcs_vport_clr_stats(struct bfa_fcs_vport_s
*vport
)
5646 memset(&vport
->vport_stats
, 0, sizeof(struct bfa_vport_stats_s
));
5650 * Lookup a virtual port. Excludes base port from lookup.
5652 struct bfa_fcs_vport_s
*
5653 bfa_fcs_vport_lookup(struct bfa_fcs_s
*fcs
, u16 vf_id
, wwn_t vpwwn
)
5655 struct bfa_fcs_vport_s
*vport
;
5656 struct bfa_fcs_fabric_s
*fabric
;
5658 bfa_trc(fcs
, vf_id
);
5659 bfa_trc(fcs
, vpwwn
);
5661 fabric
= bfa_fcs_vf_lookup(fcs
, vf_id
);
5663 bfa_trc(fcs
, vf_id
);
5667 vport
= bfa_fcs_fabric_vport_lookup(fabric
, vpwwn
);
5675 bfa_cb_lps_fdisc_comp(void *bfad
, void *uarg
, bfa_status_t status
)
5677 struct bfa_fcs_vport_s
*vport
= uarg
;
5679 bfa_trc(__vport_fcs(vport
), __vport_pwwn(vport
));
5680 bfa_trc(__vport_fcs(vport
), status
);
5685 * Initialize the V-Port fields
5687 __vport_fcid(vport
) = bfa_lps_get_pid(vport
->lps
);
5688 vport
->vport_stats
.fdisc_accepts
++;
5689 bfa_sm_send_event(vport
, BFA_FCS_VPORT_SM_RSP_OK
);
5692 case BFA_STATUS_INVALID_MAC
:
5694 vport
->vport_stats
.fdisc_acc_bad
++;
5695 bfa_sm_send_event(vport
, BFA_FCS_VPORT_SM_RSP_ERROR
);
5699 case BFA_STATUS_EPROTOCOL
:
5700 switch (bfa_lps_get_extstatus(vport
->lps
)) {
5701 case BFA_EPROTO_BAD_ACCEPT
:
5702 vport
->vport_stats
.fdisc_acc_bad
++;
5705 case BFA_EPROTO_UNKNOWN_RSP
:
5706 vport
->vport_stats
.fdisc_unknown_rsp
++;
5713 bfa_sm_send_event(vport
, BFA_FCS_VPORT_SM_RSP_ERROR
);
5716 case BFA_STATUS_FABRIC_RJT
:
5717 vport
->vport_stats
.fdisc_rejects
++;
5718 bfa_fcs_vport_fdisc_rejected(vport
);
5722 vport
->vport_stats
.fdisc_rsp_err
++;
5723 bfa_sm_send_event(vport
, BFA_FCS_VPORT_SM_RSP_ERROR
);
5731 bfa_cb_lps_fdisclogo_comp(void *bfad
, void *uarg
)
5733 struct bfa_fcs_vport_s
*vport
= uarg
;
5734 bfa_sm_send_event(vport
, BFA_FCS_VPORT_SM_RSP_OK
);
5738 * Received clear virtual link
5741 bfa_cb_lps_cvl_event(void *bfad
, void *uarg
)
5743 struct bfa_fcs_vport_s
*vport
= uarg
;
5745 /* Send an Offline followed by an ONLINE */
5746 bfa_sm_send_event(vport
, BFA_FCS_VPORT_SM_OFFLINE
);
5747 bfa_sm_send_event(vport
, BFA_FCS_VPORT_SM_ONLINE
);