]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - sys/ofed/drivers/net/mlx4/mlx4.h
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / sys / ofed / drivers / net / mlx4 / mlx4.h
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.
5  * Copyright (c) 2005, 2006, 2007, 2008 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
40 #include <linux/mutex.h>
41 #include <linux/radix-tree.h>
42 #include <linux/timer.h>
43 #include <linux/workqueue.h>
44
45 #include <linux/mlx4/device.h>
46 #include <linux/mlx4/driver.h>
47 #include <linux/mlx4/doorbell.h>
48
49 #define DRV_NAME        "mlx4_core"
50 #define PFX             DRV_NAME ": "
51 #define DRV_VERSION     "1.0-ofed1.5.2"
52 #define DRV_RELDATE     "August 4, 2010"
53
54 enum {
55         MLX4_HCR_BASE           = 0x80680,
56         MLX4_HCR_SIZE           = 0x0001c,
57         MLX4_CLR_INT_SIZE       = 0x00008
58 };
59
60 enum {
61         MLX4_MGM_ENTRY_SIZE     =  0x100,
62         MLX4_QP_PER_MGM         = 4 * (MLX4_MGM_ENTRY_SIZE / 16 - 2),
63         MLX4_MTT_ENTRY_PER_SEG  = 8
64 };
65
66 enum {
67         MLX4_NUM_PDS            = 1 << 15
68 };
69
70 enum {
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
78 enum {
79         MLX4_CMPT_SHIFT         = 24,
80         MLX4_NUM_CMPTS          = MLX4_CMPT_NUM_TYPE << MLX4_CMPT_SHIFT
81 };
82
83 #ifdef CONFIG_MLX4_DEBUG
84 extern int mlx4_debug_level;
85 #else /* CONFIG_MLX4_DEBUG */
86 #define mlx4_debug_level        (0)
87 #endif /* CONFIG_MLX4_DEBUG */
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
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
102 extern int mlx4_blck_lb;
103
104 struct mlx4_bitmap {
105         u32                     last;
106         u32                     top;
107         u32                     max;
108         u32                     reserved_top;
109         u32                     mask;
110         u32                     avail;
111         spinlock_t              lock;
112         unsigned long          *table;
113 };
114
115 struct mlx4_buddy {
116         unsigned long         **bits;
117         unsigned int           *num_free;
118         int                     max_order;
119         spinlock_t              lock;
120 };
121
122 struct mlx4_icm;
123
124 struct mlx4_icm_table {
125         u64                     virt;
126         int                     num_icm;
127         int                     num_obj;
128         int                     obj_size;
129         int                     lowmem;
130         int                     coherent;
131         struct mutex            mutex;
132         struct mlx4_icm       **icm;
133 };
134
135 struct mlx4_eq {
136         struct mlx4_dev        *dev;
137         void __iomem           *doorbell;
138         int                     eqn;
139         u32                     cons_index;
140         u16                     irq;
141         u16                     have_irq;
142         int                     nent;
143         int                     load;
144         struct mlx4_buf_list   *page_list;
145         struct mlx4_mtt         mtt;
146 };
147
148 struct mlx4_profile {
149         int                     num_qp;
150         int                     rdmarc_per_qp;
151         int                     num_srq;
152         int                     num_cq;
153         int                     num_mcg;
154         int                     num_mpt;
155         int                     num_mtt;
156 };
157
158 struct mlx4_fw {
159         u64                     clr_int_base;
160         u64                     catas_offset;
161         struct mlx4_icm        *fw_icm;
162         struct mlx4_icm        *aux_icm;
163         u32                     catas_size;
164         u16                     fw_pages;
165         u8                      clr_int_bar;
166         u8                      catas_bar;
167 };
168
169 struct mlx4_cmd {
170         struct pci_pool        *pool;
171         void __iomem           *hcr;
172         struct mutex            hcr_mutex;
173         struct semaphore        poll_sem;
174         struct semaphore        event_sem;
175         int                     max_cmds;
176         spinlock_t              context_lock;
177         int                     free_head;
178         struct mlx4_cmd_context *context;
179         u16                     token_mask;
180         u8                      use_events;
181         u8                      toggle;
182 };
183
184 struct mlx4_uar_table {
185         struct mlx4_bitmap      bitmap;
186 };
187
188 struct mlx4_mr_table {
189         struct mlx4_bitmap      mpt_bitmap;
190         struct mlx4_buddy       mtt_buddy;
191         u64                     mtt_base;
192         u64                     mpt_base;
193         struct mlx4_icm_table   mtt_table;
194         struct mlx4_icm_table   dmpt_table;
195 };
196
197 struct mlx4_cq_table {
198         struct mlx4_bitmap      bitmap;
199         spinlock_t              lock;
200         struct radix_tree_root  tree;
201         struct mlx4_icm_table   table;
202         struct mlx4_icm_table   cmpt_table;
203 };
204
205 struct mlx4_eq_table {
206         struct mlx4_bitmap      bitmap;
207         char                   *irq_names;
208         void __iomem           *clr_int;
209         void __iomem          **uar_map;
210         u32                     clr_mask;
211         struct mlx4_eq         *eq;
212         struct mlx4_icm_table   table;
213         struct mlx4_icm_table   cmpt_table;
214         int                     have_irq;
215         u8                      inta_pin;
216 };
217
218 struct mlx4_srq_table {
219         struct mlx4_bitmap      bitmap;
220         spinlock_t              lock;
221         struct mlx4_icm_table   table;
222         struct mlx4_icm_table   cmpt_table;
223 };
224
225 struct mlx4_qp_table {
226         struct mlx4_bitmap      bitmap;
227         u32                     rdmarc_base;
228         int                     rdmarc_shift;
229         spinlock_t              lock;
230         struct mlx4_icm_table   qp_table;
231         struct mlx4_icm_table   auxc_table;
232         struct mlx4_icm_table   altc_table;
233         struct mlx4_icm_table   rdmarc_table;
234         struct mlx4_icm_table   cmpt_table;
235 };
236
237 struct mlx4_mcg_table {
238         struct mutex            mutex;
239         struct mlx4_bitmap      bitmap;
240         struct mlx4_icm_table   table;
241 };
242
243 struct mlx4_catas_err {
244         u32 __iomem            *map;
245         struct timer_list       timer;
246         struct list_head        list;
247 };
248
249 #define MLX4_MAX_MAC_NUM        128
250 #define MLX4_MAC_TABLE_SIZE     (MLX4_MAX_MAC_NUM << 3)
251
252 struct mlx4_mac_table {
253         __be64                  entries[MLX4_MAX_MAC_NUM];
254         int                     refs[MLX4_MAX_MAC_NUM];
255         struct mutex            mutex;
256         int                     total;
257         int                     max;
258 };
259
260 #define MLX4_MAX_VLAN_NUM       128
261 #define MLX4_VLAN_TABLE_SIZE    (MLX4_MAX_VLAN_NUM << 2)
262
263 struct mlx4_vlan_table {
264         __be32                  entries[MLX4_MAX_VLAN_NUM];
265         int                     refs[MLX4_MAX_VLAN_NUM];
266         struct mutex            mutex;
267         int                     total;
268         int                     max;
269 };
270
271 struct mlx4_port_info {
272         struct mlx4_dev        *dev;
273         int                     port;
274         char                    dev_name[16];
275         struct device_attribute port_attr;
276         enum mlx4_port_type     tmp_type;
277         struct mlx4_mac_table   mac_table;
278         struct mlx4_vlan_table  vlan_table;
279 };
280
281 struct mlx4_sense {
282         struct mlx4_dev         *dev;
283         u8                      do_sense_port[MLX4_MAX_PORTS + 1];
284         u8                      sense_allowed[MLX4_MAX_PORTS + 1];
285         struct delayed_work     sense_poll;
286         struct workqueue_struct *sense_wq;
287         u32                     resched;
288 };
289
290 extern struct mutex drv_mutex;
291
292 struct mlx4_priv {
293         struct mlx4_dev         dev;
294
295         struct list_head        dev_list;
296         struct list_head        ctx_list;
297         spinlock_t              ctx_lock;
298
299         struct list_head        pgdir_list;
300         struct mutex            pgdir_mutex;
301
302         struct mlx4_fw          fw;
303         struct mlx4_cmd         cmd;
304
305         struct mlx4_bitmap      pd_bitmap;
306         struct mlx4_bitmap      xrcd_bitmap;
307         struct mlx4_uar_table   uar_table;
308         struct mlx4_mr_table    mr_table;
309         struct mlx4_cq_table    cq_table;
310         struct mlx4_eq_table    eq_table;
311         struct mlx4_srq_table   srq_table;
312         struct mlx4_qp_table    qp_table;
313         struct mlx4_mcg_table   mcg_table;
314         struct mlx4_bitmap      counters_bitmap;
315         struct list_head        bf_list;
316         struct mutex            bf_mutex;
317
318         struct mlx4_catas_err   catas_err;
319
320         void __iomem           *clr_base;
321
322         struct mlx4_uar         driver_uar;
323         void __iomem           *kar;
324         struct mlx4_port_info   port[MLX4_MAX_PORTS + 1];
325         struct device_attribute trigger_attr;
326         int                     trig;
327         int                     changed_ports;
328         struct mlx4_sense       sense;
329         struct mutex            port_mutex;
330         int                     iboe_counter_index[MLX4_MAX_PORTS];
331         struct io_mapping      *bf_mapping;
332 };
333
334 static inline struct mlx4_priv *mlx4_priv(struct mlx4_dev *dev)
335 {
336         return container_of(dev, struct mlx4_priv, dev);
337 }
338
339 #define MLX4_SENSE_RANGE        (HZ * 3)
340
341 extern struct workqueue_struct *mlx4_wq;
342
343 u32 mlx4_bitmap_alloc(struct mlx4_bitmap *bitmap);
344 void mlx4_bitmap_free(struct mlx4_bitmap *bitmap, u32 obj);
345 u32 mlx4_bitmap_alloc_range(struct mlx4_bitmap *bitmap, int cnt, int align);
346 void mlx4_bitmap_free_range(struct mlx4_bitmap *bitmap, u32 obj, int cnt);
347 u32 mlx4_bitmap_avail(struct mlx4_bitmap *bitmap);
348 int mlx4_bitmap_init(struct mlx4_bitmap *bitmap, u32 num, u32 mask,
349                      u32 reserved_bot, u32 resetrved_top);
350 void mlx4_bitmap_cleanup(struct mlx4_bitmap *bitmap);
351
352 int mlx4_reset(struct mlx4_dev *dev);
353
354 int mlx4_alloc_eq_table(struct mlx4_dev *dev);
355 void mlx4_free_eq_table(struct mlx4_dev *dev);
356
357 int mlx4_init_pd_table(struct mlx4_dev *dev);
358 int mlx4_init_xrcd_table(struct mlx4_dev *dev);
359 int mlx4_init_uar_table(struct mlx4_dev *dev);
360 int mlx4_init_mr_table(struct mlx4_dev *dev);
361 int mlx4_init_eq_table(struct mlx4_dev *dev);
362 int mlx4_init_cq_table(struct mlx4_dev *dev);
363 int mlx4_init_qp_table(struct mlx4_dev *dev);
364 int mlx4_init_srq_table(struct mlx4_dev *dev);
365 int mlx4_init_mcg_table(struct mlx4_dev *dev);
366
367 void mlx4_cleanup_pd_table(struct mlx4_dev *dev);
368 void mlx4_cleanup_uar_table(struct mlx4_dev *dev);
369 void mlx4_cleanup_mr_table(struct mlx4_dev *dev);
370 void mlx4_cleanup_eq_table(struct mlx4_dev *dev);
371 void mlx4_cleanup_cq_table(struct mlx4_dev *dev);
372 void mlx4_cleanup_qp_table(struct mlx4_dev *dev);
373 void mlx4_cleanup_srq_table(struct mlx4_dev *dev);
374 void mlx4_cleanup_mcg_table(struct mlx4_dev *dev);
375 void mlx4_cleanup_xrcd_table(struct mlx4_dev *dev);
376
377 void mlx4_start_catas_poll(struct mlx4_dev *dev);
378 void mlx4_stop_catas_poll(struct mlx4_dev *dev);
379 void mlx4_catas_init(void);
380 int mlx4_restart_one(struct pci_dev *pdev);
381 int mlx4_register_device(struct mlx4_dev *dev);
382 void mlx4_unregister_device(struct mlx4_dev *dev);
383 void mlx4_dispatch_event(struct mlx4_dev *dev, enum mlx4_dev_event type, int port);
384 void *mlx4_find_get_prot_dev(struct mlx4_dev *dev, enum mlx4_prot proto, int port);
385
386 struct mlx4_dev_cap;
387 struct mlx4_init_hca_param;
388
389 u64 mlx4_make_profile(struct mlx4_dev *dev,
390                       struct mlx4_profile *request,
391                       struct mlx4_dev_cap *dev_cap,
392                       struct mlx4_init_hca_param *init_hca);
393
394 int mlx4_cmd_init(struct mlx4_dev *dev);
395 void mlx4_cmd_cleanup(struct mlx4_dev *dev);
396 void mlx4_cmd_event(struct mlx4_dev *dev, u16 token, u8 status, u64 out_param);
397 int mlx4_cmd_use_events(struct mlx4_dev *dev);
398 void mlx4_cmd_use_polling(struct mlx4_dev *dev);
399
400 void mlx4_cq_completion(struct mlx4_dev *dev, u32 cqn);
401 void mlx4_cq_event(struct mlx4_dev *dev, u32 cqn, int event_type);
402
403 void mlx4_qp_event(struct mlx4_dev *dev, u32 qpn, int event_type);
404
405 void mlx4_srq_event(struct mlx4_dev *dev, u32 srqn, int event_type);
406
407 void mlx4_handle_catas_err(struct mlx4_dev *dev);
408
409 void mlx4_do_sense_ports(struct mlx4_dev *dev,
410                          enum mlx4_port_type *stype,
411                          enum mlx4_port_type *defaults);
412 void mlx4_start_sense(struct mlx4_dev *dev);
413 void mlx4_stop_sense(struct mlx4_dev *dev);
414 int mlx4_sense_init(struct mlx4_dev *dev);
415 void mlx4_sense_cleanup(struct mlx4_dev *dev);
416 int mlx4_check_port_params(struct mlx4_dev *dev,
417                            enum mlx4_port_type *port_type);
418 int mlx4_change_port_types(struct mlx4_dev *dev,
419                            enum mlx4_port_type *port_types);
420
421 void mlx4_init_mac_table(struct mlx4_dev *dev, struct mlx4_mac_table *table);
422 void mlx4_init_vlan_table(struct mlx4_dev *dev, struct mlx4_vlan_table *table);
423
424 int mlx4_SET_PORT(struct mlx4_dev *dev, u8 port);
425 int mlx4_get_port_ib_caps(struct mlx4_dev *dev, u8 port, __be32 *caps);
426
427 #endif /* MLX4_H */