blob: 13343e8849997d46b0b408e81b7b629f97be9528 [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"
51#define PFX DRV_NAME ": "
52#define DRV_VERSION "0.01"
53#define DRV_RELDATE "May 1, 2007"
54
55enum {
56 MLX4_HCR_BASE = 0x80680,
57 MLX4_HCR_SIZE = 0x0001c,
58 MLX4_CLR_INT_SIZE = 0x00008
59};
60
61enum {
Jack Morgensteine57ac0c2007-10-02 09:40:13 +020062 MLX4_MGM_ENTRY_SIZE = 0x100,
Roland Dreier225c7b12007-05-08 18:00:38 -070063 MLX4_QP_PER_MGM = 4 * (MLX4_MGM_ENTRY_SIZE / 16 - 2),
64 MLX4_MTT_ENTRY_PER_SEG = 8
65};
66
67enum {
Roland Dreier225c7b12007-05-08 18:00:38 -070068 MLX4_NUM_PDS = 1 << 15
69};
70
71enum {
72 MLX4_CMPT_TYPE_QP = 0,
73 MLX4_CMPT_TYPE_SRQ = 1,
74 MLX4_CMPT_TYPE_CQ = 2,
75 MLX4_CMPT_TYPE_EQ = 3,
76 MLX4_CMPT_NUM_TYPE
77};
78
79enum {
80 MLX4_CMPT_SHIFT = 24,
81 MLX4_NUM_CMPTS = MLX4_CMPT_NUM_TYPE << MLX4_CMPT_SHIFT
82};
83
84#ifdef CONFIG_MLX4_DEBUG
85extern int mlx4_debug_level;
Roland Dreier7b0f5df2008-11-04 11:18:56 -080086#else /* CONFIG_MLX4_DEBUG */
87#define mlx4_debug_level (0)
88#endif /* CONFIG_MLX4_DEBUG */
Roland Dreier225c7b12007-05-08 18:00:38 -070089
90#define mlx4_dbg(mdev, format, arg...) \
91 do { \
92 if (mlx4_debug_level) \
93 dev_printk(KERN_DEBUG, &mdev->pdev->dev, format, ## arg); \
94 } while (0)
95
Roland Dreier225c7b12007-05-08 18:00:38 -070096#define mlx4_err(mdev, format, arg...) \
97 dev_err(&mdev->pdev->dev, format, ## arg)
98#define mlx4_info(mdev, format, arg...) \
99 dev_info(&mdev->pdev->dev, format, ## arg)
100#define mlx4_warn(mdev, format, arg...) \
101 dev_warn(&mdev->pdev->dev, format, ## arg)
102
103struct mlx4_bitmap {
104 u32 last;
105 u32 top;
106 u32 max;
Yevgeny Petrilin93fc9e12008-10-22 10:25:29 -0700107 u32 reserved_top;
Roland Dreier225c7b12007-05-08 18:00:38 -0700108 u32 mask;
109 spinlock_t lock;
110 unsigned long *table;
111};
112
113struct mlx4_buddy {
114 unsigned long **bits;
Roland Dreiere4044cf2008-07-22 14:19:40 -0700115 unsigned int *num_free;
Roland Dreier225c7b12007-05-08 18:00:38 -0700116 int max_order;
117 spinlock_t lock;
118};
119
120struct mlx4_icm;
121
122struct mlx4_icm_table {
123 u64 virt;
124 int num_icm;
125 int num_obj;
126 int obj_size;
127 int lowmem;
Jack Morgenstein5b0bf5e2007-08-01 12:28:20 +0300128 int coherent;
Roland Dreier225c7b12007-05-08 18:00:38 -0700129 struct mutex mutex;
130 struct mlx4_icm **icm;
131};
132
133struct mlx4_eq {
134 struct mlx4_dev *dev;
135 void __iomem *doorbell;
136 int eqn;
137 u32 cons_index;
138 u16 irq;
139 u16 have_irq;
140 int nent;
141 struct mlx4_buf_list *page_list;
142 struct mlx4_mtt mtt;
143};
144
145struct mlx4_profile {
146 int num_qp;
147 int rdmarc_per_qp;
148 int num_srq;
149 int num_cq;
150 int num_mcg;
151 int num_mpt;
152 int num_mtt;
153};
154
155struct mlx4_fw {
156 u64 clr_int_base;
157 u64 catas_offset;
158 struct mlx4_icm *fw_icm;
159 struct mlx4_icm *aux_icm;
160 u32 catas_size;
161 u16 fw_pages;
162 u8 clr_int_bar;
163 u8 catas_bar;
164};
165
166struct mlx4_cmd {
167 struct pci_pool *pool;
168 void __iomem *hcr;
169 struct mutex hcr_mutex;
170 struct semaphore poll_sem;
171 struct semaphore event_sem;
172 int max_cmds;
173 spinlock_t context_lock;
174 int free_head;
175 struct mlx4_cmd_context *context;
176 u16 token_mask;
177 u8 use_events;
178 u8 toggle;
179};
180
181struct mlx4_uar_table {
182 struct mlx4_bitmap bitmap;
183};
184
185struct mlx4_mr_table {
186 struct mlx4_bitmap mpt_bitmap;
187 struct mlx4_buddy mtt_buddy;
188 u64 mtt_base;
189 u64 mpt_base;
190 struct mlx4_icm_table mtt_table;
191 struct mlx4_icm_table dmpt_table;
192};
193
194struct mlx4_cq_table {
195 struct mlx4_bitmap bitmap;
196 spinlock_t lock;
197 struct radix_tree_root tree;
198 struct mlx4_icm_table table;
199 struct mlx4_icm_table cmpt_table;
200};
201
202struct mlx4_eq_table {
203 struct mlx4_bitmap bitmap;
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -0800204 char *irq_names;
Roland Dreier225c7b12007-05-08 18:00:38 -0700205 void __iomem *clr_int;
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -0800206 void __iomem **uar_map;
Roland Dreier225c7b12007-05-08 18:00:38 -0700207 u32 clr_mask;
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -0800208 struct mlx4_eq *eq;
Roland Dreierfa0681d2009-09-05 20:24:49 -0700209 struct mlx4_icm_table table;
Roland Dreier225c7b12007-05-08 18:00:38 -0700210 struct mlx4_icm_table cmpt_table;
211 int have_irq;
212 u8 inta_pin;
213};
214
215struct mlx4_srq_table {
216 struct mlx4_bitmap bitmap;
217 spinlock_t lock;
218 struct radix_tree_root tree;
219 struct mlx4_icm_table table;
220 struct mlx4_icm_table cmpt_table;
221};
222
223struct mlx4_qp_table {
224 struct mlx4_bitmap bitmap;
225 u32 rdmarc_base;
226 int rdmarc_shift;
227 spinlock_t lock;
228 struct mlx4_icm_table qp_table;
229 struct mlx4_icm_table auxc_table;
230 struct mlx4_icm_table altc_table;
231 struct mlx4_icm_table rdmarc_table;
232 struct mlx4_icm_table cmpt_table;
233};
234
235struct mlx4_mcg_table {
236 struct mutex mutex;
237 struct mlx4_bitmap bitmap;
238 struct mlx4_icm_table table;
239};
240
241struct mlx4_catas_err {
242 u32 __iomem *map;
Jack Morgensteinee49bd92007-07-12 17:50:45 +0300243 struct timer_list timer;
244 struct list_head list;
Roland Dreier225c7b12007-05-08 18:00:38 -0700245};
246
Yevgeny Petrilin2a2336f2008-10-22 11:44:46 -0700247#define MLX4_MAX_MAC_NUM 128
248#define MLX4_MAC_TABLE_SIZE (MLX4_MAX_MAC_NUM << 3)
249
250struct mlx4_mac_table {
251 __be64 entries[MLX4_MAX_MAC_NUM];
252 int refs[MLX4_MAX_MAC_NUM];
253 struct mutex mutex;
254 int total;
255 int max;
256};
257
258#define MLX4_MAX_VLAN_NUM 128
259#define MLX4_VLAN_TABLE_SIZE (MLX4_MAX_VLAN_NUM << 2)
260
261struct mlx4_vlan_table {
262 __be32 entries[MLX4_MAX_VLAN_NUM];
263 int refs[MLX4_MAX_VLAN_NUM];
264 struct mutex mutex;
265 int total;
266 int max;
267};
268
269struct mlx4_port_info {
270 struct mlx4_dev *dev;
271 int port;
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -0700272 char dev_name[16];
273 struct device_attribute port_attr;
274 enum mlx4_port_type tmp_type;
Yevgeny Petrilin2a2336f2008-10-22 11:44:46 -0700275 struct mlx4_mac_table mac_table;
276 struct mlx4_vlan_table vlan_table;
277};
278
Yevgeny Petrilin27bf91d2009-03-18 19:45:11 -0700279struct mlx4_sense {
280 struct mlx4_dev *dev;
281 u8 do_sense_port[MLX4_MAX_PORTS + 1];
282 u8 sense_allowed[MLX4_MAX_PORTS + 1];
283 struct delayed_work sense_poll;
284};
285
Roland Dreier225c7b12007-05-08 18:00:38 -0700286struct mlx4_priv {
287 struct mlx4_dev dev;
288
289 struct list_head dev_list;
290 struct list_head ctx_list;
291 spinlock_t ctx_lock;
292
Yevgeny Petrilin62968832008-04-23 11:55:45 -0700293 struct list_head pgdir_list;
294 struct mutex pgdir_mutex;
295
Roland Dreier225c7b12007-05-08 18:00:38 -0700296 struct mlx4_fw fw;
297 struct mlx4_cmd cmd;
298
299 struct mlx4_bitmap pd_bitmap;
300 struct mlx4_uar_table uar_table;
301 struct mlx4_mr_table mr_table;
302 struct mlx4_cq_table cq_table;
303 struct mlx4_eq_table eq_table;
304 struct mlx4_srq_table srq_table;
305 struct mlx4_qp_table qp_table;
306 struct mlx4_mcg_table mcg_table;
307
308 struct mlx4_catas_err catas_err;
309
310 void __iomem *clr_base;
311
312 struct mlx4_uar driver_uar;
313 void __iomem *kar;
Yevgeny Petrilin2a2336f2008-10-22 11:44:46 -0700314 struct mlx4_port_info port[MLX4_MAX_PORTS + 1];
Yevgeny Petrilin27bf91d2009-03-18 19:45:11 -0700315 struct mlx4_sense sense;
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -0700316 struct mutex port_mutex;
Roland Dreier225c7b12007-05-08 18:00:38 -0700317};
318
319static inline struct mlx4_priv *mlx4_priv(struct mlx4_dev *dev)
320{
321 return container_of(dev, struct mlx4_priv, dev);
322}
323
Yevgeny Petrilin27bf91d2009-03-18 19:45:11 -0700324#define MLX4_SENSE_RANGE (HZ * 3)
325
326extern struct workqueue_struct *mlx4_wq;
327
Roland Dreier225c7b12007-05-08 18:00:38 -0700328u32 mlx4_bitmap_alloc(struct mlx4_bitmap *bitmap);
329void mlx4_bitmap_free(struct mlx4_bitmap *bitmap, u32 obj);
Yevgeny Petrilina3cdcbf2008-10-10 12:01:37 -0700330u32 mlx4_bitmap_alloc_range(struct mlx4_bitmap *bitmap, int cnt, int align);
331void mlx4_bitmap_free_range(struct mlx4_bitmap *bitmap, u32 obj, int cnt);
Yevgeny Petrilin93fc9e12008-10-22 10:25:29 -0700332int mlx4_bitmap_init(struct mlx4_bitmap *bitmap, u32 num, u32 mask,
333 u32 reserved_bot, u32 resetrved_top);
Roland Dreier225c7b12007-05-08 18:00:38 -0700334void mlx4_bitmap_cleanup(struct mlx4_bitmap *bitmap);
335
336int mlx4_reset(struct mlx4_dev *dev);
337
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -0800338int mlx4_alloc_eq_table(struct mlx4_dev *dev);
339void mlx4_free_eq_table(struct mlx4_dev *dev);
340
Roland Dreier225c7b12007-05-08 18:00:38 -0700341int mlx4_init_pd_table(struct mlx4_dev *dev);
342int mlx4_init_uar_table(struct mlx4_dev *dev);
343int mlx4_init_mr_table(struct mlx4_dev *dev);
344int mlx4_init_eq_table(struct mlx4_dev *dev);
345int mlx4_init_cq_table(struct mlx4_dev *dev);
346int mlx4_init_qp_table(struct mlx4_dev *dev);
347int mlx4_init_srq_table(struct mlx4_dev *dev);
348int mlx4_init_mcg_table(struct mlx4_dev *dev);
349
350void mlx4_cleanup_pd_table(struct mlx4_dev *dev);
351void mlx4_cleanup_uar_table(struct mlx4_dev *dev);
352void mlx4_cleanup_mr_table(struct mlx4_dev *dev);
353void mlx4_cleanup_eq_table(struct mlx4_dev *dev);
354void mlx4_cleanup_cq_table(struct mlx4_dev *dev);
355void mlx4_cleanup_qp_table(struct mlx4_dev *dev);
356void mlx4_cleanup_srq_table(struct mlx4_dev *dev);
357void mlx4_cleanup_mcg_table(struct mlx4_dev *dev);
358
Jack Morgensteinee49bd92007-07-12 17:50:45 +0300359void mlx4_start_catas_poll(struct mlx4_dev *dev);
360void mlx4_stop_catas_poll(struct mlx4_dev *dev);
Yevgeny Petrilin27bf91d2009-03-18 19:45:11 -0700361void mlx4_catas_init(void);
Jack Morgensteinee49bd92007-07-12 17:50:45 +0300362int mlx4_restart_one(struct pci_dev *pdev);
Roland Dreier225c7b12007-05-08 18:00:38 -0700363int mlx4_register_device(struct mlx4_dev *dev);
364void mlx4_unregister_device(struct mlx4_dev *dev);
Roland Dreier37608ee2008-04-16 21:01:08 -0700365void mlx4_dispatch_event(struct mlx4_dev *dev, enum mlx4_dev_event type, int port);
Roland Dreier225c7b12007-05-08 18:00:38 -0700366
367struct mlx4_dev_cap;
368struct mlx4_init_hca_param;
369
370u64 mlx4_make_profile(struct mlx4_dev *dev,
371 struct mlx4_profile *request,
372 struct mlx4_dev_cap *dev_cap,
373 struct mlx4_init_hca_param *init_hca);
374
Roland Dreier225c7b12007-05-08 18:00:38 -0700375int mlx4_cmd_init(struct mlx4_dev *dev);
376void mlx4_cmd_cleanup(struct mlx4_dev *dev);
377void mlx4_cmd_event(struct mlx4_dev *dev, u16 token, u8 status, u64 out_param);
378int mlx4_cmd_use_events(struct mlx4_dev *dev);
379void mlx4_cmd_use_polling(struct mlx4_dev *dev);
380
381void mlx4_cq_completion(struct mlx4_dev *dev, u32 cqn);
382void mlx4_cq_event(struct mlx4_dev *dev, u32 cqn, int event_type);
383
384void mlx4_qp_event(struct mlx4_dev *dev, u32 qpn, int event_type);
385
386void mlx4_srq_event(struct mlx4_dev *dev, u32 srqn, int event_type);
387
388void mlx4_handle_catas_err(struct mlx4_dev *dev);
389
Yevgeny Petrilin27bf91d2009-03-18 19:45:11 -0700390void mlx4_do_sense_ports(struct mlx4_dev *dev,
391 enum mlx4_port_type *stype,
392 enum mlx4_port_type *defaults);
393void mlx4_start_sense(struct mlx4_dev *dev);
394void mlx4_stop_sense(struct mlx4_dev *dev);
395void mlx4_sense_init(struct mlx4_dev *dev);
396int mlx4_check_port_params(struct mlx4_dev *dev,
397 enum mlx4_port_type *port_type);
398int mlx4_change_port_types(struct mlx4_dev *dev,
399 enum mlx4_port_type *port_types);
400
Yevgeny Petrilin2a2336f2008-10-22 11:44:46 -0700401void mlx4_init_mac_table(struct mlx4_dev *dev, struct mlx4_mac_table *table);
402void mlx4_init_vlan_table(struct mlx4_dev *dev, struct mlx4_vlan_table *table);
403
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -0700404int mlx4_SET_PORT(struct mlx4_dev *dev, u8 port);
Jack Morgenstein9a5aa622008-11-28 21:29:46 -0800405int mlx4_get_port_ib_caps(struct mlx4_dev *dev, u8 port, __be32 *caps);
Yevgeny Petrilin7ff93f82008-10-22 15:38:42 -0700406
Roland Dreier225c7b12007-05-08 18:00:38 -0700407#endif /* MLX4_H */