blob: 2139592aca5ed61365b72a765d13bdb5d5a7b544 [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);
Krishna Gudipatice7242b2012-08-22 19:52:43 -0700168 bfa_fcs_fabric_nsymb_init(&fcs->fabric);
Jing Huang7725ccf2009-09-23 17:46:15 -0700169}
170
Jing Huang5fbe25c2010-10-18 17:17:23 -0700171/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700172 * brief
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700173 * FCS instance cleanup and exit.
Jing Huang7725ccf2009-09-23 17:46:15 -0700174 *
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700175 * param[in] fcs FCS instance
176 * return None
Jing Huang7725ccf2009-09-23 17:46:15 -0700177 */
178void
179bfa_fcs_exit(struct bfa_fcs_s *fcs)
180{
181 struct bfa_fcs_mod_s *mod;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700182 int nmods, i;
Jing Huang7725ccf2009-09-23 17:46:15 -0700183
184 bfa_wc_init(&fcs->wc, bfa_fcs_exit_comp, fcs);
185
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700186 nmods = sizeof(fcs_modules) / sizeof(fcs_modules[0]);
187
188 for (i = 0; i < nmods; i++) {
Jing Huang7725ccf2009-09-23 17:46:15 -0700189
190 mod = &fcs_modules[i];
Krishna Gudipati82794a22010-03-03 17:43:30 -0800191 if (mod->modexit) {
192 bfa_wc_up(&fcs->wc);
193 mod->modexit(fcs);
194 }
Jing Huang7725ccf2009-09-23 17:46:15 -0700195 }
196
197 bfa_wc_wait(&fcs->wc);
198}
199
200
Jing Huang5fbe25c2010-10-18 17:17:23 -0700201/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700202 * Fabric module implementation.
203 */
Jing Huang7725ccf2009-09-23 17:46:15 -0700204
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700205#define BFA_FCS_FABRIC_RETRY_DELAY (2000) /* Milliseconds */
206#define BFA_FCS_FABRIC_CLEANUP_DELAY (10000) /* Milliseconds */
207
208#define bfa_fcs_fabric_set_opertype(__fabric) do { \
Krishna Gudipatid7be54c2011-06-24 20:24:52 -0700209 if (bfa_fcport_get_topology((__fabric)->fcs->bfa) \
210 == BFA_PORT_TOPOLOGY_P2P) { \
211 if (fabric->fab_type == BFA_FCS_FABRIC_SWITCHED) \
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700212 (__fabric)->oper_type = BFA_PORT_TYPE_NPORT; \
213 else \
Krishna Gudipatid7be54c2011-06-24 20:24:52 -0700214 (__fabric)->oper_type = BFA_PORT_TYPE_P2P; \
215 } else \
216 (__fabric)->oper_type = BFA_PORT_TYPE_NLPORT; \
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700217} while (0)
218
219/*
220 * forward declarations
221 */
222static void bfa_fcs_fabric_init(struct bfa_fcs_fabric_s *fabric);
223static void bfa_fcs_fabric_login(struct bfa_fcs_fabric_s *fabric);
224static void bfa_fcs_fabric_notify_online(struct bfa_fcs_fabric_s *fabric);
225static void bfa_fcs_fabric_notify_offline(struct bfa_fcs_fabric_s *fabric);
226static void bfa_fcs_fabric_delay(void *cbarg);
227static void bfa_fcs_fabric_delete(struct bfa_fcs_fabric_s *fabric);
228static void bfa_fcs_fabric_delete_comp(void *cbarg);
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700229static void bfa_fcs_fabric_stop(struct bfa_fcs_fabric_s *fabric);
230static void bfa_fcs_fabric_stop_comp(void *cbarg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700231static void bfa_fcs_fabric_process_uf(struct bfa_fcs_fabric_s *fabric,
232 struct fchs_s *fchs, u16 len);
233static void bfa_fcs_fabric_process_flogi(struct bfa_fcs_fabric_s *fabric,
234 struct fchs_s *fchs, u16 len);
235static void bfa_fcs_fabric_send_flogi_acc(struct bfa_fcs_fabric_s *fabric);
236static void bfa_fcs_fabric_flogiacc_comp(void *fcsarg,
237 struct bfa_fcxp_s *fcxp, void *cbarg,
238 bfa_status_t status,
239 u32 rsp_len,
240 u32 resid_len,
241 struct fchs_s *rspfchs);
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700242static u8 bfa_fcs_fabric_oper_bbscn(struct bfa_fcs_fabric_s *fabric);
243static bfa_boolean_t bfa_fcs_fabric_is_bbscn_enabled(
244 struct bfa_fcs_fabric_s *fabric);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700245
246static void bfa_fcs_fabric_sm_uninit(struct bfa_fcs_fabric_s *fabric,
247 enum bfa_fcs_fabric_event event);
248static void bfa_fcs_fabric_sm_created(struct bfa_fcs_fabric_s *fabric,
249 enum bfa_fcs_fabric_event event);
250static void bfa_fcs_fabric_sm_linkdown(struct bfa_fcs_fabric_s *fabric,
251 enum bfa_fcs_fabric_event event);
252static void bfa_fcs_fabric_sm_flogi(struct bfa_fcs_fabric_s *fabric,
253 enum bfa_fcs_fabric_event event);
254static void bfa_fcs_fabric_sm_flogi_retry(struct bfa_fcs_fabric_s *fabric,
255 enum bfa_fcs_fabric_event event);
256static void bfa_fcs_fabric_sm_auth(struct bfa_fcs_fabric_s *fabric,
257 enum bfa_fcs_fabric_event event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700258static void bfa_fcs_fabric_sm_nofabric(struct bfa_fcs_fabric_s *fabric,
259 enum bfa_fcs_fabric_event event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700260static void bfa_fcs_fabric_sm_evfp(struct bfa_fcs_fabric_s *fabric,
261 enum bfa_fcs_fabric_event event);
262static void bfa_fcs_fabric_sm_evfp_done(struct bfa_fcs_fabric_s *fabric,
263 enum bfa_fcs_fabric_event event);
264static void bfa_fcs_fabric_sm_isolated(struct bfa_fcs_fabric_s *fabric,
265 enum bfa_fcs_fabric_event event);
266static void bfa_fcs_fabric_sm_deleting(struct bfa_fcs_fabric_s *fabric,
267 enum bfa_fcs_fabric_event event);
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700268static void bfa_fcs_fabric_sm_stopping(struct bfa_fcs_fabric_s *fabric,
269 enum bfa_fcs_fabric_event event);
270static void bfa_fcs_fabric_sm_cleanup(struct bfa_fcs_fabric_s *fabric,
271 enum bfa_fcs_fabric_event event);
Jing Huang5fbe25c2010-10-18 17:17:23 -0700272/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700273 * Beginning state before fabric creation.
274 */
275static void
276bfa_fcs_fabric_sm_uninit(struct bfa_fcs_fabric_s *fabric,
277 enum bfa_fcs_fabric_event event)
278{
279 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
280 bfa_trc(fabric->fcs, event);
281
282 switch (event) {
283 case BFA_FCS_FABRIC_SM_CREATE:
284 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_created);
285 bfa_fcs_fabric_init(fabric);
286 bfa_fcs_lport_init(&fabric->bport, &fabric->bport.port_cfg);
287 break;
288
289 case BFA_FCS_FABRIC_SM_LINK_UP:
290 case BFA_FCS_FABRIC_SM_LINK_DOWN:
291 break;
292
293 default:
294 bfa_sm_fault(fabric->fcs, event);
295 }
296}
297
Jing Huang5fbe25c2010-10-18 17:17:23 -0700298/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700299 * Beginning state before fabric creation.
300 */
301static void
302bfa_fcs_fabric_sm_created(struct bfa_fcs_fabric_s *fabric,
303 enum bfa_fcs_fabric_event event)
304{
305 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
306 bfa_trc(fabric->fcs, event);
307
308 switch (event) {
309 case BFA_FCS_FABRIC_SM_START:
310 if (bfa_fcport_is_linkup(fabric->fcs->bfa)) {
311 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_flogi);
312 bfa_fcs_fabric_login(fabric);
313 } else
314 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
315 break;
316
317 case BFA_FCS_FABRIC_SM_LINK_UP:
318 case BFA_FCS_FABRIC_SM_LINK_DOWN:
319 break;
320
321 case BFA_FCS_FABRIC_SM_DELETE:
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -0700322 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
323 bfa_fcs_fabric_delete(fabric);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700324 break;
325
326 default:
327 bfa_sm_fault(fabric->fcs, event);
328 }
329}
330
Jing Huang5fbe25c2010-10-18 17:17:23 -0700331/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700332 * Link is down, awaiting LINK UP event from port. This is also the
333 * first state at fabric creation.
334 */
335static void
336bfa_fcs_fabric_sm_linkdown(struct bfa_fcs_fabric_s *fabric,
337 enum bfa_fcs_fabric_event event)
338{
339 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
340 bfa_trc(fabric->fcs, event);
341
342 switch (event) {
343 case BFA_FCS_FABRIC_SM_LINK_UP:
344 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_flogi);
345 bfa_fcs_fabric_login(fabric);
346 break;
347
348 case BFA_FCS_FABRIC_SM_RETRY_OP:
349 break;
350
351 case BFA_FCS_FABRIC_SM_DELETE:
352 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
353 bfa_fcs_fabric_delete(fabric);
354 break;
355
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700356 case BFA_FCS_FABRIC_SM_STOP:
357 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_cleanup);
358 bfa_fcs_fabric_stop(fabric);
359 break;
360
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700361 default:
362 bfa_sm_fault(fabric->fcs, event);
363 }
364}
365
Jing Huang5fbe25c2010-10-18 17:17:23 -0700366/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700367 * FLOGI is in progress, awaiting FLOGI reply.
368 */
369static void
370bfa_fcs_fabric_sm_flogi(struct bfa_fcs_fabric_s *fabric,
371 enum bfa_fcs_fabric_event event)
372{
373 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
374 bfa_trc(fabric->fcs, event);
375
376 switch (event) {
377 case BFA_FCS_FABRIC_SM_CONT_OP:
378
379 bfa_fcport_set_tx_bbcredit(fabric->fcs->bfa,
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700380 fabric->bb_credit,
381 bfa_fcs_fabric_oper_bbscn(fabric));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700382 fabric->fab_type = BFA_FCS_FABRIC_SWITCHED;
383
384 if (fabric->auth_reqd && fabric->is_auth) {
385 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_auth);
386 bfa_trc(fabric->fcs, event);
387 } else {
388 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_online);
389 bfa_fcs_fabric_notify_online(fabric);
390 }
391 break;
392
393 case BFA_FCS_FABRIC_SM_RETRY_OP:
394 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_flogi_retry);
395 bfa_timer_start(fabric->fcs->bfa, &fabric->delay_timer,
396 bfa_fcs_fabric_delay, fabric,
397 BFA_FCS_FABRIC_RETRY_DELAY);
398 break;
399
400 case BFA_FCS_FABRIC_SM_LOOPBACK:
401 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_loopback);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800402 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700403 bfa_fcs_fabric_set_opertype(fabric);
404 break;
405
406 case BFA_FCS_FABRIC_SM_NO_FABRIC:
407 fabric->fab_type = BFA_FCS_FABRIC_N2N;
408 bfa_fcport_set_tx_bbcredit(fabric->fcs->bfa,
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700409 fabric->bb_credit,
410 bfa_fcs_fabric_oper_bbscn(fabric));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700411 bfa_fcs_fabric_notify_online(fabric);
412 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_nofabric);
413 break;
414
415 case BFA_FCS_FABRIC_SM_LINK_DOWN:
416 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800417 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700418 break;
419
420 case BFA_FCS_FABRIC_SM_DELETE:
421 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800422 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700423 bfa_fcs_fabric_delete(fabric);
424 break;
425
426 default:
427 bfa_sm_fault(fabric->fcs, event);
428 }
429}
430
431
432static void
433bfa_fcs_fabric_sm_flogi_retry(struct bfa_fcs_fabric_s *fabric,
434 enum bfa_fcs_fabric_event event)
435{
436 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
437 bfa_trc(fabric->fcs, event);
438
439 switch (event) {
440 case BFA_FCS_FABRIC_SM_DELAYED:
441 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_flogi);
442 bfa_fcs_fabric_login(fabric);
443 break;
444
445 case BFA_FCS_FABRIC_SM_LINK_DOWN:
446 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
447 bfa_timer_stop(&fabric->delay_timer);
448 break;
449
450 case BFA_FCS_FABRIC_SM_DELETE:
451 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
452 bfa_timer_stop(&fabric->delay_timer);
453 bfa_fcs_fabric_delete(fabric);
454 break;
455
456 default:
457 bfa_sm_fault(fabric->fcs, event);
458 }
459}
460
Jing Huang5fbe25c2010-10-18 17:17:23 -0700461/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700462 * Authentication is in progress, awaiting authentication results.
463 */
464static void
465bfa_fcs_fabric_sm_auth(struct bfa_fcs_fabric_s *fabric,
466 enum bfa_fcs_fabric_event event)
467{
468 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
469 bfa_trc(fabric->fcs, event);
470
471 switch (event) {
472 case BFA_FCS_FABRIC_SM_AUTH_FAILED:
473 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_auth_failed);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800474 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700475 break;
476
477 case BFA_FCS_FABRIC_SM_AUTH_SUCCESS:
478 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_online);
479 bfa_fcs_fabric_notify_online(fabric);
480 break;
481
482 case BFA_FCS_FABRIC_SM_PERF_EVFP:
483 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_evfp);
484 break;
485
486 case BFA_FCS_FABRIC_SM_LINK_DOWN:
487 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800488 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700489 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
Jing Huang5fbe25c2010-10-18 17:17:23 -0700501/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700502 * Authentication failed
503 */
Maggie Zhangf7f738122010-12-09 19:08:43 -0800504void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700505bfa_fcs_fabric_sm_auth_failed(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);
514 bfa_fcs_fabric_notify_offline(fabric);
515 break;
516
517 case BFA_FCS_FABRIC_SM_DELETE:
518 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
519 bfa_fcs_fabric_delete(fabric);
520 break;
521
522 default:
523 bfa_sm_fault(fabric->fcs, event);
524 }
525}
526
Jing Huang5fbe25c2010-10-18 17:17:23 -0700527/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700528 * Port is in loopback mode.
529 */
Maggie Zhangf7f738122010-12-09 19:08:43 -0800530void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700531bfa_fcs_fabric_sm_loopback(struct bfa_fcs_fabric_s *fabric,
532 enum bfa_fcs_fabric_event event)
533{
534 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
535 bfa_trc(fabric->fcs, event);
536
537 switch (event) {
538 case BFA_FCS_FABRIC_SM_LINK_DOWN:
539 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
540 bfa_fcs_fabric_notify_offline(fabric);
541 break;
542
543 case BFA_FCS_FABRIC_SM_DELETE:
544 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
545 bfa_fcs_fabric_delete(fabric);
546 break;
547
548 default:
549 bfa_sm_fault(fabric->fcs, event);
550 }
551}
552
Jing Huang5fbe25c2010-10-18 17:17:23 -0700553/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700554 * There is no attached fabric - private loop or NPort-to-NPort topology.
555 */
556static void
557bfa_fcs_fabric_sm_nofabric(struct bfa_fcs_fabric_s *fabric,
558 enum bfa_fcs_fabric_event event)
559{
560 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
561 bfa_trc(fabric->fcs, event);
562
563 switch (event) {
564 case BFA_FCS_FABRIC_SM_LINK_DOWN:
565 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800566 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700567 bfa_fcs_fabric_notify_offline(fabric);
568 break;
569
570 case BFA_FCS_FABRIC_SM_DELETE:
571 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
572 bfa_fcs_fabric_delete(fabric);
573 break;
574
575 case BFA_FCS_FABRIC_SM_NO_FABRIC:
576 bfa_trc(fabric->fcs, fabric->bb_credit);
577 bfa_fcport_set_tx_bbcredit(fabric->fcs->bfa,
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700578 fabric->bb_credit,
579 bfa_fcs_fabric_oper_bbscn(fabric));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700580 break;
581
Krishna Gudipatid7be54c2011-06-24 20:24:52 -0700582 case BFA_FCS_FABRIC_SM_RETRY_OP:
583 break;
584
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700585 default:
586 bfa_sm_fault(fabric->fcs, event);
587 }
588}
589
Jing Huang5fbe25c2010-10-18 17:17:23 -0700590/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700591 * Fabric is online - normal operating state.
592 */
Maggie Zhangf7f738122010-12-09 19:08:43 -0800593void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700594bfa_fcs_fabric_sm_online(struct bfa_fcs_fabric_s *fabric,
595 enum bfa_fcs_fabric_event event)
596{
597 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
598 bfa_trc(fabric->fcs, event);
599
600 switch (event) {
601 case BFA_FCS_FABRIC_SM_LINK_DOWN:
602 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800603 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700604 bfa_fcs_fabric_notify_offline(fabric);
605 break;
606
607 case BFA_FCS_FABRIC_SM_DELETE:
608 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
609 bfa_fcs_fabric_delete(fabric);
610 break;
611
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700612 case BFA_FCS_FABRIC_SM_STOP:
613 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_stopping);
614 bfa_fcs_fabric_stop(fabric);
615 break;
616
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700617 case BFA_FCS_FABRIC_SM_AUTH_FAILED:
618 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_auth_failed);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800619 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700620 break;
621
622 case BFA_FCS_FABRIC_SM_AUTH_SUCCESS:
623 break;
624
625 default:
626 bfa_sm_fault(fabric->fcs, event);
627 }
628}
629
Jing Huang5fbe25c2010-10-18 17:17:23 -0700630/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700631 * Exchanging virtual fabric parameters.
632 */
633static void
634bfa_fcs_fabric_sm_evfp(struct bfa_fcs_fabric_s *fabric,
635 enum bfa_fcs_fabric_event event)
636{
637 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
638 bfa_trc(fabric->fcs, event);
639
640 switch (event) {
641 case BFA_FCS_FABRIC_SM_CONT_OP:
642 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_evfp_done);
643 break;
644
645 case BFA_FCS_FABRIC_SM_ISOLATE:
646 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_isolated);
647 break;
648
649 default:
650 bfa_sm_fault(fabric->fcs, event);
651 }
652}
653
Jing Huang5fbe25c2010-10-18 17:17:23 -0700654/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700655 * EVFP exchange complete and VFT tagging is enabled.
656 */
657static void
658bfa_fcs_fabric_sm_evfp_done(struct bfa_fcs_fabric_s *fabric,
659 enum bfa_fcs_fabric_event event)
660{
661 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
662 bfa_trc(fabric->fcs, event);
663}
664
Jing Huang5fbe25c2010-10-18 17:17:23 -0700665/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700666 * Port is isolated after EVFP exchange due to VF_ID mismatch (N and F).
667 */
668static void
669bfa_fcs_fabric_sm_isolated(struct bfa_fcs_fabric_s *fabric,
670 enum bfa_fcs_fabric_event event)
671{
672 struct bfad_s *bfad = (struct bfad_s *)fabric->fcs->bfad;
673 char pwwn_ptr[BFA_STRING_32];
674
675 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
676 bfa_trc(fabric->fcs, event);
677 wwn2str(pwwn_ptr, fabric->bport.port_cfg.pwwn);
678
Jing Huang88166242010-12-09 17:11:53 -0800679 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700680 "Port is isolated due to VF_ID mismatch. "
681 "PWWN: %s Port VF_ID: %04x switch port VF_ID: %04x.",
682 pwwn_ptr, fabric->fcs->port_vfid,
683 fabric->event_arg.swp_vfid);
684}
685
Jing Huang5fbe25c2010-10-18 17:17:23 -0700686/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700687 * Fabric is being deleted, awaiting vport delete completions.
688 */
689static void
690bfa_fcs_fabric_sm_deleting(struct bfa_fcs_fabric_s *fabric,
691 enum bfa_fcs_fabric_event event)
692{
693 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
694 bfa_trc(fabric->fcs, event);
695
696 switch (event) {
697 case BFA_FCS_FABRIC_SM_DELCOMP:
698 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_uninit);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800699 bfa_wc_down(&fabric->fcs->wc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700700 break;
701
702 case BFA_FCS_FABRIC_SM_LINK_UP:
703 break;
704
705 case BFA_FCS_FABRIC_SM_LINK_DOWN:
706 bfa_fcs_fabric_notify_offline(fabric);
707 break;
708
709 default:
710 bfa_sm_fault(fabric->fcs, event);
711 }
712}
713
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700714/*
715 * Fabric is being stopped, awaiting vport stop completions.
716 */
717static void
718bfa_fcs_fabric_sm_stopping(struct bfa_fcs_fabric_s *fabric,
719 enum bfa_fcs_fabric_event event)
720{
721 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
722 bfa_trc(fabric->fcs, event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700723
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700724 switch (event) {
725 case BFA_FCS_FABRIC_SM_STOPCOMP:
726 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_cleanup);
727 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_LOGOUT);
728 break;
729
730 case BFA_FCS_FABRIC_SM_LINK_UP:
731 break;
732
733 case BFA_FCS_FABRIC_SM_LINK_DOWN:
734 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_cleanup);
735 break;
736
737 default:
738 bfa_sm_fault(fabric->fcs, event);
739 }
740}
741
742/*
743 * Fabric is being stopped, cleanup without FLOGO
744 */
745static void
746bfa_fcs_fabric_sm_cleanup(struct bfa_fcs_fabric_s *fabric,
747 enum bfa_fcs_fabric_event event)
748{
749 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
750 bfa_trc(fabric->fcs, event);
751
752 switch (event) {
753 case BFA_FCS_FABRIC_SM_STOPCOMP:
754 case BFA_FCS_FABRIC_SM_LOGOCOMP:
755 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_created);
756 bfa_wc_down(&(fabric->fcs)->wc);
757 break;
758
759 case BFA_FCS_FABRIC_SM_LINK_DOWN:
760 /*
761 * Ignore - can get this event if we get notified about IOC down
762 * before the fabric completion callbk is done.
763 */
764 break;
765
766 default:
767 bfa_sm_fault(fabric->fcs, event);
768 }
769}
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700770
Jing Huang5fbe25c2010-10-18 17:17:23 -0700771/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700772 * fcs_fabric_private fabric private functions
773 */
774
775static void
776bfa_fcs_fabric_init(struct bfa_fcs_fabric_s *fabric)
777{
778 struct bfa_lport_cfg_s *port_cfg = &fabric->bport.port_cfg;
779
780 port_cfg->roles = BFA_LPORT_ROLE_FCP_IM;
Maggie Zhangf7f738122010-12-09 19:08:43 -0800781 port_cfg->nwwn = fabric->fcs->bfa->ioc.attr->nwwn;
782 port_cfg->pwwn = fabric->fcs->bfa->ioc.attr->pwwn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700783}
784
Jing Huang5fbe25c2010-10-18 17:17:23 -0700785/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700786 * Port Symbolic Name Creation for base port.
787 */
788void
789bfa_fcs_fabric_psymb_init(struct bfa_fcs_fabric_s *fabric)
790{
791 struct bfa_lport_cfg_s *port_cfg = &fabric->bport.port_cfg;
792 char model[BFA_ADAPTER_MODEL_NAME_LEN] = {0};
793 struct bfa_fcs_driver_info_s *driver_info = &fabric->fcs->driver_info;
794
795 bfa_ioc_get_adapter_model(&fabric->fcs->bfa->ioc, model);
796
797 /* Model name/number */
798 strncpy((char *)&port_cfg->sym_name, model,
799 BFA_FCS_PORT_SYMBNAME_MODEL_SZ);
800 strncat((char *)&port_cfg->sym_name, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
801 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
802
803 /* Driver Version */
804 strncat((char *)&port_cfg->sym_name, (char *)driver_info->version,
805 BFA_FCS_PORT_SYMBNAME_VERSION_SZ);
806 strncat((char *)&port_cfg->sym_name, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
807 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
808
809 /* Host machine name */
810 strncat((char *)&port_cfg->sym_name,
811 (char *)driver_info->host_machine_name,
812 BFA_FCS_PORT_SYMBNAME_MACHINENAME_SZ);
813 strncat((char *)&port_cfg->sym_name, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
814 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
815
816 /*
817 * Host OS Info :
818 * If OS Patch Info is not there, do not truncate any bytes from the
819 * OS name string and instead copy the entire OS info string (64 bytes).
820 */
821 if (driver_info->host_os_patch[0] == '\0') {
822 strncat((char *)&port_cfg->sym_name,
823 (char *)driver_info->host_os_name,
824 BFA_FCS_OS_STR_LEN);
825 strncat((char *)&port_cfg->sym_name,
826 BFA_FCS_PORT_SYMBNAME_SEPARATOR,
827 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
828 } else {
829 strncat((char *)&port_cfg->sym_name,
830 (char *)driver_info->host_os_name,
831 BFA_FCS_PORT_SYMBNAME_OSINFO_SZ);
832 strncat((char *)&port_cfg->sym_name,
833 BFA_FCS_PORT_SYMBNAME_SEPARATOR,
834 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
835
836 /* Append host OS Patch Info */
837 strncat((char *)&port_cfg->sym_name,
838 (char *)driver_info->host_os_patch,
839 BFA_FCS_PORT_SYMBNAME_OSPATCH_SZ);
840 }
841
842 /* null terminate */
843 port_cfg->sym_name.symname[BFA_SYMNAME_MAXLEN - 1] = 0;
844}
845
Jing Huang5fbe25c2010-10-18 17:17:23 -0700846/*
Krishna Gudipatice7242b2012-08-22 19:52:43 -0700847 * Node Symbolic Name Creation for base port and all vports
848 */
849void
850bfa_fcs_fabric_nsymb_init(struct bfa_fcs_fabric_s *fabric)
851{
852 struct bfa_lport_cfg_s *port_cfg = &fabric->bport.port_cfg;
853 char model[BFA_ADAPTER_MODEL_NAME_LEN] = {0};
854 struct bfa_fcs_driver_info_s *driver_info = &fabric->fcs->driver_info;
855
856 bfa_ioc_get_adapter_model(&fabric->fcs->bfa->ioc, model);
857
858 /* Model name/number */
859 strncpy((char *)&port_cfg->node_sym_name, model,
860 BFA_FCS_PORT_SYMBNAME_MODEL_SZ);
861 strncat((char *)&port_cfg->node_sym_name,
862 BFA_FCS_PORT_SYMBNAME_SEPARATOR,
863 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
864
865 /* Driver Version */
866 strncat((char *)&port_cfg->node_sym_name, (char *)driver_info->version,
867 BFA_FCS_PORT_SYMBNAME_VERSION_SZ);
868 strncat((char *)&port_cfg->node_sym_name,
869 BFA_FCS_PORT_SYMBNAME_SEPARATOR,
870 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
871
872 /* Host machine name */
873 strncat((char *)&port_cfg->node_sym_name,
874 (char *)driver_info->host_machine_name,
875 BFA_FCS_PORT_SYMBNAME_MACHINENAME_SZ);
876 strncat((char *)&port_cfg->node_sym_name,
877 BFA_FCS_PORT_SYMBNAME_SEPARATOR,
878 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
879
880 /* null terminate */
881 port_cfg->node_sym_name.symname[BFA_SYMNAME_MAXLEN - 1] = 0;
882}
883
884/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700885 * bfa lps login completion callback
886 */
887void
888bfa_cb_lps_flogi_comp(void *bfad, void *uarg, bfa_status_t status)
889{
890 struct bfa_fcs_fabric_s *fabric = uarg;
891
892 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
893 bfa_trc(fabric->fcs, status);
894
895 switch (status) {
896 case BFA_STATUS_OK:
897 fabric->stats.flogi_accepts++;
898 break;
899
900 case BFA_STATUS_INVALID_MAC:
901 /* Only for CNA */
902 fabric->stats.flogi_acc_err++;
903 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_RETRY_OP);
904
905 return;
906
907 case BFA_STATUS_EPROTOCOL:
Maggie Zhangf7f738122010-12-09 19:08:43 -0800908 switch (fabric->lps->ext_status) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700909 case BFA_EPROTO_BAD_ACCEPT:
910 fabric->stats.flogi_acc_err++;
911 break;
912
913 case BFA_EPROTO_UNKNOWN_RSP:
914 fabric->stats.flogi_unknown_rsp++;
915 break;
916
917 default:
918 break;
919 }
920 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_RETRY_OP);
921
922 return;
923
924 case BFA_STATUS_FABRIC_RJT:
925 fabric->stats.flogi_rejects++;
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700926 if (fabric->lps->lsrjt_rsn == FC_LS_RJT_RSN_LOGICAL_ERROR &&
927 fabric->lps->lsrjt_expl == FC_LS_RJT_EXP_NO_ADDL_INFO)
928 fabric->fcs->bbscn_flogi_rjt = BFA_TRUE;
929
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700930 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_RETRY_OP);
931 return;
932
933 default:
934 fabric->stats.flogi_rsp_err++;
935 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_RETRY_OP);
936 return;
937 }
938
Maggie Zhangf7f738122010-12-09 19:08:43 -0800939 fabric->bb_credit = fabric->lps->pr_bbcred;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700940 bfa_trc(fabric->fcs, fabric->bb_credit);
941
Maggie Zhangf7f738122010-12-09 19:08:43 -0800942 if (!(fabric->lps->brcd_switch))
943 fabric->fabric_name = fabric->lps->pr_nwwn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700944
945 /*
946 * Check port type. It should be 1 = F-port.
947 */
Maggie Zhangf7f738122010-12-09 19:08:43 -0800948 if (fabric->lps->fport) {
949 fabric->bport.pid = fabric->lps->lp_pid;
950 fabric->is_npiv = fabric->lps->npiv_en;
951 fabric->is_auth = fabric->lps->auth_req;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700952 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_CONT_OP);
953 } else {
954 /*
955 * Nport-2-Nport direct attached
956 */
957 fabric->bport.port_topo.pn2n.rem_port_wwn =
Maggie Zhangf7f738122010-12-09 19:08:43 -0800958 fabric->lps->pr_pwwn;
Krishna Gudipatid7be54c2011-06-24 20:24:52 -0700959 fabric->fab_type = BFA_FCS_FABRIC_N2N;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700960 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_NO_FABRIC);
961 }
962
963 bfa_trc(fabric->fcs, fabric->bport.pid);
964 bfa_trc(fabric->fcs, fabric->is_npiv);
965 bfa_trc(fabric->fcs, fabric->is_auth);
966}
Jing Huang5fbe25c2010-10-18 17:17:23 -0700967/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700968 * Allocate and send FLOGI.
969 */
970static void
971bfa_fcs_fabric_login(struct bfa_fcs_fabric_s *fabric)
972{
973 struct bfa_s *bfa = fabric->fcs->bfa;
974 struct bfa_lport_cfg_s *pcfg = &fabric->bport.port_cfg;
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700975 u8 alpa = 0, bb_scn = 0;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700976
977 if (bfa_fcport_get_topology(bfa) == BFA_PORT_TOPOLOGY_LOOP)
978 alpa = bfa_fcport_get_myalpa(bfa);
979
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700980 if (bfa_fcs_fabric_is_bbscn_enabled(fabric) &&
981 (!fabric->fcs->bbscn_flogi_rjt))
982 bb_scn = BFA_FCS_PORT_DEF_BB_SCN;
983
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700984 bfa_lps_flogi(fabric->lps, fabric, alpa, bfa_fcport_get_maxfrsize(bfa),
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700985 pcfg->pwwn, pcfg->nwwn, fabric->auth_reqd, bb_scn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700986
987 fabric->stats.flogi_sent++;
988}
989
990static void
991bfa_fcs_fabric_notify_online(struct bfa_fcs_fabric_s *fabric)
992{
993 struct bfa_fcs_vport_s *vport;
994 struct list_head *qe, *qen;
995
996 bfa_trc(fabric->fcs, fabric->fabric_name);
997
998 bfa_fcs_fabric_set_opertype(fabric);
999 fabric->stats.fabric_onlines++;
1000
Jing Huang5fbe25c2010-10-18 17:17:23 -07001001 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001002 * notify online event to base and then virtual ports
1003 */
1004 bfa_fcs_lport_online(&fabric->bport);
1005
1006 list_for_each_safe(qe, qen, &fabric->vport_q) {
1007 vport = (struct bfa_fcs_vport_s *) qe;
1008 bfa_fcs_vport_online(vport);
1009 }
1010}
1011
1012static void
1013bfa_fcs_fabric_notify_offline(struct bfa_fcs_fabric_s *fabric)
1014{
1015 struct bfa_fcs_vport_s *vport;
1016 struct list_head *qe, *qen;
1017
1018 bfa_trc(fabric->fcs, fabric->fabric_name);
1019 fabric->stats.fabric_offlines++;
1020
Jing Huang5fbe25c2010-10-18 17:17:23 -07001021 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001022 * notify offline event first to vports and then base port.
1023 */
1024 list_for_each_safe(qe, qen, &fabric->vport_q) {
1025 vport = (struct bfa_fcs_vport_s *) qe;
1026 bfa_fcs_vport_offline(vport);
1027 }
1028
1029 bfa_fcs_lport_offline(&fabric->bport);
1030
1031 fabric->fabric_name = 0;
1032 fabric->fabric_ip_addr[0] = 0;
1033}
1034
1035static void
1036bfa_fcs_fabric_delay(void *cbarg)
1037{
1038 struct bfa_fcs_fabric_s *fabric = cbarg;
1039
1040 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_DELAYED);
1041}
1042
Jing Huang5fbe25c2010-10-18 17:17:23 -07001043/*
Krishna Gudipati881c1b32012-08-22 19:52:02 -07001044 * Stop all vports and wait for vport stop completions.
1045 */
1046static void
1047bfa_fcs_fabric_stop(struct bfa_fcs_fabric_s *fabric)
1048{
1049 struct bfa_fcs_vport_s *vport;
1050 struct list_head *qe, *qen;
1051
1052 bfa_wc_init(&fabric->stop_wc, bfa_fcs_fabric_stop_comp, fabric);
1053
1054 list_for_each_safe(qe, qen, &fabric->vport_q) {
1055 vport = (struct bfa_fcs_vport_s *) qe;
1056 bfa_wc_up(&fabric->stop_wc);
1057 bfa_fcs_vport_fcs_stop(vport);
1058 }
1059
1060 bfa_wc_up(&fabric->stop_wc);
1061 bfa_fcs_lport_stop(&fabric->bport);
1062 bfa_wc_wait(&fabric->stop_wc);
1063}
1064
1065/*
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001066 * Computes operating BB_SCN value
1067 */
1068static u8
1069bfa_fcs_fabric_oper_bbscn(struct bfa_fcs_fabric_s *fabric)
1070{
1071 u8 pr_bbscn = fabric->lps->pr_bbscn;
Krishna Gudipatid7be54c2011-06-24 20:24:52 -07001072 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(fabric->fcs->bfa);
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001073
Krishna Gudipatid7be54c2011-06-24 20:24:52 -07001074 if (!(fcport->cfg.bb_scn_state && pr_bbscn))
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001075 return 0;
1076
1077 /* return max of local/remote bb_scn values */
1078 return ((pr_bbscn > BFA_FCS_PORT_DEF_BB_SCN) ?
1079 pr_bbscn : BFA_FCS_PORT_DEF_BB_SCN);
1080}
1081
1082/*
1083 * Check if BB_SCN can be enabled.
1084 */
1085static bfa_boolean_t
1086bfa_fcs_fabric_is_bbscn_enabled(struct bfa_fcs_fabric_s *fabric)
1087{
Krishna Gudipatid7be54c2011-06-24 20:24:52 -07001088 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(fabric->fcs->bfa);
1089
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001090 if (bfa_ioc_get_fcmode(&fabric->fcs->bfa->ioc) &&
Krishna Gudipatid7be54c2011-06-24 20:24:52 -07001091 fcport->cfg.bb_scn_state &&
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001092 !bfa_fcport_is_qos_enabled(fabric->fcs->bfa) &&
1093 !bfa_fcport_is_trunk_enabled(fabric->fcs->bfa))
1094 return BFA_TRUE;
1095 else
1096 return BFA_FALSE;
1097}
1098
1099/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001100 * Delete all vports and wait for vport delete completions.
1101 */
1102static void
1103bfa_fcs_fabric_delete(struct bfa_fcs_fabric_s *fabric)
1104{
1105 struct bfa_fcs_vport_s *vport;
1106 struct list_head *qe, *qen;
1107
1108 list_for_each_safe(qe, qen, &fabric->vport_q) {
1109 vport = (struct bfa_fcs_vport_s *) qe;
1110 bfa_fcs_vport_fcs_delete(vport);
1111 }
1112
1113 bfa_fcs_lport_delete(&fabric->bport);
1114 bfa_wc_wait(&fabric->wc);
1115}
1116
1117static void
1118bfa_fcs_fabric_delete_comp(void *cbarg)
1119{
1120 struct bfa_fcs_fabric_s *fabric = cbarg;
1121
1122 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_DELCOMP);
1123}
1124
Krishna Gudipati881c1b32012-08-22 19:52:02 -07001125static void
1126bfa_fcs_fabric_stop_comp(void *cbarg)
1127{
1128 struct bfa_fcs_fabric_s *fabric = cbarg;
1129
1130 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_STOPCOMP);
1131}
1132
Jing Huang5fbe25c2010-10-18 17:17:23 -07001133/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001134 * fcs_fabric_public fabric public functions
1135 */
1136
Jing Huang5fbe25c2010-10-18 17:17:23 -07001137/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001138 * Attach time initialization.
1139 */
1140void
1141bfa_fcs_fabric_attach(struct bfa_fcs_s *fcs)
1142{
1143 struct bfa_fcs_fabric_s *fabric;
1144
1145 fabric = &fcs->fabric;
Jing Huang6a18b162010-10-18 17:08:54 -07001146 memset(fabric, 0, sizeof(struct bfa_fcs_fabric_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001147
Jing Huang5fbe25c2010-10-18 17:17:23 -07001148 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001149 * Initialize base fabric.
1150 */
1151 fabric->fcs = fcs;
1152 INIT_LIST_HEAD(&fabric->vport_q);
1153 INIT_LIST_HEAD(&fabric->vf_q);
1154 fabric->lps = bfa_lps_alloc(fcs->bfa);
Jing Huangd4b671c2010-12-26 21:46:35 -08001155 WARN_ON(!fabric->lps);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001156
Jing Huang5fbe25c2010-10-18 17:17:23 -07001157 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001158 * Initialize fabric delete completion handler. Fabric deletion is
1159 * complete when the last vport delete is complete.
1160 */
1161 bfa_wc_init(&fabric->wc, bfa_fcs_fabric_delete_comp, fabric);
1162 bfa_wc_up(&fabric->wc); /* For the base port */
1163
1164 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_uninit);
1165 bfa_fcs_lport_attach(&fabric->bport, fabric->fcs, FC_VF_ID_NULL, NULL);
1166}
1167
1168void
1169bfa_fcs_fabric_modinit(struct bfa_fcs_s *fcs)
1170{
1171 bfa_sm_send_event(&fcs->fabric, BFA_FCS_FABRIC_SM_CREATE);
1172 bfa_trc(fcs, 0);
1173}
1174
Jing Huang5fbe25c2010-10-18 17:17:23 -07001175/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001176 * Module cleanup
1177 */
1178void
1179bfa_fcs_fabric_modexit(struct bfa_fcs_s *fcs)
1180{
1181 struct bfa_fcs_fabric_s *fabric;
1182
1183 bfa_trc(fcs, 0);
1184
Jing Huang5fbe25c2010-10-18 17:17:23 -07001185 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001186 * Cleanup base fabric.
1187 */
1188 fabric = &fcs->fabric;
1189 bfa_lps_delete(fabric->lps);
1190 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_DELETE);
1191}
1192
Jing Huang5fbe25c2010-10-18 17:17:23 -07001193/*
Krishna Gudipati881c1b32012-08-22 19:52:02 -07001194 * Fabric module stop -- stop FCS actions
1195 */
1196void
1197bfa_fcs_fabric_modstop(struct bfa_fcs_s *fcs)
1198{
1199 struct bfa_fcs_fabric_s *fabric;
1200
1201 bfa_trc(fcs, 0);
1202 fabric = &fcs->fabric;
1203 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_STOP);
1204}
1205
1206/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001207 * Fabric module start -- kick starts FCS actions
1208 */
1209void
1210bfa_fcs_fabric_modstart(struct bfa_fcs_s *fcs)
1211{
1212 struct bfa_fcs_fabric_s *fabric;
1213
1214 bfa_trc(fcs, 0);
1215 fabric = &fcs->fabric;
1216 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_START);
1217}
1218
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001219
Jing Huang5fbe25c2010-10-18 17:17:23 -07001220/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001221 * Link up notification from BFA physical port module.
1222 */
1223void
1224bfa_fcs_fabric_link_up(struct bfa_fcs_fabric_s *fabric)
1225{
1226 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
1227 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_LINK_UP);
1228}
1229
Jing Huang5fbe25c2010-10-18 17:17:23 -07001230/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001231 * Link down notification from BFA physical port module.
1232 */
1233void
1234bfa_fcs_fabric_link_down(struct bfa_fcs_fabric_s *fabric)
1235{
1236 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001237 fabric->fcs->bbscn_flogi_rjt = BFA_FALSE;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001238 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_LINK_DOWN);
1239}
1240
Jing Huang5fbe25c2010-10-18 17:17:23 -07001241/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001242 * A child vport is being created in the fabric.
1243 *
1244 * Call from vport module at vport creation. A list of base port and vports
1245 * belonging to a fabric is maintained to propagate link events.
1246 *
1247 * param[in] fabric - Fabric instance. This can be a base fabric or vf.
1248 * param[in] vport - Vport being created.
1249 *
1250 * @return None (always succeeds)
1251 */
1252void
1253bfa_fcs_fabric_addvport(struct bfa_fcs_fabric_s *fabric,
1254 struct bfa_fcs_vport_s *vport)
1255{
Jing Huang5fbe25c2010-10-18 17:17:23 -07001256 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001257 * - add vport to fabric's vport_q
1258 */
1259 bfa_trc(fabric->fcs, fabric->vf_id);
1260
1261 list_add_tail(&vport->qe, &fabric->vport_q);
1262 fabric->num_vports++;
1263 bfa_wc_up(&fabric->wc);
1264}
1265
Jing Huang5fbe25c2010-10-18 17:17:23 -07001266/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001267 * A child vport is being deleted from fabric.
1268 *
1269 * Vport is being deleted.
1270 */
1271void
1272bfa_fcs_fabric_delvport(struct bfa_fcs_fabric_s *fabric,
1273 struct bfa_fcs_vport_s *vport)
1274{
1275 list_del(&vport->qe);
1276 fabric->num_vports--;
1277 bfa_wc_down(&fabric->wc);
1278}
1279
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001280
Jing Huang5fbe25c2010-10-18 17:17:23 -07001281/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001282 * Lookup for a vport within a fabric given its pwwn
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001283 */
1284struct bfa_fcs_vport_s *
1285bfa_fcs_fabric_vport_lookup(struct bfa_fcs_fabric_s *fabric, wwn_t pwwn)
1286{
1287 struct bfa_fcs_vport_s *vport;
1288 struct list_head *qe;
1289
1290 list_for_each(qe, &fabric->vport_q) {
1291 vport = (struct bfa_fcs_vport_s *) qe;
1292 if (bfa_fcs_lport_get_pwwn(&vport->lport) == pwwn)
1293 return vport;
1294 }
1295
1296 return NULL;
1297}
1298
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001299
1300/*
1301 * Get OUI of the attached switch.
1302 *
1303 * Note : Use of this function should be avoided as much as possible.
1304 * This function should be used only if there is any requirement
1305* to check for FOS version below 6.3.
1306 * To check if the attached fabric is a brocade fabric, use
1307 * bfa_lps_is_brcd_fabric() which works for FOS versions 6.3
1308 * or above only.
1309 */
1310
1311u16
1312bfa_fcs_fabric_get_switch_oui(struct bfa_fcs_fabric_s *fabric)
1313{
1314 wwn_t fab_nwwn;
1315 u8 *tmp;
1316 u16 oui;
1317
Maggie Zhangf7f738122010-12-09 19:08:43 -08001318 fab_nwwn = fabric->lps->pr_nwwn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001319
1320 tmp = (u8 *)&fab_nwwn;
1321 oui = (tmp[3] << 8) | tmp[4];
1322
1323 return oui;
1324}
Jing Huang5fbe25c2010-10-18 17:17:23 -07001325/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001326 * Unsolicited frame receive handling.
1327 */
1328void
1329bfa_fcs_fabric_uf_recv(struct bfa_fcs_fabric_s *fabric, struct fchs_s *fchs,
1330 u16 len)
1331{
1332 u32 pid = fchs->d_id;
1333 struct bfa_fcs_vport_s *vport;
1334 struct list_head *qe;
1335 struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
1336 struct fc_logi_s *flogi = (struct fc_logi_s *) els_cmd;
1337
1338 bfa_trc(fabric->fcs, len);
1339 bfa_trc(fabric->fcs, pid);
1340
Jing Huang5fbe25c2010-10-18 17:17:23 -07001341 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001342 * Look for our own FLOGI frames being looped back. This means an
1343 * external loopback cable is in place. Our own FLOGI frames are
1344 * sometimes looped back when switch port gets temporarily bypassed.
1345 */
Maggie Zhangf16a1752010-12-09 19:12:32 -08001346 if ((pid == bfa_ntoh3b(FC_FABRIC_PORT)) &&
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001347 (els_cmd->els_code == FC_ELS_FLOGI) &&
1348 (flogi->port_name == bfa_fcs_lport_get_pwwn(&fabric->bport))) {
1349 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_LOOPBACK);
1350 return;
1351 }
1352
Jing Huang5fbe25c2010-10-18 17:17:23 -07001353 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001354 * FLOGI/EVFP exchanges should be consumed by base fabric.
1355 */
Maggie Zhangf16a1752010-12-09 19:12:32 -08001356 if (fchs->d_id == bfa_hton3b(FC_FABRIC_PORT)) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001357 bfa_trc(fabric->fcs, pid);
1358 bfa_fcs_fabric_process_uf(fabric, fchs, len);
1359 return;
1360 }
1361
1362 if (fabric->bport.pid == pid) {
Jing Huang5fbe25c2010-10-18 17:17:23 -07001363 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001364 * All authentication frames should be routed to auth
1365 */
1366 bfa_trc(fabric->fcs, els_cmd->els_code);
1367 if (els_cmd->els_code == FC_ELS_AUTH) {
1368 bfa_trc(fabric->fcs, els_cmd->els_code);
1369 return;
1370 }
1371
1372 bfa_trc(fabric->fcs, *(u8 *) ((u8 *) fchs));
1373 bfa_fcs_lport_uf_recv(&fabric->bport, fchs, len);
1374 return;
1375 }
1376
Jing Huang5fbe25c2010-10-18 17:17:23 -07001377 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001378 * look for a matching local port ID
1379 */
1380 list_for_each(qe, &fabric->vport_q) {
1381 vport = (struct bfa_fcs_vport_s *) qe;
1382 if (vport->lport.pid == pid) {
1383 bfa_fcs_lport_uf_recv(&vport->lport, fchs, len);
1384 return;
1385 }
1386 }
1387 bfa_trc(fabric->fcs, els_cmd->els_code);
1388 bfa_fcs_lport_uf_recv(&fabric->bport, fchs, len);
1389}
1390
Jing Huang5fbe25c2010-10-18 17:17:23 -07001391/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001392 * Unsolicited frames to be processed by fabric.
1393 */
1394static void
1395bfa_fcs_fabric_process_uf(struct bfa_fcs_fabric_s *fabric, struct fchs_s *fchs,
1396 u16 len)
1397{
1398 struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
1399
1400 bfa_trc(fabric->fcs, els_cmd->els_code);
1401
1402 switch (els_cmd->els_code) {
1403 case FC_ELS_FLOGI:
1404 bfa_fcs_fabric_process_flogi(fabric, fchs, len);
1405 break;
1406
1407 default:
1408 /*
1409 * need to generate a LS_RJT
1410 */
1411 break;
1412 }
1413}
1414
Jing Huang5fbe25c2010-10-18 17:17:23 -07001415/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001416 * Process incoming FLOGI
1417 */
1418static void
1419bfa_fcs_fabric_process_flogi(struct bfa_fcs_fabric_s *fabric,
1420 struct fchs_s *fchs, u16 len)
1421{
1422 struct fc_logi_s *flogi = (struct fc_logi_s *) (fchs + 1);
1423 struct bfa_fcs_lport_s *bport = &fabric->bport;
1424
1425 bfa_trc(fabric->fcs, fchs->s_id);
1426
1427 fabric->stats.flogi_rcvd++;
1428 /*
1429 * Check port type. It should be 0 = n-port.
1430 */
1431 if (flogi->csp.port_type) {
1432 /*
1433 * @todo: may need to send a LS_RJT
1434 */
1435 bfa_trc(fabric->fcs, flogi->port_name);
1436 fabric->stats.flogi_rejected++;
1437 return;
1438 }
1439
Jing Huangba816ea2010-10-18 17:10:50 -07001440 fabric->bb_credit = be16_to_cpu(flogi->csp.bbcred);
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001441 fabric->lps->pr_bbscn = (be16_to_cpu(flogi->csp.rxsz) >> 12);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001442 bport->port_topo.pn2n.rem_port_wwn = flogi->port_name;
1443 bport->port_topo.pn2n.reply_oxid = fchs->ox_id;
1444
1445 /*
1446 * Send a Flogi Acc
1447 */
1448 bfa_fcs_fabric_send_flogi_acc(fabric);
1449 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_NO_FABRIC);
1450}
1451
1452static void
1453bfa_fcs_fabric_send_flogi_acc(struct bfa_fcs_fabric_s *fabric)
1454{
1455 struct bfa_lport_cfg_s *pcfg = &fabric->bport.port_cfg;
1456 struct bfa_fcs_lport_n2n_s *n2n_port = &fabric->bport.port_topo.pn2n;
1457 struct bfa_s *bfa = fabric->fcs->bfa;
1458 struct bfa_fcxp_s *fcxp;
1459 u16 reqlen;
1460 struct fchs_s fchs;
1461
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07001462 fcxp = bfa_fcs_fcxp_alloc(fabric->fcs, BFA_FALSE);
Jing Huang5fbe25c2010-10-18 17:17:23 -07001463 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001464 * Do not expect this failure -- expect remote node to retry
1465 */
1466 if (!fcxp)
1467 return;
1468
1469 reqlen = fc_flogi_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
Maggie Zhangf16a1752010-12-09 19:12:32 -08001470 bfa_hton3b(FC_FABRIC_PORT),
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001471 n2n_port->reply_oxid, pcfg->pwwn,
1472 pcfg->nwwn,
1473 bfa_fcport_get_maxfrsize(bfa),
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001474 bfa_fcport_get_rx_bbcredit(bfa),
1475 bfa_fcs_fabric_oper_bbscn(fabric));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001476
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001477 bfa_fcxp_send(fcxp, NULL, fabric->vf_id, fabric->lps->bfa_tag,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001478 BFA_FALSE, FC_CLASS_3,
1479 reqlen, &fchs, bfa_fcs_fabric_flogiacc_comp, fabric,
1480 FC_MAX_PDUSZ, 0);
1481}
1482
Jing Huang5fbe25c2010-10-18 17:17:23 -07001483/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001484 * Flogi Acc completion callback.
1485 */
1486static void
1487bfa_fcs_fabric_flogiacc_comp(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
1488 bfa_status_t status, u32 rsp_len,
1489 u32 resid_len, struct fchs_s *rspfchs)
1490{
1491 struct bfa_fcs_fabric_s *fabric = cbarg;
1492
1493 bfa_trc(fabric->fcs, status);
1494}
1495
Krishna Gudipati7826f302011-07-20 16:59:13 -07001496
1497/*
1498 * Send AEN notification
1499 */
1500static void
1501bfa_fcs_fabric_aen_post(struct bfa_fcs_lport_s *port,
1502 enum bfa_port_aen_event event)
1503{
1504 struct bfad_s *bfad = (struct bfad_s *)port->fabric->fcs->bfad;
1505 struct bfa_aen_entry_s *aen_entry;
1506
1507 bfad_get_aen_entry(bfad, aen_entry);
1508 if (!aen_entry)
1509 return;
1510
1511 aen_entry->aen_data.port.pwwn = bfa_fcs_lport_get_pwwn(port);
1512 aen_entry->aen_data.port.fwwn = bfa_fcs_lport_get_fabric_name(port);
1513
1514 /* Send the AEN notification */
1515 bfad_im_post_vendor_event(aen_entry, bfad, ++port->fcs->fcs_aen_seq,
1516 BFA_AEN_CAT_PORT, event);
1517}
1518
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001519/*
1520 *
1521 * @param[in] fabric - fabric
1522 * @param[in] wwn_t - new fabric name
1523 *
1524 * @return - none
1525 */
1526void
1527bfa_fcs_fabric_set_fabric_name(struct bfa_fcs_fabric_s *fabric,
1528 wwn_t fabric_name)
1529{
1530 struct bfad_s *bfad = (struct bfad_s *)fabric->fcs->bfad;
1531 char pwwn_ptr[BFA_STRING_32];
1532 char fwwn_ptr[BFA_STRING_32];
1533
1534 bfa_trc(fabric->fcs, fabric_name);
1535
1536 if (fabric->fabric_name == 0) {
1537 /*
1538 * With BRCD switches, we don't get Fabric Name in FLOGI.
1539 * Don't generate a fabric name change event in this case.
1540 */
1541 fabric->fabric_name = fabric_name;
1542 } else {
1543 fabric->fabric_name = fabric_name;
1544 wwn2str(pwwn_ptr, bfa_fcs_lport_get_pwwn(&fabric->bport));
1545 wwn2str(fwwn_ptr,
1546 bfa_fcs_lport_get_fabric_name(&fabric->bport));
Jing Huang88166242010-12-09 17:11:53 -08001547 BFA_LOG(KERN_WARNING, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001548 "Base port WWN = %s Fabric WWN = %s\n",
1549 pwwn_ptr, fwwn_ptr);
Krishna Gudipati7826f302011-07-20 16:59:13 -07001550 bfa_fcs_fabric_aen_post(&fabric->bport,
1551 BFA_PORT_AEN_FABRIC_NAME_CHANGE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001552 }
1553}
1554
Krishna Gudipati881c1b32012-08-22 19:52:02 -07001555void
1556bfa_cb_lps_flogo_comp(void *bfad, void *uarg)
1557{
1558 struct bfa_fcs_fabric_s *fabric = uarg;
1559 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_LOGOCOMP);
1560}
1561
Jing Huang5fbe25c2010-10-18 17:17:23 -07001562/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001563 * Returns FCS vf structure for a given vf_id.
1564 *
1565 * param[in] vf_id - VF_ID
1566 *
1567 * return
1568 * If lookup succeeds, retuns fcs vf object, otherwise returns NULL
1569 */
1570bfa_fcs_vf_t *
1571bfa_fcs_vf_lookup(struct bfa_fcs_s *fcs, u16 vf_id)
1572{
1573 bfa_trc(fcs, vf_id);
1574 if (vf_id == FC_VF_ID_NULL)
1575 return &fcs->fabric;
1576
1577 return NULL;
1578}
1579
Jing Huang5fbe25c2010-10-18 17:17:23 -07001580/*
Krishna Gudipatib85daaf2011-06-13 15:55:11 -07001581 * Return the list of local logical ports present in the given VF.
1582 *
1583 * @param[in] vf vf for which logical ports are returned
1584 * @param[out] lpwwn returned logical port wwn list
1585 * @param[in,out] nlports in:size of lpwwn list;
1586 * out:total elements present,
1587 * actual elements returned is limited by the size
1588 */
1589void
1590bfa_fcs_vf_get_ports(bfa_fcs_vf_t *vf, wwn_t lpwwn[], int *nlports)
1591{
1592 struct list_head *qe;
1593 struct bfa_fcs_vport_s *vport;
1594 int i = 0;
1595 struct bfa_fcs_s *fcs;
1596
1597 if (vf == NULL || lpwwn == NULL || *nlports == 0)
1598 return;
1599
1600 fcs = vf->fcs;
1601
1602 bfa_trc(fcs, vf->vf_id);
1603 bfa_trc(fcs, (uint32_t) *nlports);
1604
1605 lpwwn[i++] = vf->bport.port_cfg.pwwn;
1606
1607 list_for_each(qe, &vf->vport_q) {
1608 if (i >= *nlports)
1609 break;
1610
1611 vport = (struct bfa_fcs_vport_s *) qe;
1612 lpwwn[i++] = vport->lport.port_cfg.pwwn;
1613 }
1614
1615 bfa_trc(fcs, i);
1616 *nlports = i;
1617}
1618
1619/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001620 * BFA FCS PPORT ( physical port)
1621 */
1622static void
1623bfa_fcs_port_event_handler(void *cbarg, enum bfa_port_linkstate event)
1624{
1625 struct bfa_fcs_s *fcs = cbarg;
1626
1627 bfa_trc(fcs, event);
1628
1629 switch (event) {
1630 case BFA_PORT_LINKUP:
1631 bfa_fcs_fabric_link_up(&fcs->fabric);
1632 break;
1633
1634 case BFA_PORT_LINKDOWN:
1635 bfa_fcs_fabric_link_down(&fcs->fabric);
1636 break;
1637
1638 default:
Jing Huangd4b671c2010-12-26 21:46:35 -08001639 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001640 }
1641}
1642
1643void
1644bfa_fcs_port_attach(struct bfa_fcs_s *fcs)
1645{
1646 bfa_fcport_event_register(fcs->bfa, bfa_fcs_port_event_handler, fcs);
1647}
1648
Jing Huang5fbe25c2010-10-18 17:17:23 -07001649/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001650 * BFA FCS UF ( Unsolicited Frames)
1651 */
1652
Jing Huang5fbe25c2010-10-18 17:17:23 -07001653/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001654 * BFA callback for unsolicited frame receive handler.
1655 *
1656 * @param[in] cbarg callback arg for receive handler
1657 * @param[in] uf unsolicited frame descriptor
1658 *
1659 * @return None
1660 */
1661static void
1662bfa_fcs_uf_recv(void *cbarg, struct bfa_uf_s *uf)
1663{
1664 struct bfa_fcs_s *fcs = (struct bfa_fcs_s *) cbarg;
1665 struct fchs_s *fchs = bfa_uf_get_frmbuf(uf);
1666 u16 len = bfa_uf_get_frmlen(uf);
1667 struct fc_vft_s *vft;
1668 struct bfa_fcs_fabric_s *fabric;
1669
Jing Huang5fbe25c2010-10-18 17:17:23 -07001670 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001671 * check for VFT header
1672 */
1673 if (fchs->routing == FC_RTG_EXT_HDR &&
1674 fchs->cat_info == FC_CAT_VFT_HDR) {
1675 bfa_stats(fcs, uf.tagged);
1676 vft = bfa_uf_get_frmbuf(uf);
1677 if (fcs->port_vfid == vft->vf_id)
1678 fabric = &fcs->fabric;
1679 else
1680 fabric = bfa_fcs_vf_lookup(fcs, (u16) vft->vf_id);
1681
Jing Huang5fbe25c2010-10-18 17:17:23 -07001682 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001683 * drop frame if vfid is unknown
1684 */
1685 if (!fabric) {
Jing Huangd4b671c2010-12-26 21:46:35 -08001686 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001687 bfa_stats(fcs, uf.vfid_unknown);
1688 bfa_uf_free(uf);
1689 return;
1690 }
1691
Jing Huang5fbe25c2010-10-18 17:17:23 -07001692 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001693 * skip vft header
1694 */
1695 fchs = (struct fchs_s *) (vft + 1);
1696 len -= sizeof(struct fc_vft_s);
1697
1698 bfa_trc(fcs, vft->vf_id);
1699 } else {
1700 bfa_stats(fcs, uf.untagged);
1701 fabric = &fcs->fabric;
1702 }
1703
1704 bfa_trc(fcs, ((u32 *) fchs)[0]);
1705 bfa_trc(fcs, ((u32 *) fchs)[1]);
1706 bfa_trc(fcs, ((u32 *) fchs)[2]);
1707 bfa_trc(fcs, ((u32 *) fchs)[3]);
1708 bfa_trc(fcs, ((u32 *) fchs)[4]);
1709 bfa_trc(fcs, ((u32 *) fchs)[5]);
1710 bfa_trc(fcs, len);
1711
1712 bfa_fcs_fabric_uf_recv(fabric, fchs, len);
1713 bfa_uf_free(uf);
1714}
1715
1716void
1717bfa_fcs_uf_attach(struct bfa_fcs_s *fcs)
1718{
1719 bfa_uf_recv_register(fcs->bfa, bfa_fcs_uf_recv, fcs);
1720}