aboutsummaryrefslogtreecommitdiff
path: root/sys/dev/iwx/if_iwx_debug.c
blob: 6a2bf32ad738423152de9ecba260758b03306669 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
/*-
 * SPDX-License-Identifier: BSD-2-Clause
 *
 * Copyright (c) 2015 Adrian Chadd <adrian@FreeBSD.org>
 * Copyright (c) 2025 The FreeBSD Foundation
 *
 * Portions of this software were developed by Tom Jones <thj@FreeBSD.org>
 * under sponsorship from the FreeBSD Foundation.
 */

#include <sys/param.h>
#include <sys/systm.h>
#include <net/ethernet.h>

#include <net80211/ieee80211.h>

#define le32_to_cpup(_a_) (le32toh(*(const uint32_t *)(_a_)))

#include <dev/iwx/if_iwxreg.h>
#include <dev/iwx/if_iwx_debug.h>

static uint16_t bbl_idx = 0;
static uint32_t bbl_seq = 0;
static uint8_t bbl_compress = 1;

static const char *
iwx_bbl_to_str(int type)
{
	switch(type) {
	case IWX_BBL_PKT_TX:
		return ("IWX_BBL_PKT_TX");
	case IWX_BBL_PKT_RX:
		return ("IWX_BBL_PKT_RX");
	case IWX_BBL_PKT_DUP:
		return ("IWX_BBL_PKT_DUP");
	case IWX_BBL_CMD_TX:
		return ("IWX_BBL_CMD_TX");
	case IWX_BBL_CMD_RX:
		return ("IWX_BBL_CMD_RX");
	case IWX_BBL_ANY:
		return ("IWX_BBL_ANY");
	default:
		return ("ERROR");
	}
}

static const char *
get_label(struct opcode_label *table, uint8_t opcode)
{
	struct opcode_label *op = table;
	while(op->label != NULL) {
		if (op->opcode == opcode)
			return op->label;
		op++;
	}
	return "NOT FOUND IN TABLE";
}

static struct opcode_label *
get_table(uint8_t group)
{
	switch (group)
	{
	case IWX_LEGACY_GROUP:
	case IWX_LONG_GROUP:
		return legacy_opcodes;
		break;
	case IWX_SYSTEM_GROUP:
		return system_opcodes;
		break;
	case IWX_MAC_CONF_GROUP:
		return macconf_opcodes;
		break;
	case IWX_DATA_PATH_GROUP:
		return data_opcodes;
		break;
	case IWX_REGULATORY_AND_NVM_GROUP:
		return reg_opcodes;
		break;
	case IWX_PHY_OPS_GROUP:
		return phyops_opcodes;
		break;
	case IWX_PROT_OFFLOAD_GROUP:
		break;
	}
	return NULL;
}

void
print_opcode(const char *func, int line, int type, uint32_t code)
{
	int print = print_mask & type;
	uint8_t opcode = iwx_cmd_opcode(code);
	uint8_t group = iwx_cmd_groupid(code);

	struct opcode_label *table = get_table(group);
	if (table == NULL) {
		printf("Couldn't find opcode table for 0x%08x", code);
		return;
	}

	for (int i = 0; i < nitems(print_codes); i++)
		if (print_codes[i][0] == group && print_codes[i][1] == opcode)
			print = 1;

	if (print) {
		printf("%s:%d %s\t%s\t%s\t(0x%08x)\n", func, line,
		    iwx_bbl_to_str(type), get_label(command_group, group),
		    get_label(table, opcode), code);
	}
}

void
iwx_dump_cmd(uint32_t id, void *data, uint16_t len, const char *str, int type)
{
	int dump = dump_mask & type;
	uint8_t opcode = iwx_cmd_opcode(id);
	uint8_t group = iwx_cmd_groupid(id);

	for (int i = 0; i < nitems(dump_codes); i++)
		if (dump_codes[i][0] == group && dump_codes[i][1] == opcode)
			dump = 1;

	if (dump)
		hexdump(data, len, str, 0);
}

void 
iwx_bbl_add_entry(uint32_t code, int type, int ticks)
{
	/* 
	 * Compress together repeated notifications, but increment the sequence
	 * number so we can track things processing.
	 */
	if (bbl_compress && (iwx_bb_log[bbl_idx].code == code &&
	    iwx_bb_log[bbl_idx].type == type)) {
		iwx_bb_log[bbl_idx].count++;
		iwx_bb_log[bbl_idx].seq = bbl_seq++;
		iwx_bb_log[bbl_idx].ticks = ticks;
		return;
	}

	if (bbl_idx++ > IWX_BBL_ENTRIES) {
#if 0
		printf("iwx bbl roll over: type %d (%lu)\n", type, code);
#endif
		bbl_idx = 0;	
	}	
	iwx_bb_log[bbl_idx].code = code;
	iwx_bb_log[bbl_idx].type = type;
	iwx_bb_log[bbl_idx].seq = bbl_seq++;
	iwx_bb_log[bbl_idx].ticks = ticks;
	iwx_bb_log[bbl_idx].count = 1;
}

static void
iwx_bbl_print_entry(struct iwx_bbl_entry *e)
{
	uint8_t opcode = iwx_cmd_opcode(e->code);
	uint8_t group = iwx_cmd_groupid(e->code);

	switch(e->type) {
	case IWX_BBL_PKT_TX:
		printf("pkt     ");
		printf("seq %08d\t pkt len %u",
			e->seq, e->code);
		break;
		printf("pkt dup ");
		printf("seq %08d\t dup count %u",
			e->seq, e->code);
		break;
	case IWX_BBL_CMD_TX:
		printf("tx ->   ");
		printf("seq %08d\tcode 0x%08x (%s:%s)",
			e->seq, e->code, get_label(command_group, group),
			get_label(get_table(group), opcode));
		break;
	case IWX_BBL_CMD_RX:
		printf("rx      ");
		printf("seq %08d\tcode 0x%08x (%s:%s)",
			e->seq, e->code, get_label(command_group, group),
			get_label(get_table(group), opcode));
		break;
	}
	if (e->count > 1)
		printf(" (count %d)", e->count);
	printf("\n");
}

void
iwx_bbl_print_log(void)
{
	int start = -1;

	start = bbl_idx+1;
	if (start > IWX_BBL_ENTRIES-1)
		start = 0;

	for (int i = start; i < IWX_BBL_ENTRIES; i++) {
		struct iwx_bbl_entry *e = &iwx_bb_log[i];
		printf("bbl entry %05d %05d: ", i, e->ticks);
		iwx_bbl_print_entry(e);
	}
	for (int i = 0; i < start; i++) {
		struct iwx_bbl_entry *e = &iwx_bb_log[i];
		printf("bbl entry %05d %05d: ", i, e->ticks);
		iwx_bbl_print_entry(e);
	}
	printf("iwx bblog index %d seq %d\n", bbl_idx, bbl_seq);
}

void
print_ratenflags(const char *func, int line, uint32_t flags, int ver)
{
	printf("%s:%d\n\t flags 0x%08x ", func, line, flags);

	if (ver >= 2) {
		printf(" rate_n_flags version 2\n");

		uint32_t type = (flags & IWX_RATE_MCS_MOD_TYPE_MSK) >> IWX_RATE_MCS_MOD_TYPE_POS;

		switch(type)
		{
		case 0:
			printf("\t(0) Legacy CCK: ");
			switch (flags & IWX_RATE_LEGACY_RATE_MSK)
			{
			case 0:
				printf("(0) 0xa - 1 Mbps\n");
				break;
			case 1:
				printf("(1) 0x14 - 2 Mbps\n");
				break;
			case 2:
				printf("(2) 0x37 - 5.5 Mbps\n");
				break;
			case 3:
				printf("(3) 0x6e - 11 nbps\n");
				break;
			}
			break;
		case 1:
			printf("\t(1) Legacy OFDM \n");
			switch (flags & IWX_RATE_LEGACY_RATE_MSK)
			{
			case 0:
				printf("(0) 6 Mbps\n");
				break;
			case 1:
				printf("(1) 9 Mbps\n");
				break;
			case 2:
				printf("(2) 12 Mbps\n");
				break;
			case 3:
				printf("(3) 18 Mbps\n");
				break;
			case 4:
				printf("(4) 24 Mbps\n");
				break;
			case 5:
				printf("(5) 36 Mbps\n");
				break;
			case 6:
				printf("(6) 48 Mbps\n");
				break;
			case 7:
				printf("(7) 54 Mbps\n");
				break;
			}
			break;
		case 2:
			printf("\t(2) High-throughput (HT)\n");
			break;
		case 3:
			printf("\t(3) Very High-throughput (VHT) \n");
			break;
		case 4:
			printf("\t(4) High-efficiency (HE)\n");
			break;
		case 5:
			printf("\t(5) Extremely High-throughput (EHT)\n");
			break;
		default:
			printf("invalid\n");
		}

		/* Not a legacy rate. */
		if (type > 1) {
			printf("\tMCS %d ", IWX_RATE_HT_MCS_INDEX(flags));
			switch((flags & IWX_RATE_MCS_CHAN_WIDTH_MSK) >> IWX_RATE_MCS_CHAN_WIDTH_POS)
			{
			case 0:
				printf("20MHz ");
				break;
			case 1:
				printf("40MHz ");
				break;
			case 2:
				printf("80MHz ");
				break;
			case 3:
				printf("160MHz ");
				break;
			case 4:
				printf("320MHz ");
				break;

			}
			printf("antennas: (%s|%s) ",
				flags & (1 << 14) ? "A" : " ",
				flags & (1 << 15) ? "B" : " ");
			if (flags & (1 << 16))
				printf("ldpc ");
			printf("\n");
		}
	} else {
		printf("%s:%d rate_n_flags versions other than < 2 not implemented",
		    __func__, __LINE__);
	}
}