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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
|
/*
* BSD LICENSE
*
* Copyright (c) 2018-2019 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.
*/
#include "spdk/env.h"
#include "spdk/assert.h"
#include "spdk/nvmf.h"
#include "spdk/nvmf_spec.h"
#include "spdk/string.h"
#include "spdk/trace.h"
#include "spdk/util.h"
#include "spdk/endian.h"
#include "spdk_internal/log.h"
#include "nvmf_internal.h"
#include "transport.h"
#include "nvmf_fc.h"
#include "fc_lld.h"
/* set to 1 to send ls disconnect in response to ls disconnect from host (per standard) */
#define NVMF_FC_LS_SEND_LS_DISCONNECT 0
/* Validation Error indexes into the string table below */
enum {
VERR_NO_ERROR = 0,
VERR_CR_ASSOC_LEN = 1,
VERR_CR_ASSOC_RQST_LEN = 2,
VERR_CR_ASSOC_CMD = 3,
VERR_CR_ASSOC_CMD_LEN = 4,
VERR_ERSP_RATIO = 5,
VERR_ASSOC_ALLOC_FAIL = 6,
VERR_CONN_ALLOC_FAIL = 7,
VERR_CR_CONN_LEN = 8,
VERR_CR_CONN_RQST_LEN = 9,
VERR_ASSOC_ID = 10,
VERR_ASSOC_ID_LEN = 11,
VERR_NO_ASSOC = 12,
VERR_CONN_ID = 13,
VERR_CONN_ID_LEN = 14,
VERR_NO_CONN = 15,
VERR_CR_CONN_CMD = 16,
VERR_CR_CONN_CMD_LEN = 17,
VERR_DISCONN_LEN = 18,
VERR_DISCONN_RQST_LEN = 19,
VERR_DISCONN_CMD = 20,
VERR_DISCONN_CMD_LEN = 21,
VERR_DISCONN_SCOPE = 22,
VERR_RS_LEN = 23,
VERR_RS_RQST_LEN = 24,
VERR_RS_CMD = 25,
VERR_RS_CMD_LEN = 26,
VERR_RS_RCTL = 27,
VERR_RS_RO = 28,
VERR_CONN_TOO_MANY = 29,
VERR_SUBNQN = 30,
VERR_HOSTNQN = 31,
VERR_SQSIZE = 32,
VERR_NO_RPORT = 33,
VERR_SUBLISTENER = 34,
};
static char *validation_errors[] = {
"OK",
"Bad CR_ASSOC Length",
"Bad CR_ASSOC Rqst Length",
"Not CR_ASSOC Cmd",
"Bad CR_ASSOC Cmd Length",
"Bad Ersp Ratio",
"Association Allocation Failed",
"Queue Allocation Failed",
"Bad CR_CONN Length",
"Bad CR_CONN Rqst Length",
"Not Association ID",
"Bad Association ID Length",
"No Association",
"Not Connection ID",
"Bad Connection ID Length",
"No Connection",
"Not CR_CONN Cmd",
"Bad CR_CONN Cmd Length",
"Bad DISCONN Length",
"Bad DISCONN Rqst Length",
"Not DISCONN Cmd",
"Bad DISCONN Cmd Length",
"Bad Disconnect Scope",
"Bad RS Length",
"Bad RS Rqst Length",
"Not RS Cmd",
"Bad RS Cmd Length",
"Bad RS R_CTL",
"Bad RS Relative Offset",
"Too many connections for association",
"Invalid subnqn or subsystem not found",
"Invalid hostnqn or subsystem doesn't allow host",
"SQ size = 0 or too big",
"No Remote Port",
"Bad Subsystem Port",
};
static inline void
nvmf_fc_add_assoc_to_tgt_port(struct spdk_nvmf_fc_nport *tgtport,
struct spdk_nvmf_fc_association *assoc,
struct spdk_nvmf_fc_remote_port_info *rport);
static inline FCNVME_BE32 cpu_to_be32(uint32_t in)
{
uint32_t t;
to_be32(&t, in);
return (FCNVME_BE32)t;
}
static inline FCNVME_BE32 nvmf_fc_lsdesc_len(size_t sz)
{
uint32_t t;
to_be32(&t, sz - (2 * sizeof(uint32_t)));
return (FCNVME_BE32)t;
}
static void
nvmf_fc_ls_format_rsp_hdr(void *buf, uint8_t ls_cmd, uint32_t desc_len,
uint8_t rqst_ls_cmd)
{
struct spdk_nvmf_fc_ls_acc_hdr *acc_hdr = buf;
acc_hdr->w0.ls_cmd = ls_cmd;
acc_hdr->desc_list_len = desc_len;
to_be32(&acc_hdr->rqst.desc_tag, FCNVME_LSDESC_RQST);
acc_hdr->rqst.desc_len =
nvmf_fc_lsdesc_len(sizeof(struct spdk_nvmf_fc_lsdesc_rqst));
acc_hdr->rqst.w0.ls_cmd = rqst_ls_cmd;
}
static int
nvmf_fc_ls_format_rjt(void *buf, uint16_t buflen, uint8_t ls_cmd,
uint8_t reason, uint8_t explanation, uint8_t vendor)
{
struct spdk_nvmf_fc_ls_rjt *rjt = buf;
bzero(buf, sizeof(struct spdk_nvmf_fc_ls_rjt));
nvmf_fc_ls_format_rsp_hdr(buf, FCNVME_LSDESC_RQST,
nvmf_fc_lsdesc_len(sizeof(struct spdk_nvmf_fc_ls_rjt)),
ls_cmd);
to_be32(&rjt->rjt.desc_tag, FCNVME_LSDESC_RJT);
rjt->rjt.desc_len = nvmf_fc_lsdesc_len(sizeof(struct spdk_nvmf_fc_lsdesc_rjt));
rjt->rjt.reason_code = reason;
rjt->rjt.reason_explanation = explanation;
rjt->rjt.vendor = vendor;
return sizeof(struct spdk_nvmf_fc_ls_rjt);
}
/* ************************************************** */
/* Allocators/Deallocators (assocations, connections, */
/* poller API data) */
static inline void
nvmf_fc_ls_free_association(struct spdk_nvmf_fc_association *assoc)
{
struct spdk_nvmf_fc_conn *fc_conn;
/* return the q slots of the conns for the association */
TAILQ_FOREACH(fc_conn, &assoc->avail_fc_conns, assoc_avail_link) {
if (fc_conn->conn_id != NVMF_FC_INVALID_CONN_ID) {
nvmf_fc_release_conn(fc_conn->hwqp, fc_conn->conn_id,
fc_conn->max_queue_depth);
}
}
/* free assocation's send disconnect buffer */
if (assoc->snd_disconn_bufs) {
nvmf_fc_free_srsr_bufs(assoc->snd_disconn_bufs);
}
/* free assocation's connections */
free(assoc->conns_buf);
/* free the association */
free(assoc);
}
static int
nvmf_fc_ls_alloc_connections(struct spdk_nvmf_fc_association *assoc,
struct spdk_nvmf_transport *nvmf_transport)
{
uint32_t i;
struct spdk_nvmf_fc_conn *fc_conn;
SPDK_DEBUGLOG(SPDK_LOG_NVMF_FC_LS, "Pre-alloc %d qpairs for host NQN %s\n",
nvmf_transport->opts.max_qpairs_per_ctrlr, assoc->host_nqn);
/* allocate memory for all connections at once */
assoc->conns_buf = calloc(nvmf_transport->opts.max_qpairs_per_ctrlr + 1,
sizeof(struct spdk_nvmf_fc_conn));
if (assoc->conns_buf == NULL) {
SPDK_ERRLOG("Out of memory for connections for new association\n");
return -ENOMEM;
}
for (i = 0; i < nvmf_transport->opts.max_qpairs_per_ctrlr; i++) {
fc_conn = assoc->conns_buf + (i * sizeof(struct spdk_nvmf_fc_conn));
fc_conn->conn_id = NVMF_FC_INVALID_CONN_ID;
fc_conn->qpair.state = SPDK_NVMF_QPAIR_UNINITIALIZED;
fc_conn->qpair.transport = nvmf_transport;
TAILQ_INSERT_TAIL(&assoc->avail_fc_conns, fc_conn, assoc_avail_link);
}
return 0;
}
static struct spdk_nvmf_fc_association *
nvmf_fc_ls_new_association(uint32_t s_id,
struct spdk_nvmf_fc_nport *tgtport,
struct spdk_nvmf_fc_remote_port_info *rport,
struct spdk_nvmf_fc_lsdesc_cr_assoc_cmd *a_cmd,
struct spdk_nvmf_subsystem *subsys,
uint16_t rpi,
struct spdk_nvmf_transport *nvmf_transport)
{
struct spdk_nvmf_fc_association *assoc;
int rc;
SPDK_DEBUGLOG(SPDK_LOG_NVMF_FC_LS,
"New Association request for port %d nport %d rpi 0x%x\n",
tgtport->fc_port->port_hdl, tgtport->nport_hdl, rpi);
assert(rport);
if (!rport) {
SPDK_ERRLOG("rport is null.\n");
return NULL;
}
assoc = calloc(1, sizeof(struct spdk_nvmf_fc_association));
if (!assoc) {
SPDK_ERRLOG("unable to allocate memory for new association\n");
return NULL;
}
/* initialize association */
#if (NVMF_FC_LS_SEND_LS_DISCONNECT == 1)
/* allocate buffers to send LS disconnect command to host */
assoc->snd_disconn_bufs =
nvmf_fc_alloc_srsr_bufs(sizeof(struct spdk_nvmf_fc_ls_disconnect_rqst),
sizeof(struct spdk_nvmf_fc_ls_rjt));
if (!assoc->snd_disconn_bufs) {
SPDK_ERRLOG("no dma memory for association's ls disconnect bufs\n");
free(assoc);
return NULL;
}
assoc->snd_disconn_bufs->rpi = rpi;
#endif
assoc->s_id = s_id;
assoc->tgtport = tgtport;
assoc->rport = rport;
assoc->subsystem = subsys;
assoc->assoc_state = SPDK_NVMF_FC_OBJECT_CREATED;
memcpy(assoc->host_id, a_cmd->hostid, FCNVME_ASSOC_HOSTID_LEN);
memcpy(assoc->host_nqn, a_cmd->hostnqn, SPDK_NVME_NQN_FIELD_SIZE);
memcpy(assoc->sub_nqn, a_cmd->subnqn, SPDK_NVME_NQN_FIELD_SIZE);
TAILQ_INIT(&assoc->fc_conns);
TAILQ_INIT(&assoc->avail_fc_conns);
assoc->ls_del_op_ctx = NULL;
/* allocate and assign connections for association */
rc = nvmf_fc_ls_alloc_connections(assoc, nvmf_transport);
if (rc != 0) {
nvmf_fc_ls_free_association(assoc);
return NULL;
}
/* add association to target port's association list */
nvmf_fc_add_assoc_to_tgt_port(tgtport, assoc, rport);
return assoc;
}
static inline void
nvmf_fc_ls_append_del_cb_ctx(struct spdk_nvmf_fc_association *assoc,
struct nvmf_fc_ls_op_ctx *opd)
{
/* append to delete assoc callback list */
if (!assoc->ls_del_op_ctx) {
assoc->ls_del_op_ctx = (void *)opd;
} else {
struct nvmf_fc_ls_op_ctx *nxt =
(struct nvmf_fc_ls_op_ctx *) assoc->ls_del_op_ctx;
while (nxt->next_op_ctx) {
nxt = nxt->next_op_ctx;
}
nxt->next_op_ctx = opd;
}
}
static struct spdk_nvmf_fc_conn *
nvmf_fc_ls_new_connection(struct spdk_nvmf_fc_association *assoc, uint16_t qid,
uint16_t esrp_ratio, uint16_t rpi, uint16_t sq_size,
struct spdk_nvmf_fc_nport *tgtport)
{
struct spdk_nvmf_fc_conn *fc_conn;
fc_conn = TAILQ_FIRST(&assoc->avail_fc_conns);
if (!fc_conn) {
SPDK_ERRLOG("out of connections for association %p\n", assoc);
return NULL;
}
/* Remove from avail list and add to in use. */
TAILQ_REMOVE(&assoc->avail_fc_conns, fc_conn, assoc_avail_link);
TAILQ_INSERT_TAIL(&assoc->fc_conns, fc_conn, assoc_link);
if (qid == 0) {
/* AdminQ connection. */
assoc->aq_conn = fc_conn;
}
fc_conn->qpair.qid = qid;
fc_conn->qpair.sq_head_max = sq_size;
TAILQ_INIT(&fc_conn->qpair.outstanding);
fc_conn->esrp_ratio = esrp_ratio;
fc_conn->fc_assoc = assoc;
fc_conn->rpi = rpi;
fc_conn->max_queue_depth = sq_size + 1;
/* save target port trid in connection (for subsystem
* listener validation in fabric connect command)
*/
nvmf_fc_create_trid(&fc_conn->trid, tgtport->fc_nodename.u.wwn,
tgtport->fc_portname.u.wwn);
return fc_conn;
}
static inline void
nvmf_fc_ls_free_connection(struct spdk_nvmf_fc_conn *fc_conn)
{
TAILQ_INSERT_TAIL(&fc_conn->fc_assoc->avail_fc_conns, fc_conn, assoc_avail_link);
}
/* End - Allocators/Deallocators (assocations, connections, */
/* poller API data) */
/* ******************************************************** */
static inline struct spdk_nvmf_fc_association *
nvmf_fc_ls_find_assoc(struct spdk_nvmf_fc_nport *tgtport, uint64_t assoc_id)
{
struct spdk_nvmf_fc_association *assoc = NULL;
TAILQ_FOREACH(assoc, &tgtport->fc_associations, link) {
if (assoc->assoc_id == assoc_id) {
if (assoc->assoc_state == SPDK_NVMF_FC_OBJECT_ZOMBIE) {
assoc = NULL;
}
break;
}
}
return assoc;
}
static inline void
nvmf_fc_add_assoc_to_tgt_port(struct spdk_nvmf_fc_nport *tgtport,
struct spdk_nvmf_fc_association *assoc,
struct spdk_nvmf_fc_remote_port_info *rport)
{
TAILQ_INSERT_TAIL(&tgtport->fc_associations, assoc, link);
tgtport->assoc_count++;
rport->assoc_count++;
}
static inline void
nvmf_fc_del_assoc_from_tgt_port(struct spdk_nvmf_fc_association *assoc)
{
struct spdk_nvmf_fc_nport *tgtport = assoc->tgtport;
TAILQ_REMOVE(&tgtport->fc_associations, assoc, link);
tgtport->assoc_count--;
assoc->rport->assoc_count--;
}
static void
nvmf_fc_ls_rsp_fail_del_conn_cb(void *cb_data, enum spdk_nvmf_fc_poller_api_ret ret)
{
struct nvmf_fc_ls_op_ctx *opd =
(struct nvmf_fc_ls_op_ctx *)cb_data;
struct spdk_nvmf_fc_ls_del_conn_api_data *dp = &opd->u.del_conn;
struct spdk_nvmf_fc_association *assoc = dp->assoc;
struct spdk_nvmf_fc_conn *fc_conn = dp->args.fc_conn;
SPDK_DEBUGLOG(SPDK_LOG_NVMF_FC_LS, "Delete Connection callback "
"for assoc_id 0x%lx conn_id 0x%lx\n", assoc->assoc_id,
fc_conn->conn_id);
if (dp->aq_conn) {
/* delete association */
nvmf_fc_del_assoc_from_tgt_port(assoc);
nvmf_fc_ls_free_association(assoc);
} else {
/* remove connection from association's connection list */
TAILQ_REMOVE(&assoc->fc_conns, fc_conn, assoc_link);
nvmf_fc_ls_free_connection(fc_conn);
}
free(opd);
}
static void
nvmf_fc_handle_xmt_ls_rsp_failure(struct spdk_nvmf_fc_association *assoc,
struct spdk_nvmf_fc_conn *fc_conn,
bool aq_conn)
{
struct spdk_nvmf_fc_ls_del_conn_api_data *api_data;
struct nvmf_fc_ls_op_ctx *opd = NULL;
SPDK_DEBUGLOG(SPDK_LOG_NVMF_FC_LS, "Transmit LS response failure "
"for assoc_id 0x%lx conn_id 0x%lx\n", assoc->assoc_id,
fc_conn->conn_id);
/* create context for delete connection API */
opd = calloc(1, sizeof(struct nvmf_fc_ls_op_ctx));
if (!opd) { /* hopefully this doesn't happen - if so, we leak the connection */
SPDK_ERRLOG("Mem alloc failed for del conn op data");
return;
}
api_data = &opd->u.del_conn;
api_data->assoc = assoc;
api_data->ls_rqst = NULL;
api_data->aq_conn = aq_conn;
api_data->args.fc_conn = fc_conn;
api_data->args.send_abts = false;
api_data->args.hwqp = fc_conn->hwqp;
api_data->args.cb_info.cb_thread = spdk_get_thread();
api_data->args.cb_info.cb_func = nvmf_fc_ls_rsp_fail_del_conn_cb;
api_data->args.cb_info.cb_data = opd;
nvmf_fc_poller_api_func(api_data->args.hwqp,
SPDK_NVMF_FC_POLLER_API_DEL_CONNECTION,
&api_data->args);
}
/* callback from poller's ADD_Connection event */
static void
nvmf_fc_ls_add_conn_cb(void *cb_data, enum spdk_nvmf_fc_poller_api_ret ret)
{
struct nvmf_fc_ls_op_ctx *opd =
(struct nvmf_fc_ls_op_ctx *)cb_data;
struct spdk_nvmf_fc_ls_add_conn_api_data *dp = &opd->u.add_conn;
struct spdk_nvmf_fc_association *assoc = dp->assoc;
struct spdk_nvmf_fc_nport *tgtport = assoc->tgtport;
struct spdk_nvmf_fc_conn *fc_conn = dp->args.fc_conn;
struct spdk_nvmf_fc_ls_rqst *ls_rqst = dp->ls_rqst;
SPDK_DEBUGLOG(SPDK_LOG_NVMF_FC_LS,
"add_conn_cb: assoc_id = 0x%lx, conn_id = 0x%lx\n",
assoc->assoc_id, fc_conn->conn_id);
fc_conn->create_opd = NULL;
if (assoc->assoc_state == SPDK_NVMF_FC_OBJECT_TO_BE_DELETED) {
/* association is already being deleted - don't continue */
free(opd);
return;
}
if (dp->aq_conn) {
struct spdk_nvmf_fc_ls_cr_assoc_acc *assoc_acc =
(struct spdk_nvmf_fc_ls_cr_assoc_acc *)ls_rqst->rspbuf.virt;
/* put connection and association ID in response */
to_be64(&assoc_acc->conn_id.connection_id, fc_conn->conn_id);
assoc_acc->assoc_id.association_id = assoc_acc->conn_id.connection_id;
} else {
struct spdk_nvmf_fc_ls_cr_conn_acc *conn_acc =
(struct spdk_nvmf_fc_ls_cr_conn_acc *)ls_rqst->rspbuf.virt;
/* put connection ID in response */
to_be64(&conn_acc->conn_id.connection_id, fc_conn->conn_id);
}
/* send LS response */
if (nvmf_fc_xmt_ls_rsp(tgtport, ls_rqst) != 0) {
SPDK_ERRLOG("Send LS response for %s failed - cleaning up\n",
dp->aq_conn ? "association" : "connection");
nvmf_fc_handle_xmt_ls_rsp_failure(assoc, fc_conn,
dp->aq_conn);
} else {
SPDK_DEBUGLOG(SPDK_LOG_NVMF_FC_LS,
"LS response (conn_id 0x%lx) sent\n", fc_conn->conn_id);
}
free(opd);
}
void
nvmf_fc_ls_add_conn_failure(
struct spdk_nvmf_fc_association *assoc,
struct spdk_nvmf_fc_ls_rqst *ls_rqst,
struct spdk_nvmf_fc_conn *fc_conn,
bool aq_conn)
{
struct spdk_nvmf_fc_ls_cr_assoc_rqst *rqst;
struct spdk_nvmf_fc_ls_cr_assoc_acc *acc;
struct spdk_nvmf_fc_nport *tgtport = assoc->tgtport;
if (fc_conn->create_opd) {
free(fc_conn->create_opd);
fc_conn->create_opd = NULL;
}
rqst = (struct spdk_nvmf_fc_ls_cr_assoc_rqst *)ls_rqst->rqstbuf.virt;
acc = (struct spdk_nvmf_fc_ls_cr_assoc_acc *)ls_rqst->rspbuf.virt;
/* send failure response */
ls_rqst->rsp_len = nvmf_fc_ls_format_rjt(acc,
FCNVME_MAX_LS_BUFFER_SIZE, rqst->w0.ls_cmd,
FCNVME_RJT_RC_INSUFF_RES,
FCNVME_RJT_EXP_NONE, 0);
nvmf_fc_ls_free_connection(fc_conn);
if (aq_conn) {
nvmf_fc_del_assoc_from_tgt_port(assoc);
nvmf_fc_ls_free_association(assoc);
}
nvmf_fc_xmt_ls_rsp(tgtport, ls_rqst);
}
static void
nvmf_fc_ls_add_conn_to_poller(
struct spdk_nvmf_fc_association *assoc,
struct spdk_nvmf_fc_ls_rqst *ls_rqst,
struct spdk_nvmf_fc_conn *fc_conn,
bool aq_conn)
{
struct nvmf_fc_ls_op_ctx *opd;
struct spdk_nvmf_fc_ls_add_conn_api_data *api_data;
SPDK_DEBUGLOG(SPDK_LOG_NVMF_FC_LS, "Add Connection to poller for "
"assoc_id 0x%lx conn_id 0x%lx\n", assoc->assoc_id,
fc_conn->conn_id);
opd = calloc(1, sizeof(struct nvmf_fc_ls_op_ctx));
if (!opd) {
SPDK_ERRLOG("allocate api data for add conn op failed\n");
nvmf_fc_ls_add_conn_failure(assoc, ls_rqst, fc_conn, aq_conn);
return;
}
/* insert conn in association's connection list */
api_data = &opd->u.add_conn;
assoc->conn_count++;
api_data->args.fc_conn = fc_conn;
api_data->args.cb_info.cb_thread = spdk_get_thread();
api_data->args.cb_info.cb_func = nvmf_fc_ls_add_conn_cb;
api_data->args.cb_info.cb_data = (void *)opd;
api_data->assoc = assoc;
api_data->ls_rqst = ls_rqst;
api_data->aq_conn = aq_conn;
SPDK_DEBUGLOG(SPDK_LOG_NVMF_FC_LS,
"New QP callback called.\n");
/* Let the nvmf_tgt decide which pollgroup to use. */
fc_conn->create_opd = opd;
spdk_nvmf_tgt_new_qpair(ls_rqst->nvmf_tgt, &fc_conn->qpair);
}
/* Delete association functions */
static void
nvmf_fc_do_del_assoc_cbs(struct nvmf_fc_ls_op_ctx *opd, int ret)
{
struct nvmf_fc_ls_op_ctx *nxt;
struct spdk_nvmf_fc_delete_assoc_api_data *dp;
while (opd) {
dp = &opd->u.del_assoc;
SPDK_DEBUGLOG(SPDK_LOG_NVMF_FC_LS, "performing delete assoc. callback\n");
dp->del_assoc_cb(dp->del_assoc_cb_data, ret);
nxt = opd->next_op_ctx;
free(opd);
opd = nxt;
}
}
static void
nvmf_fs_send_ls_disconnect_cb(void *hwqp, int32_t status, void *args)
{
if (args) {
SPDK_DEBUGLOG(SPDK_LOG_NVMF_FC_LS, "free disconnect buffers\n");
nvmf_fc_free_srsr_bufs((struct spdk_nvmf_fc_srsr_bufs *)args);
}
}
static void
nvmf_fc_del_all_conns_cb(void *cb_data, enum spdk_nvmf_fc_poller_api_ret ret)
{
struct nvmf_fc_ls_op_ctx *opd = (struct nvmf_fc_ls_op_ctx *)cb_data;
struct spdk_nvmf_fc_delete_assoc_api_data *dp = &opd->u.del_assoc;
struct spdk_nvmf_fc_association *assoc = dp->assoc;
struct spdk_nvmf_fc_conn *fc_conn = dp->args.fc_conn;
/* Assumption here is that there will be no error (i.e. ret=success).
* Since connections are deleted in parallel, nothing can be
* done anyway if there is an error because we need to complete
* all connection deletes and callback to caller */
SPDK_DEBUGLOG(SPDK_LOG_NVMF_FC_LS,
"Delete all connections for assoc_id 0x%lx, conn_id = %lx\n",
assoc->assoc_id, fc_conn->conn_id);
/* remove connection from association's connection list */
TAILQ_REMOVE(&assoc->fc_conns, fc_conn, assoc_link);
nvmf_fc_ls_free_connection(fc_conn);
if (--assoc->conn_count == 0) {
/* last connection - remove association from target port's association list */
struct nvmf_fc_ls_op_ctx *cb_opd = (struct nvmf_fc_ls_op_ctx *)assoc->ls_del_op_ctx;
SPDK_DEBUGLOG(SPDK_LOG_NVMF_FC_LS,
"remove assoc. %lx\n", assoc->assoc_id);
nvmf_fc_del_assoc_from_tgt_port(assoc);
if (assoc->snd_disconn_bufs &&
assoc->tgtport->fc_port->hw_port_status == SPDK_FC_PORT_ONLINE) {
struct spdk_nvmf_fc_ls_disconnect_rqst *dc_rqst;
struct spdk_nvmf_fc_srsr_bufs *srsr_bufs;
dc_rqst = (struct spdk_nvmf_fc_ls_disconnect_rqst *)
assoc->snd_disconn_bufs->rqst;
bzero(dc_rqst, sizeof(struct spdk_nvmf_fc_ls_disconnect_rqst));
/* fill in request descriptor */
dc_rqst->w0.ls_cmd = FCNVME_LS_DISCONNECT;
to_be32(&dc_rqst->desc_list_len,
sizeof(struct spdk_nvmf_fc_ls_disconnect_rqst) -
(2 * sizeof(uint32_t)));
/* fill in disconnect command descriptor */
to_be32(&dc_rqst->disconn_cmd.desc_tag, FCNVME_LSDESC_DISCONN_CMD);
to_be32(&dc_rqst->disconn_cmd.desc_len,
sizeof(struct spdk_nvmf_fc_lsdesc_disconn_cmd) -
(2 * sizeof(uint32_t)));
/* fill in association id descriptor */
to_be32(&dc_rqst->assoc_id.desc_tag, FCNVME_LSDESC_ASSOC_ID),
to_be32(&dc_rqst->assoc_id.desc_len,
sizeof(struct spdk_nvmf_fc_lsdesc_assoc_id) -
(2 * sizeof(uint32_t)));
to_be64(&dc_rqst->assoc_id.association_id, assoc->assoc_id);
srsr_bufs = assoc->snd_disconn_bufs;
assoc->snd_disconn_bufs = NULL;
SPDK_DEBUGLOG(SPDK_LOG_NVMF_FC_LS, "Send LS disconnect\n");
if (nvmf_fc_xmt_srsr_req(&assoc->tgtport->fc_port->ls_queue,
srsr_bufs, nvmf_fs_send_ls_disconnect_cb,
(void *)srsr_bufs)) {
SPDK_ERRLOG("Error sending LS disconnect\n");
assoc->snd_disconn_bufs = srsr_bufs;
}
}
nvmf_fc_ls_free_association(assoc);
/* perform callbacks to all callers to delete association */
nvmf_fc_do_del_assoc_cbs(cb_opd, 0);
}
free(opd);
}
static void
nvmf_fc_kill_io_del_all_conns_cb(void *cb_data, enum spdk_nvmf_fc_poller_api_ret ret)
{
struct nvmf_fc_ls_op_ctx *opd = (struct nvmf_fc_ls_op_ctx *)cb_data;
SPDK_DEBUGLOG(SPDK_LOG_NVMF_FC_LS, "Callback after killing outstanding ABTS.");
/*
* NOTE: We should not access any connection or association related data
* structures here.
*/
free(opd);
}
/* Disconnect/delete (association) request functions */
static int
_nvmf_fc_delete_association(struct spdk_nvmf_fc_nport *tgtport,
uint64_t assoc_id, bool send_abts, bool backend_initiated,
spdk_nvmf_fc_del_assoc_cb del_assoc_cb,
void *cb_data, bool from_ls_rqst)
{
struct nvmf_fc_ls_op_ctx *opd, *opd_tail, *opd_head = NULL;
struct spdk_nvmf_fc_delete_assoc_api_data *api_data;
struct spdk_nvmf_fc_conn *fc_conn;
struct spdk_nvmf_fc_association *assoc =
nvmf_fc_ls_find_assoc(tgtport, assoc_id);
struct spdk_nvmf_fc_port *fc_port = tgtport->fc_port;
enum spdk_nvmf_fc_object_state assoc_state;
SPDK_DEBUGLOG(SPDK_LOG_NVMF_FC_LS, "Delete association, "
"assoc_id 0x%lx\n", assoc_id);
if (!assoc) {
SPDK_ERRLOG("Delete association failed: %s\n",
validation_errors[VERR_NO_ASSOC]);
return VERR_NO_ASSOC;
}
/* create cb context to put in association's list of
* callbacks to call when delete association is done */
opd = calloc(1, sizeof(struct nvmf_fc_ls_op_ctx));
if (!opd) {
SPDK_ERRLOG("Mem alloc failed for del assoc cb data");
return -ENOMEM;
}
api_data = &opd->u.del_assoc;
api_data->assoc = assoc;
api_data->from_ls_rqst = from_ls_rqst;
api_data->del_assoc_cb = del_assoc_cb;
api_data->del_assoc_cb_data = cb_data;
api_data->args.cb_info.cb_data = opd;
nvmf_fc_ls_append_del_cb_ctx(assoc, opd);
assoc_state = assoc->assoc_state;
if ((assoc_state == SPDK_NVMF_FC_OBJECT_TO_BE_DELETED) &&
(fc_port->hw_port_status != SPDK_FC_PORT_QUIESCED)) {
/* association already being deleted */
return 0;
}
/* mark assoc. to be deleted */
assoc->assoc_state = SPDK_NVMF_FC_OBJECT_TO_BE_DELETED;
/* create a list of all connection to delete */
TAILQ_FOREACH(fc_conn, &assoc->fc_conns, assoc_link) {
opd = calloc(1, sizeof(struct nvmf_fc_ls_op_ctx));
if (!opd) { /* hopefully this doesn't happen */
SPDK_ERRLOG("Mem alloc failed for del conn op data");
while (opd_head) { /* free any contexts already allocated */
opd = opd_head;
opd_head = opd->next_op_ctx;
free(opd);
}
return -ENOMEM;
}
api_data = &opd->u.del_assoc;
api_data->args.fc_conn = fc_conn;
api_data->assoc = assoc;
api_data->args.send_abts = send_abts;
api_data->args.backend_initiated = backend_initiated;
api_data->args.hwqp = nvmf_fc_get_hwqp_from_conn_id(
assoc->tgtport->fc_port->io_queues,
assoc->tgtport->fc_port->num_io_queues,
fc_conn->conn_id);
api_data->args.cb_info.cb_thread = spdk_get_thread();
if ((fc_port->hw_port_status == SPDK_FC_PORT_QUIESCED) &&
(assoc_state == SPDK_NVMF_FC_OBJECT_TO_BE_DELETED)) {
/*
* If there are any connections deletes or IO abts that are
* stuck because of firmware reset, a second invocation of
* SPDK_NVMF_FC_POLLER_API_DEL_CONNECTION will result in
* outstanding connections & requests being killed and
* their corresponding callbacks being executed.
*/
api_data->args.cb_info.cb_func = nvmf_fc_kill_io_del_all_conns_cb;
} else {
api_data->args.cb_info.cb_func = nvmf_fc_del_all_conns_cb;
}
api_data->args.cb_info.cb_data = opd;
SPDK_DEBUGLOG(SPDK_LOG_NVMF_FC_LS,
"conn_id = %lx\n", fc_conn->conn_id);
if (!opd_head) {
opd_head = opd;
} else {
opd_tail->next_op_ctx = opd;
}
opd_tail = opd;
}
/* make poller api calls to delete connetions */
while (opd_head) {
opd = opd_head;
opd_head = opd->next_op_ctx;
api_data = &opd->u.del_assoc;
nvmf_fc_poller_api_func(api_data->args.hwqp,
SPDK_NVMF_FC_POLLER_API_DEL_CONNECTION,
&api_data->args);
}
return 0;
}
static void
nvmf_fc_ls_disconnect_assoc_cb(void *cb_data, uint32_t err)
{
struct nvmf_fc_ls_op_ctx *opd = (struct nvmf_fc_ls_op_ctx *)cb_data;
struct spdk_nvmf_fc_ls_disconn_assoc_api_data *dp = &opd->u.disconn_assoc;
struct spdk_nvmf_fc_nport *tgtport = dp->tgtport;
struct spdk_nvmf_fc_ls_rqst *ls_rqst = dp->ls_rqst;
SPDK_DEBUGLOG(SPDK_LOG_NVMF_FC_LS, "Disconnect association callback begin "
"nport %d\n", tgtport->nport_hdl);
if (err != 0) {
/* send failure response */
struct spdk_nvmf_fc_ls_cr_assoc_rqst *rqst =
(struct spdk_nvmf_fc_ls_cr_assoc_rqst *)ls_rqst->rqstbuf.virt;
struct spdk_nvmf_fc_ls_cr_assoc_acc *acc =
(struct spdk_nvmf_fc_ls_cr_assoc_acc *)ls_rqst->rspbuf.virt;
ls_rqst->rsp_len = nvmf_fc_ls_format_rjt(acc,
FCNVME_MAX_LS_BUFFER_SIZE,
rqst->w0.ls_cmd,
FCNVME_RJT_RC_UNAB,
FCNVME_RJT_EXP_NONE,
0);
}
nvmf_fc_xmt_ls_rsp(tgtport, ls_rqst);
free(opd);
SPDK_DEBUGLOG(SPDK_LOG_NVMF_FC_LS, "Disconnect association callback complete "
"nport %d err %d\n", tgtport->nport_hdl, err);
}
static void
nvmf_fc_ls_disconnect_assoc(struct spdk_nvmf_fc_nport *tgtport,
struct spdk_nvmf_fc_ls_rqst *ls_rqst, uint64_t assoc_id)
{
struct nvmf_fc_ls_op_ctx *opd;
struct spdk_nvmf_fc_ls_cr_assoc_rqst *rqst =
(struct spdk_nvmf_fc_ls_cr_assoc_rqst *)ls_rqst->rqstbuf.virt;
struct spdk_nvmf_fc_ls_cr_assoc_acc *acc =
(struct spdk_nvmf_fc_ls_cr_assoc_acc *)ls_rqst->rspbuf.virt;
struct spdk_nvmf_fc_ls_disconn_assoc_api_data *api_data;
int ret;
uint8_t reason = 0;
opd = calloc(1, sizeof(struct nvmf_fc_ls_op_ctx));
if (!opd) {
/* send failure response */
SPDK_ERRLOG("Allocate disconn assoc op data failed\n");
reason = FCNVME_RJT_RC_INSUFF_RES;
goto send_rjt;
}
api_data = &opd->u.disconn_assoc;
api_data->tgtport = tgtport;
api_data->ls_rqst = ls_rqst;
ret = _nvmf_fc_delete_association(tgtport, assoc_id,
false, false,
nvmf_fc_ls_disconnect_assoc_cb,
api_data, true);
if (!ret) {
return;
}
/* delete association failed */
switch (ret) {
case VERR_NO_ASSOC:
reason = FCNVME_RJT_RC_INV_ASSOC;
break;
case -ENOMEM:
reason = FCNVME_RJT_RC_INSUFF_RES;
break;
default:
reason = FCNVME_RJT_RC_LOGIC;
}
free(opd);
send_rjt:
ls_rqst->rsp_len = nvmf_fc_ls_format_rjt(acc,
FCNVME_MAX_LS_BUFFER_SIZE,
rqst->w0.ls_cmd, reason,
FCNVME_RJT_EXP_NONE, 0);
nvmf_fc_xmt_ls_rsp(tgtport, ls_rqst);
}
static int
nvmf_fc_ls_validate_host(struct spdk_nvmf_subsystem *subsystem, const char *hostnqn)
{
if (!spdk_nvmf_subsystem_host_allowed(subsystem, hostnqn)) {
return -EPERM;
}
return 0;
}
/* **************************** */
/* LS Reqeust Handler Functions */
static void
nvmf_fc_ls_process_cass(uint32_t s_id,
struct spdk_nvmf_fc_nport *tgtport,
struct spdk_nvmf_fc_ls_rqst *ls_rqst)
{
struct spdk_nvmf_fc_ls_cr_assoc_rqst *rqst =
(struct spdk_nvmf_fc_ls_cr_assoc_rqst *)ls_rqst->rqstbuf.virt;
struct spdk_nvmf_fc_ls_cr_assoc_acc *acc =
(struct spdk_nvmf_fc_ls_cr_assoc_acc *)ls_rqst->rspbuf.virt;
struct spdk_nvmf_fc_association *assoc;
struct spdk_nvmf_fc_conn *fc_conn;
struct spdk_nvmf_subsystem *subsystem = NULL;
const char *hostnqn = (const char *)rqst->assoc_cmd.hostnqn;
int errmsg_ind = 0;
uint8_t rc = FCNVME_RJT_RC_NONE;
uint8_t ec = FCNVME_RJT_EXP_NONE;
struct spdk_nvmf_transport *transport = spdk_nvmf_tgt_get_transport(ls_rqst->nvmf_tgt,
SPDK_NVME_TRANSPORT_NAME_FC);
SPDK_DEBUGLOG(SPDK_LOG_NVMF_FC_LS,
"LS_CASS: ls_rqst_len=%d, desc_list_len=%d, cmd_len=%d, sq_size=%d, "
"Subnqn: %s, Hostnqn: %s, Tgtport nn:%lx, pn:%lx\n",
ls_rqst->rqst_len, from_be32(&rqst->desc_list_len),
from_be32(&rqst->assoc_cmd.desc_len),
from_be32(&rqst->assoc_cmd.sqsize),
rqst->assoc_cmd.subnqn, hostnqn,
tgtport->fc_nodename.u.wwn, tgtport->fc_portname.u.wwn);
if (ls_rqst->rqst_len < FCNVME_LS_CA_CMD_MIN_LEN) {
SPDK_ERRLOG("assoc_cmd req len = %d, should be at least %d\n",
ls_rqst->rqst_len, FCNVME_LS_CA_CMD_MIN_LEN);
errmsg_ind = VERR_CR_ASSOC_LEN;
rc = FCNVME_RJT_RC_INV_PARAM;
ec = FCNVME_RJT_EXP_INV_LEN;
} else if (from_be32(&rqst->desc_list_len) <
FCNVME_LS_CA_DESC_LIST_MIN_LEN) {
SPDK_ERRLOG("assoc_cmd desc list len = %d, should be at least %d\n",
from_be32(&rqst->desc_list_len),
FCNVME_LS_CA_DESC_LIST_MIN_LEN);
errmsg_ind = VERR_CR_ASSOC_RQST_LEN;
rc = FCNVME_RJT_RC_INV_PARAM;
ec = FCNVME_RJT_EXP_INV_LEN;
} else if (rqst->assoc_cmd.desc_tag !=
cpu_to_be32(FCNVME_LSDESC_CREATE_ASSOC_CMD)) {
errmsg_ind = VERR_CR_ASSOC_CMD;
rc = FCNVME_RJT_RC_INV_PARAM;
} else if (from_be32(&rqst->assoc_cmd.desc_len) <
FCNVME_LS_CA_DESC_MIN_LEN) {
SPDK_ERRLOG("assoc_cmd desc len = %d, should be at least %d\n",
from_be32(&rqst->assoc_cmd.desc_len),
FCNVME_LS_CA_DESC_MIN_LEN);
errmsg_ind = VERR_CR_ASSOC_CMD_LEN;
rc = FCNVME_RJT_RC_INV_PARAM;
ec = FCNVME_RJT_EXP_INV_LEN;
} else if (!rqst->assoc_cmd.ersp_ratio ||
(from_be16(&rqst->assoc_cmd.ersp_ratio) >=
from_be16(&rqst->assoc_cmd.sqsize))) {
errmsg_ind = VERR_ERSP_RATIO;
rc = FCNVME_RJT_RC_INV_PARAM;
ec = FCNVME_RJT_EXP_INV_ESRP;
} else if (from_be16(&rqst->assoc_cmd.sqsize) == 0 ||
from_be16(&rqst->assoc_cmd.sqsize) > transport->opts.max_aq_depth) {
errmsg_ind = VERR_SQSIZE;
rc = FCNVME_RJT_RC_INV_PARAM;
ec = FCNVME_RJT_EXP_SQ_SIZE;
}
if (rc != FCNVME_RJT_RC_NONE) {
goto rjt_cass;
}
subsystem = spdk_nvmf_tgt_find_subsystem(ls_rqst->nvmf_tgt, rqst->assoc_cmd.subnqn);
if (subsystem == NULL) {
errmsg_ind = VERR_SUBNQN;
rc = FCNVME_RJT_RC_INV_PARAM;
ec = FCNVME_RJT_EXP_INV_SUBNQN;
goto rjt_cass;
}
if (nvmf_fc_ls_validate_host(subsystem, hostnqn)) {
errmsg_ind = VERR_HOSTNQN;
rc = FCNVME_RJT_RC_INV_HOST;
ec = FCNVME_RJT_EXP_INV_HOSTNQN;
goto rjt_cass;
}
/* get new association */
assoc = nvmf_fc_ls_new_association(s_id, tgtport, ls_rqst->rport,
&rqst->assoc_cmd, subsystem,
ls_rqst->rpi, transport);
if (!assoc) {
errmsg_ind = VERR_ASSOC_ALLOC_FAIL;
rc = FCNVME_RJT_RC_INSUFF_RES;
ec = FCNVME_RJT_EXP_NONE;
goto rjt_cass;
}
/* alloc admin q (i.e. connection) */
fc_conn = nvmf_fc_ls_new_connection(assoc, 0,
from_be16(&rqst->assoc_cmd.ersp_ratio),
ls_rqst->rpi,
from_be16(&rqst->assoc_cmd.sqsize),
tgtport);
if (!fc_conn) {
nvmf_fc_ls_free_association(assoc);
errmsg_ind = VERR_CONN_ALLOC_FAIL;
rc = FCNVME_RJT_RC_INSUFF_RES;
ec = FCNVME_RJT_EXP_NONE;
goto rjt_cass;
}
/* format accept response */
bzero(acc, sizeof(*acc));
ls_rqst->rsp_len = sizeof(*acc);
nvmf_fc_ls_format_rsp_hdr(acc, FCNVME_LS_ACC,
nvmf_fc_lsdesc_len(
sizeof(struct spdk_nvmf_fc_ls_cr_assoc_acc)),
FCNVME_LS_CREATE_ASSOCIATION);
to_be32(&acc->assoc_id.desc_tag, FCNVME_LSDESC_ASSOC_ID);
acc->assoc_id.desc_len =
nvmf_fc_lsdesc_len(sizeof(struct spdk_nvmf_fc_lsdesc_assoc_id));
to_be32(&acc->conn_id.desc_tag, FCNVME_LSDESC_CONN_ID);
acc->conn_id.desc_len =
nvmf_fc_lsdesc_len(sizeof(struct spdk_nvmf_fc_lsdesc_conn_id));
/* assign connection to HWQP poller - also sends response */
nvmf_fc_ls_add_conn_to_poller(assoc, ls_rqst, fc_conn, true);
return;
rjt_cass:
SPDK_ERRLOG("Create Association LS failed: %s\n", validation_errors[errmsg_ind]);
ls_rqst->rsp_len = nvmf_fc_ls_format_rjt(acc, FCNVME_MAX_LS_BUFFER_SIZE,
rqst->w0.ls_cmd, rc, ec, 0);
nvmf_fc_xmt_ls_rsp(tgtport, ls_rqst);
}
static void
nvmf_fc_ls_process_cioc(struct spdk_nvmf_fc_nport *tgtport,
struct spdk_nvmf_fc_ls_rqst *ls_rqst)
{
struct spdk_nvmf_fc_ls_cr_conn_rqst *rqst =
(struct spdk_nvmf_fc_ls_cr_conn_rqst *)ls_rqst->rqstbuf.virt;
struct spdk_nvmf_fc_ls_cr_conn_acc *acc =
(struct spdk_nvmf_fc_ls_cr_conn_acc *)ls_rqst->rspbuf.virt;
struct spdk_nvmf_fc_association *assoc;
struct spdk_nvmf_fc_conn *fc_conn = NULL;
int errmsg_ind = 0;
uint8_t rc = FCNVME_RJT_RC_NONE;
uint8_t ec = FCNVME_RJT_EXP_NONE;
struct spdk_nvmf_transport *transport = spdk_nvmf_tgt_get_transport(ls_rqst->nvmf_tgt,
SPDK_NVME_TRANSPORT_NAME_FC);
SPDK_DEBUGLOG(SPDK_LOG_NVMF_FC_LS,
"LS_CIOC: ls_rqst_len=%d, desc_list_len=%d, cmd_len=%d, "
"assoc_id=0x%lx, sq_size=%d, esrp=%d, Tgtport nn:%lx, pn:%lx\n",
ls_rqst->rqst_len, from_be32(&rqst->desc_list_len),
from_be32(&rqst->connect_cmd.desc_len),
from_be64(&rqst->assoc_id.association_id),
from_be32(&rqst->connect_cmd.sqsize),
from_be32(&rqst->connect_cmd.ersp_ratio),
tgtport->fc_nodename.u.wwn, tgtport->fc_portname.u.wwn);
if (ls_rqst->rqst_len < sizeof(struct spdk_nvmf_fc_ls_cr_conn_rqst)) {
errmsg_ind = VERR_CR_CONN_LEN;
rc = FCNVME_RJT_RC_INV_PARAM;
ec = FCNVME_RJT_EXP_INV_LEN;
} else if (rqst->desc_list_len !=
nvmf_fc_lsdesc_len(sizeof(struct spdk_nvmf_fc_ls_cr_conn_rqst))) {
errmsg_ind = VERR_CR_CONN_RQST_LEN;
rc = FCNVME_RJT_RC_INV_PARAM;
ec = FCNVME_RJT_EXP_INV_LEN;
} else if (rqst->assoc_id.desc_tag !=
cpu_to_be32(FCNVME_LSDESC_ASSOC_ID)) {
errmsg_ind = VERR_ASSOC_ID;
rc = FCNVME_RJT_RC_INV_PARAM;
} else if (rqst->assoc_id.desc_len !=
nvmf_fc_lsdesc_len(sizeof(struct spdk_nvmf_fc_lsdesc_assoc_id))) {
errmsg_ind = VERR_ASSOC_ID_LEN;
rc = FCNVME_RJT_RC_INV_PARAM;
ec = FCNVME_RJT_EXP_INV_LEN;
} else if (rqst->connect_cmd.desc_tag !=
cpu_to_be32(FCNVME_LSDESC_CREATE_CONN_CMD)) {
errmsg_ind = VERR_CR_CONN_CMD;
rc = FCNVME_RJT_RC_INV_PARAM;
} else if (rqst->connect_cmd.desc_len !=
nvmf_fc_lsdesc_len(
sizeof(struct spdk_nvmf_fc_lsdesc_cr_conn_cmd))) {
errmsg_ind = VERR_CR_CONN_CMD_LEN;
rc = FCNVME_RJT_RC_INV_PARAM;
ec = FCNVME_RJT_EXP_INV_LEN;
} else if (!rqst->connect_cmd.ersp_ratio ||
(from_be16(&rqst->connect_cmd.ersp_ratio) >=
from_be16(&rqst->connect_cmd.sqsize))) {
errmsg_ind = VERR_ERSP_RATIO;
rc = FCNVME_RJT_RC_INV_PARAM;
ec = FCNVME_RJT_EXP_INV_ESRP;
} else if (from_be16(&rqst->connect_cmd.sqsize) == 0 ||
from_be16(&rqst->connect_cmd.sqsize) > transport->opts.max_queue_depth) {
errmsg_ind = VERR_SQSIZE;
rc = FCNVME_RJT_RC_INV_PARAM;
ec = FCNVME_RJT_EXP_SQ_SIZE;
}
if (rc != FCNVME_RJT_RC_NONE) {
goto rjt_cioc;
}
/* find association */
assoc = nvmf_fc_ls_find_assoc(tgtport,
from_be64(&rqst->assoc_id.association_id));
if (!assoc) {
errmsg_ind = VERR_NO_ASSOC;
rc = FCNVME_RJT_RC_INV_ASSOC;
} else if (assoc->assoc_state == SPDK_NVMF_FC_OBJECT_TO_BE_DELETED) {
/* association is being deleted - don't allow more connections */
errmsg_ind = VERR_NO_ASSOC;
rc = FCNVME_RJT_RC_INV_ASSOC;
} else if (assoc->conn_count >= transport->opts.max_qpairs_per_ctrlr) {
errmsg_ind = VERR_CONN_TOO_MANY;
rc = FCNVME_RJT_RC_INV_PARAM;
ec = FCNVME_RJT_EXP_INV_Q_ID;
}
if (rc != FCNVME_RJT_RC_NONE) {
goto rjt_cioc;
}
fc_conn = nvmf_fc_ls_new_connection(assoc, from_be16(&rqst->connect_cmd.qid),
from_be16(&rqst->connect_cmd.ersp_ratio),
ls_rqst->rpi,
from_be16(&rqst->connect_cmd.sqsize),
tgtport);
if (!fc_conn) {
errmsg_ind = VERR_CONN_ALLOC_FAIL;
rc = FCNVME_RJT_RC_INSUFF_RES;
ec = FCNVME_RJT_EXP_NONE;
goto rjt_cioc;
}
/* format accept response */
SPDK_DEBUGLOG(SPDK_LOG_NVMF_FC_LS, "Formatting LS accept response for "
"assoc_id 0x%lx conn_id 0x%lx\n", assoc->assoc_id,
fc_conn->conn_id);
bzero(acc, sizeof(*acc));
ls_rqst->rsp_len = sizeof(*acc);
nvmf_fc_ls_format_rsp_hdr(acc, FCNVME_LS_ACC,
nvmf_fc_lsdesc_len(
sizeof(struct spdk_nvmf_fc_ls_cr_conn_acc)),
FCNVME_LS_CREATE_CONNECTION);
to_be32(&acc->conn_id.desc_tag, FCNVME_LSDESC_CONN_ID);
acc->conn_id.desc_len =
nvmf_fc_lsdesc_len(sizeof(struct spdk_nvmf_fc_lsdesc_conn_id));
/* assign connection to HWQP poller - also sends response */
nvmf_fc_ls_add_conn_to_poller(assoc, ls_rqst, fc_conn, false);
return;
rjt_cioc:
SPDK_ERRLOG("Create Connection LS failed: %s\n", validation_errors[errmsg_ind]);
ls_rqst->rsp_len = nvmf_fc_ls_format_rjt(acc, FCNVME_MAX_LS_BUFFER_SIZE,
rqst->w0.ls_cmd, rc, ec, 0);
nvmf_fc_xmt_ls_rsp(tgtport, ls_rqst);
}
static void
nvmf_fc_ls_process_disc(struct spdk_nvmf_fc_nport *tgtport,
struct spdk_nvmf_fc_ls_rqst *ls_rqst)
{
struct spdk_nvmf_fc_ls_disconnect_rqst *rqst =
(struct spdk_nvmf_fc_ls_disconnect_rqst *)ls_rqst->rqstbuf.virt;
struct spdk_nvmf_fc_ls_disconnect_acc *acc =
(struct spdk_nvmf_fc_ls_disconnect_acc *)ls_rqst->rspbuf.virt;
struct spdk_nvmf_fc_association *assoc;
int errmsg_ind = 0;
uint8_t rc = FCNVME_RJT_RC_NONE;
uint8_t ec = FCNVME_RJT_EXP_NONE;
SPDK_DEBUGLOG(SPDK_LOG_NVMF_FC_LS,
"LS_DISC: ls_rqst_len=%d, desc_list_len=%d, cmd_len=%d,"
"assoc_id=0x%lx\n",
ls_rqst->rqst_len, from_be32(&rqst->desc_list_len),
from_be32(&rqst->disconn_cmd.desc_len),
from_be64(&rqst->assoc_id.association_id));
if (ls_rqst->rqst_len < sizeof(struct spdk_nvmf_fc_ls_disconnect_rqst)) {
errmsg_ind = VERR_DISCONN_LEN;
rc = FCNVME_RJT_RC_INV_PARAM;
ec = FCNVME_RJT_EXP_INV_LEN;
} else if (rqst->desc_list_len !=
nvmf_fc_lsdesc_len(sizeof(struct spdk_nvmf_fc_ls_disconnect_rqst))) {
errmsg_ind = VERR_DISCONN_RQST_LEN;
rc = FCNVME_RJT_RC_INV_PARAM;
ec = FCNVME_RJT_EXP_INV_LEN;
} else if (rqst->assoc_id.desc_tag !=
cpu_to_be32(FCNVME_LSDESC_ASSOC_ID)) {
errmsg_ind = VERR_ASSOC_ID;
rc = FCNVME_RJT_RC_INV_PARAM;
} else if (rqst->assoc_id.desc_len !=
nvmf_fc_lsdesc_len(sizeof(struct spdk_nvmf_fc_lsdesc_assoc_id))) {
errmsg_ind = VERR_ASSOC_ID_LEN;
rc = FCNVME_RJT_RC_INV_PARAM;
ec = FCNVME_RJT_EXP_INV_LEN;
} else if (rqst->disconn_cmd.desc_tag !=
cpu_to_be32(FCNVME_LSDESC_DISCONN_CMD)) {
rc = FCNVME_RJT_RC_INV_PARAM;
errmsg_ind = VERR_DISCONN_CMD;
} else if (rqst->disconn_cmd.desc_len !=
nvmf_fc_lsdesc_len(sizeof(struct spdk_nvmf_fc_lsdesc_disconn_cmd))) {
errmsg_ind = VERR_DISCONN_CMD_LEN;
rc = FCNVME_RJT_RC_INV_PARAM;
ec = FCNVME_RJT_EXP_INV_LEN;
}
if (rc != FCNVME_RJT_RC_NONE) {
goto rjt_disc;
}
/* match an active association */
assoc = nvmf_fc_ls_find_assoc(tgtport,
from_be64(&rqst->assoc_id.association_id));
if (!assoc) {
errmsg_ind = VERR_NO_ASSOC;
rc = FCNVME_RJT_RC_INV_ASSOC;
goto rjt_disc;
}
/* format response */
bzero(acc, sizeof(*acc));
ls_rqst->rsp_len = sizeof(*acc);
nvmf_fc_ls_format_rsp_hdr(acc, FCNVME_LS_ACC,
nvmf_fc_lsdesc_len(
sizeof(struct spdk_nvmf_fc_ls_disconnect_acc)),
FCNVME_LS_DISCONNECT);
nvmf_fc_ls_disconnect_assoc(tgtport, ls_rqst, assoc->assoc_id);
return;
rjt_disc:
SPDK_ERRLOG("Disconnect LS failed: %s\n", validation_errors[errmsg_ind]);
ls_rqst->rsp_len = nvmf_fc_ls_format_rjt(acc, FCNVME_MAX_LS_BUFFER_SIZE,
rqst->w0.ls_cmd, rc, ec, 0);
nvmf_fc_xmt_ls_rsp(tgtport, ls_rqst);
}
/* ************************ */
/* external functions */
void
nvmf_fc_ls_init(struct spdk_nvmf_fc_port *fc_port)
{
}
void
nvmf_fc_ls_fini(struct spdk_nvmf_fc_port *fc_port)
{
}
void
nvmf_fc_handle_ls_rqst(struct spdk_nvmf_fc_ls_rqst *ls_rqst)
{
struct spdk_nvmf_fc_ls_rqst_w0 *w0 =
(struct spdk_nvmf_fc_ls_rqst_w0 *)ls_rqst->rqstbuf.virt;
uint32_t s_id = ls_rqst->s_id;
struct spdk_nvmf_fc_nport *tgtport = ls_rqst->nport;
SPDK_DEBUGLOG(SPDK_LOG_NVMF_FC_LS, "LS cmd=%d\n", w0->ls_cmd);
switch (w0->ls_cmd) {
case FCNVME_LS_CREATE_ASSOCIATION:
nvmf_fc_ls_process_cass(s_id, tgtport, ls_rqst);
break;
case FCNVME_LS_CREATE_CONNECTION:
nvmf_fc_ls_process_cioc(tgtport, ls_rqst);
break;
case FCNVME_LS_DISCONNECT:
nvmf_fc_ls_process_disc(tgtport, ls_rqst);
break;
default:
SPDK_ERRLOG("Invalid LS cmd=%d\n", w0->ls_cmd);
ls_rqst->rsp_len = nvmf_fc_ls_format_rjt(ls_rqst->rspbuf.virt,
FCNVME_MAX_LS_BUFFER_SIZE, w0->ls_cmd,
FCNVME_RJT_RC_INVAL, FCNVME_RJT_EXP_NONE, 0);
nvmf_fc_xmt_ls_rsp(tgtport, ls_rqst);
}
}
int
nvmf_fc_delete_association(struct spdk_nvmf_fc_nport *tgtport,
uint64_t assoc_id, bool send_abts, bool backend_initiated,
spdk_nvmf_fc_del_assoc_cb del_assoc_cb,
void *cb_data)
{
return _nvmf_fc_delete_association(tgtport, assoc_id, send_abts, backend_initiated,
del_assoc_cb, cb_data, false);
}
static void
nvmf_fc_poller_api_cb_event(void *arg)
{
struct spdk_nvmf_fc_poller_api_cb_info *cb_info =
(struct spdk_nvmf_fc_poller_api_cb_info *) arg;
assert(cb_info != NULL);
cb_info->cb_func(cb_info->cb_data, cb_info->ret);
}
static void
nvmf_fc_poller_api_perform_cb(struct spdk_nvmf_fc_poller_api_cb_info *cb_info,
enum spdk_nvmf_fc_poller_api_ret ret)
{
if (cb_info->cb_func && cb_info->cb_thread) {
cb_info->ret = ret;
/* callback to master thread */
spdk_thread_send_msg(cb_info->cb_thread, nvmf_fc_poller_api_cb_event,
(void *) cb_info);
}
}
static void
nvmf_fc_poller_api_add_connection(void *arg)
{
enum spdk_nvmf_fc_poller_api_ret ret = SPDK_NVMF_FC_POLLER_API_SUCCESS;
struct spdk_nvmf_fc_poller_api_add_connection_args *conn_args =
(struct spdk_nvmf_fc_poller_api_add_connection_args *)arg;
struct spdk_nvmf_fc_conn *fc_conn;
SPDK_DEBUGLOG(SPDK_LOG_NVMF_FC_POLLER_API, "Poller add connection, conn_id 0x%lx\n",
conn_args->fc_conn->conn_id);
/* make sure connection is not already in poller's list */
fc_conn = nvmf_fc_hwqp_find_fc_conn(conn_args->fc_conn->hwqp,
conn_args->fc_conn->conn_id);
if (fc_conn) {
SPDK_ERRLOG("duplicate connection found");
ret = SPDK_NVMF_FC_POLLER_API_DUP_CONN_ID;
} else {
SPDK_DEBUGLOG(SPDK_LOG_NVMF_FC_POLLER_API,
"conn_id=%lx", fc_conn->conn_id);
TAILQ_INSERT_TAIL(&conn_args->fc_conn->hwqp->connection_list,
conn_args->fc_conn, link);
}
/* perform callback */
nvmf_fc_poller_api_perform_cb(&conn_args->cb_info, ret);
}
static void
nvmf_fc_poller_api_quiesce_queue(void *arg)
{
struct spdk_nvmf_fc_poller_api_quiesce_queue_args *q_args =
(struct spdk_nvmf_fc_poller_api_quiesce_queue_args *) arg;
struct spdk_nvmf_fc_request *fc_req = NULL, *tmp;
/* should be already, but make sure queue is quiesced */
q_args->hwqp->state = SPDK_FC_HWQP_OFFLINE;
/*
* Kill all the outstanding commands that are in the transfer state and
* in the process of being aborted.
* We can run into this situation if an adapter reset happens when an I_T Nexus delete
* is in progress.
*/
TAILQ_FOREACH_SAFE(fc_req, &q_args->hwqp->in_use_reqs, link, tmp) {
if (nvmf_fc_req_in_xfer(fc_req) && fc_req->is_aborted == true) {
nvmf_fc_poller_api_func(q_args->hwqp, SPDK_NVMF_FC_POLLER_API_REQ_ABORT_COMPLETE,
(void *)fc_req);
}
}
/* perform callback */
nvmf_fc_poller_api_perform_cb(&q_args->cb_info, SPDK_NVMF_FC_POLLER_API_SUCCESS);
}
static void
nvmf_fc_poller_api_activate_queue(void *arg)
{
struct spdk_nvmf_fc_poller_api_quiesce_queue_args *q_args =
(struct spdk_nvmf_fc_poller_api_quiesce_queue_args *) arg;
q_args->hwqp->state = SPDK_FC_HWQP_ONLINE;
/* perform callback */
nvmf_fc_poller_api_perform_cb(&q_args->cb_info, 0);
}
static void
nvmf_fc_disconnect_qpair_cb(void *ctx)
{
struct spdk_nvmf_fc_poller_api_cb_info *cb_info = ctx;
/* perform callback */
nvmf_fc_poller_api_perform_cb(cb_info, SPDK_NVMF_FC_POLLER_API_SUCCESS);
}
static void
nvmf_fc_poller_conn_abort_done(void *hwqp, int32_t status, void *cb_args)
{
struct spdk_nvmf_fc_poller_api_del_connection_args *conn_args = cb_args;
if (conn_args->fc_request_cnt) {
conn_args->fc_request_cnt -= 1;
}
if (!conn_args->fc_request_cnt) {
if (!TAILQ_EMPTY(&conn_args->hwqp->connection_list)) {
/* All the requests for this connection are aborted. */
TAILQ_REMOVE(&conn_args->hwqp->connection_list, conn_args->fc_conn, link);
SPDK_DEBUGLOG(SPDK_LOG_NVMF_FC_POLLER_API, "Connection deleted, conn_id 0x%lx\n",
conn_args->fc_conn->conn_id);
if (!conn_args->backend_initiated) {
/* disconnect qpair from nvmf controller */
spdk_nvmf_qpair_disconnect(&conn_args->fc_conn->qpair,
nvmf_fc_disconnect_qpair_cb, &conn_args->cb_info);
}
} else {
/*
* Duplicate connection delete can happen if one is
* coming in via an association disconnect and the other
* is initiated by a port reset.
*/
SPDK_DEBUGLOG(SPDK_LOG_NVMF_FC_POLLER_API, "Duplicate conn delete.");
/* perform callback */
nvmf_fc_poller_api_perform_cb(&conn_args->cb_info, SPDK_NVMF_FC_POLLER_API_SUCCESS);
}
}
}
static void
nvmf_fc_poller_api_del_connection(void *arg)
{
struct spdk_nvmf_fc_poller_api_del_connection_args *conn_args =
(struct spdk_nvmf_fc_poller_api_del_connection_args *)arg;
struct spdk_nvmf_fc_conn *fc_conn;
struct spdk_nvmf_fc_request *fc_req = NULL, *tmp;
struct spdk_nvmf_fc_hwqp *hwqp = conn_args->hwqp;
SPDK_DEBUGLOG(SPDK_LOG_NVMF_FC_POLLER_API, "Poller delete connection, conn_id 0x%lx\n",
conn_args->fc_conn->conn_id);
/* find the connection in poller's list */
fc_conn = nvmf_fc_hwqp_find_fc_conn(hwqp, conn_args->fc_conn->conn_id);
if (!fc_conn) {
/* perform callback */
nvmf_fc_poller_api_perform_cb(&conn_args->cb_info, SPDK_NVMF_FC_POLLER_API_NO_CONN_ID);
return;
}
conn_args->fc_request_cnt = 0;
TAILQ_FOREACH_SAFE(fc_req, &hwqp->in_use_reqs, link, tmp) {
if (fc_req->fc_conn->conn_id == fc_conn->conn_id) {
if (nvmf_qpair_is_admin_queue(&fc_conn->qpair) &&
(fc_req->req.cmd->nvme_cmd.opc == SPDK_NVME_OPC_ASYNC_EVENT_REQUEST)) {
/* AER will be cleaned by spdk_nvmf_qpair_disconnect. */
continue;
}
conn_args->fc_request_cnt += 1;
nvmf_fc_request_abort(fc_req, conn_args->send_abts,
nvmf_fc_poller_conn_abort_done,
conn_args);
}
}
if (!conn_args->fc_request_cnt) {
SPDK_DEBUGLOG(SPDK_LOG_NVMF_FC_POLLER_API, "Connection deleted.\n");
TAILQ_REMOVE(&hwqp->connection_list, fc_conn, link);
if (!conn_args->backend_initiated) {
/* disconnect qpair from nvmf controller */
spdk_nvmf_qpair_disconnect(&fc_conn->qpair, nvmf_fc_disconnect_qpair_cb,
&conn_args->cb_info);
}
}
}
static void
nvmf_fc_poller_abts_done(void *hwqp, int32_t status, void *cb_args)
{
struct spdk_nvmf_fc_poller_api_abts_recvd_args *args = cb_args;
SPDK_DEBUGLOG(SPDK_LOG_NVMF_FC_POLLER_API,
"ABTS poller done, rpi: 0x%x, oxid: 0x%x, rxid: 0x%x\n",
args->ctx->rpi, args->ctx->oxid, args->ctx->rxid);
nvmf_fc_poller_api_perform_cb(&args->cb_info,
SPDK_NVMF_FC_POLLER_API_SUCCESS);
}
static void
nvmf_fc_poller_api_abts_received(void *arg)
{
struct spdk_nvmf_fc_poller_api_abts_recvd_args *args = arg;
struct spdk_nvmf_fc_request *fc_req = NULL;
struct spdk_nvmf_fc_hwqp *hwqp = args->hwqp;
TAILQ_FOREACH(fc_req, &hwqp->in_use_reqs, link) {
if ((fc_req->rpi == args->ctx->rpi) &&
(fc_req->oxid == args->ctx->oxid)) {
nvmf_fc_request_abort(fc_req, false,
nvmf_fc_poller_abts_done, args);
return;
}
}
nvmf_fc_poller_api_perform_cb(&args->cb_info,
SPDK_NVMF_FC_POLLER_API_OXID_NOT_FOUND);
}
static void
nvmf_fc_poller_api_queue_sync(void *arg)
{
struct spdk_nvmf_fc_poller_api_queue_sync_args *args = arg;
SPDK_DEBUGLOG(SPDK_LOG_NVMF_FC_POLLER_API,
"HWQP sync requested for u_id = 0x%lx\n", args->u_id);
/* Add this args to hwqp sync_cb list */
TAILQ_INSERT_TAIL(&args->hwqp->sync_cbs, args, link);
}
static void
nvmf_fc_poller_api_queue_sync_done(void *arg)
{
struct spdk_nvmf_fc_poller_api_queue_sync_done_args *args = arg;
struct spdk_nvmf_fc_hwqp *hwqp = args->hwqp;
uint64_t tag = args->tag;
struct spdk_nvmf_fc_poller_api_queue_sync_args *sync_args = NULL, *tmp = NULL;
assert(args != NULL);
TAILQ_FOREACH_SAFE(sync_args, &hwqp->sync_cbs, link, tmp) {
if (sync_args->u_id == tag) {
/* Queue successfully synced. Remove from cb list */
TAILQ_REMOVE(&hwqp->sync_cbs, sync_args, link);
SPDK_DEBUGLOG(SPDK_LOG_NVMF_FC_POLLER_API,
"HWQP sync done for u_id = 0x%lx\n", sync_args->u_id);
/* Return the status to poller */
nvmf_fc_poller_api_perform_cb(&sync_args->cb_info,
SPDK_NVMF_FC_POLLER_API_SUCCESS);
return;
}
}
free(arg);
/* note: no callback from this api */
}
static void
nvmf_fc_poller_api_add_hwqp(void *arg)
{
struct spdk_nvmf_fc_hwqp *hwqp = (struct spdk_nvmf_fc_hwqp *)arg;
hwqp->lcore_id = spdk_env_get_current_core(); /* for tracing purposes only */
TAILQ_INSERT_TAIL(&hwqp->fgroup->hwqp_list, hwqp, link);
/* note: no callback from this api */
}
static void
nvmf_fc_poller_api_remove_hwqp(void *arg)
{
struct spdk_nvmf_fc_hwqp *hwqp = (struct spdk_nvmf_fc_hwqp *)arg;
struct spdk_nvmf_fc_poll_group *fgroup = hwqp->fgroup;
TAILQ_REMOVE(&fgroup->hwqp_list, hwqp, link);
hwqp->fgroup = NULL;
/* note: no callback from this api */
}
enum spdk_nvmf_fc_poller_api_ret
nvmf_fc_poller_api_func(struct spdk_nvmf_fc_hwqp *hwqp, enum spdk_nvmf_fc_poller_api api,
void *api_args) {
switch (api)
{
case SPDK_NVMF_FC_POLLER_API_ADD_CONNECTION:
spdk_thread_send_msg(hwqp->thread,
nvmf_fc_poller_api_add_connection, api_args);
break;
case SPDK_NVMF_FC_POLLER_API_DEL_CONNECTION:
spdk_thread_send_msg(hwqp->thread,
nvmf_fc_poller_api_del_connection, api_args);
break;
case SPDK_NVMF_FC_POLLER_API_QUIESCE_QUEUE:
/* quiesce q polling now, don't wait for poller to do it */
hwqp->state = SPDK_FC_HWQP_OFFLINE;
spdk_thread_send_msg(hwqp->thread,
nvmf_fc_poller_api_quiesce_queue, api_args);
break;
case SPDK_NVMF_FC_POLLER_API_ACTIVATE_QUEUE:
spdk_thread_send_msg(hwqp->thread,
nvmf_fc_poller_api_activate_queue, api_args);
break;
case SPDK_NVMF_FC_POLLER_API_ABTS_RECEIVED:
spdk_thread_send_msg(hwqp->thread,
nvmf_fc_poller_api_abts_received, api_args);
break;
case SPDK_NVMF_FC_POLLER_API_REQ_ABORT_COMPLETE:
spdk_thread_send_msg(hwqp->thread,
nvmf_fc_request_abort_complete, api_args);
break;
case SPDK_NVMF_FC_POLLER_API_QUEUE_SYNC:
spdk_thread_send_msg(hwqp->thread,
nvmf_fc_poller_api_queue_sync, api_args);
break;
case SPDK_NVMF_FC_POLLER_API_QUEUE_SYNC_DONE:
spdk_thread_send_msg(hwqp->thread,
nvmf_fc_poller_api_queue_sync_done, api_args);
break;
case SPDK_NVMF_FC_POLLER_API_ADD_HWQP:
spdk_thread_send_msg(hwqp->thread, nvmf_fc_poller_api_add_hwqp, (void *) hwqp);
break;
case SPDK_NVMF_FC_POLLER_API_REMOVE_HWQP:
spdk_thread_send_msg(hwqp->thread, nvmf_fc_poller_api_remove_hwqp, (void *) hwqp);
break;
case SPDK_NVMF_FC_POLLER_API_ADAPTER_EVENT:
case SPDK_NVMF_FC_POLLER_API_AEN:
default:
SPDK_ERRLOG("BAD ARG!");
return SPDK_NVMF_FC_POLLER_API_INVALID_ARG;
}
return SPDK_NVMF_FC_POLLER_API_SUCCESS;
}
SPDK_LOG_REGISTER_COMPONENT("nvmf_fc_poller_api", SPDK_LOG_NVMF_FC_POLLER_API)
SPDK_LOG_REGISTER_COMPONENT("nvmf_fc_ls", SPDK_LOG_NVMF_FC_LS)
|