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