Training courses

Kernel and Embedded Linux

Bootlin training courses

Embedded Linux, kernel,
Yocto Project, Buildroot, real-time,
graphics, boot time, debugging...

Bootlin logo

Elixir Cross Referencer

   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
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
/*
 * Copyright 2008-2012 Freescale Semiconductor Inc.
 *
 * 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 Freescale Semiconductor nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 *
 * ALTERNATIVELY, this software may be distributed under the terms of the
 * GNU General Public License ("GPL") as published by the Free Software
 * Foundation, either version 2 of that License or (at your option) any
 * later version.
 *
 * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``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 Freescale Semiconductor BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */


/******************************************************************************
 @File          fm.c

 @Description   FM driver routines implementation.
*//***************************************************************************/
#include "std_ext.h"
#include "error_ext.h"
#include "xx_ext.h"
#include "string_ext.h"
#include "sprint_ext.h"
#include "debug_ext.h"
#include "fm_muram_ext.h"
#include <linux/math64.h>

#include "fm_common.h"
#include "fm_ipc.h"
#include "fm.h"
#include "fsl_fman.h"


/****************************************/
/*       static functions               */
/****************************************/

static volatile bool blockingFlag = FALSE;
static void IpcMsgCompletionCB(t_Handle   h_Fm,
                               uint8_t    *p_Msg,
                               uint8_t    *p_Reply,
                               uint32_t   replyLength,
                               t_Error    status)
{
    UNUSED(h_Fm);UNUSED(p_Msg);UNUSED(p_Reply);UNUSED(replyLength);UNUSED(status);
    blockingFlag = FALSE;
}

static void FreeInitResources(t_Fm *p_Fm)
{
    if (p_Fm->camBaseAddr)
       FM_MURAM_FreeMem(p_Fm->h_FmMuram, UINT_TO_PTR(p_Fm->camBaseAddr));
    if (p_Fm->fifoBaseAddr)
       FM_MURAM_FreeMem(p_Fm->h_FmMuram, UINT_TO_PTR(p_Fm->fifoBaseAddr));
    if (p_Fm->resAddr)
       FM_MURAM_FreeMem(p_Fm->h_FmMuram, UINT_TO_PTR(p_Fm->resAddr));
}

static bool IsFmanCtrlCodeLoaded(t_Fm *p_Fm)
{
    t_FMIramRegs    *p_Iram;

    ASSERT_COND(p_Fm);
    p_Iram = (t_FMIramRegs *)UINT_TO_PTR(p_Fm->baseAddr + FM_MM_IMEM);

    return (bool)!!(GET_UINT32(p_Iram->iready) & IRAM_READY);
}

static t_Error CheckFmParameters(t_Fm *p_Fm)
{
    if (IsFmanCtrlCodeLoaded(p_Fm) && !p_Fm->resetOnInit)
        RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("Old FMan CTRL code is loaded; FM must be reset!"));
#if (DPAA_VERSION < 11)
    if (!p_Fm->p_FmDriverParam->dma_axi_dbg_num_of_beats ||
        (p_Fm->p_FmDriverParam->dma_axi_dbg_num_of_beats > DMA_MODE_MAX_AXI_DBG_NUM_OF_BEATS))
        RETURN_ERROR(MAJOR, E_INVALID_VALUE,
                     ("axiDbgNumOfBeats has to be in the range 1 - %d", DMA_MODE_MAX_AXI_DBG_NUM_OF_BEATS));
#endif /* (DPAA_VERSION < 11) */
    if (p_Fm->p_FmDriverParam->dma_cam_num_of_entries % DMA_CAM_UNITS)
        RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("dma_cam_num_of_entries has to be divisble by %d", DMA_CAM_UNITS));
//    if (!p_Fm->p_FmDriverParam->dma_cam_num_of_entries || (p_Fm->p_FmDriverParam->dma_cam_num_of_entries > DMA_MODE_MAX_CAM_NUM_OF_ENTRIES))
//        RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("dma_cam_num_of_entries has to be in the range 1 - %d", DMA_MODE_MAX_CAM_NUM_OF_ENTRIES));
    if (p_Fm->p_FmDriverParam->dma_comm_qtsh_asrt_emer > DMA_THRESH_MAX_COMMQ)
        RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("dma_comm_qtsh_asrt_emer can not be larger than %d", DMA_THRESH_MAX_COMMQ));
    if (p_Fm->p_FmDriverParam->dma_comm_qtsh_clr_emer > DMA_THRESH_MAX_COMMQ)
        RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("dma_comm_qtsh_clr_emer can not be larger than %d", DMA_THRESH_MAX_COMMQ));
    if (p_Fm->p_FmDriverParam->dma_comm_qtsh_clr_emer >= p_Fm->p_FmDriverParam->dma_comm_qtsh_asrt_emer)
        RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("dma_comm_qtsh_clr_emer must be smaller than dma_comm_qtsh_asrt_emer"));
#if (DPAA_VERSION < 11)
    if (p_Fm->p_FmDriverParam->dma_read_buf_tsh_asrt_emer > DMA_THRESH_MAX_BUF)
        RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("dma_read_buf_tsh_asrt_emer can not be larger than %d", DMA_THRESH_MAX_BUF));
    if (p_Fm->p_FmDriverParam->dma_read_buf_tsh_clr_emer > DMA_THRESH_MAX_BUF)
        RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("dma_read_buf_tsh_clr_emer can not be larger than %d", DMA_THRESH_MAX_BUF));
    if (p_Fm->p_FmDriverParam->dma_read_buf_tsh_clr_emer >= p_Fm->p_FmDriverParam->dma_read_buf_tsh_asrt_emer)
        RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("dma_read_buf_tsh_clr_emer must be smaller than dma_read_buf_tsh_asrt_emer"));
    if (p_Fm->p_FmDriverParam->dma_write_buf_tsh_asrt_emer > DMA_THRESH_MAX_BUF)
        RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("dma_write_buf_tsh_asrt_emer can not be larger than %d", DMA_THRESH_MAX_BUF));
    if (p_Fm->p_FmDriverParam->dma_write_buf_tsh_clr_emer > DMA_THRESH_MAX_BUF)
        RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("dma_write_buf_tsh_clr_emer can not be larger than %d", DMA_THRESH_MAX_BUF));
    if (p_Fm->p_FmDriverParam->dma_write_buf_tsh_clr_emer >= p_Fm->p_FmDriverParam->dma_write_buf_tsh_asrt_emer)
        RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("dma_write_buf_tsh_clr_emer must be smaller than dma_write_buf_tsh_asrt_emer"));
#else /* (DPAA_VERSION >= 11) */
    if ((p_Fm->p_FmDriverParam->dma_dbg_cnt_mode == E_FMAN_DMA_DBG_CNT_INT_READ_EM)||
            (p_Fm->p_FmDriverParam->dma_dbg_cnt_mode == E_FMAN_DMA_DBG_CNT_INT_WRITE_EM) ||
            (p_Fm->p_FmDriverParam->dma_dbg_cnt_mode == E_FMAN_DMA_DBG_CNT_RAW_WAR_PROT))
        RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("dma_dbg_cnt_mode value not supported by this integration."));
    if ((p_Fm->p_FmDriverParam->dma_emergency_bus_select == FM_DMA_MURAM_READ_EMERGENCY)||
            (p_Fm->p_FmDriverParam->dma_emergency_bus_select == FM_DMA_MURAM_WRITE_EMERGENCY))
        RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("emergencyBusSelect value not supported by this integration."));
    if (p_Fm->p_FmDriverParam->dma_stop_on_bus_error)
        RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("dma_stop_on_bus_error not supported by this integration."));
#ifdef FM_AID_MODE_NO_TNUM_SW005
    if (p_Fm->p_FmDriverParam->dma_aid_mode != E_FMAN_DMA_AID_OUT_PORT_ID)
            RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("dma_aid_mode not supported by this integration."));
#endif /* FM_AID_MODE_NO_TNUM_SW005 */
    if (p_Fm->p_FmDriverParam->dma_axi_dbg_num_of_beats)
        RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("dma_axi_dbg_num_of_beats not supported by this integration."));
#endif /* (DPAA_VERSION < 11) */

    if (!p_Fm->p_FmStateStruct->fmClkFreq)
        RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("fmClkFreq must be set."));
    if (USEC_TO_CLK(p_Fm->p_FmDriverParam->dma_watchdog, p_Fm->p_FmStateStruct->fmClkFreq) > DMA_MAX_WATCHDOG)
        RETURN_ERROR(MAJOR, E_INVALID_VALUE,
                     ("dma_watchdog depends on FM clock. dma_watchdog(in microseconds) * clk (in Mhz), may not exceed 0x08x", DMA_MAX_WATCHDOG));

#if (DPAA_VERSION >= 11)
    if ((p_Fm->partVSPBase + p_Fm->partNumOfVSPs) > FM_VSP_MAX_NUM_OF_ENTRIES)
        RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("partVSPBase+partNumOfVSPs out of range!!!"));
#endif /* (DPAA_VERSION >= 11) */

    if (p_Fm->p_FmStateStruct->totalFifoSize % BMI_FIFO_UNITS)
        RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("totalFifoSize number has to be divisible by %d", BMI_FIFO_UNITS));
    if (!p_Fm->p_FmStateStruct->totalFifoSize ||
        (p_Fm->p_FmStateStruct->totalFifoSize > BMI_MAX_FIFO_SIZE))
        RETURN_ERROR(MAJOR, E_INVALID_VALUE,
                     ("totalFifoSize (currently defined as %d) has to be in the range of 256 to %d",
                      p_Fm->p_FmStateStruct->totalFifoSize,
                      BMI_MAX_FIFO_SIZE));
    if (!p_Fm->p_FmStateStruct->totalNumOfTasks ||
        (p_Fm->p_FmStateStruct->totalNumOfTasks > BMI_MAX_NUM_OF_TASKS))
        RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("totalNumOfTasks number has to be in the range 1 - %d", BMI_MAX_NUM_OF_TASKS));

#ifdef FM_HAS_TOTAL_DMAS
    if (!p_Fm->p_FmStateStruct->maxNumOfOpenDmas ||
        (p_Fm->p_FmStateStruct->maxNumOfOpenDmas > BMI_MAX_NUM_OF_DMAS))
        RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("maxNumOfOpenDmas number has to be in the range 1 - %d", BMI_MAX_NUM_OF_DMAS));
#endif /* FM_HAS_TOTAL_DMAS */

    if (p_Fm->p_FmDriverParam->disp_limit_tsh > FPM_MAX_DISP_LIMIT)
        RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("disp_limit_tsh can't be greater than %d", FPM_MAX_DISP_LIMIT));

    if (!p_Fm->f_Exception)
        RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("Exceptions callback not provided"));
    if (!p_Fm->f_BusError)
        RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("Exceptions callback not provided"));

#ifdef FM_NO_WATCHDOG
    if ((p_Fm->p_FmStateStruct->revInfo.majorRev == 2) &&
        (p_Fm->p_FmDriverParam->dma_watchdog))
        RETURN_ERROR(MAJOR, E_NOT_SUPPORTED, ("watchdog!"));
#endif /* FM_NO_WATCHDOG */

#ifdef FM_ECC_HALT_NO_SYNC_ERRATA_10GMAC_A008
    if ((p_Fm->p_FmStateStruct->revInfo.majorRev < 6) &&
        (p_Fm->p_FmDriverParam->halt_on_unrecov_ecc_err))
        RETURN_ERROR(MAJOR, E_NOT_SUPPORTED, ("HaltOnEccError!"));
#endif /* FM_ECC_HALT_NO_SYNC_ERRATA_10GMAC_A008 */

#ifdef FM_NO_TNUM_AGING
    if ((p_Fm->p_FmStateStruct->revInfo.majorRev != 4) &&
        (p_Fm->p_FmStateStruct->revInfo.majorRev < 6))
        if (p_Fm->p_FmDriverParam->tnum_aging_period)
        RETURN_ERROR(MAJOR, E_NOT_SUPPORTED, ("Tnum aging!"));
#endif /* FM_NO_TNUM_AGING */

    /* check that user did not set revision-dependent exceptions */
#ifdef FM_NO_DISPATCH_RAM_ECC
    if ((p_Fm->p_FmStateStruct->revInfo.majorRev != 4) &&
        (p_Fm->p_FmStateStruct->revInfo.majorRev < 6))
        if (p_Fm->userSetExceptions & FM_EX_BMI_DISPATCH_RAM_ECC)
            RETURN_ERROR(MAJOR, E_NOT_SUPPORTED, ("exception e_FM_EX_BMI_DISPATCH_RAM_ECC!"));
#endif /* FM_NO_DISPATCH_RAM_ECC */

#ifdef FM_QMI_NO_ECC_EXCEPTIONS
    if (p_Fm->p_FmStateStruct->revInfo.majorRev == 4)
        if (p_Fm->userSetExceptions & (FM_EX_QMI_SINGLE_ECC | FM_EX_QMI_DOUBLE_ECC))
            RETURN_ERROR(MAJOR, E_NOT_SUPPORTED, ("exception e_FM_EX_QMI_SINGLE_ECC/e_FM_EX_QMI_DOUBLE_ECC!"));
#endif /* FM_QMI_NO_ECC_EXCEPTIONS */

#ifdef FM_QMI_NO_SINGLE_ECC_EXCEPTION
    if (p_Fm->p_FmStateStruct->revInfo.majorRev >= 6)
        if (p_Fm->userSetExceptions & FM_EX_QMI_SINGLE_ECC)
            RETURN_ERROR(MAJOR, E_NOT_SUPPORTED, ("exception e_FM_EX_QMI_SINGLE_ECC!"));
#endif /* FM_QMI_NO_SINGLE_ECC_EXCEPTION */

    return E_OK;
}


static void SendIpcIsr(t_Fm *p_Fm, uint32_t macEvent, uint32_t pendingReg)
{
    ASSERT_COND(p_Fm->guestId == NCSW_MASTER_ID);

    if (p_Fm->intrMng[macEvent].guestId == NCSW_MASTER_ID)
        p_Fm->intrMng[macEvent].f_Isr(p_Fm->intrMng[macEvent].h_SrcHandle);

    /* If the MAC is running on guest-partition and we have IPC session with it,
       we inform him about the event through IPC; otherwise, we ignore the event. */
    else if (p_Fm->h_IpcSessions[p_Fm->intrMng[macEvent].guestId])
    {
        t_Error     err;
        t_FmIpcIsr  fmIpcIsr;
        t_FmIpcMsg  msg;

        memset(&msg, 0, sizeof(msg));
        msg.msgId = FM_GUEST_ISR;
        fmIpcIsr.pendingReg = pendingReg;
        fmIpcIsr.boolErr = FALSE;
        memcpy(msg.msgBody, &fmIpcIsr, sizeof(fmIpcIsr));
        err = XX_IpcSendMessage(p_Fm->h_IpcSessions[p_Fm->intrMng[macEvent].guestId],
                                (uint8_t*)&msg,
                                sizeof(msg.msgId) + sizeof(fmIpcIsr),
                                NULL,
                                NULL,
                                NULL,
                                NULL);
        if (err != E_OK)
            REPORT_ERROR(MINOR, err, NO_MSG);
    }
    else
        DBG(TRACE, ("FM Guest mode, without IPC - can't call ISR!"));
}

static void BmiErrEvent(t_Fm *p_Fm)
{
    uint32_t    event;
    struct fman_bmi_regs *bmi_rg = p_Fm->p_FmBmiRegs;


    event = fman_get_bmi_err_event(bmi_rg);

    if (event & BMI_ERR_INTR_EN_STORAGE_PROFILE_ECC)
        p_Fm->f_Exception(p_Fm->h_App,e_FM_EX_BMI_STORAGE_PROFILE_ECC);
    if (event & BMI_ERR_INTR_EN_LIST_RAM_ECC)
        p_Fm->f_Exception(p_Fm->h_App,e_FM_EX_BMI_LIST_RAM_ECC);
    if (event & BMI_ERR_INTR_EN_STATISTICS_RAM_ECC)
        p_Fm->f_Exception(p_Fm->h_App,e_FM_EX_BMI_STATISTICS_RAM_ECC);
    if (event & BMI_ERR_INTR_EN_DISPATCH_RAM_ECC)
        p_Fm->f_Exception(p_Fm->h_App,e_FM_EX_BMI_DISPATCH_RAM_ECC);
}

static void    QmiErrEvent(t_Fm *p_Fm)
{
    uint32_t    event;
    struct fman_qmi_regs *qmi_rg = p_Fm->p_FmQmiRegs;

    event = fman_get_qmi_err_event(qmi_rg);

    if (event & QMI_ERR_INTR_EN_DOUBLE_ECC)
        p_Fm->f_Exception(p_Fm->h_App,e_FM_EX_QMI_DOUBLE_ECC);
    if (event & QMI_ERR_INTR_EN_DEQ_FROM_DEF)
        p_Fm->f_Exception(p_Fm->h_App,e_FM_EX_QMI_DEQ_FROM_UNKNOWN_PORTID);
}

static void    DmaErrEvent(t_Fm *p_Fm)
{
    uint32_t            status, com_id;
    uint8_t             tnum;
    uint8_t             hardwarePortId;
    uint8_t             relativePortId;
    uint16_t            liodn;
    struct fman_dma_regs *dma_rg = p_Fm->p_FmDmaRegs;

    status = fman_get_dma_err_event(dma_rg);

    if (status & DMA_STATUS_BUS_ERR)
    {
        com_id = fman_get_dma_com_id(dma_rg);
        hardwarePortId = (uint8_t)(((com_id & DMA_TRANSFER_PORTID_MASK) >> DMA_TRANSFER_PORTID_SHIFT));
        ASSERT_COND(IN_RANGE(1, hardwarePortId, 63));
        HW_PORT_ID_TO_SW_PORT_ID(relativePortId, hardwarePortId);
        tnum = (uint8_t)((com_id & DMA_TRANSFER_TNUM_MASK) >> DMA_TRANSFER_TNUM_SHIFT);
        liodn = (uint16_t)(com_id & DMA_TRANSFER_LIODN_MASK);
        ASSERT_COND(p_Fm->p_FmStateStruct->portsTypes[hardwarePortId] != e_FM_PORT_TYPE_DUMMY);
        p_Fm->f_BusError(p_Fm->h_App,
                         p_Fm->p_FmStateStruct->portsTypes[hardwarePortId],
                         relativePortId,
                         fman_get_dma_addr(dma_rg),
                         tnum,
                         liodn);
    }
        if (status & DMA_STATUS_FM_SPDAT_ECC)
            p_Fm->f_Exception(p_Fm->h_App, e_FM_EX_DMA_SINGLE_PORT_ECC);
        if (status & DMA_STATUS_READ_ECC)
            p_Fm->f_Exception(p_Fm->h_App, e_FM_EX_DMA_READ_ECC);
        if (status & DMA_STATUS_SYSTEM_WRITE_ECC)
            p_Fm->f_Exception(p_Fm->h_App, e_FM_EX_DMA_SYSTEM_WRITE_ECC);
        if (status & DMA_STATUS_FM_WRITE_ECC)
            p_Fm->f_Exception(p_Fm->h_App, e_FM_EX_DMA_FM_WRITE_ECC);
    }

static void    FpmErrEvent(t_Fm *p_Fm)
{
    uint32_t    event;
    struct fman_fpm_regs *fpm_rg = p_Fm->p_FmFpmRegs;

    event = fman_get_fpm_err_event(fpm_rg);

    if ((event  & FPM_EV_MASK_DOUBLE_ECC) && (event & FPM_EV_MASK_DOUBLE_ECC_EN))
        p_Fm->f_Exception(p_Fm->h_App,e_FM_EX_FPM_DOUBLE_ECC);
    if ((event  & FPM_EV_MASK_STALL) && (event & FPM_EV_MASK_STALL_EN))
        p_Fm->f_Exception(p_Fm->h_App,e_FM_EX_FPM_STALL_ON_TASKS);
    if ((event  & FPM_EV_MASK_SINGLE_ECC) && (event & FPM_EV_MASK_SINGLE_ECC_EN))
        p_Fm->f_Exception(p_Fm->h_App,e_FM_EX_FPM_SINGLE_ECC);
}

static void    MuramErrIntr(t_Fm *p_Fm)
{
    uint32_t    event;
    struct fman_fpm_regs *fpm_rg = p_Fm->p_FmFpmRegs;

    event = fman_get_muram_err_event(fpm_rg);

    if (event & FPM_RAM_MURAM_ECC)
        p_Fm->f_Exception(p_Fm->h_App, e_FM_EX_MURAM_ECC);
}

static void IramErrIntr(t_Fm *p_Fm)
{
    uint32_t    event;
    struct fman_fpm_regs *fpm_rg = p_Fm->p_FmFpmRegs;

    event = fman_get_iram_err_event(fpm_rg);

    if (event & FPM_RAM_IRAM_ECC)
        p_Fm->f_Exception(p_Fm->h_App, e_FM_EX_IRAM_ECC);
}

static void QmiEvent(t_Fm *p_Fm)
{
    uint32_t    event;
    struct fman_qmi_regs *qmi_rg = p_Fm->p_FmQmiRegs;

    event = fman_get_qmi_event(qmi_rg);

    if (event & QMI_INTR_EN_SINGLE_ECC)
        p_Fm->f_Exception(p_Fm->h_App,e_FM_EX_QMI_SINGLE_ECC);
}

static void UnimplementedIsr(t_Handle h_Arg)
{
    UNUSED(h_Arg);

    REPORT_ERROR(MAJOR, E_NOT_SUPPORTED, ("Unimplemented ISR!"));
}

static void UnimplementedFmanCtrlIsr(t_Handle h_Arg, uint32_t event)
{
    UNUSED(h_Arg); UNUSED(event);

    REPORT_ERROR(MAJOR, E_NOT_SUPPORTED, ("Unimplemented FmCtl ISR!"));
}

static void EnableTimeStamp(t_Fm *p_Fm)
{
    struct fman_fpm_regs *fpm_rg = p_Fm->p_FmFpmRegs;

    ASSERT_COND(p_Fm->p_FmStateStruct);
    ASSERT_COND(p_Fm->p_FmStateStruct->count1MicroBit);

    fman_enable_time_stamp(fpm_rg, p_Fm->p_FmStateStruct->count1MicroBit, p_Fm->p_FmStateStruct->fmClkFreq);

    p_Fm->p_FmStateStruct->enabledTimeStamp = TRUE;
}

static t_Error ClearIRam(t_Fm *p_Fm)
{
    t_FMIramRegs    *p_Iram;
    int             i;
    int             iram_size;

    ASSERT_COND(p_Fm);
    p_Iram = (t_FMIramRegs *)UINT_TO_PTR(p_Fm->baseAddr + FM_MM_IMEM);
    iram_size = FM_IRAM_SIZE(p_Fm->p_FmStateStruct->revInfo.majorRev,p_Fm->p_FmStateStruct->revInfo.minorRev);

    /* Enable the auto-increment */
    WRITE_UINT32(p_Iram->iadd, IRAM_IADD_AIE);
    while (GET_UINT32(p_Iram->iadd) != IRAM_IADD_AIE) ;

    for (i=0; i < (iram_size/4); i++)
        WRITE_UINT32(p_Iram->idata, 0xffffffff);

    WRITE_UINT32(p_Iram->iadd, iram_size - 4);
    CORE_MemoryBarrier();
    while (GET_UINT32(p_Iram->idata) != 0xffffffff) ;

    return E_OK;
}

static t_Error LoadFmanCtrlCode(t_Fm *p_Fm)
{
    t_FMIramRegs    *p_Iram;
    int             i;
    uint32_t        tmp;
    uint8_t         compTo16;

    ASSERT_COND(p_Fm);
    p_Iram = (t_FMIramRegs *)UINT_TO_PTR(p_Fm->baseAddr + FM_MM_IMEM);

    /* Enable the auto-increment */
    WRITE_UINT32(p_Iram->iadd, IRAM_IADD_AIE);
    while (GET_UINT32(p_Iram->iadd) != IRAM_IADD_AIE) ;

    for (i=0; i < (p_Fm->firmware.size / 4); i++)
        WRITE_UINT32(p_Iram->idata, p_Fm->firmware.p_Code[i]);

    compTo16 = (uint8_t)(p_Fm->firmware.size % 16);
    if (compTo16)
        for (i=0; i < ((16-compTo16) / 4); i++)
            WRITE_UINT32(p_Iram->idata, 0xffffffff);

    WRITE_UINT32(p_Iram->iadd,p_Fm->firmware.size-4);
    while (GET_UINT32(p_Iram->iadd) != (p_Fm->firmware.size-4)) ;

    /* verify that writing has completed */
    while (GET_UINT32(p_Iram->idata) != p_Fm->firmware.p_Code[(p_Fm->firmware.size / 4)-1]) ;

    if (p_Fm->fwVerify)
    {
        WRITE_UINT32(p_Iram->iadd, IRAM_IADD_AIE);
        while (GET_UINT32(p_Iram->iadd) != IRAM_IADD_AIE) ;
        for (i=0; i < (p_Fm->firmware.size / 4); i++)
        {
            tmp = GET_UINT32(p_Iram->idata);
            if (tmp != p_Fm->firmware.p_Code[i])
                RETURN_ERROR(MAJOR, E_WRITE_FAILED,
                             ("UCode write error : write 0x%x, read 0x%x",
                              p_Fm->firmware.p_Code[i],tmp));
        }
        WRITE_UINT32(p_Iram->iadd, 0x0);
    }

    /* Enable patch from IRAM */
    WRITE_UINT32(p_Iram->iready, IRAM_READY);
    XX_UDelay(1000);

    DBG(INFO, ("FMan-Controller code (ver %d.%d.%d) loaded to IRAM.",
               ((uint16_t *)p_Fm->firmware.p_Code)[2],
               ((uint8_t *)p_Fm->firmware.p_Code)[6],
               ((uint8_t *)p_Fm->firmware.p_Code)[7]));

    return E_OK;
}

#ifdef FM_UCODE_NOT_RESET_ERRATA_BUGZILLA6173
static t_Error FwNotResetErratumBugzilla6173WA(t_Fm *p_Fm)
{
    t_FMIramRegs    *p_Iram = (t_FMIramRegs *)UINT_TO_PTR(p_Fm->baseAddr + FM_MM_IMEM);
    uint32_t        tmpReg;
    uint32_t        savedSpliodn[63];

    /* write to IRAM first location the debug instruction */
    WRITE_UINT32(p_Iram->iadd, 0);
    while (GET_UINT32(p_Iram->iadd) != 0) ;
    WRITE_UINT32(p_Iram->idata, FM_FW_DEBUG_INSTRUCTION);

    WRITE_UINT32(p_Iram->iadd, 0);
    while (GET_UINT32(p_Iram->iadd) != 0) ;
    while (GET_UINT32(p_Iram->idata) != FM_FW_DEBUG_INSTRUCTION) ;

    /* Enable patch from IRAM */
    WRITE_UINT32(p_Iram->iready, IRAM_READY);
    CORE_MemoryBarrier();
    XX_UDelay(100);
    IO2MemCpy32((uint8_t *)savedSpliodn,
                (uint8_t *)p_Fm->p_FmBmiRegs->fmbm_spliodn,
                63*sizeof(uint32_t));

    /* reset FMAN */
    WRITE_UINT32(p_Fm->p_FmFpmRegs->fm_rstc, FPM_RSTC_FM_RESET);
    CORE_MemoryBarrier();
    XX_UDelay(100);

    /* verify breakpoint debug status register */
    tmpReg = GET_UINT32(*(uint32_t *)UINT_TO_PTR(p_Fm->baseAddr + FM_DEBUG_STATUS_REGISTER_OFFSET));
    if (!tmpReg)
        REPORT_ERROR(MAJOR, E_INVALID_STATE, ("Invalid debug status register value is '0'"));

    /*************************************/
    /* Load FMan-Controller code to IRAM */
    /*************************************/
    ClearIRam(p_Fm);
    if (p_Fm->firmware.p_Code &&
        (LoadFmanCtrlCode(p_Fm) != E_OK))
        RETURN_ERROR(MAJOR, E_INVALID_STATE, NO_MSG);
    XX_UDelay(100);

    /* reset FMAN again to start the microcode */
    WRITE_UINT32(p_Fm->p_FmFpmRegs->fm_rstc, FPM_RSTC_FM_RESET);
    CORE_MemoryBarrier();
    XX_UDelay(100);
    Mem2IOCpy32((uint8_t *)p_Fm->p_FmBmiRegs->fmbm_spliodn,
                (uint8_t *)savedSpliodn,
                63*sizeof(uint32_t));

    if (fman_is_qmi_halt_not_busy_state(p_Fm->p_FmQmiRegs))
    {
        fman_resume(p_Fm->p_FmFpmRegs);
        CORE_MemoryBarrier();
        XX_UDelay(100);
    }

    return E_OK;
}
#endif /* FM_UCODE_NOT_RESET_ERRATA_BUGZILLA6173 */

static void GuestErrorIsr(t_Fm *p_Fm, uint32_t pending)
{
#define FM_G_CALL_1G_MAC_ERR_ISR(_id)   \
do {                                    \
    p_Fm->intrMng[(e_FmInterModuleEvent)(e_FM_EV_ERR_1G_MAC0+_id)].f_Isr(p_Fm->intrMng[(e_FmInterModuleEvent)(e_FM_EV_ERR_1G_MAC0+_id)].h_SrcHandle);\
} while (0)
#define FM_G_CALL_10G_MAC_ERR_ISR(_id)  \
do {                                    \
    p_Fm->intrMng[(e_FmInterModuleEvent)(e_FM_EV_ERR_10G_MAC0+_id)].f_Isr(p_Fm->intrMng[(e_FmInterModuleEvent)(e_FM_EV_ERR_10G_MAC0+_id)].h_SrcHandle);\
} while (0)

    /* error interrupts */
    if (pending & ERR_INTR_EN_1G_MAC0)
        FM_G_CALL_1G_MAC_ERR_ISR(0);
    if (pending & ERR_INTR_EN_1G_MAC1)
        FM_G_CALL_1G_MAC_ERR_ISR(1);
    if (pending & ERR_INTR_EN_1G_MAC2)
        FM_G_CALL_1G_MAC_ERR_ISR(2);
    if (pending & ERR_INTR_EN_1G_MAC3)
        FM_G_CALL_1G_MAC_ERR_ISR(3);
    if (pending & ERR_INTR_EN_1G_MAC4)
        FM_G_CALL_1G_MAC_ERR_ISR(4);
    if (pending & ERR_INTR_EN_1G_MAC5)
        FM_G_CALL_1G_MAC_ERR_ISR(5);
    if (pending & ERR_INTR_EN_1G_MAC6)
        FM_G_CALL_1G_MAC_ERR_ISR(6);
    if (pending & ERR_INTR_EN_1G_MAC7)
        FM_G_CALL_1G_MAC_ERR_ISR(7);
    if (pending & ERR_INTR_EN_10G_MAC0)
        FM_G_CALL_10G_MAC_ERR_ISR(0);
    if (pending & ERR_INTR_EN_10G_MAC1)
        FM_G_CALL_10G_MAC_ERR_ISR(1);
}

static void GuestEventIsr(t_Fm *p_Fm, uint32_t pending)
{
#define FM_G_CALL_1G_MAC_ISR(_id)   \
do {                                    \
    p_Fm->intrMng[(e_FmInterModuleEvent)(e_FM_EV_1G_MAC0+_id)].f_Isr(p_Fm->intrMng[(e_FmInterModuleEvent)(e_FM_EV_1G_MAC0+_id)].h_SrcHandle);\
} while (0)
#define FM_G_CALL_10G_MAC_ISR(_id)   \
do {                                    \
    p_Fm->intrMng[(e_FmInterModuleEvent)(e_FM_EV_10G_MAC0+_id)].f_Isr(p_Fm->intrMng[(e_FmInterModuleEvent)(e_FM_EV_10G_MAC0+_id)].h_SrcHandle);\
} while (0)

    if (pending & INTR_EN_1G_MAC0)
        FM_G_CALL_1G_MAC_ISR(0);
    if (pending & INTR_EN_1G_MAC1)
        FM_G_CALL_1G_MAC_ISR(1);
    if (pending & INTR_EN_1G_MAC2)
        FM_G_CALL_1G_MAC_ISR(2);
    if (pending & INTR_EN_1G_MAC3)
        FM_G_CALL_1G_MAC_ISR(3);
    if (pending & INTR_EN_1G_MAC4)
        FM_G_CALL_1G_MAC_ISR(4);
    if (pending & INTR_EN_1G_MAC5)
        FM_G_CALL_1G_MAC_ISR(5);
    if (pending & INTR_EN_1G_MAC6)
        FM_G_CALL_1G_MAC_ISR(6);
    if (pending & INTR_EN_1G_MAC7)
        FM_G_CALL_1G_MAC_ISR(7);
    if (pending & INTR_EN_10G_MAC0)
        FM_G_CALL_10G_MAC_ISR(0);
    if (pending & INTR_EN_10G_MAC1)
        FM_G_CALL_10G_MAC_ISR(1);
    if (pending & INTR_EN_TMR)
        p_Fm->intrMng[e_FM_EV_TMR].f_Isr(p_Fm->intrMng[e_FM_EV_TMR].h_SrcHandle);
}

#if (DPAA_VERSION >= 11)
static t_Error SetVSPWindow(t_Handle  h_Fm,
                            uint8_t   hardwarePortId,
                            uint8_t   baseStorageProfile,
                            uint8_t   log2NumOfProfiles)
{
    t_Fm                    *p_Fm = (t_Fm *)h_Fm;

    ASSERT_COND(h_Fm);
    ASSERT_COND(IN_RANGE(1, hardwarePortId, 63));

    if ((p_Fm->guestId != NCSW_MASTER_ID) &&
        !p_Fm->p_FmBmiRegs &&
        p_Fm->h_IpcSessions[0])
    {
        t_FmIpcVspSetPortWindow fmIpcVspSetPortWindow;
        t_FmIpcMsg              msg;
        t_Error                 err = E_OK;

        memset(&msg, 0, sizeof(msg));
        memset(&fmIpcVspSetPortWindow, 0, sizeof(t_FmIpcVspSetPortWindow));
        fmIpcVspSetPortWindow.hardwarePortId      = hardwarePortId;
        fmIpcVspSetPortWindow.baseStorageProfile  = baseStorageProfile;
        fmIpcVspSetPortWindow.log2NumOfProfiles   = log2NumOfProfiles;
        msg.msgId                                 = FM_VSP_SET_PORT_WINDOW;
        memcpy(msg.msgBody, &fmIpcVspSetPortWindow, sizeof(t_FmIpcVspSetPortWindow));

        err = XX_IpcSendMessage(p_Fm->h_IpcSessions[0],
                                (uint8_t*)&msg,
                                sizeof(msg.msgId),
                                NULL,
                                NULL,
                                NULL,
                                NULL);
        if (err != E_OK)
            RETURN_ERROR(MINOR, err, NO_MSG);
        return E_OK;
    }
    else if (!p_Fm->p_FmBmiRegs)
        RETURN_ERROR(MINOR, E_NOT_SUPPORTED,
                     ("Either IPC or 'baseAddress' is required!"));

    fman_set_vsp_window(p_Fm->p_FmBmiRegs,
                        hardwarePortId,
                        baseStorageProfile,
                        log2NumOfProfiles);

    return E_OK;
}

static uint8_t AllocVSPsForPartition(t_Handle  h_Fm, uint8_t base, uint8_t numOfProfiles, uint8_t guestId)
{
    t_Fm        *p_Fm = (t_Fm *)h_Fm;
    uint8_t     profilesFound = 0;
    int         i = 0;
    uint32_t    intFlags;

    if (!numOfProfiles)
        return E_OK;

    if ((numOfProfiles > FM_VSP_MAX_NUM_OF_ENTRIES) ||
        (base + numOfProfiles > FM_VSP_MAX_NUM_OF_ENTRIES))
        return (uint8_t)ILLEGAL_BASE;

    if (p_Fm->h_IpcSessions[0])
    {
        t_FmIpcResourceAllocParams  ipcAllocParams;
        t_FmIpcMsg                  msg;
        t_FmIpcReply                reply;
        t_Error                     err;
        uint32_t                    replyLength;

        memset(&msg, 0, sizeof(msg));
        memset(&reply, 0, sizeof(reply));
        memset(&ipcAllocParams, 0, sizeof(t_FmIpcResourceAllocParams));
        ipcAllocParams.guestId         = p_Fm->guestId;
        ipcAllocParams.num             = p_Fm->partNumOfVSPs;
        ipcAllocParams.base            = p_Fm->partVSPBase;
        msg.msgId                              = FM_VSP_ALLOC;
        memcpy(msg.msgBody, &ipcAllocParams, sizeof(t_FmIpcResourceAllocParams));
        replyLength = sizeof(uint32_t) + sizeof(uint8_t);
        err = XX_IpcSendMessage(p_Fm->h_IpcSessions[0],
                                (uint8_t*)&msg,
                                sizeof(msg.msgId) + sizeof(t_FmIpcResourceAllocParams),
                                (uint8_t*)&reply,
                                &replyLength,
                                NULL,
                                NULL);
        if ((err != E_OK) ||
            (replyLength != (sizeof(uint32_t) + sizeof(uint8_t))))
            RETURN_ERROR(MAJOR, err, NO_MSG);
        else
            memcpy((uint8_t*)&p_Fm->partVSPBase, reply.replyBody, sizeof(uint8_t));
        if (p_Fm->partVSPBase == (uint8_t)(ILLEGAL_BASE))
            RETURN_ERROR(MAJOR, err, NO_MSG);
    }
    if (p_Fm->guestId != NCSW_MASTER_ID)
    {
        DBG(WARNING, ("FM Guest mode, without IPC - can't validate VSP range!"));
        return (uint8_t)ILLEGAL_BASE;
    }

    intFlags = XX_LockIntrSpinlock(p_Fm->h_Spinlock);
    for (i = base; i < base + numOfProfiles; i++)
        if (p_Fm->p_FmSp->profiles[i].profilesMng.ownerId == (uint8_t)ILLEGAL_BASE)
            profilesFound++;
        else
            break;

    if (profilesFound == numOfProfiles)
        for (i = base; i<base + numOfProfiles; i++)
            p_Fm->p_FmSp->profiles[i].profilesMng.ownerId = guestId;
    else
    {
        XX_UnlockIntrSpinlock(p_Fm->h_Spinlock, intFlags);
        return (uint8_t)ILLEGAL_BASE;
    }
    XX_UnlockIntrSpinlock(p_Fm->h_Spinlock, intFlags);

    return base;
}

static void FreeVSPsForPartition(t_Handle  h_Fm, uint8_t base, uint8_t numOfProfiles, uint8_t guestId)
{
    t_Fm    *p_Fm = (t_Fm *)h_Fm;
    int     i = 0;

    ASSERT_COND(p_Fm);

    if (p_Fm->h_IpcSessions[0])
    {
        t_FmIpcResourceAllocParams  ipcAllocParams;
        t_FmIpcMsg                  msg;
        t_FmIpcReply                reply;
        uint32_t                    replyLength;
        t_Error                     err;

        memset(&msg, 0, sizeof(msg));
        memset(&reply, 0, sizeof(reply));
        memset(&ipcAllocParams, 0, sizeof(t_FmIpcResourceAllocParams));
        ipcAllocParams.guestId         = p_Fm->guestId;
        ipcAllocParams.num             = p_Fm->partNumOfVSPs;
        ipcAllocParams.base            = p_Fm->partVSPBase;
        msg.msgId                              = FM_VSP_FREE;
        memcpy(msg.msgBody, &ipcAllocParams, sizeof(t_FmIpcResourceAllocParams));
        replyLength = sizeof(uint32_t) + sizeof(uint8_t);
        err = XX_IpcSendMessage(p_Fm->h_IpcSessions[0],
                                (uint8_t*)&msg,
                                sizeof(msg.msgId) + sizeof(t_FmIpcResourceAllocParams),
                                (uint8_t*)&reply,
                                &replyLength,
                                NULL,
                                NULL);
        if (err != E_OK)
            REPORT_ERROR(MAJOR, err, NO_MSG);
        return;
    }
    if (p_Fm->guestId != NCSW_MASTER_ID)
    {
        DBG(WARNING, ("FM Guest mode, without IPC - can't validate VSP range!"));
        return;
    }

    ASSERT_COND(p_Fm->p_FmSp);

    for (i=base; i<numOfProfiles; i++)
    {
        if (p_Fm->p_FmSp->profiles[i].profilesMng.ownerId == guestId)
           p_Fm->p_FmSp->profiles[i].profilesMng.ownerId = (uint8_t)ILLEGAL_BASE;
        else
            DBG(WARNING, ("Request for freeing storage profile window which wasn't allocated to this partition"));
    }
}
#endif /* (DPAA_VERSION >= 11) */

static t_Error FmGuestHandleIpcMsgCB(t_Handle  h_Fm,
                                     uint8_t   *p_Msg,
                                     uint32_t  msgLength,
                                     uint8_t   *p_Reply,
                                     uint32_t  *p_ReplyLength)
{
    t_Fm            *p_Fm       = (t_Fm*)h_Fm;
    t_FmIpcMsg      *p_IpcMsg   = (t_FmIpcMsg*)p_Msg;

    UNUSED(p_Reply);
    SANITY_CHECK_RETURN_ERROR(p_Fm, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR((msgLength > sizeof(uint32_t)), E_INVALID_VALUE);

#ifdef DISABLE_SANITY_CHECKS
    UNUSED(msgLength);
#endif /* DISABLE_SANITY_CHECKS */

    ASSERT_COND(p_Msg);

    *p_ReplyLength = 0;

    switch (p_IpcMsg->msgId)
    {
        case (FM_GUEST_ISR):
        {
            t_FmIpcIsr ipcIsr;

            memcpy((uint8_t*)&ipcIsr, p_IpcMsg->msgBody, sizeof(t_FmIpcIsr));
            if (ipcIsr.boolErr)
                GuestErrorIsr(p_Fm, ipcIsr.pendingReg);
            else
                GuestEventIsr(p_Fm, ipcIsr.pendingReg);
            break;
        }
        default:
            *p_ReplyLength = 0;
            RETURN_ERROR(MINOR, E_INVALID_SELECTION, ("command not found!!!"));
    }
    return E_OK;
}

static t_Error FmHandleIpcMsgCB(t_Handle  h_Fm,
                                uint8_t   *p_Msg,
                                uint32_t  msgLength,
                                uint8_t   *p_Reply,
                                uint32_t  *p_ReplyLength)
{
    t_Error         err;
    t_Fm            *p_Fm       = (t_Fm*)h_Fm;
    t_FmIpcMsg      *p_IpcMsg   = (t_FmIpcMsg*)p_Msg;
    t_FmIpcReply    *p_IpcReply = (t_FmIpcReply*)p_Reply;

    SANITY_CHECK_RETURN_ERROR(p_Fm, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR((msgLength >= sizeof(uint32_t)), E_INVALID_VALUE);

#ifdef DISABLE_SANITY_CHECKS
    UNUSED(msgLength);
#endif /* DISABLE_SANITY_CHECKS */

    ASSERT_COND(p_IpcMsg);

    memset(p_IpcReply, 0, (sizeof(uint8_t) * FM_IPC_MAX_REPLY_SIZE));
    *p_ReplyLength = 0;

    switch (p_IpcMsg->msgId)
    {
        case (FM_GET_SET_PORT_PARAMS):
        {
            t_FmIpcPortInInitParams         ipcInitParams;
            t_FmInterModulePortInitParams   initParams;
            t_FmIpcPortOutInitParams        ipcOutInitParams;

            memcpy((uint8_t*)&ipcInitParams, p_IpcMsg->msgBody, sizeof(t_FmIpcPortInInitParams));
            initParams.hardwarePortId = ipcInitParams.hardwarePortId;
            initParams.portType = (e_FmPortType)ipcInitParams.enumPortType;
            initParams.independentMode = (bool)(ipcInitParams.boolIndependentMode);
            initParams.liodnOffset = ipcInitParams.liodnOffset;
            initParams.numOfTasks = ipcInitParams.numOfTasks;
            initParams.numOfExtraTasks = ipcInitParams.numOfExtraTasks;
            initParams.numOfOpenDmas = ipcInitParams.numOfOpenDmas;
            initParams.numOfExtraOpenDmas = ipcInitParams.numOfExtraOpenDmas;
            initParams.sizeOfFifo = ipcInitParams.sizeOfFifo;
            initParams.extraSizeOfFifo = ipcInitParams.extraSizeOfFifo;
            initParams.deqPipelineDepth = ipcInitParams.deqPipelineDepth;
            initParams.maxFrameLength = ipcInitParams.maxFrameLength;
            initParams.liodnBase = ipcInitParams.liodnBase;

            p_IpcReply->error = (uint32_t)FmGetSetPortParams(h_Fm, &initParams);

            ipcOutInitParams.ipcPhysAddr.high = initParams.fmMuramPhysBaseAddr.high;
            ipcOutInitParams.ipcPhysAddr.low = initParams.fmMuramPhysBaseAddr.low;
            ipcOutInitParams.sizeOfFifo = initParams.sizeOfFifo;
            ipcOutInitParams.extraSizeOfFifo = initParams.extraSizeOfFifo;
            ipcOutInitParams.numOfTasks = initParams.numOfTasks;
            ipcOutInitParams.numOfExtraTasks = initParams.numOfExtraTasks;
            ipcOutInitParams.numOfOpenDmas = initParams.numOfOpenDmas;
            ipcOutInitParams.numOfExtraOpenDmas = initParams.numOfExtraOpenDmas;
            memcpy(p_IpcReply->replyBody, (uint8_t*)&ipcOutInitParams, sizeof(ipcOutInitParams));
            *p_ReplyLength = sizeof(uint32_t) + sizeof(t_FmIpcPortOutInitParams);
            break;
        }
        case (FM_SET_SIZE_OF_FIFO):
        {
            t_FmIpcPortRsrcParams   ipcPortRsrcParams;

            memcpy((uint8_t*)&ipcPortRsrcParams, p_IpcMsg->msgBody, sizeof(t_FmIpcPortRsrcParams));
            p_IpcReply->error = (uint32_t)FmSetSizeOfFifo(h_Fm,
                                                          ipcPortRsrcParams.hardwarePortId,
                                                          &ipcPortRsrcParams.val,
                                                          &ipcPortRsrcParams.extra,
                                                          (bool)ipcPortRsrcParams.boolInitialConfig);
            *p_ReplyLength = sizeof(uint32_t);
            break;
        }
        case (FM_SET_NUM_OF_TASKS):
        {
            t_FmIpcPortRsrcParams   ipcPortRsrcParams;

            memcpy((uint8_t*)&ipcPortRsrcParams, p_IpcMsg->msgBody, sizeof(t_FmIpcPortRsrcParams));
            p_IpcReply->error = (uint32_t)FmSetNumOfTasks(h_Fm, ipcPortRsrcParams.hardwarePortId,
                                                          (uint8_t*)&ipcPortRsrcParams.val,
                                                          (uint8_t*)&ipcPortRsrcParams.extra,
                                                          (bool)ipcPortRsrcParams.boolInitialConfig);
            *p_ReplyLength = sizeof(uint32_t);
            break;
        }
        case (FM_SET_NUM_OF_OPEN_DMAS):
        {
            t_FmIpcPortRsrcParams   ipcPortRsrcParams;

            memcpy((uint8_t*)&ipcPortRsrcParams, p_IpcMsg->msgBody, sizeof(t_FmIpcPortRsrcParams));
            p_IpcReply->error = (uint32_t)FmSetNumOfOpenDmas(h_Fm, ipcPortRsrcParams.hardwarePortId,
                                                               (uint8_t*)&ipcPortRsrcParams.val,
                                                               (uint8_t*)&ipcPortRsrcParams.extra,
                                                               (bool)ipcPortRsrcParams.boolInitialConfig);
            *p_ReplyLength = sizeof(uint32_t);
            break;
        }
        case (FM_RESUME_STALLED_PORT):
            *p_ReplyLength = sizeof(uint32_t);
            p_IpcReply->error = (uint32_t)FmResumeStalledPort(h_Fm, p_IpcMsg->msgBody[0]);
            break;
        case (FM_MASTER_IS_ALIVE):
        {
            uint8_t guestId = p_IpcMsg->msgBody[0];
            /* build the FM master partition IPC address */
            memset(p_Fm->fmIpcHandlerModuleName[guestId], 0, (sizeof(char)) * MODULE_NAME_SIZE);
            if (Sprint (p_Fm->fmIpcHandlerModuleName[guestId], "FM_%d_%d",p_Fm->p_FmStateStruct->fmId, guestId) != (guestId<10 ? 6:7))
                RETURN_ERROR(MAJOR, E_INVALID_STATE, ("Sprint failed"));
            p_Fm->h_IpcSessions[guestId] = XX_IpcInitSession(p_Fm->fmIpcHandlerModuleName[guestId], p_Fm->fmModuleName);
            if (p_Fm->h_IpcSessions[guestId] == NULL)
                RETURN_ERROR(MAJOR, E_NOT_AVAILABLE, ("FM Master IPC session for guest %d", guestId));
            *(uint8_t*)(p_IpcReply->replyBody) = 1;
            *p_ReplyLength = sizeof(uint32_t) + sizeof(uint8_t);
            break;
        }
        case (FM_IS_PORT_STALLED):
        {
            bool tmp;

            p_IpcReply->error = (uint32_t)FmIsPortStalled(h_Fm, p_IpcMsg->msgBody[0], &tmp);
            *(uint8_t*)(p_IpcReply->replyBody) = (uint8_t)tmp;
            *p_ReplyLength = sizeof(uint32_t) + sizeof(uint8_t);
            break;
        }
        case (FM_RESET_MAC):
        {
            t_FmIpcMacParams    ipcMacParams;

            memcpy((uint8_t*)&ipcMacParams, p_IpcMsg->msgBody, sizeof(t_FmIpcMacParams));
            p_IpcReply->error = (uint32_t)FmResetMac(p_Fm,
                                                     (e_FmMacType)(ipcMacParams.enumType),
                                                     ipcMacParams.id);
            *p_ReplyLength = sizeof(uint32_t);
            break;
        }
        case (FM_SET_MAC_MAX_FRAME):
        {
            t_FmIpcMacMaxFrameParams    ipcMacMaxFrameParams;

            memcpy((uint8_t*)&ipcMacMaxFrameParams, p_IpcMsg->msgBody, sizeof(t_FmIpcMacMaxFrameParams));
            err = FmSetMacMaxFrame(p_Fm,
                                  (e_FmMacType)(ipcMacMaxFrameParams.macParams.enumType),
                                  ipcMacMaxFrameParams.macParams.id,
                                  ipcMacMaxFrameParams.maxFrameLength);
            if (err != E_OK)
                REPORT_ERROR(MINOR, err, NO_MSG);
            break;
        }
#if (DPAA_VERSION >= 11)
        case (FM_VSP_ALLOC) :
        {
            t_FmIpcResourceAllocParams  ipcAllocParams;
            uint8_t                     vspBase;
            memcpy(&ipcAllocParams, p_IpcMsg->msgBody, sizeof(t_FmIpcResourceAllocParams));
            vspBase =  AllocVSPsForPartition(h_Fm, (uint8_t)ipcAllocParams.base, (uint8_t)ipcAllocParams.num, ipcAllocParams.guestId);
            memcpy(p_IpcReply->replyBody, (uint8_t*)&vspBase, sizeof(uint8_t));
            *p_ReplyLength = sizeof(uint32_t) + sizeof(uint8_t);
            break;
        }
        case (FM_VSP_FREE) :
        {
            t_FmIpcResourceAllocParams   ipcAllocParams;
            memcpy(&ipcAllocParams, p_IpcMsg->msgBody, sizeof(t_FmIpcResourceAllocParams));
            FreeVSPsForPartition(h_Fm, (uint8_t)ipcAllocParams.base, (uint8_t)ipcAllocParams.num, ipcAllocParams.guestId);
            break;
        }
        case (FM_VSP_SET_PORT_WINDOW) :
        {
            t_FmIpcVspSetPortWindow   ipcVspSetPortWindow;
            memcpy(&ipcVspSetPortWindow, p_IpcMsg->msgBody, sizeof(t_FmIpcVspSetPortWindow));
            err = SetVSPWindow(h_Fm,
                                            ipcVspSetPortWindow.hardwarePortId,
                                            ipcVspSetPortWindow.baseStorageProfile,
                                            ipcVspSetPortWindow.log2NumOfProfiles);
            return err;
        }
        case (FM_SET_CONG_GRP_PFC_PRIO) :
        {
            t_FmIpcSetCongestionGroupPfcPriority    fmIpcSetCongestionGroupPfcPriority;
            memcpy(&fmIpcSetCongestionGroupPfcPriority, p_IpcMsg->msgBody, sizeof(t_FmIpcSetCongestionGroupPfcPriority));
            err = FmSetCongestionGroupPFCpriority(h_Fm,
                                                  fmIpcSetCongestionGroupPfcPriority.congestionGroupId,
                                                  fmIpcSetCongestionGroupPfcPriority.priorityBitMap);
            return err;
        }
#endif /* (DPAA_VERSION >= 11) */

        case (FM_FREE_PORT):
        {
            t_FmInterModulePortFreeParams   portParams;
            t_FmIpcPortFreeParams           ipcPortParams;

            memcpy((uint8_t*)&ipcPortParams, p_IpcMsg->msgBody, sizeof(t_FmIpcPortFreeParams));
            portParams.hardwarePortId = ipcPortParams.hardwarePortId;
            portParams.portType = (e_FmPortType)(ipcPortParams.enumPortType);
            portParams.deqPipelineDepth = ipcPortParams.deqPipelineDepth;
            FmFreePortParams(h_Fm, &portParams);
            break;
        }
        case (FM_REGISTER_INTR):
        {
            t_FmIpcRegisterIntr ipcRegIntr;

            memcpy((uint8_t*)&ipcRegIntr, p_IpcMsg->msgBody, sizeof(ipcRegIntr));
            p_Fm->intrMng[ipcRegIntr.event].guestId = ipcRegIntr.guestId;
            break;
        }
        case (FM_GET_PARAMS):
        {
             t_FmIpcParams  ipcParams;

            /* Get clock frequency */
            ipcParams.fmClkFreq = p_Fm->p_FmStateStruct->fmClkFreq;
            ipcParams.fmMacClkFreq = p_Fm->p_FmStateStruct->fmMacClkFreq;

            fman_get_revision(p_Fm->p_FmFpmRegs,&ipcParams.majorRev,&ipcParams.minorRev);

            memcpy(p_IpcReply->replyBody, (uint8_t*)&ipcParams, sizeof(t_FmIpcParams));
            *p_ReplyLength = sizeof(uint32_t) + sizeof(t_FmIpcParams);
             break;
        }
        case (FM_GET_FMAN_CTRL_CODE_REV):
        {
            t_FmCtrlCodeRevisionInfo        fmanCtrlRevInfo;
            t_FmIpcFmanCtrlCodeRevisionInfo ipcRevInfo;

            p_IpcReply->error = (uint32_t)FM_GetFmanCtrlCodeRevision(h_Fm, &fmanCtrlRevInfo);
            ipcRevInfo.packageRev = fmanCtrlRevInfo.packageRev;
            ipcRevInfo.majorRev = fmanCtrlRevInfo.majorRev;
            ipcRevInfo.minorRev = fmanCtrlRevInfo.minorRev;
            memcpy(p_IpcReply->replyBody, (uint8_t*)&ipcRevInfo, sizeof(t_FmIpcFmanCtrlCodeRevisionInfo));
            *p_ReplyLength = sizeof(uint32_t) + sizeof(t_FmIpcFmanCtrlCodeRevisionInfo);
            break;
        }

        case (FM_DMA_STAT):
        {
            t_FmDmaStatus       dmaStatus;
            t_FmIpcDmaStatus    ipcDmaStatus;

            FM_GetDmaStatus(h_Fm, &dmaStatus);
            ipcDmaStatus.boolCmqNotEmpty = (uint8_t)dmaStatus.cmqNotEmpty;
            ipcDmaStatus.boolBusError = (uint8_t)dmaStatus.busError;
            ipcDmaStatus.boolReadBufEccError = (uint8_t)dmaStatus.readBufEccError;
            ipcDmaStatus.boolWriteBufEccSysError = (uint8_t)dmaStatus.writeBufEccSysError;
            ipcDmaStatus.boolWriteBufEccFmError = (uint8_t)dmaStatus.writeBufEccFmError;
            ipcDmaStatus.boolSinglePortEccError = (uint8_t)dmaStatus.singlePortEccError;
            memcpy(p_IpcReply->replyBody, (uint8_t*)&ipcDmaStatus, sizeof(t_FmIpcDmaStatus));
            *p_ReplyLength = sizeof(uint32_t) + sizeof(t_FmIpcDmaStatus);
            break;
        }
        case (FM_ALLOC_FMAN_CTRL_EVENT_REG):
            p_IpcReply->error = (uint32_t)FmAllocFmanCtrlEventReg(h_Fm, (uint8_t*)p_IpcReply->replyBody);
            *p_ReplyLength = sizeof(uint32_t) + sizeof(uint8_t);
            break;
        case (FM_FREE_FMAN_CTRL_EVENT_REG):
            FmFreeFmanCtrlEventReg(h_Fm, p_IpcMsg->msgBody[0]);
            break;
        case (FM_GET_TIMESTAMP_SCALE):
        {
            uint32_t    timeStamp = FmGetTimeStampScale(h_Fm);

            memcpy(p_IpcReply->replyBody, (uint8_t*)&timeStamp, sizeof(uint32_t));
            *p_ReplyLength = sizeof(uint32_t) + sizeof(uint32_t);
            break;
        }
        case (FM_GET_COUNTER):
        {
            e_FmCounters    inCounter;
            uint32_t        outCounter;

            memcpy((uint8_t*)&inCounter, p_IpcMsg->msgBody, sizeof(uint32_t));
            outCounter = FM_GetCounter(h_Fm, inCounter);
            memcpy(p_IpcReply->replyBody, (uint8_t*)&outCounter, sizeof(uint32_t));
            *p_ReplyLength = sizeof(uint32_t) + sizeof(uint32_t);
            break;
        }
        case (FM_SET_FMAN_CTRL_EVENTS_ENABLE):
        {
            t_FmIpcFmanEvents ipcFmanEvents;

            memcpy((uint8_t*)&ipcFmanEvents, p_IpcMsg->msgBody, sizeof(t_FmIpcFmanEvents));
            FmSetFmanCtrlIntr(h_Fm,
                              ipcFmanEvents.eventRegId,
                              ipcFmanEvents.enableEvents);
            break;
        }
        case (FM_GET_FMAN_CTRL_EVENTS_ENABLE):
        {
            uint32_t    tmp = FmGetFmanCtrlIntr(h_Fm, p_IpcMsg->msgBody[0]);

            memcpy(p_IpcReply->replyBody, (uint8_t*)&tmp, sizeof(uint32_t));
            *p_ReplyLength = sizeof(uint32_t) + sizeof(uint32_t);
            break;
        }
        case (FM_GET_PHYS_MURAM_BASE):
        {
            t_FmPhysAddr        physAddr;
            t_FmIpcPhysAddr     ipcPhysAddr;

            FmGetPhysicalMuramBase(h_Fm, &physAddr);
            ipcPhysAddr.high    = physAddr.high;
            ipcPhysAddr.low     = physAddr.low;
            memcpy(p_IpcReply->replyBody, (uint8_t*)&ipcPhysAddr, sizeof(t_FmIpcPhysAddr));
            *p_ReplyLength = sizeof(uint32_t) + sizeof(t_FmIpcPhysAddr);
            break;
        }
        case (FM_ENABLE_RAM_ECC):
        {
            if (((err = FM_EnableRamsEcc(h_Fm)) != E_OK) ||
                ((err = FM_SetException(h_Fm, e_FM_EX_IRAM_ECC, TRUE)) != E_OK) ||
                ((err = FM_SetException(h_Fm, e_FM_EX_MURAM_ECC, TRUE)) != E_OK))
#if (!(defined(DEBUG_ERRORS)) || (DEBUG_ERRORS == 0))
                UNUSED(err);
#else
                REPORT_ERROR(MINOR, err, NO_MSG);
#endif /* (!(defined(DEBUG_ERRORS)) || (DEBUG_ERRORS == 0)) */
            break;
        }
        case (FM_DISABLE_RAM_ECC):
        {

            if (((err = FM_SetException(h_Fm, e_FM_EX_IRAM_ECC, FALSE)) != E_OK) ||
                ((err = FM_SetException(h_Fm, e_FM_EX_MURAM_ECC, FALSE)) != E_OK) ||
                ((err = FM_DisableRamsEcc(h_Fm)) != E_OK))
#if (!(defined(DEBUG_ERRORS)) || (DEBUG_ERRORS == 0))
                UNUSED(err);
#else
                REPORT_ERROR(MINOR, err, NO_MSG);
#endif /* (!(defined(DEBUG_ERRORS)) || (DEBUG_ERRORS == 0)) */
            break;
        }
        case (FM_SET_NUM_OF_FMAN_CTRL):
        {
            t_FmIpcPortNumOfFmanCtrls   ipcPortNumOfFmanCtrls;

            memcpy((uint8_t*)&ipcPortNumOfFmanCtrls, p_IpcMsg->msgBody, sizeof(t_FmIpcPortNumOfFmanCtrls));
            err = FmSetNumOfRiscsPerPort(h_Fm,
                                         ipcPortNumOfFmanCtrls.hardwarePortId,
                                         ipcPortNumOfFmanCtrls.numOfFmanCtrls,
                                         ipcPortNumOfFmanCtrls.orFmanCtrl);
            if (err != E_OK)
                REPORT_ERROR(MINOR, err, NO_MSG);
            break;
        }
#ifdef FM_TX_ECC_FRMS_ERRATA_10GMAC_A004
        case (FM_10G_TX_ECC_WA):
            p_IpcReply->error = (uint32_t)Fm10GTxEccWorkaround(h_Fm, p_IpcMsg->msgBody[0]);
            *p_ReplyLength = sizeof(uint32_t);
            break;
#endif /* FM_TX_ECC_FRMS_ERRATA_10GMAC_A004 */
        default:
            *p_ReplyLength = 0;
            RETURN_ERROR(MINOR, E_INVALID_SELECTION, ("command not found!!!"));
    }
    return E_OK;
}


/****************************************/
/*       Inter-Module functions         */
/****************************************/
#ifdef FM_TX_ECC_FRMS_ERRATA_10GMAC_A004
t_Error Fm10GTxEccWorkaround(t_Handle h_Fm, uint8_t macId)
{
    t_Fm            *p_Fm = (t_Fm*)h_Fm;
    t_Error         err = E_OK;
    t_FmIpcMsg      msg;
    t_FmIpcReply    reply;
    uint32_t        replyLength;
    uint8_t         rxHardwarePortId, txHardwarePortId;
    struct fman_fpm_regs *fpm_rg = p_Fm->p_FmFpmRegs;

    if (p_Fm->guestId != NCSW_MASTER_ID)
    {
        memset(&msg, 0, sizeof(msg));
        memset(&reply, 0, sizeof(reply));
        msg.msgId = FM_10G_TX_ECC_WA;
        msg.msgBody[0] = macId;
        replyLength = sizeof(uint32_t);
        if ((err = XX_IpcSendMessage(p_Fm->h_IpcSessions[0],
                                     (uint8_t*)&msg,
                                     sizeof(msg.msgId)+sizeof(macId),
                                     (uint8_t*)&reply,
                                     &replyLength,
                                     NULL,
                                     NULL)) != E_OK)
            RETURN_ERROR(MINOR, err, NO_MSG);
        if (replyLength != sizeof(uint32_t))
            RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("IPC reply length mismatch"));
        return (t_Error)(reply.error);
    }

    SANITY_CHECK_RETURN_ERROR((macId == 0), E_NOT_SUPPORTED);
    SANITY_CHECK_RETURN_ERROR(IsFmanCtrlCodeLoaded(p_Fm), E_INVALID_STATE);

    rxHardwarePortId = SwPortIdToHwPortId(e_FM_PORT_TYPE_RX_10G,
                                    macId,
                                    p_Fm->p_FmStateStruct->revInfo.majorRev,
                                    p_Fm->p_FmStateStruct->revInfo.minorRev);
    txHardwarePortId = SwPortIdToHwPortId(e_FM_PORT_TYPE_TX_10G,
                                    macId,
                                    p_Fm->p_FmStateStruct->revInfo.majorRev,
                                    p_Fm->p_FmStateStruct->revInfo.minorRev);
    if ((p_Fm->p_FmStateStruct->portsTypes[rxHardwarePortId] != e_FM_PORT_TYPE_DUMMY) ||
        (p_Fm->p_FmStateStruct->portsTypes[txHardwarePortId] != e_FM_PORT_TYPE_DUMMY))
        RETURN_ERROR(MAJOR, E_INVALID_STATE,
                     ("MAC should be initialized prior to Rx and Tx ports!"));

    return fman_set_erratum_10gmac_a004_wa(fpm_rg);
}
#endif /* FM_TX_ECC_FRMS_ERRATA_10GMAC_A004 */

uint16_t FmGetTnumAgingPeriod(t_Handle h_Fm)
{
    t_Fm *p_Fm = (t_Fm *)h_Fm;

    SANITY_CHECK_RETURN_VALUE(p_Fm, E_INVALID_HANDLE, 0);
    SANITY_CHECK_RETURN_VALUE(!p_Fm->p_FmDriverParam, E_INVALID_STATE, 0);

    return p_Fm->tnumAgingPeriod;
}

t_Error FmSetPortPreFetchConfiguration(t_Handle h_Fm,
                                       uint8_t  portNum,
                                       bool     preFetchConfigured)
{
    t_Fm *p_Fm = (t_Fm*)h_Fm;

    SANITY_CHECK_RETURN_ERROR(p_Fm, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(!p_Fm->p_FmDriverParam, E_INVALID_STATE);

    p_Fm->portsPreFetchConfigured[portNum] = TRUE;
    p_Fm->portsPreFetchValue[portNum] = preFetchConfigured;

    return E_OK;
}

t_Error FmGetPortPreFetchConfiguration(t_Handle h_Fm,
                                       uint8_t  portNum,
                                       bool     *p_PortConfigured,
                                       bool     *p_PreFetchConfigured)
{
    t_Fm *p_Fm = (t_Fm*)h_Fm;

    SANITY_CHECK_RETURN_ERROR(p_Fm, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(!p_Fm->p_FmDriverParam, E_INVALID_STATE);

    /* If the prefetch wasn't configured yet (not enable or disabled)
       we return the value TRUE as it was already configured */
    if (!p_Fm->portsPreFetchConfigured[portNum])
    {
        *p_PortConfigured = FALSE;
        *p_PreFetchConfigured = FALSE;
    }
    else
    {
        *p_PortConfigured = TRUE;
        *p_PreFetchConfigured = (p_Fm->portsPreFetchConfigured[portNum]);
    }

    return E_OK;
}

t_Error FmSetCongestionGroupPFCpriority(t_Handle    h_Fm,
                                        uint32_t    congestionGroupId,
                                        uint8_t     priorityBitMap)
{
    t_Fm    *p_Fm  = (t_Fm *)h_Fm;
    uint32_t regNum;

    ASSERT_COND(h_Fm);

    if (congestionGroupId > FM_PORT_NUM_OF_CONGESTION_GRPS)
        RETURN_ERROR(MAJOR, E_INVALID_VALUE,
                     ("Congestion group ID bigger than %d",
                      FM_PORT_NUM_OF_CONGESTION_GRPS));

    if (p_Fm->guestId == NCSW_MASTER_ID)
    {
        ASSERT_COND(p_Fm->baseAddr);
        regNum = (FM_PORT_NUM_OF_CONGESTION_GRPS - 1 - congestionGroupId) / 4;
        fman_set_congestion_group_pfc_priority((uint32_t *)((p_Fm->baseAddr+FM_MM_CGP)),
                                               congestionGroupId,
                                               priorityBitMap,
                                               regNum);
    }
    else if (p_Fm->h_IpcSessions[0])
    {
        t_Error                              err;
        t_FmIpcMsg                           msg;
        t_FmIpcSetCongestionGroupPfcPriority fmIpcSetCongestionGroupPfcPriority;

        memset(&msg, 0, sizeof(msg));
        memset(&fmIpcSetCongestionGroupPfcPriority, 0, sizeof(t_FmIpcSetCongestionGroupPfcPriority));
        fmIpcSetCongestionGroupPfcPriority.congestionGroupId = congestionGroupId;
        fmIpcSetCongestionGroupPfcPriority.priorityBitMap    = priorityBitMap;

        msg.msgId = FM_SET_CONG_GRP_PFC_PRIO;
        memcpy(msg.msgBody, &fmIpcSetCongestionGroupPfcPriority, sizeof(t_FmIpcSetCongestionGroupPfcPriority));

        err = XX_IpcSendMessage(p_Fm->h_IpcSessions[0],
                                (uint8_t*)&msg,
                                sizeof(msg.msgId),
                                NULL,
                                NULL,
                                NULL,
                                NULL);
        if (err != E_OK)
            RETURN_ERROR(MINOR, err, NO_MSG);
    }
    else
        RETURN_ERROR(MAJOR, E_INVALID_STATE, ("guest without IPC!"));

    return E_OK;
}

uintptr_t FmGetPcdPrsBaseAddr(t_Handle h_Fm)
{
    t_Fm        *p_Fm = (t_Fm*)h_Fm;

    SANITY_CHECK_RETURN_VALUE(p_Fm, E_INVALID_HANDLE, 0);

    if (!p_Fm->baseAddr)
    {
        REPORT_ERROR(MAJOR, E_INVALID_STATE,
                     ("No base-addr; probably Guest with IPC!"));
        return 0;
    }

    return (p_Fm->baseAddr + FM_MM_PRS);
}

uintptr_t FmGetPcdKgBaseAddr(t_Handle h_Fm)
{
    t_Fm        *p_Fm = (t_Fm*)h_Fm;

    SANITY_CHECK_RETURN_VALUE(p_Fm, E_INVALID_HANDLE, 0);

    if (!p_Fm->baseAddr)
    {
        REPORT_ERROR(MAJOR, E_INVALID_STATE,
                     ("No base-addr; probably Guest with IPC!"));
        return 0;
    }

    return (p_Fm->baseAddr + FM_MM_KG);
}

uintptr_t FmGetPcdPlcrBaseAddr(t_Handle h_Fm)
{
    t_Fm        *p_Fm = (t_Fm*)h_Fm;

    SANITY_CHECK_RETURN_VALUE(p_Fm, E_INVALID_HANDLE, 0);

    if (!p_Fm->baseAddr)
    {
        REPORT_ERROR(MAJOR, E_INVALID_STATE,
                     ("No base-addr; probably Guest with IPC!"));
        return 0;
    }

    return (p_Fm->baseAddr + FM_MM_PLCR);
}

#if (DPAA_VERSION >= 11)
uintptr_t FmGetVSPBaseAddr(t_Handle h_Fm)
{
    t_Fm        *p_Fm = (t_Fm*)h_Fm;

    SANITY_CHECK_RETURN_VALUE(p_Fm, E_INVALID_HANDLE, 0);

    return p_Fm->vspBaseAddr;
}
#endif /* (DPAA_VERSION >= 11) */

t_Handle FmGetMuramHandle(t_Handle h_Fm)
{
    t_Fm        *p_Fm = (t_Fm*)h_Fm;

    SANITY_CHECK_RETURN_VALUE(p_Fm, E_INVALID_HANDLE, NULL);

    return (p_Fm->h_FmMuram);
}

void FmGetPhysicalMuramBase(t_Handle h_Fm, t_FmPhysAddr *p_FmPhysAddr)
{
    t_Fm            *p_Fm = (t_Fm*)h_Fm;

    if (p_Fm->fmMuramPhysBaseAddr)
    {
        /* General FM driver initialization */
        p_FmPhysAddr->low = (uint32_t)p_Fm->fmMuramPhysBaseAddr;
        p_FmPhysAddr->high = (uint8_t)((p_Fm->fmMuramPhysBaseAddr & 0x000000ff00000000LL) >> 32);
        return;
    }

    ASSERT_COND(p_Fm->guestId != NCSW_MASTER_ID);

    if (p_Fm->h_IpcSessions[0])
    {
        t_Error         err;
        t_FmIpcMsg      msg;
        t_FmIpcReply    reply;
        uint32_t        replyLength;
        t_FmIpcPhysAddr ipcPhysAddr;

        memset(&msg, 0, sizeof(msg));
        memset(&reply, 0, sizeof(reply));
        msg.msgId = FM_GET_PHYS_MURAM_BASE;
        replyLength = sizeof(uint32_t) + sizeof(t_FmPhysAddr);
        err = XX_IpcSendMessage(p_Fm->h_IpcSessions[0],
                                (uint8_t*)&msg,
                                sizeof(msg.msgId),
                                (uint8_t*)&reply,
                                &replyLength,
                                NULL,
                                NULL);
        if (err != E_OK)
        {
            REPORT_ERROR(MINOR, err, NO_MSG);
            return;
        }
        if (replyLength != (sizeof(uint32_t) + sizeof(t_FmPhysAddr)))
        {
            REPORT_ERROR(MINOR, E_INVALID_VALUE,("IPC reply length mismatch"));
            return;
        }
        memcpy((uint8_t*)&ipcPhysAddr, reply.replyBody, sizeof(t_FmIpcPhysAddr));
        p_FmPhysAddr->high = ipcPhysAddr.high;
        p_FmPhysAddr->low  = ipcPhysAddr.low;
    }
    else
        REPORT_ERROR(MINOR, E_NOT_SUPPORTED,
                     ("running in guest-mode without neither IPC nor mapped register!"));
}

#if (DPAA_VERSION >= 11)
t_Error FmVSPAllocForPort (t_Handle        h_Fm,
                           e_FmPortType    portType,
                           uint8_t         portId,
                           uint8_t         numOfVSPs)
{
    t_Fm           *p_Fm = (t_Fm *)h_Fm;
    t_Error        err = E_OK;
    uint32_t       profilesFound, intFlags;
    uint8_t        first, i;
    uint8_t        log2Num;
    uint8_t        swPortIndex=0, hardwarePortId;

    SANITY_CHECK_RETURN_ERROR(p_Fm, E_INVALID_HANDLE);

     if (!numOfVSPs)
        return E_OK;

    if (numOfVSPs > FM_VSP_MAX_NUM_OF_ENTRIES)
        RETURN_ERROR(MINOR, E_INVALID_VALUE, ("numProfiles can not be bigger than %d.",FM_VSP_MAX_NUM_OF_ENTRIES));

    if (!POWER_OF_2(numOfVSPs))
        RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("numProfiles must be a power of 2."));

    LOG2((uint64_t)numOfVSPs, log2Num);

    if ((log2Num == 0) || (p_Fm->partVSPBase == 0))
        first = 0;
    else
        first = 1<<log2Num;

    if (first > (p_Fm->partVSPBase + p_Fm->partNumOfVSPs))
         RETURN_ERROR(MINOR, E_INVALID_VALUE, ("can not allocate storage profile port window"));

    if (first < p_Fm->partVSPBase)
        while (first < p_Fm->partVSPBase)
            first = first + numOfVSPs;

    if ((first + numOfVSPs) > (p_Fm->partVSPBase + p_Fm->partNumOfVSPs))
        RETURN_ERROR(MINOR, E_INVALID_VALUE, ("can not allocate storage profile port window"));

    intFlags = XX_LockIntrSpinlock(p_Fm->h_Spinlock);
    profilesFound = 0;
    for (i=first; i < p_Fm->partVSPBase + p_Fm->partNumOfVSPs; )
    {
        if (!p_Fm->p_FmSp->profiles[i].profilesMng.allocated)
        {
            profilesFound++;
            i++;
            if (profilesFound == numOfVSPs)
                break;
        }
        else
        {
            profilesFound = 0;
            /* advance i to the next aligned address */
            first = i = (uint8_t)(first + numOfVSPs);
        }
    }
    if (profilesFound == numOfVSPs)
        for (i = first; i<first + numOfVSPs; i++)
            p_Fm->p_FmSp->profiles[i].profilesMng.allocated = TRUE;
    else
    {
        XX_UnlockIntrSpinlock(p_Fm->h_Spinlock, intFlags);
        RETURN_ERROR(MINOR, E_FULL, ("No profiles."));
    }

    hardwarePortId = SwPortIdToHwPortId(portType,
                                    portId,
                                    p_Fm->p_FmStateStruct->revInfo.majorRev,
                                    p_Fm->p_FmStateStruct->revInfo.minorRev);
    HW_PORT_ID_TO_SW_PORT_INDX(swPortIndex, hardwarePortId);

    p_Fm->p_FmSp->portsMapping[swPortIndex].numOfProfiles = numOfVSPs;
    p_Fm->p_FmSp->portsMapping[swPortIndex].profilesBase = first;

    if ((err = SetVSPWindow(h_Fm,hardwarePortId, first,log2Num)) != E_OK)
        for (i = first; i < first + numOfVSPs; i++)
            p_Fm->p_FmSp->profiles[i].profilesMng.allocated = FALSE;

    XX_UnlockIntrSpinlock(p_Fm->h_Spinlock, intFlags);

    return err;
}

t_Error FmVSPFreeForPort(t_Handle        h_Fm,
                         e_FmPortType    portType,
                         uint8_t         portId)
{
    t_Fm            *p_Fm = (t_Fm *)h_Fm;
    uint8_t         swPortIndex=0, hardwarePortId, first, numOfVSPs, i;
    uint32_t        intFlags;

    SANITY_CHECK_RETURN_ERROR(p_Fm, E_INVALID_HANDLE);

    hardwarePortId = SwPortIdToHwPortId(portType,
                                    portId,
                                    p_Fm->p_FmStateStruct->revInfo.majorRev,
                                    p_Fm->p_FmStateStruct->revInfo.minorRev);
    HW_PORT_ID_TO_SW_PORT_INDX(swPortIndex, hardwarePortId);

    numOfVSPs = (uint8_t)p_Fm->p_FmSp->portsMapping[swPortIndex].numOfProfiles;
    first = (uint8_t)p_Fm->p_FmSp->portsMapping[swPortIndex].profilesBase;

    intFlags = XX_LockIntrSpinlock(p_Fm->h_Spinlock);
    for (i = first; i < first + numOfVSPs; i++)
           p_Fm->p_FmSp->profiles[i].profilesMng.allocated = FALSE;
    XX_UnlockIntrSpinlock(p_Fm->h_Spinlock, intFlags);

    p_Fm->p_FmSp->portsMapping[swPortIndex].numOfProfiles = 0;
    p_Fm->p_FmSp->portsMapping[swPortIndex].profilesBase = 0;

    return E_OK;
}
#endif /* (DPAA_VERSION >= 11) */

t_Error FmAllocFmanCtrlEventReg(t_Handle h_Fm, uint8_t *p_EventId)
{
    t_Fm            *p_Fm = (t_Fm*)h_Fm;
    uint8_t         i;

    SANITY_CHECK_RETURN_ERROR(p_Fm, E_INVALID_HANDLE);

    if ((p_Fm->guestId != NCSW_MASTER_ID) &&
        p_Fm->h_IpcSessions[0])
    {
        t_Error         err;
        t_FmIpcMsg      msg;
        t_FmIpcReply    reply;
        uint32_t        replyLength;

        memset(&msg, 0, sizeof(msg));
        memset(&reply, 0, sizeof(reply));
        msg.msgId = FM_ALLOC_FMAN_CTRL_EVENT_REG;
        replyLength = sizeof(uint32_t) + sizeof(uint8_t);
        if ((err = XX_IpcSendMessage(p_Fm->h_IpcSessions[0],
                                     (uint8_t*)&msg,
                                     sizeof(msg.msgId),
                                     (uint8_t*)&reply,
                                     &replyLength,
                                     NULL,
                                     NULL)) != E_OK)
            RETURN_ERROR(MAJOR, err, NO_MSG);

        if (replyLength != (sizeof(uint32_t) + sizeof(uint8_t)))
            RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("IPC reply length mismatch"));

        *p_EventId = *(uint8_t*)(reply.replyBody);

        return (t_Error)(reply.error);
    }
    else if (p_Fm->guestId != NCSW_MASTER_ID)
        RETURN_ERROR(MINOR, E_NOT_SUPPORTED,
                     ("running in guest-mode without IPC!"));

    for (i=0;i<FM_NUM_OF_FMAN_CTRL_EVENT_REGS;i++)
        if (!p_Fm->usedEventRegs[i])
        {
            p_Fm->usedEventRegs[i] = TRUE;
            *p_EventId = i;
            break;
        }

    if (i==FM_NUM_OF_FMAN_CTRL_EVENT_REGS)
        RETURN_ERROR(MAJOR, E_BUSY, ("No resource - FMan controller event register."));

    return E_OK;
}

void FmFreeFmanCtrlEventReg(t_Handle h_Fm, uint8_t eventId)
{
    t_Fm        *p_Fm = (t_Fm*)h_Fm;

    SANITY_CHECK_RETURN(p_Fm, E_INVALID_HANDLE);

    if ((p_Fm->guestId != NCSW_MASTER_ID) &&
        p_Fm->h_IpcSessions[0])
    {
        t_Error     err;
        t_FmIpcMsg  msg;

        memset(&msg, 0, sizeof(msg));
        msg.msgId = FM_FREE_FMAN_CTRL_EVENT_REG;
        msg.msgBody[0] = eventId;
        err = XX_IpcSendMessage(p_Fm->h_IpcSessions[0],
                                (uint8_t*)&msg,
                                sizeof(msg.msgId)+sizeof(eventId),
                                NULL,
                                NULL,
                                NULL,
                                NULL);
        if (err != E_OK)
            REPORT_ERROR(MINOR, err, NO_MSG);
        return;
    }
    else if (p_Fm->guestId != NCSW_MASTER_ID)
    {
        REPORT_ERROR(MINOR, E_NOT_SUPPORTED,
                     ("running in guest-mode without IPC!"));
        return;
    }

    ((t_Fm*)h_Fm)->usedEventRegs[eventId] = FALSE;
}

void FmSetFmanCtrlIntr(t_Handle h_Fm, uint8_t eventRegId, uint32_t enableEvents)
{
    t_Fm                *p_Fm = (t_Fm*)h_Fm;
    struct fman_fpm_regs *fpm_rg = p_Fm->p_FmFpmRegs;

    if ((p_Fm->guestId != NCSW_MASTER_ID) &&
        !p_Fm->p_FmFpmRegs &&
        p_Fm->h_IpcSessions[0])
    {
        t_FmIpcFmanEvents   fmanCtrl;
        t_Error             err;
        t_FmIpcMsg          msg;

        fmanCtrl.eventRegId = eventRegId;
        fmanCtrl.enableEvents = enableEvents;
        memset(&msg, 0, sizeof(msg));
        msg.msgId = FM_SET_FMAN_CTRL_EVENTS_ENABLE;
        memcpy(msg.msgBody, &fmanCtrl, sizeof(fmanCtrl));
        err = XX_IpcSendMessage(p_Fm->h_IpcSessions[0],
                                (uint8_t*)&msg,
                                sizeof(msg.msgId)+sizeof(fmanCtrl),
                                NULL,
                                NULL,
                                NULL,
                                NULL);
        if (err != E_OK)
            REPORT_ERROR(MINOR, err, NO_MSG);
        return;
    }
    else if (!p_Fm->p_FmFpmRegs)
    {
        REPORT_ERROR(MINOR, E_NOT_SUPPORTED,
                     ("Either IPC or 'baseAddress' is required!"));
        return;
    }

    ASSERT_COND(eventRegId < FM_NUM_OF_FMAN_CTRL_EVENT_REGS);
    fman_set_ctrl_intr(fpm_rg, eventRegId, enableEvents);
}

uint32_t FmGetFmanCtrlIntr(t_Handle h_Fm, uint8_t eventRegId)
{
    t_Fm            *p_Fm = (t_Fm*)h_Fm;
    struct fman_fpm_regs *fpm_rg = p_Fm->p_FmFpmRegs;

    if ((p_Fm->guestId != NCSW_MASTER_ID) &&
        !p_Fm->p_FmFpmRegs &&
        p_Fm->h_IpcSessions[0])
    {
        t_Error         err;
        t_FmIpcMsg      msg;
        t_FmIpcReply    reply;
        uint32_t        replyLength, ctrlIntr;

        memset(&msg, 0, sizeof(msg));
        memset(&reply, 0, sizeof(reply));
        msg.msgId = FM_GET_FMAN_CTRL_EVENTS_ENABLE;
        msg.msgBody[0] = eventRegId;
        replyLength = sizeof(uint32_t) + sizeof(uint32_t);
        err = XX_IpcSendMessage(p_Fm->h_IpcSessions[0],
                                (uint8_t*)&msg,
                                sizeof(msg.msgId)+sizeof(eventRegId),
                                (uint8_t*)&reply,
                                &replyLength,
                                NULL,
                                NULL);
        if (err != E_OK)
        {
            REPORT_ERROR(MINOR, err, NO_MSG);
            return 0;
        }
        if (replyLength != (sizeof(uint32_t) + sizeof(uint32_t)))
        {
            REPORT_ERROR(MINOR, E_INVALID_VALUE, ("IPC reply length mismatch"));
            return 0;
        }
        memcpy((uint8_t*)&ctrlIntr, reply.replyBody, sizeof(uint32_t));
        return ctrlIntr;
    }
    else if (!p_Fm->p_FmFpmRegs)
    {
        REPORT_ERROR(MINOR, E_NOT_SUPPORTED,
                     ("Either IPC or 'baseAddress' is required!"));
        return 0;
    }

    return fman_get_ctrl_intr(fpm_rg, eventRegId);
}

void FmRegisterIntr(t_Handle                h_Fm,
                    e_FmEventModules        module,
                    uint8_t                 modId,
                    e_FmIntrType            intrType,
                    void                    (*f_Isr) (t_Handle h_Arg),
                    t_Handle                h_Arg)
{
    t_Fm                *p_Fm = (t_Fm*)h_Fm;
    int                 event = 0;

    ASSERT_COND(h_Fm);

    GET_FM_MODULE_EVENT(module, modId, intrType, event);
    ASSERT_COND(event < e_FM_EV_DUMMY_LAST);

    /* register in local FM structure */
    p_Fm->intrMng[event].f_Isr = f_Isr;
    p_Fm->intrMng[event].h_SrcHandle = h_Arg;

    if ((p_Fm->guestId != NCSW_MASTER_ID) &&
        p_Fm->h_IpcSessions[0])
    {
        t_FmIpcRegisterIntr fmIpcRegisterIntr;
        t_Error             err;
        t_FmIpcMsg          msg;

        /* register in Master FM structure */
        fmIpcRegisterIntr.event = (uint32_t)event;
        fmIpcRegisterIntr.guestId = p_Fm->guestId;
        memset(&msg, 0, sizeof(msg));
        msg.msgId = FM_REGISTER_INTR;
        memcpy(msg.msgBody, &fmIpcRegisterIntr, sizeof(fmIpcRegisterIntr));
        err = XX_IpcSendMessage(p_Fm->h_IpcSessions[0],
                                (uint8_t*)&msg,
                                sizeof(msg.msgId) + sizeof(fmIpcRegisterIntr),
                                NULL,
                                NULL,
                                NULL,
                                NULL);
        if (err != E_OK)
            REPORT_ERROR(MINOR, err, NO_MSG);
    }
    else if (p_Fm->guestId != NCSW_MASTER_ID)
        REPORT_ERROR(MINOR, E_NOT_SUPPORTED,
                     ("running in guest-mode without IPC!"));
}

void FmUnregisterIntr(t_Handle                  h_Fm,
                        e_FmEventModules        module,
                        uint8_t                 modId,
                        e_FmIntrType            intrType)
{
    t_Fm        *p_Fm = (t_Fm*)h_Fm;
    int         event = 0;

    ASSERT_COND(h_Fm);

    GET_FM_MODULE_EVENT(module, modId,intrType, event);
    ASSERT_COND(event < e_FM_EV_DUMMY_LAST);

    p_Fm->intrMng[event].f_Isr = UnimplementedIsr;
    p_Fm->intrMng[event].h_SrcHandle = NULL;
}

void  FmRegisterFmanCtrlIntr(t_Handle h_Fm, uint8_t eventRegId, void (*f_Isr) (t_Handle h_Arg, uint32_t event), t_Handle    h_Arg)
{
    t_Fm       *p_Fm = (t_Fm*)h_Fm;

    ASSERT_COND(eventRegId<FM_NUM_OF_FMAN_CTRL_EVENT_REGS);

    if (p_Fm->guestId != NCSW_MASTER_ID)
    {
        REPORT_ERROR(MAJOR, E_NOT_SUPPORTED, ("FM in guest-mode"));
        return;
    }

    p_Fm->fmanCtrlIntr[eventRegId].f_Isr = f_Isr;
    p_Fm->fmanCtrlIntr[eventRegId].h_SrcHandle = h_Arg;
}

void  FmUnregisterFmanCtrlIntr(t_Handle h_Fm, uint8_t eventRegId)
{
    t_Fm       *p_Fm = (t_Fm*)h_Fm;

    ASSERT_COND(eventRegId<FM_NUM_OF_FMAN_CTRL_EVENT_REGS);

    if (p_Fm->guestId != NCSW_MASTER_ID)
    {
        REPORT_ERROR(MAJOR, E_NOT_SUPPORTED, ("FM in guest-mode"));
        return;
    }

    p_Fm->fmanCtrlIntr[eventRegId].f_Isr = UnimplementedFmanCtrlIsr;
    p_Fm->fmanCtrlIntr[eventRegId].h_SrcHandle = NULL;
}

void  FmRegisterPcd(t_Handle h_Fm, t_Handle h_FmPcd)
{
    t_Fm       *p_Fm = (t_Fm*)h_Fm;

    if (p_Fm->h_Pcd)
        REPORT_ERROR(MAJOR, E_ALREADY_EXISTS, ("PCD already set"));

    p_Fm->h_Pcd = h_FmPcd;
}

void  FmUnregisterPcd(t_Handle h_Fm)
{
    t_Fm       *p_Fm = (t_Fm*)h_Fm;

    if (!p_Fm->h_Pcd)
        REPORT_ERROR(MAJOR, E_NOT_FOUND, ("PCD handle!"));

    p_Fm->h_Pcd = NULL;
}

t_Handle FmGetPcdHandle(t_Handle h_Fm)
{
    t_Fm       *p_Fm = (t_Fm*)h_Fm;

    return p_Fm->h_Pcd;
}

uint8_t FmGetId(t_Handle h_Fm)
{
    t_Fm *p_Fm = (t_Fm*)h_Fm;

    SANITY_CHECK_RETURN_VALUE(p_Fm, E_INVALID_HANDLE, 0xff);

    return p_Fm->p_FmStateStruct->fmId;
}

t_Error FmReset(t_Handle h_Fm)
{
	t_Fm *p_Fm = (t_Fm*)h_Fm;

    SANITY_CHECK_RETURN_ERROR(p_Fm, E_INVALID_HANDLE);

    WRITE_UINT32(p_Fm->p_FmFpmRegs->fm_rstc, FPM_RSTC_FM_RESET);
    CORE_MemoryBarrier();
    XX_UDelay(100);

    return E_OK;
}

t_Error FmSetNumOfRiscsPerPort(t_Handle     h_Fm,
                               uint8_t      hardwarePortId,
                               uint8_t      numOfFmanCtrls,
                               t_FmFmanCtrl orFmanCtrl)
{

    t_Fm                        *p_Fm = (t_Fm*)h_Fm;
    struct fman_fpm_regs *fpm_rg;

    SANITY_CHECK_RETURN_ERROR(p_Fm, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(((numOfFmanCtrls > 0) && (numOfFmanCtrls < 3)) , E_INVALID_HANDLE);

    fpm_rg = p_Fm->p_FmFpmRegs;
    if ((p_Fm->guestId != NCSW_MASTER_ID) &&
        !p_Fm->p_FmFpmRegs &&
        p_Fm->h_IpcSessions[0])
    {
        t_Error                     err;
        t_FmIpcPortNumOfFmanCtrls   params;
        t_FmIpcMsg                  msg;

        memset(&msg, 0, sizeof(msg));
        params.hardwarePortId = hardwarePortId;
        params.numOfFmanCtrls = numOfFmanCtrls;
        params.orFmanCtrl = orFmanCtrl;
        msg.msgId = FM_SET_NUM_OF_FMAN_CTRL;
        memcpy(msg.msgBody, &params, sizeof(params));
        err = XX_IpcSendMessage(p_Fm->h_IpcSessions[0],
                                (uint8_t*)&msg,
                                sizeof(msg.msgId) +sizeof(params),
                                NULL,
                                NULL,
                                NULL,
                                NULL);
        if (err != E_OK)
            RETURN_ERROR(MINOR, err, NO_MSG);
        return E_OK;
    }
    else if (!p_Fm->p_FmFpmRegs)
        RETURN_ERROR(MINOR, E_NOT_SUPPORTED,
                     ("Either IPC or 'baseAddress' is required!"));

    fman_set_num_of_riscs_per_port(fpm_rg, hardwarePortId, numOfFmanCtrls, orFmanCtrl);

    return E_OK;
}

t_Error FmGetSetPortParams(t_Handle h_Fm, t_FmInterModulePortInitParams *p_PortParams)
{
    t_Fm                    *p_Fm = (t_Fm*)h_Fm;
    t_Error                 err;
    uint32_t                intFlags;
    uint8_t                 hardwarePortId = p_PortParams->hardwarePortId, macId;
    struct fman_rg          fman_rg;

    fman_rg.bmi_rg = p_Fm->p_FmBmiRegs;
    fman_rg.qmi_rg = p_Fm->p_FmQmiRegs;
    fman_rg.fpm_rg = p_Fm->p_FmFpmRegs;
    fman_rg.dma_rg = p_Fm->p_FmDmaRegs;

    if (p_Fm->guestId != NCSW_MASTER_ID)
    {
        t_FmIpcPortInInitParams     portInParams;
        t_FmIpcPortOutInitParams    portOutParams;
        t_FmIpcMsg                  msg;
        t_FmIpcReply                reply;
        uint32_t                    replyLength;

        portInParams.hardwarePortId     = p_PortParams->hardwarePortId;
        portInParams.enumPortType       = (uint32_t)p_PortParams->portType;
        portInParams.boolIndependentMode= (uint8_t)p_PortParams->independentMode;
        portInParams.liodnOffset        = p_PortParams->liodnOffset;
        portInParams.numOfTasks         = p_PortParams->numOfTasks;
        portInParams.numOfExtraTasks    = p_PortParams->numOfExtraTasks;
        portInParams.numOfOpenDmas      = p_PortParams->numOfOpenDmas;
        portInParams.numOfExtraOpenDmas = p_PortParams->numOfExtraOpenDmas;
        portInParams.sizeOfFifo         = p_PortParams->sizeOfFifo;
        portInParams.extraSizeOfFifo    = p_PortParams->extraSizeOfFifo;
        portInParams.deqPipelineDepth   = p_PortParams->deqPipelineDepth;
        portInParams.maxFrameLength     = p_PortParams->maxFrameLength;
        portInParams.liodnBase          = p_PortParams->liodnBase;

        memset(&msg, 0, sizeof(msg));
        memset(&reply, 0, sizeof(reply));
        msg.msgId = FM_GET_SET_PORT_PARAMS;
        memcpy(msg.msgBody, &portInParams, sizeof(portInParams));
        replyLength = (sizeof(uint32_t) + sizeof(t_FmIpcPortOutInitParams));
        if ((err = XX_IpcSendMessage(p_Fm->h_IpcSessions[0],
                                     (uint8_t*)&msg,
                                     sizeof(msg.msgId) +sizeof(portInParams),
                                     (uint8_t*)&reply,
                                     &replyLength,
                                     NULL,
                                     NULL)) != E_OK)
            RETURN_ERROR(MINOR, err, NO_MSG);
        if (replyLength != (sizeof(uint32_t) + sizeof(t_FmIpcPortOutInitParams)))
            RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("IPC reply length mismatch"));
        memcpy((uint8_t*)&portOutParams, reply.replyBody, sizeof(t_FmIpcPortOutInitParams));

        p_PortParams->fmMuramPhysBaseAddr.high = portOutParams.ipcPhysAddr.high;
        p_PortParams->fmMuramPhysBaseAddr.low  = portOutParams.ipcPhysAddr.low;
        p_PortParams->numOfTasks = portOutParams.numOfTasks;
        p_PortParams->numOfExtraTasks = portOutParams.numOfExtraTasks;
        p_PortParams->numOfOpenDmas = portOutParams.numOfOpenDmas;
        p_PortParams->numOfExtraOpenDmas = portOutParams.numOfExtraOpenDmas;
        p_PortParams->sizeOfFifo = portOutParams.sizeOfFifo;
        p_PortParams->extraSizeOfFifo = portOutParams.extraSizeOfFifo;

        return (t_Error)(reply.error);
    }

    ASSERT_COND(IN_RANGE(1, hardwarePortId, 63));

    intFlags = XX_LockIntrSpinlock(p_Fm->h_Spinlock);
    if (p_PortParams->independentMode)
    {
        /* set port parameters */
        p_Fm->independentMode = p_PortParams->independentMode;
        /* disable dispatch limit */
        fman_qmi_disable_dispatch_limit(fman_rg.fpm_rg);
    }

    if (p_PortParams->portType == e_FM_PORT_TYPE_OH_HOST_COMMAND)
    {
        if (p_Fm->hcPortInitialized)
        {
            XX_UnlockIntrSpinlock(p_Fm->h_Spinlock, intFlags);
            RETURN_ERROR(MAJOR, E_INVALID_STATE, ("Only one host command port is allowed."));
        }
        else
            p_Fm->hcPortInitialized = TRUE;
    }
    p_Fm->p_FmStateStruct->portsTypes[hardwarePortId] = p_PortParams->portType;

    err = FmSetNumOfTasks(p_Fm, hardwarePortId, &p_PortParams->numOfTasks, &p_PortParams->numOfExtraTasks, TRUE);
    if (err)
    {
        XX_UnlockIntrSpinlock(p_Fm->h_Spinlock, intFlags);
        RETURN_ERROR(MAJOR, err, NO_MSG);
    }

#ifdef FM_QMI_NO_DEQ_OPTIONS_SUPPORT
    if (p_Fm->p_FmStateStruct->revInfo.majorRev != 4)
#endif /* FM_QMI_NO_DEQ_OPTIONS_SUPPORT */
    if ((p_PortParams->portType != e_FM_PORT_TYPE_RX) &&
       (p_PortParams->portType != e_FM_PORT_TYPE_RX_10G))
    /* for transmit & O/H ports */
    {
        uint8_t     enqTh;
        uint8_t     deqTh;

        /* update qmi ENQ/DEQ threshold */
        p_Fm->p_FmStateStruct->accumulatedNumOfDeqTnums += p_PortParams->deqPipelineDepth;
        enqTh = fman_get_qmi_enq_th(fman_rg.qmi_rg);
        /* if enqTh is too big, we reduce it to the max value that is still OK */
        if (enqTh >= (QMI_MAX_NUM_OF_TNUMS - p_Fm->p_FmStateStruct->accumulatedNumOfDeqTnums))
        {
            enqTh = (uint8_t)(QMI_MAX_NUM_OF_TNUMS - p_Fm->p_FmStateStruct->accumulatedNumOfDeqTnums - 1);
            fman_set_qmi_enq_th(fman_rg.qmi_rg, enqTh);
        }

        deqTh = fman_get_qmi_deq_th(fman_rg.qmi_rg);
        /* if deqTh is too small, we enlarge it to the min value that is still OK.
         deqTh may not be larger than 63 (QMI_MAX_NUM_OF_TNUMS-1). */
        if ((deqTh <= p_Fm->p_FmStateStruct->accumulatedNumOfDeqTnums)  && (deqTh < QMI_MAX_NUM_OF_TNUMS-1))
        {
            deqTh = (uint8_t)(p_Fm->p_FmStateStruct->accumulatedNumOfDeqTnums + 1);
            fman_set_qmi_deq_th(fman_rg.qmi_rg, deqTh);
        }
    }

#ifdef FM_LOW_END_RESTRICTION
    if ((hardwarePortId==0x1) || (hardwarePortId==0x29))
    {
        if (p_Fm->p_FmStateStruct->lowEndRestriction)
        {
            XX_UnlockIntrSpinlock(p_Fm->h_Spinlock, intFlags);
            RETURN_ERROR(MAJOR, E_NOT_AVAILABLE, ("OP #0 cannot work with Tx Port #1."));
        }
        else
            p_Fm->p_FmStateStruct->lowEndRestriction = TRUE;
    }
#endif /* FM_LOW_END_RESTRICTION */

    err = FmSetSizeOfFifo(p_Fm,
                          hardwarePortId,
                          &p_PortParams->sizeOfFifo,
                          &p_PortParams->extraSizeOfFifo,
                          TRUE);
    if (err)
    {
        XX_UnlockIntrSpinlock(p_Fm->h_Spinlock, intFlags);
        RETURN_ERROR(MAJOR, err, NO_MSG);
    }

    err = FmSetNumOfOpenDmas(p_Fm,
                             hardwarePortId,
                             &p_PortParams->numOfOpenDmas,
                             &p_PortParams->numOfExtraOpenDmas,
                             TRUE);
    if (err)
    {
        XX_UnlockIntrSpinlock(p_Fm->h_Spinlock, intFlags);
        RETURN_ERROR(MAJOR, err, NO_MSG);
    }

    fman_set_liodn_per_port(&fman_rg,
                            hardwarePortId,
                            p_PortParams->liodnBase,
                            p_PortParams->liodnOffset);

    if (p_Fm->p_FmStateStruct->revInfo.majorRev < 6)
        fman_set_order_restoration_per_port(fman_rg.fpm_rg,
                                            hardwarePortId,
                                            p_PortParams->independentMode,
                                            !!((p_PortParams->portType==e_FM_PORT_TYPE_RX) || (p_PortParams->portType==e_FM_PORT_TYPE_RX_10G)));

    HW_PORT_ID_TO_SW_PORT_ID(macId, hardwarePortId);

#if defined(FM_MAX_NUM_OF_10G_MACS) && (FM_MAX_NUM_OF_10G_MACS)
    if ((p_PortParams->portType == e_FM_PORT_TYPE_TX_10G) ||
        (p_PortParams->portType == e_FM_PORT_TYPE_RX_10G))
    {
        ASSERT_COND(macId < FM_MAX_NUM_OF_10G_MACS);
        if (p_PortParams->maxFrameLength >= p_Fm->p_FmStateStruct->macMaxFrameLengths10G[macId])
            p_Fm->p_FmStateStruct->portMaxFrameLengths10G[macId] = p_PortParams->maxFrameLength;
        else
            RETURN_ERROR(MINOR, E_INVALID_VALUE, ("Port maxFrameLength is smaller than MAC current MTU"));
    }
    else
#endif /* defined(FM_MAX_NUM_OF_10G_MACS) && ... */
    if ((p_PortParams->portType == e_FM_PORT_TYPE_TX) ||
        (p_PortParams->portType == e_FM_PORT_TYPE_RX))
    {
        ASSERT_COND(macId < FM_MAX_NUM_OF_1G_MACS);
        if (p_PortParams->maxFrameLength >= p_Fm->p_FmStateStruct->macMaxFrameLengths1G[macId])
            p_Fm->p_FmStateStruct->portMaxFrameLengths1G[macId] = p_PortParams->maxFrameLength;
        else
            RETURN_ERROR(MINOR, E_INVALID_VALUE, ("Port maxFrameLength is smaller than MAC current MTU"));
    }

    FmGetPhysicalMuramBase(p_Fm, &p_PortParams->fmMuramPhysBaseAddr);
    XX_UnlockIntrSpinlock(p_Fm->h_Spinlock, intFlags);

    return E_OK;
}

void FmFreePortParams(t_Handle h_Fm,t_FmInterModulePortFreeParams *p_PortParams)
{
    t_Fm                    *p_Fm = (t_Fm*)h_Fm;
    uint32_t                intFlags;
    uint8_t                 hardwarePortId = p_PortParams->hardwarePortId;
    uint8_t                 numOfTasks, numOfDmas, macId;
    uint16_t                sizeOfFifo;
    t_Error                 err;
    t_FmIpcPortFreeParams   portParams;
    t_FmIpcMsg              msg;
    struct fman_qmi_regs *qmi_rg = p_Fm->p_FmQmiRegs;
    struct fman_bmi_regs *bmi_rg = p_Fm->p_FmBmiRegs;

    if (p_Fm->guestId != NCSW_MASTER_ID)
    {
        portParams.hardwarePortId = p_PortParams->hardwarePortId;
        portParams.enumPortType = (uint32_t)p_PortParams->portType;
        portParams.deqPipelineDepth = p_PortParams->deqPipelineDepth;
        memset(&msg, 0, sizeof(msg));
        msg.msgId = FM_FREE_PORT;
        memcpy(msg.msgBody, &portParams, sizeof(portParams));
        err = XX_IpcSendMessage(p_Fm->h_IpcSessions[0],
                                (uint8_t*)&msg,
                                sizeof(msg.msgId)+sizeof(portParams),
                                NULL,
                                NULL,
                                NULL,
                                NULL);
        if (err != E_OK)
            REPORT_ERROR(MINOR, err, NO_MSG);
        return;
    }

    ASSERT_COND(IN_RANGE(1, hardwarePortId, 63));

    intFlags = XX_LockIntrSpinlock(p_Fm->h_Spinlock);

    if (p_PortParams->portType == e_FM_PORT_TYPE_OH_HOST_COMMAND)
    {
        ASSERT_COND(p_Fm->hcPortInitialized);
        p_Fm->hcPortInitialized = FALSE;
    }

    p_Fm->p_FmStateStruct->portsTypes[hardwarePortId] = e_FM_PORT_TYPE_DUMMY;

    /* free numOfTasks */
    numOfTasks = fman_get_num_of_tasks(bmi_rg, hardwarePortId);
    ASSERT_COND(p_Fm->p_FmStateStruct->accumulatedNumOfTasks >= numOfTasks);
    p_Fm->p_FmStateStruct->accumulatedNumOfTasks -= numOfTasks;

    /* free numOfOpenDmas */
    numOfDmas = fman_get_num_of_dmas(bmi_rg, hardwarePortId);
    ASSERT_COND(p_Fm->p_FmStateStruct->accumulatedNumOfOpenDmas >= numOfDmas);
    p_Fm->p_FmStateStruct->accumulatedNumOfOpenDmas -= numOfDmas;

#ifdef FM_HAS_TOTAL_DMAS
    if (p_Fm->p_FmStateStruct->revInfo.majorRev < 6)
    {
        /* update total num of DMA's with committed number of open DMAS, and max uncommitted pool. */
        fman_set_num_of_open_dmas(bmi_rg,
                                  hardwarePortId,
                                  1,
                                  0,
                         (uint8_t)(p_Fm->p_FmStateStruct->accumulatedNumOfOpenDmas + p_Fm->p_FmStateStruct->extraOpenDmasPoolSize));
    }
#endif /* FM_HAS_TOTAL_DMAS */

    /* free sizeOfFifo */
    sizeOfFifo = fman_get_size_of_fifo(bmi_rg, hardwarePortId);
    ASSERT_COND(p_Fm->p_FmStateStruct->accumulatedFifoSize >= (sizeOfFifo * BMI_FIFO_UNITS));
    p_Fm->p_FmStateStruct->accumulatedFifoSize -= (sizeOfFifo * BMI_FIFO_UNITS);

#ifdef FM_QMI_NO_DEQ_OPTIONS_SUPPORT
    if (p_Fm->p_FmStateStruct->revInfo.majorRev != 4)
#endif /* FM_QMI_NO_DEQ_OPTIONS_SUPPORT */
    if ((p_PortParams->portType != e_FM_PORT_TYPE_RX) &&
        (p_PortParams->portType != e_FM_PORT_TYPE_RX_10G))
    /* for transmit & O/H ports */
    {
        uint8_t     enqTh;
        uint8_t     deqTh;

        /* update qmi ENQ/DEQ threshold */
        p_Fm->p_FmStateStruct->accumulatedNumOfDeqTnums -= p_PortParams->deqPipelineDepth;

        /* p_Fm->p_FmStateStruct->accumulatedNumOfDeqTnums is now smaller,
           so we can enlarge enqTh */
        enqTh = (uint8_t)(QMI_MAX_NUM_OF_TNUMS - p_Fm->p_FmStateStruct->accumulatedNumOfDeqTnums - 1);

         /* p_Fm->p_FmStateStruct->accumulatedNumOfDeqTnums is now smaller,
            so we can reduce deqTh */
        deqTh = (uint8_t)(p_Fm->p_FmStateStruct->accumulatedNumOfDeqTnums + 1);

        fman_set_qmi_enq_th(qmi_rg, enqTh);
        fman_set_qmi_deq_th(qmi_rg, deqTh);
    }

    HW_PORT_ID_TO_SW_PORT_ID(macId, hardwarePortId);

#if defined(FM_MAX_NUM_OF_10G_MACS) && (FM_MAX_NUM_OF_10G_MACS)
    if ((p_PortParams->portType == e_FM_PORT_TYPE_TX_10G) ||
        (p_PortParams->portType == e_FM_PORT_TYPE_RX_10G))
    {
        ASSERT_COND(macId < FM_MAX_NUM_OF_10G_MACS);
        p_Fm->p_FmStateStruct->portMaxFrameLengths10G[macId] = 0;
    }
    else
#endif /* defined(FM_MAX_NUM_OF_10G_MACS) && ... */
    if ((p_PortParams->portType == e_FM_PORT_TYPE_TX) ||
        (p_PortParams->portType == e_FM_PORT_TYPE_RX))
    {
        ASSERT_COND(macId < FM_MAX_NUM_OF_1G_MACS);
        p_Fm->p_FmStateStruct->portMaxFrameLengths1G[macId] = 0;
    }

#ifdef FM_LOW_END_RESTRICTION
    if ((hardwarePortId==0x1) || (hardwarePortId==0x29))
        p_Fm->p_FmStateStruct->lowEndRestriction = FALSE;
#endif /* FM_LOW_END_RESTRICTION */
    XX_UnlockIntrSpinlock(p_Fm->h_Spinlock, intFlags);
}

t_Error FmIsPortStalled(t_Handle h_Fm, uint8_t hardwarePortId, bool *p_IsStalled)
{
    t_Fm            *p_Fm = (t_Fm*)h_Fm;
    t_Error         err;
    t_FmIpcMsg      msg;
    t_FmIpcReply    reply;
    uint32_t        replyLength;
    struct fman_fpm_regs *fpm_rg = p_Fm->p_FmFpmRegs;

    if ((p_Fm->guestId != NCSW_MASTER_ID) &&
        !p_Fm->baseAddr &&
        p_Fm->h_IpcSessions[0])
    {
        memset(&msg, 0, sizeof(msg));
        memset(&reply, 0, sizeof(reply));
        msg.msgId = FM_IS_PORT_STALLED;
        msg.msgBody[0] = hardwarePortId;
        replyLength = sizeof(uint32_t) + sizeof(uint8_t);
        err = XX_IpcSendMessage(p_Fm->h_IpcSessions[0],
                                (uint8_t*)&msg,
                                sizeof(msg.msgId)+sizeof(hardwarePortId),
                                (uint8_t*)&reply,
                                &replyLength,
                                NULL,
                                NULL);
        if (err != E_OK)
            RETURN_ERROR(MINOR, err, NO_MSG);
        if (replyLength != (sizeof(uint32_t) + sizeof(uint8_t)))
            RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("IPC reply length mismatch"));

        *p_IsStalled = (bool)!!(*(uint8_t*)(reply.replyBody));

        return (t_Error)(reply.error);
    }
    else if (!p_Fm->baseAddr)
        RETURN_ERROR(MINOR, E_NOT_SUPPORTED,
                     ("Either IPC or 'baseAddress' is required!"));

    *p_IsStalled = fman_is_port_stalled(fpm_rg, hardwarePortId);

    return E_OK;
}

t_Error FmResumeStalledPort(t_Handle h_Fm, uint8_t hardwarePortId)
{
    t_Fm            *p_Fm = (t_Fm*)h_Fm;
    t_Error         err;
    bool            isStalled;
    struct fman_fpm_regs *fpm_rg = p_Fm->p_FmFpmRegs;

    if ((p_Fm->guestId != NCSW_MASTER_ID) &&
        !p_Fm->baseAddr &&
        p_Fm->h_IpcSessions[0])
    {
        t_FmIpcMsg      msg;
        t_FmIpcReply    reply;
        uint32_t        replyLength;

        memset(&msg, 0, sizeof(msg));
        memset(&reply, 0, sizeof(reply));
        msg.msgId = FM_RESUME_STALLED_PORT;
        msg.msgBody[0] = hardwarePortId;
        replyLength = sizeof(uint32_t);
        err = XX_IpcSendMessage(p_Fm->h_IpcSessions[0],
                                (uint8_t*)&msg,
                                sizeof(msg.msgId) + sizeof(hardwarePortId),
                                (uint8_t*)&reply,
                                &replyLength,
                                NULL,
                                NULL);
        if (err != E_OK)
            RETURN_ERROR(MINOR, err, NO_MSG);
        if (replyLength != sizeof(uint32_t))
            RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("IPC reply length mismatch"));
        return (t_Error)(reply.error);
    }
    else if (!p_Fm->baseAddr)
        RETURN_ERROR(MINOR, E_NOT_SUPPORTED,
                     ("Either IPC or 'baseAddress' is required!"));

    if (p_Fm->p_FmStateStruct->revInfo.majorRev >= 6)
        RETURN_ERROR(MINOR, E_NOT_AVAILABLE, ("Not available for this FM revision!"));

    /* Get port status */
    err = FmIsPortStalled(h_Fm, hardwarePortId, &isStalled);
    if (err)
        RETURN_ERROR(MAJOR, E_INVALID_STATE, ("Can't get port status"));
    if (!isStalled)
        return E_OK;

    fman_resume_stalled_port(fpm_rg, hardwarePortId);

    return E_OK;
}

t_Error FmResetMac(t_Handle h_Fm, e_FmMacType type, uint8_t macId)
{
    t_Fm                *p_Fm = (t_Fm*)h_Fm;
    t_Error             err;
    struct fman_fpm_regs *fpm_rg = p_Fm->p_FmFpmRegs;

#if (DPAA_VERSION >= 11)
    if (p_Fm->p_FmStateStruct->revInfo.majorRev >= 6)
        RETURN_ERROR(MINOR, E_NOT_SUPPORTED,
                     ("FMan MAC reset!"));
#endif /*(DPAA_VERSION >= 11)*/

    if ((p_Fm->guestId != NCSW_MASTER_ID) &&
        !p_Fm->baseAddr &&
        p_Fm->h_IpcSessions[0])
    {
        t_FmIpcMacParams    macParams;
        t_FmIpcMsg          msg;
        t_FmIpcReply        reply;
        uint32_t            replyLength;

        memset(&msg, 0, sizeof(msg));
        memset(&reply, 0, sizeof(reply));
        macParams.id = macId;
        macParams.enumType = (uint32_t)type;
        msg.msgId = FM_RESET_MAC;
        memcpy(msg.msgBody,  &macParams, sizeof(macParams));
        replyLength = sizeof(uint32_t);
        err = XX_IpcSendMessage(p_Fm->h_IpcSessions[0],
                                (uint8_t*)&msg,
                                sizeof(msg.msgId)+sizeof(macParams),
                                (uint8_t*)&reply,
                                &replyLength,
                                NULL,
                                NULL);
        if (err != E_OK)
            RETURN_ERROR(MINOR, err, NO_MSG);
        if (replyLength != sizeof(uint32_t))
            RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("IPC reply length mismatch"));
        return (t_Error)(reply.error);
    }
    else if (!p_Fm->baseAddr)
        RETURN_ERROR(MINOR, E_NOT_SUPPORTED,
                     ("Either IPC or 'baseAddress' is required!"));

    err = (t_Error)fman_reset_mac(fpm_rg, macId, !!(type == e_FM_MAC_10G));

    if (err == -EBUSY)
        return ERROR_CODE(E_TIMEOUT);
    else if (err)
        RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("Illegal MAC ID"));

    return E_OK;
}

t_Error FmSetMacMaxFrame(t_Handle h_Fm, e_FmMacType type, uint8_t macId, uint16_t mtu)
{
    t_Fm                        *p_Fm = (t_Fm*)h_Fm;

    if ((p_Fm->guestId != NCSW_MASTER_ID) &&
        p_Fm->h_IpcSessions[0])
    {
        t_FmIpcMacMaxFrameParams    macMaxFrameLengthParams;
        t_Error                     err;
        t_FmIpcMsg                  msg;

        memset(&msg, 0, sizeof(msg));
        macMaxFrameLengthParams.macParams.id = macId;
        macMaxFrameLengthParams.macParams.enumType = (uint32_t)type;
        macMaxFrameLengthParams.maxFrameLength = (uint16_t)mtu;
        msg.msgId = FM_SET_MAC_MAX_FRAME;
        memcpy(msg.msgBody,  &macMaxFrameLengthParams, sizeof(macMaxFrameLengthParams));
        err = XX_IpcSendMessage(p_Fm->h_IpcSessions[0],
                                (uint8_t*)&msg,
                                sizeof(msg.msgId)+sizeof(macMaxFrameLengthParams),
                                NULL,
                                NULL,
                                NULL,
                                NULL);
        if (err != E_OK)
            RETURN_ERROR(MINOR, err, NO_MSG);
        return E_OK;
    }
    else if (p_Fm->guestId != NCSW_MASTER_ID)
        RETURN_ERROR(MINOR, E_NOT_SUPPORTED,
                     ("running in guest-mode without IPC!"));

    /* if port is already initialized, check that MaxFrameLength is smaller
     * or equal to the port's max */
#if (defined(FM_MAX_NUM_OF_10G_MACS) && (FM_MAX_NUM_OF_10G_MACS))
    if (type == e_FM_MAC_10G)
    {
        if ((!p_Fm->p_FmStateStruct->portMaxFrameLengths10G[macId])
           || (p_Fm->p_FmStateStruct->portMaxFrameLengths10G[macId] &&
              (mtu <= p_Fm->p_FmStateStruct->portMaxFrameLengths10G[macId])))
               p_Fm->p_FmStateStruct->macMaxFrameLengths10G[macId] = mtu;
        else
            RETURN_ERROR(MINOR, E_INVALID_VALUE, ("MAC maxFrameLength is larger than Port maxFrameLength"));

    }
    else
#else
    UNUSED(type);
#endif /* (defined(FM_MAX_NUM_OF_10G_MACS) && ... */
    if ((!p_Fm->p_FmStateStruct->portMaxFrameLengths1G[macId])
       || (p_Fm->p_FmStateStruct->portMaxFrameLengths1G[macId] &&
          (mtu <= p_Fm->p_FmStateStruct->portMaxFrameLengths1G[macId])))
        p_Fm->p_FmStateStruct->macMaxFrameLengths1G[macId] = mtu;
    else
        RETURN_ERROR(MINOR, E_INVALID_VALUE, ("MAC maxFrameLength is larger than Port maxFrameLength"));

    return E_OK;
}

uint16_t FmGetClockFreq(t_Handle h_Fm)
{
    t_Fm *p_Fm = (t_Fm*)h_Fm;

    /* for multicore environment: this depends on the
     * fact that fmClkFreq was properly initialized at "init". */
    return p_Fm->p_FmStateStruct->fmClkFreq;
}

uint16_t FmGetMacClockFreq(t_Handle h_Fm)
{
    t_Fm *p_Fm = (t_Fm*)h_Fm;

    return p_Fm->p_FmStateStruct->fmMacClkFreq;
}

uint32_t FmGetTimeStampScale(t_Handle h_Fm)
{
    t_Fm                *p_Fm = (t_Fm*)h_Fm;

    if ((p_Fm->guestId != NCSW_MASTER_ID) &&
        !p_Fm->baseAddr &&
        p_Fm->h_IpcSessions[0])
    {
        t_Error             err;
        t_FmIpcMsg          msg;
        t_FmIpcReply        reply;
        uint32_t            replyLength, timeStamp;

        memset(&msg, 0, sizeof(msg));
        memset(&reply, 0, sizeof(reply));
        msg.msgId = FM_GET_TIMESTAMP_SCALE;
        replyLength = sizeof(uint32_t) + sizeof(uint32_t);
        if ((err = XX_IpcSendMessage(p_Fm->h_IpcSessions[0],
                                     (uint8_t*)&msg,
                                     sizeof(msg.msgId),
                                     (uint8_t*)&reply,
                                     &replyLength,
                                     NULL,
                                     NULL)) != E_OK)
        {
            REPORT_ERROR(MAJOR, err, NO_MSG);
            return 0;
        }
        if (replyLength != (sizeof(uint32_t) + sizeof(uint32_t)))
        {
            REPORT_ERROR(MAJOR, E_INVALID_VALUE, ("IPC reply length mismatch"));
            return 0;
        }

        memcpy((uint8_t*)&timeStamp, reply.replyBody, sizeof(uint32_t));
        return timeStamp;
    }
    else if ((p_Fm->guestId != NCSW_MASTER_ID) &&
             p_Fm->baseAddr)
    {
        if (!(GET_UINT32(p_Fm->p_FmFpmRegs->fmfp_tsc1) & FPM_TS_CTL_EN))
        {
            REPORT_ERROR(MAJOR, E_INVALID_STATE, ("timestamp is not enabled!"));
            return 0;
        }
    }
    else if (p_Fm->guestId != NCSW_MASTER_ID)
        DBG(WARNING, ("No IPC - can't validate FM if timestamp enabled."));

    return p_Fm->p_FmStateStruct->count1MicroBit;
}

t_Error FmEnableRamsEcc(t_Handle h_Fm)
{
    t_Fm        *p_Fm = (t_Fm*)h_Fm;

    SANITY_CHECK_RETURN_ERROR(p_Fm, E_INVALID_HANDLE);

    p_Fm->p_FmStateStruct->ramsEccOwners++;
    p_Fm->p_FmStateStruct->internalCall = TRUE;

    return FM_EnableRamsEcc(p_Fm);
}

t_Error FmDisableRamsEcc(t_Handle h_Fm)
{
    t_Fm        *p_Fm = (t_Fm*)h_Fm;

    SANITY_CHECK_RETURN_ERROR(p_Fm, E_INVALID_HANDLE);

    ASSERT_COND(p_Fm->p_FmStateStruct->ramsEccOwners);
    p_Fm->p_FmStateStruct->ramsEccOwners--;

    if (p_Fm->p_FmStateStruct->ramsEccOwners==0)
    {
        p_Fm->p_FmStateStruct->internalCall = TRUE;
        return FM_DisableRamsEcc(p_Fm);
    }

    return E_OK;
}

uint8_t FmGetGuestId(t_Handle h_Fm)
{
    t_Fm     *p_Fm = (t_Fm*)h_Fm;

    return p_Fm->guestId;
}

bool FmIsMaster(t_Handle h_Fm)
{
    t_Fm     *p_Fm = (t_Fm*)h_Fm;

    return (p_Fm->guestId == NCSW_MASTER_ID);
}

t_Error FmSetSizeOfFifo(t_Handle    h_Fm,
                        uint8_t     hardwarePortId,
                        uint32_t    *p_SizeOfFifo,
                        uint32_t    *p_ExtraSizeOfFifo,
                        bool        initialConfig)
{
    t_Fm                    *p_Fm = (t_Fm*)h_Fm;
    t_FmIpcPortRsrcParams   rsrcParams;
    t_Error                 err;
    struct fman_bmi_regs    *bmi_rg = p_Fm->p_FmBmiRegs;
    uint32_t                sizeOfFifo = *p_SizeOfFifo, extraSizeOfFifo = *p_ExtraSizeOfFifo;
    uint16_t                currentVal = 0, currentExtraVal = 0;

    if ((p_Fm->guestId != NCSW_MASTER_ID) &&
        !p_Fm->baseAddr &&
        p_Fm->h_IpcSessions[0])
    {
        t_FmIpcMsg          msg;
        t_FmIpcReply        reply;
        uint32_t            replyLength;

        rsrcParams.hardwarePortId = hardwarePortId;
        rsrcParams.val = sizeOfFifo;
        rsrcParams.extra = extraSizeOfFifo;
        rsrcParams.boolInitialConfig = (uint8_t)initialConfig;

        memset(&msg, 0, sizeof(msg));
        memset(&reply, 0, sizeof(reply));
        msg.msgId = FM_SET_SIZE_OF_FIFO;
        memcpy(msg.msgBody, &rsrcParams, sizeof(rsrcParams));
        replyLength = sizeof(uint32_t);
        if ((err = XX_IpcSendMessage(p_Fm->h_IpcSessions[0],
                                     (uint8_t*)&msg,
                                     sizeof(msg.msgId) + sizeof(rsrcParams),
                                     (uint8_t*)&reply,
                                     &replyLength,
                                     NULL,
                                     NULL)) != E_OK)
            RETURN_ERROR(MINOR, err, NO_MSG);
        if (replyLength != sizeof(uint32_t))
            RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("IPC reply length mismatch"));
        return (t_Error)(reply.error);
    }
    else if ((p_Fm->guestId != NCSW_MASTER_ID) &&
             p_Fm->baseAddr)
    {
        DBG(WARNING, ("No IPC - can't validate FM total-fifo size."));
        fman_set_size_of_fifo(bmi_rg, hardwarePortId, sizeOfFifo, extraSizeOfFifo);
    }
    else if (p_Fm->guestId != NCSW_MASTER_ID)
        RETURN_ERROR(MAJOR, E_NOT_SUPPORTED,
                     ("running in guest-mode without neither IPC nor mapped register!"));

    if (!initialConfig)
    {
        /* !initialConfig - runtime change of existing value.
         * - read the current FIFO and extra FIFO size */
        currentExtraVal = fman_get_size_of_extra_fifo(bmi_rg, hardwarePortId);
        currentVal = fman_get_size_of_fifo(bmi_rg, hardwarePortId);
    }

    if (extraSizeOfFifo > currentExtraVal)
    {
        if (extraSizeOfFifo && !p_Fm->p_FmStateStruct->extraFifoPoolSize)
            /* if this is the first time a port requires extraFifoPoolSize, the total extraFifoPoolSize
             * must be initialized to 1 buffer per port
             */
            p_Fm->p_FmStateStruct->extraFifoPoolSize = FM_MAX_NUM_OF_RX_PORTS*BMI_FIFO_UNITS;

        p_Fm->p_FmStateStruct->extraFifoPoolSize = MAX(p_Fm->p_FmStateStruct->extraFifoPoolSize, extraSizeOfFifo);
    }

    /* check that there are enough uncommitted fifo size */
    if ((p_Fm->p_FmStateStruct->accumulatedFifoSize - currentVal + sizeOfFifo) >
        (p_Fm->p_FmStateStruct->totalFifoSize - p_Fm->p_FmStateStruct->extraFifoPoolSize)){
        REPORT_ERROR(MAJOR, E_INVALID_VALUE,
            ("Port request fifo size + accumulated size > total FIFO size:"));
        RETURN_ERROR(MAJOR, E_INVALID_VALUE,
            ("port 0x%x requested %d bytes, extra size = %d, accumulated size = %d total size = %d",
                hardwarePortId, sizeOfFifo, p_Fm->p_FmStateStruct->extraFifoPoolSize,
                p_Fm->p_FmStateStruct->accumulatedFifoSize,
                p_Fm->p_FmStateStruct->totalFifoSize));
    }
    else
    {
        /* update accumulated */
        ASSERT_COND(p_Fm->p_FmStateStruct->accumulatedFifoSize >= currentVal);
        p_Fm->p_FmStateStruct->accumulatedFifoSize -= currentVal;
        p_Fm->p_FmStateStruct->accumulatedFifoSize += sizeOfFifo;
        fman_set_size_of_fifo(bmi_rg, hardwarePortId, sizeOfFifo, extraSizeOfFifo);
    }

    return E_OK;
}

t_Error FmSetNumOfTasks(t_Handle    h_Fm,
                        uint8_t     hardwarePortId,
                        uint8_t     *p_NumOfTasks,
                        uint8_t     *p_NumOfExtraTasks,
                        bool        initialConfig)
{
    t_Fm                    *p_Fm = (t_Fm *)h_Fm;
    t_Error                 err;
    struct fman_bmi_regs    *bmi_rg = p_Fm->p_FmBmiRegs;
    uint8_t                 currentVal = 0, currentExtraVal = 0, numOfTasks = *p_NumOfTasks, numOfExtraTasks = *p_NumOfExtraTasks;

    ASSERT_COND(IN_RANGE(1, hardwarePortId, 63));

    if ((p_Fm->guestId != NCSW_MASTER_ID) &&
        !p_Fm->baseAddr &&
        p_Fm->h_IpcSessions[0])
    {
        t_FmIpcPortRsrcParams   rsrcParams;
        t_FmIpcMsg              msg;
        t_FmIpcReply            reply;
        uint32_t                replyLength;

        rsrcParams.hardwarePortId = hardwarePortId;
        rsrcParams.val = numOfTasks;
        rsrcParams.extra = numOfExtraTasks;
        rsrcParams.boolInitialConfig = (uint8_t)initialConfig;

        memset(&msg, 0, sizeof(msg));
        memset(&reply, 0, sizeof(reply));
        msg.msgId = FM_SET_NUM_OF_TASKS;
        memcpy(msg.msgBody, &rsrcParams, sizeof(rsrcParams));
        replyLength = sizeof(uint32_t);
        if ((err = XX_IpcSendMessage(p_Fm->h_IpcSessions[0],
                                     (uint8_t*)&msg,
                                     sizeof(msg.msgId) + sizeof(rsrcParams),
                                     (uint8_t*)&reply,
                                     &replyLength,
                                     NULL,
                                     NULL)) != E_OK)
            RETURN_ERROR(MINOR, err, NO_MSG);
        if (replyLength != sizeof(uint32_t))
            RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("IPC reply length mismatch"));
        return (t_Error)(reply.error);
    }
    else if ((p_Fm->guestId != NCSW_MASTER_ID) &&
             p_Fm->baseAddr)
    {
        DBG(WARNING, ("No IPC - can't validate FM total-num-of-tasks."));
        fman_set_num_of_tasks(bmi_rg, hardwarePortId, numOfTasks, numOfExtraTasks);
    }
    else if (p_Fm->guestId != NCSW_MASTER_ID)
        RETURN_ERROR(MAJOR, E_NOT_SUPPORTED,
                     ("running in guest-mode without neither IPC nor mapped register!"));

    if (!initialConfig)
    {
        /* !initialConfig - runtime change of existing value.
         * - read the current number of tasks */
        currentVal = fman_get_num_of_tasks(bmi_rg, hardwarePortId);
        currentExtraVal = fman_get_num_extra_tasks(bmi_rg, hardwarePortId);
    }

    if (numOfExtraTasks > currentExtraVal)
         p_Fm->p_FmStateStruct->extraTasksPoolSize =
             (uint8_t)MAX(p_Fm->p_FmStateStruct->extraTasksPoolSize, numOfExtraTasks);

    /* check that there are enough uncommitted tasks */
    if ((p_Fm->p_FmStateStruct->accumulatedNumOfTasks - currentVal + numOfTasks) >
       (p_Fm->p_FmStateStruct->totalNumOfTasks - p_Fm->p_FmStateStruct->extraTasksPoolSize))
        RETURN_ERROR(MAJOR, E_NOT_AVAILABLE,
                     ("Requested numOfTasks and extra tasks pool for fm%d exceed total numOfTasks.",
                      p_Fm->p_FmStateStruct->fmId));
    else
    {
        ASSERT_COND(p_Fm->p_FmStateStruct->accumulatedNumOfTasks >= currentVal);
        /* update accumulated */
        p_Fm->p_FmStateStruct->accumulatedNumOfTasks -= currentVal;
        p_Fm->p_FmStateStruct->accumulatedNumOfTasks += numOfTasks;
        fman_set_num_of_tasks(bmi_rg, hardwarePortId, numOfTasks, numOfExtraTasks);
    }

    return E_OK;
}

t_Error FmSetNumOfOpenDmas(t_Handle h_Fm,
                           uint8_t hardwarePortId,
                           uint8_t *p_NumOfOpenDmas,
                           uint8_t *p_NumOfExtraOpenDmas,
                           bool    initialConfig)

{
    t_Fm                    *p_Fm = (t_Fm *)h_Fm;
    t_Error                 err;
    struct fman_bmi_regs    *bmi_rg = p_Fm->p_FmBmiRegs;
    uint8_t                 numOfOpenDmas = *p_NumOfOpenDmas, numOfExtraOpenDmas = *p_NumOfExtraOpenDmas;
    uint8_t                 totalNumDmas = 0, currentVal = 0, currentExtraVal = 0;

    ASSERT_COND(IN_RANGE(1, hardwarePortId, 63));

    if ((p_Fm->guestId != NCSW_MASTER_ID) &&
        !p_Fm->baseAddr &&
        p_Fm->h_IpcSessions[0])
    {
        t_FmIpcPortRsrcParams   rsrcParams;
        t_FmIpcMsg              msg;
        t_FmIpcReply            reply;
        uint32_t                replyLength;

        rsrcParams.hardwarePortId = hardwarePortId;
        rsrcParams.val = numOfOpenDmas;
        rsrcParams.extra = numOfExtraOpenDmas;
        rsrcParams.boolInitialConfig = (uint8_t)initialConfig;

        memset(&msg, 0, sizeof(msg));
        memset(&reply, 0, sizeof(reply));
        msg.msgId = FM_SET_NUM_OF_OPEN_DMAS;
        memcpy(msg.msgBody, &rsrcParams, sizeof(rsrcParams));
        replyLength = sizeof(uint32_t);
        if ((err = XX_IpcSendMessage(p_Fm->h_IpcSessions[0],
                                     (uint8_t*)&msg,
                                     sizeof(msg.msgId) + sizeof(rsrcParams),
                                     (uint8_t*)&reply,
                                     &replyLength,
                                     NULL,
                                     NULL)) != E_OK)
            RETURN_ERROR(MINOR, err, NO_MSG);
        if (replyLength != sizeof(uint32_t))
            RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("IPC reply length mismatch"));
        return (t_Error)(reply.error);
    }
#ifdef FM_HAS_TOTAL_DMAS
    else if (p_Fm->guestId != NCSW_MASTER_ID)
        RETURN_ERROR(MAJOR, E_NOT_SUPPORTED, ("running in guest-mode without IPC!"));
#else
    else if ((p_Fm->guestId != NCSW_MASTER_ID) &&
             p_Fm->baseAddr &&
             (p_Fm->p_FmStateStruct->revInfo.majorRev >= 6))
    {
        /*DBG(WARNING, ("No IPC - can't validate FM total-num-of-dmas."));*/

        if (!numOfOpenDmas)
        {
             /* first config without explic it value: Do Nothing - reset value shouldn't be
                changed, read register for port save */
                *p_NumOfOpenDmas = fman_get_num_of_dmas(bmi_rg, hardwarePortId);
                *p_NumOfExtraOpenDmas = fman_get_num_extra_dmas(bmi_rg, hardwarePortId);
        }
        else
            /* whether it is the first time with explicit value, or runtime "set" - write register */
            fman_set_num_of_open_dmas(bmi_rg,
                                   hardwarePortId,
                                   numOfOpenDmas,
                                   numOfExtraOpenDmas,
                                   p_Fm->p_FmStateStruct->accumulatedNumOfOpenDmas + p_Fm->p_FmStateStruct->extraOpenDmasPoolSize);
    }
    else if (p_Fm->guestId != NCSW_MASTER_ID)
        RETURN_ERROR(MAJOR, E_NOT_SUPPORTED,
                     ("running in guest-mode without neither IPC nor mapped register!"));
#endif /* FM_HAS_TOTAL_DMAS */

    if (!initialConfig)
    {
        /* !initialConfig - runtime change of existing value.
         * - read the current number of open Dma's */
        currentExtraVal = fman_get_num_extra_dmas(bmi_rg, hardwarePortId);
        currentVal = fman_get_num_of_dmas(bmi_rg, hardwarePortId);
    }

#ifdef FM_NO_GUARANTEED_RESET_VALUES
    /* it's illegal to be in a state where this is not the first set and no value is specified */
    ASSERT_COND(initialConfig || numOfOpenDmas);
    if (!numOfOpenDmas)
    {
        /* !numOfOpenDmas - first configuration according to values in regs.
         * - read the current number of open Dma's */
        currentExtraVal = fman_get_num_extra_dmas(bmi_rg, hardwarePortId);
        currentVal = fman_get_num_of_dmas(bmi_rg, hardwarePortId);
        /* This is the first configuration and user did not specify value (!numOfOpenDmas),
         * reset values will be used and we just save these values for resource management */
        p_Fm->p_FmStateStruct->extraOpenDmasPoolSize =
                    (uint8_t)MAX(p_Fm->p_FmStateStruct->extraOpenDmasPoolSize, currentExtraVal);
        p_Fm->p_FmStateStruct->accumulatedNumOfOpenDmas += currentVal;
        *p_NumOfOpenDmas = currentVal;
        *p_NumOfExtraOpenDmas = currentExtraVal;
        return E_OK;
    }
#endif /* FM_NO_GUARANTEED_RESET_VALUES */

        if (numOfExtraOpenDmas > currentExtraVal)
             p_Fm->p_FmStateStruct->extraOpenDmasPoolSize =
                 (uint8_t)MAX(p_Fm->p_FmStateStruct->extraOpenDmasPoolSize, numOfExtraOpenDmas);

#ifdef FM_HAS_TOTAL_DMAS
        if ((p_Fm->p_FmStateStruct->revInfo.majorRev < 6) &&
            (p_Fm->p_FmStateStruct->accumulatedNumOfOpenDmas - currentVal + numOfOpenDmas >
                p_Fm->p_FmStateStruct->maxNumOfOpenDmas))
                RETURN_ERROR(MAJOR, E_NOT_AVAILABLE,
                             ("Requested numOfOpenDmas for fm%d exceeds total numOfOpenDmas.",
                             p_Fm->p_FmStateStruct->fmId));
#else
        if ((p_Fm->p_FmStateStruct->revInfo.majorRev >= 6) &&
#ifdef FM_HEAVY_TRAFFIC_SEQUENCER_HANG_ERRATA_FMAN_A006981
            !((p_Fm->p_FmStateStruct->revInfo.majorRev == 6) &&
              (p_Fm->p_FmStateStruct->revInfo.minorRev == 0)) &&
#endif /* FM_HEAVY_TRAFFIC_SEQUENCER_HANG_ERRATA_FMAN_A006981 */
            (p_Fm->p_FmStateStruct->accumulatedNumOfOpenDmas - currentVal + numOfOpenDmas > DMA_THRESH_MAX_COMMQ + 1))
            RETURN_ERROR(MAJOR, E_NOT_AVAILABLE,
                         ("Requested numOfOpenDmas for fm%d exceeds DMA Command queue (%d)",
                          p_Fm->p_FmStateStruct->fmId, DMA_THRESH_MAX_COMMQ+1));
#endif /* FM_HAS_TOTAL_DMAS */
        else
        {
            ASSERT_COND(p_Fm->p_FmStateStruct->accumulatedNumOfOpenDmas >= currentVal);
            /* update acummulated */
            p_Fm->p_FmStateStruct->accumulatedNumOfOpenDmas -= currentVal;
            p_Fm->p_FmStateStruct->accumulatedNumOfOpenDmas += numOfOpenDmas;

#ifdef FM_HAS_TOTAL_DMAS
            if (p_Fm->p_FmStateStruct->revInfo.majorRev < 6)
            totalNumDmas = (uint8_t)(p_Fm->p_FmStateStruct->accumulatedNumOfOpenDmas + p_Fm->p_FmStateStruct->extraOpenDmasPoolSize);
#endif /* FM_HAS_TOTAL_DMAS */
            fman_set_num_of_open_dmas(bmi_rg,
                               hardwarePortId,
                               numOfOpenDmas,
                               numOfExtraOpenDmas,
                               totalNumDmas);
        }

    return E_OK;
}

#if (DPAA_VERSION >= 11)
t_Error FmVSPCheckRelativeProfile(t_Handle        h_Fm,
                                  e_FmPortType    portType,
                                  uint8_t         portId,
                                  uint16_t        relativeProfile)
{
    t_Fm         *p_Fm;
    t_FmSp      *p_FmPcdSp;
    uint8_t     swPortIndex=0, hardwarePortId;

    ASSERT_COND(h_Fm);
    p_Fm = (t_Fm*)h_Fm;

    hardwarePortId = SwPortIdToHwPortId(portType,
                                    portId,
                                    p_Fm->p_FmStateStruct->revInfo.majorRev,
                                    p_Fm->p_FmStateStruct->revInfo.minorRev);
    ASSERT_COND(hardwarePortId);
    HW_PORT_ID_TO_SW_PORT_INDX(swPortIndex, hardwarePortId);

    p_FmPcdSp = p_Fm->p_FmSp;
    ASSERT_COND(p_FmPcdSp);

    if (!p_FmPcdSp->portsMapping[swPortIndex].numOfProfiles)
        RETURN_ERROR(MAJOR, E_INVALID_STATE , ("Port has no allocated profiles"));
    if (relativeProfile >= p_FmPcdSp->portsMapping[swPortIndex].numOfProfiles)
        RETURN_ERROR(MAJOR, E_NOT_IN_RANGE , ("Profile id is out of range"));

    return E_OK;
}

t_Error FmVSPGetAbsoluteProfileId(t_Handle        h_Fm,
                                  e_FmPortType    portType,
                                  uint8_t         portId,
                                  uint16_t        relativeProfile,
                                  uint16_t        *p_AbsoluteId)
{
    t_Fm         *p_Fm;
    t_FmSp      *p_FmPcdSp;
    uint8_t     swPortIndex=0, hardwarePortId;
    t_Error     err;

    ASSERT_COND(h_Fm);
    p_Fm = (t_Fm*)h_Fm;

    err = FmVSPCheckRelativeProfile(h_Fm, portType, portId, relativeProfile);
    if (err != E_OK)
        return err;

    hardwarePortId = SwPortIdToHwPortId(portType,
                                    portId,
                                    p_Fm->p_FmStateStruct->revInfo.majorRev,
                                    p_Fm->p_FmStateStruct->revInfo.minorRev);
    ASSERT_COND(hardwarePortId);
    HW_PORT_ID_TO_SW_PORT_INDX(swPortIndex, hardwarePortId);

    p_FmPcdSp = p_Fm->p_FmSp;
    ASSERT_COND(p_FmPcdSp);

    *p_AbsoluteId = (uint16_t)(p_FmPcdSp->portsMapping[swPortIndex].profilesBase + relativeProfile);

    return E_OK;
}
#endif /* (DPAA_VERSION >= 11) */

static t_Error InitFmDma(t_Fm *p_Fm)
{
    t_Error err;

    err = (t_Error)fman_dma_init(p_Fm->p_FmDmaRegs, p_Fm->p_FmDriverParam);
    if (err != E_OK)
        return err;

    /* Allocate MURAM for CAM */
    p_Fm->camBaseAddr = PTR_TO_UINT(FM_MURAM_AllocMem(p_Fm->h_FmMuram,
                                                      (uint32_t)(p_Fm->p_FmDriverParam->dma_cam_num_of_entries*DMA_CAM_SIZEOF_ENTRY),
                                                      DMA_CAM_ALIGN));
    if (!p_Fm->camBaseAddr)
        RETURN_ERROR(MAJOR, E_NO_MEMORY, ("MURAM alloc for DMA CAM failed"));

    WRITE_BLOCK(UINT_TO_PTR(p_Fm->camBaseAddr),
                0,
                (uint32_t)(p_Fm->p_FmDriverParam->dma_cam_num_of_entries*DMA_CAM_SIZEOF_ENTRY));

    if (p_Fm->p_FmStateStruct->revInfo.majorRev == 2)
    {
        FM_MURAM_FreeMem(p_Fm->h_FmMuram, UINT_TO_PTR(p_Fm->camBaseAddr));

        p_Fm->camBaseAddr = PTR_TO_UINT(FM_MURAM_AllocMem(p_Fm->h_FmMuram,
                                                          (uint32_t)(p_Fm->p_FmDriverParam->dma_cam_num_of_entries*72 + 128),
                                                          64));
        if (!p_Fm->camBaseAddr)
            RETURN_ERROR(MAJOR, E_NO_MEMORY, ("MURAM alloc for DMA CAM failed"));

        WRITE_BLOCK(UINT_TO_PTR(p_Fm->camBaseAddr),
                   0,
               (uint32_t)(p_Fm->p_FmDriverParam->dma_cam_num_of_entries*72 + 128));

        switch(p_Fm->p_FmDriverParam->dma_cam_num_of_entries)
        {
            case (8):
                WRITE_UINT32(*(uint32_t*)p_Fm->camBaseAddr, 0xff000000);
                break;
            case (16):
                WRITE_UINT32(*(uint32_t*)p_Fm->camBaseAddr, 0xffff0000);
                break;
            case (24):
                WRITE_UINT32(*(uint32_t*)p_Fm->camBaseAddr, 0xffffff00);
                break;
            case (32):
                WRITE_UINT32(*(uint32_t*)p_Fm->camBaseAddr, 0xffffffff);
                break;
            default:
                RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("wrong dma_cam_num_of_entries"));
        }
    }

    p_Fm->p_FmDriverParam->cam_base_addr =
                 (uint32_t)(XX_VirtToPhys(UINT_TO_PTR(p_Fm->camBaseAddr)) - p_Fm->fmMuramPhysBaseAddr);

    return E_OK;
}

static t_Error InitFmFpm(t_Fm *p_Fm)
{
    return (t_Error)fman_fpm_init(p_Fm->p_FmFpmRegs, p_Fm->p_FmDriverParam);
}

static t_Error InitFmBmi(t_Fm *p_Fm)
{
    return (t_Error)fman_bmi_init(p_Fm->p_FmBmiRegs, p_Fm->p_FmDriverParam);
}

static t_Error InitFmQmi(t_Fm *p_Fm)
{
    return (t_Error)fman_qmi_init(p_Fm->p_FmQmiRegs, p_Fm->p_FmDriverParam);
}

static t_Error InitGuestMode(t_Fm *p_Fm)
{
    t_Error                 err = E_OK;
    int                     i;
    t_FmIpcMsg              msg;
    t_FmIpcReply            reply;
    uint32_t                replyLength;

    ASSERT_COND(p_Fm);
    ASSERT_COND(p_Fm->guestId != NCSW_MASTER_ID);

    /* build the FM guest partition IPC address */
    if (Sprint (p_Fm->fmModuleName, "FM_%d_%d",p_Fm->p_FmStateStruct->fmId, p_Fm->guestId) != (p_Fm->guestId<10 ? 6:7))
        RETURN_ERROR(MAJOR, E_INVALID_STATE, ("Sprint failed"));

    /* build the FM master partition IPC address */
    memset(p_Fm->fmIpcHandlerModuleName, 0, (sizeof(char)) * MODULE_NAME_SIZE);
    if (Sprint (p_Fm->fmIpcHandlerModuleName[0], "FM_%d_%d",p_Fm->p_FmStateStruct->fmId, NCSW_MASTER_ID) != 6)
        RETURN_ERROR(MAJOR, E_INVALID_STATE, ("Sprint failed"));

    for (i=0;i<e_FM_EV_DUMMY_LAST;i++)
        p_Fm->intrMng[i].f_Isr = UnimplementedIsr;

    p_Fm->h_IpcSessions[0] = XX_IpcInitSession(p_Fm->fmIpcHandlerModuleName[0], p_Fm->fmModuleName);
    if (p_Fm->h_IpcSessions[0])
    {
        uint8_t                 isMasterAlive;
        t_FmIpcParams           ipcParams;

        err = XX_IpcRegisterMsgHandler(p_Fm->fmModuleName, FmGuestHandleIpcMsgCB, p_Fm, FM_IPC_MAX_REPLY_SIZE);
        if (err)
            RETURN_ERROR(MAJOR, err, NO_MSG);

        memset(&msg, 0, sizeof(msg));
        memset(&reply, 0, sizeof(reply));
        msg.msgId = FM_MASTER_IS_ALIVE;
        msg.msgBody[0] = p_Fm->guestId;
        replyLength = sizeof(uint32_t) + sizeof(uint8_t);
        do
        {
            blockingFlag = TRUE;
            if ((err = XX_IpcSendMessage(p_Fm->h_IpcSessions[0],
                                         (uint8_t*)&msg,
                                         sizeof(msg.msgId)+sizeof(p_Fm->guestId),
                                         (uint8_t*)&reply,
                                         &replyLength,
                                         IpcMsgCompletionCB,
                                         p_Fm)) != E_OK)
                REPORT_ERROR(MINOR, err, NO_MSG);
            while (blockingFlag) ;
            if (replyLength != (sizeof(uint32_t) + sizeof(uint8_t)))
                REPORT_ERROR(MAJOR, E_INVALID_VALUE, ("IPC reply length mismatch"));
            isMasterAlive = *(uint8_t*)(reply.replyBody);
        } while (!isMasterAlive);

        /* read FM parameters and save */
        memset(&msg, 0, sizeof(msg));
        memset(&reply, 0, sizeof(reply));
        msg.msgId = FM_GET_PARAMS;
        replyLength = sizeof(uint32_t) + sizeof(t_FmIpcParams);
        if ((err = XX_IpcSendMessage(p_Fm->h_IpcSessions[0],
                                     (uint8_t*)&msg,
                                     sizeof(msg.msgId),
                                     (uint8_t*)&reply,
                                     &replyLength,
                                     NULL,
                                     NULL)) != E_OK)
            RETURN_ERROR(MAJOR, err, NO_MSG);
        if (replyLength != (sizeof(uint32_t) + sizeof(t_FmIpcParams)))
            RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("IPC reply length mismatch"));
        memcpy((uint8_t*)&ipcParams, reply.replyBody, sizeof(t_FmIpcParams));

        p_Fm->p_FmStateStruct->fmClkFreq = ipcParams.fmClkFreq;
        p_Fm->p_FmStateStruct->fmMacClkFreq = ipcParams.fmMacClkFreq;
        p_Fm->p_FmStateStruct->revInfo.majorRev = ipcParams.majorRev;
        p_Fm->p_FmStateStruct->revInfo.minorRev = ipcParams.minorRev;
    }
    else
    {
        DBG(WARNING, ("FM Guest mode - without IPC"));
        if (!p_Fm->p_FmStateStruct->fmClkFreq)
            RETURN_ERROR(MAJOR, E_INVALID_STATE, ("No fmClkFreq configured for guest without IPC"));
        if (p_Fm->baseAddr)
        {
            fman_get_revision(p_Fm->p_FmFpmRegs,
                              &p_Fm->p_FmStateStruct->revInfo.majorRev,
                              &p_Fm->p_FmStateStruct->revInfo.minorRev);

        }
    }

#if (DPAA_VERSION >= 11)
    p_Fm->partVSPBase = AllocVSPsForPartition(p_Fm, p_Fm->partVSPBase, p_Fm->partNumOfVSPs, p_Fm->guestId);
    if (p_Fm->partVSPBase == (uint8_t)(ILLEGAL_BASE))
        DBG(WARNING, ("partition VSPs allocation is FAILED"));
#endif /* (DPAA_VERSION >= 11) */

    /* General FM driver initialization */
    if (p_Fm->baseAddr)
        p_Fm->fmMuramPhysBaseAddr =
            (uint64_t)(XX_VirtToPhys(UINT_TO_PTR(p_Fm->baseAddr + FM_MM_MURAM)));

    XX_Free(p_Fm->p_FmDriverParam);
    p_Fm->p_FmDriverParam = NULL;

    if ((p_Fm->guestId == NCSW_MASTER_ID) ||
        (p_Fm->h_IpcSessions[0]))
    {
        FM_DisableRamsEcc(p_Fm);
        FmMuramClear(p_Fm->h_FmMuram);
        FM_EnableRamsEcc(p_Fm);
    }

    return E_OK;
}

static __inline__ enum fman_exceptions FmanExceptionTrans(e_FmExceptions exception)
{
    switch (exception) {
            case  e_FM_EX_DMA_BUS_ERROR:
                return E_FMAN_EX_DMA_BUS_ERROR;
            case  e_FM_EX_DMA_READ_ECC:
                return E_FMAN_EX_DMA_READ_ECC;
            case  e_FM_EX_DMA_SYSTEM_WRITE_ECC:
                return E_FMAN_EX_DMA_SYSTEM_WRITE_ECC;
            case  e_FM_EX_DMA_FM_WRITE_ECC:
                return E_FMAN_EX_DMA_FM_WRITE_ECC;
            case  e_FM_EX_FPM_STALL_ON_TASKS:
                return E_FMAN_EX_FPM_STALL_ON_TASKS;
            case  e_FM_EX_FPM_SINGLE_ECC:
                return E_FMAN_EX_FPM_SINGLE_ECC;
            case  e_FM_EX_FPM_DOUBLE_ECC:
                return E_FMAN_EX_FPM_DOUBLE_ECC;
            case  e_FM_EX_QMI_SINGLE_ECC:
                return E_FMAN_EX_QMI_SINGLE_ECC;
            case  e_FM_EX_QMI_DOUBLE_ECC:
                return E_FMAN_EX_QMI_DOUBLE_ECC;
            case  e_FM_EX_QMI_DEQ_FROM_UNKNOWN_PORTID:
                return E_FMAN_EX_QMI_DEQ_FROM_UNKNOWN_PORTID;
            case  e_FM_EX_BMI_LIST_RAM_ECC:
                return E_FMAN_EX_BMI_LIST_RAM_ECC;
            case  e_FM_EX_BMI_STORAGE_PROFILE_ECC:
                return E_FMAN_EX_BMI_STORAGE_PROFILE_ECC;
            case  e_FM_EX_BMI_STATISTICS_RAM_ECC:
                return E_FMAN_EX_BMI_STATISTICS_RAM_ECC;
            case  e_FM_EX_BMI_DISPATCH_RAM_ECC:
                return E_FMAN_EX_BMI_DISPATCH_RAM_ECC;
            case  e_FM_EX_IRAM_ECC:
                return E_FMAN_EX_IRAM_ECC;
            case  e_FM_EX_MURAM_ECC:
                return E_FMAN_EX_MURAM_ECC;
            default:
                return E_FMAN_EX_DMA_BUS_ERROR;
        }
}

uint8_t SwPortIdToHwPortId(e_FmPortType type, uint8_t relativePortId, uint8_t majorRev, uint8_t minorRev)
{
	switch (type)
	{
		case (e_FM_PORT_TYPE_OH_OFFLINE_PARSING):
		case (e_FM_PORT_TYPE_OH_HOST_COMMAND):
			CHECK_PORT_ID_OH_PORTS(relativePortId);
			return (uint8_t)(BASE_OH_PORTID + (relativePortId));
		case (e_FM_PORT_TYPE_RX):
			CHECK_PORT_ID_1G_RX_PORTS(relativePortId);
			return (uint8_t)(BASE_1G_RX_PORTID + (relativePortId));
		case (e_FM_PORT_TYPE_RX_10G):
                       /* The 10G port in T1024 (FMan Version 6.4) is the first port.
                        * This is the reason why the 1G port offset is used.
                        */
                       if (majorRev == 6 && minorRev == 4)
                       {
                               CHECK_PORT_ID_1G_RX_PORTS(relativePortId);
                               return (uint8_t)(BASE_1G_RX_PORTID + (relativePortId));
                       }
                       else
                       {
                               CHECK_PORT_ID_10G_RX_PORTS(relativePortId);
                               return (uint8_t)(BASE_10G_RX_PORTID + (relativePortId));
                       }
		case (e_FM_PORT_TYPE_TX):
			CHECK_PORT_ID_1G_TX_PORTS(relativePortId);
			return (uint8_t)(BASE_1G_TX_PORTID + (relativePortId));
		case (e_FM_PORT_TYPE_TX_10G):
                       /* The 10G port in T1024 (FMan Version 6.4) is the first port.
                        * This is the reason why the 1G port offset is used.
                        */
                       if (majorRev == 6 && minorRev == 4)
                       {
                               CHECK_PORT_ID_1G_TX_PORTS(relativePortId);
                               return (uint8_t)(BASE_1G_TX_PORTID + (relativePortId));
                       }
                       else
                       {
                               CHECK_PORT_ID_10G_TX_PORTS(relativePortId);
                               return (uint8_t)(BASE_10G_TX_PORTID + (relativePortId));
                       }
		default:
			REPORT_ERROR(MAJOR, E_INVALID_VALUE, ("Illegal port type"));
			return 0;
	}
}

#if (defined(DEBUG_ERRORS) && (DEBUG_ERRORS > 0))
t_Error FmDumpPortRegs (t_Handle h_Fm, uint8_t hardwarePortId)
{
    t_Fm            *p_Fm = (t_Fm *)h_Fm;

    DECLARE_DUMP;

    ASSERT_COND(IN_RANGE(1, hardwarePortId, 63));

    SANITY_CHECK_RETURN_ERROR(p_Fm, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(((p_Fm->guestId == NCSW_MASTER_ID) ||
                               p_Fm->baseAddr), E_INVALID_OPERATION);

    DUMP_TITLE(&p_Fm->p_FmBmiRegs->fmbm_pp[hardwarePortId-1], ("fmbm_pp for port %u", (hardwarePortId)));
    DUMP_MEMORY(&p_Fm->p_FmBmiRegs->fmbm_pp[hardwarePortId-1], sizeof(uint32_t));

    DUMP_TITLE(&p_Fm->p_FmBmiRegs->fmbm_pfs[hardwarePortId-1], ("fmbm_pfs for port %u", (hardwarePortId )));
    DUMP_MEMORY(&p_Fm->p_FmBmiRegs->fmbm_pfs[hardwarePortId-1], sizeof(uint32_t));

    DUMP_TITLE(&p_Fm->p_FmBmiRegs->fmbm_spliodn[hardwarePortId-1], ("fmbm_spliodn for port %u", (hardwarePortId)));
    DUMP_MEMORY(&p_Fm->p_FmBmiRegs->fmbm_spliodn[hardwarePortId-1], sizeof(uint32_t));

    DUMP_TITLE(&p_Fm->p_FmFpmRegs->fmfp_ps[hardwarePortId], ("fmfp_ps for port %u", (hardwarePortId)));
    DUMP_MEMORY(&p_Fm->p_FmFpmRegs->fmfp_ps[hardwarePortId], sizeof(uint32_t));

    DUMP_TITLE(&p_Fm->p_FmDmaRegs->fmdmplr[hardwarePortId/2], ("fmdmplr for port %u", (hardwarePortId)));
    DUMP_MEMORY(&p_Fm->p_FmDmaRegs->fmdmplr[hardwarePortId/2], sizeof(uint32_t));

    return E_OK;
}
#endif /* (defined(DEBUG_ERRORS) && (DEBUG_ERRORS > 0)) */


/*****************************************************************************/
/*                      API Init unit functions                              */
/*****************************************************************************/
t_Handle FM_Config(t_FmParams *p_FmParam)
{
    t_Fm                *p_Fm;
    uint8_t             i;
    uintptr_t           baseAddr;

    SANITY_CHECK_RETURN_VALUE(p_FmParam, E_NULL_POINTER, NULL);
    SANITY_CHECK_RETURN_VALUE(((p_FmParam->firmware.p_Code && p_FmParam->firmware.size) ||
                               (!p_FmParam->firmware.p_Code && !p_FmParam->firmware.size)),
                              E_INVALID_VALUE, NULL);

    baseAddr = p_FmParam->baseAddr;

    /* Allocate FM structure */
    p_Fm = (t_Fm *) XX_Malloc(sizeof(t_Fm));
    if (!p_Fm)
    {
        REPORT_ERROR(MAJOR, E_NO_MEMORY, ("FM driver structure"));
        return NULL;
    }
    memset(p_Fm, 0, sizeof(t_Fm));

    p_Fm->p_FmStateStruct = (t_FmStateStruct *) XX_Malloc(sizeof(t_FmStateStruct));
    if (!p_Fm->p_FmStateStruct)
    {
        XX_Free(p_Fm);
        REPORT_ERROR(MAJOR, E_NO_MEMORY, ("FM Status structure"));
        return NULL;
    }
    memset(p_Fm->p_FmStateStruct, 0, sizeof(t_FmStateStruct));

    /* Initialize FM parameters which will be kept by the driver */
    p_Fm->p_FmStateStruct->fmId = p_FmParam->fmId;
    p_Fm->guestId               = p_FmParam->guestId;

    for (i=0; i<FM_MAX_NUM_OF_HW_PORT_IDS; i++)
        p_Fm->p_FmStateStruct->portsTypes[i] = e_FM_PORT_TYPE_DUMMY;

    /* Allocate the FM driver's parameters structure */
    p_Fm->p_FmDriverParam = (struct fman_cfg *)XX_Malloc(sizeof(struct fman_cfg));
    if (!p_Fm->p_FmDriverParam)
    {
        XX_Free(p_Fm->p_FmStateStruct);
        XX_Free(p_Fm);
        REPORT_ERROR(MAJOR, E_NO_MEMORY, ("FM driver parameters"));
        return NULL;
    }
    memset(p_Fm->p_FmDriverParam, 0, sizeof(struct fman_cfg));

#if (DPAA_VERSION >= 11)
    p_Fm->p_FmSp = (t_FmSp *)XX_Malloc(sizeof(t_FmSp));
    if (!p_Fm->p_FmSp)
    {
        XX_Free(p_Fm->p_FmDriverParam);
        XX_Free(p_Fm->p_FmStateStruct);
        XX_Free(p_Fm);
        REPORT_ERROR(MAJOR, E_NO_MEMORY, ("allocation for internal data structure failed"));
        return NULL;
    }
    memset(p_Fm->p_FmSp, 0, sizeof(t_FmSp));

    for (i=0; i<FM_VSP_MAX_NUM_OF_ENTRIES; i++)
        p_Fm->p_FmSp->profiles[i].profilesMng.ownerId = (uint8_t)ILLEGAL_BASE;
#endif /* (DPAA_VERSION >= 11) */

    /* Initialize FM parameters which will be kept by the driver */
    p_Fm->p_FmStateStruct->fmId                 = p_FmParam->fmId;
    p_Fm->h_FmMuram                             = p_FmParam->h_FmMuram;
    p_Fm->h_App                                 = p_FmParam->h_App;
    p_Fm->p_FmStateStruct->fmClkFreq            = p_FmParam->fmClkFreq;
    p_Fm->p_FmStateStruct->fmMacClkFreq         = p_FmParam->fmClkFreq / ((!p_FmParam->fmMacClkRatio)? 2: p_FmParam->fmMacClkRatio);
    p_Fm->f_Exception                           = p_FmParam->f_Exception;
    p_Fm->f_BusError                            = p_FmParam->f_BusError;
    p_Fm->p_FmFpmRegs = (struct fman_fpm_regs *)UINT_TO_PTR(baseAddr + FM_MM_FPM);
    p_Fm->p_FmBmiRegs = (struct fman_bmi_regs *)UINT_TO_PTR(baseAddr + FM_MM_BMI);
    p_Fm->p_FmQmiRegs = (struct fman_qmi_regs *)UINT_TO_PTR(baseAddr + FM_MM_QMI);
    p_Fm->p_FmDmaRegs = (struct fman_dma_regs *)UINT_TO_PTR(baseAddr + FM_MM_DMA);
    p_Fm->p_FmRegs       = (struct fman_regs *)UINT_TO_PTR(baseAddr + FM_MM_BMI);
    p_Fm->baseAddr                              = baseAddr;
    p_Fm->p_FmStateStruct->irq                  = p_FmParam->irq;
    p_Fm->p_FmStateStruct->errIrq               = p_FmParam->errIrq;
    p_Fm->hcPortInitialized                     = FALSE;
    p_Fm->independentMode                       = FALSE;

    p_Fm->h_Spinlock = XX_InitSpinlock();
    if (!p_Fm->h_Spinlock)
    {
        XX_Free(p_Fm->p_FmDriverParam);
        XX_Free(p_Fm->p_FmStateStruct);
        XX_Free(p_Fm);
        REPORT_ERROR(MAJOR, E_INVALID_STATE, ("can't allocate spinlock!"));
        return NULL;
    }

#if (DPAA_VERSION >= 11)
    p_Fm->partVSPBase   = p_FmParam->partVSPBase;
    p_Fm->partNumOfVSPs = p_FmParam->partNumOfVSPs;
    p_Fm->vspBaseAddr = p_FmParam->vspBaseAddr;
#endif /* (DPAA_VERSION >= 11) */

    fman_defconfig(p_Fm->p_FmDriverParam,
                  !!(p_Fm->guestId == NCSW_MASTER_ID));
/* overide macros dependent parameters */
#ifdef FM_PEDANTIC_DMA
    p_Fm->p_FmDriverParam->pedantic_dma = TRUE;
    p_Fm->p_FmDriverParam->dma_aid_override = TRUE;
#endif /* FM_PEDANTIC_DMA */
#ifndef FM_QMI_NO_DEQ_OPTIONS_SUPPORT
    p_Fm->p_FmDriverParam->qmi_deq_option_support = TRUE;
#endif /* !FM_QMI_NO_DEQ_OPTIONS_SUPPORT */

    p_Fm->p_FmStateStruct->ramsEccEnable        = FALSE;
    p_Fm->p_FmStateStruct->extraFifoPoolSize    = 0;
    p_Fm->p_FmStateStruct->exceptions           = DEFAULT_exceptions;
    p_Fm->resetOnInit                          = DEFAULT_resetOnInit;
    p_Fm->f_ResetOnInitOverride                = DEFAULT_resetOnInitOverrideCallback;
    p_Fm->fwVerify                             = DEFAULT_VerifyUcode;
    p_Fm->firmware.size                        = p_FmParam->firmware.size;
    if (p_Fm->firmware.size)
    {
        p_Fm->firmware.p_Code = (uint32_t *)XX_Malloc(p_Fm->firmware.size);
        if (!p_Fm->firmware.p_Code)
        {
            XX_FreeSpinlock(p_Fm->h_Spinlock);
            XX_Free(p_Fm->p_FmStateStruct);
            XX_Free(p_Fm->p_FmDriverParam);
            XX_Free(p_Fm);
            REPORT_ERROR(MAJOR, E_NO_MEMORY, ("FM firmware code"));
            return NULL;
        }
        memcpy(p_Fm->firmware.p_Code, p_FmParam->firmware.p_Code ,p_Fm->firmware.size);
    }

    if (p_Fm->guestId != NCSW_MASTER_ID)
        return p_Fm;

    /* read revision */
    /* Chip dependent, will be configured in Init */
    fman_get_revision(p_Fm->p_FmFpmRegs,
                      &p_Fm->p_FmStateStruct->revInfo.majorRev,
                      &p_Fm->p_FmStateStruct->revInfo.minorRev);

#ifdef FM_AID_MODE_NO_TNUM_SW005
    if (p_Fm->p_FmStateStruct->revInfo.majorRev >= 6)
        p_Fm->p_FmDriverParam->dma_aid_mode = e_FM_DMA_AID_OUT_PORT_ID;
#endif /* FM_AID_MODE_NO_TNUM_SW005 */
#ifndef FM_QMI_NO_DEQ_OPTIONS_SUPPORT
   if (p_Fm->p_FmStateStruct->revInfo.majorRev != 4)
        p_Fm->p_FmDriverParam->qmi_def_tnums_thresh = QMI_DEF_TNUMS_THRESH;
#endif /* FM_QMI_NO_DEQ_OPTIONS_SUPPORT */

        p_Fm->p_FmStateStruct->totalFifoSize        = 0;
        p_Fm->p_FmStateStruct->totalNumOfTasks      = 
            DEFAULT_totalNumOfTasks(p_Fm->p_FmStateStruct->revInfo.majorRev,
                                    p_Fm->p_FmStateStruct->revInfo.minorRev);

#ifdef FM_HAS_TOTAL_DMAS
        p_Fm->p_FmStateStruct->maxNumOfOpenDmas     = BMI_MAX_NUM_OF_DMAS;
#endif /* FM_HAS_TOTAL_DMAS */
#if (DPAA_VERSION < 11)
        p_Fm->p_FmDriverParam->dma_comm_qtsh_clr_emer        = DEFAULT_dmaCommQLow;
        p_Fm->p_FmDriverParam->dma_comm_qtsh_asrt_emer       = DEFAULT_dmaCommQHigh;
        p_Fm->p_FmDriverParam->dma_cam_num_of_entries        = DEFAULT_dmaCamNumOfEntries;
        p_Fm->p_FmDriverParam->dma_read_buf_tsh_clr_emer      = DEFAULT_dmaReadIntBufLow;
        p_Fm->p_FmDriverParam->dma_read_buf_tsh_asrt_emer     = DEFAULT_dmaReadIntBufHigh;
        p_Fm->p_FmDriverParam->dma_write_buf_tsh_clr_emer     = DEFAULT_dmaWriteIntBufLow;
        p_Fm->p_FmDriverParam->dma_write_buf_tsh_asrt_emer    = DEFAULT_dmaWriteIntBufHigh;
        p_Fm->p_FmDriverParam->dma_axi_dbg_num_of_beats       = DEFAULT_axiDbgNumOfBeats;
#endif /* (DPAA_VERSION < 11) */
#ifdef FM_NO_TNUM_AGING
    p_Fm->p_FmDriverParam->tnum_aging_period = 0;
#endif
    p_Fm->tnumAgingPeriod = p_Fm->p_FmDriverParam->tnum_aging_period;

   return p_Fm;
}

/**************************************************************************//**
 @Function      FM_Init

 @Description   Initializes the FM module

 @Param[in]     h_Fm - FM module descriptor

 @Return        E_OK on success; Error code otherwise.
*//***************************************************************************/
t_Error FM_Init(t_Handle h_Fm)
{
    t_Fm                    *p_Fm = (t_Fm*)h_Fm;
    struct fman_cfg         *p_FmDriverParam = NULL;
    t_Error                 err = E_OK;
    int                     i;
    t_FmRevisionInfo        revInfo;
    struct fman_rg          fman_rg;

    SANITY_CHECK_RETURN_ERROR(p_Fm, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(p_Fm->p_FmDriverParam, E_INVALID_HANDLE);

    fman_rg.bmi_rg = p_Fm->p_FmBmiRegs;
    fman_rg.qmi_rg = p_Fm->p_FmQmiRegs;
    fman_rg.fpm_rg = p_Fm->p_FmFpmRegs;
    fman_rg.dma_rg = p_Fm->p_FmDmaRegs;

    p_Fm->p_FmStateStruct->count1MicroBit = FM_TIMESTAMP_1_USEC_BIT;
    p_Fm->p_FmDriverParam->num_of_fman_ctrl_evnt_regs = FM_NUM_OF_FMAN_CTRL_EVENT_REGS;

    if (p_Fm->guestId != NCSW_MASTER_ID)
        return InitGuestMode(p_Fm);

    /* if user didn't configured totalFifoSize - (totalFifoSize=0) we configure default
    * according to chip. otherwise, we use user's configuration.
    */
    if (p_Fm->p_FmStateStruct->totalFifoSize == 0)
        p_Fm->p_FmStateStruct->totalFifoSize = DEFAULT_totalFifoSize(p_Fm->p_FmStateStruct->revInfo.majorRev,
                                                                     p_Fm->p_FmStateStruct->revInfo.minorRev);

    CHECK_INIT_PARAMETERS(p_Fm, CheckFmParameters);

    p_FmDriverParam = p_Fm->p_FmDriverParam;

    FM_GetRevision(p_Fm, &revInfo);

    /* clear revision-dependent non existing exception */
#ifdef FM_NO_DISPATCH_RAM_ECC
    if ((revInfo.majorRev != 4) &&
        (revInfo.majorRev < 6))
        p_Fm->p_FmStateStruct->exceptions &= ~FM_EX_BMI_DISPATCH_RAM_ECC;
#endif /* FM_NO_DISPATCH_RAM_ECC */

#ifdef FM_QMI_NO_ECC_EXCEPTIONS
    if (revInfo.majorRev == 4)
        p_Fm->p_FmStateStruct->exceptions &= ~(FM_EX_QMI_SINGLE_ECC | FM_EX_QMI_DOUBLE_ECC);
#endif /* FM_QMI_NO_ECC_EXCEPTIONS */

#ifdef FM_QMI_NO_SINGLE_ECC_EXCEPTION
    if (revInfo.majorRev >= 6)
       p_Fm->p_FmStateStruct->exceptions &= ~FM_EX_QMI_SINGLE_ECC;
#endif /* FM_QMI_NO_SINGLE_ECC_EXCEPTION */

    FmMuramClear(p_Fm->h_FmMuram);

    /* clear CPG */
    IOMemSet32(UINT_TO_PTR(p_Fm->baseAddr + FM_MM_CGP), 0, FM_PORT_NUM_OF_CONGESTION_GRPS);

    /* add to the default exceptions the user's definitions */
    p_Fm->p_FmStateStruct->exceptions |= p_Fm->userSetExceptions;

    /* Reset the FM if required */
    if (p_Fm->resetOnInit)
    {
#ifdef FM_UCODE_NOT_RESET_ERRATA_BUGZILLA6173
        if ((err = FwNotResetErratumBugzilla6173WA(p_Fm)) != E_OK)
            RETURN_ERROR(MAJOR, err, NO_MSG);
#else  /* not FM_UCODE_NOT_RESET_ERRATA_BUGZILLA6173 */

        if (p_Fm->f_ResetOnInitOverride)
        {
        	/* Perform user specific FMan reset */
        	p_Fm->f_ResetOnInitOverride(h_Fm);
        }
        else
        {
        	/* Perform FMan reset */
        	FmReset(h_Fm);
        }

        if (fman_is_qmi_halt_not_busy_state(p_Fm->p_FmQmiRegs))
        {
            fman_resume(p_Fm->p_FmFpmRegs);
            XX_UDelay(100);
        }
#endif /* not FM_UCODE_NOT_RESET_ERRATA_BUGZILLA6173 */
    }

#ifdef FM_UCODE_NOT_RESET_ERRATA_BUGZILLA6173
    if (!p_Fm->resetOnInit) /* Skip operations done in errata workaround */
    {
#endif /* FM_UCODE_NOT_RESET_ERRATA_BUGZILLA6173 */
    /* Load FMan-Controller code to IRAM */

    ClearIRam(p_Fm);

    if (p_Fm->firmware.p_Code && (LoadFmanCtrlCode(p_Fm) != E_OK))
        RETURN_ERROR(MAJOR, E_INVALID_STATE, NO_MSG);
#ifdef FM_UCODE_NOT_RESET_ERRATA_BUGZILLA6173
    }
#endif /* FM_UCODE_NOT_RESET_ERRATA_BUGZILLA6173 */

#ifdef FM_CAPWAP_SUPPORT
    /* save first 256 byte in MURAM */
    p_Fm->resAddr = PTR_TO_UINT(FM_MURAM_AllocMem(p_Fm->h_FmMuram, 256, 0));
    if (!p_Fm->resAddr)
        RETURN_ERROR(MAJOR, E_NO_MEMORY, ("MURAM alloc for reserved Area failed"));

    WRITE_BLOCK(UINT_TO_PTR(p_Fm->resAddr), 0, 256);
#endif /* FM_CAPWAP_SUPPORT */

#if (DPAA_VERSION >= 11)
    p_Fm->partVSPBase = AllocVSPsForPartition(h_Fm, p_Fm->partVSPBase, p_Fm->partNumOfVSPs, p_Fm->guestId);
    if (p_Fm->partVSPBase == (uint8_t)(ILLEGAL_BASE))
        DBG(WARNING, ("partition VSPs allocation is FAILED"));
#endif /* (DPAA_VERSION >= 11) */

    /* General FM driver initialization */
    p_Fm->fmMuramPhysBaseAddr =
        (uint64_t)(XX_VirtToPhys(UINT_TO_PTR(p_Fm->baseAddr + FM_MM_MURAM)));

    for (i=0;i<e_FM_EV_DUMMY_LAST;i++)
        p_Fm->intrMng[i].f_Isr = UnimplementedIsr;
    for (i=0;i<FM_NUM_OF_FMAN_CTRL_EVENT_REGS;i++)
        p_Fm->fmanCtrlIntr[i].f_Isr = UnimplementedFmanCtrlIsr;

    p_FmDriverParam->exceptions = p_Fm->p_FmStateStruct->exceptions;

    /**********************/
    /* Init DMA Registers */
    /**********************/
    err = InitFmDma(p_Fm);
    if (err != E_OK)
    {
        FreeInitResources(p_Fm);
        RETURN_ERROR(MAJOR, err, NO_MSG);
    }

    /**********************/
    /* Init FPM Registers */
    /**********************/
    err = InitFmFpm(p_Fm);
    if (err != E_OK)
    {
        FreeInitResources(p_Fm);
        RETURN_ERROR(MAJOR, err, NO_MSG);
    }

    /* define common resources */
    /* allocate MURAM for FIFO according to total size */
    p_Fm->fifoBaseAddr = PTR_TO_UINT(FM_MURAM_AllocMem(p_Fm->h_FmMuram,
                                                       p_Fm->p_FmStateStruct->totalFifoSize,
                                                       BMI_FIFO_ALIGN));
    if (!p_Fm->fifoBaseAddr)
    {
        FreeInitResources(p_Fm);
        RETURN_ERROR(MAJOR, E_NO_MEMORY, ("MURAM alloc for BMI FIFO failed"));
    }

    p_FmDriverParam->fifo_base_addr = (uint32_t)(XX_VirtToPhys(UINT_TO_PTR(p_Fm->fifoBaseAddr)) - p_Fm->fmMuramPhysBaseAddr);
    p_FmDriverParam->total_fifo_size = p_Fm->p_FmStateStruct->totalFifoSize;
    p_FmDriverParam->total_num_of_tasks = p_Fm->p_FmStateStruct->totalNumOfTasks;
    p_FmDriverParam->clk_freq = p_Fm->p_FmStateStruct->fmClkFreq;

    /**********************/
    /* Init BMI Registers */
    /**********************/
    err = InitFmBmi(p_Fm);
    if (err != E_OK)
    {
        FreeInitResources(p_Fm);
        RETURN_ERROR(MAJOR, err, NO_MSG);
    }

    /**********************/
    /* Init QMI Registers */
    /**********************/
    err = InitFmQmi(p_Fm);
    if (err != E_OK)
    {
        FreeInitResources(p_Fm);
        RETURN_ERROR(MAJOR, err, NO_MSG);
    }

    /* build the FM master partition IPC address */
    if (Sprint (p_Fm->fmModuleName, "FM_%d_%d",p_Fm->p_FmStateStruct->fmId, NCSW_MASTER_ID) != 6)
    {
        FreeInitResources(p_Fm);
        RETURN_ERROR(MAJOR, E_INVALID_STATE, ("Sprint failed"));
    }

    err = XX_IpcRegisterMsgHandler(p_Fm->fmModuleName, FmHandleIpcMsgCB, p_Fm, FM_IPC_MAX_REPLY_SIZE);
    if (err)
    {
        FreeInitResources(p_Fm);
        RETURN_ERROR(MAJOR, err, NO_MSG);
    }

    /* Register the FM interrupts handlers */
    if (p_Fm->p_FmStateStruct->irq != NO_IRQ)
    {
        XX_SetIntr(p_Fm->p_FmStateStruct->irq, FM_EventIsr, p_Fm);
        XX_EnableIntr(p_Fm->p_FmStateStruct->irq);
    }

    if (p_Fm->p_FmStateStruct->errIrq != NO_IRQ)
    {
        XX_SetIntr(p_Fm->p_FmStateStruct->errIrq, (void (*) (t_Handle))FM_ErrorIsr, p_Fm);
        XX_EnableIntr(p_Fm->p_FmStateStruct->errIrq);
    }

    err = (t_Error)fman_enable(&fman_rg , p_FmDriverParam);
    if (err != E_OK)
        return err; /* FIXME */

    EnableTimeStamp(p_Fm);

    if (p_Fm->firmware.p_Code)
    {
        XX_Free(p_Fm->firmware.p_Code);
        p_Fm->firmware.p_Code = NULL;
    }

    XX_Free(p_Fm->p_FmDriverParam);
    p_Fm->p_FmDriverParam = NULL;

    return E_OK;
}

/**************************************************************************//**
 @Function      FM_Free

 @Description   Frees all resources that were assigned to FM module.

                Calling this routine invalidates the descriptor.

 @Param[in]     h_Fm - FM module descriptor

 @Return        E_OK on success; Error code otherwise.
*//***************************************************************************/
t_Error FM_Free(t_Handle h_Fm)
{
    t_Fm    *p_Fm = (t_Fm*)h_Fm;
    struct fman_rg          fman_rg;

    SANITY_CHECK_RETURN_ERROR(p_Fm, E_INVALID_HANDLE);

    fman_rg.bmi_rg = p_Fm->p_FmBmiRegs;
    fman_rg.qmi_rg = p_Fm->p_FmQmiRegs;
    fman_rg.fpm_rg = p_Fm->p_FmFpmRegs;
    fman_rg.dma_rg = p_Fm->p_FmDmaRegs;

    if (p_Fm->guestId != NCSW_MASTER_ID)
    {
#if (DPAA_VERSION >= 11)
        FreeVSPsForPartition(h_Fm, p_Fm->partVSPBase, p_Fm->partNumOfVSPs, p_Fm->guestId);

        if (p_Fm->p_FmSp)
        {
            XX_Free(p_Fm->p_FmSp);
            p_Fm->p_FmSp = NULL;
        }
#endif /* (DPAA_VERSION >= 11) */

        if (p_Fm->fmModuleName[0] != 0)
            XX_IpcUnregisterMsgHandler(p_Fm->fmModuleName);

        if (!p_Fm->recoveryMode)
            XX_Free(p_Fm->p_FmStateStruct);

        XX_Free(p_Fm);

        return E_OK;
    }

    fman_free_resources(&fman_rg);

    if ((p_Fm->guestId == NCSW_MASTER_ID) && (p_Fm->fmModuleName[0] != 0))
        XX_IpcUnregisterMsgHandler(p_Fm->fmModuleName);

    if (p_Fm->p_FmStateStruct)
    {
        if (p_Fm->p_FmStateStruct->irq != NO_IRQ)
        {
            XX_DisableIntr(p_Fm->p_FmStateStruct->irq);
            XX_FreeIntr(p_Fm->p_FmStateStruct->irq);
        }
        if (p_Fm->p_FmStateStruct->errIrq != NO_IRQ)
        {
            XX_DisableIntr(p_Fm->p_FmStateStruct->errIrq);
            XX_FreeIntr(p_Fm->p_FmStateStruct->errIrq);
        }
    }

#if (DPAA_VERSION >= 11)
    FreeVSPsForPartition(h_Fm, p_Fm->partVSPBase, p_Fm->partNumOfVSPs, p_Fm->guestId);

    if (p_Fm->p_FmSp)
    {
        XX_Free(p_Fm->p_FmSp);
        p_Fm->p_FmSp = NULL;
    }
#endif /* (DPAA_VERSION >= 11) */

    if (p_Fm->h_Spinlock)
        XX_FreeSpinlock(p_Fm->h_Spinlock);

    if (p_Fm->p_FmDriverParam)
    {
        if (p_Fm->firmware.p_Code)
            XX_Free(p_Fm->firmware.p_Code);
        XX_Free(p_Fm->p_FmDriverParam);
        p_Fm->p_FmDriverParam = NULL;
    }

    FreeInitResources(p_Fm);

    if (!p_Fm->recoveryMode && p_Fm->p_FmStateStruct)
        XX_Free(p_Fm->p_FmStateStruct);

    XX_Free(p_Fm);

    return E_OK;
}

/*************************************************/
/*       API Advanced Init unit functions        */
/*************************************************/

t_Error FM_ConfigResetOnInit(t_Handle h_Fm, bool enable)
{
    t_Fm *p_Fm = (t_Fm*)h_Fm;

    SANITY_CHECK_RETURN_ERROR(p_Fm, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(p_Fm->p_FmDriverParam, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR((p_Fm->guestId == NCSW_MASTER_ID), E_NOT_SUPPORTED);

    p_Fm->resetOnInit = enable;

    return E_OK;
}

t_Error FM_ConfigResetOnInitOverrideCallback(t_Handle h_Fm, t_FmResetOnInitOverrideCallback *f_ResetOnInitOverride)
{
    t_Fm *p_Fm = (t_Fm*)h_Fm;

    SANITY_CHECK_RETURN_ERROR(p_Fm, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(p_Fm->p_FmDriverParam, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR((p_Fm->guestId == NCSW_MASTER_ID), E_NOT_SUPPORTED);

    p_Fm->f_ResetOnInitOverride = f_ResetOnInitOverride;

    return E_OK;
}

t_Error FM_ConfigTotalFifoSize(t_Handle h_Fm, uint32_t totalFifoSize)
{
    t_Fm *p_Fm = (t_Fm*)h_Fm;

    SANITY_CHECK_RETURN_ERROR(p_Fm, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(p_Fm->p_FmDriverParam, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR((p_Fm->guestId == NCSW_MASTER_ID), E_NOT_SUPPORTED);

    p_Fm->p_FmStateStruct->totalFifoSize = totalFifoSize;

    return E_OK;
}

t_Error FM_ConfigDmaCacheOverride(t_Handle h_Fm, e_FmDmaCacheOverride cacheOverride)
{
    t_Fm                            *p_Fm = (t_Fm*)h_Fm;
    enum fman_dma_cache_override    fsl_cache_override;

    SANITY_CHECK_RETURN_ERROR(p_Fm, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(p_Fm->p_FmDriverParam, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR((p_Fm->guestId == NCSW_MASTER_ID), E_NOT_SUPPORTED);

    FMAN_CACHE_OVERRIDE_TRANS(fsl_cache_override, cacheOverride)
    p_Fm->p_FmDriverParam->dma_cache_override = fsl_cache_override;

    return E_OK;
}

t_Error FM_ConfigDmaAidOverride(t_Handle h_Fm, bool aidOverride)
{
    t_Fm *p_Fm = (t_Fm*)h_Fm;

    SANITY_CHECK_RETURN_ERROR(p_Fm, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(p_Fm->p_FmDriverParam, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR((p_Fm->guestId == NCSW_MASTER_ID), E_NOT_SUPPORTED);

    p_Fm->p_FmDriverParam->dma_aid_override = aidOverride;

    return E_OK;
}

t_Error FM_ConfigDmaAidMode(t_Handle h_Fm, e_FmDmaAidMode aidMode)
{
    t_Fm                    *p_Fm = (t_Fm*)h_Fm;
    enum fman_dma_aid_mode  fsl_aid_mode;

    SANITY_CHECK_RETURN_ERROR(p_Fm, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(p_Fm->p_FmDriverParam, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR((p_Fm->guestId == NCSW_MASTER_ID), E_NOT_SUPPORTED);

    FMAN_AID_MODE_TRANS(fsl_aid_mode, aidMode);
    p_Fm->p_FmDriverParam->dma_aid_mode = fsl_aid_mode;

    return E_OK;
}

t_Error FM_ConfigDmaAxiDbgNumOfBeats(t_Handle h_Fm, uint8_t axiDbgNumOfBeats)
{
    t_Fm *p_Fm = (t_Fm*)h_Fm;

    SANITY_CHECK_RETURN_ERROR(p_Fm, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(p_Fm->p_FmDriverParam, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR((p_Fm->guestId == NCSW_MASTER_ID), E_NOT_SUPPORTED);

#if (DPAA_VERSION >= 11)
    RETURN_ERROR(MINOR, E_NOT_SUPPORTED, ("Not available for this FM revision!"));
#else
    p_Fm->p_FmDriverParam->dma_axi_dbg_num_of_beats = axiDbgNumOfBeats;

    return E_OK;
#endif /* (DPAA_VERSION >= 11) */
}

t_Error FM_ConfigDmaCamNumOfEntries(t_Handle h_Fm, uint8_t numOfEntries)
{
    t_Fm *p_Fm = (t_Fm*)h_Fm;

    SANITY_CHECK_RETURN_ERROR(p_Fm, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(p_Fm->p_FmDriverParam, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR((p_Fm->guestId == NCSW_MASTER_ID), E_NOT_SUPPORTED);

    p_Fm->p_FmDriverParam->dma_cam_num_of_entries = numOfEntries;

    return E_OK;
}

t_Error FM_ConfigDmaDbgCounter(t_Handle h_Fm, e_FmDmaDbgCntMode fmDmaDbgCntMode)
{
    t_Fm                        *p_Fm = (t_Fm*)h_Fm;
    enum fman_dma_dbg_cnt_mode  fsl_dma_dbg_cnt;

    SANITY_CHECK_RETURN_ERROR(p_Fm, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(p_Fm->p_FmDriverParam, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR((p_Fm->guestId == NCSW_MASTER_ID), E_NOT_SUPPORTED);

    FMAN_DMA_DBG_CNT_TRANS(fsl_dma_dbg_cnt, fmDmaDbgCntMode);
    p_Fm->p_FmDriverParam->dma_dbg_cnt_mode = fsl_dma_dbg_cnt;

    return E_OK;
}

t_Error FM_ConfigDmaStopOnBusErr(t_Handle h_Fm, bool stop)
{
    t_Fm *p_Fm = (t_Fm*)h_Fm;

    SANITY_CHECK_RETURN_ERROR(p_Fm, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(p_Fm->p_FmDriverParam, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR((p_Fm->guestId == NCSW_MASTER_ID), E_NOT_SUPPORTED);

    p_Fm->p_FmDriverParam->dma_stop_on_bus_error = stop;

    return E_OK;
}

t_Error FM_ConfigDmaEmergency(t_Handle h_Fm, t_FmDmaEmergency *p_Emergency)
{
    t_Fm                            *p_Fm = (t_Fm*)h_Fm;
    enum fman_dma_emergency_level   fsl_dma_emer;

    SANITY_CHECK_RETURN_ERROR(p_Fm, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(p_Fm->p_FmDriverParam, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR((p_Fm->guestId == NCSW_MASTER_ID), E_NOT_SUPPORTED);

    FMAN_DMA_EMER_TRANS(fsl_dma_emer, p_Emergency->emergencyLevel);
    p_Fm->p_FmDriverParam->dma_en_emergency = TRUE;
    p_Fm->p_FmDriverParam->dma_emergency_bus_select = (uint32_t)p_Emergency->emergencyBusSelect;
    p_Fm->p_FmDriverParam->dma_emergency_level = fsl_dma_emer;

    return E_OK;
}

t_Error FM_ConfigDmaEmergencySmoother(t_Handle h_Fm, uint32_t emergencyCnt)
{
    t_Fm *p_Fm = (t_Fm*)h_Fm;

    SANITY_CHECK_RETURN_ERROR(p_Fm, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(p_Fm->p_FmDriverParam, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR((p_Fm->guestId == NCSW_MASTER_ID), E_NOT_SUPPORTED);

    p_Fm->p_FmDriverParam->dma_en_emergency_smoother = TRUE;
    p_Fm->p_FmDriverParam->dma_emergency_switch_counter = emergencyCnt;

    return E_OK;
}

t_Error FM_ConfigDmaErr(t_Handle h_Fm, e_FmDmaErr dmaErr)
{
    t_Fm                *p_Fm = (t_Fm*)h_Fm;
    enum fman_dma_err   fsl_dma_err;

    SANITY_CHECK_RETURN_ERROR(p_Fm, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(p_Fm->p_FmDriverParam, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR((p_Fm->guestId == NCSW_MASTER_ID), E_NOT_SUPPORTED);

    FMAN_DMA_ERR_TRANS(fsl_dma_err, dmaErr);
    p_Fm->p_FmDriverParam->dma_err = fsl_dma_err;

    return E_OK;
}

t_Error FM_ConfigCatastrophicErr(t_Handle h_Fm, e_FmCatastrophicErr catastrophicErr)
{
    t_Fm                        *p_Fm = (t_Fm*)h_Fm;
    enum fman_catastrophic_err  fsl_catastrophic_err;

    SANITY_CHECK_RETURN_ERROR(p_Fm, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(p_Fm->p_FmDriverParam, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR((p_Fm->guestId == NCSW_MASTER_ID), E_NOT_SUPPORTED);

    FMAN_CATASTROPHIC_ERR_TRANS(fsl_catastrophic_err, catastrophicErr);
    p_Fm->p_FmDriverParam->catastrophic_err = fsl_catastrophic_err;

    return E_OK;
}

t_Error FM_ConfigEnableMuramTestMode(t_Handle h_Fm)
{
    t_Fm *p_Fm = (t_Fm*)h_Fm;

    SANITY_CHECK_RETURN_ERROR(p_Fm, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(p_Fm->p_FmDriverParam, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR((p_Fm->guestId == NCSW_MASTER_ID), E_NOT_SUPPORTED);

    if (p_Fm->p_FmStateStruct->revInfo.majorRev >= 6)
        RETURN_ERROR(MINOR, E_NOT_SUPPORTED, ("Not available for this FM revision!"));

    p_Fm->p_FmDriverParam->en_muram_test_mode = TRUE;

    return E_OK;
}

t_Error FM_ConfigEnableIramTestMode(t_Handle h_Fm)
{
    t_Fm *p_Fm = (t_Fm*)h_Fm;

    SANITY_CHECK_RETURN_ERROR(p_Fm, E_INVALID_HANDLE );
    SANITY_CHECK_RETURN_ERROR(p_Fm->p_FmDriverParam, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR((p_Fm->guestId == NCSW_MASTER_ID), E_NOT_SUPPORTED);

    if (p_Fm->p_FmStateStruct->revInfo.majorRev >= 6)
        RETURN_ERROR(MINOR, E_NOT_SUPPORTED, ("Not available for this FM revision!"));

    p_Fm->p_FmDriverParam->en_iram_test_mode = TRUE;

    return E_OK;
}

t_Error FM_ConfigHaltOnExternalActivation(t_Handle h_Fm, bool enable)
{
    t_Fm *p_Fm = (t_Fm*)h_Fm;

    SANITY_CHECK_RETURN_ERROR(p_Fm, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(p_Fm->p_FmDriverParam, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR((p_Fm->guestId == NCSW_MASTER_ID), E_NOT_SUPPORTED);

    p_Fm->p_FmDriverParam->halt_on_external_activ = enable;

    return E_OK;
}

t_Error FM_ConfigHaltOnUnrecoverableEccError(t_Handle h_Fm, bool enable)
{
    t_Fm *p_Fm = (t_Fm*)h_Fm;

    SANITY_CHECK_RETURN_ERROR(p_Fm, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(p_Fm->p_FmDriverParam, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR((p_Fm->guestId == NCSW_MASTER_ID), E_NOT_SUPPORTED);

    if (p_Fm->p_FmStateStruct->revInfo.majorRev >= 6)
        RETURN_ERROR(MINOR, E_NOT_SUPPORTED, ("Not available for this FM revision!"));

    p_Fm->p_FmDriverParam->halt_on_unrecov_ecc_err = enable;

    return E_OK;
}

t_Error FM_ConfigException(t_Handle h_Fm, e_FmExceptions exception, bool enable)
{
    t_Fm                *p_Fm = (t_Fm*)h_Fm;
    uint32_t            bitMask = 0;

    SANITY_CHECK_RETURN_ERROR(p_Fm, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(p_Fm->p_FmDriverParam, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR((p_Fm->guestId == NCSW_MASTER_ID), E_NOT_SUPPORTED);

    GET_EXCEPTION_FLAG(bitMask, exception);
    if (bitMask)
    {
        if (enable)
            p_Fm->userSetExceptions |= bitMask;
        else
            p_Fm->p_FmStateStruct->exceptions &= ~bitMask;
    }
    else
        RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("Undefined exception"));

    return E_OK;
}

t_Error FM_ConfigExternalEccRamsEnable(t_Handle h_Fm, bool enable)
{
    t_Fm        *p_Fm = (t_Fm*)h_Fm;

    SANITY_CHECK_RETURN_ERROR(p_Fm, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(p_Fm->p_FmDriverParam, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR((p_Fm->guestId == NCSW_MASTER_ID), E_NOT_SUPPORTED);

    p_Fm->p_FmDriverParam->external_ecc_rams_enable = enable;

    return E_OK;
}

t_Error FM_ConfigTnumAgingPeriod(t_Handle h_Fm, uint16_t tnumAgingPeriod)
{
    t_Fm             *p_Fm = (t_Fm*)h_Fm;

    SANITY_CHECK_RETURN_ERROR(p_Fm, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(p_Fm->p_FmDriverParam, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR((p_Fm->guestId == NCSW_MASTER_ID), E_NOT_SUPPORTED);

    p_Fm->p_FmDriverParam->tnum_aging_period = tnumAgingPeriod;
    p_Fm->tnumAgingPeriod = p_Fm->p_FmDriverParam->tnum_aging_period;

    return E_OK;
}

/****************************************************/
/*       Hidden-DEBUG Only API                      */
/****************************************************/

t_Error FM_ConfigThresholds(t_Handle h_Fm, t_FmThresholds *p_FmThresholds)
{
    t_Fm *p_Fm = (t_Fm*)h_Fm;

    SANITY_CHECK_RETURN_ERROR(p_Fm, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(p_Fm->p_FmDriverParam, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR((p_Fm->guestId == NCSW_MASTER_ID), E_NOT_SUPPORTED);

    p_Fm->p_FmDriverParam->disp_limit_tsh  = p_FmThresholds->dispLimit;
    p_Fm->p_FmDriverParam->prs_disp_tsh    = p_FmThresholds->prsDispTh;
    p_Fm->p_FmDriverParam->plcr_disp_tsh   = p_FmThresholds->plcrDispTh;
    p_Fm->p_FmDriverParam->kg_disp_tsh     = p_FmThresholds->kgDispTh;
    p_Fm->p_FmDriverParam->bmi_disp_tsh    = p_FmThresholds->bmiDispTh;
    p_Fm->p_FmDriverParam->qmi_enq_disp_tsh = p_FmThresholds->qmiEnqDispTh;
    p_Fm->p_FmDriverParam->qmi_deq_disp_tsh = p_FmThresholds->qmiDeqDispTh;
    p_Fm->p_FmDriverParam->fm_ctl1_disp_tsh = p_FmThresholds->fmCtl1DispTh;
    p_Fm->p_FmDriverParam->fm_ctl2_disp_tsh = p_FmThresholds->fmCtl2DispTh;

    return E_OK;
}

t_Error FM_ConfigDmaSosEmergencyThreshold(t_Handle h_Fm, uint32_t dmaSosEmergency)
{
    t_Fm *p_Fm = (t_Fm*)h_Fm;

    SANITY_CHECK_RETURN_ERROR(p_Fm, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(p_Fm->p_FmDriverParam, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR((p_Fm->guestId == NCSW_MASTER_ID), E_NOT_SUPPORTED);

    p_Fm->p_FmDriverParam->dma_sos_emergency = dmaSosEmergency;

    return E_OK;
}

t_Error FM_ConfigDmaWriteBufThresholds(t_Handle h_Fm, t_FmDmaThresholds *p_FmDmaThresholds)

{
    t_Fm *p_Fm = (t_Fm*)h_Fm;

    SANITY_CHECK_RETURN_ERROR(p_Fm, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(p_Fm->p_FmDriverParam, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR((p_Fm->guestId == NCSW_MASTER_ID), E_NOT_SUPPORTED);

#if (DPAA_VERSION >= 11)
    RETURN_ERROR(MINOR, E_NOT_SUPPORTED, ("Not available for this FM revision!"));
#else
    p_Fm->p_FmDriverParam->dma_write_buf_tsh_asrt_emer = p_FmDmaThresholds->assertEmergency;
    p_Fm->p_FmDriverParam->dma_write_buf_tsh_clr_emer  = p_FmDmaThresholds->clearEmergency;

    return E_OK;
#endif
}

t_Error FM_ConfigDmaCommQThresholds(t_Handle h_Fm, t_FmDmaThresholds *p_FmDmaThresholds)
{
    t_Fm *p_Fm = (t_Fm*)h_Fm;

    SANITY_CHECK_RETURN_ERROR(p_Fm, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(p_Fm->p_FmDriverParam, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR((p_Fm->guestId == NCSW_MASTER_ID), E_NOT_SUPPORTED);

    p_Fm->p_FmDriverParam->dma_comm_qtsh_asrt_emer    = p_FmDmaThresholds->assertEmergency;
    p_Fm->p_FmDriverParam->dma_comm_qtsh_clr_emer     = p_FmDmaThresholds->clearEmergency;

    return E_OK;
}

t_Error FM_ConfigDmaReadBufThresholds(t_Handle h_Fm, t_FmDmaThresholds *p_FmDmaThresholds)
{
    t_Fm *p_Fm = (t_Fm*)h_Fm;

    SANITY_CHECK_RETURN_ERROR(p_Fm, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(p_Fm->p_FmDriverParam, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR((p_Fm->guestId == NCSW_MASTER_ID), E_NOT_SUPPORTED);

#if (DPAA_VERSION >= 11)
    RETURN_ERROR(MINOR, E_NOT_SUPPORTED, ("Not available for this FM revision!"));
#else
    p_Fm->p_FmDriverParam->dma_read_buf_tsh_clr_emer   = p_FmDmaThresholds->clearEmergency;
    p_Fm->p_FmDriverParam->dma_read_buf_tsh_asrt_emer  = p_FmDmaThresholds->assertEmergency;

    return E_OK;
#endif
}

t_Error FM_ConfigDmaWatchdog(t_Handle h_Fm, uint32_t watchdogValue)
{
    t_Fm                *p_Fm = (t_Fm*)h_Fm;

    SANITY_CHECK_RETURN_ERROR(p_Fm, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(p_Fm->p_FmDriverParam, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR((p_Fm->guestId == NCSW_MASTER_ID), E_NOT_SUPPORTED);

    p_Fm->p_FmDriverParam->dma_watchdog = watchdogValue;

    return E_OK;
}

t_Error FM_ConfigEnableCounters(t_Handle h_Fm)
{
    t_Fm                *p_Fm = (t_Fm*)h_Fm;

    SANITY_CHECK_RETURN_ERROR(p_Fm, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(p_Fm->p_FmDriverParam, E_INVALID_HANDLE);
UNUSED(p_Fm);

    return E_OK;
}

t_Error FmGetSetParams(t_Handle h_Fm, t_FmGetSetParams *p_Params)
{
	t_Fm* p_Fm = (t_Fm*)h_Fm;
	if (p_Params->setParams.type & UPDATE_FM_CLD)
	{
		WRITE_UINT32(p_Fm->p_FmFpmRegs->fm_cld, GET_UINT32(
				p_Fm->p_FmFpmRegs->fm_cld) | 0x00000800);
	}
	if (p_Params->setParams.type & CLEAR_IRAM_READY)
	{
	    t_FMIramRegs *p_Iram = (t_FMIramRegs *)UINT_TO_PTR(p_Fm->baseAddr + FM_MM_IMEM);
		WRITE_UINT32(p_Iram->iready,GET_UINT32(p_Iram->iready) & ~IRAM_READY);
	}
	if (p_Params->setParams.type & UPDATE_FPM_EXTC)
		WRITE_UINT32(p_Fm->p_FmFpmRegs->fmfp_extc,0x80000000);
	if (p_Params->setParams.type & UPDATE_FPM_EXTC_CLEAR)
		WRITE_UINT32(p_Fm->p_FmFpmRegs->fmfp_extc,0x00800000);
	if (p_Params->setParams.type & UPDATE_FPM_BRKC_SLP)
	{	
		if (p_Params->setParams.sleep)
			WRITE_UINT32(p_Fm->p_FmFpmRegs->fmfp_brkc, GET_UINT32(
				p_Fm->p_FmFpmRegs->fmfp_brkc) | FPM_BRKC_SLP);
		else
			WRITE_UINT32(p_Fm->p_FmFpmRegs->fmfp_brkc, GET_UINT32(
				p_Fm->p_FmFpmRegs->fmfp_brkc) & ~FPM_BRKC_SLP);
	}
	if (p_Params->getParams.type & GET_FM_CLD)
		p_Params->getParams.fm_cld = GET_UINT32(p_Fm->p_FmFpmRegs->fm_cld);
	if (p_Params->getParams.type & GET_FMQM_GS)
		p_Params->getParams.fmqm_gs = GET_UINT32(p_Fm->p_FmQmiRegs->fmqm_gs);
	if (p_Params->getParams.type & GET_FM_NPI)
		p_Params->getParams.fm_npi = GET_UINT32(p_Fm->p_FmFpmRegs->fm_npi);
	if (p_Params->getParams.type & GET_FMFP_EXTC)
		p_Params->getParams.fmfp_extc = GET_UINT32(p_Fm->p_FmFpmRegs->fmfp_extc);
	return E_OK;
}


/****************************************************/
/*       API Run-time Control uint functions        */
/****************************************************/
void FM_EventIsr(t_Handle h_Fm)
{
#define FM_M_CALL_1G_MAC_ISR(_id)    \
    {                                \
        if (p_Fm->guestId != p_Fm->intrMng[(e_FmInterModuleEvent)(e_FM_EV_1G_MAC0+_id)].guestId)    \
            SendIpcIsr(p_Fm, (e_FmInterModuleEvent)(e_FM_EV_1G_MAC0+_id), pending);                 \
        else                                                                                        \
            p_Fm->intrMng[(e_FmInterModuleEvent)(e_FM_EV_1G_MAC0+_id)].f_Isr(p_Fm->intrMng[(e_FmInterModuleEvent)(e_FM_EV_1G_MAC0+_id)].h_SrcHandle);\
    }
#define FM_M_CALL_10G_MAC_ISR(_id)   \
    {                                \
        if (p_Fm->guestId != p_Fm->intrMng[(e_FmInterModuleEvent)(e_FM_EV_10G_MAC0+_id)].guestId)    \
            SendIpcIsr(p_Fm, (e_FmInterModuleEvent)(e_FM_EV_10G_MAC0+_id), pending);                 \
        else                                                                                         \
            p_Fm->intrMng[(e_FmInterModuleEvent)(e_FM_EV_10G_MAC0+_id)].f_Isr(p_Fm->intrMng[(e_FmInterModuleEvent)(e_FM_EV_10G_MAC0+_id)].h_SrcHandle);\
    }
    t_Fm                    *p_Fm = (t_Fm*)h_Fm;
    uint32_t                pending, event;
    struct fman_fpm_regs *fpm_rg;

    SANITY_CHECK_RETURN(p_Fm, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN(!p_Fm->p_FmDriverParam, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN((p_Fm->guestId == NCSW_MASTER_ID), E_NOT_SUPPORTED);

    fpm_rg = p_Fm->p_FmFpmRegs;

    /* normal interrupts */
    pending = fman_get_normal_pending(fpm_rg);
    if (!pending)
        return;
    if (pending & INTR_EN_WAKEUP) // this is a wake up from sleep interrupt
    {
        t_FmGetSetParams fmGetSetParams;
        memset(&fmGetSetParams, 0, sizeof (t_FmGetSetParams));
        fmGetSetParams.setParams.type = UPDATE_FPM_BRKC_SLP;
        fmGetSetParams.setParams.sleep = 0;
        FmGetSetParams(h_Fm, &fmGetSetParams);
    }
    if (pending & INTR_EN_QMI)
        QmiEvent(p_Fm);
    if (pending & INTR_EN_PRS)
        p_Fm->intrMng[e_FM_EV_PRS].f_Isr(p_Fm->intrMng[e_FM_EV_PRS].h_SrcHandle);
    if (pending & INTR_EN_PLCR)
        p_Fm->intrMng[e_FM_EV_PLCR].f_Isr(p_Fm->intrMng[e_FM_EV_PLCR].h_SrcHandle);
    if (pending & INTR_EN_TMR)
            p_Fm->intrMng[e_FM_EV_TMR].f_Isr(p_Fm->intrMng[e_FM_EV_TMR].h_SrcHandle);

    /* MAC events may belong to different partitions */
    if (pending & INTR_EN_1G_MAC0)
        FM_M_CALL_1G_MAC_ISR(0);
    if (pending & INTR_EN_1G_MAC1)
        FM_M_CALL_1G_MAC_ISR(1);
    if (pending & INTR_EN_1G_MAC2)
        FM_M_CALL_1G_MAC_ISR(2);
    if (pending & INTR_EN_1G_MAC3)
        FM_M_CALL_1G_MAC_ISR(3);
    if (pending & INTR_EN_1G_MAC4)
        FM_M_CALL_1G_MAC_ISR(4);
    if (pending & INTR_EN_1G_MAC5)
        FM_M_CALL_1G_MAC_ISR(5);
    if (pending & INTR_EN_1G_MAC6)
        FM_M_CALL_1G_MAC_ISR(6);
    if (pending & INTR_EN_1G_MAC7)
        FM_M_CALL_1G_MAC_ISR(7);
    if (pending & INTR_EN_10G_MAC0)
        FM_M_CALL_10G_MAC_ISR(0);
    if (pending & INTR_EN_10G_MAC1)
        FM_M_CALL_10G_MAC_ISR(1);

    /* IM port events may belong to different partitions */
    if (pending & INTR_EN_REV0)
    {
        event = fman_get_controller_event(fpm_rg, 0);
        if (p_Fm->guestId != p_Fm->intrMng[e_FM_EV_FMAN_CTRL_0].guestId)
            /*TODO IPC ISR For Fman Ctrl */
            ASSERT_COND(0);
            /* SendIpcIsr(p_Fm, e_FM_EV_FMAN_CTRL_0, pending); */
        else
            p_Fm->fmanCtrlIntr[0].f_Isr(p_Fm->fmanCtrlIntr[0].h_SrcHandle, event);

    }
    if (pending & INTR_EN_REV1)
    {
        event = fman_get_controller_event(fpm_rg, 1);
        if (p_Fm->guestId != p_Fm->intrMng[e_FM_EV_FMAN_CTRL_1].guestId)
            /*TODO IPC ISR For Fman Ctrl */
            ASSERT_COND(0);
            /* SendIpcIsr(p_Fm, e_FM_EV_FMAN_CTRL_1, pending); */
        else
            p_Fm->fmanCtrlIntr[1].f_Isr(p_Fm->fmanCtrlIntr[1].h_SrcHandle, event);
    }
    if (pending & INTR_EN_REV2)
    {
        event = fman_get_controller_event(fpm_rg, 2);
        if (p_Fm->guestId != p_Fm->intrMng[e_FM_EV_FMAN_CTRL_2].guestId)
            /*TODO IPC ISR For Fman Ctrl */
            ASSERT_COND(0);
            /* SendIpcIsr(p_Fm, e_FM_EV_FMAN_CTRL_2, pending); */
        else
           p_Fm->fmanCtrlIntr[2].f_Isr(p_Fm->fmanCtrlIntr[2].h_SrcHandle, event);
    }
    if (pending & INTR_EN_REV3)
    {
        event = fman_get_controller_event(fpm_rg, 3);
        if (p_Fm->guestId != p_Fm->intrMng[e_FM_EV_FMAN_CTRL_3].guestId)
            /*TODO IPC ISR For Fman Ctrl */
            ASSERT_COND(0);
            /* SendIpcIsr(p_Fm, e_FM_EV_FMAN_CTRL_2, pendin3); */
        else
            p_Fm->fmanCtrlIntr[3].f_Isr(p_Fm->fmanCtrlIntr[3].h_SrcHandle, event);
    }
#ifdef FM_MACSEC_SUPPORT
    if (pending & INTR_EN_MACSEC_MAC0)
    {
       if (p_Fm->guestId != p_Fm->intrMng[e_FM_EV_MACSEC_MAC0].guestId)
            SendIpcIsr(p_Fm, e_FM_EV_MACSEC_MAC0, pending);
        else
            p_Fm->intrMng[e_FM_EV_MACSEC_MAC0].f_Isr(p_Fm->intrMng[e_FM_EV_MACSEC_MAC0].h_SrcHandle);
    }
#endif /* FM_MACSEC_SUPPORT */
}

t_Error FM_ErrorIsr(t_Handle h_Fm)
{
#define FM_M_CALL_1G_MAC_ERR_ISR(_id)   \
    {                                   \
       if (p_Fm->guestId != p_Fm->intrMng[(e_FmInterModuleEvent)(e_FM_EV_ERR_1G_MAC0+_id)].guestId) \
            SendIpcIsr(p_Fm, (e_FmInterModuleEvent)(e_FM_EV_ERR_1G_MAC0+_id), pending);             \
       else                                                                                         \
            p_Fm->intrMng[(e_FmInterModuleEvent)(e_FM_EV_ERR_1G_MAC0+_id)].f_Isr(p_Fm->intrMng[(e_FmInterModuleEvent)(e_FM_EV_ERR_1G_MAC0+_id)].h_SrcHandle);\
    }
#define FM_M_CALL_10G_MAC_ERR_ISR(_id)   \
    {                                    \
       if (p_Fm->guestId != p_Fm->intrMng[(e_FmInterModuleEvent)(e_FM_EV_ERR_10G_MAC0+_id)].guestId) \
            SendIpcIsr(p_Fm, (e_FmInterModuleEvent)(e_FM_EV_ERR_10G_MAC0+_id), pending);             \
       else                                                                                          \
            p_Fm->intrMng[(e_FmInterModuleEvent)(e_FM_EV_ERR_10G_MAC0+_id)].f_Isr(p_Fm->intrMng[(e_FmInterModuleEvent)(e_FM_EV_ERR_10G_MAC0+_id)].h_SrcHandle);\
    }
    t_Fm                    *p_Fm = (t_Fm*)h_Fm;
    uint32_t                pending;
    struct fman_fpm_regs *fpm_rg;

    SANITY_CHECK_RETURN_ERROR(h_Fm, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(!p_Fm->p_FmDriverParam, E_INVALID_STATE);
    SANITY_CHECK_RETURN_ERROR((p_Fm->guestId == NCSW_MASTER_ID), E_NOT_SUPPORTED);

    fpm_rg = p_Fm->p_FmFpmRegs;

    /* error interrupts */
    pending = fman_get_fpm_error_interrupts(fpm_rg);
    if (!pending)
        return ERROR_CODE(E_EMPTY);

    if (pending & ERR_INTR_EN_BMI)
        BmiErrEvent(p_Fm);
    if (pending & ERR_INTR_EN_QMI)
        QmiErrEvent(p_Fm);
    if (pending & ERR_INTR_EN_FPM)
        FpmErrEvent(p_Fm);
    if (pending & ERR_INTR_EN_DMA)
        DmaErrEvent(p_Fm);
    if (pending & ERR_INTR_EN_IRAM)
        IramErrIntr(p_Fm);
    if (pending & ERR_INTR_EN_MURAM)
        MuramErrIntr(p_Fm);
    if (pending & ERR_INTR_EN_PRS)
        p_Fm->intrMng[e_FM_EV_ERR_PRS].f_Isr(p_Fm->intrMng[e_FM_EV_ERR_PRS].h_SrcHandle);
    if (pending & ERR_INTR_EN_PLCR)
        p_Fm->intrMng[e_FM_EV_ERR_PLCR].f_Isr(p_Fm->intrMng[e_FM_EV_ERR_PLCR].h_SrcHandle);
    if (pending & ERR_INTR_EN_KG)
        p_Fm->intrMng[e_FM_EV_ERR_KG].f_Isr(p_Fm->intrMng[e_FM_EV_ERR_KG].h_SrcHandle);

    /* MAC events may belong to different partitions */
    if (pending & ERR_INTR_EN_1G_MAC0)
        FM_M_CALL_1G_MAC_ERR_ISR(0);
    if (pending & ERR_INTR_EN_1G_MAC1)
        FM_M_CALL_1G_MAC_ERR_ISR(1);
    if (pending & ERR_INTR_EN_1G_MAC2)
        FM_M_CALL_1G_MAC_ERR_ISR(2);
    if (pending & ERR_INTR_EN_1G_MAC3)
        FM_M_CALL_1G_MAC_ERR_ISR(3);
    if (pending & ERR_INTR_EN_1G_MAC4)
        FM_M_CALL_1G_MAC_ERR_ISR(4);
    if (pending & ERR_INTR_EN_1G_MAC5)
        FM_M_CALL_1G_MAC_ERR_ISR(5);
    if (pending & ERR_INTR_EN_1G_MAC6)
        FM_M_CALL_1G_MAC_ERR_ISR(6);
    if (pending & ERR_INTR_EN_1G_MAC7)
        FM_M_CALL_1G_MAC_ERR_ISR(7);
    if (pending & ERR_INTR_EN_10G_MAC0)
        FM_M_CALL_10G_MAC_ERR_ISR(0);
    if (pending & ERR_INTR_EN_10G_MAC1)
        FM_M_CALL_10G_MAC_ERR_ISR(1);

#ifdef FM_MACSEC_SUPPORT
    if (pending & ERR_INTR_EN_MACSEC_MAC0)
    {
       if (p_Fm->guestId != p_Fm->intrMng[e_FM_EV_ERR_MACSEC_MAC0].guestId)
            SendIpcIsr(p_Fm, e_FM_EV_ERR_MACSEC_MAC0, pending);
        else
            p_Fm->intrMng[e_FM_EV_ERR_MACSEC_MAC0].f_Isr(p_Fm->intrMng[e_FM_EV_ERR_MACSEC_MAC0].h_SrcHandle);
    }
#endif /* FM_MACSEC_SUPPORT */

    return E_OK;
}

t_Error FM_SetPortsBandwidth(t_Handle h_Fm, t_FmPortsBandwidthParams *p_PortsBandwidth)
{
    t_Fm        *p_Fm = (t_Fm*)h_Fm;
    int         i;
    uint8_t     sum;
    uint8_t     hardwarePortId;
    uint8_t     weights[64];
    uint8_t     weight, maxPercent = 0;
    struct fman_bmi_regs *bmi_rg;

    SANITY_CHECK_RETURN_ERROR(p_Fm, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(!p_Fm->p_FmDriverParam, E_INVALID_STATE);
    SANITY_CHECK_RETURN_ERROR((p_Fm->guestId == NCSW_MASTER_ID), E_NOT_SUPPORTED);

    bmi_rg = p_Fm->p_FmBmiRegs;

    memset(weights, 0, (sizeof(uint8_t) * 64));

    /* check that all ports add up to 100% */
    sum = 0;
    for (i=0; i < p_PortsBandwidth->numOfPorts; i++)
        sum +=p_PortsBandwidth->portsBandwidths[i].bandwidth;
    if (sum != 100)
        RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("Sum of ports bandwidth differ from 100%"));

    /* find highest percent */
    for (i=0; i < p_PortsBandwidth->numOfPorts; i++)
    {
        if (p_PortsBandwidth->portsBandwidths[i].bandwidth > maxPercent)
            maxPercent = p_PortsBandwidth->portsBandwidths[i].bandwidth;
    }

    ASSERT_COND(maxPercent > 0); /* guaranteed by sum = 100 */

    /* calculate weight for each port */
    for (i=0; i < p_PortsBandwidth->numOfPorts; i++)
    {
        weight = (uint8_t)((p_PortsBandwidth->portsBandwidths[i].bandwidth * PORT_MAX_WEIGHT ) / maxPercent);
        /* we want even division between 1-to-PORT_MAX_WEIGHT. so if exact division
           is not reached, we round up so that:
           0 until maxPercent/PORT_MAX_WEIGHT get "1"
           maxPercent/PORT_MAX_WEIGHT+1 until (maxPercent/PORT_MAX_WEIGHT)*2 get "2"
           ...
           maxPercent - maxPercent/PORT_MAX_WEIGHT until maxPercent get "PORT_MAX_WEIGHT: */
        if ((uint8_t)((p_PortsBandwidth->portsBandwidths[i].bandwidth * PORT_MAX_WEIGHT ) % maxPercent))
            weight++;

        /* find the location of this port within the register */
        hardwarePortId =
            SwPortIdToHwPortId(p_PortsBandwidth->portsBandwidths[i].type,
                               p_PortsBandwidth->portsBandwidths[i].relativePortId,
                               p_Fm->p_FmStateStruct->revInfo.majorRev,
                               p_Fm->p_FmStateStruct->revInfo.minorRev);

        ASSERT_COND(IN_RANGE(1, hardwarePortId, 63));
        weights[hardwarePortId] = weight;
    }

    fman_set_ports_bandwidth(bmi_rg, weights);

    return E_OK;
}

t_Error FM_EnableRamsEcc(t_Handle h_Fm)
{
    t_Fm        *p_Fm = (t_Fm*)h_Fm;
    struct fman_fpm_regs *fpm_rg;

    SANITY_CHECK_RETURN_ERROR(p_Fm, E_INVALID_HANDLE);

    fpm_rg = p_Fm->p_FmFpmRegs;

    if (p_Fm->guestId != NCSW_MASTER_ID)
    {
        t_FmIpcMsg      msg;
        t_Error         err;

        memset(&msg, 0, sizeof(msg));
        msg.msgId = FM_ENABLE_RAM_ECC;
        err = XX_IpcSendMessage(p_Fm->h_IpcSessions[0],
                                (uint8_t*)&msg,
                                sizeof(msg.msgId),
                                NULL,
                                NULL,
                                NULL,
                                NULL);
        if (err != E_OK)
            RETURN_ERROR(MINOR, err, NO_MSG);
        return E_OK;
    }

    if (!p_Fm->p_FmStateStruct->internalCall)
        p_Fm->p_FmStateStruct->explicitEnable = TRUE;
    p_Fm->p_FmStateStruct->internalCall = FALSE;

    if (p_Fm->p_FmStateStruct->ramsEccEnable)
        return E_OK;
    else
    {
        fman_enable_rams_ecc(fpm_rg);
        p_Fm->p_FmStateStruct->ramsEccEnable = TRUE;
    }

    return E_OK;
}

t_Error FM_DisableRamsEcc(t_Handle h_Fm)
{
    t_Fm        *p_Fm = (t_Fm*)h_Fm;
    bool        explicitDisable = FALSE;
    struct fman_fpm_regs *fpm_rg;

    SANITY_CHECK_RETURN_ERROR(p_Fm, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(!p_Fm->p_FmDriverParam, E_INVALID_HANDLE);

    fpm_rg = p_Fm->p_FmFpmRegs;

    if (p_Fm->guestId != NCSW_MASTER_ID)
    {
        t_Error             err;
        t_FmIpcMsg          msg;

        memset(&msg, 0, sizeof(msg));
        msg.msgId = FM_DISABLE_RAM_ECC;
        if ((err = XX_IpcSendMessage(p_Fm->h_IpcSessions[0],
                                     (uint8_t*)&msg,
                                     sizeof(msg.msgId),
                                     NULL,
                                     NULL,
                                     NULL,
                                     NULL)) != E_OK)
            RETURN_ERROR(MINOR, err, NO_MSG);
        return E_OK;
    }

    if (!p_Fm->p_FmStateStruct->internalCall)
        explicitDisable = TRUE;
    p_Fm->p_FmStateStruct->internalCall = FALSE;

    /* if rams are already disabled, or if rams were explicitly enabled and are
       currently called indirectly (not explicitly), ignore this call. */
    if (!p_Fm->p_FmStateStruct->ramsEccEnable ||
        (p_Fm->p_FmStateStruct->explicitEnable && !explicitDisable))
        return E_OK;
    else
    {
        if (p_Fm->p_FmStateStruct->explicitEnable)
            /* This is the case were both explicit are TRUE.
               Turn off this flag for cases were following ramsEnable
               routines are called */
            p_Fm->p_FmStateStruct->explicitEnable = FALSE;

        fman_enable_rams_ecc(fpm_rg);
        p_Fm->p_FmStateStruct->ramsEccEnable = FALSE;
    }

    return E_OK;
}

t_Error FM_SetException(t_Handle h_Fm, e_FmExceptions exception, bool enable)
{
    t_Fm                *p_Fm = (t_Fm*)h_Fm;
    uint32_t            bitMask = 0;
    enum fman_exceptions fslException;
    struct fman_rg       fman_rg;

    SANITY_CHECK_RETURN_ERROR(p_Fm, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(!p_Fm->p_FmDriverParam, E_INVALID_STATE);

    fman_rg.bmi_rg = p_Fm->p_FmBmiRegs;
    fman_rg.qmi_rg = p_Fm->p_FmQmiRegs;
    fman_rg.fpm_rg = p_Fm->p_FmFpmRegs;
    fman_rg.dma_rg = p_Fm->p_FmDmaRegs;

    GET_EXCEPTION_FLAG(bitMask, exception);
    if (bitMask)
    {
        if (enable)
            p_Fm->p_FmStateStruct->exceptions |= bitMask;
        else
            p_Fm->p_FmStateStruct->exceptions &= ~bitMask;

        fslException = FmanExceptionTrans(exception);

        return (t_Error)fman_set_exception(&fman_rg,
                                  fslException,
                                  enable);
    }
    else
        RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("Undefined exception"));

    return E_OK;
}

t_Error FM_GetRevision(t_Handle h_Fm, t_FmRevisionInfo *p_FmRevisionInfo)
{
    t_Fm *p_Fm = (t_Fm*)h_Fm;

    p_FmRevisionInfo->majorRev = p_Fm->p_FmStateStruct->revInfo.majorRev;
    p_FmRevisionInfo->minorRev = p_Fm->p_FmStateStruct->revInfo.minorRev;

    return E_OK;
}

t_Error FM_GetFmanCtrlCodeRevision(t_Handle h_Fm, t_FmCtrlCodeRevisionInfo *p_RevisionInfo)
{
    t_Fm                            *p_Fm = (t_Fm*)h_Fm;
    t_FMIramRegs                    *p_Iram;
    uint32_t                        revInfo;

    SANITY_CHECK_RETURN_ERROR(p_Fm, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(p_RevisionInfo, E_NULL_POINTER);

    if ((p_Fm->guestId != NCSW_MASTER_ID) &&
        p_Fm->h_IpcSessions[0])
    {
        t_Error                         err;
        t_FmIpcMsg                      msg;
        t_FmIpcReply                    reply;
        uint32_t                        replyLength;
        t_FmIpcFmanCtrlCodeRevisionInfo ipcRevInfo;

        memset(&msg, 0, sizeof(msg));
        memset(&reply, 0, sizeof(reply));
        msg.msgId = FM_GET_FMAN_CTRL_CODE_REV;
        replyLength = sizeof(uint32_t) + sizeof(t_FmCtrlCodeRevisionInfo);
        if ((err = XX_IpcSendMessage(p_Fm->h_IpcSessions[0],
                                     (uint8_t*)&msg,
                                     sizeof(msg.msgId),
                                     (uint8_t*)&reply,
                                     &replyLength,
                                     NULL,
                                     NULL)) != E_OK)
            RETURN_ERROR(MINOR, err, NO_MSG);
        if (replyLength != (sizeof(uint32_t) + sizeof(t_FmCtrlCodeRevisionInfo)))
            RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("IPC reply length mismatch"));
        memcpy((uint8_t*)&ipcRevInfo, reply.replyBody, sizeof(t_FmCtrlCodeRevisionInfo));
        p_RevisionInfo->packageRev = ipcRevInfo.packageRev;
        p_RevisionInfo->majorRev = ipcRevInfo.majorRev;
        p_RevisionInfo->minorRev = ipcRevInfo.minorRev;
        return (t_Error)(reply.error);
    }
    else if (p_Fm->guestId != NCSW_MASTER_ID)
        RETURN_ERROR(MINOR, E_NOT_SUPPORTED,
                     ("running in guest-mode without IPC!"));

    p_Iram = (t_FMIramRegs *)UINT_TO_PTR(p_Fm->baseAddr + FM_MM_IMEM);
    WRITE_UINT32(p_Iram->iadd, 0x4);
    while (GET_UINT32(p_Iram->iadd) != 0x4) ;
    revInfo = GET_UINT32(p_Iram->idata);
    p_RevisionInfo->packageRev = (uint16_t)((revInfo & 0xFFFF0000) >> 16);
    p_RevisionInfo->majorRev = (uint8_t)((revInfo & 0x0000FF00) >> 8);
    p_RevisionInfo->minorRev = (uint8_t)(revInfo & 0x000000FF);

    return E_OK;
}

uint32_t FM_GetCounter(t_Handle h_Fm, e_FmCounters counter)
{
    t_Fm        *p_Fm = (t_Fm*)h_Fm;
    t_Error     err;
    uint32_t    counterValue;
    struct fman_rg       fman_rg;
    enum fman_counters fsl_counter;

    SANITY_CHECK_RETURN_VALUE(p_Fm, E_INVALID_HANDLE, 0);
    SANITY_CHECK_RETURN_VALUE(!p_Fm->p_FmDriverParam, E_INVALID_STATE, 0);

    fman_rg.bmi_rg = p_Fm->p_FmBmiRegs;
    fman_rg.qmi_rg = p_Fm->p_FmQmiRegs;
    fman_rg.fpm_rg = p_Fm->p_FmFpmRegs;
    fman_rg.dma_rg = p_Fm->p_FmDmaRegs;

    if ((p_Fm->guestId != NCSW_MASTER_ID) &&
        !p_Fm->baseAddr &&
        p_Fm->h_IpcSessions[0])
    {
        t_FmIpcMsg          msg;
        t_FmIpcReply        reply;
        uint32_t            replyLength, outCounter;

        memset(&msg, 0, sizeof(msg));
        memset(&reply, 0, sizeof(reply));
        msg.msgId = FM_GET_COUNTER;
        memcpy(msg.msgBody, (uint8_t *)&counter, sizeof(uint32_t));
        replyLength = sizeof(uint32_t) + sizeof(uint32_t);
        err = XX_IpcSendMessage(p_Fm->h_IpcSessions[0],
                                     (uint8_t*)&msg,
                                     sizeof(msg.msgId) +sizeof(counterValue),
                                     (uint8_t*)&reply,
                                     &replyLength,
                                     NULL,
                                     NULL);
        if (err != E_OK)
        {
            REPORT_ERROR(MAJOR, err, NO_MSG);
            return 0;
        }
        if (replyLength != (sizeof(uint32_t) + sizeof(uint32_t)))
        {
            REPORT_ERROR(MAJOR, E_INVALID_VALUE, ("IPC reply length mismatch"));
            return 0;
        }

        memcpy((uint8_t*)&outCounter, reply.replyBody, sizeof(uint32_t));
        return outCounter;
    }
    else if (!p_Fm->baseAddr)
    {
        REPORT_ERROR(MAJOR, E_NOT_SUPPORTED, ("Either IPC or 'baseAddress' is required!"));
        return 0;
    }

    /* When applicable (when there is an 'enable counters' bit,
    check that counters are enabled */
    switch (counter)
    {
        case (e_FM_COUNTERS_DEQ_1):
        case (e_FM_COUNTERS_DEQ_2):
        case (e_FM_COUNTERS_DEQ_3):
            if ((p_Fm->p_FmStateStruct->revInfo.majorRev == 4) ||
                (p_Fm->p_FmStateStruct->revInfo.majorRev >= 6))
            {
                REPORT_ERROR(MAJOR, E_NOT_SUPPORTED, ("Requested counter not supported"));
                return 0;
            }
        case (e_FM_COUNTERS_ENQ_TOTAL_FRAME):
        case (e_FM_COUNTERS_DEQ_TOTAL_FRAME):
        case (e_FM_COUNTERS_DEQ_0):
        case (e_FM_COUNTERS_DEQ_FROM_DEFAULT):
        case (e_FM_COUNTERS_DEQ_FROM_CONTEXT):
        case (e_FM_COUNTERS_DEQ_FROM_FD):
        case (e_FM_COUNTERS_DEQ_CONFIRM):
            if (!(GET_UINT32(p_Fm->p_FmQmiRegs->fmqm_gc) & QMI_CFG_EN_COUNTERS))
            {
                REPORT_ERROR(MAJOR, E_INVALID_STATE, ("Requested counter was not enabled"));
                return 0;
            }
            break;
        default:
            break;
    }

    FMAN_COUNTERS_TRANS(fsl_counter, counter);
    return fman_get_counter(&fman_rg, fsl_counter);
}

t_Error FM_ModifyCounter(t_Handle h_Fm, e_FmCounters counter, uint32_t val)
{
    t_Fm *p_Fm = (t_Fm*)h_Fm;
    struct fman_rg          fman_rg;
    enum fman_counters fsl_counter;

    SANITY_CHECK_RETURN_ERROR(p_Fm, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(!p_Fm->p_FmDriverParam, E_INVALID_STATE);

   fman_rg.bmi_rg = p_Fm->p_FmBmiRegs;
   fman_rg.qmi_rg = p_Fm->p_FmQmiRegs;
   fman_rg.fpm_rg = p_Fm->p_FmFpmRegs;
   fman_rg.dma_rg = p_Fm->p_FmDmaRegs;

   FMAN_COUNTERS_TRANS(fsl_counter, counter);
   return  (t_Error)fman_modify_counter(&fman_rg, fsl_counter, val);
}

void FM_SetDmaEmergency(t_Handle h_Fm, e_FmDmaMuramPort muramPort, bool enable)
{
    t_Fm *p_Fm = (t_Fm*)h_Fm;
    struct fman_dma_regs *dma_rg;

    SANITY_CHECK_RETURN(p_Fm, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN(!p_Fm->p_FmDriverParam, E_INVALID_STATE);

    dma_rg = p_Fm->p_FmDmaRegs;

    fman_set_dma_emergency(dma_rg, !!(muramPort==e_FM_DMA_MURAM_PORT_WRITE), enable);
}

void FM_SetDmaExtBusPri(t_Handle h_Fm, e_FmDmaExtBusPri pri)
{
    t_Fm *p_Fm = (t_Fm*)h_Fm;
    struct fman_dma_regs *dma_rg;

    SANITY_CHECK_RETURN(p_Fm, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN(!p_Fm->p_FmDriverParam, E_INVALID_STATE);

    dma_rg = p_Fm->p_FmDmaRegs;

    fman_set_dma_ext_bus_pri(dma_rg, pri);
}

void FM_GetDmaStatus(t_Handle h_Fm, t_FmDmaStatus *p_FmDmaStatus)
{
    t_Fm                *p_Fm = (t_Fm*)h_Fm;
    uint32_t             dmaStatus;
    struct fman_dma_regs *dma_rg;

    SANITY_CHECK_RETURN(p_Fm, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN(!p_Fm->p_FmDriverParam, E_INVALID_STATE);

    dma_rg = p_Fm->p_FmDmaRegs;

    if ((p_Fm->guestId != NCSW_MASTER_ID) &&
        !p_Fm->baseAddr &&
        p_Fm->h_IpcSessions[0])
    {
        t_FmIpcDmaStatus    ipcDmaStatus;
        t_FmIpcMsg          msg;
        t_FmIpcReply        reply;
        t_Error             err;
        uint32_t            replyLength;

        memset(&msg, 0, sizeof(msg));
        memset(&reply, 0, sizeof(reply));
        msg.msgId = FM_DMA_STAT;
        replyLength = sizeof(uint32_t) + sizeof(t_FmIpcDmaStatus);
        err = XX_IpcSendMessage(p_Fm->h_IpcSessions[0],
                                (uint8_t*)&msg,
                                sizeof(msg.msgId),
                                (uint8_t*)&reply,
                                &replyLength,
                                NULL,
                                NULL);
        if (err != E_OK)
        {
            REPORT_ERROR(MINOR, err, NO_MSG);
            return;
        }
        if (replyLength != (sizeof(uint32_t) + sizeof(t_FmIpcDmaStatus)))
        {
            REPORT_ERROR(MAJOR, E_INVALID_VALUE, ("IPC reply length mismatch"));
            return;
        }
        memcpy((uint8_t*)&ipcDmaStatus, reply.replyBody, sizeof(t_FmIpcDmaStatus));

        p_FmDmaStatus->cmqNotEmpty = (bool)ipcDmaStatus.boolCmqNotEmpty;            /**< Command queue is not empty */
        p_FmDmaStatus->busError = (bool)ipcDmaStatus.boolBusError;                  /**< Bus error occurred */
        p_FmDmaStatus->readBufEccError = (bool)ipcDmaStatus.boolReadBufEccError;        /**< Double ECC error on buffer Read */
        p_FmDmaStatus->writeBufEccSysError =(bool)ipcDmaStatus.boolWriteBufEccSysError;    /**< Double ECC error on buffer write from system side */
        p_FmDmaStatus->writeBufEccFmError = (bool)ipcDmaStatus.boolWriteBufEccFmError;     /**< Double ECC error on buffer write from FM side */
        p_FmDmaStatus->singlePortEccError = (bool)ipcDmaStatus.boolSinglePortEccError;     /**< Double ECC error on buffer write from FM side */
        return;
    }
    else if (!p_Fm->baseAddr)
    {
        REPORT_ERROR(MINOR, E_NOT_SUPPORTED,
                     ("Either IPC or 'baseAddress' is required!"));
        return;
    }

    dmaStatus = fman_get_dma_status(dma_rg);

    p_FmDmaStatus->cmqNotEmpty = (bool)(dmaStatus & DMA_STATUS_CMD_QUEUE_NOT_EMPTY);
    p_FmDmaStatus->busError = (bool)(dmaStatus & DMA_STATUS_BUS_ERR);
    if (p_Fm->p_FmStateStruct->revInfo.majorRev >= 6)
        p_FmDmaStatus->singlePortEccError = (bool)(dmaStatus & DMA_STATUS_FM_SPDAT_ECC);
    else
    {
        p_FmDmaStatus->readBufEccError = (bool)(dmaStatus & DMA_STATUS_READ_ECC);
        p_FmDmaStatus->writeBufEccSysError = (bool)(dmaStatus & DMA_STATUS_SYSTEM_WRITE_ECC);
        p_FmDmaStatus->writeBufEccFmError = (bool)(dmaStatus & DMA_STATUS_FM_WRITE_ECC);
    }
}

void FM_Resume(t_Handle h_Fm)
{
    t_Fm            *p_Fm = (t_Fm*)h_Fm;
    struct fman_fpm_regs *fpm_rg;

    SANITY_CHECK_RETURN(p_Fm, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN(!p_Fm->p_FmDriverParam, E_INVALID_STATE);
    SANITY_CHECK_RETURN((p_Fm->guestId == NCSW_MASTER_ID), E_NOT_SUPPORTED);

    fpm_rg = p_Fm->p_FmFpmRegs;

    fman_resume(fpm_rg);
}

t_Error FM_GetSpecialOperationCoding(t_Handle               h_Fm,
                                     fmSpecialOperations_t  spOper,
                                     uint8_t                *p_SpOperCoding)
{
    t_Fm                        *p_Fm = (t_Fm*)h_Fm;
    t_FmCtrlCodeRevisionInfo    revInfo;
    t_Error                     err;

    SANITY_CHECK_RETURN_ERROR(p_Fm, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(!p_Fm->p_FmDriverParam, E_INVALID_STATE);
    SANITY_CHECK_RETURN_ERROR(p_SpOperCoding, E_NULL_POINTER);

    if (!spOper)
    {
        *p_SpOperCoding = 0;
        return E_OK;
    }

    if ((err = FM_GetFmanCtrlCodeRevision(p_Fm, &revInfo)) != E_OK)
    {
        DBG(WARNING, ("FM in guest-mode without IPC, can't validate firmware revision."));
        revInfo.packageRev = IP_OFFLOAD_PACKAGE_NUMBER;
    }
    else if (!IS_OFFLOAD_PACKAGE(revInfo.packageRev))
        RETURN_ERROR(MINOR, E_NOT_SUPPORTED, ("Fman ctrl code package"));

    switch (spOper)
    {
        case (FM_SP_OP_CAPWAP_DTLS_DEC):
                *p_SpOperCoding = 9;
                break;
        case (FM_SP_OP_CAPWAP_DTLS_ENC):
                *p_SpOperCoding = 10;
                break;
        case (FM_SP_OP_IPSEC|FM_SP_OP_IPSEC_UPDATE_UDP_LEN|FM_SP_OP_IPSEC_MANIP):
        case (FM_SP_OP_IPSEC|FM_SP_OP_IPSEC_UPDATE_UDP_LEN|FM_SP_OP_IPSEC_MANIP|FM_SP_OP_RPD):
                *p_SpOperCoding = 5;
                break;
        case (FM_SP_OP_IPSEC|FM_SP_OP_IPSEC_MANIP):
        case (FM_SP_OP_IPSEC|FM_SP_OP_IPSEC_MANIP|FM_SP_OP_RPD):
                *p_SpOperCoding = 6;
                break;
        case (FM_SP_OP_IPSEC|FM_SP_OP_IPSEC_UPDATE_UDP_LEN|FM_SP_OP_RPD):
                *p_SpOperCoding = 3;
                break;
        case (FM_SP_OP_IPSEC|FM_SP_OP_IPSEC_UPDATE_UDP_LEN):
                *p_SpOperCoding = 1;
                break;
        case (FM_SP_OP_IPSEC|FM_SP_OP_IPSEC_UPDATE_UDP_LEN|FM_SP_OP_IPSEC_NO_ETH_HDR):
                *p_SpOperCoding = 12;
                break;
        case (FM_SP_OP_IPSEC|FM_SP_OP_RPD):
                *p_SpOperCoding = 4;
                break;
        case (FM_SP_OP_IPSEC):
                *p_SpOperCoding = 2;
                break;
        case (FM_SP_OP_DCL4C):
                *p_SpOperCoding = 7;
                break;
        case (FM_SP_OP_CLEAR_RPD):
                *p_SpOperCoding = 8;
                break;
        default:
            RETURN_ERROR(MINOR, E_INVALID_VALUE, NO_MSG);
    }

    return E_OK;
}

t_Error FM_CtrlMonStart(t_Handle h_Fm)
{
    t_Fm            *p_Fm = (t_Fm *)h_Fm;
    t_FmTrbRegs     *p_MonRegs;
    uint8_t         i;

    SANITY_CHECK_RETURN_ERROR(p_Fm, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(!p_Fm->p_FmDriverParam, E_INVALID_STATE);
    SANITY_CHECK_RETURN_ERROR((p_Fm->guestId == NCSW_MASTER_ID), E_NOT_SUPPORTED);

    WRITE_UINT32(p_Fm->p_FmFpmRegs->fmfp_brkc,
                 GET_UINT32(p_Fm->p_FmFpmRegs->fmfp_brkc) | FPM_BRKC_RDBG);

    for (i = 0; i < FM_NUM_OF_CTRL; i++)
    {
        p_MonRegs = (t_FmTrbRegs *)UINT_TO_PTR(p_Fm->baseAddr + FM_MM_TRB(i));

        /* Reset control registers */
        WRITE_UINT32(p_MonRegs->tcrh, TRB_TCRH_RESET);
        WRITE_UINT32(p_MonRegs->tcrl, TRB_TCRL_RESET);

        /* Configure: counter #1 counts all stalls in risc - ldsched stall
                      counter #2 counts all stalls in risc - other stall*/
        WRITE_UINT32(p_MonRegs->tcrl, TRB_TCRL_RESET | TRB_TCRL_UTIL);

        /* Enable monitoring */
        WRITE_UINT32(p_MonRegs->tcrh, TRB_TCRH_ENABLE_COUNTERS);
    }

    return E_OK;
}

t_Error FM_CtrlMonStop(t_Handle h_Fm)
{
    t_Fm            *p_Fm = (t_Fm *)h_Fm;
    t_FmTrbRegs     *p_MonRegs;
    uint8_t         i;

    SANITY_CHECK_RETURN_ERROR(p_Fm, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(!p_Fm->p_FmDriverParam, E_INVALID_STATE);
    SANITY_CHECK_RETURN_ERROR((p_Fm->guestId == NCSW_MASTER_ID), E_NOT_SUPPORTED);

    for (i = 0; i < FM_NUM_OF_CTRL; i++)
    {
        p_MonRegs = (t_FmTrbRegs *)UINT_TO_PTR(p_Fm->baseAddr + FM_MM_TRB(i));
        WRITE_UINT32(p_MonRegs->tcrh, TRB_TCRH_DISABLE_COUNTERS);
    }

    WRITE_UINT32(p_Fm->p_FmFpmRegs->fmfp_brkc,
                 GET_UINT32(p_Fm->p_FmFpmRegs->fmfp_brkc) & ~FPM_BRKC_RDBG);

    return E_OK;
}

t_Error FM_CtrlMonGetCounters(t_Handle h_Fm, uint8_t fmCtrlIndex, t_FmCtrlMon *p_Mon)
{
    t_Fm            *p_Fm = (t_Fm *)h_Fm;
    t_FmTrbRegs     *p_MonRegs;
    uint64_t        clkCnt, utilValue, effValue;

    SANITY_CHECK_RETURN_ERROR(p_Fm, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(!p_Fm->p_FmDriverParam, E_INVALID_STATE);
    SANITY_CHECK_RETURN_ERROR((p_Fm->guestId == NCSW_MASTER_ID), E_NOT_SUPPORTED);
    SANITY_CHECK_RETURN_ERROR(p_Mon, E_NULL_POINTER);

    if (fmCtrlIndex >= FM_NUM_OF_CTRL)
        RETURN_ERROR(MAJOR, E_INVALID_VALUE, ("FM Controller index"));

    p_MonRegs = (t_FmTrbRegs *)UINT_TO_PTR(p_Fm->baseAddr + FM_MM_TRB(fmCtrlIndex));

    clkCnt = (uint64_t)
            ((uint64_t)GET_UINT32(p_MonRegs->tpcch) << 32 | GET_UINT32(p_MonRegs->tpccl));

    utilValue = (uint64_t)
            ((uint64_t)GET_UINT32(p_MonRegs->tpc1h) << 32 | GET_UINT32(p_MonRegs->tpc1l));

    effValue = (uint64_t)
            ((uint64_t)GET_UINT32(p_MonRegs->tpc2h) << 32 | GET_UINT32(p_MonRegs->tpc2l));

    p_Mon->percentCnt[0] = (uint8_t)(((clkCnt - utilValue) * 100) / clkCnt);
    if (clkCnt != utilValue)
        p_Mon->percentCnt[1] = (uint8_t)((((clkCnt - utilValue) - effValue) * 100) / (clkCnt - utilValue));
    else
        p_Mon->percentCnt[1] = 0;

    return E_OK;
}

t_Handle FM_GetMuramHandle(t_Handle h_Fm)
{
    t_Fm        *p_Fm = (t_Fm*)h_Fm;

    SANITY_CHECK_RETURN_VALUE(p_Fm, E_INVALID_HANDLE, NULL);

    return (p_Fm->h_FmMuram);
}

/****************************************************/
/*       Hidden-DEBUG Only API                      */
/****************************************************/
t_Error FM_ForceIntr (t_Handle h_Fm, e_FmExceptions exception)
{
    t_Fm *p_Fm = (t_Fm*)h_Fm;
    enum fman_exceptions fslException;
    struct fman_rg fman_rg;

    SANITY_CHECK_RETURN_ERROR(p_Fm, E_INVALID_HANDLE);
    SANITY_CHECK_RETURN_ERROR(!p_Fm->p_FmDriverParam, E_INVALID_STATE);

    fman_rg.bmi_rg = p_Fm->p_FmBmiRegs;
    fman_rg.qmi_rg = p_Fm->p_FmQmiRegs;
    fman_rg.fpm_rg = p_Fm->p_FmFpmRegs;
    fman_rg.dma_rg = p_Fm->p_FmDmaRegs;

    switch (exception)
    {
        case e_FM_EX_QMI_DEQ_FROM_UNKNOWN_PORTID:
            if (!(p_Fm->p_FmStateStruct->exceptions & FM_EX_QMI_DEQ_FROM_UNKNOWN_PORTID))
                RETURN_ERROR(MINOR, E_NOT_SUPPORTED, ("The selected exception is masked"));
            break;
        case e_FM_EX_QMI_SINGLE_ECC:
            if (p_Fm->p_FmStateStruct->revInfo.majorRev >= 6)
                 RETURN_ERROR(MAJOR, E_NOT_SUPPORTED, ("e_FM_EX_QMI_SINGLE_ECC not supported on this integration."));

            if (!(p_Fm->p_FmStateStruct->exceptions & FM_EX_QMI_SINGLE_ECC))
                RETURN_ERROR(MINOR, E_NOT_SUPPORTED, ("The selected exception is masked"));
            break;
        case e_FM_EX_QMI_DOUBLE_ECC:
            if (!(p_Fm->p_FmStateStruct->exceptions & FM_EX_QMI_DOUBLE_ECC))
                RETURN_ERROR(MINOR, E_NOT_SUPPORTED, ("The selected exception is masked"));
            break;
        case e_FM_EX_BMI_LIST_RAM_ECC:
            if (!(p_Fm->p_FmStateStruct->exceptions & FM_EX_BMI_LIST_RAM_ECC))
                RETURN_ERROR(MINOR, E_NOT_SUPPORTED, ("The selected exception is masked"));
            break;
        case e_FM_EX_BMI_STORAGE_PROFILE_ECC:
            if (!(p_Fm->p_FmStateStruct->exceptions & FM_EX_BMI_STORAGE_PROFILE_ECC))
                RETURN_ERROR(MINOR, E_NOT_SUPPORTED, ("The selected exception is masked"));
            break;
        case e_FM_EX_BMI_STATISTICS_RAM_ECC:
            if (!(p_Fm->p_FmStateStruct->exceptions & FM_EX_BMI_STATISTICS_RAM_ECC))
                RETURN_ERROR(MINOR, E_NOT_SUPPORTED, ("The selected exception is masked"));
            break;
        case e_FM_EX_BMI_DISPATCH_RAM_ECC:
            if (!(p_Fm->p_FmStateStruct->exceptions & FM_EX_BMI_DISPATCH_RAM_ECC))
                RETURN_ERROR(MINOR, E_NOT_SUPPORTED, ("The selected exception is masked"));
            break;
        default:
            RETURN_ERROR(MINOR, E_NOT_SUPPORTED, ("The selected exception may not be forced"));
    }

    fslException = FmanExceptionTrans(exception);
    fman_force_intr (&fman_rg, fslException);

    return E_OK;
}

t_Handle FmGetPcd(t_Handle h_Fm)
{
	return ((t_Fm*)h_Fm)->h_Pcd;
}
#if (DPAA_VERSION >= 11)
extern void *g_MemacRegs;
void fm_clk_down(void);
uint32_t fman_memac_get_event(void *regs, uint32_t ev_mask);
void FM_ChangeClock(t_Handle h_Fm, int hardwarePortId)
{
	int macId;
	uint32_t    event, rcr;
	t_Fm *p_Fm = (t_Fm*)h_Fm;
	rcr = GET_UINT32(p_Fm->p_FmFpmRegs->fm_rcr);
	rcr |= 0x04000000;
	WRITE_UINT32(p_Fm->p_FmFpmRegs->fm_rcr, rcr);

	HW_PORT_ID_TO_SW_PORT_ID(macId, hardwarePortId);
	do
	{
		event = fman_memac_get_event(g_MemacRegs, 0xFFFFFFFF);
	} while ((event & 0x00000020) == 0);
	fm_clk_down();
	rcr = GET_UINT32(p_Fm->p_FmFpmRegs->fm_rcr);
	rcr &= ~0x04000000;
	WRITE_UINT32(p_Fm->p_FmFpmRegs->fm_rcr, rcr);
}
#endif