xref: /openbmc/linux/drivers/s390/crypto/ap_bus.h (revision 3f3007af)
11534c382SMartin Schwidefsky /*
275014550SHolger Dengler  * Copyright IBM Corp. 2006, 2012
31534c382SMartin Schwidefsky  * Author(s): Cornelia Huck <cornelia.huck@de.ibm.com>
41534c382SMartin Schwidefsky  *	      Martin Schwidefsky <schwidefsky@de.ibm.com>
51534c382SMartin Schwidefsky  *	      Ralph Wuerthner <rwuerthn@de.ibm.com>
6cb17a636SFelix Beck  *	      Felix Beck <felix.beck@de.ibm.com>
76bed05bcSHolger Dengler  *	      Holger Dengler <hd@linux.vnet.ibm.com>
81534c382SMartin Schwidefsky  *
91534c382SMartin Schwidefsky  * Adjunct processor bus header file.
101534c382SMartin Schwidefsky  *
111534c382SMartin Schwidefsky  * This program is free software; you can redistribute it and/or modify
121534c382SMartin Schwidefsky  * it under the terms of the GNU General Public License as published by
131534c382SMartin Schwidefsky  * the Free Software Foundation; either version 2, or (at your option)
141534c382SMartin Schwidefsky  * any later version.
151534c382SMartin Schwidefsky  *
161534c382SMartin Schwidefsky  * This program is distributed in the hope that it will be useful,
171534c382SMartin Schwidefsky  * but WITHOUT ANY WARRANTY; without even the implied warranty of
181534c382SMartin Schwidefsky  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
191534c382SMartin Schwidefsky  * GNU General Public License for more details.
201534c382SMartin Schwidefsky  *
211534c382SMartin Schwidefsky  * You should have received a copy of the GNU General Public License
221534c382SMartin Schwidefsky  * along with this program; if not, write to the Free Software
231534c382SMartin Schwidefsky  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
241534c382SMartin Schwidefsky  */
251534c382SMartin Schwidefsky 
261534c382SMartin Schwidefsky #ifndef _AP_BUS_H_
271534c382SMartin Schwidefsky #define _AP_BUS_H_
281534c382SMartin Schwidefsky 
291534c382SMartin Schwidefsky #include <linux/device.h>
301534c382SMartin Schwidefsky #include <linux/mod_devicetable.h>
311534c382SMartin Schwidefsky #include <linux/types.h>
321534c382SMartin Schwidefsky 
331534c382SMartin Schwidefsky #define AP_DEVICES 64		/* Number of AP devices. */
34170387a8SIngo Tuchscherer #define AP_DOMAINS 256		/* Number of AP domains. */
3591f3e3eaSIngo Tuchscherer #define AP_RESET_TIMEOUT (HZ*0.7)	/* Time in ticks for reset timeouts. */
361534c382SMartin Schwidefsky #define AP_CONFIG_TIME 30	/* Time in seconds between AP bus rescans. */
371534c382SMartin Schwidefsky #define AP_POLL_TIME 1		/* Time in ticks between receive polls. */
381534c382SMartin Schwidefsky 
391534c382SMartin Schwidefsky extern int ap_domain_index;
401534c382SMartin Schwidefsky 
411534c382SMartin Schwidefsky /**
421534c382SMartin Schwidefsky  * The ap_qid_t identifier of an ap queue. It contains a
431534c382SMartin Schwidefsky  * 6 bit device index and a 4 bit queue index (domain).
441534c382SMartin Schwidefsky  */
451534c382SMartin Schwidefsky typedef unsigned int ap_qid_t;
461534c382SMartin Schwidefsky 
47170387a8SIngo Tuchscherer #define AP_MKQID(_device, _queue) (((_device) & 63) << 8 | ((_queue) & 255))
481534c382SMartin Schwidefsky #define AP_QID_DEVICE(_qid) (((_qid) >> 8) & 63)
49170387a8SIngo Tuchscherer #define AP_QID_QUEUE(_qid) ((_qid) & 255)
501534c382SMartin Schwidefsky 
511534c382SMartin Schwidefsky /**
521749a81dSFelix Beck  * structy ap_queue_status - Holds the AP queue status.
531749a81dSFelix Beck  * @queue_empty: Shows if queue is empty
541749a81dSFelix Beck  * @replies_waiting: Waiting replies
551749a81dSFelix Beck  * @queue_full: Is 1 if the queue is full
561749a81dSFelix Beck  * @pad: A 4 bit pad
571749a81dSFelix Beck  * @int_enabled: Shows if interrupts are enabled for the AP
581749a81dSFelix Beck  * @response_conde: Holds the 8 bit response code
591749a81dSFelix Beck  * @pad2: A 16 bit pad
601749a81dSFelix Beck  *
611534c382SMartin Schwidefsky  * The ap queue status word is returned by all three AP functions
621534c382SMartin Schwidefsky  * (PQAP, NQAP and DQAP).  There's a set of flags in the first
631534c382SMartin Schwidefsky  * byte, followed by a 1 byte response code.
641534c382SMartin Schwidefsky  */
651534c382SMartin Schwidefsky struct ap_queue_status {
661534c382SMartin Schwidefsky 	unsigned int queue_empty	: 1;
671534c382SMartin Schwidefsky 	unsigned int replies_waiting	: 1;
681534c382SMartin Schwidefsky 	unsigned int queue_full		: 1;
69cb17a636SFelix Beck 	unsigned int pad1		: 4;
70cb17a636SFelix Beck 	unsigned int int_enabled	: 1;
711534c382SMartin Schwidefsky 	unsigned int response_code	: 8;
721534c382SMartin Schwidefsky 	unsigned int pad2		: 16;
736bed05bcSHolger Dengler } __packed;
746bed05bcSHolger Dengler 
756bed05bcSHolger Dengler 
7675014550SHolger Dengler static inline int ap_test_bit(unsigned int *ptr, unsigned int nr)
776bed05bcSHolger Dengler {
7875014550SHolger Dengler 	return (*ptr & (0x80000000u >> nr)) != 0;
796bed05bcSHolger Dengler }
801534c382SMartin Schwidefsky 
811534c382SMartin Schwidefsky #define AP_RESPONSE_NORMAL		0x00
821534c382SMartin Schwidefsky #define AP_RESPONSE_Q_NOT_AVAIL		0x01
831534c382SMartin Schwidefsky #define AP_RESPONSE_RESET_IN_PROGRESS	0x02
841534c382SMartin Schwidefsky #define AP_RESPONSE_DECONFIGURED	0x03
851534c382SMartin Schwidefsky #define AP_RESPONSE_CHECKSTOPPED	0x04
861534c382SMartin Schwidefsky #define AP_RESPONSE_BUSY		0x05
87cb17a636SFelix Beck #define AP_RESPONSE_INVALID_ADDRESS	0x06
88cb17a636SFelix Beck #define AP_RESPONSE_OTHERWISE_CHANGED	0x07
891534c382SMartin Schwidefsky #define AP_RESPONSE_Q_FULL		0x10
901534c382SMartin Schwidefsky #define AP_RESPONSE_NO_PENDING_REPLY	0x10
911534c382SMartin Schwidefsky #define AP_RESPONSE_INDEX_TOO_BIG	0x11
921534c382SMartin Schwidefsky #define AP_RESPONSE_NO_FIRST_PART	0x13
931534c382SMartin Schwidefsky #define AP_RESPONSE_MESSAGE_TOO_BIG	0x15
94a6a5d73aSFelix Beck #define AP_RESPONSE_REQ_FAC_NOT_INST	0x16
951534c382SMartin Schwidefsky 
961749a81dSFelix Beck /*
971534c382SMartin Schwidefsky  * Known device types
981534c382SMartin Schwidefsky  */
991534c382SMartin Schwidefsky #define AP_DEVICE_TYPE_PCICC	3
1001534c382SMartin Schwidefsky #define AP_DEVICE_TYPE_PCICA	4
1011534c382SMartin Schwidefsky #define AP_DEVICE_TYPE_PCIXCC	5
1021534c382SMartin Schwidefsky #define AP_DEVICE_TYPE_CEX2A	6
1031534c382SMartin Schwidefsky #define AP_DEVICE_TYPE_CEX2C	7
104ffda4f71SFelix Beck #define AP_DEVICE_TYPE_CEX3A	8
105ffda4f71SFelix Beck #define AP_DEVICE_TYPE_CEX3C	9
1061e2076f4SHolger Dengler #define AP_DEVICE_TYPE_CEX4	10
107bdea1f1bSIngo Tuchscherer #define AP_DEVICE_TYPE_CEX5	11
1081534c382SMartin Schwidefsky 
1091749a81dSFelix Beck /*
110b26bd941SHolger Dengler  * Known function facilities
111b26bd941SHolger Dengler  */
112b26bd941SHolger Dengler #define AP_FUNC_MEX4K 1
113b26bd941SHolger Dengler #define AP_FUNC_CRT4K 2
114b26bd941SHolger Dengler #define AP_FUNC_COPRO 3
115b26bd941SHolger Dengler #define AP_FUNC_ACCEL 4
11691f3e3eaSIngo Tuchscherer #define AP_FUNC_EP11  5
11791f3e3eaSIngo Tuchscherer #define AP_FUNC_APXA  6
118b26bd941SHolger Dengler 
119b26bd941SHolger Dengler /*
120c50a160cSIngo Tuchscherer  * AP interrupt states
121c50a160cSIngo Tuchscherer  */
122c50a160cSIngo Tuchscherer #define AP_INTR_DISABLED	0	/* AP interrupt disabled */
123c50a160cSIngo Tuchscherer #define AP_INTR_ENABLED		1	/* AP interrupt enabled */
1243f3007afSMartin Schwidefsky 
1253f3007afSMartin Schwidefsky /*
1263f3007afSMartin Schwidefsky  * AP device states
1273f3007afSMartin Schwidefsky  */
1283f3007afSMartin Schwidefsky enum ap_state {
1293f3007afSMartin Schwidefsky 	AP_STATE_RESET_START,
1303f3007afSMartin Schwidefsky 	AP_STATE_RESET_WAIT,
1313f3007afSMartin Schwidefsky 	AP_STATE_SETIRQ_WAIT,
1323f3007afSMartin Schwidefsky 	AP_STATE_IDLE,
1333f3007afSMartin Schwidefsky 	AP_STATE_WORKING,
1343f3007afSMartin Schwidefsky 	AP_STATE_QUEUE_FULL,
1353f3007afSMartin Schwidefsky 	AP_STATE_SUSPEND_WAIT,
1363f3007afSMartin Schwidefsky 	AP_STATE_BORKED,
1373f3007afSMartin Schwidefsky 	NR_AP_STATES
1383f3007afSMartin Schwidefsky };
1393f3007afSMartin Schwidefsky 
1403f3007afSMartin Schwidefsky /*
1413f3007afSMartin Schwidefsky  * AP device events
1423f3007afSMartin Schwidefsky  */
1433f3007afSMartin Schwidefsky enum ap_event {
1443f3007afSMartin Schwidefsky 	AP_EVENT_POLL,
1453f3007afSMartin Schwidefsky 	AP_EVENT_TIMEOUT,
1463f3007afSMartin Schwidefsky 	NR_AP_EVENTS
1473f3007afSMartin Schwidefsky };
1483f3007afSMartin Schwidefsky 
1493f3007afSMartin Schwidefsky /*
1503f3007afSMartin Schwidefsky  * AP wait behaviour
1513f3007afSMartin Schwidefsky  */
1523f3007afSMartin Schwidefsky enum ap_wait {
1533f3007afSMartin Schwidefsky 	AP_WAIT_AGAIN,		/* retry immediately */
1543f3007afSMartin Schwidefsky 	AP_WAIT_TIMEOUT,	/* wait for timeout */
1553f3007afSMartin Schwidefsky 	AP_WAIT_INTERRUPT,	/* wait for thin interrupt (if available) */
1563f3007afSMartin Schwidefsky 	AP_WAIT_NONE,		/* no wait */
1573f3007afSMartin Schwidefsky 	NR_AP_WAIT
1583f3007afSMartin Schwidefsky };
159af512ed0SRalph Wuerthner 
1601534c382SMartin Schwidefsky struct ap_device;
1611534c382SMartin Schwidefsky struct ap_message;
1621534c382SMartin Schwidefsky 
1631534c382SMartin Schwidefsky struct ap_driver {
1641534c382SMartin Schwidefsky 	struct device_driver driver;
1651534c382SMartin Schwidefsky 	struct ap_device_id *ids;
1661534c382SMartin Schwidefsky 
1671534c382SMartin Schwidefsky 	int (*probe)(struct ap_device *);
1681534c382SMartin Schwidefsky 	void (*remove)(struct ap_device *);
169af512ed0SRalph Wuerthner 	int request_timeout;		/* request timeout in jiffies */
1701534c382SMartin Schwidefsky };
1711534c382SMartin Schwidefsky 
1721534c382SMartin Schwidefsky #define to_ap_drv(x) container_of((x), struct ap_driver, driver)
1731534c382SMartin Schwidefsky 
1741534c382SMartin Schwidefsky int ap_driver_register(struct ap_driver *, struct module *, char *);
1751534c382SMartin Schwidefsky void ap_driver_unregister(struct ap_driver *);
1761534c382SMartin Schwidefsky 
1773f3007afSMartin Schwidefsky typedef enum ap_wait (ap_func_t)(struct ap_device *ap_dev);
1783f3007afSMartin Schwidefsky 
1791534c382SMartin Schwidefsky struct ap_device {
1801534c382SMartin Schwidefsky 	struct device device;
1811534c382SMartin Schwidefsky 	struct ap_driver *drv;		/* Pointer to AP device driver. */
1821534c382SMartin Schwidefsky 	spinlock_t lock;		/* Per device lock. */
183cf352ce0SRalph Wuerthner 	struct list_head list;		/* private list of all AP devices. */
1841534c382SMartin Schwidefsky 
1853f3007afSMartin Schwidefsky 	enum ap_state state;		/* State of the AP device. */
1863f3007afSMartin Schwidefsky 
1871534c382SMartin Schwidefsky 	ap_qid_t qid;			/* AP queue id. */
1881534c382SMartin Schwidefsky 	int queue_depth;		/* AP queue depth.*/
1891534c382SMartin Schwidefsky 	int device_type;		/* AP device type. */
19042f4dd61SIngo Tuchscherer 	int raw_hwtype;			/* AP raw hardware type. */
191b26bd941SHolger Dengler 	unsigned int functions;		/* AP device function bitfield. */
192af512ed0SRalph Wuerthner 	struct timer_list timeout;	/* Timer for request timeouts. */
1931534c382SMartin Schwidefsky 
194c50a160cSIngo Tuchscherer 	int interrupt;			/* indicate if interrupts are enabled */
1951534c382SMartin Schwidefsky 	int queue_count;		/* # messages currently on AP queue. */
1961534c382SMartin Schwidefsky 
1971534c382SMartin Schwidefsky 	struct list_head pendingq;	/* List of message sent to AP queue. */
1981534c382SMartin Schwidefsky 	int pendingq_count;		/* # requests on pendingq list. */
1991534c382SMartin Schwidefsky 	struct list_head requestq;	/* List of message yet to be sent. */
2001534c382SMartin Schwidefsky 	int requestq_count;		/* # requests on requestq list. */
2011534c382SMartin Schwidefsky 	int total_request_count;	/* # requests ever for this AP device. */
2021534c382SMartin Schwidefsky 
2031534c382SMartin Schwidefsky 	struct ap_message *reply;	/* Per device reply message. */
2041534c382SMartin Schwidefsky 
2051534c382SMartin Schwidefsky 	void *private;			/* ap driver private pointer. */
2061534c382SMartin Schwidefsky };
2071534c382SMartin Schwidefsky 
2081534c382SMartin Schwidefsky #define to_ap_dev(x) container_of((x), struct ap_device, device)
2091534c382SMartin Schwidefsky 
2101534c382SMartin Schwidefsky struct ap_message {
2111534c382SMartin Schwidefsky 	struct list_head list;		/* Request queueing. */
2121534c382SMartin Schwidefsky 	unsigned long long psmid;	/* Message id. */
2131534c382SMartin Schwidefsky 	void *message;			/* Pointer to message buffer. */
2141534c382SMartin Schwidefsky 	size_t length;			/* Message length. */
215f58fe336SMartin Schwidefsky 	int rc;				/* Return code for this message */
2161534c382SMartin Schwidefsky 
2171534c382SMartin Schwidefsky 	void *private;			/* ap driver private pointer. */
218a6a5d73aSFelix Beck 	unsigned int special:1;		/* Used for special commands. */
21954a8f561SHolger Dengler 	/* receive is called from tasklet context */
22054a8f561SHolger Dengler 	void (*receive)(struct ap_device *, struct ap_message *,
22154a8f561SHolger Dengler 			struct ap_message *);
2221534c382SMartin Schwidefsky };
2231534c382SMartin Schwidefsky 
22475014550SHolger Dengler struct ap_config_info {
22575014550SHolger Dengler 	unsigned int special_command:1;
22675014550SHolger Dengler 	unsigned int ap_extended:1;
22775014550SHolger Dengler 	unsigned char reserved1:6;
22875014550SHolger Dengler 	unsigned char reserved2[15];
22975014550SHolger Dengler 	unsigned int apm[8];		/* AP ID mask */
23075014550SHolger Dengler 	unsigned int aqm[8];		/* AP queue mask */
23175014550SHolger Dengler 	unsigned int adm[8];		/* AP domain mask */
23275014550SHolger Dengler 	unsigned char reserved4[16];
23375014550SHolger Dengler } __packed;
23475014550SHolger Dengler 
2351534c382SMartin Schwidefsky #define AP_DEVICE(dt)					\
2361534c382SMartin Schwidefsky 	.dev_type=(dt),					\
2371534c382SMartin Schwidefsky 	.match_flags=AP_DEVICE_ID_MATCH_DEVICE_TYPE,
2381534c382SMartin Schwidefsky 
239468ffddfSFelix Beck /**
240468ffddfSFelix Beck  * ap_init_message() - Initialize ap_message.
241468ffddfSFelix Beck  * Initialize a message before using. Otherwise this might result in
242468ffddfSFelix Beck  * unexpected behaviour.
243468ffddfSFelix Beck  */
244468ffddfSFelix Beck static inline void ap_init_message(struct ap_message *ap_msg)
245468ffddfSFelix Beck {
246468ffddfSFelix Beck 	ap_msg->psmid = 0;
247468ffddfSFelix Beck 	ap_msg->length = 0;
248f58fe336SMartin Schwidefsky 	ap_msg->rc = 0;
249a6a5d73aSFelix Beck 	ap_msg->special = 0;
25054a8f561SHolger Dengler 	ap_msg->receive = NULL;
251468ffddfSFelix Beck }
252468ffddfSFelix Beck 
2531749a81dSFelix Beck /*
2541534c382SMartin Schwidefsky  * Note: don't use ap_send/ap_recv after using ap_queue_message
2551534c382SMartin Schwidefsky  * for the first time. Otherwise the ap message queue will get
2561534c382SMartin Schwidefsky  * confused.
2571534c382SMartin Schwidefsky  */
2581534c382SMartin Schwidefsky int ap_send(ap_qid_t, unsigned long long, void *, size_t);
2591534c382SMartin Schwidefsky int ap_recv(ap_qid_t, unsigned long long *, void *, size_t);
2601534c382SMartin Schwidefsky 
2611534c382SMartin Schwidefsky void ap_queue_message(struct ap_device *ap_dev, struct ap_message *ap_msg);
2621534c382SMartin Schwidefsky void ap_cancel_message(struct ap_device *ap_dev, struct ap_message *ap_msg);
2631534c382SMartin Schwidefsky void ap_flush_queue(struct ap_device *ap_dev);
264dabecb29SHolger Dengler void ap_bus_force_rescan(void);
2651534c382SMartin Schwidefsky 
2661534c382SMartin Schwidefsky int ap_module_init(void);
2671534c382SMartin Schwidefsky void ap_module_exit(void);
2681534c382SMartin Schwidefsky 
2691534c382SMartin Schwidefsky #endif /* _AP_BUS_H_ */
270