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 enum hermes_pci_versions {
116 CH_Agere_Systems_Mini_PCI_V1 = 0,
119 static struct pci_device_id wl_pci_tbl[] __devinitdata = {
120 { WL_LKM_PCI_VENDOR_ID, WL_LKM_PCI_DEVICE_ID_0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_Agere_Systems_Mini_PCI_V1 },
121 { WL_LKM_PCI_VENDOR_ID, WL_LKM_PCI_DEVICE_ID_1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_Agere_Systems_Mini_PCI_V1 },
122 { WL_LKM_PCI_VENDOR_ID, WL_LKM_PCI_DEVICE_ID_2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_Agere_Systems_Mini_PCI_V1 },
123 { } /* Terminating entry */
126 MODULE_DEVICE_TABLE(pci, wl_pci_tbl);
128 /*******************************************************************************
129 * function prototypes
130 ******************************************************************************/
131 int __devinit wl_pci_probe( struct pci_dev *pdev,
132 const struct pci_device_id *ent );
133 void __devexit wl_pci_remove(struct pci_dev *pdev);
134 int wl_pci_setup( struct pci_dev *pdev );
135 void wl_pci_enable_cardbus_interrupts( struct pci_dev *pdev );
138 int wl_pci_dma_alloc( struct pci_dev *pdev, struct wl_private *lp );
139 int wl_pci_dma_free( struct pci_dev *pdev, struct wl_private *lp );
140 int wl_pci_dma_alloc_tx_packet( struct pci_dev *pdev, struct wl_private *lp,
142 int wl_pci_dma_free_tx_packet( struct pci_dev *pdev, struct wl_private *lp,
144 int wl_pci_dma_alloc_rx_packet( struct pci_dev *pdev, struct wl_private *lp,
146 int wl_pci_dma_free_rx_packet( struct pci_dev *pdev, struct wl_private *lp,
148 int wl_pci_dma_alloc_desc_and_buf( struct pci_dev *pdev, struct wl_private *lp,
149 DESC_STRCT **desc, int size );
150 int wl_pci_dma_free_desc_and_buf( struct pci_dev *pdev, struct wl_private *lp,
152 int wl_pci_dma_alloc_desc( struct pci_dev *pdev, struct wl_private *lp,
154 int wl_pci_dma_free_desc( struct pci_dev *pdev, struct wl_private *lp,
156 int wl_pci_dma_alloc_buf( struct pci_dev *pdev, struct wl_private *lp,
157 DESC_STRCT *desc, int size );
158 int wl_pci_dma_free_buf( struct pci_dev *pdev, struct wl_private *lp,
161 void wl_pci_dma_hcf_reclaim_rx( struct wl_private *lp );
164 /*******************************************************************************
165 * PCI module function registration
166 ******************************************************************************/
167 static struct pci_driver wl_driver =
170 id_table: wl_pci_tbl,
172 remove: __devexit_p(wl_pci_remove),
177 /*******************************************************************************
178 * wl_adapter_init_module()
179 *******************************************************************************
183 * Called by init_module() to perform PCI-specific driver initialization.
193 ******************************************************************************/
194 int wl_adapter_init_module( void )
197 /*------------------------------------------------------------------------*/
199 DBG_FUNC( "wl_adapter_init_module()" );
200 DBG_ENTER( DbgInfo );
201 DBG_TRACE( DbgInfo, "wl_adapter_init_module() -- PCI\n" );
203 result = pci_register_driver( &wl_driver ); //;?replace with pci_module_init, Rubini pg 490
204 //;? why not do something with the result
206 DBG_LEAVE( DbgInfo );
208 } // wl_adapter_init_module
209 /*============================================================================*/
211 /*******************************************************************************
212 * wl_adapter_cleanup_module()
213 *******************************************************************************
217 * Called by cleanup_module() to perform PCI-specific driver cleanup.
227 ******************************************************************************/
228 void wl_adapter_cleanup_module( void )
230 //;?how comes wl_adapter_cleanup_module is located in a seemingly pci specific module
231 DBG_FUNC( "wl_adapter_cleanup_module" );
232 DBG_ENTER( DbgInfo );
234 //;?DBG_TRACE below feels like nearly redundant in the light of DBG_ENTER above
235 DBG_TRACE( DbgInfo, "wl_adapter_cleanup_module() -- PCI\n" );
237 pci_unregister_driver( &wl_driver );
239 DBG_LEAVE( DbgInfo );
241 } // wl_adapter_cleanup_module
242 /*============================================================================*/
244 /*******************************************************************************
245 * wl_adapter_insert()
246 *******************************************************************************
250 * Called by wl_pci_probe() to continue the process of device insertion.
254 * dev - a pointer to the device's net_device structure
260 ******************************************************************************/
261 int wl_adapter_insert( struct net_device *dev )
264 /*------------------------------------------------------------------------*/
266 DBG_FUNC( "wl_adapter_insert" );
267 DBG_ENTER( DbgInfo );
269 DBG_TRACE( DbgInfo, "wl_adapter_insert() -- PCI\n" );
272 DBG_ERROR( DbgInfo, "net_device pointer is NULL!!!\n" );
273 } else if( dev->priv == NULL ) {
274 DBG_ERROR( DbgInfo, "wl_private pointer is NULL!!!\n" );
275 } else if( wl_insert( dev ) ) { /* Perform remaining device initialization */
278 DBG_TRACE( DbgInfo, "wl_insert() FAILED\n" );
280 DBG_LEAVE( DbgInfo );
282 } // wl_adapter_insert
283 /*============================================================================*/
285 /*******************************************************************************
287 *******************************************************************************
295 * dev - a pointer to the device's net_device structure
301 ******************************************************************************/
302 int wl_adapter_open( struct net_device *dev )
305 int hcf_status = HCF_SUCCESS;
306 /*------------------------------------------------------------------------*/
308 DBG_FUNC( "wl_adapter_open" );
309 DBG_ENTER( DbgInfo );
311 DBG_TRACE( DbgInfo, "wl_adapter_open() -- PCI\n" );
313 hcf_status = wl_open( dev );
315 if( hcf_status != HCF_SUCCESS ) {
319 DBG_LEAVE( DbgInfo );
322 /*============================================================================*/
324 /*******************************************************************************
326 *******************************************************************************
334 * dev - a pointer to the device's net_device structure
340 ******************************************************************************/
341 int wl_adapter_close( struct net_device *dev )
343 DBG_FUNC( "wl_adapter_close" );
344 DBG_ENTER( DbgInfo );
346 DBG_TRACE( DbgInfo, "wl_adapter_close() -- PCI\n" );
347 DBG_TRACE( DbgInfo, "%s: Shutting down adapter.\n", dev->name );
351 DBG_LEAVE( DbgInfo );
353 } // wl_adapter_close
354 /*============================================================================*/
356 /*******************************************************************************
357 * wl_adapter_is_open()
358 *******************************************************************************
362 * Check whether this device is open. Returns
366 * dev - a pointer to the device's net_device structure
370 * nonzero if device is open.
372 ******************************************************************************/
373 int wl_adapter_is_open( struct net_device *dev )
375 /* This function is used in PCMCIA to check the status of the 'open' field
376 in the dev_link_t structure associated with a network device. There
377 doesn't seem to be an analog to this for PCI, and checking the status
378 contained in the net_device structure doesn't have the same effect.
379 For now, return TRUE, but find out if this is necessary for PCI. */
382 } // wl_adapter_is_open
383 /*============================================================================*/
385 /*******************************************************************************
387 *******************************************************************************
391 * Registered in the pci_driver structure, this function is called when the
392 * PCI subsystem finds a new PCI device which matches the infomation contained
393 * in the pci_device_id table.
397 * pdev - a pointer to the device's pci_dev structure
398 * ent - this device's entry in the pci_device_id table
403 * errno value otherwise
405 ******************************************************************************/
406 int __devinit wl_pci_probe( struct pci_dev *pdev,
407 const struct pci_device_id *ent )
410 /*------------------------------------------------------------------------*/
412 DBG_FUNC( "wl_pci_probe" );
413 DBG_ENTER( DbgInfo );
414 DBG_PRINT( "%s\n", VERSION_INFO );
416 result = wl_pci_setup( pdev );
418 DBG_LEAVE( DbgInfo );
422 /*============================================================================*/
424 /*******************************************************************************
426 *******************************************************************************
430 * Registered in the pci_driver structure, this function is called when the
431 * PCI subsystem detects that a PCI device which matches the infomation
432 * contained in the pci_device_id table has been removed.
436 * pdev - a pointer to the device's pci_dev structure
442 ******************************************************************************/
443 void __devexit wl_pci_remove(struct pci_dev *pdev)
445 struct net_device *dev = NULL;
446 /*------------------------------------------------------------------------*/
448 DBG_FUNC( "wl_pci_remove" );
449 DBG_ENTER( DbgInfo );
451 /* Make sure the pci_dev pointer passed in is valid */
453 DBG_ERROR( DbgInfo, "PCI subsys passed in an invalid pci_dev pointer\n" );
457 dev = (struct net_device *)pci_get_drvdata( pdev );
459 DBG_ERROR( DbgInfo, "Could not retrieve net_device structure\n" );
463 /* Perform device cleanup */
465 free_irq( dev->irq, dev );
468 wl_pci_dma_free( pdev, (struct wl_private *)dev->priv );
471 wl_device_dealloc( dev );
473 DBG_LEAVE( DbgInfo );
476 /*============================================================================*/
478 /*******************************************************************************
480 *******************************************************************************
484 * Called by wl_pci_probe() to begin a device's initialization process.
488 * pdev - a pointer to the device's pci_dev structure
493 * errno value otherwise
495 ******************************************************************************/
496 int wl_pci_setup( struct pci_dev *pdev )
499 struct net_device *dev = NULL;
500 struct wl_private *lp = NULL;
501 /*------------------------------------------------------------------------*/
503 DBG_FUNC( "wl_pci_setup" );
504 DBG_ENTER( DbgInfo );
506 /* Make sure the pci_dev pointer passed in is valid */
508 DBG_ERROR( DbgInfo, "PCI subsys passed in an invalid pci_dev pointer\n" );
512 result = pci_enable_device( pdev );
514 DBG_ERROR( DbgInfo, "pci_enable_device() failed\n" );
515 DBG_LEAVE( DbgInfo );
519 /* We found our device! Let's register it with the system */
520 DBG_TRACE( DbgInfo, "Found our device, now registering\n" );
521 dev = wl_device_alloc( );
523 DBG_ERROR( DbgInfo, "Could not register device!!!\n" );
524 DBG_LEAVE( DbgInfo );
528 /* Make sure that space was allocated for our private adapter struct */
529 if( dev->priv == NULL ) {
530 DBG_ERROR( DbgInfo, "Private adapter struct was not allocated!!!\n" );
531 DBG_LEAVE( DbgInfo );
536 /* Allocate DMA Descriptors */
537 if( wl_pci_dma_alloc( pdev, (struct wl_private *)dev->priv ) < 0 ) {
538 DBG_ERROR( DbgInfo, "Could not allocate DMA descriptor memory!!!\n" );
539 DBG_LEAVE( DbgInfo );
544 /* Register our private adapter structure with PCI */
545 pci_set_drvdata( pdev, dev );
547 /* Fill out bus specific information in the net_device struct */
548 dev->irq = pdev->irq;
549 SET_MODULE_OWNER( dev );
551 DBG_TRACE( DbgInfo, "Device Base Address: %#03lx\n", pdev->resource[0].start );
552 dev->base_addr = pdev->resource[0].start;
554 /* Initialize our device here */
555 if( !wl_adapter_insert( dev )) {
556 DBG_ERROR( DbgInfo, "wl_adapter_insert() FAILED!!!\n" );
557 wl_device_dealloc( dev );
558 DBG_LEAVE( DbgInfo );
562 /* Register our ISR */
563 DBG_TRACE( DbgInfo, "Registering ISR...\n" );
565 result = request_irq(dev->irq, wl_isr, SA_SHIRQ, dev->name, dev);
567 DBG_WARNING( DbgInfo, "Could not register ISR!!!\n" );
568 DBG_LEAVE( DbgInfo );
572 /* Make sure interrupts are enabled properly for CardBus */
573 lp = (struct wl_private *)dev->priv;
575 if( lp->hcfCtx.IFB_BusType == CFG_NIC_BUS_TYPE_CARDBUS ||
576 lp->hcfCtx.IFB_BusType == CFG_NIC_BUS_TYPE_PCI ) {
577 DBG_TRACE( DbgInfo, "This is a PCI/CardBus card, enable interrupts\n" );
578 wl_pci_enable_cardbus_interrupts( pdev );
581 /* Enable bus mastering */
582 pci_set_master( pdev );
584 DBG_LEAVE( DbgInfo );
587 /*============================================================================*/
589 /*******************************************************************************
590 * wl_pci_enable_cardbus_interrupts()
591 *******************************************************************************
595 * Called by wl_pci_setup() to enable interrupts on a CardBus device. This
596 * is done by writing bit 15 to the function event mask register. This
597 * CardBus-specific register is located in BAR2 (counting from BAR0), in memory
598 * space at byte offset 1f4 (7f4 for WARP).
602 * pdev - a pointer to the device's pci_dev structure
608 ******************************************************************************/
609 void wl_pci_enable_cardbus_interrupts( struct pci_dev *pdev )
613 u32 func_evt_mask_reg;
614 void *mem_addr_kern = NULL;
615 /*------------------------------------------------------------------------*/
617 DBG_FUNC( "wl_pci_enable_cardbus_interrupts" );
618 DBG_ENTER( DbgInfo );
620 /* Initialize to known bad values */
621 bar2_reg = 0xdeadbeef;
622 mem_addr_bus = 0xdeadbeef;
624 /* Read the BAR2 register; this register contains the base address of the
625 memory region where the function event mask register lives */
626 pci_read_config_dword( pdev, PCI_BASE_ADDRESS_2, &bar2_reg );
627 mem_addr_bus = bar2_reg & PCI_BASE_ADDRESS_MEM_MASK;
629 /* Once the base address is obtained, remap the memory region to kernel
630 space so we can retrieve the register */
631 mem_addr_kern = ioremap( mem_addr_bus, 0x200 );
634 #define REG_OFFSET 0x07F4
636 #define REG_OFFSET 0x01F4
641 /* Retrieve the functional event mask register, enable interrupts by
642 setting Bit 15, and write back the value */
643 func_evt_mask_reg = *(u32 *)( mem_addr_kern + REG_OFFSET );
644 func_evt_mask_reg |= BIT15;
645 *(u32 *)( mem_addr_kern + REG_OFFSET ) = func_evt_mask_reg;
647 /* Once complete, unmap the region and exit */
648 iounmap( mem_addr_kern );
650 DBG_LEAVE( DbgInfo );
652 } // wl_pci_enable_cardbus_interrupts
653 /*============================================================================*/
656 /*******************************************************************************
658 *******************************************************************************
662 * Allocates all resources needed for PCI/CardBus DMA operation
666 * pdev - a pointer to the device's pci_dev structure
667 * lp - the device's private adapter structure
672 * errno value otherwise
674 ******************************************************************************/
675 int wl_pci_dma_alloc( struct pci_dev *pdev, struct wl_private *lp )
679 /*------------------------------------------------------------------------*/
681 DBG_FUNC( "wl_pci_dma_alloc" );
682 DBG_ENTER( DbgInfo );
684 // lp->dma.tx_rsc_ind = lp->dma.rx_rsc_ind = 0;
686 // /* Alloc for the Tx chain and its reclaim descriptor */
687 // for( i = 0; i < NUM_TX_DESC; i++ ) {
688 // status = wl_pci_dma_alloc_tx_packet( pdev, lp, &lp->dma.tx_packet[i] );
689 // if( status == 0 ) {
690 // DBG_PRINT( "lp->dma.tx_packet[%d] : 0x%p\n", i, lp->dma.tx_packet[i] );
691 // DBG_PRINT( "lp->dma.tx_packet[%d]->next_desc_addr : 0x%p\n", i, lp->dma.tx_packet[i]->next_desc_addr );
692 // lp->dma.tx_rsc_ind++;
694 // DBG_ERROR( DbgInfo, "Could not alloc DMA Tx Packet\n" );
698 // if( status == 0 ) {
699 // status = wl_pci_dma_alloc_desc( pdev, lp, &lp->dma.tx_reclaim_desc );
700 // DBG_PRINT( "lp->dma.tx_reclaim_desc: 0x%p\n", lp->dma.tx_reclaim_desc );
702 // /* Alloc for the Rx chain and its reclaim descriptor */
703 // if( status == 0 ) {
704 // for( i = 0; i < NUM_RX_DESC; i++ ) {
705 // status = wl_pci_dma_alloc_rx_packet( pdev, lp, &lp->dma.rx_packet[i] );
706 // if( status == 0 ) {
707 // DBG_PRINT( "lp->dma.rx_packet[%d] : 0x%p\n", i, lp->dma.rx_packet[i] );
708 // DBG_PRINT( "lp->dma.rx_packet[%d]->next_desc_addr : 0x%p\n", i, lp->dma.rx_packet[i]->next_desc_addr );
709 // lp->dma.rx_rsc_ind++;
711 // DBG_ERROR( DbgInfo, "Could not alloc DMA Rx Packet\n" );
716 // if( status == 0 ) {
717 // status = wl_pci_dma_alloc_desc( pdev, lp, &lp->dma.rx_reclaim_desc );
718 // DBG_PRINT( "lp->dma.rx_reclaim_desc: 0x%p\n", lp->dma.rx_reclaim_desc );
720 // /* Store status, as host should not call HCF functions if this fails */
721 // lp->dma.status = status; //;?all useages of dma.status have been commented out
722 // DBG_LEAVE( DbgInfo );
724 } // wl_pci_dma_alloc
725 /*============================================================================*/
727 /*******************************************************************************
729 *******************************************************************************
733 * Deallocated all resources needed for PCI/CardBus DMA operation
737 * pdev - a pointer to the device's pci_dev structure
738 * lp - the device's private adapter structure
743 * errno value otherwise
745 ******************************************************************************/
746 int wl_pci_dma_free( struct pci_dev *pdev, struct wl_private *lp )
750 /*------------------------------------------------------------------------*/
752 DBG_FUNC( "wl_pci_dma_free" );
753 DBG_ENTER( DbgInfo );
755 /* Reclaim all Rx packets that were handed over to the HCF */
756 /* Do I need to do this? Before this free is called, I've already disabled
757 the port which will call wl_pci_dma_hcf_reclaim */
758 //if( lp->dma.status == 0 )
760 // wl_pci_dma_hcf_reclaim( lp );
763 /* Free everything needed for DMA Rx */
764 for( i = 0; i < NUM_RX_DESC; i++ ) {
765 if( lp->dma.rx_packet[i] ) {
766 status = wl_pci_dma_free_rx_packet( pdev, lp, &lp->dma.rx_packet[i] );
768 DBG_WARNING( DbgInfo, "Problem freeing Rx packet\n" );
772 lp->dma.rx_rsc_ind = 0;
774 if( lp->dma.rx_reclaim_desc ) {
775 status = wl_pci_dma_free_desc( pdev, lp, &lp->dma.rx_reclaim_desc );
777 DBG_WARNING( DbgInfo, "Problem freeing Rx reclaim descriptor\n" );
781 /* Free everything needed for DMA Tx */
782 for( i = 0; i < NUM_TX_DESC; i++ ) {
783 if( lp->dma.tx_packet[i] ) {
784 status = wl_pci_dma_free_tx_packet( pdev, lp, &lp->dma.tx_packet[i] );
786 DBG_WARNING( DbgInfo, "Problem freeing Tx packet\n" );
790 lp->dma.tx_rsc_ind = 0;
792 if( lp->dma.tx_reclaim_desc ) {
793 status = wl_pci_dma_free_desc( pdev, lp, &lp->dma.tx_reclaim_desc );
795 DBG_WARNING( DbgInfo, "Problem freeing Tx reclaim descriptor\n" );
799 DBG_LEAVE( DbgInfo );
803 /*============================================================================*/
805 /*******************************************************************************
806 * wl_pci_dma_alloc_tx_packet()
807 *******************************************************************************
811 * Allocates a single Tx packet, consisting of several descriptors and
812 * buffers. Data to transmit is first copied into the 'payload' buffer
813 * before being transmitted.
817 * pdev - a pointer to the device's pci_dev structure
818 * lp - the device's private adapter structure
819 * desc - a pointer which will reference the descriptor to be alloc'd.
824 * errno value otherwise
826 ******************************************************************************/
827 int wl_pci_dma_alloc_tx_packet( struct pci_dev *pdev, struct wl_private *lp,
831 // /*------------------------------------------------------------------------*/
833 // if( desc == NULL ) {
836 // if( status == 0 ) {
837 // status = wl_pci_dma_alloc_desc_and_buf( pdev, lp, desc,
838 // HCF_DMA_TX_BUF1_SIZE );
840 // if( status == 0 ) {
841 // status = wl_pci_dma_alloc_desc_and_buf( pdev, lp,
842 // &( (*desc)->next_desc_addr ),
843 // HCF_MAX_PACKET_SIZE );
846 // if( status == 0 ) {
847 // (*desc)->next_desc_phys_addr = (*desc)->next_desc_addr->desc_phys_addr;
850 } // wl_pci_dma_alloc_tx_packet
851 /*============================================================================*/
853 /*******************************************************************************
854 * wl_pci_dma_free_tx_packet()
855 *******************************************************************************
859 * Frees a single Tx packet, described in the corresponding alloc function.
863 * pdev - a pointer to the device's pci_dev structure
864 * lp - the device's private adapter structure
865 * desc - a pointer which will reference the descriptor to be alloc'd.
870 * errno value otherwise
872 ******************************************************************************/
873 int wl_pci_dma_free_tx_packet( struct pci_dev *pdev, struct wl_private *lp,
877 /*------------------------------------------------------------------------*/
879 if( *desc == NULL ) {
880 DBG_PRINT( "Null descriptor\n" );
883 //;?the "limited" NDIS strategy, assuming a frame consists ALWAYS out of 2
884 //descriptors, make this robust
885 if( status == 0 && (*desc)->next_desc_addr ) {
886 status = wl_pci_dma_free_desc_and_buf( pdev, lp, &(*desc)->next_desc_addr );
889 status = wl_pci_dma_free_desc_and_buf( pdev, lp, desc );
892 } // wl_pci_dma_free_tx_packet
893 /*============================================================================*/
895 /*******************************************************************************
896 * wl_pci_dma_alloc_rx_packet()
897 *******************************************************************************
901 * Allocates a single Rx packet, consisting of two descriptors and one
902 * contiguous buffer. THe buffer starts with the hermes-specific header.
903 * One descriptor points at the start, the other at offset 0x3a of the
908 * pdev - a pointer to the device's pci_dev structure
909 * lp - the device's private adapter structure
910 * desc - a pointer which will reference the descriptor to be alloc'd.
915 * errno value otherwise
917 ******************************************************************************/
918 int wl_pci_dma_alloc_rx_packet( struct pci_dev *pdev, struct wl_private *lp,
923 /*------------------------------------------------------------------------*/
925 // if( desc == NULL ) {
928 // //;?the "limited" NDIS strategy, assuming a frame consists ALWAYS out of 2
929 // //descriptors, make this robust
930 // if( status == 0 ) {
931 // status = wl_pci_dma_alloc_desc( pdev, lp, desc );
933 // if( status == 0 ) {
934 // status = wl_pci_dma_alloc_buf( pdev, lp, *desc, HCF_MAX_PACKET_SIZE );
936 // if( status == 0 ) {
937 // status = wl_pci_dma_alloc_desc( pdev, lp, &p );
939 // if( status == 0 ) {
940 // /* Size of 1st descriptor becomes 0x3a bytes */
941 // SET_BUF_SIZE( *desc, HCF_DMA_RX_BUF1_SIZE );
943 // /* Make 2nd descriptor point at offset 0x3a of the buffer */
944 // SET_BUF_SIZE( p, ( HCF_MAX_PACKET_SIZE - HCF_DMA_RX_BUF1_SIZE ));
945 // p->buf_addr = (*desc)->buf_addr + HCF_DMA_RX_BUF1_SIZE;
946 // p->buf_phys_addr = (*desc)->buf_phys_addr + HCF_DMA_RX_BUF1_SIZE;
947 // p->next_desc_addr = NULL;
949 // /* Chain 2nd descriptor to 1st descriptor */
950 // (*desc)->next_desc_addr = p;
951 // (*desc)->next_desc_phys_addr = p->desc_phys_addr;
955 } // wl_pci_dma_alloc_rx_packet
956 /*============================================================================*/
958 /*******************************************************************************
959 * wl_pci_dma_free_rx_packet()
960 *******************************************************************************
964 * Frees a single Rx packet, described in the corresponding alloc function.
968 * pdev - a pointer to the device's pci_dev structure
969 * lp - the device's private adapter structure
970 * desc - a pointer which will reference the descriptor to be alloc'd.
975 * errno value otherwise
977 ******************************************************************************/
978 int wl_pci_dma_free_rx_packet( struct pci_dev *pdev, struct wl_private *lp,
983 /*------------------------------------------------------------------------*/
985 if( *desc == NULL ) {
989 p = (*desc)->next_desc_addr;
991 /* Free the 2nd descriptor */
994 p->buf_phys_addr = 0;
996 status = wl_pci_dma_free_desc( pdev, lp, &p );
1000 /* Free the buffer and 1st descriptor */
1002 SET_BUF_SIZE( *desc, HCF_MAX_PACKET_SIZE );
1003 status = wl_pci_dma_free_desc_and_buf( pdev, lp, desc );
1006 } // wl_pci_dma_free_rx_packet
1007 /*============================================================================*/
1009 /*******************************************************************************
1010 * wl_pci_dma_alloc_desc_and_buf()
1011 *******************************************************************************
1015 * Allocates a DMA descriptor and buffer, and associates them with one
1020 * pdev - a pointer to the device's pci_dev structure
1021 * lp - the device's private adapter structure
1022 * desc - a pointer which will reference the descriptor to be alloc'd
1027 * errno value otherwise
1029 ******************************************************************************/
1030 int wl_pci_dma_alloc_desc_and_buf( struct pci_dev *pdev, struct wl_private *lp,
1031 DESC_STRCT **desc, int size )
1034 /*------------------------------------------------------------------------*/
1036 // if( desc == NULL ) {
1037 // status = -EFAULT;
1039 // if( status == 0 ) {
1040 // status = wl_pci_dma_alloc_desc( pdev, lp, desc );
1042 // if( status == 0 ) {
1043 // status = wl_pci_dma_alloc_buf( pdev, lp, *desc, size );
1047 } // wl_pci_dma_alloc_desc_and_buf
1048 /*============================================================================*/
1050 /*******************************************************************************
1051 * wl_pci_dma_free_desc_and_buf()
1052 *******************************************************************************
1056 * Frees a DMA descriptor and associated buffer.
1060 * pdev - a pointer to the device's pci_dev structure
1061 * lp - the device's private adapter structure
1062 * desc - a pointer which will reference the descriptor to be alloc'd
1067 * errno value otherwise
1069 ******************************************************************************/
1070 int wl_pci_dma_free_desc_and_buf( struct pci_dev *pdev, struct wl_private *lp,
1074 /*------------------------------------------------------------------------*/
1076 if( desc == NULL ) {
1079 if( status == 0 && *desc == NULL ) {
1083 status = wl_pci_dma_free_buf( pdev, lp, *desc );
1086 status = wl_pci_dma_free_desc( pdev, lp, desc );
1090 } // wl_pci_dma_free_desc_and_buf
1091 /*============================================================================*/
1093 /*******************************************************************************
1094 * wl_pci_dma_alloc_desc()
1095 *******************************************************************************
1099 * Allocates one DMA descriptor in cache coherent memory.
1103 * pdev - a pointer to the device's pci_dev structure
1104 * lp - the device's private adapter structure
1109 * errno value otherwise
1111 ******************************************************************************/
1112 int wl_pci_dma_alloc_desc( struct pci_dev *pdev, struct wl_private *lp,
1117 // /*------------------------------------------------------------------------*/
1119 // DBG_FUNC( "wl_pci_dma_alloc_desc" );
1120 // DBG_ENTER( DbgInfo );
1122 // if( desc == NULL ) {
1123 // status = -EFAULT;
1125 // if( status == 0 ) {
1126 // *desc = pci_alloc_consistent( pdev, sizeof( DESC_STRCT ), &pa );
1128 // if( *desc == NULL ) {
1129 // DBG_ERROR( DbgInfo, "pci_alloc_consistent() failed\n" );
1130 // status = -ENOMEM;
1132 // memset( *desc, 0, sizeof( DESC_STRCT ));
1133 // (*desc)->desc_phys_addr = cpu_to_le32( pa );
1135 // DBG_LEAVE( DbgInfo );
1137 } // wl_pci_dma_alloc_desc
1138 /*============================================================================*/
1140 /*******************************************************************************
1141 * wl_pci_dma_free_desc()
1142 *******************************************************************************
1146 * Frees one DMA descriptor in cache coherent memory.
1150 * pdev - a pointer to the device's pci_dev structure
1151 * lp - the device's private adapter structure
1156 * errno value otherwise
1158 ******************************************************************************/
1159 int wl_pci_dma_free_desc( struct pci_dev *pdev, struct wl_private *lp,
1163 /*------------------------------------------------------------------------*/
1165 if( *desc == NULL ) {
1169 pci_free_consistent( pdev, sizeof( DESC_STRCT ), *desc,
1170 (*desc)->desc_phys_addr );
1174 } // wl_pci_dma_free_desc
1175 /*============================================================================*/
1177 /*******************************************************************************
1178 * wl_pci_dma_alloc_buf()
1179 *******************************************************************************
1183 * Allocates one DMA buffer in cache coherent memory, and associates a DMA
1184 * descriptor with this buffer.
1188 * pdev - a pointer to the device's pci_dev structure
1189 * lp - the device's private adapter structure
1194 * errno value otherwise
1196 ******************************************************************************/
1197 int wl_pci_dma_alloc_buf( struct pci_dev *pdev, struct wl_private *lp,
1198 DESC_STRCT *desc, int size )
1202 /*------------------------------------------------------------------------*/
1204 // DBG_FUNC( "wl_pci_dma_alloc_buf" );
1205 // DBG_ENTER( DbgInfo );
1207 // if( desc == NULL ) {
1208 // status = -EFAULT;
1210 // if( status == 0 && desc->buf_addr != NULL ) {
1211 // status = -EFAULT;
1213 // if( status == 0 ) {
1214 // desc->buf_addr = pci_alloc_consistent( pdev, size, &pa );
1216 // if( desc->buf_addr == NULL ) {
1217 // DBG_ERROR( DbgInfo, "pci_alloc_consistent() failed\n" );
1218 // status = -ENOMEM;
1220 // desc->buf_phys_addr = cpu_to_le32( pa );
1221 // SET_BUF_SIZE( desc, size );
1223 // DBG_LEAVE( DbgInfo );
1225 } // wl_pci_dma_alloc_buf
1226 /*============================================================================*/
1228 /*******************************************************************************
1229 * wl_pci_dma_free_buf()
1230 *******************************************************************************
1234 * Allocates one DMA buffer in cache coherent memory, and associates a DMA
1235 * descriptor with this buffer.
1239 * pdev - a pointer to the device's pci_dev structure
1240 * lp - the device's private adapter structure
1245 * errno value otherwise
1247 ******************************************************************************/
1248 int wl_pci_dma_free_buf( struct pci_dev *pdev, struct wl_private *lp,
1252 /*------------------------------------------------------------------------*/
1254 if( desc == NULL ) {
1257 if( status == 0 && desc->buf_addr == NULL ) {
1261 pci_free_consistent( pdev, GET_BUF_SIZE( desc ), desc->buf_addr,
1262 desc->buf_phys_addr );
1265 desc->buf_phys_addr = 0;
1266 SET_BUF_SIZE( desc, 0 );
1269 } // wl_pci_dma_free_buf
1270 /*============================================================================*/
1272 /*******************************************************************************
1273 * wl_pci_dma_hcf_supply()
1274 *******************************************************************************
1278 * Supply HCF with DMA-related resources. These consist of:
1279 * - buffers and descriptors for receive purposes
1280 * - one 'reclaim' descriptor for the transmit path, used to fulfill a
1281 * certain H25 DMA engine requirement
1282 * - one 'reclaim' descriptor for the receive path, used to fulfill a
1283 * certain H25 DMA engine requirement
1285 * This function is called at start-of-day or at re-initialization.
1289 * lp - the device's private adapter structure
1294 * errno value otherwise
1296 ******************************************************************************/
1297 void wl_pci_dma_hcf_supply( struct wl_private *lp )
1300 /*------------------------------------------------------------------------*/
1302 DBG_FUNC( "wl_pci_dma_hcf_supply" );
1303 DBG_ENTER( DbgInfo );
1305 //if( lp->dma.status == 0 );
1307 /* Hand over the Rx/Tx reclaim descriptors to the HCF */
1308 if( lp->dma.tx_reclaim_desc ) {
1309 DBG_PRINT( "lp->dma.tx_reclaim_desc: 0x%p\n", lp->dma.tx_reclaim_desc );
1310 hcf_dma_tx_put( &lp->hcfCtx, lp->dma.tx_reclaim_desc, 0 );
1311 lp->dma.tx_reclaim_desc = NULL;
1312 DBG_PRINT( "lp->dma.tx_reclaim_desc: 0x%p\n", lp->dma.tx_reclaim_desc );
1314 if( lp->dma.rx_reclaim_desc ) {
1315 DBG_PRINT( "lp->dma.rx_reclaim_desc: 0x%p\n", lp->dma.rx_reclaim_desc );
1316 hcf_dma_rx_put( &lp->hcfCtx, lp->dma.rx_reclaim_desc );
1317 lp->dma.rx_reclaim_desc = NULL;
1318 DBG_PRINT( "lp->dma.rx_reclaim_desc: 0x%p\n", lp->dma.rx_reclaim_desc );
1320 /* Hand over the Rx descriptor chain to the HCF */
1321 for( i = 0; i < NUM_RX_DESC; i++ ) {
1322 DBG_PRINT( "lp->dma.rx_packet[%d]: 0x%p\n", i, lp->dma.rx_packet[i] );
1323 hcf_dma_rx_put( &lp->hcfCtx, lp->dma.rx_packet[i] );
1324 lp->dma.rx_packet[i] = NULL;
1325 DBG_PRINT( "lp->dma.rx_packet[%d]: 0x%p\n", i, lp->dma.rx_packet[i] );
1329 DBG_LEAVE( DbgInfo );
1331 } // wl_pci_dma_hcf_supply
1332 /*============================================================================*/
1334 /*******************************************************************************
1335 * wl_pci_dma_hcf_reclaim()
1336 *******************************************************************************
1340 * Return DMA-related resources from the HCF. These consist of:
1341 * - buffers and descriptors for receive purposes
1342 * - buffers and descriptors for transmit purposes
1343 * - one 'reclaim' descriptor for the transmit path, used to fulfill a
1344 * certain H25 DMA engine requirement
1345 * - one 'reclaim' descriptor for the receive path, used to fulfill a
1346 * certain H25 DMA engine requirement
1348 * This function is called at end-of-day or at re-initialization.
1352 * lp - the device's private adapter structure
1357 * errno value otherwise
1359 ******************************************************************************/
1360 void wl_pci_dma_hcf_reclaim( struct wl_private *lp )
1363 /*------------------------------------------------------------------------*/
1365 DBG_FUNC( "wl_pci_dma_hcf_reclaim" );
1366 DBG_ENTER( DbgInfo );
1368 wl_pci_dma_hcf_reclaim_rx( lp );
1369 for( i = 0; i < NUM_RX_DESC; i++ ) {
1370 DBG_PRINT( "rx_packet[%d] 0x%p\n", i, lp->dma.rx_packet[i] );
1371 // if( lp->dma.rx_packet[i] == NULL ) {
1372 // DBG_PRINT( "wl_pci_dma_hcf_reclaim: rx_packet[%d] NULL\n", i );
1376 wl_pci_dma_hcf_reclaim_tx( lp );
1377 for( i = 0; i < NUM_TX_DESC; i++ ) {
1378 DBG_PRINT( "tx_packet[%d] 0x%p\n", i, lp->dma.tx_packet[i] );
1379 // if( lp->dma.tx_packet[i] == NULL ) {
1380 // DBG_PRINT( "wl_pci_dma_hcf_reclaim: tx_packet[%d] NULL\n", i );
1384 DBG_LEAVE( DbgInfo );
1386 } // wl_pci_dma_hcf_reclaim
1387 /*============================================================================*/
1389 /*******************************************************************************
1390 * wl_pci_dma_hcf_reclaim_rx()
1391 *******************************************************************************
1395 * Reclaim Rx packets that have already been processed by the HCF.
1399 * lp - the device's private adapter structure
1404 * errno value otherwise
1406 ******************************************************************************/
1407 void wl_pci_dma_hcf_reclaim_rx( struct wl_private *lp )
1411 /*------------------------------------------------------------------------*/
1413 DBG_FUNC( "wl_pci_dma_hcf_reclaim_rx" );
1414 DBG_ENTER( DbgInfo );
1416 //if( lp->dma.status == 0 )
1418 while ( ( p = hcf_dma_rx_get( &lp->hcfCtx ) ) != NULL ) {
1419 if( p && p->buf_addr == NULL ) {
1420 /* A reclaim descriptor is being given back by the HCF. Reclaim
1421 descriptors have a NULL buf_addr */
1422 lp->dma.rx_reclaim_desc = p;
1423 DBG_PRINT( "reclaim_descriptor: 0x%p\n", p );
1426 for( i = 0; i < NUM_RX_DESC; i++ ) {
1427 if( lp->dma.rx_packet[i] == NULL ) {
1431 /* An Rx buffer descriptor is being given back by the HCF */
1432 lp->dma.rx_packet[i] = p;
1433 lp->dma.rx_rsc_ind++;
1434 DBG_PRINT( "rx_packet[%d] 0x%p\n", i, lp->dma.rx_packet[i] );
1437 DBG_LEAVE( DbgInfo );
1438 } // wl_pci_dma_hcf_reclaim_rx
1439 /*============================================================================*/
1441 /*******************************************************************************
1442 * wl_pci_dma_get_tx_packet()
1443 *******************************************************************************
1447 * Obtains a Tx descriptor from the chain to use for Tx.
1451 * lp - a pointer to the device's wl_private structure.
1455 * A pointer to the retrieved descriptor
1457 ******************************************************************************/
1458 DESC_STRCT * wl_pci_dma_get_tx_packet( struct wl_private *lp )
1461 DESC_STRCT *desc = NULL;
1462 /*------------------------------------------------------------------------*/
1464 for( i = 0; i < NUM_TX_DESC; i++ ) {
1465 if( lp->dma.tx_packet[i] ) {
1470 if( i != NUM_TX_DESC ) {
1471 desc = lp->dma.tx_packet[i];
1473 lp->dma.tx_packet[i] = NULL;
1474 lp->dma.tx_rsc_ind--;
1476 memset( desc->buf_addr, 0, HCF_DMA_TX_BUF1_SIZE );
1480 } // wl_pci_dma_get_tx_packet
1481 /*============================================================================*/
1483 /*******************************************************************************
1484 * wl_pci_dma_put_tx_packet()
1485 *******************************************************************************
1489 * Returns a Tx descriptor to the chain.
1493 * lp - a pointer to the device's wl_private structure.
1494 * desc - a pointer to the descriptor to return.
1500 ******************************************************************************/
1501 void wl_pci_dma_put_tx_packet( struct wl_private *lp, DESC_STRCT *desc )
1504 /*------------------------------------------------------------------------*/
1506 for( i = 0; i < NUM_TX_DESC; i++ ) {
1507 if( lp->dma.tx_packet[i] == NULL ) {
1512 if( i != NUM_TX_DESC ) {
1513 lp->dma.tx_packet[i] = desc;
1514 lp->dma.tx_rsc_ind++;
1516 } // wl_pci_dma_put_tx_packet
1517 /*============================================================================*/
1519 /*******************************************************************************
1520 * wl_pci_dma_hcf_reclaim_tx()
1521 *******************************************************************************
1525 * Reclaim Tx packets that have either been processed by the HCF due to a
1526 * port disable or a Tx completion.
1530 * lp - the device's private adapter structure
1535 * errno value otherwise
1537 ******************************************************************************/
1538 void wl_pci_dma_hcf_reclaim_tx( struct wl_private *lp )
1542 /*------------------------------------------------------------------------*/
1544 DBG_FUNC( "wl_pci_dma_hcf_reclaim_tx" );
1545 DBG_ENTER( DbgInfo );
1547 //if( lp->dma.status == 0 )
1549 while ( ( p = hcf_dma_tx_get( &lp->hcfCtx ) ) != NULL ) {
1551 if( p != NULL && p->buf_addr == NULL ) {
1552 /* A Reclaim descriptor is being given back by the HCF. Reclaim
1553 descriptors have a NULL buf_addr */
1554 lp->dma.tx_reclaim_desc = p;
1555 DBG_PRINT( "reclaim_descriptor: 0x%p\n", p );
1558 for( i = 0; i < NUM_TX_DESC; i++ ) {
1559 if( lp->dma.tx_packet[i] == NULL ) {
1563 /* An Rx buffer descriptor is being given back by the HCF */
1564 lp->dma.tx_packet[i] = p;
1565 lp->dma.tx_rsc_ind++;
1566 DBG_PRINT( "tx_packet[%d] 0x%p\n", i, lp->dma.tx_packet[i] );
1570 if( lp->netif_queue_on == FALSE ) {
1571 netif_wake_queue( lp->dev );
1572 WL_WDS_NETIF_WAKE_QUEUE( lp );
1573 lp->netif_queue_on = TRUE;
1575 DBG_LEAVE( DbgInfo );
1577 } // wl_pci_dma_hcf_reclaim_tx
1578 /*============================================================================*/
1579 #endif // ENABLE_DMA