1 // SPDX-License-Identifier: GPL-2.0-only
4 * Linux device driver for PCI based Prism54
6 * Copyright (c) 2006, Michael Wu <flamingice@sourmilk.net>
7 * Copyright (c) 2008, Christian Lamparter <chunkeey@web.de>
9 * Based on the islsm (softmac prism54) driver, which is:
10 * Copyright 2004-2006 Jean-Baptiste Note <jean-baptiste.note@m4x.org>, et al.
13 #include <linux/pci.h>
14 #include <linux/slab.h>
15 #include <linux/firmware.h>
16 #include <linux/etherdevice.h>
17 #include <linux/delay.h>
18 #include <linux/completion.h>
19 #include <linux/module.h>
20 #include <net/mac80211.h>
26 MODULE_AUTHOR("Michael Wu <flamingice@sourmilk.net>");
27 MODULE_DESCRIPTION("Prism54 PCI wireless driver");
28 MODULE_LICENSE("GPL");
29 MODULE_ALIAS("prism54pci");
30 MODULE_FIRMWARE("isl3886pci");
32 static const struct pci_device_id p54p_table
[] = {
33 /* Intersil PRISM Duette/Prism GT Wireless LAN adapter */
34 { PCI_DEVICE(0x1260, 0x3890) },
35 /* 3COM 3CRWE154G72 Wireless LAN adapter */
36 { PCI_DEVICE(0x10b7, 0x6001) },
37 /* Intersil PRISM Indigo Wireless LAN adapter */
38 { PCI_DEVICE(0x1260, 0x3877) },
39 /* Intersil PRISM Javelin/Xbow Wireless LAN adapter */
40 { PCI_DEVICE(0x1260, 0x3886) },
41 /* Intersil PRISM Xbow Wireless LAN adapter (Symbol AP-300) */
42 { PCI_DEVICE(0x1260, 0xffff) },
46 MODULE_DEVICE_TABLE(pci
, p54p_table
);
48 static int p54p_upload_firmware(struct ieee80211_hw
*dev
)
50 struct p54p_priv
*priv
= dev
->priv
;
54 u32 remains
, left
, device_addr
;
56 P54P_WRITE(int_enable
, cpu_to_le32(0));
57 P54P_READ(int_enable
);
60 reg
= P54P_READ(ctrl_stat
);
61 reg
&= cpu_to_le32(~ISL38XX_CTRL_STAT_RESET
);
62 reg
&= cpu_to_le32(~ISL38XX_CTRL_STAT_RAMBOOT
);
63 P54P_WRITE(ctrl_stat
, reg
);
67 reg
|= cpu_to_le32(ISL38XX_CTRL_STAT_RESET
);
68 P54P_WRITE(ctrl_stat
, reg
);
72 reg
&= cpu_to_le32(~ISL38XX_CTRL_STAT_RESET
);
73 P54P_WRITE(ctrl_stat
, reg
);
76 /* wait for the firmware to reset properly */
79 err
= p54_parse_firmware(dev
, priv
->firmware
);
83 if (priv
->common
.fw_interface
!= FW_LM86
) {
84 dev_err(&priv
->pdev
->dev
, "wrong firmware, "
85 "please get a LM86(PCI) firmware a try again.\n");
89 data
= (__le32
*) priv
->firmware
->data
;
90 remains
= priv
->firmware
->size
;
91 device_addr
= ISL38XX_DEV_FIRMWARE_ADDR
;
94 left
= min((u32
)0x1000, remains
);
95 P54P_WRITE(direct_mem_base
, cpu_to_le32(device_addr
));
96 P54P_READ(int_enable
);
98 device_addr
+= 0x1000;
100 P54P_WRITE(direct_mem_win
[i
], *data
++);
105 P54P_READ(int_enable
);
108 reg
= P54P_READ(ctrl_stat
);
109 reg
&= cpu_to_le32(~ISL38XX_CTRL_STAT_CLKRUN
);
110 reg
&= cpu_to_le32(~ISL38XX_CTRL_STAT_RESET
);
111 reg
|= cpu_to_le32(ISL38XX_CTRL_STAT_RAMBOOT
);
112 P54P_WRITE(ctrl_stat
, reg
);
113 P54P_READ(ctrl_stat
);
116 reg
|= cpu_to_le32(ISL38XX_CTRL_STAT_RESET
);
117 P54P_WRITE(ctrl_stat
, reg
);
121 reg
&= cpu_to_le32(~ISL38XX_CTRL_STAT_RESET
);
122 P54P_WRITE(ctrl_stat
, reg
);
126 /* wait for the firmware to boot properly */
132 static void p54p_refill_rx_ring(struct ieee80211_hw
*dev
,
133 int ring_index
, struct p54p_desc
*ring
, u32 ring_limit
,
134 struct sk_buff
**rx_buf
, u32 index
)
136 struct p54p_priv
*priv
= dev
->priv
;
137 struct p54p_ring_control
*ring_control
= priv
->ring_control
;
140 idx
= le32_to_cpu(ring_control
->host_idx
[ring_index
]);
143 limit
= ring_limit
- limit
;
145 i
= idx
% ring_limit
;
146 while (limit
-- > 1) {
147 struct p54p_desc
*desc
= &ring
[i
];
149 if (!desc
->host_addr
) {
152 skb
= dev_alloc_skb(priv
->common
.rx_mtu
+ 32);
156 mapping
= dma_map_single(&priv
->pdev
->dev
,
157 skb_tail_pointer(skb
),
158 priv
->common
.rx_mtu
+ 32,
161 if (dma_mapping_error(&priv
->pdev
->dev
, mapping
)) {
162 dev_kfree_skb_any(skb
);
163 dev_err(&priv
->pdev
->dev
,
164 "RX DMA Mapping error\n");
168 desc
->host_addr
= cpu_to_le32(mapping
);
169 desc
->device_addr
= 0; // FIXME: necessary?
170 desc
->len
= cpu_to_le16(priv
->common
.rx_mtu
+ 32);
181 ring_control
->host_idx
[ring_index
] = cpu_to_le32(idx
);
184 static void p54p_check_rx_ring(struct ieee80211_hw
*dev
, u32
*index
,
185 int ring_index
, struct p54p_desc
*ring
, u32 ring_limit
,
186 struct sk_buff
**rx_buf
)
188 struct p54p_priv
*priv
= dev
->priv
;
189 struct p54p_ring_control
*ring_control
= priv
->ring_control
;
190 struct p54p_desc
*desc
;
193 i
= (*index
) % ring_limit
;
194 (*index
) = idx
= le32_to_cpu(ring_control
->device_idx
[ring_index
]);
201 len
= le16_to_cpu(desc
->len
);
210 if (unlikely(len
> priv
->common
.rx_mtu
)) {
212 dev_err(&priv
->pdev
->dev
, "rx'd frame size "
213 "exceeds length threshold.\n");
215 len
= priv
->common
.rx_mtu
;
217 dma_addr
= le32_to_cpu(desc
->host_addr
);
218 dma_sync_single_for_cpu(&priv
->pdev
->dev
, dma_addr
,
219 priv
->common
.rx_mtu
+ 32,
223 if (p54_rx(dev
, skb
)) {
224 dma_unmap_single(&priv
->pdev
->dev
, dma_addr
,
225 priv
->common
.rx_mtu
+ 32,
228 desc
->host_addr
= cpu_to_le32(0);
231 dma_sync_single_for_device(&priv
->pdev
->dev
, dma_addr
,
232 priv
->common
.rx_mtu
+ 32,
234 desc
->len
= cpu_to_le16(priv
->common
.rx_mtu
+ 32);
241 p54p_refill_rx_ring(dev
, ring_index
, ring
, ring_limit
, rx_buf
, *index
);
244 static void p54p_check_tx_ring(struct ieee80211_hw
*dev
, u32
*index
,
245 int ring_index
, struct p54p_desc
*ring
, u32 ring_limit
,
246 struct sk_buff
**tx_buf
)
248 struct p54p_priv
*priv
= dev
->priv
;
249 struct p54p_ring_control
*ring_control
= priv
->ring_control
;
250 struct p54p_desc
*desc
;
254 i
= (*index
) % ring_limit
;
255 (*index
) = idx
= le32_to_cpu(ring_control
->device_idx
[ring_index
]);
264 dma_unmap_single(&priv
->pdev
->dev
,
265 le32_to_cpu(desc
->host_addr
),
266 le16_to_cpu(desc
->len
), DMA_TO_DEVICE
);
269 desc
->device_addr
= 0;
273 if (skb
&& FREE_AFTER_TX(skb
))
274 p54_free_skb(dev
, skb
);
281 static void p54p_tasklet(struct tasklet_struct
*t
)
283 struct p54p_priv
*priv
= from_tasklet(priv
, t
, tasklet
);
284 struct ieee80211_hw
*dev
= pci_get_drvdata(priv
->pdev
);
285 struct p54p_ring_control
*ring_control
= priv
->ring_control
;
287 p54p_check_tx_ring(dev
, &priv
->tx_idx_mgmt
, 3, ring_control
->tx_mgmt
,
288 ARRAY_SIZE(ring_control
->tx_mgmt
),
291 p54p_check_tx_ring(dev
, &priv
->tx_idx_data
, 1, ring_control
->tx_data
,
292 ARRAY_SIZE(ring_control
->tx_data
),
295 p54p_check_rx_ring(dev
, &priv
->rx_idx_mgmt
, 2, ring_control
->rx_mgmt
,
296 ARRAY_SIZE(ring_control
->rx_mgmt
), priv
->rx_buf_mgmt
);
298 p54p_check_rx_ring(dev
, &priv
->rx_idx_data
, 0, ring_control
->rx_data
,
299 ARRAY_SIZE(ring_control
->rx_data
), priv
->rx_buf_data
);
302 P54P_WRITE(dev_int
, cpu_to_le32(ISL38XX_DEV_INT_UPDATE
));
305 static irqreturn_t
p54p_interrupt(int irq
, void *dev_id
)
307 struct ieee80211_hw
*dev
= dev_id
;
308 struct p54p_priv
*priv
= dev
->priv
;
311 reg
= P54P_READ(int_ident
);
312 if (unlikely(reg
== cpu_to_le32(0xFFFFFFFF))) {
315 P54P_WRITE(int_ack
, reg
);
317 reg
&= P54P_READ(int_enable
);
319 if (reg
& cpu_to_le32(ISL38XX_INT_IDENT_UPDATE
))
320 tasklet_schedule(&priv
->tasklet
);
321 else if (reg
& cpu_to_le32(ISL38XX_INT_IDENT_INIT
))
322 complete(&priv
->boot_comp
);
325 return reg
? IRQ_HANDLED
: IRQ_NONE
;
328 static void p54p_tx(struct ieee80211_hw
*dev
, struct sk_buff
*skb
)
331 struct p54p_priv
*priv
= dev
->priv
;
332 struct p54p_ring_control
*ring_control
= priv
->ring_control
;
333 struct p54p_desc
*desc
;
338 spin_lock_irqsave(&priv
->lock
, flags
);
339 idx
= le32_to_cpu(ring_control
->host_idx
[1]);
340 i
= idx
% ARRAY_SIZE(ring_control
->tx_data
);
341 device_addr
= ((struct p54_hdr
*)skb
->data
)->req_id
;
343 mapping
= dma_map_single(&priv
->pdev
->dev
, skb
->data
, skb
->len
,
345 if (dma_mapping_error(&priv
->pdev
->dev
, mapping
)) {
346 spin_unlock_irqrestore(&priv
->lock
, flags
);
347 p54_free_skb(dev
, skb
);
348 dev_err(&priv
->pdev
->dev
, "TX DMA mapping error\n");
351 priv
->tx_buf_data
[i
] = skb
;
353 desc
= &ring_control
->tx_data
[i
];
354 desc
->host_addr
= cpu_to_le32(mapping
);
355 desc
->device_addr
= device_addr
;
356 desc
->len
= cpu_to_le16(skb
->len
);
360 ring_control
->host_idx
[1] = cpu_to_le32(idx
+ 1);
361 spin_unlock_irqrestore(&priv
->lock
, flags
);
363 P54P_WRITE(dev_int
, cpu_to_le32(ISL38XX_DEV_INT_UPDATE
));
367 static void p54p_stop(struct ieee80211_hw
*dev
)
369 struct p54p_priv
*priv
= dev
->priv
;
370 struct p54p_ring_control
*ring_control
= priv
->ring_control
;
372 struct p54p_desc
*desc
;
374 P54P_WRITE(int_enable
, cpu_to_le32(0));
375 P54P_READ(int_enable
);
378 free_irq(priv
->pdev
->irq
, dev
);
380 tasklet_kill(&priv
->tasklet
);
382 P54P_WRITE(dev_int
, cpu_to_le32(ISL38XX_DEV_INT_RESET
));
384 for (i
= 0; i
< ARRAY_SIZE(priv
->rx_buf_data
); i
++) {
385 desc
= &ring_control
->rx_data
[i
];
387 dma_unmap_single(&priv
->pdev
->dev
,
388 le32_to_cpu(desc
->host_addr
),
389 priv
->common
.rx_mtu
+ 32,
391 kfree_skb(priv
->rx_buf_data
[i
]);
392 priv
->rx_buf_data
[i
] = NULL
;
395 for (i
= 0; i
< ARRAY_SIZE(priv
->rx_buf_mgmt
); i
++) {
396 desc
= &ring_control
->rx_mgmt
[i
];
398 dma_unmap_single(&priv
->pdev
->dev
,
399 le32_to_cpu(desc
->host_addr
),
400 priv
->common
.rx_mtu
+ 32,
402 kfree_skb(priv
->rx_buf_mgmt
[i
]);
403 priv
->rx_buf_mgmt
[i
] = NULL
;
406 for (i
= 0; i
< ARRAY_SIZE(priv
->tx_buf_data
); i
++) {
407 desc
= &ring_control
->tx_data
[i
];
409 dma_unmap_single(&priv
->pdev
->dev
,
410 le32_to_cpu(desc
->host_addr
),
411 le16_to_cpu(desc
->len
),
414 p54_free_skb(dev
, priv
->tx_buf_data
[i
]);
415 priv
->tx_buf_data
[i
] = NULL
;
418 for (i
= 0; i
< ARRAY_SIZE(priv
->tx_buf_mgmt
); i
++) {
419 desc
= &ring_control
->tx_mgmt
[i
];
421 dma_unmap_single(&priv
->pdev
->dev
,
422 le32_to_cpu(desc
->host_addr
),
423 le16_to_cpu(desc
->len
),
426 p54_free_skb(dev
, priv
->tx_buf_mgmt
[i
]);
427 priv
->tx_buf_mgmt
[i
] = NULL
;
430 memset(ring_control
, 0, sizeof(*ring_control
));
433 static int p54p_open(struct ieee80211_hw
*dev
)
435 struct p54p_priv
*priv
= dev
->priv
;
439 init_completion(&priv
->boot_comp
);
440 err
= request_irq(priv
->pdev
->irq
, p54p_interrupt
,
441 IRQF_SHARED
, "p54pci", dev
);
443 dev_err(&priv
->pdev
->dev
, "failed to register IRQ handler\n");
447 memset(priv
->ring_control
, 0, sizeof(*priv
->ring_control
));
448 err
= p54p_upload_firmware(dev
);
450 free_irq(priv
->pdev
->irq
, dev
);
453 priv
->rx_idx_data
= priv
->tx_idx_data
= 0;
454 priv
->rx_idx_mgmt
= priv
->tx_idx_mgmt
= 0;
456 p54p_refill_rx_ring(dev
, 0, priv
->ring_control
->rx_data
,
457 ARRAY_SIZE(priv
->ring_control
->rx_data
), priv
->rx_buf_data
, 0);
459 p54p_refill_rx_ring(dev
, 2, priv
->ring_control
->rx_mgmt
,
460 ARRAY_SIZE(priv
->ring_control
->rx_mgmt
), priv
->rx_buf_mgmt
, 0);
462 P54P_WRITE(ring_control_base
, cpu_to_le32(priv
->ring_control_dma
));
463 P54P_READ(ring_control_base
);
467 P54P_WRITE(int_enable
, cpu_to_le32(ISL38XX_INT_IDENT_INIT
));
468 P54P_READ(int_enable
);
472 P54P_WRITE(dev_int
, cpu_to_le32(ISL38XX_DEV_INT_RESET
));
475 time_left
= wait_for_completion_interruptible_timeout(
476 &priv
->boot_comp
, HZ
);
477 if (time_left
<= 0) {
478 wiphy_err(dev
->wiphy
, "Cannot boot firmware!\n");
480 return time_left
? -ERESTARTSYS
: -ETIMEDOUT
;
483 P54P_WRITE(int_enable
, cpu_to_le32(ISL38XX_INT_IDENT_UPDATE
));
484 P54P_READ(int_enable
);
488 P54P_WRITE(dev_int
, cpu_to_le32(ISL38XX_DEV_INT_UPDATE
));
496 static void p54p_firmware_step2(const struct firmware
*fw
,
499 struct p54p_priv
*priv
= context
;
500 struct ieee80211_hw
*dev
= priv
->common
.hw
;
501 struct pci_dev
*pdev
= priv
->pdev
;
505 dev_err(&pdev
->dev
, "Cannot find firmware (isl3886pci)\n");
512 err
= p54p_open(dev
);
515 err
= p54_read_eeprom(dev
);
520 err
= p54_register_common(dev
, &pdev
->dev
);
526 complete(&priv
->fw_loaded
);
529 struct device
*parent
= pdev
->dev
.parent
;
535 * This will indirectly result in a call to p54p_remove.
536 * Hence, we don't need to bother with freeing any
537 * allocated ressources at all.
539 device_release_driver(&pdev
->dev
);
542 device_unlock(parent
);
548 static int p54p_probe(struct pci_dev
*pdev
,
549 const struct pci_device_id
*id
)
551 struct p54p_priv
*priv
;
552 struct ieee80211_hw
*dev
;
553 unsigned long mem_addr
, mem_len
;
557 err
= pci_enable_device(pdev
);
559 dev_err(&pdev
->dev
, "Cannot enable new PCI device\n");
563 mem_addr
= pci_resource_start(pdev
, 0);
564 mem_len
= pci_resource_len(pdev
, 0);
565 if (mem_len
< sizeof(struct p54p_csr
)) {
566 dev_err(&pdev
->dev
, "Too short PCI resources\n");
568 goto err_disable_dev
;
571 err
= pci_request_regions(pdev
, "p54pci");
573 dev_err(&pdev
->dev
, "Cannot obtain PCI resources\n");
574 goto err_disable_dev
;
577 err
= dma_set_mask(&pdev
->dev
, DMA_BIT_MASK(32));
579 err
= dma_set_coherent_mask(&pdev
->dev
, DMA_BIT_MASK(32));
581 dev_err(&pdev
->dev
, "No suitable DMA available\n");
585 pci_set_master(pdev
);
586 pci_try_set_mwi(pdev
);
588 pci_write_config_byte(pdev
, 0x40, 0);
589 pci_write_config_byte(pdev
, 0x41, 0);
591 dev
= p54_init_common(sizeof(*priv
));
593 dev_err(&pdev
->dev
, "ieee80211 alloc failed\n");
601 init_completion(&priv
->fw_loaded
);
602 SET_IEEE80211_DEV(dev
, &pdev
->dev
);
603 pci_set_drvdata(pdev
, dev
);
605 priv
->map
= ioremap(mem_addr
, mem_len
);
607 dev_err(&pdev
->dev
, "Cannot map device memory\n");
612 priv
->ring_control
= dma_alloc_coherent(&pdev
->dev
,
613 sizeof(*priv
->ring_control
),
614 &priv
->ring_control_dma
, GFP_KERNEL
);
615 if (!priv
->ring_control
) {
616 dev_err(&pdev
->dev
, "Cannot allocate rings\n");
620 priv
->common
.open
= p54p_open
;
621 priv
->common
.stop
= p54p_stop
;
622 priv
->common
.tx
= p54p_tx
;
624 spin_lock_init(&priv
->lock
);
625 tasklet_setup(&priv
->tasklet
, p54p_tasklet
);
627 err
= request_firmware_nowait(THIS_MODULE
, 1, "isl3886pci",
628 &priv
->pdev
->dev
, GFP_KERNEL
,
629 priv
, p54p_firmware_step2
);
633 dma_free_coherent(&pdev
->dev
, sizeof(*priv
->ring_control
),
634 priv
->ring_control
, priv
->ring_control_dma
);
640 p54_free_common(dev
);
643 pci_release_regions(pdev
);
645 pci_disable_device(pdev
);
651 static void p54p_remove(struct pci_dev
*pdev
)
653 struct ieee80211_hw
*dev
= pci_get_drvdata(pdev
);
654 struct p54p_priv
*priv
;
660 wait_for_completion(&priv
->fw_loaded
);
661 p54_unregister_common(dev
);
662 release_firmware(priv
->firmware
);
663 dma_free_coherent(&pdev
->dev
, sizeof(*priv
->ring_control
),
664 priv
->ring_control
, priv
->ring_control_dma
);
666 pci_release_regions(pdev
);
667 pci_disable_device(pdev
);
668 p54_free_common(dev
);
671 #ifdef CONFIG_PM_SLEEP
672 static int p54p_suspend(struct device
*device
)
674 struct pci_dev
*pdev
= to_pci_dev(device
);
676 pci_save_state(pdev
);
677 pci_set_power_state(pdev
, PCI_D3hot
);
678 pci_disable_device(pdev
);
682 static int p54p_resume(struct device
*device
)
684 struct pci_dev
*pdev
= to_pci_dev(device
);
687 err
= pci_reenable_device(pdev
);
690 return pci_set_power_state(pdev
, PCI_D0
);
693 static SIMPLE_DEV_PM_OPS(p54pci_pm_ops
, p54p_suspend
, p54p_resume
);
695 #define P54P_PM_OPS (&p54pci_pm_ops)
697 #define P54P_PM_OPS (NULL)
698 #endif /* CONFIG_PM_SLEEP */
700 static struct pci_driver p54p_driver
= {
702 .id_table
= p54p_table
,
704 .remove
= p54p_remove
,
705 .driver
.pm
= P54P_PM_OPS
,
708 module_pci_driver(p54p_driver
);