s390/ptrace: get rid of long longs in psw_bits
[linux/fpc-iii.git] / drivers / scsi / bfa / bfa_fcs.c
blob0f19455951ec37a4d165e9b0bcc03b5c77f9db50
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 "bfad_drv.h"
23 #include "bfad_im.h"
24 #include "bfa_fcs.h"
25 #include "bfa_fcbuild.h"
27 BFA_TRC_FILE(FCS, FCS);
30 * FCS sub-modules
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 },
48 * fcs_api BFA FCS API
51 static void
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);
63 * fcs_api BFA FCS API
67 * fcs attach -- called once to initialize data structures at driver attach time
69 void
70 bfa_fcs_attach(struct bfa_fcs_s *fcs, struct bfa_s *bfa, struct bfad_s *bfad,
71 bfa_boolean_t min_cfg)
73 int i;
74 struct bfa_fcs_mod_s *mod;
76 fcs->bfa = bfa;
77 fcs->bfad = bfad;
78 fcs->min_cfg = min_cfg;
79 fcs->num_rport_logins = 0;
81 bfa->fcs = BFA_TRUE;
82 fcbuild_init();
84 for (i = 0; i < ARRAY_SIZE(fcs_modules); i++) {
85 mod = &fcs_modules[i];
86 if (mod->attach)
87 mod->attach(fcs);
92 * fcs initialization, called once after bfa initialization is complete
94 void
95 bfa_fcs_init(struct bfa_fcs_s *fcs)
97 int i;
98 struct bfa_fcs_mod_s *mod;
100 for (i = 0; i < ARRAY_SIZE(fcs_modules); i++) {
101 mod = &fcs_modules[i];
102 if (mod->modinit)
103 mod->modinit(fcs);
108 * FCS update cfg - reset the pwwn/nwwn of fabric base logical port
109 * with values learned during bfa_init firmware GETATTR REQ.
111 void
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.
125 void
126 bfa_fcs_stop(struct bfa_fcs_s *fcs)
128 bfa_wc_init(&fcs->wc, bfa_fcs_exit_comp, fcs);
129 bfa_wc_up(&fcs->wc);
130 bfa_fcs_fabric_modstop(fcs);
131 bfa_wc_wait(&fcs->wc);
135 * fcs pbc vport initialization
137 void
138 bfa_fcs_pbc_vport_init(struct bfa_fcs_s *fcs)
140 int i, npbc_vports;
141 struct bfi_pbc_vport_s pbc_vports[BFI_PBC_MAX_VPORTS];
143 /* Initialize pbc vports */
144 if (!fcs->min_cfg) {
145 npbc_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]);
153 * brief
154 * FCS driver details initialization.
156 * param[in] fcs FCS instance
157 * param[in] driver_info Driver Details
159 * return None
161 void
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);
173 * brief
174 * FCS instance cleanup and exit.
176 * param[in] fcs FCS instance
177 * return None
179 void
180 bfa_fcs_exit(struct bfa_fcs_s *fcs)
182 struct bfa_fcs_mod_s *mod;
183 int nmods, i;
185 bfa_wc_init(&fcs->wc, bfa_fcs_exit_comp, fcs);
187 nmods = ARRAY_SIZE(fcs_modules);
189 for (i = 0; i < nmods; i++) {
191 mod = &fcs_modules[i];
192 if (mod->modexit) {
193 bfa_wc_up(&fcs->wc);
194 mod->modexit(fcs);
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; \
214 else \
215 (__fabric)->oper_type = BFA_PORT_TYPE_P2P; \
216 } else \
217 (__fabric)->oper_type = BFA_PORT_TYPE_NLPORT; \
218 } while (0)
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,
239 bfa_status_t status,
240 u32 rsp_len,
241 u32 resid_len,
242 struct fchs_s *rspfchs);
244 static void bfa_fcs_fabric_sm_uninit(struct bfa_fcs_fabric_s *fabric,
245 enum bfa_fcs_fabric_event event);
246 static void bfa_fcs_fabric_sm_created(struct bfa_fcs_fabric_s *fabric,
247 enum bfa_fcs_fabric_event event);
248 static void bfa_fcs_fabric_sm_linkdown(struct bfa_fcs_fabric_s *fabric,
249 enum bfa_fcs_fabric_event event);
250 static void bfa_fcs_fabric_sm_flogi(struct bfa_fcs_fabric_s *fabric,
251 enum bfa_fcs_fabric_event event);
252 static void bfa_fcs_fabric_sm_flogi_retry(struct bfa_fcs_fabric_s *fabric,
253 enum bfa_fcs_fabric_event event);
254 static void bfa_fcs_fabric_sm_auth(struct bfa_fcs_fabric_s *fabric,
255 enum bfa_fcs_fabric_event event);
256 static void bfa_fcs_fabric_sm_nofabric(struct bfa_fcs_fabric_s *fabric,
257 enum bfa_fcs_fabric_event event);
258 static void bfa_fcs_fabric_sm_evfp(struct bfa_fcs_fabric_s *fabric,
259 enum bfa_fcs_fabric_event event);
260 static void bfa_fcs_fabric_sm_evfp_done(struct bfa_fcs_fabric_s *fabric,
261 enum bfa_fcs_fabric_event event);
262 static void bfa_fcs_fabric_sm_isolated(struct bfa_fcs_fabric_s *fabric,
263 enum bfa_fcs_fabric_event event);
264 static void bfa_fcs_fabric_sm_deleting(struct bfa_fcs_fabric_s *fabric,
265 enum bfa_fcs_fabric_event event);
266 static void bfa_fcs_fabric_sm_stopping(struct bfa_fcs_fabric_s *fabric,
267 enum bfa_fcs_fabric_event event);
268 static void bfa_fcs_fabric_sm_cleanup(struct bfa_fcs_fabric_s *fabric,
269 enum bfa_fcs_fabric_event event);
271 * Beginning state before fabric creation.
273 static void
274 bfa_fcs_fabric_sm_uninit(struct bfa_fcs_fabric_s *fabric,
275 enum bfa_fcs_fabric_event event)
277 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
278 bfa_trc(fabric->fcs, event);
280 switch (event) {
281 case BFA_FCS_FABRIC_SM_CREATE:
282 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_created);
283 bfa_fcs_fabric_init(fabric);
284 bfa_fcs_lport_init(&fabric->bport, &fabric->bport.port_cfg);
285 break;
287 case BFA_FCS_FABRIC_SM_LINK_UP:
288 case BFA_FCS_FABRIC_SM_LINK_DOWN:
289 break;
291 default:
292 bfa_sm_fault(fabric->fcs, event);
297 * Beginning state before fabric creation.
299 static void
300 bfa_fcs_fabric_sm_created(struct bfa_fcs_fabric_s *fabric,
301 enum bfa_fcs_fabric_event event)
303 struct bfa_s *bfa = fabric->fcs->bfa;
305 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
306 bfa_trc(fabric->fcs, event);
308 switch (event) {
309 case BFA_FCS_FABRIC_SM_START:
310 if (!bfa_fcport_is_linkup(fabric->fcs->bfa)) {
311 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
312 break;
314 if (bfa_fcport_get_topology(bfa) ==
315 BFA_PORT_TOPOLOGY_LOOP) {
316 fabric->fab_type = BFA_FCS_FABRIC_LOOP;
317 fabric->bport.pid = bfa_fcport_get_myalpa(bfa);
318 fabric->bport.pid = bfa_hton3b(fabric->bport.pid);
319 bfa_sm_set_state(fabric,
320 bfa_fcs_fabric_sm_online);
321 bfa_fcs_fabric_set_opertype(fabric);
322 bfa_fcs_lport_online(&fabric->bport);
323 } else {
324 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_flogi);
325 bfa_fcs_fabric_login(fabric);
327 break;
329 case BFA_FCS_FABRIC_SM_LINK_UP:
330 case BFA_FCS_FABRIC_SM_LINK_DOWN:
331 break;
333 case BFA_FCS_FABRIC_SM_DELETE:
334 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
335 bfa_fcs_fabric_delete(fabric);
336 break;
338 default:
339 bfa_sm_fault(fabric->fcs, event);
344 * Link is down, awaiting LINK UP event from port. This is also the
345 * first state at fabric creation.
347 static void
348 bfa_fcs_fabric_sm_linkdown(struct bfa_fcs_fabric_s *fabric,
349 enum bfa_fcs_fabric_event event)
351 struct bfa_s *bfa = fabric->fcs->bfa;
353 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
354 bfa_trc(fabric->fcs, event);
356 switch (event) {
357 case BFA_FCS_FABRIC_SM_LINK_UP:
358 if (bfa_fcport_get_topology(bfa) != BFA_PORT_TOPOLOGY_LOOP) {
359 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_flogi);
360 bfa_fcs_fabric_login(fabric);
361 break;
363 fabric->fab_type = BFA_FCS_FABRIC_LOOP;
364 fabric->bport.pid = bfa_fcport_get_myalpa(bfa);
365 fabric->bport.pid = bfa_hton3b(fabric->bport.pid);
366 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_online);
367 bfa_fcs_fabric_set_opertype(fabric);
368 bfa_fcs_lport_online(&fabric->bport);
369 break;
371 case BFA_FCS_FABRIC_SM_RETRY_OP:
372 case BFA_FCS_FABRIC_SM_LOOPBACK:
373 break;
375 case BFA_FCS_FABRIC_SM_DELETE:
376 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
377 bfa_fcs_fabric_delete(fabric);
378 break;
380 case BFA_FCS_FABRIC_SM_STOP:
381 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_cleanup);
382 bfa_fcs_fabric_stop(fabric);
383 break;
385 default:
386 bfa_sm_fault(fabric->fcs, event);
391 * FLOGI is in progress, awaiting FLOGI reply.
393 static void
394 bfa_fcs_fabric_sm_flogi(struct bfa_fcs_fabric_s *fabric,
395 enum bfa_fcs_fabric_event event)
397 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
398 bfa_trc(fabric->fcs, event);
400 switch (event) {
401 case BFA_FCS_FABRIC_SM_CONT_OP:
403 bfa_fcport_set_tx_bbcredit(fabric->fcs->bfa,
404 fabric->bb_credit);
405 fabric->fab_type = BFA_FCS_FABRIC_SWITCHED;
407 if (fabric->auth_reqd && fabric->is_auth) {
408 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_auth);
409 bfa_trc(fabric->fcs, event);
410 } else {
411 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_online);
412 bfa_fcs_fabric_notify_online(fabric);
414 break;
416 case BFA_FCS_FABRIC_SM_RETRY_OP:
417 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_flogi_retry);
418 bfa_timer_start(fabric->fcs->bfa, &fabric->delay_timer,
419 bfa_fcs_fabric_delay, fabric,
420 BFA_FCS_FABRIC_RETRY_DELAY);
421 break;
423 case BFA_FCS_FABRIC_SM_LOOPBACK:
424 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_loopback);
425 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
426 bfa_fcs_fabric_set_opertype(fabric);
427 break;
429 case BFA_FCS_FABRIC_SM_NO_FABRIC:
430 fabric->fab_type = BFA_FCS_FABRIC_N2N;
431 bfa_fcport_set_tx_bbcredit(fabric->fcs->bfa,
432 fabric->bb_credit);
433 bfa_fcs_fabric_notify_online(fabric);
434 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_nofabric);
435 break;
437 case BFA_FCS_FABRIC_SM_LINK_DOWN:
438 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
439 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
440 break;
442 case BFA_FCS_FABRIC_SM_DELETE:
443 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
444 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
445 bfa_fcs_fabric_delete(fabric);
446 break;
448 default:
449 bfa_sm_fault(fabric->fcs, event);
454 static void
455 bfa_fcs_fabric_sm_flogi_retry(struct bfa_fcs_fabric_s *fabric,
456 enum bfa_fcs_fabric_event event)
458 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
459 bfa_trc(fabric->fcs, event);
461 switch (event) {
462 case BFA_FCS_FABRIC_SM_DELAYED:
463 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_flogi);
464 bfa_fcs_fabric_login(fabric);
465 break;
467 case BFA_FCS_FABRIC_SM_LINK_DOWN:
468 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
469 bfa_timer_stop(&fabric->delay_timer);
470 break;
472 case BFA_FCS_FABRIC_SM_DELETE:
473 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
474 bfa_timer_stop(&fabric->delay_timer);
475 bfa_fcs_fabric_delete(fabric);
476 break;
478 default:
479 bfa_sm_fault(fabric->fcs, event);
484 * Authentication is in progress, awaiting authentication results.
486 static void
487 bfa_fcs_fabric_sm_auth(struct bfa_fcs_fabric_s *fabric,
488 enum bfa_fcs_fabric_event event)
490 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
491 bfa_trc(fabric->fcs, event);
493 switch (event) {
494 case BFA_FCS_FABRIC_SM_AUTH_FAILED:
495 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_auth_failed);
496 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
497 break;
499 case BFA_FCS_FABRIC_SM_AUTH_SUCCESS:
500 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_online);
501 bfa_fcs_fabric_notify_online(fabric);
502 break;
504 case BFA_FCS_FABRIC_SM_PERF_EVFP:
505 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_evfp);
506 break;
508 case BFA_FCS_FABRIC_SM_LINK_DOWN:
509 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
510 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
511 break;
513 case BFA_FCS_FABRIC_SM_DELETE:
514 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
515 bfa_fcs_fabric_delete(fabric);
516 break;
518 default:
519 bfa_sm_fault(fabric->fcs, event);
524 * Authentication failed
526 void
527 bfa_fcs_fabric_sm_auth_failed(struct bfa_fcs_fabric_s *fabric,
528 enum bfa_fcs_fabric_event event)
530 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
531 bfa_trc(fabric->fcs, event);
533 switch (event) {
534 case BFA_FCS_FABRIC_SM_LINK_DOWN:
535 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
536 bfa_fcs_fabric_notify_offline(fabric);
537 break;
539 case BFA_FCS_FABRIC_SM_DELETE:
540 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
541 bfa_fcs_fabric_delete(fabric);
542 break;
544 default:
545 bfa_sm_fault(fabric->fcs, event);
550 * Port is in loopback mode.
552 void
553 bfa_fcs_fabric_sm_loopback(struct bfa_fcs_fabric_s *fabric,
554 enum bfa_fcs_fabric_event event)
556 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
557 bfa_trc(fabric->fcs, event);
559 switch (event) {
560 case BFA_FCS_FABRIC_SM_LINK_DOWN:
561 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
562 bfa_fcs_fabric_notify_offline(fabric);
563 break;
565 case BFA_FCS_FABRIC_SM_DELETE:
566 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
567 bfa_fcs_fabric_delete(fabric);
568 break;
570 default:
571 bfa_sm_fault(fabric->fcs, event);
576 * There is no attached fabric - private loop or NPort-to-NPort topology.
578 static void
579 bfa_fcs_fabric_sm_nofabric(struct bfa_fcs_fabric_s *fabric,
580 enum bfa_fcs_fabric_event event)
582 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
583 bfa_trc(fabric->fcs, event);
585 switch (event) {
586 case BFA_FCS_FABRIC_SM_LINK_DOWN:
587 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
588 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
589 bfa_fcs_fabric_notify_offline(fabric);
590 break;
592 case BFA_FCS_FABRIC_SM_DELETE:
593 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
594 bfa_fcs_fabric_delete(fabric);
595 break;
597 case BFA_FCS_FABRIC_SM_NO_FABRIC:
598 bfa_trc(fabric->fcs, fabric->bb_credit);
599 bfa_fcport_set_tx_bbcredit(fabric->fcs->bfa,
600 fabric->bb_credit);
601 break;
603 case BFA_FCS_FABRIC_SM_RETRY_OP:
604 break;
606 default:
607 bfa_sm_fault(fabric->fcs, event);
612 * Fabric is online - normal operating state.
614 void
615 bfa_fcs_fabric_sm_online(struct bfa_fcs_fabric_s *fabric,
616 enum bfa_fcs_fabric_event event)
618 struct bfa_s *bfa = fabric->fcs->bfa;
620 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
621 bfa_trc(fabric->fcs, event);
623 switch (event) {
624 case BFA_FCS_FABRIC_SM_LINK_DOWN:
625 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
626 if (bfa_fcport_get_topology(bfa) == BFA_PORT_TOPOLOGY_LOOP) {
627 bfa_fcs_lport_offline(&fabric->bport);
628 } else {
629 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
630 bfa_fcs_fabric_notify_offline(fabric);
632 break;
634 case BFA_FCS_FABRIC_SM_DELETE:
635 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
636 bfa_fcs_fabric_delete(fabric);
637 break;
639 case BFA_FCS_FABRIC_SM_STOP:
640 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_stopping);
641 bfa_fcs_fabric_stop(fabric);
642 break;
644 case BFA_FCS_FABRIC_SM_AUTH_FAILED:
645 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_auth_failed);
646 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
647 break;
649 case BFA_FCS_FABRIC_SM_AUTH_SUCCESS:
650 break;
652 default:
653 bfa_sm_fault(fabric->fcs, event);
658 * Exchanging virtual fabric parameters.
660 static void
661 bfa_fcs_fabric_sm_evfp(struct bfa_fcs_fabric_s *fabric,
662 enum bfa_fcs_fabric_event event)
664 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
665 bfa_trc(fabric->fcs, event);
667 switch (event) {
668 case BFA_FCS_FABRIC_SM_CONT_OP:
669 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_evfp_done);
670 break;
672 case BFA_FCS_FABRIC_SM_ISOLATE:
673 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_isolated);
674 break;
676 default:
677 bfa_sm_fault(fabric->fcs, event);
682 * EVFP exchange complete and VFT tagging is enabled.
684 static void
685 bfa_fcs_fabric_sm_evfp_done(struct bfa_fcs_fabric_s *fabric,
686 enum bfa_fcs_fabric_event event)
688 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
689 bfa_trc(fabric->fcs, event);
693 * Port is isolated after EVFP exchange due to VF_ID mismatch (N and F).
695 static void
696 bfa_fcs_fabric_sm_isolated(struct bfa_fcs_fabric_s *fabric,
697 enum bfa_fcs_fabric_event event)
699 struct bfad_s *bfad = (struct bfad_s *)fabric->fcs->bfad;
700 char pwwn_ptr[BFA_STRING_32];
702 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
703 bfa_trc(fabric->fcs, event);
704 wwn2str(pwwn_ptr, fabric->bport.port_cfg.pwwn);
706 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
707 "Port is isolated due to VF_ID mismatch. "
708 "PWWN: %s Port VF_ID: %04x switch port VF_ID: %04x.",
709 pwwn_ptr, fabric->fcs->port_vfid,
710 fabric->event_arg.swp_vfid);
714 * Fabric is being deleted, awaiting vport delete completions.
716 static void
717 bfa_fcs_fabric_sm_deleting(struct bfa_fcs_fabric_s *fabric,
718 enum bfa_fcs_fabric_event event)
720 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
721 bfa_trc(fabric->fcs, event);
723 switch (event) {
724 case BFA_FCS_FABRIC_SM_DELCOMP:
725 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_uninit);
726 bfa_wc_down(&fabric->fcs->wc);
727 break;
729 case BFA_FCS_FABRIC_SM_LINK_UP:
730 break;
732 case BFA_FCS_FABRIC_SM_LINK_DOWN:
733 bfa_fcs_fabric_notify_offline(fabric);
734 break;
736 default:
737 bfa_sm_fault(fabric->fcs, event);
742 * Fabric is being stopped, awaiting vport stop completions.
744 static void
745 bfa_fcs_fabric_sm_stopping(struct bfa_fcs_fabric_s *fabric,
746 enum bfa_fcs_fabric_event event)
748 struct bfa_s *bfa = fabric->fcs->bfa;
750 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
751 bfa_trc(fabric->fcs, event);
753 switch (event) {
754 case BFA_FCS_FABRIC_SM_STOPCOMP:
755 if (bfa_fcport_get_topology(bfa) == BFA_PORT_TOPOLOGY_LOOP) {
756 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_created);
757 } else {
758 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_cleanup);
759 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_LOGOUT);
761 break;
763 case BFA_FCS_FABRIC_SM_LINK_UP:
764 break;
766 case BFA_FCS_FABRIC_SM_LINK_DOWN:
767 if (bfa_fcport_get_topology(bfa) == BFA_PORT_TOPOLOGY_LOOP)
768 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_created);
769 else
770 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_cleanup);
771 break;
773 default:
774 bfa_sm_fault(fabric->fcs, event);
779 * Fabric is being stopped, cleanup without FLOGO
781 static void
782 bfa_fcs_fabric_sm_cleanup(struct bfa_fcs_fabric_s *fabric,
783 enum bfa_fcs_fabric_event event)
785 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
786 bfa_trc(fabric->fcs, event);
788 switch (event) {
789 case BFA_FCS_FABRIC_SM_STOPCOMP:
790 case BFA_FCS_FABRIC_SM_LOGOCOMP:
791 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_created);
792 bfa_wc_down(&(fabric->fcs)->wc);
793 break;
795 case BFA_FCS_FABRIC_SM_LINK_DOWN:
797 * Ignore - can get this event if we get notified about IOC down
798 * before the fabric completion callbk is done.
800 break;
802 default:
803 bfa_sm_fault(fabric->fcs, event);
808 * fcs_fabric_private fabric private functions
811 static void
812 bfa_fcs_fabric_init(struct bfa_fcs_fabric_s *fabric)
814 struct bfa_lport_cfg_s *port_cfg = &fabric->bport.port_cfg;
816 port_cfg->roles = BFA_LPORT_ROLE_FCP_IM;
817 port_cfg->nwwn = fabric->fcs->bfa->ioc.attr->nwwn;
818 port_cfg->pwwn = fabric->fcs->bfa->ioc.attr->pwwn;
822 * Port Symbolic Name Creation for base port.
824 void
825 bfa_fcs_fabric_psymb_init(struct bfa_fcs_fabric_s *fabric)
827 struct bfa_lport_cfg_s *port_cfg = &fabric->bport.port_cfg;
828 char model[BFA_ADAPTER_MODEL_NAME_LEN] = {0};
829 struct bfa_fcs_driver_info_s *driver_info = &fabric->fcs->driver_info;
831 bfa_ioc_get_adapter_model(&fabric->fcs->bfa->ioc, model);
833 /* Model name/number */
834 strncpy((char *)&port_cfg->sym_name, model,
835 BFA_FCS_PORT_SYMBNAME_MODEL_SZ);
836 strncat((char *)&port_cfg->sym_name, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
837 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
839 /* Driver Version */
840 strncat((char *)&port_cfg->sym_name, (char *)driver_info->version,
841 BFA_FCS_PORT_SYMBNAME_VERSION_SZ);
842 strncat((char *)&port_cfg->sym_name, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
843 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
845 /* Host machine name */
846 strncat((char *)&port_cfg->sym_name,
847 (char *)driver_info->host_machine_name,
848 BFA_FCS_PORT_SYMBNAME_MACHINENAME_SZ);
849 strncat((char *)&port_cfg->sym_name, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
850 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
853 * Host OS Info :
854 * If OS Patch Info is not there, do not truncate any bytes from the
855 * OS name string and instead copy the entire OS info string (64 bytes).
857 if (driver_info->host_os_patch[0] == '\0') {
858 strncat((char *)&port_cfg->sym_name,
859 (char *)driver_info->host_os_name,
860 BFA_FCS_OS_STR_LEN);
861 strncat((char *)&port_cfg->sym_name,
862 BFA_FCS_PORT_SYMBNAME_SEPARATOR,
863 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
864 } else {
865 strncat((char *)&port_cfg->sym_name,
866 (char *)driver_info->host_os_name,
867 BFA_FCS_PORT_SYMBNAME_OSINFO_SZ);
868 strncat((char *)&port_cfg->sym_name,
869 BFA_FCS_PORT_SYMBNAME_SEPARATOR,
870 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
872 /* Append host OS Patch Info */
873 strncat((char *)&port_cfg->sym_name,
874 (char *)driver_info->host_os_patch,
875 BFA_FCS_PORT_SYMBNAME_OSPATCH_SZ);
878 /* null terminate */
879 port_cfg->sym_name.symname[BFA_SYMNAME_MAXLEN - 1] = 0;
883 * Node Symbolic Name Creation for base port and all vports
885 void
886 bfa_fcs_fabric_nsymb_init(struct bfa_fcs_fabric_s *fabric)
888 struct bfa_lport_cfg_s *port_cfg = &fabric->bport.port_cfg;
889 char model[BFA_ADAPTER_MODEL_NAME_LEN] = {0};
890 struct bfa_fcs_driver_info_s *driver_info = &fabric->fcs->driver_info;
892 bfa_ioc_get_adapter_model(&fabric->fcs->bfa->ioc, model);
894 /* Model name/number */
895 strncpy((char *)&port_cfg->node_sym_name, model,
896 BFA_FCS_PORT_SYMBNAME_MODEL_SZ);
897 strncat((char *)&port_cfg->node_sym_name,
898 BFA_FCS_PORT_SYMBNAME_SEPARATOR,
899 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
901 /* Driver Version */
902 strncat((char *)&port_cfg->node_sym_name, (char *)driver_info->version,
903 BFA_FCS_PORT_SYMBNAME_VERSION_SZ);
904 strncat((char *)&port_cfg->node_sym_name,
905 BFA_FCS_PORT_SYMBNAME_SEPARATOR,
906 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
908 /* Host machine name */
909 strncat((char *)&port_cfg->node_sym_name,
910 (char *)driver_info->host_machine_name,
911 BFA_FCS_PORT_SYMBNAME_MACHINENAME_SZ);
912 strncat((char *)&port_cfg->node_sym_name,
913 BFA_FCS_PORT_SYMBNAME_SEPARATOR,
914 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
916 /* null terminate */
917 port_cfg->node_sym_name.symname[BFA_SYMNAME_MAXLEN - 1] = 0;
921 * bfa lps login completion callback
923 void
924 bfa_cb_lps_flogi_comp(void *bfad, void *uarg, bfa_status_t status)
926 struct bfa_fcs_fabric_s *fabric = uarg;
928 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
929 bfa_trc(fabric->fcs, status);
931 switch (status) {
932 case BFA_STATUS_OK:
933 fabric->stats.flogi_accepts++;
934 break;
936 case BFA_STATUS_INVALID_MAC:
937 /* Only for CNA */
938 fabric->stats.flogi_acc_err++;
939 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_RETRY_OP);
941 return;
943 case BFA_STATUS_EPROTOCOL:
944 switch (fabric->lps->ext_status) {
945 case BFA_EPROTO_BAD_ACCEPT:
946 fabric->stats.flogi_acc_err++;
947 break;
949 case BFA_EPROTO_UNKNOWN_RSP:
950 fabric->stats.flogi_unknown_rsp++;
951 break;
953 default:
954 break;
956 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_RETRY_OP);
958 return;
960 case BFA_STATUS_FABRIC_RJT:
961 fabric->stats.flogi_rejects++;
962 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_RETRY_OP);
963 return;
965 default:
966 fabric->stats.flogi_rsp_err++;
967 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_RETRY_OP);
968 return;
971 fabric->bb_credit = fabric->lps->pr_bbcred;
972 bfa_trc(fabric->fcs, fabric->bb_credit);
974 if (!(fabric->lps->brcd_switch))
975 fabric->fabric_name = fabric->lps->pr_nwwn;
978 * Check port type. It should be 1 = F-port.
980 if (fabric->lps->fport) {
981 fabric->bport.pid = fabric->lps->lp_pid;
982 fabric->is_npiv = fabric->lps->npiv_en;
983 fabric->is_auth = fabric->lps->auth_req;
984 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_CONT_OP);
985 } else {
987 * Nport-2-Nport direct attached
989 fabric->bport.port_topo.pn2n.rem_port_wwn =
990 fabric->lps->pr_pwwn;
991 fabric->fab_type = BFA_FCS_FABRIC_N2N;
992 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_NO_FABRIC);
995 bfa_trc(fabric->fcs, fabric->bport.pid);
996 bfa_trc(fabric->fcs, fabric->is_npiv);
997 bfa_trc(fabric->fcs, fabric->is_auth);
1000 * Allocate and send FLOGI.
1002 static void
1003 bfa_fcs_fabric_login(struct bfa_fcs_fabric_s *fabric)
1005 struct bfa_s *bfa = fabric->fcs->bfa;
1006 struct bfa_lport_cfg_s *pcfg = &fabric->bport.port_cfg;
1007 u8 alpa = 0;
1010 bfa_lps_flogi(fabric->lps, fabric, alpa, bfa_fcport_get_maxfrsize(bfa),
1011 pcfg->pwwn, pcfg->nwwn, fabric->auth_reqd);
1013 fabric->stats.flogi_sent++;
1016 static void
1017 bfa_fcs_fabric_notify_online(struct bfa_fcs_fabric_s *fabric)
1019 struct bfa_fcs_vport_s *vport;
1020 struct list_head *qe, *qen;
1022 bfa_trc(fabric->fcs, fabric->fabric_name);
1024 bfa_fcs_fabric_set_opertype(fabric);
1025 fabric->stats.fabric_onlines++;
1028 * notify online event to base and then virtual ports
1030 bfa_fcs_lport_online(&fabric->bport);
1032 list_for_each_safe(qe, qen, &fabric->vport_q) {
1033 vport = (struct bfa_fcs_vport_s *) qe;
1034 bfa_fcs_vport_online(vport);
1038 static void
1039 bfa_fcs_fabric_notify_offline(struct bfa_fcs_fabric_s *fabric)
1041 struct bfa_fcs_vport_s *vport;
1042 struct list_head *qe, *qen;
1044 bfa_trc(fabric->fcs, fabric->fabric_name);
1045 fabric->stats.fabric_offlines++;
1048 * notify offline event first to vports and then base port.
1050 list_for_each_safe(qe, qen, &fabric->vport_q) {
1051 vport = (struct bfa_fcs_vport_s *) qe;
1052 bfa_fcs_vport_offline(vport);
1055 bfa_fcs_lport_offline(&fabric->bport);
1057 fabric->fabric_name = 0;
1058 fabric->fabric_ip_addr[0] = 0;
1061 static void
1062 bfa_fcs_fabric_delay(void *cbarg)
1064 struct bfa_fcs_fabric_s *fabric = cbarg;
1066 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_DELAYED);
1070 * Stop all vports and wait for vport stop completions.
1072 static void
1073 bfa_fcs_fabric_stop(struct bfa_fcs_fabric_s *fabric)
1075 struct bfa_fcs_vport_s *vport;
1076 struct list_head *qe, *qen;
1078 bfa_wc_init(&fabric->stop_wc, bfa_fcs_fabric_stop_comp, fabric);
1080 list_for_each_safe(qe, qen, &fabric->vport_q) {
1081 vport = (struct bfa_fcs_vport_s *) qe;
1082 bfa_wc_up(&fabric->stop_wc);
1083 bfa_fcs_vport_fcs_stop(vport);
1086 bfa_wc_up(&fabric->stop_wc);
1087 bfa_fcs_lport_stop(&fabric->bport);
1088 bfa_wc_wait(&fabric->stop_wc);
1092 * Delete all vports and wait for vport delete completions.
1094 static void
1095 bfa_fcs_fabric_delete(struct bfa_fcs_fabric_s *fabric)
1097 struct bfa_fcs_vport_s *vport;
1098 struct list_head *qe, *qen;
1100 list_for_each_safe(qe, qen, &fabric->vport_q) {
1101 vport = (struct bfa_fcs_vport_s *) qe;
1102 bfa_fcs_vport_fcs_delete(vport);
1105 bfa_fcs_lport_delete(&fabric->bport);
1106 bfa_wc_wait(&fabric->wc);
1109 static void
1110 bfa_fcs_fabric_delete_comp(void *cbarg)
1112 struct bfa_fcs_fabric_s *fabric = cbarg;
1114 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_DELCOMP);
1117 static void
1118 bfa_fcs_fabric_stop_comp(void *cbarg)
1120 struct bfa_fcs_fabric_s *fabric = cbarg;
1122 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_STOPCOMP);
1126 * fcs_fabric_public fabric public functions
1130 * Attach time initialization.
1132 void
1133 bfa_fcs_fabric_attach(struct bfa_fcs_s *fcs)
1135 struct bfa_fcs_fabric_s *fabric;
1137 fabric = &fcs->fabric;
1138 memset(fabric, 0, sizeof(struct bfa_fcs_fabric_s));
1141 * Initialize base fabric.
1143 fabric->fcs = fcs;
1144 INIT_LIST_HEAD(&fabric->vport_q);
1145 INIT_LIST_HEAD(&fabric->vf_q);
1146 fabric->lps = bfa_lps_alloc(fcs->bfa);
1147 WARN_ON(!fabric->lps);
1150 * Initialize fabric delete completion handler. Fabric deletion is
1151 * complete when the last vport delete is complete.
1153 bfa_wc_init(&fabric->wc, bfa_fcs_fabric_delete_comp, fabric);
1154 bfa_wc_up(&fabric->wc); /* For the base port */
1156 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_uninit);
1157 bfa_fcs_lport_attach(&fabric->bport, fabric->fcs, FC_VF_ID_NULL, NULL);
1160 void
1161 bfa_fcs_fabric_modinit(struct bfa_fcs_s *fcs)
1163 bfa_sm_send_event(&fcs->fabric, BFA_FCS_FABRIC_SM_CREATE);
1164 bfa_trc(fcs, 0);
1168 * Module cleanup
1170 void
1171 bfa_fcs_fabric_modexit(struct bfa_fcs_s *fcs)
1173 struct bfa_fcs_fabric_s *fabric;
1175 bfa_trc(fcs, 0);
1178 * Cleanup base fabric.
1180 fabric = &fcs->fabric;
1181 bfa_lps_delete(fabric->lps);
1182 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_DELETE);
1186 * Fabric module stop -- stop FCS actions
1188 void
1189 bfa_fcs_fabric_modstop(struct bfa_fcs_s *fcs)
1191 struct bfa_fcs_fabric_s *fabric;
1193 bfa_trc(fcs, 0);
1194 fabric = &fcs->fabric;
1195 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_STOP);
1199 * Fabric module start -- kick starts FCS actions
1201 void
1202 bfa_fcs_fabric_modstart(struct bfa_fcs_s *fcs)
1204 struct bfa_fcs_fabric_s *fabric;
1206 bfa_trc(fcs, 0);
1207 fabric = &fcs->fabric;
1208 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_START);
1213 * Link up notification from BFA physical port module.
1215 void
1216 bfa_fcs_fabric_link_up(struct bfa_fcs_fabric_s *fabric)
1218 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
1219 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_LINK_UP);
1223 * Link down notification from BFA physical port module.
1225 void
1226 bfa_fcs_fabric_link_down(struct bfa_fcs_fabric_s *fabric)
1228 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
1229 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_LINK_DOWN);
1233 * A child vport is being created in the fabric.
1235 * Call from vport module at vport creation. A list of base port and vports
1236 * belonging to a fabric is maintained to propagate link events.
1238 * param[in] fabric - Fabric instance. This can be a base fabric or vf.
1239 * param[in] vport - Vport being created.
1241 * @return None (always succeeds)
1243 void
1244 bfa_fcs_fabric_addvport(struct bfa_fcs_fabric_s *fabric,
1245 struct bfa_fcs_vport_s *vport)
1248 * - add vport to fabric's vport_q
1250 bfa_trc(fabric->fcs, fabric->vf_id);
1252 list_add_tail(&vport->qe, &fabric->vport_q);
1253 fabric->num_vports++;
1254 bfa_wc_up(&fabric->wc);
1258 * A child vport is being deleted from fabric.
1260 * Vport is being deleted.
1262 void
1263 bfa_fcs_fabric_delvport(struct bfa_fcs_fabric_s *fabric,
1264 struct bfa_fcs_vport_s *vport)
1266 list_del(&vport->qe);
1267 fabric->num_vports--;
1268 bfa_wc_down(&fabric->wc);
1273 * Lookup for a vport within a fabric given its pwwn
1275 struct bfa_fcs_vport_s *
1276 bfa_fcs_fabric_vport_lookup(struct bfa_fcs_fabric_s *fabric, wwn_t pwwn)
1278 struct bfa_fcs_vport_s *vport;
1279 struct list_head *qe;
1281 list_for_each(qe, &fabric->vport_q) {
1282 vport = (struct bfa_fcs_vport_s *) qe;
1283 if (bfa_fcs_lport_get_pwwn(&vport->lport) == pwwn)
1284 return vport;
1287 return NULL;
1292 * Get OUI of the attached switch.
1294 * Note : Use of this function should be avoided as much as possible.
1295 * This function should be used only if there is any requirement
1296 * to check for FOS version below 6.3.
1297 * To check if the attached fabric is a brocade fabric, use
1298 * bfa_lps_is_brcd_fabric() which works for FOS versions 6.3
1299 * or above only.
1303 bfa_fcs_fabric_get_switch_oui(struct bfa_fcs_fabric_s *fabric)
1305 wwn_t fab_nwwn;
1306 u8 *tmp;
1307 u16 oui;
1309 fab_nwwn = fabric->lps->pr_nwwn;
1311 tmp = (u8 *)&fab_nwwn;
1312 oui = (tmp[3] << 8) | tmp[4];
1314 return oui;
1317 * Unsolicited frame receive handling.
1319 void
1320 bfa_fcs_fabric_uf_recv(struct bfa_fcs_fabric_s *fabric, struct fchs_s *fchs,
1321 u16 len)
1323 u32 pid = fchs->d_id;
1324 struct bfa_fcs_vport_s *vport;
1325 struct list_head *qe;
1326 struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
1327 struct fc_logi_s *flogi = (struct fc_logi_s *) els_cmd;
1329 bfa_trc(fabric->fcs, len);
1330 bfa_trc(fabric->fcs, pid);
1333 * Look for our own FLOGI frames being looped back. This means an
1334 * external loopback cable is in place. Our own FLOGI frames are
1335 * sometimes looped back when switch port gets temporarily bypassed.
1337 if ((pid == bfa_ntoh3b(FC_FABRIC_PORT)) &&
1338 (els_cmd->els_code == FC_ELS_FLOGI) &&
1339 (flogi->port_name == bfa_fcs_lport_get_pwwn(&fabric->bport))) {
1340 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_LOOPBACK);
1341 return;
1345 * FLOGI/EVFP exchanges should be consumed by base fabric.
1347 if (fchs->d_id == bfa_hton3b(FC_FABRIC_PORT)) {
1348 bfa_trc(fabric->fcs, pid);
1349 bfa_fcs_fabric_process_uf(fabric, fchs, len);
1350 return;
1353 if (fabric->bport.pid == pid) {
1355 * All authentication frames should be routed to auth
1357 bfa_trc(fabric->fcs, els_cmd->els_code);
1358 if (els_cmd->els_code == FC_ELS_AUTH) {
1359 bfa_trc(fabric->fcs, els_cmd->els_code);
1360 return;
1363 bfa_trc(fabric->fcs, *(u8 *) ((u8 *) fchs));
1364 bfa_fcs_lport_uf_recv(&fabric->bport, fchs, len);
1365 return;
1369 * look for a matching local port ID
1371 list_for_each(qe, &fabric->vport_q) {
1372 vport = (struct bfa_fcs_vport_s *) qe;
1373 if (vport->lport.pid == pid) {
1374 bfa_fcs_lport_uf_recv(&vport->lport, fchs, len);
1375 return;
1379 if (!bfa_fcs_fabric_is_switched(fabric))
1380 bfa_fcs_lport_uf_recv(&fabric->bport, fchs, len);
1382 bfa_trc(fabric->fcs, fchs->type);
1386 * Unsolicited frames to be processed by fabric.
1388 static void
1389 bfa_fcs_fabric_process_uf(struct bfa_fcs_fabric_s *fabric, struct fchs_s *fchs,
1390 u16 len)
1392 struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
1394 bfa_trc(fabric->fcs, els_cmd->els_code);
1396 switch (els_cmd->els_code) {
1397 case FC_ELS_FLOGI:
1398 bfa_fcs_fabric_process_flogi(fabric, fchs, len);
1399 break;
1401 default:
1403 * need to generate a LS_RJT
1405 break;
1410 * Process incoming FLOGI
1412 static void
1413 bfa_fcs_fabric_process_flogi(struct bfa_fcs_fabric_s *fabric,
1414 struct fchs_s *fchs, u16 len)
1416 struct fc_logi_s *flogi = (struct fc_logi_s *) (fchs + 1);
1417 struct bfa_fcs_lport_s *bport = &fabric->bport;
1419 bfa_trc(fabric->fcs, fchs->s_id);
1421 fabric->stats.flogi_rcvd++;
1423 * Check port type. It should be 0 = n-port.
1425 if (flogi->csp.port_type) {
1427 * @todo: may need to send a LS_RJT
1429 bfa_trc(fabric->fcs, flogi->port_name);
1430 fabric->stats.flogi_rejected++;
1431 return;
1434 fabric->bb_credit = be16_to_cpu(flogi->csp.bbcred);
1435 bport->port_topo.pn2n.rem_port_wwn = flogi->port_name;
1436 bport->port_topo.pn2n.reply_oxid = fchs->ox_id;
1439 * Send a Flogi Acc
1441 bfa_fcs_fabric_send_flogi_acc(fabric);
1442 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_NO_FABRIC);
1445 static void
1446 bfa_fcs_fabric_send_flogi_acc(struct bfa_fcs_fabric_s *fabric)
1448 struct bfa_lport_cfg_s *pcfg = &fabric->bport.port_cfg;
1449 struct bfa_fcs_lport_n2n_s *n2n_port = &fabric->bport.port_topo.pn2n;
1450 struct bfa_s *bfa = fabric->fcs->bfa;
1451 struct bfa_fcxp_s *fcxp;
1452 u16 reqlen;
1453 struct fchs_s fchs;
1455 fcxp = bfa_fcs_fcxp_alloc(fabric->fcs, BFA_FALSE);
1457 * Do not expect this failure -- expect remote node to retry
1459 if (!fcxp)
1460 return;
1462 reqlen = fc_flogi_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
1463 bfa_hton3b(FC_FABRIC_PORT),
1464 n2n_port->reply_oxid, pcfg->pwwn,
1465 pcfg->nwwn,
1466 bfa_fcport_get_maxfrsize(bfa),
1467 bfa_fcport_get_rx_bbcredit(bfa), 0);
1469 bfa_fcxp_send(fcxp, NULL, fabric->vf_id, fabric->lps->bfa_tag,
1470 BFA_FALSE, FC_CLASS_3,
1471 reqlen, &fchs, bfa_fcs_fabric_flogiacc_comp, fabric,
1472 FC_MAX_PDUSZ, 0);
1476 * Flogi Acc completion callback.
1478 static void
1479 bfa_fcs_fabric_flogiacc_comp(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
1480 bfa_status_t status, u32 rsp_len,
1481 u32 resid_len, struct fchs_s *rspfchs)
1483 struct bfa_fcs_fabric_s *fabric = cbarg;
1485 bfa_trc(fabric->fcs, status);
1490 * Send AEN notification
1492 static void
1493 bfa_fcs_fabric_aen_post(struct bfa_fcs_lport_s *port,
1494 enum bfa_port_aen_event event)
1496 struct bfad_s *bfad = (struct bfad_s *)port->fabric->fcs->bfad;
1497 struct bfa_aen_entry_s *aen_entry;
1499 bfad_get_aen_entry(bfad, aen_entry);
1500 if (!aen_entry)
1501 return;
1503 aen_entry->aen_data.port.pwwn = bfa_fcs_lport_get_pwwn(port);
1504 aen_entry->aen_data.port.fwwn = bfa_fcs_lport_get_fabric_name(port);
1506 /* Send the AEN notification */
1507 bfad_im_post_vendor_event(aen_entry, bfad, ++port->fcs->fcs_aen_seq,
1508 BFA_AEN_CAT_PORT, event);
1513 * @param[in] fabric - fabric
1514 * @param[in] wwn_t - new fabric name
1516 * @return - none
1518 void
1519 bfa_fcs_fabric_set_fabric_name(struct bfa_fcs_fabric_s *fabric,
1520 wwn_t fabric_name)
1522 struct bfad_s *bfad = (struct bfad_s *)fabric->fcs->bfad;
1523 char pwwn_ptr[BFA_STRING_32];
1524 char fwwn_ptr[BFA_STRING_32];
1526 bfa_trc(fabric->fcs, fabric_name);
1528 if (fabric->fabric_name == 0) {
1530 * With BRCD switches, we don't get Fabric Name in FLOGI.
1531 * Don't generate a fabric name change event in this case.
1533 fabric->fabric_name = fabric_name;
1534 } else {
1535 fabric->fabric_name = fabric_name;
1536 wwn2str(pwwn_ptr, bfa_fcs_lport_get_pwwn(&fabric->bport));
1537 wwn2str(fwwn_ptr,
1538 bfa_fcs_lport_get_fabric_name(&fabric->bport));
1539 BFA_LOG(KERN_WARNING, bfad, bfa_log_level,
1540 "Base port WWN = %s Fabric WWN = %s\n",
1541 pwwn_ptr, fwwn_ptr);
1542 bfa_fcs_fabric_aen_post(&fabric->bport,
1543 BFA_PORT_AEN_FABRIC_NAME_CHANGE);
1547 void
1548 bfa_cb_lps_flogo_comp(void *bfad, void *uarg)
1550 struct bfa_fcs_fabric_s *fabric = uarg;
1551 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_LOGOCOMP);
1555 * Returns FCS vf structure for a given vf_id.
1557 * param[in] vf_id - VF_ID
1559 * return
1560 * If lookup succeeds, retuns fcs vf object, otherwise returns NULL
1562 bfa_fcs_vf_t *
1563 bfa_fcs_vf_lookup(struct bfa_fcs_s *fcs, u16 vf_id)
1565 bfa_trc(fcs, vf_id);
1566 if (vf_id == FC_VF_ID_NULL)
1567 return &fcs->fabric;
1569 return NULL;
1573 * Return the list of local logical ports present in the given VF.
1575 * @param[in] vf vf for which logical ports are returned
1576 * @param[out] lpwwn returned logical port wwn list
1577 * @param[in,out] nlports in:size of lpwwn list;
1578 * out:total elements present,
1579 * actual elements returned is limited by the size
1581 void
1582 bfa_fcs_vf_get_ports(bfa_fcs_vf_t *vf, wwn_t lpwwn[], int *nlports)
1584 struct list_head *qe;
1585 struct bfa_fcs_vport_s *vport;
1586 int i = 0;
1587 struct bfa_fcs_s *fcs;
1589 if (vf == NULL || lpwwn == NULL || *nlports == 0)
1590 return;
1592 fcs = vf->fcs;
1594 bfa_trc(fcs, vf->vf_id);
1595 bfa_trc(fcs, (uint32_t) *nlports);
1597 lpwwn[i++] = vf->bport.port_cfg.pwwn;
1599 list_for_each(qe, &vf->vport_q) {
1600 if (i >= *nlports)
1601 break;
1603 vport = (struct bfa_fcs_vport_s *) qe;
1604 lpwwn[i++] = vport->lport.port_cfg.pwwn;
1607 bfa_trc(fcs, i);
1608 *nlports = i;
1612 * BFA FCS PPORT ( physical port)
1614 static void
1615 bfa_fcs_port_event_handler(void *cbarg, enum bfa_port_linkstate event)
1617 struct bfa_fcs_s *fcs = cbarg;
1619 bfa_trc(fcs, event);
1621 switch (event) {
1622 case BFA_PORT_LINKUP:
1623 bfa_fcs_fabric_link_up(&fcs->fabric);
1624 break;
1626 case BFA_PORT_LINKDOWN:
1627 bfa_fcs_fabric_link_down(&fcs->fabric);
1628 break;
1630 default:
1631 WARN_ON(1);
1635 void
1636 bfa_fcs_port_attach(struct bfa_fcs_s *fcs)
1638 bfa_fcport_event_register(fcs->bfa, bfa_fcs_port_event_handler, fcs);
1642 * BFA FCS UF ( Unsolicited Frames)
1646 * BFA callback for unsolicited frame receive handler.
1648 * @param[in] cbarg callback arg for receive handler
1649 * @param[in] uf unsolicited frame descriptor
1651 * @return None
1653 static void
1654 bfa_fcs_uf_recv(void *cbarg, struct bfa_uf_s *uf)
1656 struct bfa_fcs_s *fcs = (struct bfa_fcs_s *) cbarg;
1657 struct fchs_s *fchs = bfa_uf_get_frmbuf(uf);
1658 u16 len = bfa_uf_get_frmlen(uf);
1659 struct fc_vft_s *vft;
1660 struct bfa_fcs_fabric_s *fabric;
1663 * check for VFT header
1665 if (fchs->routing == FC_RTG_EXT_HDR &&
1666 fchs->cat_info == FC_CAT_VFT_HDR) {
1667 bfa_stats(fcs, uf.tagged);
1668 vft = bfa_uf_get_frmbuf(uf);
1669 if (fcs->port_vfid == vft->vf_id)
1670 fabric = &fcs->fabric;
1671 else
1672 fabric = bfa_fcs_vf_lookup(fcs, (u16) vft->vf_id);
1675 * drop frame if vfid is unknown
1677 if (!fabric) {
1678 WARN_ON(1);
1679 bfa_stats(fcs, uf.vfid_unknown);
1680 bfa_uf_free(uf);
1681 return;
1685 * skip vft header
1687 fchs = (struct fchs_s *) (vft + 1);
1688 len -= sizeof(struct fc_vft_s);
1690 bfa_trc(fcs, vft->vf_id);
1691 } else {
1692 bfa_stats(fcs, uf.untagged);
1693 fabric = &fcs->fabric;
1696 bfa_trc(fcs, ((u32 *) fchs)[0]);
1697 bfa_trc(fcs, ((u32 *) fchs)[1]);
1698 bfa_trc(fcs, ((u32 *) fchs)[2]);
1699 bfa_trc(fcs, ((u32 *) fchs)[3]);
1700 bfa_trc(fcs, ((u32 *) fchs)[4]);
1701 bfa_trc(fcs, ((u32 *) fchs)[5]);
1702 bfa_trc(fcs, len);
1704 bfa_fcs_fabric_uf_recv(fabric, fchs, len);
1705 bfa_uf_free(uf);
1708 void
1709 bfa_fcs_uf_attach(struct bfa_fcs_s *fcs)
1711 bfa_uf_recv_register(fcs->bfa, bfa_fcs_uf_recv, fcs);