forked from ecdufcdrvr/bcmufctdrvr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathocs_device.c
1959 lines (1705 loc) · 55.1 KB
/
ocs_device.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
* Implement remote device state machine for target and initiator.
*/
/*!
@defgroup device_sm Node State Machine: Remote Device States
*/
#include "ocs.h"
#include "ocs_device.h"
#include "ocs_fabric.h"
#include "ocs_els.h"
#include "scsi_cmds.h"
#include "ocs_spdk_nvmet.h"
static void *__ocs_d_common(const char *funcname, ocs_sm_ctx_t *ctx, ocs_sm_event_t evt, void *arg);
static void *__ocs_d_wait_del_node(ocs_sm_ctx_t *ctx, ocs_sm_event_t evt, void *arg);
static void *__ocs_d_wait_del_ini_tgt(ocs_sm_ctx_t *ctx, ocs_sm_event_t evt, void *arg);
static int32_t ocs_process_abts(ocs_io_t *io, fc_header_t *hdr);
static int32_t ocs_scsi_io_cb(ocs_io_t *io, ocs_scsi_io_status_e scsi_status, uint32_t flags, void *arg);
/**
* @brief SCSI IO callback.
*
* @par Description
* This function simply calls ocs_scsi_io_complete to free the io.
*
* @param io Pointer to the IO structure.
* @param scsi_status Completion status.
* @param flags Flags.
* @param arg Application-specified argument.
*
* @return Returns 0
*/
static int32_t
ocs_scsi_io_cb(ocs_io_t *io, ocs_scsi_io_status_e scsi_status, uint32_t flags, void *arg)
{
ocs_scsi_io_complete(io);
return 0;
}
/**
* @ingroup device_sm
* @brief Send response to PRLI.
*
* <h3 class="desc">Description</h3>
* For device nodes, this function sends a PRLI response.
*
* @param io Pointer to a SCSI IO object.
* @param ox_id OX_ID of PRLI
*
* @return Returns None.
*/
void
ocs_d_send_prli_rsp(ocs_io_t *io, uint16_t ox_id, uint8_t fc_type)
{
ocs_node_t *node = io->node;
if (fc_type == FC_TYPE_NVME) {
if (!node->ocs->enable_nvme_tgt || ocs_nvme_process_prli(io, ox_id)) {
node_printf(node, "NVME: PRLI rejected by target-server\n");
ocs_send_ls_rjt(io, ox_id, FC_REASON_UNABLE_TO_PERFORM,
FC_EXPL_NO_ADDITIONAL, 0, NULL, NULL);
}
} else {
if (node->sport->enable_tgt && (ocs_scsi_validate_initiator(node) == 0)) {
node_printf(node, "PRLI rejected by target-server\n");
ocs_send_ls_rjt(io, ox_id, FC_REASON_UNABLE_TO_PERFORM,
FC_EXPL_NO_ADDITIONAL, 0, NULL, NULL);
// Cleanup node to free RPI ?
} else {
ocs_send_prli_acc(io, ox_id, FC_TYPE_FCP, NULL, NULL);
/* Immediately go to ready state to avoid window where we're
* waiting for the PRLI LS_ACC to complete while holding FCP_CMNDs
*/
ocs_node_transition(node, __ocs_d_device_ready, NULL);
}
}
return;
}
/**
* @ingroup device_sm
* @brief Device node state machine: Initiate node shutdown
*
* @param ctx Remote node state machine context.
* @param evt Event to process.
* @param arg Per event optional argument.
*
* @return Returns NULL.
*/
void *
__ocs_d_initiate_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: {
int32_t rc = OCS_SCSI_CALL_COMPLETE; // assume no wait needed
ocs_scsi_io_alloc_disable(node);
if ((node->init || node->nvme_init) && !node->targ) {
ocs_log_info(node->ocs, "[%s] delete (initiator) WWPN %s WWNN %s\n", node->display_name,
node->wwpn, node->wwnn);
ocs_node_transition(node, __ocs_d_wait_del_node, NULL);
if (node->sport->enable_tgt) {
rc = ocs_scsi_del_initiator(node, OCS_SCSI_INITIATOR_DELETED);
}
if (rc == OCS_SCSI_CALL_COMPLETE) {
ocs_node_post_event(node, OCS_EVT_NODE_DEL_INI_COMPLETE, NULL);
}
} else if (node->targ && !node->init) {
ocs_log_info(node->ocs, "[%s] delete (target) WWPN %s WWNN %s\n", node->display_name,
node->wwpn, node->wwnn);
ocs_node_transition(node, __ocs_d_wait_del_node, NULL);
if (node->sport->enable_ini) {
rc = ocs_scsi_del_target(node, OCS_SCSI_TARGET_DELETED);
}
if (rc == OCS_SCSI_CALL_COMPLETE) {
ocs_node_post_event(node, OCS_EVT_NODE_DEL_TGT_COMPLETE, NULL);
}
} else if (node->init && node->targ) {
ocs_log_info(node->ocs, "[%s] delete (initiator+target) WWPN %s WWNN %s\n",
node->display_name, node->wwpn, node->wwnn);
ocs_node_transition(node, __ocs_d_wait_del_ini_tgt, NULL);
if (node->sport->enable_tgt) {
rc = ocs_scsi_del_initiator(node, OCS_SCSI_INITIATOR_DELETED);
}
if (rc == OCS_SCSI_CALL_COMPLETE) {
ocs_node_post_event(node, OCS_EVT_NODE_DEL_INI_COMPLETE, NULL);
}
rc = OCS_SCSI_CALL_COMPLETE; // assume no wait needed
if (node->sport->enable_ini) {
rc = ocs_scsi_del_target(node, OCS_SCSI_TARGET_DELETED);
}
if (rc == OCS_SCSI_CALL_COMPLETE) {
ocs_node_post_event(node, OCS_EVT_NODE_DEL_TGT_COMPLETE, NULL);
}
}
/* we've initiated the upcalls as needed, now kick off the node
* detach to precipitate the aborting of outstanding exchanges
* associated with said node
*
* Beware: if we've made upcall(s), we've already transitioned
* to a new state by the time we execute this.
* TODO: consider doing this before the upcalls...
*/
if (node->attached) {
/* issue hal node free; don't care if succeeds right away
* or sometime later, will check node->attached later in
* shutdown process
*/
rc = ocs_hal_node_detach(&ocs->hal, &node->rnode);
if (node->rnode.free_group) {
ocs_remote_node_group_free(node->node_group);
node->node_group = NULL;
node->rnode.free_group = FALSE;
}
if (rc != OCS_HAL_RTN_SUCCESS && rc != OCS_HAL_RTN_SUCCESS_SYNC) {
node_printf(node, "Failed freeing HAL node, rc=%d\n", rc);
}
}
/* if neither initiator nor target, proceed to cleanup */
if (!node->init && !node->targ && !node->nvme_init){
/*
* node has either been detached or is in the process of being detached,
* call common node's initiate cleanup function
*/
ocs_node_initiate_cleanup(node);
}
break;
}
case OCS_EVT_ALL_CHILD_NODES_FREE:
/* Ignore, this can happen if an ELS is aborted while in a delay/retry state */
break;
default:
__ocs_d_common(__func__, ctx, evt, arg);
return NULL;
}
return NULL;
}
/**
* @ingroup device_sm
* @brief Device node state machine: Common device event handler.
*
* <h3 class="desc">Description</h3>
* For device nodes, this event handler manages default and common events.
*
* @param funcname Function name text.
* @param ctx Remote node state machine context.
* @param evt Event to process.
* @param arg Per event optional argument.
*
* @return Returns NULL.
*/
static void *
__ocs_d_common(const char *funcname, ocs_sm_ctx_t *ctx, ocs_sm_event_t evt, void *arg)
{
ocs_node_t *node = NULL;
ocs_t *ocs = NULL;
ocs_assert(ctx, NULL);
node = ctx->app;
ocs_assert(node, NULL);
ocs = node->ocs;
ocs_assert(ocs, NULL);
switch(evt) {
/* Handle shutdown events */
case OCS_EVT_SHUTDOWN:
ocs_log_debug(ocs, "[%s] %-20s %-20s\n", node->display_name, funcname, ocs_sm_event_name(evt));
node->shutdown_reason = OCS_NODE_SHUTDOWN_DEFAULT;
ocs_node_transition(node, __ocs_d_initiate_shutdown, NULL);
break;
case OCS_EVT_SHUTDOWN_EXPLICIT_LOGO:
ocs_log_debug(ocs, "[%s] %-20s %-20s\n", node->display_name, funcname, ocs_sm_event_name(evt));
node->shutdown_reason = OCS_NODE_SHUTDOWN_EXPLICIT_LOGO;
ocs_node_transition(node, __ocs_d_initiate_shutdown, NULL);
break;
case OCS_EVT_SHUTDOWN_IMPLICIT_LOGO:
ocs_log_debug(ocs, "[%s] %-20s %-20s\n", node->display_name, funcname, ocs_sm_event_name(evt));
node->shutdown_reason = OCS_NODE_SHUTDOWN_IMPLICIT_LOGO;
ocs_node_transition(node, __ocs_d_initiate_shutdown, NULL);
break;
default:
/* call default event handler common to all nodes */
__ocs_node_common(funcname, ctx, evt, arg);
break;
}
return NULL;
}
/**
* @ingroup device_sm
* @brief Device node state machine: Wait for a domain-attach completion in loop topology.
*
* <h3 class="desc">Description</h3>
* State waits for a domain-attached completion while in loop topology.
*
* @param ctx Remote node state machine context.
* @param evt Event to process.
* @param arg Per event optional argument.
*
* @return Returns NULL.
*/
void *
__ocs_d_wait_loop(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: {
/* send PLOGI automatically if initiator */
ocs_node_init_device(node, TRUE);
break;
}
default:
__ocs_d_common(__func__, ctx, evt, arg);
return NULL;
}
return NULL;
}
/**
* @ingroup device_sm
* @brief state: wait for node resume event
*
* State is entered when a node is in I+T mode and sends a delete initiator/target
* call to the target-server/initiator-client and needs to wait for that work 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_d_wait_del_ini_tgt(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);
/* Fall through */
case OCS_EVT_NODE_ACTIVE_IO_LIST_EMPTY:
case OCS_EVT_ALL_CHILD_NODES_FREE:
/* These are expected events. */
break;
case OCS_EVT_NODE_DEL_INI_COMPLETE:
case OCS_EVT_NODE_DEL_TGT_COMPLETE:
ocs_node_transition(node, __ocs_d_wait_del_node, NULL);
break;
case OCS_EVT_EXIT:
ocs_node_accept_frames(node);
break;
case OCS_EVT_SRRS_ELS_REQ_FAIL:
/* Can happen as ELS IO IO's complete */
ocs_assert(node->els_req_cnt, NULL);
node->els_req_cnt--;
break;
/* ignore shutdown events as we're already in shutdown path */
case OCS_EVT_SHUTDOWN:
/* have default shutdown event take precedence */
node->shutdown_reason = OCS_NODE_SHUTDOWN_DEFAULT;
/* fall through */
case OCS_EVT_SHUTDOWN_EXPLICIT_LOGO:
case OCS_EVT_SHUTDOWN_IMPLICIT_LOGO:
node_printf(node, "%s received\n", ocs_sm_event_name(evt));
break;
case OCS_EVT_DOMAIN_ATTACH_OK:
/* don't care about domain_attach_ok */
break;
default:
__ocs_d_common(__func__, ctx, evt, arg);
return NULL;
}
return NULL;
}
/**
* @ingroup device_sm
* @brief state: Wait for node resume event.
*
* State is entered when a node sends a delete initiator/target call to the
* target-server/initiator-client and needs to wait for that work 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_d_wait_del_node(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);
/* Fall through */
case OCS_EVT_NODE_ACTIVE_IO_LIST_EMPTY:
case OCS_EVT_ALL_CHILD_NODES_FREE:
/* These are expected events. */
break;
case OCS_EVT_NODE_DEL_INI_COMPLETE:
case OCS_EVT_NODE_DEL_TGT_COMPLETE:
/*
* node has either been detached or is in the process of being detached,
* call common node's initiate cleanup function
*/
ocs_node_initiate_cleanup(node);
break;
case OCS_EVT_EXIT:
ocs_node_accept_frames(node);
break;
case OCS_EVT_SRRS_ELS_REQ_FAIL:
/* Can happen as ELS IO IO's complete */
ocs_assert(node->els_req_cnt, NULL);
node->els_req_cnt--;
break;
/* ignore shutdown events as we're already in shutdown path */
case OCS_EVT_SHUTDOWN:
/* have default shutdown event take precedence */
node->shutdown_reason = OCS_NODE_SHUTDOWN_DEFAULT;
/* fall through */
case OCS_EVT_SHUTDOWN_EXPLICIT_LOGO:
case OCS_EVT_SHUTDOWN_IMPLICIT_LOGO:
node_printf(node, "%s received\n", ocs_sm_event_name(evt));
break;
case OCS_EVT_DOMAIN_ATTACH_OK:
/* don't care about domain_attach_ok */
break;
default:
__ocs_d_common(__func__, ctx, evt, arg);
return NULL;
}
return NULL;
}
/**
* @brief Save the OX_ID for sending LS_ACC sometime later.
*
* <h3 class="desc">Description</h3>
* When deferring the response to an ELS request, the OX_ID of the request
* is saved using this function.
*
* @param io Pointer to a SCSI IO object.
* @param hdr Pointer to the FC header.
* @param ls Defines the type of ELS to send: LS_ACC, LS_ACC for PLOGI;
* or LSS_ACC for PRLI.
*
* @return None.
*/
void
ocs_send_ls_acc_after_attach(ocs_io_t *io, fc_header_t *hdr, ocs_node_send_ls_acc_e ls)
{
ocs_node_t *node = io->node;
uint16_t ox_id = ocs_be16toh(hdr->ox_id);
ocs_assert(node->send_ls_acc == OCS_NODE_SEND_LS_ACC_NONE);
node->ls_acc_oxid = ox_id;
node->send_ls_acc = ls;
node->ls_acc_io = io;
node->ls_acc_did = fc_be24toh(hdr->d_id);
}
/**
* @brief Process the PRLI payload.
*
* <h3 class="desc">Description</h3>
* The PRLI payload is processed; the initiator/target capabilities of the
* remote node are extracted and saved in the node object.
*
* @param node Pointer to the node object.
* @param prli Pointer to the PRLI payload.
*
* @return None.
*/
void
ocs_process_prli_payload(ocs_node_t *node, fc_prli_payload_t *prli)
{
if (prli->type == FC_TYPE_NVME) {
node->nvme_tgt = (ocs_be16toh(prli->service_params) & FC_PRLI_TARGET_FUNCTION) != 0;
node->nvme_init = (ocs_be16toh(prli->service_params) & FC_PRLI_INITIATOR_FUNCTION) != 0;
node->nvme_prli_service_params = prli->service_params; /* BE format */
} else {
node->init = (ocs_be16toh(prli->service_params) & FC_PRLI_INITIATOR_FUNCTION) != 0;
node->targ = (ocs_be16toh(prli->service_params) & FC_PRLI_TARGET_FUNCTION) != 0;
}
}
/**
* @brief Process the ABTS.
*
* <h3 class="desc">Description</h3>
* Common code to process a received ABTS. If an active IO can be found
* that matches the OX_ID of the ABTS request, a call is made to the
* backend. Otherwise, a BA_ACC is returned to the initiator.
*
* @param io Pointer to a SCSI IO object.
* @param hdr Pointer to the FC header.
*
* @return Returns 0 on success, or a negative error value on failure.
*/
static int32_t
ocs_process_abts(ocs_io_t *io, fc_header_t *hdr)
{
ocs_node_t *node = io->node;
ocs_t *ocs = node->ocs;
uint16_t ox_id = ocs_be16toh(hdr->ox_id);
uint16_t rx_id = ocs_be16toh(hdr->rx_id);
ocs_io_t *abortio;
abortio = ocs_io_find_tgt_io(ocs, node, ox_id, rx_id);
/* If an IO was found, attempt to take a reference on it */
if (abortio != NULL && (ocs_ref_get_unless_zero(&abortio->ref) != 0)) {
/* Got a reference on the IO. Hold it until backend is notified below */
node_printf(node, "Abort request: ox_id [%04x] rx_id [%04x]\n",
ox_id, rx_id);
/*
* Save the ox_id for the ABTS as the init_task_tag in our manufactured
* TMF IO object
*/
io->display_name = "abts";
io->init_task_tag = ox_id;
// don't set tgt_task_tag, don't want to confuse with XRI
/*
* Save the rx_id from the ABTS as it is needed for the BLS response,
* regardless of the IO context's rx_id
*/
io->abort_rx_id = rx_id;
/* Call target server command abort */
io->tmf_cmd = OCS_SCSI_TMF_ABORT_TASK;
ocs_scsi_recv_tmf(io, 0, OCS_SCSI_TMF_ABORT_TASK, abortio, 0);
/*
* Backend will have taken an additional reference on the IO if needed;
* done with current reference.
*/
ocs_ref_put(&abortio->ref); /* ocs_ref_get(): same function */
} else {
/*
* Either IO was not found or it has been freed between finding it
* and attempting to get the reference,
*/
node_printf(node, "Abort request: ox_id [%04x], IO not found (exists=%d)\n",
ox_id, (abortio != NULL));
#if defined(OCS_NVME_FC)
ocs_nvme_process_abts(ocs, ox_id, rx_id, node->rnode.indicator);
ocs_scsi_io_free(io);
#else
/* Send a BA_ACC */
ocs_bls_send_acc_hdr(io, hdr);
#endif
}
return 0;
}
/**
* @ingroup device_sm
* @brief Device node state machine: Wait for the PLOGI accept 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_d_wait_plogi_acc_cmpl(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_SRRS_ELS_CMPL_FAIL:
ocs_assert(node->els_cmpl_cnt, NULL);
node->els_cmpl_cnt--;
node->shutdown_reason = OCS_NODE_SHUTDOWN_DEFAULT;
ocs_node_transition(node, __ocs_d_initiate_shutdown, NULL);
break;
case OCS_EVT_SRRS_ELS_CMPL_OK: /* PLOGI ACC completions */
ocs_assert(node->els_cmpl_cnt, NULL);
node->els_cmpl_cnt--;
ocs_node_transition(node, __ocs_d_port_logged_in, NULL);
break;
default:
__ocs_d_common(__func__, ctx, evt, arg);
return NULL;
}
return NULL;
}
/**
* @ingroup device_sm
* @brief Device node state machine: Wait for the LOGO response.
*
* @param ctx Remote node state machine context.
* @param evt Event to process.
* @param arg Per event optional argument.
*
* @return Returns NULL.
*/
void *
__ocs_d_wait_logo_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_ENTER:
// TODO: may want to remove this; if we'll want to know about PLOGI
ocs_node_hold_frames(node);
break;
case OCS_EVT_EXIT:
ocs_node_accept_frames(node);
break;
case OCS_EVT_SRRS_ELS_REQ_OK:
case OCS_EVT_SRRS_ELS_REQ_RJT:
case OCS_EVT_SRRS_ELS_REQ_FAIL:
/* LOGO response received, sent shutdown */
if (node_check_els_req(ctx, evt, arg, FC_ELS_CMD_LOGO, __ocs_d_common, __func__)) {
return NULL;
}
ocs_assert(node->els_req_cnt, NULL);
node->els_req_cnt--;
node_printf(node, "LOGO sent (evt=%s), shutdown node\n", ocs_sm_event_name(evt));
//sm: / post explicit logout
ocs_node_post_event(node, OCS_EVT_SHUTDOWN_EXPLICIT_LOGO, NULL);
break;
// TODO: PLOGI: abort LOGO and process PLOGI? (SHUTDOWN_EXPLICIT/IMPLICIT_LOGO?)
default:
__ocs_d_common(__func__, ctx, evt, arg);
return NULL;
}
return NULL;
}
/**
* @brief Initialize device node.
*
* Initialize device node. If a node is an initiator, then send a PLOGI and transition
* to __ocs_d_wait_plogi_rsp, otherwise transition to __ocs_d_init.
*
* @param node Pointer to the node object.
* @param send_plogi Boolean indicating to send PLOGI command or not.
*
* @return none
*/
void
ocs_node_init_device(ocs_node_t *node, int send_plogi)
{
node->send_plogi = send_plogi;
if ((node->ocs->nodedb_mask & OCS_NODEDB_PAUSE_NEW_NODES) && !FC_ADDR_IS_DOMAIN_CTRL(node->rnode.fc_id)) {
node->nodedb_state = __ocs_d_init;
ocs_node_transition(node, __ocs_node_paused, NULL);
} else {
ocs_node_transition(node, __ocs_d_init, NULL);
}
}
/**
* @ingroup device_sm
* @brief Device node state machine: Initial node state for an initiator or a target.
*
* <h3 class="desc">Description</h3>
* This state is entered when a node is instantiated, either having been
* discovered from a name services query, or having received a PLOGI/FLOGI.
*
* @param ctx Remote node state machine context.
* @param evt Event to process.
* @param arg Per event optional argument.
* - OCS_EVT_ENTER: (uint8_t *) - 1 to send a PLOGI on
* entry (initiator-only); 0 indicates a PLOGI is
* not sent on entry (initiator-only). Not applicable for a target.
*
* @return Returns NULL.
*/
void *
__ocs_d_init(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_ENTER:
/* check if we need to send PLOGI */
if (node->send_plogi) {
/* only send if we have initiator capability, and domain is attached */
if (node->sport->enable_ini && node->sport->domain->attached) {
ocs_send_plogi(node, OCS_FC_ELS_SEND_DEFAULT_TIMEOUT,
OCS_FC_ELS_DEFAULT_RETRIES, NULL, NULL);
ocs_node_transition(node, __ocs_d_wait_plogi_rsp, NULL);
} else {
node_printf(node, "not sending plogi sport.ini=%d, domain attached=%d\n",
node->sport->enable_ini, node->sport->domain->attached);
}
}
break;
case OCS_EVT_PLOGI_RCVD: {
/* T, or I+T */
fc_header_t *hdr = cbdata->header->dma.virt;
uint32_t d_id = fc_be24toh(hdr->d_id);
ocs_node_save_sparms(node, cbdata->payload->dma.virt);
ocs_send_ls_acc_after_attach(cbdata->io, cbdata->header->dma.virt, OCS_NODE_SEND_LS_ACC_PLOGI);
/* domain already attached */
if (node->sport->domain->attached) {
rc = ocs_node_attach(node);
ocs_node_transition(node, __ocs_d_wait_node_attach, NULL);
if (rc == OCS_HAL_RTN_SUCCESS_SYNC) {
ocs_node_post_event(node, OCS_EVT_NODE_ATTACH_OK, NULL);
}
break;
}
/* domain not attached; several possibilities: */
switch (node->sport->topology) {
case OCS_SPORT_TOPOLOGY_P2P:
/* we're not attached and sport is p2p, need to attach */
ocs_domain_attach(node->sport->domain, d_id);
ocs_node_transition(node, __ocs_d_wait_domain_attach, NULL);
break;
case OCS_SPORT_TOPOLOGY_FABRIC:
/* we're not attached and sport is fabric, domain attach should have
* already been requested as part of the fabric state machine, wait for it
*/
ocs_node_transition(node, __ocs_d_wait_domain_attach, NULL);
break;
case OCS_SPORT_TOPOLOGY_UNKNOWN:
/* Two possibilities:
* 1. received a PLOGI before our FLOGI has completed (possible since
* completion comes in on another CQ), thus we don't know what we're
* connected to yet; transition to a state to wait for the fabric
* node to tell us;
* 2. PLOGI received before link went down and we haven't performed
* domain attach yet.
* Note: we cannot distinguish between 1. and 2. so have to assume PLOGI
* was received after link back up.
*/
node_printf(node, "received PLOGI, with unknown topology did=0x%x\n", d_id);
ocs_node_transition(node, __ocs_d_wait_topology_notify, NULL);
break;
default:
node_printf(node, "received PLOGI, with unexpectd topology %d\n",
node->sport->topology);
ocs_assert(FALSE, NULL);
break;
}
break;
}
case OCS_EVT_FDISC_RCVD: {
#if defined(ENABLE_FABRIC_EMULATION)
fc_header_t *hdr = cbdata->header->dma.virt;
/* If this domain is do configured then call the Fabric Emulation FDISC handler */
if (node->sport->domain->femul_enable) {
ocs_femul_process_fdisc(cbdata->io, hdr, cbdata->payload->dma.virt, cbdata->payload->dma.len);
break;
}
#endif
__ocs_d_common(__func__, ctx, evt, arg);
break;
}
case OCS_EVT_FLOGI_RCVD: {
fc_header_t *hdr = cbdata->header->dma.virt;
/* this better be coming from an NPort */
ocs_assert(ocs_rnode_is_nport(cbdata->payload->dma.virt), NULL);
//sm: / save sparams, send FLOGI acc
ocs_domain_save_sparms(node->sport->domain, cbdata->payload->dma.virt);
#if defined(ENABLE_FABRIC_EMULATION)
if (node->sport->domain->femul_enable) {
/* Process FLOGI in Fabric Emulation mode, don't transition */
ocs_femul_process_flogi(cbdata->io, hdr, cbdata->payload->dma.virt, cbdata->payload->dma.len);
break;
}
#endif
/* send FC LS_ACC response, override s_id */
ocs_fabric_set_topology(node, OCS_SPORT_TOPOLOGY_P2P);
ocs_send_flogi_p2p_acc(cbdata->io, ocs_be16toh(hdr->ox_id), fc_be24toh(hdr->d_id), NULL, NULL);
if (ocs_p2p_setup(node->sport)) {
node_printf(node, "p2p setup failed, shutting down node\n");
ocs_node_post_event(node, OCS_EVT_SHUTDOWN, NULL);
} else {
ocs_node_transition(node, __ocs_p2p_wait_flogi_acc_cmpl, NULL);
}
break;
}
case OCS_EVT_LOGO_RCVD: {
fc_header_t *hdr = cbdata->header->dma.virt;
if (!node->sport->domain->attached) {
/* most likely a frame left over from before a link down; drop and
* shut node down w/ "explicit logout" so pending frames are processed */
node_printf(node, "%s domain not attached, dropping\n", ocs_sm_event_name(evt));
ocs_node_post_event(node, OCS_EVT_SHUTDOWN_EXPLICIT_LOGO, NULL);
break;
}
ocs_send_logo_acc(cbdata->io, ocs_be16toh(hdr->ox_id), NULL, NULL);
ocs_node_transition(node, __ocs_d_wait_logo_acc_cmpl, NULL);
break;
}
case OCS_EVT_PRLI_RCVD:
case OCS_EVT_PRLO_RCVD:
case OCS_EVT_PDISC_RCVD:
case OCS_EVT_ADISC_RCVD:
case OCS_EVT_RSCN_RCVD: {
fc_header_t *hdr = cbdata->header->dma.virt;
if (!node->sport->domain->attached) {
/* most likely a frame left over from before a link down; drop and
* shut node down w/ "explicit logout" so pending frames are processed */
node_printf(node, "%s domain not attached, dropping\n", ocs_sm_event_name(evt));
ocs_node_post_event(node, OCS_EVT_SHUTDOWN_EXPLICIT_LOGO, NULL);
break;
}
node_printf(node, "%s received, sending reject\n", ocs_sm_event_name(evt));
ocs_send_ls_rjt(cbdata->io, ocs_be16toh(hdr->ox_id),
FC_REASON_UNABLE_TO_PERFORM, FC_EXPL_NPORT_LOGIN_REQUIRED, 0,
NULL, NULL);
break;
}
case OCS_EVT_FCP_CMD_RCVD: {
//note: problem, we're now expecting an ELS REQ completion from both the LOGO and PLOGI
if (!node->sport->domain->attached) {
/* most likely a frame left over from before a link down; drop and
* shut node down w/ "explicit logout" so pending frames are processed */
node_printf(node, "%s domain not attached, dropping\n", ocs_sm_event_name(evt));
ocs_node_post_event(node, OCS_EVT_SHUTDOWN_EXPLICIT_LOGO, NULL);
break;
}
/* Send LOGO */
node_printf(node, "FCP_CMND received, send LOGO\n");
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);
}
break;
}
case OCS_EVT_DOMAIN_ATTACH_OK:
/* don't care about domain_attach_ok */
break;
#if defined(ENABLE_FABRIC_EMULATION)
case OCS_EVT_SCR_RCVD:
if (node->sport->domain->femul_enable) {
fc_header_t *hdr = cbdata->header->dma.virt;
void *payload = cbdata->payload->dma.virt;
uint32_t payload_len = cbdata->payload->dma.len;
rc = ocs_femul_process_scr(cbdata->io, hdr, payload, payload_len);
if (rc == 0) {
break;
}
}
/* fall through */
#endif
default:
__ocs_d_common(__func__, ctx, evt, arg);
return NULL;
}
return NULL;
}
/**
* @ingroup device_sm
* @brief Device node state machine: Wait on a response for a sent PLOGI.
*
* <h3 class="desc">Description</h3>
* State is entered when an initiator-capable node has sent
* a PLOGI and is waiting for a response.
*
* @param ctx Remote node state machine context.
* @param evt Event to process.
* @param arg Per event optional argument.
*
* @return Returns NULL.
*/
void *
__ocs_d_wait_plogi_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_PLOGI_RCVD: {
/* T, or I+T */
/* received PLOGI with svc parms, go ahead and attach node
* when PLOGI that was sent ultimately completes, it'll be a no-op
*/
// TODO: there is an outstanding PLOGI sent, can we set a flag
// to indicate that we don't want to retry it if it times out?
ocs_node_save_sparms(node, cbdata->payload->dma.virt);
ocs_send_ls_acc_after_attach(cbdata->io, cbdata->header->dma.virt, OCS_NODE_SEND_LS_ACC_PLOGI);
//sm: domain->attached / ocs_node_attach
rc = ocs_node_attach(node);
ocs_node_transition(node, __ocs_d_wait_node_attach, NULL);
if (rc == OCS_HAL_RTN_SUCCESS_SYNC) {
ocs_node_post_event(node, OCS_EVT_NODE_ATTACH_OK, NULL);
}
break;
}
case OCS_EVT_PRLI_RCVD:
/* I, or I+T */
/* sent PLOGI and before completion was seen, received the
* PRLI from the remote node (WCQEs and RCQEs come in on
* different queues and order of processing cannot be assumed)
* Save OXID so PRLI can be sent after the attach and continue
* to wait for PLOGI response
*/
ocs_process_prli_payload(node, cbdata->payload->dma.virt);
ocs_send_ls_acc_after_attach(cbdata->io, cbdata->header->dma.virt, OCS_NODE_SEND_LS_ACC_PRLI);
ocs_node_transition(node, __ocs_d_wait_plogi_rsp_recvd_prli, NULL);
break;
// TODO this need to be looked at. we could very well be logged in