Skip to content

Commit 044a9df

Browse files
author
Christoph Hellwig
committed
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 <[email protected]> Reviewed-by: Keith Busch <[email protected]>
1 parent 9620cfb commit 044a9df

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

drivers/nvme/host/core.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1897,6 +1897,8 @@ int nvme_init_identify(struct nvme_ctrl *ctrl)
18971897
ctrl->cntlid = le16_to_cpu(id->cntlid);
18981898
ctrl->hmpre = le32_to_cpu(id->hmpre);
18991899
ctrl->hmmin = le32_to_cpu(id->hmmin);
1900+
ctrl->hmminds = le32_to_cpu(id->hmminds);
1901+
ctrl->hmmaxd = le16_to_cpu(id->hmmaxd);
19001902
}
19011903

19021904
kfree(id);

drivers/nvme/host/nvme.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,11 @@ struct nvme_ctrl {
181181
u64 ps_max_latency_us;
182182
bool apst_enabled;
183183

184+
/* PCIe only: */
184185
u32 hmpre;
185186
u32 hmmin;
187+
u32 hmminds;
188+
u16 hmmaxd;
186189

187190
/* Fabrics only */
188191
u16 sqsize;

drivers/nvme/host/pci.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1625,6 +1625,10 @@ static int __nvme_alloc_host_mem(struct nvme_dev *dev, u64 preferred,
16251625
tmp = (preferred + chunk_size - 1);
16261626
do_div(tmp, chunk_size);
16271627
max_entries = tmp;
1628+
1629+
if (dev->ctrl.hmmaxd && dev->ctrl.hmmaxd < max_entries)
1630+
max_entries = dev->ctrl.hmmaxd;
1631+
16281632
descs = dma_zalloc_coherent(dev->dev, max_entries * sizeof(*descs),
16291633
&descs_dma, GFP_KERNEL);
16301634
if (!descs)
@@ -1681,7 +1685,7 @@ static int nvme_alloc_host_mem(struct nvme_dev *dev, u64 min, u64 preferred)
16811685

16821686
/* start big and work our way down */
16831687
for (chunk_size = min_t(u64, preferred, PAGE_SIZE * MAX_ORDER_NR_PAGES);
1684-
chunk_size >= PAGE_SIZE * 2;
1688+
chunk_size >= max_t(u32, dev->ctrl.hmminds * 4096, PAGE_SIZE * 2);
16851689
chunk_size /= 2) {
16861690
if (!__nvme_alloc_host_mem(dev, preferred, chunk_size)) {
16871691
if (!min || dev->host_mem_size >= min)

include/linux/nvme.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,9 @@ struct nvme_id_ctrl {
226226
__le16 mntmt;
227227
__le16 mxtmt;
228228
__le32 sanicap;
229-
__u8 rsvd332[180];
229+
__le32 hmminds;
230+
__le16 hmmaxd;
231+
__u8 rsvd338[174];
230232
__u8 sqes;
231233
__u8 cqes;
232234
__le16 maxcmd;

0 commit comments

Comments
 (0)