Commit c768f081 authored by Martin Schwidefsky's avatar Martin Schwidefsky Committed by Linus Torvalds

[PATCH] s390: tape driver.

Rework of tape driver

  Almost complete rewrite of the s390 tape driver code by
  Martin Schwidefsky. Skipping the 2.4 era, this makes the tape
  code ready for the future.

  This driver probably doesn't have to change much before 2.6.

Authors:
	Martin Schwidefsky <schwidefsky@de.ibm.com>
	Stefan Bader <shbader@de.ibm.com>
parent f7a9fa93
......@@ -292,16 +292,6 @@ config S390_TAPE
comment "S/390 tape interface support"
depends on S390_TAPE
config S390_TAPE_CHAR
bool "Support for tape character devices"
depends on S390_TAPE
help
Select this option if you want to access your channel-attached
tape devices using the character device interface.
This interface is similar to other Linux tape devices like
SCSI-Tapes (st) and the floppy tape device (ftape).
If unsure, say "Y".
config S390_TAPE_BLOCK
bool "Support for tape block devices"
depends on S390_TAPE
......@@ -316,21 +306,14 @@ config S390_TAPE_BLOCK
comment "S/390 tape hardware support"
depends on S390_TAPE
config S390_TAPE_3490
tristate "Support for 3490 tape hardware"
config S390_TAPE_34XX
tristate "Support for 3480/3490 tape hardware"
depends on S390_TAPE
help
Select this option if you want to access IBM 3480 magnetic
Select this option if you want to access IBM 3480/3490 magnetic
tape subsystems and 100% compatibles.
It is safe to say "Y" here.
config S390_TAPE_3480
tristate "Support for 3480 tape hardware"
depends on S390_TAPE
help
Select this option if you want to access IBM 3490 magnetic
tape subsystems and 100% compatibles.
endmenu
......
This diff is collapsed.
/***************************************************************************
*
* drivers/s390/char/tape3480.c
* tape device discipline for 3480 tapes.
*
* S390 and zSeries version
* Copyright (C) 2001 IBM Corporation
* Author(s): Carsten Otte <cotte@de.ibm.com>
* Tuan Ngo-Anh <ngoanh@de.ibm.com>
*
****************************************************************************
*/
#include "tapedefs.h"
#include <linux/version.h>
#include <linux/compatmac.h>
#include "tape.h"
#include "tape34xx.h"
#include "tape3480.h"
#ifdef CONFIG_S390_TAPE_3480_MODULE
static tape_discipline_t* disc;
void
init_module(void)
{
disc = tape3480_init();
if (disc!= NULL)
tape_register_discipline(disc);
}
void
cleanup_module(void)
{
if (disc!=NULL){
tape_unregister_discipline(disc);
kfree(disc);
}
}
#endif /* CONFIG_S390_TAPE_3480_MODULE */
int
tape3480_setup_device(tape_dev_t * td)
{
tape3480_disc_data_t *data = NULL;
tape_sprintf_event (tape_dbf_area,6,"3480 dsetup: %x\n",td->first_minor);
data = kmalloc (sizeof (tape3480_disc_data_t), GFP_KERNEL | GFP_DMA);
if(data == NULL)
return -1;
data->modeset_byte = 0x00;
td->discdata = (void *) data;
return 0;
}
void
tape3480_cleanup_device(tape_dev_t * td)
{
if(td->discdata){
kfree(td->discdata);
td->discdata = NULL;
}
}
void
tape3480_shutdown (void) {
}
tape_discipline_t *
tape3480_init (void)
{
tape_discipline_t *disc;
tape_sprintf_event (tape_dbf_area,3,"3480 init\n");
disc = kmalloc (sizeof (tape_discipline_t), GFP_ATOMIC);
if (disc == NULL) {
tape_sprintf_exception (tape_dbf_area,3,"disc:nomem\n");
return disc;
}
disc->owner = THIS_MODULE;
disc->cu_type = 0x3480;
disc->setup_device = tape3480_setup_device;
disc->cleanup_device = tape3480_cleanup_device;
disc->init_device = NULL;
disc->process_eov = tape34xx_process_eov;
disc->irq = tape34xx_irq;
disc->write_block = tape34xx_write_block;
disc->read_block = tape34xx_read_block;
disc->ioctl = tape34xx_ioctl;
disc->shutdown = tape3480_shutdown;
disc->discipline_ioctl_overload = tape34xx_ioctl_overload;
disc->bread = tape34xx_bread;
disc->free_bread = tape34xx_free_bread;
disc->bread_enable_locate = tape34xx_bread_enable_locate;
disc->next = NULL;
tape_sprintf_event (tape_dbf_area,3,"3480 regis\n");
return disc;
}
/***************************************************************************
*
* drivers/s390/char/tape3480.h
* tape device discipline for 3480 tapes.
*
* S390 and zSeries version
* Copyright (C) 2001 IBM Corporation
* Author(s): Carsten Otte <cotte@de.ibm.com>
* Tuan Ngo-Anh <ngoanh@de.ibm.com>
*
****************************************************************************
*/
#ifndef _TAPE3480_H
#define _TAPE3480_H
typedef struct _tape3480_disc_data_t {
__u8 modeset_byte;
} tape3480_disc_data_t __attribute__ ((packed, aligned(8)));
tape_discipline_t * tape3480_init (void);
#endif // _TAPE3480_H
/***************************************************************************
*
* drivers/s390/char/tape3490.c
* tape device discipline for 3490E tapes.
*
* S390 and zSeries version
* Copyright (C) 2001 IBM Corporation
* Author(s): Carsten Otte <cotte@de.ibm.com>
* Tuan Ngo-Anh <ngoanh@de.ibm.com>
*
****************************************************************************
*/
#include "tapedefs.h"
#include <linux/version.h>
#include <linux/compatmac.h>
#include "tape.h"
#include "tape34xx.h"
#include "tape3490.h"
#ifdef CONFIG_S390_TAPE_3490_MODULE
static tape_discipline_t* disc;
void
init_module(void)
{
disc = tape3490_init();
if (disc!=NULL)
tape_register_discipline(disc);
}
void
cleanup_module(void)
{
if (disc!=NULL){
tape_unregister_discipline(disc);
kfree(disc);
}
}
#endif /* CONFIG_S390_TAPE_3490_MODULE */
int
tape3490_setup_device (tape_dev_t * td)
{
tape3490_disc_data_t *data = NULL;
tape_sprintf_event (tape_dbf_area,1,"3490 dsetup: %x\n",td->first_minor);
data = kmalloc (sizeof (tape3490_disc_data_t), GFP_KERNEL | GFP_DMA);
if(data == NULL)
return -1;
data->modeset_byte = 0x00;
td->discdata = (void *) data;
return 0;
}
void
tape3490_cleanup_device(tape_dev_t * td)
{
if(td->discdata){
kfree(td->discdata);
td->discdata = NULL;
}
}
void
tape3490_shutdown (void) {
}
tape_discipline_t *
tape3490_init (void)
{
tape_discipline_t *disc;
tape_sprintf_event (tape_dbf_area,3,"3490 init\n");
disc = kmalloc (sizeof (tape_discipline_t), GFP_ATOMIC);
if (disc == NULL) {
tape_sprintf_exception (tape_dbf_area,3,"disc:nomem\n");
return disc;
}
disc->owner = THIS_MODULE;
disc->cu_type = 0x3490;
disc->setup_device = tape3490_setup_device;
disc->cleanup_device = tape3490_cleanup_device;
disc->init_device = NULL;
disc->process_eov = tape34xx_process_eov;
disc->irq = tape34xx_irq;
disc->write_block = tape34xx_write_block;
disc->read_block = tape34xx_read_block;
disc->ioctl = tape34xx_ioctl;
disc->shutdown = tape3490_shutdown;
disc->discipline_ioctl_overload = tape34xx_ioctl_overload;
disc->bread = tape34xx_bread;
disc->free_bread = tape34xx_free_bread;
disc->bread_enable_locate = tape34xx_bread_enable_locate;
disc->next = NULL;
tape_sprintf_event (tape_dbf_area,3,"3490 regis\n");
return disc;
}
/***************************************************************************
*
* drivers/s390/char/tape3490.h
* tape device discipline for 3490E tapes.
*
* S390 and zSeries version
* Copyright (C) 2001 IBM Corporation
* Author(s): Carsten Otte <cotte@de.ibm.com>
* Tuan Ngo-Anh <ngoanh@de.ibm.com>
*
****************************************************************************
*/
#ifndef _TAPE3490_H
#define _TAPE3490_H
typedef struct _tape3490_disc_data_t {
__u8 modeset_byte;
} tape3490_disc_data_t __attribute__ ((packed, aligned(8)));
tape_discipline_t * tape3490_init (void);
#endif // _TAPE3490_H
This diff is collapsed.
/***************************************************************************
*
* drivers/s390/char/tape34xx.h
* common tape device discipline for 34xx tapes.
*
* S390 and zSeries version
* Copyright (C) 2001 IBM Corporation
* Author(s): Carsten Otte <cotte@de.ibm.com>
* Tuan Ngo-Anh <ngoanh@de.ibm.com>
*
****************************************************************************
*/
#ifndef _TAPE34XX_H
#define _TAPE34XX_H
/*
* The CCW commands for the Tape type of command.
*/
#define INVALID_00 0x00 /* Invalid cmd */
#define BACKSPACEBLOCK 0x27 /* Back Space block */
#define BACKSPACEFILE 0x2f /* Back Space file */
#define DATA_SEC_ERASE 0x97 /* Data security erase */
#define ERASE_GAP 0x17 /* Erase Gap */
#define FORSPACEBLOCK 0x37 /* Forward space block */
#define FORSPACEFILE 0x3F /* Forward Space file */
#define FORCE_STREAM_CNT 0xEB /* Forced streaming count # */
#define NOP 0x03 /* No operation */
#define READ_FORWARD 0x02 /* Read forward */
#define REWIND 0x07 /* Rewind */
#define REWIND_UNLOAD 0x0F /* Rewind and Unload */
#define SENSE 0x04 /* Sense */
#define NEW_MODE_SET 0xEB /* Guess it is Mode set */
#define WRITE_CMD 0x01 /* Write */
#define WRITETAPEMARK 0x1F /* Write Tape Mark */
#define ASSIGN 0xB7 /* 3420 REJECT,3480 OK */
#define CONTROL_ACCESS 0xE3 /* Set high speed */
#define DIAG_MODE_SET 0x0B /* 3420 NOP, 3480 REJECT*/
#define LOAD_DISPLAY 0x9F /* 3420 REJECT,3480 OK */
#define LOCATE 0x4F /* 3420 REJ, 3480 NOP */
#define LOOP_WRITE_TO_READ 0x8B /* 3480 REJECT */
#define MODE_SET_DB 0xDB /* 3420 REJECT,3480 OK */
#define MODE_SET_C3 0xC3 /* for 3420 */
#define MODE_SET_CB 0xCB /* for 3420 */
#define MODE_SET_D3 0xD3 /* for 3420 */
#define READ_BACKWARD 0x0C /* */
#define READ_BLOCK_ID 0x22 /* 3420 REJECT,3480 OK */
#define READ_BUFFER 0x12 /* 3420 REJECT,3480 OK */
#define READ_BUFF_LOG 0x24 /* 3420 REJECT,3480 OK */
#define RELEASE 0xD4 /* 3420 NOP, 3480 REJECT*/
#define REQ_TRK_IN_ERROR 0x1B /* 3420 NOP, 3480 REJECT*/
#define RESERVE 0xF4 /* 3420 NOP, 3480 REJECT*/
#define SENSE_GROUP_ID 0x34 /* 3420 REJECT,3480 OK */
#define SENSE_ID 0xE4 /* 3420 REJECT,3480 OK */
#define READ_DEV_CHAR 0x64 /* Read device characteristics */
#define SET_DIAGNOSE 0x4B /* 3420 NOP, 3480 REJECT*/
#define SET_GROUP_ID 0xAF /* 3420 REJECT,3480 OK */
#define SET_TAPE_WRITE_IMMED 0xC3 /* for 3480 */
#define SUSPEND 0x5B /* 3420 REJ, 3480 NOP */
#define SYNC 0x43 /* Synchronize (flush buffer) */
#define UNASSIGN 0xC7 /* 3420 REJECT,3480 OK */
#define PERF_SUBSYS_FUNC 0x77 /* 3490 CMD */
#define READ_CONFIG_DATA 0xFA /* 3490 CMD */
#define READ_MESSAGE_ID 0x4E /* 3490 CMD */
#define READ_SUBSYS_DATA 0x3E /* 3490 CMD */
#define SET_INTERFACE_ID 0x73 /* 3490 CMD */
#define COMMAND_CHAIN CCW_FLAG_CC /* redefine from irq.h */
#define CHANNEL_END DEV_STAT_CHN_END /* redefine from irq.h */
#define DEVICE_END DEV_STAT_DEV_END /* redefine from irq.h */
#define UNIT_CHECK DEV_STAT_UNIT_CHECK /* redefine from irq.h */
#define UNIT_EXCEPTION DEV_STAT_UNIT_EXCEP /* redefine from irq.h */
#define CONTROL_UNIT_END DEV_STAT_CU_END /* redefine from irq.h */
#define INCORR_LEN SCHN_STAT_INCORR_LEN /* redefine from irq.h */
#define SENSE_COMMAND_REJECT 0x80
#define SENSE_INTERVENTION_REQUIRED 0x40
#define SENSE_BUS_OUT_CHECK 0x20
#define SENSE_EQUIPMENT_CHECK 0x10
#define SENSE_DATA_CHECK 0x08
#define SENSE_OVERRUN 0x04
#define SENSE_DEFERRED_UNIT_CHECK 0x02
#define SENSE_ASSIGNED_ELSEWHERE 0x01
#define SENSE_LOCATE_FAILURE 0x80
#define SENSE_DRIVE_ONLINE 0x40
#define SENSE_RESERVED 0x20
#define SENSE_RECORD_SEQUENCE_ERR 0x10
#define SENSE_BEGINNING_OF_TAPE 0x08
#define SENSE_WRITE_MODE 0x04
#define SENSE_WRITE_PROTECT 0x02
#define SENSE_NOT_CAPABLE 0x01
#define SENSE_CHANNEL_ADAPTER_CODE 0xE0
#define SENSE_CHANNEL_ADAPTER_LOC 0x10
#define SENSE_REPORTING_CU 0x08
#define SENSE_AUTOMATIC_LOADER 0x04
#define SENSE_TAPE_SYNC_MODE 0x02
#define SENSE_TAPE_POSITIONING 0x01
typedef struct _tape34xx_disc_data_t {
__u8 modeset_byte;
} tape34xx_disc_data_t __attribute__ ((packed, aligned(8)));
#define MOD_BYTE ((tape34xx_disc_data_t *)td->discdata)->modeset_byte
/* discipline functions */
int tape34xx_ioctl_overload (tape_dev_t* td, unsigned int cmd, unsigned long arg);
tape_ccw_req_t * tape34xx_write_block (const char *data, size_t count, tape_dev_t* td);
tape_ccw_req_t * tape34xx_read_block (const char *data, size_t count, tape_dev_t* td);
tape_ccw_req_t * tape34xx_ioctl(tape_dev_t* td, int op,int count, int* rc);
tape_ccw_req_t * tape34xx_bread (struct request *req, tape_dev_t* td,int tapeblock_major);
void tape34xx_free_bread (tape_ccw_req_t* treq);
void tape34xx_bread_enable_locate (tape_ccw_req_t * treq);
tape_ccw_req_t * tape34xx_bwrite (struct request *req, tape_dev_t* td,int tapeblock_major);
/* Event handlers */
void tape34xx_default_handler (tape_dev_t * td);
void tape34xx_unexpect_uchk_handler (tape_dev_t * td);
void tape34xx_irq (tape_dev_t* td);
void tape34xx_process_eov(tape_dev_t* td);
// the error recovery stuff:
void tape34xx_error_recovery (tape_dev_t* td);
void tape34xx_error_recovery_has_failed (tape_dev_t* td,int error_id);
void tape34xx_error_recovery_succeded(tape_dev_t* td);
void tape34xx_error_recovery_do_retry(tape_dev_t* td);
void tape34xx_error_recovery_read_opposite (tape_dev_t* td);
void tape34xx_error_recovery_HWBUG (tape_dev_t* td,int condno);
#endif // _TAPE34XX_H
This diff is collapsed.
/*
* drivers/s390/char/tape_block.c
* block device frontend for tape device driver
*
* S390 and zSeries version
* Copyright (C) 2001,2002 IBM Deutschland Entwicklung GmbH, IBM Corporation
* Author(s): Carsten Otte <cotte@de.ibm.com>
* Tuan Ngo-Anh <ngoanh@de.ibm.com>
* Martin Schwidefsky <schwidefsky@de.ibm.com>
*/
#include <linux/config.h>
#include <linux/version.h>
#include <linux/module.h>
#include <linux/blkdev.h>
#include <linux/blk.h>
#include <linux/interrupt.h>
#include <linux/buffer_head.h>
#include <asm/debug.h>
#include "tape.h"
#define PRINTK_HEADER "TBLOCK:"
#define TAPEBLOCK_MAX_SEC 100
#define TAPEBLOCK_MIN_REQUEUE 3
/*
* file operation structure for tape block frontend
*/
static int tapeblock_open(struct inode *, struct file *);
static int tapeblock_release(struct inode *, struct file *);
static struct block_device_operations tapeblock_fops = {
.owner = THIS_MODULE,
.open = tapeblock_open,
.release = tapeblock_release,
};
static int tapeblock_major = 0;
/*
* Post finished request.
*/
static inline void
tapeblock_end_request(struct request *req, int uptodate)
{
if (end_that_request_first(req, uptodate, req->hard_nr_sectors))
BUG();
end_that_request_last(req);
}
static void
__tapeblock_end_request(struct tape_request *ccw_req, void *data)
{
struct tape_device *device;
struct request *req;
device = ccw_req->device;
req = (struct request *) data;
tapeblock_end_request(req, ccw_req->rc == 0);
if (ccw_req->rc == 0)
/* Update position. */
device->blk_data.block_position =
(req->sector + req->nr_sectors) >> TAPEBLOCK_HSEC_S2B;
else
/* We lost the position information due to an error. */
device->blk_data.block_position = -1;
device->discipline->free_bread(ccw_req);
if (!list_empty(&device->req_queue) ||
!blk_queue_empty(&device->blk_data.request_queue))
tasklet_schedule(&device->blk_data.tasklet);
}
/*
* Fetch requests from block device queue.
*/
static inline void
__tape_process_blk_queue(struct tape_device *device, struct list_head *new_req)
{
request_queue_t *queue;
struct list_head *l;
struct request *req;
struct tape_request *ccw_req;
int nr_queued;
/* FIXME: we have to make sure that the tapeblock frontend
owns the device. tape_state != TS_IN_USE is NOT enough. */
if (device->tape_state != TS_IN_USE)
return;
queue = &device->blk_data.request_queue;
nr_queued = 0;
/* Count number of requests on ccw queue. */
list_for_each(l, &device->req_queue)
nr_queued++;
while (!blk_queue_plugged(queue) &&
!blk_queue_empty(queue) &&
nr_queued < TAPEBLOCK_MIN_REQUEUE) {
req = elv_next_request(queue);
if (rq_data_dir(req) == WRITE) {
DBF_EVENT(1, "TBLOCK: Rejecting write request\n");
blkdev_dequeue_request(req);
tapeblock_end_request(req, 0);
continue;
}
ccw_req = device->discipline->bread(device, req);
if (IS_ERR(ccw_req)) {
if (PTR_ERR(ccw_req) == -ENOMEM)
break; /* don't try again */
DBF_EVENT(1, "TBLOCK: bread failed\n");
blkdev_dequeue_request(req);
tapeblock_end_request(req, 0);
continue;
}
ccw_req->callback = __tapeblock_end_request;
ccw_req->callback_data = (void *) req;
ccw_req->retries = TAPEBLOCK_RETRIES;
blkdev_dequeue_request(req);
list_add_tail(new_req, &ccw_req->list);
nr_queued++;
}
}
/*
* Feed requests to the tape device.
*/
static inline int
tape_queue_requests(struct tape_device *device, struct list_head *new_req)
{
struct list_head *l, *n;
struct tape_request *ccw_req;
struct request *req;
int rc, fail;
fail = 0;
list_for_each_safe(l, n, new_req) {
ccw_req = list_entry(l, struct tape_request, list);
list_del(&ccw_req->list);
rc = tape_do_io_async(device, ccw_req);
if (rc) {
/*
* Start/enqueueing failed. No retries in
* this case.
*/
req = (struct request *) ccw_req->callback_data;
tapeblock_end_request(req, 0);
device->discipline->free_bread(ccw_req);
fail = 1;
}
}
return fail;
}
/*
* Tape request queue function. Called from ll_rw_blk.c
*/
static void
tapeblock_request_fn(request_queue_t *queue)
{
struct list_head new_req;
struct tape_device *device;
device = (struct tape_device *) queue->queuedata;
while (!blk_queue_empty(queue)) {
INIT_LIST_HEAD(&new_req);
spin_lock(get_ccwdev_lock(device->cdev));
__tape_process_blk_queue(device, &new_req);
spin_unlock(get_ccwdev_lock(device->cdev));
/*
* Now queue the new request to the tape. This needs to be
* done without the device lock held.
*/
if (tape_queue_requests(device, &new_req) == 0)
/* All requests queued. Thats enough for now. */
break;
}
}
/*
* Acquire the device lock and process queues for the device.
*/
static void
tapeblock_tasklet(unsigned long data)
{
struct list_head new_req;
struct tape_device *device;
device = (struct tape_device *) data;
while (!blk_queue_empty(&device->blk_data.request_queue)) {
INIT_LIST_HEAD(&new_req);
spin_lock_irq(get_ccwdev_lock(device->cdev));
__tape_process_blk_queue(device, &new_req);
spin_unlock_irq(get_ccwdev_lock(device->cdev));
/*
* Now queue the new request to the tape. This needs to be
* done without the device lock held.
*/
if (tape_queue_requests(device, &new_req) == 0)
/* All requests queued. Thats enough for now. */
break;
}
}
/*
* This function is called for every new tapedevice
*/
int
tapeblock_setup_device(struct tape_device * device)
{
request_queue_t *blk_queue;
int rc;
/* Setup request queue and initialize gendisk for this device. */
tasklet_init(&device->blk_data.tasklet, tapeblock_tasklet,
(unsigned long) device);
spin_lock_init(&device->blk_data.request_queue_lock);
blk_queue = &device->blk_data.request_queue;
rc = blk_init_queue(blk_queue, tapeblock_request_fn,
&device->blk_data.request_queue_lock);
elevator_exit(blk_queue);
rc = elevator_init(blk_queue, &elevator_noop);
if (rc) {
blk_cleanup_queue(blk_queue);
return rc;
}
/* FIXME: We should be able to sense the sectore size */
blk_queue_hardsect_size(blk_queue, TAPEBLOCK_HSEC_SIZE);
blk_queue_max_sectors(blk_queue, TAPEBLOCK_MAX_SEC);
blk_queue_max_phys_segments(blk_queue, -1L);
blk_queue_max_hw_segments(blk_queue, -1L);
blk_queue_max_segment_size(blk_queue, -1L);
blk_queue_segment_boundary(blk_queue, -1L);
return 0;
}
void
tapeblock_cleanup_device(struct tape_device *device)
{
blk_cleanup_queue(&device->blk_data.request_queue);
tasklet_kill(&device->blk_data.tasklet);
}
/*
* Detect number of blocks of the tape.
* FIXME: can we extent this to detect the blocks size as well ?
*/
static int tapeblock_mediumdetect(struct tape_device *device)
{
unsigned int nr_of_blks;
int rc;
PRINT_INFO("Detecting media size...\n");
rc = tape_mtop(device, MTREW, 1);
if (rc)
return rc;
rc = tape_mtop(device, MTFSF, 1);
if (rc)
return rc;
rc = tape_mtop(device, MTTELL, 1);
if (rc)
return rc;
nr_of_blks = rc - 1; /* don't count FM */
rc = tape_mtop(device, MTREW, 1);
if (rc)
return rc;
PRINT_INFO("Found %i blocks on media\n", nr_of_blks);
return 0;
}
/*
* Block frontend tape device open function.
*/
int
tapeblock_open(struct inode *inode, struct file *filp) {
struct tape_device *device;
int minor, rc;
MOD_INC_USE_COUNT;
if (major(filp->f_dentry->d_inode->i_rdev) != tapeblock_major)
return -ENODEV;
minor = minor(filp->f_dentry->d_inode->i_rdev);
device = tape_get_device(minor >> TAPE_MINORS_PER_DEV);
if (IS_ERR(device)) {
MOD_DEC_USE_COUNT;
return PTR_ERR(device);
}
DBF_EVENT(6, "TBLOCK:open: %x\n", device->first_minor);
rc = tape_open(device);
if (rc == 0) {
rc = tape_assign(device);
if (rc == 0) {
device->blk_data.block_position = -1;
rc = tapeblock_mediumdetect(device);
if (rc == 0) {
filp->private_data = device;
return 0;
}
tape_unassign(device);
}
tape_release(device);
}
tape_put_device(device);
MOD_DEC_USE_COUNT;
return rc;
}
/*
* Block frontend tape device release function.
*/
int
tapeblock_release(struct inode *inode, struct file *filp) {
struct tape_device *device;
/* Remove all buffers at device close. */
/* FIXME: can we do that a tape unload ? */
invalidate_buffers(inode->i_rdev);
device = (struct tape_device *) filp->private_data;
tape_release(device);
tape_unassign(device);
tape_put_device(device);
MOD_DEC_USE_COUNT;
return 0;
}
/*
* Initialize block device frontend.
*/
int
tapeblock_init(void)
{
int rc;
/* Register the tape major number to the kernel */
rc = register_blkdev(tapeblock_major, "tBLK", &tapeblock_fops);
if (rc < 0) {
PRINT_ERR("can't get major %d for block device\n",
tapeblock_major);
return rc;
}
if (tapeblock_major == 0)
tapeblock_major = rc;
PRINT_INFO("tape gets major %d for block device\n", tapeblock_major);
return 0;
}
/*
* Deregister major for block device frontend
*/
void
tapeblock_exit(void)
{
unregister_blkdev(tapeblock_major, "tBLK");
}
This diff is collapsed.
This diff is collapsed.
/***************************************************************************
*
* drivers/s390/char/tape_idalbuf.h
* functions for idal buffer handling
*
* S390 and zSeries version
* Copyright (C) 2001 IBM Corporation
* Author(s): Michael Holzheu <holzheu@de.ibm.com>
*
****************************************************************************
*/
#include <linux/kernel.h>
#include <asm/hardirq.h> // in_interrupt
/*
* Macros
*/
#ifdef CONFIG_ARCH_S390X
// on ESAME each idal entry points to a 4K buffer
#define IDALBUF_BLK_SIZE 4096
#else
// on ESA each idal entry points to a 2K buffer
#define IDALBUF_BLK_SIZE 2048
#endif
#define IDALBUF_MAX_ENTRIES 33 // an ida list can have up to 33 entries
#define IDALBUF_PAGE_ORDER 1 // each chunk has 2exp(1) pages
#define __IDALBUF_CHUNK_SIZE ((1<<IDALBUF_PAGE_ORDER) * PAGE_SIZE)
#define __IDALBUF_ENTRIES_PER_CHUNK (__IDALBUF_CHUNK_SIZE/IDALBUF_BLK_SIZE)
// Macro which finds out, if we need idal addressing
#ifdef CONFIG_ARCH_S390X
#define __IDALBUF_DIRECT_ADDR(idal) \
( (idal->size <= __IDALBUF_CHUNK_SIZE) \
&& ( ( ((unsigned long)idal->data[0]) >> 31) == 0) )
#else
#define __IDALBUF_DIRECT_ADDR(idal) \
(idal->size <= __IDALBUF_CHUNK_SIZE)
#endif
#ifndef MIN
#define MIN(a,b) (((a)<(b))?(a):(b))
#endif
/*
* The idalbuf data structure
*/
typedef struct _idalbuf_t{
void* data[IDALBUF_MAX_ENTRIES];
int size;
} idalbuf_t;
static inline unsigned int
__round_up_multiple (unsigned int no, unsigned int mult)
{
int rem = no % mult;
return (rem ? no - rem + mult : no);
}
/*
* Setup a ccw in a way that the data buf is an idalbuf_mem_t
*/
static inline void
idalbuf_set_normalized_cda(ccw1_t *ccw, idalbuf_t* idal)
{
if(__IDALBUF_DIRECT_ADDR(idal)){
// we do not need idals - use direct addressing
ccw->cda = (unsigned long) idal->data[0];
} else {
// setup idals
ccw->flags |= CCW_FLAG_IDA;
ccw->cda = (unsigned long) idal->data;
}
ccw->count = idal->size;
}
/*
* Alloc size bytes of memory
*/
static inline idalbuf_t*
idalbuf_alloc(size_t size)
{
int i = 0;
int count = __round_up_multiple(size,IDALBUF_BLK_SIZE) / IDALBUF_BLK_SIZE;
idalbuf_t* rc;
char* addr = NULL;
int kmalloc_flags;
if(in_interrupt())
kmalloc_flags = GFP_ATOMIC;
else
kmalloc_flags = GFP_KERNEL;
if(size/IDALBUF_BLK_SIZE > IDALBUF_MAX_ENTRIES)
BUG();
// the ida list must be below 2GB --> GFP_DMA
rc = kmalloc(sizeof(idalbuf_t),kmalloc_flags | GFP_DMA);
if(!rc)
goto error;
for(i=0; i< count;i++){
if((i % __IDALBUF_ENTRIES_PER_CHUNK) == 0){
// data does not need to be below 2GB
rc->data[i] = (void*)__get_free_pages(kmalloc_flags ,IDALBUF_PAGE_ORDER);
if(!rc->data[i])
goto error;
addr = (char*)(rc->data[i]);
} else {
addr+=IDALBUF_BLK_SIZE;
rc->data[i] = addr;
}
}
rc->size=size;
return rc;
error:
if(rc){
int end = i;
for(i=end-1;i>=0;i-=__IDALBUF_ENTRIES_PER_CHUNK)
free_pages((unsigned long)rc->data[i],IDALBUF_PAGE_ORDER);
kfree(rc);
}
return NULL;
}
/*
* Free an idal buffer
*/
static inline void
idalbuf_free(idalbuf_t* idal)
{
int count = __round_up_multiple(idal->size,__IDALBUF_CHUNK_SIZE)/__IDALBUF_CHUNK_SIZE;
int i;
for(i = 0; i < count; i++){
free_pages((unsigned long)idal->data[i*__IDALBUF_ENTRIES_PER_CHUNK],IDALBUF_PAGE_ORDER);
}
kfree(idal);
}
/*
* Copy count bytes from an idal buffer to contiguous user memory
*/
static inline int
idalbuf_copy_to_user(void* to, const idalbuf_t* from, size_t count)
{
int i;
int rc = 0;
if(count > from->size)
BUG();
for(i = 0; i < count; i+=__IDALBUF_CHUNK_SIZE){
rc = copy_to_user(((char*)to) + i,from->data[i/IDALBUF_BLK_SIZE],MIN(__IDALBUF_CHUNK_SIZE,(count-i)));
if(rc)
goto out;
}
out:
return rc;
}
/*
* Copy count bytes from contiguous user memory to an idal buffer
*/
static inline int
idalbuf_copy_from_user(idalbuf_t* to, const void* from, size_t count)
{
int i;
int rc = 0;
if(count > to->size)
BUG();
for(i = 0; i < count; i+=__IDALBUF_CHUNK_SIZE){
rc = copy_from_user(to->data[i/IDALBUF_BLK_SIZE],((char*)from)+i,MIN(__IDALBUF_CHUNK_SIZE,(count-i)));
if(rc)
goto out;
}
out:
return rc;
}
/*
* Copy count bytes from an idal buffer to a contiguous kernel buffer
*/
static inline void
idalbuf_copy_from_idal(void* to, const idalbuf_t* from, size_t count)
{
int i;
if(count > from->size)
BUG();
for(i = 0; i < count; i+=__IDALBUF_CHUNK_SIZE){
memcpy((char*)to + i,(from->data[i/IDALBUF_BLK_SIZE]),MIN(__IDALBUF_CHUNK_SIZE,(count-i)) );
}
}
/*
* Copy count bytes from a contiguous kernel buffer to an idal buffer
*/
static inline void
idalbuf_copy_to_idal(idalbuf_t* to, const void* from, size_t count)
{
int i;
if(count > to->size)
BUG();
for(i = 0; i < count; i+=__IDALBUF_CHUNK_SIZE){
memcpy(to->data[i/IDALBUF_BLK_SIZE],(char*)from+i,MIN(__IDALBUF_CHUNK_SIZE,(count-i)) );
}
}
/*
* drivers/s390/char/tape.c
* tape device driver for S/390 and zSeries tapes.
*
* S390 and zSeries version
* Copyright (C) 2001 IBM Corporation
* Author(s): Carsten Otte <cotte@de.ibm.com>
* Michael Holzheu <holzheu@de.ibm.com>
* Tuan Ngo-Anh <ngoanh@de.ibm.com>
*
* PROCFS Functions
*/
#include <linux/config.h>
#include <linux/version.h>
#include <linux/module.h>
#include <linux/vmalloc.h>
#include <linux/seq_file.h>
#include "tape.h"
#define PRINTK_HEADER "T390:"
static const char *tape_med_st_verbose[MS_SIZE] =
{
[MS_UNKNOWN] = "UNKNOWN ",
[MS_LOADED] = "LOADED ",
[MS_UNLOADED] = "UNLOADED"
};
/* our proc tapedevices entry */
static struct proc_dir_entry *tape_proc_devices;
/*
* Show function for /proc/tapedevices
*/
static int tape_proc_show(struct seq_file *m, void *v)
{
struct tape_device *device;
struct tape_request *request;
const char *str;
unsigned long n;
n = (unsigned long) v - 1;
if (!n) {
seq_printf(m, "TapeNo\tDevNo\tCuType\tCuModel\tDevType\t"
"DevMod\tBlkSize\tState\tOp\tMedState\n");
}
device = tape_get_device(n);
if (IS_ERR(device))
return 0;
spin_lock_irq(get_ccwdev_lock(device->cdev));
seq_printf(m, "%d\t", (int) n);
seq_printf(m, "%s\t", device->cdev->dev.bus_id);
seq_printf(m, "%04X\t", device->cdev->id.cu_type);
seq_printf(m, "%02X\t", device->cdev->id.cu_model);
seq_printf(m, "%04X\t", device->cdev->id.dev_type);
seq_printf(m, "%02X\t", device->cdev->id.dev_model);
if (device->char_data.block_size == 0)
seq_printf(m, "auto\t");
else
seq_printf(m, "%i\t", device->char_data.block_size);
if (device->tape_state >= 0 &&
device->tape_state < TS_SIZE)
str = tape_state_verbose[device->tape_state];
else
str = "UNKNOWN";
seq_printf(m, "%s\t", str);
if (!list_empty(&device->req_queue)) {
request = list_entry(device->req_queue.next,
struct tape_request, list);
str = tape_op_verbose[request->op];
} else
str = "---";
seq_printf(m, "%s\t", str);
seq_printf(m, "%s\n", tape_med_st_verbose[device->medium_state]);
spin_unlock_irq(get_ccwdev_lock(device->cdev));
tape_put_device(device);
return 0;
}
static void *tape_proc_start(struct seq_file *m, loff_t *pos)
{
if (*pos >= (1 << KDEV_MINOR_BITS) / TAPE_MINORS_PER_DEV)
return NULL;
return (void *)((unsigned long) *pos + 1);
}
static void *tape_proc_next(struct seq_file *m, void *v, loff_t *pos)
{
++*pos;
return tape_proc_start(m, pos);
}
static void tape_proc_stop(struct seq_file *m, void *v)
{
}
static struct seq_operations tape_proc_seq = {
.start = tape_proc_start,
.next = tape_proc_next,
.stop = tape_proc_stop,
.show = tape_proc_show,
};
static int tape_proc_open(struct inode *inode, struct file *file)
{
return seq_open(file, &tape_proc_seq);
}
static struct file_operations tape_proc_ops =
{
.open = tape_proc_open,
.read = seq_read,
.llseek = seq_lseek,
.release = seq_release,
};
/*
* Initialize procfs stuff on startup
*/
void
tape_proc_init(void)
{
tape_proc_devices =
create_proc_entry ("tapedevices", S_IFREG | S_IRUGO | S_IWUSR,
&proc_root);
if (tape_proc_devices == NULL) {
PRINT_WARN("tape: Cannot register procfs entry tapedevices\n");
return;
}
tape_proc_devices->proc_fops = &tape_proc_ops;
tape_proc_devices->owner = THIS_MODULE;
}
/*
* Cleanup all stuff registered to the procfs
*/
void
tape_proc_cleanup(void)
{
if (tape_proc_devices != NULL)
remove_proc_entry ("tapedevices", &proc_root);
}
This diff is collapsed.
/*
* drivers/s390/char/tape_34xx.h
* standard tape device functions for ibm tapes.
*
* S390 and zSeries version
* Copyright (C) 2001,2002 IBM Deutschland Entwicklung GmbH, IBM Corporation
* Author(s): Carsten Otte <cotte@de.ibm.com>
* Tuan Ngo-Anh <ngoanh@de.ibm.com>
* Martin Schwidefsky <schwidefsky@de.ibm.com>
*/
#ifndef _TAPE_STD_H
#define _TAPE_STD_H
/*
* The CCW commands for the Tape type of command.
*/
#define INVALID_00 0x00 /* Invalid cmd */
#define BACKSPACEBLOCK 0x27 /* Back Space block */
#define BACKSPACEFILE 0x2f /* Back Space file */
#define DATA_SEC_ERASE 0x97 /* Data security erase */
#define ERASE_GAP 0x17 /* Erase Gap */
#define FORSPACEBLOCK 0x37 /* Forward space block */
#define FORSPACEFILE 0x3F /* Forward Space file */
#define FORCE_STREAM_CNT 0xEB /* Forced streaming count # */
#define NOP 0x03 /* No operation */
#define READ_FORWARD 0x02 /* Read forward */
#define REWIND 0x07 /* Rewind */
#define REWIND_UNLOAD 0x0F /* Rewind and Unload */
#define SENSE 0x04 /* Sense */
#define NEW_MODE_SET 0xEB /* Guess it is Mode set */
#define WRITE_CMD 0x01 /* Write */
#define WRITETAPEMARK 0x1F /* Write Tape Mark */
#define ASSIGN 0xB7 /* 3420 REJECT,3480 OK */
#define CONTROL_ACCESS 0xE3 /* Set high speed */
#define DIAG_MODE_SET 0x0B /* 3420 NOP, 3480 REJECT */
#define LOAD_DISPLAY 0x9F /* 3420 REJECT,3480 OK */
#define LOCATE 0x4F /* 3420 REJ, 3480 NOP */
#define LOOP_WRITE_TO_READ 0x8B /* 3480 REJECT */
#define MODE_SET_DB 0xDB /* 3420 REJECT,3480 OK */
#define MODE_SET_C3 0xC3 /* for 3420 */
#define MODE_SET_CB 0xCB /* for 3420 */
#define MODE_SET_D3 0xD3 /* for 3420 */
#define READ_BACKWARD 0x0C /* */
#define READ_BLOCK_ID 0x22 /* 3420 REJECT,3480 OK */
#define READ_BUFFER 0x12 /* 3420 REJECT,3480 OK */
#define READ_BUFF_LOG 0x24 /* 3420 REJECT,3480 OK */
#define RELEASE 0xD4 /* 3420 NOP, 3480 REJECT */
#define REQ_TRK_IN_ERROR 0x1B /* 3420 NOP, 3480 REJECT */
#define RESERVE 0xF4 /* 3420 NOP, 3480 REJECT */
#define SENSE_GROUP_ID 0x34 /* 3420 REJECT,3480 OK */
#define SENSE_ID 0xE4 /* 3420 REJECT,3480 OK */
#define READ_DEV_CHAR 0x64 /* Read device characteristics */
#define SET_DIAGNOSE 0x4B /* 3420 NOP, 3480 REJECT */
#define SET_GROUP_ID 0xAF /* 3420 REJECT,3480 OK */
#define SET_TAPE_WRITE_IMMED 0xC3 /* for 3480 */
#define SUSPEND 0x5B /* 3420 REJ, 3480 NOP */
#define SYNC 0x43 /* Synchronize (flush buffer) */
#define UNASSIGN 0xC7 /* 3420 REJECT,3480 OK */
#define PERF_SUBSYS_FUNC 0x77 /* 3490 CMD */
#define READ_CONFIG_DATA 0xFA /* 3490 CMD */
#define READ_MESSAGE_ID 0x4E /* 3490 CMD */
#define READ_SUBSYS_DATA 0x3E /* 3490 CMD */
#define SET_INTERFACE_ID 0x73 /* 3490 CMD */
#define SENSE_COMMAND_REJECT 0x80
#define SENSE_INTERVENTION_REQUIRED 0x40
#define SENSE_BUS_OUT_CHECK 0x20
#define SENSE_EQUIPMENT_CHECK 0x10
#define SENSE_DATA_CHECK 0x08
#define SENSE_OVERRUN 0x04
#define SENSE_DEFERRED_UNIT_CHECK 0x02
#define SENSE_ASSIGNED_ELSEWHERE 0x01
#define SENSE_LOCATE_FAILURE 0x80
#define SENSE_DRIVE_ONLINE 0x40
#define SENSE_RESERVED 0x20
#define SENSE_RECORD_SEQUENCE_ERR 0x10
#define SENSE_BEGINNING_OF_TAPE 0x08
#define SENSE_WRITE_MODE 0x04
#define SENSE_WRITE_PROTECT 0x02
#define SENSE_NOT_CAPABLE 0x01
#define SENSE_CHANNEL_ADAPTER_CODE 0xE0
#define SENSE_CHANNEL_ADAPTER_LOC 0x10
#define SENSE_REPORTING_CU 0x08
#define SENSE_AUTOMATIC_LOADER 0x04
#define SENSE_TAPE_SYNC_MODE 0x02
#define SENSE_TAPE_POSITIONING 0x01
/* discipline functions */
struct tape_request *tape_std_read_block(struct tape_device *, size_t);
void tape_std_read_backward(struct tape_device *device,
struct tape_request *request);
struct tape_request *tape_std_write_block(struct tape_device *, size_t);
struct tape_request *tape_std_bread(struct tape_device *, struct request *);
void tape_std_free_bread(struct tape_request *);
void tape_std_check_locate(struct tape_device *, struct tape_request *);
struct tape_request *tape_std_bwrite(struct request *,
struct tape_device *, int);
/* Some non-mtop commands. */
int tape_std_assign(struct tape_device *);
int tape_std_unassign(struct tape_device *);
int tape_std_read_block_id(struct tape_device *device, __u64 *id);
int tape_std_display(struct tape_device *, int, unsigned long);
/* Standard magnetic tape commands. */
int tape_std_mtbsf(struct tape_device *, int);
int tape_std_mtbsfm(struct tape_device *, int);
int tape_std_mtbsr(struct tape_device *, int);
int tape_std_mtcompression(struct tape_device *, int);
int tape_std_mteom(struct tape_device *, int);
int tape_std_mterase(struct tape_device *, int);
int tape_std_mtfsf(struct tape_device *, int);
int tape_std_mtfsfm(struct tape_device *, int);
int tape_std_mtfsr(struct tape_device *, int);
int tape_std_mtload(struct tape_device *, int);
int tape_std_mtnop(struct tape_device *, int);
int tape_std_mtoffl(struct tape_device *, int);
int tape_std_mtreset(struct tape_device *, int);
int tape_std_mtreten(struct tape_device *, int);
int tape_std_mtrew(struct tape_device *, int);
int tape_std_mtsetblk(struct tape_device *, int);
int tape_std_mtunload(struct tape_device *, int);
int tape_std_mtweof(struct tape_device *, int);
/* Event handlers */
void tape_std_default_handler(struct tape_device *);
void tape_std_unexpect_uchk_handler(struct tape_device *);
void tape_std_irq(struct tape_device *);
void tape_std_process_eov(struct tape_device *);
// the error recovery stuff:
void tape_std_error_recovery(struct tape_device *);
void tape_std_error_recovery_has_failed(struct tape_device *,int error_id);
void tape_std_error_recovery_succeded(struct tape_device *);
void tape_std_error_recovery_do_retry(struct tape_device *);
void tape_std_error_recovery_read_opposite(struct tape_device *);
void tape_std_error_recovery_HWBUG(struct tape_device *, int condno);
#endif // _TAPE_STD_H
This diff is collapsed.
/***************************************************************************
*
* drivers/s390/char/tapeblock.h
* character device frontend for tape device driver
*
* S390 and zSeries version
* Copyright (C) 2001 IBM Corporation
* Author(s): Carsten Otte <cotte@de.ibm.com>
* Tuan Ngo-Anh <ngoanh@de.ibm.com>
*
*
****************************************************************************
*/
#ifndef TAPEBLOCK_H
#define TAPEBLOCK_H
#include <linux/config.h>
#define TAPEBLOCK_READAHEAD 30
#define TAPEBLOCK_MAJOR 0
#define TAPEBLOCK_DEVFSMODE 0060644 // blkdev, rwx for user, rw for group&others
int tapeblock_open(struct inode *, struct file *);
int tapeblock_release(struct inode *, struct file *);
void tapeblock_setup(tape_dev_t* td);
void tapeblock_schedule_exec_io (tape_dev_t *td);
int tapeblock_mediumdetect(tape_dev_t* td);
#ifdef CONFIG_DEVFS_FS
devfs_handle_t tapeblock_mkdevfstree (tape_dev_t* td);
void tapeblock_rmdevfstree (tape_dev_t* td);
#endif
int tapeblock_init (void);
void tapeblock_uninit (void);
#endif
This diff is collapsed.
/***************************************************************************
*
* drivers/s390/char/tapechar.h
* character device frontend for tape device driver
*
* S390 and zSeries version
* Copyright (C) 2001 IBM Corporation
* Author(s): Carsten Otte <cotte@de.ibm.com>
* Tuan Ngo-Anh <ngoanh@de.ibm.com>
*
*
****************************************************************************
*/
#ifndef TAPECHAR_H
#define TAPECHAR_H
#include <linux/config.h>
#define TAPECHAR_DEVFSMODE 0020644 // chardev, rwx for user, rw for group&others
#define TAPECHAR_MAJOR 0 /* get dynamic major since no major officialy defined for tape */
#define TAPECHAR_NOREW_MINOR(x) x /* Minor for nonrewinding device */
#define TAPECHAR_REW_MINOR(x) (x+1) /* Minor for rewinding device */
/*
* Prototypes
*/
ssize_t tapechar_read(struct file *, char *, size_t, loff_t *);
ssize_t tapechar_write(struct file *, const char *, size_t, loff_t *);
int tapechar_ioctl(struct inode *,struct file *,unsigned int,unsigned long);
int tapechar_open (struct inode *,struct file *);
int tapechar_release (struct inode *,struct file *);
#ifdef CONFIG_DEVFS_FS
devfs_handle_t tapechar_mkdevfstree (tape_dev_t* td);
void tapechar_rmdevfstree (tape_dev_t* td);
#endif
void tapechar_init (void);
void tapechar_uninit (void);
#endif /* TAPECHAR_H */
/***********************************************************************
* drivers/s390/char/tapedefs.h
* tape device driver for S/390 and zSeries tapes.
*
* S390 and zSeries version
* Copyright (C) 2001 IBM Corporation
* Author(s): Carsten Otte <cotte@de.ibm.com>
* Tuan Ngo-Anh <ngoanh@de.ibm.com>
*
*
***********************************************************************
*/
/* Kernel Version Compatibility section */
#include <linux/version.h>
#include <linux/blkdev.h>
#include <linux/blk.h>
#include <asm/irq.h>
#include <linux/compatmac.h>
#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,2,17))
#define TAPE_DEBUG // use s390 debug feature
#else
#undef TAPE_DEBUG // debug feature not supported by our 2.2.16 code
static inline void set_normalized_cda ( ccw1_t * cp, unsigned long address ) {
cp -> cda = address;
}
static inline void clear_normalized_cda ( ccw1_t * ccw ) {
ccw -> cda = 0;
}
#define BUG() PRINT_FATAL("tape390: CRITICAL INTERNAL ERROR OCCURED. REPORT THIS BACK TO LINUX390@DE.IBM.COM\n")
#endif
#define CONFIG_S390_TAPE_DYNAMIC // allow devices to be attached or detached on the fly
#define TAPEBLOCK_RETRIES 20 // number of retries, when a block-dev request fails.
#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,3,98))
#define INIT_BLK_DEV(d_major,d_request_fn,d_queue_fn,d_current) \
do { \
blk_dev[d_major].queue = d_queue_fn; \
} while(0)
static inline struct request *
tape_next_request( request_queue_t *queue )
{
return elv_next_request(queue);
}
static inline void
tape_dequeue_request( request_queue_t * q, struct request *req )
{
blkdev_dequeue_request (req);
}
#else
#define s390_dev_info_t dev_info_t
typedef struct request *request_queue_t;
#ifndef init_waitqueue_head
#define init_waitqueue_head(x) do { *x = NULL; } while(0)
#endif
#define blk_init_queue(x,y) do {} while(0)
#define blk_queue_headactive(x,y) do {} while(0)
#define INIT_BLK_DEV(d_major,d_request_fn,d_queue_fn,d_current) \
do { \
blk_dev[d_major].request_fn = d_request_fn; \
blk_dev[d_major].queue = d_queue_fn; \
blk_dev[d_major].current_request = d_current; \
} while(0)
static inline struct request *
tape_next_request( request_queue_t *queue )
{
return *queue;
}
static inline void
tape_dequeue_request( request_queue_t * q, struct request *req )
{
*q = req->next;
req->next = NULL;
}
#endif
......@@ -122,4 +122,138 @@ clear_normalized_cda(struct ccw1 * ccw)
ccw->cda = 0;
}
/*
* Idal buffer extension
*/
struct idal_buffer {
size_t size;
size_t page_order;
void *data[0];
};
/*
* Allocate an idal buffer
*/
static inline struct idal_buffer *
idal_buffer_alloc(size_t size, int page_order)
{
struct idal_buffer *ib;
int nr_chunks, nr_ptrs, i;
nr_ptrs = (size + IDA_BLOCK_SIZE - 1) >> IDA_SIZE_LOG;
nr_chunks = (4096 << page_order) >> IDA_SIZE_LOG;
ib = kmalloc(sizeof(struct idal_buffer) + nr_ptrs*sizeof(void *),
GFP_DMA | GFP_KERNEL);
if (ib == NULL)
return ERR_PTR(-ENOMEM);
ib->size = size;
ib->page_order = page_order;
for (i = 0; i < nr_ptrs; i++) {
if ((i & (nr_chunks - 1)) != 0) {
ib->data[i] = ib->data[i-1] + IDA_BLOCK_SIZE;
continue;
}
ib->data[i] = (void *)
__get_free_pages(GFP_KERNEL, page_order);
if (ib->data[i] != NULL)
continue;
// Not enough memory
while (i >= nr_chunks) {
i -= nr_chunks;
free_pages((unsigned long) ib->data[i],
ib->page_order);
}
kfree(ib);
return ERR_PTR(-ENOMEM);
}
return ib;
}
/*
* Free an idal buffer.
*/
static inline void
idal_buffer_free(struct idal_buffer *ib)
{
int nr_chunks, nr_ptrs, i;
nr_ptrs = (ib->size + IDA_BLOCK_SIZE - 1) >> IDA_SIZE_LOG;
nr_chunks = (4096 << ib->page_order) >> IDA_SIZE_LOG;
for (i = 0; i < nr_ptrs; i += nr_chunks)
free_pages((unsigned long) ib->data[i], ib->page_order);
kfree(ib);
}
/*
* Test if a idal list is really needed.
*/
static inline int
__idal_buffer_is_needed(struct idal_buffer *ib)
{
#ifdef CONFIG_ARCH_S390X
return ib->size > (4096 << ib->page_order) ||
idal_is_needed(ib->data[0], ib->size);
#else
return ib->size > (4096 << ib->page_order);
#endif
}
/*
* Set channel data address to idal buffer.
*/
static inline void
idal_buffer_set_cda(struct idal_buffer *ib, struct ccw1 *ccw)
{
if (__idal_buffer_is_needed(ib)) {
// setup idals;
ccw->cda = (u32)(addr_t) ib->data;
ccw->flags |= CCW_FLAG_IDA;
} else
// we do not need idals - use direct addressing
ccw->cda = (u32)(addr_t) ib->data[0];
ccw->count = ib->size;
}
/*
* Copy count bytes from an idal buffer to user memory
*/
static inline size_t
idal_buffer_to_user(struct idal_buffer *ib, void *to, size_t count)
{
size_t left;
int i;
if (count > ib->size)
BUG();
for (i = 0; count > IDA_BLOCK_SIZE; i++) {
left = copy_to_user(to, ib->data[i], IDA_BLOCK_SIZE);
if (left)
return left + count - IDA_BLOCK_SIZE;
(addr_t) to += IDA_BLOCK_SIZE;
count -= IDA_BLOCK_SIZE;
}
return copy_to_user(to, ib->data[i], count);
}
/*
* Copy count bytes from user memory to an idal buffer
*/
static inline size_t
idal_buffer_from_user(struct idal_buffer *ib, const void *from, size_t count)
{
size_t left;
int i;
if (count > ib->size)
BUG();
for (i = 0; count > IDA_BLOCK_SIZE; i++) {
left = copy_from_user(ib->data[i], from, IDA_BLOCK_SIZE);
if (left)
return left + count - IDA_BLOCK_SIZE;
(addr_t) from += IDA_BLOCK_SIZE;
count -= IDA_BLOCK_SIZE;
}
return copy_from_user(ib->data[i], from, count);
}
#endif
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment