18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0+ */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * linux/drivers/misc/ibmvmc.h
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * IBM Power Systems Virtual Management Channel Support.
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Copyright (c) 2004, 2018 IBM Corp.
88c2ecf20Sopenharmony_ci *   Dave Engebretsen engebret@us.ibm.com
98c2ecf20Sopenharmony_ci *   Steven Royer seroyer@linux.vnet.ibm.com
108c2ecf20Sopenharmony_ci *   Adam Reznechek adreznec@linux.vnet.ibm.com
118c2ecf20Sopenharmony_ci *   Bryant G. Ly <bryantly@linux.vnet.ibm.com>
128c2ecf20Sopenharmony_ci */
138c2ecf20Sopenharmony_ci#ifndef IBMVMC_H
148c2ecf20Sopenharmony_ci#define IBMVMC_H
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci#include <linux/types.h>
178c2ecf20Sopenharmony_ci#include <linux/cdev.h>
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci#include <asm/vio.h>
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#define IBMVMC_PROTOCOL_VERSION    0x0101
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci#define MIN_BUF_POOL_SIZE 16
248c2ecf20Sopenharmony_ci#define MIN_HMCS          1
258c2ecf20Sopenharmony_ci#define MIN_MTU           4096
268c2ecf20Sopenharmony_ci#define MAX_BUF_POOL_SIZE 64
278c2ecf20Sopenharmony_ci#define MAX_HMCS          2
288c2ecf20Sopenharmony_ci#define MAX_MTU           (4 * 4096)
298c2ecf20Sopenharmony_ci#define DEFAULT_BUF_POOL_SIZE 32
308c2ecf20Sopenharmony_ci#define DEFAULT_HMCS          1
318c2ecf20Sopenharmony_ci#define DEFAULT_MTU           4096
328c2ecf20Sopenharmony_ci#define HMC_ID_LEN        32
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci#define VMC_INVALID_BUFFER_ID 0xFFFF
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci/* ioctl numbers */
378c2ecf20Sopenharmony_ci#define VMC_BASE	     0xCC
388c2ecf20Sopenharmony_ci#define VMC_IOCTL_SETHMCID   _IOW(VMC_BASE, 0x00, unsigned char *)
398c2ecf20Sopenharmony_ci#define VMC_IOCTL_QUERY      _IOR(VMC_BASE, 0x01, struct ibmvmc_query_struct)
408c2ecf20Sopenharmony_ci#define VMC_IOCTL_REQUESTVMC _IOR(VMC_BASE, 0x02, u32)
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci#define VMC_MSG_CAP          0x01
438c2ecf20Sopenharmony_ci#define VMC_MSG_CAP_RESP     0x81
448c2ecf20Sopenharmony_ci#define VMC_MSG_OPEN         0x02
458c2ecf20Sopenharmony_ci#define VMC_MSG_OPEN_RESP    0x82
468c2ecf20Sopenharmony_ci#define VMC_MSG_CLOSE        0x03
478c2ecf20Sopenharmony_ci#define VMC_MSG_CLOSE_RESP   0x83
488c2ecf20Sopenharmony_ci#define VMC_MSG_ADD_BUF      0x04
498c2ecf20Sopenharmony_ci#define VMC_MSG_ADD_BUF_RESP 0x84
508c2ecf20Sopenharmony_ci#define VMC_MSG_REM_BUF      0x05
518c2ecf20Sopenharmony_ci#define VMC_MSG_REM_BUF_RESP 0x85
528c2ecf20Sopenharmony_ci#define VMC_MSG_SIGNAL       0x06
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci#define VMC_MSG_SUCCESS 0
558c2ecf20Sopenharmony_ci#define VMC_MSG_INVALID_HMC_INDEX 1
568c2ecf20Sopenharmony_ci#define VMC_MSG_INVALID_BUFFER_ID 2
578c2ecf20Sopenharmony_ci#define VMC_MSG_CLOSED_HMC        3
588c2ecf20Sopenharmony_ci#define VMC_MSG_INTERFACE_FAILURE 4
598c2ecf20Sopenharmony_ci#define VMC_MSG_NO_BUFFER         5
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci#define VMC_BUF_OWNER_ALPHA 0
628c2ecf20Sopenharmony_ci#define VMC_BUF_OWNER_HV    1
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_cienum ibmvmc_states {
658c2ecf20Sopenharmony_ci	ibmvmc_state_sched_reset  = -1,
668c2ecf20Sopenharmony_ci	ibmvmc_state_initial      = 0,
678c2ecf20Sopenharmony_ci	ibmvmc_state_crqinit      = 1,
688c2ecf20Sopenharmony_ci	ibmvmc_state_capabilities = 2,
698c2ecf20Sopenharmony_ci	ibmvmc_state_ready        = 3,
708c2ecf20Sopenharmony_ci	ibmvmc_state_failed       = 4,
718c2ecf20Sopenharmony_ci};
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_cienum ibmhmc_states {
748c2ecf20Sopenharmony_ci	/* HMC connection not established */
758c2ecf20Sopenharmony_ci	ibmhmc_state_free    = 0,
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci	/* HMC connection established (open called) */
788c2ecf20Sopenharmony_ci	ibmhmc_state_initial = 1,
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ci	/* open msg sent to HV, due to ioctl(1) call */
818c2ecf20Sopenharmony_ci	ibmhmc_state_opening = 2,
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci	/* HMC connection ready, open resp msg from HV */
848c2ecf20Sopenharmony_ci	ibmhmc_state_ready   = 3,
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci	/* HMC connection failure */
878c2ecf20Sopenharmony_ci	ibmhmc_state_failed  = 4,
888c2ecf20Sopenharmony_ci};
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_cistruct ibmvmc_buffer {
918c2ecf20Sopenharmony_ci	u8 valid;	/* 1 when DMA storage allocated to buffer          */
928c2ecf20Sopenharmony_ci	u8 free;	/* 1 when buffer available for the Alpha Partition */
938c2ecf20Sopenharmony_ci	u8 owner;
948c2ecf20Sopenharmony_ci	u16 id;
958c2ecf20Sopenharmony_ci	u32 size;
968c2ecf20Sopenharmony_ci	u32 msg_len;
978c2ecf20Sopenharmony_ci	dma_addr_t dma_addr_local;
988c2ecf20Sopenharmony_ci	dma_addr_t dma_addr_remote;
998c2ecf20Sopenharmony_ci	void *real_addr_local;
1008c2ecf20Sopenharmony_ci};
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_cistruct ibmvmc_admin_crq_msg {
1038c2ecf20Sopenharmony_ci	u8 valid;	/* RPA Defined           */
1048c2ecf20Sopenharmony_ci	u8 type;	/* ibmvmc msg type       */
1058c2ecf20Sopenharmony_ci	u8 status;	/* Response msg status. Zero is success and on failure,
1068c2ecf20Sopenharmony_ci			 * either 1 - General Failure, or 2 - Invalid Version is
1078c2ecf20Sopenharmony_ci			 * returned.
1088c2ecf20Sopenharmony_ci			 */
1098c2ecf20Sopenharmony_ci	u8 rsvd[2];
1108c2ecf20Sopenharmony_ci	u8 max_hmc;	/* Max # of independent HMC connections supported */
1118c2ecf20Sopenharmony_ci	__be16 pool_size;	/* Maximum number of buffers supported per HMC
1128c2ecf20Sopenharmony_ci				 * connection
1138c2ecf20Sopenharmony_ci				 */
1148c2ecf20Sopenharmony_ci	__be32 max_mtu;		/* Maximum message size supported (bytes) */
1158c2ecf20Sopenharmony_ci	__be16 crq_size;	/* # of entries available in the CRQ for the
1168c2ecf20Sopenharmony_ci				 * source partition. The target partition must
1178c2ecf20Sopenharmony_ci				 * limit the number of outstanding messages to
1188c2ecf20Sopenharmony_ci				 * one half or less.
1198c2ecf20Sopenharmony_ci				 */
1208c2ecf20Sopenharmony_ci	__be16 version;	/* Indicates the code level of the management partition
1218c2ecf20Sopenharmony_ci			 * or the hypervisor with the high-order byte
1228c2ecf20Sopenharmony_ci			 * indicating a major version and the low-order byte
1238c2ecf20Sopenharmony_ci			 * indicating a minor version.
1248c2ecf20Sopenharmony_ci			 */
1258c2ecf20Sopenharmony_ci};
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_cistruct ibmvmc_crq_msg {
1288c2ecf20Sopenharmony_ci	u8 valid;     /* RPA Defined           */
1298c2ecf20Sopenharmony_ci	u8 type;      /* ibmvmc msg type       */
1308c2ecf20Sopenharmony_ci	u8 status;    /* Response msg status   */
1318c2ecf20Sopenharmony_ci	union {
1328c2ecf20Sopenharmony_ci		u8 rsvd;  /* Reserved              */
1338c2ecf20Sopenharmony_ci		u8 owner;
1348c2ecf20Sopenharmony_ci	} var1;
1358c2ecf20Sopenharmony_ci	u8 hmc_session;	/* Session Identifier for the current VMC connection */
1368c2ecf20Sopenharmony_ci	u8 hmc_index;	/* A unique HMC Idx would be used if multiple management
1378c2ecf20Sopenharmony_ci			 * applications running concurrently were desired
1388c2ecf20Sopenharmony_ci			 */
1398c2ecf20Sopenharmony_ci	union {
1408c2ecf20Sopenharmony_ci		__be16 rsvd;
1418c2ecf20Sopenharmony_ci		__be16 buffer_id;
1428c2ecf20Sopenharmony_ci	} var2;
1438c2ecf20Sopenharmony_ci	__be32 rsvd;
1448c2ecf20Sopenharmony_ci	union {
1458c2ecf20Sopenharmony_ci		__be32 rsvd;
1468c2ecf20Sopenharmony_ci		__be32 lioba;
1478c2ecf20Sopenharmony_ci		__be32 msg_len;
1488c2ecf20Sopenharmony_ci	} var3;
1498c2ecf20Sopenharmony_ci};
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_ci/* an RPA command/response transport queue */
1528c2ecf20Sopenharmony_cistruct crq_queue {
1538c2ecf20Sopenharmony_ci	struct ibmvmc_crq_msg *msgs;
1548c2ecf20Sopenharmony_ci	int size, cur;
1558c2ecf20Sopenharmony_ci	dma_addr_t msg_token;
1568c2ecf20Sopenharmony_ci	spinlock_t lock;
1578c2ecf20Sopenharmony_ci};
1588c2ecf20Sopenharmony_ci
1598c2ecf20Sopenharmony_ci/* VMC server adapter settings */
1608c2ecf20Sopenharmony_cistruct crq_server_adapter {
1618c2ecf20Sopenharmony_ci	struct device *dev;
1628c2ecf20Sopenharmony_ci	struct crq_queue queue;
1638c2ecf20Sopenharmony_ci	u32 liobn;
1648c2ecf20Sopenharmony_ci	u32 riobn;
1658c2ecf20Sopenharmony_ci	struct tasklet_struct work_task;
1668c2ecf20Sopenharmony_ci	wait_queue_head_t reset_wait_queue;
1678c2ecf20Sopenharmony_ci	struct task_struct *reset_task;
1688c2ecf20Sopenharmony_ci};
1698c2ecf20Sopenharmony_ci
1708c2ecf20Sopenharmony_ci/* Driver wide settings */
1718c2ecf20Sopenharmony_cistruct ibmvmc_struct {
1728c2ecf20Sopenharmony_ci	u32 state;
1738c2ecf20Sopenharmony_ci	u32 max_mtu;
1748c2ecf20Sopenharmony_ci	u32 max_buffer_pool_size;
1758c2ecf20Sopenharmony_ci	u32 max_hmc_index;
1768c2ecf20Sopenharmony_ci	struct crq_server_adapter *adapter;
1778c2ecf20Sopenharmony_ci	struct cdev cdev;
1788c2ecf20Sopenharmony_ci	u32 vmc_drc_index;
1798c2ecf20Sopenharmony_ci};
1808c2ecf20Sopenharmony_ci
1818c2ecf20Sopenharmony_cistruct ibmvmc_file_session;
1828c2ecf20Sopenharmony_ci
1838c2ecf20Sopenharmony_ci/* Connection specific settings */
1848c2ecf20Sopenharmony_cistruct ibmvmc_hmc {
1858c2ecf20Sopenharmony_ci	u8 session;
1868c2ecf20Sopenharmony_ci	u8 index;
1878c2ecf20Sopenharmony_ci	u32 state;
1888c2ecf20Sopenharmony_ci	struct crq_server_adapter *adapter;
1898c2ecf20Sopenharmony_ci	spinlock_t lock;
1908c2ecf20Sopenharmony_ci	unsigned char hmc_id[HMC_ID_LEN];
1918c2ecf20Sopenharmony_ci	struct ibmvmc_buffer buffer[MAX_BUF_POOL_SIZE];
1928c2ecf20Sopenharmony_ci	unsigned short queue_outbound_msgs[MAX_BUF_POOL_SIZE];
1938c2ecf20Sopenharmony_ci	int queue_head, queue_tail;
1948c2ecf20Sopenharmony_ci	struct ibmvmc_file_session *file_session;
1958c2ecf20Sopenharmony_ci};
1968c2ecf20Sopenharmony_ci
1978c2ecf20Sopenharmony_cistruct ibmvmc_file_session {
1988c2ecf20Sopenharmony_ci	struct file *file;
1998c2ecf20Sopenharmony_ci	struct ibmvmc_hmc *hmc;
2008c2ecf20Sopenharmony_ci	bool valid;
2018c2ecf20Sopenharmony_ci};
2028c2ecf20Sopenharmony_ci
2038c2ecf20Sopenharmony_cistruct ibmvmc_query_struct {
2048c2ecf20Sopenharmony_ci	int have_vmc;
2058c2ecf20Sopenharmony_ci	int state;
2068c2ecf20Sopenharmony_ci	int vmc_drc_index;
2078c2ecf20Sopenharmony_ci};
2088c2ecf20Sopenharmony_ci
2098c2ecf20Sopenharmony_ci#endif /* __IBMVMC_H */
210