2017-11-15 01:38:02 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2008-07-14 15:59:05 +08:00
|
|
|
/*
|
|
|
|
* Driver for s390 chsc subchannels
|
|
|
|
*
|
2011-10-30 22:16:54 +08:00
|
|
|
* Copyright IBM Corp. 2008, 2011
|
2009-06-16 16:30:24 +08:00
|
|
|
*
|
2008-07-14 15:59:05 +08:00
|
|
|
* Author(s): Cornelia Huck <cornelia.huck@de.ibm.com>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
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 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2012-02-27 17:01:52 +08:00
|
|
|
#include <linux/compat.h>
|
2008-07-14 15:59:05 +08:00
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/uaccess.h>
|
|
|
|
#include <linux/miscdevice.h>
|
2011-10-30 22:16:54 +08:00
|
|
|
#include <linux/kernel_stat.h>
|
2008-07-14 15:59:05 +08:00
|
|
|
|
|
|
|
#include <asm/cio.h>
|
|
|
|
#include <asm/chsc.h>
|
|
|
|
#include <asm/isc.h>
|
|
|
|
|
|
|
|
#include "cio.h"
|
|
|
|
#include "cio_debug.h"
|
|
|
|
#include "css.h"
|
|
|
|
#include "chsc_sch.h"
|
|
|
|
#include "ioasm.h"
|
|
|
|
|
|
|
|
static debug_info_t *chsc_debug_msg_id;
|
|
|
|
static debug_info_t *chsc_debug_log_id;
|
|
|
|
|
2013-06-06 15:50:21 +08:00
|
|
|
static struct chsc_request *on_close_request;
|
|
|
|
static struct chsc_async_area *on_close_chsc_area;
|
|
|
|
static DEFINE_MUTEX(on_close_mutex);
|
|
|
|
|
2008-07-14 15:59:05 +08:00
|
|
|
#define CHSC_MSG(imp, args...) do { \
|
|
|
|
debug_sprintf_event(chsc_debug_msg_id, imp , ##args); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define CHSC_LOG(imp, txt) do { \
|
|
|
|
debug_text_event(chsc_debug_log_id, imp , txt); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
static void CHSC_LOG_HEX(int level, void *data, int length)
|
|
|
|
{
|
2017-10-09 23:49:38 +08:00
|
|
|
debug_event(chsc_debug_log_id, level, data, length);
|
2008-07-14 15:59:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
MODULE_AUTHOR("IBM Corporation");
|
|
|
|
MODULE_DESCRIPTION("driver for s390 chsc subchannels");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
|
|
|
static void chsc_subchannel_irq(struct subchannel *sch)
|
|
|
|
{
|
2011-03-16 00:08:28 +08:00
|
|
|
struct chsc_private *private = dev_get_drvdata(&sch->dev);
|
2008-07-14 15:59:05 +08:00
|
|
|
struct chsc_request *request = private->request;
|
2014-08-18 01:30:46 +08:00
|
|
|
struct irb *irb = this_cpu_ptr(&cio_irb);
|
2008-07-14 15:59:05 +08:00
|
|
|
|
|
|
|
CHSC_LOG(4, "irb");
|
|
|
|
CHSC_LOG_HEX(4, irb, sizeof(*irb));
|
2013-01-02 22:18:18 +08:00
|
|
|
inc_irq_stat(IRQIO_CSC);
|
2011-10-30 22:16:54 +08:00
|
|
|
|
2008-07-14 15:59:05 +08:00
|
|
|
/* Copy irb to provided request and set done. */
|
|
|
|
if (!request) {
|
|
|
|
CHSC_MSG(0, "Interrupt on sch 0.%x.%04x with no request\n",
|
|
|
|
sch->schid.ssid, sch->schid.sch_no);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
private->request = NULL;
|
|
|
|
memcpy(&request->irb, irb, sizeof(*irb));
|
2008-12-25 20:39:12 +08:00
|
|
|
cio_update_schib(sch);
|
2008-07-14 15:59:05 +08:00
|
|
|
complete(&request->completion);
|
|
|
|
put_device(&sch->dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int chsc_subchannel_probe(struct subchannel *sch)
|
|
|
|
{
|
|
|
|
struct chsc_private *private;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
CHSC_MSG(6, "Detected chsc subchannel 0.%x.%04x\n",
|
|
|
|
sch->schid.ssid, sch->schid.sch_no);
|
|
|
|
sch->isc = CHSC_SCH_ISC;
|
|
|
|
private = kzalloc(sizeof(*private), GFP_KERNEL);
|
|
|
|
if (!private)
|
|
|
|
return -ENOMEM;
|
2011-03-16 00:08:28 +08:00
|
|
|
dev_set_drvdata(&sch->dev, private);
|
2008-07-14 15:59:05 +08:00
|
|
|
ret = cio_enable_subchannel(sch, (u32)(unsigned long)sch);
|
|
|
|
if (ret) {
|
|
|
|
CHSC_MSG(0, "Failed to enable 0.%x.%04x: %d\n",
|
|
|
|
sch->schid.ssid, sch->schid.sch_no, ret);
|
2011-03-16 00:08:28 +08:00
|
|
|
dev_set_drvdata(&sch->dev, NULL);
|
2008-07-14 15:59:05 +08:00
|
|
|
kfree(private);
|
|
|
|
} else {
|
2009-03-01 21:10:49 +08:00
|
|
|
if (dev_get_uevent_suppress(&sch->dev)) {
|
|
|
|
dev_set_uevent_suppress(&sch->dev, 0);
|
2008-07-14 15:59:05 +08:00
|
|
|
kobject_uevent(&sch->dev.kobj, KOBJ_ADD);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int chsc_subchannel_remove(struct subchannel *sch)
|
|
|
|
{
|
|
|
|
struct chsc_private *private;
|
|
|
|
|
|
|
|
cio_disable_subchannel(sch);
|
2011-03-16 00:08:28 +08:00
|
|
|
private = dev_get_drvdata(&sch->dev);
|
|
|
|
dev_set_drvdata(&sch->dev, NULL);
|
2008-07-14 15:59:05 +08:00
|
|
|
if (private->request) {
|
|
|
|
complete(&private->request->completion);
|
|
|
|
put_device(&sch->dev);
|
|
|
|
}
|
|
|
|
kfree(private);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void chsc_subchannel_shutdown(struct subchannel *sch)
|
|
|
|
{
|
|
|
|
cio_disable_subchannel(sch);
|
|
|
|
}
|
|
|
|
|
2009-06-16 16:30:24 +08:00
|
|
|
static int chsc_subchannel_prepare(struct subchannel *sch)
|
|
|
|
{
|
|
|
|
int cc;
|
|
|
|
struct schib schib;
|
|
|
|
/*
|
|
|
|
* Don't allow suspend while the subchannel is not idle
|
|
|
|
* since we don't have a way to clear the subchannel and
|
|
|
|
* cannot disable it with a request running.
|
|
|
|
*/
|
2015-12-18 19:58:47 +08:00
|
|
|
cc = stsch(sch->schid, &schib);
|
2009-06-16 16:30:24 +08:00
|
|
|
if (!cc && scsw_stctl(&schib.scsw))
|
|
|
|
return -EAGAIN;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int chsc_subchannel_freeze(struct subchannel *sch)
|
|
|
|
{
|
|
|
|
return cio_disable_subchannel(sch);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int chsc_subchannel_restore(struct subchannel *sch)
|
|
|
|
{
|
|
|
|
return cio_enable_subchannel(sch, (u32)(unsigned long)sch);
|
|
|
|
}
|
|
|
|
|
2008-07-14 15:59:05 +08:00
|
|
|
static struct css_device_id chsc_subchannel_ids[] = {
|
|
|
|
{ .match_flags = 0x1, .type =SUBCHANNEL_TYPE_CHSC, },
|
|
|
|
{ /* end of list */ },
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(css, chsc_subchannel_ids);
|
|
|
|
|
|
|
|
static struct css_driver chsc_subchannel_driver = {
|
2011-03-16 00:08:30 +08:00
|
|
|
.drv = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.name = "chsc_subchannel",
|
|
|
|
},
|
2008-07-14 15:59:05 +08:00
|
|
|
.subchannel_type = chsc_subchannel_ids,
|
|
|
|
.irq = chsc_subchannel_irq,
|
|
|
|
.probe = chsc_subchannel_probe,
|
|
|
|
.remove = chsc_subchannel_remove,
|
|
|
|
.shutdown = chsc_subchannel_shutdown,
|
2009-06-16 16:30:24 +08:00
|
|
|
.prepare = chsc_subchannel_prepare,
|
|
|
|
.freeze = chsc_subchannel_freeze,
|
|
|
|
.thaw = chsc_subchannel_restore,
|
|
|
|
.restore = chsc_subchannel_restore,
|
2008-07-14 15:59:05 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static int __init chsc_init_dbfs(void)
|
|
|
|
{
|
2014-02-17 18:16:10 +08:00
|
|
|
chsc_debug_msg_id = debug_register("chsc_msg", 8, 1, 4 * sizeof(long));
|
2008-07-14 15:59:05 +08:00
|
|
|
if (!chsc_debug_msg_id)
|
|
|
|
goto out;
|
|
|
|
debug_register_view(chsc_debug_msg_id, &debug_sprintf_view);
|
|
|
|
debug_set_level(chsc_debug_msg_id, 2);
|
|
|
|
chsc_debug_log_id = debug_register("chsc_log", 16, 1, 16);
|
|
|
|
if (!chsc_debug_log_id)
|
|
|
|
goto out;
|
|
|
|
debug_register_view(chsc_debug_log_id, &debug_hex_ascii_view);
|
|
|
|
debug_set_level(chsc_debug_log_id, 2);
|
|
|
|
return 0;
|
|
|
|
out:
|
2015-11-16 21:45:40 +08:00
|
|
|
debug_unregister(chsc_debug_msg_id);
|
2008-07-14 15:59:05 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void chsc_remove_dbfs(void)
|
|
|
|
{
|
|
|
|
debug_unregister(chsc_debug_log_id);
|
|
|
|
debug_unregister(chsc_debug_msg_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __init chsc_init_sch_driver(void)
|
|
|
|
{
|
|
|
|
return css_driver_register(&chsc_subchannel_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void chsc_cleanup_sch_driver(void)
|
|
|
|
{
|
|
|
|
css_driver_unregister(&chsc_subchannel_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
static DEFINE_SPINLOCK(chsc_lock);
|
|
|
|
|
2019-06-15 01:54:00 +08:00
|
|
|
static int chsc_subchannel_match_next_free(struct device *dev, const void *data)
|
2008-07-14 15:59:05 +08:00
|
|
|
{
|
|
|
|
struct subchannel *sch = to_subchannel(dev);
|
|
|
|
|
|
|
|
return sch->schib.pmcw.ena && !scsw_fctl(&sch->schib.scsw);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct subchannel *chsc_get_next_subchannel(struct subchannel *sch)
|
|
|
|
{
|
|
|
|
struct device *dev;
|
|
|
|
|
|
|
|
dev = driver_find_device(&chsc_subchannel_driver.drv,
|
|
|
|
sch ? &sch->dev : NULL, NULL,
|
|
|
|
chsc_subchannel_match_next_free);
|
|
|
|
return dev ? to_subchannel(dev) : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* chsc_async() - try to start a chsc request asynchronously
|
|
|
|
* @chsc_area: request to be started
|
|
|
|
* @request: request structure to associate
|
|
|
|
*
|
|
|
|
* Tries to start a chsc request on one of the existing chsc subchannels.
|
|
|
|
* Returns:
|
|
|
|
* %0 if the request was performed synchronously
|
|
|
|
* %-EINPROGRESS if the request was successfully started
|
|
|
|
* %-EBUSY if all chsc subchannels are busy
|
|
|
|
* %-ENODEV if no chsc subchannels are available
|
|
|
|
* Context:
|
|
|
|
* interrupts disabled, chsc_lock held
|
|
|
|
*/
|
|
|
|
static int chsc_async(struct chsc_async_area *chsc_area,
|
|
|
|
struct chsc_request *request)
|
|
|
|
{
|
|
|
|
int cc;
|
|
|
|
struct chsc_private *private;
|
|
|
|
struct subchannel *sch = NULL;
|
|
|
|
int ret = -ENODEV;
|
|
|
|
char dbf[10];
|
|
|
|
|
2010-02-27 05:37:30 +08:00
|
|
|
chsc_area->header.key = PAGE_DEFAULT_KEY >> 4;
|
2008-07-14 15:59:05 +08:00
|
|
|
while ((sch = chsc_get_next_subchannel(sch))) {
|
|
|
|
spin_lock(sch->lock);
|
2011-03-16 00:08:28 +08:00
|
|
|
private = dev_get_drvdata(&sch->dev);
|
2008-07-14 15:59:05 +08:00
|
|
|
if (private->request) {
|
|
|
|
spin_unlock(sch->lock);
|
|
|
|
ret = -EBUSY;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
chsc_area->header.sid = sch->schid;
|
|
|
|
CHSC_LOG(2, "schid");
|
|
|
|
CHSC_LOG_HEX(2, &sch->schid, sizeof(sch->schid));
|
|
|
|
cc = chsc(chsc_area);
|
2013-06-10 20:07:44 +08:00
|
|
|
snprintf(dbf, sizeof(dbf), "cc:%d", cc);
|
2008-07-14 15:59:05 +08:00
|
|
|
CHSC_LOG(2, dbf);
|
|
|
|
switch (cc) {
|
|
|
|
case 0:
|
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
sch->schib.scsw.cmd.fctl |= SCSW_FCTL_START_FUNC;
|
|
|
|
ret = -EINPROGRESS;
|
|
|
|
private->request = request;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
ret = -EBUSY;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = -ENODEV;
|
|
|
|
}
|
|
|
|
spin_unlock(sch->lock);
|
|
|
|
CHSC_MSG(2, "chsc on 0.%x.%04x returned cc=%d\n",
|
|
|
|
sch->schid.ssid, sch->schid.sch_no, cc);
|
|
|
|
if (ret == -EINPROGRESS)
|
|
|
|
return -EINPROGRESS;
|
|
|
|
put_device(&sch->dev);
|
|
|
|
if (ret == 0)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-06-06 15:44:28 +08:00
|
|
|
static void chsc_log_command(void *chsc_area)
|
2008-07-14 15:59:05 +08:00
|
|
|
{
|
|
|
|
char dbf[10];
|
|
|
|
|
2013-06-10 20:07:44 +08:00
|
|
|
snprintf(dbf, sizeof(dbf), "CHSC:%x", ((uint16_t *)chsc_area)[1]);
|
2008-07-14 15:59:05 +08:00
|
|
|
CHSC_LOG(0, dbf);
|
|
|
|
CHSC_LOG_HEX(0, chsc_area, 32);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int chsc_examine_irb(struct chsc_request *request)
|
|
|
|
{
|
|
|
|
int backed_up;
|
|
|
|
|
2008-10-11 03:33:16 +08:00
|
|
|
if (!(scsw_stctl(&request->irb.scsw) & SCSW_STCTL_STATUS_PEND))
|
2008-07-14 15:59:05 +08:00
|
|
|
return -EIO;
|
|
|
|
backed_up = scsw_cstat(&request->irb.scsw) & SCHN_STAT_CHAIN_CHECK;
|
|
|
|
request->irb.scsw.cmd.cstat &= ~SCHN_STAT_CHAIN_CHECK;
|
|
|
|
if (scsw_cstat(&request->irb.scsw) == 0)
|
|
|
|
return 0;
|
|
|
|
if (!backed_up)
|
|
|
|
return 0;
|
|
|
|
if (scsw_cstat(&request->irb.scsw) & SCHN_STAT_PROG_CHECK)
|
|
|
|
return -EIO;
|
|
|
|
if (scsw_cstat(&request->irb.scsw) & SCHN_STAT_PROT_CHECK)
|
|
|
|
return -EPERM;
|
|
|
|
if (scsw_cstat(&request->irb.scsw) & SCHN_STAT_CHN_DATA_CHK)
|
|
|
|
return -EAGAIN;
|
|
|
|
if (scsw_cstat(&request->irb.scsw) & SCHN_STAT_CHN_CTRL_CHK)
|
|
|
|
return -EAGAIN;
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int chsc_ioctl_start(void __user *user_area)
|
|
|
|
{
|
|
|
|
struct chsc_request *request;
|
|
|
|
struct chsc_async_area *chsc_area;
|
|
|
|
int ret;
|
|
|
|
char dbf[10];
|
|
|
|
|
|
|
|
if (!css_general_characteristics.dynio)
|
|
|
|
/* It makes no sense to try. */
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
chsc_area = (void *)get_zeroed_page(GFP_DMA | GFP_KERNEL);
|
|
|
|
if (!chsc_area)
|
|
|
|
return -ENOMEM;
|
|
|
|
request = kzalloc(sizeof(*request), GFP_KERNEL);
|
|
|
|
if (!request) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
init_completion(&request->completion);
|
|
|
|
if (copy_from_user(chsc_area, user_area, PAGE_SIZE)) {
|
|
|
|
ret = -EFAULT;
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
chsc_log_command(chsc_area);
|
|
|
|
spin_lock_irq(&chsc_lock);
|
|
|
|
ret = chsc_async(chsc_area, request);
|
|
|
|
spin_unlock_irq(&chsc_lock);
|
|
|
|
if (ret == -EINPROGRESS) {
|
|
|
|
wait_for_completion(&request->completion);
|
|
|
|
ret = chsc_examine_irb(request);
|
|
|
|
}
|
|
|
|
/* copy area back to user */
|
|
|
|
if (!ret)
|
|
|
|
if (copy_to_user(user_area, chsc_area, PAGE_SIZE))
|
|
|
|
ret = -EFAULT;
|
|
|
|
out_free:
|
2013-06-10 20:07:44 +08:00
|
|
|
snprintf(dbf, sizeof(dbf), "ret:%d", ret);
|
2008-07-14 15:59:05 +08:00
|
|
|
CHSC_LOG(0, dbf);
|
|
|
|
kfree(request);
|
|
|
|
free_page((unsigned long)chsc_area);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-06-06 15:50:21 +08:00
|
|
|
static int chsc_ioctl_on_close_set(void __user *user_area)
|
|
|
|
{
|
|
|
|
char dbf[13];
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
mutex_lock(&on_close_mutex);
|
|
|
|
if (on_close_chsc_area) {
|
|
|
|
ret = -EBUSY;
|
|
|
|
goto out_unlock;
|
|
|
|
}
|
|
|
|
on_close_request = kzalloc(sizeof(*on_close_request), GFP_KERNEL);
|
|
|
|
if (!on_close_request) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out_unlock;
|
|
|
|
}
|
|
|
|
on_close_chsc_area = (void *)get_zeroed_page(GFP_DMA | GFP_KERNEL);
|
|
|
|
if (!on_close_chsc_area) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out_free_request;
|
|
|
|
}
|
|
|
|
if (copy_from_user(on_close_chsc_area, user_area, PAGE_SIZE)) {
|
|
|
|
ret = -EFAULT;
|
|
|
|
goto out_free_chsc;
|
|
|
|
}
|
|
|
|
ret = 0;
|
|
|
|
goto out_unlock;
|
|
|
|
|
|
|
|
out_free_chsc:
|
|
|
|
free_page((unsigned long)on_close_chsc_area);
|
|
|
|
on_close_chsc_area = NULL;
|
|
|
|
out_free_request:
|
|
|
|
kfree(on_close_request);
|
|
|
|
on_close_request = NULL;
|
|
|
|
out_unlock:
|
|
|
|
mutex_unlock(&on_close_mutex);
|
2013-06-10 20:07:44 +08:00
|
|
|
snprintf(dbf, sizeof(dbf), "ocsret:%d", ret);
|
2013-06-06 15:50:21 +08:00
|
|
|
CHSC_LOG(0, dbf);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int chsc_ioctl_on_close_remove(void)
|
|
|
|
{
|
|
|
|
char dbf[13];
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
mutex_lock(&on_close_mutex);
|
|
|
|
if (!on_close_chsc_area) {
|
|
|
|
ret = -ENOENT;
|
|
|
|
goto out_unlock;
|
|
|
|
}
|
|
|
|
free_page((unsigned long)on_close_chsc_area);
|
|
|
|
on_close_chsc_area = NULL;
|
|
|
|
kfree(on_close_request);
|
|
|
|
on_close_request = NULL;
|
|
|
|
ret = 0;
|
|
|
|
out_unlock:
|
|
|
|
mutex_unlock(&on_close_mutex);
|
2013-06-10 20:07:44 +08:00
|
|
|
snprintf(dbf, sizeof(dbf), "ocrret:%d", ret);
|
2013-06-06 15:50:21 +08:00
|
|
|
CHSC_LOG(0, dbf);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-06-06 15:44:28 +08:00
|
|
|
static int chsc_ioctl_start_sync(void __user *user_area)
|
|
|
|
{
|
|
|
|
struct chsc_sync_area *chsc_area;
|
|
|
|
int ret, ccode;
|
|
|
|
|
|
|
|
chsc_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
|
|
|
|
if (!chsc_area)
|
|
|
|
return -ENOMEM;
|
|
|
|
if (copy_from_user(chsc_area, user_area, PAGE_SIZE)) {
|
|
|
|
ret = -EFAULT;
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
if (chsc_area->header.code & 0x4000) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
chsc_log_command(chsc_area);
|
|
|
|
ccode = chsc(chsc_area);
|
|
|
|
if (ccode != 0) {
|
|
|
|
ret = -EIO;
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
if (copy_to_user(user_area, chsc_area, PAGE_SIZE))
|
|
|
|
ret = -EFAULT;
|
|
|
|
else
|
|
|
|
ret = 0;
|
|
|
|
out_free:
|
|
|
|
free_page((unsigned long)chsc_area);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-07-14 15:59:05 +08:00
|
|
|
static int chsc_ioctl_info_channel_path(void __user *user_cd)
|
|
|
|
{
|
|
|
|
struct chsc_chp_cd *cd;
|
|
|
|
int ret, ccode;
|
|
|
|
struct {
|
|
|
|
struct chsc_header request;
|
|
|
|
u32 : 2;
|
|
|
|
u32 m : 1;
|
|
|
|
u32 : 1;
|
|
|
|
u32 fmt1 : 4;
|
|
|
|
u32 cssid : 8;
|
|
|
|
u32 : 8;
|
|
|
|
u32 first_chpid : 8;
|
|
|
|
u32 : 24;
|
|
|
|
u32 last_chpid : 8;
|
|
|
|
u32 : 32;
|
|
|
|
struct chsc_header response;
|
|
|
|
u8 data[PAGE_SIZE - 20];
|
|
|
|
} __attribute__ ((packed)) *scpcd_area;
|
|
|
|
|
|
|
|
scpcd_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
|
|
|
|
if (!scpcd_area)
|
|
|
|
return -ENOMEM;
|
|
|
|
cd = kzalloc(sizeof(*cd), GFP_KERNEL);
|
|
|
|
if (!cd) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
if (copy_from_user(cd, user_cd, sizeof(*cd))) {
|
|
|
|
ret = -EFAULT;
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
scpcd_area->request.length = 0x0010;
|
|
|
|
scpcd_area->request.code = 0x0028;
|
|
|
|
scpcd_area->m = cd->m;
|
|
|
|
scpcd_area->fmt1 = cd->fmt;
|
|
|
|
scpcd_area->cssid = cd->chpid.cssid;
|
|
|
|
scpcd_area->first_chpid = cd->chpid.id;
|
|
|
|
scpcd_area->last_chpid = cd->chpid.id;
|
|
|
|
|
|
|
|
ccode = chsc(scpcd_area);
|
|
|
|
if (ccode != 0) {
|
|
|
|
ret = -EIO;
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
if (scpcd_area->response.code != 0x0001) {
|
|
|
|
ret = -EIO;
|
|
|
|
CHSC_MSG(0, "scpcd: response code=%x\n",
|
|
|
|
scpcd_area->response.code);
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
memcpy(&cd->cpcb, &scpcd_area->response, scpcd_area->response.length);
|
|
|
|
if (copy_to_user(user_cd, cd, sizeof(*cd)))
|
|
|
|
ret = -EFAULT;
|
|
|
|
else
|
|
|
|
ret = 0;
|
|
|
|
out_free:
|
|
|
|
kfree(cd);
|
|
|
|
free_page((unsigned long)scpcd_area);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int chsc_ioctl_info_cu(void __user *user_cd)
|
|
|
|
{
|
|
|
|
struct chsc_cu_cd *cd;
|
|
|
|
int ret, ccode;
|
|
|
|
struct {
|
|
|
|
struct chsc_header request;
|
|
|
|
u32 : 2;
|
|
|
|
u32 m : 1;
|
|
|
|
u32 : 1;
|
|
|
|
u32 fmt1 : 4;
|
|
|
|
u32 cssid : 8;
|
|
|
|
u32 : 8;
|
|
|
|
u32 first_cun : 8;
|
|
|
|
u32 : 24;
|
|
|
|
u32 last_cun : 8;
|
|
|
|
u32 : 32;
|
|
|
|
struct chsc_header response;
|
|
|
|
u8 data[PAGE_SIZE - 20];
|
|
|
|
} __attribute__ ((packed)) *scucd_area;
|
|
|
|
|
|
|
|
scucd_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
|
|
|
|
if (!scucd_area)
|
|
|
|
return -ENOMEM;
|
|
|
|
cd = kzalloc(sizeof(*cd), GFP_KERNEL);
|
|
|
|
if (!cd) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
if (copy_from_user(cd, user_cd, sizeof(*cd))) {
|
|
|
|
ret = -EFAULT;
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
scucd_area->request.length = 0x0010;
|
2016-06-21 18:33:30 +08:00
|
|
|
scucd_area->request.code = 0x0026;
|
2008-07-14 15:59:05 +08:00
|
|
|
scucd_area->m = cd->m;
|
|
|
|
scucd_area->fmt1 = cd->fmt;
|
|
|
|
scucd_area->cssid = cd->cssid;
|
|
|
|
scucd_area->first_cun = cd->cun;
|
|
|
|
scucd_area->last_cun = cd->cun;
|
|
|
|
|
|
|
|
ccode = chsc(scucd_area);
|
|
|
|
if (ccode != 0) {
|
|
|
|
ret = -EIO;
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
if (scucd_area->response.code != 0x0001) {
|
|
|
|
ret = -EIO;
|
|
|
|
CHSC_MSG(0, "scucd: response code=%x\n",
|
|
|
|
scucd_area->response.code);
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
memcpy(&cd->cucb, &scucd_area->response, scucd_area->response.length);
|
|
|
|
if (copy_to_user(user_cd, cd, sizeof(*cd)))
|
|
|
|
ret = -EFAULT;
|
|
|
|
else
|
|
|
|
ret = 0;
|
|
|
|
out_free:
|
|
|
|
kfree(cd);
|
|
|
|
free_page((unsigned long)scucd_area);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int chsc_ioctl_info_sch_cu(void __user *user_cud)
|
|
|
|
{
|
|
|
|
struct chsc_sch_cud *cud;
|
|
|
|
int ret, ccode;
|
|
|
|
struct {
|
|
|
|
struct chsc_header request;
|
|
|
|
u32 : 2;
|
|
|
|
u32 m : 1;
|
|
|
|
u32 : 5;
|
|
|
|
u32 fmt1 : 4;
|
|
|
|
u32 : 2;
|
|
|
|
u32 ssid : 2;
|
|
|
|
u32 first_sch : 16;
|
|
|
|
u32 : 8;
|
|
|
|
u32 cssid : 8;
|
|
|
|
u32 last_sch : 16;
|
|
|
|
u32 : 32;
|
|
|
|
struct chsc_header response;
|
|
|
|
u8 data[PAGE_SIZE - 20];
|
|
|
|
} __attribute__ ((packed)) *sscud_area;
|
|
|
|
|
|
|
|
sscud_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
|
|
|
|
if (!sscud_area)
|
|
|
|
return -ENOMEM;
|
|
|
|
cud = kzalloc(sizeof(*cud), GFP_KERNEL);
|
|
|
|
if (!cud) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
if (copy_from_user(cud, user_cud, sizeof(*cud))) {
|
|
|
|
ret = -EFAULT;
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
sscud_area->request.length = 0x0010;
|
|
|
|
sscud_area->request.code = 0x0006;
|
|
|
|
sscud_area->m = cud->schid.m;
|
|
|
|
sscud_area->fmt1 = cud->fmt;
|
|
|
|
sscud_area->ssid = cud->schid.ssid;
|
|
|
|
sscud_area->first_sch = cud->schid.sch_no;
|
|
|
|
sscud_area->cssid = cud->schid.cssid;
|
|
|
|
sscud_area->last_sch = cud->schid.sch_no;
|
|
|
|
|
|
|
|
ccode = chsc(sscud_area);
|
|
|
|
if (ccode != 0) {
|
|
|
|
ret = -EIO;
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
if (sscud_area->response.code != 0x0001) {
|
|
|
|
ret = -EIO;
|
|
|
|
CHSC_MSG(0, "sscud: response code=%x\n",
|
|
|
|
sscud_area->response.code);
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
memcpy(&cud->scub, &sscud_area->response, sscud_area->response.length);
|
|
|
|
if (copy_to_user(user_cud, cud, sizeof(*cud)))
|
|
|
|
ret = -EFAULT;
|
|
|
|
else
|
|
|
|
ret = 0;
|
|
|
|
out_free:
|
|
|
|
kfree(cud);
|
|
|
|
free_page((unsigned long)sscud_area);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int chsc_ioctl_conf_info(void __user *user_ci)
|
|
|
|
{
|
|
|
|
struct chsc_conf_info *ci;
|
|
|
|
int ret, ccode;
|
|
|
|
struct {
|
|
|
|
struct chsc_header request;
|
|
|
|
u32 : 2;
|
|
|
|
u32 m : 1;
|
|
|
|
u32 : 1;
|
|
|
|
u32 fmt1 : 4;
|
|
|
|
u32 cssid : 8;
|
|
|
|
u32 : 6;
|
|
|
|
u32 ssid : 2;
|
|
|
|
u32 : 8;
|
|
|
|
u64 : 64;
|
|
|
|
struct chsc_header response;
|
|
|
|
u8 data[PAGE_SIZE - 20];
|
|
|
|
} __attribute__ ((packed)) *sci_area;
|
|
|
|
|
|
|
|
sci_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
|
|
|
|
if (!sci_area)
|
|
|
|
return -ENOMEM;
|
|
|
|
ci = kzalloc(sizeof(*ci), GFP_KERNEL);
|
|
|
|
if (!ci) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
if (copy_from_user(ci, user_ci, sizeof(*ci))) {
|
|
|
|
ret = -EFAULT;
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
sci_area->request.length = 0x0010;
|
|
|
|
sci_area->request.code = 0x0012;
|
|
|
|
sci_area->m = ci->id.m;
|
|
|
|
sci_area->fmt1 = ci->fmt;
|
|
|
|
sci_area->cssid = ci->id.cssid;
|
|
|
|
sci_area->ssid = ci->id.ssid;
|
|
|
|
|
|
|
|
ccode = chsc(sci_area);
|
|
|
|
if (ccode != 0) {
|
|
|
|
ret = -EIO;
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
if (sci_area->response.code != 0x0001) {
|
|
|
|
ret = -EIO;
|
|
|
|
CHSC_MSG(0, "sci: response code=%x\n",
|
|
|
|
sci_area->response.code);
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
memcpy(&ci->scid, &sci_area->response, sci_area->response.length);
|
|
|
|
if (copy_to_user(user_ci, ci, sizeof(*ci)))
|
|
|
|
ret = -EFAULT;
|
|
|
|
else
|
|
|
|
ret = 0;
|
|
|
|
out_free:
|
|
|
|
kfree(ci);
|
|
|
|
free_page((unsigned long)sci_area);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int chsc_ioctl_conf_comp_list(void __user *user_ccl)
|
|
|
|
{
|
|
|
|
struct chsc_comp_list *ccl;
|
|
|
|
int ret, ccode;
|
|
|
|
struct {
|
|
|
|
struct chsc_header request;
|
|
|
|
u32 ctype : 8;
|
|
|
|
u32 : 4;
|
|
|
|
u32 fmt : 4;
|
|
|
|
u32 : 16;
|
|
|
|
u64 : 64;
|
|
|
|
u32 list_parm[2];
|
|
|
|
u64 : 64;
|
|
|
|
struct chsc_header response;
|
|
|
|
u8 data[PAGE_SIZE - 36];
|
|
|
|
} __attribute__ ((packed)) *sccl_area;
|
|
|
|
struct {
|
|
|
|
u32 m : 1;
|
|
|
|
u32 : 31;
|
|
|
|
u32 cssid : 8;
|
|
|
|
u32 : 16;
|
|
|
|
u32 chpid : 8;
|
|
|
|
} __attribute__ ((packed)) *chpid_parm;
|
|
|
|
struct {
|
|
|
|
u32 f_cssid : 8;
|
|
|
|
u32 l_cssid : 8;
|
|
|
|
u32 : 16;
|
|
|
|
u32 res;
|
|
|
|
} __attribute__ ((packed)) *cssids_parm;
|
|
|
|
|
|
|
|
sccl_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
|
|
|
|
if (!sccl_area)
|
|
|
|
return -ENOMEM;
|
|
|
|
ccl = kzalloc(sizeof(*ccl), GFP_KERNEL);
|
|
|
|
if (!ccl) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
if (copy_from_user(ccl, user_ccl, sizeof(*ccl))) {
|
|
|
|
ret = -EFAULT;
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
sccl_area->request.length = 0x0020;
|
|
|
|
sccl_area->request.code = 0x0030;
|
|
|
|
sccl_area->fmt = ccl->req.fmt;
|
|
|
|
sccl_area->ctype = ccl->req.ctype;
|
|
|
|
switch (sccl_area->ctype) {
|
|
|
|
case CCL_CU_ON_CHP:
|
|
|
|
case CCL_IOP_CHP:
|
|
|
|
chpid_parm = (void *)&sccl_area->list_parm;
|
|
|
|
chpid_parm->m = ccl->req.chpid.m;
|
|
|
|
chpid_parm->cssid = ccl->req.chpid.chp.cssid;
|
|
|
|
chpid_parm->chpid = ccl->req.chpid.chp.id;
|
|
|
|
break;
|
|
|
|
case CCL_CSS_IMG:
|
|
|
|
case CCL_CSS_IMG_CONF_CHAR:
|
|
|
|
cssids_parm = (void *)&sccl_area->list_parm;
|
|
|
|
cssids_parm->f_cssid = ccl->req.cssids.f_cssid;
|
|
|
|
cssids_parm->l_cssid = ccl->req.cssids.l_cssid;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ccode = chsc(sccl_area);
|
|
|
|
if (ccode != 0) {
|
|
|
|
ret = -EIO;
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
if (sccl_area->response.code != 0x0001) {
|
|
|
|
ret = -EIO;
|
|
|
|
CHSC_MSG(0, "sccl: response code=%x\n",
|
|
|
|
sccl_area->response.code);
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
memcpy(&ccl->sccl, &sccl_area->response, sccl_area->response.length);
|
|
|
|
if (copy_to_user(user_ccl, ccl, sizeof(*ccl)))
|
|
|
|
ret = -EFAULT;
|
|
|
|
else
|
|
|
|
ret = 0;
|
|
|
|
out_free:
|
|
|
|
kfree(ccl);
|
|
|
|
free_page((unsigned long)sccl_area);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int chsc_ioctl_chpd(void __user *user_chpd)
|
|
|
|
{
|
2010-10-25 22:10:30 +08:00
|
|
|
struct chsc_scpd *scpd_area;
|
2008-07-14 15:59:05 +08:00
|
|
|
struct chsc_cpd_info *chpd;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
chpd = kzalloc(sizeof(*chpd), GFP_KERNEL);
|
2010-10-25 22:10:30 +08:00
|
|
|
scpd_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
|
|
|
|
if (!scpd_area || !chpd) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out_free;
|
|
|
|
}
|
2008-07-14 15:59:05 +08:00
|
|
|
if (copy_from_user(chpd, user_chpd, sizeof(*chpd))) {
|
|
|
|
ret = -EFAULT;
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
ret = chsc_determine_channel_path_desc(chpd->chpid, chpd->fmt,
|
|
|
|
chpd->rfmt, chpd->c, chpd->m,
|
2010-10-25 22:10:30 +08:00
|
|
|
scpd_area);
|
2008-07-14 15:59:05 +08:00
|
|
|
if (ret)
|
|
|
|
goto out_free;
|
2010-10-25 22:10:30 +08:00
|
|
|
memcpy(&chpd->chpdb, &scpd_area->response, scpd_area->response.length);
|
2008-07-14 15:59:05 +08:00
|
|
|
if (copy_to_user(user_chpd, chpd, sizeof(*chpd)))
|
|
|
|
ret = -EFAULT;
|
|
|
|
out_free:
|
|
|
|
kfree(chpd);
|
2010-10-25 22:10:30 +08:00
|
|
|
free_page((unsigned long)scpd_area);
|
2008-07-14 15:59:05 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int chsc_ioctl_dcal(void __user *user_dcal)
|
|
|
|
{
|
|
|
|
struct chsc_dcal *dcal;
|
|
|
|
int ret, ccode;
|
|
|
|
struct {
|
|
|
|
struct chsc_header request;
|
|
|
|
u32 atype : 8;
|
|
|
|
u32 : 4;
|
|
|
|
u32 fmt : 4;
|
|
|
|
u32 : 16;
|
|
|
|
u32 res0[2];
|
|
|
|
u32 list_parm[2];
|
|
|
|
u32 res1[2];
|
|
|
|
struct chsc_header response;
|
|
|
|
u8 data[PAGE_SIZE - 36];
|
|
|
|
} __attribute__ ((packed)) *sdcal_area;
|
|
|
|
|
|
|
|
sdcal_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
|
|
|
|
if (!sdcal_area)
|
|
|
|
return -ENOMEM;
|
|
|
|
dcal = kzalloc(sizeof(*dcal), GFP_KERNEL);
|
|
|
|
if (!dcal) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
if (copy_from_user(dcal, user_dcal, sizeof(*dcal))) {
|
|
|
|
ret = -EFAULT;
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
sdcal_area->request.length = 0x0020;
|
|
|
|
sdcal_area->request.code = 0x0034;
|
|
|
|
sdcal_area->atype = dcal->req.atype;
|
|
|
|
sdcal_area->fmt = dcal->req.fmt;
|
|
|
|
memcpy(&sdcal_area->list_parm, &dcal->req.list_parm,
|
|
|
|
sizeof(sdcal_area->list_parm));
|
|
|
|
|
|
|
|
ccode = chsc(sdcal_area);
|
|
|
|
if (ccode != 0) {
|
|
|
|
ret = -EIO;
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
if (sdcal_area->response.code != 0x0001) {
|
|
|
|
ret = -EIO;
|
|
|
|
CHSC_MSG(0, "sdcal: response code=%x\n",
|
|
|
|
sdcal_area->response.code);
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
memcpy(&dcal->sdcal, &sdcal_area->response,
|
|
|
|
sdcal_area->response.length);
|
|
|
|
if (copy_to_user(user_dcal, dcal, sizeof(*dcal)))
|
|
|
|
ret = -EFAULT;
|
|
|
|
else
|
|
|
|
ret = 0;
|
|
|
|
out_free:
|
|
|
|
kfree(dcal);
|
|
|
|
free_page((unsigned long)sdcal_area);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static long chsc_ioctl(struct file *filp, unsigned int cmd,
|
|
|
|
unsigned long arg)
|
|
|
|
{
|
2010-01-14 03:44:30 +08:00
|
|
|
void __user *argp;
|
|
|
|
|
2008-07-14 15:59:05 +08:00
|
|
|
CHSC_MSG(2, "chsc_ioctl called, cmd=%x\n", cmd);
|
2010-01-14 03:44:30 +08:00
|
|
|
if (is_compat_task())
|
|
|
|
argp = compat_ptr(arg);
|
|
|
|
else
|
|
|
|
argp = (void __user *)arg;
|
2008-07-14 15:59:05 +08:00
|
|
|
switch (cmd) {
|
|
|
|
case CHSC_START:
|
2010-01-14 03:44:30 +08:00
|
|
|
return chsc_ioctl_start(argp);
|
2013-06-06 15:44:28 +08:00
|
|
|
case CHSC_START_SYNC:
|
|
|
|
return chsc_ioctl_start_sync(argp);
|
2008-07-14 15:59:05 +08:00
|
|
|
case CHSC_INFO_CHANNEL_PATH:
|
2010-01-14 03:44:30 +08:00
|
|
|
return chsc_ioctl_info_channel_path(argp);
|
2008-07-14 15:59:05 +08:00
|
|
|
case CHSC_INFO_CU:
|
2010-01-14 03:44:30 +08:00
|
|
|
return chsc_ioctl_info_cu(argp);
|
2008-07-14 15:59:05 +08:00
|
|
|
case CHSC_INFO_SCH_CU:
|
2010-01-14 03:44:30 +08:00
|
|
|
return chsc_ioctl_info_sch_cu(argp);
|
2008-07-14 15:59:05 +08:00
|
|
|
case CHSC_INFO_CI:
|
2010-01-14 03:44:30 +08:00
|
|
|
return chsc_ioctl_conf_info(argp);
|
2008-07-14 15:59:05 +08:00
|
|
|
case CHSC_INFO_CCL:
|
2010-01-14 03:44:30 +08:00
|
|
|
return chsc_ioctl_conf_comp_list(argp);
|
2008-07-14 15:59:05 +08:00
|
|
|
case CHSC_INFO_CPD:
|
2010-01-14 03:44:30 +08:00
|
|
|
return chsc_ioctl_chpd(argp);
|
2008-07-14 15:59:05 +08:00
|
|
|
case CHSC_INFO_DCAL:
|
2010-01-14 03:44:30 +08:00
|
|
|
return chsc_ioctl_dcal(argp);
|
2013-06-06 15:50:21 +08:00
|
|
|
case CHSC_ON_CLOSE_SET:
|
|
|
|
return chsc_ioctl_on_close_set(argp);
|
|
|
|
case CHSC_ON_CLOSE_REMOVE:
|
|
|
|
return chsc_ioctl_on_close_remove();
|
2008-07-14 15:59:05 +08:00
|
|
|
default: /* unknown ioctl number */
|
|
|
|
return -ENOIOCTLCMD;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-06 15:49:09 +08:00
|
|
|
static atomic_t chsc_ready_for_use = ATOMIC_INIT(1);
|
|
|
|
|
|
|
|
static int chsc_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
if (!atomic_dec_and_test(&chsc_ready_for_use)) {
|
|
|
|
atomic_inc(&chsc_ready_for_use);
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
return nonseekable_open(inode, file);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int chsc_release(struct inode *inode, struct file *filp)
|
|
|
|
{
|
2013-06-06 15:50:21 +08:00
|
|
|
char dbf[13];
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
mutex_lock(&on_close_mutex);
|
|
|
|
if (!on_close_chsc_area)
|
|
|
|
goto out_unlock;
|
|
|
|
init_completion(&on_close_request->completion);
|
|
|
|
CHSC_LOG(0, "on_close");
|
|
|
|
chsc_log_command(on_close_chsc_area);
|
|
|
|
spin_lock_irq(&chsc_lock);
|
|
|
|
ret = chsc_async(on_close_chsc_area, on_close_request);
|
|
|
|
spin_unlock_irq(&chsc_lock);
|
|
|
|
if (ret == -EINPROGRESS) {
|
|
|
|
wait_for_completion(&on_close_request->completion);
|
|
|
|
ret = chsc_examine_irb(on_close_request);
|
|
|
|
}
|
2013-06-10 20:07:44 +08:00
|
|
|
snprintf(dbf, sizeof(dbf), "relret:%d", ret);
|
2013-06-06 15:50:21 +08:00
|
|
|
CHSC_LOG(0, dbf);
|
|
|
|
free_page((unsigned long)on_close_chsc_area);
|
|
|
|
on_close_chsc_area = NULL;
|
|
|
|
kfree(on_close_request);
|
|
|
|
on_close_request = NULL;
|
|
|
|
out_unlock:
|
|
|
|
mutex_unlock(&on_close_mutex);
|
2013-06-06 15:49:09 +08:00
|
|
|
atomic_inc(&chsc_ready_for_use);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-07-14 15:59:05 +08:00
|
|
|
static const struct file_operations chsc_fops = {
|
|
|
|
.owner = THIS_MODULE,
|
2013-06-06 15:49:09 +08:00
|
|
|
.open = chsc_open,
|
|
|
|
.release = chsc_release,
|
2008-07-14 15:59:05 +08:00
|
|
|
.unlocked_ioctl = chsc_ioctl,
|
|
|
|
.compat_ioctl = chsc_ioctl,
|
llseek: automatically add .llseek fop
All file_operations should get a .llseek operation so we can make
nonseekable_open the default for future file operations without a
.llseek pointer.
The three cases that we can automatically detect are no_llseek, seq_lseek
and default_llseek. For cases where we can we can automatically prove that
the file offset is always ignored, we use noop_llseek, which maintains
the current behavior of not returning an error from a seek.
New drivers should normally not use noop_llseek but instead use no_llseek
and call nonseekable_open at open time. Existing drivers can be converted
to do the same when the maintainer knows for certain that no user code
relies on calling seek on the device file.
The generated code is often incorrectly indented and right now contains
comments that clarify for each added line why a specific variant was
chosen. In the version that gets submitted upstream, the comments will
be gone and I will manually fix the indentation, because there does not
seem to be a way to do that using coccinelle.
Some amount of new code is currently sitting in linux-next that should get
the same modifications, which I will do at the end of the merge window.
Many thanks to Julia Lawall for helping me learn to write a semantic
patch that does all this.
===== begin semantic patch =====
// This adds an llseek= method to all file operations,
// as a preparation for making no_llseek the default.
//
// The rules are
// - use no_llseek explicitly if we do nonseekable_open
// - use seq_lseek for sequential files
// - use default_llseek if we know we access f_pos
// - use noop_llseek if we know we don't access f_pos,
// but we still want to allow users to call lseek
//
@ open1 exists @
identifier nested_open;
@@
nested_open(...)
{
<+...
nonseekable_open(...)
...+>
}
@ open exists@
identifier open_f;
identifier i, f;
identifier open1.nested_open;
@@
int open_f(struct inode *i, struct file *f)
{
<+...
(
nonseekable_open(...)
|
nested_open(...)
)
...+>
}
@ read disable optional_qualifier exists @
identifier read_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
expression E;
identifier func;
@@
ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
{
<+...
(
*off = E
|
*off += E
|
func(..., off, ...)
|
E = *off
)
...+>
}
@ read_no_fpos disable optional_qualifier exists @
identifier read_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
@@
ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
{
... when != off
}
@ write @
identifier write_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
expression E;
identifier func;
@@
ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
{
<+...
(
*off = E
|
*off += E
|
func(..., off, ...)
|
E = *off
)
...+>
}
@ write_no_fpos @
identifier write_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
@@
ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
{
... when != off
}
@ fops0 @
identifier fops;
@@
struct file_operations fops = {
...
};
@ has_llseek depends on fops0 @
identifier fops0.fops;
identifier llseek_f;
@@
struct file_operations fops = {
...
.llseek = llseek_f,
...
};
@ has_read depends on fops0 @
identifier fops0.fops;
identifier read_f;
@@
struct file_operations fops = {
...
.read = read_f,
...
};
@ has_write depends on fops0 @
identifier fops0.fops;
identifier write_f;
@@
struct file_operations fops = {
...
.write = write_f,
...
};
@ has_open depends on fops0 @
identifier fops0.fops;
identifier open_f;
@@
struct file_operations fops = {
...
.open = open_f,
...
};
// use no_llseek if we call nonseekable_open
////////////////////////////////////////////
@ nonseekable1 depends on !has_llseek && has_open @
identifier fops0.fops;
identifier nso ~= "nonseekable_open";
@@
struct file_operations fops = {
... .open = nso, ...
+.llseek = no_llseek, /* nonseekable */
};
@ nonseekable2 depends on !has_llseek @
identifier fops0.fops;
identifier open.open_f;
@@
struct file_operations fops = {
... .open = open_f, ...
+.llseek = no_llseek, /* open uses nonseekable */
};
// use seq_lseek for sequential files
/////////////////////////////////////
@ seq depends on !has_llseek @
identifier fops0.fops;
identifier sr ~= "seq_read";
@@
struct file_operations fops = {
... .read = sr, ...
+.llseek = seq_lseek, /* we have seq_read */
};
// use default_llseek if there is a readdir
///////////////////////////////////////////
@ fops1 depends on !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier readdir_e;
@@
// any other fop is used that changes pos
struct file_operations fops = {
... .readdir = readdir_e, ...
+.llseek = default_llseek, /* readdir is present */
};
// use default_llseek if at least one of read/write touches f_pos
/////////////////////////////////////////////////////////////////
@ fops2 depends on !fops1 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read.read_f;
@@
// read fops use offset
struct file_operations fops = {
... .read = read_f, ...
+.llseek = default_llseek, /* read accesses f_pos */
};
@ fops3 depends on !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier write.write_f;
@@
// write fops use offset
struct file_operations fops = {
... .write = write_f, ...
+ .llseek = default_llseek, /* write accesses f_pos */
};
// Use noop_llseek if neither read nor write accesses f_pos
///////////////////////////////////////////////////////////
@ fops4 depends on !fops1 && !fops2 && !fops3 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read_no_fpos.read_f;
identifier write_no_fpos.write_f;
@@
// write fops use offset
struct file_operations fops = {
...
.write = write_f,
.read = read_f,
...
+.llseek = noop_llseek, /* read and write both use no f_pos */
};
@ depends on has_write && !has_read && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier write_no_fpos.write_f;
@@
struct file_operations fops = {
... .write = write_f, ...
+.llseek = noop_llseek, /* write uses no f_pos */
};
@ depends on has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read_no_fpos.read_f;
@@
struct file_operations fops = {
... .read = read_f, ...
+.llseek = noop_llseek, /* read uses no f_pos */
};
@ depends on !has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
@@
struct file_operations fops = {
...
+.llseek = noop_llseek, /* no read or write fn */
};
===== End semantic patch =====
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Cc: Julia Lawall <julia@diku.dk>
Cc: Christoph Hellwig <hch@infradead.org>
2010-08-16 00:52:59 +08:00
|
|
|
.llseek = no_llseek,
|
2008-07-14 15:59:05 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct miscdevice chsc_misc_device = {
|
|
|
|
.minor = MISC_DYNAMIC_MINOR,
|
|
|
|
.name = "chsc",
|
|
|
|
.fops = &chsc_fops,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init chsc_misc_init(void)
|
|
|
|
{
|
|
|
|
return misc_register(&chsc_misc_device);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void chsc_misc_cleanup(void)
|
|
|
|
{
|
|
|
|
misc_deregister(&chsc_misc_device);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __init chsc_sch_init(void)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = chsc_init_dbfs();
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
isc_register(CHSC_SCH_ISC);
|
|
|
|
ret = chsc_init_sch_driver();
|
|
|
|
if (ret)
|
|
|
|
goto out_dbf;
|
|
|
|
ret = chsc_misc_init();
|
|
|
|
if (ret)
|
|
|
|
goto out_driver;
|
|
|
|
return ret;
|
|
|
|
out_driver:
|
|
|
|
chsc_cleanup_sch_driver();
|
|
|
|
out_dbf:
|
|
|
|
isc_unregister(CHSC_SCH_ISC);
|
|
|
|
chsc_remove_dbfs();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit chsc_sch_exit(void)
|
|
|
|
{
|
|
|
|
chsc_misc_cleanup();
|
|
|
|
chsc_cleanup_sch_driver();
|
|
|
|
isc_unregister(CHSC_SCH_ISC);
|
|
|
|
chsc_remove_dbfs();
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(chsc_sch_init);
|
|
|
|
module_exit(chsc_sch_exit);
|