1/* Driver for Realtek PCI-Express card reader 2 * Header file 3 * 4 * Copyright(c) 2009 Realtek Semiconductor Corp. All rights reserved. 5 * 6 * This program is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU General Public License as published by the 8 * Free Software Foundation; either version 2, or (at your option) any 9 * later version. 10 * 11 * This program is distributed in the hope that it will be useful, but 12 * WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License along 17 * with this program; if not, see <http://www.gnu.org/licenses/>. 18 * 19 * Author: 20 * wwang (wei_wang@realsil.com.cn) 21 * No. 450, Shenhu Road, Suzhou Industry Park, Suzhou, China 22 */ 23 24#ifndef __REALTEK_RTSX_TRACE_H 25#define __REALTEK_RTSX_TRACE_H 26 27#define _MSG_TRACE 28 29#ifdef _MSG_TRACE 30static inline char *filename(char *path) 31{ 32 char *ptr; 33 34 if (path == NULL) 35 return NULL; 36 37 ptr = path; 38 39 while (*ptr != '\0') { 40 if ((*ptr == '\\') || (*ptr == '/')) 41 path = ptr + 1; 42 43 ptr++; 44 } 45 46 return path; 47} 48 49#define TRACE_RET(chip, ret) \ 50do { \ 51 char *_file = filename(__FILE__); \ 52 RTSX_DEBUGP("[%s][%s]:[%d]\n", _file, __func__, __LINE__); \ 53 (chip)->trace_msg[(chip)->msg_idx].line = (u16)(__LINE__); \ 54 strncpy((chip)->trace_msg[(chip)->msg_idx].func, __func__, MSG_FUNC_LEN-1); \ 55 strncpy((chip)->trace_msg[(chip)->msg_idx].file, _file, MSG_FILE_LEN-1); \ 56 get_current_time((chip)->trace_msg[(chip)->msg_idx].timeval_buf, TIME_VAL_LEN); \ 57 (chip)->trace_msg[(chip)->msg_idx].valid = 1; \ 58 (chip)->msg_idx++; \ 59 if ((chip)->msg_idx >= TRACE_ITEM_CNT) { \ 60 (chip)->msg_idx = 0; \ 61 } \ 62 return ret; \ 63} while (0) 64 65#define TRACE_GOTO(chip, label) \ 66do { \ 67 char *_file = filename(__FILE__); \ 68 RTSX_DEBUGP("[%s][%s]:[%d]\n", _file, __func__, __LINE__); \ 69 (chip)->trace_msg[(chip)->msg_idx].line = (u16)(__LINE__); \ 70 strncpy((chip)->trace_msg[(chip)->msg_idx].func, __func__, MSG_FUNC_LEN-1); \ 71 strncpy((chip)->trace_msg[(chip)->msg_idx].file, _file, MSG_FILE_LEN-1); \ 72 get_current_time((chip)->trace_msg[(chip)->msg_idx].timeval_buf, TIME_VAL_LEN); \ 73 (chip)->trace_msg[(chip)->msg_idx].valid = 1; \ 74 (chip)->msg_idx++; \ 75 if ((chip)->msg_idx >= TRACE_ITEM_CNT) { \ 76 (chip)->msg_idx = 0; \ 77 } \ 78 goto label; \ 79} while (0) 80#else 81#define TRACE_RET(chip, ret) return ret 82#define TRACE_GOTO(chip, label) goto label 83#endif 84 85#ifdef CONFIG_RTS_PSTOR_DEBUG 86static inline void rtsx_dump(u8 *buf, int buf_len) 87{ 88 int i; 89 u8 tmp[16] = {0}; 90 u8 *_ptr = buf; 91 92 for (i = 0; i < ((buf_len)/16); i++) { 93 RTSX_DEBUGP("%02x %02x %02x %02x %02x %02x %02x %02x " 94 "%02x %02x %02x %02x %02x %02x %02x %02x\n", 95 _ptr[0], _ptr[1], _ptr[2], _ptr[3], _ptr[4], _ptr[5], 96 _ptr[6], _ptr[7], _ptr[8], _ptr[9], _ptr[10], _ptr[11], 97 _ptr[12], _ptr[13], _ptr[14], _ptr[15]); 98 _ptr += 16; 99 } 100 if ((buf_len) % 16) { 101 memcpy(tmp, _ptr, (buf_len) % 16); 102 _ptr = tmp; 103 RTSX_DEBUGP("%02x %02x %02x %02x %02x %02x %02x %02x " 104 "%02x %02x %02x %02x %02x %02x %02x %02x\n", 105 _ptr[0], _ptr[1], _ptr[2], _ptr[3], _ptr[4], _ptr[5], 106 _ptr[6], _ptr[7], _ptr[8], _ptr[9], _ptr[10], _ptr[11], 107 _ptr[12], _ptr[13], _ptr[14], _ptr[15]); 108 } 109} 110 111#define RTSX_DUMP(buf, buf_len) rtsx_dump((u8 *)(buf), (buf_len)) 112 113#else 114#define RTSX_DUMP(buf, buf_len) 115#endif 116 117#endif /* __REALTEK_RTSX_TRACE_H */ 118