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.
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:
14 * Redistribution and use in source and binary forms, with or
15 * without modification, are permitted provided that the following
18 * - Redistributions of source code must retain the above
19 * copyright notice, this list of conditions and the following
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.
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
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>
46 #include <linux/mlx4/device.h>
47 #include <linux/mlx4/driver.h>
48 #include <linux/mlx4/doorbell.h>
50 #define DRV_NAME "mlx4_core"
51 #define DRV_VERSION "0.01"
52 #define DRV_RELDATE "May 1, 2007"
55 MLX4_HCR_BASE
= 0x80680,
56 MLX4_HCR_SIZE
= 0x0001c,
57 MLX4_CLR_INT_SIZE
= 0x00008
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
67 MLX4_NUM_PDS
= 1 << 15
71 MLX4_CMPT_TYPE_QP
= 0,
72 MLX4_CMPT_TYPE_SRQ
= 1,
73 MLX4_CMPT_TYPE_CQ
= 2,
74 MLX4_CMPT_TYPE_EQ
= 3,
80 MLX4_NUM_CMPTS
= MLX4_CMPT_NUM_TYPE
<< MLX4_CMPT_SHIFT
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 */
89 #define mlx4_dbg(mdev, format, arg...) \
91 if (mlx4_debug_level) \
92 dev_printk(KERN_DEBUG, &mdev->pdev->dev, format, ##arg); \
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)
109 unsigned long *table
;
113 unsigned long **bits
;
114 unsigned int *num_free
;
121 struct mlx4_icm_table
{
129 struct mlx4_icm
**icm
;
133 struct mlx4_dev
*dev
;
134 void __iomem
*doorbell
;
140 struct mlx4_buf_list
*page_list
;
144 struct mlx4_profile
{
157 struct mlx4_icm
*fw_icm
;
158 struct mlx4_icm
*aux_icm
;
165 #define MGM_QPN_MASK 0x00FFFFFF
166 #define MGM_BLCK_LB_BIT 30
168 struct mlx4_promisc_qp
{
169 struct list_head list
;
173 struct mlx4_steer_index
{
174 struct list_head list
;
176 struct list_head duplicates
;
180 __be32 next_gid_index
;
181 __be32 members_count
;
184 __be32 qp
[MLX4_QP_PER_MGM
];
187 struct pci_pool
*pool
;
189 struct mutex hcr_mutex
;
190 struct semaphore poll_sem
;
191 struct semaphore event_sem
;
193 spinlock_t context_lock
;
195 struct mlx4_cmd_context
*context
;
201 struct mlx4_uar_table
{
202 struct mlx4_bitmap bitmap
;
205 struct mlx4_mr_table
{
206 struct mlx4_bitmap mpt_bitmap
;
207 struct mlx4_buddy mtt_buddy
;
210 struct mlx4_icm_table mtt_table
;
211 struct mlx4_icm_table dmpt_table
;
214 struct mlx4_cq_table
{
215 struct mlx4_bitmap bitmap
;
217 struct radix_tree_root tree
;
218 struct mlx4_icm_table table
;
219 struct mlx4_icm_table cmpt_table
;
222 struct mlx4_eq_table
{
223 struct mlx4_bitmap bitmap
;
225 void __iomem
*clr_int
;
226 void __iomem
**uar_map
;
229 struct mlx4_icm_table table
;
230 struct mlx4_icm_table cmpt_table
;
235 struct mlx4_srq_table
{
236 struct mlx4_bitmap bitmap
;
238 struct radix_tree_root tree
;
239 struct mlx4_icm_table table
;
240 struct mlx4_icm_table cmpt_table
;
243 struct mlx4_qp_table
{
244 struct mlx4_bitmap bitmap
;
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
;
255 struct mlx4_mcg_table
{
257 struct mlx4_bitmap bitmap
;
258 struct mlx4_icm_table table
;
261 struct mlx4_catas_err
{
263 struct timer_list timer
;
264 struct list_head list
;
267 #define MLX4_MAX_MAC_NUM 128
268 #define MLX4_MAC_TABLE_SIZE (MLX4_MAX_MAC_NUM << 3)
270 struct mlx4_mac_table
{
271 __be64 entries
[MLX4_MAX_MAC_NUM
];
272 int refs
[MLX4_MAX_MAC_NUM
];
278 #define MLX4_MAX_VLAN_NUM 128
279 #define MLX4_VLAN_TABLE_SIZE (MLX4_MAX_VLAN_NUM << 2)
281 struct mlx4_vlan_table
{
282 __be32 entries
[MLX4_MAX_VLAN_NUM
];
283 int refs
[MLX4_MAX_VLAN_NUM
];
289 struct mlx4_port_info
{
290 struct mlx4_dev
*dev
;
293 struct device_attribute port_attr
;
294 enum mlx4_port_type tmp_type
;
295 struct mlx4_mac_table mac_table
;
296 struct mlx4_vlan_table vlan_table
;
300 struct mlx4_dev
*dev
;
301 u8 do_sense_port
[MLX4_MAX_PORTS
+ 1];
302 u8 sense_allowed
[MLX4_MAX_PORTS
+ 1];
303 struct delayed_work sense_poll
;
306 struct mlx4_msix_ctl
{
308 spinlock_t pool_lock
;
312 struct list_head promisc_qps
[MLX4_NUM_STEERS
];
313 struct list_head steer_entries
[MLX4_NUM_STEERS
];
314 struct list_head high_prios
;
320 struct list_head dev_list
;
321 struct list_head ctx_list
;
324 struct list_head pgdir_list
;
325 struct mutex pgdir_mutex
;
330 struct mlx4_bitmap pd_bitmap
;
331 struct mlx4_uar_table uar_table
;
332 struct mlx4_mr_table mr_table
;
333 struct mlx4_cq_table cq_table
;
334 struct mlx4_eq_table eq_table
;
335 struct mlx4_srq_table srq_table
;
336 struct mlx4_qp_table qp_table
;
337 struct mlx4_mcg_table mcg_table
;
339 struct mlx4_catas_err catas_err
;
341 void __iomem
*clr_base
;
343 struct mlx4_uar driver_uar
;
345 struct mlx4_port_info port
[MLX4_MAX_PORTS
+ 1];
346 struct mlx4_sense sense
;
347 struct mutex port_mutex
;
348 struct mlx4_msix_ctl msix_ctl
;
349 struct mlx4_steer
*steer
;
352 static inline struct mlx4_priv
*mlx4_priv(struct mlx4_dev
*dev
)
354 return container_of(dev
, struct mlx4_priv
, dev
);
357 #define MLX4_SENSE_RANGE (HZ * 3)
359 extern struct workqueue_struct
*mlx4_wq
;
361 u32
mlx4_bitmap_alloc(struct mlx4_bitmap
*bitmap
);
362 void mlx4_bitmap_free(struct mlx4_bitmap
*bitmap
, u32 obj
);
363 u32
mlx4_bitmap_alloc_range(struct mlx4_bitmap
*bitmap
, int cnt
, int align
);
364 void mlx4_bitmap_free_range(struct mlx4_bitmap
*bitmap
, u32 obj
, int cnt
);
365 int mlx4_bitmap_init(struct mlx4_bitmap
*bitmap
, u32 num
, u32 mask
,
366 u32 reserved_bot
, u32 resetrved_top
);
367 void mlx4_bitmap_cleanup(struct mlx4_bitmap
*bitmap
);
369 int mlx4_reset(struct mlx4_dev
*dev
);
371 int mlx4_alloc_eq_table(struct mlx4_dev
*dev
);
372 void mlx4_free_eq_table(struct mlx4_dev
*dev
);
374 int mlx4_init_pd_table(struct mlx4_dev
*dev
);
375 int mlx4_init_uar_table(struct mlx4_dev
*dev
);
376 int mlx4_init_mr_table(struct mlx4_dev
*dev
);
377 int mlx4_init_eq_table(struct mlx4_dev
*dev
);
378 int mlx4_init_cq_table(struct mlx4_dev
*dev
);
379 int mlx4_init_qp_table(struct mlx4_dev
*dev
);
380 int mlx4_init_srq_table(struct mlx4_dev
*dev
);
381 int mlx4_init_mcg_table(struct mlx4_dev
*dev
);
383 void mlx4_cleanup_pd_table(struct mlx4_dev
*dev
);
384 void mlx4_cleanup_uar_table(struct mlx4_dev
*dev
);
385 void mlx4_cleanup_mr_table(struct mlx4_dev
*dev
);
386 void mlx4_cleanup_eq_table(struct mlx4_dev
*dev
);
387 void mlx4_cleanup_cq_table(struct mlx4_dev
*dev
);
388 void mlx4_cleanup_qp_table(struct mlx4_dev
*dev
);
389 void mlx4_cleanup_srq_table(struct mlx4_dev
*dev
);
390 void mlx4_cleanup_mcg_table(struct mlx4_dev
*dev
);
392 void mlx4_start_catas_poll(struct mlx4_dev
*dev
);
393 void mlx4_stop_catas_poll(struct mlx4_dev
*dev
);
394 void mlx4_catas_init(void);
395 int mlx4_restart_one(struct pci_dev
*pdev
);
396 int mlx4_register_device(struct mlx4_dev
*dev
);
397 void mlx4_unregister_device(struct mlx4_dev
*dev
);
398 void mlx4_dispatch_event(struct mlx4_dev
*dev
, enum mlx4_dev_event type
, int port
);
401 struct mlx4_init_hca_param
;
403 u64
mlx4_make_profile(struct mlx4_dev
*dev
,
404 struct mlx4_profile
*request
,
405 struct mlx4_dev_cap
*dev_cap
,
406 struct mlx4_init_hca_param
*init_hca
);
408 int mlx4_cmd_init(struct mlx4_dev
*dev
);
409 void mlx4_cmd_cleanup(struct mlx4_dev
*dev
);
410 void mlx4_cmd_event(struct mlx4_dev
*dev
, u16 token
, u8 status
, u64 out_param
);
411 int mlx4_cmd_use_events(struct mlx4_dev
*dev
);
412 void mlx4_cmd_use_polling(struct mlx4_dev
*dev
);
414 void mlx4_cq_completion(struct mlx4_dev
*dev
, u32 cqn
);
415 void mlx4_cq_event(struct mlx4_dev
*dev
, u32 cqn
, int event_type
);
417 void mlx4_qp_event(struct mlx4_dev
*dev
, u32 qpn
, int event_type
);
419 void mlx4_srq_event(struct mlx4_dev
*dev
, u32 srqn
, int event_type
);
421 void mlx4_handle_catas_err(struct mlx4_dev
*dev
);
423 void mlx4_do_sense_ports(struct mlx4_dev
*dev
,
424 enum mlx4_port_type
*stype
,
425 enum mlx4_port_type
*defaults
);
426 void mlx4_start_sense(struct mlx4_dev
*dev
);
427 void mlx4_stop_sense(struct mlx4_dev
*dev
);
428 void mlx4_sense_init(struct mlx4_dev
*dev
);
429 int mlx4_check_port_params(struct mlx4_dev
*dev
,
430 enum mlx4_port_type
*port_type
);
431 int mlx4_change_port_types(struct mlx4_dev
*dev
,
432 enum mlx4_port_type
*port_types
);
434 void mlx4_init_mac_table(struct mlx4_dev
*dev
, struct mlx4_mac_table
*table
);
435 void mlx4_init_vlan_table(struct mlx4_dev
*dev
, struct mlx4_vlan_table
*table
);
437 int mlx4_SET_PORT(struct mlx4_dev
*dev
, u8 port
);
438 int mlx4_get_port_ib_caps(struct mlx4_dev
*dev
, u8 port
, __be32
*caps
);
440 int mlx4_qp_detach_common(struct mlx4_dev
*dev
, struct mlx4_qp
*qp
, u8 gid
[16],
441 enum mlx4_protocol prot
, enum mlx4_steer_type steer
);
442 int mlx4_qp_attach_common(struct mlx4_dev
*dev
, struct mlx4_qp
*qp
, u8 gid
[16],
443 int block_mcast_loopback
, enum mlx4_protocol prot
,
444 enum mlx4_steer_type steer
);