Notes18检查FPGA版本,检查PCIE

Posted 码农编程录

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Notes18检查FPGA版本,检查PCIE相关的知识,希望对你有一定的参考价值。


1.fpga_check.py

# fpga_check.py 为检查FPGA版本脚本。
# 将fpga_check.py 拷贝到perfq_app所在的目录下执行。
#(/commit_code/ali_fpga/software/user/cli/perfq_app/)该脚本运行于OS下。
# 使用命令 python fpga_check.py b1  运行脚本。(参数1为 PCIE bus,根据实际情况传参)。

# coding = utf-8
import os
import sys
import subprocess

char_0 = './perfq_app -b 0000:'
char_1 = sys.argv[1]
char_2 = ':00.0 -o -R 0x1000'
command = char_0 + char_1 + char_2
print(command)
FPGA_Version = 'PIO Reg:0x1000 value:0x000001d2'
Read_Version = ''
var = subprocess.check_output(command, shell=True).decode('utf-8')

fp = open('fpga_test.txt', 'w')
fp.write(var)
fp.close()

fp = open('fpga_test.txt', 'r')
sample = fp.readlines()
for line in sample:
    line = line.strip()
    if 'Reg:0x1000' in line:
        Read_Version = line
fp.close()
os.system('sudo rm fpga_test.txt')

if Read_Version == FPGA_Version:
    print('FPGA Version is ok !')
else:
    print(var)
    print('Please check the version !')

2.pcie_check.py

# pcie_check.py脚本是检查PCIE的Corporation Device 、Region 0、Region 2、LnkCap、LnkSta信息。
# 注意板卡所在插槽位置。使用命令python pcie_check.py  b1运行脚本。
# b1为PCIE bus,根据实际情况传参。运行命令屏幕会显示相应需要检查信息的正确和错误信息。

# coding = utf-8
import os
import sys

char_0 = 'lspci -vvv -s '
char_1 = sys.argv[1]
char_2 = ':00.0 > FPGA_lspci_info.txt'
command = char_0 + char_1 + char_2
os.system(command)

Altera_Corporation_Device = 'Altera Corporation Device 0000'
Region_0 = 'size=4M'
Region_2 = 'size=16K'
LnkCap = 'Speed 16GT/s, Width x16'
LnkSta_0 = 'Speed 16GT/s'
LnkSta_1 = 'Width x16'

var = [0] * 10
i = 0
fp = open("FPGA_lspci_info.txt", "r")
sample = fp.readlines()

for line in sample:
    line = line.strip()
    if 'Unassigned class' in line:
        var[i] = line
        i = i + 1
    if 'Region 0: Memory' in line:
        var[i] = line
        i = i + 1
    if 'Region 2: Memory' in line:
        var[i] = line
        i = i + 1
    if 'LnkCap:' in line:
        var[i] = line
        i = i + 1
    if 'LnkSta:' in line:
        var[i] = line
        i = i + 1
fp.close()


if Altera_Corporation_Device in var[0]:
    print('Altera Corporation Device PASS')
else:
    print('ERROR')

if Region_0 in var[1]:
    print('Region 0 PASS')
else:
    print('ERROR')

if Region_2 in var[2]:
    print('Region 2 PASS')
else:
    print('ERROR')

if LnkCap in var[3]:
    print('LnkCap PASS')
else:
    print('ERROR')

if LnkSta_0 in var[4] and LnkSta_1 in var[4]:
    print('LnkSta PASS')
else:
    print('ERROR')
os.system('sudo rm FPGA_lspci_info.txt')

3.pcie.py

# pcie.py脚本是对PCIE通道的性能测试,主要是对FPGA寄存器读写压力测试,从而对PCIE性能进行测试。
# 请确保目录 ~/commit_code/ali_fpga/software/user/cli/perfq_app/ 目录下存在perfq_app 工具。
# 在os下将脚本文件拷到perfq_app所在的目录下使用命令 python pcie.py 参数1  参数2 运行脚本(参数1为板卡所在的号码如 b3 , 参数2为读写的次数)。 
# 运行脚本,屏幕会显示相应的错误和正确信息。

import os
import sys
import subprocess
from random import *

card_char = sys.argv[1]
times = sys.argv[2]
times = int(times)
if len(sys.argv) != 3:
    print('Please input the appropriate board and test times !')
    sys.exit(1)

char1 = '0000:'
char2 = ':00.0'
new_card = char1 + card_char + char2

Write_and_Read_1020 = './perfq_app -b 0000:b3:00.0 -o -W 0x1020 -D 0xaabbccdd'
Write_and_Read_1024 = './perfq_app -b 0000:b3:00.0 -o -W 0x1024 -D 0xaabbccdd'
Write_and_Read_1020 = Write_and_Read_1020.replace('0000:b3:00.0', new_card)
Write_and_Read_1024 = Write_and_Read_1024.replace('0000:b3:00.0', new_card)

abb = '0xaabbccdd'
New_Write_and_Read_1020 = ''
New_Write_and_Read_1024 = ''
result = 'PIO Test Successful 0'

def random_number():
    a = "".join([choice("0123456789abcdef") for i in range(8)])
    return a

def new_command(Write_and_Read_1020, abb):
    abc = random_number()  #abc为随机数 
    New_Write_and_Read_1020 = Write_and_Read_1020.replace(abb, abc)
    return New_Write_and_Read_1020

print("Test read and write fpga  reg ing ......")
fp = open('pcie_WR_reg.txt', 'w')
for i in range(times):
    New_Write_and_Read_1020 = new_command(Write_and_Read_1020, abb)
    var = subprocess.check_output(New_Write_and_Read_1020, shell=True).decode('utf-8')
    if result in var:
        pass
    else:
        print("error : read and write 1020 fpga reg  is error")
        sys.exit(1)
    fp.write(var)


    New_Write_and_Read_1024 = new_command(Write_and_Read_1024, abb)
    var = subprocess.check_output(New_Write_and_Read_1024, shell=True).decode('utf-8')
    if result in var:
        pass
    else:
        print("error : read and write 1024 fpga reg  is error")
        sys.exit(1)
    fp.write(var)
    
    if i == (times - 1):
        print("Test read and write fpga 1024 and 1020 reg is success !")
        print (times)

fp.close()
sys.exit(1)

print("Test read and write fpga 1024 reg ing ......")
for i in range(times):
    New_Write_and_Read_1024 = new_command(Write_and_Read_1024, abb)
    var = subprocess.check_output(New_Write_and_Read_1024, shell=True).decode('utf-8')
    if result in var:
        if i == (times -1):
            print("Test read and write fpga 1024 reg 500 times is success !")
    else:
        print("error :est read and write 1024 fpga reg 500 times is error")
        sys.exit(1)

如下取出第8位和第16位。

Return_value_bit8_bit16(){
    value=$1
    tmp1=$((0x$value >> 8)) #前面都是0
    value_bit8=$((0x$tmp1 & 0x01))

    tmp2=$((0x$value >> 16))
    value_bit16=$((0x$tmp2 & 0x01))  

    if [ $value_bit8 -eq 0 ] && [ $value_bit16 -eq 0 ]
    then
        echo "pass"
    else
        echo "error : Please confirm the return value !"
        exit 1
    fi 
}
Return_value_bit8_bit16 abcc10de

以上是关于Notes18检查FPGA版本,检查PCIE的主要内容,如果未能解决你的问题,请参考以下文章

基于2片Xilinx Kintex-7系列FPGA高性能VPX存储板

lattice fpga+pcie+x86平台服务器高性价比算法加速平台

lattice fpga+pcie+x86平台服务器高性价比算法加速平台

重置基于 FPGA 的 PCIe 卡并恢复其配置空间

FPGA反推法应用实例——检查代码

Notes18一键盘导出log工具,insmod,/sys/bus/pci/devices/0000