[SCSI] bfa: Brocade BFA FC SCSI driver
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / scsi / bfa / vport.c
1 /*
2 * Copyright (c) 2005-2009 Brocade Communications Systems, Inc.
3 * 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
18 /**
19 * bfa_fcs_vport.c FCS virtual port state machine
20 */
21
22 #include <bfa.h>
23 #include <bfa_svc.h>
24 #include <fcbuild.h>
25 #include "fcs_fabric.h"
26 #include "fcs_lport.h"
27 #include "fcs_vport.h"
28 #include "fcs_trcmod.h"
29 #include "fcs.h"
30 #include <aen/bfa_aen_lport.h>
31
32 BFA_TRC_FILE(FCS, VPORT);
33
34 #define __vport_fcs(__vp) (__vp)->lport.fcs
35 #define __vport_pwwn(__vp) (__vp)->lport.port_cfg.pwwn
36 #define __vport_nwwn(__vp) (__vp)->lport.port_cfg.nwwn
37 #define __vport_bfa(__vp) (__vp)->lport.fcs->bfa
38 #define __vport_fcid(__vp) (__vp)->lport.pid
39 #define __vport_fabric(__vp) (__vp)->lport.fabric
40 #define __vport_vfid(__vp) (__vp)->lport.fabric->vf_id
41
42 #define BFA_FCS_VPORT_MAX_RETRIES 5
43 /*
44 * Forward declarations
45 */
46 static void bfa_fcs_vport_do_fdisc(struct bfa_fcs_vport_s *vport);
47 static void bfa_fcs_vport_timeout(void *vport_arg);
48 static void bfa_fcs_vport_do_logo(struct bfa_fcs_vport_s *vport);
49 static void bfa_fcs_vport_free(struct bfa_fcs_vport_s *vport);
50
51 /**
52 * fcs_vport_sm FCS virtual port state machine
53 */
54
55 /**
56 * VPort State Machine events
57 */
58 enum bfa_fcs_vport_event {
59 BFA_FCS_VPORT_SM_CREATE = 1, /* vport create event */
60 BFA_FCS_VPORT_SM_DELETE = 2, /* vport delete event */
61 BFA_FCS_VPORT_SM_START = 3, /* vport start request */
62 BFA_FCS_VPORT_SM_STOP = 4, /* stop: unsupported */
63 BFA_FCS_VPORT_SM_ONLINE = 5, /* fabric online */
64 BFA_FCS_VPORT_SM_OFFLINE = 6, /* fabric offline event */
65 BFA_FCS_VPORT_SM_FRMSENT = 7, /* fdisc/logo sent events */
66 BFA_FCS_VPORT_SM_RSP_OK = 8, /* good response */
67 BFA_FCS_VPORT_SM_RSP_ERROR = 9, /* error/bad response */
68 BFA_FCS_VPORT_SM_TIMEOUT = 10, /* delay timer event */
69 BFA_FCS_VPORT_SM_DELCOMP = 11, /* lport delete completion */
70 BFA_FCS_VPORT_SM_RSP_DUP_WWN = 12, /* Dup wnn error */
71 BFA_FCS_VPORT_SM_RSP_FAILED = 13, /* non-retryable failure */
72 };
73
74 static void bfa_fcs_vport_sm_uninit(struct bfa_fcs_vport_s *vport,
75 enum bfa_fcs_vport_event event);
76 static void bfa_fcs_vport_sm_created(struct bfa_fcs_vport_s *vport,
77 enum bfa_fcs_vport_event event);
78 static void bfa_fcs_vport_sm_offline(struct bfa_fcs_vport_s *vport,
79 enum bfa_fcs_vport_event event);
80 static void bfa_fcs_vport_sm_fdisc(struct bfa_fcs_vport_s *vport,
81 enum bfa_fcs_vport_event event);
82 static void bfa_fcs_vport_sm_fdisc_retry(struct bfa_fcs_vport_s *vport,
83 enum bfa_fcs_vport_event event);
84 static void bfa_fcs_vport_sm_online(struct bfa_fcs_vport_s *vport,
85 enum bfa_fcs_vport_event event);
86 static void bfa_fcs_vport_sm_deleting(struct bfa_fcs_vport_s *vport,
87 enum bfa_fcs_vport_event event);
88 static void bfa_fcs_vport_sm_cleanup(struct bfa_fcs_vport_s *vport,
89 enum bfa_fcs_vport_event event);
90 static void bfa_fcs_vport_sm_logo(struct bfa_fcs_vport_s *vport,
91 enum bfa_fcs_vport_event event);
92 static void bfa_fcs_vport_sm_error(struct bfa_fcs_vport_s *vport,
93 enum bfa_fcs_vport_event event);
94
95 static struct bfa_sm_table_s vport_sm_table[] = {
96 {BFA_SM(bfa_fcs_vport_sm_uninit), BFA_FCS_VPORT_UNINIT},
97 {BFA_SM(bfa_fcs_vport_sm_created), BFA_FCS_VPORT_CREATED},
98 {BFA_SM(bfa_fcs_vport_sm_offline), BFA_FCS_VPORT_OFFLINE},
99 {BFA_SM(bfa_fcs_vport_sm_fdisc), BFA_FCS_VPORT_FDISC},
100 {BFA_SM(bfa_fcs_vport_sm_fdisc_retry), BFA_FCS_VPORT_FDISC_RETRY},
101 {BFA_SM(bfa_fcs_vport_sm_online), BFA_FCS_VPORT_ONLINE},
102 {BFA_SM(bfa_fcs_vport_sm_deleting), BFA_FCS_VPORT_DELETING},
103 {BFA_SM(bfa_fcs_vport_sm_cleanup), BFA_FCS_VPORT_CLEANUP},
104 {BFA_SM(bfa_fcs_vport_sm_logo), BFA_FCS_VPORT_LOGO},
105 {BFA_SM(bfa_fcs_vport_sm_error), BFA_FCS_VPORT_ERROR}
106 };
107
108 /**
109 * Beginning state.
110 */
111 static void
112 bfa_fcs_vport_sm_uninit(struct bfa_fcs_vport_s *vport,
113 enum bfa_fcs_vport_event event)
114 {
115 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
116 bfa_trc(__vport_fcs(vport), event);
117
118 switch (event) {
119 case BFA_FCS_VPORT_SM_CREATE:
120 bfa_sm_set_state(vport, bfa_fcs_vport_sm_created);
121 bfa_fcs_fabric_addvport(__vport_fabric(vport), vport);
122 break;
123
124 default:
125 bfa_assert(0);
126 }
127 }
128
129 /**
130 * Created state - a start event is required to start up the state machine.
131 */
132 static void
133 bfa_fcs_vport_sm_created(struct bfa_fcs_vport_s *vport,
134 enum bfa_fcs_vport_event event)
135 {
136 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
137 bfa_trc(__vport_fcs(vport), event);
138
139 switch (event) {
140 case BFA_FCS_VPORT_SM_START:
141 if (bfa_fcs_fabric_is_online(__vport_fabric(vport))
142 && bfa_fcs_fabric_npiv_capable(__vport_fabric(vport))) {
143 bfa_sm_set_state(vport, bfa_fcs_vport_sm_fdisc);
144 bfa_fcs_vport_do_fdisc(vport);
145 } else {
146 /**
147 * Fabric is offline or not NPIV capable, stay in
148 * offline state.
149 */
150 vport->vport_stats.fab_no_npiv++;
151 bfa_sm_set_state(vport, bfa_fcs_vport_sm_offline);
152 }
153 break;
154
155 case BFA_FCS_VPORT_SM_DELETE:
156 bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
157 bfa_fcs_port_delete(&vport->lport);
158 break;
159
160 case BFA_FCS_VPORT_SM_ONLINE:
161 case BFA_FCS_VPORT_SM_OFFLINE:
162 /**
163 * Ignore ONLINE/OFFLINE events from fabric till vport is started.
164 */
165 break;
166
167 default:
168 bfa_assert(0);
169 }
170 }
171
172 /**
173 * Offline state - awaiting ONLINE event from fabric SM.
174 */
175 static void
176 bfa_fcs_vport_sm_offline(struct bfa_fcs_vport_s *vport,
177 enum bfa_fcs_vport_event event)
178 {
179 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
180 bfa_trc(__vport_fcs(vport), event);
181
182 switch (event) {
183 case BFA_FCS_VPORT_SM_DELETE:
184 bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
185 bfa_fcs_port_delete(&vport->lport);
186 break;
187
188 case BFA_FCS_VPORT_SM_ONLINE:
189 bfa_sm_set_state(vport, bfa_fcs_vport_sm_fdisc);
190 vport->fdisc_retries = 0;
191 bfa_fcs_vport_do_fdisc(vport);
192 break;
193
194 case BFA_FCS_VPORT_SM_OFFLINE:
195 /*
196 * This can happen if the vport couldn't be initialzied due
197 * the fact that the npiv was not enabled on the switch. In
198 * that case we will put the vport in offline state. However,
199 * the link can go down and cause the this event to be sent when
200 * we are already offline. Ignore it.
201 */
202 break;
203
204 default:
205 bfa_assert(0);
206 }
207 }
208
209 /**
210 * FDISC is sent and awaiting reply from fabric.
211 */
212 static void
213 bfa_fcs_vport_sm_fdisc(struct bfa_fcs_vport_s *vport,
214 enum bfa_fcs_vport_event event)
215 {
216 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
217 bfa_trc(__vport_fcs(vport), event);
218
219 switch (event) {
220 case BFA_FCS_VPORT_SM_DELETE:
221 bfa_sm_set_state(vport, bfa_fcs_vport_sm_logo);
222 bfa_lps_discard(vport->lps);
223 bfa_fcs_vport_do_logo(vport);
224 break;
225
226 case BFA_FCS_VPORT_SM_OFFLINE:
227 bfa_sm_set_state(vport, bfa_fcs_vport_sm_offline);
228 bfa_lps_discard(vport->lps);
229 break;
230
231 case BFA_FCS_VPORT_SM_RSP_OK:
232 bfa_sm_set_state(vport, bfa_fcs_vport_sm_online);
233 bfa_fcs_port_online(&vport->lport);
234 break;
235
236 case BFA_FCS_VPORT_SM_RSP_ERROR:
237 bfa_sm_set_state(vport, bfa_fcs_vport_sm_fdisc_retry);
238 bfa_timer_start(__vport_bfa(vport), &vport->timer,
239 bfa_fcs_vport_timeout, vport,
240 BFA_FCS_RETRY_TIMEOUT);
241 break;
242
243 case BFA_FCS_VPORT_SM_RSP_FAILED:
244 bfa_sm_set_state(vport, bfa_fcs_vport_sm_offline);
245 break;
246
247 case BFA_FCS_VPORT_SM_RSP_DUP_WWN:
248 bfa_sm_set_state(vport, bfa_fcs_vport_sm_error);
249 break;
250
251 default:
252 bfa_assert(0);
253 }
254 }
255
256 /**
257 * FDISC attempt failed - a timer is active to retry FDISC.
258 */
259 static void
260 bfa_fcs_vport_sm_fdisc_retry(struct bfa_fcs_vport_s *vport,
261 enum bfa_fcs_vport_event event)
262 {
263 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
264 bfa_trc(__vport_fcs(vport), event);
265
266 switch (event) {
267 case BFA_FCS_VPORT_SM_DELETE:
268 bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
269 bfa_timer_stop(&vport->timer);
270 bfa_fcs_port_delete(&vport->lport);
271 break;
272
273 case BFA_FCS_VPORT_SM_OFFLINE:
274 bfa_sm_set_state(vport, bfa_fcs_vport_sm_offline);
275 bfa_timer_stop(&vport->timer);
276 break;
277
278 case BFA_FCS_VPORT_SM_TIMEOUT:
279 bfa_sm_set_state(vport, bfa_fcs_vport_sm_fdisc);
280 vport->vport_stats.fdisc_retries++;
281 vport->fdisc_retries++;
282 bfa_fcs_vport_do_fdisc(vport);
283 break;
284
285 default:
286 bfa_assert(0);
287 }
288 }
289
290 /**
291 * Vport is online (FDISC is complete).
292 */
293 static void
294 bfa_fcs_vport_sm_online(struct bfa_fcs_vport_s *vport,
295 enum bfa_fcs_vport_event event)
296 {
297 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
298 bfa_trc(__vport_fcs(vport), event);
299
300 switch (event) {
301 case BFA_FCS_VPORT_SM_DELETE:
302 bfa_sm_set_state(vport, bfa_fcs_vport_sm_deleting);
303 bfa_fcs_port_delete(&vport->lport);
304 break;
305
306 case BFA_FCS_VPORT_SM_OFFLINE:
307 bfa_sm_set_state(vport, bfa_fcs_vport_sm_offline);
308 bfa_lps_discard(vport->lps);
309 bfa_fcs_port_offline(&vport->lport);
310 break;
311
312 default:
313 bfa_assert(0);
314 }
315 }
316
317 /**
318 * Vport is being deleted - awaiting lport delete completion to send
319 * LOGO to fabric.
320 */
321 static void
322 bfa_fcs_vport_sm_deleting(struct bfa_fcs_vport_s *vport,
323 enum bfa_fcs_vport_event event)
324 {
325 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
326 bfa_trc(__vport_fcs(vport), event);
327
328 switch (event) {
329 case BFA_FCS_VPORT_SM_DELETE:
330 break;
331
332 case BFA_FCS_VPORT_SM_DELCOMP:
333 bfa_sm_set_state(vport, bfa_fcs_vport_sm_logo);
334 bfa_fcs_vport_do_logo(vport);
335 break;
336
337 case BFA_FCS_VPORT_SM_OFFLINE:
338 bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
339 break;
340
341 default:
342 bfa_assert(0);
343 }
344 }
345
346 /**
347 * Error State.
348 * This state will be set when the Vport Creation fails due to errors like
349 * Dup WWN. In this state only operation allowed is a Vport Delete.
350 */
351 static void
352 bfa_fcs_vport_sm_error(struct bfa_fcs_vport_s *vport,
353 enum bfa_fcs_vport_event event)
354 {
355 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
356 bfa_trc(__vport_fcs(vport), event);
357
358 switch (event) {
359 case BFA_FCS_VPORT_SM_DELETE:
360 bfa_sm_set_state(vport, bfa_fcs_vport_sm_uninit);
361 bfa_fcs_vport_free(vport);
362 break;
363
364 default:
365 bfa_trc(__vport_fcs(vport), event);
366 }
367 }
368
369 /**
370 * Lport cleanup is in progress since vport is being deleted. Fabric is
371 * offline, so no LOGO is needed to complete vport deletion.
372 */
373 static void
374 bfa_fcs_vport_sm_cleanup(struct bfa_fcs_vport_s *vport,
375 enum bfa_fcs_vport_event event)
376 {
377 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
378 bfa_trc(__vport_fcs(vport), event);
379
380 switch (event) {
381 case BFA_FCS_VPORT_SM_DELCOMP:
382 bfa_sm_set_state(vport, bfa_fcs_vport_sm_uninit);
383 bfa_fcs_vport_free(vport);
384 break;
385
386 case BFA_FCS_VPORT_SM_DELETE:
387 break;
388
389 default:
390 bfa_assert(0);
391 }
392 }
393
394 /**
395 * LOGO is sent to fabric. Vport delete is in progress. Lport delete cleanup
396 * is done.
397 */
398 static void
399 bfa_fcs_vport_sm_logo(struct bfa_fcs_vport_s *vport,
400 enum bfa_fcs_vport_event event)
401 {
402 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
403 bfa_trc(__vport_fcs(vport), event);
404
405 switch (event) {
406 case BFA_FCS_VPORT_SM_OFFLINE:
407 bfa_lps_discard(vport->lps);
408 /*
409 * !!! fall through !!!
410 */
411
412 case BFA_FCS_VPORT_SM_RSP_OK:
413 case BFA_FCS_VPORT_SM_RSP_ERROR:
414 bfa_sm_set_state(vport, bfa_fcs_vport_sm_uninit);
415 bfa_fcs_vport_free(vport);
416 break;
417
418 case BFA_FCS_VPORT_SM_DELETE:
419 break;
420
421 default:
422 bfa_assert(0);
423 }
424 }
425
426
427
428 /**
429 * fcs_vport_private FCS virtual port private functions
430 */
431
432 /**
433 * Send AEN notification
434 */
435 static void
436 bfa_fcs_vport_aen_post(bfa_fcs_lport_t *port, enum bfa_lport_aen_event event)
437 {
438 union bfa_aen_data_u aen_data;
439 struct bfa_log_mod_s *logmod = port->fcs->logm;
440 enum bfa_port_role role = port->port_cfg.roles;
441 wwn_t lpwwn = bfa_fcs_port_get_pwwn(port);
442 char lpwwn_ptr[BFA_STRING_32];
443 char *role_str[BFA_PORT_ROLE_FCP_MAX / 2 + 1] =
444 { "Initiator", "Target", "IPFC" };
445
446 wwn2str(lpwwn_ptr, lpwwn);
447
448 bfa_assert(role <= BFA_PORT_ROLE_FCP_MAX);
449
450 switch (event) {
451 case BFA_LPORT_AEN_NPIV_DUP_WWN:
452 bfa_log(logmod, BFA_AEN_LPORT_NPIV_DUP_WWN, lpwwn_ptr,
453 role_str[role / 2]);
454 break;
455 case BFA_LPORT_AEN_NPIV_FABRIC_MAX:
456 bfa_log(logmod, BFA_AEN_LPORT_NPIV_FABRIC_MAX, lpwwn_ptr,
457 role_str[role / 2]);
458 break;
459 case BFA_LPORT_AEN_NPIV_UNKNOWN:
460 bfa_log(logmod, BFA_AEN_LPORT_NPIV_UNKNOWN, lpwwn_ptr,
461 role_str[role / 2]);
462 break;
463 default:
464 break;
465 }
466
467 aen_data.lport.vf_id = port->fabric->vf_id;
468 aen_data.lport.roles = role;
469 aen_data.lport.ppwwn =
470 bfa_fcs_port_get_pwwn(bfa_fcs_get_base_port(port->fcs));
471 aen_data.lport.lpwwn = lpwwn;
472 }
473
474 /**
475 * This routine will be called to send a FDISC command.
476 */
477 static void
478 bfa_fcs_vport_do_fdisc(struct bfa_fcs_vport_s *vport)
479 {
480 bfa_lps_fdisc(vport->lps, vport,
481 bfa_pport_get_maxfrsize(__vport_bfa(vport)),
482 __vport_pwwn(vport), __vport_nwwn(vport));
483 vport->vport_stats.fdisc_sent++;
484 }
485
486 static void
487 bfa_fcs_vport_fdisc_rejected(struct bfa_fcs_vport_s *vport)
488 {
489 u8 lsrjt_rsn = bfa_lps_get_lsrjt_rsn(vport->lps);
490 u8 lsrjt_expl = bfa_lps_get_lsrjt_expl(vport->lps);
491
492 bfa_trc(__vport_fcs(vport), lsrjt_rsn);
493 bfa_trc(__vport_fcs(vport), lsrjt_expl);
494
495 /*
496 * For certain reason codes, we don't want to retry.
497 */
498 switch (bfa_lps_get_lsrjt_expl(vport->lps)) {
499 case FC_LS_RJT_EXP_INV_PORT_NAME: /* by brocade */
500 case FC_LS_RJT_EXP_INVALID_NPORT_ID: /* by Cisco */
501 if (vport->fdisc_retries < BFA_FCS_VPORT_MAX_RETRIES)
502 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
503 else {
504 bfa_fcs_vport_aen_post(&vport->lport,
505 BFA_LPORT_AEN_NPIV_DUP_WWN);
506 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_DUP_WWN);
507 }
508 break;
509
510 case FC_LS_RJT_EXP_INSUFF_RES:
511 /*
512 * This means max logins per port/switch setting on the
513 * switch was exceeded.
514 */
515 if (vport->fdisc_retries < BFA_FCS_VPORT_MAX_RETRIES)
516 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
517 else {
518 bfa_fcs_vport_aen_post(&vport->lport,
519 BFA_LPORT_AEN_NPIV_FABRIC_MAX);
520 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_FAILED);
521 }
522 break;
523
524 default:
525 if (vport->fdisc_retries == 0) /* Print only once */
526 bfa_fcs_vport_aen_post(&vport->lport,
527 BFA_LPORT_AEN_NPIV_UNKNOWN);
528 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
529 }
530 }
531
532 /**
533 * Called to send a logout to the fabric. Used when a V-Port is
534 * deleted/stopped.
535 */
536 static void
537 bfa_fcs_vport_do_logo(struct bfa_fcs_vport_s *vport)
538 {
539 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
540
541 vport->vport_stats.logo_sent++;
542 bfa_lps_fdisclogo(vport->lps);
543 }
544
545 /**
546 * This routine will be called by bfa_timer on timer timeouts.
547 *
548 * param[in] vport - pointer to bfa_fcs_vport_t.
549 * param[out] vport_status - pointer to return vport status in
550 *
551 * return
552 * void
553 *
554 * Special Considerations:
555 *
556 * note
557 */
558 static void
559 bfa_fcs_vport_timeout(void *vport_arg)
560 {
561 struct bfa_fcs_vport_s *vport = (struct bfa_fcs_vport_s *)vport_arg;
562
563 vport->vport_stats.fdisc_timeouts++;
564 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_TIMEOUT);
565 }
566
567 static void
568 bfa_fcs_vport_free(struct bfa_fcs_vport_s *vport)
569 {
570 bfa_fcs_fabric_delvport(__vport_fabric(vport), vport);
571 bfa_fcb_vport_delete(vport->vport_drv);
572 bfa_lps_delete(vport->lps);
573 }
574
575
576
577 /**
578 * fcs_vport_public FCS virtual port public interfaces
579 */
580
581 /**
582 * Online notification from fabric SM.
583 */
584 void
585 bfa_fcs_vport_online(struct bfa_fcs_vport_s *vport)
586 {
587 vport->vport_stats.fab_online++;
588 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_ONLINE);
589 }
590
591 /**
592 * Offline notification from fabric SM.
593 */
594 void
595 bfa_fcs_vport_offline(struct bfa_fcs_vport_s *vport)
596 {
597 vport->vport_stats.fab_offline++;
598 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_OFFLINE);
599 }
600
601 /**
602 * Cleanup notification from fabric SM on link timer expiry.
603 */
604 void
605 bfa_fcs_vport_cleanup(struct bfa_fcs_vport_s *vport)
606 {
607 vport->vport_stats.fab_cleanup++;
608 }
609
610 /**
611 * Delete completion callback from associated lport
612 */
613 void
614 bfa_fcs_vport_delete_comp(struct bfa_fcs_vport_s *vport)
615 {
616 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_DELCOMP);
617 }
618
619 /**
620 * Module initialization
621 */
622 void
623 bfa_fcs_vport_modinit(struct bfa_fcs_s *fcs)
624 {
625 }
626
627 /**
628 * Module cleanup
629 */
630 void
631 bfa_fcs_vport_modexit(struct bfa_fcs_s *fcs)
632 {
633 bfa_fcs_modexit_comp(fcs);
634 }
635
636 u32
637 bfa_fcs_vport_get_max(struct bfa_fcs_s *fcs)
638 {
639 struct bfa_ioc_attr_s ioc_attr;
640
641 bfa_get_attr(fcs->bfa, &ioc_attr);
642
643 if (ioc_attr.pci_attr.device_id == BFA_PCI_DEVICE_ID_CT)
644 return (BFA_FCS_MAX_VPORTS_SUPP_CT);
645 else
646 return (BFA_FCS_MAX_VPORTS_SUPP_CB);
647 }
648
649
650
651 /**
652 * fcs_vport_api Virtual port API
653 */
654
655 /**
656 * Use this function to instantiate a new FCS vport object. This
657 * function will not trigger any HW initialization process (which will be
658 * done in vport_start() call)
659 *
660 * param[in] vport - pointer to bfa_fcs_vport_t. This space
661 * needs to be allocated by the driver.
662 * param[in] fcs - FCS instance
663 * param[in] vport_cfg - vport configuration
664 * param[in] vf_id - VF_ID if vport is created within a VF.
665 * FC_VF_ID_NULL to specify base fabric.
666 * param[in] vport_drv - Opaque handle back to the driver's vport
667 * structure
668 *
669 * retval BFA_STATUS_OK - on success.
670 * retval BFA_STATUS_FAILED - on failure.
671 */
672 bfa_status_t
673 bfa_fcs_vport_create(struct bfa_fcs_vport_s *vport, struct bfa_fcs_s *fcs,
674 u16 vf_id, struct bfa_port_cfg_s *vport_cfg,
675 struct bfad_vport_s *vport_drv)
676 {
677 if (vport_cfg->pwwn == 0)
678 return (BFA_STATUS_INVALID_WWN);
679
680 if (bfa_fcs_port_get_pwwn(&fcs->fabric.bport) == vport_cfg->pwwn)
681 return BFA_STATUS_VPORT_WWN_BP;
682
683 if (bfa_fcs_vport_lookup(fcs, vf_id, vport_cfg->pwwn) != NULL)
684 return BFA_STATUS_VPORT_EXISTS;
685
686 if (bfa_fcs_fabric_vport_count(&fcs->fabric) ==
687 bfa_fcs_vport_get_max(fcs))
688 return BFA_STATUS_VPORT_MAX;
689
690 vport->lps = bfa_lps_alloc(fcs->bfa);
691 if (!vport->lps)
692 return BFA_STATUS_VPORT_MAX;
693
694 vport->vport_drv = vport_drv;
695 bfa_sm_set_state(vport, bfa_fcs_vport_sm_uninit);
696
697 bfa_fcs_lport_init(&vport->lport, fcs, vf_id, vport_cfg, vport);
698
699 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_CREATE);
700
701 return BFA_STATUS_OK;
702 }
703
704 /**
705 * Use this function initialize the vport.
706 *
707 * @param[in] vport - pointer to bfa_fcs_vport_t.
708 *
709 * @returns None
710 */
711 bfa_status_t
712 bfa_fcs_vport_start(struct bfa_fcs_vport_s *vport)
713 {
714 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_START);
715
716 return BFA_STATUS_OK;
717 }
718
719 /**
720 * Use this function quiese the vport object. This function will return
721 * immediately, when the vport is actually stopped, the
722 * bfa_drv_vport_stop_cb() will be called.
723 *
724 * param[in] vport - pointer to bfa_fcs_vport_t.
725 *
726 * return None
727 */
728 bfa_status_t
729 bfa_fcs_vport_stop(struct bfa_fcs_vport_s *vport)
730 {
731 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_STOP);
732
733 return BFA_STATUS_OK;
734 }
735
736 /**
737 * Use this function to delete a vport object. Fabric object should
738 * be stopped before this function call.
739 *
740 * param[in] vport - pointer to bfa_fcs_vport_t.
741 *
742 * return None
743 */
744 bfa_status_t
745 bfa_fcs_vport_delete(struct bfa_fcs_vport_s *vport)
746 {
747 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_DELETE);
748
749 return BFA_STATUS_OK;
750 }
751
752 /**
753 * Use this function to get vport's current status info.
754 *
755 * param[in] vport pointer to bfa_fcs_vport_t.
756 * param[out] attr pointer to return vport attributes
757 *
758 * return None
759 */
760 void
761 bfa_fcs_vport_get_attr(struct bfa_fcs_vport_s *vport,
762 struct bfa_vport_attr_s *attr)
763 {
764 if (vport == NULL || attr == NULL)
765 return;
766
767 bfa_os_memset(attr, 0, sizeof(struct bfa_vport_attr_s));
768
769 bfa_fcs_port_get_attr(&vport->lport, &attr->port_attr);
770 attr->vport_state = bfa_sm_to_state(vport_sm_table, vport->sm);
771 }
772
773 /**
774 * Use this function to get vport's statistics.
775 *
776 * param[in] vport pointer to bfa_fcs_vport_t.
777 * param[out] stats pointer to return vport statistics in
778 *
779 * return None
780 */
781 void
782 bfa_fcs_vport_get_stats(struct bfa_fcs_vport_s *vport,
783 struct bfa_vport_stats_s *stats)
784 {
785 *stats = vport->vport_stats;
786 }
787
788 /**
789 * Use this function to clear vport's statistics.
790 *
791 * param[in] vport pointer to bfa_fcs_vport_t.
792 *
793 * return None
794 */
795 void
796 bfa_fcs_vport_clr_stats(struct bfa_fcs_vport_s *vport)
797 {
798 bfa_os_memset(&vport->vport_stats, 0, sizeof(struct bfa_vport_stats_s));
799 }
800
801 /**
802 * Lookup a virtual port. Excludes base port from lookup.
803 */
804 struct bfa_fcs_vport_s *
805 bfa_fcs_vport_lookup(struct bfa_fcs_s *fcs, u16 vf_id, wwn_t vpwwn)
806 {
807 struct bfa_fcs_vport_s *vport;
808 struct bfa_fcs_fabric_s *fabric;
809
810 bfa_trc(fcs, vf_id);
811 bfa_trc(fcs, vpwwn);
812
813 fabric = bfa_fcs_vf_lookup(fcs, vf_id);
814 if (!fabric) {
815 bfa_trc(fcs, vf_id);
816 return NULL;
817 }
818
819 vport = bfa_fcs_fabric_vport_lookup(fabric, vpwwn);
820 return vport;
821 }
822
823 /**
824 * FDISC Response
825 */
826 void
827 bfa_cb_lps_fdisc_comp(void *bfad, void *uarg, bfa_status_t status)
828 {
829 struct bfa_fcs_vport_s *vport = uarg;
830
831 bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
832 bfa_trc(__vport_fcs(vport), status);
833
834 switch (status) {
835 case BFA_STATUS_OK:
836 /*
837 * Initialiaze the V-Port fields
838 */
839 __vport_fcid(vport) = bfa_lps_get_pid(vport->lps);
840 vport->vport_stats.fdisc_accepts++;
841 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_OK);
842 break;
843
844 case BFA_STATUS_INVALID_MAC:
845 /*
846 * Only for CNA
847 */
848 vport->vport_stats.fdisc_acc_bad++;
849 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
850
851 break;
852
853 case BFA_STATUS_EPROTOCOL:
854 switch (bfa_lps_get_extstatus(vport->lps)) {
855 case BFA_EPROTO_BAD_ACCEPT:
856 vport->vport_stats.fdisc_acc_bad++;
857 break;
858
859 case BFA_EPROTO_UNKNOWN_RSP:
860 vport->vport_stats.fdisc_unknown_rsp++;
861 break;
862
863 default:
864 break;
865 }
866
867 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
868 break;
869
870 case BFA_STATUS_FABRIC_RJT:
871 vport->vport_stats.fdisc_rejects++;
872 bfa_fcs_vport_fdisc_rejected(vport);
873 break;
874
875 default:
876 vport->vport_stats.fdisc_rsp_err++;
877 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
878 }
879 }
880
881 /**
882 * LOGO response
883 */
884 void
885 bfa_cb_lps_fdisclogo_comp(void *bfad, void *uarg)
886 {
887 struct bfa_fcs_vport_s *vport = uarg;
888 bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_OK);
889 }
890
891