forked from ecdufcdrvr/bcmufctdrvr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathocs_fabric.c
2133 lines (1858 loc) · 54 KB
/
ocs_fabric.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
*
* This file implements remote node state machines for:
* - Fabric logins.
* - Fabric controller events.
* - Name/directory services interaction.
* - Point-to-point logins.
*/
/*!
@defgroup fabric_sm Node State Machine: Fabric States
@defgroup ns_sm Node State Machine: Name/Directory Services States
@defgroup p2p_sm Node State Machine: Point-to-Point Node States
*/
#include "ocs.h"
#include "ocs_fabric.h"
#include "ocs_els.h"
#include "ocs_device.h"
static void ocs_fabric_initiate_shutdown(ocs_node_t *node);
static void * __ocs_fabric_common(const char *funcname, ocs_sm_ctx_t *ctx, ocs_sm_event_t evt, void *arg);
static int32_t ocs_start_ns_node(ocs_sport_t *sport);
static int32_t ocs_start_fabctl_node(ocs_sport_t *sport);
static int32_t ocs_process_gidft_payload(ocs_node_t *node, fcct_gidft_acc_t *gidft, uint32_t gidft_len);
static void ocs_process_rscn(ocs_node_t *node, ocs_node_cb_t *cbdata);
static uint64_t ocs_get_wwpn(fc_plogi_payload_t *sp);
static void gidft_delay_timer_cb(void *arg);
/**
* @ingroup fabric_sm
* @brief Fabric node state machine: Initial state.
*
* @par Description
* Send an FLOGI to a well-known fabric.
*
* @param ctx Remote node sm context.
* @param evt Event to process.
* @param arg Per event optional argument.
*
* @return Returns NULL.
*/
void *
__ocs_fabric_init(ocs_sm_ctx_t *ctx, ocs_sm_event_t evt, void *arg)
{
std_node_state_decl();
node_sm_trace();
switch(evt) {
case OCS_EVT_REENTER: // not sure why we're getting these ...
ocs_log_debug(node->ocs, ">>> reenter !!\n");
// fall through
case OCS_EVT_ENTER:
// sm: / send FLOGI
ocs_send_flogi(node, OCS_FC_FLOGI_TIMEOUT_SEC, OCS_FC_ELS_DEFAULT_RETRIES, NULL, NULL);
ocs_node_transition(node, __ocs_fabric_flogi_wait_rsp, NULL);
break;
default:
__ocs_fabric_common(__func__, ctx, evt, arg);
break;
}
return NULL;
}
/**
* @ingroup fabric_sm
* @brief Set sport topology.
*
* @par Description
* Set sport topology.
*
* @param node Pointer to the node for which the topology is set.
* @param topology Topology to set.
*
* @return Returns NULL.
*/
void
ocs_fabric_set_topology(ocs_node_t *node, ocs_sport_topology_e topology)
{
node->sport->topology = topology;
}
/**
* @ingroup fabric_sm
* @brief Notify sport topology.
*
* @par Description
* Set sport topology.
*
* @param node Pointer to the node for which the topology is set.
*
* @return Returns NULL.
*/
void
ocs_fabric_notify_topology(ocs_node_t *node)
{
ocs_node_t *tmp_node;
ocs_node_t *next;
ocs_sport_topology_e topology = node->sport->topology;
/* now loop through the nodes in the sport and send topology notification */
ocs_sport_lock(node->sport);
ocs_list_foreach_safe(&node->sport->node_list, tmp_node, next) {
if (tmp_node != node) {
ocs_node_post_event(tmp_node, OCS_EVT_SPORT_TOPOLOGY_NOTIFY, (void *)topology);
}
}
ocs_sport_unlock(node->sport);
}
/**
* @ingroup fabric_sm
* @brief Fabric node state machine: Wait for an FLOGI response.
*
* @par Description
* Wait for an FLOGI response event.
*
* @param ctx Remote node state machine context.
* @param evt Event to process.
* @param arg Per event optional argument.
*
* @return Returns NULL.
*/
void *
__ocs_fabric_flogi_wait_rsp(ocs_sm_ctx_t *ctx, ocs_sm_event_t evt, void *arg)
{
ocs_node_cb_t *cbdata = arg;
std_node_state_decl();
node_sm_trace();
switch(evt) {
case OCS_EVT_SRRS_ELS_REQ_OK: {
if (node_check_els_req(ctx, evt, arg, FC_ELS_CMD_FLOGI, __ocs_fabric_common, __func__)) {
return NULL;
}
ocs_assert(node->els_req_cnt, NULL);
node->els_req_cnt--;
ocs_domain_save_sparms(node->sport->domain, cbdata->els->els_rsp.virt);
ocs_display_sparams(node->display_name, "flogi rcvd resp", 0, NULL,
((uint8_t*)cbdata->els->els_rsp.virt) + 4);
/* Check to see if the fabric is an F_PORT or and N_PORT */
if (ocs_rnode_is_nport(cbdata->els->els_rsp.virt)) {
// sm: if nport and p2p_winner / ocs_domain_attach
ocs_fabric_set_topology(node, OCS_SPORT_TOPOLOGY_P2P);
if (ocs_p2p_setup(node->sport)) {
node_printf(node, "p2p setup failed, shutting down node\n");
node->shutdown_reason = OCS_NODE_SHUTDOWN_DEFAULT;
ocs_fabric_initiate_shutdown(node);
} else {
if (node->sport->p2p_winner) {
ocs_node_transition(node, __ocs_p2p_wait_domain_attach, NULL);
if (!node->sport->domain->attached) {
node_printf(node, "p2p winner, domain not attached\n");
ocs_domain_attach(node->sport->domain, node->sport->p2p_port_id);
} else {
/* already attached, just send ATTACH_OK */
node_printf(node, "p2p winner, domain already attached\n");
ocs_node_post_event(node, OCS_EVT_DOMAIN_ATTACH_OK, NULL);
}
} else {
/* peer is p2p winner; PLOGI will be received on the
* remote SID=1 node; this node has served its purpose
*/
node->shutdown_reason = OCS_NODE_SHUTDOWN_DEFAULT;
ocs_fabric_initiate_shutdown(node);
}
}
} else {
// sm: if not nport / ocs_domain_attach
/* ext_status has the fc_id, attach domain */
ocs_fabric_set_topology(node, OCS_SPORT_TOPOLOGY_FABRIC);
ocs_fabric_notify_topology(node);
ocs_assert(!node->sport->domain->attached, NULL);
ocs_domain_attach(node->sport->domain, cbdata->ext_status);
ocs_node_transition(node, __ocs_fabric_wait_domain_attach, NULL);
}
break;
}
case OCS_EVT_ELS_REQ_ABORTED:
case OCS_EVT_SRRS_ELS_REQ_RJT:
case OCS_EVT_SRRS_ELS_REQ_FAIL: {
ocs_sport_t *sport = node->sport;
/*
* with these errors, we have no recovery, so shutdown the sport, leave the link
* up and the domain ready
*/
if (node_check_els_req(ctx, evt, arg, FC_ELS_CMD_FLOGI, __ocs_fabric_common, __func__)) {
return NULL;
}
node_printf(node, "FLOGI failed evt=%s, shutting down sport [%s]\n", ocs_sm_event_name(evt),
sport->display_name);
ocs_assert(node->els_req_cnt, NULL);
node->els_req_cnt--;
ocs_sm_post_event(&sport->sm, OCS_EVT_SHUTDOWN, NULL);
break;
}
default:
__ocs_fabric_common(__func__, ctx, evt, arg);
break;
}
return NULL;
}
/**
* @ingroup fabric_sm
* @brief Fabric node state machine: Initial state for a virtual port.
*
* @par Description
* State entered when a virtual port is created. Send FDISC.
*
* @param ctx Remote node state machine context.
* @param evt Event to process.
* @param arg Per event optional argument.
*
* @return Returns NULL.
*/
void *
__ocs_vport_fabric_init(ocs_sm_ctx_t *ctx, ocs_sm_event_t evt, void *arg)
{
std_node_state_decl();
node_sm_trace();
switch(evt) {
case OCS_EVT_ENTER:
//sm: / send FDISC
ocs_send_fdisc(node, OCS_FC_FLOGI_TIMEOUT_SEC, OCS_FC_ELS_DEFAULT_RETRIES, NULL, NULL);
ocs_node_transition(node, __ocs_fabric_fdisc_wait_rsp, NULL);
break;
default:
__ocs_fabric_common(__func__, ctx, evt, arg);
break;
}
return NULL;
}
/**
* @ingroup fabric_sm
* @brief Fabric node state machine: Wait for an FDISC response
*
* @par Description
* Used for a virtual port. Waits for an FDISC response. If OK, issue a HAL port attach.
*
* @param ctx Remote node state machine context.
* @param evt Event to process.
* @param arg Per event optional argument.
*
* @return Returns NULL.
*/
void *
__ocs_fabric_fdisc_wait_rsp(ocs_sm_ctx_t *ctx, ocs_sm_event_t evt, void *arg)
{
ocs_node_cb_t *cbdata = arg;
std_node_state_decl();
node_sm_trace();
switch(evt) {
case OCS_EVT_SRRS_ELS_REQ_OK: {
/* fc_id is in ext_status */
if (node_check_els_req(ctx, evt, arg, FC_ELS_CMD_FDISC, __ocs_fabric_common, __func__)) {
return NULL;
}
ocs_display_sparams(node->display_name, "fdisc rcvd resp", 0, NULL,
((uint8_t*)cbdata->els->els_rsp.virt) + 4);
ocs_assert(node->els_req_cnt, NULL);
node->els_req_cnt--;
//sm: / ocs_sport_attach
ocs_sport_attach(node->sport, cbdata->ext_status);
ocs_node_transition(node, __ocs_fabric_wait_domain_attach, NULL);
break;
}
case OCS_EVT_SRRS_ELS_REQ_RJT:
case OCS_EVT_SRRS_ELS_REQ_FAIL: {
if (node_check_els_req(ctx, evt, arg, FC_ELS_CMD_FDISC, __ocs_fabric_common, __func__)) {
return NULL;
}
ocs_assert(node->els_req_cnt, NULL);
node->els_req_cnt--;
ocs_log_err(ocs, "FDISC failed, shutting down sport\n");
//sm: / shutdown sport
ocs_sm_post_event(&node->sport->sm, OCS_EVT_SHUTDOWN, NULL);
break;
}
default:
__ocs_fabric_common(__func__, ctx, evt, arg);
break;
}
return NULL;
}
/**
* @ingroup fabric_sm
* @brief Fabric node state machine: Wait for a domain/sport attach event.
*
* @par Description
* Waits for a domain/sport attach event.
*
* @param ctx Remote node state machine context.
* @param evt Event to process.
* @param arg Per event optional argument.
*
* @return Returns NULL.
*/
void *
__ocs_fabric_wait_domain_attach(ocs_sm_ctx_t *ctx, ocs_sm_event_t evt, void *arg)
{
std_node_state_decl();
node_sm_trace();
switch(evt) {
case OCS_EVT_ENTER:
ocs_node_hold_frames(node);
break;
case OCS_EVT_EXIT:
ocs_node_accept_frames(node);
break;
case OCS_EVT_DOMAIN_ATTACH_OK:
case OCS_EVT_SPORT_ATTACH_OK: {
int rc;
rc = ocs_start_ns_node(node->sport);
if (rc)
return NULL;
//sm: if enable_ini / start fabctl node
/* Instantiate the fabric controller (sends SCR) */
if (node->sport->enable_rscn) {
rc = ocs_start_fabctl_node(node->sport);
if (rc)
return NULL;
}
ocs_node_transition(node, __ocs_fabric_idle, NULL);
break;
}
default:
__ocs_fabric_common(__func__, ctx, evt, arg);
return NULL;
}
return NULL;
}
/**
* @ingroup fabric_sm
* @brief Fabric node state machine: Fabric node is idle.
*
* @par Description
* Wait for fabric node events.
*
* @param ctx Remote node state machine context.
* @param evt Event to process.
* @param arg Per event optional argument.
*
* @return Returns NULL.
*/
void *
__ocs_fabric_idle(ocs_sm_ctx_t *ctx, ocs_sm_event_t evt, void *arg)
{
std_node_state_decl();
node_sm_trace();
switch(evt) {
case OCS_EVT_DOMAIN_ATTACH_OK:
break;
default:
__ocs_fabric_common(__func__, ctx, evt, arg);
return NULL;
}
return NULL;
}
/**
* @ingroup ns_sm
* @brief Name services node state machine: Initialize.
*
* @par Description
* A PLOGI is sent to the well-known name/directory services node.
*
* @param ctx Remote node state machine context.
* @param evt Event to process.
* @param arg Per event optional argument.
*
* @return Returns NULL.
*/
void *
__ocs_ns_init(ocs_sm_ctx_t *ctx, ocs_sm_event_t evt, void *arg)
{
std_node_state_decl();
node_sm_trace();
switch(evt) {
case OCS_EVT_ENTER:
//sm: / send PLOGI
ocs_send_plogi(node, OCS_FC_ELS_SEND_DEFAULT_TIMEOUT, OCS_FC_ELS_DEFAULT_RETRIES, NULL, NULL);
ocs_node_transition(node, __ocs_ns_plogi_wait_rsp, NULL);
break;
default:
__ocs_fabric_common(__func__, ctx, evt, arg);
break;
}
return NULL;
}
/**
* @ingroup ns_sm
* @brief Name services node state machine: Wait for a PLOGI response.
*
* @par Description
* Waits for a response from PLOGI to name services node, then issues a
* node attach request to the HAL.
*
* @param ctx Remote node state machine context.
* @param evt Event to process.
* @param arg Per event optional argument.
*
* @return Returns NULL.
*/
void *
__ocs_ns_plogi_wait_rsp(ocs_sm_ctx_t *ctx, ocs_sm_event_t evt, void *arg)
{
int32_t rc;
ocs_node_cb_t *cbdata = arg;
std_node_state_decl();
node_sm_trace();
switch(evt) {
case OCS_EVT_SRRS_ELS_REQ_OK: {
/* Save service parameters */
if (node_check_els_req(ctx, evt, arg, FC_ELS_CMD_PLOGI, __ocs_fabric_common, __func__)) {
return NULL;
}
ocs_assert(node->els_req_cnt, NULL);
node->els_req_cnt--;
//sm: / save sparams, ocs_node_attach
ocs_node_save_sparms(node, cbdata->els->els_rsp.virt);
ocs_display_sparams(node->display_name, "plogi rcvd resp", 0, NULL,
((uint8_t*)cbdata->els->els_rsp.virt) + 4);
rc = ocs_node_attach(node);
ocs_node_transition(node, __ocs_ns_wait_node_attach, NULL);
if (rc == OCS_HAL_RTN_SUCCESS_SYNC) {
ocs_node_post_event(node, OCS_EVT_NODE_ATTACH_OK, NULL);
}
break;
}
default:
__ocs_fabric_common(__func__, ctx, evt, arg);
return NULL;
}
return NULL;
}
/**
* @ingroup ns_sm
* @brief Name services node state machine: Wait for a node attach completion.
*
* @par Description
* Waits for a node attach completion, then issues an RFTID name services
* request.
*
* @param ctx Remote node state machine context.
* @param evt Event to process.
* @param arg Per event optional argument.
*
* @return Returns NULL.
*/
void *
__ocs_ns_wait_node_attach(ocs_sm_ctx_t *ctx, ocs_sm_event_t evt, void *arg)
{
std_node_state_decl();
node_sm_trace();
switch(evt) {
case OCS_EVT_ENTER:
ocs_node_hold_frames(node);
break;
case OCS_EVT_EXIT:
ocs_node_accept_frames(node);
break;
case OCS_EVT_NODE_ATTACH_OK:
node->attached = TRUE;
//sm: / send RFTID
ocs_ns_send_rftid(node, OCS_FC_ELS_SEND_DEFAULT_TIMEOUT, OCS_FC_ELS_DEFAULT_RETRIES, NULL, NULL);
ocs_node_transition(node, __ocs_ns_rftid_wait_rsp, NULL);
break;
case OCS_EVT_NODE_ATTACH_FAIL:
/* node attach failed, shutdown the node */
node->attached = FALSE;
node_printf(node, "Node attach failed\n");
node->shutdown_reason = OCS_NODE_SHUTDOWN_DEFAULT;
ocs_fabric_initiate_shutdown(node);
break;
case OCS_EVT_SHUTDOWN:
node_printf(node, "Shutdown event received\n");
node->shutdown_reason = OCS_NODE_SHUTDOWN_DEFAULT;
ocs_node_transition(node, __ocs_fabric_wait_attach_evt_shutdown, NULL);
break;
/* if receive RSCN just ignore, we haven't sent GID_FT yet (ACC sent by fabctl node) */
case OCS_EVT_RSCN_RCVD:
break;
default:
__ocs_fabric_common(__func__, ctx, evt, arg);
return NULL;
}
return NULL;
}
/**
* @ingroup ns_sm
* @brief Wait for a domain/sport/node attach completion, then
* shutdown.
*
* @par Description
* Waits for a domain/sport/node attach completion, then shuts
* node down.
*
* @param ctx Remote node state machine context.
* @param evt Event to process.
* @param arg Per event optional argument.
*
* @return Returns NULL.
*/
void *
__ocs_fabric_wait_attach_evt_shutdown(ocs_sm_ctx_t *ctx, ocs_sm_event_t evt, void *arg)
{
std_node_state_decl();
node_sm_trace();
switch(evt) {
case OCS_EVT_ENTER:
ocs_node_hold_frames(node);
break;
case OCS_EVT_EXIT:
ocs_node_accept_frames(node);
break;
/* wait for any of these attach events and then shutdown */
case OCS_EVT_NODE_ATTACH_OK:
node->attached = TRUE;
node_printf(node, "Attach evt=%s, proceed to shutdown\n", ocs_sm_event_name(evt));
ocs_fabric_initiate_shutdown(node);
break;
case OCS_EVT_NODE_ATTACH_FAIL:
node->attached = FALSE;
node_printf(node, "Attach evt=%s, proceed to shutdown\n", ocs_sm_event_name(evt));
ocs_fabric_initiate_shutdown(node);
break;
/* ignore shutdown event as we're already in shutdown path */
case OCS_EVT_SHUTDOWN:
node_printf(node, "Shutdown event received\n");
break;
default:
__ocs_fabric_common(__func__, ctx, evt, arg);
return NULL;
}
return NULL;
}
/**
* @ingroup ns_sm
* @brief Name services node state machine: Wait for an RFTID response event.
*
* @par Description
* Waits for an RFTID response event; if configured for an initiator operation,
* a GIDFT name services request is issued.
*
* @param ctx Remote node state machine context.
* @param evt Event to process.
* @param arg Per event optional argument.
*
* @return Returns NULL.
*/
void *
__ocs_ns_rftid_wait_rsp(ocs_sm_ctx_t *ctx, ocs_sm_event_t evt, void *arg)
{
std_node_state_decl();
node_sm_trace();
switch(evt) {
case OCS_EVT_SRRS_ELS_REQ_OK:
if (node_check_ns_req(ctx, evt, arg, FC_GS_NAMESERVER_RFT_ID, __ocs_fabric_common, __func__)) {
return NULL;
}
ocs_assert(node->els_req_cnt, NULL);
node->els_req_cnt--;
//sm: / send RFFID
if (ocs->enable_nvme_tgt) {
ocs_ns_send_rffid(node, FC_TYPE_NVME, OCS_FC_ELS_SEND_DEFAULT_TIMEOUT,
OCS_FC_ELS_DEFAULT_RETRIES, NULL, NULL);
ocs_node_transition(node, __ocs_ns_nvme_rffid_wait_rsp, NULL);
} else {
ocs_ns_send_rffid(node, FC_TYPE_FCP, OCS_FC_ELS_SEND_DEFAULT_TIMEOUT,
OCS_FC_ELS_DEFAULT_RETRIES, NULL, NULL);
ocs_node_transition(node, __ocs_ns_rffid_wait_rsp, NULL);
}
break;
/* if receive RSCN just ignore, we haven't sent GID_FT yet (ACC sent by fabctl node) */
case OCS_EVT_RSCN_RCVD:
break;
default:
__ocs_fabric_common(__func__, ctx, evt, arg);
return NULL;
}
return NULL;
}
void *
__ocs_ns_nvme_rffid_wait_rsp(ocs_sm_ctx_t *ctx, ocs_sm_event_t evt, void *arg)
{
std_node_state_decl();
node_sm_trace();
switch(evt) {
case OCS_EVT_SRRS_ELS_REQ_OK: {
if (node_check_ns_req(ctx, evt, arg, FC_GS_NAMESERVER_RFF_ID, __ocs_fabric_common, __func__)) {
return NULL;
}
ocs_assert(node->els_req_cnt, NULL);
node->els_req_cnt--;
/* Check if we need to send RFFID for scsi. */
if (ocs->enable_scsi_tgt) {
ocs_ns_send_rffid(node, FC_TYPE_FCP, OCS_FC_ELS_SEND_DEFAULT_TIMEOUT,
OCS_FC_ELS_DEFAULT_RETRIES, NULL, NULL);
ocs_node_transition(node, __ocs_ns_rffid_wait_rsp, NULL);
} else {
if (node->sport->enable_rscn) {
//sm: if enable_rscn / send GIDFT
ocs_ns_send_gidft(node, OCS_FC_ELS_SEND_DEFAULT_TIMEOUT, OCS_FC_ELS_DEFAULT_RETRIES, NULL, NULL);
ocs_node_transition(node, __ocs_ns_gidft_wait_rsp, NULL);
} else {
/* if 'T' only, we're done, go to idle */
ocs_node_transition(node, __ocs_ns_idle, NULL);
}
}
break;
}
/* if receive RSCN just ignore, we haven't sent GID_FT yet (ACC sent by fabctl node) */
case OCS_EVT_RSCN_RCVD:
break;
default:
__ocs_fabric_common(__func__, ctx, evt, arg);
return NULL;
}
return NULL;
}
/**
* @ingroup ns_sm
* @brief Fabric node state machine: Wait for RFFID response event.
*
* @par Description
* Waits for an RFFID response event; if configured for an initiator operation,
* a GIDFT name services request is issued.
*
* @param ctx Remote node state machine context.
* @param evt Event to process.
* @param arg Per event optional argument.
*
* @return Returns NULL.
*/
void *
__ocs_ns_rffid_wait_rsp(ocs_sm_ctx_t *ctx, ocs_sm_event_t evt, void *arg)
{
std_node_state_decl();
node_sm_trace();
switch(evt) {
case OCS_EVT_SRRS_ELS_REQ_OK: {
if (node_check_ns_req(ctx, evt, arg, FC_GS_NAMESERVER_RFF_ID, __ocs_fabric_common, __func__)) {
return NULL;
}
ocs_assert(node->els_req_cnt, NULL);
node->els_req_cnt--;
if (node->sport->enable_rscn) {
//sm: if enable_rscn / send GIDFT
ocs_ns_send_gidft(node, OCS_FC_ELS_SEND_DEFAULT_TIMEOUT, OCS_FC_ELS_DEFAULT_RETRIES, NULL, NULL);
ocs_node_transition(node, __ocs_ns_gidft_wait_rsp, NULL);
} else {
/* if 'T' only, we're done, go to idle */
ocs_node_transition(node, __ocs_ns_idle, NULL);
}
break;
}
/* if receive RSCN just ignore, we haven't sent GID_FT yet (ACC sent by fabctl node) */
case OCS_EVT_RSCN_RCVD:
break;
default:
__ocs_fabric_common(__func__, ctx, evt, arg);
return NULL;
}
return NULL;
}
/**
* @ingroup ns_sm
* @brief Name services node state machine: Wait for a GIDFT response.
*
* @par Description
* Wait for a GIDFT response from the name server. Process the FC_IDs that are
* reported by creating new remote ports, as needed.
*
* @param ctx Remote node state machine context.
* @param evt Event to process.
* @param arg Per event optional argument.
*
* @return Returns NULL.
*/
void *
__ocs_ns_gidft_wait_rsp(ocs_sm_ctx_t *ctx, ocs_sm_event_t evt, void *arg)
{
ocs_node_cb_t *cbdata = arg;
std_node_state_decl();
node_sm_trace();
switch(evt) {
case OCS_EVT_SRRS_ELS_REQ_OK: {
if (node_check_ns_req(ctx, evt, arg, FC_GS_NAMESERVER_GID_FT, __ocs_fabric_common, __func__)) {
return NULL;
}
ocs_assert(node->els_req_cnt, NULL);
node->els_req_cnt--;
//sm: / process GIDFT payload
ocs_process_gidft_payload(node, cbdata->els->els_rsp.virt, cbdata->els->els_rsp.len);
//TODO: should we logout at this point or just go idle
ocs_node_transition(node, __ocs_ns_idle, NULL);
break;
}
case OCS_EVT_SRRS_ELS_REQ_FAIL: {
/* not much we can do; will retry with the next RSCN */
node_printf(node, "GID_FT failed to complete\n");
ocs_assert(node->els_req_cnt, NULL);
node->els_req_cnt--;
ocs_node_transition(node, __ocs_ns_idle, NULL);
break;
}
/* if receive RSCN here, queue up another discovery processing */
case OCS_EVT_RSCN_RCVD: {
node_printf(node, "RSCN received during GID_FT processing\n");
node->rscn_pending = 1;
break;
}
default:
__ocs_fabric_common(__func__, ctx, evt, arg);
return NULL;
}
return NULL;
}
void *
__ocs_ns_ganxt_wait_rsp(ocs_sm_ctx_t *ctx, ocs_sm_event_t evt, void *arg)
{
std_node_state_decl();
node_sm_trace();
switch(evt) {
case OCS_EVT_SRRS_ELS_REQ_OK: {
if (node_check_ns_req(ctx, evt, arg, FC_GS_NAMESERVER_GA_NXT, __ocs_fabric_common, __func__)) {
return NULL;
}
ocs_assert(node->els_req_cnt, NULL);
node->els_req_cnt--;
ocs_node_transition(node, __ocs_ns_idle, NULL);
break;
}
case OCS_EVT_SRRS_ELS_REQ_FAIL: {
ocs_assert(node->els_req_cnt, NULL);
node->els_req_cnt--;
ocs_node_transition(node, __ocs_ns_idle, NULL);
break;
}
case OCS_EVT_RSCN_RCVD: {
node->rscn_pending = 1;
break;
}
default:
__ocs_fabric_common(__func__, ctx, evt, arg);
return NULL;
}
return NULL;
}
/**
* @ingroup ns_sm
* @brief Name services node state machine: Idle state.
*
* @par Description
* Idle. Waiting for RSCN received events (posted from the fabric controller), and
* restarts the GIDFT name services query and processing.
*
* @param ctx Remote node state machine context.
* @param evt Event to process.
* @param arg Per event optional argument.
*
* @return Returns NULL.
*/
void *
__ocs_ns_idle(ocs_sm_ctx_t *ctx, ocs_sm_event_t evt, void *arg)
{
std_node_state_decl();
node_sm_trace();
switch(evt) {
case OCS_EVT_ENTER:
if (!node->rscn_pending) {
break;
}
node_printf(node, "RSCN pending, restart discovery\n");
node->rscn_pending = 0;
/* fall through */
case OCS_EVT_RSCN_RCVD: {
//sm: / send GIDFT
/* If target RSCN processing is enabled, and this is target only (not initiator),
* and tgt_rscn_delay is non-zero, then we delay issuing the GID_FT
*/
if ((ocs->tgt_rscn_delay_msec != 0) && !node->sport->enable_ini && node->sport->enable_tgt &&
enable_target_rscn(ocs)) {
ocs_node_transition(node, __ocs_ns_gidft_delay, NULL);
} else {
ocs_ns_send_gidft(node, OCS_FC_ELS_SEND_DEFAULT_TIMEOUT, OCS_FC_ELS_DEFAULT_RETRIES, NULL, NULL);
ocs_node_transition(node, __ocs_ns_gidft_wait_rsp, NULL);
}
break;
}
default:
__ocs_fabric_common(__func__, ctx, evt, arg);
break;
}
return NULL;
}
/**
* @brief Handle GIDFT delay timer callback
*
* @par Description
* Post an OCS_EVT_GIDFT_DEIALY_EXPIRED event to the passed in node.
*
* @param arg Pointer to node.
*
* @return None.
*/
static void
gidft_delay_timer_cb(void *arg)
{
ocs_node_t *node = arg;
int32_t rc;
ocs_del_timer(&node->gidft_delay_timer);
rc = ocs_xport_control(node->ocs->xport, OCS_XPORT_POST_NODE_EVENT, node, OCS_EVT_GIDFT_DELAY_EXPIRED, NULL);
if (rc) {
ocs_log_err(node->ocs, "%s: ocs_xport_control(OCS_XPORT_POST_NODE_EVENT) failed: %d\n", __func__, rc);
}
}
/**
* @ingroup ns_sm
* @brief Name services node state machine: Delayed GIDFT.
*
* @par Description
* Waiting for GIDFT delay to expire before submitting GIDFT to name server.
*
* @param ctx Remote node state machine context.
* @param evt Event to process.
* @param arg Per event optional argument.
*
* @return Returns NULL.
*/
void *
__ocs_ns_gidft_delay(ocs_sm_ctx_t *ctx, ocs_sm_event_t evt, void *arg)
{
std_node_state_decl();
node_sm_trace();
switch(evt) {
case OCS_EVT_ENTER: {
time_t delay_msec;
ocs_assert(ocs->tgt_rscn_delay_msec != 0, NULL);
/*
* Compute the delay time. Set to tgt_rscn_delay, if the time since last GIDFT
* is less than tgt_rscn_period, then use tgt_rscn_period.
*/
delay_msec = ocs->tgt_rscn_delay_msec;
if ((ocs_msectime() - node->time_last_gidft_msec) < ocs->tgt_rscn_period_msec) {
delay_msec = ocs->tgt_rscn_period_msec;
}