Home | History | Annotate | Download | only in inc
      1 /****************************************************************************
      2 **+-----------------------------------------------------------------------+**
      3 **|                                                                       |**
      4 **| Copyright(c) 1998 - 2008 Texas Instruments. All rights reserved.      |**
      5 **| All rights reserved.                                                  |**
      6 **|                                                                       |**
      7 **| Redistribution and use in source and binary forms, with or without    |**
      8 **| modification, are permitted provided that the following conditions    |**
      9 **| are met:                                                              |**
     10 **|                                                                       |**
     11 **|  * Redistributions of source code must retain the above copyright     |**
     12 **|    notice, this list of conditions and the following disclaimer.      |**
     13 **|  * Redistributions in binary form must reproduce the above copyright  |**
     14 **|    notice, this list of conditions and the following disclaimer in    |**
     15 **|    the documentation and/or other materials provided with the         |**
     16 **|    distribution.                                                      |**
     17 **|  * Neither the name Texas Instruments nor the names of its            |**
     18 **|    contributors may be used to endorse or promote products derived    |**
     19 **|    from this software without specific prior written permission.      |**
     20 **|                                                                       |**
     21 **| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS   |**
     22 **| "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT     |**
     23 **| LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |**
     24 **| A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT  |**
     25 **| OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |**
     26 **| SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT      |**
     27 **| LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |**
     28 **| DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |**
     29 **| THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT   |**
     30 **| (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |**
     31 **| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  |**
     32 **|                                                                       |**
     33 **+-----------------------------------------------------------------------+**
     34 ****************************************************************************/
     35 
     36 
     37 #ifndef ESTA_DRV_INCLUDE_FILE
     38 #define ESTA_DRV_INCLUDE_FILE
     39 
     40 #include <linux/version.h>
     41 #include <linux/completion.h>
     42 #include <linux/netdevice.h>
     43 #include <linux/interrupt.h>
     44 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27)
     45 #include <asm/arch/gpio.h>
     46 #ifdef CONFIG_ANDROID_POWER
     47 #include <linux/android_power.h>
     48 #endif
     49 #else
     50 #include <asm/gpio.h>
     51 #ifdef CONFIG_HAS_WAKELOCK
     52 #include <linux/wakelock.h>
     53 #endif
     54 #endif
     55 
     56 #ifdef CONFIG_TROUT_PWRSINK
     57 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27)
     58 #include <asm/arch/trout_pwrsink.h>
     59 #else
     60 #include <mach/trout_pwrsink.h>
     61 #endif
     62 #endif
     63 
     64 #ifdef CONFIG_HTC_PWRSINK
     65 #include <mach/htc_pwrsink.h>
     66 #endif
     67 
     68 #include "osTIType.h"
     69 #include "osAdapter.h"
     70 #include "paramOut.h"
     71 #ifndef GWSI_DRIVER /* for GWSI Stand Alone */
     72 #include "configMgr.h"
     73 #endif
     74 #include "linux_ioctl_common.h"
     75 
     76 #define TIWLAN_DRV_NAME    "tiwlan"
     77 #define TIWLAN_DRV_IF_NAME TIWLAN_DRV_NAME"%d"
     78 #define TIWLAN_DRV_NAME_WIRELESS_PROTO "IEEE 802.11-DS"
     79 #define TIWLAN_DBG_PROC    "wifidbg"
     80 
     81 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29)
     82 #define NETDEV_SET_PRIVATE(dev, drv)	dev->priv = drv
     83 #define NETDEV_GET_PRIVATE(dev)		dev->priv
     84 #else
     85 #define NETDEV_SET_PRIVATE(dev, drv)	dev->ml_priv = drv
     86 #define NETDEV_GET_PRIVATE(dev)		dev->ml_priv
     87 #endif
     88 
     89 void *wifi_kernel_prealloc(int section, unsigned long size);
     90 
     91 #ifdef TIWLAN_MSM7000
     92 #ifdef CONFIG_WIFI_CONTROL_FUNC
     93 #include <linux/platform_device.h>
     94 #include <linux/wifi_tiwlan.h>
     95 int msm_wifi_power(int on);
     96 int msm_wifi_reset(int on);
     97 #else
     98 extern int trout_wifi_power(int on);
     99 extern int trout_wifi_reset(int on);
    100 extern int trout_wifi_set_carddetect(int val);
    101 #define msm_wifi_power(a)       trout_wifi_power(a)
    102 #define msm_wifi_reset(a)       trout_wifi_reset(a)
    103 #endif
    104 #endif
    105 
    106 #ifdef CONFIG_HAS_WAKELOCK
    107 #define CONFIG_ANDROID_POWER
    108 typedef struct wake_lock android_suspend_lock_t;
    109 #define android_unlock_suspend(a)             wake_unlock(a)
    110 #define android_lock_suspend(a)               wake_lock(a)
    111 #define android_lock_suspend_auto_expire(a,t) wake_lock_timeout(a,t)
    112 #define android_init_suspend_wakelock(a,n)    wake_lock_init(a,WAKE_LOCK_SUSPEND,n)
    113 #define android_uninit_suspend_lock(a)        wake_lock_destroy(a)
    114 #endif
    115 
    116 #ifndef TIWLAN_OMAP1610_REGBASE
    117 
    118 #if defined(TIWLAN_OMAP1610_INNOVATOR)
    119 #define TIWLAN_OMAP1610_REGBASE 0xEC100000    /* VA*/
    120 #elif defined(TIWLAN_OMAP1610_WIPP) || defined(TIWLAN_OMAP1610_CRTWIPP)
    121 #ifndef OMAP_WLAN_BASE
    122 #define OMAP_WLAN_BASE  0
    123 #endif
    124 #define TIWLAN_OMAP1610_REGBASE (OMAP_WLAN_BASE+0x100000)
    125 #else
    126 /* Dm: #error TIWLAN_OMAP1610_REGBASE not defined for this platform */
    127 #endif
    128 
    129 #endif /* #ifndef TIWLAN_OMAP1610_REGBASE */
    130 
    131 #ifdef TIWLAN_OMAP1610_REGBASE
    132 
    133 #define TIWLAN_OMAP1610_REGSIZE 0x10000
    134 #define TIWLAN_OMAP1610_MEMBASE (TIWLAN_OMAP1610_REGBASE | 0x20000)
    135 #define TIWLAN_OMAP1610_MEMSIZE 0x10000
    136 
    137 #endif /* #ifdef TIWLAN_OMAP1610_REGBASE */
    138 
    139 #ifndef TIWLAN_OMAP1610_IRQ
    140 
    141 #if defined(TIWLAN_OMAP1610_INNOVATOR)
    142 #define TIWLAN_OMAP1610_IRQ     (OMAP_GPIO_IRQ(8))
    143 #elif defined(TIWLAN_OMAP1610_CRTWIPP)
    144 #define TIWLAN_OMAP1610_IRQ     (OMAP_GPIO_IRQ(2))
    145 #elif defined(TIWLAN_OMAP1610_WIPP)
    146 #define TIWLAN_OMAP1610_IRQ     (OMAP_GPIO_IRQ(2))
    147 #endif
    148 
    149 #endif /* TIWLAN_OMAP1610_IRQ */
    150 #define TIWLAN_IRQ_POLL_INTERVAL  HZ/100  /* Used when no Intr are handled from the FW */
    151 
    152 
    153 #ifdef TI_DBG
    154 #define ti_dprintf(log, fmt, args...) do { \
    155    if (log != TIWLAN_LOG_OTHER) {   \
    156       printk(KERN_INFO fmt, ## args); \
    157    } \
    158 } while (0)
    159 #else
    160 #define ti_dprintf(log, fmt, args...)
    161 #endif
    162 
    163 
    164 #define ti_nodprintf(log, fmt, args...)
    165 
    166 typedef enum {
    167    TIWLAN_LOG_ERROR,
    168    TIWLAN_LOG_INFO,
    169    TIWLAN_LOG_OTHER,
    170    TIWLAN_LOG_DUMMY
    171 } tiwlan_log_t;
    172 
    173 typedef struct tiwlan_region {
    174       unsigned long pa;
    175       void *va;
    176       unsigned long size;
    177 } tiwlan_region_t;
    178 
    179 /* Driver structure */
    180 typedef struct tiwlan_net_dev tiwlan_net_dev_t;
    181 
    182 #if defined (__KERNEL__)
    183 /* Request/response to/from control tasklet */
    184 typedef struct tiwlan_req {
    185       struct list_head list;
    186       tiwlan_net_dev_t *drv;
    187       struct
    188       {
    189             struct {
    190                   int (*f)(struct tiwlan_req *req);
    191                   unsigned long p1;
    192                   unsigned long p2;
    193                   unsigned long p3;
    194                   unsigned long p4;
    195                   int reply_expected;     /* 1=reply expected */
    196                   struct completion comp;
    197             } req;
    198             int reply;
    199       } u;
    200 } tiwlan_req_t;
    201 
    202 /* Timer structure */
    203 typedef struct timer_obj {
    204       tiwlan_req_t req;
    205          /* Timer handler function ->p1 */
    206          /* Timer handler function parameter ->p2 */
    207          /* Periodic ->p3 */
    208          /* jiffies ->p4 */
    209       struct timer_list  timer;
    210       int use_count;
    211 } timer_obj_t;
    212 
    213 
    214 #ifdef DRIVER_PROFILING
    215 
    216 /* Profiler banchmark function type */
    217 typedef void (*tiwlan_pfofile_t) (void*, unsigned);
    218 
    219 /* Maximum number of profile banchmarks */
    220 #define MAX_PROFILE_BM 10
    221 
    222 #endif
    223 
    224 #if defined(CONFIG_TROUT_PWRSINK) || defined(CONFIG_HTC_PWRSINK)
    225 #define PWRSINK_WIFI_PERCENT_BASE 4
    226 #endif
    227 
    228 /* #define DM_USE_WORKQUEUE */
    229 
    230 /* Driver structure */
    231 struct tiwlan_net_dev {
    232       struct list_head list;
    233 
    234       tiwlan_region_t acx_mem;
    235       tiwlan_region_t acx_reg;
    236       tiwlan_region_t eeprom_image;
    237       tiwlan_region_t firmware_image;
    238       int irq;
    239 #ifdef DM_USE_WORKQUEUE
    240       struct workqueue_struct *tiwlan_wq; /* Work Queue */
    241       struct work_struct tirq;         /* Work Task for interrupt */
    242       struct work_struct tw;           /* Work Task for other stuff */
    243       mem_MSDU_T *txmit_msdu_next;
    244       mem_MSDU_T *txmit_msdu_last;
    245       struct work_struct txmit;        /* Work Task for transmit */
    246 #else
    247       struct tasklet_struct tl;        /* Control tasklet */
    248 #endif
    249 #if defined(CONFIG_TROUT_PWRSINK) || defined(CONFIG_HTC_PWRSINK)
    250       struct delayed_work trxw;        /* Work Task for rx watchdog */
    251 #endif
    252 #ifdef CONFIG_ANDROID_POWER
    253       android_suspend_lock_t irq_wake_lock; /* Suspend Lock to keep system awake */
    254       android_suspend_lock_t xmit_wake_lock;
    255       android_suspend_lock_t timer_wake_lock;
    256       android_suspend_lock_t rx_wake_lock;
    257       android_suspend_lock_t exec_wake_lock;
    258       int receive_packet;              /* 1=packet was pushed to network stack */
    259 #endif
    260       int interrupt_pending;           /* 1=tasklet has to handle interrupts when awakes */
    261       int dma_done;
    262       struct list_head request_q;      /* Requests queue: -> tasklet */
    263       spinlock_t lock;
    264       unsigned long flags;
    265       struct timer_list poll_timer;    /* Polling timer. Used only when working without interrupts */
    266       int started;                     /* 1=config manager started. 0=config manager stopped */
    267       int initialized;                 /* 1=succeeded to pass init stage, 0=otherwise */
    268       int unload_driver;               /* Driver unload indicator */
    269       struct net_device_stats stats;
    270       int alloc_msdu_failures;         /* Extra statistics */
    271       initTable_t  init_table;
    272       TIWLN_ADAPTER_T adapter;
    273       struct sock *wl_sock;
    274       struct completion comp;
    275       struct net_device *netdev;
    276       void *priv;                      /* Pointer to struct net_device */
    277 
    278 #ifdef DRIVER_PROFILING
    279       tiwlan_pfofile_t fpro [MAX_PROFILE_BM];   /* Profiler functions */
    280 
    281       unsigned max_number_of_timers;            /* Maximum number of allocated timers */
    282       unsigned cur_number_of_timers;            /* Current number of allocated timers */
    283 
    284       unsigned max_heap_bytes_allocated;        /* Maximum number of allocated bytes on the heap */
    285       unsigned cur_heap_bytes_allocated;        /* Current number of allocated bytes on the heap */
    286       unsigned max_buf_bytes_allocated;         /* Maximum number of allocated bytes on the heap for TX/RX buffers */
    287 
    288       unsigned cpu_usage_estimator_start_time;  /* Time measured when CPU estimation was started */
    289       unsigned cpu_usage_estimator_stop_time;   /* Time measured when CPU estimation was stopped */
    290       unsigned cpu_usage_estimator_resolution;  /* Resolution of the CPU estimation in us */
    291       unsigned total_us_of_cpu_time;            /* Total number of CPU time used by the driver since CPU estimator started */
    292       unsigned total_us_of_bus_access_cpu_time; /* Total number of CPU time used by the bus driver since CPU estimator started */
    293       unsigned driver_entry_start_time;         /* Time measured at the start of last driver entry point */
    294       unsigned bus_driver_entry_start_time;     /* Time measured at the start of last bus driver entry point */
    295 #endif
    296 
    297 #ifdef GWSI_DRIVER
    298       void *gwsi;                      /* GWSI manager handler */
    299       void *gwsi_ev;                   /* GWSI event handler */
    300       char  gwsi_tester_buf [4096];    /* GWSI tester buffer */
    301 #endif
    302 };
    303 
    304 
    305 #define VENDOR_ID_TI            0x104c
    306 #define DEVICE_ID_TI_WLAN       0x9066
    307 
    308 /* tiwlan_send_wait_reply
    309    This internal interface function creates request and sends
    310    it to the control tasklet for processing.
    311    The calling process is blocked until the request is replied.
    312    Function f is being called in the context of the control tasklet.
    313    The request block that is passed to the function as a parameter
    314    contains p1, p2, p3, p4.
    315    The function return code is propagated back to the caller.
    316    tiwlan_send_req_and_wait returns (*f) return code or
    317    -ENOMEM if failed to allocate a request.
    318 */
    319 int tiwlan_send_wait_reply(tiwlan_net_dev_t *drv,
    320                            int (*f)(tiwlan_req_t *req),
    321                            unsigned long p1,
    322                            unsigned long p2,
    323                            unsigned long p3,
    324                            unsigned long p4);
    325 
    326 #endif /* #if defined (__KERNEL__)*/
    327 
    328 int tiwlan_init_drv(tiwlan_net_dev_t *drv, tiwlan_dev_init_t *init_info);
    329 int tiwlan_start_drv(tiwlan_net_dev_t *drv);
    330 int tiwlan_stop_drv(tiwlan_net_dev_t *drv);
    331 int tiwlan_stop_and_destroy_drv(tiwlan_net_dev_t *drv);
    332 int tiwlan_stop_and_destroy_drv_request(tiwlan_req_t *req);
    333 int tiwlan_ioctl_init(struct net_device *dev);
    334 
    335 #endif /* ESTA_DRV_INCLUDE_FILE*/
    336