blob: d2d396ca0e9a04a056595e83b77a9d937d3deae8 [file] [log] [blame]
Thomas Gleixner52fa7bf2019-05-29 07:18:06 -07001// SPDX-License-Identifier: GPL-2.0-only
Jing Huang7725ccf2009-09-23 17:46:15 -07002/*
Anil Gurumurthy889d0d42015-11-26 03:54:45 -05003 * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
4 * Copyright (c) 2014- QLogic Corporation.
Jing Huang7725ccf2009-09-23 17:46:15 -07005 * All rights reserved
Anil Gurumurthy889d0d42015-11-26 03:54:45 -05006 * www.qlogic.com
Jing Huang7725ccf2009-09-23 17:46:15 -07007 *
Anil Gurumurthy31e1d562015-11-26 03:54:46 -05008 * Linux driver for QLogic BR-series Fibre Channel Host Bus Adapter.
Jing Huang7725ccf2009-09-23 17:46:15 -07009 */
10
Jing Huang5fbe25c2010-10-18 17:17:23 -070011/*
Jing Huang7725ccf2009-09-23 17:46:15 -070012 * bfa_fcs.c BFA FCS main
13 */
14
Maggie Zhangf16a1752010-12-09 19:12:32 -080015#include "bfad_drv.h"
Krishna Gudipati7826f302011-07-20 16:59:13 -070016#include "bfad_im.h"
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070017#include "bfa_fcs.h"
18#include "bfa_fcbuild.h"
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070019
20BFA_TRC_FILE(FCS, FCS);
Jing Huang7725ccf2009-09-23 17:46:15 -070021
Jing Huang5fbe25c2010-10-18 17:17:23 -070022/*
Jing Huang7725ccf2009-09-23 17:46:15 -070023 * fcs_api BFA FCS API
24 */
25
26static void
27bfa_fcs_exit_comp(void *fcs_cbarg)
28{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070029 struct bfa_fcs_s *fcs = fcs_cbarg;
30 struct bfad_s *bfad = fcs->bfad;
Jing Huang7725ccf2009-09-23 17:46:15 -070031
32 complete(&bfad->comp);
33}
34
Jing Huang5fbe25c2010-10-18 17:17:23 -070035/*
Krishna Gudipati82794a22010-03-03 17:43:30 -080036 * fcs initialization, called once after bfa initialization is complete
37 */
38void
39bfa_fcs_init(struct bfa_fcs_s *fcs)
40{
Christoph Hellwig984dc462017-01-08 10:41:15 +010041 bfa_sm_send_event(&fcs->fabric, BFA_FCS_FABRIC_SM_CREATE);
42 bfa_trc(fcs, 0);
Krishna Gudipati75332a72011-06-13 15:54:31 -070043}
44
45/*
Christoph Hellwig984dc462017-01-08 10:41:15 +010046 * fcs_api BFA FCS API
47 */
48
49/*
Krishna Gudipati75332a72011-06-13 15:54:31 -070050 * FCS update cfg - reset the pwwn/nwwn of fabric base logical port
51 * with values learned during bfa_init firmware GETATTR REQ.
52 */
53void
54bfa_fcs_update_cfg(struct bfa_fcs_s *fcs)
55{
56 struct bfa_fcs_fabric_s *fabric = &fcs->fabric;
57 struct bfa_lport_cfg_s *port_cfg = &fabric->bport.port_cfg;
58 struct bfa_ioc_s *ioc = &fabric->fcs->bfa->ioc;
59
60 port_cfg->nwwn = ioc->attr->nwwn;
61 port_cfg->pwwn = ioc->attr->pwwn;
62}
63
64/*
Krishna Gudipati881c1b32012-08-22 19:52:02 -070065 * Stop FCS operations.
66 */
67void
68bfa_fcs_stop(struct bfa_fcs_s *fcs)
69{
70 bfa_wc_init(&fcs->wc, bfa_fcs_exit_comp, fcs);
71 bfa_wc_up(&fcs->wc);
72 bfa_fcs_fabric_modstop(fcs);
73 bfa_wc_wait(&fcs->wc);
74}
75
76/*
Krishna Gudipati75332a72011-06-13 15:54:31 -070077 * fcs pbc vport initialization
78 */
79void
80bfa_fcs_pbc_vport_init(struct bfa_fcs_s *fcs)
81{
82 int i, npbc_vports;
83 struct bfi_pbc_vport_s pbc_vports[BFI_PBC_MAX_VPORTS];
84
Jing Huangd9883542010-07-08 19:46:26 -070085 /* Initialize pbc vports */
86 if (!fcs->min_cfg) {
87 npbc_vports =
Krishna Gudipati75332a72011-06-13 15:54:31 -070088 bfa_iocfc_get_pbc_vports(fcs->bfa, pbc_vports);
Jing Huangd9883542010-07-08 19:46:26 -070089 for (i = 0; i < npbc_vports; i++)
90 bfa_fcb_pbc_vport_create(fcs->bfa->bfad, pbc_vports[i]);
91 }
Jing Huang7725ccf2009-09-23 17:46:15 -070092}
93
Jing Huang5fbe25c2010-10-18 17:17:23 -070094/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070095 * brief
96 * FCS driver details initialization.
Jing Huang7725ccf2009-09-23 17:46:15 -070097 *
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070098 * param[in] fcs FCS instance
99 * param[in] driver_info Driver Details
Jing Huang7725ccf2009-09-23 17:46:15 -0700100 *
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700101 * return None
Jing Huang7725ccf2009-09-23 17:46:15 -0700102 */
103void
104bfa_fcs_driver_info_init(struct bfa_fcs_s *fcs,
105 struct bfa_fcs_driver_info_s *driver_info)
106{
107
108 fcs->driver_info = *driver_info;
109
110 bfa_fcs_fabric_psymb_init(&fcs->fabric);
Krishna Gudipatice7242b2012-08-22 19:52:43 -0700111 bfa_fcs_fabric_nsymb_init(&fcs->fabric);
Jing Huang7725ccf2009-09-23 17:46:15 -0700112}
113
Jing Huang5fbe25c2010-10-18 17:17:23 -0700114/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700115 * brief
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700116 * FCS instance cleanup and exit.
Jing Huang7725ccf2009-09-23 17:46:15 -0700117 *
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700118 * param[in] fcs FCS instance
119 * return None
Jing Huang7725ccf2009-09-23 17:46:15 -0700120 */
121void
122bfa_fcs_exit(struct bfa_fcs_s *fcs)
123{
Jing Huang7725ccf2009-09-23 17:46:15 -0700124 bfa_wc_init(&fcs->wc, bfa_fcs_exit_comp, fcs);
Christoph Hellwig984dc462017-01-08 10:41:15 +0100125 bfa_wc_up(&fcs->wc);
126 bfa_trc(fcs, 0);
127 bfa_lps_delete(fcs->fabric.lps);
128 bfa_sm_send_event(&fcs->fabric, BFA_FCS_FABRIC_SM_DELETE);
Jing Huang7725ccf2009-09-23 17:46:15 -0700129 bfa_wc_wait(&fcs->wc);
130}
131
Jing Huang5fbe25c2010-10-18 17:17:23 -0700132/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700133 * Fabric module implementation.
134 */
Jing Huang7725ccf2009-09-23 17:46:15 -0700135
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700136#define BFA_FCS_FABRIC_RETRY_DELAY (2000) /* Milliseconds */
137#define BFA_FCS_FABRIC_CLEANUP_DELAY (10000) /* Milliseconds */
138
139#define bfa_fcs_fabric_set_opertype(__fabric) do { \
Krishna Gudipatid7be54c2011-06-24 20:24:52 -0700140 if (bfa_fcport_get_topology((__fabric)->fcs->bfa) \
141 == BFA_PORT_TOPOLOGY_P2P) { \
142 if (fabric->fab_type == BFA_FCS_FABRIC_SWITCHED) \
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700143 (__fabric)->oper_type = BFA_PORT_TYPE_NPORT; \
144 else \
Krishna Gudipatid7be54c2011-06-24 20:24:52 -0700145 (__fabric)->oper_type = BFA_PORT_TYPE_P2P; \
146 } else \
147 (__fabric)->oper_type = BFA_PORT_TYPE_NLPORT; \
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700148} while (0)
149
150/*
151 * forward declarations
152 */
153static void bfa_fcs_fabric_init(struct bfa_fcs_fabric_s *fabric);
154static void bfa_fcs_fabric_login(struct bfa_fcs_fabric_s *fabric);
155static void bfa_fcs_fabric_notify_online(struct bfa_fcs_fabric_s *fabric);
156static void bfa_fcs_fabric_notify_offline(struct bfa_fcs_fabric_s *fabric);
157static void bfa_fcs_fabric_delay(void *cbarg);
158static void bfa_fcs_fabric_delete(struct bfa_fcs_fabric_s *fabric);
159static void bfa_fcs_fabric_delete_comp(void *cbarg);
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700160static void bfa_fcs_fabric_stop(struct bfa_fcs_fabric_s *fabric);
161static void bfa_fcs_fabric_stop_comp(void *cbarg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700162static void bfa_fcs_fabric_process_uf(struct bfa_fcs_fabric_s *fabric,
163 struct fchs_s *fchs, u16 len);
164static void bfa_fcs_fabric_process_flogi(struct bfa_fcs_fabric_s *fabric,
165 struct fchs_s *fchs, u16 len);
166static void bfa_fcs_fabric_send_flogi_acc(struct bfa_fcs_fabric_s *fabric);
167static void bfa_fcs_fabric_flogiacc_comp(void *fcsarg,
168 struct bfa_fcxp_s *fcxp, void *cbarg,
169 bfa_status_t status,
170 u32 rsp_len,
171 u32 resid_len,
172 struct fchs_s *rspfchs);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700173
174static void bfa_fcs_fabric_sm_uninit(struct bfa_fcs_fabric_s *fabric,
175 enum bfa_fcs_fabric_event event);
176static void bfa_fcs_fabric_sm_created(struct bfa_fcs_fabric_s *fabric,
177 enum bfa_fcs_fabric_event event);
178static void bfa_fcs_fabric_sm_linkdown(struct bfa_fcs_fabric_s *fabric,
179 enum bfa_fcs_fabric_event event);
180static void bfa_fcs_fabric_sm_flogi(struct bfa_fcs_fabric_s *fabric,
181 enum bfa_fcs_fabric_event event);
182static void bfa_fcs_fabric_sm_flogi_retry(struct bfa_fcs_fabric_s *fabric,
183 enum bfa_fcs_fabric_event event);
184static void bfa_fcs_fabric_sm_auth(struct bfa_fcs_fabric_s *fabric,
185 enum bfa_fcs_fabric_event event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700186static void bfa_fcs_fabric_sm_nofabric(struct bfa_fcs_fabric_s *fabric,
187 enum bfa_fcs_fabric_event event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700188static void bfa_fcs_fabric_sm_evfp(struct bfa_fcs_fabric_s *fabric,
189 enum bfa_fcs_fabric_event event);
190static void bfa_fcs_fabric_sm_evfp_done(struct bfa_fcs_fabric_s *fabric,
191 enum bfa_fcs_fabric_event event);
192static void bfa_fcs_fabric_sm_isolated(struct bfa_fcs_fabric_s *fabric,
193 enum bfa_fcs_fabric_event event);
194static void bfa_fcs_fabric_sm_deleting(struct bfa_fcs_fabric_s *fabric,
195 enum bfa_fcs_fabric_event event);
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700196static void bfa_fcs_fabric_sm_stopping(struct bfa_fcs_fabric_s *fabric,
197 enum bfa_fcs_fabric_event event);
198static void bfa_fcs_fabric_sm_cleanup(struct bfa_fcs_fabric_s *fabric,
199 enum bfa_fcs_fabric_event event);
Jing Huang5fbe25c2010-10-18 17:17:23 -0700200/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700201 * Beginning state before fabric creation.
202 */
203static void
204bfa_fcs_fabric_sm_uninit(struct bfa_fcs_fabric_s *fabric,
205 enum bfa_fcs_fabric_event event)
206{
207 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
208 bfa_trc(fabric->fcs, event);
209
210 switch (event) {
211 case BFA_FCS_FABRIC_SM_CREATE:
212 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_created);
213 bfa_fcs_fabric_init(fabric);
214 bfa_fcs_lport_init(&fabric->bport, &fabric->bport.port_cfg);
215 break;
216
217 case BFA_FCS_FABRIC_SM_LINK_UP:
218 case BFA_FCS_FABRIC_SM_LINK_DOWN:
219 break;
220
221 default:
222 bfa_sm_fault(fabric->fcs, event);
223 }
224}
225
Jing Huang5fbe25c2010-10-18 17:17:23 -0700226/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700227 * Beginning state before fabric creation.
228 */
229static void
230bfa_fcs_fabric_sm_created(struct bfa_fcs_fabric_s *fabric,
231 enum bfa_fcs_fabric_event event)
232{
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -0700233 struct bfa_s *bfa = fabric->fcs->bfa;
234
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700235 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
236 bfa_trc(fabric->fcs, event);
237
238 switch (event) {
239 case BFA_FCS_FABRIC_SM_START:
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -0700240 if (!bfa_fcport_is_linkup(fabric->fcs->bfa)) {
241 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
242 break;
243 }
244 if (bfa_fcport_get_topology(bfa) ==
245 BFA_PORT_TOPOLOGY_LOOP) {
246 fabric->fab_type = BFA_FCS_FABRIC_LOOP;
247 fabric->bport.pid = bfa_fcport_get_myalpa(bfa);
248 fabric->bport.pid = bfa_hton3b(fabric->bport.pid);
249 bfa_sm_set_state(fabric,
250 bfa_fcs_fabric_sm_online);
251 bfa_fcs_fabric_set_opertype(fabric);
252 bfa_fcs_lport_online(&fabric->bport);
253 } else {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700254 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_flogi);
255 bfa_fcs_fabric_login(fabric);
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -0700256 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700257 break;
258
259 case BFA_FCS_FABRIC_SM_LINK_UP:
260 case BFA_FCS_FABRIC_SM_LINK_DOWN:
261 break;
262
263 case BFA_FCS_FABRIC_SM_DELETE:
Krishna Gudipatidd5aaf42011-06-13 15:51:24 -0700264 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
265 bfa_fcs_fabric_delete(fabric);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700266 break;
267
268 default:
269 bfa_sm_fault(fabric->fcs, event);
270 }
271}
272
Jing Huang5fbe25c2010-10-18 17:17:23 -0700273/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700274 * Link is down, awaiting LINK UP event from port. This is also the
275 * first state at fabric creation.
276 */
277static void
278bfa_fcs_fabric_sm_linkdown(struct bfa_fcs_fabric_s *fabric,
279 enum bfa_fcs_fabric_event event)
280{
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -0700281 struct bfa_s *bfa = fabric->fcs->bfa;
282
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700283 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
284 bfa_trc(fabric->fcs, event);
285
286 switch (event) {
287 case BFA_FCS_FABRIC_SM_LINK_UP:
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -0700288 if (bfa_fcport_get_topology(bfa) != BFA_PORT_TOPOLOGY_LOOP) {
289 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_flogi);
290 bfa_fcs_fabric_login(fabric);
291 break;
292 }
293 fabric->fab_type = BFA_FCS_FABRIC_LOOP;
294 fabric->bport.pid = bfa_fcport_get_myalpa(bfa);
295 fabric->bport.pid = bfa_hton3b(fabric->bport.pid);
296 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_online);
297 bfa_fcs_fabric_set_opertype(fabric);
298 bfa_fcs_lport_online(&fabric->bport);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700299 break;
300
301 case BFA_FCS_FABRIC_SM_RETRY_OP:
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -0700302 case BFA_FCS_FABRIC_SM_LOOPBACK:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700303 break;
304
305 case BFA_FCS_FABRIC_SM_DELETE:
306 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
307 bfa_fcs_fabric_delete(fabric);
308 break;
309
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700310 case BFA_FCS_FABRIC_SM_STOP:
311 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_cleanup);
312 bfa_fcs_fabric_stop(fabric);
313 break;
314
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700315 default:
316 bfa_sm_fault(fabric->fcs, event);
317 }
318}
319
Jing Huang5fbe25c2010-10-18 17:17:23 -0700320/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700321 * FLOGI is in progress, awaiting FLOGI reply.
322 */
323static void
324bfa_fcs_fabric_sm_flogi(struct bfa_fcs_fabric_s *fabric,
325 enum bfa_fcs_fabric_event event)
326{
327 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
328 bfa_trc(fabric->fcs, event);
329
330 switch (event) {
331 case BFA_FCS_FABRIC_SM_CONT_OP:
332
333 bfa_fcport_set_tx_bbcredit(fabric->fcs->bfa,
Vijaya Mohan Guvvabbe37a62013-05-13 02:33:19 -0700334 fabric->bb_credit);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700335 fabric->fab_type = BFA_FCS_FABRIC_SWITCHED;
336
337 if (fabric->auth_reqd && fabric->is_auth) {
338 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_auth);
339 bfa_trc(fabric->fcs, event);
340 } else {
341 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_online);
342 bfa_fcs_fabric_notify_online(fabric);
343 }
344 break;
345
346 case BFA_FCS_FABRIC_SM_RETRY_OP:
347 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_flogi_retry);
348 bfa_timer_start(fabric->fcs->bfa, &fabric->delay_timer,
349 bfa_fcs_fabric_delay, fabric,
350 BFA_FCS_FABRIC_RETRY_DELAY);
351 break;
352
353 case BFA_FCS_FABRIC_SM_LOOPBACK:
354 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_loopback);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800355 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700356 bfa_fcs_fabric_set_opertype(fabric);
357 break;
358
359 case BFA_FCS_FABRIC_SM_NO_FABRIC:
360 fabric->fab_type = BFA_FCS_FABRIC_N2N;
361 bfa_fcport_set_tx_bbcredit(fabric->fcs->bfa,
Vijaya Mohan Guvvabbe37a62013-05-13 02:33:19 -0700362 fabric->bb_credit);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700363 bfa_fcs_fabric_notify_online(fabric);
364 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_nofabric);
365 break;
366
367 case BFA_FCS_FABRIC_SM_LINK_DOWN:
368 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800369 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700370 break;
371
372 case BFA_FCS_FABRIC_SM_DELETE:
373 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800374 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700375 bfa_fcs_fabric_delete(fabric);
376 break;
377
378 default:
379 bfa_sm_fault(fabric->fcs, event);
380 }
381}
382
383
384static void
385bfa_fcs_fabric_sm_flogi_retry(struct bfa_fcs_fabric_s *fabric,
386 enum bfa_fcs_fabric_event event)
387{
388 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
389 bfa_trc(fabric->fcs, event);
390
391 switch (event) {
392 case BFA_FCS_FABRIC_SM_DELAYED:
393 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_flogi);
394 bfa_fcs_fabric_login(fabric);
395 break;
396
397 case BFA_FCS_FABRIC_SM_LINK_DOWN:
398 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
399 bfa_timer_stop(&fabric->delay_timer);
400 break;
401
402 case BFA_FCS_FABRIC_SM_DELETE:
403 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
404 bfa_timer_stop(&fabric->delay_timer);
405 bfa_fcs_fabric_delete(fabric);
406 break;
407
408 default:
409 bfa_sm_fault(fabric->fcs, event);
410 }
411}
412
Jing Huang5fbe25c2010-10-18 17:17:23 -0700413/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700414 * Authentication is in progress, awaiting authentication results.
415 */
416static void
417bfa_fcs_fabric_sm_auth(struct bfa_fcs_fabric_s *fabric,
418 enum bfa_fcs_fabric_event event)
419{
420 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
421 bfa_trc(fabric->fcs, event);
422
423 switch (event) {
424 case BFA_FCS_FABRIC_SM_AUTH_FAILED:
425 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_auth_failed);
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 break;
428
429 case BFA_FCS_FABRIC_SM_AUTH_SUCCESS:
430 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_online);
431 bfa_fcs_fabric_notify_online(fabric);
432 break;
433
434 case BFA_FCS_FABRIC_SM_PERF_EVFP:
435 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_evfp);
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);
445 bfa_fcs_fabric_delete(fabric);
446 break;
447
448 default:
449 bfa_sm_fault(fabric->fcs, event);
450 }
451}
452
Jing Huang5fbe25c2010-10-18 17:17:23 -0700453/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700454 * Authentication failed
455 */
Maggie Zhangf7f738122010-12-09 19:08:43 -0800456void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700457bfa_fcs_fabric_sm_auth_failed(struct bfa_fcs_fabric_s *fabric,
458 enum bfa_fcs_fabric_event event)
459{
460 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
461 bfa_trc(fabric->fcs, event);
462
463 switch (event) {
464 case BFA_FCS_FABRIC_SM_LINK_DOWN:
465 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
466 bfa_fcs_fabric_notify_offline(fabric);
467 break;
468
469 case BFA_FCS_FABRIC_SM_DELETE:
470 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
471 bfa_fcs_fabric_delete(fabric);
472 break;
473
474 default:
475 bfa_sm_fault(fabric->fcs, event);
476 }
477}
478
Jing Huang5fbe25c2010-10-18 17:17:23 -0700479/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700480 * Port is in loopback mode.
481 */
Maggie Zhangf7f738122010-12-09 19:08:43 -0800482void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700483bfa_fcs_fabric_sm_loopback(struct bfa_fcs_fabric_s *fabric,
484 enum bfa_fcs_fabric_event event)
485{
486 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
487 bfa_trc(fabric->fcs, event);
488
489 switch (event) {
490 case BFA_FCS_FABRIC_SM_LINK_DOWN:
491 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
492 bfa_fcs_fabric_notify_offline(fabric);
493 break;
494
495 case BFA_FCS_FABRIC_SM_DELETE:
496 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
497 bfa_fcs_fabric_delete(fabric);
498 break;
499
500 default:
501 bfa_sm_fault(fabric->fcs, event);
502 }
503}
504
Jing Huang5fbe25c2010-10-18 17:17:23 -0700505/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700506 * There is no attached fabric - private loop or NPort-to-NPort topology.
507 */
508static void
509bfa_fcs_fabric_sm_nofabric(struct bfa_fcs_fabric_s *fabric,
510 enum bfa_fcs_fabric_event event)
511{
512 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
513 bfa_trc(fabric->fcs, event);
514
515 switch (event) {
516 case BFA_FCS_FABRIC_SM_LINK_DOWN:
517 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800518 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700519 bfa_fcs_fabric_notify_offline(fabric);
520 break;
521
522 case BFA_FCS_FABRIC_SM_DELETE:
523 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
524 bfa_fcs_fabric_delete(fabric);
525 break;
526
527 case BFA_FCS_FABRIC_SM_NO_FABRIC:
528 bfa_trc(fabric->fcs, fabric->bb_credit);
529 bfa_fcport_set_tx_bbcredit(fabric->fcs->bfa,
Vijaya Mohan Guvvabbe37a62013-05-13 02:33:19 -0700530 fabric->bb_credit);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700531 break;
532
Krishna Gudipatid7be54c2011-06-24 20:24:52 -0700533 case BFA_FCS_FABRIC_SM_RETRY_OP:
534 break;
535
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700536 default:
537 bfa_sm_fault(fabric->fcs, event);
538 }
539}
540
Jing Huang5fbe25c2010-10-18 17:17:23 -0700541/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700542 * Fabric is online - normal operating state.
543 */
Maggie Zhangf7f738122010-12-09 19:08:43 -0800544void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700545bfa_fcs_fabric_sm_online(struct bfa_fcs_fabric_s *fabric,
546 enum bfa_fcs_fabric_event event)
547{
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -0700548 struct bfa_s *bfa = fabric->fcs->bfa;
549
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700550 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
551 bfa_trc(fabric->fcs, event);
552
553 switch (event) {
554 case BFA_FCS_FABRIC_SM_LINK_DOWN:
555 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -0700556 if (bfa_fcport_get_topology(bfa) == BFA_PORT_TOPOLOGY_LOOP) {
557 bfa_fcs_lport_offline(&fabric->bport);
558 } else {
559 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
560 bfa_fcs_fabric_notify_offline(fabric);
561 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700562 break;
563
564 case BFA_FCS_FABRIC_SM_DELETE:
565 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
566 bfa_fcs_fabric_delete(fabric);
567 break;
568
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700569 case BFA_FCS_FABRIC_SM_STOP:
570 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_stopping);
571 bfa_fcs_fabric_stop(fabric);
572 break;
573
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700574 case BFA_FCS_FABRIC_SM_AUTH_FAILED:
575 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_auth_failed);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800576 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_OFFLINE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700577 break;
578
579 case BFA_FCS_FABRIC_SM_AUTH_SUCCESS:
580 break;
581
582 default:
583 bfa_sm_fault(fabric->fcs, event);
584 }
585}
586
Jing Huang5fbe25c2010-10-18 17:17:23 -0700587/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700588 * Exchanging virtual fabric parameters.
589 */
590static void
591bfa_fcs_fabric_sm_evfp(struct bfa_fcs_fabric_s *fabric,
592 enum bfa_fcs_fabric_event event)
593{
594 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
595 bfa_trc(fabric->fcs, event);
596
597 switch (event) {
598 case BFA_FCS_FABRIC_SM_CONT_OP:
599 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_evfp_done);
600 break;
601
602 case BFA_FCS_FABRIC_SM_ISOLATE:
603 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_isolated);
604 break;
605
606 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 * EVFP exchange complete and VFT tagging is enabled.
613 */
614static void
615bfa_fcs_fabric_sm_evfp_done(struct bfa_fcs_fabric_s *fabric,
616 enum bfa_fcs_fabric_event event)
617{
618 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
619 bfa_trc(fabric->fcs, event);
620}
621
Jing Huang5fbe25c2010-10-18 17:17:23 -0700622/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700623 * Port is isolated after EVFP exchange due to VF_ID mismatch (N and F).
624 */
625static void
626bfa_fcs_fabric_sm_isolated(struct bfa_fcs_fabric_s *fabric,
627 enum bfa_fcs_fabric_event event)
628{
629 struct bfad_s *bfad = (struct bfad_s *)fabric->fcs->bfad;
630 char pwwn_ptr[BFA_STRING_32];
631
632 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
633 bfa_trc(fabric->fcs, event);
634 wwn2str(pwwn_ptr, fabric->bport.port_cfg.pwwn);
635
Jing Huang88166242010-12-09 17:11:53 -0800636 BFA_LOG(KERN_INFO, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700637 "Port is isolated due to VF_ID mismatch. "
638 "PWWN: %s Port VF_ID: %04x switch port VF_ID: %04x.",
639 pwwn_ptr, fabric->fcs->port_vfid,
640 fabric->event_arg.swp_vfid);
641}
642
Jing Huang5fbe25c2010-10-18 17:17:23 -0700643/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700644 * Fabric is being deleted, awaiting vport delete completions.
645 */
646static void
647bfa_fcs_fabric_sm_deleting(struct bfa_fcs_fabric_s *fabric,
648 enum bfa_fcs_fabric_event event)
649{
650 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
651 bfa_trc(fabric->fcs, event);
652
653 switch (event) {
654 case BFA_FCS_FABRIC_SM_DELCOMP:
655 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_uninit);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800656 bfa_wc_down(&fabric->fcs->wc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700657 break;
658
659 case BFA_FCS_FABRIC_SM_LINK_UP:
660 break;
661
662 case BFA_FCS_FABRIC_SM_LINK_DOWN:
663 bfa_fcs_fabric_notify_offline(fabric);
664 break;
665
666 default:
667 bfa_sm_fault(fabric->fcs, event);
668 }
669}
670
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700671/*
672 * Fabric is being stopped, awaiting vport stop completions.
673 */
674static void
675bfa_fcs_fabric_sm_stopping(struct bfa_fcs_fabric_s *fabric,
676 enum bfa_fcs_fabric_event event)
677{
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -0700678 struct bfa_s *bfa = fabric->fcs->bfa;
679
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700680 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
681 bfa_trc(fabric->fcs, event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700682
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700683 switch (event) {
684 case BFA_FCS_FABRIC_SM_STOPCOMP:
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -0700685 if (bfa_fcport_get_topology(bfa) == BFA_PORT_TOPOLOGY_LOOP) {
686 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_created);
687 } else {
688 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_cleanup);
689 bfa_sm_send_event(fabric->lps, BFA_LPS_SM_LOGOUT);
690 }
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700691 break;
692
693 case BFA_FCS_FABRIC_SM_LINK_UP:
694 break;
695
696 case BFA_FCS_FABRIC_SM_LINK_DOWN:
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -0700697 if (bfa_fcport_get_topology(bfa) == BFA_PORT_TOPOLOGY_LOOP)
698 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_created);
699 else
700 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_cleanup);
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700701 break;
702
703 default:
704 bfa_sm_fault(fabric->fcs, event);
705 }
706}
707
708/*
709 * Fabric is being stopped, cleanup without FLOGO
710 */
711static void
712bfa_fcs_fabric_sm_cleanup(struct bfa_fcs_fabric_s *fabric,
713 enum bfa_fcs_fabric_event event)
714{
715 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
716 bfa_trc(fabric->fcs, event);
717
718 switch (event) {
719 case BFA_FCS_FABRIC_SM_STOPCOMP:
720 case BFA_FCS_FABRIC_SM_LOGOCOMP:
721 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_created);
722 bfa_wc_down(&(fabric->fcs)->wc);
723 break;
724
725 case BFA_FCS_FABRIC_SM_LINK_DOWN:
726 /*
727 * Ignore - can get this event if we get notified about IOC down
728 * before the fabric completion callbk is done.
729 */
730 break;
731
732 default:
733 bfa_sm_fault(fabric->fcs, event);
734 }
735}
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700736
Jing Huang5fbe25c2010-10-18 17:17:23 -0700737/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700738 * fcs_fabric_private fabric private functions
739 */
740
741static void
742bfa_fcs_fabric_init(struct bfa_fcs_fabric_s *fabric)
743{
744 struct bfa_lport_cfg_s *port_cfg = &fabric->bport.port_cfg;
745
746 port_cfg->roles = BFA_LPORT_ROLE_FCP_IM;
Maggie Zhangf7f738122010-12-09 19:08:43 -0800747 port_cfg->nwwn = fabric->fcs->bfa->ioc.attr->nwwn;
748 port_cfg->pwwn = fabric->fcs->bfa->ioc.attr->pwwn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700749}
750
Jing Huang5fbe25c2010-10-18 17:17:23 -0700751/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700752 * Port Symbolic Name Creation for base port.
753 */
754void
755bfa_fcs_fabric_psymb_init(struct bfa_fcs_fabric_s *fabric)
756{
757 struct bfa_lport_cfg_s *port_cfg = &fabric->bport.port_cfg;
758 char model[BFA_ADAPTER_MODEL_NAME_LEN] = {0};
759 struct bfa_fcs_driver_info_s *driver_info = &fabric->fcs->driver_info;
760
761 bfa_ioc_get_adapter_model(&fabric->fcs->bfa->ioc, model);
762
763 /* Model name/number */
Arnd Bergmann8c5a50e2017-12-04 15:47:00 +0100764 strlcpy(port_cfg->sym_name.symname, model,
765 BFA_SYMNAME_MAXLEN);
766 strlcat(port_cfg->sym_name.symname, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
767 BFA_SYMNAME_MAXLEN);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700768
769 /* Driver Version */
Arnd Bergmann8c5a50e2017-12-04 15:47:00 +0100770 strlcat(port_cfg->sym_name.symname, driver_info->version,
771 BFA_SYMNAME_MAXLEN);
772 strlcat(port_cfg->sym_name.symname, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
773 BFA_SYMNAME_MAXLEN);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700774
775 /* Host machine name */
Arnd Bergmann8c5a50e2017-12-04 15:47:00 +0100776 strlcat(port_cfg->sym_name.symname,
777 driver_info->host_machine_name,
778 BFA_SYMNAME_MAXLEN);
779 strlcat(port_cfg->sym_name.symname, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
780 BFA_SYMNAME_MAXLEN);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700781
782 /*
783 * Host OS Info :
784 * If OS Patch Info is not there, do not truncate any bytes from the
785 * OS name string and instead copy the entire OS info string (64 bytes).
786 */
787 if (driver_info->host_os_patch[0] == '\0') {
Arnd Bergmann8c5a50e2017-12-04 15:47:00 +0100788 strlcat(port_cfg->sym_name.symname,
789 driver_info->host_os_name,
790 BFA_SYMNAME_MAXLEN);
791 strlcat(port_cfg->sym_name.symname,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700792 BFA_FCS_PORT_SYMBNAME_SEPARATOR,
Arnd Bergmann8c5a50e2017-12-04 15:47:00 +0100793 BFA_SYMNAME_MAXLEN);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700794 } else {
Arnd Bergmann8c5a50e2017-12-04 15:47:00 +0100795 strlcat(port_cfg->sym_name.symname,
796 driver_info->host_os_name,
797 BFA_SYMNAME_MAXLEN);
798 strlcat(port_cfg->sym_name.symname,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700799 BFA_FCS_PORT_SYMBNAME_SEPARATOR,
Arnd Bergmann8c5a50e2017-12-04 15:47:00 +0100800 BFA_SYMNAME_MAXLEN);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700801
802 /* Append host OS Patch Info */
Arnd Bergmann8c5a50e2017-12-04 15:47:00 +0100803 strlcat(port_cfg->sym_name.symname,
804 driver_info->host_os_patch,
805 BFA_SYMNAME_MAXLEN);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700806 }
807
808 /* null terminate */
809 port_cfg->sym_name.symname[BFA_SYMNAME_MAXLEN - 1] = 0;
810}
811
Jing Huang5fbe25c2010-10-18 17:17:23 -0700812/*
Krishna Gudipatice7242b2012-08-22 19:52:43 -0700813 * Node Symbolic Name Creation for base port and all vports
814 */
815void
816bfa_fcs_fabric_nsymb_init(struct bfa_fcs_fabric_s *fabric)
817{
818 struct bfa_lport_cfg_s *port_cfg = &fabric->bport.port_cfg;
819 char model[BFA_ADAPTER_MODEL_NAME_LEN] = {0};
820 struct bfa_fcs_driver_info_s *driver_info = &fabric->fcs->driver_info;
821
822 bfa_ioc_get_adapter_model(&fabric->fcs->bfa->ioc, model);
823
824 /* Model name/number */
Arnd Bergmann8c5a50e2017-12-04 15:47:00 +0100825 strlcpy(port_cfg->node_sym_name.symname, model,
826 BFA_SYMNAME_MAXLEN);
827 strlcat(port_cfg->node_sym_name.symname,
Krishna Gudipatice7242b2012-08-22 19:52:43 -0700828 BFA_FCS_PORT_SYMBNAME_SEPARATOR,
Arnd Bergmann8c5a50e2017-12-04 15:47:00 +0100829 BFA_SYMNAME_MAXLEN);
Krishna Gudipatice7242b2012-08-22 19:52:43 -0700830
831 /* Driver Version */
Arnd Bergmann8c5a50e2017-12-04 15:47:00 +0100832 strlcat(port_cfg->node_sym_name.symname, (char *)driver_info->version,
833 BFA_SYMNAME_MAXLEN);
834 strlcat(port_cfg->node_sym_name.symname,
Krishna Gudipatice7242b2012-08-22 19:52:43 -0700835 BFA_FCS_PORT_SYMBNAME_SEPARATOR,
Arnd Bergmann8c5a50e2017-12-04 15:47:00 +0100836 BFA_SYMNAME_MAXLEN);
Krishna Gudipatice7242b2012-08-22 19:52:43 -0700837
838 /* Host machine name */
Arnd Bergmann8c5a50e2017-12-04 15:47:00 +0100839 strlcat(port_cfg->node_sym_name.symname,
840 driver_info->host_machine_name,
841 BFA_SYMNAME_MAXLEN);
842 strlcat(port_cfg->node_sym_name.symname,
Krishna Gudipatice7242b2012-08-22 19:52:43 -0700843 BFA_FCS_PORT_SYMBNAME_SEPARATOR,
Arnd Bergmann8c5a50e2017-12-04 15:47:00 +0100844 BFA_SYMNAME_MAXLEN);
Krishna Gudipatice7242b2012-08-22 19:52:43 -0700845
846 /* null terminate */
847 port_cfg->node_sym_name.symname[BFA_SYMNAME_MAXLEN - 1] = 0;
848}
849
850/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700851 * bfa lps login completion callback
852 */
853void
854bfa_cb_lps_flogi_comp(void *bfad, void *uarg, bfa_status_t status)
855{
856 struct bfa_fcs_fabric_s *fabric = uarg;
857
858 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
859 bfa_trc(fabric->fcs, status);
860
861 switch (status) {
862 case BFA_STATUS_OK:
863 fabric->stats.flogi_accepts++;
864 break;
865
866 case BFA_STATUS_INVALID_MAC:
867 /* Only for CNA */
868 fabric->stats.flogi_acc_err++;
869 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_RETRY_OP);
870
871 return;
872
873 case BFA_STATUS_EPROTOCOL:
Maggie Zhangf7f738122010-12-09 19:08:43 -0800874 switch (fabric->lps->ext_status) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700875 case BFA_EPROTO_BAD_ACCEPT:
876 fabric->stats.flogi_acc_err++;
877 break;
878
879 case BFA_EPROTO_UNKNOWN_RSP:
880 fabric->stats.flogi_unknown_rsp++;
881 break;
882
883 default:
884 break;
885 }
886 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_RETRY_OP);
887
888 return;
889
890 case BFA_STATUS_FABRIC_RJT:
891 fabric->stats.flogi_rejects++;
892 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_RETRY_OP);
893 return;
894
895 default:
896 fabric->stats.flogi_rsp_err++;
897 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_RETRY_OP);
898 return;
899 }
900
Maggie Zhangf7f738122010-12-09 19:08:43 -0800901 fabric->bb_credit = fabric->lps->pr_bbcred;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700902 bfa_trc(fabric->fcs, fabric->bb_credit);
903
Maggie Zhangf7f738122010-12-09 19:08:43 -0800904 if (!(fabric->lps->brcd_switch))
905 fabric->fabric_name = fabric->lps->pr_nwwn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700906
907 /*
908 * Check port type. It should be 1 = F-port.
909 */
Maggie Zhangf7f738122010-12-09 19:08:43 -0800910 if (fabric->lps->fport) {
911 fabric->bport.pid = fabric->lps->lp_pid;
912 fabric->is_npiv = fabric->lps->npiv_en;
913 fabric->is_auth = fabric->lps->auth_req;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700914 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_CONT_OP);
915 } else {
916 /*
917 * Nport-2-Nport direct attached
918 */
919 fabric->bport.port_topo.pn2n.rem_port_wwn =
Maggie Zhangf7f738122010-12-09 19:08:43 -0800920 fabric->lps->pr_pwwn;
Krishna Gudipatid7be54c2011-06-24 20:24:52 -0700921 fabric->fab_type = BFA_FCS_FABRIC_N2N;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700922 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_NO_FABRIC);
923 }
924
925 bfa_trc(fabric->fcs, fabric->bport.pid);
926 bfa_trc(fabric->fcs, fabric->is_npiv);
927 bfa_trc(fabric->fcs, fabric->is_auth);
928}
Jing Huang5fbe25c2010-10-18 17:17:23 -0700929/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700930 * Allocate and send FLOGI.
931 */
932static void
933bfa_fcs_fabric_login(struct bfa_fcs_fabric_s *fabric)
934{
935 struct bfa_s *bfa = fabric->fcs->bfa;
936 struct bfa_lport_cfg_s *pcfg = &fabric->bport.port_cfg;
Vijaya Mohan Guvvabbe37a62013-05-13 02:33:19 -0700937 u8 alpa = 0;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700938
Krishna Gudipatibe540a92011-06-13 15:53:04 -0700939
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700940 bfa_lps_flogi(fabric->lps, fabric, alpa, bfa_fcport_get_maxfrsize(bfa),
Vijaya Mohan Guvvabbe37a62013-05-13 02:33:19 -0700941 pcfg->pwwn, pcfg->nwwn, fabric->auth_reqd);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700942
943 fabric->stats.flogi_sent++;
944}
945
946static void
947bfa_fcs_fabric_notify_online(struct bfa_fcs_fabric_s *fabric)
948{
949 struct bfa_fcs_vport_s *vport;
950 struct list_head *qe, *qen;
951
952 bfa_trc(fabric->fcs, fabric->fabric_name);
953
954 bfa_fcs_fabric_set_opertype(fabric);
955 fabric->stats.fabric_onlines++;
956
Jing Huang5fbe25c2010-10-18 17:17:23 -0700957 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700958 * notify online event to base and then virtual ports
959 */
960 bfa_fcs_lport_online(&fabric->bport);
961
962 list_for_each_safe(qe, qen, &fabric->vport_q) {
963 vport = (struct bfa_fcs_vport_s *) qe;
964 bfa_fcs_vport_online(vport);
965 }
966}
967
968static void
969bfa_fcs_fabric_notify_offline(struct bfa_fcs_fabric_s *fabric)
970{
971 struct bfa_fcs_vport_s *vport;
972 struct list_head *qe, *qen;
973
974 bfa_trc(fabric->fcs, fabric->fabric_name);
975 fabric->stats.fabric_offlines++;
976
Jing Huang5fbe25c2010-10-18 17:17:23 -0700977 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700978 * notify offline event first to vports and then base port.
979 */
980 list_for_each_safe(qe, qen, &fabric->vport_q) {
981 vport = (struct bfa_fcs_vport_s *) qe;
982 bfa_fcs_vport_offline(vport);
983 }
984
985 bfa_fcs_lport_offline(&fabric->bport);
986
987 fabric->fabric_name = 0;
988 fabric->fabric_ip_addr[0] = 0;
989}
990
991static void
992bfa_fcs_fabric_delay(void *cbarg)
993{
994 struct bfa_fcs_fabric_s *fabric = cbarg;
995
996 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_DELAYED);
997}
998
Jing Huang5fbe25c2010-10-18 17:17:23 -0700999/*
Krishna Gudipati881c1b32012-08-22 19:52:02 -07001000 * Stop all vports and wait for vport stop completions.
1001 */
1002static void
1003bfa_fcs_fabric_stop(struct bfa_fcs_fabric_s *fabric)
1004{
1005 struct bfa_fcs_vport_s *vport;
1006 struct list_head *qe, *qen;
1007
1008 bfa_wc_init(&fabric->stop_wc, bfa_fcs_fabric_stop_comp, fabric);
1009
1010 list_for_each_safe(qe, qen, &fabric->vport_q) {
1011 vport = (struct bfa_fcs_vport_s *) qe;
1012 bfa_wc_up(&fabric->stop_wc);
1013 bfa_fcs_vport_fcs_stop(vport);
1014 }
1015
1016 bfa_wc_up(&fabric->stop_wc);
1017 bfa_fcs_lport_stop(&fabric->bport);
1018 bfa_wc_wait(&fabric->stop_wc);
1019}
1020
1021/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001022 * Delete all vports and wait for vport delete completions.
1023 */
1024static void
1025bfa_fcs_fabric_delete(struct bfa_fcs_fabric_s *fabric)
1026{
1027 struct bfa_fcs_vport_s *vport;
1028 struct list_head *qe, *qen;
1029
1030 list_for_each_safe(qe, qen, &fabric->vport_q) {
1031 vport = (struct bfa_fcs_vport_s *) qe;
1032 bfa_fcs_vport_fcs_delete(vport);
1033 }
1034
1035 bfa_fcs_lport_delete(&fabric->bport);
1036 bfa_wc_wait(&fabric->wc);
1037}
1038
1039static void
1040bfa_fcs_fabric_delete_comp(void *cbarg)
1041{
1042 struct bfa_fcs_fabric_s *fabric = cbarg;
1043
1044 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_DELCOMP);
1045}
1046
Krishna Gudipati881c1b32012-08-22 19:52:02 -07001047static void
1048bfa_fcs_fabric_stop_comp(void *cbarg)
1049{
1050 struct bfa_fcs_fabric_s *fabric = cbarg;
1051
1052 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_STOPCOMP);
1053}
1054
Jing Huang5fbe25c2010-10-18 17:17:23 -07001055/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001056 * fcs_fabric_public fabric public functions
1057 */
1058
Jing Huang5fbe25c2010-10-18 17:17:23 -07001059/*
Krishna Gudipati881c1b32012-08-22 19:52:02 -07001060 * Fabric module stop -- stop FCS actions
1061 */
1062void
1063bfa_fcs_fabric_modstop(struct bfa_fcs_s *fcs)
1064{
1065 struct bfa_fcs_fabric_s *fabric;
1066
1067 bfa_trc(fcs, 0);
1068 fabric = &fcs->fabric;
1069 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_STOP);
1070}
1071
1072/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001073 * Fabric module start -- kick starts FCS actions
1074 */
1075void
1076bfa_fcs_fabric_modstart(struct bfa_fcs_s *fcs)
1077{
1078 struct bfa_fcs_fabric_s *fabric;
1079
1080 bfa_trc(fcs, 0);
1081 fabric = &fcs->fabric;
1082 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_START);
1083}
1084
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001085
Jing Huang5fbe25c2010-10-18 17:17:23 -07001086/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001087 * Link up notification from BFA physical port module.
1088 */
1089void
1090bfa_fcs_fabric_link_up(struct bfa_fcs_fabric_s *fabric)
1091{
1092 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
1093 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_LINK_UP);
1094}
1095
Jing Huang5fbe25c2010-10-18 17:17:23 -07001096/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001097 * Link down notification from BFA physical port module.
1098 */
1099void
1100bfa_fcs_fabric_link_down(struct bfa_fcs_fabric_s *fabric)
1101{
1102 bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
1103 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_LINK_DOWN);
1104}
1105
Jing Huang5fbe25c2010-10-18 17:17:23 -07001106/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001107 * A child vport is being created in the fabric.
1108 *
1109 * Call from vport module at vport creation. A list of base port and vports
1110 * belonging to a fabric is maintained to propagate link events.
1111 *
1112 * param[in] fabric - Fabric instance. This can be a base fabric or vf.
1113 * param[in] vport - Vport being created.
1114 *
1115 * @return None (always succeeds)
1116 */
1117void
1118bfa_fcs_fabric_addvport(struct bfa_fcs_fabric_s *fabric,
1119 struct bfa_fcs_vport_s *vport)
1120{
Jing Huang5fbe25c2010-10-18 17:17:23 -07001121 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001122 * - add vport to fabric's vport_q
1123 */
1124 bfa_trc(fabric->fcs, fabric->vf_id);
1125
1126 list_add_tail(&vport->qe, &fabric->vport_q);
1127 fabric->num_vports++;
1128 bfa_wc_up(&fabric->wc);
1129}
1130
Jing Huang5fbe25c2010-10-18 17:17:23 -07001131/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001132 * A child vport is being deleted from fabric.
1133 *
1134 * Vport is being deleted.
1135 */
1136void
1137bfa_fcs_fabric_delvport(struct bfa_fcs_fabric_s *fabric,
1138 struct bfa_fcs_vport_s *vport)
1139{
1140 list_del(&vport->qe);
1141 fabric->num_vports--;
1142 bfa_wc_down(&fabric->wc);
1143}
1144
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001145
Jing Huang5fbe25c2010-10-18 17:17:23 -07001146/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001147 * Lookup for a vport within a fabric given its pwwn
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001148 */
1149struct bfa_fcs_vport_s *
1150bfa_fcs_fabric_vport_lookup(struct bfa_fcs_fabric_s *fabric, wwn_t pwwn)
1151{
1152 struct bfa_fcs_vport_s *vport;
1153 struct list_head *qe;
1154
1155 list_for_each(qe, &fabric->vport_q) {
1156 vport = (struct bfa_fcs_vport_s *) qe;
1157 if (bfa_fcs_lport_get_pwwn(&vport->lport) == pwwn)
1158 return vport;
1159 }
1160
1161 return NULL;
1162}
1163
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001164
1165/*
1166 * Get OUI of the attached switch.
1167 *
1168 * Note : Use of this function should be avoided as much as possible.
1169 * This function should be used only if there is any requirement
1170* to check for FOS version below 6.3.
1171 * To check if the attached fabric is a brocade fabric, use
1172 * bfa_lps_is_brcd_fabric() which works for FOS versions 6.3
1173 * or above only.
1174 */
1175
1176u16
1177bfa_fcs_fabric_get_switch_oui(struct bfa_fcs_fabric_s *fabric)
1178{
1179 wwn_t fab_nwwn;
1180 u8 *tmp;
1181 u16 oui;
1182
Maggie Zhangf7f738122010-12-09 19:08:43 -08001183 fab_nwwn = fabric->lps->pr_nwwn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001184
1185 tmp = (u8 *)&fab_nwwn;
1186 oui = (tmp[3] << 8) | tmp[4];
1187
1188 return oui;
1189}
Jing Huang5fbe25c2010-10-18 17:17:23 -07001190/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001191 * Unsolicited frame receive handling.
1192 */
1193void
1194bfa_fcs_fabric_uf_recv(struct bfa_fcs_fabric_s *fabric, struct fchs_s *fchs,
1195 u16 len)
1196{
1197 u32 pid = fchs->d_id;
1198 struct bfa_fcs_vport_s *vport;
1199 struct list_head *qe;
1200 struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
1201 struct fc_logi_s *flogi = (struct fc_logi_s *) els_cmd;
1202
1203 bfa_trc(fabric->fcs, len);
1204 bfa_trc(fabric->fcs, pid);
1205
Jing Huang5fbe25c2010-10-18 17:17:23 -07001206 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001207 * Look for our own FLOGI frames being looped back. This means an
1208 * external loopback cable is in place. Our own FLOGI frames are
1209 * sometimes looped back when switch port gets temporarily bypassed.
1210 */
Maggie Zhangf16a1752010-12-09 19:12:32 -08001211 if ((pid == bfa_ntoh3b(FC_FABRIC_PORT)) &&
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001212 (els_cmd->els_code == FC_ELS_FLOGI) &&
1213 (flogi->port_name == bfa_fcs_lport_get_pwwn(&fabric->bport))) {
1214 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_LOOPBACK);
1215 return;
1216 }
1217
Jing Huang5fbe25c2010-10-18 17:17:23 -07001218 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001219 * FLOGI/EVFP exchanges should be consumed by base fabric.
1220 */
Maggie Zhangf16a1752010-12-09 19:12:32 -08001221 if (fchs->d_id == bfa_hton3b(FC_FABRIC_PORT)) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001222 bfa_trc(fabric->fcs, pid);
1223 bfa_fcs_fabric_process_uf(fabric, fchs, len);
1224 return;
1225 }
1226
1227 if (fabric->bport.pid == pid) {
Jing Huang5fbe25c2010-10-18 17:17:23 -07001228 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001229 * All authentication frames should be routed to auth
1230 */
1231 bfa_trc(fabric->fcs, els_cmd->els_code);
1232 if (els_cmd->els_code == FC_ELS_AUTH) {
1233 bfa_trc(fabric->fcs, els_cmd->els_code);
1234 return;
1235 }
1236
1237 bfa_trc(fabric->fcs, *(u8 *) ((u8 *) fchs));
1238 bfa_fcs_lport_uf_recv(&fabric->bport, fchs, len);
1239 return;
1240 }
1241
Jing Huang5fbe25c2010-10-18 17:17:23 -07001242 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001243 * look for a matching local port ID
1244 */
1245 list_for_each(qe, &fabric->vport_q) {
1246 vport = (struct bfa_fcs_vport_s *) qe;
1247 if (vport->lport.pid == pid) {
1248 bfa_fcs_lport_uf_recv(&vport->lport, fchs, len);
1249 return;
1250 }
1251 }
Krishna Gudipati61ba4392012-08-22 19:52:58 -07001252
1253 if (!bfa_fcs_fabric_is_switched(fabric))
1254 bfa_fcs_lport_uf_recv(&fabric->bport, fchs, len);
1255
1256 bfa_trc(fabric->fcs, fchs->type);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001257}
1258
Jing Huang5fbe25c2010-10-18 17:17:23 -07001259/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001260 * Unsolicited frames to be processed by fabric.
1261 */
1262static void
1263bfa_fcs_fabric_process_uf(struct bfa_fcs_fabric_s *fabric, struct fchs_s *fchs,
1264 u16 len)
1265{
1266 struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
1267
1268 bfa_trc(fabric->fcs, els_cmd->els_code);
1269
1270 switch (els_cmd->els_code) {
1271 case FC_ELS_FLOGI:
1272 bfa_fcs_fabric_process_flogi(fabric, fchs, len);
1273 break;
1274
1275 default:
1276 /*
1277 * need to generate a LS_RJT
1278 */
1279 break;
1280 }
1281}
1282
Jing Huang5fbe25c2010-10-18 17:17:23 -07001283/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001284 * Process incoming FLOGI
1285 */
1286static void
1287bfa_fcs_fabric_process_flogi(struct bfa_fcs_fabric_s *fabric,
1288 struct fchs_s *fchs, u16 len)
1289{
1290 struct fc_logi_s *flogi = (struct fc_logi_s *) (fchs + 1);
1291 struct bfa_fcs_lport_s *bport = &fabric->bport;
1292
1293 bfa_trc(fabric->fcs, fchs->s_id);
1294
1295 fabric->stats.flogi_rcvd++;
1296 /*
1297 * Check port type. It should be 0 = n-port.
1298 */
1299 if (flogi->csp.port_type) {
1300 /*
1301 * @todo: may need to send a LS_RJT
1302 */
1303 bfa_trc(fabric->fcs, flogi->port_name);
1304 fabric->stats.flogi_rejected++;
1305 return;
1306 }
1307
Jing Huangba816ea2010-10-18 17:10:50 -07001308 fabric->bb_credit = be16_to_cpu(flogi->csp.bbcred);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001309 bport->port_topo.pn2n.rem_port_wwn = flogi->port_name;
1310 bport->port_topo.pn2n.reply_oxid = fchs->ox_id;
1311
1312 /*
1313 * Send a Flogi Acc
1314 */
1315 bfa_fcs_fabric_send_flogi_acc(fabric);
1316 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_NO_FABRIC);
1317}
1318
1319static void
1320bfa_fcs_fabric_send_flogi_acc(struct bfa_fcs_fabric_s *fabric)
1321{
1322 struct bfa_lport_cfg_s *pcfg = &fabric->bport.port_cfg;
1323 struct bfa_fcs_lport_n2n_s *n2n_port = &fabric->bport.port_topo.pn2n;
1324 struct bfa_s *bfa = fabric->fcs->bfa;
1325 struct bfa_fcxp_s *fcxp;
1326 u16 reqlen;
1327 struct fchs_s fchs;
1328
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07001329 fcxp = bfa_fcs_fcxp_alloc(fabric->fcs, BFA_FALSE);
Jing Huang5fbe25c2010-10-18 17:17:23 -07001330 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001331 * Do not expect this failure -- expect remote node to retry
1332 */
1333 if (!fcxp)
1334 return;
1335
1336 reqlen = fc_flogi_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
Maggie Zhangf16a1752010-12-09 19:12:32 -08001337 bfa_hton3b(FC_FABRIC_PORT),
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001338 n2n_port->reply_oxid, pcfg->pwwn,
1339 pcfg->nwwn,
1340 bfa_fcport_get_maxfrsize(bfa),
Vijaya Mohan Guvvabbe37a62013-05-13 02:33:19 -07001341 bfa_fcport_get_rx_bbcredit(bfa), 0);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001342
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001343 bfa_fcxp_send(fcxp, NULL, fabric->vf_id, fabric->lps->bfa_tag,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001344 BFA_FALSE, FC_CLASS_3,
1345 reqlen, &fchs, bfa_fcs_fabric_flogiacc_comp, fabric,
1346 FC_MAX_PDUSZ, 0);
1347}
1348
Jing Huang5fbe25c2010-10-18 17:17:23 -07001349/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001350 * Flogi Acc completion callback.
1351 */
1352static void
1353bfa_fcs_fabric_flogiacc_comp(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
1354 bfa_status_t status, u32 rsp_len,
1355 u32 resid_len, struct fchs_s *rspfchs)
1356{
1357 struct bfa_fcs_fabric_s *fabric = cbarg;
1358
1359 bfa_trc(fabric->fcs, status);
1360}
1361
Krishna Gudipati7826f302011-07-20 16:59:13 -07001362
1363/*
1364 * Send AEN notification
1365 */
1366static void
1367bfa_fcs_fabric_aen_post(struct bfa_fcs_lport_s *port,
1368 enum bfa_port_aen_event event)
1369{
1370 struct bfad_s *bfad = (struct bfad_s *)port->fabric->fcs->bfad;
1371 struct bfa_aen_entry_s *aen_entry;
1372
1373 bfad_get_aen_entry(bfad, aen_entry);
1374 if (!aen_entry)
1375 return;
1376
1377 aen_entry->aen_data.port.pwwn = bfa_fcs_lport_get_pwwn(port);
1378 aen_entry->aen_data.port.fwwn = bfa_fcs_lport_get_fabric_name(port);
1379
1380 /* Send the AEN notification */
1381 bfad_im_post_vendor_event(aen_entry, bfad, ++port->fcs->fcs_aen_seq,
1382 BFA_AEN_CAT_PORT, event);
1383}
1384
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001385/*
1386 *
1387 * @param[in] fabric - fabric
1388 * @param[in] wwn_t - new fabric name
1389 *
1390 * @return - none
1391 */
1392void
1393bfa_fcs_fabric_set_fabric_name(struct bfa_fcs_fabric_s *fabric,
1394 wwn_t fabric_name)
1395{
1396 struct bfad_s *bfad = (struct bfad_s *)fabric->fcs->bfad;
1397 char pwwn_ptr[BFA_STRING_32];
1398 char fwwn_ptr[BFA_STRING_32];
1399
1400 bfa_trc(fabric->fcs, fabric_name);
1401
1402 if (fabric->fabric_name == 0) {
1403 /*
1404 * With BRCD switches, we don't get Fabric Name in FLOGI.
1405 * Don't generate a fabric name change event in this case.
1406 */
1407 fabric->fabric_name = fabric_name;
1408 } else {
1409 fabric->fabric_name = fabric_name;
1410 wwn2str(pwwn_ptr, bfa_fcs_lport_get_pwwn(&fabric->bport));
1411 wwn2str(fwwn_ptr,
1412 bfa_fcs_lport_get_fabric_name(&fabric->bport));
Jing Huang88166242010-12-09 17:11:53 -08001413 BFA_LOG(KERN_WARNING, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001414 "Base port WWN = %s Fabric WWN = %s\n",
1415 pwwn_ptr, fwwn_ptr);
Krishna Gudipati7826f302011-07-20 16:59:13 -07001416 bfa_fcs_fabric_aen_post(&fabric->bport,
1417 BFA_PORT_AEN_FABRIC_NAME_CHANGE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001418 }
1419}
1420
Krishna Gudipati881c1b32012-08-22 19:52:02 -07001421void
1422bfa_cb_lps_flogo_comp(void *bfad, void *uarg)
1423{
1424 struct bfa_fcs_fabric_s *fabric = uarg;
1425 bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_LOGOCOMP);
1426}
1427
Jing Huang5fbe25c2010-10-18 17:17:23 -07001428/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001429 * Returns FCS vf structure for a given vf_id.
1430 *
1431 * param[in] vf_id - VF_ID
1432 *
1433 * return
1434 * If lookup succeeds, retuns fcs vf object, otherwise returns NULL
1435 */
1436bfa_fcs_vf_t *
1437bfa_fcs_vf_lookup(struct bfa_fcs_s *fcs, u16 vf_id)
1438{
1439 bfa_trc(fcs, vf_id);
1440 if (vf_id == FC_VF_ID_NULL)
1441 return &fcs->fabric;
1442
1443 return NULL;
1444}
1445
Jing Huang5fbe25c2010-10-18 17:17:23 -07001446/*
Krishna Gudipatib85daaf2011-06-13 15:55:11 -07001447 * Return the list of local logical ports present in the given VF.
1448 *
1449 * @param[in] vf vf for which logical ports are returned
1450 * @param[out] lpwwn returned logical port wwn list
1451 * @param[in,out] nlports in:size of lpwwn list;
1452 * out:total elements present,
1453 * actual elements returned is limited by the size
1454 */
1455void
1456bfa_fcs_vf_get_ports(bfa_fcs_vf_t *vf, wwn_t lpwwn[], int *nlports)
1457{
1458 struct list_head *qe;
1459 struct bfa_fcs_vport_s *vport;
1460 int i = 0;
1461 struct bfa_fcs_s *fcs;
1462
1463 if (vf == NULL || lpwwn == NULL || *nlports == 0)
1464 return;
1465
1466 fcs = vf->fcs;
1467
1468 bfa_trc(fcs, vf->vf_id);
1469 bfa_trc(fcs, (uint32_t) *nlports);
1470
1471 lpwwn[i++] = vf->bport.port_cfg.pwwn;
1472
1473 list_for_each(qe, &vf->vport_q) {
1474 if (i >= *nlports)
1475 break;
1476
1477 vport = (struct bfa_fcs_vport_s *) qe;
1478 lpwwn[i++] = vport->lport.port_cfg.pwwn;
1479 }
1480
1481 bfa_trc(fcs, i);
1482 *nlports = i;
1483}
1484
1485/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001486 * BFA FCS PPORT ( physical port)
1487 */
1488static void
1489bfa_fcs_port_event_handler(void *cbarg, enum bfa_port_linkstate event)
1490{
1491 struct bfa_fcs_s *fcs = cbarg;
1492
1493 bfa_trc(fcs, event);
1494
1495 switch (event) {
1496 case BFA_PORT_LINKUP:
1497 bfa_fcs_fabric_link_up(&fcs->fabric);
1498 break;
1499
1500 case BFA_PORT_LINKDOWN:
1501 bfa_fcs_fabric_link_down(&fcs->fabric);
1502 break;
1503
1504 default:
Jing Huangd4b671c52010-12-26 21:46:35 -08001505 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001506 }
1507}
1508
Jing Huang5fbe25c2010-10-18 17:17:23 -07001509/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001510 * BFA FCS UF ( Unsolicited Frames)
1511 */
1512
Jing Huang5fbe25c2010-10-18 17:17:23 -07001513/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001514 * BFA callback for unsolicited frame receive handler.
1515 *
1516 * @param[in] cbarg callback arg for receive handler
1517 * @param[in] uf unsolicited frame descriptor
1518 *
1519 * @return None
1520 */
1521static void
1522bfa_fcs_uf_recv(void *cbarg, struct bfa_uf_s *uf)
1523{
1524 struct bfa_fcs_s *fcs = (struct bfa_fcs_s *) cbarg;
1525 struct fchs_s *fchs = bfa_uf_get_frmbuf(uf);
1526 u16 len = bfa_uf_get_frmlen(uf);
1527 struct fc_vft_s *vft;
1528 struct bfa_fcs_fabric_s *fabric;
1529
Jing Huang5fbe25c2010-10-18 17:17:23 -07001530 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001531 * check for VFT header
1532 */
1533 if (fchs->routing == FC_RTG_EXT_HDR &&
1534 fchs->cat_info == FC_CAT_VFT_HDR) {
1535 bfa_stats(fcs, uf.tagged);
1536 vft = bfa_uf_get_frmbuf(uf);
1537 if (fcs->port_vfid == vft->vf_id)
1538 fabric = &fcs->fabric;
1539 else
1540 fabric = bfa_fcs_vf_lookup(fcs, (u16) vft->vf_id);
1541
Jing Huang5fbe25c2010-10-18 17:17:23 -07001542 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001543 * drop frame if vfid is unknown
1544 */
1545 if (!fabric) {
Jing Huangd4b671c52010-12-26 21:46:35 -08001546 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001547 bfa_stats(fcs, uf.vfid_unknown);
1548 bfa_uf_free(uf);
1549 return;
1550 }
1551
Jing Huang5fbe25c2010-10-18 17:17:23 -07001552 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001553 * skip vft header
1554 */
1555 fchs = (struct fchs_s *) (vft + 1);
1556 len -= sizeof(struct fc_vft_s);
1557
1558 bfa_trc(fcs, vft->vf_id);
1559 } else {
1560 bfa_stats(fcs, uf.untagged);
1561 fabric = &fcs->fabric;
1562 }
1563
1564 bfa_trc(fcs, ((u32 *) fchs)[0]);
1565 bfa_trc(fcs, ((u32 *) fchs)[1]);
1566 bfa_trc(fcs, ((u32 *) fchs)[2]);
1567 bfa_trc(fcs, ((u32 *) fchs)[3]);
1568 bfa_trc(fcs, ((u32 *) fchs)[4]);
1569 bfa_trc(fcs, ((u32 *) fchs)[5]);
1570 bfa_trc(fcs, len);
1571
1572 bfa_fcs_fabric_uf_recv(fabric, fchs, len);
1573 bfa_uf_free(uf);
1574}
1575
Christoph Hellwig984dc462017-01-08 10:41:15 +01001576/*
1577 * fcs attach -- called once to initialize data structures at driver attach time
1578 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001579void
Christoph Hellwig984dc462017-01-08 10:41:15 +01001580bfa_fcs_attach(struct bfa_fcs_s *fcs, struct bfa_s *bfa, struct bfad_s *bfad,
1581 bfa_boolean_t min_cfg)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001582{
Christoph Hellwig984dc462017-01-08 10:41:15 +01001583 struct bfa_fcs_fabric_s *fabric = &fcs->fabric;
1584
1585 fcs->bfa = bfa;
1586 fcs->bfad = bfad;
1587 fcs->min_cfg = min_cfg;
1588 fcs->num_rport_logins = 0;
1589
1590 bfa->fcs = BFA_TRUE;
1591 fcbuild_init();
1592
1593 bfa_fcport_event_register(fcs->bfa, bfa_fcs_port_event_handler, fcs);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001594 bfa_uf_recv_register(fcs->bfa, bfa_fcs_uf_recv, fcs);
Christoph Hellwig984dc462017-01-08 10:41:15 +01001595
1596 memset(fabric, 0, sizeof(struct bfa_fcs_fabric_s));
1597
1598 /*
1599 * Initialize base fabric.
1600 */
1601 fabric->fcs = fcs;
1602 INIT_LIST_HEAD(&fabric->vport_q);
1603 INIT_LIST_HEAD(&fabric->vf_q);
1604 fabric->lps = bfa_lps_alloc(fcs->bfa);
1605 WARN_ON(!fabric->lps);
1606
1607 /*
1608 * Initialize fabric delete completion handler. Fabric deletion is
1609 * complete when the last vport delete is complete.
1610 */
1611 bfa_wc_init(&fabric->wc, bfa_fcs_fabric_delete_comp, fabric);
1612 bfa_wc_up(&fabric->wc); /* For the base port */
1613
1614 bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_uninit);
1615 bfa_fcs_lport_attach(&fabric->bport, fabric->fcs, FC_VF_ID_NULL, NULL);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001616}