blob: d8bb4418581b771ec6b98184265854e83579a80f [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.
Jack Morgenstein51a379d2008-07-25 10:32:52 -07005 * Copyright (c) 2005, 2006, 2007, 2008 Mellanox Technologies. All rights reserved.
Roland Dreier225c7b12007-05-08 18:00:38 -07006 * 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>
Thomas Gleixner31427882010-01-29 20:39:02 +000043#include <linux/semaphore.h>
Yevgeny Petrilin27bf91d2009-03-18 19:45:11 -070044#include <linux/workqueue.h>
Roland Dreier225c7b12007-05-08 18:00:38 -070045
46#include <linux/mlx4/device.h>
Roland Dreier37608ee2008-04-16 21:01:08 -070047#include <linux/mlx4/driver.h>
Roland Dreier225c7b12007-05-08 18:00:38 -070048#include <linux/mlx4/doorbell.h>
49
50#define DRV_NAME "mlx4_core"
Roland Dreier225c7b12007-05-08 18:00:38 -070051#define DRV_VERSION "0.01"
52#define DRV_RELDATE "May 1, 2007"
53
54enum {
55 MLX4_HCR_BASE = 0x80680,
56 MLX4_HCR_SIZE = 0x0001c,
57 MLX4_CLR_INT_SIZE = 0x00008
58};
59
60enum {
Jack Morgensteine57ac0c2007-10-02 09:40:13 +020061 MLX4_MGM_ENTRY_SIZE = 0x100,
Roland Dreier225c7b12007-05-08 18:00:38 -070062 MLX4_QP_PER_MGM = 4 * (MLX4_MGM_ENTRY_SIZE / 16 - 2),
63 MLX4_MTT_ENTRY_PER_SEG = 8
64};
65
66enum {
Roland Dreier225c7b12007-05-08 18:00:38 -070067 MLX4_NUM_PDS = 1 << 15
68};
69
70enum {
71 MLX4_CMPT_TYPE_QP = 0,
72 MLX4_CMPT_TYPE_SRQ = 1,
73 MLX4_CMPT_TYPE_CQ = 2,
74 MLX4_CMPT_TYPE_EQ = 3,
75 MLX4_CMPT_NUM_TYPE
76};
77
78enum {
79 MLX4_CMPT_SHIFT = 24,
80 MLX4_NUM_CMPTS = MLX4_CMPT_NUM_TYPE << MLX4_CMPT_SHIFT
81};
82
83#ifdef CONFIG_MLX4_DEBUG
84extern int mlx4_debug_level;
Roland Dreier7b0f5df2008-11-04 11:18:56 -080085#else /* CONFIG_MLX4_DEBUG */
86#define mlx4_debug_level (0)
87#endif /* CONFIG_MLX4_DEBUG */
Roland Dreier225c7b12007-05-08 18:00:38 -070088
89#define mlx4_dbg(mdev, format, arg...) \
Joe Perches0a645e82010-07-10 07:22:46 +000090do { \
91 if (mlx4_debug_level) \
92 dev_printk(KERN_DEBUG, &mdev->pdev->dev, format, ##arg); \
93} while (0)
Roland Dreier225c7b12007-05-08 18:00:38 -070094
Roland Dreier225c7b12007-05-08 18:00:38 -070095#define mlx4_err(mdev, format, arg...) \
Joe Perches0a645e82010-07-10 07:22:46 +000096 dev_err(&mdev->pdev->dev, format, ##arg)
Roland Dreier225c7b12007-05-08 18:00:38 -070097#define mlx4_info(mdev, format, arg...) \
Joe Perches0a645e82010-07-10 07:22:46 +000098 dev_info(&mdev->pdev->dev, format, ##arg)
Roland Dreier225c7b12007-05-08 18:00:38 -070099#define mlx4_warn(mdev, format, arg...) \
Joe Perches0a645e82010-07-10 07:22:46 +0000100 dev_warn(&mdev->pdev->dev, format, ##arg)
Roland Dreier225c7b12007-05-08 18:00:38 -0700101
102struct mlx4_bitmap {
103 u32 last;
104 u32 top;
105 u32 max;
Yevgeny Petrilin93fc9e12008-10-22 10:25:29 -0700106 u32 reserved_top;
Roland Dreier225c7b12007-05-08 18:00:38 -0700107 u32 mask;
108 spinlock_t lock;
109 unsigned long *table;
110};
111
112struct mlx4_buddy {
113 unsigned long **bits;
Roland Dreiere4044cf2008-07-22 14:19:40 -0700114 unsigned int *num_free;
Roland Dreier225c7b12007-05-08 18:00:38 -0700115 int max_order;
116 spinlock_t lock;
117};
118
119struct mlx4_icm;
120
121struct mlx4_icm_table {
122 u64 virt;
123 int num_icm;
124 int num_obj;
125 int obj_size;
126 int lowmem;
Jack Morgenstein5b0bf5e2007-08-01 12:28:20 +0300127 int coherent;
Roland Dreier225c7b12007-05-08 18:00:38 -0700128 struct mutex mutex;
129 struct mlx4_icm **icm;
130};
131
132struct mlx4_eq {
133 struct mlx4_dev *dev;
134 void __iomem *doorbell;
135 int eqn;
136 u32 cons_index;
137 u16 irq;
138 u16 have_irq;
139 int nent;
140 struct mlx4_buf_list *page_list;
141 struct mlx4_mtt mtt;
142};
143
144struct mlx4_profile {
145 int num_qp;
146 int rdmarc_per_qp;
147 int num_srq;
148 int num_cq;
149 int num_mcg;
150 int num_mpt;
151 int num_mtt;
152};
153
154struct mlx4_fw {
155 u64 clr_int_base;
156 u64 catas_offset;
157 struct mlx4_icm *fw_icm;
158 struct mlx4_icm *aux_icm;
159 u32 catas_size;
160 u16 fw_pages;
161 u8 clr_int_bar;
162 u8 catas_bar;
163};
164
Yevgeny Petrilinb12d93d2011-03-22 22:38:24 +0000165#define MGM_QPN_MASK 0x00FFFFFF
166#define MGM_BLCK_LB_BIT 30
167
168struct mlx4_promisc_qp {
169 struct list_head list;
170 u32 qpn;
171};
172
173struct mlx4_steer_index {
174 struct list_head list;
175 unsigned int index;
176 struct list_head duplicates;
177};
178
179struct mlx4_mgm {
180 __be32 next_gid_index;
181 __be32 members_count;
182 u32 reserved[2];
183 u8 gid[16];
184 __be32 qp[MLX4_QP_PER_MGM];
185};
Roland Dreier225c7b12007-05-08 18:00:38 -0700186struct mlx4_cmd {
187 struct pci_pool *pool;
188 void __iomem *hcr;
189 struct mutex hcr_mutex;
190 struct semaphore poll_sem;
191 struct semaphore event_sem;
192 int max_cmds;
193 spinlock_t context_lock;
194 int free_head;
195 struct mlx4_cmd_context *context;
196 u16 token_mask;
197 u8 use_events;
198 u8 toggle;
199};
200
201struct mlx4_uar_table {
202 struct mlx4_bitmap bitmap;
203};
204
205struct mlx4_mr_table {
206 struct mlx4_bitmap mpt_bitmap;
207 struct mlx4_buddy mtt_buddy;
208 u64 mtt_base;
209 u64 mpt_base;
210 struct mlx4_icm_table mtt_table;
211 struct mlx4_icm_table dmpt_table;
212};
213
214struct mlx4_cq_table {
215 struct mlx4_bitmap bitmap;
216 spinlock_t lock;
217 struct radix_tree_root tree;
218 struct mlx4_icm_table table;
219 struct mlx4_icm_table cmpt_table;
220};
221
222struct mlx4_eq_table {
223 struct mlx4_bitmap bitmap;
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -0800224 char *irq_names;
Roland Dreier225c7b12007-05-08 18:00:38 -0700225 void __iomem *clr_int;
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -0800226 void __iomem **uar_map;
Roland Dreier225c7b12007-05-08 18:00:38 -0700227 u32 clr_mask;
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -0800228 struct mlx4_eq *eq;
Roland Dreierfa0681d2009-09-05 20:24:49 -0700229 struct mlx4_icm_table table;
Roland Dreier225c7b12007-05-08 18:00:38 -0700230 struct mlx4_icm_table cmpt_table;
231 int have_irq;
232 u8 inta_pin;
233};
234
235struct mlx4_srq_table {
236 struct mlx4_bitmap bitmap;
237 spinlock_t lock;
238 struct radix_tree_root tree;
239 struct mlx4_icm_table table;
240 struct mlx4_icm_table cmpt_table;
241};
242
243struct mlx4_qp_table {
244 struct mlx4_bitmap bitmap;
245 u32 rdmarc_base;
246 int rdmarc_shift;
247 spinlock_t lock;
248 struct mlx4_icm_table qp_table;
249 struct mlx4_icm_table auxc_table;
250 struct mlx4_icm_table altc_table;
251 struct mlx4_icm_table rdmarc_table;
252 struct mlx4_icm_table cmpt_table;
253};
254
255struct mlx4_mcg_table {
256 struct mutex mutex;
257 struct mlx4_bitmap bitmap;
258 struct mlx4_icm_table table;
259};
260
261struct mlx4_catas_err {
262 u32 __iomem *map;
Jack Morgensteinee49bd92007-07-12 17:50:45 +0300263 struct timer_list timer;
264 struct list_head list;
Roland Dreier225c7b12007-05-08 18:00:38 -0700265};
266
Yevgeny Petrilin2a2336f2008-10-22 11:44:46 -0700267#define MLX4_MAX_MAC_NUM 128
268#define MLX4_MAC_TABLE_SIZE (MLX4_MAX_MAC_NUM << 3)
269
270struct mlx4_mac_table {
271 __be64 entries[MLX4_MAX_MAC_NUM];
272 int refs[MLX4_MAX_MAC_NUM];
273 struct mutex mutex;
274 int total;
275 int max;
276};
277
278#define MLX4_MAX_VLAN_NUM 128
279#define MLX4_VLAN_TABLE_SIZE (MLX4_MAX_VLAN_NUM << 2)
280
281struct mlx4_vlan_table {
282 __be32 entries[MLX4_MAX_VLAN_NUM];
283 int refs[MLX4_MAX_VLAN_NUM];
284 struct mutex mutex;
285 int total;
286 int max;
287};
288
Yevgeny Petrilin16792002011-03-22 22:38:31 +0000289struct mlx4_mac_entry {
290 u64 mac;
291};
292
Yevgeny Petrilin2a2336f2008-10-22 11:44:46 -0700293struct mlx4_port_info {
294 struct mlx4_dev *dev;
295 int port;
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -0700296 char dev_name[16];
297 struct device_attribute port_attr;
298 enum mlx4_port_type tmp_type;
Yevgeny Petrilin2a2336f2008-10-22 11:44:46 -0700299 struct mlx4_mac_table mac_table;
Yevgeny Petrilin16792002011-03-22 22:38:31 +0000300 struct radix_tree_root mac_tree;
Yevgeny Petrilin2a2336f2008-10-22 11:44:46 -0700301 struct mlx4_vlan_table vlan_table;
Yevgeny Petrilin16792002011-03-22 22:38:31 +0000302 int base_qpn;
Yevgeny Petrilin2a2336f2008-10-22 11:44:46 -0700303};
304
Yevgeny Petrilin27bf91d2009-03-18 19:45:11 -0700305struct mlx4_sense {
306 struct mlx4_dev *dev;
307 u8 do_sense_port[MLX4_MAX_PORTS + 1];
308 u8 sense_allowed[MLX4_MAX_PORTS + 1];
309 struct delayed_work sense_poll;
310};
311
Yevgeny Petrilin0b7ca5a2011-03-22 22:37:47 +0000312struct mlx4_msix_ctl {
313 u64 pool_bm;
314 spinlock_t pool_lock;
315};
316
Yevgeny Petrilinb12d93d2011-03-22 22:38:24 +0000317struct mlx4_steer {
318 struct list_head promisc_qps[MLX4_NUM_STEERS];
319 struct list_head steer_entries[MLX4_NUM_STEERS];
320 struct list_head high_prios;
321};
322
Roland Dreier225c7b12007-05-08 18:00:38 -0700323struct mlx4_priv {
324 struct mlx4_dev dev;
325
326 struct list_head dev_list;
327 struct list_head ctx_list;
328 spinlock_t ctx_lock;
329
Yevgeny Petrilin62968832008-04-23 11:55:45 -0700330 struct list_head pgdir_list;
331 struct mutex pgdir_mutex;
332
Roland Dreier225c7b12007-05-08 18:00:38 -0700333 struct mlx4_fw fw;
334 struct mlx4_cmd cmd;
335
336 struct mlx4_bitmap pd_bitmap;
337 struct mlx4_uar_table uar_table;
338 struct mlx4_mr_table mr_table;
339 struct mlx4_cq_table cq_table;
340 struct mlx4_eq_table eq_table;
341 struct mlx4_srq_table srq_table;
342 struct mlx4_qp_table qp_table;
343 struct mlx4_mcg_table mcg_table;
344
345 struct mlx4_catas_err catas_err;
346
347 void __iomem *clr_base;
348
349 struct mlx4_uar driver_uar;
350 void __iomem *kar;
Yevgeny Petrilin2a2336f2008-10-22 11:44:46 -0700351 struct mlx4_port_info port[MLX4_MAX_PORTS + 1];
Yevgeny Petrilin27bf91d2009-03-18 19:45:11 -0700352 struct mlx4_sense sense;
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -0700353 struct mutex port_mutex;
Yevgeny Petrilin0b7ca5a2011-03-22 22:37:47 +0000354 struct mlx4_msix_ctl msix_ctl;
Yevgeny Petrilinb12d93d2011-03-22 22:38:24 +0000355 struct mlx4_steer *steer;
Roland Dreier225c7b12007-05-08 18:00:38 -0700356};
357
358static inline struct mlx4_priv *mlx4_priv(struct mlx4_dev *dev)
359{
360 return container_of(dev, struct mlx4_priv, dev);
361}
362
Yevgeny Petrilin27bf91d2009-03-18 19:45:11 -0700363#define MLX4_SENSE_RANGE (HZ * 3)
364
365extern struct workqueue_struct *mlx4_wq;
366
Roland Dreier225c7b12007-05-08 18:00:38 -0700367u32 mlx4_bitmap_alloc(struct mlx4_bitmap *bitmap);
368void mlx4_bitmap_free(struct mlx4_bitmap *bitmap, u32 obj);
Yevgeny Petrilina3cdcbf2008-10-10 12:01:37 -0700369u32 mlx4_bitmap_alloc_range(struct mlx4_bitmap *bitmap, int cnt, int align);
370void mlx4_bitmap_free_range(struct mlx4_bitmap *bitmap, u32 obj, int cnt);
Yevgeny Petrilin93fc9e12008-10-22 10:25:29 -0700371int mlx4_bitmap_init(struct mlx4_bitmap *bitmap, u32 num, u32 mask,
372 u32 reserved_bot, u32 resetrved_top);
Roland Dreier225c7b12007-05-08 18:00:38 -0700373void mlx4_bitmap_cleanup(struct mlx4_bitmap *bitmap);
374
375int mlx4_reset(struct mlx4_dev *dev);
376
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -0800377int mlx4_alloc_eq_table(struct mlx4_dev *dev);
378void mlx4_free_eq_table(struct mlx4_dev *dev);
379
Roland Dreier225c7b12007-05-08 18:00:38 -0700380int mlx4_init_pd_table(struct mlx4_dev *dev);
381int mlx4_init_uar_table(struct mlx4_dev *dev);
382int mlx4_init_mr_table(struct mlx4_dev *dev);
383int mlx4_init_eq_table(struct mlx4_dev *dev);
384int mlx4_init_cq_table(struct mlx4_dev *dev);
385int mlx4_init_qp_table(struct mlx4_dev *dev);
386int mlx4_init_srq_table(struct mlx4_dev *dev);
387int mlx4_init_mcg_table(struct mlx4_dev *dev);
388
389void mlx4_cleanup_pd_table(struct mlx4_dev *dev);
390void mlx4_cleanup_uar_table(struct mlx4_dev *dev);
391void mlx4_cleanup_mr_table(struct mlx4_dev *dev);
392void mlx4_cleanup_eq_table(struct mlx4_dev *dev);
393void mlx4_cleanup_cq_table(struct mlx4_dev *dev);
394void mlx4_cleanup_qp_table(struct mlx4_dev *dev);
395void mlx4_cleanup_srq_table(struct mlx4_dev *dev);
396void mlx4_cleanup_mcg_table(struct mlx4_dev *dev);
397
Jack Morgensteinee49bd92007-07-12 17:50:45 +0300398void mlx4_start_catas_poll(struct mlx4_dev *dev);
399void mlx4_stop_catas_poll(struct mlx4_dev *dev);
Yevgeny Petrilin27bf91d2009-03-18 19:45:11 -0700400void mlx4_catas_init(void);
Jack Morgensteinee49bd92007-07-12 17:50:45 +0300401int mlx4_restart_one(struct pci_dev *pdev);
Roland Dreier225c7b12007-05-08 18:00:38 -0700402int mlx4_register_device(struct mlx4_dev *dev);
403void mlx4_unregister_device(struct mlx4_dev *dev);
Roland Dreier37608ee2008-04-16 21:01:08 -0700404void mlx4_dispatch_event(struct mlx4_dev *dev, enum mlx4_dev_event type, int port);
Roland Dreier225c7b12007-05-08 18:00:38 -0700405
406struct mlx4_dev_cap;
407struct mlx4_init_hca_param;
408
409u64 mlx4_make_profile(struct mlx4_dev *dev,
410 struct mlx4_profile *request,
411 struct mlx4_dev_cap *dev_cap,
412 struct mlx4_init_hca_param *init_hca);
413
Roland Dreier225c7b12007-05-08 18:00:38 -0700414int mlx4_cmd_init(struct mlx4_dev *dev);
415void mlx4_cmd_cleanup(struct mlx4_dev *dev);
416void mlx4_cmd_event(struct mlx4_dev *dev, u16 token, u8 status, u64 out_param);
417int mlx4_cmd_use_events(struct mlx4_dev *dev);
418void mlx4_cmd_use_polling(struct mlx4_dev *dev);
419
420void mlx4_cq_completion(struct mlx4_dev *dev, u32 cqn);
421void mlx4_cq_event(struct mlx4_dev *dev, u32 cqn, int event_type);
422
423void mlx4_qp_event(struct mlx4_dev *dev, u32 qpn, int event_type);
424
425void mlx4_srq_event(struct mlx4_dev *dev, u32 srqn, int event_type);
426
427void mlx4_handle_catas_err(struct mlx4_dev *dev);
428
Yevgeny Petrilin27bf91d2009-03-18 19:45:11 -0700429void mlx4_do_sense_ports(struct mlx4_dev *dev,
430 enum mlx4_port_type *stype,
431 enum mlx4_port_type *defaults);
432void mlx4_start_sense(struct mlx4_dev *dev);
433void mlx4_stop_sense(struct mlx4_dev *dev);
434void mlx4_sense_init(struct mlx4_dev *dev);
435int mlx4_check_port_params(struct mlx4_dev *dev,
436 enum mlx4_port_type *port_type);
437int mlx4_change_port_types(struct mlx4_dev *dev,
438 enum mlx4_port_type *port_types);
439
Yevgeny Petrilin2a2336f2008-10-22 11:44:46 -0700440void mlx4_init_mac_table(struct mlx4_dev *dev, struct mlx4_mac_table *table);
441void mlx4_init_vlan_table(struct mlx4_dev *dev, struct mlx4_vlan_table *table);
442
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -0700443int mlx4_SET_PORT(struct mlx4_dev *dev, u8 port);
Jack Morgenstein9a5aa622008-11-28 21:29:46 -0800444int mlx4_get_port_ib_caps(struct mlx4_dev *dev, u8 port, __be32 *caps);
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -0700445
Yevgeny Petrilinb12d93d2011-03-22 22:38:24 +0000446int mlx4_qp_detach_common(struct mlx4_dev *dev, struct mlx4_qp *qp, u8 gid[16],
447 enum mlx4_protocol prot, enum mlx4_steer_type steer);
448int mlx4_qp_attach_common(struct mlx4_dev *dev, struct mlx4_qp *qp, u8 gid[16],
449 int block_mcast_loopback, enum mlx4_protocol prot,
450 enum mlx4_steer_type steer);
Roland Dreier225c7b12007-05-08 18:00:38 -0700451#endif /* MLX4_H */