debug.c
Go to the documentation of this file.
00001 /*------------------------------------------------------------------------------
00002  *-------------------------        ATH5K Driver          -----------------------
00003  *------------------------------------------------------------------------------
00004  *                                                           V1.0  08/02/2010
00005  *
00006  *
00007  *  Feb 2010 - Samuel Cabrero <samuelcabrero@gmail.com>
00008  *              Initial release
00009  *
00010  *  ----------------------------------------------------------------------------
00011  *  Copyright (C) 2000-2010, Universidad de Zaragoza, SPAIN
00012  *
00013  *  Autors:
00014  *              Samuel Cabrero        <samuelcabrero@gmail.com>
00015  *              Danilo Tardioli       <dantard@unizar.es>
00016  *              Jose Luis Villarroel  <jlvilla@unizar.es>
00017  *
00018  *  This is a simplified version of the original ath5k driver. It should work 
00019  *  with all Atheros 5xxx WLAN cards. The 802.11 layer have been removed so it
00020  *  just send and receive frames over the air, as if it were an Ethernet bus
00021  *  interface.
00022  *
00023  *  Please read ath5k_interface.h for instructions.
00024  *
00025  *  This program is distributed under the terms of GPL version 2 and in the 
00026  *  hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 
00027  *  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
00028  *  See the GNU General Public License for more details.
00029  *
00030  *----------------------------------------------------------------------------*/
00031 
00032 /*
00033  * Copyright (c) 2007-2008 Bruno Randolf <bruno@thinktube.com>
00034  *
00035  *  This file is free software: you may copy, redistribute and/or modify it
00036  *  under the terms of the GNU General Public License as published by the
00037  *  Free Software Foundation, either version 2 of the License, or (at your
00038  *  option) any later version.
00039  *
00040  *  This file is distributed in the hope that it will be useful, but
00041  *  WITHOUT ANY WARRANTY; without even the implied warranty of
00042  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00043  *  General Public License for more details.
00044  *
00045  *  You should have received a copy of the GNU General Public License
00046  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00047  *
00048  *
00049  * This file incorporates work covered by the following copyright and
00050  * permission notice:
00051  *
00052  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
00053  * Copyright (c) 2004-2005 Atheros Communications, Inc.
00054  * Copyright (c) 2006 Devicescape Software, Inc.
00055  * Copyright (c) 2007 Jiri Slaby <jirislaby@gmail.com>
00056  * Copyright (c) 2007 Luis R. Rodriguez <mcgrof@winlab.rutgers.edu>
00057  *
00058  * All rights reserved.
00059  *
00060  * Redistribution and use in source and binary forms, with or without
00061  * modification, are permitted provided that the following conditions
00062  * are met:
00063  * 1. Redistributions of source code must retain the above copyright
00064  *    notice, this list of conditions and the following disclaimer,
00065  *    without modification.
00066  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
00067  *    similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
00068  *    redistribution must be conditioned upon including a substantially
00069  *    similar Disclaimer requirement for further binary redistribution.
00070  * 3. Neither the names of the above-listed copyright holders nor the names
00071  *    of any contributors may be used to endorse or promote products derived
00072  *    from this software without specific prior written permission.
00073  *
00074  * Alternatively, this software may be distributed under the terms of the
00075  * GNU General Public License ("GPL") version 2 as published by the Free
00076  * Software Foundation.
00077  *
00078  * NO WARRANTY
00079  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00080  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00081  * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
00082  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
00083  * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
00084  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00085  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00086  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
00087  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00088  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
00089  * THE POSSIBILITY OF SUCH DAMAGES.
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  * Funciones del kernel para imprimir buffers
00106  */
00107 #define _U      0x01    /* upper */
00108 #define _L      0x02    /* lower */
00109 #define _D      0x04    /* digit */
00110 #define _C      0x08    /* cntrl */
00111 #define _P      0x10    /* punct */
00112 #define _S      0x20    /* white space (space/lf/tab) */
00113 #define _X      0x40    /* hex digit */
00114 #define _SP     0x80    /* hard space (0x20) */
00115 
00116 unsigned char _ctype[] = {
00117 _C,_C,_C,_C,_C,_C,_C,_C,                        /* 0-7 */
00118 _C,_C|_S,_C|_S,_C|_S,_C|_S,_C|_S,_C,_C,         /* 8-15 */
00119 _C,_C,_C,_C,_C,_C,_C,_C,                        /* 16-23 */
00120 _C,_C,_C,_C,_C,_C,_C,_C,                        /* 24-31 */
00121 _S|_SP,_P,_P,_P,_P,_P,_P,_P,                    /* 32-39 */
00122 _P,_P,_P,_P,_P,_P,_P,_P,                        /* 40-47 */
00123 _D,_D,_D,_D,_D,_D,_D,_D,                        /* 48-55 */
00124 _D,_D,_P,_P,_P,_P,_P,_P,                        /* 56-63 */
00125 _P,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U,      /* 64-71 */
00126 _U,_U,_U,_U,_U,_U,_U,_U,                        /* 72-79 */
00127 _U,_U,_U,_U,_U,_U,_U,_U,                        /* 80-87 */
00128 _U,_U,_U,_P,_P,_P,_P,_P,                        /* 88-95 */
00129 _P,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L,      /* 96-103 */
00130 _L,_L,_L,_L,_L,_L,_L,_L,                        /* 104-111 */
00131 _L,_L,_L,_L,_L,_L,_L,_L,                        /* 112-119 */
00132 _L,_L,_L,_P,_P,_P,_P,_C,                        /* 120-127 */
00133 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,                /* 128-143 */
00134 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,                /* 144-159 */
00135 _S|_SP,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,   /* 160-175 */
00136 _P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,_P,       /* 176-191 */
00137 _U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,_U,       /* 192-207 */
00138 _U,_U,_U,_U,_U,_U,_U,_P,_U,_U,_U,_U,_U,_U,_U,_L,       /* 208-223 */
00139 _L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,_L,       /* 224-239 */
00140 _L,_L,_L,_L,_L,_L,_L,_P,_L,_L,_L,_L,_L,_L,_L,_L};      /* 240-255 */
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)              /* limit to one line at a time */
00174                 len = rowsize;
00175         if ((len % groupsize) != 0)     /* no mixed size output */
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  * Debug functions 
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 /* if ATH5K_DEBUG */


ros_rt_wmp
Author(s): Danilo Tardioli, dantard@unizar.es
autogenerated on Fri Jan 3 2014 12:07:54