11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * Copyright (c) 2004 Topspin Communications. All rights reserved. 34885bf64SRoland Dreier * Copyright (c) 2005, 2006 Cisco Systems. All rights reserved. 42a1d9b7fSRoland Dreier * Copyright (c) 2005 Mellanox Technologies. All rights reserved. 51da177e4SLinus Torvalds * 61da177e4SLinus Torvalds * This software is available to you under a choice of one of two 71da177e4SLinus Torvalds * licenses. You may choose to be licensed under the terms of the GNU 81da177e4SLinus Torvalds * General Public License (GPL) Version 2, available from the file 91da177e4SLinus Torvalds * COPYING in the main directory of this source tree, or the 101da177e4SLinus Torvalds * OpenIB.org BSD license below: 111da177e4SLinus Torvalds * 121da177e4SLinus Torvalds * Redistribution and use in source and binary forms, with or 131da177e4SLinus Torvalds * without modification, are permitted provided that the following 141da177e4SLinus Torvalds * conditions are met: 151da177e4SLinus Torvalds * 161da177e4SLinus Torvalds * - Redistributions of source code must retain the above 171da177e4SLinus Torvalds * copyright notice, this list of conditions and the following 181da177e4SLinus Torvalds * disclaimer. 191da177e4SLinus Torvalds * 201da177e4SLinus Torvalds * - Redistributions in binary form must reproduce the above 211da177e4SLinus Torvalds * copyright notice, this list of conditions and the following 221da177e4SLinus Torvalds * disclaimer in the documentation and/or other materials 231da177e4SLinus Torvalds * provided with the distribution. 241da177e4SLinus Torvalds * 251da177e4SLinus Torvalds * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 261da177e4SLinus Torvalds * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 271da177e4SLinus Torvalds * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 281da177e4SLinus Torvalds * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 291da177e4SLinus Torvalds * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 301da177e4SLinus Torvalds * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 311da177e4SLinus Torvalds * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 321da177e4SLinus Torvalds * SOFTWARE. 331da177e4SLinus Torvalds */ 341da177e4SLinus Torvalds 351da177e4SLinus Torvalds #ifndef MTHCA_PROVIDER_H 361da177e4SLinus Torvalds #define MTHCA_PROVIDER_H 371da177e4SLinus Torvalds 38a4d61e84SRoland Dreier #include <rdma/ib_verbs.h> 39a4d61e84SRoland Dreier #include <rdma/ib_pack.h> 401da177e4SLinus Torvalds 411da177e4SLinus Torvalds #define MTHCA_MPT_FLAG_ATOMIC (1 << 14) 421da177e4SLinus Torvalds #define MTHCA_MPT_FLAG_REMOTE_WRITE (1 << 13) 431da177e4SLinus Torvalds #define MTHCA_MPT_FLAG_REMOTE_READ (1 << 12) 441da177e4SLinus Torvalds #define MTHCA_MPT_FLAG_LOCAL_WRITE (1 << 11) 451da177e4SLinus Torvalds #define MTHCA_MPT_FLAG_LOCAL_READ (1 << 10) 461da177e4SLinus Torvalds 471da177e4SLinus Torvalds struct mthca_buf_list { 481da177e4SLinus Torvalds void *buf; 493a2baff7SFUJITA Tomonori DEFINE_DMA_UNMAP_ADDR(mapping); 501da177e4SLinus Torvalds }; 511da177e4SLinus Torvalds 5287b81670SRoland Dreier union mthca_buf { 5387b81670SRoland Dreier struct mthca_buf_list direct; 5487b81670SRoland Dreier struct mthca_buf_list *page_list; 5587b81670SRoland Dreier }; 5687b81670SRoland Dreier 571da177e4SLinus Torvalds struct mthca_uar { 581da177e4SLinus Torvalds unsigned long pfn; 591da177e4SLinus Torvalds int index; 601da177e4SLinus Torvalds }; 611da177e4SLinus Torvalds 625e0b537cSRoland Dreier struct mthca_user_db_table; 635e0b537cSRoland Dreier 645e0b537cSRoland Dreier struct mthca_ucontext { 655e0b537cSRoland Dreier struct ib_ucontext ibucontext; 665e0b537cSRoland Dreier struct mthca_uar uar; 675e0b537cSRoland Dreier struct mthca_user_db_table *db_tab; 68baaad380SRoland Dreier int reg_mr_warned; 695e0b537cSRoland Dreier }; 705e0b537cSRoland Dreier 71d56d6f95SRoland Dreier struct mthca_mtt; 72d56d6f95SRoland Dreier 731da177e4SLinus Torvalds struct mthca_mr { 741da177e4SLinus Torvalds struct ib_mr ibmr; 75f7c6a7b5SRoland Dreier struct ib_umem *umem; 76d56d6f95SRoland Dreier struct mthca_mtt *mtt; 771da177e4SLinus Torvalds }; 781da177e4SLinus Torvalds 791da177e4SLinus Torvalds struct mthca_pd { 801da177e4SLinus Torvalds struct ib_pd ibpd; 811da177e4SLinus Torvalds u32 pd_num; 821da177e4SLinus Torvalds atomic_t sqp_count; 831da177e4SLinus Torvalds struct mthca_mr ntmr; 8499264c1eSRoland Dreier int privileged; 851da177e4SLinus Torvalds }; 861da177e4SLinus Torvalds 871da177e4SLinus Torvalds struct mthca_eq { 881da177e4SLinus Torvalds struct mthca_dev *dev; 891da177e4SLinus Torvalds int eqn; 901da177e4SLinus Torvalds u32 eqn_mask; 911da177e4SLinus Torvalds u32 cons_index; 921da177e4SLinus Torvalds u16 msi_x_vector; 931da177e4SLinus Torvalds u16 msi_x_entry; 941da177e4SLinus Torvalds int have_irq; 951da177e4SLinus Torvalds int nent; 961da177e4SLinus Torvalds struct mthca_buf_list *page_list; 971da177e4SLinus Torvalds struct mthca_mr mr; 98d94a8689SArputham Benjamin char irq_name[IB_DEVICE_NAME_MAX]; 991da177e4SLinus Torvalds }; 1001da177e4SLinus Torvalds 1011da177e4SLinus Torvalds struct mthca_av; 1021da177e4SLinus Torvalds 1031da177e4SLinus Torvalds enum mthca_ah_type { 1041da177e4SLinus Torvalds MTHCA_AH_ON_HCA, 1051da177e4SLinus Torvalds MTHCA_AH_PCI_POOL, 1061da177e4SLinus Torvalds MTHCA_AH_KMALLOC 1071da177e4SLinus Torvalds }; 1081da177e4SLinus Torvalds 1091da177e4SLinus Torvalds struct mthca_ah { 1101da177e4SLinus Torvalds struct ib_ah ibah; 1111da177e4SLinus Torvalds enum mthca_ah_type type; 1121da177e4SLinus Torvalds u32 key; 1131da177e4SLinus Torvalds struct mthca_av *av; 1141da177e4SLinus Torvalds dma_addr_t avdma; 1151da177e4SLinus Torvalds }; 1161da177e4SLinus Torvalds 1171da177e4SLinus Torvalds /* 1181da177e4SLinus Torvalds * Quick description of our CQ/QP locking scheme: 1191da177e4SLinus Torvalds * 1201da177e4SLinus Torvalds * We have one global lock that protects dev->cq/qp_table. Each 1211da177e4SLinus Torvalds * struct mthca_cq/qp also has its own lock. An individual qp lock 1221da177e4SLinus Torvalds * may be taken inside of an individual cq lock. Both cqs attached to 123a19aa5c5SRoland Dreier * a qp may be locked, with the cq with the lower cqn locked first. 124a19aa5c5SRoland Dreier * No other nesting should be done. 1251da177e4SLinus Torvalds * 126a3285aa4SRoland Dreier * Each struct mthca_cq/qp also has an ref count, protected by the 127a3285aa4SRoland Dreier * corresponding table lock. The pointer from the cq/qp_table to the 128a3285aa4SRoland Dreier * struct counts as one reference. This reference also is good for 129a3285aa4SRoland Dreier * access through the consumer API, so modifying the CQ/QP etc doesn't 130a3285aa4SRoland Dreier * need to take another reference. Access to a QP because of a 131a3285aa4SRoland Dreier * completion being polled does not need a reference either. 1321da177e4SLinus Torvalds * 1331da177e4SLinus Torvalds * Finally, each struct mthca_cq/qp has a wait_queue_head_t for the 1341da177e4SLinus Torvalds * destroy function to sleep on. 1351da177e4SLinus Torvalds * 1361da177e4SLinus Torvalds * This means that access from the consumer API requires nothing but 1371da177e4SLinus Torvalds * taking the struct's lock. 1381da177e4SLinus Torvalds * 1391da177e4SLinus Torvalds * Access because of a completion event should go as follows: 1401da177e4SLinus Torvalds * - lock cq/qp_table and look up struct 1411da177e4SLinus Torvalds * - increment ref count in struct 1421da177e4SLinus Torvalds * - drop cq/qp_table lock 1431da177e4SLinus Torvalds * - lock struct, do your thing, and unlock struct 1441da177e4SLinus Torvalds * - decrement ref count; if zero, wake up waiters 1451da177e4SLinus Torvalds * 1461da177e4SLinus Torvalds * To destroy a CQ/QP, we can do the following: 147a3285aa4SRoland Dreier * - lock cq/qp_table 148a3285aa4SRoland Dreier * - remove pointer and decrement ref count 149a3285aa4SRoland Dreier * - unlock cq/qp_table lock 1501da177e4SLinus Torvalds * - wait_event until ref count is zero 1511da177e4SLinus Torvalds * 1521da177e4SLinus Torvalds * It is the consumer's responsibilty to make sure that no QP 1534885bf64SRoland Dreier * operations (WQE posting or state modification) are pending when a 1541da177e4SLinus Torvalds * QP is destroyed. Also, the consumer must make sure that calls to 1554885bf64SRoland Dreier * qp_modify are serialized. Similarly, the consumer is responsible 1564885bf64SRoland Dreier * for ensuring that no CQ resize operations are pending when a CQ 1574885bf64SRoland Dreier * is destroyed. 1581da177e4SLinus Torvalds * 1591da177e4SLinus Torvalds * Possible optimizations (wait for profile data to see if/where we 1601da177e4SLinus Torvalds * have locks bouncing between CPUs): 1611da177e4SLinus Torvalds * - split cq/qp table lock into n separate (cache-aligned) locks, 1621da177e4SLinus Torvalds * indexed (say) by the page in the table 1631da177e4SLinus Torvalds * - split QP struct lock into three (one for common info, one for the 1641da177e4SLinus Torvalds * send queue and one for the receive queue) 1651da177e4SLinus Torvalds */ 1661da177e4SLinus Torvalds 1674885bf64SRoland Dreier struct mthca_cq_buf { 1684885bf64SRoland Dreier union mthca_buf queue; 1694885bf64SRoland Dreier struct mthca_mr mr; 1704885bf64SRoland Dreier int is_direct; 1714885bf64SRoland Dreier }; 1724885bf64SRoland Dreier 1734885bf64SRoland Dreier struct mthca_cq_resize { 1744885bf64SRoland Dreier struct mthca_cq_buf buf; 1754885bf64SRoland Dreier int cqe; 1764885bf64SRoland Dreier enum { 1774885bf64SRoland Dreier CQ_RESIZE_ALLOC, 1784885bf64SRoland Dreier CQ_RESIZE_READY, 1794885bf64SRoland Dreier CQ_RESIZE_SWAPPED 1804885bf64SRoland Dreier } state; 1814885bf64SRoland Dreier }; 1824885bf64SRoland Dreier 1831da177e4SLinus Torvalds struct mthca_cq { 1841da177e4SLinus Torvalds struct ib_cq ibcq; 1851da177e4SLinus Torvalds spinlock_t lock; 186a3285aa4SRoland Dreier int refcount; 1871da177e4SLinus Torvalds int cqn; 1881da177e4SLinus Torvalds u32 cons_index; 1894885bf64SRoland Dreier struct mthca_cq_buf buf; 1904885bf64SRoland Dreier struct mthca_cq_resize *resize_buf; 19174c2174eSRoland Dreier int is_kernel; 1921da177e4SLinus Torvalds 1931da177e4SLinus Torvalds /* Next fields are Arbel only */ 1941da177e4SLinus Torvalds int set_ci_db_index; 19597f52eb4SSean Hefty __be32 *set_ci_db; 1961da177e4SLinus Torvalds int arm_db_index; 19797f52eb4SSean Hefty __be32 *arm_db; 1981da177e4SLinus Torvalds int arm_sn; 1991da177e4SLinus Torvalds 2001da177e4SLinus Torvalds wait_queue_head_t wait; 201c93b6fbaSRoland Dreier struct mutex mutex; 2021da177e4SLinus Torvalds }; 2031da177e4SLinus Torvalds 204ec34a922SRoland Dreier struct mthca_srq { 205ec34a922SRoland Dreier struct ib_srq ibsrq; 206ec34a922SRoland Dreier spinlock_t lock; 207a3285aa4SRoland Dreier int refcount; 208ec34a922SRoland Dreier int srqn; 209ec34a922SRoland Dreier int max; 210ec34a922SRoland Dreier int max_gs; 211ec34a922SRoland Dreier int wqe_shift; 212ec34a922SRoland Dreier int first_free; 213ec34a922SRoland Dreier int last_free; 214ec34a922SRoland Dreier u16 counter; /* Arbel only */ 215ec34a922SRoland Dreier int db_index; /* Arbel only */ 216ec34a922SRoland Dreier __be32 *db; /* Arbel only */ 217ec34a922SRoland Dreier void *last; 218ec34a922SRoland Dreier 219ec34a922SRoland Dreier int is_direct; 220ec34a922SRoland Dreier u64 *wrid; 221ec34a922SRoland Dreier union mthca_buf queue; 222ec34a922SRoland Dreier struct mthca_mr mr; 223ec34a922SRoland Dreier 224ec34a922SRoland Dreier wait_queue_head_t wait; 225c93b6fbaSRoland Dreier struct mutex mutex; 226ec34a922SRoland Dreier }; 227ec34a922SRoland Dreier 2281da177e4SLinus Torvalds struct mthca_wq { 2291da177e4SLinus Torvalds spinlock_t lock; 2301da177e4SLinus Torvalds int max; 2311da177e4SLinus Torvalds unsigned next_ind; 2321da177e4SLinus Torvalds unsigned last_comp; 2331da177e4SLinus Torvalds unsigned head; 2341da177e4SLinus Torvalds unsigned tail; 2351da177e4SLinus Torvalds void *last; 2361da177e4SLinus Torvalds int max_gs; 2371da177e4SLinus Torvalds int wqe_shift; 2381da177e4SLinus Torvalds 2391da177e4SLinus Torvalds int db_index; /* Arbel only */ 24097f52eb4SSean Hefty __be32 *db; 2411da177e4SLinus Torvalds }; 2421da177e4SLinus Torvalds 243*21c2fe94SLeon Romanovsky struct mthca_sqp { 244*21c2fe94SLeon Romanovsky int pkey_index; 245*21c2fe94SLeon Romanovsky u32 qkey; 246*21c2fe94SLeon Romanovsky u32 send_psn; 247*21c2fe94SLeon Romanovsky struct ib_ud_header ud_header; 248*21c2fe94SLeon Romanovsky int header_buf_size; 249*21c2fe94SLeon Romanovsky void *header_buf; 250*21c2fe94SLeon Romanovsky dma_addr_t header_dma; 251*21c2fe94SLeon Romanovsky }; 252*21c2fe94SLeon Romanovsky 2531da177e4SLinus Torvalds struct mthca_qp { 2541da177e4SLinus Torvalds struct ib_qp ibqp; 255a3285aa4SRoland Dreier int refcount; 2561da177e4SLinus Torvalds u32 qpn; 2571da177e4SLinus Torvalds int is_direct; 258bf6a9e31SJack Morgenstein u8 port; /* for SQP and memfree use only */ 259bf6a9e31SJack Morgenstein u8 alt_port; /* for memfree use only */ 2601da177e4SLinus Torvalds u8 transport; 2611da177e4SLinus Torvalds u8 state; 2621da177e4SLinus Torvalds u8 atomic_rd_en; 2631da177e4SLinus Torvalds u8 resp_depth; 2641da177e4SLinus Torvalds 2651da177e4SLinus Torvalds struct mthca_mr mr; 2661da177e4SLinus Torvalds 2671da177e4SLinus Torvalds struct mthca_wq rq; 2681da177e4SLinus Torvalds struct mthca_wq sq; 2691da177e4SLinus Torvalds enum ib_sig_type sq_policy; 2701da177e4SLinus Torvalds int send_wqe_offset; 27177369ed3SJack Morgenstein int max_inline_data; 2721da177e4SLinus Torvalds 2731da177e4SLinus Torvalds u64 *wrid; 27487b81670SRoland Dreier union mthca_buf queue; 2751da177e4SLinus Torvalds 2761da177e4SLinus Torvalds wait_queue_head_t wait; 277c93b6fbaSRoland Dreier struct mutex mutex; 278*21c2fe94SLeon Romanovsky struct mthca_sqp *sqp; 2791da177e4SLinus Torvalds }; 2801da177e4SLinus Torvalds 2815e0b537cSRoland Dreier static inline struct mthca_ucontext *to_mucontext(struct ib_ucontext *ibucontext) 2825e0b537cSRoland Dreier { 2835e0b537cSRoland Dreier return container_of(ibucontext, struct mthca_ucontext, ibucontext); 2845e0b537cSRoland Dreier } 2855e0b537cSRoland Dreier 2861da177e4SLinus Torvalds static inline struct mthca_mr *to_mmr(struct ib_mr *ibmr) 2871da177e4SLinus Torvalds { 2881da177e4SLinus Torvalds return container_of(ibmr, struct mthca_mr, ibmr); 2891da177e4SLinus Torvalds } 2901da177e4SLinus Torvalds 2911da177e4SLinus Torvalds static inline struct mthca_pd *to_mpd(struct ib_pd *ibpd) 2921da177e4SLinus Torvalds { 2931da177e4SLinus Torvalds return container_of(ibpd, struct mthca_pd, ibpd); 2941da177e4SLinus Torvalds } 2951da177e4SLinus Torvalds 2961da177e4SLinus Torvalds static inline struct mthca_ah *to_mah(struct ib_ah *ibah) 2971da177e4SLinus Torvalds { 2981da177e4SLinus Torvalds return container_of(ibah, struct mthca_ah, ibah); 2991da177e4SLinus Torvalds } 3001da177e4SLinus Torvalds 3011da177e4SLinus Torvalds static inline struct mthca_cq *to_mcq(struct ib_cq *ibcq) 3021da177e4SLinus Torvalds { 3031da177e4SLinus Torvalds return container_of(ibcq, struct mthca_cq, ibcq); 3041da177e4SLinus Torvalds } 3051da177e4SLinus Torvalds 306ec34a922SRoland Dreier static inline struct mthca_srq *to_msrq(struct ib_srq *ibsrq) 307ec34a922SRoland Dreier { 308ec34a922SRoland Dreier return container_of(ibsrq, struct mthca_srq, ibsrq); 309ec34a922SRoland Dreier } 310ec34a922SRoland Dreier 3111da177e4SLinus Torvalds static inline struct mthca_qp *to_mqp(struct ib_qp *ibqp) 3121da177e4SLinus Torvalds { 3131da177e4SLinus Torvalds return container_of(ibqp, struct mthca_qp, ibqp); 3141da177e4SLinus Torvalds } 3151da177e4SLinus Torvalds 3161da177e4SLinus Torvalds #endif /* MTHCA_PROVIDER_H */ 317