patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / drivers / net / wireless / prism54 / islpci_dev.h
1 /*
2  *  
3  *  Copyright (C) 2002 Intersil Americas Inc. 
4  *  Copyright (C) 2003 Herbert Valerio Riedel <hvr@gnu.org>
5  *  Copyright (C) 2003 Luis R. Rodriguez <mcgrof@ruslug.rutgers.edu>
6  *  Copyright (C) 2003 Aurelien Alleaume <slts@free.fr>
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License
11  *
12  *  This program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with this program; if not, write to the Free Software
19  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  *
21  */
22
23 #ifndef _ISLPCI_DEV_H
24 #define _ISLPCI_DEV_H
25
26 #include <linux/version.h>
27 #include <linux/netdevice.h>
28 #include <linux/wireless.h>
29 #include <net/iw_handler.h>
30 #include <linux/list.h>
31
32 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,41)
33 # include <linux/workqueue.h>
34 #else
35 # include <linux/tqueue.h>
36 # define work_struct tq_struct
37 # define INIT_WORK INIT_TQUEUE
38 # define schedule_work schedule_task
39 #endif
40
41 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,23)
42 #define free_netdev(x) kfree(x) 
43 #define pci_name(x) x->slot_name 
44 #endif
45
46 #include "isl_38xx.h"
47 #include "isl_oid.h"
48 #include "islpci_mgt.h"
49
50 /* some states might not be superflous and may be removed when
51    design is finalized (hvr) */
52 typedef enum {
53         PRV_STATE_OFF = 0,      /* this means hw_unavailable is != 0 */
54         PRV_STATE_PREBOOT,      /* we are in a pre-boot state (empty RAM) */
55         PRV_STATE_BOOT,         /* boot state (fw upload, run fw) */
56         PRV_STATE_POSTBOOT,     /* after boot state, need reset now */
57         PRV_STATE_PREINIT,      /* pre-init state */
58         PRV_STATE_INIT,         /* init state (restore MIB backup to device) */
59         PRV_STATE_READY,        /* driver&device are in operational state */
60         PRV_STATE_SLEEP         /* device in sleep mode */
61 } islpci_state_t;
62
63 /* ACL using MAC address */
64 struct mac_entry {
65    struct list_head _list;
66    char addr[ETH_ALEN];
67 };
68
69 struct islpci_acl {
70    enum { MAC_POLICY_OPEN=0, MAC_POLICY_ACCEPT=1, MAC_POLICY_REJECT=2 } policy;
71    struct list_head mac_list;  /* a list of mac_entry */
72    int size;   /* size of queue */
73    struct semaphore sem;   /* accessed in ioctls and trap_work */
74 };
75
76 struct islpci_membuf {
77         int size;                   /* size of memory */
78         void *mem;                  /* address of memory as seen by CPU */
79         dma_addr_t pci_addr;        /* address of memory as seen by device */
80 };
81
82 #define MAX_BSS_WPA_IE_COUNT 64
83 #define MAX_WPA_IE_LEN 64
84 struct islpci_bss_wpa_ie {
85         struct list_head list;
86         unsigned long last_update;
87         u8 bssid[ETH_ALEN];
88         u8 wpa_ie[MAX_WPA_IE_LEN];
89         size_t wpa_ie_len;
90         
91 };
92
93 typedef struct {
94         spinlock_t slock;       /* generic spinlock; */
95         
96         u32 priv_oid;
97
98         /* our mib cache */
99         u32 iw_mode;
100         struct rw_semaphore mib_sem;
101         void **mib;
102         char nickname[IW_ESSID_MAX_SIZE+1];
103         
104         /* Take care of the wireless stats */
105         struct work_struct stats_work;
106         struct semaphore stats_sem;
107         /* remember when we last updated the stats */
108         unsigned long stats_timestamp;
109         /* The first is accessed under semaphore locking.
110          * The second is the clean one we return to iwconfig.
111          */
112         struct iw_statistics local_iwstatistics;
113         struct iw_statistics iwstatistics;
114
115         struct iw_spy_data spy_data; /* iwspy support */
116
117         int monitor_type; /* ARPHRD_IEEE80211 or ARPHRD_IEEE80211_PRISM */
118
119         struct islpci_acl acl;
120
121         /* PCI bus allocation & configuration members */
122         struct pci_dev *pdev;   /* PCI structure information */
123         u32 pci_state[16];      /* used for suspend/resume */
124         char firmware[33];
125
126         void *device_base;      /* ioremapped device base address */
127
128         /* consistent DMA region */
129         void *driver_mem_address;       /* base DMA address */
130         dma_addr_t device_host_address; /* base DMA address (bus address) */
131         dma_addr_t device_psm_buffer;   /* host memory for PSM buffering (bus address) */
132
133         /* our network_device structure  */
134         struct net_device *ndev;
135
136         /* device queue interface members */
137         struct isl38xx_cb *control_block;       /* device control block 
138                                                            (== driver_mem_address!) */
139
140         /* Each queue has three indexes:
141          *   free/index_mgmt/data_rx/tx (called index, see below),
142          *   driver_curr_frag, and device_curr_frag (in the control block)
143          * All indexes are ever-increasing, but interpreted modulo the
144          * device queue size when used.
145          *   index <= device_curr_frag <= driver_curr_frag  at all times
146          * For rx queues, [index, device_curr_frag) contains fragments
147          * that the interrupt processing needs to handle (owned by driver).
148          * [device_curr_frag, driver_curr_frag) is the free space in the
149          * rx queue, waiting for data (owned by device).  The driver
150          * increments driver_curr_frag to indicate to the device that more
151          * buffers are available.
152          * If device_curr_frag == driver_curr_frag, no more rx buffers are
153          * available, and the rx DMA engine of the device is halted.
154          * For tx queues, [index, device_curr_frag) contains fragments
155          * where tx is done; they need to be freed (owned by driver).
156          * [device_curr_frag, driver_curr_frag) contains the frames
157          * that are being transferred (owned by device).  The driver
158          * increments driver_curr_frag to indicate that more tx work
159          * needs to be done.
160          */
161         u32 index_mgmt_rx;              /* real index mgmt rx queue */
162         u32 index_mgmt_tx;              /* read index mgmt tx queue */
163         u32 free_data_rx;       /* free pointer data rx queue */
164         u32 free_data_tx;       /* free pointer data tx queue */
165         u32 data_low_tx_full;   /* full detected flag */
166
167         /* frame memory buffers for the device queues */
168         struct islpci_membuf mgmt_tx[ISL38XX_CB_MGMT_QSIZE];
169         struct islpci_membuf mgmt_rx[ISL38XX_CB_MGMT_QSIZE];
170         struct sk_buff *data_low_tx[ISL38XX_CB_TX_QSIZE];
171         struct sk_buff *data_low_rx[ISL38XX_CB_RX_QSIZE];
172         dma_addr_t pci_map_tx_address[ISL38XX_CB_TX_QSIZE];
173         dma_addr_t pci_map_rx_address[ISL38XX_CB_RX_QSIZE];
174
175         /* driver network interface members */
176         struct net_device_stats statistics;
177
178         /* wait for a reset interrupt */
179         wait_queue_head_t reset_done;
180
181         /* used by islpci_mgt_transaction */
182         struct semaphore mgmt_sem; /* serialize access to mailbox and wqueue */
183         struct islpci_mgmtframe *mgmt_received;   /* mbox for incoming frame */
184         wait_queue_head_t mgmt_wqueue;            /* waitqueue for mbox */
185
186         /* state machine */
187         islpci_state_t state;
188         int state_off;          /* enumeration of off-state, if 0 then
189                                  * we're not in any off-state */
190         
191         /* WPA stuff */
192         int wpa; /* WPA mode enabled */
193         struct list_head bss_wpa_list;
194         int num_bss_wpa;
195         struct semaphore wpa_sem;
196
197         struct work_struct reset_task;
198         int reset_task_pending;
199 } islpci_private;
200
201 static inline islpci_state_t
202 islpci_get_state(islpci_private *priv)
203 {
204         /* lock */
205         return priv->state;
206         /* unlock */
207 }
208
209 islpci_state_t islpci_set_state(islpci_private *priv, islpci_state_t new_state);
210
211 #define ISLPCI_TX_TIMEOUT               (2*HZ)
212
213 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,5,75))
214 # define irqreturn_t void
215 # define IRQ_HANDLED
216 # define IRQ_NONE
217 #endif
218
219 irqreturn_t islpci_interrupt(int, void *, struct pt_regs *);
220
221 int prism54_post_setup(islpci_private *, int);
222 int islpci_reset(islpci_private *, int);
223
224 static inline void
225 islpci_trigger(islpci_private *priv)
226 {
227         isl38xx_trigger_device(islpci_get_state(priv) == PRV_STATE_SLEEP,
228                                priv->device_base);
229 }
230
231 struct net_device_stats *islpci_statistics(struct net_device *);
232
233 int prism54_bring_down(islpci_private *);
234 int islpci_alloc_memory(islpci_private *);
235 int islpci_free_memory(islpci_private *);
236 struct net_device *islpci_setup(struct pci_dev *);
237 #endif                          /* _ISLPCI_DEV_H */