Hiral Patel | 4d7007b | 2013-02-12 17:01:02 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 Cisco Systems, Inc. All rights reserved. |
| 3 | * |
| 4 | * This program is free software; you may redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; version 2 of the License. |
| 7 | * |
| 8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 9 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 10 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 11 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 12 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 13 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 14 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 15 | * SOFTWARE. |
| 16 | */ |
| 17 | |
| 18 | #ifndef __FNIC_TRACE_H__ |
| 19 | #define __FNIC_TRACE_H__ |
| 20 | |
| 21 | #define FNIC_ENTRY_SIZE_BYTES 64 |
| 22 | |
| 23 | extern ssize_t simple_read_from_buffer(void __user *to, |
| 24 | size_t count, |
| 25 | loff_t *ppos, |
| 26 | const void *from, |
| 27 | size_t available); |
| 28 | |
| 29 | extern unsigned int fnic_trace_max_pages; |
| 30 | extern int fnic_tracing_enabled; |
| 31 | extern unsigned int trace_max_pages; |
| 32 | |
| 33 | typedef struct fnic_trace_dbg { |
| 34 | int wr_idx; |
| 35 | int rd_idx; |
| 36 | unsigned long *page_offset; |
| 37 | } fnic_trace_dbg_t; |
| 38 | |
| 39 | typedef struct fnic_dbgfs { |
| 40 | int buffer_len; |
| 41 | char *buffer; |
| 42 | } fnic_dbgfs_t; |
| 43 | |
| 44 | struct fnic_trace_data { |
| 45 | union { |
| 46 | struct { |
| 47 | u32 low; |
| 48 | u32 high; |
| 49 | }; |
| 50 | u64 val; |
| 51 | } timestamp, fnaddr; |
| 52 | u32 host_no; |
| 53 | u32 tag; |
| 54 | u64 data[5]; |
| 55 | } __attribute__((__packed__)); |
| 56 | |
| 57 | typedef struct fnic_trace_data fnic_trace_data_t; |
| 58 | |
| 59 | #define FNIC_TRACE_ENTRY_SIZE \ |
| 60 | (FNIC_ENTRY_SIZE_BYTES - sizeof(fnic_trace_data_t)) |
| 61 | |
| 62 | #define FNIC_TRACE(_fn, _hn, _t, _a, _b, _c, _d, _e) \ |
| 63 | if (unlikely(fnic_tracing_enabled)) { \ |
| 64 | fnic_trace_data_t *trace_buf = fnic_trace_get_buf(); \ |
| 65 | if (trace_buf) { \ |
| 66 | if (sizeof(unsigned long) < 8) { \ |
| 67 | trace_buf->timestamp.low = jiffies; \ |
| 68 | trace_buf->fnaddr.low = (u32)(unsigned long)_fn; \ |
| 69 | } else { \ |
| 70 | trace_buf->timestamp.val = jiffies; \ |
| 71 | trace_buf->fnaddr.val = (u64)(unsigned long)_fn; \ |
| 72 | } \ |
| 73 | trace_buf->host_no = _hn; \ |
| 74 | trace_buf->tag = _t; \ |
| 75 | trace_buf->data[0] = (u64)(unsigned long)_a; \ |
| 76 | trace_buf->data[1] = (u64)(unsigned long)_b; \ |
| 77 | trace_buf->data[2] = (u64)(unsigned long)_c; \ |
| 78 | trace_buf->data[3] = (u64)(unsigned long)_d; \ |
| 79 | trace_buf->data[4] = (u64)(unsigned long)_e; \ |
| 80 | } \ |
| 81 | } |
| 82 | |
| 83 | fnic_trace_data_t *fnic_trace_get_buf(void); |
| 84 | int fnic_get_trace_data(fnic_dbgfs_t *); |
| 85 | int fnic_trace_buf_init(void); |
| 86 | void fnic_trace_free(void); |
| 87 | int fnic_trace_debugfs_init(void); |
| 88 | void fnic_trace_debugfs_terminate(void); |
| 89 | |
| 90 | #endif |