Path: blob/master/drivers/infiniband/hw/mthca/mthca_provider.h
15112 views
/*1* Copyright (c) 2004 Topspin Communications. All rights reserved.2* Copyright (c) 2005, 2006 Cisco Systems. All rights reserved.3* Copyright (c) 2005 Mellanox Technologies. All rights reserved.4*5* This software is available to you under a choice of one of two6* licenses. You may choose to be licensed under the terms of the GNU7* General Public License (GPL) Version 2, available from the file8* COPYING in the main directory of this source tree, or the9* OpenIB.org BSD license below:10*11* Redistribution and use in source and binary forms, with or12* without modification, are permitted provided that the following13* conditions are met:14*15* - Redistributions of source code must retain the above16* copyright notice, this list of conditions and the following17* disclaimer.18*19* - Redistributions in binary form must reproduce the above20* copyright notice, this list of conditions and the following21* disclaimer in the documentation and/or other materials22* provided with the distribution.23*24* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,25* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF26* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND27* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS28* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN29* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN30* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE31* SOFTWARE.32*/3334#ifndef MTHCA_PROVIDER_H35#define MTHCA_PROVIDER_H3637#include <rdma/ib_verbs.h>38#include <rdma/ib_pack.h>3940#define MTHCA_MPT_FLAG_ATOMIC (1 << 14)41#define MTHCA_MPT_FLAG_REMOTE_WRITE (1 << 13)42#define MTHCA_MPT_FLAG_REMOTE_READ (1 << 12)43#define MTHCA_MPT_FLAG_LOCAL_WRITE (1 << 11)44#define MTHCA_MPT_FLAG_LOCAL_READ (1 << 10)4546struct mthca_buf_list {47void *buf;48DEFINE_DMA_UNMAP_ADDR(mapping);49};5051union mthca_buf {52struct mthca_buf_list direct;53struct mthca_buf_list *page_list;54};5556struct mthca_uar {57unsigned long pfn;58int index;59};6061struct mthca_user_db_table;6263struct mthca_ucontext {64struct ib_ucontext ibucontext;65struct mthca_uar uar;66struct mthca_user_db_table *db_tab;67int reg_mr_warned;68};6970struct mthca_mtt;7172struct mthca_mr {73struct ib_mr ibmr;74struct ib_umem *umem;75struct mthca_mtt *mtt;76};7778struct mthca_fmr {79struct ib_fmr ibmr;80struct ib_fmr_attr attr;81struct mthca_mtt *mtt;82int maps;83union {84struct {85struct mthca_mpt_entry __iomem *mpt;86u64 __iomem *mtts;87} tavor;88struct {89struct mthca_mpt_entry *mpt;90__be64 *mtts;91dma_addr_t dma_handle;92} arbel;93} mem;94};9596struct mthca_pd {97struct ib_pd ibpd;98u32 pd_num;99atomic_t sqp_count;100struct mthca_mr ntmr;101int privileged;102};103104struct mthca_eq {105struct mthca_dev *dev;106int eqn;107u32 eqn_mask;108u32 cons_index;109u16 msi_x_vector;110u16 msi_x_entry;111int have_irq;112int nent;113struct mthca_buf_list *page_list;114struct mthca_mr mr;115char irq_name[IB_DEVICE_NAME_MAX];116};117118struct mthca_av;119120enum mthca_ah_type {121MTHCA_AH_ON_HCA,122MTHCA_AH_PCI_POOL,123MTHCA_AH_KMALLOC124};125126struct mthca_ah {127struct ib_ah ibah;128enum mthca_ah_type type;129u32 key;130struct mthca_av *av;131dma_addr_t avdma;132};133134/*135* Quick description of our CQ/QP locking scheme:136*137* We have one global lock that protects dev->cq/qp_table. Each138* struct mthca_cq/qp also has its own lock. An individual qp lock139* may be taken inside of an individual cq lock. Both cqs attached to140* a qp may be locked, with the cq with the lower cqn locked first.141* No other nesting should be done.142*143* Each struct mthca_cq/qp also has an ref count, protected by the144* corresponding table lock. The pointer from the cq/qp_table to the145* struct counts as one reference. This reference also is good for146* access through the consumer API, so modifying the CQ/QP etc doesn't147* need to take another reference. Access to a QP because of a148* completion being polled does not need a reference either.149*150* Finally, each struct mthca_cq/qp has a wait_queue_head_t for the151* destroy function to sleep on.152*153* This means that access from the consumer API requires nothing but154* taking the struct's lock.155*156* Access because of a completion event should go as follows:157* - lock cq/qp_table and look up struct158* - increment ref count in struct159* - drop cq/qp_table lock160* - lock struct, do your thing, and unlock struct161* - decrement ref count; if zero, wake up waiters162*163* To destroy a CQ/QP, we can do the following:164* - lock cq/qp_table165* - remove pointer and decrement ref count166* - unlock cq/qp_table lock167* - wait_event until ref count is zero168*169* It is the consumer's responsibilty to make sure that no QP170* operations (WQE posting or state modification) are pending when a171* QP is destroyed. Also, the consumer must make sure that calls to172* qp_modify are serialized. Similarly, the consumer is responsible173* for ensuring that no CQ resize operations are pending when a CQ174* is destroyed.175*176* Possible optimizations (wait for profile data to see if/where we177* have locks bouncing between CPUs):178* - split cq/qp table lock into n separate (cache-aligned) locks,179* indexed (say) by the page in the table180* - split QP struct lock into three (one for common info, one for the181* send queue and one for the receive queue)182*/183184struct mthca_cq_buf {185union mthca_buf queue;186struct mthca_mr mr;187int is_direct;188};189190struct mthca_cq_resize {191struct mthca_cq_buf buf;192int cqe;193enum {194CQ_RESIZE_ALLOC,195CQ_RESIZE_READY,196CQ_RESIZE_SWAPPED197} state;198};199200struct mthca_cq {201struct ib_cq ibcq;202spinlock_t lock;203int refcount;204int cqn;205u32 cons_index;206struct mthca_cq_buf buf;207struct mthca_cq_resize *resize_buf;208int is_kernel;209210/* Next fields are Arbel only */211int set_ci_db_index;212__be32 *set_ci_db;213int arm_db_index;214__be32 *arm_db;215int arm_sn;216217wait_queue_head_t wait;218struct mutex mutex;219};220221struct mthca_srq {222struct ib_srq ibsrq;223spinlock_t lock;224int refcount;225int srqn;226int max;227int max_gs;228int wqe_shift;229int first_free;230int last_free;231u16 counter; /* Arbel only */232int db_index; /* Arbel only */233__be32 *db; /* Arbel only */234void *last;235236int is_direct;237u64 *wrid;238union mthca_buf queue;239struct mthca_mr mr;240241wait_queue_head_t wait;242struct mutex mutex;243};244245struct mthca_wq {246spinlock_t lock;247int max;248unsigned next_ind;249unsigned last_comp;250unsigned head;251unsigned tail;252void *last;253int max_gs;254int wqe_shift;255256int db_index; /* Arbel only */257__be32 *db;258};259260struct mthca_qp {261struct ib_qp ibqp;262int refcount;263u32 qpn;264int is_direct;265u8 port; /* for SQP and memfree use only */266u8 alt_port; /* for memfree use only */267u8 transport;268u8 state;269u8 atomic_rd_en;270u8 resp_depth;271272struct mthca_mr mr;273274struct mthca_wq rq;275struct mthca_wq sq;276enum ib_sig_type sq_policy;277int send_wqe_offset;278int max_inline_data;279280u64 *wrid;281union mthca_buf queue;282283wait_queue_head_t wait;284struct mutex mutex;285};286287struct mthca_sqp {288struct mthca_qp qp;289int pkey_index;290u32 qkey;291u32 send_psn;292struct ib_ud_header ud_header;293int header_buf_size;294void *header_buf;295dma_addr_t header_dma;296};297298static inline struct mthca_ucontext *to_mucontext(struct ib_ucontext *ibucontext)299{300return container_of(ibucontext, struct mthca_ucontext, ibucontext);301}302303static inline struct mthca_fmr *to_mfmr(struct ib_fmr *ibmr)304{305return container_of(ibmr, struct mthca_fmr, ibmr);306}307308static inline struct mthca_mr *to_mmr(struct ib_mr *ibmr)309{310return container_of(ibmr, struct mthca_mr, ibmr);311}312313static inline struct mthca_pd *to_mpd(struct ib_pd *ibpd)314{315return container_of(ibpd, struct mthca_pd, ibpd);316}317318static inline struct mthca_ah *to_mah(struct ib_ah *ibah)319{320return container_of(ibah, struct mthca_ah, ibah);321}322323static inline struct mthca_cq *to_mcq(struct ib_cq *ibcq)324{325return container_of(ibcq, struct mthca_cq, ibcq);326}327328static inline struct mthca_srq *to_msrq(struct ib_srq *ibsrq)329{330return container_of(ibsrq, struct mthca_srq, ibsrq);331}332333static inline struct mthca_qp *to_mqp(struct ib_qp *ibqp)334{335return container_of(ibqp, struct mthca_qp, ibqp);336}337338static inline struct mthca_sqp *to_msqp(struct mthca_qp *qp)339{340return container_of(qp, struct mthca_sqp, qp);341}342343#endif /* MTHCA_PROVIDER_H */344345346