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 processing and initialization specific to PCI/miniPCI
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 <wireless/wl_version.h>
67 #include <linux/module.h>
68 #include <linux/kernel.h>
69 #include <linux/errno.h>
70 #include <linux/pci.h>
71 #include <linux/init.h>
72 #include <linux/sched.h>
73 #include <linux/ptrace.h>
74 #include <linux/ctype.h>
75 #include <linux/string.h>
76 //#include <linux/timer.h>
77 #include <linux/interrupt.h>
79 #include <linux/delay.h>
80 #include <asm/system.h>
83 #include <asm/bitops.h>
84 #include <asm/uaccess.h>
86 #include <linux/ethtool.h>
87 #include <linux/netdevice.h>
88 #include <linux/etherdevice.h>
89 #include <linux/skbuff.h>
90 #include <linux/if_arp.h>
91 #include <linux/ioport.h>
93 #include <hcf/debug.h>
99 #include <wireless/wl_if.h>
100 #include <wireless/wl_internal.h>
101 #include <wireless/wl_util.h>
102 #include <wireless/wl_main.h>
103 #include <wireless/wl_netdev.h>
104 #include <wireless/wl_pci.h>
107 /*******************************************************************************
109 ******************************************************************************/
111 extern dbg_info_t *DbgInfo;
114 /* define the PCI device Table Cardname and id tables */
115 static struct pci_device_id wl_pci_tbl[] __devinitdata = {
116 { PCI_DEVICE(PCI_VENDOR_ID_WL_LKM, PCI_DEVICE_ID_WL_LKM_0), },
117 { PCI_DEVICE(PCI_VENDOR_ID_WL_LKM, PCI_DEVICE_ID_WL_LKM_1), },
118 { PCI_DEVICE(PCI_VENDOR_ID_WL_LKM, PCI_DEVICE_ID_WL_LKM_2), },
120 { } /* Terminating entry */
123 MODULE_DEVICE_TABLE(pci, wl_pci_tbl);
125 /*******************************************************************************
126 * function prototypes
127 ******************************************************************************/
128 int __devinit wl_pci_probe( struct pci_dev *pdev,
129 const struct pci_device_id *ent );
130 void __devexit wl_pci_remove(struct pci_dev *pdev);
131 int wl_pci_setup( struct pci_dev *pdev );
132 void wl_pci_enable_cardbus_interrupts( struct pci_dev *pdev );
135 int wl_pci_dma_alloc( struct pci_dev *pdev, struct wl_private *lp );
136 int wl_pci_dma_free( struct pci_dev *pdev, struct wl_private *lp );
137 int wl_pci_dma_alloc_tx_packet( struct pci_dev *pdev, struct wl_private *lp,
139 int wl_pci_dma_free_tx_packet( struct pci_dev *pdev, struct wl_private *lp,
141 int wl_pci_dma_alloc_rx_packet( struct pci_dev *pdev, struct wl_private *lp,
143 int wl_pci_dma_free_rx_packet( struct pci_dev *pdev, struct wl_private *lp,
145 int wl_pci_dma_alloc_desc_and_buf( struct pci_dev *pdev, struct wl_private *lp,
146 DESC_STRCT **desc, int size );
147 int wl_pci_dma_free_desc_and_buf( struct pci_dev *pdev, struct wl_private *lp,
149 int wl_pci_dma_alloc_desc( struct pci_dev *pdev, struct wl_private *lp,
151 int wl_pci_dma_free_desc( struct pci_dev *pdev, struct wl_private *lp,
153 int wl_pci_dma_alloc_buf( struct pci_dev *pdev, struct wl_private *lp,
154 DESC_STRCT *desc, int size );
155 int wl_pci_dma_free_buf( struct pci_dev *pdev, struct wl_private *lp,
158 void wl_pci_dma_hcf_reclaim_rx( struct wl_private *lp );
161 /*******************************************************************************
162 * PCI module function registration
163 ******************************************************************************/
164 static struct pci_driver wl_driver =
167 id_table: wl_pci_tbl,
169 remove: __devexit_p(wl_pci_remove),
174 /*******************************************************************************
175 * wl_adapter_init_module()
176 *******************************************************************************
180 * Called by init_module() to perform PCI-specific driver initialization.
190 ******************************************************************************/
191 int wl_adapter_init_module( void )
194 /*------------------------------------------------------------------------*/
196 DBG_FUNC( "wl_adapter_init_module()" );
197 DBG_ENTER( DbgInfo );
198 DBG_TRACE( DbgInfo, "wl_adapter_init_module() -- PCI\n" );
200 result = pci_register_driver( &wl_driver ); //;?replace with pci_module_init, Rubini pg 490
201 //;? why not do something with the result
203 DBG_LEAVE( DbgInfo );
205 } // wl_adapter_init_module
206 /*============================================================================*/
208 /*******************************************************************************
209 * wl_adapter_cleanup_module()
210 *******************************************************************************
214 * Called by cleanup_module() to perform PCI-specific driver cleanup.
224 ******************************************************************************/
225 void wl_adapter_cleanup_module( void )
227 //;?how comes wl_adapter_cleanup_module is located in a seemingly pci specific module
228 DBG_FUNC( "wl_adapter_cleanup_module" );
229 DBG_ENTER( DbgInfo );
231 //;?DBG_TRACE below feels like nearly redundant in the light of DBG_ENTER above
232 DBG_TRACE( DbgInfo, "wl_adapter_cleanup_module() -- PCI\n" );
234 pci_unregister_driver( &wl_driver );
236 DBG_LEAVE( DbgInfo );
238 } // wl_adapter_cleanup_module
239 /*============================================================================*/
241 /*******************************************************************************
242 * wl_adapter_insert()
243 *******************************************************************************
247 * Called by wl_pci_probe() to continue the process of device insertion.
251 * dev - a pointer to the device's net_device structure
257 ******************************************************************************/
258 int wl_adapter_insert( struct net_device *dev )
261 /*------------------------------------------------------------------------*/
263 DBG_FUNC( "wl_adapter_insert" );
264 DBG_ENTER( DbgInfo );
266 DBG_TRACE( DbgInfo, "wl_adapter_insert() -- PCI\n" );
269 DBG_ERROR( DbgInfo, "net_device pointer is NULL!!!\n" );
270 } else if( dev->priv == NULL ) {
271 DBG_ERROR( DbgInfo, "wl_private pointer is NULL!!!\n" );
272 } else if( wl_insert( dev ) ) { /* Perform remaining device initialization */
275 DBG_TRACE( DbgInfo, "wl_insert() FAILED\n" );
277 DBG_LEAVE( DbgInfo );
279 } // wl_adapter_insert
280 /*============================================================================*/
282 /*******************************************************************************
284 *******************************************************************************
292 * dev - a pointer to the device's net_device structure
298 ******************************************************************************/
299 int wl_adapter_open( struct net_device *dev )
302 int hcf_status = HCF_SUCCESS;
303 /*------------------------------------------------------------------------*/
305 DBG_FUNC( "wl_adapter_open" );
306 DBG_ENTER( DbgInfo );
308 DBG_TRACE( DbgInfo, "wl_adapter_open() -- PCI\n" );
310 hcf_status = wl_open( dev );
312 if( hcf_status != HCF_SUCCESS ) {
316 DBG_LEAVE( DbgInfo );
319 /*============================================================================*/
321 /*******************************************************************************
323 *******************************************************************************
331 * dev - a pointer to the device's net_device structure
337 ******************************************************************************/
338 int wl_adapter_close( struct net_device *dev )
340 DBG_FUNC( "wl_adapter_close" );
341 DBG_ENTER( DbgInfo );
343 DBG_TRACE( DbgInfo, "wl_adapter_close() -- PCI\n" );
344 DBG_TRACE( DbgInfo, "%s: Shutting down adapter.\n", dev->name );
348 DBG_LEAVE( DbgInfo );
350 } // wl_adapter_close
351 /*============================================================================*/
353 /*******************************************************************************
354 * wl_adapter_is_open()
355 *******************************************************************************
359 * Check whether this device is open. Returns
363 * dev - a pointer to the device's net_device structure
367 * nonzero if device is open.
369 ******************************************************************************/
370 int wl_adapter_is_open( struct net_device *dev )
372 /* This function is used in PCMCIA to check the status of the 'open' field
373 in the dev_link_t structure associated with a network device. There
374 doesn't seem to be an analog to this for PCI, and checking the status
375 contained in the net_device structure doesn't have the same effect.
376 For now, return TRUE, but find out if this is necessary for PCI. */
379 } // wl_adapter_is_open
380 /*============================================================================*/
382 /*******************************************************************************
384 *******************************************************************************
388 * Registered in the pci_driver structure, this function is called when the
389 * PCI subsystem finds a new PCI device which matches the infomation contained
390 * in the pci_device_id table.
394 * pdev - a pointer to the device's pci_dev structure
395 * ent - this device's entry in the pci_device_id table
400 * errno value otherwise
402 ******************************************************************************/
403 int __devinit wl_pci_probe( struct pci_dev *pdev,
404 const struct pci_device_id *ent )
407 /*------------------------------------------------------------------------*/
409 DBG_FUNC( "wl_pci_probe" );
410 DBG_ENTER( DbgInfo );
411 DBG_PRINT( "%s\n", VERSION_INFO );
413 result = wl_pci_setup( pdev );
415 DBG_LEAVE( DbgInfo );
419 /*============================================================================*/
421 /*******************************************************************************
423 *******************************************************************************
427 * Registered in the pci_driver structure, this function is called when the
428 * PCI subsystem detects that a PCI device which matches the infomation
429 * contained in the pci_device_id table has been removed.
433 * pdev - a pointer to the device's pci_dev structure
439 ******************************************************************************/
440 void __devexit wl_pci_remove(struct pci_dev *pdev)
442 struct net_device *dev = NULL;
443 /*------------------------------------------------------------------------*/
445 DBG_FUNC( "wl_pci_remove" );
446 DBG_ENTER( DbgInfo );
448 /* Make sure the pci_dev pointer passed in is valid */
450 DBG_ERROR( DbgInfo, "PCI subsys passed in an invalid pci_dev pointer\n" );
454 dev = pci_get_drvdata( pdev );
456 DBG_ERROR( DbgInfo, "Could not retrieve net_device structure\n" );
460 /* Perform device cleanup */
462 free_irq( dev->irq, dev );
465 wl_pci_dma_free( pdev, dev->priv );
468 wl_device_dealloc( dev );
470 DBG_LEAVE( DbgInfo );
473 /*============================================================================*/
475 /*******************************************************************************
477 *******************************************************************************
481 * Called by wl_pci_probe() to begin a device's initialization process.
485 * pdev - a pointer to the device's pci_dev structure
490 * errno value otherwise
492 ******************************************************************************/
493 int wl_pci_setup( struct pci_dev *pdev )
496 struct net_device *dev = NULL;
497 struct wl_private *lp = NULL;
498 /*------------------------------------------------------------------------*/
500 DBG_FUNC( "wl_pci_setup" );
501 DBG_ENTER( DbgInfo );
503 /* Make sure the pci_dev pointer passed in is valid */
505 DBG_ERROR( DbgInfo, "PCI subsys passed in an invalid pci_dev pointer\n" );
509 result = pci_enable_device( pdev );
511 DBG_ERROR( DbgInfo, "pci_enable_device() failed\n" );
512 DBG_LEAVE( DbgInfo );
516 /* We found our device! Let's register it with the system */
517 DBG_TRACE( DbgInfo, "Found our device, now registering\n" );
518 dev = wl_device_alloc( );
520 DBG_ERROR( DbgInfo, "Could not register device!!!\n" );
521 DBG_LEAVE( DbgInfo );
525 /* Make sure that space was allocated for our private adapter struct */
526 if( dev->priv == NULL ) {
527 DBG_ERROR( DbgInfo, "Private adapter struct was not allocated!!!\n" );
528 DBG_LEAVE( DbgInfo );
533 /* Allocate DMA Descriptors */
534 if( wl_pci_dma_alloc( pdev, dev->priv ) < 0 ) {
535 DBG_ERROR( DbgInfo, "Could not allocate DMA descriptor memory!!!\n" );
536 DBG_LEAVE( DbgInfo );
541 /* Register our private adapter structure with PCI */
542 pci_set_drvdata( pdev, dev );
544 /* Fill out bus specific information in the net_device struct */
545 dev->irq = pdev->irq;
546 SET_MODULE_OWNER( dev );
548 DBG_TRACE( DbgInfo, "Device Base Address: %#03lx\n", pdev->resource[0].start );
549 dev->base_addr = pdev->resource[0].start;
551 /* Initialize our device here */
552 if( !wl_adapter_insert( dev )) {
553 DBG_ERROR( DbgInfo, "wl_adapter_insert() FAILED!!!\n" );
554 wl_device_dealloc( dev );
555 DBG_LEAVE( DbgInfo );
559 /* Register our ISR */
560 DBG_TRACE( DbgInfo, "Registering ISR...\n" );
562 result = request_irq(dev->irq, wl_isr, SA_SHIRQ, dev->name, dev);
564 DBG_WARNING( DbgInfo, "Could not register ISR!!!\n" );
565 DBG_LEAVE( DbgInfo );
569 /* Make sure interrupts are enabled properly for CardBus */
572 if( lp->hcfCtx.IFB_BusType == CFG_NIC_BUS_TYPE_CARDBUS ||
573 lp->hcfCtx.IFB_BusType == CFG_NIC_BUS_TYPE_PCI ) {
574 DBG_TRACE( DbgInfo, "This is a PCI/CardBus card, enable interrupts\n" );
575 wl_pci_enable_cardbus_interrupts( pdev );
578 /* Enable bus mastering */
579 pci_set_master( pdev );
581 DBG_LEAVE( DbgInfo );
584 /*============================================================================*/
586 /*******************************************************************************
587 * wl_pci_enable_cardbus_interrupts()
588 *******************************************************************************
592 * Called by wl_pci_setup() to enable interrupts on a CardBus device. This
593 * is done by writing bit 15 to the function event mask register. This
594 * CardBus-specific register is located in BAR2 (counting from BAR0), in memory
595 * space at byte offset 1f4 (7f4 for WARP).
599 * pdev - a pointer to the device's pci_dev structure
605 ******************************************************************************/
606 void wl_pci_enable_cardbus_interrupts( struct pci_dev *pdev )
610 u32 func_evt_mask_reg;
611 void *mem_addr_kern = NULL;
612 /*------------------------------------------------------------------------*/
614 DBG_FUNC( "wl_pci_enable_cardbus_interrupts" );
615 DBG_ENTER( DbgInfo );
617 /* Initialize to known bad values */
618 bar2_reg = 0xdeadbeef;
619 mem_addr_bus = 0xdeadbeef;
621 /* Read the BAR2 register; this register contains the base address of the
622 memory region where the function event mask register lives */
623 pci_read_config_dword( pdev, PCI_BASE_ADDRESS_2, &bar2_reg );
624 mem_addr_bus = bar2_reg & PCI_BASE_ADDRESS_MEM_MASK;
626 /* Once the base address is obtained, remap the memory region to kernel
627 space so we can retrieve the register */
628 mem_addr_kern = ioremap( mem_addr_bus, 0x200 );
631 #define REG_OFFSET 0x07F4
633 #define REG_OFFSET 0x01F4
638 /* Retrieve the functional event mask register, enable interrupts by
639 setting Bit 15, and write back the value */
640 func_evt_mask_reg = *(u32 *)( mem_addr_kern + REG_OFFSET );
641 func_evt_mask_reg |= BIT15;
642 *(u32 *)( mem_addr_kern + REG_OFFSET ) = func_evt_mask_reg;
644 /* Once complete, unmap the region and exit */
645 iounmap( mem_addr_kern );
647 DBG_LEAVE( DbgInfo );
649 } // wl_pci_enable_cardbus_interrupts
650 /*============================================================================*/
653 /*******************************************************************************
655 *******************************************************************************
659 * Allocates all resources needed for PCI/CardBus DMA operation
663 * pdev - a pointer to the device's pci_dev structure
664 * lp - the device's private adapter structure
669 * errno value otherwise
671 ******************************************************************************/
672 int wl_pci_dma_alloc( struct pci_dev *pdev, struct wl_private *lp )
676 /*------------------------------------------------------------------------*/
678 DBG_FUNC( "wl_pci_dma_alloc" );
679 DBG_ENTER( DbgInfo );
681 // lp->dma.tx_rsc_ind = lp->dma.rx_rsc_ind = 0;
683 // /* Alloc for the Tx chain and its reclaim descriptor */
684 // for( i = 0; i < NUM_TX_DESC; i++ ) {
685 // status = wl_pci_dma_alloc_tx_packet( pdev, lp, &lp->dma.tx_packet[i] );
686 // if( status == 0 ) {
687 // DBG_PRINT( "lp->dma.tx_packet[%d] : 0x%p\n", i, lp->dma.tx_packet[i] );
688 // DBG_PRINT( "lp->dma.tx_packet[%d]->next_desc_addr : 0x%p\n", i, lp->dma.tx_packet[i]->next_desc_addr );
689 // lp->dma.tx_rsc_ind++;
691 // DBG_ERROR( DbgInfo, "Could not alloc DMA Tx Packet\n" );
695 // if( status == 0 ) {
696 // status = wl_pci_dma_alloc_desc( pdev, lp, &lp->dma.tx_reclaim_desc );
697 // DBG_PRINT( "lp->dma.tx_reclaim_desc: 0x%p\n", lp->dma.tx_reclaim_desc );
699 // /* Alloc for the Rx chain and its reclaim descriptor */
700 // if( status == 0 ) {
701 // for( i = 0; i < NUM_RX_DESC; i++ ) {
702 // status = wl_pci_dma_alloc_rx_packet( pdev, lp, &lp->dma.rx_packet[i] );
703 // if( status == 0 ) {
704 // DBG_PRINT( "lp->dma.rx_packet[%d] : 0x%p\n", i, lp->dma.rx_packet[i] );
705 // DBG_PRINT( "lp->dma.rx_packet[%d]->next_desc_addr : 0x%p\n", i, lp->dma.rx_packet[i]->next_desc_addr );
706 // lp->dma.rx_rsc_ind++;
708 // DBG_ERROR( DbgInfo, "Could not alloc DMA Rx Packet\n" );
713 // if( status == 0 ) {
714 // status = wl_pci_dma_alloc_desc( pdev, lp, &lp->dma.rx_reclaim_desc );
715 // DBG_PRINT( "lp->dma.rx_reclaim_desc: 0x%p\n", lp->dma.rx_reclaim_desc );
717 // /* Store status, as host should not call HCF functions if this fails */
718 // lp->dma.status = status; //;?all useages of dma.status have been commented out
719 // DBG_LEAVE( DbgInfo );
721 } // wl_pci_dma_alloc
722 /*============================================================================*/
724 /*******************************************************************************
726 *******************************************************************************
730 * Deallocated all resources needed for PCI/CardBus DMA operation
734 * pdev - a pointer to the device's pci_dev structure
735 * lp - the device's private adapter structure
740 * errno value otherwise
742 ******************************************************************************/
743 int wl_pci_dma_free( struct pci_dev *pdev, struct wl_private *lp )
747 /*------------------------------------------------------------------------*/
749 DBG_FUNC( "wl_pci_dma_free" );
750 DBG_ENTER( DbgInfo );
752 /* Reclaim all Rx packets that were handed over to the HCF */
753 /* Do I need to do this? Before this free is called, I've already disabled
754 the port which will call wl_pci_dma_hcf_reclaim */
755 //if( lp->dma.status == 0 )
757 // wl_pci_dma_hcf_reclaim( lp );
760 /* Free everything needed for DMA Rx */
761 for( i = 0; i < NUM_RX_DESC; i++ ) {
762 if( lp->dma.rx_packet[i] ) {
763 status = wl_pci_dma_free_rx_packet( pdev, lp, &lp->dma.rx_packet[i] );
765 DBG_WARNING( DbgInfo, "Problem freeing Rx packet\n" );
769 lp->dma.rx_rsc_ind = 0;
771 if( lp->dma.rx_reclaim_desc ) {
772 status = wl_pci_dma_free_desc( pdev, lp, &lp->dma.rx_reclaim_desc );
774 DBG_WARNING( DbgInfo, "Problem freeing Rx reclaim descriptor\n" );
778 /* Free everything needed for DMA Tx */
779 for( i = 0; i < NUM_TX_DESC; i++ ) {
780 if( lp->dma.tx_packet[i] ) {
781 status = wl_pci_dma_free_tx_packet( pdev, lp, &lp->dma.tx_packet[i] );
783 DBG_WARNING( DbgInfo, "Problem freeing Tx packet\n" );
787 lp->dma.tx_rsc_ind = 0;
789 if( lp->dma.tx_reclaim_desc ) {
790 status = wl_pci_dma_free_desc( pdev, lp, &lp->dma.tx_reclaim_desc );
792 DBG_WARNING( DbgInfo, "Problem freeing Tx reclaim descriptor\n" );
796 DBG_LEAVE( DbgInfo );
800 /*============================================================================*/
802 /*******************************************************************************
803 * wl_pci_dma_alloc_tx_packet()
804 *******************************************************************************
808 * Allocates a single Tx packet, consisting of several descriptors and
809 * buffers. Data to transmit is first copied into the 'payload' buffer
810 * before being transmitted.
814 * pdev - a pointer to the device's pci_dev structure
815 * lp - the device's private adapter structure
816 * desc - a pointer which will reference the descriptor to be alloc'd.
821 * errno value otherwise
823 ******************************************************************************/
824 int wl_pci_dma_alloc_tx_packet( struct pci_dev *pdev, struct wl_private *lp,
828 // /*------------------------------------------------------------------------*/
830 // if( desc == NULL ) {
833 // if( status == 0 ) {
834 // status = wl_pci_dma_alloc_desc_and_buf( pdev, lp, desc,
835 // HCF_DMA_TX_BUF1_SIZE );
837 // if( status == 0 ) {
838 // status = wl_pci_dma_alloc_desc_and_buf( pdev, lp,
839 // &( (*desc)->next_desc_addr ),
840 // HCF_MAX_PACKET_SIZE );
843 // if( status == 0 ) {
844 // (*desc)->next_desc_phys_addr = (*desc)->next_desc_addr->desc_phys_addr;
847 } // wl_pci_dma_alloc_tx_packet
848 /*============================================================================*/
850 /*******************************************************************************
851 * wl_pci_dma_free_tx_packet()
852 *******************************************************************************
856 * Frees a single Tx packet, described in the corresponding alloc function.
860 * pdev - a pointer to the device's pci_dev structure
861 * lp - the device's private adapter structure
862 * desc - a pointer which will reference the descriptor to be alloc'd.
867 * errno value otherwise
869 ******************************************************************************/
870 int wl_pci_dma_free_tx_packet( struct pci_dev *pdev, struct wl_private *lp,
874 /*------------------------------------------------------------------------*/
876 if( *desc == NULL ) {
877 DBG_PRINT( "Null descriptor\n" );
880 //;?the "limited" NDIS strategy, assuming a frame consists ALWAYS out of 2
881 //descriptors, make this robust
882 if( status == 0 && (*desc)->next_desc_addr ) {
883 status = wl_pci_dma_free_desc_and_buf( pdev, lp, &(*desc)->next_desc_addr );
886 status = wl_pci_dma_free_desc_and_buf( pdev, lp, desc );
889 } // wl_pci_dma_free_tx_packet
890 /*============================================================================*/
892 /*******************************************************************************
893 * wl_pci_dma_alloc_rx_packet()
894 *******************************************************************************
898 * Allocates a single Rx packet, consisting of two descriptors and one
899 * contiguous buffer. THe buffer starts with the hermes-specific header.
900 * One descriptor points at the start, the other at offset 0x3a of the
905 * pdev - a pointer to the device's pci_dev structure
906 * lp - the device's private adapter structure
907 * desc - a pointer which will reference the descriptor to be alloc'd.
912 * errno value otherwise
914 ******************************************************************************/
915 int wl_pci_dma_alloc_rx_packet( struct pci_dev *pdev, struct wl_private *lp,
920 /*------------------------------------------------------------------------*/
922 // if( desc == NULL ) {
925 // //;?the "limited" NDIS strategy, assuming a frame consists ALWAYS out of 2
926 // //descriptors, make this robust
927 // if( status == 0 ) {
928 // status = wl_pci_dma_alloc_desc( pdev, lp, desc );
930 // if( status == 0 ) {
931 // status = wl_pci_dma_alloc_buf( pdev, lp, *desc, HCF_MAX_PACKET_SIZE );
933 // if( status == 0 ) {
934 // status = wl_pci_dma_alloc_desc( pdev, lp, &p );
936 // if( status == 0 ) {
937 // /* Size of 1st descriptor becomes 0x3a bytes */
938 // SET_BUF_SIZE( *desc, HCF_DMA_RX_BUF1_SIZE );
940 // /* Make 2nd descriptor point at offset 0x3a of the buffer */
941 // SET_BUF_SIZE( p, ( HCF_MAX_PACKET_SIZE - HCF_DMA_RX_BUF1_SIZE ));
942 // p->buf_addr = (*desc)->buf_addr + HCF_DMA_RX_BUF1_SIZE;
943 // p->buf_phys_addr = (*desc)->buf_phys_addr + HCF_DMA_RX_BUF1_SIZE;
944 // p->next_desc_addr = NULL;
946 // /* Chain 2nd descriptor to 1st descriptor */
947 // (*desc)->next_desc_addr = p;
948 // (*desc)->next_desc_phys_addr = p->desc_phys_addr;
952 } // wl_pci_dma_alloc_rx_packet
953 /*============================================================================*/
955 /*******************************************************************************
956 * wl_pci_dma_free_rx_packet()
957 *******************************************************************************
961 * Frees a single Rx packet, described in the corresponding alloc function.
965 * pdev - a pointer to the device's pci_dev structure
966 * lp - the device's private adapter structure
967 * desc - a pointer which will reference the descriptor to be alloc'd.
972 * errno value otherwise
974 ******************************************************************************/
975 int wl_pci_dma_free_rx_packet( struct pci_dev *pdev, struct wl_private *lp,
980 /*------------------------------------------------------------------------*/
982 if( *desc == NULL ) {
986 p = (*desc)->next_desc_addr;
988 /* Free the 2nd descriptor */
991 p->buf_phys_addr = 0;
993 status = wl_pci_dma_free_desc( pdev, lp, &p );
997 /* Free the buffer and 1st descriptor */
999 SET_BUF_SIZE( *desc, HCF_MAX_PACKET_SIZE );
1000 status = wl_pci_dma_free_desc_and_buf( pdev, lp, desc );
1003 } // wl_pci_dma_free_rx_packet
1004 /*============================================================================*/
1006 /*******************************************************************************
1007 * wl_pci_dma_alloc_desc_and_buf()
1008 *******************************************************************************
1012 * Allocates a DMA descriptor and buffer, and associates them with one
1017 * pdev - a pointer to the device's pci_dev structure
1018 * lp - the device's private adapter structure
1019 * desc - a pointer which will reference the descriptor to be alloc'd
1024 * errno value otherwise
1026 ******************************************************************************/
1027 int wl_pci_dma_alloc_desc_and_buf( struct pci_dev *pdev, struct wl_private *lp,
1028 DESC_STRCT **desc, int size )
1031 /*------------------------------------------------------------------------*/
1033 // if( desc == NULL ) {
1034 // status = -EFAULT;
1036 // if( status == 0 ) {
1037 // status = wl_pci_dma_alloc_desc( pdev, lp, desc );
1039 // if( status == 0 ) {
1040 // status = wl_pci_dma_alloc_buf( pdev, lp, *desc, size );
1044 } // wl_pci_dma_alloc_desc_and_buf
1045 /*============================================================================*/
1047 /*******************************************************************************
1048 * wl_pci_dma_free_desc_and_buf()
1049 *******************************************************************************
1053 * Frees a DMA descriptor and associated buffer.
1057 * pdev - a pointer to the device's pci_dev structure
1058 * lp - the device's private adapter structure
1059 * desc - a pointer which will reference the descriptor to be alloc'd
1064 * errno value otherwise
1066 ******************************************************************************/
1067 int wl_pci_dma_free_desc_and_buf( struct pci_dev *pdev, struct wl_private *lp,
1071 /*------------------------------------------------------------------------*/
1073 if( desc == NULL ) {
1076 if( status == 0 && *desc == NULL ) {
1080 status = wl_pci_dma_free_buf( pdev, lp, *desc );
1083 status = wl_pci_dma_free_desc( pdev, lp, desc );
1087 } // wl_pci_dma_free_desc_and_buf
1088 /*============================================================================*/
1090 /*******************************************************************************
1091 * wl_pci_dma_alloc_desc()
1092 *******************************************************************************
1096 * Allocates one DMA descriptor in cache coherent memory.
1100 * pdev - a pointer to the device's pci_dev structure
1101 * lp - the device's private adapter structure
1106 * errno value otherwise
1108 ******************************************************************************/
1109 int wl_pci_dma_alloc_desc( struct pci_dev *pdev, struct wl_private *lp,
1114 // /*------------------------------------------------------------------------*/
1116 // DBG_FUNC( "wl_pci_dma_alloc_desc" );
1117 // DBG_ENTER( DbgInfo );
1119 // if( desc == NULL ) {
1120 // status = -EFAULT;
1122 // if( status == 0 ) {
1123 // *desc = pci_alloc_consistent( pdev, sizeof( DESC_STRCT ), &pa );
1125 // if( *desc == NULL ) {
1126 // DBG_ERROR( DbgInfo, "pci_alloc_consistent() failed\n" );
1127 // status = -ENOMEM;
1129 // memset( *desc, 0, sizeof( DESC_STRCT ));
1130 // (*desc)->desc_phys_addr = cpu_to_le32( pa );
1132 // DBG_LEAVE( DbgInfo );
1134 } // wl_pci_dma_alloc_desc
1135 /*============================================================================*/
1137 /*******************************************************************************
1138 * wl_pci_dma_free_desc()
1139 *******************************************************************************
1143 * Frees one DMA descriptor in cache coherent memory.
1147 * pdev - a pointer to the device's pci_dev structure
1148 * lp - the device's private adapter structure
1153 * errno value otherwise
1155 ******************************************************************************/
1156 int wl_pci_dma_free_desc( struct pci_dev *pdev, struct wl_private *lp,
1160 /*------------------------------------------------------------------------*/
1162 if( *desc == NULL ) {
1166 pci_free_consistent( pdev, sizeof( DESC_STRCT ), *desc,
1167 (*desc)->desc_phys_addr );
1171 } // wl_pci_dma_free_desc
1172 /*============================================================================*/
1174 /*******************************************************************************
1175 * wl_pci_dma_alloc_buf()
1176 *******************************************************************************
1180 * Allocates one DMA buffer in cache coherent memory, and associates a DMA
1181 * descriptor with this buffer.
1185 * pdev - a pointer to the device's pci_dev structure
1186 * lp - the device's private adapter structure
1191 * errno value otherwise
1193 ******************************************************************************/
1194 int wl_pci_dma_alloc_buf( struct pci_dev *pdev, struct wl_private *lp,
1195 DESC_STRCT *desc, int size )
1199 /*------------------------------------------------------------------------*/
1201 // DBG_FUNC( "wl_pci_dma_alloc_buf" );
1202 // DBG_ENTER( DbgInfo );
1204 // if( desc == NULL ) {
1205 // status = -EFAULT;
1207 // if( status == 0 && desc->buf_addr != NULL ) {
1208 // status = -EFAULT;
1210 // if( status == 0 ) {
1211 // desc->buf_addr = pci_alloc_consistent( pdev, size, &pa );
1213 // if( desc->buf_addr == NULL ) {
1214 // DBG_ERROR( DbgInfo, "pci_alloc_consistent() failed\n" );
1215 // status = -ENOMEM;
1217 // desc->buf_phys_addr = cpu_to_le32( pa );
1218 // SET_BUF_SIZE( desc, size );
1220 // DBG_LEAVE( DbgInfo );
1222 } // wl_pci_dma_alloc_buf
1223 /*============================================================================*/
1225 /*******************************************************************************
1226 * wl_pci_dma_free_buf()
1227 *******************************************************************************
1231 * Allocates one DMA buffer in cache coherent memory, and associates a DMA
1232 * descriptor with this buffer.
1236 * pdev - a pointer to the device's pci_dev structure
1237 * lp - the device's private adapter structure
1242 * errno value otherwise
1244 ******************************************************************************/
1245 int wl_pci_dma_free_buf( struct pci_dev *pdev, struct wl_private *lp,
1249 /*------------------------------------------------------------------------*/
1251 if( desc == NULL ) {
1254 if( status == 0 && desc->buf_addr == NULL ) {
1258 pci_free_consistent( pdev, GET_BUF_SIZE( desc ), desc->buf_addr,
1259 desc->buf_phys_addr );
1262 desc->buf_phys_addr = 0;
1263 SET_BUF_SIZE( desc, 0 );
1266 } // wl_pci_dma_free_buf
1267 /*============================================================================*/
1269 /*******************************************************************************
1270 * wl_pci_dma_hcf_supply()
1271 *******************************************************************************
1275 * Supply HCF with DMA-related resources. These consist of:
1276 * - buffers and descriptors for receive purposes
1277 * - one 'reclaim' descriptor for the transmit path, used to fulfill a
1278 * certain H25 DMA engine requirement
1279 * - one 'reclaim' descriptor for the receive path, used to fulfill a
1280 * certain H25 DMA engine requirement
1282 * This function is called at start-of-day or at re-initialization.
1286 * lp - the device's private adapter structure
1291 * errno value otherwise
1293 ******************************************************************************/
1294 void wl_pci_dma_hcf_supply( struct wl_private *lp )
1297 /*------------------------------------------------------------------------*/
1299 DBG_FUNC( "wl_pci_dma_hcf_supply" );
1300 DBG_ENTER( DbgInfo );
1302 //if( lp->dma.status == 0 );
1304 /* Hand over the Rx/Tx reclaim descriptors to the HCF */
1305 if( lp->dma.tx_reclaim_desc ) {
1306 DBG_PRINT( "lp->dma.tx_reclaim_desc: 0x%p\n", lp->dma.tx_reclaim_desc );
1307 hcf_dma_tx_put( &lp->hcfCtx, lp->dma.tx_reclaim_desc, 0 );
1308 lp->dma.tx_reclaim_desc = NULL;
1309 DBG_PRINT( "lp->dma.tx_reclaim_desc: 0x%p\n", lp->dma.tx_reclaim_desc );
1311 if( lp->dma.rx_reclaim_desc ) {
1312 DBG_PRINT( "lp->dma.rx_reclaim_desc: 0x%p\n", lp->dma.rx_reclaim_desc );
1313 hcf_dma_rx_put( &lp->hcfCtx, lp->dma.rx_reclaim_desc );
1314 lp->dma.rx_reclaim_desc = NULL;
1315 DBG_PRINT( "lp->dma.rx_reclaim_desc: 0x%p\n", lp->dma.rx_reclaim_desc );
1317 /* Hand over the Rx descriptor chain to the HCF */
1318 for( i = 0; i < NUM_RX_DESC; i++ ) {
1319 DBG_PRINT( "lp->dma.rx_packet[%d]: 0x%p\n", i, lp->dma.rx_packet[i] );
1320 hcf_dma_rx_put( &lp->hcfCtx, lp->dma.rx_packet[i] );
1321 lp->dma.rx_packet[i] = NULL;
1322 DBG_PRINT( "lp->dma.rx_packet[%d]: 0x%p\n", i, lp->dma.rx_packet[i] );
1326 DBG_LEAVE( DbgInfo );
1328 } // wl_pci_dma_hcf_supply
1329 /*============================================================================*/
1331 /*******************************************************************************
1332 * wl_pci_dma_hcf_reclaim()
1333 *******************************************************************************
1337 * Return DMA-related resources from the HCF. These consist of:
1338 * - buffers and descriptors for receive purposes
1339 * - buffers and descriptors for transmit purposes
1340 * - one 'reclaim' descriptor for the transmit path, used to fulfill a
1341 * certain H25 DMA engine requirement
1342 * - one 'reclaim' descriptor for the receive path, used to fulfill a
1343 * certain H25 DMA engine requirement
1345 * This function is called at end-of-day or at re-initialization.
1349 * lp - the device's private adapter structure
1354 * errno value otherwise
1356 ******************************************************************************/
1357 void wl_pci_dma_hcf_reclaim( struct wl_private *lp )
1360 /*------------------------------------------------------------------------*/
1362 DBG_FUNC( "wl_pci_dma_hcf_reclaim" );
1363 DBG_ENTER( DbgInfo );
1365 wl_pci_dma_hcf_reclaim_rx( lp );
1366 for( i = 0; i < NUM_RX_DESC; i++ ) {
1367 DBG_PRINT( "rx_packet[%d] 0x%p\n", i, lp->dma.rx_packet[i] );
1368 // if( lp->dma.rx_packet[i] == NULL ) {
1369 // DBG_PRINT( "wl_pci_dma_hcf_reclaim: rx_packet[%d] NULL\n", i );
1373 wl_pci_dma_hcf_reclaim_tx( lp );
1374 for( i = 0; i < NUM_TX_DESC; i++ ) {
1375 DBG_PRINT( "tx_packet[%d] 0x%p\n", i, lp->dma.tx_packet[i] );
1376 // if( lp->dma.tx_packet[i] == NULL ) {
1377 // DBG_PRINT( "wl_pci_dma_hcf_reclaim: tx_packet[%d] NULL\n", i );
1381 DBG_LEAVE( DbgInfo );
1383 } // wl_pci_dma_hcf_reclaim
1384 /*============================================================================*/
1386 /*******************************************************************************
1387 * wl_pci_dma_hcf_reclaim_rx()
1388 *******************************************************************************
1392 * Reclaim Rx packets that have already been processed by the HCF.
1396 * lp - the device's private adapter structure
1401 * errno value otherwise
1403 ******************************************************************************/
1404 void wl_pci_dma_hcf_reclaim_rx( struct wl_private *lp )
1408 /*------------------------------------------------------------------------*/
1410 DBG_FUNC( "wl_pci_dma_hcf_reclaim_rx" );
1411 DBG_ENTER( DbgInfo );
1413 //if( lp->dma.status == 0 )
1415 while ( ( p = hcf_dma_rx_get( &lp->hcfCtx ) ) != NULL ) {
1416 if( p && p->buf_addr == NULL ) {
1417 /* A reclaim descriptor is being given back by the HCF. Reclaim
1418 descriptors have a NULL buf_addr */
1419 lp->dma.rx_reclaim_desc = p;
1420 DBG_PRINT( "reclaim_descriptor: 0x%p\n", p );
1423 for( i = 0; i < NUM_RX_DESC; i++ ) {
1424 if( lp->dma.rx_packet[i] == NULL ) {
1428 /* An Rx buffer descriptor is being given back by the HCF */
1429 lp->dma.rx_packet[i] = p;
1430 lp->dma.rx_rsc_ind++;
1431 DBG_PRINT( "rx_packet[%d] 0x%p\n", i, lp->dma.rx_packet[i] );
1434 DBG_LEAVE( DbgInfo );
1435 } // wl_pci_dma_hcf_reclaim_rx
1436 /*============================================================================*/
1438 /*******************************************************************************
1439 * wl_pci_dma_get_tx_packet()
1440 *******************************************************************************
1444 * Obtains a Tx descriptor from the chain to use for Tx.
1448 * lp - a pointer to the device's wl_private structure.
1452 * A pointer to the retrieved descriptor
1454 ******************************************************************************/
1455 DESC_STRCT * wl_pci_dma_get_tx_packet( struct wl_private *lp )
1458 DESC_STRCT *desc = NULL;
1459 /*------------------------------------------------------------------------*/
1461 for( i = 0; i < NUM_TX_DESC; i++ ) {
1462 if( lp->dma.tx_packet[i] ) {
1467 if( i != NUM_TX_DESC ) {
1468 desc = lp->dma.tx_packet[i];
1470 lp->dma.tx_packet[i] = NULL;
1471 lp->dma.tx_rsc_ind--;
1473 memset( desc->buf_addr, 0, HCF_DMA_TX_BUF1_SIZE );
1477 } // wl_pci_dma_get_tx_packet
1478 /*============================================================================*/
1480 /*******************************************************************************
1481 * wl_pci_dma_put_tx_packet()
1482 *******************************************************************************
1486 * Returns a Tx descriptor to the chain.
1490 * lp - a pointer to the device's wl_private structure.
1491 * desc - a pointer to the descriptor to return.
1497 ******************************************************************************/
1498 void wl_pci_dma_put_tx_packet( struct wl_private *lp, DESC_STRCT *desc )
1501 /*------------------------------------------------------------------------*/
1503 for( i = 0; i < NUM_TX_DESC; i++ ) {
1504 if( lp->dma.tx_packet[i] == NULL ) {
1509 if( i != NUM_TX_DESC ) {
1510 lp->dma.tx_packet[i] = desc;
1511 lp->dma.tx_rsc_ind++;
1513 } // wl_pci_dma_put_tx_packet
1514 /*============================================================================*/
1516 /*******************************************************************************
1517 * wl_pci_dma_hcf_reclaim_tx()
1518 *******************************************************************************
1522 * Reclaim Tx packets that have either been processed by the HCF due to a
1523 * port disable or a Tx completion.
1527 * lp - the device's private adapter structure
1532 * errno value otherwise
1534 ******************************************************************************/
1535 void wl_pci_dma_hcf_reclaim_tx( struct wl_private *lp )
1539 /*------------------------------------------------------------------------*/
1541 DBG_FUNC( "wl_pci_dma_hcf_reclaim_tx" );
1542 DBG_ENTER( DbgInfo );
1544 //if( lp->dma.status == 0 )
1546 while ( ( p = hcf_dma_tx_get( &lp->hcfCtx ) ) != NULL ) {
1548 if( p != NULL && p->buf_addr == NULL ) {
1549 /* A Reclaim descriptor is being given back by the HCF. Reclaim
1550 descriptors have a NULL buf_addr */
1551 lp->dma.tx_reclaim_desc = p;
1552 DBG_PRINT( "reclaim_descriptor: 0x%p\n", p );
1555 for( i = 0; i < NUM_TX_DESC; i++ ) {
1556 if( lp->dma.tx_packet[i] == NULL ) {
1560 /* An Rx buffer descriptor is being given back by the HCF */
1561 lp->dma.tx_packet[i] = p;
1562 lp->dma.tx_rsc_ind++;
1563 DBG_PRINT( "tx_packet[%d] 0x%p\n", i, lp->dma.tx_packet[i] );
1567 if( lp->netif_queue_on == FALSE ) {
1568 netif_wake_queue( lp->dev );
1569 WL_WDS_NETIF_WAKE_QUEUE( lp );
1570 lp->netif_queue_on = TRUE;
1572 DBG_LEAVE( DbgInfo );
1574 } // wl_pci_dma_hcf_reclaim_tx
1575 /*============================================================================*/
1576 #endif // ENABLE_DMA