doc: update sphinx installation instructions
[dpdk.git] / tools / setup.sh
index 9326d84..6097ab7 100755 (executable)
@@ -1,36 +1,35 @@
 #! /bin/bash
 
 #   BSD LICENSE
-# 
-#   Copyright(c) 2010-2013 Intel Corporation. All rights reserved.
+#
+#   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
 #   All rights reserved.
-# 
-#   Redistribution and use in source and binary forms, with or without 
-#   modification, are permitted provided that the following conditions 
+#
+#   Redistribution and use in source and binary forms, with or without
+#   modification, are permitted provided that the following conditions
 #   are met:
-# 
-#     * Redistributions of source code must retain the above copyright 
+#
+#     * Redistributions of source code must retain the above copyright
 #       notice, this list of conditions and the following disclaimer.
-#     * Redistributions in binary form must reproduce the above copyright 
-#       notice, this list of conditions and the following disclaimer in 
-#       the documentation and/or other materials provided with the 
+#     * Redistributions in binary form must reproduce the above copyright
+#       notice, this list of conditions and the following disclaimer in
+#       the documentation and/or other materials provided with the
 #       distribution.
-#     * Neither the name of Intel Corporation nor the names of its 
-#       contributors may be used to endorse or promote products derived 
+#     * Neither the name of Intel Corporation nor the names of its
+#       contributors may be used to endorse or promote products derived
 #       from this software without specific prior written permission.
-# 
-#   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
-#   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
-#   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
-#   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
-#   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
-#   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
-#   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
-#   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
-#   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
-#   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+#
+#   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+#   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+#   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+#   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+#   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+#   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+#   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+#   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+#   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+#   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 #   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-# 
 
 #
 # Run with "source /path/to/setup.sh"
@@ -45,6 +44,8 @@ echo "--------------------------------------------------------------------------
 echo " RTE_SDK exported as $RTE_SDK"
 echo "------------------------------------------------------------------------------"
 
+HUGEPGSZ=`cat /proc/meminfo  | grep Hugepagesize | cut -d : -f 2 | tr -d ' '`
+
 #
 # Application EAL parameters for setting memory options (amount/channels/ranks).
 #
@@ -58,6 +59,12 @@ quit()
        QUIT=$1
 }
 
+# Shortcut for quit.
+q()
+{
+       quit
+}
+
 #
 # Sets up environmental variables for ICC.
 #
@@ -105,14 +112,6 @@ setup_target()
        echo "------------------------------------------------------------------------------"
 }
 
-#
-# Uninstall all targets.
-#
-uninstall_targets()
-{
-       make uninstall
-}
-
 #
 # Creates hugepage filesystem.
 #
@@ -170,7 +169,8 @@ load_igb_uio_module()
 
        /sbin/lsmod | grep -s uio > /dev/null
        if [ $? -ne 0 ] ; then
-               if [ -f /lib/modules/$(uname -r)/kernel/drivers/uio/uio.ko ] ; then
+               modinfo uio > /dev/null
+               if [ $? -eq 0 ]; then
                        echo "Loading uio module"
                        sudo /sbin/modprobe uio
                fi
@@ -187,6 +187,54 @@ load_igb_uio_module()
        fi
 }
 
+#
+# Unloads VFIO modules.
+#
+remove_vfio_module()
+{
+       echo "Unloading any existing VFIO module"
+       /sbin/lsmod | grep -s vfio > /dev/null
+       if [ $? -eq 0 ] ; then
+               sudo /sbin/rmmod vfio-pci
+               sudo /sbin/rmmod vfio_iommu_type1
+               sudo /sbin/rmmod vfio
+       fi
+}
+
+#
+# Loads new vfio-pci (and vfio module if needed).
+#
+load_vfio_module()
+{
+       remove_vfio_module
+
+       VFIO_PATH="kernel/drivers/vfio/pci/vfio-pci.ko"
+
+       echo "Loading VFIO module"
+       /sbin/lsmod | grep -s vfio_pci > /dev/null
+       if [ $? -ne 0 ] ; then
+               if [ -f /lib/modules/$(uname -r)/$VFIO_PATH ] ; then
+                       sudo /sbin/modprobe vfio-pci
+               fi
+       fi
+
+       # make sure regular users can read /dev/vfio
+       echo "chmod /dev/vfio"
+       sudo chmod a+x /dev/vfio
+       if [ $? -ne 0 ] ; then
+               echo "FAIL"
+               quit
+       fi
+       echo "OK"
+
+       # check if /dev/vfio/vfio exists - that way we
+       # know we either loaded the module, or it was
+       # compiled into the kernel
+       if [ ! -e /dev/vfio/vfio ] ; then
+               echo "## ERROR: VFIO not found!"
+       fi
+}
+
 #
 # Unloads the rte_kni.ko module.
 #
@@ -223,6 +271,55 @@ load_kni_module()
        fi
 }
 
+#
+# Sets appropriate permissions on /dev/vfio/* files
+#
+set_vfio_permissions()
+{
+       # make sure regular users can read /dev/vfio
+       echo "chmod /dev/vfio"
+       sudo chmod a+x /dev/vfio
+       if [ $? -ne 0 ] ; then
+               echo "FAIL"
+               quit
+       fi
+       echo "OK"
+
+       # make sure regular user can access everything inside /dev/vfio
+       echo "chmod /dev/vfio/*"
+       sudo chmod 0666 /dev/vfio/*
+       if [ $? -ne 0 ] ; then
+               echo "FAIL"
+               quit
+       fi
+       echo "OK"
+
+       # since permissions are only to be set when running as
+       # regular user, we only check ulimit here
+       #
+       # warn if regular user is only allowed
+       # to memlock <64M of memory
+       MEMLOCK_AMNT=`ulimit -l`
+
+       if [ "$MEMLOCK_AMNT" != "unlimited" ] ; then
+               MEMLOCK_MB=`expr $MEMLOCK_AMNT / 1024`
+               echo ""
+               echo "Current user memlock limit: ${MEMLOCK_MB} MB"
+               echo ""
+               echo "This is the maximum amount of memory you will be"
+               echo "able to use with DPDK and VFIO if run as current user."
+               echo -n "To change this, please adjust limits.conf memlock "
+               echo "limit for current user."
+
+               if [ $MEMLOCK_AMNT -lt 65536 ] ; then
+                       echo ""
+                       echo "## WARNING: memlock limit is less than 64MB"
+                       echo -n "## DPDK with VFIO may not be able to initialize "
+                       echo "if run as current user."
+               fi
+       fi
+}
+
 #
 # Removes all reserved hugepages.
 #
@@ -230,7 +327,7 @@ clear_huge_pages()
 {
        echo > .echo_tmp
        for d in /sys/devices/system/node/node? ; do
-               echo "echo 0 > $d/hugepages/hugepages-2048kB/nr_hugepages" >> .echo_tmp
+               echo "echo 0 > $d/hugepages/hugepages-${HUGEPGSZ}/nr_hugepages" >> .echo_tmp
        done
        echo "Removing currently reserved hugepages"
        sudo sh .echo_tmp
@@ -247,13 +344,13 @@ set_non_numa_pages()
        clear_huge_pages
 
        echo ""
-       echo "  Input the number of 2MB pages"
-       echo "  Example: to have 128MB of hugepages available, enter '64' to"
-       echo "  reserve 64 * 2MB pages"
+       echo "  Input the number of ${HUGEPGSZ} hugepages"
+       echo "  Example: to have 128MB of hugepages available in a 2MB huge page system,"
+       echo "  enter '64' to reserve 64 * 2MB pages"
        echo -n "Number of pages: "
        read Pages
 
-       echo "echo $Pages > /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages" > .echo_tmp
+       echo "echo $Pages > /sys/kernel/mm/hugepages/hugepages-${HUGEPGSZ}/nr_hugepages" > .echo_tmp
 
        echo "Reserving hugepages"
        sudo sh .echo_tmp
@@ -270,8 +367,8 @@ set_numa_pages()
        clear_huge_pages
 
        echo ""
-       echo "  Input the number of 2MB pages for each node"
-       echo "  Example: to have 128MB of hugepages available per node,"
+       echo "  Input the number of ${HUGEPGSZ} hugepages for each node"
+       echo "  Example: to have 128MB of hugepages available per node in a 2MB huge page system,"
        echo "  enter '64' to reserve 64 * 2MB pages on each node"
 
        echo > .echo_tmp
@@ -279,7 +376,7 @@ set_numa_pages()
                node=$(basename $d)
                echo -n "Number of pages for $node: "
                read Pages
-               echo "echo $Pages > $d/hugepages/hugepages-2048kB/nr_hugepages" >> .echo_tmp
+               echo "echo $Pages > $d/hugepages/hugepages-${HUGEPGSZ}/nr_hugepages" >> .echo_tmp
        done
        echo "Reserving hugepages"
        sudo sh .echo_tmp
@@ -325,11 +422,67 @@ grep_meminfo()
 }
 
 #
-# List all hugepage file references
+# Calls dpdk_nic_bind.py --status to show the NIC and what they
+# are all bound to, in terms of drivers.
+#
+show_nics()
+{
+       if [ -d /sys/module/vfio_pci -o -d /sys/module/igb_uio ]; then
+               ${RTE_SDK}/tools/dpdk_nic_bind.py --status
+       else
+               echo "# Please load the 'igb_uio' or 'vfio-pci' kernel module before "
+               echo "# querying or adjusting NIC device bindings"
+       fi
+}
+
+#
+# Uses dpdk_nic_bind.py to move devices to work with vfio-pci
+#
+bind_nics_to_vfio()
+{
+       if [ -d /sys/module/vfio_pci ]; then
+               ${RTE_SDK}/tools/dpdk_nic_bind.py --status
+               echo ""
+               echo -n "Enter PCI address of device to bind to VFIO driver: "
+               read PCI_PATH
+               sudo ${RTE_SDK}/tools/dpdk_nic_bind.py -b vfio-pci $PCI_PATH &&
+                       echo "OK"
+       else
+               echo "# Please load the 'vfio-pci' kernel module before querying or "
+               echo "# adjusting NIC device bindings"
+       fi
+}
+
+#
+# Uses dpdk_nic_bind.py to move devices to work with igb_uio
 #
-ls_mnt_huge()
+bind_nics_to_igb_uio()
 {
-       ls -lh /mnt/huge
+       if [ -d /sys/module/igb_uio ]; then
+               ${RTE_SDK}/tools/dpdk_nic_bind.py --status
+               echo ""
+               echo -n "Enter PCI address of device to bind to IGB UIO driver: "
+               read PCI_PATH
+               sudo ${RTE_SDK}/tools/dpdk_nic_bind.py -b igb_uio $PCI_PATH && echo "OK"
+       else
+               echo "# Please load the 'igb_uio' kernel module before querying or "
+               echo "# adjusting NIC device bindings"
+       fi
+}
+
+#
+# Uses dpdk_nic_bind.py to move devices to work with kernel drivers again
+#
+unbind_nics()
+{
+       ${RTE_SDK}/tools/dpdk_nic_bind.py --status
+       echo ""
+       echo -n "Enter PCI address of device to unbind: "
+       read PCI_PATH
+       echo ""
+       echo -n "Enter name of kernel driver to bind the device to: "
+       read DRV
+       sudo ${RTE_SDK}/tools/dpdk_nic_bind.py -b $DRV $PCI_PATH && echo "OK"
 }
 
 #
@@ -360,14 +513,29 @@ step2_func()
        TEXT[1]="Insert IGB UIO module"
        FUNC[1]="load_igb_uio_module"
 
-       TEXT[2]="Insert KNI module"
-       FUNC[2]="load_kni_module"
+       TEXT[2]="Insert VFIO module"
+       FUNC[2]="load_vfio_module"
+
+       TEXT[3]="Insert KNI module"
+       FUNC[3]="load_kni_module"
+
+       TEXT[4]="Setup hugepage mappings for non-NUMA systems"
+       FUNC[4]="set_non_numa_pages"
+
+       TEXT[5]="Setup hugepage mappings for NUMA systems"
+       FUNC[5]="set_numa_pages"
+
+       TEXT[6]="Display current Ethernet device settings"
+       FUNC[6]="show_nics"
+
+       TEXT[7]="Bind Ethernet device to IGB UIO module"
+       FUNC[7]="bind_nics_to_igb_uio"
 
-       TEXT[3]="Setup hugepage mappings for non-NUMA systems"
-       FUNC[3]="set_non_numa_pages"
+       TEXT[8]="Bind Ethernet device to VFIO module"
+       FUNC[8]="bind_nics_to_vfio"
 
-       TEXT[4]="Setup hugepage mappings for NUMA systems"
-       FUNC[4]="set_numa_pages"
+       TEXT[9]="Setup VFIO permissions"
+       FUNC[9]="set_vfio_permissions"
 }
 
 #
@@ -394,8 +562,6 @@ step4_func()
        TEXT[1]="List hugepage info from /proc/meminfo"
        FUNC[1]="grep_meminfo"
 
-       TEXT[2]="List hugepage files in /mnt/huge"
-       FUNC[2]="ls_mnt_huge"
 }
 
 #
@@ -405,17 +571,20 @@ step5_func()
 {
        TITLE="Uninstall and system cleanup"
 
-       TEXT[1]="Uninstall all targets"
-       FUNC[1]="uninstall_targets"
+       TEXT[1]="Unbind NICs from IGB UIO or VFIO driver"
+       FUNC[1]="unbind_nics"
 
        TEXT[2]="Remove IGB UIO module"
        FUNC[2]="remove_igb_uio_module"
 
-       TEXT[3]="Remove KNI module"
-       FUNC[3]="remove_kni_module"
+       TEXT[3]="Remove VFIO module"
+       FUNC[3]="remove_vfio_module"
 
-       TEXT[4]="Remove hugepage mappings"
-       FUNC[4]="clear_huge_pages"
+       TEXT[4]="Remove KNI module"
+       FUNC[4]="remove_kni_module"
+
+       TEXT[5]="Remove hugepage mappings"
+       FUNC[5]="clear_huge_pages"
 }
 
 STEPS[1]="step1_func"
@@ -456,6 +625,10 @@ while [ "$QUIT" == "0" ]; do
        read our_entry
        echo ""
        ${OPTIONS[our_entry]} ${our_entry}
-       echo
-       echo -n "Press enter to continue ..."; read
+
+       if [ "$QUIT" == "0" ] ; then
+               echo
+               echo -n "Press enter to continue ..."; read
+       fi
+
 done