staging: wlags49_h2: remove DBG_ENTER() macro
[firefly-linux-kernel-4.4.55.git] / drivers / staging / wlags49_h2 / wl_pci.c
1 /*******************************************************************************
2  * Agere Systems Inc.
3  * Wireless device driver for Linux (wlags49).
4  *
5  * Copyright (c) 1998-2003 Agere Systems Inc.
6  * All rights reserved.
7  *   http://www.agere.com
8  *
9  * Initially developed by TriplePoint, Inc.
10  *   http://www.triplepoint.com
11  *
12  *------------------------------------------------------------------------------
13  *
14  *   This file contains processing and initialization specific to PCI/miniPCI
15  *   devices.
16  *
17  *------------------------------------------------------------------------------
18  *
19  * SOFTWARE LICENSE
20  *
21  * This software is provided subject to the following terms and conditions,
22  * which you should read carefully before using the software.  Using this
23  * software indicates your acceptance of these terms and conditions.  If you do
24  * not agree with these terms and conditions, do not use the software.
25  *
26  * Copyright © 2003 Agere Systems Inc.
27  * All rights reserved.
28  *
29  * Redistribution and use in source or binary forms, with or without
30  * modifications, are permitted provided that the following conditions are met:
31  *
32  * . Redistributions of source code must retain the above copyright notice, this
33  *    list of conditions and the following Disclaimer as comments in the code as
34  *    well as in the documentation and/or other materials provided with the
35  *    distribution.
36  *
37  * . Redistributions in binary form must reproduce the above copyright notice,
38  *    this list of conditions and the following Disclaimer in the documentation
39  *    and/or other materials provided with the distribution.
40  *
41  * . Neither the name of Agere Systems Inc. nor the names of the contributors
42  *    may be used to endorse or promote products derived from this software
43  *    without specific prior written permission.
44  *
45  * Disclaimer
46  *
47  * THIS SOFTWARE IS PROVIDED \93AS IS\94 AND ANY EXPRESS OR IMPLIED WARRANTIES,
48  * INCLUDING, BUT NOT LIMITED TO, INFRINGEMENT AND THE IMPLIED WARRANTIES OF
49  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  ANY
50  * USE, MODIFICATION OR DISTRIBUTION OF THIS SOFTWARE IS SOLELY AT THE USERS OWN
51  * RISK. IN NO EVENT SHALL AGERE SYSTEMS INC. OR CONTRIBUTORS BE LIABLE FOR ANY
52  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
53  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
54  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
55  * ON ANY THEORY OF LIABILITY, INCLUDING, BUT NOT LIMITED TO, CONTRACT, STRICT
56  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
57  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
58  * DAMAGE.
59  *
60  ******************************************************************************/
61
62 /*******************************************************************************
63  * include files
64  ******************************************************************************/
65 #include <wireless/wl_version.h>
66
67 #include <linux/module.h>
68 #include <linux/kernel.h>
69 #include <linux/errno.h>
70 #include <linux/pci.h>
71 #include <linux/sched.h>
72 #include <linux/ptrace.h>
73 #include <linux/ctype.h>
74 #include <linux/string.h>
75 //#include <linux/timer.h>
76 #include <linux/interrupt.h>
77 #include <linux/in.h>
78 #include <linux/delay.h>
79 #include <asm/io.h>
80 #include <asm/irq.h>
81 #include <asm/bitops.h>
82 #include <asm/uaccess.h>
83
84 #include <linux/ethtool.h>
85 #include <linux/netdevice.h>
86 #include <linux/etherdevice.h>
87 #include <linux/skbuff.h>
88 #include <linux/if_arp.h>
89 #include <linux/ioport.h>
90
91 #include <hcf/debug.h>
92
93 #include <hcf.h>
94 #include <dhf.h>
95 #include <hcfdef.h>
96
97 #include <wireless/wl_if.h>
98 #include <wireless/wl_internal.h>
99 #include <wireless/wl_util.h>
100 #include <wireless/wl_main.h>
101 #include <wireless/wl_netdev.h>
102 #include <wireless/wl_pci.h>
103
104
105 /*******************************************************************************
106  * global variables
107  ******************************************************************************/
108 #if DBG
109 extern dbg_info_t *DbgInfo;
110 #endif  // DBG
111
112 /* define the PCI device Table Cardname and id tables */
113 static struct pci_device_id wl_pci_tbl[] = {
114         { PCI_DEVICE(PCI_VENDOR_ID_WL_LKM, PCI_DEVICE_ID_WL_LKM_0), },
115         { PCI_DEVICE(PCI_VENDOR_ID_WL_LKM, PCI_DEVICE_ID_WL_LKM_1), },
116         { PCI_DEVICE(PCI_VENDOR_ID_WL_LKM, PCI_DEVICE_ID_WL_LKM_2), },
117
118         { }                     /* Terminating entry */
119 };
120
121 MODULE_DEVICE_TABLE(pci, wl_pci_tbl);
122
123 /*******************************************************************************
124  * function prototypes
125  ******************************************************************************/
126 int wl_pci_probe( struct pci_dev *pdev,
127                                 const struct pci_device_id *ent );
128 void wl_pci_remove(struct pci_dev *pdev);
129 int wl_pci_setup( struct pci_dev *pdev );
130 void wl_pci_enable_cardbus_interrupts( struct pci_dev *pdev );
131
132 #ifdef ENABLE_DMA
133 int wl_pci_dma_alloc( struct pci_dev *pdev, struct wl_private *lp );
134 int wl_pci_dma_free( struct pci_dev *pdev, struct wl_private *lp );
135 int wl_pci_dma_alloc_tx_packet( struct pci_dev *pdev, struct wl_private *lp,
136                                 DESC_STRCT **desc );
137 int wl_pci_dma_free_tx_packet( struct pci_dev *pdev, struct wl_private *lp,
138                                 DESC_STRCT **desc );
139 int wl_pci_dma_alloc_rx_packet( struct pci_dev *pdev, struct wl_private *lp,
140                                 DESC_STRCT **desc );
141 int wl_pci_dma_free_rx_packet( struct pci_dev *pdev, struct wl_private *lp,
142                                 DESC_STRCT **desc );
143 int wl_pci_dma_alloc_desc_and_buf( struct pci_dev *pdev, struct wl_private *lp,
144                                    DESC_STRCT **desc, int size );
145 int wl_pci_dma_free_desc_and_buf( struct pci_dev *pdev, struct wl_private *lp,
146                                    DESC_STRCT **desc );
147 int wl_pci_dma_alloc_desc( struct pci_dev *pdev, struct wl_private *lp,
148                            DESC_STRCT **desc );
149 int wl_pci_dma_free_desc( struct pci_dev *pdev, struct wl_private *lp,
150                            DESC_STRCT **desc );
151 int wl_pci_dma_alloc_buf( struct pci_dev *pdev, struct wl_private *lp,
152                           DESC_STRCT *desc, int size );
153 int wl_pci_dma_free_buf( struct pci_dev *pdev, struct wl_private *lp,
154                           DESC_STRCT *desc );
155
156 void wl_pci_dma_hcf_reclaim_rx( struct wl_private *lp );
157 #endif  // ENABLE_DMA
158
159 /*******************************************************************************
160  * PCI module function registration
161  ******************************************************************************/
162 static struct pci_driver wl_driver = {
163         .name     = MODULE_NAME,
164         .id_table = wl_pci_tbl,
165         .probe    = wl_pci_probe,
166         .remove   = wl_pci_remove,
167         .suspend  = NULL,
168         .resume   = NULL
169 };
170
171 /*******************************************************************************
172  *      wl_adapter_init_module()
173  *******************************************************************************
174  *
175  *  DESCRIPTION:
176  *
177  *      Called by init_module() to perform PCI-specific driver initialization.
178  *
179  *  PARAMETERS:
180  *
181  *      N/A
182  *
183  *  RETURNS:
184  *
185  *      0
186  *
187  ******************************************************************************/
188 int wl_adapter_init_module( void )
189 {
190     int result;
191
192     DBG_TRACE( DbgInfo, "wl_adapter_init_module() -- PCI\n" );
193
194     result = pci_register_driver( &wl_driver ); //;?replace with pci_module_init, Rubini pg 490
195         //;? why not do something with the result
196
197     DBG_LEAVE( DbgInfo );
198     return 0;
199 } // wl_adapter_init_module
200 /*============================================================================*/
201
202 /*******************************************************************************
203  *      wl_adapter_cleanup_module()
204  *******************************************************************************
205  *
206  *  DESCRIPTION:
207  *
208  *      Called by cleanup_module() to perform PCI-specific driver cleanup.
209  *
210  *  PARAMETERS:
211  *
212  *      N/A
213  *
214  *  RETURNS:
215  *
216  *      N/A
217  *
218  ******************************************************************************/
219 void wl_adapter_cleanup_module( void )
220 {
221         //;?how come wl_adapter_cleanup_module is located in a seemingly pci specific module
222     DBG_TRACE( DbgInfo, "wl_adapter_cleanup_module() -- PCI\n" );
223
224     pci_unregister_driver( &wl_driver );
225
226     DBG_LEAVE( DbgInfo );
227     return;
228 } // wl_adapter_cleanup_module
229 /*============================================================================*/
230
231 /*******************************************************************************
232  *      wl_adapter_insert()
233  *******************************************************************************
234  *
235  *  DESCRIPTION:
236  *
237  *      Called by wl_pci_probe() to continue the process of device insertion.
238  *
239  *  PARAMETERS:
240  *
241  *      dev - a pointer to the device's net_device structure
242  *
243  *  RETURNS:
244  *
245  *      TRUE or FALSE
246  *
247  ******************************************************************************/
248 int wl_adapter_insert( struct net_device *dev )
249 {
250     int result = FALSE;
251
252     DBG_TRACE( DbgInfo, "wl_adapter_insert() -- PCI\n" );
253
254     if( dev == NULL ) {
255         DBG_ERROR( DbgInfo, "net_device pointer is NULL!!!\n" );
256     } else if( dev->priv == NULL ) {
257         DBG_ERROR( DbgInfo, "wl_private pointer is NULL!!!\n" );
258     } else if( wl_insert( dev ) ) { /* Perform remaining device initialization */
259                 result = TRUE;
260         } else {
261         DBG_TRACE( DbgInfo, "wl_insert() FAILED\n" );
262     }
263     DBG_LEAVE( DbgInfo );
264     return result;
265 } // wl_adapter_insert
266 /*============================================================================*/
267
268 /*******************************************************************************
269  *      wl_adapter_open()
270  *******************************************************************************
271  *
272  *  DESCRIPTION:
273  *
274  *      Open the device.
275  *
276  *  PARAMETERS:
277  *
278  *      dev - a pointer to the device's net_device structure
279  *
280  *  RETURNS:
281  *
282  *      an HCF status code
283  *
284  ******************************************************************************/
285 int wl_adapter_open( struct net_device *dev )
286 {
287     int         result = 0;
288     int         hcf_status = HCF_SUCCESS;
289
290     DBG_TRACE( DbgInfo, "wl_adapter_open() -- PCI\n" );
291
292     hcf_status = wl_open( dev );
293
294     if( hcf_status != HCF_SUCCESS ) {
295         result = -ENODEV;
296     }
297
298     DBG_LEAVE( DbgInfo );
299     return result;
300 } // wl_adapter_open
301 /*============================================================================*/
302
303 /*******************************************************************************
304  *      wl_adapter_close()
305  *******************************************************************************
306  *
307  *  DESCRIPTION:
308  *
309  *      Close the device
310  *
311  *  PARAMETERS:
312  *
313  *      dev - a pointer to the device's net_device structure
314  *
315  *  RETURNS:
316  *
317  *      0
318  *
319  ******************************************************************************/
320 int wl_adapter_close( struct net_device *dev )
321 {
322     DBG_TRACE( DbgInfo, "wl_adapter_close() -- PCI\n" );
323     DBG_TRACE( DbgInfo, "%s: Shutting down adapter.\n", dev->name );
324
325     wl_close( dev );
326
327     DBG_LEAVE( DbgInfo );
328     return 0;
329 } // wl_adapter_close
330 /*============================================================================*/
331
332 /*******************************************************************************
333  *      wl_adapter_is_open()
334  *******************************************************************************
335  *
336  *  DESCRIPTION:
337  *
338  *      Check whether this device is open. Returns
339  *
340  *  PARAMETERS:
341  *
342  *      dev - a pointer to the device's net_device structure
343  *
344  *  RETURNS:
345  *
346  *      nonzero if device is open.
347  *
348  ******************************************************************************/
349 int wl_adapter_is_open( struct net_device *dev )
350 {
351     /* This function is used in PCMCIA to check the status of the 'open' field
352        in the dev_link_t structure associated with a network device. There
353        doesn't seem to be an analog to this for PCI, and checking the status
354        contained in the net_device structure doesn't have the same effect.
355        For now, return TRUE, but find out if this is necessary for PCI. */
356
357     return TRUE;
358 } // wl_adapter_is_open
359 /*============================================================================*/
360
361 /*******************************************************************************
362  *      wl_pci_probe()
363  *******************************************************************************
364  *
365  *  DESCRIPTION:
366  *
367  *      Registered in the pci_driver structure, this function is called when the
368  *  PCI subsystem finds a new PCI device which matches the information contained
369  *  in the pci_device_id table.
370  *
371  *  PARAMETERS:
372  *
373  *      pdev    - a pointer to the device's pci_dev structure
374  *      ent     - this device's entry in the pci_device_id table
375  *
376  *  RETURNS:
377  *
378  *      0 on success
379  *      errno value otherwise
380  *
381  ******************************************************************************/
382 int wl_pci_probe( struct pci_dev *pdev,
383                                 const struct pci_device_id *ent )
384 {
385     int result;
386
387         DBG_PRINT( "%s\n", VERSION_INFO );
388
389     result = wl_pci_setup( pdev );
390
391     DBG_LEAVE( DbgInfo );
392
393     return result;
394 } // wl_pci_probe
395 /*============================================================================*/
396
397 /*******************************************************************************
398  *      wl_pci_remove()
399  *******************************************************************************
400  *
401  *  DESCRIPTION:
402  *
403  *      Registered in the pci_driver structure, this function is called when the
404  *  PCI subsystem detects that a PCI device which matches the information
405  *  contained in the pci_device_id table has been removed.
406  *
407  *  PARAMETERS:
408  *
409  *      pdev - a pointer to the device's pci_dev structure
410  *
411  *  RETURNS:
412  *
413  *      N/A
414  *
415  ******************************************************************************/
416 void wl_pci_remove(struct pci_dev *pdev)
417 {
418     struct net_device       *dev = NULL;
419
420     /* Make sure the pci_dev pointer passed in is valid */
421     if( pdev == NULL ) {
422         DBG_ERROR( DbgInfo, "PCI subsys passed in an invalid pci_dev pointer\n" );
423         return;
424     }
425
426     dev = pci_get_drvdata( pdev );
427     if( dev == NULL ) {
428         DBG_ERROR( DbgInfo, "Could not retrieve net_device structure\n" );
429         return;
430     }
431
432     /* Perform device cleanup */
433     wl_remove( dev );
434     free_irq( dev->irq, dev );
435
436 #ifdef ENABLE_DMA
437     wl_pci_dma_free( pdev, dev->priv );
438 #endif
439
440     wl_device_dealloc( dev );
441
442     DBG_LEAVE( DbgInfo );
443     return;
444 } // wl_pci_remove
445 /*============================================================================*/
446
447 /*******************************************************************************
448  *      wl_pci_setup()
449  *******************************************************************************
450  *
451  *  DESCRIPTION:
452  *
453  *      Called by wl_pci_probe() to begin a device's initialization process.
454  *
455  *  PARAMETERS:
456  *
457  *      pdev - a pointer to the device's pci_dev structure
458  *
459  *  RETURNS:
460  *
461  *      0 on success
462  *      errno value otherwise
463  *
464  ******************************************************************************/
465 int wl_pci_setup( struct pci_dev *pdev )
466 {
467     int                 result = 0;
468     struct net_device   *dev = NULL;
469     struct wl_private   *lp = NULL;
470
471     /* Make sure the pci_dev pointer passed in is valid */
472     if( pdev == NULL ) {
473         DBG_ERROR( DbgInfo, "PCI subsys passed in an invalid pci_dev pointer\n" );
474         return -ENODEV;
475     }
476
477     result = pci_enable_device( pdev );
478     if( result != 0 ) {
479         DBG_ERROR( DbgInfo, "pci_enable_device() failed\n" );
480         DBG_LEAVE( DbgInfo );
481         return result;
482     }
483
484     /* We found our device! Let's register it with the system */
485     DBG_TRACE( DbgInfo, "Found our device, now registering\n" );
486     dev = wl_device_alloc( );
487     if( dev == NULL ) {
488         DBG_ERROR( DbgInfo, "Could not register device!!!\n" );
489         DBG_LEAVE( DbgInfo );
490         return -ENOMEM;
491     }
492
493     /* Make sure that space was allocated for our private adapter struct */
494     if( dev->priv == NULL ) {
495         DBG_ERROR( DbgInfo, "Private adapter struct was not allocated!!!\n" );
496         wl_device_dealloc(dev);
497         DBG_LEAVE( DbgInfo );
498         return -ENOMEM;
499     }
500
501 #ifdef ENABLE_DMA
502     /* Allocate DMA Descriptors */
503     if( wl_pci_dma_alloc( pdev, dev->priv ) < 0 ) {
504         DBG_ERROR( DbgInfo, "Could not allocate DMA descriptor memory!!!\n" );
505         wl_device_dealloc(dev);
506         DBG_LEAVE( DbgInfo );
507         return -ENOMEM;
508     }
509 #endif
510
511     /* Register our private adapter structure with PCI */
512     pci_set_drvdata( pdev, dev );
513
514     /* Fill out bus specific information in the net_device struct */
515     dev->irq = pdev->irq;
516     SET_MODULE_OWNER( dev );
517
518     DBG_TRACE( DbgInfo, "Device Base Address: %#03lx\n", pdev->resource[0].start );
519         dev->base_addr = pdev->resource[0].start;
520
521     /* Initialize our device here */
522     if( !wl_adapter_insert( dev )) {
523         DBG_ERROR( DbgInfo, "wl_adapter_insert() FAILED!!!\n" );
524         wl_device_dealloc( dev );
525         DBG_LEAVE( DbgInfo );
526         return -EINVAL;
527     }
528
529     /* Register our ISR */
530     DBG_TRACE( DbgInfo, "Registering ISR...\n" );
531
532     result = request_irq(dev->irq, wl_isr, SA_SHIRQ, dev->name, dev);
533     if( result ) {
534         DBG_WARNING( DbgInfo, "Could not register ISR!!!\n" );
535         wl_remove(dev);
536         wl_device_dealloc(dev);
537         DBG_LEAVE( DbgInfo );
538         return result;
539         }
540
541     /* Make sure interrupts are enabled properly for CardBus */
542     lp = dev->priv;
543
544     if( lp->hcfCtx.IFB_BusType == CFG_NIC_BUS_TYPE_CARDBUS ||
545             lp->hcfCtx.IFB_BusType == CFG_NIC_BUS_TYPE_PCI              ) {
546         DBG_TRACE( DbgInfo, "This is a PCI/CardBus card, enable interrupts\n" );
547         wl_pci_enable_cardbus_interrupts( pdev );
548     }
549
550     /* Enable bus mastering */
551     pci_set_master( pdev );
552
553     DBG_LEAVE( DbgInfo );
554     return 0;
555 } // wl_pci_setup
556 /*============================================================================*/
557
558 /*******************************************************************************
559  *      wl_pci_enable_cardbus_interrupts()
560  *******************************************************************************
561  *
562  *  DESCRIPTION:
563  *
564  *      Called by wl_pci_setup() to enable interrupts on a CardBus device. This
565  *  is done by writing bit 15 to the function event mask register. This
566  *  CardBus-specific register is located in BAR2 (counting from BAR0), in memory
567  *  space at byte offset 1f4 (7f4 for WARP).
568  *
569  *  PARAMETERS:
570  *
571  *      pdev - a pointer to the device's pci_dev structure
572  *
573  *  RETURNS:
574  *
575  *      N/A
576  *
577  ******************************************************************************/
578 void wl_pci_enable_cardbus_interrupts( struct pci_dev *pdev )
579 {
580     u32                 bar2_reg;
581     u32                 mem_addr_bus;
582     u32                 func_evt_mask_reg;
583     void                *mem_addr_kern = NULL;
584
585     /* Initialize to known bad values */
586     bar2_reg = 0xdeadbeef;
587     mem_addr_bus = 0xdeadbeef;
588
589     /* Read the BAR2 register; this register contains the base address of the
590        memory region where the function event mask register lives */
591     pci_read_config_dword( pdev, PCI_BASE_ADDRESS_2, &bar2_reg );
592     mem_addr_bus = bar2_reg & PCI_BASE_ADDRESS_MEM_MASK;
593
594     /* Once the base address is obtained, remap the memory region to kernel
595        space so we can retrieve the register */
596     mem_addr_kern = ioremap( mem_addr_bus, 0x200 );
597
598 #ifdef HERMES25
599 #define REG_OFFSET  0x07F4
600 #else
601 #define REG_OFFSET  0x01F4
602 #endif // HERMES25
603
604 #define BIT15       0x8000
605
606     /* Retrieve the functional event mask register, enable interrupts by
607        setting Bit 15, and write back the value */
608     func_evt_mask_reg = *(u32 *)( mem_addr_kern + REG_OFFSET );
609     func_evt_mask_reg |= BIT15;
610     *(u32 *)( mem_addr_kern + REG_OFFSET ) = func_evt_mask_reg;
611
612     /* Once complete, unmap the region and exit */
613     iounmap( mem_addr_kern );
614
615     DBG_LEAVE( DbgInfo );
616     return;
617 } // wl_pci_enable_cardbus_interrupts
618 /*============================================================================*/
619
620 #ifdef ENABLE_DMA
621 /*******************************************************************************
622  *      wl_pci_dma_alloc()
623  *******************************************************************************
624  *
625  *  DESCRIPTION:
626  *
627  *      Allocates all resources needed for PCI/CardBus DMA operation
628  *
629  *  PARAMETERS:
630  *
631  *      pdev - a pointer to the device's pci_dev structure
632  *      lp  - the device's private adapter structure
633  *
634  *  RETURNS:
635  *
636  *      0 on success
637  *      errno value otherwise
638  *
639  ******************************************************************************/
640 int wl_pci_dma_alloc( struct pci_dev *pdev, struct wl_private *lp )
641 {
642     int i;
643     int status = 0;
644
645 //     lp->dma.tx_rsc_ind = lp->dma.rx_rsc_ind = 0;
646 //
647 //     /* Alloc for the Tx chain and its reclaim descriptor */
648 //     for( i = 0; i < NUM_TX_DESC; i++ ) {
649 //         status = wl_pci_dma_alloc_tx_packet( pdev, lp, &lp->dma.tx_packet[i] );
650 //         if( status == 0 ) {
651 //             DBG_PRINT( "lp->dma.tx_packet[%d] :                 0x%p\n", i, lp->dma.tx_packet[i] );
652 //             DBG_PRINT( "lp->dma.tx_packet[%d]->next_desc_addr : 0x%p\n", i, lp->dma.tx_packet[i]->next_desc_addr );
653 //             lp->dma.tx_rsc_ind++;
654 //         } else {
655 //             DBG_ERROR( DbgInfo, "Could not alloc DMA Tx Packet\n" );
656 //             break;
657 //         }
658 //     }
659 //     if( status == 0 ) {
660 //         status = wl_pci_dma_alloc_desc( pdev, lp, &lp->dma.tx_reclaim_desc );
661 //         DBG_PRINT( "lp->dma.tx_reclaim_desc: 0x%p\n", lp->dma.tx_reclaim_desc );
662 //     }
663 //     /* Alloc for the Rx chain and its reclaim descriptor */
664 //     if( status == 0 ) {
665 //         for( i = 0; i < NUM_RX_DESC; i++ ) {
666 //             status = wl_pci_dma_alloc_rx_packet( pdev, lp, &lp->dma.rx_packet[i] );
667 //             if( status == 0 ) {
668 //                 DBG_PRINT( "lp->dma.rx_packet[%d]                 : 0x%p\n", i, lp->dma.rx_packet[i] );
669 //                 DBG_PRINT( "lp->dma.rx_packet[%d]->next_desc_addr : 0x%p\n", i, lp->dma.rx_packet[i]->next_desc_addr );
670 //                 lp->dma.rx_rsc_ind++;
671 //             } else {
672 //                 DBG_ERROR( DbgInfo, "Could not alloc DMA Rx Packet\n" );
673 //                 break;
674 //             }
675 //         }
676 //     }
677 //     if( status == 0 ) {
678 //         status = wl_pci_dma_alloc_desc( pdev, lp, &lp->dma.rx_reclaim_desc );
679 //         DBG_PRINT( "lp->dma.rx_reclaim_desc: 0x%p\n", lp->dma.rx_reclaim_desc );
680 //     }
681 //     /* Store status, as host should not call HCF functions if this fails */
682 //     lp->dma.status = status;  //;?all useages of dma.status have been commented out
683 //     DBG_LEAVE( DbgInfo );
684     return status;
685 } // wl_pci_dma_alloc
686 /*============================================================================*/
687
688 /*******************************************************************************
689  *      wl_pci_dma_free()
690  *******************************************************************************
691  *
692  *  DESCRIPTION:
693  *
694  *      Deallocated all resources needed for PCI/CardBus DMA operation
695  *
696  *  PARAMETERS:
697  *
698  *      pdev - a pointer to the device's pci_dev structure
699  *      lp  - the device's private adapter structure
700  *
701  *  RETURNS:
702  *
703  *      0 on success
704  *      errno value otherwise
705  *
706  ******************************************************************************/
707 int wl_pci_dma_free( struct pci_dev *pdev, struct wl_private *lp )
708 {
709     int i;
710     int status = 0;
711
712     /* Reclaim all Rx packets that were handed over to the HCF */
713     /* Do I need to do this? Before this free is called, I've already disabled
714        the port which will call wl_pci_dma_hcf_reclaim */
715     //if( lp->dma.status == 0 )
716     //{
717     //    wl_pci_dma_hcf_reclaim( lp );
718     //}
719
720     /* Free everything needed for DMA Rx */
721     for( i = 0; i < NUM_RX_DESC; i++ ) {
722         if( lp->dma.rx_packet[i] ) {
723             status = wl_pci_dma_free_rx_packet( pdev, lp, &lp->dma.rx_packet[i] );
724             if( status != 0 ) {
725                 DBG_WARNING( DbgInfo, "Problem freeing Rx packet\n" );
726             }
727         }
728     }
729     lp->dma.rx_rsc_ind = 0;
730
731     if( lp->dma.rx_reclaim_desc ) {
732         status = wl_pci_dma_free_desc( pdev, lp, &lp->dma.rx_reclaim_desc );
733         if( status != 0 ) {
734             DBG_WARNING( DbgInfo, "Problem freeing Rx reclaim descriptor\n" );
735         }
736     }
737
738     /* Free everything needed for DMA Tx */
739     for( i = 0; i < NUM_TX_DESC; i++ ) {
740         if( lp->dma.tx_packet[i] ) {
741             status = wl_pci_dma_free_tx_packet( pdev, lp, &lp->dma.tx_packet[i] );
742             if( status != 0 ) {
743                 DBG_WARNING( DbgInfo, "Problem freeing Tx packet\n" );
744             }
745         }
746     }
747     lp->dma.tx_rsc_ind = 0;
748
749     if( lp->dma.tx_reclaim_desc ) {
750         status = wl_pci_dma_free_desc( pdev, lp, &lp->dma.tx_reclaim_desc );
751         if( status != 0 ) {
752             DBG_WARNING( DbgInfo, "Problem freeing Tx reclaim descriptor\n" );
753         }
754     }
755
756     DBG_LEAVE( DbgInfo );
757     return status;
758 } // wl_pci_dma_free
759
760 /*============================================================================*/
761
762 /*******************************************************************************
763  *      wl_pci_dma_alloc_tx_packet()
764  *******************************************************************************
765  *
766  *  DESCRIPTION:
767  *
768  *      Allocates a single Tx packet, consisting of several descriptors and
769  *      buffers. Data to transmit is first copied into the 'payload' buffer
770  *      before being transmitted.
771  *
772  *  PARAMETERS:
773  *
774  *      pdev    - a pointer to the device's pci_dev structure
775  *      lp      - the device's private adapter structure
776  *      desc    - a pointer which will reference the descriptor to be alloc'd.
777  *
778  *  RETURNS:
779  *
780  *      0 on success
781  *      errno value otherwise
782  *
783  ******************************************************************************/
784 int wl_pci_dma_alloc_tx_packet( struct pci_dev *pdev, struct wl_private *lp,
785                                 DESC_STRCT **desc )
786 {
787 //     int status = 0;
788 //     /*------------------------------------------------------------------------*/
789 //
790 //     if( desc == NULL ) {
791 //         status = -EFAULT;
792 //     }
793 //     if( status == 0 ) {
794 //         status = wl_pci_dma_alloc_desc_and_buf( pdev, lp, desc,
795 //                                                 HCF_DMA_TX_BUF1_SIZE );
796 //
797 //         if( status == 0 ) {
798 //             status = wl_pci_dma_alloc_desc_and_buf( pdev, lp,
799 //                                                     &( (*desc)->next_desc_addr ),
800 //                                                     HCF_MAX_PACKET_SIZE );
801 //         }
802 //     }
803 //     if( status == 0 ) {
804 //         (*desc)->next_desc_phys_addr = (*desc)->next_desc_addr->desc_phys_addr;
805 //     }
806 //     return status;
807 } // wl_pci_dma_alloc_tx_packet
808 /*============================================================================*/
809
810 /*******************************************************************************
811  *      wl_pci_dma_free_tx_packet()
812  *******************************************************************************
813  *
814  *  DESCRIPTION:
815  *
816  *      Frees a single Tx packet, described in the corresponding alloc function.
817  *
818  *  PARAMETERS:
819  *
820  *      pdev    - a pointer to the device's pci_dev structure
821  *      lp      - the device's private adapter structure
822  *      desc    - a pointer which will reference the descriptor to be alloc'd.
823  *
824  *  RETURNS:
825  *
826  *      0 on success
827  *      errno value otherwise
828  *
829  ******************************************************************************/
830 int wl_pci_dma_free_tx_packet( struct pci_dev *pdev, struct wl_private *lp,
831                                 DESC_STRCT **desc )
832 {
833     int status = 0;
834     /*------------------------------------------------------------------------*/
835
836     if( *desc == NULL ) {
837         DBG_PRINT( "Null descriptor\n" );
838         status = -EFAULT;
839     }
840         //;?the "limited" NDIS strategy, assuming a frame consists ALWAYS out of 2
841         //descriptors, make this robust
842     if( status == 0 && (*desc)->next_desc_addr ) {
843         status = wl_pci_dma_free_desc_and_buf( pdev, lp, &(*desc)->next_desc_addr );
844     }
845     if( status == 0 ) {
846         status = wl_pci_dma_free_desc_and_buf( pdev, lp, desc );
847     }
848     return status;
849 } // wl_pci_dma_free_tx_packet
850 /*============================================================================*/
851
852 /*******************************************************************************
853  *      wl_pci_dma_alloc_rx_packet()
854  *******************************************************************************
855  *
856  *  DESCRIPTION:
857  *
858  *      Allocates a single Rx packet, consisting of two descriptors and one
859  *      contiguous buffer. The buffer starts with the hermes-specific header.
860  *      One descriptor points at the start, the other at offset 0x3a of the
861  *      buffer.
862  *
863  *  PARAMETERS:
864  *
865  *      pdev    - a pointer to the device's pci_dev structure
866  *      lp      - the device's private adapter structure
867  *      desc    - a pointer which will reference the descriptor to be alloc'd.
868  *
869  *  RETURNS:
870  *
871  *      0 on success
872  *      errno value otherwise
873  *
874  ******************************************************************************/
875 int wl_pci_dma_alloc_rx_packet( struct pci_dev *pdev, struct wl_private *lp,
876                                 DESC_STRCT **desc )
877 {
878     int         status = 0;
879     DESC_STRCT  *p;
880     /*------------------------------------------------------------------------*/
881
882 //     if( desc == NULL ) {
883 //         status = -EFAULT;
884 //     }
885 //      //;?the "limited" NDIS strategy, assuming a frame consists ALWAYS out of 2
886 //      //descriptors, make this robust
887 //     if( status == 0 ) {
888 //         status = wl_pci_dma_alloc_desc( pdev, lp, desc );
889 //      }
890 //     if( status == 0 ) {
891 //         status = wl_pci_dma_alloc_buf( pdev, lp, *desc, HCF_MAX_PACKET_SIZE );
892 //     }
893 //     if( status == 0 ) {
894 //         status = wl_pci_dma_alloc_desc( pdev, lp, &p );
895 //     }
896 //     if( status == 0 ) {
897 //         /* Size of 1st descriptor becomes 0x3a bytes */
898 //         SET_BUF_SIZE( *desc, HCF_DMA_RX_BUF1_SIZE );
899 //
900 //         /* Make 2nd descriptor point at offset 0x3a of the buffer */
901 //         SET_BUF_SIZE( p, ( HCF_MAX_PACKET_SIZE - HCF_DMA_RX_BUF1_SIZE ));
902 //         p->buf_addr       = (*desc)->buf_addr + HCF_DMA_RX_BUF1_SIZE;
903 //         p->buf_phys_addr  = (*desc)->buf_phys_addr + HCF_DMA_RX_BUF1_SIZE;
904 //         p->next_desc_addr = NULL;
905 //
906 //         /* Chain 2nd descriptor to 1st descriptor */
907 //         (*desc)->next_desc_addr      = p;
908 //         (*desc)->next_desc_phys_addr = p->desc_phys_addr;
909 //     }
910
911     return status;
912 } // wl_pci_dma_alloc_rx_packet
913 /*============================================================================*/
914
915 /*******************************************************************************
916  *      wl_pci_dma_free_rx_packet()
917  *******************************************************************************
918  *
919  *  DESCRIPTION:
920  *
921  *      Frees a single Rx packet, described in the corresponding alloc function.
922  *
923  *  PARAMETERS:
924  *
925  *      pdev    - a pointer to the device's pci_dev structure
926  *      lp      - the device's private adapter structure
927  *      desc    - a pointer which will reference the descriptor to be alloc'd.
928  *
929  *  RETURNS:
930  *
931  *      0 on success
932  *      errno value otherwise
933  *
934  ******************************************************************************/
935 int wl_pci_dma_free_rx_packet( struct pci_dev *pdev, struct wl_private *lp,
936                                 DESC_STRCT **desc )
937 {
938     int status = 0;
939     DESC_STRCT *p;
940     /*------------------------------------------------------------------------*/
941
942     if( *desc == NULL ) {
943         status = -EFAULT;
944     }
945     if( status == 0 ) {
946         p = (*desc)->next_desc_addr;
947
948         /* Free the 2nd descriptor */
949         if( p != NULL ) {
950             p->buf_addr      = NULL;
951             p->buf_phys_addr = 0;
952
953             status = wl_pci_dma_free_desc( pdev, lp, &p );
954         }
955     }
956
957     /* Free the buffer and 1st descriptor */
958     if( status == 0 ) {
959         SET_BUF_SIZE( *desc, HCF_MAX_PACKET_SIZE );
960         status = wl_pci_dma_free_desc_and_buf( pdev, lp, desc );
961     }
962     return status;
963 } // wl_pci_dma_free_rx_packet
964 /*============================================================================*/
965
966 /*******************************************************************************
967  *      wl_pci_dma_alloc_desc_and_buf()
968  *******************************************************************************
969  *
970  *  DESCRIPTION:
971  *
972  *      Allocates a DMA descriptor and buffer, and associates them with one
973  *      another.
974  *
975  *  PARAMETERS:
976  *
977  *      pdev  - a pointer to the device's pci_dev structure
978  *      lp    - the device's private adapter structure
979  *      desc  - a pointer which will reference the descriptor to be alloc'd
980  *
981  *  RETURNS:
982  *
983  *      0 on success
984  *      errno value otherwise
985  *
986  ******************************************************************************/
987 int wl_pci_dma_alloc_desc_and_buf( struct pci_dev *pdev, struct wl_private *lp,
988                                    DESC_STRCT **desc, int size )
989 {
990     int status = 0;
991     /*------------------------------------------------------------------------*/
992
993 //     if( desc == NULL ) {
994 //         status = -EFAULT;
995 //     }
996 //     if( status == 0 ) {
997 //         status = wl_pci_dma_alloc_desc( pdev, lp, desc );
998 //
999 //         if( status == 0 ) {
1000 //             status = wl_pci_dma_alloc_buf( pdev, lp, *desc, size );
1001 //         }
1002 //     }
1003     return status;
1004 } // wl_pci_dma_alloc_desc_and_buf
1005 /*============================================================================*/
1006
1007 /*******************************************************************************
1008  *      wl_pci_dma_free_desc_and_buf()
1009  *******************************************************************************
1010  *
1011  *  DESCRIPTION:
1012  *
1013  *      Frees a DMA descriptor and associated buffer.
1014  *
1015  *  PARAMETERS:
1016  *
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
1020  *
1021  *  RETURNS:
1022  *
1023  *      0 on success
1024  *      errno value otherwise
1025  *
1026  ******************************************************************************/
1027 int wl_pci_dma_free_desc_and_buf( struct pci_dev *pdev, struct wl_private *lp,
1028                                    DESC_STRCT **desc )
1029 {
1030     int status = 0;
1031     /*------------------------------------------------------------------------*/
1032
1033     if( desc == NULL ) {
1034         status = -EFAULT;
1035     }
1036     if( status == 0 && *desc == NULL ) {
1037         status = -EFAULT;
1038     }
1039     if( status == 0 ) {
1040         status = wl_pci_dma_free_buf( pdev, lp, *desc );
1041
1042         if( status == 0 ) {
1043             status = wl_pci_dma_free_desc( pdev, lp, desc );
1044         }
1045     }
1046     return status;
1047 } // wl_pci_dma_free_desc_and_buf
1048 /*============================================================================*/
1049
1050 /*******************************************************************************
1051  *      wl_pci_dma_alloc_desc()
1052  *******************************************************************************
1053  *
1054  *  DESCRIPTION:
1055  *
1056  *      Allocates one DMA descriptor in cache coherent memory.
1057  *
1058  *  PARAMETERS:
1059  *
1060  *      pdev - a pointer to the device's pci_dev structure
1061  *      lp  - the device's private adapter structure
1062  *
1063  *  RETURNS:
1064  *
1065  *      0 on success
1066  *      errno value otherwise
1067  *
1068  ******************************************************************************/
1069 int wl_pci_dma_alloc_desc( struct pci_dev *pdev, struct wl_private *lp,
1070                            DESC_STRCT **desc )
1071 {
1072 //     int         status = 0;
1073 //     dma_addr_t  pa;
1074 //
1075 //     if( desc == NULL ) {
1076 //         status = -EFAULT;
1077 //     }
1078 //     if( status == 0 ) {
1079 //         *desc = pci_alloc_consistent( pdev, sizeof( DESC_STRCT ), &pa );
1080 //     }
1081 //     if( *desc == NULL ) {
1082 //         DBG_ERROR( DbgInfo, "pci_alloc_consistent() failed\n" );
1083 //         status = -ENOMEM;
1084 //     } else {
1085 //         memset( *desc, 0, sizeof( DESC_STRCT ));
1086 //         (*desc)->desc_phys_addr = cpu_to_le32( pa );
1087 //     }
1088 //     DBG_LEAVE( DbgInfo );
1089 //     return status;
1090 } // wl_pci_dma_alloc_desc
1091 /*============================================================================*/
1092
1093 /*******************************************************************************
1094  *      wl_pci_dma_free_desc()
1095  *******************************************************************************
1096  *
1097  *  DESCRIPTION:
1098  *
1099  *      Frees one DMA descriptor in cache coherent memory.
1100  *
1101  *  PARAMETERS:
1102  *
1103  *      pdev - a pointer to the device's pci_dev structure
1104  *      lp  - the device's private adapter structure
1105  *
1106  *  RETURNS:
1107  *
1108  *      0 on success
1109  *      errno value otherwise
1110  *
1111  ******************************************************************************/
1112 int wl_pci_dma_free_desc( struct pci_dev *pdev, struct wl_private *lp,
1113                            DESC_STRCT **desc )
1114 {
1115     int         status = 0;
1116     /*------------------------------------------------------------------------*/
1117
1118     if( *desc == NULL ) {
1119         status = -EFAULT;
1120     }
1121     if( status == 0 ) {
1122         pci_free_consistent( pdev, sizeof( DESC_STRCT ), *desc,
1123                              (*desc)->desc_phys_addr );
1124     }
1125     *desc = NULL;
1126     return status;
1127 } // wl_pci_dma_free_desc
1128 /*============================================================================*/
1129
1130 /*******************************************************************************
1131  *      wl_pci_dma_alloc_buf()
1132  *******************************************************************************
1133  *
1134  *  DESCRIPTION:
1135  *
1136  *      Allocates one DMA buffer in cache coherent memory, and associates a DMA
1137  *      descriptor with this buffer.
1138  *
1139  *  PARAMETERS:
1140  *
1141  *      pdev - a pointer to the device's pci_dev structure
1142  *      lp  - the device's private adapter structure
1143  *
1144  *  RETURNS:
1145  *
1146  *      0 on success
1147  *      errno value otherwise
1148  *
1149  ******************************************************************************/
1150 int wl_pci_dma_alloc_buf( struct pci_dev *pdev, struct wl_private *lp,
1151                           DESC_STRCT *desc, int size )
1152 {
1153     int         status = 0;
1154     dma_addr_t  pa;
1155 //
1156 //     if( desc == NULL ) {
1157 //         status = -EFAULT;
1158 //     }
1159 //     if( status == 0 && desc->buf_addr != NULL ) {
1160 //         status = -EFAULT;
1161 //     }
1162 //     if( status == 0 ) {
1163 //         desc->buf_addr = pci_alloc_consistent( pdev, size, &pa );
1164 //     }
1165 //     if( desc->buf_addr == NULL ) {
1166 //         DBG_ERROR( DbgInfo, "pci_alloc_consistent() failed\n" );
1167 //         status = -ENOMEM;
1168 //     } else {
1169 //         desc->buf_phys_addr = cpu_to_le32( pa );
1170 //         SET_BUF_SIZE( desc, size );
1171 //     }
1172 //     DBG_LEAVE( DbgInfo );
1173     return status;
1174 } // wl_pci_dma_alloc_buf
1175 /*============================================================================*/
1176
1177 /*******************************************************************************
1178  *      wl_pci_dma_free_buf()
1179  *******************************************************************************
1180  *
1181  *  DESCRIPTION:
1182  *
1183  *      Allocates one DMA buffer in cache coherent memory, and associates a DMA
1184  *      descriptor with this buffer.
1185  *
1186  *  PARAMETERS:
1187  *
1188  *      pdev - a pointer to the device's pci_dev structure
1189  *      lp  - the device's private adapter structure
1190  *
1191  *  RETURNS:
1192  *
1193  *      0 on success
1194  *      errno value otherwise
1195  *
1196  ******************************************************************************/
1197 int wl_pci_dma_free_buf( struct pci_dev *pdev, struct wl_private *lp,
1198                          DESC_STRCT *desc )
1199 {
1200     int         status = 0;
1201     /*------------------------------------------------------------------------*/
1202
1203     if( desc == NULL ) {
1204         status = -EFAULT;
1205     }
1206     if( status == 0 && desc->buf_addr == NULL ) {
1207         status = -EFAULT;
1208     }
1209     if( status == 0 ) {
1210         pci_free_consistent( pdev, GET_BUF_SIZE( desc ), desc->buf_addr,
1211                              desc->buf_phys_addr );
1212
1213         desc->buf_addr = 0;
1214         desc->buf_phys_addr = 0;
1215         SET_BUF_SIZE( desc, 0 );
1216     }
1217     return status;
1218 } // wl_pci_dma_free_buf
1219 /*============================================================================*/
1220
1221 /*******************************************************************************
1222  *      wl_pci_dma_hcf_supply()
1223  *******************************************************************************
1224  *
1225  *  DESCRIPTION:
1226  *
1227  *      Supply HCF with DMA-related resources. These consist of:
1228  *          - buffers and descriptors for receive purposes
1229  *          - one 'reclaim' descriptor for the transmit path, used to fulfill a
1230  *            certain H25 DMA engine requirement
1231  *          - one 'reclaim' descriptor for the receive path, used to fulfill a
1232  *            certain H25 DMA engine requirement
1233  *
1234  *      This function is called at start-of-day or at re-initialization.
1235  *
1236  *  PARAMETERS:
1237  *
1238  *      lp  - the device's private adapter structure
1239  *
1240  *  RETURNS:
1241  *
1242  *      0 on success
1243  *      errno value otherwise
1244  *
1245  ******************************************************************************/
1246 void wl_pci_dma_hcf_supply( struct wl_private *lp )
1247 {
1248     int i;
1249
1250     //if( lp->dma.status == 0 );
1251     //{
1252         /* Hand over the Rx/Tx reclaim descriptors to the HCF */
1253         if( lp->dma.tx_reclaim_desc ) {
1254             DBG_PRINT( "lp->dma.tx_reclaim_desc: 0x%p\n", lp->dma.tx_reclaim_desc );
1255             hcf_dma_tx_put( &lp->hcfCtx, lp->dma.tx_reclaim_desc, 0 );
1256             lp->dma.tx_reclaim_desc = NULL;
1257             DBG_PRINT( "lp->dma.tx_reclaim_desc: 0x%p\n", lp->dma.tx_reclaim_desc );
1258         }
1259         if( lp->dma.rx_reclaim_desc ) {
1260             DBG_PRINT( "lp->dma.rx_reclaim_desc: 0x%p\n", lp->dma.rx_reclaim_desc );
1261             hcf_dma_rx_put( &lp->hcfCtx, lp->dma.rx_reclaim_desc );
1262             lp->dma.rx_reclaim_desc = NULL;
1263             DBG_PRINT( "lp->dma.rx_reclaim_desc: 0x%p\n", lp->dma.rx_reclaim_desc );
1264         }
1265         /* Hand over the Rx descriptor chain to the HCF */
1266         for( i = 0; i < NUM_RX_DESC; i++ ) {
1267             DBG_PRINT( "lp->dma.rx_packet[%d]:    0x%p\n", i, lp->dma.rx_packet[i] );
1268             hcf_dma_rx_put( &lp->hcfCtx, lp->dma.rx_packet[i] );
1269             lp->dma.rx_packet[i] = NULL;
1270             DBG_PRINT( "lp->dma.rx_packet[%d]:    0x%p\n", i, lp->dma.rx_packet[i] );
1271         }
1272     //}
1273
1274     DBG_LEAVE( DbgInfo );
1275     return;
1276 } // wl_pci_dma_hcf_supply
1277 /*============================================================================*/
1278
1279 /*******************************************************************************
1280  *      wl_pci_dma_hcf_reclaim()
1281  *******************************************************************************
1282  *
1283  *  DESCRIPTION:
1284  *
1285  *      Return DMA-related resources from the HCF. These consist of:
1286  *          - buffers and descriptors for receive purposes
1287  *          - buffers and descriptors for transmit purposes
1288  *          - one 'reclaim' descriptor for the transmit path, used to fulfill a
1289  *            certain H25 DMA engine requirement
1290  *          - one 'reclaim' descriptor for the receive path, used to fulfill a
1291  *            certain H25 DMA engine requirement
1292  *
1293  *      This function is called at end-of-day or at re-initialization.
1294  *
1295  *  PARAMETERS:
1296  *
1297  *      lp  - the device's private adapter structure
1298  *
1299  *  RETURNS:
1300  *
1301  *      0 on success
1302  *      errno value otherwise
1303  *
1304  ******************************************************************************/
1305 void wl_pci_dma_hcf_reclaim( struct wl_private *lp )
1306 {
1307     int i;
1308
1309     wl_pci_dma_hcf_reclaim_rx( lp );
1310     for( i = 0; i < NUM_RX_DESC; i++ ) {
1311         DBG_PRINT( "rx_packet[%d] 0x%p\n", i, lp->dma.rx_packet[i] );
1312 //         if( lp->dma.rx_packet[i] == NULL ) {
1313 //             DBG_PRINT( "wl_pci_dma_hcf_reclaim: rx_packet[%d] NULL\n", i );
1314 //         }
1315     }
1316
1317     wl_pci_dma_hcf_reclaim_tx( lp );
1318     for( i = 0; i < NUM_TX_DESC; i++ ) {
1319         DBG_PRINT( "tx_packet[%d] 0x%p\n", i, lp->dma.tx_packet[i] );
1320 //         if( lp->dma.tx_packet[i] == NULL ) {
1321 //             DBG_PRINT( "wl_pci_dma_hcf_reclaim: tx_packet[%d] NULL\n", i );
1322 //         }
1323      }
1324
1325     DBG_LEAVE( DbgInfo );
1326     return;
1327 } // wl_pci_dma_hcf_reclaim
1328 /*============================================================================*/
1329
1330 /*******************************************************************************
1331  *      wl_pci_dma_hcf_reclaim_rx()
1332  *******************************************************************************
1333  *
1334  *  DESCRIPTION:
1335  *
1336  *      Reclaim Rx packets that have already been processed by the HCF.
1337  *
1338  *  PARAMETERS:
1339  *
1340  *      lp  - the device's private adapter structure
1341  *
1342  *  RETURNS:
1343  *
1344  *      0 on success
1345  *      errno value otherwise
1346  *
1347  ******************************************************************************/
1348 void wl_pci_dma_hcf_reclaim_rx( struct wl_private *lp )
1349 {
1350     int         i;
1351     DESC_STRCT *p;
1352
1353     //if( lp->dma.status == 0 )
1354     //{
1355         while ( ( p = hcf_dma_rx_get( &lp->hcfCtx ) ) != NULL ) {
1356             if( p && p->buf_addr == NULL ) {
1357                 /* A reclaim descriptor is being given back by the HCF. Reclaim
1358                    descriptors have a NULL buf_addr */
1359                 lp->dma.rx_reclaim_desc = p;
1360                 DBG_PRINT( "reclaim_descriptor: 0x%p\n", p );
1361                 continue;
1362             }
1363             for( i = 0; i < NUM_RX_DESC; i++ ) {
1364                 if( lp->dma.rx_packet[i] == NULL ) {
1365                     break;
1366                 }
1367             }
1368             /* An Rx buffer descriptor is being given back by the HCF */
1369             lp->dma.rx_packet[i] = p;
1370             lp->dma.rx_rsc_ind++;
1371                 DBG_PRINT( "rx_packet[%d] 0x%p\n", i, lp->dma.rx_packet[i] );
1372         }
1373     //}
1374     DBG_LEAVE( DbgInfo );
1375 } // wl_pci_dma_hcf_reclaim_rx
1376 /*============================================================================*/
1377
1378 /*******************************************************************************
1379  *      wl_pci_dma_get_tx_packet()
1380  *******************************************************************************
1381  *
1382  *  DESCRIPTION:
1383  *
1384  *      Obtains a Tx descriptor from the chain to use for Tx.
1385  *
1386  *  PARAMETERS:
1387  *
1388  *      lp - a pointer to the device's wl_private structure.
1389  *
1390  *  RETURNS:
1391  *
1392  *      A pointer to the retrieved descriptor
1393  *
1394  ******************************************************************************/
1395 DESC_STRCT * wl_pci_dma_get_tx_packet( struct wl_private *lp )
1396 {
1397     int i;
1398     DESC_STRCT *desc = NULL;
1399     /*------------------------------------------------------------------------*/
1400
1401     for( i = 0; i < NUM_TX_DESC; i++ ) {
1402         if( lp->dma.tx_packet[i] ) {
1403             break;
1404         }
1405     }
1406
1407     if( i != NUM_TX_DESC ) {
1408         desc = lp->dma.tx_packet[i];
1409
1410         lp->dma.tx_packet[i] = NULL;
1411         lp->dma.tx_rsc_ind--;
1412
1413         memset( desc->buf_addr, 0, HCF_DMA_TX_BUF1_SIZE );
1414     }
1415
1416     return desc;
1417 } // wl_pci_dma_get_tx_packet
1418 /*============================================================================*/
1419
1420 /*******************************************************************************
1421  *      wl_pci_dma_put_tx_packet()
1422  *******************************************************************************
1423  *
1424  *  DESCRIPTION:
1425  *
1426  *      Returns a Tx descriptor to the chain.
1427  *
1428  *  PARAMETERS:
1429  *
1430  *      lp   - a pointer to the device's wl_private structure.
1431  *      desc - a pointer to the descriptor to return.
1432  *
1433  *  RETURNS:
1434  *
1435  *      N/A
1436  *
1437  ******************************************************************************/
1438 void wl_pci_dma_put_tx_packet( struct wl_private *lp, DESC_STRCT *desc )
1439 {
1440     int i;
1441     /*------------------------------------------------------------------------*/
1442
1443     for( i = 0; i < NUM_TX_DESC; i++ ) {
1444         if( lp->dma.tx_packet[i] == NULL ) {
1445             break;
1446         }
1447     }
1448
1449     if( i != NUM_TX_DESC ) {
1450         lp->dma.tx_packet[i] = desc;
1451         lp->dma.tx_rsc_ind++;
1452     }
1453 } // wl_pci_dma_put_tx_packet
1454 /*============================================================================*/
1455
1456 /*******************************************************************************
1457  *      wl_pci_dma_hcf_reclaim_tx()
1458  *******************************************************************************
1459  *
1460  *  DESCRIPTION:
1461  *
1462  *      Reclaim Tx packets that have either been processed by the HCF due to a
1463  *      port disable or a Tx completion.
1464  *
1465  *  PARAMETERS:
1466  *
1467  *      lp  - the device's private adapter structure
1468  *
1469  *  RETURNS:
1470  *
1471  *      0 on success
1472  *      errno value otherwise
1473  *
1474  ******************************************************************************/
1475 void wl_pci_dma_hcf_reclaim_tx( struct wl_private *lp )
1476 {
1477     int         i;
1478     DESC_STRCT *p;
1479
1480     //if( lp->dma.status == 0 )
1481     //{
1482         while ( ( p = hcf_dma_tx_get( &lp->hcfCtx ) ) != NULL ) {
1483
1484             if( p != NULL && p->buf_addr == NULL ) {
1485                 /* A Reclaim descriptor is being given back by the HCF. Reclaim
1486                    descriptors have a NULL buf_addr */
1487                 lp->dma.tx_reclaim_desc = p;
1488                 DBG_PRINT( "reclaim_descriptor: 0x%p\n", p );
1489                 continue;
1490             }
1491             for( i = 0; i < NUM_TX_DESC; i++ ) {
1492                 if( lp->dma.tx_packet[i] == NULL ) {
1493                     break;
1494                 }
1495             }
1496             /* An Rx buffer descriptor is being given back by the HCF */
1497             lp->dma.tx_packet[i] = p;
1498             lp->dma.tx_rsc_ind++;
1499                 DBG_PRINT( "tx_packet[%d] 0x%p\n", i, lp->dma.tx_packet[i] );
1500         }
1501     //}
1502
1503     if( lp->netif_queue_on == FALSE ) {
1504         netif_wake_queue( lp->dev );
1505         WL_WDS_NETIF_WAKE_QUEUE( lp );
1506         lp->netif_queue_on = TRUE;
1507     }
1508     DBG_LEAVE( DbgInfo );
1509     return;
1510 } // wl_pci_dma_hcf_reclaim_tx
1511 /*============================================================================*/
1512 #endif  // ENABLE_DMA