blob: a4023c2dd05092762ba3f8be32ef9fac5b1a7652 [file] [log] [blame]
Roland Dreier225c7b12007-05-08 18:00:38 -07001/*
2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
4 * Copyright (c) 2005, 2006, 2007 Cisco Systems. All rights reserved.
5 * Copyright (c) 2005 Mellanox Technologies. All rights reserved.
6 * Copyright (c) 2004 Voltaire, Inc. All rights reserved.
7 *
8 * This software is available to you under a choice of one of two
9 * licenses. You may choose to be licensed under the terms of the GNU
10 * General Public License (GPL) Version 2, available from the file
11 * COPYING in the main directory of this source tree, or the
12 * OpenIB.org BSD license below:
13 *
14 * Redistribution and use in source and binary forms, with or
15 * without modification, are permitted provided that the following
16 * conditions are met:
17 *
18 * - Redistributions of source code must retain the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer.
21 *
22 * - Redistributions in binary form must reproduce the above
23 * copyright notice, this list of conditions and the following
24 * disclaimer in the documentation and/or other materials
25 * provided with the distribution.
26 *
27 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
28 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
29 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
30 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
31 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
32 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
33 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
34 * SOFTWARE.
35 */
36
37#ifndef MLX4_H
38#define MLX4_H
39
Michael S. Tsirkin525f5f42007-07-09 20:12:20 -070040#include <linux/mutex.h>
Roland Dreier225c7b12007-05-08 18:00:38 -070041#include <linux/radix-tree.h>
Jack Morgensteinee49bd92007-07-12 17:50:45 +030042#include <linux/timer.h>
Roland Dreier225c7b12007-05-08 18:00:38 -070043
44#include <linux/mlx4/device.h>
Roland Dreier37608ee2008-04-16 21:01:08 -070045#include <linux/mlx4/driver.h>
Roland Dreier225c7b12007-05-08 18:00:38 -070046#include <linux/mlx4/doorbell.h>
47
48#define DRV_NAME "mlx4_core"
49#define PFX DRV_NAME ": "
50#define DRV_VERSION "0.01"
51#define DRV_RELDATE "May 1, 2007"
52
53enum {
54 MLX4_HCR_BASE = 0x80680,
55 MLX4_HCR_SIZE = 0x0001c,
56 MLX4_CLR_INT_SIZE = 0x00008
57};
58
59enum {
Jack Morgensteine57ac0c2007-10-02 09:40:13 +020060 MLX4_MGM_ENTRY_SIZE = 0x100,
Roland Dreier225c7b12007-05-08 18:00:38 -070061 MLX4_QP_PER_MGM = 4 * (MLX4_MGM_ENTRY_SIZE / 16 - 2),
62 MLX4_MTT_ENTRY_PER_SEG = 8
63};
64
65enum {
66 MLX4_EQ_ASYNC,
67 MLX4_EQ_COMP,
Roland Dreier225c7b12007-05-08 18:00:38 -070068 MLX4_NUM_EQ
69};
70
71enum {
72 MLX4_NUM_PDS = 1 << 15
73};
74
75enum {
76 MLX4_CMPT_TYPE_QP = 0,
77 MLX4_CMPT_TYPE_SRQ = 1,
78 MLX4_CMPT_TYPE_CQ = 2,
79 MLX4_CMPT_TYPE_EQ = 3,
80 MLX4_CMPT_NUM_TYPE
81};
82
83enum {
84 MLX4_CMPT_SHIFT = 24,
85 MLX4_NUM_CMPTS = MLX4_CMPT_NUM_TYPE << MLX4_CMPT_SHIFT
86};
87
88#ifdef CONFIG_MLX4_DEBUG
89extern int mlx4_debug_level;
90
91#define mlx4_dbg(mdev, format, arg...) \
92 do { \
93 if (mlx4_debug_level) \
94 dev_printk(KERN_DEBUG, &mdev->pdev->dev, format, ## arg); \
95 } while (0)
96
97#else /* CONFIG_MLX4_DEBUG */
98
99#define mlx4_dbg(mdev, format, arg...) do { (void) mdev; } while (0)
100
101#endif /* CONFIG_MLX4_DEBUG */
102
103#define mlx4_err(mdev, format, arg...) \
104 dev_err(&mdev->pdev->dev, format, ## arg)
105#define mlx4_info(mdev, format, arg...) \
106 dev_info(&mdev->pdev->dev, format, ## arg)
107#define mlx4_warn(mdev, format, arg...) \
108 dev_warn(&mdev->pdev->dev, format, ## arg)
109
110struct mlx4_bitmap {
111 u32 last;
112 u32 top;
113 u32 max;
114 u32 mask;
115 spinlock_t lock;
116 unsigned long *table;
117};
118
119struct mlx4_buddy {
120 unsigned long **bits;
121 int max_order;
122 spinlock_t lock;
123};
124
125struct mlx4_icm;
126
127struct mlx4_icm_table {
128 u64 virt;
129 int num_icm;
130 int num_obj;
131 int obj_size;
132 int lowmem;
Jack Morgenstein5b0bf5e2007-08-01 12:28:20 +0300133 int coherent;
Roland Dreier225c7b12007-05-08 18:00:38 -0700134 struct mutex mutex;
135 struct mlx4_icm **icm;
136};
137
138struct mlx4_eq {
139 struct mlx4_dev *dev;
140 void __iomem *doorbell;
141 int eqn;
142 u32 cons_index;
143 u16 irq;
144 u16 have_irq;
145 int nent;
146 struct mlx4_buf_list *page_list;
147 struct mlx4_mtt mtt;
148};
149
150struct mlx4_profile {
151 int num_qp;
152 int rdmarc_per_qp;
153 int num_srq;
154 int num_cq;
155 int num_mcg;
156 int num_mpt;
157 int num_mtt;
158};
159
160struct mlx4_fw {
161 u64 clr_int_base;
162 u64 catas_offset;
163 struct mlx4_icm *fw_icm;
164 struct mlx4_icm *aux_icm;
165 u32 catas_size;
166 u16 fw_pages;
167 u8 clr_int_bar;
168 u8 catas_bar;
169};
170
171struct mlx4_cmd {
172 struct pci_pool *pool;
173 void __iomem *hcr;
174 struct mutex hcr_mutex;
175 struct semaphore poll_sem;
176 struct semaphore event_sem;
177 int max_cmds;
178 spinlock_t context_lock;
179 int free_head;
180 struct mlx4_cmd_context *context;
181 u16 token_mask;
182 u8 use_events;
183 u8 toggle;
184};
185
186struct mlx4_uar_table {
187 struct mlx4_bitmap bitmap;
188};
189
190struct mlx4_mr_table {
191 struct mlx4_bitmap mpt_bitmap;
192 struct mlx4_buddy mtt_buddy;
193 u64 mtt_base;
194 u64 mpt_base;
195 struct mlx4_icm_table mtt_table;
196 struct mlx4_icm_table dmpt_table;
197};
198
199struct mlx4_cq_table {
200 struct mlx4_bitmap bitmap;
201 spinlock_t lock;
202 struct radix_tree_root tree;
203 struct mlx4_icm_table table;
204 struct mlx4_icm_table cmpt_table;
205};
206
207struct mlx4_eq_table {
208 struct mlx4_bitmap bitmap;
209 void __iomem *clr_int;
210 void __iomem *uar_map[(MLX4_NUM_EQ + 6) / 4];
211 u32 clr_mask;
212 struct mlx4_eq eq[MLX4_NUM_EQ];
213 u64 icm_virt;
214 struct page *icm_page;
215 dma_addr_t icm_dma;
216 struct mlx4_icm_table cmpt_table;
217 int have_irq;
218 u8 inta_pin;
219};
220
221struct mlx4_srq_table {
222 struct mlx4_bitmap bitmap;
223 spinlock_t lock;
224 struct radix_tree_root tree;
225 struct mlx4_icm_table table;
226 struct mlx4_icm_table cmpt_table;
227};
228
229struct mlx4_qp_table {
230 struct mlx4_bitmap bitmap;
231 u32 rdmarc_base;
232 int rdmarc_shift;
233 spinlock_t lock;
234 struct mlx4_icm_table qp_table;
235 struct mlx4_icm_table auxc_table;
236 struct mlx4_icm_table altc_table;
237 struct mlx4_icm_table rdmarc_table;
238 struct mlx4_icm_table cmpt_table;
239};
240
241struct mlx4_mcg_table {
242 struct mutex mutex;
243 struct mlx4_bitmap bitmap;
244 struct mlx4_icm_table table;
245};
246
247struct mlx4_catas_err {
248 u32 __iomem *map;
Jack Morgensteinee49bd92007-07-12 17:50:45 +0300249 struct timer_list timer;
250 struct list_head list;
Roland Dreier225c7b12007-05-08 18:00:38 -0700251};
252
253struct mlx4_priv {
254 struct mlx4_dev dev;
255
256 struct list_head dev_list;
257 struct list_head ctx_list;
258 spinlock_t ctx_lock;
259
Yevgeny Petrilin62968832008-04-23 11:55:45 -0700260 struct list_head pgdir_list;
261 struct mutex pgdir_mutex;
262
Roland Dreier225c7b12007-05-08 18:00:38 -0700263 struct mlx4_fw fw;
264 struct mlx4_cmd cmd;
265
266 struct mlx4_bitmap pd_bitmap;
267 struct mlx4_uar_table uar_table;
268 struct mlx4_mr_table mr_table;
269 struct mlx4_cq_table cq_table;
270 struct mlx4_eq_table eq_table;
271 struct mlx4_srq_table srq_table;
272 struct mlx4_qp_table qp_table;
273 struct mlx4_mcg_table mcg_table;
274
275 struct mlx4_catas_err catas_err;
276
277 void __iomem *clr_base;
278
279 struct mlx4_uar driver_uar;
280 void __iomem *kar;
Roland Dreier225c7b12007-05-08 18:00:38 -0700281};
282
283static inline struct mlx4_priv *mlx4_priv(struct mlx4_dev *dev)
284{
285 return container_of(dev, struct mlx4_priv, dev);
286}
287
288u32 mlx4_bitmap_alloc(struct mlx4_bitmap *bitmap);
289void mlx4_bitmap_free(struct mlx4_bitmap *bitmap, u32 obj);
290int mlx4_bitmap_init(struct mlx4_bitmap *bitmap, u32 num, u32 mask, u32 reserved);
291void mlx4_bitmap_cleanup(struct mlx4_bitmap *bitmap);
292
293int mlx4_reset(struct mlx4_dev *dev);
294
295int mlx4_init_pd_table(struct mlx4_dev *dev);
296int mlx4_init_uar_table(struct mlx4_dev *dev);
297int mlx4_init_mr_table(struct mlx4_dev *dev);
298int mlx4_init_eq_table(struct mlx4_dev *dev);
299int mlx4_init_cq_table(struct mlx4_dev *dev);
300int mlx4_init_qp_table(struct mlx4_dev *dev);
301int mlx4_init_srq_table(struct mlx4_dev *dev);
302int mlx4_init_mcg_table(struct mlx4_dev *dev);
303
304void mlx4_cleanup_pd_table(struct mlx4_dev *dev);
305void mlx4_cleanup_uar_table(struct mlx4_dev *dev);
306void mlx4_cleanup_mr_table(struct mlx4_dev *dev);
307void mlx4_cleanup_eq_table(struct mlx4_dev *dev);
308void mlx4_cleanup_cq_table(struct mlx4_dev *dev);
309void mlx4_cleanup_qp_table(struct mlx4_dev *dev);
310void mlx4_cleanup_srq_table(struct mlx4_dev *dev);
311void mlx4_cleanup_mcg_table(struct mlx4_dev *dev);
312
Jack Morgensteinee49bd92007-07-12 17:50:45 +0300313void mlx4_start_catas_poll(struct mlx4_dev *dev);
314void mlx4_stop_catas_poll(struct mlx4_dev *dev);
315int mlx4_catas_init(void);
316void mlx4_catas_cleanup(void);
317int mlx4_restart_one(struct pci_dev *pdev);
Roland Dreier225c7b12007-05-08 18:00:38 -0700318int mlx4_register_device(struct mlx4_dev *dev);
319void mlx4_unregister_device(struct mlx4_dev *dev);
Roland Dreier37608ee2008-04-16 21:01:08 -0700320void mlx4_dispatch_event(struct mlx4_dev *dev, enum mlx4_dev_event type, int port);
Roland Dreier225c7b12007-05-08 18:00:38 -0700321
322struct mlx4_dev_cap;
323struct mlx4_init_hca_param;
324
325u64 mlx4_make_profile(struct mlx4_dev *dev,
326 struct mlx4_profile *request,
327 struct mlx4_dev_cap *dev_cap,
328 struct mlx4_init_hca_param *init_hca);
329
330int mlx4_map_eq_icm(struct mlx4_dev *dev, u64 icm_virt);
331void mlx4_unmap_eq_icm(struct mlx4_dev *dev);
332
333int mlx4_cmd_init(struct mlx4_dev *dev);
334void mlx4_cmd_cleanup(struct mlx4_dev *dev);
335void mlx4_cmd_event(struct mlx4_dev *dev, u16 token, u8 status, u64 out_param);
336int mlx4_cmd_use_events(struct mlx4_dev *dev);
337void mlx4_cmd_use_polling(struct mlx4_dev *dev);
338
339void mlx4_cq_completion(struct mlx4_dev *dev, u32 cqn);
340void mlx4_cq_event(struct mlx4_dev *dev, u32 cqn, int event_type);
341
342void mlx4_qp_event(struct mlx4_dev *dev, u32 qpn, int event_type);
343
344void mlx4_srq_event(struct mlx4_dev *dev, u32 srqn, int event_type);
345
346void mlx4_handle_catas_err(struct mlx4_dev *dev);
347
348#endif /* MLX4_H */