0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035 #ifndef __CSIO_DEFS_H__
0036 #define __CSIO_DEFS_H__
0037
0038 #include <linux/kernel.h>
0039 #include <linux/stddef.h>
0040 #include <linux/timer.h>
0041 #include <linux/list.h>
0042 #include <linux/bug.h>
0043 #include <linux/pci.h>
0044 #include <linux/jiffies.h>
0045
0046 #define CSIO_INVALID_IDX 0xFFFFFFFF
0047 #define CSIO_INC_STATS(elem, val) ((elem)->stats.val++)
0048 #define CSIO_DEC_STATS(elem, val) ((elem)->stats.val--)
0049 #define CSIO_VALID_WWN(__n) ((*__n >> 4) == 0x5 ? true : false)
0050 #define CSIO_DID_MASK 0xFFFFFF
0051 #define CSIO_WORD_TO_BYTE 4
0052
0053 #ifndef readq
0054 static inline u64 readq(void __iomem *addr)
0055 {
0056 return readl(addr) + ((u64)readl(addr + 4) << 32);
0057 }
0058
0059 static inline void writeq(u64 val, void __iomem *addr)
0060 {
0061 writel(val, addr);
0062 writel(val >> 32, addr + 4);
0063 }
0064 #endif
0065
0066 static inline int
0067 csio_list_deleted(struct list_head *list)
0068 {
0069 return ((list->next == list) && (list->prev == list));
0070 }
0071
0072 #define csio_list_next(elem) (((struct list_head *)(elem))->next)
0073 #define csio_list_prev(elem) (((struct list_head *)(elem))->prev)
0074
0075
0076 typedef void (*csio_sm_state_t)(void *, uint32_t);
0077
0078 struct csio_sm {
0079 struct list_head sm_list;
0080 csio_sm_state_t sm_state;
0081 };
0082
0083 static inline void
0084 csio_set_state(void *smp, void *state)
0085 {
0086 ((struct csio_sm *)smp)->sm_state = (csio_sm_state_t)state;
0087 }
0088
0089 static inline void
0090 csio_init_state(struct csio_sm *smp, void *state)
0091 {
0092 csio_set_state(smp, state);
0093 }
0094
0095 static inline void
0096 csio_post_event(void *smp, uint32_t evt)
0097 {
0098 ((struct csio_sm *)smp)->sm_state(smp, evt);
0099 }
0100
0101 static inline csio_sm_state_t
0102 csio_get_state(void *smp)
0103 {
0104 return ((struct csio_sm *)smp)->sm_state;
0105 }
0106
0107 static inline bool
0108 csio_match_state(void *smp, void *state)
0109 {
0110 return (csio_get_state(smp) == (csio_sm_state_t)state);
0111 }
0112
0113 #define CSIO_ASSERT(cond) BUG_ON(!(cond))
0114
0115 #ifdef __CSIO_DEBUG__
0116 #define CSIO_DB_ASSERT(__c) CSIO_ASSERT((__c))
0117 #else
0118 #define CSIO_DB_ASSERT(__c)
0119 #endif
0120
0121 #endif