[SCSI] bfa: remove unused and empty functions
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / scsi / bfa / bfa_fcs.c
blob5b561bde226468f0971b840d10e7f89ee2d65ccb
1 /*
2 * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
3 * All rights reserved
4 * www.brocade.com
6 * Linux driver for Brocade Fibre Channel Host Bus Adapter.
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License (GPL) Version 2 as
10 * published by the Free Software Foundation
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
19 * bfa_fcs.c BFA FCS main
22 #include "bfa_fcs.h"
23 #include "bfa_fcbuild.h"
24 #include "bfad_drv.h"
26 BFA_TRC_FILE(FCS, FCS);
29 * FCS sub-modules
31 struct bfa_fcs_mod_s {
32 void (*attach) (struct bfa_fcs_s *fcs);
33 void (*modinit) (struct bfa_fcs_s *fcs);
34 void (*modexit) (struct bfa_fcs_s *fcs);
37 #define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
39 static struct bfa_fcs_mod_s fcs_modules[] = {
40 { bfa_fcs_port_attach, NULL, NULL },
41 { bfa_fcs_uf_attach, NULL, NULL },
42 { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
43 bfa_fcs_fabric_modexit },
47 * fcs_api BFA FCS API
50 static void
51 bfa_fcs_exit_comp(void *fcs_cbarg)
53 struct bfa_fcs_s *fcs = fcs_cbarg;
54 struct bfad_s *bfad = fcs->bfad;
56 complete(&bfad->comp);
62 * fcs_api BFA FCS API
66 * fcs attach -- called once to initialize data structures at driver attach time
68 void
69 bfa_fcs_attach(struct bfa_fcs_s *fcs, struct bfa_s *bfa, struct bfad_s *bfad,
70 bfa_boolean_t min_cfg)
72 int i;
73 struct bfa_fcs_mod_s *mod;
75 fcs->bfa = bfa;
76 fcs->bfad = bfad;
77 fcs->min_cfg = min_cfg;
79 bfa_attach_fcs(bfa);
80 fcbuild_init();
82 for (i = 0; i < sizeof(fcs_modules) / sizeof(fcs_modules[0]); i++) {
83 mod = &fcs_modules[i];
84 if (mod->attach)
85 mod->attach(fcs);
90 * fcs initialization, called once after bfa initialization is complete
92 void
93 bfa_fcs_init(struct bfa_fcs_s *fcs)
95 int i, npbc_vports;
96 struct bfa_fcs_mod_s *mod;
97 struct bfi_pbc_vport_s pbc_vports[BFI_PBC_MAX_VPORTS];
99 for (i = 0; i < sizeof(fcs_modules) / sizeof(fcs_modules[0]); i++) {
100 mod = &fcs_modules[i];
101 if (mod->modinit)
102 mod->modinit(fcs);
104 /* Initialize pbc vports */
105 if (!fcs->min_cfg) {
106 npbc_vports =
107 bfa_iocfc_get_pbc_vports(fcs->bfa, pbc_vports);
108 for (i = 0; i < npbc_vports; i++)
109 bfa_fcb_pbc_vport_create(fcs->bfa->bfad, pbc_vports[i]);
114 * Start FCS operations.
116 void
117 bfa_fcs_start(struct bfa_fcs_s *fcs)
119 bfa_fcs_fabric_modstart(fcs);
123 * brief
124 * FCS driver details initialization.
126 * param[in] fcs FCS instance
127 * param[in] driver_info Driver Details
129 * return None
131 void
132 bfa_fcs_driver_info_init(struct bfa_fcs_s *fcs,
133 struct bfa_fcs_driver_info_s *driver_info)
136 fcs->driver_info = *driver_info;
138 bfa_fcs_fabric_psymb_init(&fcs->fabric);
142 * brief
143 * FCS FDMI Driver Parameter Initialization
145 * param[in] fcs FCS instance
146 * param[in] fdmi_enable TRUE/FALSE
148 * return None
150 void
151 bfa_fcs_set_fdmi_param(struct bfa_fcs_s *fcs, bfa_boolean_t fdmi_enable)
154 fcs->fdmi_enabled = fdmi_enable;
158 * brief
159 * FCS instance cleanup and exit.
161 * param[in] fcs FCS instance
162 * return None
164 void
165 bfa_fcs_exit(struct bfa_fcs_s *fcs)
167 struct bfa_fcs_mod_s *mod;
168 int nmods, i;
170 bfa_wc_init(&fcs->wc, bfa_fcs_exit_comp, fcs);
172 nmods = sizeof(fcs_modules) / sizeof(fcs_modules[0]);
174 for (i = 0; i < nmods; i++) {
176 mod = &fcs_modules[i];
177 if (mod->modexit) {
178 bfa_wc_up(&fcs->wc);
179 mod->modexit(fcs);
183 bfa_wc_wait(&fcs->wc);
187 void
188 bfa_fcs_trc_init(struct bfa_fcs_s *fcs, struct bfa_trc_mod_s *trcmod)
190 fcs->trcmod = trcmod;
193 void
194 bfa_fcs_modexit_comp(struct bfa_fcs_s *fcs)
196 bfa_wc_down(&fcs->wc);
200 * Fabric module implementation.
203 #define BFA_FCS_FABRIC_RETRY_DELAY (2000) /* Milliseconds */
204 #define BFA_FCS_FABRIC_CLEANUP_DELAY (10000) /* Milliseconds */
206 #define bfa_fcs_fabric_set_opertype(__fabric) do { \
207 if (bfa_fcport_get_topology((__fabric)->fcs->bfa) \
208 == BFA_PORT_TOPOLOGY_P2P) \
209 (__fabric)->oper_type = BFA_PORT_TYPE_NPORT; \
210 else \
211 (__fabric)->oper_type = BFA_PORT_TYPE_NLPORT; \
212 } while (0)
215 * forward declarations
217 static void bfa_fcs_fabric_init(struct bfa_fcs_fabric_s *fabric);
218 static void bfa_fcs_fabric_login(struct bfa_fcs_fabric_s *fabric);
219 static void bfa_fcs_fabric_notify_online(struct bfa_fcs_fabric_s *fabric);
220 static void bfa_fcs_fabric_notify_offline(struct bfa_fcs_fabric_s *fabric);
221 static void bfa_fcs_fabric_delay(void *cbarg);
222 static void bfa_fcs_fabric_delete(struct bfa_fcs_fabric_s *fabric);
223 static void bfa_fcs_fabric_delete_comp(void *cbarg);
224 static void bfa_fcs_fabric_process_uf(struct bfa_fcs_fabric_s *fabric,
225 struct fchs_s *fchs, u16 len);
226 static void bfa_fcs_fabric_process_flogi(struct bfa_fcs_fabric_s *fabric,
227 struct fchs_s *fchs, u16 len);
228 static void bfa_fcs_fabric_send_flogi_acc(struct bfa_fcs_fabric_s *fabric);
229 static void bfa_fcs_fabric_flogiacc_comp(void *fcsarg,
230 struct bfa_fcxp_s *fcxp, void *cbarg,
231 bfa_status_t status,
232 u32 rsp_len,
233 u32 resid_len,
234 struct fchs_s *rspfchs);
236 * fcs_fabric_sm fabric state machine functions
240 * Fabric state machine events
242 enum bfa_fcs_fabric_event {
243 BFA_FCS_FABRIC_SM_CREATE = 1, /* create from driver */
244 BFA_FCS_FABRIC_SM_DELETE = 2, /* delete from driver */
245 BFA_FCS_FABRIC_SM_LINK_DOWN = 3, /* link down from port */
246 BFA_FCS_FABRIC_SM_LINK_UP = 4, /* link up from port */
247 BFA_FCS_FABRIC_SM_CONT_OP = 5, /* flogi/auth continue op */
248 BFA_FCS_FABRIC_SM_RETRY_OP = 6, /* flogi/auth retry op */
249 BFA_FCS_FABRIC_SM_NO_FABRIC = 7, /* from flogi/auth */
250 BFA_FCS_FABRIC_SM_PERF_EVFP = 8, /* from flogi/auth */
251 BFA_FCS_FABRIC_SM_ISOLATE = 9, /* from EVFP processing */
252 BFA_FCS_FABRIC_SM_NO_TAGGING = 10, /* no VFT tagging from EVFP */
253 BFA_FCS_FABRIC_SM_DELAYED = 11, /* timeout delay event */
254 BFA_FCS_FABRIC_SM_AUTH_FAILED = 12, /* auth failed */
255 BFA_FCS_FABRIC_SM_AUTH_SUCCESS = 13, /* auth successful */
256 BFA_FCS_FABRIC_SM_DELCOMP = 14, /* all vports deleted event */
257 BFA_FCS_FABRIC_SM_LOOPBACK = 15, /* Received our own FLOGI */
258 BFA_FCS_FABRIC_SM_START = 16, /* from driver */
261 static void bfa_fcs_fabric_sm_uninit(struct bfa_fcs_fabric_s *fabric,
262 enum bfa_fcs_fabric_event event);
263 static void bfa_fcs_fabric_sm_created(struct bfa_fcs_fabric_s *fabric,
264 enum bfa_fcs_fabric_event event);
265 static void bfa_fcs_fabric_sm_linkdown(struct bfa_fcs_fabric_s *fabric,
266 enum bfa_fcs_fabric_event event);
267 static void bfa_fcs_fabric_sm_flogi(struct bfa_fcs_fabric_s *fabric,
268 enum bfa_fcs_fabric_event event);
269 static void bfa_fcs_fabric_sm_flogi_retry(struct bfa_fcs_fabric_s *fabric,
270 enum bfa_fcs_fabric_event event);
271 static void bfa_fcs_fabric_sm_auth(struct bfa_fcs_fabric_s *fabric,
272 enum bfa_fcs_fabric_event event);
273 static void bfa_fcs_fabric_sm_auth_failed(struct bfa_fcs_fabric_s *fabric,
274 enum bfa_fcs_fabric_event event);
275 static void bfa_fcs_fabric_sm_loopback(struct bfa_fcs_fabric_s *fabric,
276 enum bfa_fcs_fabric_event event);
277 static void bfa_fcs_fabric_sm_nofabric(struct bfa_fcs_fabric_s *fabric,
278 enum bfa_fcs_fabric_event event);
279 static void bfa_fcs_fabric_sm_online(struct bfa_fcs_fabric_s *fabric,
280 enum bfa_fcs_fabric_event event);
281 static void bfa_fcs_fabric_sm_evfp(struct bfa_fcs_fabric_s *fabric,
282 enum bfa_fcs_fabric_event event);
283 static void bfa_fcs_fabric_sm_evfp_done(struct bfa_fcs_fabric_s *fabric,
284 enum bfa_fcs_fabric_event event);
285 static void bfa_fcs_fabric_sm_isolated(struct bfa_fcs_fabric_s *fabric,
286 enum bfa_fcs_fabric_event event);
287 static void bfa_fcs_fabric_sm_deleting(struct bfa_fcs_fabric_s *fabric,
288 enum bfa_fcs_fabric_event event);
290 * Beginning state before fabric creation.
292 static void
293 bfa_fcs_fabric_sm_uninit(struct bfa_fcs_fabric_s *fabric,
294 enum bfa_fcs_fabric_event event)
296 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
297 bfa_trc(fabric->fcs, event);
299 switch (event) {
300 case BFA_FCS_FABRIC_SM_CREATE:
301 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_created);
302 bfa_fcs_fabric_init(fabric);
303 bfa_fcs_lport_init(&fabric->bport, &fabric->bport.port_cfg);
304 break;
306 case BFA_FCS_FABRIC_SM_LINK_UP:
307 case BFA_FCS_FABRIC_SM_LINK_DOWN:
308 break;
310 default:
311 bfa_sm_fault(fabric->fcs, event);
316 * Beginning state before fabric creation.
318 static void
319 bfa_fcs_fabric_sm_created(struct bfa_fcs_fabric_s *fabric,
320 enum bfa_fcs_fabric_event event)
322 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
323 bfa_trc(fabric->fcs, event);
325 switch (event) {
326 case BFA_FCS_FABRIC_SM_START:
327 if (bfa_fcport_is_linkup(fabric->fcs->bfa)) {
328 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_flogi);
329 bfa_fcs_fabric_login(fabric);
330 } else
331 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
332 break;
334 case BFA_FCS_FABRIC_SM_LINK_UP:
335 case BFA_FCS_FABRIC_SM_LINK_DOWN:
336 break;
338 case BFA_FCS_FABRIC_SM_DELETE:
339 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_uninit);
340 bfa_fcs_modexit_comp(fabric->fcs);
341 break;
343 default:
344 bfa_sm_fault(fabric->fcs, event);
349 * Link is down, awaiting LINK UP event from port. This is also the
350 * first state at fabric creation.
352 static void
353 bfa_fcs_fabric_sm_linkdown(struct bfa_fcs_fabric_s *fabric,
354 enum bfa_fcs_fabric_event event)
356 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
357 bfa_trc(fabric->fcs, event);
359 switch (event) {
360 case BFA_FCS_FABRIC_SM_LINK_UP:
361 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_flogi);
362 bfa_fcs_fabric_login(fabric);
363 break;
365 case BFA_FCS_FABRIC_SM_RETRY_OP:
366 break;
368 case BFA_FCS_FABRIC_SM_DELETE:
369 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
370 bfa_fcs_fabric_delete(fabric);
371 break;
373 default:
374 bfa_sm_fault(fabric->fcs, event);
379 * FLOGI is in progress, awaiting FLOGI reply.
381 static void
382 bfa_fcs_fabric_sm_flogi(struct bfa_fcs_fabric_s *fabric,
383 enum bfa_fcs_fabric_event event)
385 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
386 bfa_trc(fabric->fcs, event);
388 switch (event) {
389 case BFA_FCS_FABRIC_SM_CONT_OP:
391 bfa_fcport_set_tx_bbcredit(fabric->fcs->bfa,
392 fabric->bb_credit);
393 fabric->fab_type = BFA_FCS_FABRIC_SWITCHED;
395 if (fabric->auth_reqd && fabric->is_auth) {
396 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_auth);
397 bfa_trc(fabric->fcs, event);
398 } else {
399 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_online);
400 bfa_fcs_fabric_notify_online(fabric);
402 break;
404 case BFA_FCS_FABRIC_SM_RETRY_OP:
405 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_flogi_retry);
406 bfa_timer_start(fabric->fcs->bfa, &fabric->delay_timer,
407 bfa_fcs_fabric_delay, fabric,
408 BFA_FCS_FABRIC_RETRY_DELAY);
409 break;
411 case BFA_FCS_FABRIC_SM_LOOPBACK:
412 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_loopback);
413 bfa_lps_discard(fabric->lps);
414 bfa_fcs_fabric_set_opertype(fabric);
415 break;
417 case BFA_FCS_FABRIC_SM_NO_FABRIC:
418 fabric->fab_type = BFA_FCS_FABRIC_N2N;
419 bfa_fcport_set_tx_bbcredit(fabric->fcs->bfa,
420 fabric->bb_credit);
421 bfa_fcs_fabric_notify_online(fabric);
422 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_nofabric);
423 break;
425 case BFA_FCS_FABRIC_SM_LINK_DOWN:
426 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
427 bfa_lps_discard(fabric->lps);
428 break;
430 case BFA_FCS_FABRIC_SM_DELETE:
431 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
432 bfa_lps_discard(fabric->lps);
433 bfa_fcs_fabric_delete(fabric);
434 break;
436 default:
437 bfa_sm_fault(fabric->fcs, event);
442 static void
443 bfa_fcs_fabric_sm_flogi_retry(struct bfa_fcs_fabric_s *fabric,
444 enum bfa_fcs_fabric_event event)
446 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
447 bfa_trc(fabric->fcs, event);
449 switch (event) {
450 case BFA_FCS_FABRIC_SM_DELAYED:
451 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_flogi);
452 bfa_fcs_fabric_login(fabric);
453 break;
455 case BFA_FCS_FABRIC_SM_LINK_DOWN:
456 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
457 bfa_timer_stop(&fabric->delay_timer);
458 break;
460 case BFA_FCS_FABRIC_SM_DELETE:
461 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
462 bfa_timer_stop(&fabric->delay_timer);
463 bfa_fcs_fabric_delete(fabric);
464 break;
466 default:
467 bfa_sm_fault(fabric->fcs, event);
472 * Authentication is in progress, awaiting authentication results.
474 static void
475 bfa_fcs_fabric_sm_auth(struct bfa_fcs_fabric_s *fabric,
476 enum bfa_fcs_fabric_event event)
478 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
479 bfa_trc(fabric->fcs, event);
481 switch (event) {
482 case BFA_FCS_FABRIC_SM_AUTH_FAILED:
483 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_auth_failed);
484 bfa_lps_discard(fabric->lps);
485 break;
487 case BFA_FCS_FABRIC_SM_AUTH_SUCCESS:
488 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_online);
489 bfa_fcs_fabric_notify_online(fabric);
490 break;
492 case BFA_FCS_FABRIC_SM_PERF_EVFP:
493 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_evfp);
494 break;
496 case BFA_FCS_FABRIC_SM_LINK_DOWN:
497 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
498 bfa_lps_discard(fabric->lps);
499 break;
501 case BFA_FCS_FABRIC_SM_DELETE:
502 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
503 bfa_fcs_fabric_delete(fabric);
504 break;
506 default:
507 bfa_sm_fault(fabric->fcs, event);
512 * Authentication failed
514 static void
515 bfa_fcs_fabric_sm_auth_failed(struct bfa_fcs_fabric_s *fabric,
516 enum bfa_fcs_fabric_event event)
518 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
519 bfa_trc(fabric->fcs, event);
521 switch (event) {
522 case BFA_FCS_FABRIC_SM_LINK_DOWN:
523 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
524 bfa_fcs_fabric_notify_offline(fabric);
525 break;
527 case BFA_FCS_FABRIC_SM_DELETE:
528 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
529 bfa_fcs_fabric_delete(fabric);
530 break;
532 default:
533 bfa_sm_fault(fabric->fcs, event);
538 * Port is in loopback mode.
540 static void
541 bfa_fcs_fabric_sm_loopback(struct bfa_fcs_fabric_s *fabric,
542 enum bfa_fcs_fabric_event event)
544 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
545 bfa_trc(fabric->fcs, event);
547 switch (event) {
548 case BFA_FCS_FABRIC_SM_LINK_DOWN:
549 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
550 bfa_fcs_fabric_notify_offline(fabric);
551 break;
553 case BFA_FCS_FABRIC_SM_DELETE:
554 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
555 bfa_fcs_fabric_delete(fabric);
556 break;
558 default:
559 bfa_sm_fault(fabric->fcs, event);
564 * There is no attached fabric - private loop or NPort-to-NPort topology.
566 static void
567 bfa_fcs_fabric_sm_nofabric(struct bfa_fcs_fabric_s *fabric,
568 enum bfa_fcs_fabric_event event)
570 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
571 bfa_trc(fabric->fcs, event);
573 switch (event) {
574 case BFA_FCS_FABRIC_SM_LINK_DOWN:
575 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
576 bfa_lps_discard(fabric->lps);
577 bfa_fcs_fabric_notify_offline(fabric);
578 break;
580 case BFA_FCS_FABRIC_SM_DELETE:
581 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
582 bfa_fcs_fabric_delete(fabric);
583 break;
585 case BFA_FCS_FABRIC_SM_NO_FABRIC:
586 bfa_trc(fabric->fcs, fabric->bb_credit);
587 bfa_fcport_set_tx_bbcredit(fabric->fcs->bfa,
588 fabric->bb_credit);
589 break;
591 default:
592 bfa_sm_fault(fabric->fcs, event);
597 * Fabric is online - normal operating state.
599 static void
600 bfa_fcs_fabric_sm_online(struct bfa_fcs_fabric_s *fabric,
601 enum bfa_fcs_fabric_event event)
603 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
604 bfa_trc(fabric->fcs, event);
606 switch (event) {
607 case BFA_FCS_FABRIC_SM_LINK_DOWN:
608 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
609 bfa_lps_discard(fabric->lps);
610 bfa_fcs_fabric_notify_offline(fabric);
611 break;
613 case BFA_FCS_FABRIC_SM_DELETE:
614 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
615 bfa_fcs_fabric_delete(fabric);
616 break;
618 case BFA_FCS_FABRIC_SM_AUTH_FAILED:
619 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_auth_failed);
620 bfa_lps_discard(fabric->lps);
621 break;
623 case BFA_FCS_FABRIC_SM_AUTH_SUCCESS:
624 break;
626 default:
627 bfa_sm_fault(fabric->fcs, event);
632 * Exchanging virtual fabric parameters.
634 static void
635 bfa_fcs_fabric_sm_evfp(struct bfa_fcs_fabric_s *fabric,
636 enum bfa_fcs_fabric_event event)
638 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
639 bfa_trc(fabric->fcs, event);
641 switch (event) {
642 case BFA_FCS_FABRIC_SM_CONT_OP:
643 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_evfp_done);
644 break;
646 case BFA_FCS_FABRIC_SM_ISOLATE:
647 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_isolated);
648 break;
650 default:
651 bfa_sm_fault(fabric->fcs, event);
656 * EVFP exchange complete and VFT tagging is enabled.
658 static void
659 bfa_fcs_fabric_sm_evfp_done(struct bfa_fcs_fabric_s *fabric,
660 enum bfa_fcs_fabric_event event)
662 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
663 bfa_trc(fabric->fcs, event);
667 * Port is isolated after EVFP exchange due to VF_ID mismatch (N and F).
669 static void
670 bfa_fcs_fabric_sm_isolated(struct bfa_fcs_fabric_s *fabric,
671 enum bfa_fcs_fabric_event event)
673 struct bfad_s *bfad = (struct bfad_s *)fabric->fcs->bfad;
674 char pwwn_ptr[BFA_STRING_32];
676 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
677 bfa_trc(fabric->fcs, event);
678 wwn2str(pwwn_ptr, fabric->bport.port_cfg.pwwn);
680 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
681 "Port is isolated due to VF_ID mismatch. "
682 "PWWN: %s Port VF_ID: %04x switch port VF_ID: %04x.",
683 pwwn_ptr, fabric->fcs->port_vfid,
684 fabric->event_arg.swp_vfid);
688 * Fabric is being deleted, awaiting vport delete completions.
690 static void
691 bfa_fcs_fabric_sm_deleting(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);
697 switch (event) {
698 case BFA_FCS_FABRIC_SM_DELCOMP:
699 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_uninit);
700 bfa_fcs_modexit_comp(fabric->fcs);
701 break;
703 case BFA_FCS_FABRIC_SM_LINK_UP:
704 break;
706 case BFA_FCS_FABRIC_SM_LINK_DOWN:
707 bfa_fcs_fabric_notify_offline(fabric);
708 break;
710 default:
711 bfa_sm_fault(fabric->fcs, event);
718 * fcs_fabric_private fabric private functions
721 static void
722 bfa_fcs_fabric_init(struct bfa_fcs_fabric_s *fabric)
724 struct bfa_lport_cfg_s *port_cfg = &fabric->bport.port_cfg;
726 port_cfg->roles = BFA_LPORT_ROLE_FCP_IM;
727 port_cfg->nwwn = bfa_ioc_get_nwwn(&fabric->fcs->bfa->ioc);
728 port_cfg->pwwn = bfa_ioc_get_pwwn(&fabric->fcs->bfa->ioc);
732 * Port Symbolic Name Creation for base port.
734 void
735 bfa_fcs_fabric_psymb_init(struct bfa_fcs_fabric_s *fabric)
737 struct bfa_lport_cfg_s *port_cfg = &fabric->bport.port_cfg;
738 char model[BFA_ADAPTER_MODEL_NAME_LEN] = {0};
739 struct bfa_fcs_driver_info_s *driver_info = &fabric->fcs->driver_info;
741 bfa_ioc_get_adapter_model(&fabric->fcs->bfa->ioc, model);
743 /* Model name/number */
744 strncpy((char *)&port_cfg->sym_name, model,
745 BFA_FCS_PORT_SYMBNAME_MODEL_SZ);
746 strncat((char *)&port_cfg->sym_name, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
747 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
749 /* Driver Version */
750 strncat((char *)&port_cfg->sym_name, (char *)driver_info->version,
751 BFA_FCS_PORT_SYMBNAME_VERSION_SZ);
752 strncat((char *)&port_cfg->sym_name, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
753 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
755 /* Host machine name */
756 strncat((char *)&port_cfg->sym_name,
757 (char *)driver_info->host_machine_name,
758 BFA_FCS_PORT_SYMBNAME_MACHINENAME_SZ);
759 strncat((char *)&port_cfg->sym_name, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
760 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
763 * Host OS Info :
764 * If OS Patch Info is not there, do not truncate any bytes from the
765 * OS name string and instead copy the entire OS info string (64 bytes).
767 if (driver_info->host_os_patch[0] == '\0') {
768 strncat((char *)&port_cfg->sym_name,
769 (char *)driver_info->host_os_name,
770 BFA_FCS_OS_STR_LEN);
771 strncat((char *)&port_cfg->sym_name,
772 BFA_FCS_PORT_SYMBNAME_SEPARATOR,
773 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
774 } else {
775 strncat((char *)&port_cfg->sym_name,
776 (char *)driver_info->host_os_name,
777 BFA_FCS_PORT_SYMBNAME_OSINFO_SZ);
778 strncat((char *)&port_cfg->sym_name,
779 BFA_FCS_PORT_SYMBNAME_SEPARATOR,
780 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
782 /* Append host OS Patch Info */
783 strncat((char *)&port_cfg->sym_name,
784 (char *)driver_info->host_os_patch,
785 BFA_FCS_PORT_SYMBNAME_OSPATCH_SZ);
788 /* null terminate */
789 port_cfg->sym_name.symname[BFA_SYMNAME_MAXLEN - 1] = 0;
793 * bfa lps login completion callback
795 void
796 bfa_cb_lps_flogi_comp(void *bfad, void *uarg, bfa_status_t status)
798 struct bfa_fcs_fabric_s *fabric = uarg;
800 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
801 bfa_trc(fabric->fcs, status);
803 switch (status) {
804 case BFA_STATUS_OK:
805 fabric->stats.flogi_accepts++;
806 break;
808 case BFA_STATUS_INVALID_MAC:
809 /* Only for CNA */
810 fabric->stats.flogi_acc_err++;
811 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_RETRY_OP);
813 return;
815 case BFA_STATUS_EPROTOCOL:
816 switch (bfa_lps_get_extstatus(fabric->lps)) {
817 case BFA_EPROTO_BAD_ACCEPT:
818 fabric->stats.flogi_acc_err++;
819 break;
821 case BFA_EPROTO_UNKNOWN_RSP:
822 fabric->stats.flogi_unknown_rsp++;
823 break;
825 default:
826 break;
828 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_RETRY_OP);
830 return;
832 case BFA_STATUS_FABRIC_RJT:
833 fabric->stats.flogi_rejects++;
834 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_RETRY_OP);
835 return;
837 default:
838 fabric->stats.flogi_rsp_err++;
839 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_RETRY_OP);
840 return;
843 fabric->bb_credit = bfa_lps_get_peer_bbcredit(fabric->lps);
844 bfa_trc(fabric->fcs, fabric->bb_credit);
846 if (!bfa_lps_is_brcd_fabric(fabric->lps))
847 fabric->fabric_name = bfa_lps_get_peer_nwwn(fabric->lps);
850 * Check port type. It should be 1 = F-port.
852 if (bfa_lps_is_fport(fabric->lps)) {
853 fabric->bport.pid = bfa_lps_get_pid(fabric->lps);
854 fabric->is_npiv = bfa_lps_is_npiv_en(fabric->lps);
855 fabric->is_auth = bfa_lps_is_authreq(fabric->lps);
856 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_CONT_OP);
857 } else {
859 * Nport-2-Nport direct attached
861 fabric->bport.port_topo.pn2n.rem_port_wwn =
862 bfa_lps_get_peer_pwwn(fabric->lps);
863 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_NO_FABRIC);
866 bfa_trc(fabric->fcs, fabric->bport.pid);
867 bfa_trc(fabric->fcs, fabric->is_npiv);
868 bfa_trc(fabric->fcs, fabric->is_auth);
871 * Allocate and send FLOGI.
873 static void
874 bfa_fcs_fabric_login(struct bfa_fcs_fabric_s *fabric)
876 struct bfa_s *bfa = fabric->fcs->bfa;
877 struct bfa_lport_cfg_s *pcfg = &fabric->bport.port_cfg;
878 u8 alpa = 0;
880 if (bfa_fcport_get_topology(bfa) == BFA_PORT_TOPOLOGY_LOOP)
881 alpa = bfa_fcport_get_myalpa(bfa);
883 bfa_lps_flogi(fabric->lps, fabric, alpa, bfa_fcport_get_maxfrsize(bfa),
884 pcfg->pwwn, pcfg->nwwn, fabric->auth_reqd);
886 fabric->stats.flogi_sent++;
889 static void
890 bfa_fcs_fabric_notify_online(struct bfa_fcs_fabric_s *fabric)
892 struct bfa_fcs_vport_s *vport;
893 struct list_head *qe, *qen;
895 bfa_trc(fabric->fcs, fabric->fabric_name);
897 bfa_fcs_fabric_set_opertype(fabric);
898 fabric->stats.fabric_onlines++;
901 * notify online event to base and then virtual ports
903 bfa_fcs_lport_online(&fabric->bport);
905 list_for_each_safe(qe, qen, &fabric->vport_q) {
906 vport = (struct bfa_fcs_vport_s *) qe;
907 bfa_fcs_vport_online(vport);
911 static void
912 bfa_fcs_fabric_notify_offline(struct bfa_fcs_fabric_s *fabric)
914 struct bfa_fcs_vport_s *vport;
915 struct list_head *qe, *qen;
917 bfa_trc(fabric->fcs, fabric->fabric_name);
918 fabric->stats.fabric_offlines++;
921 * notify offline event first to vports and then base port.
923 list_for_each_safe(qe, qen, &fabric->vport_q) {
924 vport = (struct bfa_fcs_vport_s *) qe;
925 bfa_fcs_vport_offline(vport);
928 bfa_fcs_lport_offline(&fabric->bport);
930 fabric->fabric_name = 0;
931 fabric->fabric_ip_addr[0] = 0;
934 static void
935 bfa_fcs_fabric_delay(void *cbarg)
937 struct bfa_fcs_fabric_s *fabric = cbarg;
939 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_DELAYED);
943 * Delete all vports and wait for vport delete completions.
945 static void
946 bfa_fcs_fabric_delete(struct bfa_fcs_fabric_s *fabric)
948 struct bfa_fcs_vport_s *vport;
949 struct list_head *qe, *qen;
951 list_for_each_safe(qe, qen, &fabric->vport_q) {
952 vport = (struct bfa_fcs_vport_s *) qe;
953 bfa_fcs_vport_fcs_delete(vport);
956 bfa_fcs_lport_delete(&fabric->bport);
957 bfa_wc_wait(&fabric->wc);
960 static void
961 bfa_fcs_fabric_delete_comp(void *cbarg)
963 struct bfa_fcs_fabric_s *fabric = cbarg;
965 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_DELCOMP);
969 * fcs_fabric_public fabric public functions
973 * Attach time initialization.
975 void
976 bfa_fcs_fabric_attach(struct bfa_fcs_s *fcs)
978 struct bfa_fcs_fabric_s *fabric;
980 fabric = &fcs->fabric;
981 memset(fabric, 0, sizeof(struct bfa_fcs_fabric_s));
984 * Initialize base fabric.
986 fabric->fcs = fcs;
987 INIT_LIST_HEAD(&fabric->vport_q);
988 INIT_LIST_HEAD(&fabric->vf_q);
989 fabric->lps = bfa_lps_alloc(fcs->bfa);
990 bfa_assert(fabric->lps);
993 * Initialize fabric delete completion handler. Fabric deletion is
994 * complete when the last vport delete is complete.
996 bfa_wc_init(&fabric->wc, bfa_fcs_fabric_delete_comp, fabric);
997 bfa_wc_up(&fabric->wc); /* For the base port */
999 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_uninit);
1000 bfa_fcs_lport_attach(&fabric->bport, fabric->fcs, FC_VF_ID_NULL, NULL);
1003 void
1004 bfa_fcs_fabric_modinit(struct bfa_fcs_s *fcs)
1006 bfa_sm_send_event(&fcs->fabric, BFA_FCS_FABRIC_SM_CREATE);
1007 bfa_trc(fcs, 0);
1011 * Module cleanup
1013 void
1014 bfa_fcs_fabric_modexit(struct bfa_fcs_s *fcs)
1016 struct bfa_fcs_fabric_s *fabric;
1018 bfa_trc(fcs, 0);
1021 * Cleanup base fabric.
1023 fabric = &fcs->fabric;
1024 bfa_lps_delete(fabric->lps);
1025 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_DELETE);
1029 * Fabric module start -- kick starts FCS actions
1031 void
1032 bfa_fcs_fabric_modstart(struct bfa_fcs_s *fcs)
1034 struct bfa_fcs_fabric_s *fabric;
1036 bfa_trc(fcs, 0);
1037 fabric = &fcs->fabric;
1038 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_START);
1041 bfa_boolean_t
1042 bfa_fcs_fabric_is_loopback(struct bfa_fcs_fabric_s *fabric)
1044 return bfa_sm_cmp_state(fabric, bfa_fcs_fabric_sm_loopback);
1047 bfa_boolean_t
1048 bfa_fcs_fabric_is_auth_failed(struct bfa_fcs_fabric_s *fabric)
1050 return bfa_sm_cmp_state(fabric, bfa_fcs_fabric_sm_auth_failed);
1053 enum bfa_port_type
1054 bfa_fcs_fabric_port_type(struct bfa_fcs_fabric_s *fabric)
1056 return fabric->oper_type;
1060 * Link up notification from BFA physical port module.
1062 void
1063 bfa_fcs_fabric_link_up(struct bfa_fcs_fabric_s *fabric)
1065 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
1066 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_LINK_UP);
1070 * Link down notification from BFA physical port module.
1072 void
1073 bfa_fcs_fabric_link_down(struct bfa_fcs_fabric_s *fabric)
1075 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
1076 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_LINK_DOWN);
1080 * A child vport is being created in the fabric.
1082 * Call from vport module at vport creation. A list of base port and vports
1083 * belonging to a fabric is maintained to propagate link events.
1085 * param[in] fabric - Fabric instance. This can be a base fabric or vf.
1086 * param[in] vport - Vport being created.
1088 * @return None (always succeeds)
1090 void
1091 bfa_fcs_fabric_addvport(struct bfa_fcs_fabric_s *fabric,
1092 struct bfa_fcs_vport_s *vport)
1095 * - add vport to fabric's vport_q
1097 bfa_trc(fabric->fcs, fabric->vf_id);
1099 list_add_tail(&vport->qe, &fabric->vport_q);
1100 fabric->num_vports++;
1101 bfa_wc_up(&fabric->wc);
1105 * A child vport is being deleted from fabric.
1107 * Vport is being deleted.
1109 void
1110 bfa_fcs_fabric_delvport(struct bfa_fcs_fabric_s *fabric,
1111 struct bfa_fcs_vport_s *vport)
1113 list_del(&vport->qe);
1114 fabric->num_vports--;
1115 bfa_wc_down(&fabric->wc);
1119 * Base port is deleted.
1121 void
1122 bfa_fcs_fabric_port_delete_comp(struct bfa_fcs_fabric_s *fabric)
1124 bfa_wc_down(&fabric->wc);
1129 * Check if fabric is online.
1131 * param[in] fabric - Fabric instance. This can be a base fabric or vf.
1133 * @return TRUE/FALSE
1136 bfa_fcs_fabric_is_online(struct bfa_fcs_fabric_s *fabric)
1138 return bfa_sm_cmp_state(fabric, bfa_fcs_fabric_sm_online);
1142 * Lookup for a vport withing a fabric given its pwwn
1144 struct bfa_fcs_vport_s *
1145 bfa_fcs_fabric_vport_lookup(struct bfa_fcs_fabric_s *fabric, wwn_t pwwn)
1147 struct bfa_fcs_vport_s *vport;
1148 struct list_head *qe;
1150 list_for_each(qe, &fabric->vport_q) {
1151 vport = (struct bfa_fcs_vport_s *) qe;
1152 if (bfa_fcs_lport_get_pwwn(&vport->lport) == pwwn)
1153 return vport;
1156 return NULL;
1160 * In a given fabric, return the number of lports.
1162 * param[in] fabric - Fabric instance. This can be a base fabric or vf.
1164 * @return : 1 or more.
1167 bfa_fcs_fabric_vport_count(struct bfa_fcs_fabric_s *fabric)
1169 return fabric->num_vports;
1173 * Get OUI of the attached switch.
1175 * Note : Use of this function should be avoided as much as possible.
1176 * This function should be used only if there is any requirement
1177 * to check for FOS version below 6.3.
1178 * To check if the attached fabric is a brocade fabric, use
1179 * bfa_lps_is_brcd_fabric() which works for FOS versions 6.3
1180 * or above only.
1184 bfa_fcs_fabric_get_switch_oui(struct bfa_fcs_fabric_s *fabric)
1186 wwn_t fab_nwwn;
1187 u8 *tmp;
1188 u16 oui;
1190 fab_nwwn = bfa_lps_get_peer_nwwn(fabric->lps);
1192 tmp = (u8 *)&fab_nwwn;
1193 oui = (tmp[3] << 8) | tmp[4];
1195 return oui;
1198 * Unsolicited frame receive handling.
1200 void
1201 bfa_fcs_fabric_uf_recv(struct bfa_fcs_fabric_s *fabric, struct fchs_s *fchs,
1202 u16 len)
1204 u32 pid = fchs->d_id;
1205 struct bfa_fcs_vport_s *vport;
1206 struct list_head *qe;
1207 struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
1208 struct fc_logi_s *flogi = (struct fc_logi_s *) els_cmd;
1210 bfa_trc(fabric->fcs, len);
1211 bfa_trc(fabric->fcs, pid);
1214 * Look for our own FLOGI frames being looped back. This means an
1215 * external loopback cable is in place. Our own FLOGI frames are
1216 * sometimes looped back when switch port gets temporarily bypassed.
1218 if ((pid == bfa_os_ntoh3b(FC_FABRIC_PORT)) &&
1219 (els_cmd->els_code == FC_ELS_FLOGI) &&
1220 (flogi->port_name == bfa_fcs_lport_get_pwwn(&fabric->bport))) {
1221 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_LOOPBACK);
1222 return;
1226 * FLOGI/EVFP exchanges should be consumed by base fabric.
1228 if (fchs->d_id == bfa_os_hton3b(FC_FABRIC_PORT)) {
1229 bfa_trc(fabric->fcs, pid);
1230 bfa_fcs_fabric_process_uf(fabric, fchs, len);
1231 return;
1234 if (fabric->bport.pid == pid) {
1236 * All authentication frames should be routed to auth
1238 bfa_trc(fabric->fcs, els_cmd->els_code);
1239 if (els_cmd->els_code == FC_ELS_AUTH) {
1240 bfa_trc(fabric->fcs, els_cmd->els_code);
1241 return;
1244 bfa_trc(fabric->fcs, *(u8 *) ((u8 *) fchs));
1245 bfa_fcs_lport_uf_recv(&fabric->bport, fchs, len);
1246 return;
1250 * look for a matching local port ID
1252 list_for_each(qe, &fabric->vport_q) {
1253 vport = (struct bfa_fcs_vport_s *) qe;
1254 if (vport->lport.pid == pid) {
1255 bfa_fcs_lport_uf_recv(&vport->lport, fchs, len);
1256 return;
1259 bfa_trc(fabric->fcs, els_cmd->els_code);
1260 bfa_fcs_lport_uf_recv(&fabric->bport, fchs, len);
1264 * Unsolicited frames to be processed by fabric.
1266 static void
1267 bfa_fcs_fabric_process_uf(struct bfa_fcs_fabric_s *fabric, struct fchs_s *fchs,
1268 u16 len)
1270 struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
1272 bfa_trc(fabric->fcs, els_cmd->els_code);
1274 switch (els_cmd->els_code) {
1275 case FC_ELS_FLOGI:
1276 bfa_fcs_fabric_process_flogi(fabric, fchs, len);
1277 break;
1279 default:
1281 * need to generate a LS_RJT
1283 break;
1288 * Process incoming FLOGI
1290 static void
1291 bfa_fcs_fabric_process_flogi(struct bfa_fcs_fabric_s *fabric,
1292 struct fchs_s *fchs, u16 len)
1294 struct fc_logi_s *flogi = (struct fc_logi_s *) (fchs + 1);
1295 struct bfa_fcs_lport_s *bport = &fabric->bport;
1297 bfa_trc(fabric->fcs, fchs->s_id);
1299 fabric->stats.flogi_rcvd++;
1301 * Check port type. It should be 0 = n-port.
1303 if (flogi->csp.port_type) {
1305 * @todo: may need to send a LS_RJT
1307 bfa_trc(fabric->fcs, flogi->port_name);
1308 fabric->stats.flogi_rejected++;
1309 return;
1312 fabric->bb_credit = be16_to_cpu(flogi->csp.bbcred);
1313 bport->port_topo.pn2n.rem_port_wwn = flogi->port_name;
1314 bport->port_topo.pn2n.reply_oxid = fchs->ox_id;
1317 * Send a Flogi Acc
1319 bfa_fcs_fabric_send_flogi_acc(fabric);
1320 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_NO_FABRIC);
1323 static void
1324 bfa_fcs_fabric_send_flogi_acc(struct bfa_fcs_fabric_s *fabric)
1326 struct bfa_lport_cfg_s *pcfg = &fabric->bport.port_cfg;
1327 struct bfa_fcs_lport_n2n_s *n2n_port = &fabric->bport.port_topo.pn2n;
1328 struct bfa_s *bfa = fabric->fcs->bfa;
1329 struct bfa_fcxp_s *fcxp;
1330 u16 reqlen;
1331 struct fchs_s fchs;
1333 fcxp = bfa_fcs_fcxp_alloc(fabric->fcs);
1335 * Do not expect this failure -- expect remote node to retry
1337 if (!fcxp)
1338 return;
1340 reqlen = fc_flogi_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
1341 bfa_os_hton3b(FC_FABRIC_PORT),
1342 n2n_port->reply_oxid, pcfg->pwwn,
1343 pcfg->nwwn,
1344 bfa_fcport_get_maxfrsize(bfa),
1345 bfa_fcport_get_rx_bbcredit(bfa));
1347 bfa_fcxp_send(fcxp, NULL, fabric->vf_id, bfa_lps_get_tag(fabric->lps),
1348 BFA_FALSE, FC_CLASS_3,
1349 reqlen, &fchs, bfa_fcs_fabric_flogiacc_comp, fabric,
1350 FC_MAX_PDUSZ, 0);
1354 * Flogi Acc completion callback.
1356 static void
1357 bfa_fcs_fabric_flogiacc_comp(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
1358 bfa_status_t status, u32 rsp_len,
1359 u32 resid_len, struct fchs_s *rspfchs)
1361 struct bfa_fcs_fabric_s *fabric = cbarg;
1363 bfa_trc(fabric->fcs, status);
1368 * @param[in] fabric - fabric
1369 * @param[in] wwn_t - new fabric name
1371 * @return - none
1373 void
1374 bfa_fcs_fabric_set_fabric_name(struct bfa_fcs_fabric_s *fabric,
1375 wwn_t fabric_name)
1377 struct bfad_s *bfad = (struct bfad_s *)fabric->fcs->bfad;
1378 char pwwn_ptr[BFA_STRING_32];
1379 char fwwn_ptr[BFA_STRING_32];
1381 bfa_trc(fabric->fcs, fabric_name);
1383 if (fabric->fabric_name == 0) {
1385 * With BRCD switches, we don't get Fabric Name in FLOGI.
1386 * Don't generate a fabric name change event in this case.
1388 fabric->fabric_name = fabric_name;
1389 } else {
1390 fabric->fabric_name = fabric_name;
1391 wwn2str(pwwn_ptr, bfa_fcs_lport_get_pwwn(&fabric->bport));
1392 wwn2str(fwwn_ptr,
1393 bfa_fcs_lport_get_fabric_name(&fabric->bport));
1394 BFA_LOG(KERN_WARNING, bfad, bfa_log_level,
1395 "Base port WWN = %s Fabric WWN = %s\n",
1396 pwwn_ptr, fwwn_ptr);
1401 * Returns FCS vf structure for a given vf_id.
1403 * param[in] vf_id - VF_ID
1405 * return
1406 * If lookup succeeds, retuns fcs vf object, otherwise returns NULL
1408 bfa_fcs_vf_t *
1409 bfa_fcs_vf_lookup(struct bfa_fcs_s *fcs, u16 vf_id)
1411 bfa_trc(fcs, vf_id);
1412 if (vf_id == FC_VF_ID_NULL)
1413 return &fcs->fabric;
1415 return NULL;
1419 * BFA FCS PPORT ( physical port)
1421 static void
1422 bfa_fcs_port_event_handler(void *cbarg, enum bfa_port_linkstate event)
1424 struct bfa_fcs_s *fcs = cbarg;
1426 bfa_trc(fcs, event);
1428 switch (event) {
1429 case BFA_PORT_LINKUP:
1430 bfa_fcs_fabric_link_up(&fcs->fabric);
1431 break;
1433 case BFA_PORT_LINKDOWN:
1434 bfa_fcs_fabric_link_down(&fcs->fabric);
1435 break;
1437 default:
1438 bfa_assert(0);
1442 void
1443 bfa_fcs_port_attach(struct bfa_fcs_s *fcs)
1445 bfa_fcport_event_register(fcs->bfa, bfa_fcs_port_event_handler, fcs);
1449 * BFA FCS UF ( Unsolicited Frames)
1453 * BFA callback for unsolicited frame receive handler.
1455 * @param[in] cbarg callback arg for receive handler
1456 * @param[in] uf unsolicited frame descriptor
1458 * @return None
1460 static void
1461 bfa_fcs_uf_recv(void *cbarg, struct bfa_uf_s *uf)
1463 struct bfa_fcs_s *fcs = (struct bfa_fcs_s *) cbarg;
1464 struct fchs_s *fchs = bfa_uf_get_frmbuf(uf);
1465 u16 len = bfa_uf_get_frmlen(uf);
1466 struct fc_vft_s *vft;
1467 struct bfa_fcs_fabric_s *fabric;
1470 * check for VFT header
1472 if (fchs->routing == FC_RTG_EXT_HDR &&
1473 fchs->cat_info == FC_CAT_VFT_HDR) {
1474 bfa_stats(fcs, uf.tagged);
1475 vft = bfa_uf_get_frmbuf(uf);
1476 if (fcs->port_vfid == vft->vf_id)
1477 fabric = &fcs->fabric;
1478 else
1479 fabric = bfa_fcs_vf_lookup(fcs, (u16) vft->vf_id);
1482 * drop frame if vfid is unknown
1484 if (!fabric) {
1485 bfa_assert(0);
1486 bfa_stats(fcs, uf.vfid_unknown);
1487 bfa_uf_free(uf);
1488 return;
1492 * skip vft header
1494 fchs = (struct fchs_s *) (vft + 1);
1495 len -= sizeof(struct fc_vft_s);
1497 bfa_trc(fcs, vft->vf_id);
1498 } else {
1499 bfa_stats(fcs, uf.untagged);
1500 fabric = &fcs->fabric;
1503 bfa_trc(fcs, ((u32 *) fchs)[0]);
1504 bfa_trc(fcs, ((u32 *) fchs)[1]);
1505 bfa_trc(fcs, ((u32 *) fchs)[2]);
1506 bfa_trc(fcs, ((u32 *) fchs)[3]);
1507 bfa_trc(fcs, ((u32 *) fchs)[4]);
1508 bfa_trc(fcs, ((u32 *) fchs)[5]);
1509 bfa_trc(fcs, len);
1511 bfa_fcs_fabric_uf_recv(fabric, fchs, len);
1512 bfa_uf_free(uf);
1515 void
1516 bfa_fcs_uf_attach(struct bfa_fcs_s *fcs)
1518 bfa_uf_recv_register(fcs->bfa, bfa_fcs_uf_recv, fcs);