| 1 |
/* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 |
/* Copyright 2012 Cisco Systems, Inc. All rights reserved. */ |
| 3 |
|
| 4 |
#ifndef __FNIC_TRACE_H__ |
| 5 |
#define __FNIC_TRACE_H__ |
| 6 |
|
| 7 |
#define FNIC_ENTRY_SIZE_BYTES 64 |
| 8 |
#define FC_TRC_SIZE_BYTES 256 |
| 9 |
#define FC_TRC_HEADER_SIZE sizeof(struct fc_trace_hdr) |
| 10 |
|
| 11 |
/* |
| 12 |
* Fisrt bit of FNIC_FC_RECV and FNIC_FC_SEND is used to represent the type |
| 13 |
* of frame 1 => Eth frame, 0=> FC frame |
| 14 |
*/ |
| 15 |
|
| 16 |
#define FNIC_FC_RECV 0x52 /* Character R */ |
| 17 |
#define FNIC_FC_SEND 0x54 /* Character T */ |
| 18 |
#define FNIC_FC_LE 0x4C /* Character L */ |
| 19 |
|
| 20 |
extern ssize_t simple_read_from_buffer(void __user *to, |
| 21 |
size_t count, |
| 22 |
loff_t *ppos, |
| 23 |
const void *from, |
| 24 |
size_t available); |
| 25 |
|
| 26 |
extern unsigned int fnic_trace_max_pages; |
| 27 |
extern int fnic_tracing_enabled; |
| 28 |
extern unsigned int trace_max_pages; |
| 29 |
|
| 30 |
extern unsigned int fnic_fc_trace_max_pages; |
| 31 |
extern int fnic_fc_tracing_enabled; |
| 32 |
extern int fnic_fc_trace_cleared; |
| 33 |
|
| 34 |
typedef struct fnic_trace_dbg { |
| 35 |
int wr_idx; |
| 36 |
int rd_idx; |
| 37 |
unsigned long *page_offset; |
| 38 |
} fnic_trace_dbg_t; |
| 39 |
|
| 40 |
typedef struct fnic_dbgfs { |
| 41 |
int buffer_len; |
| 42 |
char *buffer; |
| 43 |
} fnic_dbgfs_t; |
| 44 |
|
| 45 |
struct fnic_trace_data { |
| 46 |
union { |
| 47 |
struct { |
| 48 |
u32 low; |
| 49 |
u32 high; |
| 50 |
}; |
| 51 |
u64 val; |
| 52 |
} timestamp, fnaddr; |
| 53 |
u32 host_no; |
| 54 |
u32 tag; |
| 55 |
u64 data[5]; |
| 56 |
} __attribute__((__packed__)); |
| 57 |
|
| 58 |
typedef struct fnic_trace_data fnic_trace_data_t; |
| 59 |
|
| 60 |
struct fc_trace_hdr { |
| 61 |
struct timespec64 time_stamp; |
| 62 |
u32 host_no; |
| 63 |
u8 frame_type; |
| 64 |
u8 frame_len; |
| 65 |
} __attribute__((__packed__)); |
| 66 |
|
| 67 |
#define FC_TRACE_ADDRESS(a) \ |
| 68 |
((unsigned long)(a) + sizeof(struct fc_trace_hdr)) |
| 69 |
|
| 70 |
#define FNIC_TRACE_ENTRY_SIZE \ |
| 71 |
(FNIC_ENTRY_SIZE_BYTES - sizeof(fnic_trace_data_t)) |
| 72 |
|
| 73 |
#define FNIC_TRACE(_fn, _hn, _t, _a, _b, _c, _d, _e) \ |
| 74 |
if (unlikely(fnic_tracing_enabled)) { \ |
| 75 |
fnic_trace_data_t *trace_buf = fnic_trace_get_buf(); \ |
| 76 |
if (trace_buf) { \ |
| 77 |
if (sizeof(unsigned long) < 8) { \ |
| 78 |
trace_buf->timestamp.low = jiffies; \ |
| 79 |
trace_buf->fnaddr.low = (u32)(unsigned long)_fn; \ |
| 80 |
} else { \ |
| 81 |
trace_buf->timestamp.val = jiffies; \ |
| 82 |
trace_buf->fnaddr.val = (u64)(unsigned long)_fn; \ |
| 83 |
} \ |
| 84 |
trace_buf->host_no = _hn; \ |
| 85 |
trace_buf->tag = _t; \ |
| 86 |
trace_buf->data[0] = (u64)(unsigned long)_a; \ |
| 87 |
trace_buf->data[1] = (u64)(unsigned long)_b; \ |
| 88 |
trace_buf->data[2] = (u64)(unsigned long)_c; \ |
| 89 |
trace_buf->data[3] = (u64)(unsigned long)_d; \ |
| 90 |
trace_buf->data[4] = (u64)(unsigned long)_e; \ |
| 91 |
} \ |
| 92 |
} |
| 93 |
|
| 94 |
fnic_trace_data_t *fnic_trace_get_buf(void); |
| 95 |
int fnic_get_trace_data(fnic_dbgfs_t *); |
| 96 |
int fnic_trace_buf_init(void); |
| 97 |
void fnic_trace_free(void); |
| 98 |
int fnic_debugfs_init(void); |
| 99 |
void fnic_debugfs_terminate(void); |
| 100 |
void fnic_trace_debugfs_init(void); |
| 101 |
void fnic_trace_debugfs_terminate(void); |
| 102 |
|
| 103 |
/* Fnic FC CTLR Trace releated function */ |
| 104 |
int fnic_fc_trace_init(void); |
| 105 |
void fnic_fc_trace_free(void); |
| 106 |
int fnic_fc_trace_set_data(u32 host_no, u8 frame_type, |
| 107 |
char *frame, u32 fc_frame_len); |
| 108 |
int fnic_fc_trace_get_data(fnic_dbgfs_t *fnic_dbgfs_prt, u8 rdata_flag); |
| 109 |
void copy_and_format_trace_data(struct fc_trace_hdr *tdata, |
| 110 |
fnic_dbgfs_t *fnic_dbgfs_prt, |
| 111 |
int *len, u8 rdata_flag); |
| 112 |
void fnic_fc_trace_debugfs_init(void); |
| 113 |
void fnic_fc_trace_debugfs_terminate(void); |
| 114 |
|
| 115 |
#endif |