blob: fd3e84d32bd2fed636b61a443f32ebe71f3c54a1 [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;
Krishna Gudipati61ba4392012-08-22 19:52:58 -070079 fcs->num_rport_logins = 0;
Jing Huang7725ccf2009-09-23 17:46:15 -070080
Maggie Zhangf7f738122010-12-09 19:08:43 -080081 bfa->fcs = BFA_TRUE;
Jing Huang7725ccf2009-09-23 17:46:15 -070082 fcbuild_init();
83
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070084 for (i = 0; i < sizeof(fcs_modules) / sizeof(fcs_modules[0]); i++) {
Jing Huang7725ccf2009-09-23 17:46:15 -070085 mod = &fcs_modules[i];
Krishna Gudipati82794a22010-03-03 17:43:30 -080086 if (mod->attach)
87 mod->attach(fcs);
88 }
89}
90
Jing Huang5fbe25c2010-10-18 17:17:23 -070091/*
Krishna Gudipati82794a22010-03-03 17:43:30 -080092 * fcs initialization, called once after bfa initialization is complete
93 */
94void
95bfa_fcs_init(struct bfa_fcs_s *fcs)
96{
Krishna Gudipati75332a72011-06-13 15:54:31 -070097 int i;
Krishna Gudipati82794a22010-03-03 17:43:30 -080098 struct bfa_fcs_mod_s *mod;
99
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700100 for (i = 0; i < sizeof(fcs_modules) / sizeof(fcs_modules[0]); i++) {
Krishna Gudipati82794a22010-03-03 17:43:30 -0800101 mod = &fcs_modules[i];
102 if (mod->modinit)
103 mod->modinit(fcs);
Jing Huang7725ccf2009-09-23 17:46:15 -0700104 }
Krishna Gudipati75332a72011-06-13 15:54:31 -0700105}
106
107/*
108 * FCS update cfg - reset the pwwn/nwwn of fabric base logical port
109 * with values learned during bfa_init firmware GETATTR REQ.
110 */
111void
112bfa_fcs_update_cfg(struct bfa_fcs_s *fcs)
113{
114 struct bfa_fcs_fabric_s *fabric = &fcs->fabric;
115 struct bfa_lport_cfg_s *port_cfg = &fabric->bport.port_cfg;
116 struct bfa_ioc_s *ioc = &fabric->fcs->bfa->ioc;
117
118 port_cfg->nwwn = ioc->attr->nwwn;
119 port_cfg->pwwn = ioc->attr->pwwn;
120}
121
122/*
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700123 * Stop FCS operations.
124 */
125void
126bfa_fcs_stop(struct bfa_fcs_s *fcs)
127{
128 bfa_wc_init(&fcs->wc, bfa_fcs_exit_comp, fcs);
129 bfa_wc_up(&fcs->wc);
130 bfa_fcs_fabric_modstop(fcs);
131 bfa_wc_wait(&fcs->wc);
132}
133
134/*
Krishna Gudipati75332a72011-06-13 15:54:31 -0700135 * fcs pbc vport initialization
136 */
137void
138bfa_fcs_pbc_vport_init(struct bfa_fcs_s *fcs)
139{
140 int i, npbc_vports;
141 struct bfi_pbc_vport_s pbc_vports[BFI_PBC_MAX_VPORTS];
142
Jing Huangd9883542010-07-08 19:46:26 -0700143 /* Initialize pbc vports */
144 if (!fcs->min_cfg) {
145 npbc_vports =
Krishna Gudipati75332a72011-06-13 15:54:31 -0700146 bfa_iocfc_get_pbc_vports(fcs->bfa, pbc_vports);
Jing Huangd9883542010-07-08 19:46:26 -0700147 for (i = 0; i < npbc_vports; i++)
148 bfa_fcb_pbc_vport_create(fcs->bfa->bfad, pbc_vports[i]);
149 }
Jing Huang7725ccf2009-09-23 17:46:15 -0700150}
151
Jing Huang5fbe25c2010-10-18 17:17:23 -0700152/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700153 * brief
154 * FCS driver details initialization.
Jing Huang7725ccf2009-09-23 17:46:15 -0700155 *
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700156 * param[in] fcs FCS instance
157 * param[in] driver_info Driver Details
Jing Huang7725ccf2009-09-23 17:46:15 -0700158 *
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700159 * return None
Jing Huang7725ccf2009-09-23 17:46:15 -0700160 */
161void
162bfa_fcs_driver_info_init(struct bfa_fcs_s *fcs,
163 struct bfa_fcs_driver_info_s *driver_info)
164{
165
166 fcs->driver_info = *driver_info;
167
168 bfa_fcs_fabric_psymb_init(&fcs->fabric);
Krishna Gudipatice7242b2012-08-22 19:52:43 -0700169 bfa_fcs_fabric_nsymb_init(&fcs->fabric);
Jing Huang7725ccf2009-09-23 17:46:15 -0700170}
171
Jing Huang5fbe25c2010-10-18 17:17:23 -0700172/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700173 * brief
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700174 * FCS instance cleanup and exit.
Jing Huang7725ccf2009-09-23 17:46:15 -0700175 *
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700176 * param[in] fcs FCS instance
177 * return None
Jing Huang7725ccf2009-09-23 17:46:15 -0700178 */
179void
180bfa_fcs_exit(struct bfa_fcs_s *fcs)
181{
182 struct bfa_fcs_mod_s *mod;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700183 int nmods, i;
Jing Huang7725ccf2009-09-23 17:46:15 -0700184
185 bfa_wc_init(&fcs->wc, bfa_fcs_exit_comp, fcs);
186
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700187 nmods = sizeof(fcs_modules) / sizeof(fcs_modules[0]);
188
189 for (i = 0; i < nmods; i++) {
Jing Huang7725ccf2009-09-23 17:46:15 -0700190
191 mod = &fcs_modules[i];
Krishna Gudipati82794a22010-03-03 17:43:30 -0800192 if (mod->modexit) {
193 bfa_wc_up(&fcs->wc);
194 mod->modexit(fcs);
195 }
Jing Huang7725ccf2009-09-23 17:46:15 -0700196 }
197
198 bfa_wc_wait(&fcs->wc);
199}
200
201
Jing Huang5fbe25c2010-10-18 17:17:23 -0700202/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700203 * Fabric module implementation.
204 */
Jing Huang7725ccf2009-09-23 17:46:15 -0700205
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700206#define BFA_FCS_FABRIC_RETRY_DELAY (2000) /* Milliseconds */
207#define BFA_FCS_FABRIC_CLEANUP_DELAY (10000) /* Milliseconds */
208
209#define bfa_fcs_fabric_set_opertype(__fabric) do { \
Krishna Gudipatid7be54c2011-06-24 20:24:52 -0700210 if (bfa_fcport_get_topology((__fabric)->fcs->bfa) \
211 == BFA_PORT_TOPOLOGY_P2P) { \
212 if (fabric->fab_type == BFA_FCS_FABRIC_SWITCHED) \
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700213 (__fabric)->oper_type = BFA_PORT_TYPE_NPORT; \
214 else \
Krishna Gudipatid7be54c2011-06-24 20:24:52 -0700215 (__fabric)->oper_type = BFA_PORT_TYPE_P2P; \
216 } else \
217 (__fabric)->oper_type = BFA_PORT_TYPE_NLPORT; \
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700218} while (0)
219
220/*
221 * forward declarations
222 */
223static void bfa_fcs_fabric_init(struct bfa_fcs_fabric_s *fabric);
224static void bfa_fcs_fabric_login(struct bfa_fcs_fabric_s *fabric);
225static void bfa_fcs_fabric_notify_online(struct bfa_fcs_fabric_s *fabric);
226static void bfa_fcs_fabric_notify_offline(struct bfa_fcs_fabric_s *fabric);
227static void bfa_fcs_fabric_delay(void *cbarg);
228static void bfa_fcs_fabric_delete(struct bfa_fcs_fabric_s *fabric);
229static void bfa_fcs_fabric_delete_comp(void *cbarg);
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700230static void bfa_fcs_fabric_stop(struct bfa_fcs_fabric_s *fabric);
231static void bfa_fcs_fabric_stop_comp(void *cbarg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700232static void bfa_fcs_fabric_process_uf(struct bfa_fcs_fabric_s *fabric,
233 struct fchs_s *fchs, u16 len);
234static void bfa_fcs_fabric_process_flogi(struct bfa_fcs_fabric_s *fabric,
235 struct fchs_s *fchs, u16 len);
236static void bfa_fcs_fabric_send_flogi_acc(struct bfa_fcs_fabric_s *fabric);
237static void bfa_fcs_fabric_flogiacc_comp(void *fcsarg,
238 struct bfa_fcxp_s *fcxp, void *cbarg,
239 bfa_status_t status,
240 u32 rsp_len,
241 u32 resid_len,
242 struct fchs_s *rspfchs);
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700243static u8 bfa_fcs_fabric_oper_bbscn(struct bfa_fcs_fabric_s *fabric);
244static bfa_boolean_t bfa_fcs_fabric_is_bbscn_enabled(
245 struct bfa_fcs_fabric_s *fabric);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700246
247static void bfa_fcs_fabric_sm_uninit(struct bfa_fcs_fabric_s *fabric,
248 enum bfa_fcs_fabric_event event);
249static void bfa_fcs_fabric_sm_created(struct bfa_fcs_fabric_s *fabric,
250 enum bfa_fcs_fabric_event event);
251static void bfa_fcs_fabric_sm_linkdown(struct bfa_fcs_fabric_s *fabric,
252 enum bfa_fcs_fabric_event event);
253static void bfa_fcs_fabric_sm_flogi(struct bfa_fcs_fabric_s *fabric,
254 enum bfa_fcs_fabric_event event);
255static void bfa_fcs_fabric_sm_flogi_retry(struct bfa_fcs_fabric_s *fabric,
256 enum bfa_fcs_fabric_event event);
257static void bfa_fcs_fabric_sm_auth(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_nofabric(struct bfa_fcs_fabric_s *fabric,
260 enum bfa_fcs_fabric_event event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700261static void bfa_fcs_fabric_sm_evfp(struct bfa_fcs_fabric_s *fabric,
262 enum bfa_fcs_fabric_event event);
263static void bfa_fcs_fabric_sm_evfp_done(struct bfa_fcs_fabric_s *fabric,
264 enum bfa_fcs_fabric_event event);
265static void bfa_fcs_fabric_sm_isolated(struct bfa_fcs_fabric_s *fabric,
266 enum bfa_fcs_fabric_event event);
267static void bfa_fcs_fabric_sm_deleting(struct bfa_fcs_fabric_s *fabric,
268 enum bfa_fcs_fabric_event event);
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700269static void bfa_fcs_fabric_sm_stopping(struct bfa_fcs_fabric_s *fabric,
270 enum bfa_fcs_fabric_event event);
271static void bfa_fcs_fabric_sm_cleanup(struct bfa_fcs_fabric_s *fabric,
272 enum bfa_fcs_fabric_event event);
Jing Huang5fbe25c2010-10-18 17:17:23 -0700273/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700274 * Beginning state before fabric creation.
275 */
276static void
277bfa_fcs_fabric_sm_uninit(struct bfa_fcs_fabric_s *fabric,
278 enum bfa_fcs_fabric_event event)
279{
280 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
281 bfa_trc(fabric->fcs, event);
282
283 switch (event) {
284 case BFA_FCS_FABRIC_SM_CREATE:
285 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_created);
286 bfa_fcs_fabric_init(fabric);
287 bfa_fcs_lport_init(&fabric->bport, &fabric->bport.port_cfg);
288 break;
289
290 case BFA_FCS_FABRIC_SM_LINK_UP:
291 case BFA_FCS_FABRIC_SM_LINK_DOWN:
292 break;
293
294 default:
295 bfa_sm_fault(fabric->fcs, event);
296 }
297}
298
Jing Huang5fbe25c2010-10-18 17:17:23 -0700299/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700300 * Beginning state before fabric creation.
301 */
302static void
303bfa_fcs_fabric_sm_created(struct bfa_fcs_fabric_s *fabric,
304 enum bfa_fcs_fabric_event event)
305{
306 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
307 bfa_trc(fabric->fcs, event);
308
309 switch (event) {
310 case BFA_FCS_FABRIC_SM_START:
311 if (bfa_fcport_is_linkup(fabric->fcs->bfa)) {
312 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_flogi);
313 bfa_fcs_fabric_login(fabric);
314 } else
315 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
316 break;
317
318 case BFA_FCS_FABRIC_SM_LINK_UP:
319 case BFA_FCS_FABRIC_SM_LINK_DOWN:
320 break;
321
322 case BFA_FCS_FABRIC_SM_DELETE:
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -0700323 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
324 bfa_fcs_fabric_delete(fabric);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700325 break;
326
327 default:
328 bfa_sm_fault(fabric->fcs, event);
329 }
330}
331
Jing Huang5fbe25c2010-10-18 17:17:23 -0700332/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700333 * Link is down, awaiting LINK UP event from port. This is also the
334 * first state at fabric creation.
335 */
336static void
337bfa_fcs_fabric_sm_linkdown(struct bfa_fcs_fabric_s *fabric,
338 enum bfa_fcs_fabric_event event)
339{
340 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
341 bfa_trc(fabric->fcs, event);
342
343 switch (event) {
344 case BFA_FCS_FABRIC_SM_LINK_UP:
345 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_flogi);
346 bfa_fcs_fabric_login(fabric);
347 break;
348
349 case BFA_FCS_FABRIC_SM_RETRY_OP:
350 break;
351
352 case BFA_FCS_FABRIC_SM_DELETE:
353 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
354 bfa_fcs_fabric_delete(fabric);
355 break;
356
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700357 case BFA_FCS_FABRIC_SM_STOP:
358 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_cleanup);
359 bfa_fcs_fabric_stop(fabric);
360 break;
361
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700362 default:
363 bfa_sm_fault(fabric->fcs, event);
364 }
365}
366
Jing Huang5fbe25c2010-10-18 17:17:23 -0700367/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700368 * FLOGI is in progress, awaiting FLOGI reply.
369 */
370static void
371bfa_fcs_fabric_sm_flogi(struct bfa_fcs_fabric_s *fabric,
372 enum bfa_fcs_fabric_event event)
373{
374 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
375 bfa_trc(fabric->fcs, event);
376
377 switch (event) {
378 case BFA_FCS_FABRIC_SM_CONT_OP:
379
380 bfa_fcport_set_tx_bbcredit(fabric->fcs->bfa,
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700381 fabric->bb_credit,
382 bfa_fcs_fabric_oper_bbscn(fabric));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700383 fabric->fab_type = BFA_FCS_FABRIC_SWITCHED;
384
385 if (fabric->auth_reqd && fabric->is_auth) {
386 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_auth);
387 bfa_trc(fabric->fcs, event);
388 } else {
389 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_online);
390 bfa_fcs_fabric_notify_online(fabric);
391 }
392 break;
393
394 case BFA_FCS_FABRIC_SM_RETRY_OP:
395 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_flogi_retry);
396 bfa_timer_start(fabric->fcs->bfa, &fabric->delay_timer,
397 bfa_fcs_fabric_delay, fabric,
398 BFA_FCS_FABRIC_RETRY_DELAY);
399 break;
400
401 case BFA_FCS_FABRIC_SM_LOOPBACK:
402 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_loopback);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800403 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700404 bfa_fcs_fabric_set_opertype(fabric);
405 break;
406
407 case BFA_FCS_FABRIC_SM_NO_FABRIC:
408 fabric->fab_type = BFA_FCS_FABRIC_N2N;
409 bfa_fcport_set_tx_bbcredit(fabric->fcs->bfa,
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700410 fabric->bb_credit,
411 bfa_fcs_fabric_oper_bbscn(fabric));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700412 bfa_fcs_fabric_notify_online(fabric);
413 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_nofabric);
414 break;
415
416 case BFA_FCS_FABRIC_SM_LINK_DOWN:
417 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800418 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700419 break;
420
421 case BFA_FCS_FABRIC_SM_DELETE:
422 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800423 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700424 bfa_fcs_fabric_delete(fabric);
425 break;
426
427 default:
428 bfa_sm_fault(fabric->fcs, event);
429 }
430}
431
432
433static void
434bfa_fcs_fabric_sm_flogi_retry(struct bfa_fcs_fabric_s *fabric,
435 enum bfa_fcs_fabric_event event)
436{
437 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
438 bfa_trc(fabric->fcs, event);
439
440 switch (event) {
441 case BFA_FCS_FABRIC_SM_DELAYED:
442 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_flogi);
443 bfa_fcs_fabric_login(fabric);
444 break;
445
446 case BFA_FCS_FABRIC_SM_LINK_DOWN:
447 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
448 bfa_timer_stop(&fabric->delay_timer);
449 break;
450
451 case BFA_FCS_FABRIC_SM_DELETE:
452 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
453 bfa_timer_stop(&fabric->delay_timer);
454 bfa_fcs_fabric_delete(fabric);
455 break;
456
457 default:
458 bfa_sm_fault(fabric->fcs, event);
459 }
460}
461
Jing Huang5fbe25c2010-10-18 17:17:23 -0700462/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700463 * Authentication is in progress, awaiting authentication results.
464 */
465static void
466bfa_fcs_fabric_sm_auth(struct bfa_fcs_fabric_s *fabric,
467 enum bfa_fcs_fabric_event event)
468{
469 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
470 bfa_trc(fabric->fcs, event);
471
472 switch (event) {
473 case BFA_FCS_FABRIC_SM_AUTH_FAILED:
474 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_auth_failed);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800475 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700476 break;
477
478 case BFA_FCS_FABRIC_SM_AUTH_SUCCESS:
479 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_online);
480 bfa_fcs_fabric_notify_online(fabric);
481 break;
482
483 case BFA_FCS_FABRIC_SM_PERF_EVFP:
484 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_evfp);
485 break;
486
487 case BFA_FCS_FABRIC_SM_LINK_DOWN:
488 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800489 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700490 break;
491
492 case BFA_FCS_FABRIC_SM_DELETE:
493 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
494 bfa_fcs_fabric_delete(fabric);
495 break;
496
497 default:
498 bfa_sm_fault(fabric->fcs, event);
499 }
500}
501
Jing Huang5fbe25c2010-10-18 17:17:23 -0700502/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700503 * Authentication failed
504 */
Maggie Zhangf7f738122010-12-09 19:08:43 -0800505void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700506bfa_fcs_fabric_sm_auth_failed(struct bfa_fcs_fabric_s *fabric,
507 enum bfa_fcs_fabric_event event)
508{
509 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
510 bfa_trc(fabric->fcs, event);
511
512 switch (event) {
513 case BFA_FCS_FABRIC_SM_LINK_DOWN:
514 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
515 bfa_fcs_fabric_notify_offline(fabric);
516 break;
517
518 case BFA_FCS_FABRIC_SM_DELETE:
519 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
520 bfa_fcs_fabric_delete(fabric);
521 break;
522
523 default:
524 bfa_sm_fault(fabric->fcs, event);
525 }
526}
527
Jing Huang5fbe25c2010-10-18 17:17:23 -0700528/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700529 * Port is in loopback mode.
530 */
Maggie Zhangf7f738122010-12-09 19:08:43 -0800531void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700532bfa_fcs_fabric_sm_loopback(struct bfa_fcs_fabric_s *fabric,
533 enum bfa_fcs_fabric_event event)
534{
535 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
536 bfa_trc(fabric->fcs, event);
537
538 switch (event) {
539 case BFA_FCS_FABRIC_SM_LINK_DOWN:
540 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
541 bfa_fcs_fabric_notify_offline(fabric);
542 break;
543
544 case BFA_FCS_FABRIC_SM_DELETE:
545 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
546 bfa_fcs_fabric_delete(fabric);
547 break;
548
549 default:
550 bfa_sm_fault(fabric->fcs, event);
551 }
552}
553
Jing Huang5fbe25c2010-10-18 17:17:23 -0700554/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700555 * There is no attached fabric - private loop or NPort-to-NPort topology.
556 */
557static void
558bfa_fcs_fabric_sm_nofabric(struct bfa_fcs_fabric_s *fabric,
559 enum bfa_fcs_fabric_event event)
560{
561 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
562 bfa_trc(fabric->fcs, event);
563
564 switch (event) {
565 case BFA_FCS_FABRIC_SM_LINK_DOWN:
566 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800567 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700568 bfa_fcs_fabric_notify_offline(fabric);
569 break;
570
571 case BFA_FCS_FABRIC_SM_DELETE:
572 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
573 bfa_fcs_fabric_delete(fabric);
574 break;
575
576 case BFA_FCS_FABRIC_SM_NO_FABRIC:
577 bfa_trc(fabric->fcs, fabric->bb_credit);
578 bfa_fcport_set_tx_bbcredit(fabric->fcs->bfa,
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700579 fabric->bb_credit,
580 bfa_fcs_fabric_oper_bbscn(fabric));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700581 break;
582
Krishna Gudipatid7be54c2011-06-24 20:24:52 -0700583 case BFA_FCS_FABRIC_SM_RETRY_OP:
584 break;
585
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700586 default:
587 bfa_sm_fault(fabric->fcs, event);
588 }
589}
590
Jing Huang5fbe25c2010-10-18 17:17:23 -0700591/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700592 * Fabric is online - normal operating state.
593 */
Maggie Zhangf7f738122010-12-09 19:08:43 -0800594void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700595bfa_fcs_fabric_sm_online(struct bfa_fcs_fabric_s *fabric,
596 enum bfa_fcs_fabric_event event)
597{
598 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
599 bfa_trc(fabric->fcs, event);
600
601 switch (event) {
602 case BFA_FCS_FABRIC_SM_LINK_DOWN:
603 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800604 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700605 bfa_fcs_fabric_notify_offline(fabric);
606 break;
607
608 case BFA_FCS_FABRIC_SM_DELETE:
609 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
610 bfa_fcs_fabric_delete(fabric);
611 break;
612
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700613 case BFA_FCS_FABRIC_SM_STOP:
614 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_stopping);
615 bfa_fcs_fabric_stop(fabric);
616 break;
617
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700618 case BFA_FCS_FABRIC_SM_AUTH_FAILED:
619 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_auth_failed);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800620 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700621 break;
622
623 case BFA_FCS_FABRIC_SM_AUTH_SUCCESS:
624 break;
625
626 default:
627 bfa_sm_fault(fabric->fcs, event);
628 }
629}
630
Jing Huang5fbe25c2010-10-18 17:17:23 -0700631/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700632 * Exchanging virtual fabric parameters.
633 */
634static void
635bfa_fcs_fabric_sm_evfp(struct bfa_fcs_fabric_s *fabric,
636 enum bfa_fcs_fabric_event event)
637{
638 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
639 bfa_trc(fabric->fcs, event);
640
641 switch (event) {
642 case BFA_FCS_FABRIC_SM_CONT_OP:
643 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_evfp_done);
644 break;
645
646 case BFA_FCS_FABRIC_SM_ISOLATE:
647 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_isolated);
648 break;
649
650 default:
651 bfa_sm_fault(fabric->fcs, event);
652 }
653}
654
Jing Huang5fbe25c2010-10-18 17:17:23 -0700655/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700656 * EVFP exchange complete and VFT tagging is enabled.
657 */
658static void
659bfa_fcs_fabric_sm_evfp_done(struct bfa_fcs_fabric_s *fabric,
660 enum bfa_fcs_fabric_event event)
661{
662 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
663 bfa_trc(fabric->fcs, event);
664}
665
Jing Huang5fbe25c2010-10-18 17:17:23 -0700666/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700667 * Port is isolated after EVFP exchange due to VF_ID mismatch (N and F).
668 */
669static void
670bfa_fcs_fabric_sm_isolated(struct bfa_fcs_fabric_s *fabric,
671 enum bfa_fcs_fabric_event event)
672{
673 struct bfad_s *bfad = (struct bfad_s *)fabric->fcs->bfad;
674 char pwwn_ptr[BFA_STRING_32];
675
676 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
677 bfa_trc(fabric->fcs, event);
678 wwn2str(pwwn_ptr, fabric->bport.port_cfg.pwwn);
679
Jing Huang88166242010-12-09 17:11:53 -0800680 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700681 "Port is isolated due to VF_ID mismatch. "
682 "PWWN: %s Port VF_ID: %04x switch port VF_ID: %04x.",
683 pwwn_ptr, fabric->fcs->port_vfid,
684 fabric->event_arg.swp_vfid);
685}
686
Jing Huang5fbe25c2010-10-18 17:17:23 -0700687/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700688 * Fabric is being deleted, awaiting vport delete completions.
689 */
690static void
691bfa_fcs_fabric_sm_deleting(struct bfa_fcs_fabric_s *fabric,
692 enum bfa_fcs_fabric_event event)
693{
694 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
695 bfa_trc(fabric->fcs, event);
696
697 switch (event) {
698 case BFA_FCS_FABRIC_SM_DELCOMP:
699 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_uninit);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800700 bfa_wc_down(&fabric->fcs->wc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700701 break;
702
703 case BFA_FCS_FABRIC_SM_LINK_UP:
704 break;
705
706 case BFA_FCS_FABRIC_SM_LINK_DOWN:
707 bfa_fcs_fabric_notify_offline(fabric);
708 break;
709
710 default:
711 bfa_sm_fault(fabric->fcs, event);
712 }
713}
714
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700715/*
716 * Fabric is being stopped, awaiting vport stop completions.
717 */
718static void
719bfa_fcs_fabric_sm_stopping(struct bfa_fcs_fabric_s *fabric,
720 enum bfa_fcs_fabric_event event)
721{
722 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
723 bfa_trc(fabric->fcs, event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700724
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700725 switch (event) {
726 case BFA_FCS_FABRIC_SM_STOPCOMP:
727 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_cleanup);
728 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_LOGOUT);
729 break;
730
731 case BFA_FCS_FABRIC_SM_LINK_UP:
732 break;
733
734 case BFA_FCS_FABRIC_SM_LINK_DOWN:
735 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_cleanup);
736 break;
737
738 default:
739 bfa_sm_fault(fabric->fcs, event);
740 }
741}
742
743/*
744 * Fabric is being stopped, cleanup without FLOGO
745 */
746static void
747bfa_fcs_fabric_sm_cleanup(struct bfa_fcs_fabric_s *fabric,
748 enum bfa_fcs_fabric_event event)
749{
750 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
751 bfa_trc(fabric->fcs, event);
752
753 switch (event) {
754 case BFA_FCS_FABRIC_SM_STOPCOMP:
755 case BFA_FCS_FABRIC_SM_LOGOCOMP:
756 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_created);
757 bfa_wc_down(&(fabric->fcs)->wc);
758 break;
759
760 case BFA_FCS_FABRIC_SM_LINK_DOWN:
761 /*
762 * Ignore - can get this event if we get notified about IOC down
763 * before the fabric completion callbk is done.
764 */
765 break;
766
767 default:
768 bfa_sm_fault(fabric->fcs, event);
769 }
770}
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700771
Jing Huang5fbe25c2010-10-18 17:17:23 -0700772/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700773 * fcs_fabric_private fabric private functions
774 */
775
776static void
777bfa_fcs_fabric_init(struct bfa_fcs_fabric_s *fabric)
778{
779 struct bfa_lport_cfg_s *port_cfg = &fabric->bport.port_cfg;
780
781 port_cfg->roles = BFA_LPORT_ROLE_FCP_IM;
Maggie Zhangf7f738122010-12-09 19:08:43 -0800782 port_cfg->nwwn = fabric->fcs->bfa->ioc.attr->nwwn;
783 port_cfg->pwwn = fabric->fcs->bfa->ioc.attr->pwwn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700784}
785
Jing Huang5fbe25c2010-10-18 17:17:23 -0700786/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700787 * Port Symbolic Name Creation for base port.
788 */
789void
790bfa_fcs_fabric_psymb_init(struct bfa_fcs_fabric_s *fabric)
791{
792 struct bfa_lport_cfg_s *port_cfg = &fabric->bport.port_cfg;
793 char model[BFA_ADAPTER_MODEL_NAME_LEN] = {0};
794 struct bfa_fcs_driver_info_s *driver_info = &fabric->fcs->driver_info;
795
796 bfa_ioc_get_adapter_model(&fabric->fcs->bfa->ioc, model);
797
798 /* Model name/number */
799 strncpy((char *)&port_cfg->sym_name, model,
800 BFA_FCS_PORT_SYMBNAME_MODEL_SZ);
801 strncat((char *)&port_cfg->sym_name, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
802 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
803
804 /* Driver Version */
805 strncat((char *)&port_cfg->sym_name, (char *)driver_info->version,
806 BFA_FCS_PORT_SYMBNAME_VERSION_SZ);
807 strncat((char *)&port_cfg->sym_name, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
808 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
809
810 /* Host machine name */
811 strncat((char *)&port_cfg->sym_name,
812 (char *)driver_info->host_machine_name,
813 BFA_FCS_PORT_SYMBNAME_MACHINENAME_SZ);
814 strncat((char *)&port_cfg->sym_name, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
815 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
816
817 /*
818 * Host OS Info :
819 * If OS Patch Info is not there, do not truncate any bytes from the
820 * OS name string and instead copy the entire OS info string (64 bytes).
821 */
822 if (driver_info->host_os_patch[0] == '\0') {
823 strncat((char *)&port_cfg->sym_name,
824 (char *)driver_info->host_os_name,
825 BFA_FCS_OS_STR_LEN);
826 strncat((char *)&port_cfg->sym_name,
827 BFA_FCS_PORT_SYMBNAME_SEPARATOR,
828 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
829 } else {
830 strncat((char *)&port_cfg->sym_name,
831 (char *)driver_info->host_os_name,
832 BFA_FCS_PORT_SYMBNAME_OSINFO_SZ);
833 strncat((char *)&port_cfg->sym_name,
834 BFA_FCS_PORT_SYMBNAME_SEPARATOR,
835 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
836
837 /* Append host OS Patch Info */
838 strncat((char *)&port_cfg->sym_name,
839 (char *)driver_info->host_os_patch,
840 BFA_FCS_PORT_SYMBNAME_OSPATCH_SZ);
841 }
842
843 /* null terminate */
844 port_cfg->sym_name.symname[BFA_SYMNAME_MAXLEN - 1] = 0;
845}
846
Jing Huang5fbe25c2010-10-18 17:17:23 -0700847/*
Krishna Gudipatice7242b2012-08-22 19:52:43 -0700848 * Node Symbolic Name Creation for base port and all vports
849 */
850void
851bfa_fcs_fabric_nsymb_init(struct bfa_fcs_fabric_s *fabric)
852{
853 struct bfa_lport_cfg_s *port_cfg = &fabric->bport.port_cfg;
854 char model[BFA_ADAPTER_MODEL_NAME_LEN] = {0};
855 struct bfa_fcs_driver_info_s *driver_info = &fabric->fcs->driver_info;
856
857 bfa_ioc_get_adapter_model(&fabric->fcs->bfa->ioc, model);
858
859 /* Model name/number */
860 strncpy((char *)&port_cfg->node_sym_name, model,
861 BFA_FCS_PORT_SYMBNAME_MODEL_SZ);
862 strncat((char *)&port_cfg->node_sym_name,
863 BFA_FCS_PORT_SYMBNAME_SEPARATOR,
864 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
865
866 /* Driver Version */
867 strncat((char *)&port_cfg->node_sym_name, (char *)driver_info->version,
868 BFA_FCS_PORT_SYMBNAME_VERSION_SZ);
869 strncat((char *)&port_cfg->node_sym_name,
870 BFA_FCS_PORT_SYMBNAME_SEPARATOR,
871 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
872
873 /* Host machine name */
874 strncat((char *)&port_cfg->node_sym_name,
875 (char *)driver_info->host_machine_name,
876 BFA_FCS_PORT_SYMBNAME_MACHINENAME_SZ);
877 strncat((char *)&port_cfg->node_sym_name,
878 BFA_FCS_PORT_SYMBNAME_SEPARATOR,
879 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
880
881 /* null terminate */
882 port_cfg->node_sym_name.symname[BFA_SYMNAME_MAXLEN - 1] = 0;
883}
884
885/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700886 * bfa lps login completion callback
887 */
888void
889bfa_cb_lps_flogi_comp(void *bfad, void *uarg, bfa_status_t status)
890{
891 struct bfa_fcs_fabric_s *fabric = uarg;
892
893 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
894 bfa_trc(fabric->fcs, status);
895
896 switch (status) {
897 case BFA_STATUS_OK:
898 fabric->stats.flogi_accepts++;
899 break;
900
901 case BFA_STATUS_INVALID_MAC:
902 /* Only for CNA */
903 fabric->stats.flogi_acc_err++;
904 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_RETRY_OP);
905
906 return;
907
908 case BFA_STATUS_EPROTOCOL:
Maggie Zhangf7f738122010-12-09 19:08:43 -0800909 switch (fabric->lps->ext_status) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700910 case BFA_EPROTO_BAD_ACCEPT:
911 fabric->stats.flogi_acc_err++;
912 break;
913
914 case BFA_EPROTO_UNKNOWN_RSP:
915 fabric->stats.flogi_unknown_rsp++;
916 break;
917
918 default:
919 break;
920 }
921 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_RETRY_OP);
922
923 return;
924
925 case BFA_STATUS_FABRIC_RJT:
926 fabric->stats.flogi_rejects++;
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700927 if (fabric->lps->lsrjt_rsn == FC_LS_RJT_RSN_LOGICAL_ERROR &&
928 fabric->lps->lsrjt_expl == FC_LS_RJT_EXP_NO_ADDL_INFO)
929 fabric->fcs->bbscn_flogi_rjt = BFA_TRUE;
930
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700931 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_RETRY_OP);
932 return;
933
934 default:
935 fabric->stats.flogi_rsp_err++;
936 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_RETRY_OP);
937 return;
938 }
939
Maggie Zhangf7f738122010-12-09 19:08:43 -0800940 fabric->bb_credit = fabric->lps->pr_bbcred;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700941 bfa_trc(fabric->fcs, fabric->bb_credit);
942
Maggie Zhangf7f738122010-12-09 19:08:43 -0800943 if (!(fabric->lps->brcd_switch))
944 fabric->fabric_name = fabric->lps->pr_nwwn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700945
946 /*
947 * Check port type. It should be 1 = F-port.
948 */
Maggie Zhangf7f738122010-12-09 19:08:43 -0800949 if (fabric->lps->fport) {
950 fabric->bport.pid = fabric->lps->lp_pid;
951 fabric->is_npiv = fabric->lps->npiv_en;
952 fabric->is_auth = fabric->lps->auth_req;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700953 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_CONT_OP);
954 } else {
955 /*
956 * Nport-2-Nport direct attached
957 */
958 fabric->bport.port_topo.pn2n.rem_port_wwn =
Maggie Zhangf7f738122010-12-09 19:08:43 -0800959 fabric->lps->pr_pwwn;
Krishna Gudipatid7be54c2011-06-24 20:24:52 -0700960 fabric->fab_type = BFA_FCS_FABRIC_N2N;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700961 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_NO_FABRIC);
962 }
963
964 bfa_trc(fabric->fcs, fabric->bport.pid);
965 bfa_trc(fabric->fcs, fabric->is_npiv);
966 bfa_trc(fabric->fcs, fabric->is_auth);
967}
Jing Huang5fbe25c2010-10-18 17:17:23 -0700968/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700969 * Allocate and send FLOGI.
970 */
971static void
972bfa_fcs_fabric_login(struct bfa_fcs_fabric_s *fabric)
973{
974 struct bfa_s *bfa = fabric->fcs->bfa;
975 struct bfa_lport_cfg_s *pcfg = &fabric->bport.port_cfg;
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700976 u8 alpa = 0, bb_scn = 0;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700977
978 if (bfa_fcport_get_topology(bfa) == BFA_PORT_TOPOLOGY_LOOP)
979 alpa = bfa_fcport_get_myalpa(bfa);
980
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700981 if (bfa_fcs_fabric_is_bbscn_enabled(fabric) &&
982 (!fabric->fcs->bbscn_flogi_rjt))
983 bb_scn = BFA_FCS_PORT_DEF_BB_SCN;
984
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700985 bfa_lps_flogi(fabric->lps, fabric, alpa, bfa_fcport_get_maxfrsize(bfa),
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700986 pcfg->pwwn, pcfg->nwwn, fabric->auth_reqd, bb_scn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700987
988 fabric->stats.flogi_sent++;
989}
990
991static void
992bfa_fcs_fabric_notify_online(struct bfa_fcs_fabric_s *fabric)
993{
994 struct bfa_fcs_vport_s *vport;
995 struct list_head *qe, *qen;
996
997 bfa_trc(fabric->fcs, fabric->fabric_name);
998
999 bfa_fcs_fabric_set_opertype(fabric);
1000 fabric->stats.fabric_onlines++;
1001
Jing Huang5fbe25c2010-10-18 17:17:23 -07001002 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001003 * notify online event to base and then virtual ports
1004 */
1005 bfa_fcs_lport_online(&fabric->bport);
1006
1007 list_for_each_safe(qe, qen, &fabric->vport_q) {
1008 vport = (struct bfa_fcs_vport_s *) qe;
1009 bfa_fcs_vport_online(vport);
1010 }
1011}
1012
1013static void
1014bfa_fcs_fabric_notify_offline(struct bfa_fcs_fabric_s *fabric)
1015{
1016 struct bfa_fcs_vport_s *vport;
1017 struct list_head *qe, *qen;
1018
1019 bfa_trc(fabric->fcs, fabric->fabric_name);
1020 fabric->stats.fabric_offlines++;
1021
Jing Huang5fbe25c2010-10-18 17:17:23 -07001022 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001023 * notify offline event first to vports and then base port.
1024 */
1025 list_for_each_safe(qe, qen, &fabric->vport_q) {
1026 vport = (struct bfa_fcs_vport_s *) qe;
1027 bfa_fcs_vport_offline(vport);
1028 }
1029
1030 bfa_fcs_lport_offline(&fabric->bport);
1031
1032 fabric->fabric_name = 0;
1033 fabric->fabric_ip_addr[0] = 0;
1034}
1035
1036static void
1037bfa_fcs_fabric_delay(void *cbarg)
1038{
1039 struct bfa_fcs_fabric_s *fabric = cbarg;
1040
1041 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_DELAYED);
1042}
1043
Jing Huang5fbe25c2010-10-18 17:17:23 -07001044/*
Krishna Gudipati881c1b32012-08-22 19:52:02 -07001045 * Stop all vports and wait for vport stop completions.
1046 */
1047static void
1048bfa_fcs_fabric_stop(struct bfa_fcs_fabric_s *fabric)
1049{
1050 struct bfa_fcs_vport_s *vport;
1051 struct list_head *qe, *qen;
1052
1053 bfa_wc_init(&fabric->stop_wc, bfa_fcs_fabric_stop_comp, fabric);
1054
1055 list_for_each_safe(qe, qen, &fabric->vport_q) {
1056 vport = (struct bfa_fcs_vport_s *) qe;
1057 bfa_wc_up(&fabric->stop_wc);
1058 bfa_fcs_vport_fcs_stop(vport);
1059 }
1060
1061 bfa_wc_up(&fabric->stop_wc);
1062 bfa_fcs_lport_stop(&fabric->bport);
1063 bfa_wc_wait(&fabric->stop_wc);
1064}
1065
1066/*
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001067 * Computes operating BB_SCN value
1068 */
1069static u8
1070bfa_fcs_fabric_oper_bbscn(struct bfa_fcs_fabric_s *fabric)
1071{
1072 u8 pr_bbscn = fabric->lps->pr_bbscn;
Krishna Gudipatid7be54c2011-06-24 20:24:52 -07001073 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(fabric->fcs->bfa);
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001074
Krishna Gudipatid7be54c2011-06-24 20:24:52 -07001075 if (!(fcport->cfg.bb_scn_state && pr_bbscn))
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001076 return 0;
1077
1078 /* return max of local/remote bb_scn values */
1079 return ((pr_bbscn > BFA_FCS_PORT_DEF_BB_SCN) ?
1080 pr_bbscn : BFA_FCS_PORT_DEF_BB_SCN);
1081}
1082
1083/*
1084 * Check if BB_SCN can be enabled.
1085 */
1086static bfa_boolean_t
1087bfa_fcs_fabric_is_bbscn_enabled(struct bfa_fcs_fabric_s *fabric)
1088{
Krishna Gudipatid7be54c2011-06-24 20:24:52 -07001089 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(fabric->fcs->bfa);
1090
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001091 if (bfa_ioc_get_fcmode(&fabric->fcs->bfa->ioc) &&
Krishna Gudipatid7be54c2011-06-24 20:24:52 -07001092 fcport->cfg.bb_scn_state &&
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001093 !bfa_fcport_is_qos_enabled(fabric->fcs->bfa) &&
1094 !bfa_fcport_is_trunk_enabled(fabric->fcs->bfa))
1095 return BFA_TRUE;
1096 else
1097 return BFA_FALSE;
1098}
1099
1100/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001101 * Delete all vports and wait for vport delete completions.
1102 */
1103static void
1104bfa_fcs_fabric_delete(struct bfa_fcs_fabric_s *fabric)
1105{
1106 struct bfa_fcs_vport_s *vport;
1107 struct list_head *qe, *qen;
1108
1109 list_for_each_safe(qe, qen, &fabric->vport_q) {
1110 vport = (struct bfa_fcs_vport_s *) qe;
1111 bfa_fcs_vport_fcs_delete(vport);
1112 }
1113
1114 bfa_fcs_lport_delete(&fabric->bport);
1115 bfa_wc_wait(&fabric->wc);
1116}
1117
1118static void
1119bfa_fcs_fabric_delete_comp(void *cbarg)
1120{
1121 struct bfa_fcs_fabric_s *fabric = cbarg;
1122
1123 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_DELCOMP);
1124}
1125
Krishna Gudipati881c1b32012-08-22 19:52:02 -07001126static void
1127bfa_fcs_fabric_stop_comp(void *cbarg)
1128{
1129 struct bfa_fcs_fabric_s *fabric = cbarg;
1130
1131 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_STOPCOMP);
1132}
1133
Jing Huang5fbe25c2010-10-18 17:17:23 -07001134/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001135 * fcs_fabric_public fabric public functions
1136 */
1137
Jing Huang5fbe25c2010-10-18 17:17:23 -07001138/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001139 * Attach time initialization.
1140 */
1141void
1142bfa_fcs_fabric_attach(struct bfa_fcs_s *fcs)
1143{
1144 struct bfa_fcs_fabric_s *fabric;
1145
1146 fabric = &fcs->fabric;
Jing Huang6a18b162010-10-18 17:08:54 -07001147 memset(fabric, 0, sizeof(struct bfa_fcs_fabric_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001148
Jing Huang5fbe25c2010-10-18 17:17:23 -07001149 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001150 * Initialize base fabric.
1151 */
1152 fabric->fcs = fcs;
1153 INIT_LIST_HEAD(&fabric->vport_q);
1154 INIT_LIST_HEAD(&fabric->vf_q);
1155 fabric->lps = bfa_lps_alloc(fcs->bfa);
Jing Huangd4b671c2010-12-26 21:46:35 -08001156 WARN_ON(!fabric->lps);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001157
Jing Huang5fbe25c2010-10-18 17:17:23 -07001158 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001159 * Initialize fabric delete completion handler. Fabric deletion is
1160 * complete when the last vport delete is complete.
1161 */
1162 bfa_wc_init(&fabric->wc, bfa_fcs_fabric_delete_comp, fabric);
1163 bfa_wc_up(&fabric->wc); /* For the base port */
1164
1165 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_uninit);
1166 bfa_fcs_lport_attach(&fabric->bport, fabric->fcs, FC_VF_ID_NULL, NULL);
1167}
1168
1169void
1170bfa_fcs_fabric_modinit(struct bfa_fcs_s *fcs)
1171{
1172 bfa_sm_send_event(&fcs->fabric, BFA_FCS_FABRIC_SM_CREATE);
1173 bfa_trc(fcs, 0);
1174}
1175
Jing Huang5fbe25c2010-10-18 17:17:23 -07001176/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001177 * Module cleanup
1178 */
1179void
1180bfa_fcs_fabric_modexit(struct bfa_fcs_s *fcs)
1181{
1182 struct bfa_fcs_fabric_s *fabric;
1183
1184 bfa_trc(fcs, 0);
1185
Jing Huang5fbe25c2010-10-18 17:17:23 -07001186 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001187 * Cleanup base fabric.
1188 */
1189 fabric = &fcs->fabric;
1190 bfa_lps_delete(fabric->lps);
1191 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_DELETE);
1192}
1193
Jing Huang5fbe25c2010-10-18 17:17:23 -07001194/*
Krishna Gudipati881c1b32012-08-22 19:52:02 -07001195 * Fabric module stop -- stop FCS actions
1196 */
1197void
1198bfa_fcs_fabric_modstop(struct bfa_fcs_s *fcs)
1199{
1200 struct bfa_fcs_fabric_s *fabric;
1201
1202 bfa_trc(fcs, 0);
1203 fabric = &fcs->fabric;
1204 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_STOP);
1205}
1206
1207/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001208 * Fabric module start -- kick starts FCS actions
1209 */
1210void
1211bfa_fcs_fabric_modstart(struct bfa_fcs_s *fcs)
1212{
1213 struct bfa_fcs_fabric_s *fabric;
1214
1215 bfa_trc(fcs, 0);
1216 fabric = &fcs->fabric;
1217 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_START);
1218}
1219
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001220
Jing Huang5fbe25c2010-10-18 17:17:23 -07001221/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001222 * Link up notification from BFA physical port module.
1223 */
1224void
1225bfa_fcs_fabric_link_up(struct bfa_fcs_fabric_s *fabric)
1226{
1227 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
1228 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_LINK_UP);
1229}
1230
Jing Huang5fbe25c2010-10-18 17:17:23 -07001231/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001232 * Link down notification from BFA physical port module.
1233 */
1234void
1235bfa_fcs_fabric_link_down(struct bfa_fcs_fabric_s *fabric)
1236{
1237 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001238 fabric->fcs->bbscn_flogi_rjt = BFA_FALSE;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001239 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_LINK_DOWN);
1240}
1241
Jing Huang5fbe25c2010-10-18 17:17:23 -07001242/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001243 * A child vport is being created in the fabric.
1244 *
1245 * Call from vport module at vport creation. A list of base port and vports
1246 * belonging to a fabric is maintained to propagate link events.
1247 *
1248 * param[in] fabric - Fabric instance. This can be a base fabric or vf.
1249 * param[in] vport - Vport being created.
1250 *
1251 * @return None (always succeeds)
1252 */
1253void
1254bfa_fcs_fabric_addvport(struct bfa_fcs_fabric_s *fabric,
1255 struct bfa_fcs_vport_s *vport)
1256{
Jing Huang5fbe25c2010-10-18 17:17:23 -07001257 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001258 * - add vport to fabric's vport_q
1259 */
1260 bfa_trc(fabric->fcs, fabric->vf_id);
1261
1262 list_add_tail(&vport->qe, &fabric->vport_q);
1263 fabric->num_vports++;
1264 bfa_wc_up(&fabric->wc);
1265}
1266
Jing Huang5fbe25c2010-10-18 17:17:23 -07001267/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001268 * A child vport is being deleted from fabric.
1269 *
1270 * Vport is being deleted.
1271 */
1272void
1273bfa_fcs_fabric_delvport(struct bfa_fcs_fabric_s *fabric,
1274 struct bfa_fcs_vport_s *vport)
1275{
1276 list_del(&vport->qe);
1277 fabric->num_vports--;
1278 bfa_wc_down(&fabric->wc);
1279}
1280
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001281
Jing Huang5fbe25c2010-10-18 17:17:23 -07001282/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001283 * Lookup for a vport within a fabric given its pwwn
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001284 */
1285struct bfa_fcs_vport_s *
1286bfa_fcs_fabric_vport_lookup(struct bfa_fcs_fabric_s *fabric, wwn_t pwwn)
1287{
1288 struct bfa_fcs_vport_s *vport;
1289 struct list_head *qe;
1290
1291 list_for_each(qe, &fabric->vport_q) {
1292 vport = (struct bfa_fcs_vport_s *) qe;
1293 if (bfa_fcs_lport_get_pwwn(&vport->lport) == pwwn)
1294 return vport;
1295 }
1296
1297 return NULL;
1298}
1299
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001300
1301/*
1302 * Get OUI of the attached switch.
1303 *
1304 * Note : Use of this function should be avoided as much as possible.
1305 * This function should be used only if there is any requirement
1306* to check for FOS version below 6.3.
1307 * To check if the attached fabric is a brocade fabric, use
1308 * bfa_lps_is_brcd_fabric() which works for FOS versions 6.3
1309 * or above only.
1310 */
1311
1312u16
1313bfa_fcs_fabric_get_switch_oui(struct bfa_fcs_fabric_s *fabric)
1314{
1315 wwn_t fab_nwwn;
1316 u8 *tmp;
1317 u16 oui;
1318
Maggie Zhangf7f738122010-12-09 19:08:43 -08001319 fab_nwwn = fabric->lps->pr_nwwn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001320
1321 tmp = (u8 *)&fab_nwwn;
1322 oui = (tmp[3] << 8) | tmp[4];
1323
1324 return oui;
1325}
Jing Huang5fbe25c2010-10-18 17:17:23 -07001326/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001327 * Unsolicited frame receive handling.
1328 */
1329void
1330bfa_fcs_fabric_uf_recv(struct bfa_fcs_fabric_s *fabric, struct fchs_s *fchs,
1331 u16 len)
1332{
1333 u32 pid = fchs->d_id;
1334 struct bfa_fcs_vport_s *vport;
1335 struct list_head *qe;
1336 struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
1337 struct fc_logi_s *flogi = (struct fc_logi_s *) els_cmd;
1338
1339 bfa_trc(fabric->fcs, len);
1340 bfa_trc(fabric->fcs, pid);
1341
Jing Huang5fbe25c2010-10-18 17:17:23 -07001342 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001343 * Look for our own FLOGI frames being looped back. This means an
1344 * external loopback cable is in place. Our own FLOGI frames are
1345 * sometimes looped back when switch port gets temporarily bypassed.
1346 */
Maggie Zhangf16a1752010-12-09 19:12:32 -08001347 if ((pid == bfa_ntoh3b(FC_FABRIC_PORT)) &&
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001348 (els_cmd->els_code == FC_ELS_FLOGI) &&
1349 (flogi->port_name == bfa_fcs_lport_get_pwwn(&fabric->bport))) {
1350 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_LOOPBACK);
1351 return;
1352 }
1353
Jing Huang5fbe25c2010-10-18 17:17:23 -07001354 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001355 * FLOGI/EVFP exchanges should be consumed by base fabric.
1356 */
Maggie Zhangf16a1752010-12-09 19:12:32 -08001357 if (fchs->d_id == bfa_hton3b(FC_FABRIC_PORT)) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001358 bfa_trc(fabric->fcs, pid);
1359 bfa_fcs_fabric_process_uf(fabric, fchs, len);
1360 return;
1361 }
1362
1363 if (fabric->bport.pid == pid) {
Jing Huang5fbe25c2010-10-18 17:17:23 -07001364 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001365 * All authentication frames should be routed to auth
1366 */
1367 bfa_trc(fabric->fcs, els_cmd->els_code);
1368 if (els_cmd->els_code == FC_ELS_AUTH) {
1369 bfa_trc(fabric->fcs, els_cmd->els_code);
1370 return;
1371 }
1372
1373 bfa_trc(fabric->fcs, *(u8 *) ((u8 *) fchs));
1374 bfa_fcs_lport_uf_recv(&fabric->bport, fchs, len);
1375 return;
1376 }
1377
Jing Huang5fbe25c2010-10-18 17:17:23 -07001378 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001379 * look for a matching local port ID
1380 */
1381 list_for_each(qe, &fabric->vport_q) {
1382 vport = (struct bfa_fcs_vport_s *) qe;
1383 if (vport->lport.pid == pid) {
1384 bfa_fcs_lport_uf_recv(&vport->lport, fchs, len);
1385 return;
1386 }
1387 }
Krishna Gudipati61ba4392012-08-22 19:52:58 -07001388
1389 if (!bfa_fcs_fabric_is_switched(fabric))
1390 bfa_fcs_lport_uf_recv(&fabric->bport, fchs, len);
1391
1392 bfa_trc(fabric->fcs, fchs->type);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001393}
1394
Jing Huang5fbe25c2010-10-18 17:17:23 -07001395/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001396 * Unsolicited frames to be processed by fabric.
1397 */
1398static void
1399bfa_fcs_fabric_process_uf(struct bfa_fcs_fabric_s *fabric, struct fchs_s *fchs,
1400 u16 len)
1401{
1402 struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
1403
1404 bfa_trc(fabric->fcs, els_cmd->els_code);
1405
1406 switch (els_cmd->els_code) {
1407 case FC_ELS_FLOGI:
1408 bfa_fcs_fabric_process_flogi(fabric, fchs, len);
1409 break;
1410
1411 default:
1412 /*
1413 * need to generate a LS_RJT
1414 */
1415 break;
1416 }
1417}
1418
Jing Huang5fbe25c2010-10-18 17:17:23 -07001419/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001420 * Process incoming FLOGI
1421 */
1422static void
1423bfa_fcs_fabric_process_flogi(struct bfa_fcs_fabric_s *fabric,
1424 struct fchs_s *fchs, u16 len)
1425{
1426 struct fc_logi_s *flogi = (struct fc_logi_s *) (fchs + 1);
1427 struct bfa_fcs_lport_s *bport = &fabric->bport;
1428
1429 bfa_trc(fabric->fcs, fchs->s_id);
1430
1431 fabric->stats.flogi_rcvd++;
1432 /*
1433 * Check port type. It should be 0 = n-port.
1434 */
1435 if (flogi->csp.port_type) {
1436 /*
1437 * @todo: may need to send a LS_RJT
1438 */
1439 bfa_trc(fabric->fcs, flogi->port_name);
1440 fabric->stats.flogi_rejected++;
1441 return;
1442 }
1443
Jing Huangba816ea2010-10-18 17:10:50 -07001444 fabric->bb_credit = be16_to_cpu(flogi->csp.bbcred);
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001445 fabric->lps->pr_bbscn = (be16_to_cpu(flogi->csp.rxsz) >> 12);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001446 bport->port_topo.pn2n.rem_port_wwn = flogi->port_name;
1447 bport->port_topo.pn2n.reply_oxid = fchs->ox_id;
1448
1449 /*
1450 * Send a Flogi Acc
1451 */
1452 bfa_fcs_fabric_send_flogi_acc(fabric);
1453 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_NO_FABRIC);
1454}
1455
1456static void
1457bfa_fcs_fabric_send_flogi_acc(struct bfa_fcs_fabric_s *fabric)
1458{
1459 struct bfa_lport_cfg_s *pcfg = &fabric->bport.port_cfg;
1460 struct bfa_fcs_lport_n2n_s *n2n_port = &fabric->bport.port_topo.pn2n;
1461 struct bfa_s *bfa = fabric->fcs->bfa;
1462 struct bfa_fcxp_s *fcxp;
1463 u16 reqlen;
1464 struct fchs_s fchs;
1465
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07001466 fcxp = bfa_fcs_fcxp_alloc(fabric->fcs, BFA_FALSE);
Jing Huang5fbe25c2010-10-18 17:17:23 -07001467 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001468 * Do not expect this failure -- expect remote node to retry
1469 */
1470 if (!fcxp)
1471 return;
1472
1473 reqlen = fc_flogi_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
Maggie Zhangf16a1752010-12-09 19:12:32 -08001474 bfa_hton3b(FC_FABRIC_PORT),
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001475 n2n_port->reply_oxid, pcfg->pwwn,
1476 pcfg->nwwn,
1477 bfa_fcport_get_maxfrsize(bfa),
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001478 bfa_fcport_get_rx_bbcredit(bfa),
1479 bfa_fcs_fabric_oper_bbscn(fabric));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001480
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001481 bfa_fcxp_send(fcxp, NULL, fabric->vf_id, fabric->lps->bfa_tag,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001482 BFA_FALSE, FC_CLASS_3,
1483 reqlen, &fchs, bfa_fcs_fabric_flogiacc_comp, fabric,
1484 FC_MAX_PDUSZ, 0);
1485}
1486
Jing Huang5fbe25c2010-10-18 17:17:23 -07001487/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001488 * Flogi Acc completion callback.
1489 */
1490static void
1491bfa_fcs_fabric_flogiacc_comp(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
1492 bfa_status_t status, u32 rsp_len,
1493 u32 resid_len, struct fchs_s *rspfchs)
1494{
1495 struct bfa_fcs_fabric_s *fabric = cbarg;
1496
1497 bfa_trc(fabric->fcs, status);
1498}
1499
Krishna Gudipati7826f302011-07-20 16:59:13 -07001500
1501/*
1502 * Send AEN notification
1503 */
1504static void
1505bfa_fcs_fabric_aen_post(struct bfa_fcs_lport_s *port,
1506 enum bfa_port_aen_event event)
1507{
1508 struct bfad_s *bfad = (struct bfad_s *)port->fabric->fcs->bfad;
1509 struct bfa_aen_entry_s *aen_entry;
1510
1511 bfad_get_aen_entry(bfad, aen_entry);
1512 if (!aen_entry)
1513 return;
1514
1515 aen_entry->aen_data.port.pwwn = bfa_fcs_lport_get_pwwn(port);
1516 aen_entry->aen_data.port.fwwn = bfa_fcs_lport_get_fabric_name(port);
1517
1518 /* Send the AEN notification */
1519 bfad_im_post_vendor_event(aen_entry, bfad, ++port->fcs->fcs_aen_seq,
1520 BFA_AEN_CAT_PORT, event);
1521}
1522
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001523/*
1524 *
1525 * @param[in] fabric - fabric
1526 * @param[in] wwn_t - new fabric name
1527 *
1528 * @return - none
1529 */
1530void
1531bfa_fcs_fabric_set_fabric_name(struct bfa_fcs_fabric_s *fabric,
1532 wwn_t fabric_name)
1533{
1534 struct bfad_s *bfad = (struct bfad_s *)fabric->fcs->bfad;
1535 char pwwn_ptr[BFA_STRING_32];
1536 char fwwn_ptr[BFA_STRING_32];
1537
1538 bfa_trc(fabric->fcs, fabric_name);
1539
1540 if (fabric->fabric_name == 0) {
1541 /*
1542 * With BRCD switches, we don't get Fabric Name in FLOGI.
1543 * Don't generate a fabric name change event in this case.
1544 */
1545 fabric->fabric_name = fabric_name;
1546 } else {
1547 fabric->fabric_name = fabric_name;
1548 wwn2str(pwwn_ptr, bfa_fcs_lport_get_pwwn(&fabric->bport));
1549 wwn2str(fwwn_ptr,
1550 bfa_fcs_lport_get_fabric_name(&fabric->bport));
Jing Huang88166242010-12-09 17:11:53 -08001551 BFA_LOG(KERN_WARNING, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001552 "Base port WWN = %s Fabric WWN = %s\n",
1553 pwwn_ptr, fwwn_ptr);
Krishna Gudipati7826f302011-07-20 16:59:13 -07001554 bfa_fcs_fabric_aen_post(&fabric->bport,
1555 BFA_PORT_AEN_FABRIC_NAME_CHANGE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001556 }
1557}
1558
Krishna Gudipati881c1b32012-08-22 19:52:02 -07001559void
1560bfa_cb_lps_flogo_comp(void *bfad, void *uarg)
1561{
1562 struct bfa_fcs_fabric_s *fabric = uarg;
1563 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_LOGOCOMP);
1564}
1565
Jing Huang5fbe25c2010-10-18 17:17:23 -07001566/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001567 * Returns FCS vf structure for a given vf_id.
1568 *
1569 * param[in] vf_id - VF_ID
1570 *
1571 * return
1572 * If lookup succeeds, retuns fcs vf object, otherwise returns NULL
1573 */
1574bfa_fcs_vf_t *
1575bfa_fcs_vf_lookup(struct bfa_fcs_s *fcs, u16 vf_id)
1576{
1577 bfa_trc(fcs, vf_id);
1578 if (vf_id == FC_VF_ID_NULL)
1579 return &fcs->fabric;
1580
1581 return NULL;
1582}
1583
Jing Huang5fbe25c2010-10-18 17:17:23 -07001584/*
Krishna Gudipatib85daaf2011-06-13 15:55:11 -07001585 * Return the list of local logical ports present in the given VF.
1586 *
1587 * @param[in] vf vf for which logical ports are returned
1588 * @param[out] lpwwn returned logical port wwn list
1589 * @param[in,out] nlports in:size of lpwwn list;
1590 * out:total elements present,
1591 * actual elements returned is limited by the size
1592 */
1593void
1594bfa_fcs_vf_get_ports(bfa_fcs_vf_t *vf, wwn_t lpwwn[], int *nlports)
1595{
1596 struct list_head *qe;
1597 struct bfa_fcs_vport_s *vport;
1598 int i = 0;
1599 struct bfa_fcs_s *fcs;
1600
1601 if (vf == NULL || lpwwn == NULL || *nlports == 0)
1602 return;
1603
1604 fcs = vf->fcs;
1605
1606 bfa_trc(fcs, vf->vf_id);
1607 bfa_trc(fcs, (uint32_t) *nlports);
1608
1609 lpwwn[i++] = vf->bport.port_cfg.pwwn;
1610
1611 list_for_each(qe, &vf->vport_q) {
1612 if (i >= *nlports)
1613 break;
1614
1615 vport = (struct bfa_fcs_vport_s *) qe;
1616 lpwwn[i++] = vport->lport.port_cfg.pwwn;
1617 }
1618
1619 bfa_trc(fcs, i);
1620 *nlports = i;
1621}
1622
1623/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001624 * BFA FCS PPORT ( physical port)
1625 */
1626static void
1627bfa_fcs_port_event_handler(void *cbarg, enum bfa_port_linkstate event)
1628{
1629 struct bfa_fcs_s *fcs = cbarg;
1630
1631 bfa_trc(fcs, event);
1632
1633 switch (event) {
1634 case BFA_PORT_LINKUP:
1635 bfa_fcs_fabric_link_up(&fcs->fabric);
1636 break;
1637
1638 case BFA_PORT_LINKDOWN:
1639 bfa_fcs_fabric_link_down(&fcs->fabric);
1640 break;
1641
1642 default:
Jing Huangd4b671c2010-12-26 21:46:35 -08001643 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001644 }
1645}
1646
1647void
1648bfa_fcs_port_attach(struct bfa_fcs_s *fcs)
1649{
1650 bfa_fcport_event_register(fcs->bfa, bfa_fcs_port_event_handler, fcs);
1651}
1652
Jing Huang5fbe25c2010-10-18 17:17:23 -07001653/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001654 * BFA FCS UF ( Unsolicited Frames)
1655 */
1656
Jing Huang5fbe25c2010-10-18 17:17:23 -07001657/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001658 * BFA callback for unsolicited frame receive handler.
1659 *
1660 * @param[in] cbarg callback arg for receive handler
1661 * @param[in] uf unsolicited frame descriptor
1662 *
1663 * @return None
1664 */
1665static void
1666bfa_fcs_uf_recv(void *cbarg, struct bfa_uf_s *uf)
1667{
1668 struct bfa_fcs_s *fcs = (struct bfa_fcs_s *) cbarg;
1669 struct fchs_s *fchs = bfa_uf_get_frmbuf(uf);
1670 u16 len = bfa_uf_get_frmlen(uf);
1671 struct fc_vft_s *vft;
1672 struct bfa_fcs_fabric_s *fabric;
1673
Jing Huang5fbe25c2010-10-18 17:17:23 -07001674 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001675 * check for VFT header
1676 */
1677 if (fchs->routing == FC_RTG_EXT_HDR &&
1678 fchs->cat_info == FC_CAT_VFT_HDR) {
1679 bfa_stats(fcs, uf.tagged);
1680 vft = bfa_uf_get_frmbuf(uf);
1681 if (fcs->port_vfid == vft->vf_id)
1682 fabric = &fcs->fabric;
1683 else
1684 fabric = bfa_fcs_vf_lookup(fcs, (u16) vft->vf_id);
1685
Jing Huang5fbe25c2010-10-18 17:17:23 -07001686 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001687 * drop frame if vfid is unknown
1688 */
1689 if (!fabric) {
Jing Huangd4b671c2010-12-26 21:46:35 -08001690 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001691 bfa_stats(fcs, uf.vfid_unknown);
1692 bfa_uf_free(uf);
1693 return;
1694 }
1695
Jing Huang5fbe25c2010-10-18 17:17:23 -07001696 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001697 * skip vft header
1698 */
1699 fchs = (struct fchs_s *) (vft + 1);
1700 len -= sizeof(struct fc_vft_s);
1701
1702 bfa_trc(fcs, vft->vf_id);
1703 } else {
1704 bfa_stats(fcs, uf.untagged);
1705 fabric = &fcs->fabric;
1706 }
1707
1708 bfa_trc(fcs, ((u32 *) fchs)[0]);
1709 bfa_trc(fcs, ((u32 *) fchs)[1]);
1710 bfa_trc(fcs, ((u32 *) fchs)[2]);
1711 bfa_trc(fcs, ((u32 *) fchs)[3]);
1712 bfa_trc(fcs, ((u32 *) fchs)[4]);
1713 bfa_trc(fcs, ((u32 *) fchs)[5]);
1714 bfa_trc(fcs, len);
1715
1716 bfa_fcs_fabric_uf_recv(fabric, fchs, len);
1717 bfa_uf_free(uf);
1718}
1719
1720void
1721bfa_fcs_uf_attach(struct bfa_fcs_s *fcs)
1722{
1723 bfa_uf_recv_register(fcs->bfa, bfa_fcs_uf_recv, fcs);
1724}