Front Haul Interface Library first seed code contribution
[o-du/phy.git] / fhi_lib / app / dpdk.sh
1 #! /bin/bash
2
3 #/******************************************************************************
4 #*
5 #*   Copyright (c) 2019 Intel.
6 #*
7 #*   Licensed under the Apache License, Version 2.0 (the "License");
8 #*   you may not use this file except in compliance with the License.
9 #*   You may obtain a copy of the License at
10 #*
11 #*       http://www.apache.org/licenses/LICENSE-2.0
12 #*
13 #*   Unless required by applicable law or agreed to in writing, software
14 #*   distributed under the License is distributed on an "AS IS" BASIS,
15 #*   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 #*   See the License for the specific language governing permissions and
17 #*   limitations under the License.
18 #*
19 #*******************************************************************************/
20
21 export RTE_SDK=/home/turner/dpdk
22 export RTE_TARGET=x86_64-native-linuxapp-icc
23
24 #
25 # Unloads igb_uio.ko.
26 #
27 remove_igb_uio_module()
28 {
29     echo "Unloading any existing DPDK UIO module"
30     /sbin/lsmod | grep -s igb_uio > /dev/null
31     if [ $? -eq 0 ] ; then
32         sudo /sbin/rmmod igb_uio
33     fi
34 }
35
36 #
37 # Loads new igb_uio.ko (and uio module if needed).
38 #
39 load_igb_uio_module()
40 {
41     if [ ! -f $RTE_SDK/$RTE_TARGET/kmod/igb_uio.ko ];then
42         echo "## ERROR: Target does not have the DPDK UIO Kernel Module."
43         echo "       To fix, please try to rebuild target."
44         return
45     fi
46
47     remove_igb_uio_module
48
49     /sbin/lsmod | grep -s uio > /dev/null
50     if [ $? -ne 0 ] ; then
51         if [ -f /lib/modules/$(uname -r)/kernel/drivers/uio/uio.ko ] ; then
52             echo "Loading uio module"
53             sudo /sbin/modprobe uio
54         fi
55     fi
56
57     # UIO may be compiled into kernel, so it may not be an error if it can't
58     # be loaded.
59
60     echo "Loading DPDK UIO module"
61     sudo /sbin/insmod $RTE_SDK/$RTE_TARGET/kmod/igb_uio.ko
62     if [ $? -ne 0 ] ; then
63         echo "## ERROR: Could not load kmod/igb_uio.ko."
64         quit
65     fi
66 }
67
68 load_igb_uio_module
69
70 CPU_FEATURES_DETECT=`cat /proc/cpuinfo |grep hypervisor | wc -l`
71
72 if [ "$CPU_FEATURES_DETECT" -eq "0" ]
73 then
74 VM_DETECT='HOST'
75 echo ${VM_DETECT}
76 else
77 VM_DETECT='VM'
78 echo ${VM_DETECT}
79 fi
80
81 $RTE_SDK/usertools/dpdk-devbind.py --status
82 if [ ${VM_DETECT} == 'HOST' ]; then
83     #HOST
84     $RTE_SDK/usertools/dpdk-devbind.py --bind=igb_uio 0000:d8:02.0
85     $RTE_SDK/usertools/dpdk-devbind.py --bind=igb_uio 0000:d8:02.1
86     $RTE_SDK/usertools/dpdk-devbind.py --bind=igb_uio 0000:07:02.0
87     $RTE_SDK/usertools/dpdk-devbind.py --bind=igb_uio 0000:07:02.1
88 else
89     #VM
90     $RTE_SDK/usertools/dpdk-devbind.py --bind=igb_uio 0000:00:04.0
91     $RTE_SDK/usertools/dpdk-devbind.py --bind=igb_uio 0000:00:05.0
92     $RTE_SDK/usertools/dpdk-devbind.py --bind=igb_uio 0000:00:06.0
93     $RTE_SDK/usertools/dpdk-devbind.py --bind=igb_uio 0000:00:07.0
94 fi
95
96 $RTE_SDK/usertools/dpdk-devbind.py --status
97