blob: a5ea89cde8c43a9c837018459e9f689a83162e1e [file] [log] [blame]
Michael Wueff1a592007-09-25 18:11:01 -07001
2/*
3 * Linux device driver for PCI based Prism54
4 *
5 * Copyright (c) 2006, Michael Wu <flamingice@sourmilk.net>
Christian Lamparter7262d592008-08-24 22:30:38 +02006 * Copyright (c) 2008, Christian Lamparter <chunkeey@web.de>
Michael Wueff1a592007-09-25 18:11:01 -07007 *
8 * Based on the islsm (softmac prism54) driver, which is:
9 * Copyright 2004-2006 Jean-Baptiste Note <jean-baptiste.note@m4x.org>, et al.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
14 */
15
16#include <linux/init.h>
17#include <linux/pci.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090018#include <linux/slab.h>
Michael Wueff1a592007-09-25 18:11:01 -070019#include <linux/firmware.h>
20#include <linux/etherdevice.h>
21#include <linux/delay.h>
22#include <linux/completion.h>
23#include <net/mac80211.h>
24
25#include "p54.h"
Christian Lamparterd8c92102009-06-23 10:39:45 -050026#include "lmac.h"
Michael Wueff1a592007-09-25 18:11:01 -070027#include "p54pci.h"
28
29MODULE_AUTHOR("Michael Wu <flamingice@sourmilk.net>");
30MODULE_DESCRIPTION("Prism54 PCI wireless driver");
31MODULE_LICENSE("GPL");
32MODULE_ALIAS("prism54pci");
Christian Lamparter9a8675d2008-10-18 23:04:15 +020033MODULE_FIRMWARE("isl3886pci");
Michael Wueff1a592007-09-25 18:11:01 -070034
Alexey Dobriyana3aa1882010-01-07 11:58:11 +000035static DEFINE_PCI_DEVICE_TABLE(p54p_table) = {
Michael Wueff1a592007-09-25 18:11:01 -070036 /* Intersil PRISM Duette/Prism GT Wireless LAN adapter */
37 { PCI_DEVICE(0x1260, 0x3890) },
38 /* 3COM 3CRWE154G72 Wireless LAN adapter */
39 { PCI_DEVICE(0x10b7, 0x6001) },
40 /* Intersil PRISM Indigo Wireless LAN adapter */
41 { PCI_DEVICE(0x1260, 0x3877) },
42 /* Intersil PRISM Javelin/Xbow Wireless LAN adapter */
43 { PCI_DEVICE(0x1260, 0x3886) },
Joerg Albert50900f12010-06-13 14:22:23 +020044 /* Intersil PRISM Xbow Wireless LAN adapter (Symbol AP-300) */
45 { PCI_DEVICE(0x1260, 0xffff) },
Andrew Morton90f4dd02007-09-16 15:08:37 -070046 { },
Michael Wueff1a592007-09-25 18:11:01 -070047};
48
49MODULE_DEVICE_TABLE(pci, p54p_table);
50
51static int p54p_upload_firmware(struct ieee80211_hw *dev)
52{
53 struct p54p_priv *priv = dev->priv;
Michael Wueff1a592007-09-25 18:11:01 -070054 __le32 reg;
55 int err;
Al Viro8160c032007-12-21 22:02:23 -050056 __le32 *data;
Michael Wueff1a592007-09-25 18:11:01 -070057 u32 remains, left, device_addr;
58
Al Viro8160c032007-12-21 22:02:23 -050059 P54P_WRITE(int_enable, cpu_to_le32(0));
Michael Wueff1a592007-09-25 18:11:01 -070060 P54P_READ(int_enable);
61 udelay(10);
62
63 reg = P54P_READ(ctrl_stat);
64 reg &= cpu_to_le32(~ISL38XX_CTRL_STAT_RESET);
65 reg &= cpu_to_le32(~ISL38XX_CTRL_STAT_RAMBOOT);
66 P54P_WRITE(ctrl_stat, reg);
67 P54P_READ(ctrl_stat);
68 udelay(10);
69
70 reg |= cpu_to_le32(ISL38XX_CTRL_STAT_RESET);
71 P54P_WRITE(ctrl_stat, reg);
72 wmb();
73 udelay(10);
74
75 reg &= cpu_to_le32(~ISL38XX_CTRL_STAT_RESET);
76 P54P_WRITE(ctrl_stat, reg);
77 wmb();
78
Christian Lamparter40db0b22008-11-16 12:20:32 +010079 /* wait for the firmware to reset properly */
80 mdelay(10);
Michael Wueff1a592007-09-25 18:11:01 -070081
Christian Lamparter40db0b22008-11-16 12:20:32 +010082 err = p54_parse_firmware(dev, priv->firmware);
83 if (err)
Christian Lamparter4e416a62008-09-01 22:48:41 +020084 return err;
Michael Wueff1a592007-09-25 18:11:01 -070085
Christian Lampartere365f162008-12-26 19:09:34 +010086 if (priv->common.fw_interface != FW_LM86) {
87 dev_err(&priv->pdev->dev, "wrong firmware, "
88 "please get a LM86(PCI) firmware a try again.\n");
89 return -EINVAL;
90 }
91
Christian Lamparter40db0b22008-11-16 12:20:32 +010092 data = (__le32 *) priv->firmware->data;
93 remains = priv->firmware->size;
Michael Wueff1a592007-09-25 18:11:01 -070094 device_addr = ISL38XX_DEV_FIRMWARE_ADDR;
95 while (remains) {
96 u32 i = 0;
97 left = min((u32)0x1000, remains);
98 P54P_WRITE(direct_mem_base, cpu_to_le32(device_addr));
99 P54P_READ(int_enable);
100
101 device_addr += 0x1000;
102 while (i < left) {
103 P54P_WRITE(direct_mem_win[i], *data++);
104 i += sizeof(u32);
105 }
106
107 remains -= left;
108 P54P_READ(int_enable);
109 }
110
Michael Wueff1a592007-09-25 18:11:01 -0700111 reg = P54P_READ(ctrl_stat);
112 reg &= cpu_to_le32(~ISL38XX_CTRL_STAT_CLKRUN);
113 reg &= cpu_to_le32(~ISL38XX_CTRL_STAT_RESET);
114 reg |= cpu_to_le32(ISL38XX_CTRL_STAT_RAMBOOT);
115 P54P_WRITE(ctrl_stat, reg);
116 P54P_READ(ctrl_stat);
117 udelay(10);
118
119 reg |= cpu_to_le32(ISL38XX_CTRL_STAT_RESET);
120 P54P_WRITE(ctrl_stat, reg);
121 wmb();
122 udelay(10);
123
124 reg &= cpu_to_le32(~ISL38XX_CTRL_STAT_RESET);
125 P54P_WRITE(ctrl_stat, reg);
126 wmb();
127 udelay(10);
128
Christian Lamparter7cb77072008-09-01 22:48:51 +0200129 /* wait for the firmware to boot properly */
Michael Wueff1a592007-09-25 18:11:01 -0700130 mdelay(100);
Michael Wueff1a592007-09-25 18:11:01 -0700131
Christian Lamparter7cb77072008-09-01 22:48:51 +0200132 return 0;
Michael Wueff1a592007-09-25 18:11:01 -0700133}
134
Christian Lamparter7262d592008-08-24 22:30:38 +0200135static void p54p_refill_rx_ring(struct ieee80211_hw *dev,
136 int ring_index, struct p54p_desc *ring, u32 ring_limit,
Quintin Pitts5988f382010-04-09 21:37:38 +0200137 struct sk_buff **rx_buf, u32 index)
Michael Wueff1a592007-09-25 18:11:01 -0700138{
139 struct p54p_priv *priv = dev->priv;
Dmitry Torokhoveb76bf22007-11-02 01:55:36 -0400140 struct p54p_ring_control *ring_control = priv->ring_control;
Christian Lamparter7262d592008-08-24 22:30:38 +0200141 u32 limit, idx, i;
Michael Wueff1a592007-09-25 18:11:01 -0700142
Christian Lamparter7262d592008-08-24 22:30:38 +0200143 idx = le32_to_cpu(ring_control->host_idx[ring_index]);
144 limit = idx;
Christian Lamparter103823d2010-04-15 14:17:07 +0200145 limit -= index;
Christian Lamparter7262d592008-08-24 22:30:38 +0200146 limit = ring_limit - limit;
Michael Wueff1a592007-09-25 18:11:01 -0700147
Christian Lamparter7262d592008-08-24 22:30:38 +0200148 i = idx % ring_limit;
Michael Wueff1a592007-09-25 18:11:01 -0700149 while (limit-- > 1) {
Christian Lamparter7262d592008-08-24 22:30:38 +0200150 struct p54p_desc *desc = &ring[i];
Michael Wueff1a592007-09-25 18:11:01 -0700151
152 if (!desc->host_addr) {
153 struct sk_buff *skb;
154 dma_addr_t mapping;
Christian Lamparter4e416a62008-09-01 22:48:41 +0200155 skb = dev_alloc_skb(priv->common.rx_mtu + 32);
Michael Wueff1a592007-09-25 18:11:01 -0700156 if (!skb)
157 break;
158
159 mapping = pci_map_single(priv->pdev,
160 skb_tail_pointer(skb),
Christian Lamparter4e416a62008-09-01 22:48:41 +0200161 priv->common.rx_mtu + 32,
Michael Wueff1a592007-09-25 18:11:01 -0700162 PCI_DMA_FROMDEVICE);
Christian Lamparter288c8ce2010-01-17 23:17:29 +0100163
164 if (pci_dma_mapping_error(priv->pdev, mapping)) {
165 dev_kfree_skb_any(skb);
166 dev_err(&priv->pdev->dev,
167 "RX DMA Mapping error\n");
168 break;
169 }
170
Michael Wueff1a592007-09-25 18:11:01 -0700171 desc->host_addr = cpu_to_le32(mapping);
172 desc->device_addr = 0; // FIXME: necessary?
Christian Lamparter4e416a62008-09-01 22:48:41 +0200173 desc->len = cpu_to_le16(priv->common.rx_mtu + 32);
Michael Wueff1a592007-09-25 18:11:01 -0700174 desc->flags = 0;
Christian Lamparter7262d592008-08-24 22:30:38 +0200175 rx_buf[i] = skb;
Michael Wueff1a592007-09-25 18:11:01 -0700176 }
177
Christian Lamparter7262d592008-08-24 22:30:38 +0200178 i++;
Michael Wueff1a592007-09-25 18:11:01 -0700179 idx++;
Christian Lamparter7262d592008-08-24 22:30:38 +0200180 i %= ring_limit;
Michael Wueff1a592007-09-25 18:11:01 -0700181 }
182
183 wmb();
Christian Lamparter7262d592008-08-24 22:30:38 +0200184 ring_control->host_idx[ring_index] = cpu_to_le32(idx);
185}
186
187static void p54p_check_rx_ring(struct ieee80211_hw *dev, u32 *index,
188 int ring_index, struct p54p_desc *ring, u32 ring_limit,
189 struct sk_buff **rx_buf)
190{
191 struct p54p_priv *priv = dev->priv;
192 struct p54p_ring_control *ring_control = priv->ring_control;
193 struct p54p_desc *desc;
194 u32 idx, i;
195
196 i = (*index) % ring_limit;
197 (*index) = idx = le32_to_cpu(ring_control->device_idx[ring_index]);
198 idx %= ring_limit;
199 while (i != idx) {
200 u16 len;
201 struct sk_buff *skb;
202 desc = &ring[i];
203 len = le16_to_cpu(desc->len);
204 skb = rx_buf[i];
205
Christian Lamparter0c259702008-08-31 22:15:40 +0200206 if (!skb) {
207 i++;
208 i %= ring_limit;
Christian Lamparter7262d592008-08-24 22:30:38 +0200209 continue;
Christian Lamparter0c259702008-08-31 22:15:40 +0200210 }
Christian Lamparterf5300e02010-01-18 00:07:38 +0100211
212 if (unlikely(len > priv->common.rx_mtu)) {
213 if (net_ratelimit())
214 dev_err(&priv->pdev->dev, "rx'd frame size "
215 "exceeds length threshold.\n");
216
217 len = priv->common.rx_mtu;
218 }
Christian Lamparter7262d592008-08-24 22:30:38 +0200219 skb_put(skb, len);
220
221 if (p54_rx(dev, skb)) {
222 pci_unmap_single(priv->pdev,
223 le32_to_cpu(desc->host_addr),
Christian Lamparter4e416a62008-09-01 22:48:41 +0200224 priv->common.rx_mtu + 32,
225 PCI_DMA_FROMDEVICE);
Christian Lamparter7262d592008-08-24 22:30:38 +0200226 rx_buf[i] = NULL;
227 desc->host_addr = 0;
228 } else {
229 skb_trim(skb, 0);
Christian Lamparter4e416a62008-09-01 22:48:41 +0200230 desc->len = cpu_to_le16(priv->common.rx_mtu + 32);
Christian Lamparter7262d592008-08-24 22:30:38 +0200231 }
232
233 i++;
234 i %= ring_limit;
235 }
236
Quintin Pitts5988f382010-04-09 21:37:38 +0200237 p54p_refill_rx_ring(dev, ring_index, ring, ring_limit, rx_buf, *index);
Christian Lamparter7262d592008-08-24 22:30:38 +0200238}
239
Christian Lamparter7262d592008-08-24 22:30:38 +0200240static void p54p_check_tx_ring(struct ieee80211_hw *dev, u32 *index,
241 int ring_index, struct p54p_desc *ring, u32 ring_limit,
Christian Lamparterd7138042010-01-17 23:19:25 +0100242 struct sk_buff **tx_buf)
Christian Lamparter7262d592008-08-24 22:30:38 +0200243{
244 struct p54p_priv *priv = dev->priv;
245 struct p54p_ring_control *ring_control = priv->ring_control;
246 struct p54p_desc *desc;
Christian Lamparterd7138042010-01-17 23:19:25 +0100247 struct sk_buff *skb;
Christian Lamparter7262d592008-08-24 22:30:38 +0200248 u32 idx, i;
249
250 i = (*index) % ring_limit;
Hans de Goede0250ece2010-04-22 19:52:16 +0200251 (*index) = idx = le32_to_cpu(ring_control->device_idx[ring_index]);
Christian Lamparter7262d592008-08-24 22:30:38 +0200252 idx %= ring_limit;
253
254 while (i != idx) {
255 desc = &ring[i];
Christian Lamparterd7138042010-01-17 23:19:25 +0100256
257 skb = tx_buf[i];
Christian Lamparter7262d592008-08-24 22:30:38 +0200258 tx_buf[i] = NULL;
259
260 pci_unmap_single(priv->pdev, le32_to_cpu(desc->host_addr),
261 le16_to_cpu(desc->len), PCI_DMA_TODEVICE);
262
263 desc->host_addr = 0;
264 desc->device_addr = 0;
265 desc->len = 0;
266 desc->flags = 0;
267
Christian Lamparterb92f7d32010-01-22 08:01:11 +0100268 if (skb && FREE_AFTER_TX(skb))
Christian Lamparterd7138042010-01-17 23:19:25 +0100269 p54_free_skb(dev, skb);
Christian Lamparterd7138042010-01-17 23:19:25 +0100270
Christian Lamparter7262d592008-08-24 22:30:38 +0200271 i++;
272 i %= ring_limit;
273 }
274}
275
Christian Lamparterd7138042010-01-17 23:19:25 +0100276static void p54p_tasklet(unsigned long dev_id)
Christian Lamparter7262d592008-08-24 22:30:38 +0200277{
278 struct ieee80211_hw *dev = (struct ieee80211_hw *)dev_id;
279 struct p54p_priv *priv = dev->priv;
280 struct p54p_ring_control *ring_control = priv->ring_control;
281
Hans de Goeded4cde882010-04-22 19:52:43 +0200282 p54p_check_tx_ring(dev, &priv->tx_idx_mgmt, 3, ring_control->tx_mgmt,
283 ARRAY_SIZE(ring_control->tx_mgmt),
284 priv->tx_buf_mgmt);
285
286 p54p_check_tx_ring(dev, &priv->tx_idx_data, 1, ring_control->tx_data,
287 ARRAY_SIZE(ring_control->tx_data),
288 priv->tx_buf_data);
289
Christian Lamparter7262d592008-08-24 22:30:38 +0200290 p54p_check_rx_ring(dev, &priv->rx_idx_mgmt, 2, ring_control->rx_mgmt,
291 ARRAY_SIZE(ring_control->rx_mgmt), priv->rx_buf_mgmt);
292
293 p54p_check_rx_ring(dev, &priv->rx_idx_data, 0, ring_control->rx_data,
294 ARRAY_SIZE(ring_control->rx_data), priv->rx_buf_data);
295
296 wmb();
297 P54P_WRITE(dev_int, cpu_to_le32(ISL38XX_DEV_INT_UPDATE));
Michael Wueff1a592007-09-25 18:11:01 -0700298}
299
300static irqreturn_t p54p_interrupt(int irq, void *dev_id)
301{
302 struct ieee80211_hw *dev = dev_id;
303 struct p54p_priv *priv = dev->priv;
304 __le32 reg;
305
Michael Wueff1a592007-09-25 18:11:01 -0700306 reg = P54P_READ(int_ident);
Al Viro8160c032007-12-21 22:02:23 -0500307 if (unlikely(reg == cpu_to_le32(0xFFFFFFFF))) {
Christian Lamparterd7138042010-01-17 23:19:25 +0100308 goto out;
Michael Wueff1a592007-09-25 18:11:01 -0700309 }
Michael Wueff1a592007-09-25 18:11:01 -0700310 P54P_WRITE(int_ack, reg);
311
312 reg &= P54P_READ(int_enable);
313
Christian Lamparterd7138042010-01-17 23:19:25 +0100314 if (reg & cpu_to_le32(ISL38XX_INT_IDENT_UPDATE))
315 tasklet_schedule(&priv->tasklet);
316 else if (reg & cpu_to_le32(ISL38XX_INT_IDENT_INIT))
Michael Wueff1a592007-09-25 18:11:01 -0700317 complete(&priv->boot_comp);
318
Christian Lamparterd7138042010-01-17 23:19:25 +0100319out:
Michael Wueff1a592007-09-25 18:11:01 -0700320 return reg ? IRQ_HANDLED : IRQ_NONE;
321}
322
Christian Lamparter0a5ec962008-12-14 15:05:42 +0100323static void p54p_tx(struct ieee80211_hw *dev, struct sk_buff *skb)
Michael Wueff1a592007-09-25 18:11:01 -0700324{
Christian Lamparterb92f7d32010-01-22 08:01:11 +0100325 unsigned long flags;
Michael Wueff1a592007-09-25 18:11:01 -0700326 struct p54p_priv *priv = dev->priv;
Dmitry Torokhoveb76bf22007-11-02 01:55:36 -0400327 struct p54p_ring_control *ring_control = priv->ring_control;
Michael Wueff1a592007-09-25 18:11:01 -0700328 struct p54p_desc *desc;
329 dma_addr_t mapping;
330 u32 device_idx, idx, i;
331
332 spin_lock_irqsave(&priv->lock, flags);
Dmitry Torokhoveb76bf22007-11-02 01:55:36 -0400333 device_idx = le32_to_cpu(ring_control->device_idx[1]);
334 idx = le32_to_cpu(ring_control->host_idx[1]);
335 i = idx % ARRAY_SIZE(ring_control->tx_data);
Michael Wueff1a592007-09-25 18:11:01 -0700336
Christian Lamparterb92f30d2008-10-15 04:07:16 +0200337 mapping = pci_map_single(priv->pdev, skb->data, skb->len,
338 PCI_DMA_TODEVICE);
Christian Lamparter288c8ce2010-01-17 23:17:29 +0100339 if (pci_dma_mapping_error(priv->pdev, mapping)) {
340 spin_unlock_irqrestore(&priv->lock, flags);
341 p54_free_skb(dev, skb);
342 dev_err(&priv->pdev->dev, "TX DMA mapping error\n");
343 return ;
344 }
345 priv->tx_buf_data[i] = skb;
346
Dmitry Torokhoveb76bf22007-11-02 01:55:36 -0400347 desc = &ring_control->tx_data[i];
Michael Wueff1a592007-09-25 18:11:01 -0700348 desc->host_addr = cpu_to_le32(mapping);
John W. Linville27df6052008-10-22 16:41:55 -0400349 desc->device_addr = ((struct p54_hdr *)skb->data)->req_id;
Christian Lamparterb92f30d2008-10-15 04:07:16 +0200350 desc->len = cpu_to_le16(skb->len);
Michael Wueff1a592007-09-25 18:11:01 -0700351 desc->flags = 0;
352
353 wmb();
Dmitry Torokhoveb76bf22007-11-02 01:55:36 -0400354 ring_control->host_idx[1] = cpu_to_le32(idx + 1);
Michael Wueff1a592007-09-25 18:11:01 -0700355 spin_unlock_irqrestore(&priv->lock, flags);
356
357 P54P_WRITE(dev_int, cpu_to_le32(ISL38XX_DEV_INT_UPDATE));
358 P54P_READ(dev_int);
Michael Wueff1a592007-09-25 18:11:01 -0700359}
360
Michael Wueff1a592007-09-25 18:11:01 -0700361static void p54p_stop(struct ieee80211_hw *dev)
362{
363 struct p54p_priv *priv = dev->priv;
Dmitry Torokhoveb76bf22007-11-02 01:55:36 -0400364 struct p54p_ring_control *ring_control = priv->ring_control;
Michael Wueff1a592007-09-25 18:11:01 -0700365 unsigned int i;
366 struct p54p_desc *desc;
367
Al Viro8160c032007-12-21 22:02:23 -0500368 P54P_WRITE(int_enable, cpu_to_le32(0));
Michael Wueff1a592007-09-25 18:11:01 -0700369 P54P_READ(int_enable);
370 udelay(10);
371
372 free_irq(priv->pdev->irq, dev);
373
Christian Lamparterb92f7d32010-01-22 08:01:11 +0100374 tasklet_kill(&priv->tasklet);
375
Michael Wueff1a592007-09-25 18:11:01 -0700376 P54P_WRITE(dev_int, cpu_to_le32(ISL38XX_DEV_INT_RESET));
377
Christian Lamparter7262d592008-08-24 22:30:38 +0200378 for (i = 0; i < ARRAY_SIZE(priv->rx_buf_data); i++) {
Dmitry Torokhoveb76bf22007-11-02 01:55:36 -0400379 desc = &ring_control->rx_data[i];
Michael Wueff1a592007-09-25 18:11:01 -0700380 if (desc->host_addr)
Christian Lamparter7262d592008-08-24 22:30:38 +0200381 pci_unmap_single(priv->pdev,
382 le32_to_cpu(desc->host_addr),
Christian Lamparter4e416a62008-09-01 22:48:41 +0200383 priv->common.rx_mtu + 32,
384 PCI_DMA_FROMDEVICE);
Christian Lamparter7262d592008-08-24 22:30:38 +0200385 kfree_skb(priv->rx_buf_data[i]);
386 priv->rx_buf_data[i] = NULL;
Michael Wueff1a592007-09-25 18:11:01 -0700387 }
388
Christian Lamparter7262d592008-08-24 22:30:38 +0200389 for (i = 0; i < ARRAY_SIZE(priv->rx_buf_mgmt); i++) {
390 desc = &ring_control->rx_mgmt[i];
391 if (desc->host_addr)
392 pci_unmap_single(priv->pdev,
393 le32_to_cpu(desc->host_addr),
Christian Lamparter4e416a62008-09-01 22:48:41 +0200394 priv->common.rx_mtu + 32,
395 PCI_DMA_FROMDEVICE);
Christian Lamparter7262d592008-08-24 22:30:38 +0200396 kfree_skb(priv->rx_buf_mgmt[i]);
397 priv->rx_buf_mgmt[i] = NULL;
398 }
399
400 for (i = 0; i < ARRAY_SIZE(priv->tx_buf_data); i++) {
Dmitry Torokhoveb76bf22007-11-02 01:55:36 -0400401 desc = &ring_control->tx_data[i];
Michael Wueff1a592007-09-25 18:11:01 -0700402 if (desc->host_addr)
Christian Lamparter7262d592008-08-24 22:30:38 +0200403 pci_unmap_single(priv->pdev,
404 le32_to_cpu(desc->host_addr),
405 le16_to_cpu(desc->len),
406 PCI_DMA_TODEVICE);
Michael Wueff1a592007-09-25 18:11:01 -0700407
Christian Lamparterb92f30d2008-10-15 04:07:16 +0200408 p54_free_skb(dev, priv->tx_buf_data[i]);
Christian Lamparter7262d592008-08-24 22:30:38 +0200409 priv->tx_buf_data[i] = NULL;
Michael Wueff1a592007-09-25 18:11:01 -0700410 }
411
Christian Lamparter7262d592008-08-24 22:30:38 +0200412 for (i = 0; i < ARRAY_SIZE(priv->tx_buf_mgmt); i++) {
413 desc = &ring_control->tx_mgmt[i];
414 if (desc->host_addr)
415 pci_unmap_single(priv->pdev,
416 le32_to_cpu(desc->host_addr),
417 le16_to_cpu(desc->len),
418 PCI_DMA_TODEVICE);
419
Christian Lamparterb92f30d2008-10-15 04:07:16 +0200420 p54_free_skb(dev, priv->tx_buf_mgmt[i]);
Christian Lamparter7262d592008-08-24 22:30:38 +0200421 priv->tx_buf_mgmt[i] = NULL;
422 }
423
424 memset(ring_control, 0, sizeof(*ring_control));
Michael Wueff1a592007-09-25 18:11:01 -0700425}
426
Christian Lamparter35961622008-10-22 14:19:56 +0200427static int p54p_open(struct ieee80211_hw *dev)
428{
429 struct p54p_priv *priv = dev->priv;
430 int err;
431
432 init_completion(&priv->boot_comp);
Julia Lawall8fbd90b2009-11-18 08:25:43 +0000433 err = request_irq(priv->pdev->irq, p54p_interrupt,
Christian Lamparter35961622008-10-22 14:19:56 +0200434 IRQF_SHARED, "p54pci", dev);
435 if (err) {
Christian Lamparterad5e72e2009-03-05 21:30:37 +0100436 dev_err(&priv->pdev->dev, "failed to register IRQ handler\n");
Christian Lamparter35961622008-10-22 14:19:56 +0200437 return err;
438 }
439
440 memset(priv->ring_control, 0, sizeof(*priv->ring_control));
441 err = p54p_upload_firmware(dev);
442 if (err) {
443 free_irq(priv->pdev->irq, dev);
444 return err;
445 }
446 priv->rx_idx_data = priv->tx_idx_data = 0;
447 priv->rx_idx_mgmt = priv->tx_idx_mgmt = 0;
448
449 p54p_refill_rx_ring(dev, 0, priv->ring_control->rx_data,
Quintin Pitts5988f382010-04-09 21:37:38 +0200450 ARRAY_SIZE(priv->ring_control->rx_data), priv->rx_buf_data, 0);
Christian Lamparter35961622008-10-22 14:19:56 +0200451
452 p54p_refill_rx_ring(dev, 2, priv->ring_control->rx_mgmt,
Quintin Pitts5988f382010-04-09 21:37:38 +0200453 ARRAY_SIZE(priv->ring_control->rx_mgmt), priv->rx_buf_mgmt, 0);
Christian Lamparter35961622008-10-22 14:19:56 +0200454
455 P54P_WRITE(ring_control_base, cpu_to_le32(priv->ring_control_dma));
456 P54P_READ(ring_control_base);
457 wmb();
458 udelay(10);
459
460 P54P_WRITE(int_enable, cpu_to_le32(ISL38XX_INT_IDENT_INIT));
461 P54P_READ(int_enable);
462 wmb();
463 udelay(10);
464
465 P54P_WRITE(dev_int, cpu_to_le32(ISL38XX_DEV_INT_RESET));
466 P54P_READ(dev_int);
467
468 if (!wait_for_completion_interruptible_timeout(&priv->boot_comp, HZ)) {
469 printk(KERN_ERR "%s: Cannot boot firmware!\n",
470 wiphy_name(dev->wiphy));
471 p54p_stop(dev);
472 return -ETIMEDOUT;
473 }
474
475 P54P_WRITE(int_enable, cpu_to_le32(ISL38XX_INT_IDENT_UPDATE));
476 P54P_READ(int_enable);
477 wmb();
478 udelay(10);
479
480 P54P_WRITE(dev_int, cpu_to_le32(ISL38XX_DEV_INT_UPDATE));
481 P54P_READ(dev_int);
482 wmb();
483 udelay(10);
484
485 return 0;
486}
487
Michael Wueff1a592007-09-25 18:11:01 -0700488static int __devinit p54p_probe(struct pci_dev *pdev,
489 const struct pci_device_id *id)
490{
491 struct p54p_priv *priv;
492 struct ieee80211_hw *dev;
493 unsigned long mem_addr, mem_len;
494 int err;
Michael Wueff1a592007-09-25 18:11:01 -0700495
496 err = pci_enable_device(pdev);
497 if (err) {
Christian Lamparterad5e72e2009-03-05 21:30:37 +0100498 dev_err(&pdev->dev, "Cannot enable new PCI device\n");
Michael Wueff1a592007-09-25 18:11:01 -0700499 return err;
500 }
501
502 mem_addr = pci_resource_start(pdev, 0);
503 mem_len = pci_resource_len(pdev, 0);
504 if (mem_len < sizeof(struct p54p_csr)) {
Christian Lamparterad5e72e2009-03-05 21:30:37 +0100505 dev_err(&pdev->dev, "Too short PCI resources\n");
Christian Lamparter40db0b22008-11-16 12:20:32 +0100506 goto err_disable_dev;
Michael Wueff1a592007-09-25 18:11:01 -0700507 }
508
Christian Lamparter32ddf072008-08-08 21:17:37 +0200509 err = pci_request_regions(pdev, "p54pci");
Michael Wueff1a592007-09-25 18:11:01 -0700510 if (err) {
Christian Lamparterad5e72e2009-03-05 21:30:37 +0100511 dev_err(&pdev->dev, "Cannot obtain PCI resources\n");
Christian Lamparter40db0b22008-11-16 12:20:32 +0100512 goto err_disable_dev;
Michael Wueff1a592007-09-25 18:11:01 -0700513 }
514
Yang Hongyange9304382009-04-13 14:40:14 -0700515 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) ||
516 pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32))) {
Christian Lamparterad5e72e2009-03-05 21:30:37 +0100517 dev_err(&pdev->dev, "No suitable DMA available\n");
Michael Wueff1a592007-09-25 18:11:01 -0700518 goto err_free_reg;
519 }
520
521 pci_set_master(pdev);
522 pci_try_set_mwi(pdev);
523
524 pci_write_config_byte(pdev, 0x40, 0);
525 pci_write_config_byte(pdev, 0x41, 0);
526
527 dev = p54_init_common(sizeof(*priv));
528 if (!dev) {
Christian Lamparterad5e72e2009-03-05 21:30:37 +0100529 dev_err(&pdev->dev, "ieee80211 alloc failed\n");
Michael Wueff1a592007-09-25 18:11:01 -0700530 err = -ENOMEM;
531 goto err_free_reg;
532 }
533
534 priv = dev->priv;
535 priv->pdev = pdev;
536
537 SET_IEEE80211_DEV(dev, &pdev->dev);
538 pci_set_drvdata(pdev, dev);
539
540 priv->map = ioremap(mem_addr, mem_len);
541 if (!priv->map) {
Christian Lamparterad5e72e2009-03-05 21:30:37 +0100542 dev_err(&pdev->dev, "Cannot map device memory\n");
543 err = -ENOMEM;
Michael Wueff1a592007-09-25 18:11:01 -0700544 goto err_free_dev;
545 }
546
547 priv->ring_control = pci_alloc_consistent(pdev, sizeof(*priv->ring_control),
548 &priv->ring_control_dma);
549 if (!priv->ring_control) {
Christian Lamparterad5e72e2009-03-05 21:30:37 +0100550 dev_err(&pdev->dev, "Cannot allocate rings\n");
Michael Wueff1a592007-09-25 18:11:01 -0700551 err = -ENOMEM;
552 goto err_iounmap;
553 }
Michael Wueff1a592007-09-25 18:11:01 -0700554 priv->common.open = p54p_open;
555 priv->common.stop = p54p_stop;
556 priv->common.tx = p54p_tx;
557
558 spin_lock_init(&priv->lock);
Christian Lamparterd7138042010-01-17 23:19:25 +0100559 tasklet_init(&priv->tasklet, p54p_tasklet, (unsigned long)dev);
Michael Wueff1a592007-09-25 18:11:01 -0700560
Christian Lamparter40db0b22008-11-16 12:20:32 +0100561 err = request_firmware(&priv->firmware, "isl3886pci",
562 &priv->pdev->dev);
563 if (err) {
Christian Lamparterad5e72e2009-03-05 21:30:37 +0100564 dev_err(&pdev->dev, "Cannot find firmware (isl3886pci)\n");
Christian Lamparter40db0b22008-11-16 12:20:32 +0100565 err = request_firmware(&priv->firmware, "isl3886",
566 &priv->pdev->dev);
567 if (err)
568 goto err_free_common;
569 }
570
Christian Lamparter35961622008-10-22 14:19:56 +0200571 err = p54p_open(dev);
572 if (err)
573 goto err_free_common;
Christian Lamparter7cb77072008-09-01 22:48:51 +0200574 err = p54_read_eeprom(dev);
575 p54p_stop(dev);
576 if (err)
Christian Lamparter35961622008-10-22 14:19:56 +0200577 goto err_free_common;
Christian Lamparter7cb77072008-09-01 22:48:51 +0200578
Christian Lamparter2ac71072009-03-05 21:30:10 +0100579 err = p54_register_common(dev, &pdev->dev);
580 if (err)
Michael Wueff1a592007-09-25 18:11:01 -0700581 goto err_free_common;
Michael Wueff1a592007-09-25 18:11:01 -0700582
Michael Wueff1a592007-09-25 18:11:01 -0700583 return 0;
584
585 err_free_common:
Christian Lamparter40db0b22008-11-16 12:20:32 +0100586 release_firmware(priv->firmware);
Michael Wueff1a592007-09-25 18:11:01 -0700587 pci_free_consistent(pdev, sizeof(*priv->ring_control),
588 priv->ring_control, priv->ring_control_dma);
589
590 err_iounmap:
591 iounmap(priv->map);
592
593 err_free_dev:
594 pci_set_drvdata(pdev, NULL);
Christian Lamparterd8c92102009-06-23 10:39:45 -0500595 p54_free_common(dev);
Michael Wueff1a592007-09-25 18:11:01 -0700596
597 err_free_reg:
598 pci_release_regions(pdev);
Christian Lamparter40db0b22008-11-16 12:20:32 +0100599 err_disable_dev:
Michael Wueff1a592007-09-25 18:11:01 -0700600 pci_disable_device(pdev);
601 return err;
602}
603
604static void __devexit p54p_remove(struct pci_dev *pdev)
605{
606 struct ieee80211_hw *dev = pci_get_drvdata(pdev);
607 struct p54p_priv *priv;
608
609 if (!dev)
610 return;
611
Christian Lamparterd8c92102009-06-23 10:39:45 -0500612 p54_unregister_common(dev);
Michael Wueff1a592007-09-25 18:11:01 -0700613 priv = dev->priv;
Christian Lamparter40db0b22008-11-16 12:20:32 +0100614 release_firmware(priv->firmware);
Michael Wueff1a592007-09-25 18:11:01 -0700615 pci_free_consistent(pdev, sizeof(*priv->ring_control),
616 priv->ring_control, priv->ring_control_dma);
Michael Wueff1a592007-09-25 18:11:01 -0700617 iounmap(priv->map);
618 pci_release_regions(pdev);
619 pci_disable_device(pdev);
Christian Lamparterd8c92102009-06-23 10:39:45 -0500620 p54_free_common(dev);
Michael Wueff1a592007-09-25 18:11:01 -0700621}
622
623#ifdef CONFIG_PM
624static int p54p_suspend(struct pci_dev *pdev, pm_message_t state)
625{
626 struct ieee80211_hw *dev = pci_get_drvdata(pdev);
627 struct p54p_priv *priv = dev->priv;
628
Johannes Berg05c914f2008-09-11 00:01:58 +0200629 if (priv->common.mode != NL80211_IFTYPE_UNSPECIFIED) {
Michael Wueff1a592007-09-25 18:11:01 -0700630 ieee80211_stop_queues(dev);
631 p54p_stop(dev);
632 }
633
634 pci_save_state(pdev);
635 pci_set_power_state(pdev, pci_choose_state(pdev, state));
636 return 0;
637}
638
639static int p54p_resume(struct pci_dev *pdev)
640{
641 struct ieee80211_hw *dev = pci_get_drvdata(pdev);
642 struct p54p_priv *priv = dev->priv;
643
644 pci_set_power_state(pdev, PCI_D0);
645 pci_restore_state(pdev);
646
Johannes Berg05c914f2008-09-11 00:01:58 +0200647 if (priv->common.mode != NL80211_IFTYPE_UNSPECIFIED) {
Michael Wueff1a592007-09-25 18:11:01 -0700648 p54p_open(dev);
Johannes Berg36d68252008-05-15 12:55:26 +0200649 ieee80211_wake_queues(dev);
Michael Wueff1a592007-09-25 18:11:01 -0700650 }
651
652 return 0;
653}
654#endif /* CONFIG_PM */
655
656static struct pci_driver p54p_driver = {
Christian Lamparter32ddf072008-08-08 21:17:37 +0200657 .name = "p54pci",
Michael Wueff1a592007-09-25 18:11:01 -0700658 .id_table = p54p_table,
659 .probe = p54p_probe,
660 .remove = __devexit_p(p54p_remove),
661#ifdef CONFIG_PM
662 .suspend = p54p_suspend,
663 .resume = p54p_resume,
664#endif /* CONFIG_PM */
665};
666
667static int __init p54p_init(void)
668{
669 return pci_register_driver(&p54p_driver);
670}
671
672static void __exit p54p_exit(void)
673{
674 pci_unregister_driver(&p54p_driver);
675}
676
677module_init(p54p_init);
678module_exit(p54p_exit);