1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright IBM Corp. 2006, 2012
4 * Author(s): Cornelia Huck <cornelia.huck@de.ibm.com>
5 * Martin Schwidefsky <schwidefsky@de.ibm.com>
6 * Ralph Wuerthner <rwuerthn@de.ibm.com>
7 * Felix Beck <felix.beck@de.ibm.com>
8 * Holger Dengler <hd@linux.vnet.ibm.com>
10 * Adjunct processor bus.
13 #define KMSG_COMPONENT "ap"
14 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
16 #include <linux/kernel_stat.h>
17 #include <linux/moduleparam.h>
18 #include <linux/init.h>
19 #include <linux/delay.h>
20 #include <linux/err.h>
21 #include <linux/freezer.h>
22 #include <linux/interrupt.h>
23 #include <linux/workqueue.h>
24 #include <linux/slab.h>
25 #include <linux/notifier.h>
26 #include <linux/kthread.h>
27 #include <linux/mutex.h>
29 #include <linux/atomic.h>
31 #include <linux/hrtimer.h>
32 #include <linux/ktime.h>
33 #include <asm/facility.h>
34 #include <linux/crypto.h>
35 #include <linux/mod_devicetable.h>
36 #include <linux/debugfs.h>
37 #include <linux/ctype.h>
43 * Module parameters; note though this file itself isn't modular.
45 int ap_domain_index = -1; /* Adjunct Processor Domain Index */
46 static DEFINE_SPINLOCK(ap_domain_lock);
47 module_param_named(domain, ap_domain_index, int, 0440);
48 MODULE_PARM_DESC(domain, "domain index for ap devices");
49 EXPORT_SYMBOL(ap_domain_index);
51 static int ap_thread_flag;
52 module_param_named(poll_thread, ap_thread_flag, int, 0440);
53 MODULE_PARM_DESC(poll_thread, "Turn on/off poll thread, default is 0 (off).");
56 module_param_named(apmask, apm_str, charp, 0440);
57 MODULE_PARM_DESC(apmask, "AP bus adapter mask.");
60 module_param_named(aqmask, aqm_str, charp, 0440);
61 MODULE_PARM_DESC(aqmask, "AP bus domain mask.");
63 static struct device *ap_root_device;
65 /* Hashtable of all queue devices on the AP bus */
66 DEFINE_HASHTABLE(ap_queues, 8);
67 /* lock used for the ap_queues hashtable */
68 DEFINE_SPINLOCK(ap_queues_lock);
70 /* Default permissions (ioctl, card and domain masking) */
71 struct ap_perms ap_perms;
72 EXPORT_SYMBOL(ap_perms);
73 DEFINE_MUTEX(ap_perms_mutex);
74 EXPORT_SYMBOL(ap_perms_mutex);
76 static struct ap_config_info *ap_qci_info;
79 * AP bus related debug feature things.
81 debug_info_t *ap_dbf_info;
84 * Workqueue timer for bus rescan.
86 static struct timer_list ap_config_timer;
87 static int ap_config_time = AP_CONFIG_TIME;
88 static void ap_scan_bus(struct work_struct *);
89 static DECLARE_WORK(ap_scan_work, ap_scan_bus);
92 * Tasklet & timer for AP request polling and interrupts
94 static void ap_tasklet_fn(unsigned long);
95 static DECLARE_TASKLET_OLD(ap_tasklet, ap_tasklet_fn);
96 static DECLARE_WAIT_QUEUE_HEAD(ap_poll_wait);
97 static struct task_struct *ap_poll_kthread;
98 static DEFINE_MUTEX(ap_poll_thread_mutex);
99 static DEFINE_SPINLOCK(ap_poll_timer_lock);
100 static struct hrtimer ap_poll_timer;
102 * In LPAR poll with 4kHz frequency. Poll every 250000 nanoseconds.
103 * If z/VM change to 1500000 nanoseconds to adjust to z/VM polling.
105 static unsigned long long poll_timeout = 250000;
107 /* Maximum domain id, if not given via qci */
108 static int ap_max_domain_id = 15;
109 /* Maximum adapter id, if not given via qci */
110 static int ap_max_adapter_id = 63;
112 static struct bus_type ap_bus_type;
114 /* Adapter interrupt definitions */
115 static void ap_interrupt_handler(struct airq_struct *airq, bool floating);
117 static bool ap_irq_flag;
119 static struct airq_struct ap_airq = {
120 .handler = ap_interrupt_handler,
125 * ap_airq_ptr() - Get the address of the adapter interrupt indicator
127 * Returns the address of the local-summary-indicator of the adapter
128 * interrupt handler for AP, or NULL if adapter interrupts are not
131 void *ap_airq_ptr(void)
134 return ap_airq.lsi_ptr;
139 * ap_interrupts_available(): Test if AP interrupts are available.
141 * Returns 1 if AP interrupts are available.
143 static int ap_interrupts_available(void)
145 return test_facility(65);
149 * ap_qci_available(): Test if AP configuration
150 * information can be queried via QCI subfunction.
152 * Returns 1 if subfunction PQAP(QCI) is available.
154 static int ap_qci_available(void)
156 return test_facility(12);
160 * ap_apft_available(): Test if AP facilities test (APFT)
161 * facility is available.
163 * Returns 1 if APFT is is available.
165 static int ap_apft_available(void)
167 return test_facility(15);
171 * ap_qact_available(): Test if the PQAP(QACT) subfunction is available.
173 * Returns 1 if the QACT subfunction is available.
175 static inline int ap_qact_available(void)
178 return ap_qci_info->qact;
183 * ap_fetch_qci_info(): Fetch cryptographic config info
185 * Returns the ap configuration info fetched via PQAP(QCI).
186 * On success 0 is returned, on failure a negative errno
187 * is returned, e.g. if the PQAP(QCI) instruction is not
188 * available, the return value will be -EOPNOTSUPP.
190 static inline int ap_fetch_qci_info(struct ap_config_info *info)
192 if (!ap_qci_available())
200 * ap_init_qci_info(): Allocate and query qci config info.
201 * Does also update the static variables ap_max_domain_id
202 * and ap_max_adapter_id if this info is available.
205 static void __init ap_init_qci_info(void)
207 if (!ap_qci_available()) {
208 AP_DBF_INFO("%s QCI not supported\n", __func__);
212 ap_qci_info = kzalloc(sizeof(*ap_qci_info), GFP_KERNEL);
215 if (ap_fetch_qci_info(ap_qci_info) != 0) {
220 AP_DBF_INFO("%s successful fetched initial qci info\n", __func__);
222 if (ap_qci_info->apxa) {
223 if (ap_qci_info->Na) {
224 ap_max_adapter_id = ap_qci_info->Na;
225 AP_DBF_INFO("%s new ap_max_adapter_id is %d\n",
226 __func__, ap_max_adapter_id);
228 if (ap_qci_info->Nd) {
229 ap_max_domain_id = ap_qci_info->Nd;
230 AP_DBF_INFO("%s new ap_max_domain_id is %d\n",
231 __func__, ap_max_domain_id);
237 * ap_test_config(): helper function to extract the nrth bit
238 * within the unsigned int array field.
240 static inline int ap_test_config(unsigned int *field, unsigned int nr)
242 return ap_test_bit((field + (nr >> 5)), (nr & 0x1f));
246 * ap_test_config_card_id(): Test, whether an AP card ID is configured.
248 * Returns 0 if the card is not configured
249 * 1 if the card is configured or
250 * if the configuration information is not available
252 static inline int ap_test_config_card_id(unsigned int id)
254 if (id > ap_max_adapter_id)
257 return ap_test_config(ap_qci_info->apm, id);
262 * ap_test_config_usage_domain(): Test, whether an AP usage domain
265 * Returns 0 if the usage domain is not configured
266 * 1 if the usage domain is configured or
267 * if the configuration information is not available
269 int ap_test_config_usage_domain(unsigned int domain)
271 if (domain > ap_max_domain_id)
274 return ap_test_config(ap_qci_info->aqm, domain);
277 EXPORT_SYMBOL(ap_test_config_usage_domain);
280 * ap_test_config_ctrl_domain(): Test, whether an AP control domain
282 * @domain AP control domain ID
284 * Returns 1 if the control domain is configured
285 * 0 in all other cases
287 int ap_test_config_ctrl_domain(unsigned int domain)
289 if (!ap_qci_info || domain > ap_max_domain_id)
291 return ap_test_config(ap_qci_info->adm, domain);
293 EXPORT_SYMBOL(ap_test_config_ctrl_domain);
296 * ap_queue_info(): Check and get AP queue info.
297 * Returns true if TAPQ succeeded and the info is filled or
300 static bool ap_queue_info(ap_qid_t qid, int *q_type,
301 unsigned int *q_fac, int *q_depth, bool *q_decfg)
303 struct ap_queue_status status;
304 unsigned long info = 0;
306 /* make sure we don't run into a specifiation exception */
307 if (AP_QID_CARD(qid) > ap_max_adapter_id ||
308 AP_QID_QUEUE(qid) > ap_max_domain_id)
311 /* call TAPQ on this APQN */
312 status = ap_test_queue(qid, ap_apft_available(), &info);
313 switch (status.response_code) {
314 case AP_RESPONSE_NORMAL:
315 case AP_RESPONSE_RESET_IN_PROGRESS:
316 case AP_RESPONSE_DECONFIGURED:
317 case AP_RESPONSE_CHECKSTOPPED:
318 case AP_RESPONSE_BUSY:
320 * According to the architecture in all these cases the
321 * info should be filled. All bits 0 is not possible as
322 * there is at least one of the mode bits set.
324 if (WARN_ON_ONCE(!info))
326 *q_type = (int)((info >> 24) & 0xff);
327 *q_fac = (unsigned int)(info >> 32);
328 *q_depth = (int)(info & 0xff);
329 *q_decfg = status.response_code == AP_RESPONSE_DECONFIGURED;
331 /* For CEX2 and CEX3 the available functions
332 * are not reflected by the facilities bits.
333 * Instead it is coded into the type. So here
334 * modify the function bits based on the type.
336 case AP_DEVICE_TYPE_CEX2A:
337 case AP_DEVICE_TYPE_CEX3A:
338 *q_fac |= 0x08000000;
340 case AP_DEVICE_TYPE_CEX2C:
341 case AP_DEVICE_TYPE_CEX3C:
342 *q_fac |= 0x10000000;
350 * A response code which indicates, there is no info available.
356 void ap_wait(enum ap_sm_wait wait)
361 case AP_SM_WAIT_AGAIN:
362 case AP_SM_WAIT_INTERRUPT:
365 if (ap_poll_kthread) {
366 wake_up(&ap_poll_wait);
370 case AP_SM_WAIT_TIMEOUT:
371 spin_lock_bh(&ap_poll_timer_lock);
372 if (!hrtimer_is_queued(&ap_poll_timer)) {
373 hr_time = poll_timeout;
374 hrtimer_forward_now(&ap_poll_timer, hr_time);
375 hrtimer_restart(&ap_poll_timer);
377 spin_unlock_bh(&ap_poll_timer_lock);
379 case AP_SM_WAIT_NONE:
386 * ap_request_timeout(): Handling of request timeouts
387 * @t: timer making this callback
389 * Handles request timeouts.
391 void ap_request_timeout(struct timer_list *t)
393 struct ap_queue *aq = from_timer(aq, t, timeout);
395 spin_lock_bh(&aq->lock);
396 ap_wait(ap_sm_event(aq, AP_SM_EVENT_TIMEOUT));
397 spin_unlock_bh(&aq->lock);
401 * ap_poll_timeout(): AP receive polling for finished AP requests.
402 * @unused: Unused pointer.
404 * Schedules the AP tasklet using a high resolution timer.
406 static enum hrtimer_restart ap_poll_timeout(struct hrtimer *unused)
408 tasklet_schedule(&ap_tasklet);
409 return HRTIMER_NORESTART;
413 * ap_interrupt_handler() - Schedule ap_tasklet on interrupt
414 * @airq: pointer to adapter interrupt descriptor
416 static void ap_interrupt_handler(struct airq_struct *airq, bool floating)
418 inc_irq_stat(IRQIO_APB);
419 tasklet_schedule(&ap_tasklet);
423 * ap_tasklet_fn(): Tasklet to poll all AP devices.
424 * @dummy: Unused variable
426 * Poll all AP devices on the bus.
428 static void ap_tasklet_fn(unsigned long dummy)
432 enum ap_sm_wait wait = AP_SM_WAIT_NONE;
434 /* Reset the indicator if interrupts are used. Thus new interrupts can
435 * be received. Doing it in the beginning of the tasklet is therefor
436 * important that no requests on any AP get lost.
439 xchg(ap_airq.lsi_ptr, 0);
441 spin_lock_bh(&ap_queues_lock);
442 hash_for_each(ap_queues, bkt, aq, hnode) {
443 spin_lock_bh(&aq->lock);
444 wait = min(wait, ap_sm_event_loop(aq, AP_SM_EVENT_POLL));
445 spin_unlock_bh(&aq->lock);
447 spin_unlock_bh(&ap_queues_lock);
452 static int ap_pending_requests(void)
457 spin_lock_bh(&ap_queues_lock);
458 hash_for_each(ap_queues, bkt, aq, hnode) {
459 if (aq->queue_count == 0)
461 spin_unlock_bh(&ap_queues_lock);
464 spin_unlock_bh(&ap_queues_lock);
469 * ap_poll_thread(): Thread that polls for finished requests.
470 * @data: Unused pointer
472 * AP bus poll thread. The purpose of this thread is to poll for
473 * finished requests in a loop if there is a "free" cpu - that is
474 * a cpu that doesn't have anything better to do. The polling stops
475 * as soon as there is another task or if all messages have been
478 static int ap_poll_thread(void *data)
480 DECLARE_WAITQUEUE(wait, current);
482 set_user_nice(current, MAX_NICE);
484 while (!kthread_should_stop()) {
485 add_wait_queue(&ap_poll_wait, &wait);
486 set_current_state(TASK_INTERRUPTIBLE);
487 if (!ap_pending_requests()) {
491 set_current_state(TASK_RUNNING);
492 remove_wait_queue(&ap_poll_wait, &wait);
493 if (need_resched()) {
504 static int ap_poll_thread_start(void)
508 if (ap_irq_flag || ap_poll_kthread)
510 mutex_lock(&ap_poll_thread_mutex);
511 ap_poll_kthread = kthread_run(ap_poll_thread, NULL, "appoll");
512 rc = PTR_ERR_OR_ZERO(ap_poll_kthread);
514 ap_poll_kthread = NULL;
515 mutex_unlock(&ap_poll_thread_mutex);
519 static void ap_poll_thread_stop(void)
521 if (!ap_poll_kthread)
523 mutex_lock(&ap_poll_thread_mutex);
524 kthread_stop(ap_poll_kthread);
525 ap_poll_kthread = NULL;
526 mutex_unlock(&ap_poll_thread_mutex);
529 #define is_card_dev(x) ((x)->parent == ap_root_device)
530 #define is_queue_dev(x) ((x)->parent != ap_root_device)
534 * @dev: Pointer to device
535 * @drv: Pointer to device_driver
537 * AP bus driver registration/unregistration.
539 static int ap_bus_match(struct device *dev, struct device_driver *drv)
541 struct ap_driver *ap_drv = to_ap_drv(drv);
542 struct ap_device_id *id;
545 * Compare device type of the device with the list of
546 * supported types of the device_driver.
548 for (id = ap_drv->ids; id->match_flags; id++) {
549 if (is_card_dev(dev) &&
550 id->match_flags & AP_DEVICE_ID_MATCH_CARD_TYPE &&
551 id->dev_type == to_ap_dev(dev)->device_type)
553 if (is_queue_dev(dev) &&
554 id->match_flags & AP_DEVICE_ID_MATCH_QUEUE_TYPE &&
555 id->dev_type == to_ap_dev(dev)->device_type)
562 * ap_uevent(): Uevent function for AP devices.
563 * @dev: Pointer to device
564 * @env: Pointer to kobj_uevent_env
566 * It sets up a single environment variable DEV_TYPE which contains the
567 * hardware device type.
569 static int ap_uevent(struct device *dev, struct kobj_uevent_env *env)
571 struct ap_device *ap_dev = to_ap_dev(dev);
577 /* Set up DEV_TYPE environment variable. */
578 retval = add_uevent_var(env, "DEV_TYPE=%04X", ap_dev->device_type);
583 retval = add_uevent_var(env, "MODALIAS=ap:t%02X", ap_dev->device_type);
588 static int __ap_queue_devices_with_id_unregister(struct device *dev, void *data)
590 if (is_queue_dev(dev) &&
591 AP_QID_CARD(to_ap_queue(dev)->qid) == (int)(long) data)
592 device_unregister(dev);
596 static struct bus_type ap_bus_type = {
598 .match = &ap_bus_match,
599 .uevent = &ap_uevent,
602 static int __ap_revise_reserved(struct device *dev, void *dummy)
604 int rc, card, queue, devres, drvres;
606 if (is_queue_dev(dev)) {
607 card = AP_QID_CARD(to_ap_queue(dev)->qid);
608 queue = AP_QID_QUEUE(to_ap_queue(dev)->qid);
609 mutex_lock(&ap_perms_mutex);
610 devres = test_bit_inv(card, ap_perms.apm)
611 && test_bit_inv(queue, ap_perms.aqm);
612 mutex_unlock(&ap_perms_mutex);
613 drvres = to_ap_drv(dev->driver)->flags
614 & AP_DRIVER_FLAG_DEFAULT;
615 if (!!devres != !!drvres) {
616 AP_DBF_DBG("reprobing queue=%02x.%04x\n",
618 rc = device_reprobe(dev);
625 static void ap_bus_revise_bindings(void)
627 bus_for_each_dev(&ap_bus_type, NULL, NULL, __ap_revise_reserved);
630 int ap_owned_by_def_drv(int card, int queue)
634 if (card < 0 || card >= AP_DEVICES || queue < 0 || queue >= AP_DOMAINS)
637 mutex_lock(&ap_perms_mutex);
639 if (test_bit_inv(card, ap_perms.apm)
640 && test_bit_inv(queue, ap_perms.aqm))
643 mutex_unlock(&ap_perms_mutex);
647 EXPORT_SYMBOL(ap_owned_by_def_drv);
649 int ap_apqn_in_matrix_owned_by_def_drv(unsigned long *apm,
652 int card, queue, rc = 0;
654 mutex_lock(&ap_perms_mutex);
656 for (card = 0; !rc && card < AP_DEVICES; card++)
657 if (test_bit_inv(card, apm) &&
658 test_bit_inv(card, ap_perms.apm))
659 for (queue = 0; !rc && queue < AP_DOMAINS; queue++)
660 if (test_bit_inv(queue, aqm) &&
661 test_bit_inv(queue, ap_perms.aqm))
664 mutex_unlock(&ap_perms_mutex);
668 EXPORT_SYMBOL(ap_apqn_in_matrix_owned_by_def_drv);
670 static int ap_device_probe(struct device *dev)
672 struct ap_device *ap_dev = to_ap_dev(dev);
673 struct ap_driver *ap_drv = to_ap_drv(dev->driver);
674 int card, queue, devres, drvres, rc = -ENODEV;
676 if (!get_device(dev))
679 if (is_queue_dev(dev)) {
681 * If the apqn is marked as reserved/used by ap bus and
682 * default drivers, only probe with drivers with the default
683 * flag set. If it is not marked, only probe with drivers
684 * with the default flag not set.
686 card = AP_QID_CARD(to_ap_queue(dev)->qid);
687 queue = AP_QID_QUEUE(to_ap_queue(dev)->qid);
688 mutex_lock(&ap_perms_mutex);
689 devres = test_bit_inv(card, ap_perms.apm)
690 && test_bit_inv(queue, ap_perms.aqm);
691 mutex_unlock(&ap_perms_mutex);
692 drvres = ap_drv->flags & AP_DRIVER_FLAG_DEFAULT;
693 if (!!devres != !!drvres)
697 /* Add queue/card to list of active queues/cards */
698 spin_lock_bh(&ap_queues_lock);
699 if (is_queue_dev(dev))
700 hash_add(ap_queues, &to_ap_queue(dev)->hnode,
701 to_ap_queue(dev)->qid);
702 spin_unlock_bh(&ap_queues_lock);
704 ap_dev->drv = ap_drv;
705 rc = ap_drv->probe ? ap_drv->probe(ap_dev) : -ENODEV;
708 spin_lock_bh(&ap_queues_lock);
709 if (is_queue_dev(dev))
710 hash_del(&to_ap_queue(dev)->hnode);
711 spin_unlock_bh(&ap_queues_lock);
721 static int ap_device_remove(struct device *dev)
723 struct ap_device *ap_dev = to_ap_dev(dev);
724 struct ap_driver *ap_drv = ap_dev->drv;
726 /* prepare ap queue device removal */
727 if (is_queue_dev(dev))
728 ap_queue_prepare_remove(to_ap_queue(dev));
730 /* driver's chance to clean up gracefully */
732 ap_drv->remove(ap_dev);
734 /* now do the ap queue device remove */
735 if (is_queue_dev(dev))
736 ap_queue_remove(to_ap_queue(dev));
738 /* Remove queue/card from list of active queues/cards */
739 spin_lock_bh(&ap_queues_lock);
740 if (is_queue_dev(dev))
741 hash_del(&to_ap_queue(dev)->hnode);
742 spin_unlock_bh(&ap_queues_lock);
749 struct ap_queue *ap_get_qdev(ap_qid_t qid)
754 spin_lock_bh(&ap_queues_lock);
755 hash_for_each(ap_queues, bkt, aq, hnode) {
756 if (aq->qid == qid) {
757 get_device(&aq->ap_dev.device);
758 spin_unlock_bh(&ap_queues_lock);
762 spin_unlock_bh(&ap_queues_lock);
766 EXPORT_SYMBOL(ap_get_qdev);
768 int ap_driver_register(struct ap_driver *ap_drv, struct module *owner,
771 struct device_driver *drv = &ap_drv->driver;
773 drv->bus = &ap_bus_type;
774 drv->probe = ap_device_probe;
775 drv->remove = ap_device_remove;
778 return driver_register(drv);
780 EXPORT_SYMBOL(ap_driver_register);
782 void ap_driver_unregister(struct ap_driver *ap_drv)
784 driver_unregister(&ap_drv->driver);
786 EXPORT_SYMBOL(ap_driver_unregister);
788 void ap_bus_force_rescan(void)
790 /* processing a asynchronous bus rescan */
791 del_timer(&ap_config_timer);
792 queue_work(system_long_wq, &ap_scan_work);
793 flush_work(&ap_scan_work);
795 EXPORT_SYMBOL(ap_bus_force_rescan);
798 * A config change has happened, force an ap bus rescan.
800 void ap_bus_cfg_chg(void)
802 AP_DBF_DBG("%s config change, forcing bus rescan\n", __func__);
804 ap_bus_force_rescan();
808 * hex2bitmap() - parse hex mask string and set bitmap.
809 * Valid strings are "0x012345678" with at least one valid hex number.
810 * Rest of the bitmap to the right is padded with 0. No spaces allowed
811 * within the string, the leading 0x may be omitted.
812 * Returns the bitmask with exactly the bits set as given by the hex
813 * string (both in big endian order).
815 static int hex2bitmap(const char *str, unsigned long *bitmap, int bits)
819 /* bits needs to be a multiple of 8 */
823 if (str[0] == '0' && str[1] == 'x')
828 for (i = 0; isxdigit(*str) && i < bits; str++) {
829 b = hex_to_bin(*str);
830 for (n = 0; n < 4; n++)
832 set_bit_inv(i + n, bitmap);
844 * modify_bitmap() - parse bitmask argument and modify an existing
845 * bit mask accordingly. A concatenation (done with ',') of these
846 * terms is recognized:
847 * +<bitnr>[-<bitnr>] or -<bitnr>[-<bitnr>]
848 * <bitnr> may be any valid number (hex, decimal or octal) in the range
849 * 0...bits-1; the leading + or - is required. Here are some examples:
850 * +0-15,+32,-128,-0xFF
851 * -0-255,+1-16,+0x128
852 * +1,+2,+3,+4,-5,-7-10
853 * Returns the new bitmap after all changes have been applied. Every
854 * positive value in the string will set a bit and every negative value
855 * in the string will clear a bit. As a bit may be touched more than once,
856 * the last 'operation' wins:
857 * +0-255,-128 = first bits 0-255 will be set, then bit 128 will be
858 * cleared again. All other bits are unmodified.
860 static int modify_bitmap(const char *str, unsigned long *bitmap, int bits)
865 /* bits needs to be a multiple of 8 */
871 if (sign != '+' && sign != '-')
873 a = z = simple_strtoul(str, &np, 0);
874 if (str == np || a >= bits)
878 z = simple_strtoul(++str, &np, 0);
879 if (str == np || a > z || z >= bits)
883 for (i = a; i <= z; i++)
885 set_bit_inv(i, bitmap);
887 clear_bit_inv(i, bitmap);
888 while (*str == ',' || *str == '\n')
895 int ap_parse_mask_str(const char *str,
896 unsigned long *bitmap, int bits,
899 unsigned long *newmap, size;
902 /* bits needs to be a multiple of 8 */
906 size = BITS_TO_LONGS(bits)*sizeof(unsigned long);
907 newmap = kmalloc(size, GFP_KERNEL);
910 if (mutex_lock_interruptible(lock)) {
915 if (*str == '+' || *str == '-') {
916 memcpy(newmap, bitmap, size);
917 rc = modify_bitmap(str, newmap, bits);
919 memset(newmap, 0, size);
920 rc = hex2bitmap(str, newmap, bits);
923 memcpy(bitmap, newmap, size);
928 EXPORT_SYMBOL(ap_parse_mask_str);
934 static ssize_t ap_domain_show(struct bus_type *bus, char *buf)
936 return scnprintf(buf, PAGE_SIZE, "%d\n", ap_domain_index);
939 static ssize_t ap_domain_store(struct bus_type *bus,
940 const char *buf, size_t count)
944 if (sscanf(buf, "%i\n", &domain) != 1 ||
945 domain < 0 || domain > ap_max_domain_id ||
946 !test_bit_inv(domain, ap_perms.aqm))
949 spin_lock_bh(&ap_domain_lock);
950 ap_domain_index = domain;
951 spin_unlock_bh(&ap_domain_lock);
953 AP_DBF_INFO("stored new default domain=%d\n", domain);
958 static BUS_ATTR_RW(ap_domain);
960 static ssize_t ap_control_domain_mask_show(struct bus_type *bus, char *buf)
962 if (!ap_qci_info) /* QCI not supported */
963 return scnprintf(buf, PAGE_SIZE, "not supported\n");
965 return scnprintf(buf, PAGE_SIZE,
966 "0x%08x%08x%08x%08x%08x%08x%08x%08x\n",
967 ap_qci_info->adm[0], ap_qci_info->adm[1],
968 ap_qci_info->adm[2], ap_qci_info->adm[3],
969 ap_qci_info->adm[4], ap_qci_info->adm[5],
970 ap_qci_info->adm[6], ap_qci_info->adm[7]);
973 static BUS_ATTR_RO(ap_control_domain_mask);
975 static ssize_t ap_usage_domain_mask_show(struct bus_type *bus, char *buf)
977 if (!ap_qci_info) /* QCI not supported */
978 return scnprintf(buf, PAGE_SIZE, "not supported\n");
980 return scnprintf(buf, PAGE_SIZE,
981 "0x%08x%08x%08x%08x%08x%08x%08x%08x\n",
982 ap_qci_info->aqm[0], ap_qci_info->aqm[1],
983 ap_qci_info->aqm[2], ap_qci_info->aqm[3],
984 ap_qci_info->aqm[4], ap_qci_info->aqm[5],
985 ap_qci_info->aqm[6], ap_qci_info->aqm[7]);
988 static BUS_ATTR_RO(ap_usage_domain_mask);
990 static ssize_t ap_adapter_mask_show(struct bus_type *bus, char *buf)
992 if (!ap_qci_info) /* QCI not supported */
993 return scnprintf(buf, PAGE_SIZE, "not supported\n");
995 return scnprintf(buf, PAGE_SIZE,
996 "0x%08x%08x%08x%08x%08x%08x%08x%08x\n",
997 ap_qci_info->apm[0], ap_qci_info->apm[1],
998 ap_qci_info->apm[2], ap_qci_info->apm[3],
999 ap_qci_info->apm[4], ap_qci_info->apm[5],
1000 ap_qci_info->apm[6], ap_qci_info->apm[7]);
1003 static BUS_ATTR_RO(ap_adapter_mask);
1005 static ssize_t ap_interrupts_show(struct bus_type *bus, char *buf)
1007 return scnprintf(buf, PAGE_SIZE, "%d\n",
1008 ap_irq_flag ? 1 : 0);
1011 static BUS_ATTR_RO(ap_interrupts);
1013 static ssize_t config_time_show(struct bus_type *bus, char *buf)
1015 return scnprintf(buf, PAGE_SIZE, "%d\n", ap_config_time);
1018 static ssize_t config_time_store(struct bus_type *bus,
1019 const char *buf, size_t count)
1023 if (sscanf(buf, "%d\n", &time) != 1 || time < 5 || time > 120)
1025 ap_config_time = time;
1026 mod_timer(&ap_config_timer, jiffies + ap_config_time * HZ);
1030 static BUS_ATTR_RW(config_time);
1032 static ssize_t poll_thread_show(struct bus_type *bus, char *buf)
1034 return scnprintf(buf, PAGE_SIZE, "%d\n", ap_poll_kthread ? 1 : 0);
1037 static ssize_t poll_thread_store(struct bus_type *bus,
1038 const char *buf, size_t count)
1042 if (sscanf(buf, "%d\n", &flag) != 1)
1045 rc = ap_poll_thread_start();
1049 ap_poll_thread_stop();
1053 static BUS_ATTR_RW(poll_thread);
1055 static ssize_t poll_timeout_show(struct bus_type *bus, char *buf)
1057 return scnprintf(buf, PAGE_SIZE, "%llu\n", poll_timeout);
1060 static ssize_t poll_timeout_store(struct bus_type *bus, const char *buf,
1063 unsigned long long time;
1066 /* 120 seconds = maximum poll interval */
1067 if (sscanf(buf, "%llu\n", &time) != 1 || time < 1 ||
1068 time > 120000000000ULL)
1070 poll_timeout = time;
1071 hr_time = poll_timeout;
1073 spin_lock_bh(&ap_poll_timer_lock);
1074 hrtimer_cancel(&ap_poll_timer);
1075 hrtimer_set_expires(&ap_poll_timer, hr_time);
1076 hrtimer_start_expires(&ap_poll_timer, HRTIMER_MODE_ABS);
1077 spin_unlock_bh(&ap_poll_timer_lock);
1082 static BUS_ATTR_RW(poll_timeout);
1084 static ssize_t ap_max_domain_id_show(struct bus_type *bus, char *buf)
1086 return scnprintf(buf, PAGE_SIZE, "%d\n", ap_max_domain_id);
1089 static BUS_ATTR_RO(ap_max_domain_id);
1091 static ssize_t ap_max_adapter_id_show(struct bus_type *bus, char *buf)
1093 return scnprintf(buf, PAGE_SIZE, "%d\n", ap_max_adapter_id);
1096 static BUS_ATTR_RO(ap_max_adapter_id);
1098 static ssize_t apmask_show(struct bus_type *bus, char *buf)
1102 if (mutex_lock_interruptible(&ap_perms_mutex))
1103 return -ERESTARTSYS;
1104 rc = scnprintf(buf, PAGE_SIZE,
1105 "0x%016lx%016lx%016lx%016lx\n",
1106 ap_perms.apm[0], ap_perms.apm[1],
1107 ap_perms.apm[2], ap_perms.apm[3]);
1108 mutex_unlock(&ap_perms_mutex);
1113 static ssize_t apmask_store(struct bus_type *bus, const char *buf,
1118 rc = ap_parse_mask_str(buf, ap_perms.apm, AP_DEVICES, &ap_perms_mutex);
1122 ap_bus_revise_bindings();
1127 static BUS_ATTR_RW(apmask);
1129 static ssize_t aqmask_show(struct bus_type *bus, char *buf)
1133 if (mutex_lock_interruptible(&ap_perms_mutex))
1134 return -ERESTARTSYS;
1135 rc = scnprintf(buf, PAGE_SIZE,
1136 "0x%016lx%016lx%016lx%016lx\n",
1137 ap_perms.aqm[0], ap_perms.aqm[1],
1138 ap_perms.aqm[2], ap_perms.aqm[3]);
1139 mutex_unlock(&ap_perms_mutex);
1144 static ssize_t aqmask_store(struct bus_type *bus, const char *buf,
1149 rc = ap_parse_mask_str(buf, ap_perms.aqm, AP_DOMAINS, &ap_perms_mutex);
1153 ap_bus_revise_bindings();
1158 static BUS_ATTR_RW(aqmask);
1160 static struct bus_attribute *const ap_bus_attrs[] = {
1161 &bus_attr_ap_domain,
1162 &bus_attr_ap_control_domain_mask,
1163 &bus_attr_ap_usage_domain_mask,
1164 &bus_attr_ap_adapter_mask,
1165 &bus_attr_config_time,
1166 &bus_attr_poll_thread,
1167 &bus_attr_ap_interrupts,
1168 &bus_attr_poll_timeout,
1169 &bus_attr_ap_max_domain_id,
1170 &bus_attr_ap_max_adapter_id,
1177 * ap_select_domain(): Select an AP domain if possible and we haven't
1178 * already done so before.
1180 static void ap_select_domain(void)
1182 struct ap_queue_status status;
1186 * Choose the default domain. Either the one specified with
1187 * the "domain=" parameter or the first domain with at least
1190 spin_lock_bh(&ap_domain_lock);
1191 if (ap_domain_index >= 0) {
1192 /* Domain has already been selected. */
1195 for (dom = 0; dom <= ap_max_domain_id; dom++) {
1196 if (!ap_test_config_usage_domain(dom) ||
1197 !test_bit_inv(dom, ap_perms.aqm))
1199 for (card = 0; card <= ap_max_adapter_id; card++) {
1200 if (!ap_test_config_card_id(card) ||
1201 !test_bit_inv(card, ap_perms.apm))
1203 status = ap_test_queue(AP_MKQID(card, dom),
1204 ap_apft_available(),
1206 if (status.response_code == AP_RESPONSE_NORMAL)
1209 if (card <= ap_max_adapter_id)
1212 if (dom <= ap_max_domain_id) {
1213 ap_domain_index = dom;
1214 AP_DBF_INFO("%s new default domain is %d\n",
1215 __func__, ap_domain_index);
1218 spin_unlock_bh(&ap_domain_lock);
1222 * This function checks the type and returns either 0 for not
1223 * supported or the highest compatible type value (which may
1224 * include the input type value).
1226 static int ap_get_compatible_type(ap_qid_t qid, int rawtype, unsigned int func)
1230 /* < CEX2A is not supported */
1231 if (rawtype < AP_DEVICE_TYPE_CEX2A) {
1232 AP_DBF_WARN("get_comp_type queue=%02x.%04x unsupported type %d\n",
1233 AP_QID_CARD(qid), AP_QID_QUEUE(qid), rawtype);
1236 /* up to CEX7 known and fully supported */
1237 if (rawtype <= AP_DEVICE_TYPE_CEX7)
1240 * unknown new type > CEX7, check for compatibility
1241 * to the highest known and supported type which is
1242 * currently CEX7 with the help of the QACT function.
1244 if (ap_qact_available()) {
1245 struct ap_queue_status status;
1246 union ap_qact_ap_info apinfo = {0};
1248 apinfo.mode = (func >> 26) & 0x07;
1249 apinfo.cat = AP_DEVICE_TYPE_CEX7;
1250 status = ap_qact(qid, 0, &apinfo);
1251 if (status.response_code == AP_RESPONSE_NORMAL
1252 && apinfo.cat >= AP_DEVICE_TYPE_CEX2A
1253 && apinfo.cat <= AP_DEVICE_TYPE_CEX7)
1254 comp_type = apinfo.cat;
1257 AP_DBF_WARN("get_comp_type queue=%02x.%04x unable to map type %d\n",
1258 AP_QID_CARD(qid), AP_QID_QUEUE(qid), rawtype);
1259 else if (comp_type != rawtype)
1260 AP_DBF_INFO("get_comp_type queue=%02x.%04x map type %d to %d\n",
1261 AP_QID_CARD(qid), AP_QID_QUEUE(qid),
1262 rawtype, comp_type);
1267 * Helper function to be used with bus_find_dev
1268 * matches for the card device with the given id
1270 static int __match_card_device_with_id(struct device *dev, const void *data)
1272 return is_card_dev(dev) && to_ap_card(dev)->id == (int)(long)(void *) data;
1276 * Helper function to be used with bus_find_dev
1277 * matches for the queue device with a given qid
1279 static int __match_queue_device_with_qid(struct device *dev, const void *data)
1281 return is_queue_dev(dev) && to_ap_queue(dev)->qid == (int)(long) data;
1285 * Helper function to be used with bus_find_dev
1286 * matches any queue device with given queue id
1288 static int __match_queue_device_with_queue_id(struct device *dev, const void *data)
1290 return is_queue_dev(dev)
1291 && AP_QID_QUEUE(to_ap_queue(dev)->qid) == (int)(long) data;
1295 * Helper function for ap_scan_bus().
1296 * Remove card device and associated queue devices.
1298 static inline void ap_scan_rm_card_dev_and_queue_devs(struct ap_card *ac)
1300 bus_for_each_dev(&ap_bus_type, NULL,
1301 (void *)(long) ac->id,
1302 __ap_queue_devices_with_id_unregister);
1303 device_unregister(&ac->ap_dev.device);
1307 * Helper function for ap_scan_bus().
1308 * Does the scan bus job for all the domains within
1309 * a valid adapter given by an ap_card ptr.
1311 static inline void ap_scan_domains(struct ap_card *ac)
1317 struct ap_queue *aq;
1318 int rc, dom, depth, type;
1321 * Go through the configuration for the domains and compare them
1322 * to the existing queue devices. Also take care of the config
1323 * and error state for the queue devices.
1326 for (dom = 0; dom <= ap_max_domain_id; dom++) {
1327 qid = AP_MKQID(ac->id, dom);
1328 dev = bus_find_device(&ap_bus_type, NULL,
1330 __match_queue_device_with_qid);
1331 aq = dev ? to_ap_queue(dev) : NULL;
1332 if (!ap_test_config_usage_domain(dom)) {
1334 AP_DBF_INFO("%s(%d,%d) not in config any more, rm queue device\n",
1335 __func__, ac->id, dom);
1336 device_unregister(dev);
1341 /* domain is valid, get info from this APQN */
1342 if (!ap_queue_info(qid, &type, &func, &depth, &decfg)) {
1345 "%s(%d,%d) ap_queue_info() not successful, rm queue device\n",
1346 __func__, ac->id, dom);
1347 device_unregister(dev);
1352 /* if no queue device exists, create a new one */
1354 aq = ap_queue_create(qid, ac->ap_dev.device_type);
1356 AP_DBF_WARN("%s(%d,%d) ap_queue_create() failed\n",
1357 __func__, ac->id, dom);
1361 aq->config = !decfg;
1362 dev = &aq->ap_dev.device;
1363 dev->bus = &ap_bus_type;
1364 dev->parent = &ac->ap_dev.device;
1365 dev_set_name(dev, "%02x.%04x", ac->id, dom);
1366 /* register queue device */
1367 rc = device_register(dev);
1369 AP_DBF_WARN("%s(%d,%d) device_register() failed\n",
1370 __func__, ac->id, dom);
1371 goto put_dev_and_continue;
1373 /* get it and thus adjust reference counter */
1376 AP_DBF_INFO("%s(%d,%d) new (decfg) queue device created\n",
1377 __func__, ac->id, dom);
1379 AP_DBF_INFO("%s(%d,%d) new queue device created\n",
1380 __func__, ac->id, dom);
1381 goto put_dev_and_continue;
1383 /* Check config state on the already existing queue device */
1384 spin_lock_bh(&aq->lock);
1385 if (decfg && aq->config) {
1386 /* config off this queue device */
1388 if (aq->dev_state > AP_DEV_STATE_UNINITIATED) {
1389 aq->dev_state = AP_DEV_STATE_ERROR;
1390 aq->last_err_rc = AP_RESPONSE_DECONFIGURED;
1392 spin_unlock_bh(&aq->lock);
1393 AP_DBF_INFO("%s(%d,%d) queue device config off\n",
1394 __func__, ac->id, dom);
1395 /* 'receive' pending messages with -EAGAIN */
1397 goto put_dev_and_continue;
1399 if (!decfg && !aq->config) {
1400 /* config on this queue device */
1402 if (aq->dev_state > AP_DEV_STATE_UNINITIATED) {
1403 aq->dev_state = AP_DEV_STATE_OPERATING;
1404 aq->sm_state = AP_SM_STATE_RESET_START;
1406 spin_unlock_bh(&aq->lock);
1407 AP_DBF_INFO("%s(%d,%d) queue device config on\n",
1408 __func__, ac->id, dom);
1409 goto put_dev_and_continue;
1411 /* handle other error states */
1412 if (!decfg && aq->dev_state == AP_DEV_STATE_ERROR) {
1413 spin_unlock_bh(&aq->lock);
1414 /* 'receive' pending messages with -EAGAIN */
1416 /* re-init (with reset) the queue device */
1417 ap_queue_init_state(aq);
1418 AP_DBF_INFO("%s(%d,%d) queue device reinit enforced\n",
1419 __func__, ac->id, dom);
1420 goto put_dev_and_continue;
1422 spin_unlock_bh(&aq->lock);
1423 put_dev_and_continue:
1429 * Helper function for ap_scan_bus().
1430 * Does the scan bus job for the given adapter id.
1432 static inline void ap_scan_adapter(int ap)
1439 int rc, dom, depth, type, comp_type;
1441 /* Is there currently a card device for this adapter ? */
1442 dev = bus_find_device(&ap_bus_type, NULL,
1444 __match_card_device_with_id);
1445 ac = dev ? to_ap_card(dev) : NULL;
1447 /* Adapter not in configuration ? */
1448 if (!ap_test_config_card_id(ap)) {
1450 AP_DBF_INFO("%s(%d) ap not in config any more, rm card and queue devices\n",
1452 ap_scan_rm_card_dev_and_queue_devs(ac);
1459 * Adapter ap is valid in the current configuration. So do some checks:
1460 * If no card device exists, build one. If a card device exists, check
1461 * for type and functions changed. For all this we need to find a valid
1465 for (dom = 0; dom <= ap_max_domain_id; dom++)
1466 if (ap_test_config_usage_domain(dom)) {
1467 qid = AP_MKQID(ap, dom);
1468 if (ap_queue_info(qid, &type, &func, &depth, &decfg))
1471 if (dom > ap_max_domain_id) {
1472 /* Could not find a valid APQN for this adapter */
1475 "%s(%d) no type info (no APQN found), rm card and queue devices\n",
1477 ap_scan_rm_card_dev_and_queue_devs(ac);
1480 AP_DBF_DBG("%s(%d) no type info (no APQN found), ignored\n",
1486 /* No apdater type info available, an unusable adapter */
1488 AP_DBF_INFO("%s(%d) no valid type (0) info, rm card and queue devices\n",
1490 ap_scan_rm_card_dev_and_queue_devs(ac);
1493 AP_DBF_DBG("%s(%d) no valid type (0) info, ignored\n",
1500 /* Check APQN against existing card device for changes */
1501 if (ac->raw_hwtype != type) {
1502 AP_DBF_INFO("%s(%d) hwtype %d changed, rm card and queue devices\n",
1503 __func__, ap, type);
1504 ap_scan_rm_card_dev_and_queue_devs(ac);
1507 } else if (ac->functions != func) {
1508 AP_DBF_INFO("%s(%d) functions 0x%08x changed, rm card and queue devices\n",
1509 __func__, ap, type);
1510 ap_scan_rm_card_dev_and_queue_devs(ac);
1514 if (decfg && ac->config) {
1516 AP_DBF_INFO("%s(%d) card device config off\n",
1520 if (!decfg && !ac->config) {
1522 AP_DBF_INFO("%s(%d) card device config on\n",
1529 /* Build a new card device */
1530 comp_type = ap_get_compatible_type(qid, type, func);
1532 AP_DBF_WARN("%s(%d) type %d, can't get compatibility type\n",
1533 __func__, ap, type);
1536 ac = ap_card_create(ap, depth, type, comp_type, func);
1538 AP_DBF_WARN("%s(%d) ap_card_create() failed\n",
1542 ac->config = !decfg;
1543 dev = &ac->ap_dev.device;
1544 dev->bus = &ap_bus_type;
1545 dev->parent = ap_root_device;
1546 dev_set_name(dev, "card%02x", ap);
1547 /* Register the new card device with AP bus */
1548 rc = device_register(dev);
1550 AP_DBF_WARN("%s(%d) device_register() failed\n",
1555 /* get it and thus adjust reference counter */
1558 AP_DBF_INFO("%s(%d) new (decfg) card device type=%d func=0x%08x created\n",
1559 __func__, ap, type, func);
1561 AP_DBF_INFO("%s(%d) new card device type=%d func=0x%08x created\n",
1562 __func__, ap, type, func);
1565 /* Verify the domains and the queue devices for this card */
1566 ap_scan_domains(ac);
1568 /* release the card device */
1569 put_device(&ac->ap_dev.device);
1573 * ap_scan_bus(): Scan the AP bus for new devices
1574 * Runs periodically, workqueue timer (ap_config_time)
1576 static void ap_scan_bus(struct work_struct *unused)
1580 ap_fetch_qci_info(ap_qci_info);
1583 AP_DBF_DBG("%s running\n", __func__);
1585 /* loop over all possible adapters */
1586 for (ap = 0; ap <= ap_max_adapter_id; ap++)
1587 ap_scan_adapter(ap);
1589 /* check if there is at least one queue available with default domain */
1590 if (ap_domain_index >= 0) {
1591 struct device *dev =
1592 bus_find_device(&ap_bus_type, NULL,
1593 (void *)(long) ap_domain_index,
1594 __match_queue_device_with_queue_id);
1598 AP_DBF_INFO("no queue device with default domain %d available\n",
1602 mod_timer(&ap_config_timer, jiffies + ap_config_time * HZ);
1605 static void ap_config_timeout(struct timer_list *unused)
1607 queue_work(system_long_wq, &ap_scan_work);
1610 static int __init ap_debug_init(void)
1612 ap_dbf_info = debug_register("ap", 1, 1,
1613 DBF_MAX_SPRINTF_ARGS * sizeof(long));
1614 debug_register_view(ap_dbf_info, &debug_sprintf_view);
1615 debug_set_level(ap_dbf_info, DBF_ERR);
1620 static void __init ap_perms_init(void)
1622 /* all resources useable if no kernel parameter string given */
1623 memset(&ap_perms.ioctlm, 0xFF, sizeof(ap_perms.ioctlm));
1624 memset(&ap_perms.apm, 0xFF, sizeof(ap_perms.apm));
1625 memset(&ap_perms.aqm, 0xFF, sizeof(ap_perms.aqm));
1627 /* apm kernel parameter string */
1629 memset(&ap_perms.apm, 0, sizeof(ap_perms.apm));
1630 ap_parse_mask_str(apm_str, ap_perms.apm, AP_DEVICES,
1634 /* aqm kernel parameter string */
1636 memset(&ap_perms.aqm, 0, sizeof(ap_perms.aqm));
1637 ap_parse_mask_str(aqm_str, ap_perms.aqm, AP_DOMAINS,
1643 * ap_module_init(): The module initialization code.
1645 * Initializes the module.
1647 static int __init ap_module_init(void)
1651 rc = ap_debug_init();
1655 if (!ap_instructions_available()) {
1656 pr_warn("The hardware system does not support AP instructions\n");
1660 /* init ap_queue hashtable */
1661 hash_init(ap_queues);
1663 /* set up the AP permissions (ioctls, ap and aq masks) */
1666 /* Get AP configuration data if available */
1669 /* check default domain setting */
1670 if (ap_domain_index < -1 || ap_domain_index > ap_max_domain_id ||
1671 (ap_domain_index >= 0 &&
1672 !test_bit_inv(ap_domain_index, ap_perms.aqm))) {
1673 pr_warn("%d is not a valid cryptographic domain\n",
1675 ap_domain_index = -1;
1678 /* enable interrupts if available */
1679 if (ap_interrupts_available()) {
1680 rc = register_adapter_interrupt(&ap_airq);
1681 ap_irq_flag = (rc == 0);
1684 /* Create /sys/bus/ap. */
1685 rc = bus_register(&ap_bus_type);
1688 for (i = 0; ap_bus_attrs[i]; i++) {
1689 rc = bus_create_file(&ap_bus_type, ap_bus_attrs[i]);
1694 /* Create /sys/devices/ap. */
1695 ap_root_device = root_device_register("ap");
1696 rc = PTR_ERR_OR_ZERO(ap_root_device);
1700 /* Setup the AP bus rescan timer. */
1701 timer_setup(&ap_config_timer, ap_config_timeout, 0);
1704 * Setup the high resultion poll timer.
1705 * If we are running under z/VM adjust polling to z/VM polling rate.
1708 poll_timeout = 1500000;
1709 hrtimer_init(&ap_poll_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
1710 ap_poll_timer.function = ap_poll_timeout;
1712 /* Start the low priority AP bus poll thread. */
1713 if (ap_thread_flag) {
1714 rc = ap_poll_thread_start();
1719 queue_work(system_long_wq, &ap_scan_work);
1724 hrtimer_cancel(&ap_poll_timer);
1725 root_device_unregister(ap_root_device);
1728 bus_remove_file(&ap_bus_type, ap_bus_attrs[i]);
1729 bus_unregister(&ap_bus_type);
1732 unregister_adapter_interrupt(&ap_airq);
1736 device_initcall(ap_module_init);