1 /* 2 * Copyright (c) 2015-2016, Cisco Systems, Inc. All rights reserved. 3 * Copyright (c) 2015, Intel Corp., Inc. All rights reserved. 4 * 5 * This software is available to you under a choice of one of two 6 * licenses. You may choose to be licensed under the terms of the GNU 7 * General Public License (GPL) Version 2, available from the file 8 * COPYING in the main directory of this source tree, or the 9 * BSD license below: 10 * 11 * Redistribution and use in source and binary forms, with or 12 * without modification, are permitted provided that the following 13 * conditions are met: 14 * 15 * - Redistributions of source code must retain the above 16 * copyright notice, this list of conditions and the following 17 * disclaimer. 18 * 19 * - Redistributions in binary form must reproduce the above 20 * copyright notice, this list of conditions and the following 21 * disclaimer in the documentation and/or other materials 22 * provided with the distribution. 23 * 24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 31 * SOFTWARE. 32 * 33 */ 34 35 #ifndef FI_LOG_H 36 #define FI_LOG_H 37 38 #include "config.h" 39 40 #include <rdma/fabric.h> 41 #include <rdma/providers/fi_prov.h> 42 43 #ifdef __cplusplus 44 extern "C" { 45 #endif 46 47 enum fi_log_subsys { 48 FI_LOG_CORE, 49 FI_LOG_FABRIC, 50 FI_LOG_DOMAIN, 51 FI_LOG_EP_CTRL, 52 FI_LOG_EP_DATA, 53 FI_LOG_AV, 54 FI_LOG_CQ, 55 FI_LOG_EQ, 56 FI_LOG_MR, 57 FI_LOG_CNTR, 58 FI_LOG_SUBSYS_MAX 59 }; 60 61 enum fi_log_level { 62 FI_LOG_WARN, 63 FI_LOG_TRACE, 64 FI_LOG_INFO, 65 FI_LOG_DEBUG, 66 FI_LOG_MAX 67 }; 68 69 int fi_log_enabled(const struct fi_provider *prov, enum fi_log_level level, 70 enum fi_log_subsys subsys); 71 void fi_log(const struct fi_provider *prov, enum fi_log_level level, 72 enum fi_log_subsys subsys, const char *func, int line, 73 const char *fmt, ...) __attribute__ ((__format__ (__printf__, 6, 7))); 74 75 #define FI_LOG(prov, level, subsystem, ...) \ 76 do { \ 77 if (fi_log_enabled(prov, level, subsystem)) \ 78 fi_log(prov, level, subsystem, \ 79 __func__, __LINE__, __VA_ARGS__); \ 80 } while (0) 81 82 #define FI_WARN(prov, subsystem, ...) \ 83 FI_LOG(prov, FI_LOG_WARN, subsystem, __VA_ARGS__) 84 85 #define FI_TRACE(prov, subsystem, ...) \ 86 FI_LOG(prov, FI_LOG_TRACE, subsystem, __VA_ARGS__) 87 88 #define FI_INFO(prov, subsystem, ...) \ 89 FI_LOG(prov, FI_LOG_INFO, subsystem, __VA_ARGS__) 90 91 #if ENABLE_DEBUG 92 #define FI_DBG(prov, subsystem, ...) \ 93 FI_LOG(prov, FI_LOG_DEBUG, subsystem, __VA_ARGS__) 94 #define FI_DBG_TRACE(prov, subsystem, ...) \ 95 FI_LOG(prov, FI_LOG_TRACE, subsystem, __VA_ARGS__) 96 #else 97 #define FI_DBG(prov_name, subsystem, ...) \ 98 do {} while (0) 99 #define FI_DBG_TRACE(prov, subsystem, ...) \ 100 do {} while (0) 101 #endif 102 103 #define FI_WARN_ONCE(prov, subsystem, ...) ({ \ 104 static int warned; \ 105 if (!warned && fi_log_enabled(prov, FI_LOG_WARN, subsystem)) { \ 106 fi_log(prov, FI_LOG_WARN, subsystem, \ 107 __func__, __LINE__, __VA_ARGS__); \ 108 warned = 1; \ 109 } \ 110 }) 111 112 #ifdef __cplusplus 113 } 114 #endif 115 116 #endif /* FI_LOG_H */ 117