xref: /openbmc/qemu/hw/rdma/rdma_utils.h (revision 073d9f2c)
1 /*
2  * RDMA device: Debug utilities
3  *
4  * Copyright (C) 2018 Oracle
5  * Copyright (C) 2018 Red Hat Inc
6  *
7  *
8  * Authors:
9  *     Yuval Shaia <yuval.shaia@oracle.com>
10  *     Marcel Apfelbaum <marcel@redhat.com>
11  *
12  * This work is licensed under the terms of the GNU GPL, version 2 or later.
13  * See the COPYING file in the top-level directory.
14  *
15  */
16 
17 #ifndef RDMA_UTILS_H
18 #define RDMA_UTILS_H
19 
20 #include "hw/pci/pci.h"
21 #include "sysemu/dma.h"
22 #include "stdio.h"
23 
24 #define pr_info(fmt, ...) \
25     fprintf(stdout, "%s: %-20s (%3d): " fmt, "rdma",  __func__, __LINE__,\
26            ## __VA_ARGS__)
27 
28 #define pr_err(fmt, ...) \
29     fprintf(stderr, "%s: Error at %-20s (%3d): " fmt, "rdma", __func__, \
30         __LINE__, ## __VA_ARGS__)
31 
32 #ifdef PVRDMA_DEBUG
33 extern unsigned long pr_dbg_cnt;
34 
35 #define init_pr_dbg(void) \
36 { \
37     pr_dbg_cnt = 0; \
38 }
39 
40 #define pr_dbg(fmt, ...) \
41     fprintf(stdout, "%lx %ld: %-20s (%3d): " fmt, pthread_self(), pr_dbg_cnt++, \
42             __func__, __LINE__, ## __VA_ARGS__)
43 
44 #define pr_dbg_buf(title, buf, len) \
45 { \
46     int i; \
47     char *b = g_malloc0(len * 3 + 1); \
48     char b1[4]; \
49     for (i = 0; i < len; i++) { \
50         sprintf(b1, "%.2X ", buf[i] & 0x000000FF); \
51         strcat(b, b1); \
52     } \
53     pr_dbg("%s (%d): %s\n", title, len, b); \
54     g_free(b); \
55 }
56 
57 #else
58 #define init_pr_dbg(void)
59 #define pr_dbg(fmt, ...)
60 #define pr_dbg_buf(title, buf, len)
61 #endif
62 
63 void *rdma_pci_dma_map(PCIDevice *dev, dma_addr_t addr, dma_addr_t plen);
64 void rdma_pci_dma_unmap(PCIDevice *dev, void *buffer, dma_addr_t len);
65 
66 static inline void addrconf_addr_eui48(uint8_t *eui, const char *addr)
67 {
68     memcpy(eui, addr, 3);
69     eui[3] = 0xFF;
70     eui[4] = 0xFE;
71     memcpy(eui + 5, addr + 3, 3);
72     eui[0] ^= 2;
73 }
74 
75 #endif
76