6 ////////////////////////////////////////////////////////
10 ////////////////////////////////////////////////////////
20 #include <ntstrsafe.h>
23 #include <complib/cl_timer.h>
24 #include <complib/cl_qlist.h>
30 ////////////////////////////////////////////////////////
34 ////////////////////////////////////////////////////////
36 #define BITS_PER_LONG 32
38 #define HZ 1000000 /* 1 sec in usecs */
42 ////////////////////////////////////////////////////////
46 ////////////////////////////////////////////////////////
48 #define BUG_ON(exp) ASSERT(!(exp)) /* in Linux follows here panic() !*/
49 #define snprintf _snprintf
50 #define printk DbgPrint
51 #define KERN_ERR "err:"
52 #define KERN_WARNING "warn:"
53 #define KERN_DEBUG "dbg:"
56 #define wmb KeMemoryBarrier
57 #define rmb KeMemoryBarrier
58 #define mb KeMemoryBarrier
59 // TODO: can we make it empty ? I saw in Linux, it is an empty macro for x86 & x64
60 #define mmiowb KeMemoryBarrier
63 #define EXPORT_SYMBOL_GPL(a)
65 // gcc compiler attributes
72 #define __attribute_const__
74 #define unlikely(x) (x)
75 #define __attribute__(a)
79 #define container_of CONTAINING_RECORD
82 #define inline __inline
84 // new Linux event mechanism
85 #define complete(a) wake_up(a)
88 #define __constant_htons CL_HTON16
89 #define __constant_cpu_to_be32 CL_HTON32
92 #define __always_inline inline
94 ////////////////////////////////////////////////////////
98 ////////////////////////////////////////////////////////
101 typedef unsigned char u8, __u8;
102 typedef unsigned short int u16, __u16;
103 typedef unsigned int u32, __u32;
104 typedef unsigned __int64 u64, __u64;
105 typedef char s8, __s8;
106 typedef short int s16, __s16;
107 typedef int s32, __s32;
108 typedef __int64 s64, __s64;
117 typedef u64 io_addr_t;
120 typedef void (*MT_EMPTY_FUNC)();
122 // PCI BAR descriptor
123 typedef enum _hca_bar_type
133 typedef struct _hca_bar
142 // interface structure between Upper and Low Layers of the driver
145 // driver: OS/platform resources
146 BUS_INTERFACE_STANDARD bus_pci_ifc;
147 PCI_COMMON_CONFIG pci_cfg_space;
148 uplink_info_t uplink_info;
149 // driver: card resources
150 hca_bar_t bar[N_BARS];
151 CM_PARTIAL_RESOURCE_DESCRIPTOR int_info; /* HCA interrupt resources */
152 // driver: various objects and info
155 DMA_ADAPTER * p_dma_adapter; /* HCA adapter object */
156 DEVICE_OBJECT * p_self_do; /* mlx4 FDO */
157 // mlx4_ib: various objects and info
158 struct ib_device * ib_dev;
159 // mlx4_net: various objects and info
160 struct mlx4_dev * dev;
161 volatile long dpc_lock;
162 #ifdef USE_WDM_INTERRUPTS
163 PKINTERRUPT int_obj; /* HCA interrupt object */
164 KSPIN_LOCK isr_lock; /* lock for the ISR */
165 int msi_used; /* connected to MSI interrupts */
170 typedef void (*dpc_t)( struct _KDPC *, PVOID, PVOID, PVOID );
173 ////////////////////////////////////////////////////////
177 ////////////////////////////////////////////////////////
180 #define swab32(a) _byteswap_ulong((ULONG)(a))
181 #define cpu_to_be16(a) _byteswap_ushort((USHORT)(a))
182 #define be16_to_cpu(a) _byteswap_ushort((USHORT)(a))
183 #define cpu_to_be32(a) _byteswap_ulong((ULONG)(a))
184 #define be32_to_cpu(a) _byteswap_ulong((ULONG)(a))
185 #define cpu_to_be64(a) _byteswap_uint64((UINT64)(a))
186 #define be64_to_cpu(a) _byteswap_uint64((UINT64)(a))
187 #define be64_to_cpup(p) _byteswap_uint64(*(PUINT64)(p))
188 #define be32_to_cpup(p) _byteswap_ulong(*(PULONG)(p))
189 #define be16_to_cpup(p) _byteswap_ushort(*(PUSHORT)(p))
192 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
195 #define ALIGN(x,a) (((x)+(a)-1)&~((a)-1))
196 #define PTR_ALIGN(size) (((size) + sizeof(void*) - 1) & ~(sizeof(void*) - 1))
198 // there is a bug in Microsoft compiler, that when _byteswap_uint64() gets an expression
199 // it executes the expression but doesn't swap tte dwords
200 // So, there's a workaround
201 #ifdef BYTESWAP_UINT64_BUG_FIXED
202 #define CPU_2_BE64_PREP
203 #define CPU_2_BE64(x) cl_hton64(x)
205 #define CPU_2_BE64_PREP unsigned __int64 __tmp__
206 #define CPU_2_BE64(x) ( __tmp__ = x, cl_hton64(__tmp__) )
209 #define ERR_PTR(error) ((void*)(LONG_PTR)(error))
210 #define PTR_ERR(ptr) ((long)(LONG_PTR)(void*)(ptr))
211 //TODO: there are 2 assumptions here:
212 // - pointer can't be too big (around -1)
213 // - error can't be bigger than 1000
214 #define IS_ERR(ptr) ((ULONG_PTR)ptr > (ULONG_PTR)-1000L)
216 #define BITS_TO_LONGS(bits) \
217 (((bits)+BITS_PER_LONG-1)/BITS_PER_LONG)
220 #define ETIMEDOUT (110)
225 #define PAGE_ALIGN(Va) ((u64)((ULONG_PTR)(Va) & ~(PAGE_SIZE - 1)))
228 #define NEXT_PAGE_ALIGN(addr) (((addr)+PAGE_SIZE-1)&PAGE_MASK)
231 #define min_t(type,x,y) ((type)(x) < (type)(y) ? (type)(x) : (type)(y))
233 #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
235 #define EXPORT_SYMBOL(name)
236 #ifndef USE_WDM_INTERRUPTS
237 #define free_irq(pdev)
240 static inline NTSTATUS errno_to_ntstatus(int err)
242 #define MAP_ERR(err,ntstatus) case err: status = ntstatus; break
246 return STATUS_SUCCESS;
251 MAP_ERR( ENOENT, STATUS_NOT_FOUND );
252 MAP_ERR( EAGAIN, STATUS_DEVICE_BUSY );
253 MAP_ERR( ENOMEM, STATUS_NO_MEMORY );
254 MAP_ERR( EACCES, STATUS_ACCESS_DENIED );
255 MAP_ERR( EFAULT, STATUS_DRIVER_INTERNAL_ERROR );
256 MAP_ERR( EBUSY, STATUS_INSUFFICIENT_RESOURCES );
257 MAP_ERR( ENODEV, STATUS_NOT_SUPPORTED );
258 MAP_ERR( EINVAL, STATUS_INVALID_PARAMETER );
259 MAP_ERR( ENOSYS, STATUS_NOT_SUPPORTED );
261 status = STATUS_UNSUCCESSFUL;
268 ////////////////////////////////////////////////////////
272 ////////////////////////////////////////////////////////
274 SIZE_T strlcpy(char *dest, const void *src, SIZE_T size);
279 ////////////////////////////////////////////////////////
283 ////////////////////////////////////////////////////////
288 #include <l2w_atomic.h>
290 #include <l2w_bitmap.h>
291 #include "l2w_debug.h"
292 #include <l2w_memory.h>
293 #include <l2w_umem.h>
294 #include <l2w_list.h>
296 #include <l2w_pcipool.h>
297 #include "l2w_radix.h"
298 #include <l2w_spinlock.h>
299 #include <l2w_sync.h>
300 #include <l2w_time.h>
304 static inline int mlx4_is_livefish(struct mlx4_dev *dev)
306 return !!(dev->flags & MLX4_FLAG_LIVEFISH);
309 static inline int mlx4_is_barred(struct mlx4_dev *dev)
311 return dev->flags & (MLX4_FLAG_RESET_CLIENT | MLX4_FLAG_RESET_DRIVER);
314 static inline int mlx4_is_in_reset(struct mlx4_dev *dev)
316 return dev->flags & MLX4_FLAG_RESET_STARTED;