3ae43674d4cb1d08284027aa52c785362db128db
[dpdk.git] / drivers / net / szedata2 / szedata2_iobuf.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright (c) 2017 CESNET
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of CESNET nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #ifndef _SZEDATA2_IOBUF_H_
35 #define _SZEDATA2_IOBUF_H_
36
37 #include <stdint.h>
38
39 #include <rte_dev.h>
40
41 /* IBUF offsets from the beginning of the PCI resource address space. */
42 extern const uint32_t szedata2_ibuf_base_table[];
43 extern const uint32_t szedata2_ibuf_count;
44
45 /* OBUF offsets from the beginning of the PCI resource address space. */
46 extern const uint32_t szedata2_obuf_base_table[];
47 extern const uint32_t szedata2_obuf_count;
48
49 /**
50  * Macro takes pointer to pci resource structure (rsc)
51  * and returns pointer to mapped resource memory at
52  * specified offset (offset) typecast to the type (type).
53  */
54 #define SZEDATA2_PCI_RESOURCE_PTR(rsc, offset, type) \
55         ((type)(((uint8_t *)(rsc)->addr) + (offset)))
56
57 /**
58  * Get pointer to IBUF structure according to specified index.
59  *
60  * @param rsc
61  *     Pointer to base address of memory resource.
62  * @param index
63  *     Index of IBUF.
64  * @return
65  *     Pointer to IBUF structure.
66  */
67 static inline struct szedata2_ibuf *
68 ibuf_ptr_by_index(struct rte_mem_resource *rsc, uint32_t index)
69 {
70         if (index >= szedata2_ibuf_count)
71                 index = szedata2_ibuf_count - 1;
72         return SZEDATA2_PCI_RESOURCE_PTR(rsc, szedata2_ibuf_base_table[index],
73                 struct szedata2_ibuf *);
74 }
75
76 /**
77  * Get pointer to OBUF structure according to specified idnex.
78  *
79  * @param rsc
80  *     Pointer to base address of memory resource.
81  * @param index
82  *     Index of OBUF.
83  * @return
84  *     Pointer to OBUF structure.
85  */
86 static inline struct szedata2_obuf *
87 obuf_ptr_by_index(struct rte_mem_resource *rsc, uint32_t index)
88 {
89         if (index >= szedata2_obuf_count)
90                 index = szedata2_obuf_count - 1;
91         return SZEDATA2_PCI_RESOURCE_PTR(rsc, szedata2_obuf_base_table[index],
92                 struct szedata2_obuf *);
93 }
94
95 #endif /* _SZEDATA2_IOBUF_H_ */