From owner-svn-src-all@freebsd.org Mon Oct 19 11:09:53 2015 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 428C5A18725; Mon, 19 Oct 2015 11:09:53 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 19BF8990; Mon, 19 Oct 2015 11:09:53 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t9JB9qEs055284; Mon, 19 Oct 2015 11:09:52 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id t9JB9qIb055283; Mon, 19 Oct 2015 11:09:52 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <201510191109.t9JB9qIb055283@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Mon, 19 Oct 2015 11:09:52 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r289567 - head/sys/ofed/include/linux X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 19 Oct 2015 11:09:53 -0000 Author: hselasky Date: Mon Oct 19 11:09:51 2015 New Revision: 289567 URL: https://svnweb.freebsd.org/changeset/base/289567 Log: 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 Modified: head/sys/ofed/include/linux/scatterlist.h Modified: head/sys/ofed/include/linux/scatterlist.h ============================================================================== --- head/sys/ofed/include/linux/scatterlist.h Mon Oct 19 10:57:56 2015 (r289566) +++ head/sys/ofed/include/linux/scatterlist.h Mon Oct 19 11:09:51 2015 (r289567) @@ -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 * 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, u 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))