blob: 0d7305dfa6903a590370425c13e1a4596e27ca1a [file] [log] [blame]
Jouni Malinenff1d2762005-05-12 22:54:16 -04001#define PRISM2_PCI
2
3/* Host AP driver's support for Intersil Prism2.5 PCI cards is based on
4 * driver patches from Reyk Floeter <reyk@vantronix.net> and
5 * Andy Warner <andyw@pobox.com> */
6
7#include <linux/config.h>
8#include <linux/version.h>
9#include <linux/module.h>
10#include <linux/init.h>
11#include <linux/if.h>
12#include <linux/skbuff.h>
13#include <linux/netdevice.h>
14#include <linux/workqueue.h>
15#include <linux/wireless.h>
16#include <net/iw_handler.h>
17
18#include <linux/ioport.h>
19#include <linux/pci.h>
20#include <asm/io.h>
21
22#include "hostap_wlan.h"
23
24
25static char *version = PRISM2_VERSION " (Jouni Malinen <jkmaline@cc.hut.fi>)";
26static char *dev_info = "hostap_pci";
27
28
29MODULE_AUTHOR("Jouni Malinen");
30MODULE_DESCRIPTION("Support for Intersil Prism2.5-based 802.11 wireless LAN "
31 "PCI cards.");
32MODULE_SUPPORTED_DEVICE("Intersil Prism2.5-based WLAN PCI cards");
33MODULE_LICENSE("GPL");
Jouni Malinenf06ac312005-07-30 12:50:00 -070034MODULE_VERSION(PRISM2_VERSION);
Jouni Malinenff1d2762005-05-12 22:54:16 -040035
36
Jouni Malinen67e0e472005-08-14 19:08:41 -070037/* struct local_info::hw_priv */
38struct hostap_pci_priv {
39 void __iomem *mem_start;
40};
41
42
Jouni Malinenff1d2762005-05-12 22:54:16 -040043/* FIX: do we need mb/wmb/rmb with memory operations? */
44
45
46static struct pci_device_id prism2_pci_id_table[] __devinitdata = {
47 /* Intersil Prism3 ISL3872 11Mb/s WLAN Controller */
48 { 0x1260, 0x3872, PCI_ANY_ID, PCI_ANY_ID },
49 /* Intersil Prism2.5 ISL3874 11Mb/s WLAN Controller */
50 { 0x1260, 0x3873, PCI_ANY_ID, PCI_ANY_ID },
51 /* Samsung MagicLAN SWL-2210P */
52 { 0x167d, 0xa000, PCI_ANY_ID, PCI_ANY_ID },
53 { 0 }
54};
55
56
57#ifdef PRISM2_IO_DEBUG
58
59static inline void hfa384x_outb_debug(struct net_device *dev, int a, u8 v)
60{
61 struct hostap_interface *iface;
Jouni Malinenf7a74442005-10-02 17:18:59 -070062 struct hostap_pci_priv *hw_priv;
Jouni Malinenff1d2762005-05-12 22:54:16 -040063 local_info_t *local;
64 unsigned long flags;
65
66 iface = netdev_priv(dev);
67 local = iface->local;
Jouni Malinenf7a74442005-10-02 17:18:59 -070068 hw_priv = local->hw_priv;
Jouni Malinenff1d2762005-05-12 22:54:16 -040069
70 spin_lock_irqsave(&local->lock, flags);
71 prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_OUTB, a, v);
Jouni Malinen67e0e472005-08-14 19:08:41 -070072 writeb(v, hw_priv->mem_start + a);
Jouni Malinenff1d2762005-05-12 22:54:16 -040073 spin_unlock_irqrestore(&local->lock, flags);
74}
75
76static inline u8 hfa384x_inb_debug(struct net_device *dev, int a)
77{
78 struct hostap_interface *iface;
Jouni Malinenf7a74442005-10-02 17:18:59 -070079 struct hostap_pci_priv *hw_priv;
Jouni Malinenff1d2762005-05-12 22:54:16 -040080 local_info_t *local;
81 unsigned long flags;
82 u8 v;
83
84 iface = netdev_priv(dev);
85 local = iface->local;
Jouni Malinenf7a74442005-10-02 17:18:59 -070086 hw_priv = local->hw_priv;
Jouni Malinenff1d2762005-05-12 22:54:16 -040087
88 spin_lock_irqsave(&local->lock, flags);
Jouni Malinen67e0e472005-08-14 19:08:41 -070089 v = readb(hw_priv->mem_start + a);
Jouni Malinenff1d2762005-05-12 22:54:16 -040090 prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_INB, a, v);
91 spin_unlock_irqrestore(&local->lock, flags);
92 return v;
93}
94
95static inline void hfa384x_outw_debug(struct net_device *dev, int a, u16 v)
96{
97 struct hostap_interface *iface;
Jouni Malinenf7a74442005-10-02 17:18:59 -070098 struct hostap_pci_priv *hw_priv;
Jouni Malinenff1d2762005-05-12 22:54:16 -040099 local_info_t *local;
100 unsigned long flags;
101
102 iface = netdev_priv(dev);
103 local = iface->local;
Jouni Malinenf7a74442005-10-02 17:18:59 -0700104 hw_priv = local->hw_priv;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400105
106 spin_lock_irqsave(&local->lock, flags);
107 prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_OUTW, a, v);
Jouni Malinen67e0e472005-08-14 19:08:41 -0700108 writew(v, hw_priv->mem_start + a);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400109 spin_unlock_irqrestore(&local->lock, flags);
110}
111
112static inline u16 hfa384x_inw_debug(struct net_device *dev, int a)
113{
114 struct hostap_interface *iface;
Jouni Malinenf7a74442005-10-02 17:18:59 -0700115 struct hostap_pci_priv *hw_priv;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400116 local_info_t *local;
117 unsigned long flags;
118 u16 v;
119
120 iface = netdev_priv(dev);
121 local = iface->local;
Jouni Malinenf7a74442005-10-02 17:18:59 -0700122 hw_priv = local->hw_priv;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400123
124 spin_lock_irqsave(&local->lock, flags);
Jouni Malinen67e0e472005-08-14 19:08:41 -0700125 v = readw(hw_priv->mem_start + a);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400126 prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_INW, a, v);
127 spin_unlock_irqrestore(&local->lock, flags);
128 return v;
129}
130
131#define HFA384X_OUTB(v,a) hfa384x_outb_debug(dev, (a), (v))
132#define HFA384X_INB(a) hfa384x_inb_debug(dev, (a))
133#define HFA384X_OUTW(v,a) hfa384x_outw_debug(dev, (a), (v))
134#define HFA384X_INW(a) hfa384x_inw_debug(dev, (a))
135#define HFA384X_OUTW_DATA(v,a) hfa384x_outw_debug(dev, (a), cpu_to_le16((v)))
136#define HFA384X_INW_DATA(a) (u16) le16_to_cpu(hfa384x_inw_debug(dev, (a)))
137
138#else /* PRISM2_IO_DEBUG */
139
140static inline void hfa384x_outb(struct net_device *dev, int a, u8 v)
141{
142 struct hostap_interface *iface;
Jouni Malinen67e0e472005-08-14 19:08:41 -0700143 struct hostap_pci_priv *hw_priv;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400144 iface = netdev_priv(dev);
Jouni Malinen67e0e472005-08-14 19:08:41 -0700145 hw_priv = iface->local->hw_priv;
146 writeb(v, hw_priv->mem_start + a);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400147}
148
149static inline u8 hfa384x_inb(struct net_device *dev, int a)
150{
151 struct hostap_interface *iface;
Jouni Malinen67e0e472005-08-14 19:08:41 -0700152 struct hostap_pci_priv *hw_priv;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400153 iface = netdev_priv(dev);
Jouni Malinen67e0e472005-08-14 19:08:41 -0700154 hw_priv = iface->local->hw_priv;
155 return readb(hw_priv->mem_start + a);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400156}
157
158static inline void hfa384x_outw(struct net_device *dev, int a, u16 v)
159{
160 struct hostap_interface *iface;
Jouni Malinen67e0e472005-08-14 19:08:41 -0700161 struct hostap_pci_priv *hw_priv;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400162 iface = netdev_priv(dev);
Jouni Malinen67e0e472005-08-14 19:08:41 -0700163 hw_priv = iface->local->hw_priv;
164 writew(v, hw_priv->mem_start + a);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400165}
166
167static inline u16 hfa384x_inw(struct net_device *dev, int a)
168{
169 struct hostap_interface *iface;
Jouni Malinen67e0e472005-08-14 19:08:41 -0700170 struct hostap_pci_priv *hw_priv;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400171 iface = netdev_priv(dev);
Jouni Malinen67e0e472005-08-14 19:08:41 -0700172 hw_priv = iface->local->hw_priv;
173 return readw(hw_priv->mem_start + a);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400174}
175
176#define HFA384X_OUTB(v,a) hfa384x_outb(dev, (a), (v))
177#define HFA384X_INB(a) hfa384x_inb(dev, (a))
178#define HFA384X_OUTW(v,a) hfa384x_outw(dev, (a), (v))
179#define HFA384X_INW(a) hfa384x_inw(dev, (a))
180#define HFA384X_OUTW_DATA(v,a) hfa384x_outw(dev, (a), cpu_to_le16((v)))
181#define HFA384X_INW_DATA(a) (u16) le16_to_cpu(hfa384x_inw(dev, (a)))
182
183#endif /* PRISM2_IO_DEBUG */
184
185
186static int hfa384x_from_bap(struct net_device *dev, u16 bap, void *buf,
187 int len)
188{
189 u16 d_off;
190 u16 *pos;
191
192 d_off = (bap == 1) ? HFA384X_DATA1_OFF : HFA384X_DATA0_OFF;
193 pos = (u16 *) buf;
194
195 for ( ; len > 1; len -= 2)
196 *pos++ = HFA384X_INW_DATA(d_off);
197
198 if (len & 1)
199 *((char *) pos) = HFA384X_INB(d_off);
200
201 return 0;
202}
203
204
205static int hfa384x_to_bap(struct net_device *dev, u16 bap, void *buf, int len)
206{
207 u16 d_off;
208 u16 *pos;
209
210 d_off = (bap == 1) ? HFA384X_DATA1_OFF : HFA384X_DATA0_OFF;
211 pos = (u16 *) buf;
212
213 for ( ; len > 1; len -= 2)
214 HFA384X_OUTW_DATA(*pos++, d_off);
215
216 if (len & 1)
217 HFA384X_OUTB(*((char *) pos), d_off);
218
219 return 0;
220}
221
222
223/* FIX: This might change at some point.. */
224#include "hostap_hw.c"
225
226static void prism2_pci_cor_sreset(local_info_t *local)
227{
228 struct net_device *dev = local->dev;
229 u16 reg;
230
231 reg = HFA384X_INB(HFA384X_PCICOR_OFF);
232 printk(KERN_DEBUG "%s: Original COR value: 0x%0x\n", dev->name, reg);
233
234 /* linux-wlan-ng uses extremely long hold and settle times for
235 * COR sreset. A comment in the driver code mentions that the long
236 * delays appear to be necessary. However, at least IBM 22P6901 seems
237 * to work fine with shorter delays.
238 *
239 * Longer delays can be configured by uncommenting following line: */
240/* #define PRISM2_PCI_USE_LONG_DELAYS */
241
242#ifdef PRISM2_PCI_USE_LONG_DELAYS
243 int i;
244
245 HFA384X_OUTW(reg | 0x0080, HFA384X_PCICOR_OFF);
246 mdelay(250);
247
248 HFA384X_OUTW(reg & ~0x0080, HFA384X_PCICOR_OFF);
249 mdelay(500);
250
251 /* Wait for f/w to complete initialization (CMD:BUSY == 0) */
252 i = 2000000 / 10;
253 while ((HFA384X_INW(HFA384X_CMD_OFF) & HFA384X_CMD_BUSY) && --i)
254 udelay(10);
255
256#else /* PRISM2_PCI_USE_LONG_DELAYS */
257
258 HFA384X_OUTW(reg | 0x0080, HFA384X_PCICOR_OFF);
259 mdelay(2);
260 HFA384X_OUTW(reg & ~0x0080, HFA384X_PCICOR_OFF);
261 mdelay(2);
262
263#endif /* PRISM2_PCI_USE_LONG_DELAYS */
264
265 if (HFA384X_INW(HFA384X_CMD_OFF) & HFA384X_CMD_BUSY) {
266 printk(KERN_DEBUG "%s: COR sreset timeout\n", dev->name);
267 }
268}
269
270
271static void prism2_pci_genesis_reset(local_info_t *local, int hcr)
272{
273 struct net_device *dev = local->dev;
274
275 HFA384X_OUTW(0x00C5, HFA384X_PCICOR_OFF);
276 mdelay(10);
277 HFA384X_OUTW(hcr, HFA384X_PCIHCR_OFF);
278 mdelay(10);
279 HFA384X_OUTW(0x0045, HFA384X_PCICOR_OFF);
280 mdelay(10);
281}
282
283
284static struct prism2_helper_functions prism2_pci_funcs =
285{
286 .card_present = NULL,
287 .cor_sreset = prism2_pci_cor_sreset,
Jouni Malinenff1d2762005-05-12 22:54:16 -0400288 .genesis_reset = prism2_pci_genesis_reset,
289 .hw_type = HOSTAP_HW_PCI,
290};
291
292
293static int prism2_pci_probe(struct pci_dev *pdev,
294 const struct pci_device_id *id)
295{
296 unsigned long phymem;
297 void __iomem *mem = NULL;
298 local_info_t *local = NULL;
299 struct net_device *dev = NULL;
300 static int cards_found /* = 0 */;
301 int irq_registered = 0;
302 struct hostap_interface *iface;
Jouni Malinen67e0e472005-08-14 19:08:41 -0700303 struct hostap_pci_priv *hw_priv;
304
305 hw_priv = kmalloc(sizeof(*hw_priv), GFP_KERNEL);
306 if (hw_priv == NULL)
307 return -ENOMEM;
308 memset(hw_priv, 0, sizeof(*hw_priv));
Jouni Malinenff1d2762005-05-12 22:54:16 -0400309
310 if (pci_enable_device(pdev))
311 return -EIO;
312
313 phymem = pci_resource_start(pdev, 0);
314
315 if (!request_mem_region(phymem, pci_resource_len(pdev, 0), "Prism2")) {
316 printk(KERN_ERR "prism2: Cannot reserve PCI memory region\n");
317 goto err_out_disable;
318 }
319
320 mem = ioremap(phymem, pci_resource_len(pdev, 0));
321 if (mem == NULL) {
322 printk(KERN_ERR "prism2: Cannot remap PCI memory region\n") ;
323 goto fail;
324 }
325
Dave Hansen0cd545d2005-07-30 12:49:58 -0700326 dev = prism2_init_local_data(&prism2_pci_funcs, cards_found,
327 &pdev->dev);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400328 if (dev == NULL)
329 goto fail;
330 iface = netdev_priv(dev);
331 local = iface->local;
Jouni Malinen67e0e472005-08-14 19:08:41 -0700332 local->hw_priv = hw_priv;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400333 cards_found++;
334
335 dev->irq = pdev->irq;
Jouni Malinen67e0e472005-08-14 19:08:41 -0700336 hw_priv->mem_start = mem;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400337
338 prism2_pci_cor_sreset(local);
339
340 pci_set_drvdata(pdev, dev);
341
342 if (request_irq(dev->irq, prism2_interrupt, SA_SHIRQ, dev->name,
343 dev)) {
344 printk(KERN_WARNING "%s: request_irq failed\n", dev->name);
345 goto fail;
346 } else
347 irq_registered = 1;
348
349 if (!local->pri_only && prism2_hw_config(dev, 1)) {
350 printk(KERN_DEBUG "%s: hardware initialization failed\n",
351 dev_info);
352 goto fail;
353 }
354
355 printk(KERN_INFO "%s: Intersil Prism2.5 PCI: "
356 "mem=0x%lx, irq=%d\n", dev->name, phymem, dev->irq);
357
358 return hostap_hw_ready(dev);
359
360 fail:
Jouni Malinen67e0e472005-08-14 19:08:41 -0700361 kfree(hw_priv);
362
Jouni Malinenff1d2762005-05-12 22:54:16 -0400363 if (irq_registered && dev)
364 free_irq(dev->irq, dev);
365
366 if (mem)
367 iounmap(mem);
368
369 release_mem_region(phymem, pci_resource_len(pdev, 0));
370
371 err_out_disable:
372 pci_disable_device(pdev);
Jouni Malinen67e0e472005-08-14 19:08:41 -0700373 kfree(hw_priv);
374 if (local)
375 local->hw_priv = NULL;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400376 prism2_free_local_data(dev);
377
378 return -ENODEV;
379}
380
381
382static void prism2_pci_remove(struct pci_dev *pdev)
383{
384 struct net_device *dev;
385 struct hostap_interface *iface;
386 void __iomem *mem_start;
Jouni Malinen67e0e472005-08-14 19:08:41 -0700387 struct hostap_pci_priv *hw_priv;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400388
389 dev = pci_get_drvdata(pdev);
390 iface = netdev_priv(dev);
Jouni Malinen67e0e472005-08-14 19:08:41 -0700391 hw_priv = iface->local->hw_priv;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400392
393 /* Reset the hardware, and ensure interrupts are disabled. */
394 prism2_pci_cor_sreset(iface->local);
395 hfa384x_disable_interrupts(dev);
396
397 if (dev->irq)
398 free_irq(dev->irq, dev);
399
Jouni Malinen67e0e472005-08-14 19:08:41 -0700400 mem_start = hw_priv->mem_start;
401 kfree(hw_priv);
402 iface->local->hw_priv = NULL;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400403 prism2_free_local_data(dev);
404
405 iounmap(mem_start);
406
407 release_mem_region(pci_resource_start(pdev, 0),
408 pci_resource_len(pdev, 0));
409 pci_disable_device(pdev);
410}
411
412
413#ifdef CONFIG_PM
Andrew Mortonb2dabd52005-07-13 00:33:46 -0700414static int prism2_pci_suspend(struct pci_dev *pdev, pm_message_t state)
Jouni Malinenff1d2762005-05-12 22:54:16 -0400415{
416 struct net_device *dev = pci_get_drvdata(pdev);
417
418 if (netif_running(dev)) {
419 netif_stop_queue(dev);
420 netif_device_detach(dev);
421 }
422 prism2_suspend(dev);
423 pci_save_state(pdev);
424 pci_disable_device(pdev);
Pavel Machek583a4e82005-09-03 15:56:58 -0700425 pci_set_power_state(pdev, PCI_D3hot);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400426
427 return 0;
428}
429
430static int prism2_pci_resume(struct pci_dev *pdev)
431{
432 struct net_device *dev = pci_get_drvdata(pdev);
433
434 pci_enable_device(pdev);
435 pci_restore_state(pdev);
436 prism2_hw_config(dev, 0);
437 if (netif_running(dev)) {
438 netif_device_attach(dev);
439 netif_start_queue(dev);
440 }
441
442 return 0;
443}
444#endif /* CONFIG_PM */
445
446
447MODULE_DEVICE_TABLE(pci, prism2_pci_id_table);
448
449static struct pci_driver prism2_pci_drv_id = {
Pavel Roskin7a716532005-09-23 21:58:58 -0700450 .name = "hostap_pci",
Jouni Malinenff1d2762005-05-12 22:54:16 -0400451 .id_table = prism2_pci_id_table,
452 .probe = prism2_pci_probe,
453 .remove = prism2_pci_remove,
454#ifdef CONFIG_PM
455 .suspend = prism2_pci_suspend,
456 .resume = prism2_pci_resume,
457#endif /* CONFIG_PM */
458 /* Linux 2.4.6 added save_state and enable_wake that are not used here
459 */
460};
461
462
463static int __init init_prism2_pci(void)
464{
465 printk(KERN_INFO "%s: %s\n", dev_info, version);
466
467 return pci_register_driver(&prism2_pci_drv_id);
468}
469
470
471static void __exit exit_prism2_pci(void)
472{
473 pci_unregister_driver(&prism2_pci_drv_id);
474 printk(KERN_INFO "%s: Driver unloaded\n", dev_info);
475}
476
477
478module_init(init_prism2_pci);
479module_exit(exit_prism2_pci);