• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*-
2  * Copyright (c) 2010 Isilon Systems, Inc.
3  * Copyright (c) 2010 iX Systems, Inc.
4  * Copyright (c) 2010 Panasas, Inc.
5  * Copyright (c) 2013-2017 Mellanox Technologies, Ltd.
6  * Copyright (c) 2015 Matthew Dillon <dillon@backplane.com>
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice unmodified, this list of conditions, and the following
14  *    disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  *
30  * $FreeBSD: releng/12.2/sys/compat/linuxkpi/common/include/linux/scatterlist.h 361205 2020-05-18 09:44:26Z hselasky $
31  */
32 #ifndef	_LINUX_SCATTERLIST_H_
33 #define	_LINUX_SCATTERLIST_H_
34 
35 #include "linux/kernel.h"
36 #include "los_printf.h"
37 
38 #ifdef __cplusplus
39 #if __cplusplus
40 extern "C" {
41 #endif /* __cplusplus */
42 #endif /* __cplusplus */
43 
44 typedef unsigned long dma_addr_t;
45 typedef unsigned long ulong;
46 typedef unsigned int uint;
47 
48 typedef struct scatterlist {
49 #ifdef CONFIG_DEBUG_SG
50     ulong   sg_magic;
51 #endif
52     ulong   page_link;
53     uint    offset;
54     uint    length;
55     dma_addr_t      dma_address;
56 #ifdef CONFIG_NEED_SG_DMA_LENGTH
57     uint    dma_length;
58 #endif
59 } scatterlist_t;
60 
61 #define COMPAT_SG_MAGIC    0x87654321
62 
63 /*
64  * sg_mark_end - Mark the end of the scatterlist
65  * Param:
66  *    psg---SG entryScatterlist
67  *
68  * Description: Marks the passed in sg entry as the termination point for the psg table.
69  *              A call to sg_next() on this entry will return NULL.
70  *
71  */
sg_mark_end(scatterlist_t * psg)72 static inline void sg_mark_end(scatterlist_t *psg)
73 {
74 #ifdef CONFIG_DEBUG_SG
75     BUG_ON(psg->sg_magic != COMPAT_SG_MAGIC);
76 #endif
77     /* Set termination bit, clear potential chain bit */
78     psg->page_link |= 0x02U;
79     psg->page_link &= ~0x01U;
80 }
81 
sg_init_table(scatterlist_t * psgl,unsigned int nents)82 static inline void sg_init_table(scatterlist_t *psgl, unsigned int nents)
83 {
84     (void)memset_s(psgl, sizeof(*psgl) * nents, 0, sizeof(*psgl) * nents);
85 
86     sg_mark_end(&psgl[nents - 1]);
87 }
88 
sg_set_buf(scatterlist_t * psg,const void * buf,unsigned int buflen)89 static inline void sg_set_buf(scatterlist_t *psg, const void *buf, unsigned int buflen)
90 {
91     psg->dma_address = VMM_TO_DMA_ADDR((uintptr_t)buf);
92     psg->offset = 0;
93     psg->length = buflen;
94 }
95 
sg_init_one(scatterlist_t * psg,const void * buf,unsigned int buflen)96 static inline void sg_init_one(scatterlist_t *psg, const void *buf, unsigned int buflen)
97 {
98     sg_init_table(psg, 1);
99     sg_set_buf(psg, buf, buflen);
100 }
101 
102 #define SG_MAGIC    COMPAT_SG_MAGIC
103 #ifdef __cplusplus
104 #if __cplusplus
105 }
106 #endif /* __cplusplus */
107 #endif /* __cplusplus */
108 
109 #endif /* _LINUX_SCATTERLIST_H_ */
110