2016-04-18 18:09:11 +08:00
|
|
|
/*
|
|
|
|
* Driver for Rio Karma
|
2006-08-14 08:30:14 +08:00
|
|
|
*
|
|
|
|
* (c) 2006 Bob Copeland <me@bobcopeland.com>
|
|
|
|
* (c) 2006 Keith Bennett <keith@mcs.st-and.ac.uk>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2009-02-13 03:48:26 +08:00
|
|
|
#include <linux/module.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 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2009-02-13 03:48:26 +08:00
|
|
|
|
2006-08-14 08:30:14 +08:00
|
|
|
#include <scsi/scsi.h>
|
|
|
|
#include <scsi/scsi_cmnd.h>
|
|
|
|
#include <scsi/scsi_device.h>
|
|
|
|
|
|
|
|
#include "usb.h"
|
|
|
|
#include "transport.h"
|
|
|
|
#include "debug.h"
|
2015-05-06 17:24:21 +08:00
|
|
|
#include "scsiglue.h"
|
|
|
|
|
|
|
|
#define DRV_NAME "ums-karma"
|
2006-08-14 08:30:14 +08:00
|
|
|
|
2009-03-01 04:39:20 +08:00
|
|
|
MODULE_DESCRIPTION("Driver for Rio Karma");
|
|
|
|
MODULE_AUTHOR("Bob Copeland <me@bobcopeland.com>, Keith Bennett <keith@mcs.st-and.ac.uk>");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
2006-08-14 08:30:14 +08:00
|
|
|
#define RIO_PREFIX "RIOP\x00"
|
|
|
|
#define RIO_PREFIX_LEN 5
|
|
|
|
#define RIO_SEND_LEN 40
|
|
|
|
#define RIO_RECV_LEN 0x200
|
|
|
|
|
|
|
|
#define RIO_ENTER_STORAGE 0x1
|
|
|
|
#define RIO_LEAVE_STORAGE 0x2
|
|
|
|
#define RIO_RESET 0xC
|
|
|
|
|
|
|
|
struct karma_data {
|
|
|
|
int in_storage;
|
|
|
|
char *recv;
|
|
|
|
};
|
|
|
|
|
2009-02-13 03:48:26 +08:00
|
|
|
static int rio_karma_init(struct us_data *us);
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The table of devices
|
|
|
|
*/
|
|
|
|
#define UNUSUAL_DEV(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, \
|
|
|
|
vendorName, productName, useProtocol, useTransport, \
|
|
|
|
initFunction, flags) \
|
|
|
|
{ USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax), \
|
2012-08-29 04:37:13 +08:00
|
|
|
.driver_info = (flags) }
|
2009-02-13 03:48:26 +08:00
|
|
|
|
2011-11-15 15:53:35 +08:00
|
|
|
static struct usb_device_id karma_usb_ids[] = {
|
2009-02-13 03:48:26 +08:00
|
|
|
# include "unusual_karma.h"
|
|
|
|
{ } /* Terminating entry */
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(usb, karma_usb_ids);
|
|
|
|
|
|
|
|
#undef UNUSUAL_DEV
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The flags table
|
|
|
|
*/
|
|
|
|
#define UNUSUAL_DEV(idVendor, idProduct, bcdDeviceMin, bcdDeviceMax, \
|
|
|
|
vendor_name, product_name, use_protocol, use_transport, \
|
|
|
|
init_function, Flags) \
|
|
|
|
{ \
|
|
|
|
.vendorName = vendor_name, \
|
|
|
|
.productName = product_name, \
|
|
|
|
.useProtocol = use_protocol, \
|
|
|
|
.useTransport = use_transport, \
|
|
|
|
.initFunction = init_function, \
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct us_unusual_dev karma_unusual_dev_list[] = {
|
|
|
|
# include "unusual_karma.h"
|
|
|
|
{ } /* Terminating entry */
|
|
|
|
};
|
|
|
|
|
|
|
|
#undef UNUSUAL_DEV
|
|
|
|
|
|
|
|
|
2006-08-14 08:30:14 +08:00
|
|
|
/*
|
|
|
|
* Send commands to Rio Karma.
|
|
|
|
*
|
|
|
|
* For each command we send 40 bytes starting 'RIOP\0' followed by
|
|
|
|
* the command number and a sequence number, which the device will ack
|
|
|
|
* with a 512-byte packet with the high four bits set and everything
|
|
|
|
* else null. Then we send 'RIOP\x80' followed by a zero and the
|
|
|
|
* sequence number, until byte 5 in the response repeats the sequence
|
|
|
|
* number.
|
|
|
|
*/
|
|
|
|
static int rio_karma_send_command(char cmd, struct us_data *us)
|
|
|
|
{
|
2017-03-01 05:02:51 +08:00
|
|
|
int result;
|
2006-08-14 08:30:14 +08:00
|
|
|
unsigned long timeout;
|
|
|
|
static unsigned char seq = 1;
|
|
|
|
struct karma_data *data = (struct karma_data *) us->extra;
|
|
|
|
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "sending command %04x\n", cmd);
|
2006-08-14 08:30:14 +08:00
|
|
|
memset(us->iobuf, 0, RIO_SEND_LEN);
|
|
|
|
memcpy(us->iobuf, RIO_PREFIX, RIO_PREFIX_LEN);
|
|
|
|
us->iobuf[5] = cmd;
|
|
|
|
us->iobuf[6] = seq;
|
|
|
|
|
|
|
|
timeout = jiffies + msecs_to_jiffies(6000);
|
|
|
|
for (;;) {
|
|
|
|
result = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe,
|
2017-03-01 05:02:51 +08:00
|
|
|
us->iobuf, RIO_SEND_LEN, NULL);
|
2006-08-14 08:30:14 +08:00
|
|
|
if (result != USB_STOR_XFER_GOOD)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe,
|
2017-03-01 05:02:51 +08:00
|
|
|
data->recv, RIO_RECV_LEN, NULL);
|
2006-08-14 08:30:14 +08:00
|
|
|
if (result != USB_STOR_XFER_GOOD)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
if (data->recv[5] == seq)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (time_after(jiffies, timeout))
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
us->iobuf[4] = 0x80;
|
|
|
|
us->iobuf[5] = 0;
|
|
|
|
msleep(50);
|
|
|
|
}
|
|
|
|
|
|
|
|
seq++;
|
|
|
|
if (seq == 0)
|
|
|
|
seq = 1;
|
|
|
|
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "sent command %04x\n", cmd);
|
2006-08-14 08:30:14 +08:00
|
|
|
return 0;
|
|
|
|
err:
|
2013-04-20 02:44:00 +08:00
|
|
|
usb_stor_dbg(us, "command %04x failed\n", cmd);
|
2006-08-14 08:30:14 +08:00
|
|
|
return USB_STOR_TRANSPORT_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Trap START_STOP and READ_10 to leave/re-enter storage mode.
|
|
|
|
* Everything else is propagated to the normal bulk layer.
|
|
|
|
*/
|
2009-02-13 03:48:26 +08:00
|
|
|
static int rio_karma_transport(struct scsi_cmnd *srb, struct us_data *us)
|
2006-08-14 08:30:14 +08:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct karma_data *data = (struct karma_data *) us->extra;
|
|
|
|
|
|
|
|
if (srb->cmnd[0] == READ_10 && !data->in_storage) {
|
|
|
|
ret = rio_karma_send_command(RIO_ENTER_STORAGE, us);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
data->in_storage = 1;
|
|
|
|
return usb_stor_Bulk_transport(srb, us);
|
|
|
|
} else if (srb->cmnd[0] == START_STOP) {
|
|
|
|
ret = rio_karma_send_command(RIO_LEAVE_STORAGE, us);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
data->in_storage = 0;
|
|
|
|
return rio_karma_send_command(RIO_RESET, us);
|
|
|
|
}
|
|
|
|
return usb_stor_Bulk_transport(srb, us);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void rio_karma_destructor(void *extra)
|
|
|
|
{
|
|
|
|
struct karma_data *data = (struct karma_data *) extra;
|
|
|
|
kfree(data->recv);
|
|
|
|
}
|
|
|
|
|
2009-02-13 03:48:26 +08:00
|
|
|
static int rio_karma_init(struct us_data *us)
|
2006-08-14 08:30:14 +08:00
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
struct karma_data *data = kzalloc(sizeof(struct karma_data), GFP_NOIO);
|
|
|
|
if (!data)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
data->recv = kmalloc(RIO_RECV_LEN, GFP_NOIO);
|
|
|
|
if (!data->recv) {
|
|
|
|
kfree(data);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
us->extra = data;
|
|
|
|
us->extra_destructor = rio_karma_destructor;
|
|
|
|
ret = rio_karma_send_command(RIO_ENTER_STORAGE, us);
|
|
|
|
data->in_storage = (ret == 0);
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
2009-02-13 03:48:26 +08:00
|
|
|
|
2015-05-06 17:24:21 +08:00
|
|
|
static struct scsi_host_template karma_host_template;
|
|
|
|
|
2009-02-13 03:48:26 +08:00
|
|
|
static int karma_probe(struct usb_interface *intf,
|
|
|
|
const struct usb_device_id *id)
|
|
|
|
{
|
|
|
|
struct us_data *us;
|
|
|
|
int result;
|
|
|
|
|
|
|
|
result = usb_stor_probe1(&us, intf, id,
|
2015-05-06 17:24:21 +08:00
|
|
|
(id - karma_usb_ids) + karma_unusual_dev_list,
|
|
|
|
&karma_host_template);
|
2009-02-13 03:48:26 +08:00
|
|
|
if (result)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
us->transport_name = "Rio Karma/Bulk";
|
|
|
|
us->transport = rio_karma_transport;
|
|
|
|
us->transport_reset = usb_stor_Bulk_reset;
|
|
|
|
|
|
|
|
result = usb_stor_probe2(us);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct usb_driver karma_driver = {
|
2015-05-06 17:24:21 +08:00
|
|
|
.name = DRV_NAME,
|
2009-02-13 03:48:26 +08:00
|
|
|
.probe = karma_probe,
|
|
|
|
.disconnect = usb_stor_disconnect,
|
|
|
|
.suspend = usb_stor_suspend,
|
|
|
|
.resume = usb_stor_resume,
|
|
|
|
.reset_resume = usb_stor_reset_resume,
|
|
|
|
.pre_reset = usb_stor_pre_reset,
|
|
|
|
.post_reset = usb_stor_post_reset,
|
|
|
|
.id_table = karma_usb_ids,
|
|
|
|
.soft_unbind = 1,
|
2012-01-14 10:15:21 +08:00
|
|
|
.no_dynamic_id = 1,
|
2009-02-13 03:48:26 +08:00
|
|
|
};
|
|
|
|
|
2015-05-06 17:24:21 +08:00
|
|
|
module_usb_stor_driver(karma_driver, karma_host_template, DRV_NAME);
|