1331772Shselasky/*- 2331772Shselasky * SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0 3331772Shselasky * 4319974Shselasky * Copyright(c) 2016 Intel Corporation. 5319974Shselasky * 6319974Shselasky * This file is provided under a dual BSD/GPLv2 license. When using or 7319974Shselasky * redistributing this file, you may do so under either license. 8319974Shselasky * 9319974Shselasky * GPL LICENSE SUMMARY 10319974Shselasky * 11319974Shselasky * This program is free software; you can redistribute it and/or modify 12319974Shselasky * it under the terms of version 2 of the GNU General Public License as 13319974Shselasky * published by the Free Software Foundation. 14319974Shselasky * 15319974Shselasky * This program is distributed in the hope that it will be useful, but 16319974Shselasky * WITHOUT ANY WARRANTY; without even the implied warranty of 17319974Shselasky * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18319974Shselasky * General Public License for more details. 19319974Shselasky * 20319974Shselasky * BSD LICENSE 21319974Shselasky * 22319974Shselasky * Redistribution and use in source and binary forms, with or without 23319974Shselasky * modification, are permitted provided that the following conditions 24319974Shselasky * are met: 25319974Shselasky * 26319974Shselasky * - Redistributions of source code must retain the above copyright 27319974Shselasky * notice, this list of conditions and the following disclaimer. 28319974Shselasky * - Redistributions in binary form must reproduce the above copyright 29319974Shselasky * notice, this list of conditions and the following disclaimer in 30319974Shselasky * the documentation and/or other materials provided with the 31319974Shselasky * distribution. 32319974Shselasky * - Neither the name of Intel Corporation nor the names of its 33319974Shselasky * contributors may be used to endorse or promote products derived 34319974Shselasky * from this software without specific prior written permission. 35319974Shselasky * 36319974Shselasky * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 37319974Shselasky * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 38319974Shselasky * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 39319974Shselasky * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 40319974Shselasky * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 41319974Shselasky * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 42319974Shselasky * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 43319974Shselasky * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 44319974Shselasky * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 45319974Shselasky * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 46319974Shselasky * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 47319974Shselasky * 48331772Shselasky * $FreeBSD: stable/11/sys/ofed/include/rdma/ib_hdrs.h 331772 2018-03-30 18:17:33Z hselasky $ 49319974Shselasky */ 50319974Shselasky 51319974Shselasky#ifndef IB_HDRS_H 52319974Shselasky#define IB_HDRS_H 53319974Shselasky 54319974Shselasky#include <linux/types.h> 55319974Shselasky#include <asm/unaligned.h> 56319974Shselasky#include <rdma/ib_verbs.h> 57319974Shselasky 58319974Shselasky#define IB_SEQ_NAK (3 << 29) 59319974Shselasky 60319974Shselasky/* AETH NAK opcode values */ 61319974Shselasky#define IB_RNR_NAK 0x20 62319974Shselasky#define IB_NAK_PSN_ERROR 0x60 63319974Shselasky#define IB_NAK_INVALID_REQUEST 0x61 64319974Shselasky#define IB_NAK_REMOTE_ACCESS_ERROR 0x62 65319974Shselasky#define IB_NAK_REMOTE_OPERATIONAL_ERROR 0x63 66319974Shselasky#define IB_NAK_INVALID_RD_REQUEST 0x64 67319974Shselasky 68319974Shselasky#define IB_BTH_REQ_ACK BIT(31) 69319974Shselasky#define IB_BTH_SOLICITED BIT(23) 70319974Shselasky#define IB_BTH_MIG_REQ BIT(22) 71319974Shselasky 72319974Shselasky#define IB_GRH_VERSION 6 73319974Shselasky#define IB_GRH_VERSION_MASK 0xF 74319974Shselasky#define IB_GRH_VERSION_SHIFT 28 75319974Shselasky#define IB_GRH_TCLASS_MASK 0xFF 76319974Shselasky#define IB_GRH_TCLASS_SHIFT 20 77319974Shselasky#define IB_GRH_FLOW_MASK 0xFFFFF 78319974Shselasky#define IB_GRH_FLOW_SHIFT 0 79319974Shselasky#define IB_GRH_NEXT_HDR 0x1B 80319974Shselasky 81319974Shselaskystruct ib_reth { 82319974Shselasky __be64 vaddr; /* potentially unaligned */ 83319974Shselasky __be32 rkey; 84319974Shselasky __be32 length; 85319974Shselasky} __packed; 86319974Shselasky 87319974Shselaskystruct ib_atomic_eth { 88319974Shselasky __be64 vaddr; /* potentially unaligned */ 89319974Shselasky __be32 rkey; 90319974Shselasky __be64 swap_data; /* potentially unaligned */ 91319974Shselasky __be64 compare_data; /* potentially unaligned */ 92319974Shselasky} __packed; 93319974Shselasky 94319974Shselaskyunion ib_ehdrs { 95319974Shselasky struct { 96319974Shselasky __be32 deth[2]; 97319974Shselasky __be32 imm_data; 98319974Shselasky } ud; 99319974Shselasky struct { 100319974Shselasky struct ib_reth reth; 101319974Shselasky __be32 imm_data; 102319974Shselasky } rc; 103319974Shselasky struct { 104319974Shselasky __be32 aeth; 105319974Shselasky __be64 atomic_ack_eth; /* potentially unaligned */ 106319974Shselasky } __packed at; 107319974Shselasky __be32 imm_data; 108319974Shselasky __be32 aeth; 109319974Shselasky __be32 ieth; 110319974Shselasky struct ib_atomic_eth atomic_eth; 111319974Shselasky} __packed; 112319974Shselasky 113319974Shselaskystruct ib_other_headers { 114319974Shselasky __be32 bth[3]; 115319974Shselasky union ib_ehdrs u; 116319974Shselasky} __packed; 117319974Shselasky 118319974Shselaskystruct ib_header { 119319974Shselasky __be16 lrh[4]; 120319974Shselasky union { 121319974Shselasky struct { 122319974Shselasky struct ib_grh grh; 123319974Shselasky struct ib_other_headers oth; 124319974Shselasky } l; 125319974Shselasky struct ib_other_headers oth; 126319974Shselasky } u; 127319974Shselasky} __packed; 128319974Shselasky 129319974Shselasky/* accessors for unaligned __be64 items */ 130319974Shselasky 131319974Shselaskystatic inline u64 ib_u64_get(__be64 *p) 132319974Shselasky{ 133319974Shselasky return get_unaligned_be64(p); 134319974Shselasky} 135319974Shselasky 136319974Shselaskystatic inline void ib_u64_put(u64 val, __be64 *p) 137319974Shselasky{ 138319974Shselasky put_unaligned_be64(val, p); 139319974Shselasky} 140319974Shselasky 141319974Shselaskystatic inline u64 get_ib_reth_vaddr(struct ib_reth *reth) 142319974Shselasky{ 143319974Shselasky return ib_u64_get(&reth->vaddr); 144319974Shselasky} 145319974Shselasky 146319974Shselaskystatic inline void put_ib_reth_vaddr(u64 val, struct ib_reth *reth) 147319974Shselasky{ 148319974Shselasky ib_u64_put(val, &reth->vaddr); 149319974Shselasky} 150319974Shselasky 151319974Shselaskystatic inline u64 get_ib_ateth_vaddr(struct ib_atomic_eth *ateth) 152319974Shselasky{ 153319974Shselasky return ib_u64_get(&ateth->vaddr); 154319974Shselasky} 155319974Shselasky 156319974Shselaskystatic inline void put_ib_ateth_vaddr(u64 val, struct ib_atomic_eth *ateth) 157319974Shselasky{ 158319974Shselasky ib_u64_put(val, &ateth->vaddr); 159319974Shselasky} 160319974Shselasky 161319974Shselaskystatic inline u64 get_ib_ateth_swap(struct ib_atomic_eth *ateth) 162319974Shselasky{ 163319974Shselasky return ib_u64_get(&ateth->swap_data); 164319974Shselasky} 165319974Shselasky 166319974Shselaskystatic inline void put_ib_ateth_swap(u64 val, struct ib_atomic_eth *ateth) 167319974Shselasky{ 168319974Shselasky ib_u64_put(val, &ateth->swap_data); 169319974Shselasky} 170319974Shselasky 171319974Shselaskystatic inline u64 get_ib_ateth_compare(struct ib_atomic_eth *ateth) 172319974Shselasky{ 173319974Shselasky return ib_u64_get(&ateth->compare_data); 174319974Shselasky} 175319974Shselasky 176319974Shselaskystatic inline void put_ib_ateth_compare(u64 val, struct ib_atomic_eth *ateth) 177319974Shselasky{ 178319974Shselasky ib_u64_put(val, &ateth->compare_data); 179319974Shselasky} 180319974Shselasky 181319974Shselasky#endif /* IB_HDRS_H */ 182