From owner-svn-src-all@freebsd.org Mon May 16 23:40:34 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 17D83B3E819; Mon, 16 May 2016 23:40:34 +0000 (UTC) (envelope-from adrian@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id E6B46135E; Mon, 16 May 2016 23:40:33 +0000 (UTC) (envelope-from adrian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u4GNeXpZ089884; Mon, 16 May 2016 23:40:33 GMT (envelope-from adrian@FreeBSD.org) Received: (from adrian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u4GNeWrj089872; Mon, 16 May 2016 23:40:32 GMT (envelope-from adrian@FreeBSD.org) Message-Id: <201605162340.u4GNeWrj089872@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: adrian set sender to adrian@FreeBSD.org using -f From: Adrian Chadd Date: Mon, 16 May 2016 23:40:32 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r299990 - in head/sys: conf dev/bhnd X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 May 2016 23:40:34 -0000 Author: adrian Date: Mon May 16 23:40:32 2016 New Revision: 299990 URL: https://svnweb.freebsd.org/changeset/base/299990 Log: [bhnd] Add logging macros to BHND. There are 5 logging levels: * ERROR * WARN * INFO * DEBUG * TRACE There are 2 logging context: * with * without device DEBUG and TRACE records are printed only if bootverbose. Logging records are printed with source code line information if acceptable logging level is DEBUG or TRACE. Submitted by: Michael Zhilin Differential Revision: https://reviews.freebsd.org/D6247 Added: head/sys/dev/bhnd/bhnd_debug.h (contents, props changed) Modified: head/sys/conf/NOTES head/sys/conf/options head/sys/dev/bhnd/bhnd.h Modified: head/sys/conf/NOTES ============================================================================== --- head/sys/conf/NOTES Mon May 16 23:37:18 2016 (r299989) +++ head/sys/conf/NOTES Mon May 16 23:40:32 2016 (r299990) @@ -3061,3 +3061,6 @@ options EM_MULTIQUEUE # Activate multiq # zlib I/O stream support # This enables support for compressed core dumps. options GZIO + +# BHND(4) drivers +options BHND_LOGLEVEL # Logging threshold level \ No newline at end of file Modified: head/sys/conf/options ============================================================================== --- head/sys/conf/options Mon May 16 23:37:18 2016 (r299989) +++ head/sys/conf/options Mon May 16 23:40:32 2016 (r299990) @@ -979,3 +979,6 @@ RANDOM_ENABLE_UMA opt_global.h # Intel em(4) driver EM_MULTIQUEUE opt_em.h + +# BHND(4) driver +BHND_LOGLEVEL opt_global.h Modified: head/sys/dev/bhnd/bhnd.h ============================================================================== --- head/sys/dev/bhnd/bhnd.h Mon May 16 23:37:18 2016 (r299989) +++ head/sys/dev/bhnd/bhnd.h Mon May 16 23:40:32 2016 (r299990) @@ -39,6 +39,7 @@ #include "bhnd_ids.h" #include "bhnd_types.h" +#include "bhnd_debug.h" #include "bhnd_bus_if.h" extern devclass_t bhnd_devclass; Added: head/sys/dev/bhnd/bhnd_debug.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sys/dev/bhnd/bhnd_debug.h Mon May 16 23:40:32 2016 (r299990) @@ -0,0 +1,192 @@ +/*- + * Copyright (c) 2016 Michael Zhilin + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any + * redistribution must be conditioned upon including a substantially + * similar Disclaimer requirement for further binary redistribution. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGES. + */ + +/* $FreeBSD$ */ + +/* + * This file provides set of macros for logging: + * - BHND_ and + * - BHND__DEV + * where LEVEL = {ERROR,WARN,INFO,DEBUG} + * + * BHND_ macros is proxies to printf call and accept same parameters, + * for instance: + * BHND_INFO("register %d has value %d", reg, val); + * + * BHND__DEV macros is proxies to device_printf call and accept + * same parameters, for instance: + * BHND_INFO_DEV(dev, "register %d has value %d", reg, val); + * + * All macros contains newline char at the end of each call + * + * ERROR, WARN, INFO messages are printed only if: + * - log message level is lower than BHND_LOGGING (logging threshold) + * + * DEBUG, TRACE messages are printed only if: + * - bootverbose and + * - log message level is lower than BHND_LOGGING (logging threshold) + * + * In addition, for debugging purpose log message contains information about + * file name and line number if BHND_LOGGING is more than BHND_INFO_LEVEL + * + * NOTE: macros starting with underscore (_) are private and should be not used + * + * To override logging (for instance, force tracing), you can use: + * - "options BHND_LOGLEVEL=BHND_TRACE_LEVEL" in kernel configuration + * - "#define BHND_LOGGING BHND_TRACE_LEVEL" in source code file + * + * NOTE: kernel config option doesn't override log level defined on file level, + * so try to avoid "#define BHND_LOGGING" + */ + +#ifndef _BHND_BHND_DEBUG_H_ +#define _BHND_BHND_DEBUG_H_ + +#include + +#include "opt_global.h" + +#define BHND_ERROR_LEVEL 0x00 +#define BHND_ERROR_MSG "ERROR" +#define BHND_WARN_LEVEL 0x10 +#define BHND_WARN_MSG "!WARN" +#define BHND_INFO_LEVEL 0x20 +#define BHND_INFO_MSG " info" +#define BHND_DEBUG_LEVEL 0x30 +#define BHND_DEBUG_MSG "debug" +#define BHND_TRACE_LEVEL 0x40 +#define BHND_TRACE_MSG "trace" + +#if !(defined(BHND_LOGGING)) +#if !(defined(BHND_LOGLEVEL)) +/* By default logging will print only INFO+ message*/ +#define BHND_LOGGING BHND_INFO_LEVEL +#else /* defined(BHND_LOGLEVEL) */ +/* Kernel configuration specifies logging level */ +#define BHND_LOGGING BHND_LOGLEVEL +#endif /* !(defined(BHND_LOGLEVEL)) */ +#endif /* !(defined(BHND_LOGGING)) */ + +#if BHND_LOGGING > BHND_INFO_LEVEL +#define _BHND_PRINT(fn, level, fmt, ...) \ + do { \ + if (level##LEVEL < BHND_DEBUG_LEVEL || bootverbose) \ + fn "[BHND " level##MSG "] %s:%d => " fmt "\n", \ + __func__, __LINE__, ## __VA_ARGS__); \ + } while(0); +#else /* BHND_LOGGING <= BHND_INFO_LEVEL */ +#define _BHND_PRINT(fn, level, fmt, ...) \ + do { \ + if (level##LEVEL < BHND_DEBUG_LEVEL || bootverbose) \ + fn "bhnd: " fmt "\n", ## __VA_ARGS__); \ + } while(0); +#endif /* BHND_LOGGING > BHND_INFO_LEVEL */ + + +#define _BHND_RAWPRINTFN printf( +#define _BHND_DEVPRINTFN(dev) device_printf(dev, + +#define _BHND_LOGPRINT(level, fmt, ...) \ + _BHND_PRINT(_BHND_RAWPRINTFN, level, fmt, ## __VA_ARGS__) +#define _BHND_DEVPRINT(dev, level, fmt, ...) \ + _BHND_PRINT(_BHND_DEVPRINTFN(dev), level, fmt, ## __VA_ARGS__) + +#define BHND_ERROR(fmt, ...) \ + _BHND_LOGPRINT(BHND_ERROR_, fmt, ## __VA_ARGS__); +#define BHND_ERROR_DEV(dev, fmt, ...) \ + _BHND_DEVPRINT(dev, BHND_ERROR_, fmt, ## __VA_ARGS__) + +#if BHND_LOGGING >= BHND_WARN_LEVEL +#define BHND_WARN(fmt, ...) \ + _BHND_LOGPRINT(BHND_WARN_, fmt, ## __VA_ARGS__) +#define BHND_WARN_DEV(dev, fmt, ...) \ + _BHND_DEVPRINT(dev, BHND_WARN_, fmt, ## __VA_ARGS__) + +#if BHND_LOGGING >= BHND_INFO_LEVEL +#define BHND_INFO(fmt, ...) \ + _BHND_LOGPRINT(BHND_INFO_, fmt, ## __VA_ARGS__) +#define BHND_INFO_DEV(dev, fmt, ...) \ + _BHND_DEVPRINT(dev, BHND_INFO_, fmt, ## __VA_ARGS__) + +#if BHND_LOGGING >= BHND_DEBUG_LEVEL +#define BHND_DEBUG(fmt, ...) \ + _BHND_LOGPRINT(BHND_DEBUG_, fmt, ## __VA_ARGS__) +#define BHND_DEBUG_DEV(dev, fmt, ...) \ + _BHND_DEVPRINT(dev, BHND_DEBUG_, fmt, ## __VA_ARGS__) + +#if BHND_LOGGING >= BHND_TRACE_LEVEL +#define BHND_TRACE(fmt, ...) \ + _BHND_LOGPRINT(BHND_TRACE_, fmt, ## __VA_ARGS__) +#define BHND_TRACE_DEV(dev, fmt, ...) \ + _BHND_DEVPRINT(dev, BHND_TRACE_, fmt, ## __VA_ARGS__) + +#endif /* BHND_LOGGING >= BHND_TRACE_LEVEL */ +#endif /* BHND_LOGGING >= BHND_DEBUG_LEVEL */ +#endif /* BHND_LOGGING >= BHND_INFO_LEVEL */ +#endif /* BHND_LOGGING >= BHND_WARN_LEVEL */ + +/* + * Empty defines without device context + */ +#if !(defined(BHND_WARN)) +#define BHND_WARN(fmt, ...); +#endif + +#if !(defined(BHND_INFO)) +#define BHND_INFO(fmt, ...); +#endif + +#if !(defined(BHND_DEBUG)) +#define BHND_DEBUG(fmt, ...); +#endif + +#if !(defined(BHND_TRACE)) +#define BHND_TRACE(fmt, ...); +#endif + +/* + * Empty defines with device context + */ +#if !(defined(BHND_WARN_DEV)) +#define BHND_WARN_DEV(dev, fmt, ...); +#endif + +#if !(defined(BHND_INFO_DEV)) +#define BHND_INFO_DEV(dev, fmt, ...); +#endif + +#if !(defined(BHND_DEBUG_DEV)) +#define BHND_DEBUG_DEV(dev, fmt, ...); +#endif + +#if !(defined(BHND_TRACE_DEV)) +#define BHND_TRACE_DEV(dev, fmt, ...); +#endif + +#endif /* _BHND_BHND_DEBUG_H_ */