nvme-pci: implement the HMB entry number and size limitations

Adds support for the new Host Memory Buffer Minimum Descriptor Entry Size
and Host Memory Maximum Descriptors Entries field that were added in
TP 4002 HMB Enhancements. These allow the controller to advertise
limits for the usual number of segments in the host memory buffer, as
well as a minimum usable per-segment size.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Keith Busch <keith.busch@intel.com>

+13 -2
+2
drivers/nvme/host/core.c
··· 1897 1897 ctrl->cntlid = le16_to_cpu(id->cntlid); 1898 1898 ctrl->hmpre = le32_to_cpu(id->hmpre); 1899 1899 ctrl->hmmin = le32_to_cpu(id->hmmin); 1900 + ctrl->hmminds = le32_to_cpu(id->hmminds); 1901 + ctrl->hmmaxd = le16_to_cpu(id->hmmaxd); 1900 1902 } 1901 1903 1902 1904 kfree(id);
+3
drivers/nvme/host/nvme.h
··· 181 181 u64 ps_max_latency_us; 182 182 bool apst_enabled; 183 183 184 + /* PCIe only: */ 184 185 u32 hmpre; 185 186 u32 hmmin; 187 + u32 hmminds; 188 + u16 hmmaxd; 186 189 187 190 /* Fabrics only */ 188 191 u16 sqsize;
+5 -1
drivers/nvme/host/pci.c
··· 1625 1625 tmp = (preferred + chunk_size - 1); 1626 1626 do_div(tmp, chunk_size); 1627 1627 max_entries = tmp; 1628 + 1629 + if (dev->ctrl.hmmaxd && dev->ctrl.hmmaxd < max_entries) 1630 + max_entries = dev->ctrl.hmmaxd; 1631 + 1628 1632 descs = dma_zalloc_coherent(dev->dev, max_entries * sizeof(*descs), 1629 1633 &descs_dma, GFP_KERNEL); 1630 1634 if (!descs) ··· 1685 1681 1686 1682 /* start big and work our way down */ 1687 1683 for (chunk_size = min_t(u64, preferred, PAGE_SIZE * MAX_ORDER_NR_PAGES); 1688 - chunk_size >= PAGE_SIZE * 2; 1684 + chunk_size >= max_t(u32, dev->ctrl.hmminds * 4096, PAGE_SIZE * 2); 1689 1685 chunk_size /= 2) { 1690 1686 if (!__nvme_alloc_host_mem(dev, preferred, chunk_size)) { 1691 1687 if (!min || dev->host_mem_size >= min)
+3 -1
include/linux/nvme.h
··· 226 226 __le16 mntmt; 227 227 __le16 mxtmt; 228 228 __le32 sanicap; 229 - __u8 rsvd332[180]; 229 + __le32 hmminds; 230 + __le16 hmmaxd; 231 + __u8 rsvd338[174]; 230 232 __u8 sqes; 231 233 __u8 cqes; 232 234 __le16 maxcmd;