setup.sh: Make sure driver is known upon reset
In case collect_driver() returns immediately due to missing modalias attr, an empty $driver will be passed to check_for_driver() causing grep inside to fail. Further false-positive then leads to call to linux_bind_driver() as it's not able to locate proper paths for given driver. To avoid this, make sure collect_driver() always attempts to fallback to a driver setup.sh supports for a target device. Signed-off-by: Michal Berger <michallinuxstuff@gmail.com> Change-Id: Id5631a731910f60b63c6afb3a412575bb69d784a Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/11747 Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com> Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
parent
9fab738e6e
commit
eb8655b2fe
@ -86,6 +86,10 @@ function usage() {
|
|||||||
# /sys/bus/pci/drivers/ as neither lsmod nor /sys/modules might
|
# /sys/bus/pci/drivers/ as neither lsmod nor /sys/modules might
|
||||||
# contain needed info (like in Fedora-like OS).
|
# contain needed info (like in Fedora-like OS).
|
||||||
function check_for_driver() {
|
function check_for_driver() {
|
||||||
|
if [[ -z $1 ]]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
if lsmod | grep -q ${1//-/_}; then
|
if lsmod | grep -q ${1//-/_}; then
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
@ -166,6 +170,11 @@ function linux_unbind_driver() {
|
|||||||
ven_dev_id="${pci_ids_vendor["$bdf"]#0x} ${pci_ids_device["$bdf"]#0x}"
|
ven_dev_id="${pci_ids_vendor["$bdf"]#0x} ${pci_ids_device["$bdf"]#0x}"
|
||||||
local old_driver_name=${drivers_d["$bdf"]:-no driver}
|
local old_driver_name=${drivers_d["$bdf"]:-no driver}
|
||||||
|
|
||||||
|
if [[ $old_driver_name == "no driver" ]]; then
|
||||||
|
pci_dev_echo "$bdf" "Not bound to any driver"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ -e /sys/bus/pci/drivers/$old_driver_name ]]; then
|
if [[ -e /sys/bus/pci/drivers/$old_driver_name ]]; then
|
||||||
echo "$ven_dev_id" > "/sys/bus/pci/drivers/$old_driver_name/remove_id" 2> /dev/null || true
|
echo "$ven_dev_id" > "/sys/bus/pci/drivers/$old_driver_name/remove_id" 2> /dev/null || true
|
||||||
echo "$bdf" > "/sys/bus/pci/drivers/$old_driver_name/unbind"
|
echo "$bdf" > "/sys/bus/pci/drivers/$old_driver_name/unbind"
|
||||||
@ -256,8 +265,8 @@ function collect_driver() {
|
|||||||
local bdf=$1
|
local bdf=$1
|
||||||
local drivers driver
|
local drivers driver
|
||||||
|
|
||||||
[[ -e /sys/bus/pci/devices/$bdf/modalias ]] || return 1
|
if [[ -e /sys/bus/pci/devices/$bdf/modalias ]] \
|
||||||
if drivers=($(modprobe -R "$(< "/sys/bus/pci/devices/$bdf/modalias")")); then
|
&& drivers=($(modprobe -R "$(< "/sys/bus/pci/devices/$bdf/modalias")")); then
|
||||||
# Pick first entry in case multiple aliases are bound to a driver.
|
# Pick first entry in case multiple aliases are bound to a driver.
|
||||||
driver=$(readlink -f "/sys/module/${drivers[0]}/drivers/pci:"*)
|
driver=$(readlink -f "/sys/module/${drivers[0]}/drivers/pci:"*)
|
||||||
driver=${driver##*/}
|
driver=${driver##*/}
|
||||||
@ -537,7 +546,7 @@ function reset_linux_pci() {
|
|||||||
((all_devices_d["$bdf"] == 0)) || continue
|
((all_devices_d["$bdf"] == 0)) || continue
|
||||||
|
|
||||||
driver=$(collect_driver "$bdf")
|
driver=$(collect_driver "$bdf")
|
||||||
if ! check_for_driver "$driver"; then
|
if [[ -n $driver ]] && ! check_for_driver "$driver"; then
|
||||||
linux_bind_driver "$bdf" "$driver"
|
linux_bind_driver "$bdf" "$driver"
|
||||||
else
|
else
|
||||||
linux_unbind_driver "$bdf"
|
linux_unbind_driver "$bdf"
|
||||||
|
Loading…
Reference in New Issue
Block a user