1 /*******************************************************************************
3 * Wireless device driver for Linux (wlags49).
5 * Copyright (c) 1998-2003 Agere Systems Inc.
9 * Initially developed by TriplePoint, Inc.
10 * http://www.triplepoint.com
12 *------------------------------------------------------------------------------
14 * This file contains handler functions registered with the net_device
17 *------------------------------------------------------------------------------
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.
26 * Copyright © 2003 Agere Systems Inc.
27 * All rights reserved.
29 * Redistribution and use in source or binary forms, with or without
30 * modifications, are permitted provided that the following conditions are met:
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
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.
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.
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
60 ******************************************************************************/
62 /*******************************************************************************
64 ******************************************************************************/
65 #include <wl_version.h>
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>
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>
95 // #include <hcfdef.h>
98 #include <wl_internal.h>
102 #include <wl_netdev.h>
106 #include <wl_profile.h>
107 #endif /* USE_PROFILE */
111 #endif /* BUS_PCMCIA */
119 #define MTU_MAX (HCF_MAX_MSG - ETH_HLEN - 8)
121 #define MTU_MAX (HCF_MAX_MSG - ETH_HLEN)
124 //static int mtu = MTU_MAX;
125 //MODULE_PARM(mtu, "i");
126 //MODULE_PARM_DESC(mtu, "MTU");
128 /*******************************************************************************
130 ******************************************************************************/
131 #define BLOCK_INPUT(buf, len) \
132 desc->buf_addr = buf; \
133 desc->BUF_SIZE = len; \
134 status = hcf_rcv_msg(&(lp->hcfCtx), desc, 0)
136 #define BLOCK_INPUT_DMA(buf, len) memcpy( buf, desc_next->buf_addr, pktlen )
138 /*******************************************************************************
139 * function prototypes
140 ******************************************************************************/
142 /*******************************************************************************
144 *******************************************************************************
148 * We never need to do anything when a "Wireless" device is "initialized"
149 * by the net software, because we only register already-found cards.
153 * dev - a pointer to the device's net_device structure
158 * errno value otherwise
160 ******************************************************************************/
161 int wl_init( struct net_device *dev )
163 // unsigned long flags;
164 // struct wl_private *lp = wl_priv(dev);
166 DBG_PARAM( DbgInfo, "dev", "%s (0x%p)", dev->name, dev );
168 /* Nothing to do, but grab the spinlock anyway just in case we ever need
170 // wl_lock( lp, &flags );
171 // wl_unlock( lp, &flags );
175 /*============================================================================*/
177 /*******************************************************************************
179 *******************************************************************************
183 * Implement the SIOCSIFMAP interface.
187 * dev - a pointer to the device's net_device structure
188 * map - a pointer to the device's ifmap structure
195 ******************************************************************************/
196 int wl_config( struct net_device *dev, struct ifmap *map )
198 DBG_PARAM( DbgInfo, "dev", "%s (0x%p)", dev->name, dev );
199 DBG_PARAM( DbgInfo, "map", "0x%p", map );
201 /* The only thing we care about here is a port change. Since this not needed,
202 ignore the request. */
203 DBG_TRACE(DbgInfo, "%s: %s called.\n", dev->name, __func__);
207 /*============================================================================*/
209 /*******************************************************************************
211 *******************************************************************************
215 * Return the current device statistics.
219 * dev - a pointer to the device's net_device structure
223 * a pointer to a net_device_stats structure containing the network
226 ******************************************************************************/
227 struct net_device_stats *wl_stats( struct net_device *dev )
233 struct net_device_stats *pStats;
234 struct wl_private *lp = wl_priv(dev);
236 //DBG_PARAM( DbgInfo, "dev", "%s (0x%p)", dev->name, dev );
240 wl_lock( lp, &flags );
243 if( lp->useRTS == 1 ) {
244 wl_unlock( lp, &flags );
249 /* Return the statistics for the appropriate device */
252 for( count = 0; count < NUM_WDS_PORTS; count++ ) {
253 if( dev == lp->wds_port[count].dev ) {
254 pStats = &( lp->wds_port[count].stats );
260 /* If pStats is still NULL, then the device is not a WDS port */
261 if( pStats == NULL ) {
262 pStats = &( lp->stats );
265 wl_unlock( lp, &flags );
269 /*============================================================================*/
271 /*******************************************************************************
273 *******************************************************************************
281 * dev - a pointer to the device's net_device structure
288 ******************************************************************************/
289 int wl_open(struct net_device *dev)
291 int status = HCF_SUCCESS;
292 struct wl_private *lp = wl_priv(dev);
295 wl_lock( lp, &flags );
298 if( lp->useRTS == 1 ) {
299 DBG_TRACE( DbgInfo, "Skipping device open, in RTS mode\n" );
300 wl_unlock( lp, &flags );
309 if( lp->portState == WVLAN_PORT_STATE_DISABLED ) {
310 DBG_TRACE( DbgInfo, "Enabling Port 0\n" );
311 status = wl_enable( lp );
313 if( status != HCF_SUCCESS ) {
314 DBG_TRACE( DbgInfo, "Enable port 0 failed: 0x%x\n", status );
318 // Holding the lock too long, make a gap to allow other processes
319 wl_unlock(lp, &flags);
320 wl_lock( lp, &flags );
322 if ( strlen( lp->fw_image_filename ) ) {
323 DBG_TRACE( DbgInfo, ";???? Kludgy way to force a download\n" );
324 status = wl_go( lp );
326 status = wl_apply( lp );
329 // Holding the lock too long, make a gap to allow other processes
330 wl_unlock(lp, &flags);
331 wl_lock( lp, &flags );
333 if( status != HCF_SUCCESS ) {
334 // Unsuccessful, try reset of the card to recover
335 status = wl_reset( dev );
338 // Holding the lock too long, make a gap to allow other processes
339 wl_unlock(lp, &flags);
340 wl_lock( lp, &flags );
342 if( status == HCF_SUCCESS ) {
343 netif_carrier_on( dev );
344 WL_WDS_NETIF_CARRIER_ON( lp );
346 lp->is_handling_int = WL_HANDLING_INT; // Start handling interrupts
349 netif_start_queue( dev );
350 WL_WDS_NETIF_START_QUEUE( lp );
352 wl_hcf_error( dev, status ); /* Report the error */
353 netif_device_detach( dev ); /* Stop the device and queue */
356 wl_unlock( lp, &flags );
360 /*============================================================================*/
362 /*******************************************************************************
364 *******************************************************************************
372 * dev - a pointer to the device's net_device structure
379 ******************************************************************************/
380 int wl_close( struct net_device *dev )
382 struct wl_private *lp = wl_priv(dev);
385 DBG_PARAM(DbgInfo, "dev", "%s (0x%p)", dev->name, dev);
387 /* Mark the adapter as busy */
388 netif_stop_queue( dev );
389 WL_WDS_NETIF_STOP_QUEUE( lp );
391 netif_carrier_off( dev );
392 WL_WDS_NETIF_CARRIER_OFF( lp );
394 /* Shutdown the adapter:
395 Disable adapter interrupts
401 wl_lock( lp, &flags );
403 wl_act_int_off( lp );
404 lp->is_handling_int = WL_NOT_HANDLING_INT; // Stop handling interrupts
407 if( lp->useRTS == 1 ) {
408 DBG_TRACE( DbgInfo, "Skipping device close, in RTS mode\n" );
409 wl_unlock( lp, &flags );
414 /* Disable the ports */
417 wl_unlock( lp, &flags );
421 /*============================================================================*/
423 static void wl_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
425 strlcpy(info->driver, DRIVER_NAME, sizeof(info->driver));
426 strlcpy(info->version, DRV_VERSION_STR, sizeof(info->version));
427 // strlcpy(info.fw_version, priv->fw_name,
428 // sizeof(info.fw_version));
430 if (dev->dev.parent) {
431 dev_set_name(dev->dev.parent, "%s", info->bus_info);
432 //strlcpy(info->bus_info, dev->dev.parent->bus_id,
433 // sizeof(info->bus_info));
435 snprintf(info->bus_info, sizeof(info->bus_info),
437 // "PCMCIA 0x%lx", priv->hw.iobase);
441 static struct ethtool_ops wl_ethtool_ops = {
442 .get_drvinfo = wl_get_drvinfo,
443 .get_link = ethtool_op_get_link,
447 /*******************************************************************************
449 *******************************************************************************
453 * The IOCTL handler for the device.
457 * dev - a pointer to the device's net_device struct.
458 * rq - a pointer to the IOCTL request buffer.
459 * cmd - the IOCTL command code.
464 * errno value otherwise
466 ******************************************************************************/
467 int wl_ioctl( struct net_device *dev, struct ifreq *rq, int cmd )
469 struct wl_private *lp = wl_priv(dev);
473 DBG_PARAM(DbgInfo, "dev", "%s (0x%p)", dev->name, dev);
474 DBG_PARAM(DbgInfo, "rq", "0x%p", rq);
475 DBG_PARAM(DbgInfo, "cmd", "0x%04x", cmd);
477 wl_lock( lp, &flags );
479 wl_act_int_off( lp );
482 if( lp->useRTS == 1 ) {
483 /* Handle any RTS IOCTL here */
484 if( cmd == WL_IOCTL_RTS ) {
485 DBG_TRACE( DbgInfo, "IOCTL: WL_IOCTL_RTS\n" );
486 ret = wvlan_rts( (struct rtsreq *)rq, dev->base_addr );
488 DBG_TRACE( DbgInfo, "IOCTL not supported in RTS mode: 0x%X\n", cmd );
492 goto out_act_int_on_unlock;
496 /* Only handle UIL IOCTL requests when the UIL has the system blocked. */
497 if( !(( lp->flags & WVLAN2_UIL_BUSY ) && ( cmd != WVLAN2_IOCTL_UIL ))) {
499 struct uilreq *urq = (struct uilreq *)rq;
503 // ================== Private IOCTLs (up to 16) ==================
505 case WVLAN2_IOCTL_UIL:
506 DBG_TRACE( DbgInfo, "IOCTL: WVLAN2_IOCTL_UIL\n" );
507 ret = wvlan_uil( urq, lp );
512 DBG_TRACE(DbgInfo, "IOCTL CODE NOT SUPPORTED: 0x%X\n", cmd );
517 DBG_WARNING( DbgInfo, "DEVICE IS BUSY, CANNOT PROCESS REQUEST\n" );
522 out_act_int_on_unlock:
526 wl_unlock( lp, &flags );
530 /*============================================================================*/
532 #ifdef CONFIG_NET_POLL_CONTROLLER
533 void wl_poll(struct net_device *dev)
535 struct wl_private *lp = wl_priv(dev);
539 wl_lock( lp, &flags );
540 wl_isr(dev->irq, dev, ®s);
541 wl_unlock( lp, &flags );
545 /*******************************************************************************
547 *******************************************************************************
551 * The handler called when, for some reason, a Tx request is not completed.
555 * dev - a pointer to the device's net_device struct.
561 ******************************************************************************/
562 void wl_tx_timeout( struct net_device *dev )
568 struct wl_private *lp = wl_priv(dev);
569 struct net_device_stats *pStats = NULL;
571 DBG_WARNING( DbgInfo, "%s: Transmit timeout.\n", dev->name );
573 wl_lock( lp, &flags );
576 if( lp->useRTS == 1 ) {
577 DBG_TRACE( DbgInfo, "Skipping tx_timeout handler, in RTS mode\n" );
578 wl_unlock( lp, &flags );
583 /* Figure out which device (the "root" device or WDS port) this timeout
587 for( count = 0; count < NUM_WDS_PORTS; count++ ) {
588 if( dev == lp->wds_port[count].dev ) {
589 pStats = &( lp->wds_port[count].stats );
591 /* Break the loop so that we can use the counter to access WDS
592 information in the private structure */
599 /* If pStats is still NULL, then the device is not a WDS port */
600 if( pStats == NULL ) {
601 pStats = &( lp->stats );
604 /* Accumulate the timeout error */
607 wl_unlock( lp, &flags );
609 /*============================================================================*/
611 /*******************************************************************************
613 *******************************************************************************
617 * The routine which performs data transmits.
621 * lp - a pointer to the device's wl_private struct.
628 ******************************************************************************/
629 int wl_send( struct wl_private *lp )
634 WVLAN_LFRAME *txF = NULL;
635 struct list_head *element;
637 /*------------------------------------------------------------------------*/
640 DBG_ERROR( DbgInfo, "Private adapter struct is NULL\n" );
643 if( lp->dev == NULL ) {
644 DBG_ERROR( DbgInfo, "net_device struct in wl_private is NULL\n" );
648 /* Check for the availability of FIDs; if none are available, don't take any
649 frames off the txQ */
650 if( lp->hcfCtx.IFB_RscInd == 0 ) {
654 /* Reclaim the TxQ Elements and place them back on the free queue */
655 if( !list_empty( &( lp->txQ[0] ))) {
656 element = lp->txQ[0].next;
658 txF = (WVLAN_LFRAME * )list_entry( element, WVLAN_LFRAME, node );
660 lp->txF.skb = txF->frame.skb;
661 lp->txF.port = txF->frame.port;
663 txF->frame.skb = NULL;
666 list_del( &( txF->node ));
667 list_add( element, &( lp->txFree ));
671 if( lp->txQ_count < TX_Q_LOW_WATER_MARK ) {
672 if( lp->netif_queue_on == FALSE ) {
673 DBG_TX( DbgInfo, "Kickstarting Q: %d\n", lp->txQ_count );
674 netif_wake_queue( lp->dev );
675 WL_WDS_NETIF_WAKE_QUEUE( lp );
676 lp->netif_queue_on = TRUE;
682 if( lp->txF.skb == NULL ) {
686 /* If the device has resources (FIDs) available, then Tx the packet */
687 /* Format the TxRequest and send it to the adapter */
688 len = lp->txF.skb->len < ETH_ZLEN ? ETH_ZLEN : lp->txF.skb->len;
690 desc = &( lp->desc_tx );
691 desc->buf_addr = lp->txF.skb->data;
693 desc->next_desc_addr = NULL;
695 status = hcf_send_msg( &( lp->hcfCtx ), desc, lp->txF.port );
697 if( status == HCF_SUCCESS ) {
698 lp->dev->trans_start = jiffies;
700 DBG_TX( DbgInfo, "Transmit...\n" );
702 if( lp->txF.port == HCF_PORT_0 ) {
703 lp->stats.tx_packets++;
704 lp->stats.tx_bytes += lp->txF.skb->len;
710 lp->wds_port[(( lp->txF.port >> 8 ) - 1)].stats.tx_packets++;
711 lp->wds_port[(( lp->txF.port >> 8 ) - 1)].stats.tx_bytes += lp->txF.skb->len;
716 /* Free the skb and perform queue cleanup, as the buffer was
717 transmitted successfully */
718 dev_kfree_skb( lp->txF.skb );
726 /*============================================================================*/
728 /*******************************************************************************
730 *******************************************************************************
734 * The Tx handler function for the network layer.
738 * skb - a pointer to the sk_buff structure containing the data to transfer.
739 * dev - a pointer to the device's net_device structure.
746 ******************************************************************************/
747 int wl_tx( struct sk_buff *skb, struct net_device *dev, int port )
750 struct wl_private *lp = wl_priv(dev);
751 WVLAN_LFRAME *txF = NULL;
752 struct list_head *element;
753 /*------------------------------------------------------------------------*/
755 /* Grab the spinlock */
756 wl_lock( lp, &flags );
758 if( lp->flags & WVLAN2_UIL_BUSY ) {
759 DBG_WARNING( DbgInfo, "UIL has device blocked\n" );
760 /* Start dropping packets here??? */
761 wl_unlock( lp, &flags );
766 if( lp->useRTS == 1 ) {
767 DBG_PRINT( "RTS: we're getting a Tx...\n" );
768 wl_unlock( lp, &flags );
774 /* Get an element from the queue */
775 element = lp->txFree.next;
776 txF = (WVLAN_LFRAME *)list_entry( element, WVLAN_LFRAME, node );
778 DBG_ERROR( DbgInfo, "Problem with list_entry\n" );
779 wl_unlock( lp, &flags );
782 /* Fill out the frame */
783 txF->frame.skb = skb;
784 txF->frame.port = port;
785 /* Move the frame to the txQ */
786 /* NOTE: Here's where we would do priority queueing */
787 list_move(&(txF->node), &(lp->txQ[0]));
790 if( lp->txQ_count >= DEFAULT_NUM_TX_FRAMES ) {
791 DBG_TX( DbgInfo, "Q Full: %d\n", lp->txQ_count );
792 if( lp->netif_queue_on == TRUE ) {
793 netif_stop_queue( lp->dev );
794 WL_WDS_NETIF_STOP_QUEUE( lp );
795 lp->netif_queue_on = FALSE;
799 wl_act_int_off( lp ); /* Disable Interrupts */
801 /* Send the data to the hardware using the appropriate method */
804 wl_send_dma( lp, skb, port );
811 /* Re-enable Interrupts, release the spinlock and return */
813 wl_unlock( lp, &flags );
816 /*============================================================================*/
818 /*******************************************************************************
820 *******************************************************************************
824 * The routine which performs data reception.
828 * dev - a pointer to the device's net_device structure.
835 ******************************************************************************/
836 int wl_rx(struct net_device *dev)
840 struct wl_private *lp = wl_priv(dev);
845 /*------------------------------------------------------------------------*/
847 DBG_PARAM(DbgInfo, "dev", "%s (0x%p)", dev->name, dev);
849 if(!( lp->flags & WVLAN2_UIL_BUSY )) {
852 if( lp->useRTS == 1 ) {
853 DBG_PRINT( "RTS: We're getting an Rx...\n" );
858 /* Read the HFS_STAT register from the lookahead buffer */
859 hfs_stat = (hcf_16)(( lp->lookAheadBuf[HFS_STAT] ) |
860 ( lp->lookAheadBuf[HFS_STAT + 1] << 8 ));
862 /* Make sure the frame isn't bad */
863 if(( hfs_stat & HFS_STAT_ERR ) != HCF_SUCCESS ) {
864 DBG_WARNING( DbgInfo, "HFS_STAT_ERROR (0x%x) in Rx Packet\n",
865 lp->lookAheadBuf[HFS_STAT] );
869 /* Determine what port this packet is for */
870 port = ( hfs_stat >> 8 ) & 0x0007;
871 DBG_RX( DbgInfo, "Rx frame for port %d\n", port );
873 pktlen = lp->hcfCtx.IFB_RxLen;
875 skb = ALLOC_SKB(pktlen);
877 /* Set the netdev based on the port */
886 skb->dev = lp->wds_port[port-1].dev;
896 desc = &( lp->desc_rx );
898 desc->next_desc_addr = NULL;
901 #define BLOCK_INPUT(buf, len) \
902 desc->buf_addr = buf; \
903 desc->BUF_SIZE = len; \
904 status = hcf_rcv_msg(&(lp->hcfCtx), desc, 0)
907 GET_PACKET( skb->dev, skb, pktlen );
909 if( status == HCF_SUCCESS ) {
913 lp->stats.rx_packets++;
914 lp->stats.rx_bytes += pktlen;
919 lp->wds_port[port-1].stats.rx_packets++;
920 lp->wds_port[port-1].stats.rx_bytes += pktlen;
924 dev->last_rx = jiffies;
928 if( lp->spydata.spy_number > 0 ) {
929 char *srcaddr = skb->mac.raw + MAC_ADDR_SIZE;
931 wl_spy_gather( dev, srcaddr );
933 #endif /* WIRELESS_SPY */
934 #endif /* WIRELESS_EXT */
936 DBG_ERROR( DbgInfo, "Rx request to card FAILED\n" );
939 lp->stats.rx_dropped++;
944 lp->wds_port[port-1].stats.rx_dropped++;
948 dev_kfree_skb( skb );
951 DBG_ERROR( DbgInfo, "Could not alloc skb\n" );
954 lp->stats.rx_dropped++;
959 lp->wds_port[port-1].stats.rx_dropped++;
968 /*============================================================================*/
970 /*******************************************************************************
972 *******************************************************************************
976 * Function to handle multicast packets
980 * dev - a pointer to the device's net_device structure.
986 ******************************************************************************/
989 void wl_multicast( struct net_device *dev )
991 #if 1 //;? (HCF_TYPE) & HCF_TYPE_STA //;?should we return an error status in AP mode
992 //;?seems reasonable that even an AP-only driver could afford this small additional footprint
995 struct netdev_hw_addr *ha;
996 struct wl_private *lp = wl_priv(dev);
999 DBG_PARAM( DbgInfo, "dev", "%s (0x%p)", dev->name, dev );
1001 if( !wl_adapter_is_open( dev ))
1005 if( DBG_FLAGS( DbgInfo ) & DBG_PARAM_ON ) {
1006 DBG_PRINT(" flags: %s%s%s\n",
1007 ( dev->flags & IFF_PROMISC ) ? "Promiscuous " : "",
1008 ( dev->flags & IFF_MULTICAST ) ? "Multicast " : "",
1009 ( dev->flags & IFF_ALLMULTI ) ? "All-Multicast" : "" );
1011 DBG_PRINT( " mc_count: %d\n", netdev_mc_count(dev));
1013 netdev_for_each_mc_addr(ha, dev)
1014 DBG_PRINT(" %pM (%d)\n", ha->addr, dev->addr_len);
1018 if(!( lp->flags & WVLAN2_UIL_BUSY )) {
1021 if( lp->useRTS == 1 ) {
1022 DBG_TRACE( DbgInfo, "Skipping multicast, in RTS mode\n" );
1025 #endif /* USE_RTS */
1027 wl_lock( lp, &flags );
1028 wl_act_int_off( lp );
1030 if ( CNV_INT_TO_LITTLE( lp->hcfCtx.IFB_FWIdentity.comp_id ) == COMP_ID_FW_STA ) {
1031 if( dev->flags & IFF_PROMISC ) {
1032 /* Enable promiscuous mode */
1033 lp->ltvRecord.len = 2;
1034 lp->ltvRecord.typ = CFG_PROMISCUOUS_MODE;
1035 lp->ltvRecord.u.u16[0] = CNV_INT_TO_LITTLE( 1 );
1036 DBG_PRINT( "Enabling Promiscuous mode (IFF_PROMISC)\n" );
1037 hcf_put_info( &( lp->hcfCtx ), (LTVP)&( lp->ltvRecord ));
1039 else if ((netdev_mc_count(dev) > HCF_MAX_MULTICAST) ||
1040 ( dev->flags & IFF_ALLMULTI )) {
1041 /* Shutting off this filter will enable all multicast frames to
1042 be sent up from the device; however, this is a static RID, so
1043 a call to wl_apply() is needed */
1044 lp->ltvRecord.len = 2;
1045 lp->ltvRecord.typ = CFG_CNF_RX_ALL_GROUP_ADDR;
1046 lp->ltvRecord.u.u16[0] = CNV_INT_TO_LITTLE( 0 );
1047 DBG_PRINT( "Enabling all multicast mode (IFF_ALLMULTI)\n" );
1048 hcf_put_info( &( lp->hcfCtx ), (LTVP)&( lp->ltvRecord ));
1051 else if (!netdev_mc_empty(dev)) {
1052 /* Set the multicast addresses */
1053 lp->ltvRecord.len = ( netdev_mc_count(dev) * 3 ) + 1;
1054 lp->ltvRecord.typ = CFG_GROUP_ADDR;
1057 netdev_for_each_mc_addr(ha, dev)
1058 memcpy(&(lp->ltvRecord.u.u8[x++ * ETH_ALEN]),
1059 ha->addr, ETH_ALEN);
1060 DBG_PRINT( "Setting multicast list\n" );
1061 hcf_put_info( &( lp->hcfCtx ), (LTVP)&( lp->ltvRecord ));
1063 /* Disable promiscuous mode */
1064 lp->ltvRecord.len = 2;
1065 lp->ltvRecord.typ = CFG_PROMISCUOUS_MODE;
1066 lp->ltvRecord.u.u16[0] = CNV_INT_TO_LITTLE( 0 );
1067 DBG_PRINT( "Disabling Promiscuous mode\n" );
1068 hcf_put_info( &( lp->hcfCtx ), (LTVP)&( lp->ltvRecord ));
1070 /* Disable multicast mode */
1071 lp->ltvRecord.len = 2;
1072 lp->ltvRecord.typ = CFG_GROUP_ADDR;
1073 DBG_PRINT( "Disabling Multicast mode\n" );
1074 hcf_put_info( &( lp->hcfCtx ), (LTVP)&( lp->ltvRecord ));
1076 /* Turning on this filter will prevent all multicast frames from
1077 being sent up from the device; however, this is a static RID,
1078 so a call to wl_apply() is needed */
1079 lp->ltvRecord.len = 2;
1080 lp->ltvRecord.typ = CFG_CNF_RX_ALL_GROUP_ADDR;
1081 lp->ltvRecord.u.u16[0] = CNV_INT_TO_LITTLE( 1 );
1082 DBG_PRINT( "Disabling all multicast mode (IFF_ALLMULTI)\n" );
1083 hcf_put_info( &( lp->hcfCtx ), (LTVP)&( lp->ltvRecord ));
1087 wl_act_int_on( lp );
1088 wl_unlock( lp, &flags );
1090 #endif /* HCF_STA */
1092 /*============================================================================*/
1094 #else /* NEW_MULTICAST */
1096 void wl_multicast( struct net_device *dev, int num_addrs, void *addrs )
1098 DBG_PARAM( DbgInfo, "dev", "%s (0x%p)", dev->name, dev );
1099 DBG_PARAM( DbgInfo, "num_addrs", "%d", num_addrs );
1100 DBG_PARAM( DbgInfo, "addrs", "0x%p", addrs );
1102 #error Obsolete set multicast interface!
1104 /*============================================================================*/
1106 #endif /* NEW_MULTICAST */
1108 static const struct net_device_ops wl_netdev_ops =
1110 .ndo_start_xmit = &wl_tx_port0,
1112 .ndo_set_config = &wl_config,
1113 .ndo_get_stats = &wl_stats,
1114 .ndo_set_rx_mode = &wl_multicast,
1116 .ndo_init = &wl_insert,
1117 .ndo_open = &wl_adapter_open,
1118 .ndo_stop = &wl_adapter_close,
1119 .ndo_do_ioctl = &wl_ioctl,
1121 .ndo_tx_timeout = &wl_tx_timeout,
1123 #ifdef CONFIG_NET_POLL_CONTROLLER
1124 .ndo_poll_controller = wl_poll,
1128 /*******************************************************************************
1130 *******************************************************************************
1134 * Create instances of net_device and wl_private for the new adapter
1135 * and register the device's entry points in the net_device structure.
1143 * a pointer to an allocated and initialized net_device struct for this
1146 ******************************************************************************/
1147 struct net_device * wl_device_alloc( void )
1149 struct net_device *dev = NULL;
1150 struct wl_private *lp = NULL;
1152 /* Alloc a net_device struct */
1153 dev = alloc_etherdev(sizeof(struct wl_private));
1157 /* Initialize the 'next' pointer in the struct. Currently only used for PCI,
1158 but do it here just in case it's used for other buses in the future */
1163 if( dev->mtu > MTU_MAX )
1165 DBG_WARNING( DbgInfo, "%s: MTU set too high, limiting to %d.\n",
1166 dev->name, MTU_MAX );
1170 /* Setup the function table in the device structure. */
1172 dev->wireless_handlers = (struct iw_handler_def *)&wl_iw_handler_def;
1173 lp->wireless_data.spy_data = &lp->spy_data;
1174 dev->wireless_data = &lp->wireless_data;
1176 dev->netdev_ops = &wl_netdev_ops;
1178 dev->watchdog_timeo = TX_TIMEOUT;
1180 dev->ethtool_ops = &wl_ethtool_ops;
1182 netif_stop_queue( dev );
1184 /* Allocate virtual devices for WDS support if needed */
1185 WL_WDS_DEVICE_ALLOC( lp );
1188 } // wl_device_alloc
1189 /*============================================================================*/
1191 /*******************************************************************************
1192 * wl_device_dealloc()
1193 *******************************************************************************
1197 * Free instances of net_device and wl_private strcutres for an adapter
1198 * and perform basic cleanup.
1202 * dev - a pointer to the device's net_device structure.
1208 ******************************************************************************/
1209 void wl_device_dealloc( struct net_device *dev )
1211 // struct wl_private *lp = wl_priv(dev);
1213 /* Dealloc the WDS ports */
1214 WL_WDS_DEVICE_DEALLOC( lp );
1217 } // wl_device_dealloc
1218 /*============================================================================*/
1220 /*******************************************************************************
1222 *******************************************************************************
1226 * The handler routine for Tx over HCF_PORT_0.
1230 * skb - a pointer to the sk_buff to transmit.
1231 * dev - a pointer to a net_device structure representing HCF_PORT_0.
1237 ******************************************************************************/
1238 int wl_tx_port0( struct sk_buff *skb, struct net_device *dev )
1240 DBG_TX( DbgInfo, "Tx on Port 0\n" );
1242 return wl_tx( skb, dev, HCF_PORT_0 );
1244 return wl_tx_dma( skb, dev, HCF_PORT_0 );
1247 /*============================================================================*/
1251 /*******************************************************************************
1253 *******************************************************************************
1257 * The handler routine for Tx over HCF_PORT_1.
1261 * skb - a pointer to the sk_buff to transmit.
1262 * dev - a pointer to a net_device structure representing HCF_PORT_1.
1268 ******************************************************************************/
1269 int wl_tx_port1( struct sk_buff *skb, struct net_device *dev )
1271 DBG_TX( DbgInfo, "Tx on Port 1\n" );
1272 return wl_tx( skb, dev, HCF_PORT_1 );
1274 /*============================================================================*/
1276 /*******************************************************************************
1278 *******************************************************************************
1282 * The handler routine for Tx over HCF_PORT_2.
1286 * skb - a pointer to the sk_buff to transmit.
1287 * dev - a pointer to a net_device structure representing HCF_PORT_2.
1293 ******************************************************************************/
1294 int wl_tx_port2( struct sk_buff *skb, struct net_device *dev )
1296 DBG_TX( DbgInfo, "Tx on Port 2\n" );
1297 return wl_tx( skb, dev, HCF_PORT_2 );
1299 /*============================================================================*/
1301 /*******************************************************************************
1303 *******************************************************************************
1307 * The handler routine for Tx over HCF_PORT_3.
1311 * skb - a pointer to the sk_buff to transmit.
1312 * dev - a pointer to a net_device structure representing HCF_PORT_3.
1318 ******************************************************************************/
1319 int wl_tx_port3( struct sk_buff *skb, struct net_device *dev )
1321 DBG_TX( DbgInfo, "Tx on Port 3\n" );
1322 return wl_tx( skb, dev, HCF_PORT_3 );
1324 /*============================================================================*/
1326 /*******************************************************************************
1328 *******************************************************************************
1332 * The handler routine for Tx over HCF_PORT_4.
1336 * skb - a pointer to the sk_buff to transmit.
1337 * dev - a pointer to a net_device structure representing HCF_PORT_4.
1343 ******************************************************************************/
1344 int wl_tx_port4( struct sk_buff *skb, struct net_device *dev )
1346 DBG_TX( DbgInfo, "Tx on Port 4\n" );
1347 return wl_tx( skb, dev, HCF_PORT_4 );
1349 /*============================================================================*/
1351 /*******************************************************************************
1353 *******************************************************************************
1357 * The handler routine for Tx over HCF_PORT_5.
1361 * skb - a pointer to the sk_buff to transmit.
1362 * dev - a pointer to a net_device structure representing HCF_PORT_5.
1368 ******************************************************************************/
1369 int wl_tx_port5( struct sk_buff *skb, struct net_device *dev )
1371 DBG_TX( DbgInfo, "Tx on Port 5\n" );
1372 return wl_tx( skb, dev, HCF_PORT_5 );
1374 /*============================================================================*/
1376 /*******************************************************************************
1378 *******************************************************************************
1382 * The handler routine for Tx over HCF_PORT_6.
1386 * skb - a pointer to the sk_buff to transmit.
1387 * dev - a pointer to a net_device structure representing HCF_PORT_6.
1393 ******************************************************************************/
1394 int wl_tx_port6( struct sk_buff *skb, struct net_device *dev )
1396 DBG_TX( DbgInfo, "Tx on Port 6\n" );
1397 return wl_tx( skb, dev, HCF_PORT_6 );
1399 /*============================================================================*/
1401 /*******************************************************************************
1402 * wl_wds_device_alloc()
1403 *******************************************************************************
1407 * Create instances of net_device to represent the WDS ports, and register
1408 * the device's entry points in the net_device structure.
1412 * lp - a pointer to the device's private adapter structure
1416 * N/A, but will place pointers to the allocated and initialized net_device
1417 * structs in the private adapter structure.
1419 ******************************************************************************/
1420 void wl_wds_device_alloc( struct wl_private *lp )
1424 /* WDS support requires additional net_device structs to be allocated,
1425 so that user space apps can use these virtual devices to specify the
1426 port on which to Tx/Rx */
1427 for( count = 0; count < NUM_WDS_PORTS; count++ ) {
1428 struct net_device *dev_wds = NULL;
1430 dev_wds = kzalloc(sizeof(struct net_device), GFP_KERNEL);
1434 ether_setup( dev_wds );
1436 lp->wds_port[count].dev = dev_wds;
1438 /* Re-use wl_init for all the devices, as it currently does nothing, but
1439 is required. Re-use the stats/tx_timeout handler for all as well; the
1440 WDS port which is requesting these operations can be determined by
1441 the net_device pointer. Set the private member of all devices to point
1442 to the same net_device struct; that way, all information gets
1443 funnelled through the one "real" net_device. Name the WDS ports
1445 lp->wds_port[count].dev->init = &wl_init;
1446 lp->wds_port[count].dev->get_stats = &wl_stats;
1447 lp->wds_port[count].dev->tx_timeout = &wl_tx_timeout;
1448 lp->wds_port[count].dev->watchdog_timeo = TX_TIMEOUT;
1449 lp->wds_port[count].dev->priv = lp;
1451 sprintf( lp->wds_port[count].dev->name, "wds%d", count );
1454 /* Register the Tx handlers */
1455 lp->wds_port[0].dev->hard_start_xmit = &wl_tx_port1;
1456 lp->wds_port[1].dev->hard_start_xmit = &wl_tx_port2;
1457 lp->wds_port[2].dev->hard_start_xmit = &wl_tx_port3;
1458 lp->wds_port[3].dev->hard_start_xmit = &wl_tx_port4;
1459 lp->wds_port[4].dev->hard_start_xmit = &wl_tx_port5;
1460 lp->wds_port[5].dev->hard_start_xmit = &wl_tx_port6;
1462 WL_WDS_NETIF_STOP_QUEUE( lp );
1463 } // wl_wds_device_alloc
1464 /*============================================================================*/
1466 /*******************************************************************************
1467 * wl_wds_device_dealloc()
1468 *******************************************************************************
1472 * Free instances of net_device structures used to support WDS.
1476 * lp - a pointer to the device's private adapter structure
1482 ******************************************************************************/
1483 void wl_wds_device_dealloc( struct wl_private *lp )
1487 for( count = 0; count < NUM_WDS_PORTS; count++ ) {
1488 struct net_device *dev_wds = NULL;
1490 dev_wds = lp->wds_port[count].dev;
1492 if( dev_wds != NULL ) {
1493 if( dev_wds->flags & IFF_UP ) {
1494 dev_close( dev_wds );
1495 dev_wds->flags &= ~( IFF_UP | IFF_RUNNING );
1498 free_netdev(dev_wds);
1499 lp->wds_port[count].dev = NULL;
1502 } // wl_wds_device_dealloc
1503 /*============================================================================*/
1505 /*******************************************************************************
1506 * wl_wds_netif_start_queue()
1507 *******************************************************************************
1511 * Used to start the netif queues of all the "virtual" network devices
1512 * which represent the WDS ports.
1516 * lp - a pointer to the device's private adapter structure
1522 ******************************************************************************/
1523 void wl_wds_netif_start_queue( struct wl_private *lp )
1526 /*------------------------------------------------------------------------*/
1529 for( count = 0; count < NUM_WDS_PORTS; count++ ) {
1530 if( lp->wds_port[count].is_registered &&
1531 lp->wds_port[count].netif_queue_on == FALSE ) {
1532 netif_start_queue( lp->wds_port[count].dev );
1533 lp->wds_port[count].netif_queue_on = TRUE;
1537 } // wl_wds_netif_start_queue
1538 /*============================================================================*/
1540 /*******************************************************************************
1541 * wl_wds_netif_stop_queue()
1542 *******************************************************************************
1546 * Used to stop the netif queues of all the "virtual" network devices
1547 * which represent the WDS ports.
1551 * lp - a pointer to the device's private adapter structure
1557 ******************************************************************************/
1558 void wl_wds_netif_stop_queue( struct wl_private *lp )
1561 /*------------------------------------------------------------------------*/
1564 for( count = 0; count < NUM_WDS_PORTS; count++ ) {
1565 if( lp->wds_port[count].is_registered &&
1566 lp->wds_port[count].netif_queue_on == TRUE ) {
1567 netif_stop_queue( lp->wds_port[count].dev );
1568 lp->wds_port[count].netif_queue_on = FALSE;
1572 } // wl_wds_netif_stop_queue
1573 /*============================================================================*/
1575 /*******************************************************************************
1576 * wl_wds_netif_wake_queue()
1577 *******************************************************************************
1581 * Used to wake the netif queues of all the "virtual" network devices
1582 * which represent the WDS ports.
1586 * lp - a pointer to the device's private adapter structure
1592 ******************************************************************************/
1593 void wl_wds_netif_wake_queue( struct wl_private *lp )
1596 /*------------------------------------------------------------------------*/
1599 for( count = 0; count < NUM_WDS_PORTS; count++ ) {
1600 if( lp->wds_port[count].is_registered &&
1601 lp->wds_port[count].netif_queue_on == FALSE ) {
1602 netif_wake_queue( lp->wds_port[count].dev );
1603 lp->wds_port[count].netif_queue_on = TRUE;
1607 } // wl_wds_netif_wake_queue
1608 /*============================================================================*/
1610 /*******************************************************************************
1611 * wl_wds_netif_carrier_on()
1612 *******************************************************************************
1616 * Used to signal the network layer that carrier is present on all of the
1617 * "virtual" network devices which represent the WDS ports.
1621 * lp - a pointer to the device's private adapter structure
1627 ******************************************************************************/
1628 void wl_wds_netif_carrier_on( struct wl_private *lp )
1631 /*------------------------------------------------------------------------*/
1634 for( count = 0; count < NUM_WDS_PORTS; count++ ) {
1635 if( lp->wds_port[count].is_registered ) {
1636 netif_carrier_on( lp->wds_port[count].dev );
1640 } // wl_wds_netif_carrier_on
1641 /*============================================================================*/
1643 /*******************************************************************************
1644 * wl_wds_netif_carrier_off()
1645 *******************************************************************************
1649 * Used to signal the network layer that carrier is NOT present on all of
1650 * the "virtual" network devices which represent the WDS ports.
1654 * lp - a pointer to the device's private adapter structure
1660 ******************************************************************************/
1661 void wl_wds_netif_carrier_off( struct wl_private *lp )
1666 for(count = 0; count < NUM_WDS_PORTS; count++) {
1667 if(lp->wds_port[count].is_registered)
1668 netif_carrier_off(lp->wds_port[count].dev);
1672 } // wl_wds_netif_carrier_off
1673 /*============================================================================*/
1675 #endif /* USE_WDS */
1678 /*******************************************************************************
1680 *******************************************************************************
1684 * The routine which performs data transmits when using busmaster DMA.
1688 * lp - a pointer to the device's wl_private struct.
1689 * skb - a pointer to the network layer's data buffer.
1690 * port - the Hermes port on which to transmit.
1697 ******************************************************************************/
1698 int wl_send_dma( struct wl_private *lp, struct sk_buff *skb, int port )
1701 DESC_STRCT *desc = NULL;
1702 DESC_STRCT *desc_next = NULL;
1703 /*------------------------------------------------------------------------*/
1706 DBG_ERROR( DbgInfo, "Private adapter struct is NULL\n" );
1710 if( lp->dev == NULL ) {
1711 DBG_ERROR( DbgInfo, "net_device struct in wl_private is NULL\n" );
1715 /* AGAIN, ALL THE QUEUEING DONE HERE IN I/O MODE IS NOT PERFORMED */
1718 DBG_WARNING (DbgInfo, "Nothing to send.\n");
1724 /* Get a free descriptor */
1725 desc = wl_pci_dma_get_tx_packet( lp );
1727 if( desc == NULL ) {
1728 if( lp->netif_queue_on == TRUE ) {
1729 netif_stop_queue( lp->dev );
1730 WL_WDS_NETIF_STOP_QUEUE( lp );
1731 lp->netif_queue_on = FALSE;
1733 dev_kfree_skb( skb );
1738 SET_BUF_CNT( desc, /*HCF_DMA_FD_CNT*/HFS_ADDR_DEST );
1739 SET_BUF_SIZE( desc, HCF_DMA_TX_BUF1_SIZE );
1741 desc_next = desc->next_desc_addr;
1743 if( desc_next->buf_addr == NULL ) {
1744 DBG_ERROR( DbgInfo, "DMA descriptor buf_addr is NULL\n" );
1748 /* Copy the payload into the DMA packet */
1749 memcpy( desc_next->buf_addr, skb->data, len );
1751 SET_BUF_CNT( desc_next, len );
1752 SET_BUF_SIZE( desc_next, HCF_MAX_PACKET_SIZE );
1754 hcf_dma_tx_put( &( lp->hcfCtx ), desc, 0 );
1756 /* Free the skb and perform queue cleanup, as the buffer was
1757 transmitted successfully */
1758 dev_kfree_skb( skb );
1762 /*============================================================================*/
1764 /*******************************************************************************
1766 *******************************************************************************
1770 * The routine which performs data reception when using busmaster DMA.
1774 * dev - a pointer to the device's net_device structure.
1781 ******************************************************************************/
1782 int wl_rx_dma( struct net_device *dev )
1787 struct sk_buff *skb;
1788 struct wl_private *lp = NULL;
1789 DESC_STRCT *desc, *desc_next;
1790 //CFG_MB_INFO_RANGE2_STRCT x;
1791 /*------------------------------------------------------------------------*/
1793 DBG_PARAM(DbgInfo, "dev", "%s (0x%p)", dev->name, dev);
1795 if((( lp = dev->priv ) != NULL ) &&
1796 !( lp->flags & WVLAN2_UIL_BUSY )) {
1799 if( lp->useRTS == 1 ) {
1800 DBG_PRINT( "RTS: We're getting an Rx...\n" );
1803 #endif /* USE_RTS */
1805 //if( lp->dma.status == 0 )
1807 desc = hcf_dma_rx_get( &( lp->hcfCtx ));
1811 /* Check and see if we rcvd. a WMP frame */
1813 if((( *(hcf_8 *)&desc->buf_addr[HFS_STAT] ) &
1814 ( HFS_STAT_MSG_TYPE | HFS_STAT_ERR )) == HFS_STAT_WMP_MSG )
1816 DBG_TRACE( DbgInfo, "Got a WMP frame\n" );
1818 x.len = sizeof( CFG_MB_INFO_RANGE2_STRCT ) / sizeof( hcf_16 );
1819 x.typ = CFG_MB_INFO;
1820 x.base_typ = CFG_WMP;
1822 x.frag_buf[0].frag_len = GET_BUF_CNT( descp ) / sizeof( hcf_16 );
1823 x.frag_buf[0].frag_addr = (hcf_8 *) descp->buf_addr ;
1824 x.frag_buf[1].frag_len = ( GET_BUF_CNT( descp->next_desc_addr ) + 1 ) / sizeof( hcf_16 );
1825 x.frag_buf[1].frag_addr = (hcf_8 *) descp->next_desc_addr->buf_addr ;
1827 hcf_put_info( &( lp->hcfCtx ), (LTVP)&x );
1831 desc_next = desc->next_desc_addr;
1833 /* Make sure the buffer isn't empty */
1834 if( GET_BUF_CNT( desc ) == 0 ) {
1835 DBG_WARNING( DbgInfo, "Buffer is empty!\n" );
1837 /* Give the descriptor back to the HCF */
1838 hcf_dma_rx_put( &( lp->hcfCtx ), desc );
1842 /* Read the HFS_STAT register from the lookahead buffer */
1843 hfs_stat = (hcf_16)( desc->buf_addr[HFS_STAT/2] );
1845 /* Make sure the frame isn't bad */
1846 if(( hfs_stat & HFS_STAT_ERR ) != HCF_SUCCESS )
1848 DBG_WARNING( DbgInfo, "HFS_STAT_ERROR (0x%x) in Rx Packet\n",
1849 desc->buf_addr[HFS_STAT/2] );
1851 /* Give the descriptor back to the HCF */
1852 hcf_dma_rx_put( &( lp->hcfCtx ), desc );
1856 /* Determine what port this packet is for */
1857 port = ( hfs_stat >> 8 ) & 0x0007;
1858 DBG_RX( DbgInfo, "Rx frame for port %d\n", port );
1860 pktlen = GET_BUF_CNT(desc_next);
1862 skb = ALLOC_SKB(pktlen);
1872 skb->dev = lp->wds_port[port-1].dev;
1874 #endif /* USE_WDS */
1882 GET_PACKET_DMA( skb->dev, skb, pktlen );
1884 /* Give the descriptor back to the HCF */
1885 hcf_dma_rx_put( &( lp->hcfCtx ), desc );
1890 lp->stats.rx_packets++;
1891 lp->stats.rx_bytes += pktlen;
1896 lp->wds_port[port-1].stats.rx_packets++;
1897 lp->wds_port[port-1].stats.rx_bytes += pktlen;
1899 #endif /* USE_WDS */
1901 dev->last_rx = jiffies;
1904 DBG_ERROR( DbgInfo, "Could not alloc skb\n" );
1908 lp->stats.rx_dropped++;
1913 lp->wds_port[port-1].stats.rx_dropped++;
1915 #endif /* USE_WDS */
1924 /*============================================================================*/
1925 #endif // ENABLE_DMA