Files @ 89a4bb14d085
Branch filter:

Location: vmkdrivers/vmkdrivers/src_9/drivers/net/bnx2x/bnx2x_esx.c

unknown
ESXi-5.5-U1
   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
/* bnx2x_esx.c: Broadcom Everest network driver.
 *
 * Copyright 2008-2013 Broadcom Corporation
 *
 * Portions Copyright (c) VMware, Inc. 2008-2013, All Rights Reserved.
 * Copyright (c) 2007-2013 Broadcom Corporation
 *
 * Unless you and Broadcom execute a separate written software license
 * agreement governing use of this software, this software is licensed to you
 * under the terms of the GNU General Public License version 2, available
 * at http://www.gnu.org/licenses/old-licenses/gpl-2.0.html (the "GPL").
 *
 * Notwithstanding the above, under no circumstances may you combine this
 * software in any way with any other Broadcom software provided under a
 * license other than the GPL, without Broadcom's express prior written
 * consent.
 *
 * Maintained by: Benjamin Li <benli@broadcom.com>
 * NetQueue code from VMware
 * IOCTL code by: Benjamin Li
 * PASSTHRU code by: Shmulik Ravid
 *
 */

#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/pci.h>
#include <linux/netdevice.h>
#include <linux/delay.h>
#include <linux/ethtool.h>
#ifdef __LINUX_MUTEX_H
#include <linux/mutex.h>
#endif
#include <linux/version.h>

#include "bnx2x.h"
#include "bnx2x_cmn.h"
#include "bnx2x_esx.h"
#include "bnx2x_init.h"

/* empty implementations for thes kernel primitives because they seems to be compiled out */
inline void local_bh_enable(void) {}
inline void local_bh_disable(void) {}

#if defined(VMX86_DEBUG)
int psod_on_panic = 1;
#else
int psod_on_panic;
#endif /* VMX86_DEBUG */
module_param(psod_on_panic, int, 0);
MODULE_PARM_DESC(psod_on_panic, " PSOD on panic");

#ifdef BNX2X_NETQ
static int multi_rx_filters = -1;
module_param(multi_rx_filters, int, 0);
MODULE_PARM_DESC(multi_rx_filters, "Define the number of RX filters per "
				   "NetQueue: (allowed values: -1 to "
				   "Max # of RX filters per NetQueue, "
				   "-1: use the default number of RX filters; "
				   "0: Disable use of multiple RX filters; "
				   "1..Max # the number of RX filters "
				   "per NetQueue: will force the number "
				   "of RX filters to use for NetQueue");
#endif

#ifdef BNX2X_VMWARE_BMAPILNX
int
bnx2x_ioctl_cim(struct net_device *dev, struct ifreq *ifr)
{
	struct bnx2x *bp = netdev_priv(dev);
	void __user *useraddr = ifr->ifr_data;
	struct bnx2x_ioctl_req req;
	int rc = 0;
	u32 val;

	/* We assume all userworld apps are 32 bits ==> ifr->ifr_data is
	   a 32 bit pointer so we truncate useraddr */
	unsigned long uaddr32 = (unsigned long)useraddr & 0xffffffff;

	if (copy_from_user(&req, (void __user *)uaddr32, sizeof(req))) {
		BNX2X_ERR("%s: bnx2x_ioctl() could not copy from user\n",
			  bp->dev->name);
		return -EFAULT;
	}

	DP(NETIF_MSG_LINK, "%s: bnx2x_ioctl() CIM cmd: 0x%x\n",
	       bp->dev->name, req.cmd);

	switch(req.cmd) {
	case BNX2X_VMWARE_CIM_CMD_ENABLE_NIC:
		DP(NETIF_MSG_LINK, "%s: bnx2x_ioctl() enable NIC\n",
		       bp->dev->name);

		rc = bnx2x_open(bp->dev);
		break;
	case BNX2X_VMWARE_CIM_CMD_DISABLE_NIC:
		DP(NETIF_MSG_LINK, "%s: bnx2x_ioctl() enable NIC\n",
		       bp->dev->name);

		rc = bnx2x_close(bp->dev);
		break;
	case BNX2X_VMWARE_CIM_CMD_REG_READ: {
		u32 mem_len;

		mem_len = pci_resource_len(bp->pdev, 0);
		if(mem_len < req.cmd_req.reg_read.reg_offset) {
			BNX2X_ERR("%s: bnx2x_ioctl() reg read: "
				  "out of range: max reg: 0x%x "
				  "req reg: 0x%x\n",
				bp->dev->name,
				mem_len, req.cmd_req.reg_read.reg_offset);
			rc = -EINVAL;
			break;
		}

		val = REG_RD(bp, req.cmd_req.reg_read.reg_offset);

		DP(NETIF_MSG_LINK, "%s: bnx2x_ioctl() reg read: "
				   "reg: 0x%x value:0x%x",
		       bp->dev->name,
		       req.cmd_req.reg_read.reg_offset,
		       req.cmd_req.reg_read.reg_value);

		req.cmd_req.reg_read.reg_value = val;

		break;
	} case BNX2X_VMWARE_CIM_CMD_REG_WRITE: {
		u32 mem_len;

		mem_len = pci_resource_len(bp->pdev, 0);
		if(mem_len < req.cmd_req.reg_write.reg_offset) {
			BNX2X_ERR("%s: bnx2x_ioctl() reg write: "
				  "out of range: max reg: 0x%x "
				  "req reg: 0x%x\n",
				bp->dev->name,
				mem_len, req.cmd_req.reg_write.reg_offset);
			rc = -EINVAL;
			break;
		}
		DP(NETIF_MSG_LINK, "%s: bnx2x_ioctl() reg write: "
				   "reg: 0x%x value:0x%x",
		       bp->dev->name,
		       req.cmd_req.reg_write.reg_offset,
		       req.cmd_req.reg_write.reg_value);

		REG_WR(bp, req.cmd_req.reg_write.reg_offset,
			   req.cmd_req.reg_write.reg_value);

		break;
	} case BNX2X_VMWARE_CIM_CMD_GET_NIC_PARAM:
		DP(NETIF_MSG_LINK, "%s: bnx2x_ioctl() get NIC param\n",
		       bp->dev->name);

		req.cmd_req.get_nic_param.mtu = dev->mtu;
		memcpy(req.cmd_req.get_nic_param.current_mac_addr,
		       dev->dev_addr,
		       sizeof(req.cmd_req.get_nic_param.current_mac_addr));
		break;
	case BNX2X_VMWARE_CIM_CMD_GET_NIC_STATUS:
		DP(NETIF_MSG_LINK, "%s: bnx2x_ioctl() get NIC status\n",
		       bp->dev->name);

		req.cmd_req.get_nic_status.nic_status = netif_running(dev);
		break;
	default:
		BNX2X_ERR("%s: bnx2x_ioctl() unknown req.cmd: 0x%x\n",
		       bp->dev->name, req.cmd);
		rc = -EINVAL;
	}

	if (rc == 0 &&
	    copy_to_user((void __user *)uaddr32, &req, sizeof(req))) {
		BNX2X_ERR("%s: bnx2x_ioctl() couldn't copy to user "
			  "bnx2_ioctl_req\n", bp->dev->name);
		return -EFAULT;
	}

	return rc;
}
#endif

#ifdef BNX2X_NETQ

/* not including the default queue - qid 0*/
static inline int bnx2x_netq_valid_qid(struct bnx2x *bp, u16 qid)
{
	return ((qid > 0) && (qid <= BNX2X_NUM_NETQUEUES(bp)));
}

static int bnx2x_num_active_rx_mac_filters(struct bnx2x_fastpath *fp)

{
	struct bnx2x *bp = fp->bp;
	int i, count = 0;

	for (i = 0; i < bp->number_of_mac_filters; i++) {
		if (BNX2X_IS_NETQ_RX_FILTER_ACTIVE(fp, i))
			count++;
	}

	return count;
}

static int bnx2x_is_last_rx_mac_filter(struct bnx2x_fastpath *fp)
{
	return (bnx2x_num_active_rx_mac_filters(fp) == 1 ? 1 : 0);
}

static void bnx2x_add_rx_mac_entry(struct netq_mac_filter *filter,
				  u8 *mac)
{
	memcpy(filter->mac, mac, ETH_ALEN);
	filter->flags |= BNX2X_NETQ_RX_FILTER_ACTIVE;
}

static void bnx2x_clear_rx_mac_entry(struct netq_mac_filter *filter)
{
	memset(filter->mac, 0, ETH_ALEN);
	filter->flags &= ~BNX2X_NETQ_RX_FILTER_ACTIVE;
}

static int bnx2x_find_rx_mac_filter_add(struct bnx2x *bp,
					struct bnx2x_fastpath *fp, u8 *mac)
{
	int i;

	if (fp->mac_filters == NULL) {
		if (bp->number_of_mac_filters == 0) {
			DP(BNX2X_MSG_NETQ, "number_of_mac_filters == 0\n");
			return -ENODEV;
		}

		fp->mac_filters = kzalloc(sizeof(struct netq_mac_filter) *
					  bp->number_of_mac_filters,
					  GFP_ATOMIC);
		if (fp->mac_filters == NULL) {
			DP(BNX2X_MSG_NETQ, "Failed to allocate "
					   "RX MAC filter table\n");
			return -ENOMEM;
		}
		DP(BNX2X_MSG_NETQ, "Allocated RX MAC filter table with %d "
				   "entries on RX queue %d\n",
				   bp->number_of_mac_filters, fp->index);

		bnx2x_add_rx_mac_entry(&fp->mac_filters[0], mac);
		return 0;
	}

	for (i = 0; i < bp->number_of_mac_filters; i++) {
		if (!BNX2X_IS_NETQ_RX_FILTER_ACTIVE(fp, i)) {
			bnx2x_add_rx_mac_entry(&fp->mac_filters[i], mac);
			return i;
		}
	}

	DP(BNX2X_MSG_NETQ, "RX filters on NetQ RX Queue %d exhausted\n",
	   fp->index);
	return -ENODEV;
}

static void bnx2x_remove_rx_mac_filter(struct bnx2x *bp,
				       struct bnx2x_fastpath *fp, u16 fid,
				       int is_last_mac_filter)
{
	fp->mac_filters[fid].flags &= ~BNX2X_NETQ_RX_FILTER_ACTIVE;

	if (is_last_mac_filter) {
		fp->netq_flags &= ~BNX2X_NETQ_RX_QUEUE_ACTIVE;
		kfree(fp->mac_filters);
		fp->mac_filters = NULL;

		DP(BNX2X_MSG_NETQ, "Freed RX MAC filter table\n");
	}
}

void bnx2x_reserve_netq_feature(struct bnx2x *bp)
{
	int i;

#if (VMWARE_ESX_DDK_VERSION >= 41000)
	int num_lro_reserved = 0;
	int max_features = BNX2X_NETQ_FP_FEATURES_RESERVED + 1;
#endif

	for_each_net_queue(bp, i) {
		struct bnx2x_fastpath *fp = &bp->fp[i];
	#if (VMWARE_ESX_DDK_VERSION < 41000)
		fp->disable_tpa = 1;
	#else
		/* clear features flags */
		fp->netq_flags &= ~BNX2X_NETQ_FP_FEATURES_RESERVED_MASK;

		switch ((i % max_features) <<
			BNX2X_NETQ_FP_FEATURE_RESERVED_SHIFT_BIT) {
		case BNX2X_NETQ_FP_LRO_RESERVED:
			if ((num_lro_reserved <
			     BNX2X_NETQ_FP_LRO_RESERVED_MAX_NUM(bp)) &&
			    (bp->flags & TPA_ENABLE_FLAG)) {
				fp->netq_flags |= BNX2X_NETQ_FP_LRO_RESERVED;
				DP(BNX2X_MSG_NETQ, "Queue[%d] is reserved "
						   "for LRO\n", i);
				num_lro_reserved++;
			} else {
				/* either TPA is glabally disabled or we
				 * already reserved the max number of LRO queues
				 */
				DP(BNX2X_MSG_NETQ, "Queue[%d] is non-LRO\n", i);
				fp->netq_flags |= BNX2X_NETQ_FP_NONE_RESERVED;
				fp->disable_tpa = 1;
			}
			break;

		default:
			/* Do not reserve for LRO */
			DP(BNX2X_MSG_NETQ, "Queue[%d] is non-LRO\n", i);
			fp->netq_flags |= BNX2X_NETQ_FP_NONE_RESERVED;
			fp->disable_tpa = 1;
			break;
		}
	#endif
	}
}

static int bnx2x_get_netqueue_features(vmknetddi_queueop_get_features_args_t *args)
{
	args->features = VMKNETDDI_QUEUEOPS_FEATURE_NONE;
	args->features |= VMKNETDDI_QUEUEOPS_FEATURE_RXQUEUES;
	args->features |= VMKNETDDI_QUEUEOPS_FEATURE_TXQUEUES;
	return VMKNETDDI_QUEUEOPS_OK;
}

static int bnx2x_get_queue_count(vmknetddi_queueop_get_queue_count_args_t *args)
{
	struct bnx2x *bp = netdev_priv(args->netdev);
	u16 netq_count = max_t(u16, BNX2X_NUM_NETQUEUES(bp), 0);

	if (args->type == VMKNETDDI_QUEUEOPS_QUEUE_TYPE_RX) {
		args->count = netq_count;
		return VMKNETDDI_QUEUEOPS_OK;

	} else if (args->type == VMKNETDDI_QUEUEOPS_QUEUE_TYPE_TX) {
		args->count = netq_count;
		return VMKNETDDI_QUEUEOPS_OK;

	} else {
		DP(BNX2X_MSG_NETQ, "invalid queue type: %x\n", args->type);
		return VMKNETDDI_QUEUEOPS_ERR;
	}
}

static int bnx2x_get_filter_count(vmknetddi_queueop_get_filter_count_args_t *args)
{
	struct bnx2x *bp;
	int total_filters = 0;

	bp = netdev_priv(args->netdev);

	if ((BNX2X_NUM_NETQUEUES(bp) == 0 && !IS_MF_FCOE_AFEX(bp)) ||
	    (BNX2X_NUM_NETQUEUES(bp) == 0 && IS_MF_FCOE_AFEX(bp) &&
	     !BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp))) {
		bp->number_of_mac_filters = 0;
		args->count = 0;
		return VMKNETDDI_QUEUEOPS_OK;
	}

	if (multi_rx_filters == 0) {
		DP(BNX2X_MSG_NETQ, "Multiple RX filters disabled forced to "
				   "use only 1 filter.\n");
		bp->number_of_mac_filters = 1;
		args->count = 1;
		return VMKNETDDI_QUEUEOPS_OK;
	}

#if defined(BNX2X_ESX_CNA)
	if (args->netdev->features & NETIF_F_CNA) {
		args->count = 2;
		return VMKNETDDI_QUEUEOPS_OK;
	}
#endif
	/*  Calculate the number of credits left */
	total_filters = bp->macs_pool.check(&bp->macs_pool);
	if (total_filters > 3)
		total_filters = total_filters - 3;
	else
		total_filters = 0;

	DP(BNX2X_MSG_NETQ, "Total Avaiable filters: %d\n", total_filters);
	DP(BNX2X_MSG_NETQ, "# NetQueue: %d\n", BNX2X_NUM_NETQUEUES(bp));
	bp->number_of_mac_filters = (total_filters / BNX2X_NUM_NETQUEUES(bp));

	if (multi_rx_filters > 0) {
		if (bp->number_of_mac_filters < multi_rx_filters)
			DP(BNX2X_MSG_NETQ, "Forced RX filter setting %d higher "
					   "then checked value %d\n",
					   multi_rx_filters,
					   bp->number_of_mac_filters);


		bp->number_of_mac_filters = min_t(int,
						  bp->number_of_mac_filters,
						  multi_rx_filters);
	}
		
	DP(BNX2X_MSG_NETQ, "NetQueue assigned per filters: %d\n",
	   bp->number_of_mac_filters);

	args->count = bp->number_of_mac_filters;
	return VMKNETDDI_QUEUEOPS_OK;
}

static int bnx2x_alloc_rx_queue(struct net_device *netdev,
				vmknetddi_queueops_queueid_t *p_qid,
				struct napi_struct **napi_p)
{
	struct bnx2x *bp = netdev_priv(netdev);
	int i;

	if (bp->n_rx_queues_allocated >= BNX2X_NUM_NETQUEUES(bp)) {
		BNX2X_ERR("NetQ RX Queue %d >= BNX2X_NUM_NETQUEUES(%d)\n",
			  bp->n_rx_queues_allocated, BNX2X_NUM_NETQUEUES(bp));
		return VMKNETDDI_QUEUEOPS_ERR;
	}

	for_each_net_queue(bp, i) {
		struct bnx2x_fastpath *fp = &bp->fp[i];

		if ((!BNX2X_IS_NETQ_RX_QUEUE_ALLOCATED(fp)) &&
		    BNX2X_IS_NETQ_FP_FEAT_NONE_RESERVED(fp)) {
			fp->netq_flags |= BNX2X_NETQ_RX_QUEUE_ALLOCATED;
			bp->n_rx_queues_allocated++;
			*p_qid = VMKNETDDI_QUEUEOPS_MK_RX_QUEUEID(fp->index);
			*napi_p = &fp->napi;

			DP(BNX2X_MSG_NETQ, "RX NetQ allocated on %d\n", i);
			return VMKNETDDI_QUEUEOPS_OK;
		}
	}
	DP(BNX2X_MSG_NETQ, "No free rx queues found!\n");
	return VMKNETDDI_QUEUEOPS_ERR;
}

static int bnx2x_alloc_tx_queue(struct net_device *netdev,
				vmknetddi_queueops_queueid_t *p_qid,
				u16 *queue_mapping)
{
	struct bnx2x *bp = netdev_priv(netdev);
	int i;

	if (bp->n_tx_queues_allocated >= BNX2X_NUM_NETQUEUES(bp)) {
		BNX2X_ERR("NetQ TX Queue %d >= BNX2X_NUM_NETQUEUES(%d)\n",
			  bp->n_tx_queues_allocated, BNX2X_NUM_NETQUEUES(bp));
		return VMKNETDDI_QUEUEOPS_ERR;
	}

	for_each_net_queue(bp, i) {
		struct bnx2x_fastpath *fp = &bp->fp[i];

		if (!BNX2X_IS_NETQ_TX_QUEUE_ALLOCATED(fp)) {
			fp->netq_flags |= BNX2X_NETQ_TX_QUEUE_ALLOCATED;
			bp->n_tx_queues_allocated++;
			*p_qid = VMKNETDDI_QUEUEOPS_MK_TX_QUEUEID(fp->index);
			*queue_mapping = fp->index;

			DP(BNX2X_MSG_NETQ, "TX NetQ allocated on %d\n", i);
			return VMKNETDDI_QUEUEOPS_OK;
		}
	}
	DP(BNX2X_MSG_NETQ, "No free tx queues found!\n");
	return VMKNETDDI_QUEUEOPS_ERR;
}

static int bnx2x_alloc_queue(vmknetddi_queueop_alloc_queue_args_t *args)
{

	if (args->type == VMKNETDDI_QUEUEOPS_QUEUE_TYPE_TX)
		return bnx2x_alloc_tx_queue(args->netdev, &args->queueid,
					    &args->queue_mapping);

	else if (args->type == VMKNETDDI_QUEUEOPS_QUEUE_TYPE_RX)
		return bnx2x_alloc_rx_queue(args->netdev, &args->queueid,
					    &args->napi);
	else {
		struct bnx2x *bp = netdev_priv(args->netdev);

		DP(BNX2X_MSG_NETQ, "invalid queue type: %x\n", args->queueid);
		return VMKNETDDI_QUEUEOPS_ERR;
	}
}

#if (VMWARE_ESX_DDK_VERSION >= 41000)

static int
bnx2x_alloc_rx_queue_with_lro(struct net_device *netdev,
				vmknetddi_queueops_queueid_t *p_qid,
				struct napi_struct **napi_p)
{
	int i;
	struct bnx2x *bp;

	if (!netdev || !p_qid || !napi_p) {
		printk(KERN_ERR "bnx2x_alloc_rx_queue_with_lro: "
			"Invalid parameters! netdev(%p) p_qid(%p) napi_p(%p)\n",
			netdev, p_qid, napi_p);
		return VMKNETDDI_QUEUEOPS_ERR;
	}

	bp = netdev_priv(netdev);
	if (bp->n_rx_queues_allocated >= BNX2X_NUM_QUEUES(bp)) {
		BNX2X_ERR("NetQ RX Queue %d >= BNX2X_NUM_QUEUES(%d)\n",
			  bp->n_rx_queues_allocated, BNX2X_NUM_QUEUES(bp));
		return VMKNETDDI_QUEUEOPS_ERR;
	}

	for_each_net_queue(bp, i) {
		struct bnx2x_fastpath *fp = &bp->fp[i];
		/* if this Rx queue is not used */
		if (!BNX2X_IS_NETQ_RX_QUEUE_ALLOCATED(fp) &&
				BNX2X_IS_NETQ_FP_FEAT_LRO_RESERVED(fp)) {
			fp->netq_flags |= BNX2X_NETQ_RX_QUEUE_ALLOCATED;
			bp->n_rx_queues_allocated++;
			*p_qid = VMKNETDDI_QUEUEOPS_MK_RX_QUEUEID(fp->index);
			*napi_p = &fp->napi;
			 DP(BNX2X_MSG_NETQ,
			    "RX NetQ allocated on %d with LRO feature\n", i);
			return VMKNETDDI_QUEUEOPS_OK;
		}
	}
	DP(BNX2X_MSG_NETQ, "no free rx queues with LRO feature found!\n");
	return VMKNETDDI_QUEUEOPS_ERR;
}

#if (VMWARE_ESX_DDK_VERSION >= 50000)
#define BNX2X_NETQ_SUPPORTED_FEATURES \
	(VMKNETDDI_QUEUEOPS_QUEUE_FEAT_PAIR | \
	((bp->flags & TPA_ENABLE_FLAG) ? VMKNETDDI_QUEUEOPS_QUEUE_FEAT_LRO : 0))
#else
#define BNX2X_NETQ_SUPPORTED_FEATURES \
	((bp->flags & TPA_ENABLE_FLAG) ? VMKNETDDI_QUEUEOPS_QUEUE_FEAT_LRO : 0)
#endif
/*
 * bnx2x_alloc_queue_with_attr - Alloc queue with NETQ features.
 *
 */
static int
bnx2x_alloc_queue_with_attr(
			vmknetddi_queueop_alloc_queue_with_attr_args_t *args)
{
	int i;
	struct bnx2x *bp = netdev_priv(args->netdev);
	vmknetddi_queueops_queue_features_t feat;

	if (!args->attr || !args->nattr) {
		BNX2X_ERR("Attributes are invalid! attr(%p), nattr(%d).\n",
			args->attr, args->nattr);
		return VMKNETDDI_QUEUEOPS_ERR;
	}

	DP(BNX2X_MSG_NETQ, "Attributes number: %d\n", args->nattr);
	for (i = 0; i < args->nattr; i++) {
		DP(BNX2X_MSG_NETQ, "Attribute[%d] type: 0x%x\n",
				i, args->attr[i].type);
		switch (args->attr[i].type) {
		case VMKNETDDI_QUEUEOPS_QUEUE_ATTR_PRIOR:
			/* Nothing to do */
			BNX2X_ERR("VMKNETDDI_QUEUEOPS_QUEUE_ATTR_PRIOR "
				"isn't supported now.\n");
			break;
		case VMKNETDDI_QUEUEOPS_QUEUE_ATTR_FEAT:
			feat = args->attr[i].args.features;
			DP(BNX2X_MSG_NETQ, "Features 0x%x needed.\n", feat);

			/* Unsupported features */
			if (feat & ~BNX2X_NETQ_SUPPORTED_FEATURES) {
				BNX2X_ERR("Failed... "
					"unsupported feature 0x%x\n",
					feat & ~BNX2X_NETQ_SUPPORTED_FEATURES);
				return VMKNETDDI_QUEUEOPS_ERR;
			}

			if (feat & VMKNETDDI_QUEUEOPS_QUEUE_FEAT_LRO) {
				if (args->type !=
					    VMKNETDDI_QUEUEOPS_QUEUE_TYPE_RX) {
					BNX2X_ERR("Invalid queue type, "
						"LRO feature is only "
						"for RX queue\n");
					break;
				}
				return bnx2x_alloc_rx_queue_with_lro(
						args->netdev, &args->queueid,
						&args->napi);
			}

			/* No feature isn't allowed */
			if (!feat)
				BNX2X_ERR("Invalid feature: "
						"features is NONE!\n");
			break;
		default:
			BNX2X_ERR("Invalid attribute type\n");
			return VMKNETDDI_QUEUEOPS_ERR;
			break;
		}
	}
	BNX2X_ERR("No queue is allocated.\n");
	return VMKNETDDI_QUEUEOPS_ERR;
}

static int
bnx2x_get_supported_feature(vmknetddi_queueop_get_sup_feat_args_t *args)
{
	struct bnx2x *bp = netdev_priv(args->netdev);

	args->features = BNX2X_NETQ_SUPPORTED_FEATURES;
#if (VMWARE_ESX_DDK_VERSION >= 50000)
	DP(BNX2X_MSG_NETQ, "Netq features supported: %s %s %s\n",
	     (args->features & VMKNETDDI_QUEUEOPS_QUEUE_FEAT_LRO) ? "LRO" : "",
	     (args->features & VMKNETDDI_QUEUEOPS_QUEUE_FEAT_PAIR) ? "PAIR" : "",
	     (args->features) ? "" : "NONE"
	     );
#else
	DP(BNX2X_MSG_NETQ, "Netq features supported: %s %s\n",
	     (args->features & VMKNETDDI_QUEUEOPS_QUEUE_FEAT_LRO) ? "LRO" : "",
	     (args->features) ? "" : "NONE"
	     );
#endif

	return VMKNETDDI_QUEUEOPS_OK;
}

#if (VMWARE_ESX_DDK_VERSION >= 50000)
static int
bnx2x_get_supported_filter_class(vmknetddi_queueop_get_sup_filter_class_args_t *args)
{
	args->class = VMKNETDDI_QUEUEOPS_FILTER_MACADDR;

	return VMKNETDDI_QUEUEOPS_OK;
}
#endif
#endif

static int bnx2x_free_tx_queue(struct net_device *netdev,
			       vmknetddi_queueops_queueid_t qid)
{
	struct bnx2x *bp = netdev_priv(netdev);
	u16 index = VMKNETDDI_QUEUEOPS_QUEUEID_VAL(qid);
	struct bnx2x_fastpath *fp;

	if (!bnx2x_netq_valid_qid(bp, index))
		return VMKNETDDI_QUEUEOPS_ERR;

	fp = &bp->fp[index];

	if (!BNX2X_IS_NETQ_TX_QUEUE_ALLOCATED(fp)) {
		DP(BNX2X_MSG_NETQ, "NetQ TX Queue %d is not allocated\n",
		   index);
		return VMKNETDDI_QUEUEOPS_ERR;
	}

	fp->netq_flags &= ~BNX2X_NETQ_TX_QUEUE_ALLOCATED;
	if (bp->n_tx_queues_allocated)
		bp->n_tx_queues_allocated--;

	DP(BNX2X_MSG_NETQ, "Free NetQ TX Queue: %x\n", index);

	return VMKNETDDI_QUEUEOPS_OK;
}

static inline void bnx2x_netq_free_rx_queue(struct bnx2x *bp,
					    struct bnx2x_fastpath *fp)
{
	fp->netq_flags &= ~BNX2X_NETQ_RX_QUEUE_ALLOCATED;

	if (bp->n_rx_queues_allocated)
		bp->n_rx_queues_allocated--;
}

static int bnx2x_free_rx_queue(struct net_device *netdev,
			       vmknetddi_queueops_queueid_t qid)
{
	struct bnx2x *bp = netdev_priv(netdev);
	u16 index = VMKNETDDI_QUEUEOPS_QUEUEID_VAL(qid);
	struct bnx2x_fastpath *fp;

	if (!bnx2x_netq_valid_qid(bp, index)) {
		DP(BNX2X_MSG_NETQ, "NetQ RX Queue %d is invalid\n", index);
		return VMKNETDDI_QUEUEOPS_ERR;
	}

	fp = &bp->fp[index];

	if (!BNX2X_IS_NETQ_RX_QUEUE_ALLOCATED(fp)) {
		DP(BNX2X_MSG_NETQ, "NetQ RX Queue %d is not allocated\n",
		   index);
		return VMKNETDDI_QUEUEOPS_ERR;
	}

	bnx2x_netq_free_rx_queue(bp, fp);
	DP(BNX2X_MSG_NETQ, "Free NetQ RX Queue: %x\n", index);

	return VMKNETDDI_QUEUEOPS_OK;
}

static int bnx2x_free_queue(vmknetddi_queueop_free_queue_args_t *args)
{
	if (VMKNETDDI_QUEUEOPS_IS_TX_QUEUEID(args->queueid))
		return bnx2x_free_tx_queue(args->netdev, args->queueid);

	else if (VMKNETDDI_QUEUEOPS_IS_RX_QUEUEID(args->queueid))
		return bnx2x_free_rx_queue(args->netdev, args->queueid);

	else {
		struct net_device *netdev = args->netdev;
		struct bnx2x *bp = netdev_priv(netdev);

		DP(BNX2X_MSG_NETQ, "invalid queue type: %x\n", args->queueid);
		return VMKNETDDI_QUEUEOPS_ERR;
	}
}

static int bnx2x_get_queue_vector(vmknetddi_queueop_get_queue_vector_args_t *args)
{
	struct net_device *netdev = args->netdev;
	struct bnx2x *bp = netdev_priv(netdev);
	int qid;

	qid = VMKNETDDI_QUEUEOPS_QUEUEID_VAL(args->queueid);

	/* may be invoked also for the default queue */
	if (qid > BNX2X_NUM_NETQUEUES(bp)) {
		DP(BNX2X_MSG_NETQ, "NetQ Queue %d is invalid\n", qid);
		return VMKNETDDI_QUEUEOPS_ERR;
	}

	/*
	 * msix_table indices:
	 * 0 - default SB (slow-path operations)
	 * 1 - CNIC fast-path operations (if compiled in)
	 * 2 - Max NetQs - Net-queues starting form the default queue
	 */
	qid += (1 + CNIC_PRESENT);

	args->vector = bp->msix_table[qid].vector;
	return VMKNETDDI_QUEUEOPS_OK;
}

static int bnx2x_get_default_queue(vmknetddi_queueop_get_default_queue_args_t *args)
{
	struct net_device *netdev = args->netdev;
	struct bnx2x *bp = netdev_priv(netdev);

	if (args->type == VMKNETDDI_QUEUEOPS_QUEUE_TYPE_RX) {
		args->queueid = VMKNETDDI_QUEUEOPS_MK_RX_QUEUEID(0);
		args->napi = &bp->fp[0].napi;
		return VMKNETDDI_QUEUEOPS_OK;

	} else if (args->type == VMKNETDDI_QUEUEOPS_QUEUE_TYPE_TX) {
		args->queueid = VMKNETDDI_QUEUEOPS_MK_TX_QUEUEID(0);
		args->queue_mapping = 0;
		return VMKNETDDI_QUEUEOPS_OK;

	} else
		return VMKNETDDI_QUEUEOPS_ERR;
}


static inline int bnx2x_netq_set_mac_one(u8 *mac, struct bnx2x *bp,
					 struct bnx2x_fastpath *fp, bool add)
{
	unsigned long ramrod_flags = 0;

	set_bit(RAMROD_COMP_WAIT, &ramrod_flags);

	return bnx2x_set_mac_one(bp, mac, &fp->mac_obj, add,
				 BNX2X_NETQ_ETH_MAC, &ramrod_flags);
}

static int bnx2x_netq_remove_rx_filter(struct bnx2x *bp,
				       struct bnx2x_fastpath *fp, u16 fid)
{
	unsigned long ramrod_flags = 0;
	struct bnx2x_queue_state_params qstate = {0};
	u8 *macaddr;
	int is_last_mac_filter, rc;
	DECLARE_MAC_BUF(mac);

	if (fid >= bp->number_of_mac_filters) {
		DP(BNX2X_MSG_NETQ, "Couldn't remove invalid RX filter %d "
		   "on NetQ RX Queue %d\n", fid, fp->index);
		return VMKNETDDI_QUEUEOPS_ERR;
	} else {
		if (fp->mac_filters == NULL) {
			DP(BNX2X_MSG_NETQ, "Error Freeing RX filter "
					   "with empty RX MAC filter table\n");
			return VMKNETDDI_QUEUEOPS_ERR;
		}

		macaddr = fp->mac_filters[fid].mac;

		DP(BNX2X_MSG_NETQ, "NetQ remove RX filter: queue:%d mac:%s "
		   "filter id:%d]\n",
		   fp->index, print_mac(mac, macaddr), fid);
	}

	is_last_mac_filter = bnx2x_is_last_rx_mac_filter(fp);

	/* clear MAC */

	/* set to drop-all*/
	if (is_last_mac_filter) {
		set_bit(RAMROD_RX, &ramrod_flags);
		set_bit(RAMROD_TX, &ramrod_flags);
		set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
		rc = bnx2x_set_q_rx_mode(bp, fp->cl_id, 0, 0, 0, ramrod_flags);

		if (rc) {
			BNX2X_ERR("NetQ could not remove RX filter, "
				  "rx mode failed: queue:%d mac:%s "
				  "filter id:%d]\n",
				  fp->index, print_mac(mac, macaddr), fid);
			return VMKNETDDI_QUEUEOPS_ERR;
		}
	}

	/* delete MAC */
	rc = bnx2x_netq_set_mac_one(macaddr, bp, fp, 0);
	if (rc) {
		BNX2X_ERR("NetQ could not remove RX filter: queue:%d mac:%s "
			  "filter id:%d]\n",
			  fp->index, print_mac(mac, macaddr), fid);
		return VMKNETDDI_QUEUEOPS_ERR;
	}

	/* send empty-ramrod to flush packets lurking in the HW */
	qstate.q_obj = &fp->q_obj;
	ramrod_flags = 0;
	set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
	qstate.ramrod_flags = ramrod_flags; /* wait for completion */
	qstate.cmd = BNX2X_Q_CMD_EMPTY;
	if (bnx2x_queue_state_change(bp, &qstate)) {
		BNX2X_ERR("RX %d queue state not changed for fid: %d\n",
			  fp->index, fid);
		return VMKNETDDI_QUEUEOPS_ERR;
	}
	bnx2x_remove_rx_mac_filter(bp, fp, fid, is_last_mac_filter);

	return VMKNETDDI_QUEUEOPS_OK;
}

static int bnx2x_remove_rx_filter(vmknetddi_queueop_remove_rx_filter_args_t *args)
{
	struct bnx2x *bp = netdev_priv(args->netdev);
	u16 qid = VMKNETDDI_QUEUEOPS_QUEUEID_VAL(args->queueid);
	u16 fid = VMKNETDDI_QUEUEOPS_FILTERID_VAL(args->filterid);
	struct bnx2x_fastpath *fp = &bp->fp[qid];
	int rc;

	if (!VMKNETDDI_QUEUEOPS_IS_RX_QUEUEID(args->queueid)) {
		BNX2X_ERR("Queue ID %d is not RX queue\n", args->queueid);
		return VMKNETDDI_QUEUEOPS_ERR;
	}

	/* not invoked for the default queue */
	if (!bnx2x_netq_valid_qid(bp, qid)) {
		DP(BNX2X_MSG_NETQ, "NetQ RX Queue %d is invalid\n", qid);
		return VMKNETDDI_QUEUEOPS_ERR;
	}

	/* Verfiy the queue is allocated and has an active filter */
	if (!BNX2X_IS_NETQ_RX_QUEUE_ACTIVE(fp) ||
	    !BNX2X_IS_NETQ_RX_QUEUE_ALLOCATED(fp)) {
		DP(BNX2X_MSG_NETQ, "NetQ RX Queue %d is not allocated/active "
				   "0x%x\n", qid, fp->netq_flags);
		return VMKNETDDI_QUEUEOPS_ERR;
	}

	/* Do the work */
	rc = bnx2x_netq_remove_rx_filter(bp, fp, fid);
	if (!rc)
		DP(BNX2X_MSG_NETQ, "NetQ %d remove RX filter %d\n", qid, fid);

	return rc;
}


static int bnx2x_apply_rx_filter(vmknetddi_queueop_apply_rx_filter_args_t *args)
{
	u8 *macaddr;
	struct bnx2x *bp = netdev_priv(args->netdev);
	struct bnx2x_fastpath *fp;
	u16 qid = VMKNETDDI_QUEUEOPS_QUEUEID_VAL(args->queueid);
	u16 vlan_id;
	unsigned long accept_flags = 0, ramrod_flags = 0;
	int filter_id, rc;

	vmknetddi_queueops_filter_class_t filter;
	DECLARE_MAC_BUF(mac);

	if (!VMKNETDDI_QUEUEOPS_IS_RX_QUEUEID(args->queueid)) {
		BNX2X_ERR("Queue ID %d is not RX queue\n", args->queueid);
		return VMKNETDDI_QUEUEOPS_ERR;
	}

	filter = vmknetddi_queueops_get_filter_class(&args->filter);
	if (filter != VMKNETDDI_QUEUEOPS_FILTER_MACADDR) {
		BNX2X_ERR("Queue filter %x not MACADDR filter\n", filter);
		return VMKNETDDI_QUEUEOPS_ERR;
	}

	/* not invoked for the default queue */
	if (!bnx2x_netq_valid_qid(bp, qid)) {
		DP(BNX2X_MSG_NETQ, "NetQ RX Queue %d is invalid\n", qid);
		return VMKNETDDI_QUEUEOPS_ERR;
	}

	fp = &bp->fp[qid];

	if (!BNX2X_IS_NETQ_RX_QUEUE_ALLOCATED(fp)) {
		BNX2X_ERR("Trying to apply filter on non allocated Queue %d\n",
			  qid);
		return VMKNETDDI_QUEUEOPS_ERR;
	}

	macaddr = (void *)vmknetddi_queueops_get_filter_macaddr(&args->filter);
	vlan_id = vmknetddi_queueops_get_filter_vlanid(&args->filter);

	filter_id = bnx2x_find_rx_mac_filter_add(bp, fp, macaddr);
	if (filter_id < 0) {
		BNX2X_ERR("NetQ could not add RX filter, no filters "
			  "avaliable: queue:%d mac:%s "
			  "vlan id:%d]\n",
			   qid, print_mac(mac, macaddr), vlan_id);
		return VMKNETDDI_QUEUEOPS_ERR;
	}

	if (bnx2x_num_active_rx_mac_filters(fp) == 1) {
		/* set to recv-unicast */
		set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
		set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
		set_bit(RAMROD_RX, &ramrod_flags);
		set_bit(RAMROD_TX, &ramrod_flags);
		set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
		rc = bnx2x_set_q_rx_mode(bp, fp->cl_id, 0, accept_flags,
					 accept_flags, ramrod_flags);

		if (rc) {
			BNX2X_ERR("NetQ could not add RX filter, "
				  " rx mode failed: queue:%d mac:%s "
				  "vlan id:%d filter id:%d]\n",
				   qid, print_mac(mac, macaddr), vlan_id,
				  filter_id);
			return VMKNETDDI_QUEUEOPS_ERR;
		}
	}

	/* add MAC */
	rc = bnx2x_netq_set_mac_one(macaddr, bp, fp, 1);
	if (rc) {
		BNX2X_ERR("NetQ could not add RX filter: queue:%d mac:%s "
			  "vlan id:%d filter id:%d]\n",
			   qid, print_mac(mac, macaddr), vlan_id, filter_id);
		bnx2x_clear_rx_mac_entry(&fp->mac_filters[filter_id]);
		return VMKNETDDI_QUEUEOPS_ERR;
	}

	fp->netq_flags |= BNX2X_NETQ_RX_QUEUE_ACTIVE;
	args->filterid = VMKNETDDI_QUEUEOPS_MK_FILTERID(filter_id);
#if (VMWARE_ESX_DDK_VERSION >= 50000)
	/* Need by feature: VMKNETDDI_QUEUEOPS_FEATURE_PAIRQUEUE  */
	args->pairtxqid = qid;
#endif
	DP(BNX2X_MSG_NETQ, "NetQ set RX filter: queue:%d mac:%s "
			   "vlan id:%d filter id:%d]\n",
	   qid, print_mac(mac, macaddr), vlan_id, filter_id);

	return VMKNETDDI_QUEUEOPS_OK;
}

static int bnx2x_get_queue_stats(vmknetddi_queueop_get_stats_args_t *args)
{
	return VMKNETDDI_QUEUEOPS_ERR;
}

static int bnx2x_get_netqueue_version(vmknetddi_queueop_get_version_args_t *args)
{
	return vmknetddi_queueops_version(args);
}


void bnx2x_netq_clear_rx_queues(struct bnx2x *bp)
{
	int i;

	spin_lock(&bp->netq_lock);

	for_each_net_queue(bp, i) {
		struct bnx2x_fastpath *fp = &bp->fp[i];

		if (BNX2X_IS_NETQ_RX_QUEUE_ACTIVE(fp)) {
			int j;

			for (j = 0; j < bp->number_of_mac_filters; j++)
				if (fp->mac_filters != NULL &&
				    BNX2X_IS_NETQ_RX_FILTER_ACTIVE(fp, j))
					bnx2x_netq_remove_rx_filter(bp, fp, j);
		}

		if (BNX2X_IS_NETQ_RX_QUEUE_ALLOCATED(fp))
			bnx2x_netq_free_rx_queue(bp, fp);
	}

	spin_unlock(&bp->netq_lock);
}

int bnx2x_netqueue_ops(vmknetddi_queueops_op_t op, void *args)
{
	vmknetddi_queueop_get_queue_count_args_t *p;
	struct bnx2x *bp;
	int rc = VMKNETDDI_QUEUEOPS_ERR;

	if (op == VMKNETDDI_QUEUEOPS_OP_GET_VERSION)
		return bnx2x_get_netqueue_version(
			(vmknetddi_queueop_get_version_args_t *)args);
	else if(op == VMKNETDDI_QUEUEOPS_OP_GET_FEATURES)
		return bnx2x_get_netqueue_features(
			(vmknetddi_queueop_get_features_args_t *)args);

	p = (vmknetddi_queueop_get_queue_count_args_t *)args;
	bp = netdev_priv(p->netdev);

	spin_lock(&bp->netq_lock);

	switch (op) {
	case VMKNETDDI_QUEUEOPS_OP_GET_QUEUE_COUNT:
		rc = bnx2x_get_queue_count(
			(vmknetddi_queueop_get_queue_count_args_t *)args);
		break;

	case VMKNETDDI_QUEUEOPS_OP_GET_FILTER_COUNT:
		rc = bnx2x_get_filter_count(
			(vmknetddi_queueop_get_filter_count_args_t *)args);
		break;

	case VMKNETDDI_QUEUEOPS_OP_ALLOC_QUEUE:
		rc = bnx2x_alloc_queue(
			(vmknetddi_queueop_alloc_queue_args_t *)args);
		break;

	case VMKNETDDI_QUEUEOPS_OP_FREE_QUEUE:
		rc = bnx2x_free_queue(
			(vmknetddi_queueop_free_queue_args_t *)args);
		break;

	case VMKNETDDI_QUEUEOPS_OP_GET_QUEUE_VECTOR:
		rc = bnx2x_get_queue_vector(
			(vmknetddi_queueop_get_queue_vector_args_t *)args);
		break;

	case VMKNETDDI_QUEUEOPS_OP_GET_DEFAULT_QUEUE:
		rc = bnx2x_get_default_queue(
			(vmknetddi_queueop_get_default_queue_args_t *)args);
		break;

	case VMKNETDDI_QUEUEOPS_OP_APPLY_RX_FILTER:
		rc = bnx2x_apply_rx_filter(
			(vmknetddi_queueop_apply_rx_filter_args_t *)args);
		break;

	case VMKNETDDI_QUEUEOPS_OP_REMOVE_RX_FILTER:
		rc = bnx2x_remove_rx_filter(
			(vmknetddi_queueop_remove_rx_filter_args_t *)args);
		break;

	case VMKNETDDI_QUEUEOPS_OP_GET_STATS:
		rc = bnx2x_get_queue_stats(
			(vmknetddi_queueop_get_stats_args_t *)args);
		break;

#if (VMWARE_ESX_DDK_VERSION >= 41000)
	case VMKNETDDI_QUEUEOPS_OP_ALLOC_QUEUE_WITH_ATTR:
		rc = bnx2x_alloc_queue_with_attr(
			(vmknetddi_queueop_alloc_queue_with_attr_args_t *)args);
		break;

	case VMKNETDDI_QUEUEOPS_OP_GET_SUPPORTED_FEAT:
		rc = bnx2x_get_supported_feature(
			(vmknetddi_queueop_get_sup_feat_args_t *)args);
		break;
#if (VMWARE_ESX_DDK_VERSION >= 50000)
	case VMKNETDDI_QUEUEOPS_OP_GET_SUPPORTED_FILTER_CLASS:
		rc = bnx2x_get_supported_filter_class(
			(vmknetddi_queueop_get_sup_filter_class_args_t *)args);
		break;
#endif
#endif

	default:
		printk("Unhandled NETQUEUE OP %d\n", op);
		rc = VMKNETDDI_QUEUEOPS_ERR;
	}

	spin_unlock(&bp->netq_lock);

	return rc;
}

#endif /* BNX2X_NETQ */

#if defined(BNX2X_ESX_CNA) /* ! BNX2X_UPSTREAM */
static int bnx2x_cna_get_queue_count(
	vmknetddi_queueop_get_queue_count_args_t *args)
{
	struct net_device *netdev = args->netdev;
	struct bnx2x *bp = netdev->priv;

	if (args->type == VMKNETDDI_QUEUEOPS_QUEUE_TYPE_RX) {
		args->count = 2;
		return VMKNETDDI_QUEUEOPS_OK;

	} else if (args->type == VMKNETDDI_QUEUEOPS_QUEUE_TYPE_TX) {
		args->count = 2;
		return VMKNETDDI_QUEUEOPS_OK;

	} else {
		DP(BNX2X_MSG_NETQ, "invalid queue type: %x\n", args->type);
		return VMKNETDDI_QUEUEOPS_ERR;
	}
}
static int bnx2x_cna_alloc_rx_queue(struct net_device *netdev,
				    vmknetddi_queueops_queueid_t *p_qid,
				    struct napi_struct **napi_p)
{
	struct bnx2x *bp = netdev->priv;
	struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);

	if (!BNX2X_IS_NETQ_RX_QUEUE_ALLOCATED(fp)) {
		napi_synchronize(&bnx2x_fcoe(bp, napi));

		fp->netq_flags |= BNX2X_NETQ_RX_QUEUE_ALLOCATED;
		*p_qid = VMKNETDDI_QUEUEOPS_MK_RX_QUEUEID(1);
		*napi_p = &fp->napi;

		DP(BNX2X_MSG_NETQ, "RX CNA NetQ allocated on %d\n", 1);
		return VMKNETDDI_QUEUEOPS_OK;
	}

	DP(BNX2X_MSG_NETQ, "No free CNA rx queues found!\n");
	return VMKNETDDI_QUEUEOPS_ERR;
}

static int bnx2x_cna_get_filter_count(vmknetddi_queueop_get_filter_count_args_t *args)
{
	args->count = 2;
	return VMKNETDDI_QUEUEOPS_OK;
}

static int bnx2x_cna_alloc_tx_queue(struct net_device *netdev,
				    vmknetddi_queueops_queueid_t *p_qid,
				    u16 *queue_mapping)
{
	struct bnx2x *bp = netdev->priv;
	struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);

	if (!BNX2X_IS_NETQ_TX_QUEUE_ALLOCATED(fp)) {
		fp->netq_flags |= BNX2X_NETQ_TX_QUEUE_ALLOCATED;

		/*  TODO determine remapping */
		*p_qid = VMKNETDDI_QUEUEOPS_MK_TX_QUEUEID(1);
		*queue_mapping = 1;

		/* Start Tx */
		netif_tx_start_all_queues(netdev);

		DP(BNX2X_MSG_NETQ, "CNA NetQ TX Queue ID %d Mapping: %d\n",
			*p_qid, *queue_mapping);

		return VMKNETDDI_QUEUEOPS_OK;
	}

	DP(BNX2X_MSG_NETQ, "No free tx queues for CNA device found!\n");
	return VMKNETDDI_QUEUEOPS_ERR;
}

static int bnx2x_cna_alloc_queue(vmknetddi_queueop_alloc_queue_args_t *args)
{
	struct bnx2x *bp;

	if (args->netdev->features & NETIF_F_CNA)
		bp = args->netdev->priv;
	else
		bp = netdev_priv(args->netdev);

	if (args->type == VMKNETDDI_QUEUEOPS_QUEUE_TYPE_TX) {
		return bnx2x_cna_alloc_tx_queue(args->netdev, &args->queueid,
						&args->queue_mapping);

	} else if (args->type == VMKNETDDI_QUEUEOPS_QUEUE_TYPE_RX) {
		return bnx2x_cna_alloc_rx_queue(args->netdev, &args->queueid,
						&args->napi);
	} else {
		DP(BNX2X_MSG_NETQ, "invalid queue type: %x\n", args->queueid);
		return VMKNETDDI_QUEUEOPS_ERR;
	}
}

static int bnx2x_cna_free_tx_queue(struct net_device *netdev,
			       vmknetddi_queueops_queueid_t qid)
{
	struct bnx2x *bp = netdev->priv;
	struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);

	if (!BNX2X_IS_NETQ_TX_QUEUE_ALLOCATED(fp)) {
		DP(BNX2X_MSG_NETQ, "CNA NetQ TX Queue is not allocated\n");
		return VMKNETDDI_QUEUEOPS_ERR;
	}

	fp->netq_flags &= ~BNX2X_NETQ_TX_QUEUE_ALLOCATED;

	/* Stop TX */
	netif_tx_disable(netdev);
	netif_carrier_off(netdev);

	DP(BNX2X_MSG_NETQ, "Free CNA NetQ TX Queue\n");

	return VMKNETDDI_QUEUEOPS_OK;
}

static int bnx2x_cna_free_rx_queue(struct net_device *netdev,
				   vmknetddi_queueops_queueid_t qid)
{
	struct bnx2x *bp = netdev->priv;
	u16 index = VMKNETDDI_QUEUEOPS_QUEUEID_VAL(qid);
	struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);

	if (!BNX2X_IS_NETQ_RX_QUEUE_ALLOCATED(fp)) {
		DP(BNX2X_MSG_NETQ, "CNA NetQ RX Queue is not allocated\n");
		return VMKNETDDI_QUEUEOPS_ERR;
	}

	bnx2x_netq_free_rx_queue(bp, fp);

	DP(BNX2X_MSG_NETQ, "Free CNA NetQ RX Queue: %x\n", index);

	return VMKNETDDI_QUEUEOPS_OK;
}

static int bnx2x_cna_free_queue(vmknetddi_queueop_free_queue_args_t *args)
{
	if (VMKNETDDI_QUEUEOPS_IS_TX_QUEUEID(args->queueid))
		return bnx2x_cna_free_tx_queue(args->netdev, args->queueid);

	else if (VMKNETDDI_QUEUEOPS_IS_RX_QUEUEID(args->queueid))
		return bnx2x_cna_free_rx_queue(args->netdev, args->queueid);

	else {
		struct net_device *netdev = args->netdev;
		struct bnx2x *bp = netdev_priv(netdev);

		DP(BNX2X_MSG_NETQ, "invalid queue type: %x\n", args->queueid);
		return VMKNETDDI_QUEUEOPS_ERR;
	}
}

static int bnx2x_cna_get_queue_vector(vmknetddi_queueop_get_queue_vector_args_t *args)
{
	struct net_device *netdev = args->netdev;
	struct bnx2x *bp = netdev->priv;
	int qid;

	qid = VMKNETDDI_QUEUEOPS_QUEUEID_VAL(args->queueid);

	/* may be invoked also for the default queue */
	if (qid > BNX2X_NUM_NETQUEUES(bp)) {
		DP(BNX2X_MSG_NETQ, "NetQ Queue %d is invalid\n", qid);
		return VMKNETDDI_QUEUEOPS_ERR;
	}

	/*
	 * msix_table indices:
	 * 0 - default SB (slow-path operations)
	 * 1 - CNIC fast-path operations (if compiled in)
	 * 2 - Max NetQs - Net-queues starting form the default queue
	 */
	qid += (1 + CNIC_PRESENT);

	args->vector = bp->msix_table[qid].vector;
	return VMKNETDDI_QUEUEOPS_OK;
}

static int bnx2x_cna_get_default_queue(vmknetddi_queueop_get_default_queue_args_t *args)
{
	struct bnx2x *bp = args->netdev->priv;

	if (args->type == VMKNETDDI_QUEUEOPS_QUEUE_TYPE_RX) {
		args->queueid = VMKNETDDI_QUEUEOPS_MK_RX_QUEUEID(0);
		args->napi = &bp->fp[0].napi;
		return VMKNETDDI_QUEUEOPS_OK;

	} else if (args->type == VMKNETDDI_QUEUEOPS_QUEUE_TYPE_TX) {
		args->queueid = VMKNETDDI_QUEUEOPS_MK_TX_QUEUEID(0);
		args->queue_mapping = 0;
		return VMKNETDDI_QUEUEOPS_OK;

	} else
		return VMKNETDDI_QUEUEOPS_ERR;
}

static int bnx2x_cna_remove_rx_filter(
	vmknetddi_queueop_remove_rx_filter_args_t *args)
{
	struct bnx2x *bp = args->netdev->priv;
	u16 qid = VMKNETDDI_QUEUEOPS_QUEUEID_VAL(args->queueid);
	struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
	struct bnx2x_queue_state_params qstate = {0};
	unsigned long sp_bits = 0;

	if (!VMKNETDDI_QUEUEOPS_IS_RX_QUEUEID(args->queueid)) {
		BNX2X_ERR("Queue ID %d is not RX queue\n",
			  args->queueid);
		return VMKNETDDI_QUEUEOPS_ERR;
	}

	/* Verfiy the queue is allocated and has an active filter */
	if (!BNX2X_IS_NETQ_RX_QUEUE_ACTIVE(fp) ||
	    !BNX2X_IS_NETQ_RX_QUEUE_ALLOCATED(fp)) {
		DP(BNX2X_MSG_NETQ, "NetQ RX Queue %d is not allocated/active "
				   "0x%x\n", qid, fp->netq_flags);
		return VMKNETDDI_QUEUEOPS_ERR;
	}

	/* Stop receiving */
	netif_addr_lock_bh(bp->dev);
	bnx2x_set_fcoe_eth_rx_mode(bp, false);
	netif_addr_unlock_bh(bp->dev);

	/* bits to wait on */
	set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
	set_bit(BNX2X_FILTER_FCOE_ETH_STOP_SCHED, &sp_bits);

	if (!bnx2x_wait_sp_comp(bp, sp_bits)) {
		BNX2X_ERR("rx_mode completion timed out!\n");
		return VMKNETDDI_QUEUEOPS_ERR;
	} else {
		/* send empty-ramrod to flush packets lurking in the HW */
		qstate.q_obj = &fp->q_obj;
		qstate.cmd = BNX2X_Q_CMD_EMPTY;
		/* wait for completion */
		set_bit(RAMROD_COMP_WAIT, &qstate.ramrod_flags);
		if (bnx2x_queue_state_change(bp, &qstate))
			return VMKNETDDI_QUEUEOPS_ERR;
	}

	DP(BNX2X_MSG_NETQ, "Free CNA NetQ RX Queue: %x\n", qid);
	return VMKNETDDI_QUEUEOPS_OK;
}

static int bnx2x_cna_apply_rx_filter(
	vmknetddi_queueop_apply_rx_filter_args_t *args)
{
	struct bnx2x *bp = args->netdev->priv;
	struct bnx2x_fastpath *fp;
	u16 qid = VMKNETDDI_QUEUEOPS_QUEUEID_VAL(args->queueid);
	unsigned long sp_bits = 0;

	fp = bnx2x_fcoe_fp(bp);

	fp->netq_flags |= BNX2X_NETQ_RX_QUEUE_ACTIVE;
	args->filterid = VMKNETDDI_QUEUEOPS_MK_FILTERID(0);

	/* Need by feature: VMKNETDDI_QUEUEOPS_FEATURE_PAIRQUEUE  */
	args->pairtxqid = qid;

	/* Start receiving */
	netif_addr_lock_bh(bp->dev);
	bnx2x_set_fcoe_eth_rx_mode(bp, true);
	netif_addr_unlock_bh(bp->dev);

	/* bits to wait on */
	set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
	set_bit(BNX2X_FILTER_FCOE_ETH_START_SCHED, &sp_bits);

	if (!bnx2x_wait_sp_comp(bp, sp_bits))
		BNX2X_ERR("rx_mode completion timed out!\n");

	DP(BNX2X_MSG_NETQ, "NetQ set CNA RX filter\n");

	return VMKNETDDI_QUEUEOPS_OK;
}

int bnx2x_cna_netqueue_ops(vmknetddi_queueops_op_t op, void *args)
{
	vmknetddi_queueop_get_queue_count_args_t *p;
	struct bnx2x *bp;
	int rc = VMKNETDDI_QUEUEOPS_ERR;

	if (op == VMKNETDDI_QUEUEOPS_OP_GET_VERSION)
		return bnx2x_get_netqueue_version(
			(vmknetddi_queueop_get_version_args_t *)args);
	else if (op == VMKNETDDI_QUEUEOPS_OP_GET_FEATURES)
		return bnx2x_get_netqueue_features(
			(vmknetddi_queueop_get_features_args_t *)args);

	p = (vmknetddi_queueop_get_queue_count_args_t *)args;

	bp = p->netdev->priv;

	spin_lock(&bp->netq_lock);

	switch (op) {
	case VMKNETDDI_QUEUEOPS_OP_GET_QUEUE_COUNT:
		rc = bnx2x_cna_get_queue_count(
			(vmknetddi_queueop_get_queue_count_args_t *)args);
		break;

	case VMKNETDDI_QUEUEOPS_OP_GET_FILTER_COUNT:
		rc = bnx2x_cna_get_filter_count(
			(vmknetddi_queueop_get_filter_count_args_t *)args);
		break;

	case VMKNETDDI_QUEUEOPS_OP_ALLOC_QUEUE:
		rc = bnx2x_cna_alloc_queue(
			(vmknetddi_queueop_alloc_queue_args_t *)args);
		break;

	case VMKNETDDI_QUEUEOPS_OP_FREE_QUEUE:
		rc = bnx2x_cna_free_queue(
			(vmknetddi_queueop_free_queue_args_t *)args);
		break;

	case VMKNETDDI_QUEUEOPS_OP_GET_QUEUE_VECTOR:
		rc = bnx2x_cna_get_queue_vector(
			(vmknetddi_queueop_get_queue_vector_args_t *)args);
		break;

	case VMKNETDDI_QUEUEOPS_OP_GET_DEFAULT_QUEUE:
		rc = bnx2x_cna_get_default_queue(
			(vmknetddi_queueop_get_default_queue_args_t *)args);
		break;

	case VMKNETDDI_QUEUEOPS_OP_APPLY_RX_FILTER:
		rc = bnx2x_cna_apply_rx_filter(
			(vmknetddi_queueop_apply_rx_filter_args_t *)args);
		break;

	case VMKNETDDI_QUEUEOPS_OP_REMOVE_RX_FILTER:
		rc = bnx2x_cna_remove_rx_filter(
			(vmknetddi_queueop_remove_rx_filter_args_t *)args);
		break;

	case VMKNETDDI_QUEUEOPS_OP_GET_STATS:
		rc = bnx2x_get_queue_stats(
			(vmknetddi_queueop_get_stats_args_t *)args);
		break;

#if (VMWARE_ESX_DDK_VERSION >= 41000)
	case VMKNETDDI_QUEUEOPS_OP_ALLOC_QUEUE_WITH_ATTR:
		rc = VMKNETDDI_QUEUEOPS_ERR;
		break;

	case VMKNETDDI_QUEUEOPS_OP_GET_SUPPORTED_FEAT:
		rc = bnx2x_get_supported_feature(
			(vmknetddi_queueop_get_sup_feat_args_t *)args);
		break;


#endif

	default:
		printk(KERN_WARNING "Unhandled NETQUEUE OP %d\n", op);
		rc = VMKNETDDI_QUEUEOPS_ERR;
	}

	spin_unlock(&bp->netq_lock);

	return rc;
}
/* CNA related */
static int bnx2x_cna_open(struct net_device *cnadev)
{
	struct bnx2x *bp = cnadev->priv;
	strcpy(cnadev->name, bp->dev->name);

	netif_set_poll_cna(&bnx2x_fcoe(bp, napi));

	vmknetddi_queueops_invalidate_state(cnadev);

	if (BNX2X_IS_NETQ_TX_QUEUE_ALLOCATED(bnx2x_fcoe_fp(bp)))
		netif_tx_start_all_queues(cnadev);

	DP(NETIF_MSG_PROBE, "CNA pseudo device opened %s\n", cnadev->name);
	return 0;
}

static int bnx2x_cna_close(struct net_device *cnadev)
{
	struct bnx2x *bp = cnadev->priv;

	netif_tx_disable(cnadev);
	netif_carrier_off(cnadev);

	DP(NETIF_MSG_PROBE, "CNA pseudo device closed %s\n", cnadev->name);
	return 0;
}

static int bnx2x_cna_change_mtu(struct net_device *cnadev, int new_mtu)
{
	struct bnx2x *bp = cnadev->priv;

	if (cnadev->mtu == new_mtu)
		return 0;

	if ((new_mtu > ETH_MAX_JUMBO_PACKET_SIZE) ||
		((new_mtu + ETH_HLEN) < ETH_MIN_PACKET_SIZE))
		return -EINVAL;



	DP(BNX2X_MSG_SP,  "changing MTU from %d to %d\n",
		cnadev->mtu, new_mtu);

	/* must set new MTU before calling down or up */
	cnadev->mtu = new_mtu;

	return dev_close(cnadev) || dev_open(cnadev);
}

static inline int bnx2x_cna_set_vlan_stripping(struct bnx2x *bp, bool set)
{
	struct bnx2x_queue_state_params q_params = {0};
	struct bnx2x_queue_update_params *update_params =
		&q_params.params.update;
	int rc;
	struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);

	/* We want to wait for completion in this context */
	set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);

	/* Set the command */
	q_params.cmd = BNX2X_Q_CMD_UPDATE;

	/* Enable VLAN stripping if requested */
	if (set)
		set_bit(BNX2X_Q_UPDATE_IN_VLAN_REM,
			&update_params->update_flags);

	/* Indicate that VLAN stripping configuration has changed */
	set_bit(BNX2X_Q_UPDATE_IN_VLAN_REM_CHNG, &update_params->update_flags);

	/* Set the appropriate Queue object */
	q_params.q_obj = &fp->q_obj;

	/* Update the Queue state */
	rc = bnx2x_queue_state_change(bp, &q_params);
	if (rc) {
		BNX2X_ERR("Failed to configure VLAN stripping "
			  "for CNA FCoE ring\n");
		return rc;
	}

	return 0;
}

/* called with rtnl_lock */
static void bnx2x_cna_vlan_rx_register(struct net_device *dev,
				       struct vlan_group *vlgrp)
{
	struct bnx2x *bp = dev->priv;
	int rc;

	/* Configure VLAN stripping if NIC is up.
	 * Otherwise just set the bp->vlgrp and stripping will be
	 * configured in bnx2x_nic_load().
	 */
	if (bp->state == BNX2X_STATE_OPEN) {
		if (vlgrp != NULL) {
			rc = bnx2x_cna_set_vlan_stripping(bp, true);

			/* If we failed to configure VLAN stripping we don't
			 * want to use HW accelerated flow in bnx2x_rx_int().
			 * Thus we will leave bp->vlgrp to be equal to NULL to
			 * disable it.
			 */
			if (rc) {
				netdev_err(dev, "Failed to set HW "
						"VLAN stripping for a CNA "
						"device\n");
				bnx2x_cna_set_vlan_stripping(bp, false);
			} else
				bp->cna_vlgrp = vlgrp;
		} else {
			rc = bnx2x_cna_set_vlan_stripping(bp, false);

			if (rc)
				netdev_err(dev, "Failed to clear HW "
						"VLAN strippingfor a CNA "
						"device\n");

			bp->cna_vlgrp = NULL;
		}
	} else
		bp->cna_vlgrp = vlgrp;
}

static void bnx2x_cna_vlan_rx_add_vid(struct net_device *dev, uint16_t vid)
{
	struct bnx2x *bp = dev->priv;

	if (bp->cna_vlgrp)
		vlan_group_set_device(bp->cna_vlgrp, vid, dev);
}

static void bnx2x_cna_vlan_rx_kill_vid(struct net_device *dev, uint16_t vid)
{
	struct bnx2x *bp = dev->priv;

	if (bp->cna_vlgrp)
		vlan_group_set_device(bp->cna_vlgrp, vid, NULL);
}

/* TODO: think of a better name */
int bnx2x_cna_enable(struct bnx2x *bp, int tx_count, int rx_count)
{
	struct net_device *cnadev;
	struct net_device *netdev;
	int err;

	//u16 device_caps;
	if (NO_FCOE(bp))
		return -EINVAL;

	bp->flags |= CNA_ENABLED;

	netdev = bp->dev;

	/**
	 * Oppositely to regular net device, CNA device doesn't have
	 * a private allocated region as we don't want to duplicate
	 * bnx2x information. Though, the CNA device still need
	 * to access the bnx2x if FP. Thereby, cnadev->priv needs to
	 * point to netdev->priv.
	 */
	cnadev = alloc_etherdev_mqs(0, tx_count, rx_count);
	if (!cnadev) {
		err = -ENOMEM;
		goto err_alloc_etherdev;
	}
	bp->cnadev = cnadev;

	cnadev->priv = bp;

	cnadev->open             = &bnx2x_cna_open;
	cnadev->stop             = &bnx2x_cna_close;
	cnadev->change_mtu       = &bnx2x_cna_change_mtu;
	cnadev->do_ioctl         = netdev->do_ioctl;
	cnadev->hard_start_xmit  = netdev->hard_start_xmit;
#ifdef NETIF_F_HW_VLAN_TX
	cnadev->vlan_rx_register = bnx2x_cna_vlan_rx_register;
	cnadev->vlan_rx_add_vid  = bnx2x_cna_vlan_rx_add_vid;
	cnadev->vlan_rx_kill_vid = bnx2x_cna_vlan_rx_kill_vid;
#endif
	bnx2x_set_ethtool_ops(cnadev);

#ifdef CONFIG_DCB
	cnadev->dcbnl_ops = netdev->dcbnl_ops;
#endif

	cnadev->mtu = netdev->mtu;
	cnadev->pdev = netdev->pdev;
	cnadev->gso_max_size = GSO_MAX_SIZE;
	cnadev->features = netdev->features | NETIF_F_HWDCB | NETIF_F_CNA |
			   NETIF_F_HW_VLAN_FILTER;

	/* set the MAC address to SAN mac address */
	memcpy(cnadev->dev_addr, bp->fip_mac, ETH_ALEN);

	netif_carrier_off(cnadev);
	netif_tx_stop_all_queues(cnadev);

	VMKNETDDI_REGISTER_QUEUEOPS(cnadev, bnx2x_cna_netqueue_ops);

	netif_napi_add(bp->cnadev, &bnx2x_fp(bp, FCOE_IDX, napi),
		       bnx2x_poll, BNX2X_NAPI_WEIGHT);

	err = register_netdev(cnadev);
	if (err)
		goto err_register;

	DP(NETIF_MSG_PROBE, "CNA pseudo device registered %s\n", netdev->name);

	return err;

err_register:
	DP(NETIF_MSG_PROBE, "CNA pseudo device cannot be registered %s\n",
		netdev->name);
	free_netdev(cnadev);
err_alloc_etherdev:
	DP(NETIF_MSG_PROBE, "CNA cannot be enabled on %s\n", netdev->name);
	bp->flags &= ~CNA_ENABLED;
	return err;
}

void bnx2x_cna_disable(struct bnx2x *bp)
{
	struct net_device *cnadev = bp->cnadev;

	if (bp->flags & CNA_ENABLED) {
		bp->flags &= ~CNA_ENABLED;
		unregister_netdev(cnadev);
		DP(NETIF_MSG_PROBE, "CNA pseudo device unregistered %s\n",
			cnadev->name);

		free_netdev(cnadev);
		bp->cnadev = NULL;
	}
}
#endif
/*******************/


/*
 * NPA - Pass-Through
 */
#ifdef BCM_IOV

#include <linux/pci.h>
#include <linux/types.h>
#include <linux/netdevice.h>

#include "bnx2x_sriov.h"

#define BNX2X_UNREFERENCED(x)	(void)(x)
#define ENABLE_STR(en)		((en) ? "enable" : "disable")

#define VMK_RET(rc)				\
	((rc == 0) ? VMK_OK :			\
	 (rc == -ENOMEM) ? VMK_NO_MEMORY :	\
	 VMK_FAILURE)

/* useful wrappers */
inline int
bnx2x_vmk_pci_dev(struct bnx2x *bp, vmk_PCIDevice *vmkPfDev)
{
	struct pci_dev *pdev = bp->pdev;
	return (vmk_PCIGetPCIDevice(pci_domain_nr(pdev->bus),
				    pdev->bus->number,
				    PCI_SLOT(pdev->devfn),
				    PCI_FUNC(pdev->devfn),
				    vmkPfDev) != VMK_OK);
}

inline int
bnx2x_vmk_vf_pci_dev(struct bnx2x *bp, u16 abs_vfid, vmk_PCIDevice *vmkVfDev)
{
	vmk_PCIDevice vmkPfDev;

	if (bnx2x_vmk_pci_dev(bp, &vmkPfDev))
		return -1;

	return (vmk_PCIGetVFPCIDevice(vmkPfDev, abs_vfid, vmkVfDev) != VMK_OK);
}

inline int
bnx2x_vmk_pci_read_config_byte(vmk_PCIDevice dev, vmk_uint16 offset,
			       vmk_uint8 *val)
{
	vmk_uint32 val32;
	VMK_ReturnStatus vmkRet = vmk_PCIReadConfig(dev, VMK_PCI_CONFIG_ACCESS_8,
						    offset, &val32);
	*val = (vmk_uint8)val32;
	return vmkRet;

}

inline int
bnx2x_vmk_pci_read_config_word(vmk_PCIDevice dev, vmk_uint16 offset,
			       vmk_uint16 *val)
{
	vmk_uint32 val32;
	VMK_ReturnStatus vmkRet = vmk_PCIReadConfig(dev, VMK_PCI_CONFIG_ACCESS_16,
						    offset, &val32);
	*val = (vmk_uint16)val32;
	return vmkRet;

}

inline int
bnx2x_vmk_pci_read_config_dword(vmk_PCIDevice dev, vmk_uint16 offset,
			       vmk_uint32 *val)
{
	return vmk_PCIReadConfig(dev, VMK_PCI_CONFIG_ACCESS_32, offset, val);
}

/* Must be called only after VF-Enable*/
inline int
bnx2x_vmk_vf_bus(struct bnx2x *bp, int vfid)
{
	vmk_PCIDevice vfDev;
	u16 seg;
	u8 bus, slot, func;

	bnx2x_vmk_vf_pci_dev(bp, vfid, &vfDev);
	vmk_PCIGetSegmentBusDevFunc(vfDev, &seg, &bus, &slot, &func);
	return bus;
}

/* Must be called only after VF-Enable*/
inline int
bnx2x_vmk_vf_devfn(struct bnx2x *bp, int vfid)
{
	vmk_PCIDevice vfDev;
	u16 seg;
	u8 bus, slot, func;

	bnx2x_vmk_vf_pci_dev(bp, vfid, &vfDev);
	vmk_PCIGetSegmentBusDevFunc(vfDev, &seg, &bus, &slot, &func);
	return PCI_DEVFN(slot, func);
}

void
bnx2x_vmk_vf_set_bars(struct bnx2x *bp, struct bnx2x_virtf *vf)
{
	struct pci_dev *pdev;
	vmk_PCIDevice vfDev;
	u16 seg;
	u8 bus, slot, func;
	int i, n;

	bnx2x_vmk_vf_pci_dev(bp, vf->index, &vfDev);
	vmk_PCIGetSegmentBusDevFunc(vfDev, &seg, &bus, &slot, &func);



#if VMKLNX_DDI_VERSION >= VMKLNX_MAKE_VERSION(9, 2, 0, 0)
/*#if VMKLNX_DDI_VERSION >= VMKLNX_MAKE_VERSION(10, 0)*/
	pdev = pci_find_slot(seg, bus, PCI_DEVFN(slot, func));
#else
	pdev = pci_find_slot(bus, PCI_DEVFN(slot, func));
#endif

	if (!pdev) {
		printk(KERN_ERR"Cannot get pci_dev of VF %d.\n", vf->abs_vfid);
		return;
	}

	for (i = 0, n = 0; i < PCI_SRIOV_NUM_BARS; i += 2, n++) {
		vf->bars[n].bar = pci_resource_start(pdev, i);
		vf->bars[n].size = pci_resource_len(pdev, i);
	}
}


#define PCI_SRIOV_CAP_POS_E2	0x1c0

void
bnx2x_vmk_get_sriov_cap_pos(struct bnx2x *bp, vmk_uint16 *pos)
{
	if (pos)
		/* check for E2 TODO */
		*pos = PCI_SRIOV_CAP_POS_E2;
}


static inline
struct bnx2x_virtf *vf_by_vmkVFID(struct bnx2x *bp, vmk_VFID vmkVf)
{
	return (vmkVf < BNX2X_NR_VIRTFN(bp) ? BP_VF(bp, vmkVf) : NULL);
}

#ifdef BNX2X_PASSTHRU
// ---------------------------------------------------------------------------
//
// VF allocation
//
static int
bnx2x_pt_vf_acquire(struct net_device *netdev, vmk_NetVFRequirements *props,
		  vmk_VFID *vmkVf)
{
	struct bnx2x *bp = netdev_priv(netdev);
	struct bnx2x_virtf *vf = NULL;	/* make this compile */
	struct vf_pf_resc_request resc;
	int i;

	DP(BNX2X_MSG_IOV, "Features 0x%x, opt-Features 0x%x\n",
	   props->features, props->optFeatures);

	/* verfiy version TODO */
	/* find the first VF which is in either FREE or RESET states */
	for_each_vf(bp, i) {
		vf = BP_VF(bp, i);
		if ((vf->state == VF_FREE) || (vf->state == VF_RESET))
			break;
	}
	if (i == BNX2X_NR_VIRTFN(bp)) {
		BNX2X_ERR("No available VFs\n");
		return VMK_NO_RESOURCES;
	}

	/* acquire the resources */
	resc.num_rxqs = props->numRxQueues;
	resc.num_txqs = props->numTxQueues;
	resc.num_sbs = props->numIntrs;
	resc.num_mac_filters = 1;
	resc.num_mc_filters = 0;
	resc.num_vlan_filters = 0;

	if (bnx2x_vf_acquire(bp, vf, &resc)) {
		BNX2X_ERR("VF[%d] - Failed to provision resources, rxqs=%d, txqs=%d, intr=%d\n",
			  vf->abs_vfid,
			  props->numRxQueues,
			  props->numTxQueues,
			  props->numIntrs);
		return VMK_NO_RESOURCES;
	}

	*vmkVf = i;

	/**
	 * set the identity mapping between queues and SBs
	 * (must be done prior to get_info)
	 */
	for_each_vfq(vf, i)
		bnx2x_vfq(vf, i, sb_idx) = i;


	/*
	 * save features and MTU to be set on a per queue basis later
	 * during VF init.
	 */
	vf->mtu = props->mtu;
	vf->queue_flags = 0;

	if ((props->features | props->optFeatures) & VMK_NETVF_F_RXVLAN)
		set_bit(BNX2X_Q_FLG_VLAN, &vf->queue_flags);
	if ((props->features | props->optFeatures) & VMK_NETVF_F_LRO)
		set_bit(BNX2X_Q_FLG_TPA, &vf->queue_flags);

#ifdef BNX2X_PASSTHRU_NO_BC_FLR
	if (BP_NOMCP(bp))
		mod_timer(&bp->vfdb->flr_timer, jiffies + HZ/100);
#endif

	return VMK_OK;
}

static int
bnx2x_pt_vf_init(struct net_device *netdev, vmk_VFID vmkVf,
		 vmk_NetVFParameters *params)
{
	struct bnx2x *bp = netdev_priv(netdev);
	struct bnx2x_virtf *vf = vf_by_vmkVFID(bp, vmkVf);
	struct bnx2x_vfop_cmd cmd = {
		.done = NULL,
		.block = true,
	};
	u64 *sb_map;
	int i, rc;

	DP(BNX2X_MSG_IOV, "VF index %d\n", vmkVf);


	/* sanity */
	if (!vf || vf->state != VF_ACQUIRED)
		return VMK_BAD_PARAM;

	/* initialize function */
#ifdef BNX2X_PASSTHRU_NO_BC_FLR
	if (BP_NOMCP(bp))
		mod_timer(&bp->vfdb->flr_timer, jiffies + HZ/100);
#endif

	/* verify shared region and save plugin stats pointer */
	if (!params->u.npa.sharedRegion || params->u.npa.sharedRegionLength <
	    sizeof(struct bnx2x_vf_plugin_stats))
		return VMK_BAD_PARAM;

	vf->plugin_stats =
		(struct bnx2x_vf_plugin_stats *)params->u.npa.sharedRegion;

	memset((u8*)vf->plugin_stats, 0, sizeof(struct bnx2x_vf_plugin_stats));

	/* set GPA of sbs */
	sb_map = kzalloc(sizeof(*sb_map) * sb_count(vf), GFP_ATOMIC);
	if (!sb_map)
		return VMK_NO_MEMORY;

	for_each_vf_sb(vf, i) {
		sb_map[i] = SB_OFFSET(params->u.npa.txQueues[i].basePA,
				      params->u.npa.txQueues[i].size);
		DP(BNX2X_MSG_IOV, "VF[%d], SB[%d] - map 0x%llx, igu %d, fw %d "
				  "hc %d, mod-level %d\n",
		   vf->abs_vfid, i, sb_map[i],
		   vf_igu_sb(vf,i),
		   vf_fw_sb(vf,i),
		   vf_hc_qzone(vf,i),
		   params->u.npa.intr[i].modLevel);
	}

	rc = bnx2x_vf_init(bp, vf, sb_map);
	kfree(sb_map);

	if (rc)
		goto vf_init_error;

	/* queues */
	for_each_vfq(vf, i) {
		struct bnx2x_vf_queue *q = vfq_get(vf,i);
		struct bnx2xpi_txrx_params txrxp = {{0}};
		struct bnx2x_queue_setup_params *setup_p;
		struct bnx2x_queue_init_params *init_p;
		unsigned long q_type = 0, q_flags = 0;

		/**
		 * reinit the VF operation context
		 */
		memset(&vf->op_params.qctor, 0 , sizeof(vf->op_params.qctor));
		setup_p = &vf->op_params.qctor.prep_qsetup;
		init_p =  &vf->op_params.qctor.qstate.params.init;

		/* prepare flags */
		q_flags = vf->queue_flags;
		__set_bit(BNX2X_Q_FLG_HC, &q_flags);
		__set_bit(BNX2X_Q_FLG_STATS, &q_flags);
		if (IS_MF_SD(bp))
			__set_bit(BNX2X_Q_FLG_OV, &q_flags);

		/* TXQ */
		if (i < txq_count(vf)) {
			struct bnx2x_txq_setup_params *txq_params =
				&setup_p->txq_params;

			set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
			txrxp.tx.base = params->u.npa.txQueues[i].basePA;
			txrxp.tx.nr_desc = params->u.npa.txQueues[i].size;
			txrxp.tx.byte_len = params->u.npa.txQueues[i].length;

			DP(BNX2X_MSG_IOV, "VF[%d], TXQ[%d] - base 0x%llx, "
					  "nr_desc %d, len %d\n",
			   vf->abs_vfid,
			   q->index,
			   txrxp.tx.base,
			   txrxp.tx.nr_desc,
			   txrxp.tx.byte_len);


			/* tx init */
			init_p->tx.hc_rate = 20000; /* intr p/s default */
			init_p->tx.sb_cq_index = PLUGIN_SB_ETH_TX_CQ_INDEX;
			init_p->tx.flags = q_flags;

			/* tx setup flags */
			setup_p->flags = q_flags;

			/* tx setup general - nothing */

			/**
			 *  TODO: We need to add the mtu for txq as well
			 */

			/* tx setup tx */
			txq_params->dscr_map = bnx2xpi_tx_decr_offset(&txrxp);
			txq_params->sb_cq_index = PLUGIN_SB_ETH_TX_CQ_INDEX;
			txq_params->traffic_type = LLFC_TRAFFIC_TYPE_NW;

			bnx2x_vfop_qctor_dump_tx(bp, vf, init_p, setup_p,
						 q->index, q->sb_idx);
		}

		/* RXQ */
		if (i < rxq_count(vf)) {
			struct bnx2x_rxq_setup_params *rxq_params =
							&setup_p->rxq_params;

			set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
			txrxp.rx.base = params->u.npa.rxQueues[i].basePA;
			txrxp.rx.nr_desc = params->u.npa.rxQueues[i].size;
			txrxp.rx.byte_len = params->u.npa.rxQueues[i].length;

			DP(BNX2X_MSG_IOV, "VF[%d], RXQ[%d] - base 0x%llx, "
					  "nr_desc %d, len %d\n",
			   vf->abs_vfid,
			   q->index,
			   txrxp.rx.base,
			   txrxp.rx.nr_desc,
			   txrxp.rx.byte_len);

			/* rx init */
			init_p->rx.hc_rate = 40000; /* intr p/s default */
			init_p->rx.sb_cq_index = PLUGIN_SB_ETH_RX_CQ_INDEX;
			init_p->rx.flags = q_flags;

			/* rx setup flags */
			setup_p->flags = q_flags;

			/* rx setup general */
			setup_p->gen_params.mtu = vf->mtu;

			/* rx setup rx */
			rxq_params->drop_flags = 0;
			rxq_params->dscr_map = bnx2xpi_rx_decr_offset(&txrxp);
			rxq_params->sge_map = bnx2xpi_sge_offset(&txrxp);
			rxq_params->rcq_map = bnx2xpi_rcq_offset(&txrxp);
			rxq_params->rcq_np_map = bnx2xpi_rcq_np_offset(&txrxp);
			rxq_params->buf_sz = SHELL_SMALL_RECV_BUFFER_SIZE -
				PLUGIN_RX_ALIGN - IP_HEADER_ALIGNMENT_PADDING;
			rxq_params->cache_line_log = PLUGIN_RX_ALIGN_SHIFT;
			rxq_params->sb_cq_index = PLUGIN_SB_ETH_RX_CQ_INDEX;

			if (test_bit(BNX2X_Q_FLG_TPA, &vf->queue_flags)) {
				rxq_params->tpa_agg_sz =
					min_t(u32,
					      PLUGIN_MAX_SGES *
					      SHELL_LARGE_RECV_BUFFER_SIZE,
					      0xffff);

				rxq_params->max_sges_pkt = DIV_ROUND_UP(
					vf->mtu, SHELL_LARGE_RECV_BUFFER_SIZE);

				rxq_params->sge_buf_sz =
					min_t(u32,
					      SHELL_LARGE_RECV_BUFFER_SIZE,
					      0xffff);
			}
			bnx2x_vfop_qctor_dump_rx(bp, vf, init_p, setup_p,
						 q->index, q->sb_idx);
		}

		/* complete the prepareations */
		bnx2x_vfop_qctor_prep(bp, vf, q, &vf->op_params.qctor, q_type);

		/* invoke setup operation - blocking */
		DP(BNX2X_MSG_IOV, "VFQ SETUP[%d:%d]\n", vf->abs_vfid, i);
		if (bnx2x_vfop_qsetup_cmd(bp, vf, &cmd, i))
			goto vf_init_error;

		/**
		 * set the next-page directly in the storm RAM.
		 */
		storm_memset_rcq_np(bp, setup_p->rxq_params.rcq_np_map,
				    vfq_cl_id(vf,q));
	}
	return VMK_OK;

vf_init_error:
	/* release the VF (blocking) */
	bnx2x_vf_release(bp, vf, true);
	return VMK_FAILURE;

}

static int
bnx2x_pt_vf_release(struct net_device *netdev, vmk_VFID vmkVf)
{
	struct bnx2x *bp = netdev_priv(netdev);
	struct bnx2x_virtf *vf = vf_by_vmkVFID(bp, vmkVf);

	DP(BNX2X_MSG_IOV, "VF index %d\n", vmkVf);

	/* sanity */
	if (!vf)
		return VMK_BAD_PARAM;

	bnx2x_vf_release(bp, vf, true);	/* blocking */
	return VMK_OK;
}

// ---------------------------------------------------------------------------
//
// VF basic control
//
static int
bnx2x_pt_vf_get_info(struct net_device *netdev, vmk_VFID vmkVf,
		     vmk_NetVFInfo *info)
{
	struct bnx2x *bp = netdev_priv(netdev);
	struct bnx2x_virtf *vf = vf_by_vmkVFID(bp, vmkVf);
	struct bnx2x_plugin_device_info *plugin_data;
	vmk_uint8 numPtRegions;
	int i;

	DP(BNX2X_MSG_IOV, "VF index %d\n", vmkVf);

	/* sanity */
	if (!vf || vf->state != VF_ACQUIRED)
		return VMK_BAD_PARAM;

	/* build sbdf */
	info->sbdf = (vf->devfn) | ((vf->bus & 0xff) << 8) |
		((pci_domain_nr(bp->pdev->bus) & 0xffff) << 16);

	/* copy bar info */
	for (i = 0, numPtRegions = 0; i < 3; i++) {
		if(vf->bars[i].size) {
			info->ptRegions[numPtRegions].MA = vf->bars[i].bar;
			info->ptRegions[numPtRegions++].numPages =
				vf->bars[i].size / 4096;
		}
	}
	info->numPtRegions = numPtRegions;

	DP(BNX2X_MSG_IOV, "sbdf %08x (%04x:%02x:%02x.%01x), no pages: %d ",
	   info->sbdf,
	   (info->sbdf >> 16) & 0xffff,
	   (info->sbdf >> 8) & 0xff,
	   PCI_SLOT(info->sbdf &0xff),
	   PCI_FUNC(info->sbdf &0xff),
	   info->numPtRegions);

	for (i = 0; i < numPtRegions; i++)
		DP_CONT(BNX2X_MSG_IOV, " [ 0x%llx, %d ]" ,
			(unsigned long long int)info->ptRegions[i].MA,
			info->ptRegions[i].numPages);
	DP_CONT(BNX2X_MSG_IOV, "\n");

	/* plugin information */
	strcpy(info->u.npa.pluginName, "bnx2x_plugin-%b.so");

	/* build plugin private data  */
	memset(info->u.npa.pluginData, 0, sizeof (info->u.npa.pluginData));
	plugin_data = (struct bnx2x_plugin_device_info *)(info->u.npa.pluginData);

	for_each_vfq(vf, i) {
		struct bnx2x_vf_queue *q = vfq_get(vf, i);
		plugin_data->sb_info[i].sb_qid = vfq_qzone_id(vf, q);
		plugin_data->sb_info[i].hw_sb_id = vf_igu_sb(vf ,q->sb_idx);
		plugin_data->hw_qid[i] = vfq_qzone_id(vf, q);
	}
	plugin_data->chip_id = bp->common.chip_id;
	plugin_data->pci_func = bp->pf_num;

	plugin_data->fp_flags = BNX2X_PLUGIN_SHARED_SB_IDX;

	plugin_data->fp_flags |= test_bit(BNX2X_Q_FLG_TPA, &vf->queue_flags) ?
		0 : BNX2X_PLUGIN_DISABLE_TPA;

	return VMK_OK;
}

static int
bnx2x_pt_vf_quiesce(struct net_device *netdev, vmk_VFID vmkVf)
{
	struct bnx2x *bp = netdev_priv(netdev);
	struct bnx2x_virtf *vf = vf_by_vmkVFID(bp, vmkVf);
	struct bnx2x_vfop_cmd cmd;

	DP(BNX2X_MSG_IOV, "Invoked\n");

	/* sanity */
	if (!vf)
		return VMK_BAD_PARAM;

	/* quiesce only if vf is enabled otherwise exit gracefully */
	if (vf->state != VF_ENABLED)
		return VMK_OK;

	cmd.done = NULL;
	cmd.block = true;
	return VMK_RET(bnx2x_vfop_trigger_cmd(bp, vf, &cmd, false));
}

static int
bnx2x_pt_vf_activate(struct net_device *netdev, vmk_VFID vmkVf)
{
	struct bnx2x *bp = netdev_priv(netdev);
	struct bnx2x_virtf *vf = vf_by_vmkVFID(bp, vmkVf);
	struct bnx2x_vfop_cmd cmd;

	DP(BNX2X_MSG_IOV, "Invoked\n");

	/* sanity */
	if (!vf || vf->state != VF_ENABLED)
		return VMK_BAD_PARAM;

	cmd.done = NULL;
	cmd.block = true;
	return VMK_RET(bnx2x_vfop_trigger_cmd(bp, vf, &cmd, true));
}


static int
bnx2x_pt_vf_set_mac(struct net_device *netdev, vmk_VFID vmkVf,
		    vmk_EthAddress mac)
{
	struct bnx2x *bp = netdev_priv(netdev);
	struct bnx2x_virtf *vf = vf_by_vmkVFID(bp, vmkVf);
	struct bnx2x_vfop_cmd cmd;
	int rc;

	DECLARE_MAC_BUF(mac_buf);
	DP(BNX2X_MSG_IOV, "%s\n", print_mac(mac_buf, mac));

	/* sanity */
	if (!vf || vf->state != VF_ENABLED)
		return VMK_BAD_PARAM;

	cmd.done = NULL;
	cmd.block = true;
	rc = bnx2x_vfop_mac_set_cmd(bp, vf, &cmd, 0, mac, true);
	if (rc)
		BNX2X_ERR("Failed to add mac-vlan rule rc=%d\n", rc);

	return VMK_RET(rc);
}

// ---------------------------------------------------------------------------
//
// Multicast control
//
static int
bnx2x_pt_vf_set_multicast(struct net_device *netdev, vmk_VFID vmkVf,
			  size_t nmac, vmk_EthAddress *mac)
{
	struct bnx2x *bp = netdev_priv(netdev);
	struct bnx2x_virtf *vf = vf_by_vmkVFID(bp, vmkVf);
	struct bnx2x_vfop_cmd cmd;


	DP(BNX2X_MSG_IOV, "VF index %d, mcast_num %d\n", vmkVf, (int)nmac);

	/* sanity */
	if (!vf || vf->state != VF_ENABLED)
		return VMK_BAD_PARAM;

	if (nmac > VMK_NPA_MAX_MULTICAST_FILTERS)
		return VMK_BAD_PARAM;

	cmd.done = NULL;
	cmd.block = true;
	return VMK_RET(bnx2x_vfop_mcast_cmd(bp, vf, &cmd,
					    (bnx2x_mac_addr_t *)mac, nmac,
					    false));
}

static int
bnx2x_pt_vf_set_rx_mode(struct net_device *netdev, vmk_VFID vmkVf,
			uint8_t unicast,
			uint8_t multicast,
			uint8_t broadcast,
			uint8_t allmulti)
{
	struct bnx2x *bp = netdev_priv(netdev);
	struct bnx2x_virtf *vf = vf_by_vmkVFID(bp, vmkVf);
	unsigned long accept_flags = 0;
	struct bnx2x_vfop_cmd cmd;

	DP(BNX2X_MSG_IOV, "VF index %d, ucast %d, mcast %d, bcast %d, "
			  "allmulti %d\n",
	   vmkVf, unicast, multicast, broadcast, allmulti);

	/* sanity */
	if (!vf || vf->state != VF_ENABLED)
		return VMK_BAD_PARAM;

	/* build accept flags */
	if (unicast)
		set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
	if (multicast)
		set_bit(BNX2X_ACCEPT_MULTICAST, &accept_flags);
	if (broadcast)
		set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
	if (allmulti)
		set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);

	/**
	 * Emulation/FPGA CAM is narrow so use ANY_VLAN instead of vlan 0
	 */
	if (CHIP_REV_IS_SLOW(bp))
		set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);

	DP(BNX2X_MSG_IOV, "RX-MASK=0x%lx\n", accept_flags);

	cmd.done = NULL;
	cmd.block = true;
	return VMK_RET(bnx2x_vfop_rxmode_cmd(bp, vf, &cmd, 0, accept_flags));
}

// ---------------------------------------------------------------------------
//
// VLAN control
//

static inline int
bnx2x_vf_set_vlan(struct bnx2x *bp, struct bnx2x_virtf *vf, int qid,
		  u16 vtag, bool add)
{
	struct bnx2x_vfop_cmd cmd = {
		.done = NULL,
		.block = true,
	};
	return VMK_RET(bnx2x_vfop_vlan_set_cmd(bp, vf, &cmd, qid, vtag, add));
}

static int bnx2x_pt_vf_vlan_range(struct net_device *netdev, vmk_VFID vmkVf,
			   vmk_VlanID first, vmk_VlanID last, bool add)
{
	struct bnx2x *bp = netdev_priv(netdev);
	struct bnx2x_virtf *vf = vf_by_vmkVFID(bp, vmkVf);
	struct bnx2x_vfop_filters *vlans = NULL;
	size_t fsz;
	vmk_VlanID vid;

	struct bnx2x_vfop_cmd cmd = {
		.done = NULL,
		.block = true,
	};

	DP(BNX2X_MSG_IOV, "VF index %d, first %d, last %d\n",
	   vmkVf, first, last);

	/* sanity */
	if (!vf || vf->state != VF_ENABLED)
		return VMK_BAD_PARAM;

	/* a valid range does not include vlan 0 - igonre first == 0 */
	if (first > last || first > 4095 || last > 4095)
		return VMK_BAD_PARAM;

	fsz = (last-first+1)*sizeof(struct bnx2x_vfop_filter) +
		sizeof(struct bnx2x_vfop_filters);

	vlans = kzalloc(fsz, GFP_KERNEL);
	if (!vlans)
		return VMK_NO_MEMORY;

	INIT_LIST_HEAD(&vlans->head);
	for (vid = first; vid <= last; vid++) {
		list_add_tail(&vlans->filters[vid].link, &vlans->head);
		vlans->filters[vid].vid = vid;
		vlans->filters[vid].add = add;
		vlans->filters[vid].type = BNX2X_VFOP_FILTER_VLAN;
	}

	return VMK_RET(bnx2x_vfop_vlan_list_cmd(bp, vf, &cmd, vlans, 0, false));
}

static inline int
bnx2x_pt_vf_add_vlan_range(struct net_device *netdev, vmk_VFID vmkVf,
			   vmk_VlanID first, vmk_VlanID last)
{
	return bnx2x_pt_vf_vlan_range(netdev, vmkVf, first, last, true);
}

static inline int
bnx2x_pt_vf_del_vlan_range(struct net_device *netdev, vmk_VFID vmkVf,
			   vmk_VlanID first, vmk_VlanID last)
{
	return bnx2x_pt_vf_vlan_range(netdev, vmkVf, first, last, false);
}

static int bnx2x_vf_defvlan(struct bnx2x *bp, struct bnx2x_virtf *vf,
			    bool enable, u16 vid, u8 prio)
{
	struct bnx2x_vfop_cmd cmd = {
		.done = NULL,
		.block = true,
	};
	return VMK_RET(bnx2x_vfop_defvlan_cmd(bp, vf, &cmd, enable, vid, prio));
}

static inline int
bnx2x_vf_clear_vlans(struct bnx2x *bp, struct bnx2x_virtf *vf, int qid)
{
	struct bnx2x_vfop_cmd cmd = {
		.done = NULL,
		.block = true,
	};
	return VMK_RET(bnx2x_vfop_vlan_delall_cmd(bp, vf, &cmd, qid, false));
}

static int
bnx2x_pt_vf_set_default_vlan(struct net_device *netdev, vmk_VFID vmkVf,
			   uint8_t enable, vmk_VlanID vid,
			   vmk_VlanPriority prio)
{
	struct bnx2x *bp = netdev_priv(netdev);
	struct bnx2x_virtf *vf = vf_by_vmkVFID(bp, vmkVf);
	int rc = 0;

	DP(BNX2X_MSG_IOV, "VF index %d, vid %d, pri %d, %s\n",
	   vmkVf, vid, prio, ENABLE_STR(enable));

	/* sanity */
	if (!vf || vf->state != VF_ENABLED)
		return VMK_BAD_PARAM;

	if ((enable && vid == 0 && prio == 0) || vid > 4095 || prio > 7)
		return VMK_BAD_PARAM;

	if (!enable) {
		/* disable */
		if (!vf->def_vlan_enabled)
			/* nothing to do */
			return VMK_OK;

		/* turn off default vlan */
		rc = bnx2x_vf_defvlan(bp, vf, false, vid, prio);
		if (rc)
			goto vmkpt_err;

		/**
		 * reset vlan classification - remove the default vlan
		 * (remove all) and add vlan 0
		 */
		rc = bnx2x_vf_clear_vlans(bp, vf, 0);
		if (rc)
			goto vmkpt_err;

		rc = bnx2x_vf_set_vlan(bp, vf, 0, 0, true);
		if (rc)
			goto vmkpt_err;

		vf->def_vlan_enabled = false;
	}
	else {
		/* enable */
		if (vf->def_vlan_enabled)
			/* nothing to do */
			return VMK_OK;

		/**
		 * set vlan classifiaction - clear all vlans and add the
		 * default vlan
		 */
		rc = bnx2x_vf_clear_vlans(bp, vf, 0);
		if (rc)
			goto vmkpt_err;

		rc = bnx2x_vf_set_vlan(bp, vf, 0, vid, true);
		if (rc)
			goto vmkpt_err;

		/* turn on default vlan */
		rc = bnx2x_vf_defvlan(bp, vf, true, vid, prio);
		if (rc)
			goto vmkpt_err;

		vf->def_vlan_enabled = true;
	}
vmkpt_done:
	return VMK_RET(rc);
vmkpt_err:
	BNX2X_ERR("failed to set default vlan, VF[%d], vid %d, pri %d, %s "
		  "rc %d\n", vmkVf, vid, prio, ENABLE_STR(enable), rc);
	goto vmkpt_done;
}

// ---------------------------------------------------------------------------
//
// Misc operations
//
static int
bnx2x_pt_vf_set_antispoof(struct net_device *netdev, vmk_VFID vmkVf,
			  uint8_t enable)
{
	struct bnx2x *bp = netdev_priv(netdev);
	struct bnx2x_virtf *vf = vf_by_vmkVFID(bp, vmkVf);
	struct bnx2x_vfop_cmd cmd = {
		.done = NULL,
		.block = true,
	};
	return VMK_RET(bnx2x_vfop_antispoof_cmd(bp, vf, &cmd, enable));
}

static int
bnx2x_pt_vf_set_rss_ind_table(struct net_device *netdev, vmk_VFID vmkVf,
			    vmk_NetVFRSSIndTable *table)
{
	struct bnx2x *bp = netdev_priv(netdev);
	struct bnx2x_virtf *vf = vf_by_vmkVFID(bp, vmkVf);


	DP(BNX2X_MSG_IOV, "VF index %d\n", vmkVf);

	/* sanity */
	if (!vf || vf->state != VF_ENABLED)
		return VMK_BAD_PARAM;

	// Check table size.
	if (table->indTableSize > VMK_NETVF_RSS_MAX_IND_TABLE_SIZE)
		return VMK_BAD_PARAM;

	return VMK_OK;
}

static int
bnx2x_pt_vf_get_queue_status(struct net_device *netdev, vmk_VFID vmkVf,
			   uint8_t numTxQueues, uint8_t numRxQueues,
			   vmk_NetVFQueueStatus *tqStatus,
			   vmk_NetVFQueueStatus *rqStatus)
{
	struct bnx2x *bp = netdev_priv(netdev);
	DP(BNX2X_MSG_IOV, "VF index %d - NOT SUPPORTED \n", vmkVf);
	return VMK_OK;
}


static inline
vmk_uint64 __pt_update_single_stat(vmk_uint64 cur, vmk_uint64 *p_old)
{
	vmk_uint64 diff = (s64)cur - (s64)(*p_old);
	*p_old = cur;
	return diff;
}

static int
bnx2x_pt_vf_get_queue_stats(struct net_device *netdev, vmk_VFID vmkVf,
			  uint8_t numTxQueues, uint8_t numRxQueues,
			  vmk_NetVFTXQueueStats *tqStats,
			  vmk_NetVFRXQueueStats *rqStats)
{
	int i;
	struct bnx2x *bp = netdev_priv(netdev);
	struct bnx2x_virtf *vf = vf_by_vmkVFID(bp, vmkVf);

	/* sanity */
	if (!vf || vf->state != VF_ENABLED)
		return VMK_BAD_PARAM;

	if (rxq_count(vf) < numRxQueues || txq_count(vf) < numTxQueues)
		return VMK_BAD_PARAM;

	// First clear output structures.
	memset(tqStats, 0, numTxQueues * sizeof (vmk_NetVFTXQueueStats));
	memset(rqStats, 0, numRxQueues * sizeof (vmk_NetVFRXQueueStats));

	for (i = 0; i < numRxQueues; i++) {
		struct bnx2x_vfq_fw_stats *qstats = &vf->vfq_stats[i].qstats;
		vmk_NetVFRXQueueStats *old_vmk_rxq = &vf->vfq_stats[i].old_vmk_rxq;

		rqStats[i].unicastPkts = __pt_update_single_stat(
			HILO_U64(qstats->total_unicast_packets_received_hi,
				 qstats->total_unicast_packets_received_lo),
			&old_vmk_rxq->unicastPkts);

		rqStats[i].unicastBytes = __pt_update_single_stat(
			HILO_U64(qstats->total_unicast_bytes_received_hi,
				 qstats->total_unicast_bytes_received_lo),
			&old_vmk_rxq->unicastBytes);

		rqStats[i].multicastPkts = __pt_update_single_stat(
			HILO_U64(qstats->total_multicast_packets_received_hi,
				 qstats->total_multicast_packets_received_lo),
			&old_vmk_rxq->multicastPkts);

		rqStats[i].multicastBytes = __pt_update_single_stat(
			HILO_U64(qstats->total_multicast_bytes_received_hi,
				 qstats->total_multicast_bytes_received_lo),
			&old_vmk_rxq->multicastBytes);

		rqStats[i].broadcastPkts = __pt_update_single_stat(
			HILO_U64(qstats->total_broadcast_packets_received_hi,
				 qstats->total_broadcast_packets_received_lo),
			&old_vmk_rxq->broadcastPkts);

		rqStats[i].broadcastBytes = __pt_update_single_stat(
			HILO_U64(qstats->total_broadcast_bytes_received_hi,
				 qstats->total_broadcast_bytes_received_lo),
			&old_vmk_rxq->broadcastBytes);

		rqStats[i].outOfBufferDrops = __pt_update_single_stat(
			HILO_U64(qstats->no_buff_discard_hi,
				 qstats->no_buff_discard_lo),
			&old_vmk_rxq->outOfBufferDrops);

		rqStats[i].errorDrops = __pt_update_single_stat(
			HILO_U64(qstats->etherstatsoverrsizepkts_hi,
				 qstats->etherstatsoverrsizepkts_lo) +
			HILO_U64(qstats->error_discard_hi,
				 qstats->error_discard_lo),
			&old_vmk_rxq->errorDrops);

		rqStats[i].LROPkts = __pt_update_single_stat(
			vf->plugin_stats->rxq_stats[i].lro_pkts,
			&old_vmk_rxq->LROPkts);

		rqStats[i].LROBytes = __pt_update_single_stat(
			vf->plugin_stats->rxq_stats[i].lro_bytes,
			&old_vmk_rxq->LROBytes);
	}
	for (i = 0; i < numTxQueues; i++) {
		struct bnx2x_vfq_fw_stats *qstats = &vf->vfq_stats[i].qstats;
		vmk_NetVFTXQueueStats *old_vmk_txq = &vf->vfq_stats[i].old_vmk_txq;

		tqStats[i].unicastPkts = __pt_update_single_stat(
			HILO_U64(qstats->total_unicast_packets_sent_hi,
				 qstats->total_unicast_packets_sent_lo),
			&old_vmk_txq->unicastPkts);

		tqStats[i].unicastBytes = __pt_update_single_stat(
			HILO_U64(qstats->total_unicast_bytes_sent_hi,
				 qstats->total_unicast_bytes_sent_lo),
			&old_vmk_txq->unicastBytes);

		tqStats[i].multicastPkts = __pt_update_single_stat(
			HILO_U64(qstats->total_multicast_packets_sent_hi,
				 qstats->total_multicast_packets_sent_lo),
			&old_vmk_txq->multicastPkts);

		tqStats[i].multicastBytes = __pt_update_single_stat(
			HILO_U64(qstats->total_multicast_bytes_sent_hi,
				 qstats->total_multicast_bytes_sent_lo),
			&old_vmk_txq->multicastBytes);

		tqStats[i].broadcastPkts = __pt_update_single_stat(
			HILO_U64(qstats->total_broadcast_packets_sent_hi,
				 qstats->total_broadcast_packets_sent_lo),
			&old_vmk_txq->broadcastPkts);

		tqStats[i].broadcastBytes = __pt_update_single_stat(
			HILO_U64(qstats->total_broadcast_bytes_sent_hi,
				 qstats->total_broadcast_bytes_sent_lo),
			&old_vmk_txq->broadcastBytes);

		tqStats[i].errors = __pt_update_single_stat(
			HILO_U64(qstats->tx_error_packets_hi,
				 qstats->tx_error_packets_lo),
			&old_vmk_txq->errors);

		tqStats[i].TSOPkts = __pt_update_single_stat(
			vf->plugin_stats->txq_stats[i].tso_pkts,
			&old_vmk_txq->TSOPkts);

		tqStats[i].TSOBytes = __pt_update_single_stat(
			vf->plugin_stats->txq_stats[i].tso_bytes,
			&old_vmk_txq->TSOBytes);

		tqStats[i].discards = 0;
	}
	return VMK_OK;
}

// ---------------------------------------------------------------------------
//
// Non-passthrough vNIC control
//
static inline int bnx2x_pt_pf_mac_filter(struct bnx2x *bp, vmk_EthAddress mac,
					 bool add)
{
	unsigned long ramrod_flags = 0;
	int rc;

	set_bit(RAMROD_COMP_WAIT, &ramrod_flags);

	DECLARE_MAC_BUF(mac_buf);
	DP(BNX2X_MSG_IOV, "%s %s\n", add ? "Adding" : "Deleting",
	   print_mac(mac_buf, mac));

	rc = bnx2x_set_mac_one(bp, mac, &bp->fp->mac_obj, add,
			       BNX2X_ETH_MAC, &ramrod_flags);
	if (rc == -EEXIST)
		rc = 0;

	return rc;
}

static inline int
bnx2x_pt_pf_add_mac_filter(struct net_device *netdev, vmk_EthAddress mac)
{
	return VMK_RET(bnx2x_pt_pf_mac_filter(netdev_priv(netdev), mac, true));
}

static inline int
bnx2x_pt_pf_del_mac_filter(struct net_device *netdev, vmk_EthAddress mac)
{
	return VMK_RET(bnx2x_pt_pf_mac_filter(netdev_priv(netdev), mac, false));
}

static int
bnx2x_pt_pf_mirror_all(struct net_device *netdev, uint8_t enable)
{
	struct bnx2x *bp = netdev_priv(netdev);
	unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
	unsigned long ramrod_flags = 0;

	DP(BNX2X_MSG_IOV, "%s\n", ENABLE_STR(enable));

	if (!enable) {
		/* restore rx_mode */
		bnx2x_set_rx_mode(bp->dev);
		return VMK_OK;
	}
	if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
		/* no support for concurrent rx_mode requests */
		return VMK_BUSY;

	/* rx -promiscuous */
	set_bit(BNX2X_ACCEPT_ALL_UNICAST, &rx_accept_flags);
	set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags);
	set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);

	/* tx all-multi */
	set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
	set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags);
	set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);

	set_bit(RAMROD_RX, &ramrod_flags);
	set_bit(RAMROD_TX, &ramrod_flags);
	set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
	bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, 0, rx_accept_flags,
			    tx_accept_flags, ramrod_flags);
	return VMK_OK;
}

// ---------------------------------------------------------------------------
//
// Dispatch & logging operations
//
static VMK_ReturnStatus
bnx2x_pt_passthru_ops2(struct net_device *netdev, vmk_NetPTOP op, void *pargs)
{
	switch (op) {
	case VMK_NETPTOP_VF_ACQUIRE:
	{
		vmk_NetPTOPVFAcquireArgs *args = pargs;
		return bnx2x_pt_vf_acquire(netdev, &args->props, &args->vf);
	}
	case VMK_NETPTOP_VF_INIT:
	{
		vmk_NetPTOPVFInitArgs *args = pargs;
		return bnx2x_pt_vf_init(netdev, args->vf, &args->params);
	}
	case VMK_NETPTOP_VF_ACTIVATE:
	{
		vmk_NetPTOPVFSimpleArgs *args = pargs;
		return bnx2x_pt_vf_activate(netdev, args->vf);
	}
	case VMK_NETPTOP_VF_QUIESCE:
	{
		vmk_NetPTOPVFSimpleArgs *args = pargs;
		return bnx2x_pt_vf_quiesce(netdev, args->vf);
	}
	case VMK_NETPTOP_VF_RELEASE:
	{
		vmk_NetPTOPVFSimpleArgs *args = pargs;
		return bnx2x_pt_vf_release(netdev, args->vf);
	}
	case VMK_NETPTOP_VF_GET_INFO:
	{
		vmk_NetPTOPVFGetInfoArgs *args = pargs;
		return bnx2x_pt_vf_get_info(netdev, args->vf, &args->info);
	}
	case VMK_NETPTOP_VF_SET_RSS_IND_TABLE:
	{
		vmk_NetPTOPVFSetRSSIndTableArgs *args = pargs;
		return bnx2x_pt_vf_set_rss_ind_table(netdev, args->vf,
						     &args->table);
	}
	case VMK_NETPTOP_VF_GET_QUEUE_STATS:
	{
		vmk_NetPTOPVFGetQueueStatsArgs *args = pargs;
		return bnx2x_pt_vf_get_queue_stats(netdev, args->vf,
						   args->numTxQueues,
						   args->numRxQueues,
						   args->tqStats,
						   args->rqStats);
	}
	case VMK_NETPTOP_VF_GET_QUEUE_STATUS:
	{
		vmk_NetPTOPVFGetQueueStatusArgs *args = pargs;
		return bnx2x_pt_vf_get_queue_status(netdev,
						    args->vf,
						    args->numTxQueues,
						    args->numRxQueues,
						    args->tqStatus,
						    args->rqStatus);
	}
	case VMK_NETPTOP_VF_SET_MAC:
	{
		vmk_NetPTOPVFSetMacArgs *args = pargs;
		return bnx2x_pt_vf_set_mac(netdev, args->vf, args->mac);
	}
	case VMK_NETPTOP_VF_SET_MULTICAST:
	{
		vmk_NetPTOPVFSetMulticastArgs *args = pargs;
		return bnx2x_pt_vf_set_multicast(netdev,
						 args->vf,
						 args->nmac,
						 args->macList);
	}
	case VMK_NETPTOP_VF_SET_RX_MODE:
	{
		vmk_NetPTOPVFSetRxModeArgs *args = pargs;
		// promiscuous is not supported by NPA
		return bnx2x_pt_vf_set_rx_mode(netdev,
					       args->vf,
					       args->unicast,
					       args->multicast,
					       args->broadcast,
					       args->allmulti);
	}
	case VMK_NETPTOP_VF_ADD_VLAN_RANGE:
	{
		vmk_NetPTOPVFVlanRangeArgs *args = pargs;
		return bnx2x_pt_vf_add_vlan_range(netdev,
						  args->vf,
						  args->first,
						  args->last);
	}
	case VMK_NETPTOP_VF_DEL_VLAN_RANGE:
	{
		vmk_NetPTOPVFVlanRangeArgs *args = pargs;
		return bnx2x_pt_vf_del_vlan_range(netdev,
						  args->vf,
						  args->first,
						  args->last);
	}
	case VMK_NETPTOP_VF_SET_DEFAULT_VLAN:
	{
		vmk_NetPTOPVFSetDefaultVlanArgs *args = pargs;
		return bnx2x_pt_vf_set_default_vlan(netdev,
						    args->vf,
						    args->enable,
						    args->vid,
						    args->prio);
	}
	case VMK_NETPTOP_VF_SET_ANTISPOOF:
	{
		vmk_NetPTOPVFSetAntispoofArgs *args = pargs;
		return bnx2x_pt_vf_set_antispoof(netdev,
						 args->vf,
						 args->enable);
	}
	case VMK_NETPTOP_PF_ADD_MAC_FILTER:
	{
		vmk_NetPTOPPFMacFilterArgs *args = pargs;
		return bnx2x_pt_pf_add_mac_filter(netdev, args->mac);
	}
	case VMK_NETPTOP_PF_DEL_MAC_FILTER:
	{
		vmk_NetPTOPPFMacFilterArgs *args = pargs;
		return bnx2x_pt_pf_del_mac_filter(netdev, args->mac);
	}
	case VMK_NETPTOP_PF_MIRROR_ALL:
	{
		vmk_NetPTOPPFMirrorAllArgs *args = pargs;
		return bnx2x_pt_pf_mirror_all(netdev, args->enable);
	}
	default:
		printk("Unhandled NPA OP %d\n", op);
		return VMK_FAILURE;
	}
}

/*
 * This wrapper is here to dump registers before/after doing an
 * operation.
 */
VMK_ReturnStatus
bnx2x_pt_passthru_ops(void *client_data, vmk_NetPTOP op, void *args)
{
	VMK_ReturnStatus ret;

	// Do the job
	ret = bnx2x_pt_passthru_ops2(client_data, op, args);

	if (ret != VMK_OK) {
		printk("PT OP %d failed, ret=%X\n", op, ret);
	}
	return ret;
}

#endif /* BNX2X_PASSTHRU */
#endif /* BCM_IOV */

#if (VMWARE_ESX_DDK_VERSION >= 55000)
#define MISC_REG_AEU_MASK_ATTN_MCP 0xa068
#define NIG_REG_BMAC1_PAUSE_OUT_EN 0x10114
#define NIG_REG_EMAC1_PAUSE_OUT_EN 0x1011c

static struct dmp_config dmpcfg;
vmklnx_DumpFileHandle bnx2x_fwdmp_dh;
void *bnx2x_fwdmp_va;
struct bnx2x_fwdmp_info bnx2x_fwdmp_bp[BNX2X_MAX_NIC+1];

static void esx_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val)
{
	pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
	pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val);
	pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
			       PCICFG_VENDOR_ID_OFFSET);
}

static u32 esx_reg_rd_ind(struct bnx2x *bp, u32 addr)
{
	u32 val;

	pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
	pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val);
	pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
			       PCICFG_VENDOR_ID_OFFSET);

	return val;
}

static u32 *
read_idle_chk(struct bnx2x *bp, u32 *dst, struct chip_core_dmp *dmp)
{
	u32 i, j;

	/* Read the idle chk registers */
	for (i = 0; i < IDLE_REGS_COUNT; i++)
		if (dmpcfg.mode == (idle_addrs[i].info & dmpcfg.mode))
			for (j = 0; j < idle_addrs[i].size; j++) {
				if ((dmp->fw_hdr.dmp_size + 4) >
				    DRV_DUMP_CRASH_DMP_BUF_SIZE_E3B0) {
					SET_FLAGS(dmp->fw_hdr.flags,
						  FWDMP_FLAGS_SPACE_NEEDED);
					break;
				}
				*dst++ = RD_IND(bp,
						idle_addrs[i].addr + j*4);
				dmp->fw_hdr.dmp_size += 4;
			}
	return dst;
}

static u32 *
read_mcp_traces(struct bnx2x *bp, u32 *dst, struct chip_core_dmp *dmp)
{
	u32 trace_shmem_base;
	u32 addr;
	u32 i;

	if (dmp->fw_hdr.dmp_size + DBG_DMP_TRACE_BUFFER_SIZE >
		DRV_DUMP_CRASH_DMP_BUF_SIZE_E3B0) {
		SET_FLAGS(dmp->fw_hdr.flags, FWDMP_FLAGS_SPACE_NEEDED);
		return dst;
	}

	if (BP_PATH(bp) == 0)
		trace_shmem_base = bp->common.shmem_base;
	else
		trace_shmem_base = SHMEM2_RD(bp, other_shmem_base_addr);

	addr = trace_shmem_base - DBG_DMP_TRACE_BUFFER_SIZE;
	for (i = 0; i < DBG_DMP_TRACE_BUFFER_SIZE;) {
		if ((dmp->fw_hdr.dmp_size + 4)
			> DRV_DUMP_CRASH_DMP_BUF_SIZE_E3B0) {
			SET_FLAGS(dmp->fw_hdr.flags, FWDMP_FLAGS_SPACE_NEEDED);
			break;
		}
		*dst++ = RD_IND(bp, addr + i);
		i += 4;
		dmp->fw_hdr.dmp_size += 4;
	}
	return dst;
}

static u32 *
read_regular_regs(struct bnx2x *bp, u32 *dst, struct chip_core_dmp *dmp)
{
	u32 i, j;

	/* Read the regular address registers */
	for (i = 0; i < REGS_COUNT; i++)
		if (dmpcfg.mode == (reg_addrs[i].info & dmpcfg.mode))
			for (j = 0; j < reg_addrs[i].size; j++) {
				if ((dmp->fw_hdr.dmp_size + 4) >
				    DRV_DUMP_CRASH_DMP_BUF_SIZE_E3B0) {
					SET_FLAGS(dmp->fw_hdr.flags,
						  FWDMP_FLAGS_SPACE_NEEDED);
					break;
				}
				*dst++ = RD_IND(bp, reg_addrs[i].addr + j*4);
				dmp->fw_hdr.dmp_size += 4;
			}
	return dst;
}

static u32 *
read_wregs(struct bnx2x *bp, u32 *dst, struct chip_core_dmp *dmp)
{
	u32 i, j, k;
	u32 reg_add_read = 0;
	const struct wreg_addr *pwreg_addrs = dmpcfg.pwreg_addrs;

	for (i = 0; i < dmpcfg.wregs_count; i++) {
		if (dmpcfg.mode == (pwreg_addrs[i].info & dmpcfg.mode)) {
			reg_add_read = pwreg_addrs[i].addr;
			for (j = 0; j < pwreg_addrs[i].size; j++) {
				if ((dmp->fw_hdr.dmp_size + 4) >
				    DRV_DUMP_CRASH_DMP_BUF_SIZE_E3B0) {
					SET_FLAGS(dmp->fw_hdr.flags,
						  FWDMP_FLAGS_SPACE_NEEDED);
					break;
				}
				*dst++ = RD_IND(bp, reg_add_read);
				reg_add_read += 4;
				dmp->fw_hdr.dmp_size += 4;
				for (k = 0;
				     k < pwreg_addrs[i].read_regs_count; k++) {
					if ((dmp->fw_hdr.dmp_size + 4) >
					    DRV_DUMP_CRASH_DMP_BUF_SIZE_E3B0) {
						SET_FLAGS(dmp->fw_hdr.flags,
						      FWDMP_FLAGS_SPACE_NEEDED);
						break;
					}
					*dst++ = RD_IND(bp,
						   pwreg_addrs[i].read_regs[k]);
					dmp->fw_hdr.dmp_size += 4;
				}
			}
		}
	}
	return dst;
}

static u32 *
read_page_mode(struct bnx2x *bp, u32 *dst, struct chip_core_dmp *dmp)
{
	u32 index_page_vals       = 0;
	u32 index_page_write_regs = 0;
	const struct reg_addr *page_read_regs = dmpcfg.page_read_regs;
	u32 i, j;

	/* If one of the array size is zero, this means that
	   page mode is disabled. */
	if ((0 == dmpcfg.page_mode_values_count) ||
	    (0 == dmpcfg.page_write_regs_count) ||
	    (0 == dmpcfg.page_read_regs_count))
		return dst;

	for (index_page_vals = 0;
	     index_page_vals < dmpcfg.page_mode_values_count;
	     index_page_vals++) {
		for (index_page_write_regs = 0;
		     index_page_write_regs < dmpcfg.page_write_regs_count;
		     index_page_write_regs++) {
			WR_IND(bp,
			       dmpcfg.page_write_regs[index_page_write_regs],
			       dmpcfg.page_vals[index_page_vals]);
		}
		for (i = 0; i < dmpcfg.page_read_regs_count; i++) {
			if (dmpcfg.mode ==
				(page_read_regs[i].info & dmpcfg.mode)) {
				for (j = 0; j < page_read_regs[i].size; j++) {
					if ((dmp->fw_hdr.dmp_size + 4) >
					    DRV_DUMP_CRASH_DMP_BUF_SIZE_E3B0) {
						SET_FLAGS(dmp->fw_hdr.flags,
						   FWDMP_FLAGS_SPACE_NEEDED);
						break;
					}
					*dst++ = RD_IND(bp,
						  page_read_regs[i].addr + j*4);
					dmp->fw_hdr.dmp_size += 4;
				}
			}
		}
	}
	return dst;
}

static void
get_vfc_info(struct bnx2x *bp,
	     const struct vfc_general **xvfc_info,
	     const struct vfc_general **tvfc_info)
{
	if (CHIP_IS_E1(bp)) {
		*xvfc_info = &vfc_general_x_e1;
		*tvfc_info = &vfc_general_t_e1;
	} else if (CHIP_IS_E1H(bp)) {
		*xvfc_info = &vfc_general_x_e1h;
		*tvfc_info = &vfc_general_t_e1h;
	} else if (CHIP_IS_E2(bp)) {
		*xvfc_info = &vfc_general_x_e2;
		*tvfc_info = &vfc_general_t_e2;
	} else if (CHIP_IS_E3(bp)) {
		*xvfc_info = &vfc_general_x_e3;
		*tvfc_info = &vfc_general_t_e3;
	} else {
		*xvfc_info = NULL;
		*tvfc_info = NULL;
	}
}

static void get_vfc_ops(struct bnx2x *bp,
		   const struct vfc_read_task **xvfc_ops,
		   const struct vfc_read_task **tvfc_ops)
{
	if (CHIP_IS_E2(bp)) {
		*xvfc_ops = &vfc_task_x_e2;
		*tvfc_ops = &vfc_task_t_e2;
	} else if (CHIP_IS_E3(bp)) {
		*xvfc_ops = &vfc_task_x_e3;
		*tvfc_ops = &vfc_task_t_e3;
	} else {
		*xvfc_ops = NULL;
		*tvfc_ops = NULL;
	}
}

static void
init_extension_header(u32 data_type,
		      u32 data_source,
		      struct extension_hdr *header)
{
	header->hdr_signature = HDR_SIGNATURE;
	header->hdr_size = (sizeof(*header) -
			    sizeof(header->hdr_size)) / sizeof(u32);
	header->data_type = data_type;
	header->data_source = data_source;
}

static u8
wait_for_reg_value_equals(struct bnx2x *bp,
	u32 offset,
	u32 mask,
	u32 expected_value,
	u32 timeout_us)
{
	u32 reg_value = 0;
	u32 wait_cnt = 0;
	u32 wait_cnt_limit = timeout_us/DEFAULT_WAIT_INTERVAL_MICSEC;

	reg_value = RD_IND(bp, offset);
	while (((reg_value & mask) != expected_value) &&
		(wait_cnt++ != wait_cnt_limit)) {
		udelay(DEFAULT_WAIT_INTERVAL_MICSEC);
		reg_value = RD_IND(bp, offset);
	}
	return ((reg_value & mask) == expected_value);
}

static u32 *
read_vfc_block(struct bnx2x *bp,
		const struct vfc_general *vfc_info,
		const struct vfc_read_task *vfc_ops,
		struct extension_hdr *header,
		u32 *dst,
		struct chip_core_dmp *dmp,
		u8 *rc)
{
	u32 cur_op_idx, i;
	const struct vfc_read_write_vector *current_entry = NULL;
	u32 *dst_start = dst;

	if (!vfc_info->valid || !vfc_info->valid) {
		*rc = false;
		return dst;
	}
	if (!wait_for_reg_value_equals(bp, vfc_info->vfc_status,
				0xFFFFFFFF, 0, 1000)) {
		header->error = true;
		*rc = false;
		goto exit;
	}
	if (dmp->fw_hdr.dmp_size + sizeof(*header) >
		DRV_DUMP_CRASH_DMP_BUF_SIZE_E3B0) {
		SET_FLAGS(dmp->fw_hdr.flags, FWDMP_FLAGS_SPACE_NEEDED);
		*rc = false;
		return dst;
	}
	dst += sizeof(*header)/sizeof(u32);
	dmp->fw_hdr.dmp_size += sizeof(*header);
	for (cur_op_idx = 0; cur_op_idx < vfc_ops->array_size; ++cur_op_idx) {
		current_entry = &vfc_ops->read_write_vectors[cur_op_idx];
		for (i = 0; i < current_entry->write_value_num_valid; ++i) {
			WR_IND(bp,
				vfc_info->vfc_data_write,
				current_entry->write_value[i]);
		}
		WR_IND(bp,
			vfc_info->vfc_address, current_entry->address_value);
		for (i = 0; i < current_entry->read_size; ++i) {
			if (!wait_for_reg_value_equals(bp, vfc_info->vfc_status,
				RI_VFC_IS_READY, RI_VFC_IS_READY, 1000)) {
				u32 reg_value;

				reg_value =
					RD_IND(bp, vfc_info->vfc_status);
				header->error = true;
				*rc = false;
				goto exit;
			}
			if ((dmp->fw_hdr.dmp_size + 4) >
			    DRV_DUMP_CRASH_DMP_BUF_SIZE_E3B0) {
				SET_FLAGS(dmp->fw_hdr.flags,
					  FWDMP_FLAGS_SPACE_NEEDED);
				*rc = false;
				break;
			}
			*dst++ = RD_IND(bp, vfc_info->vfc_data_read);
			header->data_size++;
			dmp->fw_hdr.dmp_size += 4;
		}
	}
exit:
	memcpy((u8 *)dst_start, header, sizeof(*header));
	return dst;
}

static u32 *
read_vfc(struct bnx2x *bp, u32 *dst, struct chip_core_dmp *dmp, u8 *status)
{
	u8 rc = false;
	struct extension_hdr xvfc_header = {0};
	struct extension_hdr tvfc_header = {0};

	const struct vfc_general *xvfc_info = NULL;
	const struct vfc_general *tvfc_info = NULL;
	const struct vfc_read_task *xvfc_ops = NULL;
	const struct vfc_read_task *tvfc_ops = NULL;

	get_vfc_info(bp, &xvfc_info, &tvfc_info);
	get_vfc_ops(bp, &xvfc_ops, &tvfc_ops);
	if ((xvfc_info == NULL) || (tvfc_info == NULL)) {
		*status = false;
		return dst;
	}
	init_extension_header(RI_TYPE_VFC, RI_SRC_XSTORM, &xvfc_header);
	init_extension_header(RI_TYPE_VFC, RI_SRC_TSTORM, &tvfc_header);
	dst = read_vfc_block(bp,
		xvfc_info, xvfc_ops, &xvfc_header, dst, dmp, &rc);
	if (!rc) {
		*status = rc;
		return dst;
	}
	dst = read_vfc_block(bp,
		tvfc_info, tvfc_ops, &tvfc_header, dst, dmp, &rc);
	*status = rc;
	return dst;
}

static const struct igu_data *get_igu_info(struct bnx2x *bp)
{
	if (CHIP_IS_E1(bp))
		return &igu_address_e1;
	else if (CHIP_IS_E1H(bp))
		return &igu_address_e1h;
	else if (CHIP_IS_E2(bp))
		return &igu_address_e2;
	else if (CHIP_IS_E3(bp))
		return &igu_address_e3;
	else
		return NULL;
}

static u32 *
read_igu(struct bnx2x *bp, u32 *dst, struct chip_core_dmp *dmp, u8 *status)
{
	struct extension_hdr igu_header = {0};
	const struct igu_data *igu_info = get_igu_info(bp);
	u32 iter_cnt = 0;
	u32 more_data = 0;
	u32 *dst_start = dst;

	init_extension_header(RI_TYPE_IGU, RI_OTHER_BLOCK, &igu_header);
	if (!igu_info) {
		*status = false;
		return dst;
	}
	if (!igu_info->valid) {
		*status = true;
		return dst;
	}
	more_data = RD_IND(bp, igu_info->is_data_valid);
	if (!more_data) {
		*status = true;
		return dst;
	}
	if (dmp->fw_hdr.dmp_size + sizeof(igu_header) >
		DRV_DUMP_CRASH_DMP_BUF_SIZE_E3B0) {
		SET_FLAGS(dmp->fw_hdr.flags, FWDMP_FLAGS_SPACE_NEEDED);
		*status = false;
		return dst;
	}
	dst += sizeof(igu_header)/sizeof(u32);
	dmp->fw_hdr.dmp_size += sizeof(igu_header);
	igu_header.additional_data = RD_IND(bp, igu_info->is_last_commands);
	do {
		if ((dmp->fw_hdr.dmp_size + 4) >
		    DRV_DUMP_CRASH_DMP_BUF_SIZE_E3B0) {
			SET_FLAGS(dmp->fw_hdr.flags,
				  FWDMP_FLAGS_SPACE_NEEDED);
			igu_header.error = true;
			*status = false;
			break;
		}
		*dst++ = RD_IND(bp, igu_info->data[0]);
		++igu_header.data_size;
		dmp->fw_hdr.dmp_size += 4;
		if ((dmp->fw_hdr.dmp_size + 4) >
		    DRV_DUMP_CRASH_DMP_BUF_SIZE_E3B0) {
			SET_FLAGS(dmp->fw_hdr.flags,
				  FWDMP_FLAGS_SPACE_NEEDED);
			igu_header.error = true;
			*status = false;
			break;
		}
		*dst++ = RD_IND(bp, igu_info->data[1]);
		++igu_header.data_size;
		dmp->fw_hdr.dmp_size += 4;
		more_data = RD_IND(bp, igu_info->is_data_valid);
		++iter_cnt;
	} while (more_data && (iter_cnt < igu_info->max_size));

	memcpy((u8 *)dst_start, &igu_header, sizeof(igu_header));
	return dst;
}

static u32 *
read_additional_blocks(struct bnx2x *bp, u32 *dst, struct chip_core_dmp *dmp)
{
	u8 dmp_status = false;

	dst = read_vfc(bp, dst, dmp, &dmp_status);
	if (dmp_status)
		dst = read_igu(bp, dst, dmp, &dmp_status);
	return dst;
}

static u32 *
dmp_stop_timer(struct bnx2x *bp, u32 *dst, struct chip_core_dmp *dmp)
{
	u32 i, j;
	u32 *timer_scan_reg;

	if ((dmp->fw_hdr.dmp_size + (2 * dmpcfg.regs_timer_count)) >=
	    DRV_DUMP_CRASH_DMP_BUF_SIZE_E3B0) {
		SET_FLAGS(dmp->fw_hdr.flags,
			  FWDMP_FLAGS_SPACE_NEEDED);
		return dst;
	}
	if (dmp->fw_hdr.flags & FWDMP_FLAGS_LIVE_DUMP) {
		/* driver shouldn't read the timer in online
		   since it could cause attention. However,
		   it should fills the buffer and move on */
		for (i = 0;
		     i < 2 * dmpcfg.regs_timer_count;
		     i++) {
			*dst++ = 0;
			dmp->fw_hdr.dmp_size += 4;
		}
		return dst;
	}
	for (i = 0; i < dmpcfg.regs_timer_count; i++) {
		*dst = RD_IND(bp, dmpcfg.regs_timer_status_addrs[i]);
		timer_scan_reg = dst + dmpcfg.regs_timer_count;
		if (*dst == 1) {
			WR_IND(bp, dmpcfg.regs_timer_status_addrs[i], 0);
			for (j = 0; j < DRV_DUMP_MAX_TIMER_PENDING; j++) {
				*timer_scan_reg = RD_IND(bp,
					 dmpcfg.regs_timer_scan_addrs[i]);
				if (*timer_scan_reg == 0)
					break;
			}
		} else {
			*timer_scan_reg = DRV_DUMP_TIMER_SCAN_DONT_CARE;
		}
		dst++;
		dmp->fw_hdr.dmp_size += 4;
	}
	dst += dmpcfg.regs_timer_count;
	dmp->fw_hdr.dmp_size += 4 * dmpcfg.regs_timer_count;
	return dst;
}

static void
dmp_rollback_timer(struct bnx2x *bp,
	struct chip_core_dmp *dmp,
	u32 *tmr_status)
{
	u32 i;

	if (dmp->fw_hdr.flags & FWDMP_FLAGS_LIVE_DUMP)
		return;
	for (i = 0; i < dmpcfg.regs_timer_count; i++) {
		if (*tmr_status == 1)
			WR_IND(bp, dmpcfg.regs_timer_status_addrs[i], 1);
		tmr_status++;
	}
}

static void
init_dump_header(struct bnx2x *bp,
	struct esx_dump_hdr *dump_hdr,
	struct dmp_config *dmpcfg,
	struct chip_core_dmp *dmp)
{
	dump_hdr->hdr_size = (sizeof(struct esx_dump_hdr)/4) - 1;
	dump_hdr->dump_sign = hd_param_all;
	dump_hdr->idle_chk = 1;
	dump_hdr->xstorm_waitp = RD_IND(bp, DRV_DUMP_XSTORM_WAITP_ADDRESS);
	dump_hdr->tstorm_waitp = RD_IND(bp, DRV_DUMP_TSTORM_WAITP_ADDRESS);
	dump_hdr->ustorm_waitp = RD_IND(bp, DRV_DUMP_USTORM_WAITP_ADDRESS);
	dump_hdr->cstorm_waitp = RD_IND(bp, DRV_DUMP_CSTORM_WAITP_ADDRESS);

	if (CHIP_IS_E1(bp)) {
		if (dmp->fw_hdr.flags & FWDMP_FLAGS_LIVE_DUMP)
			dump_hdr->info = RI_E1_ONLINE;
		else
			dump_hdr->info = RI_E1_OFFLINE;
		dmpcfg->wregs_count = WREGS_COUNT_E1;
		dmpcfg->pwreg_addrs = wreg_addrs_e1;
		dmpcfg->regs_timer_count = TIMER_REGS_COUNT_E1;
		dmpcfg->regs_timer_status_addrs = timer_status_regs_e1;
		dmpcfg->regs_timer_scan_addrs = timer_scan_regs_e1;
		dmpcfg->page_mode_values_count =
				PAGE_MODE_VALUES_E1;
		dmpcfg->page_vals = page_vals_e1;
		dmpcfg->page_write_regs_count = PAGE_WRITE_REGS_E1;
		dmpcfg->page_write_regs = page_write_regs_e1;
		dmpcfg->page_read_regs_count = PAGE_READ_REGS_E1;
		dmpcfg->page_read_regs = page_read_regs_e1;
	} else if (CHIP_IS_E1H(bp)) {
		if (dmp->fw_hdr.flags & FWDMP_FLAGS_LIVE_DUMP)
			dump_hdr->info = RI_E1H_ONLINE;
		else
			dump_hdr->info = RI_E1H_OFFLINE;
		dmpcfg->wregs_count = WREGS_COUNT_E1H;
		dmpcfg->pwreg_addrs = wreg_addrs_e1h;
		dmpcfg->regs_timer_count = TIMER_REGS_COUNT_E1H;
		dmpcfg->regs_timer_status_addrs = timer_status_regs_e1h;
		dmpcfg->regs_timer_scan_addrs = timer_scan_regs_e1h;
		dmpcfg->page_mode_values_count =
				PAGE_MODE_VALUES_E1H;
		dmpcfg->page_vals = page_vals_e1h;
		dmpcfg->page_write_regs_count = PAGE_WRITE_REGS_E1H;
		dmpcfg->page_write_regs = page_write_regs_e1h;
		dmpcfg->page_read_regs_count = PAGE_READ_REGS_E1H;
		dmpcfg->page_read_regs = page_read_regs_e1h;
	} else if (CHIP_IS_E2(bp)) {
		if (dmp->fw_hdr.flags & FWDMP_FLAGS_LIVE_DUMP)
			dump_hdr->info = RI_E2_ONLINE |
			(BP_PATH(bp) ? RI_PATH1_DUMP : RI_PATH0_DUMP);
		else
			dump_hdr->info = RI_E2_OFFLINE |
			(BP_PATH(bp) ? RI_PATH1_DUMP : RI_PATH0_DUMP);
		dmpcfg->wregs_count = WREGS_COUNT_E2;
		dmpcfg->pwreg_addrs = wreg_addrs_e2;
		dmpcfg->regs_timer_count = TIMER_REGS_COUNT_E2;
		dmpcfg->regs_timer_status_addrs = timer_status_regs_e2;
		dmpcfg->regs_timer_scan_addrs = timer_scan_regs_e2;
		dmpcfg->page_mode_values_count =
				PAGE_MODE_VALUES_E2;
		dmpcfg->page_vals = page_vals_e2;
		dmpcfg->page_write_regs_count = PAGE_WRITE_REGS_E2;
		dmpcfg->page_write_regs = page_write_regs_e2;
		dmpcfg->page_read_regs_count = PAGE_READ_REGS_E2;
		dmpcfg->page_read_regs = page_read_regs_e2;
	} else if (CHIP_IS_E3A0(bp)) {
		if (dmp->fw_hdr.flags & FWDMP_FLAGS_LIVE_DUMP)
			dump_hdr->info = RI_E3_ONLINE |
			(BP_PATH(bp) ? RI_PATH1_DUMP : RI_PATH0_DUMP);
		else
			dump_hdr->info = RI_E3_OFFLINE |
			(BP_PATH(bp) ? RI_PATH1_DUMP : RI_PATH0_DUMP);
		dmpcfg->wregs_count = WREGS_COUNT_E3;
		dmpcfg->pwreg_addrs = wreg_addrs_e3;
		dmpcfg->regs_timer_count = TIMER_REGS_COUNT_E3;
		dmpcfg->regs_timer_status_addrs = timer_status_regs_e3;
		dmpcfg->regs_timer_scan_addrs = timer_scan_regs_e3;
		dmpcfg->page_mode_values_count =
				PAGE_MODE_VALUES_E3;
		dmpcfg->page_vals = page_vals_e3;
		dmpcfg->page_write_regs_count = PAGE_WRITE_REGS_E3;
		dmpcfg->page_write_regs = page_write_regs_e3;
		dmpcfg->page_read_regs_count = PAGE_READ_REGS_E3; 
		dmpcfg->page_read_regs = page_read_regs_e3;
	} else if (CHIP_IS_E3B0(bp)) {
		if (dmp->fw_hdr.flags & FWDMP_FLAGS_LIVE_DUMP)
			dump_hdr->info = RI_E3B0_ONLINE |
			(BP_PATH(bp) ? RI_PATH1_DUMP : RI_PATH0_DUMP);
		else
			dump_hdr->info = RI_E3B0_OFFLINE |
			(BP_PATH(bp) ? RI_PATH1_DUMP : RI_PATH0_DUMP);
		dmpcfg->wregs_count = WREGS_COUNT_E3B0;
		dmpcfg->pwreg_addrs = wreg_addrs_e3b0;
		dmpcfg->regs_timer_count = TIMER_REGS_COUNT_E3B0;
		dmpcfg->regs_timer_status_addrs = timer_status_regs_e3b0;
		dmpcfg->regs_timer_scan_addrs = timer_scan_regs_e3b0;
		dmpcfg->page_mode_values_count =
				PAGE_MODE_VALUES_E3;
		dmpcfg->page_vals = page_vals_e3;
		dmpcfg->page_write_regs_count = PAGE_WRITE_REGS_E3;
		dmpcfg->page_write_regs = page_write_regs_e3;
		dmpcfg->page_read_regs_count = PAGE_READ_REGS_E3;
		dmpcfg->page_read_regs = page_read_regs_e3;
	}
	dmpcfg->mode = dump_hdr->info & ~(RI_PATH1_DUMP |  RI_PATH0_DUMP);
}

static void disable_pause(struct bnx2x *bp)
{
	if (CHIP_IS_E1x(bp) || CHIP_IS_E2(bp)) {
		WR_IND(bp, NIG_REG_BMAC0_PAUSE_OUT_EN, 0);
		WR_IND(bp, NIG_REG_BMAC1_PAUSE_OUT_EN, 0);
		WR_IND(bp, NIG_REG_EMAC0_PAUSE_OUT_EN, 0);
		WR_IND(bp, NIG_REG_EMAC1_PAUSE_OUT_EN, 0);
	} else {
		WR_IND(bp, NIG_REG_P0_MAC_PAUSE_OUT_EN, 0);
		WR_IND(bp, NIG_REG_P1_MAC_PAUSE_OUT_EN, 0);
	}
}

VMK_ReturnStatus bnx2x_fwdmp_callback(void *cookie, vmk_Bool liveDump)
{
	VMK_ReturnStatus status = VMK_OK;
	u32 idx;
	u32 *dst, *tmr_status;
	struct bnx2x *bp;
	struct esx_dump_hdr dump_hdr = {0};
	struct chip_core_dmp *dmp;

	for (idx = 0; idx < BNX2X_MAX_NIC; idx++) {
		if (bnx2x_fwdmp_va && bnx2x_fwdmp_bp[idx].bp) {
			if (bnx2x_fwdmp_bp[idx].disable_fwdmp)
				continue;
			bp = bnx2x_fwdmp_bp[idx].bp;
			dst = bnx2x_fwdmp_va;
			/* build the fw dump header */
			dmp = (struct chip_core_dmp *)dst;
			snprintf(dmp->fw_hdr.name, sizeof(dmp->fw_hdr.name),
				"%s", bp->dev->name);
			dmp->fw_hdr.bp = (void *)bp;
			dmp->fw_hdr.chip_id = bp->common.chip_id;
			dmp->fw_hdr.len = sizeof(struct fw_dmp_hdr);
			dmp->fw_hdr.ver = 0x000700006;
			dmp->fw_hdr.dmp_size = dmp->fw_hdr.len;
			dmp->fw_hdr.flags = 0;
			if (liveDump)
				SET_FLAGS(dmp->fw_hdr.flags, FWDMP_FLAGS_LIVE_DUMP);
			memset(&dmpcfg, 0, sizeof(struct dmp_config));
			memset(&dump_hdr, 0, sizeof(struct esx_dump_hdr));
			dst = dmp->fw_dmp_buf;
			bnx2x_disable_blocks_parity(bp);
			/* build the GRC dump header */
			init_dump_header(bp, &dump_hdr, &dmpcfg, dmp);
			memcpy(dst, &dump_hdr, sizeof(struct esx_dump_hdr));
			dst += dump_hdr.hdr_size + 1;
			dmp->fw_hdr.dmp_size += (dump_hdr.hdr_size + 1) * 4;
			/* stop the timers before idle check. */
			tmr_status = dst;
			dst = dmp_stop_timer(bp, dst, dmp);
			if (dmp->fw_hdr.flags & FWDMP_FLAGS_SPACE_NEEDED)
				goto write_file;
			/* dump 1st idle check */
			dst = read_idle_chk(bp, dst, dmp);
			if (dmp->fw_hdr.flags & FWDMP_FLAGS_SPACE_NEEDED)
				goto write_file;
			/* dump 2nd idle check */
			dst = read_idle_chk(bp, dst, dmp);
			/* Enable the timers after idle check. */
			dmp_rollback_timer(bp, dmp, tmr_status);
			if (dmp->fw_hdr.flags & FWDMP_FLAGS_SPACE_NEEDED)
				goto write_file;
			/* dump mcp traces */
			dst = read_mcp_traces(bp, dst, dmp);
			if (dmp->fw_hdr.flags & FWDMP_FLAGS_SPACE_NEEDED)
				goto write_file;
			/* dump regular address registers */
			dst = read_regular_regs(bp, dst, dmp);
			if (dmp->fw_hdr.flags & FWDMP_FLAGS_SPACE_NEEDED)
				goto write_file;
			/* dump wide bus registers */
			dst = read_wregs(bp, dst, dmp);
			if (dmp->fw_hdr.flags & FWDMP_FLAGS_SPACE_NEEDED)
				goto write_file;
			/* dump read page mode registers */
			dst = read_page_mode(bp, dst, dmp);
			if (dmp->fw_hdr.flags & FWDMP_FLAGS_SPACE_NEEDED)
				goto write_file;
			/* dump additional blocks */
			dst = read_additional_blocks(bp, dst, dmp);
			if (((dmp->fw_hdr.dmp_size + 4) <=
			      DRV_DUMP_CRASH_DMP_BUF_SIZE_E3B0)) {
				*dst++ = BNX2X_FWDMP_MARKER_END;
				dmp->fw_hdr.dmp_size += 4;
			}
write_file:
			status = vmklnx_dump_range(bnx2x_fwdmp_dh,
					bnx2x_fwdmp_va, dmp->fw_hdr.dmp_size);
			if (status != VMK_OK) {
				BNX2X_ERR("failed to dump firmware/chip "
					  "data %x %d!\n", status, idx);
				break;
			}
			/* Re-enable parity attentions */
			bnx2x_clear_blocks_parity(bp);
			bnx2x_enable_blocks_parity(bp);
			if (!(dmp->fw_hdr.flags & FWDMP_FLAGS_LIVE_DUMP))
				disable_pause(bp);
		}
	}
	/* restore firmware dump on disabled adapters */
	for (idx = 0; idx < BNX2X_MAX_NIC; idx++) {
		if (bnx2x_fwdmp_bp[idx].bp && bnx2x_fwdmp_bp[idx].disable_fwdmp)
			bnx2x_fwdmp_bp[idx].disable_fwdmp = 0;
	}
	return status;
}

/*
 * Disable firmware dump on netdump worker NIC (bp) such that, the
 * grcDump, which is very intrusive, won't interrupt netdump
 * traffic. Besides the netdump worker NIC, we also need to disable
 * grcDump on other functions that shared the same device as worker
 * NIC function.
 */
void bnx2x_disable_esx_fwdmp(struct bnx2x *bp)
{
	u32 i, j;
	for (i = 0; i < BNX2X_MAX_NIC; i++) {
		if (bnx2x_fwdmp_bp[i].bp == bp) {
			struct bnx2x *fw_bp;

			bnx2x_fwdmp_bp[i].disable_fwdmp = 1;
			netdev_info(bp->dev,
			   "Firmware dump disabled on netdump worker "
			   "(bp=%p, %d).\n",
			   bp, i);
			for (j = 0; j < BNX2X_MAX_NIC; j++) {
				fw_bp = bnx2x_fwdmp_bp[j].bp;
				/* disable fw dmp on the functions that
				   shared the same device as well */
				if (fw_bp && fw_bp != bp &&
				    fw_bp->pdev->bus == bp->pdev->bus) {
					bnx2x_fwdmp_bp[j].disable_fwdmp = 1;
					netdev_info(fw_bp->dev,
					   "Firmware dump disabled on function "
					   "sharing the same device (bp=%p, %d).\n",
					   fw_bp, j);
					fw_bp->poll_disable_fwdmp = 1;
				}
			}
			bp->poll_disable_fwdmp = 1;
			break;
		}
	}
}
#endif
/*******************/