2 * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
6 * Linux driver for Brocade Fibre Channel Host Bus Adapter.
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License (GPL) Version 2 as
10 * published by the Free Software Foundation
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
19 * bfa_fcs.c BFA FCS main
25 #include "bfa_fcbuild.h"
27 BFA_TRC_FILE(FCS
, FCS
);
32 struct bfa_fcs_mod_s
{
33 void (*attach
) (struct bfa_fcs_s
*fcs
);
34 void (*modinit
) (struct bfa_fcs_s
*fcs
);
35 void (*modexit
) (struct bfa_fcs_s
*fcs
);
38 #define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
40 static struct bfa_fcs_mod_s fcs_modules
[] = {
41 { bfa_fcs_port_attach
, NULL
, NULL
},
42 { bfa_fcs_uf_attach
, NULL
, NULL
},
43 { bfa_fcs_fabric_attach
, bfa_fcs_fabric_modinit
,
44 bfa_fcs_fabric_modexit
},
52 bfa_fcs_exit_comp(void *fcs_cbarg
)
54 struct bfa_fcs_s
*fcs
= fcs_cbarg
;
55 struct bfad_s
*bfad
= fcs
->bfad
;
57 complete(&bfad
->comp
);
67 * fcs attach -- called once to initialize data structures at driver attach time
70 bfa_fcs_attach(struct bfa_fcs_s
*fcs
, struct bfa_s
*bfa
, struct bfad_s
*bfad
,
71 bfa_boolean_t min_cfg
)
74 struct bfa_fcs_mod_s
*mod
;
78 fcs
->min_cfg
= min_cfg
;
79 fcs
->num_rport_logins
= 0;
84 for (i
= 0; i
< sizeof(fcs_modules
) / sizeof(fcs_modules
[0]); i
++) {
85 mod
= &fcs_modules
[i
];
92 * fcs initialization, called once after bfa initialization is complete
95 bfa_fcs_init(struct bfa_fcs_s
*fcs
)
98 struct bfa_fcs_mod_s
*mod
;
100 for (i
= 0; i
< sizeof(fcs_modules
) / sizeof(fcs_modules
[0]); i
++) {
101 mod
= &fcs_modules
[i
];
108 * FCS update cfg - reset the pwwn/nwwn of fabric base logical port
109 * with values learned during bfa_init firmware GETATTR REQ.
112 bfa_fcs_update_cfg(struct bfa_fcs_s
*fcs
)
114 struct bfa_fcs_fabric_s
*fabric
= &fcs
->fabric
;
115 struct bfa_lport_cfg_s
*port_cfg
= &fabric
->bport
.port_cfg
;
116 struct bfa_ioc_s
*ioc
= &fabric
->fcs
->bfa
->ioc
;
118 port_cfg
->nwwn
= ioc
->attr
->nwwn
;
119 port_cfg
->pwwn
= ioc
->attr
->pwwn
;
123 * Stop FCS operations.
126 bfa_fcs_stop(struct bfa_fcs_s
*fcs
)
128 bfa_wc_init(&fcs
->wc
, bfa_fcs_exit_comp
, fcs
);
130 bfa_fcs_fabric_modstop(fcs
);
131 bfa_wc_wait(&fcs
->wc
);
135 * fcs pbc vport initialization
138 bfa_fcs_pbc_vport_init(struct bfa_fcs_s
*fcs
)
141 struct bfi_pbc_vport_s pbc_vports
[BFI_PBC_MAX_VPORTS
];
143 /* Initialize pbc vports */
146 bfa_iocfc_get_pbc_vports(fcs
->bfa
, pbc_vports
);
147 for (i
= 0; i
< npbc_vports
; i
++)
148 bfa_fcb_pbc_vport_create(fcs
->bfa
->bfad
, pbc_vports
[i
]);
154 * FCS driver details initialization.
156 * param[in] fcs FCS instance
157 * param[in] driver_info Driver Details
162 bfa_fcs_driver_info_init(struct bfa_fcs_s
*fcs
,
163 struct bfa_fcs_driver_info_s
*driver_info
)
166 fcs
->driver_info
= *driver_info
;
168 bfa_fcs_fabric_psymb_init(&fcs
->fabric
);
169 bfa_fcs_fabric_nsymb_init(&fcs
->fabric
);
174 * FCS instance cleanup and exit.
176 * param[in] fcs FCS instance
180 bfa_fcs_exit(struct bfa_fcs_s
*fcs
)
182 struct bfa_fcs_mod_s
*mod
;
185 bfa_wc_init(&fcs
->wc
, bfa_fcs_exit_comp
, fcs
);
187 nmods
= sizeof(fcs_modules
) / sizeof(fcs_modules
[0]);
189 for (i
= 0; i
< nmods
; i
++) {
191 mod
= &fcs_modules
[i
];
198 bfa_wc_wait(&fcs
->wc
);
203 * Fabric module implementation.
206 #define BFA_FCS_FABRIC_RETRY_DELAY (2000) /* Milliseconds */
207 #define BFA_FCS_FABRIC_CLEANUP_DELAY (10000) /* Milliseconds */
209 #define bfa_fcs_fabric_set_opertype(__fabric) do { \
210 if (bfa_fcport_get_topology((__fabric)->fcs->bfa) \
211 == BFA_PORT_TOPOLOGY_P2P) { \
212 if (fabric->fab_type == BFA_FCS_FABRIC_SWITCHED) \
213 (__fabric)->oper_type = BFA_PORT_TYPE_NPORT; \
215 (__fabric)->oper_type = BFA_PORT_TYPE_P2P; \
217 (__fabric)->oper_type = BFA_PORT_TYPE_NLPORT; \
221 * forward declarations
223 static void bfa_fcs_fabric_init(struct bfa_fcs_fabric_s
*fabric
);
224 static void bfa_fcs_fabric_login(struct bfa_fcs_fabric_s
*fabric
);
225 static void bfa_fcs_fabric_notify_online(struct bfa_fcs_fabric_s
*fabric
);
226 static void bfa_fcs_fabric_notify_offline(struct bfa_fcs_fabric_s
*fabric
);
227 static void bfa_fcs_fabric_delay(void *cbarg
);
228 static void bfa_fcs_fabric_delete(struct bfa_fcs_fabric_s
*fabric
);
229 static void bfa_fcs_fabric_delete_comp(void *cbarg
);
230 static void bfa_fcs_fabric_stop(struct bfa_fcs_fabric_s
*fabric
);
231 static void bfa_fcs_fabric_stop_comp(void *cbarg
);
232 static void bfa_fcs_fabric_process_uf(struct bfa_fcs_fabric_s
*fabric
,
233 struct fchs_s
*fchs
, u16 len
);
234 static void bfa_fcs_fabric_process_flogi(struct bfa_fcs_fabric_s
*fabric
,
235 struct fchs_s
*fchs
, u16 len
);
236 static void bfa_fcs_fabric_send_flogi_acc(struct bfa_fcs_fabric_s
*fabric
);
237 static void bfa_fcs_fabric_flogiacc_comp(void *fcsarg
,
238 struct bfa_fcxp_s
*fcxp
, void *cbarg
,
242 struct fchs_s
*rspfchs
);
243 static u8
bfa_fcs_fabric_oper_bbscn(struct bfa_fcs_fabric_s
*fabric
);
244 static bfa_boolean_t
bfa_fcs_fabric_is_bbscn_enabled(
245 struct bfa_fcs_fabric_s
*fabric
);
247 static void bfa_fcs_fabric_sm_uninit(struct bfa_fcs_fabric_s
*fabric
,
248 enum bfa_fcs_fabric_event event
);
249 static void bfa_fcs_fabric_sm_created(struct bfa_fcs_fabric_s
*fabric
,
250 enum bfa_fcs_fabric_event event
);
251 static void bfa_fcs_fabric_sm_linkdown(struct bfa_fcs_fabric_s
*fabric
,
252 enum bfa_fcs_fabric_event event
);
253 static void bfa_fcs_fabric_sm_flogi(struct bfa_fcs_fabric_s
*fabric
,
254 enum bfa_fcs_fabric_event event
);
255 static void bfa_fcs_fabric_sm_flogi_retry(struct bfa_fcs_fabric_s
*fabric
,
256 enum bfa_fcs_fabric_event event
);
257 static void bfa_fcs_fabric_sm_auth(struct bfa_fcs_fabric_s
*fabric
,
258 enum bfa_fcs_fabric_event event
);
259 static void bfa_fcs_fabric_sm_nofabric(struct bfa_fcs_fabric_s
*fabric
,
260 enum bfa_fcs_fabric_event event
);
261 static void bfa_fcs_fabric_sm_evfp(struct bfa_fcs_fabric_s
*fabric
,
262 enum bfa_fcs_fabric_event event
);
263 static void bfa_fcs_fabric_sm_evfp_done(struct bfa_fcs_fabric_s
*fabric
,
264 enum bfa_fcs_fabric_event event
);
265 static void bfa_fcs_fabric_sm_isolated(struct bfa_fcs_fabric_s
*fabric
,
266 enum bfa_fcs_fabric_event event
);
267 static void bfa_fcs_fabric_sm_deleting(struct bfa_fcs_fabric_s
*fabric
,
268 enum bfa_fcs_fabric_event event
);
269 static void bfa_fcs_fabric_sm_stopping(struct bfa_fcs_fabric_s
*fabric
,
270 enum bfa_fcs_fabric_event event
);
271 static void bfa_fcs_fabric_sm_cleanup(struct bfa_fcs_fabric_s
*fabric
,
272 enum bfa_fcs_fabric_event event
);
274 * Beginning state before fabric creation.
277 bfa_fcs_fabric_sm_uninit(struct bfa_fcs_fabric_s
*fabric
,
278 enum bfa_fcs_fabric_event event
)
280 bfa_trc(fabric
->fcs
, fabric
->bport
.port_cfg
.pwwn
);
281 bfa_trc(fabric
->fcs
, event
);
284 case BFA_FCS_FABRIC_SM_CREATE
:
285 bfa_sm_set_state(fabric
, bfa_fcs_fabric_sm_created
);
286 bfa_fcs_fabric_init(fabric
);
287 bfa_fcs_lport_init(&fabric
->bport
, &fabric
->bport
.port_cfg
);
290 case BFA_FCS_FABRIC_SM_LINK_UP
:
291 case BFA_FCS_FABRIC_SM_LINK_DOWN
:
295 bfa_sm_fault(fabric
->fcs
, event
);
300 * Beginning state before fabric creation.
303 bfa_fcs_fabric_sm_created(struct bfa_fcs_fabric_s
*fabric
,
304 enum bfa_fcs_fabric_event event
)
306 struct bfa_s
*bfa
= fabric
->fcs
->bfa
;
308 bfa_trc(fabric
->fcs
, fabric
->bport
.port_cfg
.pwwn
);
309 bfa_trc(fabric
->fcs
, event
);
312 case BFA_FCS_FABRIC_SM_START
:
313 if (!bfa_fcport_is_linkup(fabric
->fcs
->bfa
)) {
314 bfa_sm_set_state(fabric
, bfa_fcs_fabric_sm_linkdown
);
317 if (bfa_fcport_get_topology(bfa
) ==
318 BFA_PORT_TOPOLOGY_LOOP
) {
319 fabric
->fab_type
= BFA_FCS_FABRIC_LOOP
;
320 fabric
->bport
.pid
= bfa_fcport_get_myalpa(bfa
);
321 fabric
->bport
.pid
= bfa_hton3b(fabric
->bport
.pid
);
322 bfa_sm_set_state(fabric
,
323 bfa_fcs_fabric_sm_online
);
324 bfa_fcs_fabric_set_opertype(fabric
);
325 bfa_fcs_lport_online(&fabric
->bport
);
327 bfa_sm_set_state(fabric
, bfa_fcs_fabric_sm_flogi
);
328 bfa_fcs_fabric_login(fabric
);
332 case BFA_FCS_FABRIC_SM_LINK_UP
:
333 case BFA_FCS_FABRIC_SM_LINK_DOWN
:
336 case BFA_FCS_FABRIC_SM_DELETE
:
337 bfa_sm_set_state(fabric
, bfa_fcs_fabric_sm_deleting
);
338 bfa_fcs_fabric_delete(fabric
);
342 bfa_sm_fault(fabric
->fcs
, event
);
347 * Link is down, awaiting LINK UP event from port. This is also the
348 * first state at fabric creation.
351 bfa_fcs_fabric_sm_linkdown(struct bfa_fcs_fabric_s
*fabric
,
352 enum bfa_fcs_fabric_event event
)
354 struct bfa_s
*bfa
= fabric
->fcs
->bfa
;
356 bfa_trc(fabric
->fcs
, fabric
->bport
.port_cfg
.pwwn
);
357 bfa_trc(fabric
->fcs
, event
);
360 case BFA_FCS_FABRIC_SM_LINK_UP
:
361 if (bfa_fcport_get_topology(bfa
) != BFA_PORT_TOPOLOGY_LOOP
) {
362 bfa_sm_set_state(fabric
, bfa_fcs_fabric_sm_flogi
);
363 bfa_fcs_fabric_login(fabric
);
366 fabric
->fab_type
= BFA_FCS_FABRIC_LOOP
;
367 fabric
->bport
.pid
= bfa_fcport_get_myalpa(bfa
);
368 fabric
->bport
.pid
= bfa_hton3b(fabric
->bport
.pid
);
369 bfa_sm_set_state(fabric
, bfa_fcs_fabric_sm_online
);
370 bfa_fcs_fabric_set_opertype(fabric
);
371 bfa_fcs_lport_online(&fabric
->bport
);
374 case BFA_FCS_FABRIC_SM_RETRY_OP
:
375 case BFA_FCS_FABRIC_SM_LOOPBACK
:
378 case BFA_FCS_FABRIC_SM_DELETE
:
379 bfa_sm_set_state(fabric
, bfa_fcs_fabric_sm_deleting
);
380 bfa_fcs_fabric_delete(fabric
);
383 case BFA_FCS_FABRIC_SM_STOP
:
384 bfa_sm_set_state(fabric
, bfa_fcs_fabric_sm_cleanup
);
385 bfa_fcs_fabric_stop(fabric
);
389 bfa_sm_fault(fabric
->fcs
, event
);
394 * FLOGI is in progress, awaiting FLOGI reply.
397 bfa_fcs_fabric_sm_flogi(struct bfa_fcs_fabric_s
*fabric
,
398 enum bfa_fcs_fabric_event event
)
400 bfa_trc(fabric
->fcs
, fabric
->bport
.port_cfg
.pwwn
);
401 bfa_trc(fabric
->fcs
, event
);
404 case BFA_FCS_FABRIC_SM_CONT_OP
:
406 bfa_fcport_set_tx_bbcredit(fabric
->fcs
->bfa
,
408 bfa_fcs_fabric_oper_bbscn(fabric
));
409 fabric
->fab_type
= BFA_FCS_FABRIC_SWITCHED
;
411 if (fabric
->auth_reqd
&& fabric
->is_auth
) {
412 bfa_sm_set_state(fabric
, bfa_fcs_fabric_sm_auth
);
413 bfa_trc(fabric
->fcs
, event
);
415 bfa_sm_set_state(fabric
, bfa_fcs_fabric_sm_online
);
416 bfa_fcs_fabric_notify_online(fabric
);
420 case BFA_FCS_FABRIC_SM_RETRY_OP
:
421 bfa_sm_set_state(fabric
, bfa_fcs_fabric_sm_flogi_retry
);
422 bfa_timer_start(fabric
->fcs
->bfa
, &fabric
->delay_timer
,
423 bfa_fcs_fabric_delay
, fabric
,
424 BFA_FCS_FABRIC_RETRY_DELAY
);
427 case BFA_FCS_FABRIC_SM_LOOPBACK
:
428 bfa_sm_set_state(fabric
, bfa_fcs_fabric_sm_loopback
);
429 bfa_sm_send_event(fabric
->lps
, BFA_LPS_SM_OFFLINE
);
430 bfa_fcs_fabric_set_opertype(fabric
);
433 case BFA_FCS_FABRIC_SM_NO_FABRIC
:
434 fabric
->fab_type
= BFA_FCS_FABRIC_N2N
;
435 bfa_fcport_set_tx_bbcredit(fabric
->fcs
->bfa
,
437 bfa_fcs_fabric_oper_bbscn(fabric
));
438 bfa_fcs_fabric_notify_online(fabric
);
439 bfa_sm_set_state(fabric
, bfa_fcs_fabric_sm_nofabric
);
442 case BFA_FCS_FABRIC_SM_LINK_DOWN
:
443 bfa_sm_set_state(fabric
, bfa_fcs_fabric_sm_linkdown
);
444 bfa_sm_send_event(fabric
->lps
, BFA_LPS_SM_OFFLINE
);
447 case BFA_FCS_FABRIC_SM_DELETE
:
448 bfa_sm_set_state(fabric
, bfa_fcs_fabric_sm_deleting
);
449 bfa_sm_send_event(fabric
->lps
, BFA_LPS_SM_OFFLINE
);
450 bfa_fcs_fabric_delete(fabric
);
454 bfa_sm_fault(fabric
->fcs
, event
);
460 bfa_fcs_fabric_sm_flogi_retry(struct bfa_fcs_fabric_s
*fabric
,
461 enum bfa_fcs_fabric_event event
)
463 bfa_trc(fabric
->fcs
, fabric
->bport
.port_cfg
.pwwn
);
464 bfa_trc(fabric
->fcs
, event
);
467 case BFA_FCS_FABRIC_SM_DELAYED
:
468 bfa_sm_set_state(fabric
, bfa_fcs_fabric_sm_flogi
);
469 bfa_fcs_fabric_login(fabric
);
472 case BFA_FCS_FABRIC_SM_LINK_DOWN
:
473 bfa_sm_set_state(fabric
, bfa_fcs_fabric_sm_linkdown
);
474 bfa_timer_stop(&fabric
->delay_timer
);
477 case BFA_FCS_FABRIC_SM_DELETE
:
478 bfa_sm_set_state(fabric
, bfa_fcs_fabric_sm_deleting
);
479 bfa_timer_stop(&fabric
->delay_timer
);
480 bfa_fcs_fabric_delete(fabric
);
484 bfa_sm_fault(fabric
->fcs
, event
);
489 * Authentication is in progress, awaiting authentication results.
492 bfa_fcs_fabric_sm_auth(struct bfa_fcs_fabric_s
*fabric
,
493 enum bfa_fcs_fabric_event event
)
495 bfa_trc(fabric
->fcs
, fabric
->bport
.port_cfg
.pwwn
);
496 bfa_trc(fabric
->fcs
, event
);
499 case BFA_FCS_FABRIC_SM_AUTH_FAILED
:
500 bfa_sm_set_state(fabric
, bfa_fcs_fabric_sm_auth_failed
);
501 bfa_sm_send_event(fabric
->lps
, BFA_LPS_SM_OFFLINE
);
504 case BFA_FCS_FABRIC_SM_AUTH_SUCCESS
:
505 bfa_sm_set_state(fabric
, bfa_fcs_fabric_sm_online
);
506 bfa_fcs_fabric_notify_online(fabric
);
509 case BFA_FCS_FABRIC_SM_PERF_EVFP
:
510 bfa_sm_set_state(fabric
, bfa_fcs_fabric_sm_evfp
);
513 case BFA_FCS_FABRIC_SM_LINK_DOWN
:
514 bfa_sm_set_state(fabric
, bfa_fcs_fabric_sm_linkdown
);
515 bfa_sm_send_event(fabric
->lps
, BFA_LPS_SM_OFFLINE
);
518 case BFA_FCS_FABRIC_SM_DELETE
:
519 bfa_sm_set_state(fabric
, bfa_fcs_fabric_sm_deleting
);
520 bfa_fcs_fabric_delete(fabric
);
524 bfa_sm_fault(fabric
->fcs
, event
);
529 * Authentication failed
532 bfa_fcs_fabric_sm_auth_failed(struct bfa_fcs_fabric_s
*fabric
,
533 enum bfa_fcs_fabric_event event
)
535 bfa_trc(fabric
->fcs
, fabric
->bport
.port_cfg
.pwwn
);
536 bfa_trc(fabric
->fcs
, event
);
539 case BFA_FCS_FABRIC_SM_LINK_DOWN
:
540 bfa_sm_set_state(fabric
, bfa_fcs_fabric_sm_linkdown
);
541 bfa_fcs_fabric_notify_offline(fabric
);
544 case BFA_FCS_FABRIC_SM_DELETE
:
545 bfa_sm_set_state(fabric
, bfa_fcs_fabric_sm_deleting
);
546 bfa_fcs_fabric_delete(fabric
);
550 bfa_sm_fault(fabric
->fcs
, event
);
555 * Port is in loopback mode.
558 bfa_fcs_fabric_sm_loopback(struct bfa_fcs_fabric_s
*fabric
,
559 enum bfa_fcs_fabric_event event
)
561 bfa_trc(fabric
->fcs
, fabric
->bport
.port_cfg
.pwwn
);
562 bfa_trc(fabric
->fcs
, event
);
565 case BFA_FCS_FABRIC_SM_LINK_DOWN
:
566 bfa_sm_set_state(fabric
, bfa_fcs_fabric_sm_linkdown
);
567 bfa_fcs_fabric_notify_offline(fabric
);
570 case BFA_FCS_FABRIC_SM_DELETE
:
571 bfa_sm_set_state(fabric
, bfa_fcs_fabric_sm_deleting
);
572 bfa_fcs_fabric_delete(fabric
);
576 bfa_sm_fault(fabric
->fcs
, event
);
581 * There is no attached fabric - private loop or NPort-to-NPort topology.
584 bfa_fcs_fabric_sm_nofabric(struct bfa_fcs_fabric_s
*fabric
,
585 enum bfa_fcs_fabric_event event
)
587 bfa_trc(fabric
->fcs
, fabric
->bport
.port_cfg
.pwwn
);
588 bfa_trc(fabric
->fcs
, event
);
591 case BFA_FCS_FABRIC_SM_LINK_DOWN
:
592 bfa_sm_set_state(fabric
, bfa_fcs_fabric_sm_linkdown
);
593 bfa_sm_send_event(fabric
->lps
, BFA_LPS_SM_OFFLINE
);
594 bfa_fcs_fabric_notify_offline(fabric
);
597 case BFA_FCS_FABRIC_SM_DELETE
:
598 bfa_sm_set_state(fabric
, bfa_fcs_fabric_sm_deleting
);
599 bfa_fcs_fabric_delete(fabric
);
602 case BFA_FCS_FABRIC_SM_NO_FABRIC
:
603 bfa_trc(fabric
->fcs
, fabric
->bb_credit
);
604 bfa_fcport_set_tx_bbcredit(fabric
->fcs
->bfa
,
606 bfa_fcs_fabric_oper_bbscn(fabric
));
609 case BFA_FCS_FABRIC_SM_RETRY_OP
:
613 bfa_sm_fault(fabric
->fcs
, event
);
618 * Fabric is online - normal operating state.
621 bfa_fcs_fabric_sm_online(struct bfa_fcs_fabric_s
*fabric
,
622 enum bfa_fcs_fabric_event event
)
624 struct bfa_s
*bfa
= fabric
->fcs
->bfa
;
626 bfa_trc(fabric
->fcs
, fabric
->bport
.port_cfg
.pwwn
);
627 bfa_trc(fabric
->fcs
, event
);
630 case BFA_FCS_FABRIC_SM_LINK_DOWN
:
631 bfa_sm_set_state(fabric
, bfa_fcs_fabric_sm_linkdown
);
632 if (bfa_fcport_get_topology(bfa
) == BFA_PORT_TOPOLOGY_LOOP
) {
633 bfa_fcs_lport_offline(&fabric
->bport
);
635 bfa_sm_send_event(fabric
->lps
, BFA_LPS_SM_OFFLINE
);
636 bfa_fcs_fabric_notify_offline(fabric
);
640 case BFA_FCS_FABRIC_SM_DELETE
:
641 bfa_sm_set_state(fabric
, bfa_fcs_fabric_sm_deleting
);
642 bfa_fcs_fabric_delete(fabric
);
645 case BFA_FCS_FABRIC_SM_STOP
:
646 bfa_sm_set_state(fabric
, bfa_fcs_fabric_sm_stopping
);
647 bfa_fcs_fabric_stop(fabric
);
650 case BFA_FCS_FABRIC_SM_AUTH_FAILED
:
651 bfa_sm_set_state(fabric
, bfa_fcs_fabric_sm_auth_failed
);
652 bfa_sm_send_event(fabric
->lps
, BFA_LPS_SM_OFFLINE
);
655 case BFA_FCS_FABRIC_SM_AUTH_SUCCESS
:
659 bfa_sm_fault(fabric
->fcs
, event
);
664 * Exchanging virtual fabric parameters.
667 bfa_fcs_fabric_sm_evfp(struct bfa_fcs_fabric_s
*fabric
,
668 enum bfa_fcs_fabric_event event
)
670 bfa_trc(fabric
->fcs
, fabric
->bport
.port_cfg
.pwwn
);
671 bfa_trc(fabric
->fcs
, event
);
674 case BFA_FCS_FABRIC_SM_CONT_OP
:
675 bfa_sm_set_state(fabric
, bfa_fcs_fabric_sm_evfp_done
);
678 case BFA_FCS_FABRIC_SM_ISOLATE
:
679 bfa_sm_set_state(fabric
, bfa_fcs_fabric_sm_isolated
);
683 bfa_sm_fault(fabric
->fcs
, event
);
688 * EVFP exchange complete and VFT tagging is enabled.
691 bfa_fcs_fabric_sm_evfp_done(struct bfa_fcs_fabric_s
*fabric
,
692 enum bfa_fcs_fabric_event event
)
694 bfa_trc(fabric
->fcs
, fabric
->bport
.port_cfg
.pwwn
);
695 bfa_trc(fabric
->fcs
, event
);
699 * Port is isolated after EVFP exchange due to VF_ID mismatch (N and F).
702 bfa_fcs_fabric_sm_isolated(struct bfa_fcs_fabric_s
*fabric
,
703 enum bfa_fcs_fabric_event event
)
705 struct bfad_s
*bfad
= (struct bfad_s
*)fabric
->fcs
->bfad
;
706 char pwwn_ptr
[BFA_STRING_32
];
708 bfa_trc(fabric
->fcs
, fabric
->bport
.port_cfg
.pwwn
);
709 bfa_trc(fabric
->fcs
, event
);
710 wwn2str(pwwn_ptr
, fabric
->bport
.port_cfg
.pwwn
);
712 BFA_LOG(KERN_INFO
, bfad
, bfa_log_level
,
713 "Port is isolated due to VF_ID mismatch. "
714 "PWWN: %s Port VF_ID: %04x switch port VF_ID: %04x.",
715 pwwn_ptr
, fabric
->fcs
->port_vfid
,
716 fabric
->event_arg
.swp_vfid
);
720 * Fabric is being deleted, awaiting vport delete completions.
723 bfa_fcs_fabric_sm_deleting(struct bfa_fcs_fabric_s
*fabric
,
724 enum bfa_fcs_fabric_event event
)
726 bfa_trc(fabric
->fcs
, fabric
->bport
.port_cfg
.pwwn
);
727 bfa_trc(fabric
->fcs
, event
);
730 case BFA_FCS_FABRIC_SM_DELCOMP
:
731 bfa_sm_set_state(fabric
, bfa_fcs_fabric_sm_uninit
);
732 bfa_wc_down(&fabric
->fcs
->wc
);
735 case BFA_FCS_FABRIC_SM_LINK_UP
:
738 case BFA_FCS_FABRIC_SM_LINK_DOWN
:
739 bfa_fcs_fabric_notify_offline(fabric
);
743 bfa_sm_fault(fabric
->fcs
, event
);
748 * Fabric is being stopped, awaiting vport stop completions.
751 bfa_fcs_fabric_sm_stopping(struct bfa_fcs_fabric_s
*fabric
,
752 enum bfa_fcs_fabric_event event
)
754 struct bfa_s
*bfa
= fabric
->fcs
->bfa
;
756 bfa_trc(fabric
->fcs
, fabric
->bport
.port_cfg
.pwwn
);
757 bfa_trc(fabric
->fcs
, event
);
760 case BFA_FCS_FABRIC_SM_STOPCOMP
:
761 if (bfa_fcport_get_topology(bfa
) == BFA_PORT_TOPOLOGY_LOOP
) {
762 bfa_sm_set_state(fabric
, bfa_fcs_fabric_sm_created
);
764 bfa_sm_set_state(fabric
, bfa_fcs_fabric_sm_cleanup
);
765 bfa_sm_send_event(fabric
->lps
, BFA_LPS_SM_LOGOUT
);
769 case BFA_FCS_FABRIC_SM_LINK_UP
:
772 case BFA_FCS_FABRIC_SM_LINK_DOWN
:
773 if (bfa_fcport_get_topology(bfa
) == BFA_PORT_TOPOLOGY_LOOP
)
774 bfa_sm_set_state(fabric
, bfa_fcs_fabric_sm_created
);
776 bfa_sm_set_state(fabric
, bfa_fcs_fabric_sm_cleanup
);
780 bfa_sm_fault(fabric
->fcs
, event
);
785 * Fabric is being stopped, cleanup without FLOGO
788 bfa_fcs_fabric_sm_cleanup(struct bfa_fcs_fabric_s
*fabric
,
789 enum bfa_fcs_fabric_event event
)
791 bfa_trc(fabric
->fcs
, fabric
->bport
.port_cfg
.pwwn
);
792 bfa_trc(fabric
->fcs
, event
);
795 case BFA_FCS_FABRIC_SM_STOPCOMP
:
796 case BFA_FCS_FABRIC_SM_LOGOCOMP
:
797 bfa_sm_set_state(fabric
, bfa_fcs_fabric_sm_created
);
798 bfa_wc_down(&(fabric
->fcs
)->wc
);
801 case BFA_FCS_FABRIC_SM_LINK_DOWN
:
803 * Ignore - can get this event if we get notified about IOC down
804 * before the fabric completion callbk is done.
809 bfa_sm_fault(fabric
->fcs
, event
);
814 * fcs_fabric_private fabric private functions
818 bfa_fcs_fabric_init(struct bfa_fcs_fabric_s
*fabric
)
820 struct bfa_lport_cfg_s
*port_cfg
= &fabric
->bport
.port_cfg
;
822 port_cfg
->roles
= BFA_LPORT_ROLE_FCP_IM
;
823 port_cfg
->nwwn
= fabric
->fcs
->bfa
->ioc
.attr
->nwwn
;
824 port_cfg
->pwwn
= fabric
->fcs
->bfa
->ioc
.attr
->pwwn
;
828 * Port Symbolic Name Creation for base port.
831 bfa_fcs_fabric_psymb_init(struct bfa_fcs_fabric_s
*fabric
)
833 struct bfa_lport_cfg_s
*port_cfg
= &fabric
->bport
.port_cfg
;
834 char model
[BFA_ADAPTER_MODEL_NAME_LEN
] = {0};
835 struct bfa_fcs_driver_info_s
*driver_info
= &fabric
->fcs
->driver_info
;
837 bfa_ioc_get_adapter_model(&fabric
->fcs
->bfa
->ioc
, model
);
839 /* Model name/number */
840 strncpy((char *)&port_cfg
->sym_name
, model
,
841 BFA_FCS_PORT_SYMBNAME_MODEL_SZ
);
842 strncat((char *)&port_cfg
->sym_name
, BFA_FCS_PORT_SYMBNAME_SEPARATOR
,
843 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR
));
846 strncat((char *)&port_cfg
->sym_name
, (char *)driver_info
->version
,
847 BFA_FCS_PORT_SYMBNAME_VERSION_SZ
);
848 strncat((char *)&port_cfg
->sym_name
, BFA_FCS_PORT_SYMBNAME_SEPARATOR
,
849 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR
));
851 /* Host machine name */
852 strncat((char *)&port_cfg
->sym_name
,
853 (char *)driver_info
->host_machine_name
,
854 BFA_FCS_PORT_SYMBNAME_MACHINENAME_SZ
);
855 strncat((char *)&port_cfg
->sym_name
, BFA_FCS_PORT_SYMBNAME_SEPARATOR
,
856 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR
));
860 * If OS Patch Info is not there, do not truncate any bytes from the
861 * OS name string and instead copy the entire OS info string (64 bytes).
863 if (driver_info
->host_os_patch
[0] == '\0') {
864 strncat((char *)&port_cfg
->sym_name
,
865 (char *)driver_info
->host_os_name
,
867 strncat((char *)&port_cfg
->sym_name
,
868 BFA_FCS_PORT_SYMBNAME_SEPARATOR
,
869 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR
));
871 strncat((char *)&port_cfg
->sym_name
,
872 (char *)driver_info
->host_os_name
,
873 BFA_FCS_PORT_SYMBNAME_OSINFO_SZ
);
874 strncat((char *)&port_cfg
->sym_name
,
875 BFA_FCS_PORT_SYMBNAME_SEPARATOR
,
876 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR
));
878 /* Append host OS Patch Info */
879 strncat((char *)&port_cfg
->sym_name
,
880 (char *)driver_info
->host_os_patch
,
881 BFA_FCS_PORT_SYMBNAME_OSPATCH_SZ
);
885 port_cfg
->sym_name
.symname
[BFA_SYMNAME_MAXLEN
- 1] = 0;
889 * Node Symbolic Name Creation for base port and all vports
892 bfa_fcs_fabric_nsymb_init(struct bfa_fcs_fabric_s
*fabric
)
894 struct bfa_lport_cfg_s
*port_cfg
= &fabric
->bport
.port_cfg
;
895 char model
[BFA_ADAPTER_MODEL_NAME_LEN
] = {0};
896 struct bfa_fcs_driver_info_s
*driver_info
= &fabric
->fcs
->driver_info
;
898 bfa_ioc_get_adapter_model(&fabric
->fcs
->bfa
->ioc
, model
);
900 /* Model name/number */
901 strncpy((char *)&port_cfg
->node_sym_name
, model
,
902 BFA_FCS_PORT_SYMBNAME_MODEL_SZ
);
903 strncat((char *)&port_cfg
->node_sym_name
,
904 BFA_FCS_PORT_SYMBNAME_SEPARATOR
,
905 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR
));
908 strncat((char *)&port_cfg
->node_sym_name
, (char *)driver_info
->version
,
909 BFA_FCS_PORT_SYMBNAME_VERSION_SZ
);
910 strncat((char *)&port_cfg
->node_sym_name
,
911 BFA_FCS_PORT_SYMBNAME_SEPARATOR
,
912 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR
));
914 /* Host machine name */
915 strncat((char *)&port_cfg
->node_sym_name
,
916 (char *)driver_info
->host_machine_name
,
917 BFA_FCS_PORT_SYMBNAME_MACHINENAME_SZ
);
918 strncat((char *)&port_cfg
->node_sym_name
,
919 BFA_FCS_PORT_SYMBNAME_SEPARATOR
,
920 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR
));
923 port_cfg
->node_sym_name
.symname
[BFA_SYMNAME_MAXLEN
- 1] = 0;
927 * bfa lps login completion callback
930 bfa_cb_lps_flogi_comp(void *bfad
, void *uarg
, bfa_status_t status
)
932 struct bfa_fcs_fabric_s
*fabric
= uarg
;
934 bfa_trc(fabric
->fcs
, fabric
->bport
.port_cfg
.pwwn
);
935 bfa_trc(fabric
->fcs
, status
);
939 fabric
->stats
.flogi_accepts
++;
942 case BFA_STATUS_INVALID_MAC
:
944 fabric
->stats
.flogi_acc_err
++;
945 bfa_sm_send_event(fabric
, BFA_FCS_FABRIC_SM_RETRY_OP
);
949 case BFA_STATUS_EPROTOCOL
:
950 switch (fabric
->lps
->ext_status
) {
951 case BFA_EPROTO_BAD_ACCEPT
:
952 fabric
->stats
.flogi_acc_err
++;
955 case BFA_EPROTO_UNKNOWN_RSP
:
956 fabric
->stats
.flogi_unknown_rsp
++;
962 bfa_sm_send_event(fabric
, BFA_FCS_FABRIC_SM_RETRY_OP
);
966 case BFA_STATUS_FABRIC_RJT
:
967 fabric
->stats
.flogi_rejects
++;
968 if (fabric
->lps
->lsrjt_rsn
== FC_LS_RJT_RSN_LOGICAL_ERROR
&&
969 fabric
->lps
->lsrjt_expl
== FC_LS_RJT_EXP_NO_ADDL_INFO
)
970 fabric
->fcs
->bbscn_flogi_rjt
= BFA_TRUE
;
972 bfa_sm_send_event(fabric
, BFA_FCS_FABRIC_SM_RETRY_OP
);
976 fabric
->stats
.flogi_rsp_err
++;
977 bfa_sm_send_event(fabric
, BFA_FCS_FABRIC_SM_RETRY_OP
);
981 fabric
->bb_credit
= fabric
->lps
->pr_bbcred
;
982 bfa_trc(fabric
->fcs
, fabric
->bb_credit
);
984 if (!(fabric
->lps
->brcd_switch
))
985 fabric
->fabric_name
= fabric
->lps
->pr_nwwn
;
988 * Check port type. It should be 1 = F-port.
990 if (fabric
->lps
->fport
) {
991 fabric
->bport
.pid
= fabric
->lps
->lp_pid
;
992 fabric
->is_npiv
= fabric
->lps
->npiv_en
;
993 fabric
->is_auth
= fabric
->lps
->auth_req
;
994 bfa_sm_send_event(fabric
, BFA_FCS_FABRIC_SM_CONT_OP
);
997 * Nport-2-Nport direct attached
999 fabric
->bport
.port_topo
.pn2n
.rem_port_wwn
=
1000 fabric
->lps
->pr_pwwn
;
1001 fabric
->fab_type
= BFA_FCS_FABRIC_N2N
;
1002 bfa_sm_send_event(fabric
, BFA_FCS_FABRIC_SM_NO_FABRIC
);
1005 bfa_trc(fabric
->fcs
, fabric
->bport
.pid
);
1006 bfa_trc(fabric
->fcs
, fabric
->is_npiv
);
1007 bfa_trc(fabric
->fcs
, fabric
->is_auth
);
1010 * Allocate and send FLOGI.
1013 bfa_fcs_fabric_login(struct bfa_fcs_fabric_s
*fabric
)
1015 struct bfa_s
*bfa
= fabric
->fcs
->bfa
;
1016 struct bfa_lport_cfg_s
*pcfg
= &fabric
->bport
.port_cfg
;
1017 u8 alpa
= 0, bb_scn
= 0;
1019 if (bfa_fcs_fabric_is_bbscn_enabled(fabric
) &&
1020 (!fabric
->fcs
->bbscn_flogi_rjt
))
1021 bb_scn
= BFA_FCS_PORT_DEF_BB_SCN
;
1023 bfa_lps_flogi(fabric
->lps
, fabric
, alpa
, bfa_fcport_get_maxfrsize(bfa
),
1024 pcfg
->pwwn
, pcfg
->nwwn
, fabric
->auth_reqd
, bb_scn
);
1026 fabric
->stats
.flogi_sent
++;
1030 bfa_fcs_fabric_notify_online(struct bfa_fcs_fabric_s
*fabric
)
1032 struct bfa_fcs_vport_s
*vport
;
1033 struct list_head
*qe
, *qen
;
1035 bfa_trc(fabric
->fcs
, fabric
->fabric_name
);
1037 bfa_fcs_fabric_set_opertype(fabric
);
1038 fabric
->stats
.fabric_onlines
++;
1041 * notify online event to base and then virtual ports
1043 bfa_fcs_lport_online(&fabric
->bport
);
1045 list_for_each_safe(qe
, qen
, &fabric
->vport_q
) {
1046 vport
= (struct bfa_fcs_vport_s
*) qe
;
1047 bfa_fcs_vport_online(vport
);
1052 bfa_fcs_fabric_notify_offline(struct bfa_fcs_fabric_s
*fabric
)
1054 struct bfa_fcs_vport_s
*vport
;
1055 struct list_head
*qe
, *qen
;
1057 bfa_trc(fabric
->fcs
, fabric
->fabric_name
);
1058 fabric
->stats
.fabric_offlines
++;
1061 * notify offline event first to vports and then base port.
1063 list_for_each_safe(qe
, qen
, &fabric
->vport_q
) {
1064 vport
= (struct bfa_fcs_vport_s
*) qe
;
1065 bfa_fcs_vport_offline(vport
);
1068 bfa_fcs_lport_offline(&fabric
->bport
);
1070 fabric
->fabric_name
= 0;
1071 fabric
->fabric_ip_addr
[0] = 0;
1075 bfa_fcs_fabric_delay(void *cbarg
)
1077 struct bfa_fcs_fabric_s
*fabric
= cbarg
;
1079 bfa_sm_send_event(fabric
, BFA_FCS_FABRIC_SM_DELAYED
);
1083 * Stop all vports and wait for vport stop completions.
1086 bfa_fcs_fabric_stop(struct bfa_fcs_fabric_s
*fabric
)
1088 struct bfa_fcs_vport_s
*vport
;
1089 struct list_head
*qe
, *qen
;
1091 bfa_wc_init(&fabric
->stop_wc
, bfa_fcs_fabric_stop_comp
, fabric
);
1093 list_for_each_safe(qe
, qen
, &fabric
->vport_q
) {
1094 vport
= (struct bfa_fcs_vport_s
*) qe
;
1095 bfa_wc_up(&fabric
->stop_wc
);
1096 bfa_fcs_vport_fcs_stop(vport
);
1099 bfa_wc_up(&fabric
->stop_wc
);
1100 bfa_fcs_lport_stop(&fabric
->bport
);
1101 bfa_wc_wait(&fabric
->stop_wc
);
1105 * Computes operating BB_SCN value
1108 bfa_fcs_fabric_oper_bbscn(struct bfa_fcs_fabric_s
*fabric
)
1110 u8 pr_bbscn
= fabric
->lps
->pr_bbscn
;
1111 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(fabric
->fcs
->bfa
);
1113 if (!(fcport
->cfg
.bb_scn_state
&& pr_bbscn
))
1116 /* return max of local/remote bb_scn values */
1117 return ((pr_bbscn
> BFA_FCS_PORT_DEF_BB_SCN
) ?
1118 pr_bbscn
: BFA_FCS_PORT_DEF_BB_SCN
);
1122 * Check if BB_SCN can be enabled.
1124 static bfa_boolean_t
1125 bfa_fcs_fabric_is_bbscn_enabled(struct bfa_fcs_fabric_s
*fabric
)
1127 struct bfa_fcport_s
*fcport
= BFA_FCPORT_MOD(fabric
->fcs
->bfa
);
1129 if (bfa_ioc_get_fcmode(&fabric
->fcs
->bfa
->ioc
) &&
1130 fcport
->cfg
.bb_scn_state
&&
1131 !bfa_fcport_is_qos_enabled(fabric
->fcs
->bfa
) &&
1132 !bfa_fcport_is_trunk_enabled(fabric
->fcs
->bfa
))
1139 * Delete all vports and wait for vport delete completions.
1142 bfa_fcs_fabric_delete(struct bfa_fcs_fabric_s
*fabric
)
1144 struct bfa_fcs_vport_s
*vport
;
1145 struct list_head
*qe
, *qen
;
1147 list_for_each_safe(qe
, qen
, &fabric
->vport_q
) {
1148 vport
= (struct bfa_fcs_vport_s
*) qe
;
1149 bfa_fcs_vport_fcs_delete(vport
);
1152 bfa_fcs_lport_delete(&fabric
->bport
);
1153 bfa_wc_wait(&fabric
->wc
);
1157 bfa_fcs_fabric_delete_comp(void *cbarg
)
1159 struct bfa_fcs_fabric_s
*fabric
= cbarg
;
1161 bfa_sm_send_event(fabric
, BFA_FCS_FABRIC_SM_DELCOMP
);
1165 bfa_fcs_fabric_stop_comp(void *cbarg
)
1167 struct bfa_fcs_fabric_s
*fabric
= cbarg
;
1169 bfa_sm_send_event(fabric
, BFA_FCS_FABRIC_SM_STOPCOMP
);
1173 * fcs_fabric_public fabric public functions
1177 * Attach time initialization.
1180 bfa_fcs_fabric_attach(struct bfa_fcs_s
*fcs
)
1182 struct bfa_fcs_fabric_s
*fabric
;
1184 fabric
= &fcs
->fabric
;
1185 memset(fabric
, 0, sizeof(struct bfa_fcs_fabric_s
));
1188 * Initialize base fabric.
1191 INIT_LIST_HEAD(&fabric
->vport_q
);
1192 INIT_LIST_HEAD(&fabric
->vf_q
);
1193 fabric
->lps
= bfa_lps_alloc(fcs
->bfa
);
1194 WARN_ON(!fabric
->lps
);
1197 * Initialize fabric delete completion handler. Fabric deletion is
1198 * complete when the last vport delete is complete.
1200 bfa_wc_init(&fabric
->wc
, bfa_fcs_fabric_delete_comp
, fabric
);
1201 bfa_wc_up(&fabric
->wc
); /* For the base port */
1203 bfa_sm_set_state(fabric
, bfa_fcs_fabric_sm_uninit
);
1204 bfa_fcs_lport_attach(&fabric
->bport
, fabric
->fcs
, FC_VF_ID_NULL
, NULL
);
1208 bfa_fcs_fabric_modinit(struct bfa_fcs_s
*fcs
)
1210 bfa_sm_send_event(&fcs
->fabric
, BFA_FCS_FABRIC_SM_CREATE
);
1218 bfa_fcs_fabric_modexit(struct bfa_fcs_s
*fcs
)
1220 struct bfa_fcs_fabric_s
*fabric
;
1225 * Cleanup base fabric.
1227 fabric
= &fcs
->fabric
;
1228 bfa_lps_delete(fabric
->lps
);
1229 bfa_sm_send_event(fabric
, BFA_FCS_FABRIC_SM_DELETE
);
1233 * Fabric module stop -- stop FCS actions
1236 bfa_fcs_fabric_modstop(struct bfa_fcs_s
*fcs
)
1238 struct bfa_fcs_fabric_s
*fabric
;
1241 fabric
= &fcs
->fabric
;
1242 bfa_sm_send_event(fabric
, BFA_FCS_FABRIC_SM_STOP
);
1246 * Fabric module start -- kick starts FCS actions
1249 bfa_fcs_fabric_modstart(struct bfa_fcs_s
*fcs
)
1251 struct bfa_fcs_fabric_s
*fabric
;
1254 fabric
= &fcs
->fabric
;
1255 bfa_sm_send_event(fabric
, BFA_FCS_FABRIC_SM_START
);
1260 * Link up notification from BFA physical port module.
1263 bfa_fcs_fabric_link_up(struct bfa_fcs_fabric_s
*fabric
)
1265 bfa_trc(fabric
->fcs
, fabric
->bport
.port_cfg
.pwwn
);
1266 bfa_sm_send_event(fabric
, BFA_FCS_FABRIC_SM_LINK_UP
);
1270 * Link down notification from BFA physical port module.
1273 bfa_fcs_fabric_link_down(struct bfa_fcs_fabric_s
*fabric
)
1275 bfa_trc(fabric
->fcs
, fabric
->bport
.port_cfg
.pwwn
);
1276 fabric
->fcs
->bbscn_flogi_rjt
= BFA_FALSE
;
1277 bfa_sm_send_event(fabric
, BFA_FCS_FABRIC_SM_LINK_DOWN
);
1281 * A child vport is being created in the fabric.
1283 * Call from vport module at vport creation. A list of base port and vports
1284 * belonging to a fabric is maintained to propagate link events.
1286 * param[in] fabric - Fabric instance. This can be a base fabric or vf.
1287 * param[in] vport - Vport being created.
1289 * @return None (always succeeds)
1292 bfa_fcs_fabric_addvport(struct bfa_fcs_fabric_s
*fabric
,
1293 struct bfa_fcs_vport_s
*vport
)
1296 * - add vport to fabric's vport_q
1298 bfa_trc(fabric
->fcs
, fabric
->vf_id
);
1300 list_add_tail(&vport
->qe
, &fabric
->vport_q
);
1301 fabric
->num_vports
++;
1302 bfa_wc_up(&fabric
->wc
);
1306 * A child vport is being deleted from fabric.
1308 * Vport is being deleted.
1311 bfa_fcs_fabric_delvport(struct bfa_fcs_fabric_s
*fabric
,
1312 struct bfa_fcs_vport_s
*vport
)
1314 list_del(&vport
->qe
);
1315 fabric
->num_vports
--;
1316 bfa_wc_down(&fabric
->wc
);
1321 * Lookup for a vport within a fabric given its pwwn
1323 struct bfa_fcs_vport_s
*
1324 bfa_fcs_fabric_vport_lookup(struct bfa_fcs_fabric_s
*fabric
, wwn_t pwwn
)
1326 struct bfa_fcs_vport_s
*vport
;
1327 struct list_head
*qe
;
1329 list_for_each(qe
, &fabric
->vport_q
) {
1330 vport
= (struct bfa_fcs_vport_s
*) qe
;
1331 if (bfa_fcs_lport_get_pwwn(&vport
->lport
) == pwwn
)
1340 * Get OUI of the attached switch.
1342 * Note : Use of this function should be avoided as much as possible.
1343 * This function should be used only if there is any requirement
1344 * to check for FOS version below 6.3.
1345 * To check if the attached fabric is a brocade fabric, use
1346 * bfa_lps_is_brcd_fabric() which works for FOS versions 6.3
1351 bfa_fcs_fabric_get_switch_oui(struct bfa_fcs_fabric_s
*fabric
)
1357 fab_nwwn
= fabric
->lps
->pr_nwwn
;
1359 tmp
= (u8
*)&fab_nwwn
;
1360 oui
= (tmp
[3] << 8) | tmp
[4];
1365 * Unsolicited frame receive handling.
1368 bfa_fcs_fabric_uf_recv(struct bfa_fcs_fabric_s
*fabric
, struct fchs_s
*fchs
,
1371 u32 pid
= fchs
->d_id
;
1372 struct bfa_fcs_vport_s
*vport
;
1373 struct list_head
*qe
;
1374 struct fc_els_cmd_s
*els_cmd
= (struct fc_els_cmd_s
*) (fchs
+ 1);
1375 struct fc_logi_s
*flogi
= (struct fc_logi_s
*) els_cmd
;
1377 bfa_trc(fabric
->fcs
, len
);
1378 bfa_trc(fabric
->fcs
, pid
);
1381 * Look for our own FLOGI frames being looped back. This means an
1382 * external loopback cable is in place. Our own FLOGI frames are
1383 * sometimes looped back when switch port gets temporarily bypassed.
1385 if ((pid
== bfa_ntoh3b(FC_FABRIC_PORT
)) &&
1386 (els_cmd
->els_code
== FC_ELS_FLOGI
) &&
1387 (flogi
->port_name
== bfa_fcs_lport_get_pwwn(&fabric
->bport
))) {
1388 bfa_sm_send_event(fabric
, BFA_FCS_FABRIC_SM_LOOPBACK
);
1393 * FLOGI/EVFP exchanges should be consumed by base fabric.
1395 if (fchs
->d_id
== bfa_hton3b(FC_FABRIC_PORT
)) {
1396 bfa_trc(fabric
->fcs
, pid
);
1397 bfa_fcs_fabric_process_uf(fabric
, fchs
, len
);
1401 if (fabric
->bport
.pid
== pid
) {
1403 * All authentication frames should be routed to auth
1405 bfa_trc(fabric
->fcs
, els_cmd
->els_code
);
1406 if (els_cmd
->els_code
== FC_ELS_AUTH
) {
1407 bfa_trc(fabric
->fcs
, els_cmd
->els_code
);
1411 bfa_trc(fabric
->fcs
, *(u8
*) ((u8
*) fchs
));
1412 bfa_fcs_lport_uf_recv(&fabric
->bport
, fchs
, len
);
1417 * look for a matching local port ID
1419 list_for_each(qe
, &fabric
->vport_q
) {
1420 vport
= (struct bfa_fcs_vport_s
*) qe
;
1421 if (vport
->lport
.pid
== pid
) {
1422 bfa_fcs_lport_uf_recv(&vport
->lport
, fchs
, len
);
1427 if (!bfa_fcs_fabric_is_switched(fabric
))
1428 bfa_fcs_lport_uf_recv(&fabric
->bport
, fchs
, len
);
1430 bfa_trc(fabric
->fcs
, fchs
->type
);
1434 * Unsolicited frames to be processed by fabric.
1437 bfa_fcs_fabric_process_uf(struct bfa_fcs_fabric_s
*fabric
, struct fchs_s
*fchs
,
1440 struct fc_els_cmd_s
*els_cmd
= (struct fc_els_cmd_s
*) (fchs
+ 1);
1442 bfa_trc(fabric
->fcs
, els_cmd
->els_code
);
1444 switch (els_cmd
->els_code
) {
1446 bfa_fcs_fabric_process_flogi(fabric
, fchs
, len
);
1451 * need to generate a LS_RJT
1458 * Process incoming FLOGI
1461 bfa_fcs_fabric_process_flogi(struct bfa_fcs_fabric_s
*fabric
,
1462 struct fchs_s
*fchs
, u16 len
)
1464 struct fc_logi_s
*flogi
= (struct fc_logi_s
*) (fchs
+ 1);
1465 struct bfa_fcs_lport_s
*bport
= &fabric
->bport
;
1467 bfa_trc(fabric
->fcs
, fchs
->s_id
);
1469 fabric
->stats
.flogi_rcvd
++;
1471 * Check port type. It should be 0 = n-port.
1473 if (flogi
->csp
.port_type
) {
1475 * @todo: may need to send a LS_RJT
1477 bfa_trc(fabric
->fcs
, flogi
->port_name
);
1478 fabric
->stats
.flogi_rejected
++;
1482 fabric
->bb_credit
= be16_to_cpu(flogi
->csp
.bbcred
);
1483 fabric
->lps
->pr_bbscn
= (be16_to_cpu(flogi
->csp
.rxsz
) >> 12);
1484 bport
->port_topo
.pn2n
.rem_port_wwn
= flogi
->port_name
;
1485 bport
->port_topo
.pn2n
.reply_oxid
= fchs
->ox_id
;
1490 bfa_fcs_fabric_send_flogi_acc(fabric
);
1491 bfa_sm_send_event(fabric
, BFA_FCS_FABRIC_SM_NO_FABRIC
);
1495 bfa_fcs_fabric_send_flogi_acc(struct bfa_fcs_fabric_s
*fabric
)
1497 struct bfa_lport_cfg_s
*pcfg
= &fabric
->bport
.port_cfg
;
1498 struct bfa_fcs_lport_n2n_s
*n2n_port
= &fabric
->bport
.port_topo
.pn2n
;
1499 struct bfa_s
*bfa
= fabric
->fcs
->bfa
;
1500 struct bfa_fcxp_s
*fcxp
;
1504 fcxp
= bfa_fcs_fcxp_alloc(fabric
->fcs
, BFA_FALSE
);
1506 * Do not expect this failure -- expect remote node to retry
1511 reqlen
= fc_flogi_acc_build(&fchs
, bfa_fcxp_get_reqbuf(fcxp
),
1512 bfa_hton3b(FC_FABRIC_PORT
),
1513 n2n_port
->reply_oxid
, pcfg
->pwwn
,
1515 bfa_fcport_get_maxfrsize(bfa
),
1516 bfa_fcport_get_rx_bbcredit(bfa
),
1517 bfa_fcs_fabric_oper_bbscn(fabric
));
1519 bfa_fcxp_send(fcxp
, NULL
, fabric
->vf_id
, fabric
->lps
->bfa_tag
,
1520 BFA_FALSE
, FC_CLASS_3
,
1521 reqlen
, &fchs
, bfa_fcs_fabric_flogiacc_comp
, fabric
,
1526 * Flogi Acc completion callback.
1529 bfa_fcs_fabric_flogiacc_comp(void *fcsarg
, struct bfa_fcxp_s
*fcxp
, void *cbarg
,
1530 bfa_status_t status
, u32 rsp_len
,
1531 u32 resid_len
, struct fchs_s
*rspfchs
)
1533 struct bfa_fcs_fabric_s
*fabric
= cbarg
;
1535 bfa_trc(fabric
->fcs
, status
);
1540 * Send AEN notification
1543 bfa_fcs_fabric_aen_post(struct bfa_fcs_lport_s
*port
,
1544 enum bfa_port_aen_event event
)
1546 struct bfad_s
*bfad
= (struct bfad_s
*)port
->fabric
->fcs
->bfad
;
1547 struct bfa_aen_entry_s
*aen_entry
;
1549 bfad_get_aen_entry(bfad
, aen_entry
);
1553 aen_entry
->aen_data
.port
.pwwn
= bfa_fcs_lport_get_pwwn(port
);
1554 aen_entry
->aen_data
.port
.fwwn
= bfa_fcs_lport_get_fabric_name(port
);
1556 /* Send the AEN notification */
1557 bfad_im_post_vendor_event(aen_entry
, bfad
, ++port
->fcs
->fcs_aen_seq
,
1558 BFA_AEN_CAT_PORT
, event
);
1563 * @param[in] fabric - fabric
1564 * @param[in] wwn_t - new fabric name
1569 bfa_fcs_fabric_set_fabric_name(struct bfa_fcs_fabric_s
*fabric
,
1572 struct bfad_s
*bfad
= (struct bfad_s
*)fabric
->fcs
->bfad
;
1573 char pwwn_ptr
[BFA_STRING_32
];
1574 char fwwn_ptr
[BFA_STRING_32
];
1576 bfa_trc(fabric
->fcs
, fabric_name
);
1578 if (fabric
->fabric_name
== 0) {
1580 * With BRCD switches, we don't get Fabric Name in FLOGI.
1581 * Don't generate a fabric name change event in this case.
1583 fabric
->fabric_name
= fabric_name
;
1585 fabric
->fabric_name
= fabric_name
;
1586 wwn2str(pwwn_ptr
, bfa_fcs_lport_get_pwwn(&fabric
->bport
));
1588 bfa_fcs_lport_get_fabric_name(&fabric
->bport
));
1589 BFA_LOG(KERN_WARNING
, bfad
, bfa_log_level
,
1590 "Base port WWN = %s Fabric WWN = %s\n",
1591 pwwn_ptr
, fwwn_ptr
);
1592 bfa_fcs_fabric_aen_post(&fabric
->bport
,
1593 BFA_PORT_AEN_FABRIC_NAME_CHANGE
);
1598 bfa_cb_lps_flogo_comp(void *bfad
, void *uarg
)
1600 struct bfa_fcs_fabric_s
*fabric
= uarg
;
1601 bfa_sm_send_event(fabric
, BFA_FCS_FABRIC_SM_LOGOCOMP
);
1605 * Returns FCS vf structure for a given vf_id.
1607 * param[in] vf_id - VF_ID
1610 * If lookup succeeds, retuns fcs vf object, otherwise returns NULL
1613 bfa_fcs_vf_lookup(struct bfa_fcs_s
*fcs
, u16 vf_id
)
1615 bfa_trc(fcs
, vf_id
);
1616 if (vf_id
== FC_VF_ID_NULL
)
1617 return &fcs
->fabric
;
1623 * Return the list of local logical ports present in the given VF.
1625 * @param[in] vf vf for which logical ports are returned
1626 * @param[out] lpwwn returned logical port wwn list
1627 * @param[in,out] nlports in:size of lpwwn list;
1628 * out:total elements present,
1629 * actual elements returned is limited by the size
1632 bfa_fcs_vf_get_ports(bfa_fcs_vf_t
*vf
, wwn_t lpwwn
[], int *nlports
)
1634 struct list_head
*qe
;
1635 struct bfa_fcs_vport_s
*vport
;
1637 struct bfa_fcs_s
*fcs
;
1639 if (vf
== NULL
|| lpwwn
== NULL
|| *nlports
== 0)
1644 bfa_trc(fcs
, vf
->vf_id
);
1645 bfa_trc(fcs
, (uint32_t) *nlports
);
1647 lpwwn
[i
++] = vf
->bport
.port_cfg
.pwwn
;
1649 list_for_each(qe
, &vf
->vport_q
) {
1653 vport
= (struct bfa_fcs_vport_s
*) qe
;
1654 lpwwn
[i
++] = vport
->lport
.port_cfg
.pwwn
;
1662 * BFA FCS PPORT ( physical port)
1665 bfa_fcs_port_event_handler(void *cbarg
, enum bfa_port_linkstate event
)
1667 struct bfa_fcs_s
*fcs
= cbarg
;
1669 bfa_trc(fcs
, event
);
1672 case BFA_PORT_LINKUP
:
1673 bfa_fcs_fabric_link_up(&fcs
->fabric
);
1676 case BFA_PORT_LINKDOWN
:
1677 bfa_fcs_fabric_link_down(&fcs
->fabric
);
1686 bfa_fcs_port_attach(struct bfa_fcs_s
*fcs
)
1688 bfa_fcport_event_register(fcs
->bfa
, bfa_fcs_port_event_handler
, fcs
);
1692 * BFA FCS UF ( Unsolicited Frames)
1696 * BFA callback for unsolicited frame receive handler.
1698 * @param[in] cbarg callback arg for receive handler
1699 * @param[in] uf unsolicited frame descriptor
1704 bfa_fcs_uf_recv(void *cbarg
, struct bfa_uf_s
*uf
)
1706 struct bfa_fcs_s
*fcs
= (struct bfa_fcs_s
*) cbarg
;
1707 struct fchs_s
*fchs
= bfa_uf_get_frmbuf(uf
);
1708 u16 len
= bfa_uf_get_frmlen(uf
);
1709 struct fc_vft_s
*vft
;
1710 struct bfa_fcs_fabric_s
*fabric
;
1713 * check for VFT header
1715 if (fchs
->routing
== FC_RTG_EXT_HDR
&&
1716 fchs
->cat_info
== FC_CAT_VFT_HDR
) {
1717 bfa_stats(fcs
, uf
.tagged
);
1718 vft
= bfa_uf_get_frmbuf(uf
);
1719 if (fcs
->port_vfid
== vft
->vf_id
)
1720 fabric
= &fcs
->fabric
;
1722 fabric
= bfa_fcs_vf_lookup(fcs
, (u16
) vft
->vf_id
);
1725 * drop frame if vfid is unknown
1729 bfa_stats(fcs
, uf
.vfid_unknown
);
1737 fchs
= (struct fchs_s
*) (vft
+ 1);
1738 len
-= sizeof(struct fc_vft_s
);
1740 bfa_trc(fcs
, vft
->vf_id
);
1742 bfa_stats(fcs
, uf
.untagged
);
1743 fabric
= &fcs
->fabric
;
1746 bfa_trc(fcs
, ((u32
*) fchs
)[0]);
1747 bfa_trc(fcs
, ((u32
*) fchs
)[1]);
1748 bfa_trc(fcs
, ((u32
*) fchs
)[2]);
1749 bfa_trc(fcs
, ((u32
*) fchs
)[3]);
1750 bfa_trc(fcs
, ((u32
*) fchs
)[4]);
1751 bfa_trc(fcs
, ((u32
*) fchs
)[5]);
1754 bfa_fcs_fabric_uf_recv(fabric
, fchs
, len
);
1759 bfa_fcs_uf_attach(struct bfa_fcs_s
*fcs
)
1761 bfa_uf_recv_register(fcs
->bfa
, bfa_fcs_uf_recv
, fcs
);