blob: a3ab5cce4208b4bb924f3ebff7a97a83886f4efe [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 Gudipatia36c61f2010-09-15 11:50:55 -0700243
244static void bfa_fcs_fabric_sm_uninit(struct bfa_fcs_fabric_s *fabric,
245 enum bfa_fcs_fabric_event event);
246static void bfa_fcs_fabric_sm_created(struct bfa_fcs_fabric_s *fabric,
247 enum bfa_fcs_fabric_event event);
248static void bfa_fcs_fabric_sm_linkdown(struct bfa_fcs_fabric_s *fabric,
249 enum bfa_fcs_fabric_event event);
250static void bfa_fcs_fabric_sm_flogi(struct bfa_fcs_fabric_s *fabric,
251 enum bfa_fcs_fabric_event event);
252static void bfa_fcs_fabric_sm_flogi_retry(struct bfa_fcs_fabric_s *fabric,
253 enum bfa_fcs_fabric_event event);
254static void bfa_fcs_fabric_sm_auth(struct bfa_fcs_fabric_s *fabric,
255 enum bfa_fcs_fabric_event event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700256static void bfa_fcs_fabric_sm_nofabric(struct bfa_fcs_fabric_s *fabric,
257 enum bfa_fcs_fabric_event event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700258static void bfa_fcs_fabric_sm_evfp(struct bfa_fcs_fabric_s *fabric,
259 enum bfa_fcs_fabric_event event);
260static void bfa_fcs_fabric_sm_evfp_done(struct bfa_fcs_fabric_s *fabric,
261 enum bfa_fcs_fabric_event event);
262static void bfa_fcs_fabric_sm_isolated(struct bfa_fcs_fabric_s *fabric,
263 enum bfa_fcs_fabric_event event);
264static void bfa_fcs_fabric_sm_deleting(struct bfa_fcs_fabric_s *fabric,
265 enum bfa_fcs_fabric_event event);
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700266static void bfa_fcs_fabric_sm_stopping(struct bfa_fcs_fabric_s *fabric,
267 enum bfa_fcs_fabric_event event);
268static void bfa_fcs_fabric_sm_cleanup(struct bfa_fcs_fabric_s *fabric,
269 enum bfa_fcs_fabric_event event);
Jing Huang5fbe25c2010-10-18 17:17:23 -0700270/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700271 * Beginning state before fabric creation.
272 */
273static void
274bfa_fcs_fabric_sm_uninit(struct bfa_fcs_fabric_s *fabric,
275 enum bfa_fcs_fabric_event event)
276{
277 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
278 bfa_trc(fabric->fcs, event);
279
280 switch (event) {
281 case BFA_FCS_FABRIC_SM_CREATE:
282 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_created);
283 bfa_fcs_fabric_init(fabric);
284 bfa_fcs_lport_init(&fabric->bport, &fabric->bport.port_cfg);
285 break;
286
287 case BFA_FCS_FABRIC_SM_LINK_UP:
288 case BFA_FCS_FABRIC_SM_LINK_DOWN:
289 break;
290
291 default:
292 bfa_sm_fault(fabric->fcs, event);
293 }
294}
295
Jing Huang5fbe25c2010-10-18 17:17:23 -0700296/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700297 * Beginning state before fabric creation.
298 */
299static void
300bfa_fcs_fabric_sm_created(struct bfa_fcs_fabric_s *fabric,
301 enum bfa_fcs_fabric_event event)
302{
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -0700303 struct bfa_s *bfa = fabric->fcs->bfa;
304
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700305 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
306 bfa_trc(fabric->fcs, event);
307
308 switch (event) {
309 case BFA_FCS_FABRIC_SM_START:
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -0700310 if (!bfa_fcport_is_linkup(fabric->fcs->bfa)) {
311 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
312 break;
313 }
314 if (bfa_fcport_get_topology(bfa) ==
315 BFA_PORT_TOPOLOGY_LOOP) {
316 fabric->fab_type = BFA_FCS_FABRIC_LOOP;
317 fabric->bport.pid = bfa_fcport_get_myalpa(bfa);
318 fabric->bport.pid = bfa_hton3b(fabric->bport.pid);
319 bfa_sm_set_state(fabric,
320 bfa_fcs_fabric_sm_online);
321 bfa_fcs_fabric_set_opertype(fabric);
322 bfa_fcs_lport_online(&fabric->bport);
323 } else {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700324 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_flogi);
325 bfa_fcs_fabric_login(fabric);
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -0700326 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700327 break;
328
329 case BFA_FCS_FABRIC_SM_LINK_UP:
330 case BFA_FCS_FABRIC_SM_LINK_DOWN:
331 break;
332
333 case BFA_FCS_FABRIC_SM_DELETE:
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -0700334 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
335 bfa_fcs_fabric_delete(fabric);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700336 break;
337
338 default:
339 bfa_sm_fault(fabric->fcs, event);
340 }
341}
342
Jing Huang5fbe25c2010-10-18 17:17:23 -0700343/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700344 * Link is down, awaiting LINK UP event from port. This is also the
345 * first state at fabric creation.
346 */
347static void
348bfa_fcs_fabric_sm_linkdown(struct bfa_fcs_fabric_s *fabric,
349 enum bfa_fcs_fabric_event event)
350{
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -0700351 struct bfa_s *bfa = fabric->fcs->bfa;
352
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700353 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
354 bfa_trc(fabric->fcs, event);
355
356 switch (event) {
357 case BFA_FCS_FABRIC_SM_LINK_UP:
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -0700358 if (bfa_fcport_get_topology(bfa) != BFA_PORT_TOPOLOGY_LOOP) {
359 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_flogi);
360 bfa_fcs_fabric_login(fabric);
361 break;
362 }
363 fabric->fab_type = BFA_FCS_FABRIC_LOOP;
364 fabric->bport.pid = bfa_fcport_get_myalpa(bfa);
365 fabric->bport.pid = bfa_hton3b(fabric->bport.pid);
366 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_online);
367 bfa_fcs_fabric_set_opertype(fabric);
368 bfa_fcs_lport_online(&fabric->bport);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700369 break;
370
371 case BFA_FCS_FABRIC_SM_RETRY_OP:
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -0700372 case BFA_FCS_FABRIC_SM_LOOPBACK:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700373 break;
374
375 case BFA_FCS_FABRIC_SM_DELETE:
376 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
377 bfa_fcs_fabric_delete(fabric);
378 break;
379
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700380 case BFA_FCS_FABRIC_SM_STOP:
381 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_cleanup);
382 bfa_fcs_fabric_stop(fabric);
383 break;
384
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700385 default:
386 bfa_sm_fault(fabric->fcs, event);
387 }
388}
389
Jing Huang5fbe25c2010-10-18 17:17:23 -0700390/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700391 * FLOGI is in progress, awaiting FLOGI reply.
392 */
393static void
394bfa_fcs_fabric_sm_flogi(struct bfa_fcs_fabric_s *fabric,
395 enum bfa_fcs_fabric_event event)
396{
397 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
398 bfa_trc(fabric->fcs, event);
399
400 switch (event) {
401 case BFA_FCS_FABRIC_SM_CONT_OP:
402
403 bfa_fcport_set_tx_bbcredit(fabric->fcs->bfa,
Vijaya Mohan Guvvabbe37a62013-05-13 02:33:19 -0700404 fabric->bb_credit);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700405 fabric->fab_type = BFA_FCS_FABRIC_SWITCHED;
406
407 if (fabric->auth_reqd && fabric->is_auth) {
408 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_auth);
409 bfa_trc(fabric->fcs, event);
410 } else {
411 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_online);
412 bfa_fcs_fabric_notify_online(fabric);
413 }
414 break;
415
416 case BFA_FCS_FABRIC_SM_RETRY_OP:
417 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_flogi_retry);
418 bfa_timer_start(fabric->fcs->bfa, &fabric->delay_timer,
419 bfa_fcs_fabric_delay, fabric,
420 BFA_FCS_FABRIC_RETRY_DELAY);
421 break;
422
423 case BFA_FCS_FABRIC_SM_LOOPBACK:
424 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_loopback);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800425 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700426 bfa_fcs_fabric_set_opertype(fabric);
427 break;
428
429 case BFA_FCS_FABRIC_SM_NO_FABRIC:
430 fabric->fab_type = BFA_FCS_FABRIC_N2N;
431 bfa_fcport_set_tx_bbcredit(fabric->fcs->bfa,
Vijaya Mohan Guvvabbe37a62013-05-13 02:33:19 -0700432 fabric->bb_credit);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700433 bfa_fcs_fabric_notify_online(fabric);
434 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_nofabric);
435 break;
436
437 case BFA_FCS_FABRIC_SM_LINK_DOWN:
438 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800439 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700440 break;
441
442 case BFA_FCS_FABRIC_SM_DELETE:
443 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800444 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700445 bfa_fcs_fabric_delete(fabric);
446 break;
447
448 default:
449 bfa_sm_fault(fabric->fcs, event);
450 }
451}
452
453
454static void
455bfa_fcs_fabric_sm_flogi_retry(struct bfa_fcs_fabric_s *fabric,
456 enum bfa_fcs_fabric_event event)
457{
458 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
459 bfa_trc(fabric->fcs, event);
460
461 switch (event) {
462 case BFA_FCS_FABRIC_SM_DELAYED:
463 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_flogi);
464 bfa_fcs_fabric_login(fabric);
465 break;
466
467 case BFA_FCS_FABRIC_SM_LINK_DOWN:
468 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
469 bfa_timer_stop(&fabric->delay_timer);
470 break;
471
472 case BFA_FCS_FABRIC_SM_DELETE:
473 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
474 bfa_timer_stop(&fabric->delay_timer);
475 bfa_fcs_fabric_delete(fabric);
476 break;
477
478 default:
479 bfa_sm_fault(fabric->fcs, event);
480 }
481}
482
Jing Huang5fbe25c2010-10-18 17:17:23 -0700483/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700484 * Authentication is in progress, awaiting authentication results.
485 */
486static void
487bfa_fcs_fabric_sm_auth(struct bfa_fcs_fabric_s *fabric,
488 enum bfa_fcs_fabric_event event)
489{
490 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
491 bfa_trc(fabric->fcs, event);
492
493 switch (event) {
494 case BFA_FCS_FABRIC_SM_AUTH_FAILED:
495 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_auth_failed);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800496 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700497 break;
498
499 case BFA_FCS_FABRIC_SM_AUTH_SUCCESS:
500 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_online);
501 bfa_fcs_fabric_notify_online(fabric);
502 break;
503
504 case BFA_FCS_FABRIC_SM_PERF_EVFP:
505 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_evfp);
506 break;
507
508 case BFA_FCS_FABRIC_SM_LINK_DOWN:
509 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800510 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700511 break;
512
513 case BFA_FCS_FABRIC_SM_DELETE:
514 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
515 bfa_fcs_fabric_delete(fabric);
516 break;
517
518 default:
519 bfa_sm_fault(fabric->fcs, event);
520 }
521}
522
Jing Huang5fbe25c2010-10-18 17:17:23 -0700523/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700524 * Authentication failed
525 */
Maggie Zhangf7f738122010-12-09 19:08:43 -0800526void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700527bfa_fcs_fabric_sm_auth_failed(struct bfa_fcs_fabric_s *fabric,
528 enum bfa_fcs_fabric_event event)
529{
530 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
531 bfa_trc(fabric->fcs, event);
532
533 switch (event) {
534 case BFA_FCS_FABRIC_SM_LINK_DOWN:
535 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
536 bfa_fcs_fabric_notify_offline(fabric);
537 break;
538
539 case BFA_FCS_FABRIC_SM_DELETE:
540 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
541 bfa_fcs_fabric_delete(fabric);
542 break;
543
544 default:
545 bfa_sm_fault(fabric->fcs, event);
546 }
547}
548
Jing Huang5fbe25c2010-10-18 17:17:23 -0700549/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700550 * Port is in loopback mode.
551 */
Maggie Zhangf7f738122010-12-09 19:08:43 -0800552void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700553bfa_fcs_fabric_sm_loopback(struct bfa_fcs_fabric_s *fabric,
554 enum bfa_fcs_fabric_event event)
555{
556 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
557 bfa_trc(fabric->fcs, event);
558
559 switch (event) {
560 case BFA_FCS_FABRIC_SM_LINK_DOWN:
561 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
562 bfa_fcs_fabric_notify_offline(fabric);
563 break;
564
565 case BFA_FCS_FABRIC_SM_DELETE:
566 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
567 bfa_fcs_fabric_delete(fabric);
568 break;
569
570 default:
571 bfa_sm_fault(fabric->fcs, event);
572 }
573}
574
Jing Huang5fbe25c2010-10-18 17:17:23 -0700575/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700576 * There is no attached fabric - private loop or NPort-to-NPort topology.
577 */
578static void
579bfa_fcs_fabric_sm_nofabric(struct bfa_fcs_fabric_s *fabric,
580 enum bfa_fcs_fabric_event event)
581{
582 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
583 bfa_trc(fabric->fcs, event);
584
585 switch (event) {
586 case BFA_FCS_FABRIC_SM_LINK_DOWN:
587 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800588 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700589 bfa_fcs_fabric_notify_offline(fabric);
590 break;
591
592 case BFA_FCS_FABRIC_SM_DELETE:
593 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
594 bfa_fcs_fabric_delete(fabric);
595 break;
596
597 case BFA_FCS_FABRIC_SM_NO_FABRIC:
598 bfa_trc(fabric->fcs, fabric->bb_credit);
599 bfa_fcport_set_tx_bbcredit(fabric->fcs->bfa,
Vijaya Mohan Guvvabbe37a62013-05-13 02:33:19 -0700600 fabric->bb_credit);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700601 break;
602
Krishna Gudipatid7be54c2011-06-24 20:24:52 -0700603 case BFA_FCS_FABRIC_SM_RETRY_OP:
604 break;
605
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700606 default:
607 bfa_sm_fault(fabric->fcs, event);
608 }
609}
610
Jing Huang5fbe25c2010-10-18 17:17:23 -0700611/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700612 * Fabric is online - normal operating state.
613 */
Maggie Zhangf7f738122010-12-09 19:08:43 -0800614void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700615bfa_fcs_fabric_sm_online(struct bfa_fcs_fabric_s *fabric,
616 enum bfa_fcs_fabric_event event)
617{
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -0700618 struct bfa_s *bfa = fabric->fcs->bfa;
619
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700620 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
621 bfa_trc(fabric->fcs, event);
622
623 switch (event) {
624 case BFA_FCS_FABRIC_SM_LINK_DOWN:
625 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -0700626 if (bfa_fcport_get_topology(bfa) == BFA_PORT_TOPOLOGY_LOOP) {
627 bfa_fcs_lport_offline(&fabric->bport);
628 } else {
629 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
630 bfa_fcs_fabric_notify_offline(fabric);
631 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700632 break;
633
634 case BFA_FCS_FABRIC_SM_DELETE:
635 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
636 bfa_fcs_fabric_delete(fabric);
637 break;
638
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700639 case BFA_FCS_FABRIC_SM_STOP:
640 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_stopping);
641 bfa_fcs_fabric_stop(fabric);
642 break;
643
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700644 case BFA_FCS_FABRIC_SM_AUTH_FAILED:
645 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_auth_failed);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800646 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700647 break;
648
649 case BFA_FCS_FABRIC_SM_AUTH_SUCCESS:
650 break;
651
652 default:
653 bfa_sm_fault(fabric->fcs, event);
654 }
655}
656
Jing Huang5fbe25c2010-10-18 17:17:23 -0700657/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700658 * Exchanging virtual fabric parameters.
659 */
660static void
661bfa_fcs_fabric_sm_evfp(struct bfa_fcs_fabric_s *fabric,
662 enum bfa_fcs_fabric_event event)
663{
664 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
665 bfa_trc(fabric->fcs, event);
666
667 switch (event) {
668 case BFA_FCS_FABRIC_SM_CONT_OP:
669 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_evfp_done);
670 break;
671
672 case BFA_FCS_FABRIC_SM_ISOLATE:
673 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_isolated);
674 break;
675
676 default:
677 bfa_sm_fault(fabric->fcs, event);
678 }
679}
680
Jing Huang5fbe25c2010-10-18 17:17:23 -0700681/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700682 * EVFP exchange complete and VFT tagging is enabled.
683 */
684static void
685bfa_fcs_fabric_sm_evfp_done(struct bfa_fcs_fabric_s *fabric,
686 enum bfa_fcs_fabric_event event)
687{
688 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
689 bfa_trc(fabric->fcs, event);
690}
691
Jing Huang5fbe25c2010-10-18 17:17:23 -0700692/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700693 * Port is isolated after EVFP exchange due to VF_ID mismatch (N and F).
694 */
695static void
696bfa_fcs_fabric_sm_isolated(struct bfa_fcs_fabric_s *fabric,
697 enum bfa_fcs_fabric_event event)
698{
699 struct bfad_s *bfad = (struct bfad_s *)fabric->fcs->bfad;
700 char pwwn_ptr[BFA_STRING_32];
701
702 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
703 bfa_trc(fabric->fcs, event);
704 wwn2str(pwwn_ptr, fabric->bport.port_cfg.pwwn);
705
Jing Huang88166242010-12-09 17:11:53 -0800706 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700707 "Port is isolated due to VF_ID mismatch. "
708 "PWWN: %s Port VF_ID: %04x switch port VF_ID: %04x.",
709 pwwn_ptr, fabric->fcs->port_vfid,
710 fabric->event_arg.swp_vfid);
711}
712
Jing Huang5fbe25c2010-10-18 17:17:23 -0700713/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700714 * Fabric is being deleted, awaiting vport delete completions.
715 */
716static void
717bfa_fcs_fabric_sm_deleting(struct bfa_fcs_fabric_s *fabric,
718 enum bfa_fcs_fabric_event event)
719{
720 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
721 bfa_trc(fabric->fcs, event);
722
723 switch (event) {
724 case BFA_FCS_FABRIC_SM_DELCOMP:
725 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_uninit);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800726 bfa_wc_down(&fabric->fcs->wc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700727 break;
728
729 case BFA_FCS_FABRIC_SM_LINK_UP:
730 break;
731
732 case BFA_FCS_FABRIC_SM_LINK_DOWN:
733 bfa_fcs_fabric_notify_offline(fabric);
734 break;
735
736 default:
737 bfa_sm_fault(fabric->fcs, event);
738 }
739}
740
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700741/*
742 * Fabric is being stopped, awaiting vport stop completions.
743 */
744static void
745bfa_fcs_fabric_sm_stopping(struct bfa_fcs_fabric_s *fabric,
746 enum bfa_fcs_fabric_event event)
747{
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -0700748 struct bfa_s *bfa = fabric->fcs->bfa;
749
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700750 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
751 bfa_trc(fabric->fcs, event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700752
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700753 switch (event) {
754 case BFA_FCS_FABRIC_SM_STOPCOMP:
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -0700755 if (bfa_fcport_get_topology(bfa) == BFA_PORT_TOPOLOGY_LOOP) {
756 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_created);
757 } else {
758 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_cleanup);
759 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_LOGOUT);
760 }
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700761 break;
762
763 case BFA_FCS_FABRIC_SM_LINK_UP:
764 break;
765
766 case BFA_FCS_FABRIC_SM_LINK_DOWN:
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -0700767 if (bfa_fcport_get_topology(bfa) == BFA_PORT_TOPOLOGY_LOOP)
768 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_created);
769 else
770 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_cleanup);
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700771 break;
772
773 default:
774 bfa_sm_fault(fabric->fcs, event);
775 }
776}
777
778/*
779 * Fabric is being stopped, cleanup without FLOGO
780 */
781static void
782bfa_fcs_fabric_sm_cleanup(struct bfa_fcs_fabric_s *fabric,
783 enum bfa_fcs_fabric_event event)
784{
785 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
786 bfa_trc(fabric->fcs, event);
787
788 switch (event) {
789 case BFA_FCS_FABRIC_SM_STOPCOMP:
790 case BFA_FCS_FABRIC_SM_LOGOCOMP:
791 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_created);
792 bfa_wc_down(&(fabric->fcs)->wc);
793 break;
794
795 case BFA_FCS_FABRIC_SM_LINK_DOWN:
796 /*
797 * Ignore - can get this event if we get notified about IOC down
798 * before the fabric completion callbk is done.
799 */
800 break;
801
802 default:
803 bfa_sm_fault(fabric->fcs, event);
804 }
805}
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700806
Jing Huang5fbe25c2010-10-18 17:17:23 -0700807/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700808 * fcs_fabric_private fabric private functions
809 */
810
811static void
812bfa_fcs_fabric_init(struct bfa_fcs_fabric_s *fabric)
813{
814 struct bfa_lport_cfg_s *port_cfg = &fabric->bport.port_cfg;
815
816 port_cfg->roles = BFA_LPORT_ROLE_FCP_IM;
Maggie Zhangf7f738122010-12-09 19:08:43 -0800817 port_cfg->nwwn = fabric->fcs->bfa->ioc.attr->nwwn;
818 port_cfg->pwwn = fabric->fcs->bfa->ioc.attr->pwwn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700819}
820
Jing Huang5fbe25c2010-10-18 17:17:23 -0700821/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700822 * Port Symbolic Name Creation for base port.
823 */
824void
825bfa_fcs_fabric_psymb_init(struct bfa_fcs_fabric_s *fabric)
826{
827 struct bfa_lport_cfg_s *port_cfg = &fabric->bport.port_cfg;
828 char model[BFA_ADAPTER_MODEL_NAME_LEN] = {0};
829 struct bfa_fcs_driver_info_s *driver_info = &fabric->fcs->driver_info;
830
831 bfa_ioc_get_adapter_model(&fabric->fcs->bfa->ioc, model);
832
833 /* Model name/number */
834 strncpy((char *)&port_cfg->sym_name, model,
835 BFA_FCS_PORT_SYMBNAME_MODEL_SZ);
836 strncat((char *)&port_cfg->sym_name, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
837 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
838
839 /* Driver Version */
840 strncat((char *)&port_cfg->sym_name, (char *)driver_info->version,
841 BFA_FCS_PORT_SYMBNAME_VERSION_SZ);
842 strncat((char *)&port_cfg->sym_name, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
843 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
844
845 /* Host machine name */
846 strncat((char *)&port_cfg->sym_name,
847 (char *)driver_info->host_machine_name,
848 BFA_FCS_PORT_SYMBNAME_MACHINENAME_SZ);
849 strncat((char *)&port_cfg->sym_name, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
850 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
851
852 /*
853 * Host OS Info :
854 * If OS Patch Info is not there, do not truncate any bytes from the
855 * OS name string and instead copy the entire OS info string (64 bytes).
856 */
857 if (driver_info->host_os_patch[0] == '\0') {
858 strncat((char *)&port_cfg->sym_name,
859 (char *)driver_info->host_os_name,
860 BFA_FCS_OS_STR_LEN);
861 strncat((char *)&port_cfg->sym_name,
862 BFA_FCS_PORT_SYMBNAME_SEPARATOR,
863 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
864 } else {
865 strncat((char *)&port_cfg->sym_name,
866 (char *)driver_info->host_os_name,
867 BFA_FCS_PORT_SYMBNAME_OSINFO_SZ);
868 strncat((char *)&port_cfg->sym_name,
869 BFA_FCS_PORT_SYMBNAME_SEPARATOR,
870 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
871
872 /* Append host OS Patch Info */
873 strncat((char *)&port_cfg->sym_name,
874 (char *)driver_info->host_os_patch,
875 BFA_FCS_PORT_SYMBNAME_OSPATCH_SZ);
876 }
877
878 /* null terminate */
879 port_cfg->sym_name.symname[BFA_SYMNAME_MAXLEN - 1] = 0;
880}
881
Jing Huang5fbe25c2010-10-18 17:17:23 -0700882/*
Krishna Gudipatice7242b2012-08-22 19:52:43 -0700883 * Node Symbolic Name Creation for base port and all vports
884 */
885void
886bfa_fcs_fabric_nsymb_init(struct bfa_fcs_fabric_s *fabric)
887{
888 struct bfa_lport_cfg_s *port_cfg = &fabric->bport.port_cfg;
889 char model[BFA_ADAPTER_MODEL_NAME_LEN] = {0};
890 struct bfa_fcs_driver_info_s *driver_info = &fabric->fcs->driver_info;
891
892 bfa_ioc_get_adapter_model(&fabric->fcs->bfa->ioc, model);
893
894 /* Model name/number */
895 strncpy((char *)&port_cfg->node_sym_name, model,
896 BFA_FCS_PORT_SYMBNAME_MODEL_SZ);
897 strncat((char *)&port_cfg->node_sym_name,
898 BFA_FCS_PORT_SYMBNAME_SEPARATOR,
899 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
900
901 /* Driver Version */
902 strncat((char *)&port_cfg->node_sym_name, (char *)driver_info->version,
903 BFA_FCS_PORT_SYMBNAME_VERSION_SZ);
904 strncat((char *)&port_cfg->node_sym_name,
905 BFA_FCS_PORT_SYMBNAME_SEPARATOR,
906 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
907
908 /* Host machine name */
909 strncat((char *)&port_cfg->node_sym_name,
910 (char *)driver_info->host_machine_name,
911 BFA_FCS_PORT_SYMBNAME_MACHINENAME_SZ);
912 strncat((char *)&port_cfg->node_sym_name,
913 BFA_FCS_PORT_SYMBNAME_SEPARATOR,
914 sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
915
916 /* null terminate */
917 port_cfg->node_sym_name.symname[BFA_SYMNAME_MAXLEN - 1] = 0;
918}
919
920/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700921 * bfa lps login completion callback
922 */
923void
924bfa_cb_lps_flogi_comp(void *bfad, void *uarg, bfa_status_t status)
925{
926 struct bfa_fcs_fabric_s *fabric = uarg;
927
928 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
929 bfa_trc(fabric->fcs, status);
930
931 switch (status) {
932 case BFA_STATUS_OK:
933 fabric->stats.flogi_accepts++;
934 break;
935
936 case BFA_STATUS_INVALID_MAC:
937 /* Only for CNA */
938 fabric->stats.flogi_acc_err++;
939 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_RETRY_OP);
940
941 return;
942
943 case BFA_STATUS_EPROTOCOL:
Maggie Zhangf7f738122010-12-09 19:08:43 -0800944 switch (fabric->lps->ext_status) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700945 case BFA_EPROTO_BAD_ACCEPT:
946 fabric->stats.flogi_acc_err++;
947 break;
948
949 case BFA_EPROTO_UNKNOWN_RSP:
950 fabric->stats.flogi_unknown_rsp++;
951 break;
952
953 default:
954 break;
955 }
956 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_RETRY_OP);
957
958 return;
959
960 case BFA_STATUS_FABRIC_RJT:
961 fabric->stats.flogi_rejects++;
962 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_RETRY_OP);
963 return;
964
965 default:
966 fabric->stats.flogi_rsp_err++;
967 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_RETRY_OP);
968 return;
969 }
970
Maggie Zhangf7f738122010-12-09 19:08:43 -0800971 fabric->bb_credit = fabric->lps->pr_bbcred;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700972 bfa_trc(fabric->fcs, fabric->bb_credit);
973
Maggie Zhangf7f738122010-12-09 19:08:43 -0800974 if (!(fabric->lps->brcd_switch))
975 fabric->fabric_name = fabric->lps->pr_nwwn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700976
977 /*
978 * Check port type. It should be 1 = F-port.
979 */
Maggie Zhangf7f738122010-12-09 19:08:43 -0800980 if (fabric->lps->fport) {
981 fabric->bport.pid = fabric->lps->lp_pid;
982 fabric->is_npiv = fabric->lps->npiv_en;
983 fabric->is_auth = fabric->lps->auth_req;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700984 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_CONT_OP);
985 } else {
986 /*
987 * Nport-2-Nport direct attached
988 */
989 fabric->bport.port_topo.pn2n.rem_port_wwn =
Maggie Zhangf7f738122010-12-09 19:08:43 -0800990 fabric->lps->pr_pwwn;
Krishna Gudipatid7be54c2011-06-24 20:24:52 -0700991 fabric->fab_type = BFA_FCS_FABRIC_N2N;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700992 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_NO_FABRIC);
993 }
994
995 bfa_trc(fabric->fcs, fabric->bport.pid);
996 bfa_trc(fabric->fcs, fabric->is_npiv);
997 bfa_trc(fabric->fcs, fabric->is_auth);
998}
Jing Huang5fbe25c2010-10-18 17:17:23 -0700999/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001000 * Allocate and send FLOGI.
1001 */
1002static void
1003bfa_fcs_fabric_login(struct bfa_fcs_fabric_s *fabric)
1004{
1005 struct bfa_s *bfa = fabric->fcs->bfa;
1006 struct bfa_lport_cfg_s *pcfg = &fabric->bport.port_cfg;
Vijaya Mohan Guvvabbe37a62013-05-13 02:33:19 -07001007 u8 alpa = 0;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001008
Krishna Gudipatibe540a92011-06-13 15:53:04 -07001009
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001010 bfa_lps_flogi(fabric->lps, fabric, alpa, bfa_fcport_get_maxfrsize(bfa),
Vijaya Mohan Guvvabbe37a62013-05-13 02:33:19 -07001011 pcfg->pwwn, pcfg->nwwn, fabric->auth_reqd);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001012
1013 fabric->stats.flogi_sent++;
1014}
1015
1016static void
1017bfa_fcs_fabric_notify_online(struct bfa_fcs_fabric_s *fabric)
1018{
1019 struct bfa_fcs_vport_s *vport;
1020 struct list_head *qe, *qen;
1021
1022 bfa_trc(fabric->fcs, fabric->fabric_name);
1023
1024 bfa_fcs_fabric_set_opertype(fabric);
1025 fabric->stats.fabric_onlines++;
1026
Jing Huang5fbe25c2010-10-18 17:17:23 -07001027 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001028 * notify online event to base and then virtual ports
1029 */
1030 bfa_fcs_lport_online(&fabric->bport);
1031
1032 list_for_each_safe(qe, qen, &fabric->vport_q) {
1033 vport = (struct bfa_fcs_vport_s *) qe;
1034 bfa_fcs_vport_online(vport);
1035 }
1036}
1037
1038static void
1039bfa_fcs_fabric_notify_offline(struct bfa_fcs_fabric_s *fabric)
1040{
1041 struct bfa_fcs_vport_s *vport;
1042 struct list_head *qe, *qen;
1043
1044 bfa_trc(fabric->fcs, fabric->fabric_name);
1045 fabric->stats.fabric_offlines++;
1046
Jing Huang5fbe25c2010-10-18 17:17:23 -07001047 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001048 * notify offline event first to vports and then base port.
1049 */
1050 list_for_each_safe(qe, qen, &fabric->vport_q) {
1051 vport = (struct bfa_fcs_vport_s *) qe;
1052 bfa_fcs_vport_offline(vport);
1053 }
1054
1055 bfa_fcs_lport_offline(&fabric->bport);
1056
1057 fabric->fabric_name = 0;
1058 fabric->fabric_ip_addr[0] = 0;
1059}
1060
1061static void
1062bfa_fcs_fabric_delay(void *cbarg)
1063{
1064 struct bfa_fcs_fabric_s *fabric = cbarg;
1065
1066 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_DELAYED);
1067}
1068
Jing Huang5fbe25c2010-10-18 17:17:23 -07001069/*
Krishna Gudipati881c1b32012-08-22 19:52:02 -07001070 * Stop all vports and wait for vport stop completions.
1071 */
1072static void
1073bfa_fcs_fabric_stop(struct bfa_fcs_fabric_s *fabric)
1074{
1075 struct bfa_fcs_vport_s *vport;
1076 struct list_head *qe, *qen;
1077
1078 bfa_wc_init(&fabric->stop_wc, bfa_fcs_fabric_stop_comp, fabric);
1079
1080 list_for_each_safe(qe, qen, &fabric->vport_q) {
1081 vport = (struct bfa_fcs_vport_s *) qe;
1082 bfa_wc_up(&fabric->stop_wc);
1083 bfa_fcs_vport_fcs_stop(vport);
1084 }
1085
1086 bfa_wc_up(&fabric->stop_wc);
1087 bfa_fcs_lport_stop(&fabric->bport);
1088 bfa_wc_wait(&fabric->stop_wc);
1089}
1090
1091/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001092 * Delete all vports and wait for vport delete completions.
1093 */
1094static void
1095bfa_fcs_fabric_delete(struct bfa_fcs_fabric_s *fabric)
1096{
1097 struct bfa_fcs_vport_s *vport;
1098 struct list_head *qe, *qen;
1099
1100 list_for_each_safe(qe, qen, &fabric->vport_q) {
1101 vport = (struct bfa_fcs_vport_s *) qe;
1102 bfa_fcs_vport_fcs_delete(vport);
1103 }
1104
1105 bfa_fcs_lport_delete(&fabric->bport);
1106 bfa_wc_wait(&fabric->wc);
1107}
1108
1109static void
1110bfa_fcs_fabric_delete_comp(void *cbarg)
1111{
1112 struct bfa_fcs_fabric_s *fabric = cbarg;
1113
1114 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_DELCOMP);
1115}
1116
Krishna Gudipati881c1b32012-08-22 19:52:02 -07001117static void
1118bfa_fcs_fabric_stop_comp(void *cbarg)
1119{
1120 struct bfa_fcs_fabric_s *fabric = cbarg;
1121
1122 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_STOPCOMP);
1123}
1124
Jing Huang5fbe25c2010-10-18 17:17:23 -07001125/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001126 * fcs_fabric_public fabric public functions
1127 */
1128
Jing Huang5fbe25c2010-10-18 17:17:23 -07001129/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001130 * Attach time initialization.
1131 */
1132void
1133bfa_fcs_fabric_attach(struct bfa_fcs_s *fcs)
1134{
1135 struct bfa_fcs_fabric_s *fabric;
1136
1137 fabric = &fcs->fabric;
Jing Huang6a18b162010-10-18 17:08:54 -07001138 memset(fabric, 0, sizeof(struct bfa_fcs_fabric_s));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001139
Jing Huang5fbe25c2010-10-18 17:17:23 -07001140 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001141 * Initialize base fabric.
1142 */
1143 fabric->fcs = fcs;
1144 INIT_LIST_HEAD(&fabric->vport_q);
1145 INIT_LIST_HEAD(&fabric->vf_q);
1146 fabric->lps = bfa_lps_alloc(fcs->bfa);
Jing Huangd4b671c2010-12-26 21:46:35 -08001147 WARN_ON(!fabric->lps);
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 fabric delete completion handler. Fabric deletion is
1151 * complete when the last vport delete is complete.
1152 */
1153 bfa_wc_init(&fabric->wc, bfa_fcs_fabric_delete_comp, fabric);
1154 bfa_wc_up(&fabric->wc); /* For the base port */
1155
1156 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_uninit);
1157 bfa_fcs_lport_attach(&fabric->bport, fabric->fcs, FC_VF_ID_NULL, NULL);
1158}
1159
1160void
1161bfa_fcs_fabric_modinit(struct bfa_fcs_s *fcs)
1162{
1163 bfa_sm_send_event(&fcs->fabric, BFA_FCS_FABRIC_SM_CREATE);
1164 bfa_trc(fcs, 0);
1165}
1166
Jing Huang5fbe25c2010-10-18 17:17:23 -07001167/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001168 * Module cleanup
1169 */
1170void
1171bfa_fcs_fabric_modexit(struct bfa_fcs_s *fcs)
1172{
1173 struct bfa_fcs_fabric_s *fabric;
1174
1175 bfa_trc(fcs, 0);
1176
Jing Huang5fbe25c2010-10-18 17:17:23 -07001177 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001178 * Cleanup base fabric.
1179 */
1180 fabric = &fcs->fabric;
1181 bfa_lps_delete(fabric->lps);
1182 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_DELETE);
1183}
1184
Jing Huang5fbe25c2010-10-18 17:17:23 -07001185/*
Krishna Gudipati881c1b32012-08-22 19:52:02 -07001186 * Fabric module stop -- stop FCS actions
1187 */
1188void
1189bfa_fcs_fabric_modstop(struct bfa_fcs_s *fcs)
1190{
1191 struct bfa_fcs_fabric_s *fabric;
1192
1193 bfa_trc(fcs, 0);
1194 fabric = &fcs->fabric;
1195 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_STOP);
1196}
1197
1198/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001199 * Fabric module start -- kick starts FCS actions
1200 */
1201void
1202bfa_fcs_fabric_modstart(struct bfa_fcs_s *fcs)
1203{
1204 struct bfa_fcs_fabric_s *fabric;
1205
1206 bfa_trc(fcs, 0);
1207 fabric = &fcs->fabric;
1208 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_START);
1209}
1210
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001211
Jing Huang5fbe25c2010-10-18 17:17:23 -07001212/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001213 * Link up notification from BFA physical port module.
1214 */
1215void
1216bfa_fcs_fabric_link_up(struct bfa_fcs_fabric_s *fabric)
1217{
1218 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
1219 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_LINK_UP);
1220}
1221
Jing Huang5fbe25c2010-10-18 17:17:23 -07001222/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001223 * Link down notification from BFA physical port module.
1224 */
1225void
1226bfa_fcs_fabric_link_down(struct bfa_fcs_fabric_s *fabric)
1227{
1228 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
1229 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_LINK_DOWN);
1230}
1231
Jing Huang5fbe25c2010-10-18 17:17:23 -07001232/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001233 * A child vport is being created in the fabric.
1234 *
1235 * Call from vport module at vport creation. A list of base port and vports
1236 * belonging to a fabric is maintained to propagate link events.
1237 *
1238 * param[in] fabric - Fabric instance. This can be a base fabric or vf.
1239 * param[in] vport - Vport being created.
1240 *
1241 * @return None (always succeeds)
1242 */
1243void
1244bfa_fcs_fabric_addvport(struct bfa_fcs_fabric_s *fabric,
1245 struct bfa_fcs_vport_s *vport)
1246{
Jing Huang5fbe25c2010-10-18 17:17:23 -07001247 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001248 * - add vport to fabric's vport_q
1249 */
1250 bfa_trc(fabric->fcs, fabric->vf_id);
1251
1252 list_add_tail(&vport->qe, &fabric->vport_q);
1253 fabric->num_vports++;
1254 bfa_wc_up(&fabric->wc);
1255}
1256
Jing Huang5fbe25c2010-10-18 17:17:23 -07001257/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001258 * A child vport is being deleted from fabric.
1259 *
1260 * Vport is being deleted.
1261 */
1262void
1263bfa_fcs_fabric_delvport(struct bfa_fcs_fabric_s *fabric,
1264 struct bfa_fcs_vport_s *vport)
1265{
1266 list_del(&vport->qe);
1267 fabric->num_vports--;
1268 bfa_wc_down(&fabric->wc);
1269}
1270
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001271
Jing Huang5fbe25c2010-10-18 17:17:23 -07001272/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001273 * Lookup for a vport within a fabric given its pwwn
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001274 */
1275struct bfa_fcs_vport_s *
1276bfa_fcs_fabric_vport_lookup(struct bfa_fcs_fabric_s *fabric, wwn_t pwwn)
1277{
1278 struct bfa_fcs_vport_s *vport;
1279 struct list_head *qe;
1280
1281 list_for_each(qe, &fabric->vport_q) {
1282 vport = (struct bfa_fcs_vport_s *) qe;
1283 if (bfa_fcs_lport_get_pwwn(&vport->lport) == pwwn)
1284 return vport;
1285 }
1286
1287 return NULL;
1288}
1289
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001290
1291/*
1292 * Get OUI of the attached switch.
1293 *
1294 * Note : Use of this function should be avoided as much as possible.
1295 * This function should be used only if there is any requirement
1296* to check for FOS version below 6.3.
1297 * To check if the attached fabric is a brocade fabric, use
1298 * bfa_lps_is_brcd_fabric() which works for FOS versions 6.3
1299 * or above only.
1300 */
1301
1302u16
1303bfa_fcs_fabric_get_switch_oui(struct bfa_fcs_fabric_s *fabric)
1304{
1305 wwn_t fab_nwwn;
1306 u8 *tmp;
1307 u16 oui;
1308
Maggie Zhangf7f738122010-12-09 19:08:43 -08001309 fab_nwwn = fabric->lps->pr_nwwn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001310
1311 tmp = (u8 *)&fab_nwwn;
1312 oui = (tmp[3] << 8) | tmp[4];
1313
1314 return oui;
1315}
Jing Huang5fbe25c2010-10-18 17:17:23 -07001316/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001317 * Unsolicited frame receive handling.
1318 */
1319void
1320bfa_fcs_fabric_uf_recv(struct bfa_fcs_fabric_s *fabric, struct fchs_s *fchs,
1321 u16 len)
1322{
1323 u32 pid = fchs->d_id;
1324 struct bfa_fcs_vport_s *vport;
1325 struct list_head *qe;
1326 struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
1327 struct fc_logi_s *flogi = (struct fc_logi_s *) els_cmd;
1328
1329 bfa_trc(fabric->fcs, len);
1330 bfa_trc(fabric->fcs, pid);
1331
Jing Huang5fbe25c2010-10-18 17:17:23 -07001332 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001333 * Look for our own FLOGI frames being looped back. This means an
1334 * external loopback cable is in place. Our own FLOGI frames are
1335 * sometimes looped back when switch port gets temporarily bypassed.
1336 */
Maggie Zhangf16a1752010-12-09 19:12:32 -08001337 if ((pid == bfa_ntoh3b(FC_FABRIC_PORT)) &&
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001338 (els_cmd->els_code == FC_ELS_FLOGI) &&
1339 (flogi->port_name == bfa_fcs_lport_get_pwwn(&fabric->bport))) {
1340 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_LOOPBACK);
1341 return;
1342 }
1343
Jing Huang5fbe25c2010-10-18 17:17:23 -07001344 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001345 * FLOGI/EVFP exchanges should be consumed by base fabric.
1346 */
Maggie Zhangf16a1752010-12-09 19:12:32 -08001347 if (fchs->d_id == bfa_hton3b(FC_FABRIC_PORT)) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001348 bfa_trc(fabric->fcs, pid);
1349 bfa_fcs_fabric_process_uf(fabric, fchs, len);
1350 return;
1351 }
1352
1353 if (fabric->bport.pid == pid) {
Jing Huang5fbe25c2010-10-18 17:17:23 -07001354 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001355 * All authentication frames should be routed to auth
1356 */
1357 bfa_trc(fabric->fcs, els_cmd->els_code);
1358 if (els_cmd->els_code == FC_ELS_AUTH) {
1359 bfa_trc(fabric->fcs, els_cmd->els_code);
1360 return;
1361 }
1362
1363 bfa_trc(fabric->fcs, *(u8 *) ((u8 *) fchs));
1364 bfa_fcs_lport_uf_recv(&fabric->bport, fchs, len);
1365 return;
1366 }
1367
Jing Huang5fbe25c2010-10-18 17:17:23 -07001368 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001369 * look for a matching local port ID
1370 */
1371 list_for_each(qe, &fabric->vport_q) {
1372 vport = (struct bfa_fcs_vport_s *) qe;
1373 if (vport->lport.pid == pid) {
1374 bfa_fcs_lport_uf_recv(&vport->lport, fchs, len);
1375 return;
1376 }
1377 }
Krishna Gudipati61ba4392012-08-22 19:52:58 -07001378
1379 if (!bfa_fcs_fabric_is_switched(fabric))
1380 bfa_fcs_lport_uf_recv(&fabric->bport, fchs, len);
1381
1382 bfa_trc(fabric->fcs, fchs->type);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001383}
1384
Jing Huang5fbe25c2010-10-18 17:17:23 -07001385/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001386 * Unsolicited frames to be processed by fabric.
1387 */
1388static void
1389bfa_fcs_fabric_process_uf(struct bfa_fcs_fabric_s *fabric, struct fchs_s *fchs,
1390 u16 len)
1391{
1392 struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
1393
1394 bfa_trc(fabric->fcs, els_cmd->els_code);
1395
1396 switch (els_cmd->els_code) {
1397 case FC_ELS_FLOGI:
1398 bfa_fcs_fabric_process_flogi(fabric, fchs, len);
1399 break;
1400
1401 default:
1402 /*
1403 * need to generate a LS_RJT
1404 */
1405 break;
1406 }
1407}
1408
Jing Huang5fbe25c2010-10-18 17:17:23 -07001409/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001410 * Process incoming FLOGI
1411 */
1412static void
1413bfa_fcs_fabric_process_flogi(struct bfa_fcs_fabric_s *fabric,
1414 struct fchs_s *fchs, u16 len)
1415{
1416 struct fc_logi_s *flogi = (struct fc_logi_s *) (fchs + 1);
1417 struct bfa_fcs_lport_s *bport = &fabric->bport;
1418
1419 bfa_trc(fabric->fcs, fchs->s_id);
1420
1421 fabric->stats.flogi_rcvd++;
1422 /*
1423 * Check port type. It should be 0 = n-port.
1424 */
1425 if (flogi->csp.port_type) {
1426 /*
1427 * @todo: may need to send a LS_RJT
1428 */
1429 bfa_trc(fabric->fcs, flogi->port_name);
1430 fabric->stats.flogi_rejected++;
1431 return;
1432 }
1433
Jing Huangba816ea2010-10-18 17:10:50 -07001434 fabric->bb_credit = be16_to_cpu(flogi->csp.bbcred);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001435 bport->port_topo.pn2n.rem_port_wwn = flogi->port_name;
1436 bport->port_topo.pn2n.reply_oxid = fchs->ox_id;
1437
1438 /*
1439 * Send a Flogi Acc
1440 */
1441 bfa_fcs_fabric_send_flogi_acc(fabric);
1442 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_NO_FABRIC);
1443}
1444
1445static void
1446bfa_fcs_fabric_send_flogi_acc(struct bfa_fcs_fabric_s *fabric)
1447{
1448 struct bfa_lport_cfg_s *pcfg = &fabric->bport.port_cfg;
1449 struct bfa_fcs_lport_n2n_s *n2n_port = &fabric->bport.port_topo.pn2n;
1450 struct bfa_s *bfa = fabric->fcs->bfa;
1451 struct bfa_fcxp_s *fcxp;
1452 u16 reqlen;
1453 struct fchs_s fchs;
1454
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07001455 fcxp = bfa_fcs_fcxp_alloc(fabric->fcs, BFA_FALSE);
Jing Huang5fbe25c2010-10-18 17:17:23 -07001456 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001457 * Do not expect this failure -- expect remote node to retry
1458 */
1459 if (!fcxp)
1460 return;
1461
1462 reqlen = fc_flogi_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
Maggie Zhangf16a1752010-12-09 19:12:32 -08001463 bfa_hton3b(FC_FABRIC_PORT),
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001464 n2n_port->reply_oxid, pcfg->pwwn,
1465 pcfg->nwwn,
1466 bfa_fcport_get_maxfrsize(bfa),
Vijaya Mohan Guvvabbe37a62013-05-13 02:33:19 -07001467 bfa_fcport_get_rx_bbcredit(bfa), 0);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001468
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001469 bfa_fcxp_send(fcxp, NULL, fabric->vf_id, fabric->lps->bfa_tag,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001470 BFA_FALSE, FC_CLASS_3,
1471 reqlen, &fchs, bfa_fcs_fabric_flogiacc_comp, fabric,
1472 FC_MAX_PDUSZ, 0);
1473}
1474
Jing Huang5fbe25c2010-10-18 17:17:23 -07001475/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001476 * Flogi Acc completion callback.
1477 */
1478static void
1479bfa_fcs_fabric_flogiacc_comp(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
1480 bfa_status_t status, u32 rsp_len,
1481 u32 resid_len, struct fchs_s *rspfchs)
1482{
1483 struct bfa_fcs_fabric_s *fabric = cbarg;
1484
1485 bfa_trc(fabric->fcs, status);
1486}
1487
Krishna Gudipati7826f302011-07-20 16:59:13 -07001488
1489/*
1490 * Send AEN notification
1491 */
1492static void
1493bfa_fcs_fabric_aen_post(struct bfa_fcs_lport_s *port,
1494 enum bfa_port_aen_event event)
1495{
1496 struct bfad_s *bfad = (struct bfad_s *)port->fabric->fcs->bfad;
1497 struct bfa_aen_entry_s *aen_entry;
1498
1499 bfad_get_aen_entry(bfad, aen_entry);
1500 if (!aen_entry)
1501 return;
1502
1503 aen_entry->aen_data.port.pwwn = bfa_fcs_lport_get_pwwn(port);
1504 aen_entry->aen_data.port.fwwn = bfa_fcs_lport_get_fabric_name(port);
1505
1506 /* Send the AEN notification */
1507 bfad_im_post_vendor_event(aen_entry, bfad, ++port->fcs->fcs_aen_seq,
1508 BFA_AEN_CAT_PORT, event);
1509}
1510
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001511/*
1512 *
1513 * @param[in] fabric - fabric
1514 * @param[in] wwn_t - new fabric name
1515 *
1516 * @return - none
1517 */
1518void
1519bfa_fcs_fabric_set_fabric_name(struct bfa_fcs_fabric_s *fabric,
1520 wwn_t fabric_name)
1521{
1522 struct bfad_s *bfad = (struct bfad_s *)fabric->fcs->bfad;
1523 char pwwn_ptr[BFA_STRING_32];
1524 char fwwn_ptr[BFA_STRING_32];
1525
1526 bfa_trc(fabric->fcs, fabric_name);
1527
1528 if (fabric->fabric_name == 0) {
1529 /*
1530 * With BRCD switches, we don't get Fabric Name in FLOGI.
1531 * Don't generate a fabric name change event in this case.
1532 */
1533 fabric->fabric_name = fabric_name;
1534 } else {
1535 fabric->fabric_name = fabric_name;
1536 wwn2str(pwwn_ptr, bfa_fcs_lport_get_pwwn(&fabric->bport));
1537 wwn2str(fwwn_ptr,
1538 bfa_fcs_lport_get_fabric_name(&fabric->bport));
Jing Huang88166242010-12-09 17:11:53 -08001539 BFA_LOG(KERN_WARNING, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001540 "Base port WWN = %s Fabric WWN = %s\n",
1541 pwwn_ptr, fwwn_ptr);
Krishna Gudipati7826f302011-07-20 16:59:13 -07001542 bfa_fcs_fabric_aen_post(&fabric->bport,
1543 BFA_PORT_AEN_FABRIC_NAME_CHANGE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001544 }
1545}
1546
Krishna Gudipati881c1b32012-08-22 19:52:02 -07001547void
1548bfa_cb_lps_flogo_comp(void *bfad, void *uarg)
1549{
1550 struct bfa_fcs_fabric_s *fabric = uarg;
1551 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_LOGOCOMP);
1552}
1553
Jing Huang5fbe25c2010-10-18 17:17:23 -07001554/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001555 * Returns FCS vf structure for a given vf_id.
1556 *
1557 * param[in] vf_id - VF_ID
1558 *
1559 * return
1560 * If lookup succeeds, retuns fcs vf object, otherwise returns NULL
1561 */
1562bfa_fcs_vf_t *
1563bfa_fcs_vf_lookup(struct bfa_fcs_s *fcs, u16 vf_id)
1564{
1565 bfa_trc(fcs, vf_id);
1566 if (vf_id == FC_VF_ID_NULL)
1567 return &fcs->fabric;
1568
1569 return NULL;
1570}
1571
Jing Huang5fbe25c2010-10-18 17:17:23 -07001572/*
Krishna Gudipatib85daaf2011-06-13 15:55:11 -07001573 * Return the list of local logical ports present in the given VF.
1574 *
1575 * @param[in] vf vf for which logical ports are returned
1576 * @param[out] lpwwn returned logical port wwn list
1577 * @param[in,out] nlports in:size of lpwwn list;
1578 * out:total elements present,
1579 * actual elements returned is limited by the size
1580 */
1581void
1582bfa_fcs_vf_get_ports(bfa_fcs_vf_t *vf, wwn_t lpwwn[], int *nlports)
1583{
1584 struct list_head *qe;
1585 struct bfa_fcs_vport_s *vport;
1586 int i = 0;
1587 struct bfa_fcs_s *fcs;
1588
1589 if (vf == NULL || lpwwn == NULL || *nlports == 0)
1590 return;
1591
1592 fcs = vf->fcs;
1593
1594 bfa_trc(fcs, vf->vf_id);
1595 bfa_trc(fcs, (uint32_t) *nlports);
1596
1597 lpwwn[i++] = vf->bport.port_cfg.pwwn;
1598
1599 list_for_each(qe, &vf->vport_q) {
1600 if (i >= *nlports)
1601 break;
1602
1603 vport = (struct bfa_fcs_vport_s *) qe;
1604 lpwwn[i++] = vport->lport.port_cfg.pwwn;
1605 }
1606
1607 bfa_trc(fcs, i);
1608 *nlports = i;
1609}
1610
1611/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001612 * BFA FCS PPORT ( physical port)
1613 */
1614static void
1615bfa_fcs_port_event_handler(void *cbarg, enum bfa_port_linkstate event)
1616{
1617 struct bfa_fcs_s *fcs = cbarg;
1618
1619 bfa_trc(fcs, event);
1620
1621 switch (event) {
1622 case BFA_PORT_LINKUP:
1623 bfa_fcs_fabric_link_up(&fcs->fabric);
1624 break;
1625
1626 case BFA_PORT_LINKDOWN:
1627 bfa_fcs_fabric_link_down(&fcs->fabric);
1628 break;
1629
1630 default:
Jing Huangd4b671c2010-12-26 21:46:35 -08001631 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001632 }
1633}
1634
1635void
1636bfa_fcs_port_attach(struct bfa_fcs_s *fcs)
1637{
1638 bfa_fcport_event_register(fcs->bfa, bfa_fcs_port_event_handler, fcs);
1639}
1640
Jing Huang5fbe25c2010-10-18 17:17:23 -07001641/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001642 * BFA FCS UF ( Unsolicited Frames)
1643 */
1644
Jing Huang5fbe25c2010-10-18 17:17:23 -07001645/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001646 * BFA callback for unsolicited frame receive handler.
1647 *
1648 * @param[in] cbarg callback arg for receive handler
1649 * @param[in] uf unsolicited frame descriptor
1650 *
1651 * @return None
1652 */
1653static void
1654bfa_fcs_uf_recv(void *cbarg, struct bfa_uf_s *uf)
1655{
1656 struct bfa_fcs_s *fcs = (struct bfa_fcs_s *) cbarg;
1657 struct fchs_s *fchs = bfa_uf_get_frmbuf(uf);
1658 u16 len = bfa_uf_get_frmlen(uf);
1659 struct fc_vft_s *vft;
1660 struct bfa_fcs_fabric_s *fabric;
1661
Jing Huang5fbe25c2010-10-18 17:17:23 -07001662 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001663 * check for VFT header
1664 */
1665 if (fchs->routing == FC_RTG_EXT_HDR &&
1666 fchs->cat_info == FC_CAT_VFT_HDR) {
1667 bfa_stats(fcs, uf.tagged);
1668 vft = bfa_uf_get_frmbuf(uf);
1669 if (fcs->port_vfid == vft->vf_id)
1670 fabric = &fcs->fabric;
1671 else
1672 fabric = bfa_fcs_vf_lookup(fcs, (u16) vft->vf_id);
1673
Jing Huang5fbe25c2010-10-18 17:17:23 -07001674 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001675 * drop frame if vfid is unknown
1676 */
1677 if (!fabric) {
Jing Huangd4b671c2010-12-26 21:46:35 -08001678 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001679 bfa_stats(fcs, uf.vfid_unknown);
1680 bfa_uf_free(uf);
1681 return;
1682 }
1683
Jing Huang5fbe25c2010-10-18 17:17:23 -07001684 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001685 * skip vft header
1686 */
1687 fchs = (struct fchs_s *) (vft + 1);
1688 len -= sizeof(struct fc_vft_s);
1689
1690 bfa_trc(fcs, vft->vf_id);
1691 } else {
1692 bfa_stats(fcs, uf.untagged);
1693 fabric = &fcs->fabric;
1694 }
1695
1696 bfa_trc(fcs, ((u32 *) fchs)[0]);
1697 bfa_trc(fcs, ((u32 *) fchs)[1]);
1698 bfa_trc(fcs, ((u32 *) fchs)[2]);
1699 bfa_trc(fcs, ((u32 *) fchs)[3]);
1700 bfa_trc(fcs, ((u32 *) fchs)[4]);
1701 bfa_trc(fcs, ((u32 *) fchs)[5]);
1702 bfa_trc(fcs, len);
1703
1704 bfa_fcs_fabric_uf_recv(fabric, fchs, len);
1705 bfa_uf_free(uf);
1706}
1707
1708void
1709bfa_fcs_uf_attach(struct bfa_fcs_s *fcs)
1710{
1711 bfa_uf_recv_register(fcs->bfa, bfa_fcs_uf_recv, fcs);
1712}