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