18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci *	Copyright IBM Corp. 2001, 2007
48c2ecf20Sopenharmony_ci *	Authors:	Peter Tiedemann (ptiedem@de.ibm.com)
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#ifndef _CTCM_DBUG_H_
98c2ecf20Sopenharmony_ci#define _CTCM_DBUG_H_
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci/*
128c2ecf20Sopenharmony_ci * Debug Facility stuff
138c2ecf20Sopenharmony_ci */
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#include <asm/debug.h>
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#ifdef DEBUG
188c2ecf20Sopenharmony_ci #define do_debug 1
198c2ecf20Sopenharmony_ci#else
208c2ecf20Sopenharmony_ci #define do_debug 0
218c2ecf20Sopenharmony_ci#endif
228c2ecf20Sopenharmony_ci#ifdef DEBUGCCW
238c2ecf20Sopenharmony_ci #define do_debug_ccw 1
248c2ecf20Sopenharmony_ci #define DEBUGDATA 1
258c2ecf20Sopenharmony_ci#else
268c2ecf20Sopenharmony_ci #define do_debug_ccw 0
278c2ecf20Sopenharmony_ci#endif
288c2ecf20Sopenharmony_ci#ifdef DEBUGDATA
298c2ecf20Sopenharmony_ci #define do_debug_data 1
308c2ecf20Sopenharmony_ci#else
318c2ecf20Sopenharmony_ci #define do_debug_data 0
328c2ecf20Sopenharmony_ci#endif
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci/* define dbf debug levels similar to kernel msg levels */
358c2ecf20Sopenharmony_ci#define	CTC_DBF_ALWAYS	0	/* always print this 			*/
368c2ecf20Sopenharmony_ci#define	CTC_DBF_EMERG	0	/* system is unusable			*/
378c2ecf20Sopenharmony_ci#define	CTC_DBF_ALERT	1	/* action must be taken immediately	*/
388c2ecf20Sopenharmony_ci#define	CTC_DBF_CRIT	2	/* critical conditions			*/
398c2ecf20Sopenharmony_ci#define	CTC_DBF_ERROR	3	/* error conditions			*/
408c2ecf20Sopenharmony_ci#define	CTC_DBF_WARN	4	/* warning conditions			*/
418c2ecf20Sopenharmony_ci#define	CTC_DBF_NOTICE	5	/* normal but significant condition	*/
428c2ecf20Sopenharmony_ci#define	CTC_DBF_INFO	5	/* informational			*/
438c2ecf20Sopenharmony_ci#define	CTC_DBF_DEBUG	6	/* debug-level messages			*/
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_cienum ctcm_dbf_names {
468c2ecf20Sopenharmony_ci	CTCM_DBF_SETUP,
478c2ecf20Sopenharmony_ci	CTCM_DBF_ERROR,
488c2ecf20Sopenharmony_ci	CTCM_DBF_TRACE,
498c2ecf20Sopenharmony_ci	CTCM_DBF_MPC_SETUP,
508c2ecf20Sopenharmony_ci	CTCM_DBF_MPC_ERROR,
518c2ecf20Sopenharmony_ci	CTCM_DBF_MPC_TRACE,
528c2ecf20Sopenharmony_ci	CTCM_DBF_INFOS	/* must be last element */
538c2ecf20Sopenharmony_ci};
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_cistruct ctcm_dbf_info {
568c2ecf20Sopenharmony_ci	char name[DEBUG_MAX_NAME_LEN];
578c2ecf20Sopenharmony_ci	int pages;
588c2ecf20Sopenharmony_ci	int areas;
598c2ecf20Sopenharmony_ci	int len;
608c2ecf20Sopenharmony_ci	int level;
618c2ecf20Sopenharmony_ci	debug_info_t *id;
628c2ecf20Sopenharmony_ci};
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ciextern struct ctcm_dbf_info ctcm_dbf[CTCM_DBF_INFOS];
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ciint ctcm_register_dbf_views(void);
678c2ecf20Sopenharmony_civoid ctcm_unregister_dbf_views(void);
688c2ecf20Sopenharmony_civoid ctcm_dbf_longtext(enum ctcm_dbf_names dbf_nix, int level, char *text, ...);
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_cistatic inline const char *strtail(const char *s, int n)
718c2ecf20Sopenharmony_ci{
728c2ecf20Sopenharmony_ci	int l = strlen(s);
738c2ecf20Sopenharmony_ci	return (l > n) ? s + (l - n) : s;
748c2ecf20Sopenharmony_ci}
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ci#define CTCM_FUNTAIL strtail((char *)__func__, 16)
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci#define CTCM_DBF_TEXT(name, level, text) \
798c2ecf20Sopenharmony_ci	do { \
808c2ecf20Sopenharmony_ci		debug_text_event(ctcm_dbf[CTCM_DBF_##name].id, level, text); \
818c2ecf20Sopenharmony_ci	} while (0)
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci#define CTCM_DBF_HEX(name, level, addr, len) \
848c2ecf20Sopenharmony_ci	do { \
858c2ecf20Sopenharmony_ci		debug_event(ctcm_dbf[CTCM_DBF_##name].id, \
868c2ecf20Sopenharmony_ci					level, (void *)(addr), len); \
878c2ecf20Sopenharmony_ci	} while (0)
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ci#define CTCM_DBF_TEXT_(name, level, text...) \
908c2ecf20Sopenharmony_ci	ctcm_dbf_longtext(CTCM_DBF_##name, level, text)
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci/*
938c2ecf20Sopenharmony_ci * cat : one of {setup, mpc_setup, trace, mpc_trace, error, mpc_error}.
948c2ecf20Sopenharmony_ci * dev : netdevice with valid name field.
958c2ecf20Sopenharmony_ci * text: any text string.
968c2ecf20Sopenharmony_ci */
978c2ecf20Sopenharmony_ci#define CTCM_DBF_DEV_NAME(cat, dev, text) \
988c2ecf20Sopenharmony_ci	do { \
998c2ecf20Sopenharmony_ci		CTCM_DBF_TEXT_(cat, CTC_DBF_INFO, "%s(%s) :- %s", \
1008c2ecf20Sopenharmony_ci			CTCM_FUNTAIL, dev->name, text); \
1018c2ecf20Sopenharmony_ci	} while (0)
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci#define MPC_DBF_DEV_NAME(cat, dev, text) \
1048c2ecf20Sopenharmony_ci	do { \
1058c2ecf20Sopenharmony_ci		CTCM_DBF_TEXT_(MPC_##cat, CTC_DBF_INFO, "%s(%s) := %s", \
1068c2ecf20Sopenharmony_ci			CTCM_FUNTAIL, dev->name, text); \
1078c2ecf20Sopenharmony_ci	} while (0)
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ci#define CTCMY_DBF_DEV_NAME(cat, dev, text) \
1108c2ecf20Sopenharmony_ci	do { \
1118c2ecf20Sopenharmony_ci		if (IS_MPCDEV(dev)) \
1128c2ecf20Sopenharmony_ci			MPC_DBF_DEV_NAME(cat, dev, text); \
1138c2ecf20Sopenharmony_ci		else \
1148c2ecf20Sopenharmony_ci			CTCM_DBF_DEV_NAME(cat, dev, text); \
1158c2ecf20Sopenharmony_ci	} while (0)
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ci/*
1188c2ecf20Sopenharmony_ci * cat : one of {setup, mpc_setup, trace, mpc_trace, error, mpc_error}.
1198c2ecf20Sopenharmony_ci * dev : netdevice.
1208c2ecf20Sopenharmony_ci * text: any text string.
1218c2ecf20Sopenharmony_ci */
1228c2ecf20Sopenharmony_ci#define CTCM_DBF_DEV(cat, dev, text) \
1238c2ecf20Sopenharmony_ci	do { \
1248c2ecf20Sopenharmony_ci		CTCM_DBF_TEXT_(cat, CTC_DBF_INFO, "%s(%p) :-: %s", \
1258c2ecf20Sopenharmony_ci			CTCM_FUNTAIL, dev, text); \
1268c2ecf20Sopenharmony_ci	} while (0)
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ci#define MPC_DBF_DEV(cat, dev, text) \
1298c2ecf20Sopenharmony_ci	do { \
1308c2ecf20Sopenharmony_ci		CTCM_DBF_TEXT_(MPC_##cat, CTC_DBF_INFO, "%s(%p) :=: %s", \
1318c2ecf20Sopenharmony_ci			CTCM_FUNTAIL, dev, text); \
1328c2ecf20Sopenharmony_ci	} while (0)
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_ci#define CTCMY_DBF_DEV(cat, dev, text) \
1358c2ecf20Sopenharmony_ci	do { \
1368c2ecf20Sopenharmony_ci		if (IS_MPCDEV(dev)) \
1378c2ecf20Sopenharmony_ci			MPC_DBF_DEV(cat, dev, text); \
1388c2ecf20Sopenharmony_ci		else \
1398c2ecf20Sopenharmony_ci			CTCM_DBF_DEV(cat, dev, text); \
1408c2ecf20Sopenharmony_ci	} while (0)
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_ci#endif
143