diff options
author | hselasky <hselasky@FreeBSD.org> | 2015-10-19 11:09:51 +0000 |
---|---|---|
committer | hselasky <hselasky@FreeBSD.org> | 2015-10-19 11:09:51 +0000 |
commit | bed28ab60d0d2d7172650d8d00dd31519885955c (patch) | |
tree | e5844eb58636b2622869ab39b39fb5eafff6ae25 /sys/ofed | |
parent | c58bf9145bf400f6f98e6f221d2f329099acb120 (diff) | |
download | FreeBSD-src-bed28ab60d0d2d7172650d8d00dd31519885955c.zip FreeBSD-src-bed28ab60d0d2d7172650d8d00dd31519885955c.tar.gz |
Merge LinuxKPI changes from DragonflyBSD:
- Avoid using PAGE_MASK, because Linux defines it differently.
Use (PAGE_SIZE - 1) instead.
- Add support for for_each_sg_page() and sg_page_iter_dma_address().
Sponsored by: Mellanox Technologies
Diffstat (limited to 'sys/ofed')
-rw-r--r-- | sys/ofed/include/linux/scatterlist.h | 69 |
1 files changed, 68 insertions, 1 deletions
diff --git a/sys/ofed/include/linux/scatterlist.h b/sys/ofed/include/linux/scatterlist.h index 595e2e9..b8e7c29 100644 --- a/sys/ofed/include/linux/scatterlist.h +++ b/sys/ofed/include/linux/scatterlist.h @@ -3,6 +3,7 @@ * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. + * Copyright (c) 2015 Matthew Dillon <dillon@backplane.com> * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -64,6 +65,12 @@ struct sg_table { unsigned int orig_nents; /* original size of list */ }; +struct sg_page_iter { + struct scatterlist *sg; + unsigned int sg_pgoffset; /* page index */ + unsigned int maxents; +}; + /* * Maximum number of entries that will be allocated in one piece, if * a list larger than this is required then chaining will be utilized. @@ -93,7 +100,7 @@ static inline void sg_set_buf(struct scatterlist *sg, const void *buf, unsigned int buflen) { sg_set_page(sg, virt_to_page(buf), buflen, - ((uintptr_t)buf) & ~PAGE_MASK); + ((uintptr_t)buf) & (PAGE_SIZE - 1)); } static inline void @@ -326,6 +333,66 @@ sg_alloc_table(struct sg_table *table, unsigned int nents, gfp_t gfp_mask) return ret; } +/* + * Iterate pages in sg list. + */ +static inline void +_sg_iter_next(struct sg_page_iter *iter) +{ + struct scatterlist *sg; + unsigned int pgcount; + + sg = iter->sg; + pgcount = (sg->offset + sg->length + PAGE_SIZE - 1) >> PAGE_SHIFT; + + ++iter->sg_pgoffset; + while (iter->sg_pgoffset >= pgcount) { + iter->sg_pgoffset -= pgcount; + sg = sg_next(sg); + --iter->maxents; + if (sg == NULL || iter->maxents == 0) + break; + pgcount = (sg->offset + sg->length + PAGE_SIZE - 1) >> PAGE_SHIFT; + } + iter->sg = sg; +} + +/* + * NOTE: pgoffset is really a page index, not a byte offset. + */ +static inline void +_sg_iter_init(struct scatterlist *sgl, struct sg_page_iter *iter, + unsigned int nents, unsigned long pgoffset) +{ + if (nents) { + /* + * Nominal case. Note subtract 1 from starting page index + * for initial _sg_iter_next() call. + */ + iter->sg = sgl; + iter->sg_pgoffset = pgoffset - 1; + iter->maxents = nents; + _sg_iter_next(iter); + } else { + /* + * Degenerate case + */ + iter->sg = NULL; + iter->sg_pgoffset = 0; + iter->maxents = 0; + } +} + +static inline dma_addr_t +sg_page_iter_dma_address(struct sg_page_iter *spi) +{ + return spi->sg->address + (spi->sg_pgoffset << PAGE_SHIFT); +} + +#define for_each_sg_page(sgl, iter, nents, pgoffset) \ + for (_sg_iter_init(sgl, iter, nents, pgoffset); \ + (iter)->sg; _sg_iter_next(iter)) + #define for_each_sg(sglist, sg, sgmax, _itr) \ for (_itr = 0, sg = (sglist); _itr < (sgmax); _itr++, sg = sg_next(sg)) |