blob: 6e7d71c5409146845749a60d26a34b3d990878e0 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * 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>
5 *
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
9 *
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.
14 *
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
18 *
19 */
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/module.h>
22
23#include <linux/netdevice.h>
Kai Engertff86a542006-12-12 21:09:41 +010024#include <linux/ethtool.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <linux/pci.h>
26#include <linux/etherdevice.h>
27#include <linux/delay.h>
28#include <linux/if_arp.h>
29
30#include <asm/io.h>
31
32#include "prismcompat.h"
33#include "isl_38xx.h"
34#include "isl_ioctl.h"
35#include "islpci_dev.h"
36#include "islpci_mgt.h"
37#include "islpci_eth.h"
38#include "oid_mgt.h"
39
40#define ISL3877_IMAGE_FILE "isl3877"
41#define ISL3886_IMAGE_FILE "isl3886"
42#define ISL3890_IMAGE_FILE "isl3890"
43
44static int prism54_bring_down(islpci_private *);
45static int islpci_alloc_memory(islpci_private *);
46static struct net_device_stats *islpci_statistics(struct net_device *);
47
48/* Temporary dummy MAC address to use until firmware is loaded.
49 * The idea there is that some tools (such as nameif) may query
50 * the MAC address before the netdev is 'open'. By using a valid
51 * OUI prefix, they can process the netdev properly.
52 * Of course, this is not the final/real MAC address. It doesn't
53 * matter, as you are suppose to be able to change it anytime via
54 * ndev->set_mac_address. Jean II */
55static const unsigned char dummy_mac[6] = { 0x00, 0x30, 0xB4, 0x00, 0x00, 0x00 };
56
57static int
58isl_upload_firmware(islpci_private *priv)
59{
60 u32 reg, rc;
61 void __iomem *device_base = priv->device_base;
62
63 /* clear the RAMBoot and the Reset bit */
64 reg = readl(device_base + ISL38XX_CTRL_STAT_REG);
65 reg &= ~ISL38XX_CTRL_STAT_RESET;
66 reg &= ~ISL38XX_CTRL_STAT_RAMBOOT;
67 writel(reg, device_base + ISL38XX_CTRL_STAT_REG);
68 wmb();
69 udelay(ISL38XX_WRITEIO_DELAY);
70
71 /* set the Reset bit without reading the register ! */
72 reg |= ISL38XX_CTRL_STAT_RESET;
73 writel(reg, device_base + ISL38XX_CTRL_STAT_REG);
74 wmb();
75 udelay(ISL38XX_WRITEIO_DELAY);
76
77 /* clear the Reset bit */
78 reg &= ~ISL38XX_CTRL_STAT_RESET;
79 writel(reg, device_base + ISL38XX_CTRL_STAT_REG);
80 wmb();
81
82 /* wait a while for the device to reboot */
83 mdelay(50);
84
85 {
86 const struct firmware *fw_entry = NULL;
87 long fw_len;
88 const u32 *fw_ptr;
89
90 rc = request_firmware(&fw_entry, priv->firmware, PRISM_FW_PDEV);
91 if (rc) {
92 printk(KERN_ERR
93 "%s: request_firmware() failed for '%s'\n",
94 "prism54", priv->firmware);
95 return rc;
96 }
97 /* prepare the Direct Memory Base register */
98 reg = ISL38XX_DEV_FIRMWARE_ADDRES;
99
100 fw_ptr = (u32 *) fw_entry->data;
101 fw_len = fw_entry->size;
102
103 if (fw_len % 4) {
104 printk(KERN_ERR
105 "%s: firmware '%s' size is not multiple of 32bit, aborting!\n",
106 "prism54", priv->firmware);
107 release_firmware(fw_entry);
108 return -EILSEQ; /* Illegal byte sequence */;
109 }
110
111 while (fw_len > 0) {
112 long _fw_len =
113 (fw_len >
114 ISL38XX_MEMORY_WINDOW_SIZE) ?
115 ISL38XX_MEMORY_WINDOW_SIZE : fw_len;
116 u32 __iomem *dev_fw_ptr = device_base + ISL38XX_DIRECT_MEM_WIN;
117
Robert P. J. Daybeb7dd82007-05-09 07:14:03 +0200118 /* set the card's base address for writing the data */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 isl38xx_w32_flush(device_base, reg,
120 ISL38XX_DIR_MEM_BASE_REG);
121 wmb(); /* be paranoid */
122
123 /* increment the write address for next iteration */
124 reg += _fw_len;
125 fw_len -= _fw_len;
126
127 /* write the data to the Direct Memory Window 32bit-wise */
128 /* memcpy_toio() doesn't guarantee 32bit writes :-| */
129 while (_fw_len > 0) {
130 /* use non-swapping writel() */
131 __raw_writel(*fw_ptr, dev_fw_ptr);
132 fw_ptr++, dev_fw_ptr++;
133 _fw_len -= 4;
134 }
135
136 /* flush PCI posting */
137 (void) readl(device_base + ISL38XX_PCI_POSTING_FLUSH);
138 wmb(); /* be paranoid again */
139
140 BUG_ON(_fw_len != 0);
141 }
142
143 BUG_ON(fw_len != 0);
144
145 /* Firmware version is at offset 40 (also for "newmac") */
146 printk(KERN_DEBUG "%s: firmware version: %.8s\n",
147 priv->ndev->name, fw_entry->data + 40);
148
149 release_firmware(fw_entry);
150 }
151
152 /* now reset the device
153 * clear the Reset & ClkRun bit, set the RAMBoot bit */
154 reg = readl(device_base + ISL38XX_CTRL_STAT_REG);
155 reg &= ~ISL38XX_CTRL_STAT_CLKRUN;
156 reg &= ~ISL38XX_CTRL_STAT_RESET;
157 reg |= ISL38XX_CTRL_STAT_RAMBOOT;
158 isl38xx_w32_flush(device_base, reg, ISL38XX_CTRL_STAT_REG);
159 wmb();
160 udelay(ISL38XX_WRITEIO_DELAY);
161
162 /* set the reset bit latches the host override and RAMBoot bits
163 * into the device for operation when the reset bit is reset */
164 reg |= ISL38XX_CTRL_STAT_RESET;
165 writel(reg, device_base + ISL38XX_CTRL_STAT_REG);
166 /* don't do flush PCI posting here! */
167 wmb();
168 udelay(ISL38XX_WRITEIO_DELAY);
169
170 /* clear the reset bit should start the whole circus */
171 reg &= ~ISL38XX_CTRL_STAT_RESET;
172 writel(reg, device_base + ISL38XX_CTRL_STAT_REG);
173 /* don't do flush PCI posting here! */
174 wmb();
175 udelay(ISL38XX_WRITEIO_DELAY);
176
177 return 0;
178}
179
180/******************************************************************************
181 Device Interrupt Handler
182******************************************************************************/
183
184irqreturn_t
David Howells7d12e782006-10-05 14:55:46 +0100185islpci_interrupt(int irq, void *config)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186{
187 u32 reg;
188 islpci_private *priv = config;
189 struct net_device *ndev = priv->ndev;
190 void __iomem *device = priv->device_base;
191 int powerstate = ISL38XX_PSM_POWERSAVE_STATE;
192
193 /* lock the interrupt handler */
194 spin_lock(&priv->slock);
195
196 /* received an interrupt request on a shared IRQ line
197 * first check whether the device is in sleep mode */
198 reg = readl(device + ISL38XX_CTRL_STAT_REG);
199 if (reg & ISL38XX_CTRL_STAT_SLEEPMODE)
200 /* device is in sleep mode, IRQ was generated by someone else */
201 {
202#if VERBOSE > SHOW_ERROR_MESSAGES
203 DEBUG(SHOW_TRACING, "Assuming someone else called the IRQ\n");
204#endif
205 spin_unlock(&priv->slock);
206 return IRQ_NONE;
207 }
208
209
210 /* check whether there is any source of interrupt on the device */
211 reg = readl(device + ISL38XX_INT_IDENT_REG);
212
213 /* also check the contents of the Interrupt Enable Register, because this
214 * will filter out interrupt sources from other devices on the same irq ! */
215 reg &= readl(device + ISL38XX_INT_EN_REG);
216 reg &= ISL38XX_INT_SOURCES;
217
218 if (reg != 0) {
219 if (islpci_get_state(priv) != PRV_STATE_SLEEP)
220 powerstate = ISL38XX_PSM_ACTIVE_STATE;
221
222 /* reset the request bits in the Identification register */
223 isl38xx_w32_flush(device, reg, ISL38XX_INT_ACK_REG);
224
225#if VERBOSE > SHOW_ERROR_MESSAGES
226 DEBUG(SHOW_FUNCTION_CALLS,
227 "IRQ: Identification register 0x%p 0x%x \n", device, reg);
228#endif
229
230 /* check for each bit in the register separately */
231 if (reg & ISL38XX_INT_IDENT_UPDATE) {
232#if VERBOSE > SHOW_ERROR_MESSAGES
233 /* Queue has been updated */
234 DEBUG(SHOW_TRACING, "IRQ: Update flag \n");
235
236 DEBUG(SHOW_QUEUE_INDEXES,
237 "CB drv Qs: [%i][%i][%i][%i][%i][%i]\n",
238 le32_to_cpu(priv->control_block->
239 driver_curr_frag[0]),
240 le32_to_cpu(priv->control_block->
241 driver_curr_frag[1]),
242 le32_to_cpu(priv->control_block->
243 driver_curr_frag[2]),
244 le32_to_cpu(priv->control_block->
245 driver_curr_frag[3]),
246 le32_to_cpu(priv->control_block->
247 driver_curr_frag[4]),
248 le32_to_cpu(priv->control_block->
249 driver_curr_frag[5])
250 );
251
252 DEBUG(SHOW_QUEUE_INDEXES,
253 "CB dev Qs: [%i][%i][%i][%i][%i][%i]\n",
254 le32_to_cpu(priv->control_block->
255 device_curr_frag[0]),
256 le32_to_cpu(priv->control_block->
257 device_curr_frag[1]),
258 le32_to_cpu(priv->control_block->
259 device_curr_frag[2]),
260 le32_to_cpu(priv->control_block->
261 device_curr_frag[3]),
262 le32_to_cpu(priv->control_block->
263 device_curr_frag[4]),
264 le32_to_cpu(priv->control_block->
265 device_curr_frag[5])
266 );
267#endif
268
269 /* cleanup the data low transmit queue */
270 islpci_eth_cleanup_transmit(priv, priv->control_block);
271
272 /* device is in active state, update the
273 * powerstate flag if necessary */
274 powerstate = ISL38XX_PSM_ACTIVE_STATE;
275
276 /* check all three queues in priority order
277 * call the PIMFOR receive function until the
278 * queue is empty */
279 if (isl38xx_in_queue(priv->control_block,
280 ISL38XX_CB_RX_MGMTQ) != 0) {
281#if VERBOSE > SHOW_ERROR_MESSAGES
282 DEBUG(SHOW_TRACING,
283 "Received frame in Management Queue\n");
284#endif
285 islpci_mgt_receive(ndev);
286
287 islpci_mgt_cleanup_transmit(ndev);
288
289 /* Refill slots in receive queue */
290 islpci_mgmt_rx_fill(ndev);
291
292 /* no need to trigger the device, next
293 islpci_mgt_transaction does it */
294 }
295
296 while (isl38xx_in_queue(priv->control_block,
297 ISL38XX_CB_RX_DATA_LQ) != 0) {
298#if VERBOSE > SHOW_ERROR_MESSAGES
299 DEBUG(SHOW_TRACING,
300 "Received frame in Data Low Queue \n");
301#endif
302 islpci_eth_receive(priv);
303 }
304
305 /* check whether the data transmit queues were full */
306 if (priv->data_low_tx_full) {
307 /* check whether the transmit is not full anymore */
308 if (ISL38XX_CB_TX_QSIZE -
309 isl38xx_in_queue(priv->control_block,
310 ISL38XX_CB_TX_DATA_LQ) >=
311 ISL38XX_MIN_QTHRESHOLD) {
312 /* nope, the driver is ready for more network frames */
313 netif_wake_queue(priv->ndev);
314
315 /* reset the full flag */
316 priv->data_low_tx_full = 0;
317 }
318 }
319 }
320
321 if (reg & ISL38XX_INT_IDENT_INIT) {
322 /* Device has been initialized */
323#if VERBOSE > SHOW_ERROR_MESSAGES
324 DEBUG(SHOW_TRACING,
325 "IRQ: Init flag, device initialized \n");
326#endif
327 wake_up(&priv->reset_done);
328 }
329
330 if (reg & ISL38XX_INT_IDENT_SLEEP) {
331 /* Device intends to move to powersave state */
332#if VERBOSE > SHOW_ERROR_MESSAGES
333 DEBUG(SHOW_TRACING, "IRQ: Sleep flag \n");
334#endif
335 isl38xx_handle_sleep_request(priv->control_block,
336 &powerstate,
337 priv->device_base);
338 }
339
340 if (reg & ISL38XX_INT_IDENT_WAKEUP) {
341 /* Device has been woken up to active state */
342#if VERBOSE > SHOW_ERROR_MESSAGES
343 DEBUG(SHOW_TRACING, "IRQ: Wakeup flag \n");
344#endif
345
346 isl38xx_handle_wakeup(priv->control_block,
347 &powerstate, priv->device_base);
348 }
349 } else {
350#if VERBOSE > SHOW_ERROR_MESSAGES
351 DEBUG(SHOW_TRACING, "Assuming someone else called the IRQ\n");
352#endif
353 spin_unlock(&priv->slock);
354 return IRQ_NONE;
355 }
356
357 /* sleep -> ready */
358 if (islpci_get_state(priv) == PRV_STATE_SLEEP
359 && powerstate == ISL38XX_PSM_ACTIVE_STATE)
360 islpci_set_state(priv, PRV_STATE_READY);
361
362 /* !sleep -> sleep */
363 if (islpci_get_state(priv) != PRV_STATE_SLEEP
364 && powerstate == ISL38XX_PSM_POWERSAVE_STATE)
365 islpci_set_state(priv, PRV_STATE_SLEEP);
366
367 /* unlock the interrupt handler */
368 spin_unlock(&priv->slock);
369
370 return IRQ_HANDLED;
371}
372
373/******************************************************************************
374 Network Interface Control & Statistical functions
375******************************************************************************/
376static int
377islpci_open(struct net_device *ndev)
378{
379 u32 rc;
380 islpci_private *priv = netdev_priv(ndev);
381
382 /* reset data structures, upload firmware and reset device */
383 rc = islpci_reset(priv,1);
384 if (rc) {
385 prism54_bring_down(priv);
386 return rc; /* Returns informative message */
387 }
388
389 netif_start_queue(ndev);
Luis R. Rodriguez7b463ce2008-04-01 15:17:36 -0400390
Luis R. Rodriguez85b442e2008-04-22 14:03:32 -0400391 /* Turn off carrier if in STA or Ad-hoc mode. It will be turned on
392 * once the firmware receives a trap of being associated
393 * (GEN_OID_LINKSTATE). In other modes (AP or WDS or monitor) we
394 * should just leave the carrier on as its expected the firmware
395 * won't send us a trigger. */
396 if (priv->iw_mode == IW_MODE_INFRA || priv->iw_mode == IW_MODE_ADHOC)
397 netif_carrier_off(ndev);
398 else
399 netif_carrier_on(ndev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400
401 return 0;
402}
403
404static int
405islpci_close(struct net_device *ndev)
406{
407 islpci_private *priv = netdev_priv(ndev);
408
409 printk(KERN_DEBUG "%s: islpci_close ()\n", ndev->name);
410
411 netif_stop_queue(ndev);
412
413 return prism54_bring_down(priv);
414}
415
416static int
417prism54_bring_down(islpci_private *priv)
418{
419 void __iomem *device_base = priv->device_base;
420 u32 reg;
421 /* we are going to shutdown the device */
422 islpci_set_state(priv, PRV_STATE_PREBOOT);
423
424 /* disable all device interrupts in case they weren't */
Dmitry Torokhov93b2dd12006-10-08 00:38:15 -0400425 isl38xx_disable_interrupts(priv->device_base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426
427 /* For safety reasons, we may want to ensure that no DMA transfer is
428 * currently in progress by emptying the TX and RX queues. */
429
430 /* wait until interrupts have finished executing on other CPUs */
431 synchronize_irq(priv->pdev->irq);
432
433 reg = readl(device_base + ISL38XX_CTRL_STAT_REG);
434 reg &= ~(ISL38XX_CTRL_STAT_RESET | ISL38XX_CTRL_STAT_RAMBOOT);
435 writel(reg, device_base + ISL38XX_CTRL_STAT_REG);
436 wmb();
437 udelay(ISL38XX_WRITEIO_DELAY);
438
439 reg |= ISL38XX_CTRL_STAT_RESET;
440 writel(reg, device_base + ISL38XX_CTRL_STAT_REG);
441 wmb();
442 udelay(ISL38XX_WRITEIO_DELAY);
443
444 /* clear the Reset bit */
445 reg &= ~ISL38XX_CTRL_STAT_RESET;
446 writel(reg, device_base + ISL38XX_CTRL_STAT_REG);
447 wmb();
448
449 /* wait a while for the device to reset */
Nishanth Aravamudan3173c892005-09-11 02:09:55 -0700450 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451
452 return 0;
453}
454
455static int
456islpci_upload_fw(islpci_private *priv)
457{
458 islpci_state_t old_state;
459 u32 rc;
460
461 old_state = islpci_set_state(priv, PRV_STATE_BOOT);
462
463 printk(KERN_DEBUG "%s: uploading firmware...\n", priv->ndev->name);
464
465 rc = isl_upload_firmware(priv);
466 if (rc) {
467 /* error uploading the firmware */
468 printk(KERN_ERR "%s: could not upload firmware ('%s')\n",
469 priv->ndev->name, priv->firmware);
470
471 islpci_set_state(priv, old_state);
472 return rc;
473 }
474
475 printk(KERN_DEBUG "%s: firmware upload complete\n",
476 priv->ndev->name);
477
478 islpci_set_state(priv, PRV_STATE_POSTBOOT);
479
480 return 0;
481}
482
483static int
484islpci_reset_if(islpci_private *priv)
485{
486 long remaining;
487 int result = -ETIME;
488 int count;
489
490 DEFINE_WAIT(wait);
491 prepare_to_wait(&priv->reset_done, &wait, TASK_UNINTERRUPTIBLE);
Dmitry Torokhov93b2dd12006-10-08 00:38:15 -0400492
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 /* now the last step is to reset the interface */
494 isl38xx_interface_reset(priv->device_base, priv->device_host_address);
495 islpci_set_state(priv, PRV_STATE_PREINIT);
496
497 for(count = 0; count < 2 && result; count++) {
498 /* The software reset acknowledge needs about 220 msec here.
499 * Be conservative and wait for up to one second. */
Dmitry Torokhov93b2dd12006-10-08 00:38:15 -0400500
Nishanth Aravamudan3173c892005-09-11 02:09:55 -0700501 remaining = schedule_timeout_uninterruptible(HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502
503 if(remaining > 0) {
504 result = 0;
505 break;
506 }
507
Dmitry Torokhov93b2dd12006-10-08 00:38:15 -0400508 /* If we're here it's because our IRQ hasn't yet gone through.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 * Retry a bit more...
510 */
511 printk(KERN_ERR "%s: no 'reset complete' IRQ seen - retrying\n",
512 priv->ndev->name);
513 }
514
515 finish_wait(&priv->reset_done, &wait);
516
517 if (result) {
518 printk(KERN_ERR "%s: interface reset failure\n", priv->ndev->name);
519 return result;
520 }
521
522 islpci_set_state(priv, PRV_STATE_INIT);
523
524 /* Now that the device is 100% up, let's allow
525 * for the other interrupts --
Dmitry Torokhov93b2dd12006-10-08 00:38:15 -0400526 * NOTE: this is not *yet* true since we've only allowed the
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 * INIT interrupt on the IRQ line. We can perhaps poll
528 * the IRQ line until we know for sure the reset went through */
529 isl38xx_enable_common_interrupts(priv->device_base);
530
531 down_write(&priv->mib_sem);
532 result = mgt_commit(priv);
533 if (result) {
534 printk(KERN_ERR "%s: interface reset failure\n", priv->ndev->name);
535 up_write(&priv->mib_sem);
536 return result;
537 }
538 up_write(&priv->mib_sem);
539
540 islpci_set_state(priv, PRV_STATE_READY);
541
542 printk(KERN_DEBUG "%s: interface reset complete\n", priv->ndev->name);
543 return 0;
544}
545
546int
547islpci_reset(islpci_private *priv, int reload_firmware)
548{
549 isl38xx_control_block *cb = /* volatile not needed */
550 (isl38xx_control_block *) priv->control_block;
551 unsigned counter;
552 int rc;
553
554 if (reload_firmware)
555 islpci_set_state(priv, PRV_STATE_PREBOOT);
556 else
557 islpci_set_state(priv, PRV_STATE_POSTBOOT);
558
559 printk(KERN_DEBUG "%s: resetting device...\n", priv->ndev->name);
560
561 /* disable all device interrupts in case they weren't */
562 isl38xx_disable_interrupts(priv->device_base);
563
564 /* flush all management queues */
565 priv->index_mgmt_tx = 0;
566 priv->index_mgmt_rx = 0;
567
568 /* clear the indexes in the frame pointer */
569 for (counter = 0; counter < ISL38XX_CB_QCOUNT; counter++) {
570 cb->driver_curr_frag[counter] = cpu_to_le32(0);
571 cb->device_curr_frag[counter] = cpu_to_le32(0);
572 }
573
574 /* reset the mgmt receive queue */
575 for (counter = 0; counter < ISL38XX_CB_MGMT_QSIZE; counter++) {
576 isl38xx_fragment *frag = &cb->rx_data_mgmt[counter];
577 frag->size = cpu_to_le16(MGMT_FRAME_SIZE);
578 frag->flags = 0;
579 frag->address = cpu_to_le32(priv->mgmt_rx[counter].pci_addr);
580 }
581
582 for (counter = 0; counter < ISL38XX_CB_RX_QSIZE; counter++) {
583 cb->rx_data_low[counter].address =
584 cpu_to_le32((u32) priv->pci_map_rx_address[counter]);
585 }
586
587 /* since the receive queues are filled with empty fragments, now we can
588 * set the corresponding indexes in the Control Block */
589 priv->control_block->driver_curr_frag[ISL38XX_CB_RX_DATA_LQ] =
590 cpu_to_le32(ISL38XX_CB_RX_QSIZE);
591 priv->control_block->driver_curr_frag[ISL38XX_CB_RX_MGMTQ] =
592 cpu_to_le32(ISL38XX_CB_MGMT_QSIZE);
593
594 /* reset the remaining real index registers and full flags */
595 priv->free_data_rx = 0;
596 priv->free_data_tx = 0;
597 priv->data_low_tx_full = 0;
598
599 if (reload_firmware) { /* Should we load the firmware ? */
600 /* now that the data structures are cleaned up, upload
601 * firmware and reset interface */
602 rc = islpci_upload_fw(priv);
603 if (rc) {
604 printk(KERN_ERR "%s: islpci_reset: failure\n",
605 priv->ndev->name);
606 return rc;
607 }
608 }
609
610 /* finally reset interface */
611 rc = islpci_reset_if(priv);
612 if (rc)
613 printk(KERN_ERR "prism54: Your card/socket may be faulty, or IRQ line too busy :(\n");
614 return rc;
615}
616
617static struct net_device_stats *
618islpci_statistics(struct net_device *ndev)
619{
620 islpci_private *priv = netdev_priv(ndev);
621
622#if VERBOSE > SHOW_ERROR_MESSAGES
623 DEBUG(SHOW_FUNCTION_CALLS, "islpci_statistics\n");
624#endif
625
626 return &priv->statistics;
627}
628
629/******************************************************************************
630 Network device configuration functions
631******************************************************************************/
632static int
633islpci_alloc_memory(islpci_private *priv)
634{
635 int counter;
636
637#if VERBOSE > SHOW_ERROR_MESSAGES
638 printk(KERN_DEBUG "islpci_alloc_memory\n");
639#endif
640
641 /* remap the PCI device base address to accessable */
642 if (!(priv->device_base =
643 ioremap(pci_resource_start(priv->pdev, 0),
644 ISL38XX_PCI_MEM_SIZE))) {
645 /* error in remapping the PCI device memory address range */
646 printk(KERN_ERR "PCI memory remapping failed \n");
647 return -1;
648 }
649
650 /* memory layout for consistent DMA region:
651 *
652 * Area 1: Control Block for the device interface
653 * Area 2: Power Save Mode Buffer for temporary frame storage. Be aware that
654 * the number of supported stations in the AP determines the minimal
655 * size of the buffer !
656 */
657
658 /* perform the allocation */
659 priv->driver_mem_address = pci_alloc_consistent(priv->pdev,
660 HOST_MEM_BLOCK,
661 &priv->
662 device_host_address);
663
664 if (!priv->driver_mem_address) {
665 /* error allocating the block of PCI memory */
666 printk(KERN_ERR "%s: could not allocate DMA memory, aborting!",
667 "prism54");
668 return -1;
669 }
670
671 /* assign the Control Block to the first address of the allocated area */
672 priv->control_block =
673 (isl38xx_control_block *) priv->driver_mem_address;
674
675 /* set the Power Save Buffer pointer directly behind the CB */
676 priv->device_psm_buffer =
677 priv->device_host_address + CONTROL_BLOCK_SIZE;
678
679 /* make sure all buffer pointers are initialized */
680 for (counter = 0; counter < ISL38XX_CB_QCOUNT; counter++) {
681 priv->control_block->driver_curr_frag[counter] = cpu_to_le32(0);
682 priv->control_block->device_curr_frag[counter] = cpu_to_le32(0);
683 }
684
685 priv->index_mgmt_rx = 0;
686 memset(priv->mgmt_rx, 0, sizeof(priv->mgmt_rx));
687 memset(priv->mgmt_tx, 0, sizeof(priv->mgmt_tx));
688
689 /* allocate rx queue for management frames */
690 if (islpci_mgmt_rx_fill(priv->ndev) < 0)
691 goto out_free;
692
693 /* now get the data rx skb's */
694 memset(priv->data_low_rx, 0, sizeof (priv->data_low_rx));
695 memset(priv->pci_map_rx_address, 0, sizeof (priv->pci_map_rx_address));
696
697 for (counter = 0; counter < ISL38XX_CB_RX_QSIZE; counter++) {
698 struct sk_buff *skb;
699
700 /* allocate an sk_buff for received data frames storage
701 * each frame on receive size consists of 1 fragment
702 * include any required allignment operations */
703 if (!(skb = dev_alloc_skb(MAX_FRAGMENT_SIZE_RX + 2))) {
704 /* error allocating an sk_buff structure elements */
705 printk(KERN_ERR "Error allocating skb.\n");
706 skb = NULL;
707 goto out_free;
708 }
709 skb_reserve(skb, (4 - (long) skb->data) & 0x03);
710 /* add the new allocated sk_buff to the buffer array */
711 priv->data_low_rx[counter] = skb;
712
713 /* map the allocated skb data area to pci */
714 priv->pci_map_rx_address[counter] =
715 pci_map_single(priv->pdev, (void *) skb->data,
716 MAX_FRAGMENT_SIZE_RX + 2,
717 PCI_DMA_FROMDEVICE);
718 if (!priv->pci_map_rx_address[counter]) {
719 /* error mapping the buffer to device
720 accessable memory address */
721 printk(KERN_ERR "failed to map skb DMA'able\n");
722 goto out_free;
723 }
724 }
725
726 prism54_acl_init(&priv->acl);
Dan Williamseab411f2006-07-17 21:21:47 -0400727 prism54_wpa_bss_ie_init(priv);
Dmitry Torokhov93b2dd12006-10-08 00:38:15 -0400728 if (mgt_init(priv))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 goto out_free;
730
731 return 0;
732 out_free:
733 islpci_free_memory(priv);
734 return -1;
735}
736
737int
738islpci_free_memory(islpci_private *priv)
739{
740 int counter;
741
742 if (priv->device_base)
743 iounmap(priv->device_base);
744 priv->device_base = NULL;
745
746 /* free consistent DMA area... */
747 if (priv->driver_mem_address)
748 pci_free_consistent(priv->pdev, HOST_MEM_BLOCK,
749 priv->driver_mem_address,
750 priv->device_host_address);
751
752 /* clear some dangling pointers */
753 priv->driver_mem_address = NULL;
754 priv->device_host_address = 0;
755 priv->device_psm_buffer = 0;
756 priv->control_block = NULL;
757
758 /* clean up mgmt rx buffers */
759 for (counter = 0; counter < ISL38XX_CB_MGMT_QSIZE; counter++) {
760 struct islpci_membuf *buf = &priv->mgmt_rx[counter];
761 if (buf->pci_addr)
762 pci_unmap_single(priv->pdev, buf->pci_addr,
763 buf->size, PCI_DMA_FROMDEVICE);
764 buf->pci_addr = 0;
Jesper Juhlb4558ea2005-10-28 16:53:13 -0400765 kfree(buf->mem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 buf->size = 0;
767 buf->mem = NULL;
768 }
769
770 /* clean up data rx buffers */
771 for (counter = 0; counter < ISL38XX_CB_RX_QSIZE; counter++) {
772 if (priv->pci_map_rx_address[counter])
773 pci_unmap_single(priv->pdev,
774 priv->pci_map_rx_address[counter],
775 MAX_FRAGMENT_SIZE_RX + 2,
776 PCI_DMA_FROMDEVICE);
777 priv->pci_map_rx_address[counter] = 0;
778
779 if (priv->data_low_rx[counter])
780 dev_kfree_skb(priv->data_low_rx[counter]);
781 priv->data_low_rx[counter] = NULL;
782 }
783
784 /* Free the acces control list and the WPA list */
785 prism54_acl_clean(&priv->acl);
Dan Williamseab411f2006-07-17 21:21:47 -0400786 prism54_wpa_bss_ie_clean(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 mgt_clean(priv);
788
789 return 0;
790}
791
792#if 0
793static void
794islpci_set_multicast_list(struct net_device *dev)
795{
796 /* put device into promisc mode and let network layer handle it */
797}
798#endif
799
Kai Engertff86a542006-12-12 21:09:41 +0100800static void islpci_ethtool_get_drvinfo(struct net_device *dev,
801 struct ethtool_drvinfo *info)
802{
803 strcpy(info->driver, DRV_NAME);
804 strcpy(info->version, DRV_VERSION);
805}
806
Stephen Hemminger6685254f2009-03-20 19:36:34 +0000807static const struct ethtool_ops islpci_ethtool_ops = {
Kai Engertff86a542006-12-12 21:09:41 +0100808 .get_drvinfo = islpci_ethtool_get_drvinfo,
809};
810
Stephen Hemminger6685254f2009-03-20 19:36:34 +0000811static const struct net_device_ops islpci_netdev_ops = {
812 .ndo_open = islpci_open,
813 .ndo_stop = islpci_close,
814 .ndo_get_stats = islpci_statistics,
815 .ndo_do_ioctl = prism54_ioctl,
816 .ndo_start_xmit = islpci_eth_transmit,
817 .ndo_tx_timeout = islpci_eth_tx_timeout,
818 .ndo_set_mac_address = prism54_set_mac_address,
819 .ndo_change_mtu = eth_change_mtu,
820 .ndo_set_mac_address = eth_mac_addr,
821 .ndo_validate_addr = eth_validate_addr,
822};
823
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824struct net_device *
825islpci_setup(struct pci_dev *pdev)
826{
827 islpci_private *priv;
828 struct net_device *ndev = alloc_etherdev(sizeof (islpci_private));
829
830 if (!ndev)
831 return ndev;
832
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 pci_set_drvdata(pdev, ndev);
834#if defined(SET_NETDEV_DEV)
835 SET_NETDEV_DEV(ndev, &pdev->dev);
836#endif
837
838 /* setup the structure members */
839 ndev->base_addr = pci_resource_start(pdev, 0);
840 ndev->irq = pdev->irq;
841
842 /* initialize the function pointers */
Stephen Hemminger6685254f2009-03-20 19:36:34 +0000843 ndev->netdev_ops = &islpci_netdev_ops;
844 ndev->wireless_handlers = &prism54_handler_def;
Kai Engertff86a542006-12-12 21:09:41 +0100845 ndev->ethtool_ops = &islpci_ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 /* ndev->set_multicast_list = &islpci_set_multicast_list; */
848 ndev->addr_len = ETH_ALEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 /* Get a non-zero dummy MAC address for nameif. Jean II */
850 memcpy(ndev->dev_addr, dummy_mac, 6);
851
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852 ndev->watchdog_timeo = ISLPCI_TX_TIMEOUT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853
854 /* allocate a private device structure to the network device */
855 priv = netdev_priv(ndev);
856 priv->ndev = ndev;
857 priv->pdev = pdev;
858 priv->monitor_type = ARPHRD_IEEE80211;
859 priv->ndev->type = (priv->iw_mode == IW_MODE_MONITOR) ?
860 priv->monitor_type : ARPHRD_ETHER;
861
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 /* Add pointers to enable iwspy support. */
863 priv->wireless_data.spy_data = &priv->spy_data;
864 ndev->wireless_data = &priv->wireless_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865
866 /* save the start and end address of the PCI memory area */
867 ndev->mem_start = (unsigned long) priv->device_base;
868 ndev->mem_end = ndev->mem_start + ISL38XX_PCI_MEM_SIZE;
869
870#if VERBOSE > SHOW_ERROR_MESSAGES
871 DEBUG(SHOW_TRACING, "PCI Memory remapped to 0x%p\n", priv->device_base);
872#endif
873
874 init_waitqueue_head(&priv->reset_done);
875
876 /* init the queue read locks, process wait counter */
Matthias Kaehlcke1b34fd32007-11-05 09:41:01 +0100877 mutex_init(&priv->mgmt_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 priv->mgmt_received = NULL;
879 init_waitqueue_head(&priv->mgmt_wqueue);
Matthias Kaehlckef8139212008-02-15 20:56:59 +0100880 mutex_init(&priv->stats_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 spin_lock_init(&priv->slock);
882
883 /* init state machine with off#1 state */
884 priv->state = PRV_STATE_OFF;
885 priv->state_off = 1;
886
887 /* initialize workqueue's */
David Howellsc4028952006-11-22 14:57:56 +0000888 INIT_WORK(&priv->stats_work, prism54_update_stats);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 priv->stats_timestamp = 0;
890
David Howellsc4028952006-11-22 14:57:56 +0000891 INIT_WORK(&priv->reset_task, islpci_do_reset_and_wake);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 priv->reset_task_pending = 0;
893
894 /* allocate various memory areas */
895 if (islpci_alloc_memory(priv))
896 goto do_free_netdev;
897
898 /* select the firmware file depending on the device id */
899 switch (pdev->device) {
900 case 0x3877:
901 strcpy(priv->firmware, ISL3877_IMAGE_FILE);
902 break;
903
904 case 0x3886:
905 strcpy(priv->firmware, ISL3886_IMAGE_FILE);
906 break;
907
908 default:
909 strcpy(priv->firmware, ISL3890_IMAGE_FILE);
910 break;
911 }
912
913 if (register_netdev(ndev)) {
914 DEBUG(SHOW_ERROR_MESSAGES,
915 "ERROR: register_netdev() failed \n");
916 goto do_islpci_free_memory;
917 }
918
919 return ndev;
920
921 do_islpci_free_memory:
922 islpci_free_memory(priv);
923 do_free_netdev:
924 pci_set_drvdata(pdev, NULL);
925 free_netdev(ndev);
926 priv = NULL;
927 return NULL;
928}
929
930islpci_state_t
931islpci_set_state(islpci_private *priv, islpci_state_t new_state)
932{
933 islpci_state_t old_state;
934
935 /* lock */
936 old_state = priv->state;
937
938 /* this means either a race condition or some serious error in
939 * the driver code */
940 switch (new_state) {
941 case PRV_STATE_OFF:
942 priv->state_off++;
943 default:
944 priv->state = new_state;
945 break;
946
947 case PRV_STATE_PREBOOT:
948 /* there are actually many off-states, enumerated by
949 * state_off */
950 if (old_state == PRV_STATE_OFF)
951 priv->state_off--;
952
953 /* only if hw_unavailable is zero now it means we either
954 * were in off#1 state, or came here from
955 * somewhere else */
956 if (!priv->state_off)
957 priv->state = new_state;
958 break;
959 };
960#if 0
961 printk(KERN_DEBUG "%s: state transition %d -> %d (off#%d)\n",
962 priv->ndev->name, old_state, new_state, priv->state_off);
963#endif
964
965 /* invariants */
966 BUG_ON(priv->state_off < 0);
967 BUG_ON(priv->state_off && (priv->state != PRV_STATE_OFF));
968 BUG_ON(!priv->state_off && (priv->state == PRV_STATE_OFF));
969
970 /* unlock */
971 return old_state;
972}