Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1 | /* |
Holger Dengler | 7501455 | 2012-08-28 16:41:50 +0200 | [diff] [blame] | 2 | * Copyright IBM Corp. 2006, 2012 |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 3 | * Author(s): Cornelia Huck <cornelia.huck@de.ibm.com> |
| 4 | * Martin Schwidefsky <schwidefsky@de.ibm.com> |
| 5 | * Ralph Wuerthner <rwuerthn@de.ibm.com> |
Felix Beck | cb17a63 | 2008-12-25 13:38:41 +0100 | [diff] [blame] | 6 | * Felix Beck <felix.beck@de.ibm.com> |
Holger Dengler | 6bed05b | 2011-07-24 10:48:25 +0200 | [diff] [blame] | 7 | * Holger Dengler <hd@linux.vnet.ibm.com> |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 8 | * |
| 9 | * Adjunct processor bus. |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation; either version 2, or (at your option) |
| 14 | * any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program; if not, write to the Free Software |
| 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 24 | */ |
| 25 | |
Martin Schwidefsky | 136f7a1 | 2008-12-25 13:39:46 +0100 | [diff] [blame] | 26 | #define KMSG_COMPONENT "ap" |
| 27 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt |
| 28 | |
Holger Dengler | 62d146f | 2011-01-05 12:47:38 +0100 | [diff] [blame] | 29 | #include <linux/kernel_stat.h> |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 30 | #include <linux/module.h> |
| 31 | #include <linux/init.h> |
| 32 | #include <linux/delay.h> |
| 33 | #include <linux/err.h> |
| 34 | #include <linux/interrupt.h> |
| 35 | #include <linux/workqueue.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 36 | #include <linux/slab.h> |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 37 | #include <linux/notifier.h> |
| 38 | #include <linux/kthread.h> |
| 39 | #include <linux/mutex.h> |
Ralph Wuerthner | 85eca85 | 2006-12-08 15:54:07 +0100 | [diff] [blame] | 40 | #include <asm/reset.h> |
Felix Beck | cb17a63 | 2008-12-25 13:38:41 +0100 | [diff] [blame] | 41 | #include <asm/airq.h> |
Arun Sharma | 60063497 | 2011-07-26 16:09:06 -0700 | [diff] [blame] | 42 | #include <linux/atomic.h> |
Felix Beck | cb17a63 | 2008-12-25 13:38:41 +0100 | [diff] [blame] | 43 | #include <asm/isc.h> |
Felix Beck | fe13723 | 2008-07-14 09:59:08 +0200 | [diff] [blame] | 44 | #include <linux/hrtimer.h> |
| 45 | #include <linux/ktime.h> |
David Howells | a0616cd | 2012-03-28 18:30:02 +0100 | [diff] [blame] | 46 | #include <asm/facility.h> |
Kees Cook | 5d26a10 | 2014-11-20 17:05:53 -0800 | [diff] [blame] | 47 | #include <linux/crypto.h> |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 48 | |
| 49 | #include "ap_bus.h" |
| 50 | |
| 51 | /* Some prototypes. */ |
Al Viro | 4927b3f | 2006-12-06 19:18:20 +0000 | [diff] [blame] | 52 | static void ap_scan_bus(struct work_struct *); |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 53 | static void ap_poll_all(unsigned long); |
Felix Beck | fe13723 | 2008-07-14 09:59:08 +0200 | [diff] [blame] | 54 | static enum hrtimer_restart ap_poll_timeout(struct hrtimer *); |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 55 | static int ap_poll_thread_start(void); |
| 56 | static void ap_poll_thread_stop(void); |
Ralph Wuerthner | af512ed0 | 2007-07-10 11:24:19 +0200 | [diff] [blame] | 57 | static void ap_request_timeout(unsigned long); |
Felix Beck | cb17a63 | 2008-12-25 13:38:41 +0100 | [diff] [blame] | 58 | static inline void ap_schedule_poll_timer(void); |
Felix Beck | 772f547 | 2009-06-22 12:08:16 +0200 | [diff] [blame] | 59 | static int __ap_poll_device(struct ap_device *ap_dev, unsigned long *flags); |
| 60 | static int ap_device_remove(struct device *dev); |
| 61 | static int ap_device_probe(struct device *dev); |
Martin Schwidefsky | f4eae94 | 2013-06-24 10:30:41 +0200 | [diff] [blame] | 62 | static void ap_interrupt_handler(struct airq_struct *airq); |
Felix Beck | 772f547 | 2009-06-22 12:08:16 +0200 | [diff] [blame] | 63 | static void ap_reset(struct ap_device *ap_dev); |
| 64 | static void ap_config_timeout(unsigned long ptr); |
Felix Beck | 5314af6 | 2009-09-22 22:58:51 +0200 | [diff] [blame] | 65 | static int ap_select_domain(void); |
Holger Dengler | 7501455 | 2012-08-28 16:41:50 +0200 | [diff] [blame] | 66 | static void ap_query_configuration(void); |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 67 | |
Felix Beck | 1749a81 | 2008-04-17 07:46:28 +0200 | [diff] [blame] | 68 | /* |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 69 | * Module description. |
| 70 | */ |
| 71 | MODULE_AUTHOR("IBM Corporation"); |
Holger Dengler | 7501455 | 2012-08-28 16:41:50 +0200 | [diff] [blame] | 72 | MODULE_DESCRIPTION("Adjunct Processor Bus driver, " \ |
| 73 | "Copyright IBM Corp. 2006, 2012"); |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 74 | MODULE_LICENSE("GPL"); |
Kees Cook | 5d26a10 | 2014-11-20 17:05:53 -0800 | [diff] [blame] | 75 | MODULE_ALIAS_CRYPTO("z90crypt"); |
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 | /* |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 78 | * Module parameter |
| 79 | */ |
| 80 | int ap_domain_index = -1; /* Adjunct Processor Domain Index */ |
Michael Veigel | c1a42f4 | 2014-04-14 14:28:27 +0200 | [diff] [blame] | 81 | module_param_named(domain, ap_domain_index, int, S_IRUSR|S_IRGRP); |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 82 | MODULE_PARM_DESC(domain, "domain index for ap devices"); |
| 83 | EXPORT_SYMBOL(ap_domain_index); |
| 84 | |
Felix Beck | b90b34c | 2008-02-09 18:24:30 +0100 | [diff] [blame] | 85 | static int ap_thread_flag = 0; |
Michael Veigel | c1a42f4 | 2014-04-14 14:28:27 +0200 | [diff] [blame] | 86 | module_param_named(poll_thread, ap_thread_flag, int, S_IRUSR|S_IRGRP); |
Felix Beck | b90b34c | 2008-02-09 18:24:30 +0100 | [diff] [blame] | 87 | 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] | 88 | |
| 89 | static struct device *ap_root_device = NULL; |
Holger Dengler | 7501455 | 2012-08-28 16:41:50 +0200 | [diff] [blame] | 90 | static struct ap_config_info *ap_configuration; |
Christian Maaser | 43c207e6 | 2008-12-25 13:38:42 +0100 | [diff] [blame] | 91 | static DEFINE_SPINLOCK(ap_device_list_lock); |
Ralph Wuerthner | cf352ce | 2007-03-19 13:19:14 +0100 | [diff] [blame] | 92 | static LIST_HEAD(ap_device_list); |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 93 | |
Felix Beck | 1749a81 | 2008-04-17 07:46:28 +0200 | [diff] [blame] | 94 | /* |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 95 | * Workqueue & timer for bus rescan. |
| 96 | */ |
| 97 | static struct workqueue_struct *ap_work_queue; |
| 98 | static struct timer_list ap_config_timer; |
| 99 | static int ap_config_time = AP_CONFIG_TIME; |
Al Viro | 4927b3f | 2006-12-06 19:18:20 +0000 | [diff] [blame] | 100 | static DECLARE_WORK(ap_config_work, ap_scan_bus); |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 101 | |
Felix Beck | 1749a81 | 2008-04-17 07:46:28 +0200 | [diff] [blame] | 102 | /* |
Felix Beck | cb17a63 | 2008-12-25 13:38:41 +0100 | [diff] [blame] | 103 | * Tasklet & timer for AP request polling and interrupts |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 104 | */ |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 105 | static DECLARE_TASKLET(ap_tasklet, ap_poll_all, 0); |
| 106 | static atomic_t ap_poll_requests = ATOMIC_INIT(0); |
| 107 | static DECLARE_WAIT_QUEUE_HEAD(ap_poll_wait); |
| 108 | static struct task_struct *ap_poll_kthread = NULL; |
| 109 | static DEFINE_MUTEX(ap_poll_thread_mutex); |
Felix Beck | 9352131 | 2009-12-07 12:52:00 +0100 | [diff] [blame] | 110 | static DEFINE_SPINLOCK(ap_poll_timer_lock); |
Felix Beck | fe13723 | 2008-07-14 09:59:08 +0200 | [diff] [blame] | 111 | static struct hrtimer ap_poll_timer; |
| 112 | /* In LPAR poll with 4kHz frequency. Poll every 250000 nanoseconds. |
| 113 | * If z/VM change to 1500000 nanoseconds to adjust to z/VM polling.*/ |
| 114 | static unsigned long long poll_timeout = 250000; |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 115 | |
Felix Beck | 772f547 | 2009-06-22 12:08:16 +0200 | [diff] [blame] | 116 | /* Suspend flag */ |
| 117 | static int ap_suspend_flag; |
Felix Beck | 5314af6 | 2009-09-22 22:58:51 +0200 | [diff] [blame] | 118 | /* Flag to check if domain was set through module parameter domain=. This is |
| 119 | * important when supsend and resume is done in a z/VM environment where the |
| 120 | * domain might change. */ |
| 121 | static int user_set_domain = 0; |
Felix Beck | 772f547 | 2009-06-22 12:08:16 +0200 | [diff] [blame] | 122 | static struct bus_type ap_bus_type; |
| 123 | |
Martin Schwidefsky | f4eae94 | 2013-06-24 10:30:41 +0200 | [diff] [blame] | 124 | /* Adapter interrupt definitions */ |
| 125 | static int ap_airq_flag; |
| 126 | |
| 127 | static struct airq_struct ap_airq = { |
| 128 | .handler = ap_interrupt_handler, |
| 129 | .isc = AP_ISC, |
| 130 | }; |
| 131 | |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 132 | /** |
Felix Beck | cb17a63 | 2008-12-25 13:38:41 +0100 | [diff] [blame] | 133 | * ap_using_interrupts() - Returns non-zero if interrupt support is |
| 134 | * available. |
| 135 | */ |
| 136 | static inline int ap_using_interrupts(void) |
| 137 | { |
Martin Schwidefsky | f4eae94 | 2013-06-24 10:30:41 +0200 | [diff] [blame] | 138 | return ap_airq_flag; |
Felix Beck | cb17a63 | 2008-12-25 13:38:41 +0100 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | /** |
Felix Beck | 1749a81 | 2008-04-17 07:46:28 +0200 | [diff] [blame] | 142 | * ap_intructions_available() - Test if AP instructions are available. |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 143 | * |
Felix Beck | 1749a81 | 2008-04-17 07:46:28 +0200 | [diff] [blame] | 144 | * Returns 0 if the AP instructions are installed. |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 145 | */ |
| 146 | static inline int ap_instructions_available(void) |
| 147 | { |
| 148 | register unsigned long reg0 asm ("0") = AP_MKQID(0,0); |
| 149 | register unsigned long reg1 asm ("1") = -ENODEV; |
| 150 | register unsigned long reg2 asm ("2") = 0UL; |
| 151 | |
| 152 | asm volatile( |
| 153 | " .long 0xb2af0000\n" /* PQAP(TAPQ) */ |
| 154 | "0: la %1,0\n" |
| 155 | "1:\n" |
| 156 | EX_TABLE(0b, 1b) |
| 157 | : "+d" (reg0), "+d" (reg1), "+d" (reg2) : : "cc" ); |
| 158 | return reg1; |
| 159 | } |
| 160 | |
| 161 | /** |
Felix Beck | cb17a63 | 2008-12-25 13:38:41 +0100 | [diff] [blame] | 162 | * ap_interrupts_available(): Test if AP interrupts are available. |
| 163 | * |
| 164 | * Returns 1 if AP interrupts are available. |
| 165 | */ |
| 166 | static int ap_interrupts_available(void) |
| 167 | { |
Felix Beck | 53ec24b1 | 2011-01-05 12:46:44 +0100 | [diff] [blame] | 168 | return test_facility(2) && test_facility(65); |
Felix Beck | cb17a63 | 2008-12-25 13:38:41 +0100 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | /** |
Holger Dengler | 7501455 | 2012-08-28 16:41:50 +0200 | [diff] [blame] | 172 | * ap_configuration_available(): Test if AP configuration |
| 173 | * information is available. |
| 174 | * |
| 175 | * Returns 1 if AP configuration information is available. |
| 176 | */ |
Heiko Carstens | c80773e | 2012-09-14 11:21:17 +0200 | [diff] [blame] | 177 | #ifdef CONFIG_64BIT |
Holger Dengler | 7501455 | 2012-08-28 16:41:50 +0200 | [diff] [blame] | 178 | static int ap_configuration_available(void) |
| 179 | { |
| 180 | return test_facility(2) && test_facility(12); |
| 181 | } |
Heiko Carstens | c80773e | 2012-09-14 11:21:17 +0200 | [diff] [blame] | 182 | #endif |
Holger Dengler | 7501455 | 2012-08-28 16:41:50 +0200 | [diff] [blame] | 183 | |
| 184 | /** |
Felix Beck | 1749a81 | 2008-04-17 07:46:28 +0200 | [diff] [blame] | 185 | * ap_test_queue(): Test adjunct processor queue. |
| 186 | * @qid: The AP queue number |
| 187 | * @queue_depth: Pointer to queue depth value |
| 188 | * @device_type: Pointer to device type value |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 189 | * |
Felix Beck | 1749a81 | 2008-04-17 07:46:28 +0200 | [diff] [blame] | 190 | * Returns AP queue status structure. |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 191 | */ |
| 192 | static inline struct ap_queue_status |
| 193 | ap_test_queue(ap_qid_t qid, int *queue_depth, int *device_type) |
| 194 | { |
| 195 | register unsigned long reg0 asm ("0") = qid; |
| 196 | register struct ap_queue_status reg1 asm ("1"); |
| 197 | register unsigned long reg2 asm ("2") = 0UL; |
| 198 | |
| 199 | asm volatile(".long 0xb2af0000" /* PQAP(TAPQ) */ |
| 200 | : "+d" (reg0), "=d" (reg1), "+d" (reg2) : : "cc"); |
| 201 | *device_type = (int) (reg2 >> 24); |
| 202 | *queue_depth = (int) (reg2 & 0xff); |
| 203 | return reg1; |
| 204 | } |
| 205 | |
| 206 | /** |
Ingo Tuchscherer | 5bc334b | 2015-01-23 13:27:04 +0100 | [diff] [blame] | 207 | * ap_query_facilities(): PQAP(TAPQ) query facilities. |
| 208 | * @qid: The AP queue number |
| 209 | * |
| 210 | * Returns content of general register 2 after the PQAP(TAPQ) |
| 211 | * instruction was called. |
| 212 | */ |
| 213 | static inline unsigned long ap_query_facilities(ap_qid_t qid) |
| 214 | { |
| 215 | register unsigned long reg0 asm ("0") = qid | 0x00800000UL; |
| 216 | register unsigned long reg1 asm ("1"); |
| 217 | register unsigned long reg2 asm ("2") = 0UL; |
| 218 | |
| 219 | asm volatile(".long 0xb2af0000" /* PQAP(TAPQ) */ |
| 220 | : "+d" (reg0), "=d" (reg1), "+d" (reg2) : : "cc"); |
| 221 | return reg2; |
| 222 | } |
| 223 | |
| 224 | /** |
Felix Beck | 1749a81 | 2008-04-17 07:46:28 +0200 | [diff] [blame] | 225 | * ap_reset_queue(): Reset adjunct processor queue. |
| 226 | * @qid: The AP queue number |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 227 | * |
Felix Beck | 1749a81 | 2008-04-17 07:46:28 +0200 | [diff] [blame] | 228 | * Returns AP queue status structure. |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 229 | */ |
| 230 | static inline struct ap_queue_status ap_reset_queue(ap_qid_t qid) |
| 231 | { |
| 232 | register unsigned long reg0 asm ("0") = qid | 0x01000000UL; |
| 233 | register struct ap_queue_status reg1 asm ("1"); |
| 234 | register unsigned long reg2 asm ("2") = 0UL; |
| 235 | |
| 236 | asm volatile( |
| 237 | ".long 0xb2af0000" /* PQAP(RAPQ) */ |
| 238 | : "+d" (reg0), "=d" (reg1), "+d" (reg2) : : "cc"); |
| 239 | return reg1; |
| 240 | } |
| 241 | |
Felix Beck | cb17a63 | 2008-12-25 13:38:41 +0100 | [diff] [blame] | 242 | #ifdef CONFIG_64BIT |
| 243 | /** |
| 244 | * ap_queue_interruption_control(): Enable interruption for a specific AP. |
| 245 | * @qid: The AP queue number |
| 246 | * @ind: The notification indicator byte |
| 247 | * |
| 248 | * Returns AP queue status. |
| 249 | */ |
| 250 | static inline struct ap_queue_status |
| 251 | ap_queue_interruption_control(ap_qid_t qid, void *ind) |
| 252 | { |
| 253 | register unsigned long reg0 asm ("0") = qid | 0x03000000UL; |
| 254 | register unsigned long reg1_in asm ("1") = 0x0000800000000000UL | AP_ISC; |
| 255 | register struct ap_queue_status reg1_out asm ("1"); |
| 256 | register void *reg2 asm ("2") = ind; |
| 257 | asm volatile( |
Holger Dengler | a7475af | 2012-05-16 14:10:26 +0200 | [diff] [blame] | 258 | ".long 0xb2af0000" /* PQAP(AQIC) */ |
Felix Beck | cb17a63 | 2008-12-25 13:38:41 +0100 | [diff] [blame] | 259 | : "+d" (reg0), "+d" (reg1_in), "=d" (reg1_out), "+d" (reg2) |
| 260 | : |
| 261 | : "cc" ); |
| 262 | return reg1_out; |
| 263 | } |
| 264 | #endif |
| 265 | |
Holger Dengler | 6bed05b | 2011-07-24 10:48:25 +0200 | [diff] [blame] | 266 | #ifdef CONFIG_64BIT |
| 267 | static inline struct ap_queue_status |
| 268 | __ap_query_functions(ap_qid_t qid, unsigned int *functions) |
Felix Beck | b1f933d | 2011-01-05 12:47:44 +0100 | [diff] [blame] | 269 | { |
| 270 | register unsigned long reg0 asm ("0") = 0UL | qid | (1UL << 23); |
Holger Dengler | 6bed05b | 2011-07-24 10:48:25 +0200 | [diff] [blame] | 271 | register struct ap_queue_status reg1 asm ("1") = AP_QUEUE_STATUS_INVALID; |
| 272 | register unsigned long reg2 asm ("2"); |
Felix Beck | b1f933d | 2011-01-05 12:47:44 +0100 | [diff] [blame] | 273 | |
| 274 | asm volatile( |
Holger Dengler | a7475af | 2012-05-16 14:10:26 +0200 | [diff] [blame] | 275 | ".long 0xb2af0000\n" /* PQAP(TAPQ) */ |
Holger Dengler | 6bed05b | 2011-07-24 10:48:25 +0200 | [diff] [blame] | 276 | "0:\n" |
| 277 | EX_TABLE(0b, 0b) |
| 278 | : "+d" (reg0), "+d" (reg1), "=d" (reg2) |
Felix Beck | b1f933d | 2011-01-05 12:47:44 +0100 | [diff] [blame] | 279 | : |
| 280 | : "cc"); |
| 281 | |
Holger Dengler | 6bed05b | 2011-07-24 10:48:25 +0200 | [diff] [blame] | 282 | *functions = (unsigned int)(reg2 >> 32); |
Felix Beck | b1f933d | 2011-01-05 12:47:44 +0100 | [diff] [blame] | 283 | return reg1; |
| 284 | } |
Holger Dengler | 6bed05b | 2011-07-24 10:48:25 +0200 | [diff] [blame] | 285 | #endif |
| 286 | |
Holger Dengler | 7501455 | 2012-08-28 16:41:50 +0200 | [diff] [blame] | 287 | #ifdef CONFIG_64BIT |
| 288 | static inline int __ap_query_configuration(struct ap_config_info *config) |
| 289 | { |
| 290 | register unsigned long reg0 asm ("0") = 0x04000000UL; |
| 291 | register unsigned long reg1 asm ("1") = -EINVAL; |
| 292 | register unsigned char *reg2 asm ("2") = (unsigned char *)config; |
| 293 | |
| 294 | asm volatile( |
| 295 | ".long 0xb2af0000\n" /* PQAP(QCI) */ |
| 296 | "0: la %1,0\n" |
| 297 | "1:\n" |
| 298 | EX_TABLE(0b, 1b) |
| 299 | : "+d" (reg0), "+d" (reg1), "+d" (reg2) |
| 300 | : |
| 301 | : "cc"); |
| 302 | |
| 303 | return reg1; |
| 304 | } |
| 305 | #endif |
| 306 | |
Holger Dengler | 6bed05b | 2011-07-24 10:48:25 +0200 | [diff] [blame] | 307 | /** |
| 308 | * ap_query_functions(): Query supported functions. |
| 309 | * @qid: The AP queue number |
| 310 | * @functions: Pointer to functions field. |
| 311 | * |
| 312 | * Returns |
| 313 | * 0 on success. |
| 314 | * -ENODEV if queue not valid. |
| 315 | * -EBUSY if device busy. |
| 316 | * -EINVAL if query function is not supported |
| 317 | */ |
| 318 | static int ap_query_functions(ap_qid_t qid, unsigned int *functions) |
| 319 | { |
| 320 | #ifdef CONFIG_64BIT |
| 321 | struct ap_queue_status status; |
| 322 | int i; |
| 323 | status = __ap_query_functions(qid, functions); |
| 324 | |
| 325 | for (i = 0; i < AP_MAX_RESET; i++) { |
| 326 | if (ap_queue_status_invalid_test(&status)) |
| 327 | return -ENODEV; |
| 328 | |
| 329 | switch (status.response_code) { |
| 330 | case AP_RESPONSE_NORMAL: |
| 331 | return 0; |
| 332 | case AP_RESPONSE_RESET_IN_PROGRESS: |
| 333 | case AP_RESPONSE_BUSY: |
| 334 | break; |
| 335 | case AP_RESPONSE_Q_NOT_AVAIL: |
| 336 | case AP_RESPONSE_DECONFIGURED: |
| 337 | case AP_RESPONSE_CHECKSTOPPED: |
| 338 | case AP_RESPONSE_INVALID_ADDRESS: |
| 339 | return -ENODEV; |
| 340 | case AP_RESPONSE_OTHERWISE_CHANGED: |
| 341 | break; |
| 342 | default: |
| 343 | break; |
| 344 | } |
| 345 | if (i < AP_MAX_RESET - 1) { |
| 346 | udelay(5); |
| 347 | status = __ap_query_functions(qid, functions); |
| 348 | } |
| 349 | } |
| 350 | return -EBUSY; |
| 351 | #else |
| 352 | return -EINVAL; |
| 353 | #endif |
| 354 | } |
Felix Beck | b1f933d | 2011-01-05 12:47:44 +0100 | [diff] [blame] | 355 | |
| 356 | /** |
Felix Beck | cb17a63 | 2008-12-25 13:38:41 +0100 | [diff] [blame] | 357 | * ap_queue_enable_interruption(): Enable interruption on an AP. |
| 358 | * @qid: The AP queue number |
| 359 | * @ind: the notification indicator byte |
| 360 | * |
| 361 | * Enables interruption on AP queue via ap_queue_interruption_control(). Based |
| 362 | * on the return value it waits a while and tests the AP queue if interrupts |
| 363 | * have been switched on using ap_test_queue(). |
| 364 | */ |
| 365 | static int ap_queue_enable_interruption(ap_qid_t qid, void *ind) |
| 366 | { |
| 367 | #ifdef CONFIG_64BIT |
| 368 | struct ap_queue_status status; |
| 369 | int t_depth, t_device_type, rc, i; |
| 370 | |
| 371 | rc = -EBUSY; |
| 372 | status = ap_queue_interruption_control(qid, ind); |
| 373 | |
| 374 | for (i = 0; i < AP_MAX_RESET; i++) { |
| 375 | switch (status.response_code) { |
| 376 | case AP_RESPONSE_NORMAL: |
| 377 | if (status.int_enabled) |
| 378 | return 0; |
| 379 | break; |
| 380 | case AP_RESPONSE_RESET_IN_PROGRESS: |
| 381 | case AP_RESPONSE_BUSY: |
Holger Dengler | 8738e07 | 2012-07-02 12:39:59 +0200 | [diff] [blame] | 382 | if (i < AP_MAX_RESET - 1) { |
| 383 | udelay(5); |
| 384 | status = ap_queue_interruption_control(qid, |
| 385 | ind); |
| 386 | continue; |
| 387 | } |
Felix Beck | cb17a63 | 2008-12-25 13:38:41 +0100 | [diff] [blame] | 388 | break; |
| 389 | case AP_RESPONSE_Q_NOT_AVAIL: |
| 390 | case AP_RESPONSE_DECONFIGURED: |
| 391 | case AP_RESPONSE_CHECKSTOPPED: |
| 392 | case AP_RESPONSE_INVALID_ADDRESS: |
| 393 | return -ENODEV; |
| 394 | case AP_RESPONSE_OTHERWISE_CHANGED: |
| 395 | if (status.int_enabled) |
| 396 | return 0; |
| 397 | break; |
| 398 | default: |
| 399 | break; |
| 400 | } |
| 401 | if (i < AP_MAX_RESET - 1) { |
| 402 | udelay(5); |
| 403 | status = ap_test_queue(qid, &t_depth, &t_device_type); |
| 404 | } |
| 405 | } |
| 406 | return rc; |
| 407 | #else |
| 408 | return -EINVAL; |
| 409 | #endif |
| 410 | } |
| 411 | |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 412 | /** |
Felix Beck | 1749a81 | 2008-04-17 07:46:28 +0200 | [diff] [blame] | 413 | * __ap_send(): Send message to adjunct processor queue. |
| 414 | * @qid: The AP queue number |
| 415 | * @psmid: The program supplied message identifier |
| 416 | * @msg: The message text |
| 417 | * @length: The message length |
Felix Beck | a6a5d73 | 2009-12-07 12:51:55 +0100 | [diff] [blame] | 418 | * @special: Special Bit |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 419 | * |
Felix Beck | 1749a81 | 2008-04-17 07:46:28 +0200 | [diff] [blame] | 420 | * Returns AP queue status structure. |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 421 | * Condition code 1 on NQAP can't happen because the L bit is 1. |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 422 | * Condition code 2 on NQAP also means the send is incomplete, |
| 423 | * because a segment boundary was reached. The NQAP is repeated. |
| 424 | */ |
| 425 | static inline struct ap_queue_status |
Felix Beck | a6a5d73 | 2009-12-07 12:51:55 +0100 | [diff] [blame] | 426 | __ap_send(ap_qid_t qid, unsigned long long psmid, void *msg, size_t length, |
| 427 | unsigned int special) |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 428 | { |
| 429 | typedef struct { char _[length]; } msgblock; |
| 430 | register unsigned long reg0 asm ("0") = qid | 0x40000000UL; |
| 431 | register struct ap_queue_status reg1 asm ("1"); |
| 432 | register unsigned long reg2 asm ("2") = (unsigned long) msg; |
| 433 | register unsigned long reg3 asm ("3") = (unsigned long) length; |
| 434 | register unsigned long reg4 asm ("4") = (unsigned int) (psmid >> 32); |
Heiko Carstens | 7d6c3b4 | 2013-09-07 11:07:22 +0200 | [diff] [blame] | 435 | register unsigned long reg5 asm ("5") = psmid & 0xffffffff; |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 436 | |
Felix Beck | a6a5d73 | 2009-12-07 12:51:55 +0100 | [diff] [blame] | 437 | if (special == 1) |
| 438 | reg0 |= 0x400000UL; |
| 439 | |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 440 | asm volatile ( |
Holger Dengler | a7475af | 2012-05-16 14:10:26 +0200 | [diff] [blame] | 441 | "0: .long 0xb2ad0042\n" /* NQAP */ |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 442 | " brc 2,0b" |
| 443 | : "+d" (reg0), "=d" (reg1), "+d" (reg2), "+d" (reg3) |
| 444 | : "d" (reg4), "d" (reg5), "m" (*(msgblock *) msg) |
| 445 | : "cc" ); |
| 446 | return reg1; |
| 447 | } |
| 448 | |
| 449 | int ap_send(ap_qid_t qid, unsigned long long psmid, void *msg, size_t length) |
| 450 | { |
| 451 | struct ap_queue_status status; |
| 452 | |
Felix Beck | a6a5d73 | 2009-12-07 12:51:55 +0100 | [diff] [blame] | 453 | status = __ap_send(qid, psmid, msg, length, 0); |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 454 | switch (status.response_code) { |
| 455 | case AP_RESPONSE_NORMAL: |
| 456 | return 0; |
| 457 | case AP_RESPONSE_Q_FULL: |
Ralph Wuerthner | af512ed0 | 2007-07-10 11:24:19 +0200 | [diff] [blame] | 458 | case AP_RESPONSE_RESET_IN_PROGRESS: |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 459 | return -EBUSY; |
Felix Beck | a6a5d73 | 2009-12-07 12:51:55 +0100 | [diff] [blame] | 460 | case AP_RESPONSE_REQ_FAC_NOT_INST: |
| 461 | return -EINVAL; |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 462 | default: /* Device is gone. */ |
| 463 | return -ENODEV; |
| 464 | } |
| 465 | } |
| 466 | EXPORT_SYMBOL(ap_send); |
| 467 | |
Felix Beck | 1749a81 | 2008-04-17 07:46:28 +0200 | [diff] [blame] | 468 | /** |
| 469 | * __ap_recv(): Receive message from adjunct processor queue. |
| 470 | * @qid: The AP queue number |
| 471 | * @psmid: Pointer to program supplied message identifier |
| 472 | * @msg: The message text |
| 473 | * @length: The message length |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 474 | * |
Felix Beck | 1749a81 | 2008-04-17 07:46:28 +0200 | [diff] [blame] | 475 | * Returns AP queue status structure. |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 476 | * Condition code 1 on DQAP means the receive has taken place |
| 477 | * but only partially. The response is incomplete, hence the |
| 478 | * DQAP is repeated. |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 479 | * Condition code 2 on DQAP also means the receive is incomplete, |
| 480 | * this time because a segment boundary was reached. Again, the |
| 481 | * DQAP is repeated. |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 482 | * Note that gpr2 is used by the DQAP instruction to keep track of |
| 483 | * any 'residual' length, in case the instruction gets interrupted. |
| 484 | * Hence it gets zeroed before the instruction. |
| 485 | */ |
| 486 | static inline struct ap_queue_status |
| 487 | __ap_recv(ap_qid_t qid, unsigned long long *psmid, void *msg, size_t length) |
| 488 | { |
| 489 | typedef struct { char _[length]; } msgblock; |
| 490 | register unsigned long reg0 asm("0") = qid | 0x80000000UL; |
| 491 | register struct ap_queue_status reg1 asm ("1"); |
| 492 | register unsigned long reg2 asm("2") = 0UL; |
| 493 | register unsigned long reg4 asm("4") = (unsigned long) msg; |
| 494 | register unsigned long reg5 asm("5") = (unsigned long) length; |
| 495 | register unsigned long reg6 asm("6") = 0UL; |
| 496 | register unsigned long reg7 asm("7") = 0UL; |
| 497 | |
| 498 | |
| 499 | asm volatile( |
Holger Dengler | a7475af | 2012-05-16 14:10:26 +0200 | [diff] [blame] | 500 | "0: .long 0xb2ae0064\n" /* DQAP */ |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 501 | " brc 6,0b\n" |
| 502 | : "+d" (reg0), "=d" (reg1), "+d" (reg2), |
| 503 | "+d" (reg4), "+d" (reg5), "+d" (reg6), "+d" (reg7), |
| 504 | "=m" (*(msgblock *) msg) : : "cc" ); |
| 505 | *psmid = (((unsigned long long) reg6) << 32) + reg7; |
| 506 | return reg1; |
| 507 | } |
| 508 | |
| 509 | int ap_recv(ap_qid_t qid, unsigned long long *psmid, void *msg, size_t length) |
| 510 | { |
| 511 | struct ap_queue_status status; |
| 512 | |
| 513 | status = __ap_recv(qid, psmid, msg, length); |
| 514 | switch (status.response_code) { |
| 515 | case AP_RESPONSE_NORMAL: |
| 516 | return 0; |
| 517 | case AP_RESPONSE_NO_PENDING_REPLY: |
| 518 | if (status.queue_empty) |
| 519 | return -ENOENT; |
| 520 | return -EBUSY; |
Ralph Wuerthner | af512ed0 | 2007-07-10 11:24:19 +0200 | [diff] [blame] | 521 | case AP_RESPONSE_RESET_IN_PROGRESS: |
| 522 | return -EBUSY; |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 523 | default: |
| 524 | return -ENODEV; |
| 525 | } |
| 526 | } |
| 527 | EXPORT_SYMBOL(ap_recv); |
| 528 | |
| 529 | /** |
Felix Beck | 1749a81 | 2008-04-17 07:46:28 +0200 | [diff] [blame] | 530 | * ap_query_queue(): Check if an AP queue is available. |
| 531 | * @qid: The AP queue number |
| 532 | * @queue_depth: Pointer to queue depth value |
| 533 | * @device_type: Pointer to device type value |
| 534 | * |
| 535 | * The test is repeated for AP_MAX_RESET times. |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 536 | */ |
| 537 | static int ap_query_queue(ap_qid_t qid, int *queue_depth, int *device_type) |
| 538 | { |
| 539 | struct ap_queue_status status; |
| 540 | int t_depth, t_device_type, rc, i; |
| 541 | |
| 542 | rc = -EBUSY; |
| 543 | for (i = 0; i < AP_MAX_RESET; i++) { |
| 544 | status = ap_test_queue(qid, &t_depth, &t_device_type); |
| 545 | switch (status.response_code) { |
| 546 | case AP_RESPONSE_NORMAL: |
| 547 | *queue_depth = t_depth + 1; |
| 548 | *device_type = t_device_type; |
| 549 | rc = 0; |
| 550 | break; |
| 551 | case AP_RESPONSE_Q_NOT_AVAIL: |
| 552 | rc = -ENODEV; |
| 553 | break; |
| 554 | case AP_RESPONSE_RESET_IN_PROGRESS: |
| 555 | break; |
| 556 | case AP_RESPONSE_DECONFIGURED: |
| 557 | rc = -ENODEV; |
| 558 | break; |
| 559 | case AP_RESPONSE_CHECKSTOPPED: |
| 560 | rc = -ENODEV; |
| 561 | break; |
Felix Beck | cb17a63 | 2008-12-25 13:38:41 +0100 | [diff] [blame] | 562 | case AP_RESPONSE_INVALID_ADDRESS: |
| 563 | rc = -ENODEV; |
| 564 | break; |
| 565 | case AP_RESPONSE_OTHERWISE_CHANGED: |
| 566 | break; |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 567 | case AP_RESPONSE_BUSY: |
| 568 | break; |
| 569 | default: |
| 570 | BUG(); |
| 571 | } |
| 572 | if (rc != -EBUSY) |
| 573 | break; |
| 574 | if (i < AP_MAX_RESET - 1) |
| 575 | udelay(5); |
| 576 | } |
| 577 | return rc; |
| 578 | } |
| 579 | |
| 580 | /** |
Felix Beck | 1749a81 | 2008-04-17 07:46:28 +0200 | [diff] [blame] | 581 | * ap_init_queue(): Reset an AP queue. |
| 582 | * @qid: The AP queue number |
| 583 | * |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 584 | * Reset an AP queue and wait for it to become available again. |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 585 | */ |
| 586 | static int ap_init_queue(ap_qid_t qid) |
| 587 | { |
| 588 | struct ap_queue_status status; |
| 589 | int rc, dummy, i; |
| 590 | |
| 591 | rc = -ENODEV; |
| 592 | status = ap_reset_queue(qid); |
| 593 | for (i = 0; i < AP_MAX_RESET; i++) { |
| 594 | switch (status.response_code) { |
| 595 | case AP_RESPONSE_NORMAL: |
| 596 | if (status.queue_empty) |
| 597 | rc = 0; |
| 598 | break; |
| 599 | case AP_RESPONSE_Q_NOT_AVAIL: |
| 600 | case AP_RESPONSE_DECONFIGURED: |
| 601 | case AP_RESPONSE_CHECKSTOPPED: |
| 602 | i = AP_MAX_RESET; /* return with -ENODEV */ |
| 603 | break; |
| 604 | case AP_RESPONSE_RESET_IN_PROGRESS: |
Ralph Wuerthner | af512ed0 | 2007-07-10 11:24:19 +0200 | [diff] [blame] | 605 | rc = -EBUSY; |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 606 | case AP_RESPONSE_BUSY: |
| 607 | default: |
| 608 | break; |
| 609 | } |
Ralph Wuerthner | af512ed0 | 2007-07-10 11:24:19 +0200 | [diff] [blame] | 610 | if (rc != -ENODEV && rc != -EBUSY) |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 611 | break; |
| 612 | if (i < AP_MAX_RESET - 1) { |
Ingo Tuchscherer | 91f3e3e | 2013-11-20 10:47:13 +0100 | [diff] [blame] | 613 | /* Time we are waiting until we give up (0.7sec * 90). |
| 614 | * Since the actual request (in progress) will not |
| 615 | * interrupted immediately for the reset command, |
| 616 | * we have to be patient. In worst case we have to |
| 617 | * wait 60sec + reset time (some msec). |
| 618 | */ |
| 619 | schedule_timeout(AP_RESET_TIMEOUT); |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 620 | status = ap_test_queue(qid, &dummy, &dummy); |
| 621 | } |
| 622 | } |
Felix Beck | cb17a63 | 2008-12-25 13:38:41 +0100 | [diff] [blame] | 623 | if (rc == 0 && ap_using_interrupts()) { |
Martin Schwidefsky | f4eae94 | 2013-06-24 10:30:41 +0200 | [diff] [blame] | 624 | rc = ap_queue_enable_interruption(qid, ap_airq.lsi_ptr); |
Felix Beck | cb17a63 | 2008-12-25 13:38:41 +0100 | [diff] [blame] | 625 | /* If interruption mode is supported by the machine, |
| 626 | * but an AP can not be enabled for interruption then |
| 627 | * the AP will be discarded. */ |
| 628 | if (rc) |
| 629 | pr_err("Registering adapter interrupts for " |
| 630 | "AP %d failed\n", AP_QID_DEVICE(qid)); |
| 631 | } |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 632 | return rc; |
| 633 | } |
| 634 | |
| 635 | /** |
Felix Beck | 1749a81 | 2008-04-17 07:46:28 +0200 | [diff] [blame] | 636 | * ap_increase_queue_count(): Arm request timeout. |
| 637 | * @ap_dev: Pointer to an AP device. |
| 638 | * |
| 639 | * Arm request timeout if an AP device was idle and a new request is submitted. |
Ralph Wuerthner | af512ed0 | 2007-07-10 11:24:19 +0200 | [diff] [blame] | 640 | */ |
| 641 | static void ap_increase_queue_count(struct ap_device *ap_dev) |
| 642 | { |
| 643 | int timeout = ap_dev->drv->request_timeout; |
| 644 | |
| 645 | ap_dev->queue_count++; |
| 646 | if (ap_dev->queue_count == 1) { |
| 647 | mod_timer(&ap_dev->timeout, jiffies + timeout); |
| 648 | ap_dev->reset = AP_RESET_ARMED; |
| 649 | } |
| 650 | } |
| 651 | |
| 652 | /** |
Felix Beck | 1749a81 | 2008-04-17 07:46:28 +0200 | [diff] [blame] | 653 | * ap_decrease_queue_count(): Decrease queue count. |
| 654 | * @ap_dev: Pointer to an AP device. |
| 655 | * |
| 656 | * If AP device is still alive, re-schedule request timeout if there are still |
Ralph Wuerthner | af512ed0 | 2007-07-10 11:24:19 +0200 | [diff] [blame] | 657 | * pending requests. |
| 658 | */ |
| 659 | static void ap_decrease_queue_count(struct ap_device *ap_dev) |
| 660 | { |
| 661 | int timeout = ap_dev->drv->request_timeout; |
| 662 | |
| 663 | ap_dev->queue_count--; |
| 664 | if (ap_dev->queue_count > 0) |
| 665 | mod_timer(&ap_dev->timeout, jiffies + timeout); |
| 666 | else |
Felix Beck | 1749a81 | 2008-04-17 07:46:28 +0200 | [diff] [blame] | 667 | /* |
Ralph Wuerthner | af512ed0 | 2007-07-10 11:24:19 +0200 | [diff] [blame] | 668 | * The timeout timer should to be disabled now - since |
| 669 | * del_timer_sync() is very expensive, we just tell via the |
| 670 | * reset flag to ignore the pending timeout timer. |
| 671 | */ |
| 672 | ap_dev->reset = AP_RESET_IGNORE; |
| 673 | } |
| 674 | |
Felix Beck | 1749a81 | 2008-04-17 07:46:28 +0200 | [diff] [blame] | 675 | /* |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 676 | * AP device related attributes. |
| 677 | */ |
| 678 | static ssize_t ap_hwtype_show(struct device *dev, |
| 679 | struct device_attribute *attr, char *buf) |
| 680 | { |
| 681 | struct ap_device *ap_dev = to_ap_dev(dev); |
| 682 | return snprintf(buf, PAGE_SIZE, "%d\n", ap_dev->device_type); |
| 683 | } |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 684 | |
Christian Maaser | 43c207e6 | 2008-12-25 13:38:42 +0100 | [diff] [blame] | 685 | static DEVICE_ATTR(hwtype, 0444, ap_hwtype_show, NULL); |
Ingo Tuchscherer | 42f4dd61 | 2014-10-02 14:48:46 +0200 | [diff] [blame] | 686 | |
| 687 | static ssize_t ap_raw_hwtype_show(struct device *dev, |
| 688 | struct device_attribute *attr, char *buf) |
| 689 | { |
| 690 | struct ap_device *ap_dev = to_ap_dev(dev); |
| 691 | |
| 692 | return snprintf(buf, PAGE_SIZE, "%d\n", ap_dev->raw_hwtype); |
| 693 | } |
| 694 | |
| 695 | static DEVICE_ATTR(raw_hwtype, 0444, ap_raw_hwtype_show, NULL); |
| 696 | |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 697 | static ssize_t ap_depth_show(struct device *dev, struct device_attribute *attr, |
| 698 | char *buf) |
| 699 | { |
| 700 | struct ap_device *ap_dev = to_ap_dev(dev); |
| 701 | return snprintf(buf, PAGE_SIZE, "%d\n", ap_dev->queue_depth); |
| 702 | } |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 703 | |
Christian Maaser | 43c207e6 | 2008-12-25 13:38:42 +0100 | [diff] [blame] | 704 | static DEVICE_ATTR(depth, 0444, ap_depth_show, NULL); |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 705 | static ssize_t ap_request_count_show(struct device *dev, |
| 706 | struct device_attribute *attr, |
| 707 | char *buf) |
| 708 | { |
| 709 | struct ap_device *ap_dev = to_ap_dev(dev); |
| 710 | int rc; |
| 711 | |
| 712 | spin_lock_bh(&ap_dev->lock); |
| 713 | rc = snprintf(buf, PAGE_SIZE, "%d\n", ap_dev->total_request_count); |
| 714 | spin_unlock_bh(&ap_dev->lock); |
| 715 | return rc; |
| 716 | } |
| 717 | |
| 718 | static DEVICE_ATTR(request_count, 0444, ap_request_count_show, NULL); |
| 719 | |
Holger Dengler | b26bd94 | 2012-08-28 16:43:48 +0200 | [diff] [blame] | 720 | static ssize_t ap_requestq_count_show(struct device *dev, |
| 721 | struct device_attribute *attr, char *buf) |
| 722 | { |
| 723 | struct ap_device *ap_dev = to_ap_dev(dev); |
| 724 | int rc; |
| 725 | |
| 726 | spin_lock_bh(&ap_dev->lock); |
| 727 | rc = snprintf(buf, PAGE_SIZE, "%d\n", ap_dev->requestq_count); |
| 728 | spin_unlock_bh(&ap_dev->lock); |
| 729 | return rc; |
| 730 | } |
| 731 | |
| 732 | static DEVICE_ATTR(requestq_count, 0444, ap_requestq_count_show, NULL); |
| 733 | |
| 734 | static ssize_t ap_pendingq_count_show(struct device *dev, |
| 735 | struct device_attribute *attr, char *buf) |
| 736 | { |
| 737 | struct ap_device *ap_dev = to_ap_dev(dev); |
| 738 | int rc; |
| 739 | |
| 740 | spin_lock_bh(&ap_dev->lock); |
| 741 | rc = snprintf(buf, PAGE_SIZE, "%d\n", ap_dev->pendingq_count); |
| 742 | spin_unlock_bh(&ap_dev->lock); |
| 743 | return rc; |
| 744 | } |
| 745 | |
| 746 | static DEVICE_ATTR(pendingq_count, 0444, ap_pendingq_count_show, NULL); |
| 747 | |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 748 | static ssize_t ap_modalias_show(struct device *dev, |
| 749 | struct device_attribute *attr, char *buf) |
| 750 | { |
| 751 | return sprintf(buf, "ap:t%02X", to_ap_dev(dev)->device_type); |
| 752 | } |
| 753 | |
| 754 | static DEVICE_ATTR(modalias, 0444, ap_modalias_show, NULL); |
| 755 | |
Holger Dengler | b26bd94 | 2012-08-28 16:43:48 +0200 | [diff] [blame] | 756 | static ssize_t ap_functions_show(struct device *dev, |
| 757 | struct device_attribute *attr, char *buf) |
| 758 | { |
| 759 | struct ap_device *ap_dev = to_ap_dev(dev); |
| 760 | return snprintf(buf, PAGE_SIZE, "0x%08X\n", ap_dev->functions); |
| 761 | } |
| 762 | |
| 763 | static DEVICE_ATTR(ap_functions, 0444, ap_functions_show, NULL); |
| 764 | |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 765 | static struct attribute *ap_dev_attrs[] = { |
| 766 | &dev_attr_hwtype.attr, |
Ingo Tuchscherer | 42f4dd61 | 2014-10-02 14:48:46 +0200 | [diff] [blame] | 767 | &dev_attr_raw_hwtype.attr, |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 768 | &dev_attr_depth.attr, |
| 769 | &dev_attr_request_count.attr, |
Holger Dengler | b26bd94 | 2012-08-28 16:43:48 +0200 | [diff] [blame] | 770 | &dev_attr_requestq_count.attr, |
| 771 | &dev_attr_pendingq_count.attr, |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 772 | &dev_attr_modalias.attr, |
Holger Dengler | b26bd94 | 2012-08-28 16:43:48 +0200 | [diff] [blame] | 773 | &dev_attr_ap_functions.attr, |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 774 | NULL |
| 775 | }; |
| 776 | static struct attribute_group ap_dev_attr_group = { |
| 777 | .attrs = ap_dev_attrs |
| 778 | }; |
| 779 | |
| 780 | /** |
Felix Beck | 1749a81 | 2008-04-17 07:46:28 +0200 | [diff] [blame] | 781 | * ap_bus_match() |
| 782 | * @dev: Pointer to device |
| 783 | * @drv: Pointer to device_driver |
| 784 | * |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 785 | * AP bus driver registration/unregistration. |
| 786 | */ |
| 787 | static int ap_bus_match(struct device *dev, struct device_driver *drv) |
| 788 | { |
| 789 | struct ap_device *ap_dev = to_ap_dev(dev); |
| 790 | struct ap_driver *ap_drv = to_ap_drv(drv); |
| 791 | struct ap_device_id *id; |
| 792 | |
Felix Beck | 1749a81 | 2008-04-17 07:46:28 +0200 | [diff] [blame] | 793 | /* |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 794 | * Compare device type of the device with the list of |
| 795 | * supported types of the device_driver. |
| 796 | */ |
| 797 | for (id = ap_drv->ids; id->match_flags; id++) { |
| 798 | if ((id->match_flags & AP_DEVICE_ID_MATCH_DEVICE_TYPE) && |
| 799 | (id->dev_type != ap_dev->device_type)) |
| 800 | continue; |
| 801 | return 1; |
| 802 | } |
| 803 | return 0; |
| 804 | } |
| 805 | |
| 806 | /** |
Felix Beck | 1749a81 | 2008-04-17 07:46:28 +0200 | [diff] [blame] | 807 | * ap_uevent(): Uevent function for AP devices. |
| 808 | * @dev: Pointer to device |
| 809 | * @env: Pointer to kobj_uevent_env |
| 810 | * |
| 811 | * It sets up a single environment variable DEV_TYPE which contains the |
| 812 | * hardware device type. |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 813 | */ |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 814 | static int ap_uevent (struct device *dev, struct kobj_uevent_env *env) |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 815 | { |
| 816 | struct ap_device *ap_dev = to_ap_dev(dev); |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 817 | int retval = 0; |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 818 | |
| 819 | if (!ap_dev) |
| 820 | return -ENODEV; |
| 821 | |
| 822 | /* Set up DEV_TYPE environment variable. */ |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 823 | retval = add_uevent_var(env, "DEV_TYPE=%04X", ap_dev->device_type); |
Eric Rannaud | bf62456 | 2007-03-30 22:23:12 -0700 | [diff] [blame] | 824 | if (retval) |
| 825 | return retval; |
| 826 | |
Cornelia Huck | 66a4263b | 2006-12-04 15:40:10 +0100 | [diff] [blame] | 827 | /* Add MODALIAS= */ |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 828 | 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] | 829 | |
Eric Rannaud | bf62456 | 2007-03-30 22:23:12 -0700 | [diff] [blame] | 830 | return retval; |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 831 | } |
| 832 | |
Felix Beck | 772f547 | 2009-06-22 12:08:16 +0200 | [diff] [blame] | 833 | static int ap_bus_suspend(struct device *dev, pm_message_t state) |
| 834 | { |
| 835 | struct ap_device *ap_dev = to_ap_dev(dev); |
| 836 | unsigned long flags; |
| 837 | |
| 838 | if (!ap_suspend_flag) { |
| 839 | ap_suspend_flag = 1; |
| 840 | |
| 841 | /* Disable scanning for devices, thus we do not want to scan |
| 842 | * for them after removing. |
| 843 | */ |
| 844 | del_timer_sync(&ap_config_timer); |
| 845 | if (ap_work_queue != NULL) { |
| 846 | destroy_workqueue(ap_work_queue); |
| 847 | ap_work_queue = NULL; |
| 848 | } |
Felix Beck | 5314af6 | 2009-09-22 22:58:51 +0200 | [diff] [blame] | 849 | |
Felix Beck | 772f547 | 2009-06-22 12:08:16 +0200 | [diff] [blame] | 850 | tasklet_disable(&ap_tasklet); |
| 851 | } |
| 852 | /* Poll on the device until all requests are finished. */ |
| 853 | do { |
| 854 | flags = 0; |
Felix Beck | 95f1556 | 2009-09-11 10:28:51 +0200 | [diff] [blame] | 855 | spin_lock_bh(&ap_dev->lock); |
Felix Beck | 772f547 | 2009-06-22 12:08:16 +0200 | [diff] [blame] | 856 | __ap_poll_device(ap_dev, &flags); |
Felix Beck | 95f1556 | 2009-09-11 10:28:51 +0200 | [diff] [blame] | 857 | spin_unlock_bh(&ap_dev->lock); |
Felix Beck | 772f547 | 2009-06-22 12:08:16 +0200 | [diff] [blame] | 858 | } while ((flags & 1) || (flags & 2)); |
| 859 | |
Felix Beck | 5314af6 | 2009-09-22 22:58:51 +0200 | [diff] [blame] | 860 | spin_lock_bh(&ap_dev->lock); |
| 861 | ap_dev->unregistered = 1; |
| 862 | spin_unlock_bh(&ap_dev->lock); |
| 863 | |
Felix Beck | 772f547 | 2009-06-22 12:08:16 +0200 | [diff] [blame] | 864 | return 0; |
| 865 | } |
| 866 | |
| 867 | static int ap_bus_resume(struct device *dev) |
| 868 | { |
Felix Beck | 772f547 | 2009-06-22 12:08:16 +0200 | [diff] [blame] | 869 | struct ap_device *ap_dev = to_ap_dev(dev); |
Martin Schwidefsky | f4eae94 | 2013-06-24 10:30:41 +0200 | [diff] [blame] | 870 | int rc; |
Felix Beck | 772f547 | 2009-06-22 12:08:16 +0200 | [diff] [blame] | 871 | |
| 872 | if (ap_suspend_flag) { |
| 873 | ap_suspend_flag = 0; |
Martin Schwidefsky | f4eae94 | 2013-06-24 10:30:41 +0200 | [diff] [blame] | 874 | if (ap_interrupts_available()) { |
| 875 | if (!ap_using_interrupts()) { |
| 876 | rc = register_adapter_interrupt(&ap_airq); |
| 877 | ap_airq_flag = (rc == 0); |
| 878 | } |
| 879 | } else { |
| 880 | if (ap_using_interrupts()) { |
| 881 | unregister_adapter_interrupt(&ap_airq); |
| 882 | ap_airq_flag = 0; |
| 883 | } |
| 884 | } |
Holger Dengler | 7501455 | 2012-08-28 16:41:50 +0200 | [diff] [blame] | 885 | ap_query_configuration(); |
Felix Beck | 5314af6 | 2009-09-22 22:58:51 +0200 | [diff] [blame] | 886 | if (!user_set_domain) { |
| 887 | ap_domain_index = -1; |
| 888 | ap_select_domain(); |
| 889 | } |
Felix Beck | 772f547 | 2009-06-22 12:08:16 +0200 | [diff] [blame] | 890 | init_timer(&ap_config_timer); |
| 891 | ap_config_timer.function = ap_config_timeout; |
| 892 | ap_config_timer.data = 0; |
| 893 | ap_config_timer.expires = jiffies + ap_config_time * HZ; |
| 894 | add_timer(&ap_config_timer); |
| 895 | ap_work_queue = create_singlethread_workqueue("kapwork"); |
| 896 | if (!ap_work_queue) |
| 897 | return -ENOMEM; |
| 898 | tasklet_enable(&ap_tasklet); |
| 899 | if (!ap_using_interrupts()) |
| 900 | ap_schedule_poll_timer(); |
| 901 | else |
| 902 | tasklet_schedule(&ap_tasklet); |
| 903 | if (ap_thread_flag) |
| 904 | rc = ap_poll_thread_start(); |
Martin Schwidefsky | f4eae94 | 2013-06-24 10:30:41 +0200 | [diff] [blame] | 905 | else |
| 906 | rc = 0; |
| 907 | } else |
| 908 | rc = 0; |
Felix Beck | 5314af6 | 2009-09-22 22:58:51 +0200 | [diff] [blame] | 909 | if (AP_QID_QUEUE(ap_dev->qid) != ap_domain_index) { |
| 910 | spin_lock_bh(&ap_dev->lock); |
| 911 | ap_dev->qid = AP_MKQID(AP_QID_DEVICE(ap_dev->qid), |
| 912 | ap_domain_index); |
| 913 | spin_unlock_bh(&ap_dev->lock); |
| 914 | } |
| 915 | queue_work(ap_work_queue, &ap_config_work); |
Felix Beck | 772f547 | 2009-06-22 12:08:16 +0200 | [diff] [blame] | 916 | |
| 917 | return rc; |
| 918 | } |
| 919 | |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 920 | static struct bus_type ap_bus_type = { |
| 921 | .name = "ap", |
| 922 | .match = &ap_bus_match, |
| 923 | .uevent = &ap_uevent, |
Felix Beck | 772f547 | 2009-06-22 12:08:16 +0200 | [diff] [blame] | 924 | .suspend = ap_bus_suspend, |
| 925 | .resume = ap_bus_resume |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 926 | }; |
| 927 | |
| 928 | static int ap_device_probe(struct device *dev) |
| 929 | { |
| 930 | struct ap_device *ap_dev = to_ap_dev(dev); |
| 931 | struct ap_driver *ap_drv = to_ap_drv(dev->driver); |
| 932 | int rc; |
| 933 | |
| 934 | ap_dev->drv = ap_drv; |
Ingo Tuchscherer | 666e68e | 2014-07-14 19:11:48 +0200 | [diff] [blame] | 935 | |
| 936 | spin_lock_bh(&ap_device_list_lock); |
| 937 | list_add(&ap_dev->list, &ap_device_list); |
| 938 | spin_unlock_bh(&ap_device_list_lock); |
| 939 | |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 940 | rc = ap_drv->probe ? ap_drv->probe(ap_dev) : -ENODEV; |
Ingo Tuchscherer | 666e68e | 2014-07-14 19:11:48 +0200 | [diff] [blame] | 941 | if (rc) { |
Christian Maaser | 43c207e6 | 2008-12-25 13:38:42 +0100 | [diff] [blame] | 942 | spin_lock_bh(&ap_device_list_lock); |
Ingo Tuchscherer | 666e68e | 2014-07-14 19:11:48 +0200 | [diff] [blame] | 943 | list_del_init(&ap_dev->list); |
Christian Maaser | 43c207e6 | 2008-12-25 13:38:42 +0100 | [diff] [blame] | 944 | spin_unlock_bh(&ap_device_list_lock); |
Ralph Wuerthner | faa582c | 2008-03-05 12:37:13 +0100 | [diff] [blame] | 945 | } |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 946 | return rc; |
| 947 | } |
| 948 | |
| 949 | /** |
Felix Beck | 1749a81 | 2008-04-17 07:46:28 +0200 | [diff] [blame] | 950 | * __ap_flush_queue(): Flush requests. |
| 951 | * @ap_dev: Pointer to the AP device |
| 952 | * |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 953 | * Flush all requests from the request/pending queue of an AP device. |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 954 | */ |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 955 | static void __ap_flush_queue(struct ap_device *ap_dev) |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 956 | { |
| 957 | struct ap_message *ap_msg, *next; |
| 958 | |
| 959 | list_for_each_entry_safe(ap_msg, next, &ap_dev->pendingq, list) { |
| 960 | list_del_init(&ap_msg->list); |
| 961 | ap_dev->pendingq_count--; |
Holger Dengler | 54a8f56 | 2012-05-16 14:08:22 +0200 | [diff] [blame] | 962 | ap_msg->receive(ap_dev, ap_msg, ERR_PTR(-ENODEV)); |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 963 | } |
| 964 | list_for_each_entry_safe(ap_msg, next, &ap_dev->requestq, list) { |
| 965 | list_del_init(&ap_msg->list); |
| 966 | ap_dev->requestq_count--; |
Holger Dengler | 54a8f56 | 2012-05-16 14:08:22 +0200 | [diff] [blame] | 967 | ap_msg->receive(ap_dev, ap_msg, ERR_PTR(-ENODEV)); |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 968 | } |
| 969 | } |
| 970 | |
| 971 | void ap_flush_queue(struct ap_device *ap_dev) |
| 972 | { |
| 973 | spin_lock_bh(&ap_dev->lock); |
| 974 | __ap_flush_queue(ap_dev); |
| 975 | spin_unlock_bh(&ap_dev->lock); |
| 976 | } |
| 977 | EXPORT_SYMBOL(ap_flush_queue); |
| 978 | |
| 979 | static int ap_device_remove(struct device *dev) |
| 980 | { |
| 981 | struct ap_device *ap_dev = to_ap_dev(dev); |
| 982 | struct ap_driver *ap_drv = ap_dev->drv; |
| 983 | |
Ralph Wuerthner | 4e56296 | 2006-10-04 20:02:05 +0200 | [diff] [blame] | 984 | ap_flush_queue(ap_dev); |
Ralph Wuerthner | af512ed0 | 2007-07-10 11:24:19 +0200 | [diff] [blame] | 985 | del_timer_sync(&ap_dev->timeout); |
Christian Maaser | 43c207e6 | 2008-12-25 13:38:42 +0100 | [diff] [blame] | 986 | spin_lock_bh(&ap_device_list_lock); |
Ralph Wuerthner | cf352ce | 2007-03-19 13:19:14 +0100 | [diff] [blame] | 987 | list_del_init(&ap_dev->list); |
Christian Maaser | 43c207e6 | 2008-12-25 13:38:42 +0100 | [diff] [blame] | 988 | spin_unlock_bh(&ap_device_list_lock); |
Ralph Wuerthner | faa582c | 2008-03-05 12:37:13 +0100 | [diff] [blame] | 989 | if (ap_drv->remove) |
| 990 | ap_drv->remove(ap_dev); |
Ralph Wuerthner | e675c0d | 2007-03-26 20:42:43 +0200 | [diff] [blame] | 991 | spin_lock_bh(&ap_dev->lock); |
| 992 | atomic_sub(ap_dev->queue_count, &ap_poll_requests); |
| 993 | spin_unlock_bh(&ap_dev->lock); |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 994 | return 0; |
| 995 | } |
| 996 | |
| 997 | int ap_driver_register(struct ap_driver *ap_drv, struct module *owner, |
| 998 | char *name) |
| 999 | { |
| 1000 | struct device_driver *drv = &ap_drv->driver; |
| 1001 | |
| 1002 | drv->bus = &ap_bus_type; |
| 1003 | drv->probe = ap_device_probe; |
| 1004 | drv->remove = ap_device_remove; |
| 1005 | drv->owner = owner; |
| 1006 | drv->name = name; |
| 1007 | return driver_register(drv); |
| 1008 | } |
| 1009 | EXPORT_SYMBOL(ap_driver_register); |
| 1010 | |
| 1011 | void ap_driver_unregister(struct ap_driver *ap_drv) |
| 1012 | { |
| 1013 | driver_unregister(&ap_drv->driver); |
| 1014 | } |
| 1015 | EXPORT_SYMBOL(ap_driver_unregister); |
| 1016 | |
Holger Dengler | dabecb2 | 2012-09-10 21:34:26 +0200 | [diff] [blame] | 1017 | void ap_bus_force_rescan(void) |
| 1018 | { |
Ingo Tuchscherer | 56bbe68 | 2013-04-12 17:52:08 +0200 | [diff] [blame] | 1019 | /* reconfigure the AP bus rescan timer. */ |
| 1020 | mod_timer(&ap_config_timer, jiffies + ap_config_time * HZ); |
| 1021 | /* processing a asynchronous bus rescan */ |
| 1022 | queue_work(ap_work_queue, &ap_config_work); |
| 1023 | flush_work(&ap_config_work); |
Holger Dengler | dabecb2 | 2012-09-10 21:34:26 +0200 | [diff] [blame] | 1024 | } |
| 1025 | EXPORT_SYMBOL(ap_bus_force_rescan); |
| 1026 | |
Felix Beck | 1749a81 | 2008-04-17 07:46:28 +0200 | [diff] [blame] | 1027 | /* |
Ingo Tuchscherer | 5bc334b | 2015-01-23 13:27:04 +0100 | [diff] [blame] | 1028 | * ap_test_config(): helper function to extract the nrth bit |
| 1029 | * within the unsigned int array field. |
| 1030 | */ |
| 1031 | static inline int ap_test_config(unsigned int *field, unsigned int nr) |
| 1032 | { |
| 1033 | if (nr > 0xFFu) |
| 1034 | return 0; |
| 1035 | return ap_test_bit((field + (nr >> 5)), (nr & 0x1f)); |
| 1036 | } |
| 1037 | |
| 1038 | /* |
| 1039 | * ap_test_config_card_id(): Test, whether an AP card ID is configured. |
| 1040 | * @id AP card ID |
| 1041 | * |
| 1042 | * Returns 0 if the card is not configured |
| 1043 | * 1 if the card is configured or |
| 1044 | * if the configuration information is not available |
| 1045 | */ |
| 1046 | static inline int ap_test_config_card_id(unsigned int id) |
| 1047 | { |
| 1048 | if (!ap_configuration) |
| 1049 | return 1; |
| 1050 | return ap_test_config(ap_configuration->apm, id); |
| 1051 | } |
| 1052 | |
| 1053 | /* |
| 1054 | * ap_test_config_domain(): Test, whether an AP usage domain is configured. |
| 1055 | * @domain AP usage domain ID |
| 1056 | * |
| 1057 | * Returns 0 if the usage domain is not configured |
| 1058 | * 1 if the usage domain is configured or |
| 1059 | * if the configuration information is not available |
| 1060 | */ |
| 1061 | static inline int ap_test_config_domain(unsigned int domain) |
| 1062 | { |
Ingo Tuchscherer | ea96f78 | 2015-02-02 17:50:17 +0100 | [diff] [blame] | 1063 | if (!ap_configuration) /* QCI not supported */ |
| 1064 | if (domain < 16) |
| 1065 | return 1; /* then domains 0...15 are configured */ |
| 1066 | else |
| 1067 | return 0; |
| 1068 | else |
| 1069 | return ap_test_config(ap_configuration->aqm, domain); |
Ingo Tuchscherer | 5bc334b | 2015-01-23 13:27:04 +0100 | [diff] [blame] | 1070 | } |
| 1071 | |
| 1072 | /* |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1073 | * AP bus attributes. |
| 1074 | */ |
| 1075 | static ssize_t ap_domain_show(struct bus_type *bus, char *buf) |
| 1076 | { |
| 1077 | return snprintf(buf, PAGE_SIZE, "%d\n", ap_domain_index); |
| 1078 | } |
| 1079 | |
| 1080 | static BUS_ATTR(ap_domain, 0444, ap_domain_show, NULL); |
| 1081 | |
Ingo Tuchscherer | 91f3e3e | 2013-11-20 10:47:13 +0100 | [diff] [blame] | 1082 | static ssize_t ap_control_domain_mask_show(struct bus_type *bus, char *buf) |
| 1083 | { |
| 1084 | if (ap_configuration != NULL) { /* QCI not supported */ |
| 1085 | if (test_facility(76)) { /* format 1 - 256 bit domain field */ |
| 1086 | return snprintf(buf, PAGE_SIZE, |
| 1087 | "0x%08x%08x%08x%08x%08x%08x%08x%08x\n", |
| 1088 | ap_configuration->adm[0], ap_configuration->adm[1], |
| 1089 | ap_configuration->adm[2], ap_configuration->adm[3], |
| 1090 | ap_configuration->adm[4], ap_configuration->adm[5], |
| 1091 | ap_configuration->adm[6], ap_configuration->adm[7]); |
| 1092 | } else { /* format 0 - 16 bit domain field */ |
| 1093 | return snprintf(buf, PAGE_SIZE, "%08x%08x\n", |
| 1094 | ap_configuration->adm[0], ap_configuration->adm[1]); |
| 1095 | } |
| 1096 | } else { |
| 1097 | return snprintf(buf, PAGE_SIZE, "not supported\n"); |
| 1098 | } |
| 1099 | } |
| 1100 | |
| 1101 | static BUS_ATTR(ap_control_domain_mask, 0444, |
| 1102 | ap_control_domain_mask_show, NULL); |
| 1103 | |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1104 | static ssize_t ap_config_time_show(struct bus_type *bus, char *buf) |
| 1105 | { |
| 1106 | return snprintf(buf, PAGE_SIZE, "%d\n", ap_config_time); |
| 1107 | } |
| 1108 | |
Felix Beck | cb17a63 | 2008-12-25 13:38:41 +0100 | [diff] [blame] | 1109 | static ssize_t ap_interrupts_show(struct bus_type *bus, char *buf) |
| 1110 | { |
| 1111 | return snprintf(buf, PAGE_SIZE, "%d\n", |
| 1112 | ap_using_interrupts() ? 1 : 0); |
| 1113 | } |
| 1114 | |
| 1115 | static BUS_ATTR(ap_interrupts, 0444, ap_interrupts_show, NULL); |
| 1116 | |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1117 | static ssize_t ap_config_time_store(struct bus_type *bus, |
| 1118 | const char *buf, size_t count) |
| 1119 | { |
| 1120 | int time; |
| 1121 | |
| 1122 | if (sscanf(buf, "%d\n", &time) != 1 || time < 5 || time > 120) |
| 1123 | return -EINVAL; |
| 1124 | ap_config_time = time; |
| 1125 | if (!timer_pending(&ap_config_timer) || |
| 1126 | !mod_timer(&ap_config_timer, jiffies + ap_config_time * HZ)) { |
| 1127 | ap_config_timer.expires = jiffies + ap_config_time * HZ; |
| 1128 | add_timer(&ap_config_timer); |
| 1129 | } |
| 1130 | return count; |
| 1131 | } |
| 1132 | |
| 1133 | static BUS_ATTR(config_time, 0644, ap_config_time_show, ap_config_time_store); |
| 1134 | |
| 1135 | static ssize_t ap_poll_thread_show(struct bus_type *bus, char *buf) |
| 1136 | { |
| 1137 | return snprintf(buf, PAGE_SIZE, "%d\n", ap_poll_kthread ? 1 : 0); |
| 1138 | } |
| 1139 | |
| 1140 | static ssize_t ap_poll_thread_store(struct bus_type *bus, |
| 1141 | const char *buf, size_t count) |
| 1142 | { |
| 1143 | int flag, rc; |
| 1144 | |
| 1145 | if (sscanf(buf, "%d\n", &flag) != 1) |
| 1146 | return -EINVAL; |
| 1147 | if (flag) { |
| 1148 | rc = ap_poll_thread_start(); |
| 1149 | if (rc) |
| 1150 | return rc; |
| 1151 | } |
| 1152 | else |
| 1153 | ap_poll_thread_stop(); |
| 1154 | return count; |
| 1155 | } |
| 1156 | |
| 1157 | static BUS_ATTR(poll_thread, 0644, ap_poll_thread_show, ap_poll_thread_store); |
| 1158 | |
Felix Beck | fe13723 | 2008-07-14 09:59:08 +0200 | [diff] [blame] | 1159 | static ssize_t poll_timeout_show(struct bus_type *bus, char *buf) |
| 1160 | { |
| 1161 | return snprintf(buf, PAGE_SIZE, "%llu\n", poll_timeout); |
| 1162 | } |
| 1163 | |
| 1164 | static ssize_t poll_timeout_store(struct bus_type *bus, const char *buf, |
| 1165 | size_t count) |
| 1166 | { |
| 1167 | unsigned long long time; |
| 1168 | ktime_t hr_time; |
| 1169 | |
| 1170 | /* 120 seconds = maximum poll interval */ |
Felix Beck | cb17a63 | 2008-12-25 13:38:41 +0100 | [diff] [blame] | 1171 | if (sscanf(buf, "%llu\n", &time) != 1 || time < 1 || |
| 1172 | time > 120000000000ULL) |
Felix Beck | fe13723 | 2008-07-14 09:59:08 +0200 | [diff] [blame] | 1173 | return -EINVAL; |
| 1174 | poll_timeout = time; |
| 1175 | hr_time = ktime_set(0, poll_timeout); |
| 1176 | |
| 1177 | if (!hrtimer_is_queued(&ap_poll_timer) || |
Arjan van de Ven | 6c644ea | 2008-09-01 15:20:30 -0700 | [diff] [blame] | 1178 | !hrtimer_forward(&ap_poll_timer, hrtimer_get_expires(&ap_poll_timer), hr_time)) { |
| 1179 | hrtimer_set_expires(&ap_poll_timer, hr_time); |
| 1180 | hrtimer_start_expires(&ap_poll_timer, HRTIMER_MODE_ABS); |
Felix Beck | fe13723 | 2008-07-14 09:59:08 +0200 | [diff] [blame] | 1181 | } |
| 1182 | return count; |
| 1183 | } |
| 1184 | |
| 1185 | static BUS_ATTR(poll_timeout, 0644, poll_timeout_show, poll_timeout_store); |
| 1186 | |
Ingo Tuchscherer | 5bc334b | 2015-01-23 13:27:04 +0100 | [diff] [blame] | 1187 | static ssize_t ap_max_domain_id_show(struct bus_type *bus, char *buf) |
| 1188 | { |
| 1189 | ap_qid_t qid; |
| 1190 | int i, nd, max_domain_id = -1; |
| 1191 | unsigned long fbits; |
| 1192 | |
| 1193 | if (ap_configuration) { |
| 1194 | if (ap_domain_index >= 0 && ap_domain_index < AP_DOMAINS) { |
| 1195 | for (i = 0; i < AP_DEVICES; i++) { |
| 1196 | if (!ap_test_config_card_id(i)) |
| 1197 | continue; |
| 1198 | qid = AP_MKQID(i, ap_domain_index); |
| 1199 | fbits = ap_query_facilities(qid); |
| 1200 | if (fbits & (1UL << 57)) { |
| 1201 | /* the N bit is 0, Nd field is filled */ |
| 1202 | nd = (int)((fbits & 0x00FF0000UL)>>16); |
| 1203 | if (nd > 0) |
| 1204 | max_domain_id = nd; |
| 1205 | else |
| 1206 | max_domain_id = 15; |
| 1207 | } else { |
| 1208 | /* N bit is 1, max 16 domains */ |
| 1209 | max_domain_id = 15; |
| 1210 | } |
| 1211 | break; |
| 1212 | } |
| 1213 | } |
| 1214 | } else { |
| 1215 | /* no APXA support, older machines with max 16 domains */ |
| 1216 | max_domain_id = 15; |
| 1217 | } |
| 1218 | return snprintf(buf, PAGE_SIZE, "%d\n", max_domain_id); |
| 1219 | } |
| 1220 | |
| 1221 | static BUS_ATTR(ap_max_domain_id, 0444, ap_max_domain_id_show, NULL); |
| 1222 | |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1223 | static struct bus_attribute *const ap_bus_attrs[] = { |
| 1224 | &bus_attr_ap_domain, |
Ingo Tuchscherer | 91f3e3e | 2013-11-20 10:47:13 +0100 | [diff] [blame] | 1225 | &bus_attr_ap_control_domain_mask, |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1226 | &bus_attr_config_time, |
| 1227 | &bus_attr_poll_thread, |
Felix Beck | cb17a63 | 2008-12-25 13:38:41 +0100 | [diff] [blame] | 1228 | &bus_attr_ap_interrupts, |
Felix Beck | fe13723 | 2008-07-14 09:59:08 +0200 | [diff] [blame] | 1229 | &bus_attr_poll_timeout, |
Ingo Tuchscherer | 5bc334b | 2015-01-23 13:27:04 +0100 | [diff] [blame] | 1230 | &bus_attr_ap_max_domain_id, |
Felix Beck | fe13723 | 2008-07-14 09:59:08 +0200 | [diff] [blame] | 1231 | NULL, |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1232 | }; |
| 1233 | |
Holger Dengler | 7501455 | 2012-08-28 16:41:50 +0200 | [diff] [blame] | 1234 | /** |
| 1235 | * ap_query_configuration(): Query AP configuration information. |
| 1236 | * |
| 1237 | * Query information of installed cards and configured domains from AP. |
| 1238 | */ |
| 1239 | static void ap_query_configuration(void) |
| 1240 | { |
| 1241 | #ifdef CONFIG_64BIT |
| 1242 | if (ap_configuration_available()) { |
| 1243 | if (!ap_configuration) |
| 1244 | ap_configuration = |
| 1245 | kzalloc(sizeof(struct ap_config_info), |
| 1246 | GFP_KERNEL); |
| 1247 | if (ap_configuration) |
| 1248 | __ap_query_configuration(ap_configuration); |
| 1249 | } else |
| 1250 | ap_configuration = NULL; |
| 1251 | #else |
| 1252 | ap_configuration = NULL; |
| 1253 | #endif |
| 1254 | } |
| 1255 | |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1256 | /** |
Felix Beck | 1749a81 | 2008-04-17 07:46:28 +0200 | [diff] [blame] | 1257 | * ap_select_domain(): Select an AP domain. |
| 1258 | * |
| 1259 | * Pick one of the 16 AP domains. |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1260 | */ |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 1261 | static int ap_select_domain(void) |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1262 | { |
| 1263 | int queue_depth, device_type, count, max_count, best_domain; |
Holger Dengler | 7501455 | 2012-08-28 16:41:50 +0200 | [diff] [blame] | 1264 | ap_qid_t qid; |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1265 | int rc, i, j; |
| 1266 | |
Ingo Tuchscherer | 170387a | 2014-09-08 13:24:13 +0200 | [diff] [blame] | 1267 | /* IF APXA isn't installed, only 16 domains could be defined */ |
| 1268 | if (!ap_configuration->ap_extended && (ap_domain_index > 15)) |
| 1269 | return -EINVAL; |
| 1270 | |
Felix Beck | 1749a81 | 2008-04-17 07:46:28 +0200 | [diff] [blame] | 1271 | /* |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1272 | * We want to use a single domain. Either the one specified with |
| 1273 | * the "domain=" parameter or the domain with the maximum number |
| 1274 | * of devices. |
| 1275 | */ |
| 1276 | if (ap_domain_index >= 0 && ap_domain_index < AP_DOMAINS) |
| 1277 | /* Domain has already been selected. */ |
| 1278 | return 0; |
| 1279 | best_domain = -1; |
| 1280 | max_count = 0; |
| 1281 | for (i = 0; i < AP_DOMAINS; i++) { |
Holger Dengler | 7501455 | 2012-08-28 16:41:50 +0200 | [diff] [blame] | 1282 | if (!ap_test_config_domain(i)) |
| 1283 | continue; |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1284 | count = 0; |
| 1285 | for (j = 0; j < AP_DEVICES; j++) { |
Holger Dengler | 7501455 | 2012-08-28 16:41:50 +0200 | [diff] [blame] | 1286 | if (!ap_test_config_card_id(j)) |
| 1287 | continue; |
| 1288 | qid = AP_MKQID(j, i); |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1289 | rc = ap_query_queue(qid, &queue_depth, &device_type); |
| 1290 | if (rc) |
| 1291 | continue; |
| 1292 | count++; |
| 1293 | } |
| 1294 | if (count > max_count) { |
| 1295 | max_count = count; |
| 1296 | best_domain = i; |
| 1297 | } |
| 1298 | } |
| 1299 | if (best_domain >= 0){ |
| 1300 | ap_domain_index = best_domain; |
| 1301 | return 0; |
| 1302 | } |
| 1303 | return -ENODEV; |
| 1304 | } |
| 1305 | |
| 1306 | /** |
Felix Beck | 1749a81 | 2008-04-17 07:46:28 +0200 | [diff] [blame] | 1307 | * ap_probe_device_type(): Find the device type of an AP. |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1308 | * @ap_dev: pointer to the AP device. |
Felix Beck | 1749a81 | 2008-04-17 07:46:28 +0200 | [diff] [blame] | 1309 | * |
| 1310 | * Find the device type if query queue returned a device type of 0. |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1311 | */ |
| 1312 | static int ap_probe_device_type(struct ap_device *ap_dev) |
| 1313 | { |
| 1314 | static unsigned char msg[] = { |
| 1315 | 0x00,0x06,0x00,0x00,0x00,0x00,0x00,0x00, |
| 1316 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 1317 | 0x00,0x00,0x00,0x58,0x00,0x00,0x00,0x00, |
| 1318 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 1319 | 0x01,0x00,0x43,0x43,0x41,0x2d,0x41,0x50, |
| 1320 | 0x50,0x4c,0x20,0x20,0x20,0x01,0x01,0x01, |
| 1321 | 0x00,0x00,0x00,0x00,0x50,0x4b,0x00,0x00, |
| 1322 | 0x00,0x00,0x01,0x1c,0x00,0x00,0x00,0x00, |
| 1323 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 1324 | 0x00,0x00,0x05,0xb8,0x00,0x00,0x00,0x00, |
| 1325 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 1326 | 0x70,0x00,0x41,0x00,0x00,0x00,0x00,0x00, |
| 1327 | 0x00,0x00,0x54,0x32,0x01,0x00,0xa0,0x00, |
| 1328 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 1329 | 0x00,0x00,0x00,0x00,0xb8,0x05,0x00,0x00, |
| 1330 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 1331 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 1332 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 1333 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 1334 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 1335 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 1336 | 0x00,0x00,0x0a,0x00,0x00,0x00,0x00,0x00, |
| 1337 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| 1338 | 0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00, |
| 1339 | 0x49,0x43,0x53,0x46,0x20,0x20,0x20,0x20, |
| 1340 | 0x50,0x4b,0x0a,0x00,0x50,0x4b,0x43,0x53, |
| 1341 | 0x2d,0x31,0x2e,0x32,0x37,0x00,0x11,0x22, |
| 1342 | 0x33,0x44,0x55,0x66,0x77,0x88,0x99,0x00, |
| 1343 | 0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88, |
| 1344 | 0x99,0x00,0x11,0x22,0x33,0x44,0x55,0x66, |
| 1345 | 0x77,0x88,0x99,0x00,0x11,0x22,0x33,0x44, |
| 1346 | 0x55,0x66,0x77,0x88,0x99,0x00,0x11,0x22, |
| 1347 | 0x33,0x44,0x55,0x66,0x77,0x88,0x99,0x00, |
| 1348 | 0x11,0x22,0x33,0x5d,0x00,0x5b,0x00,0x77, |
| 1349 | 0x88,0x1e,0x00,0x00,0x57,0x00,0x00,0x00, |
| 1350 | 0x00,0x04,0x00,0x00,0x4f,0x00,0x00,0x00, |
| 1351 | 0x03,0x02,0x00,0x00,0x40,0x01,0x00,0x01, |
| 1352 | 0xce,0x02,0x68,0x2d,0x5f,0xa9,0xde,0x0c, |
| 1353 | 0xf6,0xd2,0x7b,0x58,0x4b,0xf9,0x28,0x68, |
| 1354 | 0x3d,0xb4,0xf4,0xef,0x78,0xd5,0xbe,0x66, |
| 1355 | 0x63,0x42,0xef,0xf8,0xfd,0xa4,0xf8,0xb0, |
| 1356 | 0x8e,0x29,0xc2,0xc9,0x2e,0xd8,0x45,0xb8, |
| 1357 | 0x53,0x8c,0x6f,0x4e,0x72,0x8f,0x6c,0x04, |
| 1358 | 0x9c,0x88,0xfc,0x1e,0xc5,0x83,0x55,0x57, |
| 1359 | 0xf7,0xdd,0xfd,0x4f,0x11,0x36,0x95,0x5d, |
| 1360 | }; |
| 1361 | struct ap_queue_status status; |
| 1362 | unsigned long long psmid; |
| 1363 | char *reply; |
| 1364 | int rc, i; |
| 1365 | |
| 1366 | reply = (void *) get_zeroed_page(GFP_KERNEL); |
| 1367 | if (!reply) { |
| 1368 | rc = -ENOMEM; |
| 1369 | goto out; |
| 1370 | } |
| 1371 | |
| 1372 | status = __ap_send(ap_dev->qid, 0x0102030405060708ULL, |
Felix Beck | a6a5d73 | 2009-12-07 12:51:55 +0100 | [diff] [blame] | 1373 | msg, sizeof(msg), 0); |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1374 | if (status.response_code != AP_RESPONSE_NORMAL) { |
| 1375 | rc = -ENODEV; |
| 1376 | goto out_free; |
| 1377 | } |
| 1378 | |
| 1379 | /* Wait for the test message to complete. */ |
| 1380 | for (i = 0; i < 6; i++) { |
| 1381 | mdelay(300); |
| 1382 | status = __ap_recv(ap_dev->qid, &psmid, reply, 4096); |
| 1383 | if (status.response_code == AP_RESPONSE_NORMAL && |
| 1384 | psmid == 0x0102030405060708ULL) |
| 1385 | break; |
| 1386 | } |
| 1387 | if (i < 6) { |
| 1388 | /* Got an answer. */ |
| 1389 | if (reply[0] == 0x00 && reply[1] == 0x86) |
| 1390 | ap_dev->device_type = AP_DEVICE_TYPE_PCICC; |
| 1391 | else |
| 1392 | ap_dev->device_type = AP_DEVICE_TYPE_PCICA; |
| 1393 | rc = 0; |
| 1394 | } else |
| 1395 | rc = -ENODEV; |
| 1396 | |
| 1397 | out_free: |
| 1398 | free_page((unsigned long) reply); |
| 1399 | out: |
| 1400 | return rc; |
| 1401 | } |
| 1402 | |
Martin Schwidefsky | f4eae94 | 2013-06-24 10:30:41 +0200 | [diff] [blame] | 1403 | static void ap_interrupt_handler(struct airq_struct *airq) |
Felix Beck | cb17a63 | 2008-12-25 13:38:41 +0100 | [diff] [blame] | 1404 | { |
Heiko Carstens | 420f42e | 2013-01-02 15:18:18 +0100 | [diff] [blame] | 1405 | inc_irq_stat(IRQIO_APB); |
Felix Beck | cb17a63 | 2008-12-25 13:38:41 +0100 | [diff] [blame] | 1406 | tasklet_schedule(&ap_tasklet); |
| 1407 | } |
| 1408 | |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1409 | /** |
Felix Beck | 1749a81 | 2008-04-17 07:46:28 +0200 | [diff] [blame] | 1410 | * __ap_scan_bus(): Scan the AP bus. |
| 1411 | * @dev: Pointer to device |
| 1412 | * @data: Pointer to data |
| 1413 | * |
| 1414 | * Scan the AP bus for new devices. |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1415 | */ |
| 1416 | static int __ap_scan_bus(struct device *dev, void *data) |
| 1417 | { |
| 1418 | return to_ap_dev(dev)->qid == (ap_qid_t)(unsigned long) data; |
| 1419 | } |
| 1420 | |
| 1421 | static void ap_device_release(struct device *dev) |
| 1422 | { |
| 1423 | struct ap_device *ap_dev = to_ap_dev(dev); |
| 1424 | |
| 1425 | kfree(ap_dev); |
| 1426 | } |
| 1427 | |
Al Viro | 4927b3f | 2006-12-06 19:18:20 +0000 | [diff] [blame] | 1428 | static void ap_scan_bus(struct work_struct *unused) |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1429 | { |
| 1430 | struct ap_device *ap_dev; |
| 1431 | struct device *dev; |
| 1432 | ap_qid_t qid; |
| 1433 | int queue_depth, device_type; |
Holger Dengler | 6bed05b | 2011-07-24 10:48:25 +0200 | [diff] [blame] | 1434 | unsigned int device_functions; |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1435 | int rc, i; |
| 1436 | |
Holger Dengler | 7501455 | 2012-08-28 16:41:50 +0200 | [diff] [blame] | 1437 | ap_query_configuration(); |
Ingo Tuchscherer | 56bbe68 | 2013-04-12 17:52:08 +0200 | [diff] [blame] | 1438 | if (ap_select_domain() != 0) { |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1439 | return; |
Ingo Tuchscherer | 56bbe68 | 2013-04-12 17:52:08 +0200 | [diff] [blame] | 1440 | } |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1441 | for (i = 0; i < AP_DEVICES; i++) { |
| 1442 | qid = AP_MKQID(i, ap_domain_index); |
| 1443 | dev = bus_find_device(&ap_bus_type, NULL, |
| 1444 | (void *)(unsigned long)qid, |
| 1445 | __ap_scan_bus); |
Holger Dengler | 7501455 | 2012-08-28 16:41:50 +0200 | [diff] [blame] | 1446 | if (ap_test_config_card_id(i)) |
| 1447 | rc = ap_query_queue(qid, &queue_depth, &device_type); |
| 1448 | else |
| 1449 | rc = -ENODEV; |
Ralph Wuerthner | c6a4826 | 2007-03-26 20:42:42 +0200 | [diff] [blame] | 1450 | if (dev) { |
Ralph Wuerthner | af512ed0 | 2007-07-10 11:24:19 +0200 | [diff] [blame] | 1451 | if (rc == -EBUSY) { |
| 1452 | set_current_state(TASK_UNINTERRUPTIBLE); |
| 1453 | schedule_timeout(AP_RESET_TIMEOUT); |
| 1454 | rc = ap_query_queue(qid, &queue_depth, |
| 1455 | &device_type); |
| 1456 | } |
Ralph Wuerthner | c6a4826 | 2007-03-26 20:42:42 +0200 | [diff] [blame] | 1457 | ap_dev = to_ap_dev(dev); |
| 1458 | spin_lock_bh(&ap_dev->lock); |
| 1459 | if (rc || ap_dev->unregistered) { |
| 1460 | spin_unlock_bh(&ap_dev->lock); |
Felix Beck | 5314af6 | 2009-09-22 22:58:51 +0200 | [diff] [blame] | 1461 | if (ap_dev->unregistered) |
| 1462 | i--; |
Ralph Wuerthner | c6a4826 | 2007-03-26 20:42:42 +0200 | [diff] [blame] | 1463 | device_unregister(dev); |
Ralph Wuerthner | af512ed0 | 2007-07-10 11:24:19 +0200 | [diff] [blame] | 1464 | put_device(dev); |
Ralph Wuerthner | c6a4826 | 2007-03-26 20:42:42 +0200 | [diff] [blame] | 1465 | continue; |
Ralph Wuerthner | af512ed0 | 2007-07-10 11:24:19 +0200 | [diff] [blame] | 1466 | } |
| 1467 | spin_unlock_bh(&ap_dev->lock); |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1468 | put_device(dev); |
| 1469 | continue; |
| 1470 | } |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1471 | if (rc) |
| 1472 | continue; |
| 1473 | rc = ap_init_queue(qid); |
| 1474 | if (rc) |
| 1475 | continue; |
| 1476 | ap_dev = kzalloc(sizeof(*ap_dev), GFP_KERNEL); |
| 1477 | if (!ap_dev) |
| 1478 | break; |
| 1479 | ap_dev->qid = qid; |
| 1480 | ap_dev->queue_depth = queue_depth; |
Ralph Wuerthner | 4e56296 | 2006-10-04 20:02:05 +0200 | [diff] [blame] | 1481 | ap_dev->unregistered = 1; |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1482 | spin_lock_init(&ap_dev->lock); |
| 1483 | INIT_LIST_HEAD(&ap_dev->pendingq); |
| 1484 | INIT_LIST_HEAD(&ap_dev->requestq); |
Ralph Wuerthner | cf352ce | 2007-03-19 13:19:14 +0100 | [diff] [blame] | 1485 | INIT_LIST_HEAD(&ap_dev->list); |
Ralph Wuerthner | af512ed0 | 2007-07-10 11:24:19 +0200 | [diff] [blame] | 1486 | setup_timer(&ap_dev->timeout, ap_request_timeout, |
| 1487 | (unsigned long) ap_dev); |
Holger Dengler | 6bed05b | 2011-07-24 10:48:25 +0200 | [diff] [blame] | 1488 | switch (device_type) { |
| 1489 | case 0: |
Holger Dengler | 1e2076f | 2012-08-28 16:48:29 +0200 | [diff] [blame] | 1490 | /* device type probing for old cards */ |
Holger Dengler | cf2d007 | 2011-05-23 10:24:30 +0200 | [diff] [blame] | 1491 | if (ap_probe_device_type(ap_dev)) { |
| 1492 | kfree(ap_dev); |
| 1493 | continue; |
| 1494 | } |
Holger Dengler | 6bed05b | 2011-07-24 10:48:25 +0200 | [diff] [blame] | 1495 | break; |
Holger Dengler | 6bed05b | 2011-07-24 10:48:25 +0200 | [diff] [blame] | 1496 | default: |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1497 | ap_dev->device_type = device_type; |
Holger Dengler | 6bed05b | 2011-07-24 10:48:25 +0200 | [diff] [blame] | 1498 | } |
Ingo Tuchscherer | 42f4dd61 | 2014-10-02 14:48:46 +0200 | [diff] [blame] | 1499 | ap_dev->raw_hwtype = device_type; |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1500 | |
Holger Dengler | 1e2076f | 2012-08-28 16:48:29 +0200 | [diff] [blame] | 1501 | rc = ap_query_functions(qid, &device_functions); |
| 1502 | if (!rc) |
| 1503 | ap_dev->functions = device_functions; |
| 1504 | else |
| 1505 | ap_dev->functions = 0u; |
| 1506 | |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1507 | ap_dev->device.bus = &ap_bus_type; |
| 1508 | ap_dev->device.parent = ap_root_device; |
Felix Beck | edc44fa | 2009-09-11 10:28:52 +0200 | [diff] [blame] | 1509 | if (dev_set_name(&ap_dev->device, "card%02x", |
| 1510 | AP_QID_DEVICE(ap_dev->qid))) { |
| 1511 | kfree(ap_dev); |
| 1512 | continue; |
| 1513 | } |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1514 | ap_dev->device.release = ap_device_release; |
| 1515 | rc = device_register(&ap_dev->device); |
| 1516 | if (rc) { |
Sebastian Ott | c630493 | 2009-09-11 10:28:38 +0200 | [diff] [blame] | 1517 | put_device(&ap_dev->device); |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1518 | continue; |
| 1519 | } |
| 1520 | /* Add device attributes. */ |
| 1521 | rc = sysfs_create_group(&ap_dev->device.kobj, |
| 1522 | &ap_dev_attr_group); |
Ralph Wuerthner | 4e56296 | 2006-10-04 20:02:05 +0200 | [diff] [blame] | 1523 | if (!rc) { |
| 1524 | spin_lock_bh(&ap_dev->lock); |
| 1525 | ap_dev->unregistered = 0; |
| 1526 | spin_unlock_bh(&ap_dev->lock); |
| 1527 | } |
| 1528 | else |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1529 | device_unregister(&ap_dev->device); |
| 1530 | } |
| 1531 | } |
| 1532 | |
| 1533 | static void |
| 1534 | ap_config_timeout(unsigned long ptr) |
| 1535 | { |
| 1536 | queue_work(ap_work_queue, &ap_config_work); |
| 1537 | ap_config_timer.expires = jiffies + ap_config_time * HZ; |
| 1538 | add_timer(&ap_config_timer); |
| 1539 | } |
| 1540 | |
| 1541 | /** |
Holger Dengler | bc615de | 2011-11-14 11:19:04 +0100 | [diff] [blame] | 1542 | * __ap_schedule_poll_timer(): Schedule poll timer. |
Felix Beck | 1749a81 | 2008-04-17 07:46:28 +0200 | [diff] [blame] | 1543 | * |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1544 | * Set up the timer to run the poll tasklet |
| 1545 | */ |
Holger Dengler | bc615de | 2011-11-14 11:19:04 +0100 | [diff] [blame] | 1546 | static inline void __ap_schedule_poll_timer(void) |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1547 | { |
Felix Beck | 8d406c6 | 2009-07-24 12:39:53 +0200 | [diff] [blame] | 1548 | ktime_t hr_time; |
Felix Beck | 9352131 | 2009-12-07 12:52:00 +0100 | [diff] [blame] | 1549 | |
| 1550 | spin_lock_bh(&ap_poll_timer_lock); |
Holger Dengler | bc615de | 2011-11-14 11:19:04 +0100 | [diff] [blame] | 1551 | if (hrtimer_is_queued(&ap_poll_timer) || ap_suspend_flag) |
Felix Beck | 9352131 | 2009-12-07 12:52:00 +0100 | [diff] [blame] | 1552 | goto out; |
Felix Beck | 8d406c6 | 2009-07-24 12:39:53 +0200 | [diff] [blame] | 1553 | if (ktime_to_ns(hrtimer_expires_remaining(&ap_poll_timer)) <= 0) { |
| 1554 | hr_time = ktime_set(0, poll_timeout); |
| 1555 | hrtimer_forward_now(&ap_poll_timer, hr_time); |
| 1556 | hrtimer_restart(&ap_poll_timer); |
| 1557 | } |
Felix Beck | 9352131 | 2009-12-07 12:52:00 +0100 | [diff] [blame] | 1558 | out: |
| 1559 | spin_unlock_bh(&ap_poll_timer_lock); |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1560 | } |
| 1561 | |
| 1562 | /** |
Holger Dengler | bc615de | 2011-11-14 11:19:04 +0100 | [diff] [blame] | 1563 | * ap_schedule_poll_timer(): Schedule poll timer. |
| 1564 | * |
| 1565 | * Set up the timer to run the poll tasklet |
| 1566 | */ |
| 1567 | static inline void ap_schedule_poll_timer(void) |
| 1568 | { |
| 1569 | if (ap_using_interrupts()) |
| 1570 | return; |
| 1571 | __ap_schedule_poll_timer(); |
| 1572 | } |
| 1573 | |
| 1574 | /** |
Felix Beck | 1749a81 | 2008-04-17 07:46:28 +0200 | [diff] [blame] | 1575 | * ap_poll_read(): Receive pending reply messages from an AP device. |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1576 | * @ap_dev: pointer to the AP device |
| 1577 | * @flags: pointer to control flags, bit 2^0 is set if another poll is |
| 1578 | * required, bit 2^1 is set if the poll timer needs to get armed |
Felix Beck | 1749a81 | 2008-04-17 07:46:28 +0200 | [diff] [blame] | 1579 | * |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1580 | * Returns 0 if the device is still present, -ENODEV if not. |
| 1581 | */ |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 1582 | static int ap_poll_read(struct ap_device *ap_dev, unsigned long *flags) |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1583 | { |
| 1584 | struct ap_queue_status status; |
| 1585 | struct ap_message *ap_msg; |
| 1586 | |
| 1587 | if (ap_dev->queue_count <= 0) |
| 1588 | return 0; |
| 1589 | status = __ap_recv(ap_dev->qid, &ap_dev->reply->psmid, |
| 1590 | ap_dev->reply->message, ap_dev->reply->length); |
| 1591 | switch (status.response_code) { |
| 1592 | case AP_RESPONSE_NORMAL: |
| 1593 | atomic_dec(&ap_poll_requests); |
Ralph Wuerthner | af512ed0 | 2007-07-10 11:24:19 +0200 | [diff] [blame] | 1594 | ap_decrease_queue_count(ap_dev); |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1595 | list_for_each_entry(ap_msg, &ap_dev->pendingq, list) { |
| 1596 | if (ap_msg->psmid != ap_dev->reply->psmid) |
| 1597 | continue; |
| 1598 | list_del_init(&ap_msg->list); |
| 1599 | ap_dev->pendingq_count--; |
Holger Dengler | 54a8f56 | 2012-05-16 14:08:22 +0200 | [diff] [blame] | 1600 | ap_msg->receive(ap_dev, ap_msg, ap_dev->reply); |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1601 | break; |
| 1602 | } |
| 1603 | if (ap_dev->queue_count > 0) |
| 1604 | *flags |= 1; |
| 1605 | break; |
| 1606 | case AP_RESPONSE_NO_PENDING_REPLY: |
| 1607 | if (status.queue_empty) { |
| 1608 | /* The card shouldn't forget requests but who knows. */ |
Ralph Wuerthner | e675c0d | 2007-03-26 20:42:43 +0200 | [diff] [blame] | 1609 | atomic_sub(ap_dev->queue_count, &ap_poll_requests); |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1610 | ap_dev->queue_count = 0; |
| 1611 | list_splice_init(&ap_dev->pendingq, &ap_dev->requestq); |
| 1612 | ap_dev->requestq_count += ap_dev->pendingq_count; |
| 1613 | ap_dev->pendingq_count = 0; |
| 1614 | } else |
| 1615 | *flags |= 2; |
| 1616 | break; |
| 1617 | default: |
| 1618 | return -ENODEV; |
| 1619 | } |
| 1620 | return 0; |
| 1621 | } |
| 1622 | |
| 1623 | /** |
Felix Beck | 1749a81 | 2008-04-17 07:46:28 +0200 | [diff] [blame] | 1624 | * ap_poll_write(): Send messages from the request queue to an AP device. |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1625 | * @ap_dev: pointer to the AP device |
| 1626 | * @flags: pointer to control flags, bit 2^0 is set if another poll is |
| 1627 | * required, bit 2^1 is set if the poll timer needs to get armed |
Felix Beck | 1749a81 | 2008-04-17 07:46:28 +0200 | [diff] [blame] | 1628 | * |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1629 | * Returns 0 if the device is still present, -ENODEV if not. |
| 1630 | */ |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 1631 | static int ap_poll_write(struct ap_device *ap_dev, unsigned long *flags) |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1632 | { |
| 1633 | struct ap_queue_status status; |
| 1634 | struct ap_message *ap_msg; |
| 1635 | |
| 1636 | if (ap_dev->requestq_count <= 0 || |
| 1637 | ap_dev->queue_count >= ap_dev->queue_depth) |
| 1638 | return 0; |
| 1639 | /* Start the next request on the queue. */ |
| 1640 | ap_msg = list_entry(ap_dev->requestq.next, struct ap_message, list); |
| 1641 | status = __ap_send(ap_dev->qid, ap_msg->psmid, |
Felix Beck | a6a5d73 | 2009-12-07 12:51:55 +0100 | [diff] [blame] | 1642 | ap_msg->message, ap_msg->length, ap_msg->special); |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1643 | switch (status.response_code) { |
| 1644 | case AP_RESPONSE_NORMAL: |
| 1645 | atomic_inc(&ap_poll_requests); |
Ralph Wuerthner | af512ed0 | 2007-07-10 11:24:19 +0200 | [diff] [blame] | 1646 | ap_increase_queue_count(ap_dev); |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1647 | list_move_tail(&ap_msg->list, &ap_dev->pendingq); |
| 1648 | ap_dev->requestq_count--; |
| 1649 | ap_dev->pendingq_count++; |
| 1650 | if (ap_dev->queue_count < ap_dev->queue_depth && |
| 1651 | ap_dev->requestq_count > 0) |
| 1652 | *flags |= 1; |
| 1653 | *flags |= 2; |
| 1654 | break; |
Ralph Wuerthner | af512ed0 | 2007-07-10 11:24:19 +0200 | [diff] [blame] | 1655 | case AP_RESPONSE_RESET_IN_PROGRESS: |
Holger Dengler | bc615de | 2011-11-14 11:19:04 +0100 | [diff] [blame] | 1656 | __ap_schedule_poll_timer(); |
| 1657 | case AP_RESPONSE_Q_FULL: |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1658 | *flags |= 2; |
| 1659 | break; |
| 1660 | case AP_RESPONSE_MESSAGE_TOO_BIG: |
Felix Beck | a6a5d73 | 2009-12-07 12:51:55 +0100 | [diff] [blame] | 1661 | case AP_RESPONSE_REQ_FAC_NOT_INST: |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1662 | return -EINVAL; |
| 1663 | default: |
| 1664 | return -ENODEV; |
| 1665 | } |
| 1666 | return 0; |
| 1667 | } |
| 1668 | |
| 1669 | /** |
Felix Beck | 1749a81 | 2008-04-17 07:46:28 +0200 | [diff] [blame] | 1670 | * ap_poll_queue(): Poll AP device for pending replies and send new messages. |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1671 | * @ap_dev: pointer to the bus device |
| 1672 | * @flags: pointer to control flags, bit 2^0 is set if another poll is |
| 1673 | * required, bit 2^1 is set if the poll timer needs to get armed |
Felix Beck | 1749a81 | 2008-04-17 07:46:28 +0200 | [diff] [blame] | 1674 | * |
| 1675 | * Poll AP device for pending replies and send new messages. If either |
| 1676 | * ap_poll_read or ap_poll_write returns -ENODEV unregister the device. |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1677 | * Returns 0. |
| 1678 | */ |
| 1679 | static inline int ap_poll_queue(struct ap_device *ap_dev, unsigned long *flags) |
| 1680 | { |
| 1681 | int rc; |
| 1682 | |
| 1683 | rc = ap_poll_read(ap_dev, flags); |
| 1684 | if (rc) |
| 1685 | return rc; |
| 1686 | return ap_poll_write(ap_dev, flags); |
| 1687 | } |
| 1688 | |
| 1689 | /** |
Felix Beck | 1749a81 | 2008-04-17 07:46:28 +0200 | [diff] [blame] | 1690 | * __ap_queue_message(): Queue a message to a device. |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1691 | * @ap_dev: pointer to the AP device |
| 1692 | * @ap_msg: the message to be queued |
Felix Beck | 1749a81 | 2008-04-17 07:46:28 +0200 | [diff] [blame] | 1693 | * |
| 1694 | * Queue a message to a device. Returns 0 if successful. |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1695 | */ |
| 1696 | static int __ap_queue_message(struct ap_device *ap_dev, struct ap_message *ap_msg) |
| 1697 | { |
| 1698 | struct ap_queue_status status; |
| 1699 | |
| 1700 | if (list_empty(&ap_dev->requestq) && |
| 1701 | ap_dev->queue_count < ap_dev->queue_depth) { |
| 1702 | status = __ap_send(ap_dev->qid, ap_msg->psmid, |
Felix Beck | a6a5d73 | 2009-12-07 12:51:55 +0100 | [diff] [blame] | 1703 | ap_msg->message, ap_msg->length, |
| 1704 | ap_msg->special); |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1705 | switch (status.response_code) { |
| 1706 | case AP_RESPONSE_NORMAL: |
| 1707 | list_add_tail(&ap_msg->list, &ap_dev->pendingq); |
| 1708 | atomic_inc(&ap_poll_requests); |
| 1709 | ap_dev->pendingq_count++; |
Ralph Wuerthner | af512ed0 | 2007-07-10 11:24:19 +0200 | [diff] [blame] | 1710 | ap_increase_queue_count(ap_dev); |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1711 | ap_dev->total_request_count++; |
| 1712 | break; |
| 1713 | case AP_RESPONSE_Q_FULL: |
Ralph Wuerthner | af512ed0 | 2007-07-10 11:24:19 +0200 | [diff] [blame] | 1714 | case AP_RESPONSE_RESET_IN_PROGRESS: |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1715 | list_add_tail(&ap_msg->list, &ap_dev->requestq); |
| 1716 | ap_dev->requestq_count++; |
| 1717 | ap_dev->total_request_count++; |
| 1718 | return -EBUSY; |
Felix Beck | a6a5d73 | 2009-12-07 12:51:55 +0100 | [diff] [blame] | 1719 | case AP_RESPONSE_REQ_FAC_NOT_INST: |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1720 | case AP_RESPONSE_MESSAGE_TOO_BIG: |
Holger Dengler | 54a8f56 | 2012-05-16 14:08:22 +0200 | [diff] [blame] | 1721 | ap_msg->receive(ap_dev, ap_msg, ERR_PTR(-EINVAL)); |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1722 | return -EINVAL; |
| 1723 | default: /* Device is gone. */ |
Holger Dengler | 54a8f56 | 2012-05-16 14:08:22 +0200 | [diff] [blame] | 1724 | ap_msg->receive(ap_dev, ap_msg, ERR_PTR(-ENODEV)); |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1725 | return -ENODEV; |
| 1726 | } |
| 1727 | } else { |
| 1728 | list_add_tail(&ap_msg->list, &ap_dev->requestq); |
| 1729 | ap_dev->requestq_count++; |
| 1730 | ap_dev->total_request_count++; |
| 1731 | return -EBUSY; |
| 1732 | } |
| 1733 | ap_schedule_poll_timer(); |
| 1734 | return 0; |
| 1735 | } |
| 1736 | |
| 1737 | void ap_queue_message(struct ap_device *ap_dev, struct ap_message *ap_msg) |
| 1738 | { |
| 1739 | unsigned long flags; |
| 1740 | int rc; |
| 1741 | |
Holger Dengler | 54a8f56 | 2012-05-16 14:08:22 +0200 | [diff] [blame] | 1742 | /* For asynchronous message handling a valid receive-callback |
| 1743 | * is required. */ |
| 1744 | BUG_ON(!ap_msg->receive); |
| 1745 | |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1746 | spin_lock_bh(&ap_dev->lock); |
| 1747 | if (!ap_dev->unregistered) { |
| 1748 | /* Make room on the queue by polling for finished requests. */ |
| 1749 | rc = ap_poll_queue(ap_dev, &flags); |
| 1750 | if (!rc) |
| 1751 | rc = __ap_queue_message(ap_dev, ap_msg); |
| 1752 | if (!rc) |
| 1753 | wake_up(&ap_poll_wait); |
Ralph Wuerthner | 4e56296 | 2006-10-04 20:02:05 +0200 | [diff] [blame] | 1754 | if (rc == -ENODEV) |
| 1755 | ap_dev->unregistered = 1; |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1756 | } else { |
Holger Dengler | 54a8f56 | 2012-05-16 14:08:22 +0200 | [diff] [blame] | 1757 | ap_msg->receive(ap_dev, ap_msg, ERR_PTR(-ENODEV)); |
Ralph Wuerthner | c6a4826 | 2007-03-26 20:42:42 +0200 | [diff] [blame] | 1758 | rc = -ENODEV; |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1759 | } |
| 1760 | spin_unlock_bh(&ap_dev->lock); |
| 1761 | if (rc == -ENODEV) |
| 1762 | device_unregister(&ap_dev->device); |
| 1763 | } |
| 1764 | EXPORT_SYMBOL(ap_queue_message); |
| 1765 | |
| 1766 | /** |
Felix Beck | 1749a81 | 2008-04-17 07:46:28 +0200 | [diff] [blame] | 1767 | * ap_cancel_message(): Cancel a crypto request. |
| 1768 | * @ap_dev: The AP device that has the message queued |
| 1769 | * @ap_msg: The message that is to be removed |
| 1770 | * |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1771 | * Cancel a crypto request. This is done by removing the request |
Felix Beck | 1749a81 | 2008-04-17 07:46:28 +0200 | [diff] [blame] | 1772 | * from the device pending or request queue. Note that the |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1773 | * request stays on the AP queue. When it finishes the message |
| 1774 | * reply will be discarded because the psmid can't be found. |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1775 | */ |
| 1776 | void ap_cancel_message(struct ap_device *ap_dev, struct ap_message *ap_msg) |
| 1777 | { |
| 1778 | struct ap_message *tmp; |
| 1779 | |
| 1780 | spin_lock_bh(&ap_dev->lock); |
| 1781 | if (!list_empty(&ap_msg->list)) { |
| 1782 | list_for_each_entry(tmp, &ap_dev->pendingq, list) |
| 1783 | if (tmp->psmid == ap_msg->psmid) { |
| 1784 | ap_dev->pendingq_count--; |
| 1785 | goto found; |
| 1786 | } |
| 1787 | ap_dev->requestq_count--; |
| 1788 | found: |
| 1789 | list_del_init(&ap_msg->list); |
| 1790 | } |
| 1791 | spin_unlock_bh(&ap_dev->lock); |
| 1792 | } |
| 1793 | EXPORT_SYMBOL(ap_cancel_message); |
| 1794 | |
| 1795 | /** |
Felix Beck | 1749a81 | 2008-04-17 07:46:28 +0200 | [diff] [blame] | 1796 | * ap_poll_timeout(): AP receive polling for finished AP requests. |
Felix Beck | fe13723 | 2008-07-14 09:59:08 +0200 | [diff] [blame] | 1797 | * @unused: Unused pointer. |
Felix Beck | 1749a81 | 2008-04-17 07:46:28 +0200 | [diff] [blame] | 1798 | * |
Felix Beck | fe13723 | 2008-07-14 09:59:08 +0200 | [diff] [blame] | 1799 | * Schedules the AP tasklet using a high resolution timer. |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1800 | */ |
Felix Beck | fe13723 | 2008-07-14 09:59:08 +0200 | [diff] [blame] | 1801 | static enum hrtimer_restart ap_poll_timeout(struct hrtimer *unused) |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1802 | { |
| 1803 | tasklet_schedule(&ap_tasklet); |
Felix Beck | fe13723 | 2008-07-14 09:59:08 +0200 | [diff] [blame] | 1804 | return HRTIMER_NORESTART; |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1805 | } |
| 1806 | |
| 1807 | /** |
Felix Beck | 1749a81 | 2008-04-17 07:46:28 +0200 | [diff] [blame] | 1808 | * ap_reset(): Reset a not responding AP device. |
| 1809 | * @ap_dev: Pointer to the AP device |
| 1810 | * |
Ralph Wuerthner | af512ed0 | 2007-07-10 11:24:19 +0200 | [diff] [blame] | 1811 | * Reset a not responding AP device and move all requests from the |
| 1812 | * pending queue to the request queue. |
| 1813 | */ |
| 1814 | static void ap_reset(struct ap_device *ap_dev) |
| 1815 | { |
| 1816 | int rc; |
| 1817 | |
| 1818 | ap_dev->reset = AP_RESET_IGNORE; |
| 1819 | atomic_sub(ap_dev->queue_count, &ap_poll_requests); |
| 1820 | ap_dev->queue_count = 0; |
| 1821 | list_splice_init(&ap_dev->pendingq, &ap_dev->requestq); |
| 1822 | ap_dev->requestq_count += ap_dev->pendingq_count; |
| 1823 | ap_dev->pendingq_count = 0; |
| 1824 | rc = ap_init_queue(ap_dev->qid); |
| 1825 | if (rc == -ENODEV) |
| 1826 | ap_dev->unregistered = 1; |
Holger Dengler | 7546496 | 2011-12-01 13:32:23 +0100 | [diff] [blame] | 1827 | else |
| 1828 | __ap_schedule_poll_timer(); |
Ralph Wuerthner | af512ed0 | 2007-07-10 11:24:19 +0200 | [diff] [blame] | 1829 | } |
| 1830 | |
Christian Maaser | 43c207e6 | 2008-12-25 13:38:42 +0100 | [diff] [blame] | 1831 | static int __ap_poll_device(struct ap_device *ap_dev, unsigned long *flags) |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1832 | { |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1833 | if (!ap_dev->unregistered) { |
Ralph Wuerthner | c6a4826 | 2007-03-26 20:42:42 +0200 | [diff] [blame] | 1834 | if (ap_poll_queue(ap_dev, flags)) |
Ralph Wuerthner | 4e56296 | 2006-10-04 20:02:05 +0200 | [diff] [blame] | 1835 | ap_dev->unregistered = 1; |
Ralph Wuerthner | af512ed0 | 2007-07-10 11:24:19 +0200 | [diff] [blame] | 1836 | if (ap_dev->reset == AP_RESET_DO) |
| 1837 | ap_reset(ap_dev); |
Ralph Wuerthner | c6a4826 | 2007-03-26 20:42:42 +0200 | [diff] [blame] | 1838 | } |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1839 | return 0; |
| 1840 | } |
| 1841 | |
Felix Beck | 1749a81 | 2008-04-17 07:46:28 +0200 | [diff] [blame] | 1842 | /** |
| 1843 | * ap_poll_all(): Poll all AP devices. |
| 1844 | * @dummy: Unused variable |
| 1845 | * |
| 1846 | * Poll all AP devices on the bus in a round robin fashion. Continue |
| 1847 | * polling until bit 2^0 of the control flags is not set. If bit 2^1 |
| 1848 | * of the control flags has been set arm the poll timer. |
| 1849 | */ |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1850 | static void ap_poll_all(unsigned long dummy) |
| 1851 | { |
| 1852 | unsigned long flags; |
Ralph Wuerthner | cf352ce | 2007-03-19 13:19:14 +0100 | [diff] [blame] | 1853 | struct ap_device *ap_dev; |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1854 | |
Felix Beck | cb17a63 | 2008-12-25 13:38:41 +0100 | [diff] [blame] | 1855 | /* Reset the indicator if interrupts are used. Thus new interrupts can |
| 1856 | * be received. Doing it in the beginning of the tasklet is therefor |
| 1857 | * important that no requests on any AP get lost. |
| 1858 | */ |
| 1859 | if (ap_using_interrupts()) |
Martin Schwidefsky | f4eae94 | 2013-06-24 10:30:41 +0200 | [diff] [blame] | 1860 | xchg(ap_airq.lsi_ptr, 0); |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1861 | do { |
| 1862 | flags = 0; |
Christian Maaser | 43c207e6 | 2008-12-25 13:38:42 +0100 | [diff] [blame] | 1863 | spin_lock(&ap_device_list_lock); |
Ralph Wuerthner | cf352ce | 2007-03-19 13:19:14 +0100 | [diff] [blame] | 1864 | list_for_each_entry(ap_dev, &ap_device_list, list) { |
Felix Beck | 95f1556 | 2009-09-11 10:28:51 +0200 | [diff] [blame] | 1865 | spin_lock(&ap_dev->lock); |
Christian Maaser | 43c207e6 | 2008-12-25 13:38:42 +0100 | [diff] [blame] | 1866 | __ap_poll_device(ap_dev, &flags); |
Felix Beck | 95f1556 | 2009-09-11 10:28:51 +0200 | [diff] [blame] | 1867 | spin_unlock(&ap_dev->lock); |
Ralph Wuerthner | cf352ce | 2007-03-19 13:19:14 +0100 | [diff] [blame] | 1868 | } |
Christian Maaser | 43c207e6 | 2008-12-25 13:38:42 +0100 | [diff] [blame] | 1869 | spin_unlock(&ap_device_list_lock); |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1870 | } while (flags & 1); |
| 1871 | if (flags & 2) |
| 1872 | ap_schedule_poll_timer(); |
| 1873 | } |
| 1874 | |
| 1875 | /** |
Felix Beck | 1749a81 | 2008-04-17 07:46:28 +0200 | [diff] [blame] | 1876 | * ap_poll_thread(): Thread that polls for finished requests. |
| 1877 | * @data: Unused pointer |
| 1878 | * |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1879 | * AP bus poll thread. The purpose of this thread is to poll for |
| 1880 | * finished requests in a loop if there is a "free" cpu - that is |
| 1881 | * a cpu that doesn't have anything better to do. The polling stops |
| 1882 | * as soon as there is another task or if all messages have been |
| 1883 | * delivered. |
| 1884 | */ |
| 1885 | static int ap_poll_thread(void *data) |
| 1886 | { |
| 1887 | DECLARE_WAITQUEUE(wait, current); |
| 1888 | unsigned long flags; |
| 1889 | int requests; |
Ralph Wuerthner | cf352ce | 2007-03-19 13:19:14 +0100 | [diff] [blame] | 1890 | struct ap_device *ap_dev; |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1891 | |
Dongsheng Yang | 8698a74 | 2014-03-11 18:09:12 +0800 | [diff] [blame] | 1892 | set_user_nice(current, MAX_NICE); |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1893 | while (1) { |
Felix Beck | 772f547 | 2009-06-22 12:08:16 +0200 | [diff] [blame] | 1894 | if (ap_suspend_flag) |
| 1895 | return 0; |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1896 | if (need_resched()) { |
| 1897 | schedule(); |
| 1898 | continue; |
| 1899 | } |
| 1900 | add_wait_queue(&ap_poll_wait, &wait); |
| 1901 | set_current_state(TASK_INTERRUPTIBLE); |
| 1902 | if (kthread_should_stop()) |
| 1903 | break; |
| 1904 | requests = atomic_read(&ap_poll_requests); |
| 1905 | if (requests <= 0) |
| 1906 | schedule(); |
| 1907 | set_current_state(TASK_RUNNING); |
| 1908 | remove_wait_queue(&ap_poll_wait, &wait); |
| 1909 | |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1910 | flags = 0; |
Christian Maaser | 43c207e6 | 2008-12-25 13:38:42 +0100 | [diff] [blame] | 1911 | spin_lock_bh(&ap_device_list_lock); |
Ralph Wuerthner | cf352ce | 2007-03-19 13:19:14 +0100 | [diff] [blame] | 1912 | list_for_each_entry(ap_dev, &ap_device_list, list) { |
Felix Beck | 95f1556 | 2009-09-11 10:28:51 +0200 | [diff] [blame] | 1913 | spin_lock(&ap_dev->lock); |
Christian Maaser | 43c207e6 | 2008-12-25 13:38:42 +0100 | [diff] [blame] | 1914 | __ap_poll_device(ap_dev, &flags); |
Felix Beck | 95f1556 | 2009-09-11 10:28:51 +0200 | [diff] [blame] | 1915 | spin_unlock(&ap_dev->lock); |
Ralph Wuerthner | cf352ce | 2007-03-19 13:19:14 +0100 | [diff] [blame] | 1916 | } |
Christian Maaser | 43c207e6 | 2008-12-25 13:38:42 +0100 | [diff] [blame] | 1917 | spin_unlock_bh(&ap_device_list_lock); |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1918 | } |
| 1919 | set_current_state(TASK_RUNNING); |
| 1920 | remove_wait_queue(&ap_poll_wait, &wait); |
| 1921 | return 0; |
| 1922 | } |
| 1923 | |
| 1924 | static int ap_poll_thread_start(void) |
| 1925 | { |
| 1926 | int rc; |
| 1927 | |
Felix Beck | 772f547 | 2009-06-22 12:08:16 +0200 | [diff] [blame] | 1928 | if (ap_using_interrupts() || ap_suspend_flag) |
Felix Beck | cb17a63 | 2008-12-25 13:38:41 +0100 | [diff] [blame] | 1929 | return 0; |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1930 | mutex_lock(&ap_poll_thread_mutex); |
| 1931 | if (!ap_poll_kthread) { |
| 1932 | ap_poll_kthread = kthread_run(ap_poll_thread, NULL, "appoll"); |
Thomas Meyer | ba8da21 | 2013-06-01 11:51:13 +0200 | [diff] [blame] | 1933 | rc = PTR_RET(ap_poll_kthread); |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1934 | if (rc) |
| 1935 | ap_poll_kthread = NULL; |
| 1936 | } |
| 1937 | else |
| 1938 | rc = 0; |
| 1939 | mutex_unlock(&ap_poll_thread_mutex); |
| 1940 | return rc; |
| 1941 | } |
| 1942 | |
| 1943 | static void ap_poll_thread_stop(void) |
| 1944 | { |
| 1945 | mutex_lock(&ap_poll_thread_mutex); |
| 1946 | if (ap_poll_kthread) { |
| 1947 | kthread_stop(ap_poll_kthread); |
| 1948 | ap_poll_kthread = NULL; |
| 1949 | } |
| 1950 | mutex_unlock(&ap_poll_thread_mutex); |
| 1951 | } |
| 1952 | |
Ralph Wuerthner | af512ed0 | 2007-07-10 11:24:19 +0200 | [diff] [blame] | 1953 | /** |
Felix Beck | 1749a81 | 2008-04-17 07:46:28 +0200 | [diff] [blame] | 1954 | * ap_request_timeout(): Handling of request timeouts |
| 1955 | * @data: Holds the AP device. |
| 1956 | * |
| 1957 | * Handles request timeouts. |
Ralph Wuerthner | af512ed0 | 2007-07-10 11:24:19 +0200 | [diff] [blame] | 1958 | */ |
| 1959 | static void ap_request_timeout(unsigned long data) |
| 1960 | { |
| 1961 | struct ap_device *ap_dev = (struct ap_device *) data; |
| 1962 | |
Felix Beck | cb17a63 | 2008-12-25 13:38:41 +0100 | [diff] [blame] | 1963 | if (ap_dev->reset == AP_RESET_ARMED) { |
Ralph Wuerthner | af512ed0 | 2007-07-10 11:24:19 +0200 | [diff] [blame] | 1964 | ap_dev->reset = AP_RESET_DO; |
Felix Beck | cb17a63 | 2008-12-25 13:38:41 +0100 | [diff] [blame] | 1965 | |
| 1966 | if (ap_using_interrupts()) |
| 1967 | tasklet_schedule(&ap_tasklet); |
| 1968 | } |
Ralph Wuerthner | af512ed0 | 2007-07-10 11:24:19 +0200 | [diff] [blame] | 1969 | } |
| 1970 | |
Ralph Wuerthner | 13e742b | 2006-12-15 17:18:17 +0100 | [diff] [blame] | 1971 | static void ap_reset_domain(void) |
| 1972 | { |
| 1973 | int i; |
| 1974 | |
Ralph Wuerthner | 39aa7cf | 2007-10-12 16:11:29 +0200 | [diff] [blame] | 1975 | if (ap_domain_index != -1) |
| 1976 | for (i = 0; i < AP_DEVICES; i++) |
| 1977 | ap_reset_queue(AP_MKQID(i, ap_domain_index)); |
Ralph Wuerthner | 13e742b | 2006-12-15 17:18:17 +0100 | [diff] [blame] | 1978 | } |
| 1979 | |
| 1980 | static void ap_reset_all(void) |
Ralph Wuerthner | 85eca85 | 2006-12-08 15:54:07 +0100 | [diff] [blame] | 1981 | { |
| 1982 | int i, j; |
| 1983 | |
Ingo Tuchscherer | 170387a | 2014-09-08 13:24:13 +0200 | [diff] [blame] | 1984 | for (i = 0; i < AP_DOMAINS; i++) { |
| 1985 | if (!ap_test_config_domain(i)) |
| 1986 | continue; |
| 1987 | for (j = 0; j < AP_DEVICES; j++) { |
| 1988 | if (!ap_test_config_card_id(j)) |
| 1989 | continue; |
Ralph Wuerthner | 85eca85 | 2006-12-08 15:54:07 +0100 | [diff] [blame] | 1990 | ap_reset_queue(AP_MKQID(j, i)); |
Ingo Tuchscherer | 170387a | 2014-09-08 13:24:13 +0200 | [diff] [blame] | 1991 | } |
| 1992 | } |
Ralph Wuerthner | 85eca85 | 2006-12-08 15:54:07 +0100 | [diff] [blame] | 1993 | } |
| 1994 | |
| 1995 | static struct reset_call ap_reset_call = { |
Ralph Wuerthner | 13e742b | 2006-12-15 17:18:17 +0100 | [diff] [blame] | 1996 | .fn = ap_reset_all, |
Ralph Wuerthner | 85eca85 | 2006-12-08 15:54:07 +0100 | [diff] [blame] | 1997 | }; |
| 1998 | |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 1999 | /** |
Felix Beck | 1749a81 | 2008-04-17 07:46:28 +0200 | [diff] [blame] | 2000 | * ap_module_init(): The module initialization code. |
| 2001 | * |
| 2002 | * Initializes the module. |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 2003 | */ |
| 2004 | int __init ap_module_init(void) |
| 2005 | { |
| 2006 | int rc, i; |
| 2007 | |
| 2008 | if (ap_domain_index < -1 || ap_domain_index >= AP_DOMAINS) { |
Martin Schwidefsky | 136f7a1 | 2008-12-25 13:39:46 +0100 | [diff] [blame] | 2009 | pr_warning("%d is not a valid cryptographic domain\n", |
| 2010 | ap_domain_index); |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 2011 | return -EINVAL; |
| 2012 | } |
Felix Beck | 5314af6 | 2009-09-22 22:58:51 +0200 | [diff] [blame] | 2013 | /* In resume callback we need to know if the user had set the domain. |
| 2014 | * If so, we can not just reset it. |
| 2015 | */ |
| 2016 | if (ap_domain_index >= 0) |
| 2017 | user_set_domain = 1; |
| 2018 | |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 2019 | if (ap_instructions_available() != 0) { |
Martin Schwidefsky | 136f7a1 | 2008-12-25 13:39:46 +0100 | [diff] [blame] | 2020 | pr_warning("The hardware system does not support " |
| 2021 | "AP instructions\n"); |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 2022 | return -ENODEV; |
| 2023 | } |
Felix Beck | cb17a63 | 2008-12-25 13:38:41 +0100 | [diff] [blame] | 2024 | if (ap_interrupts_available()) { |
Martin Schwidefsky | f4eae94 | 2013-06-24 10:30:41 +0200 | [diff] [blame] | 2025 | rc = register_adapter_interrupt(&ap_airq); |
| 2026 | ap_airq_flag = (rc == 0); |
Felix Beck | cb17a63 | 2008-12-25 13:38:41 +0100 | [diff] [blame] | 2027 | } |
| 2028 | |
Ralph Wuerthner | 85eca85 | 2006-12-08 15:54:07 +0100 | [diff] [blame] | 2029 | register_reset_call(&ap_reset_call); |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 2030 | |
| 2031 | /* Create /sys/bus/ap. */ |
| 2032 | rc = bus_register(&ap_bus_type); |
| 2033 | if (rc) |
| 2034 | goto out; |
| 2035 | for (i = 0; ap_bus_attrs[i]; i++) { |
| 2036 | rc = bus_create_file(&ap_bus_type, ap_bus_attrs[i]); |
| 2037 | if (rc) |
| 2038 | goto out_bus; |
| 2039 | } |
| 2040 | |
| 2041 | /* Create /sys/devices/ap. */ |
Mark McLoughlin | 035da16 | 2008-12-15 12:58:29 +0000 | [diff] [blame] | 2042 | ap_root_device = root_device_register("ap"); |
Thomas Meyer | ba8da21 | 2013-06-01 11:51:13 +0200 | [diff] [blame] | 2043 | rc = PTR_RET(ap_root_device); |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 2044 | if (rc) |
| 2045 | goto out_bus; |
| 2046 | |
| 2047 | ap_work_queue = create_singlethread_workqueue("kapwork"); |
| 2048 | if (!ap_work_queue) { |
| 2049 | rc = -ENOMEM; |
| 2050 | goto out_root; |
| 2051 | } |
| 2052 | |
Holger Dengler | 7501455 | 2012-08-28 16:41:50 +0200 | [diff] [blame] | 2053 | ap_query_configuration(); |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 2054 | if (ap_select_domain() == 0) |
| 2055 | ap_scan_bus(NULL); |
| 2056 | |
Felix Beck | 1749a81 | 2008-04-17 07:46:28 +0200 | [diff] [blame] | 2057 | /* Setup the AP bus rescan timer. */ |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 2058 | init_timer(&ap_config_timer); |
| 2059 | ap_config_timer.function = ap_config_timeout; |
| 2060 | ap_config_timer.data = 0; |
| 2061 | ap_config_timer.expires = jiffies + ap_config_time * HZ; |
| 2062 | add_timer(&ap_config_timer); |
| 2063 | |
Felix Beck | fe13723 | 2008-07-14 09:59:08 +0200 | [diff] [blame] | 2064 | /* Setup the high resultion poll timer. |
| 2065 | * If we are running under z/VM adjust polling to z/VM polling rate. |
| 2066 | */ |
| 2067 | if (MACHINE_IS_VM) |
| 2068 | poll_timeout = 1500000; |
Felix Beck | 9352131 | 2009-12-07 12:52:00 +0100 | [diff] [blame] | 2069 | spin_lock_init(&ap_poll_timer_lock); |
Felix Beck | fe13723 | 2008-07-14 09:59:08 +0200 | [diff] [blame] | 2070 | hrtimer_init(&ap_poll_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS); |
| 2071 | ap_poll_timer.function = ap_poll_timeout; |
| 2072 | |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 2073 | /* Start the low priority AP bus poll thread. */ |
| 2074 | if (ap_thread_flag) { |
| 2075 | rc = ap_poll_thread_start(); |
| 2076 | if (rc) |
| 2077 | goto out_work; |
| 2078 | } |
| 2079 | |
| 2080 | return 0; |
| 2081 | |
| 2082 | out_work: |
| 2083 | del_timer_sync(&ap_config_timer); |
Felix Beck | fe13723 | 2008-07-14 09:59:08 +0200 | [diff] [blame] | 2084 | hrtimer_cancel(&ap_poll_timer); |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 2085 | destroy_workqueue(ap_work_queue); |
| 2086 | out_root: |
Mark McLoughlin | 035da16 | 2008-12-15 12:58:29 +0000 | [diff] [blame] | 2087 | root_device_unregister(ap_root_device); |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 2088 | out_bus: |
| 2089 | while (i--) |
| 2090 | bus_remove_file(&ap_bus_type, ap_bus_attrs[i]); |
| 2091 | bus_unregister(&ap_bus_type); |
| 2092 | out: |
Ralph Wuerthner | 85eca85 | 2006-12-08 15:54:07 +0100 | [diff] [blame] | 2093 | unregister_reset_call(&ap_reset_call); |
Martin Schwidefsky | f4eae94 | 2013-06-24 10:30:41 +0200 | [diff] [blame] | 2094 | if (ap_using_interrupts()) |
| 2095 | unregister_adapter_interrupt(&ap_airq); |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 2096 | return rc; |
| 2097 | } |
| 2098 | |
| 2099 | static int __ap_match_all(struct device *dev, void *data) |
| 2100 | { |
| 2101 | return 1; |
| 2102 | } |
| 2103 | |
| 2104 | /** |
Felix Beck | 1749a81 | 2008-04-17 07:46:28 +0200 | [diff] [blame] | 2105 | * ap_modules_exit(): The module termination code |
| 2106 | * |
| 2107 | * Terminates the module. |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 2108 | */ |
| 2109 | void ap_module_exit(void) |
| 2110 | { |
| 2111 | int i; |
| 2112 | struct device *dev; |
| 2113 | |
Ralph Wuerthner | 13e742b | 2006-12-15 17:18:17 +0100 | [diff] [blame] | 2114 | ap_reset_domain(); |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 2115 | ap_poll_thread_stop(); |
| 2116 | del_timer_sync(&ap_config_timer); |
Felix Beck | fe13723 | 2008-07-14 09:59:08 +0200 | [diff] [blame] | 2117 | hrtimer_cancel(&ap_poll_timer); |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 2118 | destroy_workqueue(ap_work_queue); |
Ralph Wuerthner | 13e742b | 2006-12-15 17:18:17 +0100 | [diff] [blame] | 2119 | tasklet_kill(&ap_tasklet); |
Mark McLoughlin | 035da16 | 2008-12-15 12:58:29 +0000 | [diff] [blame] | 2120 | root_device_unregister(ap_root_device); |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 2121 | while ((dev = bus_find_device(&ap_bus_type, NULL, NULL, |
| 2122 | __ap_match_all))) |
| 2123 | { |
| 2124 | device_unregister(dev); |
| 2125 | put_device(dev); |
| 2126 | } |
| 2127 | for (i = 0; ap_bus_attrs[i]; i++) |
| 2128 | bus_remove_file(&ap_bus_type, ap_bus_attrs[i]); |
| 2129 | bus_unregister(&ap_bus_type); |
Ralph Wuerthner | 85eca85 | 2006-12-08 15:54:07 +0100 | [diff] [blame] | 2130 | unregister_reset_call(&ap_reset_call); |
Martin Schwidefsky | f4eae94 | 2013-06-24 10:30:41 +0200 | [diff] [blame] | 2131 | if (ap_using_interrupts()) |
| 2132 | unregister_adapter_interrupt(&ap_airq); |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 2133 | } |
| 2134 | |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 2135 | module_init(ap_module_init); |
| 2136 | module_exit(ap_module_exit); |