Horia Geantă | 618b5dc | 2018-10-10 14:26:48 +0300 | [diff] [blame] | 1 | /* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */ |
Horia Geantă | 297b9ce | 2017-07-18 18:30:47 +0300 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2015-2016 Freescale Semiconductor, Inc. |
| 4 | * Copyright 2017 NXP |
Horia Geantă | 297b9ce | 2017-07-18 18:30:47 +0300 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #ifndef _SG_SW_QM2_H_ |
| 8 | #define _SG_SW_QM2_H_ |
| 9 | |
Roy Pledge | c89105c | 2018-07-24 09:21:29 -0500 | [diff] [blame] | 10 | #include <soc/fsl/dpaa2-fd.h> |
Horia Geantă | 297b9ce | 2017-07-18 18:30:47 +0300 | [diff] [blame] | 11 | |
| 12 | static inline void dma_to_qm_sg_one(struct dpaa2_sg_entry *qm_sg_ptr, |
| 13 | dma_addr_t dma, u32 len, u16 offset) |
| 14 | { |
| 15 | dpaa2_sg_set_addr(qm_sg_ptr, dma); |
| 16 | dpaa2_sg_set_format(qm_sg_ptr, dpaa2_sg_single); |
| 17 | dpaa2_sg_set_final(qm_sg_ptr, false); |
| 18 | dpaa2_sg_set_len(qm_sg_ptr, len); |
| 19 | dpaa2_sg_set_bpid(qm_sg_ptr, 0); |
| 20 | dpaa2_sg_set_offset(qm_sg_ptr, offset); |
| 21 | } |
| 22 | |
| 23 | /* |
| 24 | * convert scatterlist to h/w link table format |
| 25 | * but does not have final bit; instead, returns last entry |
| 26 | */ |
| 27 | static inline struct dpaa2_sg_entry * |
Horia Geantă | 059d73e | 2019-06-10 16:30:58 +0300 | [diff] [blame] | 28 | sg_to_qm_sg(struct scatterlist *sg, int len, |
Horia Geantă | 297b9ce | 2017-07-18 18:30:47 +0300 | [diff] [blame] | 29 | struct dpaa2_sg_entry *qm_sg_ptr, u16 offset) |
| 30 | { |
Horia Geantă | 059d73e | 2019-06-10 16:30:58 +0300 | [diff] [blame] | 31 | int ent_len; |
| 32 | |
| 33 | while (len) { |
| 34 | ent_len = min_t(int, sg_dma_len(sg), len); |
| 35 | |
| 36 | dma_to_qm_sg_one(qm_sg_ptr, sg_dma_address(sg), ent_len, |
| 37 | offset); |
Horia Geantă | 297b9ce | 2017-07-18 18:30:47 +0300 | [diff] [blame] | 38 | qm_sg_ptr++; |
| 39 | sg = sg_next(sg); |
Horia Geantă | 059d73e | 2019-06-10 16:30:58 +0300 | [diff] [blame] | 40 | len -= ent_len; |
Horia Geantă | 297b9ce | 2017-07-18 18:30:47 +0300 | [diff] [blame] | 41 | } |
| 42 | return qm_sg_ptr - 1; |
| 43 | } |
| 44 | |
| 45 | /* |
| 46 | * convert scatterlist to h/w link table format |
| 47 | * scatterlist must have been previously dma mapped |
| 48 | */ |
Horia Geantă | 059d73e | 2019-06-10 16:30:58 +0300 | [diff] [blame] | 49 | static inline void sg_to_qm_sg_last(struct scatterlist *sg, int len, |
Horia Geantă | 297b9ce | 2017-07-18 18:30:47 +0300 | [diff] [blame] | 50 | struct dpaa2_sg_entry *qm_sg_ptr, |
| 51 | u16 offset) |
| 52 | { |
Horia Geantă | 059d73e | 2019-06-10 16:30:58 +0300 | [diff] [blame] | 53 | qm_sg_ptr = sg_to_qm_sg(sg, len, qm_sg_ptr, offset); |
Horia Geantă | 297b9ce | 2017-07-18 18:30:47 +0300 | [diff] [blame] | 54 | dpaa2_sg_set_final(qm_sg_ptr, true); |
| 55 | } |
| 56 | |
| 57 | #endif /* _SG_SW_QM2_H_ */ |