]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/scsi/bfa/bfa_fcs.c
[SCSI] bfa: FC credit recovery and misc bug fixes.
[mirror_ubuntu-artful-kernel.git] / drivers / scsi / bfa / bfa_fcs.c
CommitLineData
7725ccfd 1/*
a36c61f9 2 * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
7725ccfd
JH
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
5fbe25c7 18/*
7725ccfd
JH
19 * bfa_fcs.c BFA FCS main
20 */
21
f16a1750 22#include "bfad_drv.h"
a36c61f9
KG
23#include "bfa_fcs.h"
24#include "bfa_fcbuild.h"
a36c61f9
KG
25
26BFA_TRC_FILE(FCS, FCS);
7725ccfd 27
5fbe25c7 28/*
7725ccfd
JH
29 * FCS sub-modules
30 */
31struct bfa_fcs_mod_s {
82794a2e 32 void (*attach) (struct bfa_fcs_s *fcs);
a36c61f9
KG
33 void (*modinit) (struct bfa_fcs_s *fcs);
34 void (*modexit) (struct bfa_fcs_s *fcs);
7725ccfd
JH
35};
36
37#define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
38
39static struct bfa_fcs_mod_s fcs_modules[] = {
a36c61f9 40 { bfa_fcs_port_attach, NULL, NULL },
82794a2e
KG
41 { bfa_fcs_uf_attach, NULL, NULL },
42 { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
a36c61f9 43 bfa_fcs_fabric_modexit },
7725ccfd
JH
44};
45
5fbe25c7 46/*
7725ccfd
JH
47 * fcs_api BFA FCS API
48 */
49
50static void
51bfa_fcs_exit_comp(void *fcs_cbarg)
52{
a36c61f9
KG
53 struct bfa_fcs_s *fcs = fcs_cbarg;
54 struct bfad_s *bfad = fcs->bfad;
7725ccfd
JH
55
56 complete(&bfad->comp);
57}
58
59
60
5fbe25c7 61/*
7725ccfd
JH
62 * fcs_api BFA FCS API
63 */
64
5fbe25c7 65/*
82794a2e 66 * fcs attach -- called once to initialize data structures at driver attach time
7725ccfd
JH
67 */
68void
82794a2e 69bfa_fcs_attach(struct bfa_fcs_s *fcs, struct bfa_s *bfa, struct bfad_s *bfad,
a36c61f9 70 bfa_boolean_t min_cfg)
7725ccfd 71{
a36c61f9 72 int i;
7725ccfd
JH
73 struct bfa_fcs_mod_s *mod;
74
75 fcs->bfa = bfa;
76 fcs->bfad = bfad;
77 fcs->min_cfg = min_cfg;
78
f7f73812 79 bfa->fcs = BFA_TRUE;
7725ccfd
JH
80 fcbuild_init();
81
a36c61f9 82 for (i = 0; i < sizeof(fcs_modules) / sizeof(fcs_modules[0]); i++) {
7725ccfd 83 mod = &fcs_modules[i];
82794a2e
KG
84 if (mod->attach)
85 mod->attach(fcs);
86 }
87}
88
5fbe25c7 89/*
82794a2e
KG
90 * fcs initialization, called once after bfa initialization is complete
91 */
92void
93bfa_fcs_init(struct bfa_fcs_s *fcs)
94{
a36c61f9 95 int i, npbc_vports;
82794a2e 96 struct bfa_fcs_mod_s *mod;
d9883548 97 struct bfi_pbc_vport_s pbc_vports[BFI_PBC_MAX_VPORTS];
82794a2e 98
a36c61f9 99 for (i = 0; i < sizeof(fcs_modules) / sizeof(fcs_modules[0]); i++) {
82794a2e
KG
100 mod = &fcs_modules[i];
101 if (mod->modinit)
102 mod->modinit(fcs);
7725ccfd 103 }
d9883548
JH
104 /* Initialize pbc vports */
105 if (!fcs->min_cfg) {
106 npbc_vports =
a36c61f9 107 bfa_iocfc_get_pbc_vports(fcs->bfa, pbc_vports);
d9883548
JH
108 for (i = 0; i < npbc_vports; i++)
109 bfa_fcb_pbc_vport_create(fcs->bfa->bfad, pbc_vports[i]);
110 }
7725ccfd
JH
111}
112
7725ccfd 113
5fbe25c7 114/*
a36c61f9
KG
115 * brief
116 * FCS driver details initialization.
7725ccfd 117 *
a36c61f9
KG
118 * param[in] fcs FCS instance
119 * param[in] driver_info Driver Details
7725ccfd 120 *
a36c61f9 121 * return None
7725ccfd
JH
122 */
123void
124bfa_fcs_driver_info_init(struct bfa_fcs_s *fcs,
125 struct bfa_fcs_driver_info_s *driver_info)
126{
127
128 fcs->driver_info = *driver_info;
129
130 bfa_fcs_fabric_psymb_init(&fcs->fabric);
131}
132
5fbe25c7 133/*
a36c61f9
KG
134 * brief
135 * FCS instance cleanup and exit.
7725ccfd 136 *
a36c61f9
KG
137 * param[in] fcs FCS instance
138 * return None
7725ccfd
JH
139 */
140void
141bfa_fcs_exit(struct bfa_fcs_s *fcs)
142{
143 struct bfa_fcs_mod_s *mod;
a36c61f9 144 int nmods, i;
7725ccfd
JH
145
146 bfa_wc_init(&fcs->wc, bfa_fcs_exit_comp, fcs);
147
a36c61f9
KG
148 nmods = sizeof(fcs_modules) / sizeof(fcs_modules[0]);
149
150 for (i = 0; i < nmods; i++) {
7725ccfd
JH
151
152 mod = &fcs_modules[i];
82794a2e
KG
153 if (mod->modexit) {
154 bfa_wc_up(&fcs->wc);
155 mod->modexit(fcs);
156 }
7725ccfd
JH
157 }
158
159 bfa_wc_wait(&fcs->wc);
160}
161
162
5fbe25c7 163/*
a36c61f9
KG
164 * Fabric module implementation.
165 */
166
167#define BFA_FCS_FABRIC_RETRY_DELAY (2000) /* Milliseconds */
168#define BFA_FCS_FABRIC_CLEANUP_DELAY (10000) /* Milliseconds */
169
170#define bfa_fcs_fabric_set_opertype(__fabric) do { \
171 if (bfa_fcport_get_topology((__fabric)->fcs->bfa) \
172 == BFA_PORT_TOPOLOGY_P2P) \
173 (__fabric)->oper_type = BFA_PORT_TYPE_NPORT; \
174 else \
175 (__fabric)->oper_type = BFA_PORT_TYPE_NLPORT; \
176} while (0)
177
178/*
179 * forward declarations
180 */
181static void bfa_fcs_fabric_init(struct bfa_fcs_fabric_s *fabric);
182static void bfa_fcs_fabric_login(struct bfa_fcs_fabric_s *fabric);
183static void bfa_fcs_fabric_notify_online(struct bfa_fcs_fabric_s *fabric);
184static void bfa_fcs_fabric_notify_offline(struct bfa_fcs_fabric_s *fabric);
185static void bfa_fcs_fabric_delay(void *cbarg);
186static void bfa_fcs_fabric_delete(struct bfa_fcs_fabric_s *fabric);
187static void bfa_fcs_fabric_delete_comp(void *cbarg);
188static void bfa_fcs_fabric_process_uf(struct bfa_fcs_fabric_s *fabric,
189 struct fchs_s *fchs, u16 len);
190static void bfa_fcs_fabric_process_flogi(struct bfa_fcs_fabric_s *fabric,
191 struct fchs_s *fchs, u16 len);
192static void bfa_fcs_fabric_send_flogi_acc(struct bfa_fcs_fabric_s *fabric);
193static void bfa_fcs_fabric_flogiacc_comp(void *fcsarg,
194 struct bfa_fcxp_s *fcxp, void *cbarg,
195 bfa_status_t status,
196 u32 rsp_len,
197 u32 resid_len,
198 struct fchs_s *rspfchs);
be540a99
KG
199static u8 bfa_fcs_fabric_oper_bbscn(struct bfa_fcs_fabric_s *fabric);
200static bfa_boolean_t bfa_fcs_fabric_is_bbscn_enabled(
201 struct bfa_fcs_fabric_s *fabric);
a36c61f9
KG
202
203static void bfa_fcs_fabric_sm_uninit(struct bfa_fcs_fabric_s *fabric,
204 enum bfa_fcs_fabric_event event);
205static void bfa_fcs_fabric_sm_created(struct bfa_fcs_fabric_s *fabric,
206 enum bfa_fcs_fabric_event event);
207static void bfa_fcs_fabric_sm_linkdown(struct bfa_fcs_fabric_s *fabric,
208 enum bfa_fcs_fabric_event event);
209static void bfa_fcs_fabric_sm_flogi(struct bfa_fcs_fabric_s *fabric,
210 enum bfa_fcs_fabric_event event);
211static void bfa_fcs_fabric_sm_flogi_retry(struct bfa_fcs_fabric_s *fabric,
212 enum bfa_fcs_fabric_event event);
213static void bfa_fcs_fabric_sm_auth(struct bfa_fcs_fabric_s *fabric,
214 enum bfa_fcs_fabric_event event);
a36c61f9
KG
215static void bfa_fcs_fabric_sm_nofabric(struct bfa_fcs_fabric_s *fabric,
216 enum bfa_fcs_fabric_event event);
a36c61f9
KG
217static void bfa_fcs_fabric_sm_evfp(struct bfa_fcs_fabric_s *fabric,
218 enum bfa_fcs_fabric_event event);
219static void bfa_fcs_fabric_sm_evfp_done(struct bfa_fcs_fabric_s *fabric,
220 enum bfa_fcs_fabric_event event);
221static void bfa_fcs_fabric_sm_isolated(struct bfa_fcs_fabric_s *fabric,
222 enum bfa_fcs_fabric_event event);
223static void bfa_fcs_fabric_sm_deleting(struct bfa_fcs_fabric_s *fabric,
224 enum bfa_fcs_fabric_event event);
5fbe25c7 225/*
a36c61f9
KG
226 * Beginning state before fabric creation.
227 */
228static void
229bfa_fcs_fabric_sm_uninit(struct bfa_fcs_fabric_s *fabric,
230 enum bfa_fcs_fabric_event event)
231{
232 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
233 bfa_trc(fabric->fcs, event);
234
235 switch (event) {
236 case BFA_FCS_FABRIC_SM_CREATE:
237 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_created);
238 bfa_fcs_fabric_init(fabric);
239 bfa_fcs_lport_init(&fabric->bport, &fabric->bport.port_cfg);
240 break;
241
242 case BFA_FCS_FABRIC_SM_LINK_UP:
243 case BFA_FCS_FABRIC_SM_LINK_DOWN:
244 break;
245
246 default:
247 bfa_sm_fault(fabric->fcs, event);
248 }
249}
250
5fbe25c7 251/*
a36c61f9
KG
252 * Beginning state before fabric creation.
253 */
254static void
255bfa_fcs_fabric_sm_created(struct bfa_fcs_fabric_s *fabric,
256 enum bfa_fcs_fabric_event event)
257{
258 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
259 bfa_trc(fabric->fcs, event);
260
261 switch (event) {
262 case BFA_FCS_FABRIC_SM_START:
263 if (bfa_fcport_is_linkup(fabric->fcs->bfa)) {
264 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_flogi);
265 bfa_fcs_fabric_login(fabric);
266 } else
267 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
268 break;
269
270 case BFA_FCS_FABRIC_SM_LINK_UP:
271 case BFA_FCS_FABRIC_SM_LINK_DOWN:
272 break;
273
274 case BFA_FCS_FABRIC_SM_DELETE:
dd5aaf45
KG
275 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
276 bfa_fcs_fabric_delete(fabric);
a36c61f9
KG
277 break;
278
279 default:
280 bfa_sm_fault(fabric->fcs, event);
281 }
282}
283
5fbe25c7 284/*
a36c61f9
KG
285 * Link is down, awaiting LINK UP event from port. This is also the
286 * first state at fabric creation.
287 */
288static void
289bfa_fcs_fabric_sm_linkdown(struct bfa_fcs_fabric_s *fabric,
290 enum bfa_fcs_fabric_event event)
291{
292 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
293 bfa_trc(fabric->fcs, event);
294
295 switch (event) {
296 case BFA_FCS_FABRIC_SM_LINK_UP:
297 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_flogi);
298 bfa_fcs_fabric_login(fabric);
299 break;
300
301 case BFA_FCS_FABRIC_SM_RETRY_OP:
302 break;
303
304 case BFA_FCS_FABRIC_SM_DELETE:
305 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
306 bfa_fcs_fabric_delete(fabric);
307 break;
308
309 default:
310 bfa_sm_fault(fabric->fcs, event);
311 }
312}
313
5fbe25c7 314/*
a36c61f9
KG
315 * FLOGI is in progress, awaiting FLOGI reply.
316 */
317static void
318bfa_fcs_fabric_sm_flogi(struct bfa_fcs_fabric_s *fabric,
319 enum bfa_fcs_fabric_event event)
320{
321 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
322 bfa_trc(fabric->fcs, event);
323
324 switch (event) {
325 case BFA_FCS_FABRIC_SM_CONT_OP:
326
327 bfa_fcport_set_tx_bbcredit(fabric->fcs->bfa,
be540a99
KG
328 fabric->bb_credit,
329 bfa_fcs_fabric_oper_bbscn(fabric));
a36c61f9
KG
330 fabric->fab_type = BFA_FCS_FABRIC_SWITCHED;
331
332 if (fabric->auth_reqd && fabric->is_auth) {
333 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_auth);
334 bfa_trc(fabric->fcs, event);
335 } else {
336 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_online);
337 bfa_fcs_fabric_notify_online(fabric);
338 }
339 break;
340
341 case BFA_FCS_FABRIC_SM_RETRY_OP:
342 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_flogi_retry);
343 bfa_timer_start(fabric->fcs->bfa, &fabric->delay_timer,
344 bfa_fcs_fabric_delay, fabric,
345 BFA_FCS_FABRIC_RETRY_DELAY);
346 break;
347
348 case BFA_FCS_FABRIC_SM_LOOPBACK:
349 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_loopback);
f7f73812 350 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
a36c61f9
KG
351 bfa_fcs_fabric_set_opertype(fabric);
352 break;
353
354 case BFA_FCS_FABRIC_SM_NO_FABRIC:
355 fabric->fab_type = BFA_FCS_FABRIC_N2N;
356 bfa_fcport_set_tx_bbcredit(fabric->fcs->bfa,
be540a99
KG
357 fabric->bb_credit,
358 bfa_fcs_fabric_oper_bbscn(fabric));
a36c61f9
KG
359 bfa_fcs_fabric_notify_online(fabric);
360 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_nofabric);
361 break;
362
363 case BFA_FCS_FABRIC_SM_LINK_DOWN:
364 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
f7f73812 365 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
a36c61f9
KG
366 break;
367
368 case BFA_FCS_FABRIC_SM_DELETE:
369 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
f7f73812 370 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
a36c61f9
KG
371 bfa_fcs_fabric_delete(fabric);
372 break;
373
374 default:
375 bfa_sm_fault(fabric->fcs, event);
376 }
377}
378
379
380static void
381bfa_fcs_fabric_sm_flogi_retry(struct bfa_fcs_fabric_s *fabric,
382 enum bfa_fcs_fabric_event event)
383{
384 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
385 bfa_trc(fabric->fcs, event);
386
387 switch (event) {
388 case BFA_FCS_FABRIC_SM_DELAYED:
389 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_flogi);
390 bfa_fcs_fabric_login(fabric);
391 break;
392
393 case BFA_FCS_FABRIC_SM_LINK_DOWN:
394 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
395 bfa_timer_stop(&fabric->delay_timer);
396 break;
397
398 case BFA_FCS_FABRIC_SM_DELETE:
399 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
400 bfa_timer_stop(&fabric->delay_timer);
401 bfa_fcs_fabric_delete(fabric);
402 break;
403
404 default:
405 bfa_sm_fault(fabric->fcs, event);
406 }
407}
408
5fbe25c7 409/*
a36c61f9
KG
410 * Authentication is in progress, awaiting authentication results.
411 */
412static void
413bfa_fcs_fabric_sm_auth(struct bfa_fcs_fabric_s *fabric,
414 enum bfa_fcs_fabric_event event)
415{
416 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
417 bfa_trc(fabric->fcs, event);
418
419 switch (event) {
420 case BFA_FCS_FABRIC_SM_AUTH_FAILED:
421 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_auth_failed);
f7f73812 422 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
a36c61f9
KG
423 break;
424
425 case BFA_FCS_FABRIC_SM_AUTH_SUCCESS:
426 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_online);
427 bfa_fcs_fabric_notify_online(fabric);
428 break;
429
430 case BFA_FCS_FABRIC_SM_PERF_EVFP:
431 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_evfp);
432 break;
433
434 case BFA_FCS_FABRIC_SM_LINK_DOWN:
435 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
f7f73812 436 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
a36c61f9
KG
437 break;
438
439 case BFA_FCS_FABRIC_SM_DELETE:
440 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
441 bfa_fcs_fabric_delete(fabric);
442 break;
443
444 default:
445 bfa_sm_fault(fabric->fcs, event);
446 }
447}
448
5fbe25c7 449/*
a36c61f9
KG
450 * Authentication failed
451 */
f7f73812 452void
a36c61f9
KG
453bfa_fcs_fabric_sm_auth_failed(struct bfa_fcs_fabric_s *fabric,
454 enum bfa_fcs_fabric_event event)
455{
456 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
457 bfa_trc(fabric->fcs, event);
458
459 switch (event) {
460 case BFA_FCS_FABRIC_SM_LINK_DOWN:
461 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
462 bfa_fcs_fabric_notify_offline(fabric);
463 break;
464
465 case BFA_FCS_FABRIC_SM_DELETE:
466 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
467 bfa_fcs_fabric_delete(fabric);
468 break;
469
470 default:
471 bfa_sm_fault(fabric->fcs, event);
472 }
473}
474
5fbe25c7 475/*
a36c61f9
KG
476 * Port is in loopback mode.
477 */
f7f73812 478void
a36c61f9
KG
479bfa_fcs_fabric_sm_loopback(struct bfa_fcs_fabric_s *fabric,
480 enum bfa_fcs_fabric_event event)
481{
482 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
483 bfa_trc(fabric->fcs, event);
484
485 switch (event) {
486 case BFA_FCS_FABRIC_SM_LINK_DOWN:
487 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
488 bfa_fcs_fabric_notify_offline(fabric);
489 break;
490
491 case BFA_FCS_FABRIC_SM_DELETE:
492 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
493 bfa_fcs_fabric_delete(fabric);
494 break;
495
496 default:
497 bfa_sm_fault(fabric->fcs, event);
498 }
499}
500
5fbe25c7 501/*
a36c61f9
KG
502 * There is no attached fabric - private loop or NPort-to-NPort topology.
503 */
504static void
505bfa_fcs_fabric_sm_nofabric(struct bfa_fcs_fabric_s *fabric,
506 enum bfa_fcs_fabric_event event)
507{
508 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
509 bfa_trc(fabric->fcs, event);
510
511 switch (event) {
512 case BFA_FCS_FABRIC_SM_LINK_DOWN:
513 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
f7f73812 514 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
a36c61f9
KG
515 bfa_fcs_fabric_notify_offline(fabric);
516 break;
517
518 case BFA_FCS_FABRIC_SM_DELETE:
519 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
520 bfa_fcs_fabric_delete(fabric);
521 break;
522
523 case BFA_FCS_FABRIC_SM_NO_FABRIC:
524 bfa_trc(fabric->fcs, fabric->bb_credit);
525 bfa_fcport_set_tx_bbcredit(fabric->fcs->bfa,
be540a99
KG
526 fabric->bb_credit,
527 bfa_fcs_fabric_oper_bbscn(fabric));
a36c61f9
KG
528 break;
529
530 default:
531 bfa_sm_fault(fabric->fcs, event);
532 }
533}
534
5fbe25c7 535/*
a36c61f9
KG
536 * Fabric is online - normal operating state.
537 */
f7f73812 538void
a36c61f9
KG
539bfa_fcs_fabric_sm_online(struct bfa_fcs_fabric_s *fabric,
540 enum bfa_fcs_fabric_event event)
541{
542 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
543 bfa_trc(fabric->fcs, event);
544
545 switch (event) {
546 case BFA_FCS_FABRIC_SM_LINK_DOWN:
547 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
f7f73812 548 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
a36c61f9
KG
549 bfa_fcs_fabric_notify_offline(fabric);
550 break;
551
552 case BFA_FCS_FABRIC_SM_DELETE:
553 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
554 bfa_fcs_fabric_delete(fabric);
555 break;
556
557 case BFA_FCS_FABRIC_SM_AUTH_FAILED:
558 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_auth_failed);
f7f73812 559 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
a36c61f9
KG
560 break;
561
562 case BFA_FCS_FABRIC_SM_AUTH_SUCCESS:
563 break;
564
565 default:
566 bfa_sm_fault(fabric->fcs, event);
567 }
568}
569
5fbe25c7 570/*
a36c61f9
KG
571 * Exchanging virtual fabric parameters.
572 */
573static void
574bfa_fcs_fabric_sm_evfp(struct bfa_fcs_fabric_s *fabric,
575 enum bfa_fcs_fabric_event event)
576{
577 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
578 bfa_trc(fabric->fcs, event);
579
580 switch (event) {
581 case BFA_FCS_FABRIC_SM_CONT_OP:
582 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_evfp_done);
583 break;
584
585 case BFA_FCS_FABRIC_SM_ISOLATE:
586 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_isolated);
587 break;
588
589 default:
590 bfa_sm_fault(fabric->fcs, event);
591 }
592}
593
5fbe25c7 594/*
a36c61f9
KG
595 * EVFP exchange complete and VFT tagging is enabled.
596 */
597static void
598bfa_fcs_fabric_sm_evfp_done(struct bfa_fcs_fabric_s *fabric,
599 enum bfa_fcs_fabric_event event)
600{
601 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
602 bfa_trc(fabric->fcs, event);
603}
604
5fbe25c7 605/*
a36c61f9
KG
606 * Port is isolated after EVFP exchange due to VF_ID mismatch (N and F).
607 */
608static void
609bfa_fcs_fabric_sm_isolated(struct bfa_fcs_fabric_s *fabric,
610 enum bfa_fcs_fabric_event event)
611{
612 struct bfad_s *bfad = (struct bfad_s *)fabric->fcs->bfad;
613 char pwwn_ptr[BFA_STRING_32];
614
615 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
616 bfa_trc(fabric->fcs, event);
617 wwn2str(pwwn_ptr, fabric->bport.port_cfg.pwwn);
618
88166242 619 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
a36c61f9
KG
620 "Port is isolated due to VF_ID mismatch. "
621 "PWWN: %s Port VF_ID: %04x switch port VF_ID: %04x.",
622 pwwn_ptr, fabric->fcs->port_vfid,
623 fabric->event_arg.swp_vfid);
624}
625
5fbe25c7 626/*
a36c61f9
KG
627 * Fabric is being deleted, awaiting vport delete completions.
628 */
629static void
630bfa_fcs_fabric_sm_deleting(struct bfa_fcs_fabric_s *fabric,
631 enum bfa_fcs_fabric_event event)
7725ccfd 632{
a36c61f9
KG
633 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
634 bfa_trc(fabric->fcs, event);
635
636 switch (event) {
637 case BFA_FCS_FABRIC_SM_DELCOMP:
638 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_uninit);
f7f73812 639 bfa_wc_down(&fabric->fcs->wc);
a36c61f9
KG
640 break;
641
642 case BFA_FCS_FABRIC_SM_LINK_UP:
643 break;
644
645 case BFA_FCS_FABRIC_SM_LINK_DOWN:
646 bfa_fcs_fabric_notify_offline(fabric);
647 break;
648
649 default:
650 bfa_sm_fault(fabric->fcs, event);
651 }
7725ccfd
JH
652}
653
654
a36c61f9 655
5fbe25c7 656/*
a36c61f9
KG
657 * fcs_fabric_private fabric private functions
658 */
659
660static void
661bfa_fcs_fabric_init(struct bfa_fcs_fabric_s *fabric)
662{
663 struct bfa_lport_cfg_s *port_cfg = &fabric->bport.port_cfg;
664
665 port_cfg->roles = BFA_LPORT_ROLE_FCP_IM;
f7f73812
MZ
666 port_cfg->nwwn = fabric->fcs->bfa->ioc.attr->nwwn;
667 port_cfg->pwwn = fabric->fcs->bfa->ioc.attr->pwwn;
a36c61f9
KG
668}
669
5fbe25c7 670/*
a36c61f9
KG
671 * Port Symbolic Name Creation for base port.
672 */
7725ccfd 673void
a36c61f9 674bfa_fcs_fabric_psymb_init(struct bfa_fcs_fabric_s *fabric)
7725ccfd 675{
a36c61f9
KG
676 struct bfa_lport_cfg_s *port_cfg = &fabric->bport.port_cfg;
677 char model[BFA_ADAPTER_MODEL_NAME_LEN] = {0};
678 struct bfa_fcs_driver_info_s *driver_info = &fabric->fcs->driver_info;
679
680 bfa_ioc_get_adapter_model(&fabric->fcs->bfa->ioc, model);
681
682 /* Model name/number */
683 strncpy((char *)&port_cfg->sym_name, model,
684 BFA_FCS_PORT_SYMBNAME_MODEL_SZ);
685 strncat((char *)&port_cfg->sym_name, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
686 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
687
688 /* Driver Version */
689 strncat((char *)&port_cfg->sym_name, (char *)driver_info->version,
690 BFA_FCS_PORT_SYMBNAME_VERSION_SZ);
691 strncat((char *)&port_cfg->sym_name, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
692 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
693
694 /* Host machine name */
695 strncat((char *)&port_cfg->sym_name,
696 (char *)driver_info->host_machine_name,
697 BFA_FCS_PORT_SYMBNAME_MACHINENAME_SZ);
698 strncat((char *)&port_cfg->sym_name, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
699 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
700
701 /*
702 * Host OS Info :
703 * If OS Patch Info is not there, do not truncate any bytes from the
704 * OS name string and instead copy the entire OS info string (64 bytes).
705 */
706 if (driver_info->host_os_patch[0] == '\0') {
707 strncat((char *)&port_cfg->sym_name,
708 (char *)driver_info->host_os_name,
709 BFA_FCS_OS_STR_LEN);
710 strncat((char *)&port_cfg->sym_name,
711 BFA_FCS_PORT_SYMBNAME_SEPARATOR,
712 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
713 } else {
714 strncat((char *)&port_cfg->sym_name,
715 (char *)driver_info->host_os_name,
716 BFA_FCS_PORT_SYMBNAME_OSINFO_SZ);
717 strncat((char *)&port_cfg->sym_name,
718 BFA_FCS_PORT_SYMBNAME_SEPARATOR,
719 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
720
721 /* Append host OS Patch Info */
722 strncat((char *)&port_cfg->sym_name,
723 (char *)driver_info->host_os_patch,
724 BFA_FCS_PORT_SYMBNAME_OSPATCH_SZ);
725 }
726
727 /* null terminate */
728 port_cfg->sym_name.symname[BFA_SYMNAME_MAXLEN - 1] = 0;
7725ccfd
JH
729}
730
5fbe25c7 731/*
a36c61f9
KG
732 * bfa lps login completion callback
733 */
7725ccfd 734void
a36c61f9 735bfa_cb_lps_flogi_comp(void *bfad, void *uarg, bfa_status_t status)
7725ccfd 736{
a36c61f9
KG
737 struct bfa_fcs_fabric_s *fabric = uarg;
738
739 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
740 bfa_trc(fabric->fcs, status);
741
742 switch (status) {
743 case BFA_STATUS_OK:
744 fabric->stats.flogi_accepts++;
745 break;
746
747 case BFA_STATUS_INVALID_MAC:
748 /* Only for CNA */
749 fabric->stats.flogi_acc_err++;
750 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_RETRY_OP);
751
752 return;
753
754 case BFA_STATUS_EPROTOCOL:
f7f73812 755 switch (fabric->lps->ext_status) {
a36c61f9
KG
756 case BFA_EPROTO_BAD_ACCEPT:
757 fabric->stats.flogi_acc_err++;
758 break;
759
760 case BFA_EPROTO_UNKNOWN_RSP:
761 fabric->stats.flogi_unknown_rsp++;
762 break;
763
764 default:
765 break;
766 }
767 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_RETRY_OP);
768
769 return;
770
771 case BFA_STATUS_FABRIC_RJT:
772 fabric->stats.flogi_rejects++;
be540a99
KG
773 if (fabric->lps->lsrjt_rsn == FC_LS_RJT_RSN_LOGICAL_ERROR &&
774 fabric->lps->lsrjt_expl == FC_LS_RJT_EXP_NO_ADDL_INFO)
775 fabric->fcs->bbscn_flogi_rjt = BFA_TRUE;
776
a36c61f9
KG
777 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_RETRY_OP);
778 return;
779
780 default:
781 fabric->stats.flogi_rsp_err++;
782 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_RETRY_OP);
783 return;
784 }
785
f7f73812 786 fabric->bb_credit = fabric->lps->pr_bbcred;
a36c61f9
KG
787 bfa_trc(fabric->fcs, fabric->bb_credit);
788
f7f73812
MZ
789 if (!(fabric->lps->brcd_switch))
790 fabric->fabric_name = fabric->lps->pr_nwwn;
a36c61f9
KG
791
792 /*
793 * Check port type. It should be 1 = F-port.
794 */
f7f73812
MZ
795 if (fabric->lps->fport) {
796 fabric->bport.pid = fabric->lps->lp_pid;
797 fabric->is_npiv = fabric->lps->npiv_en;
798 fabric->is_auth = fabric->lps->auth_req;
a36c61f9
KG
799 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_CONT_OP);
800 } else {
801 /*
802 * Nport-2-Nport direct attached
803 */
804 fabric->bport.port_topo.pn2n.rem_port_wwn =
f7f73812 805 fabric->lps->pr_pwwn;
a36c61f9
KG
806 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_NO_FABRIC);
807 }
808
809 bfa_trc(fabric->fcs, fabric->bport.pid);
810 bfa_trc(fabric->fcs, fabric->is_npiv);
811 bfa_trc(fabric->fcs, fabric->is_auth);
812}
5fbe25c7 813/*
a36c61f9
KG
814 * Allocate and send FLOGI.
815 */
816static void
817bfa_fcs_fabric_login(struct bfa_fcs_fabric_s *fabric)
818{
819 struct bfa_s *bfa = fabric->fcs->bfa;
820 struct bfa_lport_cfg_s *pcfg = &fabric->bport.port_cfg;
be540a99 821 u8 alpa = 0, bb_scn = 0;
a36c61f9
KG
822
823 if (bfa_fcport_get_topology(bfa) == BFA_PORT_TOPOLOGY_LOOP)
824 alpa = bfa_fcport_get_myalpa(bfa);
825
be540a99
KG
826 if (bfa_fcs_fabric_is_bbscn_enabled(fabric) &&
827 (!fabric->fcs->bbscn_flogi_rjt))
828 bb_scn = BFA_FCS_PORT_DEF_BB_SCN;
829
a36c61f9 830 bfa_lps_flogi(fabric->lps, fabric, alpa, bfa_fcport_get_maxfrsize(bfa),
be540a99 831 pcfg->pwwn, pcfg->nwwn, fabric->auth_reqd, bb_scn);
a36c61f9
KG
832
833 fabric->stats.flogi_sent++;
834}
835
836static void
837bfa_fcs_fabric_notify_online(struct bfa_fcs_fabric_s *fabric)
838{
839 struct bfa_fcs_vport_s *vport;
840 struct list_head *qe, *qen;
841
842 bfa_trc(fabric->fcs, fabric->fabric_name);
843
844 bfa_fcs_fabric_set_opertype(fabric);
845 fabric->stats.fabric_onlines++;
846
5fbe25c7 847 /*
a36c61f9
KG
848 * notify online event to base and then virtual ports
849 */
850 bfa_fcs_lport_online(&fabric->bport);
851
852 list_for_each_safe(qe, qen, &fabric->vport_q) {
853 vport = (struct bfa_fcs_vport_s *) qe;
854 bfa_fcs_vport_online(vport);
855 }
856}
857
858static void
859bfa_fcs_fabric_notify_offline(struct bfa_fcs_fabric_s *fabric)
860{
861 struct bfa_fcs_vport_s *vport;
862 struct list_head *qe, *qen;
863
864 bfa_trc(fabric->fcs, fabric->fabric_name);
865 fabric->stats.fabric_offlines++;
866
5fbe25c7 867 /*
a36c61f9
KG
868 * notify offline event first to vports and then base port.
869 */
870 list_for_each_safe(qe, qen, &fabric->vport_q) {
871 vport = (struct bfa_fcs_vport_s *) qe;
872 bfa_fcs_vport_offline(vport);
873 }
874
875 bfa_fcs_lport_offline(&fabric->bport);
876
877 fabric->fabric_name = 0;
878 fabric->fabric_ip_addr[0] = 0;
879}
880
881static void
882bfa_fcs_fabric_delay(void *cbarg)
883{
884 struct bfa_fcs_fabric_s *fabric = cbarg;
885
886 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_DELAYED);
887}
888
be540a99
KG
889/*
890 * Computes operating BB_SCN value
891 */
892static u8
893bfa_fcs_fabric_oper_bbscn(struct bfa_fcs_fabric_s *fabric)
894{
895 u8 pr_bbscn = fabric->lps->pr_bbscn;
896
897 if (!(fabric->fcs->bbscn_enabled && pr_bbscn))
898 return 0;
899
900 /* return max of local/remote bb_scn values */
901 return ((pr_bbscn > BFA_FCS_PORT_DEF_BB_SCN) ?
902 pr_bbscn : BFA_FCS_PORT_DEF_BB_SCN);
903}
904
905/*
906 * Check if BB_SCN can be enabled.
907 */
908static bfa_boolean_t
909bfa_fcs_fabric_is_bbscn_enabled(struct bfa_fcs_fabric_s *fabric)
910{
911 if (bfa_ioc_get_fcmode(&fabric->fcs->bfa->ioc) &&
912 fabric->fcs->bbscn_enabled &&
913 !bfa_fcport_is_qos_enabled(fabric->fcs->bfa) &&
914 !bfa_fcport_is_trunk_enabled(fabric->fcs->bfa))
915 return BFA_TRUE;
916 else
917 return BFA_FALSE;
918}
919
5fbe25c7 920/*
a36c61f9
KG
921 * Delete all vports and wait for vport delete completions.
922 */
923static void
924bfa_fcs_fabric_delete(struct bfa_fcs_fabric_s *fabric)
925{
926 struct bfa_fcs_vport_s *vport;
927 struct list_head *qe, *qen;
928
929 list_for_each_safe(qe, qen, &fabric->vport_q) {
930 vport = (struct bfa_fcs_vport_s *) qe;
931 bfa_fcs_vport_fcs_delete(vport);
932 }
933
934 bfa_fcs_lport_delete(&fabric->bport);
935 bfa_wc_wait(&fabric->wc);
7725ccfd
JH
936}
937
a36c61f9
KG
938static void
939bfa_fcs_fabric_delete_comp(void *cbarg)
940{
941 struct bfa_fcs_fabric_s *fabric = cbarg;
942
943 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_DELCOMP);
944}
7725ccfd 945
5fbe25c7 946/*
a36c61f9
KG
947 * fcs_fabric_public fabric public functions
948 */
949
5fbe25c7 950/*
a36c61f9
KG
951 * Attach time initialization.
952 */
953void
954bfa_fcs_fabric_attach(struct bfa_fcs_s *fcs)
955{
956 struct bfa_fcs_fabric_s *fabric;
957
958 fabric = &fcs->fabric;
6a18b167 959 memset(fabric, 0, sizeof(struct bfa_fcs_fabric_s));
a36c61f9 960
5fbe25c7 961 /*
a36c61f9
KG
962 * Initialize base fabric.
963 */
964 fabric->fcs = fcs;
965 INIT_LIST_HEAD(&fabric->vport_q);
966 INIT_LIST_HEAD(&fabric->vf_q);
967 fabric->lps = bfa_lps_alloc(fcs->bfa);
d4b671c5 968 WARN_ON(!fabric->lps);
a36c61f9 969
5fbe25c7 970 /*
a36c61f9
KG
971 * Initialize fabric delete completion handler. Fabric deletion is
972 * complete when the last vport delete is complete.
973 */
974 bfa_wc_init(&fabric->wc, bfa_fcs_fabric_delete_comp, fabric);
975 bfa_wc_up(&fabric->wc); /* For the base port */
976
977 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_uninit);
978 bfa_fcs_lport_attach(&fabric->bport, fabric->fcs, FC_VF_ID_NULL, NULL);
979}
980
981void
982bfa_fcs_fabric_modinit(struct bfa_fcs_s *fcs)
983{
984 bfa_sm_send_event(&fcs->fabric, BFA_FCS_FABRIC_SM_CREATE);
985 bfa_trc(fcs, 0);
986}
987
5fbe25c7 988/*
a36c61f9
KG
989 * Module cleanup
990 */
991void
992bfa_fcs_fabric_modexit(struct bfa_fcs_s *fcs)
993{
994 struct bfa_fcs_fabric_s *fabric;
995
996 bfa_trc(fcs, 0);
997
5fbe25c7 998 /*
a36c61f9
KG
999 * Cleanup base fabric.
1000 */
1001 fabric = &fcs->fabric;
1002 bfa_lps_delete(fabric->lps);
1003 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_DELETE);
1004}
1005
5fbe25c7 1006/*
a36c61f9
KG
1007 * Fabric module start -- kick starts FCS actions
1008 */
1009void
1010bfa_fcs_fabric_modstart(struct bfa_fcs_s *fcs)
1011{
1012 struct bfa_fcs_fabric_s *fabric;
1013
1014 bfa_trc(fcs, 0);
1015 fabric = &fcs->fabric;
1016 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_START);
1017}
1018
a36c61f9 1019
5fbe25c7 1020/*
a36c61f9
KG
1021 * Link up notification from BFA physical port module.
1022 */
1023void
1024bfa_fcs_fabric_link_up(struct bfa_fcs_fabric_s *fabric)
1025{
1026 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
1027 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_LINK_UP);
1028}
1029
5fbe25c7 1030/*
a36c61f9
KG
1031 * Link down notification from BFA physical port module.
1032 */
1033void
1034bfa_fcs_fabric_link_down(struct bfa_fcs_fabric_s *fabric)
1035{
1036 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
be540a99 1037 fabric->fcs->bbscn_flogi_rjt = BFA_FALSE;
a36c61f9
KG
1038 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_LINK_DOWN);
1039}
1040
5fbe25c7 1041/*
a36c61f9
KG
1042 * A child vport is being created in the fabric.
1043 *
1044 * Call from vport module at vport creation. A list of base port and vports
1045 * belonging to a fabric is maintained to propagate link events.
1046 *
1047 * param[in] fabric - Fabric instance. This can be a base fabric or vf.
1048 * param[in] vport - Vport being created.
1049 *
1050 * @return None (always succeeds)
1051 */
1052void
1053bfa_fcs_fabric_addvport(struct bfa_fcs_fabric_s *fabric,
1054 struct bfa_fcs_vport_s *vport)
1055{
5fbe25c7 1056 /*
a36c61f9
KG
1057 * - add vport to fabric's vport_q
1058 */
1059 bfa_trc(fabric->fcs, fabric->vf_id);
1060
1061 list_add_tail(&vport->qe, &fabric->vport_q);
1062 fabric->num_vports++;
1063 bfa_wc_up(&fabric->wc);
1064}
1065
5fbe25c7 1066/*
a36c61f9
KG
1067 * A child vport is being deleted from fabric.
1068 *
1069 * Vport is being deleted.
1070 */
1071void
1072bfa_fcs_fabric_delvport(struct bfa_fcs_fabric_s *fabric,
1073 struct bfa_fcs_vport_s *vport)
1074{
1075 list_del(&vport->qe);
1076 fabric->num_vports--;
1077 bfa_wc_down(&fabric->wc);
1078}
1079
a36c61f9 1080
5fbe25c7 1081/*
25985edc 1082 * Lookup for a vport within a fabric given its pwwn
a36c61f9
KG
1083 */
1084struct bfa_fcs_vport_s *
1085bfa_fcs_fabric_vport_lookup(struct bfa_fcs_fabric_s *fabric, wwn_t pwwn)
1086{
1087 struct bfa_fcs_vport_s *vport;
1088 struct list_head *qe;
1089
1090 list_for_each(qe, &fabric->vport_q) {
1091 vport = (struct bfa_fcs_vport_s *) qe;
1092 if (bfa_fcs_lport_get_pwwn(&vport->lport) == pwwn)
1093 return vport;
1094 }
1095
1096 return NULL;
1097}
1098
a36c61f9
KG
1099
1100/*
1101 * Get OUI of the attached switch.
1102 *
1103 * Note : Use of this function should be avoided as much as possible.
1104 * This function should be used only if there is any requirement
1105* to check for FOS version below 6.3.
1106 * To check if the attached fabric is a brocade fabric, use
1107 * bfa_lps_is_brcd_fabric() which works for FOS versions 6.3
1108 * or above only.
1109 */
1110
1111u16
1112bfa_fcs_fabric_get_switch_oui(struct bfa_fcs_fabric_s *fabric)
1113{
1114 wwn_t fab_nwwn;
1115 u8 *tmp;
1116 u16 oui;
1117
f7f73812 1118 fab_nwwn = fabric->lps->pr_nwwn;
a36c61f9
KG
1119
1120 tmp = (u8 *)&fab_nwwn;
1121 oui = (tmp[3] << 8) | tmp[4];
1122
1123 return oui;
1124}
5fbe25c7 1125/*
a36c61f9
KG
1126 * Unsolicited frame receive handling.
1127 */
1128void
1129bfa_fcs_fabric_uf_recv(struct bfa_fcs_fabric_s *fabric, struct fchs_s *fchs,
1130 u16 len)
1131{
1132 u32 pid = fchs->d_id;
1133 struct bfa_fcs_vport_s *vport;
1134 struct list_head *qe;
1135 struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
1136 struct fc_logi_s *flogi = (struct fc_logi_s *) els_cmd;
1137
1138 bfa_trc(fabric->fcs, len);
1139 bfa_trc(fabric->fcs, pid);
1140
5fbe25c7 1141 /*
a36c61f9
KG
1142 * Look for our own FLOGI frames being looped back. This means an
1143 * external loopback cable is in place. Our own FLOGI frames are
1144 * sometimes looped back when switch port gets temporarily bypassed.
1145 */
f16a1750 1146 if ((pid == bfa_ntoh3b(FC_FABRIC_PORT)) &&
a36c61f9
KG
1147 (els_cmd->els_code == FC_ELS_FLOGI) &&
1148 (flogi->port_name == bfa_fcs_lport_get_pwwn(&fabric->bport))) {
1149 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_LOOPBACK);
1150 return;
1151 }
1152
5fbe25c7 1153 /*
a36c61f9
KG
1154 * FLOGI/EVFP exchanges should be consumed by base fabric.
1155 */
f16a1750 1156 if (fchs->d_id == bfa_hton3b(FC_FABRIC_PORT)) {
a36c61f9
KG
1157 bfa_trc(fabric->fcs, pid);
1158 bfa_fcs_fabric_process_uf(fabric, fchs, len);
1159 return;
1160 }
1161
1162 if (fabric->bport.pid == pid) {
5fbe25c7 1163 /*
a36c61f9
KG
1164 * All authentication frames should be routed to auth
1165 */
1166 bfa_trc(fabric->fcs, els_cmd->els_code);
1167 if (els_cmd->els_code == FC_ELS_AUTH) {
1168 bfa_trc(fabric->fcs, els_cmd->els_code);
1169 return;
1170 }
1171
1172 bfa_trc(fabric->fcs, *(u8 *) ((u8 *) fchs));
1173 bfa_fcs_lport_uf_recv(&fabric->bport, fchs, len);
1174 return;
1175 }
1176
5fbe25c7 1177 /*
a36c61f9
KG
1178 * look for a matching local port ID
1179 */
1180 list_for_each(qe, &fabric->vport_q) {
1181 vport = (struct bfa_fcs_vport_s *) qe;
1182 if (vport->lport.pid == pid) {
1183 bfa_fcs_lport_uf_recv(&vport->lport, fchs, len);
1184 return;
1185 }
1186 }
1187 bfa_trc(fabric->fcs, els_cmd->els_code);
1188 bfa_fcs_lport_uf_recv(&fabric->bport, fchs, len);
1189}
1190
5fbe25c7 1191/*
a36c61f9
KG
1192 * Unsolicited frames to be processed by fabric.
1193 */
1194static void
1195bfa_fcs_fabric_process_uf(struct bfa_fcs_fabric_s *fabric, struct fchs_s *fchs,
1196 u16 len)
1197{
1198 struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
1199
1200 bfa_trc(fabric->fcs, els_cmd->els_code);
1201
1202 switch (els_cmd->els_code) {
1203 case FC_ELS_FLOGI:
1204 bfa_fcs_fabric_process_flogi(fabric, fchs, len);
1205 break;
1206
1207 default:
1208 /*
1209 * need to generate a LS_RJT
1210 */
1211 break;
1212 }
1213}
1214
5fbe25c7 1215/*
a36c61f9
KG
1216 * Process incoming FLOGI
1217 */
1218static void
1219bfa_fcs_fabric_process_flogi(struct bfa_fcs_fabric_s *fabric,
1220 struct fchs_s *fchs, u16 len)
1221{
1222 struct fc_logi_s *flogi = (struct fc_logi_s *) (fchs + 1);
1223 struct bfa_fcs_lport_s *bport = &fabric->bport;
1224
1225 bfa_trc(fabric->fcs, fchs->s_id);
1226
1227 fabric->stats.flogi_rcvd++;
1228 /*
1229 * Check port type. It should be 0 = n-port.
1230 */
1231 if (flogi->csp.port_type) {
1232 /*
1233 * @todo: may need to send a LS_RJT
1234 */
1235 bfa_trc(fabric->fcs, flogi->port_name);
1236 fabric->stats.flogi_rejected++;
1237 return;
1238 }
1239
ba816ea8 1240 fabric->bb_credit = be16_to_cpu(flogi->csp.bbcred);
be540a99 1241 fabric->lps->pr_bbscn = (be16_to_cpu(flogi->csp.rxsz) >> 12);
a36c61f9
KG
1242 bport->port_topo.pn2n.rem_port_wwn = flogi->port_name;
1243 bport->port_topo.pn2n.reply_oxid = fchs->ox_id;
1244
1245 /*
1246 * Send a Flogi Acc
1247 */
1248 bfa_fcs_fabric_send_flogi_acc(fabric);
1249 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_NO_FABRIC);
1250}
1251
1252static void
1253bfa_fcs_fabric_send_flogi_acc(struct bfa_fcs_fabric_s *fabric)
1254{
1255 struct bfa_lport_cfg_s *pcfg = &fabric->bport.port_cfg;
1256 struct bfa_fcs_lport_n2n_s *n2n_port = &fabric->bport.port_topo.pn2n;
1257 struct bfa_s *bfa = fabric->fcs->bfa;
1258 struct bfa_fcxp_s *fcxp;
1259 u16 reqlen;
1260 struct fchs_s fchs;
1261
1262 fcxp = bfa_fcs_fcxp_alloc(fabric->fcs);
5fbe25c7 1263 /*
a36c61f9
KG
1264 * Do not expect this failure -- expect remote node to retry
1265 */
1266 if (!fcxp)
1267 return;
1268
1269 reqlen = fc_flogi_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
f16a1750 1270 bfa_hton3b(FC_FABRIC_PORT),
a36c61f9
KG
1271 n2n_port->reply_oxid, pcfg->pwwn,
1272 pcfg->nwwn,
1273 bfa_fcport_get_maxfrsize(bfa),
be540a99
KG
1274 bfa_fcport_get_rx_bbcredit(bfa),
1275 bfa_fcs_fabric_oper_bbscn(fabric));
a36c61f9 1276
f7f73812 1277 bfa_fcxp_send(fcxp, NULL, fabric->vf_id, fabric->lps->lp_tag,
a36c61f9
KG
1278 BFA_FALSE, FC_CLASS_3,
1279 reqlen, &fchs, bfa_fcs_fabric_flogiacc_comp, fabric,
1280 FC_MAX_PDUSZ, 0);
1281}
1282
5fbe25c7 1283/*
a36c61f9
KG
1284 * Flogi Acc completion callback.
1285 */
1286static void
1287bfa_fcs_fabric_flogiacc_comp(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
1288 bfa_status_t status, u32 rsp_len,
1289 u32 resid_len, struct fchs_s *rspfchs)
1290{
1291 struct bfa_fcs_fabric_s *fabric = cbarg;
1292
1293 bfa_trc(fabric->fcs, status);
1294}
1295
1296/*
1297 *
1298 * @param[in] fabric - fabric
1299 * @param[in] wwn_t - new fabric name
1300 *
1301 * @return - none
1302 */
1303void
1304bfa_fcs_fabric_set_fabric_name(struct bfa_fcs_fabric_s *fabric,
1305 wwn_t fabric_name)
1306{
1307 struct bfad_s *bfad = (struct bfad_s *)fabric->fcs->bfad;
1308 char pwwn_ptr[BFA_STRING_32];
1309 char fwwn_ptr[BFA_STRING_32];
1310
1311 bfa_trc(fabric->fcs, fabric_name);
1312
1313 if (fabric->fabric_name == 0) {
1314 /*
1315 * With BRCD switches, we don't get Fabric Name in FLOGI.
1316 * Don't generate a fabric name change event in this case.
1317 */
1318 fabric->fabric_name = fabric_name;
1319 } else {
1320 fabric->fabric_name = fabric_name;
1321 wwn2str(pwwn_ptr, bfa_fcs_lport_get_pwwn(&fabric->bport));
1322 wwn2str(fwwn_ptr,
1323 bfa_fcs_lport_get_fabric_name(&fabric->bport));
88166242 1324 BFA_LOG(KERN_WARNING, bfad, bfa_log_level,
a36c61f9
KG
1325 "Base port WWN = %s Fabric WWN = %s\n",
1326 pwwn_ptr, fwwn_ptr);
1327 }
1328}
1329
5fbe25c7 1330/*
a36c61f9
KG
1331 * Returns FCS vf structure for a given vf_id.
1332 *
1333 * param[in] vf_id - VF_ID
1334 *
1335 * return
1336 * If lookup succeeds, retuns fcs vf object, otherwise returns NULL
1337 */
1338bfa_fcs_vf_t *
1339bfa_fcs_vf_lookup(struct bfa_fcs_s *fcs, u16 vf_id)
1340{
1341 bfa_trc(fcs, vf_id);
1342 if (vf_id == FC_VF_ID_NULL)
1343 return &fcs->fabric;
1344
1345 return NULL;
1346}
1347
5fbe25c7 1348/*
a36c61f9
KG
1349 * BFA FCS PPORT ( physical port)
1350 */
1351static void
1352bfa_fcs_port_event_handler(void *cbarg, enum bfa_port_linkstate event)
1353{
1354 struct bfa_fcs_s *fcs = cbarg;
1355
1356 bfa_trc(fcs, event);
1357
1358 switch (event) {
1359 case BFA_PORT_LINKUP:
1360 bfa_fcs_fabric_link_up(&fcs->fabric);
1361 break;
1362
1363 case BFA_PORT_LINKDOWN:
1364 bfa_fcs_fabric_link_down(&fcs->fabric);
1365 break;
1366
1367 default:
d4b671c5 1368 WARN_ON(1);
a36c61f9
KG
1369 }
1370}
1371
1372void
1373bfa_fcs_port_attach(struct bfa_fcs_s *fcs)
1374{
1375 bfa_fcport_event_register(fcs->bfa, bfa_fcs_port_event_handler, fcs);
1376}
1377
5fbe25c7 1378/*
a36c61f9
KG
1379 * BFA FCS UF ( Unsolicited Frames)
1380 */
1381
5fbe25c7 1382/*
a36c61f9
KG
1383 * BFA callback for unsolicited frame receive handler.
1384 *
1385 * @param[in] cbarg callback arg for receive handler
1386 * @param[in] uf unsolicited frame descriptor
1387 *
1388 * @return None
1389 */
1390static void
1391bfa_fcs_uf_recv(void *cbarg, struct bfa_uf_s *uf)
1392{
1393 struct bfa_fcs_s *fcs = (struct bfa_fcs_s *) cbarg;
1394 struct fchs_s *fchs = bfa_uf_get_frmbuf(uf);
1395 u16 len = bfa_uf_get_frmlen(uf);
1396 struct fc_vft_s *vft;
1397 struct bfa_fcs_fabric_s *fabric;
1398
5fbe25c7 1399 /*
a36c61f9
KG
1400 * check for VFT header
1401 */
1402 if (fchs->routing == FC_RTG_EXT_HDR &&
1403 fchs->cat_info == FC_CAT_VFT_HDR) {
1404 bfa_stats(fcs, uf.tagged);
1405 vft = bfa_uf_get_frmbuf(uf);
1406 if (fcs->port_vfid == vft->vf_id)
1407 fabric = &fcs->fabric;
1408 else
1409 fabric = bfa_fcs_vf_lookup(fcs, (u16) vft->vf_id);
1410
5fbe25c7 1411 /*
a36c61f9
KG
1412 * drop frame if vfid is unknown
1413 */
1414 if (!fabric) {
d4b671c5 1415 WARN_ON(1);
a36c61f9
KG
1416 bfa_stats(fcs, uf.vfid_unknown);
1417 bfa_uf_free(uf);
1418 return;
1419 }
1420
5fbe25c7 1421 /*
a36c61f9
KG
1422 * skip vft header
1423 */
1424 fchs = (struct fchs_s *) (vft + 1);
1425 len -= sizeof(struct fc_vft_s);
1426
1427 bfa_trc(fcs, vft->vf_id);
1428 } else {
1429 bfa_stats(fcs, uf.untagged);
1430 fabric = &fcs->fabric;
1431 }
1432
1433 bfa_trc(fcs, ((u32 *) fchs)[0]);
1434 bfa_trc(fcs, ((u32 *) fchs)[1]);
1435 bfa_trc(fcs, ((u32 *) fchs)[2]);
1436 bfa_trc(fcs, ((u32 *) fchs)[3]);
1437 bfa_trc(fcs, ((u32 *) fchs)[4]);
1438 bfa_trc(fcs, ((u32 *) fchs)[5]);
1439 bfa_trc(fcs, len);
1440
1441 bfa_fcs_fabric_uf_recv(fabric, fchs, len);
1442 bfa_uf_free(uf);
1443}
1444
1445void
1446bfa_fcs_uf_attach(struct bfa_fcs_s *fcs)
1447{
1448 bfa_uf_recv_register(fcs->bfa, bfa_fcs_uf_recv, fcs);
1449}