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>
82 #include <asm/bitops.h>
83 #include <asm/uaccess.h>
85 #include <linux/ethtool.h>
86 #include <linux/netdevice.h>
87 #include <linux/etherdevice.h>
88 #include <linux/skbuff.h>
89 #include <linux/if_arp.h>
90 #include <linux/ioport.h>
92 #include <hcf/debug.h>
98 #include <wireless/wl_if.h>
99 #include <wireless/wl_internal.h>
100 #include <wireless/wl_util.h>
101 #include <wireless/wl_main.h>
102 #include <wireless/wl_netdev.h>
103 #include <wireless/wl_pci.h>
106 /*******************************************************************************
108 ******************************************************************************/
110 extern dbg_info_t *DbgInfo;
113 /* define the PCI device Table Cardname and id tables */
114 static struct pci_device_id wl_pci_tbl[] __devinitdata = {
115 { PCI_DEVICE(PCI_VENDOR_ID_WL_LKM, PCI_DEVICE_ID_WL_LKM_0), },
116 { PCI_DEVICE(PCI_VENDOR_ID_WL_LKM, PCI_DEVICE_ID_WL_LKM_1), },
117 { PCI_DEVICE(PCI_VENDOR_ID_WL_LKM, PCI_DEVICE_ID_WL_LKM_2), },
119 { } /* Terminating entry */
122 MODULE_DEVICE_TABLE(pci, wl_pci_tbl);
124 /*******************************************************************************
125 * function prototypes
126 ******************************************************************************/
127 int __devinit wl_pci_probe( struct pci_dev *pdev,
128 const struct pci_device_id *ent );
129 void __devexit wl_pci_remove(struct pci_dev *pdev);
130 int wl_pci_setup( struct pci_dev *pdev );
131 void wl_pci_enable_cardbus_interrupts( struct pci_dev *pdev );
134 int wl_pci_dma_alloc( struct pci_dev *pdev, struct wl_private *lp );
135 int wl_pci_dma_free( struct pci_dev *pdev, struct wl_private *lp );
136 int wl_pci_dma_alloc_tx_packet( struct pci_dev *pdev, struct wl_private *lp,
138 int wl_pci_dma_free_tx_packet( struct pci_dev *pdev, struct wl_private *lp,
140 int wl_pci_dma_alloc_rx_packet( struct pci_dev *pdev, struct wl_private *lp,
142 int wl_pci_dma_free_rx_packet( struct pci_dev *pdev, struct wl_private *lp,
144 int wl_pci_dma_alloc_desc_and_buf( struct pci_dev *pdev, struct wl_private *lp,
145 DESC_STRCT **desc, int size );
146 int wl_pci_dma_free_desc_and_buf( struct pci_dev *pdev, struct wl_private *lp,
148 int wl_pci_dma_alloc_desc( struct pci_dev *pdev, struct wl_private *lp,
150 int wl_pci_dma_free_desc( struct pci_dev *pdev, struct wl_private *lp,
152 int wl_pci_dma_alloc_buf( struct pci_dev *pdev, struct wl_private *lp,
153 DESC_STRCT *desc, int size );
154 int wl_pci_dma_free_buf( struct pci_dev *pdev, struct wl_private *lp,
157 void wl_pci_dma_hcf_reclaim_rx( struct wl_private *lp );
160 /*******************************************************************************
161 * PCI module function registration
162 ******************************************************************************/
163 static struct pci_driver wl_driver =
166 id_table: wl_pci_tbl,
168 remove: __devexit_p(wl_pci_remove),
173 /*******************************************************************************
174 * wl_adapter_init_module()
175 *******************************************************************************
179 * Called by init_module() to perform PCI-specific driver initialization.
189 ******************************************************************************/
190 int wl_adapter_init_module( void )
193 /*------------------------------------------------------------------------*/
195 DBG_FUNC( "wl_adapter_init_module()" );
196 DBG_ENTER( DbgInfo );
197 DBG_TRACE( DbgInfo, "wl_adapter_init_module() -- PCI\n" );
199 result = pci_register_driver( &wl_driver ); //;?replace with pci_module_init, Rubini pg 490
200 //;? why not do something with the result
202 DBG_LEAVE( DbgInfo );
204 } // wl_adapter_init_module
205 /*============================================================================*/
207 /*******************************************************************************
208 * wl_adapter_cleanup_module()
209 *******************************************************************************
213 * Called by cleanup_module() to perform PCI-specific driver cleanup.
223 ******************************************************************************/
224 void wl_adapter_cleanup_module( void )
226 //;?how comes wl_adapter_cleanup_module is located in a seemingly pci specific module
227 DBG_FUNC( "wl_adapter_cleanup_module" );
228 DBG_ENTER( DbgInfo );
230 //;?DBG_TRACE below feels like nearly redundant in the light of DBG_ENTER above
231 DBG_TRACE( DbgInfo, "wl_adapter_cleanup_module() -- PCI\n" );
233 pci_unregister_driver( &wl_driver );
235 DBG_LEAVE( DbgInfo );
237 } // wl_adapter_cleanup_module
238 /*============================================================================*/
240 /*******************************************************************************
241 * wl_adapter_insert()
242 *******************************************************************************
246 * Called by wl_pci_probe() to continue the process of device insertion.
250 * dev - a pointer to the device's net_device structure
256 ******************************************************************************/
257 int wl_adapter_insert( struct net_device *dev )
260 /*------------------------------------------------------------------------*/
262 DBG_FUNC( "wl_adapter_insert" );
263 DBG_ENTER( DbgInfo );
265 DBG_TRACE( DbgInfo, "wl_adapter_insert() -- PCI\n" );
268 DBG_ERROR( DbgInfo, "net_device pointer is NULL!!!\n" );
269 } else if( dev->priv == NULL ) {
270 DBG_ERROR( DbgInfo, "wl_private pointer is NULL!!!\n" );
271 } else if( wl_insert( dev ) ) { /* Perform remaining device initialization */
274 DBG_TRACE( DbgInfo, "wl_insert() FAILED\n" );
276 DBG_LEAVE( DbgInfo );
278 } // wl_adapter_insert
279 /*============================================================================*/
281 /*******************************************************************************
283 *******************************************************************************
291 * dev - a pointer to the device's net_device structure
297 ******************************************************************************/
298 int wl_adapter_open( struct net_device *dev )
301 int hcf_status = HCF_SUCCESS;
302 /*------------------------------------------------------------------------*/
304 DBG_FUNC( "wl_adapter_open" );
305 DBG_ENTER( DbgInfo );
307 DBG_TRACE( DbgInfo, "wl_adapter_open() -- PCI\n" );
309 hcf_status = wl_open( dev );
311 if( hcf_status != HCF_SUCCESS ) {
315 DBG_LEAVE( DbgInfo );
318 /*============================================================================*/
320 /*******************************************************************************
322 *******************************************************************************
330 * dev - a pointer to the device's net_device structure
336 ******************************************************************************/
337 int wl_adapter_close( struct net_device *dev )
339 DBG_FUNC( "wl_adapter_close" );
340 DBG_ENTER( DbgInfo );
342 DBG_TRACE( DbgInfo, "wl_adapter_close() -- PCI\n" );
343 DBG_TRACE( DbgInfo, "%s: Shutting down adapter.\n", dev->name );
347 DBG_LEAVE( DbgInfo );
349 } // wl_adapter_close
350 /*============================================================================*/
352 /*******************************************************************************
353 * wl_adapter_is_open()
354 *******************************************************************************
358 * Check whether this device is open. Returns
362 * dev - a pointer to the device's net_device structure
366 * nonzero if device is open.
368 ******************************************************************************/
369 int wl_adapter_is_open( struct net_device *dev )
371 /* This function is used in PCMCIA to check the status of the 'open' field
372 in the dev_link_t structure associated with a network device. There
373 doesn't seem to be an analog to this for PCI, and checking the status
374 contained in the net_device structure doesn't have the same effect.
375 For now, return TRUE, but find out if this is necessary for PCI. */
378 } // wl_adapter_is_open
379 /*============================================================================*/
381 /*******************************************************************************
383 *******************************************************************************
387 * Registered in the pci_driver structure, this function is called when the
388 * PCI subsystem finds a new PCI device which matches the infomation contained
389 * in the pci_device_id table.
393 * pdev - a pointer to the device's pci_dev structure
394 * ent - this device's entry in the pci_device_id table
399 * errno value otherwise
401 ******************************************************************************/
402 int __devinit wl_pci_probe( struct pci_dev *pdev,
403 const struct pci_device_id *ent )
406 /*------------------------------------------------------------------------*/
408 DBG_FUNC( "wl_pci_probe" );
409 DBG_ENTER( DbgInfo );
410 DBG_PRINT( "%s\n", VERSION_INFO );
412 result = wl_pci_setup( pdev );
414 DBG_LEAVE( DbgInfo );
418 /*============================================================================*/
420 /*******************************************************************************
422 *******************************************************************************
426 * Registered in the pci_driver structure, this function is called when the
427 * PCI subsystem detects that a PCI device which matches the infomation
428 * contained in the pci_device_id table has been removed.
432 * pdev - a pointer to the device's pci_dev structure
438 ******************************************************************************/
439 void __devexit wl_pci_remove(struct pci_dev *pdev)
441 struct net_device *dev = NULL;
442 /*------------------------------------------------------------------------*/
444 DBG_FUNC( "wl_pci_remove" );
445 DBG_ENTER( DbgInfo );
447 /* Make sure the pci_dev pointer passed in is valid */
449 DBG_ERROR( DbgInfo, "PCI subsys passed in an invalid pci_dev pointer\n" );
453 dev = pci_get_drvdata( pdev );
455 DBG_ERROR( DbgInfo, "Could not retrieve net_device structure\n" );
459 /* Perform device cleanup */
461 free_irq( dev->irq, dev );
464 wl_pci_dma_free( pdev, dev->priv );
467 wl_device_dealloc( dev );
469 DBG_LEAVE( DbgInfo );
472 /*============================================================================*/
474 /*******************************************************************************
476 *******************************************************************************
480 * Called by wl_pci_probe() to begin a device's initialization process.
484 * pdev - a pointer to the device's pci_dev structure
489 * errno value otherwise
491 ******************************************************************************/
492 int wl_pci_setup( struct pci_dev *pdev )
495 struct net_device *dev = NULL;
496 struct wl_private *lp = NULL;
497 /*------------------------------------------------------------------------*/
499 DBG_FUNC( "wl_pci_setup" );
500 DBG_ENTER( DbgInfo );
502 /* Make sure the pci_dev pointer passed in is valid */
504 DBG_ERROR( DbgInfo, "PCI subsys passed in an invalid pci_dev pointer\n" );
508 result = pci_enable_device( pdev );
510 DBG_ERROR( DbgInfo, "pci_enable_device() failed\n" );
511 DBG_LEAVE( DbgInfo );
515 /* We found our device! Let's register it with the system */
516 DBG_TRACE( DbgInfo, "Found our device, now registering\n" );
517 dev = wl_device_alloc( );
519 DBG_ERROR( DbgInfo, "Could not register device!!!\n" );
520 DBG_LEAVE( DbgInfo );
524 /* Make sure that space was allocated for our private adapter struct */
525 if( dev->priv == NULL ) {
526 DBG_ERROR( DbgInfo, "Private adapter struct was not allocated!!!\n" );
527 DBG_LEAVE( DbgInfo );
532 /* Allocate DMA Descriptors */
533 if( wl_pci_dma_alloc( pdev, dev->priv ) < 0 ) {
534 DBG_ERROR( DbgInfo, "Could not allocate DMA descriptor memory!!!\n" );
535 DBG_LEAVE( DbgInfo );
540 /* Register our private adapter structure with PCI */
541 pci_set_drvdata( pdev, dev );
543 /* Fill out bus specific information in the net_device struct */
544 dev->irq = pdev->irq;
545 SET_MODULE_OWNER( dev );
547 DBG_TRACE( DbgInfo, "Device Base Address: %#03lx\n", pdev->resource[0].start );
548 dev->base_addr = pdev->resource[0].start;
550 /* Initialize our device here */
551 if( !wl_adapter_insert( dev )) {
552 DBG_ERROR( DbgInfo, "wl_adapter_insert() FAILED!!!\n" );
553 wl_device_dealloc( dev );
554 DBG_LEAVE( DbgInfo );
558 /* Register our ISR */
559 DBG_TRACE( DbgInfo, "Registering ISR...\n" );
561 result = request_irq(dev->irq, wl_isr, SA_SHIRQ, dev->name, dev);
563 DBG_WARNING( DbgInfo, "Could not register ISR!!!\n" );
564 DBG_LEAVE( DbgInfo );
568 /* Make sure interrupts are enabled properly for CardBus */
571 if( lp->hcfCtx.IFB_BusType == CFG_NIC_BUS_TYPE_CARDBUS ||
572 lp->hcfCtx.IFB_BusType == CFG_NIC_BUS_TYPE_PCI ) {
573 DBG_TRACE( DbgInfo, "This is a PCI/CardBus card, enable interrupts\n" );
574 wl_pci_enable_cardbus_interrupts( pdev );
577 /* Enable bus mastering */
578 pci_set_master( pdev );
580 DBG_LEAVE( DbgInfo );
583 /*============================================================================*/
585 /*******************************************************************************
586 * wl_pci_enable_cardbus_interrupts()
587 *******************************************************************************
591 * Called by wl_pci_setup() to enable interrupts on a CardBus device. This
592 * is done by writing bit 15 to the function event mask register. This
593 * CardBus-specific register is located in BAR2 (counting from BAR0), in memory
594 * space at byte offset 1f4 (7f4 for WARP).
598 * pdev - a pointer to the device's pci_dev structure
604 ******************************************************************************/
605 void wl_pci_enable_cardbus_interrupts( struct pci_dev *pdev )
609 u32 func_evt_mask_reg;
610 void *mem_addr_kern = NULL;
611 /*------------------------------------------------------------------------*/
613 DBG_FUNC( "wl_pci_enable_cardbus_interrupts" );
614 DBG_ENTER( DbgInfo );
616 /* Initialize to known bad values */
617 bar2_reg = 0xdeadbeef;
618 mem_addr_bus = 0xdeadbeef;
620 /* Read the BAR2 register; this register contains the base address of the
621 memory region where the function event mask register lives */
622 pci_read_config_dword( pdev, PCI_BASE_ADDRESS_2, &bar2_reg );
623 mem_addr_bus = bar2_reg & PCI_BASE_ADDRESS_MEM_MASK;
625 /* Once the base address is obtained, remap the memory region to kernel
626 space so we can retrieve the register */
627 mem_addr_kern = ioremap( mem_addr_bus, 0x200 );
630 #define REG_OFFSET 0x07F4
632 #define REG_OFFSET 0x01F4
637 /* Retrieve the functional event mask register, enable interrupts by
638 setting Bit 15, and write back the value */
639 func_evt_mask_reg = *(u32 *)( mem_addr_kern + REG_OFFSET );
640 func_evt_mask_reg |= BIT15;
641 *(u32 *)( mem_addr_kern + REG_OFFSET ) = func_evt_mask_reg;
643 /* Once complete, unmap the region and exit */
644 iounmap( mem_addr_kern );
646 DBG_LEAVE( DbgInfo );
648 } // wl_pci_enable_cardbus_interrupts
649 /*============================================================================*/
652 /*******************************************************************************
654 *******************************************************************************
658 * Allocates all resources needed for PCI/CardBus DMA operation
662 * pdev - a pointer to the device's pci_dev structure
663 * lp - the device's private adapter structure
668 * errno value otherwise
670 ******************************************************************************/
671 int wl_pci_dma_alloc( struct pci_dev *pdev, struct wl_private *lp )
675 /*------------------------------------------------------------------------*/
677 DBG_FUNC( "wl_pci_dma_alloc" );
678 DBG_ENTER( DbgInfo );
680 // lp->dma.tx_rsc_ind = lp->dma.rx_rsc_ind = 0;
682 // /* Alloc for the Tx chain and its reclaim descriptor */
683 // for( i = 0; i < NUM_TX_DESC; i++ ) {
684 // status = wl_pci_dma_alloc_tx_packet( pdev, lp, &lp->dma.tx_packet[i] );
685 // if( status == 0 ) {
686 // DBG_PRINT( "lp->dma.tx_packet[%d] : 0x%p\n", i, lp->dma.tx_packet[i] );
687 // DBG_PRINT( "lp->dma.tx_packet[%d]->next_desc_addr : 0x%p\n", i, lp->dma.tx_packet[i]->next_desc_addr );
688 // lp->dma.tx_rsc_ind++;
690 // DBG_ERROR( DbgInfo, "Could not alloc DMA Tx Packet\n" );
694 // if( status == 0 ) {
695 // status = wl_pci_dma_alloc_desc( pdev, lp, &lp->dma.tx_reclaim_desc );
696 // DBG_PRINT( "lp->dma.tx_reclaim_desc: 0x%p\n", lp->dma.tx_reclaim_desc );
698 // /* Alloc for the Rx chain and its reclaim descriptor */
699 // if( status == 0 ) {
700 // for( i = 0; i < NUM_RX_DESC; i++ ) {
701 // status = wl_pci_dma_alloc_rx_packet( pdev, lp, &lp->dma.rx_packet[i] );
702 // if( status == 0 ) {
703 // DBG_PRINT( "lp->dma.rx_packet[%d] : 0x%p\n", i, lp->dma.rx_packet[i] );
704 // DBG_PRINT( "lp->dma.rx_packet[%d]->next_desc_addr : 0x%p\n", i, lp->dma.rx_packet[i]->next_desc_addr );
705 // lp->dma.rx_rsc_ind++;
707 // DBG_ERROR( DbgInfo, "Could not alloc DMA Rx Packet\n" );
712 // if( status == 0 ) {
713 // status = wl_pci_dma_alloc_desc( pdev, lp, &lp->dma.rx_reclaim_desc );
714 // DBG_PRINT( "lp->dma.rx_reclaim_desc: 0x%p\n", lp->dma.rx_reclaim_desc );
716 // /* Store status, as host should not call HCF functions if this fails */
717 // lp->dma.status = status; //;?all useages of dma.status have been commented out
718 // DBG_LEAVE( DbgInfo );
720 } // wl_pci_dma_alloc
721 /*============================================================================*/
723 /*******************************************************************************
725 *******************************************************************************
729 * Deallocated all resources needed for PCI/CardBus DMA operation
733 * pdev - a pointer to the device's pci_dev structure
734 * lp - the device's private adapter structure
739 * errno value otherwise
741 ******************************************************************************/
742 int wl_pci_dma_free( struct pci_dev *pdev, struct wl_private *lp )
746 /*------------------------------------------------------------------------*/
748 DBG_FUNC( "wl_pci_dma_free" );
749 DBG_ENTER( DbgInfo );
751 /* Reclaim all Rx packets that were handed over to the HCF */
752 /* Do I need to do this? Before this free is called, I've already disabled
753 the port which will call wl_pci_dma_hcf_reclaim */
754 //if( lp->dma.status == 0 )
756 // wl_pci_dma_hcf_reclaim( lp );
759 /* Free everything needed for DMA Rx */
760 for( i = 0; i < NUM_RX_DESC; i++ ) {
761 if( lp->dma.rx_packet[i] ) {
762 status = wl_pci_dma_free_rx_packet( pdev, lp, &lp->dma.rx_packet[i] );
764 DBG_WARNING( DbgInfo, "Problem freeing Rx packet\n" );
768 lp->dma.rx_rsc_ind = 0;
770 if( lp->dma.rx_reclaim_desc ) {
771 status = wl_pci_dma_free_desc( pdev, lp, &lp->dma.rx_reclaim_desc );
773 DBG_WARNING( DbgInfo, "Problem freeing Rx reclaim descriptor\n" );
777 /* Free everything needed for DMA Tx */
778 for( i = 0; i < NUM_TX_DESC; i++ ) {
779 if( lp->dma.tx_packet[i] ) {
780 status = wl_pci_dma_free_tx_packet( pdev, lp, &lp->dma.tx_packet[i] );
782 DBG_WARNING( DbgInfo, "Problem freeing Tx packet\n" );
786 lp->dma.tx_rsc_ind = 0;
788 if( lp->dma.tx_reclaim_desc ) {
789 status = wl_pci_dma_free_desc( pdev, lp, &lp->dma.tx_reclaim_desc );
791 DBG_WARNING( DbgInfo, "Problem freeing Tx reclaim descriptor\n" );
795 DBG_LEAVE( DbgInfo );
799 /*============================================================================*/
801 /*******************************************************************************
802 * wl_pci_dma_alloc_tx_packet()
803 *******************************************************************************
807 * Allocates a single Tx packet, consisting of several descriptors and
808 * buffers. Data to transmit is first copied into the 'payload' buffer
809 * before being transmitted.
813 * pdev - a pointer to the device's pci_dev structure
814 * lp - the device's private adapter structure
815 * desc - a pointer which will reference the descriptor to be alloc'd.
820 * errno value otherwise
822 ******************************************************************************/
823 int wl_pci_dma_alloc_tx_packet( struct pci_dev *pdev, struct wl_private *lp,
827 // /*------------------------------------------------------------------------*/
829 // if( desc == NULL ) {
832 // if( status == 0 ) {
833 // status = wl_pci_dma_alloc_desc_and_buf( pdev, lp, desc,
834 // HCF_DMA_TX_BUF1_SIZE );
836 // if( status == 0 ) {
837 // status = wl_pci_dma_alloc_desc_and_buf( pdev, lp,
838 // &( (*desc)->next_desc_addr ),
839 // HCF_MAX_PACKET_SIZE );
842 // if( status == 0 ) {
843 // (*desc)->next_desc_phys_addr = (*desc)->next_desc_addr->desc_phys_addr;
846 } // wl_pci_dma_alloc_tx_packet
847 /*============================================================================*/
849 /*******************************************************************************
850 * wl_pci_dma_free_tx_packet()
851 *******************************************************************************
855 * Frees a single Tx packet, described in the corresponding alloc function.
859 * pdev - a pointer to the device's pci_dev structure
860 * lp - the device's private adapter structure
861 * desc - a pointer which will reference the descriptor to be alloc'd.
866 * errno value otherwise
868 ******************************************************************************/
869 int wl_pci_dma_free_tx_packet( struct pci_dev *pdev, struct wl_private *lp,
873 /*------------------------------------------------------------------------*/
875 if( *desc == NULL ) {
876 DBG_PRINT( "Null descriptor\n" );
879 //;?the "limited" NDIS strategy, assuming a frame consists ALWAYS out of 2
880 //descriptors, make this robust
881 if( status == 0 && (*desc)->next_desc_addr ) {
882 status = wl_pci_dma_free_desc_and_buf( pdev, lp, &(*desc)->next_desc_addr );
885 status = wl_pci_dma_free_desc_and_buf( pdev, lp, desc );
888 } // wl_pci_dma_free_tx_packet
889 /*============================================================================*/
891 /*******************************************************************************
892 * wl_pci_dma_alloc_rx_packet()
893 *******************************************************************************
897 * Allocates a single Rx packet, consisting of two descriptors and one
898 * contiguous buffer. THe buffer starts with the hermes-specific header.
899 * One descriptor points at the start, the other at offset 0x3a of the
904 * pdev - a pointer to the device's pci_dev structure
905 * lp - the device's private adapter structure
906 * desc - a pointer which will reference the descriptor to be alloc'd.
911 * errno value otherwise
913 ******************************************************************************/
914 int wl_pci_dma_alloc_rx_packet( struct pci_dev *pdev, struct wl_private *lp,
919 /*------------------------------------------------------------------------*/
921 // if( desc == NULL ) {
924 // //;?the "limited" NDIS strategy, assuming a frame consists ALWAYS out of 2
925 // //descriptors, make this robust
926 // if( status == 0 ) {
927 // status = wl_pci_dma_alloc_desc( pdev, lp, desc );
929 // if( status == 0 ) {
930 // status = wl_pci_dma_alloc_buf( pdev, lp, *desc, HCF_MAX_PACKET_SIZE );
932 // if( status == 0 ) {
933 // status = wl_pci_dma_alloc_desc( pdev, lp, &p );
935 // if( status == 0 ) {
936 // /* Size of 1st descriptor becomes 0x3a bytes */
937 // SET_BUF_SIZE( *desc, HCF_DMA_RX_BUF1_SIZE );
939 // /* Make 2nd descriptor point at offset 0x3a of the buffer */
940 // SET_BUF_SIZE( p, ( HCF_MAX_PACKET_SIZE - HCF_DMA_RX_BUF1_SIZE ));
941 // p->buf_addr = (*desc)->buf_addr + HCF_DMA_RX_BUF1_SIZE;
942 // p->buf_phys_addr = (*desc)->buf_phys_addr + HCF_DMA_RX_BUF1_SIZE;
943 // p->next_desc_addr = NULL;
945 // /* Chain 2nd descriptor to 1st descriptor */
946 // (*desc)->next_desc_addr = p;
947 // (*desc)->next_desc_phys_addr = p->desc_phys_addr;
951 } // wl_pci_dma_alloc_rx_packet
952 /*============================================================================*/
954 /*******************************************************************************
955 * wl_pci_dma_free_rx_packet()
956 *******************************************************************************
960 * Frees a single Rx packet, described in the corresponding alloc function.
964 * pdev - a pointer to the device's pci_dev structure
965 * lp - the device's private adapter structure
966 * desc - a pointer which will reference the descriptor to be alloc'd.
971 * errno value otherwise
973 ******************************************************************************/
974 int wl_pci_dma_free_rx_packet( struct pci_dev *pdev, struct wl_private *lp,
979 /*------------------------------------------------------------------------*/
981 if( *desc == NULL ) {
985 p = (*desc)->next_desc_addr;
987 /* Free the 2nd descriptor */
990 p->buf_phys_addr = 0;
992 status = wl_pci_dma_free_desc( pdev, lp, &p );
996 /* Free the buffer and 1st descriptor */
998 SET_BUF_SIZE( *desc, HCF_MAX_PACKET_SIZE );
999 status = wl_pci_dma_free_desc_and_buf( pdev, lp, desc );
1002 } // wl_pci_dma_free_rx_packet
1003 /*============================================================================*/
1005 /*******************************************************************************
1006 * wl_pci_dma_alloc_desc_and_buf()
1007 *******************************************************************************
1011 * Allocates a DMA descriptor and buffer, and associates them with one
1016 * pdev - a pointer to the device's pci_dev structure
1017 * lp - the device's private adapter structure
1018 * desc - a pointer which will reference the descriptor to be alloc'd
1023 * errno value otherwise
1025 ******************************************************************************/
1026 int wl_pci_dma_alloc_desc_and_buf( struct pci_dev *pdev, struct wl_private *lp,
1027 DESC_STRCT **desc, int size )
1030 /*------------------------------------------------------------------------*/
1032 // if( desc == NULL ) {
1033 // status = -EFAULT;
1035 // if( status == 0 ) {
1036 // status = wl_pci_dma_alloc_desc( pdev, lp, desc );
1038 // if( status == 0 ) {
1039 // status = wl_pci_dma_alloc_buf( pdev, lp, *desc, size );
1043 } // wl_pci_dma_alloc_desc_and_buf
1044 /*============================================================================*/
1046 /*******************************************************************************
1047 * wl_pci_dma_free_desc_and_buf()
1048 *******************************************************************************
1052 * Frees a DMA descriptor and associated buffer.
1056 * pdev - a pointer to the device's pci_dev structure
1057 * lp - the device's private adapter structure
1058 * desc - a pointer which will reference the descriptor to be alloc'd
1063 * errno value otherwise
1065 ******************************************************************************/
1066 int wl_pci_dma_free_desc_and_buf( struct pci_dev *pdev, struct wl_private *lp,
1070 /*------------------------------------------------------------------------*/
1072 if( desc == NULL ) {
1075 if( status == 0 && *desc == NULL ) {
1079 status = wl_pci_dma_free_buf( pdev, lp, *desc );
1082 status = wl_pci_dma_free_desc( pdev, lp, desc );
1086 } // wl_pci_dma_free_desc_and_buf
1087 /*============================================================================*/
1089 /*******************************************************************************
1090 * wl_pci_dma_alloc_desc()
1091 *******************************************************************************
1095 * Allocates one DMA descriptor in cache coherent memory.
1099 * pdev - a pointer to the device's pci_dev structure
1100 * lp - the device's private adapter structure
1105 * errno value otherwise
1107 ******************************************************************************/
1108 int wl_pci_dma_alloc_desc( struct pci_dev *pdev, struct wl_private *lp,
1113 // /*------------------------------------------------------------------------*/
1115 // DBG_FUNC( "wl_pci_dma_alloc_desc" );
1116 // DBG_ENTER( DbgInfo );
1118 // if( desc == NULL ) {
1119 // status = -EFAULT;
1121 // if( status == 0 ) {
1122 // *desc = pci_alloc_consistent( pdev, sizeof( DESC_STRCT ), &pa );
1124 // if( *desc == NULL ) {
1125 // DBG_ERROR( DbgInfo, "pci_alloc_consistent() failed\n" );
1126 // status = -ENOMEM;
1128 // memset( *desc, 0, sizeof( DESC_STRCT ));
1129 // (*desc)->desc_phys_addr = cpu_to_le32( pa );
1131 // DBG_LEAVE( DbgInfo );
1133 } // wl_pci_dma_alloc_desc
1134 /*============================================================================*/
1136 /*******************************************************************************
1137 * wl_pci_dma_free_desc()
1138 *******************************************************************************
1142 * Frees one DMA descriptor in cache coherent memory.
1146 * pdev - a pointer to the device's pci_dev structure
1147 * lp - the device's private adapter structure
1152 * errno value otherwise
1154 ******************************************************************************/
1155 int wl_pci_dma_free_desc( struct pci_dev *pdev, struct wl_private *lp,
1159 /*------------------------------------------------------------------------*/
1161 if( *desc == NULL ) {
1165 pci_free_consistent( pdev, sizeof( DESC_STRCT ), *desc,
1166 (*desc)->desc_phys_addr );
1170 } // wl_pci_dma_free_desc
1171 /*============================================================================*/
1173 /*******************************************************************************
1174 * wl_pci_dma_alloc_buf()
1175 *******************************************************************************
1179 * Allocates one DMA buffer in cache coherent memory, and associates a DMA
1180 * descriptor with this buffer.
1184 * pdev - a pointer to the device's pci_dev structure
1185 * lp - the device's private adapter structure
1190 * errno value otherwise
1192 ******************************************************************************/
1193 int wl_pci_dma_alloc_buf( struct pci_dev *pdev, struct wl_private *lp,
1194 DESC_STRCT *desc, int size )
1198 /*------------------------------------------------------------------------*/
1200 // DBG_FUNC( "wl_pci_dma_alloc_buf" );
1201 // DBG_ENTER( DbgInfo );
1203 // if( desc == NULL ) {
1204 // status = -EFAULT;
1206 // if( status == 0 && desc->buf_addr != NULL ) {
1207 // status = -EFAULT;
1209 // if( status == 0 ) {
1210 // desc->buf_addr = pci_alloc_consistent( pdev, size, &pa );
1212 // if( desc->buf_addr == NULL ) {
1213 // DBG_ERROR( DbgInfo, "pci_alloc_consistent() failed\n" );
1214 // status = -ENOMEM;
1216 // desc->buf_phys_addr = cpu_to_le32( pa );
1217 // SET_BUF_SIZE( desc, size );
1219 // DBG_LEAVE( DbgInfo );
1221 } // wl_pci_dma_alloc_buf
1222 /*============================================================================*/
1224 /*******************************************************************************
1225 * wl_pci_dma_free_buf()
1226 *******************************************************************************
1230 * Allocates one DMA buffer in cache coherent memory, and associates a DMA
1231 * descriptor with this buffer.
1235 * pdev - a pointer to the device's pci_dev structure
1236 * lp - the device's private adapter structure
1241 * errno value otherwise
1243 ******************************************************************************/
1244 int wl_pci_dma_free_buf( struct pci_dev *pdev, struct wl_private *lp,
1248 /*------------------------------------------------------------------------*/
1250 if( desc == NULL ) {
1253 if( status == 0 && desc->buf_addr == NULL ) {
1257 pci_free_consistent( pdev, GET_BUF_SIZE( desc ), desc->buf_addr,
1258 desc->buf_phys_addr );
1261 desc->buf_phys_addr = 0;
1262 SET_BUF_SIZE( desc, 0 );
1265 } // wl_pci_dma_free_buf
1266 /*============================================================================*/
1268 /*******************************************************************************
1269 * wl_pci_dma_hcf_supply()
1270 *******************************************************************************
1274 * Supply HCF with DMA-related resources. These consist of:
1275 * - buffers and descriptors for receive purposes
1276 * - one 'reclaim' descriptor for the transmit path, used to fulfill a
1277 * certain H25 DMA engine requirement
1278 * - one 'reclaim' descriptor for the receive path, used to fulfill a
1279 * certain H25 DMA engine requirement
1281 * This function is called at start-of-day or at re-initialization.
1285 * lp - the device's private adapter structure
1290 * errno value otherwise
1292 ******************************************************************************/
1293 void wl_pci_dma_hcf_supply( struct wl_private *lp )
1296 /*------------------------------------------------------------------------*/
1298 DBG_FUNC( "wl_pci_dma_hcf_supply" );
1299 DBG_ENTER( DbgInfo );
1301 //if( lp->dma.status == 0 );
1303 /* Hand over the Rx/Tx reclaim descriptors to the HCF */
1304 if( lp->dma.tx_reclaim_desc ) {
1305 DBG_PRINT( "lp->dma.tx_reclaim_desc: 0x%p\n", lp->dma.tx_reclaim_desc );
1306 hcf_dma_tx_put( &lp->hcfCtx, lp->dma.tx_reclaim_desc, 0 );
1307 lp->dma.tx_reclaim_desc = NULL;
1308 DBG_PRINT( "lp->dma.tx_reclaim_desc: 0x%p\n", lp->dma.tx_reclaim_desc );
1310 if( lp->dma.rx_reclaim_desc ) {
1311 DBG_PRINT( "lp->dma.rx_reclaim_desc: 0x%p\n", lp->dma.rx_reclaim_desc );
1312 hcf_dma_rx_put( &lp->hcfCtx, lp->dma.rx_reclaim_desc );
1313 lp->dma.rx_reclaim_desc = NULL;
1314 DBG_PRINT( "lp->dma.rx_reclaim_desc: 0x%p\n", lp->dma.rx_reclaim_desc );
1316 /* Hand over the Rx descriptor chain to the HCF */
1317 for( i = 0; i < NUM_RX_DESC; i++ ) {
1318 DBG_PRINT( "lp->dma.rx_packet[%d]: 0x%p\n", i, lp->dma.rx_packet[i] );
1319 hcf_dma_rx_put( &lp->hcfCtx, lp->dma.rx_packet[i] );
1320 lp->dma.rx_packet[i] = NULL;
1321 DBG_PRINT( "lp->dma.rx_packet[%d]: 0x%p\n", i, lp->dma.rx_packet[i] );
1325 DBG_LEAVE( DbgInfo );
1327 } // wl_pci_dma_hcf_supply
1328 /*============================================================================*/
1330 /*******************************************************************************
1331 * wl_pci_dma_hcf_reclaim()
1332 *******************************************************************************
1336 * Return DMA-related resources from the HCF. These consist of:
1337 * - buffers and descriptors for receive purposes
1338 * - buffers and descriptors for transmit purposes
1339 * - one 'reclaim' descriptor for the transmit path, used to fulfill a
1340 * certain H25 DMA engine requirement
1341 * - one 'reclaim' descriptor for the receive path, used to fulfill a
1342 * certain H25 DMA engine requirement
1344 * This function is called at end-of-day or at re-initialization.
1348 * lp - the device's private adapter structure
1353 * errno value otherwise
1355 ******************************************************************************/
1356 void wl_pci_dma_hcf_reclaim( struct wl_private *lp )
1359 /*------------------------------------------------------------------------*/
1361 DBG_FUNC( "wl_pci_dma_hcf_reclaim" );
1362 DBG_ENTER( DbgInfo );
1364 wl_pci_dma_hcf_reclaim_rx( lp );
1365 for( i = 0; i < NUM_RX_DESC; i++ ) {
1366 DBG_PRINT( "rx_packet[%d] 0x%p\n", i, lp->dma.rx_packet[i] );
1367 // if( lp->dma.rx_packet[i] == NULL ) {
1368 // DBG_PRINT( "wl_pci_dma_hcf_reclaim: rx_packet[%d] NULL\n", i );
1372 wl_pci_dma_hcf_reclaim_tx( lp );
1373 for( i = 0; i < NUM_TX_DESC; i++ ) {
1374 DBG_PRINT( "tx_packet[%d] 0x%p\n", i, lp->dma.tx_packet[i] );
1375 // if( lp->dma.tx_packet[i] == NULL ) {
1376 // DBG_PRINT( "wl_pci_dma_hcf_reclaim: tx_packet[%d] NULL\n", i );
1380 DBG_LEAVE( DbgInfo );
1382 } // wl_pci_dma_hcf_reclaim
1383 /*============================================================================*/
1385 /*******************************************************************************
1386 * wl_pci_dma_hcf_reclaim_rx()
1387 *******************************************************************************
1391 * Reclaim Rx packets that have already been processed by the HCF.
1395 * lp - the device's private adapter structure
1400 * errno value otherwise
1402 ******************************************************************************/
1403 void wl_pci_dma_hcf_reclaim_rx( struct wl_private *lp )
1407 /*------------------------------------------------------------------------*/
1409 DBG_FUNC( "wl_pci_dma_hcf_reclaim_rx" );
1410 DBG_ENTER( DbgInfo );
1412 //if( lp->dma.status == 0 )
1414 while ( ( p = hcf_dma_rx_get( &lp->hcfCtx ) ) != NULL ) {
1415 if( p && p->buf_addr == NULL ) {
1416 /* A reclaim descriptor is being given back by the HCF. Reclaim
1417 descriptors have a NULL buf_addr */
1418 lp->dma.rx_reclaim_desc = p;
1419 DBG_PRINT( "reclaim_descriptor: 0x%p\n", p );
1422 for( i = 0; i < NUM_RX_DESC; i++ ) {
1423 if( lp->dma.rx_packet[i] == NULL ) {
1427 /* An Rx buffer descriptor is being given back by the HCF */
1428 lp->dma.rx_packet[i] = p;
1429 lp->dma.rx_rsc_ind++;
1430 DBG_PRINT( "rx_packet[%d] 0x%p\n", i, lp->dma.rx_packet[i] );
1433 DBG_LEAVE( DbgInfo );
1434 } // wl_pci_dma_hcf_reclaim_rx
1435 /*============================================================================*/
1437 /*******************************************************************************
1438 * wl_pci_dma_get_tx_packet()
1439 *******************************************************************************
1443 * Obtains a Tx descriptor from the chain to use for Tx.
1447 * lp - a pointer to the device's wl_private structure.
1451 * A pointer to the retrieved descriptor
1453 ******************************************************************************/
1454 DESC_STRCT * wl_pci_dma_get_tx_packet( struct wl_private *lp )
1457 DESC_STRCT *desc = NULL;
1458 /*------------------------------------------------------------------------*/
1460 for( i = 0; i < NUM_TX_DESC; i++ ) {
1461 if( lp->dma.tx_packet[i] ) {
1466 if( i != NUM_TX_DESC ) {
1467 desc = lp->dma.tx_packet[i];
1469 lp->dma.tx_packet[i] = NULL;
1470 lp->dma.tx_rsc_ind--;
1472 memset( desc->buf_addr, 0, HCF_DMA_TX_BUF1_SIZE );
1476 } // wl_pci_dma_get_tx_packet
1477 /*============================================================================*/
1479 /*******************************************************************************
1480 * wl_pci_dma_put_tx_packet()
1481 *******************************************************************************
1485 * Returns a Tx descriptor to the chain.
1489 * lp - a pointer to the device's wl_private structure.
1490 * desc - a pointer to the descriptor to return.
1496 ******************************************************************************/
1497 void wl_pci_dma_put_tx_packet( struct wl_private *lp, DESC_STRCT *desc )
1500 /*------------------------------------------------------------------------*/
1502 for( i = 0; i < NUM_TX_DESC; i++ ) {
1503 if( lp->dma.tx_packet[i] == NULL ) {
1508 if( i != NUM_TX_DESC ) {
1509 lp->dma.tx_packet[i] = desc;
1510 lp->dma.tx_rsc_ind++;
1512 } // wl_pci_dma_put_tx_packet
1513 /*============================================================================*/
1515 /*******************************************************************************
1516 * wl_pci_dma_hcf_reclaim_tx()
1517 *******************************************************************************
1521 * Reclaim Tx packets that have either been processed by the HCF due to a
1522 * port disable or a Tx completion.
1526 * lp - the device's private adapter structure
1531 * errno value otherwise
1533 ******************************************************************************/
1534 void wl_pci_dma_hcf_reclaim_tx( struct wl_private *lp )
1538 /*------------------------------------------------------------------------*/
1540 DBG_FUNC( "wl_pci_dma_hcf_reclaim_tx" );
1541 DBG_ENTER( DbgInfo );
1543 //if( lp->dma.status == 0 )
1545 while ( ( p = hcf_dma_tx_get( &lp->hcfCtx ) ) != NULL ) {
1547 if( p != NULL && p->buf_addr == NULL ) {
1548 /* A Reclaim descriptor is being given back by the HCF. Reclaim
1549 descriptors have a NULL buf_addr */
1550 lp->dma.tx_reclaim_desc = p;
1551 DBG_PRINT( "reclaim_descriptor: 0x%p\n", p );
1554 for( i = 0; i < NUM_TX_DESC; i++ ) {
1555 if( lp->dma.tx_packet[i] == NULL ) {
1559 /* An Rx buffer descriptor is being given back by the HCF */
1560 lp->dma.tx_packet[i] = p;
1561 lp->dma.tx_rsc_ind++;
1562 DBG_PRINT( "tx_packet[%d] 0x%p\n", i, lp->dma.tx_packet[i] );
1566 if( lp->netif_queue_on == FALSE ) {
1567 netif_wake_queue( lp->dev );
1568 WL_WDS_NETIF_WAKE_QUEUE( lp );
1569 lp->netif_queue_on = TRUE;
1571 DBG_LEAVE( DbgInfo );
1573 } // wl_pci_dma_hcf_reclaim_tx
1574 /*============================================================================*/
1575 #endif // ENABLE_DMA