xref: /openbmc/linux/drivers/s390/crypto/ap_bus.h (revision 9a564108)
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/types.h>
31e7fc5146STony Krowiak #include <asm/ap.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 
41e28d2af4SIngo Tuchscherer extern spinlock_t ap_list_lock;
42e28d2af4SIngo Tuchscherer extern struct list_head ap_card_list;
43e28d2af4SIngo Tuchscherer 
4475014550SHolger Dengler static inline int ap_test_bit(unsigned int *ptr, unsigned int nr)
456bed05bcSHolger Dengler {
4675014550SHolger Dengler 	return (*ptr & (0x80000000u >> nr)) != 0;
476bed05bcSHolger Dengler }
481534c382SMartin Schwidefsky 
491534c382SMartin Schwidefsky #define AP_RESPONSE_NORMAL		0x00
501534c382SMartin Schwidefsky #define AP_RESPONSE_Q_NOT_AVAIL		0x01
511534c382SMartin Schwidefsky #define AP_RESPONSE_RESET_IN_PROGRESS	0x02
521534c382SMartin Schwidefsky #define AP_RESPONSE_DECONFIGURED	0x03
531534c382SMartin Schwidefsky #define AP_RESPONSE_CHECKSTOPPED	0x04
541534c382SMartin Schwidefsky #define AP_RESPONSE_BUSY		0x05
55cb17a636SFelix Beck #define AP_RESPONSE_INVALID_ADDRESS	0x06
56cb17a636SFelix Beck #define AP_RESPONSE_OTHERWISE_CHANGED	0x07
571534c382SMartin Schwidefsky #define AP_RESPONSE_Q_FULL		0x10
581534c382SMartin Schwidefsky #define AP_RESPONSE_NO_PENDING_REPLY	0x10
591534c382SMartin Schwidefsky #define AP_RESPONSE_INDEX_TOO_BIG	0x11
601534c382SMartin Schwidefsky #define AP_RESPONSE_NO_FIRST_PART	0x13
611534c382SMartin Schwidefsky #define AP_RESPONSE_MESSAGE_TOO_BIG	0x15
62a6a5d73aSFelix Beck #define AP_RESPONSE_REQ_FAC_NOT_INST	0x16
631534c382SMartin Schwidefsky 
641749a81dSFelix Beck /*
651534c382SMartin Schwidefsky  * Known device types
661534c382SMartin Schwidefsky  */
671534c382SMartin Schwidefsky #define AP_DEVICE_TYPE_PCICC	3
681534c382SMartin Schwidefsky #define AP_DEVICE_TYPE_PCICA	4
691534c382SMartin Schwidefsky #define AP_DEVICE_TYPE_PCIXCC	5
701534c382SMartin Schwidefsky #define AP_DEVICE_TYPE_CEX2A	6
711534c382SMartin Schwidefsky #define AP_DEVICE_TYPE_CEX2C	7
72ffda4f71SFelix Beck #define AP_DEVICE_TYPE_CEX3A	8
73ffda4f71SFelix Beck #define AP_DEVICE_TYPE_CEX3C	9
741e2076f4SHolger Dengler #define AP_DEVICE_TYPE_CEX4	10
75bdea1f1bSIngo Tuchscherer #define AP_DEVICE_TYPE_CEX5	11
76b3e8652bSHarald Freudenberger #define AP_DEVICE_TYPE_CEX6	12
771534c382SMartin Schwidefsky 
781749a81dSFelix Beck /*
79b26bd941SHolger Dengler  * Known function facilities
80b26bd941SHolger Dengler  */
81b26bd941SHolger Dengler #define AP_FUNC_MEX4K 1
82b26bd941SHolger Dengler #define AP_FUNC_CRT4K 2
83b26bd941SHolger Dengler #define AP_FUNC_COPRO 3
84b26bd941SHolger Dengler #define AP_FUNC_ACCEL 4
8591f3e3eaSIngo Tuchscherer #define AP_FUNC_EP11  5
8691f3e3eaSIngo Tuchscherer #define AP_FUNC_APXA  6
87b26bd941SHolger Dengler 
88b26bd941SHolger Dengler /*
89c50a160cSIngo Tuchscherer  * AP interrupt states
90c50a160cSIngo Tuchscherer  */
91c50a160cSIngo Tuchscherer #define AP_INTR_DISABLED	0	/* AP interrupt disabled */
92c50a160cSIngo Tuchscherer #define AP_INTR_ENABLED		1	/* AP interrupt enabled */
933f3007afSMartin Schwidefsky 
943f3007afSMartin Schwidefsky /*
953f3007afSMartin Schwidefsky  * AP device states
963f3007afSMartin Schwidefsky  */
973f3007afSMartin Schwidefsky enum ap_state {
983f3007afSMartin Schwidefsky 	AP_STATE_RESET_START,
993f3007afSMartin Schwidefsky 	AP_STATE_RESET_WAIT,
1003f3007afSMartin Schwidefsky 	AP_STATE_SETIRQ_WAIT,
1013f3007afSMartin Schwidefsky 	AP_STATE_IDLE,
1023f3007afSMartin Schwidefsky 	AP_STATE_WORKING,
1033f3007afSMartin Schwidefsky 	AP_STATE_QUEUE_FULL,
1043f3007afSMartin Schwidefsky 	AP_STATE_SUSPEND_WAIT,
1053f3007afSMartin Schwidefsky 	AP_STATE_BORKED,
1063f3007afSMartin Schwidefsky 	NR_AP_STATES
1073f3007afSMartin Schwidefsky };
1083f3007afSMartin Schwidefsky 
1093f3007afSMartin Schwidefsky /*
1103f3007afSMartin Schwidefsky  * AP device events
1113f3007afSMartin Schwidefsky  */
1123f3007afSMartin Schwidefsky enum ap_event {
1133f3007afSMartin Schwidefsky 	AP_EVENT_POLL,
1143f3007afSMartin Schwidefsky 	AP_EVENT_TIMEOUT,
1153f3007afSMartin Schwidefsky 	NR_AP_EVENTS
1163f3007afSMartin Schwidefsky };
1173f3007afSMartin Schwidefsky 
1183f3007afSMartin Schwidefsky /*
1193f3007afSMartin Schwidefsky  * AP wait behaviour
1203f3007afSMartin Schwidefsky  */
1213f3007afSMartin Schwidefsky enum ap_wait {
1223f3007afSMartin Schwidefsky 	AP_WAIT_AGAIN,		/* retry immediately */
1233f3007afSMartin Schwidefsky 	AP_WAIT_TIMEOUT,	/* wait for timeout */
1243f3007afSMartin Schwidefsky 	AP_WAIT_INTERRUPT,	/* wait for thin interrupt (if available) */
1253f3007afSMartin Schwidefsky 	AP_WAIT_NONE,		/* no wait */
1263f3007afSMartin Schwidefsky 	NR_AP_WAIT
1273f3007afSMartin Schwidefsky };
128af512ed0SRalph Wuerthner 
1291534c382SMartin Schwidefsky struct ap_device;
1301534c382SMartin Schwidefsky struct ap_message;
1311534c382SMartin Schwidefsky 
1321534c382SMartin Schwidefsky struct ap_driver {
1331534c382SMartin Schwidefsky 	struct device_driver driver;
1341534c382SMartin Schwidefsky 	struct ap_device_id *ids;
1351534c382SMartin Schwidefsky 
1361534c382SMartin Schwidefsky 	int (*probe)(struct ap_device *);
1371534c382SMartin Schwidefsky 	void (*remove)(struct ap_device *);
138e28d2af4SIngo Tuchscherer 	void (*suspend)(struct ap_device *);
139e28d2af4SIngo Tuchscherer 	void (*resume)(struct ap_device *);
1401534c382SMartin Schwidefsky };
1411534c382SMartin Schwidefsky 
1421534c382SMartin Schwidefsky #define to_ap_drv(x) container_of((x), struct ap_driver, driver)
1431534c382SMartin Schwidefsky 
1441534c382SMartin Schwidefsky int ap_driver_register(struct ap_driver *, struct module *, char *);
1451534c382SMartin Schwidefsky void ap_driver_unregister(struct ap_driver *);
1461534c382SMartin Schwidefsky 
1471534c382SMartin Schwidefsky struct ap_device {
1481534c382SMartin Schwidefsky 	struct device device;
1491534c382SMartin Schwidefsky 	struct ap_driver *drv;		/* Pointer to AP device driver. */
1501534c382SMartin Schwidefsky 	int device_type;		/* AP device type. */
1511534c382SMartin Schwidefsky };
1521534c382SMartin Schwidefsky 
1531534c382SMartin Schwidefsky #define to_ap_dev(x) container_of((x), struct ap_device, device)
1541534c382SMartin Schwidefsky 
155e28d2af4SIngo Tuchscherer struct ap_card {
156e28d2af4SIngo Tuchscherer 	struct ap_device ap_dev;
157e28d2af4SIngo Tuchscherer 	struct list_head list;		/* Private list of AP cards. */
158e28d2af4SIngo Tuchscherer 	struct list_head queues;	/* List of assoc. AP queues */
159e28d2af4SIngo Tuchscherer 	void *private;			/* ap driver private pointer. */
160e28d2af4SIngo Tuchscherer 	int raw_hwtype;			/* AP raw hardware type. */
161e28d2af4SIngo Tuchscherer 	unsigned int functions;		/* AP device function bitfield. */
162e28d2af4SIngo Tuchscherer 	int queue_depth;		/* AP queue depth.*/
163e28d2af4SIngo Tuchscherer 	int id;				/* AP card number. */
164e47de21dSIngo Tuchscherer 	atomic_t total_request_count;	/* # requests ever for this AP device.*/
165e28d2af4SIngo Tuchscherer };
166e28d2af4SIngo Tuchscherer 
167e28d2af4SIngo Tuchscherer #define to_ap_card(x) container_of((x), struct ap_card, ap_dev.device)
168e28d2af4SIngo Tuchscherer 
169e28d2af4SIngo Tuchscherer struct ap_queue {
170e28d2af4SIngo Tuchscherer 	struct ap_device ap_dev;
171e28d2af4SIngo Tuchscherer 	struct list_head list;		/* Private list of AP queues. */
172e28d2af4SIngo Tuchscherer 	struct ap_card *card;		/* Ptr to assoc. AP card. */
173e28d2af4SIngo Tuchscherer 	spinlock_t lock;		/* Per device lock. */
174e28d2af4SIngo Tuchscherer 	void *private;			/* ap driver private pointer. */
175e28d2af4SIngo Tuchscherer 	ap_qid_t qid;			/* AP queue id. */
176e28d2af4SIngo Tuchscherer 	int interrupt;			/* indicate if interrupts are enabled */
177e28d2af4SIngo Tuchscherer 	int queue_count;		/* # messages currently on AP queue. */
178e28d2af4SIngo Tuchscherer 	enum ap_state state;		/* State of the AP device. */
179e28d2af4SIngo Tuchscherer 	int pendingq_count;		/* # requests on pendingq list. */
180e28d2af4SIngo Tuchscherer 	int requestq_count;		/* # requests on requestq list. */
181e28d2af4SIngo Tuchscherer 	int total_request_count;	/* # requests ever for this AP device.*/
182e28d2af4SIngo Tuchscherer 	int request_timeout;		/* Request timout in jiffies. */
183e28d2af4SIngo Tuchscherer 	struct timer_list timeout;	/* Timer for request timeouts. */
184e28d2af4SIngo Tuchscherer 	struct list_head pendingq;	/* List of message sent to AP queue. */
185e28d2af4SIngo Tuchscherer 	struct list_head requestq;	/* List of message yet to be sent. */
186e28d2af4SIngo Tuchscherer 	struct ap_message *reply;	/* Per device reply message. */
187e28d2af4SIngo Tuchscherer };
188e28d2af4SIngo Tuchscherer 
189e28d2af4SIngo Tuchscherer #define to_ap_queue(x) container_of((x), struct ap_queue, ap_dev.device)
190e28d2af4SIngo Tuchscherer 
191e28d2af4SIngo Tuchscherer typedef enum ap_wait (ap_func_t)(struct ap_queue *queue);
192e28d2af4SIngo Tuchscherer 
1931534c382SMartin Schwidefsky struct ap_message {
1941534c382SMartin Schwidefsky 	struct list_head list;		/* Request queueing. */
1951534c382SMartin Schwidefsky 	unsigned long long psmid;	/* Message id. */
1961534c382SMartin Schwidefsky 	void *message;			/* Pointer to message buffer. */
1971534c382SMartin Schwidefsky 	size_t length;			/* Message length. */
198f58fe336SMartin Schwidefsky 	int rc;				/* Return code for this message */
1991534c382SMartin Schwidefsky 
2001534c382SMartin Schwidefsky 	void *private;			/* ap driver private pointer. */
201a6a5d73aSFelix Beck 	unsigned int special:1;		/* Used for special commands. */
20254a8f561SHolger Dengler 	/* receive is called from tasklet context */
203e28d2af4SIngo Tuchscherer 	void (*receive)(struct ap_queue *, struct ap_message *,
20454a8f561SHolger Dengler 			struct ap_message *);
2051534c382SMartin Schwidefsky };
2061534c382SMartin Schwidefsky 
207468ffddfSFelix Beck /**
208468ffddfSFelix Beck  * ap_init_message() - Initialize ap_message.
209468ffddfSFelix Beck  * Initialize a message before using. Otherwise this might result in
210468ffddfSFelix Beck  * unexpected behaviour.
211468ffddfSFelix Beck  */
212468ffddfSFelix Beck static inline void ap_init_message(struct ap_message *ap_msg)
213468ffddfSFelix Beck {
214468ffddfSFelix Beck 	ap_msg->psmid = 0;
215468ffddfSFelix Beck 	ap_msg->length = 0;
216f58fe336SMartin Schwidefsky 	ap_msg->rc = 0;
217a6a5d73aSFelix Beck 	ap_msg->special = 0;
21854a8f561SHolger Dengler 	ap_msg->receive = NULL;
219468ffddfSFelix Beck }
220468ffddfSFelix Beck 
221e28d2af4SIngo Tuchscherer #define for_each_ap_card(_ac) \
222e28d2af4SIngo Tuchscherer 	list_for_each_entry(_ac, &ap_card_list, list)
223e28d2af4SIngo Tuchscherer 
224e28d2af4SIngo Tuchscherer #define for_each_ap_queue(_aq, _ac) \
225e28d2af4SIngo Tuchscherer 	list_for_each_entry(_aq, &(_ac)->queues, list)
226e28d2af4SIngo Tuchscherer 
2271749a81dSFelix Beck /*
2281534c382SMartin Schwidefsky  * Note: don't use ap_send/ap_recv after using ap_queue_message
2291534c382SMartin Schwidefsky  * for the first time. Otherwise the ap message queue will get
2301534c382SMartin Schwidefsky  * confused.
2311534c382SMartin Schwidefsky  */
2321534c382SMartin Schwidefsky int ap_send(ap_qid_t, unsigned long long, void *, size_t);
2331534c382SMartin Schwidefsky int ap_recv(ap_qid_t, unsigned long long *, void *, size_t);
2341534c382SMartin Schwidefsky 
235e28d2af4SIngo Tuchscherer enum ap_wait ap_sm_event(struct ap_queue *aq, enum ap_event event);
236e28d2af4SIngo Tuchscherer enum ap_wait ap_sm_event_loop(struct ap_queue *aq, enum ap_event event);
237e28d2af4SIngo Tuchscherer 
238e28d2af4SIngo Tuchscherer void ap_queue_message(struct ap_queue *aq, struct ap_message *ap_msg);
239e28d2af4SIngo Tuchscherer void ap_cancel_message(struct ap_queue *aq, struct ap_message *ap_msg);
240e28d2af4SIngo Tuchscherer void ap_flush_queue(struct ap_queue *aq);
241e28d2af4SIngo Tuchscherer 
242e28d2af4SIngo Tuchscherer void *ap_airq_ptr(void);
243e28d2af4SIngo Tuchscherer void ap_wait(enum ap_wait wait);
244e28d2af4SIngo Tuchscherer void ap_request_timeout(unsigned long data);
245dabecb29SHolger Dengler void ap_bus_force_rescan(void);
246e28d2af4SIngo Tuchscherer 
247e28d2af4SIngo Tuchscherer void ap_queue_init_reply(struct ap_queue *aq, struct ap_message *ap_msg);
248e28d2af4SIngo Tuchscherer struct ap_queue *ap_queue_create(ap_qid_t qid, int device_type);
249e28d2af4SIngo Tuchscherer void ap_queue_remove(struct ap_queue *aq);
250e28d2af4SIngo Tuchscherer void ap_queue_suspend(struct ap_device *ap_dev);
251e28d2af4SIngo Tuchscherer void ap_queue_resume(struct ap_device *ap_dev);
252e28d2af4SIngo Tuchscherer 
2539a564108SHarald Freudenberger struct ap_card *ap_card_create(int id, int queue_depth, int raw_device_type,
2549a564108SHarald Freudenberger 			       int comp_device_type, unsigned int functions);
2551534c382SMartin Schwidefsky 
2561534c382SMartin Schwidefsky int ap_module_init(void);
2571534c382SMartin Schwidefsky void ap_module_exit(void);
2581534c382SMartin Schwidefsky 
2591534c382SMartin Schwidefsky #endif /* _AP_BUS_H_ */
260