Commit eb8655b2 authored by Michal Berger's avatar Michal Berger Committed by Tomasz Zawadzki
Browse files

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: default avatarMichal 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: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent 9fab738e
Loading
Loading
Loading
Loading
+12 −3
Original line number Diff line number Diff line
@@ -86,6 +86,10 @@ function usage() {
# /sys/bus/pci/drivers/ as neither lsmod nor /sys/modules might
# contain needed info (like in Fedora-like OS).
function check_for_driver() {
	if [[ -z $1 ]]; then
		return 0
	fi

	if lsmod | grep -q ${1//-/_}; then
		return 1
	fi
@@ -166,6 +170,11 @@ function linux_unbind_driver() {
	ven_dev_id="${pci_ids_vendor["$bdf"]#0x} ${pci_ids_device["$bdf"]#0x}"
	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
		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"
@@ -256,8 +265,8 @@ function collect_driver() {
	local bdf=$1
	local drivers driver

	[[ -e /sys/bus/pci/devices/$bdf/modalias ]] || return 1
	if drivers=($(modprobe -R "$(< "/sys/bus/pci/devices/$bdf/modalias")")); then
	if [[ -e /sys/bus/pci/devices/$bdf/modalias ]] \
		&& drivers=($(modprobe -R "$(< "/sys/bus/pci/devices/$bdf/modalias")")); then
		# Pick first entry in case multiple aliases are bound to a driver.
		driver=$(readlink -f "/sys/module/${drivers[0]}/drivers/pci:"*)
		driver=${driver##*/}
@@ -537,7 +546,7 @@ function reset_linux_pci() {
		((all_devices_d["$bdf"] == 0)) || continue

		driver=$(collect_driver "$bdf")
		if ! check_for_driver "$driver"; then
		if [[ -n $driver ]] && ! check_for_driver "$driver"; then
			linux_bind_driver "$bdf" "$driver"
		else
			linux_unbind_driver "$bdf"