forked from ecdufcdrvr/bcmufctdrvr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ocs_els.c
2947 lines (2520 loc) · 77.9 KB
/
ocs_els.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
* Functions to build and send ELS/CT/BLS commands and responses.
*/
/*!
@defgroup els_api ELS/BLS/CT Command and Response Functions
*/
#include "ocs.h"
#include "ocs_els.h"
#include "ocs_scsi_fc.h"
#include "ocs_device.h"
#define ELS_IOFMT "[i:%04x t:%04x h:%04x]"
#define ELS_IOFMT_ARGS(els) els->init_task_tag, els->tgt_task_tag, els->hw_tag
#define node_els_trace() \
do { \
if (OCS_LOG_ENABLE_ELS_TRACE(ocs)) \
ocs_log_info(ocs, "[%s] %-20s\n", node->display_name, __func__); \
} while (0)
#define els_io_printf(els, fmt, ...) \
ocs_log_debug(els->node->ocs, "[%s]" ELS_IOFMT " %-8s " fmt, els->node->display_name, ELS_IOFMT_ARGS(els), els->display_name, ##__VA_ARGS__);
static int32_t ocs_els_send(ocs_io_t *els, uint32_t reqlen, uint32_t timeout_sec, ocs_hal_srrs_cb_t cb);
static int32_t ocs_els_send_rsp(ocs_io_t *els, uint32_t rsplen);
static int32_t ocs_els_acc_cb(ocs_hal_io_t *hio, ocs_remote_node_t *rnode, uint32_t length, int32_t status, uint32_t ext_status, void *arg);
static ocs_io_t *ocs_bls_send_acc(ocs_io_t *io, uint32_t s_id, uint16_t ox_id, uint16_t rx_id);
static int32_t ocs_bls_send_acc_cb(ocs_hal_io_t *hio, ocs_remote_node_t *rnode, uint32_t length,
int32_t status, uint32_t ext_status, void *app);
static void ocs_io_transition(ocs_io_t *els, ocs_sm_function_t state, void *data);
static ocs_io_t *ocs_els_abort_io(ocs_io_t *els, int send_abts);
static void _ocs_els_io_free(void *arg);
static void ocs_els_delay_timer_cb(void *arg);
#define OCS_ELS_RSP_LEN 1024
#define OCS_ELS_GID_FT_RSP_LEN 8096 /* Enough for 2K remote target nodes */
/**
* @ingroup els_api
* @brief ELS state machine transition wrapper.
*
* <h3 class="desc">Description</h3>
* This function is the transition wrapper for the ELS state machine. It grabs
* the node lock prior to making the transition to protect
* against multiple threads accessing a particular ELS. For example,
* one thread transitioning from __els_init to
* __ocs_els_wait_resp and another thread (tasklet) handling the
* completion of that ELS request.
*
* @param els Pointer to the IO context.
* @param state State to transition to.
* @param data Data to pass in with the transition.
*
* @return None.
*/
static void
ocs_io_transition(ocs_io_t *els, ocs_sm_function_t state, void *data)
{
/* protect ELS events with node lock */
ocs_node_t *node = els->node;
ocs_node_lock(node);
ocs_sm_transition(&els->els_sm, state, data);
ocs_node_unlock(node);
}
/**
* @ingroup els_api
* @brief ELS state machine post event wrapper.
*
* <h3 class="desc">Description</h3>
* Post an event wrapper for the ELS state machine. This function grabs
* the node lock prior to posting the event.
*
* @param els Pointer to the IO context.
* @param evt Event to process.
* @param data Data to pass in with the transition.
*
* @return None.
*/
void
ocs_els_post_event(ocs_io_t *els, ocs_sm_event_t evt, void *data)
{
/* protect ELS events with node lock */
ocs_node_t *node = els->node;
ocs_node_lock(node);
els->els_evtdepth ++;
ocs_sm_post_event(&els->els_sm, evt, data);
els->els_evtdepth --;
ocs_node_unlock(node);
if (els->els_evtdepth == 0 && els->els_req_free) {
ocs_els_io_free(els);
}
}
/**
* @ingroup els_api
* @brief Allocate an IO structure for an ELS IO context.
*
* <h3 class="desc">Description</h3>
* Allocate an IO for an ELS context. Uses OCS_ELS_RSP_LEN as response size.
*
* @param node node to associate ELS IO with
* @param reqlen Length of ELS request
* @param role Role of ELS (originator/responder)
*
* @return pointer to IO structure allocated
*/
ocs_io_t *
ocs_els_io_alloc(ocs_node_t *node, uint32_t reqlen, ocs_els_role_e role)
{
return ocs_els_io_alloc_size(node, reqlen, OCS_ELS_RSP_LEN, role);
}
/**
* @ingroup els_api
* @brief Allocate an IO structure for an ELS IO context.
*
* <h3 class="desc">Description</h3>
* Allocate an IO for an ELS context, allowing the caller to specify the size of the response.
*
* @param node node to associate ELS IO with
* @param reqlen Length of ELS request
* @param rsplen Length of ELS response
* @param role Role of ELS (originator/responder)
*
* @return pointer to IO structure allocated
*/
ocs_io_t *
ocs_els_io_alloc_size(ocs_node_t *node, uint32_t reqlen, uint32_t rsplen, ocs_els_role_e role)
{
int32_t rc;
ocs_t *ocs;
ocs_xport_t *xport;
ocs_io_t *els;
ocs_assert(node, NULL);
ocs_assert(node->ocs, NULL);
ocs = node->ocs;
ocs_assert(ocs->xport, NULL);
xport = ocs->xport;
ocs_lock(&node->active_ios_lock);
if (!node->io_alloc_enabled) {
ocs_log_debug(ocs, "%s: called with io_alloc_enabled = FALSE\n", __func__);
ocs_unlock(&node->active_ios_lock);
return NULL;
}
els = ocs_io_alloc(ocs);
if (els == NULL) {
ocs_atomic_add_return(&xport->io_alloc_failed_count, 1);
ocs_unlock(&node->active_ios_lock);
return NULL;
}
/* initialize refcount */
ocs_ref_init(&els->ref, _ocs_els_io_free, els);
switch (role) {
case OCS_ELS_ROLE_ORIGINATOR:
els->cmd_ini = TRUE;
els->cmd_tgt = FALSE;
break;
case OCS_ELS_ROLE_RESPONDER:
els->cmd_ini = FALSE;
els->cmd_tgt = TRUE;
break;
}
/* IO should not have an associated HAL IO yet. Assigned below. */
if (els->hio != NULL) {
ocs_log_err(ocs, "%s(%d): assertion failed. HIO is not null\n",
__func__, __LINE__);
ocs_io_free(ocs, els);
ocs_unlock(&node->active_ios_lock);
return NULL;
}
/* populate generic io fields */
els->ocs = ocs;
els->node = node;
/* set type and ELS-specific fields */
els->io_type = OCS_IO_TYPE_ELS;
els->display_name = "pending";
/* now allocate DMA for request and response */
rc = ocs_dma_alloc(ocs, &els->els_req, reqlen, OCS_MIN_DMA_ALIGNMENT);
if (rc == 0) {
rc = ocs_dma_alloc(ocs, &els->els_rsp, rsplen, OCS_MIN_DMA_ALIGNMENT);
if (rc != 0) {
ocs_log_err(ocs, "%s: ocs_dma_alloc rsp\n", __func__);
ocs_dma_free(ocs, &els->els_req);
ocs_io_free(ocs, els);
els = NULL;
}
} else {
ocs_log_err(ocs, "%s: ocs_dma_alloc req\n", __func__);
ocs_io_free(ocs, els);
els = NULL;
}
if (els != NULL) {
ocs_memset(&els->els_sm, 0, sizeof(els->els_sm));
els->els_sm.app = els;
/* initialize fields */
els->els_retries_remaining = OCS_FC_ELS_DEFAULT_RETRIES;
els->els_evtdepth = 0;
els->els_pend = 0;
els->els_active = 0;
/* add els structure to ELS IO list */
ocs_list_add_tail(&node->els_io_pend_list, els);
els->els_pend = 1;
}
ocs_unlock(&node->active_ios_lock);
return els;
}
/**
* @ingroup els_api
* @brief Free IO structure for an ELS IO context.
*
* <h3 class="desc">Description</h3> Free IO for an ELS
* IO context
*
* @param els ELS IO structure for which IO is allocated
*
* @return None
*/
void
ocs_els_io_free(ocs_io_t *els)
{
ocs_ref_put(&els->ref);
}
/**
* @ingroup els_api
* @brief Free IO structure for an ELS IO context.
*
* <h3 class="desc">Description</h3> Free IO for an ELS
* IO context
*
* @param arg ELS IO structure for which IO is allocated
*
* @return None
*/
static void
_ocs_els_io_free(void *arg)
{
ocs_io_t *els = (ocs_io_t *)arg;
ocs_t *ocs;
ocs_node_t *node;
int send_empty_event = FALSE;
ocs_assert(els);
ocs_assert(els->node);
ocs_assert(els->node->ocs);
ocs = els->node->ocs;
node = els->node;
ocs = node->ocs;
ocs_lock(&node->active_ios_lock);
if (els->els_active) {
/* if active, remove from active list and check empty */
ocs_list_remove(&node->els_io_active_list, els);
/* Send list empty event if the IO allocator is disabled, and the list is empty
* If node->io_alloc_enabled was not checked, the event would be posted continually
*/
send_empty_event = (!node->io_alloc_enabled) && ocs_list_empty(&node->els_io_active_list);
els->els_active = 0;
} else if (els->els_pend) {
/* if pending, remove from pending list; node shutdown isn't
* gated off the pending list (only the active list), so no
* need to check if pending list is empty
*/
ocs_list_remove(&node->els_io_pend_list, els);
els->els_pend = 0;
} else {
ocs_log_err(ocs, "%s(%d) : assertion failed: niether els->els_pend nor els->active set\n",
__func__, __LINE__);
ocs_unlock(&node->active_ios_lock);
return;
}
ocs_unlock(&node->active_ios_lock);
/* free ELS request and response buffers */
ocs_dma_free(ocs, &els->els_rsp);
ocs_dma_free(ocs, &els->els_req);
ocs_io_free(ocs, els);
if (send_empty_event) {
ocs_node_post_event(node, OCS_EVT_ALL_CHILD_NODES_FREE, NULL);
}
ocs_scsi_check_pending(ocs);
}
/**
* @ingroup els_api
* @brief Make ELS IO active
*
* @param els Pointer to the IO context to make active.
*
* @return Returns 0 on success; or a negative error code value on failure.
*/
static void
ocs_els_make_active(ocs_io_t *els)
{
ocs_node_t *node = els->node;
/* move ELS from pending list to active list */
ocs_lock(&node->active_ios_lock);
if (els->els_pend) {
if (els->els_active) {
ocs_log_err(node->ocs, "%s(%d): assertion failed: both els->els_pend and els->active set\n",
__func__, __LINE__);
ocs_unlock(&node->active_ios_lock);
return;
} else {
/* remove from pending list */
ocs_list_remove(&node->els_io_pend_list, els);
els->els_pend = 0;
/* add els structure to ELS IO list */
ocs_list_add_tail(&node->els_io_active_list, els);
els->els_active = 1;
}
} else {
/* must be retrying; make sure it's already active */
if (!els->els_active) {
ocs_log_err(node->ocs, "%s(%d) : assertion failed: niether els->els_pend nor els->active set\n",
__func__, __LINE__);
}
}
ocs_unlock(&node->active_ios_lock);
}
/**
* @ingroup els_api
* @brief Send the ELS command.
*
* <h3 class="desc">Description</h3>
* The command, given by the \c els IO context, is sent to the node that the IO was
* configured with, using ocs_hal_srrs_send(). Upon completion,
* the \c cb callback is invoked,
* with the application-specific argument set to the \c els IO context.
*
* @param els Pointer to the IO context.
* @param reqlen Byte count in the payload to send.
* @param timeout_sec Command timeout, in seconds (0 -> 2*R_A_TOV).
* @param cb Completion callback.
*
* @return Returns 0 on success; or a negative error code value on failure.
*/
static int32_t
ocs_els_send(ocs_io_t *els, uint32_t reqlen, uint32_t timeout_sec, ocs_hal_srrs_cb_t cb)
{
ocs_node_t *node = els->node;
/* update ELS request counter */
node->els_req_cnt++;
/* move ELS from pending list to active list */
ocs_els_make_active(els);
els->wire_len = reqlen;
return ocs_scsi_io_dispatch(els, cb);
}
/**
* @ingroup els_api
* @brief Send the ELS response.
*
* <h3 class="desc">Description</h3>
* The ELS response, given by the \c els IO context, is sent to the node
* that the IO was configured with, using ocs_hal_srrs_send().
*
* @param els Pointer to the IO context.
* @param rsplen Byte count in the payload to send.
*
* @return Returns 0 on success; or a negative error value on failure.
*/
static int32_t
ocs_els_send_rsp(ocs_io_t *els, uint32_t rsplen)
{
ocs_node_t *node = els->node;
/* increment ELS completion counter */
node->els_cmpl_cnt++;
/* move ELS from pending list to active list */
ocs_els_make_active(els);
els->wire_len = rsplen;
return ocs_scsi_io_dispatch(els, ocs_els_acc_cb);
}
/**
* @ingroup els_api
* @brief Handle ELS IO request completions.
*
* <h3 class="desc">Description</h3>
* This callback is used for several ELS send operations.
*
* @param hio Pointer to the HAL IO context that completed.
* @param rnode Pointer to the remote node.
* @param length Length of the returned payload data.
* @param status Status of the completion.
* @param ext_status Extended status of the completion.
* @param arg Application-specific argument (generally a pointer to the ELS IO context).
*
* @return Returns 0 on success; or a negative error value on failure.
*/
static int32_t
ocs_els_req_cb(ocs_hal_io_t *hio, ocs_remote_node_t *rnode, uint32_t length, int32_t status, uint32_t ext_status, void *arg)
{
ocs_io_t *els;
ocs_node_t *node;
ocs_t *ocs;
ocs_node_cb_t cbdata;
ocs_io_t *io;
ocs_assert(arg, -1);
io = arg;
els = io;
ocs_assert(els, -1);
ocs_assert(els->node, -1);
node = els->node;
ocs_assert(node->ocs, -1);
ocs = node->ocs;
ocs_assert(io->hio, -1);
ocs_assert(hio == io->hio, -1);
if (status != 0) {
els_io_printf(els, "status x%x ext x%x\n", status, ext_status);
}
// set the response len element of els->rsp
els->els_rsp.len = length;
cbdata.status = status;
cbdata.ext_status = ext_status;
cbdata.header = NULL;
cbdata.els = els;
/* FW returns the number of bytes received on the link in
* the WCQE, not the amount placed in the buffer; use this info to
* check if there was an overrun.
*/
if (length > els->els_rsp.size) {
ocs_log_warn(ocs, "%s ELS response returned len=%d > buflen=%zu\n",
__func__, length, els->els_rsp.size);
ocs_els_post_event(els, OCS_EVT_SRRS_ELS_REQ_FAIL, &cbdata);
return 0;
}
/* Post event to ELS IO object */
switch (status) {
case SLI4_FC_WCQE_STATUS_SUCCESS:
ocs_els_post_event(els, OCS_EVT_SRRS_ELS_REQ_OK, &cbdata);
break;
case SLI4_FC_WCQE_STATUS_LS_RJT:
ocs_els_post_event(els, OCS_EVT_SRRS_ELS_REQ_RJT, &cbdata);
break;
case SLI4_FC_WCQE_STATUS_LOCAL_REJECT:
switch (ext_status) {
case SLI4_FC_LOCAL_REJECT_SEQUENCE_TIMEOUT:
ocs_els_post_event(els, OCS_EVT_ELS_REQ_TIMEOUT, &cbdata);
break;
case SLI4_FC_LOCAL_REJECT_ABORT_REQUESTED:
ocs_els_post_event(els, OCS_EVT_ELS_REQ_ABORTED, &cbdata);
break;
default:
ocs_els_post_event(els, OCS_EVT_SRRS_ELS_REQ_FAIL, &cbdata);
break;
}
break;
default: // Other error
ocs_log_warn(ocs, "els req complete: failed status x%x, ext_status, x%x\n", status, ext_status);
ocs_els_post_event(els, OCS_EVT_SRRS_ELS_REQ_FAIL, &cbdata);
break;
}
return 0;
}
/**
* @ingroup els_api
* @brief Handle ELS IO accept/response completions.
*
* <h3 class="desc">Description</h3>
* This callback is used for several ELS send operations.
*
* @param hio Pointer to the HAL IO context that completed.
* @param rnode Pointer to the remote node.
* @param length Length of the returned payload data.
* @param status Status of the completion.
* @param ext_status Extended status of the completion.
* @param arg Application-specific argument (generally a pointer to the ELS IO context).
*
* @return Returns 0 on success; or a negative error value on failure.
*/
static int32_t
ocs_els_acc_cb(ocs_hal_io_t *hio, ocs_remote_node_t *rnode, uint32_t length, int32_t status, uint32_t ext_status, void *arg)
{
ocs_io_t *els;
ocs_node_t *node;
ocs_t *ocs;
ocs_node_cb_t cbdata;
ocs_io_t *io;
ocs_assert(arg, -1);
io = arg;
els = io;
ocs_assert(els, -1);
ocs_assert(els->node, -1);
node = els->node;
ocs_assert(node->ocs, -1);
ocs = node->ocs;
ocs_assert(io->hio, -1);
ocs_assert(hio == io->hio, -1);
cbdata.status = status;
cbdata.ext_status = ext_status;
cbdata.header = NULL;
cbdata.els = els;
/* Post node event */
switch (status) {
case SLI4_FC_WCQE_STATUS_SUCCESS:
ocs_node_post_event(node, OCS_EVT_SRRS_ELS_CMPL_OK, &cbdata);
break;
default: // Other error
ocs_log_warn(ocs, "[%s] %-8s failed status x%x, ext_status x%x\n",
node->display_name, els->display_name, status, ext_status);
ocs_log_warn(ocs, "els acc complete: failed status x%x, ext_status, x%x\n", status, ext_status);
ocs_node_post_event(node, OCS_EVT_SRRS_ELS_CMPL_FAIL, &cbdata);
break;
}
/* If this IO has a callback, invoke it */
if (els->els_callback) {
(*els->els_callback)(node, &cbdata, els->els_callback_arg);
}
ocs_els_io_free(els);
return 0;
}
/**
* @ingroup els_api
* @brief Format and send a PLOGI ELS command.
*
* <h3 class="desc">Description</h3>
* Construct a PLOGI payload using the domain SLI port service parameters,
* and send to the \c node.
*
* @param node Node to which the PLOGI is sent.
* @param timeout_sec Command timeout, in seconds.
* @param retries Number of times to retry errors before reporting a failure.
* @param cb Callback function.
* @param cbarg Callback function argument.
*
* @return Returns pointer to IO object, or NULL if error.
*/
ocs_io_t *
ocs_send_plogi(ocs_node_t *node, uint32_t timeout_sec, uint32_t retries,
void (*cb)(ocs_node_t *node, ocs_node_cb_t *cbdata, void *arg), void *cbarg)
{
ocs_io_t *els;
ocs_t *ocs = node->ocs;
fc_plogi_payload_t *plogi;
node_els_trace();
els = ocs_els_io_alloc(node, sizeof(*plogi), OCS_ELS_ROLE_ORIGINATOR);
if (els == NULL) {
ocs_log_err(ocs, "%s: IO alloc failed\n", __func__);
} else {
els->els_timeout_sec = timeout_sec;
els->els_retries_remaining = retries;
els->els_callback = cb;
els->els_callback_arg = cbarg;
els->display_name = "plogi";
/* Build PLOGI request */
plogi = els->els_req.virt;
ocs_memcpy(plogi, node->sport->service_params, sizeof(*plogi));
plogi->command_code = FC_ELS_CMD_PLOGI;
plogi->resv1 = 0;
ocs_display_sparams(node->display_name, "plogi send req", 0, NULL, plogi->common_service_parameters);
els->hio_type = OCS_HAL_ELS_REQ;
els->iparam.els.timeout = timeout_sec;
ocs_io_transition(els, __ocs_els_init, NULL);
}
return els;
}
/**
* @ingroup els_api
* @brief Format and send a FLOGI ELS command.
*
* <h3 class="desc">Description</h3>
* Construct an FLOGI payload, and send to the \c node.
*
* @param node Node to which the FLOGI is sent.
* @param timeout_sec Command timeout, in seconds.
* @param retries Number of times to retry errors before reporting a failure.
* @param cb Callback function.
* @param cbarg Callback function argument.
*
* @return Returns pointer to IO object, or NULL if error.
*/
ocs_io_t *
ocs_send_flogi(ocs_node_t *node, uint32_t timeout_sec, uint32_t retries,
els_cb_t cb, void *cbarg)
{
ocs_io_t *els;
ocs_t *ocs;
fc_plogi_payload_t *flogi;
ocs_assert(node, NULL);
ocs_assert(node->ocs, NULL);
ocs_assert(node->sport, NULL);
ocs = node->ocs;
node_els_trace();
els = ocs_els_io_alloc(node, sizeof(*flogi), OCS_ELS_ROLE_ORIGINATOR);
if (els == NULL) {
ocs_log_err(ocs, "%s: IO alloc failed\n", __func__);
} else {
els->els_timeout_sec = timeout_sec;
els->els_retries_remaining = retries;
els->els_callback = cb;
els->els_callback_arg = cbarg;
els->display_name = "flogi";
/* Build FLOGI request */
flogi = els->els_req.virt;
ocs_memcpy(flogi, node->sport->service_params, sizeof(*flogi));
flogi->command_code = FC_ELS_CMD_FLOGI;
flogi->resv1 = 0;
ocs_display_sparams(node->display_name, "flogi send req", 0, NULL, flogi->common_service_parameters);
els->hio_type = OCS_HAL_ELS_REQ;
els->iparam.els.timeout = timeout_sec;
ocs_io_transition(els, __ocs_els_init, NULL);
}
return els;
}
/**
* @ingroup els_api
* @brief Format and send a FDISC ELS command.
*
* <h3 class="desc">Description</h3>
* Construct an FDISC payload, and send to the \c node.
*
* @param node Node to which the FDISC is sent.
* @param timeout_sec Command timeout, in seconds.
* @param retries Number of times to retry errors before reporting a failure.
* @param cb Callback function.
* @param cbarg Callback function argument.
*
* @return Returns pointer to IO object, or NULL if error.
*/
ocs_io_t *
ocs_send_fdisc(ocs_node_t *node, uint32_t timeout_sec, uint32_t retries,
els_cb_t cb, void *cbarg)
{
ocs_io_t *els;
ocs_t *ocs;
fc_plogi_payload_t *fdisc;
ocs_assert(node, NULL);
ocs_assert(node->ocs, NULL);
ocs = node->ocs;
node_els_trace();
els = ocs_els_io_alloc(node, sizeof(*fdisc), OCS_ELS_ROLE_ORIGINATOR);
if (els == NULL) {
ocs_log_err(ocs, "%s: IO alloc failed\n", __func__);
} else {
els->els_timeout_sec = timeout_sec;
els->els_retries_remaining = retries;
els->els_callback = cb;
els->els_callback_arg = cbarg;
els->display_name = "fdisc";
/* Build FDISC request */
fdisc = els->els_req.virt;
ocs_memcpy(fdisc, node->sport->service_params, sizeof(*fdisc));
fdisc->command_code = FC_ELS_CMD_FDISC;
fdisc->resv1 = 0;
ocs_display_sparams(node->display_name, "fdisc send req", 0, NULL, fdisc->common_service_parameters);
els->hio_type = OCS_HAL_ELS_REQ;
els->iparam.els.timeout = timeout_sec;
ocs_io_transition(els, __ocs_els_init, NULL);
}
return els;
}
/**
* @ingroup els_api
* @brief Send a PRLI ELS command.
*
* <h3 class="desc">Description</h3>
* Construct a PRLI ELS command, and send to the \c node.
*
* @param node Node to which the PRLI is sent.
* @param timeout_sec Command timeout, in seconds.
* @param retries Number of times to retry errors before reporting a failure.
* @param cb Callback function.
* @param cbarg Callback function argument.
*
* @return Returns pointer to IO object, or NULL if error.
*/
ocs_io_t *
ocs_send_prli(ocs_node_t *node, uint32_t timeout_sec, uint32_t retries,
els_cb_t cb, void *cbarg)
{
ocs_t *ocs = node->ocs;
ocs_io_t *els;
fc_prli_payload_t *prli;
node_els_trace();
els = ocs_els_io_alloc(node, sizeof(*prli), OCS_ELS_ROLE_ORIGINATOR);
if (els == NULL) {
ocs_log_err(ocs, "%s: IO alloc failed\n", __func__);
} else {
els->els_timeout_sec = timeout_sec;
els->els_retries_remaining = retries;
els->els_callback = cb;
els->els_callback_arg = cbarg;
els->display_name = "prli";
/* Build PRLI request */
prli = els->els_req.virt;
ocs_memset(prli, 0, sizeof(*prli));
prli->command_code = FC_ELS_CMD_PRLI;
prli->page_length = 16;
prli->payload_length = ocs_htobe16(sizeof(fc_prli_payload_t));
prli->type = FC_TYPE_FCP;
prli->type_ext = 0;
prli->flags = ocs_htobe16(FC_PRLI_ESTABLISH_IMAGE_PAIR);
prli->service_params = ocs_htobe16(FC_PRLI_READ_XRDY_DISABLED |
(node->sport->enable_ini ? FC_PRLI_INITIATOR_FUNCTION : 0) |
(node->sport->enable_tgt ? FC_PRLI_TARGET_FUNCTION : 0));
els->hio_type = OCS_HAL_ELS_REQ;
els->iparam.els.timeout = timeout_sec;
ocs_io_transition(els, __ocs_els_init, NULL);
}
return els;
}
/**
* @ingroup els_api
* @brief Send a PRLO ELS command.
*
* <h3 class="desc">Description</h3>
* Construct a PRLO ELS command, and send to the \c node.
*
* @param node Node to which the PRLO is sent.
* @param timeout_sec Command timeout, in seconds.
* @param retries Number of times to retry errors before reporting a failure.
* @param cb Callback function.
* @param cbarg Callback function argument.
*
* @return Returns pointer to IO object, or NULL if error.
*/
ocs_io_t *
ocs_send_prlo(ocs_node_t *node, uint32_t timeout_sec, uint32_t retries,
els_cb_t cb, void *cbarg)
{
ocs_t *ocs = node->ocs;
ocs_io_t *els;
fc_prlo_payload_t *prlo;
node_els_trace();
els = ocs_els_io_alloc(node, sizeof(*prlo), OCS_ELS_ROLE_ORIGINATOR);
if (els == NULL) {
ocs_log_err(ocs, "%s: IO alloc failed\n", __func__);
} else {
els->els_timeout_sec = timeout_sec;
els->els_retries_remaining = retries;
els->els_callback = cb;
els->els_callback_arg = cbarg;
els->display_name = "prlo";
/* Build PRLO request */
prlo = els->els_req.virt;
ocs_memset(prlo, 0, sizeof(*prlo));
prlo->command_code = FC_ELS_CMD_PRLO;
prlo->page_length = 16;
prlo->payload_length = ocs_htobe16(sizeof(fc_prlo_payload_t));
prlo->type = FC_TYPE_FCP;
prlo->type_ext = 0;
els->hio_type = OCS_HAL_ELS_REQ;
els->iparam.els.timeout = timeout_sec;
ocs_io_transition(els, __ocs_els_init, NULL);
}
return els;
}
/**
* @ingroup els_api
* @brief Send a LOGO ELS command.
*
* <h3 class="desc">Description</h3>
* Format a LOGO, and send to the \c node.
*
* @param node Node to which the LOGO is sent.
* @param timeout_sec Command timeout, in seconds.
* @param retries Number of times to retry errors before reporting a failure.
* @param cb Callback function.
* @param cbarg Callback function argument.
*
* @return Returns pointer to IO object, or NULL if error.
*/
ocs_io_t *
ocs_send_logo(ocs_node_t *node, uint32_t timeout_sec, uint32_t retries,
els_cb_t cb, void *cbarg)
{
ocs_io_t *els;
ocs_t *ocs;
fc_logo_payload_t *logo;
fc_plogi_payload_t *sparams;
ocs = node->ocs;
node_els_trace();
sparams = (fc_plogi_payload_t*) node->sport->service_params;
els = ocs_els_io_alloc(node, sizeof(*logo), OCS_ELS_ROLE_ORIGINATOR);
if (els == NULL) {
ocs_log_err(ocs, "%s: IO alloc failed\n", __func__);
} else {
els->els_timeout_sec = timeout_sec;
els->els_retries_remaining = retries;
els->els_callback = cb;
els->els_callback_arg = cbarg;
els->display_name = "logo";
/* Build LOGO request */
logo = els->els_req.virt;
ocs_memset(logo, 0, sizeof(*logo));
logo->command_code = FC_ELS_CMD_LOGO;
logo->resv1 = 0;
logo->port_id = fc_htobe24(node->rnode.sport->fc_id);
logo->port_name_hi = sparams->port_name_hi;
logo->port_name_lo = sparams->port_name_lo;
els->hio_type = OCS_HAL_ELS_REQ;
els->iparam.els.timeout = timeout_sec;
ocs_io_transition(els, __ocs_els_init, NULL);
}
return els;
}
/**
* @ingroup els_api
* @brief Send an ADISC ELS command.
*
* <h3 class="desc">Description</h3>
* Construct an ADISC ELS command, and send to the \c node.
*
* @param node Node to which the ADISC is sent.
* @param timeout_sec Command timeout, in seconds.
* @param retries Number of times to retry errors before reporting a failure.
* @param cb Callback function.
* @param cbarg Callback function argument.
*
* @return Returns pointer to IO object, or NULL if error.
*/
ocs_io_t *
ocs_send_adisc(ocs_node_t *node, uint32_t timeout_sec, uint32_t retries,
els_cb_t cb, void *cbarg)
{
ocs_io_t *els;
ocs_t *ocs;
fc_adisc_payload_t *adisc;
fc_plogi_payload_t *sparams;
ocs_sport_t *sport = node->sport;
ocs = node->ocs;
node_els_trace();
sparams = (fc_plogi_payload_t*) node->sport->service_params;
els = ocs_els_io_alloc(node, sizeof(*adisc), OCS_ELS_ROLE_ORIGINATOR);
if (els == NULL) {
ocs_log_err(ocs, "%s: IO alloc failed\n", __func__);
} else {
els->els_timeout_sec = timeout_sec;
els->els_retries_remaining = retries;
els->els_callback = cb;
els->els_callback_arg = cbarg;
els->display_name = "adisc";
/* Build ADISC request */
adisc = els->els_req.virt;
sparams = (fc_plogi_payload_t*) node->sport->service_params;
ocs_memset(adisc, 0, sizeof(*adisc));
adisc->command_code = FC_ELS_CMD_ADISC;
adisc->hard_address = fc_htobe24(sport->fc_id);
adisc->port_name_hi = sparams->port_name_hi;
adisc->port_name_lo = sparams->port_name_lo;