DPDK 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
/* SPDX-License-Identifier: BSD-3-Clause
 * Copyright(c) 2017 Huawei Technologies Co., Ltd
 */

#include "hinic_compat.h"
#include "hinic_pmd_hwdev.h"
#include "hinic_pmd_hwif.h"
#include "hinic_pmd_eqs.h"
#include "hinic_pmd_wq.h"
#include "hinic_pmd_mgmt.h"
#include "hinic_pmd_cmdq.h"
#include "hinic_pmd_niccfg.h"
#include "hinic_pmd_mbox.h"

#define l2nic_msg_to_mgmt_sync(hwdev, cmd, buf_in,		\
			       in_size, buf_out, out_size)	\
	hinic_msg_to_mgmt_sync(hwdev, HINIC_MOD_L2NIC, cmd,	\
			buf_in, in_size,			\
			buf_out, out_size, 0)

/**
 * hinic_init_function_table - Initialize function table.
 *
 * @param hwdev
 *   The hardware interface of a nic device.
 * @param rx_buf_sz
 *   Receive buffer size.
 *
 * @return
 *   0 on success.
 *   negative error value otherwise.
 */
int hinic_init_function_table(void *hwdev, u16 rx_buf_sz)
{
	struct hinic_function_table function_table;
	u16 out_size = sizeof(function_table);
	int err;

	if (!hwdev) {
		PMD_DRV_LOG(ERR, "Hwdev is NULL");
		return -EINVAL;
	}

	memset(&function_table, 0, sizeof(function_table));
	function_table.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
	function_table.func_id = hinic_global_func_id(hwdev);
	function_table.mtu = 0x3FFF;	/* default, max mtu */
	function_table.rx_wqe_buf_size = rx_buf_sz;

	err = hinic_msg_to_mgmt_sync(hwdev, HINIC_MOD_L2NIC,
				     HINIC_PORT_CMD_INIT_FUNC,
				     &function_table, sizeof(function_table),
				     &function_table, &out_size, 0);
	if (err || function_table.mgmt_msg_head.status || !out_size) {
		PMD_DRV_LOG(ERR,
			"Failed to init func table, err: %d, status: 0x%x, out size: 0x%x",
			err, function_table.mgmt_msg_head.status, out_size);
		return -EIO;
	}

	return 0;
}

/**
 * hinic_get_base_qpn - Get global queue number.
 *
 * @param hwdev
 *   The hardware interface of a nic device.
 * @param global_qpn
 *   Global queue number.
 *
 * @return
 *   0 on success.
 *   negative error value otherwise.
 */
int hinic_get_base_qpn(void *hwdev, u16 *global_qpn)
{
	struct hinic_cmd_qpn cmd_qpn;
	u16 out_size = sizeof(cmd_qpn);
	int err;

	if (!hwdev || !global_qpn) {
		PMD_DRV_LOG(ERR, "Hwdev or global_qpn is NULL");
		return -EINVAL;
	}

	memset(&cmd_qpn, 0, sizeof(cmd_qpn));
	cmd_qpn.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
	cmd_qpn.func_id = hinic_global_func_id(hwdev);

	err = hinic_msg_to_mgmt_sync(hwdev, HINIC_MOD_L2NIC,
				     HINIC_PORT_CMD_GET_GLOBAL_QPN,
				     &cmd_qpn, sizeof(cmd_qpn), &cmd_qpn,
				     &out_size, 0);
	if (err || !out_size || cmd_qpn.mgmt_msg_head.status) {
		PMD_DRV_LOG(ERR,
			"Failed to get base qpn, err: %d, status: 0x%x, out size: 0x%x",
			err, cmd_qpn.mgmt_msg_head.status, out_size);
		return -EIO;
	}

	*global_qpn = cmd_qpn.base_qpn;

	return 0;
}

/**
 * hinic_set_mac - Init mac_vlan table in NIC.
 *
 * @param hwdev
 *   The hardware interface of a nic device.
 * @param mac_addr
 *   MAC address.
 * @param vlan_id
 *   Set 0 for mac_vlan table initialization.
 * @param func_id
 *   Global function id of NIC.
 *
 * @return
 *   0 on success.
 *   negative error value otherwise.
 */
int hinic_set_mac(void *hwdev, u8 *mac_addr, u16 vlan_id, u16 func_id)
{
	struct hinic_port_mac_set mac_info;
	u16 out_size = sizeof(mac_info);
	int err;

	if (!hwdev || !mac_addr) {
		PMD_DRV_LOG(ERR, "Hwdev or mac_addr is NULL");
		return -EINVAL;
	}

	memset(&mac_info, 0, sizeof(mac_info));
	mac_info.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
	mac_info.func_id = func_id;
	mac_info.vlan_id = vlan_id;
	memmove(mac_info.mac, mac_addr, ETH_ALEN);

	err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_SET_MAC, &mac_info,
				     sizeof(mac_info), &mac_info, &out_size);
	if (err || !out_size || (mac_info.mgmt_msg_head.status &&
	    mac_info.mgmt_msg_head.status != HINIC_PF_SET_VF_ALREADY)) {
		PMD_DRV_LOG(ERR, "Failed to set MAC, err: %d, status: 0x%x, out size: 0x%x",
			err, mac_info.mgmt_msg_head.status, out_size);
		return -EIO;
	}

	if (mac_info.mgmt_msg_head.status == HINIC_PF_SET_VF_ALREADY) {
		PMD_DRV_LOG(WARNING, "PF has already set vf mac, Ignore set operation.");
		return HINIC_PF_SET_VF_ALREADY;
	}

	return 0;
}

/**
 * hinic_del_mac - Uninit mac_vlan table in NIC.
 *
 * @param hwdev
 *   The hardware interface of a nic device.
 * @param mac_addr
 *   MAC address.
 * @param vlan_id
 *   Set 0 for mac_vlan table initialization.
 * @param func_id
 *   Global function id of NIC.
 *
 * @return
 *   0 on success.
 *   negative error value otherwise.
 */
int hinic_del_mac(void *hwdev, u8 *mac_addr, u16 vlan_id, u16 func_id)
{
	struct hinic_port_mac_set mac_info;
	u16 out_size = sizeof(mac_info);
	int err;

	if (!hwdev || !mac_addr) {
		PMD_DRV_LOG(ERR, "Hwdev or mac_addr is NULL");
		return -EINVAL;
	}

	if (vlan_id >= VLAN_N_VID) {
		PMD_DRV_LOG(ERR, "Invalid VLAN number");
		return -EINVAL;
	}

	memset(&mac_info, 0, sizeof(mac_info));
	mac_info.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
	mac_info.func_id = func_id;
	mac_info.vlan_id = vlan_id;
	memmove(mac_info.mac, mac_addr, ETH_ALEN);

	err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_DEL_MAC, &mac_info,
				     sizeof(mac_info), &mac_info, &out_size);
	if (err || !out_size || (mac_info.mgmt_msg_head.status &&
		mac_info.mgmt_msg_head.status != HINIC_PF_SET_VF_ALREADY)) {
		PMD_DRV_LOG(ERR, "Failed to delete MAC, err: %d, status: 0x%x, out size: 0x%x",
			err, mac_info.mgmt_msg_head.status, out_size);
		return -EIO;
	}
	if (mac_info.mgmt_msg_head.status == HINIC_PF_SET_VF_ALREADY) {
		PMD_DRV_LOG(WARNING, "PF has already set vf mac, Ignore delete operation.");
		return HINIC_PF_SET_VF_ALREADY;
	}

	return 0;
}

/**
 * hinic_get_default_mac - Get default mac address from hardware.
 *
 * @param hwdev
 *   The hardware interface of a nic device.
 * @param mac_addr
 *   MAC address.
 *
 * @return
 *   0 on success.
 *   negative error value otherwise.
 */
int hinic_get_default_mac(void *hwdev, u8 *mac_addr)
{
	struct hinic_port_mac_set mac_info;
	u16 out_size = sizeof(mac_info);
	int err;

	if (!hwdev || !mac_addr) {
		PMD_DRV_LOG(ERR, "Hwdev or mac_addr is NULL");
		return -EINVAL;
	}

	memset(&mac_info, 0, sizeof(mac_info));
	mac_info.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
	mac_info.func_id = hinic_global_func_id(hwdev);

	err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_GET_MAC,
				     &mac_info, sizeof(mac_info),
				     &mac_info, &out_size);
	if (err || !out_size || mac_info.mgmt_msg_head.status) {
		PMD_DRV_LOG(ERR, "Failed to get mac, err: %d, status: 0x%x, out size: 0x%x",
			err, mac_info.mgmt_msg_head.status, out_size);
		return -EIO;
	}

	memmove(mac_addr, mac_info.mac, ETH_ALEN);

	return 0;
}

/**
*  hinic_update_mac - Update mac address to hardware.
*
* @param hwdev
*   The hardware interface of a nic device.
* @param old_mac
*   Old mac address.
* @param new_mac
*   New mac address.
* @param vlan_id
*   Set 0 for mac_vlan table initialization.
* @param func_id
*   Global function id of NIC.
*
* @return
*   0 on success.
*   negative error value otherwise.
*/
int hinic_update_mac(void *hwdev, u8 *old_mac, u8 *new_mac, u16 vlan_id,
		     u16 func_id)
{
	struct hinic_port_mac_update mac_info;
	u16 out_size = sizeof(mac_info);
	int err;

	if (!hwdev || !old_mac || !new_mac) {
		PMD_DRV_LOG(ERR, "Hwdev, old_mac or new_mac is NULL");
		return -EINVAL;
	}

	memset(&mac_info, 0, sizeof(mac_info));
	mac_info.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
	mac_info.func_id = func_id;
	mac_info.vlan_id = vlan_id;
	memcpy(mac_info.old_mac, old_mac, ETH_ALEN);
	memcpy(mac_info.new_mac, new_mac, ETH_ALEN);

	err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_UPDATE_MAC,
				     &mac_info, sizeof(mac_info),
				     &mac_info, &out_size);
	if (err || !out_size ||
	    (mac_info.mgmt_msg_head.status &&
	     mac_info.mgmt_msg_head.status != HINIC_PF_SET_VF_ALREADY)) {
		PMD_DRV_LOG(ERR, "Failed to update MAC, err: %d, status: 0x%x, out size: 0x%x",
			    err, mac_info.mgmt_msg_head.status, out_size);
		return -EIO;
	}
	if (mac_info.mgmt_msg_head.status == HINIC_PF_SET_VF_ALREADY) {
		PMD_DRV_LOG(WARNING, "PF has already set vf mac, Ignore update operation");
		return HINIC_PF_SET_VF_ALREADY;
	}

	return 0;
}

/**
 * hinic_set_port_mtu -  Set MTU to port.
 *
 * @param hwdev
 *   The hardware interface of a nic device.
 * @param new_mtu
 *   MTU size.
 *
 * @return
 *   0 on success.
 *   negative error value otherwise.
 */
int hinic_set_port_mtu(void *hwdev, u32 new_mtu)
{
	struct hinic_mtu mtu_info;
	u16 out_size = sizeof(mtu_info);
	int err;

	if (!hwdev) {
		PMD_DRV_LOG(ERR, "Hwdev is NULL");
		return -EINVAL;
	}

	memset(&mtu_info, 0, sizeof(mtu_info));
	mtu_info.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
	mtu_info.func_id = hinic_global_func_id(hwdev);
	mtu_info.mtu = new_mtu;

	err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_CHANGE_MTU,
				     &mtu_info, sizeof(mtu_info),
				     &mtu_info, &out_size);
	if (err || !out_size || mtu_info.mgmt_msg_head.status) {
		PMD_DRV_LOG(ERR, "Failed to set mtu, err: %d, status: 0x%x, out size: 0x%x",
			err, mtu_info.mgmt_msg_head.status, out_size);
		return -EIO;
	}

	return 0;
}

/**
 * hinic_add_remove_vlan - Add or remove vlan id to vlan elb table.
 *
 * @param hwdev
 *   The hardware interface of a nic device.
 * @param vlan_id
 *   Vlan id.
 * @param func_id
 *   Global function id of NIC.
 * @param add
 *   Add or remove operation.
 *
 * @return
 *   0 on success.
 *   negative error value otherwise.
 */
int hinic_add_remove_vlan(void *hwdev, u16 vlan_id, u16 func_id, bool add)
{
	struct hinic_vlan_config vlan_info;
	u16 out_size = sizeof(vlan_info);
	u8 cmd;
	int err;

	if (!hwdev) {
		PMD_DRV_LOG(ERR, "Hwdev is NULL");
		return -EINVAL;
	}

	cmd = add ? HINIC_PORT_CMD_ADD_VLAN : HINIC_PORT_CMD_DEL_VLAN;

	memset(&vlan_info, 0, sizeof(vlan_info));
	vlan_info.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
	vlan_info.func_id = func_id;
	vlan_info.vlan_id = vlan_id;

	err = l2nic_msg_to_mgmt_sync(hwdev, cmd, &vlan_info, sizeof(vlan_info),
				     &vlan_info, &out_size);
	if (err || !out_size || vlan_info.mgmt_msg_head.status) {
		PMD_DRV_LOG(ERR,
			"Failed to %s vlan, err: %d, status: 0x%x, out size: 0x%x",
			add ? "add" : "remove", err,
			vlan_info.mgmt_msg_head.status, out_size);
		return -EIO;
	}

	return 0;
}

/**
 * hinic_config_vlan_filter - Enable or Disable vlan filter.
 *
 * @param hwdev
 *   The hardware interface of a nic device.
 * @param vlan_filter_ctrl
 *   Enable or Disable.
 *
 * @return
 *   0 on success.
 *   negative error value otherwise.
 */
int hinic_config_vlan_filter(void *hwdev, u32 vlan_filter_ctrl)
{
	struct hinic_hwdev *nic_hwdev = (struct hinic_hwdev *)hwdev;
	struct hinic_vlan_filter vlan_filter;
	u16 out_size = sizeof(vlan_filter);
	int err;

	if (!hwdev)
		return -EINVAL;

	memset(&vlan_filter, 0, sizeof(vlan_filter));
	vlan_filter.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
	vlan_filter.func_id = hinic_global_func_id(nic_hwdev);
	vlan_filter.vlan_filter_ctrl = vlan_filter_ctrl;

	err = l2nic_msg_to_mgmt_sync(nic_hwdev, HINIC_PORT_CMD_SET_VLAN_FILTER,
				     &vlan_filter, sizeof(vlan_filter),
				     &vlan_filter, &out_size);
	if (vlan_filter.mgmt_msg_head.status == HINIC_MGMT_CMD_UNSUPPORTED) {
		err = HINIC_MGMT_CMD_UNSUPPORTED;
	} else if ((err == HINIC_MBOX_VF_CMD_ERROR) &&
		(HINIC_IS_VF(nic_hwdev))) {
		err = HINIC_MGMT_CMD_UNSUPPORTED;
	} else if (err || !out_size || vlan_filter.mgmt_msg_head.status) {
		PMD_DRV_LOG(ERR,
			"Failed to config vlan filter, vlan_filter_ctrl: 0x%x, err: %d, status: 0x%x, out size: 0x%x",
			vlan_filter_ctrl, err,
			vlan_filter.mgmt_msg_head.status, out_size);
		err = -EIO;
	}

	return err;
}

/**
 * hinic_set_rx_vlan_offload - Enable or Disable vlan offload.
 *
 * @param hwdev
 *   The hardware interface of a nic device.
 * @param en
 *   Enable or Disable.
 *
 * @return
 *   0 on success.
 *   negative error value otherwise.
 */
int hinic_set_rx_vlan_offload(void *hwdev, u8 en)
{
	struct hinic_vlan_offload vlan_cfg;
	u16 out_size = sizeof(vlan_cfg);
	int err;

	if (!hwdev) {
		PMD_DRV_LOG(ERR, "Hwdev is NULL");
		return -EINVAL;
	}

	memset(&vlan_cfg, 0, sizeof(vlan_cfg));
	vlan_cfg.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
	vlan_cfg.func_id = hinic_global_func_id(hwdev);
	vlan_cfg.vlan_rx_offload = en;

	err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_SET_RX_VLAN_OFFLOAD,
				     &vlan_cfg, sizeof(vlan_cfg),
				     &vlan_cfg, &out_size);
	if (err || !out_size || vlan_cfg.mgmt_msg_head.status) {
		PMD_DRV_LOG(ERR,
			"Failed to set rx vlan offload, err: %d, status: 0x%x, out size: 0x%x",
			err, vlan_cfg.mgmt_msg_head.status, out_size);
		return -EIO;
	}

	return 0;
}

/**
 * hinic_get_link_status - Get link status from hardware.
 *
 * @param hwdev
 *   The hardware interface of a nic device.
 * @param link_state
 *   Link status.
 *
 * @return
 *   0 on success.
 *   negative error value otherwise.
 */
int hinic_get_link_status(void *hwdev, u8 *link_state)
{
	struct hinic_get_link get_link;
	u16 out_size = sizeof(get_link);
	int err;

	if (!hwdev || !link_state) {
		PMD_DRV_LOG(ERR, "Hwdev or link_state is NULL");
		return -EINVAL;
	}

	memset(&get_link, 0, sizeof(get_link));
	get_link.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
	get_link.func_id = hinic_global_func_id(hwdev);

	err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_GET_LINK_STATE,
				     &get_link, sizeof(get_link),
				     &get_link, &out_size);
	if (err || !out_size || get_link.mgmt_msg_head.status) {
		PMD_DRV_LOG(ERR, "Failed to get link state, err: %d, status: 0x%x, out size: 0x%x",
			err, get_link.mgmt_msg_head.status, out_size);
		return -EIO;
	}

	*link_state = get_link.link_status;

	return 0;
}

/**
 * hinic_set_vport_enable - Notify firmware that driver is ready or not.
 *
 * @param hwdev
 *   The hardware interface of a nic device.
 * @param enable
 *   1: driver is ready; 0: driver is not ok.
 *
 * @return
 *   0 on success.
 *   negative error value otherwise.
 */
int hinic_set_vport_enable(void *hwdev, bool enable)
{
	struct hinic_vport_state en_state;
	u16 out_size = sizeof(en_state);
	int err;

	if (!hwdev) {
		PMD_DRV_LOG(ERR, "Hwdev is NULL");
		return -EINVAL;
	}

	memset(&en_state, 0, sizeof(en_state));
	en_state.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
	en_state.func_id = hinic_global_func_id(hwdev);
	en_state.state = (enable ? 1 : 0);

	err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_SET_VPORT_ENABLE,
				     &en_state, sizeof(en_state),
				     &en_state, &out_size);
	if (err || !out_size || en_state.mgmt_msg_head.status) {
		PMD_DRV_LOG(ERR, "Failed to set vport state, err: %d, status: 0x%x, out size: 0x%x",
			err, en_state.mgmt_msg_head.status, out_size);
		return -EIO;
	}

	return 0;
}

/**
 * hinic_set_port_enable - Open MAG to receive packets.
 *
 * @param hwdev
 *   The hardware interface of a nic device.
 * @param enable
 *   1: open MAG; 0: close MAG.
 *
 * @return
 *   0 on success.
 *   negative error value otherwise.
 */
int hinic_set_port_enable(void *hwdev, bool enable)
{
	struct hinic_port_state en_state;
	u16 out_size = sizeof(en_state);
	int err;

	if (!hwdev) {
		PMD_DRV_LOG(ERR, "Hwdev is NULL");
		return -EINVAL;
	}

	if (HINIC_IS_VF((struct hinic_hwdev *)hwdev))
		return 0;

	memset(&en_state, 0, sizeof(en_state));
	en_state.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
	en_state.state = (enable ? HINIC_PORT_ENABLE : HINIC_PORT_DISABLE);

	err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_SET_PORT_ENABLE,
				     &en_state, sizeof(en_state),
				     &en_state, &out_size);
	if (err || !out_size || en_state.mgmt_msg_head.status) {
		PMD_DRV_LOG(ERR, "Failed to set phy port state, err: %d, status: 0x%x, out size: 0x%x",
			err, en_state.mgmt_msg_head.status, out_size);
		return -EIO;
	}

	return 0;
}

int hinic_get_port_info(void *hwdev, struct nic_port_info *port_info)
{
	struct hinic_port_info port_msg;
	u16 out_size = sizeof(port_msg);
	int err;

	if (!hwdev || !port_info) {
		PMD_DRV_LOG(ERR, "Hwdev or port_info is NULL");
		return -EINVAL;
	}

	memset(&port_msg, 0, sizeof(port_msg));
	port_msg.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
	port_msg.func_id = hinic_global_func_id(hwdev);

	err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_GET_PORT_INFO,
				     &port_msg, sizeof(port_msg),
				     &port_msg, &out_size);
	if (err || !out_size || port_msg.mgmt_msg_head.status) {
		PMD_DRV_LOG(ERR,
			"Failed to get port info, err: %d, status: 0x%x, out size: 0x%x",
			err, port_msg.mgmt_msg_head.status, out_size);
		return -EIO;
	}

	port_info->autoneg_cap = port_msg.autoneg_cap;
	port_info->autoneg_state = port_msg.autoneg_state;
	port_info->duplex = port_msg.duplex;
	port_info->port_type = port_msg.port_type;
	port_info->speed = port_msg.speed;

	return 0;
}

int hinic_set_pause_config(void *hwdev, struct nic_pause_config nic_pause)
{
	struct hinic_pause_config pause_info;
	u16 out_size = sizeof(pause_info);
	int err;

	if (!hwdev) {
		PMD_DRV_LOG(ERR, "Hwdev is NULL");
		return -EINVAL;
	}

	memset(&pause_info, 0, sizeof(pause_info));
	pause_info.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
	pause_info.func_id = hinic_global_func_id(hwdev);
	pause_info.auto_neg = nic_pause.auto_neg;
	pause_info.rx_pause = nic_pause.rx_pause;
	pause_info.tx_pause = nic_pause.tx_pause;

	err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_SET_PAUSE_INFO,
				     &pause_info, sizeof(pause_info),
				     &pause_info, &out_size);
	if (err || !out_size || pause_info.mgmt_msg_head.status) {
		PMD_DRV_LOG(ERR, "Failed to set pause info, err: %d, status: 0x%x, out size: 0x%x",
			err, pause_info.mgmt_msg_head.status, out_size);
		return -EIO;
	}

	return 0;
}

int hinic_get_pause_info(void *hwdev, struct nic_pause_config *nic_pause)
{
	struct hinic_pause_config pause_info;
	u16 out_size = sizeof(pause_info);
	int err;

	if (!hwdev || !nic_pause)
		return -EINVAL;

	memset(&pause_info, 0, sizeof(pause_info));
	pause_info.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
	pause_info.func_id = hinic_global_func_id(hwdev);

	err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_GET_PAUSE_INFO,
				     &pause_info, sizeof(pause_info),
				     &pause_info, &out_size);
	if (err || !out_size || pause_info.mgmt_msg_head.status) {
		PMD_DRV_LOG(ERR, "Failed to get pause info, err: %d, status: 0x%x, out size: 0x%x\n",
			err, pause_info.mgmt_msg_head.status, out_size);
		return -EIO;
	}

	nic_pause->auto_neg = pause_info.auto_neg;
	nic_pause->rx_pause = pause_info.rx_pause;
	nic_pause->tx_pause = pause_info.tx_pause;

	return 0;
}

int hinic_dcb_set_ets(void *hwdev, u8 *up_tc, u8 *pg_bw,
		      u8 *pgid, u8 *up_bw, u8 *prio)
{
	struct hinic_up_ets_cfg ets;
	u16 out_size = sizeof(ets);
	u16 up_bw_t = 0;
	u8 pg_bw_t = 0;
	int i, err;

	if (!hwdev || !up_tc || !pg_bw || !pgid || !up_bw || !prio) {
		PMD_DRV_LOG(ERR, "Hwdev, up_tc, pg_bw, pgid, up_bw or prio is NULL");
		return -EINVAL;
	}

	for (i = 0; i < HINIC_DCB_TC_MAX; i++) {
		up_bw_t += *(up_bw + i);
		pg_bw_t += *(pg_bw + i);

		if (*(up_tc + i) > HINIC_DCB_TC_MAX) {
			PMD_DRV_LOG(ERR, "Invalid up %d mapping tc: %d", i,
				*(up_tc + i));
			return -EINVAL;
		}
	}

	if (pg_bw_t != 100 || (up_bw_t % 100) != 0) {
		PMD_DRV_LOG(ERR,
			"Invalid pg_bw: %d or up_bw: %d", pg_bw_t, up_bw_t);
		return -EINVAL;
	}

	memset(&ets, 0, sizeof(ets));
	ets.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
	ets.port_id = 0;	/* reserved */
	memcpy(ets.up_tc, up_tc, HINIC_DCB_TC_MAX);
	memcpy(ets.pg_bw, pg_bw, HINIC_DCB_UP_MAX);
	memcpy(ets.pgid, pgid, HINIC_DCB_UP_MAX);
	memcpy(ets.up_bw, up_bw, HINIC_DCB_UP_MAX);
	memcpy(ets.prio, prio, HINIC_DCB_UP_MAX);

	err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_SET_ETS,
				     &ets, sizeof(ets), &ets, &out_size);
	if (err || ets.mgmt_msg_head.status || !out_size) {
		PMD_DRV_LOG(ERR,
			"Failed to set ets, err: %d, status: 0x%x, out size: 0x%x",
			err, ets.mgmt_msg_head.status, out_size);
		return -EIO;
	}

	return 0;
}

int hinic_get_vport_stats(void *hwdev, struct hinic_vport_stats *stats)
{
	struct hinic_port_stats_info vport_stats_cmd;
	struct hinic_cmd_vport_stats vport_stats_rsp;
	u16 out_size = sizeof(vport_stats_rsp);
	int err;

	if (!hwdev || !stats) {
		PMD_DRV_LOG(ERR, "Hwdev or stats is NULL");
		return -EINVAL;
	}

	memset(&vport_stats_rsp, 0, sizeof(vport_stats_rsp));
	memset(&vport_stats_cmd, 0, sizeof(vport_stats_cmd));
	vport_stats_cmd.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
	vport_stats_cmd.stats_version = HINIC_PORT_STATS_VERSION;
	vport_stats_cmd.func_id = hinic_global_func_id(hwdev);
	vport_stats_cmd.stats_size = sizeof(vport_stats_rsp);

	err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_GET_VPORT_STAT,
				     &vport_stats_cmd, sizeof(vport_stats_cmd),
				     &vport_stats_rsp, &out_size);
	if (err || !out_size || vport_stats_rsp.mgmt_msg_head.status) {
		PMD_DRV_LOG(ERR,
			"Get vport stats from fw failed, err: %d, status: 0x%x, out size: 0x%x",
			err, vport_stats_rsp.mgmt_msg_head.status, out_size);
		return -EIO;
	}

	memcpy(stats, &vport_stats_rsp.stats, sizeof(*stats));

	return 0;
}

int hinic_get_phy_port_stats(void *hwdev, struct hinic_phy_port_stats *stats)
{
	struct hinic_port_stats_info port_stats_cmd;
	struct hinic_port_stats port_stats_rsp;
	u16 out_size = sizeof(port_stats_rsp);
	int err;

	if (!hwdev || !stats) {
		PMD_DRV_LOG(ERR, "Hwdev or stats is NULL");
		return -EINVAL;
	}

	memset(&port_stats_rsp, 0, sizeof(port_stats_rsp));
	memset(&port_stats_cmd, 0, sizeof(port_stats_cmd));
	port_stats_cmd.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
	port_stats_cmd.stats_version = HINIC_PORT_STATS_VERSION;
	port_stats_cmd.stats_size = sizeof(port_stats_rsp);

	err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_GET_PORT_STATISTICS,
				     &port_stats_cmd, sizeof(port_stats_cmd),
				     &port_stats_rsp, &out_size);
	if (err || !out_size || port_stats_rsp.mgmt_msg_head.status) {
		PMD_DRV_LOG(ERR,
			"Failed to get port statistics, err: %d, status: 0x%x, out size: 0x%x",
			err, port_stats_rsp.mgmt_msg_head.status, out_size);
		return -EIO;
	}

	memcpy(stats, &port_stats_rsp.stats, sizeof(*stats));

	return 0;
}

int hinic_set_rss_type(void *hwdev, u32 tmpl_idx, struct nic_rss_type rss_type)
{
	struct nic_rss_context_tbl *ctx_tbl;
	struct hinic_cmd_buf *cmd_buf;
	u32 ctx = 0;
	u64 out_param;
	int err;

	if (!hwdev) {
		PMD_DRV_LOG(ERR, "Hwdev is NULL");
		return -EINVAL;
	}

	cmd_buf = hinic_alloc_cmd_buf(hwdev);
	if (!cmd_buf) {
		PMD_DRV_LOG(ERR, "Failed to allocate cmd buf");
		return -ENOMEM;
	}

	ctx |= HINIC_RSS_TYPE_SET(1, VALID) |
		HINIC_RSS_TYPE_SET(rss_type.ipv4, IPV4) |
		HINIC_RSS_TYPE_SET(rss_type.ipv6, IPV6) |
		HINIC_RSS_TYPE_SET(rss_type.ipv6_ext, IPV6_EXT) |
		HINIC_RSS_TYPE_SET(rss_type.tcp_ipv4, TCP_IPV4) |
		HINIC_RSS_TYPE_SET(rss_type.tcp_ipv6, TCP_IPV6) |
		HINIC_RSS_TYPE_SET(rss_type.tcp_ipv6_ext, TCP_IPV6_EXT) |
		HINIC_RSS_TYPE_SET(rss_type.udp_ipv4, UDP_IPV4) |
		HINIC_RSS_TYPE_SET(rss_type.udp_ipv6, UDP_IPV6);

	cmd_buf->size = sizeof(struct nic_rss_context_tbl);

	ctx_tbl = (struct nic_rss_context_tbl *)cmd_buf->buf;
	ctx_tbl->group_index = cpu_to_be32(tmpl_idx);
	ctx_tbl->offset = 0;
	ctx_tbl->size = sizeof(u32);
	ctx_tbl->size = cpu_to_be32(ctx_tbl->size);
	ctx_tbl->rsvd = 0;
	ctx_tbl->ctx = cpu_to_be32(ctx);

	/* cfg the rss context table by command queue */
	err = hinic_cmdq_direct_resp(hwdev, HINIC_ACK_TYPE_CMDQ,
				     HINIC_MOD_L2NIC,
				     HINIC_UCODE_CMD_SET_RSS_CONTEXT_TABLE,
				     cmd_buf, &out_param, 0);

	hinic_free_cmd_buf(hwdev, cmd_buf);

	if (err || out_param != 0) {
		PMD_DRV_LOG(ERR, "Failed to set rss context table");
		return -EIO;
	}

	return 0;
}

int hinic_get_rss_type(void *hwdev, u32 tmpl_idx, struct nic_rss_type *rss_type)
{
	struct hinic_rss_context_table ctx_tbl;
	u16 out_size = sizeof(ctx_tbl);
	int err;

	if (!hwdev || !rss_type) {
		PMD_DRV_LOG(ERR, "Hwdev or rss_type is NULL");
		return -EINVAL;
	}

	ctx_tbl.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
	ctx_tbl.func_id = hinic_global_func_id(hwdev);
	ctx_tbl.template_id = (u8)tmpl_idx;

	err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_GET_RSS_CTX_TBL,
				     &ctx_tbl, sizeof(ctx_tbl),
				     &ctx_tbl, &out_size);
	if (err || !out_size || ctx_tbl.mgmt_msg_head.status) {
		PMD_DRV_LOG(ERR,
			"Failed to get hash type, err: %d, status: 0x%x, out size: 0x%x",
			err, ctx_tbl.mgmt_msg_head.status, out_size);
		return -EIO;
	}

	rss_type->ipv4 = HINIC_RSS_TYPE_GET(ctx_tbl.context, IPV4);
	rss_type->ipv6 = HINIC_RSS_TYPE_GET(ctx_tbl.context, IPV6);
	rss_type->ipv6_ext = HINIC_RSS_TYPE_GET(ctx_tbl.context, IPV6_EXT);
	rss_type->tcp_ipv4 = HINIC_RSS_TYPE_GET(ctx_tbl.context, TCP_IPV4);
	rss_type->tcp_ipv6 = HINIC_RSS_TYPE_GET(ctx_tbl.context, TCP_IPV6);
	rss_type->tcp_ipv6_ext =
			HINIC_RSS_TYPE_GET(ctx_tbl.context, TCP_IPV6_EXT);
	rss_type->udp_ipv4 = HINIC_RSS_TYPE_GET(ctx_tbl.context, UDP_IPV4);
	rss_type->udp_ipv6 = HINIC_RSS_TYPE_GET(ctx_tbl.context, UDP_IPV6);

	return 0;
}

int hinic_rss_set_template_tbl(void *hwdev, u32 tmpl_idx, u8 *temp)
{
	struct hinic_rss_template_key temp_key;
	u16 out_size = sizeof(temp_key);
	int err;

	if (!hwdev || !temp) {
		PMD_DRV_LOG(ERR, "Hwdev or temp is NULL");
		return -EINVAL;
	}

	memset(&temp_key, 0, sizeof(temp_key));
	temp_key.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
	temp_key.func_id = hinic_global_func_id(hwdev);
	temp_key.template_id = (u8)tmpl_idx;
	memcpy(temp_key.key, temp, HINIC_RSS_KEY_SIZE);

	err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_SET_RSS_TEMPLATE_TBL,
				     &temp_key, sizeof(temp_key),
				     &temp_key, &out_size);
	if (err || !out_size || temp_key.mgmt_msg_head.status) {
		PMD_DRV_LOG(ERR,
			"Failed to set hash key, err: %d, status: 0x%x, out size: 0x%x",
			err, temp_key.mgmt_msg_head.status, out_size);
		return -EIO;
	}

	return 0;
}

int hinic_rss_get_template_tbl(void *hwdev, u32 tmpl_idx, u8 *temp)
{
	struct hinic_rss_template_key temp_key;
	u16 out_size = sizeof(temp_key);
	int err;

	if (!hwdev || !temp) {
		PMD_DRV_LOG(ERR, "Hwdev or temp is NULL");
		return -EINVAL;
	}

	memset(&temp_key, 0, sizeof(temp_key));
	temp_key.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
	temp_key.func_id = hinic_global_func_id(hwdev);
	temp_key.template_id = (u8)tmpl_idx;

	err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_GET_RSS_TEMPLATE_TBL,
				     &temp_key, sizeof(temp_key),
				     &temp_key, &out_size);
	if (err || !out_size || temp_key.mgmt_msg_head.status) {
		PMD_DRV_LOG(ERR, "Failed to get hash key, err: %d, status: 0x%x, out size: 0x%x",
			err, temp_key.mgmt_msg_head.status, out_size);
		return -EIO;
	}

	memcpy(temp, temp_key.key, HINIC_RSS_KEY_SIZE);

	return 0;
}

/**
 * hinic_rss_set_hash_engine - Init rss hash function.
 *
 * @param hwdev
 *   The hardware interface of a nic device.
 * @param tmpl_idx
 *   Index of rss template from NIC.
 * @param type
 *   Hash function, such as Toeplitz or XOR.
 *
 * @return
 *   0 on success.
 *   negative error value otherwise.
 */
int hinic_rss_set_hash_engine(void *hwdev, u8 tmpl_idx, u8 type)
{
	struct hinic_rss_engine_type hash_type;
	u16 out_size = sizeof(hash_type);
	int err;

	if (!hwdev) {
		PMD_DRV_LOG(ERR, "Hwdev is NULL");
		return -EINVAL;
	}

	memset(&hash_type, 0, sizeof(hash_type));
	hash_type.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
	hash_type.func_id = hinic_global_func_id(hwdev);
	hash_type.hash_engine = type;
	hash_type.template_id = tmpl_idx;

	err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_SET_RSS_HASH_ENGINE,
				     &hash_type, sizeof(hash_type),
				     &hash_type, &out_size);
	if (err || !out_size || hash_type.mgmt_msg_head.status) {
		PMD_DRV_LOG(ERR, "Failed to get hash engine, err: %d, status: 0x%x, out size: 0x%x",
			err, hash_type.mgmt_msg_head.status, out_size);
		return -EIO;
	}

	return 0;
}

int hinic_rss_set_indir_tbl(void *hwdev, u32 tmpl_idx, u32 *indir_table)
{
	struct nic_rss_indirect_tbl *indir_tbl;
	struct hinic_cmd_buf *cmd_buf;
	int i;
	u32 *temp;
	u32 indir_size;
	u64 out_param;
	int err;

	if (!hwdev || !indir_table) {
		PMD_DRV_LOG(ERR, "Hwdev or indir_table is NULL");
		return -EINVAL;
	}

	cmd_buf = hinic_alloc_cmd_buf(hwdev);
	if (!cmd_buf) {
		PMD_DRV_LOG(ERR, "Failed to allocate cmd buf");
		return -ENOMEM;
	}

	cmd_buf->size = sizeof(struct nic_rss_indirect_tbl);
	indir_tbl = cmd_buf->buf;
	indir_tbl->group_index = cpu_to_be32(tmpl_idx);

	for (i = 0; i < HINIC_RSS_INDIR_SIZE; i++) {
		indir_tbl->entry[i] = (u8)(*(indir_table + i));

		if (0x3 == (i & 0x3)) {
			temp = (u32 *)&indir_tbl->entry[i - 3];
			*temp = cpu_to_be32(*temp);
		}
	}

	/* configure the rss indirect table by command queue */
	indir_size = HINIC_RSS_INDIR_SIZE / 2;
	indir_tbl->offset = 0;
	indir_tbl->size = cpu_to_be32(indir_size);

	err = hinic_cmdq_direct_resp(hwdev, HINIC_ACK_TYPE_CMDQ,
				     HINIC_MOD_L2NIC,
				     HINIC_UCODE_CMD_SET_RSS_INDIR_TABLE,
				     cmd_buf, &out_param, 0);
	if (err || out_param != 0) {
		PMD_DRV_LOG(ERR, "Failed to set rss indir table");
		err = -EIO;
		goto free_buf;
	}

	indir_tbl->offset = cpu_to_be32(indir_size);
	indir_tbl->size = cpu_to_be32(indir_size);
	memcpy(indir_tbl->entry, &indir_tbl->entry[indir_size], indir_size);

	err = hinic_cmdq_direct_resp(hwdev, HINIC_ACK_TYPE_CMDQ,
				     HINIC_MOD_L2NIC,
				     HINIC_UCODE_CMD_SET_RSS_INDIR_TABLE,
				     cmd_buf, &out_param, 0);
	if (err || out_param != 0) {
		PMD_DRV_LOG(ERR, "Failed to set rss indir table");
		err = -EIO;
	}

free_buf:
	hinic_free_cmd_buf(hwdev, cmd_buf);

	return err;
}

int hinic_rss_get_indir_tbl(void *hwdev, u32 tmpl_idx, u32 *indir_table)
{
	struct hinic_rss_indir_table rss_cfg;
	u16 out_size = sizeof(rss_cfg);
	int err = 0, i;

	if (!hwdev || !indir_table) {
		PMD_DRV_LOG(ERR, "Hwdev or indir_table is NULL");
		return -EINVAL;
	}

	memset(&rss_cfg, 0, sizeof(rss_cfg));
	rss_cfg.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
	rss_cfg.func_id = hinic_global_func_id(hwdev);
	rss_cfg.template_id = (u8)tmpl_idx;

	err = l2nic_msg_to_mgmt_sync(hwdev,
				     HINIC_PORT_CMD_GET_RSS_TEMPLATE_INDIR_TBL,
				     &rss_cfg, sizeof(rss_cfg), &rss_cfg,
				     &out_size);
	if (err || !out_size || rss_cfg.mgmt_msg_head.status) {
		PMD_DRV_LOG(ERR, "Failed to get indir table, err: %d, status: 0x%x, out size: 0x%x",
			err, rss_cfg.mgmt_msg_head.status, out_size);
		return -EIO;
	}

	hinic_be32_to_cpu(rss_cfg.indir, HINIC_RSS_INDIR_SIZE);
	for (i = 0; i < HINIC_RSS_INDIR_SIZE; i++)
		indir_table[i] = rss_cfg.indir[i];

	return 0;
}

int hinic_rss_cfg(void *hwdev, u8 rss_en, u8 tmpl_idx, u8 tc_num, u8 *prio_tc)
{
	struct hinic_rss_config rss_cfg;
	u16 out_size = sizeof(rss_cfg);
	int err;

	/* micro code required: number of TC should be power of 2 */
	if (!hwdev || !prio_tc || (tc_num & (tc_num - 1))) {
		PMD_DRV_LOG(ERR, "Hwdev or prio_tc is NULL, or tc_num: %u Not power of 2",
			tc_num);
		return -EINVAL;
	}

	memset(&rss_cfg, 0, sizeof(rss_cfg));
	rss_cfg.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
	rss_cfg.func_id = hinic_global_func_id(hwdev);
	rss_cfg.rss_en = rss_en;
	rss_cfg.template_id = tmpl_idx;
	rss_cfg.rq_priority_number = tc_num ? (u8)ilog2(tc_num) : 0;

	memcpy(rss_cfg.prio_tc, prio_tc, HINIC_DCB_UP_MAX);

	err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_RSS_CFG,
				     &rss_cfg, sizeof(rss_cfg), &rss_cfg,
				     &out_size);
	if (err || !out_size || rss_cfg.mgmt_msg_head.status) {
		PMD_DRV_LOG(ERR, "Failed to set rss cfg, err: %d, status: 0x%x, out size: 0x%x",
			err, rss_cfg.mgmt_msg_head.status, out_size);
		return -EIO;
	}

	return 0;
}

/**
 * hinic_rss_template_alloc - Get rss template id from the chip,
 * all functions share 96 templates.
 *
 * @param hwdev
 *   The hardware interface of a nic device.
 * @param tmpl_idx
 *   Index of rss template from chip.
 *
 * @return
 *   0 on success.
 *   negative error value otherwise.
 */
int hinic_rss_template_alloc(void *hwdev, u8 *tmpl_idx)
{
	struct hinic_rss_template_mgmt template_mgmt;
	u16 out_size = sizeof(template_mgmt);
	int err;

	if (!hwdev || !tmpl_idx) {
		PMD_DRV_LOG(ERR, "Hwdev or tmpl_idx is NULL");
		return -EINVAL;
	}

	memset(&template_mgmt, 0, sizeof(template_mgmt));
	template_mgmt.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
	template_mgmt.func_id = hinic_global_func_id(hwdev);
	template_mgmt.cmd = NIC_RSS_CMD_TEMP_ALLOC;

	err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_RSS_TEMP_MGR,
				     &template_mgmt, sizeof(template_mgmt),
				     &template_mgmt, &out_size);
	if (err || !out_size || template_mgmt.mgmt_msg_head.status) {
		PMD_DRV_LOG(ERR, "Failed to alloc rss template, err: %d, status: 0x%x, out size: 0x%x",
			err, template_mgmt.mgmt_msg_head.status, out_size);
		return -EIO;
	}

	*tmpl_idx = template_mgmt.template_id;

	return 0;
}

/**
 * hinic_rss_template_free - Free rss template id to the chip.
 *
 * @param hwdev
 *   The hardware interface of a nic device.
 * @param tmpl_idx
 *   Index of rss template from chip.
 *
 * @return
 *   0 on success.
 *   negative error value otherwise.
 */
int hinic_rss_template_free(void *hwdev, u8 tmpl_idx)
{
	struct hinic_rss_template_mgmt template_mgmt;
	u16 out_size = sizeof(template_mgmt);
	int err;

	if (!hwdev) {
		PMD_DRV_LOG(ERR, "Hwdev is NULL");
		return -EINVAL;
	}

	memset(&template_mgmt, 0, sizeof(template_mgmt));
	template_mgmt.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
	template_mgmt.func_id = hinic_global_func_id(hwdev);
	template_mgmt.template_id = tmpl_idx;
	template_mgmt.cmd = NIC_RSS_CMD_TEMP_FREE;

	err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_RSS_TEMP_MGR,
				     &template_mgmt, sizeof(template_mgmt),
				     &template_mgmt, &out_size);
	if (err || !out_size || template_mgmt.mgmt_msg_head.status) {
		PMD_DRV_LOG(ERR, "Failed to free rss template, err: %d, status: 0x%x, out size: 0x%x",
			err, template_mgmt.mgmt_msg_head.status, out_size);
		return -EIO;
	}

	return 0;
}

/**
 * hinic_set_rx_vhd_mode - Change rx buffer size after initialization.
 *
 * @param hwdev
 *   The hardware interface of a nic device.
 * @param vhd_mode
 *   Not needed.
 * @param rx_buf_sz
 *   receive buffer size.
 *
 * @return
 *   0 on success.
 *   negative error value otherwise.
 */
int hinic_set_rx_vhd_mode(void *hwdev, u16 vhd_mode, u16 rx_buf_sz)
{
	struct hinic_set_vhd_mode vhd_mode_cfg;
	u16 out_size = sizeof(vhd_mode_cfg);
	int err;

	if (!hwdev) {
		PMD_DRV_LOG(ERR, "Hwdev is NULL");
		return -EINVAL;
	}

	memset(&vhd_mode_cfg, 0, sizeof(vhd_mode_cfg));

	vhd_mode_cfg.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
	vhd_mode_cfg.func_id = hinic_global_func_id(hwdev);
	vhd_mode_cfg.vhd_type = vhd_mode;
	vhd_mode_cfg.rx_wqe_buffer_size = rx_buf_sz;

	err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_SET_VHD_CFG,
				     &vhd_mode_cfg, sizeof(vhd_mode_cfg),
				     &vhd_mode_cfg, &out_size);
	if (err || !out_size || vhd_mode_cfg.mgmt_msg_head.status) {
		PMD_DRV_LOG(ERR,
			"Failed to set vhd mode, err: %d, status: 0x%x, out size: 0x%x",
			err, vhd_mode_cfg.mgmt_msg_head.status, out_size);
		return -EIO;
	}

	return 0;
}

int hinic_set_rx_mode(void *hwdev, u32 enable)
{
	struct hinic_rx_mode_config rx_mode_cfg;
	u16 out_size = sizeof(rx_mode_cfg);
	int err;

	if (!hwdev) {
		PMD_DRV_LOG(ERR, "Hwdev is NULL");
		return -EINVAL;
	}

	memset(&rx_mode_cfg, 0, sizeof(rx_mode_cfg));
	rx_mode_cfg.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
	rx_mode_cfg.func_id = hinic_global_func_id(hwdev);
	rx_mode_cfg.rx_mode = enable;

	err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_SET_RX_MODE,
				     &rx_mode_cfg, sizeof(rx_mode_cfg),
				     &rx_mode_cfg, &out_size);
	if (err || !out_size || rx_mode_cfg.mgmt_msg_head.status) {
		PMD_DRV_LOG(ERR, "Failed to set rx mode, err: %d, status: 0x%x, out size: 0x%x",
			err, rx_mode_cfg.mgmt_msg_head.status, out_size);
		return -EIO;
	}

	return 0;
}

/**
 * hinic_get_mgmt_version - Get mgmt module version from chip.
 *
 * @param hwdev
 *   The hardware interface of a nic device.
 * @param fw
 *   Firmware version.
 *
 * @return
 *   0 on success.
 *   negative error value otherwise.
 */
int hinic_get_mgmt_version(void *hwdev, char *fw)
{
	struct hinic_version_info fw_ver;
	u16 out_size = sizeof(fw_ver);
	int err;

	if (!hwdev || !fw) {
		PMD_DRV_LOG(ERR, "Hwdev or fw is NULL");
		return -EINVAL;
	}

	memset(&fw_ver, 0, sizeof(fw_ver));
	fw_ver.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;

	err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_GET_MGMT_VERSION,
				     &fw_ver, sizeof(fw_ver), &fw_ver,
				     &out_size);
	if (err || !out_size || fw_ver.mgmt_msg_head.status) {
		PMD_DRV_LOG(ERR, "Failed to get mgmt version, err: %d, status: 0x%x, out size: 0x%x\n",
			err, fw_ver.mgmt_msg_head.status, out_size);
		return -EIO;
	}

	snprintf(fw, HINIC_MGMT_VERSION_MAX_LEN, "%s", fw_ver.ver);

	return 0;
}

int hinic_set_rx_csum_offload(void *hwdev, u32 en)
{
	struct hinic_checksum_offload rx_csum_cfg;
	u16 out_size = sizeof(rx_csum_cfg);
	int err;

	if (!hwdev) {
		PMD_DRV_LOG(ERR, "Hwdev is NULL");
		return -EINVAL;
	}

	memset(&rx_csum_cfg, 0, sizeof(rx_csum_cfg));
	rx_csum_cfg.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
	rx_csum_cfg.func_id = hinic_global_func_id(hwdev);
	rx_csum_cfg.rx_csum_offload = en;

	err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_SET_RX_CSUM,
				     &rx_csum_cfg, sizeof(rx_csum_cfg),
				     &rx_csum_cfg, &out_size);
	if (err || !out_size || rx_csum_cfg.mgmt_msg_head.status) {
		PMD_DRV_LOG(ERR,
			"Failed to set rx csum offload, err: %d, status: 0x%x, out size: 0x%x",
			err, rx_csum_cfg.mgmt_msg_head.status, out_size);
		return -EIO;
	}

	return 0;
}

int hinic_set_rx_lro(void *hwdev, u8 ipv4_en, u8 ipv6_en, u8 max_wqe_num)
{
	struct hinic_lro_config lro_cfg;
	u16 out_size = sizeof(lro_cfg);
	int err;

	if (!hwdev) {
		PMD_DRV_LOG(ERR, "Hwdev is NULL");
		return -EINVAL;
	}

	memset(&lro_cfg, 0, sizeof(lro_cfg));
	lro_cfg.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
	lro_cfg.func_id = hinic_global_func_id(hwdev);
	lro_cfg.lro_ipv4_en = ipv4_en;
	lro_cfg.lro_ipv6_en = ipv6_en;
	lro_cfg.lro_max_wqe_num = max_wqe_num;

	err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_SET_LRO,
				     &lro_cfg, sizeof(lro_cfg), &lro_cfg,
				     &out_size);
	if (err || !out_size || lro_cfg.mgmt_msg_head.status) {
		PMD_DRV_LOG(ERR, "Failed to set lro offload, err: %d, status: 0x%x, out size: 0x%x",
			err, lro_cfg.mgmt_msg_head.status, out_size);
		return -EIO;
	}

	return 0;
}

int hinic_set_anti_attack(void *hwdev, bool enable)
{
	struct hinic_port_anti_attack_rate rate;
	u16 out_size = sizeof(rate);
	int err;

	if (!hwdev) {
		PMD_DRV_LOG(ERR, "Hwdev is NULL");
		return -EINVAL;
	}

	memset(&rate, 0, sizeof(rate));
	rate.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
	rate.func_id = hinic_global_func_id(hwdev);
	rate.enable = enable;
	rate.cir = ANTI_ATTACK_DEFAULT_CIR;
	rate.xir = ANTI_ATTACK_DEFAULT_XIR;
	rate.cbs = ANTI_ATTACK_DEFAULT_CBS;
	rate.xbs = ANTI_ATTACK_DEFAULT_XBS;

	err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_SET_ANTI_ATTACK_RATE,
				     &rate, sizeof(rate), &rate, &out_size);
	if (err || !out_size || rate.mgmt_msg_head.status) {
		PMD_DRV_LOG(ERR, "Can't %s port Anti-Attack rate limit, err: %d, status: 0x%x, out size: 0x%x",
			(enable ? "enable" : "disable"), err,
			rate.mgmt_msg_head.status, out_size);
		return -EIO;
	}

	return 0;
}

/* Set autoneg status and restart port link status */
int hinic_reset_port_link_cfg(void *hwdev)
{
	struct hinic_reset_link_cfg reset_cfg;
	u16 out_size = sizeof(reset_cfg);
	int err;

	memset(&reset_cfg, 0, sizeof(reset_cfg));
	reset_cfg.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
	reset_cfg.func_id = hinic_global_func_id(hwdev);

	err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_RESET_LINK_CFG,
				     &reset_cfg, sizeof(reset_cfg),
				     &reset_cfg, &out_size);
	if (err || !out_size || reset_cfg.mgmt_msg_head.status) {
		PMD_DRV_LOG(ERR, "Reset port link configure failed, err: %d, status: 0x%x, out size: 0x%x",
			err, reset_cfg.mgmt_msg_head.status, out_size);
		return -EIO;
	}

	return 0;
}

/**
 * hinic_vf_func_init - Register VF to PF.
 *
 * @param hwdev
 *   The hardware interface of a nic device.
 *
 * @return
 *   0 on success.
 *   negative error value otherwise.
 */
int hinic_vf_func_init(struct hinic_hwdev *hwdev)
{
	int err, state = 0;

	if (!HINIC_IS_VF(hwdev))
		return 0;

	err = hinic_mbox_to_pf(hwdev, HINIC_MOD_L2NIC,
			HINIC_PORT_CMD_VF_REGISTER, &state, sizeof(state),
			NULL, NULL, 0);
	if (err) {
		PMD_DRV_LOG(ERR, "Fail to register vf");
		return err;
	}

	return 0;
}

/**
 * hinic_vf_func_free - Unregister VF from PF.
 *
 * @param hwdev
 *   The hardware interface of a nic device.
 */
void hinic_vf_func_free(struct hinic_hwdev *hwdev)
{
	int err;

	if (hinic_func_type(hwdev) != TYPE_VF)
		return;

	err = hinic_mbox_to_pf(hwdev, HINIC_MOD_L2NIC,
				HINIC_PORT_CMD_VF_UNREGISTER, &err, sizeof(err),
				NULL, NULL, 0);
	if (err)
		PMD_DRV_LOG(ERR, "Fail to unregister VF, err: %d", err);
}

int hinic_set_fast_recycle_mode(void *hwdev, u8 mode)
{
	struct hinic_fast_recycled_mode fast_recycled_mode;
	u16 out_size = sizeof(fast_recycled_mode);
	int err;

	if (!hwdev) {
		PMD_DRV_LOG(ERR, "Hwdev is NULL");
		return -EINVAL;
	}

	memset(&fast_recycled_mode, 0, sizeof(fast_recycled_mode));
	fast_recycled_mode.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
	fast_recycled_mode.func_id = hinic_global_func_id(hwdev);
	fast_recycled_mode.fast_recycled_mode = mode;

	err = hinic_msg_to_mgmt_sync(hwdev, HINIC_MOD_COMM,
				     HINIC_MGMT_CMD_FAST_RECYCLE_MODE_SET,
				     &fast_recycled_mode,
				     sizeof(fast_recycled_mode),
				     &fast_recycled_mode, &out_size, 0);
	if (err || fast_recycled_mode.mgmt_msg_head.status || !out_size) {
		PMD_DRV_LOG(ERR, "Failed to set recycle mode, err: %d, status: 0x%x, out size: 0x%x",
			err, fast_recycled_mode.mgmt_msg_head.status, out_size);
		return -EIO;
	}

	return 0;
}

int hinic_clear_vport_stats(struct hinic_hwdev *hwdev)
{
	struct hinic_clear_vport_stats clear_vport_stats;
	u16 out_size = sizeof(clear_vport_stats);
	int err;

	if (!hwdev) {
		PMD_DRV_LOG(ERR, "Hwdev is NULL");
		return -EINVAL;
	}

	memset(&clear_vport_stats, 0, sizeof(clear_vport_stats));
	clear_vport_stats.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
	clear_vport_stats.func_id = hinic_global_func_id(hwdev);

	err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_CLEAN_VPORT_STAT,
				     &clear_vport_stats,
				     sizeof(clear_vport_stats),
				     &clear_vport_stats, &out_size);
	if (err || !out_size || clear_vport_stats.mgmt_msg_head.status) {
		PMD_DRV_LOG(ERR, "Failed to clear vport statistics, err: %d, status: 0x%x, out size: 0x%x",
			err, clear_vport_stats.mgmt_msg_head.status, out_size);
		return -EIO;
	}

	return 0;
}

int hinic_clear_phy_port_stats(struct hinic_hwdev *hwdev)
{
	struct hinic_clear_port_stats clear_phy_port_stats;
	u16 out_size = sizeof(clear_phy_port_stats);
	int err;

	if (!hwdev) {
		PMD_DRV_LOG(ERR, "Hwdev is NULL");
		return -EINVAL;
	}

	memset(&clear_phy_port_stats, 0, sizeof(clear_phy_port_stats));
	clear_phy_port_stats.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
	clear_phy_port_stats.func_id = hinic_global_func_id(hwdev);

	err = l2nic_msg_to_mgmt_sync(hwdev,
				     HINIC_PORT_CMD_CLEAR_PORT_STATISTICS,
				     &clear_phy_port_stats,
				     sizeof(clear_phy_port_stats),
				     &clear_phy_port_stats, &out_size);
	if (err || !out_size || clear_phy_port_stats.mgmt_msg_head.status) {
		PMD_DRV_LOG(ERR, "Failed to clear phy port statistics, err: %d, status: 0x%x, out size: 0x%x",
			err, clear_phy_port_stats.mgmt_msg_head.status,
			out_size);
		return -EIO;
	}

	return 0;
}

int hinic_set_link_status_follow(void *hwdev,
				 enum hinic_link_follow_status status)
{
	struct hinic_set_link_follow follow;
	u16 out_size = sizeof(follow);
	int err;

	if (!hwdev)
		return -EINVAL;

	if (HINIC_IS_VF((struct hinic_hwdev *)hwdev))
		return 0;

	if (status >= HINIC_LINK_FOLLOW_STATUS_MAX) {
		PMD_DRV_LOG(ERR, "Invalid link follow status: %d", status);
		return -EINVAL;
	}

	memset(&follow, 0, sizeof(follow));
	follow.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
	follow.func_id = hinic_global_func_id(hwdev);
	follow.follow_status = status;

	err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_SET_LINK_FOLLOW,
				     &follow, sizeof(follow),
				     &follow, &out_size);
	if ((follow.mgmt_msg_head.status != HINIC_MGMT_CMD_UNSUPPORTED &&
	     follow.mgmt_msg_head.status) || err || !out_size) {
		PMD_DRV_LOG(ERR,
			"Failed to set link status follow phy port status, err: %d, status: 0x%x, out size: 0x%x",
			err, follow.mgmt_msg_head.status, out_size);
		return -EIO;
	}

	return follow.mgmt_msg_head.status;
}

int hinic_get_link_mode(void *hwdev, u32 *supported, u32 *advertised)
{
	struct hinic_link_mode_cmd link_mode;
	u16 out_size = sizeof(link_mode);
	int err;

	if (!hwdev || !supported || !advertised)
		return -EINVAL;

	memset(&link_mode, 0, sizeof(link_mode));
	link_mode.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
	link_mode.func_id = hinic_global_func_id(hwdev);

	err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_GET_LINK_MODE,
				     &link_mode, sizeof(link_mode),
				     &link_mode, &out_size);
	if (err || !out_size || link_mode.mgmt_msg_head.status) {
		PMD_DRV_LOG(ERR,
			"Failed to get link mode, err: %d, status: 0x%x, out size: 0x%x",
			err, link_mode.mgmt_msg_head.status, out_size);
		return -EIO;
	}

	*supported = link_mode.supported;
	*advertised = link_mode.advertised;

	return 0;
}

/**
 * hinic_set_xsfp_tx_status - Enable or disable the fiber in
 * tx direction when set link up or down.
 *
 * @param hwdev
 *   The hardware interface of a nic device.
 * @param enable
 *   Enable or Disable.
 *
 * @return
 *   0 on success.
 *   negative error value otherwise.
 */
int hinic_set_xsfp_tx_status(void *hwdev, bool enable)
{
	struct hinic_set_xsfp_status xsfp_status;
	u16 out_size = sizeof(struct hinic_set_xsfp_status);
	int err;

	memset(&xsfp_status, 0, sizeof(xsfp_status));
	xsfp_status.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
	xsfp_status.port_id = hinic_global_func_id(hwdev);
	xsfp_status.xsfp_tx_dis = ((enable == 0) ? 1 : 0);

	err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_SET_XSFP_STATUS,
		&xsfp_status, sizeof(struct hinic_set_xsfp_status),
		&xsfp_status, &out_size);
	if (err || !out_size || xsfp_status.mgmt_msg_head.status) {
		PMD_DRV_LOG(ERR,
			"Failed to %s port xsfp status, err: %d, status: 0x%x, out size: 0x%x\n",
			enable ? "Disable" : "Enable", err,
			xsfp_status.mgmt_msg_head.status, out_size);
		return -EIO;
	}

	return 0;
}

/**
 * hinic_flush_qp_res - Flush tx && rx chip resources in case of set vport
 * fake failed when device start.
 *
 * @param hwdev
 *   The hardware interface of a nic device.
 *
 * @return
 *   0 on success.
 *   negative error value otherwise.
 */
int hinic_flush_qp_res(void *hwdev)
{
	struct hinic_clear_qp_resource qp_res;
	u16 out_size = sizeof(qp_res);
	int err;

	memset(&qp_res, 0, sizeof(qp_res));
	qp_res.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
	qp_res.func_id = hinic_global_func_id(hwdev);

	err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_CLEAR_QP_RES,
				     &qp_res, sizeof(qp_res), &qp_res,
				     &out_size);
	if (err || !out_size || qp_res.mgmt_msg_head.status) {
		PMD_DRV_LOG(ERR, "Failed to clear sq resources, err: %d, status: 0x%x, out size: 0x%x",
			err, qp_res.mgmt_msg_head.status, out_size);
		return -EIO;
	}

	return 0;
}

/**
 * hinic_vf_get_default_cos - Get default cos of VF.
 *
 * @param hwdev
 *   The hardware interface of a nic device.
 * @param cos_id
 *   Cos value.
 *
 * @return
 *   0 on success.
 *   negative error value otherwise.
 */
int hinic_vf_get_default_cos(struct hinic_hwdev *hwdev, u8 *cos_id)
{
	struct hinic_vf_default_cos vf_cos;
	u16 out_size = sizeof(vf_cos);
	int err;

	memset(&vf_cos, 0, sizeof(vf_cos));
	vf_cos.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;

	err = hinic_msg_to_mgmt_sync(hwdev, HINIC_MOD_L2NIC,
				     HINIC_PORT_CMD_GET_VF_COS, &vf_cos,
				     sizeof(vf_cos), &vf_cos, &out_size, 0);
	if (err || !out_size || vf_cos.mgmt_msg_head.status) {
		PMD_DRV_LOG(ERR, "Get VF default cos failed, err: %d, status: 0x%x, out size: 0x%x",
			err, vf_cos.mgmt_msg_head.status, out_size);
		return -EIO;
	}
	*cos_id = vf_cos.state.default_cos;

	return 0;
}

/**
 * hinic_set_fdir_filter - Set fdir filter for control path
 * packet to notify firmware.
 *
 * @param hwdev
 *   The hardware interface of a nic device.
 * @param filter_type
 *   Packet type to filter.
 * @param qid
 *   Rx qid to filter.
 * @param type_enable
 *   The status of pkt type filter.
 * @param enable
 *   Fdir function Enable or Disable.
 * @return
 *   0 on success,
 *   negative error value otherwise.
 */
int hinic_set_fdir_filter(void *hwdev, u8 filter_type, u8 qid, u8 type_enable,
			  bool enable)
{
	struct hinic_port_qfilter_info port_filer_cmd;
	u16 out_size = sizeof(port_filer_cmd);
	int err;

	if (!hwdev)
		return -EINVAL;

	memset(&port_filer_cmd, 0, sizeof(port_filer_cmd));
	port_filer_cmd.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
	port_filer_cmd.func_id = hinic_global_func_id(hwdev);
	port_filer_cmd.filter_enable = (u8)enable;
	port_filer_cmd.filter_type = filter_type;
	port_filer_cmd.qid = qid;
	port_filer_cmd.filter_type_enable = type_enable;
	port_filer_cmd.fdir_flag = 0;

	err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_Q_FILTER,
			&port_filer_cmd, sizeof(port_filer_cmd),
			&port_filer_cmd, &out_size);
	if (err || !out_size || port_filer_cmd.mgmt_msg_head.status) {
		PMD_DRV_LOG(ERR, "Set port Q filter failed, err: %d, status: 0x%x, out size: 0x%x, type: 0x%x,"
			" enable: 0x%x, qid: 0x%x, filter_type_enable: 0x%x\n",
			err, port_filer_cmd.mgmt_msg_head.status, out_size,
			filter_type, enable, qid, type_enable);
		return -EIO;
	}

	return 0;
}

/**
 * hinic_set_normal_filter - Set fdir filter for IO path packet.
 *
 * @param hwdev
 *   The hardware interface of a nic device.
 * @param qid
 *   Rx qid to filter.
 * @param normal_type_enable
 *   IO path packet function Enable or Disable
 * @param key
 *   IO path packet filter key value, such as DIP from pkt.
 * @param enable
 *   Fdir function Enable or Disable.
 * @param flag
 *   Filter flag, such as dip or others.
 * @return
 *   0 on success,
 *   negative error value otherwise.
 */
int hinic_set_normal_filter(void *hwdev, u8 qid, u8 normal_type_enable,
				u32 key, bool enable, u8 flag)
{
	struct hinic_port_qfilter_info port_filer_cmd;
	u16 out_size = sizeof(port_filer_cmd);
	int err;

	if (!hwdev)
		return -EINVAL;

	memset(&port_filer_cmd, 0, sizeof(port_filer_cmd));
	port_filer_cmd.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
	port_filer_cmd.func_id = hinic_global_func_id(hwdev);
	port_filer_cmd.filter_enable = (u8)enable;
	port_filer_cmd.qid = qid;
	port_filer_cmd.normal_type_enable = normal_type_enable;
	port_filer_cmd.fdir_flag = flag; /* fdir flag: support dip */
	port_filer_cmd.key = key;

	err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_Q_FILTER,
			&port_filer_cmd, sizeof(port_filer_cmd),
			&port_filer_cmd, &out_size);
	if (err || !out_size || port_filer_cmd.mgmt_msg_head.status) {
		PMD_DRV_LOG(ERR, "Set normal filter failed, err: %d, status: 0x%x, out size: 0x%x, fdir_flag: 0x%x,"
			" enable: 0x%x, qid: 0x%x, normal_type_enable: 0x%x, key:0x%x\n",
			err, port_filer_cmd.mgmt_msg_head.status, out_size,
			flag, enable, qid, normal_type_enable, key);
		return -EIO;
	}

	return 0;
}

/**
 * hinic_set_fdir_tcam - Set fdir filter for control packet
 * by tcam table to notify hardware.
 *
 * @param hwdev
 *   The hardware interface of a nic device.
 * @param type_mask
 *   Index of TCAM.
 * @param filter_rule
 *   TCAM rule for control packet, such as lacp or bgp.
 * @param filter_action
 *   TCAM action for control packet, such as accept or drop.
 * @return
 *   0 on success,
 *   negative error value otherwise.
 */
int hinic_set_fdir_tcam(void *hwdev, u16 type_mask,
			struct tag_pa_rule *filter_rule,
			struct tag_pa_action *filter_action)
{
	struct hinic_fdir_tcam_info port_tcam_cmd;
	u16 out_size = sizeof(port_tcam_cmd);
	int err;

	if (!hwdev)
		return -EINVAL;

	memset(&port_tcam_cmd, 0, sizeof(port_tcam_cmd));
	port_tcam_cmd.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
	port_tcam_cmd.tcam_index = type_mask;
	port_tcam_cmd.flag = TCAM_SET;
	memcpy((void *)&port_tcam_cmd.filter_rule,
		(void *)filter_rule, sizeof(struct tag_pa_rule));
	memcpy((void *)&port_tcam_cmd.filter_action,
		(void *)filter_action, sizeof(struct tag_pa_action));

	err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_TCAM_FILTER,
			&port_tcam_cmd, sizeof(port_tcam_cmd),
			&port_tcam_cmd, &out_size);
	if (err || !out_size || port_tcam_cmd.mgmt_msg_head.status) {
		PMD_DRV_LOG(ERR, "Set tcam table failed, err: %d, status: 0x%x, out size: 0x%x",
			err, port_tcam_cmd.mgmt_msg_head.status, out_size);
		return -EIO;
	}

	return 0;
}

/**
 * hinic_clear_fdir_tcam - Clear fdir filter TCAM table for control packet.
 *
 * @param hwdev
 *   The hardware interface of a nic device.
 * @param type_mask
 *   Index of TCAM.
 * @return
 *   0 on success,
 *   negative error value otherwise.
 */
int hinic_clear_fdir_tcam(void *hwdev, u16 type_mask)
{
	struct hinic_fdir_tcam_info port_tcam_cmd;
	u16 out_size = sizeof(port_tcam_cmd);
	int err;

	if (!hwdev)
		return -EINVAL;

	memset(&port_tcam_cmd, 0, sizeof(port_tcam_cmd));
	port_tcam_cmd.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
	port_tcam_cmd.tcam_index = type_mask;
	port_tcam_cmd.flag = TCAM_CLEAR;

	err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_TCAM_FILTER,
			&port_tcam_cmd, sizeof(port_tcam_cmd),
			&port_tcam_cmd, &out_size);
	if (err || !out_size || port_tcam_cmd.mgmt_msg_head.status) {
		PMD_DRV_LOG(ERR, "Clear tcam table failed, err: %d, status: 0x%x, out size: 0x%x",
			err, port_tcam_cmd.mgmt_msg_head.status, out_size);
		return -EIO;
	}

	return 0;
}

int hinic_add_tcam_rule(void *hwdev, struct tag_tcam_cfg_rule *tcam_rule)
{
	u16 out_size = sizeof(struct tag_fdir_add_rule_cmd);
	struct tag_fdir_add_rule_cmd tcam_cmd;
	int err;

	if (!hwdev) {
		PMD_DRV_LOG(ERR, "Hwdev is NULL");
		return -EINVAL;
	}

	if (tcam_rule->index >= HINIC_MAX_TCAM_RULES_NUM) {
		PMD_DRV_LOG(ERR, "Tcam rules num to add is invalid");
		return -EINVAL;
	}

	memset(&tcam_cmd, 0, sizeof(struct tag_fdir_add_rule_cmd));
	tcam_cmd.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
	memcpy((void *)&tcam_cmd.rule, (void *)tcam_rule,
		sizeof(struct tag_tcam_cfg_rule));

	err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_UP_TC_ADD_FLOW,
				&tcam_cmd, sizeof(tcam_cmd),
				&tcam_cmd, &out_size);
	if (err || tcam_cmd.mgmt_msg_head.status || !out_size) {
		PMD_DRV_LOG(ERR,
			"Add tcam rule failed, err: %d, status: 0x%x, out size: 0x%x",
			err, tcam_cmd.mgmt_msg_head.status, out_size);
		return -EIO;
	}

	return 0;
}

int hinic_del_tcam_rule(void *hwdev, u32 index)
{
	u16 out_size = sizeof(struct tag_fdir_del_rule_cmd);
	struct tag_fdir_del_rule_cmd tcam_cmd;
	int err;

	if (!hwdev) {
		PMD_DRV_LOG(ERR, "Hwdev is NULL");
		return -EINVAL;
	}

	if (index >= HINIC_MAX_TCAM_RULES_NUM) {
		PMD_DRV_LOG(ERR, "Tcam rules num to del is invalid");
		return -EINVAL;
	}

	memset(&tcam_cmd, 0, sizeof(struct tag_fdir_del_rule_cmd));
	tcam_cmd.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
	tcam_cmd.index_start = index;
	tcam_cmd.index_num = 1;

	err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_UP_TC_DEL_FLOW,
				&tcam_cmd, sizeof(tcam_cmd),
				&tcam_cmd, &out_size);
	if (err || tcam_cmd.mgmt_msg_head.status || !out_size) {
		PMD_DRV_LOG(ERR,
			"Del tcam rule failed, err: %d, status: 0x%x, out size: 0x%x",
			err, tcam_cmd.mgmt_msg_head.status, out_size);
		return -EIO;
	}

	return 0;
}

static int hinic_mgmt_tcam_block(void *hwdev, u8 alloc_en,
				u8 block_type, u16 *index)
{
	struct hinic_cmd_ctrl_tcam_block tcam_block_info;
	u16 out_size = sizeof(struct hinic_cmd_ctrl_tcam_block);
	struct hinic_hwdev *nic_hwdev = (struct hinic_hwdev *)hwdev;
	int err;

	if (!hwdev) {
		PMD_DRV_LOG(ERR, "Hwdev is NULL");
		return -EINVAL;
	}

	memset(&tcam_block_info, 0, sizeof(struct hinic_cmd_ctrl_tcam_block));
	tcam_block_info.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
	tcam_block_info.func_id = hinic_global_func_id(hwdev);
	tcam_block_info.alloc_en = alloc_en;
	tcam_block_info.tcam_type = block_type;
	tcam_block_info.tcam_block_index = *index;

	err = l2nic_msg_to_mgmt_sync(hwdev,
				HINIC_PORT_CMD_UP_TC_CTRL_TCAM_BLOCK,
				&tcam_block_info, sizeof(tcam_block_info),
				&tcam_block_info, &out_size);
	if (tcam_block_info.mgmt_msg_head.status ==
		HINIC_MGMT_CMD_UNSUPPORTED) {
		err = HINIC_MGMT_CMD_UNSUPPORTED;
		PMD_DRV_LOG(INFO, "Firmware/uP doesn't support alloc or del tcam block");
		return err;
	} else if ((err == HINIC_MBOX_VF_CMD_ERROR) &&
			(HINIC_IS_VF(nic_hwdev))) {
		err = HINIC_MGMT_CMD_UNSUPPORTED;
		PMD_DRV_LOG(INFO, "VF doesn't support alloc and del tcam block.");
		return err;
	} else if (err || (!out_size) || tcam_block_info.mgmt_msg_head.status) {
		PMD_DRV_LOG(ERR,
			"Set tcam block failed, err: %d, status: 0x%x, out size: 0x%x",
			err, tcam_block_info.mgmt_msg_head.status, out_size);
		return -EIO;
	}

	if (alloc_en)
		*index = tcam_block_info.tcam_block_index;

	return 0;
}

int hinic_alloc_tcam_block(void *hwdev, u8 block_type, u16 *index)
{
	return hinic_mgmt_tcam_block(hwdev, HINIC_TCAM_BLOCK_ENABLE,
				block_type, index);
}

int hinic_free_tcam_block(void *hwdev, u8 block_type, u16 *index)
{
	return hinic_mgmt_tcam_block(hwdev, HINIC_TCAM_BLOCK_DISABLE,
				block_type, index);
}

int hinic_flush_tcam_rule(void *hwdev)
{
	struct hinic_cmd_flush_tcam_rules tcam_flush;
	u16 out_size = sizeof(struct hinic_cmd_flush_tcam_rules);
	struct hinic_hwdev *nic_hwdev = (struct hinic_hwdev *)hwdev;
	int err;

	if (!hwdev) {
		PMD_DRV_LOG(ERR, "Hwdev is NULL");
		return -EINVAL;
	}

	memset(&tcam_flush, 0, sizeof(struct hinic_cmd_flush_tcam_rules));
	tcam_flush.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
	tcam_flush.func_id = hinic_global_func_id(hwdev);

	err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_UP_TC_FLUSH_TCAM,
			&tcam_flush, sizeof(struct hinic_cmd_flush_tcam_rules),
			&tcam_flush, &out_size);
	if (tcam_flush.mgmt_msg_head.status == HINIC_MGMT_CMD_UNSUPPORTED) {
		err = HINIC_MGMT_CMD_UNSUPPORTED;
		PMD_DRV_LOG(INFO, "Firmware/uP doesn't support flush tcam fdir");
	} else if ((err == HINIC_MBOX_VF_CMD_ERROR) &&
			(HINIC_IS_VF(nic_hwdev))) {
		err = HINIC_MGMT_CMD_UNSUPPORTED;
		PMD_DRV_LOG(INFO, "VF doesn't support flush tcam fdir");
	} else if (err || (!out_size) || tcam_flush.mgmt_msg_head.status) {
		PMD_DRV_LOG(ERR,
			"Flush tcam fdir rules failed, err: %d, status: 0x%x, out size: 0x%x",
			err, tcam_flush.mgmt_msg_head.status, out_size);
		err = -EIO;
	}

	return err;
}

int hinic_set_fdir_tcam_rule_filter(void *hwdev, bool enable)
{
	struct hinic_port_tcam_info port_tcam_cmd;
	u16 out_size = sizeof(port_tcam_cmd);
	int err;

	if (!hwdev)
		return -EINVAL;

	memset(&port_tcam_cmd, 0, sizeof(port_tcam_cmd));
	port_tcam_cmd.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
	port_tcam_cmd.func_id = hinic_global_func_id(hwdev);
	port_tcam_cmd.tcam_enable = (u8)enable;

	err = l2nic_msg_to_mgmt_sync(hwdev, HINIC_PORT_CMD_UP_TC_ENABLE,
			&port_tcam_cmd, sizeof(port_tcam_cmd),
			&port_tcam_cmd, &out_size);
	if ((port_tcam_cmd.mgmt_msg_head.status != HINIC_MGMT_CMD_UNSUPPORTED &&
		port_tcam_cmd.mgmt_msg_head.status) || err || !out_size) {
		if (err == HINIC_MBOX_VF_CMD_ERROR &&
			HINIC_IS_VF((struct hinic_hwdev *)hwdev)) {
			err = HINIC_MGMT_CMD_UNSUPPORTED;
			PMD_DRV_LOG(WARNING, "VF doesn't support setting fdir tcam filter");
			return err;
		}
		PMD_DRV_LOG(ERR, "Set fdir tcam filter failed, err: %d, "
			"status: 0x%x, out size: 0x%x, enable: 0x%x",
			err, port_tcam_cmd.mgmt_msg_head.status, out_size,
			enable);
		return -EIO;
	}

	if (port_tcam_cmd.mgmt_msg_head.status == HINIC_MGMT_CMD_UNSUPPORTED) {
		err = HINIC_MGMT_CMD_UNSUPPORTED;
		PMD_DRV_LOG(WARNING, "Fw doesn't support setting fdir tcam filter");
	}

	return err;
}