blob: 1e7e139d71eabd1bbdc9e1daa4b589f640e231e6 [file] [log] [blame]
Jing Huang7725ccf2009-09-23 17:46:15 -07001/*
Anil Gurumurthy889d0d42015-11-26 03:54:45 -05002 * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
3 * Copyright (c) 2014- QLogic Corporation.
Jing Huang7725ccf2009-09-23 17:46:15 -07004 * All rights reserved
Anil Gurumurthy889d0d42015-11-26 03:54:45 -05005 * www.qlogic.com
Jing Huang7725ccf2009-09-23 17:46:15 -07006 *
Anil Gurumurthy31e1d562015-11-26 03:54:46 -05007 * Linux driver for QLogic BR-series Fibre Channel Host Bus Adapter.
Jing Huang7725ccf2009-09-23 17:46:15 -07008 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License (GPL) Version 2 as
11 * published by the Free Software Foundation
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 */
18
Jing Huang5fbe25c2010-10-18 17:17:23 -070019/*
Jing Huang7725ccf2009-09-23 17:46:15 -070020 * bfa_fcs.c BFA FCS main
21 */
22
Maggie Zhangf16a1752010-12-09 19:12:32 -080023#include "bfad_drv.h"
Krishna Gudipati7826f302011-07-20 16:59:13 -070024#include "bfad_im.h"
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070025#include "bfa_fcs.h"
26#include "bfa_fcbuild.h"
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070027
28BFA_TRC_FILE(FCS, FCS);
Jing Huang7725ccf2009-09-23 17:46:15 -070029
Jing Huang5fbe25c2010-10-18 17:17:23 -070030/*
Jing Huang7725ccf2009-09-23 17:46:15 -070031 * FCS sub-modules
32 */
33struct bfa_fcs_mod_s {
Krishna Gudipati82794a22010-03-03 17:43:30 -080034 void (*attach) (struct bfa_fcs_s *fcs);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070035 void (*modinit) (struct bfa_fcs_s *fcs);
36 void (*modexit) (struct bfa_fcs_s *fcs);
Jing Huang7725ccf2009-09-23 17:46:15 -070037};
38
39#define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
40
41static struct bfa_fcs_mod_s fcs_modules[] = {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070042 { bfa_fcs_port_attach, NULL, NULL },
Krishna Gudipati82794a22010-03-03 17:43:30 -080043 { bfa_fcs_uf_attach, NULL, NULL },
44 { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070045 bfa_fcs_fabric_modexit },
Jing Huang7725ccf2009-09-23 17:46:15 -070046};
47
Jing Huang5fbe25c2010-10-18 17:17:23 -070048/*
Jing Huang7725ccf2009-09-23 17:46:15 -070049 * fcs_api BFA FCS API
50 */
51
52static void
53bfa_fcs_exit_comp(void *fcs_cbarg)
54{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070055 struct bfa_fcs_s *fcs = fcs_cbarg;
56 struct bfad_s *bfad = fcs->bfad;
Jing Huang7725ccf2009-09-23 17:46:15 -070057
58 complete(&bfad->comp);
59}
60
61
62
Jing Huang5fbe25c2010-10-18 17:17:23 -070063/*
Jing Huang7725ccf2009-09-23 17:46:15 -070064 * fcs_api BFA FCS API
65 */
66
Jing Huang5fbe25c2010-10-18 17:17:23 -070067/*
Krishna Gudipati82794a22010-03-03 17:43:30 -080068 * fcs attach -- called once to initialize data structures at driver attach time
Jing Huang7725ccf2009-09-23 17:46:15 -070069 */
70void
Krishna Gudipati82794a22010-03-03 17:43:30 -080071bfa_fcs_attach(struct bfa_fcs_s *fcs, struct bfa_s *bfa, struct bfad_s *bfad,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070072 bfa_boolean_t min_cfg)
Jing Huang7725ccf2009-09-23 17:46:15 -070073{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070074 int i;
Jing Huang7725ccf2009-09-23 17:46:15 -070075 struct bfa_fcs_mod_s *mod;
76
77 fcs->bfa = bfa;
78 fcs->bfad = bfad;
79 fcs->min_cfg = min_cfg;
Krishna Gudipati61ba4392012-08-22 19:52:58 -070080 fcs->num_rport_logins = 0;
Jing Huang7725ccf2009-09-23 17:46:15 -070081
Maggie Zhangf7f738122010-12-09 19:08:43 -080082 bfa->fcs = BFA_TRUE;
Jing Huang7725ccf2009-09-23 17:46:15 -070083 fcbuild_init();
84
Fabian Frederick44416c42014-06-30 19:42:42 +020085 for (i = 0; i < ARRAY_SIZE(fcs_modules); i++) {
Jing Huang7725ccf2009-09-23 17:46:15 -070086 mod = &fcs_modules[i];
Krishna Gudipati82794a22010-03-03 17:43:30 -080087 if (mod->attach)
88 mod->attach(fcs);
89 }
90}
91
Jing Huang5fbe25c2010-10-18 17:17:23 -070092/*
Krishna Gudipati82794a22010-03-03 17:43:30 -080093 * fcs initialization, called once after bfa initialization is complete
94 */
95void
96bfa_fcs_init(struct bfa_fcs_s *fcs)
97{
Krishna Gudipati75332a72011-06-13 15:54:31 -070098 int i;
Krishna Gudipati82794a22010-03-03 17:43:30 -080099 struct bfa_fcs_mod_s *mod;
100
Fabian Frederick44416c42014-06-30 19:42:42 +0200101 for (i = 0; i < ARRAY_SIZE(fcs_modules); i++) {
Krishna Gudipati82794a22010-03-03 17:43:30 -0800102 mod = &fcs_modules[i];
103 if (mod->modinit)
104 mod->modinit(fcs);
Jing Huang7725ccf2009-09-23 17:46:15 -0700105 }
Krishna Gudipati75332a72011-06-13 15:54:31 -0700106}
107
108/*
109 * FCS update cfg - reset the pwwn/nwwn of fabric base logical port
110 * with values learned during bfa_init firmware GETATTR REQ.
111 */
112void
113bfa_fcs_update_cfg(struct bfa_fcs_s *fcs)
114{
115 struct bfa_fcs_fabric_s *fabric = &fcs->fabric;
116 struct bfa_lport_cfg_s *port_cfg = &fabric->bport.port_cfg;
117 struct bfa_ioc_s *ioc = &fabric->fcs->bfa->ioc;
118
119 port_cfg->nwwn = ioc->attr->nwwn;
120 port_cfg->pwwn = ioc->attr->pwwn;
121}
122
123/*
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700124 * Stop FCS operations.
125 */
126void
127bfa_fcs_stop(struct bfa_fcs_s *fcs)
128{
129 bfa_wc_init(&fcs->wc, bfa_fcs_exit_comp, fcs);
130 bfa_wc_up(&fcs->wc);
131 bfa_fcs_fabric_modstop(fcs);
132 bfa_wc_wait(&fcs->wc);
133}
134
135/*
Krishna Gudipati75332a72011-06-13 15:54:31 -0700136 * fcs pbc vport initialization
137 */
138void
139bfa_fcs_pbc_vport_init(struct bfa_fcs_s *fcs)
140{
141 int i, npbc_vports;
142 struct bfi_pbc_vport_s pbc_vports[BFI_PBC_MAX_VPORTS];
143
Jing Huangd9883542010-07-08 19:46:26 -0700144 /* Initialize pbc vports */
145 if (!fcs->min_cfg) {
146 npbc_vports =
Krishna Gudipati75332a72011-06-13 15:54:31 -0700147 bfa_iocfc_get_pbc_vports(fcs->bfa, pbc_vports);
Jing Huangd9883542010-07-08 19:46:26 -0700148 for (i = 0; i < npbc_vports; i++)
149 bfa_fcb_pbc_vport_create(fcs->bfa->bfad, pbc_vports[i]);
150 }
Jing Huang7725ccf2009-09-23 17:46:15 -0700151}
152
Jing Huang5fbe25c2010-10-18 17:17:23 -0700153/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700154 * brief
155 * FCS driver details initialization.
Jing Huang7725ccf2009-09-23 17:46:15 -0700156 *
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700157 * param[in] fcs FCS instance
158 * param[in] driver_info Driver Details
Jing Huang7725ccf2009-09-23 17:46:15 -0700159 *
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700160 * return None
Jing Huang7725ccf2009-09-23 17:46:15 -0700161 */
162void
163bfa_fcs_driver_info_init(struct bfa_fcs_s *fcs,
164 struct bfa_fcs_driver_info_s *driver_info)
165{
166
167 fcs->driver_info = *driver_info;
168
169 bfa_fcs_fabric_psymb_init(&fcs->fabric);
Krishna Gudipatice7242b2012-08-22 19:52:43 -0700170 bfa_fcs_fabric_nsymb_init(&fcs->fabric);
Jing Huang7725ccf2009-09-23 17:46:15 -0700171}
172
Jing Huang5fbe25c2010-10-18 17:17:23 -0700173/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700174 * brief
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700175 * FCS instance cleanup and exit.
Jing Huang7725ccf2009-09-23 17:46:15 -0700176 *
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700177 * param[in] fcs FCS instance
178 * return None
Jing Huang7725ccf2009-09-23 17:46:15 -0700179 */
180void
181bfa_fcs_exit(struct bfa_fcs_s *fcs)
182{
183 struct bfa_fcs_mod_s *mod;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700184 int nmods, i;
Jing Huang7725ccf2009-09-23 17:46:15 -0700185
186 bfa_wc_init(&fcs->wc, bfa_fcs_exit_comp, fcs);
187
Fabian Frederick44416c42014-06-30 19:42:42 +0200188 nmods = ARRAY_SIZE(fcs_modules);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700189
190 for (i = 0; i < nmods; i++) {
Jing Huang7725ccf2009-09-23 17:46:15 -0700191
192 mod = &fcs_modules[i];
Krishna Gudipati82794a22010-03-03 17:43:30 -0800193 if (mod->modexit) {
194 bfa_wc_up(&fcs->wc);
195 mod->modexit(fcs);
196 }
Jing Huang7725ccf2009-09-23 17:46:15 -0700197 }
198
199 bfa_wc_wait(&fcs->wc);
200}
201
202
Jing Huang5fbe25c2010-10-18 17:17:23 -0700203/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700204 * Fabric module implementation.
205 */
Jing Huang7725ccf2009-09-23 17:46:15 -0700206
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700207#define BFA_FCS_FABRIC_RETRY_DELAY (2000) /* Milliseconds */
208#define BFA_FCS_FABRIC_CLEANUP_DELAY (10000) /* Milliseconds */
209
210#define bfa_fcs_fabric_set_opertype(__fabric) do { \
Krishna Gudipatid7be54c2011-06-24 20:24:52 -0700211 if (bfa_fcport_get_topology((__fabric)->fcs->bfa) \
212 == BFA_PORT_TOPOLOGY_P2P) { \
213 if (fabric->fab_type == BFA_FCS_FABRIC_SWITCHED) \
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700214 (__fabric)->oper_type = BFA_PORT_TYPE_NPORT; \
215 else \
Krishna Gudipatid7be54c2011-06-24 20:24:52 -0700216 (__fabric)->oper_type = BFA_PORT_TYPE_P2P; \
217 } else \
218 (__fabric)->oper_type = BFA_PORT_TYPE_NLPORT; \
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700219} while (0)
220
221/*
222 * forward declarations
223 */
224static void bfa_fcs_fabric_init(struct bfa_fcs_fabric_s *fabric);
225static void bfa_fcs_fabric_login(struct bfa_fcs_fabric_s *fabric);
226static void bfa_fcs_fabric_notify_online(struct bfa_fcs_fabric_s *fabric);
227static void bfa_fcs_fabric_notify_offline(struct bfa_fcs_fabric_s *fabric);
228static void bfa_fcs_fabric_delay(void *cbarg);
229static void bfa_fcs_fabric_delete(struct bfa_fcs_fabric_s *fabric);
230static void bfa_fcs_fabric_delete_comp(void *cbarg);
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700231static void bfa_fcs_fabric_stop(struct bfa_fcs_fabric_s *fabric);
232static void bfa_fcs_fabric_stop_comp(void *cbarg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700233static void bfa_fcs_fabric_process_uf(struct bfa_fcs_fabric_s *fabric,
234 struct fchs_s *fchs, u16 len);
235static void bfa_fcs_fabric_process_flogi(struct bfa_fcs_fabric_s *fabric,
236 struct fchs_s *fchs, u16 len);
237static void bfa_fcs_fabric_send_flogi_acc(struct bfa_fcs_fabric_s *fabric);
238static void bfa_fcs_fabric_flogiacc_comp(void *fcsarg,
239 struct bfa_fcxp_s *fcxp, void *cbarg,
240 bfa_status_t status,
241 u32 rsp_len,
242 u32 resid_len,
243 struct fchs_s *rspfchs);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700244
245static void bfa_fcs_fabric_sm_uninit(struct bfa_fcs_fabric_s *fabric,
246 enum bfa_fcs_fabric_event event);
247static void bfa_fcs_fabric_sm_created(struct bfa_fcs_fabric_s *fabric,
248 enum bfa_fcs_fabric_event event);
249static void bfa_fcs_fabric_sm_linkdown(struct bfa_fcs_fabric_s *fabric,
250 enum bfa_fcs_fabric_event event);
251static void bfa_fcs_fabric_sm_flogi(struct bfa_fcs_fabric_s *fabric,
252 enum bfa_fcs_fabric_event event);
253static void bfa_fcs_fabric_sm_flogi_retry(struct bfa_fcs_fabric_s *fabric,
254 enum bfa_fcs_fabric_event event);
255static void bfa_fcs_fabric_sm_auth(struct bfa_fcs_fabric_s *fabric,
256 enum bfa_fcs_fabric_event event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700257static void bfa_fcs_fabric_sm_nofabric(struct bfa_fcs_fabric_s *fabric,
258 enum bfa_fcs_fabric_event event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700259static void bfa_fcs_fabric_sm_evfp(struct bfa_fcs_fabric_s *fabric,
260 enum bfa_fcs_fabric_event event);
261static void bfa_fcs_fabric_sm_evfp_done(struct bfa_fcs_fabric_s *fabric,
262 enum bfa_fcs_fabric_event event);
263static void bfa_fcs_fabric_sm_isolated(struct bfa_fcs_fabric_s *fabric,
264 enum bfa_fcs_fabric_event event);
265static void bfa_fcs_fabric_sm_deleting(struct bfa_fcs_fabric_s *fabric,
266 enum bfa_fcs_fabric_event event);
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700267static void bfa_fcs_fabric_sm_stopping(struct bfa_fcs_fabric_s *fabric,
268 enum bfa_fcs_fabric_event event);
269static void bfa_fcs_fabric_sm_cleanup(struct bfa_fcs_fabric_s *fabric,
270 enum bfa_fcs_fabric_event event);
Jing Huang5fbe25c2010-10-18 17:17:23 -0700271/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700272 * Beginning state before fabric creation.
273 */
274static void
275bfa_fcs_fabric_sm_uninit(struct bfa_fcs_fabric_s *fabric,
276 enum bfa_fcs_fabric_event event)
277{
278 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
279 bfa_trc(fabric->fcs, event);
280
281 switch (event) {
282 case BFA_FCS_FABRIC_SM_CREATE:
283 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_created);
284 bfa_fcs_fabric_init(fabric);
285 bfa_fcs_lport_init(&fabric->bport, &fabric->bport.port_cfg);
286 break;
287
288 case BFA_FCS_FABRIC_SM_LINK_UP:
289 case BFA_FCS_FABRIC_SM_LINK_DOWN:
290 break;
291
292 default:
293 bfa_sm_fault(fabric->fcs, event);
294 }
295}
296
Jing Huang5fbe25c2010-10-18 17:17:23 -0700297/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700298 * Beginning state before fabric creation.
299 */
300static void
301bfa_fcs_fabric_sm_created(struct bfa_fcs_fabric_s *fabric,
302 enum bfa_fcs_fabric_event event)
303{
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -0700304 struct bfa_s *bfa = fabric->fcs->bfa;
305
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700306 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:
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -0700311 if (!bfa_fcport_is_linkup(fabric->fcs->bfa)) {
312 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
313 break;
314 }
315 if (bfa_fcport_get_topology(bfa) ==
316 BFA_PORT_TOPOLOGY_LOOP) {
317 fabric->fab_type = BFA_FCS_FABRIC_LOOP;
318 fabric->bport.pid = bfa_fcport_get_myalpa(bfa);
319 fabric->bport.pid = bfa_hton3b(fabric->bport.pid);
320 bfa_sm_set_state(fabric,
321 bfa_fcs_fabric_sm_online);
322 bfa_fcs_fabric_set_opertype(fabric);
323 bfa_fcs_lport_online(&fabric->bport);
324 } else {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700325 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_flogi);
326 bfa_fcs_fabric_login(fabric);
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -0700327 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700328 break;
329
330 case BFA_FCS_FABRIC_SM_LINK_UP:
331 case BFA_FCS_FABRIC_SM_LINK_DOWN:
332 break;
333
334 case BFA_FCS_FABRIC_SM_DELETE:
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -0700335 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
336 bfa_fcs_fabric_delete(fabric);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700337 break;
338
339 default:
340 bfa_sm_fault(fabric->fcs, event);
341 }
342}
343
Jing Huang5fbe25c2010-10-18 17:17:23 -0700344/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700345 * Link is down, awaiting LINK UP event from port. This is also the
346 * first state at fabric creation.
347 */
348static void
349bfa_fcs_fabric_sm_linkdown(struct bfa_fcs_fabric_s *fabric,
350 enum bfa_fcs_fabric_event event)
351{
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -0700352 struct bfa_s *bfa = fabric->fcs->bfa;
353
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700354 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
355 bfa_trc(fabric->fcs, event);
356
357 switch (event) {
358 case BFA_FCS_FABRIC_SM_LINK_UP:
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -0700359 if (bfa_fcport_get_topology(bfa) != BFA_PORT_TOPOLOGY_LOOP) {
360 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_flogi);
361 bfa_fcs_fabric_login(fabric);
362 break;
363 }
364 fabric->fab_type = BFA_FCS_FABRIC_LOOP;
365 fabric->bport.pid = bfa_fcport_get_myalpa(bfa);
366 fabric->bport.pid = bfa_hton3b(fabric->bport.pid);
367 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_online);
368 bfa_fcs_fabric_set_opertype(fabric);
369 bfa_fcs_lport_online(&fabric->bport);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700370 break;
371
372 case BFA_FCS_FABRIC_SM_RETRY_OP:
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -0700373 case BFA_FCS_FABRIC_SM_LOOPBACK:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700374 break;
375
376 case BFA_FCS_FABRIC_SM_DELETE:
377 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
378 bfa_fcs_fabric_delete(fabric);
379 break;
380
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700381 case BFA_FCS_FABRIC_SM_STOP:
382 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_cleanup);
383 bfa_fcs_fabric_stop(fabric);
384 break;
385
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700386 default:
387 bfa_sm_fault(fabric->fcs, event);
388 }
389}
390
Jing Huang5fbe25c2010-10-18 17:17:23 -0700391/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700392 * FLOGI is in progress, awaiting FLOGI reply.
393 */
394static void
395bfa_fcs_fabric_sm_flogi(struct bfa_fcs_fabric_s *fabric,
396 enum bfa_fcs_fabric_event event)
397{
398 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
399 bfa_trc(fabric->fcs, event);
400
401 switch (event) {
402 case BFA_FCS_FABRIC_SM_CONT_OP:
403
404 bfa_fcport_set_tx_bbcredit(fabric->fcs->bfa,
Vijaya Mohan Guvvabbe37a62013-05-13 02:33:19 -0700405 fabric->bb_credit);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700406 fabric->fab_type = BFA_FCS_FABRIC_SWITCHED;
407
408 if (fabric->auth_reqd && fabric->is_auth) {
409 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_auth);
410 bfa_trc(fabric->fcs, event);
411 } else {
412 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_online);
413 bfa_fcs_fabric_notify_online(fabric);
414 }
415 break;
416
417 case BFA_FCS_FABRIC_SM_RETRY_OP:
418 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_flogi_retry);
419 bfa_timer_start(fabric->fcs->bfa, &fabric->delay_timer,
420 bfa_fcs_fabric_delay, fabric,
421 BFA_FCS_FABRIC_RETRY_DELAY);
422 break;
423
424 case BFA_FCS_FABRIC_SM_LOOPBACK:
425 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_loopback);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800426 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700427 bfa_fcs_fabric_set_opertype(fabric);
428 break;
429
430 case BFA_FCS_FABRIC_SM_NO_FABRIC:
431 fabric->fab_type = BFA_FCS_FABRIC_N2N;
432 bfa_fcport_set_tx_bbcredit(fabric->fcs->bfa,
Vijaya Mohan Guvvabbe37a62013-05-13 02:33:19 -0700433 fabric->bb_credit);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700434 bfa_fcs_fabric_notify_online(fabric);
435 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_nofabric);
436 break;
437
438 case BFA_FCS_FABRIC_SM_LINK_DOWN:
439 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800440 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700441 break;
442
443 case BFA_FCS_FABRIC_SM_DELETE:
444 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800445 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700446 bfa_fcs_fabric_delete(fabric);
447 break;
448
449 default:
450 bfa_sm_fault(fabric->fcs, event);
451 }
452}
453
454
455static void
456bfa_fcs_fabric_sm_flogi_retry(struct bfa_fcs_fabric_s *fabric,
457 enum bfa_fcs_fabric_event event)
458{
459 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
460 bfa_trc(fabric->fcs, event);
461
462 switch (event) {
463 case BFA_FCS_FABRIC_SM_DELAYED:
464 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_flogi);
465 bfa_fcs_fabric_login(fabric);
466 break;
467
468 case BFA_FCS_FABRIC_SM_LINK_DOWN:
469 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
470 bfa_timer_stop(&fabric->delay_timer);
471 break;
472
473 case BFA_FCS_FABRIC_SM_DELETE:
474 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
475 bfa_timer_stop(&fabric->delay_timer);
476 bfa_fcs_fabric_delete(fabric);
477 break;
478
479 default:
480 bfa_sm_fault(fabric->fcs, event);
481 }
482}
483
Jing Huang5fbe25c2010-10-18 17:17:23 -0700484/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700485 * Authentication is in progress, awaiting authentication results.
486 */
487static void
488bfa_fcs_fabric_sm_auth(struct bfa_fcs_fabric_s *fabric,
489 enum bfa_fcs_fabric_event event)
490{
491 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
492 bfa_trc(fabric->fcs, event);
493
494 switch (event) {
495 case BFA_FCS_FABRIC_SM_AUTH_FAILED:
496 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_auth_failed);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800497 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700498 break;
499
500 case BFA_FCS_FABRIC_SM_AUTH_SUCCESS:
501 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_online);
502 bfa_fcs_fabric_notify_online(fabric);
503 break;
504
505 case BFA_FCS_FABRIC_SM_PERF_EVFP:
506 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_evfp);
507 break;
508
509 case BFA_FCS_FABRIC_SM_LINK_DOWN:
510 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800511 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700512 break;
513
514 case BFA_FCS_FABRIC_SM_DELETE:
515 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
516 bfa_fcs_fabric_delete(fabric);
517 break;
518
519 default:
520 bfa_sm_fault(fabric->fcs, event);
521 }
522}
523
Jing Huang5fbe25c2010-10-18 17:17:23 -0700524/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700525 * Authentication failed
526 */
Maggie Zhangf7f738122010-12-09 19:08:43 -0800527void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700528bfa_fcs_fabric_sm_auth_failed(struct bfa_fcs_fabric_s *fabric,
529 enum bfa_fcs_fabric_event event)
530{
531 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
532 bfa_trc(fabric->fcs, event);
533
534 switch (event) {
535 case BFA_FCS_FABRIC_SM_LINK_DOWN:
536 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
537 bfa_fcs_fabric_notify_offline(fabric);
538 break;
539
540 case BFA_FCS_FABRIC_SM_DELETE:
541 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
542 bfa_fcs_fabric_delete(fabric);
543 break;
544
545 default:
546 bfa_sm_fault(fabric->fcs, event);
547 }
548}
549
Jing Huang5fbe25c2010-10-18 17:17:23 -0700550/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700551 * Port is in loopback mode.
552 */
Maggie Zhangf7f738122010-12-09 19:08:43 -0800553void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700554bfa_fcs_fabric_sm_loopback(struct bfa_fcs_fabric_s *fabric,
555 enum bfa_fcs_fabric_event event)
556{
557 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
558 bfa_trc(fabric->fcs, event);
559
560 switch (event) {
561 case BFA_FCS_FABRIC_SM_LINK_DOWN:
562 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
563 bfa_fcs_fabric_notify_offline(fabric);
564 break;
565
566 case BFA_FCS_FABRIC_SM_DELETE:
567 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
568 bfa_fcs_fabric_delete(fabric);
569 break;
570
571 default:
572 bfa_sm_fault(fabric->fcs, event);
573 }
574}
575
Jing Huang5fbe25c2010-10-18 17:17:23 -0700576/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700577 * There is no attached fabric - private loop or NPort-to-NPort topology.
578 */
579static void
580bfa_fcs_fabric_sm_nofabric(struct bfa_fcs_fabric_s *fabric,
581 enum bfa_fcs_fabric_event event)
582{
583 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
584 bfa_trc(fabric->fcs, event);
585
586 switch (event) {
587 case BFA_FCS_FABRIC_SM_LINK_DOWN:
588 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800589 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700590 bfa_fcs_fabric_notify_offline(fabric);
591 break;
592
593 case BFA_FCS_FABRIC_SM_DELETE:
594 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
595 bfa_fcs_fabric_delete(fabric);
596 break;
597
598 case BFA_FCS_FABRIC_SM_NO_FABRIC:
599 bfa_trc(fabric->fcs, fabric->bb_credit);
600 bfa_fcport_set_tx_bbcredit(fabric->fcs->bfa,
Vijaya Mohan Guvvabbe37a62013-05-13 02:33:19 -0700601 fabric->bb_credit);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700602 break;
603
Krishna Gudipatid7be54c2011-06-24 20:24:52 -0700604 case BFA_FCS_FABRIC_SM_RETRY_OP:
605 break;
606
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700607 default:
608 bfa_sm_fault(fabric->fcs, event);
609 }
610}
611
Jing Huang5fbe25c2010-10-18 17:17:23 -0700612/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700613 * Fabric is online - normal operating state.
614 */
Maggie Zhangf7f738122010-12-09 19:08:43 -0800615void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700616bfa_fcs_fabric_sm_online(struct bfa_fcs_fabric_s *fabric,
617 enum bfa_fcs_fabric_event event)
618{
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -0700619 struct bfa_s *bfa = fabric->fcs->bfa;
620
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700621 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
622 bfa_trc(fabric->fcs, event);
623
624 switch (event) {
625 case BFA_FCS_FABRIC_SM_LINK_DOWN:
626 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -0700627 if (bfa_fcport_get_topology(bfa) == BFA_PORT_TOPOLOGY_LOOP) {
628 bfa_fcs_lport_offline(&fabric->bport);
629 } else {
630 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
631 bfa_fcs_fabric_notify_offline(fabric);
632 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700633 break;
634
635 case BFA_FCS_FABRIC_SM_DELETE:
636 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
637 bfa_fcs_fabric_delete(fabric);
638 break;
639
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700640 case BFA_FCS_FABRIC_SM_STOP:
641 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_stopping);
642 bfa_fcs_fabric_stop(fabric);
643 break;
644
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700645 case BFA_FCS_FABRIC_SM_AUTH_FAILED:
646 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_auth_failed);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800647 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700648 break;
649
650 case BFA_FCS_FABRIC_SM_AUTH_SUCCESS:
651 break;
652
653 default:
654 bfa_sm_fault(fabric->fcs, event);
655 }
656}
657
Jing Huang5fbe25c2010-10-18 17:17:23 -0700658/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700659 * Exchanging virtual fabric parameters.
660 */
661static void
662bfa_fcs_fabric_sm_evfp(struct bfa_fcs_fabric_s *fabric,
663 enum bfa_fcs_fabric_event event)
664{
665 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
666 bfa_trc(fabric->fcs, event);
667
668 switch (event) {
669 case BFA_FCS_FABRIC_SM_CONT_OP:
670 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_evfp_done);
671 break;
672
673 case BFA_FCS_FABRIC_SM_ISOLATE:
674 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_isolated);
675 break;
676
677 default:
678 bfa_sm_fault(fabric->fcs, event);
679 }
680}
681
Jing Huang5fbe25c2010-10-18 17:17:23 -0700682/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700683 * EVFP exchange complete and VFT tagging is enabled.
684 */
685static void
686bfa_fcs_fabric_sm_evfp_done(struct bfa_fcs_fabric_s *fabric,
687 enum bfa_fcs_fabric_event event)
688{
689 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
690 bfa_trc(fabric->fcs, event);
691}
692
Jing Huang5fbe25c2010-10-18 17:17:23 -0700693/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700694 * Port is isolated after EVFP exchange due to VF_ID mismatch (N and F).
695 */
696static void
697bfa_fcs_fabric_sm_isolated(struct bfa_fcs_fabric_s *fabric,
698 enum bfa_fcs_fabric_event event)
699{
700 struct bfad_s *bfad = (struct bfad_s *)fabric->fcs->bfad;
701 char pwwn_ptr[BFA_STRING_32];
702
703 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
704 bfa_trc(fabric->fcs, event);
705 wwn2str(pwwn_ptr, fabric->bport.port_cfg.pwwn);
706
Jing Huang88166242010-12-09 17:11:53 -0800707 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700708 "Port is isolated due to VF_ID mismatch. "
709 "PWWN: %s Port VF_ID: %04x switch port VF_ID: %04x.",
710 pwwn_ptr, fabric->fcs->port_vfid,
711 fabric->event_arg.swp_vfid);
712}
713
Jing Huang5fbe25c2010-10-18 17:17:23 -0700714/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700715 * Fabric is being deleted, awaiting vport delete completions.
716 */
717static void
718bfa_fcs_fabric_sm_deleting(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);
723
724 switch (event) {
725 case BFA_FCS_FABRIC_SM_DELCOMP:
726 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_uninit);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800727 bfa_wc_down(&fabric->fcs->wc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700728 break;
729
730 case BFA_FCS_FABRIC_SM_LINK_UP:
731 break;
732
733 case BFA_FCS_FABRIC_SM_LINK_DOWN:
734 bfa_fcs_fabric_notify_offline(fabric);
735 break;
736
737 default:
738 bfa_sm_fault(fabric->fcs, event);
739 }
740}
741
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700742/*
743 * Fabric is being stopped, awaiting vport stop completions.
744 */
745static void
746bfa_fcs_fabric_sm_stopping(struct bfa_fcs_fabric_s *fabric,
747 enum bfa_fcs_fabric_event event)
748{
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -0700749 struct bfa_s *bfa = fabric->fcs->bfa;
750
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700751 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
752 bfa_trc(fabric->fcs, event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700753
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700754 switch (event) {
755 case BFA_FCS_FABRIC_SM_STOPCOMP:
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -0700756 if (bfa_fcport_get_topology(bfa) == BFA_PORT_TOPOLOGY_LOOP) {
757 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_created);
758 } else {
759 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_cleanup);
760 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_LOGOUT);
761 }
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700762 break;
763
764 case BFA_FCS_FABRIC_SM_LINK_UP:
765 break;
766
767 case BFA_FCS_FABRIC_SM_LINK_DOWN:
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -0700768 if (bfa_fcport_get_topology(bfa) == BFA_PORT_TOPOLOGY_LOOP)
769 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_created);
770 else
771 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_cleanup);
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700772 break;
773
774 default:
775 bfa_sm_fault(fabric->fcs, event);
776 }
777}
778
779/*
780 * Fabric is being stopped, cleanup without FLOGO
781 */
782static void
783bfa_fcs_fabric_sm_cleanup(struct bfa_fcs_fabric_s *fabric,
784 enum bfa_fcs_fabric_event event)
785{
786 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
787 bfa_trc(fabric->fcs, event);
788
789 switch (event) {
790 case BFA_FCS_FABRIC_SM_STOPCOMP:
791 case BFA_FCS_FABRIC_SM_LOGOCOMP:
792 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_created);
793 bfa_wc_down(&(fabric->fcs)->wc);
794 break;
795
796 case BFA_FCS_FABRIC_SM_LINK_DOWN:
797 /*
798 * Ignore - can get this event if we get notified about IOC down
799 * before the fabric completion callbk is done.
800 */
801 break;
802
803 default:
804 bfa_sm_fault(fabric->fcs, event);
805 }
806}
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700807
Jing Huang5fbe25c2010-10-18 17:17:23 -0700808/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700809 * fcs_fabric_private fabric private functions
810 */
811
812static void
813bfa_fcs_fabric_init(struct bfa_fcs_fabric_s *fabric)
814{
815 struct bfa_lport_cfg_s *port_cfg = &fabric->bport.port_cfg;
816
817 port_cfg->roles = BFA_LPORT_ROLE_FCP_IM;
Maggie Zhangf7f738122010-12-09 19:08:43 -0800818 port_cfg->nwwn = fabric->fcs->bfa->ioc.attr->nwwn;
819 port_cfg->pwwn = fabric->fcs->bfa->ioc.attr->pwwn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700820}
821
Jing Huang5fbe25c2010-10-18 17:17:23 -0700822/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700823 * Port Symbolic Name Creation for base port.
824 */
825void
826bfa_fcs_fabric_psymb_init(struct bfa_fcs_fabric_s *fabric)
827{
828 struct bfa_lport_cfg_s *port_cfg = &fabric->bport.port_cfg;
829 char model[BFA_ADAPTER_MODEL_NAME_LEN] = {0};
830 struct bfa_fcs_driver_info_s *driver_info = &fabric->fcs->driver_info;
831
832 bfa_ioc_get_adapter_model(&fabric->fcs->bfa->ioc, model);
833
834 /* Model name/number */
835 strncpy((char *)&port_cfg->sym_name, model,
836 BFA_FCS_PORT_SYMBNAME_MODEL_SZ);
837 strncat((char *)&port_cfg->sym_name, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
838 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
839
840 /* Driver Version */
841 strncat((char *)&port_cfg->sym_name, (char *)driver_info->version,
842 BFA_FCS_PORT_SYMBNAME_VERSION_SZ);
843 strncat((char *)&port_cfg->sym_name, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
844 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
845
846 /* Host machine name */
847 strncat((char *)&port_cfg->sym_name,
848 (char *)driver_info->host_machine_name,
849 BFA_FCS_PORT_SYMBNAME_MACHINENAME_SZ);
850 strncat((char *)&port_cfg->sym_name, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
851 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
852
853 /*
854 * Host OS Info :
855 * If OS Patch Info is not there, do not truncate any bytes from the
856 * OS name string and instead copy the entire OS info string (64 bytes).
857 */
858 if (driver_info->host_os_patch[0] == '\0') {
859 strncat((char *)&port_cfg->sym_name,
860 (char *)driver_info->host_os_name,
861 BFA_FCS_OS_STR_LEN);
862 strncat((char *)&port_cfg->sym_name,
863 BFA_FCS_PORT_SYMBNAME_SEPARATOR,
864 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
865 } else {
866 strncat((char *)&port_cfg->sym_name,
867 (char *)driver_info->host_os_name,
868 BFA_FCS_PORT_SYMBNAME_OSINFO_SZ);
869 strncat((char *)&port_cfg->sym_name,
870 BFA_FCS_PORT_SYMBNAME_SEPARATOR,
871 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
872
873 /* Append host OS Patch Info */
874 strncat((char *)&port_cfg->sym_name,
875 (char *)driver_info->host_os_patch,
876 BFA_FCS_PORT_SYMBNAME_OSPATCH_SZ);
877 }
878
879 /* null terminate */
880 port_cfg->sym_name.symname[BFA_SYMNAME_MAXLEN - 1] = 0;
881}
882
Jing Huang5fbe25c2010-10-18 17:17:23 -0700883/*
Krishna Gudipatice7242b2012-08-22 19:52:43 -0700884 * Node Symbolic Name Creation for base port and all vports
885 */
886void
887bfa_fcs_fabric_nsymb_init(struct bfa_fcs_fabric_s *fabric)
888{
889 struct bfa_lport_cfg_s *port_cfg = &fabric->bport.port_cfg;
890 char model[BFA_ADAPTER_MODEL_NAME_LEN] = {0};
891 struct bfa_fcs_driver_info_s *driver_info = &fabric->fcs->driver_info;
892
893 bfa_ioc_get_adapter_model(&fabric->fcs->bfa->ioc, model);
894
895 /* Model name/number */
896 strncpy((char *)&port_cfg->node_sym_name, model,
897 BFA_FCS_PORT_SYMBNAME_MODEL_SZ);
898 strncat((char *)&port_cfg->node_sym_name,
899 BFA_FCS_PORT_SYMBNAME_SEPARATOR,
900 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
901
902 /* Driver Version */
903 strncat((char *)&port_cfg->node_sym_name, (char *)driver_info->version,
904 BFA_FCS_PORT_SYMBNAME_VERSION_SZ);
905 strncat((char *)&port_cfg->node_sym_name,
906 BFA_FCS_PORT_SYMBNAME_SEPARATOR,
907 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
908
909 /* Host machine name */
910 strncat((char *)&port_cfg->node_sym_name,
911 (char *)driver_info->host_machine_name,
912 BFA_FCS_PORT_SYMBNAME_MACHINENAME_SZ);
913 strncat((char *)&port_cfg->node_sym_name,
914 BFA_FCS_PORT_SYMBNAME_SEPARATOR,
915 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
916
917 /* null terminate */
918 port_cfg->node_sym_name.symname[BFA_SYMNAME_MAXLEN - 1] = 0;
919}
920
921/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700922 * bfa lps login completion callback
923 */
924void
925bfa_cb_lps_flogi_comp(void *bfad, void *uarg, bfa_status_t status)
926{
927 struct bfa_fcs_fabric_s *fabric = uarg;
928
929 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
930 bfa_trc(fabric->fcs, status);
931
932 switch (status) {
933 case BFA_STATUS_OK:
934 fabric->stats.flogi_accepts++;
935 break;
936
937 case BFA_STATUS_INVALID_MAC:
938 /* Only for CNA */
939 fabric->stats.flogi_acc_err++;
940 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_RETRY_OP);
941
942 return;
943
944 case BFA_STATUS_EPROTOCOL:
Maggie Zhangf7f738122010-12-09 19:08:43 -0800945 switch (fabric->lps->ext_status) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700946 case BFA_EPROTO_BAD_ACCEPT:
947 fabric->stats.flogi_acc_err++;
948 break;
949
950 case BFA_EPROTO_UNKNOWN_RSP:
951 fabric->stats.flogi_unknown_rsp++;
952 break;
953
954 default:
955 break;
956 }
957 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_RETRY_OP);
958
959 return;
960
961 case BFA_STATUS_FABRIC_RJT:
962 fabric->stats.flogi_rejects++;
963 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_RETRY_OP);
964 return;
965
966 default:
967 fabric->stats.flogi_rsp_err++;
968 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_RETRY_OP);
969 return;
970 }
971
Maggie Zhangf7f738122010-12-09 19:08:43 -0800972 fabric->bb_credit = fabric->lps->pr_bbcred;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700973 bfa_trc(fabric->fcs, fabric->bb_credit);
974
Maggie Zhangf7f738122010-12-09 19:08:43 -0800975 if (!(fabric->lps->brcd_switch))
976 fabric->fabric_name = fabric->lps->pr_nwwn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700977
978 /*
979 * Check port type. It should be 1 = F-port.
980 */
Maggie Zhangf7f738122010-12-09 19:08:43 -0800981 if (fabric->lps->fport) {
982 fabric->bport.pid = fabric->lps->lp_pid;
983 fabric->is_npiv = fabric->lps->npiv_en;
984 fabric->is_auth = fabric->lps->auth_req;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700985 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_CONT_OP);
986 } else {
987 /*
988 * Nport-2-Nport direct attached
989 */
990 fabric->bport.port_topo.pn2n.rem_port_wwn =
Maggie Zhangf7f738122010-12-09 19:08:43 -0800991 fabric->lps->pr_pwwn;
Krishna Gudipatid7be54c2011-06-24 20:24:52 -0700992 fabric->fab_type = BFA_FCS_FABRIC_N2N;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700993 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_NO_FABRIC);
994 }
995
996 bfa_trc(fabric->fcs, fabric->bport.pid);
997 bfa_trc(fabric->fcs, fabric->is_npiv);
998 bfa_trc(fabric->fcs, fabric->is_auth);
999}
Jing Huang5fbe25c2010-10-18 17:17:23 -07001000/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001001 * Allocate and send FLOGI.
1002 */
1003static void
1004bfa_fcs_fabric_login(struct bfa_fcs_fabric_s *fabric)
1005{
1006 struct bfa_s *bfa = fabric->fcs->bfa;
1007 struct bfa_lport_cfg_s *pcfg = &fabric->bport.port_cfg;
Vijaya Mohan Guvvabbe37a62013-05-13 02:33:19 -07001008 u8 alpa = 0;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001009
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001010
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001011 bfa_lps_flogi(fabric->lps, fabric, alpa, bfa_fcport_get_maxfrsize(bfa),
Vijaya Mohan Guvvabbe37a62013-05-13 02:33:19 -07001012 pcfg->pwwn, pcfg->nwwn, fabric->auth_reqd);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001013
1014 fabric->stats.flogi_sent++;
1015}
1016
1017static void
1018bfa_fcs_fabric_notify_online(struct bfa_fcs_fabric_s *fabric)
1019{
1020 struct bfa_fcs_vport_s *vport;
1021 struct list_head *qe, *qen;
1022
1023 bfa_trc(fabric->fcs, fabric->fabric_name);
1024
1025 bfa_fcs_fabric_set_opertype(fabric);
1026 fabric->stats.fabric_onlines++;
1027
Jing Huang5fbe25c2010-10-18 17:17:23 -07001028 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001029 * notify online event to base and then virtual ports
1030 */
1031 bfa_fcs_lport_online(&fabric->bport);
1032
1033 list_for_each_safe(qe, qen, &fabric->vport_q) {
1034 vport = (struct bfa_fcs_vport_s *) qe;
1035 bfa_fcs_vport_online(vport);
1036 }
1037}
1038
1039static void
1040bfa_fcs_fabric_notify_offline(struct bfa_fcs_fabric_s *fabric)
1041{
1042 struct bfa_fcs_vport_s *vport;
1043 struct list_head *qe, *qen;
1044
1045 bfa_trc(fabric->fcs, fabric->fabric_name);
1046 fabric->stats.fabric_offlines++;
1047
Jing Huang5fbe25c2010-10-18 17:17:23 -07001048 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001049 * notify offline event first to vports and then base port.
1050 */
1051 list_for_each_safe(qe, qen, &fabric->vport_q) {
1052 vport = (struct bfa_fcs_vport_s *) qe;
1053 bfa_fcs_vport_offline(vport);
1054 }
1055
1056 bfa_fcs_lport_offline(&fabric->bport);
1057
1058 fabric->fabric_name = 0;
1059 fabric->fabric_ip_addr[0] = 0;
1060}
1061
1062static void
1063bfa_fcs_fabric_delay(void *cbarg)
1064{
1065 struct bfa_fcs_fabric_s *fabric = cbarg;
1066
1067 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_DELAYED);
1068}
1069
Jing Huang5fbe25c2010-10-18 17:17:23 -07001070/*
Krishna Gudipati881c1b32012-08-22 19:52:02 -07001071 * Stop all vports and wait for vport stop completions.
1072 */
1073static void
1074bfa_fcs_fabric_stop(struct bfa_fcs_fabric_s *fabric)
1075{
1076 struct bfa_fcs_vport_s *vport;
1077 struct list_head *qe, *qen;
1078
1079 bfa_wc_init(&fabric->stop_wc, bfa_fcs_fabric_stop_comp, fabric);
1080
1081 list_for_each_safe(qe, qen, &fabric->vport_q) {
1082 vport = (struct bfa_fcs_vport_s *) qe;
1083 bfa_wc_up(&fabric->stop_wc);
1084 bfa_fcs_vport_fcs_stop(vport);
1085 }
1086
1087 bfa_wc_up(&fabric->stop_wc);
1088 bfa_fcs_lport_stop(&fabric->bport);
1089 bfa_wc_wait(&fabric->stop_wc);
1090}
1091
1092/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001093 * Delete all vports and wait for vport delete completions.
1094 */
1095static void
1096bfa_fcs_fabric_delete(struct bfa_fcs_fabric_s *fabric)
1097{
1098 struct bfa_fcs_vport_s *vport;
1099 struct list_head *qe, *qen;
1100
1101 list_for_each_safe(qe, qen, &fabric->vport_q) {
1102 vport = (struct bfa_fcs_vport_s *) qe;
1103 bfa_fcs_vport_fcs_delete(vport);
1104 }
1105
1106 bfa_fcs_lport_delete(&fabric->bport);
1107 bfa_wc_wait(&fabric->wc);
1108}
1109
1110static void
1111bfa_fcs_fabric_delete_comp(void *cbarg)
1112{
1113 struct bfa_fcs_fabric_s *fabric = cbarg;
1114
1115 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_DELCOMP);
1116}
1117
Krishna Gudipati881c1b32012-08-22 19:52:02 -07001118static void
1119bfa_fcs_fabric_stop_comp(void *cbarg)
1120{
1121 struct bfa_fcs_fabric_s *fabric = cbarg;
1122
1123 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_STOPCOMP);
1124}
1125
Jing Huang5fbe25c2010-10-18 17:17:23 -07001126/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001127 * fcs_fabric_public fabric public functions
1128 */
1129
Jing Huang5fbe25c2010-10-18 17:17:23 -07001130/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001131 * Attach time initialization.
1132 */
1133void
1134bfa_fcs_fabric_attach(struct bfa_fcs_s *fcs)
1135{
1136 struct bfa_fcs_fabric_s *fabric;
1137
1138 fabric = &fcs->fabric;
Jing Huang6a18b162010-10-18 17:08:54 -07001139 memset(fabric, 0, sizeof(struct bfa_fcs_fabric_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001140
Jing Huang5fbe25c2010-10-18 17:17:23 -07001141 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001142 * Initialize base fabric.
1143 */
1144 fabric->fcs = fcs;
1145 INIT_LIST_HEAD(&fabric->vport_q);
1146 INIT_LIST_HEAD(&fabric->vf_q);
1147 fabric->lps = bfa_lps_alloc(fcs->bfa);
Jing Huangd4b671c2010-12-26 21:46:35 -08001148 WARN_ON(!fabric->lps);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001149
Jing Huang5fbe25c2010-10-18 17:17:23 -07001150 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001151 * Initialize fabric delete completion handler. Fabric deletion is
1152 * complete when the last vport delete is complete.
1153 */
1154 bfa_wc_init(&fabric->wc, bfa_fcs_fabric_delete_comp, fabric);
1155 bfa_wc_up(&fabric->wc); /* For the base port */
1156
1157 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_uninit);
1158 bfa_fcs_lport_attach(&fabric->bport, fabric->fcs, FC_VF_ID_NULL, NULL);
1159}
1160
1161void
1162bfa_fcs_fabric_modinit(struct bfa_fcs_s *fcs)
1163{
1164 bfa_sm_send_event(&fcs->fabric, BFA_FCS_FABRIC_SM_CREATE);
1165 bfa_trc(fcs, 0);
1166}
1167
Jing Huang5fbe25c2010-10-18 17:17:23 -07001168/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001169 * Module cleanup
1170 */
1171void
1172bfa_fcs_fabric_modexit(struct bfa_fcs_s *fcs)
1173{
1174 struct bfa_fcs_fabric_s *fabric;
1175
1176 bfa_trc(fcs, 0);
1177
Jing Huang5fbe25c2010-10-18 17:17:23 -07001178 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001179 * Cleanup base fabric.
1180 */
1181 fabric = &fcs->fabric;
1182 bfa_lps_delete(fabric->lps);
1183 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_DELETE);
1184}
1185
Jing Huang5fbe25c2010-10-18 17:17:23 -07001186/*
Krishna Gudipati881c1b32012-08-22 19:52:02 -07001187 * Fabric module stop -- stop FCS actions
1188 */
1189void
1190bfa_fcs_fabric_modstop(struct bfa_fcs_s *fcs)
1191{
1192 struct bfa_fcs_fabric_s *fabric;
1193
1194 bfa_trc(fcs, 0);
1195 fabric = &fcs->fabric;
1196 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_STOP);
1197}
1198
1199/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001200 * Fabric module start -- kick starts FCS actions
1201 */
1202void
1203bfa_fcs_fabric_modstart(struct bfa_fcs_s *fcs)
1204{
1205 struct bfa_fcs_fabric_s *fabric;
1206
1207 bfa_trc(fcs, 0);
1208 fabric = &fcs->fabric;
1209 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_START);
1210}
1211
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001212
Jing Huang5fbe25c2010-10-18 17:17:23 -07001213/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001214 * Link up notification from BFA physical port module.
1215 */
1216void
1217bfa_fcs_fabric_link_up(struct bfa_fcs_fabric_s *fabric)
1218{
1219 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
1220 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_LINK_UP);
1221}
1222
Jing Huang5fbe25c2010-10-18 17:17:23 -07001223/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001224 * Link down notification from BFA physical port module.
1225 */
1226void
1227bfa_fcs_fabric_link_down(struct bfa_fcs_fabric_s *fabric)
1228{
1229 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
1230 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_LINK_DOWN);
1231}
1232
Jing Huang5fbe25c2010-10-18 17:17:23 -07001233/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001234 * A child vport is being created in the fabric.
1235 *
1236 * Call from vport module at vport creation. A list of base port and vports
1237 * belonging to a fabric is maintained to propagate link events.
1238 *
1239 * param[in] fabric - Fabric instance. This can be a base fabric or vf.
1240 * param[in] vport - Vport being created.
1241 *
1242 * @return None (always succeeds)
1243 */
1244void
1245bfa_fcs_fabric_addvport(struct bfa_fcs_fabric_s *fabric,
1246 struct bfa_fcs_vport_s *vport)
1247{
Jing Huang5fbe25c2010-10-18 17:17:23 -07001248 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001249 * - add vport to fabric's vport_q
1250 */
1251 bfa_trc(fabric->fcs, fabric->vf_id);
1252
1253 list_add_tail(&vport->qe, &fabric->vport_q);
1254 fabric->num_vports++;
1255 bfa_wc_up(&fabric->wc);
1256}
1257
Jing Huang5fbe25c2010-10-18 17:17:23 -07001258/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001259 * A child vport is being deleted from fabric.
1260 *
1261 * Vport is being deleted.
1262 */
1263void
1264bfa_fcs_fabric_delvport(struct bfa_fcs_fabric_s *fabric,
1265 struct bfa_fcs_vport_s *vport)
1266{
1267 list_del(&vport->qe);
1268 fabric->num_vports--;
1269 bfa_wc_down(&fabric->wc);
1270}
1271
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001272
Jing Huang5fbe25c2010-10-18 17:17:23 -07001273/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001274 * Lookup for a vport within a fabric given its pwwn
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001275 */
1276struct bfa_fcs_vport_s *
1277bfa_fcs_fabric_vport_lookup(struct bfa_fcs_fabric_s *fabric, wwn_t pwwn)
1278{
1279 struct bfa_fcs_vport_s *vport;
1280 struct list_head *qe;
1281
1282 list_for_each(qe, &fabric->vport_q) {
1283 vport = (struct bfa_fcs_vport_s *) qe;
1284 if (bfa_fcs_lport_get_pwwn(&vport->lport) == pwwn)
1285 return vport;
1286 }
1287
1288 return NULL;
1289}
1290
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001291
1292/*
1293 * Get OUI of the attached switch.
1294 *
1295 * Note : Use of this function should be avoided as much as possible.
1296 * This function should be used only if there is any requirement
1297* to check for FOS version below 6.3.
1298 * To check if the attached fabric is a brocade fabric, use
1299 * bfa_lps_is_brcd_fabric() which works for FOS versions 6.3
1300 * or above only.
1301 */
1302
1303u16
1304bfa_fcs_fabric_get_switch_oui(struct bfa_fcs_fabric_s *fabric)
1305{
1306 wwn_t fab_nwwn;
1307 u8 *tmp;
1308 u16 oui;
1309
Maggie Zhangf7f738122010-12-09 19:08:43 -08001310 fab_nwwn = fabric->lps->pr_nwwn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001311
1312 tmp = (u8 *)&fab_nwwn;
1313 oui = (tmp[3] << 8) | tmp[4];
1314
1315 return oui;
1316}
Jing Huang5fbe25c2010-10-18 17:17:23 -07001317/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001318 * Unsolicited frame receive handling.
1319 */
1320void
1321bfa_fcs_fabric_uf_recv(struct bfa_fcs_fabric_s *fabric, struct fchs_s *fchs,
1322 u16 len)
1323{
1324 u32 pid = fchs->d_id;
1325 struct bfa_fcs_vport_s *vport;
1326 struct list_head *qe;
1327 struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
1328 struct fc_logi_s *flogi = (struct fc_logi_s *) els_cmd;
1329
1330 bfa_trc(fabric->fcs, len);
1331 bfa_trc(fabric->fcs, pid);
1332
Jing Huang5fbe25c2010-10-18 17:17:23 -07001333 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001334 * Look for our own FLOGI frames being looped back. This means an
1335 * external loopback cable is in place. Our own FLOGI frames are
1336 * sometimes looped back when switch port gets temporarily bypassed.
1337 */
Maggie Zhangf16a1752010-12-09 19:12:32 -08001338 if ((pid == bfa_ntoh3b(FC_FABRIC_PORT)) &&
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001339 (els_cmd->els_code == FC_ELS_FLOGI) &&
1340 (flogi->port_name == bfa_fcs_lport_get_pwwn(&fabric->bport))) {
1341 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_LOOPBACK);
1342 return;
1343 }
1344
Jing Huang5fbe25c2010-10-18 17:17:23 -07001345 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001346 * FLOGI/EVFP exchanges should be consumed by base fabric.
1347 */
Maggie Zhangf16a1752010-12-09 19:12:32 -08001348 if (fchs->d_id == bfa_hton3b(FC_FABRIC_PORT)) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001349 bfa_trc(fabric->fcs, pid);
1350 bfa_fcs_fabric_process_uf(fabric, fchs, len);
1351 return;
1352 }
1353
1354 if (fabric->bport.pid == pid) {
Jing Huang5fbe25c2010-10-18 17:17:23 -07001355 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001356 * All authentication frames should be routed to auth
1357 */
1358 bfa_trc(fabric->fcs, els_cmd->els_code);
1359 if (els_cmd->els_code == FC_ELS_AUTH) {
1360 bfa_trc(fabric->fcs, els_cmd->els_code);
1361 return;
1362 }
1363
1364 bfa_trc(fabric->fcs, *(u8 *) ((u8 *) fchs));
1365 bfa_fcs_lport_uf_recv(&fabric->bport, fchs, len);
1366 return;
1367 }
1368
Jing Huang5fbe25c2010-10-18 17:17:23 -07001369 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001370 * look for a matching local port ID
1371 */
1372 list_for_each(qe, &fabric->vport_q) {
1373 vport = (struct bfa_fcs_vport_s *) qe;
1374 if (vport->lport.pid == pid) {
1375 bfa_fcs_lport_uf_recv(&vport->lport, fchs, len);
1376 return;
1377 }
1378 }
Krishna Gudipati61ba4392012-08-22 19:52:58 -07001379
1380 if (!bfa_fcs_fabric_is_switched(fabric))
1381 bfa_fcs_lport_uf_recv(&fabric->bport, fchs, len);
1382
1383 bfa_trc(fabric->fcs, fchs->type);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001384}
1385
Jing Huang5fbe25c2010-10-18 17:17:23 -07001386/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001387 * Unsolicited frames to be processed by fabric.
1388 */
1389static void
1390bfa_fcs_fabric_process_uf(struct bfa_fcs_fabric_s *fabric, struct fchs_s *fchs,
1391 u16 len)
1392{
1393 struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
1394
1395 bfa_trc(fabric->fcs, els_cmd->els_code);
1396
1397 switch (els_cmd->els_code) {
1398 case FC_ELS_FLOGI:
1399 bfa_fcs_fabric_process_flogi(fabric, fchs, len);
1400 break;
1401
1402 default:
1403 /*
1404 * need to generate a LS_RJT
1405 */
1406 break;
1407 }
1408}
1409
Jing Huang5fbe25c2010-10-18 17:17:23 -07001410/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001411 * Process incoming FLOGI
1412 */
1413static void
1414bfa_fcs_fabric_process_flogi(struct bfa_fcs_fabric_s *fabric,
1415 struct fchs_s *fchs, u16 len)
1416{
1417 struct fc_logi_s *flogi = (struct fc_logi_s *) (fchs + 1);
1418 struct bfa_fcs_lport_s *bport = &fabric->bport;
1419
1420 bfa_trc(fabric->fcs, fchs->s_id);
1421
1422 fabric->stats.flogi_rcvd++;
1423 /*
1424 * Check port type. It should be 0 = n-port.
1425 */
1426 if (flogi->csp.port_type) {
1427 /*
1428 * @todo: may need to send a LS_RJT
1429 */
1430 bfa_trc(fabric->fcs, flogi->port_name);
1431 fabric->stats.flogi_rejected++;
1432 return;
1433 }
1434
Jing Huangba816ea2010-10-18 17:10:50 -07001435 fabric->bb_credit = be16_to_cpu(flogi->csp.bbcred);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001436 bport->port_topo.pn2n.rem_port_wwn = flogi->port_name;
1437 bport->port_topo.pn2n.reply_oxid = fchs->ox_id;
1438
1439 /*
1440 * Send a Flogi Acc
1441 */
1442 bfa_fcs_fabric_send_flogi_acc(fabric);
1443 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_NO_FABRIC);
1444}
1445
1446static void
1447bfa_fcs_fabric_send_flogi_acc(struct bfa_fcs_fabric_s *fabric)
1448{
1449 struct bfa_lport_cfg_s *pcfg = &fabric->bport.port_cfg;
1450 struct bfa_fcs_lport_n2n_s *n2n_port = &fabric->bport.port_topo.pn2n;
1451 struct bfa_s *bfa = fabric->fcs->bfa;
1452 struct bfa_fcxp_s *fcxp;
1453 u16 reqlen;
1454 struct fchs_s fchs;
1455
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07001456 fcxp = bfa_fcs_fcxp_alloc(fabric->fcs, BFA_FALSE);
Jing Huang5fbe25c2010-10-18 17:17:23 -07001457 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001458 * Do not expect this failure -- expect remote node to retry
1459 */
1460 if (!fcxp)
1461 return;
1462
1463 reqlen = fc_flogi_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
Maggie Zhangf16a1752010-12-09 19:12:32 -08001464 bfa_hton3b(FC_FABRIC_PORT),
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001465 n2n_port->reply_oxid, pcfg->pwwn,
1466 pcfg->nwwn,
1467 bfa_fcport_get_maxfrsize(bfa),
Vijaya Mohan Guvvabbe37a62013-05-13 02:33:19 -07001468 bfa_fcport_get_rx_bbcredit(bfa), 0);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001469
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001470 bfa_fcxp_send(fcxp, NULL, fabric->vf_id, fabric->lps->bfa_tag,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001471 BFA_FALSE, FC_CLASS_3,
1472 reqlen, &fchs, bfa_fcs_fabric_flogiacc_comp, fabric,
1473 FC_MAX_PDUSZ, 0);
1474}
1475
Jing Huang5fbe25c2010-10-18 17:17:23 -07001476/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001477 * Flogi Acc completion callback.
1478 */
1479static void
1480bfa_fcs_fabric_flogiacc_comp(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
1481 bfa_status_t status, u32 rsp_len,
1482 u32 resid_len, struct fchs_s *rspfchs)
1483{
1484 struct bfa_fcs_fabric_s *fabric = cbarg;
1485
1486 bfa_trc(fabric->fcs, status);
1487}
1488
Krishna Gudipati7826f302011-07-20 16:59:13 -07001489
1490/*
1491 * Send AEN notification
1492 */
1493static void
1494bfa_fcs_fabric_aen_post(struct bfa_fcs_lport_s *port,
1495 enum bfa_port_aen_event event)
1496{
1497 struct bfad_s *bfad = (struct bfad_s *)port->fabric->fcs->bfad;
1498 struct bfa_aen_entry_s *aen_entry;
1499
1500 bfad_get_aen_entry(bfad, aen_entry);
1501 if (!aen_entry)
1502 return;
1503
1504 aen_entry->aen_data.port.pwwn = bfa_fcs_lport_get_pwwn(port);
1505 aen_entry->aen_data.port.fwwn = bfa_fcs_lport_get_fabric_name(port);
1506
1507 /* Send the AEN notification */
1508 bfad_im_post_vendor_event(aen_entry, bfad, ++port->fcs->fcs_aen_seq,
1509 BFA_AEN_CAT_PORT, event);
1510}
1511
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001512/*
1513 *
1514 * @param[in] fabric - fabric
1515 * @param[in] wwn_t - new fabric name
1516 *
1517 * @return - none
1518 */
1519void
1520bfa_fcs_fabric_set_fabric_name(struct bfa_fcs_fabric_s *fabric,
1521 wwn_t fabric_name)
1522{
1523 struct bfad_s *bfad = (struct bfad_s *)fabric->fcs->bfad;
1524 char pwwn_ptr[BFA_STRING_32];
1525 char fwwn_ptr[BFA_STRING_32];
1526
1527 bfa_trc(fabric->fcs, fabric_name);
1528
1529 if (fabric->fabric_name == 0) {
1530 /*
1531 * With BRCD switches, we don't get Fabric Name in FLOGI.
1532 * Don't generate a fabric name change event in this case.
1533 */
1534 fabric->fabric_name = fabric_name;
1535 } else {
1536 fabric->fabric_name = fabric_name;
1537 wwn2str(pwwn_ptr, bfa_fcs_lport_get_pwwn(&fabric->bport));
1538 wwn2str(fwwn_ptr,
1539 bfa_fcs_lport_get_fabric_name(&fabric->bport));
Jing Huang88166242010-12-09 17:11:53 -08001540 BFA_LOG(KERN_WARNING, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001541 "Base port WWN = %s Fabric WWN = %s\n",
1542 pwwn_ptr, fwwn_ptr);
Krishna Gudipati7826f302011-07-20 16:59:13 -07001543 bfa_fcs_fabric_aen_post(&fabric->bport,
1544 BFA_PORT_AEN_FABRIC_NAME_CHANGE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001545 }
1546}
1547
Krishna Gudipati881c1b32012-08-22 19:52:02 -07001548void
1549bfa_cb_lps_flogo_comp(void *bfad, void *uarg)
1550{
1551 struct bfa_fcs_fabric_s *fabric = uarg;
1552 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_LOGOCOMP);
1553}
1554
Jing Huang5fbe25c2010-10-18 17:17:23 -07001555/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001556 * Returns FCS vf structure for a given vf_id.
1557 *
1558 * param[in] vf_id - VF_ID
1559 *
1560 * return
1561 * If lookup succeeds, retuns fcs vf object, otherwise returns NULL
1562 */
1563bfa_fcs_vf_t *
1564bfa_fcs_vf_lookup(struct bfa_fcs_s *fcs, u16 vf_id)
1565{
1566 bfa_trc(fcs, vf_id);
1567 if (vf_id == FC_VF_ID_NULL)
1568 return &fcs->fabric;
1569
1570 return NULL;
1571}
1572
Jing Huang5fbe25c2010-10-18 17:17:23 -07001573/*
Krishna Gudipatib85daaf2011-06-13 15:55:11 -07001574 * Return the list of local logical ports present in the given VF.
1575 *
1576 * @param[in] vf vf for which logical ports are returned
1577 * @param[out] lpwwn returned logical port wwn list
1578 * @param[in,out] nlports in:size of lpwwn list;
1579 * out:total elements present,
1580 * actual elements returned is limited by the size
1581 */
1582void
1583bfa_fcs_vf_get_ports(bfa_fcs_vf_t *vf, wwn_t lpwwn[], int *nlports)
1584{
1585 struct list_head *qe;
1586 struct bfa_fcs_vport_s *vport;
1587 int i = 0;
1588 struct bfa_fcs_s *fcs;
1589
1590 if (vf == NULL || lpwwn == NULL || *nlports == 0)
1591 return;
1592
1593 fcs = vf->fcs;
1594
1595 bfa_trc(fcs, vf->vf_id);
1596 bfa_trc(fcs, (uint32_t) *nlports);
1597
1598 lpwwn[i++] = vf->bport.port_cfg.pwwn;
1599
1600 list_for_each(qe, &vf->vport_q) {
1601 if (i >= *nlports)
1602 break;
1603
1604 vport = (struct bfa_fcs_vport_s *) qe;
1605 lpwwn[i++] = vport->lport.port_cfg.pwwn;
1606 }
1607
1608 bfa_trc(fcs, i);
1609 *nlports = i;
1610}
1611
1612/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001613 * BFA FCS PPORT ( physical port)
1614 */
1615static void
1616bfa_fcs_port_event_handler(void *cbarg, enum bfa_port_linkstate event)
1617{
1618 struct bfa_fcs_s *fcs = cbarg;
1619
1620 bfa_trc(fcs, event);
1621
1622 switch (event) {
1623 case BFA_PORT_LINKUP:
1624 bfa_fcs_fabric_link_up(&fcs->fabric);
1625 break;
1626
1627 case BFA_PORT_LINKDOWN:
1628 bfa_fcs_fabric_link_down(&fcs->fabric);
1629 break;
1630
1631 default:
Jing Huangd4b671c2010-12-26 21:46:35 -08001632 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001633 }
1634}
1635
1636void
1637bfa_fcs_port_attach(struct bfa_fcs_s *fcs)
1638{
1639 bfa_fcport_event_register(fcs->bfa, bfa_fcs_port_event_handler, fcs);
1640}
1641
Jing Huang5fbe25c2010-10-18 17:17:23 -07001642/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001643 * BFA FCS UF ( Unsolicited Frames)
1644 */
1645
Jing Huang5fbe25c2010-10-18 17:17:23 -07001646/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001647 * BFA callback for unsolicited frame receive handler.
1648 *
1649 * @param[in] cbarg callback arg for receive handler
1650 * @param[in] uf unsolicited frame descriptor
1651 *
1652 * @return None
1653 */
1654static void
1655bfa_fcs_uf_recv(void *cbarg, struct bfa_uf_s *uf)
1656{
1657 struct bfa_fcs_s *fcs = (struct bfa_fcs_s *) cbarg;
1658 struct fchs_s *fchs = bfa_uf_get_frmbuf(uf);
1659 u16 len = bfa_uf_get_frmlen(uf);
1660 struct fc_vft_s *vft;
1661 struct bfa_fcs_fabric_s *fabric;
1662
Jing Huang5fbe25c2010-10-18 17:17:23 -07001663 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001664 * check for VFT header
1665 */
1666 if (fchs->routing == FC_RTG_EXT_HDR &&
1667 fchs->cat_info == FC_CAT_VFT_HDR) {
1668 bfa_stats(fcs, uf.tagged);
1669 vft = bfa_uf_get_frmbuf(uf);
1670 if (fcs->port_vfid == vft->vf_id)
1671 fabric = &fcs->fabric;
1672 else
1673 fabric = bfa_fcs_vf_lookup(fcs, (u16) vft->vf_id);
1674
Jing Huang5fbe25c2010-10-18 17:17:23 -07001675 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001676 * drop frame if vfid is unknown
1677 */
1678 if (!fabric) {
Jing Huangd4b671c2010-12-26 21:46:35 -08001679 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001680 bfa_stats(fcs, uf.vfid_unknown);
1681 bfa_uf_free(uf);
1682 return;
1683 }
1684
Jing Huang5fbe25c2010-10-18 17:17:23 -07001685 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001686 * skip vft header
1687 */
1688 fchs = (struct fchs_s *) (vft + 1);
1689 len -= sizeof(struct fc_vft_s);
1690
1691 bfa_trc(fcs, vft->vf_id);
1692 } else {
1693 bfa_stats(fcs, uf.untagged);
1694 fabric = &fcs->fabric;
1695 }
1696
1697 bfa_trc(fcs, ((u32 *) fchs)[0]);
1698 bfa_trc(fcs, ((u32 *) fchs)[1]);
1699 bfa_trc(fcs, ((u32 *) fchs)[2]);
1700 bfa_trc(fcs, ((u32 *) fchs)[3]);
1701 bfa_trc(fcs, ((u32 *) fchs)[4]);
1702 bfa_trc(fcs, ((u32 *) fchs)[5]);
1703 bfa_trc(fcs, len);
1704
1705 bfa_fcs_fabric_uf_recv(fabric, fchs, len);
1706 bfa_uf_free(uf);
1707}
1708
1709void
1710bfa_fcs_uf_attach(struct bfa_fcs_s *fcs)
1711{
1712 bfa_uf_recv_register(fcs->bfa, bfa_fcs_uf_recv, fcs);
1713}