Merge branch 'for-linus' of git://git390.marist.edu/pub/scm/linux-2.6
[safe/jmp/linux-2.6] / drivers / scsi / st.c
index f934016..24211d0 100644 (file)
@@ -17,7 +17,7 @@
    Last modified: 18-JAN-1998 Richard Gooch <rgooch@atnf.csiro.au> Devfs support
  */
 
-static const char *verstr = "20080504";
+static const char *verstr = "20081215";
 
 #include <linux/module.h>
 
@@ -27,6 +27,7 @@ static const char *verstr = "20080504";
 #include <linux/mm.h>
 #include <linux/init.h>
 #include <linux/string.h>
+#include <linux/slab.h>
 #include <linux/errno.h>
 #include <linux/mtio.h>
 #include <linux/cdrom.h>
@@ -182,7 +183,6 @@ static struct scsi_tape **scsi_tapes = NULL;
 
 static int modes_defined;
 
-static struct st_buffer *new_tape_buffer(int, int, int);
 static int enlarge_buffer(struct st_buffer *, int, int);
 static void clear_buffer(struct st_buffer *);
 static void normalize_buffer(struct st_buffer *);
@@ -375,9 +375,9 @@ static int st_chk_result(struct scsi_tape *STp, struct st_request * SRpnt)
        if (!debugging) { /* Abnormal conditions for tape */
                if (!cmdstatp->have_sense)
                        printk(KERN_WARNING
-                              "%s: Error %x (sugg. bt 0x%x, driver bt 0x%x, host bt 0x%x).\n",
-                              name, result, suggestion(result),
-                              driver_byte(result) & DRIVER_MASK, host_byte(result));
+                              "%s: Error %x (driver bt 0x%x, host bt 0x%x).\n",
+                              name, result, driver_byte(result),
+                              host_byte(result));
                else if (cmdstatp->have_sense &&
                         scode != NO_SENSE &&
                         scode != RECOVERED_ERROR &&
@@ -464,7 +464,7 @@ static void st_scsi_execute_end(struct request *req, int uptodate)
        struct scsi_tape *STp = SRpnt->stp;
 
        STp->buffer->cmdstat.midlevel_result = SRpnt->result = req->errors;
-       STp->buffer->cmdstat.residual = req->data_len;
+       STp->buffer->cmdstat.residual = req->resid_len;
 
        if (SRpnt->waiting)
                complete(SRpnt->waiting);
@@ -492,10 +492,13 @@ static int st_scsi_execute(struct st_request *SRpnt, const unsigned char *cmd,
 
        mdata->null_mapped = 1;
 
-       err = blk_rq_map_user(req->q, req, mdata, NULL, bufflen, GFP_KERNEL);
-       if (err) {
-               blk_put_request(req);
-               return DRIVER_ERROR << 24;
+       if (bufflen) {
+               err = blk_rq_map_user(req->q, req, mdata, NULL, bufflen,
+                                     GFP_KERNEL);
+               if (err) {
+                       blk_put_request(req);
+                       return DRIVER_ERROR << 24;
+               }
        }
 
        SRpnt->bio = req->bio;
@@ -550,13 +553,15 @@ st_do_scsi(struct st_request * SRpnt, struct scsi_tape * STp, unsigned char *cmd
        SRpnt->waiting = waiting;
 
        if (STp->buffer->do_dio) {
+               mdata->page_order = 0;
                mdata->nr_entries = STp->buffer->sg_segs;
                mdata->pages = STp->buffer->mapped_pages;
        } else {
+               mdata->page_order = STp->buffer->reserved_page_order;
                mdata->nr_entries =
                        DIV_ROUND_UP(bytes, PAGE_SIZE << mdata->page_order);
-               STp->buffer->map_data.pages = STp->buffer->reserved_pages;
-               STp->buffer->map_data.offset = 0;
+               mdata->pages = STp->buffer->reserved_pages;
+               mdata->offset = 0;
        }
 
        memcpy(SRpnt->cmd, cmd, sizeof(SRpnt->cmd));
@@ -578,28 +583,6 @@ st_do_scsi(struct st_request * SRpnt, struct scsi_tape * STp, unsigned char *cmd
        return SRpnt;
 }
 
-static int st_scsi_kern_execute(struct st_request *streq,
-                               const unsigned char *cmd, int data_direction,
-                               void *buffer, unsigned bufflen, int timeout,
-                               int retries)
-{
-       struct scsi_tape *stp = streq->stp;
-       int ret, resid;
-
-       stp->buffer->cmdstat.have_sense = 0;
-       memcpy(streq->cmd, cmd, sizeof(streq->cmd));
-
-       ret = scsi_execute(stp->device, cmd, data_direction, buffer, bufflen,
-                          streq->sense, timeout, retries, 0, &resid);
-       if (driver_byte(ret) & DRIVER_ERROR)
-               return -EBUSY;
-
-       stp->buffer->cmdstat.midlevel_result = streq->result = ret;
-       stp->buffer->cmdstat.residual = resid;
-       stp->buffer->syscall_result = st_chk_result(stp, streq);
-
-       return 0;
-}
 
 /* Handle the write-behind checking (waits for completion). Returns -ENOSPC if
    write has been correct but EOM early warning reached, -EIO if write ended in
@@ -672,7 +655,6 @@ static int cross_eof(struct scsi_tape * STp, int forward)
 {
        struct st_request *SRpnt;
        unsigned char cmd[MAX_COMMAND_SIZE];
-       int ret;
 
        cmd[0] = SPACE;
        cmd[1] = 0x01;          /* Space FileMarks */
@@ -686,26 +668,20 @@ static int cross_eof(struct scsi_tape * STp, int forward)
         DEBC(printk(ST_DEB_MSG "%s: Stepping over filemark %s.\n",
                   tape_name(STp), forward ? "forward" : "backward"));
 
-       SRpnt = st_allocate_request(STp);
+       SRpnt = st_do_scsi(NULL, STp, cmd, 0, DMA_NONE,
+                          STp->device->request_queue->rq_timeout,
+                          MAX_RETRIES, 1);
        if (!SRpnt)
-               return STp->buffer->syscall_result;
-
-       ret = st_scsi_kern_execute(SRpnt, cmd, DMA_NONE, NULL, 0,
-                                  STp->device->request_queue->rq_timeout,
-                                  MAX_RETRIES);
-       if (ret)
-               goto out;
+               return (STp->buffer)->syscall_result;
 
-       ret = STp->buffer->syscall_result;
+       st_release_request(SRpnt);
+       SRpnt = NULL;
 
        if ((STp->buffer)->cmdstat.midlevel_result != 0)
                printk(KERN_ERR "%s: Stepping over filemark %s failed.\n",
                   tape_name(STp), forward ? "forward" : "backward");
 
-out:
-       st_release_request(SRpnt);
-
-       return ret;
+       return (STp->buffer)->syscall_result;
 }
 
 
@@ -926,24 +902,21 @@ static int test_ready(struct scsi_tape *STp, int do_wait)
        int attentions, waits, max_wait, scode;
        int retval = CHKRES_READY, new_session = 0;
        unsigned char cmd[MAX_COMMAND_SIZE];
-       struct st_request *SRpnt;
+       struct st_request *SRpnt = NULL;
        struct st_cmdstatus *cmdstatp = &STp->buffer->cmdstat;
 
-       SRpnt = st_allocate_request(STp);
-       if (!SRpnt)
-               return STp->buffer->syscall_result;
-
        max_wait = do_wait ? ST_BLOCK_SECONDS : 0;
 
        for (attentions=waits=0; ; ) {
                memset((void *) &cmd[0], 0, MAX_COMMAND_SIZE);
                cmd[0] = TEST_UNIT_READY;
+               SRpnt = st_do_scsi(SRpnt, STp, cmd, 0, DMA_NONE,
+                                  STp->long_timeout, MAX_READY_RETRIES, 1);
 
-               retval = st_scsi_kern_execute(SRpnt, cmd, DMA_NONE, NULL, 0,
-                                             STp->long_timeout,
-                                             MAX_READY_RETRIES);
-               if (retval)
+               if (!SRpnt) {
+                       retval = (STp->buffer)->syscall_result;
                        break;
+               }
 
                if (cmdstatp->have_sense) {
 
@@ -987,8 +960,8 @@ static int test_ready(struct scsi_tape *STp, int do_wait)
                break;
        }
 
-       st_release_request(SRpnt);
-
+       if (SRpnt != NULL)
+               st_release_request(SRpnt);
        return retval;
 }
 
@@ -1065,24 +1038,17 @@ static int check_tape(struct scsi_tape *STp, struct file *filp)
                }
        }
 
-       SRpnt = st_allocate_request(STp);
-       if (!SRpnt) {
-               retval = STp->buffer->syscall_result;
-               goto err_out;
-       }
-
        if (STp->omit_blklims)
                STp->min_block = STp->max_block = (-1);
        else {
                memset((void *) &cmd[0], 0, MAX_COMMAND_SIZE);
                cmd[0] = READ_BLOCK_LIMITS;
 
-               retval = st_scsi_kern_execute(SRpnt, cmd, DMA_FROM_DEVICE,
-                                             STp->buffer->b_data, 6,
-                                             STp->device->request_queue->rq_timeout,
-                                             MAX_READY_RETRIES);
-               if (retval) {
-                       st_release_request(SRpnt);
+               SRpnt = st_do_scsi(SRpnt, STp, cmd, 6, DMA_FROM_DEVICE,
+                                  STp->device->request_queue->rq_timeout,
+                                  MAX_READY_RETRIES, 1);
+               if (!SRpnt) {
+                       retval = (STp->buffer)->syscall_result;
                        goto err_out;
                }
 
@@ -1106,12 +1072,11 @@ static int check_tape(struct scsi_tape *STp, struct file *filp)
        cmd[0] = MODE_SENSE;
        cmd[4] = 12;
 
-       retval = st_scsi_kern_execute(SRpnt, cmd, DMA_FROM_DEVICE,
-                                     STp->buffer->b_data, 12,
-                                     STp->device->request_queue->rq_timeout,
-                                     MAX_READY_RETRIES);
-       if (retval) {
-               st_release_request(SRpnt);
+       SRpnt = st_do_scsi(SRpnt, STp, cmd, 12, DMA_FROM_DEVICE,
+                          STp->device->request_queue->rq_timeout,
+                          MAX_READY_RETRIES, 1);
+       if (!SRpnt) {
+               retval = (STp->buffer)->syscall_result;
                goto err_out;
        }
 
@@ -1341,17 +1306,11 @@ static int st_flush(struct file *filp, fl_owner_t id)
                cmd[0] = WRITE_FILEMARKS;
                cmd[4] = 1 + STp->two_fm;
 
-               SRpnt = st_allocate_request(STp);
+               SRpnt = st_do_scsi(NULL, STp, cmd, 0, DMA_NONE,
+                                  STp->device->request_queue->rq_timeout,
+                                  MAX_WRITE_RETRIES, 1);
                if (!SRpnt) {
-                       result = STp->buffer->syscall_result;
-                       goto out;
-               }
-
-               result = st_scsi_kern_execute(SRpnt, cmd, DMA_NONE, NULL, 0,
-                                             STp->device->request_queue->rq_timeout,
-                                             MAX_WRITE_RETRIES);
-               if (result) {
-                       st_release_request(SRpnt);
+                       result = (STp->buffer)->syscall_result;
                        goto out;
                }
 
@@ -1525,7 +1484,6 @@ static int setup_buffering(struct scsi_tape *STp, const char __user *buf,
                else
                        STbp->do_dio = 0;  /* fall back to buffering with any error */
                STbp->sg_segs = STbp->do_dio;
-               STbp->frp_sg_current = 0;
                DEB(
                     if (STbp->do_dio) {
                        STp->nbr_dio++;
@@ -2325,7 +2283,8 @@ static int st_set_options(struct scsi_tape *STp, long options)
        } else if (code == MT_ST_SET_CLN) {
                value = (options & ~MT_ST_OPTIONS) & 0xff;
                if (value != 0 &&
-                   value < EXTENDED_SENSE_START && value >= SCSI_SENSE_BUFFERSIZE)
+                       (value < EXTENDED_SENSE_START ||
+                               value >= SCSI_SENSE_BUFFERSIZE))
                        return (-EINVAL);
                STp->cln_mode = value;
                STp->cln_sense_mask = (options >> 8) & 0xff;
@@ -2417,7 +2376,6 @@ static int read_mode_page(struct scsi_tape *STp, int page, int omit_block_descs)
 {
        unsigned char cmd[MAX_COMMAND_SIZE];
        struct st_request *SRpnt;
-       int ret;
 
        memset(cmd, 0, MAX_COMMAND_SIZE);
        cmd[0] = MODE_SENSE;
@@ -2426,17 +2384,14 @@ static int read_mode_page(struct scsi_tape *STp, int page, int omit_block_descs)
        cmd[2] = page;
        cmd[4] = 255;
 
-       SRpnt = st_allocate_request(STp);
-       if (!SRpnt)
-               return STp->buffer->syscall_result;
+       SRpnt = st_do_scsi(NULL, STp, cmd, cmd[4], DMA_FROM_DEVICE,
+                          STp->device->request_queue->rq_timeout, 0, 1);
+       if (SRpnt == NULL)
+               return (STp->buffer)->syscall_result;
 
-       ret = st_scsi_kern_execute(SRpnt, cmd, DMA_FROM_DEVICE,
-                                  STp->buffer->b_data, cmd[4],
-                                  STp->device->request_queue->rq_timeout,
-                                  MAX_RETRIES);
        st_release_request(SRpnt);
 
-       return ret ? : STp->buffer->syscall_result;
+       return STp->buffer->syscall_result;
 }
 
 
@@ -2444,9 +2399,10 @@ static int read_mode_page(struct scsi_tape *STp, int page, int omit_block_descs)
    in the buffer is correctly formatted. The long timeout is used if slow is non-zero. */
 static int write_mode_page(struct scsi_tape *STp, int page, int slow)
 {
-       int pgo, timeout, ret = 0;
+       int pgo;
        unsigned char cmd[MAX_COMMAND_SIZE];
        struct st_request *SRpnt;
+       int timeout;
 
        memset(cmd, 0, MAX_COMMAND_SIZE);
        cmd[0] = MODE_SELECT;
@@ -2460,21 +2416,16 @@ static int write_mode_page(struct scsi_tape *STp, int page, int slow)
        (STp->buffer)->b_data[MH_OFF_DEV_SPECIFIC] &= ~MH_BIT_WP;
        (STp->buffer)->b_data[pgo + MP_OFF_PAGE_NBR] &= MP_MSK_PAGE_NBR;
 
-       SRpnt = st_allocate_request(STp);
-       if (!SRpnt)
-               return ret;
-
-       timeout = slow ? STp->long_timeout :
-               STp->device->request_queue->rq_timeout;
-
-       ret = st_scsi_kern_execute(SRpnt, cmd, DMA_TO_DEVICE,
-                                  STp->buffer->b_data, cmd[4], timeout, 0);
-       if (!ret)
-               ret = STp->buffer->syscall_result;
+       timeout = slow ?
+               STp->long_timeout : STp->device->request_queue->rq_timeout;
+       SRpnt = st_do_scsi(NULL, STp, cmd, cmd[4], DMA_TO_DEVICE,
+                          timeout, 0, 1);
+       if (SRpnt == NULL)
+               return (STp->buffer)->syscall_result;
 
        st_release_request(SRpnt);
 
-       return ret;
+       return STp->buffer->syscall_result;
 }
 
 
@@ -2592,16 +2543,13 @@ static int do_load_unload(struct scsi_tape *STp, struct file *filp, int load_cod
                printk(ST_DEB_MSG "%s: Loading tape.\n", name);
                );
 
-       SRpnt = st_allocate_request(STp);
+       SRpnt = st_do_scsi(NULL, STp, cmd, 0, DMA_NONE,
+                          timeout, MAX_RETRIES, 1);
        if (!SRpnt)
-               return STp->buffer->syscall_result;
-
-       retval = st_scsi_kern_execute(SRpnt, cmd, DMA_NONE, NULL, 0, timeout,
-                                     MAX_RETRIES);
-       if (retval)
-               goto out;
+               return (STp->buffer)->syscall_result;
 
        retval = (STp->buffer)->syscall_result;
+       st_release_request(SRpnt);
 
        if (!retval) {  /* SCSI command successful */
 
@@ -2620,8 +2568,6 @@ static int do_load_unload(struct scsi_tape *STp, struct file *filp, int load_cod
                STps = &(STp->ps[STp->partition]);
                STps->drv_file = STps->drv_block = (-1);
        }
-out:
-       st_release_request(SRpnt);
 
        return retval;
 }
@@ -2897,15 +2843,12 @@ static int st_int_ioctl(struct scsi_tape *STp, unsigned int cmd_in, unsigned lon
                return (-ENOSYS);
        }
 
-       SRpnt = st_allocate_request(STp);
+       SRpnt = st_do_scsi(NULL, STp, cmd, datalen, direction,
+                          timeout, MAX_RETRIES, 1);
        if (!SRpnt)
                return (STp->buffer)->syscall_result;
 
-       ioctl_result = st_scsi_kern_execute(SRpnt, cmd, direction,
-                                           STp->buffer->b_data, datalen,
-                                           timeout, MAX_RETRIES);
-       if (!ioctl_result)
-               ioctl_result = (STp->buffer)->syscall_result;
+       ioctl_result = (STp->buffer)->syscall_result;
 
        if (!ioctl_result) {    /* SCSI command successful */
                st_release_request(SRpnt);
@@ -2920,11 +2863,8 @@ static int st_int_ioctl(struct scsi_tape *STp, unsigned int cmd_in, unsigned lon
                        ioctl_result = st_int_ioctl(STp, MTBSF, 1);
 
                if (cmd_in == MTSETBLK || cmd_in == SET_DENS_AND_BLK) {
-                       int old_block_size = STp->block_size;
                        STp->block_size = arg & MT_ST_BLKSIZE_MASK;
                        if (STp->block_size != 0) {
-                               if (old_block_size == 0)
-                                       normalize_buffer(STp->buffer);
                                (STp->buffer)->buffer_blocks =
                                    (STp->buffer)->buffer_size / STp->block_size;
                        }
@@ -3025,7 +2965,7 @@ static int st_int_ioctl(struct scsi_tape *STp, unsigned int cmd_in, unsigned lon
                            !(STp->use_pf & PF_TESTED)) {
                                /* Try the other possible state of Page Format if not
                                   already tried */
-                               STp->use_pf = !STp->use_pf | PF_TESTED;
+                               STp->use_pf = (STp->use_pf ^ USE_PF) | PF_TESTED;
                                st_release_request(SRpnt);
                                SRpnt = NULL;
                                return st_int_ioctl(STp, cmd_in, arg);
@@ -3067,17 +3007,11 @@ static int get_location(struct scsi_tape *STp, unsigned int *block, int *partiti
                if (!logical && !STp->scsi2_logical)
                        scmd[1] = 1;
        }
-
-       SRpnt = st_allocate_request(STp);
+       SRpnt = st_do_scsi(NULL, STp, scmd, 20, DMA_FROM_DEVICE,
+                          STp->device->request_queue->rq_timeout,
+                          MAX_READY_RETRIES, 1);
        if (!SRpnt)
-               return STp->buffer->syscall_result;
-
-       result = st_scsi_kern_execute(SRpnt, scmd, DMA_FROM_DEVICE,
-                                     STp->buffer->b_data, 20,
-                                     STp->device->request_queue->rq_timeout,
-                                     MAX_READY_RETRIES);
-       if (result)
-               goto out;
+               return (STp->buffer)->syscall_result;
 
        if ((STp->buffer)->syscall_result != 0 ||
            (STp->device->scsi_level >= SCSI_2 &&
@@ -3105,7 +3039,6 @@ static int get_location(struct scsi_tape *STp, unsigned int *block, int *partiti
                 DEBC(printk(ST_DEB_MSG "%s: Got tape pos. blk %d part %d.\n", name,
                             *block, *partition));
        }
-out:
        st_release_request(SRpnt);
        SRpnt = NULL;
 
@@ -3180,14 +3113,10 @@ static int set_location(struct scsi_tape *STp, unsigned int block, int partition
                timeout = STp->device->request_queue->rq_timeout;
        }
 
-       SRpnt = st_allocate_request(STp);
+       SRpnt = st_do_scsi(NULL, STp, scmd, 0, DMA_NONE,
+                          timeout, MAX_READY_RETRIES, 1);
        if (!SRpnt)
-               return STp->buffer->syscall_result;
-
-       result = st_scsi_kern_execute(SRpnt, scmd, DMA_NONE, NULL, 0,
-                                     timeout, MAX_READY_RETRIES);
-       if (result)
-               goto out;
+               return (STp->buffer)->syscall_result;
 
        STps->drv_block = STps->drv_file = (-1);
        STps->eof = ST_NOEOF;
@@ -3212,7 +3141,7 @@ static int set_location(struct scsi_tape *STp, unsigned int block, int partition
                        STps->drv_block = STps->drv_file = 0;
                result = 0;
        }
-out:
+
        st_release_request(SRpnt);
        SRpnt = NULL;
 
@@ -3741,30 +3670,22 @@ static long st_compat_ioctl(struct file *file, unsigned int cmd, unsigned long a
 
 /* Try to allocate a new tape buffer. Calling function must not hold
    dev_arr_lock. */
-static struct st_buffer *
- new_tape_buffer(int from_initialization, int need_dma, int max_sg)
+static struct st_buffer *new_tape_buffer(int need_dma, int max_sg)
 {
-       int got = 0;
-       gfp_t priority;
        struct st_buffer *tb;
 
-       if (from_initialization)
-               priority = GFP_ATOMIC;
-       else
-               priority = GFP_KERNEL;
-
-       tb = kzalloc(sizeof(struct st_buffer), priority);
+       tb = kzalloc(sizeof(struct st_buffer), GFP_ATOMIC);
        if (!tb) {
                printk(KERN_NOTICE "st: Can't allocate new tape buffer.\n");
                return NULL;
        }
-       tb->frp_segs = tb->orig_frp_segs = 0;
+       tb->frp_segs = 0;
        tb->use_sg = max_sg;
-
        tb->dma = need_dma;
-       tb->buffer_size = got;
+       tb->buffer_size = 0;
 
-       tb->reserved_pages = kzalloc(max_sg * sizeof(struct page *), priority);
+       tb->reserved_pages = kzalloc(max_sg * sizeof(struct page *),
+                                    GFP_ATOMIC);
        if (!tb->reserved_pages) {
                kfree(tb);
                return NULL;
@@ -3775,6 +3696,8 @@ static struct st_buffer *
 
 
 /* Try to allocate enough space in the tape buffer */
+#define ST_MAX_ORDER 6
+
 static int enlarge_buffer(struct st_buffer * STbuffer, int new_size, int need_dma)
 {
        int segs, nbr, max_segs, b_size, order, got;
@@ -3799,13 +3722,20 @@ static int enlarge_buffer(struct st_buffer * STbuffer, int new_size, int need_dm
                priority |= __GFP_ZERO;
 
        if (STbuffer->frp_segs) {
-               order = STbuffer->map_data.page_order;
+               order = STbuffer->reserved_page_order;
                b_size = PAGE_SIZE << order;
        } else {
                for (b_size = PAGE_SIZE, order = 0;
-                    order <= 6 && b_size < new_size; order++, b_size *= 2)
+                    order < ST_MAX_ORDER && b_size < new_size;
+                    order++, b_size *= 2)
                        ;  /* empty */
        }
+       if (max_segs * (PAGE_SIZE << order) < new_size) {
+               if (order == ST_MAX_ORDER)
+                       return 0;
+               normalize_buffer(STbuffer);
+               return enlarge_buffer(STbuffer, new_size, need_dma);
+       }
 
        for (segs = STbuffer->frp_segs, got = STbuffer->buffer_size;
             segs < max_segs && got < new_size;) {
@@ -3825,7 +3755,7 @@ static int enlarge_buffer(struct st_buffer * STbuffer, int new_size, int need_dm
                segs++;
        }
        STbuffer->b_data = page_address(STbuffer->reserved_pages[0]);
-       STbuffer->map_data.page_order = order;
+       STbuffer->reserved_page_order = order;
 
        return 1;
 }
@@ -3838,7 +3768,7 @@ static void clear_buffer(struct st_buffer * st_bp)
 
        for (i=0; i < st_bp->frp_segs; i++)
                memset(page_address(st_bp->reserved_pages[i]), 0,
-                      PAGE_SIZE << st_bp->map_data.page_order);
+                      PAGE_SIZE << st_bp->reserved_page_order);
        st_bp->cleared = 1;
 }
 
@@ -3846,16 +3776,15 @@ static void clear_buffer(struct st_buffer * st_bp)
 /* Release the extra buffer */
 static void normalize_buffer(struct st_buffer * STbuffer)
 {
-       int i, order = STbuffer->map_data.page_order;
+       int i, order = STbuffer->reserved_page_order;
 
-       for (i = STbuffer->orig_frp_segs; i < STbuffer->frp_segs; i++) {
+       for (i = 0; i < STbuffer->frp_segs; i++) {
                __free_pages(STbuffer->reserved_pages[i], order);
                STbuffer->buffer_size -= (PAGE_SIZE << order);
        }
-       STbuffer->frp_segs = STbuffer->orig_frp_segs;
-       STbuffer->frp_sg_current = 0;
+       STbuffer->frp_segs = 0;
        STbuffer->sg_segs = 0;
-       STbuffer->map_data.page_order = 0;
+       STbuffer->reserved_page_order = 0;
        STbuffer->map_data.offset = 0;
 }
 
@@ -3865,7 +3794,7 @@ static void normalize_buffer(struct st_buffer * STbuffer)
 static int append_to_buffer(const char __user *ubp, struct st_buffer * st_bp, int do_count)
 {
        int i, cnt, res, offset;
-       int length = PAGE_SIZE << st_bp->map_data.page_order;
+       int length = PAGE_SIZE << st_bp->reserved_page_order;
 
        for (i = 0, offset = st_bp->buffer_bytes;
             i < st_bp->frp_segs && offset >= length; i++)
@@ -3897,7 +3826,7 @@ static int append_to_buffer(const char __user *ubp, struct st_buffer * st_bp, in
 static int from_buffer(struct st_buffer * st_bp, char __user *ubp, int do_count)
 {
        int i, cnt, res, offset;
-       int length = PAGE_SIZE << st_bp->map_data.page_order;
+       int length = PAGE_SIZE << st_bp->reserved_page_order;
 
        for (i = 0, offset = st_bp->read_pointer;
             i < st_bp->frp_segs && offset >= length; i++)
@@ -3930,7 +3859,7 @@ static void move_buffer_data(struct st_buffer * st_bp, int offset)
 {
        int src_seg, dst_seg, src_offset = 0, dst_offset;
        int count, total;
-       int length = PAGE_SIZE << st_bp->map_data.page_order;
+       int length = PAGE_SIZE << st_bp->reserved_page_order;
 
        if (offset == 0)
                return;
@@ -4033,6 +3962,7 @@ static const struct file_operations st_fops =
        .open =         st_open,
        .flush =        st_flush,
        .release =      st_release,
+       .llseek =       noop_llseek,
 };
 
 static int st_probe(struct device *dev)
@@ -4055,11 +3985,10 @@ static int st_probe(struct device *dev)
                return -ENODEV;
        }
 
-       i = min(SDp->request_queue->max_hw_segments,
-               SDp->request_queue->max_phys_segments);
+       i = queue_max_segments(SDp->request_queue);
        if (st_max_sg_segs < i)
                i = st_max_sg_segs;
-       buffer = new_tape_buffer(1, (SDp->host)->unchecked_isa_dma, i);
+       buffer = new_tape_buffer((SDp->host)->unchecked_isa_dma, i);
        if (buffer == NULL) {
                printk(KERN_ERR
                       "st: Can't allocate new tape buffer. Device not attached.\n");
@@ -4313,7 +4242,6 @@ static void scsi_tape_release(struct kref *kref)
        tpnt->device = NULL;
 
        if (tpnt->buffer) {
-               tpnt->buffer->orig_frp_segs = 0;
                normalize_buffer(tpnt->buffer);
                kfree(tpnt->buffer->reserved_pages);
                kfree(tpnt->buffer);
@@ -4653,7 +4581,6 @@ static int sgl_map_user_pages(struct st_buffer *STbp,
         }
 
        mdata->offset = uaddr & ~PAGE_MASK;
-       mdata->page_order = 0;
        STbp->mapped_pages = pages;
 
        return nr_pages;