blob: 658626039171b9e3235cfce06924a23496812108 [file] [log] [blame]
Greg Kroah-Hartman812141a2017-11-14 18:38:01 +01001// SPDX-License-Identifier: GPL-2.0+
Martin Schwidefsky1534c382006-09-20 15:58:25 +02002/*
Holger Dengler75014552012-08-28 16:41:50 +02003 * Copyright IBM Corp. 2006, 2012
Martin Schwidefsky1534c382006-09-20 15:58:25 +02004 * Author(s): Cornelia Huck <cornelia.huck@de.ibm.com>
5 * Martin Schwidefsky <schwidefsky@de.ibm.com>
6 * Ralph Wuerthner <rwuerthn@de.ibm.com>
Felix Beckcb17a632008-12-25 13:38:41 +01007 * Felix Beck <felix.beck@de.ibm.com>
Holger Dengler6bed05b2011-07-24 10:48:25 +02008 * Holger Dengler <hd@linux.vnet.ibm.com>
Martin Schwidefsky1534c382006-09-20 15:58:25 +02009 *
10 * Adjunct processor bus.
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2, or (at your option)
15 * any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 */
26
Martin Schwidefsky136f7a12008-12-25 13:39:46 +010027#define KMSG_COMPONENT "ap"
28#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
29
Holger Dengler62d146f2011-01-05 12:47:38 +010030#include <linux/kernel_stat.h>
Paul Gortmaker50a0d462017-02-09 09:48:10 -050031#include <linux/moduleparam.h>
Martin Schwidefsky1534c382006-09-20 15:58:25 +020032#include <linux/init.h>
33#include <linux/delay.h>
34#include <linux/err.h>
35#include <linux/interrupt.h>
36#include <linux/workqueue.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090037#include <linux/slab.h>
Martin Schwidefsky1534c382006-09-20 15:58:25 +020038#include <linux/notifier.h>
39#include <linux/kthread.h>
40#include <linux/mutex.h>
Martin Schwidefsky83e9d5d2015-07-17 13:43:18 +020041#include <linux/suspend.h>
Ralph Wuerthner85eca852006-12-08 15:54:07 +010042#include <asm/reset.h>
Felix Beckcb17a632008-12-25 13:38:41 +010043#include <asm/airq.h>
Arun Sharma600634972011-07-26 16:09:06 -070044#include <linux/atomic.h>
Felix Beckcb17a632008-12-25 13:38:41 +010045#include <asm/isc.h>
Felix Beckfe137232008-07-14 09:59:08 +020046#include <linux/hrtimer.h>
47#include <linux/ktime.h>
David Howellsa0616cd2012-03-28 18:30:02 +010048#include <asm/facility.h>
Kees Cook5d26a102014-11-20 17:05:53 -080049#include <linux/crypto.h>
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +020050#include <linux/mod_devicetable.h>
Harald Freudenbergercccd85b2016-11-24 06:45:21 +010051#include <linux/debugfs.h>
Martin Schwidefsky1534c382006-09-20 15:58:25 +020052
53#include "ap_bus.h"
Martin Schwidefsky0db78552016-09-21 12:48:54 +020054#include "ap_asm.h"
Harald Freudenbergercccd85b2016-11-24 06:45:21 +010055#include "ap_debug.h"
Martin Schwidefsky1534c382006-09-20 15:58:25 +020056
Felix Beck1749a812008-04-17 07:46:28 +020057/*
Paul Gortmaker50a0d462017-02-09 09:48:10 -050058 * Module parameters; note though this file itself isn't modular.
Martin Schwidefsky1534c382006-09-20 15:58:25 +020059 */
60int ap_domain_index = -1; /* Adjunct Processor Domain Index */
Ingo Tuchschererfc1d3f02016-08-25 11:11:30 +020061static DEFINE_SPINLOCK(ap_domain_lock);
Michael Veigelc1a42f42014-04-14 14:28:27 +020062module_param_named(domain, ap_domain_index, int, S_IRUSR|S_IRGRP);
Martin Schwidefsky1534c382006-09-20 15:58:25 +020063MODULE_PARM_DESC(domain, "domain index for ap devices");
64EXPORT_SYMBOL(ap_domain_index);
65
Felix Beckb90b34c2008-02-09 18:24:30 +010066static int ap_thread_flag = 0;
Michael Veigelc1a42f42014-04-14 14:28:27 +020067module_param_named(poll_thread, ap_thread_flag, int, S_IRUSR|S_IRGRP);
Felix Beckb90b34c2008-02-09 18:24:30 +010068MODULE_PARM_DESC(poll_thread, "Turn on/off poll thread, default is 0 (off).");
Martin Schwidefsky1534c382006-09-20 15:58:25 +020069
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +020070static struct device *ap_root_device;
71
72DEFINE_SPINLOCK(ap_list_lock);
73LIST_HEAD(ap_card_list);
74
Holger Dengler75014552012-08-28 16:41:50 +020075static struct ap_config_info *ap_configuration;
Sascha Silbee3877532015-10-27 18:29:52 +010076static bool initialised;
Martin Schwidefsky1534c382006-09-20 15:58:25 +020077
Felix Beck1749a812008-04-17 07:46:28 +020078/*
Harald Freudenbergercccd85b2016-11-24 06:45:21 +010079 * AP bus related debug feature things.
80 */
Harald Freudenbergercccd85b2016-11-24 06:45:21 +010081debug_info_t *ap_dbf_info;
82
83/*
Martin Schwidefsky8139b892015-07-27 12:47:40 +020084 * Workqueue timer for bus rescan.
Martin Schwidefsky1534c382006-09-20 15:58:25 +020085 */
Martin Schwidefsky1534c382006-09-20 15:58:25 +020086static struct timer_list ap_config_timer;
87static int ap_config_time = AP_CONFIG_TIME;
Martin Schwidefsky3f3007a2015-09-14 17:01:23 +020088static void ap_scan_bus(struct work_struct *);
Martin Schwidefsky8139b892015-07-27 12:47:40 +020089static DECLARE_WORK(ap_scan_work, ap_scan_bus);
Martin Schwidefsky1534c382006-09-20 15:58:25 +020090
Felix Beck1749a812008-04-17 07:46:28 +020091/*
Felix Beckcb17a632008-12-25 13:38:41 +010092 * Tasklet & timer for AP request polling and interrupts
Martin Schwidefsky1534c382006-09-20 15:58:25 +020093 */
Martin Schwidefsky3f3007a2015-09-14 17:01:23 +020094static void ap_tasklet_fn(unsigned long);
95static DECLARE_TASKLET(ap_tasklet, ap_tasklet_fn, 0);
Martin Schwidefsky1534c382006-09-20 15:58:25 +020096static DECLARE_WAIT_QUEUE_HEAD(ap_poll_wait);
97static struct task_struct *ap_poll_kthread = NULL;
98static DEFINE_MUTEX(ap_poll_thread_mutex);
Felix Beck93521312009-12-07 12:52:00 +010099static DEFINE_SPINLOCK(ap_poll_timer_lock);
Felix Beckfe137232008-07-14 09:59:08 +0200100static struct hrtimer ap_poll_timer;
101/* In LPAR poll with 4kHz frequency. Poll every 250000 nanoseconds.
102 * If z/VM change to 1500000 nanoseconds to adjust to z/VM polling.*/
103static unsigned long long poll_timeout = 250000;
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200104
Felix Beck772f5472009-06-22 12:08:16 +0200105/* Suspend flag */
106static int ap_suspend_flag;
Martin Schwidefsky889875a2015-06-26 16:55:35 +0200107/* Maximum domain id */
108static int ap_max_domain_id;
Felix Beck5314af62009-09-22 22:58:51 +0200109/* Flag to check if domain was set through module parameter domain=. This is
110 * important when supsend and resume is done in a z/VM environment where the
111 * domain might change. */
112static int user_set_domain = 0;
Felix Beck772f5472009-06-22 12:08:16 +0200113static struct bus_type ap_bus_type;
114
Martin Schwidefskyf4eae942013-06-24 10:30:41 +0200115/* Adapter interrupt definitions */
Martin Schwidefsky3f3007a2015-09-14 17:01:23 +0200116static void ap_interrupt_handler(struct airq_struct *airq);
117
Martin Schwidefskyf4eae942013-06-24 10:30:41 +0200118static int ap_airq_flag;
119
120static struct airq_struct ap_airq = {
121 .handler = ap_interrupt_handler,
122 .isc = AP_ISC,
123};
124
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200125/**
Felix Beckcb17a632008-12-25 13:38:41 +0100126 * ap_using_interrupts() - Returns non-zero if interrupt support is
127 * available.
128 */
129static inline int ap_using_interrupts(void)
130{
Martin Schwidefskyf4eae942013-06-24 10:30:41 +0200131 return ap_airq_flag;
Felix Beckcb17a632008-12-25 13:38:41 +0100132}
133
134/**
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +0200135 * ap_airq_ptr() - Get the address of the adapter interrupt indicator
136 *
137 * Returns the address of the local-summary-indicator of the adapter
138 * interrupt handler for AP, or NULL if adapter interrupts are not
139 * available.
140 */
141void *ap_airq_ptr(void)
142{
143 if (ap_using_interrupts())
144 return ap_airq.lsi_ptr;
145 return NULL;
146}
147
148/**
Felix Beckcb17a632008-12-25 13:38:41 +0100149 * ap_interrupts_available(): Test if AP interrupts are available.
150 *
151 * Returns 1 if AP interrupts are available.
152 */
153static int ap_interrupts_available(void)
154{
Heiko Carstens86cd7412015-02-14 11:23:21 +0100155 return test_facility(65);
Felix Beckcb17a632008-12-25 13:38:41 +0100156}
157
158/**
Holger Dengler75014552012-08-28 16:41:50 +0200159 * ap_configuration_available(): Test if AP configuration
160 * information is available.
161 *
162 * Returns 1 if AP configuration information is available.
163 */
164static int ap_configuration_available(void)
165{
Heiko Carstens86cd7412015-02-14 11:23:21 +0100166 return test_facility(12);
Holger Dengler75014552012-08-28 16:41:50 +0200167}
168
169/**
Tony Krowiake7fc5142016-11-08 07:09:13 +0100170 * ap_apft_available(): Test if AP facilities test (APFT)
171 * facility is available.
172 *
173 * Returns 1 if APFT is is available.
174 */
175static int ap_apft_available(void)
176{
177 return test_facility(15);
178}
179
Harald Freudenberger9a564102017-10-16 12:28:35 +0200180/*
181 * ap_qact_available(): Test if the PQAP(QACT) subfunction is available.
182 *
183 * Returns 1 if the QACT subfunction is available.
184 */
185static inline int ap_qact_available(void)
186{
187 if (ap_configuration)
188 return ap_configuration->qact;
189 return 0;
190}
191
Tony Krowiake7fc5142016-11-08 07:09:13 +0100192/**
Felix Beck1749a812008-04-17 07:46:28 +0200193 * ap_test_queue(): Test adjunct processor queue.
194 * @qid: The AP queue number
Tony Krowiake7fc5142016-11-08 07:09:13 +0100195 * @tbit: Test facilities bit
Martin Schwidefsky6acbe212015-06-26 15:40:41 +0200196 * @info: Pointer to queue descriptor
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200197 *
Felix Beck1749a812008-04-17 07:46:28 +0200198 * Returns AP queue status structure.
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200199 */
Tony Krowiake7fc5142016-11-08 07:09:13 +0100200struct ap_queue_status ap_test_queue(ap_qid_t qid,
201 int tbit,
202 unsigned long *info)
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200203{
Tony Krowiake7fc5142016-11-08 07:09:13 +0100204 if (tbit)
205 qid |= 1UL << 23; /* set T bit*/
Martin Schwidefsky0db78552016-09-21 12:48:54 +0200206 return ap_tapq(qid, info);
Holger Dengler75014552012-08-28 16:41:50 +0200207}
Tony Krowiake7fc5142016-11-08 07:09:13 +0100208EXPORT_SYMBOL(ap_test_queue);
Holger Dengler75014552012-08-28 16:41:50 +0200209
Harald Freudenberger050349b2016-11-08 11:54:28 +0100210/*
211 * ap_query_configuration(): Fetch cryptographic config info
212 *
213 * Returns the ap configuration info fetched via PQAP(QCI).
214 * On success 0 is returned, on failure a negative errno
215 * is returned, e.g. if the PQAP(QCI) instruction is not
216 * available, the return value will be -EOPNOTSUPP.
217 */
218int ap_query_configuration(struct ap_config_info *info)
Heiko Carstens11d37672016-06-20 14:00:27 +0200219{
Harald Freudenberger050349b2016-11-08 11:54:28 +0100220 if (!ap_configuration_available())
Heiko Carstens11d37672016-06-20 14:00:27 +0200221 return -EOPNOTSUPP;
Harald Freudenberger050349b2016-11-08 11:54:28 +0100222 if (!info)
223 return -EINVAL;
224 return ap_qci(info);
Heiko Carstens11d37672016-06-20 14:00:27 +0200225}
Harald Freudenberger050349b2016-11-08 11:54:28 +0100226EXPORT_SYMBOL(ap_query_configuration);
Heiko Carstens11d37672016-06-20 14:00:27 +0200227
Holger Dengler6bed05b2011-07-24 10:48:25 +0200228/**
Martin Schwidefsky889875a2015-06-26 16:55:35 +0200229 * ap_init_configuration(): Allocate and query configuration array.
230 */
231static void ap_init_configuration(void)
232{
233 if (!ap_configuration_available())
234 return;
235
236 ap_configuration = kzalloc(sizeof(*ap_configuration), GFP_KERNEL);
237 if (!ap_configuration)
238 return;
Harald Freudenberger050349b2016-11-08 11:54:28 +0100239 if (ap_query_configuration(ap_configuration) != 0) {
Martin Schwidefsky889875a2015-06-26 16:55:35 +0200240 kfree(ap_configuration);
241 ap_configuration = NULL;
242 return;
243 }
244}
245
246/*
247 * ap_test_config(): helper function to extract the nrth bit
248 * within the unsigned int array field.
249 */
250static inline int ap_test_config(unsigned int *field, unsigned int nr)
251{
252 return ap_test_bit((field + (nr >> 5)), (nr & 0x1f));
253}
254
255/*
256 * ap_test_config_card_id(): Test, whether an AP card ID is configured.
257 * @id AP card ID
258 *
259 * Returns 0 if the card is not configured
260 * 1 if the card is configured or
261 * if the configuration information is not available
262 */
263static inline int ap_test_config_card_id(unsigned int id)
264{
265 if (!ap_configuration) /* QCI not supported */
266 return 1;
267 return ap_test_config(ap_configuration->apm, id);
268}
269
270/*
271 * ap_test_config_domain(): Test, whether an AP usage domain is configured.
272 * @domain AP usage domain ID
273 *
274 * Returns 0 if the usage domain is not configured
275 * 1 if the usage domain is configured or
276 * if the configuration information is not available
277 */
278static inline int ap_test_config_domain(unsigned int domain)
279{
280 if (!ap_configuration) /* QCI not supported */
281 return domain < 16;
282 return ap_test_config(ap_configuration->aqm, domain);
283}
284
285/**
Felix Beck1749a812008-04-17 07:46:28 +0200286 * ap_query_queue(): Check if an AP queue is available.
287 * @qid: The AP queue number
288 * @queue_depth: Pointer to queue depth value
289 * @device_type: Pointer to device type value
Martin Schwidefsky6acbe212015-06-26 15:40:41 +0200290 * @facilities: Pointer to facility indicator
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200291 */
Martin Schwidefsky6acbe212015-06-26 15:40:41 +0200292static int ap_query_queue(ap_qid_t qid, int *queue_depth, int *device_type,
293 unsigned int *facilities)
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200294{
295 struct ap_queue_status status;
Martin Schwidefsky6acbe212015-06-26 15:40:41 +0200296 unsigned long info;
Martin Schwidefsky889875a2015-06-26 16:55:35 +0200297 int nd;
298
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +0200299 if (!ap_test_config_card_id(AP_QID_CARD(qid)))
Martin Schwidefsky889875a2015-06-26 16:55:35 +0200300 return -ENODEV;
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200301
Tony Krowiake7fc5142016-11-08 07:09:13 +0100302 status = ap_test_queue(qid, ap_apft_available(), &info);
Ingo Tuchschererc50a1602015-06-17 16:19:15 +0200303 switch (status.response_code) {
304 case AP_RESPONSE_NORMAL:
Martin Schwidefsky6acbe212015-06-26 15:40:41 +0200305 *queue_depth = (int)(info & 0xff);
306 *device_type = (int)((info >> 24) & 0xff);
307 *facilities = (unsigned int)(info >> 32);
Martin Schwidefsky889875a2015-06-26 16:55:35 +0200308 /* Update maximum domain id */
309 nd = (info >> 16) & 0xff;
Ingo Tuchschererc1c13682016-11-02 10:23:24 +0100310 /* if N bit is available, z13 and newer */
Martin Schwidefsky889875a2015-06-26 16:55:35 +0200311 if ((info & (1UL << 57)) && nd > 0)
312 ap_max_domain_id = nd;
Ingo Tuchschererc1c13682016-11-02 10:23:24 +0100313 else /* older machine types */
314 ap_max_domain_id = 15;
Harald Freudenberger14878422016-10-27 08:57:39 +0200315 switch (*device_type) {
316 /* For CEX2 and CEX3 the available functions
317 * are not refrected by the facilities bits.
318 * Instead it is coded into the type. So here
319 * modify the function bits based on the type.
320 */
321 case AP_DEVICE_TYPE_CEX2A:
322 case AP_DEVICE_TYPE_CEX3A:
323 *facilities |= 0x08000000;
324 break;
325 case AP_DEVICE_TYPE_CEX2C:
326 case AP_DEVICE_TYPE_CEX3C:
327 *facilities |= 0x10000000;
328 break;
329 default:
330 break;
331 }
Ingo Tuchschererc50a1602015-06-17 16:19:15 +0200332 return 0;
333 case AP_RESPONSE_Q_NOT_AVAIL:
334 case AP_RESPONSE_DECONFIGURED:
335 case AP_RESPONSE_CHECKSTOPPED:
336 case AP_RESPONSE_INVALID_ADDRESS:
337 return -ENODEV;
338 case AP_RESPONSE_RESET_IN_PROGRESS:
339 case AP_RESPONSE_OTHERWISE_CHANGED:
340 case AP_RESPONSE_BUSY:
341 return -EBUSY;
342 default:
343 BUG();
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200344 }
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200345}
346
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +0200347void ap_wait(enum ap_wait wait)
Martin Schwidefsky3f3007a2015-09-14 17:01:23 +0200348{
349 ktime_t hr_time;
350
351 switch (wait) {
352 case AP_WAIT_AGAIN:
353 case AP_WAIT_INTERRUPT:
354 if (ap_using_interrupts())
355 break;
356 if (ap_poll_kthread) {
357 wake_up(&ap_poll_wait);
358 break;
359 }
360 /* Fall through */
361 case AP_WAIT_TIMEOUT:
362 spin_lock_bh(&ap_poll_timer_lock);
363 if (!hrtimer_is_queued(&ap_poll_timer)) {
Thomas Gleixner8b0e1952016-12-25 12:30:41 +0100364 hr_time = poll_timeout;
Martin Schwidefsky3f3007a2015-09-14 17:01:23 +0200365 hrtimer_forward_now(&ap_poll_timer, hr_time);
366 hrtimer_restart(&ap_poll_timer);
367 }
368 spin_unlock_bh(&ap_poll_timer_lock);
369 break;
370 case AP_WAIT_NONE:
371 default:
372 break;
373 }
374}
375
Martin Schwidefsky3f3007a2015-09-14 17:01:23 +0200376/**
377 * ap_request_timeout(): Handling of request timeouts
Kees Cookcefbeb52017-10-25 03:27:37 -0700378 * @t: timer making this callback
Martin Schwidefsky3f3007a2015-09-14 17:01:23 +0200379 *
380 * Handles request timeouts.
381 */
Kees Cookcefbeb52017-10-25 03:27:37 -0700382void ap_request_timeout(struct timer_list *t)
Martin Schwidefsky3f3007a2015-09-14 17:01:23 +0200383{
Kees Cookcefbeb52017-10-25 03:27:37 -0700384 struct ap_queue *aq = from_timer(aq, t, timeout);
Martin Schwidefsky3f3007a2015-09-14 17:01:23 +0200385
386 if (ap_suspend_flag)
387 return;
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +0200388 spin_lock_bh(&aq->lock);
389 ap_wait(ap_sm_event(aq, AP_EVENT_TIMEOUT));
390 spin_unlock_bh(&aq->lock);
Martin Schwidefsky3f3007a2015-09-14 17:01:23 +0200391}
392
393/**
394 * ap_poll_timeout(): AP receive polling for finished AP requests.
395 * @unused: Unused pointer.
396 *
397 * Schedules the AP tasklet using a high resolution timer.
398 */
399static enum hrtimer_restart ap_poll_timeout(struct hrtimer *unused)
400{
401 if (!ap_suspend_flag)
402 tasklet_schedule(&ap_tasklet);
403 return HRTIMER_NORESTART;
404}
405
406/**
407 * ap_interrupt_handler() - Schedule ap_tasklet on interrupt
408 * @airq: pointer to adapter interrupt descriptor
409 */
410static void ap_interrupt_handler(struct airq_struct *airq)
411{
412 inc_irq_stat(IRQIO_APB);
413 if (!ap_suspend_flag)
414 tasklet_schedule(&ap_tasklet);
415}
416
417/**
418 * ap_tasklet_fn(): Tasklet to poll all AP devices.
419 * @dummy: Unused variable
420 *
421 * Poll all AP devices on the bus.
422 */
423static void ap_tasklet_fn(unsigned long dummy)
424{
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +0200425 struct ap_card *ac;
426 struct ap_queue *aq;
Martin Schwidefsky3f3007a2015-09-14 17:01:23 +0200427 enum ap_wait wait = AP_WAIT_NONE;
428
429 /* Reset the indicator if interrupts are used. Thus new interrupts can
430 * be received. Doing it in the beginning of the tasklet is therefor
431 * important that no requests on any AP get lost.
432 */
433 if (ap_using_interrupts())
434 xchg(ap_airq.lsi_ptr, 0);
435
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +0200436 spin_lock_bh(&ap_list_lock);
437 for_each_ap_card(ac) {
438 for_each_ap_queue(aq, ac) {
439 spin_lock_bh(&aq->lock);
440 wait = min(wait, ap_sm_event_loop(aq, AP_EVENT_POLL));
441 spin_unlock_bh(&aq->lock);
442 }
Martin Schwidefsky3f3007a2015-09-14 17:01:23 +0200443 }
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +0200444 spin_unlock_bh(&ap_list_lock);
445
446 ap_wait(wait);
Ralph Wuerthneraf512ed02007-07-10 11:24:19 +0200447}
448
Martin Schwidefsky9af3e042016-09-21 14:12:53 +0200449static int ap_pending_requests(void)
450{
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +0200451 struct ap_card *ac;
452 struct ap_queue *aq;
Martin Schwidefsky9af3e042016-09-21 14:12:53 +0200453
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +0200454 spin_lock_bh(&ap_list_lock);
455 for_each_ap_card(ac) {
456 for_each_ap_queue(aq, ac) {
457 if (aq->queue_count == 0)
458 continue;
459 spin_unlock_bh(&ap_list_lock);
460 return 1;
Martin Schwidefsky9af3e042016-09-21 14:12:53 +0200461 }
Martin Schwidefsky9af3e042016-09-21 14:12:53 +0200462 }
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +0200463 spin_unlock_bh(&ap_list_lock);
464 return 0;
Martin Schwidefsky9af3e042016-09-21 14:12:53 +0200465}
466
Martin Schwidefsky83e9d5d2015-07-17 13:43:18 +0200467/**
468 * ap_poll_thread(): Thread that polls for finished requests.
469 * @data: Unused pointer
470 *
471 * AP bus poll thread. The purpose of this thread is to poll for
472 * finished requests in a loop if there is a "free" cpu - that is
473 * a cpu that doesn't have anything better to do. The polling stops
474 * as soon as there is another task or if all messages have been
475 * delivered.
476 */
477static int ap_poll_thread(void *data)
478{
479 DECLARE_WAITQUEUE(wait, current);
Martin Schwidefsky83e9d5d2015-07-17 13:43:18 +0200480
481 set_user_nice(current, MAX_NICE);
482 set_freezable();
483 while (!kthread_should_stop()) {
484 add_wait_queue(&ap_poll_wait, &wait);
485 set_current_state(TASK_INTERRUPTIBLE);
Martin Schwidefsky9af3e042016-09-21 14:12:53 +0200486 if (ap_suspend_flag || !ap_pending_requests()) {
Martin Schwidefsky83e9d5d2015-07-17 13:43:18 +0200487 schedule();
488 try_to_freeze();
489 }
490 set_current_state(TASK_RUNNING);
491 remove_wait_queue(&ap_poll_wait, &wait);
Martin Schwidefsky83e9d5d2015-07-17 13:43:18 +0200492 if (need_resched()) {
493 schedule();
494 try_to_freeze();
495 continue;
496 }
Martin Schwidefsky3f3007a2015-09-14 17:01:23 +0200497 ap_tasklet_fn(0);
Martin Schwidefsky9af3e042016-09-21 14:12:53 +0200498 }
499
Martin Schwidefsky83e9d5d2015-07-17 13:43:18 +0200500 return 0;
501}
502
503static int ap_poll_thread_start(void)
504{
505 int rc;
506
507 if (ap_using_interrupts() || ap_poll_kthread)
508 return 0;
509 mutex_lock(&ap_poll_thread_mutex);
510 ap_poll_kthread = kthread_run(ap_poll_thread, NULL, "appoll");
511 rc = PTR_RET(ap_poll_kthread);
512 if (rc)
513 ap_poll_kthread = NULL;
514 mutex_unlock(&ap_poll_thread_mutex);
515 return rc;
516}
517
518static void ap_poll_thread_stop(void)
519{
520 if (!ap_poll_kthread)
521 return;
522 mutex_lock(&ap_poll_thread_mutex);
523 kthread_stop(ap_poll_kthread);
524 ap_poll_kthread = NULL;
525 mutex_unlock(&ap_poll_thread_mutex);
526}
527
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +0200528#define is_card_dev(x) ((x)->parent == ap_root_device)
529#define is_queue_dev(x) ((x)->parent != ap_root_device)
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200530
531/**
Felix Beck1749a812008-04-17 07:46:28 +0200532 * ap_bus_match()
533 * @dev: Pointer to device
534 * @drv: Pointer to device_driver
535 *
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200536 * AP bus driver registration/unregistration.
537 */
538static int ap_bus_match(struct device *dev, struct device_driver *drv)
539{
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200540 struct ap_driver *ap_drv = to_ap_drv(drv);
541 struct ap_device_id *id;
542
Felix Beck1749a812008-04-17 07:46:28 +0200543 /*
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200544 * Compare device type of the device with the list of
545 * supported types of the device_driver.
546 */
547 for (id = ap_drv->ids; id->match_flags; id++) {
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +0200548 if (is_card_dev(dev) &&
549 id->match_flags & AP_DEVICE_ID_MATCH_CARD_TYPE &&
550 id->dev_type == to_ap_dev(dev)->device_type)
551 return 1;
552 if (is_queue_dev(dev) &&
553 id->match_flags & AP_DEVICE_ID_MATCH_QUEUE_TYPE &&
554 id->dev_type == to_ap_dev(dev)->device_type)
555 return 1;
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200556 }
557 return 0;
558}
559
560/**
Felix Beck1749a812008-04-17 07:46:28 +0200561 * ap_uevent(): Uevent function for AP devices.
562 * @dev: Pointer to device
563 * @env: Pointer to kobj_uevent_env
564 *
565 * It sets up a single environment variable DEV_TYPE which contains the
566 * hardware device type.
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200567 */
Kay Sievers7eff2e72007-08-14 15:15:12 +0200568static int ap_uevent (struct device *dev, struct kobj_uevent_env *env)
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200569{
570 struct ap_device *ap_dev = to_ap_dev(dev);
Kay Sievers7eff2e72007-08-14 15:15:12 +0200571 int retval = 0;
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200572
573 if (!ap_dev)
574 return -ENODEV;
575
576 /* Set up DEV_TYPE environment variable. */
Kay Sievers7eff2e72007-08-14 15:15:12 +0200577 retval = add_uevent_var(env, "DEV_TYPE=%04X", ap_dev->device_type);
Eric Rannaudbf624562007-03-30 22:23:12 -0700578 if (retval)
579 return retval;
580
Cornelia Huck66a4263b2006-12-04 15:40:10 +0100581 /* Add MODALIAS= */
Kay Sievers7eff2e72007-08-14 15:15:12 +0200582 retval = add_uevent_var(env, "MODALIAS=ap:t%02X", ap_dev->device_type);
Eric Rannaudbf624562007-03-30 22:23:12 -0700583
Eric Rannaudbf624562007-03-30 22:23:12 -0700584 return retval;
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200585}
586
Lars-Peter Clausen3e488c92016-11-22 22:06:00 +0100587static int ap_dev_suspend(struct device *dev)
Felix Beck772f5472009-06-22 12:08:16 +0200588{
589 struct ap_device *ap_dev = to_ap_dev(dev);
Felix Beck772f5472009-06-22 12:08:16 +0200590
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +0200591 if (ap_dev->drv && ap_dev->drv->suspend)
592 ap_dev->drv->suspend(ap_dev);
593 return 0;
594}
595
596static int ap_dev_resume(struct device *dev)
597{
598 struct ap_device *ap_dev = to_ap_dev(dev);
599
600 if (ap_dev->drv && ap_dev->drv->resume)
601 ap_dev->drv->resume(ap_dev);
Felix Beck772f5472009-06-22 12:08:16 +0200602 return 0;
603}
604
Martin Schwidefsky83e9d5d2015-07-17 13:43:18 +0200605static void ap_bus_suspend(void)
606{
Harald Freudenbergercccd85b2016-11-24 06:45:21 +0100607 AP_DBF(DBF_DEBUG, "ap_bus_suspend running\n");
608
Martin Schwidefsky83e9d5d2015-07-17 13:43:18 +0200609 ap_suspend_flag = 1;
610 /*
611 * Disable scanning for devices, thus we do not want to scan
612 * for them after removing.
613 */
Martin Schwidefsky8139b892015-07-27 12:47:40 +0200614 flush_work(&ap_scan_work);
Martin Schwidefsky83e9d5d2015-07-17 13:43:18 +0200615 tasklet_disable(&ap_tasklet);
616}
617
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +0200618static int __ap_card_devices_unregister(struct device *dev, void *dummy)
Martin Schwidefsky83e9d5d2015-07-17 13:43:18 +0200619{
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +0200620 if (is_card_dev(dev))
621 device_unregister(dev);
622 return 0;
623}
624
625static int __ap_queue_devices_unregister(struct device *dev, void *dummy)
626{
627 if (is_queue_dev(dev))
628 device_unregister(dev);
629 return 0;
630}
631
632static int __ap_queue_devices_with_id_unregister(struct device *dev, void *data)
633{
634 if (is_queue_dev(dev) &&
635 AP_QID_CARD(to_ap_queue(dev)->qid) == (int)(long) data)
636 device_unregister(dev);
Martin Schwidefsky83e9d5d2015-07-17 13:43:18 +0200637 return 0;
638}
639
640static void ap_bus_resume(void)
641{
Martin Schwidefskyf4eae942013-06-24 10:30:41 +0200642 int rc;
Felix Beck772f5472009-06-22 12:08:16 +0200643
Harald Freudenbergercccd85b2016-11-24 06:45:21 +0100644 AP_DBF(DBF_DEBUG, "ap_bus_resume running\n");
645
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +0200646 /* remove all queue devices */
647 bus_for_each_dev(&ap_bus_type, NULL, NULL,
648 __ap_queue_devices_unregister);
649 /* remove all card devices */
650 bus_for_each_dev(&ap_bus_type, NULL, NULL,
651 __ap_card_devices_unregister);
652
Martin Schwidefsky83e9d5d2015-07-17 13:43:18 +0200653 /* Reset thin interrupt setting */
654 if (ap_interrupts_available() && !ap_using_interrupts()) {
655 rc = register_adapter_interrupt(&ap_airq);
656 ap_airq_flag = (rc == 0);
Felix Beck5314af62009-09-22 22:58:51 +0200657 }
Martin Schwidefsky83e9d5d2015-07-17 13:43:18 +0200658 if (!ap_interrupts_available() && ap_using_interrupts()) {
659 unregister_adapter_interrupt(&ap_airq);
660 ap_airq_flag = 0;
661 }
662 /* Reset domain */
663 if (!user_set_domain)
664 ap_domain_index = -1;
665 /* Get things going again */
666 ap_suspend_flag = 0;
667 if (ap_airq_flag)
668 xchg(ap_airq.lsi_ptr, 0);
669 tasklet_enable(&ap_tasklet);
Martin Schwidefsky8139b892015-07-27 12:47:40 +0200670 queue_work(system_long_wq, &ap_scan_work);
Felix Beck772f5472009-06-22 12:08:16 +0200671}
672
Martin Schwidefsky83e9d5d2015-07-17 13:43:18 +0200673static int ap_power_event(struct notifier_block *this, unsigned long event,
674 void *ptr)
675{
676 switch (event) {
677 case PM_HIBERNATION_PREPARE:
678 case PM_SUSPEND_PREPARE:
679 ap_bus_suspend();
680 break;
681 case PM_POST_HIBERNATION:
682 case PM_POST_SUSPEND:
683 ap_bus_resume();
684 break;
685 default:
686 break;
687 }
688 return NOTIFY_DONE;
689}
690static struct notifier_block ap_power_notifier = {
691 .notifier_call = ap_power_event,
692};
693
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +0200694static SIMPLE_DEV_PM_OPS(ap_bus_pm_ops, ap_dev_suspend, ap_dev_resume);
Lars-Peter Clausen3e488c92016-11-22 22:06:00 +0100695
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200696static struct bus_type ap_bus_type = {
697 .name = "ap",
698 .match = &ap_bus_match,
699 .uevent = &ap_uevent,
Lars-Peter Clausen3e488c92016-11-22 22:06:00 +0100700 .pm = &ap_bus_pm_ops,
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200701};
702
703static int ap_device_probe(struct device *dev)
704{
705 struct ap_device *ap_dev = to_ap_dev(dev);
706 struct ap_driver *ap_drv = to_ap_drv(dev->driver);
707 int rc;
708
Harald Freudenbergere3850502017-05-24 10:26:29 +0200709 /* Add queue/card to list of active queues/cards */
710 spin_lock_bh(&ap_list_lock);
711 if (is_card_dev(dev))
712 list_add(&to_ap_card(dev)->list, &ap_card_list);
713 else
714 list_add(&to_ap_queue(dev)->list,
715 &to_ap_queue(dev)->card->queues);
716 spin_unlock_bh(&ap_list_lock);
717
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200718 ap_dev->drv = ap_drv;
719 rc = ap_drv->probe ? ap_drv->probe(ap_dev) : -ENODEV;
Harald Freudenbergere3850502017-05-24 10:26:29 +0200720
721 if (rc) {
722 spin_lock_bh(&ap_list_lock);
723 if (is_card_dev(dev))
724 list_del_init(&to_ap_card(dev)->list);
725 else
726 list_del_init(&to_ap_queue(dev)->list);
727 spin_unlock_bh(&ap_list_lock);
Martin Schwidefsky3f3007a2015-09-14 17:01:23 +0200728 ap_dev->drv = NULL;
Harald Freudenbergere3850502017-05-24 10:26:29 +0200729 }
730
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200731 return rc;
732}
733
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200734static int ap_device_remove(struct device *dev)
735{
736 struct ap_device *ap_dev = to_ap_dev(dev);
737 struct ap_driver *ap_drv = ap_dev->drv;
738
Harald Freudenbergere3850502017-05-24 10:26:29 +0200739 if (ap_drv->remove)
740 ap_drv->remove(ap_dev);
741
742 /* Remove queue/card from list of active queues/cards */
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +0200743 spin_lock_bh(&ap_list_lock);
744 if (is_card_dev(dev))
745 list_del_init(&to_ap_card(dev)->list);
746 else
747 list_del_init(&to_ap_queue(dev)->list);
748 spin_unlock_bh(&ap_list_lock);
Harald Freudenbergere3850502017-05-24 10:26:29 +0200749
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200750 return 0;
751}
752
753int ap_driver_register(struct ap_driver *ap_drv, struct module *owner,
754 char *name)
755{
756 struct device_driver *drv = &ap_drv->driver;
757
Sascha Silbee3877532015-10-27 18:29:52 +0100758 if (!initialised)
759 return -ENODEV;
760
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200761 drv->bus = &ap_bus_type;
762 drv->probe = ap_device_probe;
763 drv->remove = ap_device_remove;
764 drv->owner = owner;
765 drv->name = name;
766 return driver_register(drv);
767}
768EXPORT_SYMBOL(ap_driver_register);
769
770void ap_driver_unregister(struct ap_driver *ap_drv)
771{
772 driver_unregister(&ap_drv->driver);
773}
774EXPORT_SYMBOL(ap_driver_unregister);
775
Holger Denglerdabecb22012-09-10 21:34:26 +0200776void ap_bus_force_rescan(void)
777{
Martin Schwidefsky83e9d5d2015-07-17 13:43:18 +0200778 if (ap_suspend_flag)
779 return;
Ingo Tuchscherer56bbe682013-04-12 17:52:08 +0200780 /* processing a asynchronous bus rescan */
Martin Schwidefskyfcd0d1f2015-07-23 10:55:59 +0200781 del_timer(&ap_config_timer);
Martin Schwidefsky8139b892015-07-27 12:47:40 +0200782 queue_work(system_long_wq, &ap_scan_work);
783 flush_work(&ap_scan_work);
Holger Denglerdabecb22012-09-10 21:34:26 +0200784}
785EXPORT_SYMBOL(ap_bus_force_rescan);
786
Felix Beck1749a812008-04-17 07:46:28 +0200787/*
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200788 * AP bus attributes.
789 */
790static ssize_t ap_domain_show(struct bus_type *bus, char *buf)
791{
792 return snprintf(buf, PAGE_SIZE, "%d\n", ap_domain_index);
793}
794
Ingo Tuchschererfc1d3f02016-08-25 11:11:30 +0200795static ssize_t ap_domain_store(struct bus_type *bus,
796 const char *buf, size_t count)
797{
798 int domain;
799
800 if (sscanf(buf, "%i\n", &domain) != 1 ||
801 domain < 0 || domain > ap_max_domain_id)
802 return -EINVAL;
803 spin_lock_bh(&ap_domain_lock);
804 ap_domain_index = domain;
805 spin_unlock_bh(&ap_domain_lock);
Harald Freudenbergercccd85b2016-11-24 06:45:21 +0100806
Harald Freudenbergerac994e82017-05-12 16:35:14 +0200807 AP_DBF(DBF_DEBUG, "stored new default domain=%d\n", domain);
Harald Freudenbergercccd85b2016-11-24 06:45:21 +0100808
Ingo Tuchschererfc1d3f02016-08-25 11:11:30 +0200809 return count;
810}
811
812static BUS_ATTR(ap_domain, 0644, ap_domain_show, ap_domain_store);
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200813
Ingo Tuchscherer91f3e3ea2013-11-20 10:47:13 +0100814static ssize_t ap_control_domain_mask_show(struct bus_type *bus, char *buf)
815{
Martin Schwidefsky889875a2015-06-26 16:55:35 +0200816 if (!ap_configuration) /* QCI not supported */
817 return snprintf(buf, PAGE_SIZE, "not supported\n");
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +0200818
Martin Schwidefsky889875a2015-06-26 16:55:35 +0200819 return snprintf(buf, PAGE_SIZE,
820 "0x%08x%08x%08x%08x%08x%08x%08x%08x\n",
Ingo Tuchscherer91f3e3ea2013-11-20 10:47:13 +0100821 ap_configuration->adm[0], ap_configuration->adm[1],
822 ap_configuration->adm[2], ap_configuration->adm[3],
823 ap_configuration->adm[4], ap_configuration->adm[5],
824 ap_configuration->adm[6], ap_configuration->adm[7]);
Ingo Tuchscherer91f3e3ea2013-11-20 10:47:13 +0100825}
826
827static BUS_ATTR(ap_control_domain_mask, 0444,
828 ap_control_domain_mask_show, NULL);
829
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +0200830static ssize_t ap_usage_domain_mask_show(struct bus_type *bus, char *buf)
831{
832 if (!ap_configuration) /* QCI not supported */
833 return snprintf(buf, PAGE_SIZE, "not supported\n");
834
835 return snprintf(buf, PAGE_SIZE,
836 "0x%08x%08x%08x%08x%08x%08x%08x%08x\n",
837 ap_configuration->aqm[0], ap_configuration->aqm[1],
838 ap_configuration->aqm[2], ap_configuration->aqm[3],
839 ap_configuration->aqm[4], ap_configuration->aqm[5],
840 ap_configuration->aqm[6], ap_configuration->aqm[7]);
841}
842
843static BUS_ATTR(ap_usage_domain_mask, 0444,
844 ap_usage_domain_mask_show, NULL);
845
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200846static ssize_t ap_config_time_show(struct bus_type *bus, char *buf)
847{
848 return snprintf(buf, PAGE_SIZE, "%d\n", ap_config_time);
849}
850
Felix Beckcb17a632008-12-25 13:38:41 +0100851static ssize_t ap_interrupts_show(struct bus_type *bus, char *buf)
852{
853 return snprintf(buf, PAGE_SIZE, "%d\n",
854 ap_using_interrupts() ? 1 : 0);
855}
856
857static BUS_ATTR(ap_interrupts, 0444, ap_interrupts_show, NULL);
858
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200859static ssize_t ap_config_time_store(struct bus_type *bus,
860 const char *buf, size_t count)
861{
862 int time;
863
864 if (sscanf(buf, "%d\n", &time) != 1 || time < 5 || time > 120)
865 return -EINVAL;
866 ap_config_time = time;
Martin Schwidefskyfcd0d1f2015-07-23 10:55:59 +0200867 mod_timer(&ap_config_timer, jiffies + ap_config_time * HZ);
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200868 return count;
869}
870
871static BUS_ATTR(config_time, 0644, ap_config_time_show, ap_config_time_store);
872
873static ssize_t ap_poll_thread_show(struct bus_type *bus, char *buf)
874{
875 return snprintf(buf, PAGE_SIZE, "%d\n", ap_poll_kthread ? 1 : 0);
876}
877
878static ssize_t ap_poll_thread_store(struct bus_type *bus,
879 const char *buf, size_t count)
880{
881 int flag, rc;
882
883 if (sscanf(buf, "%d\n", &flag) != 1)
884 return -EINVAL;
885 if (flag) {
886 rc = ap_poll_thread_start();
887 if (rc)
Martin Schwidefsky83e9d5d2015-07-17 13:43:18 +0200888 count = rc;
889 } else
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200890 ap_poll_thread_stop();
891 return count;
892}
893
894static BUS_ATTR(poll_thread, 0644, ap_poll_thread_show, ap_poll_thread_store);
895
Felix Beckfe137232008-07-14 09:59:08 +0200896static ssize_t poll_timeout_show(struct bus_type *bus, char *buf)
897{
898 return snprintf(buf, PAGE_SIZE, "%llu\n", poll_timeout);
899}
900
901static ssize_t poll_timeout_store(struct bus_type *bus, const char *buf,
902 size_t count)
903{
904 unsigned long long time;
905 ktime_t hr_time;
906
907 /* 120 seconds = maximum poll interval */
Felix Beckcb17a632008-12-25 13:38:41 +0100908 if (sscanf(buf, "%llu\n", &time) != 1 || time < 1 ||
909 time > 120000000000ULL)
Felix Beckfe137232008-07-14 09:59:08 +0200910 return -EINVAL;
911 poll_timeout = time;
Thomas Gleixner8b0e1952016-12-25 12:30:41 +0100912 hr_time = poll_timeout;
Felix Beckfe137232008-07-14 09:59:08 +0200913
Ingo Tuchscherer8cc2af72015-04-28 10:31:44 +0200914 spin_lock_bh(&ap_poll_timer_lock);
915 hrtimer_cancel(&ap_poll_timer);
916 hrtimer_set_expires(&ap_poll_timer, hr_time);
917 hrtimer_start_expires(&ap_poll_timer, HRTIMER_MODE_ABS);
918 spin_unlock_bh(&ap_poll_timer_lock);
919
Felix Beckfe137232008-07-14 09:59:08 +0200920 return count;
921}
922
923static BUS_ATTR(poll_timeout, 0644, poll_timeout_show, poll_timeout_store);
924
Ingo Tuchscherer5bc334b2015-01-23 13:27:04 +0100925static ssize_t ap_max_domain_id_show(struct bus_type *bus, char *buf)
926{
Martin Schwidefsky889875a2015-06-26 16:55:35 +0200927 int max_domain_id;
Ingo Tuchscherer5bc334b2015-01-23 13:27:04 +0100928
Martin Schwidefsky889875a2015-06-26 16:55:35 +0200929 if (ap_configuration)
930 max_domain_id = ap_max_domain_id ? : -1;
931 else
Ingo Tuchscherer5bc334b2015-01-23 13:27:04 +0100932 max_domain_id = 15;
Ingo Tuchscherer5bc334b2015-01-23 13:27:04 +0100933 return snprintf(buf, PAGE_SIZE, "%d\n", max_domain_id);
934}
935
936static BUS_ATTR(ap_max_domain_id, 0444, ap_max_domain_id_show, NULL);
937
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200938static struct bus_attribute *const ap_bus_attrs[] = {
939 &bus_attr_ap_domain,
Ingo Tuchscherer91f3e3ea2013-11-20 10:47:13 +0100940 &bus_attr_ap_control_domain_mask,
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +0200941 &bus_attr_ap_usage_domain_mask,
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200942 &bus_attr_config_time,
943 &bus_attr_poll_thread,
Felix Beckcb17a632008-12-25 13:38:41 +0100944 &bus_attr_ap_interrupts,
Felix Beckfe137232008-07-14 09:59:08 +0200945 &bus_attr_poll_timeout,
Ingo Tuchscherer5bc334b2015-01-23 13:27:04 +0100946 &bus_attr_ap_max_domain_id,
Felix Beckfe137232008-07-14 09:59:08 +0200947 NULL,
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200948};
949
Holger Dengler75014552012-08-28 16:41:50 +0200950/**
Felix Beck1749a812008-04-17 07:46:28 +0200951 * ap_select_domain(): Select an AP domain.
952 *
953 * Pick one of the 16 AP domains.
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200954 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100955static int ap_select_domain(void)
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200956{
Martin Schwidefsky6acbe212015-06-26 15:40:41 +0200957 int count, max_count, best_domain;
958 struct ap_queue_status status;
959 int i, j;
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200960
Felix Beck1749a812008-04-17 07:46:28 +0200961 /*
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200962 * We want to use a single domain. Either the one specified with
963 * the "domain=" parameter or the domain with the maximum number
964 * of devices.
965 */
Ingo Tuchschererfc1d3f02016-08-25 11:11:30 +0200966 spin_lock_bh(&ap_domain_lock);
967 if (ap_domain_index >= 0) {
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200968 /* Domain has already been selected. */
Ingo Tuchschererfc1d3f02016-08-25 11:11:30 +0200969 spin_unlock_bh(&ap_domain_lock);
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200970 return 0;
Ingo Tuchschererfc1d3f02016-08-25 11:11:30 +0200971 }
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200972 best_domain = -1;
973 max_count = 0;
974 for (i = 0; i < AP_DOMAINS; i++) {
Holger Dengler75014552012-08-28 16:41:50 +0200975 if (!ap_test_config_domain(i))
976 continue;
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200977 count = 0;
978 for (j = 0; j < AP_DEVICES; j++) {
Holger Dengler75014552012-08-28 16:41:50 +0200979 if (!ap_test_config_card_id(j))
980 continue;
Tony Krowiake7fc5142016-11-08 07:09:13 +0100981 status = ap_test_queue(AP_MKQID(j, i),
982 ap_apft_available(),
983 NULL);
Martin Schwidefsky6acbe212015-06-26 15:40:41 +0200984 if (status.response_code != AP_RESPONSE_NORMAL)
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200985 continue;
986 count++;
987 }
988 if (count > max_count) {
989 max_count = count;
990 best_domain = i;
991 }
992 }
993 if (best_domain >= 0){
994 ap_domain_index = best_domain;
Harald Freudenbergerac994e82017-05-12 16:35:14 +0200995 AP_DBF(DBF_DEBUG, "new ap_domain_index=%d\n", ap_domain_index);
Ingo Tuchschererfc1d3f02016-08-25 11:11:30 +0200996 spin_unlock_bh(&ap_domain_lock);
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200997 return 0;
998 }
Ingo Tuchschererfc1d3f02016-08-25 11:11:30 +0200999 spin_unlock_bh(&ap_domain_lock);
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001000 return -ENODEV;
1001}
1002
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +02001003/*
Harald Freudenberger9a564102017-10-16 12:28:35 +02001004 * This function checks the type and returns either 0 for not
1005 * supported or the highest compatible type value (which may
1006 * include the input type value).
1007 */
1008static int ap_get_compatible_type(ap_qid_t qid, int rawtype, unsigned int func)
1009{
1010 int comp_type = 0;
1011
1012 /* < CEX2A is not supported */
1013 if (rawtype < AP_DEVICE_TYPE_CEX2A)
1014 return 0;
1015 /* up to CEX6 known and fully supported */
1016 if (rawtype <= AP_DEVICE_TYPE_CEX6)
1017 return rawtype;
1018 /*
1019 * unknown new type > CEX6, check for compatibility
1020 * to the highest known and supported type which is
1021 * currently CEX6 with the help of the QACT function.
1022 */
1023 if (ap_qact_available()) {
1024 struct ap_queue_status status;
Harald Freudenberger56c5c682017-10-30 12:10:54 +01001025 union ap_qact_ap_info apinfo = {0};
Harald Freudenberger9a564102017-10-16 12:28:35 +02001026
1027 apinfo.mode = (func >> 26) & 0x07;
1028 apinfo.cat = AP_DEVICE_TYPE_CEX6;
1029 status = ap_qact(qid, 0, &apinfo);
1030 if (status.response_code == AP_RESPONSE_NORMAL
1031 && apinfo.cat >= AP_DEVICE_TYPE_CEX2A
1032 && apinfo.cat <= AP_DEVICE_TYPE_CEX6)
1033 comp_type = apinfo.cat;
1034 }
1035 if (!comp_type)
1036 AP_DBF(DBF_WARN, "queue=%02x.%04x unable to map type %d\n",
1037 AP_QID_CARD(qid), AP_QID_QUEUE(qid), rawtype);
1038 else if (comp_type != rawtype)
1039 AP_DBF(DBF_INFO, "queue=%02x.%04x map type %d to %d\n",
1040 AP_QID_CARD(qid), AP_QID_QUEUE(qid), rawtype, comp_type);
1041 return comp_type;
1042}
1043
1044/*
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +02001045 * helper function to be used with bus_find_dev
1046 * matches for the card device with the given id
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001047 */
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +02001048static int __match_card_device_with_id(struct device *dev, void *data)
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001049{
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +02001050 return is_card_dev(dev) && to_ap_card(dev)->id == (int)(long) data;
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001051}
1052
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +02001053/* helper function to be used with bus_find_dev
1054 * matches for the queue device with a given qid
1055 */
1056static int __match_queue_device_with_qid(struct device *dev, void *data)
1057{
1058 return is_queue_dev(dev) && to_ap_queue(dev)->qid == (int)(long) data;
1059}
1060
1061/**
1062 * ap_scan_bus(): Scan the AP bus for new devices
1063 * Runs periodically, workqueue timer (ap_config_time)
1064 */
Al Viro4927b3f2006-12-06 19:18:20 +00001065static void ap_scan_bus(struct work_struct *unused)
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001066{
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +02001067 struct ap_queue *aq;
1068 struct ap_card *ac;
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001069 struct device *dev;
1070 ap_qid_t qid;
Harald Freudenberger9a564102017-10-16 12:28:35 +02001071 int comp_type, depth = 0, type = 0;
1072 unsigned int func = 0;
Harald Freudenbergerac994e82017-05-12 16:35:14 +02001073 int rc, id, dom, borked, domains, defdomdevs = 0;
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001074
Harald Freudenbergercccd85b2016-11-24 06:45:21 +01001075 AP_DBF(DBF_DEBUG, "ap_scan_bus running\n");
1076
Harald Freudenberger050349b2016-11-08 11:54:28 +01001077 ap_query_configuration(ap_configuration);
Martin Schwidefsky83e9d5d2015-07-17 13:43:18 +02001078 if (ap_select_domain() != 0)
Martin Schwidefskyfcd0d1f2015-07-23 10:55:59 +02001079 goto out;
Martin Schwidefsky889875a2015-06-26 16:55:35 +02001080
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +02001081 for (id = 0; id < AP_DEVICES; id++) {
1082 /* check if device is registered */
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001083 dev = bus_find_device(&ap_bus_type, NULL,
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +02001084 (void *)(long) id,
1085 __match_card_device_with_id);
1086 ac = dev ? to_ap_card(dev) : NULL;
1087 if (!ap_test_config_card_id(id)) {
1088 if (dev) {
1089 /* Card device has been removed from
1090 * configuration, remove the belonging
1091 * queue devices.
1092 */
1093 bus_for_each_dev(&ap_bus_type, NULL,
1094 (void *)(long) id,
1095 __ap_queue_devices_with_id_unregister);
1096 /* now remove the card device */
Martin Schwidefsky3f3007a2015-09-14 17:01:23 +02001097 device_unregister(dev);
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +02001098 put_device(dev);
1099 }
1100 continue;
1101 }
1102 /* According to the configuration there should be a card
1103 * device, so check if there is at least one valid queue
1104 * and maybe create queue devices and the card device.
1105 */
1106 domains = 0;
1107 for (dom = 0; dom < AP_DOMAINS; dom++) {
1108 qid = AP_MKQID(id, dom);
1109 dev = bus_find_device(&ap_bus_type, NULL,
1110 (void *)(long) qid,
1111 __match_queue_device_with_qid);
1112 aq = dev ? to_ap_queue(dev) : NULL;
1113 if (!ap_test_config_domain(dom)) {
1114 if (dev) {
1115 /* Queue device exists but has been
1116 * removed from configuration.
1117 */
1118 device_unregister(dev);
1119 put_device(dev);
1120 }
Martin Schwidefsky3f3007a2015-09-14 17:01:23 +02001121 continue;
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +02001122 }
Harald Freudenberger9a564102017-10-16 12:28:35 +02001123 rc = ap_query_queue(qid, &depth, &type, &func);
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +02001124 if (dev) {
1125 spin_lock_bh(&aq->lock);
1126 if (rc == -ENODEV ||
1127 /* adapter reconfiguration */
Harald Freudenberger9a564102017-10-16 12:28:35 +02001128 (ac && ac->functions != func))
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +02001129 aq->state = AP_STATE_BORKED;
1130 borked = aq->state == AP_STATE_BORKED;
1131 spin_unlock_bh(&aq->lock);
1132 if (borked) /* Remove broken device */
1133 device_unregister(dev);
1134 put_device(dev);
1135 if (!borked) {
1136 domains++;
Harald Freudenbergerac994e82017-05-12 16:35:14 +02001137 if (dom == ap_domain_index)
1138 defdomdevs++;
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +02001139 continue;
1140 }
1141 }
1142 if (rc)
1143 continue;
Harald Freudenberger9a564102017-10-16 12:28:35 +02001144 /* a new queue device is needed, check out comp type */
1145 comp_type = ap_get_compatible_type(qid, type, func);
1146 if (!comp_type)
1147 continue;
1148 /* maybe a card device needs to be created first */
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +02001149 if (!ac) {
Harald Freudenberger9a564102017-10-16 12:28:35 +02001150 ac = ap_card_create(id, depth, type,
1151 comp_type, func);
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +02001152 if (!ac)
1153 continue;
1154 ac->ap_dev.device.bus = &ap_bus_type;
1155 ac->ap_dev.device.parent = ap_root_device;
1156 dev_set_name(&ac->ap_dev.device,
1157 "card%02x", id);
1158 /* Register card with AP bus */
1159 rc = device_register(&ac->ap_dev.device);
1160 if (rc) {
1161 put_device(&ac->ap_dev.device);
1162 ac = NULL;
1163 break;
1164 }
1165 /* get it and thus adjust reference counter */
1166 get_device(&ac->ap_dev.device);
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +02001167 }
1168 /* now create the new queue device */
Harald Freudenberger9a564102017-10-16 12:28:35 +02001169 aq = ap_queue_create(qid, comp_type);
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +02001170 if (!aq)
1171 continue;
1172 aq->card = ac;
1173 aq->ap_dev.device.bus = &ap_bus_type;
1174 aq->ap_dev.device.parent = &ac->ap_dev.device;
1175 dev_set_name(&aq->ap_dev.device,
1176 "%02x.%04x", id, dom);
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +02001177 /* Start with a device reset */
1178 spin_lock_bh(&aq->lock);
1179 ap_wait(ap_sm_event(aq, AP_EVENT_POLL));
1180 spin_unlock_bh(&aq->lock);
1181 /* Register device */
1182 rc = device_register(&aq->ap_dev.device);
1183 if (rc) {
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +02001184 put_device(&aq->ap_dev.device);
1185 continue;
1186 }
1187 domains++;
Harald Freudenbergerac994e82017-05-12 16:35:14 +02001188 if (dom == ap_domain_index)
1189 defdomdevs++;
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +02001190 } /* end domain loop */
1191 if (ac) {
1192 /* remove card dev if there are no queue devices */
1193 if (!domains)
1194 device_unregister(&ac->ap_dev.device);
1195 put_device(&ac->ap_dev.device);
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001196 }
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +02001197 } /* end device loop */
Harald Freudenbergerac994e82017-05-12 16:35:14 +02001198
1199 if (defdomdevs < 1)
1200 AP_DBF(DBF_INFO, "no queue device with default domain %d available\n",
1201 ap_domain_index);
1202
Martin Schwidefskyfcd0d1f2015-07-23 10:55:59 +02001203out:
1204 mod_timer(&ap_config_timer, jiffies + ap_config_time * HZ);
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001205}
1206
Kees Cookcefbeb52017-10-25 03:27:37 -07001207static void ap_config_timeout(struct timer_list *unused)
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001208{
Martin Schwidefsky83e9d5d2015-07-17 13:43:18 +02001209 if (ap_suspend_flag)
1210 return;
Martin Schwidefsky8139b892015-07-27 12:47:40 +02001211 queue_work(system_long_wq, &ap_scan_work);
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001212}
1213
Ralph Wuerthner13e742b2006-12-15 17:18:17 +01001214static void ap_reset_all(void)
Ralph Wuerthner85eca852006-12-08 15:54:07 +01001215{
1216 int i, j;
1217
Ingo Tuchscherer170387a2014-09-08 13:24:13 +02001218 for (i = 0; i < AP_DOMAINS; i++) {
1219 if (!ap_test_config_domain(i))
1220 continue;
1221 for (j = 0; j < AP_DEVICES; j++) {
1222 if (!ap_test_config_card_id(j))
1223 continue;
Martin Schwidefsky0db78552016-09-21 12:48:54 +02001224 ap_rapq(AP_MKQID(j, i));
Ingo Tuchscherer170387a2014-09-08 13:24:13 +02001225 }
1226 }
Ralph Wuerthner85eca852006-12-08 15:54:07 +01001227}
1228
1229static struct reset_call ap_reset_call = {
Ralph Wuerthner13e742b2006-12-15 17:18:17 +01001230 .fn = ap_reset_all,
Ralph Wuerthner85eca852006-12-08 15:54:07 +01001231};
1232
Harald Freudenbergercccd85b2016-11-24 06:45:21 +01001233int __init ap_debug_init(void)
1234{
Harald Freudenbergercccd85b2016-11-24 06:45:21 +01001235 ap_dbf_info = debug_register("ap", 1, 1,
1236 DBF_MAX_SPRINTF_ARGS * sizeof(long));
1237 debug_register_view(ap_dbf_info, &debug_sprintf_view);
1238 debug_set_level(ap_dbf_info, DBF_ERR);
1239
1240 return 0;
1241}
1242
1243void ap_debug_exit(void)
1244{
Harald Freudenbergercccd85b2016-11-24 06:45:21 +01001245 debug_unregister(ap_dbf_info);
1246}
1247
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001248/**
Felix Beck1749a812008-04-17 07:46:28 +02001249 * ap_module_init(): The module initialization code.
1250 *
1251 * Initializes the module.
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001252 */
1253int __init ap_module_init(void)
1254{
Martin Schwidefsky889875a2015-06-26 16:55:35 +02001255 int max_domain_id;
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001256 int rc, i;
1257
Harald Freudenbergercccd85b2016-11-24 06:45:21 +01001258 rc = ap_debug_init();
1259 if (rc)
1260 return rc;
1261
Martin Schwidefsky889875a2015-06-26 16:55:35 +02001262 if (ap_instructions_available() != 0) {
1263 pr_warn("The hardware system does not support AP instructions\n");
1264 return -ENODEV;
1265 }
1266
1267 /* Get AP configuration data if available */
1268 ap_init_configuration();
1269
1270 if (ap_configuration)
Harald Freudenbergerac994e82017-05-12 16:35:14 +02001271 max_domain_id =
1272 ap_max_domain_id ? ap_max_domain_id : AP_DOMAINS - 1;
Martin Schwidefsky889875a2015-06-26 16:55:35 +02001273 else
1274 max_domain_id = 15;
1275 if (ap_domain_index < -1 || ap_domain_index > max_domain_id) {
1276 pr_warn("%d is not a valid cryptographic domain\n",
1277 ap_domain_index);
Harald Freudenbergerac994e82017-05-12 16:35:14 +02001278 ap_domain_index = -1;
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001279 }
Felix Beck5314af62009-09-22 22:58:51 +02001280 /* In resume callback we need to know if the user had set the domain.
1281 * If so, we can not just reset it.
1282 */
1283 if (ap_domain_index >= 0)
1284 user_set_domain = 1;
1285
Felix Beckcb17a632008-12-25 13:38:41 +01001286 if (ap_interrupts_available()) {
Martin Schwidefskyf4eae942013-06-24 10:30:41 +02001287 rc = register_adapter_interrupt(&ap_airq);
1288 ap_airq_flag = (rc == 0);
Felix Beckcb17a632008-12-25 13:38:41 +01001289 }
1290
Ralph Wuerthner85eca852006-12-08 15:54:07 +01001291 register_reset_call(&ap_reset_call);
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001292
1293 /* Create /sys/bus/ap. */
1294 rc = bus_register(&ap_bus_type);
1295 if (rc)
1296 goto out;
1297 for (i = 0; ap_bus_attrs[i]; i++) {
1298 rc = bus_create_file(&ap_bus_type, ap_bus_attrs[i]);
1299 if (rc)
1300 goto out_bus;
1301 }
1302
1303 /* Create /sys/devices/ap. */
Mark McLoughlin035da162008-12-15 12:58:29 +00001304 ap_root_device = root_device_register("ap");
Thomas Meyerba8da212013-06-01 11:51:13 +02001305 rc = PTR_RET(ap_root_device);
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001306 if (rc)
1307 goto out_bus;
1308
Felix Beck1749a812008-04-17 07:46:28 +02001309 /* Setup the AP bus rescan timer. */
Kees Cookcefbeb52017-10-25 03:27:37 -07001310 timer_setup(&ap_config_timer, ap_config_timeout, 0);
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001311
Martin Schwidefsky3f3007a2015-09-14 17:01:23 +02001312 /*
1313 * Setup the high resultion poll timer.
Felix Beckfe137232008-07-14 09:59:08 +02001314 * If we are running under z/VM adjust polling to z/VM polling rate.
1315 */
1316 if (MACHINE_IS_VM)
1317 poll_timeout = 1500000;
Felix Beck93521312009-12-07 12:52:00 +01001318 spin_lock_init(&ap_poll_timer_lock);
Felix Beckfe137232008-07-14 09:59:08 +02001319 hrtimer_init(&ap_poll_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
1320 ap_poll_timer.function = ap_poll_timeout;
1321
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001322 /* Start the low priority AP bus poll thread. */
1323 if (ap_thread_flag) {
1324 rc = ap_poll_thread_start();
1325 if (rc)
1326 goto out_work;
1327 }
1328
Martin Schwidefsky83e9d5d2015-07-17 13:43:18 +02001329 rc = register_pm_notifier(&ap_power_notifier);
1330 if (rc)
1331 goto out_pm;
1332
Martin Schwidefsky8139b892015-07-27 12:47:40 +02001333 queue_work(system_long_wq, &ap_scan_work);
Sascha Silbee3877532015-10-27 18:29:52 +01001334 initialised = true;
Martin Schwidefsky3f3007a2015-09-14 17:01:23 +02001335
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001336 return 0;
1337
Martin Schwidefsky83e9d5d2015-07-17 13:43:18 +02001338out_pm:
1339 ap_poll_thread_stop();
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001340out_work:
Felix Beckfe137232008-07-14 09:59:08 +02001341 hrtimer_cancel(&ap_poll_timer);
Mark McLoughlin035da162008-12-15 12:58:29 +00001342 root_device_unregister(ap_root_device);
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001343out_bus:
1344 while (i--)
1345 bus_remove_file(&ap_bus_type, ap_bus_attrs[i]);
1346 bus_unregister(&ap_bus_type);
1347out:
Ralph Wuerthner85eca852006-12-08 15:54:07 +01001348 unregister_reset_call(&ap_reset_call);
Martin Schwidefskyf4eae942013-06-24 10:30:41 +02001349 if (ap_using_interrupts())
1350 unregister_adapter_interrupt(&ap_airq);
Martin Schwidefsky889875a2015-06-26 16:55:35 +02001351 kfree(ap_configuration);
Martin Schwidefsky1534c382006-09-20 15:58:25 +02001352 return rc;
1353}
Paul Gortmaker50a0d462017-02-09 09:48:10 -05001354device_initcall(ap_module_init);