Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug in dma_if_pcie_rd when max read request size is set to 4096 bytes #35

Open
EricCSun opened this issue Jul 7, 2023 · 0 comments
Open

Comments

@EricCSun
Copy link

EricCSun commented Jul 7, 2023

Hi Alex,
please consider this situation:

  1. max read request size is set to 4096 bytes.
  2. request a dma read from any address that is 4K aligned (say 0x1000), dma length is 4096 bytes.

Normally only one Mrd TLP will be sent, but dma_if_pcie_rd generates two TLPs, one is a Mrd from address 0x1000 and another is a Mrd from address 0x2000, both TLP's dword count is 1024 (4096 bytes). The later Mrd will corrupt the data.

I think the cause is in dma_if_pcie_rd.v, line 675:

req_last_tlp = (((req_pcie_addr_reg & 12'hfff) + (req_op_count_reg & 12'hfff)) & 12'hfff) == 0 && req_op_count_reg >> 12 == 0;

In above situation,"(((req_pcie_addr_reg & 12'hfff) + (req_op_count_reg & 12'hfff)) & 12'hfff) == 0" is true, req_op_count_reg is 4096, hence “req_op_count_reg >> 12” equals 1,"req_op_count_reg >> 12 == 0" is false, req_last_tlp is not assigned to 1, an unexpected tlp will be generated.

Is it OK to delete "&& req_op_count_reg >> 12 == 0" in line 675?
req_op_count_reg must be not greater than max read request size to reach line 675 (see line 663) and the maximum value of max read request size is 4096. "req_op_count_reg >> 12 == 0" is false only when req_op_count_reg equals 4096.
In the case that req_op_count_reg equals 4096, there is a chance that it is the last TLP (above situation), and "(((req_pcie_addr_reg & 12'hfff) + (req_op_count_reg & 12'hfff)) & 12'hfff) == 0" will determine wheter it is the last TLP.
In other cases that req_op_count_reg is less than 4096, "req_op_count_reg >> 12 == 0" is always false, so there is no need to evaluate it.

Please tell me if I was wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant