4 * Copyright (c) 2017 CESNET
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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
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.
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.
34 #ifndef _SZEDATA2_IOBUF_H_
35 #define _SZEDATA2_IOBUF_H_
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;
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;
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).
54 #define SZEDATA2_PCI_RESOURCE_PTR(rsc, offset, type) \
55 ((type)(((uint8_t *)(rsc)->addr) + (offset)))
58 * Get pointer to IBUF structure according to specified index.
61 * Pointer to base address of memory resource.
65 * Pointer to IBUF structure.
67 static inline struct szedata2_ibuf *
68 ibuf_ptr_by_index(struct rte_mem_resource *rsc, uint32_t index)
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 *);
77 * Get pointer to OBUF structure according to specified idnex.
80 * Pointer to base address of memory resource.
84 * Pointer to OBUF structure.
86 static inline struct szedata2_obuf *
87 obuf_ptr_by_index(struct rte_mem_resource *rsc, uint32_t index)
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 *);
95 #endif /* _SZEDATA2_IOBUF_H_ */