[SCSI] bfa: FCS authentication related changes.
[safe/jmp/linux-2.6] / drivers / scsi / bfa / fabric.c
1 /*
2  * Copyright (c) 2005-2009 Brocade Communications Systems, Inc.
3  * All rights reserved
4  * www.brocade.com
5  *
6  * Linux driver for Brocade Fibre Channel Host Bus Adapter.
7  *
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
11  *
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.
16  */
17
18 /**
19  *  fabric.c Fabric module implementation.
20  */
21
22 #include "fcs_fabric.h"
23 #include "fcs_lport.h"
24 #include "fcs_vport.h"
25 #include "fcs_trcmod.h"
26 #include "fcs_fcxp.h"
27 #include "fcs_auth.h"
28 #include "fcs.h"
29 #include "fcbuild.h"
30 #include <log/bfa_log_fcs.h>
31 #include <aen/bfa_aen_port.h>
32 #include <bfa_svc.h>
33
34 BFA_TRC_FILE(FCS, FABRIC);
35
36 #define BFA_FCS_FABRIC_RETRY_DELAY      (2000)  /* Milliseconds */
37 #define BFA_FCS_FABRIC_CLEANUP_DELAY    (10000) /* Milliseconds */
38
39 #define bfa_fcs_fabric_set_opertype(__fabric) do {             \
40         if (bfa_pport_get_topology((__fabric)->fcs->bfa)       \
41                                 == BFA_PPORT_TOPOLOGY_P2P)     \
42                 (__fabric)->oper_type = BFA_PPORT_TYPE_NPORT;  \
43         else                                                   \
44                 (__fabric)->oper_type = BFA_PPORT_TYPE_NLPORT; \
45 } while (0)
46
47 /*
48  * forward declarations
49  */
50 static void     bfa_fcs_fabric_init(struct bfa_fcs_fabric_s *fabric);
51 static void     bfa_fcs_fabric_login(struct bfa_fcs_fabric_s *fabric);
52 static void     bfa_fcs_fabric_notify_online(struct bfa_fcs_fabric_s *fabric);
53 static void     bfa_fcs_fabric_notify_offline(struct bfa_fcs_fabric_s *fabric);
54 static void     bfa_fcs_fabric_delay(void *cbarg);
55 static void     bfa_fcs_fabric_delete(struct bfa_fcs_fabric_s *fabric);
56 static void     bfa_fcs_fabric_delete_comp(void *cbarg);
57 static void     bfa_fcs_fabric_process_uf(struct bfa_fcs_fabric_s *fabric,
58                                           struct fchs_s *fchs, u16 len);
59 static void     bfa_fcs_fabric_process_flogi(struct bfa_fcs_fabric_s *fabric,
60                                              struct fchs_s *fchs, u16 len);
61 static void     bfa_fcs_fabric_send_flogi_acc(struct bfa_fcs_fabric_s *fabric);
62 static void     bfa_fcs_fabric_flogiacc_comp(void *fcsarg,
63                                              struct bfa_fcxp_s *fcxp,
64                                              void *cbarg, bfa_status_t status,
65                                              u32 rsp_len,
66                                              u32 resid_len,
67                                              struct fchs_s *rspfchs);
68 /**
69  *  fcs_fabric_sm fabric state machine functions
70  */
71
72 /**
73  * Fabric state machine events
74  */
75 enum bfa_fcs_fabric_event {
76         BFA_FCS_FABRIC_SM_CREATE = 1,   /*  fabric create from driver */
77         BFA_FCS_FABRIC_SM_DELETE = 2,   /*  fabric delete from driver */
78         BFA_FCS_FABRIC_SM_LINK_DOWN = 3,        /*  link down from port */
79         BFA_FCS_FABRIC_SM_LINK_UP = 4,  /*  link up from port */
80         BFA_FCS_FABRIC_SM_CONT_OP = 5,  /*  continue op from flogi/auth */
81         BFA_FCS_FABRIC_SM_RETRY_OP = 6, /*  continue op from flogi/auth */
82         BFA_FCS_FABRIC_SM_NO_FABRIC = 7,        /*  no fabric from flogi/auth
83                                                  */
84         BFA_FCS_FABRIC_SM_PERF_EVFP = 8,        /*  perform EVFP from
85                                                  *flogi/auth */
86         BFA_FCS_FABRIC_SM_ISOLATE = 9,  /*  isolate from EVFP processing */
87         BFA_FCS_FABRIC_SM_NO_TAGGING = 10,/*  no VFT tagging from EVFP */
88         BFA_FCS_FABRIC_SM_DELAYED = 11, /*  timeout delay event */
89         BFA_FCS_FABRIC_SM_AUTH_FAILED = 12,     /*  authentication failed */
90         BFA_FCS_FABRIC_SM_AUTH_SUCCESS = 13,    /*  authentication successful
91                                                  */
92         BFA_FCS_FABRIC_SM_DELCOMP = 14, /*  all vports deleted event */
93         BFA_FCS_FABRIC_SM_LOOPBACK = 15,        /*  Received our own FLOGI */
94         BFA_FCS_FABRIC_SM_START = 16,   /*  fabric delete from driver */
95 };
96
97 static void     bfa_fcs_fabric_sm_uninit(struct bfa_fcs_fabric_s *fabric,
98                                          enum bfa_fcs_fabric_event event);
99 static void     bfa_fcs_fabric_sm_created(struct bfa_fcs_fabric_s *fabric,
100                                           enum bfa_fcs_fabric_event event);
101 static void     bfa_fcs_fabric_sm_linkdown(struct bfa_fcs_fabric_s *fabric,
102                                            enum bfa_fcs_fabric_event event);
103 static void     bfa_fcs_fabric_sm_flogi(struct bfa_fcs_fabric_s *fabric,
104                                         enum bfa_fcs_fabric_event event);
105 static void     bfa_fcs_fabric_sm_flogi_retry(struct bfa_fcs_fabric_s *fabric,
106                                               enum bfa_fcs_fabric_event event);
107 static void     bfa_fcs_fabric_sm_auth(struct bfa_fcs_fabric_s *fabric,
108                                        enum bfa_fcs_fabric_event event);
109 static void     bfa_fcs_fabric_sm_auth_failed(struct bfa_fcs_fabric_s *fabric,
110                                               enum bfa_fcs_fabric_event event);
111 static void     bfa_fcs_fabric_sm_loopback(struct bfa_fcs_fabric_s *fabric,
112                                            enum bfa_fcs_fabric_event event);
113 static void     bfa_fcs_fabric_sm_nofabric(struct bfa_fcs_fabric_s *fabric,
114                                            enum bfa_fcs_fabric_event event);
115 static void     bfa_fcs_fabric_sm_online(struct bfa_fcs_fabric_s *fabric,
116                                          enum bfa_fcs_fabric_event event);
117 static void     bfa_fcs_fabric_sm_evfp(struct bfa_fcs_fabric_s *fabric,
118                                        enum bfa_fcs_fabric_event event);
119 static void     bfa_fcs_fabric_sm_evfp_done(struct bfa_fcs_fabric_s *fabric,
120                                             enum bfa_fcs_fabric_event event);
121 static void     bfa_fcs_fabric_sm_isolated(struct bfa_fcs_fabric_s *fabric,
122                                            enum bfa_fcs_fabric_event event);
123 static void     bfa_fcs_fabric_sm_deleting(struct bfa_fcs_fabric_s *fabric,
124                                            enum bfa_fcs_fabric_event event);
125 /**
126  *   Beginning state before fabric creation.
127  */
128 static void
129 bfa_fcs_fabric_sm_uninit(struct bfa_fcs_fabric_s *fabric,
130                          enum bfa_fcs_fabric_event event)
131 {
132         bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
133         bfa_trc(fabric->fcs, event);
134
135         switch (event) {
136         case BFA_FCS_FABRIC_SM_CREATE:
137                 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_created);
138                 bfa_fcs_fabric_init(fabric);
139                 bfa_fcs_lport_init(&fabric->bport, &fabric->bport.port_cfg);
140                 break;
141
142         case BFA_FCS_FABRIC_SM_LINK_UP:
143         case BFA_FCS_FABRIC_SM_LINK_DOWN:
144                 break;
145
146         default:
147                 bfa_sm_fault(fabric->fcs, event);
148         }
149 }
150
151 /**
152  *   Beginning state before fabric creation.
153  */
154 static void
155 bfa_fcs_fabric_sm_created(struct bfa_fcs_fabric_s *fabric,
156                           enum bfa_fcs_fabric_event event)
157 {
158         bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
159         bfa_trc(fabric->fcs, event);
160
161         switch (event) {
162         case BFA_FCS_FABRIC_SM_START:
163                 if (bfa_pport_is_linkup(fabric->fcs->bfa)) {
164                         bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_flogi);
165                         bfa_fcs_fabric_login(fabric);
166                 } else
167                         bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
168                 break;
169
170         case BFA_FCS_FABRIC_SM_LINK_UP:
171         case BFA_FCS_FABRIC_SM_LINK_DOWN:
172                 break;
173
174         case BFA_FCS_FABRIC_SM_DELETE:
175                 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_uninit);
176                 bfa_fcs_modexit_comp(fabric->fcs);
177                 break;
178
179         default:
180                 bfa_sm_fault(fabric->fcs, event);
181         }
182 }
183
184 /**
185  *   Link is down, awaiting LINK UP event from port. This is also the
186  *   first state at fabric creation.
187  */
188 static void
189 bfa_fcs_fabric_sm_linkdown(struct bfa_fcs_fabric_s *fabric,
190                            enum bfa_fcs_fabric_event event)
191 {
192         bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
193         bfa_trc(fabric->fcs, event);
194
195         switch (event) {
196         case BFA_FCS_FABRIC_SM_LINK_UP:
197                 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_flogi);
198                 bfa_fcs_fabric_login(fabric);
199                 break;
200
201         case BFA_FCS_FABRIC_SM_RETRY_OP:
202                 break;
203
204         case BFA_FCS_FABRIC_SM_DELETE:
205                 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
206                 bfa_fcs_fabric_delete(fabric);
207                 break;
208
209         default:
210                 bfa_sm_fault(fabric->fcs, event);
211         }
212 }
213
214 /**
215  *   FLOGI is in progress, awaiting FLOGI reply.
216  */
217 static void
218 bfa_fcs_fabric_sm_flogi(struct bfa_fcs_fabric_s *fabric,
219                         enum bfa_fcs_fabric_event event)
220 {
221         bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
222         bfa_trc(fabric->fcs, event);
223
224         switch (event) {
225         case BFA_FCS_FABRIC_SM_CONT_OP:
226
227                 bfa_pport_set_tx_bbcredit(fabric->fcs->bfa, fabric->bb_credit);
228                 fabric->fab_type = BFA_FCS_FABRIC_SWITCHED;
229
230                 if (fabric->auth_reqd && fabric->is_auth) {
231                         bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_auth);
232                         bfa_trc(fabric->fcs, event);
233                 } else {
234                         bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_online);
235                         bfa_fcs_fabric_notify_online(fabric);
236                 }
237                 break;
238
239         case BFA_FCS_FABRIC_SM_RETRY_OP:
240                 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_flogi_retry);
241                 bfa_timer_start(fabric->fcs->bfa, &fabric->delay_timer,
242                                 bfa_fcs_fabric_delay, fabric,
243                                 BFA_FCS_FABRIC_RETRY_DELAY);
244                 break;
245
246         case BFA_FCS_FABRIC_SM_LOOPBACK:
247                 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_loopback);
248                 bfa_lps_discard(fabric->lps);
249                 bfa_fcs_fabric_set_opertype(fabric);
250                 break;
251
252         case BFA_FCS_FABRIC_SM_NO_FABRIC:
253                 fabric->fab_type = BFA_FCS_FABRIC_N2N;
254                 bfa_pport_set_tx_bbcredit(fabric->fcs->bfa, fabric->bb_credit);
255                 bfa_fcs_fabric_notify_online(fabric);
256                 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_nofabric);
257                 break;
258
259         case BFA_FCS_FABRIC_SM_LINK_DOWN:
260                 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
261                 bfa_lps_discard(fabric->lps);
262                 break;
263
264         case BFA_FCS_FABRIC_SM_DELETE:
265                 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
266                 bfa_lps_discard(fabric->lps);
267                 bfa_fcs_fabric_delete(fabric);
268                 break;
269
270         default:
271                 bfa_sm_fault(fabric->fcs, event);
272         }
273 }
274
275
276 static void
277 bfa_fcs_fabric_sm_flogi_retry(struct bfa_fcs_fabric_s *fabric,
278                               enum bfa_fcs_fabric_event event)
279 {
280         bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
281         bfa_trc(fabric->fcs, event);
282
283         switch (event) {
284         case BFA_FCS_FABRIC_SM_DELAYED:
285                 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_flogi);
286                 bfa_fcs_fabric_login(fabric);
287                 break;
288
289         case BFA_FCS_FABRIC_SM_LINK_DOWN:
290                 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
291                 bfa_timer_stop(&fabric->delay_timer);
292                 break;
293
294         case BFA_FCS_FABRIC_SM_DELETE:
295                 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
296                 bfa_timer_stop(&fabric->delay_timer);
297                 bfa_fcs_fabric_delete(fabric);
298                 break;
299
300         default:
301                 bfa_sm_fault(fabric->fcs, event);
302         }
303 }
304
305 /**
306  *   Authentication is in progress, awaiting authentication results.
307  */
308 static void
309 bfa_fcs_fabric_sm_auth(struct bfa_fcs_fabric_s *fabric,
310                        enum bfa_fcs_fabric_event event)
311 {
312         bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
313         bfa_trc(fabric->fcs, event);
314
315         switch (event) {
316         case BFA_FCS_FABRIC_SM_AUTH_FAILED:
317                 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_auth_failed);
318                 bfa_lps_discard(fabric->lps);
319                 break;
320
321         case BFA_FCS_FABRIC_SM_AUTH_SUCCESS:
322                 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_online);
323                 bfa_fcs_fabric_notify_online(fabric);
324                 break;
325
326         case BFA_FCS_FABRIC_SM_PERF_EVFP:
327                 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_evfp);
328                 break;
329
330         case BFA_FCS_FABRIC_SM_LINK_DOWN:
331                 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
332                 bfa_lps_discard(fabric->lps);
333                 break;
334
335         case BFA_FCS_FABRIC_SM_DELETE:
336                 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
337                 bfa_fcs_fabric_delete(fabric);
338                 break;
339
340         default:
341                 bfa_sm_fault(fabric->fcs, event);
342         }
343 }
344
345 /**
346  *   Authentication failed
347  */
348 static void
349 bfa_fcs_fabric_sm_auth_failed(struct bfa_fcs_fabric_s *fabric,
350                               enum bfa_fcs_fabric_event event)
351 {
352         bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
353         bfa_trc(fabric->fcs, event);
354
355         switch (event) {
356         case BFA_FCS_FABRIC_SM_LINK_DOWN:
357                 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
358                 bfa_fcs_fabric_notify_offline(fabric);
359                 break;
360
361         case BFA_FCS_FABRIC_SM_DELETE:
362                 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
363                 bfa_fcs_fabric_delete(fabric);
364                 break;
365
366         default:
367                 bfa_sm_fault(fabric->fcs, event);
368         }
369 }
370
371 /**
372  *   Port is in loopback mode.
373  */
374 static void
375 bfa_fcs_fabric_sm_loopback(struct bfa_fcs_fabric_s *fabric,
376                            enum bfa_fcs_fabric_event event)
377 {
378         bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
379         bfa_trc(fabric->fcs, event);
380
381         switch (event) {
382         case BFA_FCS_FABRIC_SM_LINK_DOWN:
383                 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
384                 bfa_fcs_fabric_notify_offline(fabric);
385                 break;
386
387         case BFA_FCS_FABRIC_SM_DELETE:
388                 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
389                 bfa_fcs_fabric_delete(fabric);
390                 break;
391
392         default:
393                 bfa_sm_fault(fabric->fcs, event);
394         }
395 }
396
397 /**
398  *   There is no attached fabric - private loop or NPort-to-NPort topology.
399  */
400 static void
401 bfa_fcs_fabric_sm_nofabric(struct bfa_fcs_fabric_s *fabric,
402                            enum bfa_fcs_fabric_event event)
403 {
404         bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
405         bfa_trc(fabric->fcs, event);
406
407         switch (event) {
408         case BFA_FCS_FABRIC_SM_LINK_DOWN:
409                 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
410                 bfa_lps_discard(fabric->lps);
411                 bfa_fcs_fabric_notify_offline(fabric);
412                 break;
413
414         case BFA_FCS_FABRIC_SM_DELETE:
415                 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
416                 bfa_fcs_fabric_delete(fabric);
417                 break;
418
419         case BFA_FCS_FABRIC_SM_NO_FABRIC:
420                 bfa_trc(fabric->fcs, fabric->bb_credit);
421                 bfa_pport_set_tx_bbcredit(fabric->fcs->bfa, fabric->bb_credit);
422                 break;
423
424         default:
425                 bfa_sm_fault(fabric->fcs, event);
426         }
427 }
428
429 /**
430  *   Fabric is online - normal operating state.
431  */
432 static void
433 bfa_fcs_fabric_sm_online(struct bfa_fcs_fabric_s *fabric,
434                          enum bfa_fcs_fabric_event event)
435 {
436         bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
437         bfa_trc(fabric->fcs, event);
438
439         switch (event) {
440         case BFA_FCS_FABRIC_SM_LINK_DOWN:
441                 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
442                 bfa_lps_discard(fabric->lps);
443                 bfa_fcs_fabric_notify_offline(fabric);
444                 break;
445
446         case BFA_FCS_FABRIC_SM_DELETE:
447                 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
448                 bfa_fcs_fabric_delete(fabric);
449                 break;
450
451         case BFA_FCS_FABRIC_SM_AUTH_FAILED:
452                 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_auth_failed);
453                 bfa_lps_discard(fabric->lps);
454                 break;
455
456         case BFA_FCS_FABRIC_SM_AUTH_SUCCESS:
457                 break;
458
459         default:
460                 bfa_sm_fault(fabric->fcs, event);
461         }
462 }
463
464 /**
465  *   Exchanging virtual fabric parameters.
466  */
467 static void
468 bfa_fcs_fabric_sm_evfp(struct bfa_fcs_fabric_s *fabric,
469                        enum bfa_fcs_fabric_event event)
470 {
471         bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
472         bfa_trc(fabric->fcs, event);
473
474         switch (event) {
475         case BFA_FCS_FABRIC_SM_CONT_OP:
476                 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_evfp_done);
477                 break;
478
479         case BFA_FCS_FABRIC_SM_ISOLATE:
480                 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_isolated);
481                 break;
482
483         default:
484                 bfa_sm_fault(fabric->fcs, event);
485         }
486 }
487
488 /**
489  *   EVFP exchange complete and VFT tagging is enabled.
490  */
491 static void
492 bfa_fcs_fabric_sm_evfp_done(struct bfa_fcs_fabric_s *fabric,
493                             enum bfa_fcs_fabric_event event)
494 {
495         bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
496         bfa_trc(fabric->fcs, event);
497 }
498
499 /**
500  *   Port is isolated after EVFP exchange due to VF_ID mismatch (N and F).
501  */
502 static void
503 bfa_fcs_fabric_sm_isolated(struct bfa_fcs_fabric_s *fabric,
504                            enum bfa_fcs_fabric_event event)
505 {
506         bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
507         bfa_trc(fabric->fcs, event);
508
509         bfa_log(fabric->fcs->logm, BFA_LOG_FCS_FABRIC_ISOLATED,
510                 fabric->bport.port_cfg.pwwn, fabric->fcs->port_vfid,
511                 fabric->event_arg.swp_vfid);
512 }
513
514 /**
515  *   Fabric is being deleted, awaiting vport delete completions.
516  */
517 static void
518 bfa_fcs_fabric_sm_deleting(struct bfa_fcs_fabric_s *fabric,
519                            enum bfa_fcs_fabric_event event)
520 {
521         bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
522         bfa_trc(fabric->fcs, event);
523
524         switch (event) {
525         case BFA_FCS_FABRIC_SM_DELCOMP:
526                 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_uninit);
527                 bfa_fcs_modexit_comp(fabric->fcs);
528                 break;
529
530         case BFA_FCS_FABRIC_SM_LINK_UP:
531                 break;
532
533         case BFA_FCS_FABRIC_SM_LINK_DOWN:
534                 bfa_fcs_fabric_notify_offline(fabric);
535                 break;
536
537         default:
538                 bfa_sm_fault(fabric->fcs, event);
539         }
540 }
541
542
543
544 /**
545  *  fcs_fabric_private fabric private functions
546  */
547
548 static void
549 bfa_fcs_fabric_init(struct bfa_fcs_fabric_s *fabric)
550 {
551         struct bfa_port_cfg_s *port_cfg = &fabric->bport.port_cfg;
552
553         port_cfg->roles = BFA_PORT_ROLE_FCP_IM;
554         port_cfg->nwwn = bfa_ioc_get_nwwn(&fabric->fcs->bfa->ioc);
555         port_cfg->pwwn = bfa_ioc_get_pwwn(&fabric->fcs->bfa->ioc);
556 }
557
558 /**
559  * Port Symbolic Name Creation for base port.
560  */
561 void
562 bfa_fcs_fabric_psymb_init(struct bfa_fcs_fabric_s *fabric)
563 {
564         struct bfa_port_cfg_s *port_cfg = &fabric->bport.port_cfg;
565         struct bfa_adapter_attr_s adapter_attr;
566         struct bfa_fcs_driver_info_s *driver_info = &fabric->fcs->driver_info;
567
568         bfa_os_memset((void *)&adapter_attr, 0,
569                       sizeof(struct bfa_adapter_attr_s));
570         bfa_ioc_get_adapter_attr(&fabric->fcs->bfa->ioc, &adapter_attr);
571
572         /*
573          * Model name/number
574          */
575         strncpy((char *)&port_cfg->sym_name, adapter_attr.model,
576                 BFA_FCS_PORT_SYMBNAME_MODEL_SZ);
577         strncat((char *)&port_cfg->sym_name, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
578                 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
579
580         /*
581          * Driver Version
582          */
583         strncat((char *)&port_cfg->sym_name, (char *)driver_info->version,
584                 BFA_FCS_PORT_SYMBNAME_VERSION_SZ);
585         strncat((char *)&port_cfg->sym_name, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
586                 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
587
588         /*
589          * Host machine name
590          */
591         strncat((char *)&port_cfg->sym_name,
592                 (char *)driver_info->host_machine_name,
593                 BFA_FCS_PORT_SYMBNAME_MACHINENAME_SZ);
594         strncat((char *)&port_cfg->sym_name, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
595                 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
596
597         /*
598          * Host OS Info :
599          * If OS Patch Info is not there, do not truncate any bytes from the
600          * OS name string and instead copy the entire OS info string (64 bytes).
601          */
602         if (driver_info->host_os_patch[0] == '\0') {
603                 strncat((char *)&port_cfg->sym_name,
604                         (char *)driver_info->host_os_name, BFA_FCS_OS_STR_LEN);
605                 strncat((char *)&port_cfg->sym_name,
606                         BFA_FCS_PORT_SYMBNAME_SEPARATOR,
607                         sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
608         } else {
609                 strncat((char *)&port_cfg->sym_name,
610                         (char *)driver_info->host_os_name,
611                         BFA_FCS_PORT_SYMBNAME_OSINFO_SZ);
612                 strncat((char *)&port_cfg->sym_name,
613                         BFA_FCS_PORT_SYMBNAME_SEPARATOR,
614                         sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
615
616                 /*
617                  * Append host OS Patch Info
618                  */
619                 strncat((char *)&port_cfg->sym_name,
620                         (char *)driver_info->host_os_patch,
621                         BFA_FCS_PORT_SYMBNAME_OSPATCH_SZ);
622         }
623
624         /*
625          * null terminate
626          */
627         port_cfg->sym_name.symname[BFA_SYMNAME_MAXLEN - 1] = 0;
628 }
629
630 /**
631  * bfa lps login completion callback
632  */
633 void
634 bfa_cb_lps_flogi_comp(void *bfad, void *uarg, bfa_status_t status)
635 {
636         struct bfa_fcs_fabric_s *fabric = uarg;
637
638         bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
639         bfa_trc(fabric->fcs, status);
640
641         switch (status) {
642         case BFA_STATUS_OK:
643                 fabric->stats.flogi_accepts++;
644                 break;
645
646         case BFA_STATUS_INVALID_MAC:
647                 /*
648                  * Only for CNA
649                  */
650                 fabric->stats.flogi_acc_err++;
651                 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_RETRY_OP);
652
653                 return;
654
655         case BFA_STATUS_EPROTOCOL:
656                 switch (bfa_lps_get_extstatus(fabric->lps)) {
657                 case BFA_EPROTO_BAD_ACCEPT:
658                         fabric->stats.flogi_acc_err++;
659                         break;
660
661                 case BFA_EPROTO_UNKNOWN_RSP:
662                         fabric->stats.flogi_unknown_rsp++;
663                         break;
664
665                 default:
666                         break;
667                 }
668                 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_RETRY_OP);
669
670                 return;
671
672         case BFA_STATUS_FABRIC_RJT:
673                 fabric->stats.flogi_rejects++;
674                 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_RETRY_OP);
675                 return;
676
677         default:
678                 fabric->stats.flogi_rsp_err++;
679                 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_RETRY_OP);
680                 return;
681         }
682
683         fabric->bb_credit = bfa_lps_get_peer_bbcredit(fabric->lps);
684         bfa_trc(fabric->fcs, fabric->bb_credit);
685
686         if (!bfa_lps_is_brcd_fabric(fabric->lps))
687                 fabric->fabric_name = bfa_lps_get_peer_nwwn(fabric->lps);
688
689         /*
690          * Check port type. It should be 1 = F-port.
691          */
692         if (bfa_lps_is_fport(fabric->lps)) {
693                 fabric->bport.pid = bfa_lps_get_pid(fabric->lps);
694                 fabric->is_npiv = bfa_lps_is_npiv_en(fabric->lps);
695                 fabric->is_auth = bfa_lps_is_authreq(fabric->lps);
696                 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_CONT_OP);
697         } else {
698                 /*
699                  * Nport-2-Nport direct attached
700                  */
701                 fabric->bport.port_topo.pn2n.rem_port_wwn =
702                         bfa_lps_get_peer_pwwn(fabric->lps);
703                 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_NO_FABRIC);
704         }
705
706         bfa_trc(fabric->fcs, fabric->bport.pid);
707         bfa_trc(fabric->fcs, fabric->is_npiv);
708         bfa_trc(fabric->fcs, fabric->is_auth);
709 }
710
711 /**
712  *              Allocate and send FLOGI.
713  */
714 static void
715 bfa_fcs_fabric_login(struct bfa_fcs_fabric_s *fabric)
716 {
717         struct bfa_s   *bfa = fabric->fcs->bfa;
718         struct bfa_port_cfg_s *pcfg = &fabric->bport.port_cfg;
719         u8         alpa = 0;
720
721         if (bfa_pport_get_topology(bfa) == BFA_PPORT_TOPOLOGY_LOOP)
722                 alpa = bfa_pport_get_myalpa(bfa);
723
724         bfa_lps_flogi(fabric->lps, fabric, alpa, bfa_pport_get_maxfrsize(bfa),
725                       pcfg->pwwn, pcfg->nwwn, fabric->auth_reqd);
726
727         fabric->stats.flogi_sent++;
728 }
729
730 static void
731 bfa_fcs_fabric_notify_online(struct bfa_fcs_fabric_s *fabric)
732 {
733         struct bfa_fcs_vport_s *vport;
734         struct list_head *qe, *qen;
735
736         bfa_trc(fabric->fcs, fabric->fabric_name);
737
738         bfa_fcs_fabric_set_opertype(fabric);
739         fabric->stats.fabric_onlines++;
740
741         /**
742          * notify online event to base and then virtual ports
743          */
744         bfa_fcs_port_online(&fabric->bport);
745
746         list_for_each_safe(qe, qen, &fabric->vport_q) {
747                 vport = (struct bfa_fcs_vport_s *)qe;
748                 bfa_fcs_vport_online(vport);
749         }
750 }
751
752 static void
753 bfa_fcs_fabric_notify_offline(struct bfa_fcs_fabric_s *fabric)
754 {
755         struct bfa_fcs_vport_s *vport;
756         struct list_head *qe, *qen;
757
758         bfa_trc(fabric->fcs, fabric->fabric_name);
759         fabric->stats.fabric_offlines++;
760
761         /**
762          * notify offline event first to vports and then base port.
763          */
764         list_for_each_safe(qe, qen, &fabric->vport_q) {
765                 vport = (struct bfa_fcs_vport_s *)qe;
766                 bfa_fcs_vport_offline(vport);
767         }
768
769         bfa_fcs_port_offline(&fabric->bport);
770
771         fabric->fabric_name = 0;
772         fabric->fabric_ip_addr[0] = 0;
773 }
774
775 static void
776 bfa_fcs_fabric_delay(void *cbarg)
777 {
778         struct bfa_fcs_fabric_s *fabric = cbarg;
779
780         bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_DELAYED);
781 }
782
783 /**
784  * Delete all vports and wait for vport delete completions.
785  */
786 static void
787 bfa_fcs_fabric_delete(struct bfa_fcs_fabric_s *fabric)
788 {
789         struct bfa_fcs_vport_s *vport;
790         struct list_head *qe, *qen;
791
792         list_for_each_safe(qe, qen, &fabric->vport_q) {
793                 vport = (struct bfa_fcs_vport_s *)qe;
794                 bfa_fcs_vport_delete(vport);
795         }
796
797         bfa_fcs_port_delete(&fabric->bport);
798         bfa_wc_wait(&fabric->wc);
799 }
800
801 static void
802 bfa_fcs_fabric_delete_comp(void *cbarg)
803 {
804         struct bfa_fcs_fabric_s *fabric = cbarg;
805
806         bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_DELCOMP);
807 }
808
809
810
811 /**
812  *  fcs_fabric_public fabric public functions
813  */
814
815 /**
816  *   Attach time initialization
817  */
818 void
819 bfa_fcs_fabric_attach(struct bfa_fcs_s *fcs)
820 {
821         struct bfa_fcs_fabric_s *fabric;
822
823         fabric = &fcs->fabric;
824         bfa_os_memset(fabric, 0, sizeof(struct bfa_fcs_fabric_s));
825
826         /**
827          * Initialize base fabric.
828          */
829         fabric->fcs = fcs;
830         INIT_LIST_HEAD(&fabric->vport_q);
831         INIT_LIST_HEAD(&fabric->vf_q);
832         fabric->lps = bfa_lps_alloc(fcs->bfa);
833         bfa_assert(fabric->lps);
834
835         /**
836          * Initialize fabric delete completion handler. Fabric deletion is complete
837          * when the last vport delete is complete.
838          */
839         bfa_wc_init(&fabric->wc, bfa_fcs_fabric_delete_comp, fabric);
840         bfa_wc_up(&fabric->wc); /* For the base port */
841
842         bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_uninit);
843         bfa_fcs_lport_attach(&fabric->bport, fabric->fcs, FC_VF_ID_NULL, NULL);
844 }
845
846 void
847 bfa_fcs_fabric_modinit(struct bfa_fcs_s *fcs)
848 {
849         bfa_sm_send_event(&fcs->fabric, BFA_FCS_FABRIC_SM_CREATE);
850         bfa_trc(fcs, 0);
851 }
852
853 /**
854  *   Module cleanup
855  */
856 void
857 bfa_fcs_fabric_modexit(struct bfa_fcs_s *fcs)
858 {
859         struct bfa_fcs_fabric_s *fabric;
860
861         bfa_trc(fcs, 0);
862
863         /**
864          * Cleanup base fabric.
865          */
866         fabric = &fcs->fabric;
867         bfa_lps_delete(fabric->lps);
868         bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_DELETE);
869 }
870
871 /**
872  * Fabric module start -- kick starts FCS actions
873  */
874 void
875 bfa_fcs_fabric_modstart(struct bfa_fcs_s *fcs)
876 {
877         struct bfa_fcs_fabric_s *fabric;
878
879         bfa_trc(fcs, 0);
880         fabric = &fcs->fabric;
881         bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_START);
882 }
883
884 /**
885  *   Suspend fabric activity as part of driver suspend.
886  */
887 void
888 bfa_fcs_fabric_modsusp(struct bfa_fcs_s *fcs)
889 {
890 }
891
892 bfa_boolean_t
893 bfa_fcs_fabric_is_loopback(struct bfa_fcs_fabric_s *fabric)
894 {
895         return bfa_sm_cmp_state(fabric, bfa_fcs_fabric_sm_loopback);
896 }
897
898 bfa_boolean_t
899 bfa_fcs_fabric_is_auth_failed(struct bfa_fcs_fabric_s *fabric)
900 {
901         return bfa_sm_cmp_state(fabric, bfa_fcs_fabric_sm_auth_failed);
902 }
903
904 enum bfa_pport_type
905 bfa_fcs_fabric_port_type(struct bfa_fcs_fabric_s *fabric)
906 {
907         return fabric->oper_type;
908 }
909
910 /**
911  *   Link up notification from BFA physical port module.
912  */
913 void
914 bfa_fcs_fabric_link_up(struct bfa_fcs_fabric_s *fabric)
915 {
916         bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
917         bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_LINK_UP);
918 }
919
920 /**
921  *   Link down notification from BFA physical port module.
922  */
923 void
924 bfa_fcs_fabric_link_down(struct bfa_fcs_fabric_s *fabric)
925 {
926         bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
927         bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_LINK_DOWN);
928 }
929
930 /**
931  *   A child vport is being created in the fabric.
932  *
933  *   Call from vport module at vport creation. A list of base port and vports
934  *   belonging to a fabric is maintained to propagate link events.
935  *
936  *   param[in] fabric - Fabric instance. This can be a base fabric or vf.
937  *   param[in] vport  - Vport being created.
938  *
939  *   @return None (always succeeds)
940  */
941 void
942 bfa_fcs_fabric_addvport(struct bfa_fcs_fabric_s *fabric,
943                         struct bfa_fcs_vport_s *vport)
944 {
945         /**
946          * - add vport to fabric's vport_q
947          */
948         bfa_trc(fabric->fcs, fabric->vf_id);
949
950         list_add_tail(&vport->qe, &fabric->vport_q);
951         fabric->num_vports++;
952         bfa_wc_up(&fabric->wc);
953 }
954
955 /**
956  *   A child vport is being deleted from fabric.
957  *
958  *   Vport is being deleted.
959  */
960 void
961 bfa_fcs_fabric_delvport(struct bfa_fcs_fabric_s *fabric,
962                         struct bfa_fcs_vport_s *vport)
963 {
964         list_del(&vport->qe);
965         fabric->num_vports--;
966         bfa_wc_down(&fabric->wc);
967 }
968
969 /**
970  *   Base port is deleted.
971  */
972 void
973 bfa_fcs_fabric_port_delete_comp(struct bfa_fcs_fabric_s *fabric)
974 {
975         bfa_wc_down(&fabric->wc);
976 }
977
978 /**
979  *    Check if fabric is online.
980  *
981  *   param[in] fabric - Fabric instance. This can be a base fabric or vf.
982  *
983  *   @return  TRUE/FALSE
984  */
985 int
986 bfa_fcs_fabric_is_online(struct bfa_fcs_fabric_s *fabric)
987 {
988         return bfa_sm_cmp_state(fabric, bfa_fcs_fabric_sm_online);
989 }
990
991
992 bfa_status_t
993 bfa_fcs_fabric_addvf(struct bfa_fcs_fabric_s *vf, struct bfa_fcs_s *fcs,
994                      struct bfa_port_cfg_s *port_cfg,
995                      struct bfad_vf_s *vf_drv)
996 {
997         bfa_sm_set_state(vf, bfa_fcs_fabric_sm_uninit);
998         return BFA_STATUS_OK;
999 }
1000
1001 /**
1002  * Lookup for a vport withing a fabric given its pwwn
1003  */
1004 struct bfa_fcs_vport_s *
1005 bfa_fcs_fabric_vport_lookup(struct bfa_fcs_fabric_s *fabric, wwn_t pwwn)
1006 {
1007         struct bfa_fcs_vport_s *vport;
1008         struct list_head *qe;
1009
1010         list_for_each(qe, &fabric->vport_q) {
1011                 vport = (struct bfa_fcs_vport_s *)qe;
1012                 if (bfa_fcs_port_get_pwwn(&vport->lport) == pwwn)
1013                         return vport;
1014         }
1015
1016         return NULL;
1017 }
1018
1019 /**
1020  *    In a given fabric, return the number of lports.
1021  *
1022  *   param[in] fabric - Fabric instance. This can be a base fabric or vf.
1023  *
1024 *    @return : 1 or more.
1025  */
1026 u16
1027 bfa_fcs_fabric_vport_count(struct bfa_fcs_fabric_s *fabric)
1028 {
1029         return fabric->num_vports;
1030 }
1031
1032 /**
1033  *              Unsolicited frame receive handling.
1034  */
1035 void
1036 bfa_fcs_fabric_uf_recv(struct bfa_fcs_fabric_s *fabric, struct fchs_s *fchs,
1037                        u16 len)
1038 {
1039         u32        pid = fchs->d_id;
1040         struct bfa_fcs_vport_s *vport;
1041         struct list_head *qe;
1042         struct fc_els_cmd_s   *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
1043         struct fc_logi_s     *flogi = (struct fc_logi_s *) els_cmd;
1044
1045         bfa_trc(fabric->fcs, len);
1046         bfa_trc(fabric->fcs, pid);
1047
1048         /**
1049          * Look for our own FLOGI frames being looped back. This means an
1050          * external loopback cable is in place. Our own FLOGI frames are
1051          * sometimes looped back when switch port gets temporarily bypassed.
1052          */
1053         if ((pid == bfa_os_ntoh3b(FC_FABRIC_PORT))
1054             && (els_cmd->els_code == FC_ELS_FLOGI)
1055             && (flogi->port_name == bfa_fcs_port_get_pwwn(&fabric->bport))) {
1056                 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_LOOPBACK);
1057                 return;
1058         }
1059
1060         /**
1061          * FLOGI/EVFP exchanges should be consumed by base fabric.
1062          */
1063         if (fchs->d_id == bfa_os_hton3b(FC_FABRIC_PORT)) {
1064                 bfa_trc(fabric->fcs, pid);
1065                 bfa_fcs_fabric_process_uf(fabric, fchs, len);
1066                 return;
1067         }
1068
1069         if (fabric->bport.pid == pid) {
1070                 /**
1071                  * All authentication frames should be routed to auth
1072                  */
1073                 bfa_trc(fabric->fcs, els_cmd->els_code);
1074                 if (els_cmd->els_code == FC_ELS_AUTH) {
1075                         bfa_trc(fabric->fcs, els_cmd->els_code);
1076                         fabric->auth.response = (u8 *) els_cmd;
1077                         return;
1078                 }
1079
1080                 bfa_trc(fabric->fcs, *(u8 *) ((u8 *) fchs));
1081                 bfa_fcs_port_uf_recv(&fabric->bport, fchs, len);
1082                 return;
1083         }
1084
1085         /**
1086          * look for a matching local port ID
1087          */
1088         list_for_each(qe, &fabric->vport_q) {
1089                 vport = (struct bfa_fcs_vport_s *)qe;
1090                 if (vport->lport.pid == pid) {
1091                         bfa_fcs_port_uf_recv(&vport->lport, fchs, len);
1092                         return;
1093                 }
1094         }
1095         bfa_trc(fabric->fcs, els_cmd->els_code);
1096         bfa_fcs_port_uf_recv(&fabric->bport, fchs, len);
1097 }
1098
1099 /**
1100  *              Unsolicited frames to be processed by fabric.
1101  */
1102 static void
1103 bfa_fcs_fabric_process_uf(struct bfa_fcs_fabric_s *fabric, struct fchs_s *fchs,
1104                           u16 len)
1105 {
1106         struct fc_els_cmd_s   *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
1107
1108         bfa_trc(fabric->fcs, els_cmd->els_code);
1109
1110         switch (els_cmd->els_code) {
1111         case FC_ELS_FLOGI:
1112                 bfa_fcs_fabric_process_flogi(fabric, fchs, len);
1113                 break;
1114
1115         default:
1116                 /*
1117                  * need to generate a LS_RJT
1118                  */
1119                 break;
1120         }
1121 }
1122
1123 /**
1124  *      Process incoming FLOGI
1125  */
1126 static void
1127 bfa_fcs_fabric_process_flogi(struct bfa_fcs_fabric_s *fabric,
1128                         struct fchs_s *fchs, u16 len)
1129 {
1130         struct fc_logi_s     *flogi = (struct fc_logi_s *) (fchs + 1);
1131         struct bfa_fcs_port_s *bport = &fabric->bport;
1132
1133         bfa_trc(fabric->fcs, fchs->s_id);
1134
1135         fabric->stats.flogi_rcvd++;
1136         /*
1137          * Check port type. It should be 0 = n-port.
1138          */
1139         if (flogi->csp.port_type) {
1140                 /*
1141                  * @todo: may need to send a LS_RJT
1142                  */
1143                 bfa_trc(fabric->fcs, flogi->port_name);
1144                 fabric->stats.flogi_rejected++;
1145                 return;
1146         }
1147
1148         fabric->bb_credit = bfa_os_ntohs(flogi->csp.bbcred);
1149         bport->port_topo.pn2n.rem_port_wwn = flogi->port_name;
1150         bport->port_topo.pn2n.reply_oxid = fchs->ox_id;
1151
1152         /*
1153          * Send a Flogi Acc
1154          */
1155         bfa_fcs_fabric_send_flogi_acc(fabric);
1156         bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_NO_FABRIC);
1157 }
1158
1159 static void
1160 bfa_fcs_fabric_send_flogi_acc(struct bfa_fcs_fabric_s *fabric)
1161 {
1162         struct bfa_port_cfg_s *pcfg = &fabric->bport.port_cfg;
1163         struct bfa_fcs_port_n2n_s *n2n_port = &fabric->bport.port_topo.pn2n;
1164         struct bfa_s   *bfa = fabric->fcs->bfa;
1165         struct bfa_fcxp_s *fcxp;
1166         u16        reqlen;
1167         struct fchs_s          fchs;
1168
1169         fcxp = bfa_fcs_fcxp_alloc(fabric->fcs);
1170         /**
1171          * Do not expect this failure -- expect remote node to retry
1172          */
1173         if (!fcxp)
1174                 return;
1175
1176         reqlen = fc_flogi_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
1177                                     bfa_os_hton3b(FC_FABRIC_PORT),
1178                                     n2n_port->reply_oxid, pcfg->pwwn,
1179                                     pcfg->nwwn, bfa_pport_get_maxfrsize(bfa),
1180                                     bfa_pport_get_rx_bbcredit(bfa));
1181
1182         bfa_fcxp_send(fcxp, NULL, fabric->vf_id, bfa_lps_get_tag(fabric->lps),
1183                         BFA_FALSE, FC_CLASS_3, reqlen, &fchs,
1184                         bfa_fcs_fabric_flogiacc_comp, fabric,
1185                         FC_MAX_PDUSZ, 0); /* Timeout 0 indicates no
1186                                            * response expected
1187                                            */
1188 }
1189
1190 /**
1191  *   Flogi Acc completion callback.
1192  */
1193 static void
1194 bfa_fcs_fabric_flogiacc_comp(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
1195                              bfa_status_t status, u32 rsp_len,
1196                              u32 resid_len, struct fchs_s *rspfchs)
1197 {
1198         struct bfa_fcs_fabric_s *fabric = cbarg;
1199
1200         bfa_trc(fabric->fcs, status);
1201 }
1202
1203 /*
1204  *
1205  * @param[in] fabric - fabric
1206  * @param[in] result - 1
1207  *
1208  * @return - none
1209  */
1210 void
1211 bfa_fcs_auth_finished(struct bfa_fcs_fabric_s *fabric, enum auth_status status)
1212 {
1213         bfa_trc(fabric->fcs, status);
1214
1215         if (status == FC_AUTH_STATE_SUCCESS)
1216                 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_AUTH_SUCCESS);
1217         else
1218                 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_AUTH_FAILED);
1219 }
1220
1221 /**
1222  * Send AEN notification
1223  */
1224 static void
1225 bfa_fcs_fabric_aen_post(struct bfa_fcs_port_s *port,
1226                         enum bfa_port_aen_event event)
1227 {
1228         union bfa_aen_data_u aen_data;
1229         struct bfa_log_mod_s *logmod = port->fcs->logm;
1230         wwn_t           pwwn = bfa_fcs_port_get_pwwn(port);
1231         wwn_t           fwwn = bfa_fcs_port_get_fabric_name(port);
1232         char            pwwn_ptr[BFA_STRING_32];
1233         char            fwwn_ptr[BFA_STRING_32];
1234
1235         wwn2str(pwwn_ptr, pwwn);
1236         wwn2str(fwwn_ptr, fwwn);
1237
1238         switch (event) {
1239         case BFA_PORT_AEN_FABRIC_NAME_CHANGE:
1240                 bfa_log(logmod, BFA_AEN_PORT_FABRIC_NAME_CHANGE, pwwn_ptr,
1241                         fwwn_ptr);
1242                 break;
1243         default:
1244                 break;
1245         }
1246
1247         aen_data.port.pwwn = pwwn;
1248         aen_data.port.fwwn = fwwn;
1249 }
1250
1251 /*
1252  *
1253  * @param[in] fabric - fabric
1254  * @param[in] wwn_t - new fabric name
1255  *
1256  * @return - none
1257  */
1258 void
1259 bfa_fcs_fabric_set_fabric_name(struct bfa_fcs_fabric_s *fabric,
1260                                wwn_t fabric_name)
1261 {
1262         bfa_trc(fabric->fcs, fabric_name);
1263
1264         if (fabric->fabric_name == 0) {
1265                 /*
1266                  * With BRCD switches, we don't get Fabric Name in FLOGI.
1267                  * Don't generate a fabric name change event in this case.
1268                  */
1269                 fabric->fabric_name = fabric_name;
1270         } else {
1271                 fabric->fabric_name = fabric_name;
1272                 /*
1273                  * Generate a Event
1274                  */
1275                 bfa_fcs_fabric_aen_post(&fabric->bport,
1276                                         BFA_PORT_AEN_FABRIC_NAME_CHANGE);
1277         }
1278
1279 }
1280
1281 /**
1282  * Not used by FCS.
1283  */
1284 void
1285 bfa_cb_lps_flogo_comp(void *bfad, void *uarg)
1286 {
1287 }
1288
1289