doc: whitespace changes in licenses
[dpdk.git] / tools / setup.sh
index 058bc86..cddcbdc 100755 (executable)
@@ -2,35 +2,34 @@
 
 #   BSD LICENSE
 # 
-#   Copyright(c) 2010-2012 Intel Corporation. All rights reserved.
+#   Copyright(c) 2010-2013 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"
@@ -59,7 +58,7 @@ quit()
 }
 
 #
-# Sets up envronment variables for ICC.
+# Sets up environmental variables for ICC.
 #
 setup_icc()
 {
@@ -187,6 +186,42 @@ load_igb_uio_module()
        fi
 }
 
+#
+# Unloads the rte_kni.ko module.
+#
+remove_kni_module()
+{
+       echo "Unloading any existing DPDK KNI module"
+       /sbin/lsmod | grep -s rte_kni > /dev/null
+       if [ $? -eq 0 ] ; then
+               sudo /sbin/rmmod rte_kni
+       fi
+}
+
+#
+# Loads the rte_kni.ko module.
+#
+load_kni_module()
+{
+    # Check that the KNI module is already built.
+       if [ ! -f $RTE_SDK/$RTE_TARGET/kmod/rte_kni.ko ];then
+               echo "## ERROR: Target does not have the DPDK KNI Module."
+               echo "       To fix, please try to rebuild target."
+               return
+       fi
+
+    # Unload existing version if present.
+       remove_kni_module
+
+    # Now try load the KNI module.
+       echo "Loading DPDK KNI module"
+       sudo /sbin/insmod $RTE_SDK/$RTE_TARGET/kmod/rte_kni.ko
+       if [ $? -ne 0 ] ; then
+               echo "## ERROR: Could not load kmod/rte_kni.ko."
+               quit
+       fi
+}
+
 #
 # Removes all reserved hugepages.
 #
@@ -289,11 +324,49 @@ grep_meminfo()
 }
 
 #
-# List all hugepage file references
+# Calls pci_unbind.py --status to show the NIC and what they
+# are all bound to, in terms of drivers.
 #
-ls_mnt_huge()
+show_nics()
 {
-       ls -lh /mnt/huge
+       if  /sbin/lsmod  | grep -q igb_uio ; then 
+               ${RTE_SDK}/tools/pci_unbind.py --status
+       else 
+               echo "# Please load the 'igb_uio' kernel module before querying or "
+               echo "# adjusting NIC device bindings"
+       fi
+}
+
+#
+# Uses pci_unbind.py to move devices to work with igb_uio
+#
+bind_nics()
+{
+       if  /sbin/lsmod  | grep -q igb_uio ; then 
+               ${RTE_SDK}/tools/pci_unbind.py --status
+               echo ""
+               echo -n "Enter PCI address of device to bind to IGB UIO driver: "
+               read PCI_PATH
+               sudo ${RTE_SDK}/tools/pci_unbind.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 pci_unbind.py to move devices to work with kernel drivers again
+#
+unbind_nics()
+{
+       ${RTE_SDK}/tools/pci_unbind.py --status
+       echo ""
+       echo -n "Enter PCI address of device to bind to IGB UIO driver: "
+       read PCI_PATH
+       echo ""
+       echo -n "Enter name of kernel driver to bind the device to: "
+       read DRV
+       sudo ${RTE_SDK}/tools/pci_unbind.py -b $DRV $PCI_PATH && echo "OK"
 }
 
 #
@@ -324,11 +397,20 @@ step2_func()
        TEXT[1]="Insert IGB UIO module"
        FUNC[1]="load_igb_uio_module"
 
-       TEXT[2]="Setup hugepage mappings for non-NUMA systems"
-       FUNC[2]="set_non_numa_pages"
+       TEXT[2]="Insert KNI module"
+       FUNC[2]="load_kni_module"
 
-       TEXT[3]="Setup hugepage mappings for NUMA systems"
-       FUNC[3]="set_numa_pages"
+       TEXT[3]="Setup hugepage mappings for non-NUMA systems"
+       FUNC[3]="set_non_numa_pages"
+
+       TEXT[4]="Setup hugepage mappings for NUMA systems"
+       FUNC[4]="set_numa_pages"
+
+       TEXT[5]="Display current Ethernet device settings"
+       FUNC[5]="show_nics"
+
+       TEXT[6]="Bind Ethernet device to IGB UIO module"
+       FUNC[6]="bind_nics"
 }
 
 #
@@ -355,8 +437,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"
 }
 
 #
@@ -369,11 +449,17 @@ step5_func()
        TEXT[1]="Uninstall all targets"
        FUNC[1]="uninstall_targets"
 
-       TEXT[2]="Remove IGB UIO module"
-       FUNC[2]="remove_igb_uio_module"
+       TEXT[2]="Unbind NICs from IGB UIO driver"
+       FUNC[2]="unbind_nics"
+
+       TEXT[3]="Remove IGB UIO module"
+       FUNC[3]="remove_igb_uio_module"
+
+       TEXT[4]="Remove KNI module"
+       FUNC[4]="remove_kni_module"
 
-       TEXT[3]="Remove hugepage mappings"
-       FUNC[3]="clear_huge_pages"
+       TEXT[5]="Remove hugepage mappings"
+       FUNC[5]="clear_huge_pages"
 }
 
 STEPS[1]="step1_func"