]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - drivers/net/npe/include/IxEthDBLocks_p.h
doc: SPI: Add qspi test details on AM43xx
[karo-tx-uboot.git] / drivers / net / npe / include / IxEthDBLocks_p.h
1 /**
2  * @file IxEthAccDBLocks_p.h
3  *
4  * @brief Definition of transaction lock stacks and lock utility macros
5  * 
6  * @par
7  * IXP400 SW Release version 2.0
8  * 
9  * -- Copyright Notice --
10  * 
11  * @par
12  * Copyright 2001-2005, Intel Corporation.
13  * All rights reserved.
14  * 
15  * @par
16  * SPDX-License-Identifier:     BSD-3-Clause
17  * @par
18  * -- End of Copyright Notice --
19  */
20
21 #ifndef IxEthAccDBLocks_p_H
22 #define IxEthAccDBLocks_p_H
23
24 #include "IxOsPrintf.h"
25
26 /* Lock and lock stacks */
27 typedef struct
28 {
29     IxOsalFastMutex* locks[MAX_LOCKS];
30     UINT32 stackPointer, basePointer;
31 } LockStack;
32
33 #define TRY_LOCK(mutex) \
34     { \
35         if (ixOsalFastMutexTryLock(mutex) != IX_SUCCESS) \
36         { \
37             return IX_ETH_DB_BUSY; \
38         } \
39     }
40
41
42 #define UNLOCK(mutex) { ixOsalFastMutexUnlock(mutex); }
43
44 #define INIT_STACK(stack) \
45     { \
46         (stack)->basePointer  = 0; \
47         (stack)->stackPointer = 0; \
48     }
49
50 #define PUSH_LOCK(stack, lock) \
51     { \
52         if ((stack)->stackPointer == MAX_LOCKS) \
53         { \
54             ERROR_LOG("Ethernet DB: maximum number of elements in a lock stack has been exceeded on push, heavy chaining?\n"); \
55             UNROLL_STACK(stack); \
56             \
57             return IX_ETH_DB_NOMEM; \
58         } \
59         \
60         if (ixOsalFastMutexTryLock(lock) == IX_SUCCESS) \
61         { \
62             (stack)->locks[(stack)->stackPointer++] = (lock); \
63         } \
64         else \
65         { \
66             UNROLL_STACK(stack); \
67             \
68             return IX_ETH_DB_BUSY; \
69         } \
70     }
71
72 #define POP_LOCK(stack) \
73     { \
74         ixOsalFastMutexUnlock((stack)->locks[--(stack)->stackPointer]); \
75     }
76
77 #define UNROLL_STACK(stack) \
78     { \
79         while ((stack)->stackPointer > (stack)->basePointer) \
80         { \
81             POP_LOCK(stack); \
82         } \
83     }
84
85 #define SHIFT_STACK(stack) \
86     { \
87         if ((stack)->basePointer == MAX_LOCKS - 1) \
88         { \
89             ERROR_LOG("Ethernet DB: maximum number of elements in a lock stack has been exceeded on shift, heavy chaining?\n"); \
90             UNROLL_STACK(stack); \
91             \
92             return IX_ETH_DB_BUSY; \
93         } \
94         \
95         ixOsalFastMutexUnlock((stack)->locks[(stack)->basePointer++]); \
96     }
97
98 #endif /* IxEthAccDBLocks_p_H */