[PCIe] Hot reset and FLR reset Performing in linux

“热重置”是通过PCI Express链路触发的常规重置。当链路被迫进入电气空闲状态时,或通过发送带有热复位bit的TS1和TS2有序集来触发热复位。软件可以通过设置然后清除设备上游桥接端口的PCI配置空间中桥接控制寄存器中的辅助总线复位位来启动热复位。(下图Bridge Control Register->Secondary Bus Reset)

Secondary Bus Reset - Setting this bit triggers a hot reset on the corresponding PCI Express Port.
Software must ensure a minimum reset duration (Trst). Software and systems must honor
first-access-following-reset timing requirements defined in Section 6.6 ., unless the Readiness
Notifications mechanism (see Section 6.23 ) is used or if the Immediate Readiness bit in the relevant
Function’s Status register is Set.
Port configuration registers must not be changed, except as required to update Port status.
Default value of this bit is 0b.

“功能级别重置”(FLR)是仅影响PCI Express设备的单个功能的重置。它不得重置整个PCIe设备。 PCIe规范不需要实现功能级别的重置。通过将PCI配置空间中PCI Express功能结构中功能的设备控制寄存器中的启动功能级别复位位置1,可以启动功能级别复位。

Linux以/sys/bus/pci/devices/$dev/reset的形式公开功能级别的重置功能。向该文件写入1将启动相应功能的功能级复位。请注意,这仅影响设备的特定功能,而不影响整个设备,并且不要求设备按照PCIe规范实施功能级别的重置。

我不知道触发热重置的任何“较好”方法(没有sysfs条目)。但是,可以通过以下脚本使用setpci进行操作(其实就是写下游端口配置空间的Bridge Control Register->Secondary Bus Reset):

#!/bin/bash

dev=$1

if [ -z "$dev" ]; then
    echo "Error: no device specified"
    exit 1
fi

if [ ! -e "/sys/bus/pci/devices/$dev" ]; then
    dev="0000:$dev"
fi

if [ ! -e "/sys/bus/pci/devices/$dev" ]; then
    echo "Error: device $dev not found"
    exit 1
fi

port=$(basename $(dirname $(readlink "/sys/bus/pci/devices/$dev")))

if [ ! -e "/sys/bus/pci/devices/$port" ]; then
    echo "Error: device $port not found"
    exit 1
fi

echo "Removing $dev..."

echo 1 > "/sys/bus/pci/devices/$dev/remove"

echo "Performing hot reset of port $port..."

bc=$(setpci -s $port BRIDGE_CONTROL)

echo "Bridge control:" $bc

setpci -s $port BRIDGE_CONTROL=$(printf "%04x" $(("0x$bc" | 0x40)))
sleep 0.01
setpci -s $port BRIDGE_CONTROL=$bc
sleep 0.5

echo "Rescanning bus..."

echo 1 > "/sys/bus/pci/devices/$port/rescan"

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章