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