Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /* SPDX-License-Identifier: GPL-2.0+ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Copyright IBM Corp. 2006, 2019
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Author(s): Cornelia Huck <cornelia.huck@de.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *	      Martin Schwidefsky <schwidefsky@de.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *	      Ralph Wuerthner <rwuerthn@de.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *	      Felix Beck <felix.beck@de.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *	      Holger Dengler <hd@linux.vnet.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * Adjunct processor bus header file.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #ifndef _AP_BUS_H_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #define _AP_BUS_H_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/hashtable.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <asm/isc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <asm/ap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #define AP_DEVICES 256		/* Number of AP devices. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #define AP_DOMAINS 256		/* Number of AP domains. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #define AP_IOCTLS  256		/* Number of ioctls. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #define AP_RESET_TIMEOUT (HZ*0.7)	/* Time in ticks for reset timeouts. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #define AP_CONFIG_TIME 30	/* Time in seconds between AP bus rescans. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #define AP_POLL_TIME 1		/* Time in ticks between receive polls. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) extern int ap_domain_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) extern DECLARE_HASHTABLE(ap_queues, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) extern spinlock_t ap_queues_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) static inline int ap_test_bit(unsigned int *ptr, unsigned int nr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	return (*ptr & (0x80000000u >> nr)) != 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #define AP_RESPONSE_NORMAL		0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #define AP_RESPONSE_Q_NOT_AVAIL		0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #define AP_RESPONSE_RESET_IN_PROGRESS	0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #define AP_RESPONSE_DECONFIGURED	0x03
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #define AP_RESPONSE_CHECKSTOPPED	0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #define AP_RESPONSE_BUSY		0x05
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) #define AP_RESPONSE_INVALID_ADDRESS	0x06
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) #define AP_RESPONSE_OTHERWISE_CHANGED	0x07
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) #define AP_RESPONSE_Q_FULL		0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) #define AP_RESPONSE_NO_PENDING_REPLY	0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) #define AP_RESPONSE_INDEX_TOO_BIG	0x11
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) #define AP_RESPONSE_NO_FIRST_PART	0x13
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) #define AP_RESPONSE_MESSAGE_TOO_BIG	0x15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) #define AP_RESPONSE_REQ_FAC_NOT_INST	0x16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) #define AP_RESPONSE_INVALID_DOMAIN	0x42
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56)  * Known device types
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) #define AP_DEVICE_TYPE_PCICC	3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) #define AP_DEVICE_TYPE_PCICA	4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) #define AP_DEVICE_TYPE_PCIXCC	5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) #define AP_DEVICE_TYPE_CEX2A	6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) #define AP_DEVICE_TYPE_CEX2C	7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) #define AP_DEVICE_TYPE_CEX3A	8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) #define AP_DEVICE_TYPE_CEX3C	9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) #define AP_DEVICE_TYPE_CEX4	10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) #define AP_DEVICE_TYPE_CEX5	11
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) #define AP_DEVICE_TYPE_CEX6	12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) #define AP_DEVICE_TYPE_CEX7	13
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71)  * Known function facilities
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) #define AP_FUNC_MEX4K 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) #define AP_FUNC_CRT4K 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) #define AP_FUNC_COPRO 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) #define AP_FUNC_ACCEL 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) #define AP_FUNC_EP11  5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) #define AP_FUNC_APXA  6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81)  * AP queue state machine states
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) enum ap_sm_state {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	AP_SM_STATE_RESET_START = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	AP_SM_STATE_RESET_WAIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	AP_SM_STATE_SETIRQ_WAIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	AP_SM_STATE_IDLE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	AP_SM_STATE_WORKING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	AP_SM_STATE_QUEUE_FULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	NR_AP_SM_STATES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94)  * AP queue state machine events
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) enum ap_sm_event {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	AP_SM_EVENT_POLL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	AP_SM_EVENT_TIMEOUT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	NR_AP_SM_EVENTS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)  * AP queue state wait behaviour
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) enum ap_sm_wait {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	AP_SM_WAIT_AGAIN = 0,	/* retry immediately */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	AP_SM_WAIT_TIMEOUT,	/* wait for timeout */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	AP_SM_WAIT_INTERRUPT,	/* wait for thin interrupt (if available) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	AP_SM_WAIT_NONE,	/* no wait */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	NR_AP_SM_WAIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)  * AP queue device states
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) enum ap_dev_state {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	AP_DEV_STATE_UNINITIATED = 0,	/* fresh and virgin, not touched */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	AP_DEV_STATE_OPERATING,		/* queue dev is working normal */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	AP_DEV_STATE_SHUTDOWN,		/* remove/unbind/shutdown in progress */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	AP_DEV_STATE_ERROR,		/* device is in error state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	NR_AP_DEV_STATES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) struct ap_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) struct ap_message;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)  * The ap driver struct includes a flags field which holds some info for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)  * the ap bus about the driver. Currently only one flag is supported and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)  * used: The DEFAULT flag marks an ap driver as a default driver which is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)  * used together with the apmask and aqmask whitelisting of the ap bus.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) #define AP_DRIVER_FLAG_DEFAULT 0x0001
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) struct ap_driver {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	struct device_driver driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	struct ap_device_id *ids;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	unsigned int flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	int (*probe)(struct ap_device *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	void (*remove)(struct ap_device *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) #define to_ap_drv(x) container_of((x), struct ap_driver, driver)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) int ap_driver_register(struct ap_driver *, struct module *, char *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) void ap_driver_unregister(struct ap_driver *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) struct ap_device {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	struct device device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	struct ap_driver *drv;		/* Pointer to AP device driver. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	int device_type;		/* AP device type. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) #define to_ap_dev(x) container_of((x), struct ap_device, device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) struct ap_card {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	struct ap_device ap_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	void *private;			/* ap driver private pointer. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	int raw_hwtype;			/* AP raw hardware type. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	unsigned int functions;		/* AP device function bitfield. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	int queue_depth;		/* AP queue depth.*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	int id;				/* AP card number. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	bool config;			/* configured state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	atomic64_t total_request_count;	/* # requests ever for this AP device.*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) #define to_ap_card(x) container_of((x), struct ap_card, ap_dev.device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) struct ap_queue {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	struct ap_device ap_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	struct hlist_node hnode;	/* Node for the ap_queues hashtable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	struct ap_card *card;		/* Ptr to assoc. AP card. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	spinlock_t lock;		/* Per device lock. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	void *private;			/* ap driver private pointer. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	enum ap_dev_state dev_state;	/* queue device state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	bool config;			/* configured state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	ap_qid_t qid;			/* AP queue id. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	bool interrupt;			/* indicate if interrupts are enabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	int queue_count;		/* # messages currently on AP queue. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	int pendingq_count;		/* # requests on pendingq list. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	int requestq_count;		/* # requests on requestq list. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	u64 total_request_count;	/* # requests ever for this AP device.*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	int request_timeout;		/* Request timeout in jiffies. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	struct timer_list timeout;	/* Timer for request timeouts. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	struct list_head pendingq;	/* List of message sent to AP queue. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	struct list_head requestq;	/* List of message yet to be sent. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	struct ap_message *reply;	/* Per device reply message. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	enum ap_sm_state sm_state;	/* ap queue state machine state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	int last_err_rc;		/* last error state response code */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) #define to_ap_queue(x) container_of((x), struct ap_queue, ap_dev.device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) typedef enum ap_sm_wait (ap_func_t)(struct ap_queue *queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) /* failure injection cmd struct */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) struct ap_fi {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		u16 cmd;		/* fi flags + action */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 			u8 flags;	/* fi flags only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 			u8 action;	/* fi action only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) /* all currently known fi actions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) enum ap_fi_actions {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	AP_FI_ACTION_CCA_AGENT_FF   = 0x01,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	AP_FI_ACTION_CCA_DOM_INVAL  = 0x02,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	AP_FI_ACTION_NQAP_QID_INVAL = 0x03,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) /* all currently known fi flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) enum ap_fi_flags {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	AP_FI_FLAG_NO_RETRY	  = 0x01,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	AP_FI_FLAG_TOGGLE_SPECIAL = 0x02,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) struct ap_message {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	struct list_head list;		/* Request queueing. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	unsigned long long psmid;	/* Message id. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	void *msg;			/* Pointer to message buffer. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	unsigned int len;		/* Message length. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	u16 flags;			/* Flags, see AP_MSG_FLAG_xxx */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	struct ap_fi fi;		/* Failure Injection cmd */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	int rc;				/* Return code for this message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	void *private;			/* ap driver private pointer. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	/* receive is called from tasklet context */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	void (*receive)(struct ap_queue *, struct ap_message *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 			struct ap_message *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) #define AP_MSG_FLAG_SPECIAL  1		/* flag msg as 'special' with NQAP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)  * ap_init_message() - Initialize ap_message.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)  * Initialize a message before using. Otherwise this might result in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)  * unexpected behaviour.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) static inline void ap_init_message(struct ap_message *ap_msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	memset(ap_msg, 0, sizeof(*ap_msg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)  * ap_release_message() - Release ap_message.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)  * Releases all memory used internal within the ap_message struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)  * Currently this is the message and private field.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) static inline void ap_release_message(struct ap_message *ap_msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	kfree_sensitive(ap_msg->msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	kfree_sensitive(ap_msg->private);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)  * Note: don't use ap_send/ap_recv after using ap_queue_message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)  * for the first time. Otherwise the ap message queue will get
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)  * confused.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) int ap_send(ap_qid_t, unsigned long long, void *, size_t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) int ap_recv(ap_qid_t, unsigned long long *, void *, size_t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) enum ap_sm_wait ap_sm_event(struct ap_queue *aq, enum ap_sm_event event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) enum ap_sm_wait ap_sm_event_loop(struct ap_queue *aq, enum ap_sm_event event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) int ap_queue_message(struct ap_queue *aq, struct ap_message *ap_msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) void ap_cancel_message(struct ap_queue *aq, struct ap_message *ap_msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) void ap_flush_queue(struct ap_queue *aq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) void *ap_airq_ptr(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) void ap_wait(enum ap_sm_wait wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) void ap_request_timeout(struct timer_list *t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) void ap_bus_force_rescan(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) int ap_test_config_usage_domain(unsigned int domain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) int ap_test_config_ctrl_domain(unsigned int domain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) void ap_queue_init_reply(struct ap_queue *aq, struct ap_message *ap_msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) struct ap_queue *ap_queue_create(ap_qid_t qid, int device_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) void ap_queue_prepare_remove(struct ap_queue *aq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) void ap_queue_remove(struct ap_queue *aq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) void ap_queue_init_state(struct ap_queue *aq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) struct ap_card *ap_card_create(int id, int queue_depth, int raw_device_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 			       int comp_device_type, unsigned int functions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) struct ap_perms {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	unsigned long ioctlm[BITS_TO_LONGS(AP_IOCTLS)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	unsigned long apm[BITS_TO_LONGS(AP_DEVICES)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	unsigned long aqm[BITS_TO_LONGS(AP_DOMAINS)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) extern struct ap_perms ap_perms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) extern struct mutex ap_perms_mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)  * Get ap_queue device for this qid.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)  * Returns ptr to the struct ap_queue device or NULL if there
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)  * was no ap_queue device with this qid found. When something is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)  * found, the reference count of the embedded device is increased.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)  * So the caller has to decrease the reference count after use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)  * with a call to put_device(&aq->ap_dev.device).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) struct ap_queue *ap_get_qdev(ap_qid_t qid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)  * check APQN for owned/reserved by ap bus and default driver(s).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)  * Checks if this APQN is or will be in use by the ap bus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)  * and the default set of drivers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)  * If yes, returns 1, if not returns 0. On error a negative
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)  * errno value is returned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) int ap_owned_by_def_drv(int card, int queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318)  * check 'matrix' of APQNs for owned/reserved by ap bus and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)  * default driver(s).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)  * Checks if there is at least one APQN in the given 'matrix'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)  * marked as owned/reserved by the ap bus and default driver(s).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)  * If such an APQN is found the return value is 1, otherwise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)  * 0 is returned. On error a negative errno value is returned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)  * The parameter apm is a bitmask which should be declared
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)  * as DECLARE_BITMAP(apm, AP_DEVICES), the aqm parameter is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)  * similar, should be declared as DECLARE_BITMAP(aqm, AP_DOMAINS).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) int ap_apqn_in_matrix_owned_by_def_drv(unsigned long *apm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 				       unsigned long *aqm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)  * ap_parse_mask_str() - helper function to parse a bitmap string
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)  * and clear/set the bits in the bitmap accordingly. The string may be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)  * given as absolute value, a hex string like 0x1F2E3D4C5B6A" simple
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)  * overwriting the current content of the bitmap. Or as relative string
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)  * like "+1-16,-32,-0x40,+128" where only single bits or ranges of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)  * bits are cleared or set. Distinction is done based on the very
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)  * first character which may be '+' or '-' for the relative string
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)  * and othewise assume to be an absolute value string. If parsing fails
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)  * a negative errno value is returned. All arguments and bitmaps are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)  * big endian order.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) int ap_parse_mask_str(const char *str,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 		      unsigned long *bitmap, int bits,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 		      struct mutex *lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) #endif /* _AP_BUS_H_ */