1*4882a593Smuzhiyun /* 2*4882a593Smuzhiyun * linux/drivers/scsi/esas2r/esas2r_log.h 3*4882a593Smuzhiyun * For use with ATTO ExpressSAS R6xx SAS/SATA RAID controllers 4*4882a593Smuzhiyun * 5*4882a593Smuzhiyun * Copyright (c) 2001-2013 ATTO Technology, Inc. 6*4882a593Smuzhiyun * (mailto:linuxdrivers@attotech.com) 7*4882a593Smuzhiyun * 8*4882a593Smuzhiyun * This program is free software; you can redistribute it and/or 9*4882a593Smuzhiyun * modify it under the terms of the GNU General Public License 10*4882a593Smuzhiyun * as published by the Free Software Foundation; either version 2 11*4882a593Smuzhiyun * of the License, or (at your option) any later version. 12*4882a593Smuzhiyun * 13*4882a593Smuzhiyun * This program is distributed in the hope that it will be useful, 14*4882a593Smuzhiyun * but WITHOUT ANY WARRANTY; without even the implied warranty of 15*4882a593Smuzhiyun * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16*4882a593Smuzhiyun * GNU General Public License for more details. 17*4882a593Smuzhiyun * 18*4882a593Smuzhiyun * NO WARRANTY 19*4882a593Smuzhiyun * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR 20*4882a593Smuzhiyun * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT 21*4882a593Smuzhiyun * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, 22*4882a593Smuzhiyun * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is 23*4882a593Smuzhiyun * solely responsible for determining the appropriateness of using and 24*4882a593Smuzhiyun * distributing the Program and assumes all risks associated with its 25*4882a593Smuzhiyun * exercise of rights under this Agreement, including but not limited to 26*4882a593Smuzhiyun * the risks and costs of program errors, damage to or loss of data, 27*4882a593Smuzhiyun * programs or equipment, and unavailability or interruption of operations. 28*4882a593Smuzhiyun * 29*4882a593Smuzhiyun * DISCLAIMER OF LIABILITY 30*4882a593Smuzhiyun * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY 31*4882a593Smuzhiyun * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 32*4882a593Smuzhiyun * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND 33*4882a593Smuzhiyun * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 34*4882a593Smuzhiyun * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 35*4882a593Smuzhiyun * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED 36*4882a593Smuzhiyun * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES 37*4882a593Smuzhiyun * 38*4882a593Smuzhiyun * You should have received a copy of the GNU General Public License 39*4882a593Smuzhiyun * along with this program; if not, write to the Free Software 40*4882a593Smuzhiyun * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 41*4882a593Smuzhiyun * USA. 42*4882a593Smuzhiyun */ 43*4882a593Smuzhiyun 44*4882a593Smuzhiyun #ifndef __esas2r_log_h__ 45*4882a593Smuzhiyun #define __esas2r_log_h__ 46*4882a593Smuzhiyun 47*4882a593Smuzhiyun struct device; 48*4882a593Smuzhiyun 49*4882a593Smuzhiyun enum { 50*4882a593Smuzhiyun ESAS2R_LOG_NONE = 0, /* no events logged */ 51*4882a593Smuzhiyun ESAS2R_LOG_CRIT = 1, /* critical events */ 52*4882a593Smuzhiyun ESAS2R_LOG_WARN = 2, /* warning events */ 53*4882a593Smuzhiyun ESAS2R_LOG_INFO = 3, /* info events */ 54*4882a593Smuzhiyun ESAS2R_LOG_DEBG = 4, /* debugging events */ 55*4882a593Smuzhiyun ESAS2R_LOG_TRCE = 5, /* tracing events */ 56*4882a593Smuzhiyun 57*4882a593Smuzhiyun #ifdef ESAS2R_TRACE 58*4882a593Smuzhiyun ESAS2R_LOG_DFLT = ESAS2R_LOG_TRCE 59*4882a593Smuzhiyun #else 60*4882a593Smuzhiyun ESAS2R_LOG_DFLT = ESAS2R_LOG_WARN 61*4882a593Smuzhiyun #endif 62*4882a593Smuzhiyun }; 63*4882a593Smuzhiyun 64*4882a593Smuzhiyun __printf(2, 3) int esas2r_log(const long level, const char *format, ...); 65*4882a593Smuzhiyun __printf(3, 4) int esas2r_log_dev(const long level, 66*4882a593Smuzhiyun const struct device *dev, 67*4882a593Smuzhiyun const char *format, 68*4882a593Smuzhiyun ...); 69*4882a593Smuzhiyun int esas2r_log_hexdump(const long level, 70*4882a593Smuzhiyun const void *buf, 71*4882a593Smuzhiyun size_t len); 72*4882a593Smuzhiyun 73*4882a593Smuzhiyun /* 74*4882a593Smuzhiyun * the following macros are provided specifically for debugging and tracing 75*4882a593Smuzhiyun * messages. esas2r_debug() is provided for generic non-hardware layer 76*4882a593Smuzhiyun * debugging and tracing events. esas2r_hdebug is provided specifically for 77*4882a593Smuzhiyun * hardware layer debugging and tracing events. 78*4882a593Smuzhiyun */ 79*4882a593Smuzhiyun 80*4882a593Smuzhiyun #ifdef ESAS2R_DEBUG 81*4882a593Smuzhiyun #define esas2r_debug(f, args ...) esas2r_log(ESAS2R_LOG_DEBG, f, ## args) 82*4882a593Smuzhiyun #define esas2r_hdebug(f, args ...) esas2r_log(ESAS2R_LOG_DEBG, f, ## args) 83*4882a593Smuzhiyun #else 84*4882a593Smuzhiyun #define esas2r_debug(f, args ...) 85*4882a593Smuzhiyun #define esas2r_hdebug(f, args ...) 86*4882a593Smuzhiyun #endif /* ESAS2R_DEBUG */ 87*4882a593Smuzhiyun 88*4882a593Smuzhiyun /* 89*4882a593Smuzhiyun * the following macros are provided in order to trace the driver and catch 90*4882a593Smuzhiyun * some more serious bugs. be warned, enabling these macros may *severely* 91*4882a593Smuzhiyun * impact performance. 92*4882a593Smuzhiyun */ 93*4882a593Smuzhiyun 94*4882a593Smuzhiyun #ifdef ESAS2R_TRACE 95*4882a593Smuzhiyun #define esas2r_bugon() \ 96*4882a593Smuzhiyun do { \ 97*4882a593Smuzhiyun esas2r_log(ESAS2R_LOG_TRCE, "esas2r_bugon() called in %s:%d" \ 98*4882a593Smuzhiyun " - dumping stack and stopping kernel", __func__, \ 99*4882a593Smuzhiyun __LINE__); \ 100*4882a593Smuzhiyun dump_stack(); \ 101*4882a593Smuzhiyun BUG(); \ 102*4882a593Smuzhiyun } while (0) 103*4882a593Smuzhiyun 104*4882a593Smuzhiyun #define esas2r_trace_enter() esas2r_log(ESAS2R_LOG_TRCE, "entered %s (%s:%d)", \ 105*4882a593Smuzhiyun __func__, __FILE__, __LINE__) 106*4882a593Smuzhiyun #define esas2r_trace_exit() esas2r_log(ESAS2R_LOG_TRCE, "exited %s (%s:%d)", \ 107*4882a593Smuzhiyun __func__, __FILE__, __LINE__) 108*4882a593Smuzhiyun #define esas2r_trace(f, args ...) esas2r_log(ESAS2R_LOG_TRCE, "(%s:%s:%d): " \ 109*4882a593Smuzhiyun f, __func__, __FILE__, __LINE__, \ 110*4882a593Smuzhiyun ## args) 111*4882a593Smuzhiyun #else 112*4882a593Smuzhiyun #define esas2r_bugon() 113*4882a593Smuzhiyun #define esas2r_trace_enter() 114*4882a593Smuzhiyun #define esas2r_trace_exit() 115*4882a593Smuzhiyun #define esas2r_trace(f, args ...) 116*4882a593Smuzhiyun #endif /* ESAS2R_TRACE */ 117*4882a593Smuzhiyun 118*4882a593Smuzhiyun #endif /* __esas2r_log_h__ */ 119