6 ////////////////////////////////////////////////////////
10 ////////////////////////////////////////////////////////
19 #include <ntstrsafe.h>
22 #include <complib/cl_timer.h>
23 #include <complib/cl_qlist.h>
29 ////////////////////////////////////////////////////////
33 ////////////////////////////////////////////////////////
35 #define BITS_PER_LONG 32
37 #define HZ 1000000 /* 1 sec in usecs */
41 ////////////////////////////////////////////////////////
45 ////////////////////////////////////////////////////////
47 #define BUG_ON(exp) ASSERT(!(exp)) /* in Linux follows here panic() !*/
48 #define snprintf _snprintf
49 #define printk DbgPrint
50 #define KERN_ERR "err:"
51 #define KERN_WARNING "warn:"
52 #define KERN_DEBUG "dbg:"
55 #define wmb KeMemoryBarrier
56 #define rmb KeMemoryBarrier
57 #define mb KeMemoryBarrier
58 // TODO: can we make it empty ? I saw in Linux, it is an empty macro for x86 & x64
59 #define mmiowb KeMemoryBarrier
62 #define EXPORT_SYMBOL_GPL(a)
64 // gcc compiler attributes
71 #define __attribute_const__
73 #define unlikely(x) (x)
74 #define __attribute__(a)
78 #define container_of CONTAINING_RECORD
81 #define inline __inline
83 // new Linux event mechanism
84 #define complete(a) wake_up(a)
87 #define __constant_htons CL_HTON16
88 #define __constant_cpu_to_be32 CL_HTON32
91 #define __always_inline inline
93 ////////////////////////////////////////////////////////
97 ////////////////////////////////////////////////////////
100 typedef unsigned char u8, __u8;
101 typedef unsigned short int u16, __u16;
102 typedef unsigned int u32, __u32;
103 typedef unsigned __int64 u64, __u64;
104 typedef char s8, __s8;
105 typedef short int s16, __s16;
106 typedef int s32, __s32;
107 typedef __int64 s64, __s64;
116 typedef u64 io_addr_t;
119 typedef void (*MT_EMPTY_FUNC)();
121 // PCI BAR descriptor
122 typedef enum _hca_bar_type
132 typedef struct _hca_bar
141 // interface structure between Upper and Low Layers of the driver
144 // driver: OS/platform resources
145 BUS_INTERFACE_STANDARD bus_pci_ifc;
146 PCI_COMMON_CONFIG pci_cfg_space;
147 uplink_info_t uplink_info;
148 // driver: card resources
149 hca_bar_t bar[N_BARS];
150 CM_PARTIAL_RESOURCE_DESCRIPTOR int_info; /* HCA interrupt resources */
151 // driver: various objects and info
154 DMA_ADAPTER * p_dma_adapter; /* HCA adapter object */
155 DEVICE_OBJECT * p_self_do; /* mlx4 FDO */
156 // mlx4_ib: various objects and info
157 struct ib_device * ib_dev;
158 // mlx4_net: various objects and info
159 struct mlx4_dev * dev;
160 volatile long dpc_lock;
161 #ifdef USE_WDM_INTERRUPTS
162 PKINTERRUPT int_obj; /* HCA interrupt object */
163 KSPIN_LOCK isr_lock; /* lock for the ISR */
168 typedef void (*dpc_t)( struct _KDPC *, PVOID, PVOID, PVOID );
171 ////////////////////////////////////////////////////////
175 ////////////////////////////////////////////////////////
178 #define swab32(a) _byteswap_ulong((ULONG)(a))
179 #define cpu_to_be16(a) _byteswap_ushort((USHORT)(a))
180 #define be16_to_cpu(a) _byteswap_ushort((USHORT)(a))
181 #define cpu_to_be32(a) _byteswap_ulong((ULONG)(a))
182 #define be32_to_cpu(a) _byteswap_ulong((ULONG)(a))
183 #define cpu_to_be64(a) _byteswap_uint64((UINT64)(a))
184 #define be64_to_cpu(a) _byteswap_uint64((UINT64)(a))
185 #define be64_to_cpup(p) _byteswap_uint64(*(PUINT64)(p))
186 #define be32_to_cpup(p) _byteswap_ulong(*(PULONG)(p))
187 #define be16_to_cpup(p) _byteswap_ushort(*(PUSHORT)(p))
190 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
193 #define ALIGN(x,a) (((x)+(a)-1)&~((a)-1))
194 #define PTR_ALIGN(size) (((size) + sizeof(void*) - 1) & ~(sizeof(void*) - 1))
196 // there is a bug in Microsoft compiler, that when _byteswap_uint64() gets an expression
197 // it executes the expression but doesn't swap tte dwords
198 // So, there's a workaround
199 #ifdef BYTESWAP_UINT64_BUG_FIXED
200 #define CPU_2_BE64_PREP
201 #define CPU_2_BE64(x) cl_hton64(x)
203 #define CPU_2_BE64_PREP unsigned __int64 __tmp__
204 #define CPU_2_BE64(x) ( __tmp__ = x, cl_hton64(__tmp__) )
207 #define ERR_PTR(error) ((void*)(LONG_PTR)(error))
208 #define PTR_ERR(ptr) ((long)(LONG_PTR)(void*)(ptr))
209 //TODO: there are 2 assumptions here:
210 // - pointer can't be too big (around -1)
211 // - error can't be bigger than 1000
212 #define IS_ERR(ptr) ((ULONG_PTR)ptr > (ULONG_PTR)-1000L)
214 #define BITS_TO_LONGS(bits) \
215 (((bits)+BITS_PER_LONG-1)/BITS_PER_LONG)
218 #define ETIMEDOUT (110)
223 #define PAGE_ALIGN(Va) ((u64)((ULONG_PTR)(Va) & ~(PAGE_SIZE - 1)))
226 #define NEXT_PAGE_ALIGN(addr) (((addr)+PAGE_SIZE-1)&PAGE_MASK)
229 #define min_t(type,x,y) ((type)(x) < (type)(y) ? (type)(x) : (type)(y))
231 #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
233 #define EXPORT_SYMBOL(name)
234 #ifndef USE_WDM_INTERRUPTS
235 #define free_irq(pdev)
238 static inline NTSTATUS errno_to_ntstatus(int err)
240 #define MAP_ERR(err,ntstatus) case err: status = ntstatus; break
244 return STATUS_SUCCESS;
249 MAP_ERR( ENOENT, STATUS_NOT_FOUND );
250 MAP_ERR( EAGAIN, STATUS_DEVICE_BUSY );
251 MAP_ERR( ENOMEM, STATUS_NO_MEMORY );
252 MAP_ERR( EACCES, STATUS_ACCESS_DENIED );
253 MAP_ERR( EFAULT, STATUS_DRIVER_INTERNAL_ERROR );
254 MAP_ERR( EBUSY, STATUS_INSUFFICIENT_RESOURCES );
255 MAP_ERR( ENODEV, STATUS_NOT_SUPPORTED );
256 MAP_ERR( EINVAL, STATUS_INVALID_PARAMETER );
257 MAP_ERR( ENOSYS, STATUS_NOT_SUPPORTED );
259 status = STATUS_UNSUCCESSFUL;
266 ////////////////////////////////////////////////////////
270 ////////////////////////////////////////////////////////
272 SIZE_T strlcpy(char *dest, const void *src, SIZE_T size);
277 ////////////////////////////////////////////////////////
281 ////////////////////////////////////////////////////////
286 #include <l2w_atomic.h>
288 #include <l2w_bitmap.h>
289 #include "l2w_debug.h"
290 #include <l2w_memory.h>
291 #include <l2w_umem.h>
292 #include <l2w_list.h>
294 #include <l2w_pcipool.h>
295 #include "l2w_radix.h"
296 #include <l2w_spinlock.h>
297 #include <l2w_sync.h>
298 #include <l2w_time.h>
302 static inline int mlx4_is_livefish(struct mlx4_dev *dev)
304 return dev->flags & MLX4_FLAG_LIVEFISH;
307 static inline int mlx4_is_barred(struct mlx4_dev *dev)
309 return dev->flags & (MLX4_FLAG_RESET_CLIENT | MLX4_FLAG_RESET_DRIVER);
312 static inline int mlx4_is_in_reset(struct mlx4_dev *dev)
314 return dev->flags & MLX4_FLAG_RESET_STARTED;