162306a36Sopenharmony_ci/*
262306a36Sopenharmony_ci *  linux/drivers/scsi/esas2r/esas2r_log.h
362306a36Sopenharmony_ci *      For use with ATTO ExpressSAS R6xx SAS/SATA RAID controllers
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci *  Copyright (c) 2001-2013 ATTO Technology, Inc.
662306a36Sopenharmony_ci *  (mailto:linuxdrivers@attotech.com)
762306a36Sopenharmony_ci *
862306a36Sopenharmony_ci * This program is free software; you can redistribute it and/or
962306a36Sopenharmony_ci * modify it under the terms of the GNU General Public License
1062306a36Sopenharmony_ci * as published by the Free Software Foundation; either version 2
1162306a36Sopenharmony_ci * of the License, or (at your option) any later version.
1262306a36Sopenharmony_ci *
1362306a36Sopenharmony_ci * This program is distributed in the hope that it will be useful,
1462306a36Sopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of
1562306a36Sopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1662306a36Sopenharmony_ci * GNU General Public License for more details.
1762306a36Sopenharmony_ci *
1862306a36Sopenharmony_ci * NO WARRANTY
1962306a36Sopenharmony_ci * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
2062306a36Sopenharmony_ci * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
2162306a36Sopenharmony_ci * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
2262306a36Sopenharmony_ci * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
2362306a36Sopenharmony_ci * solely responsible for determining the appropriateness of using and
2462306a36Sopenharmony_ci * distributing the Program and assumes all risks associated with its
2562306a36Sopenharmony_ci * exercise of rights under this Agreement, including but not limited to
2662306a36Sopenharmony_ci * the risks and costs of program errors, damage to or loss of data,
2762306a36Sopenharmony_ci * programs or equipment, and unavailability or interruption of operations.
2862306a36Sopenharmony_ci *
2962306a36Sopenharmony_ci * DISCLAIMER OF LIABILITY
3062306a36Sopenharmony_ci * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
3162306a36Sopenharmony_ci * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3262306a36Sopenharmony_ci * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
3362306a36Sopenharmony_ci * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
3462306a36Sopenharmony_ci * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
3562306a36Sopenharmony_ci * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
3662306a36Sopenharmony_ci * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
3762306a36Sopenharmony_ci *
3862306a36Sopenharmony_ci * You should have received a copy of the GNU General Public License
3962306a36Sopenharmony_ci * along with this program; if not, write to the Free Software
4062306a36Sopenharmony_ci * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
4162306a36Sopenharmony_ci * USA.
4262306a36Sopenharmony_ci */
4362306a36Sopenharmony_ci
4462306a36Sopenharmony_ci#ifndef __esas2r_log_h__
4562306a36Sopenharmony_ci#define __esas2r_log_h__
4662306a36Sopenharmony_ci
4762306a36Sopenharmony_cistruct device;
4862306a36Sopenharmony_ci
4962306a36Sopenharmony_cienum {
5062306a36Sopenharmony_ci	ESAS2R_LOG_NONE = 0,    /* no events logged */
5162306a36Sopenharmony_ci	ESAS2R_LOG_CRIT = 1,    /* critical events  */
5262306a36Sopenharmony_ci	ESAS2R_LOG_WARN = 2,    /* warning events   */
5362306a36Sopenharmony_ci	ESAS2R_LOG_INFO = 3,    /* info events      */
5462306a36Sopenharmony_ci	ESAS2R_LOG_DEBG = 4,    /* debugging events */
5562306a36Sopenharmony_ci	ESAS2R_LOG_TRCE = 5,    /* tracing events   */
5662306a36Sopenharmony_ci
5762306a36Sopenharmony_ci#ifdef ESAS2R_TRACE
5862306a36Sopenharmony_ci	ESAS2R_LOG_DFLT = ESAS2R_LOG_TRCE
5962306a36Sopenharmony_ci#else
6062306a36Sopenharmony_ci	ESAS2R_LOG_DFLT = ESAS2R_LOG_WARN
6162306a36Sopenharmony_ci#endif
6262306a36Sopenharmony_ci};
6362306a36Sopenharmony_ci
6462306a36Sopenharmony_ci__printf(2, 3) int esas2r_log(const long level, const char *format, ...);
6562306a36Sopenharmony_ci__printf(3, 4) int esas2r_log_dev(const long level,
6662306a36Sopenharmony_ci		   const struct device *dev,
6762306a36Sopenharmony_ci		   const char *format,
6862306a36Sopenharmony_ci		   ...);
6962306a36Sopenharmony_ciint esas2r_log_hexdump(const long level,
7062306a36Sopenharmony_ci		       const void *buf,
7162306a36Sopenharmony_ci		       size_t len);
7262306a36Sopenharmony_ci
7362306a36Sopenharmony_ci/*
7462306a36Sopenharmony_ci * the following macros are provided specifically for debugging and tracing
7562306a36Sopenharmony_ci * messages.  esas2r_debug() is provided for generic non-hardware layer
7662306a36Sopenharmony_ci * debugging and tracing events.  esas2r_hdebug is provided specifically for
7762306a36Sopenharmony_ci * hardware layer debugging and tracing events.
7862306a36Sopenharmony_ci */
7962306a36Sopenharmony_ci
8062306a36Sopenharmony_ci#ifdef ESAS2R_DEBUG
8162306a36Sopenharmony_ci#define esas2r_debug(f, args ...) esas2r_log(ESAS2R_LOG_DEBG, f, ## args)
8262306a36Sopenharmony_ci#define esas2r_hdebug(f, args ...) esas2r_log(ESAS2R_LOG_DEBG, f, ## args)
8362306a36Sopenharmony_ci#else
8462306a36Sopenharmony_ci#define esas2r_debug(f, args ...)
8562306a36Sopenharmony_ci#define esas2r_hdebug(f, args ...)
8662306a36Sopenharmony_ci#endif  /* ESAS2R_DEBUG */
8762306a36Sopenharmony_ci
8862306a36Sopenharmony_ci/*
8962306a36Sopenharmony_ci * the following macros are provided in order to trace the driver and catch
9062306a36Sopenharmony_ci * some more serious bugs.  be warned, enabling these macros may *severely*
9162306a36Sopenharmony_ci * impact performance.
9262306a36Sopenharmony_ci */
9362306a36Sopenharmony_ci
9462306a36Sopenharmony_ci#ifdef ESAS2R_TRACE
9562306a36Sopenharmony_ci#define esas2r_bugon() \
9662306a36Sopenharmony_ci	do { \
9762306a36Sopenharmony_ci		esas2r_log(ESAS2R_LOG_TRCE, "esas2r_bugon() called in %s:%d" \
9862306a36Sopenharmony_ci			   " - dumping stack and stopping kernel", __func__, \
9962306a36Sopenharmony_ci			   __LINE__); \
10062306a36Sopenharmony_ci		dump_stack(); \
10162306a36Sopenharmony_ci		BUG(); \
10262306a36Sopenharmony_ci	} while (0)
10362306a36Sopenharmony_ci
10462306a36Sopenharmony_ci#define esas2r_trace_enter() esas2r_log(ESAS2R_LOG_TRCE, "entered %s (%s:%d)", \
10562306a36Sopenharmony_ci					__func__, __FILE__, __LINE__)
10662306a36Sopenharmony_ci#define esas2r_trace_exit() esas2r_log(ESAS2R_LOG_TRCE, "exited %s (%s:%d)", \
10762306a36Sopenharmony_ci				       __func__, __FILE__, __LINE__)
10862306a36Sopenharmony_ci#define esas2r_trace(f, args ...) esas2r_log(ESAS2R_LOG_TRCE, "(%s:%s:%d): " \
10962306a36Sopenharmony_ci					     f, __func__, __FILE__, __LINE__, \
11062306a36Sopenharmony_ci					     ## args)
11162306a36Sopenharmony_ci#else
11262306a36Sopenharmony_ci#define esas2r_bugon()
11362306a36Sopenharmony_ci#define esas2r_trace_enter()
11462306a36Sopenharmony_ci#define esas2r_trace_exit()
11562306a36Sopenharmony_ci#define esas2r_trace(f, args ...)
11662306a36Sopenharmony_ci#endif  /* ESAS2R_TRACE */
11762306a36Sopenharmony_ci
11862306a36Sopenharmony_ci#endif  /* __esas2r_log_h__ */
119