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