2 * linux/drivers/s390/crypto/ap_bus.c
4 * Copyright (C) 2006 IBM Corporation
5 * Author(s): Cornelia Huck <cornelia.huck@de.ibm.com>
6 * Martin Schwidefsky <schwidefsky@de.ibm.com>
7 * Ralph Wuerthner <rwuerthn@de.ibm.com>
8 * Felix Beck <felix.beck@de.ibm.com>
10 * Adjunct processor bus.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2, or (at your option)
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 #include <linux/module.h>
28 #include <linux/init.h>
29 #include <linux/delay.h>
30 #include <linux/err.h>
31 #include <linux/interrupt.h>
32 #include <linux/workqueue.h>
33 #include <linux/notifier.h>
34 #include <linux/kthread.h>
35 #include <linux/mutex.h>
36 #include <asm/s390_rdev.h>
37 #include <asm/reset.h>
39 #include <asm/atomic.h>
40 #include <asm/system.h>
42 #include <linux/hrtimer.h>
43 #include <linux/ktime.h>
47 /* Some prototypes. */
48 static void ap_scan_bus(struct work_struct *);
49 static void ap_poll_all(unsigned long);
50 static enum hrtimer_restart ap_poll_timeout(struct hrtimer *);
51 static int ap_poll_thread_start(void);
52 static void ap_poll_thread_stop(void);
53 static void ap_request_timeout(unsigned long);
54 static inline void ap_schedule_poll_timer(void);
59 MODULE_AUTHOR("IBM Corporation");
60 MODULE_DESCRIPTION("Adjunct Processor Bus driver, "
61 "Copyright 2006 IBM Corporation");
62 MODULE_LICENSE("GPL");
67 int ap_domain_index = -1; /* Adjunct Processor Domain Index */
68 module_param_named(domain, ap_domain_index, int, 0000);
69 MODULE_PARM_DESC(domain, "domain index for ap devices");
70 EXPORT_SYMBOL(ap_domain_index);
72 static int ap_thread_flag = 0;
73 module_param_named(poll_thread, ap_thread_flag, int, 0000);
74 MODULE_PARM_DESC(poll_thread, "Turn on/off poll thread, default is 0 (off).");
76 static struct device *ap_root_device = NULL;
77 static DEFINE_SPINLOCK(ap_device_list_lock);
78 static LIST_HEAD(ap_device_list);
81 * Workqueue & timer for bus rescan.
83 static struct workqueue_struct *ap_work_queue;
84 static struct timer_list ap_config_timer;
85 static int ap_config_time = AP_CONFIG_TIME;
86 static DECLARE_WORK(ap_config_work, ap_scan_bus);
89 * Tasklet & timer for AP request polling and interrupts
91 static DECLARE_TASKLET(ap_tasklet, ap_poll_all, 0);
92 static atomic_t ap_poll_requests = ATOMIC_INIT(0);
93 static DECLARE_WAIT_QUEUE_HEAD(ap_poll_wait);
94 static struct task_struct *ap_poll_kthread = NULL;
95 static DEFINE_MUTEX(ap_poll_thread_mutex);
96 static void *ap_interrupt_indicator;
97 static 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.*/
100 static unsigned long long poll_timeout = 250000;
103 * ap_using_interrupts() - Returns non-zero if interrupt support is
106 static inline int ap_using_interrupts(void)
108 return ap_interrupt_indicator != NULL;
112 * ap_intructions_available() - Test if AP instructions are available.
114 * Returns 0 if the AP instructions are installed.
116 static inline int ap_instructions_available(void)
118 register unsigned long reg0 asm ("0") = AP_MKQID(0,0);
119 register unsigned long reg1 asm ("1") = -ENODEV;
120 register unsigned long reg2 asm ("2") = 0UL;
123 " .long 0xb2af0000\n" /* PQAP(TAPQ) */
127 : "+d" (reg0), "+d" (reg1), "+d" (reg2) : : "cc" );
132 * ap_interrupts_available(): Test if AP interrupts are available.
134 * Returns 1 if AP interrupts are available.
136 static int ap_interrupts_available(void)
138 unsigned long long facility_bits[2];
140 if (stfle(facility_bits, 2) <= 1)
142 if (!(facility_bits[0] & (1ULL << 61)) ||
143 !(facility_bits[1] & (1ULL << 62)))
149 * ap_test_queue(): Test adjunct processor queue.
150 * @qid: The AP queue number
151 * @queue_depth: Pointer to queue depth value
152 * @device_type: Pointer to device type value
154 * Returns AP queue status structure.
156 static inline struct ap_queue_status
157 ap_test_queue(ap_qid_t qid, int *queue_depth, int *device_type)
159 register unsigned long reg0 asm ("0") = qid;
160 register struct ap_queue_status reg1 asm ("1");
161 register unsigned long reg2 asm ("2") = 0UL;
163 asm volatile(".long 0xb2af0000" /* PQAP(TAPQ) */
164 : "+d" (reg0), "=d" (reg1), "+d" (reg2) : : "cc");
165 *device_type = (int) (reg2 >> 24);
166 *queue_depth = (int) (reg2 & 0xff);
171 * ap_reset_queue(): Reset adjunct processor queue.
172 * @qid: The AP queue number
174 * Returns AP queue status structure.
176 static inline struct ap_queue_status ap_reset_queue(ap_qid_t qid)
178 register unsigned long reg0 asm ("0") = qid | 0x01000000UL;
179 register struct ap_queue_status reg1 asm ("1");
180 register unsigned long reg2 asm ("2") = 0UL;
183 ".long 0xb2af0000" /* PQAP(RAPQ) */
184 : "+d" (reg0), "=d" (reg1), "+d" (reg2) : : "cc");
190 * ap_queue_interruption_control(): Enable interruption for a specific AP.
191 * @qid: The AP queue number
192 * @ind: The notification indicator byte
194 * Returns AP queue status.
196 static inline struct ap_queue_status
197 ap_queue_interruption_control(ap_qid_t qid, void *ind)
199 register unsigned long reg0 asm ("0") = qid | 0x03000000UL;
200 register unsigned long reg1_in asm ("1") = 0x0000800000000000UL | AP_ISC;
201 register struct ap_queue_status reg1_out asm ("1");
202 register void *reg2 asm ("2") = ind;
204 ".long 0xb2af0000" /* PQAP(RAPQ) */
205 : "+d" (reg0), "+d" (reg1_in), "=d" (reg1_out), "+d" (reg2)
213 * ap_queue_enable_interruption(): Enable interruption on an AP.
214 * @qid: The AP queue number
215 * @ind: the notification indicator byte
217 * Enables interruption on AP queue via ap_queue_interruption_control(). Based
218 * on the return value it waits a while and tests the AP queue if interrupts
219 * have been switched on using ap_test_queue().
221 static int ap_queue_enable_interruption(ap_qid_t qid, void *ind)
224 struct ap_queue_status status;
225 int t_depth, t_device_type, rc, i;
228 status = ap_queue_interruption_control(qid, ind);
230 for (i = 0; i < AP_MAX_RESET; i++) {
231 switch (status.response_code) {
232 case AP_RESPONSE_NORMAL:
233 if (status.int_enabled)
236 case AP_RESPONSE_RESET_IN_PROGRESS:
237 case AP_RESPONSE_BUSY:
239 case AP_RESPONSE_Q_NOT_AVAIL:
240 case AP_RESPONSE_DECONFIGURED:
241 case AP_RESPONSE_CHECKSTOPPED:
242 case AP_RESPONSE_INVALID_ADDRESS:
244 case AP_RESPONSE_OTHERWISE_CHANGED:
245 if (status.int_enabled)
251 if (i < AP_MAX_RESET - 1) {
253 status = ap_test_queue(qid, &t_depth, &t_device_type);
263 * __ap_send(): Send message to adjunct processor queue.
264 * @qid: The AP queue number
265 * @psmid: The program supplied message identifier
266 * @msg: The message text
267 * @length: The message length
269 * Returns AP queue status structure.
270 * Condition code 1 on NQAP can't happen because the L bit is 1.
271 * Condition code 2 on NQAP also means the send is incomplete,
272 * because a segment boundary was reached. The NQAP is repeated.
274 static inline struct ap_queue_status
275 __ap_send(ap_qid_t qid, unsigned long long psmid, void *msg, size_t length)
277 typedef struct { char _[length]; } msgblock;
278 register unsigned long reg0 asm ("0") = qid | 0x40000000UL;
279 register struct ap_queue_status reg1 asm ("1");
280 register unsigned long reg2 asm ("2") = (unsigned long) msg;
281 register unsigned long reg3 asm ("3") = (unsigned long) length;
282 register unsigned long reg4 asm ("4") = (unsigned int) (psmid >> 32);
283 register unsigned long reg5 asm ("5") = (unsigned int) psmid;
286 "0: .long 0xb2ad0042\n" /* DQAP */
288 : "+d" (reg0), "=d" (reg1), "+d" (reg2), "+d" (reg3)
289 : "d" (reg4), "d" (reg5), "m" (*(msgblock *) msg)
294 int ap_send(ap_qid_t qid, unsigned long long psmid, void *msg, size_t length)
296 struct ap_queue_status status;
298 status = __ap_send(qid, psmid, msg, length);
299 switch (status.response_code) {
300 case AP_RESPONSE_NORMAL:
302 case AP_RESPONSE_Q_FULL:
303 case AP_RESPONSE_RESET_IN_PROGRESS:
305 default: /* Device is gone. */
309 EXPORT_SYMBOL(ap_send);
312 * __ap_recv(): Receive message from adjunct processor queue.
313 * @qid: The AP queue number
314 * @psmid: Pointer to program supplied message identifier
315 * @msg: The message text
316 * @length: The message length
318 * Returns AP queue status structure.
319 * Condition code 1 on DQAP means the receive has taken place
320 * but only partially. The response is incomplete, hence the
322 * Condition code 2 on DQAP also means the receive is incomplete,
323 * this time because a segment boundary was reached. Again, the
325 * Note that gpr2 is used by the DQAP instruction to keep track of
326 * any 'residual' length, in case the instruction gets interrupted.
327 * Hence it gets zeroed before the instruction.
329 static inline struct ap_queue_status
330 __ap_recv(ap_qid_t qid, unsigned long long *psmid, void *msg, size_t length)
332 typedef struct { char _[length]; } msgblock;
333 register unsigned long reg0 asm("0") = qid | 0x80000000UL;
334 register struct ap_queue_status reg1 asm ("1");
335 register unsigned long reg2 asm("2") = 0UL;
336 register unsigned long reg4 asm("4") = (unsigned long) msg;
337 register unsigned long reg5 asm("5") = (unsigned long) length;
338 register unsigned long reg6 asm("6") = 0UL;
339 register unsigned long reg7 asm("7") = 0UL;
343 "0: .long 0xb2ae0064\n"
345 : "+d" (reg0), "=d" (reg1), "+d" (reg2),
346 "+d" (reg4), "+d" (reg5), "+d" (reg6), "+d" (reg7),
347 "=m" (*(msgblock *) msg) : : "cc" );
348 *psmid = (((unsigned long long) reg6) << 32) + reg7;
352 int ap_recv(ap_qid_t qid, unsigned long long *psmid, void *msg, size_t length)
354 struct ap_queue_status status;
356 status = __ap_recv(qid, psmid, msg, length);
357 switch (status.response_code) {
358 case AP_RESPONSE_NORMAL:
360 case AP_RESPONSE_NO_PENDING_REPLY:
361 if (status.queue_empty)
364 case AP_RESPONSE_RESET_IN_PROGRESS:
370 EXPORT_SYMBOL(ap_recv);
373 * ap_query_queue(): Check if an AP queue is available.
374 * @qid: The AP queue number
375 * @queue_depth: Pointer to queue depth value
376 * @device_type: Pointer to device type value
378 * The test is repeated for AP_MAX_RESET times.
380 static int ap_query_queue(ap_qid_t qid, int *queue_depth, int *device_type)
382 struct ap_queue_status status;
383 int t_depth, t_device_type, rc, i;
386 for (i = 0; i < AP_MAX_RESET; i++) {
387 status = ap_test_queue(qid, &t_depth, &t_device_type);
388 switch (status.response_code) {
389 case AP_RESPONSE_NORMAL:
390 *queue_depth = t_depth + 1;
391 *device_type = t_device_type;
394 case AP_RESPONSE_Q_NOT_AVAIL:
397 case AP_RESPONSE_RESET_IN_PROGRESS:
399 case AP_RESPONSE_DECONFIGURED:
402 case AP_RESPONSE_CHECKSTOPPED:
405 case AP_RESPONSE_INVALID_ADDRESS:
408 case AP_RESPONSE_OTHERWISE_CHANGED:
410 case AP_RESPONSE_BUSY:
417 if (i < AP_MAX_RESET - 1)
424 * ap_init_queue(): Reset an AP queue.
425 * @qid: The AP queue number
427 * Reset an AP queue and wait for it to become available again.
429 static int ap_init_queue(ap_qid_t qid)
431 struct ap_queue_status status;
435 status = ap_reset_queue(qid);
436 for (i = 0; i < AP_MAX_RESET; i++) {
437 switch (status.response_code) {
438 case AP_RESPONSE_NORMAL:
439 if (status.queue_empty)
442 case AP_RESPONSE_Q_NOT_AVAIL:
443 case AP_RESPONSE_DECONFIGURED:
444 case AP_RESPONSE_CHECKSTOPPED:
445 i = AP_MAX_RESET; /* return with -ENODEV */
447 case AP_RESPONSE_RESET_IN_PROGRESS:
449 case AP_RESPONSE_BUSY:
453 if (rc != -ENODEV && rc != -EBUSY)
455 if (i < AP_MAX_RESET - 1) {
457 status = ap_test_queue(qid, &dummy, &dummy);
460 if (rc == 0 && ap_using_interrupts()) {
461 rc = ap_queue_enable_interruption(qid, ap_interrupt_indicator);
462 /* If interruption mode is supported by the machine,
463 * but an AP can not be enabled for interruption then
464 * the AP will be discarded. */
466 pr_err("Registering adapter interrupts for "
467 "AP %d failed\n", AP_QID_DEVICE(qid));
473 * ap_increase_queue_count(): Arm request timeout.
474 * @ap_dev: Pointer to an AP device.
476 * Arm request timeout if an AP device was idle and a new request is submitted.
478 static void ap_increase_queue_count(struct ap_device *ap_dev)
480 int timeout = ap_dev->drv->request_timeout;
482 ap_dev->queue_count++;
483 if (ap_dev->queue_count == 1) {
484 mod_timer(&ap_dev->timeout, jiffies + timeout);
485 ap_dev->reset = AP_RESET_ARMED;
490 * ap_decrease_queue_count(): Decrease queue count.
491 * @ap_dev: Pointer to an AP device.
493 * If AP device is still alive, re-schedule request timeout if there are still
496 static void ap_decrease_queue_count(struct ap_device *ap_dev)
498 int timeout = ap_dev->drv->request_timeout;
500 ap_dev->queue_count--;
501 if (ap_dev->queue_count > 0)
502 mod_timer(&ap_dev->timeout, jiffies + timeout);
505 * The timeout timer should to be disabled now - since
506 * del_timer_sync() is very expensive, we just tell via the
507 * reset flag to ignore the pending timeout timer.
509 ap_dev->reset = AP_RESET_IGNORE;
513 * AP device related attributes.
515 static ssize_t ap_hwtype_show(struct device *dev,
516 struct device_attribute *attr, char *buf)
518 struct ap_device *ap_dev = to_ap_dev(dev);
519 return snprintf(buf, PAGE_SIZE, "%d\n", ap_dev->device_type);
522 static DEVICE_ATTR(hwtype, 0444, ap_hwtype_show, NULL);
523 static ssize_t ap_depth_show(struct device *dev, struct device_attribute *attr,
526 struct ap_device *ap_dev = to_ap_dev(dev);
527 return snprintf(buf, PAGE_SIZE, "%d\n", ap_dev->queue_depth);
530 static DEVICE_ATTR(depth, 0444, ap_depth_show, NULL);
531 static ssize_t ap_request_count_show(struct device *dev,
532 struct device_attribute *attr,
535 struct ap_device *ap_dev = to_ap_dev(dev);
538 spin_lock_bh(&ap_dev->lock);
539 rc = snprintf(buf, PAGE_SIZE, "%d\n", ap_dev->total_request_count);
540 spin_unlock_bh(&ap_dev->lock);
544 static DEVICE_ATTR(request_count, 0444, ap_request_count_show, NULL);
546 static ssize_t ap_modalias_show(struct device *dev,
547 struct device_attribute *attr, char *buf)
549 return sprintf(buf, "ap:t%02X", to_ap_dev(dev)->device_type);
552 static DEVICE_ATTR(modalias, 0444, ap_modalias_show, NULL);
554 static struct attribute *ap_dev_attrs[] = {
555 &dev_attr_hwtype.attr,
556 &dev_attr_depth.attr,
557 &dev_attr_request_count.attr,
558 &dev_attr_modalias.attr,
561 static struct attribute_group ap_dev_attr_group = {
562 .attrs = ap_dev_attrs
567 * @dev: Pointer to device
568 * @drv: Pointer to device_driver
570 * AP bus driver registration/unregistration.
572 static int ap_bus_match(struct device *dev, struct device_driver *drv)
574 struct ap_device *ap_dev = to_ap_dev(dev);
575 struct ap_driver *ap_drv = to_ap_drv(drv);
576 struct ap_device_id *id;
579 * Compare device type of the device with the list of
580 * supported types of the device_driver.
582 for (id = ap_drv->ids; id->match_flags; id++) {
583 if ((id->match_flags & AP_DEVICE_ID_MATCH_DEVICE_TYPE) &&
584 (id->dev_type != ap_dev->device_type))
592 * ap_uevent(): Uevent function for AP devices.
593 * @dev: Pointer to device
594 * @env: Pointer to kobj_uevent_env
596 * It sets up a single environment variable DEV_TYPE which contains the
597 * hardware device type.
599 static int ap_uevent (struct device *dev, struct kobj_uevent_env *env)
601 struct ap_device *ap_dev = to_ap_dev(dev);
607 /* Set up DEV_TYPE environment variable. */
608 retval = add_uevent_var(env, "DEV_TYPE=%04X", ap_dev->device_type);
613 retval = add_uevent_var(env, "MODALIAS=ap:t%02X", ap_dev->device_type);
618 static struct bus_type ap_bus_type = {
620 .match = &ap_bus_match,
621 .uevent = &ap_uevent,
624 static int ap_device_probe(struct device *dev)
626 struct ap_device *ap_dev = to_ap_dev(dev);
627 struct ap_driver *ap_drv = to_ap_drv(dev->driver);
630 ap_dev->drv = ap_drv;
631 rc = ap_drv->probe ? ap_drv->probe(ap_dev) : -ENODEV;
633 spin_lock_bh(&ap_device_list_lock);
634 list_add(&ap_dev->list, &ap_device_list);
635 spin_unlock_bh(&ap_device_list_lock);
641 * __ap_flush_queue(): Flush requests.
642 * @ap_dev: Pointer to the AP device
644 * Flush all requests from the request/pending queue of an AP device.
646 static void __ap_flush_queue(struct ap_device *ap_dev)
648 struct ap_message *ap_msg, *next;
650 list_for_each_entry_safe(ap_msg, next, &ap_dev->pendingq, list) {
651 list_del_init(&ap_msg->list);
652 ap_dev->pendingq_count--;
653 ap_dev->drv->receive(ap_dev, ap_msg, ERR_PTR(-ENODEV));
655 list_for_each_entry_safe(ap_msg, next, &ap_dev->requestq, list) {
656 list_del_init(&ap_msg->list);
657 ap_dev->requestq_count--;
658 ap_dev->drv->receive(ap_dev, ap_msg, ERR_PTR(-ENODEV));
662 void ap_flush_queue(struct ap_device *ap_dev)
664 spin_lock_bh(&ap_dev->lock);
665 __ap_flush_queue(ap_dev);
666 spin_unlock_bh(&ap_dev->lock);
668 EXPORT_SYMBOL(ap_flush_queue);
670 static int ap_device_remove(struct device *dev)
672 struct ap_device *ap_dev = to_ap_dev(dev);
673 struct ap_driver *ap_drv = ap_dev->drv;
675 ap_flush_queue(ap_dev);
676 del_timer_sync(&ap_dev->timeout);
677 spin_lock_bh(&ap_device_list_lock);
678 list_del_init(&ap_dev->list);
679 spin_unlock_bh(&ap_device_list_lock);
681 ap_drv->remove(ap_dev);
682 spin_lock_bh(&ap_dev->lock);
683 atomic_sub(ap_dev->queue_count, &ap_poll_requests);
684 spin_unlock_bh(&ap_dev->lock);
688 int ap_driver_register(struct ap_driver *ap_drv, struct module *owner,
691 struct device_driver *drv = &ap_drv->driver;
693 drv->bus = &ap_bus_type;
694 drv->probe = ap_device_probe;
695 drv->remove = ap_device_remove;
698 return driver_register(drv);
700 EXPORT_SYMBOL(ap_driver_register);
702 void ap_driver_unregister(struct ap_driver *ap_drv)
704 driver_unregister(&ap_drv->driver);
706 EXPORT_SYMBOL(ap_driver_unregister);
711 static ssize_t ap_domain_show(struct bus_type *bus, char *buf)
713 return snprintf(buf, PAGE_SIZE, "%d\n", ap_domain_index);
716 static BUS_ATTR(ap_domain, 0444, ap_domain_show, NULL);
718 static ssize_t ap_config_time_show(struct bus_type *bus, char *buf)
720 return snprintf(buf, PAGE_SIZE, "%d\n", ap_config_time);
723 static ssize_t ap_interrupts_show(struct bus_type *bus, char *buf)
725 return snprintf(buf, PAGE_SIZE, "%d\n",
726 ap_using_interrupts() ? 1 : 0);
729 static BUS_ATTR(ap_interrupts, 0444, ap_interrupts_show, NULL);
731 static ssize_t ap_config_time_store(struct bus_type *bus,
732 const char *buf, size_t count)
736 if (sscanf(buf, "%d\n", &time) != 1 || time < 5 || time > 120)
738 ap_config_time = time;
739 if (!timer_pending(&ap_config_timer) ||
740 !mod_timer(&ap_config_timer, jiffies + ap_config_time * HZ)) {
741 ap_config_timer.expires = jiffies + ap_config_time * HZ;
742 add_timer(&ap_config_timer);
747 static BUS_ATTR(config_time, 0644, ap_config_time_show, ap_config_time_store);
749 static ssize_t ap_poll_thread_show(struct bus_type *bus, char *buf)
751 return snprintf(buf, PAGE_SIZE, "%d\n", ap_poll_kthread ? 1 : 0);
754 static ssize_t ap_poll_thread_store(struct bus_type *bus,
755 const char *buf, size_t count)
759 if (sscanf(buf, "%d\n", &flag) != 1)
762 rc = ap_poll_thread_start();
767 ap_poll_thread_stop();
771 static BUS_ATTR(poll_thread, 0644, ap_poll_thread_show, ap_poll_thread_store);
773 static ssize_t poll_timeout_show(struct bus_type *bus, char *buf)
775 return snprintf(buf, PAGE_SIZE, "%llu\n", poll_timeout);
778 static ssize_t poll_timeout_store(struct bus_type *bus, const char *buf,
781 unsigned long long time;
784 /* 120 seconds = maximum poll interval */
785 if (sscanf(buf, "%llu\n", &time) != 1 || time < 1 ||
786 time > 120000000000ULL)
789 hr_time = ktime_set(0, poll_timeout);
791 if (!hrtimer_is_queued(&ap_poll_timer) ||
792 !hrtimer_forward(&ap_poll_timer, hrtimer_get_expires(&ap_poll_timer), hr_time)) {
793 hrtimer_set_expires(&ap_poll_timer, hr_time);
794 hrtimer_start_expires(&ap_poll_timer, HRTIMER_MODE_ABS);
799 static BUS_ATTR(poll_timeout, 0644, poll_timeout_show, poll_timeout_store);
801 static struct bus_attribute *const ap_bus_attrs[] = {
803 &bus_attr_config_time,
804 &bus_attr_poll_thread,
805 &bus_attr_ap_interrupts,
806 &bus_attr_poll_timeout,
811 * ap_select_domain(): Select an AP domain.
813 * Pick one of the 16 AP domains.
815 static int ap_select_domain(void)
817 int queue_depth, device_type, count, max_count, best_domain;
821 * We want to use a single domain. Either the one specified with
822 * the "domain=" parameter or the domain with the maximum number
825 if (ap_domain_index >= 0 && ap_domain_index < AP_DOMAINS)
826 /* Domain has already been selected. */
830 for (i = 0; i < AP_DOMAINS; i++) {
832 for (j = 0; j < AP_DEVICES; j++) {
833 ap_qid_t qid = AP_MKQID(j, i);
834 rc = ap_query_queue(qid, &queue_depth, &device_type);
839 if (count > max_count) {
844 if (best_domain >= 0){
845 ap_domain_index = best_domain;
852 * ap_probe_device_type(): Find the device type of an AP.
853 * @ap_dev: pointer to the AP device.
855 * Find the device type if query queue returned a device type of 0.
857 static int ap_probe_device_type(struct ap_device *ap_dev)
859 static unsigned char msg[] = {
860 0x00,0x06,0x00,0x00,0x00,0x00,0x00,0x00,
861 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
862 0x00,0x00,0x00,0x58,0x00,0x00,0x00,0x00,
863 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
864 0x01,0x00,0x43,0x43,0x41,0x2d,0x41,0x50,
865 0x50,0x4c,0x20,0x20,0x20,0x01,0x01,0x01,
866 0x00,0x00,0x00,0x00,0x50,0x4b,0x00,0x00,
867 0x00,0x00,0x01,0x1c,0x00,0x00,0x00,0x00,
868 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
869 0x00,0x00,0x05,0xb8,0x00,0x00,0x00,0x00,
870 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
871 0x70,0x00,0x41,0x00,0x00,0x00,0x00,0x00,
872 0x00,0x00,0x54,0x32,0x01,0x00,0xa0,0x00,
873 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
874 0x00,0x00,0x00,0x00,0xb8,0x05,0x00,0x00,
875 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
876 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
877 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
878 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
879 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
880 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
881 0x00,0x00,0x0a,0x00,0x00,0x00,0x00,0x00,
882 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
883 0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,
884 0x49,0x43,0x53,0x46,0x20,0x20,0x20,0x20,
885 0x50,0x4b,0x0a,0x00,0x50,0x4b,0x43,0x53,
886 0x2d,0x31,0x2e,0x32,0x37,0x00,0x11,0x22,
887 0x33,0x44,0x55,0x66,0x77,0x88,0x99,0x00,
888 0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88,
889 0x99,0x00,0x11,0x22,0x33,0x44,0x55,0x66,
890 0x77,0x88,0x99,0x00,0x11,0x22,0x33,0x44,
891 0x55,0x66,0x77,0x88,0x99,0x00,0x11,0x22,
892 0x33,0x44,0x55,0x66,0x77,0x88,0x99,0x00,
893 0x11,0x22,0x33,0x5d,0x00,0x5b,0x00,0x77,
894 0x88,0x1e,0x00,0x00,0x57,0x00,0x00,0x00,
895 0x00,0x04,0x00,0x00,0x4f,0x00,0x00,0x00,
896 0x03,0x02,0x00,0x00,0x40,0x01,0x00,0x01,
897 0xce,0x02,0x68,0x2d,0x5f,0xa9,0xde,0x0c,
898 0xf6,0xd2,0x7b,0x58,0x4b,0xf9,0x28,0x68,
899 0x3d,0xb4,0xf4,0xef,0x78,0xd5,0xbe,0x66,
900 0x63,0x42,0xef,0xf8,0xfd,0xa4,0xf8,0xb0,
901 0x8e,0x29,0xc2,0xc9,0x2e,0xd8,0x45,0xb8,
902 0x53,0x8c,0x6f,0x4e,0x72,0x8f,0x6c,0x04,
903 0x9c,0x88,0xfc,0x1e,0xc5,0x83,0x55,0x57,
904 0xf7,0xdd,0xfd,0x4f,0x11,0x36,0x95,0x5d,
906 struct ap_queue_status status;
907 unsigned long long psmid;
911 reply = (void *) get_zeroed_page(GFP_KERNEL);
917 status = __ap_send(ap_dev->qid, 0x0102030405060708ULL,
919 if (status.response_code != AP_RESPONSE_NORMAL) {
924 /* Wait for the test message to complete. */
925 for (i = 0; i < 6; i++) {
927 status = __ap_recv(ap_dev->qid, &psmid, reply, 4096);
928 if (status.response_code == AP_RESPONSE_NORMAL &&
929 psmid == 0x0102030405060708ULL)
934 if (reply[0] == 0x00 && reply[1] == 0x86)
935 ap_dev->device_type = AP_DEVICE_TYPE_PCICC;
937 ap_dev->device_type = AP_DEVICE_TYPE_PCICA;
943 free_page((unsigned long) reply);
948 static void ap_interrupt_handler(void *unused1, void *unused2)
950 tasklet_schedule(&ap_tasklet);
954 * __ap_scan_bus(): Scan the AP bus.
955 * @dev: Pointer to device
956 * @data: Pointer to data
958 * Scan the AP bus for new devices.
960 static int __ap_scan_bus(struct device *dev, void *data)
962 return to_ap_dev(dev)->qid == (ap_qid_t)(unsigned long) data;
965 static void ap_device_release(struct device *dev)
967 struct ap_device *ap_dev = to_ap_dev(dev);
972 static void ap_scan_bus(struct work_struct *unused)
974 struct ap_device *ap_dev;
977 int queue_depth, device_type;
980 if (ap_select_domain() != 0)
982 for (i = 0; i < AP_DEVICES; i++) {
983 qid = AP_MKQID(i, ap_domain_index);
984 dev = bus_find_device(&ap_bus_type, NULL,
985 (void *)(unsigned long)qid,
987 rc = ap_query_queue(qid, &queue_depth, &device_type);
990 set_current_state(TASK_UNINTERRUPTIBLE);
991 schedule_timeout(AP_RESET_TIMEOUT);
992 rc = ap_query_queue(qid, &queue_depth,
995 ap_dev = to_ap_dev(dev);
996 spin_lock_bh(&ap_dev->lock);
997 if (rc || ap_dev->unregistered) {
998 spin_unlock_bh(&ap_dev->lock);
999 device_unregister(dev);
1003 spin_unlock_bh(&ap_dev->lock);
1009 rc = ap_init_queue(qid);
1012 ap_dev = kzalloc(sizeof(*ap_dev), GFP_KERNEL);
1016 ap_dev->queue_depth = queue_depth;
1017 ap_dev->unregistered = 1;
1018 spin_lock_init(&ap_dev->lock);
1019 INIT_LIST_HEAD(&ap_dev->pendingq);
1020 INIT_LIST_HEAD(&ap_dev->requestq);
1021 INIT_LIST_HEAD(&ap_dev->list);
1022 setup_timer(&ap_dev->timeout, ap_request_timeout,
1023 (unsigned long) ap_dev);
1024 if (device_type == 0)
1025 ap_probe_device_type(ap_dev);
1027 ap_dev->device_type = device_type;
1029 ap_dev->device.bus = &ap_bus_type;
1030 ap_dev->device.parent = ap_root_device;
1031 dev_set_name(&ap_dev->device, "card%02x",
1032 AP_QID_DEVICE(ap_dev->qid));
1033 ap_dev->device.release = ap_device_release;
1034 rc = device_register(&ap_dev->device);
1039 /* Add device attributes. */
1040 rc = sysfs_create_group(&ap_dev->device.kobj,
1041 &ap_dev_attr_group);
1043 spin_lock_bh(&ap_dev->lock);
1044 ap_dev->unregistered = 0;
1045 spin_unlock_bh(&ap_dev->lock);
1048 device_unregister(&ap_dev->device);
1053 ap_config_timeout(unsigned long ptr)
1055 queue_work(ap_work_queue, &ap_config_work);
1056 ap_config_timer.expires = jiffies + ap_config_time * HZ;
1057 add_timer(&ap_config_timer);
1061 * ap_schedule_poll_timer(): Schedule poll timer.
1063 * Set up the timer to run the poll tasklet
1065 static inline void ap_schedule_poll_timer(void)
1067 if (ap_using_interrupts())
1069 if (hrtimer_is_queued(&ap_poll_timer))
1071 hrtimer_start(&ap_poll_timer, ktime_set(0, poll_timeout),
1076 * ap_poll_read(): Receive pending reply messages from an AP device.
1077 * @ap_dev: pointer to the AP device
1078 * @flags: pointer to control flags, bit 2^0 is set if another poll is
1079 * required, bit 2^1 is set if the poll timer needs to get armed
1081 * Returns 0 if the device is still present, -ENODEV if not.
1083 static int ap_poll_read(struct ap_device *ap_dev, unsigned long *flags)
1085 struct ap_queue_status status;
1086 struct ap_message *ap_msg;
1088 if (ap_dev->queue_count <= 0)
1090 status = __ap_recv(ap_dev->qid, &ap_dev->reply->psmid,
1091 ap_dev->reply->message, ap_dev->reply->length);
1092 switch (status.response_code) {
1093 case AP_RESPONSE_NORMAL:
1094 atomic_dec(&ap_poll_requests);
1095 ap_decrease_queue_count(ap_dev);
1096 list_for_each_entry(ap_msg, &ap_dev->pendingq, list) {
1097 if (ap_msg->psmid != ap_dev->reply->psmid)
1099 list_del_init(&ap_msg->list);
1100 ap_dev->pendingq_count--;
1101 ap_dev->drv->receive(ap_dev, ap_msg, ap_dev->reply);
1104 if (ap_dev->queue_count > 0)
1107 case AP_RESPONSE_NO_PENDING_REPLY:
1108 if (status.queue_empty) {
1109 /* The card shouldn't forget requests but who knows. */
1110 atomic_sub(ap_dev->queue_count, &ap_poll_requests);
1111 ap_dev->queue_count = 0;
1112 list_splice_init(&ap_dev->pendingq, &ap_dev->requestq);
1113 ap_dev->requestq_count += ap_dev->pendingq_count;
1114 ap_dev->pendingq_count = 0;
1125 * ap_poll_write(): Send messages from the request queue to an AP device.
1126 * @ap_dev: pointer to the AP device
1127 * @flags: pointer to control flags, bit 2^0 is set if another poll is
1128 * required, bit 2^1 is set if the poll timer needs to get armed
1130 * Returns 0 if the device is still present, -ENODEV if not.
1132 static int ap_poll_write(struct ap_device *ap_dev, unsigned long *flags)
1134 struct ap_queue_status status;
1135 struct ap_message *ap_msg;
1137 if (ap_dev->requestq_count <= 0 ||
1138 ap_dev->queue_count >= ap_dev->queue_depth)
1140 /* Start the next request on the queue. */
1141 ap_msg = list_entry(ap_dev->requestq.next, struct ap_message, list);
1142 status = __ap_send(ap_dev->qid, ap_msg->psmid,
1143 ap_msg->message, ap_msg->length);
1144 switch (status.response_code) {
1145 case AP_RESPONSE_NORMAL:
1146 atomic_inc(&ap_poll_requests);
1147 ap_increase_queue_count(ap_dev);
1148 list_move_tail(&ap_msg->list, &ap_dev->pendingq);
1149 ap_dev->requestq_count--;
1150 ap_dev->pendingq_count++;
1151 if (ap_dev->queue_count < ap_dev->queue_depth &&
1152 ap_dev->requestq_count > 0)
1156 case AP_RESPONSE_Q_FULL:
1157 case AP_RESPONSE_RESET_IN_PROGRESS:
1160 case AP_RESPONSE_MESSAGE_TOO_BIG:
1169 * ap_poll_queue(): Poll AP device for pending replies and send new messages.
1170 * @ap_dev: pointer to the bus device
1171 * @flags: pointer to control flags, bit 2^0 is set if another poll is
1172 * required, bit 2^1 is set if the poll timer needs to get armed
1174 * Poll AP device for pending replies and send new messages. If either
1175 * ap_poll_read or ap_poll_write returns -ENODEV unregister the device.
1178 static inline int ap_poll_queue(struct ap_device *ap_dev, unsigned long *flags)
1182 rc = ap_poll_read(ap_dev, flags);
1185 return ap_poll_write(ap_dev, flags);
1189 * __ap_queue_message(): Queue a message to a device.
1190 * @ap_dev: pointer to the AP device
1191 * @ap_msg: the message to be queued
1193 * Queue a message to a device. Returns 0 if successful.
1195 static int __ap_queue_message(struct ap_device *ap_dev, struct ap_message *ap_msg)
1197 struct ap_queue_status status;
1199 if (list_empty(&ap_dev->requestq) &&
1200 ap_dev->queue_count < ap_dev->queue_depth) {
1201 status = __ap_send(ap_dev->qid, ap_msg->psmid,
1202 ap_msg->message, ap_msg->length);
1203 switch (status.response_code) {
1204 case AP_RESPONSE_NORMAL:
1205 list_add_tail(&ap_msg->list, &ap_dev->pendingq);
1206 atomic_inc(&ap_poll_requests);
1207 ap_dev->pendingq_count++;
1208 ap_increase_queue_count(ap_dev);
1209 ap_dev->total_request_count++;
1211 case AP_RESPONSE_Q_FULL:
1212 case AP_RESPONSE_RESET_IN_PROGRESS:
1213 list_add_tail(&ap_msg->list, &ap_dev->requestq);
1214 ap_dev->requestq_count++;
1215 ap_dev->total_request_count++;
1217 case AP_RESPONSE_MESSAGE_TOO_BIG:
1218 ap_dev->drv->receive(ap_dev, ap_msg, ERR_PTR(-EINVAL));
1220 default: /* Device is gone. */
1221 ap_dev->drv->receive(ap_dev, ap_msg, ERR_PTR(-ENODEV));
1225 list_add_tail(&ap_msg->list, &ap_dev->requestq);
1226 ap_dev->requestq_count++;
1227 ap_dev->total_request_count++;
1230 ap_schedule_poll_timer();
1234 void ap_queue_message(struct ap_device *ap_dev, struct ap_message *ap_msg)
1236 unsigned long flags;
1239 spin_lock_bh(&ap_dev->lock);
1240 if (!ap_dev->unregistered) {
1241 /* Make room on the queue by polling for finished requests. */
1242 rc = ap_poll_queue(ap_dev, &flags);
1244 rc = __ap_queue_message(ap_dev, ap_msg);
1246 wake_up(&ap_poll_wait);
1248 ap_dev->unregistered = 1;
1250 ap_dev->drv->receive(ap_dev, ap_msg, ERR_PTR(-ENODEV));
1253 spin_unlock_bh(&ap_dev->lock);
1255 device_unregister(&ap_dev->device);
1257 EXPORT_SYMBOL(ap_queue_message);
1260 * ap_cancel_message(): Cancel a crypto request.
1261 * @ap_dev: The AP device that has the message queued
1262 * @ap_msg: The message that is to be removed
1264 * Cancel a crypto request. This is done by removing the request
1265 * from the device pending or request queue. Note that the
1266 * request stays on the AP queue. When it finishes the message
1267 * reply will be discarded because the psmid can't be found.
1269 void ap_cancel_message(struct ap_device *ap_dev, struct ap_message *ap_msg)
1271 struct ap_message *tmp;
1273 spin_lock_bh(&ap_dev->lock);
1274 if (!list_empty(&ap_msg->list)) {
1275 list_for_each_entry(tmp, &ap_dev->pendingq, list)
1276 if (tmp->psmid == ap_msg->psmid) {
1277 ap_dev->pendingq_count--;
1280 ap_dev->requestq_count--;
1282 list_del_init(&ap_msg->list);
1284 spin_unlock_bh(&ap_dev->lock);
1286 EXPORT_SYMBOL(ap_cancel_message);
1289 * ap_poll_timeout(): AP receive polling for finished AP requests.
1290 * @unused: Unused pointer.
1292 * Schedules the AP tasklet using a high resolution timer.
1294 static enum hrtimer_restart ap_poll_timeout(struct hrtimer *unused)
1296 tasklet_schedule(&ap_tasklet);
1297 return HRTIMER_NORESTART;
1301 * ap_reset(): Reset a not responding AP device.
1302 * @ap_dev: Pointer to the AP device
1304 * Reset a not responding AP device and move all requests from the
1305 * pending queue to the request queue.
1307 static void ap_reset(struct ap_device *ap_dev)
1311 ap_dev->reset = AP_RESET_IGNORE;
1312 atomic_sub(ap_dev->queue_count, &ap_poll_requests);
1313 ap_dev->queue_count = 0;
1314 list_splice_init(&ap_dev->pendingq, &ap_dev->requestq);
1315 ap_dev->requestq_count += ap_dev->pendingq_count;
1316 ap_dev->pendingq_count = 0;
1317 rc = ap_init_queue(ap_dev->qid);
1319 ap_dev->unregistered = 1;
1322 static int __ap_poll_device(struct ap_device *ap_dev, unsigned long *flags)
1324 spin_lock(&ap_dev->lock);
1325 if (!ap_dev->unregistered) {
1326 if (ap_poll_queue(ap_dev, flags))
1327 ap_dev->unregistered = 1;
1328 if (ap_dev->reset == AP_RESET_DO)
1331 spin_unlock(&ap_dev->lock);
1336 * ap_poll_all(): Poll all AP devices.
1337 * @dummy: Unused variable
1339 * Poll all AP devices on the bus in a round robin fashion. Continue
1340 * polling until bit 2^0 of the control flags is not set. If bit 2^1
1341 * of the control flags has been set arm the poll timer.
1343 static void ap_poll_all(unsigned long dummy)
1345 unsigned long flags;
1346 struct ap_device *ap_dev;
1348 /* Reset the indicator if interrupts are used. Thus new interrupts can
1349 * be received. Doing it in the beginning of the tasklet is therefor
1350 * important that no requests on any AP get lost.
1352 if (ap_using_interrupts())
1353 xchg((u8 *)ap_interrupt_indicator, 0);
1356 spin_lock(&ap_device_list_lock);
1357 list_for_each_entry(ap_dev, &ap_device_list, list) {
1358 __ap_poll_device(ap_dev, &flags);
1360 spin_unlock(&ap_device_list_lock);
1361 } while (flags & 1);
1363 ap_schedule_poll_timer();
1367 * ap_poll_thread(): Thread that polls for finished requests.
1368 * @data: Unused pointer
1370 * AP bus poll thread. The purpose of this thread is to poll for
1371 * finished requests in a loop if there is a "free" cpu - that is
1372 * a cpu that doesn't have anything better to do. The polling stops
1373 * as soon as there is another task or if all messages have been
1376 static int ap_poll_thread(void *data)
1378 DECLARE_WAITQUEUE(wait, current);
1379 unsigned long flags;
1381 struct ap_device *ap_dev;
1383 set_user_nice(current, 19);
1385 if (need_resched()) {
1389 add_wait_queue(&ap_poll_wait, &wait);
1390 set_current_state(TASK_INTERRUPTIBLE);
1391 if (kthread_should_stop())
1393 requests = atomic_read(&ap_poll_requests);
1396 set_current_state(TASK_RUNNING);
1397 remove_wait_queue(&ap_poll_wait, &wait);
1400 spin_lock_bh(&ap_device_list_lock);
1401 list_for_each_entry(ap_dev, &ap_device_list, list) {
1402 __ap_poll_device(ap_dev, &flags);
1404 spin_unlock_bh(&ap_device_list_lock);
1406 set_current_state(TASK_RUNNING);
1407 remove_wait_queue(&ap_poll_wait, &wait);
1411 static int ap_poll_thread_start(void)
1415 if (ap_using_interrupts())
1417 mutex_lock(&ap_poll_thread_mutex);
1418 if (!ap_poll_kthread) {
1419 ap_poll_kthread = kthread_run(ap_poll_thread, NULL, "appoll");
1420 rc = IS_ERR(ap_poll_kthread) ? PTR_ERR(ap_poll_kthread) : 0;
1422 ap_poll_kthread = NULL;
1426 mutex_unlock(&ap_poll_thread_mutex);
1430 static void ap_poll_thread_stop(void)
1432 mutex_lock(&ap_poll_thread_mutex);
1433 if (ap_poll_kthread) {
1434 kthread_stop(ap_poll_kthread);
1435 ap_poll_kthread = NULL;
1437 mutex_unlock(&ap_poll_thread_mutex);
1441 * ap_request_timeout(): Handling of request timeouts
1442 * @data: Holds the AP device.
1444 * Handles request timeouts.
1446 static void ap_request_timeout(unsigned long data)
1448 struct ap_device *ap_dev = (struct ap_device *) data;
1450 if (ap_dev->reset == AP_RESET_ARMED) {
1451 ap_dev->reset = AP_RESET_DO;
1453 if (ap_using_interrupts())
1454 tasklet_schedule(&ap_tasklet);
1458 static void ap_reset_domain(void)
1462 if (ap_domain_index != -1)
1463 for (i = 0; i < AP_DEVICES; i++)
1464 ap_reset_queue(AP_MKQID(i, ap_domain_index));
1467 static void ap_reset_all(void)
1471 for (i = 0; i < AP_DOMAINS; i++)
1472 for (j = 0; j < AP_DEVICES; j++)
1473 ap_reset_queue(AP_MKQID(j, i));
1476 static struct reset_call ap_reset_call = {
1481 * ap_module_init(): The module initialization code.
1483 * Initializes the module.
1485 int __init ap_module_init(void)
1489 if (ap_domain_index < -1 || ap_domain_index >= AP_DOMAINS) {
1490 printk(KERN_WARNING "Invalid param: domain = %d. "
1491 " Not loading.\n", ap_domain_index);
1494 if (ap_instructions_available() != 0) {
1495 printk(KERN_WARNING "AP instructions not installed.\n");
1498 if (ap_interrupts_available()) {
1499 isc_register(AP_ISC);
1500 ap_interrupt_indicator = s390_register_adapter_interrupt(
1501 &ap_interrupt_handler, NULL, AP_ISC);
1502 if (IS_ERR(ap_interrupt_indicator)) {
1503 ap_interrupt_indicator = NULL;
1504 isc_unregister(AP_ISC);
1508 register_reset_call(&ap_reset_call);
1510 /* Create /sys/bus/ap. */
1511 rc = bus_register(&ap_bus_type);
1514 for (i = 0; ap_bus_attrs[i]; i++) {
1515 rc = bus_create_file(&ap_bus_type, ap_bus_attrs[i]);
1520 /* Create /sys/devices/ap. */
1521 ap_root_device = s390_root_dev_register("ap");
1522 rc = IS_ERR(ap_root_device) ? PTR_ERR(ap_root_device) : 0;
1526 ap_work_queue = create_singlethread_workqueue("kapwork");
1527 if (!ap_work_queue) {
1532 if (ap_select_domain() == 0)
1535 /* Setup the AP bus rescan timer. */
1536 init_timer(&ap_config_timer);
1537 ap_config_timer.function = ap_config_timeout;
1538 ap_config_timer.data = 0;
1539 ap_config_timer.expires = jiffies + ap_config_time * HZ;
1540 add_timer(&ap_config_timer);
1542 /* Setup the high resultion poll timer.
1543 * If we are running under z/VM adjust polling to z/VM polling rate.
1546 poll_timeout = 1500000;
1547 hrtimer_init(&ap_poll_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
1548 ap_poll_timer.function = ap_poll_timeout;
1550 /* Start the low priority AP bus poll thread. */
1551 if (ap_thread_flag) {
1552 rc = ap_poll_thread_start();
1560 del_timer_sync(&ap_config_timer);
1561 hrtimer_cancel(&ap_poll_timer);
1562 destroy_workqueue(ap_work_queue);
1564 s390_root_dev_unregister(ap_root_device);
1567 bus_remove_file(&ap_bus_type, ap_bus_attrs[i]);
1568 bus_unregister(&ap_bus_type);
1570 unregister_reset_call(&ap_reset_call);
1571 if (ap_using_interrupts()) {
1572 s390_unregister_adapter_interrupt(ap_interrupt_indicator, AP_ISC);
1573 isc_unregister(AP_ISC);
1578 static int __ap_match_all(struct device *dev, void *data)
1584 * ap_modules_exit(): The module termination code
1586 * Terminates the module.
1588 void ap_module_exit(void)
1594 ap_poll_thread_stop();
1595 del_timer_sync(&ap_config_timer);
1596 hrtimer_cancel(&ap_poll_timer);
1597 destroy_workqueue(ap_work_queue);
1598 tasklet_kill(&ap_tasklet);
1599 s390_root_dev_unregister(ap_root_device);
1600 while ((dev = bus_find_device(&ap_bus_type, NULL, NULL,
1603 device_unregister(dev);
1606 for (i = 0; ap_bus_attrs[i]; i++)
1607 bus_remove_file(&ap_bus_type, ap_bus_attrs[i]);
1608 bus_unregister(&ap_bus_type);
1609 unregister_reset_call(&ap_reset_call);
1610 if (ap_using_interrupts()) {
1611 s390_unregister_adapter_interrupt(ap_interrupt_indicator, AP_ISC);
1612 isc_unregister(AP_ISC);
1616 #ifndef CONFIG_ZCRYPT_MONOLITHIC
1617 module_init(ap_module_init);
1618 module_exit(ap_module_exit);