[MLTHCA] added polling mode support.
[mirror/winof/.git] / hw / mthca / kernel / hca_driver.h
1 /*\r
2  * Copyright (c) 2005 SilverStorm Technologies.  All rights reserved.\r
3  *\r
4  * This software is available to you under the OpenIB.org BSD license\r
5  * below:\r
6  *\r
7  *     Redistribution and use in source and binary forms, with or\r
8  *     without modification, are permitted provided that the following\r
9  *     conditions are met:\r
10  *\r
11  *      - Redistributions of source code must retain the above\r
12  *        copyright notice, this list of conditions and the following\r
13  *        disclaimer.\r
14  *\r
15  *      - Redistributions in binary form must reproduce the above\r
16  *        copyright notice, this list of conditions and the following\r
17  *        disclaimer in the documentation and/or other materials\r
18  *        provided with the distribution.\r
19  *\r
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
21  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
22  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
23  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS\r
24  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN\r
25  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
26  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
27  * SOFTWARE.\r
28  *\r
29  * $Id$\r
30  */\r
31 \r
32 \r
33 #if !defined( _HCA_DRIVER_H_ )\r
34 #define _HCA_DRIVER_H_\r
35 \r
36 \r
37 #include <complib/cl_types.h>\r
38 #include <complib/cl_pnp_po.h>\r
39 #include <complib/cl_mutex.h>\r
40 #include <iba/ib_ci_ifc.h>\r
41 #include "mthca/mthca_vc.h"\r
42 #include "hca_data.h"\r
43 #include "mt_l2w.h"\r
44 #include "hca_debug.h"\r
45 \r
46 \r
47 #include "hca_pnp.h"\r
48 #include "hca_pci.h"\r
49 \r
50 #if !defined(FILE_DEVICE_INFINIBAND) // Not defined in WXP DDK\r
51 #define FILE_DEVICE_INFINIBAND          0x0000003B\r
52 #endif\r
53 \r
54 /****s* HCA/hca_reg_state_t\r
55 * NAME\r
56 *       hca_reg_state_t\r
57 *\r
58 * DESCRIPTION\r
59 *       State for tracking registration with AL.  This state is independent of the\r
60 *       device PnP state, and both are used to properly register with AL.\r
61 *\r
62 * SYNOPSIS\r
63 */\r
64 typedef enum _hca_reg_state\r
65 {\r
66         HCA_SHUTDOWN,\r
67         HCA_ADDED,\r
68         HCA_STARTED,\r
69         HCA_IFC_DEREFERENCED,\r
70         HCA_REGISTERED\r
71 \r
72 }       hca_reg_state_t;\r
73 /*\r
74 * VALUES\r
75 *       HCA_SHUTDOWN\r
76 *               Cleaning up.\r
77 *\r
78 *       HCA_ADDED\r
79 *               AddDevice was called and successfully registered for interface\r
80 *               notifications.\r
81 *\r
82 *       HCA_STARTED\r
83 *               IRP_MN_START_DEVICE was called.  The HCA is fully functional.\r
84 *\r
85 *       HCA_IFC_DEREFERENCED\r
86 *               DEVICE_QUERY_REMOVE for IBBUS was received.\r
87 *\r
88 *       HCA_REGISTERED\r
89 *               Fully functional and registered with the bus root.\r
90 *********/\r
91 \r
92 \r
93 typedef enum _hca_bar_type\r
94 {\r
95         HCA_BAR_TYPE_HCR,\r
96         HCA_BAR_TYPE_UAR,\r
97         HCA_BAR_TYPE_DDR,\r
98         HCA_BAR_TYPE_MAX\r
99 \r
100 }       hca_bar_type_t;\r
101 \r
102 \r
103 typedef struct _hca_bar\r
104 {\r
105         uint64_t                        phys;\r
106         void                            *virt;\r
107         SIZE_T                          size;\r
108 \r
109 }       hca_bar_t;\r
110 \r
111 \r
112 typedef struct _hca_dev_ext\r
113 {\r
114         /* -------------------------------------------------\r
115         *               PNP DATA         \r
116         * ------------------------------------------------ */\r
117         cl_pnp_po_ext_t cl_ext;                                         /* COMPLIB PnP object */\r
118         void                                    *       pnp_ifc_entry;                  /* Notification entry for PnP interface events. */\r
119         void                                    *       pnp_target_entry;       /* Notification entry for PnP target events. */\r
120         PNP_DEVICE_STATE                        pnpState; /* state for PnP Manager */\r
121 \r
122         /* -------------------------------------------------\r
123         *               POWER MANAGER DATA       \r
124         * ------------------------------------------------ */\r
125         /* Cache of the system to device power states. */\r
126         DEVICE_POWER_STATE              DevicePower[PowerSystemMaximum];\r
127         DEVICE_POWER_STATE              DevicePowerState;\r
128         SYSTEM_POWER_STATE              SystemPowerState;\r
129         PIO_WORKITEM                    pPoWorkItem;\r
130 \r
131         /* -------------------------------------------------\r
132         *               IB_AL DATA       \r
133         * ------------------------------------------------ */\r
134         ib_ci_ifc_t                                                     ci_ifc;                         /* Interface for the lower edge of the IB_AL device. */\r
135         hca_reg_state_t                                 state;                          /* State for tracking registration with AL */\r
136         DEVICE_OBJECT                           *       p_al_dev;               /* IB_AL FDO */\r
137         FILE_OBJECT                                     *       p_al_file_obj;  /* IB_AL file object */\r
138         UNICODE_STRING                                  al_sym_name;    /* IB_AL symbolic name */\r
139 \r
140         /* -------------------------------------------------\r
141         *               LOW LEVEL DRIVER' DATA   \r
142         * ------------------------------------------------ */\r
143         mlnx_hca_t                                                      hca;\r
144         atomic32_t                                                              usecnt; /* the number of working applications*/\r
145         cl_spinlock_t                                                   uctx_lock;                      // spinlock for the below chain\r
146         cl_qlist_t                                                              uctx_list;                      // chain of user contexts\r
147 \r
148         /* -------------------------------------------------\r
149         *               OS DATA          \r
150         * ------------------------------------------------ */\r
151         hca_bar_t                                                       bar[HCA_BAR_TYPE_MAX];          /* HCA memory bars */\r
152         CM_PARTIAL_RESOURCE_DESCRIPTOR  interruptInfo;  /* HCA interrupt resources */\r
153         PKINTERRUPT                                             int_obj;                                                                                /* HCA interrupt object */\r
154         spinlock_t                                                      isr_lock;                                                                       /* lock for the ISR */\r
155         ULONG                                                                   bus_number;                                                     /* HCA's bus number */\r
156         BUS_INTERFACE_STANDARD                  hcaBusIfc;      /* PCI bus interface */\r
157 \r
158         /* -------------------------------------------------\r
159         *               VARIABLES        \r
160         * ------------------------------------------------ */\r
161         DMA_ADAPTER                             *       p_dma_adapter;          /* HCA adapter object */\r
162         ULONG                                                                   n_map_regs;                     /* num of allocated adapter map registers */\r
163         PCI_COMMON_CONFIG               hcaConfig;                              /* saved HCA PCI configuration header */\r
164         int                                                                             hca_hidden;                     /* flag: when set - no attached DDR memory */\r
165         \r
166 }       hca_dev_ext_t;\r
167 \r
168 #define EXT_FROM_HOB(hob_p)                     (container_of(hob_p,  hca_dev_ext_t, hca.hob))\r
169 #define HCA_FROM_HOB(hob_p)                     (container_of(hob_p,  mlnx_hca_t, hob))\r
170 #define MDEV_FROM_HOB(hob_p)            (HCA_FROM_HOB(hob_p)->mdev)\r
171 #define IBDEV_FROM_HOB(hob_p)           (&EXT_FROM_HOB(hob_p)->hca.mdev->ib_dev)\r
172 #define HOBUL_FROM_HOB(hob_p)           (&EXT_FROM_HOB(hob_p)->hca.hobul)\r
173 #define HOB_FROM_IBDEV(dev_p)           (mlnx_hob_t *)&dev_p->mdev->ext->hca.hob\r
174 \r
175 \r
176 #define IB_GET_ERR_STR  ib_dev->mdev->ext->ci_ifc.get_err_str\r
177 #if DBG || defined( EVENT_TRACING )\r
178 #define PREP_IBDEV_FOR_PRINT(val)       struct ib_device *ib_dev = val\r
179 #else\r
180 #define PREP_IBDEV_FOR_PRINT(val)\r
181 #endif\r
182 \r
183 /***********************************\r
184 Firmware Update definitions\r
185 ***********************************/\r
186 #define PCI_CONF_ADDR   (0x00000058)\r
187 #define PCI_CONF_DATA   (0x0000005c)\r
188 #define FLASH_OFFSET    (0x000f01a4)\r
189 #define READ_BIT                (1<<29)\r
190 #define WRITE_BIT               (2<<29)\r
191 #define ADDR_MSK                (0x0007ffff)\r
192 #define CMD_MASK                (0xe0000000)\r
193 #define BANK_SHIFT              (19)\r
194 #define BANK_MASK               (0xfff80000)\r
195 #define MAX_FLASH_SIZE  (0x80000) // 512K\r
196 \r
197 #define SEMAP63                         (0xf03fc)\r
198 #define GPIO_DIR_L                      (0xf008c)\r
199 #define GPIO_POL_L                      (0xf0094)\r
200 #define GPIO_MOD_L                      (0xf009c)\r
201 #define GPIO_DAT_L                      (0xf0084)\r
202 #define GPIO_DATACLEAR_L        (0xf00d4)\r
203 #define GPIO_DATASET_L          (0xf00dc)\r
204 \r
205 #define CPUMODE                         (0xf0150)\r
206 #define CPUMODE_MSK                     (0xc0000000UL)\r
207 #define CPUMODE_SHIFT           (30)\r
208 \r
209 /* Definitions intended to become shared with UM. Later... */\r
210 #define FW_READ                 0x00\r
211 #define FW_WRITE                0x01\r
212 #define FW_READ_CMD             0x08\r
213 #define FW_WRITE_CMD    0x09\r
214 #define FW_OPEN_IF              0xe7\r
215 #define FW_CLOSE_IF             0x7e\r
216 \r
217 #if 1//WORKAROUND_POLL_EQ\r
218 #define FW_POLL_EQ_START                0x0D\r
219 #define FW_POLL_EQ_STOP                 0x0E\r
220 #endif\r
221 \r
222 #define FW_SIGNATURE            (0x5a445a44)\r
223 #define FW_SECT_SIZE            (0x10000)\r
224 \r
225 static inline errno_to_iberr(int err)\r
226 {\r
227 #define MAP_ERR(err,ibstatus)   case err: ib_status = ibstatus; break\r
228         ib_api_status_t ib_status = IB_UNKNOWN_ERROR;\r
229         if (err < 0)\r
230                 err = -err;\r
231         switch (err) {\r
232                 MAP_ERR( ENOENT, IB_NOT_FOUND );\r
233                 MAP_ERR( EINTR, IB_INTERRUPTED );\r
234                 MAP_ERR( EAGAIN, IB_RESOURCE_BUSY );\r
235                 MAP_ERR( ENOMEM, IB_INSUFFICIENT_MEMORY );\r
236                 MAP_ERR( EACCES, IB_INVALID_PERMISSION );\r
237                 MAP_ERR( EFAULT, IB_ERROR );\r
238                 MAP_ERR( EBUSY, IB_RESOURCE_BUSY );\r
239                 MAP_ERR( ENODEV, IB_UNSUPPORTED );\r
240                 MAP_ERR( EINVAL, IB_INVALID_PARAMETER );\r
241                 MAP_ERR( ENOSYS, IB_UNSUPPORTED );\r
242                 MAP_ERR( ERANGE, IB_INVALID_SETTING );\r
243                 default:\r
244                         //HCA_PRINT(TRACE_LEVEL_ERROR, HCA_DBG_SHIM,\r
245                         //      "Unmapped errno (%d)\n", err);\r
246                         break;\r
247         }\r
248         return ib_status;\r
249 }\r
250 \r
251 #endif  /* !defined( _HCA_DRIVER_H_ ) */\r