forked from ecdufcdrvr/bcmufctdrvr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ocs_unsol.c
1445 lines (1282 loc) · 40.3 KB
/
ocs_unsol.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
* Code to handle unsolicited received FC frames.
*/
/*!
* @defgroup unsol Unsolicited Frame Handling
*/
#include "ocs.h"
#include "ocs_els.h"
#include "ocs_fabric.h"
#include "ocs_device.h"
#include "scsi_cmds.h"
#define frame_printf(ocs, hdr, fmt, ...) \
do { \
char s_id_text[16]; \
ocs_node_fcid_display(fc_be24toh((hdr)->s_id), s_id_text, sizeof(s_id_text)); \
ocs_log_debug(ocs, "[%06x.%s] %02x/%04x/%04x: " fmt, fc_be24toh((hdr)->d_id), s_id_text, \
(hdr)->r_ctl, ocs_be16toh((hdr)->ox_id), ocs_be16toh((hdr)->rx_id), ##__VA_ARGS__); \
} while(0)
static int32_t ocs_unsol_process(ocs_t *ocs, ocs_hal_sequence_t *seq);
static int32_t ocs_dispatch_fcp_cmd(ocs_node_t *node, ocs_hal_sequence_t *seq);
static int32_t ocs_dispatch_fcp_cmd_auto_xfer_rdy(ocs_node_t *node, ocs_hal_sequence_t *seq);
static int32_t ocs_dispatch_fcp_data(ocs_node_t *node, ocs_hal_sequence_t *seq);
static uint32_t ocs_fc_decode_lun(uint8_t *lu);
static int32_t ocs_domain_dispatch_frame(void *arg, ocs_hal_sequence_t *seq);
static int32_t ocs_node_dispatch_frame(void *arg, ocs_hal_sequence_t *seq);
static int32_t ocs_fc_tmf_rejected_cb(ocs_io_t *io, ocs_scsi_io_status_e scsi_status, uint32_t flags, void *arg);
static ocs_hal_sequence_t *ocs_frame_next(ocs_list_t *pend_list, ocs_lock_t *list_lock);
static uint8_t ocs_node_frames_held(void *arg);
static uint8_t ocs_domain_frames_held(void *arg);
static int32_t ocs_purge_pending(ocs_t *ocs, ocs_list_t *pend_list, ocs_lock_t *list_lock);
static int32_t ocs_sframe_send_task_set_full_or_busy(ocs_node_t *node, ocs_hal_sequence_t *seq);
#define OCS_MAX_FRAMES_BEFORE_YEILDING 10000
/**
* @brief Process the RQ circular buffer and process the incoming frames.
*
* @param mythread Pointer to thread object.
*
* @return Returns 0 on success, or a non-zero value on failure.
*/
int32_t
ocs_unsol_rq_thread(ocs_thread_t *mythread)
{
ocs_xport_rq_thread_info_t *thread_data = mythread->arg;
ocs_t *ocs = thread_data->ocs;
ocs_hal_sequence_t *seq;
uint32_t yield_count = OCS_MAX_FRAMES_BEFORE_YEILDING;
ocs_log_debug(ocs, "%s %s: running\n", __func__, mythread->name);
while (!ocs_thread_terminate_requested(mythread)) {
seq = ocs_cbuf_get(thread_data->seq_cbuf, 100000);
if (seq == NULL) {
/* Prevent soft lockups by yielding the CPU */
ocs_thread_yield(&thread_data->thread);
yield_count = OCS_MAX_FRAMES_BEFORE_YEILDING;
continue;
}
/* Note: Always returns 0 */
ocs_unsol_process((ocs_t*)seq->hal->os, seq);
/* We have to prevent CPU soft lockups, so just yield the CPU after x frames. */
if (--yield_count == 0) {
ocs_thread_yield(&thread_data->thread);
yield_count = OCS_MAX_FRAMES_BEFORE_YEILDING;
}
}
ocs_log_debug(ocs, "%s %s: exiting\n", __func__, mythread->name);
thread_data->thread_started = FALSE;
return 0;
}
/**
* @ingroup unsol
* @brief Callback function when aborting a port owned XRI
* exchanges.
*
* @return Returns 0.
*/
static int32_t
ocs_unsol_abort_cb (ocs_hal_io_t *hio, ocs_remote_node_t *rnode, uint32_t len, int32_t status, uint32_t ext, void *arg)
{
ocs_t *ocs = arg;
ocs_assert(hio, -1);
ocs_assert(arg, -1);
ocs_log_debug(ocs, "%s: xri=0x%x tag=0x%x\n", __func__, hio->indicator, hio->reqtag);
ocs_hal_io_free(&ocs->hal, hio);
return 0;
}
/**
* @ingroup unsol
* @brief Abort either a RQ Pair auto XFER RDY XRI.
* @return Returns None.
*/
static void
ocs_port_owned_abort(ocs_t *ocs, ocs_hal_io_t *hio)
{
ocs_hal_rtn_e hal_rc;
hal_rc = ocs_hal_io_abort(&ocs->hal, hio, FALSE,
ocs_unsol_abort_cb, ocs);
if((hal_rc == OCS_HAL_RTN_IO_ABORT_IN_PROGRESS) ||
(hal_rc == OCS_HAL_RTN_IO_PORT_OWNED_ALREADY_ABORTED)) {
ocs_log_debug(ocs, "%s: already aborted XRI 0x%x\n",
__func__, hio->indicator);
} else if(hal_rc != OCS_HAL_RTN_SUCCESS) {
ocs_log_debug(ocs, "%s: Error aborting XRI 0x%x status %d\n",
__func__, hio->indicator, hal_rc);
}
}
/**
* @ingroup unsol
* @brief Handle unsolicited FC frames.
*
* <h3 class="desc">Description</h3>
* This function is called from the HAL with unsolicited FC frames (FCP, ELS, BLS, etc.).
*
* @param arg Application-specified callback data.
* @param seq Header/payload sequence buffers.
*
* @return Returns 0 on success; or a negative error value on failure.
*/
int32_t
ocs_unsolicited_cb(void *arg, ocs_hal_sequence_t *seq)
{
ocs_t *ocs = arg;
ocs_xport_t *xport = ocs->xport;
int32_t rc;
CPUTRACE("");
if (ocs->rq_threads == 0) {
rc = ocs_unsol_process(ocs, seq);
} else {
/* use the ox_id to dispatch this IO to a thread */
fc_header_t *hdr = seq->header->dma.virt;
uint32_t ox_id = ocs_be16toh(hdr->ox_id);
uint32_t thr_index = ox_id % ocs->rq_threads;
rc = ocs_cbuf_put(xport->rq_thread_info[thr_index].seq_cbuf, seq);
}
if (rc) {
ocs_hal_sequence_free(&ocs->hal, seq);
}
return 0;
}
/**
* @ingroup unsol
* @brief Handle unsolicited FC frames.
*
* <h3 class="desc">Description</h3>
* This function is called either from ocs_unsolicited_cb() or ocs_unsol_rq_thread().
*
* @param ocs Pointer to the ocs structure.
* @param seq Header/payload sequence buffers.
*
* @return Returns 0 on success, or a negative error value on failure.
*/
static int32_t
ocs_unsol_process(ocs_t *ocs, ocs_hal_sequence_t *seq)
{
ocs_xport_fcfi_t *xport_fcfi = NULL;
ocs_domain_t *domain;
uint8_t seq_fcfi = seq->fcfi;
/* HAL_WORKAROUND_OVERRIDE_FCFI_IN_SRB */
if (ocs->hal.workaround.override_fcfi) {
if (ocs->hal.first_domain_idx > -1) {
seq_fcfi = ocs->hal.first_domain_idx;
}
}
/* Range check seq->fcfi */
if (seq_fcfi < ARRAY_SIZE(ocs->xport->fcfi)) {
xport_fcfi = &ocs->xport->fcfi[seq_fcfi];
}
/* If the transport FCFI entry is NULL, then drop the frame */
if (xport_fcfi == NULL) {
ocs_log_test(ocs, "%s: FCFI %d is not valid, dropping frame\n", __func__, seq->fcfi);
if (seq->hio != NULL) {
ocs_port_owned_abort(ocs, seq->hio);
}
ocs_hal_sequence_free(&ocs->hal, seq);
return 0;
}
domain = ocs_hal_domain_get(&ocs->hal, seq_fcfi);
/*
* If we are holding frames or the domain is not yet registered or
* there's already frames on the pending list,
* then add the new frame to pending list
*/
if (domain == NULL ||
xport_fcfi->hold_frames ||
!ocs_list_empty(&xport_fcfi->pend_frames)) {
ocs_lock(&xport_fcfi->pend_frames_lock);
ocs_list_add_tail(&xport_fcfi->pend_frames, seq);
ocs_unlock(&xport_fcfi->pend_frames_lock);
if (domain != NULL) {
/* immediately process pending frames */
ocs_domain_process_pending(domain);
}
} else {
/*
* We are not holding frames and pending list is empty, just process frame.
* A non-zero return means the frame was not handled - so cleanup
*/
if (ocs_domain_dispatch_frame(domain, seq)) {
if (seq->hio != NULL) {
ocs_port_owned_abort(ocs, seq->hio);
}
ocs_hal_sequence_free(&ocs->hal, seq);
}
}
return 0;
}
/**
* @ingroup unsol
* @brief Process pending frames queued to the given node.
*
* <h3 class="desc">Description</h3>
* Frames that are queued for the \c node are dispatched and returned
* to the RQ.
*
* @param node Node of the queued frames that are to be dispatched.
*
* @return Returns 0 on success, or a negative error value on failure.
*/
int32_t
ocs_process_node_pending(ocs_node_t *node)
{
ocs_t *ocs = node->ocs;
ocs_hal_sequence_t *seq = NULL;
uint32_t pend_frames_processed = 0;
for (;;) {
/* need to check for hold frames condition after each frame processed
* because any given frame could cause a transition to a state that
* holds frames
*/
if (ocs_node_frames_held(node)) {
break;
}
/* Get next frame/sequence */
ocs_lock(&node->pend_frames_lock);
seq = ocs_list_remove_head(&node->pend_frames);
if (seq == NULL) {
pend_frames_processed = node->pend_frames_processed;
node->pend_frames_processed = 0;
ocs_unlock(&node->pend_frames_lock);
break;
}
node->pend_frames_processed++;
ocs_unlock(&node->pend_frames_lock);
/* now dispatch frame(s) to dispatch function */
if (ocs_node_dispatch_frame(node, seq)) {
if (seq->hio != NULL) {
ocs_port_owned_abort(ocs, seq->hio);
}
ocs_hal_sequence_free(&ocs->hal, seq);
}
}
if (pend_frames_processed != 0) {
ocs_log_debug(ocs, "%s: %u node frames held and processed\n", __func__, pend_frames_processed);
}
return 0;
}
/**
* @ingroup unsol
* @brief Process pending frames queued to the given domain.
*
* <h3 class="desc">Description</h3>
* Frames that are queued for the \c domain are dispatched and
* returned to the RQ.
*
* @param domain Domain of the queued frames that are to be
* dispatched.
*
* @return Returns 0 on success, or a negative error value on failure.
*/
int32_t
ocs_domain_process_pending(ocs_domain_t *domain)
{
ocs_t *ocs = domain->ocs;
ocs_xport_fcfi_t *xport_fcfi;
ocs_hal_sequence_t *seq = NULL;
uint32_t pend_frames_processed = 0;
ocs_assert(domain->fcf_indicator < SLI4_MAX_FCFI, -1);
xport_fcfi = &ocs->xport->fcfi[domain->fcf_indicator];
for (;;) {
/* need to check for hold frames condition after each frame processed
* because any given frame could cause a transition to a state that
* holds frames
*/
if (ocs_domain_frames_held(domain)) {
break;
}
/* Get next frame/sequence */
ocs_lock(&xport_fcfi->pend_frames_lock);
seq = ocs_list_remove_head(&xport_fcfi->pend_frames);
if (seq == NULL) {
pend_frames_processed = xport_fcfi->pend_frames_processed;
xport_fcfi->pend_frames_processed = 0;
ocs_unlock(&xport_fcfi->pend_frames_lock);
break;
}
xport_fcfi->pend_frames_processed++;
ocs_unlock(&xport_fcfi->pend_frames_lock);
/* now dispatch frame(s) to dispatch function */
if (ocs_domain_dispatch_frame(domain, seq)) {
if (seq->hio != NULL) {
ocs_port_owned_abort(ocs, seq->hio);
}
ocs_hal_sequence_free(&ocs->hal, seq);
}
}
if (pend_frames_processed != 0) {
ocs_log_debug(ocs, "%s: %u domain frames held and processed\n", __func__, pend_frames_processed);
}
return 0;
}
/**
* @ingroup unsol
* @brief Purge given pending list
*
* <h3 class="desc">Description</h3>
* Frames that are queued on the given pending list are
* discarded and returned to the RQ.
*
* @param ocs Pointer to ocs object.
* @param pend_list Pending list to be purged.
* @param list_lock Lock that protects pending list.
*
* @return Returns 0 on success, or a negative error value on failure.
*/
static int32_t
ocs_purge_pending(ocs_t *ocs, ocs_list_t *pend_list, ocs_lock_t *list_lock)
{
ocs_hal_sequence_t *frame;
for (;;) {
frame = ocs_frame_next(pend_list, list_lock);
if (frame == NULL) {
break;
}
frame_printf(ocs, (fc_header_t*) frame->header->dma.virt, "Discarding held frame\n");
if (frame->hio != NULL) {
ocs_port_owned_abort(ocs, frame->hio);
}
ocs_hal_sequence_free(&ocs->hal, frame);
}
return 0;
}
/**
* @ingroup unsol
* @brief Purge node's pending (queued) frames.
*
* <h3 class="desc">Description</h3>
* Frames that are queued for the \c node are discarded and returned
* to the RQ.
*
* @param node Node of the queued frames that are to be discarded.
*
* @return Returns 0 on success, or a negative error value on failure.
*/
int32_t
ocs_node_purge_pending(ocs_node_t *node)
{
return ocs_purge_pending(node->ocs, &node->pend_frames, &node->pend_frames_lock);
}
/**
* @ingroup unsol
* @brief Purge xport's pending (queued) frames.
*
* <h3 class="desc">Description</h3>
* Frames that are queued for the \c xport are discarded and
* returned to the RQ.
*
* @param domain Pointer to domain object.
*
* @return Returns 0 on success; or a negative error value on failure.
*/
int32_t
ocs_domain_purge_pending(ocs_domain_t *domain)
{
ocs_t *ocs = domain->ocs;
ocs_xport_fcfi_t *xport_fcfi;
ocs_assert(domain->fcf_indicator < SLI4_MAX_FCFI, -1);
xport_fcfi = &ocs->xport->fcfi[domain->fcf_indicator];
return ocs_purge_pending(domain->ocs,
&xport_fcfi->pend_frames,
&xport_fcfi->pend_frames_lock);
}
/**
* @ingroup unsol
* @brief Check if node's pending frames are held.
*
* @param arg Node for which the pending frame hold condition is
* checked.
*
* @return Returns 1 if node is holding pending frames, or 0
* if not.
*/
static uint8_t
ocs_node_frames_held(void *arg)
{
ocs_node_t *node = (ocs_node_t *)arg;
return node->hold_frames;
}
/**
* @ingroup unsol
* @brief Check if domain's pending frames are held.
*
* @param arg Domain for which the pending frame hold condition is
* checked.
*
* @return Returns 1 if domain is holding pending frames, or 0
* if not.
*/
static uint8_t
ocs_domain_frames_held(void *arg)
{
ocs_domain_t *domain = (ocs_domain_t *)arg;
ocs_t *ocs = domain->ocs;
ocs_xport_fcfi_t *xport_fcfi;
ocs_assert(domain != NULL, 1);
ocs_assert(domain->fcf_indicator < SLI4_MAX_FCFI, 1);
xport_fcfi = &ocs->xport->fcfi[domain->fcf_indicator];
return xport_fcfi->hold_frames;
}
/**
* @ingroup unsol
* @brief Globally (at xport level) hold unsolicited frames.
*
* <h3 class="desc">Description</h3>
* This function places a hold on processing unsolicited FC
* frames queued to the xport pending list.
*
* @param domain Pointer to domain object.
*
* @return Returns None.
*/
void
ocs_domain_hold_frames(ocs_domain_t *domain)
{
ocs_t *ocs = domain->ocs;
ocs_xport_fcfi_t *xport_fcfi;
ocs_assert(domain->fcf_indicator < SLI4_MAX_FCFI);
xport_fcfi = &ocs->xport->fcfi[domain->fcf_indicator];
if (!xport_fcfi->hold_frames) {
ocs_log_debug(domain->ocs, "%s: hold frames set for FCFI %d\n",
__func__, domain->fcf_indicator);
xport_fcfi->hold_frames = 1;
}
}
/**
* @ingroup unsol
* @brief Clear hold on unsolicited frames.
*
* <h3 class="desc">Description</h3>
* This function clears the hold on processing unsolicited FC
* frames queued to the domain pending list.
*
* @param domain Pointer to domain object.
*
* @return Returns None.
*/
void
ocs_domain_accept_frames(ocs_domain_t *domain)
{
ocs_t *ocs = domain->ocs;
ocs_xport_fcfi_t *xport_fcfi;
ocs_assert(domain->fcf_indicator < SLI4_MAX_FCFI);
xport_fcfi = &ocs->xport->fcfi[domain->fcf_indicator];
if (xport_fcfi->hold_frames == 1) {
ocs_log_debug(domain->ocs, "%s: hold frames cleared for FCFI %d\n",
__func__, domain->fcf_indicator);
}
xport_fcfi->hold_frames = 0;
ocs_domain_process_pending(domain);
}
/**
* @ingroup unsol
* @brief Dispatch unsolicited FC frame.
*
* <h3 class="desc">Description</h3>
* This function processes an unsolicited FC frame queued at the
* domain level.
*
* @param arg Pointer to ocs object.
* @param seq Header/payload sequence buffers.
*
* @return Returns 0 if frame processed and RX buffers cleaned
* up appropriately, -1 if frame not handled.
*/
static __inline int32_t
ocs_domain_dispatch_frame(void *arg, ocs_hal_sequence_t *seq)
{
ocs_domain_t *domain = (ocs_domain_t *)arg;
ocs_t *ocs = domain->ocs;
fc_header_t *hdr;
uint32_t s_id;
uint32_t d_id;
ocs_node_t *node = NULL;
ocs_sport_t *sport = NULL;
ocs_assert(seq->header, -1);
ocs_assert(seq->header->dma.virt, -1);
ocs_assert(seq->payload->dma.virt, -1);
hdr = seq->header->dma.virt;
/* extract the s_id and d_id */
s_id = fc_be24toh(hdr->s_id);
d_id = fc_be24toh(hdr->d_id);
sport = domain->sport;
if (sport == NULL) {
frame_printf(ocs, hdr, "phy sport for FC ID 0x%06x is NULL, dropping frame\n", d_id);
return -1;
}
if (sport->fc_id != d_id) {
/* Not a physical port IO lookup sport associated with the npiv port */
sport = ocs_sport_find(domain, d_id); /* Look up without lock */
if (sport == NULL) {
if (hdr->type == FC_TYPE_FCP) {
/* Drop frame */
ocs_log_warn(ocs, "%s: unsolicited FCP frame with invalid d_id x%x, dropping\n",
__func__, d_id);
return -1;
} else {
/* p2p will use this case */
sport = domain->sport;
}
}
}
/* Lookup the node given the remote s_id */
node = ocs_node_find(sport, s_id);
/* If not found, then create a new node */
if (node == NULL) {
/* If this is solicited data or control based on R_CTL and there is no node context,
* then we can drop the frame
*/
if ((hdr->r_ctl == FC_RCTL_FC4_DATA) && (
(hdr->info == FC_RCTL_INFO_SOL_DATA) || (hdr->info == FC_RCTL_INFO_SOL_CTRL))) {
ocs_log_debug(ocs, "%s: solicited data/ctrl frame without node, dropping\n", __func__);
return -1;
}
node = ocs_node_alloc(sport, s_id, FALSE, FALSE);
if (node == NULL) {
ocs_log_err(ocs, "%s(%d) ocs_node_alloc() failed\n", __func__, __LINE__);
return -1;
}
/* don't send PLOGI on ocs_d_init entry */
ocs_node_init_device(node, FALSE);
}
if (node->hold_frames || !ocs_list_empty((&node->pend_frames))) {
/* TODO: info log level
frame_printf(ocs, hdr, "Holding frame\n");
*/
/* add frame to node's pending list */
ocs_lock(&node->pend_frames_lock);
ocs_list_add_tail(&node->pend_frames, seq);
ocs_unlock(&node->pend_frames_lock);
return 0;
}
/* now dispatch frame to the node frame handler */
return ocs_node_dispatch_frame(node, seq);
}
/**
* @ingroup unsol
* @brief Dispatch a frame.
*
* <h3 class="desc">Description</h3>
* A frame is dispatched from the \c node to the handler.
*
* @param arg Node that originated the frame.
* @param seq Header/payload sequence buffers.
*
* @return Returns 0 if frame processed and RX buffers cleaned
* up appropriately, -1 if frame not handled.
*/
static int32_t
ocs_node_dispatch_frame(void *arg, ocs_hal_sequence_t *seq)
{
fc_header_t *hdr = seq->header->dma.virt;
uint32_t port_id;
ocs_node_t *node = (ocs_node_t *)arg;
int32_t rc = -1;
int32_t sit_set = 0;
port_id = fc_be24toh(hdr->s_id);
ocs_assert(port_id == node->rnode.fc_id, -1);
if (fc_be24toh(hdr->f_ctl) & FC_FCTL_END_SEQUENCE) {
/*if SIT is set */
if (fc_be24toh(hdr->f_ctl) & FC_FCTL_SEQUENCE_INITIATIVE) {
sit_set = 1;
}
switch (hdr->r_ctl) {
case FC_RCTL_ELS:
if (sit_set) {
rc = ocs_node_recv_els_frame(node, seq);
}
break;
case FC_RCTL_BLS:
if (sit_set) {
rc = ocs_node_recv_abts_frame(node, seq);
}else {
rc = ocs_node_recv_bls_no_sit(node, seq);
}
break;
case FC_RCTL_FC4_DATA:
switch(hdr->type) {
case FC_TYPE_FCP:
if (hdr->info == FC_RCTL_INFO_UNSOL_CMD) {
if (node->fcp_enabled) {
if (sit_set) {
rc = ocs_dispatch_fcp_cmd(node, seq);
}else {
/* send the auto xfer ready command */
rc = ocs_dispatch_fcp_cmd_auto_xfer_rdy(node, seq);
}
} else {
rc = ocs_node_recv_fcp_cmd(node, seq);
}
} else if (hdr->info == FC_RCTL_INFO_SOL_DATA) {
if (sit_set) {
rc = ocs_dispatch_fcp_data(node, seq);
}
}
break;
case FC_TYPE_GS:
if (sit_set) {
rc = ocs_node_recv_ct_frame(node, seq);
}
break;
default:
break;
}
break;
}
} else {
node_printf(node, "Dropping frame hdr = %08x %08x %08x %08x %08x %08x\n",
ocs_htobe32(((uint32_t *)hdr)[0]),
ocs_htobe32(((uint32_t *)hdr)[1]),
ocs_htobe32(((uint32_t *)hdr)[2]),
ocs_htobe32(((uint32_t *)hdr)[3]),
ocs_htobe32(((uint32_t *)hdr)[4]),
ocs_htobe32(((uint32_t *)hdr)[5]));
}
return rc;
}
/**
* @ingroup unsol
* @brief Dispatch unsolicited FCP frames (RQ Pair).
*
* <h3 class="desc">Description</h3>
* Dispatch unsolicited FCP frames (called from the device node state machine).
*
* @param io Pointer to the IO context.
* @param task_management_flags Task management flags from the FCP_CMND frame.
* @param node Node that originated the frame.
* @param lun 32-bit LUN from FCP_CMND frame.
*
* @return Returns None.
*/
static void
ocs_dispatch_unsolicited_tmf(ocs_io_t *io, uint8_t task_management_flags, ocs_node_t *node, uint32_t lun)
{
uint32_t i;
struct {
uint32_t mask;
ocs_scsi_tmf_cmd_e cmd;
} tmflist[] = {
{FCP_QUERY_TASK_SET, OCS_SCSI_TMF_QUERY_TASK_SET},
{FCP_ABORT_TASK_SET, OCS_SCSI_TMF_ABORT_TASK_SET},
{FCP_CLEAR_TASK_SET, OCS_SCSI_TMF_CLEAR_TASK_SET},
{FCP_QUERY_ASYNCHRONOUS_EVENT, OCS_SCSI_TMF_QUERY_ASYNCHRONOUS_EVENT},
{FCP_LOGICAL_UNIT_RESET, OCS_SCSI_TMF_LOGICAL_UNIT_RESET},
{FCP_TARGET_RESET, OCS_SCSI_TMF_TARGET_RESET},
{FCP_CLEAR_ACA, OCS_SCSI_TMF_CLEAR_ACA}};
io->exp_xfer_len = 0; /* BUG 32235 */
for (i = 0; i < ARRAY_SIZE(tmflist); i ++) {
if (tmflist[i].mask & task_management_flags) {
io->tmf_cmd = tmflist[i].cmd;
ocs_scsi_recv_tmf(io, lun, tmflist[i].cmd, NULL, 0);
break;
}
}
if (i == ARRAY_SIZE(tmflist)) {
/* Not handled */
node_printf(node, "TMF x%x rejected\n", task_management_flags);
ocs_scsi_send_tmf_resp(io, OCS_SCSI_TMF_FUNCTION_REJECTED, NULL, ocs_fc_tmf_rejected_cb, NULL);
}
}
static int32_t
ocs_validate_fcp_cmd(ocs_t *ocs, ocs_hal_sequence_t *seq)
{
size_t exp_payload_len = 0;
fcp_cmnd_iu_t *cmnd = seq->payload->dma.virt;
exp_payload_len = sizeof(fcp_cmnd_iu_t) - 16 + cmnd->additional_fcp_cdb_length;
/*
* If we received less than FCP_CMND_IU bytes, assume that the frame is
* corrupted in some way and drop it. This was seen when jamming the FCTL
* fill bytes field.
*/
if (seq->payload->dma.len < exp_payload_len) {
fc_header_t *fchdr = seq->header->dma.virt;
ocs_log_debug(ocs, "%s: dropping ox_id %04x with payload length (%zd) less than expected (%zd)\n",
__func__, ocs_be16toh(fchdr->ox_id), seq->payload->dma.len,
exp_payload_len);
return -1;
}
return 0;
}
static void
ocs_populate_io_fcp_cmd(ocs_io_t *io, fcp_cmnd_iu_t *cmnd, fc_header_t *fchdr, uint8_t sit)
{
uint32_t *fcp_dl;
io->init_task_tag = ocs_be16toh(fchdr->ox_id);
/* note, tgt_task_tag, hw_tag set when HAL io is allocated */
fcp_dl = (uint32_t*)(&(cmnd->fcp_cdb_and_dl));
fcp_dl += cmnd->additional_fcp_cdb_length;
io->exp_xfer_len = ocs_be32toh(*fcp_dl);
io->transferred = 0;
/* The upper 7 bits of CS_CTL is the frame priority thru the SAN.
* Our assertion here is, the priority given to a frame containing
* the FCP cmd should be the priority given to ALL frames contained
* in that IO. Thus we need to save the incoming CS_CTL here.
*/
if (fc_be24toh(fchdr->f_ctl) & FC_FCTL_PRIORITY_ENABLE) {
io->cs_ctl = fchdr->cs_ctl;
} else {
io->cs_ctl = 0;
}
io->seq_init = sit;
}
static uint32_t
ocs_get_flags_fcp_cmd(fcp_cmnd_iu_t *cmnd)
{
uint32_t flags = 0;
switch (cmnd->task_attribute) {
case FCP_TASK_ATTR_SIMPLE:
flags |= OCS_SCSI_CMD_SIMPLE;
break;
case FCP_TASK_ATTR_HEAD_OF_QUEUE:
flags |= OCS_SCSI_CMD_HEAD_OF_QUEUE;
break;
case FCP_TASK_ATTR_ORDERED:
flags |= OCS_SCSI_CMD_ORDERED;
break;
case FCP_TASK_ATTR_ACA:
flags |= OCS_SCSI_CMD_ACA;
break;
case FCP_TASK_ATTR_UNTAGGED:
flags |= OCS_SCSI_CMD_UNTAGGED;
break;
}
if (cmnd->wrdata)
flags |= OCS_SCSI_CMD_DIR_IN;
if (cmnd->rddata)
flags |= OCS_SCSI_CMD_DIR_OUT;
return flags;
}
/**
* @ingroup unsol
* @brief Dispatch unsolicited FCP_CMND frame.
*
* <h3 class="desc">Description</h3>
* Dispatch unsolicited FCP_CMND frame. RQ Pair mode - always
* used for RQ Pair mode since first burst is not supported.
*
* @param node Node that originated the frame.
* @param seq Header/payload sequence buffers.
*
* @return Returns 0 if frame processed and RX buffers cleaned
* up appropriately, -1 if frame not handled and RX buffers need
* to be returned.
*/
static int32_t
ocs_dispatch_fcp_cmd(ocs_node_t *node, ocs_hal_sequence_t *seq)
{
ocs_t *ocs = node->ocs;
fc_header_t *fchdr = seq->header->dma.virt;
fcp_cmnd_iu_t *cmnd = NULL;
ocs_io_t *io = NULL;
uint32_t lun = UINT32_MAX;
int32_t rc = 0;
ocs_assert(seq->payload, -1);
cmnd = seq->payload->dma.virt;
/* perform FCP_CMND validation check(s) */
if (ocs_validate_fcp_cmd(ocs, seq)) {
return -1;
}
lun = ocs_fc_decode_lun(cmnd->fcp_lun);
if (lun == UINT32_MAX) {
return -1;
}
io = ocs_scsi_io_alloc(node, OCS_SCSI_IO_ROLE_RESPONDER);
if (io == NULL) {
uint32_t send_frame_capable;
/* If we have SEND_FRAME capability, then use it to send task set full or busy */
rc = ocs_hal_get(&ocs->hal, OCS_HAL_SEND_FRAME_CAPABLE, &send_frame_capable);
if ((rc == 0) && send_frame_capable) {
rc = ocs_sframe_send_task_set_full_or_busy(node, seq);
if (rc) {
ocs_log_test(ocs, "%s: ocs_sframe_send_task_set_full_or_busy failed: %d\n", __func__, rc);
}
return rc;
}
ocs_log_err(ocs, "%s: IO allocation failed ox_id %04x\n", __func__, ocs_be16toh(fchdr->ox_id));
return -1;
}
io->hal_priv = seq->hal_priv;
/* RQ pair, if we got here, SIT=1 */
ocs_populate_io_fcp_cmd(io, cmnd, fchdr, TRUE);
if (cmnd->task_management_flags) {
ocs_dispatch_unsolicited_tmf(io, cmnd->task_management_flags, node, lun);
} else {
uint32_t flags = ocs_get_flags_fcp_cmd(cmnd);
/* can return failure for things like task set full and UAs,
* no need to treat as a dropped frame if rc != 0
*/
ocs_scsi_recv_cmd(io, lun, cmnd->fcp_cdb,
sizeof(cmnd->fcp_cdb) +
(cmnd->additional_fcp_cdb_length * sizeof(uint32_t)),
flags);
}
/* successfully processed, now return RX buffer to the chip */
ocs_hal_sequence_free(&ocs->hal, seq);
return 0;
}
/**
* @ingroup unsol
* @brief Dispatch unsolicited FCP_CMND frame (auto xfer rdy).
*
* <h3 class="desc">Description</h3>
* Dispatch unsolicited FCP_CMND frame that is assisted with auto xfer ready.
*
* @param node Node that originated the frame.
* @param seq Header/payload sequence buffers.
*
* @return Returns 0 if frame processed and RX buffers cleaned
* up appropriately, -1 if frame not handled and RX buffers need
* to be returned.
*/
static int32_t
ocs_dispatch_fcp_cmd_auto_xfer_rdy(ocs_node_t *node, ocs_hal_sequence_t *seq)
{
ocs_t *ocs = node->ocs;
fc_header_t *fchdr = seq->header->dma.virt;
fcp_cmnd_iu_t *cmnd = NULL;
ocs_io_t *io = NULL;
uint32_t lun = UINT32_MAX;
int32_t rc = 0;
ocs_assert(seq->payload, -1);
cmnd = seq->payload->dma.virt;
/* perform FCP_CMND validation check(s) */
if (ocs_validate_fcp_cmd(ocs, seq)) {
return -1;
}
/* make sure first burst or auto xfer_rdy is enabled */
if (!seq->auto_xrdy) {
node_printf(node, "IO is not Auto Xfr Rdy assisted, dropping FCP_CMND\n");
return -1;
}
lun = ocs_fc_decode_lun(cmnd->fcp_lun);
// TODO should there be a check here for an error? Why do any of the
// below if the LUN decode failed?
io = ocs_scsi_io_alloc(node, OCS_SCSI_IO_ROLE_RESPONDER);
if (io == NULL) {
uint32_t send_frame_capable;
/* If we have SEND_FRAME capability, then use it to send task set full or busy */
rc = ocs_hal_get(&ocs->hal, OCS_HAL_SEND_FRAME_CAPABLE, &send_frame_capable);
if ((rc == 0) && send_frame_capable) {
rc = ocs_sframe_send_task_set_full_or_busy(node, seq);
if (rc) {