[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"

 

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