1219820Sjeff/* 2219820Sjeff * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved. 3219820Sjeff * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved. 4219820Sjeff * Copyright (c) 2005, 2006 Cisco Systems. All rights reserved. 5219820Sjeff * Copyright (c) 2005 Mellanox Technologies. All rights reserved. 6219820Sjeff * Copyright (c) 2004 Voltaire, Inc. All rights reserved. 7219820Sjeff * 8219820Sjeff * This software is available to you under a choice of one of two 9219820Sjeff * licenses. You may choose to be licensed under the terms of the GNU 10219820Sjeff * General Public License (GPL) Version 2, available from the file 11219820Sjeff * COPYING in the main directory of this source tree, or the 12219820Sjeff * OpenIB.org BSD license below: 13219820Sjeff * 14219820Sjeff * Redistribution and use in source and binary forms, with or 15219820Sjeff * without modification, are permitted provided that the following 16219820Sjeff * conditions are met: 17219820Sjeff * 18219820Sjeff * - Redistributions of source code must retain the above 19219820Sjeff * copyright notice, this list of conditions and the following 20219820Sjeff * disclaimer. 21219820Sjeff * 22219820Sjeff * - Redistributions in binary form must reproduce the above 23219820Sjeff * copyright notice, this list of conditions and the following 24219820Sjeff * disclaimer in the documentation and/or other materials 25219820Sjeff * provided with the distribution. 26219820Sjeff * 27219820Sjeff * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 28219820Sjeff * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 29219820Sjeff * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 30219820Sjeff * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 31219820Sjeff * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 32219820Sjeff * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 33219820Sjeff * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 34219820Sjeff * SOFTWARE. 35219820Sjeff */ 36219820Sjeff 37219820Sjeff#ifndef MTHCA_DEV_H 38219820Sjeff#define MTHCA_DEV_H 39219820Sjeff 40219820Sjeff#include <linux/spinlock.h> 41219820Sjeff#include <linux/kernel.h> 42219820Sjeff#include <linux/pci.h> 43219820Sjeff#include <linux/dma-mapping.h> 44219820Sjeff#include <linux/timer.h> 45219820Sjeff#include <linux/mutex.h> 46219820Sjeff#include <linux/list.h> 47219820Sjeff#include <linux/semaphore.h> 48219820Sjeff 49219820Sjeff#include "mthca_provider.h" 50219820Sjeff#include "mthca_doorbell.h" 51219820Sjeff 52219820Sjeff#define DRV_NAME "ib_mthca" 53219820Sjeff#define PFX DRV_NAME ": " 54219820Sjeff#define DRV_VERSION "1.0-ofed1.5.2" 55219820Sjeff#define DRV_RELDATE "August 4, 2010" 56219820Sjeff 57219820Sjeffenum { 58219820Sjeff MTHCA_FLAG_DDR_HIDDEN = 1 << 1, 59219820Sjeff MTHCA_FLAG_SRQ = 1 << 2, 60219820Sjeff MTHCA_FLAG_MSI_X = 1 << 3, 61219820Sjeff MTHCA_FLAG_NO_LAM = 1 << 4, 62219820Sjeff MTHCA_FLAG_FMR = 1 << 5, 63219820Sjeff MTHCA_FLAG_MEMFREE = 1 << 6, 64219820Sjeff MTHCA_FLAG_PCIE = 1 << 7, 65219820Sjeff MTHCA_FLAG_SINAI_OPT = 1 << 8 66219820Sjeff}; 67219820Sjeff 68219820Sjeffenum { 69219820Sjeff MTHCA_MAX_PORTS = 2 70219820Sjeff}; 71219820Sjeff 72219820Sjeffenum { 73219820Sjeff MTHCA_BOARD_ID_LEN = 64 74219820Sjeff}; 75219820Sjeff 76219820Sjeffenum { 77219820Sjeff MTHCA_EQ_CONTEXT_SIZE = 0x40, 78219820Sjeff MTHCA_CQ_CONTEXT_SIZE = 0x40, 79219820Sjeff MTHCA_QP_CONTEXT_SIZE = 0x200, 80219820Sjeff MTHCA_RDB_ENTRY_SIZE = 0x20, 81219820Sjeff MTHCA_AV_SIZE = 0x20, 82219820Sjeff MTHCA_MGM_ENTRY_SIZE = 0x100, 83219820Sjeff 84219820Sjeff /* Arbel FW gives us these, but we need them for Tavor */ 85219820Sjeff MTHCA_MPT_ENTRY_SIZE = 0x40, 86219820Sjeff MTHCA_MTT_SEG_SIZE = 0x40, 87219820Sjeff 88219820Sjeff MTHCA_QP_PER_MGM = 4 * (MTHCA_MGM_ENTRY_SIZE / 16 - 2) 89219820Sjeff}; 90219820Sjeff 91219820Sjeffenum { 92219820Sjeff MTHCA_EQ_CMD, 93219820Sjeff MTHCA_EQ_ASYNC, 94219820Sjeff MTHCA_EQ_COMP, 95219820Sjeff MTHCA_NUM_EQ 96219820Sjeff}; 97219820Sjeff 98219820Sjeffenum { 99219820Sjeff MTHCA_OPCODE_NOP = 0x00, 100219820Sjeff MTHCA_OPCODE_RDMA_WRITE = 0x08, 101219820Sjeff MTHCA_OPCODE_RDMA_WRITE_IMM = 0x09, 102219820Sjeff MTHCA_OPCODE_SEND = 0x0a, 103219820Sjeff MTHCA_OPCODE_SEND_IMM = 0x0b, 104219820Sjeff MTHCA_OPCODE_RDMA_READ = 0x10, 105219820Sjeff MTHCA_OPCODE_ATOMIC_CS = 0x11, 106219820Sjeff MTHCA_OPCODE_ATOMIC_FA = 0x12, 107219820Sjeff MTHCA_OPCODE_BIND_MW = 0x18, 108219820Sjeff MTHCA_OPCODE_INVALID = 0xff 109219820Sjeff}; 110219820Sjeff 111219820Sjeffenum { 112219820Sjeff MTHCA_CMD_USE_EVENTS = 1 << 0, 113219820Sjeff MTHCA_CMD_POST_DOORBELLS = 1 << 1 114219820Sjeff}; 115219820Sjeff 116219820Sjeffenum { 117219820Sjeff MTHCA_CMD_NUM_DBELL_DWORDS = 8 118219820Sjeff}; 119219820Sjeff 120219820Sjeffstruct mthca_cmd { 121219820Sjeff struct pci_pool *pool; 122219820Sjeff struct mutex hcr_mutex; 123219820Sjeff struct semaphore poll_sem; 124219820Sjeff struct semaphore event_sem; 125219820Sjeff int max_cmds; 126219820Sjeff spinlock_t context_lock; 127219820Sjeff int free_head; 128219820Sjeff struct mthca_cmd_context *context; 129219820Sjeff u16 token_mask; 130219820Sjeff u32 flags; 131219820Sjeff void __iomem *dbell_map; 132219820Sjeff u16 dbell_offsets[MTHCA_CMD_NUM_DBELL_DWORDS]; 133219820Sjeff}; 134219820Sjeff 135219820Sjeffstruct mthca_limits { 136219820Sjeff int num_ports; 137219820Sjeff int vl_cap; 138219820Sjeff int mtu_cap; 139219820Sjeff int gid_table_len; 140219820Sjeff int pkey_table_len; 141219820Sjeff int local_ca_ack_delay; 142219820Sjeff int num_uars; 143219820Sjeff int max_sg; 144219820Sjeff int num_qps; 145219820Sjeff int max_wqes; 146219820Sjeff int max_desc_sz; 147219820Sjeff int max_qp_init_rdma; 148219820Sjeff int reserved_qps; 149219820Sjeff int num_srqs; 150219820Sjeff int max_srq_wqes; 151219820Sjeff int max_srq_sge; 152219820Sjeff int reserved_srqs; 153219820Sjeff int num_eecs; 154219820Sjeff int reserved_eecs; 155219820Sjeff int num_cqs; 156219820Sjeff int max_cqes; 157219820Sjeff int reserved_cqs; 158219820Sjeff int num_eqs; 159219820Sjeff int reserved_eqs; 160219820Sjeff int num_mpts; 161219820Sjeff int num_mtt_segs; 162219820Sjeff int mtt_seg_size; 163219820Sjeff int fmr_reserved_mtts; 164219820Sjeff int reserved_mtts; 165219820Sjeff int reserved_mrws; 166219820Sjeff int reserved_uars; 167219820Sjeff int num_mgms; 168219820Sjeff int num_amgms; 169219820Sjeff int reserved_mcgs; 170219820Sjeff int num_pds; 171219820Sjeff int reserved_pds; 172219820Sjeff u32 page_size_cap; 173219820Sjeff u32 flags; 174219820Sjeff u16 stat_rate_support; 175219820Sjeff u8 port_width_cap; 176219820Sjeff}; 177219820Sjeff 178219820Sjeffstruct mthca_alloc { 179219820Sjeff u32 last; 180219820Sjeff u32 top; 181219820Sjeff u32 max; 182219820Sjeff u32 mask; 183219820Sjeff spinlock_t lock; 184219820Sjeff unsigned long *table; 185219820Sjeff}; 186219820Sjeff 187219820Sjeffstruct mthca_array { 188219820Sjeff struct { 189219820Sjeff void **page; 190219820Sjeff int used; 191219820Sjeff } *page_list; 192219820Sjeff}; 193219820Sjeff 194219820Sjeffstruct mthca_uar_table { 195219820Sjeff struct mthca_alloc alloc; 196219820Sjeff u64 uarc_base; 197219820Sjeff int uarc_size; 198219820Sjeff}; 199219820Sjeff 200219820Sjeffstruct mthca_pd_table { 201219820Sjeff struct mthca_alloc alloc; 202219820Sjeff}; 203219820Sjeff 204219820Sjeffstruct mthca_buddy { 205219820Sjeff unsigned long **bits; 206219820Sjeff int *num_free; 207219820Sjeff int max_order; 208219820Sjeff spinlock_t lock; 209219820Sjeff}; 210219820Sjeff 211219820Sjeffstruct mthca_mr_table { 212219820Sjeff struct mthca_alloc mpt_alloc; 213219820Sjeff struct mthca_buddy mtt_buddy; 214219820Sjeff struct mthca_buddy *fmr_mtt_buddy; 215219820Sjeff u64 mtt_base; 216219820Sjeff u64 mpt_base; 217219820Sjeff struct mthca_icm_table *mtt_table; 218219820Sjeff struct mthca_icm_table *mpt_table; 219219820Sjeff struct { 220219820Sjeff void __iomem *mpt_base; 221219820Sjeff void __iomem *mtt_base; 222219820Sjeff struct mthca_buddy mtt_buddy; 223219820Sjeff } tavor_fmr; 224219820Sjeff}; 225219820Sjeff 226219820Sjeffstruct mthca_eq_table { 227219820Sjeff struct mthca_alloc alloc; 228219820Sjeff void __iomem *clr_int; 229219820Sjeff u32 clr_mask; 230219820Sjeff u32 arm_mask; 231219820Sjeff struct mthca_eq eq[MTHCA_NUM_EQ]; 232219820Sjeff u64 icm_virt; 233219820Sjeff struct page *icm_page; 234219820Sjeff dma_addr_t icm_dma; 235219820Sjeff int have_irq; 236219820Sjeff u8 inta_pin; 237219820Sjeff}; 238219820Sjeff 239219820Sjeffstruct mthca_cq_table { 240219820Sjeff struct mthca_alloc alloc; 241219820Sjeff spinlock_t lock; 242219820Sjeff struct mthca_array cq; 243219820Sjeff struct mthca_icm_table *table; 244219820Sjeff}; 245219820Sjeff 246219820Sjeffstruct mthca_srq_table { 247219820Sjeff struct mthca_alloc alloc; 248219820Sjeff spinlock_t lock; 249219820Sjeff struct mthca_array srq; 250219820Sjeff struct mthca_icm_table *table; 251219820Sjeff}; 252219820Sjeff 253219820Sjeffstruct mthca_qp_table { 254219820Sjeff struct mthca_alloc alloc; 255219820Sjeff u32 rdb_base; 256219820Sjeff int rdb_shift; 257219820Sjeff int sqp_start; 258219820Sjeff spinlock_t lock; 259219820Sjeff struct mthca_array qp; 260219820Sjeff struct mthca_icm_table *qp_table; 261219820Sjeff struct mthca_icm_table *eqp_table; 262219820Sjeff struct mthca_icm_table *rdb_table; 263219820Sjeff}; 264219820Sjeff 265219820Sjeffstruct mthca_av_table { 266219820Sjeff struct pci_pool *pool; 267219820Sjeff int num_ddr_avs; 268219820Sjeff u64 ddr_av_base; 269219820Sjeff void __iomem *av_map; 270219820Sjeff struct mthca_alloc alloc; 271219820Sjeff}; 272219820Sjeff 273219820Sjeffstruct mthca_mcg_table { 274219820Sjeff struct mutex mutex; 275219820Sjeff struct mthca_alloc alloc; 276219820Sjeff struct mthca_icm_table *table; 277219820Sjeff}; 278219820Sjeff 279219820Sjeffstruct mthca_catas_err { 280219820Sjeff u64 addr; 281219820Sjeff u32 __iomem *map; 282219820Sjeff u32 size; 283219820Sjeff struct timer_list timer; 284219820Sjeff struct list_head list; 285219820Sjeff}; 286219820Sjeff 287219820Sjeffextern struct mutex mthca_device_mutex; 288219820Sjeff 289219820Sjeffstruct mthca_dev { 290219820Sjeff struct ib_device ib_dev; 291219820Sjeff struct pci_dev *pdev; 292219820Sjeff 293219820Sjeff int hca_type; 294219820Sjeff unsigned long mthca_flags; 295219820Sjeff unsigned long device_cap_flags; 296219820Sjeff 297219820Sjeff u32 rev_id; 298219820Sjeff char board_id[MTHCA_BOARD_ID_LEN]; 299219820Sjeff 300219820Sjeff /* firmware info */ 301219820Sjeff u64 fw_ver; 302219820Sjeff union { 303219820Sjeff struct { 304219820Sjeff u64 fw_start; 305219820Sjeff u64 fw_end; 306219820Sjeff } tavor; 307219820Sjeff struct { 308219820Sjeff u64 clr_int_base; 309219820Sjeff u64 eq_arm_base; 310219820Sjeff u64 eq_set_ci_base; 311219820Sjeff struct mthca_icm *fw_icm; 312219820Sjeff struct mthca_icm *aux_icm; 313219820Sjeff u16 fw_pages; 314219820Sjeff } arbel; 315219820Sjeff } fw; 316219820Sjeff 317219820Sjeff u64 ddr_start; 318219820Sjeff u64 ddr_end; 319219820Sjeff 320219820Sjeff MTHCA_DECLARE_DOORBELL_LOCK(doorbell_lock) 321219820Sjeff struct mutex cap_mask_mutex; 322219820Sjeff 323219820Sjeff void __iomem *hcr; 324219820Sjeff void __iomem *kar; 325219820Sjeff void __iomem *clr_base; 326219820Sjeff union { 327219820Sjeff struct { 328219820Sjeff void __iomem *ecr_base; 329219820Sjeff } tavor; 330219820Sjeff struct { 331219820Sjeff void __iomem *eq_arm; 332219820Sjeff void __iomem *eq_set_ci_base; 333219820Sjeff } arbel; 334219820Sjeff } eq_regs; 335219820Sjeff 336219820Sjeff struct mthca_cmd cmd; 337219820Sjeff struct mthca_limits limits; 338219820Sjeff 339219820Sjeff struct mthca_uar_table uar_table; 340219820Sjeff struct mthca_pd_table pd_table; 341219820Sjeff struct mthca_mr_table mr_table; 342219820Sjeff struct mthca_eq_table eq_table; 343219820Sjeff struct mthca_cq_table cq_table; 344219820Sjeff struct mthca_srq_table srq_table; 345219820Sjeff struct mthca_qp_table qp_table; 346219820Sjeff struct mthca_av_table av_table; 347219820Sjeff struct mthca_mcg_table mcg_table; 348219820Sjeff 349219820Sjeff struct mthca_catas_err catas_err; 350219820Sjeff 351219820Sjeff struct mthca_uar driver_uar; 352219820Sjeff struct mthca_db_table *db_tab; 353219820Sjeff struct mthca_pd driver_pd; 354219820Sjeff struct mthca_mr driver_mr; 355219820Sjeff 356219820Sjeff struct ib_mad_agent *send_agent[MTHCA_MAX_PORTS][2]; 357219820Sjeff struct ib_ah *sm_ah[MTHCA_MAX_PORTS]; 358219820Sjeff spinlock_t sm_lock; 359219820Sjeff u8 rate[MTHCA_MAX_PORTS]; 360219820Sjeff int active; 361219820Sjeff}; 362219820Sjeff 363219820Sjeff#ifdef CONFIG_INFINIBAND_MTHCA_DEBUG 364219820Sjeffextern int mthca_debug_level; 365219820Sjeff 366219820Sjeff#define mthca_dbg(mdev, format, arg...) \ 367219820Sjeff do { \ 368219820Sjeff if (mthca_debug_level) \ 369219820Sjeff dev_printk(KERN_DEBUG, &mdev->pdev->dev, format, ## arg); \ 370219820Sjeff } while (0) 371219820Sjeff 372219820Sjeff#else /* CONFIG_INFINIBAND_MTHCA_DEBUG */ 373219820Sjeff 374219820Sjeff#define mthca_dbg(mdev, format, arg...) do { (void) mdev; } while (0) 375219820Sjeff 376219820Sjeff#endif /* CONFIG_INFINIBAND_MTHCA_DEBUG */ 377219820Sjeff 378219820Sjeff#define mthca_err(mdev, format, arg...) \ 379219820Sjeff dev_err(&mdev->pdev->dev, format, ## arg) 380219820Sjeff#define mthca_info(mdev, format, arg...) \ 381219820Sjeff dev_info(&mdev->pdev->dev, format, ## arg) 382219820Sjeff#define mthca_warn(mdev, format, arg...) \ 383219820Sjeff dev_warn(&mdev->pdev->dev, format, ## arg) 384219820Sjeff 385219820Sjeffextern void __buggy_use_of_MTHCA_GET(void); 386219820Sjeffextern void __buggy_use_of_MTHCA_PUT(void); 387219820Sjeff 388219820Sjeff#define MTHCA_GET(dest, source, offset) \ 389219820Sjeff do { \ 390219820Sjeff void *__p = (char *) (source) + (offset); \ 391219820Sjeff switch (sizeof (dest)) { \ 392219820Sjeff case 1: (dest) = *(u8 *) __p; break; \ 393219820Sjeff case 2: (dest) = be16_to_cpup(__p); break; \ 394219820Sjeff case 4: (dest) = be32_to_cpup(__p); break; \ 395219820Sjeff case 8: (dest) = be64_to_cpup(__p); break; \ 396219820Sjeff default: __buggy_use_of_MTHCA_GET(); \ 397219820Sjeff } \ 398219820Sjeff } while (0) 399219820Sjeff 400219820Sjeff#define MTHCA_PUT(dest, source, offset) \ 401219820Sjeff do { \ 402219820Sjeff void *__d = ((char *) (dest) + (offset)); \ 403219820Sjeff switch (sizeof(source)) { \ 404219820Sjeff case 1: *(u8 *) __d = (source); break; \ 405219820Sjeff case 2: *(__be16 *) __d = cpu_to_be16(source); break; \ 406219820Sjeff case 4: *(__be32 *) __d = cpu_to_be32(source); break; \ 407219820Sjeff case 8: *(__be64 *) __d = cpu_to_be64(source); break; \ 408219820Sjeff default: __buggy_use_of_MTHCA_PUT(); \ 409219820Sjeff } \ 410219820Sjeff } while (0) 411219820Sjeff 412219820Sjeffint mthca_reset(struct mthca_dev *mdev); 413219820Sjeff 414219820Sjeffu32 mthca_alloc(struct mthca_alloc *alloc); 415219820Sjeffvoid mthca_free(struct mthca_alloc *alloc, u32 obj); 416219820Sjeffint mthca_alloc_init(struct mthca_alloc *alloc, u32 num, u32 mask, 417219820Sjeff u32 reserved); 418219820Sjeffvoid mthca_alloc_cleanup(struct mthca_alloc *alloc); 419219820Sjeffvoid *mthca_array_get(struct mthca_array *array, int index); 420219820Sjeffint mthca_array_set(struct mthca_array *array, int index, void *value); 421219820Sjeffvoid mthca_array_clear(struct mthca_array *array, int index); 422219820Sjeffint mthca_array_init(struct mthca_array *array, int nent); 423219820Sjeffvoid mthca_array_cleanup(struct mthca_array *array, int nent); 424219820Sjeffint mthca_buf_alloc(struct mthca_dev *dev, int size, int max_direct, 425219820Sjeff union mthca_buf *buf, int *is_direct, struct mthca_pd *pd, 426219820Sjeff int hca_write, struct mthca_mr *mr); 427219820Sjeffvoid mthca_buf_free(struct mthca_dev *dev, int size, union mthca_buf *buf, 428219820Sjeff int is_direct, struct mthca_mr *mr); 429219820Sjeff 430219820Sjeffint mthca_init_uar_table(struct mthca_dev *dev); 431219820Sjeffint mthca_init_pd_table(struct mthca_dev *dev); 432219820Sjeffint mthca_init_mr_table(struct mthca_dev *dev); 433219820Sjeffint mthca_init_eq_table(struct mthca_dev *dev); 434219820Sjeffint mthca_init_cq_table(struct mthca_dev *dev); 435219820Sjeffint mthca_init_srq_table(struct mthca_dev *dev); 436219820Sjeffint mthca_init_qp_table(struct mthca_dev *dev); 437219820Sjeffint mthca_init_av_table(struct mthca_dev *dev); 438219820Sjeffint mthca_init_mcg_table(struct mthca_dev *dev); 439219820Sjeff 440219820Sjeffvoid mthca_cleanup_uar_table(struct mthca_dev *dev); 441219820Sjeffvoid mthca_cleanup_pd_table(struct mthca_dev *dev); 442219820Sjeffvoid mthca_cleanup_mr_table(struct mthca_dev *dev); 443219820Sjeffvoid mthca_cleanup_eq_table(struct mthca_dev *dev); 444219820Sjeffvoid mthca_cleanup_cq_table(struct mthca_dev *dev); 445219820Sjeffvoid mthca_cleanup_srq_table(struct mthca_dev *dev); 446219820Sjeffvoid mthca_cleanup_qp_table(struct mthca_dev *dev); 447219820Sjeffvoid mthca_cleanup_av_table(struct mthca_dev *dev); 448219820Sjeffvoid mthca_cleanup_mcg_table(struct mthca_dev *dev); 449219820Sjeff 450219820Sjeffint mthca_register_device(struct mthca_dev *dev); 451219820Sjeffvoid mthca_unregister_device(struct mthca_dev *dev); 452219820Sjeff 453219820Sjeffvoid mthca_start_catas_poll(struct mthca_dev *dev); 454219820Sjeffvoid mthca_stop_catas_poll(struct mthca_dev *dev); 455219820Sjeffint __mthca_restart_one(struct pci_dev *pdev); 456219820Sjeffint mthca_catas_init(void); 457219820Sjeffvoid mthca_catas_cleanup(void); 458219820Sjeff 459219820Sjeffint mthca_uar_alloc(struct mthca_dev *dev, struct mthca_uar *uar); 460219820Sjeffvoid mthca_uar_free(struct mthca_dev *dev, struct mthca_uar *uar); 461219820Sjeff 462219820Sjeffint mthca_pd_alloc(struct mthca_dev *dev, int privileged, struct mthca_pd *pd); 463219820Sjeffvoid mthca_pd_free(struct mthca_dev *dev, struct mthca_pd *pd); 464219820Sjeff 465219820Sjeffint mthca_write_mtt_size(struct mthca_dev *dev); 466219820Sjeff 467219820Sjeffstruct mthca_mtt *mthca_alloc_mtt(struct mthca_dev *dev, int size); 468219820Sjeffvoid mthca_free_mtt(struct mthca_dev *dev, struct mthca_mtt *mtt); 469219820Sjeffint mthca_write_mtt(struct mthca_dev *dev, struct mthca_mtt *mtt, 470219820Sjeff int start_index, u64 *buffer_list, int list_len); 471219820Sjeffint mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift, 472219820Sjeff u64 iova, u64 total_size, u32 access, struct mthca_mr *mr); 473219820Sjeffint mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd, 474219820Sjeff u32 access, struct mthca_mr *mr); 475219820Sjeffint mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd, 476219820Sjeff u64 *buffer_list, int buffer_size_shift, 477219820Sjeff int list_len, u64 iova, u64 total_size, 478219820Sjeff u32 access, struct mthca_mr *mr); 479219820Sjeffvoid mthca_free_mr(struct mthca_dev *dev, struct mthca_mr *mr); 480219820Sjeff 481219820Sjeffint mthca_fmr_alloc(struct mthca_dev *dev, u32 pd, 482219820Sjeff u32 access, struct mthca_fmr *fmr); 483219820Sjeffint mthca_tavor_map_phys_fmr(struct ib_fmr *ibfmr, u64 *page_list, 484219820Sjeff int list_len, u64 iova); 485219820Sjeffvoid mthca_tavor_fmr_unmap(struct mthca_dev *dev, struct mthca_fmr *fmr); 486219820Sjeffint mthca_arbel_map_phys_fmr(struct ib_fmr *ibfmr, u64 *page_list, 487219820Sjeff int list_len, u64 iova); 488219820Sjeffvoid mthca_arbel_fmr_unmap(struct mthca_dev *dev, struct mthca_fmr *fmr); 489219820Sjeffint mthca_free_fmr(struct mthca_dev *dev, struct mthca_fmr *fmr); 490219820Sjeff 491219820Sjeffint mthca_map_eq_icm(struct mthca_dev *dev, u64 icm_virt); 492219820Sjeffvoid mthca_unmap_eq_icm(struct mthca_dev *dev); 493219820Sjeff 494219820Sjeffint mthca_poll_cq(struct ib_cq *ibcq, int num_entries, 495219820Sjeff struct ib_wc *entry); 496219820Sjeffint mthca_tavor_arm_cq(struct ib_cq *cq, enum ib_cq_notify_flags flags); 497219820Sjeffint mthca_arbel_arm_cq(struct ib_cq *cq, enum ib_cq_notify_flags flags); 498219820Sjeffint mthca_init_cq(struct mthca_dev *dev, int nent, 499219820Sjeff struct mthca_ucontext *ctx, u32 pdn, 500219820Sjeff struct mthca_cq *cq); 501219820Sjeffvoid mthca_free_cq(struct mthca_dev *dev, 502219820Sjeff struct mthca_cq *cq); 503219820Sjeffvoid mthca_cq_completion(struct mthca_dev *dev, u32 cqn); 504219820Sjeffvoid mthca_cq_event(struct mthca_dev *dev, u32 cqn, 505219820Sjeff enum ib_event_type event_type); 506219820Sjeffvoid mthca_cq_clean(struct mthca_dev *dev, struct mthca_cq *cq, u32 qpn, 507219820Sjeff struct mthca_srq *srq); 508219820Sjeffvoid mthca_cq_resize_copy_cqes(struct mthca_cq *cq); 509219820Sjeffint mthca_alloc_cq_buf(struct mthca_dev *dev, struct mthca_cq_buf *buf, int nent); 510219820Sjeffvoid mthca_free_cq_buf(struct mthca_dev *dev, struct mthca_cq_buf *buf, int cqe); 511219820Sjeff 512219820Sjeffint mthca_alloc_srq(struct mthca_dev *dev, struct mthca_pd *pd, 513219820Sjeff struct ib_srq_attr *attr, struct mthca_srq *srq); 514219820Sjeffvoid mthca_free_srq(struct mthca_dev *dev, struct mthca_srq *srq); 515219820Sjeffint mthca_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr, 516219820Sjeff enum ib_srq_attr_mask attr_mask, struct ib_udata *udata); 517219820Sjeffint mthca_query_srq(struct ib_srq *srq, struct ib_srq_attr *srq_attr); 518219820Sjeffint mthca_max_srq_sge(struct mthca_dev *dev); 519219820Sjeffvoid mthca_srq_event(struct mthca_dev *dev, u32 srqn, 520219820Sjeff enum ib_event_type event_type); 521219820Sjeffvoid mthca_free_srq_wqe(struct mthca_srq *srq, u32 wqe_addr); 522219820Sjeffint mthca_tavor_post_srq_recv(struct ib_srq *srq, struct ib_recv_wr *wr, 523219820Sjeff struct ib_recv_wr **bad_wr); 524219820Sjeffint mthca_arbel_post_srq_recv(struct ib_srq *srq, struct ib_recv_wr *wr, 525219820Sjeff struct ib_recv_wr **bad_wr); 526219820Sjeff 527219820Sjeffvoid mthca_qp_event(struct mthca_dev *dev, u32 qpn, 528219820Sjeff enum ib_event_type event_type); 529219820Sjeffint mthca_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *qp_attr, int qp_attr_mask, 530219820Sjeff struct ib_qp_init_attr *qp_init_attr); 531219820Sjeffint mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask, 532219820Sjeff struct ib_udata *udata); 533219820Sjeffint mthca_tavor_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr, 534219820Sjeff struct ib_send_wr **bad_wr); 535219820Sjeffint mthca_tavor_post_receive(struct ib_qp *ibqp, struct ib_recv_wr *wr, 536219820Sjeff struct ib_recv_wr **bad_wr); 537219820Sjeffint mthca_arbel_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr, 538219820Sjeff struct ib_send_wr **bad_wr); 539219820Sjeffint mthca_arbel_post_receive(struct ib_qp *ibqp, struct ib_recv_wr *wr, 540219820Sjeff struct ib_recv_wr **bad_wr); 541219820Sjeffvoid mthca_free_err_wqe(struct mthca_dev *dev, struct mthca_qp *qp, int is_send, 542219820Sjeff int index, int *dbd, __be32 *new_wqe); 543219820Sjeffint mthca_alloc_qp(struct mthca_dev *dev, 544219820Sjeff struct mthca_pd *pd, 545219820Sjeff struct mthca_cq *send_cq, 546219820Sjeff struct mthca_cq *recv_cq, 547219820Sjeff enum ib_qp_type type, 548219820Sjeff enum ib_sig_type send_policy, 549219820Sjeff struct ib_qp_cap *cap, 550219820Sjeff struct mthca_qp *qp); 551219820Sjeffint mthca_alloc_sqp(struct mthca_dev *dev, 552219820Sjeff struct mthca_pd *pd, 553219820Sjeff struct mthca_cq *send_cq, 554219820Sjeff struct mthca_cq *recv_cq, 555219820Sjeff enum ib_sig_type send_policy, 556219820Sjeff struct ib_qp_cap *cap, 557219820Sjeff int qpn, 558219820Sjeff int port, 559219820Sjeff struct mthca_sqp *sqp); 560219820Sjeffvoid mthca_free_qp(struct mthca_dev *dev, struct mthca_qp *qp); 561219820Sjeffint mthca_create_ah(struct mthca_dev *dev, 562219820Sjeff struct mthca_pd *pd, 563219820Sjeff struct ib_ah_attr *ah_attr, 564219820Sjeff struct mthca_ah *ah); 565219820Sjeffint mthca_destroy_ah(struct mthca_dev *dev, struct mthca_ah *ah); 566219820Sjeffint mthca_read_ah(struct mthca_dev *dev, struct mthca_ah *ah, 567219820Sjeff struct ib_ud_header *header); 568219820Sjeffint mthca_ah_query(struct ib_ah *ibah, struct ib_ah_attr *attr); 569219820Sjeffint mthca_ah_grh_present(struct mthca_ah *ah); 570219820Sjeffu8 mthca_get_rate(struct mthca_dev *dev, int static_rate, u8 port); 571219820Sjeffenum ib_rate mthca_rate_to_ib(struct mthca_dev *dev, u8 mthca_rate, u8 port); 572219820Sjeff 573219820Sjeffint mthca_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid); 574219820Sjeffint mthca_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid); 575219820Sjeff 576219820Sjeffint mthca_process_mad(struct ib_device *ibdev, 577219820Sjeff int mad_flags, 578219820Sjeff u8 port_num, 579219820Sjeff struct ib_wc *in_wc, 580219820Sjeff struct ib_grh *in_grh, 581219820Sjeff struct ib_mad *in_mad, 582219820Sjeff struct ib_mad *out_mad); 583219820Sjeffint mthca_create_agents(struct mthca_dev *dev); 584219820Sjeffvoid mthca_free_agents(struct mthca_dev *dev); 585219820Sjeff 586219820Sjeffstatic inline struct mthca_dev *to_mdev(struct ib_device *ibdev) 587219820Sjeff{ 588219820Sjeff return container_of(ibdev, struct mthca_dev, ib_dev); 589219820Sjeff} 590219820Sjeff 591219820Sjeffstatic inline int mthca_is_memfree(struct mthca_dev *dev) 592219820Sjeff{ 593219820Sjeff return dev->mthca_flags & MTHCA_FLAG_MEMFREE; 594219820Sjeff} 595219820Sjeff 596219820Sjeff#endif /* MTHCA_DEV_H */ 597