2 * Copyright (C) 2005 - 2009 ServerEngines
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License version 2
7 * as published by the Free Software Foundation. The full GNU General
8 * Public License is included in this distribution in the file called COPYING.
10 * Contact Information:
11 * linux-drivers@serverengines.com
14 * 209 N. Fair Oaks Ave
21 #include <linux/pci.h>
22 #include <linux/if_vlan.h>
32 struct be_queue_info
{
33 struct be_dma_mem dma_mem
;
35 u16 entry_size
; /* Size of an element in the queue */
39 atomic_t used
; /* Number of valid elements in the queue */
42 static inline u32
MODULO(u16 val
, u16 limit
)
44 WARN_ON(limit
& (limit
- 1));
45 return val
& (limit
- 1);
48 static inline void index_inc(u16
*index
, u16 limit
)
50 *index
= MODULO((*index
+ 1), limit
);
53 static inline void *queue_head_node(struct be_queue_info
*q
)
55 return q
->dma_mem
.va
+ q
->head
* q
->entry_size
;
58 static inline void *queue_tail_node(struct be_queue_info
*q
)
60 return q
->dma_mem
.va
+ q
->tail
* q
->entry_size
;
63 static inline void queue_head_inc(struct be_queue_info
*q
)
65 index_inc(&q
->head
, q
->len
);
68 static inline void queue_tail_inc(struct be_queue_info
*q
)
70 index_inc(&q
->tail
, q
->len
);
76 struct be_queue_info q
;
79 /* Adaptive interrupt coalescing (AIC) info */
81 u16 min_eqd
; /* in usecs */
82 u16 max_eqd
; /* in usecs */
83 u16 cur_eqd
; /* in usecs */
87 struct be_queue_info
*q
;
88 struct be_queue_info
*cq
;
93 u8 __iomem
*db
; /* Door Bell */
94 u8 __iomem
*pcicfg
; /* PCI config space */
97 /* Mbox used for cmd request/response */
98 spinlock_t mbox_lock
; /* For serializing mbox cmds to BE card */
99 struct be_dma_mem mbox_mem
;
100 /* Mbox mem is adjusted to align to 16 bytes. The allocated addr
101 * is stored for freeing purpose */
102 struct be_dma_mem mbox_mem_alloced
;
105 struct be_mcc_obj mcc_obj
;
106 spinlock_t mcc_lock
; /* For serializing mcc cmds to BE card */
107 spinlock_t mcc_cq_lock
;
109 /* MCC Async callback */
110 void (*async_cb
) (void *adapter
, bool link_up
);
116 #define PAGE_SHIFT_4K 12
117 #define PAGE_SIZE_4K (1 << PAGE_SHIFT_4K)
119 /* Returns number of pages spanned by the data starting at the given addr */
120 #define PAGES_4K_SPANNED(_address, size) \
121 ((u32)((((size_t)(_address) & (PAGE_SIZE_4K - 1)) + \
122 (size) + (PAGE_SIZE_4K - 1)) >> PAGE_SHIFT_4K))
124 /* Byte offset into the page corresponding to given address */
125 #define OFFSET_IN_PAGE(addr) \
126 ((size_t)(addr) & (PAGE_SIZE_4K-1))
128 /* Returns bit offset within a DWORD of a bitfield */
129 #define AMAP_BIT_OFFSET(_struct, field) \
130 (((size_t)&(((_struct *)0)->field))%32)
132 /* Returns the bit mask of the field that is NOT shifted into location. */
133 static inline u32
amap_mask(u32 bitsize
)
135 return (bitsize
== 32 ? 0xFFFFFFFF : (1 << bitsize
) - 1);
138 static inline void amap_set(void *ptr
, u32 dw_offset
, u32 mask
,
139 u32 offset
, u32 value
)
141 u32
*dw
= (u32
*) ptr
+ dw_offset
;
142 *dw
&= ~(mask
<< offset
);
143 *dw
|= (mask
& value
) << offset
;
146 #define AMAP_SET_BITS(_struct, field, ptr, val) \
148 offsetof(_struct, field)/32, \
149 amap_mask(sizeof(((_struct *)0)->field)), \
150 AMAP_BIT_OFFSET(_struct, field), \
153 static inline u32
amap_get(void *ptr
, u32 dw_offset
, u32 mask
, u32 offset
)
156 return mask
& (*(dw
+ dw_offset
) >> offset
);
159 #define AMAP_GET_BITS(_struct, field, ptr) \
161 offsetof(_struct, field)/32, \
162 amap_mask(sizeof(((_struct *)0)->field)), \
163 AMAP_BIT_OFFSET(_struct, field))
165 #define be_dws_cpu_to_le(wrb, len) swap_dws(wrb, len)
166 #define be_dws_le_to_cpu(wrb, len) swap_dws(wrb, len)
167 static inline void swap_dws(void *wrb
, int len
)
173 *dw
= cpu_to_le32(*dw
);
177 #endif /* __BIG_ENDIAN */
180 extern void beiscsi_cq_notify(struct be_ctrl_info
*ctrl
, u16 qid
, bool arm
,
183 #endif /* BEISCSI_H */