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