Merge branch 'master' into next
[linux-2.6] / drivers / staging / agnx / debug.h
1 #ifndef AGNX_DEBUG_H_
2 #define AGNX_DEBUG_H_
3
4 #include "agnx.h"
5 #include "phy.h"
6 #include "sta.h"
7 #include "xmit.h"
8
9 #define AGNX_TRACE              printk(KERN_ERR PFX "function:%s line:%d\n", __func__, __LINE__)
10
11 #define PRINTK_LE16(prefix, var)        printk(KERN_DEBUG PFX #prefix ": " #var " 0x%.4x\n", le16_to_cpu(var))
12 #define PRINTK_LE32(prefix, var)        printk(KERN_DEBUG PFX #prefix ": " #var " 0x%.8x\n", le32_to_cpu(var))
13 #define PRINTK_U8(prefix, var)          printk(KERN_DEBUG PFX #prefix ": " #var " 0x%.2x\n", var)
14 #define PRINTK_BE16(prefix, var)        printk(KERN_DEBUG PFX #prefix ": " #var " 0x%.4x\n", be16_to_cpu(var))
15 #define PRINTK_BE32(prefix, var)        printk(KERN_DEBUG PFX #prefix ": " #var " 0x%.8x\n", be32_to_cpu(var))
16 #define PRINTK_BITS(prefix, field)      printk(KERN_DEBUG PFX #prefix ": " #field ": 0x%x\n", (reg & field) >> field##_SHIFT)
17
18 static inline void agnx_bug(char *reason)
19 {
20         printk(KERN_ERR PFX "%s\n", reason);
21         BUG();
22 }
23
24 static inline void agnx_print_desc(struct agnx_desc *desc)
25 {
26         u32 reg = be32_to_cpu(desc->frag);
27
28         PRINTK_BITS(DESC, PACKET_LEN);
29
30         if (reg & FIRST_FRAG) {
31                 PRINTK_BITS(DESC, FIRST_PACKET_MASK);
32                 PRINTK_BITS(DESC, FIRST_RESERV2);
33                 PRINTK_BITS(DESC, FIRST_TKIP_ERROR);
34                 PRINTK_BITS(DESC, FIRST_TKIP_PACKET);
35                 PRINTK_BITS(DESC, FIRST_RESERV1);
36                 PRINTK_BITS(DESC, FIRST_FRAG_LEN);
37         } else {
38                 PRINTK_BITS(DESC, SUB_RESERV2);
39                 PRINTK_BITS(DESC, SUB_TKIP_ERROR);
40                 PRINTK_BITS(DESC, SUB_TKIP_PACKET);
41                 PRINTK_BITS(DESC, SUB_RESERV1);
42                 PRINTK_BITS(DESC, SUB_FRAG_LEN);
43         }
44
45         PRINTK_BITS(DESC, FIRST_FRAG);
46         PRINTK_BITS(DESC, LAST_FRAG);
47         PRINTK_BITS(DESC, OWNER);
48 }
49
50
51 static inline void dump_ieee80211b_phy_hdr(__be32 _11b0, __be32 _11b1)
52 {
53
54 }
55
56 static inline void agnx_print_hdr(struct agnx_hdr *hdr)
57 {
58         u32 reg;
59         int i;
60
61         reg = be32_to_cpu(hdr->reg0);
62         PRINTK_BITS(HDR, RTS);
63         PRINTK_BITS(HDR, MULTICAST);
64         PRINTK_BITS(HDR, ACK);
65         PRINTK_BITS(HDR, TM);
66         PRINTK_BITS(HDR, RELAY);
67         PRINTK_BITS(HDR, REVISED_FCS);
68         PRINTK_BITS(HDR, NEXT_BUFFER_ADDR);
69
70         reg = be32_to_cpu(hdr->reg1);
71         PRINTK_BITS(HDR, MAC_HDR_LEN);
72         PRINTK_BITS(HDR, DURATION_OVERIDE);
73         PRINTK_BITS(HDR, PHY_HDR_OVERIDE);
74         PRINTK_BITS(HDR, CRC_FAIL);
75         PRINTK_BITS(HDR, SEQUENCE_NUMBER);
76         PRINTK_BITS(HDR, BUFF_HEAD_ADDR);
77
78         reg = be32_to_cpu(hdr->reg2);
79         PRINTK_BITS(HDR, PDU_COUNT);
80         PRINTK_BITS(HDR, WEP_KEY);
81         PRINTK_BITS(HDR, USES_WEP_KEY);
82         PRINTK_BITS(HDR, KEEP_ALIVE);
83         PRINTK_BITS(HDR, BUFF_TAIL_ADDR);
84
85         reg = be32_to_cpu(hdr->reg3);
86         PRINTK_BITS(HDR, CTS_11G);
87         PRINTK_BITS(HDR, RTS_11G);
88         PRINTK_BITS(HDR, FRAG_SIZE);
89         PRINTK_BITS(HDR, PAYLOAD_LEN);
90         PRINTK_BITS(HDR, FRAG_NUM);
91
92         reg = be32_to_cpu(hdr->reg4);
93         PRINTK_BITS(HDR, RELAY_STAID);
94         PRINTK_BITS(HDR, STATION_ID);
95         PRINTK_BITS(HDR, WORKQUEUE_ID);
96
97         reg = be32_to_cpu(hdr->reg5);
98         /* printf the route flag */
99         PRINTK_BITS(HDR, ROUTE_HOST);
100         PRINTK_BITS(HDR, ROUTE_CARD_CPU);
101         PRINTK_BITS(HDR, ROUTE_ENCRYPTION);
102         PRINTK_BITS(HDR, ROUTE_TX);
103         PRINTK_BITS(HDR, ROUTE_RX1);
104         PRINTK_BITS(HDR, ROUTE_RX2);
105         PRINTK_BITS(HDR, ROUTE_COMPRESSION);
106
107         PRINTK_BE32(HDR, hdr->_11g0);
108         PRINTK_BE32(HDR, hdr->_11g1);
109         PRINTK_BE32(HDR, hdr->_11b0);
110         PRINTK_BE32(HDR, hdr->_11b1);
111
112         dump_ieee80211b_phy_hdr(hdr->_11b0, hdr->_11b1);
113
114         /* Fixme */
115         for (i = 0; i < ARRAY_SIZE(hdr->mac_hdr); i++) {
116                 if (i == 0)
117                         printk(KERN_DEBUG PFX "IEEE80211 HDR: ");
118                 printk("%.2x ", hdr->mac_hdr[i]);
119                 if (i + 1 == ARRAY_SIZE(hdr->mac_hdr))
120                         printk("\n");
121         }
122
123         PRINTK_BE16(HDR, hdr->rts_duration);
124         PRINTK_BE16(HDR, hdr->last_duration);
125         PRINTK_BE16(HDR, hdr->sec_last_duration);
126         PRINTK_BE16(HDR, hdr->other_duration);
127         PRINTK_BE16(HDR, hdr->tx_other_duration);
128         PRINTK_BE16(HDR, hdr->last_11g_len);
129         PRINTK_BE16(HDR, hdr->other_11g_len);
130         PRINTK_BE16(HDR, hdr->last_11b_len);
131         PRINTK_BE16(HDR, hdr->other_11b_len);
132
133         /* FIXME */
134         reg = be16_to_cpu(hdr->reg6);
135         PRINTK_BITS(HDR, MBF);
136         PRINTK_BITS(HDR, RSVD4);
137
138         PRINTK_BE16(HDR, hdr->rx_frag_stat);
139
140         PRINTK_BE32(HDR, hdr->time_stamp);
141         PRINTK_BE32(HDR, hdr->phy_stats_hi);
142         PRINTK_BE32(HDR, hdr->phy_stats_lo);
143         PRINTK_BE32(HDR, hdr->mic_key0);
144         PRINTK_BE32(HDR, hdr->mic_key1);
145 } /* agnx_print_hdr */
146
147
148 static inline void agnx_print_rx_hdr(struct agnx_hdr *hdr)
149 {
150         agnx_print_hdr(hdr);
151
152         PRINTK_BE16(HDR, hdr->rx.rx_packet_duration);
153         PRINTK_BE16(HDR, hdr->rx.replay_cnt);
154
155         PRINTK_U8(HDR, hdr->rx_channel);
156 }
157
158 static inline void agnx_print_tx_hdr(struct agnx_hdr *hdr)
159 {
160         agnx_print_hdr(hdr);
161
162         PRINTK_U8(HDR, hdr->tx.long_retry_limit);
163         PRINTK_U8(HDR, hdr->tx.short_retry_limit);
164         PRINTK_U8(HDR, hdr->tx.long_retry_cnt);
165         PRINTK_U8(HDR, hdr->tx.short_retry_cnt);
166
167         PRINTK_U8(HDR, hdr->rx_channel);
168 }
169
170 static inline void
171 agnx_print_sta_power(struct agnx_priv *priv, unsigned int sta_idx)
172 {
173         struct agnx_sta_power power;
174         u32 reg;
175
176         get_sta_power(priv, &power, sta_idx);
177
178         reg = le32_to_cpu(power.reg);
179         PRINTK_BITS(STA_POWER, SIGNAL);
180         PRINTK_BITS(STA_POWER, RATE);
181         PRINTK_BITS(STA_POWER, TIFS);
182         PRINTK_BITS(STA_POWER, EDCF);
183         PRINTK_BITS(STA_POWER, CHANNEL_BOND);
184         PRINTK_BITS(STA_POWER, PHY_MODE);
185         PRINTK_BITS(STA_POWER, POWER_LEVEL);
186         PRINTK_BITS(STA_POWER, NUM_TRANSMITTERS);
187 }
188
189 static inline void
190 agnx_print_sta_tx_wq(struct agnx_priv *priv, unsigned int sta_idx, unsigned int wq_idx)
191 {
192         struct agnx_sta_tx_wq tx_wq;
193         u32 reg;
194
195         get_sta_tx_wq(priv, &tx_wq, sta_idx, wq_idx);
196
197         reg = le32_to_cpu(tx_wq.reg0);
198         PRINTK_BITS(STA_TX_WQ, TAIL_POINTER);
199         PRINTK_BITS(STA_TX_WQ, HEAD_POINTER_LOW);
200
201         reg = le32_to_cpu(tx_wq.reg3);
202         PRINTK_BITS(STA_TX_WQ, HEAD_POINTER_HIGH);
203         PRINTK_BITS(STA_TX_WQ, ACK_POINTER_LOW);
204
205         reg = le32_to_cpu(tx_wq.reg1);
206         PRINTK_BITS(STA_TX_WQ, ACK_POINTER_HIGH);
207         PRINTK_BITS(STA_TX_WQ, HEAD_TIMOUT_TAIL_PACK_CNT);
208         PRINTK_BITS(STA_TX_WQ, ACK_TIMOUT_TAIL_PACK_CNT);
209
210         reg = le32_to_cpu(tx_wq.reg2);
211         PRINTK_BITS(STA_TX_WQ, HEAD_TIMOUT_WIN_LIM_BYTE_CNT);
212         PRINTK_BITS(STA_TX_WQ, HEAD_TIMOUT_WIN_LIM_FRAG_CNT);
213         PRINTK_BITS(STA_TX_WQ, WORK_QUEUE_ACK_TYPE);
214         PRINTK_BITS(STA_TX_WQ, WORK_QUEUE_VALID);
215 }
216
217 static inline void agnx_print_sta_traffic(struct agnx_sta_traffic *traffic)
218 {
219         u32 reg;
220
221         reg = le32_to_cpu(traffic->reg0);
222         PRINTK_BITS(STA_TRAFFIC, ACK_TIMOUT_CNT);
223         PRINTK_BITS(STA_TRAFFIC, TRAFFIC_ACK_TYPE);
224         PRINTK_BITS(STA_TRAFFIC, NEW_PACKET);
225         PRINTK_BITS(STA_TRAFFIC, TRAFFIC_VALID);
226         PRINTK_BITS(STA_TRAFFIC, RX_HDR_DESC_POINTER);
227
228         reg = le32_to_cpu(traffic->reg1);
229         PRINTK_BITS(STA_TRAFFIC, RX_PACKET_TIMESTAMP);
230         PRINTK_BITS(STA_TRAFFIC, TRAFFIC_RESERVED);
231         PRINTK_BITS(STA_TRAFFIC, SV);
232         PRINTK_BITS(STA_TRAFFIC, RX_SEQUENCE_NUM);
233
234         PRINTK_LE32(STA_TRAFFIC, traffic->tx_replay_cnt_low);
235
236         PRINTK_LE16(STA_TRAFFIC, traffic->tx_replay_cnt_high);
237         PRINTK_LE16(STA_TRAFFIC, traffic->rx_replay_cnt_high);
238
239         PRINTK_LE32(STA_TRAFFIC, traffic->rx_replay_cnt_low);
240 }
241
242 static inline void agnx_print_sta(struct agnx_priv *priv, unsigned int sta_idx)
243 {
244         struct agnx_sta station;
245         struct agnx_sta *sta = &station;
246         u32 reg;
247         unsigned int i;
248
249         get_sta(priv, sta, sta_idx);
250
251         for (i = 0; i < 4; i++)
252                 PRINTK_LE32(STA, sta->tx_session_keys[i]);
253         for (i = 0; i < 4; i++)
254                 PRINTK_LE32(STA, sta->rx_session_keys[i]);
255
256         reg = le32_to_cpu(sta->reg);
257         PRINTK_BITS(STA, ID_1);
258         PRINTK_BITS(STA, ID_0);
259         PRINTK_BITS(STA, ENABLE_CONCATENATION);
260         PRINTK_BITS(STA, ENABLE_DECOMPRESSION);
261         PRINTK_BITS(STA, STA_RESERVED);
262         PRINTK_BITS(STA, EAP);
263         PRINTK_BITS(STA, ED_NULL);
264         PRINTK_BITS(STA, ENCRYPTION_POLICY);
265         PRINTK_BITS(STA, DEFINED_KEY_ID);
266         PRINTK_BITS(STA, FIXED_KEY);
267         PRINTK_BITS(STA, KEY_VALID);
268         PRINTK_BITS(STA, STATION_VALID);
269
270         PRINTK_LE32(STA, sta->tx_aes_blks_unicast);
271         PRINTK_LE32(STA, sta->rx_aes_blks_unicast);
272
273         PRINTK_LE16(STA, sta->aes_format_err_unicast_cnt);
274         PRINTK_LE16(STA, sta->aes_replay_unicast);
275
276         PRINTK_LE16(STA, sta->aes_decrypt_err_unicast);
277         PRINTK_LE16(STA, sta->aes_decrypt_err_default);
278
279         PRINTK_LE16(STA, sta->single_retry_packets);
280         PRINTK_LE16(STA, sta->failed_tx_packets);
281
282         PRINTK_LE16(STA, sta->muti_retry_packets);
283         PRINTK_LE16(STA, sta->ack_timeouts);
284
285         PRINTK_LE16(STA, sta->frag_tx_cnt);
286         PRINTK_LE16(STA, sta->rts_brq_sent);
287
288         PRINTK_LE16(STA, sta->tx_packets);
289         PRINTK_LE16(STA, sta->cts_back_timeout);
290
291         PRINTK_LE32(STA, sta->phy_stats_high);
292         PRINTK_LE32(STA, sta->phy_stats_low);
293
294 //      for (i = 0; i < 8; i++)
295         agnx_print_sta_traffic(sta->traffic + 0);
296
297         PRINTK_LE16(STA, sta->traffic_class0_frag_success);
298         PRINTK_LE16(STA, sta->traffic_class1_frag_success);
299         PRINTK_LE16(STA, sta->traffic_class2_frag_success);
300         PRINTK_LE16(STA, sta->traffic_class3_frag_success);
301         PRINTK_LE16(STA, sta->traffic_class4_frag_success);
302         PRINTK_LE16(STA, sta->traffic_class5_frag_success);
303         PRINTK_LE16(STA, sta->traffic_class6_frag_success);
304         PRINTK_LE16(STA, sta->traffic_class7_frag_success);
305
306         PRINTK_LE16(STA, sta->num_frag_non_prime_rates);
307         PRINTK_LE16(STA, sta->ack_timeout_non_prime_rates);
308 }
309
310
311 static inline void dump_ieee80211_hdr(struct ieee80211_hdr *hdr, char *tag)
312 {
313         u16 fctl;
314         int hdrlen;
315         DECLARE_MAC_BUF(mac);
316
317         fctl = le16_to_cpu(hdr->frame_control);
318         switch (fctl & IEEE80211_FCTL_FTYPE) {
319         case IEEE80211_FTYPE_DATA:
320                 printk(PFX "%s DATA ", tag);
321                 break;
322         case IEEE80211_FTYPE_CTL:
323                 printk(PFX "%s CTL ", tag);
324                 break;
325         case IEEE80211_FTYPE_MGMT:
326                 printk(PFX "%s MGMT ", tag);
327                 switch(fctl & IEEE80211_FCTL_STYPE) {
328                 case IEEE80211_STYPE_ASSOC_REQ:
329                         printk("SubType: ASSOC_REQ ");
330                         break;
331                 case IEEE80211_STYPE_ASSOC_RESP:
332                         printk("SubType: ASSOC_RESP ");
333                         break;
334                 case IEEE80211_STYPE_REASSOC_REQ:
335                         printk("SubType: REASSOC_REQ ");
336                         break;
337                 case IEEE80211_STYPE_REASSOC_RESP:
338                         printk("SubType: REASSOC_RESP ");
339                         break;
340                 case IEEE80211_STYPE_PROBE_REQ:
341                         printk("SubType: PROBE_REQ ");
342                         break;
343                 case IEEE80211_STYPE_PROBE_RESP:
344                         printk("SubType: PROBE_RESP ");
345                         break;
346                 case IEEE80211_STYPE_BEACON:
347                         printk("SubType: BEACON ");
348                         break;
349                 case IEEE80211_STYPE_ATIM:
350                         printk("SubType: ATIM ");
351                         break;
352                 case IEEE80211_STYPE_DISASSOC:
353                         printk("SubType: DISASSOC ");
354                         break;
355                 case IEEE80211_STYPE_AUTH:
356                         printk("SubType: AUTH ");
357                         break;
358                 case IEEE80211_STYPE_DEAUTH:
359                         printk("SubType: DEAUTH ");
360                         break;
361                 case IEEE80211_STYPE_ACTION:
362                         printk("SubType: ACTION ");
363                         break;
364                 default:
365                         printk("SubType: Unknow\n");
366                 }
367                 break;
368         default:
369                 printk(PFX "%s Packet type: Unknow\n", tag);
370         }
371
372         hdrlen = ieee80211_hdrlen(fctl);
373
374         if (hdrlen >= 4)
375                 printk("FC=0x%04x DUR=0x%04x",
376                        fctl, le16_to_cpu(hdr->duration_id));
377         if (hdrlen >= 10)
378                 printk(" A1=%s", print_mac(mac, hdr->addr1));
379         if (hdrlen >= 16)
380                 printk(" A2=%s", print_mac(mac, hdr->addr2));
381         if (hdrlen >= 24)
382                 printk(" A3=%s", print_mac(mac, hdr->addr3));
383         if (hdrlen >= 30)
384                 printk(" A4=%s", print_mac(mac, hdr->addr4));
385         printk("\n");
386 }
387
388 static inline void dump_txm_registers(struct agnx_priv *priv)
389 {
390         void __iomem *ctl = priv->ctl;
391         int i;
392         for (i = 0; i <=0x1e8; i += 4) {
393                 printk(KERN_DEBUG PFX "TXM: %x---> 0x%.8x\n", i, ioread32(ctl + i));
394         }
395 }
396 static inline void dump_rxm_registers(struct agnx_priv *priv)
397 {
398         void __iomem *ctl = priv->ctl;
399         int i;
400         for (i = 0; i <=0x108; i += 4)
401                 printk(KERN_DEBUG PFX "RXM: %x---> 0x%.8x\n", i, ioread32(ctl + 0x2000 + i));
402 }
403 static inline void dump_bm_registers(struct agnx_priv *priv)
404 {
405         void __iomem *ctl = priv->ctl;
406         int i;
407         for (i = 0; i <=0x90; i += 4)
408                 printk(KERN_DEBUG PFX "BM: %x---> 0x%.8x\n", i, ioread32(ctl + 0x2c00 + i));
409 }
410 static inline void dump_cir_registers(struct agnx_priv *priv)
411 {
412         void __iomem *ctl = priv->ctl;
413         int i;
414         for (i = 0; i <=0xb8; i += 4)
415                 printk(KERN_DEBUG PFX "CIR: %x---> 0x%.8x\n", i, ioread32(ctl + 0x3000 + i));
416 }
417
418 #endif /* AGNX_DEBUG_H_ */