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 "isl3877"
44 #define ISL3886_IMAGE_FILE "isl3886"
45 #define ISL3890_IMAGE_FILE "isl3890"
46 MODULE_FIRMWARE(ISL3877_IMAGE_FILE
);
47 MODULE_FIRMWARE(ISL3886_IMAGE_FILE
);
48 MODULE_FIRMWARE(ISL3890_IMAGE_FILE
);
50 static int prism54_bring_down(islpci_private
*);
51 static int islpci_alloc_memory(islpci_private
*);
53 /* Temporary dummy MAC address to use until firmware is loaded.
54 * The idea there is that some tools (such as nameif) may query
55 * the MAC address before the netdev is 'open'. By using a valid
56 * OUI prefix, they can process the netdev properly.
57 * Of course, this is not the final/real MAC address. It doesn't
58 * matter, as you are suppose to be able to change it anytime via
59 * ndev->set_mac_address. Jean II */
60 static const unsigned char dummy_mac
[6] = { 0x00, 0x30, 0xB4, 0x00, 0x00, 0x00 };
63 isl_upload_firmware(islpci_private
*priv
)
66 void __iomem
*device_base
= priv
->device_base
;
68 /* clear the RAMBoot and the Reset bit */
69 reg
= readl(device_base
+ ISL38XX_CTRL_STAT_REG
);
70 reg
&= ~ISL38XX_CTRL_STAT_RESET
;
71 reg
&= ~ISL38XX_CTRL_STAT_RAMBOOT
;
72 writel(reg
, device_base
+ ISL38XX_CTRL_STAT_REG
);
74 udelay(ISL38XX_WRITEIO_DELAY
);
76 /* set the Reset bit without reading the register ! */
77 reg
|= ISL38XX_CTRL_STAT_RESET
;
78 writel(reg
, device_base
+ ISL38XX_CTRL_STAT_REG
);
80 udelay(ISL38XX_WRITEIO_DELAY
);
82 /* clear the Reset bit */
83 reg
&= ~ISL38XX_CTRL_STAT_RESET
;
84 writel(reg
, device_base
+ ISL38XX_CTRL_STAT_REG
);
87 /* wait a while for the device to reboot */
91 const struct firmware
*fw_entry
= NULL
;
95 rc
= request_firmware(&fw_entry
, priv
->firmware
, PRISM_FW_PDEV
);
98 "%s: request_firmware() failed for '%s'\n",
99 "prism54", priv
->firmware
);
102 /* prepare the Direct Memory Base register */
103 reg
= ISL38XX_DEV_FIRMWARE_ADDRES
;
105 fw_ptr
= (u32
*) fw_entry
->data
;
106 fw_len
= fw_entry
->size
;
110 "%s: firmware '%s' size is not multiple of 32bit, aborting!\n",
111 "prism54", priv
->firmware
);
112 release_firmware(fw_entry
);
113 return -EILSEQ
; /* Illegal byte sequence */;
119 ISL38XX_MEMORY_WINDOW_SIZE
) ?
120 ISL38XX_MEMORY_WINDOW_SIZE
: fw_len
;
121 u32 __iomem
*dev_fw_ptr
= device_base
+ ISL38XX_DIRECT_MEM_WIN
;
123 /* set the card's base address for writing the data */
124 isl38xx_w32_flush(device_base
, reg
,
125 ISL38XX_DIR_MEM_BASE_REG
);
126 wmb(); /* be paranoid */
128 /* increment the write address for next iteration */
132 /* write the data to the Direct Memory Window 32bit-wise */
133 /* memcpy_toio() doesn't guarantee 32bit writes :-| */
134 while (_fw_len
> 0) {
135 /* use non-swapping writel() */
136 __raw_writel(*fw_ptr
, dev_fw_ptr
);
137 fw_ptr
++, dev_fw_ptr
++;
141 /* flush PCI posting */
142 (void) readl(device_base
+ ISL38XX_PCI_POSTING_FLUSH
);
143 wmb(); /* be paranoid again */
145 BUG_ON(_fw_len
!= 0);
150 /* Firmware version is at offset 40 (also for "newmac") */
151 printk(KERN_DEBUG
"%s: firmware version: %.8s\n",
152 priv
->ndev
->name
, fw_entry
->data
+ 40);
154 release_firmware(fw_entry
);
157 /* now reset the device
158 * clear the Reset & ClkRun bit, set the RAMBoot bit */
159 reg
= readl(device_base
+ ISL38XX_CTRL_STAT_REG
);
160 reg
&= ~ISL38XX_CTRL_STAT_CLKRUN
;
161 reg
&= ~ISL38XX_CTRL_STAT_RESET
;
162 reg
|= ISL38XX_CTRL_STAT_RAMBOOT
;
163 isl38xx_w32_flush(device_base
, reg
, ISL38XX_CTRL_STAT_REG
);
165 udelay(ISL38XX_WRITEIO_DELAY
);
167 /* set the reset bit latches the host override and RAMBoot bits
168 * into the device for operation when the reset bit is reset */
169 reg
|= ISL38XX_CTRL_STAT_RESET
;
170 writel(reg
, device_base
+ ISL38XX_CTRL_STAT_REG
);
171 /* don't do flush PCI posting here! */
173 udelay(ISL38XX_WRITEIO_DELAY
);
175 /* clear the reset bit should start the whole circus */
176 reg
&= ~ISL38XX_CTRL_STAT_RESET
;
177 writel(reg
, device_base
+ ISL38XX_CTRL_STAT_REG
);
178 /* don't do flush PCI posting here! */
180 udelay(ISL38XX_WRITEIO_DELAY
);
185 /******************************************************************************
186 Device Interrupt Handler
187 ******************************************************************************/
190 islpci_interrupt(int irq
, void *config
)
193 islpci_private
*priv
= config
;
194 struct net_device
*ndev
= priv
->ndev
;
195 void __iomem
*device
= priv
->device_base
;
196 int powerstate
= ISL38XX_PSM_POWERSAVE_STATE
;
198 /* lock the interrupt handler */
199 spin_lock(&priv
->slock
);
201 /* received an interrupt request on a shared IRQ line
202 * first check whether the device is in sleep mode */
203 reg
= readl(device
+ ISL38XX_CTRL_STAT_REG
);
204 if (reg
& ISL38XX_CTRL_STAT_SLEEPMODE
)
205 /* device is in sleep mode, IRQ was generated by someone else */
207 #if VERBOSE > SHOW_ERROR_MESSAGES
208 DEBUG(SHOW_TRACING
, "Assuming someone else called the IRQ\n");
210 spin_unlock(&priv
->slock
);
215 /* check whether there is any source of interrupt on the device */
216 reg
= readl(device
+ ISL38XX_INT_IDENT_REG
);
218 /* also check the contents of the Interrupt Enable Register, because this
219 * will filter out interrupt sources from other devices on the same irq ! */
220 reg
&= readl(device
+ ISL38XX_INT_EN_REG
);
221 reg
&= ISL38XX_INT_SOURCES
;
224 if (islpci_get_state(priv
) != PRV_STATE_SLEEP
)
225 powerstate
= ISL38XX_PSM_ACTIVE_STATE
;
227 /* reset the request bits in the Identification register */
228 isl38xx_w32_flush(device
, reg
, ISL38XX_INT_ACK_REG
);
230 #if VERBOSE > SHOW_ERROR_MESSAGES
231 DEBUG(SHOW_FUNCTION_CALLS
,
232 "IRQ: Identification register 0x%p 0x%x\n", device
, reg
);
235 /* check for each bit in the register separately */
236 if (reg
& ISL38XX_INT_IDENT_UPDATE
) {
237 #if VERBOSE > SHOW_ERROR_MESSAGES
238 /* Queue has been updated */
239 DEBUG(SHOW_TRACING
, "IRQ: Update flag\n");
241 DEBUG(SHOW_QUEUE_INDEXES
,
242 "CB drv Qs: [%i][%i][%i][%i][%i][%i]\n",
243 le32_to_cpu(priv
->control_block
->
244 driver_curr_frag
[0]),
245 le32_to_cpu(priv
->control_block
->
246 driver_curr_frag
[1]),
247 le32_to_cpu(priv
->control_block
->
248 driver_curr_frag
[2]),
249 le32_to_cpu(priv
->control_block
->
250 driver_curr_frag
[3]),
251 le32_to_cpu(priv
->control_block
->
252 driver_curr_frag
[4]),
253 le32_to_cpu(priv
->control_block
->
257 DEBUG(SHOW_QUEUE_INDEXES
,
258 "CB dev Qs: [%i][%i][%i][%i][%i][%i]\n",
259 le32_to_cpu(priv
->control_block
->
260 device_curr_frag
[0]),
261 le32_to_cpu(priv
->control_block
->
262 device_curr_frag
[1]),
263 le32_to_cpu(priv
->control_block
->
264 device_curr_frag
[2]),
265 le32_to_cpu(priv
->control_block
->
266 device_curr_frag
[3]),
267 le32_to_cpu(priv
->control_block
->
268 device_curr_frag
[4]),
269 le32_to_cpu(priv
->control_block
->
274 /* cleanup the data low transmit queue */
275 islpci_eth_cleanup_transmit(priv
, priv
->control_block
);
277 /* device is in active state, update the
278 * powerstate flag if necessary */
279 powerstate
= ISL38XX_PSM_ACTIVE_STATE
;
281 /* check all three queues in priority order
282 * call the PIMFOR receive function until the
284 if (isl38xx_in_queue(priv
->control_block
,
285 ISL38XX_CB_RX_MGMTQ
) != 0) {
286 #if VERBOSE > SHOW_ERROR_MESSAGES
288 "Received frame in Management Queue\n");
290 islpci_mgt_receive(ndev
);
292 islpci_mgt_cleanup_transmit(ndev
);
294 /* Refill slots in receive queue */
295 islpci_mgmt_rx_fill(ndev
);
297 /* no need to trigger the device, next
298 islpci_mgt_transaction does it */
301 while (isl38xx_in_queue(priv
->control_block
,
302 ISL38XX_CB_RX_DATA_LQ
) != 0) {
303 #if VERBOSE > SHOW_ERROR_MESSAGES
305 "Received frame in Data Low Queue\n");
307 islpci_eth_receive(priv
);
310 /* check whether the data transmit queues were full */
311 if (priv
->data_low_tx_full
) {
312 /* check whether the transmit is not full anymore */
313 if (ISL38XX_CB_TX_QSIZE
-
314 isl38xx_in_queue(priv
->control_block
,
315 ISL38XX_CB_TX_DATA_LQ
) >=
316 ISL38XX_MIN_QTHRESHOLD
) {
317 /* nope, the driver is ready for more network frames */
318 netif_wake_queue(priv
->ndev
);
320 /* reset the full flag */
321 priv
->data_low_tx_full
= 0;
326 if (reg
& ISL38XX_INT_IDENT_INIT
) {
327 /* Device has been initialized */
328 #if VERBOSE > SHOW_ERROR_MESSAGES
330 "IRQ: Init flag, device initialized\n");
332 wake_up(&priv
->reset_done
);
335 if (reg
& ISL38XX_INT_IDENT_SLEEP
) {
336 /* Device intends to move to powersave state */
337 #if VERBOSE > SHOW_ERROR_MESSAGES
338 DEBUG(SHOW_TRACING
, "IRQ: Sleep flag\n");
340 isl38xx_handle_sleep_request(priv
->control_block
,
345 if (reg
& ISL38XX_INT_IDENT_WAKEUP
) {
346 /* Device has been woken up to active state */
347 #if VERBOSE > SHOW_ERROR_MESSAGES
348 DEBUG(SHOW_TRACING
, "IRQ: Wakeup flag\n");
351 isl38xx_handle_wakeup(priv
->control_block
,
352 &powerstate
, priv
->device_base
);
355 #if VERBOSE > SHOW_ERROR_MESSAGES
356 DEBUG(SHOW_TRACING
, "Assuming someone else called the IRQ\n");
358 spin_unlock(&priv
->slock
);
363 if (islpci_get_state(priv
) == PRV_STATE_SLEEP
364 && powerstate
== ISL38XX_PSM_ACTIVE_STATE
)
365 islpci_set_state(priv
, PRV_STATE_READY
);
367 /* !sleep -> sleep */
368 if (islpci_get_state(priv
) != PRV_STATE_SLEEP
369 && powerstate
== ISL38XX_PSM_POWERSAVE_STATE
)
370 islpci_set_state(priv
, PRV_STATE_SLEEP
);
372 /* unlock the interrupt handler */
373 spin_unlock(&priv
->slock
);
378 /******************************************************************************
379 Network Interface Control & Statistical functions
380 ******************************************************************************/
382 islpci_open(struct net_device
*ndev
)
385 islpci_private
*priv
= netdev_priv(ndev
);
387 /* reset data structures, upload firmware and reset device */
388 rc
= islpci_reset(priv
,1);
390 prism54_bring_down(priv
);
391 return rc
; /* Returns informative message */
394 netif_start_queue(ndev
);
396 /* Turn off carrier if in STA or Ad-hoc mode. It will be turned on
397 * once the firmware receives a trap of being associated
398 * (GEN_OID_LINKSTATE). In other modes (AP or WDS or monitor) we
399 * should just leave the carrier on as its expected the firmware
400 * won't send us a trigger. */
401 if (priv
->iw_mode
== IW_MODE_INFRA
|| priv
->iw_mode
== IW_MODE_ADHOC
)
402 netif_carrier_off(ndev
);
404 netif_carrier_on(ndev
);
410 islpci_close(struct net_device
*ndev
)
412 islpci_private
*priv
= netdev_priv(ndev
);
414 printk(KERN_DEBUG
"%s: islpci_close ()\n", ndev
->name
);
416 netif_stop_queue(ndev
);
418 return prism54_bring_down(priv
);
422 prism54_bring_down(islpci_private
*priv
)
424 void __iomem
*device_base
= priv
->device_base
;
426 /* we are going to shutdown the device */
427 islpci_set_state(priv
, PRV_STATE_PREBOOT
);
429 /* disable all device interrupts in case they weren't */
430 isl38xx_disable_interrupts(priv
->device_base
);
432 /* For safety reasons, we may want to ensure that no DMA transfer is
433 * currently in progress by emptying the TX and RX queues. */
435 /* wait until interrupts have finished executing on other CPUs */
436 synchronize_irq(priv
->pdev
->irq
);
438 reg
= readl(device_base
+ ISL38XX_CTRL_STAT_REG
);
439 reg
&= ~(ISL38XX_CTRL_STAT_RESET
| ISL38XX_CTRL_STAT_RAMBOOT
);
440 writel(reg
, device_base
+ ISL38XX_CTRL_STAT_REG
);
442 udelay(ISL38XX_WRITEIO_DELAY
);
444 reg
|= ISL38XX_CTRL_STAT_RESET
;
445 writel(reg
, device_base
+ ISL38XX_CTRL_STAT_REG
);
447 udelay(ISL38XX_WRITEIO_DELAY
);
449 /* clear the Reset bit */
450 reg
&= ~ISL38XX_CTRL_STAT_RESET
;
451 writel(reg
, device_base
+ ISL38XX_CTRL_STAT_REG
);
454 /* wait a while for the device to reset */
455 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
461 islpci_upload_fw(islpci_private
*priv
)
463 islpci_state_t old_state
;
466 old_state
= islpci_set_state(priv
, PRV_STATE_BOOT
);
468 printk(KERN_DEBUG
"%s: uploading firmware...\n", priv
->ndev
->name
);
470 rc
= isl_upload_firmware(priv
);
472 /* error uploading the firmware */
473 printk(KERN_ERR
"%s: could not upload firmware ('%s')\n",
474 priv
->ndev
->name
, priv
->firmware
);
476 islpci_set_state(priv
, old_state
);
480 printk(KERN_DEBUG
"%s: firmware upload complete\n",
483 islpci_set_state(priv
, PRV_STATE_POSTBOOT
);
489 islpci_reset_if(islpci_private
*priv
)
496 prepare_to_wait(&priv
->reset_done
, &wait
, TASK_UNINTERRUPTIBLE
);
498 /* now the last step is to reset the interface */
499 isl38xx_interface_reset(priv
->device_base
, priv
->device_host_address
);
500 islpci_set_state(priv
, PRV_STATE_PREINIT
);
502 for(count
= 0; count
< 2 && result
; count
++) {
503 /* The software reset acknowledge needs about 220 msec here.
504 * Be conservative and wait for up to one second. */
506 remaining
= schedule_timeout_uninterruptible(HZ
);
513 /* If we're here it's because our IRQ hasn't yet gone through.
514 * Retry a bit more...
516 printk(KERN_ERR
"%s: no 'reset complete' IRQ seen - retrying\n",
520 finish_wait(&priv
->reset_done
, &wait
);
523 printk(KERN_ERR
"%s: interface reset failure\n", priv
->ndev
->name
);
527 islpci_set_state(priv
, PRV_STATE_INIT
);
529 /* Now that the device is 100% up, let's allow
530 * for the other interrupts --
531 * NOTE: this is not *yet* true since we've only allowed the
532 * INIT interrupt on the IRQ line. We can perhaps poll
533 * the IRQ line until we know for sure the reset went through */
534 isl38xx_enable_common_interrupts(priv
->device_base
);
536 down_write(&priv
->mib_sem
);
537 result
= mgt_commit(priv
);
539 printk(KERN_ERR
"%s: interface reset failure\n", priv
->ndev
->name
);
540 up_write(&priv
->mib_sem
);
543 up_write(&priv
->mib_sem
);
545 islpci_set_state(priv
, PRV_STATE_READY
);
547 printk(KERN_DEBUG
"%s: interface reset complete\n", priv
->ndev
->name
);
552 islpci_reset(islpci_private
*priv
, int reload_firmware
)
554 isl38xx_control_block
*cb
= /* volatile not needed */
555 (isl38xx_control_block
*) priv
->control_block
;
560 islpci_set_state(priv
, PRV_STATE_PREBOOT
);
562 islpci_set_state(priv
, PRV_STATE_POSTBOOT
);
564 printk(KERN_DEBUG
"%s: resetting device...\n", priv
->ndev
->name
);
566 /* disable all device interrupts in case they weren't */
567 isl38xx_disable_interrupts(priv
->device_base
);
569 /* flush all management queues */
570 priv
->index_mgmt_tx
= 0;
571 priv
->index_mgmt_rx
= 0;
573 /* clear the indexes in the frame pointer */
574 for (counter
= 0; counter
< ISL38XX_CB_QCOUNT
; counter
++) {
575 cb
->driver_curr_frag
[counter
] = cpu_to_le32(0);
576 cb
->device_curr_frag
[counter
] = cpu_to_le32(0);
579 /* reset the mgmt receive queue */
580 for (counter
= 0; counter
< ISL38XX_CB_MGMT_QSIZE
; counter
++) {
581 isl38xx_fragment
*frag
= &cb
->rx_data_mgmt
[counter
];
582 frag
->size
= cpu_to_le16(MGMT_FRAME_SIZE
);
584 frag
->address
= cpu_to_le32(priv
->mgmt_rx
[counter
].pci_addr
);
587 for (counter
= 0; counter
< ISL38XX_CB_RX_QSIZE
; counter
++) {
588 cb
->rx_data_low
[counter
].address
=
589 cpu_to_le32((u32
) priv
->pci_map_rx_address
[counter
]);
592 /* since the receive queues are filled with empty fragments, now we can
593 * set the corresponding indexes in the Control Block */
594 priv
->control_block
->driver_curr_frag
[ISL38XX_CB_RX_DATA_LQ
] =
595 cpu_to_le32(ISL38XX_CB_RX_QSIZE
);
596 priv
->control_block
->driver_curr_frag
[ISL38XX_CB_RX_MGMTQ
] =
597 cpu_to_le32(ISL38XX_CB_MGMT_QSIZE
);
599 /* reset the remaining real index registers and full flags */
600 priv
->free_data_rx
= 0;
601 priv
->free_data_tx
= 0;
602 priv
->data_low_tx_full
= 0;
604 if (reload_firmware
) { /* Should we load the firmware ? */
605 /* now that the data structures are cleaned up, upload
606 * firmware and reset interface */
607 rc
= islpci_upload_fw(priv
);
609 printk(KERN_ERR
"%s: islpci_reset: failure\n",
615 /* finally reset interface */
616 rc
= islpci_reset_if(priv
);
618 printk(KERN_ERR
"prism54: Your card/socket may be faulty, or IRQ line too busy :(\n");
622 /******************************************************************************
623 Network device configuration functions
624 ******************************************************************************/
626 islpci_alloc_memory(islpci_private
*priv
)
630 #if VERBOSE > SHOW_ERROR_MESSAGES
631 printk(KERN_DEBUG
"islpci_alloc_memory\n");
634 /* remap the PCI device base address to accessible */
635 if (!(priv
->device_base
=
636 ioremap(pci_resource_start(priv
->pdev
, 0),
637 ISL38XX_PCI_MEM_SIZE
))) {
638 /* error in remapping the PCI device memory address range */
639 printk(KERN_ERR
"PCI memory remapping failed\n");
643 /* memory layout for consistent DMA region:
645 * Area 1: Control Block for the device interface
646 * Area 2: Power Save Mode Buffer for temporary frame storage. Be aware that
647 * the number of supported stations in the AP determines the minimal
648 * size of the buffer !
651 /* perform the allocation */
652 priv
->driver_mem_address
= pci_alloc_consistent(priv
->pdev
,
655 device_host_address
);
657 if (!priv
->driver_mem_address
) {
658 /* error allocating the block of PCI memory */
659 printk(KERN_ERR
"%s: could not allocate DMA memory, aborting!",
664 /* assign the Control Block to the first address of the allocated area */
665 priv
->control_block
=
666 (isl38xx_control_block
*) priv
->driver_mem_address
;
668 /* set the Power Save Buffer pointer directly behind the CB */
669 priv
->device_psm_buffer
=
670 priv
->device_host_address
+ CONTROL_BLOCK_SIZE
;
672 /* make sure all buffer pointers are initialized */
673 for (counter
= 0; counter
< ISL38XX_CB_QCOUNT
; counter
++) {
674 priv
->control_block
->driver_curr_frag
[counter
] = cpu_to_le32(0);
675 priv
->control_block
->device_curr_frag
[counter
] = cpu_to_le32(0);
678 priv
->index_mgmt_rx
= 0;
679 memset(priv
->mgmt_rx
, 0, sizeof(priv
->mgmt_rx
));
680 memset(priv
->mgmt_tx
, 0, sizeof(priv
->mgmt_tx
));
682 /* allocate rx queue for management frames */
683 if (islpci_mgmt_rx_fill(priv
->ndev
) < 0)
686 /* now get the data rx skb's */
687 memset(priv
->data_low_rx
, 0, sizeof (priv
->data_low_rx
));
688 memset(priv
->pci_map_rx_address
, 0, sizeof (priv
->pci_map_rx_address
));
690 for (counter
= 0; counter
< ISL38XX_CB_RX_QSIZE
; counter
++) {
693 /* allocate an sk_buff for received data frames storage
694 * each frame on receive size consists of 1 fragment
695 * include any required allignment operations */
696 if (!(skb
= dev_alloc_skb(MAX_FRAGMENT_SIZE_RX
+ 2))) {
697 /* error allocating an sk_buff structure elements */
698 printk(KERN_ERR
"Error allocating skb.\n");
702 skb_reserve(skb
, (4 - (long) skb
->data
) & 0x03);
703 /* add the new allocated sk_buff to the buffer array */
704 priv
->data_low_rx
[counter
] = skb
;
706 /* map the allocated skb data area to pci */
707 priv
->pci_map_rx_address
[counter
] =
708 pci_map_single(priv
->pdev
, (void *) skb
->data
,
709 MAX_FRAGMENT_SIZE_RX
+ 2,
711 if (!priv
->pci_map_rx_address
[counter
]) {
712 /* error mapping the buffer to device
713 accessible memory address */
714 printk(KERN_ERR
"failed to map skb DMA'able\n");
719 prism54_acl_init(&priv
->acl
);
720 prism54_wpa_bss_ie_init(priv
);
726 islpci_free_memory(priv
);
731 islpci_free_memory(islpci_private
*priv
)
735 if (priv
->device_base
)
736 iounmap(priv
->device_base
);
737 priv
->device_base
= NULL
;
739 /* free consistent DMA area... */
740 if (priv
->driver_mem_address
)
741 pci_free_consistent(priv
->pdev
, HOST_MEM_BLOCK
,
742 priv
->driver_mem_address
,
743 priv
->device_host_address
);
745 /* clear some dangling pointers */
746 priv
->driver_mem_address
= NULL
;
747 priv
->device_host_address
= 0;
748 priv
->device_psm_buffer
= 0;
749 priv
->control_block
= NULL
;
751 /* clean up mgmt rx buffers */
752 for (counter
= 0; counter
< ISL38XX_CB_MGMT_QSIZE
; counter
++) {
753 struct islpci_membuf
*buf
= &priv
->mgmt_rx
[counter
];
755 pci_unmap_single(priv
->pdev
, buf
->pci_addr
,
756 buf
->size
, PCI_DMA_FROMDEVICE
);
763 /* clean up data rx buffers */
764 for (counter
= 0; counter
< ISL38XX_CB_RX_QSIZE
; counter
++) {
765 if (priv
->pci_map_rx_address
[counter
])
766 pci_unmap_single(priv
->pdev
,
767 priv
->pci_map_rx_address
[counter
],
768 MAX_FRAGMENT_SIZE_RX
+ 2,
770 priv
->pci_map_rx_address
[counter
] = 0;
772 if (priv
->data_low_rx
[counter
])
773 dev_kfree_skb(priv
->data_low_rx
[counter
]);
774 priv
->data_low_rx
[counter
] = NULL
;
777 /* Free the access control list and the WPA list */
778 prism54_acl_clean(&priv
->acl
);
779 prism54_wpa_bss_ie_clean(priv
);
787 islpci_set_multicast_list(struct net_device
*dev
)
789 /* put device into promisc mode and let network layer handle it */
793 static void islpci_ethtool_get_drvinfo(struct net_device
*dev
,
794 struct ethtool_drvinfo
*info
)
796 strcpy(info
->driver
, DRV_NAME
);
797 strcpy(info
->version
, DRV_VERSION
);
800 static const struct ethtool_ops islpci_ethtool_ops
= {
801 .get_drvinfo
= islpci_ethtool_get_drvinfo
,
804 static const struct net_device_ops islpci_netdev_ops
= {
805 .ndo_open
= islpci_open
,
806 .ndo_stop
= islpci_close
,
807 .ndo_do_ioctl
= prism54_ioctl
,
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_change_mtu
= eth_change_mtu
,
812 .ndo_validate_addr
= eth_validate_addr
,
816 islpci_setup(struct pci_dev
*pdev
)
818 islpci_private
*priv
;
819 struct net_device
*ndev
= alloc_etherdev(sizeof (islpci_private
));
824 pci_set_drvdata(pdev
, ndev
);
825 #if defined(SET_NETDEV_DEV)
826 SET_NETDEV_DEV(ndev
, &pdev
->dev
);
829 /* setup the structure members */
830 ndev
->base_addr
= pci_resource_start(pdev
, 0);
831 ndev
->irq
= pdev
->irq
;
833 /* initialize the function pointers */
834 ndev
->netdev_ops
= &islpci_netdev_ops
;
835 ndev
->wireless_handlers
= &prism54_handler_def
;
836 ndev
->ethtool_ops
= &islpci_ethtool_ops
;
838 /* ndev->set_multicast_list = &islpci_set_multicast_list; */
839 ndev
->addr_len
= ETH_ALEN
;
840 /* Get a non-zero dummy MAC address for nameif. Jean II */
841 memcpy(ndev
->dev_addr
, dummy_mac
, 6);
843 ndev
->watchdog_timeo
= ISLPCI_TX_TIMEOUT
;
845 /* allocate a private device structure to the network device */
846 priv
= netdev_priv(ndev
);
849 priv
->monitor_type
= ARPHRD_IEEE80211
;
850 priv
->ndev
->type
= (priv
->iw_mode
== IW_MODE_MONITOR
) ?
851 priv
->monitor_type
: ARPHRD_ETHER
;
853 /* Add pointers to enable iwspy support. */
854 priv
->wireless_data
.spy_data
= &priv
->spy_data
;
855 ndev
->wireless_data
= &priv
->wireless_data
;
857 /* save the start and end address of the PCI memory area */
858 ndev
->mem_start
= (unsigned long) priv
->device_base
;
859 ndev
->mem_end
= ndev
->mem_start
+ ISL38XX_PCI_MEM_SIZE
;
861 #if VERBOSE > SHOW_ERROR_MESSAGES
862 DEBUG(SHOW_TRACING
, "PCI Memory remapped to 0x%p\n", priv
->device_base
);
865 init_waitqueue_head(&priv
->reset_done
);
867 /* init the queue read locks, process wait counter */
868 mutex_init(&priv
->mgmt_lock
);
869 priv
->mgmt_received
= NULL
;
870 init_waitqueue_head(&priv
->mgmt_wqueue
);
871 mutex_init(&priv
->stats_lock
);
872 spin_lock_init(&priv
->slock
);
874 /* init state machine with off#1 state */
875 priv
->state
= PRV_STATE_OFF
;
878 /* initialize workqueue's */
879 INIT_WORK(&priv
->stats_work
, prism54_update_stats
);
880 priv
->stats_timestamp
= 0;
882 INIT_WORK(&priv
->reset_task
, islpci_do_reset_and_wake
);
883 priv
->reset_task_pending
= 0;
885 /* allocate various memory areas */
886 if (islpci_alloc_memory(priv
))
889 /* select the firmware file depending on the device id */
890 switch (pdev
->device
) {
892 strcpy(priv
->firmware
, ISL3877_IMAGE_FILE
);
896 strcpy(priv
->firmware
, ISL3886_IMAGE_FILE
);
900 strcpy(priv
->firmware
, ISL3890_IMAGE_FILE
);
904 if (register_netdev(ndev
)) {
905 DEBUG(SHOW_ERROR_MESSAGES
,
906 "ERROR: register_netdev() failed\n");
907 goto do_islpci_free_memory
;
912 do_islpci_free_memory
:
913 islpci_free_memory(priv
);
915 pci_set_drvdata(pdev
, NULL
);
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
));