2006-09-20 20:58:25 +07:00
|
|
|
/*
|
2012-08-28 21:41:50 +07:00
|
|
|
* Copyright IBM Corp. 2006, 2012
|
2006-09-20 20:58:25 +07:00
|
|
|
* Author(s): Cornelia Huck <cornelia.huck@de.ibm.com>
|
|
|
|
* Martin Schwidefsky <schwidefsky@de.ibm.com>
|
|
|
|
* Ralph Wuerthner <rwuerthn@de.ibm.com>
|
2008-12-25 19:38:41 +07:00
|
|
|
* Felix Beck <felix.beck@de.ibm.com>
|
2011-07-24 15:48:25 +07:00
|
|
|
* Holger Dengler <hd@linux.vnet.ibm.com>
|
2006-09-20 20:58:25 +07:00
|
|
|
*
|
|
|
|
* Adjunct processor bus.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
2008-12-25 19:39:46 +07:00
|
|
|
#define KMSG_COMPONENT "ap"
|
|
|
|
#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
|
|
|
|
|
2011-01-05 18:47:38 +07:00
|
|
|
#include <linux/kernel_stat.h>
|
2006-09-20 20:58:25 +07:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/workqueue.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 15:04:11 +07:00
|
|
|
#include <linux/slab.h>
|
2006-09-20 20:58:25 +07:00
|
|
|
#include <linux/notifier.h>
|
|
|
|
#include <linux/kthread.h>
|
|
|
|
#include <linux/mutex.h>
|
2015-07-17 18:43:18 +07:00
|
|
|
#include <linux/suspend.h>
|
2006-12-08 21:54:07 +07:00
|
|
|
#include <asm/reset.h>
|
2008-12-25 19:38:41 +07:00
|
|
|
#include <asm/airq.h>
|
2011-07-27 06:09:06 +07:00
|
|
|
#include <linux/atomic.h>
|
2008-12-25 19:38:41 +07:00
|
|
|
#include <asm/isc.h>
|
2008-07-14 14:59:08 +07:00
|
|
|
#include <linux/hrtimer.h>
|
|
|
|
#include <linux/ktime.h>
|
2012-03-29 00:30:02 +07:00
|
|
|
#include <asm/facility.h>
|
2014-11-21 08:05:53 +07:00
|
|
|
#include <linux/crypto.h>
|
2006-09-20 20:58:25 +07:00
|
|
|
|
|
|
|
#include "ap_bus.h"
|
|
|
|
|
2008-04-17 12:46:28 +07:00
|
|
|
/*
|
2006-09-20 20:58:25 +07:00
|
|
|
* Module description.
|
|
|
|
*/
|
|
|
|
MODULE_AUTHOR("IBM Corporation");
|
2012-08-28 21:41:50 +07:00
|
|
|
MODULE_DESCRIPTION("Adjunct Processor Bus driver, " \
|
|
|
|
"Copyright IBM Corp. 2006, 2012");
|
2006-09-20 20:58:25 +07:00
|
|
|
MODULE_LICENSE("GPL");
|
2014-11-21 08:05:53 +07:00
|
|
|
MODULE_ALIAS_CRYPTO("z90crypt");
|
2006-09-20 20:58:25 +07:00
|
|
|
|
2008-04-17 12:46:28 +07:00
|
|
|
/*
|
2006-09-20 20:58:25 +07:00
|
|
|
* Module parameter
|
|
|
|
*/
|
|
|
|
int ap_domain_index = -1; /* Adjunct Processor Domain Index */
|
2014-04-14 19:28:27 +07:00
|
|
|
module_param_named(domain, ap_domain_index, int, S_IRUSR|S_IRGRP);
|
2006-09-20 20:58:25 +07:00
|
|
|
MODULE_PARM_DESC(domain, "domain index for ap devices");
|
|
|
|
EXPORT_SYMBOL(ap_domain_index);
|
|
|
|
|
2008-02-10 00:24:30 +07:00
|
|
|
static int ap_thread_flag = 0;
|
2014-04-14 19:28:27 +07:00
|
|
|
module_param_named(poll_thread, ap_thread_flag, int, S_IRUSR|S_IRGRP);
|
2008-02-10 00:24:30 +07:00
|
|
|
MODULE_PARM_DESC(poll_thread, "Turn on/off poll thread, default is 0 (off).");
|
2006-09-20 20:58:25 +07:00
|
|
|
|
|
|
|
static struct device *ap_root_device = NULL;
|
2012-08-28 21:41:50 +07:00
|
|
|
static struct ap_config_info *ap_configuration;
|
2008-12-25 19:38:42 +07:00
|
|
|
static DEFINE_SPINLOCK(ap_device_list_lock);
|
2007-03-19 19:19:14 +07:00
|
|
|
static LIST_HEAD(ap_device_list);
|
2006-09-20 20:58:25 +07:00
|
|
|
|
2008-04-17 12:46:28 +07:00
|
|
|
/*
|
2006-09-20 20:58:25 +07:00
|
|
|
* Workqueue & timer for bus rescan.
|
|
|
|
*/
|
|
|
|
static struct workqueue_struct *ap_work_queue;
|
|
|
|
static struct timer_list ap_config_timer;
|
|
|
|
static int ap_config_time = AP_CONFIG_TIME;
|
2015-09-14 22:01:23 +07:00
|
|
|
static void ap_scan_bus(struct work_struct *);
|
2006-12-07 02:18:20 +07:00
|
|
|
static DECLARE_WORK(ap_config_work, ap_scan_bus);
|
2006-09-20 20:58:25 +07:00
|
|
|
|
2008-04-17 12:46:28 +07:00
|
|
|
/*
|
2008-12-25 19:38:41 +07:00
|
|
|
* Tasklet & timer for AP request polling and interrupts
|
2006-09-20 20:58:25 +07:00
|
|
|
*/
|
2015-09-14 22:01:23 +07:00
|
|
|
static void ap_tasklet_fn(unsigned long);
|
|
|
|
static DECLARE_TASKLET(ap_tasklet, ap_tasklet_fn, 0);
|
2006-09-20 20:58:25 +07:00
|
|
|
static atomic_t ap_poll_requests = ATOMIC_INIT(0);
|
|
|
|
static DECLARE_WAIT_QUEUE_HEAD(ap_poll_wait);
|
|
|
|
static struct task_struct *ap_poll_kthread = NULL;
|
|
|
|
static DEFINE_MUTEX(ap_poll_thread_mutex);
|
2009-12-07 18:52:00 +07:00
|
|
|
static DEFINE_SPINLOCK(ap_poll_timer_lock);
|
2008-07-14 14:59:08 +07:00
|
|
|
static struct hrtimer ap_poll_timer;
|
|
|
|
/* In LPAR poll with 4kHz frequency. Poll every 250000 nanoseconds.
|
|
|
|
* If z/VM change to 1500000 nanoseconds to adjust to z/VM polling.*/
|
|
|
|
static unsigned long long poll_timeout = 250000;
|
2006-09-20 20:58:25 +07:00
|
|
|
|
2009-06-22 17:08:16 +07:00
|
|
|
/* Suspend flag */
|
|
|
|
static int ap_suspend_flag;
|
2015-06-26 21:55:35 +07:00
|
|
|
/* Maximum domain id */
|
|
|
|
static int ap_max_domain_id;
|
2009-09-23 03:58:51 +07:00
|
|
|
/* Flag to check if domain was set through module parameter domain=. This is
|
|
|
|
* important when supsend and resume is done in a z/VM environment where the
|
|
|
|
* domain might change. */
|
|
|
|
static int user_set_domain = 0;
|
2009-06-22 17:08:16 +07:00
|
|
|
static struct bus_type ap_bus_type;
|
|
|
|
|
2013-06-24 15:30:41 +07:00
|
|
|
/* Adapter interrupt definitions */
|
2015-09-14 22:01:23 +07:00
|
|
|
static void ap_interrupt_handler(struct airq_struct *airq);
|
|
|
|
|
2013-06-24 15:30:41 +07:00
|
|
|
static int ap_airq_flag;
|
|
|
|
|
|
|
|
static struct airq_struct ap_airq = {
|
|
|
|
.handler = ap_interrupt_handler,
|
|
|
|
.isc = AP_ISC,
|
|
|
|
};
|
|
|
|
|
2008-12-25 19:38:41 +07:00
|
|
|
/**
|
|
|
|
* ap_using_interrupts() - Returns non-zero if interrupt support is
|
|
|
|
* available.
|
|
|
|
*/
|
|
|
|
static inline int ap_using_interrupts(void)
|
|
|
|
{
|
2013-06-24 15:30:41 +07:00
|
|
|
return ap_airq_flag;
|
2008-12-25 19:38:41 +07:00
|
|
|
}
|
|
|
|
|
2006-09-20 20:58:25 +07:00
|
|
|
/**
|
2008-04-17 12:46:28 +07:00
|
|
|
* ap_intructions_available() - Test if AP instructions are available.
|
2006-09-20 20:58:25 +07:00
|
|
|
*
|
2008-04-17 12:46:28 +07:00
|
|
|
* Returns 0 if the AP instructions are installed.
|
2006-09-20 20:58:25 +07:00
|
|
|
*/
|
|
|
|
static inline int ap_instructions_available(void)
|
|
|
|
{
|
|
|
|
register unsigned long reg0 asm ("0") = AP_MKQID(0,0);
|
|
|
|
register unsigned long reg1 asm ("1") = -ENODEV;
|
|
|
|
register unsigned long reg2 asm ("2") = 0UL;
|
|
|
|
|
|
|
|
asm volatile(
|
|
|
|
" .long 0xb2af0000\n" /* PQAP(TAPQ) */
|
|
|
|
"0: la %1,0\n"
|
|
|
|
"1:\n"
|
|
|
|
EX_TABLE(0b, 1b)
|
|
|
|
: "+d" (reg0), "+d" (reg1), "+d" (reg2) : : "cc" );
|
|
|
|
return reg1;
|
|
|
|
}
|
|
|
|
|
2008-12-25 19:38:41 +07:00
|
|
|
/**
|
|
|
|
* ap_interrupts_available(): Test if AP interrupts are available.
|
|
|
|
*
|
|
|
|
* Returns 1 if AP interrupts are available.
|
|
|
|
*/
|
|
|
|
static int ap_interrupts_available(void)
|
|
|
|
{
|
2015-02-14 17:23:21 +07:00
|
|
|
return test_facility(65);
|
2008-12-25 19:38:41 +07:00
|
|
|
}
|
|
|
|
|
2012-08-28 21:41:50 +07:00
|
|
|
/**
|
|
|
|
* ap_configuration_available(): Test if AP configuration
|
|
|
|
* information is available.
|
|
|
|
*
|
|
|
|
* Returns 1 if AP configuration information is available.
|
|
|
|
*/
|
|
|
|
static int ap_configuration_available(void)
|
|
|
|
{
|
2015-02-14 17:23:21 +07:00
|
|
|
return test_facility(12);
|
2012-08-28 21:41:50 +07:00
|
|
|
}
|
|
|
|
|
2006-09-20 20:58:25 +07:00
|
|
|
/**
|
2008-04-17 12:46:28 +07:00
|
|
|
* ap_test_queue(): Test adjunct processor queue.
|
|
|
|
* @qid: The AP queue number
|
2015-06-26 20:40:41 +07:00
|
|
|
* @info: Pointer to queue descriptor
|
2006-09-20 20:58:25 +07:00
|
|
|
*
|
2008-04-17 12:46:28 +07:00
|
|
|
* Returns AP queue status structure.
|
2006-09-20 20:58:25 +07:00
|
|
|
*/
|
|
|
|
static inline struct ap_queue_status
|
2015-06-26 20:40:41 +07:00
|
|
|
ap_test_queue(ap_qid_t qid, unsigned long *info)
|
2006-09-20 20:58:25 +07:00
|
|
|
{
|
|
|
|
register unsigned long reg0 asm ("0") = qid;
|
|
|
|
register struct ap_queue_status reg1 asm ("1");
|
|
|
|
register unsigned long reg2 asm ("2") = 0UL;
|
|
|
|
|
2015-06-26 20:40:41 +07:00
|
|
|
if (test_facility(15))
|
|
|
|
reg0 |= 1UL << 23; /* set APFT T bit*/
|
2006-09-20 20:58:25 +07:00
|
|
|
asm volatile(".long 0xb2af0000" /* PQAP(TAPQ) */
|
|
|
|
: "+d" (reg0), "=d" (reg1), "+d" (reg2) : : "cc");
|
2015-06-26 20:40:41 +07:00
|
|
|
if (info)
|
|
|
|
*info = reg2;
|
2006-09-20 20:58:25 +07:00
|
|
|
return reg1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-04-17 12:46:28 +07:00
|
|
|
* ap_reset_queue(): Reset adjunct processor queue.
|
|
|
|
* @qid: The AP queue number
|
2006-09-20 20:58:25 +07:00
|
|
|
*
|
2008-04-17 12:46:28 +07:00
|
|
|
* Returns AP queue status structure.
|
2006-09-20 20:58:25 +07:00
|
|
|
*/
|
|
|
|
static inline struct ap_queue_status ap_reset_queue(ap_qid_t qid)
|
|
|
|
{
|
|
|
|
register unsigned long reg0 asm ("0") = qid | 0x01000000UL;
|
|
|
|
register struct ap_queue_status reg1 asm ("1");
|
|
|
|
register unsigned long reg2 asm ("2") = 0UL;
|
|
|
|
|
|
|
|
asm volatile(
|
|
|
|
".long 0xb2af0000" /* PQAP(RAPQ) */
|
|
|
|
: "+d" (reg0), "=d" (reg1), "+d" (reg2) : : "cc");
|
|
|
|
return reg1;
|
|
|
|
}
|
|
|
|
|
2008-12-25 19:38:41 +07:00
|
|
|
/**
|
|
|
|
* ap_queue_interruption_control(): Enable interruption for a specific AP.
|
|
|
|
* @qid: The AP queue number
|
|
|
|
* @ind: The notification indicator byte
|
|
|
|
*
|
|
|
|
* Returns AP queue status.
|
|
|
|
*/
|
|
|
|
static inline struct ap_queue_status
|
|
|
|
ap_queue_interruption_control(ap_qid_t qid, void *ind)
|
|
|
|
{
|
|
|
|
register unsigned long reg0 asm ("0") = qid | 0x03000000UL;
|
|
|
|
register unsigned long reg1_in asm ("1") = 0x0000800000000000UL | AP_ISC;
|
|
|
|
register struct ap_queue_status reg1_out asm ("1");
|
|
|
|
register void *reg2 asm ("2") = ind;
|
|
|
|
asm volatile(
|
2012-05-16 19:10:26 +07:00
|
|
|
".long 0xb2af0000" /* PQAP(AQIC) */
|
2008-12-25 19:38:41 +07:00
|
|
|
: "+d" (reg0), "+d" (reg1_in), "=d" (reg1_out), "+d" (reg2)
|
|
|
|
:
|
|
|
|
: "cc" );
|
|
|
|
return reg1_out;
|
|
|
|
}
|
|
|
|
|
2015-06-26 21:55:35 +07:00
|
|
|
/**
|
|
|
|
* ap_query_configuration(): Get AP configuration data
|
|
|
|
*
|
|
|
|
* Returns 0 on success, or -EOPNOTSUPP.
|
|
|
|
*/
|
|
|
|
static inline int ap_query_configuration(void)
|
2012-08-28 21:41:50 +07:00
|
|
|
{
|
|
|
|
register unsigned long reg0 asm ("0") = 0x04000000UL;
|
|
|
|
register unsigned long reg1 asm ("1") = -EINVAL;
|
2015-06-26 21:55:35 +07:00
|
|
|
register void *reg2 asm ("2") = (void *) ap_configuration;
|
2012-08-28 21:41:50 +07:00
|
|
|
|
2015-06-26 21:55:35 +07:00
|
|
|
if (!ap_configuration)
|
|
|
|
return -EOPNOTSUPP;
|
2012-08-28 21:41:50 +07:00
|
|
|
asm volatile(
|
|
|
|
".long 0xb2af0000\n" /* PQAP(QCI) */
|
|
|
|
"0: la %1,0\n"
|
|
|
|
"1:\n"
|
|
|
|
EX_TABLE(0b, 1b)
|
|
|
|
: "+d" (reg0), "+d" (reg1), "+d" (reg2)
|
|
|
|
:
|
|
|
|
: "cc");
|
|
|
|
|
|
|
|
return reg1;
|
|
|
|
}
|
|
|
|
|
2015-06-26 21:55:35 +07:00
|
|
|
/**
|
|
|
|
* ap_init_configuration(): Allocate and query configuration array.
|
|
|
|
*/
|
|
|
|
static void ap_init_configuration(void)
|
|
|
|
{
|
|
|
|
if (!ap_configuration_available())
|
|
|
|
return;
|
|
|
|
|
|
|
|
ap_configuration = kzalloc(sizeof(*ap_configuration), GFP_KERNEL);
|
|
|
|
if (!ap_configuration)
|
|
|
|
return;
|
|
|
|
if (ap_query_configuration() != 0) {
|
|
|
|
kfree(ap_configuration);
|
|
|
|
ap_configuration = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ap_test_config(): helper function to extract the nrth bit
|
|
|
|
* within the unsigned int array field.
|
|
|
|
*/
|
|
|
|
static inline int ap_test_config(unsigned int *field, unsigned int nr)
|
|
|
|
{
|
|
|
|
return ap_test_bit((field + (nr >> 5)), (nr & 0x1f));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ap_test_config_card_id(): Test, whether an AP card ID is configured.
|
|
|
|
* @id AP card ID
|
|
|
|
*
|
|
|
|
* Returns 0 if the card is not configured
|
|
|
|
* 1 if the card is configured or
|
|
|
|
* if the configuration information is not available
|
|
|
|
*/
|
|
|
|
static inline int ap_test_config_card_id(unsigned int id)
|
|
|
|
{
|
|
|
|
if (!ap_configuration) /* QCI not supported */
|
|
|
|
return 1;
|
|
|
|
return ap_test_config(ap_configuration->apm, id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ap_test_config_domain(): Test, whether an AP usage domain is configured.
|
|
|
|
* @domain AP usage domain ID
|
|
|
|
*
|
|
|
|
* Returns 0 if the usage domain is not configured
|
|
|
|
* 1 if the usage domain is configured or
|
|
|
|
* if the configuration information is not available
|
|
|
|
*/
|
|
|
|
static inline int ap_test_config_domain(unsigned int domain)
|
|
|
|
{
|
|
|
|
if (!ap_configuration) /* QCI not supported */
|
|
|
|
return domain < 16;
|
|
|
|
return ap_test_config(ap_configuration->aqm, domain);
|
|
|
|
}
|
|
|
|
|
2008-12-25 19:38:41 +07:00
|
|
|
/**
|
|
|
|
* ap_queue_enable_interruption(): Enable interruption on an AP.
|
|
|
|
* @qid: The AP queue number
|
|
|
|
* @ind: the notification indicator byte
|
|
|
|
*
|
|
|
|
* Enables interruption on AP queue via ap_queue_interruption_control(). Based
|
|
|
|
* on the return value it waits a while and tests the AP queue if interrupts
|
|
|
|
* have been switched on using ap_test_queue().
|
|
|
|
*/
|
2015-06-17 21:19:15 +07:00
|
|
|
static int ap_queue_enable_interruption(struct ap_device *ap_dev, void *ind)
|
2008-12-25 19:38:41 +07:00
|
|
|
{
|
|
|
|
struct ap_queue_status status;
|
|
|
|
|
2015-06-17 21:19:15 +07:00
|
|
|
status = ap_queue_interruption_control(ap_dev->qid, ind);
|
|
|
|
switch (status.response_code) {
|
|
|
|
case AP_RESPONSE_NORMAL:
|
|
|
|
case AP_RESPONSE_OTHERWISE_CHANGED:
|
|
|
|
return 0;
|
|
|
|
case AP_RESPONSE_Q_NOT_AVAIL:
|
|
|
|
case AP_RESPONSE_DECONFIGURED:
|
|
|
|
case AP_RESPONSE_CHECKSTOPPED:
|
|
|
|
case AP_RESPONSE_INVALID_ADDRESS:
|
2015-09-14 22:01:23 +07:00
|
|
|
pr_err("Registering adapter interrupts for AP %d failed\n",
|
|
|
|
AP_QID_DEVICE(ap_dev->qid));
|
|
|
|
return -EOPNOTSUPP;
|
2015-06-17 21:19:15 +07:00
|
|
|
case AP_RESPONSE_RESET_IN_PROGRESS:
|
|
|
|
case AP_RESPONSE_BUSY:
|
|
|
|
default:
|
|
|
|
return -EBUSY;
|
2008-12-25 19:38:41 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-20 20:58:25 +07:00
|
|
|
/**
|
2008-04-17 12:46:28 +07:00
|
|
|
* __ap_send(): Send message to adjunct processor queue.
|
|
|
|
* @qid: The AP queue number
|
|
|
|
* @psmid: The program supplied message identifier
|
|
|
|
* @msg: The message text
|
|
|
|
* @length: The message length
|
2009-12-07 18:51:55 +07:00
|
|
|
* @special: Special Bit
|
2006-09-20 20:58:25 +07:00
|
|
|
*
|
2008-04-17 12:46:28 +07:00
|
|
|
* Returns AP queue status structure.
|
2006-09-20 20:58:25 +07:00
|
|
|
* Condition code 1 on NQAP can't happen because the L bit is 1.
|
|
|
|
* Condition code 2 on NQAP also means the send is incomplete,
|
|
|
|
* because a segment boundary was reached. The NQAP is repeated.
|
|
|
|
*/
|
|
|
|
static inline struct ap_queue_status
|
2009-12-07 18:51:55 +07:00
|
|
|
__ap_send(ap_qid_t qid, unsigned long long psmid, void *msg, size_t length,
|
|
|
|
unsigned int special)
|
2006-09-20 20:58:25 +07:00
|
|
|
{
|
|
|
|
typedef struct { char _[length]; } msgblock;
|
|
|
|
register unsigned long reg0 asm ("0") = qid | 0x40000000UL;
|
|
|
|
register struct ap_queue_status reg1 asm ("1");
|
|
|
|
register unsigned long reg2 asm ("2") = (unsigned long) msg;
|
|
|
|
register unsigned long reg3 asm ("3") = (unsigned long) length;
|
|
|
|
register unsigned long reg4 asm ("4") = (unsigned int) (psmid >> 32);
|
2013-09-07 16:07:22 +07:00
|
|
|
register unsigned long reg5 asm ("5") = psmid & 0xffffffff;
|
2006-09-20 20:58:25 +07:00
|
|
|
|
2009-12-07 18:51:55 +07:00
|
|
|
if (special == 1)
|
|
|
|
reg0 |= 0x400000UL;
|
|
|
|
|
2006-09-20 20:58:25 +07:00
|
|
|
asm volatile (
|
2012-05-16 19:10:26 +07:00
|
|
|
"0: .long 0xb2ad0042\n" /* NQAP */
|
2006-09-20 20:58:25 +07:00
|
|
|
" brc 2,0b"
|
|
|
|
: "+d" (reg0), "=d" (reg1), "+d" (reg2), "+d" (reg3)
|
|
|
|
: "d" (reg4), "d" (reg5), "m" (*(msgblock *) msg)
|
|
|
|
: "cc" );
|
|
|
|
return reg1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ap_send(ap_qid_t qid, unsigned long long psmid, void *msg, size_t length)
|
|
|
|
{
|
|
|
|
struct ap_queue_status status;
|
|
|
|
|
2009-12-07 18:51:55 +07:00
|
|
|
status = __ap_send(qid, psmid, msg, length, 0);
|
2006-09-20 20:58:25 +07:00
|
|
|
switch (status.response_code) {
|
|
|
|
case AP_RESPONSE_NORMAL:
|
|
|
|
return 0;
|
|
|
|
case AP_RESPONSE_Q_FULL:
|
2007-07-10 16:24:19 +07:00
|
|
|
case AP_RESPONSE_RESET_IN_PROGRESS:
|
2006-09-20 20:58:25 +07:00
|
|
|
return -EBUSY;
|
2009-12-07 18:51:55 +07:00
|
|
|
case AP_RESPONSE_REQ_FAC_NOT_INST:
|
|
|
|
return -EINVAL;
|
2006-09-20 20:58:25 +07:00
|
|
|
default: /* Device is gone. */
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ap_send);
|
|
|
|
|
2008-04-17 12:46:28 +07:00
|
|
|
/**
|
|
|
|
* __ap_recv(): Receive message from adjunct processor queue.
|
|
|
|
* @qid: The AP queue number
|
|
|
|
* @psmid: Pointer to program supplied message identifier
|
|
|
|
* @msg: The message text
|
|
|
|
* @length: The message length
|
2006-09-20 20:58:25 +07:00
|
|
|
*
|
2008-04-17 12:46:28 +07:00
|
|
|
* Returns AP queue status structure.
|
2006-09-20 20:58:25 +07:00
|
|
|
* Condition code 1 on DQAP means the receive has taken place
|
|
|
|
* but only partially. The response is incomplete, hence the
|
|
|
|
* DQAP is repeated.
|
|
|
|
* Condition code 2 on DQAP also means the receive is incomplete,
|
|
|
|
* this time because a segment boundary was reached. Again, the
|
|
|
|
* DQAP is repeated.
|
|
|
|
* Note that gpr2 is used by the DQAP instruction to keep track of
|
|
|
|
* any 'residual' length, in case the instruction gets interrupted.
|
|
|
|
* Hence it gets zeroed before the instruction.
|
|
|
|
*/
|
|
|
|
static inline struct ap_queue_status
|
|
|
|
__ap_recv(ap_qid_t qid, unsigned long long *psmid, void *msg, size_t length)
|
|
|
|
{
|
|
|
|
typedef struct { char _[length]; } msgblock;
|
|
|
|
register unsigned long reg0 asm("0") = qid | 0x80000000UL;
|
|
|
|
register struct ap_queue_status reg1 asm ("1");
|
|
|
|
register unsigned long reg2 asm("2") = 0UL;
|
|
|
|
register unsigned long reg4 asm("4") = (unsigned long) msg;
|
|
|
|
register unsigned long reg5 asm("5") = (unsigned long) length;
|
|
|
|
register unsigned long reg6 asm("6") = 0UL;
|
|
|
|
register unsigned long reg7 asm("7") = 0UL;
|
|
|
|
|
|
|
|
|
|
|
|
asm volatile(
|
2012-05-16 19:10:26 +07:00
|
|
|
"0: .long 0xb2ae0064\n" /* DQAP */
|
2006-09-20 20:58:25 +07:00
|
|
|
" brc 6,0b\n"
|
|
|
|
: "+d" (reg0), "=d" (reg1), "+d" (reg2),
|
|
|
|
"+d" (reg4), "+d" (reg5), "+d" (reg6), "+d" (reg7),
|
|
|
|
"=m" (*(msgblock *) msg) : : "cc" );
|
|
|
|
*psmid = (((unsigned long long) reg6) << 32) + reg7;
|
|
|
|
return reg1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ap_recv(ap_qid_t qid, unsigned long long *psmid, void *msg, size_t length)
|
|
|
|
{
|
|
|
|
struct ap_queue_status status;
|
|
|
|
|
|
|
|
status = __ap_recv(qid, psmid, msg, length);
|
|
|
|
switch (status.response_code) {
|
|
|
|
case AP_RESPONSE_NORMAL:
|
|
|
|
return 0;
|
|
|
|
case AP_RESPONSE_NO_PENDING_REPLY:
|
|
|
|
if (status.queue_empty)
|
|
|
|
return -ENOENT;
|
|
|
|
return -EBUSY;
|
2007-07-10 16:24:19 +07:00
|
|
|
case AP_RESPONSE_RESET_IN_PROGRESS:
|
|
|
|
return -EBUSY;
|
2006-09-20 20:58:25 +07:00
|
|
|
default:
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ap_recv);
|
|
|
|
|
|
|
|
/**
|
2008-04-17 12:46:28 +07:00
|
|
|
* ap_query_queue(): Check if an AP queue is available.
|
|
|
|
* @qid: The AP queue number
|
|
|
|
* @queue_depth: Pointer to queue depth value
|
|
|
|
* @device_type: Pointer to device type value
|
2015-06-26 20:40:41 +07:00
|
|
|
* @facilities: Pointer to facility indicator
|
2006-09-20 20:58:25 +07:00
|
|
|
*/
|
2015-06-26 20:40:41 +07:00
|
|
|
static int ap_query_queue(ap_qid_t qid, int *queue_depth, int *device_type,
|
|
|
|
unsigned int *facilities)
|
2006-09-20 20:58:25 +07:00
|
|
|
{
|
|
|
|
struct ap_queue_status status;
|
2015-06-26 20:40:41 +07:00
|
|
|
unsigned long info;
|
2015-06-26 21:55:35 +07:00
|
|
|
int nd;
|
|
|
|
|
|
|
|
if (!ap_test_config_card_id(AP_QID_DEVICE(qid)))
|
|
|
|
return -ENODEV;
|
2006-09-20 20:58:25 +07:00
|
|
|
|
2015-06-26 20:40:41 +07:00
|
|
|
status = ap_test_queue(qid, &info);
|
2015-06-17 21:19:15 +07:00
|
|
|
switch (status.response_code) {
|
|
|
|
case AP_RESPONSE_NORMAL:
|
2015-06-26 20:40:41 +07:00
|
|
|
*queue_depth = (int)(info & 0xff);
|
|
|
|
*device_type = (int)((info >> 24) & 0xff);
|
|
|
|
*facilities = (unsigned int)(info >> 32);
|
2015-06-26 21:55:35 +07:00
|
|
|
/* Update maximum domain id */
|
|
|
|
nd = (info >> 16) & 0xff;
|
|
|
|
if ((info & (1UL << 57)) && nd > 0)
|
|
|
|
ap_max_domain_id = nd;
|
2015-06-17 21:19:15 +07:00
|
|
|
return 0;
|
|
|
|
case AP_RESPONSE_Q_NOT_AVAIL:
|
|
|
|
case AP_RESPONSE_DECONFIGURED:
|
|
|
|
case AP_RESPONSE_CHECKSTOPPED:
|
|
|
|
case AP_RESPONSE_INVALID_ADDRESS:
|
|
|
|
return -ENODEV;
|
|
|
|
case AP_RESPONSE_RESET_IN_PROGRESS:
|
|
|
|
case AP_RESPONSE_OTHERWISE_CHANGED:
|
|
|
|
case AP_RESPONSE_BUSY:
|
|
|
|
return -EBUSY;
|
|
|
|
default:
|
|
|
|
BUG();
|
2006-09-20 20:58:25 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-14 22:01:23 +07:00
|
|
|
/* State machine definitions and helpers */
|
|
|
|
|
|
|
|
static void ap_sm_wait(enum ap_wait wait)
|
|
|
|
{
|
|
|
|
ktime_t hr_time;
|
|
|
|
|
|
|
|
switch (wait) {
|
|
|
|
case AP_WAIT_AGAIN:
|
|
|
|
case AP_WAIT_INTERRUPT:
|
|
|
|
if (ap_using_interrupts())
|
|
|
|
break;
|
|
|
|
if (ap_poll_kthread) {
|
|
|
|
wake_up(&ap_poll_wait);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* Fall through */
|
|
|
|
case AP_WAIT_TIMEOUT:
|
|
|
|
spin_lock_bh(&ap_poll_timer_lock);
|
|
|
|
if (!hrtimer_is_queued(&ap_poll_timer)) {
|
|
|
|
hr_time = ktime_set(0, poll_timeout);
|
|
|
|
hrtimer_forward_now(&ap_poll_timer, hr_time);
|
|
|
|
hrtimer_restart(&ap_poll_timer);
|
|
|
|
}
|
|
|
|
spin_unlock_bh(&ap_poll_timer_lock);
|
|
|
|
break;
|
|
|
|
case AP_WAIT_NONE:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum ap_wait ap_sm_nop(struct ap_device *ap_dev)
|
|
|
|
{
|
|
|
|
return AP_WAIT_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ap_sm_recv(): Receive pending reply messages from an AP device but do
|
|
|
|
* not change the state of the device.
|
|
|
|
* @ap_dev: pointer to the AP device
|
|
|
|
*
|
|
|
|
* Returns AP_WAIT_NONE, AP_WAIT_AGAIN, or AP_WAIT_INTERRUPT
|
|
|
|
*/
|
|
|
|
static struct ap_queue_status ap_sm_recv(struct ap_device *ap_dev)
|
|
|
|
{
|
|
|
|
struct ap_queue_status status;
|
|
|
|
struct ap_message *ap_msg;
|
|
|
|
|
|
|
|
status = __ap_recv(ap_dev->qid, &ap_dev->reply->psmid,
|
|
|
|
ap_dev->reply->message, ap_dev->reply->length);
|
|
|
|
switch (status.response_code) {
|
|
|
|
case AP_RESPONSE_NORMAL:
|
|
|
|
atomic_dec(&ap_poll_requests);
|
|
|
|
ap_dev->queue_count--;
|
|
|
|
if (ap_dev->queue_count > 0)
|
|
|
|
mod_timer(&ap_dev->timeout,
|
|
|
|
jiffies + ap_dev->drv->request_timeout);
|
|
|
|
list_for_each_entry(ap_msg, &ap_dev->pendingq, list) {
|
|
|
|
if (ap_msg->psmid != ap_dev->reply->psmid)
|
|
|
|
continue;
|
|
|
|
list_del_init(&ap_msg->list);
|
|
|
|
ap_dev->pendingq_count--;
|
|
|
|
ap_msg->receive(ap_dev, ap_msg, ap_dev->reply);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case AP_RESPONSE_NO_PENDING_REPLY:
|
|
|
|
if (!status.queue_empty || ap_dev->queue_count <= 0)
|
|
|
|
break;
|
|
|
|
/* The card shouldn't forget requests but who knows. */
|
|
|
|
atomic_sub(ap_dev->queue_count, &ap_poll_requests);
|
|
|
|
ap_dev->queue_count = 0;
|
|
|
|
list_splice_init(&ap_dev->pendingq, &ap_dev->requestq);
|
|
|
|
ap_dev->requestq_count += ap_dev->pendingq_count;
|
|
|
|
ap_dev->pendingq_count = 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ap_sm_read(): Receive pending reply messages from an AP device.
|
|
|
|
* @ap_dev: pointer to the AP device
|
|
|
|
*
|
|
|
|
* Returns AP_WAIT_NONE, AP_WAIT_AGAIN, or AP_WAIT_INTERRUPT
|
|
|
|
*/
|
|
|
|
static enum ap_wait ap_sm_read(struct ap_device *ap_dev)
|
|
|
|
{
|
|
|
|
struct ap_queue_status status;
|
|
|
|
|
|
|
|
status = ap_sm_recv(ap_dev);
|
|
|
|
switch (status.response_code) {
|
|
|
|
case AP_RESPONSE_NORMAL:
|
|
|
|
if (ap_dev->queue_count > 0)
|
|
|
|
return AP_WAIT_AGAIN;
|
|
|
|
ap_dev->state = AP_STATE_IDLE;
|
|
|
|
return AP_WAIT_NONE;
|
|
|
|
case AP_RESPONSE_NO_PENDING_REPLY:
|
|
|
|
if (ap_dev->queue_count > 0)
|
|
|
|
return AP_WAIT_INTERRUPT;
|
|
|
|
ap_dev->state = AP_STATE_IDLE;
|
|
|
|
return AP_WAIT_NONE;
|
|
|
|
default:
|
|
|
|
ap_dev->state = AP_STATE_BORKED;
|
|
|
|
return AP_WAIT_NONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ap_sm_write(): Send messages from the request queue to an AP device.
|
|
|
|
* @ap_dev: pointer to the AP device
|
|
|
|
*
|
|
|
|
* Returns AP_WAIT_NONE, AP_WAIT_AGAIN, or AP_WAIT_INTERRUPT
|
|
|
|
*/
|
|
|
|
static enum ap_wait ap_sm_write(struct ap_device *ap_dev)
|
|
|
|
{
|
|
|
|
struct ap_queue_status status;
|
|
|
|
struct ap_message *ap_msg;
|
|
|
|
|
|
|
|
if (ap_dev->requestq_count <= 0)
|
|
|
|
return AP_WAIT_NONE;
|
|
|
|
/* Start the next request on the queue. */
|
|
|
|
ap_msg = list_entry(ap_dev->requestq.next, struct ap_message, list);
|
|
|
|
status = __ap_send(ap_dev->qid, ap_msg->psmid,
|
|
|
|
ap_msg->message, ap_msg->length, ap_msg->special);
|
|
|
|
switch (status.response_code) {
|
|
|
|
case AP_RESPONSE_NORMAL:
|
|
|
|
atomic_inc(&ap_poll_requests);
|
|
|
|
ap_dev->queue_count++;
|
|
|
|
if (ap_dev->queue_count == 1)
|
|
|
|
mod_timer(&ap_dev->timeout,
|
|
|
|
jiffies + ap_dev->drv->request_timeout);
|
|
|
|
list_move_tail(&ap_msg->list, &ap_dev->pendingq);
|
|
|
|
ap_dev->requestq_count--;
|
|
|
|
ap_dev->pendingq_count++;
|
|
|
|
if (ap_dev->queue_count < ap_dev->queue_depth) {
|
|
|
|
ap_dev->state = AP_STATE_WORKING;
|
|
|
|
return AP_WAIT_AGAIN;
|
|
|
|
}
|
|
|
|
/* fall through */
|
|
|
|
case AP_RESPONSE_Q_FULL:
|
|
|
|
ap_dev->state = AP_STATE_QUEUE_FULL;
|
|
|
|
return AP_WAIT_INTERRUPT;
|
|
|
|
case AP_RESPONSE_RESET_IN_PROGRESS:
|
|
|
|
ap_dev->state = AP_STATE_RESET_WAIT;
|
|
|
|
return AP_WAIT_TIMEOUT;
|
|
|
|
case AP_RESPONSE_MESSAGE_TOO_BIG:
|
|
|
|
case AP_RESPONSE_REQ_FAC_NOT_INST:
|
|
|
|
list_del_init(&ap_msg->list);
|
|
|
|
ap_dev->requestq_count--;
|
|
|
|
ap_msg->rc = -EINVAL;
|
|
|
|
ap_msg->receive(ap_dev, ap_msg, NULL);
|
|
|
|
return AP_WAIT_AGAIN;
|
|
|
|
default:
|
|
|
|
ap_dev->state = AP_STATE_BORKED;
|
|
|
|
return AP_WAIT_NONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-20 20:58:25 +07:00
|
|
|
/**
|
2015-09-14 22:01:23 +07:00
|
|
|
* ap_sm_read_write(): Send and receive messages to/from an AP device.
|
|
|
|
* @ap_dev: pointer to the AP device
|
|
|
|
*
|
|
|
|
* Returns AP_WAIT_NONE, AP_WAIT_AGAIN, or AP_WAIT_INTERRUPT
|
|
|
|
*/
|
|
|
|
static enum ap_wait ap_sm_read_write(struct ap_device *ap_dev)
|
|
|
|
{
|
|
|
|
return min(ap_sm_read(ap_dev), ap_sm_write(ap_dev));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ap_sm_reset(): Reset an AP queue.
|
2008-04-17 12:46:28 +07:00
|
|
|
* @qid: The AP queue number
|
|
|
|
*
|
2015-06-17 21:19:15 +07:00
|
|
|
* Submit the Reset command to an AP queue.
|
2006-09-20 20:58:25 +07:00
|
|
|
*/
|
2015-09-14 22:01:23 +07:00
|
|
|
static enum ap_wait ap_sm_reset(struct ap_device *ap_dev)
|
2006-09-20 20:58:25 +07:00
|
|
|
{
|
|
|
|
struct ap_queue_status status;
|
|
|
|
|
2015-06-17 21:19:15 +07:00
|
|
|
status = ap_reset_queue(ap_dev->qid);
|
|
|
|
switch (status.response_code) {
|
|
|
|
case AP_RESPONSE_NORMAL:
|
|
|
|
case AP_RESPONSE_RESET_IN_PROGRESS:
|
2015-09-14 22:01:23 +07:00
|
|
|
ap_dev->state = AP_STATE_RESET_WAIT;
|
|
|
|
ap_dev->interrupt = AP_INTR_DISABLED;
|
|
|
|
return AP_WAIT_TIMEOUT;
|
2015-06-17 21:19:15 +07:00
|
|
|
case AP_RESPONSE_BUSY:
|
2015-09-14 22:01:23 +07:00
|
|
|
return AP_WAIT_TIMEOUT;
|
2015-06-17 21:19:15 +07:00
|
|
|
case AP_RESPONSE_Q_NOT_AVAIL:
|
|
|
|
case AP_RESPONSE_DECONFIGURED:
|
|
|
|
case AP_RESPONSE_CHECKSTOPPED:
|
|
|
|
default:
|
2015-09-14 22:01:23 +07:00
|
|
|
ap_dev->state = AP_STATE_BORKED;
|
|
|
|
return AP_WAIT_NONE;
|
2008-12-25 19:38:41 +07:00
|
|
|
}
|
2006-09-20 20:58:25 +07:00
|
|
|
}
|
|
|
|
|
2007-07-10 16:24:19 +07:00
|
|
|
/**
|
2015-09-14 22:01:23 +07:00
|
|
|
* ap_sm_reset_wait(): Test queue for completion of the reset operation
|
|
|
|
* @ap_dev: pointer to the AP device
|
2008-04-17 12:46:28 +07:00
|
|
|
*
|
2015-09-14 22:01:23 +07:00
|
|
|
* Returns AP_POLL_IMMEDIATELY, AP_POLL_AFTER_TIMEROUT or 0.
|
2007-07-10 16:24:19 +07:00
|
|
|
*/
|
2015-09-14 22:01:23 +07:00
|
|
|
static enum ap_wait ap_sm_reset_wait(struct ap_device *ap_dev)
|
2007-07-10 16:24:19 +07:00
|
|
|
{
|
2015-09-14 22:01:23 +07:00
|
|
|
struct ap_queue_status status;
|
|
|
|
unsigned long info;
|
2007-07-10 16:24:19 +07:00
|
|
|
|
2015-09-14 22:01:23 +07:00
|
|
|
if (ap_dev->queue_count > 0)
|
|
|
|
/* Try to read a completed message and get the status */
|
|
|
|
status = ap_sm_recv(ap_dev);
|
|
|
|
else
|
|
|
|
/* Get the status with TAPQ */
|
|
|
|
status = ap_test_queue(ap_dev->qid, &info);
|
|
|
|
|
|
|
|
switch (status.response_code) {
|
|
|
|
case AP_RESPONSE_NORMAL:
|
|
|
|
if (ap_using_interrupts() &&
|
|
|
|
ap_queue_enable_interruption(ap_dev,
|
|
|
|
ap_airq.lsi_ptr) == 0)
|
|
|
|
ap_dev->state = AP_STATE_SETIRQ_WAIT;
|
|
|
|
else
|
|
|
|
ap_dev->state = (ap_dev->queue_count > 0) ?
|
|
|
|
AP_STATE_WORKING : AP_STATE_IDLE;
|
|
|
|
return AP_WAIT_AGAIN;
|
|
|
|
case AP_RESPONSE_BUSY:
|
|
|
|
case AP_RESPONSE_RESET_IN_PROGRESS:
|
|
|
|
return AP_WAIT_TIMEOUT;
|
|
|
|
case AP_RESPONSE_Q_NOT_AVAIL:
|
|
|
|
case AP_RESPONSE_DECONFIGURED:
|
|
|
|
case AP_RESPONSE_CHECKSTOPPED:
|
|
|
|
default:
|
|
|
|
ap_dev->state = AP_STATE_BORKED;
|
|
|
|
return AP_WAIT_NONE;
|
2007-07-10 16:24:19 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-09-14 22:01:23 +07:00
|
|
|
* ap_sm_setirq_wait(): Test queue for completion of the irq enablement
|
|
|
|
* @ap_dev: pointer to the AP device
|
2008-04-17 12:46:28 +07:00
|
|
|
*
|
2015-09-14 22:01:23 +07:00
|
|
|
* Returns AP_POLL_IMMEDIATELY, AP_POLL_AFTER_TIMEROUT or 0.
|
2007-07-10 16:24:19 +07:00
|
|
|
*/
|
2015-09-14 22:01:23 +07:00
|
|
|
static enum ap_wait ap_sm_setirq_wait(struct ap_device *ap_dev)
|
2007-07-10 16:24:19 +07:00
|
|
|
{
|
2015-09-14 22:01:23 +07:00
|
|
|
struct ap_queue_status status;
|
|
|
|
unsigned long info;
|
2007-07-10 16:24:19 +07:00
|
|
|
|
|
|
|
if (ap_dev->queue_count > 0)
|
2015-09-14 22:01:23 +07:00
|
|
|
/* Try to read a completed message and get the status */
|
|
|
|
status = ap_sm_recv(ap_dev);
|
2007-07-10 16:24:19 +07:00
|
|
|
else
|
2015-09-14 22:01:23 +07:00
|
|
|
/* Get the status with TAPQ */
|
|
|
|
status = ap_test_queue(ap_dev->qid, &info);
|
|
|
|
|
|
|
|
if (status.int_enabled == 1) {
|
|
|
|
/* Irqs are now enabled */
|
|
|
|
ap_dev->interrupt = AP_INTR_ENABLED;
|
|
|
|
ap_dev->state = (ap_dev->queue_count > 0) ?
|
|
|
|
AP_STATE_WORKING : AP_STATE_IDLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (status.response_code) {
|
|
|
|
case AP_RESPONSE_NORMAL:
|
|
|
|
if (ap_dev->queue_count > 0)
|
|
|
|
return AP_WAIT_AGAIN;
|
|
|
|
/* fallthrough */
|
|
|
|
case AP_RESPONSE_NO_PENDING_REPLY:
|
|
|
|
return AP_WAIT_TIMEOUT;
|
|
|
|
default:
|
|
|
|
ap_dev->state = AP_STATE_BORKED;
|
|
|
|
return AP_WAIT_NONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* AP state machine jump table
|
|
|
|
*/
|
|
|
|
ap_func_t *ap_jumptable[NR_AP_STATES][NR_AP_EVENTS] = {
|
|
|
|
[AP_STATE_RESET_START] = {
|
|
|
|
[AP_EVENT_POLL] = ap_sm_reset,
|
|
|
|
[AP_EVENT_TIMEOUT] = ap_sm_nop,
|
|
|
|
},
|
|
|
|
[AP_STATE_RESET_WAIT] = {
|
|
|
|
[AP_EVENT_POLL] = ap_sm_reset_wait,
|
|
|
|
[AP_EVENT_TIMEOUT] = ap_sm_nop,
|
|
|
|
},
|
|
|
|
[AP_STATE_SETIRQ_WAIT] = {
|
|
|
|
[AP_EVENT_POLL] = ap_sm_setirq_wait,
|
|
|
|
[AP_EVENT_TIMEOUT] = ap_sm_nop,
|
|
|
|
},
|
|
|
|
[AP_STATE_IDLE] = {
|
|
|
|
[AP_EVENT_POLL] = ap_sm_write,
|
|
|
|
[AP_EVENT_TIMEOUT] = ap_sm_nop,
|
|
|
|
},
|
|
|
|
[AP_STATE_WORKING] = {
|
|
|
|
[AP_EVENT_POLL] = ap_sm_read_write,
|
|
|
|
[AP_EVENT_TIMEOUT] = ap_sm_reset,
|
|
|
|
},
|
|
|
|
[AP_STATE_QUEUE_FULL] = {
|
|
|
|
[AP_EVENT_POLL] = ap_sm_read,
|
|
|
|
[AP_EVENT_TIMEOUT] = ap_sm_reset,
|
|
|
|
},
|
|
|
|
[AP_STATE_SUSPEND_WAIT] = {
|
|
|
|
[AP_EVENT_POLL] = ap_sm_read,
|
|
|
|
[AP_EVENT_TIMEOUT] = ap_sm_nop,
|
|
|
|
},
|
|
|
|
[AP_STATE_BORKED] = {
|
|
|
|
[AP_EVENT_POLL] = ap_sm_nop,
|
|
|
|
[AP_EVENT_TIMEOUT] = ap_sm_nop,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline enum ap_wait ap_sm_event(struct ap_device *ap_dev,
|
|
|
|
enum ap_event event)
|
|
|
|
{
|
|
|
|
return ap_jumptable[ap_dev->state][event](ap_dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline enum ap_wait ap_sm_event_loop(struct ap_device *ap_dev,
|
|
|
|
enum ap_event event)
|
|
|
|
{
|
|
|
|
enum ap_wait wait;
|
|
|
|
|
|
|
|
while ((wait = ap_sm_event(ap_dev, event)) == AP_WAIT_AGAIN)
|
|
|
|
;
|
|
|
|
return wait;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ap_request_timeout(): Handling of request timeouts
|
|
|
|
* @data: Holds the AP device.
|
|
|
|
*
|
|
|
|
* Handles request timeouts.
|
|
|
|
*/
|
|
|
|
static void ap_request_timeout(unsigned long data)
|
|
|
|
{
|
|
|
|
struct ap_device *ap_dev = (struct ap_device *) data;
|
|
|
|
|
|
|
|
if (ap_suspend_flag)
|
|
|
|
return;
|
|
|
|
spin_lock_bh(&ap_dev->lock);
|
|
|
|
ap_sm_wait(ap_sm_event(ap_dev, AP_EVENT_TIMEOUT));
|
|
|
|
spin_unlock_bh(&ap_dev->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ap_poll_timeout(): AP receive polling for finished AP requests.
|
|
|
|
* @unused: Unused pointer.
|
|
|
|
*
|
|
|
|
* Schedules the AP tasklet using a high resolution timer.
|
|
|
|
*/
|
|
|
|
static enum hrtimer_restart ap_poll_timeout(struct hrtimer *unused)
|
|
|
|
{
|
|
|
|
if (!ap_suspend_flag)
|
|
|
|
tasklet_schedule(&ap_tasklet);
|
|
|
|
return HRTIMER_NORESTART;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ap_interrupt_handler() - Schedule ap_tasklet on interrupt
|
|
|
|
* @airq: pointer to adapter interrupt descriptor
|
|
|
|
*/
|
|
|
|
static void ap_interrupt_handler(struct airq_struct *airq)
|
|
|
|
{
|
|
|
|
inc_irq_stat(IRQIO_APB);
|
|
|
|
if (!ap_suspend_flag)
|
|
|
|
tasklet_schedule(&ap_tasklet);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ap_tasklet_fn(): Tasklet to poll all AP devices.
|
|
|
|
* @dummy: Unused variable
|
|
|
|
*
|
|
|
|
* Poll all AP devices on the bus.
|
|
|
|
*/
|
|
|
|
static void ap_tasklet_fn(unsigned long dummy)
|
|
|
|
{
|
|
|
|
struct ap_device *ap_dev;
|
|
|
|
enum ap_wait wait = AP_WAIT_NONE;
|
|
|
|
|
|
|
|
/* Reset the indicator if interrupts are used. Thus new interrupts can
|
|
|
|
* be received. Doing it in the beginning of the tasklet is therefor
|
|
|
|
* important that no requests on any AP get lost.
|
|
|
|
*/
|
|
|
|
if (ap_using_interrupts())
|
|
|
|
xchg(ap_airq.lsi_ptr, 0);
|
|
|
|
|
|
|
|
spin_lock(&ap_device_list_lock);
|
|
|
|
list_for_each_entry(ap_dev, &ap_device_list, list) {
|
|
|
|
spin_lock_bh(&ap_dev->lock);
|
|
|
|
wait = min(wait, ap_sm_event_loop(ap_dev, AP_EVENT_POLL));
|
|
|
|
spin_unlock_bh(&ap_dev->lock);
|
|
|
|
}
|
|
|
|
spin_unlock(&ap_device_list_lock);
|
|
|
|
ap_sm_wait(wait);
|
2007-07-10 16:24:19 +07:00
|
|
|
}
|
|
|
|
|
2015-07-17 18:43:18 +07:00
|
|
|
/**
|
|
|
|
* ap_poll_thread(): Thread that polls for finished requests.
|
|
|
|
* @data: Unused pointer
|
|
|
|
*
|
|
|
|
* AP bus poll thread. The purpose of this thread is to poll for
|
|
|
|
* finished requests in a loop if there is a "free" cpu - that is
|
|
|
|
* a cpu that doesn't have anything better to do. The polling stops
|
|
|
|
* as soon as there is another task or if all messages have been
|
|
|
|
* delivered.
|
|
|
|
*/
|
|
|
|
static int ap_poll_thread(void *data)
|
|
|
|
{
|
|
|
|
DECLARE_WAITQUEUE(wait, current);
|
|
|
|
|
|
|
|
set_user_nice(current, MAX_NICE);
|
|
|
|
set_freezable();
|
|
|
|
while (!kthread_should_stop()) {
|
|
|
|
add_wait_queue(&ap_poll_wait, &wait);
|
|
|
|
set_current_state(TASK_INTERRUPTIBLE);
|
|
|
|
if (ap_suspend_flag ||
|
|
|
|
atomic_read(&ap_poll_requests) <= 0) {
|
|
|
|
schedule();
|
|
|
|
try_to_freeze();
|
|
|
|
}
|
|
|
|
set_current_state(TASK_RUNNING);
|
|
|
|
remove_wait_queue(&ap_poll_wait, &wait);
|
|
|
|
if (need_resched()) {
|
|
|
|
schedule();
|
|
|
|
try_to_freeze();
|
|
|
|
continue;
|
|
|
|
}
|
2015-09-14 22:01:23 +07:00
|
|
|
ap_tasklet_fn(0);
|
2015-07-17 18:43:18 +07:00
|
|
|
} while (!kthread_should_stop());
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ap_poll_thread_start(void)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (ap_using_interrupts() || ap_poll_kthread)
|
|
|
|
return 0;
|
|
|
|
mutex_lock(&ap_poll_thread_mutex);
|
|
|
|
ap_poll_kthread = kthread_run(ap_poll_thread, NULL, "appoll");
|
|
|
|
rc = PTR_RET(ap_poll_kthread);
|
|
|
|
if (rc)
|
|
|
|
ap_poll_kthread = NULL;
|
|
|
|
mutex_unlock(&ap_poll_thread_mutex);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ap_poll_thread_stop(void)
|
|
|
|
{
|
|
|
|
if (!ap_poll_kthread)
|
|
|
|
return;
|
|
|
|
mutex_lock(&ap_poll_thread_mutex);
|
|
|
|
kthread_stop(ap_poll_kthread);
|
|
|
|
ap_poll_kthread = NULL;
|
|
|
|
mutex_unlock(&ap_poll_thread_mutex);
|
|
|
|
}
|
|
|
|
|
2015-09-14 22:01:23 +07:00
|
|
|
/**
|
|
|
|
* ap_queue_message(): Queue a request to an AP device.
|
|
|
|
* @ap_dev: The AP device to queue the message to
|
|
|
|
* @ap_msg: The message that is to be added
|
|
|
|
*/
|
|
|
|
void ap_queue_message(struct ap_device *ap_dev, struct ap_message *ap_msg)
|
|
|
|
{
|
|
|
|
/* For asynchronous message handling a valid receive-callback
|
|
|
|
* is required. */
|
|
|
|
BUG_ON(!ap_msg->receive);
|
|
|
|
|
|
|
|
spin_lock_bh(&ap_dev->lock);
|
|
|
|
/* Queue the message. */
|
|
|
|
list_add_tail(&ap_msg->list, &ap_dev->requestq);
|
|
|
|
ap_dev->requestq_count++;
|
|
|
|
ap_dev->total_request_count++;
|
|
|
|
/* Send/receive as many request from the queue as possible. */
|
|
|
|
ap_sm_wait(ap_sm_event_loop(ap_dev, AP_EVENT_POLL));
|
|
|
|
spin_unlock_bh(&ap_dev->lock);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ap_queue_message);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ap_cancel_message(): Cancel a crypto request.
|
|
|
|
* @ap_dev: The AP device that has the message queued
|
|
|
|
* @ap_msg: The message that is to be removed
|
|
|
|
*
|
|
|
|
* Cancel a crypto request. This is done by removing the request
|
|
|
|
* from the device pending or request queue. Note that the
|
|
|
|
* request stays on the AP queue. When it finishes the message
|
|
|
|
* reply will be discarded because the psmid can't be found.
|
|
|
|
*/
|
|
|
|
void ap_cancel_message(struct ap_device *ap_dev, struct ap_message *ap_msg)
|
|
|
|
{
|
|
|
|
struct ap_message *tmp;
|
|
|
|
|
|
|
|
spin_lock_bh(&ap_dev->lock);
|
|
|
|
if (!list_empty(&ap_msg->list)) {
|
|
|
|
list_for_each_entry(tmp, &ap_dev->pendingq, list)
|
|
|
|
if (tmp->psmid == ap_msg->psmid) {
|
|
|
|
ap_dev->pendingq_count--;
|
|
|
|
goto found;
|
|
|
|
}
|
|
|
|
ap_dev->requestq_count--;
|
|
|
|
found:
|
|
|
|
list_del_init(&ap_msg->list);
|
|
|
|
}
|
|
|
|
spin_unlock_bh(&ap_dev->lock);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ap_cancel_message);
|
|
|
|
|
2008-04-17 12:46:28 +07:00
|
|
|
/*
|
2006-09-20 20:58:25 +07:00
|
|
|
* AP device related attributes.
|
|
|
|
*/
|
|
|
|
static ssize_t ap_hwtype_show(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
struct ap_device *ap_dev = to_ap_dev(dev);
|
|
|
|
return snprintf(buf, PAGE_SIZE, "%d\n", ap_dev->device_type);
|
|
|
|
}
|
|
|
|
|
2008-12-25 19:38:42 +07:00
|
|
|
static DEVICE_ATTR(hwtype, 0444, ap_hwtype_show, NULL);
|
2014-10-02 19:48:46 +07:00
|
|
|
|
|
|
|
static ssize_t ap_raw_hwtype_show(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
struct ap_device *ap_dev = to_ap_dev(dev);
|
|
|
|
|
|
|
|
return snprintf(buf, PAGE_SIZE, "%d\n", ap_dev->raw_hwtype);
|
|
|
|
}
|
|
|
|
|
|
|
|
static DEVICE_ATTR(raw_hwtype, 0444, ap_raw_hwtype_show, NULL);
|
|
|
|
|
2006-09-20 20:58:25 +07:00
|
|
|
static ssize_t ap_depth_show(struct device *dev, struct device_attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
struct ap_device *ap_dev = to_ap_dev(dev);
|
|
|
|
return snprintf(buf, PAGE_SIZE, "%d\n", ap_dev->queue_depth);
|
|
|
|
}
|
|
|
|
|
2008-12-25 19:38:42 +07:00
|
|
|
static DEVICE_ATTR(depth, 0444, ap_depth_show, NULL);
|
2006-09-20 20:58:25 +07:00
|
|
|
static ssize_t ap_request_count_show(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
struct ap_device *ap_dev = to_ap_dev(dev);
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
spin_lock_bh(&ap_dev->lock);
|
|
|
|
rc = snprintf(buf, PAGE_SIZE, "%d\n", ap_dev->total_request_count);
|
|
|
|
spin_unlock_bh(&ap_dev->lock);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static DEVICE_ATTR(request_count, 0444, ap_request_count_show, NULL);
|
|
|
|
|
2012-08-28 21:43:48 +07:00
|
|
|
static ssize_t ap_requestq_count_show(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
struct ap_device *ap_dev = to_ap_dev(dev);
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
spin_lock_bh(&ap_dev->lock);
|
|
|
|
rc = snprintf(buf, PAGE_SIZE, "%d\n", ap_dev->requestq_count);
|
|
|
|
spin_unlock_bh(&ap_dev->lock);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static DEVICE_ATTR(requestq_count, 0444, ap_requestq_count_show, NULL);
|
|
|
|
|
|
|
|
static ssize_t ap_pendingq_count_show(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
struct ap_device *ap_dev = to_ap_dev(dev);
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
spin_lock_bh(&ap_dev->lock);
|
|
|
|
rc = snprintf(buf, PAGE_SIZE, "%d\n", ap_dev->pendingq_count);
|
|
|
|
spin_unlock_bh(&ap_dev->lock);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static DEVICE_ATTR(pendingq_count, 0444, ap_pendingq_count_show, NULL);
|
|
|
|
|
2015-06-17 21:19:15 +07:00
|
|
|
static ssize_t ap_reset_show(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
struct ap_device *ap_dev = to_ap_dev(dev);
|
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
spin_lock_bh(&ap_dev->lock);
|
2015-09-14 22:01:23 +07:00
|
|
|
switch (ap_dev->state) {
|
|
|
|
case AP_STATE_RESET_START:
|
|
|
|
case AP_STATE_RESET_WAIT:
|
|
|
|
rc = snprintf(buf, PAGE_SIZE, "Reset in progress.\n");
|
2015-06-17 21:19:15 +07:00
|
|
|
break;
|
2015-09-14 22:01:23 +07:00
|
|
|
case AP_STATE_WORKING:
|
|
|
|
case AP_STATE_QUEUE_FULL:
|
2015-06-17 21:19:15 +07:00
|
|
|
rc = snprintf(buf, PAGE_SIZE, "Reset Timer armed.\n");
|
|
|
|
break;
|
|
|
|
default:
|
2015-09-14 22:01:23 +07:00
|
|
|
rc = snprintf(buf, PAGE_SIZE, "No Reset Timer set.\n");
|
2015-06-17 21:19:15 +07:00
|
|
|
}
|
|
|
|
spin_unlock_bh(&ap_dev->lock);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static DEVICE_ATTR(reset, 0444, ap_reset_show, NULL);
|
|
|
|
|
|
|
|
static ssize_t ap_interrupt_show(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
struct ap_device *ap_dev = to_ap_dev(dev);
|
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
spin_lock_bh(&ap_dev->lock);
|
2015-09-14 22:01:23 +07:00
|
|
|
if (ap_dev->state == AP_STATE_SETIRQ_WAIT)
|
2015-06-17 21:19:15 +07:00
|
|
|
rc = snprintf(buf, PAGE_SIZE, "Enable Interrupt pending.\n");
|
2015-09-14 22:01:23 +07:00
|
|
|
else if (ap_dev->interrupt == AP_INTR_ENABLED)
|
|
|
|
rc = snprintf(buf, PAGE_SIZE, "Interrupts enabled.\n");
|
|
|
|
else
|
|
|
|
rc = snprintf(buf, PAGE_SIZE, "Interrupts disabled.\n");
|
2015-06-17 21:19:15 +07:00
|
|
|
spin_unlock_bh(&ap_dev->lock);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static DEVICE_ATTR(interrupt, 0444, ap_interrupt_show, NULL);
|
|
|
|
|
2006-09-20 20:58:25 +07:00
|
|
|
static ssize_t ap_modalias_show(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
{
|
2015-06-17 21:19:15 +07:00
|
|
|
return sprintf(buf, "ap:t%02X\n", to_ap_dev(dev)->device_type);
|
2006-09-20 20:58:25 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static DEVICE_ATTR(modalias, 0444, ap_modalias_show, NULL);
|
|
|
|
|
2012-08-28 21:43:48 +07:00
|
|
|
static ssize_t ap_functions_show(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
struct ap_device *ap_dev = to_ap_dev(dev);
|
|
|
|
return snprintf(buf, PAGE_SIZE, "0x%08X\n", ap_dev->functions);
|
|
|
|
}
|
|
|
|
|
|
|
|
static DEVICE_ATTR(ap_functions, 0444, ap_functions_show, NULL);
|
|
|
|
|
2006-09-20 20:58:25 +07:00
|
|
|
static struct attribute *ap_dev_attrs[] = {
|
|
|
|
&dev_attr_hwtype.attr,
|
2014-10-02 19:48:46 +07:00
|
|
|
&dev_attr_raw_hwtype.attr,
|
2006-09-20 20:58:25 +07:00
|
|
|
&dev_attr_depth.attr,
|
|
|
|
&dev_attr_request_count.attr,
|
2012-08-28 21:43:48 +07:00
|
|
|
&dev_attr_requestq_count.attr,
|
|
|
|
&dev_attr_pendingq_count.attr,
|
2015-06-17 21:19:15 +07:00
|
|
|
&dev_attr_reset.attr,
|
|
|
|
&dev_attr_interrupt.attr,
|
2006-09-20 20:58:25 +07:00
|
|
|
&dev_attr_modalias.attr,
|
2012-08-28 21:43:48 +07:00
|
|
|
&dev_attr_ap_functions.attr,
|
2006-09-20 20:58:25 +07:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
static struct attribute_group ap_dev_attr_group = {
|
|
|
|
.attrs = ap_dev_attrs
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2008-04-17 12:46:28 +07:00
|
|
|
* ap_bus_match()
|
|
|
|
* @dev: Pointer to device
|
|
|
|
* @drv: Pointer to device_driver
|
|
|
|
*
|
2006-09-20 20:58:25 +07:00
|
|
|
* AP bus driver registration/unregistration.
|
|
|
|
*/
|
|
|
|
static int ap_bus_match(struct device *dev, struct device_driver *drv)
|
|
|
|
{
|
|
|
|
struct ap_device *ap_dev = to_ap_dev(dev);
|
|
|
|
struct ap_driver *ap_drv = to_ap_drv(drv);
|
|
|
|
struct ap_device_id *id;
|
|
|
|
|
2008-04-17 12:46:28 +07:00
|
|
|
/*
|
2006-09-20 20:58:25 +07:00
|
|
|
* Compare device type of the device with the list of
|
|
|
|
* supported types of the device_driver.
|
|
|
|
*/
|
|
|
|
for (id = ap_drv->ids; id->match_flags; id++) {
|
|
|
|
if ((id->match_flags & AP_DEVICE_ID_MATCH_DEVICE_TYPE) &&
|
|
|
|
(id->dev_type != ap_dev->device_type))
|
|
|
|
continue;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-04-17 12:46:28 +07:00
|
|
|
* ap_uevent(): Uevent function for AP devices.
|
|
|
|
* @dev: Pointer to device
|
|
|
|
* @env: Pointer to kobj_uevent_env
|
|
|
|
*
|
|
|
|
* It sets up a single environment variable DEV_TYPE which contains the
|
|
|
|
* hardware device type.
|
2006-09-20 20:58:25 +07:00
|
|
|
*/
|
2007-08-14 20:15:12 +07:00
|
|
|
static int ap_uevent (struct device *dev, struct kobj_uevent_env *env)
|
2006-09-20 20:58:25 +07:00
|
|
|
{
|
|
|
|
struct ap_device *ap_dev = to_ap_dev(dev);
|
2007-08-14 20:15:12 +07:00
|
|
|
int retval = 0;
|
2006-09-20 20:58:25 +07:00
|
|
|
|
|
|
|
if (!ap_dev)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
/* Set up DEV_TYPE environment variable. */
|
2007-08-14 20:15:12 +07:00
|
|
|
retval = add_uevent_var(env, "DEV_TYPE=%04X", ap_dev->device_type);
|
2007-03-31 12:23:12 +07:00
|
|
|
if (retval)
|
|
|
|
return retval;
|
|
|
|
|
2006-12-04 21:40:10 +07:00
|
|
|
/* Add MODALIAS= */
|
2007-08-14 20:15:12 +07:00
|
|
|
retval = add_uevent_var(env, "MODALIAS=ap:t%02X", ap_dev->device_type);
|
2007-03-31 12:23:12 +07:00
|
|
|
|
|
|
|
return retval;
|
2006-09-20 20:58:25 +07:00
|
|
|
}
|
|
|
|
|
2015-07-17 18:43:18 +07:00
|
|
|
static int ap_dev_suspend(struct device *dev, pm_message_t state)
|
2009-06-22 17:08:16 +07:00
|
|
|
{
|
|
|
|
struct ap_device *ap_dev = to_ap_dev(dev);
|
|
|
|
|
|
|
|
/* Poll on the device until all requests are finished. */
|
2015-09-14 22:01:23 +07:00
|
|
|
spin_lock_bh(&ap_dev->lock);
|
|
|
|
ap_dev->state = AP_STATE_SUSPEND_WAIT;
|
|
|
|
while (ap_sm_event(ap_dev, AP_EVENT_POLL) != AP_WAIT_NONE)
|
|
|
|
;
|
|
|
|
ap_dev->state = AP_STATE_BORKED;
|
|
|
|
spin_unlock_bh(&ap_dev->lock);
|
2015-07-17 18:43:18 +07:00
|
|
|
return 0;
|
|
|
|
}
|
2009-09-23 03:58:51 +07:00
|
|
|
|
2015-07-17 18:43:18 +07:00
|
|
|
static int ap_dev_resume(struct device *dev)
|
|
|
|
{
|
2009-06-22 17:08:16 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-07-17 18:43:18 +07:00
|
|
|
static void ap_bus_suspend(void)
|
|
|
|
{
|
|
|
|
ap_suspend_flag = 1;
|
|
|
|
/*
|
|
|
|
* Disable scanning for devices, thus we do not want to scan
|
|
|
|
* for them after removing.
|
|
|
|
*/
|
|
|
|
flush_workqueue(ap_work_queue);
|
|
|
|
tasklet_disable(&ap_tasklet);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __ap_devices_unregister(struct device *dev, void *dummy)
|
|
|
|
{
|
|
|
|
device_unregister(dev);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ap_bus_resume(void)
|
2009-06-22 17:08:16 +07:00
|
|
|
{
|
2013-06-24 15:30:41 +07:00
|
|
|
int rc;
|
2009-06-22 17:08:16 +07:00
|
|
|
|
2015-07-17 18:43:18 +07:00
|
|
|
/* Unconditionally remove all AP devices */
|
|
|
|
bus_for_each_dev(&ap_bus_type, NULL, NULL, __ap_devices_unregister);
|
|
|
|
/* Reset thin interrupt setting */
|
|
|
|
if (ap_interrupts_available() && !ap_using_interrupts()) {
|
|
|
|
rc = register_adapter_interrupt(&ap_airq);
|
|
|
|
ap_airq_flag = (rc == 0);
|
2009-09-23 03:58:51 +07:00
|
|
|
}
|
2015-07-17 18:43:18 +07:00
|
|
|
if (!ap_interrupts_available() && ap_using_interrupts()) {
|
|
|
|
unregister_adapter_interrupt(&ap_airq);
|
|
|
|
ap_airq_flag = 0;
|
|
|
|
}
|
|
|
|
/* Reset domain */
|
|
|
|
if (!user_set_domain)
|
|
|
|
ap_domain_index = -1;
|
|
|
|
/* Get things going again */
|
|
|
|
ap_suspend_flag = 0;
|
|
|
|
if (ap_airq_flag)
|
|
|
|
xchg(ap_airq.lsi_ptr, 0);
|
|
|
|
tasklet_enable(&ap_tasklet);
|
2009-09-23 03:58:51 +07:00
|
|
|
queue_work(ap_work_queue, &ap_config_work);
|
2015-07-17 18:43:18 +07:00
|
|
|
}
|
2009-06-22 17:08:16 +07:00
|
|
|
|
2015-07-17 18:43:18 +07:00
|
|
|
static int ap_power_event(struct notifier_block *this, unsigned long event,
|
|
|
|
void *ptr)
|
|
|
|
{
|
|
|
|
switch (event) {
|
|
|
|
case PM_HIBERNATION_PREPARE:
|
|
|
|
case PM_SUSPEND_PREPARE:
|
|
|
|
ap_bus_suspend();
|
|
|
|
break;
|
|
|
|
case PM_POST_HIBERNATION:
|
|
|
|
case PM_POST_SUSPEND:
|
|
|
|
ap_bus_resume();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return NOTIFY_DONE;
|
2009-06-22 17:08:16 +07:00
|
|
|
}
|
2015-07-17 18:43:18 +07:00
|
|
|
static struct notifier_block ap_power_notifier = {
|
|
|
|
.notifier_call = ap_power_event,
|
|
|
|
};
|
2009-06-22 17:08:16 +07:00
|
|
|
|
2006-09-20 20:58:25 +07:00
|
|
|
static struct bus_type ap_bus_type = {
|
|
|
|
.name = "ap",
|
|
|
|
.match = &ap_bus_match,
|
|
|
|
.uevent = &ap_uevent,
|
2015-07-17 18:43:18 +07:00
|
|
|
.suspend = ap_dev_suspend,
|
|
|
|
.resume = ap_dev_resume,
|
2006-09-20 20:58:25 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
static int ap_device_probe(struct device *dev)
|
|
|
|
{
|
|
|
|
struct ap_device *ap_dev = to_ap_dev(dev);
|
2015-09-14 22:01:23 +07:00
|
|
|
struct ap_driver *ap_drv = to_ap_drv(dev->driver);
|
|
|
|
int rc;
|
2014-07-15 00:11:48 +07:00
|
|
|
|
2015-09-14 22:01:23 +07:00
|
|
|
ap_dev->drv = ap_drv;
|
2006-09-20 20:58:25 +07:00
|
|
|
rc = ap_drv->probe ? ap_drv->probe(ap_dev) : -ENODEV;
|
2015-09-14 22:01:23 +07:00
|
|
|
if (rc)
|
|
|
|
ap_dev->drv = NULL;
|
2006-09-20 20:58:25 +07:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-04-17 12:46:28 +07:00
|
|
|
* __ap_flush_queue(): Flush requests.
|
|
|
|
* @ap_dev: Pointer to the AP device
|
|
|
|
*
|
2006-09-20 20:58:25 +07:00
|
|
|
* Flush all requests from the request/pending queue of an AP device.
|
|
|
|
*/
|
2007-02-06 03:18:53 +07:00
|
|
|
static void __ap_flush_queue(struct ap_device *ap_dev)
|
2006-09-20 20:58:25 +07:00
|
|
|
{
|
|
|
|
struct ap_message *ap_msg, *next;
|
|
|
|
|
|
|
|
list_for_each_entry_safe(ap_msg, next, &ap_dev->pendingq, list) {
|
|
|
|
list_del_init(&ap_msg->list);
|
|
|
|
ap_dev->pendingq_count--;
|
2015-09-14 21:59:27 +07:00
|
|
|
ap_msg->rc = -EAGAIN;
|
|
|
|
ap_msg->receive(ap_dev, ap_msg, NULL);
|
2006-09-20 20:58:25 +07:00
|
|
|
}
|
|
|
|
list_for_each_entry_safe(ap_msg, next, &ap_dev->requestq, list) {
|
|
|
|
list_del_init(&ap_msg->list);
|
|
|
|
ap_dev->requestq_count--;
|
2015-09-14 21:59:27 +07:00
|
|
|
ap_msg->rc = -EAGAIN;
|
|
|
|
ap_msg->receive(ap_dev, ap_msg, NULL);
|
2006-09-20 20:58:25 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ap_flush_queue(struct ap_device *ap_dev)
|
|
|
|
{
|
|
|
|
spin_lock_bh(&ap_dev->lock);
|
|
|
|
__ap_flush_queue(ap_dev);
|
|
|
|
spin_unlock_bh(&ap_dev->lock);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ap_flush_queue);
|
|
|
|
|
|
|
|
static int ap_device_remove(struct device *dev)
|
|
|
|
{
|
|
|
|
struct ap_device *ap_dev = to_ap_dev(dev);
|
|
|
|
struct ap_driver *ap_drv = ap_dev->drv;
|
|
|
|
|
2006-10-05 01:02:05 +07:00
|
|
|
ap_flush_queue(ap_dev);
|
2007-07-10 16:24:19 +07:00
|
|
|
del_timer_sync(&ap_dev->timeout);
|
2008-12-25 19:38:42 +07:00
|
|
|
spin_lock_bh(&ap_device_list_lock);
|
2007-03-19 19:19:14 +07:00
|
|
|
list_del_init(&ap_dev->list);
|
2008-12-25 19:38:42 +07:00
|
|
|
spin_unlock_bh(&ap_device_list_lock);
|
2008-03-05 18:37:13 +07:00
|
|
|
if (ap_drv->remove)
|
|
|
|
ap_drv->remove(ap_dev);
|
2007-03-27 01:42:43 +07:00
|
|
|
spin_lock_bh(&ap_dev->lock);
|
|
|
|
atomic_sub(ap_dev->queue_count, &ap_poll_requests);
|
|
|
|
spin_unlock_bh(&ap_dev->lock);
|
2006-09-20 20:58:25 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-09-14 22:01:23 +07:00
|
|
|
static void ap_device_release(struct device *dev)
|
|
|
|
{
|
|
|
|
kfree(to_ap_dev(dev));
|
|
|
|
}
|
|
|
|
|
2006-09-20 20:58:25 +07:00
|
|
|
int ap_driver_register(struct ap_driver *ap_drv, struct module *owner,
|
|
|
|
char *name)
|
|
|
|
{
|
|
|
|
struct device_driver *drv = &ap_drv->driver;
|
|
|
|
|
|
|
|
drv->bus = &ap_bus_type;
|
|
|
|
drv->probe = ap_device_probe;
|
|
|
|
drv->remove = ap_device_remove;
|
|
|
|
drv->owner = owner;
|
|
|
|
drv->name = name;
|
|
|
|
return driver_register(drv);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ap_driver_register);
|
|
|
|
|
|
|
|
void ap_driver_unregister(struct ap_driver *ap_drv)
|
|
|
|
{
|
|
|
|
driver_unregister(&ap_drv->driver);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ap_driver_unregister);
|
|
|
|
|
2012-09-11 02:34:26 +07:00
|
|
|
void ap_bus_force_rescan(void)
|
|
|
|
{
|
2015-07-17 18:43:18 +07:00
|
|
|
if (ap_suspend_flag)
|
|
|
|
return;
|
2013-04-12 22:52:08 +07:00
|
|
|
/* processing a asynchronous bus rescan */
|
2015-07-23 15:55:59 +07:00
|
|
|
del_timer(&ap_config_timer);
|
2013-04-12 22:52:08 +07:00
|
|
|
queue_work(ap_work_queue, &ap_config_work);
|
|
|
|
flush_work(&ap_config_work);
|
2012-09-11 02:34:26 +07:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ap_bus_force_rescan);
|
|
|
|
|
2008-04-17 12:46:28 +07:00
|
|
|
/*
|
2006-09-20 20:58:25 +07:00
|
|
|
* AP bus attributes.
|
|
|
|
*/
|
|
|
|
static ssize_t ap_domain_show(struct bus_type *bus, char *buf)
|
|
|
|
{
|
|
|
|
return snprintf(buf, PAGE_SIZE, "%d\n", ap_domain_index);
|
|
|
|
}
|
|
|
|
|
|
|
|
static BUS_ATTR(ap_domain, 0444, ap_domain_show, NULL);
|
|
|
|
|
2013-11-20 16:47:13 +07:00
|
|
|
static ssize_t ap_control_domain_mask_show(struct bus_type *bus, char *buf)
|
|
|
|
{
|
2015-06-26 21:55:35 +07:00
|
|
|
if (!ap_configuration) /* QCI not supported */
|
|
|
|
return snprintf(buf, PAGE_SIZE, "not supported\n");
|
|
|
|
if (!test_facility(76))
|
|
|
|
/* format 0 - 16 bit domain field */
|
|
|
|
return snprintf(buf, PAGE_SIZE, "%08x%08x\n",
|
|
|
|
ap_configuration->adm[0],
|
|
|
|
ap_configuration->adm[1]);
|
|
|
|
/* format 1 - 256 bit domain field */
|
|
|
|
return snprintf(buf, PAGE_SIZE,
|
|
|
|
"0x%08x%08x%08x%08x%08x%08x%08x%08x\n",
|
2013-11-20 16:47:13 +07:00
|
|
|
ap_configuration->adm[0], ap_configuration->adm[1],
|
|
|
|
ap_configuration->adm[2], ap_configuration->adm[3],
|
|
|
|
ap_configuration->adm[4], ap_configuration->adm[5],
|
|
|
|
ap_configuration->adm[6], ap_configuration->adm[7]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static BUS_ATTR(ap_control_domain_mask, 0444,
|
|
|
|
ap_control_domain_mask_show, NULL);
|
|
|
|
|
2006-09-20 20:58:25 +07:00
|
|
|
static ssize_t ap_config_time_show(struct bus_type *bus, char *buf)
|
|
|
|
{
|
|
|
|
return snprintf(buf, PAGE_SIZE, "%d\n", ap_config_time);
|
|
|
|
}
|
|
|
|
|
2008-12-25 19:38:41 +07:00
|
|
|
static ssize_t ap_interrupts_show(struct bus_type *bus, char *buf)
|
|
|
|
{
|
|
|
|
return snprintf(buf, PAGE_SIZE, "%d\n",
|
|
|
|
ap_using_interrupts() ? 1 : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static BUS_ATTR(ap_interrupts, 0444, ap_interrupts_show, NULL);
|
|
|
|
|
2006-09-20 20:58:25 +07:00
|
|
|
static ssize_t ap_config_time_store(struct bus_type *bus,
|
|
|
|
const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
int time;
|
|
|
|
|
|
|
|
if (sscanf(buf, "%d\n", &time) != 1 || time < 5 || time > 120)
|
|
|
|
return -EINVAL;
|
|
|
|
ap_config_time = time;
|
2015-07-23 15:55:59 +07:00
|
|
|
mod_timer(&ap_config_timer, jiffies + ap_config_time * HZ);
|
2006-09-20 20:58:25 +07:00
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BUS_ATTR(config_time, 0644, ap_config_time_show, ap_config_time_store);
|
|
|
|
|
|
|
|
static ssize_t ap_poll_thread_show(struct bus_type *bus, char *buf)
|
|
|
|
{
|
|
|
|
return snprintf(buf, PAGE_SIZE, "%d\n", ap_poll_kthread ? 1 : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t ap_poll_thread_store(struct bus_type *bus,
|
|
|
|
const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
int flag, rc;
|
|
|
|
|
|
|
|
if (sscanf(buf, "%d\n", &flag) != 1)
|
|
|
|
return -EINVAL;
|
|
|
|
if (flag) {
|
|
|
|
rc = ap_poll_thread_start();
|
|
|
|
if (rc)
|
2015-07-17 18:43:18 +07:00
|
|
|
count = rc;
|
|
|
|
} else
|
2006-09-20 20:58:25 +07:00
|
|
|
ap_poll_thread_stop();
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BUS_ATTR(poll_thread, 0644, ap_poll_thread_show, ap_poll_thread_store);
|
|
|
|
|
2008-07-14 14:59:08 +07:00
|
|
|
static ssize_t poll_timeout_show(struct bus_type *bus, char *buf)
|
|
|
|
{
|
|
|
|
return snprintf(buf, PAGE_SIZE, "%llu\n", poll_timeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t poll_timeout_store(struct bus_type *bus, const char *buf,
|
|
|
|
size_t count)
|
|
|
|
{
|
|
|
|
unsigned long long time;
|
|
|
|
ktime_t hr_time;
|
|
|
|
|
|
|
|
/* 120 seconds = maximum poll interval */
|
2008-12-25 19:38:41 +07:00
|
|
|
if (sscanf(buf, "%llu\n", &time) != 1 || time < 1 ||
|
|
|
|
time > 120000000000ULL)
|
2008-07-14 14:59:08 +07:00
|
|
|
return -EINVAL;
|
|
|
|
poll_timeout = time;
|
|
|
|
hr_time = ktime_set(0, poll_timeout);
|
|
|
|
|
2015-04-28 15:31:44 +07:00
|
|
|
spin_lock_bh(&ap_poll_timer_lock);
|
|
|
|
hrtimer_cancel(&ap_poll_timer);
|
|
|
|
hrtimer_set_expires(&ap_poll_timer, hr_time);
|
|
|
|
hrtimer_start_expires(&ap_poll_timer, HRTIMER_MODE_ABS);
|
|
|
|
spin_unlock_bh(&ap_poll_timer_lock);
|
|
|
|
|
2008-07-14 14:59:08 +07:00
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BUS_ATTR(poll_timeout, 0644, poll_timeout_show, poll_timeout_store);
|
|
|
|
|
2015-01-23 19:27:04 +07:00
|
|
|
static ssize_t ap_max_domain_id_show(struct bus_type *bus, char *buf)
|
|
|
|
{
|
2015-06-26 21:55:35 +07:00
|
|
|
int max_domain_id;
|
|
|
|
|
|
|
|
if (ap_configuration)
|
|
|
|
max_domain_id = ap_max_domain_id ? : -1;
|
|
|
|
else
|
2015-01-23 19:27:04 +07:00
|
|
|
max_domain_id = 15;
|
|
|
|
return snprintf(buf, PAGE_SIZE, "%d\n", max_domain_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
static BUS_ATTR(ap_max_domain_id, 0444, ap_max_domain_id_show, NULL);
|
|
|
|
|
2006-09-20 20:58:25 +07:00
|
|
|
static struct bus_attribute *const ap_bus_attrs[] = {
|
|
|
|
&bus_attr_ap_domain,
|
2013-11-20 16:47:13 +07:00
|
|
|
&bus_attr_ap_control_domain_mask,
|
2006-09-20 20:58:25 +07:00
|
|
|
&bus_attr_config_time,
|
|
|
|
&bus_attr_poll_thread,
|
2008-12-25 19:38:41 +07:00
|
|
|
&bus_attr_ap_interrupts,
|
2008-07-14 14:59:08 +07:00
|
|
|
&bus_attr_poll_timeout,
|
2015-01-23 19:27:04 +07:00
|
|
|
&bus_attr_ap_max_domain_id,
|
2008-07-14 14:59:08 +07:00
|
|
|
NULL,
|
2006-09-20 20:58:25 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2008-04-17 12:46:28 +07:00
|
|
|
* ap_select_domain(): Select an AP domain.
|
|
|
|
*
|
|
|
|
* Pick one of the 16 AP domains.
|
2006-09-20 20:58:25 +07:00
|
|
|
*/
|
2007-02-06 03:18:53 +07:00
|
|
|
static int ap_select_domain(void)
|
2006-09-20 20:58:25 +07:00
|
|
|
{
|
2015-06-26 20:40:41 +07:00
|
|
|
int count, max_count, best_domain;
|
|
|
|
struct ap_queue_status status;
|
|
|
|
int i, j;
|
2006-09-20 20:58:25 +07:00
|
|
|
|
2008-04-17 12:46:28 +07:00
|
|
|
/*
|
2006-09-20 20:58:25 +07:00
|
|
|
* We want to use a single domain. Either the one specified with
|
|
|
|
* the "domain=" parameter or the domain with the maximum number
|
|
|
|
* of devices.
|
|
|
|
*/
|
2015-06-26 21:55:35 +07:00
|
|
|
if (ap_domain_index >= 0)
|
2006-09-20 20:58:25 +07:00
|
|
|
/* Domain has already been selected. */
|
|
|
|
return 0;
|
|
|
|
best_domain = -1;
|
|
|
|
max_count = 0;
|
|
|
|
for (i = 0; i < AP_DOMAINS; i++) {
|
2012-08-28 21:41:50 +07:00
|
|
|
if (!ap_test_config_domain(i))
|
|
|
|
continue;
|
2006-09-20 20:58:25 +07:00
|
|
|
count = 0;
|
|
|
|
for (j = 0; j < AP_DEVICES; j++) {
|
2012-08-28 21:41:50 +07:00
|
|
|
if (!ap_test_config_card_id(j))
|
|
|
|
continue;
|
2015-06-26 20:40:41 +07:00
|
|
|
status = ap_test_queue(AP_MKQID(j, i), NULL);
|
|
|
|
if (status.response_code != AP_RESPONSE_NORMAL)
|
2006-09-20 20:58:25 +07:00
|
|
|
continue;
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
if (count > max_count) {
|
|
|
|
max_count = count;
|
|
|
|
best_domain = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (best_domain >= 0){
|
|
|
|
ap_domain_index = best_domain;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-04-17 12:46:28 +07:00
|
|
|
* __ap_scan_bus(): Scan the AP bus.
|
|
|
|
* @dev: Pointer to device
|
|
|
|
* @data: Pointer to data
|
|
|
|
*
|
|
|
|
* Scan the AP bus for new devices.
|
2006-09-20 20:58:25 +07:00
|
|
|
*/
|
|
|
|
static int __ap_scan_bus(struct device *dev, void *data)
|
|
|
|
{
|
|
|
|
return to_ap_dev(dev)->qid == (ap_qid_t)(unsigned long) data;
|
|
|
|
}
|
|
|
|
|
2006-12-07 02:18:20 +07:00
|
|
|
static void ap_scan_bus(struct work_struct *unused)
|
2006-09-20 20:58:25 +07:00
|
|
|
{
|
|
|
|
struct ap_device *ap_dev;
|
|
|
|
struct device *dev;
|
|
|
|
ap_qid_t qid;
|
2015-06-17 21:19:15 +07:00
|
|
|
int queue_depth = 0, device_type = 0;
|
2015-09-14 22:01:23 +07:00
|
|
|
unsigned int device_functions = 0;
|
|
|
|
int rc, i, borked;
|
2006-09-20 20:58:25 +07:00
|
|
|
|
2012-08-28 21:41:50 +07:00
|
|
|
ap_query_configuration();
|
2015-07-17 18:43:18 +07:00
|
|
|
if (ap_select_domain() != 0)
|
2015-07-23 15:55:59 +07:00
|
|
|
goto out;
|
2015-06-26 21:55:35 +07:00
|
|
|
|
2006-09-20 20:58:25 +07:00
|
|
|
for (i = 0; i < AP_DEVICES; i++) {
|
|
|
|
qid = AP_MKQID(i, ap_domain_index);
|
|
|
|
dev = bus_find_device(&ap_bus_type, NULL,
|
|
|
|
(void *)(unsigned long)qid,
|
|
|
|
__ap_scan_bus);
|
2015-06-26 21:55:35 +07:00
|
|
|
rc = ap_query_queue(qid, &queue_depth, &device_type,
|
|
|
|
&device_functions);
|
2007-03-27 01:42:42 +07:00
|
|
|
if (dev) {
|
|
|
|
ap_dev = to_ap_dev(dev);
|
|
|
|
spin_lock_bh(&ap_dev->lock);
|
2015-09-14 22:01:23 +07:00
|
|
|
if (rc == -ENODEV)
|
|
|
|
ap_dev->state = AP_STATE_BORKED;
|
|
|
|
borked = ap_dev->state == AP_STATE_BORKED;
|
2007-07-10 16:24:19 +07:00
|
|
|
spin_unlock_bh(&ap_dev->lock);
|
2015-09-14 22:01:23 +07:00
|
|
|
if (borked) /* Remove broken device */
|
|
|
|
device_unregister(dev);
|
2006-09-20 20:58:25 +07:00
|
|
|
put_device(dev);
|
2015-09-14 22:01:23 +07:00
|
|
|
if (!borked)
|
|
|
|
continue;
|
2006-09-20 20:58:25 +07:00
|
|
|
}
|
|
|
|
if (rc)
|
|
|
|
continue;
|
|
|
|
ap_dev = kzalloc(sizeof(*ap_dev), GFP_KERNEL);
|
|
|
|
if (!ap_dev)
|
|
|
|
break;
|
|
|
|
ap_dev->qid = qid;
|
2015-09-14 22:01:23 +07:00
|
|
|
ap_dev->state = AP_STATE_RESET_START;
|
|
|
|
ap_dev->interrupt = AP_INTR_DISABLED;
|
2006-09-20 20:58:25 +07:00
|
|
|
ap_dev->queue_depth = queue_depth;
|
2015-06-26 20:40:41 +07:00
|
|
|
ap_dev->raw_hwtype = device_type;
|
|
|
|
ap_dev->device_type = device_type;
|
|
|
|
ap_dev->functions = device_functions;
|
2006-09-20 20:58:25 +07:00
|
|
|
spin_lock_init(&ap_dev->lock);
|
|
|
|
INIT_LIST_HEAD(&ap_dev->pendingq);
|
|
|
|
INIT_LIST_HEAD(&ap_dev->requestq);
|
2007-03-19 19:19:14 +07:00
|
|
|
INIT_LIST_HEAD(&ap_dev->list);
|
2007-07-10 16:24:19 +07:00
|
|
|
setup_timer(&ap_dev->timeout, ap_request_timeout,
|
|
|
|
(unsigned long) ap_dev);
|
2012-08-28 21:48:29 +07:00
|
|
|
|
2006-09-20 20:58:25 +07:00
|
|
|
ap_dev->device.bus = &ap_bus_type;
|
|
|
|
ap_dev->device.parent = ap_root_device;
|
2015-09-14 22:01:23 +07:00
|
|
|
rc = dev_set_name(&ap_dev->device, "card%02x",
|
|
|
|
AP_QID_DEVICE(ap_dev->qid));
|
|
|
|
if (rc) {
|
2009-09-11 15:28:52 +07:00
|
|
|
kfree(ap_dev);
|
|
|
|
continue;
|
|
|
|
}
|
2015-09-14 22:01:23 +07:00
|
|
|
/* Add to list of devices */
|
|
|
|
spin_lock_bh(&ap_device_list_lock);
|
|
|
|
list_add(&ap_dev->list, &ap_device_list);
|
|
|
|
spin_unlock_bh(&ap_device_list_lock);
|
|
|
|
/* Start with a device reset */
|
|
|
|
spin_lock_bh(&ap_dev->lock);
|
|
|
|
ap_sm_wait(ap_sm_event(ap_dev, AP_EVENT_POLL));
|
|
|
|
spin_unlock_bh(&ap_dev->lock);
|
|
|
|
/* Register device */
|
2006-09-20 20:58:25 +07:00
|
|
|
ap_dev->device.release = ap_device_release;
|
|
|
|
rc = device_register(&ap_dev->device);
|
|
|
|
if (rc) {
|
2015-09-14 22:01:23 +07:00
|
|
|
spin_lock_bh(&ap_dev->lock);
|
|
|
|
list_del_init(&ap_dev->list);
|
|
|
|
spin_unlock_bh(&ap_dev->lock);
|
2009-09-11 15:28:38 +07:00
|
|
|
put_device(&ap_dev->device);
|
2006-09-20 20:58:25 +07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* Add device attributes. */
|
|
|
|
rc = sysfs_create_group(&ap_dev->device.kobj,
|
|
|
|
&ap_dev_attr_group);
|
2015-09-14 22:01:23 +07:00
|
|
|
if (rc) {
|
2006-09-20 20:58:25 +07:00
|
|
|
device_unregister(&ap_dev->device);
|
2015-09-14 22:01:23 +07:00
|
|
|
continue;
|
|
|
|
}
|
2006-09-20 20:58:25 +07:00
|
|
|
}
|
2015-07-23 15:55:59 +07:00
|
|
|
out:
|
|
|
|
mod_timer(&ap_config_timer, jiffies + ap_config_time * HZ);
|
2006-09-20 20:58:25 +07:00
|
|
|
}
|
|
|
|
|
2015-07-17 18:43:18 +07:00
|
|
|
static void ap_config_timeout(unsigned long ptr)
|
2006-09-20 20:58:25 +07:00
|
|
|
{
|
2015-07-17 18:43:18 +07:00
|
|
|
if (ap_suspend_flag)
|
|
|
|
return;
|
2006-09-20 20:58:25 +07:00
|
|
|
queue_work(ap_work_queue, &ap_config_work);
|
|
|
|
}
|
|
|
|
|
2006-12-15 23:18:17 +07:00
|
|
|
static void ap_reset_domain(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2015-06-26 21:55:35 +07:00
|
|
|
if (ap_domain_index == -1 || !ap_test_config_domain(ap_domain_index))
|
|
|
|
return;
|
|
|
|
for (i = 0; i < AP_DEVICES; i++)
|
|
|
|
ap_reset_queue(AP_MKQID(i, ap_domain_index));
|
2006-12-15 23:18:17 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ap_reset_all(void)
|
2006-12-08 21:54:07 +07:00
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
|
2014-09-08 18:24:13 +07:00
|
|
|
for (i = 0; i < AP_DOMAINS; i++) {
|
|
|
|
if (!ap_test_config_domain(i))
|
|
|
|
continue;
|
|
|
|
for (j = 0; j < AP_DEVICES; j++) {
|
|
|
|
if (!ap_test_config_card_id(j))
|
|
|
|
continue;
|
2006-12-08 21:54:07 +07:00
|
|
|
ap_reset_queue(AP_MKQID(j, i));
|
2014-09-08 18:24:13 +07:00
|
|
|
}
|
|
|
|
}
|
2006-12-08 21:54:07 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct reset_call ap_reset_call = {
|
2006-12-15 23:18:17 +07:00
|
|
|
.fn = ap_reset_all,
|
2006-12-08 21:54:07 +07:00
|
|
|
};
|
|
|
|
|
2006-09-20 20:58:25 +07:00
|
|
|
/**
|
2008-04-17 12:46:28 +07:00
|
|
|
* ap_module_init(): The module initialization code.
|
|
|
|
*
|
|
|
|
* Initializes the module.
|
2006-09-20 20:58:25 +07:00
|
|
|
*/
|
|
|
|
int __init ap_module_init(void)
|
|
|
|
{
|
2015-06-26 21:55:35 +07:00
|
|
|
int max_domain_id;
|
2006-09-20 20:58:25 +07:00
|
|
|
int rc, i;
|
|
|
|
|
2015-06-26 21:55:35 +07:00
|
|
|
if (ap_instructions_available() != 0) {
|
|
|
|
pr_warn("The hardware system does not support AP instructions\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get AP configuration data if available */
|
|
|
|
ap_init_configuration();
|
|
|
|
|
|
|
|
if (ap_configuration)
|
|
|
|
max_domain_id = ap_max_domain_id ? : (AP_DOMAINS - 1);
|
|
|
|
else
|
|
|
|
max_domain_id = 15;
|
|
|
|
if (ap_domain_index < -1 || ap_domain_index > max_domain_id) {
|
|
|
|
pr_warn("%d is not a valid cryptographic domain\n",
|
|
|
|
ap_domain_index);
|
2006-09-20 20:58:25 +07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2009-09-23 03:58:51 +07:00
|
|
|
/* In resume callback we need to know if the user had set the domain.
|
|
|
|
* If so, we can not just reset it.
|
|
|
|
*/
|
|
|
|
if (ap_domain_index >= 0)
|
|
|
|
user_set_domain = 1;
|
|
|
|
|
2008-12-25 19:38:41 +07:00
|
|
|
if (ap_interrupts_available()) {
|
2013-06-24 15:30:41 +07:00
|
|
|
rc = register_adapter_interrupt(&ap_airq);
|
|
|
|
ap_airq_flag = (rc == 0);
|
2008-12-25 19:38:41 +07:00
|
|
|
}
|
|
|
|
|
2006-12-08 21:54:07 +07:00
|
|
|
register_reset_call(&ap_reset_call);
|
2006-09-20 20:58:25 +07:00
|
|
|
|
|
|
|
/* Create /sys/bus/ap. */
|
|
|
|
rc = bus_register(&ap_bus_type);
|
|
|
|
if (rc)
|
|
|
|
goto out;
|
|
|
|
for (i = 0; ap_bus_attrs[i]; i++) {
|
|
|
|
rc = bus_create_file(&ap_bus_type, ap_bus_attrs[i]);
|
|
|
|
if (rc)
|
|
|
|
goto out_bus;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create /sys/devices/ap. */
|
2008-12-15 19:58:29 +07:00
|
|
|
ap_root_device = root_device_register("ap");
|
2013-06-01 16:51:13 +07:00
|
|
|
rc = PTR_RET(ap_root_device);
|
2006-09-20 20:58:25 +07:00
|
|
|
if (rc)
|
|
|
|
goto out_bus;
|
|
|
|
|
|
|
|
ap_work_queue = create_singlethread_workqueue("kapwork");
|
|
|
|
if (!ap_work_queue) {
|
|
|
|
rc = -ENOMEM;
|
|
|
|
goto out_root;
|
|
|
|
}
|
|
|
|
|
2008-04-17 12:46:28 +07:00
|
|
|
/* Setup the AP bus rescan timer. */
|
2015-07-23 15:55:59 +07:00
|
|
|
setup_timer(&ap_config_timer, ap_config_timeout, 0);
|
2006-09-20 20:58:25 +07:00
|
|
|
|
2015-09-14 22:01:23 +07:00
|
|
|
/*
|
|
|
|
* Setup the high resultion poll timer.
|
2008-07-14 14:59:08 +07:00
|
|
|
* If we are running under z/VM adjust polling to z/VM polling rate.
|
|
|
|
*/
|
|
|
|
if (MACHINE_IS_VM)
|
|
|
|
poll_timeout = 1500000;
|
2009-12-07 18:52:00 +07:00
|
|
|
spin_lock_init(&ap_poll_timer_lock);
|
2008-07-14 14:59:08 +07:00
|
|
|
hrtimer_init(&ap_poll_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
|
|
|
|
ap_poll_timer.function = ap_poll_timeout;
|
|
|
|
|
2006-09-20 20:58:25 +07:00
|
|
|
/* Start the low priority AP bus poll thread. */
|
|
|
|
if (ap_thread_flag) {
|
|
|
|
rc = ap_poll_thread_start();
|
|
|
|
if (rc)
|
|
|
|
goto out_work;
|
|
|
|
}
|
|
|
|
|
2015-07-17 18:43:18 +07:00
|
|
|
rc = register_pm_notifier(&ap_power_notifier);
|
|
|
|
if (rc)
|
|
|
|
goto out_pm;
|
|
|
|
|
2015-09-14 22:01:23 +07:00
|
|
|
queue_work(ap_work_queue, &ap_config_work);
|
|
|
|
|
2006-09-20 20:58:25 +07:00
|
|
|
return 0;
|
|
|
|
|
2015-07-17 18:43:18 +07:00
|
|
|
out_pm:
|
|
|
|
ap_poll_thread_stop();
|
2006-09-20 20:58:25 +07:00
|
|
|
out_work:
|
2008-07-14 14:59:08 +07:00
|
|
|
hrtimer_cancel(&ap_poll_timer);
|
2006-09-20 20:58:25 +07:00
|
|
|
destroy_workqueue(ap_work_queue);
|
|
|
|
out_root:
|
2008-12-15 19:58:29 +07:00
|
|
|
root_device_unregister(ap_root_device);
|
2006-09-20 20:58:25 +07:00
|
|
|
out_bus:
|
|
|
|
while (i--)
|
|
|
|
bus_remove_file(&ap_bus_type, ap_bus_attrs[i]);
|
|
|
|
bus_unregister(&ap_bus_type);
|
|
|
|
out:
|
2006-12-08 21:54:07 +07:00
|
|
|
unregister_reset_call(&ap_reset_call);
|
2013-06-24 15:30:41 +07:00
|
|
|
if (ap_using_interrupts())
|
|
|
|
unregister_adapter_interrupt(&ap_airq);
|
2015-06-26 21:55:35 +07:00
|
|
|
kfree(ap_configuration);
|
2006-09-20 20:58:25 +07:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-04-17 12:46:28 +07:00
|
|
|
* ap_modules_exit(): The module termination code
|
|
|
|
*
|
|
|
|
* Terminates the module.
|
2006-09-20 20:58:25 +07:00
|
|
|
*/
|
|
|
|
void ap_module_exit(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2006-12-15 23:18:17 +07:00
|
|
|
ap_reset_domain();
|
2006-09-20 20:58:25 +07:00
|
|
|
ap_poll_thread_stop();
|
|
|
|
del_timer_sync(&ap_config_timer);
|
2008-07-14 14:59:08 +07:00
|
|
|
hrtimer_cancel(&ap_poll_timer);
|
2006-09-20 20:58:25 +07:00
|
|
|
destroy_workqueue(ap_work_queue);
|
2006-12-15 23:18:17 +07:00
|
|
|
tasklet_kill(&ap_tasklet);
|
2015-07-17 18:43:18 +07:00
|
|
|
bus_for_each_dev(&ap_bus_type, NULL, NULL, __ap_devices_unregister);
|
2006-09-20 20:58:25 +07:00
|
|
|
for (i = 0; ap_bus_attrs[i]; i++)
|
|
|
|
bus_remove_file(&ap_bus_type, ap_bus_attrs[i]);
|
2015-07-17 18:43:18 +07:00
|
|
|
unregister_pm_notifier(&ap_power_notifier);
|
2015-04-30 20:36:48 +07:00
|
|
|
root_device_unregister(ap_root_device);
|
2006-09-20 20:58:25 +07:00
|
|
|
bus_unregister(&ap_bus_type);
|
2015-06-26 21:55:35 +07:00
|
|
|
kfree(ap_configuration);
|
2006-12-08 21:54:07 +07:00
|
|
|
unregister_reset_call(&ap_reset_call);
|
2013-06-24 15:30:41 +07:00
|
|
|
if (ap_using_interrupts())
|
|
|
|
unregister_adapter_interrupt(&ap_airq);
|
2006-09-20 20:58:25 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
module_init(ap_module_init);
|
|
|
|
module_exit(ap_module_exit);
|