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