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 int ap_airq_flag;
119 static struct airq_struct ap_airq = {
120 .handler = ap_interrupt_handler,
125 * ap_using_interrupts() - Returns non-zero if interrupt support is
128 static inline int ap_using_interrupts(void)
134 * ap_airq_ptr() - Get the address of the adapter interrupt indicator
136 * Returns the address of the local-summary-indicator of the adapter
137 * interrupt handler for AP, or NULL if adapter interrupts are not
140 void *ap_airq_ptr(void)
142 if (ap_using_interrupts())
143 return ap_airq.lsi_ptr;
148 * ap_interrupts_available(): Test if AP interrupts are available.
150 * Returns 1 if AP interrupts are available.
152 static int ap_interrupts_available(void)
154 return test_facility(65);
158 * ap_qci_available(): Test if AP configuration
159 * information can be queried via QCI subfunction.
161 * Returns 1 if subfunction PQAP(QCI) is available.
163 static int ap_qci_available(void)
165 return test_facility(12);
169 * ap_apft_available(): Test if AP facilities test (APFT)
170 * facility is available.
172 * Returns 1 if APFT is is available.
174 static int ap_apft_available(void)
176 return test_facility(15);
180 * ap_qact_available(): Test if the PQAP(QACT) subfunction is available.
182 * Returns 1 if the QACT subfunction is available.
184 static inline int ap_qact_available(void)
187 return ap_qci_info->qact;
192 * ap_fetch_qci_info(): Fetch cryptographic config info
194 * Returns the ap configuration info fetched via PQAP(QCI).
195 * On success 0 is returned, on failure a negative errno
196 * is returned, e.g. if the PQAP(QCI) instruction is not
197 * available, the return value will be -EOPNOTSUPP.
199 static inline int ap_fetch_qci_info(struct ap_config_info *info)
201 if (!ap_qci_available())
209 * ap_init_qci_info(): Allocate and query qci config info.
210 * Does also update the static variables ap_max_domain_id
211 * and ap_max_adapter_id if this info is available.
214 static void __init ap_init_qci_info(void)
216 if (!ap_qci_available()) {
217 AP_DBF_INFO("%s QCI not supported\n", __func__);
221 ap_qci_info = kzalloc(sizeof(*ap_qci_info), GFP_KERNEL);
224 if (ap_fetch_qci_info(ap_qci_info) != 0) {
229 AP_DBF_INFO("%s successful fetched initial qci info\n", __func__);
231 if (ap_qci_info->apxa) {
232 if (ap_qci_info->Na) {
233 ap_max_adapter_id = ap_qci_info->Na;
234 AP_DBF_INFO("%s new ap_max_adapter_id is %d\n",
235 __func__, ap_max_adapter_id);
237 if (ap_qci_info->Nd) {
238 ap_max_domain_id = ap_qci_info->Nd;
239 AP_DBF_INFO("%s new ap_max_domain_id is %d\n",
240 __func__, ap_max_domain_id);
246 * ap_test_config(): helper function to extract the nrth bit
247 * within the unsigned int array field.
249 static inline int ap_test_config(unsigned int *field, unsigned int nr)
251 return ap_test_bit((field + (nr >> 5)), (nr & 0x1f));
255 * ap_test_config_card_id(): Test, whether an AP card ID is configured.
257 * Returns 0 if the card is not configured
258 * 1 if the card is configured or
259 * if the configuration information is not available
261 static inline int ap_test_config_card_id(unsigned int id)
263 if (id > ap_max_adapter_id)
266 return ap_test_config(ap_qci_info->apm, id);
271 * ap_test_config_usage_domain(): Test, whether an AP usage domain
274 * Returns 0 if the usage domain is not configured
275 * 1 if the usage domain is configured or
276 * if the configuration information is not available
278 int ap_test_config_usage_domain(unsigned int domain)
280 if (domain > ap_max_domain_id)
283 return ap_test_config(ap_qci_info->aqm, domain);
286 EXPORT_SYMBOL(ap_test_config_usage_domain);
289 * ap_test_config_ctrl_domain(): Test, whether an AP control domain
291 * @domain AP control domain ID
293 * Returns 1 if the control domain is configured
294 * 0 in all other cases
296 int ap_test_config_ctrl_domain(unsigned int domain)
298 if (!ap_qci_info || domain > ap_max_domain_id)
300 return ap_test_config(ap_qci_info->adm, domain);
302 EXPORT_SYMBOL(ap_test_config_ctrl_domain);
305 * ap_queue_info(): Check and get AP queue info.
306 * Returns true if TAPQ succeeded and the info is filled or
309 static bool ap_queue_info(ap_qid_t qid, int *q_type,
310 unsigned int *q_fac, int *q_depth, bool *q_decfg)
312 struct ap_queue_status status;
313 unsigned long info = 0;
315 /* make sure we don't run into a specifiation exception */
316 if (AP_QID_CARD(qid) > ap_max_adapter_id ||
317 AP_QID_QUEUE(qid) > ap_max_domain_id)
320 /* call TAPQ on this APQN */
321 status = ap_test_queue(qid, ap_apft_available(), &info);
322 switch (status.response_code) {
323 case AP_RESPONSE_NORMAL:
324 case AP_RESPONSE_RESET_IN_PROGRESS:
325 case AP_RESPONSE_DECONFIGURED:
326 case AP_RESPONSE_CHECKSTOPPED:
327 case AP_RESPONSE_BUSY:
329 * According to the architecture in all these cases the
330 * info should be filled. All bits 0 is not possible as
331 * there is at least one of the mode bits set.
333 if (WARN_ON_ONCE(!info))
335 *q_type = (int)((info >> 24) & 0xff);
336 *q_fac = (unsigned int)(info >> 32);
337 *q_depth = (int)(info & 0xff);
338 *q_decfg = status.response_code == AP_RESPONSE_DECONFIGURED;
340 /* For CEX2 and CEX3 the available functions
341 * are not reflected by the facilities bits.
342 * Instead it is coded into the type. So here
343 * modify the function bits based on the type.
345 case AP_DEVICE_TYPE_CEX2A:
346 case AP_DEVICE_TYPE_CEX3A:
347 *q_fac |= 0x08000000;
349 case AP_DEVICE_TYPE_CEX2C:
350 case AP_DEVICE_TYPE_CEX3C:
351 *q_fac |= 0x10000000;
359 * A response code which indicates, there is no info available.
365 void ap_wait(enum ap_sm_wait wait)
370 case AP_SM_WAIT_AGAIN:
371 case AP_SM_WAIT_INTERRUPT:
372 if (ap_using_interrupts())
374 if (ap_poll_kthread) {
375 wake_up(&ap_poll_wait);
379 case AP_SM_WAIT_TIMEOUT:
380 spin_lock_bh(&ap_poll_timer_lock);
381 if (!hrtimer_is_queued(&ap_poll_timer)) {
382 hr_time = poll_timeout;
383 hrtimer_forward_now(&ap_poll_timer, hr_time);
384 hrtimer_restart(&ap_poll_timer);
386 spin_unlock_bh(&ap_poll_timer_lock);
388 case AP_SM_WAIT_NONE:
395 * ap_request_timeout(): Handling of request timeouts
396 * @t: timer making this callback
398 * Handles request timeouts.
400 void ap_request_timeout(struct timer_list *t)
402 struct ap_queue *aq = from_timer(aq, t, timeout);
404 spin_lock_bh(&aq->lock);
405 ap_wait(ap_sm_event(aq, AP_SM_EVENT_TIMEOUT));
406 spin_unlock_bh(&aq->lock);
410 * ap_poll_timeout(): AP receive polling for finished AP requests.
411 * @unused: Unused pointer.
413 * Schedules the AP tasklet using a high resolution timer.
415 static enum hrtimer_restart ap_poll_timeout(struct hrtimer *unused)
417 tasklet_schedule(&ap_tasklet);
418 return HRTIMER_NORESTART;
422 * ap_interrupt_handler() - Schedule ap_tasklet on interrupt
423 * @airq: pointer to adapter interrupt descriptor
425 static void ap_interrupt_handler(struct airq_struct *airq, bool floating)
427 inc_irq_stat(IRQIO_APB);
428 tasklet_schedule(&ap_tasklet);
432 * ap_tasklet_fn(): Tasklet to poll all AP devices.
433 * @dummy: Unused variable
435 * Poll all AP devices on the bus.
437 static void ap_tasklet_fn(unsigned long dummy)
441 enum ap_sm_wait wait = AP_SM_WAIT_NONE;
443 /* Reset the indicator if interrupts are used. Thus new interrupts can
444 * be received. Doing it in the beginning of the tasklet is therefor
445 * important that no requests on any AP get lost.
447 if (ap_using_interrupts())
448 xchg(ap_airq.lsi_ptr, 0);
450 spin_lock_bh(&ap_queues_lock);
451 hash_for_each(ap_queues, bkt, aq, hnode) {
452 spin_lock_bh(&aq->lock);
453 wait = min(wait, ap_sm_event_loop(aq, AP_SM_EVENT_POLL));
454 spin_unlock_bh(&aq->lock);
456 spin_unlock_bh(&ap_queues_lock);
461 static int ap_pending_requests(void)
466 spin_lock_bh(&ap_queues_lock);
467 hash_for_each(ap_queues, bkt, aq, hnode) {
468 if (aq->queue_count == 0)
470 spin_unlock_bh(&ap_queues_lock);
473 spin_unlock_bh(&ap_queues_lock);
478 * ap_poll_thread(): Thread that polls for finished requests.
479 * @data: Unused pointer
481 * AP bus poll thread. The purpose of this thread is to poll for
482 * finished requests in a loop if there is a "free" cpu - that is
483 * a cpu that doesn't have anything better to do. The polling stops
484 * as soon as there is another task or if all messages have been
487 static int ap_poll_thread(void *data)
489 DECLARE_WAITQUEUE(wait, current);
491 set_user_nice(current, MAX_NICE);
493 while (!kthread_should_stop()) {
494 add_wait_queue(&ap_poll_wait, &wait);
495 set_current_state(TASK_INTERRUPTIBLE);
496 if (!ap_pending_requests()) {
500 set_current_state(TASK_RUNNING);
501 remove_wait_queue(&ap_poll_wait, &wait);
502 if (need_resched()) {
513 static int ap_poll_thread_start(void)
517 if (ap_using_interrupts() || ap_poll_kthread)
519 mutex_lock(&ap_poll_thread_mutex);
520 ap_poll_kthread = kthread_run(ap_poll_thread, NULL, "appoll");
521 rc = PTR_ERR_OR_ZERO(ap_poll_kthread);
523 ap_poll_kthread = NULL;
524 mutex_unlock(&ap_poll_thread_mutex);
528 static void ap_poll_thread_stop(void)
530 if (!ap_poll_kthread)
532 mutex_lock(&ap_poll_thread_mutex);
533 kthread_stop(ap_poll_kthread);
534 ap_poll_kthread = NULL;
535 mutex_unlock(&ap_poll_thread_mutex);
538 #define is_card_dev(x) ((x)->parent == ap_root_device)
539 #define is_queue_dev(x) ((x)->parent != ap_root_device)
543 * @dev: Pointer to device
544 * @drv: Pointer to device_driver
546 * AP bus driver registration/unregistration.
548 static int ap_bus_match(struct device *dev, struct device_driver *drv)
550 struct ap_driver *ap_drv = to_ap_drv(drv);
551 struct ap_device_id *id;
554 * Compare device type of the device with the list of
555 * supported types of the device_driver.
557 for (id = ap_drv->ids; id->match_flags; id++) {
558 if (is_card_dev(dev) &&
559 id->match_flags & AP_DEVICE_ID_MATCH_CARD_TYPE &&
560 id->dev_type == to_ap_dev(dev)->device_type)
562 if (is_queue_dev(dev) &&
563 id->match_flags & AP_DEVICE_ID_MATCH_QUEUE_TYPE &&
564 id->dev_type == to_ap_dev(dev)->device_type)
571 * ap_uevent(): Uevent function for AP devices.
572 * @dev: Pointer to device
573 * @env: Pointer to kobj_uevent_env
575 * It sets up a single environment variable DEV_TYPE which contains the
576 * hardware device type.
578 static int ap_uevent(struct device *dev, struct kobj_uevent_env *env)
580 struct ap_device *ap_dev = to_ap_dev(dev);
586 /* Set up DEV_TYPE environment variable. */
587 retval = add_uevent_var(env, "DEV_TYPE=%04X", ap_dev->device_type);
592 retval = add_uevent_var(env, "MODALIAS=ap:t%02X", ap_dev->device_type);
597 static int __ap_queue_devices_with_id_unregister(struct device *dev, void *data)
599 if (is_queue_dev(dev) &&
600 AP_QID_CARD(to_ap_queue(dev)->qid) == (int)(long) data)
601 device_unregister(dev);
605 static struct bus_type ap_bus_type = {
607 .match = &ap_bus_match,
608 .uevent = &ap_uevent,
611 static int __ap_revise_reserved(struct device *dev, void *dummy)
613 int rc, card, queue, devres, drvres;
615 if (is_queue_dev(dev)) {
616 card = AP_QID_CARD(to_ap_queue(dev)->qid);
617 queue = AP_QID_QUEUE(to_ap_queue(dev)->qid);
618 mutex_lock(&ap_perms_mutex);
619 devres = test_bit_inv(card, ap_perms.apm)
620 && test_bit_inv(queue, ap_perms.aqm);
621 mutex_unlock(&ap_perms_mutex);
622 drvres = to_ap_drv(dev->driver)->flags
623 & AP_DRIVER_FLAG_DEFAULT;
624 if (!!devres != !!drvres) {
625 AP_DBF_DBG("reprobing queue=%02x.%04x\n",
627 rc = device_reprobe(dev);
634 static void ap_bus_revise_bindings(void)
636 bus_for_each_dev(&ap_bus_type, NULL, NULL, __ap_revise_reserved);
639 int ap_owned_by_def_drv(int card, int queue)
643 if (card < 0 || card >= AP_DEVICES || queue < 0 || queue >= AP_DOMAINS)
646 mutex_lock(&ap_perms_mutex);
648 if (test_bit_inv(card, ap_perms.apm)
649 && test_bit_inv(queue, ap_perms.aqm))
652 mutex_unlock(&ap_perms_mutex);
656 EXPORT_SYMBOL(ap_owned_by_def_drv);
658 int ap_apqn_in_matrix_owned_by_def_drv(unsigned long *apm,
661 int card, queue, rc = 0;
663 mutex_lock(&ap_perms_mutex);
665 for (card = 0; !rc && card < AP_DEVICES; card++)
666 if (test_bit_inv(card, apm) &&
667 test_bit_inv(card, ap_perms.apm))
668 for (queue = 0; !rc && queue < AP_DOMAINS; queue++)
669 if (test_bit_inv(queue, aqm) &&
670 test_bit_inv(queue, ap_perms.aqm))
673 mutex_unlock(&ap_perms_mutex);
677 EXPORT_SYMBOL(ap_apqn_in_matrix_owned_by_def_drv);
679 static int ap_device_probe(struct device *dev)
681 struct ap_device *ap_dev = to_ap_dev(dev);
682 struct ap_driver *ap_drv = to_ap_drv(dev->driver);
683 int card, queue, devres, drvres, rc = -ENODEV;
685 if (!get_device(dev))
688 if (is_queue_dev(dev)) {
690 * If the apqn is marked as reserved/used by ap bus and
691 * default drivers, only probe with drivers with the default
692 * flag set. If it is not marked, only probe with drivers
693 * with the default flag not set.
695 card = AP_QID_CARD(to_ap_queue(dev)->qid);
696 queue = AP_QID_QUEUE(to_ap_queue(dev)->qid);
697 mutex_lock(&ap_perms_mutex);
698 devres = test_bit_inv(card, ap_perms.apm)
699 && test_bit_inv(queue, ap_perms.aqm);
700 mutex_unlock(&ap_perms_mutex);
701 drvres = ap_drv->flags & AP_DRIVER_FLAG_DEFAULT;
702 if (!!devres != !!drvres)
706 /* Add queue/card to list of active queues/cards */
707 spin_lock_bh(&ap_queues_lock);
708 if (is_queue_dev(dev))
709 hash_add(ap_queues, &to_ap_queue(dev)->hnode,
710 to_ap_queue(dev)->qid);
711 spin_unlock_bh(&ap_queues_lock);
713 ap_dev->drv = ap_drv;
714 rc = ap_drv->probe ? ap_drv->probe(ap_dev) : -ENODEV;
717 spin_lock_bh(&ap_queues_lock);
718 if (is_queue_dev(dev))
719 hash_del(&to_ap_queue(dev)->hnode);
720 spin_unlock_bh(&ap_queues_lock);
730 static int ap_device_remove(struct device *dev)
732 struct ap_device *ap_dev = to_ap_dev(dev);
733 struct ap_driver *ap_drv = ap_dev->drv;
735 /* prepare ap queue device removal */
736 if (is_queue_dev(dev))
737 ap_queue_prepare_remove(to_ap_queue(dev));
739 /* driver's chance to clean up gracefully */
741 ap_drv->remove(ap_dev);
743 /* now do the ap queue device remove */
744 if (is_queue_dev(dev))
745 ap_queue_remove(to_ap_queue(dev));
747 /* Remove queue/card from list of active queues/cards */
748 spin_lock_bh(&ap_queues_lock);
749 if (is_queue_dev(dev))
750 hash_del(&to_ap_queue(dev)->hnode);
751 spin_unlock_bh(&ap_queues_lock);
758 struct ap_queue *ap_get_qdev(ap_qid_t qid)
763 spin_lock_bh(&ap_queues_lock);
764 hash_for_each(ap_queues, bkt, aq, hnode) {
765 if (aq->qid == qid) {
766 get_device(&aq->ap_dev.device);
767 spin_unlock_bh(&ap_queues_lock);
771 spin_unlock_bh(&ap_queues_lock);
775 EXPORT_SYMBOL(ap_get_qdev);
777 int ap_driver_register(struct ap_driver *ap_drv, struct module *owner,
780 struct device_driver *drv = &ap_drv->driver;
782 drv->bus = &ap_bus_type;
783 drv->probe = ap_device_probe;
784 drv->remove = ap_device_remove;
787 return driver_register(drv);
789 EXPORT_SYMBOL(ap_driver_register);
791 void ap_driver_unregister(struct ap_driver *ap_drv)
793 driver_unregister(&ap_drv->driver);
795 EXPORT_SYMBOL(ap_driver_unregister);
797 void ap_bus_force_rescan(void)
799 /* processing a asynchronous bus rescan */
800 del_timer(&ap_config_timer);
801 queue_work(system_long_wq, &ap_scan_work);
802 flush_work(&ap_scan_work);
804 EXPORT_SYMBOL(ap_bus_force_rescan);
807 * A config change has happened, force an ap bus rescan.
809 void ap_bus_cfg_chg(void)
811 AP_DBF_DBG("%s config change, forcing bus rescan\n", __func__);
813 ap_bus_force_rescan();
817 * hex2bitmap() - parse hex mask string and set bitmap.
818 * Valid strings are "0x012345678" with at least one valid hex number.
819 * Rest of the bitmap to the right is padded with 0. No spaces allowed
820 * within the string, the leading 0x may be omitted.
821 * Returns the bitmask with exactly the bits set as given by the hex
822 * string (both in big endian order).
824 static int hex2bitmap(const char *str, unsigned long *bitmap, int bits)
828 /* bits needs to be a multiple of 8 */
832 if (str[0] == '0' && str[1] == 'x')
837 for (i = 0; isxdigit(*str) && i < bits; str++) {
838 b = hex_to_bin(*str);
839 for (n = 0; n < 4; n++)
841 set_bit_inv(i + n, bitmap);
853 * modify_bitmap() - parse bitmask argument and modify an existing
854 * bit mask accordingly. A concatenation (done with ',') of these
855 * terms is recognized:
856 * +<bitnr>[-<bitnr>] or -<bitnr>[-<bitnr>]
857 * <bitnr> may be any valid number (hex, decimal or octal) in the range
858 * 0...bits-1; the leading + or - is required. Here are some examples:
859 * +0-15,+32,-128,-0xFF
860 * -0-255,+1-16,+0x128
861 * +1,+2,+3,+4,-5,-7-10
862 * Returns the new bitmap after all changes have been applied. Every
863 * positive value in the string will set a bit and every negative value
864 * in the string will clear a bit. As a bit may be touched more than once,
865 * the last 'operation' wins:
866 * +0-255,-128 = first bits 0-255 will be set, then bit 128 will be
867 * cleared again. All other bits are unmodified.
869 static int modify_bitmap(const char *str, unsigned long *bitmap, int bits)
874 /* bits needs to be a multiple of 8 */
880 if (sign != '+' && sign != '-')
882 a = z = simple_strtoul(str, &np, 0);
883 if (str == np || a >= bits)
887 z = simple_strtoul(++str, &np, 0);
888 if (str == np || a > z || z >= bits)
892 for (i = a; i <= z; i++)
894 set_bit_inv(i, bitmap);
896 clear_bit_inv(i, bitmap);
897 while (*str == ',' || *str == '\n')
904 int ap_parse_mask_str(const char *str,
905 unsigned long *bitmap, int bits,
908 unsigned long *newmap, size;
911 /* bits needs to be a multiple of 8 */
915 size = BITS_TO_LONGS(bits)*sizeof(unsigned long);
916 newmap = kmalloc(size, GFP_KERNEL);
919 if (mutex_lock_interruptible(lock)) {
924 if (*str == '+' || *str == '-') {
925 memcpy(newmap, bitmap, size);
926 rc = modify_bitmap(str, newmap, bits);
928 memset(newmap, 0, size);
929 rc = hex2bitmap(str, newmap, bits);
932 memcpy(bitmap, newmap, size);
937 EXPORT_SYMBOL(ap_parse_mask_str);
943 static ssize_t ap_domain_show(struct bus_type *bus, char *buf)
945 return scnprintf(buf, PAGE_SIZE, "%d\n", ap_domain_index);
948 static ssize_t ap_domain_store(struct bus_type *bus,
949 const char *buf, size_t count)
953 if (sscanf(buf, "%i\n", &domain) != 1 ||
954 domain < 0 || domain > ap_max_domain_id ||
955 !test_bit_inv(domain, ap_perms.aqm))
958 spin_lock_bh(&ap_domain_lock);
959 ap_domain_index = domain;
960 spin_unlock_bh(&ap_domain_lock);
962 AP_DBF_INFO("stored new default domain=%d\n", domain);
967 static BUS_ATTR_RW(ap_domain);
969 static ssize_t ap_control_domain_mask_show(struct bus_type *bus, char *buf)
971 if (!ap_qci_info) /* QCI not supported */
972 return scnprintf(buf, PAGE_SIZE, "not supported\n");
974 return scnprintf(buf, PAGE_SIZE,
975 "0x%08x%08x%08x%08x%08x%08x%08x%08x\n",
976 ap_qci_info->adm[0], ap_qci_info->adm[1],
977 ap_qci_info->adm[2], ap_qci_info->adm[3],
978 ap_qci_info->adm[4], ap_qci_info->adm[5],
979 ap_qci_info->adm[6], ap_qci_info->adm[7]);
982 static BUS_ATTR_RO(ap_control_domain_mask);
984 static ssize_t ap_usage_domain_mask_show(struct bus_type *bus, char *buf)
986 if (!ap_qci_info) /* QCI not supported */
987 return scnprintf(buf, PAGE_SIZE, "not supported\n");
989 return scnprintf(buf, PAGE_SIZE,
990 "0x%08x%08x%08x%08x%08x%08x%08x%08x\n",
991 ap_qci_info->aqm[0], ap_qci_info->aqm[1],
992 ap_qci_info->aqm[2], ap_qci_info->aqm[3],
993 ap_qci_info->aqm[4], ap_qci_info->aqm[5],
994 ap_qci_info->aqm[6], ap_qci_info->aqm[7]);
997 static BUS_ATTR_RO(ap_usage_domain_mask);
999 static ssize_t ap_adapter_mask_show(struct bus_type *bus, char *buf)
1001 if (!ap_qci_info) /* QCI not supported */
1002 return scnprintf(buf, PAGE_SIZE, "not supported\n");
1004 return scnprintf(buf, PAGE_SIZE,
1005 "0x%08x%08x%08x%08x%08x%08x%08x%08x\n",
1006 ap_qci_info->apm[0], ap_qci_info->apm[1],
1007 ap_qci_info->apm[2], ap_qci_info->apm[3],
1008 ap_qci_info->apm[4], ap_qci_info->apm[5],
1009 ap_qci_info->apm[6], ap_qci_info->apm[7]);
1012 static BUS_ATTR_RO(ap_adapter_mask);
1014 static ssize_t ap_interrupts_show(struct bus_type *bus, char *buf)
1016 return scnprintf(buf, PAGE_SIZE, "%d\n",
1017 ap_using_interrupts() ? 1 : 0);
1020 static BUS_ATTR_RO(ap_interrupts);
1022 static ssize_t config_time_show(struct bus_type *bus, char *buf)
1024 return scnprintf(buf, PAGE_SIZE, "%d\n", ap_config_time);
1027 static ssize_t config_time_store(struct bus_type *bus,
1028 const char *buf, size_t count)
1032 if (sscanf(buf, "%d\n", &time) != 1 || time < 5 || time > 120)
1034 ap_config_time = time;
1035 mod_timer(&ap_config_timer, jiffies + ap_config_time * HZ);
1039 static BUS_ATTR_RW(config_time);
1041 static ssize_t poll_thread_show(struct bus_type *bus, char *buf)
1043 return scnprintf(buf, PAGE_SIZE, "%d\n", ap_poll_kthread ? 1 : 0);
1046 static ssize_t poll_thread_store(struct bus_type *bus,
1047 const char *buf, size_t count)
1051 if (sscanf(buf, "%d\n", &flag) != 1)
1054 rc = ap_poll_thread_start();
1058 ap_poll_thread_stop();
1062 static BUS_ATTR_RW(poll_thread);
1064 static ssize_t poll_timeout_show(struct bus_type *bus, char *buf)
1066 return scnprintf(buf, PAGE_SIZE, "%llu\n", poll_timeout);
1069 static ssize_t poll_timeout_store(struct bus_type *bus, const char *buf,
1072 unsigned long long time;
1075 /* 120 seconds = maximum poll interval */
1076 if (sscanf(buf, "%llu\n", &time) != 1 || time < 1 ||
1077 time > 120000000000ULL)
1079 poll_timeout = time;
1080 hr_time = poll_timeout;
1082 spin_lock_bh(&ap_poll_timer_lock);
1083 hrtimer_cancel(&ap_poll_timer);
1084 hrtimer_set_expires(&ap_poll_timer, hr_time);
1085 hrtimer_start_expires(&ap_poll_timer, HRTIMER_MODE_ABS);
1086 spin_unlock_bh(&ap_poll_timer_lock);
1091 static BUS_ATTR_RW(poll_timeout);
1093 static ssize_t ap_max_domain_id_show(struct bus_type *bus, char *buf)
1095 return scnprintf(buf, PAGE_SIZE, "%d\n", ap_max_domain_id);
1098 static BUS_ATTR_RO(ap_max_domain_id);
1100 static ssize_t ap_max_adapter_id_show(struct bus_type *bus, char *buf)
1102 return scnprintf(buf, PAGE_SIZE, "%d\n", ap_max_adapter_id);
1105 static BUS_ATTR_RO(ap_max_adapter_id);
1107 static ssize_t apmask_show(struct bus_type *bus, char *buf)
1111 if (mutex_lock_interruptible(&ap_perms_mutex))
1112 return -ERESTARTSYS;
1113 rc = scnprintf(buf, PAGE_SIZE,
1114 "0x%016lx%016lx%016lx%016lx\n",
1115 ap_perms.apm[0], ap_perms.apm[1],
1116 ap_perms.apm[2], ap_perms.apm[3]);
1117 mutex_unlock(&ap_perms_mutex);
1122 static ssize_t apmask_store(struct bus_type *bus, const char *buf,
1127 rc = ap_parse_mask_str(buf, ap_perms.apm, AP_DEVICES, &ap_perms_mutex);
1131 ap_bus_revise_bindings();
1136 static BUS_ATTR_RW(apmask);
1138 static ssize_t aqmask_show(struct bus_type *bus, char *buf)
1142 if (mutex_lock_interruptible(&ap_perms_mutex))
1143 return -ERESTARTSYS;
1144 rc = scnprintf(buf, PAGE_SIZE,
1145 "0x%016lx%016lx%016lx%016lx\n",
1146 ap_perms.aqm[0], ap_perms.aqm[1],
1147 ap_perms.aqm[2], ap_perms.aqm[3]);
1148 mutex_unlock(&ap_perms_mutex);
1153 static ssize_t aqmask_store(struct bus_type *bus, const char *buf,
1158 rc = ap_parse_mask_str(buf, ap_perms.aqm, AP_DOMAINS, &ap_perms_mutex);
1162 ap_bus_revise_bindings();
1167 static BUS_ATTR_RW(aqmask);
1169 static struct bus_attribute *const ap_bus_attrs[] = {
1170 &bus_attr_ap_domain,
1171 &bus_attr_ap_control_domain_mask,
1172 &bus_attr_ap_usage_domain_mask,
1173 &bus_attr_ap_adapter_mask,
1174 &bus_attr_config_time,
1175 &bus_attr_poll_thread,
1176 &bus_attr_ap_interrupts,
1177 &bus_attr_poll_timeout,
1178 &bus_attr_ap_max_domain_id,
1179 &bus_attr_ap_max_adapter_id,
1186 * ap_select_domain(): Select an AP domain if possible and we haven't
1187 * already done so before.
1189 static void ap_select_domain(void)
1191 struct ap_queue_status status;
1195 * Choose the default domain. Either the one specified with
1196 * the "domain=" parameter or the first domain with at least
1199 spin_lock_bh(&ap_domain_lock);
1200 if (ap_domain_index >= 0) {
1201 /* Domain has already been selected. */
1204 for (dom = 0; dom <= ap_max_domain_id; dom++) {
1205 if (!ap_test_config_usage_domain(dom) ||
1206 !test_bit_inv(dom, ap_perms.aqm))
1208 for (card = 0; card <= ap_max_adapter_id; card++) {
1209 if (!ap_test_config_card_id(card) ||
1210 !test_bit_inv(card, ap_perms.apm))
1212 status = ap_test_queue(AP_MKQID(card, dom),
1213 ap_apft_available(),
1215 if (status.response_code == AP_RESPONSE_NORMAL)
1218 if (card <= ap_max_adapter_id)
1221 if (dom <= ap_max_domain_id) {
1222 ap_domain_index = dom;
1223 AP_DBF_INFO("%s new default domain is %d\n",
1224 __func__, ap_domain_index);
1227 spin_unlock_bh(&ap_domain_lock);
1231 * This function checks the type and returns either 0 for not
1232 * supported or the highest compatible type value (which may
1233 * include the input type value).
1235 static int ap_get_compatible_type(ap_qid_t qid, int rawtype, unsigned int func)
1239 /* < CEX2A is not supported */
1240 if (rawtype < AP_DEVICE_TYPE_CEX2A) {
1241 AP_DBF_WARN("get_comp_type queue=%02x.%04x unsupported type %d\n",
1242 AP_QID_CARD(qid), AP_QID_QUEUE(qid), rawtype);
1245 /* up to CEX7 known and fully supported */
1246 if (rawtype <= AP_DEVICE_TYPE_CEX7)
1249 * unknown new type > CEX7, check for compatibility
1250 * to the highest known and supported type which is
1251 * currently CEX7 with the help of the QACT function.
1253 if (ap_qact_available()) {
1254 struct ap_queue_status status;
1255 union ap_qact_ap_info apinfo = {0};
1257 apinfo.mode = (func >> 26) & 0x07;
1258 apinfo.cat = AP_DEVICE_TYPE_CEX7;
1259 status = ap_qact(qid, 0, &apinfo);
1260 if (status.response_code == AP_RESPONSE_NORMAL
1261 && apinfo.cat >= AP_DEVICE_TYPE_CEX2A
1262 && apinfo.cat <= AP_DEVICE_TYPE_CEX7)
1263 comp_type = apinfo.cat;
1266 AP_DBF_WARN("get_comp_type queue=%02x.%04x unable to map type %d\n",
1267 AP_QID_CARD(qid), AP_QID_QUEUE(qid), rawtype);
1268 else if (comp_type != rawtype)
1269 AP_DBF_INFO("get_comp_type queue=%02x.%04x map type %d to %d\n",
1270 AP_QID_CARD(qid), AP_QID_QUEUE(qid),
1271 rawtype, comp_type);
1276 * Helper function to be used with bus_find_dev
1277 * matches for the card device with the given id
1279 static int __match_card_device_with_id(struct device *dev, const void *data)
1281 return is_card_dev(dev) && to_ap_card(dev)->id == (int)(long)(void *) data;
1285 * Helper function to be used with bus_find_dev
1286 * matches for the queue device with a given qid
1288 static int __match_queue_device_with_qid(struct device *dev, const void *data)
1290 return is_queue_dev(dev) && to_ap_queue(dev)->qid == (int)(long) data;
1294 * Helper function to be used with bus_find_dev
1295 * matches any queue device with given queue id
1297 static int __match_queue_device_with_queue_id(struct device *dev, const void *data)
1299 return is_queue_dev(dev)
1300 && AP_QID_QUEUE(to_ap_queue(dev)->qid) == (int)(long) data;
1304 * Helper function for ap_scan_bus().
1305 * Remove card device and associated queue devices.
1307 static inline void ap_scan_rm_card_dev_and_queue_devs(struct ap_card *ac)
1309 bus_for_each_dev(&ap_bus_type, NULL,
1310 (void *)(long) ac->id,
1311 __ap_queue_devices_with_id_unregister);
1312 device_unregister(&ac->ap_dev.device);
1316 * Helper function for ap_scan_bus().
1317 * Does the scan bus job for all the domains within
1318 * a valid adapter given by an ap_card ptr.
1320 static inline void ap_scan_domains(struct ap_card *ac)
1326 struct ap_queue *aq;
1327 int rc, dom, depth, type;
1330 * Go through the configuration for the domains and compare them
1331 * to the existing queue devices. Also take care of the config
1332 * and error state for the queue devices.
1335 for (dom = 0; dom <= ap_max_domain_id; dom++) {
1336 qid = AP_MKQID(ac->id, dom);
1337 dev = bus_find_device(&ap_bus_type, NULL,
1339 __match_queue_device_with_qid);
1340 aq = dev ? to_ap_queue(dev) : NULL;
1341 if (!ap_test_config_usage_domain(dom)) {
1343 AP_DBF_INFO("%s(%d,%d) not in config any more, rm queue device\n",
1344 __func__, ac->id, dom);
1345 device_unregister(dev);
1350 /* domain is valid, get info from this APQN */
1351 if (!ap_queue_info(qid, &type, &func, &depth, &decfg)) {
1354 "%s(%d,%d) ap_queue_info() not successful, rm queue device\n",
1355 __func__, ac->id, dom);
1356 device_unregister(dev);
1361 /* if no queue device exists, create a new one */
1363 aq = ap_queue_create(qid, ac->ap_dev.device_type);
1365 AP_DBF_WARN("%s(%d,%d) ap_queue_create() failed\n",
1366 __func__, ac->id, dom);
1370 aq->config = !decfg;
1371 dev = &aq->ap_dev.device;
1372 dev->bus = &ap_bus_type;
1373 dev->parent = &ac->ap_dev.device;
1374 dev_set_name(dev, "%02x.%04x", ac->id, dom);
1375 /* register queue device */
1376 rc = device_register(dev);
1378 AP_DBF_WARN("%s(%d,%d) device_register() failed\n",
1379 __func__, ac->id, dom);
1380 goto put_dev_and_continue;
1382 /* get it and thus adjust reference counter */
1385 AP_DBF_INFO("%s(%d,%d) new (decfg) queue device created\n",
1386 __func__, ac->id, dom);
1388 AP_DBF_INFO("%s(%d,%d) new queue device created\n",
1389 __func__, ac->id, dom);
1390 goto put_dev_and_continue;
1392 /* Check config state on the already existing queue device */
1393 spin_lock_bh(&aq->lock);
1394 if (decfg && aq->config) {
1395 /* config off this queue device */
1397 if (aq->dev_state > AP_DEV_STATE_UNINITIATED) {
1398 aq->dev_state = AP_DEV_STATE_ERROR;
1399 aq->last_err_rc = AP_RESPONSE_DECONFIGURED;
1401 spin_unlock_bh(&aq->lock);
1402 AP_DBF_INFO("%s(%d,%d) queue device config off\n",
1403 __func__, ac->id, dom);
1404 /* 'receive' pending messages with -EAGAIN */
1406 goto put_dev_and_continue;
1408 if (!decfg && !aq->config) {
1409 /* config on this queue device */
1411 if (aq->dev_state > AP_DEV_STATE_UNINITIATED) {
1412 aq->dev_state = AP_DEV_STATE_OPERATING;
1413 aq->sm_state = AP_SM_STATE_RESET_START;
1415 spin_unlock_bh(&aq->lock);
1416 AP_DBF_INFO("%s(%d,%d) queue device config on\n",
1417 __func__, ac->id, dom);
1418 goto put_dev_and_continue;
1420 /* handle other error states */
1421 if (!decfg && aq->dev_state == AP_DEV_STATE_ERROR) {
1422 spin_unlock_bh(&aq->lock);
1423 /* 'receive' pending messages with -EAGAIN */
1425 /* re-init (with reset) the queue device */
1426 ap_queue_init_state(aq);
1427 AP_DBF_INFO("%s(%d,%d) queue device reinit enforced\n",
1428 __func__, ac->id, dom);
1429 goto put_dev_and_continue;
1431 spin_unlock_bh(&aq->lock);
1432 put_dev_and_continue:
1438 * Helper function for ap_scan_bus().
1439 * Does the scan bus job for the given adapter id.
1441 static inline void ap_scan_adapter(int ap)
1448 int rc, dom, depth, type, comp_type;
1450 /* Is there currently a card device for this adapter ? */
1451 dev = bus_find_device(&ap_bus_type, NULL,
1453 __match_card_device_with_id);
1454 ac = dev ? to_ap_card(dev) : NULL;
1456 /* Adapter not in configuration ? */
1457 if (!ap_test_config_card_id(ap)) {
1459 AP_DBF_INFO("%s(%d) ap not in config any more, rm card and queue devices\n",
1461 ap_scan_rm_card_dev_and_queue_devs(ac);
1468 * Adapter ap is valid in the current configuration. So do some checks:
1469 * If no card device exists, build one. If a card device exists, check
1470 * for type and functions changed. For all this we need to find a valid
1474 for (dom = 0; dom <= ap_max_domain_id; dom++)
1475 if (ap_test_config_usage_domain(dom)) {
1476 qid = AP_MKQID(ap, dom);
1477 if (ap_queue_info(qid, &type, &func, &depth, &decfg))
1480 if (dom > ap_max_domain_id) {
1481 /* Could not find a valid APQN for this adapter */
1484 "%s(%d) no type info (no APQN found), rm card and queue devices\n",
1486 ap_scan_rm_card_dev_and_queue_devs(ac);
1489 AP_DBF_DBG("%s(%d) no type info (no APQN found), ignored\n",
1495 /* No apdater type info available, an unusable adapter */
1497 AP_DBF_INFO("%s(%d) no valid type (0) info, rm card and queue devices\n",
1499 ap_scan_rm_card_dev_and_queue_devs(ac);
1502 AP_DBF_DBG("%s(%d) no valid type (0) info, ignored\n",
1509 /* Check APQN against existing card device for changes */
1510 if (ac->raw_hwtype != type) {
1511 AP_DBF_INFO("%s(%d) hwtype %d changed, rm card and queue devices\n",
1512 __func__, ap, type);
1513 ap_scan_rm_card_dev_and_queue_devs(ac);
1516 } else if (ac->functions != func) {
1517 AP_DBF_INFO("%s(%d) functions 0x%08x changed, rm card and queue devices\n",
1518 __func__, ap, type);
1519 ap_scan_rm_card_dev_and_queue_devs(ac);
1523 if (decfg && ac->config) {
1525 AP_DBF_INFO("%s(%d) card device config off\n",
1529 if (!decfg && !ac->config) {
1531 AP_DBF_INFO("%s(%d) card device config on\n",
1538 /* Build a new card device */
1539 comp_type = ap_get_compatible_type(qid, type, func);
1541 AP_DBF_WARN("%s(%d) type %d, can't get compatibility type\n",
1542 __func__, ap, type);
1545 ac = ap_card_create(ap, depth, type, comp_type, func);
1547 AP_DBF_WARN("%s(%d) ap_card_create() failed\n",
1551 ac->config = !decfg;
1552 dev = &ac->ap_dev.device;
1553 dev->bus = &ap_bus_type;
1554 dev->parent = ap_root_device;
1555 dev_set_name(dev, "card%02x", ap);
1556 /* Register the new card device with AP bus */
1557 rc = device_register(dev);
1559 AP_DBF_WARN("%s(%d) device_register() failed\n",
1564 /* get it and thus adjust reference counter */
1567 AP_DBF_INFO("%s(%d) new (decfg) card device type=%d func=0x%08x created\n",
1568 __func__, ap, type, func);
1570 AP_DBF_INFO("%s(%d) new card device type=%d func=0x%08x created\n",
1571 __func__, ap, type, func);
1574 /* Verify the domains and the queue devices for this card */
1575 ap_scan_domains(ac);
1577 /* release the card device */
1578 put_device(&ac->ap_dev.device);
1582 * ap_scan_bus(): Scan the AP bus for new devices
1583 * Runs periodically, workqueue timer (ap_config_time)
1585 static void ap_scan_bus(struct work_struct *unused)
1589 ap_fetch_qci_info(ap_qci_info);
1592 AP_DBF_DBG("%s running\n", __func__);
1594 /* loop over all possible adapters */
1595 for (ap = 0; ap <= ap_max_adapter_id; ap++)
1596 ap_scan_adapter(ap);
1598 /* check if there is at least one queue available with default domain */
1599 if (ap_domain_index >= 0) {
1600 struct device *dev =
1601 bus_find_device(&ap_bus_type, NULL,
1602 (void *)(long) ap_domain_index,
1603 __match_queue_device_with_queue_id);
1607 AP_DBF_INFO("no queue device with default domain %d available\n",
1611 mod_timer(&ap_config_timer, jiffies + ap_config_time * HZ);
1614 static void ap_config_timeout(struct timer_list *unused)
1616 queue_work(system_long_wq, &ap_scan_work);
1619 static int __init ap_debug_init(void)
1621 ap_dbf_info = debug_register("ap", 1, 1,
1622 DBF_MAX_SPRINTF_ARGS * sizeof(long));
1623 debug_register_view(ap_dbf_info, &debug_sprintf_view);
1624 debug_set_level(ap_dbf_info, DBF_ERR);
1629 static void __init ap_perms_init(void)
1631 /* all resources useable if no kernel parameter string given */
1632 memset(&ap_perms.ioctlm, 0xFF, sizeof(ap_perms.ioctlm));
1633 memset(&ap_perms.apm, 0xFF, sizeof(ap_perms.apm));
1634 memset(&ap_perms.aqm, 0xFF, sizeof(ap_perms.aqm));
1636 /* apm kernel parameter string */
1638 memset(&ap_perms.apm, 0, sizeof(ap_perms.apm));
1639 ap_parse_mask_str(apm_str, ap_perms.apm, AP_DEVICES,
1643 /* aqm kernel parameter string */
1645 memset(&ap_perms.aqm, 0, sizeof(ap_perms.aqm));
1646 ap_parse_mask_str(aqm_str, ap_perms.aqm, AP_DOMAINS,
1652 * ap_module_init(): The module initialization code.
1654 * Initializes the module.
1656 static int __init ap_module_init(void)
1660 rc = ap_debug_init();
1664 if (!ap_instructions_available()) {
1665 pr_warn("The hardware system does not support AP instructions\n");
1669 /* init ap_queue hashtable */
1670 hash_init(ap_queues);
1672 /* set up the AP permissions (ioctls, ap and aq masks) */
1675 /* Get AP configuration data if available */
1678 /* check default domain setting */
1679 if (ap_domain_index < -1 || ap_domain_index > ap_max_domain_id ||
1680 (ap_domain_index >= 0 &&
1681 !test_bit_inv(ap_domain_index, ap_perms.aqm))) {
1682 pr_warn("%d is not a valid cryptographic domain\n",
1684 ap_domain_index = -1;
1687 /* enable interrupts if available */
1688 if (ap_interrupts_available()) {
1689 rc = register_adapter_interrupt(&ap_airq);
1690 ap_airq_flag = (rc == 0);
1693 /* Create /sys/bus/ap. */
1694 rc = bus_register(&ap_bus_type);
1697 for (i = 0; ap_bus_attrs[i]; i++) {
1698 rc = bus_create_file(&ap_bus_type, ap_bus_attrs[i]);
1703 /* Create /sys/devices/ap. */
1704 ap_root_device = root_device_register("ap");
1705 rc = PTR_ERR_OR_ZERO(ap_root_device);
1709 /* Setup the AP bus rescan timer. */
1710 timer_setup(&ap_config_timer, ap_config_timeout, 0);
1713 * Setup the high resultion poll timer.
1714 * If we are running under z/VM adjust polling to z/VM polling rate.
1717 poll_timeout = 1500000;
1718 hrtimer_init(&ap_poll_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
1719 ap_poll_timer.function = ap_poll_timeout;
1721 /* Start the low priority AP bus poll thread. */
1722 if (ap_thread_flag) {
1723 rc = ap_poll_thread_start();
1728 queue_work(system_long_wq, &ap_scan_work);
1733 hrtimer_cancel(&ap_poll_timer);
1734 root_device_unregister(ap_root_device);
1737 bus_remove_file(&ap_bus_type, ap_bus_attrs[i]);
1738 bus_unregister(&ap_bus_type);
1740 if (ap_using_interrupts())
1741 unregister_adapter_interrupt(&ap_airq);
1745 device_initcall(ap_module_init);