2016-06-08 01:47:02 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2016-06-29 17:02:03 +00:00
|
|
|
NVMF_PORT=4420
|
2016-06-17 19:56:56 +00:00
|
|
|
NVMF_IP_PREFIX="192.168.100"
|
2016-06-08 01:47:02 +00:00
|
|
|
NVMF_IP_LEAST_ADDR=8
|
2016-06-17 19:56:56 +00:00
|
|
|
NVMF_FIRST_TARGET_IP=$NVMF_IP_PREFIX.$NVMF_IP_LEAST_ADDR
|
2016-08-17 22:42:21 +00:00
|
|
|
RPC_PORT=5260
|
2016-06-08 01:47:02 +00:00
|
|
|
|
|
|
|
function load_ib_rdma_modules()
|
|
|
|
{
|
|
|
|
if [ `uname` != Linux ]; then
|
2016-07-08 21:19:11 +00:00
|
|
|
return 0
|
2016-06-08 01:47:02 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
modprobe ib_cm
|
|
|
|
modprobe ib_core
|
|
|
|
modprobe ib_ucm
|
|
|
|
modprobe ib_umad
|
|
|
|
modprobe ib_uverbs
|
|
|
|
modprobe iw_cm
|
|
|
|
modprobe rdma_cm
|
|
|
|
modprobe rdma_ucm
|
|
|
|
}
|
|
|
|
|
|
|
|
function detect_mellanox_nics()
|
|
|
|
{
|
2016-07-08 21:19:11 +00:00
|
|
|
if ! hash lspci; then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
2016-06-08 01:47:02 +00:00
|
|
|
nvmf_nic_bdfs=`lspci | grep Ethernet | grep Mellanox | awk -F ' ' '{print "0000:"$1}'`
|
|
|
|
mlx_core_driver="mlx4_core"
|
|
|
|
mlx_ib_driver="mlx4_ib"
|
|
|
|
mlx_en_driver="mlx4_en"
|
|
|
|
|
|
|
|
if [ -z "$nvmf_nic_bdfs" ]; then
|
2016-07-08 21:19:11 +00:00
|
|
|
return 0
|
2016-06-08 01:47:02 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# for nvmf target loopback test, suppose we only have one type of card.
|
|
|
|
for nvmf_nic_bdf in $nvmf_nic_bdfs
|
|
|
|
do
|
|
|
|
result=`find /sys -name $nvmf_nic_bdf | grep driver | awk -F / '{ print $6 }'`
|
|
|
|
if [ "$result" == "mlx5_core" ]; then
|
|
|
|
mlx_core_driver="mlx5_core"
|
|
|
|
mlx_ib_driver="mlx5_ib"
|
|
|
|
mlx_en_driver=""
|
|
|
|
fi
|
|
|
|
break;
|
|
|
|
done
|
|
|
|
|
|
|
|
modprobe $mlx_core_driver
|
|
|
|
modprobe $mlx_ib_driver
|
|
|
|
if [ -n "$mlx_en_driver" ]; then
|
|
|
|
modprobe $mlx_en_driver
|
|
|
|
fi
|
|
|
|
|
2016-06-17 19:56:56 +00:00
|
|
|
# The mlx4 driver takes an extra few seconds to load after modprobe returns,
|
|
|
|
# otherwise ifconfig operations will do nothing.
|
|
|
|
sleep 5
|
2016-06-08 01:47:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function detect_rdma_nics()
|
|
|
|
{
|
|
|
|
# could be add other nics, so wrap it
|
|
|
|
detect_mellanox_nics
|
|
|
|
}
|
|
|
|
|
|
|
|
function allocate_nic_ips()
|
|
|
|
{
|
2016-06-17 19:56:56 +00:00
|
|
|
let count=$NVMF_IP_LEAST_ADDR
|
|
|
|
for nic_type in `ls /sys/class/infiniband`; do
|
|
|
|
for nic_name in `ls /sys/class/infiniband/${nic_type}/device/net`; do
|
|
|
|
ifconfig $nic_name $NVMF_IP_PREFIX.$count netmask 255.255.255.0 up
|
2016-07-08 21:19:11 +00:00
|
|
|
|
|
|
|
# dump configuration for debug log
|
|
|
|
ifconfig $nic_name
|
2016-06-17 19:56:56 +00:00
|
|
|
let count=$count+1
|
|
|
|
done
|
2016-06-08 01:47:02 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
function nvmfcleanup()
|
|
|
|
{
|
2016-07-11 18:06:55 +00:00
|
|
|
sync
|
2016-06-08 01:47:02 +00:00
|
|
|
rmmod nvme-rdma
|
|
|
|
}
|
|
|
|
|
|
|
|
function rdma_device_init()
|
|
|
|
{
|
|
|
|
load_ib_rdma_modules
|
|
|
|
detect_rdma_nics
|
2016-06-17 19:56:56 +00:00
|
|
|
allocate_nic_ips
|
2016-06-08 01:47:02 +00:00
|
|
|
}
|
|
|
|
|
2016-07-08 21:19:11 +00:00
|
|
|
function rdma_nic_available()
|
|
|
|
{
|
|
|
|
ifconfig | grep -q $NVMF_IP_PREFIX
|
|
|
|
}
|