11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * Copyright (c) 2004 Topspin Communications. All rights reserved. 35e0b537cSRoland Dreier * Copyright (c) 2005 Cisco Systems. All rights reserved. 41da177e4SLinus Torvalds * 51da177e4SLinus Torvalds * This software is available to you under a choice of one of two 61da177e4SLinus Torvalds * licenses. You may choose to be licensed under the terms of the GNU 71da177e4SLinus Torvalds * General Public License (GPL) Version 2, available from the file 81da177e4SLinus Torvalds * COPYING in the main directory of this source tree, or the 91da177e4SLinus Torvalds * OpenIB.org BSD license below: 101da177e4SLinus Torvalds * 111da177e4SLinus Torvalds * Redistribution and use in source and binary forms, with or 121da177e4SLinus Torvalds * without modification, are permitted provided that the following 131da177e4SLinus Torvalds * conditions are met: 141da177e4SLinus Torvalds * 151da177e4SLinus Torvalds * - Redistributions of source code must retain the above 161da177e4SLinus Torvalds * copyright notice, this list of conditions and the following 171da177e4SLinus Torvalds * disclaimer. 181da177e4SLinus Torvalds * 191da177e4SLinus Torvalds * - Redistributions in binary form must reproduce the above 201da177e4SLinus Torvalds * copyright notice, this list of conditions and the following 211da177e4SLinus Torvalds * disclaimer in the documentation and/or other materials 221da177e4SLinus Torvalds * provided with the distribution. 231da177e4SLinus Torvalds * 241da177e4SLinus Torvalds * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 251da177e4SLinus Torvalds * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 261da177e4SLinus Torvalds * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 271da177e4SLinus Torvalds * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 281da177e4SLinus Torvalds * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 291da177e4SLinus Torvalds * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 301da177e4SLinus Torvalds * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 311da177e4SLinus Torvalds * SOFTWARE. 321da177e4SLinus Torvalds * 331da177e4SLinus Torvalds * $Id: mthca_provider.h 1349 2004-12-16 21:09:43Z roland $ 341da177e4SLinus Torvalds */ 351da177e4SLinus Torvalds 361da177e4SLinus Torvalds #ifndef MTHCA_PROVIDER_H 371da177e4SLinus Torvalds #define MTHCA_PROVIDER_H 381da177e4SLinus Torvalds 391da177e4SLinus Torvalds #include <ib_verbs.h> 401da177e4SLinus Torvalds #include <ib_pack.h> 411da177e4SLinus Torvalds 421da177e4SLinus Torvalds #define MTHCA_MPT_FLAG_ATOMIC (1 << 14) 431da177e4SLinus Torvalds #define MTHCA_MPT_FLAG_REMOTE_WRITE (1 << 13) 441da177e4SLinus Torvalds #define MTHCA_MPT_FLAG_REMOTE_READ (1 << 12) 451da177e4SLinus Torvalds #define MTHCA_MPT_FLAG_LOCAL_WRITE (1 << 11) 461da177e4SLinus Torvalds #define MTHCA_MPT_FLAG_LOCAL_READ (1 << 10) 471da177e4SLinus Torvalds 481da177e4SLinus Torvalds struct mthca_buf_list { 491da177e4SLinus Torvalds void *buf; 501da177e4SLinus Torvalds DECLARE_PCI_UNMAP_ADDR(mapping) 511da177e4SLinus Torvalds }; 521da177e4SLinus Torvalds 531da177e4SLinus Torvalds struct mthca_uar { 541da177e4SLinus Torvalds unsigned long pfn; 551da177e4SLinus Torvalds int index; 561da177e4SLinus Torvalds }; 571da177e4SLinus Torvalds 585e0b537cSRoland Dreier struct mthca_user_db_table; 595e0b537cSRoland Dreier 605e0b537cSRoland Dreier struct mthca_ucontext { 615e0b537cSRoland Dreier struct ib_ucontext ibucontext; 625e0b537cSRoland Dreier struct mthca_uar uar; 635e0b537cSRoland Dreier struct mthca_user_db_table *db_tab; 645e0b537cSRoland Dreier }; 655e0b537cSRoland Dreier 66d56d6f95SRoland Dreier struct mthca_mtt; 67d56d6f95SRoland Dreier 681da177e4SLinus Torvalds struct mthca_mr { 691da177e4SLinus Torvalds struct ib_mr ibmr; 70d56d6f95SRoland Dreier struct mthca_mtt *mtt; 711da177e4SLinus Torvalds }; 721da177e4SLinus Torvalds 73e0f5fdcaSMichael S. Tsirkin struct mthca_fmr { 74e0f5fdcaSMichael S. Tsirkin struct ib_fmr ibmr; 75e0f5fdcaSMichael S. Tsirkin struct ib_fmr_attr attr; 76d56d6f95SRoland Dreier struct mthca_mtt *mtt; 77e0f5fdcaSMichael S. Tsirkin int maps; 78e0f5fdcaSMichael S. Tsirkin union { 79e0f5fdcaSMichael S. Tsirkin struct { 80e0f5fdcaSMichael S. Tsirkin struct mthca_mpt_entry __iomem *mpt; 81e0f5fdcaSMichael S. Tsirkin u64 __iomem *mtts; 82e0f5fdcaSMichael S. Tsirkin } tavor; 83e0f5fdcaSMichael S. Tsirkin struct { 84e0f5fdcaSMichael S. Tsirkin struct mthca_mpt_entry *mpt; 85e0f5fdcaSMichael S. Tsirkin __be64 *mtts; 86e0f5fdcaSMichael S. Tsirkin } arbel; 87e0f5fdcaSMichael S. Tsirkin } mem; 88e0f5fdcaSMichael S. Tsirkin }; 89e0f5fdcaSMichael S. Tsirkin 901da177e4SLinus Torvalds struct mthca_pd { 911da177e4SLinus Torvalds struct ib_pd ibpd; 921da177e4SLinus Torvalds u32 pd_num; 931da177e4SLinus Torvalds atomic_t sqp_count; 941da177e4SLinus Torvalds struct mthca_mr ntmr; 9599264c1eSRoland Dreier int privileged; 961da177e4SLinus Torvalds }; 971da177e4SLinus Torvalds 981da177e4SLinus Torvalds struct mthca_eq { 991da177e4SLinus Torvalds struct mthca_dev *dev; 1001da177e4SLinus Torvalds int eqn; 1011da177e4SLinus Torvalds u32 eqn_mask; 1021da177e4SLinus Torvalds u32 cons_index; 1031da177e4SLinus Torvalds u16 msi_x_vector; 1041da177e4SLinus Torvalds u16 msi_x_entry; 1051da177e4SLinus Torvalds int have_irq; 1061da177e4SLinus Torvalds int nent; 1071da177e4SLinus Torvalds struct mthca_buf_list *page_list; 1081da177e4SLinus Torvalds struct mthca_mr mr; 1091da177e4SLinus Torvalds }; 1101da177e4SLinus Torvalds 1111da177e4SLinus Torvalds struct mthca_av; 1121da177e4SLinus Torvalds 1131da177e4SLinus Torvalds enum mthca_ah_type { 1141da177e4SLinus Torvalds MTHCA_AH_ON_HCA, 1151da177e4SLinus Torvalds MTHCA_AH_PCI_POOL, 1161da177e4SLinus Torvalds MTHCA_AH_KMALLOC 1171da177e4SLinus Torvalds }; 1181da177e4SLinus Torvalds 1191da177e4SLinus Torvalds struct mthca_ah { 1201da177e4SLinus Torvalds struct ib_ah ibah; 1211da177e4SLinus Torvalds enum mthca_ah_type type; 1221da177e4SLinus Torvalds u32 key; 1231da177e4SLinus Torvalds struct mthca_av *av; 1241da177e4SLinus Torvalds dma_addr_t avdma; 1251da177e4SLinus Torvalds }; 1261da177e4SLinus Torvalds 1271da177e4SLinus Torvalds /* 1281da177e4SLinus Torvalds * Quick description of our CQ/QP locking scheme: 1291da177e4SLinus Torvalds * 1301da177e4SLinus Torvalds * We have one global lock that protects dev->cq/qp_table. Each 1311da177e4SLinus Torvalds * struct mthca_cq/qp also has its own lock. An individual qp lock 1321da177e4SLinus Torvalds * may be taken inside of an individual cq lock. Both cqs attached to 1331da177e4SLinus Torvalds * a qp may be locked, with the send cq locked first. No other 1341da177e4SLinus Torvalds * nesting should be done. 1351da177e4SLinus Torvalds * 1361da177e4SLinus Torvalds * Each struct mthca_cq/qp also has an atomic_t ref count. The 1371da177e4SLinus Torvalds * pointer from the cq/qp_table to the struct counts as one reference. 1381da177e4SLinus Torvalds * This reference also is good for access through the consumer API, so 1391da177e4SLinus Torvalds * modifying the CQ/QP etc doesn't need to take another reference. 1401da177e4SLinus Torvalds * Access because of a completion being polled does need a reference. 1411da177e4SLinus Torvalds * 1421da177e4SLinus Torvalds * Finally, each struct mthca_cq/qp has a wait_queue_head_t for the 1431da177e4SLinus Torvalds * destroy function to sleep on. 1441da177e4SLinus Torvalds * 1451da177e4SLinus Torvalds * This means that access from the consumer API requires nothing but 1461da177e4SLinus Torvalds * taking the struct's lock. 1471da177e4SLinus Torvalds * 1481da177e4SLinus Torvalds * Access because of a completion event should go as follows: 1491da177e4SLinus Torvalds * - lock cq/qp_table and look up struct 1501da177e4SLinus Torvalds * - increment ref count in struct 1511da177e4SLinus Torvalds * - drop cq/qp_table lock 1521da177e4SLinus Torvalds * - lock struct, do your thing, and unlock struct 1531da177e4SLinus Torvalds * - decrement ref count; if zero, wake up waiters 1541da177e4SLinus Torvalds * 1551da177e4SLinus Torvalds * To destroy a CQ/QP, we can do the following: 1561da177e4SLinus Torvalds * - lock cq/qp_table, remove pointer, unlock cq/qp_table lock 1571da177e4SLinus Torvalds * - decrement ref count 1581da177e4SLinus Torvalds * - wait_event until ref count is zero 1591da177e4SLinus Torvalds * 1601da177e4SLinus Torvalds * It is the consumer's responsibilty to make sure that no QP 1611da177e4SLinus Torvalds * operations (WQE posting or state modification) are pending when the 1621da177e4SLinus Torvalds * QP is destroyed. Also, the consumer must make sure that calls to 1631da177e4SLinus Torvalds * qp_modify are serialized. 1641da177e4SLinus Torvalds * 1651da177e4SLinus Torvalds * Possible optimizations (wait for profile data to see if/where we 1661da177e4SLinus Torvalds * have locks bouncing between CPUs): 1671da177e4SLinus Torvalds * - split cq/qp table lock into n separate (cache-aligned) locks, 1681da177e4SLinus Torvalds * indexed (say) by the page in the table 1691da177e4SLinus Torvalds * - split QP struct lock into three (one for common info, one for the 1701da177e4SLinus Torvalds * send queue and one for the receive queue) 1711da177e4SLinus Torvalds */ 1721da177e4SLinus Torvalds 1731da177e4SLinus Torvalds struct mthca_cq { 1741da177e4SLinus Torvalds struct ib_cq ibcq; 1751da177e4SLinus Torvalds spinlock_t lock; 1761da177e4SLinus Torvalds atomic_t refcount; 1771da177e4SLinus Torvalds int cqn; 1781da177e4SLinus Torvalds u32 cons_index; 1791da177e4SLinus Torvalds int is_direct; 180*74c2174eSRoland Dreier int is_kernel; 1811da177e4SLinus Torvalds 1821da177e4SLinus Torvalds /* Next fields are Arbel only */ 1831da177e4SLinus Torvalds int set_ci_db_index; 1841da177e4SLinus Torvalds u32 *set_ci_db; 1851da177e4SLinus Torvalds int arm_db_index; 1861da177e4SLinus Torvalds u32 *arm_db; 1871da177e4SLinus Torvalds int arm_sn; 1881da177e4SLinus Torvalds 1891da177e4SLinus Torvalds union { 1901da177e4SLinus Torvalds struct mthca_buf_list direct; 1911da177e4SLinus Torvalds struct mthca_buf_list *page_list; 1921da177e4SLinus Torvalds } queue; 1931da177e4SLinus Torvalds struct mthca_mr mr; 1941da177e4SLinus Torvalds wait_queue_head_t wait; 1951da177e4SLinus Torvalds }; 1961da177e4SLinus Torvalds 1971da177e4SLinus Torvalds struct mthca_wq { 1981da177e4SLinus Torvalds spinlock_t lock; 1991da177e4SLinus Torvalds int max; 2001da177e4SLinus Torvalds unsigned next_ind; 2011da177e4SLinus Torvalds unsigned last_comp; 2021da177e4SLinus Torvalds unsigned head; 2031da177e4SLinus Torvalds unsigned tail; 2041da177e4SLinus Torvalds void *last; 2051da177e4SLinus Torvalds int max_gs; 2061da177e4SLinus Torvalds int wqe_shift; 2071da177e4SLinus Torvalds 2081da177e4SLinus Torvalds int db_index; /* Arbel only */ 2091da177e4SLinus Torvalds u32 *db; 2101da177e4SLinus Torvalds }; 2111da177e4SLinus Torvalds 2121da177e4SLinus Torvalds struct mthca_qp { 2131da177e4SLinus Torvalds struct ib_qp ibqp; 2141da177e4SLinus Torvalds atomic_t refcount; 2151da177e4SLinus Torvalds u32 qpn; 2161da177e4SLinus Torvalds int is_direct; 2171da177e4SLinus Torvalds u8 transport; 2181da177e4SLinus Torvalds u8 state; 2191da177e4SLinus Torvalds u8 atomic_rd_en; 2201da177e4SLinus Torvalds u8 resp_depth; 2211da177e4SLinus Torvalds 2221da177e4SLinus Torvalds struct mthca_mr mr; 2231da177e4SLinus Torvalds 2241da177e4SLinus Torvalds struct mthca_wq rq; 2251da177e4SLinus Torvalds struct mthca_wq sq; 2261da177e4SLinus Torvalds enum ib_sig_type sq_policy; 2271da177e4SLinus Torvalds int send_wqe_offset; 2281da177e4SLinus Torvalds 2291da177e4SLinus Torvalds u64 *wrid; 2301da177e4SLinus Torvalds union { 2311da177e4SLinus Torvalds struct mthca_buf_list direct; 2321da177e4SLinus Torvalds struct mthca_buf_list *page_list; 2331da177e4SLinus Torvalds } queue; 2341da177e4SLinus Torvalds 2351da177e4SLinus Torvalds wait_queue_head_t wait; 2361da177e4SLinus Torvalds }; 2371da177e4SLinus Torvalds 2381da177e4SLinus Torvalds struct mthca_sqp { 2391da177e4SLinus Torvalds struct mthca_qp qp; 2401da177e4SLinus Torvalds int port; 2411da177e4SLinus Torvalds int pkey_index; 2421da177e4SLinus Torvalds u32 qkey; 2431da177e4SLinus Torvalds u32 send_psn; 2441da177e4SLinus Torvalds struct ib_ud_header ud_header; 2451da177e4SLinus Torvalds int header_buf_size; 2461da177e4SLinus Torvalds void *header_buf; 2471da177e4SLinus Torvalds dma_addr_t header_dma; 2481da177e4SLinus Torvalds }; 2491da177e4SLinus Torvalds 2505e0b537cSRoland Dreier static inline struct mthca_ucontext *to_mucontext(struct ib_ucontext *ibucontext) 2515e0b537cSRoland Dreier { 2525e0b537cSRoland Dreier return container_of(ibucontext, struct mthca_ucontext, ibucontext); 2535e0b537cSRoland Dreier } 2545e0b537cSRoland Dreier 255e0f5fdcaSMichael S. Tsirkin static inline struct mthca_fmr *to_mfmr(struct ib_fmr *ibmr) 256e0f5fdcaSMichael S. Tsirkin { 257e0f5fdcaSMichael S. Tsirkin return container_of(ibmr, struct mthca_fmr, ibmr); 258e0f5fdcaSMichael S. Tsirkin } 259e0f5fdcaSMichael S. Tsirkin 2601da177e4SLinus Torvalds static inline struct mthca_mr *to_mmr(struct ib_mr *ibmr) 2611da177e4SLinus Torvalds { 2621da177e4SLinus Torvalds return container_of(ibmr, struct mthca_mr, ibmr); 2631da177e4SLinus Torvalds } 2641da177e4SLinus Torvalds 2651da177e4SLinus Torvalds static inline struct mthca_pd *to_mpd(struct ib_pd *ibpd) 2661da177e4SLinus Torvalds { 2671da177e4SLinus Torvalds return container_of(ibpd, struct mthca_pd, ibpd); 2681da177e4SLinus Torvalds } 2691da177e4SLinus Torvalds 2701da177e4SLinus Torvalds static inline struct mthca_ah *to_mah(struct ib_ah *ibah) 2711da177e4SLinus Torvalds { 2721da177e4SLinus Torvalds return container_of(ibah, struct mthca_ah, ibah); 2731da177e4SLinus Torvalds } 2741da177e4SLinus Torvalds 2751da177e4SLinus Torvalds static inline struct mthca_cq *to_mcq(struct ib_cq *ibcq) 2761da177e4SLinus Torvalds { 2771da177e4SLinus Torvalds return container_of(ibcq, struct mthca_cq, ibcq); 2781da177e4SLinus Torvalds } 2791da177e4SLinus Torvalds 2801da177e4SLinus Torvalds static inline struct mthca_qp *to_mqp(struct ib_qp *ibqp) 2811da177e4SLinus Torvalds { 2821da177e4SLinus Torvalds return container_of(ibqp, struct mthca_qp, ibqp); 2831da177e4SLinus Torvalds } 2841da177e4SLinus Torvalds 2851da177e4SLinus Torvalds static inline struct mthca_sqp *to_msqp(struct mthca_qp *qp) 2861da177e4SLinus Torvalds { 2871da177e4SLinus Torvalds return container_of(qp, struct mthca_sqp, qp); 2881da177e4SLinus Torvalds } 2891da177e4SLinus Torvalds 2901da177e4SLinus Torvalds #endif /* MTHCA_PROVIDER_H */ 291