Path: blob/master/drivers/infiniband/hw/mthca/mthca_dev.h
15112 views
/*1* Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.2* Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.3* Copyright (c) 2005, 2006 Cisco Systems. All rights reserved.4* Copyright (c) 2005 Mellanox Technologies. All rights reserved.5* Copyright (c) 2004 Voltaire, Inc. All rights reserved.6*7* This software is available to you under a choice of one of two8* licenses. You may choose to be licensed under the terms of the GNU9* General Public License (GPL) Version 2, available from the file10* COPYING in the main directory of this source tree, or the11* OpenIB.org BSD license below:12*13* Redistribution and use in source and binary forms, with or14* without modification, are permitted provided that the following15* conditions are met:16*17* - Redistributions of source code must retain the above18* copyright notice, this list of conditions and the following19* disclaimer.20*21* - Redistributions in binary form must reproduce the above22* copyright notice, this list of conditions and the following23* disclaimer in the documentation and/or other materials24* provided with the distribution.25*26* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,27* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF28* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND29* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS30* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN31* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN32* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE33* SOFTWARE.34*/3536#ifndef MTHCA_DEV_H37#define MTHCA_DEV_H3839#include <linux/spinlock.h>40#include <linux/kernel.h>41#include <linux/pci.h>42#include <linux/dma-mapping.h>43#include <linux/timer.h>44#include <linux/mutex.h>45#include <linux/list.h>46#include <linux/semaphore.h>4748#include "mthca_provider.h"49#include "mthca_doorbell.h"5051#define DRV_NAME "ib_mthca"52#define PFX DRV_NAME ": "53#define DRV_VERSION "1.0"54#define DRV_RELDATE "April 4, 2008"5556enum {57MTHCA_FLAG_DDR_HIDDEN = 1 << 1,58MTHCA_FLAG_SRQ = 1 << 2,59MTHCA_FLAG_MSI_X = 1 << 3,60MTHCA_FLAG_NO_LAM = 1 << 4,61MTHCA_FLAG_FMR = 1 << 5,62MTHCA_FLAG_MEMFREE = 1 << 6,63MTHCA_FLAG_PCIE = 1 << 7,64MTHCA_FLAG_SINAI_OPT = 1 << 865};6667enum {68MTHCA_MAX_PORTS = 269};7071enum {72MTHCA_BOARD_ID_LEN = 6473};7475enum {76MTHCA_EQ_CONTEXT_SIZE = 0x40,77MTHCA_CQ_CONTEXT_SIZE = 0x40,78MTHCA_QP_CONTEXT_SIZE = 0x200,79MTHCA_RDB_ENTRY_SIZE = 0x20,80MTHCA_AV_SIZE = 0x20,81MTHCA_MGM_ENTRY_SIZE = 0x100,8283/* Arbel FW gives us these, but we need them for Tavor */84MTHCA_MPT_ENTRY_SIZE = 0x40,85MTHCA_MTT_SEG_SIZE = 0x40,8687MTHCA_QP_PER_MGM = 4 * (MTHCA_MGM_ENTRY_SIZE / 16 - 2)88};8990enum {91MTHCA_EQ_CMD,92MTHCA_EQ_ASYNC,93MTHCA_EQ_COMP,94MTHCA_NUM_EQ95};9697enum {98MTHCA_OPCODE_NOP = 0x00,99MTHCA_OPCODE_RDMA_WRITE = 0x08,100MTHCA_OPCODE_RDMA_WRITE_IMM = 0x09,101MTHCA_OPCODE_SEND = 0x0a,102MTHCA_OPCODE_SEND_IMM = 0x0b,103MTHCA_OPCODE_RDMA_READ = 0x10,104MTHCA_OPCODE_ATOMIC_CS = 0x11,105MTHCA_OPCODE_ATOMIC_FA = 0x12,106MTHCA_OPCODE_BIND_MW = 0x18,107MTHCA_OPCODE_INVALID = 0xff108};109110enum {111MTHCA_CMD_USE_EVENTS = 1 << 0,112MTHCA_CMD_POST_DOORBELLS = 1 << 1113};114115enum {116MTHCA_CMD_NUM_DBELL_DWORDS = 8117};118119struct mthca_cmd {120struct pci_pool *pool;121struct mutex hcr_mutex;122struct semaphore poll_sem;123struct semaphore event_sem;124int max_cmds;125spinlock_t context_lock;126int free_head;127struct mthca_cmd_context *context;128u16 token_mask;129u32 flags;130void __iomem *dbell_map;131u16 dbell_offsets[MTHCA_CMD_NUM_DBELL_DWORDS];132};133134struct mthca_limits {135int num_ports;136int vl_cap;137int mtu_cap;138int gid_table_len;139int pkey_table_len;140int local_ca_ack_delay;141int num_uars;142int max_sg;143int num_qps;144int max_wqes;145int max_desc_sz;146int max_qp_init_rdma;147int reserved_qps;148int num_srqs;149int max_srq_wqes;150int max_srq_sge;151int reserved_srqs;152int num_eecs;153int reserved_eecs;154int num_cqs;155int max_cqes;156int reserved_cqs;157int num_eqs;158int reserved_eqs;159int num_mpts;160int num_mtt_segs;161int mtt_seg_size;162int fmr_reserved_mtts;163int reserved_mtts;164int reserved_mrws;165int reserved_uars;166int num_mgms;167int num_amgms;168int reserved_mcgs;169int num_pds;170int reserved_pds;171u32 page_size_cap;172u32 flags;173u16 stat_rate_support;174u8 port_width_cap;175};176177struct mthca_alloc {178u32 last;179u32 top;180u32 max;181u32 mask;182spinlock_t lock;183unsigned long *table;184};185186struct mthca_array {187struct {188void **page;189int used;190} *page_list;191};192193struct mthca_uar_table {194struct mthca_alloc alloc;195u64 uarc_base;196int uarc_size;197};198199struct mthca_pd_table {200struct mthca_alloc alloc;201};202203struct mthca_buddy {204unsigned long **bits;205int *num_free;206int max_order;207spinlock_t lock;208};209210struct mthca_mr_table {211struct mthca_alloc mpt_alloc;212struct mthca_buddy mtt_buddy;213struct mthca_buddy *fmr_mtt_buddy;214u64 mtt_base;215u64 mpt_base;216struct mthca_icm_table *mtt_table;217struct mthca_icm_table *mpt_table;218struct {219void __iomem *mpt_base;220void __iomem *mtt_base;221struct mthca_buddy mtt_buddy;222} tavor_fmr;223};224225struct mthca_eq_table {226struct mthca_alloc alloc;227void __iomem *clr_int;228u32 clr_mask;229u32 arm_mask;230struct mthca_eq eq[MTHCA_NUM_EQ];231u64 icm_virt;232struct page *icm_page;233dma_addr_t icm_dma;234int have_irq;235u8 inta_pin;236};237238struct mthca_cq_table {239struct mthca_alloc alloc;240spinlock_t lock;241struct mthca_array cq;242struct mthca_icm_table *table;243};244245struct mthca_srq_table {246struct mthca_alloc alloc;247spinlock_t lock;248struct mthca_array srq;249struct mthca_icm_table *table;250};251252struct mthca_qp_table {253struct mthca_alloc alloc;254u32 rdb_base;255int rdb_shift;256int sqp_start;257spinlock_t lock;258struct mthca_array qp;259struct mthca_icm_table *qp_table;260struct mthca_icm_table *eqp_table;261struct mthca_icm_table *rdb_table;262};263264struct mthca_av_table {265struct pci_pool *pool;266int num_ddr_avs;267u64 ddr_av_base;268void __iomem *av_map;269struct mthca_alloc alloc;270};271272struct mthca_mcg_table {273struct mutex mutex;274struct mthca_alloc alloc;275struct mthca_icm_table *table;276};277278struct mthca_catas_err {279u64 addr;280u32 __iomem *map;281u32 size;282struct timer_list timer;283struct list_head list;284};285286extern struct mutex mthca_device_mutex;287288struct mthca_dev {289struct ib_device ib_dev;290struct pci_dev *pdev;291292int hca_type;293unsigned long mthca_flags;294unsigned long device_cap_flags;295296u32 rev_id;297char board_id[MTHCA_BOARD_ID_LEN];298299/* firmware info */300u64 fw_ver;301union {302struct {303u64 fw_start;304u64 fw_end;305} tavor;306struct {307u64 clr_int_base;308u64 eq_arm_base;309u64 eq_set_ci_base;310struct mthca_icm *fw_icm;311struct mthca_icm *aux_icm;312u16 fw_pages;313} arbel;314} fw;315316u64 ddr_start;317u64 ddr_end;318319MTHCA_DECLARE_DOORBELL_LOCK(doorbell_lock)320struct mutex cap_mask_mutex;321322void __iomem *hcr;323void __iomem *kar;324void __iomem *clr_base;325union {326struct {327void __iomem *ecr_base;328} tavor;329struct {330void __iomem *eq_arm;331void __iomem *eq_set_ci_base;332} arbel;333} eq_regs;334335struct mthca_cmd cmd;336struct mthca_limits limits;337338struct mthca_uar_table uar_table;339struct mthca_pd_table pd_table;340struct mthca_mr_table mr_table;341struct mthca_eq_table eq_table;342struct mthca_cq_table cq_table;343struct mthca_srq_table srq_table;344struct mthca_qp_table qp_table;345struct mthca_av_table av_table;346struct mthca_mcg_table mcg_table;347348struct mthca_catas_err catas_err;349350struct mthca_uar driver_uar;351struct mthca_db_table *db_tab;352struct mthca_pd driver_pd;353struct mthca_mr driver_mr;354355struct ib_mad_agent *send_agent[MTHCA_MAX_PORTS][2];356struct ib_ah *sm_ah[MTHCA_MAX_PORTS];357spinlock_t sm_lock;358u8 rate[MTHCA_MAX_PORTS];359bool active;360};361362#ifdef CONFIG_INFINIBAND_MTHCA_DEBUG363extern int mthca_debug_level;364365#define mthca_dbg(mdev, format, arg...) \366do { \367if (mthca_debug_level) \368dev_printk(KERN_DEBUG, &mdev->pdev->dev, format, ## arg); \369} while (0)370371#else /* CONFIG_INFINIBAND_MTHCA_DEBUG */372373#define mthca_dbg(mdev, format, arg...) do { (void) mdev; } while (0)374375#endif /* CONFIG_INFINIBAND_MTHCA_DEBUG */376377#define mthca_err(mdev, format, arg...) \378dev_err(&mdev->pdev->dev, format, ## arg)379#define mthca_info(mdev, format, arg...) \380dev_info(&mdev->pdev->dev, format, ## arg)381#define mthca_warn(mdev, format, arg...) \382dev_warn(&mdev->pdev->dev, format, ## arg)383384extern void __buggy_use_of_MTHCA_GET(void);385extern void __buggy_use_of_MTHCA_PUT(void);386387#define MTHCA_GET(dest, source, offset) \388do { \389void *__p = (char *) (source) + (offset); \390switch (sizeof (dest)) { \391case 1: (dest) = *(u8 *) __p; break; \392case 2: (dest) = be16_to_cpup(__p); break; \393case 4: (dest) = be32_to_cpup(__p); break; \394case 8: (dest) = be64_to_cpup(__p); break; \395default: __buggy_use_of_MTHCA_GET(); \396} \397} while (0)398399#define MTHCA_PUT(dest, source, offset) \400do { \401void *__d = ((char *) (dest) + (offset)); \402switch (sizeof(source)) { \403case 1: *(u8 *) __d = (source); break; \404case 2: *(__be16 *) __d = cpu_to_be16(source); break; \405case 4: *(__be32 *) __d = cpu_to_be32(source); break; \406case 8: *(__be64 *) __d = cpu_to_be64(source); break; \407default: __buggy_use_of_MTHCA_PUT(); \408} \409} while (0)410411int mthca_reset(struct mthca_dev *mdev);412413u32 mthca_alloc(struct mthca_alloc *alloc);414void mthca_free(struct mthca_alloc *alloc, u32 obj);415int mthca_alloc_init(struct mthca_alloc *alloc, u32 num, u32 mask,416u32 reserved);417void mthca_alloc_cleanup(struct mthca_alloc *alloc);418void *mthca_array_get(struct mthca_array *array, int index);419int mthca_array_set(struct mthca_array *array, int index, void *value);420void mthca_array_clear(struct mthca_array *array, int index);421int mthca_array_init(struct mthca_array *array, int nent);422void mthca_array_cleanup(struct mthca_array *array, int nent);423int mthca_buf_alloc(struct mthca_dev *dev, int size, int max_direct,424union mthca_buf *buf, int *is_direct, struct mthca_pd *pd,425int hca_write, struct mthca_mr *mr);426void mthca_buf_free(struct mthca_dev *dev, int size, union mthca_buf *buf,427int is_direct, struct mthca_mr *mr);428429int mthca_init_uar_table(struct mthca_dev *dev);430int mthca_init_pd_table(struct mthca_dev *dev);431int mthca_init_mr_table(struct mthca_dev *dev);432int mthca_init_eq_table(struct mthca_dev *dev);433int mthca_init_cq_table(struct mthca_dev *dev);434int mthca_init_srq_table(struct mthca_dev *dev);435int mthca_init_qp_table(struct mthca_dev *dev);436int mthca_init_av_table(struct mthca_dev *dev);437int mthca_init_mcg_table(struct mthca_dev *dev);438439void mthca_cleanup_uar_table(struct mthca_dev *dev);440void mthca_cleanup_pd_table(struct mthca_dev *dev);441void mthca_cleanup_mr_table(struct mthca_dev *dev);442void mthca_cleanup_eq_table(struct mthca_dev *dev);443void mthca_cleanup_cq_table(struct mthca_dev *dev);444void mthca_cleanup_srq_table(struct mthca_dev *dev);445void mthca_cleanup_qp_table(struct mthca_dev *dev);446void mthca_cleanup_av_table(struct mthca_dev *dev);447void mthca_cleanup_mcg_table(struct mthca_dev *dev);448449int mthca_register_device(struct mthca_dev *dev);450void mthca_unregister_device(struct mthca_dev *dev);451452void mthca_start_catas_poll(struct mthca_dev *dev);453void mthca_stop_catas_poll(struct mthca_dev *dev);454int __mthca_restart_one(struct pci_dev *pdev);455int mthca_catas_init(void);456void mthca_catas_cleanup(void);457458int mthca_uar_alloc(struct mthca_dev *dev, struct mthca_uar *uar);459void mthca_uar_free(struct mthca_dev *dev, struct mthca_uar *uar);460461int mthca_pd_alloc(struct mthca_dev *dev, int privileged, struct mthca_pd *pd);462void mthca_pd_free(struct mthca_dev *dev, struct mthca_pd *pd);463464int mthca_write_mtt_size(struct mthca_dev *dev);465466struct mthca_mtt *mthca_alloc_mtt(struct mthca_dev *dev, int size);467void mthca_free_mtt(struct mthca_dev *dev, struct mthca_mtt *mtt);468int mthca_write_mtt(struct mthca_dev *dev, struct mthca_mtt *mtt,469int start_index, u64 *buffer_list, int list_len);470int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,471u64 iova, u64 total_size, u32 access, struct mthca_mr *mr);472int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,473u32 access, struct mthca_mr *mr);474int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,475u64 *buffer_list, int buffer_size_shift,476int list_len, u64 iova, u64 total_size,477u32 access, struct mthca_mr *mr);478void mthca_free_mr(struct mthca_dev *dev, struct mthca_mr *mr);479480int mthca_fmr_alloc(struct mthca_dev *dev, u32 pd,481u32 access, struct mthca_fmr *fmr);482int mthca_tavor_map_phys_fmr(struct ib_fmr *ibfmr, u64 *page_list,483int list_len, u64 iova);484void mthca_tavor_fmr_unmap(struct mthca_dev *dev, struct mthca_fmr *fmr);485int mthca_arbel_map_phys_fmr(struct ib_fmr *ibfmr, u64 *page_list,486int list_len, u64 iova);487void mthca_arbel_fmr_unmap(struct mthca_dev *dev, struct mthca_fmr *fmr);488int mthca_free_fmr(struct mthca_dev *dev, struct mthca_fmr *fmr);489490int mthca_map_eq_icm(struct mthca_dev *dev, u64 icm_virt);491void mthca_unmap_eq_icm(struct mthca_dev *dev);492493int mthca_poll_cq(struct ib_cq *ibcq, int num_entries,494struct ib_wc *entry);495int mthca_tavor_arm_cq(struct ib_cq *cq, enum ib_cq_notify_flags flags);496int mthca_arbel_arm_cq(struct ib_cq *cq, enum ib_cq_notify_flags flags);497int mthca_init_cq(struct mthca_dev *dev, int nent,498struct mthca_ucontext *ctx, u32 pdn,499struct mthca_cq *cq);500void mthca_free_cq(struct mthca_dev *dev,501struct mthca_cq *cq);502void mthca_cq_completion(struct mthca_dev *dev, u32 cqn);503void mthca_cq_event(struct mthca_dev *dev, u32 cqn,504enum ib_event_type event_type);505void mthca_cq_clean(struct mthca_dev *dev, struct mthca_cq *cq, u32 qpn,506struct mthca_srq *srq);507void mthca_cq_resize_copy_cqes(struct mthca_cq *cq);508int mthca_alloc_cq_buf(struct mthca_dev *dev, struct mthca_cq_buf *buf, int nent);509void mthca_free_cq_buf(struct mthca_dev *dev, struct mthca_cq_buf *buf, int cqe);510511int mthca_alloc_srq(struct mthca_dev *dev, struct mthca_pd *pd,512struct ib_srq_attr *attr, struct mthca_srq *srq);513void mthca_free_srq(struct mthca_dev *dev, struct mthca_srq *srq);514int mthca_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr,515enum ib_srq_attr_mask attr_mask, struct ib_udata *udata);516int mthca_query_srq(struct ib_srq *srq, struct ib_srq_attr *srq_attr);517int mthca_max_srq_sge(struct mthca_dev *dev);518void mthca_srq_event(struct mthca_dev *dev, u32 srqn,519enum ib_event_type event_type);520void mthca_free_srq_wqe(struct mthca_srq *srq, u32 wqe_addr);521int mthca_tavor_post_srq_recv(struct ib_srq *srq, struct ib_recv_wr *wr,522struct ib_recv_wr **bad_wr);523int mthca_arbel_post_srq_recv(struct ib_srq *srq, struct ib_recv_wr *wr,524struct ib_recv_wr **bad_wr);525526void mthca_qp_event(struct mthca_dev *dev, u32 qpn,527enum ib_event_type event_type);528int mthca_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *qp_attr, int qp_attr_mask,529struct ib_qp_init_attr *qp_init_attr);530int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask,531struct ib_udata *udata);532int mthca_tavor_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,533struct ib_send_wr **bad_wr);534int mthca_tavor_post_receive(struct ib_qp *ibqp, struct ib_recv_wr *wr,535struct ib_recv_wr **bad_wr);536int mthca_arbel_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,537struct ib_send_wr **bad_wr);538int mthca_arbel_post_receive(struct ib_qp *ibqp, struct ib_recv_wr *wr,539struct ib_recv_wr **bad_wr);540void mthca_free_err_wqe(struct mthca_dev *dev, struct mthca_qp *qp, int is_send,541int index, int *dbd, __be32 *new_wqe);542int mthca_alloc_qp(struct mthca_dev *dev,543struct mthca_pd *pd,544struct mthca_cq *send_cq,545struct mthca_cq *recv_cq,546enum ib_qp_type type,547enum ib_sig_type send_policy,548struct ib_qp_cap *cap,549struct mthca_qp *qp);550int mthca_alloc_sqp(struct mthca_dev *dev,551struct mthca_pd *pd,552struct mthca_cq *send_cq,553struct mthca_cq *recv_cq,554enum ib_sig_type send_policy,555struct ib_qp_cap *cap,556int qpn,557int port,558struct mthca_sqp *sqp);559void mthca_free_qp(struct mthca_dev *dev, struct mthca_qp *qp);560int mthca_create_ah(struct mthca_dev *dev,561struct mthca_pd *pd,562struct ib_ah_attr *ah_attr,563struct mthca_ah *ah);564int mthca_destroy_ah(struct mthca_dev *dev, struct mthca_ah *ah);565int mthca_read_ah(struct mthca_dev *dev, struct mthca_ah *ah,566struct ib_ud_header *header);567int mthca_ah_query(struct ib_ah *ibah, struct ib_ah_attr *attr);568int mthca_ah_grh_present(struct mthca_ah *ah);569u8 mthca_get_rate(struct mthca_dev *dev, int static_rate, u8 port);570enum ib_rate mthca_rate_to_ib(struct mthca_dev *dev, u8 mthca_rate, u8 port);571572int mthca_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid);573int mthca_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid);574575int mthca_process_mad(struct ib_device *ibdev,576int mad_flags,577u8 port_num,578struct ib_wc *in_wc,579struct ib_grh *in_grh,580struct ib_mad *in_mad,581struct ib_mad *out_mad);582int mthca_create_agents(struct mthca_dev *dev);583void mthca_free_agents(struct mthca_dev *dev);584585static inline struct mthca_dev *to_mdev(struct ib_device *ibdev)586{587return container_of(ibdev, struct mthca_dev, ib_dev);588}589590static inline int mthca_is_memfree(struct mthca_dev *dev)591{592return dev->mthca_flags & MTHCA_FLAG_MEMFREE;593}594595#endif /* MTHCA_DEV_H */596597598