1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
  2/*
  3 * Management Component Transport Protocol (MCTP)
  4 *
  5 * Copyright (c) 2021 Code Construct
  6 * Copyright (c) 2021 Google
  7 */
  8
  9#ifndef __UAPI_MCTP_H
 10#define __UAPI_MCTP_H
 11
 12#include <linux/types.h>
 13#include <linux/socket.h>
 14#include <linux/netdevice.h>
 15
 16typedef __u8			mctp_eid_t;
 17
 18struct mctp_addr {
 19	mctp_eid_t		s_addr;
 20};
 21
 22struct sockaddr_mctp {
 23	__kernel_sa_family_t	smctp_family;
 24	__u16			__smctp_pad0;
 25	unsigned int		smctp_network;
 26	struct mctp_addr	smctp_addr;
 27	__u8			smctp_type;
 28	__u8			smctp_tag;
 29	__u8			__smctp_pad1;
 30};
 31
 32struct sockaddr_mctp_ext {
 33	struct sockaddr_mctp	smctp_base;
 34	int			smctp_ifindex;
 35	__u8			smctp_halen;
 36	__u8			__smctp_pad0[3];
 37	__u8			smctp_haddr[MAX_ADDR_LEN];
 38};
 39
 40/* A "fully qualified" MCTP address, which includes the system-local network ID,
 41 * required to uniquely resolve a routable EID.
 42 */
 43struct mctp_fq_addr {
 44	unsigned int	net;
 45	mctp_eid_t	eid;
 46};
 47
 48#define MCTP_NET_ANY		0x0
 49
 50#define MCTP_ADDR_NULL		0x00
 51#define MCTP_ADDR_ANY		0xff
 52
 53#define MCTP_TAG_MASK		0x07
 54#define MCTP_TAG_OWNER		0x08
 55#define MCTP_TAG_PREALLOC	0x10
 56
 57#define MCTP_OPT_ADDR_EXT	1
 58
 59#define SIOCMCTPALLOCTAG	(SIOCPROTOPRIVATE + 0)
 60#define SIOCMCTPDROPTAG		(SIOCPROTOPRIVATE + 1)
 61#define SIOCMCTPALLOCTAG2	(SIOCPROTOPRIVATE + 2)
 62#define SIOCMCTPDROPTAG2	(SIOCPROTOPRIVATE + 3)
 63
 64/* Deprecated: use mctp_ioc_tag_ctl2 / TAG2 ioctls instead, which defines the
 65 * MCTP network ID as part of the allocated tag. Using this assumes the default
 66 * net ID for allocated tags, which may not give correct behaviour on system
 67 * with multiple networks configured.
 68 */
 69struct mctp_ioc_tag_ctl {
 70	mctp_eid_t	peer_addr;
 71
 72	/* For SIOCMCTPALLOCTAG: must be passed as zero, kernel will
 73	 * populate with the allocated tag value. Returned tag value will
 74	 * always have TO and PREALLOC set.
 75	 *
 76	 * For SIOCMCTPDROPTAG: userspace provides tag value to drop, from
 77	 * a prior SIOCMCTPALLOCTAG call (and so must have TO and PREALLOC set).
 78	 */
 79	__u8		tag;
 80	__u16		flags;
 81};
 82
 83struct mctp_ioc_tag_ctl2 {
 84	/* Peer details: network ID, peer EID, local EID. All set by the
 85	 * caller.
 86	 *
 87	 * Local EID must be MCTP_ADDR_NULL or MCTP_ADDR_ANY in current
 88	 * kernels.
 89	 */
 90	unsigned int	net;
 91	mctp_eid_t	peer_addr;
 92	mctp_eid_t	local_addr;
 93
 94	/* Set by caller, but no flags defined currently. Must be 0 */
 95	__u16		flags;
 96
 97	/* For SIOCMCTPALLOCTAG2: must be passed as zero, kernel will
 98	 * populate with the allocated tag value. Returned tag value will
 99	 * always have TO and PREALLOC set.
100	 *
101	 * For SIOCMCTPDROPTAG2: userspace provides tag value to drop, from
102	 * a prior SIOCMCTPALLOCTAG2 call (and so must have TO and PREALLOC set).
103	 */
104	__u8		tag;
105
106};
107
108#endif /* __UAPI_MCTP_H */