blob: d24dc7dc072328fcecab649193ed4cbad0c17caa [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
Jouni Malinenff1d2762005-05-12 22:54:16 -04007#include <linux/module.h>
8#include <linux/init.h>
9#include <linux/if.h>
10#include <linux/skbuff.h>
11#include <linux/netdevice.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090012#include <linux/slab.h>
Jouni Malinenff1d2762005-05-12 22:54:16 -040013#include <linux/workqueue.h>
14#include <linux/wireless.h>
15#include <net/iw_handler.h>
16
17#include <linux/ioport.h>
18#include <linux/pci.h>
19#include <asm/io.h>
20
21#include "hostap_wlan.h"
22
23
Jouni Malinenff1d2762005-05-12 22:54:16 -040024static char *dev_info = "hostap_pci";
25
26
27MODULE_AUTHOR("Jouni Malinen");
28MODULE_DESCRIPTION("Support for Intersil Prism2.5-based 802.11 wireless LAN "
29 "PCI cards.");
30MODULE_SUPPORTED_DEVICE("Intersil Prism2.5-based WLAN PCI cards");
31MODULE_LICENSE("GPL");
32
33
Jouni Malinen67e0e472005-08-14 19:08:41 -070034/* struct local_info::hw_priv */
35struct hostap_pci_priv {
36 void __iomem *mem_start;
37};
38
39
Jouni Malinenff1d2762005-05-12 22:54:16 -040040/* FIX: do we need mb/wmb/rmb with memory operations? */
41
42
Alexey Dobriyana3aa1882010-01-07 11:58:11 +000043static DEFINE_PCI_DEVICE_TABLE(prism2_pci_id_table) = {
Jouni Malinenff1d2762005-05-12 22:54:16 -040044 /* Intersil Prism3 ISL3872 11Mb/s WLAN Controller */
45 { 0x1260, 0x3872, PCI_ANY_ID, PCI_ANY_ID },
46 /* Intersil Prism2.5 ISL3874 11Mb/s WLAN Controller */
47 { 0x1260, 0x3873, PCI_ANY_ID, PCI_ANY_ID },
48 /* Samsung MagicLAN SWL-2210P */
49 { 0x167d, 0xa000, PCI_ANY_ID, PCI_ANY_ID },
50 { 0 }
51};
52
53
54#ifdef PRISM2_IO_DEBUG
55
56static inline void hfa384x_outb_debug(struct net_device *dev, int a, u8 v)
57{
58 struct hostap_interface *iface;
Jouni Malinenf7a74442005-10-02 17:18:59 -070059 struct hostap_pci_priv *hw_priv;
Jouni Malinenff1d2762005-05-12 22:54:16 -040060 local_info_t *local;
61 unsigned long flags;
62
63 iface = netdev_priv(dev);
64 local = iface->local;
Jouni Malinenf7a74442005-10-02 17:18:59 -070065 hw_priv = local->hw_priv;
Jouni Malinenff1d2762005-05-12 22:54:16 -040066
67 spin_lock_irqsave(&local->lock, flags);
68 prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_OUTB, a, v);
Jouni Malinen67e0e472005-08-14 19:08:41 -070069 writeb(v, hw_priv->mem_start + a);
Jouni Malinenff1d2762005-05-12 22:54:16 -040070 spin_unlock_irqrestore(&local->lock, flags);
71}
72
73static inline u8 hfa384x_inb_debug(struct net_device *dev, int a)
74{
75 struct hostap_interface *iface;
Jouni Malinenf7a74442005-10-02 17:18:59 -070076 struct hostap_pci_priv *hw_priv;
Jouni Malinenff1d2762005-05-12 22:54:16 -040077 local_info_t *local;
78 unsigned long flags;
79 u8 v;
80
81 iface = netdev_priv(dev);
82 local = iface->local;
Jouni Malinenf7a74442005-10-02 17:18:59 -070083 hw_priv = local->hw_priv;
Jouni Malinenff1d2762005-05-12 22:54:16 -040084
85 spin_lock_irqsave(&local->lock, flags);
Jouni Malinen67e0e472005-08-14 19:08:41 -070086 v = readb(hw_priv->mem_start + a);
Jouni Malinenff1d2762005-05-12 22:54:16 -040087 prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_INB, a, v);
88 spin_unlock_irqrestore(&local->lock, flags);
89 return v;
90}
91
92static inline void hfa384x_outw_debug(struct net_device *dev, int a, u16 v)
93{
94 struct hostap_interface *iface;
Jouni Malinenf7a74442005-10-02 17:18:59 -070095 struct hostap_pci_priv *hw_priv;
Jouni Malinenff1d2762005-05-12 22:54:16 -040096 local_info_t *local;
97 unsigned long flags;
98
99 iface = netdev_priv(dev);
100 local = iface->local;
Jouni Malinenf7a74442005-10-02 17:18:59 -0700101 hw_priv = local->hw_priv;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400102
103 spin_lock_irqsave(&local->lock, flags);
104 prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_OUTW, a, v);
Jouni Malinen67e0e472005-08-14 19:08:41 -0700105 writew(v, hw_priv->mem_start + a);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400106 spin_unlock_irqrestore(&local->lock, flags);
107}
108
109static inline u16 hfa384x_inw_debug(struct net_device *dev, int a)
110{
111 struct hostap_interface *iface;
Jouni Malinenf7a74442005-10-02 17:18:59 -0700112 struct hostap_pci_priv *hw_priv;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400113 local_info_t *local;
114 unsigned long flags;
115 u16 v;
116
117 iface = netdev_priv(dev);
118 local = iface->local;
Jouni Malinenf7a74442005-10-02 17:18:59 -0700119 hw_priv = local->hw_priv;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400120
121 spin_lock_irqsave(&local->lock, flags);
Jouni Malinen67e0e472005-08-14 19:08:41 -0700122 v = readw(hw_priv->mem_start + a);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400123 prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_INW, a, v);
124 spin_unlock_irqrestore(&local->lock, flags);
125 return v;
126}
127
128#define HFA384X_OUTB(v,a) hfa384x_outb_debug(dev, (a), (v))
129#define HFA384X_INB(a) hfa384x_inb_debug(dev, (a))
130#define HFA384X_OUTW(v,a) hfa384x_outw_debug(dev, (a), (v))
131#define HFA384X_INW(a) hfa384x_inw_debug(dev, (a))
Al Viro8a9faf32007-12-21 03:30:16 -0500132#define HFA384X_OUTW_DATA(v,a) hfa384x_outw_debug(dev, (a), le16_to_cpu((v)))
133#define HFA384X_INW_DATA(a) cpu_to_le16(hfa384x_inw_debug(dev, (a)))
Jouni Malinenff1d2762005-05-12 22:54:16 -0400134
135#else /* PRISM2_IO_DEBUG */
136
137static inline void hfa384x_outb(struct net_device *dev, int a, u8 v)
138{
139 struct hostap_interface *iface;
Jouni Malinen67e0e472005-08-14 19:08:41 -0700140 struct hostap_pci_priv *hw_priv;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400141 iface = netdev_priv(dev);
Jouni Malinen67e0e472005-08-14 19:08:41 -0700142 hw_priv = iface->local->hw_priv;
143 writeb(v, hw_priv->mem_start + a);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400144}
145
146static inline u8 hfa384x_inb(struct net_device *dev, int a)
147{
148 struct hostap_interface *iface;
Jouni Malinen67e0e472005-08-14 19:08:41 -0700149 struct hostap_pci_priv *hw_priv;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400150 iface = netdev_priv(dev);
Jouni Malinen67e0e472005-08-14 19:08:41 -0700151 hw_priv = iface->local->hw_priv;
152 return readb(hw_priv->mem_start + a);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400153}
154
155static inline void hfa384x_outw(struct net_device *dev, int a, u16 v)
156{
157 struct hostap_interface *iface;
Jouni Malinen67e0e472005-08-14 19:08:41 -0700158 struct hostap_pci_priv *hw_priv;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400159 iface = netdev_priv(dev);
Jouni Malinen67e0e472005-08-14 19:08:41 -0700160 hw_priv = iface->local->hw_priv;
161 writew(v, hw_priv->mem_start + a);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400162}
163
164static inline u16 hfa384x_inw(struct net_device *dev, int a)
165{
166 struct hostap_interface *iface;
Jouni Malinen67e0e472005-08-14 19:08:41 -0700167 struct hostap_pci_priv *hw_priv;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400168 iface = netdev_priv(dev);
Jouni Malinen67e0e472005-08-14 19:08:41 -0700169 hw_priv = iface->local->hw_priv;
170 return readw(hw_priv->mem_start + a);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400171}
172
173#define HFA384X_OUTB(v,a) hfa384x_outb(dev, (a), (v))
174#define HFA384X_INB(a) hfa384x_inb(dev, (a))
175#define HFA384X_OUTW(v,a) hfa384x_outw(dev, (a), (v))
176#define HFA384X_INW(a) hfa384x_inw(dev, (a))
Al Viro8a9faf32007-12-21 03:30:16 -0500177#define HFA384X_OUTW_DATA(v,a) hfa384x_outw(dev, (a), le16_to_cpu((v)))
178#define HFA384X_INW_DATA(a) cpu_to_le16(hfa384x_inw(dev, (a)))
Jouni Malinenff1d2762005-05-12 22:54:16 -0400179
180#endif /* PRISM2_IO_DEBUG */
181
182
183static int hfa384x_from_bap(struct net_device *dev, u16 bap, void *buf,
184 int len)
185{
186 u16 d_off;
Al Viro8a9faf32007-12-21 03:30:16 -0500187 __le16 *pos;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400188
189 d_off = (bap == 1) ? HFA384X_DATA1_OFF : HFA384X_DATA0_OFF;
Al Viro8a9faf32007-12-21 03:30:16 -0500190 pos = (__le16 *) buf;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400191
192 for ( ; len > 1; len -= 2)
193 *pos++ = HFA384X_INW_DATA(d_off);
194
195 if (len & 1)
196 *((char *) pos) = HFA384X_INB(d_off);
197
198 return 0;
199}
200
201
202static int hfa384x_to_bap(struct net_device *dev, u16 bap, void *buf, int len)
203{
204 u16 d_off;
Al Viro8a9faf32007-12-21 03:30:16 -0500205 __le16 *pos;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400206
207 d_off = (bap == 1) ? HFA384X_DATA1_OFF : HFA384X_DATA0_OFF;
Al Viro8a9faf32007-12-21 03:30:16 -0500208 pos = (__le16 *) buf;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400209
210 for ( ; len > 1; len -= 2)
211 HFA384X_OUTW_DATA(*pos++, d_off);
212
213 if (len & 1)
214 HFA384X_OUTB(*((char *) pos), d_off);
215
216 return 0;
217}
218
219
220/* FIX: This might change at some point.. */
221#include "hostap_hw.c"
222
223static void prism2_pci_cor_sreset(local_info_t *local)
224{
225 struct net_device *dev = local->dev;
226 u16 reg;
227
228 reg = HFA384X_INB(HFA384X_PCICOR_OFF);
229 printk(KERN_DEBUG "%s: Original COR value: 0x%0x\n", dev->name, reg);
230
231 /* linux-wlan-ng uses extremely long hold and settle times for
232 * COR sreset. A comment in the driver code mentions that the long
233 * delays appear to be necessary. However, at least IBM 22P6901 seems
234 * to work fine with shorter delays.
235 *
236 * Longer delays can be configured by uncommenting following line: */
237/* #define PRISM2_PCI_USE_LONG_DELAYS */
238
239#ifdef PRISM2_PCI_USE_LONG_DELAYS
240 int i;
241
242 HFA384X_OUTW(reg | 0x0080, HFA384X_PCICOR_OFF);
243 mdelay(250);
244
245 HFA384X_OUTW(reg & ~0x0080, HFA384X_PCICOR_OFF);
246 mdelay(500);
247
248 /* Wait for f/w to complete initialization (CMD:BUSY == 0) */
249 i = 2000000 / 10;
250 while ((HFA384X_INW(HFA384X_CMD_OFF) & HFA384X_CMD_BUSY) && --i)
251 udelay(10);
252
253#else /* PRISM2_PCI_USE_LONG_DELAYS */
254
255 HFA384X_OUTW(reg | 0x0080, HFA384X_PCICOR_OFF);
256 mdelay(2);
257 HFA384X_OUTW(reg & ~0x0080, HFA384X_PCICOR_OFF);
258 mdelay(2);
259
260#endif /* PRISM2_PCI_USE_LONG_DELAYS */
261
262 if (HFA384X_INW(HFA384X_CMD_OFF) & HFA384X_CMD_BUSY) {
263 printk(KERN_DEBUG "%s: COR sreset timeout\n", dev->name);
264 }
265}
266
267
268static void prism2_pci_genesis_reset(local_info_t *local, int hcr)
269{
270 struct net_device *dev = local->dev;
271
272 HFA384X_OUTW(0x00C5, HFA384X_PCICOR_OFF);
273 mdelay(10);
274 HFA384X_OUTW(hcr, HFA384X_PCIHCR_OFF);
275 mdelay(10);
276 HFA384X_OUTW(0x0045, HFA384X_PCICOR_OFF);
277 mdelay(10);
278}
279
280
281static struct prism2_helper_functions prism2_pci_funcs =
282{
283 .card_present = NULL,
284 .cor_sreset = prism2_pci_cor_sreset,
Jouni Malinenff1d2762005-05-12 22:54:16 -0400285 .genesis_reset = prism2_pci_genesis_reset,
286 .hw_type = HOSTAP_HW_PCI,
287};
288
289
290static int prism2_pci_probe(struct pci_dev *pdev,
291 const struct pci_device_id *id)
292{
293 unsigned long phymem;
294 void __iomem *mem = NULL;
295 local_info_t *local = NULL;
296 struct net_device *dev = NULL;
297 static int cards_found /* = 0 */;
298 int irq_registered = 0;
299 struct hostap_interface *iface;
Jouni Malinen67e0e472005-08-14 19:08:41 -0700300 struct hostap_pci_priv *hw_priv;
301
Yan Burmanb0471bb72006-12-02 13:33:40 +0200302 hw_priv = kzalloc(sizeof(*hw_priv), GFP_KERNEL);
Jouni Malinen67e0e472005-08-14 19:08:41 -0700303 if (hw_priv == NULL)
304 return -ENOMEM;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400305
306 if (pci_enable_device(pdev))
Jouni Malinen93201992006-03-19 19:21:49 -0800307 goto err_out_free;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400308
309 phymem = pci_resource_start(pdev, 0);
310
311 if (!request_mem_region(phymem, pci_resource_len(pdev, 0), "Prism2")) {
312 printk(KERN_ERR "prism2: Cannot reserve PCI memory region\n");
313 goto err_out_disable;
314 }
315
Arjan van de Ven275f1652008-10-20 21:42:39 -0700316 mem = pci_ioremap_bar(pdev, 0);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400317 if (mem == NULL) {
318 printk(KERN_ERR "prism2: Cannot remap PCI memory region\n") ;
319 goto fail;
320 }
321
Dave Hansen0cd545d2005-07-30 12:49:58 -0700322 dev = prism2_init_local_data(&prism2_pci_funcs, cards_found,
323 &pdev->dev);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400324 if (dev == NULL)
325 goto fail;
326 iface = netdev_priv(dev);
327 local = iface->local;
Jouni Malinen67e0e472005-08-14 19:08:41 -0700328 local->hw_priv = hw_priv;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400329 cards_found++;
330
331 dev->irq = pdev->irq;
Jouni Malinen67e0e472005-08-14 19:08:41 -0700332 hw_priv->mem_start = mem;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400333
334 prism2_pci_cor_sreset(local);
335
336 pci_set_drvdata(pdev, dev);
337
Thomas Gleixner1fb9df52006-07-01 19:29:39 -0700338 if (request_irq(dev->irq, prism2_interrupt, IRQF_SHARED, dev->name,
Jouni Malinenff1d2762005-05-12 22:54:16 -0400339 dev)) {
340 printk(KERN_WARNING "%s: request_irq failed\n", dev->name);
341 goto fail;
342 } else
343 irq_registered = 1;
344
345 if (!local->pri_only && prism2_hw_config(dev, 1)) {
346 printk(KERN_DEBUG "%s: hardware initialization failed\n",
347 dev_info);
348 goto fail;
349 }
350
351 printk(KERN_INFO "%s: Intersil Prism2.5 PCI: "
352 "mem=0x%lx, irq=%d\n", dev->name, phymem, dev->irq);
353
354 return hostap_hw_ready(dev);
355
356 fail:
357 if (irq_registered && dev)
358 free_irq(dev->irq, dev);
359
360 if (mem)
361 iounmap(mem);
362
363 release_mem_region(phymem, pci_resource_len(pdev, 0));
364
365 err_out_disable:
366 pci_disable_device(pdev);
367 prism2_free_local_data(dev);
Jouni Malinen93201992006-03-19 19:21:49 -0800368
369 err_out_free:
Jouni Malinenc3551842005-10-02 17:19:00 -0700370 kfree(hw_priv);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400371
372 return -ENODEV;
373}
374
375
376static void prism2_pci_remove(struct pci_dev *pdev)
377{
378 struct net_device *dev;
379 struct hostap_interface *iface;
380 void __iomem *mem_start;
Jouni Malinen67e0e472005-08-14 19:08:41 -0700381 struct hostap_pci_priv *hw_priv;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400382
383 dev = pci_get_drvdata(pdev);
384 iface = netdev_priv(dev);
Jouni Malinen67e0e472005-08-14 19:08:41 -0700385 hw_priv = iface->local->hw_priv;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400386
387 /* Reset the hardware, and ensure interrupts are disabled. */
388 prism2_pci_cor_sreset(iface->local);
389 hfa384x_disable_interrupts(dev);
390
391 if (dev->irq)
392 free_irq(dev->irq, dev);
393
Jouni Malinen67e0e472005-08-14 19:08:41 -0700394 mem_start = hw_priv->mem_start;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400395 prism2_free_local_data(dev);
Jouni Malinenc3551842005-10-02 17:19:00 -0700396 kfree(hw_priv);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400397
398 iounmap(mem_start);
399
400 release_mem_region(pci_resource_start(pdev, 0),
401 pci_resource_len(pdev, 0));
402 pci_disable_device(pdev);
403}
404
405
406#ifdef CONFIG_PM
Andrew Mortonb2dabd52005-07-13 00:33:46 -0700407static int prism2_pci_suspend(struct pci_dev *pdev, pm_message_t state)
Jouni Malinenff1d2762005-05-12 22:54:16 -0400408{
409 struct net_device *dev = pci_get_drvdata(pdev);
410
411 if (netif_running(dev)) {
412 netif_stop_queue(dev);
413 netif_device_detach(dev);
414 }
415 prism2_suspend(dev);
416 pci_save_state(pdev);
417 pci_disable_device(pdev);
Pavel Machek583a4e82005-09-03 15:56:58 -0700418 pci_set_power_state(pdev, PCI_D3hot);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400419
420 return 0;
421}
422
423static int prism2_pci_resume(struct pci_dev *pdev)
424{
425 struct net_device *dev = pci_get_drvdata(pdev);
John W. Linville02e0e5e2006-11-07 20:53:48 -0500426 int err;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400427
John W. Linville02e0e5e2006-11-07 20:53:48 -0500428 err = pci_enable_device(pdev);
429 if (err) {
430 printk(KERN_ERR "%s: pci_enable_device failed on resume\n",
431 dev->name);
432 return err;
433 }
Jouni Malinenff1d2762005-05-12 22:54:16 -0400434 pci_restore_state(pdev);
435 prism2_hw_config(dev, 0);
436 if (netif_running(dev)) {
437 netif_device_attach(dev);
438 netif_start_queue(dev);
439 }
440
441 return 0;
442}
443#endif /* CONFIG_PM */
444
445
446MODULE_DEVICE_TABLE(pci, prism2_pci_id_table);
447
Randy Dunlap2493d8e2007-10-29 11:20:26 -0700448static struct pci_driver prism2_pci_driver = {
Pavel Roskin7a716532005-09-23 21:58:58 -0700449 .name = "hostap_pci",
Jouni Malinenff1d2762005-05-12 22:54:16 -0400450 .id_table = prism2_pci_id_table,
451 .probe = prism2_pci_probe,
452 .remove = prism2_pci_remove,
453#ifdef CONFIG_PM
454 .suspend = prism2_pci_suspend,
455 .resume = prism2_pci_resume,
456#endif /* CONFIG_PM */
Jouni Malinenff1d2762005-05-12 22:54:16 -0400457};
458
459
460static int __init init_prism2_pci(void)
461{
Randy Dunlap2493d8e2007-10-29 11:20:26 -0700462 return pci_register_driver(&prism2_pci_driver);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400463}
464
465
466static void __exit exit_prism2_pci(void)
467{
Randy Dunlap2493d8e2007-10-29 11:20:26 -0700468 pci_unregister_driver(&prism2_pci_driver);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400469}
470
471
472module_init(init_prism2_pci);
473module_exit(exit_prism2_pci);