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