| .. | .. |
|---|
| 1 | +/* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */ |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright 2013-2016 Freescale Semiconductor, Inc. |
|---|
| 3 | 4 | * Copyright 2016-2017 NXP |
|---|
| 4 | | - * |
|---|
| 5 | | - * Redistribution and use in source and binary forms, with or without |
|---|
| 6 | | - * modification, are permitted provided that the following conditions are met: |
|---|
| 7 | | - * * Redistributions of source code must retain the above copyright |
|---|
| 8 | | - * notice, this list of conditions and the following disclaimer. |
|---|
| 9 | | - * * Redistributions in binary form must reproduce the above copyright |
|---|
| 10 | | - * notice, this list of conditions and the following disclaimer in the |
|---|
| 11 | | - * documentation and/or other materials provided with the distribution. |
|---|
| 12 | | - * * Neither the name of Freescale Semiconductor nor the |
|---|
| 13 | | - * names of its contributors may be used to endorse or promote products |
|---|
| 14 | | - * derived from this software without specific prior written permission. |
|---|
| 15 | | - * |
|---|
| 16 | | - * |
|---|
| 17 | | - * ALTERNATIVELY, this software may be distributed under the terms of the |
|---|
| 18 | | - * GNU General Public License ("GPL") as published by the Free Software |
|---|
| 19 | | - * Foundation, either version 2 of that License or (at your option) any |
|---|
| 20 | | - * later version. |
|---|
| 21 | | - * |
|---|
| 22 | | - * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY |
|---|
| 23 | | - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|---|
| 24 | | - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
|---|
| 25 | | - * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY |
|---|
| 26 | | - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
|---|
| 27 | | - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|---|
| 28 | | - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
|---|
| 29 | | - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|---|
| 30 | | - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
|---|
| 31 | | - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|---|
| 32 | 5 | */ |
|---|
| 33 | 6 | |
|---|
| 34 | 7 | #ifndef __SG_SW_QM_H |
|---|
| .. | .. |
|---|
| 81 | 54 | * but does not have final bit; instead, returns last entry |
|---|
| 82 | 55 | */ |
|---|
| 83 | 56 | static inline struct qm_sg_entry * |
|---|
| 84 | | -sg_to_qm_sg(struct scatterlist *sg, int sg_count, |
|---|
| 57 | +sg_to_qm_sg(struct scatterlist *sg, int len, |
|---|
| 85 | 58 | struct qm_sg_entry *qm_sg_ptr, u16 offset) |
|---|
| 86 | 59 | { |
|---|
| 87 | | - while (sg_count && sg) { |
|---|
| 88 | | - dma_to_qm_sg_one(qm_sg_ptr, sg_dma_address(sg), |
|---|
| 89 | | - sg_dma_len(sg), offset); |
|---|
| 60 | + int ent_len; |
|---|
| 61 | + |
|---|
| 62 | + while (len) { |
|---|
| 63 | + ent_len = min_t(int, sg_dma_len(sg), len); |
|---|
| 64 | + |
|---|
| 65 | + dma_to_qm_sg_one(qm_sg_ptr, sg_dma_address(sg), ent_len, |
|---|
| 66 | + offset); |
|---|
| 90 | 67 | qm_sg_ptr++; |
|---|
| 91 | 68 | sg = sg_next(sg); |
|---|
| 92 | | - sg_count--; |
|---|
| 69 | + len -= ent_len; |
|---|
| 93 | 70 | } |
|---|
| 94 | 71 | return qm_sg_ptr - 1; |
|---|
| 95 | 72 | } |
|---|
| .. | .. |
|---|
| 98 | 75 | * convert scatterlist to h/w link table format |
|---|
| 99 | 76 | * scatterlist must have been previously dma mapped |
|---|
| 100 | 77 | */ |
|---|
| 101 | | -static inline void sg_to_qm_sg_last(struct scatterlist *sg, int sg_count, |
|---|
| 78 | +static inline void sg_to_qm_sg_last(struct scatterlist *sg, int len, |
|---|
| 102 | 79 | struct qm_sg_entry *qm_sg_ptr, u16 offset) |
|---|
| 103 | 80 | { |
|---|
| 104 | | - qm_sg_ptr = sg_to_qm_sg(sg, sg_count, qm_sg_ptr, offset); |
|---|
| 81 | + qm_sg_ptr = sg_to_qm_sg(sg, len, qm_sg_ptr, offset); |
|---|
| 105 | 82 | qm_sg_entry_set_f(qm_sg_ptr, qm_sg_entry_get_len(qm_sg_ptr)); |
|---|
| 106 | 83 | } |
|---|
| 107 | 84 | |
|---|