2 * Copyright (C) 2002 Intersil Americas Inc.
3 * Copyright (C) 2003 Herbert Valerio Riedel <hvr@gnu.org>
4 * Copyright (C) 2003 Luis R. Rodriguez <mcgrof@ruslug.rutgers.edu>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <linux/hardirq.h>
22 #include <linux/module.h>
23 #include <linux/slab.h>
25 #include <linux/netdevice.h>
26 #include <linux/ethtool.h>
27 #include <linux/pci.h>
28 #include <linux/sched.h>
29 #include <linux/etherdevice.h>
30 #include <linux/delay.h>
31 #include <linux/if_arp.h>
35 #include "prismcompat.h"
37 #include "isl_ioctl.h"
38 #include "islpci_dev.h"
39 #include "islpci_mgt.h"
40 #include "islpci_eth.h"
43 #define ISL3877_IMAGE_FILE "/*(DEBLOBBED)*/"
44 #define ISL3886_IMAGE_FILE "/*(DEBLOBBED)*/"
45 #define ISL3890_IMAGE_FILE "/*(DEBLOBBED)*/"
48 static int prism54_bring_down(islpci_private *);
49 static int islpci_alloc_memory(islpci_private *);
51 /* Temporary dummy MAC address to use until firmware is loaded.
52 * The idea there is that some tools (such as nameif) may query
53 * the MAC address before the netdev is 'open'. By using a valid
54 * OUI prefix, they can process the netdev properly.
55 * Of course, this is not the final/real MAC address. It doesn't
56 * matter, as you are suppose to be able to change it anytime via
57 * ndev->set_mac_address. Jean II */
58 static const unsigned char dummy_mac[6] = { 0x00, 0x30, 0xB4, 0x00, 0x00, 0x00 };
61 isl_upload_firmware(islpci_private *priv)
64 void __iomem *device_base = priv->device_base;
66 /* clear the RAMBoot and the Reset bit */
67 reg = readl(device_base + ISL38XX_CTRL_STAT_REG);
68 reg &= ~ISL38XX_CTRL_STAT_RESET;
69 reg &= ~ISL38XX_CTRL_STAT_RAMBOOT;
70 writel(reg, device_base + ISL38XX_CTRL_STAT_REG);
72 udelay(ISL38XX_WRITEIO_DELAY);
74 /* set the Reset bit without reading the register ! */
75 reg |= ISL38XX_CTRL_STAT_RESET;
76 writel(reg, device_base + ISL38XX_CTRL_STAT_REG);
78 udelay(ISL38XX_WRITEIO_DELAY);
80 /* clear the Reset bit */
81 reg &= ~ISL38XX_CTRL_STAT_RESET;
82 writel(reg, device_base + ISL38XX_CTRL_STAT_REG);
85 /* wait a while for the device to reboot */
89 const struct firmware *fw_entry = NULL;
93 rc = reject_firmware(&fw_entry, priv->firmware, PRISM_FW_PDEV);
96 "%s: reject_firmware() failed for '%s'\n",
97 "prism54", priv->firmware);
100 /* prepare the Direct Memory Base register */
101 reg = ISL38XX_DEV_FIRMWARE_ADDRES;
103 fw_ptr = (u32 *) fw_entry->data;
104 fw_len = fw_entry->size;
108 "%s: firmware '%s' size is not multiple of 32bit, aborting!\n",
109 "prism54", priv->firmware);
110 release_firmware(fw_entry);
111 return -EILSEQ; /* Illegal byte sequence */;
117 ISL38XX_MEMORY_WINDOW_SIZE) ?
118 ISL38XX_MEMORY_WINDOW_SIZE : fw_len;
119 u32 __iomem *dev_fw_ptr = device_base + ISL38XX_DIRECT_MEM_WIN;
121 /* set the card's base address for writing the data */
122 isl38xx_w32_flush(device_base, reg,
123 ISL38XX_DIR_MEM_BASE_REG);
124 wmb(); /* be paranoid */
126 /* increment the write address for next iteration */
130 /* write the data to the Direct Memory Window 32bit-wise */
131 /* memcpy_toio() doesn't guarantee 32bit writes :-| */
132 while (_fw_len > 0) {
133 /* use non-swapping writel() */
134 __raw_writel(*fw_ptr, dev_fw_ptr);
135 fw_ptr++, dev_fw_ptr++;
139 /* flush PCI posting */
140 (void) readl(device_base + ISL38XX_PCI_POSTING_FLUSH);
141 wmb(); /* be paranoid again */
143 BUG_ON(_fw_len != 0);
148 /* Firmware version is at offset 40 (also for "newmac") */
149 printk(KERN_DEBUG "%s: firmware version: %.8s\n",
150 priv->ndev->name, fw_entry->data + 40);
152 release_firmware(fw_entry);
155 /* now reset the device
156 * clear the Reset & ClkRun bit, set the RAMBoot bit */
157 reg = readl(device_base + ISL38XX_CTRL_STAT_REG);
158 reg &= ~ISL38XX_CTRL_STAT_CLKRUN;
159 reg &= ~ISL38XX_CTRL_STAT_RESET;
160 reg |= ISL38XX_CTRL_STAT_RAMBOOT;
161 isl38xx_w32_flush(device_base, reg, ISL38XX_CTRL_STAT_REG);
163 udelay(ISL38XX_WRITEIO_DELAY);
165 /* set the reset bit latches the host override and RAMBoot bits
166 * into the device for operation when the reset bit is reset */
167 reg |= ISL38XX_CTRL_STAT_RESET;
168 writel(reg, device_base + ISL38XX_CTRL_STAT_REG);
169 /* don't do flush PCI posting here! */
171 udelay(ISL38XX_WRITEIO_DELAY);
173 /* clear the reset bit should start the whole circus */
174 reg &= ~ISL38XX_CTRL_STAT_RESET;
175 writel(reg, device_base + ISL38XX_CTRL_STAT_REG);
176 /* don't do flush PCI posting here! */
178 udelay(ISL38XX_WRITEIO_DELAY);
183 /******************************************************************************
184 Device Interrupt Handler
185 ******************************************************************************/
188 islpci_interrupt(int irq, void *config)
191 islpci_private *priv = config;
192 struct net_device *ndev = priv->ndev;
193 void __iomem *device = priv->device_base;
194 int powerstate = ISL38XX_PSM_POWERSAVE_STATE;
196 /* lock the interrupt handler */
197 spin_lock(&priv->slock);
199 /* received an interrupt request on a shared IRQ line
200 * first check whether the device is in sleep mode */
201 reg = readl(device + ISL38XX_CTRL_STAT_REG);
202 if (reg & ISL38XX_CTRL_STAT_SLEEPMODE)
203 /* device is in sleep mode, IRQ was generated by someone else */
205 #if VERBOSE > SHOW_ERROR_MESSAGES
206 DEBUG(SHOW_TRACING, "Assuming someone else called the IRQ\n");
208 spin_unlock(&priv->slock);
213 /* check whether there is any source of interrupt on the device */
214 reg = readl(device + ISL38XX_INT_IDENT_REG);
216 /* also check the contents of the Interrupt Enable Register, because this
217 * will filter out interrupt sources from other devices on the same irq ! */
218 reg &= readl(device + ISL38XX_INT_EN_REG);
219 reg &= ISL38XX_INT_SOURCES;
222 if (islpci_get_state(priv) != PRV_STATE_SLEEP)
223 powerstate = ISL38XX_PSM_ACTIVE_STATE;
225 /* reset the request bits in the Identification register */
226 isl38xx_w32_flush(device, reg, ISL38XX_INT_ACK_REG);
228 #if VERBOSE > SHOW_ERROR_MESSAGES
229 DEBUG(SHOW_FUNCTION_CALLS,
230 "IRQ: Identification register 0x%p 0x%x\n", device, reg);
233 /* check for each bit in the register separately */
234 if (reg & ISL38XX_INT_IDENT_UPDATE) {
235 #if VERBOSE > SHOW_ERROR_MESSAGES
236 /* Queue has been updated */
237 DEBUG(SHOW_TRACING, "IRQ: Update flag\n");
239 DEBUG(SHOW_QUEUE_INDEXES,
240 "CB drv Qs: [%i][%i][%i][%i][%i][%i]\n",
241 le32_to_cpu(priv->control_block->
242 driver_curr_frag[0]),
243 le32_to_cpu(priv->control_block->
244 driver_curr_frag[1]),
245 le32_to_cpu(priv->control_block->
246 driver_curr_frag[2]),
247 le32_to_cpu(priv->control_block->
248 driver_curr_frag[3]),
249 le32_to_cpu(priv->control_block->
250 driver_curr_frag[4]),
251 le32_to_cpu(priv->control_block->
255 DEBUG(SHOW_QUEUE_INDEXES,
256 "CB dev Qs: [%i][%i][%i][%i][%i][%i]\n",
257 le32_to_cpu(priv->control_block->
258 device_curr_frag[0]),
259 le32_to_cpu(priv->control_block->
260 device_curr_frag[1]),
261 le32_to_cpu(priv->control_block->
262 device_curr_frag[2]),
263 le32_to_cpu(priv->control_block->
264 device_curr_frag[3]),
265 le32_to_cpu(priv->control_block->
266 device_curr_frag[4]),
267 le32_to_cpu(priv->control_block->
272 /* cleanup the data low transmit queue */
273 islpci_eth_cleanup_transmit(priv, priv->control_block);
275 /* device is in active state, update the
276 * powerstate flag if necessary */
277 powerstate = ISL38XX_PSM_ACTIVE_STATE;
279 /* check all three queues in priority order
280 * call the PIMFOR receive function until the
282 if (isl38xx_in_queue(priv->control_block,
283 ISL38XX_CB_RX_MGMTQ) != 0) {
284 #if VERBOSE > SHOW_ERROR_MESSAGES
286 "Received frame in Management Queue\n");
288 islpci_mgt_receive(ndev);
290 islpci_mgt_cleanup_transmit(ndev);
292 /* Refill slots in receive queue */
293 islpci_mgmt_rx_fill(ndev);
295 /* no need to trigger the device, next
296 islpci_mgt_transaction does it */
299 while (isl38xx_in_queue(priv->control_block,
300 ISL38XX_CB_RX_DATA_LQ) != 0) {
301 #if VERBOSE > SHOW_ERROR_MESSAGES
303 "Received frame in Data Low Queue\n");
305 islpci_eth_receive(priv);
308 /* check whether the data transmit queues were full */
309 if (priv->data_low_tx_full) {
310 /* check whether the transmit is not full anymore */
311 if (ISL38XX_CB_TX_QSIZE -
312 isl38xx_in_queue(priv->control_block,
313 ISL38XX_CB_TX_DATA_LQ) >=
314 ISL38XX_MIN_QTHRESHOLD) {
315 /* nope, the driver is ready for more network frames */
316 netif_wake_queue(priv->ndev);
318 /* reset the full flag */
319 priv->data_low_tx_full = 0;
324 if (reg & ISL38XX_INT_IDENT_INIT) {
325 /* Device has been initialized */
326 #if VERBOSE > SHOW_ERROR_MESSAGES
328 "IRQ: Init flag, device initialized\n");
330 wake_up(&priv->reset_done);
333 if (reg & ISL38XX_INT_IDENT_SLEEP) {
334 /* Device intends to move to powersave state */
335 #if VERBOSE > SHOW_ERROR_MESSAGES
336 DEBUG(SHOW_TRACING, "IRQ: Sleep flag\n");
338 isl38xx_handle_sleep_request(priv->control_block,
343 if (reg & ISL38XX_INT_IDENT_WAKEUP) {
344 /* Device has been woken up to active state */
345 #if VERBOSE > SHOW_ERROR_MESSAGES
346 DEBUG(SHOW_TRACING, "IRQ: Wakeup flag\n");
349 isl38xx_handle_wakeup(priv->control_block,
350 &powerstate, priv->device_base);
353 #if VERBOSE > SHOW_ERROR_MESSAGES
354 DEBUG(SHOW_TRACING, "Assuming someone else called the IRQ\n");
356 spin_unlock(&priv->slock);
361 if (islpci_get_state(priv) == PRV_STATE_SLEEP
362 && powerstate == ISL38XX_PSM_ACTIVE_STATE)
363 islpci_set_state(priv, PRV_STATE_READY);
365 /* !sleep -> sleep */
366 if (islpci_get_state(priv) != PRV_STATE_SLEEP
367 && powerstate == ISL38XX_PSM_POWERSAVE_STATE)
368 islpci_set_state(priv, PRV_STATE_SLEEP);
370 /* unlock the interrupt handler */
371 spin_unlock(&priv->slock);
376 /******************************************************************************
377 Network Interface Control & Statistical functions
378 ******************************************************************************/
380 islpci_open(struct net_device *ndev)
383 islpci_private *priv = netdev_priv(ndev);
385 /* reset data structures, upload firmware and reset device */
386 rc = islpci_reset(priv,1);
388 prism54_bring_down(priv);
389 return rc; /* Returns informative message */
392 netif_start_queue(ndev);
394 /* Turn off carrier if in STA or Ad-hoc mode. It will be turned on
395 * once the firmware receives a trap of being associated
396 * (GEN_OID_LINKSTATE). In other modes (AP or WDS or monitor) we
397 * should just leave the carrier on as its expected the firmware
398 * won't send us a trigger. */
399 if (priv->iw_mode == IW_MODE_INFRA || priv->iw_mode == IW_MODE_ADHOC)
400 netif_carrier_off(ndev);
402 netif_carrier_on(ndev);
408 islpci_close(struct net_device *ndev)
410 islpci_private *priv = netdev_priv(ndev);
412 printk(KERN_DEBUG "%s: islpci_close ()\n", ndev->name);
414 netif_stop_queue(ndev);
416 return prism54_bring_down(priv);
420 prism54_bring_down(islpci_private *priv)
422 void __iomem *device_base = priv->device_base;
424 /* we are going to shutdown the device */
425 islpci_set_state(priv, PRV_STATE_PREBOOT);
427 /* disable all device interrupts in case they weren't */
428 isl38xx_disable_interrupts(priv->device_base);
430 /* For safety reasons, we may want to ensure that no DMA transfer is
431 * currently in progress by emptying the TX and RX queues. */
433 /* wait until interrupts have finished executing on other CPUs */
434 synchronize_irq(priv->pdev->irq);
436 reg = readl(device_base + ISL38XX_CTRL_STAT_REG);
437 reg &= ~(ISL38XX_CTRL_STAT_RESET | ISL38XX_CTRL_STAT_RAMBOOT);
438 writel(reg, device_base + ISL38XX_CTRL_STAT_REG);
440 udelay(ISL38XX_WRITEIO_DELAY);
442 reg |= ISL38XX_CTRL_STAT_RESET;
443 writel(reg, device_base + ISL38XX_CTRL_STAT_REG);
445 udelay(ISL38XX_WRITEIO_DELAY);
447 /* clear the Reset bit */
448 reg &= ~ISL38XX_CTRL_STAT_RESET;
449 writel(reg, device_base + ISL38XX_CTRL_STAT_REG);
452 /* wait a while for the device to reset */
453 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
459 islpci_upload_fw(islpci_private *priv)
461 islpci_state_t old_state;
464 old_state = islpci_set_state(priv, PRV_STATE_BOOT);
466 printk(KERN_DEBUG "%s: uploading firmware...\n", priv->ndev->name);
468 rc = isl_upload_firmware(priv);
470 /* error uploading the firmware */
471 printk(KERN_ERR "%s: could not upload firmware ('%s')\n",
472 priv->ndev->name, priv->firmware);
474 islpci_set_state(priv, old_state);
478 printk(KERN_DEBUG "%s: firmware upload complete\n",
481 islpci_set_state(priv, PRV_STATE_POSTBOOT);
487 islpci_reset_if(islpci_private *priv)
494 prepare_to_wait(&priv->reset_done, &wait, TASK_UNINTERRUPTIBLE);
496 /* now the last step is to reset the interface */
497 isl38xx_interface_reset(priv->device_base, priv->device_host_address);
498 islpci_set_state(priv, PRV_STATE_PREINIT);
500 for(count = 0; count < 2 && result; count++) {
501 /* The software reset acknowledge needs about 220 msec here.
502 * Be conservative and wait for up to one second. */
504 remaining = schedule_timeout_uninterruptible(HZ);
511 /* If we're here it's because our IRQ hasn't yet gone through.
512 * Retry a bit more...
514 printk(KERN_ERR "%s: no 'reset complete' IRQ seen - retrying\n",
518 finish_wait(&priv->reset_done, &wait);
521 printk(KERN_ERR "%s: interface reset failure\n", priv->ndev->name);
525 islpci_set_state(priv, PRV_STATE_INIT);
527 /* Now that the device is 100% up, let's allow
528 * for the other interrupts --
529 * NOTE: this is not *yet* true since we've only allowed the
530 * INIT interrupt on the IRQ line. We can perhaps poll
531 * the IRQ line until we know for sure the reset went through */
532 isl38xx_enable_common_interrupts(priv->device_base);
534 down_write(&priv->mib_sem);
535 result = mgt_commit(priv);
537 printk(KERN_ERR "%s: interface reset failure\n", priv->ndev->name);
538 up_write(&priv->mib_sem);
541 up_write(&priv->mib_sem);
543 islpci_set_state(priv, PRV_STATE_READY);
545 printk(KERN_DEBUG "%s: interface reset complete\n", priv->ndev->name);
550 islpci_reset(islpci_private *priv, int reload_firmware)
552 isl38xx_control_block *cb = /* volatile not needed */
553 (isl38xx_control_block *) priv->control_block;
558 islpci_set_state(priv, PRV_STATE_PREBOOT);
560 islpci_set_state(priv, PRV_STATE_POSTBOOT);
562 printk(KERN_DEBUG "%s: resetting device...\n", priv->ndev->name);
564 /* disable all device interrupts in case they weren't */
565 isl38xx_disable_interrupts(priv->device_base);
567 /* flush all management queues */
568 priv->index_mgmt_tx = 0;
569 priv->index_mgmt_rx = 0;
571 /* clear the indexes in the frame pointer */
572 for (counter = 0; counter < ISL38XX_CB_QCOUNT; counter++) {
573 cb->driver_curr_frag[counter] = cpu_to_le32(0);
574 cb->device_curr_frag[counter] = cpu_to_le32(0);
577 /* reset the mgmt receive queue */
578 for (counter = 0; counter < ISL38XX_CB_MGMT_QSIZE; counter++) {
579 isl38xx_fragment *frag = &cb->rx_data_mgmt[counter];
580 frag->size = cpu_to_le16(MGMT_FRAME_SIZE);
582 frag->address = cpu_to_le32(priv->mgmt_rx[counter].pci_addr);
585 for (counter = 0; counter < ISL38XX_CB_RX_QSIZE; counter++) {
586 cb->rx_data_low[counter].address =
587 cpu_to_le32((u32) priv->pci_map_rx_address[counter]);
590 /* since the receive queues are filled with empty fragments, now we can
591 * set the corresponding indexes in the Control Block */
592 priv->control_block->driver_curr_frag[ISL38XX_CB_RX_DATA_LQ] =
593 cpu_to_le32(ISL38XX_CB_RX_QSIZE);
594 priv->control_block->driver_curr_frag[ISL38XX_CB_RX_MGMTQ] =
595 cpu_to_le32(ISL38XX_CB_MGMT_QSIZE);
597 /* reset the remaining real index registers and full flags */
598 priv->free_data_rx = 0;
599 priv->free_data_tx = 0;
600 priv->data_low_tx_full = 0;
602 if (reload_firmware) { /* Should we load the firmware ? */
603 /* now that the data structures are cleaned up, upload
604 * firmware and reset interface */
605 rc = islpci_upload_fw(priv);
607 printk(KERN_ERR "%s: islpci_reset: failure\n",
613 /* finally reset interface */
614 rc = islpci_reset_if(priv);
616 printk(KERN_ERR "prism54: Your card/socket may be faulty, or IRQ line too busy :(\n");
620 /******************************************************************************
621 Network device configuration functions
622 ******************************************************************************/
624 islpci_alloc_memory(islpci_private *priv)
628 #if VERBOSE > SHOW_ERROR_MESSAGES
629 printk(KERN_DEBUG "islpci_alloc_memory\n");
632 /* remap the PCI device base address to accessible */
633 if (!(priv->device_base =
634 ioremap(pci_resource_start(priv->pdev, 0),
635 ISL38XX_PCI_MEM_SIZE))) {
636 /* error in remapping the PCI device memory address range */
637 printk(KERN_ERR "PCI memory remapping failed\n");
641 /* memory layout for consistent DMA region:
643 * Area 1: Control Block for the device interface
644 * Area 2: Power Save Mode Buffer for temporary frame storage. Be aware that
645 * the number of supported stations in the AP determines the minimal
646 * size of the buffer !
649 /* perform the allocation */
650 priv->driver_mem_address = pci_alloc_consistent(priv->pdev,
653 device_host_address);
655 if (!priv->driver_mem_address) {
656 /* error allocating the block of PCI memory */
657 printk(KERN_ERR "%s: could not allocate DMA memory, aborting!",
662 /* assign the Control Block to the first address of the allocated area */
663 priv->control_block =
664 (isl38xx_control_block *) priv->driver_mem_address;
666 /* set the Power Save Buffer pointer directly behind the CB */
667 priv->device_psm_buffer =
668 priv->device_host_address + CONTROL_BLOCK_SIZE;
670 /* make sure all buffer pointers are initialized */
671 for (counter = 0; counter < ISL38XX_CB_QCOUNT; counter++) {
672 priv->control_block->driver_curr_frag[counter] = cpu_to_le32(0);
673 priv->control_block->device_curr_frag[counter] = cpu_to_le32(0);
676 priv->index_mgmt_rx = 0;
677 memset(priv->mgmt_rx, 0, sizeof(priv->mgmt_rx));
678 memset(priv->mgmt_tx, 0, sizeof(priv->mgmt_tx));
680 /* allocate rx queue for management frames */
681 if (islpci_mgmt_rx_fill(priv->ndev) < 0)
684 /* now get the data rx skb's */
685 memset(priv->data_low_rx, 0, sizeof (priv->data_low_rx));
686 memset(priv->pci_map_rx_address, 0, sizeof (priv->pci_map_rx_address));
688 for (counter = 0; counter < ISL38XX_CB_RX_QSIZE; counter++) {
691 /* allocate an sk_buff for received data frames storage
692 * each frame on receive size consists of 1 fragment
693 * include any required allignment operations */
694 if (!(skb = dev_alloc_skb(MAX_FRAGMENT_SIZE_RX + 2))) {
695 /* error allocating an sk_buff structure elements */
696 printk(KERN_ERR "Error allocating skb.\n");
700 skb_reserve(skb, (4 - (long) skb->data) & 0x03);
701 /* add the new allocated sk_buff to the buffer array */
702 priv->data_low_rx[counter] = skb;
704 /* map the allocated skb data area to pci */
705 priv->pci_map_rx_address[counter] =
706 pci_map_single(priv->pdev, (void *) skb->data,
707 MAX_FRAGMENT_SIZE_RX + 2,
709 if (!priv->pci_map_rx_address[counter]) {
710 /* error mapping the buffer to device
711 accessible memory address */
712 printk(KERN_ERR "failed to map skb DMA'able\n");
717 prism54_acl_init(&priv->acl);
718 prism54_wpa_bss_ie_init(priv);
724 islpci_free_memory(priv);
729 islpci_free_memory(islpci_private *priv)
733 if (priv->device_base)
734 iounmap(priv->device_base);
735 priv->device_base = NULL;
737 /* free consistent DMA area... */
738 if (priv->driver_mem_address)
739 pci_free_consistent(priv->pdev, HOST_MEM_BLOCK,
740 priv->driver_mem_address,
741 priv->device_host_address);
743 /* clear some dangling pointers */
744 priv->driver_mem_address = NULL;
745 priv->device_host_address = 0;
746 priv->device_psm_buffer = 0;
747 priv->control_block = NULL;
749 /* clean up mgmt rx buffers */
750 for (counter = 0; counter < ISL38XX_CB_MGMT_QSIZE; counter++) {
751 struct islpci_membuf *buf = &priv->mgmt_rx[counter];
753 pci_unmap_single(priv->pdev, buf->pci_addr,
754 buf->size, PCI_DMA_FROMDEVICE);
761 /* clean up data rx buffers */
762 for (counter = 0; counter < ISL38XX_CB_RX_QSIZE; counter++) {
763 if (priv->pci_map_rx_address[counter])
764 pci_unmap_single(priv->pdev,
765 priv->pci_map_rx_address[counter],
766 MAX_FRAGMENT_SIZE_RX + 2,
768 priv->pci_map_rx_address[counter] = 0;
770 if (priv->data_low_rx[counter])
771 dev_kfree_skb(priv->data_low_rx[counter]);
772 priv->data_low_rx[counter] = NULL;
775 /* Free the access control list and the WPA list */
776 prism54_acl_clean(&priv->acl);
777 prism54_wpa_bss_ie_clean(priv);
785 islpci_set_multicast_list(struct net_device *dev)
787 /* put device into promisc mode and let network layer handle it */
791 static void islpci_ethtool_get_drvinfo(struct net_device *dev,
792 struct ethtool_drvinfo *info)
794 strcpy(info->driver, DRV_NAME);
795 strcpy(info->version, DRV_VERSION);
798 static const struct ethtool_ops islpci_ethtool_ops = {
799 .get_drvinfo = islpci_ethtool_get_drvinfo,
802 static const struct net_device_ops islpci_netdev_ops = {
803 .ndo_open = islpci_open,
804 .ndo_stop = islpci_close,
805 .ndo_do_ioctl = prism54_ioctl,
806 .ndo_start_xmit = islpci_eth_transmit,
807 .ndo_tx_timeout = islpci_eth_tx_timeout,
808 .ndo_set_mac_address = prism54_set_mac_address,
809 .ndo_change_mtu = eth_change_mtu,
810 .ndo_validate_addr = eth_validate_addr,
813 static struct device_type wlan_type = {
818 islpci_setup(struct pci_dev *pdev)
820 islpci_private *priv;
821 struct net_device *ndev = alloc_etherdev(sizeof (islpci_private));
826 pci_set_drvdata(pdev, ndev);
827 SET_NETDEV_DEV(ndev, &pdev->dev);
828 SET_NETDEV_DEVTYPE(ndev, &wlan_type);
830 /* setup the structure members */
831 ndev->base_addr = pci_resource_start(pdev, 0);
832 ndev->irq = pdev->irq;
834 /* initialize the function pointers */
835 ndev->netdev_ops = &islpci_netdev_ops;
836 ndev->wireless_handlers = &prism54_handler_def;
837 ndev->ethtool_ops = &islpci_ethtool_ops;
839 /* ndev->set_multicast_list = &islpci_set_multicast_list; */
840 ndev->addr_len = ETH_ALEN;
841 /* Get a non-zero dummy MAC address for nameif. Jean II */
842 memcpy(ndev->dev_addr, dummy_mac, 6);
844 ndev->watchdog_timeo = ISLPCI_TX_TIMEOUT;
846 /* allocate a private device structure to the network device */
847 priv = netdev_priv(ndev);
850 priv->monitor_type = ARPHRD_IEEE80211;
851 priv->ndev->type = (priv->iw_mode == IW_MODE_MONITOR) ?
852 priv->monitor_type : ARPHRD_ETHER;
854 /* Add pointers to enable iwspy support. */
855 priv->wireless_data.spy_data = &priv->spy_data;
856 ndev->wireless_data = &priv->wireless_data;
858 /* save the start and end address of the PCI memory area */
859 ndev->mem_start = (unsigned long) priv->device_base;
860 ndev->mem_end = ndev->mem_start + ISL38XX_PCI_MEM_SIZE;
862 #if VERBOSE > SHOW_ERROR_MESSAGES
863 DEBUG(SHOW_TRACING, "PCI Memory remapped to 0x%p\n", priv->device_base);
866 init_waitqueue_head(&priv->reset_done);
868 /* init the queue read locks, process wait counter */
869 mutex_init(&priv->mgmt_lock);
870 priv->mgmt_received = NULL;
871 init_waitqueue_head(&priv->mgmt_wqueue);
872 mutex_init(&priv->stats_lock);
873 spin_lock_init(&priv->slock);
875 /* init state machine with off#1 state */
876 priv->state = PRV_STATE_OFF;
879 /* initialize workqueue's */
880 INIT_WORK(&priv->stats_work, prism54_update_stats);
881 priv->stats_timestamp = 0;
883 INIT_WORK(&priv->reset_task, islpci_do_reset_and_wake);
884 priv->reset_task_pending = 0;
886 /* allocate various memory areas */
887 if (islpci_alloc_memory(priv))
890 /* select the firmware file depending on the device id */
891 switch (pdev->device) {
893 strcpy(priv->firmware, ISL3877_IMAGE_FILE);
897 strcpy(priv->firmware, ISL3886_IMAGE_FILE);
901 strcpy(priv->firmware, ISL3890_IMAGE_FILE);
905 if (register_netdev(ndev)) {
906 DEBUG(SHOW_ERROR_MESSAGES,
907 "ERROR: register_netdev() failed\n");
908 goto do_islpci_free_memory;
913 do_islpci_free_memory:
914 islpci_free_memory(priv);
916 pci_set_drvdata(pdev, NULL);
923 islpci_set_state(islpci_private *priv, islpci_state_t new_state)
925 islpci_state_t old_state;
928 old_state = priv->state;
930 /* this means either a race condition or some serious error in
936 priv->state = new_state;
939 case PRV_STATE_PREBOOT:
940 /* there are actually many off-states, enumerated by
942 if (old_state == PRV_STATE_OFF)
945 /* only if hw_unavailable is zero now it means we either
946 * were in off#1 state, or came here from
948 if (!priv->state_off)
949 priv->state = new_state;
953 printk(KERN_DEBUG "%s: state transition %d -> %d (off#%d)\n",
954 priv->ndev->name, old_state, new_state, priv->state_off);
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));