summaryrefslogtreecommitdiffstats
path: root/drivers/staging/agnx/debug.h
blob: 7947f327a2147903df2e4ad4d643ff170eed4031 (plain)
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
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
#ifndef AGNX_DEBUG_H_
#define AGNX_DEBUG_H_

#include "agnx.h"
#include "phy.h"
#include "sta.h"
#include "xmit.h"

#define AGNX_TRACE              printk(KERN_ERR PFX "function:%s line:%d\n", __func__, __LINE__)

#define PRINTK_LE16(prefix, var)	printk(KERN_DEBUG PFX #prefix ": " #var " 0x%.4x\n", le16_to_cpu(var))
#define PRINTK_LE32(prefix, var)	printk(KERN_DEBUG PFX #prefix ": " #var " 0x%.8x\n", le32_to_cpu(var))
#define PRINTK_U8(prefix, var) 		printk(KERN_DEBUG PFX #prefix ": " #var " 0x%.2x\n", var)
#define PRINTK_BE16(prefix, var)	printk(KERN_DEBUG PFX #prefix ": " #var " 0x%.4x\n", be16_to_cpu(var))
#define PRINTK_BE32(prefix, var)	printk(KERN_DEBUG PFX #prefix ": " #var " 0x%.8x\n", be32_to_cpu(var))
#define PRINTK_BITS(prefix, field)    	printk(KERN_DEBUG PFX #prefix ": " #field ": 0x%x\n", (reg & field) >> field##_SHIFT)

static inline void agnx_bug(char *reason)
{
	printk(KERN_ERR PFX "%s\n", reason);
	BUG();
}

static inline void agnx_print_desc(struct agnx_desc *desc)
{
	u32 reg = be32_to_cpu(desc->frag);

	PRINTK_BITS(DESC, PACKET_LEN);

	if (reg & FIRST_FRAG) {
		PRINTK_BITS(DESC, FIRST_PACKET_MASK);
		PRINTK_BITS(DESC, FIRST_RESERV2);
		PRINTK_BITS(DESC, FIRST_TKIP_ERROR);
		PRINTK_BITS(DESC, FIRST_TKIP_PACKET);
		PRINTK_BITS(DESC, FIRST_RESERV1);
		PRINTK_BITS(DESC, FIRST_FRAG_LEN);
	} else {
		PRINTK_BITS(DESC, SUB_RESERV2);
		PRINTK_BITS(DESC, SUB_TKIP_ERROR);
		PRINTK_BITS(DESC, SUB_TKIP_PACKET);
		PRINTK_BITS(DESC, SUB_RESERV1);
		PRINTK_BITS(DESC, SUB_FRAG_LEN);
	}

	PRINTK_BITS(DESC, FIRST_FRAG);
	PRINTK_BITS(DESC, LAST_FRAG);
	PRINTK_BITS(DESC, OWNER);
}


static inline void dump_ieee80211b_phy_hdr(__be32 _11b0, __be32 _11b1)
{

}

static inline void agnx_print_hdr(struct agnx_hdr *hdr)
{
	u32 reg;
	int i;

	reg = be32_to_cpu(hdr->reg0);
	PRINTK_BITS(HDR, RTS);
	PRINTK_BITS(HDR, MULTICAST);
	PRINTK_BITS(HDR, ACK);
	PRINTK_BITS(HDR, TM);
	PRINTK_BITS(HDR, RELAY);
	PRINTK_BITS(HDR, REVISED_FCS);
	PRINTK_BITS(HDR, NEXT_BUFFER_ADDR);

	reg = be32_to_cpu(hdr->reg1);
	PRINTK_BITS(HDR, MAC_HDR_LEN);
	PRINTK_BITS(HDR, DURATION_OVERIDE);
	PRINTK_BITS(HDR, PHY_HDR_OVERIDE);
	PRINTK_BITS(HDR, CRC_FAIL);
	PRINTK_BITS(HDR, SEQUENCE_NUMBER);
	PRINTK_BITS(HDR, BUFF_HEAD_ADDR);

	reg = be32_to_cpu(hdr->reg2);
	PRINTK_BITS(HDR, PDU_COUNT);
	PRINTK_BITS(HDR, WEP_KEY);
	PRINTK_BITS(HDR, USES_WEP_KEY);
	PRINTK_BITS(HDR, KEEP_ALIVE);
	PRINTK_BITS(HDR, BUFF_TAIL_ADDR);

	reg = be32_to_cpu(hdr->reg3);
	PRINTK_BITS(HDR, CTS_11G);
	PRINTK_BITS(HDR, RTS_11G);
	PRINTK_BITS(HDR, FRAG_SIZE);
	PRINTK_BITS(HDR, PAYLOAD_LEN);
	PRINTK_BITS(HDR, FRAG_NUM);

	reg = be32_to_cpu(hdr->reg4);
	PRINTK_BITS(HDR, RELAY_STAID);
	PRINTK_BITS(HDR, STATION_ID);
	PRINTK_BITS(HDR, WORKQUEUE_ID);

	reg = be32_to_cpu(hdr->reg5);
	/* printf the route flag */
	PRINTK_BITS(HDR, ROUTE_HOST);
	PRINTK_BITS(HDR, ROUTE_CARD_CPU);
	PRINTK_BITS(HDR, ROUTE_ENCRYPTION);
	PRINTK_BITS(HDR, ROUTE_TX);
	PRINTK_BITS(HDR, ROUTE_RX1);
	PRINTK_BITS(HDR, ROUTE_RX2);
	PRINTK_BITS(HDR, ROUTE_COMPRESSION);

	PRINTK_BE32(HDR, hdr->_11g0);
	PRINTK_BE32(HDR, hdr->_11g1);
	PRINTK_BE32(HDR, hdr->_11b0);
	PRINTK_BE32(HDR, hdr->_11b1);

	dump_ieee80211b_phy_hdr(hdr->_11b0, hdr->_11b1);

	/* Fixme */
	for (i = 0; i < ARRAY_SIZE(hdr->mac_hdr); i++) {
		if (i == 0)
			printk(KERN_DEBUG PFX "IEEE80211 HDR: ");
		printk("%.2x ", hdr->mac_hdr[i]);
		if (i + 1 == ARRAY_SIZE(hdr->mac_hdr))
			printk("\n");
	}

	PRINTK_BE16(HDR, hdr->rts_duration);
	PRINTK_BE16(HDR, hdr->last_duration);
	PRINTK_BE16(HDR, hdr->sec_last_duration);
	PRINTK_BE16(HDR, hdr->other_duration);
	PRINTK_BE16(HDR, hdr->tx_other_duration);
	PRINTK_BE16(HDR, hdr->last_11g_len);
	PRINTK_BE16(HDR, hdr->other_11g_len);
	PRINTK_BE16(HDR, hdr->last_11b_len);
	PRINTK_BE16(HDR, hdr->other_11b_len);

	/* FIXME */
	reg = be16_to_cpu(hdr->reg6);
	PRINTK_BITS(HDR, MBF);
	PRINTK_BITS(HDR, RSVD4);

	PRINTK_BE16(HDR, hdr->rx_frag_stat);

	PRINTK_BE32(HDR, hdr->time_stamp);
	PRINTK_BE32(HDR, hdr->phy_stats_hi);
	PRINTK_BE32(HDR, hdr->phy_stats_lo);
	PRINTK_BE32(HDR, hdr->mic_key0);
	PRINTK_BE32(HDR, hdr->mic_key1);
} /* agnx_print_hdr */


static inline void agnx_print_rx_hdr(struct agnx_hdr *hdr)
{
	agnx_print_hdr(hdr);

	PRINTK_BE16(HDR, hdr->rx.rx_packet_duration);
	PRINTK_BE16(HDR, hdr->rx.replay_cnt);

	PRINTK_U8(HDR, hdr->rx_channel);
}

static inline void agnx_print_tx_hdr(struct agnx_hdr *hdr)
{
	agnx_print_hdr(hdr);

	PRINTK_U8(HDR, hdr->tx.long_retry_limit);
	PRINTK_U8(HDR, hdr->tx.short_retry_limit);
	PRINTK_U8(HDR, hdr->tx.long_retry_cnt);
	PRINTK_U8(HDR, hdr->tx.short_retry_cnt);

	PRINTK_U8(HDR, hdr->rx_channel);
}

static inline void
agnx_print_sta_power(struct agnx_priv *priv, unsigned int sta_idx)
{
	struct agnx_sta_power power;
	u32 reg;

	get_sta_power(priv, &power, sta_idx);

	reg = le32_to_cpu(power.reg);
	PRINTK_BITS(STA_POWER, SIGNAL);
	PRINTK_BITS(STA_POWER, RATE);
	PRINTK_BITS(STA_POWER, TIFS);
	PRINTK_BITS(STA_POWER, EDCF);
	PRINTK_BITS(STA_POWER, CHANNEL_BOND);
	PRINTK_BITS(STA_POWER, PHY_MODE);
	PRINTK_BITS(STA_POWER, POWER_LEVEL);
	PRINTK_BITS(STA_POWER, NUM_TRANSMITTERS);
}

static inline void
agnx_print_sta_tx_wq(struct agnx_priv *priv, unsigned int sta_idx, unsigned int wq_idx)
{
	struct agnx_sta_tx_wq tx_wq;
	u32 reg;

	get_sta_tx_wq(priv, &tx_wq, sta_idx, wq_idx);

	reg = le32_to_cpu(tx_wq.reg0);
	PRINTK_BITS(STA_TX_WQ, TAIL_POINTER);
	PRINTK_BITS(STA_TX_WQ, HEAD_POINTER_LOW);

	reg = le32_to_cpu(tx_wq.reg3);
	PRINTK_BITS(STA_TX_WQ, HEAD_POINTER_HIGH);
	PRINTK_BITS(STA_TX_WQ, ACK_POINTER_LOW);

	reg = le32_to_cpu(tx_wq.reg1);
	PRINTK_BITS(STA_TX_WQ, ACK_POINTER_HIGH);
	PRINTK_BITS(STA_TX_WQ, HEAD_TIMOUT_TAIL_PACK_CNT);
	PRINTK_BITS(STA_TX_WQ, ACK_TIMOUT_TAIL_PACK_CNT);

	reg = le32_to_cpu(tx_wq.reg2);
	PRINTK_BITS(STA_TX_WQ, HEAD_TIMOUT_WIN_LIM_BYTE_CNT);
	PRINTK_BITS(STA_TX_WQ, HEAD_TIMOUT_WIN_LIM_FRAG_CNT);
	PRINTK_BITS(STA_TX_WQ, WORK_QUEUE_ACK_TYPE);
	PRINTK_BITS(STA_TX_WQ, WORK_QUEUE_VALID);
}

static inline void agnx_print_sta_traffic(struct agnx_sta_traffic *traffic)
{
	u32 reg;

	reg = le32_to_cpu(traffic->reg0);
	PRINTK_BITS(STA_TRAFFIC, ACK_TIMOUT_CNT);
	PRINTK_BITS(STA_TRAFFIC, TRAFFIC_ACK_TYPE);
	PRINTK_BITS(STA_TRAFFIC, NEW_PACKET);
	PRINTK_BITS(STA_TRAFFIC, TRAFFIC_VALID);
	PRINTK_BITS(STA_TRAFFIC, RX_HDR_DESC_POINTER);

	reg = le32_to_cpu(traffic->reg1);
	PRINTK_BITS(STA_TRAFFIC, RX_PACKET_TIMESTAMP);
	PRINTK_BITS(STA_TRAFFIC, TRAFFIC_RESERVED);
	PRINTK_BITS(STA_TRAFFIC, SV);
	PRINTK_BITS(STA_TRAFFIC, RX_SEQUENCE_NUM);

	PRINTK_LE32(STA_TRAFFIC, traffic->tx_replay_cnt_low);

	PRINTK_LE16(STA_TRAFFIC, traffic->tx_replay_cnt_high);
	PRINTK_LE16(STA_TRAFFIC, traffic->rx_replay_cnt_high);

	PRINTK_LE32(STA_TRAFFIC, traffic->rx_replay_cnt_low);
}

static inline void agnx_print_sta(struct agnx_priv *priv, unsigned int sta_idx)
{
	struct agnx_sta station;
	struct agnx_sta *sta = &station;
	u32 reg;
	unsigned int i;

	get_sta(priv, sta, sta_idx);

	for (i = 0; i < 4; i++)
		PRINTK_LE32(STA, sta->tx_session_keys[i]);
	for (i = 0; i < 4; i++)
		PRINTK_LE32(STA, sta->rx_session_keys[i]);

	reg = le32_to_cpu(sta->reg);
	PRINTK_BITS(STA, ID_1);
	PRINTK_BITS(STA, ID_0);
	PRINTK_BITS(STA, ENABLE_CONCATENATION);
	PRINTK_BITS(STA, ENABLE_DECOMPRESSION);
	PRINTK_BITS(STA, STA_RESERVED);
	PRINTK_BITS(STA, EAP);
	PRINTK_BITS(STA, ED_NULL);
	PRINTK_BITS(STA, ENCRYPTION_POLICY);
	PRINTK_BITS(STA, DEFINED_KEY_ID);
	PRINTK_BITS(STA, FIXED_KEY);
	PRINTK_BITS(STA, KEY_VALID);
	PRINTK_BITS(STA, STATION_VALID);

	PRINTK_LE32(STA, sta->tx_aes_blks_unicast);
	PRINTK_LE32(STA, sta->rx_aes_blks_unicast);

	PRINTK_LE16(STA, sta->aes_format_err_unicast_cnt);
	PRINTK_LE16(STA, sta->aes_replay_unicast);

	PRINTK_LE16(STA, sta->aes_decrypt_err_unicast);
	PRINTK_LE16(STA, sta->aes_decrypt_err_default);

	PRINTK_LE16(STA, sta->single_retry_packets);
	PRINTK_LE16(STA, sta->failed_tx_packets);

	PRINTK_LE16(STA, sta->muti_retry_packets);
	PRINTK_LE16(STA, sta->ack_timeouts);

	PRINTK_LE16(STA, sta->frag_tx_cnt);
	PRINTK_LE16(STA, sta->rts_brq_sent);

	PRINTK_LE16(STA, sta->tx_packets);
	PRINTK_LE16(STA, sta->cts_back_timeout);

	PRINTK_LE32(STA, sta->phy_stats_high);
	PRINTK_LE32(STA, sta->phy_stats_low);

	/* for (i = 0; i < 8; i++) */
	agnx_print_sta_traffic(sta->traffic + 0);

	PRINTK_LE16(STA, sta->traffic_class0_frag_success);
	PRINTK_LE16(STA, sta->traffic_class1_frag_success);
	PRINTK_LE16(STA, sta->traffic_class2_frag_success);
	PRINTK_LE16(STA, sta->traffic_class3_frag_success);
	PRINTK_LE16(STA, sta->traffic_class4_frag_success);
	PRINTK_LE16(STA, sta->traffic_class5_frag_success);
	PRINTK_LE16(STA, sta->traffic_class6_frag_success);
	PRINTK_LE16(STA, sta->traffic_class7_frag_success);

	PRINTK_LE16(STA, sta->num_frag_non_prime_rates);
	PRINTK_LE16(STA, sta->ack_timeout_non_prime_rates);
}


static inline void dump_ieee80211_hdr(struct ieee80211_hdr *hdr, char *tag)
{
	u16 fctl;
	int hdrlen;

	fctl = le16_to_cpu(hdr->frame_control);
	switch (fctl & IEEE80211_FCTL_FTYPE) {
	case IEEE80211_FTYPE_DATA:
		printk(PFX "%s DATA ", tag);
		break;
	case IEEE80211_FTYPE_CTL:
		printk(PFX "%s CTL ", tag);
		break;
	case IEEE80211_FTYPE_MGMT:
		printk(PFX "%s MGMT ", tag);
		switch (fctl & IEEE80211_FCTL_STYPE) {
		case IEEE80211_STYPE_ASSOC_REQ:
			printk("SubType: ASSOC_REQ ");
			break;
		case IEEE80211_STYPE_ASSOC_RESP:
			printk("SubType: ASSOC_RESP ");
			break;
		case IEEE80211_STYPE_REASSOC_REQ:
			printk("SubType: REASSOC_REQ ");
			break;
		case IEEE80211_STYPE_REASSOC_RESP:
			printk("SubType: REASSOC_RESP ");
			break;
		case IEEE80211_STYPE_PROBE_REQ:
			printk("SubType: PROBE_REQ ");
			break;
		case IEEE80211_STYPE_PROBE_RESP:
			printk("SubType: PROBE_RESP ");
			break;
		case IEEE80211_STYPE_BEACON:
			printk("SubType: BEACON ");
			break;
		case IEEE80211_STYPE_ATIM:
			printk("SubType: ATIM ");
			break;
		case IEEE80211_STYPE_DISASSOC:
			printk("SubType: DISASSOC ");
			break;
		case IEEE80211_STYPE_AUTH:
			printk("SubType: AUTH ");
			break;
		case IEEE80211_STYPE_DEAUTH:
			printk("SubType: DEAUTH ");
			break;
		case IEEE80211_STYPE_ACTION:
			printk("SubType: ACTION ");
			break;
		default:
			printk("SubType: Unknow\n");
		}
		break;
	default:
		printk(PFX "%s Packet type: Unknow\n", tag);
	}

	hdrlen = ieee80211_hdrlen(fctl);

	if (hdrlen >= 4)
		printk("FC=0x%04x DUR=0x%04x",
		       fctl, le16_to_cpu(hdr->duration_id));
	if (hdrlen >= 10)
		printk(" A1=%pM", hdr->addr1);
	if (hdrlen >= 16)
		printk(" A2=%pM", hdr->addr2);
	if (hdrlen >= 24)
		printk(" A3=%pM", hdr->addr3);
	if (hdrlen >= 30)
		printk(" A4=%pM", hdr->addr4);
	printk("\n");
}

static inline void dump_txm_registers(struct agnx_priv *priv)
{
	void __iomem *ctl = priv->ctl;
	int i;
	for (i = 0; i <= 0x1e8; i += 4)
		printk(KERN_DEBUG PFX "TXM: %x---> 0x%.8x\n", i, ioread32(ctl + i));
}
static inline void dump_rxm_registers(struct agnx_priv *priv)
{
	void __iomem *ctl = priv->ctl;
	int i;
	for (i = 0; i <= 0x108; i += 4)
		printk(KERN_DEBUG PFX "RXM: %x---> 0x%.8x\n", i, ioread32(ctl + 0x2000 + i));
}
static inline void dump_bm_registers(struct agnx_priv *priv)
{
	void __iomem *ctl = priv->ctl;
	int i;
	for (i = 0; i <= 0x90; i += 4)
		printk(KERN_DEBUG PFX "BM: %x---> 0x%.8x\n", i, ioread32(ctl + 0x2c00 + i));
}
static inline void dump_cir_registers(struct agnx_priv *priv)
{
	void __iomem *ctl = priv->ctl;
	int i;
	for (i = 0; i <= 0xb8; i += 4)
		printk(KERN_DEBUG PFX "CIR: %x---> 0x%.8x\n", i, ioread32(ctl + 0x3000 + i));
}

#endif /* AGNX_DEBUG_H_ */