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 * $Id: mthca_provider.h 1349 2004-12-16 21:09:43Z roland $ 351da177e4SLinus Torvalds */ 361da177e4SLinus Torvalds 371da177e4SLinus Torvalds #ifndef MTHCA_PROVIDER_H 381da177e4SLinus Torvalds #define MTHCA_PROVIDER_H 391da177e4SLinus Torvalds 40a4d61e84SRoland Dreier #include <rdma/ib_verbs.h> 41a4d61e84SRoland Dreier #include <rdma/ib_pack.h> 421da177e4SLinus Torvalds 431da177e4SLinus Torvalds #define MTHCA_MPT_FLAG_ATOMIC (1 << 14) 441da177e4SLinus Torvalds #define MTHCA_MPT_FLAG_REMOTE_WRITE (1 << 13) 451da177e4SLinus Torvalds #define MTHCA_MPT_FLAG_REMOTE_READ (1 << 12) 461da177e4SLinus Torvalds #define MTHCA_MPT_FLAG_LOCAL_WRITE (1 << 11) 471da177e4SLinus Torvalds #define MTHCA_MPT_FLAG_LOCAL_READ (1 << 10) 481da177e4SLinus Torvalds 491da177e4SLinus Torvalds struct mthca_buf_list { 501da177e4SLinus Torvalds void *buf; 511da177e4SLinus Torvalds DECLARE_PCI_UNMAP_ADDR(mapping) 521da177e4SLinus Torvalds }; 531da177e4SLinus Torvalds 5487b81670SRoland Dreier union mthca_buf { 5587b81670SRoland Dreier struct mthca_buf_list direct; 5687b81670SRoland Dreier struct mthca_buf_list *page_list; 5787b81670SRoland Dreier }; 5887b81670SRoland Dreier 591da177e4SLinus Torvalds struct mthca_uar { 601da177e4SLinus Torvalds unsigned long pfn; 611da177e4SLinus Torvalds int index; 621da177e4SLinus Torvalds }; 631da177e4SLinus Torvalds 645e0b537cSRoland Dreier struct mthca_user_db_table; 655e0b537cSRoland Dreier 665e0b537cSRoland Dreier struct mthca_ucontext { 675e0b537cSRoland Dreier struct ib_ucontext ibucontext; 685e0b537cSRoland Dreier struct mthca_uar uar; 695e0b537cSRoland Dreier struct mthca_user_db_table *db_tab; 705e0b537cSRoland Dreier }; 715e0b537cSRoland Dreier 72d56d6f95SRoland Dreier struct mthca_mtt; 73d56d6f95SRoland Dreier 741da177e4SLinus Torvalds struct mthca_mr { 751da177e4SLinus Torvalds struct ib_mr ibmr; 76d56d6f95SRoland Dreier struct mthca_mtt *mtt; 771da177e4SLinus Torvalds }; 781da177e4SLinus Torvalds 79e0f5fdcaSMichael S. Tsirkin struct mthca_fmr { 80e0f5fdcaSMichael S. Tsirkin struct ib_fmr ibmr; 81e0f5fdcaSMichael S. Tsirkin struct ib_fmr_attr attr; 82d56d6f95SRoland Dreier struct mthca_mtt *mtt; 83e0f5fdcaSMichael S. Tsirkin int maps; 84e0f5fdcaSMichael S. Tsirkin union { 85e0f5fdcaSMichael S. Tsirkin struct { 86e0f5fdcaSMichael S. Tsirkin struct mthca_mpt_entry __iomem *mpt; 87e0f5fdcaSMichael S. Tsirkin u64 __iomem *mtts; 88e0f5fdcaSMichael S. Tsirkin } tavor; 89e0f5fdcaSMichael S. Tsirkin struct { 90e0f5fdcaSMichael S. Tsirkin struct mthca_mpt_entry *mpt; 91e0f5fdcaSMichael S. Tsirkin __be64 *mtts; 92e0f5fdcaSMichael S. Tsirkin } arbel; 93e0f5fdcaSMichael S. Tsirkin } mem; 94e0f5fdcaSMichael S. Tsirkin }; 95e0f5fdcaSMichael S. Tsirkin 961da177e4SLinus Torvalds struct mthca_pd { 971da177e4SLinus Torvalds struct ib_pd ibpd; 981da177e4SLinus Torvalds u32 pd_num; 991da177e4SLinus Torvalds atomic_t sqp_count; 1001da177e4SLinus Torvalds struct mthca_mr ntmr; 10199264c1eSRoland Dreier int privileged; 1021da177e4SLinus Torvalds }; 1031da177e4SLinus Torvalds 1041da177e4SLinus Torvalds struct mthca_eq { 1051da177e4SLinus Torvalds struct mthca_dev *dev; 1061da177e4SLinus Torvalds int eqn; 1071da177e4SLinus Torvalds u32 eqn_mask; 1081da177e4SLinus Torvalds u32 cons_index; 1091da177e4SLinus Torvalds u16 msi_x_vector; 1101da177e4SLinus Torvalds u16 msi_x_entry; 1111da177e4SLinus Torvalds int have_irq; 1121da177e4SLinus Torvalds int nent; 1131da177e4SLinus Torvalds struct mthca_buf_list *page_list; 1141da177e4SLinus Torvalds struct mthca_mr mr; 1151da177e4SLinus Torvalds }; 1161da177e4SLinus Torvalds 1171da177e4SLinus Torvalds struct mthca_av; 1181da177e4SLinus Torvalds 1191da177e4SLinus Torvalds enum mthca_ah_type { 1201da177e4SLinus Torvalds MTHCA_AH_ON_HCA, 1211da177e4SLinus Torvalds MTHCA_AH_PCI_POOL, 1221da177e4SLinus Torvalds MTHCA_AH_KMALLOC 1231da177e4SLinus Torvalds }; 1241da177e4SLinus Torvalds 1251da177e4SLinus Torvalds struct mthca_ah { 1261da177e4SLinus Torvalds struct ib_ah ibah; 1271da177e4SLinus Torvalds enum mthca_ah_type type; 1281da177e4SLinus Torvalds u32 key; 1291da177e4SLinus Torvalds struct mthca_av *av; 1301da177e4SLinus Torvalds dma_addr_t avdma; 1311da177e4SLinus Torvalds }; 1321da177e4SLinus Torvalds 1331da177e4SLinus Torvalds /* 1341da177e4SLinus Torvalds * Quick description of our CQ/QP locking scheme: 1351da177e4SLinus Torvalds * 1361da177e4SLinus Torvalds * We have one global lock that protects dev->cq/qp_table. Each 1371da177e4SLinus Torvalds * struct mthca_cq/qp also has its own lock. An individual qp lock 1381da177e4SLinus Torvalds * may be taken inside of an individual cq lock. Both cqs attached to 1391da177e4SLinus Torvalds * a qp may be locked, with the send cq locked first. No other 1401da177e4SLinus Torvalds * nesting should be done. 1411da177e4SLinus Torvalds * 142a3285aa4SRoland Dreier * Each struct mthca_cq/qp also has an ref count, protected by the 143a3285aa4SRoland Dreier * corresponding table lock. The pointer from the cq/qp_table to the 144a3285aa4SRoland Dreier * struct counts as one reference. This reference also is good for 145a3285aa4SRoland Dreier * access through the consumer API, so modifying the CQ/QP etc doesn't 146a3285aa4SRoland Dreier * need to take another reference. Access to a QP because of a 147a3285aa4SRoland Dreier * completion being polled does not need a reference either. 1481da177e4SLinus Torvalds * 1491da177e4SLinus Torvalds * Finally, each struct mthca_cq/qp has a wait_queue_head_t for the 1501da177e4SLinus Torvalds * destroy function to sleep on. 1511da177e4SLinus Torvalds * 1521da177e4SLinus Torvalds * This means that access from the consumer API requires nothing but 1531da177e4SLinus Torvalds * taking the struct's lock. 1541da177e4SLinus Torvalds * 1551da177e4SLinus Torvalds * Access because of a completion event should go as follows: 1561da177e4SLinus Torvalds * - lock cq/qp_table and look up struct 1571da177e4SLinus Torvalds * - increment ref count in struct 1581da177e4SLinus Torvalds * - drop cq/qp_table lock 1591da177e4SLinus Torvalds * - lock struct, do your thing, and unlock struct 1601da177e4SLinus Torvalds * - decrement ref count; if zero, wake up waiters 1611da177e4SLinus Torvalds * 1621da177e4SLinus Torvalds * To destroy a CQ/QP, we can do the following: 163a3285aa4SRoland Dreier * - lock cq/qp_table 164a3285aa4SRoland Dreier * - remove pointer and decrement ref count 165a3285aa4SRoland Dreier * - unlock cq/qp_table lock 1661da177e4SLinus Torvalds * - wait_event until ref count is zero 1671da177e4SLinus Torvalds * 1681da177e4SLinus Torvalds * It is the consumer's responsibilty to make sure that no QP 1694885bf64SRoland Dreier * operations (WQE posting or state modification) are pending when a 1701da177e4SLinus Torvalds * QP is destroyed. Also, the consumer must make sure that calls to 1714885bf64SRoland Dreier * qp_modify are serialized. Similarly, the consumer is responsible 1724885bf64SRoland Dreier * for ensuring that no CQ resize operations are pending when a CQ 1734885bf64SRoland Dreier * is destroyed. 1741da177e4SLinus Torvalds * 1751da177e4SLinus Torvalds * Possible optimizations (wait for profile data to see if/where we 1761da177e4SLinus Torvalds * have locks bouncing between CPUs): 1771da177e4SLinus Torvalds * - split cq/qp table lock into n separate (cache-aligned) locks, 1781da177e4SLinus Torvalds * indexed (say) by the page in the table 1791da177e4SLinus Torvalds * - split QP struct lock into three (one for common info, one for the 1801da177e4SLinus Torvalds * send queue and one for the receive queue) 1811da177e4SLinus Torvalds */ 1821da177e4SLinus Torvalds 1834885bf64SRoland Dreier struct mthca_cq_buf { 1844885bf64SRoland Dreier union mthca_buf queue; 1854885bf64SRoland Dreier struct mthca_mr mr; 1864885bf64SRoland Dreier int is_direct; 1874885bf64SRoland Dreier }; 1884885bf64SRoland Dreier 1894885bf64SRoland Dreier struct mthca_cq_resize { 1904885bf64SRoland Dreier struct mthca_cq_buf buf; 1914885bf64SRoland Dreier int cqe; 1924885bf64SRoland Dreier enum { 1934885bf64SRoland Dreier CQ_RESIZE_ALLOC, 1944885bf64SRoland Dreier CQ_RESIZE_READY, 1954885bf64SRoland Dreier CQ_RESIZE_SWAPPED 1964885bf64SRoland Dreier } state; 1974885bf64SRoland Dreier }; 1984885bf64SRoland Dreier 1991da177e4SLinus Torvalds struct mthca_cq { 2001da177e4SLinus Torvalds struct ib_cq ibcq; 2011da177e4SLinus Torvalds spinlock_t lock; 202a3285aa4SRoland Dreier int refcount; 2031da177e4SLinus Torvalds int cqn; 2041da177e4SLinus Torvalds u32 cons_index; 2054885bf64SRoland Dreier struct mthca_cq_buf buf; 2064885bf64SRoland Dreier struct mthca_cq_resize *resize_buf; 20774c2174eSRoland Dreier int is_kernel; 2081da177e4SLinus Torvalds 2091da177e4SLinus Torvalds /* Next fields are Arbel only */ 2101da177e4SLinus Torvalds int set_ci_db_index; 21197f52eb4SSean Hefty __be32 *set_ci_db; 2121da177e4SLinus Torvalds int arm_db_index; 21397f52eb4SSean Hefty __be32 *arm_db; 2141da177e4SLinus Torvalds int arm_sn; 2151da177e4SLinus Torvalds 2161da177e4SLinus Torvalds wait_queue_head_t wait; 217*c93b6fbaSRoland Dreier struct mutex mutex; 2181da177e4SLinus Torvalds }; 2191da177e4SLinus Torvalds 220ec34a922SRoland Dreier struct mthca_srq { 221ec34a922SRoland Dreier struct ib_srq ibsrq; 222ec34a922SRoland Dreier spinlock_t lock; 223a3285aa4SRoland Dreier int refcount; 224ec34a922SRoland Dreier int srqn; 225ec34a922SRoland Dreier int max; 226ec34a922SRoland Dreier int max_gs; 227ec34a922SRoland Dreier int wqe_shift; 228ec34a922SRoland Dreier int first_free; 229ec34a922SRoland Dreier int last_free; 230ec34a922SRoland Dreier u16 counter; /* Arbel only */ 231ec34a922SRoland Dreier int db_index; /* Arbel only */ 232ec34a922SRoland Dreier __be32 *db; /* Arbel only */ 233ec34a922SRoland Dreier void *last; 234ec34a922SRoland Dreier 235ec34a922SRoland Dreier int is_direct; 236ec34a922SRoland Dreier u64 *wrid; 237ec34a922SRoland Dreier union mthca_buf queue; 238ec34a922SRoland Dreier struct mthca_mr mr; 239ec34a922SRoland Dreier 240ec34a922SRoland Dreier wait_queue_head_t wait; 241*c93b6fbaSRoland Dreier struct mutex mutex; 242ec34a922SRoland Dreier }; 243ec34a922SRoland Dreier 2441da177e4SLinus Torvalds struct mthca_wq { 2451da177e4SLinus Torvalds spinlock_t lock; 2461da177e4SLinus Torvalds int max; 2471da177e4SLinus Torvalds unsigned next_ind; 2481da177e4SLinus Torvalds unsigned last_comp; 2491da177e4SLinus Torvalds unsigned head; 2501da177e4SLinus Torvalds unsigned tail; 2511da177e4SLinus Torvalds void *last; 2521da177e4SLinus Torvalds int max_gs; 2531da177e4SLinus Torvalds int wqe_shift; 2541da177e4SLinus Torvalds 2551da177e4SLinus Torvalds int db_index; /* Arbel only */ 25697f52eb4SSean Hefty __be32 *db; 2571da177e4SLinus Torvalds }; 2581da177e4SLinus Torvalds 2591da177e4SLinus Torvalds struct mthca_qp { 2601da177e4SLinus Torvalds struct ib_qp ibqp; 261a3285aa4SRoland Dreier int refcount; 2621da177e4SLinus Torvalds u32 qpn; 2631da177e4SLinus Torvalds int is_direct; 264bf6a9e31SJack Morgenstein u8 port; /* for SQP and memfree use only */ 265bf6a9e31SJack Morgenstein u8 alt_port; /* for memfree use only */ 2661da177e4SLinus Torvalds u8 transport; 2671da177e4SLinus Torvalds u8 state; 2681da177e4SLinus Torvalds u8 atomic_rd_en; 2691da177e4SLinus Torvalds u8 resp_depth; 2701da177e4SLinus Torvalds 2711da177e4SLinus Torvalds struct mthca_mr mr; 2721da177e4SLinus Torvalds 2731da177e4SLinus Torvalds struct mthca_wq rq; 2741da177e4SLinus Torvalds struct mthca_wq sq; 2751da177e4SLinus Torvalds enum ib_sig_type sq_policy; 2761da177e4SLinus Torvalds int send_wqe_offset; 27777369ed3SJack Morgenstein int max_inline_data; 2781da177e4SLinus Torvalds 2791da177e4SLinus Torvalds u64 *wrid; 28087b81670SRoland Dreier union mthca_buf queue; 2811da177e4SLinus Torvalds 2821da177e4SLinus Torvalds wait_queue_head_t wait; 283*c93b6fbaSRoland Dreier struct mutex mutex; 2841da177e4SLinus Torvalds }; 2851da177e4SLinus Torvalds 2861da177e4SLinus Torvalds struct mthca_sqp { 2871da177e4SLinus Torvalds struct mthca_qp qp; 2881da177e4SLinus Torvalds int pkey_index; 2891da177e4SLinus Torvalds u32 qkey; 2901da177e4SLinus Torvalds u32 send_psn; 2911da177e4SLinus Torvalds struct ib_ud_header ud_header; 2921da177e4SLinus Torvalds int header_buf_size; 2931da177e4SLinus Torvalds void *header_buf; 2941da177e4SLinus Torvalds dma_addr_t header_dma; 2951da177e4SLinus Torvalds }; 2961da177e4SLinus Torvalds 2975e0b537cSRoland Dreier static inline struct mthca_ucontext *to_mucontext(struct ib_ucontext *ibucontext) 2985e0b537cSRoland Dreier { 2995e0b537cSRoland Dreier return container_of(ibucontext, struct mthca_ucontext, ibucontext); 3005e0b537cSRoland Dreier } 3015e0b537cSRoland Dreier 302e0f5fdcaSMichael S. Tsirkin static inline struct mthca_fmr *to_mfmr(struct ib_fmr *ibmr) 303e0f5fdcaSMichael S. Tsirkin { 304e0f5fdcaSMichael S. Tsirkin return container_of(ibmr, struct mthca_fmr, ibmr); 305e0f5fdcaSMichael S. Tsirkin } 306e0f5fdcaSMichael S. Tsirkin 3071da177e4SLinus Torvalds static inline struct mthca_mr *to_mmr(struct ib_mr *ibmr) 3081da177e4SLinus Torvalds { 3091da177e4SLinus Torvalds return container_of(ibmr, struct mthca_mr, ibmr); 3101da177e4SLinus Torvalds } 3111da177e4SLinus Torvalds 3121da177e4SLinus Torvalds static inline struct mthca_pd *to_mpd(struct ib_pd *ibpd) 3131da177e4SLinus Torvalds { 3141da177e4SLinus Torvalds return container_of(ibpd, struct mthca_pd, ibpd); 3151da177e4SLinus Torvalds } 3161da177e4SLinus Torvalds 3171da177e4SLinus Torvalds static inline struct mthca_ah *to_mah(struct ib_ah *ibah) 3181da177e4SLinus Torvalds { 3191da177e4SLinus Torvalds return container_of(ibah, struct mthca_ah, ibah); 3201da177e4SLinus Torvalds } 3211da177e4SLinus Torvalds 3221da177e4SLinus Torvalds static inline struct mthca_cq *to_mcq(struct ib_cq *ibcq) 3231da177e4SLinus Torvalds { 3241da177e4SLinus Torvalds return container_of(ibcq, struct mthca_cq, ibcq); 3251da177e4SLinus Torvalds } 3261da177e4SLinus Torvalds 327ec34a922SRoland Dreier static inline struct mthca_srq *to_msrq(struct ib_srq *ibsrq) 328ec34a922SRoland Dreier { 329ec34a922SRoland Dreier return container_of(ibsrq, struct mthca_srq, ibsrq); 330ec34a922SRoland Dreier } 331ec34a922SRoland Dreier 3321da177e4SLinus Torvalds static inline struct mthca_qp *to_mqp(struct ib_qp *ibqp) 3331da177e4SLinus Torvalds { 3341da177e4SLinus Torvalds return container_of(ibqp, struct mthca_qp, ibqp); 3351da177e4SLinus Torvalds } 3361da177e4SLinus Torvalds 3371da177e4SLinus Torvalds static inline struct mthca_sqp *to_msqp(struct mthca_qp *qp) 3381da177e4SLinus Torvalds { 3391da177e4SLinus Torvalds return container_of(qp, struct mthca_sqp, qp); 3401da177e4SLinus Torvalds } 3411da177e4SLinus Torvalds 3421da177e4SLinus Torvalds #endif /* MTHCA_PROVIDER_H */ 343