2 * Copyright (c) 2005 SilverStorm Technologies. All rights reserved.
\r
3 * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
\r
5 * This software is available to you under the OpenIB.org BSD license
\r
8 * Redistribution and use in source and binary forms, with or
\r
9 * without modification, are permitted provided that the following
\r
10 * conditions are met:
\r
12 * - Redistributions of source code must retain the above
\r
13 * copyright notice, this list of conditions and the following
\r
16 * - Redistributions in binary form must reproduce the above
\r
17 * copyright notice, this list of conditions and the following
\r
18 * disclaimer in the documentation and/or other materials
\r
19 * provided with the distribution.
\r
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
\r
22 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
\r
23 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
\r
24 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
\r
25 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
\r
26 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
27 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
\r
30 * $Id: al.c 1611 2006-08-20 14:48:55Z sleybo $
\r
36 ////////////////////////////////////////////////////////
\r
40 ////////////////////////////////////////////////////////
\r
42 #ifdef USE_WDM_FRAMEWORK
\r
43 #include <complib/cl_pnp_po.h>
\r
45 #include <iba/ib_ci_ifc.h>
\r
48 #include "bus_intf.h"
\r
51 ////////////////////////////////////////////////////////
\r
55 ////////////////////////////////////////////////////////
\r
57 #if !defined(FILE_DEVICE_INFINIBAND) // Not defined in WXP DDK
\r
58 #define FILE_DEVICE_INFINIBAND 0x0000003B
\r
61 #define BUSENUM_POOL_TAG (ULONG) 'suBT'
\r
63 #define HCARESOURCENAME L"MofResourceName"
\r
66 #define min(_a, _b) (((_a) < (_b)) ? (_a) : (_b))
\r
70 #define max(_a, _b) (((_a) > (_b)) ? (_a) : (_b))
\r
74 ////////////////////////////////////////////////////////
\r
78 ////////////////////////////////////////////////////////
\r
80 /****s* HCA/hca_reg_state_t
\r
85 * State for tracking registration with AL. This state is independent of the
\r
86 * device PnP state, and both are used to properly register with AL.
\r
90 typedef enum _hca_reg_state
\r
103 * AddDevice was called and successfully registered for interface
\r
107 * IRP_MN_START_DEVICE was called. The HCA is fully functional.
\r
112 // Structure for reporting data to WMI
\r
115 typedef struct _HCA_WMI_STD_DATA {
\r
116 UINT32 DebugPrintLevel;
\r
117 UINT32 DebugPrintFlags;
\r
119 } HCA_WMI_STD_DATA, * PHCA_WMI_STD_DATA;
\r
122 #pragma warning(disable:4201) // nameless struct/union
\r
123 typedef struct _GLOBALS {
\r
126 #pragma warning(default:4201) // nameless struct/union
\r
131 // The device extension of the bus itself. From whence the PDO's are born.
\r
134 typedef struct _FDO_DEVICE_DATA
\r
136 #ifdef USE_WDM_FRAMEWORK
\r
137 /* -------------------------------------------------
\r
138 * PNP and POWER MANAGER DATA
\r
139 * ------------------------------------------------ */
\r
140 cl_pnp_po_ext_t cl_ext; /* COMPLIB PnP object */
\r
141 /* Cache of the system to device power states. */
\r
142 DEVICE_POWER_STATE DevicePower[PowerSystemMaximum];
\r
143 DEVICE_POWER_STATE DevicePowerState;
\r
144 SYSTEM_POWER_STATE SystemPowerState;
\r
145 PIO_WORKITEM pPoWorkItem;
\r
149 /* -------------------------------------------------
\r
151 * ------------------------------------------------ */
\r
152 WDFDEVICE FdoDevice;
\r
155 HCA_WMI_STD_DATA WmiData;
\r
157 /* -------------------------------------------------
\r
159 * ------------------------------------------------ */
\r
160 void * pnp_ifc_entry; /* Notification entry for PnP interface events. */
\r
161 void * pnp_target_entry; /* Notification entry for PnP target events. */
\r
162 PNP_DEVICE_STATE pnpState; /* state for PnP Manager */
\r
164 /* -------------------------------------------------
\r
166 * ------------------------------------------------ */
\r
167 /* Number of references on the upper interface. */
\r
168 atomic32_t n_hca_ifc_ref;
\r
169 hca_reg_state_t state; /* State for tracking registration with AL */
\r
170 DEVICE_OBJECT * p_al_dev; /* IB_AL FDO */
\r
171 FILE_OBJECT * p_al_file_obj; /* IB_AL file object */
\r
172 UNICODE_STRING al_sym_name; /* IB_AL symbolic name */
\r
174 /* -------------------------------------------------
\r
176 * ------------------------------------------------ */
\r
178 atomic32_t usecnt; /* the number of working applications*/
\r
179 spinlock_t uctx_lock; // spinlock for the below chain
\r
180 cl_qlist_t uctx_list; // chain of user contexts
\r
181 int bus_pci_ifc_taken;
\r
182 BUS_INTERFACE_STANDARD bus_pci_ifc; /* PCI bus interface */
\r
184 /* -------------------------------------------------
\r
185 * LOW LEVEL DRIVER' DATA
\r
186 * ------------------------------------------------ */
\r
187 int bus_ib_ifc_taken;
\r
188 MLX4_BUS_IB_INTERFACE bus_ib_ifc;
\r
191 } FDO_DEVICE_DATA, *PFDO_DEVICE_DATA;
\r
193 #ifndef USE_WDM_FRAMEWORK
\r
195 WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(FDO_DEVICE_DATA, FdoGetData)
\r
197 typedef struct _QUEUE_DATA
\r
199 PFDO_DEVICE_DATA FdoData;
\r
201 } QUEUE_DATA, *PQUEUE_DATA;
\r
203 WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(QUEUE_DATA, QueueGetData)
\r
207 ////////////////////////////////////////////////////////
\r
211 ////////////////////////////////////////////////////////
\r
213 static inline PFDO_DEVICE_DATA hca2fdo(mlnx_hca_t *p_hca)
\r
215 return CONTAINING_RECORD(p_hca, FDO_DEVICE_DATA, hca);
\r
218 static inline struct ib_device *hca2ibdev(mlnx_hca_t *p_hca)
\r
220 return (hca2fdo(p_hca))->bus_ib_ifc.p_ibdev;
\r
223 static inline mlnx_hca_t *ibdev2hca(struct ib_device *p_ibdev)
\r
225 return &p_ibdev->x.p_fdo->hca;
\r
228 static inline struct pci_dev *hca2pdev(mlnx_hca_t *p_hca)
\r
230 return (hca2fdo(p_hca))->bus_ib_ifc.pdev;
\r
233 static inline struct mlx4_dev *hca2mdev(mlnx_hca_t *p_hca)
\r
235 return (hca2fdo(p_hca))->bus_ib_ifc.pdev->dev;
\r
238 static inline boolean_t hca_is_livefish(PFDO_DEVICE_DATA p_fdo)
\r
240 if (p_fdo == NULL) {
\r
243 return p_fdo->bus_ib_ifc.is_livefish;
\r
246 static inline ib_api_status_t errno_to_iberr(int err)
\r
248 #define MAP_NT_ERR(err,ibstatus) case err: ib_status = ibstatus; break
\r
249 ib_api_status_t ib_status;
\r
257 MAP_NT_ERR( ENOENT, IB_NOT_FOUND );
\r
258 MAP_NT_ERR( EINTR, IB_INTERRUPTED );
\r
259 MAP_NT_ERR( EAGAIN, IB_RESOURCE_BUSY );
\r
260 MAP_NT_ERR( ENOMEM, IB_INSUFFICIENT_MEMORY );
\r
261 MAP_NT_ERR( EACCES, IB_INVALID_PERMISSION );
\r
262 MAP_NT_ERR( EFAULT, IB_ERROR );
\r
263 MAP_NT_ERR( EBUSY, IB_RESOURCE_BUSY );
\r
264 MAP_NT_ERR( ENODEV, IB_UNSUPPORTED );
\r
265 MAP_NT_ERR( EINVAL, IB_INVALID_PARAMETER );
\r
266 MAP_NT_ERR( ENOSYS, IB_UNSUPPORTED );
\r
267 MAP_NT_ERR( ERANGE, IB_INVALID_SETTING );
\r
269 //HCA_PRINT(TRACE_LEVEL_ERROR, HCA_DBG_SHIM,
\r
270 // "Unmapped errno (%d)\n", err);
\r
271 ib_status = IB_UNKNOWN_ERROR;
\r
277 static inline int start_port(struct ib_device *device)
\r
279 return device->node_type == RDMA_NODE_IB_SWITCH ? 0 : 1;
\r
282 static inline int end_port(struct ib_device *device)
\r
284 return device->node_type == RDMA_NODE_IB_SWITCH ? 0 : device->phys_port_cnt;
\r
287 #ifndef USE_WDM_FRAMEWORK
\r
289 ////////////////////////////////////////////////////////
\r
293 ////////////////////////////////////////////////////////
\r
295 DRIVER_INITIALIZE DriverEntry;
\r
299 IN WDFDRIVER Driver
\r
304 IN WDFDRIVER Driver,
\r
305 IN PWDFDEVICE_INIT Device
\r
310 IN WDFDEVICE Device,
\r
311 IN WDF_POWER_DEVICE_STATE PreviousState
\r
316 IN WDFDEVICE Device,
\r
317 IN WDF_POWER_DEVICE_STATE TargetState
\r
321 EvtPrepareHardware(
\r
322 IN WDFDEVICE Device,
\r
323 IN WDFCMRESLIST ResourcesRaw,
\r
324 IN WDFCMRESLIST ResourcesTranslated
\r
328 EvtReleaseHardware(
\r
329 IN WDFDEVICE Device,
\r
330 IN WDFCMRESLIST ResourcesTranslated
\r
335 // Implemented in wmi.c
\r
345 IN WDFWMIINSTANCE WmiInstance,
\r
346 IN ULONG DataItemId,
\r
347 IN ULONG InBufferSize,
\r
352 EvtStdDataSetInstance(
\r
353 IN WDFWMIINSTANCE WmiInstance,
\r
354 IN ULONG InBufferSize,
\r
359 EvtStdDataQueryInstance(
\r
360 IN WDFWMIINSTANCE WmiInstance,
\r
361 IN ULONG OutBufferSize,
\r
362 IN PVOID OutBuffer,
\r
363 OUT PULONG BufferUsed
\r