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