2022.07.02:
PCIE对于高速串行通信领域来说,是一个很常见的名字,最近研究了很久的PCIE资料,完成了从一无所知的小白到稍懂一点的小白的转变。当然PCIE的演变历程悠久,涉及到的知识万万千千,实际工作中,我首先追求的是知识储备够用即可,不去强求精通所有的应用,完全的实用主义者,先搞定0->1。
对于altera系列FPGA系列的PCIE开发来说,结合当前的系统,我只研究了PCIE的EP端知识及rtl实现,看过的文档很多,最重要的两个文档是:《ug_pci_express.pdf》、《PCI+EXPRESS体系结构导读.pdf》。
一.PCIE的基础知识简要说明:
- PCIE使用端对端的连接方式,RX&TX差分对;
- PCIE传输速率
单lane传输
Gen | Gen1 | Gen2 | Gen3 |
Gbpsx1 | 2.5Gbps | 5Gbps | 8Gbps |
编码方式 | 8B/10B | 8B/10B | 128B/130B |
有效带宽x1 | 2Gbps | 4Gbps | 7.8Gbps |
PCIE可由多lane组成,支持总线位宽类型:x1、x2、x4、x8、x12、x16、x32.
传输带宽:单lane带宽*总线位宽。
3.PCIE总线结构
- 物理层:8B/10B,链路训练
- 数据链路层:数据传输
- 事务层:接收应用层的数据请求(重点研究对象)
- 应用层:以Altera为例,采用的接口有两种:(a)Avalon-ST Interface;(b)Alvalon-MM Interface.
二.Altera FPGA PCIE IP Core设计
Altera PCIE采用的接口有两种:Avalon-ST Interface和Alvalon-MM Interface.
据说Alvalon-MM Interface设计简单,满足常见应用,适合新手快速上手(俗话说,欲速则不达,心急吃不了热豆腐),我简单研究了一下,没搞好(...尬);后续设计选择采用了Avalon-ST Interface类型,选择一条艰难之路。
1.IP参数设计:
(1)System settings
(2)PCI Registers
(3)Capabilities
(4)Buffer Setup
(5)Power Management
2.PCIE事务层TLP
TLP格式(通用字段4Byte)
Byte3 | Byte2 | Byte1 | Byte0 | ||||||||||||||||||||||||||||
7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
R | Fmt | Type | R | TC | R | TD | EP | Attr | AT | Length |
PCIE支持很多种事务,对于一般的应用,只要弄懂memory write和memory
read就足够了,可以做普通的寄存器读写、DMA读写。
3.需要注意的地方
- RC端初始化扫描设备,FPGA作为EP端时,需要做什么?
配置好系统时钟、复位、TX、RX即可。
- PCIE IP CORE的reconfig接口部分要级联ALTGX_RECONFIG;
- 要注意DMA操作过程中的Tag管理;
- Memory操作过程的4K边界处理;
- 3DW/4DW的处理。
- 系统RTL设计
FPGA RTL设计,共4个模块:
遇到的主要问题,是memory read的completion路由ID时序控制错误,导致RC端出现超时ERROR。
历经各种问题,各种调试,九九八十一难,终于取得真经,调试成功,终成功应用,很有成就感。作为技术人员来说,技术成就感不就是我们一直追求的东西吗?(虽然很早就有人做完了,但闻道有先后,咱就不妄自菲薄了)
- 后续展望
- 当前中断类型采用的还是常规中断,没有使用MSI中断,有时间再研究一下。
- 80%多的DMA读取效率还有待于提高,争取搞到90%。
- 对于PCIE这个庞然大物来说,自己依然是一个小白,总觉得自己遇到的问题不够多,研究的不够深,还需要虚心学习、深入研究。