watchdog: pic32-dmt: Remove .owner field for driver
[linux/fpc-iii.git] / drivers / scsi / bfa / bfa_fcs.c
blob1e7e139d71eabd1bbdc9e1daa4b589f640e231e6
1 /*
2 * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
3 * Copyright (c) 2014- QLogic Corporation.
4 * All rights reserved
5 * www.qlogic.com
7 * Linux driver for QLogic BR-series Fibre Channel Host Bus Adapter.
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License (GPL) Version 2 as
11 * published by the Free Software Foundation
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
20 * bfa_fcs.c BFA FCS main
23 #include "bfad_drv.h"
24 #include "bfad_im.h"
25 #include "bfa_fcs.h"
26 #include "bfa_fcbuild.h"
28 BFA_TRC_FILE(FCS, FCS);
31 * FCS sub-modules
33 struct bfa_fcs_mod_s {
34 void (*attach) (struct bfa_fcs_s *fcs);
35 void (*modinit) (struct bfa_fcs_s *fcs);
36 void (*modexit) (struct bfa_fcs_s *fcs);
39 #define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
41 static struct bfa_fcs_mod_s fcs_modules[] = {
42 { bfa_fcs_port_attach, NULL, NULL },
43 { bfa_fcs_uf_attach, NULL, NULL },
44 { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
45 bfa_fcs_fabric_modexit },
49 * fcs_api BFA FCS API
52 static void
53 bfa_fcs_exit_comp(void *fcs_cbarg)
55 struct bfa_fcs_s *fcs = fcs_cbarg;
56 struct bfad_s *bfad = fcs->bfad;
58 complete(&bfad->comp);
64 * fcs_api BFA FCS API
68 * fcs attach -- called once to initialize data structures at driver attach time
70 void
71 bfa_fcs_attach(struct bfa_fcs_s *fcs, struct bfa_s *bfa, struct bfad_s *bfad,
72 bfa_boolean_t min_cfg)
74 int i;
75 struct bfa_fcs_mod_s *mod;
77 fcs->bfa = bfa;
78 fcs->bfad = bfad;
79 fcs->min_cfg = min_cfg;
80 fcs->num_rport_logins = 0;
82 bfa->fcs = BFA_TRUE;
83 fcbuild_init();
85 for (i = 0; i < ARRAY_SIZE(fcs_modules); i++) {
86 mod = &fcs_modules[i];
87 if (mod->attach)
88 mod->attach(fcs);
93 * fcs initialization, called once after bfa initialization is complete
95 void
96 bfa_fcs_init(struct bfa_fcs_s *fcs)
98 int i;
99 struct bfa_fcs_mod_s *mod;
101 for (i = 0; i < ARRAY_SIZE(fcs_modules); i++) {
102 mod = &fcs_modules[i];
103 if (mod->modinit)
104 mod->modinit(fcs);
109 * FCS update cfg - reset the pwwn/nwwn of fabric base logical port
110 * with values learned during bfa_init firmware GETATTR REQ.
112 void
113 bfa_fcs_update_cfg(struct bfa_fcs_s *fcs)
115 struct bfa_fcs_fabric_s *fabric = &fcs->fabric;
116 struct bfa_lport_cfg_s *port_cfg = &fabric->bport.port_cfg;
117 struct bfa_ioc_s *ioc = &fabric->fcs->bfa->ioc;
119 port_cfg->nwwn = ioc->attr->nwwn;
120 port_cfg->pwwn = ioc->attr->pwwn;
124 * Stop FCS operations.
126 void
127 bfa_fcs_stop(struct bfa_fcs_s *fcs)
129 bfa_wc_init(&fcs->wc, bfa_fcs_exit_comp, fcs);
130 bfa_wc_up(&fcs->wc);
131 bfa_fcs_fabric_modstop(fcs);
132 bfa_wc_wait(&fcs->wc);
136 * fcs pbc vport initialization
138 void
139 bfa_fcs_pbc_vport_init(struct bfa_fcs_s *fcs)
141 int i, npbc_vports;
142 struct bfi_pbc_vport_s pbc_vports[BFI_PBC_MAX_VPORTS];
144 /* Initialize pbc vports */
145 if (!fcs->min_cfg) {
146 npbc_vports =
147 bfa_iocfc_get_pbc_vports(fcs->bfa, pbc_vports);
148 for (i = 0; i < npbc_vports; i++)
149 bfa_fcb_pbc_vport_create(fcs->bfa->bfad, pbc_vports[i]);
154 * brief
155 * FCS driver details initialization.
157 * param[in] fcs FCS instance
158 * param[in] driver_info Driver Details
160 * return None
162 void
163 bfa_fcs_driver_info_init(struct bfa_fcs_s *fcs,
164 struct bfa_fcs_driver_info_s *driver_info)
167 fcs->driver_info = *driver_info;
169 bfa_fcs_fabric_psymb_init(&fcs->fabric);
170 bfa_fcs_fabric_nsymb_init(&fcs->fabric);
174 * brief
175 * FCS instance cleanup and exit.
177 * param[in] fcs FCS instance
178 * return None
180 void
181 bfa_fcs_exit(struct bfa_fcs_s *fcs)
183 struct bfa_fcs_mod_s *mod;
184 int nmods, i;
186 bfa_wc_init(&fcs->wc, bfa_fcs_exit_comp, fcs);
188 nmods = ARRAY_SIZE(fcs_modules);
190 for (i = 0; i < nmods; i++) {
192 mod = &fcs_modules[i];
193 if (mod->modexit) {
194 bfa_wc_up(&fcs->wc);
195 mod->modexit(fcs);
199 bfa_wc_wait(&fcs->wc);
204 * Fabric module implementation.
207 #define BFA_FCS_FABRIC_RETRY_DELAY (2000) /* Milliseconds */
208 #define BFA_FCS_FABRIC_CLEANUP_DELAY (10000) /* Milliseconds */
210 #define bfa_fcs_fabric_set_opertype(__fabric) do { \
211 if (bfa_fcport_get_topology((__fabric)->fcs->bfa) \
212 == BFA_PORT_TOPOLOGY_P2P) { \
213 if (fabric->fab_type == BFA_FCS_FABRIC_SWITCHED) \
214 (__fabric)->oper_type = BFA_PORT_TYPE_NPORT; \
215 else \
216 (__fabric)->oper_type = BFA_PORT_TYPE_P2P; \
217 } else \
218 (__fabric)->oper_type = BFA_PORT_TYPE_NLPORT; \
219 } while (0)
222 * forward declarations
224 static void bfa_fcs_fabric_init(struct bfa_fcs_fabric_s *fabric);
225 static void bfa_fcs_fabric_login(struct bfa_fcs_fabric_s *fabric);
226 static void bfa_fcs_fabric_notify_online(struct bfa_fcs_fabric_s *fabric);
227 static void bfa_fcs_fabric_notify_offline(struct bfa_fcs_fabric_s *fabric);
228 static void bfa_fcs_fabric_delay(void *cbarg);
229 static void bfa_fcs_fabric_delete(struct bfa_fcs_fabric_s *fabric);
230 static void bfa_fcs_fabric_delete_comp(void *cbarg);
231 static void bfa_fcs_fabric_stop(struct bfa_fcs_fabric_s *fabric);
232 static void bfa_fcs_fabric_stop_comp(void *cbarg);
233 static void bfa_fcs_fabric_process_uf(struct bfa_fcs_fabric_s *fabric,
234 struct fchs_s *fchs, u16 len);
235 static void bfa_fcs_fabric_process_flogi(struct bfa_fcs_fabric_s *fabric,
236 struct fchs_s *fchs, u16 len);
237 static void bfa_fcs_fabric_send_flogi_acc(struct bfa_fcs_fabric_s *fabric);
238 static void bfa_fcs_fabric_flogiacc_comp(void *fcsarg,
239 struct bfa_fcxp_s *fcxp, void *cbarg,
240 bfa_status_t status,
241 u32 rsp_len,
242 u32 resid_len,
243 struct fchs_s *rspfchs);
245 static void bfa_fcs_fabric_sm_uninit(struct bfa_fcs_fabric_s *fabric,
246 enum bfa_fcs_fabric_event event);
247 static void bfa_fcs_fabric_sm_created(struct bfa_fcs_fabric_s *fabric,
248 enum bfa_fcs_fabric_event event);
249 static void bfa_fcs_fabric_sm_linkdown(struct bfa_fcs_fabric_s *fabric,
250 enum bfa_fcs_fabric_event event);
251 static void bfa_fcs_fabric_sm_flogi(struct bfa_fcs_fabric_s *fabric,
252 enum bfa_fcs_fabric_event event);
253 static void bfa_fcs_fabric_sm_flogi_retry(struct bfa_fcs_fabric_s *fabric,
254 enum bfa_fcs_fabric_event event);
255 static void bfa_fcs_fabric_sm_auth(struct bfa_fcs_fabric_s *fabric,
256 enum bfa_fcs_fabric_event event);
257 static void bfa_fcs_fabric_sm_nofabric(struct bfa_fcs_fabric_s *fabric,
258 enum bfa_fcs_fabric_event event);
259 static void bfa_fcs_fabric_sm_evfp(struct bfa_fcs_fabric_s *fabric,
260 enum bfa_fcs_fabric_event event);
261 static void bfa_fcs_fabric_sm_evfp_done(struct bfa_fcs_fabric_s *fabric,
262 enum bfa_fcs_fabric_event event);
263 static void bfa_fcs_fabric_sm_isolated(struct bfa_fcs_fabric_s *fabric,
264 enum bfa_fcs_fabric_event event);
265 static void bfa_fcs_fabric_sm_deleting(struct bfa_fcs_fabric_s *fabric,
266 enum bfa_fcs_fabric_event event);
267 static void bfa_fcs_fabric_sm_stopping(struct bfa_fcs_fabric_s *fabric,
268 enum bfa_fcs_fabric_event event);
269 static void bfa_fcs_fabric_sm_cleanup(struct bfa_fcs_fabric_s *fabric,
270 enum bfa_fcs_fabric_event event);
272 * Beginning state before fabric creation.
274 static void
275 bfa_fcs_fabric_sm_uninit(struct bfa_fcs_fabric_s *fabric,
276 enum bfa_fcs_fabric_event event)
278 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
279 bfa_trc(fabric->fcs, event);
281 switch (event) {
282 case BFA_FCS_FABRIC_SM_CREATE:
283 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_created);
284 bfa_fcs_fabric_init(fabric);
285 bfa_fcs_lport_init(&fabric->bport, &fabric->bport.port_cfg);
286 break;
288 case BFA_FCS_FABRIC_SM_LINK_UP:
289 case BFA_FCS_FABRIC_SM_LINK_DOWN:
290 break;
292 default:
293 bfa_sm_fault(fabric->fcs, event);
298 * Beginning state before fabric creation.
300 static void
301 bfa_fcs_fabric_sm_created(struct bfa_fcs_fabric_s *fabric,
302 enum bfa_fcs_fabric_event event)
304 struct bfa_s *bfa = fabric->fcs->bfa;
306 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
307 bfa_trc(fabric->fcs, event);
309 switch (event) {
310 case BFA_FCS_FABRIC_SM_START:
311 if (!bfa_fcport_is_linkup(fabric->fcs->bfa)) {
312 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
313 break;
315 if (bfa_fcport_get_topology(bfa) ==
316 BFA_PORT_TOPOLOGY_LOOP) {
317 fabric->fab_type = BFA_FCS_FABRIC_LOOP;
318 fabric->bport.pid = bfa_fcport_get_myalpa(bfa);
319 fabric->bport.pid = bfa_hton3b(fabric->bport.pid);
320 bfa_sm_set_state(fabric,
321 bfa_fcs_fabric_sm_online);
322 bfa_fcs_fabric_set_opertype(fabric);
323 bfa_fcs_lport_online(&fabric->bport);
324 } else {
325 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_flogi);
326 bfa_fcs_fabric_login(fabric);
328 break;
330 case BFA_FCS_FABRIC_SM_LINK_UP:
331 case BFA_FCS_FABRIC_SM_LINK_DOWN:
332 break;
334 case BFA_FCS_FABRIC_SM_DELETE:
335 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
336 bfa_fcs_fabric_delete(fabric);
337 break;
339 default:
340 bfa_sm_fault(fabric->fcs, event);
345 * Link is down, awaiting LINK UP event from port. This is also the
346 * first state at fabric creation.
348 static void
349 bfa_fcs_fabric_sm_linkdown(struct bfa_fcs_fabric_s *fabric,
350 enum bfa_fcs_fabric_event event)
352 struct bfa_s *bfa = fabric->fcs->bfa;
354 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
355 bfa_trc(fabric->fcs, event);
357 switch (event) {
358 case BFA_FCS_FABRIC_SM_LINK_UP:
359 if (bfa_fcport_get_topology(bfa) != BFA_PORT_TOPOLOGY_LOOP) {
360 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_flogi);
361 bfa_fcs_fabric_login(fabric);
362 break;
364 fabric->fab_type = BFA_FCS_FABRIC_LOOP;
365 fabric->bport.pid = bfa_fcport_get_myalpa(bfa);
366 fabric->bport.pid = bfa_hton3b(fabric->bport.pid);
367 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_online);
368 bfa_fcs_fabric_set_opertype(fabric);
369 bfa_fcs_lport_online(&fabric->bport);
370 break;
372 case BFA_FCS_FABRIC_SM_RETRY_OP:
373 case BFA_FCS_FABRIC_SM_LOOPBACK:
374 break;
376 case BFA_FCS_FABRIC_SM_DELETE:
377 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
378 bfa_fcs_fabric_delete(fabric);
379 break;
381 case BFA_FCS_FABRIC_SM_STOP:
382 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_cleanup);
383 bfa_fcs_fabric_stop(fabric);
384 break;
386 default:
387 bfa_sm_fault(fabric->fcs, event);
392 * FLOGI is in progress, awaiting FLOGI reply.
394 static void
395 bfa_fcs_fabric_sm_flogi(struct bfa_fcs_fabric_s *fabric,
396 enum bfa_fcs_fabric_event event)
398 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
399 bfa_trc(fabric->fcs, event);
401 switch (event) {
402 case BFA_FCS_FABRIC_SM_CONT_OP:
404 bfa_fcport_set_tx_bbcredit(fabric->fcs->bfa,
405 fabric->bb_credit);
406 fabric->fab_type = BFA_FCS_FABRIC_SWITCHED;
408 if (fabric->auth_reqd && fabric->is_auth) {
409 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_auth);
410 bfa_trc(fabric->fcs, event);
411 } else {
412 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_online);
413 bfa_fcs_fabric_notify_online(fabric);
415 break;
417 case BFA_FCS_FABRIC_SM_RETRY_OP:
418 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_flogi_retry);
419 bfa_timer_start(fabric->fcs->bfa, &fabric->delay_timer,
420 bfa_fcs_fabric_delay, fabric,
421 BFA_FCS_FABRIC_RETRY_DELAY);
422 break;
424 case BFA_FCS_FABRIC_SM_LOOPBACK:
425 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_loopback);
426 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
427 bfa_fcs_fabric_set_opertype(fabric);
428 break;
430 case BFA_FCS_FABRIC_SM_NO_FABRIC:
431 fabric->fab_type = BFA_FCS_FABRIC_N2N;
432 bfa_fcport_set_tx_bbcredit(fabric->fcs->bfa,
433 fabric->bb_credit);
434 bfa_fcs_fabric_notify_online(fabric);
435 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_nofabric);
436 break;
438 case BFA_FCS_FABRIC_SM_LINK_DOWN:
439 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
440 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
441 break;
443 case BFA_FCS_FABRIC_SM_DELETE:
444 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
445 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
446 bfa_fcs_fabric_delete(fabric);
447 break;
449 default:
450 bfa_sm_fault(fabric->fcs, event);
455 static void
456 bfa_fcs_fabric_sm_flogi_retry(struct bfa_fcs_fabric_s *fabric,
457 enum bfa_fcs_fabric_event event)
459 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
460 bfa_trc(fabric->fcs, event);
462 switch (event) {
463 case BFA_FCS_FABRIC_SM_DELAYED:
464 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_flogi);
465 bfa_fcs_fabric_login(fabric);
466 break;
468 case BFA_FCS_FABRIC_SM_LINK_DOWN:
469 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
470 bfa_timer_stop(&fabric->delay_timer);
471 break;
473 case BFA_FCS_FABRIC_SM_DELETE:
474 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
475 bfa_timer_stop(&fabric->delay_timer);
476 bfa_fcs_fabric_delete(fabric);
477 break;
479 default:
480 bfa_sm_fault(fabric->fcs, event);
485 * Authentication is in progress, awaiting authentication results.
487 static void
488 bfa_fcs_fabric_sm_auth(struct bfa_fcs_fabric_s *fabric,
489 enum bfa_fcs_fabric_event event)
491 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
492 bfa_trc(fabric->fcs, event);
494 switch (event) {
495 case BFA_FCS_FABRIC_SM_AUTH_FAILED:
496 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_auth_failed);
497 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
498 break;
500 case BFA_FCS_FABRIC_SM_AUTH_SUCCESS:
501 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_online);
502 bfa_fcs_fabric_notify_online(fabric);
503 break;
505 case BFA_FCS_FABRIC_SM_PERF_EVFP:
506 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_evfp);
507 break;
509 case BFA_FCS_FABRIC_SM_LINK_DOWN:
510 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
511 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
512 break;
514 case BFA_FCS_FABRIC_SM_DELETE:
515 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
516 bfa_fcs_fabric_delete(fabric);
517 break;
519 default:
520 bfa_sm_fault(fabric->fcs, event);
525 * Authentication failed
527 void
528 bfa_fcs_fabric_sm_auth_failed(struct bfa_fcs_fabric_s *fabric,
529 enum bfa_fcs_fabric_event event)
531 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
532 bfa_trc(fabric->fcs, event);
534 switch (event) {
535 case BFA_FCS_FABRIC_SM_LINK_DOWN:
536 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
537 bfa_fcs_fabric_notify_offline(fabric);
538 break;
540 case BFA_FCS_FABRIC_SM_DELETE:
541 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
542 bfa_fcs_fabric_delete(fabric);
543 break;
545 default:
546 bfa_sm_fault(fabric->fcs, event);
551 * Port is in loopback mode.
553 void
554 bfa_fcs_fabric_sm_loopback(struct bfa_fcs_fabric_s *fabric,
555 enum bfa_fcs_fabric_event event)
557 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
558 bfa_trc(fabric->fcs, event);
560 switch (event) {
561 case BFA_FCS_FABRIC_SM_LINK_DOWN:
562 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
563 bfa_fcs_fabric_notify_offline(fabric);
564 break;
566 case BFA_FCS_FABRIC_SM_DELETE:
567 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
568 bfa_fcs_fabric_delete(fabric);
569 break;
571 default:
572 bfa_sm_fault(fabric->fcs, event);
577 * There is no attached fabric - private loop or NPort-to-NPort topology.
579 static void
580 bfa_fcs_fabric_sm_nofabric(struct bfa_fcs_fabric_s *fabric,
581 enum bfa_fcs_fabric_event event)
583 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
584 bfa_trc(fabric->fcs, event);
586 switch (event) {
587 case BFA_FCS_FABRIC_SM_LINK_DOWN:
588 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
589 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
590 bfa_fcs_fabric_notify_offline(fabric);
591 break;
593 case BFA_FCS_FABRIC_SM_DELETE:
594 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
595 bfa_fcs_fabric_delete(fabric);
596 break;
598 case BFA_FCS_FABRIC_SM_NO_FABRIC:
599 bfa_trc(fabric->fcs, fabric->bb_credit);
600 bfa_fcport_set_tx_bbcredit(fabric->fcs->bfa,
601 fabric->bb_credit);
602 break;
604 case BFA_FCS_FABRIC_SM_RETRY_OP:
605 break;
607 default:
608 bfa_sm_fault(fabric->fcs, event);
613 * Fabric is online - normal operating state.
615 void
616 bfa_fcs_fabric_sm_online(struct bfa_fcs_fabric_s *fabric,
617 enum bfa_fcs_fabric_event event)
619 struct bfa_s *bfa = fabric->fcs->bfa;
621 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
622 bfa_trc(fabric->fcs, event);
624 switch (event) {
625 case BFA_FCS_FABRIC_SM_LINK_DOWN:
626 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
627 if (bfa_fcport_get_topology(bfa) == BFA_PORT_TOPOLOGY_LOOP) {
628 bfa_fcs_lport_offline(&fabric->bport);
629 } else {
630 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
631 bfa_fcs_fabric_notify_offline(fabric);
633 break;
635 case BFA_FCS_FABRIC_SM_DELETE:
636 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
637 bfa_fcs_fabric_delete(fabric);
638 break;
640 case BFA_FCS_FABRIC_SM_STOP:
641 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_stopping);
642 bfa_fcs_fabric_stop(fabric);
643 break;
645 case BFA_FCS_FABRIC_SM_AUTH_FAILED:
646 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_auth_failed);
647 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
648 break;
650 case BFA_FCS_FABRIC_SM_AUTH_SUCCESS:
651 break;
653 default:
654 bfa_sm_fault(fabric->fcs, event);
659 * Exchanging virtual fabric parameters.
661 static void
662 bfa_fcs_fabric_sm_evfp(struct bfa_fcs_fabric_s *fabric,
663 enum bfa_fcs_fabric_event event)
665 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
666 bfa_trc(fabric->fcs, event);
668 switch (event) {
669 case BFA_FCS_FABRIC_SM_CONT_OP:
670 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_evfp_done);
671 break;
673 case BFA_FCS_FABRIC_SM_ISOLATE:
674 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_isolated);
675 break;
677 default:
678 bfa_sm_fault(fabric->fcs, event);
683 * EVFP exchange complete and VFT tagging is enabled.
685 static void
686 bfa_fcs_fabric_sm_evfp_done(struct bfa_fcs_fabric_s *fabric,
687 enum bfa_fcs_fabric_event event)
689 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
690 bfa_trc(fabric->fcs, event);
694 * Port is isolated after EVFP exchange due to VF_ID mismatch (N and F).
696 static void
697 bfa_fcs_fabric_sm_isolated(struct bfa_fcs_fabric_s *fabric,
698 enum bfa_fcs_fabric_event event)
700 struct bfad_s *bfad = (struct bfad_s *)fabric->fcs->bfad;
701 char pwwn_ptr[BFA_STRING_32];
703 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
704 bfa_trc(fabric->fcs, event);
705 wwn2str(pwwn_ptr, fabric->bport.port_cfg.pwwn);
707 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
708 "Port is isolated due to VF_ID mismatch. "
709 "PWWN: %s Port VF_ID: %04x switch port VF_ID: %04x.",
710 pwwn_ptr, fabric->fcs->port_vfid,
711 fabric->event_arg.swp_vfid);
715 * Fabric is being deleted, awaiting vport delete completions.
717 static void
718 bfa_fcs_fabric_sm_deleting(struct bfa_fcs_fabric_s *fabric,
719 enum bfa_fcs_fabric_event event)
721 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
722 bfa_trc(fabric->fcs, event);
724 switch (event) {
725 case BFA_FCS_FABRIC_SM_DELCOMP:
726 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_uninit);
727 bfa_wc_down(&fabric->fcs->wc);
728 break;
730 case BFA_FCS_FABRIC_SM_LINK_UP:
731 break;
733 case BFA_FCS_FABRIC_SM_LINK_DOWN:
734 bfa_fcs_fabric_notify_offline(fabric);
735 break;
737 default:
738 bfa_sm_fault(fabric->fcs, event);
743 * Fabric is being stopped, awaiting vport stop completions.
745 static void
746 bfa_fcs_fabric_sm_stopping(struct bfa_fcs_fabric_s *fabric,
747 enum bfa_fcs_fabric_event event)
749 struct bfa_s *bfa = fabric->fcs->bfa;
751 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
752 bfa_trc(fabric->fcs, event);
754 switch (event) {
755 case BFA_FCS_FABRIC_SM_STOPCOMP:
756 if (bfa_fcport_get_topology(bfa) == BFA_PORT_TOPOLOGY_LOOP) {
757 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_created);
758 } else {
759 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_cleanup);
760 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_LOGOUT);
762 break;
764 case BFA_FCS_FABRIC_SM_LINK_UP:
765 break;
767 case BFA_FCS_FABRIC_SM_LINK_DOWN:
768 if (bfa_fcport_get_topology(bfa) == BFA_PORT_TOPOLOGY_LOOP)
769 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_created);
770 else
771 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_cleanup);
772 break;
774 default:
775 bfa_sm_fault(fabric->fcs, event);
780 * Fabric is being stopped, cleanup without FLOGO
782 static void
783 bfa_fcs_fabric_sm_cleanup(struct bfa_fcs_fabric_s *fabric,
784 enum bfa_fcs_fabric_event event)
786 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
787 bfa_trc(fabric->fcs, event);
789 switch (event) {
790 case BFA_FCS_FABRIC_SM_STOPCOMP:
791 case BFA_FCS_FABRIC_SM_LOGOCOMP:
792 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_created);
793 bfa_wc_down(&(fabric->fcs)->wc);
794 break;
796 case BFA_FCS_FABRIC_SM_LINK_DOWN:
798 * Ignore - can get this event if we get notified about IOC down
799 * before the fabric completion callbk is done.
801 break;
803 default:
804 bfa_sm_fault(fabric->fcs, event);
809 * fcs_fabric_private fabric private functions
812 static void
813 bfa_fcs_fabric_init(struct bfa_fcs_fabric_s *fabric)
815 struct bfa_lport_cfg_s *port_cfg = &fabric->bport.port_cfg;
817 port_cfg->roles = BFA_LPORT_ROLE_FCP_IM;
818 port_cfg->nwwn = fabric->fcs->bfa->ioc.attr->nwwn;
819 port_cfg->pwwn = fabric->fcs->bfa->ioc.attr->pwwn;
823 * Port Symbolic Name Creation for base port.
825 void
826 bfa_fcs_fabric_psymb_init(struct bfa_fcs_fabric_s *fabric)
828 struct bfa_lport_cfg_s *port_cfg = &fabric->bport.port_cfg;
829 char model[BFA_ADAPTER_MODEL_NAME_LEN] = {0};
830 struct bfa_fcs_driver_info_s *driver_info = &fabric->fcs->driver_info;
832 bfa_ioc_get_adapter_model(&fabric->fcs->bfa->ioc, model);
834 /* Model name/number */
835 strncpy((char *)&port_cfg->sym_name, model,
836 BFA_FCS_PORT_SYMBNAME_MODEL_SZ);
837 strncat((char *)&port_cfg->sym_name, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
838 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
840 /* Driver Version */
841 strncat((char *)&port_cfg->sym_name, (char *)driver_info->version,
842 BFA_FCS_PORT_SYMBNAME_VERSION_SZ);
843 strncat((char *)&port_cfg->sym_name, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
844 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
846 /* Host machine name */
847 strncat((char *)&port_cfg->sym_name,
848 (char *)driver_info->host_machine_name,
849 BFA_FCS_PORT_SYMBNAME_MACHINENAME_SZ);
850 strncat((char *)&port_cfg->sym_name, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
851 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
854 * Host OS Info :
855 * If OS Patch Info is not there, do not truncate any bytes from the
856 * OS name string and instead copy the entire OS info string (64 bytes).
858 if (driver_info->host_os_patch[0] == '\0') {
859 strncat((char *)&port_cfg->sym_name,
860 (char *)driver_info->host_os_name,
861 BFA_FCS_OS_STR_LEN);
862 strncat((char *)&port_cfg->sym_name,
863 BFA_FCS_PORT_SYMBNAME_SEPARATOR,
864 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
865 } else {
866 strncat((char *)&port_cfg->sym_name,
867 (char *)driver_info->host_os_name,
868 BFA_FCS_PORT_SYMBNAME_OSINFO_SZ);
869 strncat((char *)&port_cfg->sym_name,
870 BFA_FCS_PORT_SYMBNAME_SEPARATOR,
871 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
873 /* Append host OS Patch Info */
874 strncat((char *)&port_cfg->sym_name,
875 (char *)driver_info->host_os_patch,
876 BFA_FCS_PORT_SYMBNAME_OSPATCH_SZ);
879 /* null terminate */
880 port_cfg->sym_name.symname[BFA_SYMNAME_MAXLEN - 1] = 0;
884 * Node Symbolic Name Creation for base port and all vports
886 void
887 bfa_fcs_fabric_nsymb_init(struct bfa_fcs_fabric_s *fabric)
889 struct bfa_lport_cfg_s *port_cfg = &fabric->bport.port_cfg;
890 char model[BFA_ADAPTER_MODEL_NAME_LEN] = {0};
891 struct bfa_fcs_driver_info_s *driver_info = &fabric->fcs->driver_info;
893 bfa_ioc_get_adapter_model(&fabric->fcs->bfa->ioc, model);
895 /* Model name/number */
896 strncpy((char *)&port_cfg->node_sym_name, model,
897 BFA_FCS_PORT_SYMBNAME_MODEL_SZ);
898 strncat((char *)&port_cfg->node_sym_name,
899 BFA_FCS_PORT_SYMBNAME_SEPARATOR,
900 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
902 /* Driver Version */
903 strncat((char *)&port_cfg->node_sym_name, (char *)driver_info->version,
904 BFA_FCS_PORT_SYMBNAME_VERSION_SZ);
905 strncat((char *)&port_cfg->node_sym_name,
906 BFA_FCS_PORT_SYMBNAME_SEPARATOR,
907 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
909 /* Host machine name */
910 strncat((char *)&port_cfg->node_sym_name,
911 (char *)driver_info->host_machine_name,
912 BFA_FCS_PORT_SYMBNAME_MACHINENAME_SZ);
913 strncat((char *)&port_cfg->node_sym_name,
914 BFA_FCS_PORT_SYMBNAME_SEPARATOR,
915 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
917 /* null terminate */
918 port_cfg->node_sym_name.symname[BFA_SYMNAME_MAXLEN - 1] = 0;
922 * bfa lps login completion callback
924 void
925 bfa_cb_lps_flogi_comp(void *bfad, void *uarg, bfa_status_t status)
927 struct bfa_fcs_fabric_s *fabric = uarg;
929 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
930 bfa_trc(fabric->fcs, status);
932 switch (status) {
933 case BFA_STATUS_OK:
934 fabric->stats.flogi_accepts++;
935 break;
937 case BFA_STATUS_INVALID_MAC:
938 /* Only for CNA */
939 fabric->stats.flogi_acc_err++;
940 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_RETRY_OP);
942 return;
944 case BFA_STATUS_EPROTOCOL:
945 switch (fabric->lps->ext_status) {
946 case BFA_EPROTO_BAD_ACCEPT:
947 fabric->stats.flogi_acc_err++;
948 break;
950 case BFA_EPROTO_UNKNOWN_RSP:
951 fabric->stats.flogi_unknown_rsp++;
952 break;
954 default:
955 break;
957 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_RETRY_OP);
959 return;
961 case BFA_STATUS_FABRIC_RJT:
962 fabric->stats.flogi_rejects++;
963 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_RETRY_OP);
964 return;
966 default:
967 fabric->stats.flogi_rsp_err++;
968 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_RETRY_OP);
969 return;
972 fabric->bb_credit = fabric->lps->pr_bbcred;
973 bfa_trc(fabric->fcs, fabric->bb_credit);
975 if (!(fabric->lps->brcd_switch))
976 fabric->fabric_name = fabric->lps->pr_nwwn;
979 * Check port type. It should be 1 = F-port.
981 if (fabric->lps->fport) {
982 fabric->bport.pid = fabric->lps->lp_pid;
983 fabric->is_npiv = fabric->lps->npiv_en;
984 fabric->is_auth = fabric->lps->auth_req;
985 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_CONT_OP);
986 } else {
988 * Nport-2-Nport direct attached
990 fabric->bport.port_topo.pn2n.rem_port_wwn =
991 fabric->lps->pr_pwwn;
992 fabric->fab_type = BFA_FCS_FABRIC_N2N;
993 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_NO_FABRIC);
996 bfa_trc(fabric->fcs, fabric->bport.pid);
997 bfa_trc(fabric->fcs, fabric->is_npiv);
998 bfa_trc(fabric->fcs, fabric->is_auth);
1001 * Allocate and send FLOGI.
1003 static void
1004 bfa_fcs_fabric_login(struct bfa_fcs_fabric_s *fabric)
1006 struct bfa_s *bfa = fabric->fcs->bfa;
1007 struct bfa_lport_cfg_s *pcfg = &fabric->bport.port_cfg;
1008 u8 alpa = 0;
1011 bfa_lps_flogi(fabric->lps, fabric, alpa, bfa_fcport_get_maxfrsize(bfa),
1012 pcfg->pwwn, pcfg->nwwn, fabric->auth_reqd);
1014 fabric->stats.flogi_sent++;
1017 static void
1018 bfa_fcs_fabric_notify_online(struct bfa_fcs_fabric_s *fabric)
1020 struct bfa_fcs_vport_s *vport;
1021 struct list_head *qe, *qen;
1023 bfa_trc(fabric->fcs, fabric->fabric_name);
1025 bfa_fcs_fabric_set_opertype(fabric);
1026 fabric->stats.fabric_onlines++;
1029 * notify online event to base and then virtual ports
1031 bfa_fcs_lport_online(&fabric->bport);
1033 list_for_each_safe(qe, qen, &fabric->vport_q) {
1034 vport = (struct bfa_fcs_vport_s *) qe;
1035 bfa_fcs_vport_online(vport);
1039 static void
1040 bfa_fcs_fabric_notify_offline(struct bfa_fcs_fabric_s *fabric)
1042 struct bfa_fcs_vport_s *vport;
1043 struct list_head *qe, *qen;
1045 bfa_trc(fabric->fcs, fabric->fabric_name);
1046 fabric->stats.fabric_offlines++;
1049 * notify offline event first to vports and then base port.
1051 list_for_each_safe(qe, qen, &fabric->vport_q) {
1052 vport = (struct bfa_fcs_vport_s *) qe;
1053 bfa_fcs_vport_offline(vport);
1056 bfa_fcs_lport_offline(&fabric->bport);
1058 fabric->fabric_name = 0;
1059 fabric->fabric_ip_addr[0] = 0;
1062 static void
1063 bfa_fcs_fabric_delay(void *cbarg)
1065 struct bfa_fcs_fabric_s *fabric = cbarg;
1067 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_DELAYED);
1071 * Stop all vports and wait for vport stop completions.
1073 static void
1074 bfa_fcs_fabric_stop(struct bfa_fcs_fabric_s *fabric)
1076 struct bfa_fcs_vport_s *vport;
1077 struct list_head *qe, *qen;
1079 bfa_wc_init(&fabric->stop_wc, bfa_fcs_fabric_stop_comp, fabric);
1081 list_for_each_safe(qe, qen, &fabric->vport_q) {
1082 vport = (struct bfa_fcs_vport_s *) qe;
1083 bfa_wc_up(&fabric->stop_wc);
1084 bfa_fcs_vport_fcs_stop(vport);
1087 bfa_wc_up(&fabric->stop_wc);
1088 bfa_fcs_lport_stop(&fabric->bport);
1089 bfa_wc_wait(&fabric->stop_wc);
1093 * Delete all vports and wait for vport delete completions.
1095 static void
1096 bfa_fcs_fabric_delete(struct bfa_fcs_fabric_s *fabric)
1098 struct bfa_fcs_vport_s *vport;
1099 struct list_head *qe, *qen;
1101 list_for_each_safe(qe, qen, &fabric->vport_q) {
1102 vport = (struct bfa_fcs_vport_s *) qe;
1103 bfa_fcs_vport_fcs_delete(vport);
1106 bfa_fcs_lport_delete(&fabric->bport);
1107 bfa_wc_wait(&fabric->wc);
1110 static void
1111 bfa_fcs_fabric_delete_comp(void *cbarg)
1113 struct bfa_fcs_fabric_s *fabric = cbarg;
1115 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_DELCOMP);
1118 static void
1119 bfa_fcs_fabric_stop_comp(void *cbarg)
1121 struct bfa_fcs_fabric_s *fabric = cbarg;
1123 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_STOPCOMP);
1127 * fcs_fabric_public fabric public functions
1131 * Attach time initialization.
1133 void
1134 bfa_fcs_fabric_attach(struct bfa_fcs_s *fcs)
1136 struct bfa_fcs_fabric_s *fabric;
1138 fabric = &fcs->fabric;
1139 memset(fabric, 0, sizeof(struct bfa_fcs_fabric_s));
1142 * Initialize base fabric.
1144 fabric->fcs = fcs;
1145 INIT_LIST_HEAD(&fabric->vport_q);
1146 INIT_LIST_HEAD(&fabric->vf_q);
1147 fabric->lps = bfa_lps_alloc(fcs->bfa);
1148 WARN_ON(!fabric->lps);
1151 * Initialize fabric delete completion handler. Fabric deletion is
1152 * complete when the last vport delete is complete.
1154 bfa_wc_init(&fabric->wc, bfa_fcs_fabric_delete_comp, fabric);
1155 bfa_wc_up(&fabric->wc); /* For the base port */
1157 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_uninit);
1158 bfa_fcs_lport_attach(&fabric->bport, fabric->fcs, FC_VF_ID_NULL, NULL);
1161 void
1162 bfa_fcs_fabric_modinit(struct bfa_fcs_s *fcs)
1164 bfa_sm_send_event(&fcs->fabric, BFA_FCS_FABRIC_SM_CREATE);
1165 bfa_trc(fcs, 0);
1169 * Module cleanup
1171 void
1172 bfa_fcs_fabric_modexit(struct bfa_fcs_s *fcs)
1174 struct bfa_fcs_fabric_s *fabric;
1176 bfa_trc(fcs, 0);
1179 * Cleanup base fabric.
1181 fabric = &fcs->fabric;
1182 bfa_lps_delete(fabric->lps);
1183 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_DELETE);
1187 * Fabric module stop -- stop FCS actions
1189 void
1190 bfa_fcs_fabric_modstop(struct bfa_fcs_s *fcs)
1192 struct bfa_fcs_fabric_s *fabric;
1194 bfa_trc(fcs, 0);
1195 fabric = &fcs->fabric;
1196 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_STOP);
1200 * Fabric module start -- kick starts FCS actions
1202 void
1203 bfa_fcs_fabric_modstart(struct bfa_fcs_s *fcs)
1205 struct bfa_fcs_fabric_s *fabric;
1207 bfa_trc(fcs, 0);
1208 fabric = &fcs->fabric;
1209 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_START);
1214 * Link up notification from BFA physical port module.
1216 void
1217 bfa_fcs_fabric_link_up(struct bfa_fcs_fabric_s *fabric)
1219 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
1220 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_LINK_UP);
1224 * Link down notification from BFA physical port module.
1226 void
1227 bfa_fcs_fabric_link_down(struct bfa_fcs_fabric_s *fabric)
1229 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
1230 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_LINK_DOWN);
1234 * A child vport is being created in the fabric.
1236 * Call from vport module at vport creation. A list of base port and vports
1237 * belonging to a fabric is maintained to propagate link events.
1239 * param[in] fabric - Fabric instance. This can be a base fabric or vf.
1240 * param[in] vport - Vport being created.
1242 * @return None (always succeeds)
1244 void
1245 bfa_fcs_fabric_addvport(struct bfa_fcs_fabric_s *fabric,
1246 struct bfa_fcs_vport_s *vport)
1249 * - add vport to fabric's vport_q
1251 bfa_trc(fabric->fcs, fabric->vf_id);
1253 list_add_tail(&vport->qe, &fabric->vport_q);
1254 fabric->num_vports++;
1255 bfa_wc_up(&fabric->wc);
1259 * A child vport is being deleted from fabric.
1261 * Vport is being deleted.
1263 void
1264 bfa_fcs_fabric_delvport(struct bfa_fcs_fabric_s *fabric,
1265 struct bfa_fcs_vport_s *vport)
1267 list_del(&vport->qe);
1268 fabric->num_vports--;
1269 bfa_wc_down(&fabric->wc);
1274 * Lookup for a vport within a fabric given its pwwn
1276 struct bfa_fcs_vport_s *
1277 bfa_fcs_fabric_vport_lookup(struct bfa_fcs_fabric_s *fabric, wwn_t pwwn)
1279 struct bfa_fcs_vport_s *vport;
1280 struct list_head *qe;
1282 list_for_each(qe, &fabric->vport_q) {
1283 vport = (struct bfa_fcs_vport_s *) qe;
1284 if (bfa_fcs_lport_get_pwwn(&vport->lport) == pwwn)
1285 return vport;
1288 return NULL;
1293 * Get OUI of the attached switch.
1295 * Note : Use of this function should be avoided as much as possible.
1296 * This function should be used only if there is any requirement
1297 * to check for FOS version below 6.3.
1298 * To check if the attached fabric is a brocade fabric, use
1299 * bfa_lps_is_brcd_fabric() which works for FOS versions 6.3
1300 * or above only.
1304 bfa_fcs_fabric_get_switch_oui(struct bfa_fcs_fabric_s *fabric)
1306 wwn_t fab_nwwn;
1307 u8 *tmp;
1308 u16 oui;
1310 fab_nwwn = fabric->lps->pr_nwwn;
1312 tmp = (u8 *)&fab_nwwn;
1313 oui = (tmp[3] << 8) | tmp[4];
1315 return oui;
1318 * Unsolicited frame receive handling.
1320 void
1321 bfa_fcs_fabric_uf_recv(struct bfa_fcs_fabric_s *fabric, struct fchs_s *fchs,
1322 u16 len)
1324 u32 pid = fchs->d_id;
1325 struct bfa_fcs_vport_s *vport;
1326 struct list_head *qe;
1327 struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
1328 struct fc_logi_s *flogi = (struct fc_logi_s *) els_cmd;
1330 bfa_trc(fabric->fcs, len);
1331 bfa_trc(fabric->fcs, pid);
1334 * Look for our own FLOGI frames being looped back. This means an
1335 * external loopback cable is in place. Our own FLOGI frames are
1336 * sometimes looped back when switch port gets temporarily bypassed.
1338 if ((pid == bfa_ntoh3b(FC_FABRIC_PORT)) &&
1339 (els_cmd->els_code == FC_ELS_FLOGI) &&
1340 (flogi->port_name == bfa_fcs_lport_get_pwwn(&fabric->bport))) {
1341 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_LOOPBACK);
1342 return;
1346 * FLOGI/EVFP exchanges should be consumed by base fabric.
1348 if (fchs->d_id == bfa_hton3b(FC_FABRIC_PORT)) {
1349 bfa_trc(fabric->fcs, pid);
1350 bfa_fcs_fabric_process_uf(fabric, fchs, len);
1351 return;
1354 if (fabric->bport.pid == pid) {
1356 * All authentication frames should be routed to auth
1358 bfa_trc(fabric->fcs, els_cmd->els_code);
1359 if (els_cmd->els_code == FC_ELS_AUTH) {
1360 bfa_trc(fabric->fcs, els_cmd->els_code);
1361 return;
1364 bfa_trc(fabric->fcs, *(u8 *) ((u8 *) fchs));
1365 bfa_fcs_lport_uf_recv(&fabric->bport, fchs, len);
1366 return;
1370 * look for a matching local port ID
1372 list_for_each(qe, &fabric->vport_q) {
1373 vport = (struct bfa_fcs_vport_s *) qe;
1374 if (vport->lport.pid == pid) {
1375 bfa_fcs_lport_uf_recv(&vport->lport, fchs, len);
1376 return;
1380 if (!bfa_fcs_fabric_is_switched(fabric))
1381 bfa_fcs_lport_uf_recv(&fabric->bport, fchs, len);
1383 bfa_trc(fabric->fcs, fchs->type);
1387 * Unsolicited frames to be processed by fabric.
1389 static void
1390 bfa_fcs_fabric_process_uf(struct bfa_fcs_fabric_s *fabric, struct fchs_s *fchs,
1391 u16 len)
1393 struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
1395 bfa_trc(fabric->fcs, els_cmd->els_code);
1397 switch (els_cmd->els_code) {
1398 case FC_ELS_FLOGI:
1399 bfa_fcs_fabric_process_flogi(fabric, fchs, len);
1400 break;
1402 default:
1404 * need to generate a LS_RJT
1406 break;
1411 * Process incoming FLOGI
1413 static void
1414 bfa_fcs_fabric_process_flogi(struct bfa_fcs_fabric_s *fabric,
1415 struct fchs_s *fchs, u16 len)
1417 struct fc_logi_s *flogi = (struct fc_logi_s *) (fchs + 1);
1418 struct bfa_fcs_lport_s *bport = &fabric->bport;
1420 bfa_trc(fabric->fcs, fchs->s_id);
1422 fabric->stats.flogi_rcvd++;
1424 * Check port type. It should be 0 = n-port.
1426 if (flogi->csp.port_type) {
1428 * @todo: may need to send a LS_RJT
1430 bfa_trc(fabric->fcs, flogi->port_name);
1431 fabric->stats.flogi_rejected++;
1432 return;
1435 fabric->bb_credit = be16_to_cpu(flogi->csp.bbcred);
1436 bport->port_topo.pn2n.rem_port_wwn = flogi->port_name;
1437 bport->port_topo.pn2n.reply_oxid = fchs->ox_id;
1440 * Send a Flogi Acc
1442 bfa_fcs_fabric_send_flogi_acc(fabric);
1443 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_NO_FABRIC);
1446 static void
1447 bfa_fcs_fabric_send_flogi_acc(struct bfa_fcs_fabric_s *fabric)
1449 struct bfa_lport_cfg_s *pcfg = &fabric->bport.port_cfg;
1450 struct bfa_fcs_lport_n2n_s *n2n_port = &fabric->bport.port_topo.pn2n;
1451 struct bfa_s *bfa = fabric->fcs->bfa;
1452 struct bfa_fcxp_s *fcxp;
1453 u16 reqlen;
1454 struct fchs_s fchs;
1456 fcxp = bfa_fcs_fcxp_alloc(fabric->fcs, BFA_FALSE);
1458 * Do not expect this failure -- expect remote node to retry
1460 if (!fcxp)
1461 return;
1463 reqlen = fc_flogi_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
1464 bfa_hton3b(FC_FABRIC_PORT),
1465 n2n_port->reply_oxid, pcfg->pwwn,
1466 pcfg->nwwn,
1467 bfa_fcport_get_maxfrsize(bfa),
1468 bfa_fcport_get_rx_bbcredit(bfa), 0);
1470 bfa_fcxp_send(fcxp, NULL, fabric->vf_id, fabric->lps->bfa_tag,
1471 BFA_FALSE, FC_CLASS_3,
1472 reqlen, &fchs, bfa_fcs_fabric_flogiacc_comp, fabric,
1473 FC_MAX_PDUSZ, 0);
1477 * Flogi Acc completion callback.
1479 static void
1480 bfa_fcs_fabric_flogiacc_comp(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
1481 bfa_status_t status, u32 rsp_len,
1482 u32 resid_len, struct fchs_s *rspfchs)
1484 struct bfa_fcs_fabric_s *fabric = cbarg;
1486 bfa_trc(fabric->fcs, status);
1491 * Send AEN notification
1493 static void
1494 bfa_fcs_fabric_aen_post(struct bfa_fcs_lport_s *port,
1495 enum bfa_port_aen_event event)
1497 struct bfad_s *bfad = (struct bfad_s *)port->fabric->fcs->bfad;
1498 struct bfa_aen_entry_s *aen_entry;
1500 bfad_get_aen_entry(bfad, aen_entry);
1501 if (!aen_entry)
1502 return;
1504 aen_entry->aen_data.port.pwwn = bfa_fcs_lport_get_pwwn(port);
1505 aen_entry->aen_data.port.fwwn = bfa_fcs_lport_get_fabric_name(port);
1507 /* Send the AEN notification */
1508 bfad_im_post_vendor_event(aen_entry, bfad, ++port->fcs->fcs_aen_seq,
1509 BFA_AEN_CAT_PORT, event);
1514 * @param[in] fabric - fabric
1515 * @param[in] wwn_t - new fabric name
1517 * @return - none
1519 void
1520 bfa_fcs_fabric_set_fabric_name(struct bfa_fcs_fabric_s *fabric,
1521 wwn_t fabric_name)
1523 struct bfad_s *bfad = (struct bfad_s *)fabric->fcs->bfad;
1524 char pwwn_ptr[BFA_STRING_32];
1525 char fwwn_ptr[BFA_STRING_32];
1527 bfa_trc(fabric->fcs, fabric_name);
1529 if (fabric->fabric_name == 0) {
1531 * With BRCD switches, we don't get Fabric Name in FLOGI.
1532 * Don't generate a fabric name change event in this case.
1534 fabric->fabric_name = fabric_name;
1535 } else {
1536 fabric->fabric_name = fabric_name;
1537 wwn2str(pwwn_ptr, bfa_fcs_lport_get_pwwn(&fabric->bport));
1538 wwn2str(fwwn_ptr,
1539 bfa_fcs_lport_get_fabric_name(&fabric->bport));
1540 BFA_LOG(KERN_WARNING, bfad, bfa_log_level,
1541 "Base port WWN = %s Fabric WWN = %s\n",
1542 pwwn_ptr, fwwn_ptr);
1543 bfa_fcs_fabric_aen_post(&fabric->bport,
1544 BFA_PORT_AEN_FABRIC_NAME_CHANGE);
1548 void
1549 bfa_cb_lps_flogo_comp(void *bfad, void *uarg)
1551 struct bfa_fcs_fabric_s *fabric = uarg;
1552 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_LOGOCOMP);
1556 * Returns FCS vf structure for a given vf_id.
1558 * param[in] vf_id - VF_ID
1560 * return
1561 * If lookup succeeds, retuns fcs vf object, otherwise returns NULL
1563 bfa_fcs_vf_t *
1564 bfa_fcs_vf_lookup(struct bfa_fcs_s *fcs, u16 vf_id)
1566 bfa_trc(fcs, vf_id);
1567 if (vf_id == FC_VF_ID_NULL)
1568 return &fcs->fabric;
1570 return NULL;
1574 * Return the list of local logical ports present in the given VF.
1576 * @param[in] vf vf for which logical ports are returned
1577 * @param[out] lpwwn returned logical port wwn list
1578 * @param[in,out] nlports in:size of lpwwn list;
1579 * out:total elements present,
1580 * actual elements returned is limited by the size
1582 void
1583 bfa_fcs_vf_get_ports(bfa_fcs_vf_t *vf, wwn_t lpwwn[], int *nlports)
1585 struct list_head *qe;
1586 struct bfa_fcs_vport_s *vport;
1587 int i = 0;
1588 struct bfa_fcs_s *fcs;
1590 if (vf == NULL || lpwwn == NULL || *nlports == 0)
1591 return;
1593 fcs = vf->fcs;
1595 bfa_trc(fcs, vf->vf_id);
1596 bfa_trc(fcs, (uint32_t) *nlports);
1598 lpwwn[i++] = vf->bport.port_cfg.pwwn;
1600 list_for_each(qe, &vf->vport_q) {
1601 if (i >= *nlports)
1602 break;
1604 vport = (struct bfa_fcs_vport_s *) qe;
1605 lpwwn[i++] = vport->lport.port_cfg.pwwn;
1608 bfa_trc(fcs, i);
1609 *nlports = i;
1613 * BFA FCS PPORT ( physical port)
1615 static void
1616 bfa_fcs_port_event_handler(void *cbarg, enum bfa_port_linkstate event)
1618 struct bfa_fcs_s *fcs = cbarg;
1620 bfa_trc(fcs, event);
1622 switch (event) {
1623 case BFA_PORT_LINKUP:
1624 bfa_fcs_fabric_link_up(&fcs->fabric);
1625 break;
1627 case BFA_PORT_LINKDOWN:
1628 bfa_fcs_fabric_link_down(&fcs->fabric);
1629 break;
1631 default:
1632 WARN_ON(1);
1636 void
1637 bfa_fcs_port_attach(struct bfa_fcs_s *fcs)
1639 bfa_fcport_event_register(fcs->bfa, bfa_fcs_port_event_handler, fcs);
1643 * BFA FCS UF ( Unsolicited Frames)
1647 * BFA callback for unsolicited frame receive handler.
1649 * @param[in] cbarg callback arg for receive handler
1650 * @param[in] uf unsolicited frame descriptor
1652 * @return None
1654 static void
1655 bfa_fcs_uf_recv(void *cbarg, struct bfa_uf_s *uf)
1657 struct bfa_fcs_s *fcs = (struct bfa_fcs_s *) cbarg;
1658 struct fchs_s *fchs = bfa_uf_get_frmbuf(uf);
1659 u16 len = bfa_uf_get_frmlen(uf);
1660 struct fc_vft_s *vft;
1661 struct bfa_fcs_fabric_s *fabric;
1664 * check for VFT header
1666 if (fchs->routing == FC_RTG_EXT_HDR &&
1667 fchs->cat_info == FC_CAT_VFT_HDR) {
1668 bfa_stats(fcs, uf.tagged);
1669 vft = bfa_uf_get_frmbuf(uf);
1670 if (fcs->port_vfid == vft->vf_id)
1671 fabric = &fcs->fabric;
1672 else
1673 fabric = bfa_fcs_vf_lookup(fcs, (u16) vft->vf_id);
1676 * drop frame if vfid is unknown
1678 if (!fabric) {
1679 WARN_ON(1);
1680 bfa_stats(fcs, uf.vfid_unknown);
1681 bfa_uf_free(uf);
1682 return;
1686 * skip vft header
1688 fchs = (struct fchs_s *) (vft + 1);
1689 len -= sizeof(struct fc_vft_s);
1691 bfa_trc(fcs, vft->vf_id);
1692 } else {
1693 bfa_stats(fcs, uf.untagged);
1694 fabric = &fcs->fabric;
1697 bfa_trc(fcs, ((u32 *) fchs)[0]);
1698 bfa_trc(fcs, ((u32 *) fchs)[1]);
1699 bfa_trc(fcs, ((u32 *) fchs)[2]);
1700 bfa_trc(fcs, ((u32 *) fchs)[3]);
1701 bfa_trc(fcs, ((u32 *) fchs)[4]);
1702 bfa_trc(fcs, ((u32 *) fchs)[5]);
1703 bfa_trc(fcs, len);
1705 bfa_fcs_fabric_uf_recv(fabric, fchs, len);
1706 bfa_uf_free(uf);
1709 void
1710 bfa_fcs_uf_attach(struct bfa_fcs_s *fcs)
1712 bfa_uf_recv_register(fcs->bfa, bfa_fcs_uf_recv, fcs);