Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

scatterlist: introduce sg_nents_for_dma() helper

Sometimes the user needs to split each entry on the mapped scatter list
due to DMA length constrains. This helper returns a number of entities
assuming that each of them is not bigger than supplied maximum length.

Reviewed-by: Bjorn Andersson <andersson@kernel.org>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://patch.msgid.link/20260108105619.3513561-2-andriy.shevchenko@linux.intel.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>

authored by

Andy Shevchenko and committed by
Vinod Koul
80c70bfb fe7b87d9

+28
+2
include/linux/scatterlist.h
··· 441 441 442 442 int sg_nents(struct scatterlist *sg); 443 443 int sg_nents_for_len(struct scatterlist *sg, u64 len); 444 + int sg_nents_for_dma(struct scatterlist *sgl, unsigned int sglen, size_t len); 445 + 444 446 struct scatterlist *sg_last(struct scatterlist *s, unsigned int); 445 447 void sg_init_table(struct scatterlist *, unsigned int); 446 448 void sg_init_one(struct scatterlist *, const void *, unsigned int);
+26
lib/scatterlist.c
··· 65 65 EXPORT_SYMBOL(sg_nents_for_len); 66 66 67 67 /** 68 + * sg_nents_for_dma - return the count of DMA-capable entries in scatterlist 69 + * @sgl: The scatterlist 70 + * @sglen: The current number of entries 71 + * @len: The maximum length of DMA-capable block 72 + * 73 + * Description: 74 + * Determines the number of entries in @sgl which would be permitted in 75 + * DMA-capable transfer if list had been split accordingly, taking into 76 + * account chaining as well. 77 + * 78 + * Returns: 79 + * the number of sgl entries needed 80 + * 81 + **/ 82 + int sg_nents_for_dma(struct scatterlist *sgl, unsigned int sglen, size_t len) 83 + { 84 + struct scatterlist *sg; 85 + int i, nents = 0; 86 + 87 + for_each_sg(sgl, sg, sglen, i) 88 + nents += DIV_ROUND_UP(sg_dma_len(sg), len); 89 + return nents; 90 + } 91 + EXPORT_SYMBOL(sg_nents_for_dma); 92 + 93 + /** 68 94 * sg_last - return the last scatterlist entry in a list 69 95 * @sgl: First entry in the scatterlist 70 96 * @nents: Number of entries in the scatterlist