aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/p54/p54pci.c
diff options
context:
space:
mode:
authorChristian Lamparter <chunkeey@web.de>2008-09-01 16:48:51 -0400
committerJohn W. Linville <linville@tuxdriver.com>2008-09-05 16:17:48 -0400
commit7cb770729ba895f73253dfcd46c3fcba45d896f9 (patch)
tree8a970a683779490b478b9737154cb5d2e792c0a5 /drivers/net/wireless/p54/p54pci.c
parent4e416a6f49b710bfe162f0cb24bc68c74493d2a0 (diff)
p54: move eeprom code into common library
Both p54pci and p54usb uses a good chunk of device specific code to get the data from the device's eeprom into the drivers memory. So, this patch reduces the code size and will it make life easier if someone wants to implement ethtool eeprom dumping features. Signed-off-by: Christian Lamparter <chunkeey@web.de> Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers/net/wireless/p54/p54pci.c')
-rw-r--r--drivers/net/wireless/p54/p54pci.c144
1 files changed, 13 insertions, 131 deletions
diff --git a/drivers/net/wireless/p54/p54pci.c b/drivers/net/wireless/p54/p54pci.c
index fdfc7189f0ff..1594786205f8 100644
--- a/drivers/net/wireless/p54/p54pci.c
+++ b/drivers/net/wireless/p54/p54pci.c
@@ -72,8 +72,6 @@ static int p54p_upload_firmware(struct ieee80211_hw *dev)
72 P54P_WRITE(ctrl_stat, reg); 72 P54P_WRITE(ctrl_stat, reg);
73 wmb(); 73 wmb();
74 74
75 mdelay(50);
76
77 err = request_firmware(&fw_entry, "isl3886", &priv->pdev->dev); 75 err = request_firmware(&fw_entry, "isl3886", &priv->pdev->dev);
78 if (err) { 76 if (err) {
79 printk(KERN_ERR "%s (p54pci): cannot find firmware " 77 printk(KERN_ERR "%s (p54pci): cannot find firmware "
@@ -126,120 +124,10 @@ static int p54p_upload_firmware(struct ieee80211_hw *dev)
126 wmb(); 124 wmb();
127 udelay(10); 125 udelay(10);
128 126
129 return 0; 127 /* wait for the firmware to boot properly */
130}
131
132static irqreturn_t p54p_simple_interrupt(int irq, void *dev_id)
133{
134 struct p54p_priv *priv = (struct p54p_priv *) dev_id;
135 __le32 reg;
136
137 reg = P54P_READ(int_ident);
138 P54P_WRITE(int_ack, reg);
139
140 if (reg & P54P_READ(int_enable))
141 complete(&priv->boot_comp);
142
143 return IRQ_HANDLED;
144}
145
146static int p54p_read_eeprom(struct ieee80211_hw *dev)
147{
148 struct p54p_priv *priv = dev->priv;
149 struct p54p_ring_control *ring_control = priv->ring_control;
150 int err;
151 struct p54_control_hdr *hdr;
152 void *eeprom;
153 dma_addr_t rx_mapping, tx_mapping;
154 u16 alen;
155
156 init_completion(&priv->boot_comp);
157 err = request_irq(priv->pdev->irq, &p54p_simple_interrupt,
158 IRQF_SHARED, "p54pci", priv);
159 if (err) {
160 printk(KERN_ERR "%s (p54pci): failed to register IRQ handler\n",
161 pci_name(priv->pdev));
162 return err;
163 }
164
165 eeprom = kmalloc(0x2010 + EEPROM_READBACK_LEN, GFP_KERNEL);
166 if (!eeprom) {
167 printk(KERN_ERR "%s (p54pci): no memory for eeprom!\n",
168 pci_name(priv->pdev));
169 err = -ENOMEM;
170 goto out;
171 }
172
173 memset(ring_control, 0, sizeof(*ring_control));
174 P54P_WRITE(ring_control_base, cpu_to_le32(priv->ring_control_dma));
175 P54P_READ(ring_control_base);
176 udelay(10);
177
178 P54P_WRITE(int_enable, cpu_to_le32(ISL38XX_INT_IDENT_INIT));
179 P54P_READ(int_enable);
180 udelay(10);
181
182 P54P_WRITE(dev_int, cpu_to_le32(ISL38XX_DEV_INT_RESET));
183
184 if (!wait_for_completion_interruptible_timeout(&priv->boot_comp, HZ)) {
185 printk(KERN_ERR "%s (p54pci): Cannot boot firmware!\n",
186 pci_name(priv->pdev));
187 err = -EINVAL;
188 goto out;
189 }
190
191 P54P_WRITE(int_enable, cpu_to_le32(ISL38XX_INT_IDENT_UPDATE));
192 P54P_READ(int_enable);
193
194 hdr = eeprom + 0x2010;
195 p54_fill_eeprom_readback(hdr);
196 hdr->req_id = cpu_to_le32(priv->common.rx_start);
197
198 rx_mapping = pci_map_single(priv->pdev, eeprom,
199 0x2010, PCI_DMA_FROMDEVICE);
200 tx_mapping = pci_map_single(priv->pdev, (void *)hdr,
201 EEPROM_READBACK_LEN, PCI_DMA_TODEVICE);
202
203 ring_control->rx_mgmt[0].host_addr = cpu_to_le32(rx_mapping);
204 ring_control->rx_mgmt[0].len = cpu_to_le16(0x2010);
205 ring_control->tx_data[0].host_addr = cpu_to_le32(tx_mapping);
206 ring_control->tx_data[0].device_addr = hdr->req_id;
207 ring_control->tx_data[0].len = cpu_to_le16(EEPROM_READBACK_LEN);
208
209 ring_control->host_idx[2] = cpu_to_le32(1);
210 ring_control->host_idx[1] = cpu_to_le32(1);
211
212 wmb();
213 mdelay(100); 128 mdelay(100);
214 P54P_WRITE(dev_int, cpu_to_le32(ISL38XX_DEV_INT_UPDATE));
215
216 wait_for_completion_interruptible_timeout(&priv->boot_comp, HZ);
217 wait_for_completion_interruptible_timeout(&priv->boot_comp, HZ);
218
219 pci_unmap_single(priv->pdev, tx_mapping,
220 EEPROM_READBACK_LEN, PCI_DMA_TODEVICE);
221 pci_unmap_single(priv->pdev, rx_mapping,
222 0x2010, PCI_DMA_FROMDEVICE);
223
224 alen = le16_to_cpu(ring_control->rx_mgmt[0].len);
225 if (le32_to_cpu(ring_control->device_idx[2]) != 1 ||
226 alen < 0x10) {
227 printk(KERN_ERR "%s (p54pci): Cannot read eeprom!\n",
228 pci_name(priv->pdev));
229 err = -EINVAL;
230 goto out;
231 }
232 129
233 p54_parse_eeprom(dev, (u8 *)eeprom + 0x10, alen - 0x10); 130 return 0;
234
235 out:
236 kfree(eeprom);
237 P54P_WRITE(int_enable, cpu_to_le32(0));
238 P54P_READ(int_enable);
239 udelay(10);
240 free_irq(priv->pdev->irq, priv);
241 P54P_WRITE(dev_int, cpu_to_le32(ISL38XX_DEV_INT_RESET));
242 return err;
243} 131}
244 132
245static void p54p_refill_rx_ring(struct ieee80211_hw *dev, 133static void p54p_refill_rx_ring(struct ieee80211_hw *dev,
@@ -473,6 +361,11 @@ static int p54p_open(struct ieee80211_hw *dev)
473 } 361 }
474 362
475 memset(priv->ring_control, 0, sizeof(*priv->ring_control)); 363 memset(priv->ring_control, 0, sizeof(*priv->ring_control));
364 err = p54p_upload_firmware(dev);
365 if (err) {
366 free_irq(priv->pdev->irq, dev);
367 return err;
368 }
476 priv->rx_idx_data = priv->tx_idx_data = 0; 369 priv->rx_idx_data = priv->tx_idx_data = 0;
477 priv->rx_idx_mgmt = priv->tx_idx_mgmt = 0; 370 priv->rx_idx_mgmt = priv->tx_idx_mgmt = 0;
478 371
@@ -482,8 +375,6 @@ static int p54p_open(struct ieee80211_hw *dev)
482 p54p_refill_rx_ring(dev, 2, priv->ring_control->rx_mgmt, 375 p54p_refill_rx_ring(dev, 2, priv->ring_control->rx_mgmt,
483 ARRAY_SIZE(priv->ring_control->rx_mgmt), priv->rx_buf_mgmt); 376 ARRAY_SIZE(priv->ring_control->rx_mgmt), priv->rx_buf_mgmt);
484 377
485 p54p_upload_firmware(dev);
486
487 P54P_WRITE(ring_control_base, cpu_to_le32(priv->ring_control_dma)); 378 P54P_WRITE(ring_control_base, cpu_to_le32(priv->ring_control_dma));
488 P54P_READ(ring_control_base); 379 P54P_READ(ring_control_base);
489 wmb(); 380 wmb();
@@ -658,16 +549,6 @@ static int __devinit p54p_probe(struct pci_dev *pdev,
658 err = -ENOMEM; 549 err = -ENOMEM;
659 goto err_iounmap; 550 goto err_iounmap;
660 } 551 }
661 memset(priv->ring_control, 0, sizeof(*priv->ring_control));
662
663 err = p54p_upload_firmware(dev);
664 if (err)
665 goto err_free_desc;
666
667 err = p54p_read_eeprom(dev);
668 if (err)
669 goto err_free_desc;
670
671 priv->common.open = p54p_open; 552 priv->common.open = p54p_open;
672 priv->common.stop = p54p_stop; 553 priv->common.stop = p54p_stop;
673 priv->common.tx = p54p_tx; 554 priv->common.tx = p54p_tx;
@@ -675,6 +556,12 @@ static int __devinit p54p_probe(struct pci_dev *pdev,
675 spin_lock_init(&priv->lock); 556 spin_lock_init(&priv->lock);
676 tasklet_init(&priv->rx_tasklet, p54p_rx_tasklet, (unsigned long)dev); 557 tasklet_init(&priv->rx_tasklet, p54p_rx_tasklet, (unsigned long)dev);
677 558
559 p54p_open(dev);
560 err = p54_read_eeprom(dev);
561 p54p_stop(dev);
562 if (err)
563 goto err_free_desc;
564
678 err = ieee80211_register_hw(dev); 565 err = ieee80211_register_hw(dev);
679 if (err) { 566 if (err) {
680 printk(KERN_ERR "%s (p54pci): Cannot register netdevice\n", 567 printk(KERN_ERR "%s (p54pci): Cannot register netdevice\n",
@@ -682,11 +569,6 @@ static int __devinit p54p_probe(struct pci_dev *pdev,
682 goto err_free_common; 569 goto err_free_common;
683 } 570 }
684 571
685 printk(KERN_INFO "%s: hwaddr %s, isl38%02x\n",
686 wiphy_name(dev->wiphy),
687 print_mac(mac, dev->wiphy->perm_addr),
688 priv->common.version);
689
690 return 0; 572 return 0;
691 573
692 err_free_common: 574 err_free_common: