st.c (0dbd888936a23514716b8d944775bc56f731363a) st.c (40f6b36c6243462fb95d0343237331c423494b03)
1/*
2 SCSI Tape Driver for Linux version 1.1 and newer. See the accompanying
3 file Documentation/scsi/st.txt for more information.
4
5 History:
6 Rewritten from Dwayne Forsyth's SCSI tape driver by Kai Makisara.
7 Contribution and ideas from several people including (in alphabetical
8 order) Klaus Ehrenfried, Eugene Exarevsky, Eric Lee Green, Wolfgang Denk,
9 Steve Hirsch, Andreas Koppenh"ofer, Michael Leodolter, Eyal Lebedinsky,
10 Michael Schaefer, J"org Weule, and Eric Youngdale.
11
12 Copyright 1992 - 2008 Kai Makisara
13 email Kai.Makisara@kolumbus.fi
14
15 Some small formal changes - aeb, 950809
16
17 Last modified: 18-JAN-1998 Richard Gooch <rgooch@atnf.csiro.au> Devfs support
18 */
19
1/*
2 SCSI Tape Driver for Linux version 1.1 and newer. See the accompanying
3 file Documentation/scsi/st.txt for more information.
4
5 History:
6 Rewritten from Dwayne Forsyth's SCSI tape driver by Kai Makisara.
7 Contribution and ideas from several people including (in alphabetical
8 order) Klaus Ehrenfried, Eugene Exarevsky, Eric Lee Green, Wolfgang Denk,
9 Steve Hirsch, Andreas Koppenh"ofer, Michael Leodolter, Eyal Lebedinsky,
10 Michael Schaefer, J"org Weule, and Eric Youngdale.
11
12 Copyright 1992 - 2008 Kai Makisara
13 email Kai.Makisara@kolumbus.fi
14
15 Some small formal changes - aeb, 950809
16
17 Last modified: 18-JAN-1998 Richard Gooch <rgooch@atnf.csiro.au> Devfs support
18 */
19
20static const char *verstr = "20080221";
20static const char *verstr = "20080224";
21
22#include <linux/module.h>
23
24#include <linux/fs.h>
25#include <linux/kernel.h>
26#include <linux/sched.h>
27#include <linux/mm.h>
28#include <linux/init.h>

--- 149 unchanged lines hidden (view full) ---

178static int st_max_sg_segs = ST_MAX_SG;
179
180static struct scsi_tape **scsi_tapes = NULL;
181
182static int modes_defined;
183
184static struct st_buffer *new_tape_buffer(int, int, int);
185static int enlarge_buffer(struct st_buffer *, int, int);
21
22#include <linux/module.h>
23
24#include <linux/fs.h>
25#include <linux/kernel.h>
26#include <linux/sched.h>
27#include <linux/mm.h>
28#include <linux/init.h>

--- 149 unchanged lines hidden (view full) ---

178static int st_max_sg_segs = ST_MAX_SG;
179
180static struct scsi_tape **scsi_tapes = NULL;
181
182static int modes_defined;
183
184static struct st_buffer *new_tape_buffer(int, int, int);
185static int enlarge_buffer(struct st_buffer *, int, int);
186static void clear_buffer(struct st_buffer *);
186static void normalize_buffer(struct st_buffer *);
187static int append_to_buffer(const char __user *, struct st_buffer *, int);
188static int from_buffer(struct st_buffer *, char __user *, int);
189static void move_buffer_data(struct st_buffer *, int);
190static void buf_to_sg(struct st_buffer *, unsigned int);
191
192static int sgl_map_user_pages(struct scatterlist *, const unsigned int,
193 unsigned long, size_t, int);

--- 243 unchanged lines hidden (view full) ---

437/* Wakeup from interrupt */
438static void st_sleep_done(void *data, char *sense, int result, int resid)
439{
440 struct st_request *SRpnt = data;
441 struct scsi_tape *STp = SRpnt->stp;
442
443 memcpy(SRpnt->sense, sense, SCSI_SENSE_BUFFERSIZE);
444 (STp->buffer)->cmdstat.midlevel_result = SRpnt->result = result;
187static void normalize_buffer(struct st_buffer *);
188static int append_to_buffer(const char __user *, struct st_buffer *, int);
189static int from_buffer(struct st_buffer *, char __user *, int);
190static void move_buffer_data(struct st_buffer *, int);
191static void buf_to_sg(struct st_buffer *, unsigned int);
192
193static int sgl_map_user_pages(struct scatterlist *, const unsigned int,
194 unsigned long, size_t, int);

--- 243 unchanged lines hidden (view full) ---

438/* Wakeup from interrupt */
439static void st_sleep_done(void *data, char *sense, int result, int resid)
440{
441 struct st_request *SRpnt = data;
442 struct scsi_tape *STp = SRpnt->stp;
443
444 memcpy(SRpnt->sense, sense, SCSI_SENSE_BUFFERSIZE);
445 (STp->buffer)->cmdstat.midlevel_result = SRpnt->result = result;
446 (STp->buffer)->cmdstat.residual = resid;
445 DEB( STp->write_pending = 0; )
446
447 if (SRpnt->waiting)
448 complete(SRpnt->waiting);
449}
450
451static struct st_request *st_allocate_request(void)
452{

--- 701 unchanged lines hidden (view full) ---

1154 /* See that we have at least a one page buffer available */
1155 if (!enlarge_buffer(STp->buffer, PAGE_SIZE, STp->restr_dma)) {
1156 printk(KERN_WARNING "%s: Can't allocate one page tape buffer.\n",
1157 name);
1158 retval = (-EOVERFLOW);
1159 goto err_out;
1160 }
1161
447 DEB( STp->write_pending = 0; )
448
449 if (SRpnt->waiting)
450 complete(SRpnt->waiting);
451}
452
453static struct st_request *st_allocate_request(void)
454{

--- 701 unchanged lines hidden (view full) ---

1156 /* See that we have at least a one page buffer available */
1157 if (!enlarge_buffer(STp->buffer, PAGE_SIZE, STp->restr_dma)) {
1158 printk(KERN_WARNING "%s: Can't allocate one page tape buffer.\n",
1159 name);
1160 retval = (-EOVERFLOW);
1161 goto err_out;
1162 }
1163
1164 (STp->buffer)->cleared = 0;
1162 (STp->buffer)->writing = 0;
1163 (STp->buffer)->syscall_result = 0;
1164
1165 STp->write_prot = ((filp->f_flags & O_ACCMODE) == O_RDONLY);
1166
1167 STp->dirty = 0;
1168 for (i = 0; i < ST_NBR_PARTITIONS; i++) {
1169 STps = &(STp->ps[i]);

--- 257 unchanged lines hidden (view full) ---

1427 } else
1428 STbp->do_dio = 0;
1429 DEB( STp->nbr_requests++; )
1430
1431 if (!STbp->do_dio) {
1432 if (STp->block_size)
1433 bufsize = STp->block_size > st_fixed_buffer_size ?
1434 STp->block_size : st_fixed_buffer_size;
1165 (STp->buffer)->writing = 0;
1166 (STp->buffer)->syscall_result = 0;
1167
1168 STp->write_prot = ((filp->f_flags & O_ACCMODE) == O_RDONLY);
1169
1170 STp->dirty = 0;
1171 for (i = 0; i < ST_NBR_PARTITIONS; i++) {
1172 STps = &(STp->ps[i]);

--- 257 unchanged lines hidden (view full) ---

1430 } else
1431 STbp->do_dio = 0;
1432 DEB( STp->nbr_requests++; )
1433
1434 if (!STbp->do_dio) {
1435 if (STp->block_size)
1436 bufsize = STp->block_size > st_fixed_buffer_size ?
1437 STp->block_size : st_fixed_buffer_size;
1435 else
1438 else {
1436 bufsize = count;
1439 bufsize = count;
1440 /* Make sure that data from previous user is not leaked even if
1441 HBA does not return correct residual */
1442 if (is_read && STp->sili && !STbp->cleared)
1443 clear_buffer(STbp);
1444 }
1445
1437 if (bufsize > STbp->buffer_size &&
1438 !enlarge_buffer(STbp, bufsize, STp->restr_dma)) {
1439 printk(KERN_WARNING "%s: Can't allocate %d byte tape buffer.\n",
1440 tape_name(STp), bufsize);
1441 retval = (-EOVERFLOW);
1442 goto out;
1443 }
1444 if (STp->block_size)

--- 333 unchanged lines hidden (view full) ---

1778 blks = bytes / STp->block_size;
1779 bytes = blks * STp->block_size;
1780 }
1781 }
1782
1783 memset(cmd, 0, MAX_COMMAND_SIZE);
1784 cmd[0] = READ_6;
1785 cmd[1] = (STp->block_size != 0);
1446 if (bufsize > STbp->buffer_size &&
1447 !enlarge_buffer(STbp, bufsize, STp->restr_dma)) {
1448 printk(KERN_WARNING "%s: Can't allocate %d byte tape buffer.\n",
1449 tape_name(STp), bufsize);
1450 retval = (-EOVERFLOW);
1451 goto out;
1452 }
1453 if (STp->block_size)

--- 333 unchanged lines hidden (view full) ---

1787 blks = bytes / STp->block_size;
1788 bytes = blks * STp->block_size;
1789 }
1790 }
1791
1792 memset(cmd, 0, MAX_COMMAND_SIZE);
1793 cmd[0] = READ_6;
1794 cmd[1] = (STp->block_size != 0);
1795 if (!cmd[1] && STp->sili)
1796 cmd[1] |= 2;
1786 cmd[2] = blks >> 16;
1787 cmd[3] = blks >> 8;
1788 cmd[4] = blks;
1789
1790 SRpnt = *aSRpnt;
1791 SRpnt = st_do_scsi(SRpnt, STp, cmd, bytes, DMA_FROM_DEVICE,
1792 STp->device->timeout, MAX_RETRIES, 1);
1793 release_buffering(STp, 1);

--- 112 unchanged lines hidden (view full) ---

1906 }
1907 /* End of extended sense test */
1908 else { /* Non-extended sense */
1909 retval = STbp->syscall_result;
1910 }
1911
1912 }
1913 /* End of error handling */
1797 cmd[2] = blks >> 16;
1798 cmd[3] = blks >> 8;
1799 cmd[4] = blks;
1800
1801 SRpnt = *aSRpnt;
1802 SRpnt = st_do_scsi(SRpnt, STp, cmd, bytes, DMA_FROM_DEVICE,
1803 STp->device->timeout, MAX_RETRIES, 1);
1804 release_buffering(STp, 1);

--- 112 unchanged lines hidden (view full) ---

1917 }
1918 /* End of extended sense test */
1919 else { /* Non-extended sense */
1920 retval = STbp->syscall_result;
1921 }
1922
1923 }
1924 /* End of error handling */
1914 else /* Read successful */
1925 else { /* Read successful */
1915 STbp->buffer_bytes = bytes;
1926 STbp->buffer_bytes = bytes;
1927 if (STp->sili) /* In fixed block mode residual is always zero here */
1928 STbp->buffer_bytes -= STp->buffer->cmdstat.residual;
1929 }
1916
1917 if (STps->drv_block >= 0) {
1918 if (STp->block_size == 0)
1919 STps->drv_block++;
1920 else
1921 STps->drv_block += STbp->buffer_bytes / STp->block_size;
1922 }
1923 return retval;

--- 161 unchanged lines hidden (view full) ---

2085 printk(KERN_INFO
2086 "%s: can bsr: %d, two FMs: %d, fast mteom: %d, auto lock: %d,\n",
2087 name, STp->can_bsr, STp->two_fm, STp->fast_mteom, STp->do_auto_lock);
2088 printk(KERN_INFO
2089 "%s: defs for wr: %d, no block limits: %d, partitions: %d, s2 log: %d\n",
2090 name, STm->defaults_for_writes, STp->omit_blklims, STp->can_partitions,
2091 STp->scsi2_logical);
2092 printk(KERN_INFO
1930
1931 if (STps->drv_block >= 0) {
1932 if (STp->block_size == 0)
1933 STps->drv_block++;
1934 else
1935 STps->drv_block += STbp->buffer_bytes / STp->block_size;
1936 }
1937 return retval;

--- 161 unchanged lines hidden (view full) ---

2099 printk(KERN_INFO
2100 "%s: can bsr: %d, two FMs: %d, fast mteom: %d, auto lock: %d,\n",
2101 name, STp->can_bsr, STp->two_fm, STp->fast_mteom, STp->do_auto_lock);
2102 printk(KERN_INFO
2103 "%s: defs for wr: %d, no block limits: %d, partitions: %d, s2 log: %d\n",
2104 name, STm->defaults_for_writes, STp->omit_blklims, STp->can_partitions,
2105 STp->scsi2_logical);
2106 printk(KERN_INFO
2093 "%s: sysv: %d nowait: %d\n", name, STm->sysv, STp->immediate);
2107 "%s: sysv: %d nowait: %d sili: %d\n", name, STm->sysv, STp->immediate,
2108 STp->sili);
2094 printk(KERN_INFO "%s: debugging: %d\n",
2095 name, debugging);
2096 }
2097}
2098 )
2099
2100
2101static int st_set_options(struct scsi_tape *STp, long options)

--- 26 unchanged lines hidden (view full) ---

2128 STp->do_auto_lock = (options & MT_ST_AUTO_LOCK) != 0;
2129 STp->can_bsr = (options & MT_ST_CAN_BSR) != 0;
2130 STp->omit_blklims = (options & MT_ST_NO_BLKLIMS) != 0;
2131 if ((STp->device)->scsi_level >= SCSI_2)
2132 STp->can_partitions = (options & MT_ST_CAN_PARTITIONS) != 0;
2133 STp->scsi2_logical = (options & MT_ST_SCSI2LOGICAL) != 0;
2134 STp->immediate = (options & MT_ST_NOWAIT) != 0;
2135 STm->sysv = (options & MT_ST_SYSV) != 0;
2109 printk(KERN_INFO "%s: debugging: %d\n",
2110 name, debugging);
2111 }
2112}
2113 )
2114
2115
2116static int st_set_options(struct scsi_tape *STp, long options)

--- 26 unchanged lines hidden (view full) ---

2143 STp->do_auto_lock = (options & MT_ST_AUTO_LOCK) != 0;
2144 STp->can_bsr = (options & MT_ST_CAN_BSR) != 0;
2145 STp->omit_blklims = (options & MT_ST_NO_BLKLIMS) != 0;
2146 if ((STp->device)->scsi_level >= SCSI_2)
2147 STp->can_partitions = (options & MT_ST_CAN_PARTITIONS) != 0;
2148 STp->scsi2_logical = (options & MT_ST_SCSI2LOGICAL) != 0;
2149 STp->immediate = (options & MT_ST_NOWAIT) != 0;
2150 STm->sysv = (options & MT_ST_SYSV) != 0;
2151 STp->sili = (options & MT_ST_SILI) != 0;
2136 DEB( debugging = (options & MT_ST_DEBUGGING) != 0;
2137 st_log_options(STp, STm, name); )
2138 } else if (code == MT_ST_SETBOOLEANS || code == MT_ST_CLEARBOOLEANS) {
2139 value = (code == MT_ST_SETBOOLEANS);
2140 if ((options & MT_ST_BUFFER_WRITES) != 0)
2141 STm->do_buffer_writes = value;
2142 if ((options & MT_ST_ASYNC_WRITES) != 0)
2143 STm->do_async_writes = value;

--- 15 unchanged lines hidden (view full) ---

2159 (options & MT_ST_CAN_PARTITIONS) != 0)
2160 STp->can_partitions = value;
2161 if ((options & MT_ST_SCSI2LOGICAL) != 0)
2162 STp->scsi2_logical = value;
2163 if ((options & MT_ST_NOWAIT) != 0)
2164 STp->immediate = value;
2165 if ((options & MT_ST_SYSV) != 0)
2166 STm->sysv = value;
2152 DEB( debugging = (options & MT_ST_DEBUGGING) != 0;
2153 st_log_options(STp, STm, name); )
2154 } else if (code == MT_ST_SETBOOLEANS || code == MT_ST_CLEARBOOLEANS) {
2155 value = (code == MT_ST_SETBOOLEANS);
2156 if ((options & MT_ST_BUFFER_WRITES) != 0)
2157 STm->do_buffer_writes = value;
2158 if ((options & MT_ST_ASYNC_WRITES) != 0)
2159 STm->do_async_writes = value;

--- 15 unchanged lines hidden (view full) ---

2175 (options & MT_ST_CAN_PARTITIONS) != 0)
2176 STp->can_partitions = value;
2177 if ((options & MT_ST_SCSI2LOGICAL) != 0)
2178 STp->scsi2_logical = value;
2179 if ((options & MT_ST_NOWAIT) != 0)
2180 STp->immediate = value;
2181 if ((options & MT_ST_SYSV) != 0)
2182 STm->sysv = value;
2183 if ((options & MT_ST_SILI) != 0)
2184 STp->sili = value;
2167 DEB(
2168 if ((options & MT_ST_DEBUGGING) != 0)
2169 debugging = value;
2170 st_log_options(STp, STm, name); )
2171 } else if (code == MT_ST_WRITE_THRESHOLD) {
2172 /* Retained for compatibility */
2173 } else if (code == MT_ST_DEF_BLKSIZE) {
2174 value = (options & ~MT_ST_OPTIONS);

--- 1475 unchanged lines hidden (view full) ---

3650 DEB(STbuffer->buffer_size = got);
3651 normalize_buffer(STbuffer);
3652 return 0;
3653 }
3654 STbuffer->frp[segs].length = b_size;
3655 STbuffer->frp_segs += 1;
3656 got += b_size;
3657 STbuffer->buffer_size = got;
2185 DEB(
2186 if ((options & MT_ST_DEBUGGING) != 0)
2187 debugging = value;
2188 st_log_options(STp, STm, name); )
2189 } else if (code == MT_ST_WRITE_THRESHOLD) {
2190 /* Retained for compatibility */
2191 } else if (code == MT_ST_DEF_BLKSIZE) {
2192 value = (options & ~MT_ST_OPTIONS);

--- 1475 unchanged lines hidden (view full) ---

3668 DEB(STbuffer->buffer_size = got);
3669 normalize_buffer(STbuffer);
3670 return 0;
3671 }
3672 STbuffer->frp[segs].length = b_size;
3673 STbuffer->frp_segs += 1;
3674 got += b_size;
3675 STbuffer->buffer_size = got;
3676 if (STbuffer->cleared)
3677 memset(page_address(STbuffer->frp[segs].page), 0, b_size);
3658 segs++;
3659 }
3660 STbuffer->b_data = page_address(STbuffer->frp[0].page);
3661
3662 return 1;
3663}
3664
3665
3678 segs++;
3679 }
3680 STbuffer->b_data = page_address(STbuffer->frp[0].page);
3681
3682 return 1;
3683}
3684
3685
3686/* Make sure that no data from previous user is in the internal buffer */
3687static void clear_buffer(struct st_buffer * st_bp)
3688{
3689 int i;
3690
3691 for (i=0; i < st_bp->frp_segs; i++)
3692 memset(page_address(st_bp->frp[i].page), 0, st_bp->frp[i].length);
3693 st_bp->cleared = 1;
3694}
3695
3696
3666/* Release the extra buffer */
3667static void normalize_buffer(struct st_buffer * STbuffer)
3668{
3669 int i, order;
3670
3671 for (i = STbuffer->orig_frp_segs; i < STbuffer->frp_segs; i++) {
3672 order = get_order(STbuffer->frp[i].length);
3673 __free_pages(STbuffer->frp[i].page, order);

--- 308 unchanged lines hidden (view full) ---

3982 tpnt->use_pf = (SDp->scsi_level >= SCSI_2);
3983 tpnt->density = 0;
3984 tpnt->do_auto_lock = ST_AUTO_LOCK;
3985 tpnt->can_bsr = (SDp->scsi_level > 2 ? 1 : ST_IN_FILE_POS); /* BSR mandatory in SCSI3 */
3986 tpnt->can_partitions = 0;
3987 tpnt->two_fm = ST_TWO_FM;
3988 tpnt->fast_mteom = ST_FAST_MTEOM;
3989 tpnt->scsi2_logical = ST_SCSI2LOGICAL;
3697/* Release the extra buffer */
3698static void normalize_buffer(struct st_buffer * STbuffer)
3699{
3700 int i, order;
3701
3702 for (i = STbuffer->orig_frp_segs; i < STbuffer->frp_segs; i++) {
3703 order = get_order(STbuffer->frp[i].length);
3704 __free_pages(STbuffer->frp[i].page, order);

--- 308 unchanged lines hidden (view full) ---

4013 tpnt->use_pf = (SDp->scsi_level >= SCSI_2);
4014 tpnt->density = 0;
4015 tpnt->do_auto_lock = ST_AUTO_LOCK;
4016 tpnt->can_bsr = (SDp->scsi_level > 2 ? 1 : ST_IN_FILE_POS); /* BSR mandatory in SCSI3 */
4017 tpnt->can_partitions = 0;
4018 tpnt->two_fm = ST_TWO_FM;
4019 tpnt->fast_mteom = ST_FAST_MTEOM;
4020 tpnt->scsi2_logical = ST_SCSI2LOGICAL;
4021 tpnt->sili = ST_SILI;
3990 tpnt->immediate = ST_NOWAIT;
3991 tpnt->default_drvbuffer = 0xff; /* No forced buffering */
3992 tpnt->partition = 0;
3993 tpnt->new_partition = 0;
3994 tpnt->nbr_partitions = 0;
3995 tpnt->device->timeout = ST_TIMEOUT;
3996 tpnt->long_timeout = ST_LONG_TIMEOUT;
3997 tpnt->try_dio = try_direct_io && !SDp->host->unchecked_isa_dma;

--- 493 unchanged lines hidden ---
4022 tpnt->immediate = ST_NOWAIT;
4023 tpnt->default_drvbuffer = 0xff; /* No forced buffering */
4024 tpnt->partition = 0;
4025 tpnt->new_partition = 0;
4026 tpnt->nbr_partitions = 0;
4027 tpnt->device->timeout = ST_TIMEOUT;
4028 tpnt->long_timeout = ST_LONG_TIMEOUT;
4029 tpnt->try_dio = try_direct_io && !SDp->host->unchecked_isa_dma;

--- 493 unchanged lines hidden ---