11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.
3cd4e8fb4STom Duffy * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
44885bf64SRoland Dreier * Copyright (c) 2005, 2006 Cisco Systems. All rights reserved.
52a1d9b7fSRoland Dreier * Copyright (c) 2005 Mellanox Technologies. All rights reserved.
62a1d9b7fSRoland Dreier * Copyright (c) 2004 Voltaire, Inc. All rights reserved.
71da177e4SLinus Torvalds *
81da177e4SLinus Torvalds * This software is available to you under a choice of one of two
91da177e4SLinus Torvalds * licenses. You may choose to be licensed under the terms of the GNU
101da177e4SLinus Torvalds * General Public License (GPL) Version 2, available from the file
111da177e4SLinus Torvalds * COPYING in the main directory of this source tree, or the
121da177e4SLinus Torvalds * OpenIB.org BSD license below:
131da177e4SLinus Torvalds *
141da177e4SLinus Torvalds * Redistribution and use in source and binary forms, with or
151da177e4SLinus Torvalds * without modification, are permitted provided that the following
161da177e4SLinus Torvalds * conditions are met:
171da177e4SLinus Torvalds *
181da177e4SLinus Torvalds * - Redistributions of source code must retain the above
191da177e4SLinus Torvalds * copyright notice, this list of conditions and the following
201da177e4SLinus Torvalds * disclaimer.
211da177e4SLinus Torvalds *
221da177e4SLinus Torvalds * - Redistributions in binary form must reproduce the above
231da177e4SLinus Torvalds * copyright notice, this list of conditions and the following
241da177e4SLinus Torvalds * disclaimer in the documentation and/or other materials
251da177e4SLinus Torvalds * provided with the distribution.
261da177e4SLinus Torvalds *
271da177e4SLinus Torvalds * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
281da177e4SLinus Torvalds * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
291da177e4SLinus Torvalds * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
301da177e4SLinus Torvalds * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
311da177e4SLinus Torvalds * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
321da177e4SLinus Torvalds * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
331da177e4SLinus Torvalds * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
341da177e4SLinus Torvalds * SOFTWARE.
351da177e4SLinus Torvalds */
361da177e4SLinus Torvalds
371da177e4SLinus Torvalds #ifndef MTHCA_DEV_H
381da177e4SLinus Torvalds #define MTHCA_DEV_H
391da177e4SLinus Torvalds
401da177e4SLinus Torvalds #include <linux/spinlock.h>
411da177e4SLinus Torvalds #include <linux/kernel.h>
421da177e4SLinus Torvalds #include <linux/pci.h>
431da177e4SLinus Torvalds #include <linux/dma-mapping.h>
44de25968cSTim Schmielau #include <linux/timer.h>
45fd9cfdd1SRoland Dreier #include <linux/mutex.h>
46b3b30f5eSJack Morgenstein #include <linux/list.h>
476188e10dSMatthew Wilcox #include <linux/semaphore.h>
481da177e4SLinus Torvalds
491da177e4SLinus Torvalds #include "mthca_provider.h"
501da177e4SLinus Torvalds #include "mthca_doorbell.h"
511da177e4SLinus Torvalds
521da177e4SLinus Torvalds #define DRV_NAME "ib_mthca"
531da177e4SLinus Torvalds #define PFX DRV_NAME ": "
54940801b2SJack Morgenstein #define DRV_VERSION "1.0"
55940801b2SJack Morgenstein #define DRV_RELDATE "April 4, 2008"
561da177e4SLinus Torvalds
571da177e4SLinus Torvalds enum {
581da177e4SLinus Torvalds MTHCA_FLAG_DDR_HIDDEN = 1 << 1,
591da177e4SLinus Torvalds MTHCA_FLAG_SRQ = 1 << 2,
60e57895d3SAdrian Bunk MTHCA_FLAG_MSI_X = 1 << 3,
61e57895d3SAdrian Bunk MTHCA_FLAG_NO_LAM = 1 << 4,
62e57895d3SAdrian Bunk MTHCA_FLAG_FMR = 1 << 5,
63e57895d3SAdrian Bunk MTHCA_FLAG_MEMFREE = 1 << 6,
64e57895d3SAdrian Bunk MTHCA_FLAG_PCIE = 1 << 7,
65e57895d3SAdrian Bunk MTHCA_FLAG_SINAI_OPT = 1 << 8
661da177e4SLinus Torvalds };
671da177e4SLinus Torvalds
681da177e4SLinus Torvalds enum {
691da177e4SLinus Torvalds MTHCA_MAX_PORTS = 2
701da177e4SLinus Torvalds };
711da177e4SLinus Torvalds
721da177e4SLinus Torvalds enum {
732e8b981cSMichael S. Tsirkin MTHCA_BOARD_ID_LEN = 64
742e8b981cSMichael S. Tsirkin };
752e8b981cSMichael S. Tsirkin
762e8b981cSMichael S. Tsirkin enum {
771da177e4SLinus Torvalds MTHCA_EQ_CONTEXT_SIZE = 0x40,
781da177e4SLinus Torvalds MTHCA_CQ_CONTEXT_SIZE = 0x40,
791da177e4SLinus Torvalds MTHCA_QP_CONTEXT_SIZE = 0x200,
801da177e4SLinus Torvalds MTHCA_RDB_ENTRY_SIZE = 0x20,
811da177e4SLinus Torvalds MTHCA_AV_SIZE = 0x20,
821a1eb6a6SRoland Dreier MTHCA_MGM_ENTRY_SIZE = 0x100,
831da177e4SLinus Torvalds
841da177e4SLinus Torvalds /* Arbel FW gives us these, but we need them for Tavor */
851da177e4SLinus Torvalds MTHCA_MPT_ENTRY_SIZE = 0x40,
861da177e4SLinus Torvalds MTHCA_MTT_SEG_SIZE = 0x40,
87efaae8f7SJack Morgenstein
88efaae8f7SJack Morgenstein MTHCA_QP_PER_MGM = 4 * (MTHCA_MGM_ENTRY_SIZE / 16 - 2)
891da177e4SLinus Torvalds };
901da177e4SLinus Torvalds
911da177e4SLinus Torvalds enum {
921da177e4SLinus Torvalds MTHCA_EQ_CMD,
931da177e4SLinus Torvalds MTHCA_EQ_ASYNC,
941da177e4SLinus Torvalds MTHCA_EQ_COMP,
951da177e4SLinus Torvalds MTHCA_NUM_EQ
961da177e4SLinus Torvalds };
971da177e4SLinus Torvalds
982a4443a6SMichael S. Tsirkin enum {
992a4443a6SMichael S. Tsirkin MTHCA_OPCODE_NOP = 0x00,
1002a4443a6SMichael S. Tsirkin MTHCA_OPCODE_RDMA_WRITE = 0x08,
1012a4443a6SMichael S. Tsirkin MTHCA_OPCODE_RDMA_WRITE_IMM = 0x09,
1022a4443a6SMichael S. Tsirkin MTHCA_OPCODE_SEND = 0x0a,
1032a4443a6SMichael S. Tsirkin MTHCA_OPCODE_SEND_IMM = 0x0b,
1042a4443a6SMichael S. Tsirkin MTHCA_OPCODE_RDMA_READ = 0x10,
1052a4443a6SMichael S. Tsirkin MTHCA_OPCODE_ATOMIC_CS = 0x11,
1062a4443a6SMichael S. Tsirkin MTHCA_OPCODE_ATOMIC_FA = 0x12,
1072a4443a6SMichael S. Tsirkin MTHCA_OPCODE_BIND_MW = 0x18,
1082a4443a6SMichael S. Tsirkin };
1092a4443a6SMichael S. Tsirkin
11014abdffcSEli Cohen enum {
11114abdffcSEli Cohen MTHCA_CMD_USE_EVENTS = 1 << 0,
11214abdffcSEli Cohen MTHCA_CMD_POST_DOORBELLS = 1 << 1
11314abdffcSEli Cohen };
11414abdffcSEli Cohen
11514abdffcSEli Cohen enum {
11614abdffcSEli Cohen MTHCA_CMD_NUM_DBELL_DWORDS = 8
11714abdffcSEli Cohen };
11814abdffcSEli Cohen
1191da177e4SLinus Torvalds struct mthca_cmd {
12011880a55SRomain Perier struct dma_pool *pool;
121fd9cfdd1SRoland Dreier struct mutex hcr_mutex;
1221da177e4SLinus Torvalds struct semaphore poll_sem;
1231da177e4SLinus Torvalds struct semaphore event_sem;
1241da177e4SLinus Torvalds int max_cmds;
1251da177e4SLinus Torvalds spinlock_t context_lock;
1261da177e4SLinus Torvalds int free_head;
1271da177e4SLinus Torvalds struct mthca_cmd_context *context;
1281da177e4SLinus Torvalds u16 token_mask;
12914abdffcSEli Cohen u32 flags;
13014abdffcSEli Cohen void __iomem *dbell_map;
13114abdffcSEli Cohen u16 dbell_offsets[MTHCA_CMD_NUM_DBELL_DWORDS];
1321da177e4SLinus Torvalds };
1331da177e4SLinus Torvalds
1341da177e4SLinus Torvalds struct mthca_limits {
1351da177e4SLinus Torvalds int num_ports;
1361da177e4SLinus Torvalds int vl_cap;
1371da177e4SLinus Torvalds int mtu_cap;
1381da177e4SLinus Torvalds int gid_table_len;
1391da177e4SLinus Torvalds int pkey_table_len;
1401da177e4SLinus Torvalds int local_ca_ack_delay;
1411da177e4SLinus Torvalds int num_uars;
1421da177e4SLinus Torvalds int max_sg;
1431da177e4SLinus Torvalds int num_qps;
144efaae8f7SJack Morgenstein int max_wqes;
14577369ed3SJack Morgenstein int max_desc_sz;
146efaae8f7SJack Morgenstein int max_qp_init_rdma;
1471da177e4SLinus Torvalds int reserved_qps;
1481da177e4SLinus Torvalds int num_srqs;
149efaae8f7SJack Morgenstein int max_srq_wqes;
15059fef3b1SJack Morgenstein int max_srq_sge;
1511da177e4SLinus Torvalds int reserved_srqs;
1521da177e4SLinus Torvalds int num_eecs;
1531da177e4SLinus Torvalds int reserved_eecs;
1541da177e4SLinus Torvalds int num_cqs;
155efaae8f7SJack Morgenstein int max_cqes;
1561da177e4SLinus Torvalds int reserved_cqs;
1571da177e4SLinus Torvalds int num_eqs;
1581da177e4SLinus Torvalds int reserved_eqs;
1591da177e4SLinus Torvalds int num_mpts;
1601da177e4SLinus Torvalds int num_mtt_segs;
161c1f67a88SEli Cohen int mtt_seg_size;
162e0f5fdcaSMichael S. Tsirkin int fmr_reserved_mtts;
1631da177e4SLinus Torvalds int reserved_mtts;
1641da177e4SLinus Torvalds int reserved_mrws;
1651da177e4SLinus Torvalds int reserved_uars;
1661da177e4SLinus Torvalds int num_mgms;
1671da177e4SLinus Torvalds int num_amgms;
1681da177e4SLinus Torvalds int reserved_mcgs;
1691da177e4SLinus Torvalds int num_pds;
1701da177e4SLinus Torvalds int reserved_pds;
1710f69ce1eSJack Morgenstein u32 page_size_cap;
17233033b79SJack Morgenstein u32 flags;
173bf6a9e31SJack Morgenstein u16 stat_rate_support;
174da6561c2SRoland Dreier u8 port_width_cap;
1751da177e4SLinus Torvalds };
1761da177e4SLinus Torvalds
1771da177e4SLinus Torvalds struct mthca_alloc {
1781da177e4SLinus Torvalds u32 last;
1791da177e4SLinus Torvalds u32 top;
1801da177e4SLinus Torvalds u32 max;
1811da177e4SLinus Torvalds u32 mask;
1821da177e4SLinus Torvalds spinlock_t lock;
1831da177e4SLinus Torvalds unsigned long *table;
1841da177e4SLinus Torvalds };
1851da177e4SLinus Torvalds
1861da177e4SLinus Torvalds struct mthca_array {
1871da177e4SLinus Torvalds struct {
1881da177e4SLinus Torvalds void **page;
1891da177e4SLinus Torvalds int used;
1901da177e4SLinus Torvalds } *page_list;
1911da177e4SLinus Torvalds };
1921da177e4SLinus Torvalds
1931da177e4SLinus Torvalds struct mthca_uar_table {
1941da177e4SLinus Torvalds struct mthca_alloc alloc;
1951da177e4SLinus Torvalds u64 uarc_base;
1961da177e4SLinus Torvalds int uarc_size;
1971da177e4SLinus Torvalds };
1981da177e4SLinus Torvalds
1991da177e4SLinus Torvalds struct mthca_pd_table {
2001da177e4SLinus Torvalds struct mthca_alloc alloc;
2011da177e4SLinus Torvalds };
2021da177e4SLinus Torvalds
2039095e208SMichael S. Tsirkin struct mthca_buddy {
2049095e208SMichael S. Tsirkin unsigned long **bits;
205e8bb4bebSRoland Dreier int *num_free;
2069095e208SMichael S. Tsirkin int max_order;
2079095e208SMichael S. Tsirkin spinlock_t lock;
2089095e208SMichael S. Tsirkin };
2099095e208SMichael S. Tsirkin
2101da177e4SLinus Torvalds struct mthca_mr_table {
2111da177e4SLinus Torvalds struct mthca_alloc mpt_alloc;
2129095e208SMichael S. Tsirkin struct mthca_buddy mtt_buddy;
213e0f5fdcaSMichael S. Tsirkin struct mthca_buddy *fmr_mtt_buddy;
2141da177e4SLinus Torvalds u64 mtt_base;
215e0f5fdcaSMichael S. Tsirkin u64 mpt_base;
2161da177e4SLinus Torvalds struct mthca_icm_table *mtt_table;
2171da177e4SLinus Torvalds struct mthca_icm_table *mpt_table;
218e0f5fdcaSMichael S. Tsirkin struct {
219e0f5fdcaSMichael S. Tsirkin void __iomem *mpt_base;
220e0f5fdcaSMichael S. Tsirkin void __iomem *mtt_base;
221e0f5fdcaSMichael S. Tsirkin struct mthca_buddy mtt_buddy;
222e0f5fdcaSMichael S. Tsirkin } tavor_fmr;
2231da177e4SLinus Torvalds };
2241da177e4SLinus Torvalds
2251da177e4SLinus Torvalds struct mthca_eq_table {
2261da177e4SLinus Torvalds struct mthca_alloc alloc;
2271da177e4SLinus Torvalds void __iomem *clr_int;
2281da177e4SLinus Torvalds u32 clr_mask;
2291da177e4SLinus Torvalds u32 arm_mask;
2301da177e4SLinus Torvalds struct mthca_eq eq[MTHCA_NUM_EQ];
2311da177e4SLinus Torvalds u64 icm_virt;
2321da177e4SLinus Torvalds struct page *icm_page;
2331da177e4SLinus Torvalds dma_addr_t icm_dma;
2341da177e4SLinus Torvalds int have_irq;
2351da177e4SLinus Torvalds u8 inta_pin;
2361da177e4SLinus Torvalds };
2371da177e4SLinus Torvalds
2381da177e4SLinus Torvalds struct mthca_cq_table {
2391da177e4SLinus Torvalds struct mthca_alloc alloc;
2401da177e4SLinus Torvalds spinlock_t lock;
2411da177e4SLinus Torvalds struct mthca_array cq;
2421da177e4SLinus Torvalds struct mthca_icm_table *table;
2431da177e4SLinus Torvalds };
2441da177e4SLinus Torvalds
245ec34a922SRoland Dreier struct mthca_srq_table {
246ec34a922SRoland Dreier struct mthca_alloc alloc;
247ec34a922SRoland Dreier spinlock_t lock;
248ec34a922SRoland Dreier struct mthca_array srq;
249ec34a922SRoland Dreier struct mthca_icm_table *table;
250ec34a922SRoland Dreier };
251ec34a922SRoland Dreier
2521da177e4SLinus Torvalds struct mthca_qp_table {
2531da177e4SLinus Torvalds struct mthca_alloc alloc;
2541da177e4SLinus Torvalds u32 rdb_base;
2551da177e4SLinus Torvalds int rdb_shift;
2561da177e4SLinus Torvalds int sqp_start;
2571da177e4SLinus Torvalds spinlock_t lock;
2581da177e4SLinus Torvalds struct mthca_array qp;
2591da177e4SLinus Torvalds struct mthca_icm_table *qp_table;
2601da177e4SLinus Torvalds struct mthca_icm_table *eqp_table;
26108aeb14eSRoland Dreier struct mthca_icm_table *rdb_table;
2621da177e4SLinus Torvalds };
2631da177e4SLinus Torvalds
2641da177e4SLinus Torvalds struct mthca_av_table {
26511880a55SRomain Perier struct dma_pool *pool;
2661da177e4SLinus Torvalds int num_ddr_avs;
2671da177e4SLinus Torvalds u64 ddr_av_base;
2681da177e4SLinus Torvalds void __iomem *av_map;
2691da177e4SLinus Torvalds struct mthca_alloc alloc;
2701da177e4SLinus Torvalds };
2711da177e4SLinus Torvalds
2721da177e4SLinus Torvalds struct mthca_mcg_table {
273fd9cfdd1SRoland Dreier struct mutex mutex;
2741da177e4SLinus Torvalds struct mthca_alloc alloc;
2751da177e4SLinus Torvalds struct mthca_icm_table *table;
2761da177e4SLinus Torvalds };
2771da177e4SLinus Torvalds
2783d155f8cSRoland Dreier struct mthca_catas_err {
2793d155f8cSRoland Dreier u64 addr;
2803d155f8cSRoland Dreier u32 __iomem *map;
2813d155f8cSRoland Dreier u32 size;
2823d155f8cSRoland Dreier struct timer_list timer;
283b3b30f5eSJack Morgenstein struct list_head list;
2843d155f8cSRoland Dreier };
2853d155f8cSRoland Dreier
286b3b30f5eSJack Morgenstein extern struct mutex mthca_device_mutex;
287b3b30f5eSJack Morgenstein
2881da177e4SLinus Torvalds struct mthca_dev {
2891da177e4SLinus Torvalds struct ib_device ib_dev;
2901da177e4SLinus Torvalds struct pci_dev *pdev;
2911da177e4SLinus Torvalds
2921da177e4SLinus Torvalds int hca_type;
2931da177e4SLinus Torvalds unsigned long mthca_flags;
2941da177e4SLinus Torvalds unsigned long device_cap_flags;
2951da177e4SLinus Torvalds
2961da177e4SLinus Torvalds u32 rev_id;
2972e8b981cSMichael S. Tsirkin char board_id[MTHCA_BOARD_ID_LEN];
2981da177e4SLinus Torvalds
2991da177e4SLinus Torvalds /* firmware info */
3001da177e4SLinus Torvalds u64 fw_ver;
3011da177e4SLinus Torvalds union {
3021da177e4SLinus Torvalds struct {
3031da177e4SLinus Torvalds u64 fw_start;
3041da177e4SLinus Torvalds u64 fw_end;
3051da177e4SLinus Torvalds } tavor;
3061da177e4SLinus Torvalds struct {
3071da177e4SLinus Torvalds u64 clr_int_base;
3081da177e4SLinus Torvalds u64 eq_arm_base;
3091da177e4SLinus Torvalds u64 eq_set_ci_base;
3101da177e4SLinus Torvalds struct mthca_icm *fw_icm;
3111da177e4SLinus Torvalds struct mthca_icm *aux_icm;
3121da177e4SLinus Torvalds u16 fw_pages;
3131da177e4SLinus Torvalds } arbel;
3141da177e4SLinus Torvalds } fw;
3151da177e4SLinus Torvalds
3161da177e4SLinus Torvalds u64 ddr_start;
3171da177e4SLinus Torvalds u64 ddr_end;
3181da177e4SLinus Torvalds
3191da177e4SLinus Torvalds MTHCA_DECLARE_DOORBELL_LOCK(doorbell_lock)
320fd9cfdd1SRoland Dreier struct mutex cap_mask_mutex;
3211da177e4SLinus Torvalds
3221da177e4SLinus Torvalds void __iomem *hcr;
3231da177e4SLinus Torvalds void __iomem *kar;
3241da177e4SLinus Torvalds void __iomem *clr_base;
3251da177e4SLinus Torvalds union {
3261da177e4SLinus Torvalds struct {
3271da177e4SLinus Torvalds void __iomem *ecr_base;
3281da177e4SLinus Torvalds } tavor;
3291da177e4SLinus Torvalds struct {
3301da177e4SLinus Torvalds void __iomem *eq_arm;
3311da177e4SLinus Torvalds void __iomem *eq_set_ci_base;
3321da177e4SLinus Torvalds } arbel;
3331da177e4SLinus Torvalds } eq_regs;
3341da177e4SLinus Torvalds
3351da177e4SLinus Torvalds struct mthca_cmd cmd;
3361da177e4SLinus Torvalds struct mthca_limits limits;
3371da177e4SLinus Torvalds
3381da177e4SLinus Torvalds struct mthca_uar_table uar_table;
3391da177e4SLinus Torvalds struct mthca_pd_table pd_table;
3401da177e4SLinus Torvalds struct mthca_mr_table mr_table;
3411da177e4SLinus Torvalds struct mthca_eq_table eq_table;
3421da177e4SLinus Torvalds struct mthca_cq_table cq_table;
343ec34a922SRoland Dreier struct mthca_srq_table srq_table;
3441da177e4SLinus Torvalds struct mthca_qp_table qp_table;
3451da177e4SLinus Torvalds struct mthca_av_table av_table;
3461da177e4SLinus Torvalds struct mthca_mcg_table mcg_table;
3471da177e4SLinus Torvalds
3483d155f8cSRoland Dreier struct mthca_catas_err catas_err;
3493d155f8cSRoland Dreier
3501da177e4SLinus Torvalds struct mthca_uar driver_uar;
3511da177e4SLinus Torvalds struct mthca_db_table *db_tab;
3521da177e4SLinus Torvalds struct mthca_pd driver_pd;
3531da177e4SLinus Torvalds struct mthca_mr driver_mr;
3541da177e4SLinus Torvalds
3551da177e4SLinus Torvalds struct ib_mad_agent *send_agent[MTHCA_MAX_PORTS][2];
3561da177e4SLinus Torvalds struct ib_ah *sm_ah[MTHCA_MAX_PORTS];
3571da177e4SLinus Torvalds spinlock_t sm_lock;
358bf6a9e31SJack Morgenstein u8 rate[MTHCA_MAX_PORTS];
359d8410647SJack Morgenstein bool active;
3601da177e4SLinus Torvalds };
3611da177e4SLinus Torvalds
362227c939bSRoland Dreier #ifdef CONFIG_INFINIBAND_MTHCA_DEBUG
363227c939bSRoland Dreier extern int mthca_debug_level;
364227c939bSRoland Dreier
3651da177e4SLinus Torvalds #define mthca_dbg(mdev, format, arg...) \
366227c939bSRoland Dreier do { \
367227c939bSRoland Dreier if (mthca_debug_level) \
368227c939bSRoland Dreier dev_printk(KERN_DEBUG, &mdev->pdev->dev, format, ## arg); \
369227c939bSRoland Dreier } while (0)
370227c939bSRoland Dreier
371227c939bSRoland Dreier #else /* CONFIG_INFINIBAND_MTHCA_DEBUG */
372227c939bSRoland Dreier
373227c939bSRoland Dreier #define mthca_dbg(mdev, format, arg...) do { (void) mdev; } while (0)
374227c939bSRoland Dreier
375227c939bSRoland Dreier #endif /* CONFIG_INFINIBAND_MTHCA_DEBUG */
376227c939bSRoland Dreier
3771da177e4SLinus Torvalds #define mthca_err(mdev, format, arg...) \
3781da177e4SLinus Torvalds dev_err(&mdev->pdev->dev, format, ## arg)
3791da177e4SLinus Torvalds #define mthca_info(mdev, format, arg...) \
3801da177e4SLinus Torvalds dev_info(&mdev->pdev->dev, format, ## arg)
3811da177e4SLinus Torvalds #define mthca_warn(mdev, format, arg...) \
3821da177e4SLinus Torvalds dev_warn(&mdev->pdev->dev, format, ## arg)
3831da177e4SLinus Torvalds
3841da177e4SLinus Torvalds extern void __buggy_use_of_MTHCA_GET(void);
3851da177e4SLinus Torvalds extern void __buggy_use_of_MTHCA_PUT(void);
3861da177e4SLinus Torvalds
3871da177e4SLinus Torvalds #define MTHCA_GET(dest, source, offset) \
3881da177e4SLinus Torvalds do { \
3891da177e4SLinus Torvalds void *__p = (char *) (source) + (offset); \
3901da177e4SLinus Torvalds switch (sizeof (dest)) { \
3911da177e4SLinus Torvalds case 1: (dest) = *(u8 *) __p; break; \
3921da177e4SLinus Torvalds case 2: (dest) = be16_to_cpup(__p); break; \
3931da177e4SLinus Torvalds case 4: (dest) = be32_to_cpup(__p); break; \
3941da177e4SLinus Torvalds case 8: (dest) = be64_to_cpup(__p); break; \
3951da177e4SLinus Torvalds default: __buggy_use_of_MTHCA_GET(); \
3961da177e4SLinus Torvalds } \
3971da177e4SLinus Torvalds } while (0)
3981da177e4SLinus Torvalds
3991da177e4SLinus Torvalds #define MTHCA_PUT(dest, source, offset) \
4001da177e4SLinus Torvalds do { \
40197f52eb4SSean Hefty void *__d = ((char *) (dest) + (offset)); \
4021da177e4SLinus Torvalds switch (sizeof(source)) { \
40397f52eb4SSean Hefty case 1: *(u8 *) __d = (source); break; \
40497f52eb4SSean Hefty case 2: *(__be16 *) __d = cpu_to_be16(source); break; \
40597f52eb4SSean Hefty case 4: *(__be32 *) __d = cpu_to_be32(source); break; \
40697f52eb4SSean Hefty case 8: *(__be64 *) __d = cpu_to_be64(source); break; \
4071da177e4SLinus Torvalds default: __buggy_use_of_MTHCA_PUT(); \
4081da177e4SLinus Torvalds } \
4091da177e4SLinus Torvalds } while (0)
4101da177e4SLinus Torvalds
4111da177e4SLinus Torvalds int mthca_reset(struct mthca_dev *mdev);
4121da177e4SLinus Torvalds
4131da177e4SLinus Torvalds u32 mthca_alloc(struct mthca_alloc *alloc);
4141da177e4SLinus Torvalds void mthca_free(struct mthca_alloc *alloc, u32 obj);
4151da177e4SLinus Torvalds int mthca_alloc_init(struct mthca_alloc *alloc, u32 num, u32 mask,
4161da177e4SLinus Torvalds u32 reserved);
4171da177e4SLinus Torvalds void mthca_alloc_cleanup(struct mthca_alloc *alloc);
4181da177e4SLinus Torvalds void *mthca_array_get(struct mthca_array *array, int index);
4191da177e4SLinus Torvalds int mthca_array_set(struct mthca_array *array, int index, void *value);
4201da177e4SLinus Torvalds void mthca_array_clear(struct mthca_array *array, int index);
4211da177e4SLinus Torvalds int mthca_array_init(struct mthca_array *array, int nent);
4221da177e4SLinus Torvalds void mthca_array_cleanup(struct mthca_array *array, int nent);
42387b81670SRoland Dreier int mthca_buf_alloc(struct mthca_dev *dev, int size, int max_direct,
42487b81670SRoland Dreier union mthca_buf *buf, int *is_direct, struct mthca_pd *pd,
42587b81670SRoland Dreier int hca_write, struct mthca_mr *mr);
42687b81670SRoland Dreier void mthca_buf_free(struct mthca_dev *dev, int size, union mthca_buf *buf,
42787b81670SRoland Dreier int is_direct, struct mthca_mr *mr);
4281da177e4SLinus Torvalds
4291da177e4SLinus Torvalds int mthca_init_uar_table(struct mthca_dev *dev);
4301da177e4SLinus Torvalds int mthca_init_pd_table(struct mthca_dev *dev);
4311da177e4SLinus Torvalds int mthca_init_mr_table(struct mthca_dev *dev);
4321da177e4SLinus Torvalds int mthca_init_eq_table(struct mthca_dev *dev);
4331da177e4SLinus Torvalds int mthca_init_cq_table(struct mthca_dev *dev);
434ec34a922SRoland Dreier int mthca_init_srq_table(struct mthca_dev *dev);
4351da177e4SLinus Torvalds int mthca_init_qp_table(struct mthca_dev *dev);
4361da177e4SLinus Torvalds int mthca_init_av_table(struct mthca_dev *dev);
4371da177e4SLinus Torvalds int mthca_init_mcg_table(struct mthca_dev *dev);
4381da177e4SLinus Torvalds
4391da177e4SLinus Torvalds void mthca_cleanup_uar_table(struct mthca_dev *dev);
4401da177e4SLinus Torvalds void mthca_cleanup_pd_table(struct mthca_dev *dev);
4411da177e4SLinus Torvalds void mthca_cleanup_mr_table(struct mthca_dev *dev);
4421da177e4SLinus Torvalds void mthca_cleanup_eq_table(struct mthca_dev *dev);
4431da177e4SLinus Torvalds void mthca_cleanup_cq_table(struct mthca_dev *dev);
444ec34a922SRoland Dreier void mthca_cleanup_srq_table(struct mthca_dev *dev);
4451da177e4SLinus Torvalds void mthca_cleanup_qp_table(struct mthca_dev *dev);
4461da177e4SLinus Torvalds void mthca_cleanup_av_table(struct mthca_dev *dev);
4471da177e4SLinus Torvalds void mthca_cleanup_mcg_table(struct mthca_dev *dev);
4481da177e4SLinus Torvalds
4491da177e4SLinus Torvalds int mthca_register_device(struct mthca_dev *dev);
4501da177e4SLinus Torvalds void mthca_unregister_device(struct mthca_dev *dev);
4511da177e4SLinus Torvalds
4523d155f8cSRoland Dreier void mthca_start_catas_poll(struct mthca_dev *dev);
4533d155f8cSRoland Dreier void mthca_stop_catas_poll(struct mthca_dev *dev);
454b3b30f5eSJack Morgenstein int __mthca_restart_one(struct pci_dev *pdev);
455b3b30f5eSJack Morgenstein int mthca_catas_init(void);
456b3b30f5eSJack Morgenstein void mthca_catas_cleanup(void);
4573d155f8cSRoland Dreier
4581da177e4SLinus Torvalds int mthca_uar_alloc(struct mthca_dev *dev, struct mthca_uar *uar);
4591da177e4SLinus Torvalds void mthca_uar_free(struct mthca_dev *dev, struct mthca_uar *uar);
4601da177e4SLinus Torvalds
46199264c1eSRoland Dreier int mthca_pd_alloc(struct mthca_dev *dev, int privileged, struct mthca_pd *pd);
4621da177e4SLinus Torvalds void mthca_pd_free(struct mthca_dev *dev, struct mthca_pd *pd);
4631da177e4SLinus Torvalds
464b2875d4cSMichael S. Tsirkin int mthca_write_mtt_size(struct mthca_dev *dev);
465b2875d4cSMichael S. Tsirkin
466d56d6f95SRoland Dreier struct mthca_mtt *mthca_alloc_mtt(struct mthca_dev *dev, int size);
467d56d6f95SRoland Dreier void mthca_free_mtt(struct mthca_dev *dev, struct mthca_mtt *mtt);
468d56d6f95SRoland Dreier int mthca_write_mtt(struct mthca_dev *dev, struct mthca_mtt *mtt,
469d56d6f95SRoland Dreier int start_index, u64 *buffer_list, int list_len);
470d56d6f95SRoland Dreier int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
471d56d6f95SRoland Dreier u64 iova, u64 total_size, u32 access, struct mthca_mr *mr);
4721da177e4SLinus Torvalds int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
4731da177e4SLinus Torvalds u32 access, struct mthca_mr *mr);
4741da177e4SLinus Torvalds int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
4751da177e4SLinus Torvalds u64 *buffer_list, int buffer_size_shift,
4761da177e4SLinus Torvalds int list_len, u64 iova, u64 total_size,
4771da177e4SLinus Torvalds u32 access, struct mthca_mr *mr);
4781da177e4SLinus Torvalds void mthca_free_mr(struct mthca_dev *dev, struct mthca_mr *mr);
4791da177e4SLinus Torvalds
4801da177e4SLinus Torvalds int mthca_map_eq_icm(struct mthca_dev *dev, u64 icm_virt);
4811da177e4SLinus Torvalds void mthca_unmap_eq_icm(struct mthca_dev *dev);
4821da177e4SLinus Torvalds
4831da177e4SLinus Torvalds int mthca_poll_cq(struct ib_cq *ibcq, int num_entries,
4841da177e4SLinus Torvalds struct ib_wc *entry);
485ed23a727SRoland Dreier int mthca_tavor_arm_cq(struct ib_cq *cq, enum ib_cq_notify_flags flags);
486ed23a727SRoland Dreier int mthca_arbel_arm_cq(struct ib_cq *cq, enum ib_cq_notify_flags flags);
4871da177e4SLinus Torvalds int mthca_init_cq(struct mthca_dev *dev, int nent,
48874c2174eSRoland Dreier struct mthca_ucontext *ctx, u32 pdn,
4891da177e4SLinus Torvalds struct mthca_cq *cq);
4901da177e4SLinus Torvalds void mthca_free_cq(struct mthca_dev *dev,
4911da177e4SLinus Torvalds struct mthca_cq *cq);
492affcd505SMichael S. Tsirkin void mthca_cq_completion(struct mthca_dev *dev, u32 cqn);
493affcd505SMichael S. Tsirkin void mthca_cq_event(struct mthca_dev *dev, u32 cqn,
494affcd505SMichael S. Tsirkin enum ib_event_type event_type);
495a3285aa4SRoland Dreier void mthca_cq_clean(struct mthca_dev *dev, struct mthca_cq *cq, u32 qpn,
496ec34a922SRoland Dreier struct mthca_srq *srq);
4974885bf64SRoland Dreier void mthca_cq_resize_copy_cqes(struct mthca_cq *cq);
4984885bf64SRoland Dreier int mthca_alloc_cq_buf(struct mthca_dev *dev, struct mthca_cq_buf *buf, int nent);
4994885bf64SRoland Dreier void mthca_free_cq_buf(struct mthca_dev *dev, struct mthca_cq_buf *buf, int cqe);
500ec34a922SRoland Dreier
501ec34a922SRoland Dreier int mthca_alloc_srq(struct mthca_dev *dev, struct mthca_pd *pd,
502e00b64f7SShamir Rabinovitch struct ib_srq_attr *attr, struct mthca_srq *srq,
503e00b64f7SShamir Rabinovitch struct ib_udata *udata);
504ec34a922SRoland Dreier void mthca_free_srq(struct mthca_dev *dev, struct mthca_srq *srq);
50590f104daSRoland Dreier int mthca_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr,
5069bc57e2dSRalph Campbell enum ib_srq_attr_mask attr_mask, struct ib_udata *udata);
5078ebe5077SEli Cohen int mthca_query_srq(struct ib_srq *srq, struct ib_srq_attr *srq_attr);
50859fef3b1SJack Morgenstein int mthca_max_srq_sge(struct mthca_dev *dev);
509ec34a922SRoland Dreier void mthca_srq_event(struct mthca_dev *dev, u32 srqn,
510ec34a922SRoland Dreier enum ib_event_type event_type);
511ec34a922SRoland Dreier void mthca_free_srq_wqe(struct mthca_srq *srq, u32 wqe_addr);
512d34ac5cdSBart Van Assche int mthca_tavor_post_srq_recv(struct ib_srq *srq, const struct ib_recv_wr *wr,
513d34ac5cdSBart Van Assche const struct ib_recv_wr **bad_wr);
514d34ac5cdSBart Van Assche int mthca_arbel_post_srq_recv(struct ib_srq *srq, const struct ib_recv_wr *wr,
515d34ac5cdSBart Van Assche const struct ib_recv_wr **bad_wr);
5161da177e4SLinus Torvalds
5171da177e4SLinus Torvalds void mthca_qp_event(struct mthca_dev *dev, u32 qpn,
5181da177e4SLinus Torvalds enum ib_event_type event_type);
5198ebe5077SEli Cohen int mthca_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *qp_attr, int qp_attr_mask,
5208ebe5077SEli Cohen struct ib_qp_init_attr *qp_init_attr);
5219bc57e2dSRalph Campbell int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask,
5229bc57e2dSRalph Campbell struct ib_udata *udata);
523d34ac5cdSBart Van Assche int mthca_tavor_post_send(struct ib_qp *ibqp, const struct ib_send_wr *wr,
524d34ac5cdSBart Van Assche const struct ib_send_wr **bad_wr);
525d34ac5cdSBart Van Assche int mthca_tavor_post_receive(struct ib_qp *ibqp, const struct ib_recv_wr *wr,
526d34ac5cdSBart Van Assche const struct ib_recv_wr **bad_wr);
527d34ac5cdSBart Van Assche int mthca_arbel_post_send(struct ib_qp *ibqp, const struct ib_send_wr *wr,
528d34ac5cdSBart Van Assche const struct ib_send_wr **bad_wr);
529d34ac5cdSBart Van Assche int mthca_arbel_post_receive(struct ib_qp *ibqp, const struct ib_recv_wr *wr,
530d34ac5cdSBart Van Assche const struct ib_recv_wr **bad_wr);
531d9b98b0fSRoland Dreier void mthca_free_err_wqe(struct mthca_dev *dev, struct mthca_qp *qp, int is_send,
53297f52eb4SSean Hefty int index, int *dbd, __be32 *new_wqe);
5331da177e4SLinus Torvalds int mthca_alloc_qp(struct mthca_dev *dev,
5341da177e4SLinus Torvalds struct mthca_pd *pd,
5351da177e4SLinus Torvalds struct mthca_cq *send_cq,
5361da177e4SLinus Torvalds struct mthca_cq *recv_cq,
5371da177e4SLinus Torvalds enum ib_qp_type type,
5381da177e4SLinus Torvalds enum ib_sig_type send_policy,
53980c8ec2cSRoland Dreier struct ib_qp_cap *cap,
540e00b64f7SShamir Rabinovitch struct mthca_qp *qp,
541e00b64f7SShamir Rabinovitch struct ib_udata *udata);
5421da177e4SLinus Torvalds int mthca_alloc_sqp(struct mthca_dev *dev,
5431da177e4SLinus Torvalds struct mthca_pd *pd,
5441da177e4SLinus Torvalds struct mthca_cq *send_cq,
5451da177e4SLinus Torvalds struct mthca_cq *recv_cq,
5461da177e4SLinus Torvalds enum ib_sig_type send_policy,
54780c8ec2cSRoland Dreier struct ib_qp_cap *cap,
5481da177e4SLinus Torvalds int qpn,
549*1fb7f897SMark Bloch u32 port,
55021c2fe94SLeon Romanovsky struct mthca_qp *qp,
551e00b64f7SShamir Rabinovitch struct ib_udata *udata);
5521da177e4SLinus Torvalds void mthca_free_qp(struct mthca_dev *dev, struct mthca_qp *qp);
5531da177e4SLinus Torvalds int mthca_create_ah(struct mthca_dev *dev,
5541da177e4SLinus Torvalds struct mthca_pd *pd,
55590898850SDasaratharaman Chandramouli struct rdma_ah_attr *ah_attr,
5561da177e4SLinus Torvalds struct mthca_ah *ah);
5571da177e4SLinus Torvalds int mthca_destroy_ah(struct mthca_dev *dev, struct mthca_ah *ah);
5581da177e4SLinus Torvalds int mthca_read_ah(struct mthca_dev *dev, struct mthca_ah *ah,
5591da177e4SLinus Torvalds struct ib_ud_header *header);
56090898850SDasaratharaman Chandramouli int mthca_ah_query(struct ib_ah *ibah, struct rdma_ah_attr *attr);
5619eacee2aSMichael S. Tsirkin int mthca_ah_grh_present(struct mthca_ah *ah);
562*1fb7f897SMark Bloch u8 mthca_get_rate(struct mthca_dev *dev, int static_rate, u32 port);
563*1fb7f897SMark Bloch enum ib_rate mthca_rate_to_ib(struct mthca_dev *dev, u8 mthca_rate, u32 port);
5641da177e4SLinus Torvalds
5651da177e4SLinus Torvalds int mthca_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid);
5661da177e4SLinus Torvalds int mthca_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid);
5671da177e4SLinus Torvalds
568*1fb7f897SMark Bloch int mthca_process_mad(struct ib_device *ibdev, int mad_flags, u32 port_num,
569e26e7b88SLeon Romanovsky const struct ib_wc *in_wc, const struct ib_grh *in_grh,
570e26e7b88SLeon Romanovsky const struct ib_mad *in, struct ib_mad *out,
571e26e7b88SLeon Romanovsky size_t *out_mad_size, u16 *out_mad_pkey_index);
5721da177e4SLinus Torvalds int mthca_create_agents(struct mthca_dev *dev);
5731da177e4SLinus Torvalds void mthca_free_agents(struct mthca_dev *dev);
5741da177e4SLinus Torvalds
to_mdev(struct ib_device * ibdev)5751da177e4SLinus Torvalds static inline struct mthca_dev *to_mdev(struct ib_device *ibdev)
5761da177e4SLinus Torvalds {
5771da177e4SLinus Torvalds return container_of(ibdev, struct mthca_dev, ib_dev);
5781da177e4SLinus Torvalds }
5791da177e4SLinus Torvalds
mthca_is_memfree(struct mthca_dev * dev)580d10ddbf6SRoland Dreier static inline int mthca_is_memfree(struct mthca_dev *dev)
581d10ddbf6SRoland Dreier {
58268a3c212SRoland Dreier return dev->mthca_flags & MTHCA_FLAG_MEMFREE;
583d10ddbf6SRoland Dreier }
584d10ddbf6SRoland Dreier
5851da177e4SLinus Torvalds #endif /* MTHCA_DEV_H */
586