00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092 #include "debug.h"
00093 #include "base.h"
00094
00095 unsigned int ath5k_debug = ATH5K_DEBUG_NONE;
00096
00097 #if ATH5K_DEBUG
00098
00099 void ath5k_set_debug_level (struct ath5k_softc *sc)
00100 {
00101 sc->debug_level = ath5k_debug;
00102 }
00103
00104
00105
00106
00107 #define _U 0x01
00108 #define _L 0x02
00109 #define _D 0x04
00110 #define _C 0x08
00111 #define _P 0x10
00112 #define _S 0x20
00113 #define _X 0x40
00114 #define _SP 0x80
00115
00116 unsigned char _ctype[] = {
00117 _C,_C,_C,_C,_C,_C,_C,_C,
00118 _C,_C|_S,_C|_S,_C|_S,_C|_S,_C|_S,_C,_C,
00119 _C,_C,_C,_C,_C,_C,_C,_C,
00120 _C,_C,_C,_C,_C,_C,_C,_C,
00121 _S|_SP,_P,_P,_P,_P,_P,_P,_P,
00122 _P,_P,_P,_P,_P,_P,_P,_P,
00123 _D,_D,_D,_D,_D,_D,_D,_D,
00124 _D,_D,_P,_P,_P,_P,_P,_P,
00125 _P,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U,
00126 _U,_U,_U,_U,_U,_U,_U,_U,
00127 _U,_U,_U,_U,_U,_U,_U,_U,
00128 _U,_U,_U,_P,_P,_P,_P,_P,
00129 _P,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L,
00130 _L,_L,_L,_L,_L,_L,_L,_L,
00131 _L,_L,_L,_L,_L,_L,_L,_L,
00132 _L,_L,_L,_P,_P,_P,_P,_C,
00133 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
00134 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
00135 _S|_SP,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,
00136 _P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,
00137 _U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,
00138 _U,_U,_U,_U,_U,_U,_U,_P,_U,_U,_U,_U,_U,_U,_U,_L,
00139 _L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,
00140 _L,_L,_L,_L,_L,_L,_L,_P,_L,_L,_L,_L,_L,_L,_L,_L};
00141
00142
00143 #define __ismask(x) (_ctype[(int)(unsigned char)(x)])
00144 #define isprint(c) ((__ismask(c)&(_P|_U|_L|_D|_SP)) != 0)
00145 #define isascii(c) (((unsigned char)(c))<=0x7f)
00146 #define hex_asc(x) "0123456789abcdef"[x]
00147
00148 int scnprintf(char * buf, size_t size, const char *fmt, ...)
00149 {
00150 va_list args;
00151 int i;
00152
00153 va_start(args, fmt);
00154 i = vsnprintf(buf, size, fmt, args);
00155 va_end(args);
00156 return (i >= size) ? (size - 1) : i;
00157 }
00158
00159 void hex_dump_to_buffer(const void *buf, size_t len, int rowsize,
00160 int groupsize, char *linebuf, size_t linebuflen,
00161 bool ascii)
00162 {
00163 const u8 *ptr = buf;
00164 u8 ch;
00165 int j, lx = 0;
00166 int ascii_column;
00167
00168 if (rowsize != 16 && rowsize != 32)
00169 rowsize = 16;
00170
00171 if (!len)
00172 goto nil;
00173 if (len > rowsize)
00174 len = rowsize;
00175 if ((len % groupsize) != 0)
00176 groupsize = 1;
00177
00178 switch (groupsize) {
00179 case 8: {
00180 const u64 *ptr8 = buf;
00181 int ngroups = len / groupsize;
00182
00183 for (j = 0; j < ngroups; j++)
00184 lx += scnprintf(linebuf + lx, linebuflen - lx,
00185 "%16.16llx ", (unsigned long long)*(ptr8 + j));
00186 ascii_column = 17 * ngroups + 2;
00187 break;
00188 }
00189
00190 case 4: {
00191 const u32 *ptr4 = buf;
00192 int ngroups = len / groupsize;
00193
00194 for (j = 0; j < ngroups; j++)
00195 lx += scnprintf(linebuf + lx, linebuflen - lx,
00196 "%8.8x ", *(ptr4 + j));
00197 ascii_column = 9 * ngroups + 2;
00198 break;
00199 }
00200
00201 case 2: {
00202 const u16 *ptr2 = buf;
00203 int ngroups = len / groupsize;
00204
00205 for (j = 0; j < ngroups; j++)
00206 lx += scnprintf(linebuf + lx, linebuflen - lx,
00207 "%4.4x ", *(ptr2 + j));
00208 ascii_column = 5 * ngroups + 2;
00209 break;
00210 }
00211
00212 default:
00213 for (j = 0; (j < rowsize) && (j < len) && (lx + 4) < linebuflen;
00214 j++) {
00215 ch = ptr[j];
00216 linebuf[lx++] = hex_asc(ch >> 4);
00217 linebuf[lx++] = hex_asc(ch & 0x0f);
00218 linebuf[lx++] = ' ';
00219 }
00220 ascii_column = 3 * rowsize + 2;
00221 break;
00222 }
00223 if (!ascii)
00224 goto nil;
00225
00226 while (lx < (linebuflen - 1) && lx < (ascii_column - 1))
00227 linebuf[lx++] = ' ';
00228 for (j = 0; (j < rowsize) && (j < len) && (lx + 2) < linebuflen; j++)
00229 linebuf[lx++] = (isascii(ptr[j]) && isprint(ptr[j])) ? ptr[j]
00230 : '.';
00231 nil:
00232 linebuf[lx++] = '\0';
00233 }
00234
00235 void print_hex_dump(const char *prefix_str, int prefix_type,
00236 int rowsize, int groupsize,
00237 const void *buf, size_t len, bool ascii)
00238 {
00239 const u8 *ptr = buf;
00240 int i, linelen, remaining = len;
00241 char linebuf[200];
00242
00243 if (rowsize != 16 && rowsize != 32)
00244 rowsize = 16;
00245
00246 for (i = 0; i < len; i += rowsize) {
00247 linelen = min(remaining, rowsize);
00248 remaining -= rowsize;
00249 hex_dump_to_buffer(ptr + i, linelen, rowsize, groupsize,
00250 linebuf, sizeof(linebuf), ascii);
00251
00252 printk("%s%s\n", prefix_str, linebuf);
00253 }
00254 }
00255
00256 void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
00257 const void *buf, size_t len)
00258 {
00259 print_hex_dump(prefix_str, prefix_type, 16, 1, buf, len, 1);
00260 }
00261
00262
00263
00264
00265 void
00266 ath5k_debug_dump_bands(struct ath5k_softc *sc)
00267 {
00268 unsigned int b, i;
00269
00270 if (likely(!(sc->debug_level & ATH5K_DEBUG_DUMPBANDS)))
00271 return;
00272
00273 BUG_ON(!sc->sbands);
00274
00275 for (b = 0; b < IEEE80211_NUM_BANDS; b++) {
00276 struct ieee80211_supported_band *band = &sc->sbands[b];
00277 char bname[6];
00278 switch (band->band) {
00279 case IEEE80211_BAND_2GHZ:
00280 strcpy(bname, "2 GHz");
00281 break;
00282 case IEEE80211_BAND_5GHZ:
00283 strcpy(bname, "5 GHz");
00284 break;
00285 default:
00286 printk(KERN_DEBUG "Band not supported: %d\n",
00287 band->band);
00288 return;
00289 }
00290 printk(KERN_DEBUG "Band %s: channels %d, rates %d\n", bname,
00291 band->n_channels, band->n_bitrates);
00292 printk(KERN_DEBUG " channels:\n");
00293 for (i = 0; i < band->n_channels; i++)
00294 printk(KERN_DEBUG " %3d %d %.4x\n",
00295 ath5k_frequency_to_channel(
00296 band->channels[i].center_freq),
00297 band->channels[i].center_freq,
00298 band->channels[i].hw_value);
00299 printk(KERN_DEBUG " rates:\n");
00300 for (i = 0; i < band->n_bitrates; i++)
00301 printk(KERN_DEBUG " %4d %.4x %.4x %.4x\n",
00302 band->bitrates[i].bitrate,
00303 band->bitrates[i].hw_value,
00304 band->bitrates[i].flags,
00305 band->bitrates[i].hw_value_short);
00306 }
00307 }
00308
00309 static inline void
00310 ath5k_debug_printrxbuf(struct ath5k_buf *bf, int done,
00311 struct ath5k_rx_status *rs)
00312 {
00313 struct ath5k_desc *ds = bf->desc;
00314 struct ath5k_hw_all_rx_desc *rd = &ds->ud.ds_rx;
00315
00316 printk(KERN_DEBUG "R (%p %x) %08x %08x %08x %08x %08x %08x %c\n",
00317 ds, (unsigned int)bf->desc,
00318 ds->ds_link, ds->ds_data,
00319 rd->rx_ctl.rx_control_0, rd->rx_ctl.rx_control_1,
00320 rd->u.rx_stat.rx_status_0, rd->u.rx_stat.rx_status_0,
00321 !done ? ' ' : (rs->rs_status == 0) ? '*' : '!');
00322 }
00323
00324 void
00325 ath5k_debug_dump_skb(struct ath5k_softc *sc,
00326 struct sk_buff *skb, const char *prefix, int tx)
00327 {
00328 char buf[16];
00329
00330 if (likely(!((tx && (sc->debug_level & ATH5K_DEBUG_DUMP_TX)) ||
00331 (!tx && (sc->debug_level & ATH5K_DEBUG_DUMP_RX)))))
00332 return;
00333
00334 snprintf(buf, sizeof(buf), "phyX %s", prefix);
00335
00336 print_hex_dump_bytes(buf, 0, skb->data,
00337 min(200U, skb->len));
00338
00339 printk(KERN_DEBUG "\n");
00340 }
00341
00342 void
00343 ath5k_debug_printtxbuf(struct ath5k_softc *sc, struct ath5k_buf *bf)
00344 {
00345 struct ath5k_desc *ds = bf->desc;
00346 struct ath5k_hw_5212_tx_desc *td = &ds->ud.ds_tx5212;
00347 struct ath5k_tx_status ts = {};
00348 int done;
00349
00350 if (likely(!(sc->debug_level & ATH5K_DEBUG_RESET)))
00351 return;
00352
00353 done = sc->ah->ah_proc_tx_desc(sc->ah, bf->desc, &ts);
00354
00355 printk(KERN_DEBUG "T (%p %x) %08x %08x %08x %08x %08x %08x %08x "
00356 "%08x %c\n", ds, (unsigned int)bf->desc, ds->ds_link,
00357 ds->ds_data, td->tx_ctl.tx_control_0, td->tx_ctl.tx_control_1,
00358 td->tx_ctl.tx_control_2, td->tx_ctl.tx_control_3,
00359 td->tx_stat.tx_status_0, td->tx_stat.tx_status_1,
00360 done ? ' ' : (ts.ts_status == 0) ? '*' : '!');
00361 }
00362
00363 #endif