Files
@ d0a14f973771
Branch filter:
Location: vmkdrivers/vmkdrivers/src_9/drivers/net/bnx2x/bnx2x_esx.c
d0a14f973771
56.1 KiB
text/x-csrc
ESXi-5.0-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 | /* bnx2x_esx.c: Broadcom Everest network driver.
*
* Copyright 2007-2011 Broadcom Corporation
*
* Portions Copyright (c) VMware, Inc. 2008-2011, All Rights Reserved.
* Copyright (c) 2007-2011 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_common.h"
#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"
"bnx2x_ioctl_req\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
/* handles an sp event specific to a netq. The routine is called for all sp
* events, return 0 if it handled the event, non-zero otherwise
*/
int bnx2x_netq_sp_event(struct bnx2x *bp, struct bnx2x_fastpath *fp,
int cid, int command)
{
/* The only 'empty ramrod' is sent when clearing the netq rx filter */
if (command == RAMROD_CMD_ID_ETH_EMPTY) {
DP(BNX2X_MSG_NETQ, "got Empty rmarod. CID %d\n", cid);
fp->netq_filter_event = 0;
return 0;
}
return 1;
}
/* 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)));
}
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->disable_tpa = 1;
}
break;
default:
/* Do not reserve for LRO */
DP(BNX2X_MSG_NETQ, "Queue[%d] is non-LRO\n", i);
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)
{
/* Only support 1 Mac filter per queue */
args->count = 1;
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_nondefault_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;
}
#define BNX2X_NETQ_SUPPORTED_FEATURES \
(VMKNETDDI_QUEUEOPS_QUEUE_FEAT_PAIR | \
((bp->flags & TPA_ENABLE_FLAG) ? VMKNETDDI_QUEUEOPS_QUEUE_FEAT_LRO : 0))
/*
* 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;
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"
);
return VMKNETDDI_QUEUEOPS_OK;
}
#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);
if (!bnx2x_netq_valid_qid(bp, index))
return VMKNETDDI_QUEUEOPS_ERR;
struct bnx2x_fastpath *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;
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;
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);
if (!bnx2x_netq_valid_qid(bp, index)) {
DP(BNX2X_MSG_NETQ, "NetQ RX Queue %d is invalid\n", index);
return VMKNETDDI_QUEUEOPS_ERR;
}
struct bnx2x_fastpath *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_CONTEXT_USE);
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)
{
struct bnx2x_list_elem *first = NULL;
unsigned long ramrod_flags = 0;
DECLARE_MAC_BUF(mac);
/* Only support one Mac filter per queue */
if (fid != 0) {
DP(BNX2X_MSG_NETQ, "Invalid filter id %d\n", fid);
return VMKNETDDI_QUEUEOPS_ERR;
}
/* clear MAC */
first = list_first_entry(&fp->mac_obj.head,
struct bnx2x_list_elem, link);
DP(BNX2X_MSG_NETQ, "remove rx filter %s from queue[%d]\n",
print_mac(mac, first->data.mac.mac), fp->index);
bnx2x_netq_set_mac_one(first->data.mac.mac, bp, fp, 0);
/* set to drop-all*/
set_bit(RAMROD_RX, &ramrod_flags);
set_bit(RAMROD_TX, &ramrod_flags);
set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
bnx2x_set_cl_rx_mode(bp, fp->cl_id, 0, 0, ramrod_flags);
/* send empty-ramrod to flush packets lurking in the HW */
fp->netq_filter_event = 1;
bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_EMPTY, fp->cid, 0, fp->cl_id, 0);
/* Wait for completion */
if(bnx2x_wait_ramrod(bp, 0, fp->index, &fp->netq_filter_event, 0)) {
/* timeout */
BNX2X_ERR("Remove RX filter for netq %x failed - "
"HW flush timed out\n", fp->index);
return VMKNETDDI_QUEUEOPS_ERR;
}
fp->netq_flags &= ~BNX2X_NETQ_RX_QUEUE_ACTIVE;
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 remove RX filter: %x\n", qid);
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;
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_ACTIVE(fp) ||
!BNX2X_IS_NETQ_RX_QUEUE_ALLOCATED(fp))
return VMKNETDDI_QUEUEOPS_ERR;
macaddr = (void *)vmknetddi_queueops_get_filter_macaddr(&args->filter);
vlan_id = vmknetddi_queueops_get_filter_vlanid(&args->filter);
/* 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);
bnx2x_set_cl_rx_mode(bp, fp->cl_id, 0, accept_flags, ramrod_flags);
/* add MAC */
bnx2x_netq_set_mac_one(macaddr, bp, fp, 1);
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;
DP(BNX2X_MSG_NETQ, "NetQ set RX filter: %d [%s %d]\n",
qid, print_mac(mac, macaddr), vlan_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))
bnx2x_netq_remove_rx_filter(bp, fp, 0);
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;
#endif
default:
printk("Unhandled NETQUEUE OP %d\n", op);
rc = VMKNETDDI_QUEUEOPS_ERR;
}
spin_unlock(&bp->netq_lock);
return rc;
}
#endif /* BNX2X_NETQ */
/*
* NPA - Pass-Through
*/
#ifdef BCM_IOV
#include <linux/pci.h>
#include <linux/types.h>
#include <linux/netdevice.h>
#include "bnx2x_vf.h"
#define BNX2X_UNREFERENCED(x) (void)(x)
#define VMK_RET(rc) (((rc) == VF_API_SUCCESS) ? VMK_OK : VMK_FAILURE)
#define ENABLE_STR(en) ((en) ? "enable" : "disable")
/* 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_PCIReadConfigSpace(dev, VMK_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_PCIReadConfigSpace(dev, VMK_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_PCIReadConfigSpace(dev, VMK_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("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) != VF_API_SUCCESS) {
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_vf_rxq(vf, i) {
bnx2x_vf_rxq(vf, i, sb_idx) = i;
if (i < vf->txq_count)
bnx2x_vf_txq(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_QUEUE_FLG_VLAN, &vf->queue_flags);
if ((props->features | props->optFeatures) & VMK_NETVF_F_LRO)
set_bit(BNX2X_QUEUE_FLG_TPA, &vf->queue_flags);
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);
u64 *sb_map;
vf_api_t rc;
int i;
DP(BNX2X_MSG_IOV, "VF index %d\n", vmkVf);
/* sanity */
if (!vf || vf->state != VF_ACQUIRED)
return VMK_BAD_PARAM;
/* initialize function */
/* 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) * vf->sb_count, 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 != VF_API_SUCCESS)
goto vf_init_error;
/* queues */
for_each_vf_rxq(vf, i) {
struct bnx2x_vfq *rxq = VF_RXQ(vf, i);
struct bnx2x_client_init_params initp = {{0}};
struct bnx2xpi_txrx_params txrxp = {{0}};
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,
rxq->index,
txrxp.rx.base,
txrxp.rx.nr_desc,
txrxp.rx.byte_len);
/* first txq - rx queue count >= tx queue count */
if (i < vf->txq_count) {
struct bnx2x_vfq *txq = VF_TXQ(vf, i);
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,
txq->index,
txrxp.tx.base,
txrxp.tx.nr_desc,
txrxp.tx.byte_len);
/* prepare txq init parameters */
initp.txq_params.flags = 0;
initp.txq_params.dscr_map = bnx2xpi_tx_decr_offset(&txrxp);
initp.txq_params.sb_cq_index = PLUGIN_SB_ETH_TX_CQ_INDEX;
initp.txq_params.hc_rate = 20000; /* intr p/s default */
initp.txq_params.traffic_type = LLFC_TRAFFIC_TYPE_NW;
bnx2x_vf_txq_setup(bp, vf, txq, &initp);
}
/* prepare rxq init parameters */
initp.rxq_params.flags = vf->queue_flags;
set_bit(BNX2X_QUEUE_FLG_STATS, &initp.rxq_params.flags);
initp.rxq_params.dscr_map = bnx2xpi_rx_decr_offset(&txrxp);
initp.rxq_params.sge_map = bnx2xpi_sge_offset(&txrxp);
initp.rxq_params.rcq_map = bnx2xpi_rcq_offset(&txrxp);
initp.rxq_params.rcq_np_map = bnx2xpi_rcq_np_offset(&txrxp);
initp.rxq_params.mtu = vf->mtu;
initp.rxq_params.buf_sz = SHELL_SMALL_RECV_BUFFER_SIZE -
PLUGIN_RX_ALIGN - BNX2X_FW_IP_HDR_ALIGN_PAD;
initp.rxq_params.cache_line_log = PLUGIN_RX_ALIGN_SHIFT;
initp.rxq_params.sb_cq_index = PLUGIN_SB_ETH_RX_CQ_INDEX;
initp.rxq_params.stat_id = vfq_cl_id(vf, rxq);
initp.rxq_params.hc_rate = 40000; /* intr p/s default */
if (test_bit(BNX2X_QUEUE_FLG_TPA, &vf->queue_flags)) {
initp.rxq_params.tpa_agg_sz = min_t(u32, PLUGIN_MAX_SGES * SHELL_LARGE_RECV_BUFFER_SIZE, 0xffff);
initp.rxq_params.max_sges_pkt = DIV_ROUND_UP(vf->mtu, SHELL_LARGE_RECV_BUFFER_SIZE);
initp.rxq_params.sge_buf_sz = min_t(u32, SHELL_LARGE_RECV_BUFFER_SIZE, 0xffff);
}
DP(BNX2X_MSG_IOV, "VF[%d:%d] offsets - tx 0x%llx, rx 0x%llx, "
"rcq 0x%llx, rcq-np 0x%llx, sge 0x%llx\n",
vf->abs_vfid,
rxq->index,
initp.txq_params.dscr_map,
initp.rxq_params.dscr_map,
initp.rxq_params.rcq_map,
initp.rxq_params.rcq_np_map,
initp.rxq_params.sge_map);
DP(BNX2X_MSG_IOV, "VF[%d:%d] rx flags 0x%lx, tx flags 0x%lx\n",
vf->abs_vfid, rxq->index,
initp.rxq_params.flags, initp.txq_params.flags);
if (bnx2x_vf_rxq_setup(bp, vf, rxq, &initp, 0))
goto vf_init_error;
storm_memset_rcq_np(bp, initp.rxq_params.rcq_np_map,
vfq_cl_id(vf, rxq));
/* add vlan 0 and mark as 'untagged' */
if (VF_IS_LEADING_RXQ(rxq)) {
unsigned long ramrod_flags = 0;
set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
bnx2x_vf_set_vlan(bp, rxq, 0, true, ramrod_flags);
}
}
return VMK_OK;
vf_init_error:
/* release the VF */
bnx2x_vf_release(bp, vf);
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);
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_vf_rxq(vf, i) {
struct bnx2x_vfq *rxq = VF_RXQ(vf, i);
plugin_data->sb_info[i].sb_qid = vfq_qzone_id(vf, rxq);
plugin_data->sb_info[i].hw_sb_id = vfq_igu_sb_id(vf ,rxq);
plugin_data->hw_qid[i] = vfq_qzone_id(vf, rxq);
}
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_QUEUE_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);
DP(BNX2X_MSG_IOV, "Invoked\n");
/* sanity */
if (!vf)
return VMK_BAD_PARAM;
/* quiesxce only if vf is enabled otherwise exit gracefully */
if (vf->state != VF_ENABLED)
return VMK_OK;
return (VMK_RET(bnx2x_vf_trigger(bp, vf, 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);
DP(BNX2X_MSG_IOV, "Invoked\n");
/* sanity */
if (!vf || vf->state != VF_ENABLED)
return VMK_BAD_PARAM;
return (VMK_RET(bnx2x_vf_trigger(bp, vf, 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_vfq *rxq = NULL;
unsigned long ramrod_flags = 0;
vf_api_t 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;
rxq = VF_LEADING_RXQ(vf);
set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
rc = bnx2x_vf_set_mac(bp, rxq, mac, 1, ramrod_flags);
if (rc) {
BNX2X_ERR("Failed to add mac-vlan rule rc=%d\n", rc);
return VMK_FAILURE;
}
return VMK_OK;
}
// ---------------------------------------------------------------------------
//
// 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);
vf_api_t rc;
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;
rc = bnx2x_vf_set_mcasts(bp, vf ,(bnx2x_mac_addr_t *)mac, nmac, false);
return VMK_RET(rc);
}
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);
struct bnx2x_vfq *rxq = NULL;
vf_api_t rc = VF_API_SUCCESS;
unsigned long accept_flags = 0;
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;
rxq = VF_LEADING_RXQ(vf);
/* 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);
DP(BNX2X_MSG_IOV, "RX-MASK=0x%lx\n", accept_flags);
rc = bnx2x_vf_set_rxq_mode(bp, vf, rxq, accept_flags);
return VMK_RET(rc);
}
// ---------------------------------------------------------------------------
//
// VLAN control
//
static int
bnx2x_pt_vf_add_vlan_range(struct net_device *netdev, vmk_VFID vmkVf, vmk_VlanID first,
vmk_VlanID last)
{
vmk_VlanID vlan_id;
int vlan_cnt;
struct bnx2x *bp = netdev_priv(netdev);
struct bnx2x_virtf *vf = vf_by_vmkVFID(bp, vmkVf);
struct bnx2x_vfq *rxq = NULL;
unsigned long ramrod_flags = 0;
vf_api_t rc = VF_API_SUCCESS;
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;
rxq = VF_LEADING_RXQ(vf);
/* set common ramrod flags used for all add/del ops below */
set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
/* count how many vlans need to be added */
for (vlan_id = first, vlan_cnt = 0; vlan_id <= last; vlan_id++) {
/* ignore vlan 0*/
if (!vlan_id)
continue;
if (!bnx2x_vf_check_vlan_op(bp, rxq, vlan_id, true))
continue;
vlan_cnt++;
}
if ((atomic_read(&rxq->vlan_count) + vlan_cnt) > vf->vlan_rules_count) {
BNX2X_ERR("Add VLAN range: invalid range %d-%d count %d\n",
first, last, vlan_cnt);
return VMK_BAD_PARAM;
}
/* add the range */
for (vlan_id = first, vlan_cnt = 0; vlan_id <= last; vlan_id++) {
/* ignore vlan 0*/
if (!vlan_id)
continue;
if (!bnx2x_vf_check_vlan_op(bp, rxq, vlan_id, true))
continue;
rc = bnx2x_vf_set_vlan(bp, rxq, vlan_id, true, ramrod_flags);
if (rc) {
BNX2X_ERR("Add VLAN range: failed to delete "
"vlan %d\n", vlan_id);
break;
}
vlan_cnt++;
}
if (!rc && !atomic_read(&rxq->vlan_count) && vlan_cnt) {
/* delete vlan 0*/
rc = bnx2x_vf_set_vlan(bp, rxq, 0, false, ramrod_flags);
}
atomic_add(vlan_cnt, &rxq->vlan_count);
return VMK_RET(rc);
}
static int
bnx2x_pt_vf_del_vlan_range(struct net_device *netdev, vmk_VFID vmkVf,
vmk_VlanID first, vmk_VlanID last)
{
vmk_VlanID vlan_id;
int vlan_cnt;
struct bnx2x *bp = netdev_priv(netdev);
struct bnx2x_virtf *vf = vf_by_vmkVFID(bp, vmkVf);
struct bnx2x_vfq *rxq = NULL;
unsigned long ramrod_flags = 0;
vf_api_t rc = VF_API_SUCCESS;
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;
rxq = VF_LEADING_RXQ(vf);
/* set common ramrod flags used for all add/del ops below */
set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
/* check that the range is valid and caclculate the range size */
for (vlan_id = first, vlan_cnt = 0; vlan_id <= last; vlan_id++) {
/* ignore vlan 0*/
if (!vlan_id)
continue;
if (!bnx2x_vf_check_vlan_op(bp, rxq, vlan_id, false))
break;
vlan_cnt++;
}
if (vlan_id <= last) {
BNX2X_ERR("Delete VLAN range: invalid range %d-%d\n",
first, last);
return VMK_BAD_PARAM;
}
if (!vlan_cnt)
/* nothing to do */
return VMK_OK;
if (vlan_cnt == atomic_read(&rxq->vlan_count))
/* add vlan 0 before deleting the range */
rc = bnx2x_vf_set_vlan(bp, rxq, 0, true, ramrod_flags);
if (rc) {
BNX2X_ERR("Delete VLAN range: failed to add vlan 0\n");
return VMK_FAILURE;
}
/* delete the range */
for (vlan_id = first, vlan_cnt = 0; vlan_id <= last; vlan_id++) {
/* ignore vlan 0*/
if (!vlan_id)
continue;
rc = bnx2x_vf_set_vlan(bp, rxq, vlan_id, false, ramrod_flags);
if (rc) {
BNX2X_ERR("Delete VLAN range: failed to delete "
"vlan %d\n", vlan_id);
break;
}
vlan_cnt++;
}
atomic_sub(vlan_cnt, &rxq->vlan_count);
return VMK_RET(rc);
}
static int
bnx2x_default_vlan_ramrod(struct bnx2x *bp, struct bnx2x_virtf *vf, bool enable,
u16 vid, u8 prio)
{
struct client_update_ramrod_data *client_update;
int i;
for_each_vf_rxq(vf, i) {
struct bnx2x_vfq *rxq = VF_RXQ(vf, i);
/* turn anti-spoffing on or off on each tx queue */
if (i >= vf->txq_count)
break;
client_update = BP_VF_SP(bp, vf, client_update);
memset(client_update, 0, sizeof(*client_update));
client_update->client_id = vfq_cl_id(vf, rxq);
client_update->default_vlan = cpu_to_le16(vid | (prio << 12));
client_update->default_vlan_enable_flg = enable ? 1 : 0;
client_update->anti_spoofing_change_flg = 1;
client_update->inner_vlan_removal_change_flg = 1;
client_update->inner_vlan_removal_enable_flg = enable ? 1 : 0;
if (bnx2x_vf_queue_update_ramrod(bp, rxq,
BP_VF_SP_MAP(bp, vf, client_update), true)) /* block */
return VMK_FAILURE;
}
return VMK_OK;
}
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);
struct bnx2x_vfq *rxq = NULL;
unsigned long ramrod_flags = 0;
vf_api_t rc = VF_API_SUCCESS;
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;
rxq = VF_LEADING_RXQ(vf);
/* set common ramrod flags used for all add/del ops below */
set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
if (!enable) {
/* disable */
if (!vf->def_vlan_enabled)
/* nothing to do */
return VMK_OK;
/* turn off default vlan */
bnx2x_default_vlan_ramrod(bp, vf ,false, vid, prio);
/* reset vlan classification - add vlan 0 and remove the
* default vlan (remove all vlans except 0)
*/
rc = bnx2x_vf_set_vlan(bp, rxq, 0, true, ramrod_flags);
if (!rc)
rc = bnx2x_vf_clear_vlans(bp, rxq, true, 0,
ramrod_flags);
vf->def_vlan_enabled = false;
}
else {
/* enable */
if (vf->def_vlan_enabled)
/* nothing to do */
return VMK_OK;
/* set vlan classifiaction - add default valn and
* remove all the rest
*/
rc = bnx2x_vf_set_vlan(bp, rxq, vid, true, ramrod_flags);
if (!rc)
rc = bnx2x_vf_clear_vlans(bp, rxq, true, vid,
ramrod_flags);
/* turn on default vlan */
bnx2x_default_vlan_ramrod(bp, vf ,true, vid, prio);
vf->def_vlan_enabled = true;
}
return VMK_RET(rc);
}
// ---------------------------------------------------------------------------
//
// 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 client_update_ramrod_data *client_update;
int i;
DP(BNX2X_MSG_IOV, "VF index %d, %s\n", vmkVf, ENABLE_STR(enable));
/* sanity */
if (!vf || vf->state != VF_ENABLED)
return VMK_BAD_PARAM;
for_each_vf_rxq(vf, i) {
struct bnx2x_vfq *rxq = VF_RXQ(vf, i);
/* turn anti-spoffing on or off on each tx queue */
if (i >= vf->txq_count)
break;
client_update = BP_VF_SP(bp, vf, client_update);
memset(client_update, 0, sizeof(*client_update));
client_update->client_id = vfq_cl_id(vf, rxq);
client_update->anti_spoofing_enable_flg = enable ? 1 : 0;
client_update->anti_spoofing_change_flg = 1;
if (bnx2x_vf_queue_update_ramrod(bp, rxq,
BP_VF_SP_MAP(bp, vf, client_update), true)) /* block */
return VMK_FAILURE;
}
return VMK_OK;
}
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 (vf->rxq_count < numRxQueues || vf->txq_count < 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 int
bnx2x_pt_pf_add_mac_filter(struct net_device *netdev, vmk_EthAddress mac)
{
struct bnx2x *bp = netdev_priv(netdev);
DECLARE_MAC_BUF(mac_buf);
DP(BNX2X_MSG_IOV, "%s\n", print_mac(mac_buf, mac));
bnx2x_iov_set_tx_mac(bp, mac, 1);
return VMK_OK;
}
static int
bnx2x_pt_pf_del_mac_filter(struct net_device *netdev, vmk_EthAddress mac)
{
struct bnx2x *bp = netdev_priv(netdev);
DECLARE_MAC_BUF(mac_buf);
DP(BNX2X_MSG_IOV, "%s\n", print_mac(mac_buf, mac));
bnx2x_iov_set_tx_mac(bp, mac, 0);
return VMK_OK;
}
static int
bnx2x_pt_pf_mirror_all(struct net_device *netdev, uint8_t enable)
{
struct bnx2x *bp = netdev_priv(netdev);
unsigned long accept_flags = 0, 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;
set_bit(BNX2X_ACCEPT_ALL_UNICAST, &accept_flags);
set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
set_bit(RAMROD_RX, &ramrod_flags);
set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
bnx2x_set_cl_rx_mode(bp, bp->fp->cl_id, 0, 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 */
|