5 rootdir
=$
(readlink
-f $
(dirname $0))/..
7 function linux_iter_pci
{
8 # Argument is the class code
9 # TODO: More specifically match against only class codes in the grep
11 lspci
-mm -n |
grep $1 |
tr -d '"' |
awk -F " " '{print "0000:"$1}'
14 function linux_bind_driver
() {
17 old_driver_name
="no driver"
18 ven_dev_id
=$
(lspci
-n -s $bdf | cut
-d' ' -f3 |
sed 's/:/ /')
20 if [ -e "/sys/bus/pci/devices/$bdf/driver" ]; then
21 old_driver_name
=$
(basename $
(readlink
/sys
/bus
/pci
/devices
/$bdf/driver
))
23 if [ "$driver_name" = "$old_driver_name" ]; then
27 echo "$ven_dev_id" > "/sys/bus/pci/devices/$bdf/driver/remove_id" 2> /dev
/null || true
28 echo "$bdf" > "/sys/bus/pci/devices/$bdf/driver/unbind"
31 echo "$bdf ($ven_dev_id): $old_driver_name -> $driver_name"
33 echo "$ven_dev_id" > "/sys/bus/pci/drivers/$driver_name/new_id" 2> /dev
/null || true
34 echo "$bdf" > "/sys/bus/pci/drivers/$driver_name/bind" 2> /dev
/null || true
36 iommu_group
=$
(basename $
(readlink
-f /sys
/bus
/pci
/devices
/$bdf/iommu_group
))
37 if [ -e "/dev/vfio/$iommu_group" ]; then
38 if [ "$username" != "" ]; then
39 chown
"$username" "/dev/vfio/$iommu_group"
44 function linux_hugetlbfs_mount
() {
45 mount |
grep '^hugetlbfs ' |
awk '{ print $3 }'
48 function configure_linux
{
50 if [ -z "$(ls /sys/kernel/iommu_groups)" ]; then
52 driver_name
=uio_pci_generic
56 modprobe
$driver_name || true
57 for bdf
in $
(linux_iter_pci
0108); do
58 linux_bind_driver
"$bdf" "$driver_name"
64 #collect all the device_id info of ioat devices.
65 grep "PCI_DEVICE_ID_INTEL_IOAT" $rootdir/include
/spdk
/pci_ids.h \
66 |
awk -F"x" '{print $2}' > $TMP
68 for dev_id
in `cat $TMP`; do
69 # Abuse linux_iter_pci by giving it a device ID instead of a class code
70 for bdf
in $
(linux_iter_pci
$dev_id); do
71 linux_bind_driver
"$bdf" "$driver_name"
76 echo "1" > "/sys/bus/pci/rescan"
78 hugetlbfs_mount
=$
(linux_hugetlbfs_mount
)
80 if [ -z "$hugetlbfs_mount" ]; then
81 hugetlbfs_mount
=/mnt
/huge
82 echo "Mounting hugetlbfs at $hugetlbfs_mount"
83 mkdir
-p "$hugetlbfs_mount"
84 mount
-t hugetlbfs nodev
"$hugetlbfs_mount"
86 echo "$NRHUGE" > /proc
/sys
/vm
/nr_hugepages
88 if [ "$driver_name" = "vfio-pci" ]; then
89 if [ "$username" != "" ]; then
90 chown
"$username" "$hugetlbfs_mount"
93 MEMLOCK_AMNT
=`ulimit -l`
94 if [ "$MEMLOCK_AMNT" != "unlimited" ] ; then
95 MEMLOCK_MB
=$
(( $MEMLOCK_AMNT / 1024 ))
97 echo "Current user memlock limit: ${MEMLOCK_MB} MB"
99 echo "This is the maximum amount of memory you will be"
100 echo "able to use with DPDK and VFIO if run as current user."
101 echo -n "To change this, please adjust limits.conf memlock "
102 echo "limit for current user."
104 if [ $MEMLOCK_AMNT -lt 65536 ] ; then
106 echo "## WARNING: memlock limit is less than 64MB"
107 echo -n "## DPDK with VFIO may not be able to initialize "
108 echo "if run as current user."
114 function reset_linux
{
116 modprobe nvme || true
117 for bdf
in $
(linux_iter_pci
0108); do
118 linux_bind_driver
"$bdf" nvme
124 #collect all the device_id info of ioat devices.
125 grep "PCI_DEVICE_ID_INTEL_IOAT" $rootdir/include
/spdk
/pci_ids.h \
126 |
awk -F"x" '{print $2}' > $TMP
128 modprobe ioatdma || true
129 for dev_id
in `cat $TMP`; do
130 # Abuse linux_iter_pci by giving it a device ID instead of a class code
131 for bdf
in $
(linux_iter_pci
$dev_id); do
132 linux_bind_driver
"$bdf" ioatdma
137 echo "1" > "/sys/bus/pci/rescan"
139 hugetlbfs_mount
=$
(linux_hugetlbfs_mount
)
140 rm -f "$hugetlbfs_mount"/spdk
*map_
*
143 function status_linux
{
146 echo -e "BDF\t\tNuma Node\tDriver name\t\tDevice name"
147 for bdf
in $
(linux_iter_pci
0108); do
148 driver
=`grep DRIVER /sys/bus/pci/devices/$bdf/uevent |awk -F"=" '{print $2}'`
149 node
=`cat /sys/bus/pci/devices/$bdf/numa_node`;
150 if [ "$driver" = "nvme" ]; then
151 name
="\t"`ls /sys/bus/pci/devices/$bdf/nvme`;
155 echo -e "$bdf\t$node\t\t$driver\t\t$name";
160 #collect all the device_id info of ioat devices.
161 TMP
=`grep "PCI_DEVICE_ID_INTEL_IOAT" $rootdir/include/spdk/pci_ids.h \
162 | awk -F"x" '{print $2}'`
163 echo -e "BDF\t\tNuma Node\tDriver Name"
164 for dev_id
in $TMP; do
165 # Abuse linux_iter_pci by giving it a device ID instead of a class code
166 for bdf
in $
(linux_iter_pci
$dev_id); do
167 driver
=`grep DRIVER /sys/bus/pci/devices/$bdf/uevent |awk -F"=" '{print $2}'`
168 node
=`cat /sys/bus/pci/devices/$bdf/numa_node`;
169 echo -e "$bdf\t$node\t\t$driver"
174 function configure_freebsd
{
178 GREP_STR
="class=0x010802"
181 grep "PCI_DEVICE_ID_INTEL_IOAT" $rootdir/include
/spdk
/pci_ids.h \
182 |
awk -F"x" '{print $2}' > $TMP
183 for dev_id
in `cat $TMP`; do
184 GREP_STR
="${GREP_STR}\|chip=0x${dev_id}8086"
187 AWK_PROG
="{if (count > 0) printf \",\"; printf \"%s:%s:%s\",\$2,\$3,\$4; count++}"
188 echo $AWK_PROG > $TMP
190 BDFS
=`pciconf -l | grep "${GREP_STR}" | awk -F: -f $TMP`
192 kldunload nic_uio.ko || true
193 kenv hw.nic_uio.bdfs
=$BDFS
197 kldunload contigmem.ko || true
198 kenv hw.contigmem.num_buffers
=$
((NRHUGE
* 2 / 256))
199 kenv hw.contigmem.buffer_size
=$
((256 * 1024 * 1024))
203 function reset_freebsd
{
204 kldunload contigmem.ko || true
205 kldunload nic_uio.ko || true
213 if [ "$username" = "reset" -o "$username" = "config" -o "$username" = "status" ]; then
218 if [ "$mode" == "" ]; then
222 if [ "$username" = "" ]; then
223 username
="$SUDO_USER"
224 if [ "$username" = "" ]; then
225 username
=`logname 2>/dev/null` || true
229 if [ `uname` = Linux
]; then
230 if [ "$mode" == "config" ]; then
232 elif [ "$mode" == "reset" ]; then
234 elif [ "$mode" == "status" ]; then
238 if [ "$mode" == "config" ]; then
240 elif [ "$mode" == "reset" ]; then