blob: 671a1a227f94a6729869baa12377f8d9cc5ade55 [file] [log] [blame]
Jing Huang7725ccf2009-09-23 17:46:15 -07001/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002 * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
Jing Huang7725ccf2009-09-23 17:46:15 -07003 * 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
Jing Huang5fbe25c2010-10-18 17:17:23 -070018/*
Jing Huang7725ccf2009-09-23 17:46:15 -070019 * bfa_fcs.c BFA FCS main
20 */
21
Maggie Zhangf16a1752010-12-09 19:12:32 -080022#include "bfad_drv.h"
Krishna Gudipati7826f302011-07-20 16:59:13 -070023#include "bfad_im.h"
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070024#include "bfa_fcs.h"
25#include "bfa_fcbuild.h"
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070026
27BFA_TRC_FILE(FCS, FCS);
Jing Huang7725ccf2009-09-23 17:46:15 -070028
Jing Huang5fbe25c2010-10-18 17:17:23 -070029/*
Jing Huang7725ccf2009-09-23 17:46:15 -070030 * FCS sub-modules
31 */
32struct bfa_fcs_mod_s {
Krishna Gudipati82794a22010-03-03 17:43:30 -080033 void (*attach) (struct bfa_fcs_s *fcs);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070034 void (*modinit) (struct bfa_fcs_s *fcs);
35 void (*modexit) (struct bfa_fcs_s *fcs);
Jing Huang7725ccf2009-09-23 17:46:15 -070036};
37
38#define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
39
40static struct bfa_fcs_mod_s fcs_modules[] = {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070041 { bfa_fcs_port_attach, NULL, NULL },
Krishna Gudipati82794a22010-03-03 17:43:30 -080042 { bfa_fcs_uf_attach, NULL, NULL },
43 { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070044 bfa_fcs_fabric_modexit },
Jing Huang7725ccf2009-09-23 17:46:15 -070045};
46
Jing Huang5fbe25c2010-10-18 17:17:23 -070047/*
Jing Huang7725ccf2009-09-23 17:46:15 -070048 * fcs_api BFA FCS API
49 */
50
51static void
52bfa_fcs_exit_comp(void *fcs_cbarg)
53{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070054 struct bfa_fcs_s *fcs = fcs_cbarg;
55 struct bfad_s *bfad = fcs->bfad;
Jing Huang7725ccf2009-09-23 17:46:15 -070056
57 complete(&bfad->comp);
58}
59
60
61
Jing Huang5fbe25c2010-10-18 17:17:23 -070062/*
Jing Huang7725ccf2009-09-23 17:46:15 -070063 * fcs_api BFA FCS API
64 */
65
Jing Huang5fbe25c2010-10-18 17:17:23 -070066/*
Krishna Gudipati82794a22010-03-03 17:43:30 -080067 * fcs attach -- called once to initialize data structures at driver attach time
Jing Huang7725ccf2009-09-23 17:46:15 -070068 */
69void
Krishna Gudipati82794a22010-03-03 17:43:30 -080070bfa_fcs_attach(struct bfa_fcs_s *fcs, struct bfa_s *bfa, struct bfad_s *bfad,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070071 bfa_boolean_t min_cfg)
Jing Huang7725ccf2009-09-23 17:46:15 -070072{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070073 int i;
Jing Huang7725ccf2009-09-23 17:46:15 -070074 struct bfa_fcs_mod_s *mod;
75
76 fcs->bfa = bfa;
77 fcs->bfad = bfad;
78 fcs->min_cfg = min_cfg;
79
Maggie Zhangf7f738122010-12-09 19:08:43 -080080 bfa->fcs = BFA_TRUE;
Jing Huang7725ccf2009-09-23 17:46:15 -070081 fcbuild_init();
82
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070083 for (i = 0; i < sizeof(fcs_modules) / sizeof(fcs_modules[0]); i++) {
Jing Huang7725ccf2009-09-23 17:46:15 -070084 mod = &fcs_modules[i];
Krishna Gudipati82794a22010-03-03 17:43:30 -080085 if (mod->attach)
86 mod->attach(fcs);
87 }
88}
89
Jing Huang5fbe25c2010-10-18 17:17:23 -070090/*
Krishna Gudipati82794a22010-03-03 17:43:30 -080091 * fcs initialization, called once after bfa initialization is complete
92 */
93void
94bfa_fcs_init(struct bfa_fcs_s *fcs)
95{
Krishna Gudipati75332a72011-06-13 15:54:31 -070096 int i;
Krishna Gudipati82794a22010-03-03 17:43:30 -080097 struct bfa_fcs_mod_s *mod;
98
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070099 for (i = 0; i < sizeof(fcs_modules) / sizeof(fcs_modules[0]); i++) {
Krishna Gudipati82794a22010-03-03 17:43:30 -0800100 mod = &fcs_modules[i];
101 if (mod->modinit)
102 mod->modinit(fcs);
Jing Huang7725ccf2009-09-23 17:46:15 -0700103 }
Krishna Gudipati75332a72011-06-13 15:54:31 -0700104}
105
106/*
107 * FCS update cfg - reset the pwwn/nwwn of fabric base logical port
108 * with values learned during bfa_init firmware GETATTR REQ.
109 */
110void
111bfa_fcs_update_cfg(struct bfa_fcs_s *fcs)
112{
113 struct bfa_fcs_fabric_s *fabric = &fcs->fabric;
114 struct bfa_lport_cfg_s *port_cfg = &fabric->bport.port_cfg;
115 struct bfa_ioc_s *ioc = &fabric->fcs->bfa->ioc;
116
117 port_cfg->nwwn = ioc->attr->nwwn;
118 port_cfg->pwwn = ioc->attr->pwwn;
119}
120
121/*
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700122 * Stop FCS operations.
123 */
124void
125bfa_fcs_stop(struct bfa_fcs_s *fcs)
126{
127 bfa_wc_init(&fcs->wc, bfa_fcs_exit_comp, fcs);
128 bfa_wc_up(&fcs->wc);
129 bfa_fcs_fabric_modstop(fcs);
130 bfa_wc_wait(&fcs->wc);
131}
132
133/*
Krishna Gudipati75332a72011-06-13 15:54:31 -0700134 * fcs pbc vport initialization
135 */
136void
137bfa_fcs_pbc_vport_init(struct bfa_fcs_s *fcs)
138{
139 int i, npbc_vports;
140 struct bfi_pbc_vport_s pbc_vports[BFI_PBC_MAX_VPORTS];
141
Jing Huangd9883542010-07-08 19:46:26 -0700142 /* Initialize pbc vports */
143 if (!fcs->min_cfg) {
144 npbc_vports =
Krishna Gudipati75332a72011-06-13 15:54:31 -0700145 bfa_iocfc_get_pbc_vports(fcs->bfa, pbc_vports);
Jing Huangd9883542010-07-08 19:46:26 -0700146 for (i = 0; i < npbc_vports; i++)
147 bfa_fcb_pbc_vport_create(fcs->bfa->bfad, pbc_vports[i]);
148 }
Jing Huang7725ccf2009-09-23 17:46:15 -0700149}
150
Jing Huang5fbe25c2010-10-18 17:17:23 -0700151/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700152 * brief
153 * FCS driver details initialization.
Jing Huang7725ccf2009-09-23 17:46:15 -0700154 *
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700155 * param[in] fcs FCS instance
156 * param[in] driver_info Driver Details
Jing Huang7725ccf2009-09-23 17:46:15 -0700157 *
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700158 * return None
Jing Huang7725ccf2009-09-23 17:46:15 -0700159 */
160void
161bfa_fcs_driver_info_init(struct bfa_fcs_s *fcs,
162 struct bfa_fcs_driver_info_s *driver_info)
163{
164
165 fcs->driver_info = *driver_info;
166
167 bfa_fcs_fabric_psymb_init(&fcs->fabric);
168}
169
Jing Huang5fbe25c2010-10-18 17:17:23 -0700170/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700171 * brief
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700172 * FCS instance cleanup and exit.
Jing Huang7725ccf2009-09-23 17:46:15 -0700173 *
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700174 * param[in] fcs FCS instance
175 * return None
Jing Huang7725ccf2009-09-23 17:46:15 -0700176 */
177void
178bfa_fcs_exit(struct bfa_fcs_s *fcs)
179{
180 struct bfa_fcs_mod_s *mod;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700181 int nmods, i;
Jing Huang7725ccf2009-09-23 17:46:15 -0700182
183 bfa_wc_init(&fcs->wc, bfa_fcs_exit_comp, fcs);
184
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700185 nmods = sizeof(fcs_modules) / sizeof(fcs_modules[0]);
186
187 for (i = 0; i < nmods; i++) {
Jing Huang7725ccf2009-09-23 17:46:15 -0700188
189 mod = &fcs_modules[i];
Krishna Gudipati82794a22010-03-03 17:43:30 -0800190 if (mod->modexit) {
191 bfa_wc_up(&fcs->wc);
192 mod->modexit(fcs);
193 }
Jing Huang7725ccf2009-09-23 17:46:15 -0700194 }
195
196 bfa_wc_wait(&fcs->wc);
197}
198
199
Jing Huang5fbe25c2010-10-18 17:17:23 -0700200/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700201 * Fabric module implementation.
202 */
Jing Huang7725ccf2009-09-23 17:46:15 -0700203
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700204#define BFA_FCS_FABRIC_RETRY_DELAY (2000) /* Milliseconds */
205#define BFA_FCS_FABRIC_CLEANUP_DELAY (10000) /* Milliseconds */
206
207#define bfa_fcs_fabric_set_opertype(__fabric) do { \
Krishna Gudipatid7be54c2011-06-24 20:24:52 -0700208 if (bfa_fcport_get_topology((__fabric)->fcs->bfa) \
209 == BFA_PORT_TOPOLOGY_P2P) { \
210 if (fabric->fab_type == BFA_FCS_FABRIC_SWITCHED) \
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700211 (__fabric)->oper_type = BFA_PORT_TYPE_NPORT; \
212 else \
Krishna Gudipatid7be54c2011-06-24 20:24:52 -0700213 (__fabric)->oper_type = BFA_PORT_TYPE_P2P; \
214 } else \
215 (__fabric)->oper_type = BFA_PORT_TYPE_NLPORT; \
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700216} while (0)
217
218/*
219 * forward declarations
220 */
221static void bfa_fcs_fabric_init(struct bfa_fcs_fabric_s *fabric);
222static void bfa_fcs_fabric_login(struct bfa_fcs_fabric_s *fabric);
223static void bfa_fcs_fabric_notify_online(struct bfa_fcs_fabric_s *fabric);
224static void bfa_fcs_fabric_notify_offline(struct bfa_fcs_fabric_s *fabric);
225static void bfa_fcs_fabric_delay(void *cbarg);
226static void bfa_fcs_fabric_delete(struct bfa_fcs_fabric_s *fabric);
227static void bfa_fcs_fabric_delete_comp(void *cbarg);
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700228static void bfa_fcs_fabric_stop(struct bfa_fcs_fabric_s *fabric);
229static void bfa_fcs_fabric_stop_comp(void *cbarg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700230static void bfa_fcs_fabric_process_uf(struct bfa_fcs_fabric_s *fabric,
231 struct fchs_s *fchs, u16 len);
232static void bfa_fcs_fabric_process_flogi(struct bfa_fcs_fabric_s *fabric,
233 struct fchs_s *fchs, u16 len);
234static void bfa_fcs_fabric_send_flogi_acc(struct bfa_fcs_fabric_s *fabric);
235static void bfa_fcs_fabric_flogiacc_comp(void *fcsarg,
236 struct bfa_fcxp_s *fcxp, void *cbarg,
237 bfa_status_t status,
238 u32 rsp_len,
239 u32 resid_len,
240 struct fchs_s *rspfchs);
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700241static u8 bfa_fcs_fabric_oper_bbscn(struct bfa_fcs_fabric_s *fabric);
242static bfa_boolean_t bfa_fcs_fabric_is_bbscn_enabled(
243 struct bfa_fcs_fabric_s *fabric);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700244
245static void bfa_fcs_fabric_sm_uninit(struct bfa_fcs_fabric_s *fabric,
246 enum bfa_fcs_fabric_event event);
247static void bfa_fcs_fabric_sm_created(struct bfa_fcs_fabric_s *fabric,
248 enum bfa_fcs_fabric_event event);
249static void bfa_fcs_fabric_sm_linkdown(struct bfa_fcs_fabric_s *fabric,
250 enum bfa_fcs_fabric_event event);
251static void bfa_fcs_fabric_sm_flogi(struct bfa_fcs_fabric_s *fabric,
252 enum bfa_fcs_fabric_event event);
253static void bfa_fcs_fabric_sm_flogi_retry(struct bfa_fcs_fabric_s *fabric,
254 enum bfa_fcs_fabric_event event);
255static void bfa_fcs_fabric_sm_auth(struct bfa_fcs_fabric_s *fabric,
256 enum bfa_fcs_fabric_event event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700257static void bfa_fcs_fabric_sm_nofabric(struct bfa_fcs_fabric_s *fabric,
258 enum bfa_fcs_fabric_event event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700259static void bfa_fcs_fabric_sm_evfp(struct bfa_fcs_fabric_s *fabric,
260 enum bfa_fcs_fabric_event event);
261static void bfa_fcs_fabric_sm_evfp_done(struct bfa_fcs_fabric_s *fabric,
262 enum bfa_fcs_fabric_event event);
263static void bfa_fcs_fabric_sm_isolated(struct bfa_fcs_fabric_s *fabric,
264 enum bfa_fcs_fabric_event event);
265static void bfa_fcs_fabric_sm_deleting(struct bfa_fcs_fabric_s *fabric,
266 enum bfa_fcs_fabric_event event);
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700267static void bfa_fcs_fabric_sm_stopping(struct bfa_fcs_fabric_s *fabric,
268 enum bfa_fcs_fabric_event event);
269static void bfa_fcs_fabric_sm_cleanup(struct bfa_fcs_fabric_s *fabric,
270 enum bfa_fcs_fabric_event event);
Jing Huang5fbe25c2010-10-18 17:17:23 -0700271/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700272 * Beginning state before fabric creation.
273 */
274static void
275bfa_fcs_fabric_sm_uninit(struct bfa_fcs_fabric_s *fabric,
276 enum bfa_fcs_fabric_event event)
277{
278 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
279 bfa_trc(fabric->fcs, event);
280
281 switch (event) {
282 case BFA_FCS_FABRIC_SM_CREATE:
283 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_created);
284 bfa_fcs_fabric_init(fabric);
285 bfa_fcs_lport_init(&fabric->bport, &fabric->bport.port_cfg);
286 break;
287
288 case BFA_FCS_FABRIC_SM_LINK_UP:
289 case BFA_FCS_FABRIC_SM_LINK_DOWN:
290 break;
291
292 default:
293 bfa_sm_fault(fabric->fcs, event);
294 }
295}
296
Jing Huang5fbe25c2010-10-18 17:17:23 -0700297/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700298 * Beginning state before fabric creation.
299 */
300static void
301bfa_fcs_fabric_sm_created(struct bfa_fcs_fabric_s *fabric,
302 enum bfa_fcs_fabric_event event)
303{
304 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
305 bfa_trc(fabric->fcs, event);
306
307 switch (event) {
308 case BFA_FCS_FABRIC_SM_START:
309 if (bfa_fcport_is_linkup(fabric->fcs->bfa)) {
310 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_flogi);
311 bfa_fcs_fabric_login(fabric);
312 } else
313 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
314 break;
315
316 case BFA_FCS_FABRIC_SM_LINK_UP:
317 case BFA_FCS_FABRIC_SM_LINK_DOWN:
318 break;
319
320 case BFA_FCS_FABRIC_SM_DELETE:
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -0700321 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
322 bfa_fcs_fabric_delete(fabric);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700323 break;
324
325 default:
326 bfa_sm_fault(fabric->fcs, event);
327 }
328}
329
Jing Huang5fbe25c2010-10-18 17:17:23 -0700330/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700331 * Link is down, awaiting LINK UP event from port. This is also the
332 * first state at fabric creation.
333 */
334static void
335bfa_fcs_fabric_sm_linkdown(struct bfa_fcs_fabric_s *fabric,
336 enum bfa_fcs_fabric_event event)
337{
338 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
339 bfa_trc(fabric->fcs, event);
340
341 switch (event) {
342 case BFA_FCS_FABRIC_SM_LINK_UP:
343 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_flogi);
344 bfa_fcs_fabric_login(fabric);
345 break;
346
347 case BFA_FCS_FABRIC_SM_RETRY_OP:
348 break;
349
350 case BFA_FCS_FABRIC_SM_DELETE:
351 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
352 bfa_fcs_fabric_delete(fabric);
353 break;
354
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700355 case BFA_FCS_FABRIC_SM_STOP:
356 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_cleanup);
357 bfa_fcs_fabric_stop(fabric);
358 break;
359
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700360 default:
361 bfa_sm_fault(fabric->fcs, event);
362 }
363}
364
Jing Huang5fbe25c2010-10-18 17:17:23 -0700365/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700366 * FLOGI is in progress, awaiting FLOGI reply.
367 */
368static void
369bfa_fcs_fabric_sm_flogi(struct bfa_fcs_fabric_s *fabric,
370 enum bfa_fcs_fabric_event event)
371{
372 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
373 bfa_trc(fabric->fcs, event);
374
375 switch (event) {
376 case BFA_FCS_FABRIC_SM_CONT_OP:
377
378 bfa_fcport_set_tx_bbcredit(fabric->fcs->bfa,
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700379 fabric->bb_credit,
380 bfa_fcs_fabric_oper_bbscn(fabric));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700381 fabric->fab_type = BFA_FCS_FABRIC_SWITCHED;
382
383 if (fabric->auth_reqd && fabric->is_auth) {
384 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_auth);
385 bfa_trc(fabric->fcs, event);
386 } else {
387 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_online);
388 bfa_fcs_fabric_notify_online(fabric);
389 }
390 break;
391
392 case BFA_FCS_FABRIC_SM_RETRY_OP:
393 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_flogi_retry);
394 bfa_timer_start(fabric->fcs->bfa, &fabric->delay_timer,
395 bfa_fcs_fabric_delay, fabric,
396 BFA_FCS_FABRIC_RETRY_DELAY);
397 break;
398
399 case BFA_FCS_FABRIC_SM_LOOPBACK:
400 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_loopback);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800401 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700402 bfa_fcs_fabric_set_opertype(fabric);
403 break;
404
405 case BFA_FCS_FABRIC_SM_NO_FABRIC:
406 fabric->fab_type = BFA_FCS_FABRIC_N2N;
407 bfa_fcport_set_tx_bbcredit(fabric->fcs->bfa,
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700408 fabric->bb_credit,
409 bfa_fcs_fabric_oper_bbscn(fabric));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700410 bfa_fcs_fabric_notify_online(fabric);
411 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_nofabric);
412 break;
413
414 case BFA_FCS_FABRIC_SM_LINK_DOWN:
415 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800416 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700417 break;
418
419 case BFA_FCS_FABRIC_SM_DELETE:
420 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800421 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700422 bfa_fcs_fabric_delete(fabric);
423 break;
424
425 default:
426 bfa_sm_fault(fabric->fcs, event);
427 }
428}
429
430
431static void
432bfa_fcs_fabric_sm_flogi_retry(struct bfa_fcs_fabric_s *fabric,
433 enum bfa_fcs_fabric_event event)
434{
435 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
436 bfa_trc(fabric->fcs, event);
437
438 switch (event) {
439 case BFA_FCS_FABRIC_SM_DELAYED:
440 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_flogi);
441 bfa_fcs_fabric_login(fabric);
442 break;
443
444 case BFA_FCS_FABRIC_SM_LINK_DOWN:
445 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
446 bfa_timer_stop(&fabric->delay_timer);
447 break;
448
449 case BFA_FCS_FABRIC_SM_DELETE:
450 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
451 bfa_timer_stop(&fabric->delay_timer);
452 bfa_fcs_fabric_delete(fabric);
453 break;
454
455 default:
456 bfa_sm_fault(fabric->fcs, event);
457 }
458}
459
Jing Huang5fbe25c2010-10-18 17:17:23 -0700460/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700461 * Authentication is in progress, awaiting authentication results.
462 */
463static void
464bfa_fcs_fabric_sm_auth(struct bfa_fcs_fabric_s *fabric,
465 enum bfa_fcs_fabric_event event)
466{
467 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
468 bfa_trc(fabric->fcs, event);
469
470 switch (event) {
471 case BFA_FCS_FABRIC_SM_AUTH_FAILED:
472 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_auth_failed);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800473 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700474 break;
475
476 case BFA_FCS_FABRIC_SM_AUTH_SUCCESS:
477 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_online);
478 bfa_fcs_fabric_notify_online(fabric);
479 break;
480
481 case BFA_FCS_FABRIC_SM_PERF_EVFP:
482 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_evfp);
483 break;
484
485 case BFA_FCS_FABRIC_SM_LINK_DOWN:
486 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800487 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700488 break;
489
490 case BFA_FCS_FABRIC_SM_DELETE:
491 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
492 bfa_fcs_fabric_delete(fabric);
493 break;
494
495 default:
496 bfa_sm_fault(fabric->fcs, event);
497 }
498}
499
Jing Huang5fbe25c2010-10-18 17:17:23 -0700500/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700501 * Authentication failed
502 */
Maggie Zhangf7f738122010-12-09 19:08:43 -0800503void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700504bfa_fcs_fabric_sm_auth_failed(struct bfa_fcs_fabric_s *fabric,
505 enum bfa_fcs_fabric_event event)
506{
507 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
508 bfa_trc(fabric->fcs, event);
509
510 switch (event) {
511 case BFA_FCS_FABRIC_SM_LINK_DOWN:
512 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
513 bfa_fcs_fabric_notify_offline(fabric);
514 break;
515
516 case BFA_FCS_FABRIC_SM_DELETE:
517 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
518 bfa_fcs_fabric_delete(fabric);
519 break;
520
521 default:
522 bfa_sm_fault(fabric->fcs, event);
523 }
524}
525
Jing Huang5fbe25c2010-10-18 17:17:23 -0700526/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700527 * Port is in loopback mode.
528 */
Maggie Zhangf7f738122010-12-09 19:08:43 -0800529void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700530bfa_fcs_fabric_sm_loopback(struct bfa_fcs_fabric_s *fabric,
531 enum bfa_fcs_fabric_event event)
532{
533 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
534 bfa_trc(fabric->fcs, event);
535
536 switch (event) {
537 case BFA_FCS_FABRIC_SM_LINK_DOWN:
538 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
539 bfa_fcs_fabric_notify_offline(fabric);
540 break;
541
542 case BFA_FCS_FABRIC_SM_DELETE:
543 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
544 bfa_fcs_fabric_delete(fabric);
545 break;
546
547 default:
548 bfa_sm_fault(fabric->fcs, event);
549 }
550}
551
Jing Huang5fbe25c2010-10-18 17:17:23 -0700552/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700553 * There is no attached fabric - private loop or NPort-to-NPort topology.
554 */
555static void
556bfa_fcs_fabric_sm_nofabric(struct bfa_fcs_fabric_s *fabric,
557 enum bfa_fcs_fabric_event event)
558{
559 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
560 bfa_trc(fabric->fcs, event);
561
562 switch (event) {
563 case BFA_FCS_FABRIC_SM_LINK_DOWN:
564 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800565 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700566 bfa_fcs_fabric_notify_offline(fabric);
567 break;
568
569 case BFA_FCS_FABRIC_SM_DELETE:
570 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
571 bfa_fcs_fabric_delete(fabric);
572 break;
573
574 case BFA_FCS_FABRIC_SM_NO_FABRIC:
575 bfa_trc(fabric->fcs, fabric->bb_credit);
576 bfa_fcport_set_tx_bbcredit(fabric->fcs->bfa,
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700577 fabric->bb_credit,
578 bfa_fcs_fabric_oper_bbscn(fabric));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700579 break;
580
Krishna Gudipatid7be54c2011-06-24 20:24:52 -0700581 case BFA_FCS_FABRIC_SM_RETRY_OP:
582 break;
583
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700584 default:
585 bfa_sm_fault(fabric->fcs, event);
586 }
587}
588
Jing Huang5fbe25c2010-10-18 17:17:23 -0700589/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700590 * Fabric is online - normal operating state.
591 */
Maggie Zhangf7f738122010-12-09 19:08:43 -0800592void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700593bfa_fcs_fabric_sm_online(struct bfa_fcs_fabric_s *fabric,
594 enum bfa_fcs_fabric_event event)
595{
596 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
597 bfa_trc(fabric->fcs, event);
598
599 switch (event) {
600 case BFA_FCS_FABRIC_SM_LINK_DOWN:
601 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800602 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700603 bfa_fcs_fabric_notify_offline(fabric);
604 break;
605
606 case BFA_FCS_FABRIC_SM_DELETE:
607 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
608 bfa_fcs_fabric_delete(fabric);
609 break;
610
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700611 case BFA_FCS_FABRIC_SM_STOP:
612 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_stopping);
613 bfa_fcs_fabric_stop(fabric);
614 break;
615
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700616 case BFA_FCS_FABRIC_SM_AUTH_FAILED:
617 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_auth_failed);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800618 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700619 break;
620
621 case BFA_FCS_FABRIC_SM_AUTH_SUCCESS:
622 break;
623
624 default:
625 bfa_sm_fault(fabric->fcs, event);
626 }
627}
628
Jing Huang5fbe25c2010-10-18 17:17:23 -0700629/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700630 * Exchanging virtual fabric parameters.
631 */
632static void
633bfa_fcs_fabric_sm_evfp(struct bfa_fcs_fabric_s *fabric,
634 enum bfa_fcs_fabric_event event)
635{
636 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
637 bfa_trc(fabric->fcs, event);
638
639 switch (event) {
640 case BFA_FCS_FABRIC_SM_CONT_OP:
641 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_evfp_done);
642 break;
643
644 case BFA_FCS_FABRIC_SM_ISOLATE:
645 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_isolated);
646 break;
647
648 default:
649 bfa_sm_fault(fabric->fcs, event);
650 }
651}
652
Jing Huang5fbe25c2010-10-18 17:17:23 -0700653/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700654 * EVFP exchange complete and VFT tagging is enabled.
655 */
656static void
657bfa_fcs_fabric_sm_evfp_done(struct bfa_fcs_fabric_s *fabric,
658 enum bfa_fcs_fabric_event event)
659{
660 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
661 bfa_trc(fabric->fcs, event);
662}
663
Jing Huang5fbe25c2010-10-18 17:17:23 -0700664/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700665 * Port is isolated after EVFP exchange due to VF_ID mismatch (N and F).
666 */
667static void
668bfa_fcs_fabric_sm_isolated(struct bfa_fcs_fabric_s *fabric,
669 enum bfa_fcs_fabric_event event)
670{
671 struct bfad_s *bfad = (struct bfad_s *)fabric->fcs->bfad;
672 char pwwn_ptr[BFA_STRING_32];
673
674 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
675 bfa_trc(fabric->fcs, event);
676 wwn2str(pwwn_ptr, fabric->bport.port_cfg.pwwn);
677
Jing Huang88166242010-12-09 17:11:53 -0800678 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700679 "Port is isolated due to VF_ID mismatch. "
680 "PWWN: %s Port VF_ID: %04x switch port VF_ID: %04x.",
681 pwwn_ptr, fabric->fcs->port_vfid,
682 fabric->event_arg.swp_vfid);
683}
684
Jing Huang5fbe25c2010-10-18 17:17:23 -0700685/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700686 * Fabric is being deleted, awaiting vport delete completions.
687 */
688static void
689bfa_fcs_fabric_sm_deleting(struct bfa_fcs_fabric_s *fabric,
690 enum bfa_fcs_fabric_event event)
691{
692 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
693 bfa_trc(fabric->fcs, event);
694
695 switch (event) {
696 case BFA_FCS_FABRIC_SM_DELCOMP:
697 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_uninit);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800698 bfa_wc_down(&fabric->fcs->wc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700699 break;
700
701 case BFA_FCS_FABRIC_SM_LINK_UP:
702 break;
703
704 case BFA_FCS_FABRIC_SM_LINK_DOWN:
705 bfa_fcs_fabric_notify_offline(fabric);
706 break;
707
708 default:
709 bfa_sm_fault(fabric->fcs, event);
710 }
711}
712
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700713/*
714 * Fabric is being stopped, awaiting vport stop completions.
715 */
716static void
717bfa_fcs_fabric_sm_stopping(struct bfa_fcs_fabric_s *fabric,
718 enum bfa_fcs_fabric_event event)
719{
720 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
721 bfa_trc(fabric->fcs, event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700722
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700723 switch (event) {
724 case BFA_FCS_FABRIC_SM_STOPCOMP:
725 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_cleanup);
726 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_LOGOUT);
727 break;
728
729 case BFA_FCS_FABRIC_SM_LINK_UP:
730 break;
731
732 case BFA_FCS_FABRIC_SM_LINK_DOWN:
733 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_cleanup);
734 break;
735
736 default:
737 bfa_sm_fault(fabric->fcs, event);
738 }
739}
740
741/*
742 * Fabric is being stopped, cleanup without FLOGO
743 */
744static void
745bfa_fcs_fabric_sm_cleanup(struct bfa_fcs_fabric_s *fabric,
746 enum bfa_fcs_fabric_event event)
747{
748 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
749 bfa_trc(fabric->fcs, event);
750
751 switch (event) {
752 case BFA_FCS_FABRIC_SM_STOPCOMP:
753 case BFA_FCS_FABRIC_SM_LOGOCOMP:
754 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_created);
755 bfa_wc_down(&(fabric->fcs)->wc);
756 break;
757
758 case BFA_FCS_FABRIC_SM_LINK_DOWN:
759 /*
760 * Ignore - can get this event if we get notified about IOC down
761 * before the fabric completion callbk is done.
762 */
763 break;
764
765 default:
766 bfa_sm_fault(fabric->fcs, event);
767 }
768}
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700769
Jing Huang5fbe25c2010-10-18 17:17:23 -0700770/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700771 * fcs_fabric_private fabric private functions
772 */
773
774static void
775bfa_fcs_fabric_init(struct bfa_fcs_fabric_s *fabric)
776{
777 struct bfa_lport_cfg_s *port_cfg = &fabric->bport.port_cfg;
778
779 port_cfg->roles = BFA_LPORT_ROLE_FCP_IM;
Maggie Zhangf7f738122010-12-09 19:08:43 -0800780 port_cfg->nwwn = fabric->fcs->bfa->ioc.attr->nwwn;
781 port_cfg->pwwn = fabric->fcs->bfa->ioc.attr->pwwn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700782}
783
Jing Huang5fbe25c2010-10-18 17:17:23 -0700784/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700785 * Port Symbolic Name Creation for base port.
786 */
787void
788bfa_fcs_fabric_psymb_init(struct bfa_fcs_fabric_s *fabric)
789{
790 struct bfa_lport_cfg_s *port_cfg = &fabric->bport.port_cfg;
791 char model[BFA_ADAPTER_MODEL_NAME_LEN] = {0};
792 struct bfa_fcs_driver_info_s *driver_info = &fabric->fcs->driver_info;
793
794 bfa_ioc_get_adapter_model(&fabric->fcs->bfa->ioc, model);
795
796 /* Model name/number */
797 strncpy((char *)&port_cfg->sym_name, model,
798 BFA_FCS_PORT_SYMBNAME_MODEL_SZ);
799 strncat((char *)&port_cfg->sym_name, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
800 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
801
802 /* Driver Version */
803 strncat((char *)&port_cfg->sym_name, (char *)driver_info->version,
804 BFA_FCS_PORT_SYMBNAME_VERSION_SZ);
805 strncat((char *)&port_cfg->sym_name, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
806 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
807
808 /* Host machine name */
809 strncat((char *)&port_cfg->sym_name,
810 (char *)driver_info->host_machine_name,
811 BFA_FCS_PORT_SYMBNAME_MACHINENAME_SZ);
812 strncat((char *)&port_cfg->sym_name, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
813 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
814
815 /*
816 * Host OS Info :
817 * If OS Patch Info is not there, do not truncate any bytes from the
818 * OS name string and instead copy the entire OS info string (64 bytes).
819 */
820 if (driver_info->host_os_patch[0] == '\0') {
821 strncat((char *)&port_cfg->sym_name,
822 (char *)driver_info->host_os_name,
823 BFA_FCS_OS_STR_LEN);
824 strncat((char *)&port_cfg->sym_name,
825 BFA_FCS_PORT_SYMBNAME_SEPARATOR,
826 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
827 } else {
828 strncat((char *)&port_cfg->sym_name,
829 (char *)driver_info->host_os_name,
830 BFA_FCS_PORT_SYMBNAME_OSINFO_SZ);
831 strncat((char *)&port_cfg->sym_name,
832 BFA_FCS_PORT_SYMBNAME_SEPARATOR,
833 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
834
835 /* Append host OS Patch Info */
836 strncat((char *)&port_cfg->sym_name,
837 (char *)driver_info->host_os_patch,
838 BFA_FCS_PORT_SYMBNAME_OSPATCH_SZ);
839 }
840
841 /* null terminate */
842 port_cfg->sym_name.symname[BFA_SYMNAME_MAXLEN - 1] = 0;
843}
844
Jing Huang5fbe25c2010-10-18 17:17:23 -0700845/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700846 * bfa lps login completion callback
847 */
848void
849bfa_cb_lps_flogi_comp(void *bfad, void *uarg, bfa_status_t status)
850{
851 struct bfa_fcs_fabric_s *fabric = uarg;
852
853 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
854 bfa_trc(fabric->fcs, status);
855
856 switch (status) {
857 case BFA_STATUS_OK:
858 fabric->stats.flogi_accepts++;
859 break;
860
861 case BFA_STATUS_INVALID_MAC:
862 /* Only for CNA */
863 fabric->stats.flogi_acc_err++;
864 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_RETRY_OP);
865
866 return;
867
868 case BFA_STATUS_EPROTOCOL:
Maggie Zhangf7f738122010-12-09 19:08:43 -0800869 switch (fabric->lps->ext_status) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700870 case BFA_EPROTO_BAD_ACCEPT:
871 fabric->stats.flogi_acc_err++;
872 break;
873
874 case BFA_EPROTO_UNKNOWN_RSP:
875 fabric->stats.flogi_unknown_rsp++;
876 break;
877
878 default:
879 break;
880 }
881 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_RETRY_OP);
882
883 return;
884
885 case BFA_STATUS_FABRIC_RJT:
886 fabric->stats.flogi_rejects++;
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700887 if (fabric->lps->lsrjt_rsn == FC_LS_RJT_RSN_LOGICAL_ERROR &&
888 fabric->lps->lsrjt_expl == FC_LS_RJT_EXP_NO_ADDL_INFO)
889 fabric->fcs->bbscn_flogi_rjt = BFA_TRUE;
890
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700891 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_RETRY_OP);
892 return;
893
894 default:
895 fabric->stats.flogi_rsp_err++;
896 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_RETRY_OP);
897 return;
898 }
899
Maggie Zhangf7f738122010-12-09 19:08:43 -0800900 fabric->bb_credit = fabric->lps->pr_bbcred;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700901 bfa_trc(fabric->fcs, fabric->bb_credit);
902
Maggie Zhangf7f738122010-12-09 19:08:43 -0800903 if (!(fabric->lps->brcd_switch))
904 fabric->fabric_name = fabric->lps->pr_nwwn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700905
906 /*
907 * Check port type. It should be 1 = F-port.
908 */
Maggie Zhangf7f738122010-12-09 19:08:43 -0800909 if (fabric->lps->fport) {
910 fabric->bport.pid = fabric->lps->lp_pid;
911 fabric->is_npiv = fabric->lps->npiv_en;
912 fabric->is_auth = fabric->lps->auth_req;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700913 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_CONT_OP);
914 } else {
915 /*
916 * Nport-2-Nport direct attached
917 */
918 fabric->bport.port_topo.pn2n.rem_port_wwn =
Maggie Zhangf7f738122010-12-09 19:08:43 -0800919 fabric->lps->pr_pwwn;
Krishna Gudipatid7be54c2011-06-24 20:24:52 -0700920 fabric->fab_type = BFA_FCS_FABRIC_N2N;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700921 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_NO_FABRIC);
922 }
923
924 bfa_trc(fabric->fcs, fabric->bport.pid);
925 bfa_trc(fabric->fcs, fabric->is_npiv);
926 bfa_trc(fabric->fcs, fabric->is_auth);
927}
Jing Huang5fbe25c2010-10-18 17:17:23 -0700928/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700929 * Allocate and send FLOGI.
930 */
931static void
932bfa_fcs_fabric_login(struct bfa_fcs_fabric_s *fabric)
933{
934 struct bfa_s *bfa = fabric->fcs->bfa;
935 struct bfa_lport_cfg_s *pcfg = &fabric->bport.port_cfg;
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700936 u8 alpa = 0, bb_scn = 0;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700937
938 if (bfa_fcport_get_topology(bfa) == BFA_PORT_TOPOLOGY_LOOP)
939 alpa = bfa_fcport_get_myalpa(bfa);
940
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700941 if (bfa_fcs_fabric_is_bbscn_enabled(fabric) &&
942 (!fabric->fcs->bbscn_flogi_rjt))
943 bb_scn = BFA_FCS_PORT_DEF_BB_SCN;
944
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700945 bfa_lps_flogi(fabric->lps, fabric, alpa, bfa_fcport_get_maxfrsize(bfa),
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700946 pcfg->pwwn, pcfg->nwwn, fabric->auth_reqd, bb_scn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700947
948 fabric->stats.flogi_sent++;
949}
950
951static void
952bfa_fcs_fabric_notify_online(struct bfa_fcs_fabric_s *fabric)
953{
954 struct bfa_fcs_vport_s *vport;
955 struct list_head *qe, *qen;
956
957 bfa_trc(fabric->fcs, fabric->fabric_name);
958
959 bfa_fcs_fabric_set_opertype(fabric);
960 fabric->stats.fabric_onlines++;
961
Jing Huang5fbe25c2010-10-18 17:17:23 -0700962 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700963 * notify online event to base and then virtual ports
964 */
965 bfa_fcs_lport_online(&fabric->bport);
966
967 list_for_each_safe(qe, qen, &fabric->vport_q) {
968 vport = (struct bfa_fcs_vport_s *) qe;
969 bfa_fcs_vport_online(vport);
970 }
971}
972
973static void
974bfa_fcs_fabric_notify_offline(struct bfa_fcs_fabric_s *fabric)
975{
976 struct bfa_fcs_vport_s *vport;
977 struct list_head *qe, *qen;
978
979 bfa_trc(fabric->fcs, fabric->fabric_name);
980 fabric->stats.fabric_offlines++;
981
Jing Huang5fbe25c2010-10-18 17:17:23 -0700982 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700983 * notify offline event first to vports and then base port.
984 */
985 list_for_each_safe(qe, qen, &fabric->vport_q) {
986 vport = (struct bfa_fcs_vport_s *) qe;
987 bfa_fcs_vport_offline(vport);
988 }
989
990 bfa_fcs_lport_offline(&fabric->bport);
991
992 fabric->fabric_name = 0;
993 fabric->fabric_ip_addr[0] = 0;
994}
995
996static void
997bfa_fcs_fabric_delay(void *cbarg)
998{
999 struct bfa_fcs_fabric_s *fabric = cbarg;
1000
1001 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_DELAYED);
1002}
1003
Jing Huang5fbe25c2010-10-18 17:17:23 -07001004/*
Krishna Gudipati881c1b32012-08-22 19:52:02 -07001005 * Stop all vports and wait for vport stop completions.
1006 */
1007static void
1008bfa_fcs_fabric_stop(struct bfa_fcs_fabric_s *fabric)
1009{
1010 struct bfa_fcs_vport_s *vport;
1011 struct list_head *qe, *qen;
1012
1013 bfa_wc_init(&fabric->stop_wc, bfa_fcs_fabric_stop_comp, fabric);
1014
1015 list_for_each_safe(qe, qen, &fabric->vport_q) {
1016 vport = (struct bfa_fcs_vport_s *) qe;
1017 bfa_wc_up(&fabric->stop_wc);
1018 bfa_fcs_vport_fcs_stop(vport);
1019 }
1020
1021 bfa_wc_up(&fabric->stop_wc);
1022 bfa_fcs_lport_stop(&fabric->bport);
1023 bfa_wc_wait(&fabric->stop_wc);
1024}
1025
1026/*
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001027 * Computes operating BB_SCN value
1028 */
1029static u8
1030bfa_fcs_fabric_oper_bbscn(struct bfa_fcs_fabric_s *fabric)
1031{
1032 u8 pr_bbscn = fabric->lps->pr_bbscn;
Krishna Gudipatid7be54c2011-06-24 20:24:52 -07001033 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(fabric->fcs->bfa);
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001034
Krishna Gudipatid7be54c2011-06-24 20:24:52 -07001035 if (!(fcport->cfg.bb_scn_state && pr_bbscn))
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001036 return 0;
1037
1038 /* return max of local/remote bb_scn values */
1039 return ((pr_bbscn > BFA_FCS_PORT_DEF_BB_SCN) ?
1040 pr_bbscn : BFA_FCS_PORT_DEF_BB_SCN);
1041}
1042
1043/*
1044 * Check if BB_SCN can be enabled.
1045 */
1046static bfa_boolean_t
1047bfa_fcs_fabric_is_bbscn_enabled(struct bfa_fcs_fabric_s *fabric)
1048{
Krishna Gudipatid7be54c2011-06-24 20:24:52 -07001049 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(fabric->fcs->bfa);
1050
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001051 if (bfa_ioc_get_fcmode(&fabric->fcs->bfa->ioc) &&
Krishna Gudipatid7be54c2011-06-24 20:24:52 -07001052 fcport->cfg.bb_scn_state &&
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001053 !bfa_fcport_is_qos_enabled(fabric->fcs->bfa) &&
1054 !bfa_fcport_is_trunk_enabled(fabric->fcs->bfa))
1055 return BFA_TRUE;
1056 else
1057 return BFA_FALSE;
1058}
1059
1060/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001061 * Delete all vports and wait for vport delete completions.
1062 */
1063static void
1064bfa_fcs_fabric_delete(struct bfa_fcs_fabric_s *fabric)
1065{
1066 struct bfa_fcs_vport_s *vport;
1067 struct list_head *qe, *qen;
1068
1069 list_for_each_safe(qe, qen, &fabric->vport_q) {
1070 vport = (struct bfa_fcs_vport_s *) qe;
1071 bfa_fcs_vport_fcs_delete(vport);
1072 }
1073
1074 bfa_fcs_lport_delete(&fabric->bport);
1075 bfa_wc_wait(&fabric->wc);
1076}
1077
1078static void
1079bfa_fcs_fabric_delete_comp(void *cbarg)
1080{
1081 struct bfa_fcs_fabric_s *fabric = cbarg;
1082
1083 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_DELCOMP);
1084}
1085
Krishna Gudipati881c1b32012-08-22 19:52:02 -07001086static void
1087bfa_fcs_fabric_stop_comp(void *cbarg)
1088{
1089 struct bfa_fcs_fabric_s *fabric = cbarg;
1090
1091 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_STOPCOMP);
1092}
1093
Jing Huang5fbe25c2010-10-18 17:17:23 -07001094/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001095 * fcs_fabric_public fabric public functions
1096 */
1097
Jing Huang5fbe25c2010-10-18 17:17:23 -07001098/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001099 * Attach time initialization.
1100 */
1101void
1102bfa_fcs_fabric_attach(struct bfa_fcs_s *fcs)
1103{
1104 struct bfa_fcs_fabric_s *fabric;
1105
1106 fabric = &fcs->fabric;
Jing Huang6a18b162010-10-18 17:08:54 -07001107 memset(fabric, 0, sizeof(struct bfa_fcs_fabric_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001108
Jing Huang5fbe25c2010-10-18 17:17:23 -07001109 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001110 * Initialize base fabric.
1111 */
1112 fabric->fcs = fcs;
1113 INIT_LIST_HEAD(&fabric->vport_q);
1114 INIT_LIST_HEAD(&fabric->vf_q);
1115 fabric->lps = bfa_lps_alloc(fcs->bfa);
Jing Huangd4b671c2010-12-26 21:46:35 -08001116 WARN_ON(!fabric->lps);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001117
Jing Huang5fbe25c2010-10-18 17:17:23 -07001118 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001119 * Initialize fabric delete completion handler. Fabric deletion is
1120 * complete when the last vport delete is complete.
1121 */
1122 bfa_wc_init(&fabric->wc, bfa_fcs_fabric_delete_comp, fabric);
1123 bfa_wc_up(&fabric->wc); /* For the base port */
1124
1125 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_uninit);
1126 bfa_fcs_lport_attach(&fabric->bport, fabric->fcs, FC_VF_ID_NULL, NULL);
1127}
1128
1129void
1130bfa_fcs_fabric_modinit(struct bfa_fcs_s *fcs)
1131{
1132 bfa_sm_send_event(&fcs->fabric, BFA_FCS_FABRIC_SM_CREATE);
1133 bfa_trc(fcs, 0);
1134}
1135
Jing Huang5fbe25c2010-10-18 17:17:23 -07001136/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001137 * Module cleanup
1138 */
1139void
1140bfa_fcs_fabric_modexit(struct bfa_fcs_s *fcs)
1141{
1142 struct bfa_fcs_fabric_s *fabric;
1143
1144 bfa_trc(fcs, 0);
1145
Jing Huang5fbe25c2010-10-18 17:17:23 -07001146 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001147 * Cleanup base fabric.
1148 */
1149 fabric = &fcs->fabric;
1150 bfa_lps_delete(fabric->lps);
1151 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_DELETE);
1152}
1153
Jing Huang5fbe25c2010-10-18 17:17:23 -07001154/*
Krishna Gudipati881c1b32012-08-22 19:52:02 -07001155 * Fabric module stop -- stop FCS actions
1156 */
1157void
1158bfa_fcs_fabric_modstop(struct bfa_fcs_s *fcs)
1159{
1160 struct bfa_fcs_fabric_s *fabric;
1161
1162 bfa_trc(fcs, 0);
1163 fabric = &fcs->fabric;
1164 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_STOP);
1165}
1166
1167/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001168 * Fabric module start -- kick starts FCS actions
1169 */
1170void
1171bfa_fcs_fabric_modstart(struct bfa_fcs_s *fcs)
1172{
1173 struct bfa_fcs_fabric_s *fabric;
1174
1175 bfa_trc(fcs, 0);
1176 fabric = &fcs->fabric;
1177 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_START);
1178}
1179
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001180
Jing Huang5fbe25c2010-10-18 17:17:23 -07001181/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001182 * Link up notification from BFA physical port module.
1183 */
1184void
1185bfa_fcs_fabric_link_up(struct bfa_fcs_fabric_s *fabric)
1186{
1187 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
1188 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_LINK_UP);
1189}
1190
Jing Huang5fbe25c2010-10-18 17:17:23 -07001191/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001192 * Link down notification from BFA physical port module.
1193 */
1194void
1195bfa_fcs_fabric_link_down(struct bfa_fcs_fabric_s *fabric)
1196{
1197 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001198 fabric->fcs->bbscn_flogi_rjt = BFA_FALSE;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001199 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_LINK_DOWN);
1200}
1201
Jing Huang5fbe25c2010-10-18 17:17:23 -07001202/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001203 * A child vport is being created in the fabric.
1204 *
1205 * Call from vport module at vport creation. A list of base port and vports
1206 * belonging to a fabric is maintained to propagate link events.
1207 *
1208 * param[in] fabric - Fabric instance. This can be a base fabric or vf.
1209 * param[in] vport - Vport being created.
1210 *
1211 * @return None (always succeeds)
1212 */
1213void
1214bfa_fcs_fabric_addvport(struct bfa_fcs_fabric_s *fabric,
1215 struct bfa_fcs_vport_s *vport)
1216{
Jing Huang5fbe25c2010-10-18 17:17:23 -07001217 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001218 * - add vport to fabric's vport_q
1219 */
1220 bfa_trc(fabric->fcs, fabric->vf_id);
1221
1222 list_add_tail(&vport->qe, &fabric->vport_q);
1223 fabric->num_vports++;
1224 bfa_wc_up(&fabric->wc);
1225}
1226
Jing Huang5fbe25c2010-10-18 17:17:23 -07001227/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001228 * A child vport is being deleted from fabric.
1229 *
1230 * Vport is being deleted.
1231 */
1232void
1233bfa_fcs_fabric_delvport(struct bfa_fcs_fabric_s *fabric,
1234 struct bfa_fcs_vport_s *vport)
1235{
1236 list_del(&vport->qe);
1237 fabric->num_vports--;
1238 bfa_wc_down(&fabric->wc);
1239}
1240
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001241
Jing Huang5fbe25c2010-10-18 17:17:23 -07001242/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001243 * Lookup for a vport within a fabric given its pwwn
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001244 */
1245struct bfa_fcs_vport_s *
1246bfa_fcs_fabric_vport_lookup(struct bfa_fcs_fabric_s *fabric, wwn_t pwwn)
1247{
1248 struct bfa_fcs_vport_s *vport;
1249 struct list_head *qe;
1250
1251 list_for_each(qe, &fabric->vport_q) {
1252 vport = (struct bfa_fcs_vport_s *) qe;
1253 if (bfa_fcs_lport_get_pwwn(&vport->lport) == pwwn)
1254 return vport;
1255 }
1256
1257 return NULL;
1258}
1259
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001260
1261/*
1262 * Get OUI of the attached switch.
1263 *
1264 * Note : Use of this function should be avoided as much as possible.
1265 * This function should be used only if there is any requirement
1266* to check for FOS version below 6.3.
1267 * To check if the attached fabric is a brocade fabric, use
1268 * bfa_lps_is_brcd_fabric() which works for FOS versions 6.3
1269 * or above only.
1270 */
1271
1272u16
1273bfa_fcs_fabric_get_switch_oui(struct bfa_fcs_fabric_s *fabric)
1274{
1275 wwn_t fab_nwwn;
1276 u8 *tmp;
1277 u16 oui;
1278
Maggie Zhangf7f738122010-12-09 19:08:43 -08001279 fab_nwwn = fabric->lps->pr_nwwn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001280
1281 tmp = (u8 *)&fab_nwwn;
1282 oui = (tmp[3] << 8) | tmp[4];
1283
1284 return oui;
1285}
Jing Huang5fbe25c2010-10-18 17:17:23 -07001286/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001287 * Unsolicited frame receive handling.
1288 */
1289void
1290bfa_fcs_fabric_uf_recv(struct bfa_fcs_fabric_s *fabric, struct fchs_s *fchs,
1291 u16 len)
1292{
1293 u32 pid = fchs->d_id;
1294 struct bfa_fcs_vport_s *vport;
1295 struct list_head *qe;
1296 struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
1297 struct fc_logi_s *flogi = (struct fc_logi_s *) els_cmd;
1298
1299 bfa_trc(fabric->fcs, len);
1300 bfa_trc(fabric->fcs, pid);
1301
Jing Huang5fbe25c2010-10-18 17:17:23 -07001302 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001303 * Look for our own FLOGI frames being looped back. This means an
1304 * external loopback cable is in place. Our own FLOGI frames are
1305 * sometimes looped back when switch port gets temporarily bypassed.
1306 */
Maggie Zhangf16a1752010-12-09 19:12:32 -08001307 if ((pid == bfa_ntoh3b(FC_FABRIC_PORT)) &&
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001308 (els_cmd->els_code == FC_ELS_FLOGI) &&
1309 (flogi->port_name == bfa_fcs_lport_get_pwwn(&fabric->bport))) {
1310 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_LOOPBACK);
1311 return;
1312 }
1313
Jing Huang5fbe25c2010-10-18 17:17:23 -07001314 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001315 * FLOGI/EVFP exchanges should be consumed by base fabric.
1316 */
Maggie Zhangf16a1752010-12-09 19:12:32 -08001317 if (fchs->d_id == bfa_hton3b(FC_FABRIC_PORT)) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001318 bfa_trc(fabric->fcs, pid);
1319 bfa_fcs_fabric_process_uf(fabric, fchs, len);
1320 return;
1321 }
1322
1323 if (fabric->bport.pid == pid) {
Jing Huang5fbe25c2010-10-18 17:17:23 -07001324 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001325 * All authentication frames should be routed to auth
1326 */
1327 bfa_trc(fabric->fcs, els_cmd->els_code);
1328 if (els_cmd->els_code == FC_ELS_AUTH) {
1329 bfa_trc(fabric->fcs, els_cmd->els_code);
1330 return;
1331 }
1332
1333 bfa_trc(fabric->fcs, *(u8 *) ((u8 *) fchs));
1334 bfa_fcs_lport_uf_recv(&fabric->bport, fchs, len);
1335 return;
1336 }
1337
Jing Huang5fbe25c2010-10-18 17:17:23 -07001338 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001339 * look for a matching local port ID
1340 */
1341 list_for_each(qe, &fabric->vport_q) {
1342 vport = (struct bfa_fcs_vport_s *) qe;
1343 if (vport->lport.pid == pid) {
1344 bfa_fcs_lport_uf_recv(&vport->lport, fchs, len);
1345 return;
1346 }
1347 }
1348 bfa_trc(fabric->fcs, els_cmd->els_code);
1349 bfa_fcs_lport_uf_recv(&fabric->bport, fchs, len);
1350}
1351
Jing Huang5fbe25c2010-10-18 17:17:23 -07001352/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001353 * Unsolicited frames to be processed by fabric.
1354 */
1355static void
1356bfa_fcs_fabric_process_uf(struct bfa_fcs_fabric_s *fabric, struct fchs_s *fchs,
1357 u16 len)
1358{
1359 struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
1360
1361 bfa_trc(fabric->fcs, els_cmd->els_code);
1362
1363 switch (els_cmd->els_code) {
1364 case FC_ELS_FLOGI:
1365 bfa_fcs_fabric_process_flogi(fabric, fchs, len);
1366 break;
1367
1368 default:
1369 /*
1370 * need to generate a LS_RJT
1371 */
1372 break;
1373 }
1374}
1375
Jing Huang5fbe25c2010-10-18 17:17:23 -07001376/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001377 * Process incoming FLOGI
1378 */
1379static void
1380bfa_fcs_fabric_process_flogi(struct bfa_fcs_fabric_s *fabric,
1381 struct fchs_s *fchs, u16 len)
1382{
1383 struct fc_logi_s *flogi = (struct fc_logi_s *) (fchs + 1);
1384 struct bfa_fcs_lport_s *bport = &fabric->bport;
1385
1386 bfa_trc(fabric->fcs, fchs->s_id);
1387
1388 fabric->stats.flogi_rcvd++;
1389 /*
1390 * Check port type. It should be 0 = n-port.
1391 */
1392 if (flogi->csp.port_type) {
1393 /*
1394 * @todo: may need to send a LS_RJT
1395 */
1396 bfa_trc(fabric->fcs, flogi->port_name);
1397 fabric->stats.flogi_rejected++;
1398 return;
1399 }
1400
Jing Huangba816ea2010-10-18 17:10:50 -07001401 fabric->bb_credit = be16_to_cpu(flogi->csp.bbcred);
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001402 fabric->lps->pr_bbscn = (be16_to_cpu(flogi->csp.rxsz) >> 12);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001403 bport->port_topo.pn2n.rem_port_wwn = flogi->port_name;
1404 bport->port_topo.pn2n.reply_oxid = fchs->ox_id;
1405
1406 /*
1407 * Send a Flogi Acc
1408 */
1409 bfa_fcs_fabric_send_flogi_acc(fabric);
1410 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_NO_FABRIC);
1411}
1412
1413static void
1414bfa_fcs_fabric_send_flogi_acc(struct bfa_fcs_fabric_s *fabric)
1415{
1416 struct bfa_lport_cfg_s *pcfg = &fabric->bport.port_cfg;
1417 struct bfa_fcs_lport_n2n_s *n2n_port = &fabric->bport.port_topo.pn2n;
1418 struct bfa_s *bfa = fabric->fcs->bfa;
1419 struct bfa_fcxp_s *fcxp;
1420 u16 reqlen;
1421 struct fchs_s fchs;
1422
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07001423 fcxp = bfa_fcs_fcxp_alloc(fabric->fcs, BFA_FALSE);
Jing Huang5fbe25c2010-10-18 17:17:23 -07001424 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001425 * Do not expect this failure -- expect remote node to retry
1426 */
1427 if (!fcxp)
1428 return;
1429
1430 reqlen = fc_flogi_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
Maggie Zhangf16a1752010-12-09 19:12:32 -08001431 bfa_hton3b(FC_FABRIC_PORT),
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001432 n2n_port->reply_oxid, pcfg->pwwn,
1433 pcfg->nwwn,
1434 bfa_fcport_get_maxfrsize(bfa),
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001435 bfa_fcport_get_rx_bbcredit(bfa),
1436 bfa_fcs_fabric_oper_bbscn(fabric));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001437
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001438 bfa_fcxp_send(fcxp, NULL, fabric->vf_id, fabric->lps->bfa_tag,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001439 BFA_FALSE, FC_CLASS_3,
1440 reqlen, &fchs, bfa_fcs_fabric_flogiacc_comp, fabric,
1441 FC_MAX_PDUSZ, 0);
1442}
1443
Jing Huang5fbe25c2010-10-18 17:17:23 -07001444/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001445 * Flogi Acc completion callback.
1446 */
1447static void
1448bfa_fcs_fabric_flogiacc_comp(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
1449 bfa_status_t status, u32 rsp_len,
1450 u32 resid_len, struct fchs_s *rspfchs)
1451{
1452 struct bfa_fcs_fabric_s *fabric = cbarg;
1453
1454 bfa_trc(fabric->fcs, status);
1455}
1456
Krishna Gudipati7826f302011-07-20 16:59:13 -07001457
1458/*
1459 * Send AEN notification
1460 */
1461static void
1462bfa_fcs_fabric_aen_post(struct bfa_fcs_lport_s *port,
1463 enum bfa_port_aen_event event)
1464{
1465 struct bfad_s *bfad = (struct bfad_s *)port->fabric->fcs->bfad;
1466 struct bfa_aen_entry_s *aen_entry;
1467
1468 bfad_get_aen_entry(bfad, aen_entry);
1469 if (!aen_entry)
1470 return;
1471
1472 aen_entry->aen_data.port.pwwn = bfa_fcs_lport_get_pwwn(port);
1473 aen_entry->aen_data.port.fwwn = bfa_fcs_lport_get_fabric_name(port);
1474
1475 /* Send the AEN notification */
1476 bfad_im_post_vendor_event(aen_entry, bfad, ++port->fcs->fcs_aen_seq,
1477 BFA_AEN_CAT_PORT, event);
1478}
1479
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001480/*
1481 *
1482 * @param[in] fabric - fabric
1483 * @param[in] wwn_t - new fabric name
1484 *
1485 * @return - none
1486 */
1487void
1488bfa_fcs_fabric_set_fabric_name(struct bfa_fcs_fabric_s *fabric,
1489 wwn_t fabric_name)
1490{
1491 struct bfad_s *bfad = (struct bfad_s *)fabric->fcs->bfad;
1492 char pwwn_ptr[BFA_STRING_32];
1493 char fwwn_ptr[BFA_STRING_32];
1494
1495 bfa_trc(fabric->fcs, fabric_name);
1496
1497 if (fabric->fabric_name == 0) {
1498 /*
1499 * With BRCD switches, we don't get Fabric Name in FLOGI.
1500 * Don't generate a fabric name change event in this case.
1501 */
1502 fabric->fabric_name = fabric_name;
1503 } else {
1504 fabric->fabric_name = fabric_name;
1505 wwn2str(pwwn_ptr, bfa_fcs_lport_get_pwwn(&fabric->bport));
1506 wwn2str(fwwn_ptr,
1507 bfa_fcs_lport_get_fabric_name(&fabric->bport));
Jing Huang88166242010-12-09 17:11:53 -08001508 BFA_LOG(KERN_WARNING, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001509 "Base port WWN = %s Fabric WWN = %s\n",
1510 pwwn_ptr, fwwn_ptr);
Krishna Gudipati7826f302011-07-20 16:59:13 -07001511 bfa_fcs_fabric_aen_post(&fabric->bport,
1512 BFA_PORT_AEN_FABRIC_NAME_CHANGE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001513 }
1514}
1515
Krishna Gudipati881c1b32012-08-22 19:52:02 -07001516void
1517bfa_cb_lps_flogo_comp(void *bfad, void *uarg)
1518{
1519 struct bfa_fcs_fabric_s *fabric = uarg;
1520 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_LOGOCOMP);
1521}
1522
Jing Huang5fbe25c2010-10-18 17:17:23 -07001523/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001524 * Returns FCS vf structure for a given vf_id.
1525 *
1526 * param[in] vf_id - VF_ID
1527 *
1528 * return
1529 * If lookup succeeds, retuns fcs vf object, otherwise returns NULL
1530 */
1531bfa_fcs_vf_t *
1532bfa_fcs_vf_lookup(struct bfa_fcs_s *fcs, u16 vf_id)
1533{
1534 bfa_trc(fcs, vf_id);
1535 if (vf_id == FC_VF_ID_NULL)
1536 return &fcs->fabric;
1537
1538 return NULL;
1539}
1540
Jing Huang5fbe25c2010-10-18 17:17:23 -07001541/*
Krishna Gudipatib85daaf2011-06-13 15:55:11 -07001542 * Return the list of local logical ports present in the given VF.
1543 *
1544 * @param[in] vf vf for which logical ports are returned
1545 * @param[out] lpwwn returned logical port wwn list
1546 * @param[in,out] nlports in:size of lpwwn list;
1547 * out:total elements present,
1548 * actual elements returned is limited by the size
1549 */
1550void
1551bfa_fcs_vf_get_ports(bfa_fcs_vf_t *vf, wwn_t lpwwn[], int *nlports)
1552{
1553 struct list_head *qe;
1554 struct bfa_fcs_vport_s *vport;
1555 int i = 0;
1556 struct bfa_fcs_s *fcs;
1557
1558 if (vf == NULL || lpwwn == NULL || *nlports == 0)
1559 return;
1560
1561 fcs = vf->fcs;
1562
1563 bfa_trc(fcs, vf->vf_id);
1564 bfa_trc(fcs, (uint32_t) *nlports);
1565
1566 lpwwn[i++] = vf->bport.port_cfg.pwwn;
1567
1568 list_for_each(qe, &vf->vport_q) {
1569 if (i >= *nlports)
1570 break;
1571
1572 vport = (struct bfa_fcs_vport_s *) qe;
1573 lpwwn[i++] = vport->lport.port_cfg.pwwn;
1574 }
1575
1576 bfa_trc(fcs, i);
1577 *nlports = i;
1578}
1579
1580/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001581 * BFA FCS PPORT ( physical port)
1582 */
1583static void
1584bfa_fcs_port_event_handler(void *cbarg, enum bfa_port_linkstate event)
1585{
1586 struct bfa_fcs_s *fcs = cbarg;
1587
1588 bfa_trc(fcs, event);
1589
1590 switch (event) {
1591 case BFA_PORT_LINKUP:
1592 bfa_fcs_fabric_link_up(&fcs->fabric);
1593 break;
1594
1595 case BFA_PORT_LINKDOWN:
1596 bfa_fcs_fabric_link_down(&fcs->fabric);
1597 break;
1598
1599 default:
Jing Huangd4b671c2010-12-26 21:46:35 -08001600 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001601 }
1602}
1603
1604void
1605bfa_fcs_port_attach(struct bfa_fcs_s *fcs)
1606{
1607 bfa_fcport_event_register(fcs->bfa, bfa_fcs_port_event_handler, fcs);
1608}
1609
Jing Huang5fbe25c2010-10-18 17:17:23 -07001610/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001611 * BFA FCS UF ( Unsolicited Frames)
1612 */
1613
Jing Huang5fbe25c2010-10-18 17:17:23 -07001614/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001615 * BFA callback for unsolicited frame receive handler.
1616 *
1617 * @param[in] cbarg callback arg for receive handler
1618 * @param[in] uf unsolicited frame descriptor
1619 *
1620 * @return None
1621 */
1622static void
1623bfa_fcs_uf_recv(void *cbarg, struct bfa_uf_s *uf)
1624{
1625 struct bfa_fcs_s *fcs = (struct bfa_fcs_s *) cbarg;
1626 struct fchs_s *fchs = bfa_uf_get_frmbuf(uf);
1627 u16 len = bfa_uf_get_frmlen(uf);
1628 struct fc_vft_s *vft;
1629 struct bfa_fcs_fabric_s *fabric;
1630
Jing Huang5fbe25c2010-10-18 17:17:23 -07001631 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001632 * check for VFT header
1633 */
1634 if (fchs->routing == FC_RTG_EXT_HDR &&
1635 fchs->cat_info == FC_CAT_VFT_HDR) {
1636 bfa_stats(fcs, uf.tagged);
1637 vft = bfa_uf_get_frmbuf(uf);
1638 if (fcs->port_vfid == vft->vf_id)
1639 fabric = &fcs->fabric;
1640 else
1641 fabric = bfa_fcs_vf_lookup(fcs, (u16) vft->vf_id);
1642
Jing Huang5fbe25c2010-10-18 17:17:23 -07001643 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001644 * drop frame if vfid is unknown
1645 */
1646 if (!fabric) {
Jing Huangd4b671c2010-12-26 21:46:35 -08001647 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001648 bfa_stats(fcs, uf.vfid_unknown);
1649 bfa_uf_free(uf);
1650 return;
1651 }
1652
Jing Huang5fbe25c2010-10-18 17:17:23 -07001653 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001654 * skip vft header
1655 */
1656 fchs = (struct fchs_s *) (vft + 1);
1657 len -= sizeof(struct fc_vft_s);
1658
1659 bfa_trc(fcs, vft->vf_id);
1660 } else {
1661 bfa_stats(fcs, uf.untagged);
1662 fabric = &fcs->fabric;
1663 }
1664
1665 bfa_trc(fcs, ((u32 *) fchs)[0]);
1666 bfa_trc(fcs, ((u32 *) fchs)[1]);
1667 bfa_trc(fcs, ((u32 *) fchs)[2]);
1668 bfa_trc(fcs, ((u32 *) fchs)[3]);
1669 bfa_trc(fcs, ((u32 *) fchs)[4]);
1670 bfa_trc(fcs, ((u32 *) fchs)[5]);
1671 bfa_trc(fcs, len);
1672
1673 bfa_fcs_fabric_uf_recv(fabric, fchs, len);
1674 bfa_uf_free(uf);
1675}
1676
1677void
1678bfa_fcs_uf_attach(struct bfa_fcs_s *fcs)
1679{
1680 bfa_uf_recv_register(fcs->bfa, bfa_fcs_uf_recv, fcs);
1681}