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
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
|
/*-
* Copyright(c) 2002-2011 Exar Corp.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification are permitted provided the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. 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.
*
* 3. Neither the name of the Exar 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.
*/
/*$FreeBSD$*/
#include <dev/vxge/vxgehal/vxgehal.h>
/*
* __hal_fifo_mempool_item_alloc - Allocate List blocks for TxD list callback
* @mempoolh: Handle to memory pool
* @memblock: Address of this memory block
* @memblock_index: Index of this memory block
* @dma_object: dma object for this block
* @item: Pointer to this item
* @index: Index of this item in memory block
* @is_last: If this is last item in the block
* @userdata: Specific data of user
*
* This function is callback passed to __hal_mempool_create to create memory
* pool for TxD list
*/
static vxge_hal_status_e
__hal_fifo_mempool_item_alloc(
vxge_hal_mempool_h mempoolh,
void *memblock,
u32 memblock_index,
vxge_hal_mempool_dma_t *dma_object,
void *item,
u32 item_index,
u32 is_last,
void *userdata)
{
u32 i;
void *block_priv;
u32 memblock_item_idx;
__hal_fifo_t *fifo = (__hal_fifo_t *) userdata;
vxge_assert(fifo != NULL);
vxge_assert(item);
#if (VXGE_COMPONENT_HAL_POOL & VXGE_DEBUG_MODULE_MASK)
{
__hal_device_t *hldev = (__hal_device_t *) fifo->channel.devh;
vxge_hal_trace_log_pool("==> %s:%s:%d",
__FILE__, __func__, __LINE__);
vxge_hal_trace_log_pool(
"mempoolh = 0x"VXGE_OS_STXFMT", "
"memblock = 0x"VXGE_OS_STXFMT", memblock_index = %d, "
"dma_object = 0x"VXGE_OS_STXFMT", \
item = 0x"VXGE_OS_STXFMT", "
"item_index = %d, is_last = %d, userdata = 0x"VXGE_OS_STXFMT,
(ptr_t) mempoolh, (ptr_t) memblock, memblock_index,
(ptr_t) dma_object, (ptr_t) item, item_index, is_last,
(ptr_t) userdata);
}
#endif
block_priv = __hal_mempool_item_priv((vxge_hal_mempool_t *) mempoolh,
memblock_index, item, &memblock_item_idx);
vxge_assert(block_priv != NULL);
for (i = 0; i < fifo->txdl_per_memblock; i++) {
__hal_fifo_txdl_priv_t *txdl_priv;
vxge_hal_fifo_txd_t *txdp;
int dtr_index = item_index * fifo->txdl_per_memblock + i;
txdp = (vxge_hal_fifo_txd_t *) ((void *)
((char *) item + i * fifo->txdl_size));
txdp->host_control = dtr_index;
fifo->channel.dtr_arr[dtr_index].dtr = txdp;
fifo->channel.dtr_arr[dtr_index].uld_priv = (void *)
((char *) block_priv + fifo->txdl_priv_size * i);
fifo->channel.dtr_arr[dtr_index].hal_priv = (void *)
(((char *) fifo->channel.dtr_arr[dtr_index].uld_priv) +
fifo->per_txdl_space);
txdl_priv = (__hal_fifo_txdl_priv_t *)
fifo->channel.dtr_arr[dtr_index].hal_priv;
vxge_assert(txdl_priv);
/* pre-format HAL's TxDL's private */
/* LINTED */
txdl_priv->dma_offset = (char *) txdp - (char *) memblock;
txdl_priv->dma_addr = dma_object->addr + txdl_priv->dma_offset;
txdl_priv->dma_handle = dma_object->handle;
txdl_priv->memblock = memblock;
txdl_priv->first_txdp = (vxge_hal_fifo_txd_t *) txdp;
txdl_priv->next_txdl_priv = NULL;
txdl_priv->dang_txdl = NULL;
txdl_priv->dang_frags = 0;
txdl_priv->alloc_frags = 0;
#if defined(VXGE_DEBUG_ASSERT)
txdl_priv->dma_object = dma_object;
#endif
#if defined(VXGE_HAL_ALIGN_XMIT)
txdl_priv->align_vaddr = NULL;
txdl_priv->align_dma_addr = (dma_addr_t) 0;
#ifndef VXGE_HAL_ALIGN_XMIT_ALLOC_RT
/* CONSTCOND */
if (TRUE) {
vxge_hal_status_e status;
if (fifo->config->alignment_size) {
status = __hal_fifo_txdl_align_alloc_map(fifo,
txdp);
if (status != VXGE_HAL_OK) {
#if (VXGE_COMPONENT_HAL_POOL & VXGE_DEBUG_MODULE_MASK)
__hal_device_t *hldev;
hldev = (__hal_device_t *)
fifo->channel.devh;
vxge_hal_err_log_pool(
"align buffer[%d] %d bytes, \
status %d",
(item_index * fifo->txdl_per_memblock + i),
fifo->align_size, status);
vxge_hal_trace_log_pool(
"<== %s:%s:%d Result: 0",
__FILE__, __func__, __LINE__);
#endif
return (status);
}
}
}
#endif
#endif
if (fifo->txdl_init) {
fifo->txdl_init(fifo->channel.vph,
(vxge_hal_txdl_h) txdp,
VXGE_HAL_FIFO_ULD_PRIV(fifo, txdp),
VXGE_HAL_FIFO_TXDL_INDEX(txdp),
fifo->channel.userdata, VXGE_HAL_OPEN_NORMAL);
}
}
#if (VXGE_COMPONENT_HAL_POOL & VXGE_DEBUG_MODULE_MASK)
{
__hal_device_t *hldev = (__hal_device_t *) fifo->channel.devh;
vxge_hal_trace_log_pool("<== %s:%s:%d Result: 0",
__FILE__, __func__, __LINE__);
}
#endif
return (VXGE_HAL_OK);
}
/*
* __hal_fifo_mempool_item_free - Free List blocks for TxD list callback
* @mempoolh: Handle to memory pool
* @memblock: Address of this memory block
* @memblock_index: Index of this memory block
* @dma_object: dma object for this block
* @item: Pointer to this item
* @index: Index of this item in memory block
* @is_last: If this is last item in the block
* @userdata: Specific data of user
*
* This function is callback passed to __hal_mempool_free to destroy memory
* pool for TxD list
*/
static vxge_hal_status_e
__hal_fifo_mempool_item_free(
vxge_hal_mempool_h mempoolh,
void *memblock,
u32 memblock_index,
vxge_hal_mempool_dma_t *dma_object,
void *item,
u32 item_index,
u32 is_last,
void *userdata)
{
vxge_assert(item);
#if (VXGE_COMPONENT_HAL_POOL & VXGE_DEBUG_MODULE_MASK)
{
__hal_fifo_t *fifo = (__hal_fifo_t *) userdata;
vxge_assert(fifo != NULL);
__hal_device_t *hldev = (__hal_device_t *) fifo->channel.devh;
vxge_hal_trace_log_pool("==> %s:%s:%d",
__FILE__, __func__, __LINE__);
vxge_hal_trace_log_pool("mempoolh = 0x"VXGE_OS_STXFMT", "
"memblock = 0x"VXGE_OS_STXFMT", memblock_index = %d, "
"dma_object = 0x"VXGE_OS_STXFMT", \
item = 0x"VXGE_OS_STXFMT", "
"item_index = %d, is_last = %d, userdata = 0x"VXGE_OS_STXFMT,
(ptr_t) mempoolh, (ptr_t) memblock, memblock_index,
(ptr_t) dma_object, (ptr_t) item, item_index, is_last,
(ptr_t) userdata);
}
#endif
#if defined(VXGE_HAL_ALIGN_XMIT)
{
__hal_fifo_t *fifo = (__hal_fifo_t *) userdata;
vxge_assert(fifo != NULL);
if (fifo->config->alignment_size) {
int i;
vxge_hal_fifo_txd_t *txdp;
for (i = 0; i < fifo->txdl_per_memblock; i++) {
txdp = (void *)
((char *) item + i * fifo->txdl_size);
__hal_fifo_txdl_align_free_unmap(fifo, txdp);
}
}
}
#endif
#if (VXGE_COMPONENT_HAL_POOL & VXGE_DEBUG_MODULE_MASK)
{
__hal_fifo_t *fifo = (__hal_fifo_t *) userdata;
vxge_assert(fifo != NULL);
__hal_device_t *hldev = (__hal_device_t *) fifo->channel.devh;
vxge_hal_trace_log_pool("<== %s:%s:%d Result: 0",
__FILE__, __func__, __LINE__);
}
#endif
return (VXGE_HAL_OK);
}
/*
* __hal_fifo_create - Create a FIFO
* @vpath_handle: Handle returned by virtual path open
* @attr: FIFO configuration parameters structure
*
* This function creates FIFO and initializes it.
*
*/
vxge_hal_status_e
__hal_fifo_create(
vxge_hal_vpath_h vpath_handle,
vxge_hal_fifo_attr_t *attr)
{
vxge_hal_status_e status;
__hal_fifo_t *fifo;
vxge_hal_fifo_config_t *config;
u32 txdl_size, memblock_size, txdl_per_memblock;
__hal_vpath_handle_t *vp = (__hal_vpath_handle_t *) vpath_handle;
__hal_device_t *hldev;
vxge_assert((vpath_handle != NULL) && (attr != NULL));
hldev = (__hal_device_t *) vp->vpath->hldev;
vxge_hal_trace_log_fifo("==> %s:%s:%d",
__FILE__, __func__, __LINE__);
vxge_hal_trace_log_fifo(
"vpath_handle = 0x"VXGE_OS_STXFMT", attr = 0x"VXGE_OS_STXFMT,
(ptr_t) vpath_handle, (ptr_t) attr);
if ((vpath_handle == NULL) || (attr == NULL)) {
vxge_hal_err_log_fifo("null pointer passed == > %s : %d",
__func__, __LINE__);
vxge_hal_trace_log_fifo("<== %s:%s:%d Result: %d",
__FILE__, __func__, __LINE__,
VXGE_HAL_ERR_INVALID_HANDLE);
return (VXGE_HAL_ERR_INVALID_HANDLE);
}
config =
&vp->vpath->hldev->header.config.vp_config[vp->vpath->vp_id].fifo;
txdl_size = config->max_frags * sizeof(vxge_hal_fifo_txd_t);
if (txdl_size <= VXGE_OS_HOST_PAGE_SIZE)
memblock_size = VXGE_OS_HOST_PAGE_SIZE;
else
memblock_size = txdl_size;
txdl_per_memblock = memblock_size / txdl_size;
config->fifo_length = ((config->fifo_length + txdl_per_memblock - 1) /
txdl_per_memblock) * txdl_per_memblock;
fifo = (__hal_fifo_t *) vxge_hal_channel_allocate(
(vxge_hal_device_h) vp->vpath->hldev,
vpath_handle,
VXGE_HAL_CHANNEL_TYPE_FIFO,
config->fifo_length,
attr->per_txdl_space,
attr->userdata);
if (fifo == NULL) {
vxge_hal_err_log_fifo("Memory allocation failed == > %s : %d",
__func__, __LINE__);
vxge_hal_trace_log_fifo("<== %s:%s:%d Result: %d",
__FILE__, __func__, __LINE__,
VXGE_HAL_ERR_OUT_OF_MEMORY);
return (VXGE_HAL_ERR_OUT_OF_MEMORY);
}
vp->vpath->fifoh = fifo;
fifo->stats = &vp->vpath->sw_stats->fifo_stats;
fifo->config = config;
fifo->memblock_size = memblock_size;
#if defined(VXGE_HAL_TX_MULTI_POST)
vxge_os_spin_lock_init(&fifo->channel.post_lock,
vp->vpath->hldev->header.pdev);
#elif defined(VXGE_HAL_TX_MULTI_POST_IRQ)
vxge_os_spin_lock_init_irq(&fifo->channel.post_lock,
vp->vpath->hldev->header.irqh);
#endif
fifo->align_size =
fifo->config->alignment_size * fifo->config->max_aligned_frags;
/* apply "interrupts per txdl" attribute */
fifo->interrupt_type = VXGE_HAL_FIFO_TXD_INT_TYPE_UTILZ;
if (fifo->config->intr) {
fifo->interrupt_type = VXGE_HAL_FIFO_TXD_INT_TYPE_PER_LIST;
}
fifo->no_snoop_bits = config->no_snoop_bits;
/*
* FIFO memory management strategy:
*
* TxDL splitted into three independent parts:
* - set of TxD's
* - TxD HAL private part
* - upper layer private part
*
* Adaptative memory allocation used. i.e. Memory allocated on
* demand with the size which will fit into one memory block.
* One memory block may contain more than one TxDL. In simple case
* memory block size can be equal to CPU page size. On more
* sophisticated OS's memory block can be contiguous across
* several pages.
*
* During "reserve" operations more memory can be allocated on demand
* for example due to FIFO full condition.
*
* Pool of memory memblocks never shrinks except __hal_fifo_close
* routine which will essentially stop channel and free the resources.
*/
/* TxDL common private size == TxDL private + ULD private */
fifo->txdl_priv_size =
sizeof(__hal_fifo_txdl_priv_t) + attr->per_txdl_space;
fifo->txdl_priv_size =
((fifo->txdl_priv_size + __vxge_os_cacheline_size - 1) /
__vxge_os_cacheline_size) * __vxge_os_cacheline_size;
fifo->per_txdl_space = attr->per_txdl_space;
/* recompute txdl size to be cacheline aligned */
fifo->txdl_size = txdl_size;
fifo->txdl_per_memblock = txdl_per_memblock;
/*
* since txdl_init() callback will be called from item_alloc(),
* the same way channels userdata might be used prior to
* channel_initialize()
*/
fifo->txdl_init = attr->txdl_init;
fifo->txdl_term = attr->txdl_term;
fifo->callback = attr->callback;
if (fifo->txdl_per_memblock == 0) {
__hal_fifo_delete(vpath_handle);
vxge_hal_trace_log_fifo("<== %s:%s:%d Result: %d",
__FILE__, __func__, __LINE__,
VXGE_HAL_ERR_INVALID_BLOCK_SIZE);
return (VXGE_HAL_ERR_INVALID_BLOCK_SIZE);
}
/* calculate actual TxDL block private size */
fifo->txdlblock_priv_size =
fifo->txdl_priv_size * fifo->txdl_per_memblock;
fifo->mempool =
vxge_hal_mempool_create((vxge_hal_device_h) vp->vpath->hldev,
fifo->memblock_size,
fifo->memblock_size,
fifo->txdlblock_priv_size,
fifo->config->fifo_length /
fifo->txdl_per_memblock,
fifo->config->fifo_length /
fifo->txdl_per_memblock,
__hal_fifo_mempool_item_alloc,
__hal_fifo_mempool_item_free,
fifo);
if (fifo->mempool == NULL) {
__hal_fifo_delete(vpath_handle);
vxge_hal_trace_log_fifo("<== %s:%s:%d Result: %d",
__FILE__, __func__, __LINE__, VXGE_HAL_ERR_OUT_OF_MEMORY);
return (VXGE_HAL_ERR_OUT_OF_MEMORY);
}
status = vxge_hal_channel_initialize(&fifo->channel);
if (status != VXGE_HAL_OK) {
__hal_fifo_delete(vpath_handle);
vxge_hal_trace_log_fifo("<== %s:%s:%d Result: %d",
__FILE__, __func__, __LINE__, status);
return (status);
}
vxge_hal_trace_log_fifo("<== %s:%s:%d Result: 0",
__FILE__, __func__, __LINE__);
return (VXGE_HAL_OK);
}
/*
* __hal_fifo_abort - Returns the TxD
* @fifoh: Fifo to be reset
* @reopen: See vxge_hal_reopen_e {}.
*
* This function terminates the TxDs of fifo
*/
void
__hal_fifo_abort(
vxge_hal_fifo_h fifoh,
vxge_hal_reopen_e reopen)
{
u32 i = 0;
__hal_fifo_t *fifo = (__hal_fifo_t *) fifoh;
__hal_device_t *hldev;
vxge_hal_txdl_h txdlh;
vxge_assert(fifoh != NULL);
hldev = (__hal_device_t *) fifo->channel.devh;
vxge_hal_trace_log_fifo("==> %s:%s:%d",
__FILE__, __func__, __LINE__);
vxge_hal_trace_log_fifo("fifo = 0x"VXGE_OS_STXFMT", reopen = %d",
(ptr_t) fifoh, reopen);
if (fifo->txdl_term) {
__hal_channel_for_each_dtr(&fifo->channel, txdlh, i) {
if (!__hal_channel_is_posted_dtr(&fifo->channel,
i)) {
fifo->txdl_term(fifo->channel.vph, txdlh,
VXGE_HAL_FIFO_ULD_PRIV(fifo, txdlh),
VXGE_HAL_TXDL_STATE_FREED,
fifo->channel.userdata,
reopen);
}
}
}
for (;;) {
__hal_channel_dtr_try_complete(&fifo->channel, &txdlh);
if (txdlh == NULL)
break;
__hal_channel_dtr_complete(&fifo->channel);
if (fifo->txdl_term) {
fifo->txdl_term(fifo->channel.vph, txdlh,
VXGE_HAL_FIFO_ULD_PRIV(fifo, txdlh),
VXGE_HAL_TXDL_STATE_POSTED,
fifo->channel.userdata,
reopen);
}
__hal_channel_dtr_free(&fifo->channel,
VXGE_HAL_FIFO_TXDL_INDEX(txdlh));
}
vxge_hal_trace_log_fifo("<== %s:%s:%d Result: 0",
__FILE__, __func__, __LINE__);
}
/*
* __hal_fifo_reset - Resets the fifo
* @fifoh: Fifo to be reset
*
* This function resets the fifo during vpath reset operation
*/
vxge_hal_status_e
__hal_fifo_reset(
vxge_hal_fifo_h fifoh)
{
vxge_hal_status_e status;
__hal_device_t *hldev;
__hal_fifo_t *fifo = (__hal_fifo_t *) fifoh;
vxge_assert(fifoh != NULL);
hldev = (__hal_device_t *) fifo->channel.devh;
vxge_hal_trace_log_fifo("==> %s:%s:%d",
__FILE__, __func__, __LINE__);
vxge_hal_trace_log_fifo("fifo = 0x"VXGE_OS_STXFMT,
(ptr_t) fifoh);
__hal_fifo_abort(fifoh, VXGE_HAL_RESET_ONLY);
status = __hal_channel_reset(&fifo->channel);
if (status != VXGE_HAL_OK) {
vxge_hal_trace_log_fifo("<== %s:%s:%d Result: %d",
__FILE__, __func__, __LINE__, status);
return (status);
}
vxge_hal_trace_log_fifo("<== %s:%s:%d Result: 0",
__FILE__, __func__, __LINE__);
return (VXGE_HAL_OK);
}
/*
* vxge_hal_fifo_doorbell_reset - Resets the doorbell fifo
* @vapth_handle: Vpath Handle
*
* This function resets the doorbell fifo during if fifo error occurs
*/
vxge_hal_status_e
vxge_hal_fifo_doorbell_reset(
vxge_hal_vpath_h vpath_handle)
{
u32 i;
vxge_hal_txdl_h txdlh;
__hal_fifo_t *fifo;
__hal_virtualpath_t *vpath;
__hal_fifo_txdl_priv_t *txdl_priv;
__hal_device_t *hldev;
__hal_vpath_handle_t *vp = (__hal_vpath_handle_t *) vpath_handle;
vxge_hal_status_e status = VXGE_HAL_OK;
vxge_assert(vpath_handle != NULL);
hldev = vp->vpath->hldev;
vxge_hal_trace_log_fifo("==> %s:%s:%d",
__FILE__, __func__, __LINE__);
vxge_hal_trace_log_fifo("vpath_handle = 0x"VXGE_OS_STXFMT,
(ptr_t) vpath_handle);
fifo = (__hal_fifo_t *) vp->vpath->fifoh;
vpath = ((__hal_vpath_handle_t *) fifo->channel.vph)->vpath;
status = __hal_non_offload_db_reset(fifo->channel.vph);
if (status != VXGE_HAL_OK) {
vxge_hal_trace_log_fifo("<== %s:%s:%d Result: 0",
__FILE__, __func__, __LINE__);
return (status);
}
__hal_channel_for_each_posted_dtr(&fifo->channel, txdlh, i) {
txdl_priv = VXGE_HAL_FIFO_HAL_PRIV(fifo, txdlh);
__hal_non_offload_db_post(fifo->channel.vph,
((VXGE_HAL_FIFO_TXD_NO_BW_LIMIT_GET(
((vxge_hal_fifo_txd_t *) txdlh)->control_1)) ?
(((u64) txdl_priv->dma_addr) | 0x1) :
(u64) txdl_priv->dma_addr),
txdl_priv->frags - 1,
vpath->vp_config->fifo.no_snoop_bits);
}
vxge_hal_trace_log_fifo("<== %s:%s:%d Result: 0",
__FILE__, __func__, __LINE__);
return (status);
}
/*
* __hal_fifo_delete - Removes the FIFO
* @vpath_handle: Virtual path handle to which this queue belongs
*
* This function freeup the memory pool and removes the FIFO
*/
void
__hal_fifo_delete(
vxge_hal_vpath_h vpath_handle)
{
__hal_vpath_handle_t *vp = (__hal_vpath_handle_t *) vpath_handle;
__hal_fifo_t *fifo;
__hal_device_t *hldev;
vxge_assert(vpath_handle != NULL);
hldev = vp->vpath->hldev;
vxge_hal_trace_log_fifo("==> %s:%s:%d",
__FILE__, __func__, __LINE__);
vxge_hal_trace_log_fifo("vpath_handle = 0x"VXGE_OS_STXFMT,
(ptr_t) vpath_handle);
fifo = (__hal_fifo_t *) vp->vpath->fifoh;
vxge_assert(fifo != NULL);
if (fifo->mempool) {
__hal_fifo_abort(vp->vpath->fifoh, VXGE_HAL_OPEN_NORMAL);
vxge_hal_mempool_destroy(fifo->mempool);
}
vxge_hal_channel_terminate(&fifo->channel);
#if defined(VXGE_HAL_TX_MULTI_POST)
vxge_os_spin_lock_destroy(&fifo->channel.post_lock,
vp->vpath->hldev->header.pdev);
#elif defined(VXGE_HAL_TX_MULTI_POST_IRQ)
vxge_os_spin_lock_destroy_irq(&fifo->channel.post_lock,
vp->vpath->hldev->header.pdev);
#endif
vxge_hal_channel_free(&fifo->channel);
vxge_hal_trace_log_fifo("<== %s:%s:%d Result: 0",
__FILE__, __func__, __LINE__);
}
#if defined(VXGE_HAL_ALIGN_XMIT)
/*
* __hal_fifo_txdl_align_free_unmap - Unmap the alignement buffers
* @fifo: Fifo
* @txdp: txdl
*
* This function unmaps dma memory for the alignment buffers
*/
void
__hal_fifo_txdl_align_free_unmap(
__hal_fifo_t *fifo,
vxge_hal_fifo_txd_t *txdp)
{
__hal_device_t *hldev;
__hal_fifo_txdl_priv_t *txdl_priv;
vxge_assert((fifo != NULL) && (txdp != NULL));
hldev = (__hal_device_t *) fifo->channel.devh;
vxge_hal_trace_log_fifo("==> %s:%s:%d",
__FILE__, __func__, __LINE__);
vxge_hal_trace_log_fifo(
"fifo = 0x"VXGE_OS_STXFMT", txdp = 0x"VXGE_OS_STXFMT,
(ptr_t) fifo, (ptr_t) txdp);
txdl_priv = VXGE_HAL_FIFO_HAL_PRIV(fifo, txdp);
if (txdl_priv->align_vaddr != NULL) {
__hal_blockpool_free(fifo->channel.devh,
txdl_priv->align_vaddr,
fifo->align_size,
&txdl_priv->align_dma_addr,
&txdl_priv->align_dma_handle,
&txdl_priv->align_dma_acch);
txdl_priv->align_vaddr = NULL;
txdl_priv->align_dma_addr = 0;
}
vxge_hal_trace_log_fifo("<== %s:%s:%d Result: 0",
__FILE__, __func__, __LINE__);
}
/*
* __hal_fifo_txdl_align_alloc_map - Maps the alignement buffers
* @fifo: Fifo
* @txdp: txdl
*
* This function maps dma memory for the alignment buffers
*/
vxge_hal_status_e
__hal_fifo_txdl_align_alloc_map(
__hal_fifo_t *fifo,
vxge_hal_fifo_txd_t *txdp)
{
__hal_device_t *hldev;
__hal_fifo_txdl_priv_t *txdl_priv;
vxge_assert((fifo != NULL) && (txdp != NULL));
hldev = (__hal_device_t *) fifo->channel.devh;
vxge_hal_trace_log_fifo("==> %s:%s:%d",
__FILE__, __func__, __LINE__);
vxge_hal_trace_log_fifo(
"fifo = 0x"VXGE_OS_STXFMT", txdp = 0x"VXGE_OS_STXFMT,
(ptr_t) fifo, (ptr_t) txdp);
txdl_priv = VXGE_HAL_FIFO_HAL_PRIV(fifo, txdp);
/* allocate alignment DMA-buffer */
txdl_priv->align_vaddr =
(u8 *) __hal_blockpool_malloc(fifo->channel.devh,
fifo->align_size,
&txdl_priv->align_dma_addr,
&txdl_priv->align_dma_handle,
&txdl_priv->align_dma_acch);
if (txdl_priv->align_vaddr == NULL) {
vxge_hal_trace_log_fifo("<== %s:%s:%d Result: %d",
__FILE__, __func__, __LINE__, VXGE_HAL_ERR_OUT_OF_MEMORY);
return (VXGE_HAL_ERR_OUT_OF_MEMORY);
}
vxge_hal_trace_log_fifo("<== %s:%s:%d Result: 0",
__FILE__, __func__, __LINE__);
return (VXGE_HAL_OK);
}
#endif
/*
* vxge_hal_fifo_free_txdl_count_get - returns the number of txdls
* available in the fifo
* @vpath_handle: Virtual path handle.
*/
u32
vxge_hal_fifo_free_txdl_count_get(vxge_hal_vpath_h vpath_handle)
{
return __hal_channel_free_dtr_count(&((__hal_fifo_t *)
((__hal_vpath_handle_t *) vpath_handle)->vpath->fifoh)->channel);
}
/*
* vxge_hal_fifo_txdl_private_get - Retrieve per-descriptor private data.
* @vpath_handle: Virtual path handle.
* @txdlh: Descriptor handle.
*
* Retrieve per-descriptor private data.
* Note that ULD requests per-descriptor space via
* vxge_hal_fifo_attr_t passed to
* vxge_hal_vpath_open().
*
* Returns: private ULD data associated with the descriptor.
*/
void *
vxge_hal_fifo_txdl_private_get(
vxge_hal_vpath_h vpath_handle,
vxge_hal_txdl_h txdlh)
{
return (VXGE_HAL_FIFO_ULD_PRIV(((__hal_fifo_t *)
((__hal_vpath_handle_t *) vpath_handle)->vpath->fifoh), txdlh));
}
/*
* vxge_hal_fifo_txdl_reserve - Reserve fifo descriptor.
* @vapth_handle: virtual path handle.
* @txdlh: Reserved descriptor. On success HAL fills this "out" parameter
* with a valid handle.
* @txdl_priv: Buffer to return the pointer to per txdl space
*
* Reserve a single TxDL (that is, fifo descriptor)
* for the subsequent filling-in by upper layerdriver (ULD))
* and posting on the corresponding channel (@channelh)
* via vxge_hal_fifo_txdl_post().
*
* Note: it is the responsibility of ULD to reserve multiple descriptors
* for lengthy (e.g., LSO) transmit operation. A single fifo descriptor
* carries up to configured number (fifo.max_frags) of contiguous buffers.
*
* Returns: VXGE_HAL_OK - success;
* VXGE_HAL_INF_OUT_OF_DESCRIPTORS - Currently no descriptors available
*
*/
vxge_hal_status_e
vxge_hal_fifo_txdl_reserve(
vxge_hal_vpath_h vpath_handle,
vxge_hal_txdl_h *txdlh,
void **txdl_priv)
{
u32 i;
__hal_vpath_handle_t *vp = (__hal_vpath_handle_t *) vpath_handle;
__hal_device_t *hldev;
__hal_fifo_t *fifo;
vxge_hal_status_e status;
#if defined(VXGE_HAL_TX_MULTI_POST_IRQ)
unsigned long flags = 0;
#endif
vxge_assert((vpath_handle != NULL) && (txdlh != NULL));
hldev = vp->vpath->hldev;
vxge_hal_trace_log_fifo("==> %s:%s:%d",
__FILE__, __func__, __LINE__);
vxge_hal_trace_log_fifo(
"vpath_handle = 0x"VXGE_OS_STXFMT", txdlh = 0x"VXGE_OS_STXFMT,
(ptr_t) vpath_handle, (ptr_t) txdlh);
fifo = (__hal_fifo_t *) vp->vpath->fifoh;
vxge_assert(fifo != NULL);
#if defined(VXGE_HAL_TX_MULTI_POST)
vxge_os_spin_lock(&fifo->channel.post_lock);
#elif defined(VXGE_HAL_TX_MULTI_POST_IRQ)
vxge_os_spin_lock_irq(&fifo->channel.post_lock, flags);
#endif
status = __hal_channel_dtr_reserve(&fifo->channel, txdlh);
#if defined(VXGE_HAL_TX_MULTI_POST)
vxge_os_spin_unlock(&fifo->channel.post_lock);
#elif defined(VXGE_HAL_TX_MULTI_POST_IRQ)
vxge_os_spin_unlock_irq(&fifo->channel.post_lock, flags);
#endif
if (status == VXGE_HAL_OK) {
vxge_hal_fifo_txd_t *txdp = (vxge_hal_fifo_txd_t *)*txdlh;
__hal_fifo_txdl_priv_t *priv;
priv = VXGE_HAL_FIFO_HAL_PRIV(fifo, txdp);
/* reset the TxDL's private */
priv->align_dma_offset = 0;
priv->align_vaddr_start = priv->align_vaddr;
priv->align_used_frags = 0;
priv->frags = 0;
priv->alloc_frags = fifo->config->max_frags;
priv->dang_txdl = NULL;
priv->dang_frags = 0;
priv->next_txdl_priv = NULL;
priv->bytes_sent = 0;
*txdl_priv = VXGE_HAL_FIFO_ULD_PRIV(fifo, txdp);
for (i = 0; i < fifo->config->max_frags; i++) {
txdp = ((vxge_hal_fifo_txd_t *)*txdlh) + i;
txdp->control_0 = txdp->control_1 = 0;
}
#if defined(VXGE_OS_MEMORY_CHECK)
priv->allocated = 1;
#endif
}
vxge_hal_trace_log_fifo("<== %s:%s:%d Result: 0",
__FILE__, __func__, __LINE__);
return (status);
}
/*
* vxge_hal_fifo_txdl_buffer_set - Set transmit buffer pointer in the
* descriptor.
* @vpath_handle: virtual path handle.
* @txdlh: Descriptor handle.
* @frag_idx: Index of the data buffer in the caller's scatter-gather list
* (of buffers).
* @dma_pointer: DMA address of the data buffer referenced by @frag_idx.
* @size: Size of the data buffer (in bytes).
*
* This API is part of the preparation of the transmit descriptor for posting
* (via vxge_hal_fifo_txdl_post()). The related "preparation" APIs include
* vxge_hal_fifo_txdl_mss_set() and vxge_hal_fifo_txdl_cksum_set_bits().
* All three APIs fill in the fields of the fifo descriptor,
* in accordance with the X3100 specification.
*
*/
void
vxge_hal_fifo_txdl_buffer_set(
vxge_hal_vpath_h vpath_handle,
vxge_hal_txdl_h txdlh,
u32 frag_idx,
dma_addr_t dma_pointer,
unsigned long size)
{
__hal_vpath_handle_t *vp = (__hal_vpath_handle_t *) vpath_handle;
__hal_fifo_t *fifo;
__hal_device_t *hldev;
__hal_fifo_txdl_priv_t *txdl_priv;
vxge_hal_fifo_txd_t *txdp;
vxge_assert((vpath_handle != NULL) && (txdlh != NULL) &&
(dma_pointer != 0) && (size != 0));
hldev = vp->vpath->hldev;
vxge_hal_trace_log_fifo("==> %s:%s:%d",
__FILE__, __func__, __LINE__);
vxge_hal_trace_log_fifo("vpath_handle = 0x"VXGE_OS_STXFMT", "
"txdlh = 0x"VXGE_OS_STXFMT", frag_idx = %d, "
"dma_pointer = 0x"VXGE_OS_LLXFMT", size = %lu",
(ptr_t) vpath_handle, (ptr_t) txdlh,
frag_idx, (u64) dma_pointer, size);
fifo = (__hal_fifo_t *) vp->vpath->fifoh;
vxge_assert(fifo != NULL);
txdl_priv = VXGE_HAL_FIFO_HAL_PRIV(fifo, txdlh);
txdp = (vxge_hal_fifo_txd_t *) txdlh + txdl_priv->frags;
/*
* Note:
* it is the responsibility of upper layers and not HAL
* detect it and skip zero-size fragment
*/
vxge_assert(size > 0);
vxge_assert(frag_idx < txdl_priv->alloc_frags);
txdp->buffer_pointer = (u64) dma_pointer;
txdp->control_0 |= VXGE_HAL_FIFO_TXD_BUFFER_SIZE(size);
txdl_priv->bytes_sent += size;
fifo->stats->total_buffers++;
txdl_priv->frags++;
vxge_hal_trace_log_fifo("<== %s:%s:%d Result: 0",
__FILE__, __func__, __LINE__);
}
/*
* vxge_hal_fifo_txdl_buffer_set_aligned - Align transmit buffer and fill
* in fifo descriptor.
* @vpath_handle: Virtual path handle.
* @txdlh: Descriptor handle.
* @frag_idx: Index of the data buffer in the caller's scatter-gather list
* (of buffers).
* @vaddr: Virtual address of the data buffer.
* @dma_pointer: DMA address of the data buffer referenced by @frag_idx.
* @size: Size of the data buffer (in bytes).
* @misaligned_size: Size (in bytes) of the misaligned portion of the
* data buffer. Calculated by the caller, based on the platform/OS/other
* specific criteria, which is outside of HAL's domain. See notes below.
*
* This API is part of the transmit descriptor preparation for posting
* (via vxge_hal_fifo_txdl_post()). The related "preparation" APIs include
* vxge_hal_fifo_txdl_mss_set() and vxge_hal_fifo_txdl_cksum_set_bits().
* All three APIs fill in the fields of the fifo descriptor,
* in accordance with the X3100 specification.
* On the PCI-X based systems aligning transmit data typically provides better
* transmit performance. The typical alignment granularity: L2 cacheline size.
* However, HAL does not make assumptions in terms of the alignment granularity;
* this is specified via additional @misaligned_size parameter described above.
* Prior to calling vxge_hal_fifo_txdl_buffer_set_aligned(),
* ULD is supposed to check alignment of a given fragment/buffer. For this HAL
* provides a separate vxge_hal_check_alignment() API sufficient to cover
* most (but not all) possible alignment criteria.
* If the buffer appears to be aligned, the ULD calls
* vxge_hal_fifo_txdl_buffer_set().
* Otherwise, ULD calls vxge_hal_fifo_txdl_buffer_set_aligned().
*
* Note; This API is a "superset" of vxge_hal_fifo_txdl_buffer_set(). In
* addition to filling in the specified descriptor it aligns transmit data on
* the specified boundary.
* Note: Decision on whether to align or not to align a given contiguous
* transmit buffer is outside of HAL's domain. To this end ULD can use any
* programmable criteria, which can help to 1) boost transmit performance,
* and/or 2) provide a workaround for PCI bridge bugs, if any.
*
*/
vxge_hal_status_e
vxge_hal_fifo_txdl_buffer_set_aligned(
vxge_hal_vpath_h vpath_handle,
vxge_hal_txdl_h txdlh,
u32 frag_idx,
void *vaddr,
dma_addr_t dma_pointer,
u32 size,
u32 misaligned_size)
{
__hal_vpath_handle_t *vp = (__hal_vpath_handle_t *) vpath_handle;
__hal_fifo_t *fifo;
__hal_device_t *hldev;
__hal_fifo_txdl_priv_t *txdl_priv;
vxge_hal_fifo_txd_t *txdp;
int remaining_size;
ptrdiff_t prev_boff;
vxge_assert((vpath_handle != NULL) && (txdlh != NULL) &&
(vaddr != NULL) && (dma_pointer != 0) &&
(size != 0) && (misaligned_size != 0));
hldev = vp->vpath->hldev;
vxge_hal_trace_log_fifo("==> %s:%s:%d",
__FILE__, __func__, __LINE__);
vxge_hal_trace_log_fifo(
"vpath_handle = 0x"VXGE_OS_STXFMT", txdlh = 0x"VXGE_OS_STXFMT", "
"frag_idx = %d, vaddr = 0x"VXGE_OS_STXFMT", "
"dma_pointer = 0x"VXGE_OS_LLXFMT", size = %d, "
"misaligned_size = %d", (ptr_t) vpath_handle,
(ptr_t) txdlh, frag_idx, (ptr_t) vaddr, (u64) dma_pointer, size,
misaligned_size);
fifo = (__hal_fifo_t *) vp->vpath->fifoh;
vxge_assert(fifo != NULL);
txdl_priv = VXGE_HAL_FIFO_HAL_PRIV(fifo, txdlh);
txdp = (vxge_hal_fifo_txd_t *) txdlh + txdl_priv->frags;
/*
* On some systems buffer size could be zero.
* It is the responsibility of ULD and *not HAL* to
* detect it and skip it.
*/
vxge_assert(size > 0);
vxge_assert(frag_idx < txdl_priv->alloc_frags);
vxge_assert(misaligned_size != 0 &&
misaligned_size <= fifo->config->alignment_size);
remaining_size = size - misaligned_size;
vxge_assert(remaining_size >= 0);
vxge_os_memcpy((char *) txdl_priv->align_vaddr_start,
vaddr, misaligned_size);
if (txdl_priv->align_used_frags >= fifo->config->max_aligned_frags) {
return (VXGE_HAL_ERR_OUT_ALIGNED_FRAGS);
}
/* setup new buffer */
/* LINTED */
prev_boff = txdl_priv->align_vaddr_start - txdl_priv->align_vaddr;
txdp->buffer_pointer = (u64) txdl_priv->align_dma_addr + prev_boff;
txdp->control_0 |= VXGE_HAL_FIFO_TXD_BUFFER_SIZE(misaligned_size);
txdl_priv->bytes_sent += misaligned_size;
fifo->stats->total_buffers++;
txdl_priv->frags++;
txdl_priv->align_used_frags++;
txdl_priv->align_vaddr_start += fifo->config->alignment_size;
txdl_priv->align_dma_offset = 0;
#if defined(VXGE_OS_DMA_REQUIRES_SYNC)
/* sync new buffer */
vxge_os_dma_sync(fifo->channel.pdev,
txdl_priv->align_dma_handle,
txdp->buffer_pointer,
0,
misaligned_size,
VXGE_OS_DMA_DIR_TODEVICE);
#endif
if (remaining_size) {
vxge_assert(frag_idx < txdl_priv->alloc_frags);
txdp++;
txdp->buffer_pointer = (u64) dma_pointer + misaligned_size;
txdp->control_0 |=
VXGE_HAL_FIFO_TXD_BUFFER_SIZE(remaining_size);
txdl_priv->bytes_sent += remaining_size;
fifo->stats->total_buffers++;
txdl_priv->frags++;
}
vxge_hal_trace_log_fifo("<== %s:%s:%d Result: 0",
__FILE__, __func__, __LINE__);
return (VXGE_HAL_OK);
}
/*
* vxge_hal_fifo_txdl_buffer_append - Append the contents of virtually
* contiguous data buffer to a single physically contiguous buffer.
* @vpath_handle: Virtual path handle.
* @txdlh: Descriptor handle.
* @vaddr: Virtual address of the data buffer.
* @size: Size of the data buffer (in bytes).
*
* This API is part of the transmit descriptor preparation for posting
* (via vxge_hal_fifo_txdl_post()).
* The main difference of this API wrt to the APIs
* vxge_hal_fifo_txdl_buffer_set_aligned() is that this API appends the
* contents of virtually contiguous data buffers received from
* upper layer into a single physically contiguous data buffer and the
* device will do a DMA from this buffer.
*
* See Also: vxge_hal_fifo_txdl_buffer_finalize(),
* vxge_hal_fifo_txdl_buffer_set(),
* vxge_hal_fifo_txdl_buffer_set_aligned().
*/
vxge_hal_status_e
vxge_hal_fifo_txdl_buffer_append(
vxge_hal_vpath_h vpath_handle,
vxge_hal_txdl_h txdlh,
void *vaddr,
u32 size)
{
__hal_vpath_handle_t *vp = (__hal_vpath_handle_t *) vpath_handle;
__hal_fifo_t *fifo;
__hal_device_t *hldev;
__hal_fifo_txdl_priv_t *txdl_priv;
ptrdiff_t used;
vxge_assert((vpath_handle != NULL) && (txdlh != NULL) &&
(vaddr != NULL) && (size == 0));
hldev = vp->vpath->hldev;
vxge_hal_trace_log_fifo("==> %s:%s:%d",
__FILE__, __func__, __LINE__);
vxge_hal_trace_log_fifo("vpath_handle = 0x"VXGE_OS_STXFMT", "
"txdlh = 0x"VXGE_OS_STXFMT", vaddr = 0x"VXGE_OS_STXFMT", "
"size = %d", (ptr_t) vpath_handle, (ptr_t) txdlh,
(ptr_t) vaddr, size);
fifo = (__hal_fifo_t *) vp->vpath->fifoh;
vxge_assert(fifo != NULL);
txdl_priv = VXGE_HAL_FIFO_HAL_PRIV(fifo, txdlh);
/* LINTED */
used = txdl_priv->align_vaddr_start - txdl_priv->align_vaddr;
used += txdl_priv->align_dma_offset;
if (used + (unsigned int)size > (unsigned int)fifo->align_size)
return (VXGE_HAL_ERR_OUT_ALIGNED_FRAGS);
vxge_os_memcpy((char *) txdl_priv->align_vaddr_start +
txdl_priv->align_dma_offset, vaddr, size);
fifo->stats->copied_frags++;
txdl_priv->align_dma_offset += size;
vxge_hal_trace_log_fifo("<== %s:%s:%d Result: 0",
__FILE__, __func__, __LINE__);
return (VXGE_HAL_OK);
}
/*
* vxge_hal_fifo_txdl_buffer_finalize - Prepares a descriptor that contains the
* single physically contiguous buffer.
*
* @vpath_handle: Virtual path handle.
* @txdlh: Descriptor handle.
* @frag_idx: Index of the data buffer in the Txdl list.
*
* This API in conjunction with vxge_hal_fifo_txdl_buffer_append() prepares
* a descriptor that consists of a single physically contiguous buffer
* which inturn contains the contents of one or more virtually contiguous
* buffers received from the upper layer.
*
* See Also: vxge_hal_fifo_txdl_buffer_append().
*/
void
vxge_hal_fifo_txdl_buffer_finalize(
vxge_hal_vpath_h vpath_handle,
vxge_hal_txdl_h txdlh,
u32 frag_idx)
{
__hal_vpath_handle_t *vp = (__hal_vpath_handle_t *) vpath_handle;
__hal_fifo_t *fifo;
__hal_device_t *hldev;
__hal_fifo_txdl_priv_t *txdl_priv;
vxge_hal_fifo_txd_t *txdp;
ptrdiff_t prev_boff;
vxge_assert((vpath_handle != NULL) &&
(txdlh != NULL) && (frag_idx != 0));
hldev = vp->vpath->hldev;
vxge_hal_trace_log_fifo("==> %s:%s:%d",
__FILE__, __func__, __LINE__);
vxge_hal_trace_log_fifo("vpath_handle = 0x"VXGE_OS_STXFMT", "
"txdlh = 0x"VXGE_OS_STXFMT", frag_idx = %d", (ptr_t) vpath_handle,
(ptr_t) txdlh, frag_idx);
fifo = (__hal_fifo_t *) vp->vpath->fifoh;
vxge_assert(fifo != NULL);
txdl_priv = VXGE_HAL_FIFO_HAL_PRIV(fifo, txdlh);
txdp = (vxge_hal_fifo_txd_t *) txdlh + txdl_priv->frags;
/* LINTED */
prev_boff = txdl_priv->align_vaddr_start - txdl_priv->align_vaddr;
txdp->buffer_pointer = (u64) txdl_priv->align_dma_addr + prev_boff;
txdp->control_0 |=
VXGE_HAL_FIFO_TXD_BUFFER_SIZE(txdl_priv->align_dma_offset);
txdl_priv->bytes_sent += (unsigned int)txdl_priv->align_dma_offset;
fifo->stats->total_buffers++;
fifo->stats->copied_buffers++;
txdl_priv->frags++;
txdl_priv->align_used_frags++;
#if defined(VXGE_OS_DMA_REQUIRES_SYNC)
/* sync pre-mapped buffer */
vxge_os_dma_sync(fifo->channel.pdev,
txdl_priv->align_dma_handle,
txdp->buffer_pointer,
0,
txdl_priv->align_dma_offset,
VXGE_OS_DMA_DIR_TODEVICE);
#endif
/* increment vaddr_start for the next buffer_append() iteration */
txdl_priv->align_vaddr_start += txdl_priv->align_dma_offset;
txdl_priv->align_dma_offset = 0;
vxge_hal_trace_log_fifo("<== %s:%s:%d Result: 0",
__FILE__, __func__, __LINE__);
}
/*
* vxge_hal_fifo_txdl_new_frame_set - Start the new packet by setting TXDL flags
* @vpath_handle: virtual path handle.
* @txdlh: Descriptor handle.
* @tagged: Is the frame tagged
*
* This API is part of the preparation of the transmit descriptor for posting
* (via vxge_hal_fifo_txdl_post()). This api is used to mark the end of previous
* frame and start of a new frame.
*
*/
void
vxge_hal_fifo_txdl_new_frame_set(
vxge_hal_vpath_h vpath_handle,
vxge_hal_txdl_h txdlh,
u32 tagged)
{
__hal_vpath_handle_t *vp = (__hal_vpath_handle_t *) vpath_handle;
__hal_fifo_t *fifo;
__hal_device_t *hldev;
__hal_fifo_txdl_priv_t *txdl_priv;
vxge_hal_fifo_txd_t *txdp;
vxge_assert((vpath_handle != NULL) && (txdlh != NULL));
hldev = vp->vpath->hldev;
vxge_hal_trace_log_fifo("==> %s:%s:%d",
__FILE__, __func__, __LINE__);
vxge_hal_trace_log_fifo("vpath_handle = 0x"VXGE_OS_STXFMT", "
"txdlh = 0x"VXGE_OS_STXFMT", tagged = %d",
(ptr_t) vpath_handle, (ptr_t) txdlh, tagged);
fifo = (__hal_fifo_t *) vp->vpath->fifoh;
vxge_assert(fifo != NULL);
txdl_priv = VXGE_HAL_FIFO_HAL_PRIV(fifo, txdlh);
txdp = (vxge_hal_fifo_txd_t *) txdlh + txdl_priv->frags;
txdp->control_0 |=
VXGE_HAL_FIFO_TXD_HOST_STEER(vp->vpath->vp_config->wire_port);
txdp->control_0 |= VXGE_HAL_FIFO_TXD_GATHER_CODE(
VXGE_HAL_FIFO_TXD_GATHER_CODE_FIRST);
txdp->control_1 |= fifo->interrupt_type;
txdp->control_1 |= VXGE_HAL_FIFO_TXD_INT_NUMBER(
vp->vpath->tx_intr_num);
if (tagged)
txdp->control_1 |= VXGE_HAL_FIFO_TXD_NO_BW_LIMIT;
if (txdl_priv->frags) {
txdp = (vxge_hal_fifo_txd_t *) txdlh + (txdl_priv->frags - 1);
txdp->control_0 |= VXGE_HAL_FIFO_TXD_GATHER_CODE(
VXGE_HAL_FIFO_TXD_GATHER_CODE_LAST);
}
vxge_hal_trace_log_fifo("<== %s:%s:%d Result: 0",
__FILE__, __func__, __LINE__);
}
/*
* vxge_hal_fifo_txdl_post - Post descriptor on the fifo channel.
* @vpath_handle: Virtual path handle.
* @txdlh: Descriptor obtained via vxge_hal_fifo_txdl_reserve()
* @tagged: Is the frame tagged
*
* Post descriptor on the 'fifo' type channel for transmission.
* Prior to posting the descriptor should be filled in accordance with
* Host/X3100 interface specification for a given service (LL, etc.).
*
*/
void
vxge_hal_fifo_txdl_post(
vxge_hal_vpath_h vpath_handle,
vxge_hal_txdl_h txdlh,
u32 tagged)
{
u64 list_ptr;
__hal_vpath_handle_t *vp = (__hal_vpath_handle_t *) vpath_handle;
__hal_fifo_t *fifo;
__hal_device_t *hldev;
__hal_fifo_txdl_priv_t *txdl_priv;
vxge_hal_fifo_txd_t *txdp_last;
vxge_hal_fifo_txd_t *txdp_first;
#if defined(VXGE_HAL_TX_MULTI_POST_IRQ)
unsigned long flags = 0;
#endif
vxge_assert((vpath_handle != NULL) && (txdlh != NULL));
hldev = vp->vpath->hldev;
vxge_hal_trace_log_fifo("==> %s:%s:%d",
__FILE__, __func__, __LINE__);
vxge_hal_trace_log_fifo("vpath_handle = 0x"VXGE_OS_STXFMT", "
"txdlh = 0x"VXGE_OS_STXFMT", tagged = %d",
(ptr_t) vpath_handle, (ptr_t) txdlh, tagged);
fifo = (__hal_fifo_t *) vp->vpath->fifoh;
vxge_assert(fifo != NULL);
txdl_priv = VXGE_HAL_FIFO_HAL_PRIV(fifo, txdlh);
txdp_first = (vxge_hal_fifo_txd_t *) txdlh;
txdp_first->control_0 |=
VXGE_HAL_FIFO_TXD_HOST_STEER(vp->vpath->vp_config->wire_port);
txdp_first->control_0 |=
VXGE_HAL_FIFO_TXD_GATHER_CODE(VXGE_HAL_FIFO_TXD_GATHER_CODE_FIRST);
txdp_first->control_1 |=
VXGE_HAL_FIFO_TXD_INT_NUMBER(vp->vpath->tx_intr_num);
txdp_first->control_1 |= fifo->interrupt_type;
list_ptr = (u64) txdl_priv->dma_addr;
if (tagged) {
txdp_first->control_1 |= VXGE_HAL_FIFO_TXD_NO_BW_LIMIT;
list_ptr |= 0x1;
}
txdp_last =
(vxge_hal_fifo_txd_t *) txdlh + (txdl_priv->frags - 1);
txdp_last->control_0 |=
VXGE_HAL_FIFO_TXD_GATHER_CODE(VXGE_HAL_FIFO_TXD_GATHER_CODE_LAST);
#if defined(VXGE_HAL_TX_MULTI_POST)
vxge_os_spin_lock(&fifo->channel.post_lock);
#elif defined(VXGE_HAL_TX_MULTI_POST_IRQ)
vxge_os_spin_lock_irq(&fifo->channel.post_lock, flags);
#endif
txdp_first->control_0 |= VXGE_HAL_FIFO_TXD_LIST_OWN_ADAPTER;
#if defined(VXGE_DEBUG_ASSERT)
/* make sure device overwrites the t_code value on completion */
txdp_first->control_0 |=
VXGE_HAL_FIFO_TXD_T_CODE(VXGE_HAL_FIFO_TXD_T_CODE_UNUSED);
#endif
#if defined(VXGE_OS_DMA_REQUIRES_SYNC) && defined(VXGE_HAL_DMA_TXDL_STREAMING)
/* sync the TxDL to device */
vxge_os_dma_sync(fifo->channel.pdev,
txdl_priv->dma_handle,
txdl_priv->dma_addr,
txdl_priv->dma_offset,
txdl_priv->frags << 5, /* sizeof(vxge_hal_fifo_txd_t) */
VXGE_OS_DMA_DIR_TODEVICE);
#endif
/*
* we want touch dtr_arr in order with ownership bit set to HW
*/
__hal_channel_dtr_post(&fifo->channel, VXGE_HAL_FIFO_TXDL_INDEX(txdlh));
__hal_non_offload_db_post(vpath_handle,
list_ptr,
txdl_priv->frags - 1,
vp->vpath->vp_config->fifo.no_snoop_bits);
#if defined(VXGE_HAL_FIFO_DUMP_TXD)
vxge_hal_info_log_fifo(
""VXGE_OS_LLXFMT":"VXGE_OS_LLXFMT":"VXGE_OS_LLXFMT":"
VXGE_OS_LLXFMT" dma "VXGE_OS_LLXFMT,
txdp_first->control_0, txdp_first->control_1,
txdp_first->buffer_pointer, VXGE_HAL_FIFO_TXDL_INDEX(txdp_first),
txdl_priv->dma_addr);
#endif
fifo->stats->total_posts++;
fifo->stats->common_stats.usage_cnt++;
if (fifo->stats->common_stats.usage_max <
fifo->stats->common_stats.usage_cnt)
fifo->stats->common_stats.usage_max =
fifo->stats->common_stats.usage_cnt;
#if defined(VXGE_HAL_TX_MULTI_POST)
vxge_os_spin_unlock(&fifo->channel.post_lock);
#elif defined(VXGE_HAL_TX_MULTI_POST_IRQ)
vxge_os_spin_unlock_irq(&fifo->channel.post_lock, flags);
#endif
vxge_hal_trace_log_fifo("<== %s:%s:%d Result: 0",
__FILE__, __func__, __LINE__);
}
/*
* vxge_hal_fifo_is_next_txdl_completed - Checks if the next txdl is completed
* @vpath_handle: Virtual path handle.
*/
vxge_hal_status_e
vxge_hal_fifo_is_next_txdl_completed(vxge_hal_vpath_h vpath_handle)
{
__hal_vpath_handle_t *vp = (__hal_vpath_handle_t *) vpath_handle;
__hal_fifo_t *fifo;
__hal_device_t *hldev;
vxge_hal_fifo_txd_t *txdp;
vxge_hal_txdl_h txdlh;
vxge_hal_status_e status = VXGE_HAL_INF_NO_MORE_COMPLETED_DESCRIPTORS;
#if defined(VXGE_HAL_TX_MULTI_POST_IRQ)
unsigned long flags = 0;
#endif
vxge_assert(vpath_handle != NULL);
hldev = vp->vpath->hldev;
vxge_hal_trace_log_fifo("==> %s:%s:%d",
__FILE__, __func__, __LINE__);
vxge_hal_trace_log_fifo("vpath_handle = 0x"VXGE_OS_STXFMT,
(ptr_t) vpath_handle);
fifo = (__hal_fifo_t *) vp->vpath->fifoh;
vxge_assert(fifo != NULL);
#if defined(VXGE_HAL_TX_MULTI_POST)
vxge_os_spin_lock(&fifo->channel.post_lock);
#elif defined(VXGE_HAL_TX_MULTI_POST_IRQ)
vxge_os_spin_lock_irq(&fifo->channel.post_lock, flags);
#endif
__hal_channel_dtr_try_complete(&fifo->channel, &txdlh);
txdp = (vxge_hal_fifo_txd_t *) txdlh;
if ((txdp != NULL) &&
(!(txdp->control_0 & VXGE_HAL_FIFO_TXD_LIST_OWN_ADAPTER))) {
status = VXGE_HAL_OK;
}
#if defined(VXGE_HAL_TX_MULTI_POST)
vxge_os_spin_unlock(&fifo->channel.post_lock);
#elif defined(VXGE_HAL_TX_MULTI_POST_IRQ)
vxge_os_spin_unlock_irq(&fifo->channel.post_lock, flags);
#endif
vxge_hal_trace_log_fifo("<== %s:%s:%d Result: %d",
__FILE__, __func__, __LINE__, status);
/* no more completions */
return (status);
}
/*
* vxge_hal_fifo_txdl_next_completed - Retrieve next completed descriptor.
* @vpath_handle: Virtual path handle.
* @txdlh: Descriptor handle. Returned by HAL.
* @txdl_priv: Buffer to return the pointer to per txdl space
* @t_code: Transfer code, as per X3100 User Guide,
* Transmit Descriptor Format.
* Returned by HAL.
*
* Retrieve the _next_ completed descriptor.
* HAL uses channel callback (*vxge_hal_channel_callback_f) to notifiy
* upper-layer driver (ULD) of new completed descriptors. After that
* the ULD can use vxge_hal_fifo_txdl_next_completed to retrieve the rest
* completions (the very first completion is passed by HAL via
* vxge_hal_channel_callback_f).
*
* Implementation-wise, the upper-layer driver is free to call
* vxge_hal_fifo_txdl_next_completed either immediately from inside the
* channel callback, or in a deferred fashion and separate (from HAL)
* context.
*
* Non-zero @t_code means failure to process the descriptor.
* The failure could happen, for instance, when the link is
* down, in which case X3100 completes the descriptor because it
* is not able to send the data out.
*
* For details please refer to X3100 User Guide.
*
* Returns: VXGE_HAL_OK - success.
* VXGE_HAL_INF_NO_MORE_COMPLETED_DESCRIPTORS - No completed descriptors
* are currently available for processing.
*
*/
vxge_hal_status_e
vxge_hal_fifo_txdl_next_completed(
vxge_hal_vpath_h vpath_handle,
vxge_hal_txdl_h * txdlh,
void **txdl_priv,
vxge_hal_fifo_tcode_e * t_code)
{
__hal_fifo_t *fifo;
__hal_device_t *hldev;
vxge_hal_fifo_txd_t *txdp;
#if defined(VXGE_OS_DMA_REQUIRES_SYNC) && defined(VXGE_HAL_DMA_TXDL_STREAMING)
__hal_fifo_txdl_priv_t *priv;
#endif
#if defined(VXGE_HAL_TX_MULTI_POST_IRQ)
unsigned long flags = 0;
#endif
__hal_vpath_handle_t *vp = (__hal_vpath_handle_t *) vpath_handle;
vxge_hal_status_e status = VXGE_HAL_INF_NO_MORE_COMPLETED_DESCRIPTORS;
vxge_assert((vpath_handle != NULL) &&
(txdlh != NULL) && (t_code != NULL));
hldev = vp->vpath->hldev;
vxge_hal_trace_log_fifo("==> %s:%s:%d",
__FILE__, __func__, __LINE__);
vxge_hal_trace_log_fifo("vpath_handle = 0x"VXGE_OS_STXFMT", "
"txdlh = 0x"VXGE_OS_STXFMT", t_code = 0x"VXGE_OS_STXFMT,
(ptr_t) vpath_handle, (ptr_t) txdlh, (ptr_t) t_code);
fifo = (__hal_fifo_t *) vp->vpath->fifoh;
vxge_assert(fifo != NULL);
*txdlh = 0;
#if defined(VXGE_HAL_TX_MULTI_POST)
vxge_os_spin_lock(&fifo->channel.post_lock);
#elif defined(VXGE_HAL_TX_MULTI_POST_IRQ)
vxge_os_spin_lock_irq(&fifo->channel.post_lock, flags);
#endif
__hal_channel_dtr_try_complete(&fifo->channel, txdlh);
txdp = (vxge_hal_fifo_txd_t *) * txdlh;
if (txdp != NULL) {
#if defined(VXGE_OS_DMA_REQUIRES_SYNC) && defined(VXGE_HAL_DMA_TXDL_STREAMING)
priv = VXGE_HAL_FIFO_HAL_PRIV(fifo, txdp);
/*
* sync TxDL to read the ownership
*
* Note: 16bytes means Control_1 & Control_2
*/
vxge_os_dma_sync(fifo->channel.pdev,
priv->dma_handle,
priv->dma_addr,
priv->dma_offset,
16,
VXGE_OS_DMA_DIR_FROMDEVICE);
#endif
/* check whether host owns it */
if (!(txdp->control_0 & VXGE_HAL_FIFO_TXD_LIST_OWN_ADAPTER)) {
__hal_channel_dtr_complete(&fifo->channel);
*txdl_priv = VXGE_HAL_FIFO_ULD_PRIV(fifo, txdp);
*t_code = (vxge_hal_fifo_tcode_e)
VXGE_HAL_FIFO_TXD_T_CODE_GET(txdp->control_0);
if (fifo->stats->common_stats.usage_cnt > 0)
fifo->stats->common_stats.usage_cnt--;
status = VXGE_HAL_OK;
}
}
/* no more completions */
#if defined(VXGE_HAL_TX_MULTI_POST)
vxge_os_spin_unlock(&fifo->channel.post_lock);
#elif defined(VXGE_HAL_TX_MULTI_POST_IRQ)
vxge_os_spin_unlock_irq(&fifo->channel.post_lock, flags);
#endif
vxge_hal_trace_log_fifo("<== %s:%s:%d Result: %d",
__FILE__, __func__, __LINE__, status);
return (status);
}
/*
* vxge_hal_fifo_handle_tcode - Handle transfer code.
* @vpath_handle: Virtual Path handle.
* @txdlh: Descriptor handle.
* @t_code: One of the enumerated (and documented in the X3100 user guide)
* "transfer codes".
*
* Handle descriptor's transfer code. The latter comes with each completed
* descriptor.
*
* Returns: one of the vxge_hal_status_e {} enumerated types.
* VXGE_HAL_OK - for success.
* VXGE_HAL_ERR_CRITICAL - when encounters critical error.
*/
vxge_hal_status_e
vxge_hal_fifo_handle_tcode(
vxge_hal_vpath_h vpath_handle,
vxge_hal_txdl_h txdlh,
vxge_hal_fifo_tcode_e t_code)
{
__hal_vpath_handle_t *vp = (__hal_vpath_handle_t *) vpath_handle;
__hal_device_t *hldev;
vxge_assert((vpath_handle != NULL) && (txdlh != NULL));
hldev = vp->vpath->hldev;
vxge_hal_trace_log_fifo("==> %s:%s:%d",
__FILE__, __func__, __LINE__);
vxge_hal_trace_log_fifo("vpath_handle = 0x"VXGE_OS_STXFMT", "
"txdlh = 0x"VXGE_OS_STXFMT", t_code = 0x%d",
(ptr_t) vpath_handle, (ptr_t) txdlh, t_code);
switch ((t_code & 0x7)) {
case 0:
/* 000: Transfer operation completed successfully. */
break;
case 1:
/*
* 001: a PCI read transaction (either TxD or frame data)
* returned with corrupt data.
*/
break;
case 2:
/* 010: a PCI read transaction was returned with no data. */
break;
case 3:
/*
* 011: The host attempted to send either a frame or LSO
* MSS that was too long (>9800B).
*/
break;
case 4:
/*
* 100: Error detected during TCP/UDP Large Send
* Offload operation, due to improper header template,
* unsupported protocol, etc.
*/
break;
default:
vxge_hal_trace_log_fifo("<== %s:%s:%d Result: %d",
__FILE__, __func__, __LINE__, VXGE_HAL_ERR_INVALID_TCODE);
return (VXGE_HAL_ERR_INVALID_TCODE);
}
vp->vpath->sw_stats->fifo_stats.txd_t_code_err_cnt[t_code]++;
vxge_hal_trace_log_fifo("<== %s:%s:%d Result: %d",
__FILE__, __func__, __LINE__, VXGE_HAL_OK);
return (VXGE_HAL_OK);
}
/*
* __hal_fifo_txdl_free_many - Free the fragments
* @fifo: FIFO
* @txdp: Poniter to a TxD
* @list_size: List size
* @frags: Number of fragments
*
* This routinf frees the fragments in a txdl
*/
void
__hal_fifo_txdl_free_many(
__hal_fifo_t *fifo,
vxge_hal_fifo_txd_t * txdp,
u32 list_size,
u32 frags)
{
__hal_fifo_txdl_priv_t *current_txdl_priv;
__hal_fifo_txdl_priv_t *next_txdl_priv;
u32 invalid_frags = frags % list_size;
__hal_vpath_handle_t *vp = (__hal_vpath_handle_t *) fifo->channel.vph;
__hal_device_t *hldev;
vxge_assert((fifo != NULL) && (txdp != NULL));
hldev = vp->vpath->hldev;
vxge_hal_trace_log_fifo("==> %s:%s:%d",
__FILE__, __func__, __LINE__);
vxge_hal_trace_log_fifo(
"fifo = 0x"VXGE_OS_STXFMT", txdp = 0x"VXGE_OS_STXFMT", "
"list_size = %d, frags = %d", (ptr_t) fifo, (ptr_t) txdp,
list_size, frags);
if (invalid_frags) {
vxge_hal_trace_log_fifo(
"freeing corrupt txdlh 0x"VXGE_OS_STXFMT", "
"fragments %d list size %d",
(ptr_t) txdp, frags, list_size);
vxge_assert(invalid_frags == 0);
}
while (txdp) {
vxge_hal_trace_log_fifo("freeing linked txdlh 0x"VXGE_OS_STXFMT
", " "fragments %d list size %d",
(ptr_t) txdp, frags, list_size);
current_txdl_priv = VXGE_HAL_FIFO_HAL_PRIV(fifo, txdp);
#if defined(VXGE_DEBUG_ASSERT) && defined(VXGE_OS_MEMORY_CHECK)
current_txdl_priv->allocated = 0;
#endif
__hal_channel_dtr_free(&fifo->channel,
VXGE_HAL_FIFO_TXDL_INDEX(txdp));
next_txdl_priv = current_txdl_priv->next_txdl_priv;
vxge_assert(frags);
frags -= list_size;
if (next_txdl_priv) {
current_txdl_priv->next_txdl_priv = NULL;
txdp = next_txdl_priv->first_txdp;
} else {
vxge_hal_trace_log_fifo(
"freed linked txdlh fragments %d list size %d",
frags, list_size);
break;
}
}
vxge_assert(frags == 0);
vxge_hal_trace_log_fifo("<== %s:%s:%d Result: 0",
__FILE__, __func__, __LINE__);
}
/*
* vxge_hal_fifo_txdl_free - Free descriptor.
* @vpath_handle: Virtual path handle.
* @txdlh: Descriptor handle.
*
* Free the reserved descriptor. This operation is "symmetrical" to
* vxge_hal_fifo_txdl_reserve. The "free-ing" completes the descriptor's
* lifecycle.
*
* After free-ing (see vxge_hal_fifo_txdl_free()) the descriptor again can
* be:
*
* - reserved (vxge_hal_fifo_txdl_reserve);
*
* - posted (vxge_hal_fifo_txdl_post);
*
* - completed (vxge_hal_fifo_txdl_next_completed);
*
* - and recycled again (vxge_hal_fifo_txdl_free).
*
* For alternative state transitions and more details please refer to
* the design doc.
*
*/
void
vxge_hal_fifo_txdl_free(
vxge_hal_vpath_h vpath_handle,
vxge_hal_txdl_h txdlh)
{
__hal_vpath_handle_t *vp = (__hal_vpath_handle_t *) vpath_handle;
__hal_fifo_t *fifo;
__hal_device_t *hldev;
__hal_fifo_txdl_priv_t *txdl_priv;
u32 max_frags;
#if defined(VXGE_HAL_TX_MULTI_POST_IRQ)
u32 flags = 0;
#endif
vxge_assert((vpath_handle != NULL) && (txdlh != NULL));
hldev = vp->vpath->hldev;
vxge_hal_trace_log_fifo("==> %s:%s:%d",
__FILE__, __func__, __LINE__);
vxge_hal_trace_log_fifo("vpath_handle = 0x"VXGE_OS_STXFMT", "
"txdlh = 0x"VXGE_OS_STXFMT, (ptr_t) vpath_handle, (ptr_t) txdlh);
fifo = (__hal_fifo_t *) vp->vpath->fifoh;
vxge_assert(fifo != NULL);
txdl_priv = VXGE_HAL_FIFO_HAL_PRIV(fifo, txdlh);
max_frags = fifo->config->max_frags;
#if defined(VXGE_HAL_TX_MULTI_POST)
vxge_os_spin_lock(&fifo->channel.post_lock);
#elif defined(VXGE_HAL_TX_MULTI_POST_IRQ)
vxge_os_spin_lock_irq(&fifo->channel.post_lock, flags);
#endif
if (txdl_priv->alloc_frags > max_frags) {
vxge_hal_fifo_txd_t *dang_txdp = (vxge_hal_fifo_txd_t *)
txdl_priv->dang_txdl;
u32 dang_frags = txdl_priv->dang_frags;
u32 alloc_frags = txdl_priv->alloc_frags;
txdl_priv->dang_txdl = NULL;
txdl_priv->dang_frags = 0;
txdl_priv->alloc_frags = 0;
/* txdlh must have a linked list of txdlh */
vxge_assert(txdl_priv->next_txdl_priv);
/* free any dangling txdlh first */
if (dang_txdp) {
vxge_hal_info_log_fifo(
"freeing dangled txdlh 0x"VXGE_OS_STXFMT" for %d "
"fragments", (ptr_t) dang_txdp, dang_frags);
__hal_fifo_txdl_free_many(fifo, dang_txdp,
max_frags, dang_frags);
}
/* now free the reserved txdlh list */
vxge_hal_info_log_fifo(
"freeing txdlh 0x"VXGE_OS_STXFMT" list of %d fragments",
(ptr_t) txdlh, alloc_frags);
__hal_fifo_txdl_free_many(fifo,
(vxge_hal_fifo_txd_t *) txdlh, max_frags,
alloc_frags);
} else {
__hal_channel_dtr_free(&fifo->channel,
VXGE_HAL_FIFO_TXDL_INDEX(txdlh));
}
fifo->channel.poll_bytes += txdl_priv->bytes_sent;
#if defined(VXGE_DEBUG_ASSERT) && defined(VXGE_OS_MEMORY_CHECK)
txdl_priv->allocated = 0;
#endif
#if defined(VXGE_HAL_TX_MULTI_POST)
vxge_os_spin_unlock(&fifo->channel.post_lock);
#elif defined(VXGE_HAL_TX_MULTI_POST_IRQ)
vxge_os_spin_unlock_irq(&fifo->channel.post_lock, flags);
#endif
vxge_hal_trace_log_fifo("<== %s:%s:%d Result: 0",
__FILE__, __func__, __LINE__);
}
|