Linux 5.1.15
[linux/fpc-iii.git] / drivers / scsi / bfa / bfa_fcs.c
blob932feb0ed4da1e0d0e5846b302342ef2ad2e008a
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_api BFA FCS API
34 static void
35 bfa_fcs_exit_comp(void *fcs_cbarg)
37 struct bfa_fcs_s *fcs = fcs_cbarg;
38 struct bfad_s *bfad = fcs->bfad;
40 complete(&bfad->comp);
44 * fcs initialization, called once after bfa initialization is complete
46 void
47 bfa_fcs_init(struct bfa_fcs_s *fcs)
49 bfa_sm_send_event(&fcs->fabric, BFA_FCS_FABRIC_SM_CREATE);
50 bfa_trc(fcs, 0);
54 * fcs_api BFA FCS API
58 * FCS update cfg - reset the pwwn/nwwn of fabric base logical port
59 * with values learned during bfa_init firmware GETATTR REQ.
61 void
62 bfa_fcs_update_cfg(struct bfa_fcs_s *fcs)
64 struct bfa_fcs_fabric_s *fabric = &fcs->fabric;
65 struct bfa_lport_cfg_s *port_cfg = &fabric->bport.port_cfg;
66 struct bfa_ioc_s *ioc = &fabric->fcs->bfa->ioc;
68 port_cfg->nwwn = ioc->attr->nwwn;
69 port_cfg->pwwn = ioc->attr->pwwn;
73 * Stop FCS operations.
75 void
76 bfa_fcs_stop(struct bfa_fcs_s *fcs)
78 bfa_wc_init(&fcs->wc, bfa_fcs_exit_comp, fcs);
79 bfa_wc_up(&fcs->wc);
80 bfa_fcs_fabric_modstop(fcs);
81 bfa_wc_wait(&fcs->wc);
85 * fcs pbc vport initialization
87 void
88 bfa_fcs_pbc_vport_init(struct bfa_fcs_s *fcs)
90 int i, npbc_vports;
91 struct bfi_pbc_vport_s pbc_vports[BFI_PBC_MAX_VPORTS];
93 /* Initialize pbc vports */
94 if (!fcs->min_cfg) {
95 npbc_vports =
96 bfa_iocfc_get_pbc_vports(fcs->bfa, pbc_vports);
97 for (i = 0; i < npbc_vports; i++)
98 bfa_fcb_pbc_vport_create(fcs->bfa->bfad, pbc_vports[i]);
103 * brief
104 * FCS driver details initialization.
106 * param[in] fcs FCS instance
107 * param[in] driver_info Driver Details
109 * return None
111 void
112 bfa_fcs_driver_info_init(struct bfa_fcs_s *fcs,
113 struct bfa_fcs_driver_info_s *driver_info)
116 fcs->driver_info = *driver_info;
118 bfa_fcs_fabric_psymb_init(&fcs->fabric);
119 bfa_fcs_fabric_nsymb_init(&fcs->fabric);
123 * brief
124 * FCS instance cleanup and exit.
126 * param[in] fcs FCS instance
127 * return None
129 void
130 bfa_fcs_exit(struct bfa_fcs_s *fcs)
132 bfa_wc_init(&fcs->wc, bfa_fcs_exit_comp, fcs);
133 bfa_wc_up(&fcs->wc);
134 bfa_trc(fcs, 0);
135 bfa_lps_delete(fcs->fabric.lps);
136 bfa_sm_send_event(&fcs->fabric, BFA_FCS_FABRIC_SM_DELETE);
137 bfa_wc_wait(&fcs->wc);
141 * Fabric module implementation.
144 #define BFA_FCS_FABRIC_RETRY_DELAY (2000) /* Milliseconds */
145 #define BFA_FCS_FABRIC_CLEANUP_DELAY (10000) /* Milliseconds */
147 #define bfa_fcs_fabric_set_opertype(__fabric) do { \
148 if (bfa_fcport_get_topology((__fabric)->fcs->bfa) \
149 == BFA_PORT_TOPOLOGY_P2P) { \
150 if (fabric->fab_type == BFA_FCS_FABRIC_SWITCHED) \
151 (__fabric)->oper_type = BFA_PORT_TYPE_NPORT; \
152 else \
153 (__fabric)->oper_type = BFA_PORT_TYPE_P2P; \
154 } else \
155 (__fabric)->oper_type = BFA_PORT_TYPE_NLPORT; \
156 } while (0)
159 * forward declarations
161 static void bfa_fcs_fabric_init(struct bfa_fcs_fabric_s *fabric);
162 static void bfa_fcs_fabric_login(struct bfa_fcs_fabric_s *fabric);
163 static void bfa_fcs_fabric_notify_online(struct bfa_fcs_fabric_s *fabric);
164 static void bfa_fcs_fabric_notify_offline(struct bfa_fcs_fabric_s *fabric);
165 static void bfa_fcs_fabric_delay(void *cbarg);
166 static void bfa_fcs_fabric_delete(struct bfa_fcs_fabric_s *fabric);
167 static void bfa_fcs_fabric_delete_comp(void *cbarg);
168 static void bfa_fcs_fabric_stop(struct bfa_fcs_fabric_s *fabric);
169 static void bfa_fcs_fabric_stop_comp(void *cbarg);
170 static void bfa_fcs_fabric_process_uf(struct bfa_fcs_fabric_s *fabric,
171 struct fchs_s *fchs, u16 len);
172 static void bfa_fcs_fabric_process_flogi(struct bfa_fcs_fabric_s *fabric,
173 struct fchs_s *fchs, u16 len);
174 static void bfa_fcs_fabric_send_flogi_acc(struct bfa_fcs_fabric_s *fabric);
175 static void bfa_fcs_fabric_flogiacc_comp(void *fcsarg,
176 struct bfa_fcxp_s *fcxp, void *cbarg,
177 bfa_status_t status,
178 u32 rsp_len,
179 u32 resid_len,
180 struct fchs_s *rspfchs);
182 static void bfa_fcs_fabric_sm_uninit(struct bfa_fcs_fabric_s *fabric,
183 enum bfa_fcs_fabric_event event);
184 static void bfa_fcs_fabric_sm_created(struct bfa_fcs_fabric_s *fabric,
185 enum bfa_fcs_fabric_event event);
186 static void bfa_fcs_fabric_sm_linkdown(struct bfa_fcs_fabric_s *fabric,
187 enum bfa_fcs_fabric_event event);
188 static void bfa_fcs_fabric_sm_flogi(struct bfa_fcs_fabric_s *fabric,
189 enum bfa_fcs_fabric_event event);
190 static void bfa_fcs_fabric_sm_flogi_retry(struct bfa_fcs_fabric_s *fabric,
191 enum bfa_fcs_fabric_event event);
192 static void bfa_fcs_fabric_sm_auth(struct bfa_fcs_fabric_s *fabric,
193 enum bfa_fcs_fabric_event event);
194 static void bfa_fcs_fabric_sm_nofabric(struct bfa_fcs_fabric_s *fabric,
195 enum bfa_fcs_fabric_event event);
196 static void bfa_fcs_fabric_sm_evfp(struct bfa_fcs_fabric_s *fabric,
197 enum bfa_fcs_fabric_event event);
198 static void bfa_fcs_fabric_sm_evfp_done(struct bfa_fcs_fabric_s *fabric,
199 enum bfa_fcs_fabric_event event);
200 static void bfa_fcs_fabric_sm_isolated(struct bfa_fcs_fabric_s *fabric,
201 enum bfa_fcs_fabric_event event);
202 static void bfa_fcs_fabric_sm_deleting(struct bfa_fcs_fabric_s *fabric,
203 enum bfa_fcs_fabric_event event);
204 static void bfa_fcs_fabric_sm_stopping(struct bfa_fcs_fabric_s *fabric,
205 enum bfa_fcs_fabric_event event);
206 static void bfa_fcs_fabric_sm_cleanup(struct bfa_fcs_fabric_s *fabric,
207 enum bfa_fcs_fabric_event event);
209 * Beginning state before fabric creation.
211 static void
212 bfa_fcs_fabric_sm_uninit(struct bfa_fcs_fabric_s *fabric,
213 enum bfa_fcs_fabric_event event)
215 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
216 bfa_trc(fabric->fcs, event);
218 switch (event) {
219 case BFA_FCS_FABRIC_SM_CREATE:
220 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_created);
221 bfa_fcs_fabric_init(fabric);
222 bfa_fcs_lport_init(&fabric->bport, &fabric->bport.port_cfg);
223 break;
225 case BFA_FCS_FABRIC_SM_LINK_UP:
226 case BFA_FCS_FABRIC_SM_LINK_DOWN:
227 break;
229 default:
230 bfa_sm_fault(fabric->fcs, event);
235 * Beginning state before fabric creation.
237 static void
238 bfa_fcs_fabric_sm_created(struct bfa_fcs_fabric_s *fabric,
239 enum bfa_fcs_fabric_event event)
241 struct bfa_s *bfa = fabric->fcs->bfa;
243 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
244 bfa_trc(fabric->fcs, event);
246 switch (event) {
247 case BFA_FCS_FABRIC_SM_START:
248 if (!bfa_fcport_is_linkup(fabric->fcs->bfa)) {
249 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
250 break;
252 if (bfa_fcport_get_topology(bfa) ==
253 BFA_PORT_TOPOLOGY_LOOP) {
254 fabric->fab_type = BFA_FCS_FABRIC_LOOP;
255 fabric->bport.pid = bfa_fcport_get_myalpa(bfa);
256 fabric->bport.pid = bfa_hton3b(fabric->bport.pid);
257 bfa_sm_set_state(fabric,
258 bfa_fcs_fabric_sm_online);
259 bfa_fcs_fabric_set_opertype(fabric);
260 bfa_fcs_lport_online(&fabric->bport);
261 } else {
262 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_flogi);
263 bfa_fcs_fabric_login(fabric);
265 break;
267 case BFA_FCS_FABRIC_SM_LINK_UP:
268 case BFA_FCS_FABRIC_SM_LINK_DOWN:
269 break;
271 case BFA_FCS_FABRIC_SM_DELETE:
272 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
273 bfa_fcs_fabric_delete(fabric);
274 break;
276 default:
277 bfa_sm_fault(fabric->fcs, event);
282 * Link is down, awaiting LINK UP event from port. This is also the
283 * first state at fabric creation.
285 static void
286 bfa_fcs_fabric_sm_linkdown(struct bfa_fcs_fabric_s *fabric,
287 enum bfa_fcs_fabric_event event)
289 struct bfa_s *bfa = fabric->fcs->bfa;
291 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
292 bfa_trc(fabric->fcs, event);
294 switch (event) {
295 case BFA_FCS_FABRIC_SM_LINK_UP:
296 if (bfa_fcport_get_topology(bfa) != BFA_PORT_TOPOLOGY_LOOP) {
297 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_flogi);
298 bfa_fcs_fabric_login(fabric);
299 break;
301 fabric->fab_type = BFA_FCS_FABRIC_LOOP;
302 fabric->bport.pid = bfa_fcport_get_myalpa(bfa);
303 fabric->bport.pid = bfa_hton3b(fabric->bport.pid);
304 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_online);
305 bfa_fcs_fabric_set_opertype(fabric);
306 bfa_fcs_lport_online(&fabric->bport);
307 break;
309 case BFA_FCS_FABRIC_SM_RETRY_OP:
310 case BFA_FCS_FABRIC_SM_LOOPBACK:
311 break;
313 case BFA_FCS_FABRIC_SM_DELETE:
314 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
315 bfa_fcs_fabric_delete(fabric);
316 break;
318 case BFA_FCS_FABRIC_SM_STOP:
319 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_cleanup);
320 bfa_fcs_fabric_stop(fabric);
321 break;
323 default:
324 bfa_sm_fault(fabric->fcs, event);
329 * FLOGI is in progress, awaiting FLOGI reply.
331 static void
332 bfa_fcs_fabric_sm_flogi(struct bfa_fcs_fabric_s *fabric,
333 enum bfa_fcs_fabric_event event)
335 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
336 bfa_trc(fabric->fcs, event);
338 switch (event) {
339 case BFA_FCS_FABRIC_SM_CONT_OP:
341 bfa_fcport_set_tx_bbcredit(fabric->fcs->bfa,
342 fabric->bb_credit);
343 fabric->fab_type = BFA_FCS_FABRIC_SWITCHED;
345 if (fabric->auth_reqd && fabric->is_auth) {
346 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_auth);
347 bfa_trc(fabric->fcs, event);
348 } else {
349 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_online);
350 bfa_fcs_fabric_notify_online(fabric);
352 break;
354 case BFA_FCS_FABRIC_SM_RETRY_OP:
355 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_flogi_retry);
356 bfa_timer_start(fabric->fcs->bfa, &fabric->delay_timer,
357 bfa_fcs_fabric_delay, fabric,
358 BFA_FCS_FABRIC_RETRY_DELAY);
359 break;
361 case BFA_FCS_FABRIC_SM_LOOPBACK:
362 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_loopback);
363 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
364 bfa_fcs_fabric_set_opertype(fabric);
365 break;
367 case BFA_FCS_FABRIC_SM_NO_FABRIC:
368 fabric->fab_type = BFA_FCS_FABRIC_N2N;
369 bfa_fcport_set_tx_bbcredit(fabric->fcs->bfa,
370 fabric->bb_credit);
371 bfa_fcs_fabric_notify_online(fabric);
372 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_nofabric);
373 break;
375 case BFA_FCS_FABRIC_SM_LINK_DOWN:
376 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
377 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
378 break;
380 case BFA_FCS_FABRIC_SM_DELETE:
381 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
382 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
383 bfa_fcs_fabric_delete(fabric);
384 break;
386 default:
387 bfa_sm_fault(fabric->fcs, event);
392 static void
393 bfa_fcs_fabric_sm_flogi_retry(struct bfa_fcs_fabric_s *fabric,
394 enum bfa_fcs_fabric_event event)
396 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
397 bfa_trc(fabric->fcs, event);
399 switch (event) {
400 case BFA_FCS_FABRIC_SM_DELAYED:
401 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_flogi);
402 bfa_fcs_fabric_login(fabric);
403 break;
405 case BFA_FCS_FABRIC_SM_LINK_DOWN:
406 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
407 bfa_timer_stop(&fabric->delay_timer);
408 break;
410 case BFA_FCS_FABRIC_SM_DELETE:
411 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
412 bfa_timer_stop(&fabric->delay_timer);
413 bfa_fcs_fabric_delete(fabric);
414 break;
416 default:
417 bfa_sm_fault(fabric->fcs, event);
422 * Authentication is in progress, awaiting authentication results.
424 static void
425 bfa_fcs_fabric_sm_auth(struct bfa_fcs_fabric_s *fabric,
426 enum bfa_fcs_fabric_event event)
428 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
429 bfa_trc(fabric->fcs, event);
431 switch (event) {
432 case BFA_FCS_FABRIC_SM_AUTH_FAILED:
433 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_auth_failed);
434 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
435 break;
437 case BFA_FCS_FABRIC_SM_AUTH_SUCCESS:
438 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_online);
439 bfa_fcs_fabric_notify_online(fabric);
440 break;
442 case BFA_FCS_FABRIC_SM_PERF_EVFP:
443 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_evfp);
444 break;
446 case BFA_FCS_FABRIC_SM_LINK_DOWN:
447 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
448 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
449 break;
451 case BFA_FCS_FABRIC_SM_DELETE:
452 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
453 bfa_fcs_fabric_delete(fabric);
454 break;
456 default:
457 bfa_sm_fault(fabric->fcs, event);
462 * Authentication failed
464 void
465 bfa_fcs_fabric_sm_auth_failed(struct bfa_fcs_fabric_s *fabric,
466 enum bfa_fcs_fabric_event event)
468 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
469 bfa_trc(fabric->fcs, event);
471 switch (event) {
472 case BFA_FCS_FABRIC_SM_LINK_DOWN:
473 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
474 bfa_fcs_fabric_notify_offline(fabric);
475 break;
477 case BFA_FCS_FABRIC_SM_DELETE:
478 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
479 bfa_fcs_fabric_delete(fabric);
480 break;
482 default:
483 bfa_sm_fault(fabric->fcs, event);
488 * Port is in loopback mode.
490 void
491 bfa_fcs_fabric_sm_loopback(struct bfa_fcs_fabric_s *fabric,
492 enum bfa_fcs_fabric_event event)
494 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
495 bfa_trc(fabric->fcs, event);
497 switch (event) {
498 case BFA_FCS_FABRIC_SM_LINK_DOWN:
499 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
500 bfa_fcs_fabric_notify_offline(fabric);
501 break;
503 case BFA_FCS_FABRIC_SM_DELETE:
504 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
505 bfa_fcs_fabric_delete(fabric);
506 break;
508 default:
509 bfa_sm_fault(fabric->fcs, event);
514 * There is no attached fabric - private loop or NPort-to-NPort topology.
516 static void
517 bfa_fcs_fabric_sm_nofabric(struct bfa_fcs_fabric_s *fabric,
518 enum bfa_fcs_fabric_event event)
520 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
521 bfa_trc(fabric->fcs, event);
523 switch (event) {
524 case BFA_FCS_FABRIC_SM_LINK_DOWN:
525 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
526 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
527 bfa_fcs_fabric_notify_offline(fabric);
528 break;
530 case BFA_FCS_FABRIC_SM_DELETE:
531 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
532 bfa_fcs_fabric_delete(fabric);
533 break;
535 case BFA_FCS_FABRIC_SM_NO_FABRIC:
536 bfa_trc(fabric->fcs, fabric->bb_credit);
537 bfa_fcport_set_tx_bbcredit(fabric->fcs->bfa,
538 fabric->bb_credit);
539 break;
541 case BFA_FCS_FABRIC_SM_RETRY_OP:
542 break;
544 default:
545 bfa_sm_fault(fabric->fcs, event);
550 * Fabric is online - normal operating state.
552 void
553 bfa_fcs_fabric_sm_online(struct bfa_fcs_fabric_s *fabric,
554 enum bfa_fcs_fabric_event event)
556 struct bfa_s *bfa = fabric->fcs->bfa;
558 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
559 bfa_trc(fabric->fcs, event);
561 switch (event) {
562 case BFA_FCS_FABRIC_SM_LINK_DOWN:
563 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
564 if (bfa_fcport_get_topology(bfa) == BFA_PORT_TOPOLOGY_LOOP) {
565 bfa_fcs_lport_offline(&fabric->bport);
566 } else {
567 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
568 bfa_fcs_fabric_notify_offline(fabric);
570 break;
572 case BFA_FCS_FABRIC_SM_DELETE:
573 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
574 bfa_fcs_fabric_delete(fabric);
575 break;
577 case BFA_FCS_FABRIC_SM_STOP:
578 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_stopping);
579 bfa_fcs_fabric_stop(fabric);
580 break;
582 case BFA_FCS_FABRIC_SM_AUTH_FAILED:
583 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_auth_failed);
584 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
585 break;
587 case BFA_FCS_FABRIC_SM_AUTH_SUCCESS:
588 break;
590 default:
591 bfa_sm_fault(fabric->fcs, event);
596 * Exchanging virtual fabric parameters.
598 static void
599 bfa_fcs_fabric_sm_evfp(struct bfa_fcs_fabric_s *fabric,
600 enum bfa_fcs_fabric_event event)
602 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
603 bfa_trc(fabric->fcs, event);
605 switch (event) {
606 case BFA_FCS_FABRIC_SM_CONT_OP:
607 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_evfp_done);
608 break;
610 case BFA_FCS_FABRIC_SM_ISOLATE:
611 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_isolated);
612 break;
614 default:
615 bfa_sm_fault(fabric->fcs, event);
620 * EVFP exchange complete and VFT tagging is enabled.
622 static void
623 bfa_fcs_fabric_sm_evfp_done(struct bfa_fcs_fabric_s *fabric,
624 enum bfa_fcs_fabric_event event)
626 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
627 bfa_trc(fabric->fcs, event);
631 * Port is isolated after EVFP exchange due to VF_ID mismatch (N and F).
633 static void
634 bfa_fcs_fabric_sm_isolated(struct bfa_fcs_fabric_s *fabric,
635 enum bfa_fcs_fabric_event event)
637 struct bfad_s *bfad = (struct bfad_s *)fabric->fcs->bfad;
638 char pwwn_ptr[BFA_STRING_32];
640 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
641 bfa_trc(fabric->fcs, event);
642 wwn2str(pwwn_ptr, fabric->bport.port_cfg.pwwn);
644 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
645 "Port is isolated due to VF_ID mismatch. "
646 "PWWN: %s Port VF_ID: %04x switch port VF_ID: %04x.",
647 pwwn_ptr, fabric->fcs->port_vfid,
648 fabric->event_arg.swp_vfid);
652 * Fabric is being deleted, awaiting vport delete completions.
654 static void
655 bfa_fcs_fabric_sm_deleting(struct bfa_fcs_fabric_s *fabric,
656 enum bfa_fcs_fabric_event event)
658 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
659 bfa_trc(fabric->fcs, event);
661 switch (event) {
662 case BFA_FCS_FABRIC_SM_DELCOMP:
663 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_uninit);
664 bfa_wc_down(&fabric->fcs->wc);
665 break;
667 case BFA_FCS_FABRIC_SM_LINK_UP:
668 break;
670 case BFA_FCS_FABRIC_SM_LINK_DOWN:
671 bfa_fcs_fabric_notify_offline(fabric);
672 break;
674 default:
675 bfa_sm_fault(fabric->fcs, event);
680 * Fabric is being stopped, awaiting vport stop completions.
682 static void
683 bfa_fcs_fabric_sm_stopping(struct bfa_fcs_fabric_s *fabric,
684 enum bfa_fcs_fabric_event event)
686 struct bfa_s *bfa = fabric->fcs->bfa;
688 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
689 bfa_trc(fabric->fcs, event);
691 switch (event) {
692 case BFA_FCS_FABRIC_SM_STOPCOMP:
693 if (bfa_fcport_get_topology(bfa) == BFA_PORT_TOPOLOGY_LOOP) {
694 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_created);
695 } else {
696 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_cleanup);
697 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_LOGOUT);
699 break;
701 case BFA_FCS_FABRIC_SM_LINK_UP:
702 break;
704 case BFA_FCS_FABRIC_SM_LINK_DOWN:
705 if (bfa_fcport_get_topology(bfa) == BFA_PORT_TOPOLOGY_LOOP)
706 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_created);
707 else
708 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_cleanup);
709 break;
711 default:
712 bfa_sm_fault(fabric->fcs, event);
717 * Fabric is being stopped, cleanup without FLOGO
719 static void
720 bfa_fcs_fabric_sm_cleanup(struct bfa_fcs_fabric_s *fabric,
721 enum bfa_fcs_fabric_event event)
723 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
724 bfa_trc(fabric->fcs, event);
726 switch (event) {
727 case BFA_FCS_FABRIC_SM_STOPCOMP:
728 case BFA_FCS_FABRIC_SM_LOGOCOMP:
729 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_created);
730 bfa_wc_down(&(fabric->fcs)->wc);
731 break;
733 case BFA_FCS_FABRIC_SM_LINK_DOWN:
735 * Ignore - can get this event if we get notified about IOC down
736 * before the fabric completion callbk is done.
738 break;
740 default:
741 bfa_sm_fault(fabric->fcs, event);
746 * fcs_fabric_private fabric private functions
749 static void
750 bfa_fcs_fabric_init(struct bfa_fcs_fabric_s *fabric)
752 struct bfa_lport_cfg_s *port_cfg = &fabric->bport.port_cfg;
754 port_cfg->roles = BFA_LPORT_ROLE_FCP_IM;
755 port_cfg->nwwn = fabric->fcs->bfa->ioc.attr->nwwn;
756 port_cfg->pwwn = fabric->fcs->bfa->ioc.attr->pwwn;
760 * Port Symbolic Name Creation for base port.
762 void
763 bfa_fcs_fabric_psymb_init(struct bfa_fcs_fabric_s *fabric)
765 struct bfa_lport_cfg_s *port_cfg = &fabric->bport.port_cfg;
766 char model[BFA_ADAPTER_MODEL_NAME_LEN] = {0};
767 struct bfa_fcs_driver_info_s *driver_info = &fabric->fcs->driver_info;
769 bfa_ioc_get_adapter_model(&fabric->fcs->bfa->ioc, model);
771 /* Model name/number */
772 strlcpy(port_cfg->sym_name.symname, model,
773 BFA_SYMNAME_MAXLEN);
774 strlcat(port_cfg->sym_name.symname, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
775 BFA_SYMNAME_MAXLEN);
777 /* Driver Version */
778 strlcat(port_cfg->sym_name.symname, driver_info->version,
779 BFA_SYMNAME_MAXLEN);
780 strlcat(port_cfg->sym_name.symname, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
781 BFA_SYMNAME_MAXLEN);
783 /* Host machine name */
784 strlcat(port_cfg->sym_name.symname,
785 driver_info->host_machine_name,
786 BFA_SYMNAME_MAXLEN);
787 strlcat(port_cfg->sym_name.symname, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
788 BFA_SYMNAME_MAXLEN);
791 * Host OS Info :
792 * If OS Patch Info is not there, do not truncate any bytes from the
793 * OS name string and instead copy the entire OS info string (64 bytes).
795 if (driver_info->host_os_patch[0] == '\0') {
796 strlcat(port_cfg->sym_name.symname,
797 driver_info->host_os_name,
798 BFA_SYMNAME_MAXLEN);
799 strlcat(port_cfg->sym_name.symname,
800 BFA_FCS_PORT_SYMBNAME_SEPARATOR,
801 BFA_SYMNAME_MAXLEN);
802 } else {
803 strlcat(port_cfg->sym_name.symname,
804 driver_info->host_os_name,
805 BFA_SYMNAME_MAXLEN);
806 strlcat(port_cfg->sym_name.symname,
807 BFA_FCS_PORT_SYMBNAME_SEPARATOR,
808 BFA_SYMNAME_MAXLEN);
810 /* Append host OS Patch Info */
811 strlcat(port_cfg->sym_name.symname,
812 driver_info->host_os_patch,
813 BFA_SYMNAME_MAXLEN);
816 /* null terminate */
817 port_cfg->sym_name.symname[BFA_SYMNAME_MAXLEN - 1] = 0;
821 * Node Symbolic Name Creation for base port and all vports
823 void
824 bfa_fcs_fabric_nsymb_init(struct bfa_fcs_fabric_s *fabric)
826 struct bfa_lport_cfg_s *port_cfg = &fabric->bport.port_cfg;
827 char model[BFA_ADAPTER_MODEL_NAME_LEN] = {0};
828 struct bfa_fcs_driver_info_s *driver_info = &fabric->fcs->driver_info;
830 bfa_ioc_get_adapter_model(&fabric->fcs->bfa->ioc, model);
832 /* Model name/number */
833 strlcpy(port_cfg->node_sym_name.symname, model,
834 BFA_SYMNAME_MAXLEN);
835 strlcat(port_cfg->node_sym_name.symname,
836 BFA_FCS_PORT_SYMBNAME_SEPARATOR,
837 BFA_SYMNAME_MAXLEN);
839 /* Driver Version */
840 strlcat(port_cfg->node_sym_name.symname, (char *)driver_info->version,
841 BFA_SYMNAME_MAXLEN);
842 strlcat(port_cfg->node_sym_name.symname,
843 BFA_FCS_PORT_SYMBNAME_SEPARATOR,
844 BFA_SYMNAME_MAXLEN);
846 /* Host machine name */
847 strlcat(port_cfg->node_sym_name.symname,
848 driver_info->host_machine_name,
849 BFA_SYMNAME_MAXLEN);
850 strlcat(port_cfg->node_sym_name.symname,
851 BFA_FCS_PORT_SYMBNAME_SEPARATOR,
852 BFA_SYMNAME_MAXLEN);
854 /* null terminate */
855 port_cfg->node_sym_name.symname[BFA_SYMNAME_MAXLEN - 1] = 0;
859 * bfa lps login completion callback
861 void
862 bfa_cb_lps_flogi_comp(void *bfad, void *uarg, bfa_status_t status)
864 struct bfa_fcs_fabric_s *fabric = uarg;
866 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
867 bfa_trc(fabric->fcs, status);
869 switch (status) {
870 case BFA_STATUS_OK:
871 fabric->stats.flogi_accepts++;
872 break;
874 case BFA_STATUS_INVALID_MAC:
875 /* Only for CNA */
876 fabric->stats.flogi_acc_err++;
877 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_RETRY_OP);
879 return;
881 case BFA_STATUS_EPROTOCOL:
882 switch (fabric->lps->ext_status) {
883 case BFA_EPROTO_BAD_ACCEPT:
884 fabric->stats.flogi_acc_err++;
885 break;
887 case BFA_EPROTO_UNKNOWN_RSP:
888 fabric->stats.flogi_unknown_rsp++;
889 break;
891 default:
892 break;
894 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_RETRY_OP);
896 return;
898 case BFA_STATUS_FABRIC_RJT:
899 fabric->stats.flogi_rejects++;
900 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_RETRY_OP);
901 return;
903 default:
904 fabric->stats.flogi_rsp_err++;
905 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_RETRY_OP);
906 return;
909 fabric->bb_credit = fabric->lps->pr_bbcred;
910 bfa_trc(fabric->fcs, fabric->bb_credit);
912 if (!(fabric->lps->brcd_switch))
913 fabric->fabric_name = fabric->lps->pr_nwwn;
916 * Check port type. It should be 1 = F-port.
918 if (fabric->lps->fport) {
919 fabric->bport.pid = fabric->lps->lp_pid;
920 fabric->is_npiv = fabric->lps->npiv_en;
921 fabric->is_auth = fabric->lps->auth_req;
922 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_CONT_OP);
923 } else {
925 * Nport-2-Nport direct attached
927 fabric->bport.port_topo.pn2n.rem_port_wwn =
928 fabric->lps->pr_pwwn;
929 fabric->fab_type = BFA_FCS_FABRIC_N2N;
930 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_NO_FABRIC);
933 bfa_trc(fabric->fcs, fabric->bport.pid);
934 bfa_trc(fabric->fcs, fabric->is_npiv);
935 bfa_trc(fabric->fcs, fabric->is_auth);
938 * Allocate and send FLOGI.
940 static void
941 bfa_fcs_fabric_login(struct bfa_fcs_fabric_s *fabric)
943 struct bfa_s *bfa = fabric->fcs->bfa;
944 struct bfa_lport_cfg_s *pcfg = &fabric->bport.port_cfg;
945 u8 alpa = 0;
948 bfa_lps_flogi(fabric->lps, fabric, alpa, bfa_fcport_get_maxfrsize(bfa),
949 pcfg->pwwn, pcfg->nwwn, fabric->auth_reqd);
951 fabric->stats.flogi_sent++;
954 static void
955 bfa_fcs_fabric_notify_online(struct bfa_fcs_fabric_s *fabric)
957 struct bfa_fcs_vport_s *vport;
958 struct list_head *qe, *qen;
960 bfa_trc(fabric->fcs, fabric->fabric_name);
962 bfa_fcs_fabric_set_opertype(fabric);
963 fabric->stats.fabric_onlines++;
966 * notify online event to base and then virtual ports
968 bfa_fcs_lport_online(&fabric->bport);
970 list_for_each_safe(qe, qen, &fabric->vport_q) {
971 vport = (struct bfa_fcs_vport_s *) qe;
972 bfa_fcs_vport_online(vport);
976 static void
977 bfa_fcs_fabric_notify_offline(struct bfa_fcs_fabric_s *fabric)
979 struct bfa_fcs_vport_s *vport;
980 struct list_head *qe, *qen;
982 bfa_trc(fabric->fcs, fabric->fabric_name);
983 fabric->stats.fabric_offlines++;
986 * notify offline event first to vports and then base port.
988 list_for_each_safe(qe, qen, &fabric->vport_q) {
989 vport = (struct bfa_fcs_vport_s *) qe;
990 bfa_fcs_vport_offline(vport);
993 bfa_fcs_lport_offline(&fabric->bport);
995 fabric->fabric_name = 0;
996 fabric->fabric_ip_addr[0] = 0;
999 static void
1000 bfa_fcs_fabric_delay(void *cbarg)
1002 struct bfa_fcs_fabric_s *fabric = cbarg;
1004 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_DELAYED);
1008 * Stop all vports and wait for vport stop completions.
1010 static void
1011 bfa_fcs_fabric_stop(struct bfa_fcs_fabric_s *fabric)
1013 struct bfa_fcs_vport_s *vport;
1014 struct list_head *qe, *qen;
1016 bfa_wc_init(&fabric->stop_wc, bfa_fcs_fabric_stop_comp, fabric);
1018 list_for_each_safe(qe, qen, &fabric->vport_q) {
1019 vport = (struct bfa_fcs_vport_s *) qe;
1020 bfa_wc_up(&fabric->stop_wc);
1021 bfa_fcs_vport_fcs_stop(vport);
1024 bfa_wc_up(&fabric->stop_wc);
1025 bfa_fcs_lport_stop(&fabric->bport);
1026 bfa_wc_wait(&fabric->stop_wc);
1030 * Delete all vports and wait for vport delete completions.
1032 static void
1033 bfa_fcs_fabric_delete(struct bfa_fcs_fabric_s *fabric)
1035 struct bfa_fcs_vport_s *vport;
1036 struct list_head *qe, *qen;
1038 list_for_each_safe(qe, qen, &fabric->vport_q) {
1039 vport = (struct bfa_fcs_vport_s *) qe;
1040 bfa_fcs_vport_fcs_delete(vport);
1043 bfa_fcs_lport_delete(&fabric->bport);
1044 bfa_wc_wait(&fabric->wc);
1047 static void
1048 bfa_fcs_fabric_delete_comp(void *cbarg)
1050 struct bfa_fcs_fabric_s *fabric = cbarg;
1052 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_DELCOMP);
1055 static void
1056 bfa_fcs_fabric_stop_comp(void *cbarg)
1058 struct bfa_fcs_fabric_s *fabric = cbarg;
1060 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_STOPCOMP);
1064 * fcs_fabric_public fabric public functions
1068 * Fabric module stop -- stop FCS actions
1070 void
1071 bfa_fcs_fabric_modstop(struct bfa_fcs_s *fcs)
1073 struct bfa_fcs_fabric_s *fabric;
1075 bfa_trc(fcs, 0);
1076 fabric = &fcs->fabric;
1077 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_STOP);
1081 * Fabric module start -- kick starts FCS actions
1083 void
1084 bfa_fcs_fabric_modstart(struct bfa_fcs_s *fcs)
1086 struct bfa_fcs_fabric_s *fabric;
1088 bfa_trc(fcs, 0);
1089 fabric = &fcs->fabric;
1090 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_START);
1095 * Link up notification from BFA physical port module.
1097 void
1098 bfa_fcs_fabric_link_up(struct bfa_fcs_fabric_s *fabric)
1100 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
1101 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_LINK_UP);
1105 * Link down notification from BFA physical port module.
1107 void
1108 bfa_fcs_fabric_link_down(struct bfa_fcs_fabric_s *fabric)
1110 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
1111 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_LINK_DOWN);
1115 * A child vport is being created in the fabric.
1117 * Call from vport module at vport creation. A list of base port and vports
1118 * belonging to a fabric is maintained to propagate link events.
1120 * param[in] fabric - Fabric instance. This can be a base fabric or vf.
1121 * param[in] vport - Vport being created.
1123 * @return None (always succeeds)
1125 void
1126 bfa_fcs_fabric_addvport(struct bfa_fcs_fabric_s *fabric,
1127 struct bfa_fcs_vport_s *vport)
1130 * - add vport to fabric's vport_q
1132 bfa_trc(fabric->fcs, fabric->vf_id);
1134 list_add_tail(&vport->qe, &fabric->vport_q);
1135 fabric->num_vports++;
1136 bfa_wc_up(&fabric->wc);
1140 * A child vport is being deleted from fabric.
1142 * Vport is being deleted.
1144 void
1145 bfa_fcs_fabric_delvport(struct bfa_fcs_fabric_s *fabric,
1146 struct bfa_fcs_vport_s *vport)
1148 list_del(&vport->qe);
1149 fabric->num_vports--;
1150 bfa_wc_down(&fabric->wc);
1155 * Lookup for a vport within a fabric given its pwwn
1157 struct bfa_fcs_vport_s *
1158 bfa_fcs_fabric_vport_lookup(struct bfa_fcs_fabric_s *fabric, wwn_t pwwn)
1160 struct bfa_fcs_vport_s *vport;
1161 struct list_head *qe;
1163 list_for_each(qe, &fabric->vport_q) {
1164 vport = (struct bfa_fcs_vport_s *) qe;
1165 if (bfa_fcs_lport_get_pwwn(&vport->lport) == pwwn)
1166 return vport;
1169 return NULL;
1174 * Get OUI of the attached switch.
1176 * Note : Use of this function should be avoided as much as possible.
1177 * This function should be used only if there is any requirement
1178 * to check for FOS version below 6.3.
1179 * To check if the attached fabric is a brocade fabric, use
1180 * bfa_lps_is_brcd_fabric() which works for FOS versions 6.3
1181 * or above only.
1185 bfa_fcs_fabric_get_switch_oui(struct bfa_fcs_fabric_s *fabric)
1187 wwn_t fab_nwwn;
1188 u8 *tmp;
1189 u16 oui;
1191 fab_nwwn = fabric->lps->pr_nwwn;
1193 tmp = (u8 *)&fab_nwwn;
1194 oui = (tmp[3] << 8) | tmp[4];
1196 return oui;
1199 * Unsolicited frame receive handling.
1201 void
1202 bfa_fcs_fabric_uf_recv(struct bfa_fcs_fabric_s *fabric, struct fchs_s *fchs,
1203 u16 len)
1205 u32 pid = fchs->d_id;
1206 struct bfa_fcs_vport_s *vport;
1207 struct list_head *qe;
1208 struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
1209 struct fc_logi_s *flogi = (struct fc_logi_s *) els_cmd;
1211 bfa_trc(fabric->fcs, len);
1212 bfa_trc(fabric->fcs, pid);
1215 * Look for our own FLOGI frames being looped back. This means an
1216 * external loopback cable is in place. Our own FLOGI frames are
1217 * sometimes looped back when switch port gets temporarily bypassed.
1219 if ((pid == bfa_ntoh3b(FC_FABRIC_PORT)) &&
1220 (els_cmd->els_code == FC_ELS_FLOGI) &&
1221 (flogi->port_name == bfa_fcs_lport_get_pwwn(&fabric->bport))) {
1222 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_LOOPBACK);
1223 return;
1227 * FLOGI/EVFP exchanges should be consumed by base fabric.
1229 if (fchs->d_id == bfa_hton3b(FC_FABRIC_PORT)) {
1230 bfa_trc(fabric->fcs, pid);
1231 bfa_fcs_fabric_process_uf(fabric, fchs, len);
1232 return;
1235 if (fabric->bport.pid == pid) {
1237 * All authentication frames should be routed to auth
1239 bfa_trc(fabric->fcs, els_cmd->els_code);
1240 if (els_cmd->els_code == FC_ELS_AUTH) {
1241 bfa_trc(fabric->fcs, els_cmd->els_code);
1242 return;
1245 bfa_trc(fabric->fcs, *(u8 *) ((u8 *) fchs));
1246 bfa_fcs_lport_uf_recv(&fabric->bport, fchs, len);
1247 return;
1251 * look for a matching local port ID
1253 list_for_each(qe, &fabric->vport_q) {
1254 vport = (struct bfa_fcs_vport_s *) qe;
1255 if (vport->lport.pid == pid) {
1256 bfa_fcs_lport_uf_recv(&vport->lport, fchs, len);
1257 return;
1261 if (!bfa_fcs_fabric_is_switched(fabric))
1262 bfa_fcs_lport_uf_recv(&fabric->bport, fchs, len);
1264 bfa_trc(fabric->fcs, fchs->type);
1268 * Unsolicited frames to be processed by fabric.
1270 static void
1271 bfa_fcs_fabric_process_uf(struct bfa_fcs_fabric_s *fabric, struct fchs_s *fchs,
1272 u16 len)
1274 struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
1276 bfa_trc(fabric->fcs, els_cmd->els_code);
1278 switch (els_cmd->els_code) {
1279 case FC_ELS_FLOGI:
1280 bfa_fcs_fabric_process_flogi(fabric, fchs, len);
1281 break;
1283 default:
1285 * need to generate a LS_RJT
1287 break;
1292 * Process incoming FLOGI
1294 static void
1295 bfa_fcs_fabric_process_flogi(struct bfa_fcs_fabric_s *fabric,
1296 struct fchs_s *fchs, u16 len)
1298 struct fc_logi_s *flogi = (struct fc_logi_s *) (fchs + 1);
1299 struct bfa_fcs_lport_s *bport = &fabric->bport;
1301 bfa_trc(fabric->fcs, fchs->s_id);
1303 fabric->stats.flogi_rcvd++;
1305 * Check port type. It should be 0 = n-port.
1307 if (flogi->csp.port_type) {
1309 * @todo: may need to send a LS_RJT
1311 bfa_trc(fabric->fcs, flogi->port_name);
1312 fabric->stats.flogi_rejected++;
1313 return;
1316 fabric->bb_credit = be16_to_cpu(flogi->csp.bbcred);
1317 bport->port_topo.pn2n.rem_port_wwn = flogi->port_name;
1318 bport->port_topo.pn2n.reply_oxid = fchs->ox_id;
1321 * Send a Flogi Acc
1323 bfa_fcs_fabric_send_flogi_acc(fabric);
1324 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_NO_FABRIC);
1327 static void
1328 bfa_fcs_fabric_send_flogi_acc(struct bfa_fcs_fabric_s *fabric)
1330 struct bfa_lport_cfg_s *pcfg = &fabric->bport.port_cfg;
1331 struct bfa_fcs_lport_n2n_s *n2n_port = &fabric->bport.port_topo.pn2n;
1332 struct bfa_s *bfa = fabric->fcs->bfa;
1333 struct bfa_fcxp_s *fcxp;
1334 u16 reqlen;
1335 struct fchs_s fchs;
1337 fcxp = bfa_fcs_fcxp_alloc(fabric->fcs, BFA_FALSE);
1339 * Do not expect this failure -- expect remote node to retry
1341 if (!fcxp)
1342 return;
1344 reqlen = fc_flogi_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
1345 bfa_hton3b(FC_FABRIC_PORT),
1346 n2n_port->reply_oxid, pcfg->pwwn,
1347 pcfg->nwwn,
1348 bfa_fcport_get_maxfrsize(bfa),
1349 bfa_fcport_get_rx_bbcredit(bfa), 0);
1351 bfa_fcxp_send(fcxp, NULL, fabric->vf_id, fabric->lps->bfa_tag,
1352 BFA_FALSE, FC_CLASS_3,
1353 reqlen, &fchs, bfa_fcs_fabric_flogiacc_comp, fabric,
1354 FC_MAX_PDUSZ, 0);
1358 * Flogi Acc completion callback.
1360 static void
1361 bfa_fcs_fabric_flogiacc_comp(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
1362 bfa_status_t status, u32 rsp_len,
1363 u32 resid_len, struct fchs_s *rspfchs)
1365 struct bfa_fcs_fabric_s *fabric = cbarg;
1367 bfa_trc(fabric->fcs, status);
1372 * Send AEN notification
1374 static void
1375 bfa_fcs_fabric_aen_post(struct bfa_fcs_lport_s *port,
1376 enum bfa_port_aen_event event)
1378 struct bfad_s *bfad = (struct bfad_s *)port->fabric->fcs->bfad;
1379 struct bfa_aen_entry_s *aen_entry;
1381 bfad_get_aen_entry(bfad, aen_entry);
1382 if (!aen_entry)
1383 return;
1385 aen_entry->aen_data.port.pwwn = bfa_fcs_lport_get_pwwn(port);
1386 aen_entry->aen_data.port.fwwn = bfa_fcs_lport_get_fabric_name(port);
1388 /* Send the AEN notification */
1389 bfad_im_post_vendor_event(aen_entry, bfad, ++port->fcs->fcs_aen_seq,
1390 BFA_AEN_CAT_PORT, event);
1395 * @param[in] fabric - fabric
1396 * @param[in] wwn_t - new fabric name
1398 * @return - none
1400 void
1401 bfa_fcs_fabric_set_fabric_name(struct bfa_fcs_fabric_s *fabric,
1402 wwn_t fabric_name)
1404 struct bfad_s *bfad = (struct bfad_s *)fabric->fcs->bfad;
1405 char pwwn_ptr[BFA_STRING_32];
1406 char fwwn_ptr[BFA_STRING_32];
1408 bfa_trc(fabric->fcs, fabric_name);
1410 if (fabric->fabric_name == 0) {
1412 * With BRCD switches, we don't get Fabric Name in FLOGI.
1413 * Don't generate a fabric name change event in this case.
1415 fabric->fabric_name = fabric_name;
1416 } else {
1417 fabric->fabric_name = fabric_name;
1418 wwn2str(pwwn_ptr, bfa_fcs_lport_get_pwwn(&fabric->bport));
1419 wwn2str(fwwn_ptr,
1420 bfa_fcs_lport_get_fabric_name(&fabric->bport));
1421 BFA_LOG(KERN_WARNING, bfad, bfa_log_level,
1422 "Base port WWN = %s Fabric WWN = %s\n",
1423 pwwn_ptr, fwwn_ptr);
1424 bfa_fcs_fabric_aen_post(&fabric->bport,
1425 BFA_PORT_AEN_FABRIC_NAME_CHANGE);
1429 void
1430 bfa_cb_lps_flogo_comp(void *bfad, void *uarg)
1432 struct bfa_fcs_fabric_s *fabric = uarg;
1433 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_LOGOCOMP);
1437 * Returns FCS vf structure for a given vf_id.
1439 * param[in] vf_id - VF_ID
1441 * return
1442 * If lookup succeeds, retuns fcs vf object, otherwise returns NULL
1444 bfa_fcs_vf_t *
1445 bfa_fcs_vf_lookup(struct bfa_fcs_s *fcs, u16 vf_id)
1447 bfa_trc(fcs, vf_id);
1448 if (vf_id == FC_VF_ID_NULL)
1449 return &fcs->fabric;
1451 return NULL;
1455 * Return the list of local logical ports present in the given VF.
1457 * @param[in] vf vf for which logical ports are returned
1458 * @param[out] lpwwn returned logical port wwn list
1459 * @param[in,out] nlports in:size of lpwwn list;
1460 * out:total elements present,
1461 * actual elements returned is limited by the size
1463 void
1464 bfa_fcs_vf_get_ports(bfa_fcs_vf_t *vf, wwn_t lpwwn[], int *nlports)
1466 struct list_head *qe;
1467 struct bfa_fcs_vport_s *vport;
1468 int i = 0;
1469 struct bfa_fcs_s *fcs;
1471 if (vf == NULL || lpwwn == NULL || *nlports == 0)
1472 return;
1474 fcs = vf->fcs;
1476 bfa_trc(fcs, vf->vf_id);
1477 bfa_trc(fcs, (uint32_t) *nlports);
1479 lpwwn[i++] = vf->bport.port_cfg.pwwn;
1481 list_for_each(qe, &vf->vport_q) {
1482 if (i >= *nlports)
1483 break;
1485 vport = (struct bfa_fcs_vport_s *) qe;
1486 lpwwn[i++] = vport->lport.port_cfg.pwwn;
1489 bfa_trc(fcs, i);
1490 *nlports = i;
1494 * BFA FCS PPORT ( physical port)
1496 static void
1497 bfa_fcs_port_event_handler(void *cbarg, enum bfa_port_linkstate event)
1499 struct bfa_fcs_s *fcs = cbarg;
1501 bfa_trc(fcs, event);
1503 switch (event) {
1504 case BFA_PORT_LINKUP:
1505 bfa_fcs_fabric_link_up(&fcs->fabric);
1506 break;
1508 case BFA_PORT_LINKDOWN:
1509 bfa_fcs_fabric_link_down(&fcs->fabric);
1510 break;
1512 default:
1513 WARN_ON(1);
1518 * BFA FCS UF ( Unsolicited Frames)
1522 * BFA callback for unsolicited frame receive handler.
1524 * @param[in] cbarg callback arg for receive handler
1525 * @param[in] uf unsolicited frame descriptor
1527 * @return None
1529 static void
1530 bfa_fcs_uf_recv(void *cbarg, struct bfa_uf_s *uf)
1532 struct bfa_fcs_s *fcs = (struct bfa_fcs_s *) cbarg;
1533 struct fchs_s *fchs = bfa_uf_get_frmbuf(uf);
1534 u16 len = bfa_uf_get_frmlen(uf);
1535 struct fc_vft_s *vft;
1536 struct bfa_fcs_fabric_s *fabric;
1539 * check for VFT header
1541 if (fchs->routing == FC_RTG_EXT_HDR &&
1542 fchs->cat_info == FC_CAT_VFT_HDR) {
1543 bfa_stats(fcs, uf.tagged);
1544 vft = bfa_uf_get_frmbuf(uf);
1545 if (fcs->port_vfid == vft->vf_id)
1546 fabric = &fcs->fabric;
1547 else
1548 fabric = bfa_fcs_vf_lookup(fcs, (u16) vft->vf_id);
1551 * drop frame if vfid is unknown
1553 if (!fabric) {
1554 WARN_ON(1);
1555 bfa_stats(fcs, uf.vfid_unknown);
1556 bfa_uf_free(uf);
1557 return;
1561 * skip vft header
1563 fchs = (struct fchs_s *) (vft + 1);
1564 len -= sizeof(struct fc_vft_s);
1566 bfa_trc(fcs, vft->vf_id);
1567 } else {
1568 bfa_stats(fcs, uf.untagged);
1569 fabric = &fcs->fabric;
1572 bfa_trc(fcs, ((u32 *) fchs)[0]);
1573 bfa_trc(fcs, ((u32 *) fchs)[1]);
1574 bfa_trc(fcs, ((u32 *) fchs)[2]);
1575 bfa_trc(fcs, ((u32 *) fchs)[3]);
1576 bfa_trc(fcs, ((u32 *) fchs)[4]);
1577 bfa_trc(fcs, ((u32 *) fchs)[5]);
1578 bfa_trc(fcs, len);
1580 bfa_fcs_fabric_uf_recv(fabric, fchs, len);
1581 bfa_uf_free(uf);
1585 * fcs attach -- called once to initialize data structures at driver attach time
1587 void
1588 bfa_fcs_attach(struct bfa_fcs_s *fcs, struct bfa_s *bfa, struct bfad_s *bfad,
1589 bfa_boolean_t min_cfg)
1591 struct bfa_fcs_fabric_s *fabric = &fcs->fabric;
1593 fcs->bfa = bfa;
1594 fcs->bfad = bfad;
1595 fcs->min_cfg = min_cfg;
1596 fcs->num_rport_logins = 0;
1598 bfa->fcs = BFA_TRUE;
1599 fcbuild_init();
1601 bfa_fcport_event_register(fcs->bfa, bfa_fcs_port_event_handler, fcs);
1602 bfa_uf_recv_register(fcs->bfa, bfa_fcs_uf_recv, fcs);
1604 memset(fabric, 0, sizeof(struct bfa_fcs_fabric_s));
1607 * Initialize base fabric.
1609 fabric->fcs = fcs;
1610 INIT_LIST_HEAD(&fabric->vport_q);
1611 INIT_LIST_HEAD(&fabric->vf_q);
1612 fabric->lps = bfa_lps_alloc(fcs->bfa);
1613 WARN_ON(!fabric->lps);
1616 * Initialize fabric delete completion handler. Fabric deletion is
1617 * complete when the last vport delete is complete.
1619 bfa_wc_init(&fabric->wc, bfa_fcs_fabric_delete_comp, fabric);
1620 bfa_wc_up(&fabric->wc); /* For the base port */
1622 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_uninit);
1623 bfa_fcs_lport_attach(&fabric->bport, fabric->fcs, FC_VF_ID_NULL, NULL);