162306a36Sopenharmony_ci/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * 462306a36Sopenharmony_ci * This file is provided under a dual BSD/GPLv2 license. When using or 562306a36Sopenharmony_ci * redistributing this file, you may do so under either license. 662306a36Sopenharmony_ci * 762306a36Sopenharmony_ci * GPL LICENSE SUMMARY 862306a36Sopenharmony_ci * 962306a36Sopenharmony_ci * Copyright(c) 2015 - 2020 Intel Corporation. 1062306a36Sopenharmony_ci * 1162306a36Sopenharmony_ci * This program is free software; you can redistribute it and/or modify 1262306a36Sopenharmony_ci * it under the terms of version 2 of the GNU General Public License as 1362306a36Sopenharmony_ci * published by the Free Software Foundation. 1462306a36Sopenharmony_ci * 1562306a36Sopenharmony_ci * This program is distributed in the hope that it will be useful, but 1662306a36Sopenharmony_ci * WITHOUT ANY WARRANTY; without even the implied warranty of 1762306a36Sopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 1862306a36Sopenharmony_ci * General Public License for more details. 1962306a36Sopenharmony_ci * 2062306a36Sopenharmony_ci * BSD LICENSE 2162306a36Sopenharmony_ci * 2262306a36Sopenharmony_ci * Copyright(c) 2015 Intel Corporation. 2362306a36Sopenharmony_ci * 2462306a36Sopenharmony_ci * Redistribution and use in source and binary forms, with or without 2562306a36Sopenharmony_ci * modification, are permitted provided that the following conditions 2662306a36Sopenharmony_ci * are met: 2762306a36Sopenharmony_ci * 2862306a36Sopenharmony_ci * - Redistributions of source code must retain the above copyright 2962306a36Sopenharmony_ci * notice, this list of conditions and the following disclaimer. 3062306a36Sopenharmony_ci * - Redistributions in binary form must reproduce the above copyright 3162306a36Sopenharmony_ci * notice, this list of conditions and the following disclaimer in 3262306a36Sopenharmony_ci * the documentation and/or other materials provided with the 3362306a36Sopenharmony_ci * distribution. 3462306a36Sopenharmony_ci * - Neither the name of Intel Corporation nor the names of its 3562306a36Sopenharmony_ci * contributors may be used to endorse or promote products derived 3662306a36Sopenharmony_ci * from this software without specific prior written permission. 3762306a36Sopenharmony_ci * 3862306a36Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 3962306a36Sopenharmony_ci * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 4062306a36Sopenharmony_ci * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 4162306a36Sopenharmony_ci * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 4262306a36Sopenharmony_ci * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 4362306a36Sopenharmony_ci * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 4462306a36Sopenharmony_ci * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 4562306a36Sopenharmony_ci * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 4662306a36Sopenharmony_ci * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 4762306a36Sopenharmony_ci * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 4862306a36Sopenharmony_ci * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 4962306a36Sopenharmony_ci * 5062306a36Sopenharmony_ci */ 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_ci/* 5362306a36Sopenharmony_ci * This file contains defines, structures, etc. that are used 5462306a36Sopenharmony_ci * to communicate between kernel and user code. 5562306a36Sopenharmony_ci */ 5662306a36Sopenharmony_ci 5762306a36Sopenharmony_ci#ifndef _LINUX__HFI1_USER_H 5862306a36Sopenharmony_ci#define _LINUX__HFI1_USER_H 5962306a36Sopenharmony_ci 6062306a36Sopenharmony_ci#include <linux/types.h> 6162306a36Sopenharmony_ci#include <rdma/rdma_user_ioctl.h> 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_ci/* 6462306a36Sopenharmony_ci * This version number is given to the driver by the user code during 6562306a36Sopenharmony_ci * initialization in the spu_userversion field of hfi1_user_info, so 6662306a36Sopenharmony_ci * the driver can check for compatibility with user code. 6762306a36Sopenharmony_ci * 6862306a36Sopenharmony_ci * The major version changes when data structures change in an incompatible 6962306a36Sopenharmony_ci * way. The driver must be the same for initialization to succeed. 7062306a36Sopenharmony_ci */ 7162306a36Sopenharmony_ci#define HFI1_USER_SWMAJOR 6 7262306a36Sopenharmony_ci 7362306a36Sopenharmony_ci/* 7462306a36Sopenharmony_ci * Minor version differences are always compatible 7562306a36Sopenharmony_ci * a within a major version, however if user software is larger 7662306a36Sopenharmony_ci * than driver software, some new features and/or structure fields 7762306a36Sopenharmony_ci * may not be implemented; the user code must deal with this if it 7862306a36Sopenharmony_ci * cares, or it must abort after initialization reports the difference. 7962306a36Sopenharmony_ci */ 8062306a36Sopenharmony_ci#define HFI1_USER_SWMINOR 3 8162306a36Sopenharmony_ci 8262306a36Sopenharmony_ci/* 8362306a36Sopenharmony_ci * We will encode the major/minor inside a single 32bit version number. 8462306a36Sopenharmony_ci */ 8562306a36Sopenharmony_ci#define HFI1_SWMAJOR_SHIFT 16 8662306a36Sopenharmony_ci 8762306a36Sopenharmony_ci/* 8862306a36Sopenharmony_ci * Set of HW and driver capability/feature bits. 8962306a36Sopenharmony_ci * These bit values are used to configure enabled/disabled HW and 9062306a36Sopenharmony_ci * driver features. The same set of bits are communicated to user 9162306a36Sopenharmony_ci * space. 9262306a36Sopenharmony_ci */ 9362306a36Sopenharmony_ci#define HFI1_CAP_DMA_RTAIL (1UL << 0) /* Use DMA'ed RTail value */ 9462306a36Sopenharmony_ci#define HFI1_CAP_SDMA (1UL << 1) /* Enable SDMA support */ 9562306a36Sopenharmony_ci#define HFI1_CAP_SDMA_AHG (1UL << 2) /* Enable SDMA AHG support */ 9662306a36Sopenharmony_ci#define HFI1_CAP_EXTENDED_PSN (1UL << 3) /* Enable Extended PSN support */ 9762306a36Sopenharmony_ci#define HFI1_CAP_HDRSUPP (1UL << 4) /* Enable Header Suppression */ 9862306a36Sopenharmony_ci#define HFI1_CAP_TID_RDMA (1UL << 5) /* Enable TID RDMA operations */ 9962306a36Sopenharmony_ci#define HFI1_CAP_USE_SDMA_HEAD (1UL << 6) /* DMA Hdr Q tail vs. use CSR */ 10062306a36Sopenharmony_ci#define HFI1_CAP_MULTI_PKT_EGR (1UL << 7) /* Enable multi-packet Egr buffs*/ 10162306a36Sopenharmony_ci#define HFI1_CAP_NODROP_RHQ_FULL (1UL << 8) /* Don't drop on Hdr Q full */ 10262306a36Sopenharmony_ci#define HFI1_CAP_NODROP_EGR_FULL (1UL << 9) /* Don't drop on EGR buffs full */ 10362306a36Sopenharmony_ci#define HFI1_CAP_TID_UNMAP (1UL << 10) /* Disable Expected TID caching */ 10462306a36Sopenharmony_ci#define HFI1_CAP_PRINT_UNIMPL (1UL << 11) /* Show for unimplemented feats */ 10562306a36Sopenharmony_ci#define HFI1_CAP_ALLOW_PERM_JKEY (1UL << 12) /* Allow use of permissive JKEY */ 10662306a36Sopenharmony_ci#define HFI1_CAP_NO_INTEGRITY (1UL << 13) /* Enable ctxt integrity checks */ 10762306a36Sopenharmony_ci#define HFI1_CAP_PKEY_CHECK (1UL << 14) /* Enable ctxt PKey checking */ 10862306a36Sopenharmony_ci#define HFI1_CAP_STATIC_RATE_CTRL (1UL << 15) /* Allow PBC.StaticRateControl */ 10962306a36Sopenharmony_ci#define HFI1_CAP_OPFN (1UL << 16) /* Enable the OPFN protocol */ 11062306a36Sopenharmony_ci#define HFI1_CAP_SDMA_HEAD_CHECK (1UL << 17) /* SDMA head checking */ 11162306a36Sopenharmony_ci#define HFI1_CAP_EARLY_CREDIT_RETURN (1UL << 18) /* early credit return */ 11262306a36Sopenharmony_ci#define HFI1_CAP_AIP (1UL << 19) /* Enable accelerated IP */ 11362306a36Sopenharmony_ci 11462306a36Sopenharmony_ci#define HFI1_RCVHDR_ENTSIZE_2 (1UL << 0) 11562306a36Sopenharmony_ci#define HFI1_RCVHDR_ENTSIZE_16 (1UL << 1) 11662306a36Sopenharmony_ci#define HFI1_RCVDHR_ENTSIZE_32 (1UL << 2) 11762306a36Sopenharmony_ci 11862306a36Sopenharmony_ci#define _HFI1_EVENT_FROZEN_BIT 0 11962306a36Sopenharmony_ci#define _HFI1_EVENT_LINKDOWN_BIT 1 12062306a36Sopenharmony_ci#define _HFI1_EVENT_LID_CHANGE_BIT 2 12162306a36Sopenharmony_ci#define _HFI1_EVENT_LMC_CHANGE_BIT 3 12262306a36Sopenharmony_ci#define _HFI1_EVENT_SL2VL_CHANGE_BIT 4 12362306a36Sopenharmony_ci#define _HFI1_EVENT_TID_MMU_NOTIFY_BIT 5 12462306a36Sopenharmony_ci#define _HFI1_MAX_EVENT_BIT _HFI1_EVENT_TID_MMU_NOTIFY_BIT 12562306a36Sopenharmony_ci 12662306a36Sopenharmony_ci#define HFI1_EVENT_FROZEN (1UL << _HFI1_EVENT_FROZEN_BIT) 12762306a36Sopenharmony_ci#define HFI1_EVENT_LINKDOWN (1UL << _HFI1_EVENT_LINKDOWN_BIT) 12862306a36Sopenharmony_ci#define HFI1_EVENT_LID_CHANGE (1UL << _HFI1_EVENT_LID_CHANGE_BIT) 12962306a36Sopenharmony_ci#define HFI1_EVENT_LMC_CHANGE (1UL << _HFI1_EVENT_LMC_CHANGE_BIT) 13062306a36Sopenharmony_ci#define HFI1_EVENT_SL2VL_CHANGE (1UL << _HFI1_EVENT_SL2VL_CHANGE_BIT) 13162306a36Sopenharmony_ci#define HFI1_EVENT_TID_MMU_NOTIFY (1UL << _HFI1_EVENT_TID_MMU_NOTIFY_BIT) 13262306a36Sopenharmony_ci 13362306a36Sopenharmony_ci/* 13462306a36Sopenharmony_ci * These are the status bits readable (in ASCII form, 64bit value) 13562306a36Sopenharmony_ci * from the "status" sysfs file. For binary compatibility, values 13662306a36Sopenharmony_ci * must remain as is; removed states can be reused for different 13762306a36Sopenharmony_ci * purposes. 13862306a36Sopenharmony_ci */ 13962306a36Sopenharmony_ci#define HFI1_STATUS_INITTED 0x1 /* basic initialization done */ 14062306a36Sopenharmony_ci/* Chip has been found and initialized */ 14162306a36Sopenharmony_ci#define HFI1_STATUS_CHIP_PRESENT 0x20 14262306a36Sopenharmony_ci/* IB link is at ACTIVE, usable for data traffic */ 14362306a36Sopenharmony_ci#define HFI1_STATUS_IB_READY 0x40 14462306a36Sopenharmony_ci/* link is configured, LID, MTU, etc. have been set */ 14562306a36Sopenharmony_ci#define HFI1_STATUS_IB_CONF 0x80 14662306a36Sopenharmony_ci/* A Fatal hardware error has occurred. */ 14762306a36Sopenharmony_ci#define HFI1_STATUS_HWERROR 0x200 14862306a36Sopenharmony_ci 14962306a36Sopenharmony_ci/* 15062306a36Sopenharmony_ci * Number of supported shared contexts. 15162306a36Sopenharmony_ci * This is the maximum number of software contexts that can share 15262306a36Sopenharmony_ci * a hardware send/receive context. 15362306a36Sopenharmony_ci */ 15462306a36Sopenharmony_ci#define HFI1_MAX_SHARED_CTXTS 8 15562306a36Sopenharmony_ci 15662306a36Sopenharmony_ci/* 15762306a36Sopenharmony_ci * Poll types 15862306a36Sopenharmony_ci */ 15962306a36Sopenharmony_ci#define HFI1_POLL_TYPE_ANYRCV 0x0 16062306a36Sopenharmony_ci#define HFI1_POLL_TYPE_URGENT 0x1 16162306a36Sopenharmony_ci 16262306a36Sopenharmony_cienum hfi1_sdma_comp_state { 16362306a36Sopenharmony_ci FREE = 0, 16462306a36Sopenharmony_ci QUEUED, 16562306a36Sopenharmony_ci COMPLETE, 16662306a36Sopenharmony_ci ERROR 16762306a36Sopenharmony_ci}; 16862306a36Sopenharmony_ci 16962306a36Sopenharmony_ci/* 17062306a36Sopenharmony_ci * SDMA completion ring entry 17162306a36Sopenharmony_ci */ 17262306a36Sopenharmony_cistruct hfi1_sdma_comp_entry { 17362306a36Sopenharmony_ci __u32 status; 17462306a36Sopenharmony_ci __u32 errcode; 17562306a36Sopenharmony_ci}; 17662306a36Sopenharmony_ci 17762306a36Sopenharmony_ci/* 17862306a36Sopenharmony_ci * Device status and notifications from driver to user-space. 17962306a36Sopenharmony_ci */ 18062306a36Sopenharmony_cistruct hfi1_status { 18162306a36Sopenharmony_ci __aligned_u64 dev; /* device/hw status bits */ 18262306a36Sopenharmony_ci __aligned_u64 port; /* port state and status bits */ 18362306a36Sopenharmony_ci char freezemsg[]; 18462306a36Sopenharmony_ci}; 18562306a36Sopenharmony_ci 18662306a36Sopenharmony_cienum sdma_req_opcode { 18762306a36Sopenharmony_ci EXPECTED = 0, 18862306a36Sopenharmony_ci EAGER 18962306a36Sopenharmony_ci}; 19062306a36Sopenharmony_ci 19162306a36Sopenharmony_ci#define HFI1_SDMA_REQ_VERSION_MASK 0xF 19262306a36Sopenharmony_ci#define HFI1_SDMA_REQ_VERSION_SHIFT 0x0 19362306a36Sopenharmony_ci#define HFI1_SDMA_REQ_OPCODE_MASK 0xF 19462306a36Sopenharmony_ci#define HFI1_SDMA_REQ_OPCODE_SHIFT 0x4 19562306a36Sopenharmony_ci#define HFI1_SDMA_REQ_IOVCNT_MASK 0xFF 19662306a36Sopenharmony_ci#define HFI1_SDMA_REQ_IOVCNT_SHIFT 0x8 19762306a36Sopenharmony_ci 19862306a36Sopenharmony_cistruct sdma_req_info { 19962306a36Sopenharmony_ci /* 20062306a36Sopenharmony_ci * bits 0-3 - version (currently unused) 20162306a36Sopenharmony_ci * bits 4-7 - opcode (enum sdma_req_opcode) 20262306a36Sopenharmony_ci * bits 8-15 - io vector count 20362306a36Sopenharmony_ci */ 20462306a36Sopenharmony_ci __u16 ctrl; 20562306a36Sopenharmony_ci /* 20662306a36Sopenharmony_ci * Number of fragments contained in this request. 20762306a36Sopenharmony_ci * User-space has already computed how many 20862306a36Sopenharmony_ci * fragment-sized packet the user buffer will be 20962306a36Sopenharmony_ci * split into. 21062306a36Sopenharmony_ci */ 21162306a36Sopenharmony_ci __u16 npkts; 21262306a36Sopenharmony_ci /* 21362306a36Sopenharmony_ci * Size of each fragment the user buffer will be 21462306a36Sopenharmony_ci * split into. 21562306a36Sopenharmony_ci */ 21662306a36Sopenharmony_ci __u16 fragsize; 21762306a36Sopenharmony_ci /* 21862306a36Sopenharmony_ci * Index of the slot in the SDMA completion ring 21962306a36Sopenharmony_ci * this request should be using. User-space is 22062306a36Sopenharmony_ci * in charge of managing its own ring. 22162306a36Sopenharmony_ci */ 22262306a36Sopenharmony_ci __u16 comp_idx; 22362306a36Sopenharmony_ci} __attribute__((__packed__)); 22462306a36Sopenharmony_ci 22562306a36Sopenharmony_ci/* 22662306a36Sopenharmony_ci * SW KDETH header. 22762306a36Sopenharmony_ci * swdata is SW defined portion. 22862306a36Sopenharmony_ci */ 22962306a36Sopenharmony_cistruct hfi1_kdeth_header { 23062306a36Sopenharmony_ci __le32 ver_tid_offset; 23162306a36Sopenharmony_ci __le16 jkey; 23262306a36Sopenharmony_ci __le16 hcrc; 23362306a36Sopenharmony_ci __le32 swdata[7]; 23462306a36Sopenharmony_ci} __attribute__((__packed__)); 23562306a36Sopenharmony_ci 23662306a36Sopenharmony_ci/* 23762306a36Sopenharmony_ci * Structure describing the headers that User space uses. The 23862306a36Sopenharmony_ci * structure above is a subset of this one. 23962306a36Sopenharmony_ci */ 24062306a36Sopenharmony_cistruct hfi1_pkt_header { 24162306a36Sopenharmony_ci __le16 pbc[4]; 24262306a36Sopenharmony_ci __be16 lrh[4]; 24362306a36Sopenharmony_ci __be32 bth[3]; 24462306a36Sopenharmony_ci struct hfi1_kdeth_header kdeth; 24562306a36Sopenharmony_ci} __attribute__((__packed__)); 24662306a36Sopenharmony_ci 24762306a36Sopenharmony_ci 24862306a36Sopenharmony_ci/* 24962306a36Sopenharmony_ci * The list of usermode accessible registers. 25062306a36Sopenharmony_ci */ 25162306a36Sopenharmony_cienum hfi1_ureg { 25262306a36Sopenharmony_ci /* (RO) DMA RcvHdr to be used next. */ 25362306a36Sopenharmony_ci ur_rcvhdrtail = 0, 25462306a36Sopenharmony_ci /* (RW) RcvHdr entry to be processed next by host. */ 25562306a36Sopenharmony_ci ur_rcvhdrhead = 1, 25662306a36Sopenharmony_ci /* (RO) Index of next Eager index to use. */ 25762306a36Sopenharmony_ci ur_rcvegrindextail = 2, 25862306a36Sopenharmony_ci /* (RW) Eager TID to be processed next */ 25962306a36Sopenharmony_ci ur_rcvegrindexhead = 3, 26062306a36Sopenharmony_ci /* (RO) Receive Eager Offset Tail */ 26162306a36Sopenharmony_ci ur_rcvegroffsettail = 4, 26262306a36Sopenharmony_ci /* For internal use only; max register number. */ 26362306a36Sopenharmony_ci ur_maxreg, 26462306a36Sopenharmony_ci /* (RW) Receive TID flow table */ 26562306a36Sopenharmony_ci ur_rcvtidflowtable = 256 26662306a36Sopenharmony_ci}; 26762306a36Sopenharmony_ci 26862306a36Sopenharmony_ci#endif /* _LINIUX__HFI1_USER_H */ 269