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