8d310e7d6743a56d11d36d5b00af5eae392a40f3
[sfrench/cifs-2.6.git] / drivers / net / ethernet / mellanox / mlx5 / core / diag / fw_tracer.h
1 /*
2  * Copyright (c) 2018, Mellanox Technologies. All rights reserved.
3  *
4  * This software is available to you under a choice of one of two
5  * licenses.  You may choose to be licensed under the terms of the GNU
6  * General Public License (GPL) Version 2, available from the file
7  * COPYING in the main directory of this source tree, or the
8  * OpenIB.org BSD license below:
9  *
10  *     Redistribution and use in source and binary forms, with or
11  *     without modification, are permitted provided that the following
12  *     conditions are met:
13  *
14  *      - Redistributions of source code must retain the above
15  *        copyright notice, this list of conditions and the following
16  *        disclaimer.
17  *
18  *      - Redistributions in binary form must reproduce the above
19  *        copyright notice, this list of conditions and the following
20  *        disclaimer in the documentation and/or other materials
21  *        provided with the distribution.
22  *
23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30  * SOFTWARE.
31  */
32
33 #ifndef __LIB_TRACER_H__
34 #define __LIB_TRACER_H__
35
36 #include <linux/mlx5/driver.h>
37 #include "mlx5_core.h"
38
39 #define STRINGS_DB_SECTIONS_NUM 8
40 #define STRINGS_DB_READ_SIZE_BYTES 256
41 #define STRINGS_DB_LEFTOVER_SIZE_BYTES 64
42 #define TRACER_BUFFER_PAGE_NUM 64
43 #define TRACER_BUFFER_CHUNK 4096
44 #define TRACE_BUFFER_SIZE_BYTE (TRACER_BUFFER_PAGE_NUM * TRACER_BUFFER_CHUNK)
45
46 #define TRACER_BLOCK_SIZE_BYTE 256
47 #define TRACES_PER_BLOCK 32
48
49 #define TRACER_MAX_PARAMS 7
50 #define MESSAGE_HASH_BITS 6
51 #define MESSAGE_HASH_SIZE BIT(MESSAGE_HASH_BITS)
52
53 #define MASK_52_7 (0x1FFFFFFFFFFF80)
54 #define MASK_6_0  (0x7F)
55
56 struct mlx5_fw_tracer {
57         struct mlx5_core_dev *dev;
58         bool owner;
59         u8   trc_ver;
60         struct workqueue_struct *work_queue;
61         struct work_struct ownership_change_work;
62         struct work_struct read_fw_strings_work;
63
64         /* Strings DB */
65         struct {
66                 u8 first_string_trace;
67                 u8 num_string_trace;
68                 u32 num_string_db;
69                 u32 base_address_out[STRINGS_DB_SECTIONS_NUM];
70                 u32 size_out[STRINGS_DB_SECTIONS_NUM];
71                 void *buffer[STRINGS_DB_SECTIONS_NUM];
72                 bool loaded;
73         } str_db;
74
75         /* Log Buffer */
76         struct {
77                 u32 pdn;
78                 void *log_buf;
79                 dma_addr_t dma;
80                 u32 size;
81                 struct mlx5_core_mkey mkey;
82                 u32 consumer_index;
83         } buff;
84
85         u64 last_timestamp;
86         struct work_struct handle_traces_work;
87         struct hlist_head hash[MESSAGE_HASH_SIZE];
88         struct list_head ready_strings_list;
89 };
90
91 struct tracer_string_format {
92         char *string;
93         int params[TRACER_MAX_PARAMS];
94         int num_of_params;
95         int last_param_num;
96         u8 event_id;
97         u32 tmsn;
98         struct hlist_node hlist;
99         struct list_head list;
100         u32 timestamp;
101         bool lost;
102 };
103
104 enum mlx5_fw_tracer_ownership_state {
105         MLX5_FW_TRACER_RELEASE_OWNERSHIP,
106         MLX5_FW_TRACER_ACQUIRE_OWNERSHIP,
107 };
108
109 enum tracer_ctrl_fields_select {
110         TRACE_STATUS = 1 << 0,
111 };
112
113 enum tracer_event_type {
114         TRACER_EVENT_TYPE_STRING,
115         TRACER_EVENT_TYPE_TIMESTAMP = 0xFF,
116         TRACER_EVENT_TYPE_UNRECOGNIZED,
117 };
118
119 enum tracing_mode {
120         TRACE_TO_MEMORY = 1 << 0,
121 };
122
123 struct tracer_timestamp_event {
124         u64        timestamp;
125         u8         unreliable;
126 };
127
128 struct tracer_string_event {
129         u32        timestamp;
130         u32        tmsn;
131         u32        tdsn;
132         u32        string_param;
133 };
134
135 struct tracer_event {
136         bool      lost_event;
137         u32       type;
138         u8        event_id;
139         union {
140                 struct tracer_string_event string_event;
141                 struct tracer_timestamp_event timestamp_event;
142         };
143 };
144
145 struct mlx5_ifc_tracer_event_bits {
146         u8         lost[0x1];
147         u8         timestamp[0x7];
148         u8         event_id[0x8];
149         u8         event_data[0x30];
150 };
151
152 struct mlx5_ifc_tracer_string_event_bits {
153         u8         lost[0x1];
154         u8         timestamp[0x7];
155         u8         event_id[0x8];
156         u8         tmsn[0xd];
157         u8         tdsn[0x3];
158         u8         string_param[0x20];
159 };
160
161 struct mlx5_ifc_tracer_timestamp_event_bits {
162         u8         timestamp7_0[0x8];
163         u8         event_id[0x8];
164         u8         urts[0x3];
165         u8         timestamp52_40[0xd];
166         u8         timestamp39_8[0x20];
167 };
168
169 struct mlx5_fw_tracer *mlx5_fw_tracer_create(struct mlx5_core_dev *dev);
170 int mlx5_fw_tracer_init(struct mlx5_fw_tracer *tracer);
171 void mlx5_fw_tracer_cleanup(struct mlx5_fw_tracer *tracer);
172 void mlx5_fw_tracer_destroy(struct mlx5_fw_tracer *tracer);
173 void mlx5_fw_tracer_event(struct mlx5_core_dev *dev, struct mlx5_eqe *eqe) { return; }
174
175 #endif