xref: /linux/include/uapi/linux/rio_mport_cdev.h (revision 498495dba268b20e8eadd7fe93c140c68b6cc9d2)
1*e2be04c7SGreg Kroah-Hartman /* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */
24e1016daSAlexandre Bounine /*
34e1016daSAlexandre Bounine  * Copyright (c) 2015-2016, Integrated Device Technology Inc.
44e1016daSAlexandre Bounine  * Copyright (c) 2015, Prodrive Technologies
54e1016daSAlexandre Bounine  * Copyright (c) 2015, Texas Instruments Incorporated
64e1016daSAlexandre Bounine  * Copyright (c) 2015, RapidIO Trade Association
74e1016daSAlexandre Bounine  * All rights reserved.
84e1016daSAlexandre Bounine  *
94e1016daSAlexandre Bounine  * This software is available to you under a choice of one of two licenses.
104e1016daSAlexandre Bounine  * You may choose to be licensed under the terms of the GNU General Public
114e1016daSAlexandre Bounine  * License(GPL) Version 2, or the BSD-3 Clause license below:
124e1016daSAlexandre Bounine  *
134e1016daSAlexandre Bounine  * Redistribution and use in source and binary forms, with or without
144e1016daSAlexandre Bounine  * modification, are permitted provided that the following conditions are met:
154e1016daSAlexandre Bounine  *
164e1016daSAlexandre Bounine  * 1. Redistributions of source code must retain the above copyright notice,
174e1016daSAlexandre Bounine  * this list of conditions and the following disclaimer.
184e1016daSAlexandre Bounine  *
194e1016daSAlexandre Bounine  * 2. Redistributions in binary form must reproduce the above copyright notice,
204e1016daSAlexandre Bounine  * this list of conditions and the following disclaimer in the documentation
214e1016daSAlexandre Bounine  * and/or other materials provided with the distribution.
224e1016daSAlexandre Bounine  *
234e1016daSAlexandre Bounine  * 3. Neither the name of the copyright holder nor the names of its contributors
244e1016daSAlexandre Bounine  * may be used to endorse or promote products derived from this software without
254e1016daSAlexandre Bounine  * specific prior written permission.
264e1016daSAlexandre Bounine  *
274e1016daSAlexandre Bounine  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
284e1016daSAlexandre Bounine  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
294e1016daSAlexandre Bounine  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
304e1016daSAlexandre Bounine  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
314e1016daSAlexandre Bounine  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
324e1016daSAlexandre Bounine  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
334e1016daSAlexandre Bounine  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
344e1016daSAlexandre Bounine  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
354e1016daSAlexandre Bounine  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
364e1016daSAlexandre Bounine  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
374e1016daSAlexandre Bounine  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
384e1016daSAlexandre Bounine  */
394e1016daSAlexandre Bounine 
404e1016daSAlexandre Bounine #ifndef _RIO_MPORT_CDEV_H_
414e1016daSAlexandre Bounine #define _RIO_MPORT_CDEV_H_
424e1016daSAlexandre Bounine 
434e1016daSAlexandre Bounine #include <linux/ioctl.h>
444e1016daSAlexandre Bounine #include <linux/types.h>
454e1016daSAlexandre Bounine 
464e1016daSAlexandre Bounine struct rio_mport_maint_io {
474e1016daSAlexandre Bounine 	__u16 rioid;		/* destID of remote device */
484e1016daSAlexandre Bounine 	__u8  hopcount;		/* hopcount to remote device */
494e1016daSAlexandre Bounine 	__u8  pad0[5];
504e1016daSAlexandre Bounine 	__u32 offset;		/* offset in register space */
514e1016daSAlexandre Bounine 	__u32 length;		/* length in bytes */
524e1016daSAlexandre Bounine 	__u64 buffer;		/* pointer to data buffer */
534e1016daSAlexandre Bounine };
544e1016daSAlexandre Bounine 
554e1016daSAlexandre Bounine /*
564e1016daSAlexandre Bounine  * Definitions for RapidIO data transfers:
574e1016daSAlexandre Bounine  * - memory mapped (MAPPED)
584e1016daSAlexandre Bounine  * - packet generation from memory (TRANSFER)
594e1016daSAlexandre Bounine  */
604e1016daSAlexandre Bounine #define RIO_TRANSFER_MODE_MAPPED	(1 << 0)
614e1016daSAlexandre Bounine #define RIO_TRANSFER_MODE_TRANSFER	(1 << 1)
624e1016daSAlexandre Bounine #define RIO_CAP_DBL_SEND		(1 << 2)
634e1016daSAlexandre Bounine #define RIO_CAP_DBL_RECV		(1 << 3)
644e1016daSAlexandre Bounine #define RIO_CAP_PW_SEND			(1 << 4)
654e1016daSAlexandre Bounine #define RIO_CAP_PW_RECV			(1 << 5)
664e1016daSAlexandre Bounine #define RIO_CAP_MAP_OUTB		(1 << 6)
674e1016daSAlexandre Bounine #define RIO_CAP_MAP_INB			(1 << 7)
684e1016daSAlexandre Bounine 
694e1016daSAlexandre Bounine struct rio_mport_properties {
704e1016daSAlexandre Bounine 	__u16 hdid;
714e1016daSAlexandre Bounine 	__u8  id;			/* Physical port ID */
724e1016daSAlexandre Bounine 	__u8  index;
734e1016daSAlexandre Bounine 	__u32 flags;
744e1016daSAlexandre Bounine 	__u32 sys_size;		/* Default addressing size */
754e1016daSAlexandre Bounine 	__u8  port_ok;
764e1016daSAlexandre Bounine 	__u8  link_speed;
774e1016daSAlexandre Bounine 	__u8  link_width;
784e1016daSAlexandre Bounine 	__u8  pad0;
794e1016daSAlexandre Bounine 	__u32 dma_max_sge;
804e1016daSAlexandre Bounine 	__u32 dma_max_size;
814e1016daSAlexandre Bounine 	__u32 dma_align;
824e1016daSAlexandre Bounine 	__u32 transfer_mode;		/* Default transfer mode */
834e1016daSAlexandre Bounine 	__u32 cap_sys_size;		/* Capable system sizes */
844e1016daSAlexandre Bounine 	__u32 cap_addr_size;		/* Capable addressing sizes */
854e1016daSAlexandre Bounine 	__u32 cap_transfer_mode;	/* Capable transfer modes */
864e1016daSAlexandre Bounine 	__u32 cap_mport;		/* Mport capabilities */
874e1016daSAlexandre Bounine };
884e1016daSAlexandre Bounine 
894e1016daSAlexandre Bounine /*
904e1016daSAlexandre Bounine  * Definitions for RapidIO events;
914e1016daSAlexandre Bounine  * - incoming port-writes
924e1016daSAlexandre Bounine  * - incoming doorbells
934e1016daSAlexandre Bounine  */
944e1016daSAlexandre Bounine #define RIO_DOORBELL	(1 << 0)
954e1016daSAlexandre Bounine #define RIO_PORTWRITE	(1 << 1)
964e1016daSAlexandre Bounine 
974e1016daSAlexandre Bounine struct rio_doorbell {
984e1016daSAlexandre Bounine 	__u16 rioid;
994e1016daSAlexandre Bounine 	__u16 payload;
1004e1016daSAlexandre Bounine };
1014e1016daSAlexandre Bounine 
1024e1016daSAlexandre Bounine struct rio_doorbell_filter {
1034e1016daSAlexandre Bounine 	__u16 rioid;	/* Use RIO_INVALID_DESTID to match all ids */
1044e1016daSAlexandre Bounine 	__u16 low;
1054e1016daSAlexandre Bounine 	__u16 high;
1064e1016daSAlexandre Bounine 	__u16 pad0;
1074e1016daSAlexandre Bounine };
1084e1016daSAlexandre Bounine 
1094e1016daSAlexandre Bounine 
1104e1016daSAlexandre Bounine struct rio_portwrite {
1114e1016daSAlexandre Bounine 	__u32 payload[16];
1124e1016daSAlexandre Bounine };
1134e1016daSAlexandre Bounine 
1144e1016daSAlexandre Bounine struct rio_pw_filter {
1154e1016daSAlexandre Bounine 	__u32 mask;
1164e1016daSAlexandre Bounine 	__u32 low;
1174e1016daSAlexandre Bounine 	__u32 high;
1184e1016daSAlexandre Bounine 	__u32 pad0;
1194e1016daSAlexandre Bounine };
1204e1016daSAlexandre Bounine 
1214e1016daSAlexandre Bounine /* RapidIO base address for inbound requests set to value defined below
1224e1016daSAlexandre Bounine  * indicates that no specific RIO-to-local address translation is requested
1234e1016daSAlexandre Bounine  * and driver should use direct (one-to-one) address mapping.
1244e1016daSAlexandre Bounine */
1254e1016daSAlexandre Bounine #define RIO_MAP_ANY_ADDR	(__u64)(~((__u64) 0))
1264e1016daSAlexandre Bounine 
1274e1016daSAlexandre Bounine struct rio_mmap {
1284e1016daSAlexandre Bounine 	__u16 rioid;
1294e1016daSAlexandre Bounine 	__u16 pad0[3];
1304e1016daSAlexandre Bounine 	__u64 rio_addr;
1314e1016daSAlexandre Bounine 	__u64 length;
1324e1016daSAlexandre Bounine 	__u64 handle;
1334e1016daSAlexandre Bounine 	__u64 address;
1344e1016daSAlexandre Bounine };
1354e1016daSAlexandre Bounine 
1364e1016daSAlexandre Bounine struct rio_dma_mem {
1374e1016daSAlexandre Bounine 	__u64 length;		/* length of DMA memory */
1384e1016daSAlexandre Bounine 	__u64 dma_handle;	/* handle associated with this memory */
1394e1016daSAlexandre Bounine 	__u64 address;
1404e1016daSAlexandre Bounine };
1414e1016daSAlexandre Bounine 
1424e1016daSAlexandre Bounine struct rio_event {
1434e1016daSAlexandre Bounine 	__u32 header;	/* event type RIO_DOORBELL or RIO_PORTWRITE */
1444e1016daSAlexandre Bounine 	union {
1454e1016daSAlexandre Bounine 		struct rio_doorbell doorbell;	/* header for RIO_DOORBELL */
1464e1016daSAlexandre Bounine 		struct rio_portwrite portwrite; /* header for RIO_PORTWRITE */
1474e1016daSAlexandre Bounine 	} u;
1484e1016daSAlexandre Bounine 	__u32 pad0;
1494e1016daSAlexandre Bounine };
1504e1016daSAlexandre Bounine 
1514e1016daSAlexandre Bounine enum rio_transfer_sync {
1524e1016daSAlexandre Bounine 	RIO_TRANSFER_SYNC,	/* synchronous transfer */
1534e1016daSAlexandre Bounine 	RIO_TRANSFER_ASYNC,	/* asynchronous transfer */
1544e1016daSAlexandre Bounine 	RIO_TRANSFER_FAF,	/* fire-and-forget transfer */
1554e1016daSAlexandre Bounine };
1564e1016daSAlexandre Bounine 
1574e1016daSAlexandre Bounine enum rio_transfer_dir {
1584e1016daSAlexandre Bounine 	RIO_TRANSFER_DIR_READ,	/* Read operation */
1594e1016daSAlexandre Bounine 	RIO_TRANSFER_DIR_WRITE,	/* Write operation */
1604e1016daSAlexandre Bounine };
1614e1016daSAlexandre Bounine 
1624e1016daSAlexandre Bounine /*
1634e1016daSAlexandre Bounine  * RapidIO data exchange transactions are lists of individual transfers. Each
1644e1016daSAlexandre Bounine  * transfer exchanges data between two RapidIO devices by remote direct memory
1654e1016daSAlexandre Bounine  * access and has its own completion code.
1664e1016daSAlexandre Bounine  *
1674e1016daSAlexandre Bounine  * The RapidIO specification defines four types of data exchange requests:
1684e1016daSAlexandre Bounine  * NREAD, NWRITE, SWRITE and NWRITE_R. The RapidIO DMA channel interface allows
1694e1016daSAlexandre Bounine  * to specify the required type of write operation or combination of them when
1704e1016daSAlexandre Bounine  * only the last data packet requires response.
1714e1016daSAlexandre Bounine  *
1724e1016daSAlexandre Bounine  * NREAD:    read up to 256 bytes from remote device memory into local memory
1734e1016daSAlexandre Bounine  * NWRITE:   write up to 256 bytes from local memory to remote device memory
1744e1016daSAlexandre Bounine  *           without confirmation
1754e1016daSAlexandre Bounine  * SWRITE:   as NWRITE, but all addresses and payloads must be 64-bit aligned
1764e1016daSAlexandre Bounine  * NWRITE_R: as NWRITE, but expect acknowledgment from remote device.
1774e1016daSAlexandre Bounine  *
1784e1016daSAlexandre Bounine  * The default exchange is chosen from NREAD and any of the WRITE modes as the
1794e1016daSAlexandre Bounine  * driver sees fit. For write requests the user can explicitly choose between
1804e1016daSAlexandre Bounine  * any of the write modes for each transaction.
1814e1016daSAlexandre Bounine  */
1824e1016daSAlexandre Bounine enum rio_exchange {
1834e1016daSAlexandre Bounine 	RIO_EXCHANGE_DEFAULT,	/* Default method */
1844e1016daSAlexandre Bounine 	RIO_EXCHANGE_NWRITE,	/* All packets using NWRITE */
1854e1016daSAlexandre Bounine 	RIO_EXCHANGE_SWRITE,	/* All packets using SWRITE */
1864e1016daSAlexandre Bounine 	RIO_EXCHANGE_NWRITE_R,	/* Last packet NWRITE_R, others NWRITE */
1874e1016daSAlexandre Bounine 	RIO_EXCHANGE_SWRITE_R,	/* Last packet NWRITE_R, others SWRITE */
1884e1016daSAlexandre Bounine 	RIO_EXCHANGE_NWRITE_R_ALL, /* All packets using NWRITE_R */
1894e1016daSAlexandre Bounine };
1904e1016daSAlexandre Bounine 
1914e1016daSAlexandre Bounine struct rio_transfer_io {
1924e1016daSAlexandre Bounine 	__u64 rio_addr;	/* Address in target's RIO mem space */
1934e1016daSAlexandre Bounine 	__u64 loc_addr;
1944e1016daSAlexandre Bounine 	__u64 handle;
1954e1016daSAlexandre Bounine 	__u64 offset;	/* Offset in buffer */
1964e1016daSAlexandre Bounine 	__u64 length;	/* Length in bytes */
1974e1016daSAlexandre Bounine 	__u16 rioid;	/* Target destID */
1984e1016daSAlexandre Bounine 	__u16 method;	/* Data exchange method, one of rio_exchange enum */
1994e1016daSAlexandre Bounine 	__u32 completion_code;	/* Completion code for this transfer */
2004e1016daSAlexandre Bounine };
2014e1016daSAlexandre Bounine 
2024e1016daSAlexandre Bounine struct rio_transaction {
2034e1016daSAlexandre Bounine 	__u64 block;	/* Pointer to array of <count> transfers */
2044e1016daSAlexandre Bounine 	__u32 count;	/* Number of transfers */
2054e1016daSAlexandre Bounine 	__u32 transfer_mode;	/* Data transfer mode */
2064e1016daSAlexandre Bounine 	__u16 sync;	/* Synch method, one of rio_transfer_sync enum */
2074e1016daSAlexandre Bounine 	__u16 dir;	/* Transfer direction, one of rio_transfer_dir enum */
2084e1016daSAlexandre Bounine 	__u32 pad0;
2094e1016daSAlexandre Bounine };
2104e1016daSAlexandre Bounine 
2114e1016daSAlexandre Bounine struct rio_async_tx_wait {
2124e1016daSAlexandre Bounine 	__u32 token;	/* DMA transaction ID token */
2134e1016daSAlexandre Bounine 	__u32 timeout;	/* Wait timeout in msec, if 0 use default TO */
2144e1016daSAlexandre Bounine };
2154e1016daSAlexandre Bounine 
2164e1016daSAlexandre Bounine #define RIO_MAX_DEVNAME_SZ	20
2174e1016daSAlexandre Bounine 
2184e1016daSAlexandre Bounine struct rio_rdev_info {
2194e1016daSAlexandre Bounine 	__u16 destid;
2204e1016daSAlexandre Bounine 	__u8 hopcount;
2214e1016daSAlexandre Bounine 	__u8 pad0;
2224e1016daSAlexandre Bounine 	__u32 comptag;
2234e1016daSAlexandre Bounine 	char name[RIO_MAX_DEVNAME_SZ + 1];
2244e1016daSAlexandre Bounine };
2254e1016daSAlexandre Bounine 
2264e1016daSAlexandre Bounine /* Driver IOCTL codes */
2274e1016daSAlexandre Bounine #define RIO_MPORT_DRV_MAGIC           'm'
2284e1016daSAlexandre Bounine 
2294e1016daSAlexandre Bounine #define RIO_MPORT_MAINT_HDID_SET	\
2304e1016daSAlexandre Bounine 	_IOW(RIO_MPORT_DRV_MAGIC, 1, __u16)
2314e1016daSAlexandre Bounine #define RIO_MPORT_MAINT_COMPTAG_SET	\
2324e1016daSAlexandre Bounine 	_IOW(RIO_MPORT_DRV_MAGIC, 2, __u32)
2334e1016daSAlexandre Bounine #define RIO_MPORT_MAINT_PORT_IDX_GET	\
2344e1016daSAlexandre Bounine 	_IOR(RIO_MPORT_DRV_MAGIC, 3, __u32)
2354e1016daSAlexandre Bounine #define RIO_MPORT_GET_PROPERTIES \
2364e1016daSAlexandre Bounine 	_IOR(RIO_MPORT_DRV_MAGIC, 4, struct rio_mport_properties)
2374e1016daSAlexandre Bounine #define RIO_MPORT_MAINT_READ_LOCAL \
2384e1016daSAlexandre Bounine 	_IOR(RIO_MPORT_DRV_MAGIC, 5, struct rio_mport_maint_io)
2394e1016daSAlexandre Bounine #define RIO_MPORT_MAINT_WRITE_LOCAL \
2404e1016daSAlexandre Bounine 	_IOW(RIO_MPORT_DRV_MAGIC, 6, struct rio_mport_maint_io)
2414e1016daSAlexandre Bounine #define RIO_MPORT_MAINT_READ_REMOTE \
2424e1016daSAlexandre Bounine 	_IOR(RIO_MPORT_DRV_MAGIC, 7, struct rio_mport_maint_io)
2434e1016daSAlexandre Bounine #define RIO_MPORT_MAINT_WRITE_REMOTE \
2444e1016daSAlexandre Bounine 	_IOW(RIO_MPORT_DRV_MAGIC, 8, struct rio_mport_maint_io)
2454e1016daSAlexandre Bounine #define RIO_ENABLE_DOORBELL_RANGE	\
2464e1016daSAlexandre Bounine 	_IOW(RIO_MPORT_DRV_MAGIC, 9, struct rio_doorbell_filter)
2474e1016daSAlexandre Bounine #define RIO_DISABLE_DOORBELL_RANGE	\
2484e1016daSAlexandre Bounine 	_IOW(RIO_MPORT_DRV_MAGIC, 10, struct rio_doorbell_filter)
2494e1016daSAlexandre Bounine #define RIO_ENABLE_PORTWRITE_RANGE	\
2504e1016daSAlexandre Bounine 	_IOW(RIO_MPORT_DRV_MAGIC, 11, struct rio_pw_filter)
2514e1016daSAlexandre Bounine #define RIO_DISABLE_PORTWRITE_RANGE	\
2524e1016daSAlexandre Bounine 	_IOW(RIO_MPORT_DRV_MAGIC, 12, struct rio_pw_filter)
2534e1016daSAlexandre Bounine #define RIO_SET_EVENT_MASK		\
2544e1016daSAlexandre Bounine 	_IOW(RIO_MPORT_DRV_MAGIC, 13, __u32)
2554e1016daSAlexandre Bounine #define RIO_GET_EVENT_MASK		\
2564e1016daSAlexandre Bounine 	_IOR(RIO_MPORT_DRV_MAGIC, 14, __u32)
2574e1016daSAlexandre Bounine #define RIO_MAP_OUTBOUND \
2584e1016daSAlexandre Bounine 	_IOWR(RIO_MPORT_DRV_MAGIC, 15, struct rio_mmap)
2594e1016daSAlexandre Bounine #define RIO_UNMAP_OUTBOUND \
2604e1016daSAlexandre Bounine 	_IOW(RIO_MPORT_DRV_MAGIC, 16, struct rio_mmap)
2614e1016daSAlexandre Bounine #define RIO_MAP_INBOUND \
2624e1016daSAlexandre Bounine 	_IOWR(RIO_MPORT_DRV_MAGIC, 17, struct rio_mmap)
2634e1016daSAlexandre Bounine #define RIO_UNMAP_INBOUND \
2644e1016daSAlexandre Bounine 	_IOW(RIO_MPORT_DRV_MAGIC, 18, __u64)
2654e1016daSAlexandre Bounine #define RIO_ALLOC_DMA \
2664e1016daSAlexandre Bounine 	_IOWR(RIO_MPORT_DRV_MAGIC, 19, struct rio_dma_mem)
2674e1016daSAlexandre Bounine #define RIO_FREE_DMA \
2684e1016daSAlexandre Bounine 	_IOW(RIO_MPORT_DRV_MAGIC, 20, __u64)
2694e1016daSAlexandre Bounine #define RIO_TRANSFER \
2704e1016daSAlexandre Bounine 	_IOWR(RIO_MPORT_DRV_MAGIC, 21, struct rio_transaction)
2714e1016daSAlexandre Bounine #define RIO_WAIT_FOR_ASYNC \
2724e1016daSAlexandre Bounine 	_IOW(RIO_MPORT_DRV_MAGIC, 22, struct rio_async_tx_wait)
2734e1016daSAlexandre Bounine #define RIO_DEV_ADD \
2744e1016daSAlexandre Bounine 	_IOW(RIO_MPORT_DRV_MAGIC, 23, struct rio_rdev_info)
2754e1016daSAlexandre Bounine #define RIO_DEV_DEL \
2764e1016daSAlexandre Bounine 	_IOW(RIO_MPORT_DRV_MAGIC, 24, struct rio_rdev_info)
2774e1016daSAlexandre Bounine 
2784e1016daSAlexandre Bounine #endif /* _RIO_MPORT_CDEV_H_ */
279