summaryrefslogtreecommitdiff
path: root/drivers/s390/char/tape_char.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/s390/char/tape_char.c')
-rw-r--r--drivers/s390/char/tape_char.c142
1 files changed, 57 insertions, 85 deletions
diff --git a/drivers/s390/char/tape_char.c b/drivers/s390/char/tape_char.c
index 89778d922d9f..c5d3c303c15c 100644
--- a/drivers/s390/char/tape_char.c
+++ b/drivers/s390/char/tape_char.c
@@ -10,14 +10,12 @@
* Martin Schwidefsky <schwidefsky@de.ibm.com>
*/
-#define KMSG_COMPONENT "tape"
-#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
+#define pr_fmt(fmt) "tape: " fmt
#include <linux/module.h>
#include <linux/types.h>
#include <linux/proc_fs.h>
#include <linux/mtio.h>
-#include <linux/compat.h>
#include <linux/uaccess.h>
@@ -37,9 +35,6 @@ static ssize_t tapechar_write(struct file *, const char __user *, size_t, loff_t
static int tapechar_open(struct inode *,struct file *);
static int tapechar_release(struct inode *,struct file *);
static long tapechar_ioctl(struct file *, unsigned int, unsigned long);
-#ifdef CONFIG_COMPAT
-static long tapechar_compat_ioctl(struct file *, unsigned int, unsigned long);
-#endif
static const struct file_operations tape_fops =
{
@@ -47,9 +42,6 @@ static const struct file_operations tape_fops =
.read = tapechar_read,
.write = tapechar_write,
.unlocked_ioctl = tapechar_ioctl,
-#ifdef CONFIG_COMPAT
- .compat_ioctl = tapechar_compat_ioctl,
-#endif
.open = tapechar_open,
.release = tapechar_release,
};
@@ -64,7 +56,7 @@ tapechar_setup_device(struct tape_device * device)
{
char device_name[20];
- sprintf(device_name, "ntibm%i", device->first_minor / 2);
+ scnprintf(device_name, sizeof(device_name), "ntibm%i", device->first_minor / 2);
device->nt = register_tape_dev(
&device->cdev->dev,
MKDEV(tapechar_major, device->first_minor),
@@ -93,33 +85,6 @@ tapechar_cleanup_device(struct tape_device *device)
device->nt = NULL;
}
-static int
-tapechar_check_idalbuffer(struct tape_device *device, size_t block_size)
-{
- struct idal_buffer *new;
-
- if (device->char_data.idal_buf != NULL &&
- device->char_data.idal_buf->size == block_size)
- return 0;
-
- if (block_size > MAX_BLOCKSIZE) {
- DBF_EVENT(3, "Invalid blocksize (%zd > %d)\n",
- block_size, MAX_BLOCKSIZE);
- return -EINVAL;
- }
-
- /* The current idal buffer is not correct. Allocate a new one. */
- new = idal_buffer_alloc(block_size, 0);
- if (IS_ERR(new))
- return -ENOMEM;
-
- if (device->char_data.idal_buf != NULL)
- idal_buffer_free(device->char_data.idal_buf);
-
- device->char_data.idal_buf = new;
-
- return 0;
-}
/*
* Tape device read function
@@ -127,9 +92,12 @@ tapechar_check_idalbuffer(struct tape_device *device, size_t block_size)
static ssize_t
tapechar_read(struct file *filp, char __user *data, size_t count, loff_t *ppos)
{
- struct tape_device *device;
struct tape_request *request;
+ struct ccw1 *ccw, *last_ccw;
+ struct tape_device *device;
+ struct idal_buffer **ibs;
size_t block_size;
+ size_t read = 0;
int rc;
DBF_EVENT(6, "TCHAR:read\n");
@@ -156,24 +124,37 @@ tapechar_read(struct file *filp, char __user *data, size_t count, loff_t *ppos)
block_size = count;
}
- rc = tapechar_check_idalbuffer(device, block_size);
+ rc = tape_check_idalbuffer(device, block_size);
if (rc)
return rc;
DBF_EVENT(6, "TCHAR:nbytes: %lx\n", block_size);
/* Let the discipline build the ccw chain. */
- request = device->discipline->read_block(device, block_size);
+ request = device->discipline->read_block(device);
if (IS_ERR(request))
return PTR_ERR(request);
/* Execute it. */
rc = tape_do_io(device, request);
if (rc == 0) {
- rc = block_size - request->rescnt;
DBF_EVENT(6, "TCHAR:rbytes: %x\n", rc);
- /* Copy data from idal buffer to user space. */
- if (idal_buffer_to_user(device->char_data.idal_buf,
- data, rc) != 0)
- rc = -EFAULT;
+ /* Channel Program Address (cpa) points to last CCW + 8 */
+ last_ccw = dma32_to_virt(request->irb.scsw.cmd.cpa);
+ ccw = request->cpaddr;
+ ibs = device->char_data.ibs;
+ while (++ccw < last_ccw) {
+ /* Copy data from idal buffer to user space. */
+ if (idal_buffer_to_user(*ibs++, data, ccw->count) != 0) {
+ rc = -EFAULT;
+ break;
+ }
+ read += ccw->count;
+ data += ccw->count;
+ }
+ if (&last_ccw[-1] == &request->cpaddr[1] &&
+ request->rescnt == last_ccw[-1].count)
+ rc = 0;
+ else
+ rc = read - request->rescnt;
}
tape_free_request(request);
return rc;
@@ -185,10 +166,12 @@ tapechar_read(struct file *filp, char __user *data, size_t count, loff_t *ppos)
static ssize_t
tapechar_write(struct file *filp, const char __user *data, size_t count, loff_t *ppos)
{
- struct tape_device *device;
struct tape_request *request;
+ struct ccw1 *ccw, *last_ccw;
+ struct tape_device *device;
+ struct idal_buffer **ibs;
+ size_t written = 0;
size_t block_size;
- size_t written;
int nblocks;
int i, rc;
@@ -208,35 +191,45 @@ tapechar_write(struct file *filp, const char __user *data, size_t count, loff_t
nblocks = 1;
}
- rc = tapechar_check_idalbuffer(device, block_size);
+ rc = tape_check_idalbuffer(device, block_size);
if (rc)
return rc;
- DBF_EVENT(6,"TCHAR:nbytes: %lx\n", block_size);
+ DBF_EVENT(6, "TCHAR:nbytes: %lx\n", block_size);
DBF_EVENT(6, "TCHAR:nblocks: %x\n", nblocks);
/* Let the discipline build the ccw chain. */
- request = device->discipline->write_block(device, block_size);
+ request = device->discipline->write_block(device);
if (IS_ERR(request))
return PTR_ERR(request);
- rc = 0;
- written = 0;
+
for (i = 0; i < nblocks; i++) {
- /* Copy data from user space to idal buffer. */
- if (idal_buffer_from_user(device->char_data.idal_buf,
- data, block_size)) {
- rc = -EFAULT;
- break;
+ size_t wbytes = 0; /* Used to trace written data in dbf */
+
+ ibs = device->char_data.ibs;
+ while (ibs && *ibs) {
+ if (idal_buffer_from_user(*ibs, data, (*ibs)->size)) {
+ rc = -EFAULT;
+ goto out;
+ }
+ data += (*ibs)->size;
+ ibs++;
}
rc = tape_do_io(device, request);
if (rc)
- break;
- DBF_EVENT(6, "TCHAR:wbytes: %lx\n",
- block_size - request->rescnt);
- written += block_size - request->rescnt;
+ goto out;
+
+ /* Channel Program Address (cpa) points to last CCW + 8 */
+ last_ccw = dma32_to_virt(request->irb.scsw.cmd.cpa);
+ ccw = request->cpaddr;
+ while (++ccw < last_ccw)
+ wbytes += ccw->count;
+ DBF_EVENT(6, "TCHAR:wbytes: %lx\n", wbytes - request->rescnt);
+ written += wbytes - request->rescnt;
if (request->rescnt != 0)
break;
- data += block_size;
}
+
+out:
tape_free_request(request);
if (rc == -ENOSPC) {
/*
@@ -324,10 +317,8 @@ tapechar_release(struct inode *inode, struct file *filp)
}
}
- if (device->char_data.idal_buf != NULL) {
- idal_buffer_free(device->char_data.idal_buf);
- device->char_data.idal_buf = NULL;
- }
+ if (device->char_data.ibs)
+ idal_buffer_array_free(&device->char_data.ibs);
tape_release(device);
filp->private_data = NULL;
tape_put_device(device);
@@ -442,25 +433,6 @@ tapechar_ioctl(struct file *filp, unsigned int no, unsigned long data)
return rc;
}
-#ifdef CONFIG_COMPAT
-static long
-tapechar_compat_ioctl(struct file *filp, unsigned int no, unsigned long data)
-{
- struct tape_device *device = filp->private_data;
- long rc;
-
- if (no == MTIOCPOS32)
- no = MTIOCPOS;
- else if (no == MTIOCGET32)
- no = MTIOCGET;
-
- mutex_lock(&device->mutex);
- rc = __tapechar_ioctl(device, no, compat_ptr(data));
- mutex_unlock(&device->mutex);
- return rc;
-}
-#endif /* CONFIG_COMPAT */
-
/*
* Initialize character device frontend.
*/