基于Xilinx Alveo FPGA 100Gbps网卡(NIC)实现之二FPGA项目(2/4)

基于Xilinx Alveo FPGA 100Gbps网卡(NIC)

1、准备工作
2、FPGA项目
3、ONIC驱动
4、DPDK驱动



前言

上一章已介绍如何建立基于Xilinx Alveo FPGA 100Gbps网卡(NIC)的开发环境,主要介绍的是系统和软件方面的准备,FPGA硬件自然也需要准备,至于硬件如何安装就不再这里详述了,安装后可以通过lspci查看相关硬件是否安装正确,接下来将介绍如何搭建FPGA项目,是的FPGA变为我们所需要的网卡设备。


一、下载开源项目

OpenNIC FPGA项目可通过**这里**下载,也可以通过GIT CLONE命令下载:

> git clone https://github.com/Xilinx/open-nic-shell.git

下载完成后解压,解压后的文件目录结构如下:

    |-- open-nic-shell --
        |-- constr --
            |-- au50 --
	        |-- au55c --
	        |-- au55n --
            |-- au200 --
            |-- au250 --
            |-- au280 --
	        |-- U45N --
        |-- plugin --
            |-- p2p --
        |-- script --
            |-- board_settings --
            |-- build.tcl
        |-- src --
            |-- box_250mhz --
            |-- box_322mhz --
            |-- cmac_subsystem --
            |-- packet_adapter --
            |-- qdma_subsystem --
            |-- system_config --
            |-- utility --
            |-- open_nic_shell.sv
        |-- LICENSE.txt
        |-- README.md

其中constr文件夹存放相关板卡的信息,src文件夹存放相关的源码,script文件夹存放用于生成和编译相应的项目的脚步,plugin文件夹存放一些可用的插件。


二、创建FPGA NIC项目

创建项目需要使用script文件中的build.tcl,上文中已将vivado加入了bashrc,所以直接使用terminal命令即可生成所需项目。
首先进入srcipt文件夹

> cd script

如果使用的是Alveo U45N板卡,请参考使用如下命令:

vivado -mode tcl -source build.tcl -tclargs -board au45n -tag nic -jobs 8 -max_pkt_len 9600 -num_phys_func 2 -num_cmac_port 2 -num_qdma 2

或者使用vivado带图形GUI显示创建过程:

vivado -mode gui -source build.tcl -tclargs -board au45n -tag nic -jobs 8 -max_pkt_len 9600 -num_phys_func 2 -num_cmac_port 2 -num_qdma 2

如果使用的是Alveo U55C板卡,请参考使用如下命令:

vivado -mode gui -source build.tcl -tclargs -board au55c -tag nic -jobs 8 -max_pkt_len 9600 -num_phys_func 2 -num_cmac_port 2 -num_qdma 1
或者
vivado -mode tcl -source build.tcl -tclargs -board au55c -tag nic -jobs 8 -max_pkt_len 9600 -num_phys_func 2 -num_cmac_port 2 -num_qdma 1

注意不同板卡由于硬件不同,如U45N有2个QDMA,一个是与PCIe的,另一个是与卡上自带的ARM连接,而U55C只有和PCIe。
另外创建项目与操作系统无关,也即创建过程也可在WINDOWS上进行,只需要在windows上安装VITIS,同样用cmd或power shell运行上面的命令即可。


三、创建项目选项

Build options:


    -board_repo  PATH
                 path to local Xilinx board store repository for offline build.
                 This option is used when Vivado is unable to connect to github
                 and update the board repository.

    -board       BOARD_NAME
                 supported boards include:
                 - au250, and
                 - au280, and
                 - au200, and
                 - au55c, and
                 - au55n, and
                 - au50,  and
				 - U45N.

    -tag         DESIGN_TAG
                 string to identify the build.  The tag, along with the board
                 name, becomes part of the build directory name.

    -overwrite   0 (default), 1
                 indicate if the script should overwrite existing build results.

    -jobs        [1, 32] (default to 8)
                 number of jobs for synthesis and implementation.

    -synth_ip    0, 1 (default)
                 indicate if IPs are out-of-box synthesized after creation.

    -impl        0 (default), 1
                 indicate if the script runs towards bitstream generation.  If
                 set to 0, the script only creates the project and do not launch
                 any run.

    -post_impl   0 (default), 1
                 indicate if MCS file is generated after bitstream generations.

    -user_plugin PATH
                 path to the user plugin repository.

Design parameters:

-build_timestamp VALUE
                     VALUE should be an 8-digit hexdecimal value without prefix.
                     It serves as the timestamp to identify the build and is
                     written into the shell register 0x0.  If not specified, the
                     date and time of the build is recorded using the format
                     MMDDhhmm, where MM is for month, DD for day, hh for hour
                     and mm for minute.

    -min_pkt_len     [64, 256] (default to 64)
                     minimum packet length.

    -max_pkt_len     [256, 9600] (default to 1514)
                     maximum packet length.

    -use_phys_func   0, 1 (default)
                     indicates if the QDMA H2C and C2H AXI4-stream interfaces are
                     included in the 250MHz user logic box.  A common scenario
                     for not using them is networking accelerators without DMA.
                     Regardless the value of this option, the QDMA IP is always
                     present in the shell since it also provide the AXI-lite
                     interfaces for register access.

    -num_phys_func   [1, 4] (default to 1)
                     number of QDMA physical functions per QDMA subsystem.

    -num_qdma        1 (default), 2
                     number of QDMA subsystems, subjects to the board model.

    -num_queue       [1, 2048] (default to 512)
                     number of QDMA queues.

    -num_cmac_port   1 (default), 2
                     number of CMAC ports, subjects to the board model.


四、出错处理

对于创建项目中出现的错误(不走运会遇到哈哈),需要关注提示message。

比如U45N可能会遇到如下信息:

"user_plugin_250mhz_inst.vh" line23

可以更改如下信息

$fatal("No implementation for NUM_PHYS_FUNC (%d) != NUM_CMAC_PORT (%d)", NUM_PHYS_FUNC, NUM_CMAC_PORT);

$fatal("No implementation for NUM_PHYS_FUNC != NUM_CMAC_PORT");

又比如

# "open_nic_shell.sv" line202
wire [16*NUM_QDMA-1:0] qdma_pcie_rxp;
wire [16*NUM_QDMA-1:0] qdma_pcie_rxn;
wire [16*NUM_QDMA-1:0] qdma_pcie_txp;
wire [16*NUM_QDMA-1:0] qdma_pcie_txn;

耐心修改每一处错误,一般是由于自动生成的代码位宽不匹配造成的问题。

五、编译成功

编译成功后会在~.runs->impl_1中生成bitstream,并有可能时序不收敛,可以尝试更换综合实现的策略。
在这里插入图片描述

资源占比来看占用总资源的10%左右。
在这里插入图片描述

六、烧写FPGA程序

生成的bitstream文件不能直接写入flash中,需要转成mcs后才能烧写,所以需要先将bitsream文件转成mcs文件。
比如Alveo U45N器件可使用vivado tcl命令如下(注意文件名替换为自己的命名

write_cfgmem -force -format mcs -interface spix4 -size 128 -loadbit "up 0x0 open_nic_shell_u45n.bit" -file "open_nic_shell_u45n.mcs"

而Alveo U55C需要添加偏移地址,其它型号具体可查看官方文档

write_cfgmem -force -format mcs -interface spix4 -size 128 -loadbit "up 0x01002000 open_nic_shell.bit" -file "open_nic_shell.mcs"

接下来准备写入flash,如果是Linux系统,可能会找不到器件,原因是安装vitis时下载器的驱动默认没有安装上去,好了只能自己安装了。

cd /tools/Xilinx/Vivado/2023.2/data/xicom/cable_drivers/lin64/install_script/install_drivers
sudo ./install_driver

可以使用图像界面写入mcs文件,器件选择mt25qu02g-spi-x1_x2_x4,再选择生成的mcs即可。
具体可参考《FPGA Device in the Vivado Design Suite User Guide: Programming and Debugging (UG908)》

Connect to the Alveo U45N data center accelerator card using the Vivado hardware manager via the ADK2 connector. Details on connecting to the Alveo card through the ADK2 connector are provided in the Alveo Debug Kit User Guide (UG1538).
Right click on device xcu26_0, under the Hardware window, and select Add Configuration Memory Device .  Enter "mt25qu02g-spi-x1_x2_x4" in the search bar and select part mt25qu02g-spi-x1_x2_x4.
Select OK when prompted "Do you want to program the configuration memory device now?" or right-click the target to select Program the Configuration Memory Device.
Select the MCS file target.
Select Configuration File Only.
Click OK.
After programming has completed, disconnect the card in the hardware manager, and disconnect the JTAG programming cable from the Alveo accelerator card.
Perform a cold reboot on the host machine to complete the card update.

本章总结&未完待续

至此FPGA已经准备完成,FPGA已经变成一块网卡设备了,接下来只需要相应的驱动Driver即可让这块NIC工作了。
接下来将进行驱动的编译和使用。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值