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