18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Copyright (c) 2004, 2005 Topspin Communications.  All rights reserved.
38c2ecf20Sopenharmony_ci * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
48c2ecf20Sopenharmony_ci * Copyright (c) 2005, 2006 Cisco Systems.  All rights reserved.
58c2ecf20Sopenharmony_ci * Copyright (c) 2005 Mellanox Technologies. All rights reserved.
68c2ecf20Sopenharmony_ci * Copyright (c) 2004 Voltaire, Inc. All rights reserved.
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci * This software is available to you under a choice of one of two
98c2ecf20Sopenharmony_ci * licenses.  You may choose to be licensed under the terms of the GNU
108c2ecf20Sopenharmony_ci * General Public License (GPL) Version 2, available from the file
118c2ecf20Sopenharmony_ci * COPYING in the main directory of this source tree, or the
128c2ecf20Sopenharmony_ci * OpenIB.org BSD license below:
138c2ecf20Sopenharmony_ci *
148c2ecf20Sopenharmony_ci *     Redistribution and use in source and binary forms, with or
158c2ecf20Sopenharmony_ci *     without modification, are permitted provided that the following
168c2ecf20Sopenharmony_ci *     conditions are met:
178c2ecf20Sopenharmony_ci *
188c2ecf20Sopenharmony_ci *      - Redistributions of source code must retain the above
198c2ecf20Sopenharmony_ci *        copyright notice, this list of conditions and the following
208c2ecf20Sopenharmony_ci *        disclaimer.
218c2ecf20Sopenharmony_ci *
228c2ecf20Sopenharmony_ci *      - Redistributions in binary form must reproduce the above
238c2ecf20Sopenharmony_ci *        copyright notice, this list of conditions and the following
248c2ecf20Sopenharmony_ci *        disclaimer in the documentation and/or other materials
258c2ecf20Sopenharmony_ci *        provided with the distribution.
268c2ecf20Sopenharmony_ci *
278c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
288c2ecf20Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
298c2ecf20Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
308c2ecf20Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
318c2ecf20Sopenharmony_ci * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
328c2ecf20Sopenharmony_ci * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
338c2ecf20Sopenharmony_ci * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
348c2ecf20Sopenharmony_ci * SOFTWARE.
358c2ecf20Sopenharmony_ci */
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci#ifndef MTHCA_DEV_H
388c2ecf20Sopenharmony_ci#define MTHCA_DEV_H
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci#include <linux/spinlock.h>
418c2ecf20Sopenharmony_ci#include <linux/kernel.h>
428c2ecf20Sopenharmony_ci#include <linux/pci.h>
438c2ecf20Sopenharmony_ci#include <linux/dma-mapping.h>
448c2ecf20Sopenharmony_ci#include <linux/timer.h>
458c2ecf20Sopenharmony_ci#include <linux/mutex.h>
468c2ecf20Sopenharmony_ci#include <linux/list.h>
478c2ecf20Sopenharmony_ci#include <linux/semaphore.h>
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci#include "mthca_provider.h"
508c2ecf20Sopenharmony_ci#include "mthca_doorbell.h"
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci#define DRV_NAME	"ib_mthca"
538c2ecf20Sopenharmony_ci#define PFX		DRV_NAME ": "
548c2ecf20Sopenharmony_ci#define DRV_VERSION	"1.0"
558c2ecf20Sopenharmony_ci#define DRV_RELDATE	"April 4, 2008"
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_cienum {
588c2ecf20Sopenharmony_ci	MTHCA_FLAG_DDR_HIDDEN = 1 << 1,
598c2ecf20Sopenharmony_ci	MTHCA_FLAG_SRQ        = 1 << 2,
608c2ecf20Sopenharmony_ci	MTHCA_FLAG_MSI_X      = 1 << 3,
618c2ecf20Sopenharmony_ci	MTHCA_FLAG_NO_LAM     = 1 << 4,
628c2ecf20Sopenharmony_ci	MTHCA_FLAG_FMR        = 1 << 5,
638c2ecf20Sopenharmony_ci	MTHCA_FLAG_MEMFREE    = 1 << 6,
648c2ecf20Sopenharmony_ci	MTHCA_FLAG_PCIE       = 1 << 7,
658c2ecf20Sopenharmony_ci	MTHCA_FLAG_SINAI_OPT  = 1 << 8
668c2ecf20Sopenharmony_ci};
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_cienum {
698c2ecf20Sopenharmony_ci	MTHCA_MAX_PORTS = 2
708c2ecf20Sopenharmony_ci};
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_cienum {
738c2ecf20Sopenharmony_ci	MTHCA_BOARD_ID_LEN = 64
748c2ecf20Sopenharmony_ci};
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_cienum {
778c2ecf20Sopenharmony_ci	MTHCA_EQ_CONTEXT_SIZE =  0x40,
788c2ecf20Sopenharmony_ci	MTHCA_CQ_CONTEXT_SIZE =  0x40,
798c2ecf20Sopenharmony_ci	MTHCA_QP_CONTEXT_SIZE = 0x200,
808c2ecf20Sopenharmony_ci	MTHCA_RDB_ENTRY_SIZE  =  0x20,
818c2ecf20Sopenharmony_ci	MTHCA_AV_SIZE         =  0x20,
828c2ecf20Sopenharmony_ci	MTHCA_MGM_ENTRY_SIZE  = 0x100,
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci	/* Arbel FW gives us these, but we need them for Tavor */
858c2ecf20Sopenharmony_ci	MTHCA_MPT_ENTRY_SIZE  =  0x40,
868c2ecf20Sopenharmony_ci	MTHCA_MTT_SEG_SIZE    =  0x40,
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci	MTHCA_QP_PER_MGM      = 4 * (MTHCA_MGM_ENTRY_SIZE / 16 - 2)
898c2ecf20Sopenharmony_ci};
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_cienum {
928c2ecf20Sopenharmony_ci	MTHCA_EQ_CMD,
938c2ecf20Sopenharmony_ci	MTHCA_EQ_ASYNC,
948c2ecf20Sopenharmony_ci	MTHCA_EQ_COMP,
958c2ecf20Sopenharmony_ci	MTHCA_NUM_EQ
968c2ecf20Sopenharmony_ci};
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_cienum {
998c2ecf20Sopenharmony_ci	MTHCA_OPCODE_NOP            = 0x00,
1008c2ecf20Sopenharmony_ci	MTHCA_OPCODE_RDMA_WRITE     = 0x08,
1018c2ecf20Sopenharmony_ci	MTHCA_OPCODE_RDMA_WRITE_IMM = 0x09,
1028c2ecf20Sopenharmony_ci	MTHCA_OPCODE_SEND           = 0x0a,
1038c2ecf20Sopenharmony_ci	MTHCA_OPCODE_SEND_IMM       = 0x0b,
1048c2ecf20Sopenharmony_ci	MTHCA_OPCODE_RDMA_READ      = 0x10,
1058c2ecf20Sopenharmony_ci	MTHCA_OPCODE_ATOMIC_CS      = 0x11,
1068c2ecf20Sopenharmony_ci	MTHCA_OPCODE_ATOMIC_FA      = 0x12,
1078c2ecf20Sopenharmony_ci	MTHCA_OPCODE_BIND_MW        = 0x18,
1088c2ecf20Sopenharmony_ci};
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_cienum {
1118c2ecf20Sopenharmony_ci	MTHCA_CMD_USE_EVENTS         = 1 << 0,
1128c2ecf20Sopenharmony_ci	MTHCA_CMD_POST_DOORBELLS     = 1 << 1
1138c2ecf20Sopenharmony_ci};
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_cienum {
1168c2ecf20Sopenharmony_ci	MTHCA_CMD_NUM_DBELL_DWORDS = 8
1178c2ecf20Sopenharmony_ci};
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_cistruct mthca_cmd {
1208c2ecf20Sopenharmony_ci	struct dma_pool          *pool;
1218c2ecf20Sopenharmony_ci	struct mutex              hcr_mutex;
1228c2ecf20Sopenharmony_ci	struct semaphore 	  poll_sem;
1238c2ecf20Sopenharmony_ci	struct semaphore 	  event_sem;
1248c2ecf20Sopenharmony_ci	int              	  max_cmds;
1258c2ecf20Sopenharmony_ci	spinlock_t                context_lock;
1268c2ecf20Sopenharmony_ci	int                       free_head;
1278c2ecf20Sopenharmony_ci	struct mthca_cmd_context *context;
1288c2ecf20Sopenharmony_ci	u16                       token_mask;
1298c2ecf20Sopenharmony_ci	u32                       flags;
1308c2ecf20Sopenharmony_ci	void __iomem             *dbell_map;
1318c2ecf20Sopenharmony_ci	u16                       dbell_offsets[MTHCA_CMD_NUM_DBELL_DWORDS];
1328c2ecf20Sopenharmony_ci};
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_cistruct mthca_limits {
1358c2ecf20Sopenharmony_ci	int      num_ports;
1368c2ecf20Sopenharmony_ci	int      vl_cap;
1378c2ecf20Sopenharmony_ci	int      mtu_cap;
1388c2ecf20Sopenharmony_ci	int      gid_table_len;
1398c2ecf20Sopenharmony_ci	int      pkey_table_len;
1408c2ecf20Sopenharmony_ci	int      local_ca_ack_delay;
1418c2ecf20Sopenharmony_ci	int      num_uars;
1428c2ecf20Sopenharmony_ci	int      max_sg;
1438c2ecf20Sopenharmony_ci	int      num_qps;
1448c2ecf20Sopenharmony_ci	int      max_wqes;
1458c2ecf20Sopenharmony_ci	int	 max_desc_sz;
1468c2ecf20Sopenharmony_ci	int	 max_qp_init_rdma;
1478c2ecf20Sopenharmony_ci	int      reserved_qps;
1488c2ecf20Sopenharmony_ci	int      num_srqs;
1498c2ecf20Sopenharmony_ci	int      max_srq_wqes;
1508c2ecf20Sopenharmony_ci	int      max_srq_sge;
1518c2ecf20Sopenharmony_ci	int      reserved_srqs;
1528c2ecf20Sopenharmony_ci	int      num_eecs;
1538c2ecf20Sopenharmony_ci	int      reserved_eecs;
1548c2ecf20Sopenharmony_ci	int      num_cqs;
1558c2ecf20Sopenharmony_ci	int      max_cqes;
1568c2ecf20Sopenharmony_ci	int      reserved_cqs;
1578c2ecf20Sopenharmony_ci	int      num_eqs;
1588c2ecf20Sopenharmony_ci	int      reserved_eqs;
1598c2ecf20Sopenharmony_ci	int      num_mpts;
1608c2ecf20Sopenharmony_ci	int      num_mtt_segs;
1618c2ecf20Sopenharmony_ci	int	 mtt_seg_size;
1628c2ecf20Sopenharmony_ci	int      fmr_reserved_mtts;
1638c2ecf20Sopenharmony_ci	int      reserved_mtts;
1648c2ecf20Sopenharmony_ci	int      reserved_mrws;
1658c2ecf20Sopenharmony_ci	int      reserved_uars;
1668c2ecf20Sopenharmony_ci	int      num_mgms;
1678c2ecf20Sopenharmony_ci	int      num_amgms;
1688c2ecf20Sopenharmony_ci	int      reserved_mcgs;
1698c2ecf20Sopenharmony_ci	int      num_pds;
1708c2ecf20Sopenharmony_ci	int      reserved_pds;
1718c2ecf20Sopenharmony_ci	u32      page_size_cap;
1728c2ecf20Sopenharmony_ci	u32      flags;
1738c2ecf20Sopenharmony_ci	u16      stat_rate_support;
1748c2ecf20Sopenharmony_ci	u8       port_width_cap;
1758c2ecf20Sopenharmony_ci};
1768c2ecf20Sopenharmony_ci
1778c2ecf20Sopenharmony_cistruct mthca_alloc {
1788c2ecf20Sopenharmony_ci	u32            last;
1798c2ecf20Sopenharmony_ci	u32            top;
1808c2ecf20Sopenharmony_ci	u32            max;
1818c2ecf20Sopenharmony_ci	u32            mask;
1828c2ecf20Sopenharmony_ci	spinlock_t     lock;
1838c2ecf20Sopenharmony_ci	unsigned long *table;
1848c2ecf20Sopenharmony_ci};
1858c2ecf20Sopenharmony_ci
1868c2ecf20Sopenharmony_cistruct mthca_array {
1878c2ecf20Sopenharmony_ci	struct {
1888c2ecf20Sopenharmony_ci		void    **page;
1898c2ecf20Sopenharmony_ci		int       used;
1908c2ecf20Sopenharmony_ci	} *page_list;
1918c2ecf20Sopenharmony_ci};
1928c2ecf20Sopenharmony_ci
1938c2ecf20Sopenharmony_cistruct mthca_uar_table {
1948c2ecf20Sopenharmony_ci	struct mthca_alloc alloc;
1958c2ecf20Sopenharmony_ci	u64                uarc_base;
1968c2ecf20Sopenharmony_ci	int                uarc_size;
1978c2ecf20Sopenharmony_ci};
1988c2ecf20Sopenharmony_ci
1998c2ecf20Sopenharmony_cistruct mthca_pd_table {
2008c2ecf20Sopenharmony_ci	struct mthca_alloc alloc;
2018c2ecf20Sopenharmony_ci};
2028c2ecf20Sopenharmony_ci
2038c2ecf20Sopenharmony_cistruct mthca_buddy {
2048c2ecf20Sopenharmony_ci	unsigned long **bits;
2058c2ecf20Sopenharmony_ci	int	       *num_free;
2068c2ecf20Sopenharmony_ci	int             max_order;
2078c2ecf20Sopenharmony_ci	spinlock_t      lock;
2088c2ecf20Sopenharmony_ci};
2098c2ecf20Sopenharmony_ci
2108c2ecf20Sopenharmony_cistruct mthca_mr_table {
2118c2ecf20Sopenharmony_ci	struct mthca_alloc      mpt_alloc;
2128c2ecf20Sopenharmony_ci	struct mthca_buddy      mtt_buddy;
2138c2ecf20Sopenharmony_ci	struct mthca_buddy     *fmr_mtt_buddy;
2148c2ecf20Sopenharmony_ci	u64                     mtt_base;
2158c2ecf20Sopenharmony_ci	u64                     mpt_base;
2168c2ecf20Sopenharmony_ci	struct mthca_icm_table *mtt_table;
2178c2ecf20Sopenharmony_ci	struct mthca_icm_table *mpt_table;
2188c2ecf20Sopenharmony_ci	struct {
2198c2ecf20Sopenharmony_ci		void __iomem   *mpt_base;
2208c2ecf20Sopenharmony_ci		void __iomem   *mtt_base;
2218c2ecf20Sopenharmony_ci		struct mthca_buddy mtt_buddy;
2228c2ecf20Sopenharmony_ci	} tavor_fmr;
2238c2ecf20Sopenharmony_ci};
2248c2ecf20Sopenharmony_ci
2258c2ecf20Sopenharmony_cistruct mthca_eq_table {
2268c2ecf20Sopenharmony_ci	struct mthca_alloc alloc;
2278c2ecf20Sopenharmony_ci	void __iomem      *clr_int;
2288c2ecf20Sopenharmony_ci	u32                clr_mask;
2298c2ecf20Sopenharmony_ci	u32                arm_mask;
2308c2ecf20Sopenharmony_ci	struct mthca_eq    eq[MTHCA_NUM_EQ];
2318c2ecf20Sopenharmony_ci	u64                icm_virt;
2328c2ecf20Sopenharmony_ci	struct page       *icm_page;
2338c2ecf20Sopenharmony_ci	dma_addr_t         icm_dma;
2348c2ecf20Sopenharmony_ci	int                have_irq;
2358c2ecf20Sopenharmony_ci	u8                 inta_pin;
2368c2ecf20Sopenharmony_ci};
2378c2ecf20Sopenharmony_ci
2388c2ecf20Sopenharmony_cistruct mthca_cq_table {
2398c2ecf20Sopenharmony_ci	struct mthca_alloc 	alloc;
2408c2ecf20Sopenharmony_ci	spinlock_t         	lock;
2418c2ecf20Sopenharmony_ci	struct mthca_array      cq;
2428c2ecf20Sopenharmony_ci	struct mthca_icm_table *table;
2438c2ecf20Sopenharmony_ci};
2448c2ecf20Sopenharmony_ci
2458c2ecf20Sopenharmony_cistruct mthca_srq_table {
2468c2ecf20Sopenharmony_ci	struct mthca_alloc 	alloc;
2478c2ecf20Sopenharmony_ci	spinlock_t         	lock;
2488c2ecf20Sopenharmony_ci	struct mthca_array      srq;
2498c2ecf20Sopenharmony_ci	struct mthca_icm_table *table;
2508c2ecf20Sopenharmony_ci};
2518c2ecf20Sopenharmony_ci
2528c2ecf20Sopenharmony_cistruct mthca_qp_table {
2538c2ecf20Sopenharmony_ci	struct mthca_alloc     	alloc;
2548c2ecf20Sopenharmony_ci	u32                    	rdb_base;
2558c2ecf20Sopenharmony_ci	int                    	rdb_shift;
2568c2ecf20Sopenharmony_ci	int                    	sqp_start;
2578c2ecf20Sopenharmony_ci	spinlock_t             	lock;
2588c2ecf20Sopenharmony_ci	struct mthca_array     	qp;
2598c2ecf20Sopenharmony_ci	struct mthca_icm_table *qp_table;
2608c2ecf20Sopenharmony_ci	struct mthca_icm_table *eqp_table;
2618c2ecf20Sopenharmony_ci	struct mthca_icm_table *rdb_table;
2628c2ecf20Sopenharmony_ci};
2638c2ecf20Sopenharmony_ci
2648c2ecf20Sopenharmony_cistruct mthca_av_table {
2658c2ecf20Sopenharmony_ci	struct dma_pool   *pool;
2668c2ecf20Sopenharmony_ci	int                num_ddr_avs;
2678c2ecf20Sopenharmony_ci	u64                ddr_av_base;
2688c2ecf20Sopenharmony_ci	void __iomem      *av_map;
2698c2ecf20Sopenharmony_ci	struct mthca_alloc alloc;
2708c2ecf20Sopenharmony_ci};
2718c2ecf20Sopenharmony_ci
2728c2ecf20Sopenharmony_cistruct mthca_mcg_table {
2738c2ecf20Sopenharmony_ci	struct mutex		mutex;
2748c2ecf20Sopenharmony_ci	struct mthca_alloc 	alloc;
2758c2ecf20Sopenharmony_ci	struct mthca_icm_table *table;
2768c2ecf20Sopenharmony_ci};
2778c2ecf20Sopenharmony_ci
2788c2ecf20Sopenharmony_cistruct mthca_catas_err {
2798c2ecf20Sopenharmony_ci	u64			addr;
2808c2ecf20Sopenharmony_ci	u32 __iomem	       *map;
2818c2ecf20Sopenharmony_ci	u32			size;
2828c2ecf20Sopenharmony_ci	struct timer_list	timer;
2838c2ecf20Sopenharmony_ci	struct list_head	list;
2848c2ecf20Sopenharmony_ci};
2858c2ecf20Sopenharmony_ci
2868c2ecf20Sopenharmony_ciextern struct mutex mthca_device_mutex;
2878c2ecf20Sopenharmony_ci
2888c2ecf20Sopenharmony_cistruct mthca_dev {
2898c2ecf20Sopenharmony_ci	struct ib_device  ib_dev;
2908c2ecf20Sopenharmony_ci	struct pci_dev   *pdev;
2918c2ecf20Sopenharmony_ci
2928c2ecf20Sopenharmony_ci	int          	 hca_type;
2938c2ecf20Sopenharmony_ci	unsigned long	 mthca_flags;
2948c2ecf20Sopenharmony_ci	unsigned long    device_cap_flags;
2958c2ecf20Sopenharmony_ci
2968c2ecf20Sopenharmony_ci	u32              rev_id;
2978c2ecf20Sopenharmony_ci	char             board_id[MTHCA_BOARD_ID_LEN];
2988c2ecf20Sopenharmony_ci
2998c2ecf20Sopenharmony_ci	/* firmware info */
3008c2ecf20Sopenharmony_ci	u64              fw_ver;
3018c2ecf20Sopenharmony_ci	union {
3028c2ecf20Sopenharmony_ci		struct {
3038c2ecf20Sopenharmony_ci			u64 fw_start;
3048c2ecf20Sopenharmony_ci			u64 fw_end;
3058c2ecf20Sopenharmony_ci		}        tavor;
3068c2ecf20Sopenharmony_ci		struct {
3078c2ecf20Sopenharmony_ci			u64 clr_int_base;
3088c2ecf20Sopenharmony_ci			u64 eq_arm_base;
3098c2ecf20Sopenharmony_ci			u64 eq_set_ci_base;
3108c2ecf20Sopenharmony_ci			struct mthca_icm *fw_icm;
3118c2ecf20Sopenharmony_ci			struct mthca_icm *aux_icm;
3128c2ecf20Sopenharmony_ci			u16 fw_pages;
3138c2ecf20Sopenharmony_ci		}        arbel;
3148c2ecf20Sopenharmony_ci	}                fw;
3158c2ecf20Sopenharmony_ci
3168c2ecf20Sopenharmony_ci	u64              ddr_start;
3178c2ecf20Sopenharmony_ci	u64              ddr_end;
3188c2ecf20Sopenharmony_ci
3198c2ecf20Sopenharmony_ci	MTHCA_DECLARE_DOORBELL_LOCK(doorbell_lock)
3208c2ecf20Sopenharmony_ci	struct mutex cap_mask_mutex;
3218c2ecf20Sopenharmony_ci
3228c2ecf20Sopenharmony_ci	void __iomem    *hcr;
3238c2ecf20Sopenharmony_ci	void __iomem    *kar;
3248c2ecf20Sopenharmony_ci	void __iomem    *clr_base;
3258c2ecf20Sopenharmony_ci	union {
3268c2ecf20Sopenharmony_ci		struct {
3278c2ecf20Sopenharmony_ci			void __iomem *ecr_base;
3288c2ecf20Sopenharmony_ci		} tavor;
3298c2ecf20Sopenharmony_ci		struct {
3308c2ecf20Sopenharmony_ci			void __iomem *eq_arm;
3318c2ecf20Sopenharmony_ci			void __iomem *eq_set_ci_base;
3328c2ecf20Sopenharmony_ci		} arbel;
3338c2ecf20Sopenharmony_ci	} eq_regs;
3348c2ecf20Sopenharmony_ci
3358c2ecf20Sopenharmony_ci	struct mthca_cmd    cmd;
3368c2ecf20Sopenharmony_ci	struct mthca_limits limits;
3378c2ecf20Sopenharmony_ci
3388c2ecf20Sopenharmony_ci	struct mthca_uar_table uar_table;
3398c2ecf20Sopenharmony_ci	struct mthca_pd_table  pd_table;
3408c2ecf20Sopenharmony_ci	struct mthca_mr_table  mr_table;
3418c2ecf20Sopenharmony_ci	struct mthca_eq_table  eq_table;
3428c2ecf20Sopenharmony_ci	struct mthca_cq_table  cq_table;
3438c2ecf20Sopenharmony_ci	struct mthca_srq_table srq_table;
3448c2ecf20Sopenharmony_ci	struct mthca_qp_table  qp_table;
3458c2ecf20Sopenharmony_ci	struct mthca_av_table  av_table;
3468c2ecf20Sopenharmony_ci	struct mthca_mcg_table mcg_table;
3478c2ecf20Sopenharmony_ci
3488c2ecf20Sopenharmony_ci	struct mthca_catas_err catas_err;
3498c2ecf20Sopenharmony_ci
3508c2ecf20Sopenharmony_ci	struct mthca_uar       driver_uar;
3518c2ecf20Sopenharmony_ci	struct mthca_db_table *db_tab;
3528c2ecf20Sopenharmony_ci	struct mthca_pd        driver_pd;
3538c2ecf20Sopenharmony_ci	struct mthca_mr        driver_mr;
3548c2ecf20Sopenharmony_ci
3558c2ecf20Sopenharmony_ci	struct ib_mad_agent  *send_agent[MTHCA_MAX_PORTS][2];
3568c2ecf20Sopenharmony_ci	struct ib_ah         *sm_ah[MTHCA_MAX_PORTS];
3578c2ecf20Sopenharmony_ci	spinlock_t            sm_lock;
3588c2ecf20Sopenharmony_ci	u8                    rate[MTHCA_MAX_PORTS];
3598c2ecf20Sopenharmony_ci	bool		      active;
3608c2ecf20Sopenharmony_ci};
3618c2ecf20Sopenharmony_ci
3628c2ecf20Sopenharmony_ci#ifdef CONFIG_INFINIBAND_MTHCA_DEBUG
3638c2ecf20Sopenharmony_ciextern int mthca_debug_level;
3648c2ecf20Sopenharmony_ci
3658c2ecf20Sopenharmony_ci#define mthca_dbg(mdev, format, arg...)					\
3668c2ecf20Sopenharmony_ci	do {								\
3678c2ecf20Sopenharmony_ci		if (mthca_debug_level)					\
3688c2ecf20Sopenharmony_ci			dev_printk(KERN_DEBUG, &mdev->pdev->dev, format, ## arg); \
3698c2ecf20Sopenharmony_ci	} while (0)
3708c2ecf20Sopenharmony_ci
3718c2ecf20Sopenharmony_ci#else /* CONFIG_INFINIBAND_MTHCA_DEBUG */
3728c2ecf20Sopenharmony_ci
3738c2ecf20Sopenharmony_ci#define mthca_dbg(mdev, format, arg...) do { (void) mdev; } while (0)
3748c2ecf20Sopenharmony_ci
3758c2ecf20Sopenharmony_ci#endif /* CONFIG_INFINIBAND_MTHCA_DEBUG */
3768c2ecf20Sopenharmony_ci
3778c2ecf20Sopenharmony_ci#define mthca_err(mdev, format, arg...) \
3788c2ecf20Sopenharmony_ci	dev_err(&mdev->pdev->dev, format, ## arg)
3798c2ecf20Sopenharmony_ci#define mthca_info(mdev, format, arg...) \
3808c2ecf20Sopenharmony_ci	dev_info(&mdev->pdev->dev, format, ## arg)
3818c2ecf20Sopenharmony_ci#define mthca_warn(mdev, format, arg...) \
3828c2ecf20Sopenharmony_ci	dev_warn(&mdev->pdev->dev, format, ## arg)
3838c2ecf20Sopenharmony_ci
3848c2ecf20Sopenharmony_ciextern void __buggy_use_of_MTHCA_GET(void);
3858c2ecf20Sopenharmony_ciextern void __buggy_use_of_MTHCA_PUT(void);
3868c2ecf20Sopenharmony_ci
3878c2ecf20Sopenharmony_ci#define MTHCA_GET(dest, source, offset)                               \
3888c2ecf20Sopenharmony_ci	do {                                                          \
3898c2ecf20Sopenharmony_ci		void *__p = (char *) (source) + (offset);             \
3908c2ecf20Sopenharmony_ci		switch (sizeof (dest)) {                              \
3918c2ecf20Sopenharmony_ci		case 1: (dest) = *(u8 *) __p;       break;	      \
3928c2ecf20Sopenharmony_ci		case 2: (dest) = be16_to_cpup(__p); break;	      \
3938c2ecf20Sopenharmony_ci		case 4: (dest) = be32_to_cpup(__p); break;	      \
3948c2ecf20Sopenharmony_ci		case 8: (dest) = be64_to_cpup(__p); break;	      \
3958c2ecf20Sopenharmony_ci		default: __buggy_use_of_MTHCA_GET();		      \
3968c2ecf20Sopenharmony_ci		}                                                     \
3978c2ecf20Sopenharmony_ci	} while (0)
3988c2ecf20Sopenharmony_ci
3998c2ecf20Sopenharmony_ci#define MTHCA_PUT(dest, source, offset)                               \
4008c2ecf20Sopenharmony_ci	do {                                                          \
4018c2ecf20Sopenharmony_ci		void *__d = ((char *) (dest) + (offset));	      \
4028c2ecf20Sopenharmony_ci		switch (sizeof(source)) {                             \
4038c2ecf20Sopenharmony_ci		case 1: *(u8 *) __d = (source);                break; \
4048c2ecf20Sopenharmony_ci		case 2:	*(__be16 *) __d = cpu_to_be16(source); break; \
4058c2ecf20Sopenharmony_ci		case 4:	*(__be32 *) __d = cpu_to_be32(source); break; \
4068c2ecf20Sopenharmony_ci		case 8:	*(__be64 *) __d = cpu_to_be64(source); break; \
4078c2ecf20Sopenharmony_ci		default: __buggy_use_of_MTHCA_PUT();		      \
4088c2ecf20Sopenharmony_ci		}                                                     \
4098c2ecf20Sopenharmony_ci	} while (0)
4108c2ecf20Sopenharmony_ci
4118c2ecf20Sopenharmony_ciint mthca_reset(struct mthca_dev *mdev);
4128c2ecf20Sopenharmony_ci
4138c2ecf20Sopenharmony_ciu32 mthca_alloc(struct mthca_alloc *alloc);
4148c2ecf20Sopenharmony_civoid mthca_free(struct mthca_alloc *alloc, u32 obj);
4158c2ecf20Sopenharmony_ciint mthca_alloc_init(struct mthca_alloc *alloc, u32 num, u32 mask,
4168c2ecf20Sopenharmony_ci		     u32 reserved);
4178c2ecf20Sopenharmony_civoid mthca_alloc_cleanup(struct mthca_alloc *alloc);
4188c2ecf20Sopenharmony_civoid *mthca_array_get(struct mthca_array *array, int index);
4198c2ecf20Sopenharmony_ciint mthca_array_set(struct mthca_array *array, int index, void *value);
4208c2ecf20Sopenharmony_civoid mthca_array_clear(struct mthca_array *array, int index);
4218c2ecf20Sopenharmony_ciint mthca_array_init(struct mthca_array *array, int nent);
4228c2ecf20Sopenharmony_civoid mthca_array_cleanup(struct mthca_array *array, int nent);
4238c2ecf20Sopenharmony_ciint mthca_buf_alloc(struct mthca_dev *dev, int size, int max_direct,
4248c2ecf20Sopenharmony_ci		    union mthca_buf *buf, int *is_direct, struct mthca_pd *pd,
4258c2ecf20Sopenharmony_ci		    int hca_write, struct mthca_mr *mr);
4268c2ecf20Sopenharmony_civoid mthca_buf_free(struct mthca_dev *dev, int size, union mthca_buf *buf,
4278c2ecf20Sopenharmony_ci		    int is_direct, struct mthca_mr *mr);
4288c2ecf20Sopenharmony_ci
4298c2ecf20Sopenharmony_ciint mthca_init_uar_table(struct mthca_dev *dev);
4308c2ecf20Sopenharmony_ciint mthca_init_pd_table(struct mthca_dev *dev);
4318c2ecf20Sopenharmony_ciint mthca_init_mr_table(struct mthca_dev *dev);
4328c2ecf20Sopenharmony_ciint mthca_init_eq_table(struct mthca_dev *dev);
4338c2ecf20Sopenharmony_ciint mthca_init_cq_table(struct mthca_dev *dev);
4348c2ecf20Sopenharmony_ciint mthca_init_srq_table(struct mthca_dev *dev);
4358c2ecf20Sopenharmony_ciint mthca_init_qp_table(struct mthca_dev *dev);
4368c2ecf20Sopenharmony_ciint mthca_init_av_table(struct mthca_dev *dev);
4378c2ecf20Sopenharmony_ciint mthca_init_mcg_table(struct mthca_dev *dev);
4388c2ecf20Sopenharmony_ci
4398c2ecf20Sopenharmony_civoid mthca_cleanup_uar_table(struct mthca_dev *dev);
4408c2ecf20Sopenharmony_civoid mthca_cleanup_pd_table(struct mthca_dev *dev);
4418c2ecf20Sopenharmony_civoid mthca_cleanup_mr_table(struct mthca_dev *dev);
4428c2ecf20Sopenharmony_civoid mthca_cleanup_eq_table(struct mthca_dev *dev);
4438c2ecf20Sopenharmony_civoid mthca_cleanup_cq_table(struct mthca_dev *dev);
4448c2ecf20Sopenharmony_civoid mthca_cleanup_srq_table(struct mthca_dev *dev);
4458c2ecf20Sopenharmony_civoid mthca_cleanup_qp_table(struct mthca_dev *dev);
4468c2ecf20Sopenharmony_civoid mthca_cleanup_av_table(struct mthca_dev *dev);
4478c2ecf20Sopenharmony_civoid mthca_cleanup_mcg_table(struct mthca_dev *dev);
4488c2ecf20Sopenharmony_ci
4498c2ecf20Sopenharmony_ciint mthca_register_device(struct mthca_dev *dev);
4508c2ecf20Sopenharmony_civoid mthca_unregister_device(struct mthca_dev *dev);
4518c2ecf20Sopenharmony_ci
4528c2ecf20Sopenharmony_civoid mthca_start_catas_poll(struct mthca_dev *dev);
4538c2ecf20Sopenharmony_civoid mthca_stop_catas_poll(struct mthca_dev *dev);
4548c2ecf20Sopenharmony_ciint __mthca_restart_one(struct pci_dev *pdev);
4558c2ecf20Sopenharmony_ciint mthca_catas_init(void);
4568c2ecf20Sopenharmony_civoid mthca_catas_cleanup(void);
4578c2ecf20Sopenharmony_ci
4588c2ecf20Sopenharmony_ciint mthca_uar_alloc(struct mthca_dev *dev, struct mthca_uar *uar);
4598c2ecf20Sopenharmony_civoid mthca_uar_free(struct mthca_dev *dev, struct mthca_uar *uar);
4608c2ecf20Sopenharmony_ci
4618c2ecf20Sopenharmony_ciint mthca_pd_alloc(struct mthca_dev *dev, int privileged, struct mthca_pd *pd);
4628c2ecf20Sopenharmony_civoid mthca_pd_free(struct mthca_dev *dev, struct mthca_pd *pd);
4638c2ecf20Sopenharmony_ci
4648c2ecf20Sopenharmony_ciint mthca_write_mtt_size(struct mthca_dev *dev);
4658c2ecf20Sopenharmony_ci
4668c2ecf20Sopenharmony_cistruct mthca_mtt *mthca_alloc_mtt(struct mthca_dev *dev, int size);
4678c2ecf20Sopenharmony_civoid mthca_free_mtt(struct mthca_dev *dev, struct mthca_mtt *mtt);
4688c2ecf20Sopenharmony_ciint mthca_write_mtt(struct mthca_dev *dev, struct mthca_mtt *mtt,
4698c2ecf20Sopenharmony_ci		    int start_index, u64 *buffer_list, int list_len);
4708c2ecf20Sopenharmony_ciint mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
4718c2ecf20Sopenharmony_ci		   u64 iova, u64 total_size, u32 access, struct mthca_mr *mr);
4728c2ecf20Sopenharmony_ciint mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
4738c2ecf20Sopenharmony_ci			   u32 access, struct mthca_mr *mr);
4748c2ecf20Sopenharmony_ciint mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
4758c2ecf20Sopenharmony_ci			u64 *buffer_list, int buffer_size_shift,
4768c2ecf20Sopenharmony_ci			int list_len, u64 iova, u64 total_size,
4778c2ecf20Sopenharmony_ci			u32 access, struct mthca_mr *mr);
4788c2ecf20Sopenharmony_civoid mthca_free_mr(struct mthca_dev *dev,  struct mthca_mr *mr);
4798c2ecf20Sopenharmony_ci
4808c2ecf20Sopenharmony_ciint mthca_map_eq_icm(struct mthca_dev *dev, u64 icm_virt);
4818c2ecf20Sopenharmony_civoid mthca_unmap_eq_icm(struct mthca_dev *dev);
4828c2ecf20Sopenharmony_ci
4838c2ecf20Sopenharmony_ciint mthca_poll_cq(struct ib_cq *ibcq, int num_entries,
4848c2ecf20Sopenharmony_ci		  struct ib_wc *entry);
4858c2ecf20Sopenharmony_ciint mthca_tavor_arm_cq(struct ib_cq *cq, enum ib_cq_notify_flags flags);
4868c2ecf20Sopenharmony_ciint mthca_arbel_arm_cq(struct ib_cq *cq, enum ib_cq_notify_flags flags);
4878c2ecf20Sopenharmony_ciint mthca_init_cq(struct mthca_dev *dev, int nent,
4888c2ecf20Sopenharmony_ci		  struct mthca_ucontext *ctx, u32 pdn,
4898c2ecf20Sopenharmony_ci		  struct mthca_cq *cq);
4908c2ecf20Sopenharmony_civoid mthca_free_cq(struct mthca_dev *dev,
4918c2ecf20Sopenharmony_ci		   struct mthca_cq *cq);
4928c2ecf20Sopenharmony_civoid mthca_cq_completion(struct mthca_dev *dev, u32 cqn);
4938c2ecf20Sopenharmony_civoid mthca_cq_event(struct mthca_dev *dev, u32 cqn,
4948c2ecf20Sopenharmony_ci		    enum ib_event_type event_type);
4958c2ecf20Sopenharmony_civoid mthca_cq_clean(struct mthca_dev *dev, struct mthca_cq *cq, u32 qpn,
4968c2ecf20Sopenharmony_ci		    struct mthca_srq *srq);
4978c2ecf20Sopenharmony_civoid mthca_cq_resize_copy_cqes(struct mthca_cq *cq);
4988c2ecf20Sopenharmony_ciint mthca_alloc_cq_buf(struct mthca_dev *dev, struct mthca_cq_buf *buf, int nent);
4998c2ecf20Sopenharmony_civoid mthca_free_cq_buf(struct mthca_dev *dev, struct mthca_cq_buf *buf, int cqe);
5008c2ecf20Sopenharmony_ci
5018c2ecf20Sopenharmony_ciint mthca_alloc_srq(struct mthca_dev *dev, struct mthca_pd *pd,
5028c2ecf20Sopenharmony_ci		    struct ib_srq_attr *attr, struct mthca_srq *srq,
5038c2ecf20Sopenharmony_ci		    struct ib_udata *udata);
5048c2ecf20Sopenharmony_civoid mthca_free_srq(struct mthca_dev *dev, struct mthca_srq *srq);
5058c2ecf20Sopenharmony_ciint mthca_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr,
5068c2ecf20Sopenharmony_ci		     enum ib_srq_attr_mask attr_mask, struct ib_udata *udata);
5078c2ecf20Sopenharmony_ciint mthca_query_srq(struct ib_srq *srq, struct ib_srq_attr *srq_attr);
5088c2ecf20Sopenharmony_ciint mthca_max_srq_sge(struct mthca_dev *dev);
5098c2ecf20Sopenharmony_civoid mthca_srq_event(struct mthca_dev *dev, u32 srqn,
5108c2ecf20Sopenharmony_ci		     enum ib_event_type event_type);
5118c2ecf20Sopenharmony_civoid mthca_free_srq_wqe(struct mthca_srq *srq, u32 wqe_addr);
5128c2ecf20Sopenharmony_ciint mthca_tavor_post_srq_recv(struct ib_srq *srq, const struct ib_recv_wr *wr,
5138c2ecf20Sopenharmony_ci			      const struct ib_recv_wr **bad_wr);
5148c2ecf20Sopenharmony_ciint mthca_arbel_post_srq_recv(struct ib_srq *srq, const struct ib_recv_wr *wr,
5158c2ecf20Sopenharmony_ci			      const struct ib_recv_wr **bad_wr);
5168c2ecf20Sopenharmony_ci
5178c2ecf20Sopenharmony_civoid mthca_qp_event(struct mthca_dev *dev, u32 qpn,
5188c2ecf20Sopenharmony_ci		    enum ib_event_type event_type);
5198c2ecf20Sopenharmony_ciint mthca_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *qp_attr, int qp_attr_mask,
5208c2ecf20Sopenharmony_ci		   struct ib_qp_init_attr *qp_init_attr);
5218c2ecf20Sopenharmony_ciint mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask,
5228c2ecf20Sopenharmony_ci		    struct ib_udata *udata);
5238c2ecf20Sopenharmony_ciint mthca_tavor_post_send(struct ib_qp *ibqp, const struct ib_send_wr *wr,
5248c2ecf20Sopenharmony_ci			  const struct ib_send_wr **bad_wr);
5258c2ecf20Sopenharmony_ciint mthca_tavor_post_receive(struct ib_qp *ibqp, const struct ib_recv_wr *wr,
5268c2ecf20Sopenharmony_ci			     const struct ib_recv_wr **bad_wr);
5278c2ecf20Sopenharmony_ciint mthca_arbel_post_send(struct ib_qp *ibqp, const struct ib_send_wr *wr,
5288c2ecf20Sopenharmony_ci			  const struct ib_send_wr **bad_wr);
5298c2ecf20Sopenharmony_ciint mthca_arbel_post_receive(struct ib_qp *ibqp, const struct ib_recv_wr *wr,
5308c2ecf20Sopenharmony_ci			     const struct ib_recv_wr **bad_wr);
5318c2ecf20Sopenharmony_civoid mthca_free_err_wqe(struct mthca_dev *dev, struct mthca_qp *qp, int is_send,
5328c2ecf20Sopenharmony_ci			int index, int *dbd, __be32 *new_wqe);
5338c2ecf20Sopenharmony_ciint mthca_alloc_qp(struct mthca_dev *dev,
5348c2ecf20Sopenharmony_ci		   struct mthca_pd *pd,
5358c2ecf20Sopenharmony_ci		   struct mthca_cq *send_cq,
5368c2ecf20Sopenharmony_ci		   struct mthca_cq *recv_cq,
5378c2ecf20Sopenharmony_ci		   enum ib_qp_type type,
5388c2ecf20Sopenharmony_ci		   enum ib_sig_type send_policy,
5398c2ecf20Sopenharmony_ci		   struct ib_qp_cap *cap,
5408c2ecf20Sopenharmony_ci		   struct mthca_qp *qp,
5418c2ecf20Sopenharmony_ci		   struct ib_udata *udata);
5428c2ecf20Sopenharmony_ciint mthca_alloc_sqp(struct mthca_dev *dev,
5438c2ecf20Sopenharmony_ci		    struct mthca_pd *pd,
5448c2ecf20Sopenharmony_ci		    struct mthca_cq *send_cq,
5458c2ecf20Sopenharmony_ci		    struct mthca_cq *recv_cq,
5468c2ecf20Sopenharmony_ci		    enum ib_sig_type send_policy,
5478c2ecf20Sopenharmony_ci		    struct ib_qp_cap *cap,
5488c2ecf20Sopenharmony_ci		    int qpn,
5498c2ecf20Sopenharmony_ci		    int port,
5508c2ecf20Sopenharmony_ci		    struct mthca_qp *qp,
5518c2ecf20Sopenharmony_ci		    struct ib_udata *udata);
5528c2ecf20Sopenharmony_civoid mthca_free_qp(struct mthca_dev *dev, struct mthca_qp *qp);
5538c2ecf20Sopenharmony_ciint mthca_create_ah(struct mthca_dev *dev,
5548c2ecf20Sopenharmony_ci		    struct mthca_pd *pd,
5558c2ecf20Sopenharmony_ci		    struct rdma_ah_attr *ah_attr,
5568c2ecf20Sopenharmony_ci		    struct mthca_ah *ah);
5578c2ecf20Sopenharmony_ciint mthca_destroy_ah(struct mthca_dev *dev, struct mthca_ah *ah);
5588c2ecf20Sopenharmony_ciint mthca_read_ah(struct mthca_dev *dev, struct mthca_ah *ah,
5598c2ecf20Sopenharmony_ci		  struct ib_ud_header *header);
5608c2ecf20Sopenharmony_ciint mthca_ah_query(struct ib_ah *ibah, struct rdma_ah_attr *attr);
5618c2ecf20Sopenharmony_ciint mthca_ah_grh_present(struct mthca_ah *ah);
5628c2ecf20Sopenharmony_ciu8 mthca_get_rate(struct mthca_dev *dev, int static_rate, u8 port);
5638c2ecf20Sopenharmony_cienum ib_rate mthca_rate_to_ib(struct mthca_dev *dev, u8 mthca_rate, u8 port);
5648c2ecf20Sopenharmony_ci
5658c2ecf20Sopenharmony_ciint mthca_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid);
5668c2ecf20Sopenharmony_ciint mthca_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid);
5678c2ecf20Sopenharmony_ci
5688c2ecf20Sopenharmony_ciint mthca_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
5698c2ecf20Sopenharmony_ci		      const struct ib_wc *in_wc, const struct ib_grh *in_grh,
5708c2ecf20Sopenharmony_ci		      const struct ib_mad *in, struct ib_mad *out,
5718c2ecf20Sopenharmony_ci		      size_t *out_mad_size, u16 *out_mad_pkey_index);
5728c2ecf20Sopenharmony_ciint mthca_create_agents(struct mthca_dev *dev);
5738c2ecf20Sopenharmony_civoid mthca_free_agents(struct mthca_dev *dev);
5748c2ecf20Sopenharmony_ci
5758c2ecf20Sopenharmony_cistatic inline struct mthca_dev *to_mdev(struct ib_device *ibdev)
5768c2ecf20Sopenharmony_ci{
5778c2ecf20Sopenharmony_ci	return container_of(ibdev, struct mthca_dev, ib_dev);
5788c2ecf20Sopenharmony_ci}
5798c2ecf20Sopenharmony_ci
5808c2ecf20Sopenharmony_cistatic inline int mthca_is_memfree(struct mthca_dev *dev)
5818c2ecf20Sopenharmony_ci{
5828c2ecf20Sopenharmony_ci	return dev->mthca_flags & MTHCA_FLAG_MEMFREE;
5838c2ecf20Sopenharmony_ci}
5848c2ecf20Sopenharmony_ci
5858c2ecf20Sopenharmony_ci#endif /* MTHCA_DEV_H */
586