Lines Matching refs:sg
15 * @sg: The current sg entry
18 * Usually the next entry will be @sg@ + 1, but if this sg element is part
23 struct scatterlist *sg_next(struct scatterlist *sg)
25 if (sg_is_last(sg))
28 sg++;
29 if (unlikely(sg_is_chain(sg)))
30 sg = sg_chain_ptr(sg);
32 return sg;
38 * @sg: The scatterlist
41 * Allows to know how many entries are in sg, taking into acount
45 int sg_nents(struct scatterlist *sg)
48 for (nents = 0; sg; sg = sg_next(sg))
57 * @sg: The scatterlist
61 * Determines the number of entries in sg that are required to meet
65 * the number of sg entries needed, negative error on failure
68 int sg_nents_for_len(struct scatterlist *sg, u64 len)
76 for (nents = 0, total = 0; sg; sg = sg_next(sg)) {
78 total += sg->length;
103 struct scatterlist *sg, *ret = NULL;
106 for_each_sg(sgl, sg, nents, i)
107 ret = sg;
120 * If this is part of a chained sg table, sg_mark_end() should be
132 * sg_init_one - Initialize a single entry sg list
133 * @sg: SG entry
138 void sg_init_one(struct scatterlist *sg, const void *buf, unsigned int buflen)
140 sg_init_table(sg, 1);
141 sg_set_buf(sg, buf, buflen);
169 static void sg_kfree(struct scatterlist *sg, unsigned int nents)
172 kmemleak_free(sg);
173 free_page((unsigned long) sg);
175 kfree(sg);
179 * __sg_free_table - Free a previously mapped sg table
180 * @table: The sg table header to use
187 * Free an sg table previously allocated and setup with
208 * then assign 'next' to the sg table after the current one.
235 * sg_free_table - Free a previously allocated sg table
236 * @table: The mapped sg table header
246 * __sg_alloc_table - Allocate and initialize an sg table with given allocator
247 * @table: The sg table header to use
248 * @nents: Number of entries in sg list
271 struct scatterlist *sg, *prv;
299 sg = first_chunk;
302 sg = alloc_fn(alloc_size, gfp_mask);
304 if (unlikely(!sg)) {
317 sg_init_table(sg, alloc_size);
321 * If this is the first mapping, assign the sg table header.
325 sg_chain(prv, prv_max_ents, sg);
327 table->sgl = sg;
333 sg_mark_end(&sg[sg_size - 1]);
335 prv = sg;
345 * sg_alloc_table - Allocate and initialize an sg table
346 * @table: The sg table header to use
347 * @nents: Number of entries in sg list
351 * Allocate and initialize an sg table. If @nents@ is larger than
352 * SG_MAX_SINGLE_ALLOC a chained sg table will be setup.
400 * __sg_alloc_table_from_pages - Allocate and initialize an sg table from
402 * @sgt: The sg table header to use
413 * If @prv is NULL, allocate and initialize an sg table from a list of pages,
526 * sg_alloc_table_from_pages - Allocate and initialize an sg table from
528 * @sgt: The sg table header to use
536 * Allocate and initialize an sg table from a list of pages. Contiguous
539 * specified by the page array. The returned sg table is released by
571 struct scatterlist *sgl, *sg;
593 sg = sgl;
602 sg_set_page(sg, page, elem_len, 0);
604 sg = sg_next(sg);
643 struct scatterlist *sg;
647 for_each_sg(sgl, sg, nents, i) {
648 if (!sg)
650 page = sg_page(sg);
688 piter->sg = sglist;
693 static int sg_page_count(struct scatterlist *sg)
695 return PAGE_ALIGN(sg->offset + sg->length) >> PAGE_SHIFT;
700 if (!piter->__nents || !piter->sg)
706 while (piter->sg_pgoffset >= sg_page_count(piter->sg)) {
707 piter->sg_pgoffset -= sg_page_count(piter->sg);
708 piter->sg = sg_next(piter->sg);
709 if (!--piter->__nents || !piter->sg)
717 static int sg_dma_page_count(struct scatterlist *sg)
719 return PAGE_ALIGN(sg->offset + sg_dma_len(sg)) >> PAGE_SHIFT;
726 if (!piter->__nents || !piter->sg)
732 while (piter->sg_pgoffset >= sg_dma_page_count(piter->sg)) {
733 piter->sg_pgoffset -= sg_dma_page_count(piter->sg);
734 piter->sg = sg_next(piter->sg);
735 if (!--piter->__nents || !piter->sg)
744 * sg_miter_start - start mapping iteration over a sg list
745 * @miter: sg mapping iter to be started
746 * @sgl: sg list to iterate over
747 * @nents: number of sg entries
769 struct scatterlist *sg;
774 sg = miter->piter.sg;
776 miter->__offset = miter->piter.sg_pgoffset ? 0 : sg->offset;
779 miter->__remaining = sg->offset + sg->length -
791 * @miter: sg mapping iter to be skipped
804 * true if @miter contains the valid mapping. false if end of sg
829 * @miter: sg mapping iter to proceed
841 * true if @miter contains the next mapping. false if end of sg
869 * @miter: sg mapping iter to be stopped
915 * @to_buffer: transfer direction (true == from an sg list to a
916 * buffer, false == from a buffer to an sg list)