-
Notifications
You must be signed in to change notification settings - Fork 102
/
qla_target.c
7475 lines (6407 loc) · 200 KB
/
qla_target.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
// SPDX-License-Identifier: GPL-2.0-only
/*
* qla_target.c SCSI LLD infrastructure for QLogic 22xx/23xx/24xx/25xx
*
* based on qla2x00t.c code:
*
* Copyright (C) 2004 - 2010 Vladislav Bolkhovitin <vst@vlnb.net>
* Copyright (C) 2004 - 2005 Leonid Stoljar
* Copyright (C) 2006 Nathaniel Clark <nate@misrule.us>
* Copyright (C) 2006 - 2010 ID7 Ltd.
*
* Forward port and refactoring to modern qla2xxx and target/configfs
*
* Copyright (C) 2010-2013 Nicholas A. Bellinger <nab@kernel.org>
*/
#include <linux/module.h>
#include <linux/init.h>
#include <linux/types.h>
#include <linux/blkdev.h>
#include <linux/interrupt.h>
#include <linux/pci.h>
#include <linux/delay.h>
#include <linux/list.h>
#include <linux/workqueue.h>
#include <asm/unaligned.h>
#include <scsi/scsi.h>
#include <scsi/scsi_host.h>
#include <scsi/scsi_tcq.h>
#include "qla_def.h"
#include "qla_target.h"
static int ql2xtgt_tape_enable;
module_param(ql2xtgt_tape_enable, int, S_IRUGO|S_IWUSR);
MODULE_PARM_DESC(ql2xtgt_tape_enable,
"Enables Sequence level error recovery (aka FC Tape). Default is 0 - no SLER. 1 - Enable SLER.");
static char *qlini_mode = QLA2XXX_INI_MODE_STR_ENABLED;
module_param(qlini_mode, charp, S_IRUGO);
MODULE_PARM_DESC(qlini_mode,
"Determines when initiator mode will be enabled. Possible values: "
"\"exclusive\" - initiator mode will be enabled on load, "
"disabled on enabling target mode and then on disabling target mode "
"enabled back; "
"\"disabled\" - initiator mode will never be enabled; "
"\"dual\" - Initiator Modes will be enabled. Target Mode can be activated "
"when ready "
"\"enabled\" (default) - initiator mode will always stay enabled.");
int ql2xuctrlirq = 1;
module_param(ql2xuctrlirq, int, 0644);
MODULE_PARM_DESC(ql2xuctrlirq,
"User to control IRQ placement via smp_affinity."
"Valid with qlini_mode=disabled."
"1(default): enable");
int ql2x_ini_mode = QLA2XXX_INI_MODE_EXCLUSIVE;
static int qla_sam_status = SAM_STAT_BUSY;
static int tc_sam_status = SAM_STAT_TASK_SET_FULL; /* target core */
/*
* From scsi/fc/fc_fcp.h
*/
enum fcp_resp_rsp_codes {
FCP_TMF_CMPL = 0,
FCP_DATA_LEN_INVALID = 1,
FCP_CMND_FIELDS_INVALID = 2,
FCP_DATA_PARAM_MISMATCH = 3,
FCP_TMF_REJECTED = 4,
FCP_TMF_FAILED = 5,
FCP_TMF_INVALID_LUN = 9,
};
/*
* fc_pri_ta from scsi/fc/fc_fcp.h
*/
#define FCP_PTA_SIMPLE 0 /* simple task attribute */
#define FCP_PTA_HEADQ 1 /* head of queue task attribute */
#define FCP_PTA_ORDERED 2 /* ordered task attribute */
#define FCP_PTA_ACA 4 /* auto. contingent allegiance */
#define FCP_PTA_MASK 7 /* mask for task attribute field */
#define FCP_PRI_SHIFT 3 /* priority field starts in bit 3 */
#define FCP_PRI_RESVD_MASK 0x80 /* reserved bits in priority field */
/*
* This driver calls qla2x00_alloc_iocbs() and qla2x00_issue_marker(), which
* must be called under HW lock and could unlock/lock it inside.
* It isn't an issue, since in the current implementation on the time when
* those functions are called:
*
* - Either context is IRQ and only IRQ handler can modify HW data,
* including rings related fields,
*
* - Or access to target mode variables from struct qla_tgt doesn't
* cross those functions boundaries, except tgt_stop, which
* additionally protected by irq_cmd_count.
*/
/* Predefs for callbacks handed to qla2xxx LLD */
static void qlt_24xx_atio_pkt(struct scsi_qla_host *ha,
struct atio_from_isp *pkt, uint8_t);
static void qlt_response_pkt(struct scsi_qla_host *ha, struct rsp_que *rsp,
response_t *pkt);
static int qlt_issue_task_mgmt(struct fc_port *sess, u64 lun,
int fn, void *iocb, int flags);
static void qlt_send_term_exchange(struct qla_qpair *, struct qla_tgt_cmd
*cmd, struct atio_from_isp *atio, int ha_locked, int ul_abort);
static void qlt_alloc_qfull_cmd(struct scsi_qla_host *vha,
struct atio_from_isp *atio, uint16_t status, int qfull);
static void qlt_disable_vha(struct scsi_qla_host *vha);
static void qlt_clear_tgt_db(struct qla_tgt *tgt);
static void qlt_send_notify_ack(struct qla_qpair *qpair,
struct imm_ntfy_from_isp *ntfy,
uint32_t add_flags, uint16_t resp_code, int resp_code_valid,
uint16_t srr_flags, uint16_t srr_reject_code, uint8_t srr_explan);
static void qlt_send_term_imm_notif(struct scsi_qla_host *vha,
struct imm_ntfy_from_isp *imm, int ha_locked);
static struct fc_port *qlt_create_sess(struct scsi_qla_host *vha,
fc_port_t *fcport, bool local);
void qlt_unreg_sess(struct fc_port *sess);
static void qlt_24xx_handle_abts(struct scsi_qla_host *,
struct abts_recv_from_24xx *);
static void qlt_send_busy(struct qla_qpair *, struct atio_from_isp *,
uint16_t);
static int qlt_check_reserve_free_req(struct qla_qpair *qpair, uint32_t);
static inline uint32_t qlt_make_handle(struct qla_qpair *);
/*
* Global Variables
*/
static struct kmem_cache *qla_tgt_mgmt_cmd_cachep;
struct kmem_cache *qla_tgt_plogi_cachep;
static mempool_t *qla_tgt_mgmt_cmd_mempool;
static struct workqueue_struct *qla_tgt_wq;
static DEFINE_MUTEX(qla_tgt_mutex);
static LIST_HEAD(qla_tgt_glist);
static const char *prot_op_str(u32 prot_op)
{
switch (prot_op) {
case TARGET_PROT_NORMAL: return "NORMAL";
case TARGET_PROT_DIN_INSERT: return "DIN_INSERT";
case TARGET_PROT_DOUT_INSERT: return "DOUT_INSERT";
case TARGET_PROT_DIN_STRIP: return "DIN_STRIP";
case TARGET_PROT_DOUT_STRIP: return "DOUT_STRIP";
case TARGET_PROT_DIN_PASS: return "DIN_PASS";
case TARGET_PROT_DOUT_PASS: return "DOUT_PASS";
default: return "UNKNOWN";
}
}
/* This API intentionally takes dest as a parameter, rather than returning
* int value to avoid caller forgetting to issue wmb() after the store */
void qlt_do_generation_tick(struct scsi_qla_host *vha, int *dest)
{
scsi_qla_host_t *base_vha = pci_get_drvdata(vha->hw->pdev);
*dest = atomic_inc_return(&base_vha->generation_tick);
/* memory barrier */
wmb();
}
/* Might release hw lock, then reaquire!! */
static inline int qlt_issue_marker(struct scsi_qla_host *vha, int vha_locked)
{
/* Send marker if required */
if (unlikely(vha->marker_needed != 0)) {
int rc = qla2x00_issue_marker(vha, vha_locked);
if (rc != QLA_SUCCESS) {
ql_dbg(ql_dbg_tgt, vha, 0xe03d,
"qla_target(%d): issue_marker() failed\n",
vha->vp_idx);
}
return rc;
}
return QLA_SUCCESS;
}
struct scsi_qla_host *qla_find_host_by_d_id(struct scsi_qla_host *vha,
be_id_t d_id)
{
struct scsi_qla_host *host;
uint32_t key;
if (vha->d_id.b.area == d_id.area &&
vha->d_id.b.domain == d_id.domain &&
vha->d_id.b.al_pa == d_id.al_pa)
return vha;
key = be_to_port_id(d_id).b24;
host = btree_lookup32(&vha->hw->host_map, key);
if (!host)
ql_dbg(ql_dbg_tgt_mgt + ql_dbg_verbose, vha, 0xf005,
"Unable to find host %06x\n", key);
return host;
}
static inline
struct scsi_qla_host *qlt_find_host_by_vp_idx(struct scsi_qla_host *vha,
uint16_t vp_idx)
{
struct qla_hw_data *ha = vha->hw;
if (vha->vp_idx == vp_idx)
return vha;
BUG_ON(ha->tgt.tgt_vp_map == NULL);
if (likely(test_bit(vp_idx, ha->vp_idx_map)))
return ha->tgt.tgt_vp_map[vp_idx].vha;
return NULL;
}
static inline void qlt_incr_num_pend_cmds(struct scsi_qla_host *vha)
{
unsigned long flags;
spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags);
vha->hw->tgt.num_pend_cmds++;
if (vha->hw->tgt.num_pend_cmds > vha->qla_stats.stat_max_pend_cmds)
vha->qla_stats.stat_max_pend_cmds =
vha->hw->tgt.num_pend_cmds;
spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags);
}
static inline void qlt_decr_num_pend_cmds(struct scsi_qla_host *vha)
{
unsigned long flags;
spin_lock_irqsave(&vha->hw->tgt.q_full_lock, flags);
vha->hw->tgt.num_pend_cmds--;
spin_unlock_irqrestore(&vha->hw->tgt.q_full_lock, flags);
}
static void qlt_queue_unknown_atio(scsi_qla_host_t *vha,
struct atio_from_isp *atio, uint8_t ha_locked)
{
struct qla_tgt_sess_op *u;
struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
unsigned long flags;
if (tgt->tgt_stop) {
ql_dbg(ql_dbg_async, vha, 0x502c,
"qla_target(%d): dropping unknown ATIO_TYPE7, because tgt is being stopped",
vha->vp_idx);
goto out_term;
}
u = kzalloc(sizeof(*u), GFP_ATOMIC);
if (u == NULL)
goto out_term;
u->vha = vha;
memcpy(&u->atio, atio, sizeof(*atio));
INIT_LIST_HEAD(&u->cmd_list);
spin_lock_irqsave(&vha->cmd_list_lock, flags);
list_add_tail(&u->cmd_list, &vha->unknown_atio_list);
spin_unlock_irqrestore(&vha->cmd_list_lock, flags);
schedule_delayed_work(&vha->unknown_atio_work, 1);
out:
return;
out_term:
qlt_send_term_exchange(vha->hw->base_qpair, NULL, atio, ha_locked, 0);
goto out;
}
static void qlt_try_to_dequeue_unknown_atios(struct scsi_qla_host *vha,
uint8_t ha_locked)
{
struct qla_tgt_sess_op *u, *t;
scsi_qla_host_t *host;
struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
unsigned long flags;
uint8_t queued = 0;
list_for_each_entry_safe(u, t, &vha->unknown_atio_list, cmd_list) {
if (u->aborted) {
ql_dbg(ql_dbg_async, vha, 0x502e,
"Freeing unknown %s %p, because of Abort\n",
"ATIO_TYPE7", u);
qlt_send_term_exchange(vha->hw->base_qpair, NULL,
&u->atio, ha_locked, 0);
goto abort;
}
host = qla_find_host_by_d_id(vha, u->atio.u.isp24.fcp_hdr.d_id);
if (host != NULL) {
ql_dbg(ql_dbg_async + ql_dbg_verbose, vha, 0x502f,
"Requeuing unknown ATIO_TYPE7 %p\n", u);
qlt_24xx_atio_pkt(host, &u->atio, ha_locked);
} else if (tgt->tgt_stop) {
ql_dbg(ql_dbg_async + ql_dbg_verbose, vha, 0x503a,
"Freeing unknown %s %p, because tgt is being stopped\n",
"ATIO_TYPE7", u);
qlt_send_term_exchange(vha->hw->base_qpair, NULL,
&u->atio, ha_locked, 0);
} else {
ql_dbg(ql_dbg_async + ql_dbg_verbose, vha, 0x503d,
"Reschedule u %p, vha %p, host %p\n", u, vha, host);
if (!queued) {
queued = 1;
schedule_delayed_work(&vha->unknown_atio_work,
1);
}
continue;
}
abort:
spin_lock_irqsave(&vha->cmd_list_lock, flags);
list_del(&u->cmd_list);
spin_unlock_irqrestore(&vha->cmd_list_lock, flags);
kfree(u);
}
}
void qlt_unknown_atio_work_fn(struct work_struct *work)
{
struct scsi_qla_host *vha = container_of(to_delayed_work(work),
struct scsi_qla_host, unknown_atio_work);
qlt_try_to_dequeue_unknown_atios(vha, 0);
}
static bool qlt_24xx_atio_pkt_all_vps(struct scsi_qla_host *vha,
struct atio_from_isp *atio, uint8_t ha_locked)
{
ql_dbg(ql_dbg_tgt, vha, 0xe072,
"%s: qla_target(%d): type %x ox_id %04x\n",
__func__, vha->vp_idx, atio->u.raw.entry_type,
be16_to_cpu(atio->u.isp24.fcp_hdr.ox_id));
switch (atio->u.raw.entry_type) {
case ATIO_TYPE7:
{
struct scsi_qla_host *host = qla_find_host_by_d_id(vha,
atio->u.isp24.fcp_hdr.d_id);
if (unlikely(NULL == host)) {
ql_dbg(ql_dbg_tgt, vha, 0xe03e,
"qla_target(%d): Received ATIO_TYPE7 "
"with unknown d_id %x:%x:%x\n", vha->vp_idx,
atio->u.isp24.fcp_hdr.d_id.domain,
atio->u.isp24.fcp_hdr.d_id.area,
atio->u.isp24.fcp_hdr.d_id.al_pa);
qlt_queue_unknown_atio(vha, atio, ha_locked);
break;
}
if (unlikely(!list_empty(&vha->unknown_atio_list)))
qlt_try_to_dequeue_unknown_atios(vha, ha_locked);
qlt_24xx_atio_pkt(host, atio, ha_locked);
break;
}
case IMMED_NOTIFY_TYPE:
{
struct scsi_qla_host *host = vha;
struct imm_ntfy_from_isp *entry =
(struct imm_ntfy_from_isp *)atio;
qlt_issue_marker(vha, ha_locked);
if ((entry->u.isp24.vp_index != 0xFF) &&
(entry->u.isp24.nport_handle != cpu_to_le16(0xFFFF))) {
host = qlt_find_host_by_vp_idx(vha,
entry->u.isp24.vp_index);
if (unlikely(!host)) {
ql_dbg(ql_dbg_tgt, vha, 0xe03f,
"qla_target(%d): Received "
"ATIO (IMMED_NOTIFY_TYPE) "
"with unknown vp_index %d\n",
vha->vp_idx, entry->u.isp24.vp_index);
break;
}
}
qlt_24xx_atio_pkt(host, atio, ha_locked);
break;
}
case VP_RPT_ID_IOCB_TYPE:
qla24xx_report_id_acquisition(vha,
(struct vp_rpt_id_entry_24xx *)atio);
break;
case ABTS_RECV_24XX:
{
struct abts_recv_from_24xx *entry =
(struct abts_recv_from_24xx *)atio;
struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha,
entry->vp_index);
unsigned long flags;
if (unlikely(!host)) {
ql_dbg(ql_dbg_tgt, vha, 0xe00a,
"qla_target(%d): Response pkt (ABTS_RECV_24XX) "
"received, with unknown vp_index %d\n",
vha->vp_idx, entry->vp_index);
break;
}
if (!ha_locked)
spin_lock_irqsave(&host->hw->hardware_lock, flags);
qlt_24xx_handle_abts(host, (struct abts_recv_from_24xx *)atio);
if (!ha_locked)
spin_unlock_irqrestore(&host->hw->hardware_lock, flags);
break;
}
/* case PUREX_IOCB_TYPE: ql2xmvasynctoatio */
default:
ql_dbg(ql_dbg_tgt, vha, 0xe040,
"qla_target(%d): Received unknown ATIO atio "
"type %x\n", vha->vp_idx, atio->u.raw.entry_type);
break;
}
return false;
}
void qlt_response_pkt_all_vps(struct scsi_qla_host *vha,
struct rsp_que *rsp, response_t *pkt)
{
switch (pkt->entry_type) {
case CTIO_CRC2:
ql_dbg(ql_dbg_tgt, vha, 0xe073,
"qla_target(%d):%s: CRC2 Response pkt\n",
vha->vp_idx, __func__);
fallthrough;
case CTIO_TYPE7:
{
struct ctio7_from_24xx *entry = (struct ctio7_from_24xx *)pkt;
struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha,
entry->vp_index);
if (unlikely(!host)) {
ql_dbg(ql_dbg_tgt, vha, 0xe041,
"qla_target(%d): Response pkt (CTIO_TYPE7) "
"received, with unknown vp_index %d\n",
vha->vp_idx, entry->vp_index);
break;
}
qlt_response_pkt(host, rsp, pkt);
break;
}
case IMMED_NOTIFY_TYPE:
{
struct scsi_qla_host *host;
struct imm_ntfy_from_isp *entry =
(struct imm_ntfy_from_isp *)pkt;
host = qlt_find_host_by_vp_idx(vha, entry->u.isp24.vp_index);
if (unlikely(!host)) {
ql_dbg(ql_dbg_tgt, vha, 0xe042,
"qla_target(%d): Response pkt (IMMED_NOTIFY_TYPE) "
"received, with unknown vp_index %d\n",
vha->vp_idx, entry->u.isp24.vp_index);
break;
}
qlt_response_pkt(host, rsp, pkt);
break;
}
case NOTIFY_ACK_TYPE:
{
struct scsi_qla_host *host = vha;
struct nack_to_isp *entry = (struct nack_to_isp *)pkt;
if (0xFF != entry->u.isp24.vp_index) {
host = qlt_find_host_by_vp_idx(vha,
entry->u.isp24.vp_index);
if (unlikely(!host)) {
ql_dbg(ql_dbg_tgt, vha, 0xe043,
"qla_target(%d): Response "
"pkt (NOTIFY_ACK_TYPE) "
"received, with unknown "
"vp_index %d\n", vha->vp_idx,
entry->u.isp24.vp_index);
break;
}
}
qlt_response_pkt(host, rsp, pkt);
break;
}
case ABTS_RECV_24XX:
{
struct abts_recv_from_24xx *entry =
(struct abts_recv_from_24xx *)pkt;
struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha,
entry->vp_index);
if (unlikely(!host)) {
ql_dbg(ql_dbg_tgt, vha, 0xe044,
"qla_target(%d): Response pkt "
"(ABTS_RECV_24XX) received, with unknown "
"vp_index %d\n", vha->vp_idx, entry->vp_index);
break;
}
qlt_response_pkt(host, rsp, pkt);
break;
}
case ABTS_RESP_24XX:
{
struct abts_resp_to_24xx *entry =
(struct abts_resp_to_24xx *)pkt;
struct scsi_qla_host *host = qlt_find_host_by_vp_idx(vha,
entry->vp_index);
if (unlikely(!host)) {
ql_dbg(ql_dbg_tgt, vha, 0xe045,
"qla_target(%d): Response pkt "
"(ABTS_RECV_24XX) received, with unknown "
"vp_index %d\n", vha->vp_idx, entry->vp_index);
break;
}
qlt_response_pkt(host, rsp, pkt);
break;
}
default:
qlt_response_pkt(vha, rsp, pkt);
break;
}
}
/*
* All qlt_plogi_ack_t operations are protected by hardware_lock
*/
static int qla24xx_post_nack_work(struct scsi_qla_host *vha, fc_port_t *fcport,
struct imm_ntfy_from_isp *ntfy, int type)
{
struct qla_work_evt *e;
e = qla2x00_alloc_work(vha, QLA_EVT_NACK);
if (!e)
return QLA_FUNCTION_FAILED;
e->u.nack.fcport = fcport;
e->u.nack.type = type;
memcpy(e->u.nack.iocb, ntfy, sizeof(struct imm_ntfy_from_isp));
return qla2x00_post_work(vha, e);
}
static void qla2x00_async_nack_sp_done(srb_t *sp, int res)
{
struct scsi_qla_host *vha = sp->vha;
unsigned long flags;
ql_dbg(ql_dbg_disc, vha, 0x20f2,
"Async done-%s res %x %8phC type %d\n",
sp->name, res, sp->fcport->port_name, sp->type);
spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
sp->fcport->flags &= ~FCF_ASYNC_SENT;
sp->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
switch (sp->type) {
case SRB_NACK_PLOGI:
sp->fcport->login_gen++;
sp->fcport->fw_login_state = DSC_LS_PLOGI_COMP;
sp->fcport->logout_on_delete = 1;
sp->fcport->plogi_nack_done_deadline = jiffies + HZ;
sp->fcport->send_els_logo = 0;
if (sp->fcport->flags & FCF_FCSP_DEVICE) {
ql_dbg(ql_dbg_edif, vha, 0x20ef,
"%s %8phC edif: PLOGI- AUTH WAIT\n", __func__,
sp->fcport->port_name);
qla2x00_set_fcport_disc_state(sp->fcport,
DSC_LOGIN_AUTH_PEND);
qla2x00_post_aen_work(vha, FCH_EVT_PORT_ONLINE,
sp->fcport->d_id.b24);
qla_edb_eventcreate(vha, VND_CMD_AUTH_STATE_NEEDED, sp->fcport->d_id.b24,
0, sp->fcport);
}
break;
case SRB_NACK_PRLI:
sp->fcport->fw_login_state = DSC_LS_PRLI_COMP;
sp->fcport->deleted = 0;
sp->fcport->send_els_logo = 0;
if (!sp->fcport->login_succ &&
!IS_SW_RESV_ADDR(sp->fcport->d_id)) {
sp->fcport->login_succ = 1;
vha->fcport_count++;
spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
qla24xx_sched_upd_fcport(sp->fcport);
spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
} else {
sp->fcport->login_retry = 0;
qla2x00_set_fcport_disc_state(sp->fcport,
DSC_LOGIN_COMPLETE);
sp->fcport->deleted = 0;
sp->fcport->logout_on_delete = 1;
}
break;
case SRB_NACK_LOGO:
sp->fcport->login_gen++;
sp->fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
qlt_logo_completion_handler(sp->fcport, MBS_COMMAND_COMPLETE);
break;
}
spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
kref_put(&sp->cmd_kref, qla2x00_sp_release);
}
int qla24xx_async_notify_ack(scsi_qla_host_t *vha, fc_port_t *fcport,
struct imm_ntfy_from_isp *ntfy, int type)
{
int rval = QLA_FUNCTION_FAILED;
srb_t *sp;
char *c = NULL;
fcport->flags |= FCF_ASYNC_SENT;
switch (type) {
case SRB_NACK_PLOGI:
fcport->fw_login_state = DSC_LS_PLOGI_PEND;
c = "PLOGI";
if (vha->hw->flags.edif_enabled &&
(le16_to_cpu(ntfy->u.isp24.flags) & NOTIFY24XX_FLAGS_FCSP))
fcport->flags |= FCF_FCSP_DEVICE;
break;
case SRB_NACK_PRLI:
fcport->fw_login_state = DSC_LS_PRLI_PEND;
fcport->deleted = 0;
c = "PRLI";
break;
case SRB_NACK_LOGO:
fcport->fw_login_state = DSC_LS_LOGO_PEND;
c = "LOGO";
break;
}
sp = qla2x00_get_sp(vha, fcport, GFP_ATOMIC);
if (!sp)
goto done;
sp->type = type;
sp->name = "nack";
qla2x00_init_async_sp(sp, qla2x00_get_async_timeout(vha) + 2,
qla2x00_async_nack_sp_done);
sp->u.iocb_cmd.u.nack.ntfy = ntfy;
ql_dbg(ql_dbg_disc, vha, 0x20f4,
"Async-%s %8phC hndl %x %s\n",
sp->name, fcport->port_name, sp->handle, c);
rval = qla2x00_start_sp(sp);
if (rval != QLA_SUCCESS)
goto done_free_sp;
return rval;
done_free_sp:
kref_put(&sp->cmd_kref, qla2x00_sp_release);
done:
fcport->flags &= ~FCF_ASYNC_SENT;
return rval;
}
void qla24xx_do_nack_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
{
fc_port_t *t;
switch (e->u.nack.type) {
case SRB_NACK_PRLI:
t = e->u.nack.fcport;
flush_work(&t->del_work);
flush_work(&t->free_work);
mutex_lock(&vha->vha_tgt.tgt_mutex);
t = qlt_create_sess(vha, e->u.nack.fcport, 0);
mutex_unlock(&vha->vha_tgt.tgt_mutex);
if (t) {
ql_log(ql_log_info, vha, 0xd034,
"%s create sess success %p", __func__, t);
/* create sess has an extra kref */
vha->hw->tgt.tgt_ops->put_sess(e->u.nack.fcport);
}
break;
}
qla24xx_async_notify_ack(vha, e->u.nack.fcport,
(struct imm_ntfy_from_isp *)e->u.nack.iocb, e->u.nack.type);
}
void qla24xx_delete_sess_fn(struct work_struct *work)
{
fc_port_t *fcport = container_of(work, struct fc_port, del_work);
struct qla_hw_data *ha = NULL;
if (!fcport || !fcport->vha || !fcport->vha->hw)
return;
ha = fcport->vha->hw;
if (fcport->se_sess) {
ha->tgt.tgt_ops->shutdown_sess(fcport);
ha->tgt.tgt_ops->put_sess(fcport);
} else {
qlt_unreg_sess(fcport);
}
}
/*
* Called from qla2x00_reg_remote_port()
*/
void qlt_fc_port_added(struct scsi_qla_host *vha, fc_port_t *fcport)
{
struct qla_hw_data *ha = vha->hw;
struct qla_tgt *tgt = vha->vha_tgt.qla_tgt;
struct fc_port *sess = fcport;
unsigned long flags;
if (!vha->hw->tgt.tgt_ops)
return;
spin_lock_irqsave(&ha->tgt.sess_lock, flags);
if (tgt->tgt_stop) {
spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
return;
}
if (fcport->disc_state == DSC_DELETE_PEND) {
spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
return;
}
if (!sess->se_sess) {
spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
mutex_lock(&vha->vha_tgt.tgt_mutex);
sess = qlt_create_sess(vha, fcport, false);
mutex_unlock(&vha->vha_tgt.tgt_mutex);
spin_lock_irqsave(&ha->tgt.sess_lock, flags);
} else {
if (fcport->fw_login_state == DSC_LS_PRLI_COMP) {
spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
return;
}
if (!kref_get_unless_zero(&sess->sess_kref)) {
ql_dbg(ql_dbg_disc, vha, 0x2107,
"%s: kref_get fail sess %8phC \n",
__func__, sess->port_name);
spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
return;
}
ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04c,
"qla_target(%u): %ssession for port %8phC "
"(loop ID %d) reappeared\n", vha->vp_idx,
sess->local ? "local " : "", sess->port_name, sess->loop_id);
ql_dbg(ql_dbg_tgt_mgt, vha, 0xf007,
"Reappeared sess %p\n", sess);
ha->tgt.tgt_ops->update_sess(sess, fcport->d_id,
fcport->loop_id,
(fcport->flags & FCF_CONF_COMP_SUPPORTED));
}
if (sess && sess->local) {
ql_dbg(ql_dbg_tgt_mgt, vha, 0xf04d,
"qla_target(%u): local session for "
"port %8phC (loop ID %d) became global\n", vha->vp_idx,
fcport->port_name, sess->loop_id);
sess->local = 0;
}
spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
ha->tgt.tgt_ops->put_sess(sess);
}
/*
* This is a zero-base ref-counting solution, since hardware_lock
* guarantees that ref_count is not modified concurrently.
* Upon successful return content of iocb is undefined
*/
static struct qlt_plogi_ack_t *
qlt_plogi_ack_find_add(struct scsi_qla_host *vha, port_id_t *id,
struct imm_ntfy_from_isp *iocb)
{
struct qlt_plogi_ack_t *pla;
lockdep_assert_held(&vha->hw->hardware_lock);
list_for_each_entry(pla, &vha->plogi_ack_list, list) {
if (pla->id.b24 == id->b24) {
ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0x210d,
"%s %d %8phC Term INOT due to new INOT",
__func__, __LINE__,
pla->iocb.u.isp24.port_name);
qlt_send_term_imm_notif(vha, &pla->iocb, 1);
memcpy(&pla->iocb, iocb, sizeof(pla->iocb));
return pla;
}
}
pla = kmem_cache_zalloc(qla_tgt_plogi_cachep, GFP_ATOMIC);
if (!pla) {
ql_dbg(ql_dbg_async, vha, 0x5088,
"qla_target(%d): Allocation of plogi_ack failed\n",
vha->vp_idx);
return NULL;
}
memcpy(&pla->iocb, iocb, sizeof(pla->iocb));
pla->id = *id;
list_add_tail(&pla->list, &vha->plogi_ack_list);
return pla;
}
void qlt_plogi_ack_unref(struct scsi_qla_host *vha,
struct qlt_plogi_ack_t *pla)
{
struct imm_ntfy_from_isp *iocb = &pla->iocb;
port_id_t port_id;
uint16_t loop_id;
fc_port_t *fcport = pla->fcport;
BUG_ON(!pla->ref_count);
pla->ref_count--;
if (pla->ref_count)
return;
ql_dbg(ql_dbg_disc, vha, 0x5089,
"Sending PLOGI ACK to wwn %8phC s_id %02x:%02x:%02x loop_id %#04x"
" exch %#x ox_id %#x\n", iocb->u.isp24.port_name,
iocb->u.isp24.port_id[2], iocb->u.isp24.port_id[1],
iocb->u.isp24.port_id[0],
le16_to_cpu(iocb->u.isp24.nport_handle),
iocb->u.isp24.exchange_address, iocb->ox_id);
port_id.b.domain = iocb->u.isp24.port_id[2];
port_id.b.area = iocb->u.isp24.port_id[1];
port_id.b.al_pa = iocb->u.isp24.port_id[0];
port_id.b.rsvd_1 = 0;
loop_id = le16_to_cpu(iocb->u.isp24.nport_handle);
fcport->loop_id = loop_id;
fcport->d_id = port_id;
if (iocb->u.isp24.status_subcode == ELS_PLOGI)
qla24xx_post_nack_work(vha, fcport, iocb, SRB_NACK_PLOGI);
else
qla24xx_post_nack_work(vha, fcport, iocb, SRB_NACK_PRLI);
list_for_each_entry(fcport, &vha->vp_fcports, list) {
if (fcport->plogi_link[QLT_PLOGI_LINK_SAME_WWN] == pla)
fcport->plogi_link[QLT_PLOGI_LINK_SAME_WWN] = NULL;
if (fcport->plogi_link[QLT_PLOGI_LINK_CONFLICT] == pla)
fcport->plogi_link[QLT_PLOGI_LINK_CONFLICT] = NULL;
}
list_del(&pla->list);
kmem_cache_free(qla_tgt_plogi_cachep, pla);
}
void
qlt_plogi_ack_link(struct scsi_qla_host *vha, struct qlt_plogi_ack_t *pla,
struct fc_port *sess, enum qlt_plogi_link_t link)
{
struct imm_ntfy_from_isp *iocb = &pla->iocb;
/* Inc ref_count first because link might already be pointing at pla */
pla->ref_count++;
ql_dbg(ql_dbg_tgt_mgt, vha, 0xf097,
"Linking sess %p [%d] wwn %8phC with PLOGI ACK to wwn %8phC"
" s_id %02x:%02x:%02x, ref=%d pla %p link %d\n",
sess, link, sess->port_name,
iocb->u.isp24.port_name, iocb->u.isp24.port_id[2],
iocb->u.isp24.port_id[1], iocb->u.isp24.port_id[0],
pla->ref_count, pla, link);
if (link == QLT_PLOGI_LINK_CONFLICT) {
switch (sess->disc_state) {
case DSC_DELETED:
case DSC_DELETE_PEND:
pla->ref_count--;
return;
default:
break;
}
}
if (sess->plogi_link[link])
qlt_plogi_ack_unref(vha, sess->plogi_link[link]);
if (link == QLT_PLOGI_LINK_SAME_WWN)
pla->fcport = sess;
sess->plogi_link[link] = pla;
}
typedef struct {
/* These fields must be initialized by the caller */
port_id_t id;
/*
* number of cmds dropped while we were waiting for
* initiator to ack LOGO initialize to 1 if LOGO is
* triggered by a command, otherwise, to 0
*/
int cmd_count;
/* These fields are used by callee */
struct list_head list;
} qlt_port_logo_t;
static void
qlt_send_first_logo(struct scsi_qla_host *vha, qlt_port_logo_t *logo)
{
qlt_port_logo_t *tmp;
int res;
if (test_bit(PFLG_DRIVER_REMOVING, &vha->pci_flags)) {
res = 0;
goto out;
}
mutex_lock(&vha->vha_tgt.tgt_mutex);
list_for_each_entry(tmp, &vha->logo_list, list) {
if (tmp->id.b24 == logo->id.b24) {
tmp->cmd_count += logo->cmd_count;
mutex_unlock(&vha->vha_tgt.tgt_mutex);
return;
}
}
list_add_tail(&logo->list, &vha->logo_list);
mutex_unlock(&vha->vha_tgt.tgt_mutex);
res = qla24xx_els_dcmd_iocb(vha, ELS_DCMD_LOGO, logo->id);
mutex_lock(&vha->vha_tgt.tgt_mutex);
list_del(&logo->list);
mutex_unlock(&vha->vha_tgt.tgt_mutex);
out:
ql_dbg(ql_dbg_tgt_mgt, vha, 0xf098,
"Finished LOGO to %02x:%02x:%02x, dropped %d cmds, res = %#x\n",
logo->id.b.domain, logo->id.b.area, logo->id.b.al_pa,
logo->cmd_count, res);
}
void qlt_free_session_done(struct work_struct *work)
{
struct fc_port *sess = container_of(work, struct fc_port,
free_work);
struct qla_tgt *tgt = sess->tgt;
struct scsi_qla_host *vha = sess->vha;
struct qla_hw_data *ha = vha->hw;
unsigned long flags;
bool logout_started = false;
scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
struct qlt_plogi_ack_t *own =
sess->plogi_link[QLT_PLOGI_LINK_SAME_WWN];
ql_dbg(ql_dbg_disc, vha, 0xf084,
"%s: se_sess %p / sess %p from port %8phC loop_id %#04x"
" s_id %02x:%02x:%02x logout %d keep %d els_logo %d\n",
__func__, sess->se_sess, sess, sess->port_name, sess->loop_id,
sess->d_id.b.domain, sess->d_id.b.area, sess->d_id.b.al_pa,
sess->logout_on_delete, sess->keep_nport_handle,
sess->send_els_logo);
if (!IS_SW_RESV_ADDR(sess->d_id)) {
qla2x00_mark_device_lost(vha, sess, 0);
if (sess->send_els_logo) {
qlt_port_logo_t logo;
logo.id = sess->d_id;
logo.cmd_count = 0;
INIT_LIST_HEAD(&logo.list);
if (!own)
qlt_send_first_logo(vha, &logo);
sess->send_els_logo = 0;
}
if (sess->logout_on_delete && sess->loop_id != FC_NO_LOOP_ID) {
int rc;
if (!own ||