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.
21 #include "bfa_fcbuild.h"
24 BFA_TRC_FILE(FCS
, PORT
);
26 static void bfa_fcs_lport_send_ls_rjt(struct bfa_fcs_lport_s
*port
,
27 struct fchs_s
*rx_fchs
, u8 reason_code
,
29 static void bfa_fcs_lport_plogi(struct bfa_fcs_lport_s
*port
,
30 struct fchs_s
*rx_fchs
, struct fc_logi_s
*plogi
);
31 static void bfa_fcs_lport_online_actions(struct bfa_fcs_lport_s
*port
);
32 static void bfa_fcs_lport_offline_actions(struct bfa_fcs_lport_s
*port
);
33 static void bfa_fcs_lport_unknown_init(struct bfa_fcs_lport_s
*port
);
34 static void bfa_fcs_lport_unknown_online(struct bfa_fcs_lport_s
*port
);
35 static void bfa_fcs_lport_unknown_offline(struct bfa_fcs_lport_s
*port
);
36 static void bfa_fcs_lport_deleted(struct bfa_fcs_lport_s
*port
);
37 static void bfa_fcs_lport_echo(struct bfa_fcs_lport_s
*port
,
38 struct fchs_s
*rx_fchs
,
39 struct fc_echo_s
*echo
, u16 len
);
40 static void bfa_fcs_lport_rnid(struct bfa_fcs_lport_s
*port
,
41 struct fchs_s
*rx_fchs
,
42 struct fc_rnid_cmd_s
*rnid
, u16 len
);
43 static void bfa_fs_port_get_gen_topo_data(struct bfa_fcs_lport_s
*port
,
44 struct fc_rnid_general_topology_data_s
*gen_topo_data
);
46 static void bfa_fcs_lport_fab_init(struct bfa_fcs_lport_s
*port
);
47 static void bfa_fcs_lport_fab_online(struct bfa_fcs_lport_s
*port
);
48 static void bfa_fcs_lport_fab_offline(struct bfa_fcs_lport_s
*port
);
50 static void bfa_fcs_lport_n2n_init(struct bfa_fcs_lport_s
*port
);
51 static void bfa_fcs_lport_n2n_online(struct bfa_fcs_lport_s
*port
);
52 static void bfa_fcs_lport_n2n_offline(struct bfa_fcs_lport_s
*port
);
55 void (*init
) (struct bfa_fcs_lport_s
*port
);
56 void (*online
) (struct bfa_fcs_lport_s
*port
);
57 void (*offline
) (struct bfa_fcs_lport_s
*port
);
60 bfa_fcs_lport_unknown_init
, bfa_fcs_lport_unknown_online
,
61 bfa_fcs_lport_unknown_offline
}, {
62 bfa_fcs_lport_fab_init
, bfa_fcs_lport_fab_online
,
63 bfa_fcs_lport_fab_offline
}, {
64 bfa_fcs_lport_n2n_init
, bfa_fcs_lport_n2n_online
,
65 bfa_fcs_lport_n2n_offline
},
69 * fcs_port_sm FCS logical port state machine
72 enum bfa_fcs_lport_event
{
73 BFA_FCS_PORT_SM_CREATE
= 1,
74 BFA_FCS_PORT_SM_ONLINE
= 2,
75 BFA_FCS_PORT_SM_OFFLINE
= 3,
76 BFA_FCS_PORT_SM_DELETE
= 4,
77 BFA_FCS_PORT_SM_DELRPORT
= 5,
78 BFA_FCS_PORT_SM_STOP
= 6,
81 static void bfa_fcs_lport_sm_uninit(struct bfa_fcs_lport_s
*port
,
82 enum bfa_fcs_lport_event event
);
83 static void bfa_fcs_lport_sm_init(struct bfa_fcs_lport_s
*port
,
84 enum bfa_fcs_lport_event event
);
85 static void bfa_fcs_lport_sm_online(struct bfa_fcs_lport_s
*port
,
86 enum bfa_fcs_lport_event event
);
87 static void bfa_fcs_lport_sm_offline(struct bfa_fcs_lport_s
*port
,
88 enum bfa_fcs_lport_event event
);
89 static void bfa_fcs_lport_sm_deleting(struct bfa_fcs_lport_s
*port
,
90 enum bfa_fcs_lport_event event
);
91 static void bfa_fcs_lport_sm_stopping(struct bfa_fcs_lport_s
*port
,
92 enum bfa_fcs_lport_event event
);
95 bfa_fcs_lport_sm_uninit(
96 struct bfa_fcs_lport_s
*port
,
97 enum bfa_fcs_lport_event event
)
99 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
100 bfa_trc(port
->fcs
, event
);
103 case BFA_FCS_PORT_SM_CREATE
:
104 bfa_sm_set_state(port
, bfa_fcs_lport_sm_init
);
108 bfa_sm_fault(port
->fcs
, event
);
113 bfa_fcs_lport_sm_init(struct bfa_fcs_lport_s
*port
,
114 enum bfa_fcs_lport_event event
)
116 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
117 bfa_trc(port
->fcs
, event
);
120 case BFA_FCS_PORT_SM_ONLINE
:
121 bfa_sm_set_state(port
, bfa_fcs_lport_sm_online
);
122 bfa_fcs_lport_online_actions(port
);
125 case BFA_FCS_PORT_SM_DELETE
:
126 bfa_sm_set_state(port
, bfa_fcs_lport_sm_uninit
);
127 bfa_fcs_lport_deleted(port
);
130 case BFA_FCS_PORT_SM_STOP
:
131 /* If vport - send completion call back */
133 bfa_fcs_vport_stop_comp(port
->vport
);
135 bfa_wc_down(&(port
->fabric
->stop_wc
));
138 case BFA_FCS_PORT_SM_OFFLINE
:
142 bfa_sm_fault(port
->fcs
, event
);
147 bfa_fcs_lport_sm_online(
148 struct bfa_fcs_lport_s
*port
,
149 enum bfa_fcs_lport_event event
)
151 struct bfa_fcs_rport_s
*rport
;
152 struct list_head
*qe
, *qen
;
154 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
155 bfa_trc(port
->fcs
, event
);
158 case BFA_FCS_PORT_SM_OFFLINE
:
159 bfa_sm_set_state(port
, bfa_fcs_lport_sm_offline
);
160 bfa_fcs_lport_offline_actions(port
);
163 case BFA_FCS_PORT_SM_STOP
:
164 __port_action
[port
->fabric
->fab_type
].offline(port
);
166 if (port
->num_rports
== 0) {
167 bfa_sm_set_state(port
, bfa_fcs_lport_sm_init
);
168 /* If vport - send completion call back */
170 bfa_fcs_vport_stop_comp(port
->vport
);
172 bfa_wc_down(&(port
->fabric
->stop_wc
));
174 bfa_sm_set_state(port
, bfa_fcs_lport_sm_stopping
);
175 list_for_each_safe(qe
, qen
, &port
->rport_q
) {
176 rport
= (struct bfa_fcs_rport_s
*) qe
;
177 bfa_sm_send_event(rport
, RPSM_EVENT_DELETE
);
182 case BFA_FCS_PORT_SM_DELETE
:
184 __port_action
[port
->fabric
->fab_type
].offline(port
);
186 if (port
->num_rports
== 0) {
187 bfa_sm_set_state(port
, bfa_fcs_lport_sm_uninit
);
188 bfa_fcs_lport_deleted(port
);
190 bfa_sm_set_state(port
, bfa_fcs_lport_sm_deleting
);
191 list_for_each_safe(qe
, qen
, &port
->rport_q
) {
192 rport
= (struct bfa_fcs_rport_s
*) qe
;
193 bfa_sm_send_event(rport
, RPSM_EVENT_DELETE
);
198 case BFA_FCS_PORT_SM_DELRPORT
:
202 bfa_sm_fault(port
->fcs
, event
);
207 bfa_fcs_lport_sm_offline(
208 struct bfa_fcs_lport_s
*port
,
209 enum bfa_fcs_lport_event event
)
211 struct bfa_fcs_rport_s
*rport
;
212 struct list_head
*qe
, *qen
;
214 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
215 bfa_trc(port
->fcs
, event
);
218 case BFA_FCS_PORT_SM_ONLINE
:
219 bfa_sm_set_state(port
, bfa_fcs_lport_sm_online
);
220 bfa_fcs_lport_online_actions(port
);
223 case BFA_FCS_PORT_SM_STOP
:
224 if (port
->num_rports
== 0) {
225 bfa_sm_set_state(port
, bfa_fcs_lport_sm_init
);
226 /* If vport - send completion call back */
228 bfa_fcs_vport_stop_comp(port
->vport
);
230 bfa_wc_down(&(port
->fabric
->stop_wc
));
232 bfa_sm_set_state(port
, bfa_fcs_lport_sm_stopping
);
233 list_for_each_safe(qe
, qen
, &port
->rport_q
) {
234 rport
= (struct bfa_fcs_rport_s
*) qe
;
235 bfa_sm_send_event(rport
, RPSM_EVENT_DELETE
);
240 case BFA_FCS_PORT_SM_DELETE
:
241 if (port
->num_rports
== 0) {
242 bfa_sm_set_state(port
, bfa_fcs_lport_sm_uninit
);
243 bfa_fcs_lport_deleted(port
);
245 bfa_sm_set_state(port
, bfa_fcs_lport_sm_deleting
);
246 list_for_each_safe(qe
, qen
, &port
->rport_q
) {
247 rport
= (struct bfa_fcs_rport_s
*) qe
;
248 bfa_sm_send_event(rport
, RPSM_EVENT_DELETE
);
253 case BFA_FCS_PORT_SM_DELRPORT
:
254 case BFA_FCS_PORT_SM_OFFLINE
:
258 bfa_sm_fault(port
->fcs
, event
);
263 bfa_fcs_lport_sm_stopping(struct bfa_fcs_lport_s
*port
,
264 enum bfa_fcs_lport_event event
)
266 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
267 bfa_trc(port
->fcs
, event
);
270 case BFA_FCS_PORT_SM_DELRPORT
:
271 if (port
->num_rports
== 0) {
272 bfa_sm_set_state(port
, bfa_fcs_lport_sm_init
);
273 /* If vport - send completion call back */
275 bfa_fcs_vport_stop_comp(port
->vport
);
277 bfa_wc_down(&(port
->fabric
->stop_wc
));
282 bfa_sm_fault(port
->fcs
, event
);
287 bfa_fcs_lport_sm_deleting(
288 struct bfa_fcs_lport_s
*port
,
289 enum bfa_fcs_lport_event event
)
291 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
292 bfa_trc(port
->fcs
, event
);
295 case BFA_FCS_PORT_SM_DELRPORT
:
296 if (port
->num_rports
== 0) {
297 bfa_sm_set_state(port
, bfa_fcs_lport_sm_uninit
);
298 bfa_fcs_lport_deleted(port
);
303 bfa_sm_fault(port
->fcs
, event
);
312 * Send AEN notification
315 bfa_fcs_lport_aen_post(struct bfa_fcs_lport_s
*port
,
316 enum bfa_lport_aen_event event
)
318 struct bfad_s
*bfad
= (struct bfad_s
*)port
->fabric
->fcs
->bfad
;
319 struct bfa_aen_entry_s
*aen_entry
;
321 bfad_get_aen_entry(bfad
, aen_entry
);
325 aen_entry
->aen_data
.lport
.vf_id
= port
->fabric
->vf_id
;
326 aen_entry
->aen_data
.lport
.roles
= port
->port_cfg
.roles
;
327 aen_entry
->aen_data
.lport
.ppwwn
= bfa_fcs_lport_get_pwwn(
328 bfa_fcs_get_base_port(port
->fcs
));
329 aen_entry
->aen_data
.lport
.lpwwn
= bfa_fcs_lport_get_pwwn(port
);
331 /* Send the AEN notification */
332 bfad_im_post_vendor_event(aen_entry
, bfad
, ++port
->fcs
->fcs_aen_seq
,
333 BFA_AEN_CAT_LPORT
, event
);
340 bfa_fcs_lport_send_ls_rjt(struct bfa_fcs_lport_s
*port
, struct fchs_s
*rx_fchs
,
341 u8 reason_code
, u8 reason_code_expl
)
344 struct bfa_fcxp_s
*fcxp
;
345 struct bfa_rport_s
*bfa_rport
= NULL
;
348 bfa_trc(port
->fcs
, rx_fchs
->d_id
);
349 bfa_trc(port
->fcs
, rx_fchs
->s_id
);
351 fcxp
= bfa_fcs_fcxp_alloc(port
->fcs
, BFA_FALSE
);
355 len
= fc_ls_rjt_build(&fchs
, bfa_fcxp_get_reqbuf(fcxp
),
356 rx_fchs
->s_id
, bfa_fcs_lport_get_fcid(port
),
357 rx_fchs
->ox_id
, reason_code
, reason_code_expl
);
359 bfa_fcxp_send(fcxp
, bfa_rport
, port
->fabric
->vf_id
, port
->lp_tag
,
360 BFA_FALSE
, FC_CLASS_3
, len
, &fchs
, NULL
, NULL
,
368 bfa_fcs_lport_send_fcgs_rjt(struct bfa_fcs_lport_s
*port
,
369 struct fchs_s
*rx_fchs
, u8 reason_code
, u8 reason_code_expl
)
372 struct bfa_fcxp_s
*fcxp
;
373 struct bfa_rport_s
*bfa_rport
= NULL
;
375 struct ct_hdr_s
*rx_cthdr
= (struct ct_hdr_s
*)(rx_fchs
+ 1);
376 struct ct_hdr_s
*ct_hdr
;
378 bfa_trc(port
->fcs
, rx_fchs
->d_id
);
379 bfa_trc(port
->fcs
, rx_fchs
->s_id
);
381 fcxp
= bfa_fcs_fcxp_alloc(port
->fcs
, BFA_FALSE
);
385 ct_hdr
= bfa_fcxp_get_reqbuf(fcxp
);
386 ct_hdr
->gs_type
= rx_cthdr
->gs_type
;
387 ct_hdr
->gs_sub_type
= rx_cthdr
->gs_sub_type
;
389 len
= fc_gs_rjt_build(&fchs
, ct_hdr
, rx_fchs
->s_id
,
390 bfa_fcs_lport_get_fcid(port
),
391 rx_fchs
->ox_id
, reason_code
, reason_code_expl
);
393 bfa_fcxp_send(fcxp
, bfa_rport
, port
->fabric
->vf_id
, port
->lp_tag
,
394 BFA_FALSE
, FC_CLASS_3
, len
, &fchs
, NULL
, NULL
,
399 * Process incoming plogi from a remote port.
402 bfa_fcs_lport_plogi(struct bfa_fcs_lport_s
*port
,
403 struct fchs_s
*rx_fchs
, struct fc_logi_s
*plogi
)
405 struct bfa_fcs_rport_s
*rport
;
407 bfa_trc(port
->fcs
, rx_fchs
->d_id
);
408 bfa_trc(port
->fcs
, rx_fchs
->s_id
);
411 * If min cfg mode is enabled, drop any incoming PLOGIs
413 if (__fcs_min_cfg(port
->fcs
)) {
414 bfa_trc(port
->fcs
, rx_fchs
->s_id
);
418 if (fc_plogi_parse(rx_fchs
) != FC_PARSE_OK
) {
419 bfa_trc(port
->fcs
, rx_fchs
->s_id
);
423 bfa_fcs_lport_send_ls_rjt(port
, rx_fchs
,
424 FC_LS_RJT_RSN_PROTOCOL_ERROR
,
425 FC_LS_RJT_EXP_SPARMS_ERR_OPTIONS
);
430 * Direct Attach P2P mode : verify address assigned by the r-port.
432 if ((!bfa_fcs_fabric_is_switched(port
->fabric
)) &&
433 (memcmp((void *)&bfa_fcs_lport_get_pwwn(port
),
434 (void *)&plogi
->port_name
, sizeof(wwn_t
)) < 0)) {
435 if (BFA_FCS_PID_IS_WKA(rx_fchs
->d_id
)) {
436 /* Address assigned to us cannot be a WKA */
437 bfa_fcs_lport_send_ls_rjt(port
, rx_fchs
,
438 FC_LS_RJT_RSN_PROTOCOL_ERROR
,
439 FC_LS_RJT_EXP_INVALID_NPORT_ID
);
442 port
->pid
= rx_fchs
->d_id
;
443 bfa_lps_set_n2n_pid(port
->fabric
->lps
, rx_fchs
->d_id
);
447 * First, check if we know the device by pwwn.
449 rport
= bfa_fcs_lport_get_rport_by_pwwn(port
, plogi
->port_name
);
452 * Direct Attach P2P mode : handle address assigned by r-port.
454 if ((!bfa_fcs_fabric_is_switched(port
->fabric
)) &&
455 (memcmp((void *)&bfa_fcs_lport_get_pwwn(port
),
456 (void *)&plogi
->port_name
, sizeof(wwn_t
)) < 0)) {
457 port
->pid
= rx_fchs
->d_id
;
458 bfa_lps_set_n2n_pid(port
->fabric
->lps
, rx_fchs
->d_id
);
459 rport
->pid
= rx_fchs
->s_id
;
461 bfa_fcs_rport_plogi(rport
, rx_fchs
, plogi
);
466 * Next, lookup rport by PID.
468 rport
= bfa_fcs_lport_get_rport_by_pid(port
, rx_fchs
->s_id
);
471 * Inbound PLOGI from a new device.
473 bfa_fcs_rport_plogi_create(port
, rx_fchs
, plogi
);
478 * Rport is known only by PID.
482 * This is a different device with the same pid. Old device
483 * disappeared. Send implicit LOGO to old device.
485 WARN_ON(rport
->pwwn
== plogi
->port_name
);
486 bfa_sm_send_event(rport
, RPSM_EVENT_LOGO_IMP
);
489 * Inbound PLOGI from a new device (with old PID).
491 bfa_fcs_rport_plogi_create(port
, rx_fchs
, plogi
);
496 * PLOGI crossing each other.
498 WARN_ON(rport
->pwwn
!= WWN_NULL
);
499 bfa_fcs_rport_plogi(rport
, rx_fchs
, plogi
);
503 * Process incoming ECHO.
504 * Since it does not require a login, it is processed here.
507 bfa_fcs_lport_echo(struct bfa_fcs_lport_s
*port
, struct fchs_s
*rx_fchs
,
508 struct fc_echo_s
*echo
, u16 rx_len
)
511 struct bfa_fcxp_s
*fcxp
;
512 struct bfa_rport_s
*bfa_rport
= NULL
;
515 bfa_trc(port
->fcs
, rx_fchs
->s_id
);
516 bfa_trc(port
->fcs
, rx_fchs
->d_id
);
518 fcxp
= bfa_fcs_fcxp_alloc(port
->fcs
, BFA_FALSE
);
522 len
= fc_ls_acc_build(&fchs
, bfa_fcxp_get_reqbuf(fcxp
),
523 rx_fchs
->s_id
, bfa_fcs_lport_get_fcid(port
),
527 * Copy the payload (if any) from the echo frame
529 pyld_len
= rx_len
- sizeof(struct fchs_s
);
530 bfa_trc(port
->fcs
, rx_len
);
531 bfa_trc(port
->fcs
, pyld_len
);
534 memcpy(((u8
*) bfa_fcxp_get_reqbuf(fcxp
)) +
535 sizeof(struct fc_echo_s
), (echo
+ 1),
536 (pyld_len
- sizeof(struct fc_echo_s
)));
538 bfa_fcxp_send(fcxp
, bfa_rport
, port
->fabric
->vf_id
, port
->lp_tag
,
539 BFA_FALSE
, FC_CLASS_3
, pyld_len
, &fchs
, NULL
, NULL
,
544 * Process incoming RNID.
545 * Since it does not require a login, it is processed here.
548 bfa_fcs_lport_rnid(struct bfa_fcs_lport_s
*port
, struct fchs_s
*rx_fchs
,
549 struct fc_rnid_cmd_s
*rnid
, u16 rx_len
)
551 struct fc_rnid_common_id_data_s common_id_data
;
552 struct fc_rnid_general_topology_data_s gen_topo_data
;
554 struct bfa_fcxp_s
*fcxp
;
555 struct bfa_rport_s
*bfa_rport
= NULL
;
559 bfa_trc(port
->fcs
, rx_fchs
->s_id
);
560 bfa_trc(port
->fcs
, rx_fchs
->d_id
);
561 bfa_trc(port
->fcs
, rx_len
);
563 fcxp
= bfa_fcs_fcxp_alloc(port
->fcs
, BFA_FALSE
);
568 * Check Node Indentification Data Format
569 * We only support General Topology Discovery Format.
570 * For any other requested Data Formats, we return Common Node Id Data
571 * only, as per FC-LS.
573 bfa_trc(port
->fcs
, rnid
->node_id_data_format
);
574 if (rnid
->node_id_data_format
== RNID_NODEID_DATA_FORMAT_DISCOVERY
) {
575 data_format
= RNID_NODEID_DATA_FORMAT_DISCOVERY
;
577 * Get General topology data for this port
579 bfa_fs_port_get_gen_topo_data(port
, &gen_topo_data
);
581 data_format
= RNID_NODEID_DATA_FORMAT_COMMON
;
585 * Copy the Node Id Info
587 common_id_data
.port_name
= bfa_fcs_lport_get_pwwn(port
);
588 common_id_data
.node_name
= bfa_fcs_lport_get_nwwn(port
);
590 len
= fc_rnid_acc_build(&fchs
, bfa_fcxp_get_reqbuf(fcxp
),
591 rx_fchs
->s_id
, bfa_fcs_lport_get_fcid(port
),
592 rx_fchs
->ox_id
, data_format
, &common_id_data
,
595 bfa_fcxp_send(fcxp
, bfa_rport
, port
->fabric
->vf_id
, port
->lp_tag
,
596 BFA_FALSE
, FC_CLASS_3
, len
, &fchs
, NULL
, NULL
,
601 * Fill out General Topolpgy Discovery Data for RNID ELS.
604 bfa_fs_port_get_gen_topo_data(struct bfa_fcs_lport_s
*port
,
605 struct fc_rnid_general_topology_data_s
*gen_topo_data
)
607 memset(gen_topo_data
, 0,
608 sizeof(struct fc_rnid_general_topology_data_s
));
610 gen_topo_data
->asso_type
= cpu_to_be32(RNID_ASSOCIATED_TYPE_HOST
);
611 gen_topo_data
->phy_port_num
= 0; /* @todo */
612 gen_topo_data
->num_attached_nodes
= cpu_to_be32(1);
616 bfa_fcs_lport_online_actions(struct bfa_fcs_lport_s
*port
)
618 struct bfad_s
*bfad
= (struct bfad_s
*)port
->fcs
->bfad
;
619 char lpwwn_buf
[BFA_STRING_32
];
621 bfa_trc(port
->fcs
, port
->fabric
->oper_type
);
623 __port_action
[port
->fabric
->fab_type
].init(port
);
624 __port_action
[port
->fabric
->fab_type
].online(port
);
626 wwn2str(lpwwn_buf
, bfa_fcs_lport_get_pwwn(port
));
627 BFA_LOG(KERN_WARNING
, bfad
, bfa_log_level
,
628 "Logical port online: WWN = %s Role = %s\n",
629 lpwwn_buf
, "Initiator");
630 bfa_fcs_lport_aen_post(port
, BFA_LPORT_AEN_ONLINE
);
632 bfad
->bfad_flags
|= BFAD_PORT_ONLINE
;
636 bfa_fcs_lport_offline_actions(struct bfa_fcs_lport_s
*port
)
638 struct list_head
*qe
, *qen
;
639 struct bfa_fcs_rport_s
*rport
;
640 struct bfad_s
*bfad
= (struct bfad_s
*)port
->fcs
->bfad
;
641 char lpwwn_buf
[BFA_STRING_32
];
643 bfa_trc(port
->fcs
, port
->fabric
->oper_type
);
645 __port_action
[port
->fabric
->fab_type
].offline(port
);
647 wwn2str(lpwwn_buf
, bfa_fcs_lport_get_pwwn(port
));
648 if (bfa_sm_cmp_state(port
->fabric
,
649 bfa_fcs_fabric_sm_online
) == BFA_TRUE
) {
650 BFA_LOG(KERN_WARNING
, bfad
, bfa_log_level
,
651 "Logical port lost fabric connectivity: WWN = %s Role = %s\n",
652 lpwwn_buf
, "Initiator");
653 bfa_fcs_lport_aen_post(port
, BFA_LPORT_AEN_DISCONNECT
);
655 BFA_LOG(KERN_WARNING
, bfad
, bfa_log_level
,
656 "Logical port taken offline: WWN = %s Role = %s\n",
657 lpwwn_buf
, "Initiator");
658 bfa_fcs_lport_aen_post(port
, BFA_LPORT_AEN_OFFLINE
);
661 list_for_each_safe(qe
, qen
, &port
->rport_q
) {
662 rport
= (struct bfa_fcs_rport_s
*) qe
;
663 bfa_sm_send_event(rport
, RPSM_EVENT_LOGO_IMP
);
668 bfa_fcs_lport_unknown_init(struct bfa_fcs_lport_s
*port
)
674 bfa_fcs_lport_unknown_online(struct bfa_fcs_lport_s
*port
)
680 bfa_fcs_lport_unknown_offline(struct bfa_fcs_lport_s
*port
)
686 bfa_fcs_lport_abts_acc(struct bfa_fcs_lport_s
*port
, struct fchs_s
*rx_fchs
)
689 struct bfa_fcxp_s
*fcxp
;
692 bfa_trc(port
->fcs
, rx_fchs
->d_id
);
693 bfa_trc(port
->fcs
, rx_fchs
->s_id
);
695 fcxp
= bfa_fcs_fcxp_alloc(port
->fcs
, BFA_FALSE
);
699 len
= fc_ba_acc_build(&fchs
, bfa_fcxp_get_reqbuf(fcxp
),
700 rx_fchs
->s_id
, bfa_fcs_lport_get_fcid(port
),
703 bfa_fcxp_send(fcxp
, NULL
, port
->fabric
->vf_id
, port
->lp_tag
,
704 BFA_FALSE
, FC_CLASS_3
, len
, &fchs
, NULL
, NULL
,
708 bfa_fcs_lport_deleted(struct bfa_fcs_lport_s
*port
)
710 struct bfad_s
*bfad
= (struct bfad_s
*)port
->fcs
->bfad
;
711 char lpwwn_buf
[BFA_STRING_32
];
713 wwn2str(lpwwn_buf
, bfa_fcs_lport_get_pwwn(port
));
714 BFA_LOG(KERN_INFO
, bfad
, bfa_log_level
,
715 "Logical port deleted: WWN = %s Role = %s\n",
716 lpwwn_buf
, "Initiator");
717 bfa_fcs_lport_aen_post(port
, BFA_LPORT_AEN_DELETE
);
719 /* Base port will be deleted by the OS driver */
721 bfa_fcs_vport_delete_comp(port
->vport
);
723 bfa_wc_down(&port
->fabric
->wc
);
728 * Unsolicited frame receive handling.
731 bfa_fcs_lport_uf_recv(struct bfa_fcs_lport_s
*lport
,
732 struct fchs_s
*fchs
, u16 len
)
734 u32 pid
= fchs
->s_id
;
735 struct bfa_fcs_rport_s
*rport
= NULL
;
736 struct fc_els_cmd_s
*els_cmd
= (struct fc_els_cmd_s
*) (fchs
+ 1);
738 bfa_stats(lport
, uf_recvs
);
739 bfa_trc(lport
->fcs
, fchs
->type
);
741 if (!bfa_fcs_lport_is_online(lport
)) {
742 bfa_stats(lport
, uf_recv_drops
);
747 * First, handle ELSs that donot require a login.
752 if ((fchs
->type
== FC_TYPE_ELS
) &&
753 (els_cmd
->els_code
== FC_ELS_PLOGI
)) {
754 bfa_fcs_lport_plogi(lport
, fchs
, (struct fc_logi_s
*) els_cmd
);
759 * Handle ECHO separately.
761 if ((fchs
->type
== FC_TYPE_ELS
) && (els_cmd
->els_code
== FC_ELS_ECHO
)) {
762 bfa_fcs_lport_echo(lport
, fchs
,
763 (struct fc_echo_s
*)els_cmd
, len
);
768 * Handle RNID separately.
770 if ((fchs
->type
== FC_TYPE_ELS
) && (els_cmd
->els_code
== FC_ELS_RNID
)) {
771 bfa_fcs_lport_rnid(lport
, fchs
,
772 (struct fc_rnid_cmd_s
*) els_cmd
, len
);
776 if (fchs
->type
== FC_TYPE_BLS
) {
777 if ((fchs
->routing
== FC_RTG_BASIC_LINK
) &&
778 (fchs
->cat_info
== FC_CAT_ABTS
))
779 bfa_fcs_lport_abts_acc(lport
, fchs
);
783 if (fchs
->type
== FC_TYPE_SERVICES
) {
785 * Unhandled FC-GS frames. Send a FC-CT Reject
787 bfa_fcs_lport_send_fcgs_rjt(lport
, fchs
, CT_RSN_NOT_SUPP
,
788 CT_NS_EXP_NOADDITIONAL
);
793 * look for a matching remote port ID
795 rport
= bfa_fcs_lport_get_rport_by_pid(lport
, pid
);
797 bfa_trc(rport
->fcs
, fchs
->s_id
);
798 bfa_trc(rport
->fcs
, fchs
->d_id
);
799 bfa_trc(rport
->fcs
, fchs
->type
);
801 bfa_fcs_rport_uf_recv(rport
, fchs
, len
);
806 * Only handles ELS frames for now.
808 if (fchs
->type
!= FC_TYPE_ELS
) {
809 bfa_trc(lport
->fcs
, fchs
->s_id
);
810 bfa_trc(lport
->fcs
, fchs
->d_id
);
811 /* ignore type FC_TYPE_FC_FSS */
812 if (fchs
->type
!= FC_TYPE_FC_FSS
)
813 bfa_sm_fault(lport
->fcs
, fchs
->type
);
817 bfa_trc(lport
->fcs
, els_cmd
->els_code
);
818 if (els_cmd
->els_code
== FC_ELS_RSCN
) {
819 bfa_fcs_lport_scn_process_rscn(lport
, fchs
, len
);
823 if (els_cmd
->els_code
== FC_ELS_LOGO
) {
825 * @todo Handle LOGO frames received.
830 if (els_cmd
->els_code
== FC_ELS_PRLI
) {
832 * @todo Handle PRLI frames received.
838 * Unhandled ELS frames. Send a LS_RJT.
840 bfa_fcs_lport_send_ls_rjt(lport
, fchs
, FC_LS_RJT_RSN_CMD_NOT_SUPP
,
841 FC_LS_RJT_EXP_NO_ADDL_INFO
);
846 * PID based Lookup for a R-Port in the Port R-Port Queue
848 struct bfa_fcs_rport_s
*
849 bfa_fcs_lport_get_rport_by_pid(struct bfa_fcs_lport_s
*port
, u32 pid
)
851 struct bfa_fcs_rport_s
*rport
;
852 struct list_head
*qe
;
854 list_for_each(qe
, &port
->rport_q
) {
855 rport
= (struct bfa_fcs_rport_s
*) qe
;
856 if (rport
->pid
== pid
)
860 bfa_trc(port
->fcs
, pid
);
865 * OLD_PID based Lookup for a R-Port in the Port R-Port Queue
867 struct bfa_fcs_rport_s
*
868 bfa_fcs_lport_get_rport_by_old_pid(struct bfa_fcs_lport_s
*port
, u32 pid
)
870 struct bfa_fcs_rport_s
*rport
;
871 struct list_head
*qe
;
873 list_for_each(qe
, &port
->rport_q
) {
874 rport
= (struct bfa_fcs_rport_s
*) qe
;
875 if (rport
->old_pid
== pid
)
879 bfa_trc(port
->fcs
, pid
);
884 * PWWN based Lookup for a R-Port in the Port R-Port Queue
886 struct bfa_fcs_rport_s
*
887 bfa_fcs_lport_get_rport_by_pwwn(struct bfa_fcs_lport_s
*port
, wwn_t pwwn
)
889 struct bfa_fcs_rport_s
*rport
;
890 struct list_head
*qe
;
892 list_for_each(qe
, &port
->rport_q
) {
893 rport
= (struct bfa_fcs_rport_s
*) qe
;
894 if (wwn_is_equal(rport
->pwwn
, pwwn
))
898 bfa_trc(port
->fcs
, pwwn
);
903 * NWWN based Lookup for a R-Port in the Port R-Port Queue
905 struct bfa_fcs_rport_s
*
906 bfa_fcs_lport_get_rport_by_nwwn(struct bfa_fcs_lport_s
*port
, wwn_t nwwn
)
908 struct bfa_fcs_rport_s
*rport
;
909 struct list_head
*qe
;
911 list_for_each(qe
, &port
->rport_q
) {
912 rport
= (struct bfa_fcs_rport_s
*) qe
;
913 if (wwn_is_equal(rport
->nwwn
, nwwn
))
917 bfa_trc(port
->fcs
, nwwn
);
922 * PWWN & PID based Lookup for a R-Port in the Port R-Port Queue
924 struct bfa_fcs_rport_s
*
925 bfa_fcs_lport_get_rport_by_qualifier(struct bfa_fcs_lport_s
*port
,
928 struct bfa_fcs_rport_s
*rport
;
929 struct list_head
*qe
;
931 list_for_each(qe
, &port
->rport_q
) {
932 rport
= (struct bfa_fcs_rport_s
*) qe
;
933 if (wwn_is_equal(rport
->pwwn
, pwwn
) && rport
->pid
== pid
)
937 bfa_trc(port
->fcs
, pwwn
);
942 * Called by rport module when new rports are discovered.
945 bfa_fcs_lport_add_rport(
946 struct bfa_fcs_lport_s
*port
,
947 struct bfa_fcs_rport_s
*rport
)
949 list_add_tail(&rport
->qe
, &port
->rport_q
);
954 * Called by rport module to when rports are deleted.
957 bfa_fcs_lport_del_rport(
958 struct bfa_fcs_lport_s
*port
,
959 struct bfa_fcs_rport_s
*rport
)
961 WARN_ON(!bfa_q_is_on_q(&port
->rport_q
, rport
));
962 list_del(&rport
->qe
);
965 bfa_sm_send_event(port
, BFA_FCS_PORT_SM_DELRPORT
);
969 * Called by fabric for base port when fabric login is complete.
970 * Called by vport for virtual ports when FDISC is complete.
973 bfa_fcs_lport_online(struct bfa_fcs_lport_s
*port
)
975 bfa_sm_send_event(port
, BFA_FCS_PORT_SM_ONLINE
);
979 * Called by fabric for base port when fabric goes offline.
980 * Called by vport for virtual ports when virtual port becomes offline.
983 bfa_fcs_lport_offline(struct bfa_fcs_lport_s
*port
)
985 bfa_sm_send_event(port
, BFA_FCS_PORT_SM_OFFLINE
);
989 * Called by fabric for base port and by vport for virtual ports
990 * when target mode driver is unloaded.
993 bfa_fcs_lport_stop(struct bfa_fcs_lport_s
*port
)
995 bfa_sm_send_event(port
, BFA_FCS_PORT_SM_STOP
);
999 * Called by fabric to delete base lport and associated resources.
1001 * Called by vport to delete lport and associated resources. Should call
1002 * bfa_fcs_vport_delete_comp() for vports on completion.
1005 bfa_fcs_lport_delete(struct bfa_fcs_lport_s
*port
)
1007 bfa_sm_send_event(port
, BFA_FCS_PORT_SM_DELETE
);
1011 * Return TRUE if port is online, else return FALSE
1014 bfa_fcs_lport_is_online(struct bfa_fcs_lport_s
*port
)
1016 return bfa_sm_cmp_state(port
, bfa_fcs_lport_sm_online
);
1020 * Attach time initialization of logical ports.
1023 bfa_fcs_lport_attach(struct bfa_fcs_lport_s
*lport
, struct bfa_fcs_s
*fcs
,
1024 u16 vf_id
, struct bfa_fcs_vport_s
*vport
)
1027 lport
->fabric
= bfa_fcs_vf_lookup(fcs
, vf_id
);
1028 lport
->vport
= vport
;
1029 lport
->lp_tag
= (vport
) ? vport
->lps
->bfa_tag
:
1030 lport
->fabric
->lps
->bfa_tag
;
1032 INIT_LIST_HEAD(&lport
->rport_q
);
1033 lport
->num_rports
= 0;
1037 * Logical port initialization of base or virtual port.
1038 * Called by fabric for base port or by vport for virtual ports.
1042 bfa_fcs_lport_init(struct bfa_fcs_lport_s
*lport
,
1043 struct bfa_lport_cfg_s
*port_cfg
)
1045 struct bfa_fcs_vport_s
*vport
= lport
->vport
;
1046 struct bfad_s
*bfad
= (struct bfad_s
*)lport
->fcs
->bfad
;
1047 char lpwwn_buf
[BFA_STRING_32
];
1049 lport
->port_cfg
= *port_cfg
;
1051 lport
->bfad_port
= bfa_fcb_lport_new(lport
->fcs
->bfad
, lport
,
1052 lport
->port_cfg
.roles
,
1053 lport
->fabric
->vf_drv
,
1054 vport
? vport
->vport_drv
: NULL
);
1056 wwn2str(lpwwn_buf
, bfa_fcs_lport_get_pwwn(lport
));
1057 BFA_LOG(KERN_INFO
, bfad
, bfa_log_level
,
1058 "New logical port created: WWN = %s Role = %s\n",
1059 lpwwn_buf
, "Initiator");
1060 bfa_fcs_lport_aen_post(lport
, BFA_LPORT_AEN_NEW
);
1062 bfa_sm_set_state(lport
, bfa_fcs_lport_sm_uninit
);
1063 bfa_sm_send_event(lport
, BFA_FCS_PORT_SM_CREATE
);
1071 bfa_fcs_lport_get_attr(
1072 struct bfa_fcs_lport_s
*port
,
1073 struct bfa_lport_attr_s
*port_attr
)
1075 if (bfa_sm_cmp_state(port
, bfa_fcs_lport_sm_online
))
1076 port_attr
->pid
= port
->pid
;
1080 port_attr
->port_cfg
= port
->port_cfg
;
1083 port_attr
->port_type
= port
->fabric
->oper_type
;
1084 port_attr
->loopback
= bfa_sm_cmp_state(port
->fabric
,
1085 bfa_fcs_fabric_sm_loopback
);
1086 port_attr
->authfail
=
1087 bfa_sm_cmp_state(port
->fabric
,
1088 bfa_fcs_fabric_sm_auth_failed
);
1089 port_attr
->fabric_name
= bfa_fcs_lport_get_fabric_name(port
);
1090 memcpy(port_attr
->fabric_ip_addr
,
1091 bfa_fcs_lport_get_fabric_ipaddr(port
),
1092 BFA_FCS_FABRIC_IPADDR_SZ
);
1094 if (port
->vport
!= NULL
) {
1095 port_attr
->port_type
= BFA_PORT_TYPE_VPORT
;
1096 port_attr
->fpma_mac
=
1097 port
->vport
->lps
->lp_mac
;
1099 port_attr
->fpma_mac
=
1100 port
->fabric
->lps
->lp_mac
;
1103 port_attr
->port_type
= BFA_PORT_TYPE_UNKNOWN
;
1104 port_attr
->state
= BFA_LPORT_UNINIT
;
1109 * bfa_fcs_lport_fab port fab functions
1113 * Called by port to initialize fabric services of the base port.
1116 bfa_fcs_lport_fab_init(struct bfa_fcs_lport_s
*port
)
1118 bfa_fcs_lport_ns_init(port
);
1119 bfa_fcs_lport_scn_init(port
);
1120 bfa_fcs_lport_ms_init(port
);
1124 * Called by port to notify transition to online state.
1127 bfa_fcs_lport_fab_online(struct bfa_fcs_lport_s
*port
)
1129 bfa_fcs_lport_ns_online(port
);
1130 bfa_fcs_lport_scn_online(port
);
1134 * Called by port to notify transition to offline state.
1137 bfa_fcs_lport_fab_offline(struct bfa_fcs_lport_s
*port
)
1139 bfa_fcs_lport_ns_offline(port
);
1140 bfa_fcs_lport_scn_offline(port
);
1141 bfa_fcs_lport_ms_offline(port
);
1145 * bfa_fcs_lport_n2n functions
1149 * Called by fcs/port to initialize N2N topology.
1152 bfa_fcs_lport_n2n_init(struct bfa_fcs_lport_s
*port
)
1157 * Called by fcs/port to notify transition to online state.
1160 bfa_fcs_lport_n2n_online(struct bfa_fcs_lport_s
*port
)
1162 struct bfa_fcs_lport_n2n_s
*n2n_port
= &port
->port_topo
.pn2n
;
1163 struct bfa_lport_cfg_s
*pcfg
= &port
->port_cfg
;
1164 struct bfa_fcs_rport_s
*rport
;
1166 bfa_trc(port
->fcs
, pcfg
->pwwn
);
1169 * If our PWWN is > than that of the r-port, we have to initiate PLOGI
1170 * and assign an Address. if not, we need to wait for its PLOGI.
1172 * If our PWWN is < than that of the remote port, it will send a PLOGI
1173 * with the PIDs assigned. The rport state machine take care of this
1177 ((void *)&pcfg
->pwwn
, (void *)&n2n_port
->rem_port_wwn
,
1178 sizeof(wwn_t
)) > 0) {
1179 port
->pid
= N2N_LOCAL_PID
;
1180 bfa_lps_set_n2n_pid(port
->fabric
->lps
, N2N_LOCAL_PID
);
1182 * First, check if we know the device by pwwn.
1184 rport
= bfa_fcs_lport_get_rport_by_pwwn(port
,
1185 n2n_port
->rem_port_wwn
);
1187 bfa_trc(port
->fcs
, rport
->pid
);
1188 bfa_trc(port
->fcs
, rport
->pwwn
);
1189 rport
->pid
= N2N_REMOTE_PID
;
1190 bfa_sm_send_event(rport
, RPSM_EVENT_PLOGI_SEND
);
1195 * In n2n there can be only one rport. Delete the old one
1196 * whose pid should be zero, because it is offline.
1198 if (port
->num_rports
> 0) {
1199 rport
= bfa_fcs_lport_get_rport_by_pid(port
, 0);
1200 WARN_ON(rport
== NULL
);
1202 bfa_trc(port
->fcs
, rport
->pwwn
);
1203 bfa_sm_send_event(rport
, RPSM_EVENT_DELETE
);
1206 bfa_fcs_rport_create(port
, N2N_REMOTE_PID
);
1211 * Called by fcs/port to notify transition to offline state.
1214 bfa_fcs_lport_n2n_offline(struct bfa_fcs_lport_s
*port
)
1216 struct bfa_fcs_lport_n2n_s
*n2n_port
= &port
->port_topo
.pn2n
;
1218 bfa_trc(port
->fcs
, port
->pid
);
1220 n2n_port
->rem_port_wwn
= 0;
1221 n2n_port
->reply_oxid
= 0;
1224 #define BFA_FCS_FDMI_CMD_MAX_RETRIES 2
1227 * forward declarations
1229 static void bfa_fcs_lport_fdmi_send_rhba(void *fdmi_cbarg
,
1230 struct bfa_fcxp_s
*fcxp_alloced
);
1231 static void bfa_fcs_lport_fdmi_send_rprt(void *fdmi_cbarg
,
1232 struct bfa_fcxp_s
*fcxp_alloced
);
1233 static void bfa_fcs_lport_fdmi_send_rpa(void *fdmi_cbarg
,
1234 struct bfa_fcxp_s
*fcxp_alloced
);
1235 static void bfa_fcs_lport_fdmi_rhba_response(void *fcsarg
,
1236 struct bfa_fcxp_s
*fcxp
,
1238 bfa_status_t req_status
,
1241 struct fchs_s
*rsp_fchs
);
1242 static void bfa_fcs_lport_fdmi_rprt_response(void *fcsarg
,
1243 struct bfa_fcxp_s
*fcxp
,
1245 bfa_status_t req_status
,
1248 struct fchs_s
*rsp_fchs
);
1249 static void bfa_fcs_lport_fdmi_rpa_response(void *fcsarg
,
1250 struct bfa_fcxp_s
*fcxp
,
1252 bfa_status_t req_status
,
1255 struct fchs_s
*rsp_fchs
);
1256 static void bfa_fcs_lport_fdmi_timeout(void *arg
);
1257 static u16
bfa_fcs_lport_fdmi_build_rhba_pyld(struct bfa_fcs_lport_fdmi_s
*fdmi
,
1259 static u16
bfa_fcs_lport_fdmi_build_rprt_pyld(struct bfa_fcs_lport_fdmi_s
*fdmi
,
1261 static u16
bfa_fcs_lport_fdmi_build_rpa_pyld(struct bfa_fcs_lport_fdmi_s
*fdmi
,
1263 static u16
bfa_fcs_lport_fdmi_build_portattr_block(struct bfa_fcs_lport_fdmi_s
*
1265 static void bfa_fcs_fdmi_get_hbaattr(struct bfa_fcs_lport_fdmi_s
*fdmi
,
1266 struct bfa_fcs_fdmi_hba_attr_s
*hba_attr
);
1267 static void bfa_fcs_fdmi_get_portattr(struct bfa_fcs_lport_fdmi_s
*fdmi
,
1268 struct bfa_fcs_fdmi_port_attr_s
*port_attr
);
1269 u32
bfa_fcs_fdmi_convert_speed(enum bfa_port_speed pport_speed
);
1272 * fcs_fdmi_sm FCS FDMI state machine
1276 * FDMI State Machine events
1278 enum port_fdmi_event
{
1279 FDMISM_EVENT_PORT_ONLINE
= 1,
1280 FDMISM_EVENT_PORT_OFFLINE
= 2,
1281 FDMISM_EVENT_RSP_OK
= 4,
1282 FDMISM_EVENT_RSP_ERROR
= 5,
1283 FDMISM_EVENT_TIMEOUT
= 6,
1284 FDMISM_EVENT_RHBA_SENT
= 7,
1285 FDMISM_EVENT_RPRT_SENT
= 8,
1286 FDMISM_EVENT_RPA_SENT
= 9,
1289 static void bfa_fcs_lport_fdmi_sm_offline(struct bfa_fcs_lport_fdmi_s
*fdmi
,
1290 enum port_fdmi_event event
);
1291 static void bfa_fcs_lport_fdmi_sm_sending_rhba(
1292 struct bfa_fcs_lport_fdmi_s
*fdmi
,
1293 enum port_fdmi_event event
);
1294 static void bfa_fcs_lport_fdmi_sm_rhba(struct bfa_fcs_lport_fdmi_s
*fdmi
,
1295 enum port_fdmi_event event
);
1296 static void bfa_fcs_lport_fdmi_sm_rhba_retry(
1297 struct bfa_fcs_lport_fdmi_s
*fdmi
,
1298 enum port_fdmi_event event
);
1299 static void bfa_fcs_lport_fdmi_sm_sending_rprt(
1300 struct bfa_fcs_lport_fdmi_s
*fdmi
,
1301 enum port_fdmi_event event
);
1302 static void bfa_fcs_lport_fdmi_sm_rprt(struct bfa_fcs_lport_fdmi_s
*fdmi
,
1303 enum port_fdmi_event event
);
1304 static void bfa_fcs_lport_fdmi_sm_rprt_retry(
1305 struct bfa_fcs_lport_fdmi_s
*fdmi
,
1306 enum port_fdmi_event event
);
1307 static void bfa_fcs_lport_fdmi_sm_sending_rpa(
1308 struct bfa_fcs_lport_fdmi_s
*fdmi
,
1309 enum port_fdmi_event event
);
1310 static void bfa_fcs_lport_fdmi_sm_rpa(struct bfa_fcs_lport_fdmi_s
*fdmi
,
1311 enum port_fdmi_event event
);
1312 static void bfa_fcs_lport_fdmi_sm_rpa_retry(
1313 struct bfa_fcs_lport_fdmi_s
*fdmi
,
1314 enum port_fdmi_event event
);
1315 static void bfa_fcs_lport_fdmi_sm_online(struct bfa_fcs_lport_fdmi_s
*fdmi
,
1316 enum port_fdmi_event event
);
1317 static void bfa_fcs_lport_fdmi_sm_disabled(
1318 struct bfa_fcs_lport_fdmi_s
*fdmi
,
1319 enum port_fdmi_event event
);
1321 * Start in offline state - awaiting MS to send start.
1324 bfa_fcs_lport_fdmi_sm_offline(struct bfa_fcs_lport_fdmi_s
*fdmi
,
1325 enum port_fdmi_event event
)
1327 struct bfa_fcs_lport_s
*port
= fdmi
->ms
->port
;
1329 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
1330 bfa_trc(port
->fcs
, event
);
1332 fdmi
->retry_cnt
= 0;
1335 case FDMISM_EVENT_PORT_ONLINE
:
1338 * For Vports, register a new port.
1340 bfa_sm_set_state(fdmi
,
1341 bfa_fcs_lport_fdmi_sm_sending_rprt
);
1342 bfa_fcs_lport_fdmi_send_rprt(fdmi
, NULL
);
1345 * For a base port, we should first register the HBA
1346 * attribute. The HBA attribute also contains the base
1347 * port registration.
1349 bfa_sm_set_state(fdmi
,
1350 bfa_fcs_lport_fdmi_sm_sending_rhba
);
1351 bfa_fcs_lport_fdmi_send_rhba(fdmi
, NULL
);
1355 case FDMISM_EVENT_PORT_OFFLINE
:
1359 bfa_sm_fault(port
->fcs
, event
);
1364 bfa_fcs_lport_fdmi_sm_sending_rhba(struct bfa_fcs_lport_fdmi_s
*fdmi
,
1365 enum port_fdmi_event event
)
1367 struct bfa_fcs_lport_s
*port
= fdmi
->ms
->port
;
1369 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
1370 bfa_trc(port
->fcs
, event
);
1373 case FDMISM_EVENT_RHBA_SENT
:
1374 bfa_sm_set_state(fdmi
, bfa_fcs_lport_fdmi_sm_rhba
);
1377 case FDMISM_EVENT_PORT_OFFLINE
:
1378 bfa_sm_set_state(fdmi
, bfa_fcs_lport_fdmi_sm_offline
);
1379 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(port
),
1384 bfa_sm_fault(port
->fcs
, event
);
1389 bfa_fcs_lport_fdmi_sm_rhba(struct bfa_fcs_lport_fdmi_s
*fdmi
,
1390 enum port_fdmi_event event
)
1392 struct bfa_fcs_lport_s
*port
= fdmi
->ms
->port
;
1394 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
1395 bfa_trc(port
->fcs
, event
);
1398 case FDMISM_EVENT_RSP_ERROR
:
1400 * if max retries have not been reached, start timer for a
1403 if (fdmi
->retry_cnt
++ < BFA_FCS_FDMI_CMD_MAX_RETRIES
) {
1404 bfa_sm_set_state(fdmi
,
1405 bfa_fcs_lport_fdmi_sm_rhba_retry
);
1406 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(port
),
1408 bfa_fcs_lport_fdmi_timeout
, fdmi
,
1409 BFA_FCS_RETRY_TIMEOUT
);
1412 * set state to offline
1414 bfa_sm_set_state(fdmi
, bfa_fcs_lport_fdmi_sm_offline
);
1418 case FDMISM_EVENT_RSP_OK
:
1420 * Initiate Register Port Attributes
1422 bfa_sm_set_state(fdmi
, bfa_fcs_lport_fdmi_sm_sending_rpa
);
1423 fdmi
->retry_cnt
= 0;
1424 bfa_fcs_lport_fdmi_send_rpa(fdmi
, NULL
);
1427 case FDMISM_EVENT_PORT_OFFLINE
:
1428 bfa_fcxp_discard(fdmi
->fcxp
);
1429 bfa_sm_set_state(fdmi
, bfa_fcs_lport_fdmi_sm_offline
);
1433 bfa_sm_fault(port
->fcs
, event
);
1438 bfa_fcs_lport_fdmi_sm_rhba_retry(struct bfa_fcs_lport_fdmi_s
*fdmi
,
1439 enum port_fdmi_event event
)
1441 struct bfa_fcs_lport_s
*port
= fdmi
->ms
->port
;
1443 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
1444 bfa_trc(port
->fcs
, event
);
1447 case FDMISM_EVENT_TIMEOUT
:
1449 * Retry Timer Expired. Re-send
1451 bfa_sm_set_state(fdmi
, bfa_fcs_lport_fdmi_sm_sending_rhba
);
1452 bfa_fcs_lport_fdmi_send_rhba(fdmi
, NULL
);
1455 case FDMISM_EVENT_PORT_OFFLINE
:
1456 bfa_sm_set_state(fdmi
, bfa_fcs_lport_fdmi_sm_offline
);
1457 bfa_timer_stop(&fdmi
->timer
);
1461 bfa_sm_fault(port
->fcs
, event
);
1466 * RPRT : Register Port
1469 bfa_fcs_lport_fdmi_sm_sending_rprt(struct bfa_fcs_lport_fdmi_s
*fdmi
,
1470 enum port_fdmi_event event
)
1472 struct bfa_fcs_lport_s
*port
= fdmi
->ms
->port
;
1474 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
1475 bfa_trc(port
->fcs
, event
);
1478 case FDMISM_EVENT_RPRT_SENT
:
1479 bfa_sm_set_state(fdmi
, bfa_fcs_lport_fdmi_sm_rprt
);
1482 case FDMISM_EVENT_PORT_OFFLINE
:
1483 bfa_sm_set_state(fdmi
, bfa_fcs_lport_fdmi_sm_offline
);
1484 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(port
),
1489 bfa_sm_fault(port
->fcs
, event
);
1494 bfa_fcs_lport_fdmi_sm_rprt(struct bfa_fcs_lport_fdmi_s
*fdmi
,
1495 enum port_fdmi_event event
)
1497 struct bfa_fcs_lport_s
*port
= fdmi
->ms
->port
;
1499 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
1500 bfa_trc(port
->fcs
, event
);
1503 case FDMISM_EVENT_RSP_ERROR
:
1505 * if max retries have not been reached, start timer for a
1508 if (fdmi
->retry_cnt
++ < BFA_FCS_FDMI_CMD_MAX_RETRIES
) {
1509 bfa_sm_set_state(fdmi
,
1510 bfa_fcs_lport_fdmi_sm_rprt_retry
);
1511 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(port
),
1513 bfa_fcs_lport_fdmi_timeout
, fdmi
,
1514 BFA_FCS_RETRY_TIMEOUT
);
1518 * set state to offline
1520 bfa_sm_set_state(fdmi
, bfa_fcs_lport_fdmi_sm_offline
);
1521 fdmi
->retry_cnt
= 0;
1525 case FDMISM_EVENT_RSP_OK
:
1526 fdmi
->retry_cnt
= 0;
1527 bfa_sm_set_state(fdmi
, bfa_fcs_lport_fdmi_sm_online
);
1530 case FDMISM_EVENT_PORT_OFFLINE
:
1531 bfa_fcxp_discard(fdmi
->fcxp
);
1532 bfa_sm_set_state(fdmi
, bfa_fcs_lport_fdmi_sm_offline
);
1536 bfa_sm_fault(port
->fcs
, event
);
1541 bfa_fcs_lport_fdmi_sm_rprt_retry(struct bfa_fcs_lport_fdmi_s
*fdmi
,
1542 enum port_fdmi_event event
)
1544 struct bfa_fcs_lport_s
*port
= fdmi
->ms
->port
;
1546 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
1547 bfa_trc(port
->fcs
, event
);
1550 case FDMISM_EVENT_TIMEOUT
:
1552 * Retry Timer Expired. Re-send
1554 bfa_sm_set_state(fdmi
, bfa_fcs_lport_fdmi_sm_sending_rprt
);
1555 bfa_fcs_lport_fdmi_send_rprt(fdmi
, NULL
);
1558 case FDMISM_EVENT_PORT_OFFLINE
:
1559 bfa_sm_set_state(fdmi
, bfa_fcs_lport_fdmi_sm_offline
);
1560 bfa_timer_stop(&fdmi
->timer
);
1564 bfa_sm_fault(port
->fcs
, event
);
1569 * Register Port Attributes
1572 bfa_fcs_lport_fdmi_sm_sending_rpa(struct bfa_fcs_lport_fdmi_s
*fdmi
,
1573 enum port_fdmi_event event
)
1575 struct bfa_fcs_lport_s
*port
= fdmi
->ms
->port
;
1577 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
1578 bfa_trc(port
->fcs
, event
);
1581 case FDMISM_EVENT_RPA_SENT
:
1582 bfa_sm_set_state(fdmi
, bfa_fcs_lport_fdmi_sm_rpa
);
1585 case FDMISM_EVENT_PORT_OFFLINE
:
1586 bfa_sm_set_state(fdmi
, bfa_fcs_lport_fdmi_sm_offline
);
1587 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(port
),
1592 bfa_sm_fault(port
->fcs
, event
);
1597 bfa_fcs_lport_fdmi_sm_rpa(struct bfa_fcs_lport_fdmi_s
*fdmi
,
1598 enum port_fdmi_event event
)
1600 struct bfa_fcs_lport_s
*port
= fdmi
->ms
->port
;
1602 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
1603 bfa_trc(port
->fcs
, event
);
1606 case FDMISM_EVENT_RSP_ERROR
:
1608 * if max retries have not been reached, start timer for a
1611 if (fdmi
->retry_cnt
++ < BFA_FCS_FDMI_CMD_MAX_RETRIES
) {
1612 bfa_sm_set_state(fdmi
, bfa_fcs_lport_fdmi_sm_rpa_retry
);
1613 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(port
),
1615 bfa_fcs_lport_fdmi_timeout
, fdmi
,
1616 BFA_FCS_RETRY_TIMEOUT
);
1619 * set state to offline
1621 bfa_sm_set_state(fdmi
, bfa_fcs_lport_fdmi_sm_offline
);
1622 fdmi
->retry_cnt
= 0;
1626 case FDMISM_EVENT_RSP_OK
:
1627 bfa_sm_set_state(fdmi
, bfa_fcs_lport_fdmi_sm_online
);
1628 fdmi
->retry_cnt
= 0;
1631 case FDMISM_EVENT_PORT_OFFLINE
:
1632 bfa_fcxp_discard(fdmi
->fcxp
);
1633 bfa_sm_set_state(fdmi
, bfa_fcs_lport_fdmi_sm_offline
);
1637 bfa_sm_fault(port
->fcs
, event
);
1642 bfa_fcs_lport_fdmi_sm_rpa_retry(struct bfa_fcs_lport_fdmi_s
*fdmi
,
1643 enum port_fdmi_event event
)
1645 struct bfa_fcs_lport_s
*port
= fdmi
->ms
->port
;
1647 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
1648 bfa_trc(port
->fcs
, event
);
1651 case FDMISM_EVENT_TIMEOUT
:
1653 * Retry Timer Expired. Re-send
1655 bfa_sm_set_state(fdmi
, bfa_fcs_lport_fdmi_sm_sending_rpa
);
1656 bfa_fcs_lport_fdmi_send_rpa(fdmi
, NULL
);
1659 case FDMISM_EVENT_PORT_OFFLINE
:
1660 bfa_sm_set_state(fdmi
, bfa_fcs_lport_fdmi_sm_offline
);
1661 bfa_timer_stop(&fdmi
->timer
);
1665 bfa_sm_fault(port
->fcs
, event
);
1670 bfa_fcs_lport_fdmi_sm_online(struct bfa_fcs_lport_fdmi_s
*fdmi
,
1671 enum port_fdmi_event event
)
1673 struct bfa_fcs_lport_s
*port
= fdmi
->ms
->port
;
1675 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
1676 bfa_trc(port
->fcs
, event
);
1679 case FDMISM_EVENT_PORT_OFFLINE
:
1680 bfa_sm_set_state(fdmi
, bfa_fcs_lport_fdmi_sm_offline
);
1684 bfa_sm_fault(port
->fcs
, event
);
1688 * FDMI is disabled state.
1691 bfa_fcs_lport_fdmi_sm_disabled(struct bfa_fcs_lport_fdmi_s
*fdmi
,
1692 enum port_fdmi_event event
)
1694 struct bfa_fcs_lport_s
*port
= fdmi
->ms
->port
;
1696 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
1697 bfa_trc(port
->fcs
, event
);
1699 /* No op State. It can only be enabled at Driver Init. */
1703 * RHBA : Register HBA Attributes.
1706 bfa_fcs_lport_fdmi_send_rhba(void *fdmi_cbarg
, struct bfa_fcxp_s
*fcxp_alloced
)
1708 struct bfa_fcs_lport_fdmi_s
*fdmi
= fdmi_cbarg
;
1709 struct bfa_fcs_lport_s
*port
= fdmi
->ms
->port
;
1712 struct bfa_fcxp_s
*fcxp
;
1715 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
1717 fcxp
= fcxp_alloced
? fcxp_alloced
:
1718 bfa_fcs_fcxp_alloc(port
->fcs
, BFA_TRUE
);
1720 bfa_fcs_fcxp_alloc_wait(port
->fcs
->bfa
, &fdmi
->fcxp_wqe
,
1721 bfa_fcs_lport_fdmi_send_rhba
, fdmi
, BFA_TRUE
);
1726 pyld
= bfa_fcxp_get_reqbuf(fcxp
);
1727 memset(pyld
, 0, FC_MAX_PDUSZ
);
1729 len
= fc_fdmi_reqhdr_build(&fchs
, pyld
, bfa_fcs_lport_get_fcid(port
),
1733 bfa_fcs_lport_fdmi_build_rhba_pyld(fdmi
,
1734 (u8
*) ((struct ct_hdr_s
*) pyld
1737 bfa_fcxp_send(fcxp
, NULL
, port
->fabric
->vf_id
, port
->lp_tag
, BFA_FALSE
,
1738 FC_CLASS_3
, (len
+ attr_len
), &fchs
,
1739 bfa_fcs_lport_fdmi_rhba_response
, (void *)fdmi
,
1740 FC_MAX_PDUSZ
, FC_FCCT_TOV
);
1742 bfa_sm_send_event(fdmi
, FDMISM_EVENT_RHBA_SENT
);
1746 bfa_fcs_lport_fdmi_build_rhba_pyld(struct bfa_fcs_lport_fdmi_s
*fdmi
, u8
*pyld
)
1748 struct bfa_fcs_lport_s
*port
= fdmi
->ms
->port
;
1749 struct bfa_fcs_fdmi_hba_attr_s hba_attr
;
1750 struct bfa_fcs_fdmi_hba_attr_s
*fcs_hba_attr
= &hba_attr
;
1751 struct fdmi_rhba_s
*rhba
= (struct fdmi_rhba_s
*) pyld
;
1752 struct fdmi_attr_s
*attr
;
1758 * get hba attributes
1760 bfa_fcs_fdmi_get_hbaattr(fdmi
, fcs_hba_attr
);
1762 rhba
->hba_id
= bfa_fcs_lport_get_pwwn(port
);
1763 rhba
->port_list
.num_ports
= cpu_to_be32(1);
1764 rhba
->port_list
.port_entry
= bfa_fcs_lport_get_pwwn(port
);
1766 len
= sizeof(rhba
->hba_id
) + sizeof(rhba
->port_list
);
1769 len
+= sizeof(rhba
->hba_attr_blk
.attr_count
);
1772 * fill out the invididual entries of the HBA attrib Block
1774 curr_ptr
= (u8
*) &rhba
->hba_attr_blk
.hba_attr
;
1779 attr
= (struct fdmi_attr_s
*) curr_ptr
;
1780 attr
->type
= cpu_to_be16(FDMI_HBA_ATTRIB_NODENAME
);
1781 templen
= sizeof(wwn_t
);
1782 memcpy(attr
->value
, &bfa_fcs_lport_get_nwwn(port
), templen
);
1783 curr_ptr
+= sizeof(attr
->type
) + sizeof(templen
) + templen
;
1786 attr
->len
= cpu_to_be16(templen
+ sizeof(attr
->type
) +
1792 attr
= (struct fdmi_attr_s
*) curr_ptr
;
1793 attr
->type
= cpu_to_be16(FDMI_HBA_ATTRIB_MANUFACTURER
);
1794 templen
= (u16
) strlen(fcs_hba_attr
->manufacturer
);
1795 memcpy(attr
->value
, fcs_hba_attr
->manufacturer
, templen
);
1796 templen
= fc_roundup(templen
, sizeof(u32
));
1797 curr_ptr
+= sizeof(attr
->type
) + sizeof(templen
) + templen
;
1800 attr
->len
= cpu_to_be16(templen
+ sizeof(attr
->type
) +
1806 attr
= (struct fdmi_attr_s
*) curr_ptr
;
1807 attr
->type
= cpu_to_be16(FDMI_HBA_ATTRIB_SERIALNUM
);
1808 templen
= (u16
) strlen(fcs_hba_attr
->serial_num
);
1809 memcpy(attr
->value
, fcs_hba_attr
->serial_num
, templen
);
1810 templen
= fc_roundup(templen
, sizeof(u32
));
1811 curr_ptr
+= sizeof(attr
->type
) + sizeof(templen
) + templen
;
1814 attr
->len
= cpu_to_be16(templen
+ sizeof(attr
->type
) +
1820 attr
= (struct fdmi_attr_s
*) curr_ptr
;
1821 attr
->type
= cpu_to_be16(FDMI_HBA_ATTRIB_MODEL
);
1822 templen
= (u16
) strlen(fcs_hba_attr
->model
);
1823 memcpy(attr
->value
, fcs_hba_attr
->model
, templen
);
1824 templen
= fc_roundup(templen
, sizeof(u32
));
1825 curr_ptr
+= sizeof(attr
->type
) + sizeof(templen
) + templen
;
1828 attr
->len
= cpu_to_be16(templen
+ sizeof(attr
->type
) +
1834 attr
= (struct fdmi_attr_s
*) curr_ptr
;
1835 attr
->type
= cpu_to_be16(FDMI_HBA_ATTRIB_MODEL_DESC
);
1836 templen
= (u16
) strlen(fcs_hba_attr
->model_desc
);
1837 memcpy(attr
->value
, fcs_hba_attr
->model_desc
, templen
);
1838 templen
= fc_roundup(templen
, sizeof(u32
));
1839 curr_ptr
+= sizeof(attr
->type
) + sizeof(templen
) + templen
;
1842 attr
->len
= cpu_to_be16(templen
+ sizeof(attr
->type
) +
1848 if (fcs_hba_attr
->hw_version
[0] != '\0') {
1849 attr
= (struct fdmi_attr_s
*) curr_ptr
;
1850 attr
->type
= cpu_to_be16(FDMI_HBA_ATTRIB_HW_VERSION
);
1851 templen
= (u16
) strlen(fcs_hba_attr
->hw_version
);
1852 memcpy(attr
->value
, fcs_hba_attr
->hw_version
, templen
);
1853 templen
= fc_roundup(templen
, sizeof(u32
));
1854 curr_ptr
+= sizeof(attr
->type
) + sizeof(templen
) + templen
;
1857 attr
->len
= cpu_to_be16(templen
+ sizeof(attr
->type
) +
1864 attr
= (struct fdmi_attr_s
*) curr_ptr
;
1865 attr
->type
= cpu_to_be16(FDMI_HBA_ATTRIB_DRIVER_VERSION
);
1866 templen
= (u16
) strlen(fcs_hba_attr
->driver_version
);
1867 memcpy(attr
->value
, fcs_hba_attr
->driver_version
, templen
);
1868 templen
= fc_roundup(templen
, sizeof(u32
));
1869 curr_ptr
+= sizeof(attr
->type
) + sizeof(templen
) + templen
;
1872 attr
->len
= cpu_to_be16(templen
+ sizeof(attr
->type
) +
1876 * Option Rom Version
1878 if (fcs_hba_attr
->option_rom_ver
[0] != '\0') {
1879 attr
= (struct fdmi_attr_s
*) curr_ptr
;
1880 attr
->type
= cpu_to_be16(FDMI_HBA_ATTRIB_ROM_VERSION
);
1881 templen
= (u16
) strlen(fcs_hba_attr
->option_rom_ver
);
1882 memcpy(attr
->value
, fcs_hba_attr
->option_rom_ver
, templen
);
1883 templen
= fc_roundup(templen
, sizeof(u32
));
1884 curr_ptr
+= sizeof(attr
->type
) + sizeof(templen
) + templen
;
1887 attr
->len
= cpu_to_be16(templen
+ sizeof(attr
->type
) +
1892 * f/w Version = driver version
1894 attr
= (struct fdmi_attr_s
*) curr_ptr
;
1895 attr
->type
= cpu_to_be16(FDMI_HBA_ATTRIB_FW_VERSION
);
1896 templen
= (u16
) strlen(fcs_hba_attr
->driver_version
);
1897 memcpy(attr
->value
, fcs_hba_attr
->driver_version
, templen
);
1898 templen
= fc_roundup(templen
, sizeof(u32
));
1899 curr_ptr
+= sizeof(attr
->type
) + sizeof(templen
) + templen
;
1902 attr
->len
= cpu_to_be16(templen
+ sizeof(attr
->type
) +
1908 if (fcs_hba_attr
->os_name
[0] != '\0') {
1909 attr
= (struct fdmi_attr_s
*) curr_ptr
;
1910 attr
->type
= cpu_to_be16(FDMI_HBA_ATTRIB_OS_NAME
);
1911 templen
= (u16
) strlen(fcs_hba_attr
->os_name
);
1912 memcpy(attr
->value
, fcs_hba_attr
->os_name
, templen
);
1913 templen
= fc_roundup(templen
, sizeof(u32
));
1914 curr_ptr
+= sizeof(attr
->type
) + sizeof(templen
) + templen
;
1917 attr
->len
= cpu_to_be16(templen
+ sizeof(attr
->type
) +
1924 attr
= (struct fdmi_attr_s
*) curr_ptr
;
1925 attr
->type
= cpu_to_be16(FDMI_HBA_ATTRIB_MAX_CT
);
1926 templen
= sizeof(fcs_hba_attr
->max_ct_pyld
);
1927 memcpy(attr
->value
, &fcs_hba_attr
->max_ct_pyld
, templen
);
1930 attr
->len
= cpu_to_be16(templen
+ sizeof(attr
->type
) +
1934 * Update size of payload
1936 len
+= ((sizeof(attr
->type
) + sizeof(attr
->len
)) * count
);
1938 rhba
->hba_attr_blk
.attr_count
= cpu_to_be32(count
);
1943 bfa_fcs_lport_fdmi_rhba_response(void *fcsarg
, struct bfa_fcxp_s
*fcxp
,
1944 void *cbarg
, bfa_status_t req_status
,
1945 u32 rsp_len
, u32 resid_len
,
1946 struct fchs_s
*rsp_fchs
)
1948 struct bfa_fcs_lport_fdmi_s
*fdmi
=
1949 (struct bfa_fcs_lport_fdmi_s
*) cbarg
;
1950 struct bfa_fcs_lport_s
*port
= fdmi
->ms
->port
;
1951 struct ct_hdr_s
*cthdr
= NULL
;
1953 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
1958 if (req_status
!= BFA_STATUS_OK
) {
1959 bfa_trc(port
->fcs
, req_status
);
1960 bfa_sm_send_event(fdmi
, FDMISM_EVENT_RSP_ERROR
);
1964 cthdr
= (struct ct_hdr_s
*) BFA_FCXP_RSP_PLD(fcxp
);
1965 cthdr
->cmd_rsp_code
= be16_to_cpu(cthdr
->cmd_rsp_code
);
1967 if (cthdr
->cmd_rsp_code
== CT_RSP_ACCEPT
) {
1968 bfa_sm_send_event(fdmi
, FDMISM_EVENT_RSP_OK
);
1972 bfa_trc(port
->fcs
, cthdr
->reason_code
);
1973 bfa_trc(port
->fcs
, cthdr
->exp_code
);
1974 bfa_sm_send_event(fdmi
, FDMISM_EVENT_RSP_ERROR
);
1978 * RPRT : Register Port
1981 bfa_fcs_lport_fdmi_send_rprt(void *fdmi_cbarg
, struct bfa_fcxp_s
*fcxp_alloced
)
1983 struct bfa_fcs_lport_fdmi_s
*fdmi
= fdmi_cbarg
;
1984 struct bfa_fcs_lport_s
*port
= fdmi
->ms
->port
;
1987 struct bfa_fcxp_s
*fcxp
;
1990 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
1992 fcxp
= fcxp_alloced
? fcxp_alloced
:
1993 bfa_fcs_fcxp_alloc(port
->fcs
, BFA_TRUE
);
1995 bfa_fcs_fcxp_alloc_wait(port
->fcs
->bfa
, &fdmi
->fcxp_wqe
,
1996 bfa_fcs_lport_fdmi_send_rprt
, fdmi
, BFA_TRUE
);
2001 pyld
= bfa_fcxp_get_reqbuf(fcxp
);
2002 memset(pyld
, 0, FC_MAX_PDUSZ
);
2004 len
= fc_fdmi_reqhdr_build(&fchs
, pyld
, bfa_fcs_lport_get_fcid(port
),
2008 bfa_fcs_lport_fdmi_build_rprt_pyld(fdmi
,
2009 (u8
*) ((struct ct_hdr_s
*) pyld
2012 bfa_fcxp_send(fcxp
, NULL
, port
->fabric
->vf_id
, port
->lp_tag
, BFA_FALSE
,
2013 FC_CLASS_3
, len
+ attr_len
, &fchs
,
2014 bfa_fcs_lport_fdmi_rprt_response
, (void *)fdmi
,
2015 FC_MAX_PDUSZ
, FC_FCCT_TOV
);
2017 bfa_sm_send_event(fdmi
, FDMISM_EVENT_RPRT_SENT
);
2021 * This routine builds Port Attribute Block that used in RPA, RPRT commands.
2024 bfa_fcs_lport_fdmi_build_portattr_block(struct bfa_fcs_lport_fdmi_s
*fdmi
,
2027 struct bfa_fcs_fdmi_port_attr_s fcs_port_attr
;
2028 struct fdmi_port_attr_s
*port_attrib
= (struct fdmi_port_attr_s
*) pyld
;
2029 struct fdmi_attr_s
*attr
;
2036 * get port attributes
2038 bfa_fcs_fdmi_get_portattr(fdmi
, &fcs_port_attr
);
2040 len
= sizeof(port_attrib
->attr_count
);
2043 * fill out the invididual entries
2045 curr_ptr
= (u8
*) &port_attrib
->port_attr
;
2050 attr
= (struct fdmi_attr_s
*) curr_ptr
;
2051 attr
->type
= cpu_to_be16(FDMI_PORT_ATTRIB_FC4_TYPES
);
2052 templen
= sizeof(fcs_port_attr
.supp_fc4_types
);
2053 memcpy(attr
->value
, fcs_port_attr
.supp_fc4_types
, templen
);
2054 curr_ptr
+= sizeof(attr
->type
) + sizeof(templen
) + templen
;
2058 cpu_to_be16(templen
+ sizeof(attr
->type
) +
2064 attr
= (struct fdmi_attr_s
*) curr_ptr
;
2065 attr
->type
= cpu_to_be16(FDMI_PORT_ATTRIB_SUPP_SPEED
);
2066 templen
= sizeof(fcs_port_attr
.supp_speed
);
2067 memcpy(attr
->value
, &fcs_port_attr
.supp_speed
, templen
);
2068 curr_ptr
+= sizeof(attr
->type
) + sizeof(templen
) + templen
;
2072 cpu_to_be16(templen
+ sizeof(attr
->type
) +
2076 * current Port Speed
2078 attr
= (struct fdmi_attr_s
*) curr_ptr
;
2079 attr
->type
= cpu_to_be16(FDMI_PORT_ATTRIB_PORT_SPEED
);
2080 templen
= sizeof(fcs_port_attr
.curr_speed
);
2081 memcpy(attr
->value
, &fcs_port_attr
.curr_speed
, templen
);
2082 curr_ptr
+= sizeof(attr
->type
) + sizeof(templen
) + templen
;
2085 attr
->len
= cpu_to_be16(templen
+ sizeof(attr
->type
) +
2091 attr
= (struct fdmi_attr_s
*) curr_ptr
;
2092 attr
->type
= cpu_to_be16(FDMI_PORT_ATTRIB_FRAME_SIZE
);
2093 templen
= sizeof(fcs_port_attr
.max_frm_size
);
2094 memcpy(attr
->value
, &fcs_port_attr
.max_frm_size
, templen
);
2095 curr_ptr
+= sizeof(attr
->type
) + sizeof(templen
) + templen
;
2098 attr
->len
= cpu_to_be16(templen
+ sizeof(attr
->type
) +
2104 if (fcs_port_attr
.os_device_name
[0] != '\0') {
2105 attr
= (struct fdmi_attr_s
*) curr_ptr
;
2106 attr
->type
= cpu_to_be16(FDMI_PORT_ATTRIB_DEV_NAME
);
2107 templen
= (u16
) strlen(fcs_port_attr
.os_device_name
);
2108 memcpy(attr
->value
, fcs_port_attr
.os_device_name
, templen
);
2109 templen
= fc_roundup(templen
, sizeof(u32
));
2110 curr_ptr
+= sizeof(attr
->type
) + sizeof(templen
) + templen
;
2113 attr
->len
= cpu_to_be16(templen
+ sizeof(attr
->type
) +
2119 if (fcs_port_attr
.host_name
[0] != '\0') {
2120 attr
= (struct fdmi_attr_s
*) curr_ptr
;
2121 attr
->type
= cpu_to_be16(FDMI_PORT_ATTRIB_HOST_NAME
);
2122 templen
= (u16
) strlen(fcs_port_attr
.host_name
);
2123 memcpy(attr
->value
, fcs_port_attr
.host_name
, templen
);
2124 templen
= fc_roundup(templen
, sizeof(u32
));
2125 curr_ptr
+= sizeof(attr
->type
) + sizeof(templen
) + templen
;
2128 attr
->len
= cpu_to_be16(templen
+ sizeof(attr
->type
) +
2133 * Update size of payload
2135 port_attrib
->attr_count
= cpu_to_be32(count
);
2136 len
+= ((sizeof(attr
->type
) + sizeof(attr
->len
)) * count
);
2141 bfa_fcs_lport_fdmi_build_rprt_pyld(struct bfa_fcs_lport_fdmi_s
*fdmi
, u8
*pyld
)
2143 struct bfa_fcs_lport_s
*port
= fdmi
->ms
->port
;
2144 struct fdmi_rprt_s
*rprt
= (struct fdmi_rprt_s
*) pyld
;
2147 rprt
->hba_id
= bfa_fcs_lport_get_pwwn(bfa_fcs_get_base_port(port
->fcs
));
2148 rprt
->port_name
= bfa_fcs_lport_get_pwwn(port
);
2150 len
= bfa_fcs_lport_fdmi_build_portattr_block(fdmi
,
2151 (u8
*) &rprt
->port_attr_blk
);
2153 len
+= sizeof(rprt
->hba_id
) + sizeof(rprt
->port_name
);
2159 bfa_fcs_lport_fdmi_rprt_response(void *fcsarg
, struct bfa_fcxp_s
*fcxp
,
2160 void *cbarg
, bfa_status_t req_status
,
2161 u32 rsp_len
, u32 resid_len
,
2162 struct fchs_s
*rsp_fchs
)
2164 struct bfa_fcs_lport_fdmi_s
*fdmi
=
2165 (struct bfa_fcs_lport_fdmi_s
*) cbarg
;
2166 struct bfa_fcs_lport_s
*port
= fdmi
->ms
->port
;
2167 struct ct_hdr_s
*cthdr
= NULL
;
2169 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
2174 if (req_status
!= BFA_STATUS_OK
) {
2175 bfa_trc(port
->fcs
, req_status
);
2176 bfa_sm_send_event(fdmi
, FDMISM_EVENT_RSP_ERROR
);
2180 cthdr
= (struct ct_hdr_s
*) BFA_FCXP_RSP_PLD(fcxp
);
2181 cthdr
->cmd_rsp_code
= be16_to_cpu(cthdr
->cmd_rsp_code
);
2183 if (cthdr
->cmd_rsp_code
== CT_RSP_ACCEPT
) {
2184 bfa_sm_send_event(fdmi
, FDMISM_EVENT_RSP_OK
);
2188 bfa_trc(port
->fcs
, cthdr
->reason_code
);
2189 bfa_trc(port
->fcs
, cthdr
->exp_code
);
2190 bfa_sm_send_event(fdmi
, FDMISM_EVENT_RSP_ERROR
);
2194 * RPA : Register Port Attributes.
2197 bfa_fcs_lport_fdmi_send_rpa(void *fdmi_cbarg
, struct bfa_fcxp_s
*fcxp_alloced
)
2199 struct bfa_fcs_lport_fdmi_s
*fdmi
= fdmi_cbarg
;
2200 struct bfa_fcs_lport_s
*port
= fdmi
->ms
->port
;
2203 struct bfa_fcxp_s
*fcxp
;
2206 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
2208 fcxp
= fcxp_alloced
? fcxp_alloced
:
2209 bfa_fcs_fcxp_alloc(port
->fcs
, BFA_TRUE
);
2211 bfa_fcs_fcxp_alloc_wait(port
->fcs
->bfa
, &fdmi
->fcxp_wqe
,
2212 bfa_fcs_lport_fdmi_send_rpa
, fdmi
, BFA_TRUE
);
2217 pyld
= bfa_fcxp_get_reqbuf(fcxp
);
2218 memset(pyld
, 0, FC_MAX_PDUSZ
);
2220 len
= fc_fdmi_reqhdr_build(&fchs
, pyld
, bfa_fcs_lport_get_fcid(port
),
2223 attr_len
= bfa_fcs_lport_fdmi_build_rpa_pyld(fdmi
,
2224 (u8
*) ((struct ct_hdr_s
*) pyld
+ 1));
2226 bfa_fcxp_send(fcxp
, NULL
, port
->fabric
->vf_id
, port
->lp_tag
, BFA_FALSE
,
2227 FC_CLASS_3
, len
+ attr_len
, &fchs
,
2228 bfa_fcs_lport_fdmi_rpa_response
, (void *)fdmi
,
2229 FC_MAX_PDUSZ
, FC_FCCT_TOV
);
2231 bfa_sm_send_event(fdmi
, FDMISM_EVENT_RPA_SENT
);
2235 bfa_fcs_lport_fdmi_build_rpa_pyld(struct bfa_fcs_lport_fdmi_s
*fdmi
, u8
*pyld
)
2237 struct bfa_fcs_lport_s
*port
= fdmi
->ms
->port
;
2238 struct fdmi_rpa_s
*rpa
= (struct fdmi_rpa_s
*) pyld
;
2241 rpa
->port_name
= bfa_fcs_lport_get_pwwn(port
);
2243 len
= bfa_fcs_lport_fdmi_build_portattr_block(fdmi
,
2244 (u8
*) &rpa
->port_attr_blk
);
2246 len
+= sizeof(rpa
->port_name
);
2252 bfa_fcs_lport_fdmi_rpa_response(void *fcsarg
, struct bfa_fcxp_s
*fcxp
,
2253 void *cbarg
, bfa_status_t req_status
, u32 rsp_len
,
2254 u32 resid_len
, struct fchs_s
*rsp_fchs
)
2256 struct bfa_fcs_lport_fdmi_s
*fdmi
=
2257 (struct bfa_fcs_lport_fdmi_s
*) cbarg
;
2258 struct bfa_fcs_lport_s
*port
= fdmi
->ms
->port
;
2259 struct ct_hdr_s
*cthdr
= NULL
;
2261 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
2266 if (req_status
!= BFA_STATUS_OK
) {
2267 bfa_trc(port
->fcs
, req_status
);
2268 bfa_sm_send_event(fdmi
, FDMISM_EVENT_RSP_ERROR
);
2272 cthdr
= (struct ct_hdr_s
*) BFA_FCXP_RSP_PLD(fcxp
);
2273 cthdr
->cmd_rsp_code
= be16_to_cpu(cthdr
->cmd_rsp_code
);
2275 if (cthdr
->cmd_rsp_code
== CT_RSP_ACCEPT
) {
2276 bfa_sm_send_event(fdmi
, FDMISM_EVENT_RSP_OK
);
2280 bfa_trc(port
->fcs
, cthdr
->reason_code
);
2281 bfa_trc(port
->fcs
, cthdr
->exp_code
);
2282 bfa_sm_send_event(fdmi
, FDMISM_EVENT_RSP_ERROR
);
2286 bfa_fcs_lport_fdmi_timeout(void *arg
)
2288 struct bfa_fcs_lport_fdmi_s
*fdmi
= (struct bfa_fcs_lport_fdmi_s
*) arg
;
2290 bfa_sm_send_event(fdmi
, FDMISM_EVENT_TIMEOUT
);
2294 bfa_fcs_fdmi_get_hbaattr(struct bfa_fcs_lport_fdmi_s
*fdmi
,
2295 struct bfa_fcs_fdmi_hba_attr_s
*hba_attr
)
2297 struct bfa_fcs_lport_s
*port
= fdmi
->ms
->port
;
2298 struct bfa_fcs_driver_info_s
*driver_info
= &port
->fcs
->driver_info
;
2300 memset(hba_attr
, 0, sizeof(struct bfa_fcs_fdmi_hba_attr_s
));
2302 bfa_ioc_get_adapter_manufacturer(&port
->fcs
->bfa
->ioc
,
2303 hba_attr
->manufacturer
);
2304 bfa_ioc_get_adapter_serial_num(&port
->fcs
->bfa
->ioc
,
2305 hba_attr
->serial_num
);
2306 bfa_ioc_get_adapter_model(&port
->fcs
->bfa
->ioc
,
2308 bfa_ioc_get_adapter_model(&port
->fcs
->bfa
->ioc
,
2309 hba_attr
->model_desc
);
2310 bfa_ioc_get_pci_chip_rev(&port
->fcs
->bfa
->ioc
,
2311 hba_attr
->hw_version
);
2312 bfa_ioc_get_adapter_optrom_ver(&port
->fcs
->bfa
->ioc
,
2313 hba_attr
->option_rom_ver
);
2314 bfa_ioc_get_adapter_fw_ver(&port
->fcs
->bfa
->ioc
,
2315 hba_attr
->fw_version
);
2317 strncpy(hba_attr
->driver_version
, (char *)driver_info
->version
,
2318 sizeof(hba_attr
->driver_version
));
2320 strncpy(hba_attr
->os_name
, driver_info
->host_os_name
,
2321 sizeof(hba_attr
->os_name
));
2324 * If there is a patch level, append it
2325 * to the os name along with a separator
2327 if (driver_info
->host_os_patch
[0] != '\0') {
2328 strncat(hba_attr
->os_name
, BFA_FCS_PORT_SYMBNAME_SEPARATOR
,
2329 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR
));
2330 strncat(hba_attr
->os_name
, driver_info
->host_os_patch
,
2331 sizeof(driver_info
->host_os_patch
));
2334 hba_attr
->max_ct_pyld
= cpu_to_be32(FC_MAX_PDUSZ
);
2338 bfa_fcs_fdmi_get_portattr(struct bfa_fcs_lport_fdmi_s
*fdmi
,
2339 struct bfa_fcs_fdmi_port_attr_s
*port_attr
)
2341 struct bfa_fcs_lport_s
*port
= fdmi
->ms
->port
;
2342 struct bfa_fcs_driver_info_s
*driver_info
= &port
->fcs
->driver_info
;
2343 struct bfa_port_attr_s pport_attr
;
2345 memset(port_attr
, 0, sizeof(struct bfa_fcs_fdmi_port_attr_s
));
2348 * get pport attributes from hal
2350 bfa_fcport_get_attr(port
->fcs
->bfa
, &pport_attr
);
2353 * get FC4 type Bitmask
2355 fc_get_fc4type_bitmask(FC_TYPE_FCP
, port_attr
->supp_fc4_types
);
2360 switch (pport_attr
.speed_supported
) {
2361 case BFA_PORT_SPEED_16GBPS
:
2362 port_attr
->supp_speed
=
2363 cpu_to_be32(BFA_FCS_FDMI_SUPP_SPEEDS_16G
);
2366 case BFA_PORT_SPEED_10GBPS
:
2367 port_attr
->supp_speed
=
2368 cpu_to_be32(BFA_FCS_FDMI_SUPP_SPEEDS_10G
);
2371 case BFA_PORT_SPEED_8GBPS
:
2372 port_attr
->supp_speed
=
2373 cpu_to_be32(BFA_FCS_FDMI_SUPP_SPEEDS_8G
);
2376 case BFA_PORT_SPEED_4GBPS
:
2377 port_attr
->supp_speed
=
2378 cpu_to_be32(BFA_FCS_FDMI_SUPP_SPEEDS_4G
);
2382 bfa_sm_fault(port
->fcs
, pport_attr
.speed_supported
);
2388 port_attr
->curr_speed
= cpu_to_be32(
2389 bfa_fcs_fdmi_convert_speed(pport_attr
.speed
));
2394 port_attr
->max_frm_size
= cpu_to_be32(FC_MAX_PDUSZ
);
2399 strncpy(port_attr
->os_device_name
, (char *)driver_info
->os_device_name
,
2400 sizeof(port_attr
->os_device_name
));
2405 strncpy(port_attr
->host_name
, (char *)driver_info
->host_machine_name
,
2406 sizeof(port_attr
->host_name
));
2411 * Convert BFA speed to FDMI format.
2414 bfa_fcs_fdmi_convert_speed(bfa_port_speed_t pport_speed
)
2418 switch (pport_speed
) {
2419 case BFA_PORT_SPEED_1GBPS
:
2420 case BFA_PORT_SPEED_2GBPS
:
2424 case BFA_PORT_SPEED_4GBPS
:
2425 ret
= FDMI_TRANS_SPEED_4G
;
2428 case BFA_PORT_SPEED_8GBPS
:
2429 ret
= FDMI_TRANS_SPEED_8G
;
2432 case BFA_PORT_SPEED_10GBPS
:
2433 ret
= FDMI_TRANS_SPEED_10G
;
2436 case BFA_PORT_SPEED_16GBPS
:
2437 ret
= FDMI_TRANS_SPEED_16G
;
2441 ret
= FDMI_TRANS_SPEED_UNKNOWN
;
2447 bfa_fcs_lport_fdmi_init(struct bfa_fcs_lport_ms_s
*ms
)
2449 struct bfa_fcs_lport_fdmi_s
*fdmi
= &ms
->fdmi
;
2452 if (ms
->port
->fcs
->fdmi_enabled
)
2453 bfa_sm_set_state(fdmi
, bfa_fcs_lport_fdmi_sm_offline
);
2455 bfa_sm_set_state(fdmi
, bfa_fcs_lport_fdmi_sm_disabled
);
2459 bfa_fcs_lport_fdmi_offline(struct bfa_fcs_lport_ms_s
*ms
)
2461 struct bfa_fcs_lport_fdmi_s
*fdmi
= &ms
->fdmi
;
2464 bfa_sm_send_event(fdmi
, FDMISM_EVENT_PORT_OFFLINE
);
2468 bfa_fcs_lport_fdmi_online(struct bfa_fcs_lport_ms_s
*ms
)
2470 struct bfa_fcs_lport_fdmi_s
*fdmi
= &ms
->fdmi
;
2473 bfa_sm_send_event(fdmi
, FDMISM_EVENT_PORT_ONLINE
);
2476 #define BFA_FCS_MS_CMD_MAX_RETRIES 2
2479 * forward declarations
2481 static void bfa_fcs_lport_ms_send_plogi(void *ms_cbarg
,
2482 struct bfa_fcxp_s
*fcxp_alloced
);
2483 static void bfa_fcs_lport_ms_timeout(void *arg
);
2484 static void bfa_fcs_lport_ms_plogi_response(void *fcsarg
,
2485 struct bfa_fcxp_s
*fcxp
,
2487 bfa_status_t req_status
,
2490 struct fchs_s
*rsp_fchs
);
2492 static void bfa_fcs_lport_ms_send_gmal(void *ms_cbarg
,
2493 struct bfa_fcxp_s
*fcxp_alloced
);
2494 static void bfa_fcs_lport_ms_gmal_response(void *fcsarg
,
2495 struct bfa_fcxp_s
*fcxp
,
2497 bfa_status_t req_status
,
2500 struct fchs_s
*rsp_fchs
);
2501 static void bfa_fcs_lport_ms_send_gfn(void *ms_cbarg
,
2502 struct bfa_fcxp_s
*fcxp_alloced
);
2503 static void bfa_fcs_lport_ms_gfn_response(void *fcsarg
,
2504 struct bfa_fcxp_s
*fcxp
,
2506 bfa_status_t req_status
,
2509 struct fchs_s
*rsp_fchs
);
2511 * fcs_ms_sm FCS MS state machine
2515 * MS State Machine events
2517 enum port_ms_event
{
2518 MSSM_EVENT_PORT_ONLINE
= 1,
2519 MSSM_EVENT_PORT_OFFLINE
= 2,
2520 MSSM_EVENT_RSP_OK
= 3,
2521 MSSM_EVENT_RSP_ERROR
= 4,
2522 MSSM_EVENT_TIMEOUT
= 5,
2523 MSSM_EVENT_FCXP_SENT
= 6,
2524 MSSM_EVENT_PORT_FABRIC_RSCN
= 7
2527 static void bfa_fcs_lport_ms_sm_offline(struct bfa_fcs_lport_ms_s
*ms
,
2528 enum port_ms_event event
);
2529 static void bfa_fcs_lport_ms_sm_plogi_sending(struct bfa_fcs_lport_ms_s
*ms
,
2530 enum port_ms_event event
);
2531 static void bfa_fcs_lport_ms_sm_plogi(struct bfa_fcs_lport_ms_s
*ms
,
2532 enum port_ms_event event
);
2533 static void bfa_fcs_lport_ms_sm_plogi_retry(struct bfa_fcs_lport_ms_s
*ms
,
2534 enum port_ms_event event
);
2535 static void bfa_fcs_lport_ms_sm_gmal_sending(struct bfa_fcs_lport_ms_s
*ms
,
2536 enum port_ms_event event
);
2537 static void bfa_fcs_lport_ms_sm_gmal(struct bfa_fcs_lport_ms_s
*ms
,
2538 enum port_ms_event event
);
2539 static void bfa_fcs_lport_ms_sm_gmal_retry(struct bfa_fcs_lport_ms_s
*ms
,
2540 enum port_ms_event event
);
2541 static void bfa_fcs_lport_ms_sm_gfn_sending(struct bfa_fcs_lport_ms_s
*ms
,
2542 enum port_ms_event event
);
2543 static void bfa_fcs_lport_ms_sm_gfn(struct bfa_fcs_lport_ms_s
*ms
,
2544 enum port_ms_event event
);
2545 static void bfa_fcs_lport_ms_sm_gfn_retry(struct bfa_fcs_lport_ms_s
*ms
,
2546 enum port_ms_event event
);
2547 static void bfa_fcs_lport_ms_sm_online(struct bfa_fcs_lport_ms_s
*ms
,
2548 enum port_ms_event event
);
2550 * Start in offline state - awaiting NS to send start.
2553 bfa_fcs_lport_ms_sm_offline(struct bfa_fcs_lport_ms_s
*ms
,
2554 enum port_ms_event event
)
2556 bfa_trc(ms
->port
->fcs
, ms
->port
->port_cfg
.pwwn
);
2557 bfa_trc(ms
->port
->fcs
, event
);
2560 case MSSM_EVENT_PORT_ONLINE
:
2561 bfa_sm_set_state(ms
, bfa_fcs_lport_ms_sm_plogi_sending
);
2562 bfa_fcs_lport_ms_send_plogi(ms
, NULL
);
2565 case MSSM_EVENT_PORT_OFFLINE
:
2569 bfa_sm_fault(ms
->port
->fcs
, event
);
2574 bfa_fcs_lport_ms_sm_plogi_sending(struct bfa_fcs_lport_ms_s
*ms
,
2575 enum port_ms_event event
)
2577 bfa_trc(ms
->port
->fcs
, ms
->port
->port_cfg
.pwwn
);
2578 bfa_trc(ms
->port
->fcs
, event
);
2581 case MSSM_EVENT_FCXP_SENT
:
2582 bfa_sm_set_state(ms
, bfa_fcs_lport_ms_sm_plogi
);
2585 case MSSM_EVENT_PORT_OFFLINE
:
2586 bfa_sm_set_state(ms
, bfa_fcs_lport_ms_sm_offline
);
2587 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ms
->port
),
2592 bfa_sm_fault(ms
->port
->fcs
, event
);
2597 bfa_fcs_lport_ms_sm_plogi(struct bfa_fcs_lport_ms_s
*ms
,
2598 enum port_ms_event event
)
2600 bfa_trc(ms
->port
->fcs
, ms
->port
->port_cfg
.pwwn
);
2601 bfa_trc(ms
->port
->fcs
, event
);
2604 case MSSM_EVENT_RSP_ERROR
:
2606 * Start timer for a delayed retry
2608 bfa_sm_set_state(ms
, bfa_fcs_lport_ms_sm_plogi_retry
);
2609 ms
->port
->stats
.ms_retries
++;
2610 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ms
->port
),
2611 &ms
->timer
, bfa_fcs_lport_ms_timeout
, ms
,
2612 BFA_FCS_RETRY_TIMEOUT
);
2615 case MSSM_EVENT_RSP_OK
:
2617 * since plogi is done, now invoke MS related sub-modules
2619 bfa_fcs_lport_fdmi_online(ms
);
2622 * if this is a Vport, go to online state.
2624 if (ms
->port
->vport
) {
2625 bfa_sm_set_state(ms
, bfa_fcs_lport_ms_sm_online
);
2630 * For a base port we need to get the
2631 * switch's IP address.
2633 bfa_sm_set_state(ms
, bfa_fcs_lport_ms_sm_gmal_sending
);
2634 bfa_fcs_lport_ms_send_gmal(ms
, NULL
);
2637 case MSSM_EVENT_PORT_OFFLINE
:
2638 bfa_sm_set_state(ms
, bfa_fcs_lport_ms_sm_offline
);
2639 bfa_fcxp_discard(ms
->fcxp
);
2643 bfa_sm_fault(ms
->port
->fcs
, event
);
2648 bfa_fcs_lport_ms_sm_plogi_retry(struct bfa_fcs_lport_ms_s
*ms
,
2649 enum port_ms_event event
)
2651 bfa_trc(ms
->port
->fcs
, ms
->port
->port_cfg
.pwwn
);
2652 bfa_trc(ms
->port
->fcs
, event
);
2655 case MSSM_EVENT_TIMEOUT
:
2657 * Retry Timer Expired. Re-send
2659 bfa_sm_set_state(ms
, bfa_fcs_lport_ms_sm_plogi_sending
);
2660 bfa_fcs_lport_ms_send_plogi(ms
, NULL
);
2663 case MSSM_EVENT_PORT_OFFLINE
:
2664 bfa_sm_set_state(ms
, bfa_fcs_lport_ms_sm_offline
);
2665 bfa_timer_stop(&ms
->timer
);
2669 bfa_sm_fault(ms
->port
->fcs
, event
);
2674 bfa_fcs_lport_ms_sm_online(struct bfa_fcs_lport_ms_s
*ms
,
2675 enum port_ms_event event
)
2677 bfa_trc(ms
->port
->fcs
, ms
->port
->port_cfg
.pwwn
);
2678 bfa_trc(ms
->port
->fcs
, event
);
2681 case MSSM_EVENT_PORT_OFFLINE
:
2682 bfa_sm_set_state(ms
, bfa_fcs_lport_ms_sm_offline
);
2685 case MSSM_EVENT_PORT_FABRIC_RSCN
:
2686 bfa_sm_set_state(ms
, bfa_fcs_lport_ms_sm_gfn_sending
);
2688 bfa_fcs_lport_ms_send_gfn(ms
, NULL
);
2692 bfa_sm_fault(ms
->port
->fcs
, event
);
2697 bfa_fcs_lport_ms_sm_gmal_sending(struct bfa_fcs_lport_ms_s
*ms
,
2698 enum port_ms_event event
)
2700 bfa_trc(ms
->port
->fcs
, ms
->port
->port_cfg
.pwwn
);
2701 bfa_trc(ms
->port
->fcs
, event
);
2704 case MSSM_EVENT_FCXP_SENT
:
2705 bfa_sm_set_state(ms
, bfa_fcs_lport_ms_sm_gmal
);
2708 case MSSM_EVENT_PORT_OFFLINE
:
2709 bfa_sm_set_state(ms
, bfa_fcs_lport_ms_sm_offline
);
2710 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ms
->port
),
2715 bfa_sm_fault(ms
->port
->fcs
, event
);
2720 bfa_fcs_lport_ms_sm_gmal(struct bfa_fcs_lport_ms_s
*ms
,
2721 enum port_ms_event event
)
2723 bfa_trc(ms
->port
->fcs
, ms
->port
->port_cfg
.pwwn
);
2724 bfa_trc(ms
->port
->fcs
, event
);
2727 case MSSM_EVENT_RSP_ERROR
:
2729 * Start timer for a delayed retry
2731 if (ms
->retry_cnt
++ < BFA_FCS_MS_CMD_MAX_RETRIES
) {
2732 bfa_sm_set_state(ms
, bfa_fcs_lport_ms_sm_gmal_retry
);
2733 ms
->port
->stats
.ms_retries
++;
2734 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ms
->port
),
2735 &ms
->timer
, bfa_fcs_lport_ms_timeout
, ms
,
2736 BFA_FCS_RETRY_TIMEOUT
);
2738 bfa_sm_set_state(ms
, bfa_fcs_lport_ms_sm_gfn_sending
);
2739 bfa_fcs_lport_ms_send_gfn(ms
, NULL
);
2744 case MSSM_EVENT_RSP_OK
:
2745 bfa_sm_set_state(ms
, bfa_fcs_lport_ms_sm_gfn_sending
);
2746 bfa_fcs_lport_ms_send_gfn(ms
, NULL
);
2749 case MSSM_EVENT_PORT_OFFLINE
:
2750 bfa_sm_set_state(ms
, bfa_fcs_lport_ms_sm_offline
);
2751 bfa_fcxp_discard(ms
->fcxp
);
2755 bfa_sm_fault(ms
->port
->fcs
, event
);
2760 bfa_fcs_lport_ms_sm_gmal_retry(struct bfa_fcs_lport_ms_s
*ms
,
2761 enum port_ms_event event
)
2763 bfa_trc(ms
->port
->fcs
, ms
->port
->port_cfg
.pwwn
);
2764 bfa_trc(ms
->port
->fcs
, event
);
2767 case MSSM_EVENT_TIMEOUT
:
2769 * Retry Timer Expired. Re-send
2771 bfa_sm_set_state(ms
, bfa_fcs_lport_ms_sm_gmal_sending
);
2772 bfa_fcs_lport_ms_send_gmal(ms
, NULL
);
2775 case MSSM_EVENT_PORT_OFFLINE
:
2776 bfa_sm_set_state(ms
, bfa_fcs_lport_ms_sm_offline
);
2777 bfa_timer_stop(&ms
->timer
);
2781 bfa_sm_fault(ms
->port
->fcs
, event
);
2785 * ms_pvt MS local functions
2789 bfa_fcs_lport_ms_send_gmal(void *ms_cbarg
, struct bfa_fcxp_s
*fcxp_alloced
)
2791 struct bfa_fcs_lport_ms_s
*ms
= ms_cbarg
;
2792 bfa_fcs_lport_t
*port
= ms
->port
;
2795 struct bfa_fcxp_s
*fcxp
;
2797 bfa_trc(port
->fcs
, port
->pid
);
2799 fcxp
= fcxp_alloced
? fcxp_alloced
:
2800 bfa_fcs_fcxp_alloc(port
->fcs
, BFA_TRUE
);
2802 bfa_fcs_fcxp_alloc_wait(port
->fcs
->bfa
, &ms
->fcxp_wqe
,
2803 bfa_fcs_lport_ms_send_gmal
, ms
, BFA_TRUE
);
2808 len
= fc_gmal_req_build(&fchs
, bfa_fcxp_get_reqbuf(fcxp
),
2809 bfa_fcs_lport_get_fcid(port
),
2810 port
->fabric
->lps
->pr_nwwn
);
2812 bfa_fcxp_send(fcxp
, NULL
, port
->fabric
->vf_id
, port
->lp_tag
, BFA_FALSE
,
2813 FC_CLASS_3
, len
, &fchs
,
2814 bfa_fcs_lport_ms_gmal_response
, (void *)ms
,
2815 FC_MAX_PDUSZ
, FC_FCCT_TOV
);
2817 bfa_sm_send_event(ms
, MSSM_EVENT_FCXP_SENT
);
2821 bfa_fcs_lport_ms_gmal_response(void *fcsarg
, struct bfa_fcxp_s
*fcxp
,
2822 void *cbarg
, bfa_status_t req_status
,
2823 u32 rsp_len
, u32 resid_len
,
2824 struct fchs_s
*rsp_fchs
)
2826 struct bfa_fcs_lport_ms_s
*ms
= (struct bfa_fcs_lport_ms_s
*) cbarg
;
2827 bfa_fcs_lport_t
*port
= ms
->port
;
2828 struct ct_hdr_s
*cthdr
= NULL
;
2829 struct fcgs_gmal_resp_s
*gmal_resp
;
2830 struct fcgs_gmal_entry_s
*gmal_entry
;
2834 bfa_trc(port
->fcs
, req_status
);
2835 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
2840 if (req_status
!= BFA_STATUS_OK
) {
2841 bfa_trc(port
->fcs
, req_status
);
2842 bfa_sm_send_event(ms
, MSSM_EVENT_RSP_ERROR
);
2846 cthdr
= (struct ct_hdr_s
*) BFA_FCXP_RSP_PLD(fcxp
);
2847 cthdr
->cmd_rsp_code
= be16_to_cpu(cthdr
->cmd_rsp_code
);
2849 if (cthdr
->cmd_rsp_code
== CT_RSP_ACCEPT
) {
2850 gmal_resp
= (struct fcgs_gmal_resp_s
*)(cthdr
+ 1);
2852 num_entries
= be32_to_cpu(gmal_resp
->ms_len
);
2853 if (num_entries
== 0) {
2854 bfa_sm_send_event(ms
, MSSM_EVENT_RSP_ERROR
);
2858 * The response could contain multiple Entries.
2859 * Entries for SNMP interface, etc.
2860 * We look for the entry with a telnet prefix.
2861 * First "http://" entry refers to IP addr
2864 gmal_entry
= (struct fcgs_gmal_entry_s
*)gmal_resp
->ms_ma
;
2865 while (num_entries
> 0) {
2866 if (strncmp(gmal_entry
->prefix
,
2867 CT_GMAL_RESP_PREFIX_HTTP
,
2868 sizeof(gmal_entry
->prefix
)) == 0) {
2871 * if the IP address is terminating with a '/',
2873 * Byte 0 consists of the length of the string.
2875 rsp_str
= &(gmal_entry
->prefix
[0]);
2876 if (rsp_str
[gmal_entry
->len
-1] == '/')
2877 rsp_str
[gmal_entry
->len
-1] = 0;
2879 /* copy IP Address to fabric */
2880 strncpy(bfa_fcs_lport_get_fabric_ipaddr(port
),
2881 gmal_entry
->ip_addr
,
2882 BFA_FCS_FABRIC_IPADDR_SZ
);
2890 bfa_sm_send_event(ms
, MSSM_EVENT_RSP_OK
);
2894 bfa_trc(port
->fcs
, cthdr
->reason_code
);
2895 bfa_trc(port
->fcs
, cthdr
->exp_code
);
2896 bfa_sm_send_event(ms
, MSSM_EVENT_RSP_ERROR
);
2900 bfa_fcs_lport_ms_sm_gfn_sending(struct bfa_fcs_lport_ms_s
*ms
,
2901 enum port_ms_event event
)
2903 bfa_trc(ms
->port
->fcs
, ms
->port
->port_cfg
.pwwn
);
2904 bfa_trc(ms
->port
->fcs
, event
);
2907 case MSSM_EVENT_FCXP_SENT
:
2908 bfa_sm_set_state(ms
, bfa_fcs_lport_ms_sm_gfn
);
2911 case MSSM_EVENT_PORT_OFFLINE
:
2912 bfa_sm_set_state(ms
, bfa_fcs_lport_ms_sm_offline
);
2913 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ms
->port
),
2918 bfa_sm_fault(ms
->port
->fcs
, event
);
2923 bfa_fcs_lport_ms_sm_gfn(struct bfa_fcs_lport_ms_s
*ms
,
2924 enum port_ms_event event
)
2926 bfa_trc(ms
->port
->fcs
, ms
->port
->port_cfg
.pwwn
);
2927 bfa_trc(ms
->port
->fcs
, event
);
2930 case MSSM_EVENT_RSP_ERROR
:
2932 * Start timer for a delayed retry
2934 if (ms
->retry_cnt
++ < BFA_FCS_MS_CMD_MAX_RETRIES
) {
2935 bfa_sm_set_state(ms
, bfa_fcs_lport_ms_sm_gfn_retry
);
2936 ms
->port
->stats
.ms_retries
++;
2937 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ms
->port
),
2938 &ms
->timer
, bfa_fcs_lport_ms_timeout
, ms
,
2939 BFA_FCS_RETRY_TIMEOUT
);
2941 bfa_sm_set_state(ms
, bfa_fcs_lport_ms_sm_online
);
2946 case MSSM_EVENT_RSP_OK
:
2947 bfa_sm_set_state(ms
, bfa_fcs_lport_ms_sm_online
);
2950 case MSSM_EVENT_PORT_OFFLINE
:
2951 bfa_sm_set_state(ms
, bfa_fcs_lport_ms_sm_offline
);
2952 bfa_fcxp_discard(ms
->fcxp
);
2956 bfa_sm_fault(ms
->port
->fcs
, event
);
2961 bfa_fcs_lport_ms_sm_gfn_retry(struct bfa_fcs_lport_ms_s
*ms
,
2962 enum port_ms_event event
)
2964 bfa_trc(ms
->port
->fcs
, ms
->port
->port_cfg
.pwwn
);
2965 bfa_trc(ms
->port
->fcs
, event
);
2968 case MSSM_EVENT_TIMEOUT
:
2970 * Retry Timer Expired. Re-send
2972 bfa_sm_set_state(ms
, bfa_fcs_lport_ms_sm_gfn_sending
);
2973 bfa_fcs_lport_ms_send_gfn(ms
, NULL
);
2976 case MSSM_EVENT_PORT_OFFLINE
:
2977 bfa_sm_set_state(ms
, bfa_fcs_lport_ms_sm_offline
);
2978 bfa_timer_stop(&ms
->timer
);
2982 bfa_sm_fault(ms
->port
->fcs
, event
);
2986 * ms_pvt MS local functions
2990 bfa_fcs_lport_ms_send_gfn(void *ms_cbarg
, struct bfa_fcxp_s
*fcxp_alloced
)
2992 struct bfa_fcs_lport_ms_s
*ms
= ms_cbarg
;
2993 bfa_fcs_lport_t
*port
= ms
->port
;
2996 struct bfa_fcxp_s
*fcxp
;
2998 bfa_trc(port
->fcs
, port
->pid
);
3000 fcxp
= fcxp_alloced
? fcxp_alloced
:
3001 bfa_fcs_fcxp_alloc(port
->fcs
, BFA_TRUE
);
3003 bfa_fcs_fcxp_alloc_wait(port
->fcs
->bfa
, &ms
->fcxp_wqe
,
3004 bfa_fcs_lport_ms_send_gfn
, ms
, BFA_TRUE
);
3009 len
= fc_gfn_req_build(&fchs
, bfa_fcxp_get_reqbuf(fcxp
),
3010 bfa_fcs_lport_get_fcid(port
),
3011 port
->fabric
->lps
->pr_nwwn
);
3013 bfa_fcxp_send(fcxp
, NULL
, port
->fabric
->vf_id
, port
->lp_tag
, BFA_FALSE
,
3014 FC_CLASS_3
, len
, &fchs
,
3015 bfa_fcs_lport_ms_gfn_response
, (void *)ms
,
3016 FC_MAX_PDUSZ
, FC_FCCT_TOV
);
3018 bfa_sm_send_event(ms
, MSSM_EVENT_FCXP_SENT
);
3022 bfa_fcs_lport_ms_gfn_response(void *fcsarg
, struct bfa_fcxp_s
*fcxp
,
3023 void *cbarg
, bfa_status_t req_status
, u32 rsp_len
,
3024 u32 resid_len
, struct fchs_s
*rsp_fchs
)
3026 struct bfa_fcs_lport_ms_s
*ms
= (struct bfa_fcs_lport_ms_s
*) cbarg
;
3027 bfa_fcs_lport_t
*port
= ms
->port
;
3028 struct ct_hdr_s
*cthdr
= NULL
;
3031 bfa_trc(port
->fcs
, req_status
);
3032 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
3037 if (req_status
!= BFA_STATUS_OK
) {
3038 bfa_trc(port
->fcs
, req_status
);
3039 bfa_sm_send_event(ms
, MSSM_EVENT_RSP_ERROR
);
3043 cthdr
= (struct ct_hdr_s
*) BFA_FCXP_RSP_PLD(fcxp
);
3044 cthdr
->cmd_rsp_code
= be16_to_cpu(cthdr
->cmd_rsp_code
);
3046 if (cthdr
->cmd_rsp_code
== CT_RSP_ACCEPT
) {
3047 gfn_resp
= (wwn_t
*)(cthdr
+ 1);
3048 /* check if it has actually changed */
3049 if ((memcmp((void *)&bfa_fcs_lport_get_fabric_name(port
),
3050 gfn_resp
, sizeof(wwn_t
)) != 0)) {
3051 bfa_fcs_fabric_set_fabric_name(port
->fabric
, *gfn_resp
);
3053 bfa_sm_send_event(ms
, MSSM_EVENT_RSP_OK
);
3057 bfa_trc(port
->fcs
, cthdr
->reason_code
);
3058 bfa_trc(port
->fcs
, cthdr
->exp_code
);
3059 bfa_sm_send_event(ms
, MSSM_EVENT_RSP_ERROR
);
3063 * ms_pvt MS local functions
3067 bfa_fcs_lport_ms_send_plogi(void *ms_cbarg
, struct bfa_fcxp_s
*fcxp_alloced
)
3069 struct bfa_fcs_lport_ms_s
*ms
= ms_cbarg
;
3070 struct bfa_fcs_lport_s
*port
= ms
->port
;
3073 struct bfa_fcxp_s
*fcxp
;
3075 bfa_trc(port
->fcs
, port
->pid
);
3077 fcxp
= fcxp_alloced
? fcxp_alloced
:
3078 bfa_fcs_fcxp_alloc(port
->fcs
, BFA_TRUE
);
3080 port
->stats
.ms_plogi_alloc_wait
++;
3081 bfa_fcs_fcxp_alloc_wait(port
->fcs
->bfa
, &ms
->fcxp_wqe
,
3082 bfa_fcs_lport_ms_send_plogi
, ms
, BFA_TRUE
);
3087 len
= fc_plogi_build(&fchs
, bfa_fcxp_get_reqbuf(fcxp
),
3088 bfa_hton3b(FC_MGMT_SERVER
),
3089 bfa_fcs_lport_get_fcid(port
), 0,
3090 port
->port_cfg
.pwwn
, port
->port_cfg
.nwwn
,
3091 bfa_fcport_get_maxfrsize(port
->fcs
->bfa
),
3092 bfa_fcport_get_rx_bbcredit(port
->fcs
->bfa
));
3094 bfa_fcxp_send(fcxp
, NULL
, port
->fabric
->vf_id
, port
->lp_tag
, BFA_FALSE
,
3095 FC_CLASS_3
, len
, &fchs
,
3096 bfa_fcs_lport_ms_plogi_response
, (void *)ms
,
3097 FC_MAX_PDUSZ
, FC_ELS_TOV
);
3099 port
->stats
.ms_plogi_sent
++;
3100 bfa_sm_send_event(ms
, MSSM_EVENT_FCXP_SENT
);
3104 bfa_fcs_lport_ms_plogi_response(void *fcsarg
, struct bfa_fcxp_s
*fcxp
,
3105 void *cbarg
, bfa_status_t req_status
,
3106 u32 rsp_len
, u32 resid_len
, struct fchs_s
*rsp_fchs
)
3108 struct bfa_fcs_lport_ms_s
*ms
= (struct bfa_fcs_lport_ms_s
*) cbarg
;
3109 struct bfa_fcs_lport_s
*port
= ms
->port
;
3110 struct fc_els_cmd_s
*els_cmd
;
3111 struct fc_ls_rjt_s
*ls_rjt
;
3113 bfa_trc(port
->fcs
, req_status
);
3114 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
3119 if (req_status
!= BFA_STATUS_OK
) {
3120 port
->stats
.ms_plogi_rsp_err
++;
3121 bfa_trc(port
->fcs
, req_status
);
3122 bfa_sm_send_event(ms
, MSSM_EVENT_RSP_ERROR
);
3126 els_cmd
= (struct fc_els_cmd_s
*) BFA_FCXP_RSP_PLD(fcxp
);
3128 switch (els_cmd
->els_code
) {
3131 if (rsp_len
< sizeof(struct fc_logi_s
)) {
3132 bfa_trc(port
->fcs
, rsp_len
);
3133 port
->stats
.ms_plogi_acc_err
++;
3134 bfa_sm_send_event(ms
, MSSM_EVENT_RSP_ERROR
);
3137 port
->stats
.ms_plogi_accepts
++;
3138 bfa_sm_send_event(ms
, MSSM_EVENT_RSP_OK
);
3142 ls_rjt
= (struct fc_ls_rjt_s
*) BFA_FCXP_RSP_PLD(fcxp
);
3144 bfa_trc(port
->fcs
, ls_rjt
->reason_code
);
3145 bfa_trc(port
->fcs
, ls_rjt
->reason_code_expl
);
3147 port
->stats
.ms_rejects
++;
3148 bfa_sm_send_event(ms
, MSSM_EVENT_RSP_ERROR
);
3152 port
->stats
.ms_plogi_unknown_rsp
++;
3153 bfa_trc(port
->fcs
, els_cmd
->els_code
);
3154 bfa_sm_send_event(ms
, MSSM_EVENT_RSP_ERROR
);
3159 bfa_fcs_lport_ms_timeout(void *arg
)
3161 struct bfa_fcs_lport_ms_s
*ms
= (struct bfa_fcs_lport_ms_s
*) arg
;
3163 ms
->port
->stats
.ms_timeouts
++;
3164 bfa_sm_send_event(ms
, MSSM_EVENT_TIMEOUT
);
3169 bfa_fcs_lport_ms_init(struct bfa_fcs_lport_s
*port
)
3171 struct bfa_fcs_lport_ms_s
*ms
= BFA_FCS_GET_MS_FROM_PORT(port
);
3174 bfa_sm_set_state(ms
, bfa_fcs_lport_ms_sm_offline
);
3177 * Invoke init routines of sub modules.
3179 bfa_fcs_lport_fdmi_init(ms
);
3183 bfa_fcs_lport_ms_offline(struct bfa_fcs_lport_s
*port
)
3185 struct bfa_fcs_lport_ms_s
*ms
= BFA_FCS_GET_MS_FROM_PORT(port
);
3188 bfa_sm_send_event(ms
, MSSM_EVENT_PORT_OFFLINE
);
3189 bfa_fcs_lport_fdmi_offline(ms
);
3193 bfa_fcs_lport_ms_online(struct bfa_fcs_lport_s
*port
)
3195 struct bfa_fcs_lport_ms_s
*ms
= BFA_FCS_GET_MS_FROM_PORT(port
);
3198 bfa_sm_send_event(ms
, MSSM_EVENT_PORT_ONLINE
);
3201 bfa_fcs_lport_ms_fabric_rscn(struct bfa_fcs_lport_s
*port
)
3203 struct bfa_fcs_lport_ms_s
*ms
= BFA_FCS_GET_MS_FROM_PORT(port
);
3205 /* todo. Handle this only when in Online state */
3206 if (bfa_sm_cmp_state(ms
, bfa_fcs_lport_ms_sm_online
))
3207 bfa_sm_send_event(ms
, MSSM_EVENT_PORT_FABRIC_RSCN
);
3211 * @page ns_sm_info VPORT NS State Machine
3213 * @section ns_sm_interactions VPORT NS State Machine Interactions
3215 * @section ns_sm VPORT NS State Machine
3220 * forward declarations
3222 static void bfa_fcs_lport_ns_send_plogi(void *ns_cbarg
,
3223 struct bfa_fcxp_s
*fcxp_alloced
);
3224 static void bfa_fcs_lport_ns_send_rspn_id(void *ns_cbarg
,
3225 struct bfa_fcxp_s
*fcxp_alloced
);
3226 static void bfa_fcs_lport_ns_send_rft_id(void *ns_cbarg
,
3227 struct bfa_fcxp_s
*fcxp_alloced
);
3228 static void bfa_fcs_lport_ns_send_rff_id(void *ns_cbarg
,
3229 struct bfa_fcxp_s
*fcxp_alloced
);
3230 static void bfa_fcs_lport_ns_send_gid_ft(void *ns_cbarg
,
3231 struct bfa_fcxp_s
*fcxp_alloced
);
3232 static void bfa_fcs_lport_ns_timeout(void *arg
);
3233 static void bfa_fcs_lport_ns_plogi_response(void *fcsarg
,
3234 struct bfa_fcxp_s
*fcxp
,
3236 bfa_status_t req_status
,
3239 struct fchs_s
*rsp_fchs
);
3240 static void bfa_fcs_lport_ns_rspn_id_response(void *fcsarg
,
3241 struct bfa_fcxp_s
*fcxp
,
3243 bfa_status_t req_status
,
3246 struct fchs_s
*rsp_fchs
);
3247 static void bfa_fcs_lport_ns_rft_id_response(void *fcsarg
,
3248 struct bfa_fcxp_s
*fcxp
,
3250 bfa_status_t req_status
,
3253 struct fchs_s
*rsp_fchs
);
3254 static void bfa_fcs_lport_ns_rff_id_response(void *fcsarg
,
3255 struct bfa_fcxp_s
*fcxp
,
3257 bfa_status_t req_status
,
3260 struct fchs_s
*rsp_fchs
);
3261 static void bfa_fcs_lport_ns_gid_ft_response(void *fcsarg
,
3262 struct bfa_fcxp_s
*fcxp
,
3264 bfa_status_t req_status
,
3267 struct fchs_s
*rsp_fchs
);
3268 static void bfa_fcs_lport_ns_process_gidft_pids(
3269 struct bfa_fcs_lport_s
*port
,
3270 u32
*pid_buf
, u32 n_pids
);
3272 static void bfa_fcs_lport_ns_boot_target_disc(bfa_fcs_lport_t
*port
);
3274 * fcs_ns_sm FCS nameserver interface state machine
3278 * VPort NS State Machine events
3280 enum vport_ns_event
{
3281 NSSM_EVENT_PORT_ONLINE
= 1,
3282 NSSM_EVENT_PORT_OFFLINE
= 2,
3283 NSSM_EVENT_PLOGI_SENT
= 3,
3284 NSSM_EVENT_RSP_OK
= 4,
3285 NSSM_EVENT_RSP_ERROR
= 5,
3286 NSSM_EVENT_TIMEOUT
= 6,
3287 NSSM_EVENT_NS_QUERY
= 7,
3288 NSSM_EVENT_RSPNID_SENT
= 8,
3289 NSSM_EVENT_RFTID_SENT
= 9,
3290 NSSM_EVENT_RFFID_SENT
= 10,
3291 NSSM_EVENT_GIDFT_SENT
= 11,
3294 static void bfa_fcs_lport_ns_sm_offline(struct bfa_fcs_lport_ns_s
*ns
,
3295 enum vport_ns_event event
);
3296 static void bfa_fcs_lport_ns_sm_plogi_sending(struct bfa_fcs_lport_ns_s
*ns
,
3297 enum vport_ns_event event
);
3298 static void bfa_fcs_lport_ns_sm_plogi(struct bfa_fcs_lport_ns_s
*ns
,
3299 enum vport_ns_event event
);
3300 static void bfa_fcs_lport_ns_sm_plogi_retry(struct bfa_fcs_lport_ns_s
*ns
,
3301 enum vport_ns_event event
);
3302 static void bfa_fcs_lport_ns_sm_sending_rspn_id(
3303 struct bfa_fcs_lport_ns_s
*ns
,
3304 enum vport_ns_event event
);
3305 static void bfa_fcs_lport_ns_sm_rspn_id(struct bfa_fcs_lport_ns_s
*ns
,
3306 enum vport_ns_event event
);
3307 static void bfa_fcs_lport_ns_sm_rspn_id_retry(struct bfa_fcs_lport_ns_s
*ns
,
3308 enum vport_ns_event event
);
3309 static void bfa_fcs_lport_ns_sm_sending_rft_id(
3310 struct bfa_fcs_lport_ns_s
*ns
,
3311 enum vport_ns_event event
);
3312 static void bfa_fcs_lport_ns_sm_rft_id_retry(struct bfa_fcs_lport_ns_s
*ns
,
3313 enum vport_ns_event event
);
3314 static void bfa_fcs_lport_ns_sm_rft_id(struct bfa_fcs_lport_ns_s
*ns
,
3315 enum vport_ns_event event
);
3316 static void bfa_fcs_lport_ns_sm_sending_rff_id(
3317 struct bfa_fcs_lport_ns_s
*ns
,
3318 enum vport_ns_event event
);
3319 static void bfa_fcs_lport_ns_sm_rff_id_retry(struct bfa_fcs_lport_ns_s
*ns
,
3320 enum vport_ns_event event
);
3321 static void bfa_fcs_lport_ns_sm_rff_id(struct bfa_fcs_lport_ns_s
*ns
,
3322 enum vport_ns_event event
);
3323 static void bfa_fcs_lport_ns_sm_sending_gid_ft(
3324 struct bfa_fcs_lport_ns_s
*ns
,
3325 enum vport_ns_event event
);
3326 static void bfa_fcs_lport_ns_sm_gid_ft(struct bfa_fcs_lport_ns_s
*ns
,
3327 enum vport_ns_event event
);
3328 static void bfa_fcs_lport_ns_sm_gid_ft_retry(struct bfa_fcs_lport_ns_s
*ns
,
3329 enum vport_ns_event event
);
3330 static void bfa_fcs_lport_ns_sm_online(struct bfa_fcs_lport_ns_s
*ns
,
3331 enum vport_ns_event event
);
3333 * Start in offline state - awaiting linkup
3336 bfa_fcs_lport_ns_sm_offline(struct bfa_fcs_lport_ns_s
*ns
,
3337 enum vport_ns_event event
)
3339 bfa_trc(ns
->port
->fcs
, ns
->port
->port_cfg
.pwwn
);
3340 bfa_trc(ns
->port
->fcs
, event
);
3343 case NSSM_EVENT_PORT_ONLINE
:
3344 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_plogi_sending
);
3345 bfa_fcs_lport_ns_send_plogi(ns
, NULL
);
3348 case NSSM_EVENT_PORT_OFFLINE
:
3352 bfa_sm_fault(ns
->port
->fcs
, event
);
3357 bfa_fcs_lport_ns_sm_plogi_sending(struct bfa_fcs_lport_ns_s
*ns
,
3358 enum vport_ns_event event
)
3360 bfa_trc(ns
->port
->fcs
, ns
->port
->port_cfg
.pwwn
);
3361 bfa_trc(ns
->port
->fcs
, event
);
3364 case NSSM_EVENT_PLOGI_SENT
:
3365 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_plogi
);
3368 case NSSM_EVENT_PORT_OFFLINE
:
3369 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_offline
);
3370 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns
->port
),
3375 bfa_sm_fault(ns
->port
->fcs
, event
);
3380 bfa_fcs_lport_ns_sm_plogi(struct bfa_fcs_lport_ns_s
*ns
,
3381 enum vport_ns_event event
)
3383 bfa_trc(ns
->port
->fcs
, ns
->port
->port_cfg
.pwwn
);
3384 bfa_trc(ns
->port
->fcs
, event
);
3387 case NSSM_EVENT_RSP_ERROR
:
3389 * Start timer for a delayed retry
3391 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_plogi_retry
);
3392 ns
->port
->stats
.ns_retries
++;
3393 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns
->port
),
3394 &ns
->timer
, bfa_fcs_lport_ns_timeout
, ns
,
3395 BFA_FCS_RETRY_TIMEOUT
);
3398 case NSSM_EVENT_RSP_OK
:
3399 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_sending_rspn_id
);
3400 bfa_fcs_lport_ns_send_rspn_id(ns
, NULL
);
3403 case NSSM_EVENT_PORT_OFFLINE
:
3404 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_offline
);
3405 bfa_fcxp_discard(ns
->fcxp
);
3409 bfa_sm_fault(ns
->port
->fcs
, event
);
3414 bfa_fcs_lport_ns_sm_plogi_retry(struct bfa_fcs_lport_ns_s
*ns
,
3415 enum vport_ns_event event
)
3417 bfa_trc(ns
->port
->fcs
, ns
->port
->port_cfg
.pwwn
);
3418 bfa_trc(ns
->port
->fcs
, event
);
3421 case NSSM_EVENT_TIMEOUT
:
3423 * Retry Timer Expired. Re-send
3425 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_plogi_sending
);
3426 bfa_fcs_lport_ns_send_plogi(ns
, NULL
);
3429 case NSSM_EVENT_PORT_OFFLINE
:
3430 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_offline
);
3431 bfa_timer_stop(&ns
->timer
);
3435 bfa_sm_fault(ns
->port
->fcs
, event
);
3440 bfa_fcs_lport_ns_sm_sending_rspn_id(struct bfa_fcs_lport_ns_s
*ns
,
3441 enum vport_ns_event event
)
3443 bfa_trc(ns
->port
->fcs
, ns
->port
->port_cfg
.pwwn
);
3444 bfa_trc(ns
->port
->fcs
, event
);
3447 case NSSM_EVENT_RSPNID_SENT
:
3448 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_rspn_id
);
3451 case NSSM_EVENT_PORT_OFFLINE
:
3452 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_offline
);
3453 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns
->port
),
3458 bfa_sm_fault(ns
->port
->fcs
, event
);
3463 bfa_fcs_lport_ns_sm_rspn_id(struct bfa_fcs_lport_ns_s
*ns
,
3464 enum vport_ns_event event
)
3466 bfa_trc(ns
->port
->fcs
, ns
->port
->port_cfg
.pwwn
);
3467 bfa_trc(ns
->port
->fcs
, event
);
3470 case NSSM_EVENT_RSP_ERROR
:
3472 * Start timer for a delayed retry
3474 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_rspn_id_retry
);
3475 ns
->port
->stats
.ns_retries
++;
3476 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns
->port
),
3477 &ns
->timer
, bfa_fcs_lport_ns_timeout
, ns
,
3478 BFA_FCS_RETRY_TIMEOUT
);
3481 case NSSM_EVENT_RSP_OK
:
3482 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_sending_rft_id
);
3483 bfa_fcs_lport_ns_send_rft_id(ns
, NULL
);
3486 case NSSM_EVENT_PORT_OFFLINE
:
3487 bfa_fcxp_discard(ns
->fcxp
);
3488 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_offline
);
3492 bfa_sm_fault(ns
->port
->fcs
, event
);
3497 bfa_fcs_lport_ns_sm_rspn_id_retry(struct bfa_fcs_lport_ns_s
*ns
,
3498 enum vport_ns_event event
)
3500 bfa_trc(ns
->port
->fcs
, ns
->port
->port_cfg
.pwwn
);
3501 bfa_trc(ns
->port
->fcs
, event
);
3504 case NSSM_EVENT_TIMEOUT
:
3506 * Retry Timer Expired. Re-send
3508 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_sending_rspn_id
);
3509 bfa_fcs_lport_ns_send_rspn_id(ns
, NULL
);
3512 case NSSM_EVENT_PORT_OFFLINE
:
3513 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_offline
);
3514 bfa_timer_stop(&ns
->timer
);
3518 bfa_sm_fault(ns
->port
->fcs
, event
);
3523 bfa_fcs_lport_ns_sm_sending_rft_id(struct bfa_fcs_lport_ns_s
*ns
,
3524 enum vport_ns_event event
)
3526 bfa_trc(ns
->port
->fcs
, ns
->port
->port_cfg
.pwwn
);
3527 bfa_trc(ns
->port
->fcs
, event
);
3530 case NSSM_EVENT_RFTID_SENT
:
3531 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_rft_id
);
3534 case NSSM_EVENT_PORT_OFFLINE
:
3535 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_offline
);
3536 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns
->port
),
3541 bfa_sm_fault(ns
->port
->fcs
, event
);
3546 bfa_fcs_lport_ns_sm_rft_id(struct bfa_fcs_lport_ns_s
*ns
,
3547 enum vport_ns_event event
)
3549 bfa_trc(ns
->port
->fcs
, ns
->port
->port_cfg
.pwwn
);
3550 bfa_trc(ns
->port
->fcs
, event
);
3553 case NSSM_EVENT_RSP_OK
:
3554 /* Now move to register FC4 Features */
3555 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_sending_rff_id
);
3556 bfa_fcs_lport_ns_send_rff_id(ns
, NULL
);
3559 case NSSM_EVENT_RSP_ERROR
:
3561 * Start timer for a delayed retry
3563 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_rft_id_retry
);
3564 ns
->port
->stats
.ns_retries
++;
3565 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns
->port
),
3566 &ns
->timer
, bfa_fcs_lport_ns_timeout
, ns
,
3567 BFA_FCS_RETRY_TIMEOUT
);
3570 case NSSM_EVENT_PORT_OFFLINE
:
3571 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_offline
);
3572 bfa_fcxp_discard(ns
->fcxp
);
3576 bfa_sm_fault(ns
->port
->fcs
, event
);
3581 bfa_fcs_lport_ns_sm_rft_id_retry(struct bfa_fcs_lport_ns_s
*ns
,
3582 enum vport_ns_event event
)
3584 bfa_trc(ns
->port
->fcs
, ns
->port
->port_cfg
.pwwn
);
3585 bfa_trc(ns
->port
->fcs
, event
);
3588 case NSSM_EVENT_TIMEOUT
:
3589 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_sending_rft_id
);
3590 bfa_fcs_lport_ns_send_rft_id(ns
, NULL
);
3593 case NSSM_EVENT_PORT_OFFLINE
:
3594 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_offline
);
3595 bfa_timer_stop(&ns
->timer
);
3599 bfa_sm_fault(ns
->port
->fcs
, event
);
3604 bfa_fcs_lport_ns_sm_sending_rff_id(struct bfa_fcs_lport_ns_s
*ns
,
3605 enum vport_ns_event event
)
3607 bfa_trc(ns
->port
->fcs
, ns
->port
->port_cfg
.pwwn
);
3608 bfa_trc(ns
->port
->fcs
, event
);
3611 case NSSM_EVENT_RFFID_SENT
:
3612 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_rff_id
);
3615 case NSSM_EVENT_PORT_OFFLINE
:
3616 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_offline
);
3617 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns
->port
),
3622 bfa_sm_fault(ns
->port
->fcs
, event
);
3627 bfa_fcs_lport_ns_sm_rff_id(struct bfa_fcs_lport_ns_s
*ns
,
3628 enum vport_ns_event event
)
3630 bfa_trc(ns
->port
->fcs
, ns
->port
->port_cfg
.pwwn
);
3631 bfa_trc(ns
->port
->fcs
, event
);
3634 case NSSM_EVENT_RSP_OK
:
3637 * If min cfg mode is enabled, we donot initiate rport
3638 * discovery with the fabric. Instead, we will retrieve the
3639 * boot targets from HAL/FW.
3641 if (__fcs_min_cfg(ns
->port
->fcs
)) {
3642 bfa_fcs_lport_ns_boot_target_disc(ns
->port
);
3643 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_online
);
3648 * If the port role is Initiator Mode issue NS query.
3649 * If it is Target Mode, skip this and go to online.
3651 if (BFA_FCS_VPORT_IS_INITIATOR_MODE(ns
->port
)) {
3652 bfa_sm_set_state(ns
,
3653 bfa_fcs_lport_ns_sm_sending_gid_ft
);
3654 bfa_fcs_lport_ns_send_gid_ft(ns
, NULL
);
3657 * kick off mgmt srvr state machine
3659 bfa_fcs_lport_ms_online(ns
->port
);
3662 case NSSM_EVENT_RSP_ERROR
:
3664 * Start timer for a delayed retry
3666 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_rff_id_retry
);
3667 ns
->port
->stats
.ns_retries
++;
3668 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns
->port
),
3669 &ns
->timer
, bfa_fcs_lport_ns_timeout
, ns
,
3670 BFA_FCS_RETRY_TIMEOUT
);
3673 case NSSM_EVENT_PORT_OFFLINE
:
3674 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_offline
);
3675 bfa_fcxp_discard(ns
->fcxp
);
3679 bfa_sm_fault(ns
->port
->fcs
, event
);
3684 bfa_fcs_lport_ns_sm_rff_id_retry(struct bfa_fcs_lport_ns_s
*ns
,
3685 enum vport_ns_event event
)
3687 bfa_trc(ns
->port
->fcs
, ns
->port
->port_cfg
.pwwn
);
3688 bfa_trc(ns
->port
->fcs
, event
);
3691 case NSSM_EVENT_TIMEOUT
:
3692 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_sending_rff_id
);
3693 bfa_fcs_lport_ns_send_rff_id(ns
, NULL
);
3696 case NSSM_EVENT_PORT_OFFLINE
:
3697 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_offline
);
3698 bfa_timer_stop(&ns
->timer
);
3702 bfa_sm_fault(ns
->port
->fcs
, event
);
3706 bfa_fcs_lport_ns_sm_sending_gid_ft(struct bfa_fcs_lport_ns_s
*ns
,
3707 enum vport_ns_event event
)
3709 bfa_trc(ns
->port
->fcs
, ns
->port
->port_cfg
.pwwn
);
3710 bfa_trc(ns
->port
->fcs
, event
);
3713 case NSSM_EVENT_GIDFT_SENT
:
3714 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_gid_ft
);
3717 case NSSM_EVENT_PORT_OFFLINE
:
3718 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_offline
);
3719 bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ns
->port
),
3724 bfa_sm_fault(ns
->port
->fcs
, event
);
3729 bfa_fcs_lport_ns_sm_gid_ft(struct bfa_fcs_lport_ns_s
*ns
,
3730 enum vport_ns_event event
)
3732 bfa_trc(ns
->port
->fcs
, ns
->port
->port_cfg
.pwwn
);
3733 bfa_trc(ns
->port
->fcs
, event
);
3736 case NSSM_EVENT_RSP_OK
:
3737 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_online
);
3740 case NSSM_EVENT_RSP_ERROR
:
3742 * TBD: for certain reject codes, we don't need to retry
3745 * Start timer for a delayed retry
3747 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_gid_ft_retry
);
3748 ns
->port
->stats
.ns_retries
++;
3749 bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ns
->port
),
3750 &ns
->timer
, bfa_fcs_lport_ns_timeout
, ns
,
3751 BFA_FCS_RETRY_TIMEOUT
);
3754 case NSSM_EVENT_PORT_OFFLINE
:
3755 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_offline
);
3756 bfa_fcxp_discard(ns
->fcxp
);
3759 case NSSM_EVENT_NS_QUERY
:
3763 bfa_sm_fault(ns
->port
->fcs
, event
);
3768 bfa_fcs_lport_ns_sm_gid_ft_retry(struct bfa_fcs_lport_ns_s
*ns
,
3769 enum vport_ns_event event
)
3771 bfa_trc(ns
->port
->fcs
, ns
->port
->port_cfg
.pwwn
);
3772 bfa_trc(ns
->port
->fcs
, event
);
3775 case NSSM_EVENT_TIMEOUT
:
3776 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_sending_gid_ft
);
3777 bfa_fcs_lport_ns_send_gid_ft(ns
, NULL
);
3780 case NSSM_EVENT_PORT_OFFLINE
:
3781 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_offline
);
3782 bfa_timer_stop(&ns
->timer
);
3786 bfa_sm_fault(ns
->port
->fcs
, event
);
3791 bfa_fcs_lport_ns_sm_online(struct bfa_fcs_lport_ns_s
*ns
,
3792 enum vport_ns_event event
)
3794 bfa_trc(ns
->port
->fcs
, ns
->port
->port_cfg
.pwwn
);
3795 bfa_trc(ns
->port
->fcs
, event
);
3798 case NSSM_EVENT_PORT_OFFLINE
:
3799 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_offline
);
3802 case NSSM_EVENT_NS_QUERY
:
3804 * If the port role is Initiator Mode issue NS query.
3805 * If it is Target Mode, skip this and go to online.
3807 if (BFA_FCS_VPORT_IS_INITIATOR_MODE(ns
->port
)) {
3808 bfa_sm_set_state(ns
,
3809 bfa_fcs_lport_ns_sm_sending_gid_ft
);
3810 bfa_fcs_lport_ns_send_gid_ft(ns
, NULL
);
3815 bfa_sm_fault(ns
->port
->fcs
, event
);
3822 * ns_pvt Nameserver local functions
3826 bfa_fcs_lport_ns_send_plogi(void *ns_cbarg
, struct bfa_fcxp_s
*fcxp_alloced
)
3828 struct bfa_fcs_lport_ns_s
*ns
= ns_cbarg
;
3829 struct bfa_fcs_lport_s
*port
= ns
->port
;
3832 struct bfa_fcxp_s
*fcxp
;
3834 bfa_trc(port
->fcs
, port
->pid
);
3836 fcxp
= fcxp_alloced
? fcxp_alloced
:
3837 bfa_fcs_fcxp_alloc(port
->fcs
, BFA_TRUE
);
3839 port
->stats
.ns_plogi_alloc_wait
++;
3840 bfa_fcs_fcxp_alloc_wait(port
->fcs
->bfa
, &ns
->fcxp_wqe
,
3841 bfa_fcs_lport_ns_send_plogi
, ns
, BFA_TRUE
);
3846 len
= fc_plogi_build(&fchs
, bfa_fcxp_get_reqbuf(fcxp
),
3847 bfa_hton3b(FC_NAME_SERVER
),
3848 bfa_fcs_lport_get_fcid(port
), 0,
3849 port
->port_cfg
.pwwn
, port
->port_cfg
.nwwn
,
3850 bfa_fcport_get_maxfrsize(port
->fcs
->bfa
),
3851 bfa_fcport_get_rx_bbcredit(port
->fcs
->bfa
));
3853 bfa_fcxp_send(fcxp
, NULL
, port
->fabric
->vf_id
, port
->lp_tag
, BFA_FALSE
,
3854 FC_CLASS_3
, len
, &fchs
,
3855 bfa_fcs_lport_ns_plogi_response
, (void *)ns
,
3856 FC_MAX_PDUSZ
, FC_ELS_TOV
);
3857 port
->stats
.ns_plogi_sent
++;
3859 bfa_sm_send_event(ns
, NSSM_EVENT_PLOGI_SENT
);
3863 bfa_fcs_lport_ns_plogi_response(void *fcsarg
, struct bfa_fcxp_s
*fcxp
,
3864 void *cbarg
, bfa_status_t req_status
, u32 rsp_len
,
3865 u32 resid_len
, struct fchs_s
*rsp_fchs
)
3867 struct bfa_fcs_lport_ns_s
*ns
= (struct bfa_fcs_lport_ns_s
*) cbarg
;
3868 struct bfa_fcs_lport_s
*port
= ns
->port
;
3869 /* struct fc_logi_s *plogi_resp; */
3870 struct fc_els_cmd_s
*els_cmd
;
3871 struct fc_ls_rjt_s
*ls_rjt
;
3873 bfa_trc(port
->fcs
, req_status
);
3874 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
3879 if (req_status
!= BFA_STATUS_OK
) {
3880 bfa_trc(port
->fcs
, req_status
);
3881 port
->stats
.ns_plogi_rsp_err
++;
3882 bfa_sm_send_event(ns
, NSSM_EVENT_RSP_ERROR
);
3886 els_cmd
= (struct fc_els_cmd_s
*) BFA_FCXP_RSP_PLD(fcxp
);
3888 switch (els_cmd
->els_code
) {
3891 if (rsp_len
< sizeof(struct fc_logi_s
)) {
3892 bfa_trc(port
->fcs
, rsp_len
);
3893 port
->stats
.ns_plogi_acc_err
++;
3894 bfa_sm_send_event(ns
, NSSM_EVENT_RSP_ERROR
);
3897 port
->stats
.ns_plogi_accepts
++;
3898 bfa_sm_send_event(ns
, NSSM_EVENT_RSP_OK
);
3902 ls_rjt
= (struct fc_ls_rjt_s
*) BFA_FCXP_RSP_PLD(fcxp
);
3904 bfa_trc(port
->fcs
, ls_rjt
->reason_code
);
3905 bfa_trc(port
->fcs
, ls_rjt
->reason_code_expl
);
3907 port
->stats
.ns_rejects
++;
3909 bfa_sm_send_event(ns
, NSSM_EVENT_RSP_ERROR
);
3913 port
->stats
.ns_plogi_unknown_rsp
++;
3914 bfa_trc(port
->fcs
, els_cmd
->els_code
);
3915 bfa_sm_send_event(ns
, NSSM_EVENT_RSP_ERROR
);
3920 * Register the symbolic port name.
3923 bfa_fcs_lport_ns_send_rspn_id(void *ns_cbarg
, struct bfa_fcxp_s
*fcxp_alloced
)
3925 struct bfa_fcs_lport_ns_s
*ns
= ns_cbarg
;
3926 struct bfa_fcs_lport_s
*port
= ns
->port
;
3929 struct bfa_fcxp_s
*fcxp
;
3931 u8
*psymbl
= &symbl
[0];
3933 memset(symbl
, 0, sizeof(symbl
));
3935 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
3937 fcxp
= fcxp_alloced
? fcxp_alloced
:
3938 bfa_fcs_fcxp_alloc(port
->fcs
, BFA_TRUE
);
3940 port
->stats
.ns_rspnid_alloc_wait
++;
3941 bfa_fcs_fcxp_alloc_wait(port
->fcs
->bfa
, &ns
->fcxp_wqe
,
3942 bfa_fcs_lport_ns_send_rspn_id
, ns
, BFA_TRUE
);
3948 * for V-Port, form a Port Symbolic Name
3952 * For Vports, we append the vport's port symbolic name
3953 * to that of the base port.
3956 strncpy((char *)psymbl
,
3958 (bfa_fcs_lport_get_psym_name
3959 (bfa_fcs_get_base_port(port
->fcs
))),
3961 bfa_fcs_lport_get_psym_name(bfa_fcs_get_base_port
3964 /* Ensure we have a null terminating string. */
3965 ((char *)psymbl
)[strlen((char *) &
3966 bfa_fcs_lport_get_psym_name(bfa_fcs_get_base_port
3968 strncat((char *)psymbl
,
3969 (char *) &(bfa_fcs_lport_get_psym_name(port
)),
3970 strlen((char *) &bfa_fcs_lport_get_psym_name(port
)));
3972 psymbl
= (u8
*) &(bfa_fcs_lport_get_psym_name(port
));
3975 len
= fc_rspnid_build(&fchs
, bfa_fcxp_get_reqbuf(fcxp
),
3976 bfa_fcs_lport_get_fcid(port
), 0, psymbl
);
3978 bfa_fcxp_send(fcxp
, NULL
, port
->fabric
->vf_id
, port
->lp_tag
, BFA_FALSE
,
3979 FC_CLASS_3
, len
, &fchs
,
3980 bfa_fcs_lport_ns_rspn_id_response
, (void *)ns
,
3981 FC_MAX_PDUSZ
, FC_FCCT_TOV
);
3983 port
->stats
.ns_rspnid_sent
++;
3985 bfa_sm_send_event(ns
, NSSM_EVENT_RSPNID_SENT
);
3989 bfa_fcs_lport_ns_rspn_id_response(void *fcsarg
, struct bfa_fcxp_s
*fcxp
,
3990 void *cbarg
, bfa_status_t req_status
,
3991 u32 rsp_len
, u32 resid_len
,
3992 struct fchs_s
*rsp_fchs
)
3994 struct bfa_fcs_lport_ns_s
*ns
= (struct bfa_fcs_lport_ns_s
*) cbarg
;
3995 struct bfa_fcs_lport_s
*port
= ns
->port
;
3996 struct ct_hdr_s
*cthdr
= NULL
;
3998 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
4003 if (req_status
!= BFA_STATUS_OK
) {
4004 bfa_trc(port
->fcs
, req_status
);
4005 port
->stats
.ns_rspnid_rsp_err
++;
4006 bfa_sm_send_event(ns
, NSSM_EVENT_RSP_ERROR
);
4010 cthdr
= (struct ct_hdr_s
*) BFA_FCXP_RSP_PLD(fcxp
);
4011 cthdr
->cmd_rsp_code
= be16_to_cpu(cthdr
->cmd_rsp_code
);
4013 if (cthdr
->cmd_rsp_code
== CT_RSP_ACCEPT
) {
4014 port
->stats
.ns_rspnid_accepts
++;
4015 bfa_sm_send_event(ns
, NSSM_EVENT_RSP_OK
);
4019 port
->stats
.ns_rspnid_rejects
++;
4020 bfa_trc(port
->fcs
, cthdr
->reason_code
);
4021 bfa_trc(port
->fcs
, cthdr
->exp_code
);
4022 bfa_sm_send_event(ns
, NSSM_EVENT_RSP_ERROR
);
4026 * Register FC4-Types
4029 bfa_fcs_lport_ns_send_rft_id(void *ns_cbarg
, struct bfa_fcxp_s
*fcxp_alloced
)
4031 struct bfa_fcs_lport_ns_s
*ns
= ns_cbarg
;
4032 struct bfa_fcs_lport_s
*port
= ns
->port
;
4035 struct bfa_fcxp_s
*fcxp
;
4037 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
4039 fcxp
= fcxp_alloced
? fcxp_alloced
:
4040 bfa_fcs_fcxp_alloc(port
->fcs
, BFA_TRUE
);
4042 port
->stats
.ns_rftid_alloc_wait
++;
4043 bfa_fcs_fcxp_alloc_wait(port
->fcs
->bfa
, &ns
->fcxp_wqe
,
4044 bfa_fcs_lport_ns_send_rft_id
, ns
, BFA_TRUE
);
4049 len
= fc_rftid_build(&fchs
, bfa_fcxp_get_reqbuf(fcxp
),
4050 bfa_fcs_lport_get_fcid(port
), 0, port
->port_cfg
.roles
);
4052 bfa_fcxp_send(fcxp
, NULL
, port
->fabric
->vf_id
, port
->lp_tag
, BFA_FALSE
,
4053 FC_CLASS_3
, len
, &fchs
,
4054 bfa_fcs_lport_ns_rft_id_response
, (void *)ns
,
4055 FC_MAX_PDUSZ
, FC_FCCT_TOV
);
4057 port
->stats
.ns_rftid_sent
++;
4058 bfa_sm_send_event(ns
, NSSM_EVENT_RFTID_SENT
);
4062 bfa_fcs_lport_ns_rft_id_response(void *fcsarg
, struct bfa_fcxp_s
*fcxp
,
4063 void *cbarg
, bfa_status_t req_status
,
4064 u32 rsp_len
, u32 resid_len
,
4065 struct fchs_s
*rsp_fchs
)
4067 struct bfa_fcs_lport_ns_s
*ns
= (struct bfa_fcs_lport_ns_s
*) cbarg
;
4068 struct bfa_fcs_lport_s
*port
= ns
->port
;
4069 struct ct_hdr_s
*cthdr
= NULL
;
4071 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
4076 if (req_status
!= BFA_STATUS_OK
) {
4077 bfa_trc(port
->fcs
, req_status
);
4078 port
->stats
.ns_rftid_rsp_err
++;
4079 bfa_sm_send_event(ns
, NSSM_EVENT_RSP_ERROR
);
4083 cthdr
= (struct ct_hdr_s
*) BFA_FCXP_RSP_PLD(fcxp
);
4084 cthdr
->cmd_rsp_code
= be16_to_cpu(cthdr
->cmd_rsp_code
);
4086 if (cthdr
->cmd_rsp_code
== CT_RSP_ACCEPT
) {
4087 port
->stats
.ns_rftid_accepts
++;
4088 bfa_sm_send_event(ns
, NSSM_EVENT_RSP_OK
);
4092 port
->stats
.ns_rftid_rejects
++;
4093 bfa_trc(port
->fcs
, cthdr
->reason_code
);
4094 bfa_trc(port
->fcs
, cthdr
->exp_code
);
4095 bfa_sm_send_event(ns
, NSSM_EVENT_RSP_ERROR
);
4099 * Register FC4-Features : Should be done after RFT_ID
4102 bfa_fcs_lport_ns_send_rff_id(void *ns_cbarg
, struct bfa_fcxp_s
*fcxp_alloced
)
4104 struct bfa_fcs_lport_ns_s
*ns
= ns_cbarg
;
4105 struct bfa_fcs_lport_s
*port
= ns
->port
;
4108 struct bfa_fcxp_s
*fcxp
;
4111 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
4113 fcxp
= fcxp_alloced
? fcxp_alloced
:
4114 bfa_fcs_fcxp_alloc(port
->fcs
, BFA_TRUE
);
4116 port
->stats
.ns_rffid_alloc_wait
++;
4117 bfa_fcs_fcxp_alloc_wait(port
->fcs
->bfa
, &ns
->fcxp_wqe
,
4118 bfa_fcs_lport_ns_send_rff_id
, ns
, BFA_TRUE
);
4123 if (BFA_FCS_VPORT_IS_INITIATOR_MODE(ns
->port
))
4124 fc4_ftrs
= FC_GS_FCP_FC4_FEATURE_INITIATOR
;
4126 len
= fc_rffid_build(&fchs
, bfa_fcxp_get_reqbuf(fcxp
),
4127 bfa_fcs_lport_get_fcid(port
), 0,
4128 FC_TYPE_FCP
, fc4_ftrs
);
4130 bfa_fcxp_send(fcxp
, NULL
, port
->fabric
->vf_id
, port
->lp_tag
, BFA_FALSE
,
4131 FC_CLASS_3
, len
, &fchs
,
4132 bfa_fcs_lport_ns_rff_id_response
, (void *)ns
,
4133 FC_MAX_PDUSZ
, FC_FCCT_TOV
);
4135 port
->stats
.ns_rffid_sent
++;
4136 bfa_sm_send_event(ns
, NSSM_EVENT_RFFID_SENT
);
4140 bfa_fcs_lport_ns_rff_id_response(void *fcsarg
, struct bfa_fcxp_s
*fcxp
,
4141 void *cbarg
, bfa_status_t req_status
,
4142 u32 rsp_len
, u32 resid_len
,
4143 struct fchs_s
*rsp_fchs
)
4145 struct bfa_fcs_lport_ns_s
*ns
= (struct bfa_fcs_lport_ns_s
*) cbarg
;
4146 struct bfa_fcs_lport_s
*port
= ns
->port
;
4147 struct ct_hdr_s
*cthdr
= NULL
;
4149 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
4154 if (req_status
!= BFA_STATUS_OK
) {
4155 bfa_trc(port
->fcs
, req_status
);
4156 port
->stats
.ns_rffid_rsp_err
++;
4157 bfa_sm_send_event(ns
, NSSM_EVENT_RSP_ERROR
);
4161 cthdr
= (struct ct_hdr_s
*) BFA_FCXP_RSP_PLD(fcxp
);
4162 cthdr
->cmd_rsp_code
= be16_to_cpu(cthdr
->cmd_rsp_code
);
4164 if (cthdr
->cmd_rsp_code
== CT_RSP_ACCEPT
) {
4165 port
->stats
.ns_rffid_accepts
++;
4166 bfa_sm_send_event(ns
, NSSM_EVENT_RSP_OK
);
4170 port
->stats
.ns_rffid_rejects
++;
4171 bfa_trc(port
->fcs
, cthdr
->reason_code
);
4172 bfa_trc(port
->fcs
, cthdr
->exp_code
);
4174 if (cthdr
->reason_code
== CT_RSN_NOT_SUPP
) {
4175 /* if this command is not supported, we don't retry */
4176 bfa_sm_send_event(ns
, NSSM_EVENT_RSP_OK
);
4178 bfa_sm_send_event(ns
, NSSM_EVENT_RSP_ERROR
);
4181 * Query Fabric for FC4-Types Devices.
4183 * TBD : Need to use a local (FCS private) response buffer, since the response
4184 * can be larger than 2K.
4187 bfa_fcs_lport_ns_send_gid_ft(void *ns_cbarg
, struct bfa_fcxp_s
*fcxp_alloced
)
4189 struct bfa_fcs_lport_ns_s
*ns
= ns_cbarg
;
4190 struct bfa_fcs_lport_s
*port
= ns
->port
;
4193 struct bfa_fcxp_s
*fcxp
;
4195 bfa_trc(port
->fcs
, port
->pid
);
4197 fcxp
= fcxp_alloced
? fcxp_alloced
:
4198 bfa_fcs_fcxp_alloc(port
->fcs
, BFA_TRUE
);
4200 port
->stats
.ns_gidft_alloc_wait
++;
4201 bfa_fcs_fcxp_alloc_wait(port
->fcs
->bfa
, &ns
->fcxp_wqe
,
4202 bfa_fcs_lport_ns_send_gid_ft
, ns
, BFA_TRUE
);
4208 * This query is only initiated for FCP initiator mode.
4210 len
= fc_gid_ft_build(&fchs
, bfa_fcxp_get_reqbuf(fcxp
),
4211 ns
->port
->pid
, FC_TYPE_FCP
);
4213 bfa_fcxp_send(fcxp
, NULL
, port
->fabric
->vf_id
, port
->lp_tag
, BFA_FALSE
,
4214 FC_CLASS_3
, len
, &fchs
,
4215 bfa_fcs_lport_ns_gid_ft_response
, (void *)ns
,
4216 bfa_fcxp_get_maxrsp(port
->fcs
->bfa
), FC_FCCT_TOV
);
4218 port
->stats
.ns_gidft_sent
++;
4220 bfa_sm_send_event(ns
, NSSM_EVENT_GIDFT_SENT
);
4224 bfa_fcs_lport_ns_gid_ft_response(void *fcsarg
, struct bfa_fcxp_s
*fcxp
,
4225 void *cbarg
, bfa_status_t req_status
,
4226 u32 rsp_len
, u32 resid_len
,
4227 struct fchs_s
*rsp_fchs
)
4229 struct bfa_fcs_lport_ns_s
*ns
= (struct bfa_fcs_lport_ns_s
*) cbarg
;
4230 struct bfa_fcs_lport_s
*port
= ns
->port
;
4231 struct ct_hdr_s
*cthdr
= NULL
;
4234 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
4239 if (req_status
!= BFA_STATUS_OK
) {
4240 bfa_trc(port
->fcs
, req_status
);
4241 port
->stats
.ns_gidft_rsp_err
++;
4242 bfa_sm_send_event(ns
, NSSM_EVENT_RSP_ERROR
);
4246 if (resid_len
!= 0) {
4248 * TBD : we will need to allocate a larger buffer & retry the
4251 bfa_trc(port
->fcs
, rsp_len
);
4252 bfa_trc(port
->fcs
, resid_len
);
4256 cthdr
= (struct ct_hdr_s
*) BFA_FCXP_RSP_PLD(fcxp
);
4257 cthdr
->cmd_rsp_code
= be16_to_cpu(cthdr
->cmd_rsp_code
);
4259 switch (cthdr
->cmd_rsp_code
) {
4263 port
->stats
.ns_gidft_accepts
++;
4264 n_pids
= (fc_get_ctresp_pyld_len(rsp_len
) / sizeof(u32
));
4265 bfa_trc(port
->fcs
, n_pids
);
4266 bfa_fcs_lport_ns_process_gidft_pids(port
,
4267 (u32
*) (cthdr
+ 1),
4269 bfa_sm_send_event(ns
, NSSM_EVENT_RSP_OK
);
4275 * Check the reason code & explanation.
4276 * There may not have been any FC4 devices in the fabric
4278 port
->stats
.ns_gidft_rejects
++;
4279 bfa_trc(port
->fcs
, cthdr
->reason_code
);
4280 bfa_trc(port
->fcs
, cthdr
->exp_code
);
4282 if ((cthdr
->reason_code
== CT_RSN_UNABLE_TO_PERF
)
4283 && (cthdr
->exp_code
== CT_NS_EXP_FT_NOT_REG
)) {
4285 bfa_sm_send_event(ns
, NSSM_EVENT_RSP_OK
);
4288 * for all other errors, retry
4290 bfa_sm_send_event(ns
, NSSM_EVENT_RSP_ERROR
);
4295 port
->stats
.ns_gidft_unknown_rsp
++;
4296 bfa_trc(port
->fcs
, cthdr
->cmd_rsp_code
);
4297 bfa_sm_send_event(ns
, NSSM_EVENT_RSP_ERROR
);
4302 * This routine will be called by bfa_timer on timer timeouts.
4304 * param[in] port - pointer to bfa_fcs_lport_t.
4309 * Special Considerations:
4314 bfa_fcs_lport_ns_timeout(void *arg
)
4316 struct bfa_fcs_lport_ns_s
*ns
= (struct bfa_fcs_lport_ns_s
*) arg
;
4318 ns
->port
->stats
.ns_timeouts
++;
4319 bfa_sm_send_event(ns
, NSSM_EVENT_TIMEOUT
);
4323 * Process the PID list in GID_FT response
4326 bfa_fcs_lport_ns_process_gidft_pids(struct bfa_fcs_lport_s
*port
, u32
*pid_buf
,
4329 struct fcgs_gidft_resp_s
*gidft_entry
;
4330 struct bfa_fcs_rport_s
*rport
;
4333 for (ii
= 0; ii
< n_pids
; ii
++) {
4334 gidft_entry
= (struct fcgs_gidft_resp_s
*) &pid_buf
[ii
];
4336 if (gidft_entry
->pid
== port
->pid
)
4340 * Check if this rport already exists
4342 rport
= bfa_fcs_lport_get_rport_by_pid(port
, gidft_entry
->pid
);
4343 if (rport
== NULL
) {
4345 * this is a new device. create rport
4347 rport
= bfa_fcs_rport_create(port
, gidft_entry
->pid
);
4350 * this rport already exists
4352 bfa_fcs_rport_scn(rport
);
4355 bfa_trc(port
->fcs
, gidft_entry
->pid
);
4358 * if the last entry bit is set, bail out.
4360 if (gidft_entry
->last
)
4366 * fcs_ns_public FCS nameserver public interfaces
4370 * Functions called by port/fab.
4371 * These will send relevant Events to the ns state machine.
4374 bfa_fcs_lport_ns_init(struct bfa_fcs_lport_s
*port
)
4376 struct bfa_fcs_lport_ns_s
*ns
= BFA_FCS_GET_NS_FROM_PORT(port
);
4379 bfa_sm_set_state(ns
, bfa_fcs_lport_ns_sm_offline
);
4383 bfa_fcs_lport_ns_offline(struct bfa_fcs_lport_s
*port
)
4385 struct bfa_fcs_lport_ns_s
*ns
= BFA_FCS_GET_NS_FROM_PORT(port
);
4388 bfa_sm_send_event(ns
, NSSM_EVENT_PORT_OFFLINE
);
4392 bfa_fcs_lport_ns_online(struct bfa_fcs_lport_s
*port
)
4394 struct bfa_fcs_lport_ns_s
*ns
= BFA_FCS_GET_NS_FROM_PORT(port
);
4397 bfa_sm_send_event(ns
, NSSM_EVENT_PORT_ONLINE
);
4401 bfa_fcs_lport_ns_query(struct bfa_fcs_lport_s
*port
)
4403 struct bfa_fcs_lport_ns_s
*ns
= BFA_FCS_GET_NS_FROM_PORT(port
);
4405 bfa_trc(port
->fcs
, port
->pid
);
4406 bfa_sm_send_event(ns
, NSSM_EVENT_NS_QUERY
);
4410 bfa_fcs_lport_ns_boot_target_disc(bfa_fcs_lport_t
*port
)
4413 struct bfa_fcs_rport_s
*rport
;
4415 wwn_t wwns
[BFA_PREBOOT_BOOTLUN_MAX
];
4418 bfa_iocfc_get_bootwwns(port
->fcs
->bfa
, &nwwns
, wwns
);
4420 for (ii
= 0 ; ii
< nwwns
; ++ii
) {
4421 rport
= bfa_fcs_rport_create_by_wwn(port
, wwns
[ii
]);
4427 bfa_fcs_lport_ns_util_send_rspn_id(void *cbarg
, struct bfa_fcxp_s
*fcxp_alloced
)
4429 struct bfa_fcs_lport_ns_s
*ns
= cbarg
;
4430 struct bfa_fcs_lport_s
*port
= ns
->port
;
4432 struct bfa_fcxp_s
*fcxp
;
4434 u8
*psymbl
= &symbl
[0];
4437 if (!bfa_sm_cmp_state(port
, bfa_fcs_lport_sm_online
))
4440 /* Avoid sending RSPN in the following states. */
4441 if (bfa_sm_cmp_state(ns
, bfa_fcs_lport_ns_sm_offline
) ||
4442 bfa_sm_cmp_state(ns
, bfa_fcs_lport_ns_sm_plogi_sending
) ||
4443 bfa_sm_cmp_state(ns
, bfa_fcs_lport_ns_sm_plogi
) ||
4444 bfa_sm_cmp_state(ns
, bfa_fcs_lport_ns_sm_plogi_retry
) ||
4445 bfa_sm_cmp_state(ns
, bfa_fcs_lport_ns_sm_rspn_id_retry
))
4448 memset(symbl
, 0, sizeof(symbl
));
4449 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
4451 fcxp
= fcxp_alloced
? fcxp_alloced
:
4452 bfa_fcs_fcxp_alloc(port
->fcs
, BFA_FALSE
);
4454 port
->stats
.ns_rspnid_alloc_wait
++;
4455 bfa_fcs_fcxp_alloc_wait(port
->fcs
->bfa
, &ns
->fcxp_wqe
,
4456 bfa_fcs_lport_ns_util_send_rspn_id
, ns
, BFA_FALSE
);
4464 * For Vports, we append the vport's port symbolic name
4465 * to that of the base port.
4467 strncpy((char *)psymbl
, (char *)&(bfa_fcs_lport_get_psym_name
4468 (bfa_fcs_get_base_port(port
->fcs
))),
4469 strlen((char *)&bfa_fcs_lport_get_psym_name(
4470 bfa_fcs_get_base_port(port
->fcs
))));
4472 /* Ensure we have a null terminating string. */
4473 ((char *)psymbl
)[strlen((char *)&bfa_fcs_lport_get_psym_name(
4474 bfa_fcs_get_base_port(port
->fcs
)))] = 0;
4476 strncat((char *)psymbl
,
4477 (char *)&(bfa_fcs_lport_get_psym_name(port
)),
4478 strlen((char *)&bfa_fcs_lport_get_psym_name(port
)));
4481 len
= fc_rspnid_build(&fchs
, bfa_fcxp_get_reqbuf(fcxp
),
4482 bfa_fcs_lport_get_fcid(port
), 0, psymbl
);
4484 bfa_fcxp_send(fcxp
, NULL
, port
->fabric
->vf_id
, port
->lp_tag
, BFA_FALSE
,
4485 FC_CLASS_3
, len
, &fchs
, NULL
, NULL
, FC_MAX_PDUSZ
, 0);
4487 port
->stats
.ns_rspnid_sent
++;
4494 #define FC_QOS_RSCN_EVENT 0x0c
4495 #define FC_FABRIC_NAME_RSCN_EVENT 0x0d
4498 * forward declarations
4500 static void bfa_fcs_lport_scn_send_scr(void *scn_cbarg
,
4501 struct bfa_fcxp_s
*fcxp_alloced
);
4502 static void bfa_fcs_lport_scn_scr_response(void *fcsarg
,
4503 struct bfa_fcxp_s
*fcxp
,
4505 bfa_status_t req_status
,
4508 struct fchs_s
*rsp_fchs
);
4509 static void bfa_fcs_lport_scn_send_ls_acc(struct bfa_fcs_lport_s
*port
,
4510 struct fchs_s
*rx_fchs
);
4511 static void bfa_fcs_lport_scn_timeout(void *arg
);
4514 * fcs_scm_sm FCS SCN state machine
4518 * VPort SCN State Machine events
4520 enum port_scn_event
{
4521 SCNSM_EVENT_PORT_ONLINE
= 1,
4522 SCNSM_EVENT_PORT_OFFLINE
= 2,
4523 SCNSM_EVENT_RSP_OK
= 3,
4524 SCNSM_EVENT_RSP_ERROR
= 4,
4525 SCNSM_EVENT_TIMEOUT
= 5,
4526 SCNSM_EVENT_SCR_SENT
= 6,
4529 static void bfa_fcs_lport_scn_sm_offline(struct bfa_fcs_lport_scn_s
*scn
,
4530 enum port_scn_event event
);
4531 static void bfa_fcs_lport_scn_sm_sending_scr(
4532 struct bfa_fcs_lport_scn_s
*scn
,
4533 enum port_scn_event event
);
4534 static void bfa_fcs_lport_scn_sm_scr(struct bfa_fcs_lport_scn_s
*scn
,
4535 enum port_scn_event event
);
4536 static void bfa_fcs_lport_scn_sm_scr_retry(struct bfa_fcs_lport_scn_s
*scn
,
4537 enum port_scn_event event
);
4538 static void bfa_fcs_lport_scn_sm_online(struct bfa_fcs_lport_scn_s
*scn
,
4539 enum port_scn_event event
);
4542 * Starting state - awaiting link up.
4545 bfa_fcs_lport_scn_sm_offline(struct bfa_fcs_lport_scn_s
*scn
,
4546 enum port_scn_event event
)
4549 case SCNSM_EVENT_PORT_ONLINE
:
4550 bfa_sm_set_state(scn
, bfa_fcs_lport_scn_sm_sending_scr
);
4551 bfa_fcs_lport_scn_send_scr(scn
, NULL
);
4554 case SCNSM_EVENT_PORT_OFFLINE
:
4558 bfa_sm_fault(scn
->port
->fcs
, event
);
4563 bfa_fcs_lport_scn_sm_sending_scr(struct bfa_fcs_lport_scn_s
*scn
,
4564 enum port_scn_event event
)
4567 case SCNSM_EVENT_SCR_SENT
:
4568 bfa_sm_set_state(scn
, bfa_fcs_lport_scn_sm_scr
);
4571 case SCNSM_EVENT_PORT_OFFLINE
:
4572 bfa_sm_set_state(scn
, bfa_fcs_lport_scn_sm_offline
);
4573 bfa_fcxp_walloc_cancel(scn
->port
->fcs
->bfa
, &scn
->fcxp_wqe
);
4577 bfa_sm_fault(scn
->port
->fcs
, event
);
4582 bfa_fcs_lport_scn_sm_scr(struct bfa_fcs_lport_scn_s
*scn
,
4583 enum port_scn_event event
)
4585 struct bfa_fcs_lport_s
*port
= scn
->port
;
4588 case SCNSM_EVENT_RSP_OK
:
4589 bfa_sm_set_state(scn
, bfa_fcs_lport_scn_sm_online
);
4592 case SCNSM_EVENT_RSP_ERROR
:
4593 bfa_sm_set_state(scn
, bfa_fcs_lport_scn_sm_scr_retry
);
4594 bfa_timer_start(port
->fcs
->bfa
, &scn
->timer
,
4595 bfa_fcs_lport_scn_timeout
, scn
,
4596 BFA_FCS_RETRY_TIMEOUT
);
4599 case SCNSM_EVENT_PORT_OFFLINE
:
4600 bfa_sm_set_state(scn
, bfa_fcs_lport_scn_sm_offline
);
4601 bfa_fcxp_discard(scn
->fcxp
);
4605 bfa_sm_fault(port
->fcs
, event
);
4610 bfa_fcs_lport_scn_sm_scr_retry(struct bfa_fcs_lport_scn_s
*scn
,
4611 enum port_scn_event event
)
4614 case SCNSM_EVENT_TIMEOUT
:
4615 bfa_sm_set_state(scn
, bfa_fcs_lport_scn_sm_sending_scr
);
4616 bfa_fcs_lport_scn_send_scr(scn
, NULL
);
4619 case SCNSM_EVENT_PORT_OFFLINE
:
4620 bfa_sm_set_state(scn
, bfa_fcs_lport_scn_sm_offline
);
4621 bfa_timer_stop(&scn
->timer
);
4625 bfa_sm_fault(scn
->port
->fcs
, event
);
4630 bfa_fcs_lport_scn_sm_online(struct bfa_fcs_lport_scn_s
*scn
,
4631 enum port_scn_event event
)
4634 case SCNSM_EVENT_PORT_OFFLINE
:
4635 bfa_sm_set_state(scn
, bfa_fcs_lport_scn_sm_offline
);
4639 bfa_sm_fault(scn
->port
->fcs
, event
);
4646 * fcs_scn_private FCS SCN private functions
4650 * This routine will be called to send a SCR command.
4653 bfa_fcs_lport_scn_send_scr(void *scn_cbarg
, struct bfa_fcxp_s
*fcxp_alloced
)
4655 struct bfa_fcs_lport_scn_s
*scn
= scn_cbarg
;
4656 struct bfa_fcs_lport_s
*port
= scn
->port
;
4659 struct bfa_fcxp_s
*fcxp
;
4661 bfa_trc(port
->fcs
, port
->pid
);
4662 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
4664 fcxp
= fcxp_alloced
? fcxp_alloced
:
4665 bfa_fcs_fcxp_alloc(port
->fcs
, BFA_TRUE
);
4667 bfa_fcs_fcxp_alloc_wait(port
->fcs
->bfa
, &scn
->fcxp_wqe
,
4668 bfa_fcs_lport_scn_send_scr
, scn
, BFA_TRUE
);
4673 /* Handle VU registrations for Base port only */
4674 if ((!port
->vport
) && bfa_ioc_get_fcmode(&port
->fcs
->bfa
->ioc
)) {
4675 len
= fc_scr_build(&fchs
, bfa_fcxp_get_reqbuf(fcxp
),
4676 port
->fabric
->lps
->brcd_switch
,
4679 len
= fc_scr_build(&fchs
, bfa_fcxp_get_reqbuf(fcxp
),
4684 bfa_fcxp_send(fcxp
, NULL
, port
->fabric
->vf_id
, port
->lp_tag
, BFA_FALSE
,
4685 FC_CLASS_3
, len
, &fchs
,
4686 bfa_fcs_lport_scn_scr_response
,
4687 (void *)scn
, FC_MAX_PDUSZ
, FC_ELS_TOV
);
4689 bfa_sm_send_event(scn
, SCNSM_EVENT_SCR_SENT
);
4693 bfa_fcs_lport_scn_scr_response(void *fcsarg
, struct bfa_fcxp_s
*fcxp
,
4694 void *cbarg
, bfa_status_t req_status
, u32 rsp_len
,
4695 u32 resid_len
, struct fchs_s
*rsp_fchs
)
4697 struct bfa_fcs_lport_scn_s
*scn
= (struct bfa_fcs_lport_scn_s
*) cbarg
;
4698 struct bfa_fcs_lport_s
*port
= scn
->port
;
4699 struct fc_els_cmd_s
*els_cmd
;
4700 struct fc_ls_rjt_s
*ls_rjt
;
4702 bfa_trc(port
->fcs
, port
->port_cfg
.pwwn
);
4707 if (req_status
!= BFA_STATUS_OK
) {
4708 bfa_trc(port
->fcs
, req_status
);
4709 bfa_sm_send_event(scn
, SCNSM_EVENT_RSP_ERROR
);
4713 els_cmd
= (struct fc_els_cmd_s
*) BFA_FCXP_RSP_PLD(fcxp
);
4715 switch (els_cmd
->els_code
) {
4718 bfa_sm_send_event(scn
, SCNSM_EVENT_RSP_OK
);
4723 ls_rjt
= (struct fc_ls_rjt_s
*) BFA_FCXP_RSP_PLD(fcxp
);
4725 bfa_trc(port
->fcs
, ls_rjt
->reason_code
);
4726 bfa_trc(port
->fcs
, ls_rjt
->reason_code_expl
);
4728 bfa_sm_send_event(scn
, SCNSM_EVENT_RSP_ERROR
);
4732 bfa_sm_send_event(scn
, SCNSM_EVENT_RSP_ERROR
);
4740 bfa_fcs_lport_scn_send_ls_acc(struct bfa_fcs_lport_s
*port
,
4741 struct fchs_s
*rx_fchs
)
4744 struct bfa_fcxp_s
*fcxp
;
4745 struct bfa_rport_s
*bfa_rport
= NULL
;
4748 bfa_trc(port
->fcs
, rx_fchs
->s_id
);
4750 fcxp
= bfa_fcs_fcxp_alloc(port
->fcs
, BFA_FALSE
);
4754 len
= fc_ls_acc_build(&fchs
, bfa_fcxp_get_reqbuf(fcxp
),
4755 rx_fchs
->s_id
, bfa_fcs_lport_get_fcid(port
),
4758 bfa_fcxp_send(fcxp
, bfa_rport
, port
->fabric
->vf_id
, port
->lp_tag
,
4759 BFA_FALSE
, FC_CLASS_3
, len
, &fchs
, NULL
, NULL
,
4764 * This routine will be called by bfa_timer on timer timeouts.
4766 * param[in] vport - pointer to bfa_fcs_lport_t.
4767 * param[out] vport_status - pointer to return vport status in
4772 * Special Considerations:
4777 bfa_fcs_lport_scn_timeout(void *arg
)
4779 struct bfa_fcs_lport_scn_s
*scn
= (struct bfa_fcs_lport_scn_s
*) arg
;
4781 bfa_sm_send_event(scn
, SCNSM_EVENT_TIMEOUT
);
4787 * fcs_scn_public FCS state change notification public interfaces
4791 * Functions called by port/fab
4794 bfa_fcs_lport_scn_init(struct bfa_fcs_lport_s
*port
)
4796 struct bfa_fcs_lport_scn_s
*scn
= BFA_FCS_GET_SCN_FROM_PORT(port
);
4799 bfa_sm_set_state(scn
, bfa_fcs_lport_scn_sm_offline
);
4803 bfa_fcs_lport_scn_offline(struct bfa_fcs_lport_s
*port
)
4805 struct bfa_fcs_lport_scn_s
*scn
= BFA_FCS_GET_SCN_FROM_PORT(port
);
4808 bfa_sm_send_event(scn
, SCNSM_EVENT_PORT_OFFLINE
);
4812 bfa_fcs_lport_scn_online(struct bfa_fcs_lport_s
*port
)
4814 struct bfa_fcs_lport_scn_s
*scn
= BFA_FCS_GET_SCN_FROM_PORT(port
);
4817 bfa_sm_send_event(scn
, SCNSM_EVENT_PORT_ONLINE
);
4821 bfa_fcs_lport_scn_portid_rscn(struct bfa_fcs_lport_s
*port
, u32 rpid
)
4823 struct bfa_fcs_rport_s
*rport
;
4825 bfa_trc(port
->fcs
, rpid
);
4828 * If this is an unknown device, then it just came online.
4829 * Otherwise let rport handle the RSCN event.
4831 rport
= bfa_fcs_lport_get_rport_by_pid(port
, rpid
);
4833 rport
= bfa_fcs_lport_get_rport_by_old_pid(port
, rpid
);
4835 if (rport
== NULL
) {
4837 * If min cfg mode is enabled, we donot need to
4838 * discover any new rports.
4840 if (!__fcs_min_cfg(port
->fcs
))
4841 rport
= bfa_fcs_rport_create(port
, rpid
);
4843 bfa_fcs_rport_scn(rport
);
4847 * rscn format based PID comparison
4849 #define __fc_pid_match(__c0, __c1, __fmt) \
4850 (((__fmt) == FC_RSCN_FORMAT_FABRIC) || \
4851 (((__fmt) == FC_RSCN_FORMAT_DOMAIN) && \
4852 ((__c0)[0] == (__c1)[0])) || \
4853 (((__fmt) == FC_RSCN_FORMAT_AREA) && \
4854 ((__c0)[0] == (__c1)[0]) && \
4855 ((__c0)[1] == (__c1)[1])))
4858 bfa_fcs_lport_scn_multiport_rscn(struct bfa_fcs_lport_s
*port
,
4859 enum fc_rscn_format format
,
4862 struct bfa_fcs_rport_s
*rport
;
4863 struct list_head
*qe
, *qe_next
;
4866 bfa_trc(port
->fcs
, format
);
4867 bfa_trc(port
->fcs
, rscn_pid
);
4869 c0
= (u8
*) &rscn_pid
;
4871 list_for_each_safe(qe
, qe_next
, &port
->rport_q
) {
4872 rport
= (struct bfa_fcs_rport_s
*) qe
;
4873 c1
= (u8
*) &rport
->pid
;
4874 if (__fc_pid_match(c0
, c1
, format
))
4875 bfa_fcs_rport_scn(rport
);
4881 bfa_fcs_lport_scn_process_rscn(struct bfa_fcs_lport_s
*port
,
4882 struct fchs_s
*fchs
, u32 len
)
4884 struct fc_rscn_pl_s
*rscn
= (struct fc_rscn_pl_s
*) (fchs
+ 1);
4887 bfa_boolean_t nsquery
= BFA_FALSE
, found
;
4891 (be16_to_cpu(rscn
->payldlen
) -
4892 sizeof(u32
)) / sizeof(rscn
->event
[0]);
4894 bfa_trc(port
->fcs
, num_entries
);
4896 port
->stats
.num_rscn
++;
4898 bfa_fcs_lport_scn_send_ls_acc(port
, fchs
);
4900 for (i
= 0; i
< num_entries
; i
++) {
4901 rscn_pid
= rscn
->event
[i
].portid
;
4903 bfa_trc(port
->fcs
, rscn
->event
[i
].format
);
4904 bfa_trc(port
->fcs
, rscn_pid
);
4906 /* check for duplicate entries in the list */
4908 for (j
= 0; j
< i
; j
++) {
4909 if (rscn
->event
[j
].portid
== rscn_pid
) {
4915 /* if found in down the list, pid has been already processed */
4917 bfa_trc(port
->fcs
, rscn_pid
);
4921 switch (rscn
->event
[i
].format
) {
4922 case FC_RSCN_FORMAT_PORTID
:
4923 if (rscn
->event
[i
].qualifier
== FC_QOS_RSCN_EVENT
) {
4925 * Ignore this event.
4926 * f/w would have processed it
4928 bfa_trc(port
->fcs
, rscn_pid
);
4930 port
->stats
.num_portid_rscn
++;
4931 bfa_fcs_lport_scn_portid_rscn(port
, rscn_pid
);
4935 case FC_RSCN_FORMAT_FABRIC
:
4936 if (rscn
->event
[i
].qualifier
==
4937 FC_FABRIC_NAME_RSCN_EVENT
) {
4938 bfa_fcs_lport_ms_fabric_rscn(port
);
4941 /* !!!!!!!!! Fall Through !!!!!!!!!!!!! */
4943 case FC_RSCN_FORMAT_AREA
:
4944 case FC_RSCN_FORMAT_DOMAIN
:
4946 bfa_fcs_lport_scn_multiport_rscn(port
,
4947 rscn
->event
[i
].format
,
4959 * If any of area, domain or fabric RSCN is received, do a fresh
4960 * discovery to find new devices.
4963 bfa_fcs_lport_ns_query(port
);
4970 * fcs_port_api BFA FCS port API
4972 struct bfa_fcs_lport_s
*
4973 bfa_fcs_get_base_port(struct bfa_fcs_s
*fcs
)
4975 return &fcs
->fabric
.bport
;
4979 bfa_fcs_lport_get_rport(struct bfa_fcs_lport_s
*port
, wwn_t wwn
, int index
,
4980 int nrports
, bfa_boolean_t bwwn
)
4982 struct list_head
*qh
, *qe
;
4983 struct bfa_fcs_rport_s
*rport
= NULL
;
4985 struct bfa_fcs_s
*fcs
;
4987 if (port
== NULL
|| nrports
== 0)
4991 bfa_trc(fcs
, (u32
) nrports
);
4994 qh
= &port
->rport_q
;
4995 qe
= bfa_q_first(qh
);
4997 while ((qe
!= qh
) && (i
< nrports
)) {
4998 rport
= (struct bfa_fcs_rport_s
*) qe
;
4999 if (bfa_ntoh3b(rport
->pid
) > 0xFFF000) {
5000 qe
= bfa_q_next(qe
);
5001 bfa_trc(fcs
, (u32
) rport
->pwwn
);
5002 bfa_trc(fcs
, rport
->pid
);
5008 if (!memcmp(&wwn
, &rport
->pwwn
, 8))
5016 qe
= bfa_q_next(qe
);
5027 bfa_fcs_lport_get_rport_quals(struct bfa_fcs_lport_s
*port
,
5028 struct bfa_rport_qualifier_s rports
[], int *nrports
)
5030 struct list_head
*qh
, *qe
;
5031 struct bfa_fcs_rport_s
*rport
= NULL
;
5033 struct bfa_fcs_s
*fcs
;
5035 if (port
== NULL
|| rports
== NULL
|| *nrports
== 0)
5039 bfa_trc(fcs
, (u32
) *nrports
);
5042 qh
= &port
->rport_q
;
5043 qe
= bfa_q_first(qh
);
5045 while ((qe
!= qh
) && (i
< *nrports
)) {
5046 rport
= (struct bfa_fcs_rport_s
*) qe
;
5047 if (bfa_ntoh3b(rport
->pid
) > 0xFFF000) {
5048 qe
= bfa_q_next(qe
);
5049 bfa_trc(fcs
, (u32
) rport
->pwwn
);
5050 bfa_trc(fcs
, rport
->pid
);
5055 if (!rport
->pwwn
&& !rport
->pid
) {
5056 qe
= bfa_q_next(qe
);
5060 rports
[i
].pwwn
= rport
->pwwn
;
5061 rports
[i
].pid
= rport
->pid
;
5064 qe
= bfa_q_next(qe
);
5072 * Iterate's through all the rport's in the given port to
5073 * determine the maximum operating speed.
5075 * !!!! To be used in TRL Functionality only !!!!
5078 bfa_fcs_lport_get_rport_max_speed(bfa_fcs_lport_t
*port
)
5080 struct list_head
*qh
, *qe
;
5081 struct bfa_fcs_rport_s
*rport
= NULL
;
5082 struct bfa_fcs_s
*fcs
;
5083 bfa_port_speed_t max_speed
= 0;
5084 struct bfa_port_attr_s port_attr
;
5085 bfa_port_speed_t port_speed
, rport_speed
;
5086 bfa_boolean_t trl_enabled
= bfa_fcport_is_ratelim(port
->fcs
->bfa
);
5094 /* Get Physical port's current speed */
5095 bfa_fcport_get_attr(port
->fcs
->bfa
, &port_attr
);
5096 port_speed
= port_attr
.speed
;
5097 bfa_trc(fcs
, port_speed
);
5099 qh
= &port
->rport_q
;
5100 qe
= bfa_q_first(qh
);
5103 rport
= (struct bfa_fcs_rport_s
*) qe
;
5104 if ((bfa_ntoh3b(rport
->pid
) > 0xFFF000) ||
5105 (bfa_fcs_rport_get_state(rport
) == BFA_RPORT_OFFLINE
) ||
5106 (rport
->scsi_function
!= BFA_RPORT_TARGET
)) {
5107 qe
= bfa_q_next(qe
);
5111 rport_speed
= rport
->rpf
.rpsc_speed
;
5112 if ((trl_enabled
) && (rport_speed
==
5113 BFA_PORT_SPEED_UNKNOWN
)) {
5114 /* Use default ratelim speed setting */
5116 bfa_fcport_get_ratelim_speed(port
->fcs
->bfa
);
5119 if (rport_speed
> max_speed
)
5120 max_speed
= rport_speed
;
5122 qe
= bfa_q_next(qe
);
5125 if (max_speed
> port_speed
)
5126 max_speed
= port_speed
;
5128 bfa_trc(fcs
, max_speed
);
5132 struct bfa_fcs_lport_s
*
5133 bfa_fcs_lookup_port(struct bfa_fcs_s
*fcs
, u16 vf_id
, wwn_t lpwwn
)
5135 struct bfa_fcs_vport_s
*vport
;
5138 WARN_ON(fcs
== NULL
);
5140 vf
= bfa_fcs_vf_lookup(fcs
, vf_id
);
5142 bfa_trc(fcs
, vf_id
);
5146 if (!lpwwn
|| (vf
->bport
.port_cfg
.pwwn
== lpwwn
))
5149 vport
= bfa_fcs_fabric_vport_lookup(vf
, lpwwn
);
5151 return &vport
->lport
;
5157 * API corresponding to NPIV_VPORT_GETINFO.
5160 bfa_fcs_lport_get_info(struct bfa_fcs_lport_s
*port
,
5161 struct bfa_lport_info_s
*port_info
)
5164 bfa_trc(port
->fcs
, port
->fabric
->fabric_name
);
5166 if (port
->vport
== NULL
) {
5168 * This is a Physical port
5170 port_info
->port_type
= BFA_LPORT_TYPE_PHYSICAL
;
5173 * @todo : need to fix the state & reason
5175 port_info
->port_state
= 0;
5176 port_info
->offline_reason
= 0;
5178 port_info
->port_wwn
= bfa_fcs_lport_get_pwwn(port
);
5179 port_info
->node_wwn
= bfa_fcs_lport_get_nwwn(port
);
5181 port_info
->max_vports_supp
=
5182 bfa_lps_get_max_vport(port
->fcs
->bfa
);
5183 port_info
->num_vports_inuse
=
5184 port
->fabric
->num_vports
;
5185 port_info
->max_rports_supp
= BFA_FCS_MAX_RPORTS_SUPP
;
5186 port_info
->num_rports_inuse
= port
->num_rports
;
5189 * This is a virtual port
5191 port_info
->port_type
= BFA_LPORT_TYPE_VIRTUAL
;
5194 * @todo : need to fix the state & reason
5196 port_info
->port_state
= 0;
5197 port_info
->offline_reason
= 0;
5199 port_info
->port_wwn
= bfa_fcs_lport_get_pwwn(port
);
5200 port_info
->node_wwn
= bfa_fcs_lport_get_nwwn(port
);
5205 bfa_fcs_lport_get_stats(struct bfa_fcs_lport_s
*fcs_port
,
5206 struct bfa_lport_stats_s
*port_stats
)
5208 *port_stats
= fcs_port
->stats
;
5212 bfa_fcs_lport_clear_stats(struct bfa_fcs_lport_s
*fcs_port
)
5214 memset(&fcs_port
->stats
, 0, sizeof(struct bfa_lport_stats_s
));
5218 * FCS virtual port state machine
5221 #define __vport_fcs(__vp) ((__vp)->lport.fcs)
5222 #define __vport_pwwn(__vp) ((__vp)->lport.port_cfg.pwwn)
5223 #define __vport_nwwn(__vp) ((__vp)->lport.port_cfg.nwwn)
5224 #define __vport_bfa(__vp) ((__vp)->lport.fcs->bfa)
5225 #define __vport_fcid(__vp) ((__vp)->lport.pid)
5226 #define __vport_fabric(__vp) ((__vp)->lport.fabric)
5227 #define __vport_vfid(__vp) ((__vp)->lport.fabric->vf_id)
5229 #define BFA_FCS_VPORT_MAX_RETRIES 5
5231 * Forward declarations
5233 static void bfa_fcs_vport_do_fdisc(struct bfa_fcs_vport_s
*vport
);
5234 static void bfa_fcs_vport_timeout(void *vport_arg
);
5235 static void bfa_fcs_vport_do_logo(struct bfa_fcs_vport_s
*vport
);
5236 static void bfa_fcs_vport_free(struct bfa_fcs_vport_s
*vport
);
5239 * fcs_vport_sm FCS virtual port state machine
5243 * VPort State Machine events
5245 enum bfa_fcs_vport_event
{
5246 BFA_FCS_VPORT_SM_CREATE
= 1, /* vport create event */
5247 BFA_FCS_VPORT_SM_DELETE
= 2, /* vport delete event */
5248 BFA_FCS_VPORT_SM_START
= 3, /* vport start request */
5249 BFA_FCS_VPORT_SM_STOP
= 4, /* stop: unsupported */
5250 BFA_FCS_VPORT_SM_ONLINE
= 5, /* fabric online */
5251 BFA_FCS_VPORT_SM_OFFLINE
= 6, /* fabric offline event */
5252 BFA_FCS_VPORT_SM_FRMSENT
= 7, /* fdisc/logo sent events */
5253 BFA_FCS_VPORT_SM_RSP_OK
= 8, /* good response */
5254 BFA_FCS_VPORT_SM_RSP_ERROR
= 9, /* error/bad response */
5255 BFA_FCS_VPORT_SM_TIMEOUT
= 10, /* delay timer event */
5256 BFA_FCS_VPORT_SM_DELCOMP
= 11, /* lport delete completion */
5257 BFA_FCS_VPORT_SM_RSP_DUP_WWN
= 12, /* Dup wnn error*/
5258 BFA_FCS_VPORT_SM_RSP_FAILED
= 13, /* non-retryable failure */
5259 BFA_FCS_VPORT_SM_STOPCOMP
= 14, /* vport delete completion */
5262 static void bfa_fcs_vport_sm_uninit(struct bfa_fcs_vport_s
*vport
,
5263 enum bfa_fcs_vport_event event
);
5264 static void bfa_fcs_vport_sm_created(struct bfa_fcs_vport_s
*vport
,
5265 enum bfa_fcs_vport_event event
);
5266 static void bfa_fcs_vport_sm_offline(struct bfa_fcs_vport_s
*vport
,
5267 enum bfa_fcs_vport_event event
);
5268 static void bfa_fcs_vport_sm_fdisc(struct bfa_fcs_vport_s
*vport
,
5269 enum bfa_fcs_vport_event event
);
5270 static void bfa_fcs_vport_sm_fdisc_retry(struct bfa_fcs_vport_s
*vport
,
5271 enum bfa_fcs_vport_event event
);
5272 static void bfa_fcs_vport_sm_fdisc_rsp_wait(struct bfa_fcs_vport_s
*vport
,
5273 enum bfa_fcs_vport_event event
);
5274 static void bfa_fcs_vport_sm_online(struct bfa_fcs_vport_s
*vport
,
5275 enum bfa_fcs_vport_event event
);
5276 static void bfa_fcs_vport_sm_deleting(struct bfa_fcs_vport_s
*vport
,
5277 enum bfa_fcs_vport_event event
);
5278 static void bfa_fcs_vport_sm_cleanup(struct bfa_fcs_vport_s
*vport
,
5279 enum bfa_fcs_vport_event event
);
5280 static void bfa_fcs_vport_sm_logo(struct bfa_fcs_vport_s
*vport
,
5281 enum bfa_fcs_vport_event event
);
5282 static void bfa_fcs_vport_sm_error(struct bfa_fcs_vport_s
*vport
,
5283 enum bfa_fcs_vport_event event
);
5284 static void bfa_fcs_vport_sm_stopping(struct bfa_fcs_vport_s
*vport
,
5285 enum bfa_fcs_vport_event event
);
5286 static void bfa_fcs_vport_sm_logo_for_stop(struct bfa_fcs_vport_s
*vport
,
5287 enum bfa_fcs_vport_event event
);
5289 static struct bfa_sm_table_s vport_sm_table
[] = {
5290 {BFA_SM(bfa_fcs_vport_sm_uninit
), BFA_FCS_VPORT_UNINIT
},
5291 {BFA_SM(bfa_fcs_vport_sm_created
), BFA_FCS_VPORT_CREATED
},
5292 {BFA_SM(bfa_fcs_vport_sm_offline
), BFA_FCS_VPORT_OFFLINE
},
5293 {BFA_SM(bfa_fcs_vport_sm_fdisc
), BFA_FCS_VPORT_FDISC
},
5294 {BFA_SM(bfa_fcs_vport_sm_fdisc_retry
), BFA_FCS_VPORT_FDISC_RETRY
},
5295 {BFA_SM(bfa_fcs_vport_sm_fdisc_rsp_wait
), BFA_FCS_VPORT_FDISC_RSP_WAIT
},
5296 {BFA_SM(bfa_fcs_vport_sm_online
), BFA_FCS_VPORT_ONLINE
},
5297 {BFA_SM(bfa_fcs_vport_sm_deleting
), BFA_FCS_VPORT_DELETING
},
5298 {BFA_SM(bfa_fcs_vport_sm_cleanup
), BFA_FCS_VPORT_CLEANUP
},
5299 {BFA_SM(bfa_fcs_vport_sm_logo
), BFA_FCS_VPORT_LOGO
},
5300 {BFA_SM(bfa_fcs_vport_sm_error
), BFA_FCS_VPORT_ERROR
}
5307 bfa_fcs_vport_sm_uninit(struct bfa_fcs_vport_s
*vport
,
5308 enum bfa_fcs_vport_event event
)
5310 bfa_trc(__vport_fcs(vport
), __vport_pwwn(vport
));
5311 bfa_trc(__vport_fcs(vport
), event
);
5314 case BFA_FCS_VPORT_SM_CREATE
:
5315 bfa_sm_set_state(vport
, bfa_fcs_vport_sm_created
);
5316 bfa_fcs_fabric_addvport(__vport_fabric(vport
), vport
);
5320 bfa_sm_fault(__vport_fcs(vport
), event
);
5325 * Created state - a start event is required to start up the state machine.
5328 bfa_fcs_vport_sm_created(struct bfa_fcs_vport_s
*vport
,
5329 enum bfa_fcs_vport_event event
)
5331 bfa_trc(__vport_fcs(vport
), __vport_pwwn(vport
));
5332 bfa_trc(__vport_fcs(vport
), event
);
5335 case BFA_FCS_VPORT_SM_START
:
5336 if (bfa_sm_cmp_state(__vport_fabric(vport
),
5337 bfa_fcs_fabric_sm_online
)
5338 && bfa_fcs_fabric_npiv_capable(__vport_fabric(vport
))) {
5339 bfa_sm_set_state(vport
, bfa_fcs_vport_sm_fdisc
);
5340 bfa_fcs_vport_do_fdisc(vport
);
5343 * Fabric is offline or not NPIV capable, stay in
5346 vport
->vport_stats
.fab_no_npiv
++;
5347 bfa_sm_set_state(vport
, bfa_fcs_vport_sm_offline
);
5351 case BFA_FCS_VPORT_SM_DELETE
:
5352 bfa_sm_set_state(vport
, bfa_fcs_vport_sm_cleanup
);
5353 bfa_fcs_lport_delete(&vport
->lport
);
5356 case BFA_FCS_VPORT_SM_ONLINE
:
5357 case BFA_FCS_VPORT_SM_OFFLINE
:
5359 * Ignore ONLINE/OFFLINE events from fabric
5360 * till vport is started.
5365 bfa_sm_fault(__vport_fcs(vport
), event
);
5370 * Offline state - awaiting ONLINE event from fabric SM.
5373 bfa_fcs_vport_sm_offline(struct bfa_fcs_vport_s
*vport
,
5374 enum bfa_fcs_vport_event event
)
5376 bfa_trc(__vport_fcs(vport
), __vport_pwwn(vport
));
5377 bfa_trc(__vport_fcs(vport
), event
);
5380 case BFA_FCS_VPORT_SM_DELETE
:
5381 bfa_sm_set_state(vport
, bfa_fcs_vport_sm_cleanup
);
5382 bfa_fcs_lport_delete(&vport
->lport
);
5385 case BFA_FCS_VPORT_SM_ONLINE
:
5386 bfa_sm_set_state(vport
, bfa_fcs_vport_sm_fdisc
);
5387 vport
->fdisc_retries
= 0;
5388 bfa_fcs_vport_do_fdisc(vport
);
5391 case BFA_FCS_VPORT_SM_STOP
:
5392 bfa_sm_set_state(vport
, bfa_fcs_vport_sm_cleanup
);
5393 bfa_sm_send_event(&vport
->lport
, BFA_FCS_PORT_SM_STOP
);
5396 case BFA_FCS_VPORT_SM_OFFLINE
:
5398 * This can happen if the vport couldn't be initialzied
5399 * due the fact that the npiv was not enabled on the switch.
5400 * In that case we will put the vport in offline state.
5401 * However, the link can go down and cause the this event to
5402 * be sent when we are already offline. Ignore it.
5407 bfa_sm_fault(__vport_fcs(vport
), event
);
5413 * FDISC is sent and awaiting reply from fabric.
5416 bfa_fcs_vport_sm_fdisc(struct bfa_fcs_vport_s
*vport
,
5417 enum bfa_fcs_vport_event event
)
5419 bfa_trc(__vport_fcs(vport
), __vport_pwwn(vport
));
5420 bfa_trc(__vport_fcs(vport
), event
);
5423 case BFA_FCS_VPORT_SM_DELETE
:
5424 bfa_sm_set_state(vport
, bfa_fcs_vport_sm_fdisc_rsp_wait
);
5427 case BFA_FCS_VPORT_SM_OFFLINE
:
5428 bfa_sm_set_state(vport
, bfa_fcs_vport_sm_offline
);
5429 bfa_sm_send_event(vport
->lps
, BFA_LPS_SM_OFFLINE
);
5432 case BFA_FCS_VPORT_SM_RSP_OK
:
5433 bfa_sm_set_state(vport
, bfa_fcs_vport_sm_online
);
5434 bfa_fcs_lport_online(&vport
->lport
);
5437 case BFA_FCS_VPORT_SM_RSP_ERROR
:
5438 bfa_sm_set_state(vport
, bfa_fcs_vport_sm_fdisc_retry
);
5439 bfa_timer_start(__vport_bfa(vport
), &vport
->timer
,
5440 bfa_fcs_vport_timeout
, vport
,
5441 BFA_FCS_RETRY_TIMEOUT
);
5444 case BFA_FCS_VPORT_SM_RSP_FAILED
:
5445 bfa_sm_set_state(vport
, bfa_fcs_vport_sm_offline
);
5448 case BFA_FCS_VPORT_SM_RSP_DUP_WWN
:
5449 bfa_sm_set_state(vport
, bfa_fcs_vport_sm_error
);
5453 bfa_sm_fault(__vport_fcs(vport
), event
);
5458 * FDISC attempt failed - a timer is active to retry FDISC.
5461 bfa_fcs_vport_sm_fdisc_retry(struct bfa_fcs_vport_s
*vport
,
5462 enum bfa_fcs_vport_event event
)
5464 bfa_trc(__vport_fcs(vport
), __vport_pwwn(vport
));
5465 bfa_trc(__vport_fcs(vport
), event
);
5468 case BFA_FCS_VPORT_SM_DELETE
:
5469 bfa_sm_set_state(vport
, bfa_fcs_vport_sm_cleanup
);
5470 bfa_timer_stop(&vport
->timer
);
5471 bfa_fcs_lport_delete(&vport
->lport
);
5474 case BFA_FCS_VPORT_SM_OFFLINE
:
5475 bfa_sm_set_state(vport
, bfa_fcs_vport_sm_offline
);
5476 bfa_timer_stop(&vport
->timer
);
5479 case BFA_FCS_VPORT_SM_TIMEOUT
:
5480 bfa_sm_set_state(vport
, bfa_fcs_vport_sm_fdisc
);
5481 vport
->vport_stats
.fdisc_retries
++;
5482 vport
->fdisc_retries
++;
5483 bfa_fcs_vport_do_fdisc(vport
);
5487 bfa_sm_fault(__vport_fcs(vport
), event
);
5492 * FDISC is in progress and we got a vport delete request -
5493 * this is a wait state while we wait for fdisc response and
5494 * we will transition to the appropriate state - on rsp status.
5497 bfa_fcs_vport_sm_fdisc_rsp_wait(struct bfa_fcs_vport_s
*vport
,
5498 enum bfa_fcs_vport_event event
)
5500 bfa_trc(__vport_fcs(vport
), __vport_pwwn(vport
));
5501 bfa_trc(__vport_fcs(vport
), event
);
5504 case BFA_FCS_VPORT_SM_RSP_OK
:
5505 bfa_sm_set_state(vport
, bfa_fcs_vport_sm_deleting
);
5506 bfa_fcs_lport_delete(&vport
->lport
);
5509 case BFA_FCS_VPORT_SM_DELETE
:
5512 case BFA_FCS_VPORT_SM_OFFLINE
:
5513 case BFA_FCS_VPORT_SM_RSP_ERROR
:
5514 case BFA_FCS_VPORT_SM_RSP_FAILED
:
5515 case BFA_FCS_VPORT_SM_RSP_DUP_WWN
:
5516 bfa_sm_set_state(vport
, bfa_fcs_vport_sm_cleanup
);
5517 bfa_sm_send_event(vport
->lps
, BFA_LPS_SM_OFFLINE
);
5518 bfa_fcs_lport_delete(&vport
->lport
);
5522 bfa_sm_fault(__vport_fcs(vport
), event
);
5527 * Vport is online (FDISC is complete).
5530 bfa_fcs_vport_sm_online(struct bfa_fcs_vport_s
*vport
,
5531 enum bfa_fcs_vport_event event
)
5533 bfa_trc(__vport_fcs(vport
), __vport_pwwn(vport
));
5534 bfa_trc(__vport_fcs(vport
), event
);
5537 case BFA_FCS_VPORT_SM_DELETE
:
5538 bfa_sm_set_state(vport
, bfa_fcs_vport_sm_deleting
);
5539 bfa_fcs_lport_delete(&vport
->lport
);
5542 case BFA_FCS_VPORT_SM_STOP
:
5543 bfa_sm_set_state(vport
, bfa_fcs_vport_sm_stopping
);
5544 bfa_sm_send_event(&vport
->lport
, BFA_FCS_PORT_SM_STOP
);
5547 case BFA_FCS_VPORT_SM_OFFLINE
:
5548 bfa_sm_set_state(vport
, bfa_fcs_vport_sm_offline
);
5549 bfa_sm_send_event(vport
->lps
, BFA_LPS_SM_OFFLINE
);
5550 bfa_fcs_lport_offline(&vport
->lport
);
5554 bfa_sm_fault(__vport_fcs(vport
), event
);
5559 * Vport is being stopped - awaiting lport stop completion to send
5563 bfa_fcs_vport_sm_stopping(struct bfa_fcs_vport_s
*vport
,
5564 enum bfa_fcs_vport_event event
)
5566 bfa_trc(__vport_fcs(vport
), __vport_pwwn(vport
));
5567 bfa_trc(__vport_fcs(vport
), event
);
5570 case BFA_FCS_VPORT_SM_STOPCOMP
:
5571 bfa_sm_set_state(vport
, bfa_fcs_vport_sm_logo_for_stop
);
5572 bfa_fcs_vport_do_logo(vport
);
5575 case BFA_FCS_VPORT_SM_OFFLINE
:
5576 bfa_sm_set_state(vport
, bfa_fcs_vport_sm_cleanup
);
5580 bfa_sm_fault(__vport_fcs(vport
), event
);
5585 * Vport is being deleted - awaiting lport delete completion to send
5589 bfa_fcs_vport_sm_deleting(struct bfa_fcs_vport_s
*vport
,
5590 enum bfa_fcs_vport_event event
)
5592 bfa_trc(__vport_fcs(vport
), __vport_pwwn(vport
));
5593 bfa_trc(__vport_fcs(vport
), event
);
5596 case BFA_FCS_VPORT_SM_DELETE
:
5599 case BFA_FCS_VPORT_SM_DELCOMP
:
5600 bfa_sm_set_state(vport
, bfa_fcs_vport_sm_logo
);
5601 bfa_fcs_vport_do_logo(vport
);
5604 case BFA_FCS_VPORT_SM_OFFLINE
:
5605 bfa_sm_set_state(vport
, bfa_fcs_vport_sm_cleanup
);
5609 bfa_sm_fault(__vport_fcs(vport
), event
);
5615 * This state will be set when the Vport Creation fails due
5616 * to errors like Dup WWN. In this state only operation allowed
5617 * is a Vport Delete.
5620 bfa_fcs_vport_sm_error(struct bfa_fcs_vport_s
*vport
,
5621 enum bfa_fcs_vport_event event
)
5623 bfa_trc(__vport_fcs(vport
), __vport_pwwn(vport
));
5624 bfa_trc(__vport_fcs(vport
), event
);
5627 case BFA_FCS_VPORT_SM_DELETE
:
5628 bfa_sm_set_state(vport
, bfa_fcs_vport_sm_cleanup
);
5629 bfa_fcs_lport_delete(&vport
->lport
);
5633 bfa_trc(__vport_fcs(vport
), event
);
5638 * Lport cleanup is in progress since vport is being deleted. Fabric is
5639 * offline, so no LOGO is needed to complete vport deletion.
5642 bfa_fcs_vport_sm_cleanup(struct bfa_fcs_vport_s
*vport
,
5643 enum bfa_fcs_vport_event event
)
5645 bfa_trc(__vport_fcs(vport
), __vport_pwwn(vport
));
5646 bfa_trc(__vport_fcs(vport
), event
);
5649 case BFA_FCS_VPORT_SM_DELCOMP
:
5650 bfa_sm_set_state(vport
, bfa_fcs_vport_sm_uninit
);
5651 bfa_fcs_vport_free(vport
);
5654 case BFA_FCS_VPORT_SM_STOPCOMP
:
5655 bfa_sm_set_state(vport
, bfa_fcs_vport_sm_created
);
5658 case BFA_FCS_VPORT_SM_DELETE
:
5662 bfa_sm_fault(__vport_fcs(vport
), event
);
5667 * LOGO is sent to fabric. Vport stop is in progress. Lport stop cleanup
5671 bfa_fcs_vport_sm_logo_for_stop(struct bfa_fcs_vport_s
*vport
,
5672 enum bfa_fcs_vport_event event
)
5674 bfa_trc(__vport_fcs(vport
), __vport_pwwn(vport
));
5675 bfa_trc(__vport_fcs(vport
), event
);
5678 case BFA_FCS_VPORT_SM_OFFLINE
:
5679 bfa_sm_send_event(vport
->lps
, BFA_LPS_SM_OFFLINE
);
5681 * !!! fall through !!!
5684 case BFA_FCS_VPORT_SM_RSP_OK
:
5685 case BFA_FCS_VPORT_SM_RSP_ERROR
:
5686 bfa_sm_set_state(vport
, bfa_fcs_vport_sm_created
);
5690 bfa_sm_fault(__vport_fcs(vport
), event
);
5695 * LOGO is sent to fabric. Vport delete is in progress. Lport delete cleanup
5699 bfa_fcs_vport_sm_logo(struct bfa_fcs_vport_s
*vport
,
5700 enum bfa_fcs_vport_event event
)
5702 bfa_trc(__vport_fcs(vport
), __vport_pwwn(vport
));
5703 bfa_trc(__vport_fcs(vport
), event
);
5706 case BFA_FCS_VPORT_SM_OFFLINE
:
5707 bfa_sm_send_event(vport
->lps
, BFA_LPS_SM_OFFLINE
);
5709 * !!! fall through !!!
5712 case BFA_FCS_VPORT_SM_RSP_OK
:
5713 case BFA_FCS_VPORT_SM_RSP_ERROR
:
5714 bfa_sm_set_state(vport
, bfa_fcs_vport_sm_uninit
);
5715 bfa_fcs_vport_free(vport
);
5718 case BFA_FCS_VPORT_SM_DELETE
:
5722 bfa_sm_fault(__vport_fcs(vport
), event
);
5729 * fcs_vport_private FCS virtual port private functions
5732 * Send AEN notification
5735 bfa_fcs_vport_aen_post(struct bfa_fcs_lport_s
*port
,
5736 enum bfa_lport_aen_event event
)
5738 struct bfad_s
*bfad
= (struct bfad_s
*)port
->fabric
->fcs
->bfad
;
5739 struct bfa_aen_entry_s
*aen_entry
;
5741 bfad_get_aen_entry(bfad
, aen_entry
);
5745 aen_entry
->aen_data
.lport
.vf_id
= port
->fabric
->vf_id
;
5746 aen_entry
->aen_data
.lport
.roles
= port
->port_cfg
.roles
;
5747 aen_entry
->aen_data
.lport
.ppwwn
= bfa_fcs_lport_get_pwwn(
5748 bfa_fcs_get_base_port(port
->fcs
));
5749 aen_entry
->aen_data
.lport
.lpwwn
= bfa_fcs_lport_get_pwwn(port
);
5751 /* Send the AEN notification */
5752 bfad_im_post_vendor_event(aen_entry
, bfad
, ++port
->fcs
->fcs_aen_seq
,
5753 BFA_AEN_CAT_LPORT
, event
);
5757 * This routine will be called to send a FDISC command.
5760 bfa_fcs_vport_do_fdisc(struct bfa_fcs_vport_s
*vport
)
5762 bfa_lps_fdisc(vport
->lps
, vport
,
5763 bfa_fcport_get_maxfrsize(__vport_bfa(vport
)),
5764 __vport_pwwn(vport
), __vport_nwwn(vport
));
5765 vport
->vport_stats
.fdisc_sent
++;
5769 bfa_fcs_vport_fdisc_rejected(struct bfa_fcs_vport_s
*vport
)
5771 u8 lsrjt_rsn
= vport
->lps
->lsrjt_rsn
;
5772 u8 lsrjt_expl
= vport
->lps
->lsrjt_expl
;
5774 bfa_trc(__vport_fcs(vport
), lsrjt_rsn
);
5775 bfa_trc(__vport_fcs(vport
), lsrjt_expl
);
5777 /* For certain reason codes, we don't want to retry. */
5778 switch (vport
->lps
->lsrjt_expl
) {
5779 case FC_LS_RJT_EXP_INV_PORT_NAME
: /* by brocade */
5780 case FC_LS_RJT_EXP_INVALID_NPORT_ID
: /* by Cisco */
5781 if (vport
->fdisc_retries
< BFA_FCS_VPORT_MAX_RETRIES
)
5782 bfa_sm_send_event(vport
, BFA_FCS_VPORT_SM_RSP_ERROR
);
5784 bfa_fcs_vport_aen_post(&vport
->lport
,
5785 BFA_LPORT_AEN_NPIV_DUP_WWN
);
5786 bfa_sm_send_event(vport
, BFA_FCS_VPORT_SM_RSP_DUP_WWN
);
5790 case FC_LS_RJT_EXP_INSUFF_RES
:
5792 * This means max logins per port/switch setting on the
5793 * switch was exceeded.
5795 if (vport
->fdisc_retries
< BFA_FCS_VPORT_MAX_RETRIES
)
5796 bfa_sm_send_event(vport
, BFA_FCS_VPORT_SM_RSP_ERROR
);
5798 bfa_fcs_vport_aen_post(&vport
->lport
,
5799 BFA_LPORT_AEN_NPIV_FABRIC_MAX
);
5800 bfa_sm_send_event(vport
, BFA_FCS_VPORT_SM_RSP_FAILED
);
5805 if (vport
->fdisc_retries
== 0)
5806 bfa_fcs_vport_aen_post(&vport
->lport
,
5807 BFA_LPORT_AEN_NPIV_UNKNOWN
);
5808 bfa_sm_send_event(vport
, BFA_FCS_VPORT_SM_RSP_ERROR
);
5813 * Called to send a logout to the fabric. Used when a V-Port is
5817 bfa_fcs_vport_do_logo(struct bfa_fcs_vport_s
*vport
)
5819 bfa_trc(__vport_fcs(vport
), __vport_pwwn(vport
));
5821 vport
->vport_stats
.logo_sent
++;
5822 bfa_lps_fdisclogo(vport
->lps
);
5827 * This routine will be called by bfa_timer on timer timeouts.
5829 * param[in] vport - pointer to bfa_fcs_vport_t.
5830 * param[out] vport_status - pointer to return vport status in
5835 * Special Considerations:
5840 bfa_fcs_vport_timeout(void *vport_arg
)
5842 struct bfa_fcs_vport_s
*vport
= (struct bfa_fcs_vport_s
*) vport_arg
;
5844 vport
->vport_stats
.fdisc_timeouts
++;
5845 bfa_sm_send_event(vport
, BFA_FCS_VPORT_SM_TIMEOUT
);
5849 bfa_fcs_vport_free(struct bfa_fcs_vport_s
*vport
)
5851 struct bfad_vport_s
*vport_drv
=
5852 (struct bfad_vport_s
*)vport
->vport_drv
;
5854 bfa_fcs_fabric_delvport(__vport_fabric(vport
), vport
);
5855 bfa_lps_delete(vport
->lps
);
5857 if (vport_drv
->comp_del
) {
5858 complete(vport_drv
->comp_del
);
5863 * We queue the vport delete work to the IM work_q from here.
5864 * The memory for the bfad_vport_s is freed from the FC function
5865 * template vport_delete entry point.
5867 bfad_im_port_delete(vport_drv
->drv_port
.bfad
, &vport_drv
->drv_port
);
5871 * fcs_vport_public FCS virtual port public interfaces
5875 * Online notification from fabric SM.
5878 bfa_fcs_vport_online(struct bfa_fcs_vport_s
*vport
)
5880 vport
->vport_stats
.fab_online
++;
5881 if (bfa_fcs_fabric_npiv_capable(__vport_fabric(vport
)))
5882 bfa_sm_send_event(vport
, BFA_FCS_VPORT_SM_ONLINE
);
5884 vport
->vport_stats
.fab_no_npiv
++;
5888 * Offline notification from fabric SM.
5891 bfa_fcs_vport_offline(struct bfa_fcs_vport_s
*vport
)
5893 vport
->vport_stats
.fab_offline
++;
5894 bfa_sm_send_event(vport
, BFA_FCS_VPORT_SM_OFFLINE
);
5898 * Cleanup notification from fabric SM on link timer expiry.
5901 bfa_fcs_vport_cleanup(struct bfa_fcs_vport_s
*vport
)
5903 vport
->vport_stats
.fab_cleanup
++;
5907 * Stop notification from fabric SM. To be invoked from within FCS.
5910 bfa_fcs_vport_fcs_stop(struct bfa_fcs_vport_s
*vport
)
5912 bfa_sm_send_event(vport
, BFA_FCS_VPORT_SM_STOP
);
5916 * delete notification from fabric SM. To be invoked from within FCS.
5919 bfa_fcs_vport_fcs_delete(struct bfa_fcs_vport_s
*vport
)
5921 bfa_sm_send_event(vport
, BFA_FCS_VPORT_SM_DELETE
);
5925 * Stop completion callback from associated lport
5928 bfa_fcs_vport_stop_comp(struct bfa_fcs_vport_s
*vport
)
5930 bfa_sm_send_event(vport
, BFA_FCS_VPORT_SM_STOPCOMP
);
5934 * Delete completion callback from associated lport
5937 bfa_fcs_vport_delete_comp(struct bfa_fcs_vport_s
*vport
)
5939 bfa_sm_send_event(vport
, BFA_FCS_VPORT_SM_DELCOMP
);
5945 * fcs_vport_api Virtual port API
5949 * Use this function to instantiate a new FCS vport object. This
5950 * function will not trigger any HW initialization process (which will be
5951 * done in vport_start() call)
5953 * param[in] vport - pointer to bfa_fcs_vport_t. This space
5954 * needs to be allocated by the driver.
5955 * param[in] fcs - FCS instance
5956 * param[in] vport_cfg - vport configuration
5957 * param[in] vf_id - VF_ID if vport is created within a VF.
5958 * FC_VF_ID_NULL to specify base fabric.
5959 * param[in] vport_drv - Opaque handle back to the driver's vport
5962 * retval BFA_STATUS_OK - on success.
5963 * retval BFA_STATUS_FAILED - on failure.
5966 bfa_fcs_vport_create(struct bfa_fcs_vport_s
*vport
, struct bfa_fcs_s
*fcs
,
5967 u16 vf_id
, struct bfa_lport_cfg_s
*vport_cfg
,
5968 struct bfad_vport_s
*vport_drv
)
5970 if (vport_cfg
->pwwn
== 0)
5971 return BFA_STATUS_INVALID_WWN
;
5973 if (bfa_fcs_lport_get_pwwn(&fcs
->fabric
.bport
) == vport_cfg
->pwwn
)
5974 return BFA_STATUS_VPORT_WWN_BP
;
5976 if (bfa_fcs_vport_lookup(fcs
, vf_id
, vport_cfg
->pwwn
) != NULL
)
5977 return BFA_STATUS_VPORT_EXISTS
;
5979 if (fcs
->fabric
.num_vports
==
5980 bfa_lps_get_max_vport(fcs
->bfa
))
5981 return BFA_STATUS_VPORT_MAX
;
5983 vport
->lps
= bfa_lps_alloc(fcs
->bfa
);
5985 return BFA_STATUS_VPORT_MAX
;
5987 vport
->vport_drv
= vport_drv
;
5988 vport_cfg
->preboot_vp
= BFA_FALSE
;
5990 bfa_sm_set_state(vport
, bfa_fcs_vport_sm_uninit
);
5991 bfa_fcs_lport_attach(&vport
->lport
, fcs
, vf_id
, vport
);
5992 bfa_fcs_lport_init(&vport
->lport
, vport_cfg
);
5993 bfa_sm_send_event(vport
, BFA_FCS_VPORT_SM_CREATE
);
5995 return BFA_STATUS_OK
;
5999 * Use this function to instantiate a new FCS PBC vport object. This
6000 * function will not trigger any HW initialization process (which will be
6001 * done in vport_start() call)
6003 * param[in] vport - pointer to bfa_fcs_vport_t. This space
6004 * needs to be allocated by the driver.
6005 * param[in] fcs - FCS instance
6006 * param[in] vport_cfg - vport configuration
6007 * param[in] vf_id - VF_ID if vport is created within a VF.
6008 * FC_VF_ID_NULL to specify base fabric.
6009 * param[in] vport_drv - Opaque handle back to the driver's vport
6012 * retval BFA_STATUS_OK - on success.
6013 * retval BFA_STATUS_FAILED - on failure.
6016 bfa_fcs_pbc_vport_create(struct bfa_fcs_vport_s
*vport
, struct bfa_fcs_s
*fcs
,
6017 u16 vf_id
, struct bfa_lport_cfg_s
*vport_cfg
,
6018 struct bfad_vport_s
*vport_drv
)
6022 rc
= bfa_fcs_vport_create(vport
, fcs
, vf_id
, vport_cfg
, vport_drv
);
6023 vport
->lport
.port_cfg
.preboot_vp
= BFA_TRUE
;
6029 * Use this function to findout if this is a pbc vport or not.
6031 * @param[in] vport - pointer to bfa_fcs_vport_t.
6036 bfa_fcs_is_pbc_vport(struct bfa_fcs_vport_s
*vport
)
6039 if (vport
&& (vport
->lport
.port_cfg
.preboot_vp
== BFA_TRUE
))
6047 * Use this function initialize the vport.
6049 * @param[in] vport - pointer to bfa_fcs_vport_t.
6054 bfa_fcs_vport_start(struct bfa_fcs_vport_s
*vport
)
6056 bfa_sm_send_event(vport
, BFA_FCS_VPORT_SM_START
);
6058 return BFA_STATUS_OK
;
6062 * Use this function quiese the vport object. This function will return
6063 * immediately, when the vport is actually stopped, the
6064 * bfa_drv_vport_stop_cb() will be called.
6066 * param[in] vport - pointer to bfa_fcs_vport_t.
6071 bfa_fcs_vport_stop(struct bfa_fcs_vport_s
*vport
)
6073 bfa_sm_send_event(vport
, BFA_FCS_VPORT_SM_STOP
);
6075 return BFA_STATUS_OK
;
6079 * Use this function to delete a vport object. Fabric object should
6080 * be stopped before this function call.
6082 * !!!!!!! Donot invoke this from within FCS !!!!!!!
6084 * param[in] vport - pointer to bfa_fcs_vport_t.
6089 bfa_fcs_vport_delete(struct bfa_fcs_vport_s
*vport
)
6092 if (vport
->lport
.port_cfg
.preboot_vp
)
6093 return BFA_STATUS_PBC
;
6095 bfa_sm_send_event(vport
, BFA_FCS_VPORT_SM_DELETE
);
6097 return BFA_STATUS_OK
;
6101 * Use this function to get vport's current status info.
6103 * param[in] vport pointer to bfa_fcs_vport_t.
6104 * param[out] attr pointer to return vport attributes
6109 bfa_fcs_vport_get_attr(struct bfa_fcs_vport_s
*vport
,
6110 struct bfa_vport_attr_s
*attr
)
6112 if (vport
== NULL
|| attr
== NULL
)
6115 memset(attr
, 0, sizeof(struct bfa_vport_attr_s
));
6117 bfa_fcs_lport_get_attr(&vport
->lport
, &attr
->port_attr
);
6118 attr
->vport_state
= bfa_sm_to_state(vport_sm_table
, vport
->sm
);
6123 * Lookup a virtual port. Excludes base port from lookup.
6125 struct bfa_fcs_vport_s
*
6126 bfa_fcs_vport_lookup(struct bfa_fcs_s
*fcs
, u16 vf_id
, wwn_t vpwwn
)
6128 struct bfa_fcs_vport_s
*vport
;
6129 struct bfa_fcs_fabric_s
*fabric
;
6131 bfa_trc(fcs
, vf_id
);
6132 bfa_trc(fcs
, vpwwn
);
6134 fabric
= bfa_fcs_vf_lookup(fcs
, vf_id
);
6136 bfa_trc(fcs
, vf_id
);
6140 vport
= bfa_fcs_fabric_vport_lookup(fabric
, vpwwn
);
6148 bfa_cb_lps_fdisc_comp(void *bfad
, void *uarg
, bfa_status_t status
)
6150 struct bfa_fcs_vport_s
*vport
= uarg
;
6152 bfa_trc(__vport_fcs(vport
), __vport_pwwn(vport
));
6153 bfa_trc(__vport_fcs(vport
), status
);
6158 * Initialize the V-Port fields
6160 __vport_fcid(vport
) = vport
->lps
->lp_pid
;
6161 vport
->vport_stats
.fdisc_accepts
++;
6162 bfa_sm_send_event(vport
, BFA_FCS_VPORT_SM_RSP_OK
);
6165 case BFA_STATUS_INVALID_MAC
:
6167 vport
->vport_stats
.fdisc_acc_bad
++;
6168 bfa_sm_send_event(vport
, BFA_FCS_VPORT_SM_RSP_ERROR
);
6172 case BFA_STATUS_EPROTOCOL
:
6173 switch (vport
->lps
->ext_status
) {
6174 case BFA_EPROTO_BAD_ACCEPT
:
6175 vport
->vport_stats
.fdisc_acc_bad
++;
6178 case BFA_EPROTO_UNKNOWN_RSP
:
6179 vport
->vport_stats
.fdisc_unknown_rsp
++;
6186 bfa_sm_send_event(vport
, BFA_FCS_VPORT_SM_RSP_ERROR
);
6189 case BFA_STATUS_FABRIC_RJT
:
6190 vport
->vport_stats
.fdisc_rejects
++;
6191 bfa_fcs_vport_fdisc_rejected(vport
);
6195 vport
->vport_stats
.fdisc_rsp_err
++;
6196 bfa_sm_send_event(vport
, BFA_FCS_VPORT_SM_RSP_ERROR
);
6204 bfa_cb_lps_fdisclogo_comp(void *bfad
, void *uarg
)
6206 struct bfa_fcs_vport_s
*vport
= uarg
;
6207 bfa_sm_send_event(vport
, BFA_FCS_VPORT_SM_RSP_OK
);
6211 * Received clear virtual link
6214 bfa_cb_lps_cvl_event(void *bfad
, void *uarg
)
6216 struct bfa_fcs_vport_s
*vport
= uarg
;
6218 /* Send an Offline followed by an ONLINE */
6219 bfa_sm_send_event(vport
, BFA_FCS_VPORT_SM_OFFLINE
);
6220 bfa_sm_send_event(vport
, BFA_FCS_VPORT_SM_ONLINE
);