ath5k_linux_layer.h
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 #ifndef _ATH5K_LINUX_LAYER_H_
00033 #define _ATH5K_LINUX_LAYER_H_
00034 
00035 #include <limits.h>
00036 #include <stdio.h>
00037 #include <stdbool.h>
00038 #include <stddef.h>
00039 #include <time.h>
00040 #include <malloc.h>
00041 #include <sys/pci.h>
00042 #include <string.h>
00043 #include <pthread.h>
00044 #include <intr.h>
00045 #include <sys/pio.h>
00046 #include <sys/io.h>
00047 #include <drivers/if_ether.h>
00048 #include <stdint.h>
00049 #include <math.h>
00050 
00051 /********************************\
00052         PCI VENDOR AND DEVICE ID's      
00053 \********************************/
00054 #define PCI_VENDOR_ID_ATHEROS                   0x168c
00055 
00056 
00057 /***********\
00058         TYPES
00059 \***********/
00060 typedef uint64_t        u64;
00061 typedef uint32_t        u32;
00062 typedef uint16_t        u16;
00063 typedef uint8_t         u8;
00064 typedef int64_t         s64;
00065 typedef int32_t         s32;
00066 typedef int16_t         s16;
00067 typedef int8_t          s8;
00068 typedef uintptr_t       dma_addr_t;
00069 typedef s8                      __le8;
00070 typedef s16                     __le16;
00071 typedef s32                     __le32;
00072 typedef s64                     __le64;
00073 typedef u8                      __u8;
00074 typedef u16                     __u16;
00075 typedef u32                     __u32;
00076 typedef u64                     __u64;
00077 
00078 typedef unsigned int u_int;
00079 
00080 /*********************\
00081         GENERAL DEFINES
00082 \*********************/
00083 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
00084 
00085 #define __packed __attribute__((__packed__))
00086 #define __iomem
00087 #define __devinit
00088 #define __devexit
00089 
00090 #define likely(x)       (x)
00091 #define unlikely(x)     (x)
00092 
00093 /***********************************\
00094         LITTLE/BIG ENDIAN CONVERSIONS
00095 \***********************************/
00096 #define cpu_to_le16(x) (u16)(x)
00097 #define le16_to_cpu(x) (x)
00098 
00099 /***********************\
00100         MEMORY ALLOCATION
00101 \***********************/
00102 #define GFP_KERNEL
00103 #define kzalloc(size,mode)                      malloc(size)
00104 #define kmalloc(size,mode)                      malloc(size)
00105 #define kcalloc(elems,size,mode)        calloc(elems,size)
00106 #define kfree(x)                                        free(x)
00107 
00108 /********\
00109         IO
00110 \********/
00111 #define ioread32(addr)                          readl(addr)
00112 #define iowrite32(val,addr)                     writel(val,addr)
00113 
00114 /************\
00115         PRINTs
00116 \************/
00117 #define printk                                          printc
00118 
00119 #define KERN_ERR
00120 #define KERN_EMERG
00121 #define KERN_ALERT
00122 #define KERN_CRIT
00123 #define KERN_WARNING
00124 #define KERN_NOTICE
00125 #define KERN_INFO
00126 #define KERN_DEBUG
00127 
00128 
00129 #define BUG() do { \
00130         printe("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __func__); \
00131 } while (0)
00132 
00133 #define BUG_ON(condition) do { if (condition) BUG(); } while(0)
00134 
00135 /* Force a compilation error if condition is true */
00136 #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
00137 
00138 #define __WARN() do { \
00139         printk("WARNING: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __func__); \
00140 } while (0)
00141 
00142 #define WARN_ON(condition) ({                                           \
00143         int __ret_warn_on = !!(condition);                              \
00144         if (unlikely(__ret_warn_on))                                    \
00145                 __WARN();                                               \
00146         unlikely(__ret_warn_on);                                        \
00147 })
00148 
00149 
00150 /****************\
00151         INTERRUPTS
00152 \****************/
00153 #define IRQ_NONE        POSIX_INTR_NOT_HANDLED
00154 #define IRQ_HANDLED POSIX_INTR_HANDLED_NOTIFY
00155 
00156 
00157 /********************\
00158         BIT OPERATIONS
00159 \********************/
00160 #define BITOP_ADDR(x) "=m" (*(volatile long *) (x))
00161 #define ADDR BITOP_ADDR(addr)
00162 #define BITS_PER_LONG           32
00163 
00164 static inline int fls(int x)
00165 {
00166         int r = 32;
00167 
00168         if (!x)
00169                 return 0;
00170         if (!(x & 0xffff0000u)) {
00171                 x <<= 16;
00172                 r -= 16;
00173         }
00174         if (!(x & 0xff000000u)) {
00175                 x <<= 8;
00176                 r -= 8;
00177         }
00178         if (!(x & 0xf0000000u)) {
00179                 x <<= 4;
00180                 r -= 4;
00181         }
00182         if (!(x & 0xc0000000u)) {
00183                 x <<= 2;
00184                 r -= 2;
00185         }
00186         if (!(x & 0x80000000u)) {
00187                 x <<= 1;
00188                 r -= 1;
00189         }
00190         return r;
00191 }
00192 
00193 static inline void __set_bit(int nr, volatile unsigned long *addr)
00194 {
00195         asm volatile("bts %1,%0" : ADDR : "Ir" (nr) : "memory");
00196 }
00197 
00198 static inline void __clear_bit(int nr, volatile unsigned long *addr)
00199 {
00200         asm volatile("btr %1,%0" : ADDR : "Ir" (nr));
00201 }
00202 
00203 static inline int get_bitmask_order(unsigned int count)
00204 {
00205         int order;
00206 
00207         order = fls(count);
00208         return order;   /* We could be slightly more clever with -1 here... */
00209 }
00210 
00211 static inline int constant_test_bit(int nr, const volatile unsigned long *addr)
00212 {
00213         return ((1UL << (nr % BITS_PER_LONG)) &
00214             (((unsigned long *)addr)[nr / BITS_PER_LONG])) != 0;
00215 }
00216 
00217 static inline int variable_test_bit(int nr, volatile const unsigned long *addr)
00218 {
00219         int oldbit;
00220 
00221         asm volatile("bt %2,%1\n\t"
00222                      "sbb %0,%0"
00223                      : "=r" (oldbit)
00224                      : "m" (*(unsigned long *)addr), "Ir" (nr));
00225 
00226         return oldbit;
00227 }
00228 
00229 #define test_bit(nr, addr)                      \
00230         (__builtin_constant_p((nr))             \
00231          ? constant_test_bit((nr), (addr))      \
00232          : variable_test_bit((nr), (addr)))
00233 
00234 #define BITS_PER_BYTE           8
00235 #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
00236 #define BITS_TO_LONGS(nr)       DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
00237 #define DECLARE_BITMAP(name,bits) \
00238         unsigned long name[BITS_TO_LONGS(bits)]
00239         
00240 
00241 /**********\
00242         MATH
00243 \**********/
00244 #define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y))
00245 #define max(x, y) ({                            \
00246         typeof(x) _max1 = (x);                  \
00247         typeof(y) _max2 = (y);                  \
00248         (void) (&_max1 == &_max2);              \
00249         _max1 > _max2 ? _max1 : _max2; })
00250 #define min(x, y) ({                            \
00251         typeof(x) _min1 = (x);                  \
00252         typeof(y) _min2 = (y);                  \
00253         (void) (&_min1 == &_min2);              \
00254         _min1 < _min2 ? _min1 : _min2; })
00255 
00260 static inline int ilog2(unsigned int n) {
00261   int pos = 0;
00262   if (n >= 1<<16) { n >>= 16; pos += 16; }
00263   if (n >= 1<< 8) { n >>=  8; pos +=  8; }
00264   if (n >= 1<< 4) { n >>=  4; pos +=  4; }
00265   if (n >= 1<< 2) { n >>=  2; pos +=  2; }
00266   if (n >= 1<< 1) {           pos +=  1; }
00267   return ((n == 0) ? (-1) : pos);
00268 }
00269 
00270 
00271 /***********\
00272         SLEEP
00273 \***********/
00274 #define udelay(u) do { \
00275         struct timespec ts = {0, u*1000}; \
00276         nanosleep (&ts, NULL); \
00277 } while (0);
00278 
00279 #define mdelay(u) do { \
00280         struct timespec ts = {0, u*1000*1000}; \
00281         nanosleep (&ts, NULL); \
00282 } while (0);
00283 
00284 
00285 /*****************\
00286         ERROR CODES
00287 \*****************/
00288 #define EPERM            1      /* Operation not permitted */
00289 #define ENOENT           2      /* No such file or directory */
00290 #define ESRCH            3      /* No such process */
00291 #define EINTR            4      /* Interrupted system call */
00292 #define EIO              5      /* I/O error */
00293 #define ENXIO            6      /* No such device or address */
00294 #define E2BIG            7      /* Argument list too long */
00295 #define ENOEXEC          8      /* Exec format error */
00296 #define EBADF            9      /* Bad file number */
00297 #define ECHILD          10      /* No child processes */
00298 #define EAGAIN          11      /* Try again */
00299 #define ENOMEM          12      /* Out of memory */
00300 #define EACCES          13      /* Permission denied */
00301 #define EFAULT          14      /* Bad address */
00302 #define ENOTBLK         15      /* Block device required */
00303 #define EBUSY           16      /* Device or resource busy */
00304 #define EEXIST          17      /* File exists */
00305 #define EXDEV           18      /* Cross-device link */
00306 #define ENODEV          19      /* No such device */
00307 #define ENOTDIR         20      /* Not a directory */
00308 #define EISDIR          21      /* Is a directory */
00309 #define EINVAL          22      /* Invalid argument */
00310 #define ENFILE          23      /* File table overflow */
00311 #define EMFILE          24      /* Too many open files */
00312 #define ENOTTY          25      /* Not a typewriter */
00313 #define ETXTBSY         26      /* Text file busy */
00314 #define EFBIG           27      /* File too large */
00315 #define ENOSPC          28      /* No space left on device */
00316 #define ESPIPE          29      /* Illegal seek */
00317 #define EROFS           30      /* Read-only file system */
00318 #define EMLINK          31      /* Too many links */
00319 #define EPIPE           32      /* Broken pipe */
00320 #define EDOM            33      /* Math argument out of domain of func */
00321 #define ERANGE          34      /* Math result not representable */
00322 #define EOPNOTSUPP      95      /* Operation not supported on transport endpoint */
00323 #define ETIMEDOUT       110     /* Connection timed out */
00324 #define EINPROGRESS     115     /* Operation now in progress */
00325 #define ENOTSUPP        524     /* Operation is not supported */
00326 #define MAX_ERRNO       4095
00327 #define NETDEV_TX_BUSY  1               /* driver tx path was busy*/
00328 #define NETDEV_TX_OK    0       /* driver took care of packet */
00329 
00330 #define IS_ERR(x) ((unsigned long)(x) >= (unsigned long)-MAX_ERRNO)
00331 #define PTR_ERR(x) ((unsigned long)(x))
00332 #define ERR_PTR(x) ((void *)(x))
00333 
00334 
00335 
00336 /*******************\
00337         SOCKET BUFFER
00338 \*******************/
00339 struct sk_buff
00340 {
00341         unsigned char *head;
00342         unsigned char *data;
00343         unsigned char *tail;
00344         unsigned char *end;
00345 
00346         unsigned int len;
00347 };
00348 
00349 static inline struct sk_buff *dev_alloc_skb (unsigned int len)
00350 {       
00351         struct sk_buff *skb = (struct sk_buff *) malloc(sizeof (struct sk_buff));
00352         if (!skb)
00353                 printe("Error instanciando sk_buff\n");
00354         
00355         skb->data = (unsigned char *)malloc(len);
00356         if (!skb->data)
00357                 printe("Error instanciando skb->data\n");
00358 
00359         memset(skb->data, 0, len);
00360         
00361         skb->head = skb->data;
00362         skb->tail = skb->data;
00363         skb->end  = skb->tail + len;
00364         skb->len  = 0;
00365 
00366         return skb;
00367 }
00368 
00369 #define dev_kfree_skb(a)        dev_kfree_skb_any(a)
00370 
00371 static inline void dev_kfree_skb_any(struct sk_buff *skb)
00372 {
00373         if (!skb)
00374                 return;
00375         else
00376                 free(skb);
00377 }
00378 
00379 static inline unsigned char *skb_put (struct sk_buff *skb, int len)
00380 {
00381         unsigned char *prev_tail = skb->tail;
00382 
00383         skb->tail += len;
00384         skb->len += len;
00385 
00386         return prev_tail;
00387 }
00388 
00389 static inline void skb_reserve(struct sk_buff *skb, int len)
00390 {
00391         skb->data += len;
00392         skb->tail += len;
00393 }
00394 
00395 static inline int skb_tailroom(const struct sk_buff *skb)
00396 {       
00397         return skb->end - skb->tail;
00398 }
00399 
00400 static inline unsigned int skb_headroom(const struct sk_buff *skb)
00401 {
00402         return skb->data - skb->head;
00403 }
00404 
00405 static inline unsigned char *skb_pull(struct sk_buff *skb, unsigned int len)
00406 {
00407         if (len > skb->len)
00408                 return NULL;
00409         else
00410         {
00411                 skb->len -= len;
00412                 return skb->data += len;
00413         }
00414 }
00415 
00416 static inline unsigned char *skb_push(struct sk_buff *skb, unsigned int len)
00417 {
00418         skb->data -= len;
00419         skb->len += len;
00420         if (skb->data < skb->head)
00421                 printe("skb_push: no hay suficiente espacio disponible");
00422 
00423         return skb->data;
00424 }
00425 
00426 static inline void skb_copy_from_linear_data(const struct sk_buff *skb,
00427                                              void *to,
00428                                              const unsigned int len)
00429 {
00430         memcpy(to, skb->data, len);
00431 }
00432 
00433 static inline void skb_copy_from_linear_data_offset(const struct sk_buff *skb,
00434                                                     const int offset, void *to,
00435                                                     const unsigned int len)
00436 {
00437         memcpy(to, skb->data + offset, len);
00438 }
00439 
00440 static inline void skb_copy_to_linear_data(struct sk_buff *skb,
00441                                            const void *from,
00442                                            const unsigned int len)
00443 {
00444         memcpy(skb->data, from, len);
00445 }
00446 
00447 static inline void skb_copy_to_linear_data_offset(struct sk_buff *skb,
00448                                                   const int offset,
00449                                                   const void *from,
00450                                                   const unsigned int len)
00451 {
00452         memcpy(skb->data + offset, from, len);
00453 }
00454 
00455 
00456 /****************\
00457         LINUX LIST
00458 \****************/
00459 #define list_first_entry(ptr, type, member) list_entry((ptr)->next, type, member)
00460 
00461 #endif
00462 


ros_rt_wmp
Author(s): Danilo Tardioli, dantard@unizar.es
autogenerated on Mon Oct 6 2014 08:27:09