sample: eliminate clever code to determine which proc file is accessed
[madwifi/.git] / ath / if_ath_hal_macros.h
1 /*-
2  * Copyright (c) 2007 Michael Taylor
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer,
10         without modification.
11  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12  *    similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
13  *    redistribution must be conditioned upon including a substantially
14  *    similar Disclaimer requirement for further binary redistribution.
15  * 3. Neither the names of the above-listed copyright holders nor the names
16  *    of any contributors may be used to endorse or promote products derived
17  *    from this software without specific prior written permission.
18  *
19  * Alternatively, this software may be distributed under the terms of the
20  * GNU General Public License ("GPL") version 2 as published by the Free
21  * Software Foundation.
22  *
23  * NO WARRANTY
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26  * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
27  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
28  * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
29  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
32  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
34  * THE POSSIBILITY OF SUCH DAMAGES.
35  *
36  * $Id: foo mtaylor $
37  */
38 /* 
39  * This file provides some macros that are used by if_ath_hal.h,
40  * if_ath_hal_wrappers.h, and if_ath_hal_wrappers.c.
41  * 
42  * The macros are provided for the HAL lock and for dynamically deciding whether
43  * to define the HAL wrapper functions as inline or in the implementation file
44  * at build time.  i.e. inline for speed, or non-inline for debugging visibility
45  * into the HAL methods being called (despite obfuscation).
46  * 
47  * The if_ath_hal.h file is generated from ath_hal/ah.h at build time by the
48  * build system.
49  */
50 #ifndef _IF_ATH_HAL_MACROS_H_
51 #define _IF_ATH_HAL_MACROS_H_
52
53 #define ATH_HAL_LOCK_INIT(_sc)  spin_lock_init(&(_sc)->sc_hal_lock)
54 #define ATH_HAL_LOCK_DESTROY(_sc)
55 #define ATH_HAL_LOCK_IRQ(_sc)   do { \
56    unsigned long __sc_halLockflags;                                \
57    ATH_HAL_LOCK_CHECK(_sc);                                        \
58    spin_lock_irqsave(&(_sc)->sc_hal_lock, __sc_halLockflags);
59 #define ATH_HAL_UNLOCK_IRQ(_sc) \
60    ATH_HAL_LOCK_ASSERT(_sc);                                       \
61    spin_unlock_irqrestore(&(_sc)->sc_hal_lock, __sc_halLockflags); \
62    } while (0)
63 #define ATH_HAL_UNLOCK_IRQ_EARLY(_sc) \
64    ATH_HAL_LOCK_ASSERT(_sc);                                       \
65    spin_unlock_irqrestore(&(_sc)->sc_hal_lock, __sc_halLockflags);
66
67 #if (defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)) && defined(spin_is_locked)
68 #define ATH_HAL_LOCK_ASSERT(_sc) \
69         KASSERT(spin_is_locked(&(_sc)->sc_hal_lock), ("HAL not locked!"))
70 #if (defined(ATH_DEBUG_SPINLOCKS))
71 #define ATH_HAL_LOCK_CHECK(_sc) do { \
72         if (spin_is_locked(&(_sc)->sc_hal_lock)) \
73                 IPRINTF(_sc, "About to block on HAL lock! [%s:%d]\n", __func__, __LINE__); \
74 } while(0)
75 #else /* #if (defined(ATH_DEBUG_SPINLOCKS)) */
76 #define ATH_HAL_LOCK_CHECK(_sc)
77 #endif /* #if (defined(ATH_DEBUG_SPINLOCKS)) */
78
79 #else
80 #define ATH_HAL_LOCK_ASSERT(_sc)
81 #define ATH_HAL_LOCK_CHECK(_sc)
82 #endif
83
84 #endif /* #ifndef _IF_ATH_HAL_MACROS_H_ */