]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/net/mlx4/mlx4.h
IB/mlx4: Annotate CQ locking
[mirror_ubuntu-artful-kernel.git] / drivers / net / mlx4 / mlx4.h
CommitLineData
225c7b1f
RD
1/*
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.
51a379d0 5 * Copyright (c) 2005, 2006, 2007, 2008 Mellanox Technologies. All rights reserved.
225c7b1f
RD
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
525f5f44 40#include <linux/mutex.h>
225c7b1f 41#include <linux/radix-tree.h>
ee49bd93 42#include <linux/timer.h>
27bf91d6 43#include <linux/workqueue.h>
225c7b1f
RD
44
45#include <linux/mlx4/device.h>
37608eea 46#include <linux/mlx4/driver.h>
225c7b1f
RD
47#include <linux/mlx4/doorbell.h>
48
49#define DRV_NAME "mlx4_core"
50#define PFX DRV_NAME ": "
51#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
225c7b1f 60enum {
e57ac0c2 61 MLX4_MGM_ENTRY_SIZE = 0x100,
225c7b1f
RD
62 MLX4_QP_PER_MGM = 4 * (MLX4_MGM_ENTRY_SIZE / 16 - 2),
63 MLX4_MTT_ENTRY_PER_SEG = 8
64};
65
225c7b1f
RD
66enum {
67 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;
7b0f5df4
RD
85#else /* CONFIG_MLX4_DEBUG */
86#define mlx4_debug_level (0)
87#endif /* CONFIG_MLX4_DEBUG */
225c7b1f
RD
88
89#define mlx4_dbg(mdev, format, arg...) \
90 do { \
91 if (mlx4_debug_level) \
92 dev_printk(KERN_DEBUG, &mdev->pdev->dev, format, ## arg); \
93 } while (0)
94
225c7b1f
RD
95#define mlx4_err(mdev, format, arg...) \
96 dev_err(&mdev->pdev->dev, format, ## arg)
97#define mlx4_info(mdev, format, arg...) \
98 dev_info(&mdev->pdev->dev, format, ## arg)
99#define mlx4_warn(mdev, format, arg...) \
100 dev_warn(&mdev->pdev->dev, format, ## arg)
101
102struct mlx4_bitmap {
103 u32 last;
104 u32 top;
105 u32 max;
93fc9e1b 106 u32 reserved_top;
225c7b1f
RD
107 u32 mask;
108 spinlock_t lock;
109 unsigned long *table;
110};
111
112struct mlx4_buddy {
113 unsigned long **bits;
e4044cfc 114 unsigned int *num_free;
225c7b1f
RD
115 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;
5b0bf5e2 127 int coherent;
225c7b1f
RD
128 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
165struct mlx4_cmd {
166 struct pci_pool *pool;
167 void __iomem *hcr;
168 struct mutex hcr_mutex;
169 struct semaphore poll_sem;
170 struct semaphore event_sem;
171 int max_cmds;
172 spinlock_t context_lock;
173 int free_head;
174 struct mlx4_cmd_context *context;
175 u16 token_mask;
176 u8 use_events;
177 u8 toggle;
178};
179
180struct mlx4_uar_table {
181 struct mlx4_bitmap bitmap;
182};
183
184struct mlx4_mr_table {
185 struct mlx4_bitmap mpt_bitmap;
186 struct mlx4_buddy mtt_buddy;
187 u64 mtt_base;
188 u64 mpt_base;
189 struct mlx4_icm_table mtt_table;
190 struct mlx4_icm_table dmpt_table;
191};
192
193struct mlx4_cq_table {
194 struct mlx4_bitmap bitmap;
195 spinlock_t lock;
196 struct radix_tree_root tree;
197 struct mlx4_icm_table table;
198 struct mlx4_icm_table cmpt_table;
199};
200
201struct mlx4_eq_table {
202 struct mlx4_bitmap bitmap;
b8dd786f 203 char *irq_names;
225c7b1f 204 void __iomem *clr_int;
b8dd786f 205 void __iomem **uar_map;
225c7b1f 206 u32 clr_mask;
b8dd786f 207 struct mlx4_eq *eq;
225c7b1f
RD
208 u64 icm_virt;
209 struct page *icm_page;
210 dma_addr_t icm_dma;
211 struct mlx4_icm_table cmpt_table;
212 int have_irq;
213 u8 inta_pin;
214};
215
216struct mlx4_srq_table {
217 struct mlx4_bitmap bitmap;
218 spinlock_t lock;
219 struct radix_tree_root tree;
220 struct mlx4_icm_table table;
221 struct mlx4_icm_table cmpt_table;
222};
223
224struct mlx4_qp_table {
225 struct mlx4_bitmap bitmap;
226 u32 rdmarc_base;
227 int rdmarc_shift;
228 spinlock_t lock;
229 struct mlx4_icm_table qp_table;
230 struct mlx4_icm_table auxc_table;
231 struct mlx4_icm_table altc_table;
232 struct mlx4_icm_table rdmarc_table;
233 struct mlx4_icm_table cmpt_table;
234};
235
236struct mlx4_mcg_table {
237 struct mutex mutex;
238 struct mlx4_bitmap bitmap;
239 struct mlx4_icm_table table;
240};
241
242struct mlx4_catas_err {
243 u32 __iomem *map;
ee49bd93
JM
244 struct timer_list timer;
245 struct list_head list;
225c7b1f
RD
246};
247
2a2336f8
YP
248#define MLX4_MAX_MAC_NUM 128
249#define MLX4_MAC_TABLE_SIZE (MLX4_MAX_MAC_NUM << 3)
250
251struct mlx4_mac_table {
252 __be64 entries[MLX4_MAX_MAC_NUM];
253 int refs[MLX4_MAX_MAC_NUM];
254 struct mutex mutex;
255 int total;
256 int max;
257};
258
259#define MLX4_MAX_VLAN_NUM 128
260#define MLX4_VLAN_TABLE_SIZE (MLX4_MAX_VLAN_NUM << 2)
261
262struct mlx4_vlan_table {
263 __be32 entries[MLX4_MAX_VLAN_NUM];
264 int refs[MLX4_MAX_VLAN_NUM];
265 struct mutex mutex;
266 int total;
267 int max;
268};
269
270struct mlx4_port_info {
271 struct mlx4_dev *dev;
272 int port;
7ff93f8b
YP
273 char dev_name[16];
274 struct device_attribute port_attr;
275 enum mlx4_port_type tmp_type;
2a2336f8
YP
276 struct mlx4_mac_table mac_table;
277 struct mlx4_vlan_table vlan_table;
278};
279
27bf91d6
YP
280struct mlx4_sense {
281 struct mlx4_dev *dev;
282 u8 do_sense_port[MLX4_MAX_PORTS + 1];
283 u8 sense_allowed[MLX4_MAX_PORTS + 1];
284 struct delayed_work sense_poll;
285};
286
225c7b1f
RD
287struct mlx4_priv {
288 struct mlx4_dev dev;
289
290 struct list_head dev_list;
291 struct list_head ctx_list;
292 spinlock_t ctx_lock;
293
6296883c
YP
294 struct list_head pgdir_list;
295 struct mutex pgdir_mutex;
296
225c7b1f
RD
297 struct mlx4_fw fw;
298 struct mlx4_cmd cmd;
299
300 struct mlx4_bitmap pd_bitmap;
301 struct mlx4_uar_table uar_table;
302 struct mlx4_mr_table mr_table;
303 struct mlx4_cq_table cq_table;
304 struct mlx4_eq_table eq_table;
305 struct mlx4_srq_table srq_table;
306 struct mlx4_qp_table qp_table;
307 struct mlx4_mcg_table mcg_table;
308
309 struct mlx4_catas_err catas_err;
310
311 void __iomem *clr_base;
312
313 struct mlx4_uar driver_uar;
314 void __iomem *kar;
2a2336f8 315 struct mlx4_port_info port[MLX4_MAX_PORTS + 1];
27bf91d6 316 struct mlx4_sense sense;
7ff93f8b 317 struct mutex port_mutex;
225c7b1f
RD
318};
319
320static inline struct mlx4_priv *mlx4_priv(struct mlx4_dev *dev)
321{
322 return container_of(dev, struct mlx4_priv, dev);
323}
324
27bf91d6
YP
325#define MLX4_SENSE_RANGE (HZ * 3)
326
327extern struct workqueue_struct *mlx4_wq;
328
225c7b1f
RD
329u32 mlx4_bitmap_alloc(struct mlx4_bitmap *bitmap);
330void mlx4_bitmap_free(struct mlx4_bitmap *bitmap, u32 obj);
a3cdcbfa
YP
331u32 mlx4_bitmap_alloc_range(struct mlx4_bitmap *bitmap, int cnt, int align);
332void mlx4_bitmap_free_range(struct mlx4_bitmap *bitmap, u32 obj, int cnt);
93fc9e1b
YP
333int mlx4_bitmap_init(struct mlx4_bitmap *bitmap, u32 num, u32 mask,
334 u32 reserved_bot, u32 resetrved_top);
225c7b1f
RD
335void mlx4_bitmap_cleanup(struct mlx4_bitmap *bitmap);
336
337int mlx4_reset(struct mlx4_dev *dev);
338
b8dd786f
YP
339int mlx4_alloc_eq_table(struct mlx4_dev *dev);
340void mlx4_free_eq_table(struct mlx4_dev *dev);
341
225c7b1f
RD
342int mlx4_init_pd_table(struct mlx4_dev *dev);
343int mlx4_init_uar_table(struct mlx4_dev *dev);
344int mlx4_init_mr_table(struct mlx4_dev *dev);
345int mlx4_init_eq_table(struct mlx4_dev *dev);
346int mlx4_init_cq_table(struct mlx4_dev *dev);
347int mlx4_init_qp_table(struct mlx4_dev *dev);
348int mlx4_init_srq_table(struct mlx4_dev *dev);
349int mlx4_init_mcg_table(struct mlx4_dev *dev);
350
351void mlx4_cleanup_pd_table(struct mlx4_dev *dev);
352void mlx4_cleanup_uar_table(struct mlx4_dev *dev);
353void mlx4_cleanup_mr_table(struct mlx4_dev *dev);
354void mlx4_cleanup_eq_table(struct mlx4_dev *dev);
355void mlx4_cleanup_cq_table(struct mlx4_dev *dev);
356void mlx4_cleanup_qp_table(struct mlx4_dev *dev);
357void mlx4_cleanup_srq_table(struct mlx4_dev *dev);
358void mlx4_cleanup_mcg_table(struct mlx4_dev *dev);
359
ee49bd93
JM
360void mlx4_start_catas_poll(struct mlx4_dev *dev);
361void mlx4_stop_catas_poll(struct mlx4_dev *dev);
27bf91d6 362void mlx4_catas_init(void);
ee49bd93 363int mlx4_restart_one(struct pci_dev *pdev);
225c7b1f
RD
364int mlx4_register_device(struct mlx4_dev *dev);
365void mlx4_unregister_device(struct mlx4_dev *dev);
37608eea 366void mlx4_dispatch_event(struct mlx4_dev *dev, enum mlx4_dev_event type, int port);
225c7b1f
RD
367
368struct mlx4_dev_cap;
369struct mlx4_init_hca_param;
370
371u64 mlx4_make_profile(struct mlx4_dev *dev,
372 struct mlx4_profile *request,
373 struct mlx4_dev_cap *dev_cap,
374 struct mlx4_init_hca_param *init_hca);
375
376int mlx4_map_eq_icm(struct mlx4_dev *dev, u64 icm_virt);
377void mlx4_unmap_eq_icm(struct mlx4_dev *dev);
378
379int mlx4_cmd_init(struct mlx4_dev *dev);
380void mlx4_cmd_cleanup(struct mlx4_dev *dev);
381void mlx4_cmd_event(struct mlx4_dev *dev, u16 token, u8 status, u64 out_param);
382int mlx4_cmd_use_events(struct mlx4_dev *dev);
383void mlx4_cmd_use_polling(struct mlx4_dev *dev);
384
385void mlx4_cq_completion(struct mlx4_dev *dev, u32 cqn);
386void mlx4_cq_event(struct mlx4_dev *dev, u32 cqn, int event_type);
387
388void mlx4_qp_event(struct mlx4_dev *dev, u32 qpn, int event_type);
389
390void mlx4_srq_event(struct mlx4_dev *dev, u32 srqn, int event_type);
391
392void mlx4_handle_catas_err(struct mlx4_dev *dev);
393
27bf91d6
YP
394void mlx4_do_sense_ports(struct mlx4_dev *dev,
395 enum mlx4_port_type *stype,
396 enum mlx4_port_type *defaults);
397void mlx4_start_sense(struct mlx4_dev *dev);
398void mlx4_stop_sense(struct mlx4_dev *dev);
399void mlx4_sense_init(struct mlx4_dev *dev);
400int mlx4_check_port_params(struct mlx4_dev *dev,
401 enum mlx4_port_type *port_type);
402int mlx4_change_port_types(struct mlx4_dev *dev,
403 enum mlx4_port_type *port_types);
404
2a2336f8
YP
405void mlx4_init_mac_table(struct mlx4_dev *dev, struct mlx4_mac_table *table);
406void mlx4_init_vlan_table(struct mlx4_dev *dev, struct mlx4_vlan_table *table);
407
7ff93f8b 408int mlx4_SET_PORT(struct mlx4_dev *dev, u8 port);
9a5aa622 409int mlx4_get_port_ib_caps(struct mlx4_dev *dev, u8 port, __be32 *caps);
7ff93f8b 410
225c7b1f 411#endif /* MLX4_H */