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, see <http://www.gnu.org/licenses/>.
20 #include <linux/hardirq.h>
21 #include <linux/module.h>
22 #include <linux/slab.h>
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>
34 #include "prismcompat.h"
36 #include "isl_ioctl.h"
37 #include "islpci_dev.h"
38 #include "islpci_mgt.h"
39 #include "islpci_eth.h"
42 #define ISL3877_IMAGE_FILE "/*(DEBLOBBED)*/"
43 #define ISL3886_IMAGE_FILE "/*(DEBLOBBED)*/"
44 #define ISL3890_IMAGE_FILE "/*(DEBLOBBED)*/"
47 static int prism54_bring_down(islpci_private *);
48 static int islpci_alloc_memory(islpci_private *);
50 /* Temporary dummy MAC address to use until firmware is loaded.
51 * The idea there is that some tools (such as nameif) may query
52 * the MAC address before the netdev is 'open'. By using a valid
53 * OUI prefix, they can process the netdev properly.
54 * Of course, this is not the final/real MAC address. It doesn't
55 * matter, as you are suppose to be able to change it anytime via
56 * ndev->set_mac_address. Jean II */
57 static const unsigned char dummy_mac[6] = { 0x00, 0x30, 0xB4, 0x00, 0x00, 0x00 };
60 isl_upload_firmware(islpci_private *priv)
63 void __iomem *device_base = priv->device_base;
65 /* clear the RAMBoot and the Reset bit */
66 reg = readl(device_base + ISL38XX_CTRL_STAT_REG);
67 reg &= ~ISL38XX_CTRL_STAT_RESET;
68 reg &= ~ISL38XX_CTRL_STAT_RAMBOOT;
69 writel(reg, device_base + ISL38XX_CTRL_STAT_REG);
71 udelay(ISL38XX_WRITEIO_DELAY);
73 /* set the Reset bit without reading the register ! */
74 reg |= ISL38XX_CTRL_STAT_RESET;
75 writel(reg, device_base + ISL38XX_CTRL_STAT_REG);
77 udelay(ISL38XX_WRITEIO_DELAY);
79 /* clear the Reset bit */
80 reg &= ~ISL38XX_CTRL_STAT_RESET;
81 writel(reg, device_base + ISL38XX_CTRL_STAT_REG);
84 /* wait a while for the device to reboot */
88 const struct firmware *fw_entry = NULL;
92 rc = reject_firmware(&fw_entry, priv->firmware, PRISM_FW_PDEV);
95 "%s: reject_firmware() failed for '%s'\n",
96 "prism54", priv->firmware);
99 /* prepare the Direct Memory Base register */
100 reg = ISL38XX_DEV_FIRMWARE_ADDRES;
102 fw_ptr = (u32 *) fw_entry->data;
103 fw_len = fw_entry->size;
107 "%s: firmware '%s' size is not multiple of 32bit, aborting!\n",
108 "prism54", priv->firmware);
109 release_firmware(fw_entry);
110 return -EILSEQ; /* Illegal byte sequence */;
116 ISL38XX_MEMORY_WINDOW_SIZE) ?
117 ISL38XX_MEMORY_WINDOW_SIZE : fw_len;
118 u32 __iomem *dev_fw_ptr = device_base + ISL38XX_DIRECT_MEM_WIN;
120 /* set the card's base address for writing the data */
121 isl38xx_w32_flush(device_base, reg,
122 ISL38XX_DIR_MEM_BASE_REG);
123 wmb(); /* be paranoid */
125 /* increment the write address for next iteration */
129 /* write the data to the Direct Memory Window 32bit-wise */
130 /* memcpy_toio() doesn't guarantee 32bit writes :-| */
131 while (_fw_len > 0) {
132 /* use non-swapping writel() */
133 __raw_writel(*fw_ptr, dev_fw_ptr);
134 fw_ptr++, dev_fw_ptr++;
138 /* flush PCI posting */
139 (void) readl(device_base + ISL38XX_PCI_POSTING_FLUSH);
140 wmb(); /* be paranoid again */
142 BUG_ON(_fw_len != 0);
147 /* Firmware version is at offset 40 (also for "newmac") */
148 printk(KERN_DEBUG "%s: firmware version: %.8s\n",
149 priv->ndev->name, fw_entry->data + 40);
151 release_firmware(fw_entry);
154 /* now reset the device
155 * clear the Reset & ClkRun bit, set the RAMBoot bit */
156 reg = readl(device_base + ISL38XX_CTRL_STAT_REG);
157 reg &= ~ISL38XX_CTRL_STAT_CLKRUN;
158 reg &= ~ISL38XX_CTRL_STAT_RESET;
159 reg |= ISL38XX_CTRL_STAT_RAMBOOT;
160 isl38xx_w32_flush(device_base, reg, ISL38XX_CTRL_STAT_REG);
162 udelay(ISL38XX_WRITEIO_DELAY);
164 /* set the reset bit latches the host override and RAMBoot bits
165 * into the device for operation when the reset bit is reset */
166 reg |= ISL38XX_CTRL_STAT_RESET;
167 writel(reg, device_base + ISL38XX_CTRL_STAT_REG);
168 /* don't do flush PCI posting here! */
170 udelay(ISL38XX_WRITEIO_DELAY);
172 /* clear the reset bit should start the whole circus */
173 reg &= ~ISL38XX_CTRL_STAT_RESET;
174 writel(reg, device_base + ISL38XX_CTRL_STAT_REG);
175 /* don't do flush PCI posting here! */
177 udelay(ISL38XX_WRITEIO_DELAY);
182 /******************************************************************************
183 Device Interrupt Handler
184 ******************************************************************************/
187 islpci_interrupt(int irq, void *config)
190 islpci_private *priv = config;
191 struct net_device *ndev = priv->ndev;
192 void __iomem *device = priv->device_base;
193 int powerstate = ISL38XX_PSM_POWERSAVE_STATE;
195 /* lock the interrupt handler */
196 spin_lock(&priv->slock);
198 /* received an interrupt request on a shared IRQ line
199 * first check whether the device is in sleep mode */
200 reg = readl(device + ISL38XX_CTRL_STAT_REG);
201 if (reg & ISL38XX_CTRL_STAT_SLEEPMODE)
202 /* device is in sleep mode, IRQ was generated by someone else */
204 #if VERBOSE > SHOW_ERROR_MESSAGES
205 DEBUG(SHOW_TRACING, "Assuming someone else called the IRQ\n");
207 spin_unlock(&priv->slock);
212 /* check whether there is any source of interrupt on the device */
213 reg = readl(device + ISL38XX_INT_IDENT_REG);
215 /* also check the contents of the Interrupt Enable Register, because this
216 * will filter out interrupt sources from other devices on the same irq ! */
217 reg &= readl(device + ISL38XX_INT_EN_REG);
218 reg &= ISL38XX_INT_SOURCES;
221 if (islpci_get_state(priv) != PRV_STATE_SLEEP)
222 powerstate = ISL38XX_PSM_ACTIVE_STATE;
224 /* reset the request bits in the Identification register */
225 isl38xx_w32_flush(device, reg, ISL38XX_INT_ACK_REG);
227 #if VERBOSE > SHOW_ERROR_MESSAGES
228 DEBUG(SHOW_FUNCTION_CALLS,
229 "IRQ: Identification register 0x%p 0x%x\n", device, reg);
232 /* check for each bit in the register separately */
233 if (reg & ISL38XX_INT_IDENT_UPDATE) {
234 #if VERBOSE > SHOW_ERROR_MESSAGES
235 /* Queue has been updated */
236 DEBUG(SHOW_TRACING, "IRQ: Update flag\n");
238 DEBUG(SHOW_QUEUE_INDEXES,
239 "CB drv Qs: [%i][%i][%i][%i][%i][%i]\n",
240 le32_to_cpu(priv->control_block->
241 driver_curr_frag[0]),
242 le32_to_cpu(priv->control_block->
243 driver_curr_frag[1]),
244 le32_to_cpu(priv->control_block->
245 driver_curr_frag[2]),
246 le32_to_cpu(priv->control_block->
247 driver_curr_frag[3]),
248 le32_to_cpu(priv->control_block->
249 driver_curr_frag[4]),
250 le32_to_cpu(priv->control_block->
254 DEBUG(SHOW_QUEUE_INDEXES,
255 "CB dev Qs: [%i][%i][%i][%i][%i][%i]\n",
256 le32_to_cpu(priv->control_block->
257 device_curr_frag[0]),
258 le32_to_cpu(priv->control_block->
259 device_curr_frag[1]),
260 le32_to_cpu(priv->control_block->
261 device_curr_frag[2]),
262 le32_to_cpu(priv->control_block->
263 device_curr_frag[3]),
264 le32_to_cpu(priv->control_block->
265 device_curr_frag[4]),
266 le32_to_cpu(priv->control_block->
271 /* cleanup the data low transmit queue */
272 islpci_eth_cleanup_transmit(priv, priv->control_block);
274 /* device is in active state, update the
275 * powerstate flag if necessary */
276 powerstate = ISL38XX_PSM_ACTIVE_STATE;
278 /* check all three queues in priority order
279 * call the PIMFOR receive function until the
281 if (isl38xx_in_queue(priv->control_block,
282 ISL38XX_CB_RX_MGMTQ) != 0) {
283 #if VERBOSE > SHOW_ERROR_MESSAGES
285 "Received frame in Management Queue\n");
287 islpci_mgt_receive(ndev);
289 islpci_mgt_cleanup_transmit(ndev);
291 /* Refill slots in receive queue */
292 islpci_mgmt_rx_fill(ndev);
294 /* no need to trigger the device, next
295 islpci_mgt_transaction does it */
298 while (isl38xx_in_queue(priv->control_block,
299 ISL38XX_CB_RX_DATA_LQ) != 0) {
300 #if VERBOSE > SHOW_ERROR_MESSAGES
302 "Received frame in Data Low Queue\n");
304 islpci_eth_receive(priv);
307 /* check whether the data transmit queues were full */
308 if (priv->data_low_tx_full) {
309 /* check whether the transmit is not full anymore */
310 if (ISL38XX_CB_TX_QSIZE -
311 isl38xx_in_queue(priv->control_block,
312 ISL38XX_CB_TX_DATA_LQ) >=
313 ISL38XX_MIN_QTHRESHOLD) {
314 /* nope, the driver is ready for more network frames */
315 netif_wake_queue(priv->ndev);
317 /* reset the full flag */
318 priv->data_low_tx_full = 0;
323 if (reg & ISL38XX_INT_IDENT_INIT) {
324 /* Device has been initialized */
325 #if VERBOSE > SHOW_ERROR_MESSAGES
327 "IRQ: Init flag, device initialized\n");
329 wake_up(&priv->reset_done);
332 if (reg & ISL38XX_INT_IDENT_SLEEP) {
333 /* Device intends to move to powersave state */
334 #if VERBOSE > SHOW_ERROR_MESSAGES
335 DEBUG(SHOW_TRACING, "IRQ: Sleep flag\n");
337 isl38xx_handle_sleep_request(priv->control_block,
342 if (reg & ISL38XX_INT_IDENT_WAKEUP) {
343 /* Device has been woken up to active state */
344 #if VERBOSE > SHOW_ERROR_MESSAGES
345 DEBUG(SHOW_TRACING, "IRQ: Wakeup flag\n");
348 isl38xx_handle_wakeup(priv->control_block,
349 &powerstate, priv->device_base);
352 #if VERBOSE > SHOW_ERROR_MESSAGES
353 DEBUG(SHOW_TRACING, "Assuming someone else called the IRQ\n");
355 spin_unlock(&priv->slock);
360 if (islpci_get_state(priv) == PRV_STATE_SLEEP
361 && powerstate == ISL38XX_PSM_ACTIVE_STATE)
362 islpci_set_state(priv, PRV_STATE_READY);
364 /* !sleep -> sleep */
365 if (islpci_get_state(priv) != PRV_STATE_SLEEP
366 && powerstate == ISL38XX_PSM_POWERSAVE_STATE)
367 islpci_set_state(priv, PRV_STATE_SLEEP);
369 /* unlock the interrupt handler */
370 spin_unlock(&priv->slock);
375 /******************************************************************************
376 Network Interface Control & Statistical functions
377 ******************************************************************************/
379 islpci_open(struct net_device *ndev)
382 islpci_private *priv = netdev_priv(ndev);
384 /* reset data structures, upload firmware and reset device */
385 rc = islpci_reset(priv,1);
387 prism54_bring_down(priv);
388 return rc; /* Returns informative message */
391 netif_start_queue(ndev);
393 /* Turn off carrier if in STA or Ad-hoc mode. It will be turned on
394 * once the firmware receives a trap of being associated
395 * (GEN_OID_LINKSTATE). In other modes (AP or WDS or monitor) we
396 * should just leave the carrier on as its expected the firmware
397 * won't send us a trigger. */
398 if (priv->iw_mode == IW_MODE_INFRA || priv->iw_mode == IW_MODE_ADHOC)
399 netif_carrier_off(ndev);
401 netif_carrier_on(ndev);
407 islpci_close(struct net_device *ndev)
409 islpci_private *priv = netdev_priv(ndev);
411 printk(KERN_DEBUG "%s: islpci_close ()\n", ndev->name);
413 netif_stop_queue(ndev);
415 return prism54_bring_down(priv);
419 prism54_bring_down(islpci_private *priv)
421 void __iomem *device_base = priv->device_base;
423 /* we are going to shutdown the device */
424 islpci_set_state(priv, PRV_STATE_PREBOOT);
426 /* disable all device interrupts in case they weren't */
427 isl38xx_disable_interrupts(priv->device_base);
429 /* For safety reasons, we may want to ensure that no DMA transfer is
430 * currently in progress by emptying the TX and RX queues. */
432 /* wait until interrupts have finished executing on other CPUs */
433 synchronize_irq(priv->pdev->irq);
435 reg = readl(device_base + ISL38XX_CTRL_STAT_REG);
436 reg &= ~(ISL38XX_CTRL_STAT_RESET | ISL38XX_CTRL_STAT_RAMBOOT);
437 writel(reg, device_base + ISL38XX_CTRL_STAT_REG);
439 udelay(ISL38XX_WRITEIO_DELAY);
441 reg |= ISL38XX_CTRL_STAT_RESET;
442 writel(reg, device_base + ISL38XX_CTRL_STAT_REG);
444 udelay(ISL38XX_WRITEIO_DELAY);
446 /* clear the Reset bit */
447 reg &= ~ISL38XX_CTRL_STAT_RESET;
448 writel(reg, device_base + ISL38XX_CTRL_STAT_REG);
451 /* wait a while for the device to reset */
452 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
458 islpci_upload_fw(islpci_private *priv)
460 islpci_state_t old_state;
463 old_state = islpci_set_state(priv, PRV_STATE_BOOT);
465 printk(KERN_DEBUG "%s: uploading firmware...\n", priv->ndev->name);
467 rc = isl_upload_firmware(priv);
469 /* error uploading the firmware */
470 printk(KERN_ERR "%s: could not upload firmware ('%s')\n",
471 priv->ndev->name, priv->firmware);
473 islpci_set_state(priv, old_state);
477 printk(KERN_DEBUG "%s: firmware upload complete\n",
480 islpci_set_state(priv, PRV_STATE_POSTBOOT);
486 islpci_reset_if(islpci_private *priv)
493 prepare_to_wait(&priv->reset_done, &wait, TASK_UNINTERRUPTIBLE);
495 /* now the last step is to reset the interface */
496 isl38xx_interface_reset(priv->device_base, priv->device_host_address);
497 islpci_set_state(priv, PRV_STATE_PREINIT);
499 for(count = 0; count < 2 && result; count++) {
500 /* The software reset acknowledge needs about 220 msec here.
501 * Be conservative and wait for up to one second. */
503 remaining = schedule_timeout_uninterruptible(HZ);
510 /* If we're here it's because our IRQ hasn't yet gone through.
511 * Retry a bit more...
513 printk(KERN_ERR "%s: no 'reset complete' IRQ seen - retrying\n",
517 finish_wait(&priv->reset_done, &wait);
520 printk(KERN_ERR "%s: interface reset failure\n", priv->ndev->name);
524 islpci_set_state(priv, PRV_STATE_INIT);
526 /* Now that the device is 100% up, let's allow
527 * for the other interrupts --
528 * NOTE: this is not *yet* true since we've only allowed the
529 * INIT interrupt on the IRQ line. We can perhaps poll
530 * the IRQ line until we know for sure the reset went through */
531 isl38xx_enable_common_interrupts(priv->device_base);
533 down_write(&priv->mib_sem);
534 result = mgt_commit(priv);
536 printk(KERN_ERR "%s: interface reset failure\n", priv->ndev->name);
537 up_write(&priv->mib_sem);
540 up_write(&priv->mib_sem);
542 islpci_set_state(priv, PRV_STATE_READY);
544 printk(KERN_DEBUG "%s: interface reset complete\n", priv->ndev->name);
549 islpci_reset(islpci_private *priv, int reload_firmware)
551 isl38xx_control_block *cb = /* volatile not needed */
552 (isl38xx_control_block *) priv->control_block;
557 islpci_set_state(priv, PRV_STATE_PREBOOT);
559 islpci_set_state(priv, PRV_STATE_POSTBOOT);
561 printk(KERN_DEBUG "%s: resetting device...\n", priv->ndev->name);
563 /* disable all device interrupts in case they weren't */
564 isl38xx_disable_interrupts(priv->device_base);
566 /* flush all management queues */
567 priv->index_mgmt_tx = 0;
568 priv->index_mgmt_rx = 0;
570 /* clear the indexes in the frame pointer */
571 for (counter = 0; counter < ISL38XX_CB_QCOUNT; counter++) {
572 cb->driver_curr_frag[counter] = cpu_to_le32(0);
573 cb->device_curr_frag[counter] = cpu_to_le32(0);
576 /* reset the mgmt receive queue */
577 for (counter = 0; counter < ISL38XX_CB_MGMT_QSIZE; counter++) {
578 isl38xx_fragment *frag = &cb->rx_data_mgmt[counter];
579 frag->size = cpu_to_le16(MGMT_FRAME_SIZE);
581 frag->address = cpu_to_le32(priv->mgmt_rx[counter].pci_addr);
584 for (counter = 0; counter < ISL38XX_CB_RX_QSIZE; counter++) {
585 cb->rx_data_low[counter].address =
586 cpu_to_le32((u32) priv->pci_map_rx_address[counter]);
589 /* since the receive queues are filled with empty fragments, now we can
590 * set the corresponding indexes in the Control Block */
591 priv->control_block->driver_curr_frag[ISL38XX_CB_RX_DATA_LQ] =
592 cpu_to_le32(ISL38XX_CB_RX_QSIZE);
593 priv->control_block->driver_curr_frag[ISL38XX_CB_RX_MGMTQ] =
594 cpu_to_le32(ISL38XX_CB_MGMT_QSIZE);
596 /* reset the remaining real index registers and full flags */
597 priv->free_data_rx = 0;
598 priv->free_data_tx = 0;
599 priv->data_low_tx_full = 0;
601 if (reload_firmware) { /* Should we load the firmware ? */
602 /* now that the data structures are cleaned up, upload
603 * firmware and reset interface */
604 rc = islpci_upload_fw(priv);
606 printk(KERN_ERR "%s: islpci_reset: failure\n",
612 /* finally reset interface */
613 rc = islpci_reset_if(priv);
615 printk(KERN_ERR "prism54: Your card/socket may be faulty, or IRQ line too busy :(\n");
619 /******************************************************************************
620 Network device configuration functions
621 ******************************************************************************/
623 islpci_alloc_memory(islpci_private *priv)
627 #if VERBOSE > SHOW_ERROR_MESSAGES
628 printk(KERN_DEBUG "islpci_alloc_memory\n");
631 /* remap the PCI device base address to accessible */
632 if (!(priv->device_base =
633 ioremap(pci_resource_start(priv->pdev, 0),
634 ISL38XX_PCI_MEM_SIZE))) {
635 /* error in remapping the PCI device memory address range */
636 printk(KERN_ERR "PCI memory remapping failed\n");
640 /* memory layout for consistent DMA region:
642 * Area 1: Control Block for the device interface
643 * Area 2: Power Save Mode Buffer for temporary frame storage. Be aware that
644 * the number of supported stations in the AP determines the minimal
645 * size of the buffer !
648 /* perform the allocation */
649 priv->driver_mem_address = pci_alloc_consistent(priv->pdev,
652 device_host_address);
654 if (!priv->driver_mem_address) {
655 /* error allocating the block of PCI memory */
656 printk(KERN_ERR "%s: could not allocate DMA memory, aborting!",
661 /* assign the Control Block to the first address of the allocated area */
662 priv->control_block =
663 (isl38xx_control_block *) priv->driver_mem_address;
665 /* set the Power Save Buffer pointer directly behind the CB */
666 priv->device_psm_buffer =
667 priv->device_host_address + CONTROL_BLOCK_SIZE;
669 /* make sure all buffer pointers are initialized */
670 for (counter = 0; counter < ISL38XX_CB_QCOUNT; counter++) {
671 priv->control_block->driver_curr_frag[counter] = cpu_to_le32(0);
672 priv->control_block->device_curr_frag[counter] = cpu_to_le32(0);
675 priv->index_mgmt_rx = 0;
676 memset(priv->mgmt_rx, 0, sizeof(priv->mgmt_rx));
677 memset(priv->mgmt_tx, 0, sizeof(priv->mgmt_tx));
679 /* allocate rx queue for management frames */
680 if (islpci_mgmt_rx_fill(priv->ndev) < 0)
683 /* now get the data rx skb's */
684 memset(priv->data_low_rx, 0, sizeof (priv->data_low_rx));
685 memset(priv->pci_map_rx_address, 0, sizeof (priv->pci_map_rx_address));
687 for (counter = 0; counter < ISL38XX_CB_RX_QSIZE; counter++) {
690 /* allocate an sk_buff for received data frames storage
691 * each frame on receive size consists of 1 fragment
692 * include any required allignment operations */
693 if (!(skb = dev_alloc_skb(MAX_FRAGMENT_SIZE_RX + 2))) {
694 /* error allocating an sk_buff structure elements */
695 printk(KERN_ERR "Error allocating skb.\n");
699 skb_reserve(skb, (4 - (long) skb->data) & 0x03);
700 /* add the new allocated sk_buff to the buffer array */
701 priv->data_low_rx[counter] = skb;
703 /* map the allocated skb data area to pci */
704 priv->pci_map_rx_address[counter] =
705 pci_map_single(priv->pdev, (void *) skb->data,
706 MAX_FRAGMENT_SIZE_RX + 2,
708 if (pci_dma_mapping_error(priv->pdev,
709 priv->pci_map_rx_address[counter])) {
710 priv->pci_map_rx_address[counter] = 0;
711 /* error mapping the buffer to device
712 accessible memory address */
713 printk(KERN_ERR "failed to map skb DMA'able\n");
718 prism54_acl_init(&priv->acl);
719 prism54_wpa_bss_ie_init(priv);
725 islpci_free_memory(priv);
730 islpci_free_memory(islpci_private *priv)
734 if (priv->device_base)
735 iounmap(priv->device_base);
736 priv->device_base = NULL;
738 /* free consistent DMA area... */
739 if (priv->driver_mem_address)
740 pci_free_consistent(priv->pdev, HOST_MEM_BLOCK,
741 priv->driver_mem_address,
742 priv->device_host_address);
744 /* clear some dangling pointers */
745 priv->driver_mem_address = NULL;
746 priv->device_host_address = 0;
747 priv->device_psm_buffer = 0;
748 priv->control_block = NULL;
750 /* clean up mgmt rx buffers */
751 for (counter = 0; counter < ISL38XX_CB_MGMT_QSIZE; counter++) {
752 struct islpci_membuf *buf = &priv->mgmt_rx[counter];
754 pci_unmap_single(priv->pdev, buf->pci_addr,
755 buf->size, PCI_DMA_FROMDEVICE);
762 /* clean up data rx buffers */
763 for (counter = 0; counter < ISL38XX_CB_RX_QSIZE; counter++) {
764 if (priv->pci_map_rx_address[counter])
765 pci_unmap_single(priv->pdev,
766 priv->pci_map_rx_address[counter],
767 MAX_FRAGMENT_SIZE_RX + 2,
769 priv->pci_map_rx_address[counter] = 0;
771 if (priv->data_low_rx[counter])
772 dev_kfree_skb(priv->data_low_rx[counter]);
773 priv->data_low_rx[counter] = NULL;
776 /* Free the access control list and the WPA list */
777 prism54_acl_clean(&priv->acl);
778 prism54_wpa_bss_ie_clean(priv);
786 islpci_set_multicast_list(struct net_device *dev)
788 /* put device into promisc mode and let network layer handle it */
792 static void islpci_ethtool_get_drvinfo(struct net_device *dev,
793 struct ethtool_drvinfo *info)
795 strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
796 strlcpy(info->version, DRV_VERSION, sizeof(info->version));
799 static const struct ethtool_ops islpci_ethtool_ops = {
800 .get_drvinfo = islpci_ethtool_get_drvinfo,
803 static const struct net_device_ops islpci_netdev_ops = {
804 .ndo_open = islpci_open,
805 .ndo_stop = islpci_close,
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, ETH_ALEN);
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);
922 islpci_set_state(islpci_private *priv, islpci_state_t new_state)
924 islpci_state_t old_state;
927 old_state = priv->state;
929 /* this means either a race condition or some serious error in
935 priv->state = new_state;
938 case PRV_STATE_PREBOOT:
939 /* there are actually many off-states, enumerated by
941 if (old_state == PRV_STATE_OFF)
944 /* only if hw_unavailable is zero now it means we either
945 * were in off#1 state, or came here from
947 if (!priv->state_off)
948 priv->state = new_state;
952 printk(KERN_DEBUG "%s: state transition %d -> %d (off#%d)\n",
953 priv->ndev->name, old_state, new_state, priv->state_off);
957 BUG_ON(priv->state_off < 0);
958 BUG_ON(priv->state_off && (priv->state != PRV_STATE_OFF));
959 BUG_ON(!priv->state_off && (priv->state == PRV_STATE_OFF));