Path: blob/master/drivers/infiniband/hw/mlx4/mlx4_ib.h
15112 views
/*1* Copyright (c) 2006, 2007 Cisco Systems. All rights reserved.2* Copyright (c) 2007, 2008 Mellanox Technologies. All rights reserved.3*4* This software is available to you under a choice of one of two5* licenses. You may choose to be licensed under the terms of the GNU6* General Public License (GPL) Version 2, available from the file7* COPYING in the main directory of this source tree, or the8* OpenIB.org BSD license below:9*10* Redistribution and use in source and binary forms, with or11* without modification, are permitted provided that the following12* conditions are met:13*14* - Redistributions of source code must retain the above15* copyright notice, this list of conditions and the following16* disclaimer.17*18* - Redistributions in binary form must reproduce the above19* copyright notice, this list of conditions and the following20* disclaimer in the documentation and/or other materials21* provided with the distribution.22*23* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,24* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF25* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND26* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS27* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN28* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN29* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE30* SOFTWARE.31*/3233#ifndef MLX4_IB_H34#define MLX4_IB_H3536#include <linux/compiler.h>37#include <linux/list.h>38#include <linux/mutex.h>3940#include <rdma/ib_verbs.h>41#include <rdma/ib_umem.h>4243#include <linux/mlx4/device.h>44#include <linux/mlx4/doorbell.h>4546struct mlx4_ib_ucontext {47struct ib_ucontext ibucontext;48struct mlx4_uar uar;49struct list_head db_page_list;50struct mutex db_page_mutex;51};5253struct mlx4_ib_pd {54struct ib_pd ibpd;55u32 pdn;56};5758struct mlx4_ib_cq_buf {59struct mlx4_buf buf;60struct mlx4_mtt mtt;61};6263struct mlx4_ib_cq_resize {64struct mlx4_ib_cq_buf buf;65int cqe;66};6768struct mlx4_ib_cq {69struct ib_cq ibcq;70struct mlx4_cq mcq;71struct mlx4_ib_cq_buf buf;72struct mlx4_ib_cq_resize *resize_buf;73struct mlx4_db db;74spinlock_t lock;75struct mutex resize_mutex;76struct ib_umem *umem;77struct ib_umem *resize_umem;78};7980struct mlx4_ib_mr {81struct ib_mr ibmr;82struct mlx4_mr mmr;83struct ib_umem *umem;84};8586struct mlx4_ib_fast_reg_page_list {87struct ib_fast_reg_page_list ibfrpl;88__be64 *mapped_page_list;89dma_addr_t map;90};9192struct mlx4_ib_fmr {93struct ib_fmr ibfmr;94struct mlx4_fmr mfmr;95};9697struct mlx4_ib_wq {98u64 *wrid;99spinlock_t lock;100int wqe_cnt;101int max_post;102int max_gs;103int offset;104int wqe_shift;105unsigned head;106unsigned tail;107};108109enum mlx4_ib_qp_flags {110MLX4_IB_QP_LSO = 1 << 0,111MLX4_IB_QP_BLOCK_MULTICAST_LOOPBACK = 1 << 1,112};113114struct mlx4_ib_gid_entry {115struct list_head list;116union ib_gid gid;117int added;118u8 port;119};120121struct mlx4_ib_qp {122struct ib_qp ibqp;123struct mlx4_qp mqp;124struct mlx4_buf buf;125126struct mlx4_db db;127struct mlx4_ib_wq rq;128129u32 doorbell_qpn;130__be32 sq_signal_bits;131unsigned sq_next_wqe;132int sq_max_wqes_per_wr;133int sq_spare_wqes;134struct mlx4_ib_wq sq;135136struct ib_umem *umem;137struct mlx4_mtt mtt;138int buf_size;139struct mutex mutex;140u32 flags;141u8 port;142u8 alt_port;143u8 atomic_rd_en;144u8 resp_depth;145u8 sq_no_prefetch;146u8 state;147int mlx_type;148struct list_head gid_list;149};150151struct mlx4_ib_srq {152struct ib_srq ibsrq;153struct mlx4_srq msrq;154struct mlx4_buf buf;155struct mlx4_db db;156u64 *wrid;157spinlock_t lock;158int head;159int tail;160u16 wqe_ctr;161struct ib_umem *umem;162struct mlx4_mtt mtt;163struct mutex mutex;164};165166struct mlx4_ib_ah {167struct ib_ah ibah;168union mlx4_ext_av av;169};170171struct mlx4_ib_iboe {172spinlock_t lock;173struct net_device *netdevs[MLX4_MAX_PORTS];174struct notifier_block nb;175union ib_gid gid_table[MLX4_MAX_PORTS][128];176};177178struct mlx4_ib_dev {179struct ib_device ib_dev;180struct mlx4_dev *dev;181int num_ports;182void __iomem *uar_map;183184struct mlx4_uar priv_uar;185u32 priv_pdn;186MLX4_DECLARE_DOORBELL_LOCK(uar_lock);187188struct ib_mad_agent *send_agent[MLX4_MAX_PORTS][2];189struct ib_ah *sm_ah[MLX4_MAX_PORTS];190spinlock_t sm_lock;191192struct mutex cap_mask_mutex;193bool ib_active;194struct mlx4_ib_iboe iboe;195};196197static inline struct mlx4_ib_dev *to_mdev(struct ib_device *ibdev)198{199return container_of(ibdev, struct mlx4_ib_dev, ib_dev);200}201202static inline struct mlx4_ib_ucontext *to_mucontext(struct ib_ucontext *ibucontext)203{204return container_of(ibucontext, struct mlx4_ib_ucontext, ibucontext);205}206207static inline struct mlx4_ib_pd *to_mpd(struct ib_pd *ibpd)208{209return container_of(ibpd, struct mlx4_ib_pd, ibpd);210}211212static inline struct mlx4_ib_cq *to_mcq(struct ib_cq *ibcq)213{214return container_of(ibcq, struct mlx4_ib_cq, ibcq);215}216217static inline struct mlx4_ib_cq *to_mibcq(struct mlx4_cq *mcq)218{219return container_of(mcq, struct mlx4_ib_cq, mcq);220}221222static inline struct mlx4_ib_mr *to_mmr(struct ib_mr *ibmr)223{224return container_of(ibmr, struct mlx4_ib_mr, ibmr);225}226227static inline struct mlx4_ib_fast_reg_page_list *to_mfrpl(struct ib_fast_reg_page_list *ibfrpl)228{229return container_of(ibfrpl, struct mlx4_ib_fast_reg_page_list, ibfrpl);230}231232static inline struct mlx4_ib_fmr *to_mfmr(struct ib_fmr *ibfmr)233{234return container_of(ibfmr, struct mlx4_ib_fmr, ibfmr);235}236static inline struct mlx4_ib_qp *to_mqp(struct ib_qp *ibqp)237{238return container_of(ibqp, struct mlx4_ib_qp, ibqp);239}240241static inline struct mlx4_ib_qp *to_mibqp(struct mlx4_qp *mqp)242{243return container_of(mqp, struct mlx4_ib_qp, mqp);244}245246static inline struct mlx4_ib_srq *to_msrq(struct ib_srq *ibsrq)247{248return container_of(ibsrq, struct mlx4_ib_srq, ibsrq);249}250251static inline struct mlx4_ib_srq *to_mibsrq(struct mlx4_srq *msrq)252{253return container_of(msrq, struct mlx4_ib_srq, msrq);254}255256static inline struct mlx4_ib_ah *to_mah(struct ib_ah *ibah)257{258return container_of(ibah, struct mlx4_ib_ah, ibah);259}260261int mlx4_ib_db_map_user(struct mlx4_ib_ucontext *context, unsigned long virt,262struct mlx4_db *db);263void mlx4_ib_db_unmap_user(struct mlx4_ib_ucontext *context, struct mlx4_db *db);264265struct ib_mr *mlx4_ib_get_dma_mr(struct ib_pd *pd, int acc);266int mlx4_ib_umem_write_mtt(struct mlx4_ib_dev *dev, struct mlx4_mtt *mtt,267struct ib_umem *umem);268struct ib_mr *mlx4_ib_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,269u64 virt_addr, int access_flags,270struct ib_udata *udata);271int mlx4_ib_dereg_mr(struct ib_mr *mr);272struct ib_mr *mlx4_ib_alloc_fast_reg_mr(struct ib_pd *pd,273int max_page_list_len);274struct ib_fast_reg_page_list *mlx4_ib_alloc_fast_reg_page_list(struct ib_device *ibdev,275int page_list_len);276void mlx4_ib_free_fast_reg_page_list(struct ib_fast_reg_page_list *page_list);277278int mlx4_ib_modify_cq(struct ib_cq *cq, u16 cq_count, u16 cq_period);279int mlx4_ib_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata);280struct ib_cq *mlx4_ib_create_cq(struct ib_device *ibdev, int entries, int vector,281struct ib_ucontext *context,282struct ib_udata *udata);283int mlx4_ib_destroy_cq(struct ib_cq *cq);284int mlx4_ib_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *wc);285int mlx4_ib_arm_cq(struct ib_cq *cq, enum ib_cq_notify_flags flags);286void __mlx4_ib_cq_clean(struct mlx4_ib_cq *cq, u32 qpn, struct mlx4_ib_srq *srq);287void mlx4_ib_cq_clean(struct mlx4_ib_cq *cq, u32 qpn, struct mlx4_ib_srq *srq);288289struct ib_ah *mlx4_ib_create_ah(struct ib_pd *pd, struct ib_ah_attr *ah_attr);290int mlx4_ib_query_ah(struct ib_ah *ibah, struct ib_ah_attr *ah_attr);291int mlx4_ib_destroy_ah(struct ib_ah *ah);292293struct ib_srq *mlx4_ib_create_srq(struct ib_pd *pd,294struct ib_srq_init_attr *init_attr,295struct ib_udata *udata);296int mlx4_ib_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr,297enum ib_srq_attr_mask attr_mask, struct ib_udata *udata);298int mlx4_ib_query_srq(struct ib_srq *srq, struct ib_srq_attr *srq_attr);299int mlx4_ib_destroy_srq(struct ib_srq *srq);300void mlx4_ib_free_srq_wqe(struct mlx4_ib_srq *srq, int wqe_index);301int mlx4_ib_post_srq_recv(struct ib_srq *ibsrq, struct ib_recv_wr *wr,302struct ib_recv_wr **bad_wr);303304struct ib_qp *mlx4_ib_create_qp(struct ib_pd *pd,305struct ib_qp_init_attr *init_attr,306struct ib_udata *udata);307int mlx4_ib_destroy_qp(struct ib_qp *qp);308int mlx4_ib_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,309int attr_mask, struct ib_udata *udata);310int mlx4_ib_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *qp_attr, int qp_attr_mask,311struct ib_qp_init_attr *qp_init_attr);312int mlx4_ib_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,313struct ib_send_wr **bad_wr);314int mlx4_ib_post_recv(struct ib_qp *ibqp, struct ib_recv_wr *wr,315struct ib_recv_wr **bad_wr);316317int mlx4_MAD_IFC(struct mlx4_ib_dev *dev, int ignore_mkey, int ignore_bkey,318int port, struct ib_wc *in_wc, struct ib_grh *in_grh,319void *in_mad, void *response_mad);320int mlx4_ib_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,321struct ib_wc *in_wc, struct ib_grh *in_grh,322struct ib_mad *in_mad, struct ib_mad *out_mad);323int mlx4_ib_mad_init(struct mlx4_ib_dev *dev);324void mlx4_ib_mad_cleanup(struct mlx4_ib_dev *dev);325326struct ib_fmr *mlx4_ib_fmr_alloc(struct ib_pd *pd, int mr_access_flags,327struct ib_fmr_attr *fmr_attr);328int mlx4_ib_map_phys_fmr(struct ib_fmr *ibfmr, u64 *page_list, int npages,329u64 iova);330int mlx4_ib_unmap_fmr(struct list_head *fmr_list);331int mlx4_ib_fmr_dealloc(struct ib_fmr *fmr);332333int mlx4_ib_resolve_grh(struct mlx4_ib_dev *dev, const struct ib_ah_attr *ah_attr,334u8 *mac, int *is_mcast, u8 port);335336static inline int mlx4_ib_ah_grh_present(struct mlx4_ib_ah *ah)337{338u8 port = be32_to_cpu(ah->av.ib.port_pd) >> 24 & 3;339340if (rdma_port_get_link_layer(ah->ibah.device, port) == IB_LINK_LAYER_ETHERNET)341return 1;342343return !!(ah->av.ib.g_slid & 0x80);344}345346int mlx4_ib_add_mc(struct mlx4_ib_dev *mdev, struct mlx4_ib_qp *mqp,347union ib_gid *gid);348349#endif /* MLX4_IB_H */350351352