[PATCH V2 1/2] nvme-core: replace ctrl page size with a macro

Christoph Hellwig hch at lst.de
Mon Jul 13 03:42:10 EDT 2020


On Thu, Jul 09, 2020 at 04:40:24PM -0700, Chaitanya Kulkarni wrote:
> +/*
> + * Default to a 4K page size, with the intention to update this
> + * path in the future to accommodate architectures with differing
> + * kernel and IO page sizes.
> + */
> +#define NVME_CTRL_PAGE_SHIFT	12
> +#define NVME_CTRL_PAGE_SIZE	4096

NVME_CTRL_PAGE_SIZE can be defined as

(1 << NVME_CTRL_PAGE_SHIFT) instead of duplicating the value.

> index 45e94f016ec2..68f7c090cf51 100644
> --- a/drivers/nvme/host/pci.c
> +++ b/drivers/nvme/host/pci.c
> @@ -348,8 +348,8 @@ static bool nvme_dbbuf_update_and_check_event(u16 value, u32 *dbbuf_db,
>   */
>  static int nvme_npages(unsigned size, struct nvme_dev *dev)
>  {
> -	unsigned nprps = DIV_ROUND_UP(size + dev->ctrl.page_size,
> -				      dev->ctrl.page_size);
> +	unsigned nprps = DIV_ROUND_UP(size + NVME_CTRL_PAGE_SIZE,
> +						NVME_CTRL_PAGE_SIZE);
>  	return DIV_ROUND_UP(8 * nprps, PAGE_SIZE - 8);

This looks like the existing code here is wrong, as DIV_ROUND_UP already
adds the page size itself.  But that is better left for another patch..



More information about the Linux-nvme mailing list