NVME fix PRP Offset Invalid
cover NVME fix PRP Offset Invalid
Our QA team had problems writing large files (187MB) to the FAT filesystem on a Samsung EVO 970 NVME drive and I was able to track it down to PRP buffer issues. Namely, this buffer cannot cross a page boundary and it should be allocated in page-sized chunks. This patch modifies the U-Boot NVME driver to match what the Linux kernel PCI driver does.
Aaron Williams (1):
nvme: Fix PRP Offset Invalid
drivers/nvme/nvme.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
--
2.16.4
PATCH 1/1 nvme: Fix PRP Offset Invalid
When large writes take place I saw a Samsung EVO 970+ return a status value of 0x13, PRP Offset Invalid. I tracked this down to the improper handling of PRP entries. The blocks the PRP entries are placed in cannot cross a page boundary and thus should be allocated on page boundaries. This is how the Linux kernel driver works.
With this patch, the PRP pool is allocated on a page boundary and other than the very first allocation, the pool size is a multiple of the page size. Each page can hold (4096 / 8) - 1 entries since the last entry must point to the next page in the pool.
--- drivers/nvme/nvme.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/nvme/nvme.c +6 -3
@@ -75,6 +75,8 @@ static int nvme_setup_prps(struct nvme_dev *dev, u64 *prp2,int length = total_len;int i, nprps; length -= (page_size - offset); +u32 prps_per_page = (page_size >>3 ) -1 ; +u32 num_pages;if (length <=0 ) { *prp2 =0 ;
@@ -90,15 +92,16 @@ static int nvme_setup_prps(struct nvme_dev *dev, u64 *prp2, } nprps =DIV_ROUND_UP (length, page_size); + num_pages = (nprps + prps_per_page -1 ) / prps_per_page;if (nprps > dev->prp_entry_num) {free (dev->prp_pool); - dev->prp_pool =malloc (nprps <<3 ); + dev->prp_pool =memalign (page_size, num_pages * page_size);if (!dev->prp_pool) {printf ("Error: malloc prp_pool fail\n" );return -ENOMEM ; } - dev->prp_entry_num = nprps; + dev->prp_entry_num = ((page_size >>3 ) -1 ) * num_pages; } prp_pool = dev->prp_pool;
@@ -791,7 +794,7 @@ static int nvme_probe(struct udevice *udev) }memset (ndev->queues,0 ,NVME_Q_NUM *sizeof (struct nvme_queue *)); - ndev->prp_pool =malloc (MAX_PRP_POOL ); + ndev->prp_pool =memalign (1 <<12 ,MAX_PRP_POOL );if (!ndev->prp_pool) { ret = -ENOMEM ;printf ("Error: %s: Out of memory!\n" , udev->name);
--
2.16.4