forked from ecdufcdrvr/bcmufctdrvr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathocs_sport.c
1915 lines (1673 loc) · 55.4 KB
/
ocs_sport.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* BSD LICENSE
*
* Copyright (c) 2011-2018 Broadcom. All Rights Reserved.
* The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file
* Details SLI port (sport) functions.
*/
#include "ocs.h"
#include "ocs_fabric.h"
#include "ocs_els.h"
#include "ocs_device.h"
#include "ocs_spdk_nvmet.h"
static void ocs_vport_update_spec(ocs_sport_t *sport);
static void ocs_vport_link_down(ocs_sport_t *sport);
void ocs_mgmt_sport_list(ocs_textbuf_t *textbuf, void *sport);
void ocs_mgmt_sport_get_all(ocs_textbuf_t *textbuf, void *sport);
int ocs_mgmt_sport_get(ocs_textbuf_t *textbuf, char *parent, char *name, void *sport);
int ocs_mgmt_sport_set(char *parent, char *name, char *value, void *sport);
int ocs_mgmt_sport_exec(char *parent, char *action, void *arg_in, uint32_t arg_in_length,
void *arg_out, uint32_t arg_out_length, void *sport);
static ocs_mgmt_functions_t sport_mgmt_functions = {
.get_list_handler = ocs_mgmt_sport_list,
.get_handler = ocs_mgmt_sport_get,
.get_all_handler = ocs_mgmt_sport_get_all,
.set_handler = ocs_mgmt_sport_set,
.exec_handler = ocs_mgmt_sport_exec,
};
/*!
@defgroup sport_sm SLI Port (sport) State Machine: States
*/
/**
* @ingroup sport_sm
* @brief SLI port HAL callback.
*
* @par Description
* This function is called in response to a HAL sport event. This code resolves
* the reference to the sport object, and posts the corresponding event.
*
* @param arg Pointer to the OCS context.
* @param event HAL sport event.
* @param data Application-specific event (pointer to the sport).
*
* @return Returns 0 on success, or a negative error value on failure.
*/
int32_t
ocs_port_cb(void *arg, ocs_hal_port_event_e event, void *data)
{
ocs_t *ocs = arg;
ocs_sli_port_t *sport = data;
switch (event) {
case OCS_HAL_PORT_ALLOC_OK:
ocs_log_debug(ocs, "%s: OCS_HAL_PORT_ALLOC_OK\n", __func__);
ocs_sm_post_event(&sport->sm, OCS_EVT_SPORT_ALLOC_OK, NULL);
break;
case OCS_HAL_PORT_ALLOC_FAIL:
ocs_log_debug(ocs, "%s: OCS_HAL_PORT_ALLOC_FAIL\n", __func__);
ocs_sm_post_event(&sport->sm, OCS_EVT_SPORT_ALLOC_FAIL, NULL);
break;
case OCS_HAL_PORT_ATTACH_OK:
ocs_log_debug(ocs, "%s: OCS_HAL_PORT_ATTACH_OK\n", __func__);
ocs_sm_post_event(&sport->sm, OCS_EVT_SPORT_ATTACH_OK, NULL);
break;
case OCS_HAL_PORT_ATTACH_FAIL:
ocs_log_debug(ocs, "%s: OCS_HAL_PORT_ATTACH_FAIL\n", __func__);
ocs_sm_post_event(&sport->sm, OCS_EVT_SPORT_ATTACH_FAIL, NULL);
break;
case OCS_HAL_PORT_FREE_OK:
ocs_log_debug(ocs, "%s: OCS_HAL_PORT_FREE_OK\n", __func__);
ocs_sm_post_event(&sport->sm, OCS_EVT_SPORT_FREE_OK, NULL);
break;
case OCS_HAL_PORT_FREE_FAIL:
ocs_log_debug(ocs, "%s: OCS_HAL_PORT_FREE_FAIL\n", __func__);
ocs_sm_post_event(&sport->sm, OCS_EVT_SPORT_FREE_FAIL, NULL);
break;
default:
ocs_log_test(ocs, "%s: unknown event %#x\n", __func__, event);
}
return 0;
}
/**
* @ingroup sport_sm
* @brief Allocate a SLI port object.
*
* @par Description
* A sport object is allocated and associated with the domain. Various
* structure members are initialized.
*
* @param domain Pointer to the domain structure.
* @param wwpn World wide port name in host endian.
* @param wwnn World wide node name in host endian.
* @param fc_id Port ID of sport may be specified, use UINT32_MAX to fabric choose
* @param enable_ini Enables initiator capability on this port using a non-zero value.
* @param enable_tgt Enables target capability on this port using a non-zero value.
*
* @return Pointer to an ocs_sport_t object; or NULL.
*/
ocs_sport_t *
ocs_sport_alloc(ocs_domain_t *domain, uint64_t wwpn, uint64_t wwnn, uint32_t fc_id, uint8_t enable_ini, uint8_t enable_tgt)
{
ocs_sport_t *sport;
if (domain->ocs->ctrlmask & OCS_CTRLMASK_INHIBIT_INITIATOR) {
enable_ini = 0;
}
/* Return a failure if this sport has already been allocated */
if (wwpn != 0) {
sport = ocs_sport_find_wwn(domain, wwnn, wwpn);
if (sport != NULL) {
ocs_log_test(domain->ocs, "%s: Failed: SPORT %016" PRIx64 " %016" PRIx64 " already allocated\n",
__func__, wwnn, wwpn);
return NULL;
}
}
sport = ocs_malloc(domain->ocs, sizeof(*sport), OCS_M_NOWAIT | OCS_M_ZERO);
if (sport) {
sport->ocs = domain->ocs;
ocs_snprintf(sport->display_name, sizeof(sport->display_name), "------");
sport->domain = domain;
sport->lookup = spv_new(domain->ocs);
sport->instance_index = domain->sport_instance_count++;
ocs_sport_lock_init(sport);
ocs_list_init(&sport->node_list, ocs_node_t, link);
sport->sm.app = sport;
sport->enable_ini = enable_ini;
sport->enable_tgt = enable_tgt;
sport->enable_rscn = (sport->enable_ini || (sport->enable_tgt && enable_target_rscn(sport->ocs)));
/* Copy service parameters from domain */
ocs_memcpy(sport->service_params, domain->service_params, sizeof(fc_plogi_payload_t));
/* Update requested fc_id */
sport->fc_id = fc_id;
/* Update the sport's service parameters for the new wwn's */
sport->wwpn = wwpn;
sport->wwnn = wwnn;
ocs_snprintf(sport->wwnn_str, sizeof(sport->wwnn_str), "%016" PRIX64, wwnn);
/* Initialize node group list */
ocs_lock_init(sport->ocs, &sport->node_group_lock, "node_group_lock[%d]", sport->instance_index);
ocs_list_init(&sport->node_group_dir_list, ocs_node_group_dir_t, link);
/* if this is the "first" sport of the domain, then make it the "phys" sport */
ocs_domain_lock(domain);
if (ocs_list_empty(&domain->sport_list)) {
domain->sport = sport;
}
ocs_list_add_tail(&domain->sport_list, sport);
ocs_domain_unlock(domain);
sport->mgmt_functions = &sport_mgmt_functions;
ocs_log_debug(domain->ocs, "[%s] allocate sport\n", sport->display_name);
}
return sport;
}
/**
* @ingroup sport_sm
* @brief Free a SLI port object.
*
* @par Description
* The sport object is freed.
*
* @param sport Pointer to the SLI port object.
*
* @return None.
*/
void
ocs_sport_free(ocs_sport_t *sport)
{
ocs_domain_t *domain;
ocs_node_group_dir_t *node_group_dir;
ocs_node_group_dir_t *node_group_dir_next;
int post_all_free = FALSE;
if (sport) {
domain = sport->domain;
ocs_log_debug(domain->ocs, "[%s] free sport\n", sport->display_name);
ocs_domain_lock(domain);
ocs_list_remove(&domain->sport_list, sport);
ocs_sport_lock(sport);
spv_del(sport->lookup);
sport->lookup = NULL;
ocs_lock(&domain->lookup_lock);
/* Remove the sport from the domain's sparse vector lookup table */
spv_set(domain->lookup, sport->fc_id, NULL);
ocs_unlock(&domain->lookup_lock);
/* if this is the physical sport, then clear it out of the domain */
if (sport == domain->sport) {
domain->sport = NULL;
}
/*
* If the domain's sport_list is empty, then post the ALL_NODES_FREE event to the domain,
* after the lock is released. The domain may be free'd as a result of the event.
*/
if (ocs_list_empty(&domain->sport_list)) {
post_all_free = TRUE;
}
/* Free any node group directories */
ocs_lock(&sport->node_group_lock);
ocs_list_foreach_safe(&sport->node_group_dir_list, node_group_dir, node_group_dir_next) {
ocs_unlock(&sport->node_group_lock);
ocs_node_group_dir_free(node_group_dir);
ocs_lock(&sport->node_group_lock);
}
ocs_unlock(&sport->node_group_lock);
ocs_sport_unlock(sport);
ocs_domain_unlock(domain);
if (post_all_free) {
ocs_domain_post_event(domain, OCS_EVT_ALL_CHILD_NODES_FREE, NULL);
}
ocs_sport_lock_free(sport);
ocs_lock_free(&sport->node_group_lock);
ocs_free(domain->ocs, sport, sizeof(*sport));
}
}
/**
* @ingroup sport_sm
* @brief Free memory resources of a SLI port object.
*
* @par Description
* After the sport object is freed, its child objects are freed.
*
* @param sport Pointer to the SLI port object.
*
* @return None.
*/
void ocs_sport_force_free(ocs_sport_t *sport)
{
ocs_node_t *node;
ocs_node_t *next;
/* shutdown sm processing */
ocs_sm_disable(&sport->sm);
ocs_scsi_notify_sport_force_free(sport);
ocs_sport_lock(sport);
ocs_list_foreach_safe(&sport->node_list, node, next) {
ocs_node_force_free(node);
}
ocs_sport_unlock(sport);
ocs_sport_free(sport);
}
/**
* @ingroup sport_sm
* @brief Return a SLI port object, given an instance index.
*
* @par Description
* A pointer to a sport object is returned, given its instance @c index.
*
* @param domain Pointer to the domain.
* @param index Instance index value to find.
*
* @return Returns a pointer to the ocs_sport_t object; or NULL.
*/
ocs_sport_t *
ocs_sport_get_instance(ocs_domain_t *domain, uint32_t index)
{
ocs_sport_t *sport;
ocs_domain_lock(domain);
ocs_list_foreach(&domain->sport_list, sport) {
if (sport->instance_index == index) {
ocs_domain_unlock(domain);
return sport;
}
}
ocs_domain_unlock(domain);
return NULL;
}
/**
* @ingroup sport_sm
* @brief Find a SLI port object, given an FC_ID.
*
* @par Description
* Returns a pointer to the sport object, given an FC_ID.
*
* @param domain Pointer to the domain.
* @param d_id FC_ID to find.
*
* @return Returns a pointer to the ocs_sport_t; or NULL.
*/
ocs_sport_t *
ocs_sport_find(ocs_domain_t *domain, uint32_t d_id)
{
ocs_sport_t *sport;
ocs_assert(domain, NULL);
ocs_lock(&domain->lookup_lock);
if (domain->lookup == NULL) {
ocs_log_test(domain->ocs, "%s(%d): assertion failed: domain->lookup is not valid\n",
__func__, __LINE__);
ocs_unlock(&domain->lookup_lock);
return NULL;
}
sport = spv_get(domain->lookup, d_id);
ocs_unlock(&domain->lookup_lock);
return sport;
}
/**
* @ingroup sport_sm
* @brief Find a SLI port, given the WWNN and WWPN.
*
* @par Description
* Return a pointer to a sport, given the WWNN and WWPN.
*
* @param domain Pointer to the domain.
* @param wwnn World wide node name.
* @param wwpn World wide port name.
*
* @return Returns a pointer to a SLI port, if found; or NULL.
*/
ocs_sport_t *
ocs_sport_find_wwn(ocs_domain_t *domain, uint64_t wwnn, uint64_t wwpn)
{
ocs_sport_t *sport = NULL;
ocs_domain_lock(domain);
ocs_list_foreach(&domain->sport_list, sport) {
if ((sport->wwnn == wwnn) && (sport->wwpn == wwpn)) {
ocs_domain_unlock(domain);
return sport;
}
}
ocs_domain_unlock(domain);
return NULL;
}
/**
* @ingroup sport_sm
* @brief Request a SLI port attach.
*
* @par Description
* External call to request an attach for a sport, given an FC_ID.
*
* @param sport Pointer to the sport context.
* @param fc_id FC_ID of which to attach.
*
* @return Returns 0 on success, or a negative error value on failure.
*/
int32_t
ocs_sport_attach(ocs_sport_t *sport, uint32_t fc_id)
{
ocs_hal_rtn_e rc;
ocs_node_t *node;
/* Set our lookup */
ocs_lock(&sport->domain->lookup_lock);
spv_set(sport->domain->lookup, fc_id, sport);
ocs_unlock(&sport->domain->lookup_lock);
/* Update our display_name */
ocs_node_fcid_display(fc_id, sport->display_name, sizeof(sport->display_name));
ocs_sport_lock(sport);
ocs_list_foreach(&sport->node_list, node) {
ocs_node_update_display_name(node);
}
ocs_sport_unlock(sport);
ocs_log_debug(sport->ocs, "[%s] attach sport: fc_id x%06x\n", sport->display_name, fc_id);
rc = ocs_hal_port_attach(&sport->ocs->hal, sport, fc_id);
if (rc != OCS_HAL_RTN_SUCCESS) {
ocs_log_err(sport->ocs, "%s: ocs_hal_port_attach failed: %d\n", __func__, rc);
return -1;
}
return 0;
}
/**
* @brief Common SLI port state machine declarations and initialization.
*/
#define std_sport_state_decl() \
ocs_sport_t *sport = NULL; \
ocs_domain_t *domain = NULL; \
ocs_t *ocs = NULL; \
\
ocs_assert(ctx, NULL); \
sport = ctx->app; \
ocs_assert(sport, NULL); \
\
domain = sport->domain; \
ocs_assert(domain, NULL); \
ocs = sport->ocs; \
ocs_assert(ocs, NULL);
/**
* @brief Common SLI port state machine trace logging.
*/
#define sport_sm_trace(sport) \
do { \
if (OCS_LOG_ENABLE_DOMAIN_SM_TRACE(ocs)) \
ocs_log_debug(ocs, "[%s] %-20s %-20s\n", sport->display_name, __func__, ocs_sm_event_name(evt)); \
} while (0)
/**
* @brief SLI port state machine: Common event handler.
*
* @par Description
* Handle common sport events.
*
* @param funcname Function name to display.
* @param ctx Sport state machine context.
* @param evt Event to process.
* @param arg Per event optional argument.
*
* @return Returns NULL.
*/
static void *
__ocs_sport_common(const char *funcname, ocs_sm_ctx_t *ctx, ocs_sm_event_t evt, void *arg)
{
std_sport_state_decl();
switch(evt) {
case OCS_EVT_ENTER:
case OCS_EVT_REENTER:
case OCS_EVT_EXIT:
case OCS_EVT_ALL_CHILD_NODES_FREE:
break;
case OCS_EVT_SPORT_ATTACH_OK:
ocs_sm_transition(ctx, __ocs_sport_attached, NULL);
break;
case OCS_EVT_SHUTDOWN: {
ocs_node_t *node;
ocs_node_t *node_next;
int node_list_empty;
/* Flag this sport as shutting down */
sport->shutting_down = 1;
if (sport->is_vport) {
ocs_vport_link_down(sport);
}
ocs_sport_lock(sport);
node_list_empty = ocs_list_empty(&sport->node_list);
ocs_sport_unlock(sport);
if (node_list_empty) {
//sm: node list is empty / ocs_hal_port_free
/* Remove the sport from the domain's sparse vector lookup table */
ocs_lock(&domain->lookup_lock);
spv_set(domain->lookup, sport->fc_id, NULL);
ocs_unlock(&domain->lookup_lock);
ocs_sm_transition(ctx, __ocs_sport_wait_port_free, NULL);
if (ocs_hal_port_free(&ocs->hal, sport)) {
ocs_log_test(sport->ocs, "%s: ocs_hal_port_free failed\n", __func__);
/* Not much we can do, free the sport anyways */
ocs_sport_free(sport);
}
} else {
//sm: node list is not empty / shutdown nodes
ocs_sm_transition(ctx, __ocs_sport_wait_shutdown, NULL);
ocs_sport_lock(sport);
ocs_list_foreach_safe(&sport->node_list, node, node_next) {
/*
* If this is a vport, logout of the fabric controller so that it
* deletes the vport on the switch.
*/
if((node->rnode.fc_id == FC_ADDR_FABRIC) && (sport->is_vport)) {
/* if link is down, don't send logo */
if (sport->ocs->hal.link.status == SLI_LINK_STATUS_DOWN) {
ocs_node_post_event(node, OCS_EVT_SHUTDOWN, NULL);
} else {
ocs_log_debug(ocs,"[%s] %s: sport shutdown vport,sending logo to node\n",
node->display_name, __func__);
if (ocs_send_logo(node, OCS_FC_ELS_SEND_DEFAULT_TIMEOUT,
0, NULL, NULL) == NULL) {
/* failed to send LOGO, go ahead and cleanup node anyways */
node_printf(node, "Failed to send LOGO\n");
ocs_node_post_event(node, OCS_EVT_SHUTDOWN_EXPLICIT_LOGO, NULL);
} else {
/* sent LOGO, wait for response */
ocs_node_transition(node, __ocs_d_wait_logo_rsp, NULL);
}
}
} else {
ocs_node_post_event(node, OCS_EVT_SHUTDOWN, NULL);
}
}
ocs_sport_unlock(sport);
}
break;
}
default:
ocs_log_test(sport->ocs, "[%s] %-20s %-20s not handled\n", sport->display_name, funcname, ocs_sm_event_name(evt));
break;
}
return NULL;
}
/**
* @ingroup sport_sm
* @brief SLI port state machine: Physical sport allocated.
*
* @par Description
* This is the initial state for sport objects.
*
* @param ctx Remote node state machine context.
* @param evt Event to process.
* @param arg Per event optional argument.
*
* @return Returns NULL.
*/
void *
__ocs_sport_allocated(ocs_sm_ctx_t *ctx, ocs_sm_event_t evt, void *arg)
{
std_sport_state_decl();
sport_sm_trace(sport);
switch(evt) {
/* the physical sport is attached */
case OCS_EVT_SPORT_ATTACH_OK:
ocs_assert(sport == domain->sport, NULL);
ocs_sm_transition(ctx, __ocs_sport_attached, NULL);
break;
case OCS_EVT_SPORT_ALLOC_OK:
/* ignore */
break;
default:
__ocs_sport_common(__func__, ctx, evt, arg);
return NULL;
}
return NULL;
}
/**
* @ingroup sport_sm
* @brief SLI port state machine: Handle initial virtual port events.
*
* @par Description
* This state is entered when a virtual port is instantiated,
*
* @param ctx Remote node state machine context.
* @param evt Event to process.
* @param arg Per event optional argument.
*
* @return Returns NULL.
*/
void *
__ocs_sport_vport_init(ocs_sm_ctx_t *ctx, ocs_sm_event_t evt, void *arg)
{
std_sport_state_decl();
sport_sm_trace(sport);
switch(evt) {
case OCS_EVT_ENTER: {
uint64_t be_wwpn = ocs_htobe64(sport->wwpn);
if (sport->wwpn == 0) {
ocs_log_debug(ocs, "vport: letting f/w select WWN\n");
}
if (sport->fc_id != UINT32_MAX) {
ocs_log_debug(ocs, "vport: hard coding port id: %x\n", sport->fc_id);
}
ocs_sm_transition(ctx, __ocs_sport_vport_wait_alloc, NULL);
/* If wwpn is zero, then we'll let the f/w */
if (ocs_hal_port_alloc(&ocs->hal, sport, sport->domain,
(sport->wwpn == 0) ? NULL : (uint8_t *)&be_wwpn)) {
ocs_log_err(ocs, "Can't allocate port\n");
break;
}
break;
}
default:
__ocs_sport_common(__func__, ctx, evt, arg);
return NULL;
}
return NULL;
}
/**
* @ingroup sport_sm
* @brief SLI port state machine: Wait for the HAL SLI port allocation to complete.
*
* @par Description
* Waits for the HAL sport allocation request to complete.
*
* @param ctx Remote node state machine context.
* @param evt Event to process.
* @param arg Per event optional argument.
*
* @return Returns NULL.
*/
void *
__ocs_sport_vport_wait_alloc(ocs_sm_ctx_t *ctx, ocs_sm_event_t evt, void *arg)
{
std_sport_state_decl();
sport_sm_trace(sport);
switch(evt) {
case OCS_EVT_SPORT_ALLOC_OK: {
fc_plogi_payload_t *sp = (fc_plogi_payload_t*) sport->service_params;
ocs_node_t *fabric;
/* If we let f/w assign wwn's, then sport wwn's with those returned by hal */
if (sport->wwnn == 0) {
sport->wwnn = ocs_be64toh(sport->sli_wwnn);
sport->wwpn = ocs_be64toh(sport->sli_wwpn);
ocs_snprintf(sport->wwnn_str, sizeof(sport->wwnn_str), "%016" PRIX64, sport->wwpn);
}
/* Update the sport's service parameters */
sp->port_name_hi = ocs_htobe32((uint32_t) (sport->wwpn >> 32ll));
sp->port_name_lo = ocs_htobe32((uint32_t) sport->wwpn);
sp->node_name_hi = ocs_htobe32((uint32_t) (sport->wwnn >> 32ll));
sp->node_name_lo = ocs_htobe32((uint32_t) sport->wwnn);
/* if sport->fc_id is uninitialized, then request that the fabric node use FDISC
* to find an fc_id. Otherwise we're restoring vports, or we're in
* fabric emulation mode, so attach the fc_id
*/
if (sport->fc_id == UINT32_MAX) {
fabric = ocs_node_alloc(sport, FC_ADDR_FABRIC, FALSE, FALSE);
if (fabric == NULL) {
ocs_log_err(ocs, "%s: ocs_node_alloc() failed\n", __func__);
return NULL;
}
ocs_node_transition(fabric, __ocs_vport_fabric_init, NULL);
} else {
ocs_snprintf(sport->wwnn_str, sizeof(sport->wwnn_str), "%016" PRIX64, sport->wwpn);
ocs_sport_attach(sport, sport->fc_id);
}
ocs_sm_transition(ctx, __ocs_sport_vport_allocated, NULL);
break;
}
default:
__ocs_sport_common(__func__, ctx, evt, arg);
return NULL;
}
return NULL;
}
/**
* @ingroup sport_sm
* @brief SLI port state machine: virtual sport allocated.
*
* @par Description
* This state is entered after the sport is allocated; it then waits for a fabric node
* FDISC to complete, which requests a sport attach.
* The sport attach complete is handled in this state.
*
* @param ctx Remote node state machine context.
* @param evt Event to process.
* @param arg Per event optional argument.
*
* @return Returns NULL.
*/
void *
__ocs_sport_vport_allocated(ocs_sm_ctx_t *ctx, ocs_sm_event_t evt, void *arg)
{
std_sport_state_decl();
sport_sm_trace(sport);
switch(evt) {
case OCS_EVT_SPORT_ATTACH_OK: {
ocs_node_t *node;
if (!(domain->femul_enable)) {
/* Find our fabric node, and forward this event */
node = ocs_node_find(sport, FC_ADDR_FABRIC);
if (node == NULL) {
ocs_log_test(ocs, "%s: can't find node %06x\n", __func__, FC_ADDR_FABRIC);
break;
}
//sm: / forward sport attach to fabric node
ocs_node_post_event(node, evt, NULL);
}
ocs_sm_transition(ctx, __ocs_sport_attached, NULL);
break;
}
default:
__ocs_sport_common(__func__, ctx, evt, arg);
return NULL;
}
return NULL;
}
/**
* @ingroup sport_sm
* @brief SLI port state machine: Attached.
*
* @par Description
* State entered after the sport attach has completed.
*
* @param ctx Remote node state machine context.
* @param evt Event to process.
* @param arg Per event optional argument.
*
* @return Returns NULL.
*/
void *
__ocs_sport_attached(ocs_sm_ctx_t *ctx, ocs_sm_event_t evt, void *arg)
{
std_sport_state_decl();
sport_sm_trace(sport);
switch(evt) {
case OCS_EVT_ENTER: {
ocs_node_t *node;
ocs_log_debug(ocs, "[%s] SPORT attached WWPN %016" PRIx64 " WWNN %016" PRIx64 "\n", sport->display_name,
sport->wwpn, sport->wwnn);
ocs_sport_lock(sport);
ocs_list_foreach(&sport->node_list, node) {
ocs_node_update_display_name(node);
}
ocs_sport_unlock(sport);
sport->tgt_id = sport->fc_id;
if (ocs->enable_ini) {
ocs_scsi_ini_new_sport(sport);
}
if (ocs->enable_tgt) {
ocs_scsi_tgt_new_sport(sport);
ocs_nvme_tgt_new_sport(sport);
}
/* Update the vport (if its not the physical sport) parameters */
if (sport->is_vport) {
ocs_vport_update_spec(sport);
}
#if defined(ENABLE_FABRIC_EMULATION)
/* If Fabric Emulation, then register with driver name server */
if (domain->femul_enable) {
ocs_femul_sport_attach(sport);
/* Decrement outstanding femul_count, if it goes to zero, then notify fabric emulation */
if (ocs_atomic_read(&domain->femul_count)) {
if (ocs_atomic_sub_return(&domain->femul_count, 1) == 1) {
ocs_femul_ports_attached(domain);
}
}
}
#endif
break;
}
case OCS_EVT_EXIT:
ocs_log_debug(ocs, "[%s] SPORT deattached WWPN %016" PRIx64 " WWNN %016" PRIx64 "\n", sport->display_name,
sport->wwpn, sport->wwnn);
if (ocs->enable_ini) {
ocs_scsi_ini_del_sport(sport);
}
if (ocs->enable_tgt) {
ocs_scsi_tgt_del_sport(sport);
}
break;
default:
__ocs_sport_common(__func__, ctx, evt, arg);
return NULL;
}
return NULL;
}
/**
* @ingroup sport_sm
* @brief SLI port state machine: Wait for the node shutdowns to complete.
*
* @par Description
* Waits for the ALL_CHILD_NODES_FREE event to be posted from the node
* shutdown process.
*
* @param ctx Remote node state machine context.
* @param evt Event to process.
* @param arg Per event optional argument.
*
* @return Returns NULL.
*/
void *
__ocs_sport_wait_shutdown(ocs_sm_ctx_t *ctx, ocs_sm_event_t evt, void *arg)
{
std_sport_state_decl();
sport_sm_trace(sport);
switch(evt) {
case OCS_EVT_SPORT_ALLOC_OK:
case OCS_EVT_SPORT_ALLOC_FAIL:
case OCS_EVT_SPORT_ATTACH_OK:
case OCS_EVT_SPORT_ATTACH_FAIL:
/* ignore these events - just wait for the all free event */
break;
case OCS_EVT_ALL_CHILD_NODES_FREE: {
/* Remove the sport from the domain's sparse vector lookup table */
ocs_lock(&domain->lookup_lock);
spv_set(domain->lookup, sport->fc_id, NULL);
ocs_unlock(&domain->lookup_lock);
ocs_sm_transition(ctx, __ocs_sport_wait_port_free, NULL);
if (ocs_hal_port_free(&ocs->hal, sport)) {
ocs_log_err(sport->ocs, "%s: ocs_hal_port_free failed\n", __func__);
/* Not much we can do, free the sport anyways */
ocs_sport_free(sport);
}
break;
}
default:
__ocs_sport_common(__func__, ctx, evt, arg);
return NULL;
}
return NULL;
}
/**
* @ingroup sport_sm
* @brief SLI port state machine: Wait for the HAL's port free to complete.
*
* @par Description
* Waits for the HAL's port free to complete.
*
* @param ctx Remote node state machine context.
* @param evt Event to process.
* @param arg Per event optional argument.
*
* @return Returns NULL.
*/
void *
__ocs_sport_wait_port_free(ocs_sm_ctx_t *ctx, ocs_sm_event_t evt, void *arg)
{
std_sport_state_decl();
sport_sm_trace(sport);
switch(evt) {
case OCS_EVT_SPORT_ATTACH_OK:
/* Ignore as we are waiting for the free CB */
break;
case OCS_EVT_SPORT_FREE_OK: {
/* All done, free myself */
//sm: / ocs_sport_free
ocs_sport_free(sport);
break;
}
default:
__ocs_sport_common(__func__, ctx, evt, arg);
return NULL;
}
return NULL;
}
/**
* @ingroup sport_sm
* @brief Start the vports on a domain
*
* @par Description
* Use the vport specification to find the associated vports and start them.
*
* @param domain Pointer to the domain context.
*
* @return Returns 0 on success, or a negative error value on failure.
*/
int32_t
ocs_vport_start(ocs_domain_t *domain)
{
ocs_t *ocs = domain->ocs;
ocs_xport_t *xport = ocs->xport;
ocs_vport_spec_t *vport;
ocs_vport_spec_t *next;
ocs_sport_t *sport;
int32_t rc = 0;
ocs_device_lock(ocs);
ocs_list_foreach_safe(&xport->vport_list, vport, next) {
if (vport->domain_instance == domain->instance_index &&
vport->sport == NULL) {
#if defined(ENABLE_FABRIC_EMULATION)
if (domain->femul_enable) {
vport->fc_id = ocs_femul_portid_alloc(domain);
}
#endif
/* Allocate a sport */
vport->sport = sport = ocs_sport_alloc(domain, vport->wwpn, vport->wwnn, vport->fc_id,
vport->enable_ini, vport->enable_tgt);
if (sport == NULL) {
rc = -1;
} else {
sport->is_vport = 1;
sport->tgt_data = vport->tgt_data;
sport->ini_data = vport->ini_data;
/* Transition to vport_init */
ocs_sm_transition(&sport->sm, __ocs_sport_vport_init, NULL);
}
}
}
ocs_device_unlock(ocs);
return rc;
}
/**
* @ingroup sport_sm
* @brief Clear the sport reference in the vport specification.
*
* @par Description
* Clear the sport pointer on the vport specification when the vport is torn down. This allows it to be
* re-created when the link is re-established.
*
* @param sport Pointer to the sport context.
*/
static void
ocs_vport_link_down(ocs_sport_t *sport)
{
ocs_t *ocs = sport->ocs;
ocs_xport_t *xport = ocs->xport;
ocs_vport_spec_t *vport;
ocs_device_lock(ocs);
ocs_list_foreach(&xport->vport_list, vport) {
if (vport->sport == sport) {
vport->sport = NULL;
break;
}
}
ocs_device_unlock(ocs);
}