1*40688bd5SNishad Kamdar /* SPDX-License-Identifier: GPL-2.0+ */ 2*40688bd5SNishad Kamdar /* 30eca353eSBryant G. Ly * linux/drivers/misc/ibmvmc.h 40eca353eSBryant G. Ly * 50eca353eSBryant G. Ly * IBM Power Systems Virtual Management Channel Support. 60eca353eSBryant G. Ly * 70eca353eSBryant G. Ly * Copyright (c) 2004, 2018 IBM Corp. 80eca353eSBryant G. Ly * Dave Engebretsen engebret@us.ibm.com 90eca353eSBryant G. Ly * Steven Royer seroyer@linux.vnet.ibm.com 100eca353eSBryant G. Ly * Adam Reznechek adreznec@linux.vnet.ibm.com 110eca353eSBryant G. Ly * Bryant G. Ly <bryantly@linux.vnet.ibm.com> 120eca353eSBryant G. Ly */ 130eca353eSBryant G. Ly #ifndef IBMVMC_H 140eca353eSBryant G. Ly #define IBMVMC_H 150eca353eSBryant G. Ly 160eca353eSBryant G. Ly #include <linux/types.h> 170eca353eSBryant G. Ly #include <linux/cdev.h> 180eca353eSBryant G. Ly 190eca353eSBryant G. Ly #include <asm/vio.h> 200eca353eSBryant G. Ly 210eca353eSBryant G. Ly #define IBMVMC_PROTOCOL_VERSION 0x0101 220eca353eSBryant G. Ly 230eca353eSBryant G. Ly #define MIN_BUF_POOL_SIZE 16 240eca353eSBryant G. Ly #define MIN_HMCS 1 250eca353eSBryant G. Ly #define MIN_MTU 4096 260eca353eSBryant G. Ly #define MAX_BUF_POOL_SIZE 64 270eca353eSBryant G. Ly #define MAX_HMCS 2 280eca353eSBryant G. Ly #define MAX_MTU (4 * 4096) 290eca353eSBryant G. Ly #define DEFAULT_BUF_POOL_SIZE 32 300eca353eSBryant G. Ly #define DEFAULT_HMCS 1 310eca353eSBryant G. Ly #define DEFAULT_MTU 4096 320eca353eSBryant G. Ly #define HMC_ID_LEN 32 330eca353eSBryant G. Ly 340eca353eSBryant G. Ly #define VMC_INVALID_BUFFER_ID 0xFFFF 350eca353eSBryant G. Ly 360eca353eSBryant G. Ly /* ioctl numbers */ 370eca353eSBryant G. Ly #define VMC_BASE 0xCC 380eca353eSBryant G. Ly #define VMC_IOCTL_SETHMCID _IOW(VMC_BASE, 0x00, unsigned char *) 390eca353eSBryant G. Ly #define VMC_IOCTL_QUERY _IOR(VMC_BASE, 0x01, struct ibmvmc_query_struct) 400eca353eSBryant G. Ly #define VMC_IOCTL_REQUESTVMC _IOR(VMC_BASE, 0x02, u32) 410eca353eSBryant G. Ly 420eca353eSBryant G. Ly #define VMC_MSG_CAP 0x01 430eca353eSBryant G. Ly #define VMC_MSG_CAP_RESP 0x81 440eca353eSBryant G. Ly #define VMC_MSG_OPEN 0x02 450eca353eSBryant G. Ly #define VMC_MSG_OPEN_RESP 0x82 460eca353eSBryant G. Ly #define VMC_MSG_CLOSE 0x03 470eca353eSBryant G. Ly #define VMC_MSG_CLOSE_RESP 0x83 480eca353eSBryant G. Ly #define VMC_MSG_ADD_BUF 0x04 490eca353eSBryant G. Ly #define VMC_MSG_ADD_BUF_RESP 0x84 500eca353eSBryant G. Ly #define VMC_MSG_REM_BUF 0x05 510eca353eSBryant G. Ly #define VMC_MSG_REM_BUF_RESP 0x85 520eca353eSBryant G. Ly #define VMC_MSG_SIGNAL 0x06 530eca353eSBryant G. Ly 540eca353eSBryant G. Ly #define VMC_MSG_SUCCESS 0 550eca353eSBryant G. Ly #define VMC_MSG_INVALID_HMC_INDEX 1 560eca353eSBryant G. Ly #define VMC_MSG_INVALID_BUFFER_ID 2 570eca353eSBryant G. Ly #define VMC_MSG_CLOSED_HMC 3 580eca353eSBryant G. Ly #define VMC_MSG_INTERFACE_FAILURE 4 590eca353eSBryant G. Ly #define VMC_MSG_NO_BUFFER 5 600eca353eSBryant G. Ly 610eca353eSBryant G. Ly #define VMC_BUF_OWNER_ALPHA 0 620eca353eSBryant G. Ly #define VMC_BUF_OWNER_HV 1 630eca353eSBryant G. Ly 640eca353eSBryant G. Ly enum ibmvmc_states { 650eca353eSBryant G. Ly ibmvmc_state_sched_reset = -1, 660eca353eSBryant G. Ly ibmvmc_state_initial = 0, 670eca353eSBryant G. Ly ibmvmc_state_crqinit = 1, 680eca353eSBryant G. Ly ibmvmc_state_capabilities = 2, 690eca353eSBryant G. Ly ibmvmc_state_ready = 3, 700eca353eSBryant G. Ly ibmvmc_state_failed = 4, 710eca353eSBryant G. Ly }; 720eca353eSBryant G. Ly 730eca353eSBryant G. Ly enum ibmhmc_states { 740eca353eSBryant G. Ly /* HMC connection not established */ 750eca353eSBryant G. Ly ibmhmc_state_free = 0, 760eca353eSBryant G. Ly 770eca353eSBryant G. Ly /* HMC connection established (open called) */ 780eca353eSBryant G. Ly ibmhmc_state_initial = 1, 790eca353eSBryant G. Ly 800eca353eSBryant G. Ly /* open msg sent to HV, due to ioctl(1) call */ 810eca353eSBryant G. Ly ibmhmc_state_opening = 2, 820eca353eSBryant G. Ly 830eca353eSBryant G. Ly /* HMC connection ready, open resp msg from HV */ 840eca353eSBryant G. Ly ibmhmc_state_ready = 3, 850eca353eSBryant G. Ly 860eca353eSBryant G. Ly /* HMC connection failure */ 870eca353eSBryant G. Ly ibmhmc_state_failed = 4, 880eca353eSBryant G. Ly }; 890eca353eSBryant G. Ly 900eca353eSBryant G. Ly struct ibmvmc_buffer { 910eca353eSBryant G. Ly u8 valid; /* 1 when DMA storage allocated to buffer */ 920eca353eSBryant G. Ly u8 free; /* 1 when buffer available for the Alpha Partition */ 930eca353eSBryant G. Ly u8 owner; 940eca353eSBryant G. Ly u16 id; 950eca353eSBryant G. Ly u32 size; 960eca353eSBryant G. Ly u32 msg_len; 970eca353eSBryant G. Ly dma_addr_t dma_addr_local; 980eca353eSBryant G. Ly dma_addr_t dma_addr_remote; 990eca353eSBryant G. Ly void *real_addr_local; 1000eca353eSBryant G. Ly }; 1010eca353eSBryant G. Ly 1020eca353eSBryant G. Ly struct ibmvmc_admin_crq_msg { 1030eca353eSBryant G. Ly u8 valid; /* RPA Defined */ 1040eca353eSBryant G. Ly u8 type; /* ibmvmc msg type */ 1050eca353eSBryant G. Ly u8 status; /* Response msg status. Zero is success and on failure, 1060eca353eSBryant G. Ly * either 1 - General Failure, or 2 - Invalid Version is 1070eca353eSBryant G. Ly * returned. 1080eca353eSBryant G. Ly */ 1090eca353eSBryant G. Ly u8 rsvd[2]; 1100eca353eSBryant G. Ly u8 max_hmc; /* Max # of independent HMC connections supported */ 1110eca353eSBryant G. Ly __be16 pool_size; /* Maximum number of buffers supported per HMC 1120eca353eSBryant G. Ly * connection 1130eca353eSBryant G. Ly */ 1140eca353eSBryant G. Ly __be32 max_mtu; /* Maximum message size supported (bytes) */ 1150eca353eSBryant G. Ly __be16 crq_size; /* # of entries available in the CRQ for the 1160eca353eSBryant G. Ly * source partition. The target partition must 1170eca353eSBryant G. Ly * limit the number of outstanding messages to 1180eca353eSBryant G. Ly * one half or less. 1190eca353eSBryant G. Ly */ 1200eca353eSBryant G. Ly __be16 version; /* Indicates the code level of the management partition 1210eca353eSBryant G. Ly * or the hypervisor with the high-order byte 1220eca353eSBryant G. Ly * indicating a major version and the low-order byte 1230eca353eSBryant G. Ly * indicating a minor version. 1240eca353eSBryant G. Ly */ 1250eca353eSBryant G. Ly }; 1260eca353eSBryant G. Ly 1270eca353eSBryant G. Ly struct ibmvmc_crq_msg { 1280eca353eSBryant G. Ly u8 valid; /* RPA Defined */ 1290eca353eSBryant G. Ly u8 type; /* ibmvmc msg type */ 1300eca353eSBryant G. Ly u8 status; /* Response msg status */ 1310eca353eSBryant G. Ly union { 1320eca353eSBryant G. Ly u8 rsvd; /* Reserved */ 1330eca353eSBryant G. Ly u8 owner; 1340eca353eSBryant G. Ly } var1; 1350eca353eSBryant G. Ly u8 hmc_session; /* Session Identifier for the current VMC connection */ 1360eca353eSBryant G. Ly u8 hmc_index; /* A unique HMC Idx would be used if multiple management 1370eca353eSBryant G. Ly * applications running concurrently were desired 1380eca353eSBryant G. Ly */ 1390eca353eSBryant G. Ly union { 1400eca353eSBryant G. Ly __be16 rsvd; 1410eca353eSBryant G. Ly __be16 buffer_id; 1420eca353eSBryant G. Ly } var2; 1430eca353eSBryant G. Ly __be32 rsvd; 1440eca353eSBryant G. Ly union { 1450eca353eSBryant G. Ly __be32 rsvd; 1460eca353eSBryant G. Ly __be32 lioba; 1470eca353eSBryant G. Ly __be32 msg_len; 1480eca353eSBryant G. Ly } var3; 1490eca353eSBryant G. Ly }; 1500eca353eSBryant G. Ly 1510eca353eSBryant G. Ly /* an RPA command/response transport queue */ 1520eca353eSBryant G. Ly struct crq_queue { 1530eca353eSBryant G. Ly struct ibmvmc_crq_msg *msgs; 1540eca353eSBryant G. Ly int size, cur; 1550eca353eSBryant G. Ly dma_addr_t msg_token; 1560eca353eSBryant G. Ly spinlock_t lock; 1570eca353eSBryant G. Ly }; 1580eca353eSBryant G. Ly 1590eca353eSBryant G. Ly /* VMC server adapter settings */ 1600eca353eSBryant G. Ly struct crq_server_adapter { 1610eca353eSBryant G. Ly struct device *dev; 1620eca353eSBryant G. Ly struct crq_queue queue; 1630eca353eSBryant G. Ly u32 liobn; 1640eca353eSBryant G. Ly u32 riobn; 1650eca353eSBryant G. Ly struct tasklet_struct work_task; 1660eca353eSBryant G. Ly wait_queue_head_t reset_wait_queue; 1670eca353eSBryant G. Ly struct task_struct *reset_task; 1680eca353eSBryant G. Ly }; 1690eca353eSBryant G. Ly 1700eca353eSBryant G. Ly /* Driver wide settings */ 1710eca353eSBryant G. Ly struct ibmvmc_struct { 1720eca353eSBryant G. Ly u32 state; 1730eca353eSBryant G. Ly u32 max_mtu; 1740eca353eSBryant G. Ly u32 max_buffer_pool_size; 1750eca353eSBryant G. Ly u32 max_hmc_index; 1760eca353eSBryant G. Ly struct crq_server_adapter *adapter; 1770eca353eSBryant G. Ly struct cdev cdev; 1780eca353eSBryant G. Ly u32 vmc_drc_index; 1790eca353eSBryant G. Ly }; 1800eca353eSBryant G. Ly 1810eca353eSBryant G. Ly struct ibmvmc_file_session; 1820eca353eSBryant G. Ly 1830eca353eSBryant G. Ly /* Connection specific settings */ 1840eca353eSBryant G. Ly struct ibmvmc_hmc { 1850eca353eSBryant G. Ly u8 session; 1860eca353eSBryant G. Ly u8 index; 1870eca353eSBryant G. Ly u32 state; 1880eca353eSBryant G. Ly struct crq_server_adapter *adapter; 1890eca353eSBryant G. Ly spinlock_t lock; 1900eca353eSBryant G. Ly unsigned char hmc_id[HMC_ID_LEN]; 1910eca353eSBryant G. Ly struct ibmvmc_buffer buffer[MAX_BUF_POOL_SIZE]; 1920eca353eSBryant G. Ly unsigned short queue_outbound_msgs[MAX_BUF_POOL_SIZE]; 1930eca353eSBryant G. Ly int queue_head, queue_tail; 1940eca353eSBryant G. Ly struct ibmvmc_file_session *file_session; 1950eca353eSBryant G. Ly }; 1960eca353eSBryant G. Ly 1970eca353eSBryant G. Ly struct ibmvmc_file_session { 1980eca353eSBryant G. Ly struct file *file; 1990eca353eSBryant G. Ly struct ibmvmc_hmc *hmc; 2000eca353eSBryant G. Ly bool valid; 2010eca353eSBryant G. Ly }; 2020eca353eSBryant G. Ly 2030eca353eSBryant G. Ly struct ibmvmc_query_struct { 2040eca353eSBryant G. Ly int have_vmc; 2050eca353eSBryant G. Ly int state; 2060eca353eSBryant G. Ly int vmc_drc_index; 2070eca353eSBryant G. Ly }; 2080eca353eSBryant G. Ly 2090eca353eSBryant G. Ly #endif /* __IBMVMC_H */ 210