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