Merge branch 'sched-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[firefly-linux-kernel-4.4.55.git] / drivers / staging / wlags49_h2 / wl_netdev.c
1 /*******************************************************************************
2  * Agere Systems Inc.
3  * Wireless device driver for Linux (wlags49).
4  *
5  * Copyright (c) 1998-2003 Agere Systems Inc.
6  * All rights reserved.
7  *   http://www.agere.com
8  *
9  * Initially developed by TriplePoint, Inc.
10  *   http://www.triplepoint.com
11  *
12  *------------------------------------------------------------------------------
13  *
14  *   This file contains handler functions registered with the net_device
15  *   structure.
16  *
17  *------------------------------------------------------------------------------
18  *
19  * SOFTWARE LICENSE
20  *
21  * This software is provided subject to the following terms and conditions,
22  * which you should read carefully before using the software.  Using this
23  * software indicates your acceptance of these terms and conditions.  If you do
24  * not agree with these terms and conditions, do not use the software.
25  *
26  * Copyright © 2003 Agere Systems Inc.
27  * All rights reserved.
28  *
29  * Redistribution and use in source or binary forms, with or without
30  * modifications, are permitted provided that the following conditions are met:
31  *
32  * . Redistributions of source code must retain the above copyright notice, this
33  *    list of conditions and the following Disclaimer as comments in the code as
34  *    well as in the documentation and/or other materials provided with the
35  *    distribution.
36  *
37  * . Redistributions in binary form must reproduce the above copyright notice,
38  *    this list of conditions and the following Disclaimer in the documentation
39  *    and/or other materials provided with the distribution.
40  *
41  * . Neither the name of Agere Systems Inc. nor the names of the contributors
42  *    may be used to endorse or promote products derived from this software
43  *    without specific prior written permission.
44  *
45  * Disclaimer
46  *
47  * THIS SOFTWARE IS PROVIDED \93AS IS\94 AND ANY EXPRESS OR IMPLIED WARRANTIES,
48  * INCLUDING, BUT NOT LIMITED TO, INFRINGEMENT AND THE IMPLIED WARRANTIES OF
49  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  ANY
50  * USE, MODIFICATION OR DISTRIBUTION OF THIS SOFTWARE IS SOLELY AT THE USERS OWN
51  * RISK. IN NO EVENT SHALL AGERE SYSTEMS INC. OR CONTRIBUTORS BE LIABLE FOR ANY
52  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
53  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
54  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
55  * ON ANY THEORY OF LIABILITY, INCLUDING, BUT NOT LIMITED TO, CONTRACT, STRICT
56  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
57  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
58  * DAMAGE.
59  *
60  ******************************************************************************/
61
62 /*******************************************************************************
63  * include files
64  ******************************************************************************/
65 #include <wl_version.h>
66
67 #include <linux/module.h>
68 #include <linux/slab.h>
69 #include <linux/types.h>
70 #include <linux/kernel.h>
71 #include <linux/netdevice.h>
72 #include <linux/ethtool.h>
73 #include <linux/etherdevice.h>
74
75 #include <debug.h>
76
77 #include <hcf.h>
78 #include <dhf.h>
79
80 #include <wl_if.h>
81 #include <wl_internal.h>
82 #include <wl_util.h>
83 #include <wl_priv.h>
84 #include <wl_main.h>
85 #include <wl_netdev.h>
86 #include <wl_wext.h>
87
88 #ifdef USE_PROFILE
89 #include <wl_profile.h>
90 #endif /* USE_PROFILE */
91
92 #ifdef BUS_PCMCIA
93 #include <wl_cs.h>
94 #endif /* BUS_PCMCIA */
95
96 #ifdef BUS_PCI
97 #include <wl_pci.h>
98 #endif /* BUS_PCI */
99
100 #if HCF_ENCAP
101 #define MTU_MAX (HCF_MAX_MSG - ETH_HLEN - 8)
102 #else
103 #define MTU_MAX (HCF_MAX_MSG - ETH_HLEN)
104 #endif
105
106 /*******************************************************************************
107  * macros
108  ******************************************************************************/
109 #define BLOCK_INPUT(buf, len) \
110         do { \
111                 desc->buf_addr = buf; \
112                 desc->BUF_SIZE = len; \
113                 status = hcf_rcv_msg(&(lp->hcfCtx), desc, 0); \
114         } while (0)
115
116 #define BLOCK_INPUT_DMA(buf, len) memcpy( buf, desc_next->buf_addr, pktlen )
117
118 /*******************************************************************************
119  * function prototypes
120  ******************************************************************************/
121
122 /*******************************************************************************
123  *      wl_init()
124  *******************************************************************************
125  *
126  *  DESCRIPTION:
127  *
128  *      We never need to do anything when a "Wireless" device is "initialized"
129  *  by the net software, because we only register already-found cards.
130  *
131  *  PARAMETERS:
132  *
133  *      dev - a pointer to the device's net_device structure
134  *
135  *  RETURNS:
136  *
137  *      0 on success
138  *      errno value otherwise
139  *
140  ******************************************************************************/
141 int wl_init(struct net_device *dev)
142 {
143         DBG_PARAM(DbgInfo, "dev", "%s (0x%p)", dev->name, dev);
144         return 0;
145 }                               /* wl_init */
146
147 /*============================================================================*/
148
149 /*******************************************************************************
150  *      wl_config()
151  *******************************************************************************
152  *
153  *  DESCRIPTION:
154  *
155  *      Implement the SIOCSIFMAP interface.
156  *
157  *  PARAMETERS:
158  *
159  *      dev - a pointer to the device's net_device structure
160  *      map - a pointer to the device's ifmap structure
161  *
162  *  RETURNS:
163  *
164  *      0 on success
165  *      errno otherwise
166  *
167  ******************************************************************************/
168 int wl_config(struct net_device *dev, struct ifmap *map)
169 {
170         DBG_PARAM(DbgInfo, "dev", "%s (0x%p)", dev->name, dev);
171         DBG_PARAM(DbgInfo, "map", "0x%p", map);
172
173         /*
174          * The only thing we care about here is a port change.
175          * Since this not needed, ignore the request. 
176          */
177         DBG_TRACE(DbgInfo, "%s: %s called.\n", dev->name, __func__);
178
179         return 0;
180 }                               /* wl_config */
181
182 /*============================================================================*/
183
184 /*******************************************************************************
185  *      wl_stats()
186  *******************************************************************************
187  *
188  *  DESCRIPTION:
189  *
190  *      Return the current device statistics.
191  *
192  *  PARAMETERS:
193  *
194  *      dev - a pointer to the device's net_device structure
195  *
196  *  RETURNS:
197  *
198  *      a pointer to a net_device_stats structure containing the network
199  *      statistics.
200  *
201  ******************************************************************************/
202 struct net_device_stats *wl_stats(struct net_device *dev)
203 {
204 #ifdef USE_WDS
205         int count;
206 #endif /* USE_WDS */
207         unsigned long flags;
208         struct net_device_stats *pStats;
209         struct wl_private *lp = wl_priv(dev);
210
211         /*DBG_PARAM( DbgInfo, "dev", "%s (0x%p)", dev->name, dev ); */
212
213         pStats = NULL;
214
215         wl_lock(lp, &flags);
216
217 #ifdef USE_RTS
218         if (lp->useRTS == 1) {
219                 wl_unlock(lp, &flags);
220                 return NULL;
221         }
222 #endif /* USE_RTS */
223
224         /* Return the statistics for the appropriate device */
225 #ifdef USE_WDS
226
227         for (count = 0; count < NUM_WDS_PORTS; count++) {
228                 if (dev == lp->wds_port[count].dev)
229                         pStats = &(lp->wds_port[count].stats);
230         }
231
232 #endif /* USE_WDS */
233
234         /* If pStats is still NULL, then the device is not a WDS port */
235         if (pStats == NULL)
236                 pStats = &(lp->stats);
237
238         wl_unlock(lp, &flags);
239
240         return pStats;
241 }                               /* wl_stats */
242
243 /*============================================================================*/
244
245 /*******************************************************************************
246  *      wl_open()
247  *******************************************************************************
248  *
249  *  DESCRIPTION:
250  *
251  *      Open the device.
252  *
253  *  PARAMETERS:
254  *
255  *      dev - a pointer to the device's net_device structure
256  *
257  *  RETURNS:
258  *
259  *      0 on success
260  *      errno otherwise
261  *
262  ******************************************************************************/
263 int wl_open(struct net_device *dev)
264 {
265         int status = HCF_SUCCESS;
266         struct wl_private *lp = wl_priv(dev);
267         unsigned long flags;
268
269         wl_lock(lp, &flags);
270
271 #ifdef USE_RTS
272         if (lp->useRTS == 1) {
273                 DBG_TRACE(DbgInfo, "Skipping device open, in RTS mode\n");
274                 wl_unlock(lp, &flags);
275                 return -EIO;
276         }
277 #endif /* USE_RTS */
278
279 #ifdef USE_PROFILE
280         parse_config(dev);
281 #endif
282
283         if (lp->portState == WVLAN_PORT_STATE_DISABLED) {
284                 DBG_TRACE(DbgInfo, "Enabling Port 0\n");
285                 status = wl_enable(lp);
286
287                 if (status != HCF_SUCCESS) {
288                         DBG_TRACE(DbgInfo, "Enable port 0 failed: 0x%x\n",
289                                   status);
290                 }
291         }
292
293         /* Holding the lock too long, make a gap to allow other processes */
294         wl_unlock(lp, &flags);
295         wl_lock(lp, &flags);
296
297         if (strlen(lp->fw_image_filename)) {
298                 DBG_TRACE(DbgInfo, ";???? Kludgy way to force a download\n");
299                 status = wl_go(lp);
300         } else {
301                 status = wl_apply(lp);
302         }
303
304         /* Holding the lock too long, make a gap to allow other processes */
305         wl_unlock(lp, &flags);
306         wl_lock(lp, &flags);
307
308         /* Unsuccessful, try reset of the card to recover */
309         if (status != HCF_SUCCESS)
310                 status = wl_reset(dev);
311
312         /* Holding the lock too long, make a gap to allow other processes */
313         wl_unlock(lp, &flags);
314         wl_lock(lp, &flags);
315
316         if (status == HCF_SUCCESS) {
317                 netif_carrier_on(dev);
318                 WL_WDS_NETIF_CARRIER_ON(lp);
319
320                 /* Start handling interrupts */
321                 lp->is_handling_int = WL_HANDLING_INT;
322                 wl_act_int_on(lp);
323
324                 netif_start_queue(dev);
325                 WL_WDS_NETIF_START_QUEUE(lp);
326         } else {
327                 wl_hcf_error(dev, status);      /* Report the error */
328                 netif_device_detach(dev);       /* Stop the device and queue */
329         }
330
331         wl_unlock(lp, &flags);
332
333         return status;
334 }                               /* wl_open */
335
336 /*============================================================================*/
337
338 /*******************************************************************************
339  *      wl_close()
340  *******************************************************************************
341  *
342  *  DESCRIPTION:
343  *
344  *      Close the device.
345  *
346  *  PARAMETERS:
347  *
348  *      dev - a pointer to the device's net_device structure
349  *
350  *  RETURNS:
351  *
352  *      0 on success
353  *      errno otherwise
354  *
355  ******************************************************************************/
356 int wl_close(struct net_device *dev)
357 {
358         struct wl_private *lp = wl_priv(dev);
359         unsigned long flags;
360
361         DBG_PARAM(DbgInfo, "dev", "%s (0x%p)", dev->name, dev);
362
363         /* Mark the adapter as busy */
364         netif_stop_queue(dev);
365         WL_WDS_NETIF_STOP_QUEUE(lp);
366
367         netif_carrier_off(dev);
368         WL_WDS_NETIF_CARRIER_OFF(lp);
369
370         /*
371          * Shutdown the adapter:
372          * Disable adapter interrupts
373          * Stop Tx/Rx
374          * Update statistics
375          * Set low power mode
376          */
377
378         wl_lock(lp, &flags);
379
380         wl_act_int_off(lp);
381         /* Stop handling interrupts */
382         lp->is_handling_int = WL_NOT_HANDLING_INT;
383
384 #ifdef USE_RTS
385         if (lp->useRTS == 1) {
386                 DBG_TRACE(DbgInfo, "Skipping device close, in RTS mode\n");
387                 wl_unlock(lp, &flags);
388                 return -EIO;
389         }
390 #endif /* USE_RTS */
391
392         /* Disable the ports */
393         wl_disable(lp);
394
395         wl_unlock(lp, &flags);
396
397         return 0;
398 }                               /* wl_close */
399
400 /*============================================================================*/
401
402 static void wl_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
403 {
404         strlcpy(info->driver, DRIVER_NAME, sizeof(info->driver));
405         strlcpy(info->version, DRV_VERSION_STR, sizeof(info->version));
406
407         if (dev->dev.parent) {
408                 dev_set_name(dev->dev.parent, "%s", info->bus_info);
409         } else {
410                 snprintf(info->bus_info, sizeof(info->bus_info),
411                          "PCMCIA FIXME");
412         }
413 }                               /* wl_get_drvinfo */
414
415 static struct ethtool_ops wl_ethtool_ops = {
416         .get_drvinfo = wl_get_drvinfo,
417         .get_link = ethtool_op_get_link,
418 };
419
420 /*******************************************************************************
421  *      wl_ioctl()
422  *******************************************************************************
423  *
424  *  DESCRIPTION:
425  *
426  *      The IOCTL handler for the device.
427  *
428  *  PARAMETERS:
429  *
430  *      dev - a pointer to the device's net_device struct.
431  *      rq  - a pointer to the IOCTL request buffer.
432  *      cmd - the IOCTL command code.
433  *
434  *  RETURNS:
435  *
436  *      0 on success
437  *      errno value otherwise
438  *
439  ******************************************************************************/
440 int wl_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
441 {
442         struct wl_private *lp = wl_priv(dev);
443         unsigned long flags;
444         int ret = 0;
445
446         DBG_PARAM(DbgInfo, "dev", "%s (0x%p)", dev->name, dev);
447         DBG_PARAM(DbgInfo, "rq", "0x%p", rq);
448         DBG_PARAM(DbgInfo, "cmd", "0x%04x", cmd);
449
450         wl_lock(lp, &flags);
451
452         wl_act_int_off(lp);
453
454 #ifdef USE_RTS
455         if (lp->useRTS == 1) {
456                 /* Handle any RTS IOCTL here */
457                 if (cmd == WL_IOCTL_RTS) {
458                         DBG_TRACE(DbgInfo, "IOCTL: WL_IOCTL_RTS\n");
459                         ret = wvlan_rts((struct rtsreq *)rq, dev->base_addr);
460                 } else {
461                         DBG_TRACE(DbgInfo,
462                                   "IOCTL not supported in RTS mode: 0x%X\n",
463                                   cmd);
464                         ret = -EOPNOTSUPP;
465                 }
466
467                 goto out_act_int_on_unlock;
468         }
469 #endif /* USE_RTS */
470
471         /* Only handle UIL IOCTL requests when the UIL has the system blocked. */
472         if (!((lp->flags & WVLAN2_UIL_BUSY) && (cmd != WVLAN2_IOCTL_UIL))) {
473 #ifdef USE_UIL
474                 struct uilreq *urq = (struct uilreq *)rq;
475 #endif /* USE_UIL */
476
477                 switch (cmd) {
478                         /* ================== Private IOCTLs (up to 16) ================== */
479 #ifdef USE_UIL
480                 case WVLAN2_IOCTL_UIL:
481                         DBG_TRACE(DbgInfo, "IOCTL: WVLAN2_IOCTL_UIL\n");
482                         ret = wvlan_uil(urq, lp);
483                         break;
484 #endif /* USE_UIL */
485
486                 default:
487                         DBG_TRACE(DbgInfo, "IOCTL CODE NOT SUPPORTED: 0x%X\n",
488                                   cmd);
489                         ret = -EOPNOTSUPP;
490                         break;
491                 }
492         } else {
493                 DBG_WARNING(DbgInfo,
494                             "DEVICE IS BUSY, CANNOT PROCESS REQUEST\n");
495                 ret = -EBUSY;
496         }
497
498 #ifdef USE_RTS
499 out_act_int_on_unlock:
500 #endif /* USE_RTS */
501         wl_act_int_on(lp);
502
503         wl_unlock(lp, &flags);
504
505         return ret;
506 }                               /* wl_ioctl */
507
508 /*============================================================================*/
509
510 #ifdef CONFIG_NET_POLL_CONTROLLER
511 static void wl_poll(struct net_device *dev)
512 {
513         struct wl_private *lp = wl_priv(dev);
514         unsigned long flags;
515         struct pt_regs regs;
516
517         wl_lock(lp, &flags);
518         wl_isr(dev->irq, dev, &regs);
519         wl_unlock(lp, &flags);
520 }
521 #endif
522
523 /*******************************************************************************
524  *      wl_tx_timeout()
525  *******************************************************************************
526  *
527  *  DESCRIPTION:
528  *
529  *      The handler called when, for some reason, a Tx request is not completed.
530  *
531  *  PARAMETERS:
532  *
533  *      dev - a pointer to the device's net_device struct.
534  *
535  *  RETURNS:
536  *
537  *      N/A
538  *
539  ******************************************************************************/
540 void wl_tx_timeout(struct net_device *dev)
541 {
542 #ifdef USE_WDS
543         int count;
544 #endif /* USE_WDS */
545         unsigned long flags;
546         struct wl_private *lp = wl_priv(dev);
547         struct net_device_stats *pStats = NULL;
548
549         DBG_WARNING(DbgInfo, "%s: Transmit timeout.\n", dev->name);
550
551         wl_lock(lp, &flags);
552
553 #ifdef USE_RTS
554         if (lp->useRTS == 1) {
555                 DBG_TRACE(DbgInfo,
556                           "Skipping tx_timeout handler, in RTS mode\n");
557                 wl_unlock(lp, &flags);
558                 return;
559         }
560 #endif /* USE_RTS */
561
562         /* Figure out which device (the "root" device or WDS port) this timeout
563            is for */
564 #ifdef USE_WDS
565
566         for (count = 0; count < NUM_WDS_PORTS; count++) {
567                 if (dev == lp->wds_port[count].dev) {
568                         pStats = &(lp->wds_port[count].stats);
569
570                         /* Break the loop so that we can use the counter to access WDS
571                            information in the private structure */
572                         break;
573                 }
574         }
575
576 #endif /* USE_WDS */
577
578         /* If pStats is still NULL, then the device is not a WDS port */
579         if (pStats == NULL)
580                 pStats = &(lp->stats);
581
582         /* Accumulate the timeout error */
583         pStats->tx_errors++;
584
585         wl_unlock(lp, &flags);
586 }                               /* wl_tx_timeout */
587
588 /*============================================================================*/
589
590 /*******************************************************************************
591  *      wl_send()
592  *******************************************************************************
593  *
594  *  DESCRIPTION:
595  *
596  *      The routine which performs data transmits.
597  *
598  *  PARAMETERS:
599  *
600  *      lp  - a pointer to the device's wl_private struct.
601  *
602  *  RETURNS:
603  *
604  *      0 on success
605  *      1 on error
606  *
607  ******************************************************************************/
608 int wl_send(struct wl_private *lp)
609 {
610
611         int status;
612         DESC_STRCT *desc;
613         WVLAN_LFRAME *txF = NULL;
614         struct list_head *element;
615         int len;
616     /*------------------------------------------------------------------------*/
617
618         if (lp == NULL) {
619                 DBG_ERROR(DbgInfo, "Private adapter struct is NULL\n");
620                 return FALSE;
621         }
622         if (lp->dev == NULL) {
623                 DBG_ERROR(DbgInfo, "net_device struct in wl_private is NULL\n");
624                 return FALSE;
625         }
626
627         /*
628          * Check for the availability of FIDs; if none are available,
629          * don't take any frames off the txQ
630          */
631         if (lp->hcfCtx.IFB_RscInd == 0)
632                 return FALSE;
633
634         /* Reclaim the TxQ Elements and place them back on the free queue */
635         if (!list_empty(&(lp->txQ[0]))) {
636                 element = lp->txQ[0].next;
637
638                 txF = (WVLAN_LFRAME *) list_entry(element, WVLAN_LFRAME, node);
639                 if (txF != NULL) {
640                         lp->txF.skb = txF->frame.skb;
641                         lp->txF.port = txF->frame.port;
642
643                         txF->frame.skb = NULL;
644                         txF->frame.port = 0;
645
646                         list_del(&(txF->node));
647                         list_add(element, &(lp->txFree));
648
649                         lp->txQ_count--;
650
651                         if (lp->txQ_count < TX_Q_LOW_WATER_MARK) {
652                                 if (lp->netif_queue_on == FALSE) {
653                                         DBG_TX(DbgInfo, "Kickstarting Q: %d\n",
654                                                lp->txQ_count);
655                                         netif_wake_queue(lp->dev);
656                                         WL_WDS_NETIF_WAKE_QUEUE(lp);
657                                         lp->netif_queue_on = TRUE;
658                                 }
659                         }
660                 }
661         }
662
663         if (lp->txF.skb == NULL)
664                 return FALSE;
665
666         /* If the device has resources (FIDs) available, then Tx the packet */
667         /* Format the TxRequest and send it to the adapter */
668         len = lp->txF.skb->len < ETH_ZLEN ? ETH_ZLEN : lp->txF.skb->len;
669
670         desc = &(lp->desc_tx);
671         desc->buf_addr = lp->txF.skb->data;
672         desc->BUF_CNT = len;
673         desc->next_desc_addr = NULL;
674
675         status = hcf_send_msg(&(lp->hcfCtx), desc, lp->txF.port);
676
677         if (status == HCF_SUCCESS) {
678                 lp->dev->trans_start = jiffies;
679
680                 DBG_TX(DbgInfo, "Transmit...\n");
681
682                 if (lp->txF.port == HCF_PORT_0) {
683                         lp->stats.tx_packets++;
684                         lp->stats.tx_bytes += lp->txF.skb->len;
685                 }
686 #ifdef USE_WDS
687                 else {
688                         lp->wds_port[((lp->txF.port >> 8) -
689                                       1)].stats.tx_packets++;
690                         lp->wds_port[((lp->txF.port >> 8) -
691                                       1)].stats.tx_bytes += lp->txF.skb->len;
692                 }
693
694 #endif /* USE_WDS */
695
696                 /* Free the skb and perform queue cleanup, as the buffer was
697                    transmitted successfully */
698                 dev_consume_skb_any( lp->txF.skb );
699
700                 lp->txF.skb = NULL;
701                 lp->txF.port = 0;
702         }
703
704         return TRUE;
705 }                               /* wl_send */
706
707 /*============================================================================*/
708
709 /*******************************************************************************
710  *      wl_tx()
711  *******************************************************************************
712  *
713  *  DESCRIPTION:
714  *
715  *      The Tx handler function for the network layer.
716  *
717  *  PARAMETERS:
718  *
719  *      skb - a pointer to the sk_buff structure containing the data to transfer.
720  *      dev - a pointer to the device's net_device structure.
721  *
722  *  RETURNS:
723  *
724  *      0 on success
725  *      1 on error
726  *
727  ******************************************************************************/
728 int wl_tx(struct sk_buff *skb, struct net_device *dev, int port)
729 {
730         unsigned long flags;
731         struct wl_private *lp = wl_priv(dev);
732         WVLAN_LFRAME *txF = NULL;
733         struct list_head *element;
734     /*------------------------------------------------------------------------*/
735
736         /* Grab the spinlock */
737         wl_lock(lp, &flags);
738
739         if (lp->flags & WVLAN2_UIL_BUSY) {
740                 DBG_WARNING(DbgInfo, "UIL has device blocked\n");
741                 /* Start dropping packets here??? */
742                 wl_unlock(lp, &flags);
743                 return 1;
744         }
745 #ifdef USE_RTS
746         if (lp->useRTS == 1) {
747                 DBG_PRINT("RTS: we're getting a Tx...\n");
748                 wl_unlock(lp, &flags);
749                 return 1;
750         }
751 #endif /* USE_RTS */
752
753         if (!lp->use_dma) {
754                 /* Get an element from the queue */
755                 element = lp->txFree.next;
756                 txF = (WVLAN_LFRAME *) list_entry(element, WVLAN_LFRAME, node);
757                 if (txF == NULL) {
758                         DBG_ERROR(DbgInfo, "Problem with list_entry\n");
759                         wl_unlock(lp, &flags);
760                         return 1;
761                 }
762                 /* Fill out the frame */
763                 txF->frame.skb = skb;
764                 txF->frame.port = port;
765                 /* Move the frame to the txQ */
766                 /* NOTE: Here's where we would do priority queueing */
767                 list_move(&(txF->node), &(lp->txQ[0]));
768
769                 lp->txQ_count++;
770                 if (lp->txQ_count >= DEFAULT_NUM_TX_FRAMES) {
771                         DBG_TX(DbgInfo, "Q Full: %d\n", lp->txQ_count);
772                         if (lp->netif_queue_on == TRUE) {
773                                 netif_stop_queue(lp->dev);
774                                 WL_WDS_NETIF_STOP_QUEUE(lp);
775                                 lp->netif_queue_on = FALSE;
776                         }
777                 }
778         }
779         wl_act_int_off(lp);     /* Disable Interrupts */
780
781         /* Send the data to the hardware using the appropriate method */
782 #ifdef ENABLE_DMA
783         if (lp->use_dma) {
784                 wl_send_dma(lp, skb, port);
785         } else
786 #endif
787         {
788                 wl_send(lp);
789         }
790         /* Re-enable Interrupts, release the spinlock and return */
791         wl_act_int_on(lp);
792         wl_unlock(lp, &flags);
793         return 0;
794 }                               /* wl_tx */
795
796 /*============================================================================*/
797
798 /*******************************************************************************
799  *      wl_rx()
800  *******************************************************************************
801  *
802  *  DESCRIPTION:
803  *
804  *      The routine which performs data reception.
805  *
806  *  PARAMETERS:
807  *
808  *      dev - a pointer to the device's net_device structure.
809  *
810  *  RETURNS:
811  *
812  *      0 on success
813  *      1 on error
814  *
815  ******************************************************************************/
816 int wl_rx(struct net_device *dev)
817 {
818         int port;
819         struct sk_buff *skb;
820         struct wl_private *lp = wl_priv(dev);
821         int status;
822         hcf_16 pktlen;
823         hcf_16 hfs_stat;
824         DESC_STRCT *desc;
825     /*------------------------------------------------------------------------*/
826
827         DBG_PARAM(DbgInfo, "dev", "%s (0x%p)", dev->name, dev);
828
829         if (!(lp->flags & WVLAN2_UIL_BUSY)) {
830
831 #ifdef USE_RTS
832                 if (lp->useRTS == 1) {
833                         DBG_PRINT("RTS: We're getting an Rx...\n");
834                         return -EIO;
835                 }
836 #endif /* USE_RTS */
837
838                 /* Read the HFS_STAT register from the lookahead buffer */
839                 hfs_stat = (hcf_16) ((lp->lookAheadBuf[HFS_STAT]) |
840                                      (lp->lookAheadBuf[HFS_STAT + 1] << 8));
841
842                 /* Make sure the frame isn't bad */
843                 if ((hfs_stat & HFS_STAT_ERR) != HCF_SUCCESS) {
844                         DBG_WARNING(DbgInfo,
845                                     "HFS_STAT_ERROR (0x%x) in Rx Packet\n",
846                                     lp->lookAheadBuf[HFS_STAT]);
847                         return -EIO;
848                 }
849
850                 /* Determine what port this packet is for */
851                 port = (hfs_stat >> 8) & 0x0007;
852                 DBG_RX(DbgInfo, "Rx frame for port %d\n", port);
853
854                 pktlen = lp->hcfCtx.IFB_RxLen;
855                 if (pktlen != 0) {
856                         skb = ALLOC_SKB(pktlen);
857                         if (skb != NULL) {
858                                 /* Set the netdev based on the port */
859                                 switch (port) {
860 #ifdef USE_WDS
861                                 case 1:
862                                 case 2:
863                                 case 3:
864                                 case 4:
865                                 case 5:
866                                 case 6:
867                                         skb->dev = lp->wds_port[port - 1].dev;
868                                         break;
869 #endif /* USE_WDS */
870
871                                 case 0:
872                                 default:
873                                         skb->dev = dev;
874                                         break;
875                                 }
876
877                                 desc = &(lp->desc_rx);
878
879                                 desc->next_desc_addr = NULL;
880
881 /*
882 #define BLOCK_INPUT(buf, len) \
883     desc->buf_addr = buf; \
884     desc->BUF_SIZE = len; \
885     status = hcf_rcv_msg(&(lp->hcfCtx), desc, 0)
886 */
887
888                                 GET_PACKET(skb->dev, skb, pktlen);
889
890                                 if (status == HCF_SUCCESS) {
891                                         netif_rx(skb);
892
893                                         if (port == 0) {
894                                                 lp->stats.rx_packets++;
895                                                 lp->stats.rx_bytes += pktlen;
896                                         }
897 #ifdef USE_WDS
898                                         else {
899                                                 lp->wds_port[port -
900                                                              1].stats.
901                                                     rx_packets++;
902                                                 lp->wds_port[port -
903                                                              1].stats.
904                                                     rx_bytes += pktlen;
905                                         }
906 #endif /* USE_WDS */
907
908                                         dev->last_rx = jiffies;
909
910 #ifdef WIRELESS_EXT
911 #ifdef WIRELESS_SPY
912                                         if (lp->spydata.spy_number > 0) {
913                                                 char *srcaddr =
914                                                     skb->mac.raw +
915                                                     MAC_ADDR_SIZE;
916
917                                                 wl_spy_gather(dev, srcaddr);
918                                         }
919 #endif /* WIRELESS_SPY */
920 #endif /* WIRELESS_EXT */
921                                 } else {
922                                         DBG_ERROR(DbgInfo,
923                                                   "Rx request to card FAILED\n");
924
925                                         if (port == 0)
926                                                 lp->stats.rx_dropped++;
927 #ifdef USE_WDS
928                                         else {
929                                                 lp->wds_port[port -
930                                                              1].stats.
931                                                     rx_dropped++;
932                                         }
933 #endif /* USE_WDS */
934
935                                         dev_kfree_skb(skb);
936                                 }
937                         } else {
938                                 DBG_ERROR(DbgInfo, "Could not alloc skb\n");
939
940                                 if (port == 0)
941                                         lp->stats.rx_dropped++;
942 #ifdef USE_WDS
943                                 else {
944                                         lp->wds_port[port -
945                                                      1].stats.rx_dropped++;
946                                 }
947 #endif /* USE_WDS */
948                         }
949                 }
950         }
951
952         return 0;
953 }                               /* wl_rx */
954
955 /*============================================================================*/
956
957 /*******************************************************************************
958  *      wl_multicast()
959  *******************************************************************************
960  *
961  *  DESCRIPTION:
962  *
963  *      Function to handle multicast packets
964  *
965  *  PARAMETERS:
966  *
967  *      dev - a pointer to the device's net_device structure.
968  *
969  *  RETURNS:
970  *
971  *      N/A
972  *
973  ******************************************************************************/
974 #ifdef NEW_MULTICAST
975
976 void wl_multicast(struct net_device *dev)
977 {
978 #if 1                           /* (HCF_TYPE) & HCF_TYPE_STA */
979         /*
980          * should we return an error status in AP mode ?
981          * seems reasonable that even an AP-only driver
982          * could afford this small additional footprint
983          */
984
985         int x;
986         struct netdev_hw_addr *ha;
987         struct wl_private *lp = wl_priv(dev);
988         unsigned long flags;
989
990         DBG_PARAM(DbgInfo, "dev", "%s (0x%p)", dev->name, dev);
991
992         if (!wl_adapter_is_open(dev))
993                 return;
994
995 #if DBG
996         if (DBG_FLAGS(DbgInfo) & DBG_PARAM_ON) {
997                 DBG_PRINT("  flags: %s%s%s\n",
998                           (dev->flags & IFF_PROMISC) ? "Promiscuous " : "",
999                           (dev->flags & IFF_MULTICAST) ? "Multicast " : "",
1000                           (dev->flags & IFF_ALLMULTI) ? "All-Multicast" : "");
1001
1002                 DBG_PRINT("  mc_count: %d\n", netdev_mc_count(dev));
1003
1004                 netdev_for_each_mc_addr(ha, dev)
1005                     DBG_PRINT("    %pM (%d)\n", ha->addr, dev->addr_len);
1006         }
1007 #endif /* DBG */
1008
1009         if (!(lp->flags & WVLAN2_UIL_BUSY)) {
1010
1011 #ifdef USE_RTS
1012                 if (lp->useRTS == 1) {
1013                         DBG_TRACE(DbgInfo, "Skipping multicast, in RTS mode\n");
1014                         return;
1015                 }
1016 #endif /* USE_RTS */
1017
1018                 wl_lock(lp, &flags);
1019                 wl_act_int_off(lp);
1020
1021                 if (CNV_INT_TO_LITTLE(lp->hcfCtx.IFB_FWIdentity.comp_id) ==
1022                     COMP_ID_FW_STA) {
1023                         if (dev->flags & IFF_PROMISC) {
1024                                 /* Enable promiscuous mode */
1025                                 lp->ltvRecord.len = 2;
1026                                 lp->ltvRecord.typ = CFG_PROMISCUOUS_MODE;
1027                                 lp->ltvRecord.u.u16[0] = CNV_INT_TO_LITTLE(1);
1028                                 DBG_PRINT
1029                                     ("Enabling Promiscuous mode (IFF_PROMISC)\n");
1030                                 hcf_put_info(&(lp->hcfCtx),
1031                                              (LTVP) & (lp->ltvRecord));
1032                         } else if ((netdev_mc_count(dev) > HCF_MAX_MULTICAST)
1033                                    || (dev->flags & IFF_ALLMULTI)) {
1034                                 /* Shutting off this filter will enable all multicast frames to
1035                                    be sent up from the device; however, this is a static RID, so
1036                                    a call to wl_apply() is needed */
1037                                 lp->ltvRecord.len = 2;
1038                                 lp->ltvRecord.typ = CFG_CNF_RX_ALL_GROUP_ADDR;
1039                                 lp->ltvRecord.u.u16[0] = CNV_INT_TO_LITTLE(0);
1040                                 DBG_PRINT
1041                                     ("Enabling all multicast mode (IFF_ALLMULTI)\n");
1042                                 hcf_put_info(&(lp->hcfCtx),
1043                                              (LTVP) & (lp->ltvRecord));
1044                                 wl_apply(lp);
1045                         } else if (!netdev_mc_empty(dev)) {
1046                                 /* Set the multicast addresses */
1047                                 lp->ltvRecord.len =
1048                                     (netdev_mc_count(dev) * 3) + 1;
1049                                 lp->ltvRecord.typ = CFG_GROUP_ADDR;
1050
1051                                 x = 0;
1052                                 netdev_for_each_mc_addr(ha, dev)
1053                                     memcpy(&
1054                                            (lp->ltvRecord.u.u8[x++ * ETH_ALEN]),
1055                                            ha->addr, ETH_ALEN);
1056                                 DBG_PRINT("Setting multicast list\n");
1057                                 hcf_put_info(&(lp->hcfCtx),
1058                                              (LTVP) & (lp->ltvRecord));
1059                         } else {
1060                                 /* Disable promiscuous mode */
1061                                 lp->ltvRecord.len = 2;
1062                                 lp->ltvRecord.typ = CFG_PROMISCUOUS_MODE;
1063                                 lp->ltvRecord.u.u16[0] = CNV_INT_TO_LITTLE(0);
1064                                 DBG_PRINT("Disabling Promiscuous mode\n");
1065                                 hcf_put_info(&(lp->hcfCtx),
1066                                              (LTVP) & (lp->ltvRecord));
1067
1068                                 /* Disable multicast mode */
1069                                 lp->ltvRecord.len = 2;
1070                                 lp->ltvRecord.typ = CFG_GROUP_ADDR;
1071                                 DBG_PRINT("Disabling Multicast mode\n");
1072                                 hcf_put_info(&(lp->hcfCtx),
1073                                              (LTVP) & (lp->ltvRecord));
1074
1075                                 /*
1076                                  * Turning on this filter will prevent all multicast frames from
1077                                  * being sent up from the device; however, this is a static RID,
1078                                  * so a call to wl_apply() is needed
1079                                  */
1080                                 lp->ltvRecord.len = 2;
1081                                 lp->ltvRecord.typ = CFG_CNF_RX_ALL_GROUP_ADDR;
1082                                 lp->ltvRecord.u.u16[0] = CNV_INT_TO_LITTLE(1);
1083                                 DBG_PRINT
1084                                     ("Disabling all multicast mode (IFF_ALLMULTI)\n");
1085                                 hcf_put_info(&(lp->hcfCtx),
1086                                              (LTVP) & (lp->ltvRecord));
1087                                 wl_apply(lp);
1088                         }
1089                 }
1090                 wl_act_int_on(lp);
1091                 wl_unlock(lp, &flags);
1092         }
1093 #endif /* HCF_STA */
1094 }                               /* wl_multicast */
1095
1096 /*============================================================================*/
1097
1098 #else /* NEW_MULTICAST */
1099
1100 void wl_multicast(struct net_device *dev, int num_addrs, void *addrs)
1101 {
1102         DBG_PARAM(DbgInfo, "dev", "%s (0x%p)", dev->name, dev);
1103         DBG_PARAM(DbgInfo, "num_addrs", "%d", num_addrs);
1104         DBG_PARAM(DbgInfo, "addrs", "0x%p", addrs);
1105
1106 #error Obsolete set multicast interface!
1107 }                               /* wl_multicast */
1108
1109 /*============================================================================*/
1110
1111 #endif /* NEW_MULTICAST */
1112
1113 static const struct net_device_ops wl_netdev_ops = {
1114         .ndo_start_xmit = &wl_tx_port0,
1115
1116         .ndo_set_config = &wl_config,
1117         .ndo_get_stats = &wl_stats,
1118         .ndo_set_rx_mode = &wl_multicast,
1119
1120         .ndo_init = &wl_insert,
1121         .ndo_open = &wl_adapter_open,
1122         .ndo_stop = &wl_adapter_close,
1123         .ndo_do_ioctl = &wl_ioctl,
1124
1125         .ndo_tx_timeout = &wl_tx_timeout,
1126
1127 #ifdef CONFIG_NET_POLL_CONTROLLER
1128         .ndo_poll_controller = wl_poll,
1129 #endif
1130 };
1131
1132 /*******************************************************************************
1133  *      wl_device_alloc()
1134  *******************************************************************************
1135  *
1136  *  DESCRIPTION:
1137  *
1138  *      Create instances of net_device and wl_private for the new adapter
1139  *  and register the device's entry points in the net_device structure.
1140  *
1141  *  PARAMETERS:
1142  *
1143  *      N/A
1144  *
1145  *  RETURNS:
1146  *
1147  *      a pointer to an allocated and initialized net_device struct for this
1148  *      device.
1149  *
1150  ******************************************************************************/
1151 struct net_device *wl_device_alloc(void)
1152 {
1153         struct net_device *dev = NULL;
1154         struct wl_private *lp = NULL;
1155
1156         /* Alloc a net_device struct */
1157         dev = alloc_etherdev(sizeof(struct wl_private));
1158         if (!dev)
1159                 return NULL;
1160
1161         /*
1162          * Initialize the 'next' pointer in the struct.
1163          * Currently only used for PCI,
1164          * but do it here just in case it's used
1165          * for other buses in the future
1166          */
1167         lp = wl_priv(dev);
1168
1169         /* Check MTU */
1170         if (dev->mtu > MTU_MAX) {
1171                 DBG_WARNING(DbgInfo, "%s: MTU set too high, limiting to %d.\n",
1172                             dev->name, MTU_MAX);
1173                 dev->mtu = MTU_MAX;
1174         }
1175
1176         /* Setup the function table in the device structure. */
1177
1178         dev->wireless_handlers = (struct iw_handler_def *)&wl_iw_handler_def;
1179         lp->wireless_data.spy_data = &lp->spy_data;
1180         dev->wireless_data = &lp->wireless_data;
1181
1182         dev->netdev_ops = &wl_netdev_ops;
1183
1184         dev->watchdog_timeo = TX_TIMEOUT;
1185
1186         dev->ethtool_ops = &wl_ethtool_ops;
1187
1188         netif_stop_queue(dev);
1189
1190         /* Allocate virtual devices for WDS support if needed */
1191         WL_WDS_DEVICE_ALLOC(lp);
1192
1193         return dev;
1194 }                               /* wl_device_alloc */
1195
1196 /*============================================================================*/
1197
1198 /*******************************************************************************
1199  *      wl_device_dealloc()
1200  *******************************************************************************
1201  *
1202  *  DESCRIPTION:
1203  *
1204  *      Free instances of net_device and wl_private strcutres for an adapter
1205  *  and perform basic cleanup.
1206  *
1207  *  PARAMETERS:
1208  *
1209  *      dev - a pointer to the device's net_device structure.
1210  *
1211  *  RETURNS:
1212  *
1213  *      N/A
1214  *
1215  ******************************************************************************/
1216 void wl_device_dealloc(struct net_device *dev)
1217 {
1218         /* Dealloc the WDS ports */
1219         WL_WDS_DEVICE_DEALLOC(lp);
1220
1221         free_netdev(dev);
1222 }                               /* wl_device_dealloc */
1223
1224 /*============================================================================*/
1225
1226 /*******************************************************************************
1227  *      wl_tx_port0()
1228  *******************************************************************************
1229  *
1230  *  DESCRIPTION:
1231  *
1232  *      The handler routine for Tx over HCF_PORT_0.
1233  *
1234  *  PARAMETERS:
1235  *
1236  *      skb - a pointer to the sk_buff to transmit.
1237  *      dev - a pointer to a net_device structure representing HCF_PORT_0.
1238  *
1239  *  RETURNS:
1240  *
1241  *      N/A
1242  *
1243  ******************************************************************************/
1244 int wl_tx_port0(struct sk_buff *skb, struct net_device *dev)
1245 {
1246         DBG_TX(DbgInfo, "Tx on Port 0\n");
1247
1248         return wl_tx(skb, dev, HCF_PORT_0);
1249 #ifdef ENABLE_DMA
1250         return wl_tx_dma(skb, dev, HCF_PORT_0);
1251 #endif
1252 }                               /* wl_tx_port0i */
1253
1254 /*============================================================================*/
1255
1256 #ifdef USE_WDS
1257
1258 /*******************************************************************************
1259  *      wl_tx_port1()
1260  *******************************************************************************
1261  *
1262  *  DESCRIPTION:
1263  *
1264  *      The handler routine for Tx over HCF_PORT_1.
1265  *
1266  *  PARAMETERS:
1267  *
1268  *      skb - a pointer to the sk_buff to transmit.
1269  *      dev - a pointer to a net_device structure representing HCF_PORT_1.
1270  *
1271  *  RETURNS:
1272  *
1273  *      N/A
1274  *
1275  ******************************************************************************/
1276 int wl_tx_port1(struct sk_buff *skb, struct net_device *dev)
1277 {
1278         DBG_TX(DbgInfo, "Tx on Port 1\n");
1279         return wl_tx(skb, dev, HCF_PORT_1);
1280 }                               /* wl_tx_port1 */
1281
1282 /*============================================================================*/
1283
1284 /*******************************************************************************
1285  *      wl_tx_port2()
1286  *******************************************************************************
1287  *
1288  *  DESCRIPTION:
1289  *
1290  *      The handler routine for Tx over HCF_PORT_2.
1291  *
1292  *  PARAMETERS:
1293  *
1294  *      skb - a pointer to the sk_buff to transmit.
1295  *      dev - a pointer to a net_device structure representing HCF_PORT_2.
1296  *
1297  *  RETURNS:
1298  *
1299  *      N/A
1300  *
1301  ******************************************************************************/
1302 int wl_tx_port2(struct sk_buff *skb, struct net_device *dev)
1303 {
1304         DBG_TX(DbgInfo, "Tx on Port 2\n");
1305         return wl_tx(skb, dev, HCF_PORT_2);
1306 }                               /* wl_tx_port2 */
1307
1308 /*============================================================================*/
1309
1310 /*******************************************************************************
1311  *      wl_tx_port3()
1312  *******************************************************************************
1313  *
1314  *  DESCRIPTION:
1315  *
1316  *      The handler routine for Tx over HCF_PORT_3.
1317  *
1318  *  PARAMETERS:
1319  *
1320  *      skb - a pointer to the sk_buff to transmit.
1321  *      dev - a pointer to a net_device structure representing HCF_PORT_3.
1322  *
1323  *  RETURNS:
1324  *
1325  *      N/A
1326  *
1327  ******************************************************************************/
1328 int wl_tx_port3(struct sk_buff *skb, struct net_device *dev)
1329 {
1330         DBG_TX(DbgInfo, "Tx on Port 3\n");
1331         return wl_tx(skb, dev, HCF_PORT_3);
1332 }                               /* wl_tx_port3 */
1333
1334 /*============================================================================*/
1335
1336 /*******************************************************************************
1337  *      wl_tx_port4()
1338  *******************************************************************************
1339  *
1340  *  DESCRIPTION:
1341  *
1342  *      The handler routine for Tx over HCF_PORT_4.
1343  *
1344  *  PARAMETERS:
1345  *
1346  *      skb - a pointer to the sk_buff to transmit.
1347  *      dev - a pointer to a net_device structure representing HCF_PORT_4.
1348  *
1349  *  RETURNS:
1350  *
1351  *      N/A
1352  *
1353  ******************************************************************************/
1354 int wl_tx_port4(struct sk_buff *skb, struct net_device *dev)
1355 {
1356         DBG_TX(DbgInfo, "Tx on Port 4\n");
1357         return wl_tx(skb, dev, HCF_PORT_4);
1358 }                               /* wl_tx_port4 */
1359
1360 /*============================================================================*/
1361
1362 /*******************************************************************************
1363  *      wl_tx_port5()
1364  *******************************************************************************
1365  *
1366  *  DESCRIPTION:
1367  *
1368  *      The handler routine for Tx over HCF_PORT_5.
1369  *
1370  *  PARAMETERS:
1371  *
1372  *      skb - a pointer to the sk_buff to transmit.
1373  *      dev - a pointer to a net_device structure representing HCF_PORT_5.
1374  *
1375  *  RETURNS:
1376  *
1377  *      N/A
1378  *
1379  ******************************************************************************/
1380 int wl_tx_port5(struct sk_buff *skb, struct net_device *dev)
1381 {
1382         DBG_TX(DbgInfo, "Tx on Port 5\n");
1383         return wl_tx(skb, dev, HCF_PORT_5);
1384 }                               /* wl_tx_port5 */
1385
1386 /*============================================================================*/
1387
1388 /*******************************************************************************
1389  *      wl_tx_port6()
1390  *******************************************************************************
1391  *
1392  *  DESCRIPTION:
1393  *
1394  *      The handler routine for Tx over HCF_PORT_6.
1395  *
1396  *  PARAMETERS:
1397  *
1398  *      skb - a pointer to the sk_buff to transmit.
1399  *      dev - a pointer to a net_device structure representing HCF_PORT_6.
1400  *
1401  *  RETURNS:
1402  *
1403  *      N/A
1404  *
1405  ******************************************************************************/
1406 int wl_tx_port6(struct sk_buff *skb, struct net_device *dev)
1407 {
1408         DBG_TX(DbgInfo, "Tx on Port 6\n");
1409         return wl_tx(skb, dev, HCF_PORT_6);
1410 }                               /* wl_tx_port6 */
1411
1412 /*============================================================================*/
1413
1414 /*******************************************************************************
1415  *      wl_wds_device_alloc()
1416  *******************************************************************************
1417  *
1418  *  DESCRIPTION:
1419  *
1420  *      Create instances of net_device to represent the WDS ports, and register
1421  *  the device's entry points in the net_device structure.
1422  *
1423  *  PARAMETERS:
1424  *
1425  *      lp  - a pointer to the device's private adapter structure
1426  *
1427  *  RETURNS:
1428  *
1429  *      N/A, but will place pointers to the allocated and initialized net_device
1430  *      structs in the private adapter structure.
1431  *
1432  ******************************************************************************/
1433 void wl_wds_device_alloc(struct wl_private *lp)
1434 {
1435         int count;
1436
1437         /* WDS support requires additional net_device structs to be allocated,
1438            so that user space apps can use these virtual devices to specify the
1439            port on which to Tx/Rx */
1440         for (count = 0; count < NUM_WDS_PORTS; count++) {
1441                 struct net_device *dev_wds = NULL;
1442
1443                 dev_wds = kzalloc(sizeof(struct net_device), GFP_KERNEL);
1444                 if (!dev_wds)
1445                         return;
1446
1447                 ether_setup(dev_wds);
1448
1449                 lp->wds_port[count].dev = dev_wds;
1450
1451                 /* Re-use wl_init for all the devices, as it currently does nothing, but
1452                  * is required. Re-use the stats/tx_timeout handler for all as well; the
1453                  * WDS port which is requesting these operations can be determined by
1454                  * the net_device pointer. Set the private member of all devices to point
1455                  * to the same net_device struct; that way, all information gets
1456                  * funnelled through the one "real" net_device. Name the WDS ports
1457                  * "wds<n>"
1458                  * */
1459                 lp->wds_port[count].dev->init = &wl_init;
1460                 lp->wds_port[count].dev->get_stats = &wl_stats;
1461                 lp->wds_port[count].dev->tx_timeout = &wl_tx_timeout;
1462                 lp->wds_port[count].dev->watchdog_timeo = TX_TIMEOUT;
1463                 lp->wds_port[count].dev->priv = lp;
1464
1465                 sprintf(lp->wds_port[count].dev->name, "wds%d", count);
1466         }
1467
1468         /* Register the Tx handlers */
1469         lp->wds_port[0].dev->hard_start_xmit = &wl_tx_port1;
1470         lp->wds_port[1].dev->hard_start_xmit = &wl_tx_port2;
1471         lp->wds_port[2].dev->hard_start_xmit = &wl_tx_port3;
1472         lp->wds_port[3].dev->hard_start_xmit = &wl_tx_port4;
1473         lp->wds_port[4].dev->hard_start_xmit = &wl_tx_port5;
1474         lp->wds_port[5].dev->hard_start_xmit = &wl_tx_port6;
1475
1476         WL_WDS_NETIF_STOP_QUEUE(lp);
1477 }                               /* wl_wds_device_alloc */
1478
1479 /*============================================================================*/
1480
1481 /*******************************************************************************
1482  *      wl_wds_device_dealloc()
1483  *******************************************************************************
1484  *
1485  *  DESCRIPTION:
1486  *
1487  *      Free instances of net_device structures used to support WDS.
1488  *
1489  *  PARAMETERS:
1490  *
1491  *      lp  - a pointer to the device's private adapter structure
1492  *
1493  *  RETURNS:
1494  *
1495  *      N/A
1496  *
1497  ******************************************************************************/
1498 void wl_wds_device_dealloc(struct wl_private *lp)
1499 {
1500         int count;
1501
1502         for (count = 0; count < NUM_WDS_PORTS; count++) {
1503                 struct net_device *dev_wds = NULL;
1504
1505                 dev_wds = lp->wds_port[count].dev;
1506
1507                 if (dev_wds != NULL) {
1508                         if (dev_wds->flags & IFF_UP) {
1509                                 dev_close(dev_wds);
1510                                 dev_wds->flags &= ~(IFF_UP | IFF_RUNNING);
1511                         }
1512
1513                         free_netdev(dev_wds);
1514                         lp->wds_port[count].dev = NULL;
1515                 }
1516         }
1517 }                               /* wl_wds_device_dealloc */
1518
1519 /*============================================================================*/
1520
1521 /*******************************************************************************
1522  *      wl_wds_netif_start_queue()
1523  *******************************************************************************
1524  *
1525  *  DESCRIPTION:
1526  *
1527  *      Used to start the netif queues of all the "virtual" network devices
1528  *      which represent the WDS ports.
1529  *
1530  *  PARAMETERS:
1531  *
1532  *      lp  - a pointer to the device's private adapter structure
1533  *
1534  *  RETURNS:
1535  *
1536  *      N/A
1537  *
1538  ******************************************************************************/
1539 void wl_wds_netif_start_queue(struct wl_private *lp)
1540 {
1541         int count;
1542     /*------------------------------------------------------------------------*/
1543
1544         if (lp != NULL) {
1545                 for (count = 0; count < NUM_WDS_PORTS; count++) {
1546                         if (lp->wds_port[count].is_registered &&
1547                             lp->wds_port[count].netif_queue_on == FALSE) {
1548                                 netif_start_queue(lp->wds_port[count].dev);
1549                                 lp->wds_port[count].netif_queue_on = TRUE;
1550                         }
1551                 }
1552         }
1553 }                               /* wl_wds_netif_start_queue */
1554
1555 /*============================================================================*/
1556
1557 /*******************************************************************************
1558  *      wl_wds_netif_stop_queue()
1559  *******************************************************************************
1560  *
1561  *  DESCRIPTION:
1562  *
1563  *      Used to stop the netif queues of all the "virtual" network devices
1564  *      which represent the WDS ports.
1565  *
1566  *  PARAMETERS:
1567  *
1568  *      lp  - a pointer to the device's private adapter structure
1569  *
1570  *  RETURNS:
1571  *
1572  *      N/A
1573  *
1574  ******************************************************************************/
1575 void wl_wds_netif_stop_queue(struct wl_private *lp)
1576 {
1577         int count;
1578     /*------------------------------------------------------------------------*/
1579
1580         if (lp != NULL) {
1581                 for (count = 0; count < NUM_WDS_PORTS; count++) {
1582                         if (lp->wds_port[count].is_registered &&
1583                             lp->wds_port[count].netif_queue_on == TRUE) {
1584                                 netif_stop_queue(lp->wds_port[count].dev);
1585                                 lp->wds_port[count].netif_queue_on = FALSE;
1586                         }
1587                 }
1588         }
1589 }                               /* wl_wds_netif_stop_queue */
1590
1591 /*============================================================================*/
1592
1593 /*******************************************************************************
1594  *      wl_wds_netif_wake_queue()
1595  *******************************************************************************
1596  *
1597  *  DESCRIPTION:
1598  *
1599  *      Used to wake the netif queues of all the "virtual" network devices
1600  *      which represent the WDS ports.
1601  *
1602  *  PARAMETERS:
1603  *
1604  *      lp  - a pointer to the device's private adapter structure
1605  *
1606  *  RETURNS:
1607  *
1608  *      N/A
1609  *
1610  ******************************************************************************/
1611 void wl_wds_netif_wake_queue(struct wl_private *lp)
1612 {
1613         int count;
1614     /*------------------------------------------------------------------------*/
1615
1616         if (lp != NULL) {
1617                 for (count = 0; count < NUM_WDS_PORTS; count++) {
1618                         if (lp->wds_port[count].is_registered &&
1619                             lp->wds_port[count].netif_queue_on == FALSE) {
1620                                 netif_wake_queue(lp->wds_port[count].dev);
1621                                 lp->wds_port[count].netif_queue_on = TRUE;
1622                         }
1623                 }
1624         }
1625 }                               /* wl_wds_netif_wake_queue */
1626
1627 /*============================================================================*/
1628
1629 /*******************************************************************************
1630  *      wl_wds_netif_carrier_on()
1631  *******************************************************************************
1632  *
1633  *  DESCRIPTION:
1634  *
1635  *      Used to signal the network layer that carrier is present on all of the
1636  *      "virtual" network devices which represent the WDS ports.
1637  *
1638  *  PARAMETERS:
1639  *
1640  *      lp  - a pointer to the device's private adapter structure
1641  *
1642  *  RETURNS:
1643  *
1644  *      N/A
1645  *
1646  ******************************************************************************/
1647 void wl_wds_netif_carrier_on(struct wl_private *lp)
1648 {
1649         int count;
1650     /*------------------------------------------------------------------------*/
1651
1652         if (lp != NULL) {
1653                 for (count = 0; count < NUM_WDS_PORTS; count++) {
1654                         if (lp->wds_port[count].is_registered)
1655                                 netif_carrier_on(lp->wds_port[count].dev);
1656                 }
1657         }
1658 }                               /* wl_wds_netif_carrier_on */
1659
1660 /*============================================================================*/
1661
1662 /*******************************************************************************
1663  *      wl_wds_netif_carrier_off()
1664  *******************************************************************************
1665  *
1666  *  DESCRIPTION:
1667  *
1668  *      Used to signal the network layer that carrier is NOT present on all of
1669  *      the "virtual" network devices which represent the WDS ports.
1670  *
1671  *  PARAMETERS:
1672  *
1673  *      lp  - a pointer to the device's private adapter structure
1674  *
1675  *  RETURNS:
1676  *
1677  *      N/A
1678  *
1679  ******************************************************************************/
1680 void wl_wds_netif_carrier_off(struct wl_private *lp)
1681 {
1682         int count;
1683
1684         if (lp != NULL) {
1685                 for (count = 0; count < NUM_WDS_PORTS; count++) {
1686                         if (lp->wds_port[count].is_registered)
1687                                 netif_carrier_off(lp->wds_port[count].dev);
1688                 }
1689         }
1690
1691 }                               /* wl_wds_netif_carrier_off */
1692
1693 /*============================================================================*/
1694
1695 #endif /* USE_WDS */
1696
1697 #ifdef ENABLE_DMA
1698 /*******************************************************************************
1699  *      wl_send_dma()
1700  *******************************************************************************
1701  *
1702  *  DESCRIPTION:
1703  *
1704  *      The routine which performs data transmits when using busmaster DMA.
1705  *
1706  *  PARAMETERS:
1707  *
1708  *      lp   - a pointer to the device's wl_private struct.
1709  *      skb  - a pointer to the network layer's data buffer.
1710  *      port - the Hermes port on which to transmit.
1711  *
1712  *  RETURNS:
1713  *
1714  *      0 on success
1715  *      1 on error
1716  *
1717  ******************************************************************************/
1718 int wl_send_dma(struct wl_private *lp, struct sk_buff *skb, int port)
1719 {
1720         int len;
1721         DESC_STRCT *desc = NULL;
1722         DESC_STRCT *desc_next = NULL;
1723     /*------------------------------------------------------------------------*/
1724
1725         if (lp == NULL) {
1726                 DBG_ERROR(DbgInfo, "Private adapter struct is NULL\n");
1727                 return FALSE;
1728         }
1729
1730         if (lp->dev == NULL) {
1731                 DBG_ERROR(DbgInfo, "net_device struct in wl_private is NULL\n");
1732                 return FALSE;
1733         }
1734
1735         /* AGAIN, ALL THE QUEUEING DONE HERE IN I/O MODE IS NOT PERFORMED */
1736
1737         if (skb == NULL) {
1738                 DBG_WARNING(DbgInfo, "Nothing to send.\n");
1739                 return FALSE;
1740         }
1741
1742         len = skb->len;
1743
1744         /* Get a free descriptor */
1745         desc = wl_pci_dma_get_tx_packet(lp);
1746
1747         if (desc == NULL) {
1748                 if (lp->netif_queue_on == TRUE) {
1749                         netif_stop_queue(lp->dev);
1750                         WL_WDS_NETIF_STOP_QUEUE(lp);
1751                         lp->netif_queue_on = FALSE;
1752
1753                         dev_kfree_skb_any( skb );
1754                         return 0;
1755                 }
1756         }
1757
1758         SET_BUF_CNT(desc, /*HCF_DMA_FD_CNT */ HFS_ADDR_DEST);
1759         SET_BUF_SIZE(desc, HCF_DMA_TX_BUF1_SIZE);
1760
1761         desc_next = desc->next_desc_addr;
1762
1763         if (desc_next->buf_addr == NULL) {
1764                 DBG_ERROR(DbgInfo, "DMA descriptor buf_addr is NULL\n");
1765                 return FALSE;
1766         }
1767
1768         /* Copy the payload into the DMA packet */
1769         memcpy(desc_next->buf_addr, skb->data, len);
1770
1771         SET_BUF_CNT(desc_next, len);
1772         SET_BUF_SIZE(desc_next, HCF_MAX_PACKET_SIZE);
1773
1774         hcf_dma_tx_put(&(lp->hcfCtx), desc, 0);
1775
1776         /* Free the skb and perform queue cleanup, as the buffer was
1777            transmitted successfully */
1778         dev_consume_skb_any( skb );
1779
1780         return TRUE;
1781 }                               /* wl_send_dma */
1782
1783 /*============================================================================*/
1784
1785 /*******************************************************************************
1786  *      wl_rx_dma()
1787  *******************************************************************************
1788  *
1789  *  DESCRIPTION:
1790  *
1791  *      The routine which performs data reception when using busmaster DMA.
1792  *
1793  *  PARAMETERS:
1794  *
1795  *      dev - a pointer to the device's net_device structure.
1796  *
1797  *  RETURNS:
1798  *
1799  *      0 on success
1800  *      1 on error
1801  *
1802  ******************************************************************************/
1803 int wl_rx_dma(struct net_device *dev)
1804 {
1805         int port;
1806         hcf_16 pktlen;
1807         hcf_16 hfs_stat;
1808         struct sk_buff *skb;
1809         struct wl_private *lp = NULL;
1810         DESC_STRCT *desc, *desc_next;
1811     /*------------------------------------------------------------------------*/
1812
1813         DBG_PARAM(DbgInfo, "dev", "%s (0x%p)", dev->name, dev);
1814
1815         lp = dev->priv;
1816         if ((lp != NULL) && !(lp->flags & WVLAN2_UIL_BUSY)) {
1817
1818 #ifdef USE_RTS
1819                 if (lp->useRTS == 1) {
1820                         DBG_PRINT("RTS: We're getting an Rx...\n");
1821                         return -EIO;
1822                 }
1823 #endif /* USE_RTS */
1824
1825                 /*
1826                  *if( lp->dma.status == 0 )
1827                  *{
1828                  */
1829                 desc = hcf_dma_rx_get(&(lp->hcfCtx));
1830
1831                 if (desc != NULL) {
1832                         /* Check and see if we rcvd. a WMP frame */
1833                         /*
1834                            if((( *(hcf_8 *)&desc->buf_addr[HFS_STAT] ) &
1835                            ( HFS_STAT_MSG_TYPE | HFS_STAT_ERR )) == HFS_STAT_WMP_MSG )
1836                            {
1837                            DBG_TRACE( DbgInfo, "Got a WMP frame\n" );
1838
1839                            x.len = sizeof( CFG_MB_INFO_RANGE2_STRCT ) / sizeof( hcf_16 );
1840                            x.typ = CFG_MB_INFO;
1841                            x.base_typ = CFG_WMP;
1842                            x.frag_cnt = 2;
1843                            x.frag_buf[0].frag_len  = GET_BUF_CNT( descp ) / sizeof( hcf_16 );
1844                            x.frag_buf[0].frag_addr = (hcf_8 *) descp->buf_addr ;
1845                            x.frag_buf[1].frag_len  = ( GET_BUF_CNT( descp->next_desc_addr ) + 1 ) / sizeof( hcf_16 );
1846                            x.frag_buf[1].frag_addr = (hcf_8 *) descp->next_desc_addr->buf_addr ;
1847
1848                            hcf_put_info( &( lp->hcfCtx ), (LTVP)&x );
1849                            }
1850                          */
1851
1852                         desc_next = desc->next_desc_addr;
1853
1854                         /* Make sure the buffer isn't empty */
1855                         if (GET_BUF_CNT(desc) == 0) {
1856                                 DBG_WARNING(DbgInfo, "Buffer is empty!\n");
1857
1858                                 /* Give the descriptor back to the HCF */
1859                                 hcf_dma_rx_put(&(lp->hcfCtx), desc);
1860                                 return -EIO;
1861                         }
1862
1863                         /* Read the HFS_STAT register from the lookahead buffer */
1864                         hfs_stat = (hcf_16) (desc->buf_addr[HFS_STAT / 2]);
1865
1866                         /* Make sure the frame isn't bad */
1867                         if ((hfs_stat & HFS_STAT_ERR) != HCF_SUCCESS) {
1868                                 DBG_WARNING(DbgInfo,
1869                                             "HFS_STAT_ERROR (0x%x) in Rx Packet\n",
1870                                             desc->buf_addr[HFS_STAT / 2]);
1871
1872                                 /* Give the descriptor back to the HCF */
1873                                 hcf_dma_rx_put(&(lp->hcfCtx), desc);
1874                                 return -EIO;
1875                         }
1876
1877                         /* Determine what port this packet is for */
1878                         port = (hfs_stat >> 8) & 0x0007;
1879                         DBG_RX(DbgInfo, "Rx frame for port %d\n", port);
1880
1881                         pktlen = GET_BUF_CNT(desc_next);
1882                         if (pktlen != 0) {
1883                                 skb = ALLOC_SKB(pktlen);
1884                                 if (skb != NULL) {
1885                                         switch (port) {
1886 #ifdef USE_WDS
1887                                         case 1:
1888                                         case 2:
1889                                         case 3:
1890                                         case 4:
1891                                         case 5:
1892                                         case 6:
1893                                                 skb->dev =
1894                                                     lp->wds_port[port - 1].dev;
1895                                                 break;
1896 #endif /* USE_WDS */
1897
1898                                         case 0:
1899                                         default:
1900                                                 skb->dev = dev;
1901                                                 break;
1902                                         }
1903
1904                                         GET_PACKET_DMA(skb->dev, skb, pktlen);
1905
1906                                         /* Give the descriptor back to the HCF */
1907                                         hcf_dma_rx_put(&(lp->hcfCtx), desc);
1908
1909                                         netif_rx(skb);
1910
1911                                         if (port == 0) {
1912                                                 lp->stats.rx_packets++;
1913                                                 lp->stats.rx_bytes += pktlen;
1914                                         }
1915 #ifdef USE_WDS
1916                                         else {
1917                                                 lp->wds_port[port -
1918                                                              1].stats.
1919                                                     rx_packets++;
1920                                                 lp->wds_port[port -
1921                                                              1].stats.
1922                                                     rx_bytes += pktlen;
1923                                         }
1924 #endif /* USE_WDS */
1925
1926                                         dev->last_rx = jiffies;
1927
1928                                 } else {
1929                                         DBG_ERROR(DbgInfo,
1930                                                   "Could not alloc skb\n");
1931
1932                                         if (port == 0)
1933                                                 lp->stats.rx_dropped++;
1934 #ifdef USE_WDS
1935                                         else {
1936                                                 lp->wds_port[port -
1937                                                              1].stats.
1938                                                     rx_dropped++;
1939                                         }
1940 #endif /* USE_WDS */
1941                                 }
1942                         }
1943                 }
1944                 /*}*/
1945         }
1946
1947         return 0;
1948 }                               /* wl_rx_dma */
1949
1950 /*============================================================================*/
1951 #endif /* ENABLE_DMA */