1
2
3
4
5
6
7
8#include <linux/hardirq.h>
9#include <linux/module.h>
10#include <linux/slab.h>
11
12#include <linux/netdevice.h>
13#include <linux/ethtool.h>
14#include <linux/pci.h>
15#include <linux/sched.h>
16#include <linux/etherdevice.h>
17#include <linux/delay.h>
18#include <linux/if_arp.h>
19
20#include <asm/io.h>
21
22#include "prismcompat.h"
23#include "isl_38xx.h"
24#include "isl_ioctl.h"
25#include "islpci_dev.h"
26#include "islpci_mgt.h"
27#include "islpci_eth.h"
28#include "oid_mgt.h"
29
30#define ISL3877_IMAGE_FILE "isl3877"
31#define ISL3886_IMAGE_FILE "isl3886"
32#define ISL3890_IMAGE_FILE "isl3890"
33MODULE_FIRMWARE(ISL3877_IMAGE_FILE);
34MODULE_FIRMWARE(ISL3886_IMAGE_FILE);
35MODULE_FIRMWARE(ISL3890_IMAGE_FILE);
36
37static int prism54_bring_down(islpci_private *);
38static int islpci_alloc_memory(islpci_private *);
39
40
41
42
43
44
45
46
47static const unsigned char dummy_mac[6] = { 0x00, 0x30, 0xB4, 0x00, 0x00, 0x00 };
48
49static int
50isl_upload_firmware(islpci_private *priv)
51{
52 u32 reg, rc;
53 void __iomem *device_base = priv->device_base;
54
55
56 reg = readl(device_base + ISL38XX_CTRL_STAT_REG);
57 reg &= ~ISL38XX_CTRL_STAT_RESET;
58 reg &= ~ISL38XX_CTRL_STAT_RAMBOOT;
59 writel(reg, device_base + ISL38XX_CTRL_STAT_REG);
60 wmb();
61 udelay(ISL38XX_WRITEIO_DELAY);
62
63
64 reg |= ISL38XX_CTRL_STAT_RESET;
65 writel(reg, device_base + ISL38XX_CTRL_STAT_REG);
66 wmb();
67 udelay(ISL38XX_WRITEIO_DELAY);
68
69
70 reg &= ~ISL38XX_CTRL_STAT_RESET;
71 writel(reg, device_base + ISL38XX_CTRL_STAT_REG);
72 wmb();
73
74
75 mdelay(50);
76
77 {
78 const struct firmware *fw_entry = NULL;
79 long fw_len;
80 const u32 *fw_ptr;
81
82 rc = request_firmware(&fw_entry, priv->firmware, PRISM_FW_PDEV);
83 if (rc) {
84 printk(KERN_ERR
85 "%s: request_firmware() failed for '%s'\n",
86 "prism54", priv->firmware);
87 return rc;
88 }
89
90 reg = ISL38XX_DEV_FIRMWARE_ADDRES;
91
92 fw_ptr = (u32 *) fw_entry->data;
93 fw_len = fw_entry->size;
94
95 if (fw_len % 4) {
96 printk(KERN_ERR
97 "%s: firmware '%s' size is not multiple of 32bit, aborting!\n",
98 "prism54", priv->firmware);
99 release_firmware(fw_entry);
100 return -EILSEQ; ;
101 }
102
103 while (fw_len > 0) {
104 long _fw_len =
105 (fw_len >
106 ISL38XX_MEMORY_WINDOW_SIZE) ?
107 ISL38XX_MEMORY_WINDOW_SIZE : fw_len;
108 u32 __iomem *dev_fw_ptr = device_base + ISL38XX_DIRECT_MEM_WIN;
109
110
111 isl38xx_w32_flush(device_base, reg,
112 ISL38XX_DIR_MEM_BASE_REG);
113 wmb();
114
115
116 reg += _fw_len;
117 fw_len -= _fw_len;
118
119
120
121 while (_fw_len > 0) {
122
123 __raw_writel(*fw_ptr, dev_fw_ptr);
124 fw_ptr++, dev_fw_ptr++;
125 _fw_len -= 4;
126 }
127
128
129 (void) readl(device_base + ISL38XX_PCI_POSTING_FLUSH);
130 wmb();
131
132 BUG_ON(_fw_len != 0);
133 }
134
135 BUG_ON(fw_len != 0);
136
137
138 printk(KERN_DEBUG "%s: firmware version: %.8s\n",
139 priv->ndev->name, fw_entry->data + 40);
140
141 release_firmware(fw_entry);
142 }
143
144
145
146 reg = readl(device_base + ISL38XX_CTRL_STAT_REG);
147 reg &= ~ISL38XX_CTRL_STAT_CLKRUN;
148 reg &= ~ISL38XX_CTRL_STAT_RESET;
149 reg |= ISL38XX_CTRL_STAT_RAMBOOT;
150 isl38xx_w32_flush(device_base, reg, ISL38XX_CTRL_STAT_REG);
151 wmb();
152 udelay(ISL38XX_WRITEIO_DELAY);
153
154
155
156 reg |= ISL38XX_CTRL_STAT_RESET;
157 writel(reg, device_base + ISL38XX_CTRL_STAT_REG);
158
159 wmb();
160 udelay(ISL38XX_WRITEIO_DELAY);
161
162
163 reg &= ~ISL38XX_CTRL_STAT_RESET;
164 writel(reg, device_base + ISL38XX_CTRL_STAT_REG);
165
166 wmb();
167 udelay(ISL38XX_WRITEIO_DELAY);
168
169 return 0;
170}
171
172
173
174
175
176irqreturn_t
177islpci_interrupt(int irq, void *config)
178{
179 u32 reg;
180 islpci_private *priv = config;
181 struct net_device *ndev = priv->ndev;
182 void __iomem *device = priv->device_base;
183 int powerstate = ISL38XX_PSM_POWERSAVE_STATE;
184
185
186 spin_lock(&priv->slock);
187
188
189
190 reg = readl(device + ISL38XX_CTRL_STAT_REG);
191 if (reg & ISL38XX_CTRL_STAT_SLEEPMODE)
192
193 {
194#if VERBOSE > SHOW_ERROR_MESSAGES
195 DEBUG(SHOW_TRACING, "Assuming someone else called the IRQ\n");
196#endif
197 spin_unlock(&priv->slock);
198 return IRQ_NONE;
199 }
200
201
202
203 reg = readl(device + ISL38XX_INT_IDENT_REG);
204
205
206
207 reg &= readl(device + ISL38XX_INT_EN_REG);
208 reg &= ISL38XX_INT_SOURCES;
209
210 if (reg != 0) {
211 if (islpci_get_state(priv) != PRV_STATE_SLEEP)
212 powerstate = ISL38XX_PSM_ACTIVE_STATE;
213
214
215 isl38xx_w32_flush(device, reg, ISL38XX_INT_ACK_REG);
216
217#if VERBOSE > SHOW_ERROR_MESSAGES
218 DEBUG(SHOW_FUNCTION_CALLS,
219 "IRQ: Identification register 0x%p 0x%x\n", device, reg);
220#endif
221
222
223 if (reg & ISL38XX_INT_IDENT_UPDATE) {
224#if VERBOSE > SHOW_ERROR_MESSAGES
225
226 DEBUG(SHOW_TRACING, "IRQ: Update flag\n");
227
228 DEBUG(SHOW_QUEUE_INDEXES,
229 "CB drv Qs: [%i][%i][%i][%i][%i][%i]\n",
230 le32_to_cpu(priv->control_block->
231 driver_curr_frag[0]),
232 le32_to_cpu(priv->control_block->
233 driver_curr_frag[1]),
234 le32_to_cpu(priv->control_block->
235 driver_curr_frag[2]),
236 le32_to_cpu(priv->control_block->
237 driver_curr_frag[3]),
238 le32_to_cpu(priv->control_block->
239 driver_curr_frag[4]),
240 le32_to_cpu(priv->control_block->
241 driver_curr_frag[5])
242 );
243
244 DEBUG(SHOW_QUEUE_INDEXES,
245 "CB dev Qs: [%i][%i][%i][%i][%i][%i]\n",
246 le32_to_cpu(priv->control_block->
247 device_curr_frag[0]),
248 le32_to_cpu(priv->control_block->
249 device_curr_frag[1]),
250 le32_to_cpu(priv->control_block->
251 device_curr_frag[2]),
252 le32_to_cpu(priv->control_block->
253 device_curr_frag[3]),
254 le32_to_cpu(priv->control_block->
255 device_curr_frag[4]),
256 le32_to_cpu(priv->control_block->
257 device_curr_frag[5])
258 );
259#endif
260
261
262 islpci_eth_cleanup_transmit(priv, priv->control_block);
263
264
265
266 powerstate = ISL38XX_PSM_ACTIVE_STATE;
267
268
269
270
271 if (isl38xx_in_queue(priv->control_block,
272 ISL38XX_CB_RX_MGMTQ) != 0) {
273#if VERBOSE > SHOW_ERROR_MESSAGES
274 DEBUG(SHOW_TRACING,
275 "Received frame in Management Queue\n");
276#endif
277 islpci_mgt_receive(ndev);
278
279 islpci_mgt_cleanup_transmit(ndev);
280
281
282 islpci_mgmt_rx_fill(ndev);
283
284
285
286 }
287
288 while (isl38xx_in_queue(priv->control_block,
289 ISL38XX_CB_RX_DATA_LQ) != 0) {
290#if VERBOSE > SHOW_ERROR_MESSAGES
291 DEBUG(SHOW_TRACING,
292 "Received frame in Data Low Queue\n");
293#endif
294 islpci_eth_receive(priv);
295 }
296
297
298 if (priv->data_low_tx_full) {
299
300 if (ISL38XX_CB_TX_QSIZE -
301 isl38xx_in_queue(priv->control_block,
302 ISL38XX_CB_TX_DATA_LQ) >=
303 ISL38XX_MIN_QTHRESHOLD) {
304
305 netif_wake_queue(priv->ndev);
306
307
308 priv->data_low_tx_full = 0;
309 }
310 }
311 }
312
313 if (reg & ISL38XX_INT_IDENT_INIT) {
314
315#if VERBOSE > SHOW_ERROR_MESSAGES
316 DEBUG(SHOW_TRACING,
317 "IRQ: Init flag, device initialized\n");
318#endif
319 wake_up(&priv->reset_done);
320 }
321
322 if (reg & ISL38XX_INT_IDENT_SLEEP) {
323
324#if VERBOSE > SHOW_ERROR_MESSAGES
325 DEBUG(SHOW_TRACING, "IRQ: Sleep flag\n");
326#endif
327 isl38xx_handle_sleep_request(priv->control_block,
328 &powerstate,
329 priv->device_base);
330 }
331
332 if (reg & ISL38XX_INT_IDENT_WAKEUP) {
333
334#if VERBOSE > SHOW_ERROR_MESSAGES
335 DEBUG(SHOW_TRACING, "IRQ: Wakeup flag\n");
336#endif
337
338 isl38xx_handle_wakeup(priv->control_block,
339 &powerstate, priv->device_base);
340 }
341 } else {
342#if VERBOSE > SHOW_ERROR_MESSAGES
343 DEBUG(SHOW_TRACING, "Assuming someone else called the IRQ\n");
344#endif
345 spin_unlock(&priv->slock);
346 return IRQ_NONE;
347 }
348
349
350 if (islpci_get_state(priv) == PRV_STATE_SLEEP
351 && powerstate == ISL38XX_PSM_ACTIVE_STATE)
352 islpci_set_state(priv, PRV_STATE_READY);
353
354
355 if (islpci_get_state(priv) != PRV_STATE_SLEEP
356 && powerstate == ISL38XX_PSM_POWERSAVE_STATE)
357 islpci_set_state(priv, PRV_STATE_SLEEP);
358
359
360 spin_unlock(&priv->slock);
361
362 return IRQ_HANDLED;
363}
364
365
366
367
368static int
369islpci_open(struct net_device *ndev)
370{
371 u32 rc;
372 islpci_private *priv = netdev_priv(ndev);
373
374
375 rc = islpci_reset(priv,1);
376 if (rc) {
377 prism54_bring_down(priv);
378 return rc;
379 }
380
381 netif_start_queue(ndev);
382
383
384
385
386
387
388 if (priv->iw_mode == IW_MODE_INFRA || priv->iw_mode == IW_MODE_ADHOC)
389 netif_carrier_off(ndev);
390 else
391 netif_carrier_on(ndev);
392
393 return 0;
394}
395
396static int
397islpci_close(struct net_device *ndev)
398{
399 islpci_private *priv = netdev_priv(ndev);
400
401 printk(KERN_DEBUG "%s: islpci_close ()\n", ndev->name);
402
403 netif_stop_queue(ndev);
404
405 return prism54_bring_down(priv);
406}
407
408static int
409prism54_bring_down(islpci_private *priv)
410{
411 void __iomem *device_base = priv->device_base;
412 u32 reg;
413
414 islpci_set_state(priv, PRV_STATE_PREBOOT);
415
416
417 isl38xx_disable_interrupts(priv->device_base);
418
419
420
421
422
423 synchronize_irq(priv->pdev->irq);
424
425 reg = readl(device_base + ISL38XX_CTRL_STAT_REG);
426 reg &= ~(ISL38XX_CTRL_STAT_RESET | ISL38XX_CTRL_STAT_RAMBOOT);
427 writel(reg, device_base + ISL38XX_CTRL_STAT_REG);
428 wmb();
429 udelay(ISL38XX_WRITEIO_DELAY);
430
431 reg |= ISL38XX_CTRL_STAT_RESET;
432 writel(reg, device_base + ISL38XX_CTRL_STAT_REG);
433 wmb();
434 udelay(ISL38XX_WRITEIO_DELAY);
435
436
437 reg &= ~ISL38XX_CTRL_STAT_RESET;
438 writel(reg, device_base + ISL38XX_CTRL_STAT_REG);
439 wmb();
440
441
442 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
443
444 return 0;
445}
446
447static int
448islpci_upload_fw(islpci_private *priv)
449{
450 islpci_state_t old_state;
451 u32 rc;
452
453 old_state = islpci_set_state(priv, PRV_STATE_BOOT);
454
455 printk(KERN_DEBUG "%s: uploading firmware...\n", priv->ndev->name);
456
457 rc = isl_upload_firmware(priv);
458 if (rc) {
459
460 printk(KERN_ERR "%s: could not upload firmware ('%s')\n",
461 priv->ndev->name, priv->firmware);
462
463 islpci_set_state(priv, old_state);
464 return rc;
465 }
466
467 printk(KERN_DEBUG "%s: firmware upload complete\n",
468 priv->ndev->name);
469
470 islpci_set_state(priv, PRV_STATE_POSTBOOT);
471
472 return 0;
473}
474
475static int
476islpci_reset_if(islpci_private *priv)
477{
478 long remaining;
479 int result = -ETIME;
480 int count;
481
482 DEFINE_WAIT(wait);
483 prepare_to_wait(&priv->reset_done, &wait, TASK_UNINTERRUPTIBLE);
484
485
486 isl38xx_interface_reset(priv->device_base, priv->device_host_address);
487 islpci_set_state(priv, PRV_STATE_PREINIT);
488
489 for(count = 0; count < 2 && result; count++) {
490
491
492
493 remaining = schedule_timeout_uninterruptible(HZ);
494
495 if(remaining > 0) {
496 result = 0;
497 break;
498 }
499
500
501
502
503 printk(KERN_ERR "%s: no 'reset complete' IRQ seen - retrying\n",
504 priv->ndev->name);
505 }
506
507 finish_wait(&priv->reset_done, &wait);
508
509 if (result) {
510 printk(KERN_ERR "%s: interface reset failure\n", priv->ndev->name);
511 return result;
512 }
513
514 islpci_set_state(priv, PRV_STATE_INIT);
515
516
517
518
519
520
521 isl38xx_enable_common_interrupts(priv->device_base);
522
523 down_write(&priv->mib_sem);
524 result = mgt_commit(priv);
525 if (result) {
526 printk(KERN_ERR "%s: interface reset failure\n", priv->ndev->name);
527 up_write(&priv->mib_sem);
528 return result;
529 }
530 up_write(&priv->mib_sem);
531
532 islpci_set_state(priv, PRV_STATE_READY);
533
534 printk(KERN_DEBUG "%s: interface reset complete\n", priv->ndev->name);
535 return 0;
536}
537
538int
539islpci_reset(islpci_private *priv, int reload_firmware)
540{
541 isl38xx_control_block *cb =
542 (isl38xx_control_block *) priv->control_block;
543 unsigned counter;
544 int rc;
545
546 if (reload_firmware)
547 islpci_set_state(priv, PRV_STATE_PREBOOT);
548 else
549 islpci_set_state(priv, PRV_STATE_POSTBOOT);
550
551 printk(KERN_DEBUG "%s: resetting device...\n", priv->ndev->name);
552
553
554 isl38xx_disable_interrupts(priv->device_base);
555
556
557 priv->index_mgmt_tx = 0;
558 priv->index_mgmt_rx = 0;
559
560
561 for (counter = 0; counter < ISL38XX_CB_QCOUNT; counter++) {
562 cb->driver_curr_frag[counter] = cpu_to_le32(0);
563 cb->device_curr_frag[counter] = cpu_to_le32(0);
564 }
565
566
567 for (counter = 0; counter < ISL38XX_CB_MGMT_QSIZE; counter++) {
568 isl38xx_fragment *frag = &cb->rx_data_mgmt[counter];
569 frag->size = cpu_to_le16(MGMT_FRAME_SIZE);
570 frag->flags = 0;
571 frag->address = cpu_to_le32(priv->mgmt_rx[counter].pci_addr);
572 }
573
574 for (counter = 0; counter < ISL38XX_CB_RX_QSIZE; counter++) {
575 cb->rx_data_low[counter].address =
576 cpu_to_le32((u32) priv->pci_map_rx_address[counter]);
577 }
578
579
580
581 priv->control_block->driver_curr_frag[ISL38XX_CB_RX_DATA_LQ] =
582 cpu_to_le32(ISL38XX_CB_RX_QSIZE);
583 priv->control_block->driver_curr_frag[ISL38XX_CB_RX_MGMTQ] =
584 cpu_to_le32(ISL38XX_CB_MGMT_QSIZE);
585
586
587 priv->free_data_rx = 0;
588 priv->free_data_tx = 0;
589 priv->data_low_tx_full = 0;
590
591 if (reload_firmware) {
592
593
594 rc = islpci_upload_fw(priv);
595 if (rc) {
596 printk(KERN_ERR "%s: islpci_reset: failure\n",
597 priv->ndev->name);
598 return rc;
599 }
600 }
601
602
603 rc = islpci_reset_if(priv);
604 if (rc)
605 printk(KERN_ERR "prism54: Your card/socket may be faulty, or IRQ line too busy :(\n");
606 return rc;
607}
608
609
610
611
612static int
613islpci_alloc_memory(islpci_private *priv)
614{
615 int counter;
616
617#if VERBOSE > SHOW_ERROR_MESSAGES
618 printk(KERN_DEBUG "islpci_alloc_memory\n");
619#endif
620
621
622 if (!(priv->device_base =
623 ioremap(pci_resource_start(priv->pdev, 0),
624 ISL38XX_PCI_MEM_SIZE))) {
625
626 printk(KERN_ERR "PCI memory remapping failed\n");
627 return -1;
628 }
629
630
631
632
633
634
635
636
637
638
639 priv->driver_mem_address = pci_alloc_consistent(priv->pdev,
640 HOST_MEM_BLOCK,
641 &priv->
642 device_host_address);
643
644 if (!priv->driver_mem_address) {
645
646 printk(KERN_ERR "%s: could not allocate DMA memory, aborting!",
647 "prism54");
648 return -1;
649 }
650
651
652 priv->control_block =
653 (isl38xx_control_block *) priv->driver_mem_address;
654
655
656 priv->device_psm_buffer =
657 priv->device_host_address + CONTROL_BLOCK_SIZE;
658
659
660 for (counter = 0; counter < ISL38XX_CB_QCOUNT; counter++) {
661 priv->control_block->driver_curr_frag[counter] = cpu_to_le32(0);
662 priv->control_block->device_curr_frag[counter] = cpu_to_le32(0);
663 }
664
665 priv->index_mgmt_rx = 0;
666 memset(priv->mgmt_rx, 0, sizeof(priv->mgmt_rx));
667 memset(priv->mgmt_tx, 0, sizeof(priv->mgmt_tx));
668
669
670 if (islpci_mgmt_rx_fill(priv->ndev) < 0)
671 goto out_free;
672
673
674 memset(priv->data_low_rx, 0, sizeof (priv->data_low_rx));
675 memset(priv->pci_map_rx_address, 0, sizeof (priv->pci_map_rx_address));
676
677 for (counter = 0; counter < ISL38XX_CB_RX_QSIZE; counter++) {
678 struct sk_buff *skb;
679
680
681
682
683 if (!(skb = dev_alloc_skb(MAX_FRAGMENT_SIZE_RX + 2))) {
684
685 printk(KERN_ERR "Error allocating skb.\n");
686 skb = NULL;
687 goto out_free;
688 }
689 skb_reserve(skb, (4 - (long) skb->data) & 0x03);
690
691 priv->data_low_rx[counter] = skb;
692
693
694 priv->pci_map_rx_address[counter] =
695 pci_map_single(priv->pdev, (void *) skb->data,
696 MAX_FRAGMENT_SIZE_RX + 2,
697 PCI_DMA_FROMDEVICE);
698 if (pci_dma_mapping_error(priv->pdev,
699 priv->pci_map_rx_address[counter])) {
700 priv->pci_map_rx_address[counter] = 0;
701
702
703 printk(KERN_ERR "failed to map skb DMA'able\n");
704 goto out_free;
705 }
706 }
707
708 prism54_acl_init(&priv->acl);
709 prism54_wpa_bss_ie_init(priv);
710 if (mgt_init(priv))
711 goto out_free;
712
713 return 0;
714 out_free:
715 islpci_free_memory(priv);
716 return -1;
717}
718
719int
720islpci_free_memory(islpci_private *priv)
721{
722 int counter;
723
724 if (priv->device_base)
725 iounmap(priv->device_base);
726 priv->device_base = NULL;
727
728
729 if (priv->driver_mem_address)
730 pci_free_consistent(priv->pdev, HOST_MEM_BLOCK,
731 priv->driver_mem_address,
732 priv->device_host_address);
733
734
735 priv->driver_mem_address = NULL;
736 priv->device_host_address = 0;
737 priv->device_psm_buffer = 0;
738 priv->control_block = NULL;
739
740
741 for (counter = 0; counter < ISL38XX_CB_MGMT_QSIZE; counter++) {
742 struct islpci_membuf *buf = &priv->mgmt_rx[counter];
743 if (buf->pci_addr)
744 pci_unmap_single(priv->pdev, buf->pci_addr,
745 buf->size, PCI_DMA_FROMDEVICE);
746 buf->pci_addr = 0;
747 kfree(buf->mem);
748 buf->size = 0;
749 buf->mem = NULL;
750 }
751
752
753 for (counter = 0; counter < ISL38XX_CB_RX_QSIZE; counter++) {
754 if (priv->pci_map_rx_address[counter])
755 pci_unmap_single(priv->pdev,
756 priv->pci_map_rx_address[counter],
757 MAX_FRAGMENT_SIZE_RX + 2,
758 PCI_DMA_FROMDEVICE);
759 priv->pci_map_rx_address[counter] = 0;
760
761 if (priv->data_low_rx[counter])
762 dev_kfree_skb(priv->data_low_rx[counter]);
763 priv->data_low_rx[counter] = NULL;
764 }
765
766
767 prism54_acl_clean(&priv->acl);
768 prism54_wpa_bss_ie_clean(priv);
769 mgt_clean(priv);
770
771 return 0;
772}
773
774#if 0
775static void
776islpci_set_multicast_list(struct net_device *dev)
777{
778
779}
780#endif
781
782static void islpci_ethtool_get_drvinfo(struct net_device *dev,
783 struct ethtool_drvinfo *info)
784{
785 strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
786 strlcpy(info->version, DRV_VERSION, sizeof(info->version));
787}
788
789static const struct ethtool_ops islpci_ethtool_ops = {
790 .get_drvinfo = islpci_ethtool_get_drvinfo,
791};
792
793static const struct net_device_ops islpci_netdev_ops = {
794 .ndo_open = islpci_open,
795 .ndo_stop = islpci_close,
796 .ndo_start_xmit = islpci_eth_transmit,
797 .ndo_tx_timeout = islpci_eth_tx_timeout,
798 .ndo_set_mac_address = prism54_set_mac_address,
799 .ndo_validate_addr = eth_validate_addr,
800};
801
802static struct device_type wlan_type = {
803 .name = "wlan",
804};
805
806struct net_device *
807islpci_setup(struct pci_dev *pdev)
808{
809 islpci_private *priv;
810 struct net_device *ndev = alloc_etherdev(sizeof (islpci_private));
811
812 if (!ndev)
813 return ndev;
814
815 pci_set_drvdata(pdev, ndev);
816 SET_NETDEV_DEV(ndev, &pdev->dev);
817 SET_NETDEV_DEVTYPE(ndev, &wlan_type);
818
819
820 ndev->base_addr = pci_resource_start(pdev, 0);
821 ndev->irq = pdev->irq;
822
823
824 ndev->netdev_ops = &islpci_netdev_ops;
825 ndev->wireless_handlers = &prism54_handler_def;
826 ndev->ethtool_ops = &islpci_ethtool_ops;
827
828
829 ndev->addr_len = ETH_ALEN;
830
831 memcpy(ndev->dev_addr, dummy_mac, ETH_ALEN);
832
833 ndev->watchdog_timeo = ISLPCI_TX_TIMEOUT;
834
835
836 priv = netdev_priv(ndev);
837 priv->ndev = ndev;
838 priv->pdev = pdev;
839 priv->monitor_type = ARPHRD_IEEE80211;
840 priv->ndev->type = (priv->iw_mode == IW_MODE_MONITOR) ?
841 priv->monitor_type : ARPHRD_ETHER;
842
843
844 priv->wireless_data.spy_data = &priv->spy_data;
845 ndev->wireless_data = &priv->wireless_data;
846
847
848 ndev->mem_start = (unsigned long) priv->device_base;
849 ndev->mem_end = ndev->mem_start + ISL38XX_PCI_MEM_SIZE;
850
851#if VERBOSE > SHOW_ERROR_MESSAGES
852 DEBUG(SHOW_TRACING, "PCI Memory remapped to 0x%p\n", priv->device_base);
853#endif
854
855 init_waitqueue_head(&priv->reset_done);
856
857
858 mutex_init(&priv->mgmt_lock);
859 priv->mgmt_received = NULL;
860 init_waitqueue_head(&priv->mgmt_wqueue);
861 mutex_init(&priv->stats_lock);
862 spin_lock_init(&priv->slock);
863
864
865 priv->state = PRV_STATE_OFF;
866 priv->state_off = 1;
867
868
869 INIT_WORK(&priv->stats_work, prism54_update_stats);
870 priv->stats_timestamp = 0;
871
872 INIT_WORK(&priv->reset_task, islpci_do_reset_and_wake);
873 priv->reset_task_pending = 0;
874
875
876 if (islpci_alloc_memory(priv))
877 goto do_free_netdev;
878
879
880 switch (pdev->device) {
881 case 0x3877:
882 strcpy(priv->firmware, ISL3877_IMAGE_FILE);
883 break;
884
885 case 0x3886:
886 strcpy(priv->firmware, ISL3886_IMAGE_FILE);
887 break;
888
889 default:
890 strcpy(priv->firmware, ISL3890_IMAGE_FILE);
891 break;
892 }
893
894 if (register_netdev(ndev)) {
895 DEBUG(SHOW_ERROR_MESSAGES,
896 "ERROR: register_netdev() failed\n");
897 goto do_islpci_free_memory;
898 }
899
900 return ndev;
901
902 do_islpci_free_memory:
903 islpci_free_memory(priv);
904 do_free_netdev:
905 free_netdev(ndev);
906 priv = NULL;
907 return NULL;
908}
909
910islpci_state_t
911islpci_set_state(islpci_private *priv, islpci_state_t new_state)
912{
913 islpci_state_t old_state;
914
915
916 old_state = priv->state;
917
918
919
920 switch (new_state) {
921 case PRV_STATE_OFF:
922 priv->state_off++;
923
924 default:
925 priv->state = new_state;
926 break;
927
928 case PRV_STATE_PREBOOT:
929
930
931 if (old_state == PRV_STATE_OFF)
932 priv->state_off--;
933
934
935
936
937 if (!priv->state_off)
938 priv->state = new_state;
939 break;
940 }
941#if 0
942 printk(KERN_DEBUG "%s: state transition %d -> %d (off#%d)\n",
943 priv->ndev->name, old_state, new_state, priv->state_off);
944#endif
945
946
947 BUG_ON(priv->state_off < 0);
948 BUG_ON(priv->state_off && (priv->state != PRV_STATE_OFF));
949 BUG_ON(!priv->state_off && (priv->state == PRV_STATE_OFF));
950
951
952 return old_state;
953}
954