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