blob: 61f768518a34b0e963cd6b569610045a3f65188b [file] [log] [blame]
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001/*
Holger Dengler75014552012-08-28 16:41:50 +02002 * Copyright IBM Corp. 2006, 2012
Martin Schwidefsky1534c382006-09-20 15:58:25 +02003 * Author(s): Cornelia Huck <cornelia.huck@de.ibm.com>
4 * Martin Schwidefsky <schwidefsky@de.ibm.com>
5 * Ralph Wuerthner <rwuerthn@de.ibm.com>
Felix Beckcb17a632008-12-25 13:38:41 +01006 * Felix Beck <felix.beck@de.ibm.com>
Holger Dengler6bed05b2011-07-24 10:48:25 +02007 * Holger Dengler <hd@linux.vnet.ibm.com>
Martin Schwidefsky1534c382006-09-20 15:58:25 +02008 *
9 * Adjunct processor bus.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2, or (at your option)
14 * any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 */
25
Martin Schwidefsky136f7a12008-12-25 13:39:46 +010026#define KMSG_COMPONENT "ap"
27#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
28
Holger Dengler62d146f2011-01-05 12:47:38 +010029#include <linux/kernel_stat.h>
Martin Schwidefsky1534c382006-09-20 15:58:25 +020030#include <linux/module.h>
31#include <linux/init.h>
32#include <linux/delay.h>
33#include <linux/err.h>
34#include <linux/interrupt.h>
35#include <linux/workqueue.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090036#include <linux/slab.h>
Martin Schwidefsky1534c382006-09-20 15:58:25 +020037#include <linux/notifier.h>
38#include <linux/kthread.h>
39#include <linux/mutex.h>
Martin Schwidefsky83e9d5d2015-07-17 13:43:18 +020040#include <linux/suspend.h>
Ralph Wuerthner85eca852006-12-08 15:54:07 +010041#include <asm/reset.h>
Felix Beckcb17a632008-12-25 13:38:41 +010042#include <asm/airq.h>
Arun Sharma600634972011-07-26 16:09:06 -070043#include <linux/atomic.h>
Felix Beckcb17a632008-12-25 13:38:41 +010044#include <asm/isc.h>
Felix Beckfe137232008-07-14 09:59:08 +020045#include <linux/hrtimer.h>
46#include <linux/ktime.h>
David Howellsa0616cd2012-03-28 18:30:02 +010047#include <asm/facility.h>
Kees Cook5d26a102014-11-20 17:05:53 -080048#include <linux/crypto.h>
Martin Schwidefsky1534c382006-09-20 15:58:25 +020049
50#include "ap_bus.h"
51
Felix Beck1749a812008-04-17 07:46:28 +020052/*
Martin Schwidefsky1534c382006-09-20 15:58:25 +020053 * Module description.
54 */
55MODULE_AUTHOR("IBM Corporation");
Holger Dengler75014552012-08-28 16:41:50 +020056MODULE_DESCRIPTION("Adjunct Processor Bus driver, " \
57 "Copyright IBM Corp. 2006, 2012");
Martin Schwidefsky1534c382006-09-20 15:58:25 +020058MODULE_LICENSE("GPL");
Kees Cook5d26a102014-11-20 17:05:53 -080059MODULE_ALIAS_CRYPTO("z90crypt");
Martin Schwidefsky1534c382006-09-20 15:58:25 +020060
Felix Beck1749a812008-04-17 07:46:28 +020061/*
Martin Schwidefsky1534c382006-09-20 15:58:25 +020062 * Module parameter
63 */
64int ap_domain_index = -1; /* Adjunct Processor Domain Index */
Michael Veigelc1a42f42014-04-14 14:28:27 +020065module_param_named(domain, ap_domain_index, int, S_IRUSR|S_IRGRP);
Martin Schwidefsky1534c382006-09-20 15:58:25 +020066MODULE_PARM_DESC(domain, "domain index for ap devices");
67EXPORT_SYMBOL(ap_domain_index);
68
Felix Beckb90b34c2008-02-09 18:24:30 +010069static int ap_thread_flag = 0;
Michael Veigelc1a42f42014-04-14 14:28:27 +020070module_param_named(poll_thread, ap_thread_flag, int, S_IRUSR|S_IRGRP);
Felix Beckb90b34c2008-02-09 18:24:30 +010071MODULE_PARM_DESC(poll_thread, "Turn on/off poll thread, default is 0 (off).");
Martin Schwidefsky1534c382006-09-20 15:58:25 +020072
73static struct device *ap_root_device = NULL;
Holger Dengler75014552012-08-28 16:41:50 +020074static struct ap_config_info *ap_configuration;
Christian Maaser43c207e62008-12-25 13:38:42 +010075static DEFINE_SPINLOCK(ap_device_list_lock);
Ralph Wuerthnercf352ce2007-03-19 13:19:14 +010076static LIST_HEAD(ap_device_list);
Sascha Silbee3877532015-10-27 18:29:52 +010077static bool initialised;
Martin Schwidefsky1534c382006-09-20 15:58:25 +020078
Felix Beck1749a812008-04-17 07:46:28 +020079/*
Martin Schwidefsky8139b892015-07-27 12:47:40 +020080 * Workqueue timer for bus rescan.
Martin Schwidefsky1534c382006-09-20 15:58:25 +020081 */
Martin Schwidefsky1534c382006-09-20 15:58:25 +020082static struct timer_list ap_config_timer;
83static int ap_config_time = AP_CONFIG_TIME;
Martin Schwidefsky3f3007a2015-09-14 17:01:23 +020084static void ap_scan_bus(struct work_struct *);
Martin Schwidefsky8139b892015-07-27 12:47:40 +020085static DECLARE_WORK(ap_scan_work, ap_scan_bus);
Martin Schwidefsky1534c382006-09-20 15:58:25 +020086
Felix Beck1749a812008-04-17 07:46:28 +020087/*
Felix Beckcb17a632008-12-25 13:38:41 +010088 * Tasklet & timer for AP request polling and interrupts
Martin Schwidefsky1534c382006-09-20 15:58:25 +020089 */
Martin Schwidefsky3f3007a2015-09-14 17:01:23 +020090static void ap_tasklet_fn(unsigned long);
91static DECLARE_TASKLET(ap_tasklet, ap_tasklet_fn, 0);
Martin Schwidefsky1534c382006-09-20 15:58:25 +020092static atomic_t ap_poll_requests = ATOMIC_INIT(0);
93static DECLARE_WAIT_QUEUE_HEAD(ap_poll_wait);
94static struct task_struct *ap_poll_kthread = NULL;
95static DEFINE_MUTEX(ap_poll_thread_mutex);
Felix Beck93521312009-12-07 12:52:00 +010096static DEFINE_SPINLOCK(ap_poll_timer_lock);
Felix Beckfe137232008-07-14 09:59:08 +020097static struct hrtimer ap_poll_timer;
98/* In LPAR poll with 4kHz frequency. Poll every 250000 nanoseconds.
99 * If z/VM change to 1500000 nanoseconds to adjust to z/VM polling.*/
100static unsigned long long poll_timeout = 250000;
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200101
Felix Beck772f5472009-06-22 12:08:16 +0200102/* Suspend flag */
103static int ap_suspend_flag;
Martin Schwidefsky889875a2015-06-26 16:55:35 +0200104/* Maximum domain id */
105static int ap_max_domain_id;
Felix Beck5314af62009-09-22 22:58:51 +0200106/* Flag to check if domain was set through module parameter domain=. This is
107 * important when supsend and resume is done in a z/VM environment where the
108 * domain might change. */
109static int user_set_domain = 0;
Felix Beck772f5472009-06-22 12:08:16 +0200110static struct bus_type ap_bus_type;
111
Martin Schwidefskyf4eae942013-06-24 10:30:41 +0200112/* Adapter interrupt definitions */
Martin Schwidefsky3f3007a2015-09-14 17:01:23 +0200113static void ap_interrupt_handler(struct airq_struct *airq);
114
Martin Schwidefskyf4eae942013-06-24 10:30:41 +0200115static int ap_airq_flag;
116
117static struct airq_struct ap_airq = {
118 .handler = ap_interrupt_handler,
119 .isc = AP_ISC,
120};
121
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200122/**
Felix Beckcb17a632008-12-25 13:38:41 +0100123 * ap_using_interrupts() - Returns non-zero if interrupt support is
124 * available.
125 */
126static inline int ap_using_interrupts(void)
127{
Martin Schwidefskyf4eae942013-06-24 10:30:41 +0200128 return ap_airq_flag;
Felix Beckcb17a632008-12-25 13:38:41 +0100129}
130
131/**
Felix Beck1749a812008-04-17 07:46:28 +0200132 * ap_intructions_available() - Test if AP instructions are available.
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200133 *
Felix Beck1749a812008-04-17 07:46:28 +0200134 * Returns 0 if the AP instructions are installed.
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200135 */
136static inline int ap_instructions_available(void)
137{
138 register unsigned long reg0 asm ("0") = AP_MKQID(0,0);
139 register unsigned long reg1 asm ("1") = -ENODEV;
140 register unsigned long reg2 asm ("2") = 0UL;
141
142 asm volatile(
143 " .long 0xb2af0000\n" /* PQAP(TAPQ) */
144 "0: la %1,0\n"
145 "1:\n"
146 EX_TABLE(0b, 1b)
147 : "+d" (reg0), "+d" (reg1), "+d" (reg2) : : "cc" );
148 return reg1;
149}
150
151/**
Felix Beckcb17a632008-12-25 13:38:41 +0100152 * ap_interrupts_available(): Test if AP interrupts are available.
153 *
154 * Returns 1 if AP interrupts are available.
155 */
156static int ap_interrupts_available(void)
157{
Heiko Carstens86cd7412015-02-14 11:23:21 +0100158 return test_facility(65);
Felix Beckcb17a632008-12-25 13:38:41 +0100159}
160
161/**
Holger Dengler75014552012-08-28 16:41:50 +0200162 * ap_configuration_available(): Test if AP configuration
163 * information is available.
164 *
165 * Returns 1 if AP configuration information is available.
166 */
167static int ap_configuration_available(void)
168{
Heiko Carstens86cd7412015-02-14 11:23:21 +0100169 return test_facility(12);
Holger Dengler75014552012-08-28 16:41:50 +0200170}
171
172/**
Felix Beck1749a812008-04-17 07:46:28 +0200173 * ap_test_queue(): Test adjunct processor queue.
174 * @qid: The AP queue number
Martin Schwidefsky6acbe212015-06-26 15:40:41 +0200175 * @info: Pointer to queue descriptor
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200176 *
Felix Beck1749a812008-04-17 07:46:28 +0200177 * Returns AP queue status structure.
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200178 */
179static inline struct ap_queue_status
Martin Schwidefsky6acbe212015-06-26 15:40:41 +0200180ap_test_queue(ap_qid_t qid, unsigned long *info)
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200181{
182 register unsigned long reg0 asm ("0") = qid;
183 register struct ap_queue_status reg1 asm ("1");
184 register unsigned long reg2 asm ("2") = 0UL;
185
Martin Schwidefsky6acbe212015-06-26 15:40:41 +0200186 if (test_facility(15))
187 reg0 |= 1UL << 23; /* set APFT T bit*/
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200188 asm volatile(".long 0xb2af0000" /* PQAP(TAPQ) */
189 : "+d" (reg0), "=d" (reg1), "+d" (reg2) : : "cc");
Martin Schwidefsky6acbe212015-06-26 15:40:41 +0200190 if (info)
191 *info = reg2;
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200192 return reg1;
193}
194
195/**
Felix Beck1749a812008-04-17 07:46:28 +0200196 * ap_reset_queue(): Reset adjunct processor queue.
197 * @qid: The AP queue number
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200198 *
Felix Beck1749a812008-04-17 07:46:28 +0200199 * Returns AP queue status structure.
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200200 */
201static inline struct ap_queue_status ap_reset_queue(ap_qid_t qid)
202{
203 register unsigned long reg0 asm ("0") = qid | 0x01000000UL;
204 register struct ap_queue_status reg1 asm ("1");
205 register unsigned long reg2 asm ("2") = 0UL;
206
207 asm volatile(
208 ".long 0xb2af0000" /* PQAP(RAPQ) */
209 : "+d" (reg0), "=d" (reg1), "+d" (reg2) : : "cc");
210 return reg1;
211}
212
Felix Beckcb17a632008-12-25 13:38:41 +0100213/**
214 * ap_queue_interruption_control(): Enable interruption for a specific AP.
215 * @qid: The AP queue number
216 * @ind: The notification indicator byte
217 *
218 * Returns AP queue status.
219 */
220static inline struct ap_queue_status
221ap_queue_interruption_control(ap_qid_t qid, void *ind)
222{
223 register unsigned long reg0 asm ("0") = qid | 0x03000000UL;
224 register unsigned long reg1_in asm ("1") = 0x0000800000000000UL | AP_ISC;
225 register struct ap_queue_status reg1_out asm ("1");
226 register void *reg2 asm ("2") = ind;
227 asm volatile(
Holger Denglera7475af2012-05-16 14:10:26 +0200228 ".long 0xb2af0000" /* PQAP(AQIC) */
Felix Beckcb17a632008-12-25 13:38:41 +0100229 : "+d" (reg0), "+d" (reg1_in), "=d" (reg1_out), "+d" (reg2)
230 :
231 : "cc" );
232 return reg1_out;
233}
Felix Beckcb17a632008-12-25 13:38:41 +0100234
Martin Schwidefsky889875a2015-06-26 16:55:35 +0200235/**
236 * ap_query_configuration(): Get AP configuration data
237 *
238 * Returns 0 on success, or -EOPNOTSUPP.
239 */
240static inline int ap_query_configuration(void)
Holger Dengler75014552012-08-28 16:41:50 +0200241{
242 register unsigned long reg0 asm ("0") = 0x04000000UL;
243 register unsigned long reg1 asm ("1") = -EINVAL;
Martin Schwidefsky889875a2015-06-26 16:55:35 +0200244 register void *reg2 asm ("2") = (void *) ap_configuration;
Holger Dengler75014552012-08-28 16:41:50 +0200245
Martin Schwidefsky889875a2015-06-26 16:55:35 +0200246 if (!ap_configuration)
247 return -EOPNOTSUPP;
Holger Dengler75014552012-08-28 16:41:50 +0200248 asm volatile(
249 ".long 0xb2af0000\n" /* PQAP(QCI) */
250 "0: la %1,0\n"
251 "1:\n"
252 EX_TABLE(0b, 1b)
253 : "+d" (reg0), "+d" (reg1), "+d" (reg2)
254 :
255 : "cc");
256
257 return reg1;
258}
Holger Dengler75014552012-08-28 16:41:50 +0200259
Holger Dengler6bed05b2011-07-24 10:48:25 +0200260/**
Martin Schwidefsky889875a2015-06-26 16:55:35 +0200261 * ap_init_configuration(): Allocate and query configuration array.
262 */
263static void ap_init_configuration(void)
264{
265 if (!ap_configuration_available())
266 return;
267
268 ap_configuration = kzalloc(sizeof(*ap_configuration), GFP_KERNEL);
269 if (!ap_configuration)
270 return;
271 if (ap_query_configuration() != 0) {
272 kfree(ap_configuration);
273 ap_configuration = NULL;
274 return;
275 }
276}
277
278/*
279 * ap_test_config(): helper function to extract the nrth bit
280 * within the unsigned int array field.
281 */
282static inline int ap_test_config(unsigned int *field, unsigned int nr)
283{
284 return ap_test_bit((field + (nr >> 5)), (nr & 0x1f));
285}
286
287/*
288 * ap_test_config_card_id(): Test, whether an AP card ID is configured.
289 * @id AP card ID
290 *
291 * Returns 0 if the card is not configured
292 * 1 if the card is configured or
293 * if the configuration information is not available
294 */
295static inline int ap_test_config_card_id(unsigned int id)
296{
297 if (!ap_configuration) /* QCI not supported */
298 return 1;
299 return ap_test_config(ap_configuration->apm, id);
300}
301
302/*
303 * ap_test_config_domain(): Test, whether an AP usage domain is configured.
304 * @domain AP usage domain ID
305 *
306 * Returns 0 if the usage domain is not configured
307 * 1 if the usage domain is configured or
308 * if the configuration information is not available
309 */
310static inline int ap_test_config_domain(unsigned int domain)
311{
312 if (!ap_configuration) /* QCI not supported */
313 return domain < 16;
314 return ap_test_config(ap_configuration->aqm, domain);
315}
316
317/**
Felix Beckcb17a632008-12-25 13:38:41 +0100318 * ap_queue_enable_interruption(): Enable interruption on an AP.
319 * @qid: The AP queue number
320 * @ind: the notification indicator byte
321 *
322 * Enables interruption on AP queue via ap_queue_interruption_control(). Based
323 * on the return value it waits a while and tests the AP queue if interrupts
324 * have been switched on using ap_test_queue().
325 */
Ingo Tuchschererc50a1602015-06-17 16:19:15 +0200326static int ap_queue_enable_interruption(struct ap_device *ap_dev, void *ind)
Felix Beckcb17a632008-12-25 13:38:41 +0100327{
Felix Beckcb17a632008-12-25 13:38:41 +0100328 struct ap_queue_status status;
Felix Beckcb17a632008-12-25 13:38:41 +0100329
Ingo Tuchschererc50a1602015-06-17 16:19:15 +0200330 status = ap_queue_interruption_control(ap_dev->qid, ind);
331 switch (status.response_code) {
332 case AP_RESPONSE_NORMAL:
333 case AP_RESPONSE_OTHERWISE_CHANGED:
334 return 0;
335 case AP_RESPONSE_Q_NOT_AVAIL:
336 case AP_RESPONSE_DECONFIGURED:
337 case AP_RESPONSE_CHECKSTOPPED:
338 case AP_RESPONSE_INVALID_ADDRESS:
Martin Schwidefsky3f3007a2015-09-14 17:01:23 +0200339 pr_err("Registering adapter interrupts for AP %d failed\n",
340 AP_QID_DEVICE(ap_dev->qid));
341 return -EOPNOTSUPP;
Ingo Tuchschererc50a1602015-06-17 16:19:15 +0200342 case AP_RESPONSE_RESET_IN_PROGRESS:
343 case AP_RESPONSE_BUSY:
344 default:
345 return -EBUSY;
Felix Beckcb17a632008-12-25 13:38:41 +0100346 }
Felix Beckcb17a632008-12-25 13:38:41 +0100347}
348
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200349/**
Felix Beck1749a812008-04-17 07:46:28 +0200350 * __ap_send(): Send message to adjunct processor queue.
351 * @qid: The AP queue number
352 * @psmid: The program supplied message identifier
353 * @msg: The message text
354 * @length: The message length
Felix Becka6a5d732009-12-07 12:51:55 +0100355 * @special: Special Bit
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200356 *
Felix Beck1749a812008-04-17 07:46:28 +0200357 * Returns AP queue status structure.
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200358 * Condition code 1 on NQAP can't happen because the L bit is 1.
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200359 * Condition code 2 on NQAP also means the send is incomplete,
360 * because a segment boundary was reached. The NQAP is repeated.
361 */
362static inline struct ap_queue_status
Felix Becka6a5d732009-12-07 12:51:55 +0100363__ap_send(ap_qid_t qid, unsigned long long psmid, void *msg, size_t length,
364 unsigned int special)
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200365{
366 typedef struct { char _[length]; } msgblock;
367 register unsigned long reg0 asm ("0") = qid | 0x40000000UL;
368 register struct ap_queue_status reg1 asm ("1");
369 register unsigned long reg2 asm ("2") = (unsigned long) msg;
370 register unsigned long reg3 asm ("3") = (unsigned long) length;
371 register unsigned long reg4 asm ("4") = (unsigned int) (psmid >> 32);
Heiko Carstens7d6c3b42013-09-07 11:07:22 +0200372 register unsigned long reg5 asm ("5") = psmid & 0xffffffff;
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200373
Felix Becka6a5d732009-12-07 12:51:55 +0100374 if (special == 1)
375 reg0 |= 0x400000UL;
376
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200377 asm volatile (
Holger Denglera7475af2012-05-16 14:10:26 +0200378 "0: .long 0xb2ad0042\n" /* NQAP */
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200379 " brc 2,0b"
380 : "+d" (reg0), "=d" (reg1), "+d" (reg2), "+d" (reg3)
381 : "d" (reg4), "d" (reg5), "m" (*(msgblock *) msg)
382 : "cc" );
383 return reg1;
384}
385
386int ap_send(ap_qid_t qid, unsigned long long psmid, void *msg, size_t length)
387{
388 struct ap_queue_status status;
389
Felix Becka6a5d732009-12-07 12:51:55 +0100390 status = __ap_send(qid, psmid, msg, length, 0);
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200391 switch (status.response_code) {
392 case AP_RESPONSE_NORMAL:
393 return 0;
394 case AP_RESPONSE_Q_FULL:
Ralph Wuerthneraf512ed02007-07-10 11:24:19 +0200395 case AP_RESPONSE_RESET_IN_PROGRESS:
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200396 return -EBUSY;
Felix Becka6a5d732009-12-07 12:51:55 +0100397 case AP_RESPONSE_REQ_FAC_NOT_INST:
398 return -EINVAL;
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200399 default: /* Device is gone. */
400 return -ENODEV;
401 }
402}
403EXPORT_SYMBOL(ap_send);
404
Felix Beck1749a812008-04-17 07:46:28 +0200405/**
406 * __ap_recv(): Receive message from adjunct processor queue.
407 * @qid: The AP queue number
408 * @psmid: Pointer to program supplied message identifier
409 * @msg: The message text
410 * @length: The message length
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200411 *
Felix Beck1749a812008-04-17 07:46:28 +0200412 * Returns AP queue status structure.
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200413 * Condition code 1 on DQAP means the receive has taken place
414 * but only partially. The response is incomplete, hence the
415 * DQAP is repeated.
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200416 * Condition code 2 on DQAP also means the receive is incomplete,
417 * this time because a segment boundary was reached. Again, the
418 * DQAP is repeated.
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200419 * Note that gpr2 is used by the DQAP instruction to keep track of
420 * any 'residual' length, in case the instruction gets interrupted.
421 * Hence it gets zeroed before the instruction.
422 */
423static inline struct ap_queue_status
424__ap_recv(ap_qid_t qid, unsigned long long *psmid, void *msg, size_t length)
425{
426 typedef struct { char _[length]; } msgblock;
427 register unsigned long reg0 asm("0") = qid | 0x80000000UL;
428 register struct ap_queue_status reg1 asm ("1");
429 register unsigned long reg2 asm("2") = 0UL;
430 register unsigned long reg4 asm("4") = (unsigned long) msg;
431 register unsigned long reg5 asm("5") = (unsigned long) length;
432 register unsigned long reg6 asm("6") = 0UL;
433 register unsigned long reg7 asm("7") = 0UL;
434
435
436 asm volatile(
Holger Denglera7475af2012-05-16 14:10:26 +0200437 "0: .long 0xb2ae0064\n" /* DQAP */
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200438 " brc 6,0b\n"
439 : "+d" (reg0), "=d" (reg1), "+d" (reg2),
440 "+d" (reg4), "+d" (reg5), "+d" (reg6), "+d" (reg7),
441 "=m" (*(msgblock *) msg) : : "cc" );
442 *psmid = (((unsigned long long) reg6) << 32) + reg7;
443 return reg1;
444}
445
446int ap_recv(ap_qid_t qid, unsigned long long *psmid, void *msg, size_t length)
447{
448 struct ap_queue_status status;
449
450 status = __ap_recv(qid, psmid, msg, length);
451 switch (status.response_code) {
452 case AP_RESPONSE_NORMAL:
453 return 0;
454 case AP_RESPONSE_NO_PENDING_REPLY:
455 if (status.queue_empty)
456 return -ENOENT;
457 return -EBUSY;
Ralph Wuerthneraf512ed02007-07-10 11:24:19 +0200458 case AP_RESPONSE_RESET_IN_PROGRESS:
459 return -EBUSY;
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200460 default:
461 return -ENODEV;
462 }
463}
464EXPORT_SYMBOL(ap_recv);
465
466/**
Felix Beck1749a812008-04-17 07:46:28 +0200467 * ap_query_queue(): Check if an AP queue is available.
468 * @qid: The AP queue number
469 * @queue_depth: Pointer to queue depth value
470 * @device_type: Pointer to device type value
Martin Schwidefsky6acbe212015-06-26 15:40:41 +0200471 * @facilities: Pointer to facility indicator
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200472 */
Martin Schwidefsky6acbe212015-06-26 15:40:41 +0200473static int ap_query_queue(ap_qid_t qid, int *queue_depth, int *device_type,
474 unsigned int *facilities)
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200475{
476 struct ap_queue_status status;
Martin Schwidefsky6acbe212015-06-26 15:40:41 +0200477 unsigned long info;
Martin Schwidefsky889875a2015-06-26 16:55:35 +0200478 int nd;
479
480 if (!ap_test_config_card_id(AP_QID_DEVICE(qid)))
481 return -ENODEV;
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200482
Martin Schwidefsky6acbe212015-06-26 15:40:41 +0200483 status = ap_test_queue(qid, &info);
Ingo Tuchschererc50a1602015-06-17 16:19:15 +0200484 switch (status.response_code) {
485 case AP_RESPONSE_NORMAL:
Martin Schwidefsky6acbe212015-06-26 15:40:41 +0200486 *queue_depth = (int)(info & 0xff);
487 *device_type = (int)((info >> 24) & 0xff);
488 *facilities = (unsigned int)(info >> 32);
Martin Schwidefsky889875a2015-06-26 16:55:35 +0200489 /* Update maximum domain id */
490 nd = (info >> 16) & 0xff;
491 if ((info & (1UL << 57)) && nd > 0)
492 ap_max_domain_id = nd;
Ingo Tuchschererc50a1602015-06-17 16:19:15 +0200493 return 0;
494 case AP_RESPONSE_Q_NOT_AVAIL:
495 case AP_RESPONSE_DECONFIGURED:
496 case AP_RESPONSE_CHECKSTOPPED:
497 case AP_RESPONSE_INVALID_ADDRESS:
498 return -ENODEV;
499 case AP_RESPONSE_RESET_IN_PROGRESS:
500 case AP_RESPONSE_OTHERWISE_CHANGED:
501 case AP_RESPONSE_BUSY:
502 return -EBUSY;
503 default:
504 BUG();
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200505 }
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200506}
507
Martin Schwidefsky3f3007a2015-09-14 17:01:23 +0200508/* State machine definitions and helpers */
509
510static void ap_sm_wait(enum ap_wait wait)
511{
512 ktime_t hr_time;
513
514 switch (wait) {
515 case AP_WAIT_AGAIN:
516 case AP_WAIT_INTERRUPT:
517 if (ap_using_interrupts())
518 break;
519 if (ap_poll_kthread) {
520 wake_up(&ap_poll_wait);
521 break;
522 }
523 /* Fall through */
524 case AP_WAIT_TIMEOUT:
525 spin_lock_bh(&ap_poll_timer_lock);
526 if (!hrtimer_is_queued(&ap_poll_timer)) {
527 hr_time = ktime_set(0, poll_timeout);
528 hrtimer_forward_now(&ap_poll_timer, hr_time);
529 hrtimer_restart(&ap_poll_timer);
530 }
531 spin_unlock_bh(&ap_poll_timer_lock);
532 break;
533 case AP_WAIT_NONE:
534 default:
535 break;
536 }
537}
538
539static enum ap_wait ap_sm_nop(struct ap_device *ap_dev)
540{
541 return AP_WAIT_NONE;
542}
543
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200544/**
Martin Schwidefsky3f3007a2015-09-14 17:01:23 +0200545 * ap_sm_recv(): Receive pending reply messages from an AP device but do
546 * not change the state of the device.
547 * @ap_dev: pointer to the AP device
548 *
549 * Returns AP_WAIT_NONE, AP_WAIT_AGAIN, or AP_WAIT_INTERRUPT
550 */
551static struct ap_queue_status ap_sm_recv(struct ap_device *ap_dev)
552{
553 struct ap_queue_status status;
554 struct ap_message *ap_msg;
555
556 status = __ap_recv(ap_dev->qid, &ap_dev->reply->psmid,
557 ap_dev->reply->message, ap_dev->reply->length);
558 switch (status.response_code) {
559 case AP_RESPONSE_NORMAL:
560 atomic_dec(&ap_poll_requests);
561 ap_dev->queue_count--;
562 if (ap_dev->queue_count > 0)
563 mod_timer(&ap_dev->timeout,
564 jiffies + ap_dev->drv->request_timeout);
565 list_for_each_entry(ap_msg, &ap_dev->pendingq, list) {
566 if (ap_msg->psmid != ap_dev->reply->psmid)
567 continue;
568 list_del_init(&ap_msg->list);
569 ap_dev->pendingq_count--;
570 ap_msg->receive(ap_dev, ap_msg, ap_dev->reply);
571 break;
572 }
573 case AP_RESPONSE_NO_PENDING_REPLY:
574 if (!status.queue_empty || ap_dev->queue_count <= 0)
575 break;
576 /* The card shouldn't forget requests but who knows. */
577 atomic_sub(ap_dev->queue_count, &ap_poll_requests);
578 ap_dev->queue_count = 0;
579 list_splice_init(&ap_dev->pendingq, &ap_dev->requestq);
580 ap_dev->requestq_count += ap_dev->pendingq_count;
581 ap_dev->pendingq_count = 0;
582 break;
583 default:
584 break;
585 }
586 return status;
587}
588
589/**
590 * ap_sm_read(): Receive pending reply messages from an AP device.
591 * @ap_dev: pointer to the AP device
592 *
593 * Returns AP_WAIT_NONE, AP_WAIT_AGAIN, or AP_WAIT_INTERRUPT
594 */
595static enum ap_wait ap_sm_read(struct ap_device *ap_dev)
596{
597 struct ap_queue_status status;
598
599 status = ap_sm_recv(ap_dev);
600 switch (status.response_code) {
601 case AP_RESPONSE_NORMAL:
602 if (ap_dev->queue_count > 0)
603 return AP_WAIT_AGAIN;
604 ap_dev->state = AP_STATE_IDLE;
605 return AP_WAIT_NONE;
606 case AP_RESPONSE_NO_PENDING_REPLY:
607 if (ap_dev->queue_count > 0)
608 return AP_WAIT_INTERRUPT;
609 ap_dev->state = AP_STATE_IDLE;
610 return AP_WAIT_NONE;
611 default:
612 ap_dev->state = AP_STATE_BORKED;
613 return AP_WAIT_NONE;
614 }
615}
616
617/**
618 * ap_sm_write(): Send messages from the request queue to an AP device.
619 * @ap_dev: pointer to the AP device
620 *
621 * Returns AP_WAIT_NONE, AP_WAIT_AGAIN, or AP_WAIT_INTERRUPT
622 */
623static enum ap_wait ap_sm_write(struct ap_device *ap_dev)
624{
625 struct ap_queue_status status;
626 struct ap_message *ap_msg;
627
628 if (ap_dev->requestq_count <= 0)
629 return AP_WAIT_NONE;
630 /* Start the next request on the queue. */
631 ap_msg = list_entry(ap_dev->requestq.next, struct ap_message, list);
632 status = __ap_send(ap_dev->qid, ap_msg->psmid,
633 ap_msg->message, ap_msg->length, ap_msg->special);
634 switch (status.response_code) {
635 case AP_RESPONSE_NORMAL:
636 atomic_inc(&ap_poll_requests);
637 ap_dev->queue_count++;
638 if (ap_dev->queue_count == 1)
639 mod_timer(&ap_dev->timeout,
640 jiffies + ap_dev->drv->request_timeout);
641 list_move_tail(&ap_msg->list, &ap_dev->pendingq);
642 ap_dev->requestq_count--;
643 ap_dev->pendingq_count++;
644 if (ap_dev->queue_count < ap_dev->queue_depth) {
645 ap_dev->state = AP_STATE_WORKING;
646 return AP_WAIT_AGAIN;
647 }
648 /* fall through */
649 case AP_RESPONSE_Q_FULL:
650 ap_dev->state = AP_STATE_QUEUE_FULL;
651 return AP_WAIT_INTERRUPT;
652 case AP_RESPONSE_RESET_IN_PROGRESS:
653 ap_dev->state = AP_STATE_RESET_WAIT;
654 return AP_WAIT_TIMEOUT;
655 case AP_RESPONSE_MESSAGE_TOO_BIG:
656 case AP_RESPONSE_REQ_FAC_NOT_INST:
657 list_del_init(&ap_msg->list);
658 ap_dev->requestq_count--;
659 ap_msg->rc = -EINVAL;
660 ap_msg->receive(ap_dev, ap_msg, NULL);
661 return AP_WAIT_AGAIN;
662 default:
663 ap_dev->state = AP_STATE_BORKED;
664 return AP_WAIT_NONE;
665 }
666}
667
668/**
669 * ap_sm_read_write(): Send and receive messages to/from an AP device.
670 * @ap_dev: pointer to the AP device
671 *
672 * Returns AP_WAIT_NONE, AP_WAIT_AGAIN, or AP_WAIT_INTERRUPT
673 */
674static enum ap_wait ap_sm_read_write(struct ap_device *ap_dev)
675{
676 return min(ap_sm_read(ap_dev), ap_sm_write(ap_dev));
677}
678
679/**
680 * ap_sm_reset(): Reset an AP queue.
Felix Beck1749a812008-04-17 07:46:28 +0200681 * @qid: The AP queue number
682 *
Ingo Tuchschererc50a1602015-06-17 16:19:15 +0200683 * Submit the Reset command to an AP queue.
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200684 */
Martin Schwidefsky3f3007a2015-09-14 17:01:23 +0200685static enum ap_wait ap_sm_reset(struct ap_device *ap_dev)
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200686{
687 struct ap_queue_status status;
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200688
Ingo Tuchschererc50a1602015-06-17 16:19:15 +0200689 status = ap_reset_queue(ap_dev->qid);
690 switch (status.response_code) {
691 case AP_RESPONSE_NORMAL:
Ingo Tuchschererc50a1602015-06-17 16:19:15 +0200692 case AP_RESPONSE_RESET_IN_PROGRESS:
Martin Schwidefsky3f3007a2015-09-14 17:01:23 +0200693 ap_dev->state = AP_STATE_RESET_WAIT;
694 ap_dev->interrupt = AP_INTR_DISABLED;
695 return AP_WAIT_TIMEOUT;
Ingo Tuchschererc50a1602015-06-17 16:19:15 +0200696 case AP_RESPONSE_BUSY:
Martin Schwidefsky3f3007a2015-09-14 17:01:23 +0200697 return AP_WAIT_TIMEOUT;
Ingo Tuchschererc50a1602015-06-17 16:19:15 +0200698 case AP_RESPONSE_Q_NOT_AVAIL:
699 case AP_RESPONSE_DECONFIGURED:
700 case AP_RESPONSE_CHECKSTOPPED:
701 default:
Martin Schwidefsky3f3007a2015-09-14 17:01:23 +0200702 ap_dev->state = AP_STATE_BORKED;
703 return AP_WAIT_NONE;
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200704 }
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200705}
706
707/**
Martin Schwidefsky3f3007a2015-09-14 17:01:23 +0200708 * ap_sm_reset_wait(): Test queue for completion of the reset operation
709 * @ap_dev: pointer to the AP device
Felix Beck1749a812008-04-17 07:46:28 +0200710 *
Martin Schwidefsky3f3007a2015-09-14 17:01:23 +0200711 * Returns AP_POLL_IMMEDIATELY, AP_POLL_AFTER_TIMEROUT or 0.
Ralph Wuerthneraf512ed02007-07-10 11:24:19 +0200712 */
Martin Schwidefsky3f3007a2015-09-14 17:01:23 +0200713static enum ap_wait ap_sm_reset_wait(struct ap_device *ap_dev)
Ralph Wuerthneraf512ed02007-07-10 11:24:19 +0200714{
Martin Schwidefsky3f3007a2015-09-14 17:01:23 +0200715 struct ap_queue_status status;
716 unsigned long info;
Ralph Wuerthneraf512ed02007-07-10 11:24:19 +0200717
Ralph Wuerthneraf512ed02007-07-10 11:24:19 +0200718 if (ap_dev->queue_count > 0)
Martin Schwidefsky3f3007a2015-09-14 17:01:23 +0200719 /* Try to read a completed message and get the status */
720 status = ap_sm_recv(ap_dev);
Ralph Wuerthneraf512ed02007-07-10 11:24:19 +0200721 else
Martin Schwidefsky3f3007a2015-09-14 17:01:23 +0200722 /* Get the status with TAPQ */
723 status = ap_test_queue(ap_dev->qid, &info);
724
725 switch (status.response_code) {
726 case AP_RESPONSE_NORMAL:
727 if (ap_using_interrupts() &&
728 ap_queue_enable_interruption(ap_dev,
729 ap_airq.lsi_ptr) == 0)
730 ap_dev->state = AP_STATE_SETIRQ_WAIT;
731 else
732 ap_dev->state = (ap_dev->queue_count > 0) ?
733 AP_STATE_WORKING : AP_STATE_IDLE;
734 return AP_WAIT_AGAIN;
735 case AP_RESPONSE_BUSY:
736 case AP_RESPONSE_RESET_IN_PROGRESS:
737 return AP_WAIT_TIMEOUT;
738 case AP_RESPONSE_Q_NOT_AVAIL:
739 case AP_RESPONSE_DECONFIGURED:
740 case AP_RESPONSE_CHECKSTOPPED:
741 default:
742 ap_dev->state = AP_STATE_BORKED;
743 return AP_WAIT_NONE;
744 }
745}
746
747/**
748 * ap_sm_setirq_wait(): Test queue for completion of the irq enablement
749 * @ap_dev: pointer to the AP device
750 *
751 * Returns AP_POLL_IMMEDIATELY, AP_POLL_AFTER_TIMEROUT or 0.
752 */
753static enum ap_wait ap_sm_setirq_wait(struct ap_device *ap_dev)
754{
755 struct ap_queue_status status;
756 unsigned long info;
757
758 if (ap_dev->queue_count > 0)
759 /* Try to read a completed message and get the status */
760 status = ap_sm_recv(ap_dev);
761 else
762 /* Get the status with TAPQ */
763 status = ap_test_queue(ap_dev->qid, &info);
764
765 if (status.int_enabled == 1) {
766 /* Irqs are now enabled */
767 ap_dev->interrupt = AP_INTR_ENABLED;
768 ap_dev->state = (ap_dev->queue_count > 0) ?
769 AP_STATE_WORKING : AP_STATE_IDLE;
770 }
771
772 switch (status.response_code) {
773 case AP_RESPONSE_NORMAL:
774 if (ap_dev->queue_count > 0)
775 return AP_WAIT_AGAIN;
776 /* fallthrough */
777 case AP_RESPONSE_NO_PENDING_REPLY:
778 return AP_WAIT_TIMEOUT;
779 default:
780 ap_dev->state = AP_STATE_BORKED;
781 return AP_WAIT_NONE;
782 }
783}
784
785/*
786 * AP state machine jump table
787 */
788ap_func_t *ap_jumptable[NR_AP_STATES][NR_AP_EVENTS] = {
789 [AP_STATE_RESET_START] = {
790 [AP_EVENT_POLL] = ap_sm_reset,
791 [AP_EVENT_TIMEOUT] = ap_sm_nop,
792 },
793 [AP_STATE_RESET_WAIT] = {
794 [AP_EVENT_POLL] = ap_sm_reset_wait,
795 [AP_EVENT_TIMEOUT] = ap_sm_nop,
796 },
797 [AP_STATE_SETIRQ_WAIT] = {
798 [AP_EVENT_POLL] = ap_sm_setirq_wait,
799 [AP_EVENT_TIMEOUT] = ap_sm_nop,
800 },
801 [AP_STATE_IDLE] = {
802 [AP_EVENT_POLL] = ap_sm_write,
803 [AP_EVENT_TIMEOUT] = ap_sm_nop,
804 },
805 [AP_STATE_WORKING] = {
806 [AP_EVENT_POLL] = ap_sm_read_write,
807 [AP_EVENT_TIMEOUT] = ap_sm_reset,
808 },
809 [AP_STATE_QUEUE_FULL] = {
810 [AP_EVENT_POLL] = ap_sm_read,
811 [AP_EVENT_TIMEOUT] = ap_sm_reset,
812 },
813 [AP_STATE_SUSPEND_WAIT] = {
814 [AP_EVENT_POLL] = ap_sm_read,
815 [AP_EVENT_TIMEOUT] = ap_sm_nop,
816 },
817 [AP_STATE_BORKED] = {
818 [AP_EVENT_POLL] = ap_sm_nop,
819 [AP_EVENT_TIMEOUT] = ap_sm_nop,
820 },
821};
822
823static inline enum ap_wait ap_sm_event(struct ap_device *ap_dev,
824 enum ap_event event)
825{
826 return ap_jumptable[ap_dev->state][event](ap_dev);
827}
828
829static inline enum ap_wait ap_sm_event_loop(struct ap_device *ap_dev,
830 enum ap_event event)
831{
832 enum ap_wait wait;
833
834 while ((wait = ap_sm_event(ap_dev, event)) == AP_WAIT_AGAIN)
835 ;
836 return wait;
837}
838
839/**
840 * ap_request_timeout(): Handling of request timeouts
841 * @data: Holds the AP device.
842 *
843 * Handles request timeouts.
844 */
845static void ap_request_timeout(unsigned long data)
846{
847 struct ap_device *ap_dev = (struct ap_device *) data;
848
849 if (ap_suspend_flag)
850 return;
851 spin_lock_bh(&ap_dev->lock);
852 ap_sm_wait(ap_sm_event(ap_dev, AP_EVENT_TIMEOUT));
853 spin_unlock_bh(&ap_dev->lock);
854}
855
856/**
857 * ap_poll_timeout(): AP receive polling for finished AP requests.
858 * @unused: Unused pointer.
859 *
860 * Schedules the AP tasklet using a high resolution timer.
861 */
862static enum hrtimer_restart ap_poll_timeout(struct hrtimer *unused)
863{
864 if (!ap_suspend_flag)
865 tasklet_schedule(&ap_tasklet);
866 return HRTIMER_NORESTART;
867}
868
869/**
870 * ap_interrupt_handler() - Schedule ap_tasklet on interrupt
871 * @airq: pointer to adapter interrupt descriptor
872 */
873static void ap_interrupt_handler(struct airq_struct *airq)
874{
875 inc_irq_stat(IRQIO_APB);
876 if (!ap_suspend_flag)
877 tasklet_schedule(&ap_tasklet);
878}
879
880/**
881 * ap_tasklet_fn(): Tasklet to poll all AP devices.
882 * @dummy: Unused variable
883 *
884 * Poll all AP devices on the bus.
885 */
886static void ap_tasklet_fn(unsigned long dummy)
887{
888 struct ap_device *ap_dev;
889 enum ap_wait wait = AP_WAIT_NONE;
890
891 /* Reset the indicator if interrupts are used. Thus new interrupts can
892 * be received. Doing it in the beginning of the tasklet is therefor
893 * important that no requests on any AP get lost.
894 */
895 if (ap_using_interrupts())
896 xchg(ap_airq.lsi_ptr, 0);
897
898 spin_lock(&ap_device_list_lock);
899 list_for_each_entry(ap_dev, &ap_device_list, list) {
900 spin_lock_bh(&ap_dev->lock);
901 wait = min(wait, ap_sm_event_loop(ap_dev, AP_EVENT_POLL));
902 spin_unlock_bh(&ap_dev->lock);
903 }
904 spin_unlock(&ap_device_list_lock);
905 ap_sm_wait(wait);
Ralph Wuerthneraf512ed02007-07-10 11:24:19 +0200906}
907
Martin Schwidefsky83e9d5d2015-07-17 13:43:18 +0200908/**
909 * ap_poll_thread(): Thread that polls for finished requests.
910 * @data: Unused pointer
911 *
912 * AP bus poll thread. The purpose of this thread is to poll for
913 * finished requests in a loop if there is a "free" cpu - that is
914 * a cpu that doesn't have anything better to do. The polling stops
915 * as soon as there is another task or if all messages have been
916 * delivered.
917 */
918static int ap_poll_thread(void *data)
919{
920 DECLARE_WAITQUEUE(wait, current);
Martin Schwidefsky83e9d5d2015-07-17 13:43:18 +0200921
922 set_user_nice(current, MAX_NICE);
923 set_freezable();
924 while (!kthread_should_stop()) {
925 add_wait_queue(&ap_poll_wait, &wait);
926 set_current_state(TASK_INTERRUPTIBLE);
927 if (ap_suspend_flag ||
928 atomic_read(&ap_poll_requests) <= 0) {
929 schedule();
930 try_to_freeze();
931 }
932 set_current_state(TASK_RUNNING);
933 remove_wait_queue(&ap_poll_wait, &wait);
Martin Schwidefsky83e9d5d2015-07-17 13:43:18 +0200934 if (need_resched()) {
935 schedule();
936 try_to_freeze();
937 continue;
938 }
Martin Schwidefsky3f3007a2015-09-14 17:01:23 +0200939 ap_tasklet_fn(0);
Martin Schwidefsky83e9d5d2015-07-17 13:43:18 +0200940 } while (!kthread_should_stop());
941 return 0;
942}
943
944static int ap_poll_thread_start(void)
945{
946 int rc;
947
948 if (ap_using_interrupts() || ap_poll_kthread)
949 return 0;
950 mutex_lock(&ap_poll_thread_mutex);
951 ap_poll_kthread = kthread_run(ap_poll_thread, NULL, "appoll");
952 rc = PTR_RET(ap_poll_kthread);
953 if (rc)
954 ap_poll_kthread = NULL;
955 mutex_unlock(&ap_poll_thread_mutex);
956 return rc;
957}
958
959static void ap_poll_thread_stop(void)
960{
961 if (!ap_poll_kthread)
962 return;
963 mutex_lock(&ap_poll_thread_mutex);
964 kthread_stop(ap_poll_kthread);
965 ap_poll_kthread = NULL;
966 mutex_unlock(&ap_poll_thread_mutex);
967}
968
Martin Schwidefsky3f3007a2015-09-14 17:01:23 +0200969/**
970 * ap_queue_message(): Queue a request to an AP device.
971 * @ap_dev: The AP device to queue the message to
972 * @ap_msg: The message that is to be added
973 */
974void ap_queue_message(struct ap_device *ap_dev, struct ap_message *ap_msg)
975{
976 /* For asynchronous message handling a valid receive-callback
977 * is required. */
978 BUG_ON(!ap_msg->receive);
979
980 spin_lock_bh(&ap_dev->lock);
981 /* Queue the message. */
982 list_add_tail(&ap_msg->list, &ap_dev->requestq);
983 ap_dev->requestq_count++;
984 ap_dev->total_request_count++;
985 /* Send/receive as many request from the queue as possible. */
986 ap_sm_wait(ap_sm_event_loop(ap_dev, AP_EVENT_POLL));
987 spin_unlock_bh(&ap_dev->lock);
988}
989EXPORT_SYMBOL(ap_queue_message);
990
991/**
992 * ap_cancel_message(): Cancel a crypto request.
993 * @ap_dev: The AP device that has the message queued
994 * @ap_msg: The message that is to be removed
995 *
996 * Cancel a crypto request. This is done by removing the request
997 * from the device pending or request queue. Note that the
998 * request stays on the AP queue. When it finishes the message
999 * reply will be discarded because the psmid can't be found.
1000 */
1001void ap_cancel_message(struct ap_device *ap_dev, struct ap_message *ap_msg)
1002{
1003 struct ap_message *tmp;
1004
1005 spin_lock_bh(&ap_dev->lock);
1006 if (!list_empty(&ap_msg->list)) {
1007 list_for_each_entry(tmp, &ap_dev->pendingq, list)
1008 if (tmp->psmid == ap_msg->psmid) {
1009 ap_dev->pendingq_count--;
1010 goto found;
1011 }
1012 ap_dev->requestq_count--;
1013found:
1014 list_del_init(&ap_msg->list);
1015 }
1016 spin_unlock_bh(&ap_dev->lock);
1017}
1018EXPORT_SYMBOL(ap_cancel_message);
1019
Felix Beck1749a812008-04-17 07:46:28 +02001020/*
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001021 * AP device related attributes.
1022 */
1023static ssize_t ap_hwtype_show(struct device *dev,
1024 struct device_attribute *attr, char *buf)
1025{
1026 struct ap_device *ap_dev = to_ap_dev(dev);
1027 return snprintf(buf, PAGE_SIZE, "%d\n", ap_dev->device_type);
1028}
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001029
Christian Maaser43c207e62008-12-25 13:38:42 +01001030static DEVICE_ATTR(hwtype, 0444, ap_hwtype_show, NULL);
Ingo Tuchscherer42f4dd612014-10-02 14:48:46 +02001031
1032static ssize_t ap_raw_hwtype_show(struct device *dev,
1033 struct device_attribute *attr, char *buf)
1034{
1035 struct ap_device *ap_dev = to_ap_dev(dev);
1036
1037 return snprintf(buf, PAGE_SIZE, "%d\n", ap_dev->raw_hwtype);
1038}
1039
1040static DEVICE_ATTR(raw_hwtype, 0444, ap_raw_hwtype_show, NULL);
1041
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001042static ssize_t ap_depth_show(struct device *dev, struct device_attribute *attr,
1043 char *buf)
1044{
1045 struct ap_device *ap_dev = to_ap_dev(dev);
1046 return snprintf(buf, PAGE_SIZE, "%d\n", ap_dev->queue_depth);
1047}
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001048
Christian Maaser43c207e62008-12-25 13:38:42 +01001049static DEVICE_ATTR(depth, 0444, ap_depth_show, NULL);
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001050static ssize_t ap_request_count_show(struct device *dev,
1051 struct device_attribute *attr,
1052 char *buf)
1053{
1054 struct ap_device *ap_dev = to_ap_dev(dev);
1055 int rc;
1056
1057 spin_lock_bh(&ap_dev->lock);
1058 rc = snprintf(buf, PAGE_SIZE, "%d\n", ap_dev->total_request_count);
1059 spin_unlock_bh(&ap_dev->lock);
1060 return rc;
1061}
1062
1063static DEVICE_ATTR(request_count, 0444, ap_request_count_show, NULL);
1064
Holger Denglerb26bd942012-08-28 16:43:48 +02001065static ssize_t ap_requestq_count_show(struct device *dev,
1066 struct device_attribute *attr, char *buf)
1067{
1068 struct ap_device *ap_dev = to_ap_dev(dev);
1069 int rc;
1070
1071 spin_lock_bh(&ap_dev->lock);
1072 rc = snprintf(buf, PAGE_SIZE, "%d\n", ap_dev->requestq_count);
1073 spin_unlock_bh(&ap_dev->lock);
1074 return rc;
1075}
1076
1077static DEVICE_ATTR(requestq_count, 0444, ap_requestq_count_show, NULL);
1078
1079static ssize_t ap_pendingq_count_show(struct device *dev,
1080 struct device_attribute *attr, char *buf)
1081{
1082 struct ap_device *ap_dev = to_ap_dev(dev);
1083 int rc;
1084
1085 spin_lock_bh(&ap_dev->lock);
1086 rc = snprintf(buf, PAGE_SIZE, "%d\n", ap_dev->pendingq_count);
1087 spin_unlock_bh(&ap_dev->lock);
1088 return rc;
1089}
1090
1091static DEVICE_ATTR(pendingq_count, 0444, ap_pendingq_count_show, NULL);
1092
Ingo Tuchschererc50a1602015-06-17 16:19:15 +02001093static ssize_t ap_reset_show(struct device *dev,
1094 struct device_attribute *attr, char *buf)
1095{
1096 struct ap_device *ap_dev = to_ap_dev(dev);
1097 int rc = 0;
1098
1099 spin_lock_bh(&ap_dev->lock);
Martin Schwidefsky3f3007a2015-09-14 17:01:23 +02001100 switch (ap_dev->state) {
1101 case AP_STATE_RESET_START:
1102 case AP_STATE_RESET_WAIT:
Ingo Tuchschererc50a1602015-06-17 16:19:15 +02001103 rc = snprintf(buf, PAGE_SIZE, "Reset in progress.\n");
1104 break;
Martin Schwidefsky3f3007a2015-09-14 17:01:23 +02001105 case AP_STATE_WORKING:
1106 case AP_STATE_QUEUE_FULL:
1107 rc = snprintf(buf, PAGE_SIZE, "Reset Timer armed.\n");
Ingo Tuchschererc50a1602015-06-17 16:19:15 +02001108 break;
Martin Schwidefsky3f3007a2015-09-14 17:01:23 +02001109 default:
1110 rc = snprintf(buf, PAGE_SIZE, "No Reset Timer set.\n");
Ingo Tuchschererc50a1602015-06-17 16:19:15 +02001111 }
1112 spin_unlock_bh(&ap_dev->lock);
1113 return rc;
1114}
1115
1116static DEVICE_ATTR(reset, 0444, ap_reset_show, NULL);
1117
1118static ssize_t ap_interrupt_show(struct device *dev,
1119 struct device_attribute *attr, char *buf)
1120{
1121 struct ap_device *ap_dev = to_ap_dev(dev);
1122 int rc = 0;
1123
1124 spin_lock_bh(&ap_dev->lock);
Martin Schwidefsky3f3007a2015-09-14 17:01:23 +02001125 if (ap_dev->state == AP_STATE_SETIRQ_WAIT)
Ingo Tuchschererc50a1602015-06-17 16:19:15 +02001126 rc = snprintf(buf, PAGE_SIZE, "Enable Interrupt pending.\n");
Martin Schwidefsky3f3007a2015-09-14 17:01:23 +02001127 else if (ap_dev->interrupt == AP_INTR_ENABLED)
1128 rc = snprintf(buf, PAGE_SIZE, "Interrupts enabled.\n");
1129 else
1130 rc = snprintf(buf, PAGE_SIZE, "Interrupts disabled.\n");
Ingo Tuchschererc50a1602015-06-17 16:19:15 +02001131 spin_unlock_bh(&ap_dev->lock);
1132 return rc;
1133}
1134
1135static DEVICE_ATTR(interrupt, 0444, ap_interrupt_show, NULL);
1136
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001137static ssize_t ap_modalias_show(struct device *dev,
1138 struct device_attribute *attr, char *buf)
1139{
Ingo Tuchschererc50a1602015-06-17 16:19:15 +02001140 return sprintf(buf, "ap:t%02X\n", to_ap_dev(dev)->device_type);
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001141}
1142
1143static DEVICE_ATTR(modalias, 0444, ap_modalias_show, NULL);
1144
Holger Denglerb26bd942012-08-28 16:43:48 +02001145static ssize_t ap_functions_show(struct device *dev,
1146 struct device_attribute *attr, char *buf)
1147{
1148 struct ap_device *ap_dev = to_ap_dev(dev);
1149 return snprintf(buf, PAGE_SIZE, "0x%08X\n", ap_dev->functions);
1150}
1151
1152static DEVICE_ATTR(ap_functions, 0444, ap_functions_show, NULL);
1153
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001154static struct attribute *ap_dev_attrs[] = {
1155 &dev_attr_hwtype.attr,
Ingo Tuchscherer42f4dd612014-10-02 14:48:46 +02001156 &dev_attr_raw_hwtype.attr,
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001157 &dev_attr_depth.attr,
1158 &dev_attr_request_count.attr,
Holger Denglerb26bd942012-08-28 16:43:48 +02001159 &dev_attr_requestq_count.attr,
1160 &dev_attr_pendingq_count.attr,
Ingo Tuchschererc50a1602015-06-17 16:19:15 +02001161 &dev_attr_reset.attr,
1162 &dev_attr_interrupt.attr,
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001163 &dev_attr_modalias.attr,
Holger Denglerb26bd942012-08-28 16:43:48 +02001164 &dev_attr_ap_functions.attr,
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001165 NULL
1166};
1167static struct attribute_group ap_dev_attr_group = {
1168 .attrs = ap_dev_attrs
1169};
1170
1171/**
Felix Beck1749a812008-04-17 07:46:28 +02001172 * ap_bus_match()
1173 * @dev: Pointer to device
1174 * @drv: Pointer to device_driver
1175 *
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001176 * AP bus driver registration/unregistration.
1177 */
1178static int ap_bus_match(struct device *dev, struct device_driver *drv)
1179{
1180 struct ap_device *ap_dev = to_ap_dev(dev);
1181 struct ap_driver *ap_drv = to_ap_drv(drv);
1182 struct ap_device_id *id;
1183
Felix Beck1749a812008-04-17 07:46:28 +02001184 /*
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001185 * Compare device type of the device with the list of
1186 * supported types of the device_driver.
1187 */
1188 for (id = ap_drv->ids; id->match_flags; id++) {
1189 if ((id->match_flags & AP_DEVICE_ID_MATCH_DEVICE_TYPE) &&
1190 (id->dev_type != ap_dev->device_type))
1191 continue;
1192 return 1;
1193 }
1194 return 0;
1195}
1196
1197/**
Felix Beck1749a812008-04-17 07:46:28 +02001198 * ap_uevent(): Uevent function for AP devices.
1199 * @dev: Pointer to device
1200 * @env: Pointer to kobj_uevent_env
1201 *
1202 * It sets up a single environment variable DEV_TYPE which contains the
1203 * hardware device type.
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001204 */
Kay Sievers7eff2e72007-08-14 15:15:12 +02001205static int ap_uevent (struct device *dev, struct kobj_uevent_env *env)
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001206{
1207 struct ap_device *ap_dev = to_ap_dev(dev);
Kay Sievers7eff2e72007-08-14 15:15:12 +02001208 int retval = 0;
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001209
1210 if (!ap_dev)
1211 return -ENODEV;
1212
1213 /* Set up DEV_TYPE environment variable. */
Kay Sievers7eff2e72007-08-14 15:15:12 +02001214 retval = add_uevent_var(env, "DEV_TYPE=%04X", ap_dev->device_type);
Eric Rannaudbf624562007-03-30 22:23:12 -07001215 if (retval)
1216 return retval;
1217
Cornelia Huck66a4263b2006-12-04 15:40:10 +01001218 /* Add MODALIAS= */
Kay Sievers7eff2e72007-08-14 15:15:12 +02001219 retval = add_uevent_var(env, "MODALIAS=ap:t%02X", ap_dev->device_type);
Eric Rannaudbf624562007-03-30 22:23:12 -07001220
Eric Rannaudbf624562007-03-30 22:23:12 -07001221 return retval;
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001222}
1223
Martin Schwidefsky83e9d5d2015-07-17 13:43:18 +02001224static int ap_dev_suspend(struct device *dev, pm_message_t state)
Felix Beck772f5472009-06-22 12:08:16 +02001225{
1226 struct ap_device *ap_dev = to_ap_dev(dev);
Felix Beck772f5472009-06-22 12:08:16 +02001227
Felix Beck772f5472009-06-22 12:08:16 +02001228 /* Poll on the device until all requests are finished. */
Martin Schwidefsky3f3007a2015-09-14 17:01:23 +02001229 spin_lock_bh(&ap_dev->lock);
1230 ap_dev->state = AP_STATE_SUSPEND_WAIT;
1231 while (ap_sm_event(ap_dev, AP_EVENT_POLL) != AP_WAIT_NONE)
1232 ;
1233 ap_dev->state = AP_STATE_BORKED;
1234 spin_unlock_bh(&ap_dev->lock);
Felix Beck772f5472009-06-22 12:08:16 +02001235 return 0;
1236}
1237
Martin Schwidefsky83e9d5d2015-07-17 13:43:18 +02001238static int ap_dev_resume(struct device *dev)
Felix Beck772f5472009-06-22 12:08:16 +02001239{
Martin Schwidefsky83e9d5d2015-07-17 13:43:18 +02001240 return 0;
1241}
1242
1243static void ap_bus_suspend(void)
1244{
1245 ap_suspend_flag = 1;
1246 /*
1247 * Disable scanning for devices, thus we do not want to scan
1248 * for them after removing.
1249 */
Martin Schwidefsky8139b892015-07-27 12:47:40 +02001250 flush_work(&ap_scan_work);
Martin Schwidefsky83e9d5d2015-07-17 13:43:18 +02001251 tasklet_disable(&ap_tasklet);
1252}
1253
1254static int __ap_devices_unregister(struct device *dev, void *dummy)
1255{
1256 device_unregister(dev);
1257 return 0;
1258}
1259
1260static void ap_bus_resume(void)
1261{
Martin Schwidefskyf4eae942013-06-24 10:30:41 +02001262 int rc;
Felix Beck772f5472009-06-22 12:08:16 +02001263
Martin Schwidefsky83e9d5d2015-07-17 13:43:18 +02001264 /* Unconditionally remove all AP devices */
1265 bus_for_each_dev(&ap_bus_type, NULL, NULL, __ap_devices_unregister);
1266 /* Reset thin interrupt setting */
1267 if (ap_interrupts_available() && !ap_using_interrupts()) {
1268 rc = register_adapter_interrupt(&ap_airq);
1269 ap_airq_flag = (rc == 0);
Felix Beck5314af62009-09-22 22:58:51 +02001270 }
Martin Schwidefsky83e9d5d2015-07-17 13:43:18 +02001271 if (!ap_interrupts_available() && ap_using_interrupts()) {
1272 unregister_adapter_interrupt(&ap_airq);
1273 ap_airq_flag = 0;
1274 }
1275 /* Reset domain */
1276 if (!user_set_domain)
1277 ap_domain_index = -1;
1278 /* Get things going again */
1279 ap_suspend_flag = 0;
1280 if (ap_airq_flag)
1281 xchg(ap_airq.lsi_ptr, 0);
1282 tasklet_enable(&ap_tasklet);
Martin Schwidefsky8139b892015-07-27 12:47:40 +02001283 queue_work(system_long_wq, &ap_scan_work);
Felix Beck772f5472009-06-22 12:08:16 +02001284}
1285
Martin Schwidefsky83e9d5d2015-07-17 13:43:18 +02001286static int ap_power_event(struct notifier_block *this, unsigned long event,
1287 void *ptr)
1288{
1289 switch (event) {
1290 case PM_HIBERNATION_PREPARE:
1291 case PM_SUSPEND_PREPARE:
1292 ap_bus_suspend();
1293 break;
1294 case PM_POST_HIBERNATION:
1295 case PM_POST_SUSPEND:
1296 ap_bus_resume();
1297 break;
1298 default:
1299 break;
1300 }
1301 return NOTIFY_DONE;
1302}
1303static struct notifier_block ap_power_notifier = {
1304 .notifier_call = ap_power_event,
1305};
1306
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001307static struct bus_type ap_bus_type = {
1308 .name = "ap",
1309 .match = &ap_bus_match,
1310 .uevent = &ap_uevent,
Martin Schwidefsky83e9d5d2015-07-17 13:43:18 +02001311 .suspend = ap_dev_suspend,
1312 .resume = ap_dev_resume,
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001313};
1314
1315static int ap_device_probe(struct device *dev)
1316{
1317 struct ap_device *ap_dev = to_ap_dev(dev);
1318 struct ap_driver *ap_drv = to_ap_drv(dev->driver);
1319 int rc;
1320
1321 ap_dev->drv = ap_drv;
1322 rc = ap_drv->probe ? ap_drv->probe(ap_dev) : -ENODEV;
Martin Schwidefsky3f3007a2015-09-14 17:01:23 +02001323 if (rc)
1324 ap_dev->drv = NULL;
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001325 return rc;
1326}
1327
1328/**
Felix Beck1749a812008-04-17 07:46:28 +02001329 * __ap_flush_queue(): Flush requests.
1330 * @ap_dev: Pointer to the AP device
1331 *
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001332 * Flush all requests from the request/pending queue of an AP device.
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001333 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +01001334static void __ap_flush_queue(struct ap_device *ap_dev)
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001335{
1336 struct ap_message *ap_msg, *next;
1337
1338 list_for_each_entry_safe(ap_msg, next, &ap_dev->pendingq, list) {
1339 list_del_init(&ap_msg->list);
1340 ap_dev->pendingq_count--;
Martin Schwidefskyf58fe332015-09-14 16:59:27 +02001341 ap_msg->rc = -EAGAIN;
1342 ap_msg->receive(ap_dev, ap_msg, NULL);
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001343 }
1344 list_for_each_entry_safe(ap_msg, next, &ap_dev->requestq, list) {
1345 list_del_init(&ap_msg->list);
1346 ap_dev->requestq_count--;
Martin Schwidefskyf58fe332015-09-14 16:59:27 +02001347 ap_msg->rc = -EAGAIN;
1348 ap_msg->receive(ap_dev, ap_msg, NULL);
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001349 }
1350}
1351
1352void ap_flush_queue(struct ap_device *ap_dev)
1353{
1354 spin_lock_bh(&ap_dev->lock);
1355 __ap_flush_queue(ap_dev);
1356 spin_unlock_bh(&ap_dev->lock);
1357}
1358EXPORT_SYMBOL(ap_flush_queue);
1359
1360static int ap_device_remove(struct device *dev)
1361{
1362 struct ap_device *ap_dev = to_ap_dev(dev);
1363 struct ap_driver *ap_drv = ap_dev->drv;
1364
Ralph Wuerthner4e562962006-10-04 20:02:05 +02001365 ap_flush_queue(ap_dev);
Ralph Wuerthneraf512ed02007-07-10 11:24:19 +02001366 del_timer_sync(&ap_dev->timeout);
Christian Maaser43c207e62008-12-25 13:38:42 +01001367 spin_lock_bh(&ap_device_list_lock);
Ralph Wuerthnercf352ce2007-03-19 13:19:14 +01001368 list_del_init(&ap_dev->list);
Christian Maaser43c207e62008-12-25 13:38:42 +01001369 spin_unlock_bh(&ap_device_list_lock);
Ralph Wuerthnerfaa582c2008-03-05 12:37:13 +01001370 if (ap_drv->remove)
1371 ap_drv->remove(ap_dev);
Ralph Wuerthnere675c0d2007-03-26 20:42:43 +02001372 spin_lock_bh(&ap_dev->lock);
1373 atomic_sub(ap_dev->queue_count, &ap_poll_requests);
1374 spin_unlock_bh(&ap_dev->lock);
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001375 return 0;
1376}
1377
Martin Schwidefsky3f3007a2015-09-14 17:01:23 +02001378static void ap_device_release(struct device *dev)
1379{
1380 kfree(to_ap_dev(dev));
1381}
1382
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001383int ap_driver_register(struct ap_driver *ap_drv, struct module *owner,
1384 char *name)
1385{
1386 struct device_driver *drv = &ap_drv->driver;
1387
Sascha Silbee3877532015-10-27 18:29:52 +01001388 if (!initialised)
1389 return -ENODEV;
1390
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001391 drv->bus = &ap_bus_type;
1392 drv->probe = ap_device_probe;
1393 drv->remove = ap_device_remove;
1394 drv->owner = owner;
1395 drv->name = name;
1396 return driver_register(drv);
1397}
1398EXPORT_SYMBOL(ap_driver_register);
1399
1400void ap_driver_unregister(struct ap_driver *ap_drv)
1401{
1402 driver_unregister(&ap_drv->driver);
1403}
1404EXPORT_SYMBOL(ap_driver_unregister);
1405
Holger Denglerdabecb22012-09-10 21:34:26 +02001406void ap_bus_force_rescan(void)
1407{
Martin Schwidefsky83e9d5d2015-07-17 13:43:18 +02001408 if (ap_suspend_flag)
1409 return;
Ingo Tuchscherer56bbe682013-04-12 17:52:08 +02001410 /* processing a asynchronous bus rescan */
Martin Schwidefskyfcd0d1f2015-07-23 10:55:59 +02001411 del_timer(&ap_config_timer);
Martin Schwidefsky8139b892015-07-27 12:47:40 +02001412 queue_work(system_long_wq, &ap_scan_work);
1413 flush_work(&ap_scan_work);
Holger Denglerdabecb22012-09-10 21:34:26 +02001414}
1415EXPORT_SYMBOL(ap_bus_force_rescan);
1416
Felix Beck1749a812008-04-17 07:46:28 +02001417/*
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001418 * AP bus attributes.
1419 */
1420static ssize_t ap_domain_show(struct bus_type *bus, char *buf)
1421{
1422 return snprintf(buf, PAGE_SIZE, "%d\n", ap_domain_index);
1423}
1424
1425static BUS_ATTR(ap_domain, 0444, ap_domain_show, NULL);
1426
Ingo Tuchscherer91f3e3e2013-11-20 10:47:13 +01001427static ssize_t ap_control_domain_mask_show(struct bus_type *bus, char *buf)
1428{
Martin Schwidefsky889875a2015-06-26 16:55:35 +02001429 if (!ap_configuration) /* QCI not supported */
1430 return snprintf(buf, PAGE_SIZE, "not supported\n");
1431 if (!test_facility(76))
1432 /* format 0 - 16 bit domain field */
1433 return snprintf(buf, PAGE_SIZE, "%08x%08x\n",
1434 ap_configuration->adm[0],
1435 ap_configuration->adm[1]);
1436 /* format 1 - 256 bit domain field */
1437 return snprintf(buf, PAGE_SIZE,
1438 "0x%08x%08x%08x%08x%08x%08x%08x%08x\n",
Ingo Tuchscherer91f3e3e2013-11-20 10:47:13 +01001439 ap_configuration->adm[0], ap_configuration->adm[1],
1440 ap_configuration->adm[2], ap_configuration->adm[3],
1441 ap_configuration->adm[4], ap_configuration->adm[5],
1442 ap_configuration->adm[6], ap_configuration->adm[7]);
Ingo Tuchscherer91f3e3e2013-11-20 10:47:13 +01001443}
1444
1445static BUS_ATTR(ap_control_domain_mask, 0444,
1446 ap_control_domain_mask_show, NULL);
1447
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001448static ssize_t ap_config_time_show(struct bus_type *bus, char *buf)
1449{
1450 return snprintf(buf, PAGE_SIZE, "%d\n", ap_config_time);
1451}
1452
Felix Beckcb17a632008-12-25 13:38:41 +01001453static ssize_t ap_interrupts_show(struct bus_type *bus, char *buf)
1454{
1455 return snprintf(buf, PAGE_SIZE, "%d\n",
1456 ap_using_interrupts() ? 1 : 0);
1457}
1458
1459static BUS_ATTR(ap_interrupts, 0444, ap_interrupts_show, NULL);
1460
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001461static ssize_t ap_config_time_store(struct bus_type *bus,
1462 const char *buf, size_t count)
1463{
1464 int time;
1465
1466 if (sscanf(buf, "%d\n", &time) != 1 || time < 5 || time > 120)
1467 return -EINVAL;
1468 ap_config_time = time;
Martin Schwidefskyfcd0d1f2015-07-23 10:55:59 +02001469 mod_timer(&ap_config_timer, jiffies + ap_config_time * HZ);
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001470 return count;
1471}
1472
1473static BUS_ATTR(config_time, 0644, ap_config_time_show, ap_config_time_store);
1474
1475static ssize_t ap_poll_thread_show(struct bus_type *bus, char *buf)
1476{
1477 return snprintf(buf, PAGE_SIZE, "%d\n", ap_poll_kthread ? 1 : 0);
1478}
1479
1480static ssize_t ap_poll_thread_store(struct bus_type *bus,
1481 const char *buf, size_t count)
1482{
1483 int flag, rc;
1484
1485 if (sscanf(buf, "%d\n", &flag) != 1)
1486 return -EINVAL;
1487 if (flag) {
1488 rc = ap_poll_thread_start();
1489 if (rc)
Martin Schwidefsky83e9d5d2015-07-17 13:43:18 +02001490 count = rc;
1491 } else
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001492 ap_poll_thread_stop();
1493 return count;
1494}
1495
1496static BUS_ATTR(poll_thread, 0644, ap_poll_thread_show, ap_poll_thread_store);
1497
Felix Beckfe137232008-07-14 09:59:08 +02001498static ssize_t poll_timeout_show(struct bus_type *bus, char *buf)
1499{
1500 return snprintf(buf, PAGE_SIZE, "%llu\n", poll_timeout);
1501}
1502
1503static ssize_t poll_timeout_store(struct bus_type *bus, const char *buf,
1504 size_t count)
1505{
1506 unsigned long long time;
1507 ktime_t hr_time;
1508
1509 /* 120 seconds = maximum poll interval */
Felix Beckcb17a632008-12-25 13:38:41 +01001510 if (sscanf(buf, "%llu\n", &time) != 1 || time < 1 ||
1511 time > 120000000000ULL)
Felix Beckfe137232008-07-14 09:59:08 +02001512 return -EINVAL;
1513 poll_timeout = time;
1514 hr_time = ktime_set(0, poll_timeout);
1515
Ingo Tuchscherer8cc2af72015-04-28 10:31:44 +02001516 spin_lock_bh(&ap_poll_timer_lock);
1517 hrtimer_cancel(&ap_poll_timer);
1518 hrtimer_set_expires(&ap_poll_timer, hr_time);
1519 hrtimer_start_expires(&ap_poll_timer, HRTIMER_MODE_ABS);
1520 spin_unlock_bh(&ap_poll_timer_lock);
1521
Felix Beckfe137232008-07-14 09:59:08 +02001522 return count;
1523}
1524
1525static BUS_ATTR(poll_timeout, 0644, poll_timeout_show, poll_timeout_store);
1526
Ingo Tuchscherer5bc334b2015-01-23 13:27:04 +01001527static ssize_t ap_max_domain_id_show(struct bus_type *bus, char *buf)
1528{
Martin Schwidefsky889875a2015-06-26 16:55:35 +02001529 int max_domain_id;
Ingo Tuchscherer5bc334b2015-01-23 13:27:04 +01001530
Martin Schwidefsky889875a2015-06-26 16:55:35 +02001531 if (ap_configuration)
1532 max_domain_id = ap_max_domain_id ? : -1;
1533 else
Ingo Tuchscherer5bc334b2015-01-23 13:27:04 +01001534 max_domain_id = 15;
Ingo Tuchscherer5bc334b2015-01-23 13:27:04 +01001535 return snprintf(buf, PAGE_SIZE, "%d\n", max_domain_id);
1536}
1537
1538static BUS_ATTR(ap_max_domain_id, 0444, ap_max_domain_id_show, NULL);
1539
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001540static struct bus_attribute *const ap_bus_attrs[] = {
1541 &bus_attr_ap_domain,
Ingo Tuchscherer91f3e3e2013-11-20 10:47:13 +01001542 &bus_attr_ap_control_domain_mask,
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001543 &bus_attr_config_time,
1544 &bus_attr_poll_thread,
Felix Beckcb17a632008-12-25 13:38:41 +01001545 &bus_attr_ap_interrupts,
Felix Beckfe137232008-07-14 09:59:08 +02001546 &bus_attr_poll_timeout,
Ingo Tuchscherer5bc334b2015-01-23 13:27:04 +01001547 &bus_attr_ap_max_domain_id,
Felix Beckfe137232008-07-14 09:59:08 +02001548 NULL,
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001549};
1550
Holger Dengler75014552012-08-28 16:41:50 +02001551/**
Felix Beck1749a812008-04-17 07:46:28 +02001552 * ap_select_domain(): Select an AP domain.
1553 *
1554 * Pick one of the 16 AP domains.
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001555 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +01001556static int ap_select_domain(void)
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001557{
Martin Schwidefsky6acbe212015-06-26 15:40:41 +02001558 int count, max_count, best_domain;
1559 struct ap_queue_status status;
1560 int i, j;
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001561
Felix Beck1749a812008-04-17 07:46:28 +02001562 /*
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001563 * We want to use a single domain. Either the one specified with
1564 * the "domain=" parameter or the domain with the maximum number
1565 * of devices.
1566 */
Martin Schwidefsky889875a2015-06-26 16:55:35 +02001567 if (ap_domain_index >= 0)
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001568 /* Domain has already been selected. */
1569 return 0;
1570 best_domain = -1;
1571 max_count = 0;
1572 for (i = 0; i < AP_DOMAINS; i++) {
Holger Dengler75014552012-08-28 16:41:50 +02001573 if (!ap_test_config_domain(i))
1574 continue;
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001575 count = 0;
1576 for (j = 0; j < AP_DEVICES; j++) {
Holger Dengler75014552012-08-28 16:41:50 +02001577 if (!ap_test_config_card_id(j))
1578 continue;
Martin Schwidefsky6acbe212015-06-26 15:40:41 +02001579 status = ap_test_queue(AP_MKQID(j, i), NULL);
1580 if (status.response_code != AP_RESPONSE_NORMAL)
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001581 continue;
1582 count++;
1583 }
1584 if (count > max_count) {
1585 max_count = count;
1586 best_domain = i;
1587 }
1588 }
1589 if (best_domain >= 0){
1590 ap_domain_index = best_domain;
1591 return 0;
1592 }
1593 return -ENODEV;
1594}
1595
1596/**
Felix Beck1749a812008-04-17 07:46:28 +02001597 * __ap_scan_bus(): Scan the AP bus.
1598 * @dev: Pointer to device
1599 * @data: Pointer to data
1600 *
1601 * Scan the AP bus for new devices.
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001602 */
1603static int __ap_scan_bus(struct device *dev, void *data)
1604{
1605 return to_ap_dev(dev)->qid == (ap_qid_t)(unsigned long) data;
1606}
1607
Al Viro4927b3f2006-12-06 19:18:20 +00001608static void ap_scan_bus(struct work_struct *unused)
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001609{
1610 struct ap_device *ap_dev;
1611 struct device *dev;
1612 ap_qid_t qid;
Ingo Tuchschererc50a1602015-06-17 16:19:15 +02001613 int queue_depth = 0, device_type = 0;
Martin Schwidefsky3f3007a2015-09-14 17:01:23 +02001614 unsigned int device_functions = 0;
1615 int rc, i, borked;
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001616
Holger Dengler75014552012-08-28 16:41:50 +02001617 ap_query_configuration();
Martin Schwidefsky83e9d5d2015-07-17 13:43:18 +02001618 if (ap_select_domain() != 0)
Martin Schwidefskyfcd0d1f2015-07-23 10:55:59 +02001619 goto out;
Martin Schwidefsky889875a2015-06-26 16:55:35 +02001620
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001621 for (i = 0; i < AP_DEVICES; i++) {
1622 qid = AP_MKQID(i, ap_domain_index);
1623 dev = bus_find_device(&ap_bus_type, NULL,
1624 (void *)(unsigned long)qid,
1625 __ap_scan_bus);
Martin Schwidefsky889875a2015-06-26 16:55:35 +02001626 rc = ap_query_queue(qid, &queue_depth, &device_type,
1627 &device_functions);
Ralph Wuerthnerc6a48262007-03-26 20:42:42 +02001628 if (dev) {
1629 ap_dev = to_ap_dev(dev);
1630 spin_lock_bh(&ap_dev->lock);
Martin Schwidefsky3f3007a2015-09-14 17:01:23 +02001631 if (rc == -ENODEV)
1632 ap_dev->state = AP_STATE_BORKED;
1633 borked = ap_dev->state == AP_STATE_BORKED;
Ralph Wuerthneraf512ed02007-07-10 11:24:19 +02001634 spin_unlock_bh(&ap_dev->lock);
Martin Schwidefsky3f3007a2015-09-14 17:01:23 +02001635 if (borked) /* Remove broken device */
1636 device_unregister(dev);
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001637 put_device(dev);
Martin Schwidefsky3f3007a2015-09-14 17:01:23 +02001638 if (!borked)
1639 continue;
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001640 }
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001641 if (rc)
1642 continue;
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001643 ap_dev = kzalloc(sizeof(*ap_dev), GFP_KERNEL);
1644 if (!ap_dev)
1645 break;
1646 ap_dev->qid = qid;
Martin Schwidefsky3f3007a2015-09-14 17:01:23 +02001647 ap_dev->state = AP_STATE_RESET_START;
1648 ap_dev->interrupt = AP_INTR_DISABLED;
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001649 ap_dev->queue_depth = queue_depth;
Martin Schwidefsky6acbe212015-06-26 15:40:41 +02001650 ap_dev->raw_hwtype = device_type;
1651 ap_dev->device_type = device_type;
1652 ap_dev->functions = device_functions;
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001653 spin_lock_init(&ap_dev->lock);
1654 INIT_LIST_HEAD(&ap_dev->pendingq);
1655 INIT_LIST_HEAD(&ap_dev->requestq);
Ralph Wuerthnercf352ce2007-03-19 13:19:14 +01001656 INIT_LIST_HEAD(&ap_dev->list);
Ralph Wuerthneraf512ed02007-07-10 11:24:19 +02001657 setup_timer(&ap_dev->timeout, ap_request_timeout,
1658 (unsigned long) ap_dev);
Holger Dengler1e2076f2012-08-28 16:48:29 +02001659
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001660 ap_dev->device.bus = &ap_bus_type;
1661 ap_dev->device.parent = ap_root_device;
Martin Schwidefsky3f3007a2015-09-14 17:01:23 +02001662 rc = dev_set_name(&ap_dev->device, "card%02x",
1663 AP_QID_DEVICE(ap_dev->qid));
1664 if (rc) {
Felix Beckedc44fa2009-09-11 10:28:52 +02001665 kfree(ap_dev);
1666 continue;
1667 }
Martin Schwidefsky3f3007a2015-09-14 17:01:23 +02001668 /* Add to list of devices */
1669 spin_lock_bh(&ap_device_list_lock);
1670 list_add(&ap_dev->list, &ap_device_list);
1671 spin_unlock_bh(&ap_device_list_lock);
1672 /* Start with a device reset */
1673 spin_lock_bh(&ap_dev->lock);
1674 ap_sm_wait(ap_sm_event(ap_dev, AP_EVENT_POLL));
1675 spin_unlock_bh(&ap_dev->lock);
1676 /* Register device */
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001677 ap_dev->device.release = ap_device_release;
1678 rc = device_register(&ap_dev->device);
1679 if (rc) {
Martin Schwidefsky3f3007a2015-09-14 17:01:23 +02001680 spin_lock_bh(&ap_dev->lock);
1681 list_del_init(&ap_dev->list);
1682 spin_unlock_bh(&ap_dev->lock);
Sebastian Ottc6304932009-09-11 10:28:38 +02001683 put_device(&ap_dev->device);
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001684 continue;
1685 }
1686 /* Add device attributes. */
1687 rc = sysfs_create_group(&ap_dev->device.kobj,
1688 &ap_dev_attr_group);
Martin Schwidefsky3f3007a2015-09-14 17:01:23 +02001689 if (rc) {
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001690 device_unregister(&ap_dev->device);
Martin Schwidefsky3f3007a2015-09-14 17:01:23 +02001691 continue;
1692 }
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001693 }
Martin Schwidefskyfcd0d1f2015-07-23 10:55:59 +02001694out:
1695 mod_timer(&ap_config_timer, jiffies + ap_config_time * HZ);
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001696}
1697
Martin Schwidefsky83e9d5d2015-07-17 13:43:18 +02001698static void ap_config_timeout(unsigned long ptr)
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001699{
Martin Schwidefsky83e9d5d2015-07-17 13:43:18 +02001700 if (ap_suspend_flag)
1701 return;
Martin Schwidefsky8139b892015-07-27 12:47:40 +02001702 queue_work(system_long_wq, &ap_scan_work);
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001703}
1704
Ralph Wuerthner13e742b2006-12-15 17:18:17 +01001705static void ap_reset_domain(void)
1706{
1707 int i;
1708
Martin Schwidefsky889875a2015-06-26 16:55:35 +02001709 if (ap_domain_index == -1 || !ap_test_config_domain(ap_domain_index))
1710 return;
1711 for (i = 0; i < AP_DEVICES; i++)
1712 ap_reset_queue(AP_MKQID(i, ap_domain_index));
Ralph Wuerthner13e742b2006-12-15 17:18:17 +01001713}
1714
1715static void ap_reset_all(void)
Ralph Wuerthner85eca852006-12-08 15:54:07 +01001716{
1717 int i, j;
1718
Ingo Tuchscherer170387a2014-09-08 13:24:13 +02001719 for (i = 0; i < AP_DOMAINS; i++) {
1720 if (!ap_test_config_domain(i))
1721 continue;
1722 for (j = 0; j < AP_DEVICES; j++) {
1723 if (!ap_test_config_card_id(j))
1724 continue;
Ralph Wuerthner85eca852006-12-08 15:54:07 +01001725 ap_reset_queue(AP_MKQID(j, i));
Ingo Tuchscherer170387a2014-09-08 13:24:13 +02001726 }
1727 }
Ralph Wuerthner85eca852006-12-08 15:54:07 +01001728}
1729
1730static struct reset_call ap_reset_call = {
Ralph Wuerthner13e742b2006-12-15 17:18:17 +01001731 .fn = ap_reset_all,
Ralph Wuerthner85eca852006-12-08 15:54:07 +01001732};
1733
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001734/**
Felix Beck1749a812008-04-17 07:46:28 +02001735 * ap_module_init(): The module initialization code.
1736 *
1737 * Initializes the module.
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001738 */
1739int __init ap_module_init(void)
1740{
Martin Schwidefsky889875a2015-06-26 16:55:35 +02001741 int max_domain_id;
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001742 int rc, i;
1743
Martin Schwidefsky889875a2015-06-26 16:55:35 +02001744 if (ap_instructions_available() != 0) {
1745 pr_warn("The hardware system does not support AP instructions\n");
1746 return -ENODEV;
1747 }
1748
1749 /* Get AP configuration data if available */
1750 ap_init_configuration();
1751
1752 if (ap_configuration)
1753 max_domain_id = ap_max_domain_id ? : (AP_DOMAINS - 1);
1754 else
1755 max_domain_id = 15;
1756 if (ap_domain_index < -1 || ap_domain_index > max_domain_id) {
1757 pr_warn("%d is not a valid cryptographic domain\n",
1758 ap_domain_index);
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001759 return -EINVAL;
1760 }
Felix Beck5314af62009-09-22 22:58:51 +02001761 /* In resume callback we need to know if the user had set the domain.
1762 * If so, we can not just reset it.
1763 */
1764 if (ap_domain_index >= 0)
1765 user_set_domain = 1;
1766
Felix Beckcb17a632008-12-25 13:38:41 +01001767 if (ap_interrupts_available()) {
Martin Schwidefskyf4eae942013-06-24 10:30:41 +02001768 rc = register_adapter_interrupt(&ap_airq);
1769 ap_airq_flag = (rc == 0);
Felix Beckcb17a632008-12-25 13:38:41 +01001770 }
1771
Ralph Wuerthner85eca852006-12-08 15:54:07 +01001772 register_reset_call(&ap_reset_call);
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001773
1774 /* Create /sys/bus/ap. */
1775 rc = bus_register(&ap_bus_type);
1776 if (rc)
1777 goto out;
1778 for (i = 0; ap_bus_attrs[i]; i++) {
1779 rc = bus_create_file(&ap_bus_type, ap_bus_attrs[i]);
1780 if (rc)
1781 goto out_bus;
1782 }
1783
1784 /* Create /sys/devices/ap. */
Mark McLoughlin035da162008-12-15 12:58:29 +00001785 ap_root_device = root_device_register("ap");
Thomas Meyerba8da212013-06-01 11:51:13 +02001786 rc = PTR_RET(ap_root_device);
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001787 if (rc)
1788 goto out_bus;
1789
Felix Beck1749a812008-04-17 07:46:28 +02001790 /* Setup the AP bus rescan timer. */
Martin Schwidefskyfcd0d1f2015-07-23 10:55:59 +02001791 setup_timer(&ap_config_timer, ap_config_timeout, 0);
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001792
Martin Schwidefsky3f3007a2015-09-14 17:01:23 +02001793 /*
1794 * Setup the high resultion poll timer.
Felix Beckfe137232008-07-14 09:59:08 +02001795 * If we are running under z/VM adjust polling to z/VM polling rate.
1796 */
1797 if (MACHINE_IS_VM)
1798 poll_timeout = 1500000;
Felix Beck93521312009-12-07 12:52:00 +01001799 spin_lock_init(&ap_poll_timer_lock);
Felix Beckfe137232008-07-14 09:59:08 +02001800 hrtimer_init(&ap_poll_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
1801 ap_poll_timer.function = ap_poll_timeout;
1802
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001803 /* Start the low priority AP bus poll thread. */
1804 if (ap_thread_flag) {
1805 rc = ap_poll_thread_start();
1806 if (rc)
1807 goto out_work;
1808 }
1809
Martin Schwidefsky83e9d5d2015-07-17 13:43:18 +02001810 rc = register_pm_notifier(&ap_power_notifier);
1811 if (rc)
1812 goto out_pm;
1813
Martin Schwidefsky8139b892015-07-27 12:47:40 +02001814 queue_work(system_long_wq, &ap_scan_work);
Sascha Silbee3877532015-10-27 18:29:52 +01001815 initialised = true;
Martin Schwidefsky3f3007a2015-09-14 17:01:23 +02001816
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001817 return 0;
1818
Martin Schwidefsky83e9d5d2015-07-17 13:43:18 +02001819out_pm:
1820 ap_poll_thread_stop();
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001821out_work:
Felix Beckfe137232008-07-14 09:59:08 +02001822 hrtimer_cancel(&ap_poll_timer);
Mark McLoughlin035da162008-12-15 12:58:29 +00001823 root_device_unregister(ap_root_device);
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001824out_bus:
1825 while (i--)
1826 bus_remove_file(&ap_bus_type, ap_bus_attrs[i]);
1827 bus_unregister(&ap_bus_type);
1828out:
Ralph Wuerthner85eca852006-12-08 15:54:07 +01001829 unregister_reset_call(&ap_reset_call);
Martin Schwidefskyf4eae942013-06-24 10:30:41 +02001830 if (ap_using_interrupts())
1831 unregister_adapter_interrupt(&ap_airq);
Martin Schwidefsky889875a2015-06-26 16:55:35 +02001832 kfree(ap_configuration);
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001833 return rc;
1834}
1835
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001836/**
Felix Beck1749a812008-04-17 07:46:28 +02001837 * ap_modules_exit(): The module termination code
1838 *
1839 * Terminates the module.
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001840 */
1841void ap_module_exit(void)
1842{
1843 int i;
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001844
Sascha Silbee3877532015-10-27 18:29:52 +01001845 initialised = false;
Ralph Wuerthner13e742b2006-12-15 17:18:17 +01001846 ap_reset_domain();
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001847 ap_poll_thread_stop();
1848 del_timer_sync(&ap_config_timer);
Felix Beckfe137232008-07-14 09:59:08 +02001849 hrtimer_cancel(&ap_poll_timer);
Ralph Wuerthner13e742b2006-12-15 17:18:17 +01001850 tasklet_kill(&ap_tasklet);
Martin Schwidefsky83e9d5d2015-07-17 13:43:18 +02001851 bus_for_each_dev(&ap_bus_type, NULL, NULL, __ap_devices_unregister);
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001852 for (i = 0; ap_bus_attrs[i]; i++)
1853 bus_remove_file(&ap_bus_type, ap_bus_attrs[i]);
Martin Schwidefsky83e9d5d2015-07-17 13:43:18 +02001854 unregister_pm_notifier(&ap_power_notifier);
Ingo Tuchschererf60b8d42015-04-30 15:36:48 +02001855 root_device_unregister(ap_root_device);
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001856 bus_unregister(&ap_bus_type);
Martin Schwidefsky889875a2015-06-26 16:55:35 +02001857 kfree(ap_configuration);
Ralph Wuerthner85eca852006-12-08 15:54:07 +01001858 unregister_reset_call(&ap_reset_call);
Martin Schwidefskyf4eae942013-06-24 10:30:41 +02001859 if (ap_using_interrupts())
1860 unregister_adapter_interrupt(&ap_airq);
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001861}
1862
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001863module_init(ap_module_init);
1864module_exit(ap_module_exit);