11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * Copyright (c) 2004 Topspin Communications. All rights reserved. 31da177e4SLinus Torvalds * 41da177e4SLinus Torvalds * This software is available to you under a choice of one of two 51da177e4SLinus Torvalds * licenses. You may choose to be licensed under the terms of the GNU 61da177e4SLinus Torvalds * General Public License (GPL) Version 2, available from the file 71da177e4SLinus Torvalds * COPYING in the main directory of this source tree, or the 81da177e4SLinus Torvalds * OpenIB.org BSD license below: 91da177e4SLinus Torvalds * 101da177e4SLinus Torvalds * Redistribution and use in source and binary forms, with or 111da177e4SLinus Torvalds * without modification, are permitted provided that the following 121da177e4SLinus Torvalds * conditions are met: 131da177e4SLinus Torvalds * 141da177e4SLinus Torvalds * - Redistributions of source code must retain the above 151da177e4SLinus Torvalds * copyright notice, this list of conditions and the following 161da177e4SLinus Torvalds * disclaimer. 171da177e4SLinus Torvalds * 181da177e4SLinus Torvalds * - Redistributions in binary form must reproduce the above 191da177e4SLinus Torvalds * copyright notice, this list of conditions and the following 201da177e4SLinus Torvalds * disclaimer in the documentation and/or other materials 211da177e4SLinus Torvalds * provided with the distribution. 221da177e4SLinus Torvalds * 231da177e4SLinus Torvalds * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 241da177e4SLinus Torvalds * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 251da177e4SLinus Torvalds * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 261da177e4SLinus Torvalds * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 271da177e4SLinus Torvalds * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 281da177e4SLinus Torvalds * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 291da177e4SLinus Torvalds * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 301da177e4SLinus Torvalds * SOFTWARE. 311da177e4SLinus Torvalds * 321da177e4SLinus Torvalds * $Id: mthca_provider.h 1349 2004-12-16 21:09:43Z roland $ 331da177e4SLinus Torvalds */ 341da177e4SLinus Torvalds 351da177e4SLinus Torvalds #ifndef MTHCA_PROVIDER_H 361da177e4SLinus Torvalds #define MTHCA_PROVIDER_H 371da177e4SLinus Torvalds 381da177e4SLinus Torvalds #include <ib_verbs.h> 391da177e4SLinus Torvalds #include <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; 491da177e4SLinus Torvalds DECLARE_PCI_UNMAP_ADDR(mapping) 501da177e4SLinus Torvalds }; 511da177e4SLinus Torvalds 521da177e4SLinus Torvalds struct mthca_uar { 531da177e4SLinus Torvalds unsigned long pfn; 541da177e4SLinus Torvalds int index; 551da177e4SLinus Torvalds }; 561da177e4SLinus Torvalds 57*d56d6f95SRoland Dreier struct mthca_mtt; 58*d56d6f95SRoland Dreier 591da177e4SLinus Torvalds struct mthca_mr { 601da177e4SLinus Torvalds struct ib_mr ibmr; 61*d56d6f95SRoland Dreier struct mthca_mtt *mtt; 621da177e4SLinus Torvalds }; 631da177e4SLinus Torvalds 64e0f5fdcaSMichael S. Tsirkin struct mthca_fmr { 65e0f5fdcaSMichael S. Tsirkin struct ib_fmr ibmr; 66e0f5fdcaSMichael S. Tsirkin struct ib_fmr_attr attr; 67*d56d6f95SRoland Dreier struct mthca_mtt *mtt; 68e0f5fdcaSMichael S. Tsirkin int maps; 69e0f5fdcaSMichael S. Tsirkin union { 70e0f5fdcaSMichael S. Tsirkin struct { 71e0f5fdcaSMichael S. Tsirkin struct mthca_mpt_entry __iomem *mpt; 72e0f5fdcaSMichael S. Tsirkin u64 __iomem *mtts; 73e0f5fdcaSMichael S. Tsirkin } tavor; 74e0f5fdcaSMichael S. Tsirkin struct { 75e0f5fdcaSMichael S. Tsirkin struct mthca_mpt_entry *mpt; 76e0f5fdcaSMichael S. Tsirkin __be64 *mtts; 77e0f5fdcaSMichael S. Tsirkin } arbel; 78e0f5fdcaSMichael S. Tsirkin } mem; 79e0f5fdcaSMichael S. Tsirkin }; 80e0f5fdcaSMichael S. Tsirkin 811da177e4SLinus Torvalds struct mthca_pd { 821da177e4SLinus Torvalds struct ib_pd ibpd; 831da177e4SLinus Torvalds u32 pd_num; 841da177e4SLinus Torvalds atomic_t sqp_count; 851da177e4SLinus Torvalds struct mthca_mr ntmr; 861da177e4SLinus Torvalds }; 871da177e4SLinus Torvalds 881da177e4SLinus Torvalds struct mthca_eq { 891da177e4SLinus Torvalds struct mthca_dev *dev; 901da177e4SLinus Torvalds int eqn; 911da177e4SLinus Torvalds u32 eqn_mask; 921da177e4SLinus Torvalds u32 cons_index; 931da177e4SLinus Torvalds u16 msi_x_vector; 941da177e4SLinus Torvalds u16 msi_x_entry; 951da177e4SLinus Torvalds int have_irq; 961da177e4SLinus Torvalds int nent; 971da177e4SLinus Torvalds struct mthca_buf_list *page_list; 981da177e4SLinus Torvalds struct mthca_mr mr; 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 1231da177e4SLinus Torvalds * a qp may be locked, with the send cq locked first. No other 1241da177e4SLinus Torvalds * nesting should be done. 1251da177e4SLinus Torvalds * 1261da177e4SLinus Torvalds * Each struct mthca_cq/qp also has an atomic_t ref count. The 1271da177e4SLinus Torvalds * pointer from the cq/qp_table to the struct counts as one reference. 1281da177e4SLinus Torvalds * This reference also is good for access through the consumer API, so 1291da177e4SLinus Torvalds * modifying the CQ/QP etc doesn't need to take another reference. 1301da177e4SLinus Torvalds * Access because of a completion being polled does need a reference. 1311da177e4SLinus Torvalds * 1321da177e4SLinus Torvalds * Finally, each struct mthca_cq/qp has a wait_queue_head_t for the 1331da177e4SLinus Torvalds * destroy function to sleep on. 1341da177e4SLinus Torvalds * 1351da177e4SLinus Torvalds * This means that access from the consumer API requires nothing but 1361da177e4SLinus Torvalds * taking the struct's lock. 1371da177e4SLinus Torvalds * 1381da177e4SLinus Torvalds * Access because of a completion event should go as follows: 1391da177e4SLinus Torvalds * - lock cq/qp_table and look up struct 1401da177e4SLinus Torvalds * - increment ref count in struct 1411da177e4SLinus Torvalds * - drop cq/qp_table lock 1421da177e4SLinus Torvalds * - lock struct, do your thing, and unlock struct 1431da177e4SLinus Torvalds * - decrement ref count; if zero, wake up waiters 1441da177e4SLinus Torvalds * 1451da177e4SLinus Torvalds * To destroy a CQ/QP, we can do the following: 1461da177e4SLinus Torvalds * - lock cq/qp_table, remove pointer, unlock cq/qp_table lock 1471da177e4SLinus Torvalds * - decrement ref count 1481da177e4SLinus Torvalds * - wait_event until ref count is zero 1491da177e4SLinus Torvalds * 1501da177e4SLinus Torvalds * It is the consumer's responsibilty to make sure that no QP 1511da177e4SLinus Torvalds * operations (WQE posting or state modification) are pending when the 1521da177e4SLinus Torvalds * QP is destroyed. Also, the consumer must make sure that calls to 1531da177e4SLinus Torvalds * qp_modify are serialized. 1541da177e4SLinus Torvalds * 1551da177e4SLinus Torvalds * Possible optimizations (wait for profile data to see if/where we 1561da177e4SLinus Torvalds * have locks bouncing between CPUs): 1571da177e4SLinus Torvalds * - split cq/qp table lock into n separate (cache-aligned) locks, 1581da177e4SLinus Torvalds * indexed (say) by the page in the table 1591da177e4SLinus Torvalds * - split QP struct lock into three (one for common info, one for the 1601da177e4SLinus Torvalds * send queue and one for the receive queue) 1611da177e4SLinus Torvalds */ 1621da177e4SLinus Torvalds 1631da177e4SLinus Torvalds struct mthca_cq { 1641da177e4SLinus Torvalds struct ib_cq ibcq; 1651da177e4SLinus Torvalds spinlock_t lock; 1661da177e4SLinus Torvalds atomic_t refcount; 1671da177e4SLinus Torvalds int cqn; 1681da177e4SLinus Torvalds u32 cons_index; 1691da177e4SLinus Torvalds int is_direct; 1701da177e4SLinus Torvalds 1711da177e4SLinus Torvalds /* Next fields are Arbel only */ 1721da177e4SLinus Torvalds int set_ci_db_index; 1731da177e4SLinus Torvalds u32 *set_ci_db; 1741da177e4SLinus Torvalds int arm_db_index; 1751da177e4SLinus Torvalds u32 *arm_db; 1761da177e4SLinus Torvalds int arm_sn; 1771da177e4SLinus Torvalds 1781da177e4SLinus Torvalds union { 1791da177e4SLinus Torvalds struct mthca_buf_list direct; 1801da177e4SLinus Torvalds struct mthca_buf_list *page_list; 1811da177e4SLinus Torvalds } queue; 1821da177e4SLinus Torvalds struct mthca_mr mr; 1831da177e4SLinus Torvalds wait_queue_head_t wait; 1841da177e4SLinus Torvalds }; 1851da177e4SLinus Torvalds 1861da177e4SLinus Torvalds struct mthca_wq { 1871da177e4SLinus Torvalds spinlock_t lock; 1881da177e4SLinus Torvalds int max; 1891da177e4SLinus Torvalds unsigned next_ind; 1901da177e4SLinus Torvalds unsigned last_comp; 1911da177e4SLinus Torvalds unsigned head; 1921da177e4SLinus Torvalds unsigned tail; 1931da177e4SLinus Torvalds void *last; 1941da177e4SLinus Torvalds int max_gs; 1951da177e4SLinus Torvalds int wqe_shift; 1961da177e4SLinus Torvalds 1971da177e4SLinus Torvalds int db_index; /* Arbel only */ 1981da177e4SLinus Torvalds u32 *db; 1991da177e4SLinus Torvalds }; 2001da177e4SLinus Torvalds 2011da177e4SLinus Torvalds struct mthca_qp { 2021da177e4SLinus Torvalds struct ib_qp ibqp; 2031da177e4SLinus Torvalds atomic_t refcount; 2041da177e4SLinus Torvalds u32 qpn; 2051da177e4SLinus Torvalds int is_direct; 2061da177e4SLinus Torvalds u8 transport; 2071da177e4SLinus Torvalds u8 state; 2081da177e4SLinus Torvalds u8 atomic_rd_en; 2091da177e4SLinus Torvalds u8 resp_depth; 2101da177e4SLinus Torvalds 2111da177e4SLinus Torvalds struct mthca_mr mr; 2121da177e4SLinus Torvalds 2131da177e4SLinus Torvalds struct mthca_wq rq; 2141da177e4SLinus Torvalds struct mthca_wq sq; 2151da177e4SLinus Torvalds enum ib_sig_type sq_policy; 2161da177e4SLinus Torvalds int send_wqe_offset; 2171da177e4SLinus Torvalds 2181da177e4SLinus Torvalds u64 *wrid; 2191da177e4SLinus Torvalds union { 2201da177e4SLinus Torvalds struct mthca_buf_list direct; 2211da177e4SLinus Torvalds struct mthca_buf_list *page_list; 2221da177e4SLinus Torvalds } queue; 2231da177e4SLinus Torvalds 2241da177e4SLinus Torvalds wait_queue_head_t wait; 2251da177e4SLinus Torvalds }; 2261da177e4SLinus Torvalds 2271da177e4SLinus Torvalds struct mthca_sqp { 2281da177e4SLinus Torvalds struct mthca_qp qp; 2291da177e4SLinus Torvalds int port; 2301da177e4SLinus Torvalds int pkey_index; 2311da177e4SLinus Torvalds u32 qkey; 2321da177e4SLinus Torvalds u32 send_psn; 2331da177e4SLinus Torvalds struct ib_ud_header ud_header; 2341da177e4SLinus Torvalds int header_buf_size; 2351da177e4SLinus Torvalds void *header_buf; 2361da177e4SLinus Torvalds dma_addr_t header_dma; 2371da177e4SLinus Torvalds }; 2381da177e4SLinus Torvalds 239e0f5fdcaSMichael S. Tsirkin static inline struct mthca_fmr *to_mfmr(struct ib_fmr *ibmr) 240e0f5fdcaSMichael S. Tsirkin { 241e0f5fdcaSMichael S. Tsirkin return container_of(ibmr, struct mthca_fmr, ibmr); 242e0f5fdcaSMichael S. Tsirkin } 243e0f5fdcaSMichael S. Tsirkin 2441da177e4SLinus Torvalds static inline struct mthca_mr *to_mmr(struct ib_mr *ibmr) 2451da177e4SLinus Torvalds { 2461da177e4SLinus Torvalds return container_of(ibmr, struct mthca_mr, ibmr); 2471da177e4SLinus Torvalds } 2481da177e4SLinus Torvalds 2491da177e4SLinus Torvalds static inline struct mthca_pd *to_mpd(struct ib_pd *ibpd) 2501da177e4SLinus Torvalds { 2511da177e4SLinus Torvalds return container_of(ibpd, struct mthca_pd, ibpd); 2521da177e4SLinus Torvalds } 2531da177e4SLinus Torvalds 2541da177e4SLinus Torvalds static inline struct mthca_ah *to_mah(struct ib_ah *ibah) 2551da177e4SLinus Torvalds { 2561da177e4SLinus Torvalds return container_of(ibah, struct mthca_ah, ibah); 2571da177e4SLinus Torvalds } 2581da177e4SLinus Torvalds 2591da177e4SLinus Torvalds static inline struct mthca_cq *to_mcq(struct ib_cq *ibcq) 2601da177e4SLinus Torvalds { 2611da177e4SLinus Torvalds return container_of(ibcq, struct mthca_cq, ibcq); 2621da177e4SLinus Torvalds } 2631da177e4SLinus Torvalds 2641da177e4SLinus Torvalds static inline struct mthca_qp *to_mqp(struct ib_qp *ibqp) 2651da177e4SLinus Torvalds { 2661da177e4SLinus Torvalds return container_of(ibqp, struct mthca_qp, ibqp); 2671da177e4SLinus Torvalds } 2681da177e4SLinus Torvalds 2691da177e4SLinus Torvalds static inline struct mthca_sqp *to_msqp(struct mthca_qp *qp) 2701da177e4SLinus Torvalds { 2711da177e4SLinus Torvalds return container_of(qp, struct mthca_sqp, qp); 2721da177e4SLinus Torvalds } 2731da177e4SLinus Torvalds 2741da177e4SLinus Torvalds #endif /* MTHCA_PROVIDER_H */ 275