Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    1) // SPDX-License-Identifier: GPL-2.0+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  * Copyright IBM Corp. 2006, 2012
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  * Author(s): Cornelia Huck <cornelia.huck@de.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  *	      Martin Schwidefsky <schwidefsky@de.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  *	      Ralph Wuerthner <rwuerthn@de.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  *	      Felix Beck <felix.beck@de.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)  *	      Holger Dengler <hd@linux.vnet.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10)  * Adjunct processor bus.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13) #define KMSG_COMPONENT "ap"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14) #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) #include <linux/kernel_stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) #include <linux/moduleparam.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) #include <linux/freezer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) #include <linux/workqueue.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) #include <linux/notifier.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) #include <linux/kthread.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) #include <asm/airq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) #include <linux/atomic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) #include <asm/isc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) #include <linux/hrtimer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) #include <linux/ktime.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) #include <asm/facility.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) #include <linux/crypto.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) #include <linux/mod_devicetable.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) #include <linux/debugfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) #include <linux/ctype.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) #include "ap_bus.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) #include "ap_debug.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43)  * Module parameters; note though this file itself isn't modular.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) int ap_domain_index = -1;	/* Adjunct Processor Domain Index */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) static DEFINE_SPINLOCK(ap_domain_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) module_param_named(domain, ap_domain_index, int, 0440);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) MODULE_PARM_DESC(domain, "domain index for ap devices");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) EXPORT_SYMBOL(ap_domain_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) static int ap_thread_flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) module_param_named(poll_thread, ap_thread_flag, int, 0440);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) MODULE_PARM_DESC(poll_thread, "Turn on/off poll thread, default is 0 (off).");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) static char *apm_str;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) module_param_named(apmask, apm_str, charp, 0440);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) MODULE_PARM_DESC(apmask, "AP bus adapter mask.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) static char *aqm_str;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) module_param_named(aqmask, aqm_str, charp, 0440);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) MODULE_PARM_DESC(aqmask, "AP bus domain mask.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) static struct device *ap_root_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) /* Hashtable of all queue devices on the AP bus */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) DEFINE_HASHTABLE(ap_queues, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) /* lock used for the ap_queues hashtable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) DEFINE_SPINLOCK(ap_queues_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) /* Default permissions (ioctl, card and domain masking) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) struct ap_perms ap_perms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) EXPORT_SYMBOL(ap_perms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) DEFINE_MUTEX(ap_perms_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) EXPORT_SYMBOL(ap_perms_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) static struct ap_config_info *ap_qci_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79)  * AP bus related debug feature things.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) debug_info_t *ap_dbf_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84)  * Workqueue timer for bus rescan.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) static struct timer_list ap_config_timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) static int ap_config_time = AP_CONFIG_TIME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) static void ap_scan_bus(struct work_struct *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) static DECLARE_WORK(ap_scan_work, ap_scan_bus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92)  * Tasklet & timer for AP request polling and interrupts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) static void ap_tasklet_fn(unsigned long);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) static DECLARE_TASKLET_OLD(ap_tasklet, ap_tasklet_fn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) static DECLARE_WAIT_QUEUE_HEAD(ap_poll_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) static struct task_struct *ap_poll_kthread;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) static DEFINE_MUTEX(ap_poll_thread_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) static DEFINE_SPINLOCK(ap_poll_timer_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) static struct hrtimer ap_poll_timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102)  * In LPAR poll with 4kHz frequency. Poll every 250000 nanoseconds.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103)  * If z/VM change to 1500000 nanoseconds to adjust to z/VM polling.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) static unsigned long long poll_timeout = 250000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) /* Maximum domain id, if not given via qci */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) static int ap_max_domain_id = 15;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) /* Maximum adapter id, if not given via qci */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) static int ap_max_adapter_id = 63;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) static struct bus_type ap_bus_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) /* Adapter interrupt definitions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) static void ap_interrupt_handler(struct airq_struct *airq, bool floating);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) static bool ap_irq_flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) static struct airq_struct ap_airq = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 	.handler = ap_interrupt_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 	.isc = AP_ISC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125)  * ap_airq_ptr() - Get the address of the adapter interrupt indicator
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127)  * Returns the address of the local-summary-indicator of the adapter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128)  * interrupt handler for AP, or NULL if adapter interrupts are not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129)  * available.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) void *ap_airq_ptr(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) 	if (ap_irq_flag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 		return ap_airq.lsi_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139)  * ap_interrupts_available(): Test if AP interrupts are available.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141)  * Returns 1 if AP interrupts are available.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) static int ap_interrupts_available(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 	return test_facility(65);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149)  * ap_qci_available(): Test if AP configuration
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150)  * information can be queried via QCI subfunction.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152)  * Returns 1 if subfunction PQAP(QCI) is available.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) static int ap_qci_available(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) 	return test_facility(12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160)  * ap_apft_available(): Test if AP facilities test (APFT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161)  * facility is available.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163)  * Returns 1 if APFT is is available.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) static int ap_apft_available(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 	return test_facility(15);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171)  * ap_qact_available(): Test if the PQAP(QACT) subfunction is available.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173)  * Returns 1 if the QACT subfunction is available.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) static inline int ap_qact_available(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 	if (ap_qci_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 		return ap_qci_info->qact;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183)  * ap_fetch_qci_info(): Fetch cryptographic config info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185)  * Returns the ap configuration info fetched via PQAP(QCI).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186)  * On success 0 is returned, on failure a negative errno
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187)  * is returned, e.g. if the PQAP(QCI) instruction is not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188)  * available, the return value will be -EOPNOTSUPP.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) static inline int ap_fetch_qci_info(struct ap_config_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 	if (!ap_qci_available())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 		return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 	if (!info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 	return ap_qci(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200)  * ap_init_qci_info(): Allocate and query qci config info.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201)  * Does also update the static variables ap_max_domain_id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202)  * and ap_max_adapter_id if this info is available.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) static void __init ap_init_qci_info(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 	if (!ap_qci_available()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 		AP_DBF_INFO("%s QCI not supported\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 	ap_qci_info = kzalloc(sizeof(*ap_qci_info), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 	if (!ap_qci_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 	if (ap_fetch_qci_info(ap_qci_info) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 		kfree(ap_qci_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 		ap_qci_info = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 	AP_DBF_INFO("%s successful fetched initial qci info\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 	if (ap_qci_info->apxa) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 		if (ap_qci_info->Na) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 			ap_max_adapter_id = ap_qci_info->Na;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 			AP_DBF_INFO("%s new ap_max_adapter_id is %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 				    __func__, ap_max_adapter_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 		if (ap_qci_info->Nd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 			ap_max_domain_id = ap_qci_info->Nd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 			AP_DBF_INFO("%s new ap_max_domain_id is %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 				    __func__, ap_max_domain_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237)  * ap_test_config(): helper function to extract the nrth bit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238)  *		     within the unsigned int array field.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) static inline int ap_test_config(unsigned int *field, unsigned int nr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 	return ap_test_bit((field + (nr >> 5)), (nr & 0x1f));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246)  * ap_test_config_card_id(): Test, whether an AP card ID is configured.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248)  * Returns 0 if the card is not configured
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249)  *	   1 if the card is configured or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250)  *	     if the configuration information is not available
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) static inline int ap_test_config_card_id(unsigned int id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 	if (id > ap_max_adapter_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 	if (ap_qci_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 		return ap_test_config(ap_qci_info->apm, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262)  * ap_test_config_usage_domain(): Test, whether an AP usage domain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263)  * is configured.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265)  * Returns 0 if the usage domain is not configured
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266)  *	   1 if the usage domain is configured or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267)  *	     if the configuration information is not available
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) int ap_test_config_usage_domain(unsigned int domain)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 	if (domain > ap_max_domain_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 	if (ap_qci_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 		return ap_test_config(ap_qci_info->aqm, domain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) EXPORT_SYMBOL(ap_test_config_usage_domain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280)  * ap_test_config_ctrl_domain(): Test, whether an AP control domain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281)  * is configured.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282)  * @domain AP control domain ID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284)  * Returns 1 if the control domain is configured
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285)  *	   0 in all other cases
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) int ap_test_config_ctrl_domain(unsigned int domain)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 	if (!ap_qci_info || domain > ap_max_domain_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 	return ap_test_config(ap_qci_info->adm, domain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) EXPORT_SYMBOL(ap_test_config_ctrl_domain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296)  * ap_queue_info(): Check and get AP queue info.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297)  * Returns true if TAPQ succeeded and the info is filled or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298)  * false otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) static bool ap_queue_info(ap_qid_t qid, int *q_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 			  unsigned int *q_fac, int *q_depth, bool *q_decfg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 	struct ap_queue_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 	unsigned long info = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 	/* make sure we don't run into a specifiation exception */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 	if (AP_QID_CARD(qid) > ap_max_adapter_id ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 	    AP_QID_QUEUE(qid) > ap_max_domain_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 	/* call TAPQ on this APQN */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 	status = ap_test_queue(qid, ap_apft_available(), &info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 	switch (status.response_code) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 	case AP_RESPONSE_NORMAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 	case AP_RESPONSE_RESET_IN_PROGRESS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 	case AP_RESPONSE_DECONFIGURED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 	case AP_RESPONSE_CHECKSTOPPED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 	case AP_RESPONSE_BUSY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 		 * According to the architecture in all these cases the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 		 * info should be filled. All bits 0 is not possible as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 		 * there is at least one of the mode bits set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 		if (WARN_ON_ONCE(!info))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 			return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 		*q_type = (int)((info >> 24) & 0xff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 		*q_fac = (unsigned int)(info >> 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 		*q_depth = (int)(info & 0xff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 		*q_decfg = status.response_code == AP_RESPONSE_DECONFIGURED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 		switch (*q_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 			/* For CEX2 and CEX3 the available functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 			 * are not reflected by the facilities bits.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 			 * Instead it is coded into the type. So here
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 			 * modify the function bits based on the type.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 		case AP_DEVICE_TYPE_CEX2A:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 		case AP_DEVICE_TYPE_CEX3A:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 			*q_fac |= 0x08000000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 		case AP_DEVICE_TYPE_CEX2C:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 		case AP_DEVICE_TYPE_CEX3C:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 			*q_fac |= 0x10000000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 		 * A response code which indicates, there is no info available.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) void ap_wait(enum ap_sm_wait wait)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 	ktime_t hr_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 	switch (wait) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 	case AP_SM_WAIT_AGAIN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 	case AP_SM_WAIT_INTERRUPT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 		if (ap_irq_flag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 		if (ap_poll_kthread) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 			wake_up(&ap_poll_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 	case AP_SM_WAIT_TIMEOUT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 		spin_lock_bh(&ap_poll_timer_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 		if (!hrtimer_is_queued(&ap_poll_timer)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 			hr_time = poll_timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 			hrtimer_forward_now(&ap_poll_timer, hr_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 			hrtimer_restart(&ap_poll_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 		spin_unlock_bh(&ap_poll_timer_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 	case AP_SM_WAIT_NONE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386)  * ap_request_timeout(): Handling of request timeouts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387)  * @t: timer making this callback
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389)  * Handles request timeouts.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) void ap_request_timeout(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 	struct ap_queue *aq = from_timer(aq, t, timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 	spin_lock_bh(&aq->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 	ap_wait(ap_sm_event(aq, AP_SM_EVENT_TIMEOUT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 	spin_unlock_bh(&aq->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401)  * ap_poll_timeout(): AP receive polling for finished AP requests.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402)  * @unused: Unused pointer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404)  * Schedules the AP tasklet using a high resolution timer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) static enum hrtimer_restart ap_poll_timeout(struct hrtimer *unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 	tasklet_schedule(&ap_tasklet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 	return HRTIMER_NORESTART;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413)  * ap_interrupt_handler() - Schedule ap_tasklet on interrupt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414)  * @airq: pointer to adapter interrupt descriptor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) static void ap_interrupt_handler(struct airq_struct *airq, bool floating)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 	inc_irq_stat(IRQIO_APB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 	tasklet_schedule(&ap_tasklet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423)  * ap_tasklet_fn(): Tasklet to poll all AP devices.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424)  * @dummy: Unused variable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426)  * Poll all AP devices on the bus.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) static void ap_tasklet_fn(unsigned long dummy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 	int bkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 	struct ap_queue *aq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 	enum ap_sm_wait wait = AP_SM_WAIT_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 	/* Reset the indicator if interrupts are used. Thus new interrupts can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 	 * be received. Doing it in the beginning of the tasklet is therefor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 	 * important that no requests on any AP get lost.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 	if (ap_irq_flag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 		xchg(ap_airq.lsi_ptr, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 	spin_lock_bh(&ap_queues_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 	hash_for_each(ap_queues, bkt, aq, hnode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 		spin_lock_bh(&aq->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 		wait = min(wait, ap_sm_event_loop(aq, AP_SM_EVENT_POLL));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 		spin_unlock_bh(&aq->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 	spin_unlock_bh(&ap_queues_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 	ap_wait(wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) static int ap_pending_requests(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 	int bkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 	struct ap_queue *aq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 	spin_lock_bh(&ap_queues_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 	hash_for_each(ap_queues, bkt, aq, hnode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 		if (aq->queue_count == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 		spin_unlock_bh(&ap_queues_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 	spin_unlock_bh(&ap_queues_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469)  * ap_poll_thread(): Thread that polls for finished requests.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470)  * @data: Unused pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472)  * AP bus poll thread. The purpose of this thread is to poll for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473)  * finished requests in a loop if there is a "free" cpu - that is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474)  * a cpu that doesn't have anything better to do. The polling stops
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475)  * as soon as there is another task or if all messages have been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476)  * delivered.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) static int ap_poll_thread(void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 	DECLARE_WAITQUEUE(wait, current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 	set_user_nice(current, MAX_NICE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 	set_freezable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 	while (!kthread_should_stop()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 		add_wait_queue(&ap_poll_wait, &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 		set_current_state(TASK_INTERRUPTIBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 		if (!ap_pending_requests()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 			schedule();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 			try_to_freeze();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 		set_current_state(TASK_RUNNING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 		remove_wait_queue(&ap_poll_wait, &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 		if (need_resched()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 			schedule();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 			try_to_freeze();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 		ap_tasklet_fn(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) static int ap_poll_thread_start(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 	if (ap_irq_flag || ap_poll_kthread)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 	mutex_lock(&ap_poll_thread_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 	ap_poll_kthread = kthread_run(ap_poll_thread, NULL, "appoll");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 	rc = PTR_ERR_OR_ZERO(ap_poll_kthread);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 		ap_poll_kthread = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 	mutex_unlock(&ap_poll_thread_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) static void ap_poll_thread_stop(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 	if (!ap_poll_kthread)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 	mutex_lock(&ap_poll_thread_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 	kthread_stop(ap_poll_kthread);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 	ap_poll_kthread = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 	mutex_unlock(&ap_poll_thread_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) #define is_card_dev(x) ((x)->parent == ap_root_device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) #define is_queue_dev(x) ((x)->parent != ap_root_device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533)  * ap_bus_match()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534)  * @dev: Pointer to device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535)  * @drv: Pointer to device_driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537)  * AP bus driver registration/unregistration.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) static int ap_bus_match(struct device *dev, struct device_driver *drv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 	struct ap_driver *ap_drv = to_ap_drv(drv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 	struct ap_device_id *id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 	 * Compare device type of the device with the list of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 	 * supported types of the device_driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 	for (id = ap_drv->ids; id->match_flags; id++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 		if (is_card_dev(dev) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 		    id->match_flags & AP_DEVICE_ID_MATCH_CARD_TYPE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 		    id->dev_type == to_ap_dev(dev)->device_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 			return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 		if (is_queue_dev(dev) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 		    id->match_flags & AP_DEVICE_ID_MATCH_QUEUE_TYPE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 		    id->dev_type == to_ap_dev(dev)->device_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 			return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562)  * ap_uevent(): Uevent function for AP devices.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563)  * @dev: Pointer to device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564)  * @env: Pointer to kobj_uevent_env
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566)  * It sets up a single environment variable DEV_TYPE which contains the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567)  * hardware device type.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) static int ap_uevent(struct device *dev, struct kobj_uevent_env *env)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 	struct ap_device *ap_dev = to_ap_dev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 	int retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 	if (!ap_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 	/* Set up DEV_TYPE environment variable. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 	retval = add_uevent_var(env, "DEV_TYPE=%04X", ap_dev->device_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 	if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 		return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 	/* Add MODALIAS= */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 	retval = add_uevent_var(env, "MODALIAS=ap:t%02X", ap_dev->device_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) static int __ap_queue_devices_with_id_unregister(struct device *dev, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 	if (is_queue_dev(dev) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 	    AP_QID_CARD(to_ap_queue(dev)->qid) == (int)(long) data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 		device_unregister(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) static struct bus_type ap_bus_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 	.name = "ap",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 	.match = &ap_bus_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 	.uevent = &ap_uevent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) static int __ap_revise_reserved(struct device *dev, void *dummy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 	int rc, card, queue, devres, drvres;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 	if (is_queue_dev(dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 		card = AP_QID_CARD(to_ap_queue(dev)->qid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 		queue = AP_QID_QUEUE(to_ap_queue(dev)->qid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 		mutex_lock(&ap_perms_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 		devres = test_bit_inv(card, ap_perms.apm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 			&& test_bit_inv(queue, ap_perms.aqm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 		mutex_unlock(&ap_perms_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 		drvres = to_ap_drv(dev->driver)->flags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 			& AP_DRIVER_FLAG_DEFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 		if (!!devres != !!drvres) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 			AP_DBF_DBG("reprobing queue=%02x.%04x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 				   card, queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 			rc = device_reprobe(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) static void ap_bus_revise_bindings(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 	bus_for_each_dev(&ap_bus_type, NULL, NULL, __ap_revise_reserved);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) int ap_owned_by_def_drv(int card, int queue)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 	if (card < 0 || card >= AP_DEVICES || queue < 0 || queue >= AP_DOMAINS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 	mutex_lock(&ap_perms_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 	if (test_bit_inv(card, ap_perms.apm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 	    && test_bit_inv(queue, ap_perms.aqm))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 		rc = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 	mutex_unlock(&ap_perms_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) EXPORT_SYMBOL(ap_owned_by_def_drv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) int ap_apqn_in_matrix_owned_by_def_drv(unsigned long *apm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 				       unsigned long *aqm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 	int card, queue, rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 	mutex_lock(&ap_perms_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 	for (card = 0; !rc && card < AP_DEVICES; card++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 		if (test_bit_inv(card, apm) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 		    test_bit_inv(card, ap_perms.apm))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 			for (queue = 0; !rc && queue < AP_DOMAINS; queue++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 				if (test_bit_inv(queue, aqm) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 				    test_bit_inv(queue, ap_perms.aqm))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 					rc = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 	mutex_unlock(&ap_perms_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) EXPORT_SYMBOL(ap_apqn_in_matrix_owned_by_def_drv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) static int ap_device_probe(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 	struct ap_device *ap_dev = to_ap_dev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 	struct ap_driver *ap_drv = to_ap_drv(dev->driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 	int card, queue, devres, drvres, rc = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 	if (!get_device(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 	if (is_queue_dev(dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 		 * If the apqn is marked as reserved/used by ap bus and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 		 * default drivers, only probe with drivers with the default
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 		 * flag set. If it is not marked, only probe with drivers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 		 * with the default flag not set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 		card = AP_QID_CARD(to_ap_queue(dev)->qid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 		queue = AP_QID_QUEUE(to_ap_queue(dev)->qid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 		mutex_lock(&ap_perms_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 		devres = test_bit_inv(card, ap_perms.apm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 			&& test_bit_inv(queue, ap_perms.aqm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 		mutex_unlock(&ap_perms_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 		drvres = ap_drv->flags & AP_DRIVER_FLAG_DEFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 		if (!!devres != !!drvres)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 	/* Add queue/card to list of active queues/cards */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 	spin_lock_bh(&ap_queues_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 	if (is_queue_dev(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 		hash_add(ap_queues, &to_ap_queue(dev)->hnode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 			 to_ap_queue(dev)->qid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 	spin_unlock_bh(&ap_queues_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 	ap_dev->drv = ap_drv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 	rc = ap_drv->probe ? ap_drv->probe(ap_dev) : -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 		spin_lock_bh(&ap_queues_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 		if (is_queue_dev(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 			hash_del(&to_ap_queue(dev)->hnode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 		spin_unlock_bh(&ap_queues_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 		ap_dev->drv = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 		put_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) static int ap_device_remove(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 	struct ap_device *ap_dev = to_ap_dev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 	struct ap_driver *ap_drv = ap_dev->drv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 	/* prepare ap queue device removal */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 	if (is_queue_dev(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 		ap_queue_prepare_remove(to_ap_queue(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 	/* driver's chance to clean up gracefully */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 	if (ap_drv->remove)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 		ap_drv->remove(ap_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 	/* now do the ap queue device remove */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 	if (is_queue_dev(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 		ap_queue_remove(to_ap_queue(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 	/* Remove queue/card from list of active queues/cards */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 	spin_lock_bh(&ap_queues_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 	if (is_queue_dev(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 		hash_del(&to_ap_queue(dev)->hnode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 	spin_unlock_bh(&ap_queues_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 	put_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) struct ap_queue *ap_get_qdev(ap_qid_t qid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 	int bkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 	struct ap_queue *aq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 	spin_lock_bh(&ap_queues_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 	hash_for_each(ap_queues, bkt, aq, hnode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 		if (aq->qid == qid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 			get_device(&aq->ap_dev.device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 			spin_unlock_bh(&ap_queues_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 			return aq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 	spin_unlock_bh(&ap_queues_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) EXPORT_SYMBOL(ap_get_qdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) int ap_driver_register(struct ap_driver *ap_drv, struct module *owner,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 		       char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 	struct device_driver *drv = &ap_drv->driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 	drv->bus = &ap_bus_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 	drv->probe = ap_device_probe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 	drv->remove = ap_device_remove;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 	drv->owner = owner;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 	drv->name = name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 	return driver_register(drv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) EXPORT_SYMBOL(ap_driver_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) void ap_driver_unregister(struct ap_driver *ap_drv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 	driver_unregister(&ap_drv->driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) EXPORT_SYMBOL(ap_driver_unregister);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) void ap_bus_force_rescan(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 	/* processing a asynchronous bus rescan */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 	del_timer(&ap_config_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 	queue_work(system_long_wq, &ap_scan_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 	flush_work(&ap_scan_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) EXPORT_SYMBOL(ap_bus_force_rescan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) * A config change has happened, force an ap bus rescan.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) void ap_bus_cfg_chg(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 	AP_DBF_DBG("%s config change, forcing bus rescan\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 	ap_bus_force_rescan();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808)  * hex2bitmap() - parse hex mask string and set bitmap.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809)  * Valid strings are "0x012345678" with at least one valid hex number.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810)  * Rest of the bitmap to the right is padded with 0. No spaces allowed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811)  * within the string, the leading 0x may be omitted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812)  * Returns the bitmask with exactly the bits set as given by the hex
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813)  * string (both in big endian order).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) static int hex2bitmap(const char *str, unsigned long *bitmap, int bits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 	int i, n, b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 	/* bits needs to be a multiple of 8 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 	if (bits & 0x07)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 	if (str[0] == '0' && str[1] == 'x')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 		str++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 	if (*str == 'x')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 		str++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 	for (i = 0; isxdigit(*str) && i < bits; str++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 		b = hex_to_bin(*str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 		for (n = 0; n < 4; n++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 			if (b & (0x08 >> n))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 				set_bit_inv(i + n, bitmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 		i += 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 	if (*str == '\n')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 		str++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 	if (*str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844)  * modify_bitmap() - parse bitmask argument and modify an existing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845)  * bit mask accordingly. A concatenation (done with ',') of these
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846)  * terms is recognized:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847)  *   +<bitnr>[-<bitnr>] or -<bitnr>[-<bitnr>]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848)  * <bitnr> may be any valid number (hex, decimal or octal) in the range
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849)  * 0...bits-1; the leading + or - is required. Here are some examples:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850)  *   +0-15,+32,-128,-0xFF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851)  *   -0-255,+1-16,+0x128
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852)  *   +1,+2,+3,+4,-5,-7-10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853)  * Returns the new bitmap after all changes have been applied. Every
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854)  * positive value in the string will set a bit and every negative value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855)  * in the string will clear a bit. As a bit may be touched more than once,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856)  * the last 'operation' wins:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857)  * +0-255,-128 = first bits 0-255 will be set, then bit 128 will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858)  * cleared again. All other bits are unmodified.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) static int modify_bitmap(const char *str, unsigned long *bitmap, int bits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 	int a, i, z;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 	char *np, sign;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 	/* bits needs to be a multiple of 8 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 	if (bits & 0x07)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 	while (*str) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 		sign = *str++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 		if (sign != '+' && sign != '-')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 		a = z = simple_strtoul(str, &np, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 		if (str == np || a >= bits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 		str = np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 		if (*str == '-') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 			z = simple_strtoul(++str, &np, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 			if (str == np || a > z || z >= bits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 				return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 			str = np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 		for (i = a; i <= z; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 			if (sign == '+')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 				set_bit_inv(i, bitmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 				clear_bit_inv(i, bitmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 		while (*str == ',' || *str == '\n')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 			str++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) int ap_parse_mask_str(const char *str,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 		      unsigned long *bitmap, int bits,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 		      struct mutex *lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 	unsigned long *newmap, size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 	/* bits needs to be a multiple of 8 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 	if (bits & 0x07)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 	size = BITS_TO_LONGS(bits)*sizeof(unsigned long);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 	newmap = kmalloc(size, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 	if (!newmap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 	if (mutex_lock_interruptible(lock)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 		kfree(newmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 		return -ERESTARTSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 	if (*str == '+' || *str == '-') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 		memcpy(newmap, bitmap, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 		rc = modify_bitmap(str, newmap, bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 		memset(newmap, 0, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 		rc = hex2bitmap(str, newmap, bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 	if (rc == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 		memcpy(bitmap, newmap, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 	mutex_unlock(lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 	kfree(newmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) EXPORT_SYMBOL(ap_parse_mask_str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931)  * AP bus attributes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) static ssize_t ap_domain_show(struct bus_type *bus, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 	return scnprintf(buf, PAGE_SIZE, "%d\n", ap_domain_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) static ssize_t ap_domain_store(struct bus_type *bus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 			       const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 	int domain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 	if (sscanf(buf, "%i\n", &domain) != 1 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 	    domain < 0 || domain > ap_max_domain_id ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 	    !test_bit_inv(domain, ap_perms.aqm))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 	spin_lock_bh(&ap_domain_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 	ap_domain_index = domain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 	spin_unlock_bh(&ap_domain_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 	AP_DBF_INFO("stored new default domain=%d\n", domain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) static BUS_ATTR_RW(ap_domain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) static ssize_t ap_control_domain_mask_show(struct bus_type *bus, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 	if (!ap_qci_info)	/* QCI not supported */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 		return scnprintf(buf, PAGE_SIZE, "not supported\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 	return scnprintf(buf, PAGE_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 			 "0x%08x%08x%08x%08x%08x%08x%08x%08x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 			 ap_qci_info->adm[0], ap_qci_info->adm[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 			 ap_qci_info->adm[2], ap_qci_info->adm[3],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 			 ap_qci_info->adm[4], ap_qci_info->adm[5],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 			 ap_qci_info->adm[6], ap_qci_info->adm[7]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) static BUS_ATTR_RO(ap_control_domain_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) static ssize_t ap_usage_domain_mask_show(struct bus_type *bus, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 	if (!ap_qci_info)	/* QCI not supported */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 		return scnprintf(buf, PAGE_SIZE, "not supported\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 	return scnprintf(buf, PAGE_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 			 "0x%08x%08x%08x%08x%08x%08x%08x%08x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 			 ap_qci_info->aqm[0], ap_qci_info->aqm[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 			 ap_qci_info->aqm[2], ap_qci_info->aqm[3],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 			 ap_qci_info->aqm[4], ap_qci_info->aqm[5],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 			 ap_qci_info->aqm[6], ap_qci_info->aqm[7]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) static BUS_ATTR_RO(ap_usage_domain_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) static ssize_t ap_adapter_mask_show(struct bus_type *bus, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 	if (!ap_qci_info)	/* QCI not supported */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 		return scnprintf(buf, PAGE_SIZE, "not supported\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 	return scnprintf(buf, PAGE_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 			 "0x%08x%08x%08x%08x%08x%08x%08x%08x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 			 ap_qci_info->apm[0], ap_qci_info->apm[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 			 ap_qci_info->apm[2], ap_qci_info->apm[3],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 			 ap_qci_info->apm[4], ap_qci_info->apm[5],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 			 ap_qci_info->apm[6], ap_qci_info->apm[7]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) static BUS_ATTR_RO(ap_adapter_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) static ssize_t ap_interrupts_show(struct bus_type *bus, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 	return scnprintf(buf, PAGE_SIZE, "%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 			 ap_irq_flag ? 1 : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) static BUS_ATTR_RO(ap_interrupts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) static ssize_t config_time_show(struct bus_type *bus, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 	return scnprintf(buf, PAGE_SIZE, "%d\n", ap_config_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) static ssize_t config_time_store(struct bus_type *bus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 				 const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 	int time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 	if (sscanf(buf, "%d\n", &time) != 1 || time < 5 || time > 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 	ap_config_time = time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 	mod_timer(&ap_config_timer, jiffies + ap_config_time * HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) static BUS_ATTR_RW(config_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) static ssize_t poll_thread_show(struct bus_type *bus, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 	return scnprintf(buf, PAGE_SIZE, "%d\n", ap_poll_kthread ? 1 : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) static ssize_t poll_thread_store(struct bus_type *bus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 				 const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 	int flag, rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 	if (sscanf(buf, "%d\n", &flag) != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 	if (flag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 		rc = ap_poll_thread_start();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 		if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 			count = rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 		ap_poll_thread_stop();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) static BUS_ATTR_RW(poll_thread);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) static ssize_t poll_timeout_show(struct bus_type *bus, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 	return scnprintf(buf, PAGE_SIZE, "%llu\n", poll_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) static ssize_t poll_timeout_store(struct bus_type *bus, const char *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 				  size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 	unsigned long long time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 	ktime_t hr_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 	/* 120 seconds = maximum poll interval */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 	if (sscanf(buf, "%llu\n", &time) != 1 || time < 1 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 	    time > 120000000000ULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 	poll_timeout = time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 	hr_time = poll_timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 	spin_lock_bh(&ap_poll_timer_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 	hrtimer_cancel(&ap_poll_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 	hrtimer_set_expires(&ap_poll_timer, hr_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 	hrtimer_start_expires(&ap_poll_timer, HRTIMER_MODE_ABS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 	spin_unlock_bh(&ap_poll_timer_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) static BUS_ATTR_RW(poll_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) static ssize_t ap_max_domain_id_show(struct bus_type *bus, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 	return scnprintf(buf, PAGE_SIZE, "%d\n", ap_max_domain_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) static BUS_ATTR_RO(ap_max_domain_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) static ssize_t ap_max_adapter_id_show(struct bus_type *bus, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 	return scnprintf(buf, PAGE_SIZE, "%d\n", ap_max_adapter_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) static BUS_ATTR_RO(ap_max_adapter_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) static ssize_t apmask_show(struct bus_type *bus, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 	if (mutex_lock_interruptible(&ap_perms_mutex))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 		return -ERESTARTSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 	rc = scnprintf(buf, PAGE_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 		       "0x%016lx%016lx%016lx%016lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 		       ap_perms.apm[0], ap_perms.apm[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 		       ap_perms.apm[2], ap_perms.apm[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 	mutex_unlock(&ap_perms_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) static ssize_t apmask_store(struct bus_type *bus, const char *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 			    size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 	rc = ap_parse_mask_str(buf, ap_perms.apm, AP_DEVICES, &ap_perms_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 	ap_bus_revise_bindings();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) static BUS_ATTR_RW(apmask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) static ssize_t aqmask_show(struct bus_type *bus, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 	if (mutex_lock_interruptible(&ap_perms_mutex))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 		return -ERESTARTSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 	rc = scnprintf(buf, PAGE_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 		       "0x%016lx%016lx%016lx%016lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 		       ap_perms.aqm[0], ap_perms.aqm[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 		       ap_perms.aqm[2], ap_perms.aqm[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 	mutex_unlock(&ap_perms_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) static ssize_t aqmask_store(struct bus_type *bus, const char *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) 			    size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 	rc = ap_parse_mask_str(buf, ap_perms.aqm, AP_DOMAINS, &ap_perms_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) 	ap_bus_revise_bindings();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) static BUS_ATTR_RW(aqmask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) static struct bus_attribute *const ap_bus_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 	&bus_attr_ap_domain,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 	&bus_attr_ap_control_domain_mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 	&bus_attr_ap_usage_domain_mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) 	&bus_attr_ap_adapter_mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) 	&bus_attr_config_time,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 	&bus_attr_poll_thread,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 	&bus_attr_ap_interrupts,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 	&bus_attr_poll_timeout,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) 	&bus_attr_ap_max_domain_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 	&bus_attr_ap_max_adapter_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) 	&bus_attr_apmask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) 	&bus_attr_aqmask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) 	NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177)  * ap_select_domain(): Select an AP domain if possible and we haven't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178)  * already done so before.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) static void ap_select_domain(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) 	struct ap_queue_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) 	int card, dom;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) 	 * Choose the default domain. Either the one specified with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) 	 * the "domain=" parameter or the first domain with at least
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) 	 * one valid APQN.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) 	spin_lock_bh(&ap_domain_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) 	if (ap_domain_index >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) 		/* Domain has already been selected. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) 	for (dom = 0; dom <= ap_max_domain_id; dom++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) 		if (!ap_test_config_usage_domain(dom) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) 		    !test_bit_inv(dom, ap_perms.aqm))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) 		for (card = 0; card <= ap_max_adapter_id; card++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) 			if (!ap_test_config_card_id(card) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) 			    !test_bit_inv(card, ap_perms.apm))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) 			status = ap_test_queue(AP_MKQID(card, dom),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) 					       ap_apft_available(),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) 					       NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) 			if (status.response_code == AP_RESPONSE_NORMAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) 		if (card <= ap_max_adapter_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) 	if (dom <= ap_max_domain_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) 		ap_domain_index = dom;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) 		AP_DBF_INFO("%s new default domain is %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) 			    __func__, ap_domain_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) 	spin_unlock_bh(&ap_domain_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222)  * This function checks the type and returns either 0 for not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223)  * supported or the highest compatible type value (which may
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224)  * include the input type value).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) static int ap_get_compatible_type(ap_qid_t qid, int rawtype, unsigned int func)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) 	int comp_type = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) 	/* < CEX2A is not supported */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) 	if (rawtype < AP_DEVICE_TYPE_CEX2A) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) 		AP_DBF_WARN("get_comp_type queue=%02x.%04x unsupported type %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) 			    AP_QID_CARD(qid), AP_QID_QUEUE(qid), rawtype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) 	/* up to CEX7 known and fully supported */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) 	if (rawtype <= AP_DEVICE_TYPE_CEX7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) 		return rawtype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) 	 * unknown new type > CEX7, check for compatibility
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) 	 * to the highest known and supported type which is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) 	 * currently CEX7 with the help of the QACT function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) 	if (ap_qact_available()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) 		struct ap_queue_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) 		union ap_qact_ap_info apinfo = {0};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) 		apinfo.mode = (func >> 26) & 0x07;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) 		apinfo.cat = AP_DEVICE_TYPE_CEX7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) 		status = ap_qact(qid, 0, &apinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) 		if (status.response_code == AP_RESPONSE_NORMAL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) 		    && apinfo.cat >= AP_DEVICE_TYPE_CEX2A
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) 		    && apinfo.cat <= AP_DEVICE_TYPE_CEX7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) 			comp_type = apinfo.cat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) 	if (!comp_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) 		AP_DBF_WARN("get_comp_type queue=%02x.%04x unable to map type %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) 			    AP_QID_CARD(qid), AP_QID_QUEUE(qid), rawtype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) 	else if (comp_type != rawtype)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) 		AP_DBF_INFO("get_comp_type queue=%02x.%04x map type %d to %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) 			    AP_QID_CARD(qid), AP_QID_QUEUE(qid),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) 			    rawtype, comp_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) 	return comp_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267)  * Helper function to be used with bus_find_dev
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268)  * matches for the card device with the given id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) static int __match_card_device_with_id(struct device *dev, const void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) 	return is_card_dev(dev) && to_ap_card(dev)->id == (int)(long)(void *) data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276)  * Helper function to be used with bus_find_dev
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277)  * matches for the queue device with a given qid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) static int __match_queue_device_with_qid(struct device *dev, const void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) 	return is_queue_dev(dev) && to_ap_queue(dev)->qid == (int)(long) data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285)  * Helper function to be used with bus_find_dev
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286)  * matches any queue device with given queue id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) static int __match_queue_device_with_queue_id(struct device *dev, const void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) 	return is_queue_dev(dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) 		&& AP_QID_QUEUE(to_ap_queue(dev)->qid) == (int)(long) data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295)  * Helper function for ap_scan_bus().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296)  * Remove card device and associated queue devices.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) static inline void ap_scan_rm_card_dev_and_queue_devs(struct ap_card *ac)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) 	bus_for_each_dev(&ap_bus_type, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) 			 (void *)(long) ac->id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) 			 __ap_queue_devices_with_id_unregister);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) 	device_unregister(&ac->ap_dev.device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307)  * Helper function for ap_scan_bus().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308)  * Does the scan bus job for all the domains within
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309)  * a valid adapter given by an ap_card ptr.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) static inline void ap_scan_domains(struct ap_card *ac)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) 	bool decfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) 	ap_qid_t qid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) 	unsigned int func;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) 	struct device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) 	struct ap_queue *aq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) 	int rc, dom, depth, type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) 	 * Go through the configuration for the domains and compare them
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) 	 * to the existing queue devices. Also take care of the config
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) 	 * and error state for the queue devices.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) 	for (dom = 0; dom <= ap_max_domain_id; dom++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) 		qid = AP_MKQID(ac->id, dom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) 		dev = bus_find_device(&ap_bus_type, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) 				      (void *)(long) qid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) 				      __match_queue_device_with_qid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) 		aq = dev ? to_ap_queue(dev) : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) 		if (!ap_test_config_usage_domain(dom)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) 			if (dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) 				AP_DBF_INFO("%s(%d,%d) not in config any more, rm queue device\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) 					    __func__, ac->id, dom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) 				device_unregister(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) 				put_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) 		/* domain is valid, get info from this APQN */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) 		if (!ap_queue_info(qid, &type, &func, &depth, &decfg)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) 			if (aq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) 				AP_DBF_INFO(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) 					"%s(%d,%d) ap_queue_info() not successful, rm queue device\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) 					__func__, ac->id, dom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) 				device_unregister(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) 				put_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) 		/* if no queue device exists, create a new one */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) 		if (!aq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) 			aq = ap_queue_create(qid, ac->ap_dev.device_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) 			if (!aq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) 				AP_DBF_WARN("%s(%d,%d) ap_queue_create() failed\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) 					    __func__, ac->id, dom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) 			aq->card = ac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) 			aq->config = !decfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) 			dev = &aq->ap_dev.device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) 			dev->bus = &ap_bus_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) 			dev->parent = &ac->ap_dev.device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) 			dev_set_name(dev, "%02x.%04x", ac->id, dom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) 			/* register queue device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) 			rc = device_register(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) 			if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) 				AP_DBF_WARN("%s(%d,%d) device_register() failed\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) 					    __func__, ac->id, dom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) 				goto put_dev_and_continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) 			/* get it and thus adjust reference counter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) 			get_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) 			if (decfg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) 				AP_DBF_INFO("%s(%d,%d) new (decfg) queue device created\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) 					    __func__, ac->id, dom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) 				AP_DBF_INFO("%s(%d,%d) new queue device created\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) 					    __func__, ac->id, dom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) 			goto put_dev_and_continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) 		/* Check config state on the already existing queue device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) 		spin_lock_bh(&aq->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) 		if (decfg && aq->config) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) 			/* config off this queue device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) 			aq->config = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) 			if (aq->dev_state > AP_DEV_STATE_UNINITIATED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) 				aq->dev_state = AP_DEV_STATE_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) 				aq->last_err_rc = AP_RESPONSE_DECONFIGURED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) 			spin_unlock_bh(&aq->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) 			AP_DBF_INFO("%s(%d,%d) queue device config off\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) 				    __func__, ac->id, dom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) 			/* 'receive' pending messages with -EAGAIN */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) 			ap_flush_queue(aq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) 			goto put_dev_and_continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) 		if (!decfg && !aq->config) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) 			/* config on this queue device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) 			aq->config = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) 			if (aq->dev_state > AP_DEV_STATE_UNINITIATED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) 				aq->dev_state = AP_DEV_STATE_OPERATING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) 				aq->sm_state = AP_SM_STATE_RESET_START;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) 			spin_unlock_bh(&aq->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) 			AP_DBF_INFO("%s(%d,%d) queue device config on\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) 				    __func__, ac->id, dom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) 			goto put_dev_and_continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) 		/* handle other error states */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) 		if (!decfg && aq->dev_state == AP_DEV_STATE_ERROR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) 			spin_unlock_bh(&aq->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) 			/* 'receive' pending messages with -EAGAIN */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) 			ap_flush_queue(aq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) 			/* re-init (with reset) the queue device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) 			ap_queue_init_state(aq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) 			AP_DBF_INFO("%s(%d,%d) queue device reinit enforced\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) 				    __func__, ac->id, dom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) 			goto put_dev_and_continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) 		spin_unlock_bh(&aq->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) put_dev_and_continue:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) 		put_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429)  * Helper function for ap_scan_bus().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430)  * Does the scan bus job for the given adapter id.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) static inline void ap_scan_adapter(int ap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) 	bool decfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) 	ap_qid_t qid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) 	unsigned int func;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) 	struct device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) 	struct ap_card *ac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) 	int rc, dom, depth, type, comp_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) 	/* Is there currently a card device for this adapter ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) 	dev = bus_find_device(&ap_bus_type, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) 			      (void *)(long) ap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) 			      __match_card_device_with_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) 	ac = dev ? to_ap_card(dev) : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) 	/* Adapter not in configuration ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) 	if (!ap_test_config_card_id(ap)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) 		if (ac) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) 			AP_DBF_INFO("%s(%d) ap not in config any more, rm card and queue devices\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) 				    __func__, ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) 			ap_scan_rm_card_dev_and_queue_devs(ac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) 			put_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) 	 * Adapter ap is valid in the current configuration. So do some checks:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) 	 * If no card device exists, build one. If a card device exists, check
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) 	 * for type and functions changed. For all this we need to find a valid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) 	 * APQN first.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) 	for (dom = 0; dom <= ap_max_domain_id; dom++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) 		if (ap_test_config_usage_domain(dom)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) 			qid = AP_MKQID(ap, dom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) 			if (ap_queue_info(qid, &type, &func, &depth, &decfg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) 	if (dom > ap_max_domain_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) 		/* Could not find a valid APQN for this adapter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) 		if (ac) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) 			AP_DBF_INFO(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) 				"%s(%d) no type info (no APQN found), rm card and queue devices\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) 				__func__, ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) 			ap_scan_rm_card_dev_and_queue_devs(ac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) 			put_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) 			AP_DBF_DBG("%s(%d) no type info (no APQN found), ignored\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) 				   __func__, ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) 	if (!type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) 		/* No apdater type info available, an unusable adapter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) 		if (ac) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) 			AP_DBF_INFO("%s(%d) no valid type (0) info, rm card and queue devices\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) 				    __func__, ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) 			ap_scan_rm_card_dev_and_queue_devs(ac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) 			put_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) 			AP_DBF_DBG("%s(%d) no valid type (0) info, ignored\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) 				   __func__, ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) 	if (ac) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) 		/* Check APQN against existing card device for changes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) 		if (ac->raw_hwtype != type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) 			AP_DBF_INFO("%s(%d) hwtype %d changed, rm card and queue devices\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) 				    __func__, ap, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) 			ap_scan_rm_card_dev_and_queue_devs(ac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) 			put_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) 			ac = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) 		} else if (ac->functions != func) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) 			AP_DBF_INFO("%s(%d) functions 0x%08x changed, rm card and queue devices\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) 				    __func__, ap, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) 			ap_scan_rm_card_dev_and_queue_devs(ac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) 			put_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) 			ac = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) 			if (decfg && ac->config) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) 				ac->config = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) 				AP_DBF_INFO("%s(%d) card device config off\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) 					    __func__, ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) 			if (!decfg && !ac->config) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) 				ac->config = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) 				AP_DBF_INFO("%s(%d) card device config on\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) 					    __func__, ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) 	if (!ac) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) 		/* Build a new card device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) 		comp_type = ap_get_compatible_type(qid, type, func);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) 		if (!comp_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) 			AP_DBF_WARN("%s(%d) type %d, can't get compatibility type\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) 				    __func__, ap, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) 		ac = ap_card_create(ap, depth, type, comp_type, func);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) 		if (!ac) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) 			AP_DBF_WARN("%s(%d) ap_card_create() failed\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) 				    __func__, ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) 		ac->config = !decfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) 		dev = &ac->ap_dev.device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) 		dev->bus = &ap_bus_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) 		dev->parent = ap_root_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) 		dev_set_name(dev, "card%02x", ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) 		/* Register the new card device with AP bus */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) 		rc = device_register(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) 		if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) 			AP_DBF_WARN("%s(%d) device_register() failed\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) 				    __func__, ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) 			put_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) 		/* get it and thus adjust reference counter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) 		get_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) 		if (decfg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) 			AP_DBF_INFO("%s(%d) new (decfg) card device type=%d func=0x%08x created\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) 				    __func__, ap, type, func);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) 			AP_DBF_INFO("%s(%d) new card device type=%d func=0x%08x created\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) 				    __func__, ap, type, func);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) 	/* Verify the domains and the queue devices for this card */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) 	ap_scan_domains(ac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) 	/* release the card device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) 	put_device(&ac->ap_dev.device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573)  * ap_scan_bus(): Scan the AP bus for new devices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574)  * Runs periodically, workqueue timer (ap_config_time)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) static void ap_scan_bus(struct work_struct *unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) 	int ap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) 	ap_fetch_qci_info(ap_qci_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) 	ap_select_domain();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) 	AP_DBF_DBG("%s running\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) 	/* loop over all possible adapters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) 	for (ap = 0; ap <= ap_max_adapter_id; ap++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) 		ap_scan_adapter(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) 	/* check if there is at least one queue available with default domain */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) 	if (ap_domain_index >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) 		struct device *dev =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) 			bus_find_device(&ap_bus_type, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) 					(void *)(long) ap_domain_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) 					__match_queue_device_with_queue_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) 		if (dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) 			put_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) 			AP_DBF_INFO("no queue device with default domain %d available\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) 				    ap_domain_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) 	mod_timer(&ap_config_timer, jiffies + ap_config_time * HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) static void ap_config_timeout(struct timer_list *unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) 	queue_work(system_long_wq, &ap_scan_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) static int __init ap_debug_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) 	ap_dbf_info = debug_register("ap", 1, 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) 				     DBF_MAX_SPRINTF_ARGS * sizeof(long));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) 	debug_register_view(ap_dbf_info, &debug_sprintf_view);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) 	debug_set_level(ap_dbf_info, DBF_ERR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) static void __init ap_perms_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) 	/* all resources useable if no kernel parameter string given */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) 	memset(&ap_perms.ioctlm, 0xFF, sizeof(ap_perms.ioctlm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) 	memset(&ap_perms.apm, 0xFF, sizeof(ap_perms.apm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) 	memset(&ap_perms.aqm, 0xFF, sizeof(ap_perms.aqm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) 	/* apm kernel parameter string */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) 	if (apm_str) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) 		memset(&ap_perms.apm, 0, sizeof(ap_perms.apm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) 		ap_parse_mask_str(apm_str, ap_perms.apm, AP_DEVICES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) 				  &ap_perms_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) 	/* aqm kernel parameter string */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) 	if (aqm_str) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) 		memset(&ap_perms.aqm, 0, sizeof(ap_perms.aqm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) 		ap_parse_mask_str(aqm_str, ap_perms.aqm, AP_DOMAINS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) 				  &ap_perms_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643)  * ap_module_init(): The module initialization code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645)  * Initializes the module.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) static int __init ap_module_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) 	int rc, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) 	rc = ap_debug_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) 	if (!ap_instructions_available()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) 		pr_warn("The hardware system does not support AP instructions\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) 	/* init ap_queue hashtable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) 	hash_init(ap_queues);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) 	/* set up the AP permissions (ioctls, ap and aq masks) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) 	ap_perms_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) 	/* Get AP configuration data if available */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) 	ap_init_qci_info();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) 	/* check default domain setting */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) 	if (ap_domain_index < -1 || ap_domain_index > ap_max_domain_id ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) 	    (ap_domain_index >= 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) 	     !test_bit_inv(ap_domain_index, ap_perms.aqm))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) 		pr_warn("%d is not a valid cryptographic domain\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) 			ap_domain_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) 		ap_domain_index = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) 	/* enable interrupts if available */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) 	if (ap_interrupts_available()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) 		rc = register_adapter_interrupt(&ap_airq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) 		ap_irq_flag = (rc == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) 	/* Create /sys/bus/ap. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) 	rc = bus_register(&ap_bus_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) 	for (i = 0; ap_bus_attrs[i]; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) 		rc = bus_create_file(&ap_bus_type, ap_bus_attrs[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) 		if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) 			goto out_bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) 	/* Create /sys/devices/ap. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) 	ap_root_device = root_device_register("ap");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) 	rc = PTR_ERR_OR_ZERO(ap_root_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) 		goto out_bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) 	/* Setup the AP bus rescan timer. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) 	timer_setup(&ap_config_timer, ap_config_timeout, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) 	 * Setup the high resultion poll timer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) 	 * If we are running under z/VM adjust polling to z/VM polling rate.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) 	if (MACHINE_IS_VM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) 		poll_timeout = 1500000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) 	hrtimer_init(&ap_poll_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) 	ap_poll_timer.function = ap_poll_timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) 	/* Start the low priority AP bus poll thread. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) 	if (ap_thread_flag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) 		rc = ap_poll_thread_start();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) 		if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) 			goto out_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) 	queue_work(system_long_wq, &ap_scan_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) out_work:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) 	hrtimer_cancel(&ap_poll_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) 	root_device_unregister(ap_root_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) out_bus:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) 	while (i--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) 		bus_remove_file(&ap_bus_type, ap_bus_attrs[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) 	bus_unregister(&ap_bus_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) 	if (ap_irq_flag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) 		unregister_adapter_interrupt(&ap_airq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) 	kfree(ap_qci_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) device_initcall(ap_module_init);