summaryrefslogtreecommitdiffstats
path: root/drivers/staging/gasket/gasket_logging.h
blob: e288da6caa1d0dc67f7b72286ce4be201a315812 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* SPDX-License-Identifier: GPL-2.0 */
/* Common logging utilities for the Gasket driver framework.
 *
 * Copyright (C) 2018 Google, Inc.
 *
 * This software is licensed under the terms of the GNU General Public
 * License version 2, as published by the Free Software Foundation, and
 * may be copied, distributed, and modified under those terms.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

#include <linux/pci.h>
#include <linux/printk.h>

#ifndef _GASKET_LOGGING_H_
#define _GASKET_LOGGING_H_

/* Base macro; other logging can/should be built on top of this. */
#define gasket_dev_log(level, device, pci_dev, format, arg...)                 \
	if (false) {                                                           \
		if (pci_dev) {                                                 \
			dev_##level(&(pci_dev)->dev, "%s: " format "\n",       \
				__func__, ##arg);                              \
		} else {                                                       \
			gasket_nodev_log(level, format, ##arg);                \
		}                                                              \
	}

/* "No-device" logging macros. */
#define gasket_nodev_log(level, format, arg...)                                \
	if (false) pr_##level("gasket: %s: " format "\n", __func__, ##arg)

#define gasket_nodev_debug(format, arg...)                                     \
	if (false) gasket_nodev_log(debug, format, ##arg)

#define gasket_nodev_info(format, arg...)                                      \
	if (false) gasket_nodev_log(info, format, ##arg)

#define gasket_nodev_warn(format, arg...)                                      \
	if (false) gasket_nodev_log(warn, format, ##arg)

#define gasket_nodev_error(format, arg...)                                     \
	if (false) gasket_nodev_log(err, format, ##arg)

/* gasket_dev logging macros */
#define gasket_log_info(gasket_dev, format, arg...)                            \
	if (false) gasket_dev_log(info, (gasket_dev)->dev_info.device,         \
		(gasket_dev)->pci_dev, format, ##arg)

#define gasket_log_warn(gasket_dev, format, arg...)                            \
	if (false) gasket_dev_log(warn, (gasket_dev)->dev_info.device,         \
		(gasket_dev)->pci_dev, format, ##arg)

#define gasket_log_error(gasket_dev, format, arg...)                           \
	if (false) gasket_dev_log(err, (gasket_dev)->dev_info.device,          \
		(gasket_dev)->pci_dev, format, ##arg)

#define gasket_log_debug(gasket_dev, format, arg...)                           \
	if (false){                                                            \
		if ((gasket_dev)->pci_dev) {                                   \
			dev_dbg(&((gasket_dev)->pci_dev)->dev, "%s: " format   \
			"\n", __func__, ##arg);                                \
		} else {                                                       \
			gasket_nodev_log(debug, format, ##arg);                \
		}                                                              \
	}

#endif