Carl van Schaik | 6d7b2ff | 2018-07-06 22:00:55 +1000 | [diff] [blame] | 1 | /* |
| 2 | * drivers/vservices/debug.h |
| 3 | * |
| 4 | * Copyright (c) 2012-2018 General Dynamics |
| 5 | * Copyright (c) 2014 Open Kernel Labs, Inc. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify it |
| 8 | * under the terms and conditions of the GNU General Public License, |
| 9 | * version 2, as published by the Free Software Foundation. |
| 10 | * |
| 11 | * Debugging macros and support functions for Virtual Services. |
| 12 | */ |
| 13 | #ifndef _VSERVICES_DEBUG_H |
| 14 | #define _VSERVICES_DEBUG_H |
| 15 | |
| 16 | #include <linux/version.h> |
| 17 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 38) |
| 18 | #include <linux/printk.h> |
| 19 | #else |
| 20 | #ifndef no_printk |
| 21 | #define no_printk(format, args...) do { } while (0) |
| 22 | #endif |
| 23 | #endif |
| 24 | |
| 25 | #include <vservices/session.h> |
| 26 | #include "transport.h" |
| 27 | |
| 28 | #define VS_DEBUG_TRANSPORT (1 << 0) |
| 29 | #define VS_DEBUG_TRANSPORT_MESSAGES (1 << 1) |
| 30 | #define VS_DEBUG_SESSION (1 << 2) |
| 31 | #define VS_DEBUG_CLIENT (1 << 3) |
| 32 | #define VS_DEBUG_CLIENT_CORE (1 << 4) |
| 33 | #define VS_DEBUG_SERVER (1 << 5) |
| 34 | #define VS_DEBUG_SERVER_CORE (1 << 6) |
| 35 | #define VS_DEBUG_PROTOCOL (1 << 7) |
| 36 | #define VS_DEBUG_ALL 0xff |
| 37 | |
| 38 | #ifdef CONFIG_VSERVICES_DEBUG |
| 39 | |
| 40 | #define vs_debug(type, session, format, args...) \ |
| 41 | do { \ |
| 42 | if ((session)->debug_mask & (type)) \ |
| 43 | dev_dbg(&(session)->dev, format, ##args); \ |
| 44 | } while (0) |
| 45 | |
| 46 | #define vs_dev_debug(type, session, dev, format, args...) \ |
| 47 | do { \ |
| 48 | if ((session)->debug_mask & (type)) \ |
| 49 | dev_dbg(dev, format, ##args); \ |
| 50 | } while (0) |
| 51 | |
| 52 | static inline void vs_debug_dump_mbuf(struct vs_session_device *session, |
| 53 | struct vs_mbuf *mbuf) |
| 54 | { |
| 55 | if (session->debug_mask & VS_DEBUG_TRANSPORT_MESSAGES) |
| 56 | print_hex_dump_bytes("msg:", DUMP_PREFIX_OFFSET, |
| 57 | mbuf->data, mbuf->size); |
| 58 | } |
| 59 | |
| 60 | #else |
| 61 | |
| 62 | /* Dummy versions: Use no_printk to retain type/format string checking */ |
| 63 | #define vs_debug(type, session, format, args...) \ |
| 64 | do { (void)session; no_printk(format, ##args); } while(0) |
| 65 | |
| 66 | #define vs_dev_debug(type, session, dev, format, args...) \ |
| 67 | do { (void)session; (void)dev; no_printk(format, ##args); } while(0) |
| 68 | |
| 69 | static inline void vs_debug_dump_mbuf(struct vs_session_device *session, |
| 70 | struct vs_mbuf *mbuf) {} |
| 71 | |
| 72 | #endif /* CONFIG_VSERVICES_DEBUG */ |
| 73 | |
| 74 | #endif /* _VSERVICES_DEBUG_H */ |