1f931551bSRalph Campbell /* 21dd173b0SMike Marciniszyn * Copyright (c) 2012, 2013 Intel Corporation. All rights reserved. 31fb9fed6SMike Marciniszyn * Copyright (c) 2006 - 2012 QLogic Corporation. All rights reserved. 4f931551bSRalph Campbell * Copyright (c) 2005, 2006 PathScale, Inc. All rights reserved. 5f931551bSRalph Campbell * 6f931551bSRalph Campbell * This software is available to you under a choice of one of two 7f931551bSRalph Campbell * licenses. You may choose to be licensed under the terms of the GNU 8f931551bSRalph Campbell * General Public License (GPL) Version 2, available from the file 9f931551bSRalph Campbell * COPYING in the main directory of this source tree, or the 10f931551bSRalph Campbell * OpenIB.org BSD license below: 11f931551bSRalph Campbell * 12f931551bSRalph Campbell * Redistribution and use in source and binary forms, with or 13f931551bSRalph Campbell * without modification, are permitted provided that the following 14f931551bSRalph Campbell * conditions are met: 15f931551bSRalph Campbell * 16f931551bSRalph Campbell * - Redistributions of source code must retain the above 17f931551bSRalph Campbell * copyright notice, this list of conditions and the following 18f931551bSRalph Campbell * disclaimer. 19f931551bSRalph Campbell * 20f931551bSRalph Campbell * - Redistributions in binary form must reproduce the above 21f931551bSRalph Campbell * copyright notice, this list of conditions and the following 22f931551bSRalph Campbell * disclaimer in the documentation and/or other materials 23f931551bSRalph Campbell * provided with the distribution. 24f931551bSRalph Campbell * 25f931551bSRalph Campbell * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 26f931551bSRalph Campbell * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27f931551bSRalph Campbell * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28f931551bSRalph Campbell * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 29f931551bSRalph Campbell * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 30f931551bSRalph Campbell * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 31f931551bSRalph Campbell * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 32f931551bSRalph Campbell * SOFTWARE. 33f931551bSRalph Campbell */ 34f931551bSRalph Campbell 35f931551bSRalph Campbell #ifndef QIB_VERBS_H 36f931551bSRalph Campbell #define QIB_VERBS_H 37f931551bSRalph Campbell 38f931551bSRalph Campbell #include <linux/types.h> 39f931551bSRalph Campbell #include <linux/spinlock.h> 40f931551bSRalph Campbell #include <linux/kernel.h> 41f931551bSRalph Campbell #include <linux/interrupt.h> 42f931551bSRalph Campbell #include <linux/kref.h> 43f931551bSRalph Campbell #include <linux/workqueue.h> 4485caafe3SMike Marciniszyn #include <linux/kthread.h> 456a82649fSMike Marciniszyn #include <linux/completion.h> 46f931551bSRalph Campbell #include <rdma/ib_pack.h> 47f931551bSRalph Campbell #include <rdma/ib_user_verbs.h> 482dc05ab5SDennis Dalessandro #include <rdma/rdma_vt.h> 49f931551bSRalph Campbell 50f931551bSRalph Campbell struct qib_ctxtdata; 51f931551bSRalph Campbell struct qib_pportdata; 52f931551bSRalph Campbell struct qib_devdata; 53f931551bSRalph Campbell struct qib_verbs_txreq; 54f931551bSRalph Campbell 55f931551bSRalph Campbell #define QIB_MAX_RDMA_ATOMIC 16 56f931551bSRalph Campbell #define QIB_GUIDS_PER_PORT 5 57f931551bSRalph Campbell 58f931551bSRalph Campbell /* 59f931551bSRalph Campbell * Increment this value if any changes that break userspace ABI 60f931551bSRalph Campbell * compatibility are made. 61f931551bSRalph Campbell */ 62f931551bSRalph Campbell #define QIB_UVERBS_ABI_VERSION 2 63f931551bSRalph Campbell 64f931551bSRalph Campbell /* 65f931551bSRalph Campbell * Define an ib_cq_notify value that is not valid so we know when CQ 66f931551bSRalph Campbell * notifications are armed. 67f931551bSRalph Campbell */ 68f931551bSRalph Campbell #define IB_CQ_NONE (IB_CQ_NEXT_COMP + 1) 69f931551bSRalph Campbell 70f931551bSRalph Campbell #define IB_SEQ_NAK (3 << 29) 71f931551bSRalph Campbell 72f931551bSRalph Campbell /* AETH NAK opcode values */ 73f931551bSRalph Campbell #define IB_RNR_NAK 0x20 74f931551bSRalph Campbell #define IB_NAK_PSN_ERROR 0x60 75f931551bSRalph Campbell #define IB_NAK_INVALID_REQUEST 0x61 76f931551bSRalph Campbell #define IB_NAK_REMOTE_ACCESS_ERROR 0x62 77f931551bSRalph Campbell #define IB_NAK_REMOTE_OPERATIONAL_ERROR 0x63 78f931551bSRalph Campbell #define IB_NAK_INVALID_RD_REQUEST 0x64 79f931551bSRalph Campbell 80f931551bSRalph Campbell /* Flags for checking QP state (see ib_qib_state_ops[]) */ 81f931551bSRalph Campbell #define QIB_POST_SEND_OK 0x01 82f931551bSRalph Campbell #define QIB_POST_RECV_OK 0x02 83f931551bSRalph Campbell #define QIB_PROCESS_RECV_OK 0x04 84f931551bSRalph Campbell #define QIB_PROCESS_SEND_OK 0x08 85f931551bSRalph Campbell #define QIB_PROCESS_NEXT_SEND_OK 0x10 86f931551bSRalph Campbell #define QIB_FLUSH_SEND 0x20 87f931551bSRalph Campbell #define QIB_FLUSH_RECV 0x40 88f931551bSRalph Campbell #define QIB_PROCESS_OR_FLUSH_SEND \ 89f931551bSRalph Campbell (QIB_PROCESS_SEND_OK | QIB_FLUSH_SEND) 90f931551bSRalph Campbell 91f931551bSRalph Campbell /* IB Performance Manager status values */ 92f931551bSRalph Campbell #define IB_PMA_SAMPLE_STATUS_DONE 0x00 93f931551bSRalph Campbell #define IB_PMA_SAMPLE_STATUS_STARTED 0x01 94f931551bSRalph Campbell #define IB_PMA_SAMPLE_STATUS_RUNNING 0x02 95f931551bSRalph Campbell 96f931551bSRalph Campbell /* Mandatory IB performance counter select values. */ 97f931551bSRalph Campbell #define IB_PMA_PORT_XMIT_DATA cpu_to_be16(0x0001) 98f931551bSRalph Campbell #define IB_PMA_PORT_RCV_DATA cpu_to_be16(0x0002) 99f931551bSRalph Campbell #define IB_PMA_PORT_XMIT_PKTS cpu_to_be16(0x0003) 100f931551bSRalph Campbell #define IB_PMA_PORT_RCV_PKTS cpu_to_be16(0x0004) 101f931551bSRalph Campbell #define IB_PMA_PORT_XMIT_WAIT cpu_to_be16(0x0005) 102f931551bSRalph Campbell 103f931551bSRalph Campbell #define QIB_VENDOR_IPG cpu_to_be16(0xFFA0) 104f931551bSRalph Campbell 105f931551bSRalph Campbell #define IB_BTH_REQ_ACK (1 << 31) 106f931551bSRalph Campbell #define IB_BTH_SOLICITED (1 << 23) 107f931551bSRalph Campbell #define IB_BTH_MIG_REQ (1 << 22) 108f931551bSRalph Campbell 109f931551bSRalph Campbell /* XXX Should be defined in ib_verbs.h enum ib_port_cap_flags */ 110f931551bSRalph Campbell #define IB_PORT_OTHER_LOCAL_CHANGES_SUP (1 << 26) 111f931551bSRalph Campbell 112f931551bSRalph Campbell #define IB_GRH_VERSION 6 113f931551bSRalph Campbell #define IB_GRH_VERSION_MASK 0xF 114f931551bSRalph Campbell #define IB_GRH_VERSION_SHIFT 28 115f931551bSRalph Campbell #define IB_GRH_TCLASS_MASK 0xFF 116f931551bSRalph Campbell #define IB_GRH_TCLASS_SHIFT 20 117f931551bSRalph Campbell #define IB_GRH_FLOW_MASK 0xFFFFF 118f931551bSRalph Campbell #define IB_GRH_FLOW_SHIFT 0 119f931551bSRalph Campbell #define IB_GRH_NEXT_HDR 0x1B 120f931551bSRalph Campbell 121f931551bSRalph Campbell #define IB_DEFAULT_GID_PREFIX cpu_to_be64(0xfe80000000000000ULL) 122f931551bSRalph Campbell 123f931551bSRalph Campbell /* Values for set/get portinfo VLCap OperationalVLs */ 124f931551bSRalph Campbell #define IB_VL_VL0 1 125f931551bSRalph Campbell #define IB_VL_VL0_1 2 126f931551bSRalph Campbell #define IB_VL_VL0_3 3 127f931551bSRalph Campbell #define IB_VL_VL0_7 4 128f931551bSRalph Campbell #define IB_VL_VL0_14 5 129f931551bSRalph Campbell 130f931551bSRalph Campbell static inline int qib_num_vls(int vls) 131f931551bSRalph Campbell { 132f931551bSRalph Campbell switch (vls) { 133f931551bSRalph Campbell default: 134f931551bSRalph Campbell case IB_VL_VL0: 135f931551bSRalph Campbell return 1; 136f931551bSRalph Campbell case IB_VL_VL0_1: 137f931551bSRalph Campbell return 2; 138f931551bSRalph Campbell case IB_VL_VL0_3: 139f931551bSRalph Campbell return 4; 140f931551bSRalph Campbell case IB_VL_VL0_7: 141f931551bSRalph Campbell return 8; 142f931551bSRalph Campbell case IB_VL_VL0_14: 143f931551bSRalph Campbell return 15; 144f931551bSRalph Campbell } 145f931551bSRalph Campbell } 146f931551bSRalph Campbell 147f931551bSRalph Campbell struct ib_reth { 148f931551bSRalph Campbell __be64 vaddr; 149f931551bSRalph Campbell __be32 rkey; 150f931551bSRalph Campbell __be32 length; 15178a58864SMike Marciniszyn } __packed; 152f931551bSRalph Campbell 153f931551bSRalph Campbell struct ib_atomic_eth { 154f931551bSRalph Campbell __be32 vaddr[2]; /* unaligned so access as 2 32-bit words */ 155f931551bSRalph Campbell __be32 rkey; 156f931551bSRalph Campbell __be64 swap_data; 157f931551bSRalph Campbell __be64 compare_data; 15878a58864SMike Marciniszyn } __packed; 159f931551bSRalph Campbell 160f931551bSRalph Campbell struct qib_other_headers { 161f931551bSRalph Campbell __be32 bth[3]; 162f931551bSRalph Campbell union { 163f931551bSRalph Campbell struct { 164f931551bSRalph Campbell __be32 deth[2]; 165f931551bSRalph Campbell __be32 imm_data; 166f931551bSRalph Campbell } ud; 167f931551bSRalph Campbell struct { 168f931551bSRalph Campbell struct ib_reth reth; 169f931551bSRalph Campbell __be32 imm_data; 170f931551bSRalph Campbell } rc; 171f931551bSRalph Campbell struct { 172f931551bSRalph Campbell __be32 aeth; 173f931551bSRalph Campbell __be32 atomic_ack_eth[2]; 174f931551bSRalph Campbell } at; 175f931551bSRalph Campbell __be32 imm_data; 176f931551bSRalph Campbell __be32 aeth; 177f931551bSRalph Campbell struct ib_atomic_eth atomic_eth; 178f931551bSRalph Campbell } u; 17978a58864SMike Marciniszyn } __packed; 180f931551bSRalph Campbell 181f931551bSRalph Campbell /* 182f931551bSRalph Campbell * Note that UD packets with a GRH header are 8+40+12+8 = 68 bytes 183f931551bSRalph Campbell * long (72 w/ imm_data). Only the first 56 bytes of the IB header 184f931551bSRalph Campbell * will be in the eager header buffer. The remaining 12 or 16 bytes 185f931551bSRalph Campbell * are in the data buffer. 186f931551bSRalph Campbell */ 187f931551bSRalph Campbell struct qib_ib_header { 188f931551bSRalph Campbell __be16 lrh[4]; 189f931551bSRalph Campbell union { 190f931551bSRalph Campbell struct { 191f931551bSRalph Campbell struct ib_grh grh; 192f931551bSRalph Campbell struct qib_other_headers oth; 193f931551bSRalph Campbell } l; 194f931551bSRalph Campbell struct qib_other_headers oth; 195f931551bSRalph Campbell } u; 19678a58864SMike Marciniszyn } __packed; 197f931551bSRalph Campbell 198f931551bSRalph Campbell struct qib_pio_header { 199f931551bSRalph Campbell __le32 pbc[2]; 200f931551bSRalph Campbell struct qib_ib_header hdr; 20178a58864SMike Marciniszyn } __packed; 202f931551bSRalph Campbell 203f931551bSRalph Campbell /* 204f931551bSRalph Campbell * There is one struct qib_mcast for each multicast GID. 205f931551bSRalph Campbell * All attached QPs are then stored as a list of 206f931551bSRalph Campbell * struct qib_mcast_qp. 207f931551bSRalph Campbell */ 208f931551bSRalph Campbell struct qib_mcast_qp { 209f931551bSRalph Campbell struct list_head list; 2107c2e11feSDennis Dalessandro struct rvt_qp *qp; 211f931551bSRalph Campbell }; 212f931551bSRalph Campbell 213f931551bSRalph Campbell struct qib_mcast { 214f931551bSRalph Campbell struct rb_node rb_node; 215f931551bSRalph Campbell union ib_gid mgid; 216f931551bSRalph Campbell struct list_head qp_list; 217f931551bSRalph Campbell wait_queue_head_t wait; 218f931551bSRalph Campbell atomic_t refcount; 219f931551bSRalph Campbell int n_attached; 220f931551bSRalph Campbell }; 221f931551bSRalph Campbell 222f931551bSRalph Campbell /* 223f931551bSRalph Campbell * This structure is used to contain the head pointer, tail pointer, 224f931551bSRalph Campbell * and completion queue entries as a single memory allocation so 225f931551bSRalph Campbell * it can be mmap'ed into user space. 226f931551bSRalph Campbell */ 227f931551bSRalph Campbell struct qib_cq_wc { 228f931551bSRalph Campbell u32 head; /* index of next entry to fill */ 229f931551bSRalph Campbell u32 tail; /* index of next ib_poll_cq() entry */ 230f931551bSRalph Campbell union { 231f931551bSRalph Campbell /* these are actually size ibcq.cqe + 1 */ 232f931551bSRalph Campbell struct ib_uverbs_wc uqueue[0]; 233f931551bSRalph Campbell struct ib_wc kqueue[0]; 234f931551bSRalph Campbell }; 235f931551bSRalph Campbell }; 236f931551bSRalph Campbell 237f931551bSRalph Campbell /* 238f931551bSRalph Campbell * The completion queue structure. 239f931551bSRalph Campbell */ 240f931551bSRalph Campbell struct qib_cq { 241f931551bSRalph Campbell struct ib_cq ibcq; 24285caafe3SMike Marciniszyn struct kthread_work comptask; 24385caafe3SMike Marciniszyn struct qib_devdata *dd; 244f931551bSRalph Campbell spinlock_t lock; /* protect changes in this struct */ 245f931551bSRalph Campbell u8 notify; 246f931551bSRalph Campbell u8 triggered; 247f931551bSRalph Campbell struct qib_cq_wc *queue; 2487c2e11feSDennis Dalessandro struct rvt_mmap_info *ip; 249f931551bSRalph Campbell }; 250f931551bSRalph Campbell 251f931551bSRalph Campbell /* 252ffc26907SDennis Dalessandro * qib specific data structure that will be hidden from rvt after the queue pair 253ffc26907SDennis Dalessandro * is made common. 254ffc26907SDennis Dalessandro */ 255ffc26907SDennis Dalessandro struct qib_qp_priv { 256ffc26907SDennis Dalessandro struct qib_ib_header *s_hdr; /* next packet header to send */ 257ffc26907SDennis Dalessandro struct list_head iowait; /* link for wait PIO buf */ 258ffc26907SDennis Dalessandro atomic_t s_dma_busy; 259ffc26907SDennis Dalessandro struct qib_verbs_txreq *s_tx; 260ffc26907SDennis Dalessandro struct work_struct s_work; 261ffc26907SDennis Dalessandro wait_queue_head_t wait_dma; 2627c2e11feSDennis Dalessandro struct rvt_qp *owner; 263f931551bSRalph Campbell }; 264f931551bSRalph Campbell 265f931551bSRalph Campbell #define QIB_PSN_CREDIT 16 266f931551bSRalph Campbell 267f931551bSRalph Campbell /* 2687c2e11feSDennis Dalessandro * Since struct rvt_swqe is not a fixed size, we can't simply index into 2697c2e11feSDennis Dalessandro * struct rvt_qp.s_wq. This function does the array index computation. 270f931551bSRalph Campbell */ 2717c2e11feSDennis Dalessandro static inline struct rvt_swqe *get_swqe_ptr(struct rvt_qp *qp, 272f931551bSRalph Campbell unsigned n) 273f931551bSRalph Campbell { 2747c2e11feSDennis Dalessandro return (struct rvt_swqe *)((char *)qp->s_wq + 2757c2e11feSDennis Dalessandro (sizeof(struct rvt_swqe) + 276f931551bSRalph Campbell qp->s_max_sge * 2777c2e11feSDennis Dalessandro sizeof(struct rvt_sge)) * n); 278f931551bSRalph Campbell } 279f931551bSRalph Campbell 280f931551bSRalph Campbell /* 2817c2e11feSDennis Dalessandro * Since struct rvt_rwqe is not a fixed size, we can't simply index into 2827c2e11feSDennis Dalessandro * struct rvt_rwq.wq. This function does the array index computation. 283f931551bSRalph Campbell */ 2847c2e11feSDennis Dalessandro static inline struct rvt_rwqe *get_rwqe_ptr(struct rvt_rq *rq, unsigned n) 285f931551bSRalph Campbell { 2867c2e11feSDennis Dalessandro return (struct rvt_rwqe *) 287f931551bSRalph Campbell ((char *) rq->wq->wq + 2887c2e11feSDennis Dalessandro (sizeof(struct rvt_rwqe) + 289f931551bSRalph Campbell rq->max_sge * sizeof(struct ib_sge)) * n); 290f931551bSRalph Campbell } 291f931551bSRalph Campbell 292f931551bSRalph Campbell struct qib_opcode_stats { 293f931551bSRalph Campbell u64 n_packets; /* number of packets */ 294f931551bSRalph Campbell u64 n_bytes; /* total number of bytes */ 295f931551bSRalph Campbell }; 296f931551bSRalph Campbell 297ddb88765SMike Marciniszyn struct qib_opcode_stats_perctx { 298ddb88765SMike Marciniszyn struct qib_opcode_stats stats[128]; 299ddb88765SMike Marciniszyn }; 300ddb88765SMike Marciniszyn 3017d7632adSMike Marciniszyn struct qib_pma_counters { 3027d7632adSMike Marciniszyn u64 n_unicast_xmit; /* total unicast packets sent */ 3037d7632adSMike Marciniszyn u64 n_unicast_rcv; /* total unicast packets received */ 3047d7632adSMike Marciniszyn u64 n_multicast_xmit; /* total multicast packets sent */ 3057d7632adSMike Marciniszyn u64 n_multicast_rcv; /* total multicast packets received */ 3067d7632adSMike Marciniszyn }; 3077d7632adSMike Marciniszyn 308f931551bSRalph Campbell struct qib_ibport { 309f24a6d48SHarish Chegondi struct rvt_ibport rvp; 31096ab1ac1SDennis Dalessandro struct rvt_ah *sm_ah; 31196ab1ac1SDennis Dalessandro struct rvt_ah *smi_ah; 312f931551bSRalph Campbell __be64 guids[QIB_GUIDS_PER_PORT - 1]; /* writable GUIDs */ 3137d7632adSMike Marciniszyn struct qib_pma_counters __percpu *pmastats; 3147d7632adSMike Marciniszyn u64 z_unicast_xmit; /* starting count for PMA */ 3157d7632adSMike Marciniszyn u64 z_unicast_rcv; /* starting count for PMA */ 3167d7632adSMike Marciniszyn u64 z_multicast_xmit; /* starting count for PMA */ 3177d7632adSMike Marciniszyn u64 z_multicast_rcv; /* starting count for PMA */ 318f931551bSRalph Campbell u64 z_symbol_error_counter; /* starting count for PMA */ 319f931551bSRalph Campbell u64 z_link_error_recovery_counter; /* starting count for PMA */ 320f931551bSRalph Campbell u64 z_link_downed_counter; /* starting count for PMA */ 321f931551bSRalph Campbell u64 z_port_rcv_errors; /* starting count for PMA */ 322f931551bSRalph Campbell u64 z_port_rcv_remphys_errors; /* starting count for PMA */ 323f931551bSRalph Campbell u64 z_port_xmit_discards; /* starting count for PMA */ 324f931551bSRalph Campbell u64 z_port_xmit_data; /* starting count for PMA */ 325f931551bSRalph Campbell u64 z_port_rcv_data; /* starting count for PMA */ 326f931551bSRalph Campbell u64 z_port_xmit_packets; /* starting count for PMA */ 327f931551bSRalph Campbell u64 z_port_rcv_packets; /* starting count for PMA */ 328f931551bSRalph Campbell u32 z_local_link_integrity_errors; /* starting count for PMA */ 329f931551bSRalph Campbell u32 z_excessive_buffer_overrun_errors; /* starting count for PMA */ 330f931551bSRalph Campbell u32 z_vl15_dropped; /* starting count for PMA */ 331f931551bSRalph Campbell u8 sl_to_vl[16]; 332f931551bSRalph Campbell }; 333f931551bSRalph Campbell 334f931551bSRalph Campbell struct qib_ibdev { 3352dc05ab5SDennis Dalessandro struct rvt_dev_info rdi; 336f931551bSRalph Campbell 337f931551bSRalph Campbell struct list_head piowait; /* list for wait PIO buf */ 338f931551bSRalph Campbell struct list_head dmawait; /* list for wait DMA */ 339f931551bSRalph Campbell struct list_head txwait; /* list for wait qib_verbs_txreq */ 340f931551bSRalph Campbell struct list_head memwait; /* list for wait kernel memory */ 341f931551bSRalph Campbell struct list_head txreq_free; 342f931551bSRalph Campbell struct timer_list mem_timer; 343f931551bSRalph Campbell struct qib_pio_header *pio_hdrs; 344f931551bSRalph Campbell dma_addr_t pio_hdrs_phys; 345af061a64SMike Marciniszyn u32 qp_rnd; /* random bytes for hash */ 346f931551bSRalph Campbell 347f931551bSRalph Campbell u32 n_piowait; 348f931551bSRalph Campbell u32 n_txwait; 349f931551bSRalph Campbell 350f931551bSRalph Campbell u32 n_cqs_allocated; /* number of CQs allocated for device */ 351f931551bSRalph Campbell spinlock_t n_cqs_lock; 352f931551bSRalph Campbell u32 n_qps_allocated; /* number of QPs allocated for device */ 353f931551bSRalph Campbell spinlock_t n_qps_lock; 354f931551bSRalph Campbell u32 n_srqs_allocated; /* number of SRQs allocated for device */ 355f931551bSRalph Campbell spinlock_t n_srqs_lock; 356f931551bSRalph Campbell u32 n_mcast_grps_allocated; /* number of mcast groups allocated */ 357f931551bSRalph Campbell spinlock_t n_mcast_grps_lock; 358ddb88765SMike Marciniszyn #ifdef CONFIG_DEBUG_FS 359ddb88765SMike Marciniszyn /* per HCA debugfs */ 360ddb88765SMike Marciniszyn struct dentry *qib_ibdev_dbg; 361ddb88765SMike Marciniszyn #endif 362f931551bSRalph Campbell }; 363f931551bSRalph Campbell 364f931551bSRalph Campbell struct qib_verbs_counters { 365f931551bSRalph Campbell u64 symbol_error_counter; 366f931551bSRalph Campbell u64 link_error_recovery_counter; 367f931551bSRalph Campbell u64 link_downed_counter; 368f931551bSRalph Campbell u64 port_rcv_errors; 369f931551bSRalph Campbell u64 port_rcv_remphys_errors; 370f931551bSRalph Campbell u64 port_xmit_discards; 371f931551bSRalph Campbell u64 port_xmit_data; 372f931551bSRalph Campbell u64 port_rcv_data; 373f931551bSRalph Campbell u64 port_xmit_packets; 374f931551bSRalph Campbell u64 port_rcv_packets; 375f931551bSRalph Campbell u32 local_link_integrity_errors; 376f931551bSRalph Campbell u32 excessive_buffer_overrun_errors; 377f931551bSRalph Campbell u32 vl15_dropped; 378f931551bSRalph Campbell }; 379f931551bSRalph Campbell 380f931551bSRalph Campbell static inline struct qib_cq *to_icq(struct ib_cq *ibcq) 381f931551bSRalph Campbell { 382f931551bSRalph Campbell return container_of(ibcq, struct qib_cq, ibcq); 383f931551bSRalph Campbell } 384f931551bSRalph Campbell 3857c2e11feSDennis Dalessandro static inline struct rvt_qp *to_iqp(struct ib_qp *ibqp) 386f931551bSRalph Campbell { 3877c2e11feSDennis Dalessandro return container_of(ibqp, struct rvt_qp, ibqp); 388f931551bSRalph Campbell } 389f931551bSRalph Campbell 390f931551bSRalph Campbell static inline struct qib_ibdev *to_idev(struct ib_device *ibdev) 391f931551bSRalph Campbell { 3922dc05ab5SDennis Dalessandro struct rvt_dev_info *rdi; 3932dc05ab5SDennis Dalessandro 3942dc05ab5SDennis Dalessandro rdi = container_of(ibdev, struct rvt_dev_info, ibdev); 3952dc05ab5SDennis Dalessandro return container_of(rdi, struct qib_ibdev, rdi); 396f931551bSRalph Campbell } 397f931551bSRalph Campbell 398f931551bSRalph Campbell /* 399f931551bSRalph Campbell * Send if not busy or waiting for I/O and either 400f931551bSRalph Campbell * a RC response is pending or we can process send work requests. 401f931551bSRalph Campbell */ 4027c2e11feSDennis Dalessandro static inline int qib_send_ok(struct rvt_qp *qp) 403f931551bSRalph Campbell { 40401ba79d4SHarish Chegondi return !(qp->s_flags & (RVT_S_BUSY | RVT_S_ANY_WAIT_IO)) && 40501ba79d4SHarish Chegondi (qp->s_hdrwords || (qp->s_flags & RVT_S_RESP_PENDING) || 40601ba79d4SHarish Chegondi !(qp->s_flags & RVT_S_ANY_WAIT_SEND)); 407f931551bSRalph Campbell } 408f931551bSRalph Campbell 409f931551bSRalph Campbell /* 410f931551bSRalph Campbell * This must be called with s_lock held. 411f931551bSRalph Campbell */ 4127c2e11feSDennis Dalessandro void qib_schedule_send(struct rvt_qp *qp); 413f931551bSRalph Campbell 414f931551bSRalph Campbell static inline int qib_pkey_ok(u16 pkey1, u16 pkey2) 415f931551bSRalph Campbell { 416f931551bSRalph Campbell u16 p1 = pkey1 & 0x7FFF; 417f931551bSRalph Campbell u16 p2 = pkey2 & 0x7FFF; 418f931551bSRalph Campbell 419f931551bSRalph Campbell /* 420f931551bSRalph Campbell * Low 15 bits must be non-zero and match, and 421f931551bSRalph Campbell * one of the two must be a full member. 422f931551bSRalph Campbell */ 423f931551bSRalph Campbell return p1 && p1 == p2 && ((__s16)pkey1 < 0 || (__s16)pkey2 < 0); 424f931551bSRalph Campbell } 425f931551bSRalph Campbell 426f931551bSRalph Campbell void qib_bad_pqkey(struct qib_ibport *ibp, __be16 trap_num, u32 key, u32 sl, 427f931551bSRalph Campbell u32 qp1, u32 qp2, __be16 lid1, __be16 lid2); 428f931551bSRalph Campbell void qib_cap_mask_chg(struct qib_ibport *ibp); 429f931551bSRalph Campbell void qib_sys_guid_chg(struct qib_ibport *ibp); 430f931551bSRalph Campbell void qib_node_desc_chg(struct qib_ibport *ibp); 431f931551bSRalph Campbell int qib_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num, 432a97e2d86SIra Weiny const struct ib_wc *in_wc, const struct ib_grh *in_grh, 4334cd7c947SIra Weiny const struct ib_mad_hdr *in, size_t in_mad_size, 4344cd7c947SIra Weiny struct ib_mad_hdr *out, size_t *out_mad_size, 4354cd7c947SIra Weiny u16 *out_mad_pkey_index); 436f931551bSRalph Campbell int qib_create_agents(struct qib_ibdev *dev); 437f931551bSRalph Campbell void qib_free_agents(struct qib_ibdev *dev); 438f931551bSRalph Campbell 439f931551bSRalph Campbell /* 440f931551bSRalph Campbell * Compare the lower 24 bits of the two values. 441f931551bSRalph Campbell * Returns an integer <, ==, or > than zero. 442f931551bSRalph Campbell */ 443f931551bSRalph Campbell static inline int qib_cmp24(u32 a, u32 b) 444f931551bSRalph Campbell { 445f931551bSRalph Campbell return (((int) a) - ((int) b)) << 8; 446f931551bSRalph Campbell } 447f931551bSRalph Campbell 448f931551bSRalph Campbell struct qib_mcast *qib_mcast_find(struct qib_ibport *ibp, union ib_gid *mgid); 449f931551bSRalph Campbell 450f931551bSRalph Campbell int qib_snapshot_counters(struct qib_pportdata *ppd, u64 *swords, 451f931551bSRalph Campbell u64 *rwords, u64 *spkts, u64 *rpkts, 452f931551bSRalph Campbell u64 *xmit_wait); 453f931551bSRalph Campbell 454f931551bSRalph Campbell int qib_get_counters(struct qib_pportdata *ppd, 455f931551bSRalph Campbell struct qib_verbs_counters *cntrs); 456f931551bSRalph Campbell 457f931551bSRalph Campbell int qib_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid); 458f931551bSRalph Campbell 459f931551bSRalph Campbell int qib_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid); 460f931551bSRalph Campbell 461f931551bSRalph Campbell int qib_mcast_tree_empty(struct qib_ibport *ibp); 462f931551bSRalph Campbell 4637c2e11feSDennis Dalessandro __be32 qib_compute_aeth(struct rvt_qp *qp); 464f931551bSRalph Campbell 4657c2e11feSDennis Dalessandro struct rvt_qp *qib_lookup_qpn(struct qib_ibport *ibp, u32 qpn); 466f931551bSRalph Campbell 467f931551bSRalph Campbell struct ib_qp *qib_create_qp(struct ib_pd *ibpd, 468f931551bSRalph Campbell struct ib_qp_init_attr *init_attr, 469f931551bSRalph Campbell struct ib_udata *udata); 470f931551bSRalph Campbell 471f931551bSRalph Campbell int qib_destroy_qp(struct ib_qp *ibqp); 472f931551bSRalph Campbell 4737c2e11feSDennis Dalessandro int qib_error_qp(struct rvt_qp *qp, enum ib_wc_status err); 474f931551bSRalph Campbell 475f931551bSRalph Campbell int qib_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, 476f931551bSRalph Campbell int attr_mask, struct ib_udata *udata); 477f931551bSRalph Campbell 478f931551bSRalph Campbell int qib_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, 479f931551bSRalph Campbell int attr_mask, struct ib_qp_init_attr *init_attr); 480f931551bSRalph Campbell 481f931551bSRalph Campbell unsigned qib_free_all_qps(struct qib_devdata *dd); 482f931551bSRalph Campbell 483898fa52bSHarish Chegondi void qib_init_qpn_table(struct qib_devdata *dd, struct rvt_qpn_table *qpt); 484f931551bSRalph Campbell 485898fa52bSHarish Chegondi void qib_free_qpn_table(struct rvt_qpn_table *qpt); 486f931551bSRalph Campbell 4871dd173b0SMike Marciniszyn #ifdef CONFIG_DEBUG_FS 4881dd173b0SMike Marciniszyn 4891dd173b0SMike Marciniszyn struct qib_qp_iter; 4901dd173b0SMike Marciniszyn 4911dd173b0SMike Marciniszyn struct qib_qp_iter *qib_qp_iter_init(struct qib_ibdev *dev); 4921dd173b0SMike Marciniszyn 4931dd173b0SMike Marciniszyn int qib_qp_iter_next(struct qib_qp_iter *iter); 4941dd173b0SMike Marciniszyn 4951dd173b0SMike Marciniszyn void qib_qp_iter_print(struct seq_file *s, struct qib_qp_iter *iter); 4961dd173b0SMike Marciniszyn 4971dd173b0SMike Marciniszyn #endif 4981dd173b0SMike Marciniszyn 4997c2e11feSDennis Dalessandro void qib_get_credit(struct rvt_qp *qp, u32 aeth); 500f931551bSRalph Campbell 501f931551bSRalph Campbell unsigned qib_pkt_delay(u32 plen, u8 snd_mult, u8 rcv_mult); 502f931551bSRalph Campbell 503f931551bSRalph Campbell void qib_verbs_sdma_desc_avail(struct qib_pportdata *ppd, unsigned avail); 504f931551bSRalph Campbell 505f931551bSRalph Campbell void qib_put_txreq(struct qib_verbs_txreq *tx); 506f931551bSRalph Campbell 5077c2e11feSDennis Dalessandro int qib_verbs_send(struct rvt_qp *qp, struct qib_ib_header *hdr, 5087c2e11feSDennis Dalessandro u32 hdrwords, struct rvt_sge_state *ss, u32 len); 509f931551bSRalph Campbell 5107c2e11feSDennis Dalessandro void qib_copy_sge(struct rvt_sge_state *ss, void *data, u32 length, 511f931551bSRalph Campbell int release); 512f931551bSRalph Campbell 5137c2e11feSDennis Dalessandro void qib_skip_sge(struct rvt_sge_state *ss, u32 length, int release); 514f931551bSRalph Campbell 515f931551bSRalph Campbell void qib_uc_rcv(struct qib_ibport *ibp, struct qib_ib_header *hdr, 5167c2e11feSDennis Dalessandro int has_grh, void *data, u32 tlen, struct rvt_qp *qp); 517f931551bSRalph Campbell 518f931551bSRalph Campbell void qib_rc_rcv(struct qib_ctxtdata *rcd, struct qib_ib_header *hdr, 5197c2e11feSDennis Dalessandro int has_grh, void *data, u32 tlen, struct rvt_qp *qp); 520f931551bSRalph Campbell 521f931551bSRalph Campbell int qib_check_ah(struct ib_device *ibdev, struct ib_ah_attr *ah_attr); 522f931551bSRalph Campbell 5231fb9fed6SMike Marciniszyn struct ib_ah *qib_create_qp0_ah(struct qib_ibport *ibp, u16 dlid); 5241fb9fed6SMike Marciniszyn 525f931551bSRalph Campbell void qib_rc_rnr_retry(unsigned long arg); 526f931551bSRalph Campbell 5277c2e11feSDennis Dalessandro void qib_rc_send_complete(struct rvt_qp *qp, struct qib_ib_header *hdr); 528f931551bSRalph Campbell 5297c2e11feSDennis Dalessandro void qib_rc_error(struct rvt_qp *qp, enum ib_wc_status err); 530f931551bSRalph Campbell 5317c2e11feSDennis Dalessandro int qib_post_ud_send(struct rvt_qp *qp, struct ib_send_wr *wr); 532f931551bSRalph Campbell 533f931551bSRalph Campbell void qib_ud_rcv(struct qib_ibport *ibp, struct qib_ib_header *hdr, 5347c2e11feSDennis Dalessandro int has_grh, void *data, u32 tlen, struct rvt_qp *qp); 535f931551bSRalph Campbell 536f931551bSRalph Campbell int qib_post_srq_receive(struct ib_srq *ibsrq, struct ib_recv_wr *wr, 537f931551bSRalph Campbell struct ib_recv_wr **bad_wr); 538f931551bSRalph Campbell 539f931551bSRalph Campbell struct ib_srq *qib_create_srq(struct ib_pd *ibpd, 540f931551bSRalph Campbell struct ib_srq_init_attr *srq_init_attr, 541f931551bSRalph Campbell struct ib_udata *udata); 542f931551bSRalph Campbell 543f931551bSRalph Campbell int qib_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr, 544f931551bSRalph Campbell enum ib_srq_attr_mask attr_mask, 545f931551bSRalph Campbell struct ib_udata *udata); 546f931551bSRalph Campbell 547f931551bSRalph Campbell int qib_query_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr); 548f931551bSRalph Campbell 549f931551bSRalph Campbell int qib_destroy_srq(struct ib_srq *ibsrq); 550f931551bSRalph Campbell 55185caafe3SMike Marciniszyn int qib_cq_init(struct qib_devdata *dd); 55285caafe3SMike Marciniszyn 55385caafe3SMike Marciniszyn void qib_cq_exit(struct qib_devdata *dd); 55485caafe3SMike Marciniszyn 555f931551bSRalph Campbell void qib_cq_enter(struct qib_cq *cq, struct ib_wc *entry, int sig); 556f931551bSRalph Campbell 557f931551bSRalph Campbell int qib_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *entry); 558f931551bSRalph Campbell 559bcf4c1eaSMatan Barak struct ib_cq *qib_create_cq(struct ib_device *ibdev, 560bcf4c1eaSMatan Barak const struct ib_cq_init_attr *attr, 561bcf4c1eaSMatan Barak struct ib_ucontext *context, 562f931551bSRalph Campbell struct ib_udata *udata); 563f931551bSRalph Campbell 564f931551bSRalph Campbell int qib_destroy_cq(struct ib_cq *ibcq); 565f931551bSRalph Campbell 566f931551bSRalph Campbell int qib_req_notify_cq(struct ib_cq *ibcq, enum ib_cq_notify_flags notify_flags); 567f931551bSRalph Campbell 568f931551bSRalph Campbell int qib_resize_cq(struct ib_cq *ibcq, int cqe, struct ib_udata *udata); 569f931551bSRalph Campbell 5708aac4cc3SMike Marciniszyn void mr_rcu_callback(struct rcu_head *list); 5718aac4cc3SMike Marciniszyn 5727c2e11feSDennis Dalessandro static inline void qib_put_ss(struct rvt_sge_state *ss) 5736a82649fSMike Marciniszyn { 5746a82649fSMike Marciniszyn while (ss->num_sge) { 5757c2e11feSDennis Dalessandro rvt_put_mr(ss->sge.mr); 5766a82649fSMike Marciniszyn if (--ss->num_sge) 5776a82649fSMike Marciniszyn ss->sge = *ss->sg_list++; 5786a82649fSMike Marciniszyn } 5796a82649fSMike Marciniszyn } 5806a82649fSMike Marciniszyn 5817c2e11feSDennis Dalessandro int qib_get_rwqe(struct rvt_qp *qp, int wr_id_only); 582f931551bSRalph Campbell 5837c2e11feSDennis Dalessandro void qib_migrate_qp(struct rvt_qp *qp); 584f931551bSRalph Campbell 585f931551bSRalph Campbell int qib_ruc_check_hdr(struct qib_ibport *ibp, struct qib_ib_header *hdr, 5867c2e11feSDennis Dalessandro int has_grh, struct rvt_qp *qp, u32 bth0); 587f931551bSRalph Campbell 588f931551bSRalph Campbell u32 qib_make_grh(struct qib_ibport *ibp, struct ib_grh *hdr, 589f931551bSRalph Campbell struct ib_global_route *grh, u32 hwords, u32 nwords); 590f931551bSRalph Campbell 5917c2e11feSDennis Dalessandro void qib_make_ruc_header(struct rvt_qp *qp, struct qib_other_headers *ohdr, 592f931551bSRalph Campbell u32 bth0, u32 bth2); 593f931551bSRalph Campbell 594f931551bSRalph Campbell void qib_do_send(struct work_struct *work); 595f931551bSRalph Campbell 5967c2e11feSDennis Dalessandro void qib_send_complete(struct rvt_qp *qp, struct rvt_swqe *wqe, 597f931551bSRalph Campbell enum ib_wc_status status); 598f931551bSRalph Campbell 5997c2e11feSDennis Dalessandro void qib_send_rc_ack(struct rvt_qp *qp); 600f931551bSRalph Campbell 6017c2e11feSDennis Dalessandro int qib_make_rc_req(struct rvt_qp *qp); 602f931551bSRalph Campbell 6037c2e11feSDennis Dalessandro int qib_make_uc_req(struct rvt_qp *qp); 604f931551bSRalph Campbell 6057c2e11feSDennis Dalessandro int qib_make_ud_req(struct rvt_qp *qp); 606f931551bSRalph Campbell 607f931551bSRalph Campbell int qib_register_ib_device(struct qib_devdata *); 608f931551bSRalph Campbell 609f931551bSRalph Campbell void qib_unregister_ib_device(struct qib_devdata *); 610f931551bSRalph Campbell 611f931551bSRalph Campbell void qib_ib_rcv(struct qib_ctxtdata *, void *, void *, u32); 612f931551bSRalph Campbell 613f931551bSRalph Campbell void qib_ib_piobufavail(struct qib_devdata *); 614f931551bSRalph Campbell 615f931551bSRalph Campbell unsigned qib_get_npkeys(struct qib_devdata *); 616f931551bSRalph Campbell 617f931551bSRalph Campbell unsigned qib_get_pkey(struct qib_ibport *, unsigned); 618f931551bSRalph Campbell 619f931551bSRalph Campbell extern const enum ib_wc_opcode ib_qib_wc_opcode[]; 620f931551bSRalph Campbell 621f931551bSRalph Campbell /* 622f931551bSRalph Campbell * Below HCA-independent IB PhysPortState values, returned 623f931551bSRalph Campbell * by the f_ibphys_portstate() routine. 624f931551bSRalph Campbell */ 625f931551bSRalph Campbell #define IB_PHYSPORTSTATE_SLEEP 1 626f931551bSRalph Campbell #define IB_PHYSPORTSTATE_POLL 2 627f931551bSRalph Campbell #define IB_PHYSPORTSTATE_DISABLED 3 628f931551bSRalph Campbell #define IB_PHYSPORTSTATE_CFG_TRAIN 4 629f931551bSRalph Campbell #define IB_PHYSPORTSTATE_LINKUP 5 630f931551bSRalph Campbell #define IB_PHYSPORTSTATE_LINK_ERR_RECOVER 6 631f931551bSRalph Campbell #define IB_PHYSPORTSTATE_CFG_DEBOUNCE 8 632f931551bSRalph Campbell #define IB_PHYSPORTSTATE_CFG_IDLE 0xB 633f931551bSRalph Campbell #define IB_PHYSPORTSTATE_RECOVERY_RETRAIN 0xC 634f931551bSRalph Campbell #define IB_PHYSPORTSTATE_RECOVERY_WAITRMT 0xE 635f931551bSRalph Campbell #define IB_PHYSPORTSTATE_RECOVERY_IDLE 0xF 636f931551bSRalph Campbell #define IB_PHYSPORTSTATE_CFG_ENH 0x10 637f931551bSRalph Campbell #define IB_PHYSPORTSTATE_CFG_WAIT_ENH 0x13 638f931551bSRalph Campbell 639f931551bSRalph Campbell extern const int ib_qib_state_ops[]; 640f931551bSRalph Campbell 641f931551bSRalph Campbell extern __be64 ib_qib_sys_image_guid; /* in network order */ 642f931551bSRalph Campbell 6437c2e11feSDennis Dalessandro extern unsigned int ib_rvt_lkey_table_size; 644f931551bSRalph Campbell 645f931551bSRalph Campbell extern unsigned int ib_qib_max_cqes; 646f931551bSRalph Campbell 647f931551bSRalph Campbell extern unsigned int ib_qib_max_cqs; 648f931551bSRalph Campbell 649f931551bSRalph Campbell extern unsigned int ib_qib_max_qp_wrs; 650f931551bSRalph Campbell 651f931551bSRalph Campbell extern unsigned int ib_qib_max_qps; 652f931551bSRalph Campbell 653f931551bSRalph Campbell extern unsigned int ib_qib_max_sges; 654f931551bSRalph Campbell 655f931551bSRalph Campbell extern unsigned int ib_qib_max_mcast_grps; 656f931551bSRalph Campbell 657f931551bSRalph Campbell extern unsigned int ib_qib_max_mcast_qp_attached; 658f931551bSRalph Campbell 659f931551bSRalph Campbell extern unsigned int ib_qib_max_srqs; 660f931551bSRalph Campbell 661f931551bSRalph Campbell extern unsigned int ib_qib_max_srq_sges; 662f931551bSRalph Campbell 663f931551bSRalph Campbell extern unsigned int ib_qib_max_srq_wrs; 664f931551bSRalph Campbell 665f931551bSRalph Campbell extern const u32 ib_qib_rnr_table[]; 666f931551bSRalph Campbell 667f931551bSRalph Campbell #endif /* QIB_VERBS_H */ 668