TAS
TCP Acceleration as an OS Service
dma.h
1 /*
2  * Copyright 2019 University of Washington, Max Planck Institute for
3  * Software Systems, and The University of Texas at Austin
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining
6  * a copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sublicense, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
25 #ifndef DMA_H_
26 #define DMA_H_
27 
28 #include <stddef.h>
29 #include <stdint.h>
30 
31 #include <rte_config.h>
32 #include <rte_memcpy.h>
33 #include <tas.h>
34 
35 #ifdef DATAPLANE_STATS
36 void dma_dump_stats(void);
37 #endif
38 
39 static inline void dma_read(uintptr_t addr, size_t len, void *buf)
40 {
41  assert(addr + len >= addr && addr + len <= config.shm_len);
42 
43  rte_memcpy(buf, (uint8_t *) tas_shm + addr, len);
44 
45 #ifdef FLEXNIC_TRACE_DMA
46  struct flexnic_trace_entry_dma evt = {
47  .addr = addr,
48  .len = len,
49  };
50  trace_event2(FLEXNIC_TRACE_EV_DMARD, sizeof(evt), &evt,
51  MIN(len, UINT16_MAX - sizeof(evt)), buf);
52 #endif
53 }
54 
55 static inline void dma_write(uintptr_t addr, size_t len, const void *buf)
56 {
57  assert(addr + len >= addr && addr + len <= config.shm_len);
58 
59  rte_memcpy((uint8_t *) tas_shm + addr, buf, len);
60 
61 #ifdef FLEXNIC_TRACE_DMA
62  struct flexnic_trace_entry_dma evt = {
63  .addr = addr,
64  .len = len,
65  };
66  trace_event2(FLEXNIC_TRACE_EV_DMAWR, sizeof(evt), &evt,
67  MIN(len, UINT16_MAX - sizeof(evt)), buf);
68 #endif
69 }
70 
71 static inline void *dma_pointer(uintptr_t addr, size_t len)
72 {
73  /* validate address */
74  assert(addr + len >= addr && addr + len <= config.shm_len);
75 
76  return (uint8_t *) tas_shm + addr;
77 }
78 
79 #endif /* ndef DMA_H_ */
Definition: tas_trace.h:55