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 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>
 
  44 #include <linux/mlx4/device.h>
 
  45 #include <linux/mlx4/driver.h>
 
  46 #include <linux/mlx4/doorbell.h>
 
  48 #define DRV_NAME        "mlx4_core"
 
  49 #define PFX             DRV_NAME ": "
 
  50 #define DRV_VERSION     "0.01"
 
  51 #define DRV_RELDATE     "May 1, 2007"
 
  54         MLX4_HCR_BASE           = 0x80680,
 
  55         MLX4_HCR_SIZE           = 0x0001c,
 
  56         MLX4_CLR_INT_SIZE       = 0x00008
 
  60         MLX4_MGM_ENTRY_SIZE     =  0x100,
 
  61         MLX4_QP_PER_MGM         = 4 * (MLX4_MGM_ENTRY_SIZE / 16 - 2),
 
  62         MLX4_MTT_ENTRY_PER_SEG  = 8
 
  72         MLX4_NUM_PDS            = 1 << 15
 
  76         MLX4_CMPT_TYPE_QP       = 0,
 
  77         MLX4_CMPT_TYPE_SRQ      = 1,
 
  78         MLX4_CMPT_TYPE_CQ       = 2,
 
  79         MLX4_CMPT_TYPE_EQ       = 3,
 
  85         MLX4_NUM_CMPTS          = MLX4_CMPT_NUM_TYPE << MLX4_CMPT_SHIFT
 
  88 #ifdef CONFIG_MLX4_DEBUG
 
  89 extern int mlx4_debug_level;
 
  91 #define mlx4_dbg(mdev, format, arg...)                                  \
 
  93                 if (mlx4_debug_level)                                   \
 
  94                         dev_printk(KERN_DEBUG, &mdev->pdev->dev, format, ## arg); \
 
  97 #else /* CONFIG_MLX4_DEBUG */
 
  99 #define mlx4_dbg(mdev, format, arg...) do { (void) mdev; } while (0)
 
 101 #endif /* CONFIG_MLX4_DEBUG */
 
 103 #define mlx4_err(mdev, format, arg...) \
 
 104         dev_err(&mdev->pdev->dev, format, ## arg)
 
 105 #define mlx4_info(mdev, format, arg...) \
 
 106         dev_info(&mdev->pdev->dev, format, ## arg)
 
 107 #define mlx4_warn(mdev, format, arg...) \
 
 108         dev_warn(&mdev->pdev->dev, format, ## arg)
 
 116         unsigned long          *table;
 
 120         unsigned long         **bits;
 
 121         unsigned int           *num_free;
 
 128 struct mlx4_icm_table {
 
 136         struct mlx4_icm       **icm;
 
 140         struct mlx4_dev        *dev;
 
 141         void __iomem           *doorbell;
 
 147         struct mlx4_buf_list   *page_list;
 
 151 struct mlx4_profile {
 
 164         struct mlx4_icm        *fw_icm;
 
 165         struct mlx4_icm        *aux_icm;
 
 173         struct pci_pool        *pool;
 
 175         struct mutex            hcr_mutex;
 
 176         struct semaphore        poll_sem;
 
 177         struct semaphore        event_sem;
 
 179         spinlock_t              context_lock;
 
 181         struct mlx4_cmd_context *context;
 
 187 struct mlx4_uar_table {
 
 188         struct mlx4_bitmap      bitmap;
 
 191 struct mlx4_mr_table {
 
 192         struct mlx4_bitmap      mpt_bitmap;
 
 193         struct mlx4_buddy       mtt_buddy;
 
 196         struct mlx4_icm_table   mtt_table;
 
 197         struct mlx4_icm_table   dmpt_table;
 
 200 struct mlx4_cq_table {
 
 201         struct mlx4_bitmap      bitmap;
 
 203         struct radix_tree_root  tree;
 
 204         struct mlx4_icm_table   table;
 
 205         struct mlx4_icm_table   cmpt_table;
 
 208 struct mlx4_eq_table {
 
 209         struct mlx4_bitmap      bitmap;
 
 210         void __iomem           *clr_int;
 
 211         void __iomem           *uar_map[(MLX4_NUM_EQ + 6) / 4];
 
 213         struct mlx4_eq          eq[MLX4_NUM_EQ];
 
 215         struct page            *icm_page;
 
 217         struct mlx4_icm_table   cmpt_table;
 
 222 struct mlx4_srq_table {
 
 223         struct mlx4_bitmap      bitmap;
 
 225         struct radix_tree_root  tree;
 
 226         struct mlx4_icm_table   table;
 
 227         struct mlx4_icm_table   cmpt_table;
 
 230 struct mlx4_qp_table {
 
 231         struct mlx4_bitmap      bitmap;
 
 235         struct mlx4_icm_table   qp_table;
 
 236         struct mlx4_icm_table   auxc_table;
 
 237         struct mlx4_icm_table   altc_table;
 
 238         struct mlx4_icm_table   rdmarc_table;
 
 239         struct mlx4_icm_table   cmpt_table;
 
 242 struct mlx4_mcg_table {
 
 244         struct mlx4_bitmap      bitmap;
 
 245         struct mlx4_icm_table   table;
 
 248 struct mlx4_catas_err {
 
 250         struct timer_list       timer;
 
 251         struct list_head        list;
 
 257         struct list_head        dev_list;
 
 258         struct list_head        ctx_list;
 
 261         struct list_head        pgdir_list;
 
 262         struct mutex            pgdir_mutex;
 
 267         struct mlx4_bitmap      pd_bitmap;
 
 268         struct mlx4_uar_table   uar_table;
 
 269         struct mlx4_mr_table    mr_table;
 
 270         struct mlx4_cq_table    cq_table;
 
 271         struct mlx4_eq_table    eq_table;
 
 272         struct mlx4_srq_table   srq_table;
 
 273         struct mlx4_qp_table    qp_table;
 
 274         struct mlx4_mcg_table   mcg_table;
 
 276         struct mlx4_catas_err   catas_err;
 
 278         void __iomem           *clr_base;
 
 280         struct mlx4_uar         driver_uar;
 
 284 static inline struct mlx4_priv *mlx4_priv(struct mlx4_dev *dev)
 
 286         return container_of(dev, struct mlx4_priv, dev);
 
 289 u32 mlx4_bitmap_alloc(struct mlx4_bitmap *bitmap);
 
 290 void mlx4_bitmap_free(struct mlx4_bitmap *bitmap, u32 obj);
 
 291 int mlx4_bitmap_init(struct mlx4_bitmap *bitmap, u32 num, u32 mask, u32 reserved);
 
 292 void mlx4_bitmap_cleanup(struct mlx4_bitmap *bitmap);
 
 294 int mlx4_reset(struct mlx4_dev *dev);
 
 296 int mlx4_init_pd_table(struct mlx4_dev *dev);
 
 297 int mlx4_init_uar_table(struct mlx4_dev *dev);
 
 298 int mlx4_init_mr_table(struct mlx4_dev *dev);
 
 299 int mlx4_init_eq_table(struct mlx4_dev *dev);
 
 300 int mlx4_init_cq_table(struct mlx4_dev *dev);
 
 301 int mlx4_init_qp_table(struct mlx4_dev *dev);
 
 302 int mlx4_init_srq_table(struct mlx4_dev *dev);
 
 303 int mlx4_init_mcg_table(struct mlx4_dev *dev);
 
 305 void mlx4_cleanup_pd_table(struct mlx4_dev *dev);
 
 306 void mlx4_cleanup_uar_table(struct mlx4_dev *dev);
 
 307 void mlx4_cleanup_mr_table(struct mlx4_dev *dev);
 
 308 void mlx4_cleanup_eq_table(struct mlx4_dev *dev);
 
 309 void mlx4_cleanup_cq_table(struct mlx4_dev *dev);
 
 310 void mlx4_cleanup_qp_table(struct mlx4_dev *dev);
 
 311 void mlx4_cleanup_srq_table(struct mlx4_dev *dev);
 
 312 void mlx4_cleanup_mcg_table(struct mlx4_dev *dev);
 
 314 void mlx4_start_catas_poll(struct mlx4_dev *dev);
 
 315 void mlx4_stop_catas_poll(struct mlx4_dev *dev);
 
 316 int mlx4_catas_init(void);
 
 317 void mlx4_catas_cleanup(void);
 
 318 int mlx4_restart_one(struct pci_dev *pdev);
 
 319 int mlx4_register_device(struct mlx4_dev *dev);
 
 320 void mlx4_unregister_device(struct mlx4_dev *dev);
 
 321 void mlx4_dispatch_event(struct mlx4_dev *dev, enum mlx4_dev_event type, int port);
 
 324 struct mlx4_init_hca_param;
 
 326 u64 mlx4_make_profile(struct mlx4_dev *dev,
 
 327                       struct mlx4_profile *request,
 
 328                       struct mlx4_dev_cap *dev_cap,
 
 329                       struct mlx4_init_hca_param *init_hca);
 
 331 int mlx4_map_eq_icm(struct mlx4_dev *dev, u64 icm_virt);
 
 332 void mlx4_unmap_eq_icm(struct mlx4_dev *dev);
 
 334 int mlx4_cmd_init(struct mlx4_dev *dev);
 
 335 void mlx4_cmd_cleanup(struct mlx4_dev *dev);
 
 336 void mlx4_cmd_event(struct mlx4_dev *dev, u16 token, u8 status, u64 out_param);
 
 337 int mlx4_cmd_use_events(struct mlx4_dev *dev);
 
 338 void mlx4_cmd_use_polling(struct mlx4_dev *dev);
 
 340 void mlx4_cq_completion(struct mlx4_dev *dev, u32 cqn);
 
 341 void mlx4_cq_event(struct mlx4_dev *dev, u32 cqn, int event_type);
 
 343 void mlx4_qp_event(struct mlx4_dev *dev, u32 qpn, int event_type);
 
 345 void mlx4_srq_event(struct mlx4_dev *dev, u32 srqn, int event_type);
 
 347 void mlx4_handle_catas_err(struct mlx4_dev *dev);