Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Borislav Petkov | 5ce78af | 2008-02-02 19:56:48 +0100 | [diff] [blame] | 2 | * IDE ATAPI streaming tape driver. |
| 3 | * |
Bartlomiej Zolnierkiewicz | 59bca8c | 2008-02-01 23:09:33 +0100 | [diff] [blame] | 4 | * Copyright (C) 1995-1999 Gadi Oxman <gadio@netvision.net.il> |
| 5 | * Copyright (C) 2003-2005 Bartlomiej Zolnierkiewicz |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * This driver was constructed as a student project in the software laboratory |
| 8 | * of the faculty of electrical engineering in the Technion - Israel's |
| 9 | * Institute Of Technology, with the guide of Avner Lottem and Dr. Ilana David. |
| 10 | * |
| 11 | * It is hereby placed under the terms of the GNU general public license. |
| 12 | * (See linux/COPYING). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | * |
Borislav Petkov | 5ce78af | 2008-02-02 19:56:48 +0100 | [diff] [blame] | 14 | * For a historical changelog see |
| 15 | * Documentation/ide/ChangeLog.ide-tape.1995-2002 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | */ |
| 17 | |
Bartlomiej Zolnierkiewicz | 51509ee | 2008-10-10 22:39:34 +0200 | [diff] [blame] | 18 | #define DRV_NAME "ide-tape" |
| 19 | |
Borislav Petkov | dfe7993 | 2008-02-06 02:57:55 +0100 | [diff] [blame] | 20 | #define IDETAPE_VERSION "1.20" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <linux/module.h> |
| 23 | #include <linux/types.h> |
| 24 | #include <linux/string.h> |
| 25 | #include <linux/kernel.h> |
| 26 | #include <linux/delay.h> |
| 27 | #include <linux/timer.h> |
| 28 | #include <linux/mm.h> |
| 29 | #include <linux/interrupt.h> |
Marcelo Feitoza Parisi | 9bae1ff | 2006-03-28 01:56:46 -0800 | [diff] [blame] | 30 | #include <linux/jiffies.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <linux/major.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include <linux/errno.h> |
| 33 | #include <linux/genhd.h> |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 34 | #include <linux/seq_file.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #include <linux/slab.h> |
| 36 | #include <linux/pci.h> |
| 37 | #include <linux/ide.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | #include <linux/completion.h> |
| 39 | #include <linux/bitops.h> |
Arjan van de Ven | cf8b897 | 2006-03-23 03:00:45 -0800 | [diff] [blame] | 40 | #include <linux/mutex.h> |
Borislav Petkov | 90699ce | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 41 | #include <scsi/scsi.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
| 43 | #include <asm/byteorder.h> |
Borislav Petkov | c837cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 44 | #include <linux/uaccess.h> |
| 45 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | #include <asm/unaligned.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #include <linux/mtio.h> |
| 48 | |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 49 | /* define to see debug info */ |
Borislav Petkov | e972d70 | 2009-07-17 23:55:16 +0000 | [diff] [blame] | 50 | #undef IDETAPE_DEBUG_LOG |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 51 | |
Borislav Petkov | e972d70 | 2009-07-17 23:55:16 +0000 | [diff] [blame] | 52 | #ifdef IDETAPE_DEBUG_LOG |
| 53 | #define ide_debug_log(lvl, fmt, args...) __ide_debug_log(lvl, fmt, ## args) |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 54 | #else |
Borislav Petkov | e972d70 | 2009-07-17 23:55:16 +0000 | [diff] [blame] | 55 | #define ide_debug_log(lvl, fmt, args...) do {} while (0) |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 56 | #endif |
| 57 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | /**************************** Tunable parameters *****************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | /* |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 60 | * After each failed packet command we issue a request sense command and retry |
| 61 | * the packet command IDETAPE_MAX_PC_RETRIES times. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | * |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 63 | * Setting IDETAPE_MAX_PC_RETRIES to 0 will disable retries. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | */ |
| 65 | #define IDETAPE_MAX_PC_RETRIES 3 |
| 66 | |
| 67 | /* |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 68 | * The following parameter is used to select the point in the internal tape fifo |
| 69 | * in which we will start to refill the buffer. Decreasing the following |
| 70 | * parameter will improve the system's latency and interactive response, while |
| 71 | * using a high value might improve system throughput. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | */ |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 73 | #define IDETAPE_FIFO_THRESHOLD 2 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | |
| 75 | /* |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 76 | * DSC polling parameters. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | * |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 78 | * Polling for DSC (a single bit in the status register) is a very important |
| 79 | * function in ide-tape. There are two cases in which we poll for DSC: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | * |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 81 | * 1. Before a read/write packet command, to ensure that we can transfer data |
| 82 | * from/to the tape's data buffers, without causing an actual media access. |
| 83 | * In case the tape is not ready yet, we take out our request from the device |
| 84 | * request queue, so that ide.c could service requests from the other device |
| 85 | * on the same interface in the meantime. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | * |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 87 | * 2. After the successful initialization of a "media access packet command", |
| 88 | * which is a command that can take a long time to complete (the interval can |
| 89 | * range from several seconds to even an hour). Again, we postpone our request |
| 90 | * in the middle to free the bus for the other device. The polling frequency |
| 91 | * here should be lower than the read/write frequency since those media access |
| 92 | * commands are slow. We start from a "fast" frequency - IDETAPE_DSC_MA_FAST |
| 93 | * (1 second), and if we don't receive DSC after IDETAPE_DSC_MA_THRESHOLD |
| 94 | * (5 min), we switch it to a lower frequency - IDETAPE_DSC_MA_SLOW (1 min). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | * |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 96 | * We also set a timeout for the timer, in case something goes wrong. The |
| 97 | * timeout should be longer then the maximum execution time of a tape operation. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | */ |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 99 | |
| 100 | /* DSC timings. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | #define IDETAPE_DSC_RW_MIN 5*HZ/100 /* 50 msec */ |
| 102 | #define IDETAPE_DSC_RW_MAX 40*HZ/100 /* 400 msec */ |
| 103 | #define IDETAPE_DSC_RW_TIMEOUT 2*60*HZ /* 2 minutes */ |
| 104 | #define IDETAPE_DSC_MA_FAST 2*HZ /* 2 seconds */ |
| 105 | #define IDETAPE_DSC_MA_THRESHOLD 5*60*HZ /* 5 minutes */ |
| 106 | #define IDETAPE_DSC_MA_SLOW 30*HZ /* 30 seconds */ |
| 107 | #define IDETAPE_DSC_MA_TIMEOUT 2*60*60*HZ /* 2 hours */ |
| 108 | |
| 109 | /*************************** End of tunable parameters ***********************/ |
| 110 | |
Borislav Petkov | 54abf37 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 111 | /* tape directions */ |
| 112 | enum { |
| 113 | IDETAPE_DIR_NONE = (1 << 0), |
| 114 | IDETAPE_DIR_READ = (1 << 1), |
| 115 | IDETAPE_DIR_WRITE = (1 << 2), |
| 116 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | |
Borislav Petkov | 03056b9 | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 118 | /* Tape door status */ |
| 119 | #define DOOR_UNLOCKED 0 |
| 120 | #define DOOR_LOCKED 1 |
| 121 | #define DOOR_EXPLICITLY_LOCKED 2 |
| 122 | |
| 123 | /* Some defines for the SPACE command */ |
| 124 | #define IDETAPE_SPACE_OVER_FILEMARK 1 |
| 125 | #define IDETAPE_SPACE_TO_EOD 3 |
| 126 | |
| 127 | /* Some defines for the LOAD UNLOAD command */ |
| 128 | #define IDETAPE_LU_LOAD_MASK 1 |
| 129 | #define IDETAPE_LU_RETENSION_MASK 2 |
| 130 | #define IDETAPE_LU_EOT_MASK 4 |
| 131 | |
Borislav Petkov | 03056b9 | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 132 | /* Structures related to the SELECT SENSE / MODE SENSE packet commands. */ |
| 133 | #define IDETAPE_BLOCK_DESCRIPTOR 0 |
| 134 | #define IDETAPE_CAPABILITIES_PAGE 0x2a |
| 135 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | /* |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 137 | * Most of our global data which we need to save even as we leave the driver due |
| 138 | * to an interrupt or a timer event is stored in the struct defined below. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | */ |
| 140 | typedef struct ide_tape_obj { |
Bartlomiej Zolnierkiewicz | 7f3c868 | 2009-01-06 17:20:53 +0100 | [diff] [blame] | 141 | ide_drive_t *drive; |
| 142 | struct ide_driver *driver; |
| 143 | struct gendisk *disk; |
Bartlomiej Zolnierkiewicz | 8fed436 | 2009-02-25 20:28:24 +0100 | [diff] [blame] | 144 | struct device dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | |
Bartlomiej Zolnierkiewicz | 2e8a6f8 | 2008-10-10 22:39:36 +0200 | [diff] [blame] | 146 | /* used by REQ_IDETAPE_{READ,WRITE} requests */ |
| 147 | struct ide_atapi_pc queued_pc; |
Bartlomiej Zolnierkiewicz | 394a4c2 | 2008-10-10 22:39:35 +0200 | [diff] [blame] | 148 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | /* |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 150 | * DSC polling variables. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | * |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 152 | * While polling for DSC we use postponed_rq to postpone the current |
| 153 | * request so that ide.c will be able to service pending requests on the |
| 154 | * other device. Note that at most we will have only one DSC (usually |
Borislav Petkov | 5bd50dc | 2008-04-27 15:38:28 +0200 | [diff] [blame] | 155 | * data transfer) request in the device request queue. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | */ |
Borislav Petkov | 6f3848a | 2009-07-21 23:08:23 -0700 | [diff] [blame] | 157 | bool postponed_rq; |
| 158 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | /* The time in which we started polling for DSC */ |
| 160 | unsigned long dsc_polling_start; |
| 161 | /* Timer used to poll for dsc */ |
| 162 | struct timer_list dsc_timer; |
| 163 | /* Read/Write dsc polling frequency */ |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 164 | unsigned long best_dsc_rw_freq; |
| 165 | unsigned long dsc_poll_freq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | unsigned long dsc_timeout; |
| 167 | |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 168 | /* Read position information */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | u8 partition; |
| 170 | /* Current block */ |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 171 | unsigned int first_frame; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 173 | /* Last error information */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | u8 sense_key, asc, ascq; |
| 175 | |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 176 | /* Character device operation */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | unsigned int minor; |
| 178 | /* device name */ |
| 179 | char name[4]; |
| 180 | /* Current character device data transfer direction */ |
Borislav Petkov | 54abf37 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 181 | u8 chrdev_dir; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 183 | /* tape block size, usually 512 or 1024 bytes */ |
| 184 | unsigned short blk_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | int user_bs_factor; |
Borislav Petkov | b642201 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 186 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | /* Copy of the tape's Capabilities and Mechanical Page */ |
Borislav Petkov | b642201 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 188 | u8 caps[20]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | |
| 190 | /* |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 191 | * Active data transfer request parameters. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | * |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 193 | * At most, there is only one ide-tape originated data transfer request |
| 194 | * in the device request queue. This allows ide.c to easily service |
| 195 | * requests from the other device when we postpone our active request. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | */ |
Borislav Petkov | 83042b2 | 2008-04-27 15:38:27 +0200 | [diff] [blame] | 197 | |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 198 | /* Data buffer size chosen based on the tape's recommendation */ |
Borislav Petkov | f73850a | 2008-04-27 15:38:33 +0200 | [diff] [blame] | 199 | int buffer_size; |
Tejun Heo | 963da55 | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 200 | /* Staging buffer of buffer_size bytes */ |
| 201 | void *buf; |
| 202 | /* The read/write cursor */ |
| 203 | void *cur; |
| 204 | /* The number of valid bytes in buf */ |
| 205 | size_t valid; |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 206 | |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 207 | /* Measures average tape speed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | unsigned long avg_time; |
| 209 | int avg_size; |
| 210 | int avg_speed; |
| 211 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | /* the door is currently locked */ |
| 213 | int door_locked; |
| 214 | /* the tape hardware is write protected */ |
| 215 | char drv_write_prot; |
| 216 | /* the tape is write protected (hardware or opened as read-only) */ |
| 217 | char write_prot; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | } idetape_tape_t; |
| 219 | |
Arnd Bergmann | 2a48fc0 | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 220 | static DEFINE_MUTEX(ide_tape_mutex); |
Arjan van de Ven | cf8b897 | 2006-03-23 03:00:45 -0800 | [diff] [blame] | 221 | static DEFINE_MUTEX(idetape_ref_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | |
Borislav Petkov | cbba2fa | 2009-10-11 00:25:19 +0000 | [diff] [blame] | 223 | static DEFINE_MUTEX(idetape_chrdev_mutex); |
| 224 | |
Will Dyson | d5dee80 | 2005-09-16 02:55:07 -0700 | [diff] [blame] | 225 | static struct class *idetape_sysfs_class; |
| 226 | |
Bartlomiej Zolnierkiewicz | 8fed436 | 2009-02-25 20:28:24 +0100 | [diff] [blame] | 227 | static void ide_tape_release(struct device *); |
Bartlomiej Zolnierkiewicz | 08da591 | 2008-07-24 22:53:15 +0200 | [diff] [blame] | 228 | |
Borislav Petkov | 9d01e4c | 2009-06-08 22:03:03 +0200 | [diff] [blame] | 229 | static struct ide_tape_obj *idetape_devs[MAX_HWIFS * MAX_DRIVES]; |
| 230 | |
| 231 | static struct ide_tape_obj *ide_tape_get(struct gendisk *disk, bool cdev, |
| 232 | unsigned int i) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | { |
| 234 | struct ide_tape_obj *tape = NULL; |
| 235 | |
Arjan van de Ven | cf8b897 | 2006-03-23 03:00:45 -0800 | [diff] [blame] | 236 | mutex_lock(&idetape_ref_mutex); |
Borislav Petkov | 9d01e4c | 2009-06-08 22:03:03 +0200 | [diff] [blame] | 237 | |
| 238 | if (cdev) |
| 239 | tape = idetape_devs[i]; |
| 240 | else |
| 241 | tape = ide_drv_g(disk, ide_tape_obj); |
| 242 | |
Bartlomiej Zolnierkiewicz | 08da591 | 2008-07-24 22:53:15 +0200 | [diff] [blame] | 243 | if (tape) { |
Bartlomiej Zolnierkiewicz | d3e33ff | 2008-08-05 18:16:59 +0200 | [diff] [blame] | 244 | if (ide_device_get(tape->drive)) |
Bartlomiej Zolnierkiewicz | 08da591 | 2008-07-24 22:53:15 +0200 | [diff] [blame] | 245 | tape = NULL; |
Bartlomiej Zolnierkiewicz | d3e33ff | 2008-08-05 18:16:59 +0200 | [diff] [blame] | 246 | else |
Bartlomiej Zolnierkiewicz | 8fed436 | 2009-02-25 20:28:24 +0100 | [diff] [blame] | 247 | get_device(&tape->dev); |
Bartlomiej Zolnierkiewicz | 08da591 | 2008-07-24 22:53:15 +0200 | [diff] [blame] | 248 | } |
Borislav Petkov | 9d01e4c | 2009-06-08 22:03:03 +0200 | [diff] [blame] | 249 | |
Arjan van de Ven | cf8b897 | 2006-03-23 03:00:45 -0800 | [diff] [blame] | 250 | mutex_unlock(&idetape_ref_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | return tape; |
| 252 | } |
| 253 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | static void ide_tape_put(struct ide_tape_obj *tape) |
| 255 | { |
Bartlomiej Zolnierkiewicz | d3e33ff | 2008-08-05 18:16:59 +0200 | [diff] [blame] | 256 | ide_drive_t *drive = tape->drive; |
| 257 | |
Arjan van de Ven | cf8b897 | 2006-03-23 03:00:45 -0800 | [diff] [blame] | 258 | mutex_lock(&idetape_ref_mutex); |
Bartlomiej Zolnierkiewicz | 8fed436 | 2009-02-25 20:28:24 +0100 | [diff] [blame] | 259 | put_device(&tape->dev); |
Bartlomiej Zolnierkiewicz | d3e33ff | 2008-08-05 18:16:59 +0200 | [diff] [blame] | 260 | ide_device_put(drive); |
Arjan van de Ven | cf8b897 | 2006-03-23 03:00:45 -0800 | [diff] [blame] | 261 | mutex_unlock(&idetape_ref_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | } |
| 263 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | /* |
Borislav Petkov | 1b5db43 | 2008-02-02 19:56:48 +0100 | [diff] [blame] | 265 | * called on each failed packet command retry to analyze the request sense. We |
| 266 | * currently do not utilize this information. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | */ |
Borislav Petkov | ae3a838 | 2009-05-02 10:58:17 +0200 | [diff] [blame] | 268 | static void idetape_analyze_error(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | { |
| 270 | idetape_tape_t *tape = drive->driver_data; |
Bartlomiej Zolnierkiewicz | 5e2040fd | 2009-03-27 12:46:34 +0100 | [diff] [blame] | 271 | struct ide_atapi_pc *pc = drive->failed_pc; |
Borislav Petkov | dfb7e62 | 2009-05-01 20:35:21 +0200 | [diff] [blame] | 272 | struct request *rq = drive->hwif->rq; |
Borislav Petkov | ae3a838 | 2009-05-02 10:58:17 +0200 | [diff] [blame] | 273 | u8 *sense = bio_data(rq->bio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | |
Borislav Petkov | 1b5db43 | 2008-02-02 19:56:48 +0100 | [diff] [blame] | 275 | tape->sense_key = sense[2] & 0xF; |
| 276 | tape->asc = sense[12]; |
| 277 | tape->ascq = sense[13]; |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 278 | |
Borislav Petkov | e972d70 | 2009-07-17 23:55:16 +0000 | [diff] [blame] | 279 | ide_debug_log(IDE_DBG_FUNC, |
| 280 | "cmd: 0x%x, sense key = %x, asc = %x, ascq = %x", |
| 281 | rq->cmd[0], tape->sense_key, tape->asc, tape->ascq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | |
Borislav Petkov | 077e6db | 2009-05-01 21:21:02 +0200 | [diff] [blame] | 283 | /* correct remaining bytes to transfer */ |
Tejun Heo | 21d9c5d | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 284 | if (pc->flags & PC_FLAG_DMA_ERROR) |
Borislav Petkov | 077e6db | 2009-05-01 21:21:02 +0200 | [diff] [blame] | 285 | rq->resid_len = tape->blk_size * get_unaligned_be32(&sense[3]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | |
| 287 | /* |
| 288 | * If error was the result of a zero-length read or write command, |
| 289 | * with sense key=5, asc=0x22, ascq=0, let it slide. Some drives |
| 290 | * (i.e. Seagate STT3401A Travan) don't support 0-length read/writes. |
| 291 | */ |
Borislav Petkov | 90699ce | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 292 | if ((pc->c[0] == READ_6 || pc->c[0] == WRITE_6) |
Borislav Petkov | 1b5db43 | 2008-02-02 19:56:48 +0100 | [diff] [blame] | 293 | /* length == 0 */ |
| 294 | && pc->c[4] == 0 && pc->c[3] == 0 && pc->c[2] == 0) { |
| 295 | if (tape->sense_key == 5) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | /* don't report an error, everything's ok */ |
| 297 | pc->error = 0; |
| 298 | /* don't retry read/write */ |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 299 | pc->flags |= PC_FLAG_ABORT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | } |
| 301 | } |
Borislav Petkov | 90699ce | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 302 | if (pc->c[0] == READ_6 && (sense[2] & 0x80)) { |
Bartlomiej Zolnierkiewicz | c152cc1 | 2009-03-27 12:46:34 +0100 | [diff] [blame] | 303 | pc->error = IDE_DRV_ERROR_FILEMARK; |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 304 | pc->flags |= PC_FLAG_ABORT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | } |
Borislav Petkov | 90699ce | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 306 | if (pc->c[0] == WRITE_6) { |
Borislav Petkov | 1b5db43 | 2008-02-02 19:56:48 +0100 | [diff] [blame] | 307 | if ((sense[2] & 0x40) || (tape->sense_key == 0xd |
| 308 | && tape->asc == 0x0 && tape->ascq == 0x2)) { |
Bartlomiej Zolnierkiewicz | c152cc1 | 2009-03-27 12:46:34 +0100 | [diff] [blame] | 309 | pc->error = IDE_DRV_ERROR_EOD; |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 310 | pc->flags |= PC_FLAG_ABORT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | } |
| 312 | } |
Borislav Petkov | 90699ce | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 313 | if (pc->c[0] == READ_6 || pc->c[0] == WRITE_6) { |
Borislav Petkov | 1b5db43 | 2008-02-02 19:56:48 +0100 | [diff] [blame] | 314 | if (tape->sense_key == 8) { |
Bartlomiej Zolnierkiewicz | c152cc1 | 2009-03-27 12:46:34 +0100 | [diff] [blame] | 315 | pc->error = IDE_DRV_ERROR_EOD; |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 316 | pc->flags |= PC_FLAG_ABORT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | } |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 318 | if (!(pc->flags & PC_FLAG_ABORT) && |
Borislav Petkov | 077e6db | 2009-05-01 21:21:02 +0200 | [diff] [blame] | 319 | (blk_rq_bytes(rq) - rq->resid_len)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | pc->retries = IDETAPE_MAX_PC_RETRIES + 1; |
| 321 | } |
| 322 | } |
| 323 | |
Bartlomiej Zolnierkiewicz | b14c721 | 2008-10-13 21:39:30 +0200 | [diff] [blame] | 324 | static void ide_tape_handle_dsc(ide_drive_t *); |
| 325 | |
Bartlomiej Zolnierkiewicz | 03a2faa | 2009-03-27 12:46:36 +0100 | [diff] [blame] | 326 | static int ide_tape_callback(ide_drive_t *drive, int dsc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | { |
| 328 | idetape_tape_t *tape = drive->driver_data; |
Bartlomiej Zolnierkiewicz | 2b9efba | 2008-10-13 21:39:31 +0200 | [diff] [blame] | 329 | struct ide_atapi_pc *pc = drive->pc; |
Bartlomiej Zolnierkiewicz | 313afea | 2009-03-27 12:46:34 +0100 | [diff] [blame] | 330 | struct request *rq = drive->hwif->rq; |
Bartlomiej Zolnierkiewicz | 5985e6a | 2008-07-15 21:21:55 +0200 | [diff] [blame] | 331 | int uptodate = pc->error ? 0 : 1; |
Bartlomiej Zolnierkiewicz | 313afea | 2009-03-27 12:46:34 +0100 | [diff] [blame] | 332 | int err = uptodate ? 0 : IDE_DRV_ERROR_GENERAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | |
Borislav Petkov | e972d70 | 2009-07-17 23:55:16 +0000 | [diff] [blame] | 334 | ide_debug_log(IDE_DBG_FUNC, "cmd: 0x%x, dsc: %d, err: %d", rq->cmd[0], |
| 335 | dsc, err); |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 336 | |
Bartlomiej Zolnierkiewicz | b14c721 | 2008-10-13 21:39:30 +0200 | [diff] [blame] | 337 | if (dsc) |
| 338 | ide_tape_handle_dsc(drive); |
| 339 | |
Bartlomiej Zolnierkiewicz | 5e2040fd | 2009-03-27 12:46:34 +0100 | [diff] [blame] | 340 | if (drive->failed_pc == pc) |
| 341 | drive->failed_pc = NULL; |
Bartlomiej Zolnierkiewicz | dd2e9a0 | 2008-07-15 21:22:01 +0200 | [diff] [blame] | 342 | |
Bartlomiej Zolnierkiewicz | 5985e6a | 2008-07-15 21:21:55 +0200 | [diff] [blame] | 343 | if (pc->c[0] == REQUEST_SENSE) { |
| 344 | if (uptodate) |
Borislav Petkov | ae3a838 | 2009-05-02 10:58:17 +0200 | [diff] [blame] | 345 | idetape_analyze_error(drive); |
Bartlomiej Zolnierkiewicz | 5985e6a | 2008-07-15 21:21:55 +0200 | [diff] [blame] | 346 | else |
| 347 | printk(KERN_ERR "ide-tape: Error in REQUEST SENSE " |
| 348 | "itself - Aborting request!\n"); |
| 349 | } else if (pc->c[0] == READ_6 || pc->c[0] == WRITE_6) { |
Borislav Petkov | 077e6db | 2009-05-01 21:21:02 +0200 | [diff] [blame] | 350 | unsigned int blocks = |
| 351 | (blk_rq_bytes(rq) - rq->resid_len) / tape->blk_size; |
Bartlomiej Zolnierkiewicz | 5985e6a | 2008-07-15 21:21:55 +0200 | [diff] [blame] | 352 | |
| 353 | tape->avg_size += blocks * tape->blk_size; |
| 354 | |
| 355 | if (time_after_eq(jiffies, tape->avg_time + HZ)) { |
| 356 | tape->avg_speed = tape->avg_size * HZ / |
| 357 | (jiffies - tape->avg_time) / 1024; |
| 358 | tape->avg_size = 0; |
| 359 | tape->avg_time = jiffies; |
| 360 | } |
| 361 | |
| 362 | tape->first_frame += blocks; |
Bartlomiej Zolnierkiewicz | 5985e6a | 2008-07-15 21:21:55 +0200 | [diff] [blame] | 363 | |
Bartlomiej Zolnierkiewicz | 313afea | 2009-03-27 12:46:34 +0100 | [diff] [blame] | 364 | if (pc->error) { |
| 365 | uptodate = 0; |
| 366 | err = pc->error; |
| 367 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | } |
Bartlomiej Zolnierkiewicz | 313afea | 2009-03-27 12:46:34 +0100 | [diff] [blame] | 369 | rq->errors = err; |
| 370 | |
Bartlomiej Zolnierkiewicz | 03a2faa | 2009-03-27 12:46:36 +0100 | [diff] [blame] | 371 | return uptodate; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | } |
| 373 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | /* |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 375 | * Postpone the current request so that ide.c will be able to service requests |
Bartlomiej Zolnierkiewicz | b65fac3 | 2009-01-06 17:20:50 +0100 | [diff] [blame] | 376 | * from another device on the same port while we are polling for DSC. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | */ |
Borislav Petkov | 6f3848a | 2009-07-21 23:08:23 -0700 | [diff] [blame] | 378 | static void ide_tape_stall_queue(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | { |
| 380 | idetape_tape_t *tape = drive->driver_data; |
| 381 | |
Borislav Petkov | e972d70 | 2009-07-17 23:55:16 +0000 | [diff] [blame] | 382 | ide_debug_log(IDE_DBG_FUNC, "cmd: 0x%x, dsc_poll_freq: %lu", |
Borislav Petkov | 6f3848a | 2009-07-21 23:08:23 -0700 | [diff] [blame] | 383 | drive->hwif->rq->cmd[0], tape->dsc_poll_freq); |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 384 | |
Borislav Petkov | 6f3848a | 2009-07-21 23:08:23 -0700 | [diff] [blame] | 385 | tape->postponed_rq = true; |
Bartlomiej Zolnierkiewicz | b65fac3 | 2009-01-06 17:20:50 +0100 | [diff] [blame] | 386 | |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 387 | ide_stall_queue(drive, tape->dsc_poll_freq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | } |
| 389 | |
Bartlomiej Zolnierkiewicz | 74e63e74 | 2008-07-15 21:22:01 +0200 | [diff] [blame] | 390 | static void ide_tape_handle_dsc(ide_drive_t *drive) |
| 391 | { |
| 392 | idetape_tape_t *tape = drive->driver_data; |
| 393 | |
| 394 | /* Media access command */ |
| 395 | tape->dsc_polling_start = jiffies; |
| 396 | tape->dsc_poll_freq = IDETAPE_DSC_MA_FAST; |
| 397 | tape->dsc_timeout = jiffies + IDETAPE_DSC_MA_TIMEOUT; |
| 398 | /* Allow ide.c to handle other requests */ |
Borislav Petkov | 6f3848a | 2009-07-21 23:08:23 -0700 | [diff] [blame] | 399 | ide_tape_stall_queue(drive); |
Bartlomiej Zolnierkiewicz | 74e63e74 | 2008-07-15 21:22:01 +0200 | [diff] [blame] | 400 | } |
| 401 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | /* |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 403 | * Packet Command Interface |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | * |
Bartlomiej Zolnierkiewicz | 2b9efba | 2008-10-13 21:39:31 +0200 | [diff] [blame] | 405 | * The current Packet Command is available in drive->pc, and will not change |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 406 | * until we finish handling it. Each packet command is associated with a |
| 407 | * callback function that will be called when the command is finished. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | * |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 409 | * The handling will be done in three stages: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | * |
Bartlomiej Zolnierkiewicz | b788ee9 | 2009-03-27 12:46:46 +0100 | [diff] [blame] | 411 | * 1. ide_tape_issue_pc will send the packet command to the drive, and will set |
Bartlomiej Zolnierkiewicz | aa5d2de7 | 2008-10-13 21:39:32 +0200 | [diff] [blame] | 412 | * the interrupt handler to ide_pc_intr. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | * |
Bartlomiej Zolnierkiewicz | aa5d2de7 | 2008-10-13 21:39:32 +0200 | [diff] [blame] | 414 | * 2. On each interrupt, ide_pc_intr will be called. This step will be |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 415 | * repeated until the device signals us that no more interrupts will be issued. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | * |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 417 | * 3. ATAPI Tape media access commands have immediate status with a delayed |
| 418 | * process. In case of a successful initiation of a media access packet command, |
| 419 | * the DSC bit will be set when the actual execution of the command is finished. |
| 420 | * Since the tape drive will not issue an interrupt, we have to poll for this |
| 421 | * event. In this case, we define the request as "low priority request" by |
| 422 | * setting rq_status to IDETAPE_RQ_POSTPONED, set a timer to poll for DSC and |
| 423 | * exit the driver. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | * |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 425 | * ide.c will then give higher priority to requests which originate from the |
| 426 | * other device, until will change rq_status to RQ_ACTIVE. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | * |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 428 | * 4. When the packet command is finished, it will be checked for errors. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | * |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 430 | * 5. In case an error was found, we queue a request sense packet command in |
| 431 | * front of the request queue and retry the operation up to |
| 432 | * IDETAPE_MAX_PC_RETRIES times. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | * |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 434 | * 6. In case no error was found, or we decided to give up and not to retry |
| 435 | * again, the callback function will be called and then we will handle the next |
| 436 | * request. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | |
Bartlomiej Zolnierkiewicz | b788ee9 | 2009-03-27 12:46:46 +0100 | [diff] [blame] | 439 | static ide_startstop_t ide_tape_issue_pc(ide_drive_t *drive, |
| 440 | struct ide_cmd *cmd, |
| 441 | struct ide_atapi_pc *pc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | idetape_tape_t *tape = drive->driver_data; |
Borislav Petkov | dfb7e62 | 2009-05-01 20:35:21 +0200 | [diff] [blame] | 444 | struct request *rq = drive->hwif->rq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | |
Bartlomiej Zolnierkiewicz | 5e2040fd | 2009-03-27 12:46:34 +0100 | [diff] [blame] | 446 | if (drive->failed_pc == NULL && pc->c[0] != REQUEST_SENSE) |
| 447 | drive->failed_pc = pc; |
Bartlomiej Zolnierkiewicz | 2b9efba | 2008-10-13 21:39:31 +0200 | [diff] [blame] | 448 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | /* Set the current packet command */ |
Bartlomiej Zolnierkiewicz | 2b9efba | 2008-10-13 21:39:31 +0200 | [diff] [blame] | 450 | drive->pc = pc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | |
| 452 | if (pc->retries > IDETAPE_MAX_PC_RETRIES || |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 453 | (pc->flags & PC_FLAG_ABORT)) { |
Tejun Heo | b3071d1 | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 454 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | /* |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 456 | * We will "abort" retrying a packet command in case legitimate |
| 457 | * error code was received (crossing a filemark, or end of the |
| 458 | * media, for example). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | */ |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 460 | if (!(pc->flags & PC_FLAG_ABORT)) { |
Borislav Petkov | 90699ce | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 461 | if (!(pc->c[0] == TEST_UNIT_READY && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | tape->sense_key == 2 && tape->asc == 4 && |
| 463 | (tape->ascq == 1 || tape->ascq == 8))) { |
| 464 | printk(KERN_ERR "ide-tape: %s: I/O error, " |
| 465 | "pc = %2x, key = %2x, " |
| 466 | "asc = %2x, ascq = %2x\n", |
| 467 | tape->name, pc->c[0], |
| 468 | tape->sense_key, tape->asc, |
| 469 | tape->ascq); |
| 470 | } |
| 471 | /* Giving up */ |
Bartlomiej Zolnierkiewicz | c152cc1 | 2009-03-27 12:46:34 +0100 | [diff] [blame] | 472 | pc->error = IDE_DRV_ERROR_GENERAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | } |
Tejun Heo | b3071d1 | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 474 | |
Bartlomiej Zolnierkiewicz | 5e2040fd | 2009-03-27 12:46:34 +0100 | [diff] [blame] | 475 | drive->failed_pc = NULL; |
Bartlomiej Zolnierkiewicz | b14c721 | 2008-10-13 21:39:30 +0200 | [diff] [blame] | 476 | drive->pc_callback(drive, 0); |
Borislav Petkov | dfb7e62 | 2009-05-01 20:35:21 +0200 | [diff] [blame] | 477 | ide_complete_rq(drive, -EIO, blk_rq_bytes(rq)); |
Bartlomiej Zolnierkiewicz | 92f5daf | 2008-07-15 21:21:55 +0200 | [diff] [blame] | 478 | return ide_stopped; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | } |
Borislav Petkov | e972d70 | 2009-07-17 23:55:16 +0000 | [diff] [blame] | 480 | ide_debug_log(IDE_DBG_SENSE, "retry #%d, cmd: 0x%02x", pc->retries, |
| 481 | pc->c[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | |
| 483 | pc->retries++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | |
Bartlomiej Zolnierkiewicz | b788ee9 | 2009-03-27 12:46:46 +0100 | [diff] [blame] | 485 | return ide_issue_pc(drive, cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | } |
| 487 | |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 488 | /* A mode sense command is used to "sense" tape parameters. */ |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 489 | static void idetape_create_mode_sense_cmd(struct ide_atapi_pc *pc, u8 page_code) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | { |
Bartlomiej Zolnierkiewicz | 7bf7420 | 2008-10-10 22:39:37 +0200 | [diff] [blame] | 491 | ide_init_pc(pc); |
Borislav Petkov | 90699ce | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 492 | pc->c[0] = MODE_SENSE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | if (page_code != IDETAPE_BLOCK_DESCRIPTOR) |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 494 | /* DBD = 1 - Don't return block descriptors */ |
| 495 | pc->c[1] = 8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | pc->c[2] = page_code; |
| 497 | /* |
| 498 | * Changed pc->c[3] to 0 (255 will at best return unused info). |
| 499 | * |
| 500 | * For SCSI this byte is defined as subpage instead of high byte |
| 501 | * of length and some IDE drives seem to interpret it this way |
| 502 | * and return an error when 255 is used. |
| 503 | */ |
| 504 | pc->c[3] = 0; |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 505 | /* We will just discard data in that case */ |
| 506 | pc->c[4] = 255; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | if (page_code == IDETAPE_BLOCK_DESCRIPTOR) |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 508 | pc->req_xfer = 12; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | else if (page_code == IDETAPE_CAPABILITIES_PAGE) |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 510 | pc->req_xfer = 24; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | else |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 512 | pc->req_xfer = 50; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | } |
| 514 | |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 515 | static ide_startstop_t idetape_media_access_finished(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | { |
Bartlomiej Zolnierkiewicz | b73c7ee | 2008-07-23 19:55:52 +0200 | [diff] [blame] | 517 | ide_hwif_t *hwif = drive->hwif; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | idetape_tape_t *tape = drive->driver_data; |
Bartlomiej Zolnierkiewicz | 2b9efba | 2008-10-13 21:39:31 +0200 | [diff] [blame] | 519 | struct ide_atapi_pc *pc = drive->pc; |
Bartlomiej Zolnierkiewicz | 22c525b | 2008-01-25 22:17:11 +0100 | [diff] [blame] | 520 | u8 stat; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | |
Bartlomiej Zolnierkiewicz | 374e042 | 2008-07-23 19:55:56 +0200 | [diff] [blame] | 522 | stat = hwif->tp_ops->read_status(hwif); |
Bartlomiej Zolnierkiewicz | c47137a | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 523 | |
Bartlomiej Zolnierkiewicz | 3a7d248 | 2008-10-10 22:39:21 +0200 | [diff] [blame] | 524 | if (stat & ATA_DSC) { |
| 525 | if (stat & ATA_ERR) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | /* Error detected */ |
Borislav Petkov | 90699ce | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 527 | if (pc->c[0] != TEST_UNIT_READY) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | printk(KERN_ERR "ide-tape: %s: I/O error, ", |
| 529 | tape->name); |
| 530 | /* Retry operation */ |
Borislav Petkov | 6b544fc | 2009-04-19 07:00:42 +0900 | [diff] [blame] | 531 | ide_retry_pc(drive); |
Bartlomiej Zolnierkiewicz | 258ec41 | 2008-07-15 21:21:55 +0200 | [diff] [blame] | 532 | return ide_stopped; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | } |
| 534 | pc->error = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | } else { |
Bartlomiej Zolnierkiewicz | c152cc1 | 2009-03-27 12:46:34 +0100 | [diff] [blame] | 536 | pc->error = IDE_DRV_ERROR_GENERAL; |
Bartlomiej Zolnierkiewicz | 5e2040fd | 2009-03-27 12:46:34 +0100 | [diff] [blame] | 537 | drive->failed_pc = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | } |
Bartlomiej Zolnierkiewicz | b14c721 | 2008-10-13 21:39:30 +0200 | [diff] [blame] | 539 | drive->pc_callback(drive, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | return ide_stopped; |
| 541 | } |
| 542 | |
Borislav Petkov | cd2abbf | 2008-07-15 21:22:03 +0200 | [diff] [blame] | 543 | static void ide_tape_create_rw_cmd(idetape_tape_t *tape, |
Borislav Petkov | 0014c75 | 2008-07-23 19:56:00 +0200 | [diff] [blame] | 544 | struct ide_atapi_pc *pc, struct request *rq, |
| 545 | u8 opcode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | { |
Borislav Petkov | 10c0b34 | 2009-05-01 20:29:53 +0200 | [diff] [blame] | 547 | unsigned int length = blk_rq_sectors(rq) / (tape->blk_size >> 9); |
Borislav Petkov | 0014c75 | 2008-07-23 19:56:00 +0200 | [diff] [blame] | 548 | |
Bartlomiej Zolnierkiewicz | 7bf7420 | 2008-10-10 22:39:37 +0200 | [diff] [blame] | 549 | ide_init_pc(pc); |
Borislav Petkov | 860ff5e | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 550 | put_unaligned(cpu_to_be32(length), (unsigned int *) &pc->c[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | pc->c[1] = 1; |
Borislav Petkov | 19f52a7 | 2009-05-04 09:53:03 +0200 | [diff] [blame] | 552 | |
| 553 | if (blk_rq_bytes(rq) == tape->buffer_size) |
Bartlomiej Zolnierkiewicz | 5e33109 | 2008-07-15 21:21:56 +0200 | [diff] [blame] | 554 | pc->flags |= PC_FLAG_DMA_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | |
Tejun Heo | 963da55 | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 556 | if (opcode == READ_6) |
Borislav Petkov | cd2abbf | 2008-07-15 21:22:03 +0200 | [diff] [blame] | 557 | pc->c[0] = READ_6; |
Tejun Heo | 963da55 | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 558 | else if (opcode == WRITE_6) { |
Borislav Petkov | cd2abbf | 2008-07-15 21:22:03 +0200 | [diff] [blame] | 559 | pc->c[0] = WRITE_6; |
| 560 | pc->flags |= PC_FLAG_WRITING; |
Borislav Petkov | cd2abbf | 2008-07-15 21:22:03 +0200 | [diff] [blame] | 561 | } |
Borislav Petkov | 0014c75 | 2008-07-23 19:56:00 +0200 | [diff] [blame] | 562 | |
| 563 | memcpy(rq->cmd, pc->c, 12); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | } |
| 565 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | static ide_startstop_t idetape_do_request(ide_drive_t *drive, |
| 567 | struct request *rq, sector_t block) |
| 568 | { |
Bartlomiej Zolnierkiewicz | b73c7ee | 2008-07-23 19:55:52 +0200 | [diff] [blame] | 569 | ide_hwif_t *hwif = drive->hwif; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | idetape_tape_t *tape = drive->driver_data; |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 571 | struct ide_atapi_pc *pc = NULL; |
Bartlomiej Zolnierkiewicz | b788ee9 | 2009-03-27 12:46:46 +0100 | [diff] [blame] | 572 | struct ide_cmd cmd; |
Bartlomiej Zolnierkiewicz | 22c525b | 2008-01-25 22:17:11 +0100 | [diff] [blame] | 573 | u8 stat; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | |
Borislav Petkov | e972d70 | 2009-07-17 23:55:16 +0000 | [diff] [blame] | 575 | ide_debug_log(IDE_DBG_RQ, "cmd: 0x%x, sector: %llu, nr_sectors: %u", |
| 576 | rq->cmd[0], (unsigned long long)blk_rq_pos(rq), |
| 577 | blk_rq_sectors(rq)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | |
Christoph Hellwig | 4f8c951 | 2015-04-17 22:37:16 +0200 | [diff] [blame] | 579 | BUG_ON(!(rq->cmd_type == REQ_TYPE_DRV_PRIV || |
Christoph Hellwig | b0b93b4 | 2015-04-17 22:37:18 +0200 | [diff] [blame] | 580 | rq->cmd_type == REQ_TYPE_ATA_SENSE)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 582 | /* Retry a failed packet command */ |
Bartlomiej Zolnierkiewicz | 5e2040fd | 2009-03-27 12:46:34 +0100 | [diff] [blame] | 583 | if (drive->failed_pc && drive->pc->c[0] == REQUEST_SENSE) { |
| 584 | pc = drive->failed_pc; |
Bartlomiej Zolnierkiewicz | 28c7214 | 2008-07-15 21:21:59 +0200 | [diff] [blame] | 585 | goto out; |
| 586 | } |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 587 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | /* |
| 589 | * If the tape is still busy, postpone our request and service |
| 590 | * the other device meanwhile. |
| 591 | */ |
Bartlomiej Zolnierkiewicz | 374e042 | 2008-07-23 19:55:56 +0200 | [diff] [blame] | 592 | stat = hwif->tp_ops->read_status(hwif); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame] | 594 | if ((drive->dev_flags & IDE_DFLAG_DSC_OVERLAP) == 0 && |
| 595 | (rq->cmd[13] & REQ_IDETAPE_PC2) == 0) |
Borislav Petkov | 626542c | 2009-06-07 15:37:05 +0200 | [diff] [blame] | 596 | drive->atapi_flags |= IDE_AFLAG_IGNORE_DSC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame] | 598 | if (drive->dev_flags & IDE_DFLAG_POST_RESET) { |
Borislav Petkov | 626542c | 2009-06-07 15:37:05 +0200 | [diff] [blame] | 599 | drive->atapi_flags |= IDE_AFLAG_IGNORE_DSC; |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame] | 600 | drive->dev_flags &= ~IDE_DFLAG_POST_RESET; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | } |
| 602 | |
Borislav Petkov | 626542c | 2009-06-07 15:37:05 +0200 | [diff] [blame] | 603 | if (!(drive->atapi_flags & IDE_AFLAG_IGNORE_DSC) && |
| 604 | !(stat & ATA_DSC)) { |
Borislav Petkov | 6f3848a | 2009-07-21 23:08:23 -0700 | [diff] [blame] | 605 | if (!tape->postponed_rq) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | tape->dsc_polling_start = jiffies; |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 607 | tape->dsc_poll_freq = tape->best_dsc_rw_freq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | tape->dsc_timeout = jiffies + IDETAPE_DSC_RW_TIMEOUT; |
| 609 | } else if (time_after(jiffies, tape->dsc_timeout)) { |
| 610 | printk(KERN_ERR "ide-tape: %s: DSC timeout\n", |
| 611 | tape->name); |
Borislav Petkov | 83dd573 | 2008-07-23 19:56:00 +0200 | [diff] [blame] | 612 | if (rq->cmd[13] & REQ_IDETAPE_PC2) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | idetape_media_access_finished(drive); |
| 614 | return ide_stopped; |
| 615 | } else { |
| 616 | return ide_do_reset(drive); |
| 617 | } |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 618 | } else if (time_after(jiffies, |
| 619 | tape->dsc_polling_start + |
| 620 | IDETAPE_DSC_MA_THRESHOLD)) |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 621 | tape->dsc_poll_freq = IDETAPE_DSC_MA_SLOW; |
Borislav Petkov | 6f3848a | 2009-07-21 23:08:23 -0700 | [diff] [blame] | 622 | ide_tape_stall_queue(drive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | return ide_stopped; |
Borislav Petkov | 6f3848a | 2009-07-21 23:08:23 -0700 | [diff] [blame] | 624 | } else { |
Borislav Petkov | 626542c | 2009-06-07 15:37:05 +0200 | [diff] [blame] | 625 | drive->atapi_flags &= ~IDE_AFLAG_IGNORE_DSC; |
Borislav Petkov | 6f3848a | 2009-07-21 23:08:23 -0700 | [diff] [blame] | 626 | tape->postponed_rq = false; |
| 627 | } |
Borislav Petkov | 626542c | 2009-06-07 15:37:05 +0200 | [diff] [blame] | 628 | |
Borislav Petkov | 83dd573 | 2008-07-23 19:56:00 +0200 | [diff] [blame] | 629 | if (rq->cmd[13] & REQ_IDETAPE_READ) { |
Bartlomiej Zolnierkiewicz | 2e8a6f8 | 2008-10-10 22:39:36 +0200 | [diff] [blame] | 630 | pc = &tape->queued_pc; |
Borislav Petkov | 0014c75 | 2008-07-23 19:56:00 +0200 | [diff] [blame] | 631 | ide_tape_create_rw_cmd(tape, pc, rq, READ_6); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | goto out; |
| 633 | } |
Borislav Petkov | 83dd573 | 2008-07-23 19:56:00 +0200 | [diff] [blame] | 634 | if (rq->cmd[13] & REQ_IDETAPE_WRITE) { |
Bartlomiej Zolnierkiewicz | 2e8a6f8 | 2008-10-10 22:39:36 +0200 | [diff] [blame] | 635 | pc = &tape->queued_pc; |
Borislav Petkov | 0014c75 | 2008-07-23 19:56:00 +0200 | [diff] [blame] | 636 | ide_tape_create_rw_cmd(tape, pc, rq, WRITE_6); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | goto out; |
| 638 | } |
Borislav Petkov | 83dd573 | 2008-07-23 19:56:00 +0200 | [diff] [blame] | 639 | if (rq->cmd[13] & REQ_IDETAPE_PC1) { |
Tejun Heo | c267cc1 | 2009-04-19 07:00:42 +0900 | [diff] [blame] | 640 | pc = (struct ide_atapi_pc *)rq->special; |
Borislav Petkov | 83dd573 | 2008-07-23 19:56:00 +0200 | [diff] [blame] | 641 | rq->cmd[13] &= ~(REQ_IDETAPE_PC1); |
| 642 | rq->cmd[13] |= REQ_IDETAPE_PC2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | goto out; |
| 644 | } |
Borislav Petkov | 83dd573 | 2008-07-23 19:56:00 +0200 | [diff] [blame] | 645 | if (rq->cmd[13] & REQ_IDETAPE_PC2) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | idetape_media_access_finished(drive); |
| 647 | return ide_stopped; |
| 648 | } |
| 649 | BUG(); |
Bartlomiej Zolnierkiewicz | 28c7214 | 2008-07-15 21:21:59 +0200 | [diff] [blame] | 650 | |
Borislav Petkov | f2e3ab5 | 2008-07-23 19:56:01 +0200 | [diff] [blame] | 651 | out: |
Borislav Petkov | 6b544fc | 2009-04-19 07:00:42 +0900 | [diff] [blame] | 652 | /* prepare sense request for this command */ |
| 653 | ide_prep_sense(drive, rq); |
| 654 | |
Bartlomiej Zolnierkiewicz | b788ee9 | 2009-03-27 12:46:46 +0100 | [diff] [blame] | 655 | memset(&cmd, 0, sizeof(cmd)); |
| 656 | |
| 657 | if (rq_data_dir(rq)) |
| 658 | cmd.tf_flags |= IDE_TFLAG_WRITE; |
| 659 | |
| 660 | cmd.rq = rq; |
| 661 | |
Borislav Petkov | dfb7e62 | 2009-05-01 20:35:21 +0200 | [diff] [blame] | 662 | ide_init_sg_cmd(&cmd, blk_rq_bytes(rq)); |
Tejun Heo | 5c4be57 | 2009-04-19 07:00:42 +0900 | [diff] [blame] | 663 | ide_map_sg(drive, &cmd); |
| 664 | |
Bartlomiej Zolnierkiewicz | b788ee9 | 2009-03-27 12:46:46 +0100 | [diff] [blame] | 665 | return ide_tape_issue_pc(drive, &cmd, pc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | } |
| 667 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | /* |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 669 | * Write a filemark if write_filemark=1. Flush the device buffers without |
| 670 | * writing a filemark otherwise. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | */ |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 672 | static void idetape_create_write_filemark_cmd(ide_drive_t *drive, |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 673 | struct ide_atapi_pc *pc, int write_filemark) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | { |
Bartlomiej Zolnierkiewicz | 7bf7420 | 2008-10-10 22:39:37 +0200 | [diff] [blame] | 675 | ide_init_pc(pc); |
Borislav Petkov | 90699ce | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 676 | pc->c[0] = WRITE_FILEMARKS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | pc->c[4] = write_filemark; |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 678 | pc->flags |= PC_FLAG_WAIT_FOR_DSC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | } |
| 680 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | static int idetape_wait_ready(ide_drive_t *drive, unsigned long timeout) |
| 682 | { |
| 683 | idetape_tape_t *tape = drive->driver_data; |
Bartlomiej Zolnierkiewicz | 2ac07d9 | 2008-10-10 22:39:38 +0200 | [diff] [blame] | 684 | struct gendisk *disk = tape->disk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | int load_attempted = 0; |
| 686 | |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 687 | /* Wait for the tape to become ready */ |
Borislav Petkov | 49d8078 | 2009-06-07 15:37:06 +0200 | [diff] [blame] | 688 | set_bit(ilog2(IDE_AFLAG_MEDIUM_PRESENT), &drive->atapi_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | timeout += jiffies; |
| 690 | while (time_before(jiffies, timeout)) { |
Bartlomiej Zolnierkiewicz | de699ad | 2008-10-10 22:39:39 +0200 | [diff] [blame] | 691 | if (ide_do_test_unit_ready(drive, disk) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | return 0; |
| 693 | if ((tape->sense_key == 2 && tape->asc == 4 && tape->ascq == 2) |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 694 | || (tape->asc == 0x3A)) { |
| 695 | /* no media */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | if (load_attempted) |
| 697 | return -ENOMEDIUM; |
Bartlomiej Zolnierkiewicz | 0c8a6c7 | 2008-10-10 22:39:39 +0200 | [diff] [blame] | 698 | ide_do_start_stop(drive, disk, IDETAPE_LU_LOAD_MASK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | load_attempted = 1; |
| 700 | /* not about to be ready */ |
| 701 | } else if (!(tape->sense_key == 2 && tape->asc == 4 && |
| 702 | (tape->ascq == 1 || tape->ascq == 8))) |
| 703 | return -EIO; |
Nishanth Aravamudan | 80ce45f | 2005-09-10 00:27:08 -0700 | [diff] [blame] | 704 | msleep(100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | } |
| 706 | return -EIO; |
| 707 | } |
| 708 | |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 709 | static int idetape_flush_tape_buffers(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | { |
Bartlomiej Zolnierkiewicz | 2ac07d9 | 2008-10-10 22:39:38 +0200 | [diff] [blame] | 711 | struct ide_tape_obj *tape = drive->driver_data; |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 712 | struct ide_atapi_pc pc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | int rc; |
| 714 | |
| 715 | idetape_create_write_filemark_cmd(drive, &pc, 0); |
Borislav Petkov | b13345f | 2009-05-02 10:26:12 +0200 | [diff] [blame] | 716 | rc = ide_queue_pc_tail(drive, tape->disk, &pc, NULL, 0); |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 717 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | return rc; |
| 719 | idetape_wait_ready(drive, 60 * 5 * HZ); |
| 720 | return 0; |
| 721 | } |
| 722 | |
Borislav Petkov | 55ce3a1 | 2009-05-04 09:38:15 +0200 | [diff] [blame] | 723 | static int ide_tape_read_position(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | { |
| 725 | idetape_tape_t *tape = drive->driver_data; |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 726 | struct ide_atapi_pc pc; |
Borislav Petkov | 55ce3a1 | 2009-05-04 09:38:15 +0200 | [diff] [blame] | 727 | u8 buf[20]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | |
Borislav Petkov | e972d70 | 2009-07-17 23:55:16 +0000 | [diff] [blame] | 729 | ide_debug_log(IDE_DBG_FUNC, "enter"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | |
Borislav Petkov | 55ce3a1 | 2009-05-04 09:38:15 +0200 | [diff] [blame] | 731 | /* prep cmd */ |
| 732 | ide_init_pc(&pc); |
| 733 | pc.c[0] = READ_POSITION; |
| 734 | pc.req_xfer = 20; |
| 735 | |
| 736 | if (ide_queue_pc_tail(drive, tape->disk, &pc, buf, pc.req_xfer)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | return -1; |
Borislav Petkov | 55ce3a1 | 2009-05-04 09:38:15 +0200 | [diff] [blame] | 738 | |
| 739 | if (!pc.error) { |
Borislav Petkov | e972d70 | 2009-07-17 23:55:16 +0000 | [diff] [blame] | 740 | ide_debug_log(IDE_DBG_FUNC, "BOP - %s", |
Borislav Petkov | 55ce3a1 | 2009-05-04 09:38:15 +0200 | [diff] [blame] | 741 | (buf[0] & 0x80) ? "Yes" : "No"); |
Borislav Petkov | e972d70 | 2009-07-17 23:55:16 +0000 | [diff] [blame] | 742 | ide_debug_log(IDE_DBG_FUNC, "EOP - %s", |
Borislav Petkov | 55ce3a1 | 2009-05-04 09:38:15 +0200 | [diff] [blame] | 743 | (buf[0] & 0x40) ? "Yes" : "No"); |
| 744 | |
| 745 | if (buf[0] & 0x4) { |
| 746 | printk(KERN_INFO "ide-tape: Block location is unknown" |
| 747 | "to the tape\n"); |
Bartlomiej Zolnierkiewicz | 8dcce40 | 2009-06-13 12:00:54 +0200 | [diff] [blame] | 748 | clear_bit(ilog2(IDE_AFLAG_ADDRESS_VALID), |
| 749 | &drive->atapi_flags); |
Borislav Petkov | 55ce3a1 | 2009-05-04 09:38:15 +0200 | [diff] [blame] | 750 | return -1; |
| 751 | } else { |
Borislav Petkov | e972d70 | 2009-07-17 23:55:16 +0000 | [diff] [blame] | 752 | ide_debug_log(IDE_DBG_FUNC, "Block Location: %u", |
| 753 | be32_to_cpup((__be32 *)&buf[4])); |
Borislav Petkov | 55ce3a1 | 2009-05-04 09:38:15 +0200 | [diff] [blame] | 754 | |
| 755 | tape->partition = buf[1]; |
| 756 | tape->first_frame = be32_to_cpup((__be32 *)&buf[4]); |
Bartlomiej Zolnierkiewicz | 8dcce40 | 2009-06-13 12:00:54 +0200 | [diff] [blame] | 757 | set_bit(ilog2(IDE_AFLAG_ADDRESS_VALID), |
| 758 | &drive->atapi_flags); |
Borislav Petkov | 55ce3a1 | 2009-05-04 09:38:15 +0200 | [diff] [blame] | 759 | } |
| 760 | } |
| 761 | |
| 762 | return tape->first_frame; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | } |
| 764 | |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 765 | static void idetape_create_locate_cmd(ide_drive_t *drive, |
| 766 | struct ide_atapi_pc *pc, |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 767 | unsigned int block, u8 partition, int skip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | { |
Bartlomiej Zolnierkiewicz | 7bf7420 | 2008-10-10 22:39:37 +0200 | [diff] [blame] | 769 | ide_init_pc(pc); |
Borislav Petkov | 90699ce | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 770 | pc->c[0] = POSITION_TO_ELEMENT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | pc->c[1] = 2; |
Borislav Petkov | 860ff5e | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 772 | put_unaligned(cpu_to_be32(block), (unsigned int *) &pc->c[3]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | pc->c[8] = partition; |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 774 | pc->flags |= PC_FLAG_WAIT_FOR_DSC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | } |
| 776 | |
Borislav Petkov | ec0fdb0 | 2008-04-27 15:38:34 +0200 | [diff] [blame] | 777 | static void __ide_tape_discard_merge_buffer(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | { |
| 779 | idetape_tape_t *tape = drive->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | |
Borislav Petkov | 54abf37 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 781 | if (tape->chrdev_dir != IDETAPE_DIR_READ) |
Borislav Petkov | 9798630 | 2008-04-27 15:38:34 +0200 | [diff] [blame] | 782 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | |
Borislav Petkov | 49d8078 | 2009-06-07 15:37:06 +0200 | [diff] [blame] | 784 | clear_bit(ilog2(IDE_AFLAG_FILEMARK), &drive->atapi_flags); |
Tejun Heo | 963da55 | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 785 | tape->valid = 0; |
| 786 | if (tape->buf != NULL) { |
| 787 | kfree(tape->buf); |
| 788 | tape->buf = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | } |
| 790 | |
Borislav Petkov | 54abf37 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 791 | tape->chrdev_dir = IDETAPE_DIR_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 | } |
| 793 | |
| 794 | /* |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 795 | * Position the tape to the requested block using the LOCATE packet command. |
| 796 | * A READ POSITION command is then issued to check where we are positioned. Like |
| 797 | * all higher level operations, we queue the commands at the tail of the request |
| 798 | * queue and wait for their completion. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | */ |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 800 | static int idetape_position_tape(ide_drive_t *drive, unsigned int block, |
| 801 | u8 partition, int skip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | { |
| 803 | idetape_tape_t *tape = drive->driver_data; |
Bartlomiej Zolnierkiewicz | 2ac07d9 | 2008-10-10 22:39:38 +0200 | [diff] [blame] | 804 | struct gendisk *disk = tape->disk; |
Borislav Petkov | 55ce3a1 | 2009-05-04 09:38:15 +0200 | [diff] [blame] | 805 | int ret; |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 806 | struct ide_atapi_pc pc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | |
Borislav Petkov | 54abf37 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 808 | if (tape->chrdev_dir == IDETAPE_DIR_READ) |
Borislav Petkov | ec0fdb0 | 2008-04-27 15:38:34 +0200 | [diff] [blame] | 809 | __ide_tape_discard_merge_buffer(drive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | idetape_wait_ready(drive, 60 * 5 * HZ); |
| 811 | idetape_create_locate_cmd(drive, &pc, block, partition, skip); |
Borislav Petkov | 55ce3a1 | 2009-05-04 09:38:15 +0200 | [diff] [blame] | 812 | ret = ide_queue_pc_tail(drive, disk, &pc, NULL, 0); |
| 813 | if (ret) |
| 814 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | |
Borislav Petkov | 55ce3a1 | 2009-05-04 09:38:15 +0200 | [diff] [blame] | 816 | ret = ide_tape_read_position(drive); |
| 817 | if (ret < 0) |
| 818 | return ret; |
| 819 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | } |
| 821 | |
Borislav Petkov | ec0fdb0 | 2008-04-27 15:38:34 +0200 | [diff] [blame] | 822 | static void ide_tape_discard_merge_buffer(ide_drive_t *drive, |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 823 | int restore_position) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | { |
| 825 | idetape_tape_t *tape = drive->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | int seek, position; |
| 827 | |
Borislav Petkov | ec0fdb0 | 2008-04-27 15:38:34 +0200 | [diff] [blame] | 828 | __ide_tape_discard_merge_buffer(drive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | if (restore_position) { |
Borislav Petkov | 55ce3a1 | 2009-05-04 09:38:15 +0200 | [diff] [blame] | 830 | position = ide_tape_read_position(drive); |
Borislav Petkov | 9798630 | 2008-04-27 15:38:34 +0200 | [diff] [blame] | 831 | seek = position > 0 ? position : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | if (idetape_position_tape(drive, seek, 0, 0)) { |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 833 | printk(KERN_INFO "ide-tape: %s: position_tape failed in" |
Borislav Petkov | ec0fdb0 | 2008-04-27 15:38:34 +0200 | [diff] [blame] | 834 | " %s\n", tape->name, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | return; |
| 836 | } |
| 837 | } |
| 838 | } |
| 839 | |
| 840 | /* |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 841 | * Generate a read/write request for the block device interface and wait for it |
| 842 | * to be serviced. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | */ |
Tejun Heo | 6bb11dd | 2009-04-19 08:46:03 +0900 | [diff] [blame] | 844 | static int idetape_queue_rw_tail(ide_drive_t *drive, int cmd, int size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | { |
| 846 | idetape_tape_t *tape = drive->driver_data; |
FUJITA Tomonori | 64ea1b4 | 2008-07-15 21:21:43 +0200 | [diff] [blame] | 847 | struct request *rq; |
Tejun Heo | 21d9c5d | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 848 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | |
Borislav Petkov | e972d70 | 2009-07-17 23:55:16 +0000 | [diff] [blame] | 850 | ide_debug_log(IDE_DBG_FUNC, "cmd: 0x%x, size: %d", cmd, size); |
| 851 | |
Tejun Heo | 21d9c5d | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 852 | BUG_ON(cmd != REQ_IDETAPE_READ && cmd != REQ_IDETAPE_WRITE); |
Tejun Heo | 6bb11dd | 2009-04-19 08:46:03 +0900 | [diff] [blame] | 853 | BUG_ON(size < 0 || size % tape->blk_size); |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 854 | |
FUJITA Tomonori | 64ea1b4 | 2008-07-15 21:21:43 +0200 | [diff] [blame] | 855 | rq = blk_get_request(drive->queue, READ, __GFP_WAIT); |
Christoph Hellwig | 4f8c951 | 2015-04-17 22:37:16 +0200 | [diff] [blame] | 856 | rq->cmd_type = REQ_TYPE_DRV_PRIV; |
Borislav Petkov | 83dd573 | 2008-07-23 19:56:00 +0200 | [diff] [blame] | 857 | rq->cmd[13] = cmd; |
FUJITA Tomonori | 64ea1b4 | 2008-07-15 21:21:43 +0200 | [diff] [blame] | 858 | rq->rq_disk = tape->disk; |
Linus Torvalds | c905959 | 2009-06-11 10:52:27 -0700 | [diff] [blame] | 859 | rq->__sector = tape->first_frame; |
Tejun Heo | 21d9c5d | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 860 | |
| 861 | if (size) { |
Tejun Heo | 963da55 | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 862 | ret = blk_rq_map_kern(drive->queue, rq, tape->buf, size, |
Tejun Heo | 21d9c5d | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 863 | __GFP_WAIT); |
| 864 | if (ret) |
| 865 | goto out_put; |
| 866 | } |
| 867 | |
FUJITA Tomonori | 64ea1b4 | 2008-07-15 21:21:43 +0200 | [diff] [blame] | 868 | blk_execute_rq(drive->queue, tape->disk, rq, 0); |
| 869 | |
Tejun Heo | 963da55 | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 870 | /* calculate the number of transferred bytes and update buffer state */ |
Tejun Heo | c3a4d78 | 2009-05-07 22:24:37 +0900 | [diff] [blame] | 871 | size -= rq->resid_len; |
Tejun Heo | 963da55 | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 872 | tape->cur = tape->buf; |
Tejun Heo | 21d9c5d | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 873 | if (cmd == REQ_IDETAPE_READ) |
Tejun Heo | 963da55 | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 874 | tape->valid = size; |
| 875 | else |
| 876 | tape->valid = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 | |
Tejun Heo | 21d9c5d | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 878 | ret = size; |
| 879 | if (rq->errors == IDE_DRV_ERROR_GENERAL) |
| 880 | ret = -EIO; |
Tejun Heo | 21d9c5d | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 881 | out_put: |
| 882 | blk_put_request(rq); |
FUJITA Tomonori | 64ea1b4 | 2008-07-15 21:21:43 +0200 | [diff] [blame] | 883 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | } |
| 885 | |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 886 | static void idetape_create_inquiry_cmd(struct ide_atapi_pc *pc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | { |
Bartlomiej Zolnierkiewicz | 7bf7420 | 2008-10-10 22:39:37 +0200 | [diff] [blame] | 888 | ide_init_pc(pc); |
Borislav Petkov | 90699ce | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 889 | pc->c[0] = INQUIRY; |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 890 | pc->c[4] = 254; |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 891 | pc->req_xfer = 254; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | } |
| 893 | |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 894 | static void idetape_create_rewind_cmd(ide_drive_t *drive, |
| 895 | struct ide_atapi_pc *pc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | { |
Bartlomiej Zolnierkiewicz | 7bf7420 | 2008-10-10 22:39:37 +0200 | [diff] [blame] | 897 | ide_init_pc(pc); |
Borislav Petkov | 90699ce | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 898 | pc->c[0] = REZERO_UNIT; |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 899 | pc->flags |= PC_FLAG_WAIT_FOR_DSC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | } |
| 901 | |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 902 | static void idetape_create_erase_cmd(struct ide_atapi_pc *pc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | { |
Bartlomiej Zolnierkiewicz | 7bf7420 | 2008-10-10 22:39:37 +0200 | [diff] [blame] | 904 | ide_init_pc(pc); |
Borislav Petkov | 90699ce | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 905 | pc->c[0] = ERASE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 | pc->c[1] = 1; |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 907 | pc->flags |= PC_FLAG_WAIT_FOR_DSC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | } |
| 909 | |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 910 | static void idetape_create_space_cmd(struct ide_atapi_pc *pc, int count, u8 cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 | { |
Bartlomiej Zolnierkiewicz | 7bf7420 | 2008-10-10 22:39:37 +0200 | [diff] [blame] | 912 | ide_init_pc(pc); |
Borislav Petkov | 90699ce | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 913 | pc->c[0] = SPACE; |
Borislav Petkov | 860ff5e | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 914 | put_unaligned(cpu_to_be32(count), (unsigned int *) &pc->c[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | pc->c[1] = cmd; |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 916 | pc->flags |= PC_FLAG_WAIT_FOR_DSC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 917 | } |
| 918 | |
Borislav Petkov | d9df937 | 2008-04-27 15:38:34 +0200 | [diff] [blame] | 919 | static void ide_tape_flush_merge_buffer(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | { |
| 921 | idetape_tape_t *tape = drive->driver_data; |
Borislav Petkov | 55a5d29 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 922 | |
Borislav Petkov | 54abf37 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 923 | if (tape->chrdev_dir != IDETAPE_DIR_WRITE) { |
Borislav Petkov | 077e3bd | 2008-04-27 15:38:34 +0200 | [diff] [blame] | 924 | printk(KERN_ERR "ide-tape: bug: Trying to empty merge buffer" |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 925 | " but we are not writing.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 926 | return; |
| 927 | } |
Tejun Heo | 963da55 | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 928 | if (tape->buf) { |
Tejun Heo | 6bb11dd | 2009-04-19 08:46:03 +0900 | [diff] [blame] | 929 | size_t aligned = roundup(tape->valid, tape->blk_size); |
| 930 | |
| 931 | memset(tape->cur, 0, aligned - tape->valid); |
Tejun Heo | 07bd968 | 2009-04-19 08:46:03 +0900 | [diff] [blame] | 932 | idetape_queue_rw_tail(drive, REQ_IDETAPE_WRITE, aligned); |
Tejun Heo | 963da55 | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 933 | kfree(tape->buf); |
| 934 | tape->buf = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | } |
Borislav Petkov | 54abf37 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 936 | tape->chrdev_dir = IDETAPE_DIR_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | } |
| 938 | |
Tejun Heo | 88f1b94 | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 939 | static int idetape_init_rw(ide_drive_t *drive, int dir) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | { |
| 941 | idetape_tape_t *tape = drive->driver_data; |
Tejun Heo | 88f1b94 | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 942 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 943 | |
Tejun Heo | 88f1b94 | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 944 | BUG_ON(dir != IDETAPE_DIR_READ && dir != IDETAPE_DIR_WRITE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 945 | |
Tejun Heo | 88f1b94 | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 946 | if (tape->chrdev_dir == dir) |
| 947 | return 0; |
| 948 | |
| 949 | if (tape->chrdev_dir == IDETAPE_DIR_READ) |
| 950 | ide_tape_discard_merge_buffer(drive, 1); |
| 951 | else if (tape->chrdev_dir == IDETAPE_DIR_WRITE) { |
| 952 | ide_tape_flush_merge_buffer(drive); |
| 953 | idetape_flush_tape_buffers(drive); |
| 954 | } |
| 955 | |
| 956 | if (tape->buf || tape->valid) { |
| 957 | printk(KERN_ERR "ide-tape: valid should be 0 now\n"); |
| 958 | tape->valid = 0; |
| 959 | } |
| 960 | |
| 961 | tape->buf = kmalloc(tape->buffer_size, GFP_KERNEL); |
| 962 | if (!tape->buf) |
| 963 | return -ENOMEM; |
| 964 | tape->chrdev_dir = dir; |
| 965 | tape->cur = tape->buf; |
| 966 | |
| 967 | /* |
| 968 | * Issue a 0 rw command to ensure that DSC handshake is |
| 969 | * switched from completion mode to buffer available mode. No |
| 970 | * point in issuing this if DSC overlap isn't supported, some |
| 971 | * drives (Seagate STT3401A) will return an error. |
| 972 | */ |
| 973 | if (drive->dev_flags & IDE_DFLAG_DSC_OVERLAP) { |
| 974 | int cmd = dir == IDETAPE_DIR_READ ? REQ_IDETAPE_READ |
| 975 | : REQ_IDETAPE_WRITE; |
| 976 | |
| 977 | rc = idetape_queue_rw_tail(drive, cmd, 0); |
| 978 | if (rc < 0) { |
| 979 | kfree(tape->buf); |
| 980 | tape->buf = NULL; |
| 981 | tape->chrdev_dir = IDETAPE_DIR_NONE; |
| 982 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 983 | } |
| 984 | } |
Borislav Petkov | 5e69bd9 | 2008-04-27 15:38:25 +0200 | [diff] [blame] | 985 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 986 | return 0; |
| 987 | } |
| 988 | |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 989 | static void idetape_pad_zeros(ide_drive_t *drive, int bcount) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | { |
| 991 | idetape_tape_t *tape = drive->driver_data; |
Tejun Heo | 963da55 | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 992 | |
| 993 | memset(tape->buf, 0, tape->buffer_size); |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 994 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | while (bcount) { |
Tejun Heo | 963da55 | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 996 | unsigned int count = min(tape->buffer_size, bcount); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 997 | |
Tejun Heo | 6bb11dd | 2009-04-19 08:46:03 +0900 | [diff] [blame] | 998 | idetape_queue_rw_tail(drive, REQ_IDETAPE_WRITE, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 999 | bcount -= count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1000 | } |
| 1001 | } |
| 1002 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1003 | /* |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 1004 | * Rewinds the tape to the Beginning Of the current Partition (BOP). We |
| 1005 | * currently support only one partition. |
| 1006 | */ |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1007 | static int idetape_rewind_tape(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1008 | { |
Bartlomiej Zolnierkiewicz | 2ac07d9 | 2008-10-10 22:39:38 +0200 | [diff] [blame] | 1009 | struct ide_tape_obj *tape = drive->driver_data; |
| 1010 | struct gendisk *disk = tape->disk; |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1011 | struct ide_atapi_pc pc; |
Borislav Petkov | 55ce3a1 | 2009-05-04 09:38:15 +0200 | [diff] [blame] | 1012 | int ret; |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 1013 | |
Borislav Petkov | e972d70 | 2009-07-17 23:55:16 +0000 | [diff] [blame] | 1014 | ide_debug_log(IDE_DBG_FUNC, "enter"); |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 1015 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1016 | idetape_create_rewind_cmd(drive, &pc); |
Borislav Petkov | 55ce3a1 | 2009-05-04 09:38:15 +0200 | [diff] [blame] | 1017 | ret = ide_queue_pc_tail(drive, disk, &pc, NULL, 0); |
| 1018 | if (ret) |
| 1019 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1020 | |
Borislav Petkov | 55ce3a1 | 2009-05-04 09:38:15 +0200 | [diff] [blame] | 1021 | ret = ide_tape_read_position(drive); |
| 1022 | if (ret < 0) |
| 1023 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1024 | return 0; |
| 1025 | } |
| 1026 | |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 1027 | /* mtio.h compatible commands should be issued to the chrdev interface. */ |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1028 | static int idetape_blkdev_ioctl(ide_drive_t *drive, unsigned int cmd, |
| 1029 | unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | { |
| 1031 | idetape_tape_t *tape = drive->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1032 | void __user *argp = (void __user *)arg; |
| 1033 | |
Borislav Petkov | d59823f | 2008-02-02 19:56:51 +0100 | [diff] [blame] | 1034 | struct idetape_config { |
| 1035 | int dsc_rw_frequency; |
| 1036 | int dsc_media_access_frequency; |
| 1037 | int nr_stages; |
| 1038 | } config; |
| 1039 | |
Borislav Petkov | e972d70 | 2009-07-17 23:55:16 +0000 | [diff] [blame] | 1040 | ide_debug_log(IDE_DBG_FUNC, "cmd: 0x%04x", cmd); |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 1041 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1042 | switch (cmd) { |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1043 | case 0x0340: |
| 1044 | if (copy_from_user(&config, argp, sizeof(config))) |
| 1045 | return -EFAULT; |
| 1046 | tape->best_dsc_rw_freq = config.dsc_rw_frequency; |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1047 | break; |
| 1048 | case 0x0350: |
Michael Buesch | 2fc2111 | 2009-07-19 09:15:19 +0000 | [diff] [blame] | 1049 | memset(&config, 0, sizeof(config)); |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1050 | config.dsc_rw_frequency = (int) tape->best_dsc_rw_freq; |
Borislav Petkov | 83042b2 | 2008-04-27 15:38:27 +0200 | [diff] [blame] | 1051 | config.nr_stages = 1; |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1052 | if (copy_to_user(argp, &config, sizeof(config))) |
| 1053 | return -EFAULT; |
| 1054 | break; |
| 1055 | default: |
| 1056 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1057 | } |
| 1058 | return 0; |
| 1059 | } |
| 1060 | |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1061 | static int idetape_space_over_filemarks(ide_drive_t *drive, short mt_op, |
| 1062 | int mt_count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1063 | { |
| 1064 | idetape_tape_t *tape = drive->driver_data; |
Bartlomiej Zolnierkiewicz | 2ac07d9 | 2008-10-10 22:39:38 +0200 | [diff] [blame] | 1065 | struct gendisk *disk = tape->disk; |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1066 | struct ide_atapi_pc pc; |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1067 | int retval, count = 0; |
Borislav Petkov | b642201 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 1068 | int sprev = !!(tape->caps[4] & 0x20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1069 | |
Borislav Petkov | e972d70 | 2009-07-17 23:55:16 +0000 | [diff] [blame] | 1070 | |
| 1071 | ide_debug_log(IDE_DBG_FUNC, "mt_op: %d, mt_count: %d", mt_op, mt_count); |
| 1072 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1073 | if (mt_count == 0) |
| 1074 | return 0; |
| 1075 | if (MTBSF == mt_op || MTBSFM == mt_op) { |
Borislav Petkov | b642201 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 1076 | if (!sprev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1077 | return -EIO; |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1078 | mt_count = -mt_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1079 | } |
| 1080 | |
Borislav Petkov | 54abf37 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1081 | if (tape->chrdev_dir == IDETAPE_DIR_READ) { |
Tejun Heo | 963da55 | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 1082 | tape->valid = 0; |
Borislav Petkov | 49d8078 | 2009-06-07 15:37:06 +0200 | [diff] [blame] | 1083 | if (test_and_clear_bit(ilog2(IDE_AFLAG_FILEMARK), |
| 1084 | &drive->atapi_flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1085 | ++count; |
Borislav Petkov | ec0fdb0 | 2008-04-27 15:38:34 +0200 | [diff] [blame] | 1086 | ide_tape_discard_merge_buffer(drive, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1087 | } |
| 1088 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1089 | switch (mt_op) { |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1090 | case MTFSF: |
| 1091 | case MTBSF: |
| 1092 | idetape_create_space_cmd(&pc, mt_count - count, |
| 1093 | IDETAPE_SPACE_OVER_FILEMARK); |
Borislav Petkov | b13345f | 2009-05-02 10:26:12 +0200 | [diff] [blame] | 1094 | return ide_queue_pc_tail(drive, disk, &pc, NULL, 0); |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1095 | case MTFSFM: |
| 1096 | case MTBSFM: |
| 1097 | if (!sprev) |
| 1098 | return -EIO; |
| 1099 | retval = idetape_space_over_filemarks(drive, MTFSF, |
| 1100 | mt_count - count); |
| 1101 | if (retval) |
| 1102 | return retval; |
| 1103 | count = (MTBSFM == mt_op ? 1 : -1); |
| 1104 | return idetape_space_over_filemarks(drive, MTFSF, count); |
| 1105 | default: |
| 1106 | printk(KERN_ERR "ide-tape: MTIO operation %d not supported\n", |
| 1107 | mt_op); |
| 1108 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1109 | } |
| 1110 | } |
| 1111 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1112 | /* |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 1113 | * Our character device read / write functions. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1114 | * |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 1115 | * The tape is optimized to maximize throughput when it is transferring an |
| 1116 | * integral number of the "continuous transfer limit", which is a parameter of |
| 1117 | * the specific tape (26kB on my particular tape, 32kB for Onstream). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1118 | * |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 1119 | * As of version 1.3 of the driver, the character device provides an abstract |
| 1120 | * continuous view of the media - any mix of block sizes (even 1 byte) on the |
| 1121 | * same backup/restore procedure is supported. The driver will internally |
| 1122 | * convert the requests to the recommended transfer unit, so that an unmatch |
| 1123 | * between the user's block size to the recommended size will only result in a |
| 1124 | * (slightly) increased driver overhead, but will no longer hit performance. |
| 1125 | * This is not applicable to Onstream. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1126 | */ |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1127 | static ssize_t idetape_chrdev_read(struct file *file, char __user *buf, |
| 1128 | size_t count, loff_t *ppos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1129 | { |
Borislav Petkov | 5aeddf9 | 2008-10-13 21:39:34 +0200 | [diff] [blame] | 1130 | struct ide_tape_obj *tape = file->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1131 | ide_drive_t *drive = tape->drive; |
Tejun Heo | 07bd968 | 2009-04-19 08:46:03 +0900 | [diff] [blame] | 1132 | size_t done = 0; |
Daniel Walker | dcd9637 | 2006-06-25 05:47:37 -0700 | [diff] [blame] | 1133 | ssize_t ret = 0; |
Tejun Heo | 07bd968 | 2009-04-19 08:46:03 +0900 | [diff] [blame] | 1134 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1135 | |
Borislav Petkov | e972d70 | 2009-07-17 23:55:16 +0000 | [diff] [blame] | 1136 | ide_debug_log(IDE_DBG_FUNC, "count %Zd", count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1137 | |
Borislav Petkov | 54abf37 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1138 | if (tape->chrdev_dir != IDETAPE_DIR_READ) { |
Borislav Petkov | 49d8078 | 2009-06-07 15:37:06 +0200 | [diff] [blame] | 1139 | if (test_bit(ilog2(IDE_AFLAG_DETECT_BS), &drive->atapi_flags)) |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1140 | if (count > tape->blk_size && |
| 1141 | (count % tape->blk_size) == 0) |
| 1142 | tape->user_bs_factor = count / tape->blk_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1143 | } |
Tejun Heo | 07bd968 | 2009-04-19 08:46:03 +0900 | [diff] [blame] | 1144 | |
Tejun Heo | 88f1b94 | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 1145 | rc = idetape_init_rw(drive, IDETAPE_DIR_READ); |
Borislav Petkov | 8d06bfa | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 1146 | if (rc < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1147 | return rc; |
Tejun Heo | 07bd968 | 2009-04-19 08:46:03 +0900 | [diff] [blame] | 1148 | |
| 1149 | while (done < count) { |
| 1150 | size_t todo; |
| 1151 | |
| 1152 | /* refill if staging buffer is empty */ |
| 1153 | if (!tape->valid) { |
| 1154 | /* If we are at a filemark, nothing more to read */ |
Borislav Petkov | 49d8078 | 2009-06-07 15:37:06 +0200 | [diff] [blame] | 1155 | if (test_bit(ilog2(IDE_AFLAG_FILEMARK), |
| 1156 | &drive->atapi_flags)) |
Tejun Heo | 07bd968 | 2009-04-19 08:46:03 +0900 | [diff] [blame] | 1157 | break; |
| 1158 | /* read */ |
| 1159 | if (idetape_queue_rw_tail(drive, REQ_IDETAPE_READ, |
| 1160 | tape->buffer_size) <= 0) |
| 1161 | break; |
| 1162 | } |
| 1163 | |
| 1164 | /* copy out */ |
| 1165 | todo = min_t(size_t, count - done, tape->valid); |
| 1166 | if (copy_to_user(buf + done, tape->cur, todo)) |
Daniel Walker | dcd9637 | 2006-06-25 05:47:37 -0700 | [diff] [blame] | 1167 | ret = -EFAULT; |
Tejun Heo | 07bd968 | 2009-04-19 08:46:03 +0900 | [diff] [blame] | 1168 | |
| 1169 | tape->cur += todo; |
| 1170 | tape->valid -= todo; |
| 1171 | done += todo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1172 | } |
Tejun Heo | 07bd968 | 2009-04-19 08:46:03 +0900 | [diff] [blame] | 1173 | |
Borislav Petkov | 49d8078 | 2009-06-07 15:37:06 +0200 | [diff] [blame] | 1174 | if (!done && test_bit(ilog2(IDE_AFLAG_FILEMARK), &drive->atapi_flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1175 | idetape_space_over_filemarks(drive, MTFSF, 1); |
| 1176 | return 0; |
| 1177 | } |
Daniel Walker | dcd9637 | 2006-06-25 05:47:37 -0700 | [diff] [blame] | 1178 | |
Tejun Heo | 07bd968 | 2009-04-19 08:46:03 +0900 | [diff] [blame] | 1179 | return ret ? ret : done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1180 | } |
| 1181 | |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1182 | static ssize_t idetape_chrdev_write(struct file *file, const char __user *buf, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1183 | size_t count, loff_t *ppos) |
| 1184 | { |
Borislav Petkov | 5aeddf9 | 2008-10-13 21:39:34 +0200 | [diff] [blame] | 1185 | struct ide_tape_obj *tape = file->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1186 | ide_drive_t *drive = tape->drive; |
Tejun Heo | 07bd968 | 2009-04-19 08:46:03 +0900 | [diff] [blame] | 1187 | size_t done = 0; |
Daniel Walker | dcd9637 | 2006-06-25 05:47:37 -0700 | [diff] [blame] | 1188 | ssize_t ret = 0; |
Tejun Heo | 88f1b94 | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 1189 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1190 | |
| 1191 | /* The drive is write protected. */ |
| 1192 | if (tape->write_prot) |
| 1193 | return -EACCES; |
| 1194 | |
Borislav Petkov | e972d70 | 2009-07-17 23:55:16 +0000 | [diff] [blame] | 1195 | ide_debug_log(IDE_DBG_FUNC, "count %Zd", count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1196 | |
| 1197 | /* Initialize write operation */ |
Tejun Heo | 88f1b94 | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 1198 | rc = idetape_init_rw(drive, IDETAPE_DIR_WRITE); |
| 1199 | if (rc < 0) |
| 1200 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1201 | |
Tejun Heo | 07bd968 | 2009-04-19 08:46:03 +0900 | [diff] [blame] | 1202 | while (done < count) { |
| 1203 | size_t todo; |
| 1204 | |
| 1205 | /* flush if staging buffer is full */ |
| 1206 | if (tape->valid == tape->buffer_size && |
| 1207 | idetape_queue_rw_tail(drive, REQ_IDETAPE_WRITE, |
| 1208 | tape->buffer_size) <= 0) |
| 1209 | return rc; |
| 1210 | |
| 1211 | /* copy in */ |
| 1212 | todo = min_t(size_t, count - done, |
| 1213 | tape->buffer_size - tape->valid); |
| 1214 | if (copy_from_user(tape->cur, buf + done, todo)) |
Daniel Walker | dcd9637 | 2006-06-25 05:47:37 -0700 | [diff] [blame] | 1215 | ret = -EFAULT; |
Tejun Heo | 07bd968 | 2009-04-19 08:46:03 +0900 | [diff] [blame] | 1216 | |
| 1217 | tape->cur += todo; |
| 1218 | tape->valid += todo; |
| 1219 | done += todo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1220 | } |
Tejun Heo | 07bd968 | 2009-04-19 08:46:03 +0900 | [diff] [blame] | 1221 | |
| 1222 | return ret ? ret : done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1223 | } |
| 1224 | |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1225 | static int idetape_write_filemark(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1226 | { |
Bartlomiej Zolnierkiewicz | 2ac07d9 | 2008-10-10 22:39:38 +0200 | [diff] [blame] | 1227 | struct ide_tape_obj *tape = drive->driver_data; |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1228 | struct ide_atapi_pc pc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1229 | |
| 1230 | /* Write a filemark */ |
| 1231 | idetape_create_write_filemark_cmd(drive, &pc, 1); |
Borislav Petkov | b13345f | 2009-05-02 10:26:12 +0200 | [diff] [blame] | 1232 | if (ide_queue_pc_tail(drive, tape->disk, &pc, NULL, 0)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1233 | printk(KERN_ERR "ide-tape: Couldn't write a filemark\n"); |
| 1234 | return -EIO; |
| 1235 | } |
| 1236 | return 0; |
| 1237 | } |
| 1238 | |
| 1239 | /* |
Borislav Petkov | d99c9da | 2008-02-02 19:56:51 +0100 | [diff] [blame] | 1240 | * Called from idetape_chrdev_ioctl when the general mtio MTIOCTOP ioctl is |
| 1241 | * requested. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1242 | * |
Borislav Petkov | d99c9da | 2008-02-02 19:56:51 +0100 | [diff] [blame] | 1243 | * Note: MTBSF and MTBSFM are not supported when the tape doesn't support |
| 1244 | * spacing over filemarks in the reverse direction. In this case, MTFSFM is also |
Borislav Petkov | 5bd50dc | 2008-04-27 15:38:28 +0200 | [diff] [blame] | 1245 | * usually not supported. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1246 | * |
Borislav Petkov | d99c9da | 2008-02-02 19:56:51 +0100 | [diff] [blame] | 1247 | * The following commands are currently not supported: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1248 | * |
Borislav Petkov | d99c9da | 2008-02-02 19:56:51 +0100 | [diff] [blame] | 1249 | * MTFSS, MTBSS, MTWSM, MTSETDENSITY, MTSETDRVBUFFER, MT_ST_BOOLEANS, |
| 1250 | * MT_ST_WRITE_THRESHOLD. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1251 | */ |
Borislav Petkov | d99c9da | 2008-02-02 19:56:51 +0100 | [diff] [blame] | 1252 | static int idetape_mtioctop(ide_drive_t *drive, short mt_op, int mt_count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1253 | { |
| 1254 | idetape_tape_t *tape = drive->driver_data; |
Bartlomiej Zolnierkiewicz | 2ac07d9 | 2008-10-10 22:39:38 +0200 | [diff] [blame] | 1255 | struct gendisk *disk = tape->disk; |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1256 | struct ide_atapi_pc pc; |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1257 | int i, retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1258 | |
Borislav Petkov | e972d70 | 2009-07-17 23:55:16 +0000 | [diff] [blame] | 1259 | ide_debug_log(IDE_DBG_FUNC, "MTIOCTOP ioctl: mt_op: %d, mt_count: %d", |
| 1260 | mt_op, mt_count); |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1261 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1262 | switch (mt_op) { |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1263 | case MTFSF: |
| 1264 | case MTFSFM: |
| 1265 | case MTBSF: |
| 1266 | case MTBSFM: |
| 1267 | if (!mt_count) |
| 1268 | return 0; |
| 1269 | return idetape_space_over_filemarks(drive, mt_op, mt_count); |
| 1270 | default: |
| 1271 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1272 | } |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1273 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1274 | switch (mt_op) { |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1275 | case MTWEOF: |
| 1276 | if (tape->write_prot) |
| 1277 | return -EACCES; |
Borislav Petkov | ec0fdb0 | 2008-04-27 15:38:34 +0200 | [diff] [blame] | 1278 | ide_tape_discard_merge_buffer(drive, 1); |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1279 | for (i = 0; i < mt_count; i++) { |
| 1280 | retval = idetape_write_filemark(drive); |
| 1281 | if (retval) |
| 1282 | return retval; |
| 1283 | } |
| 1284 | return 0; |
| 1285 | case MTREW: |
Borislav Petkov | ec0fdb0 | 2008-04-27 15:38:34 +0200 | [diff] [blame] | 1286 | ide_tape_discard_merge_buffer(drive, 0); |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1287 | if (idetape_rewind_tape(drive)) |
| 1288 | return -EIO; |
| 1289 | return 0; |
| 1290 | case MTLOAD: |
Borislav Petkov | ec0fdb0 | 2008-04-27 15:38:34 +0200 | [diff] [blame] | 1291 | ide_tape_discard_merge_buffer(drive, 0); |
Bartlomiej Zolnierkiewicz | 0c8a6c7 | 2008-10-10 22:39:39 +0200 | [diff] [blame] | 1292 | return ide_do_start_stop(drive, disk, IDETAPE_LU_LOAD_MASK); |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1293 | case MTUNLOAD: |
| 1294 | case MTOFFL: |
| 1295 | /* |
| 1296 | * If door is locked, attempt to unlock before |
| 1297 | * attempting to eject. |
| 1298 | */ |
| 1299 | if (tape->door_locked) { |
Bartlomiej Zolnierkiewicz | 0578042 | 2008-10-10 22:39:38 +0200 | [diff] [blame] | 1300 | if (!ide_set_media_lock(drive, disk, 0)) |
Bartlomiej Zolnierkiewicz | 385a4b8 | 2008-10-10 22:39:37 +0200 | [diff] [blame] | 1301 | tape->door_locked = DOOR_UNLOCKED; |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1302 | } |
Borislav Petkov | ec0fdb0 | 2008-04-27 15:38:34 +0200 | [diff] [blame] | 1303 | ide_tape_discard_merge_buffer(drive, 0); |
Bartlomiej Zolnierkiewicz | 0c8a6c7 | 2008-10-10 22:39:39 +0200 | [diff] [blame] | 1304 | retval = ide_do_start_stop(drive, disk, !IDETAPE_LU_LOAD_MASK); |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1305 | if (!retval) |
Borislav Petkov | 49d8078 | 2009-06-07 15:37:06 +0200 | [diff] [blame] | 1306 | clear_bit(ilog2(IDE_AFLAG_MEDIUM_PRESENT), |
| 1307 | &drive->atapi_flags); |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1308 | return retval; |
| 1309 | case MTNOP: |
Borislav Petkov | ec0fdb0 | 2008-04-27 15:38:34 +0200 | [diff] [blame] | 1310 | ide_tape_discard_merge_buffer(drive, 0); |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1311 | return idetape_flush_tape_buffers(drive); |
| 1312 | case MTRETEN: |
Borislav Petkov | ec0fdb0 | 2008-04-27 15:38:34 +0200 | [diff] [blame] | 1313 | ide_tape_discard_merge_buffer(drive, 0); |
Bartlomiej Zolnierkiewicz | 0c8a6c7 | 2008-10-10 22:39:39 +0200 | [diff] [blame] | 1314 | return ide_do_start_stop(drive, disk, |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1315 | IDETAPE_LU_RETENSION_MASK | IDETAPE_LU_LOAD_MASK); |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1316 | case MTEOM: |
| 1317 | idetape_create_space_cmd(&pc, 0, IDETAPE_SPACE_TO_EOD); |
Borislav Petkov | b13345f | 2009-05-02 10:26:12 +0200 | [diff] [blame] | 1318 | return ide_queue_pc_tail(drive, disk, &pc, NULL, 0); |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1319 | case MTERASE: |
| 1320 | (void)idetape_rewind_tape(drive); |
| 1321 | idetape_create_erase_cmd(&pc); |
Borislav Petkov | b13345f | 2009-05-02 10:26:12 +0200 | [diff] [blame] | 1322 | return ide_queue_pc_tail(drive, disk, &pc, NULL, 0); |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1323 | case MTSETBLK: |
| 1324 | if (mt_count) { |
| 1325 | if (mt_count < tape->blk_size || |
| 1326 | mt_count % tape->blk_size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1327 | return -EIO; |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1328 | tape->user_bs_factor = mt_count / tape->blk_size; |
Borislav Petkov | 49d8078 | 2009-06-07 15:37:06 +0200 | [diff] [blame] | 1329 | clear_bit(ilog2(IDE_AFLAG_DETECT_BS), |
| 1330 | &drive->atapi_flags); |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1331 | } else |
Borislav Petkov | 49d8078 | 2009-06-07 15:37:06 +0200 | [diff] [blame] | 1332 | set_bit(ilog2(IDE_AFLAG_DETECT_BS), |
| 1333 | &drive->atapi_flags); |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1334 | return 0; |
| 1335 | case MTSEEK: |
Borislav Petkov | ec0fdb0 | 2008-04-27 15:38:34 +0200 | [diff] [blame] | 1336 | ide_tape_discard_merge_buffer(drive, 0); |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1337 | return idetape_position_tape(drive, |
| 1338 | mt_count * tape->user_bs_factor, tape->partition, 0); |
| 1339 | case MTSETPART: |
Borislav Petkov | ec0fdb0 | 2008-04-27 15:38:34 +0200 | [diff] [blame] | 1340 | ide_tape_discard_merge_buffer(drive, 0); |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1341 | return idetape_position_tape(drive, 0, mt_count, 0); |
| 1342 | case MTFSR: |
| 1343 | case MTBSR: |
| 1344 | case MTLOCK: |
Bartlomiej Zolnierkiewicz | 0578042 | 2008-10-10 22:39:38 +0200 | [diff] [blame] | 1345 | retval = ide_set_media_lock(drive, disk, 1); |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1346 | if (retval) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1347 | return retval; |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1348 | tape->door_locked = DOOR_EXPLICITLY_LOCKED; |
| 1349 | return 0; |
| 1350 | case MTUNLOCK: |
Bartlomiej Zolnierkiewicz | 0578042 | 2008-10-10 22:39:38 +0200 | [diff] [blame] | 1351 | retval = ide_set_media_lock(drive, disk, 0); |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1352 | if (retval) |
| 1353 | return retval; |
| 1354 | tape->door_locked = DOOR_UNLOCKED; |
| 1355 | return 0; |
| 1356 | default: |
| 1357 | printk(KERN_ERR "ide-tape: MTIO operation %d not supported\n", |
| 1358 | mt_op); |
| 1359 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1360 | } |
| 1361 | } |
| 1362 | |
| 1363 | /* |
Borislav Petkov | d99c9da | 2008-02-02 19:56:51 +0100 | [diff] [blame] | 1364 | * Our character device ioctls. General mtio.h magnetic io commands are |
| 1365 | * supported here, and not in the corresponding block interface. Our own |
| 1366 | * ide-tape ioctls are supported on both interfaces. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1367 | */ |
Alan Cox | 05227ad | 2010-01-04 06:24:00 +0000 | [diff] [blame] | 1368 | static long do_idetape_chrdev_ioctl(struct file *file, |
Borislav Petkov | d99c9da | 2008-02-02 19:56:51 +0100 | [diff] [blame] | 1369 | unsigned int cmd, unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1370 | { |
Borislav Petkov | 5aeddf9 | 2008-10-13 21:39:34 +0200 | [diff] [blame] | 1371 | struct ide_tape_obj *tape = file->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1372 | ide_drive_t *drive = tape->drive; |
| 1373 | struct mtop mtop; |
| 1374 | struct mtget mtget; |
| 1375 | struct mtpos mtpos; |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1376 | int block_offset = 0, position = tape->first_frame; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1377 | void __user *argp = (void __user *)arg; |
| 1378 | |
Borislav Petkov | e972d70 | 2009-07-17 23:55:16 +0000 | [diff] [blame] | 1379 | ide_debug_log(IDE_DBG_FUNC, "cmd: 0x%x", cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1380 | |
Borislav Petkov | 54abf37 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1381 | if (tape->chrdev_dir == IDETAPE_DIR_WRITE) { |
Borislav Petkov | d9df937 | 2008-04-27 15:38:34 +0200 | [diff] [blame] | 1382 | ide_tape_flush_merge_buffer(drive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1383 | idetape_flush_tape_buffers(drive); |
| 1384 | } |
| 1385 | if (cmd == MTIOCGET || cmd == MTIOCPOS) { |
Tejun Heo | 963da55 | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 1386 | block_offset = tape->valid / |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1387 | (tape->blk_size * tape->user_bs_factor); |
Borislav Petkov | 55ce3a1 | 2009-05-04 09:38:15 +0200 | [diff] [blame] | 1388 | position = ide_tape_read_position(drive); |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1389 | if (position < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1390 | return -EIO; |
| 1391 | } |
| 1392 | switch (cmd) { |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1393 | case MTIOCTOP: |
| 1394 | if (copy_from_user(&mtop, argp, sizeof(struct mtop))) |
| 1395 | return -EFAULT; |
| 1396 | return idetape_mtioctop(drive, mtop.mt_op, mtop.mt_count); |
| 1397 | case MTIOCGET: |
| 1398 | memset(&mtget, 0, sizeof(struct mtget)); |
| 1399 | mtget.mt_type = MT_ISSCSI2; |
| 1400 | mtget.mt_blkno = position / tape->user_bs_factor - block_offset; |
| 1401 | mtget.mt_dsreg = |
| 1402 | ((tape->blk_size * tape->user_bs_factor) |
| 1403 | << MT_ST_BLKSIZE_SHIFT) & MT_ST_BLKSIZE_MASK; |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1404 | |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1405 | if (tape->drv_write_prot) |
| 1406 | mtget.mt_gstat |= GMT_WR_PROT(0xffffffff); |
| 1407 | |
| 1408 | if (copy_to_user(argp, &mtget, sizeof(struct mtget))) |
| 1409 | return -EFAULT; |
| 1410 | return 0; |
| 1411 | case MTIOCPOS: |
| 1412 | mtpos.mt_blkno = position / tape->user_bs_factor - block_offset; |
| 1413 | if (copy_to_user(argp, &mtpos, sizeof(struct mtpos))) |
| 1414 | return -EFAULT; |
| 1415 | return 0; |
| 1416 | default: |
| 1417 | if (tape->chrdev_dir == IDETAPE_DIR_READ) |
Borislav Petkov | ec0fdb0 | 2008-04-27 15:38:34 +0200 | [diff] [blame] | 1418 | ide_tape_discard_merge_buffer(drive, 1); |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1419 | return idetape_blkdev_ioctl(drive, cmd, arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1420 | } |
| 1421 | } |
| 1422 | |
Alan Cox | 05227ad | 2010-01-04 06:24:00 +0000 | [diff] [blame] | 1423 | static long idetape_chrdev_ioctl(struct file *file, |
| 1424 | unsigned int cmd, unsigned long arg) |
| 1425 | { |
| 1426 | long ret; |
Arnd Bergmann | 2a48fc0 | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 1427 | mutex_lock(&ide_tape_mutex); |
Alan Cox | 05227ad | 2010-01-04 06:24:00 +0000 | [diff] [blame] | 1428 | ret = do_idetape_chrdev_ioctl(file, cmd, arg); |
Arnd Bergmann | 2a48fc0 | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 1429 | mutex_unlock(&ide_tape_mutex); |
Alan Cox | 05227ad | 2010-01-04 06:24:00 +0000 | [diff] [blame] | 1430 | return ret; |
| 1431 | } |
| 1432 | |
Borislav Petkov | 3cffb9c | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 1433 | /* |
| 1434 | * Do a mode sense page 0 with block descriptor and if it succeeds set the tape |
| 1435 | * block size with the reported value. |
| 1436 | */ |
| 1437 | static void ide_tape_get_bsize_from_bdesc(ide_drive_t *drive) |
| 1438 | { |
| 1439 | idetape_tape_t *tape = drive->driver_data; |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1440 | struct ide_atapi_pc pc; |
Borislav Petkov | 837272b | 2009-05-04 09:48:57 +0200 | [diff] [blame] | 1441 | u8 buf[12]; |
Borislav Petkov | 3cffb9c | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 1442 | |
| 1443 | idetape_create_mode_sense_cmd(&pc, IDETAPE_BLOCK_DESCRIPTOR); |
Borislav Petkov | 837272b | 2009-05-04 09:48:57 +0200 | [diff] [blame] | 1444 | if (ide_queue_pc_tail(drive, tape->disk, &pc, buf, pc.req_xfer)) { |
Borislav Petkov | 3cffb9c | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 1445 | printk(KERN_ERR "ide-tape: Can't get block descriptor\n"); |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1446 | if (tape->blk_size == 0) { |
Borislav Petkov | 3cffb9c | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 1447 | printk(KERN_WARNING "ide-tape: Cannot deal with zero " |
| 1448 | "block size, assuming 32k\n"); |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1449 | tape->blk_size = 32768; |
Borislav Petkov | 3cffb9c | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 1450 | } |
| 1451 | return; |
| 1452 | } |
Borislav Petkov | 837272b | 2009-05-04 09:48:57 +0200 | [diff] [blame] | 1453 | tape->blk_size = (buf[4 + 5] << 16) + |
| 1454 | (buf[4 + 6] << 8) + |
| 1455 | buf[4 + 7]; |
| 1456 | tape->drv_write_prot = (buf[2] & 0x80) >> 7; |
Borislav Petkov | e972d70 | 2009-07-17 23:55:16 +0000 | [diff] [blame] | 1457 | |
| 1458 | ide_debug_log(IDE_DBG_FUNC, "blk_size: %d, write_prot: %d", |
| 1459 | tape->blk_size, tape->drv_write_prot); |
Borislav Petkov | 3cffb9c | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 1460 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1461 | |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1462 | static int idetape_chrdev_open(struct inode *inode, struct file *filp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1463 | { |
| 1464 | unsigned int minor = iminor(inode), i = minor & ~0xc0; |
| 1465 | ide_drive_t *drive; |
| 1466 | idetape_tape_t *tape; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1467 | int retval; |
| 1468 | |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 1469 | if (i >= MAX_HWIFS * MAX_DRIVES) |
| 1470 | return -ENXIO; |
| 1471 | |
Borislav Petkov | cbba2fa | 2009-10-11 00:25:19 +0000 | [diff] [blame] | 1472 | mutex_lock(&idetape_chrdev_mutex); |
| 1473 | |
Borislav Petkov | 9d01e4c | 2009-06-08 22:03:03 +0200 | [diff] [blame] | 1474 | tape = ide_tape_get(NULL, true, i); |
Jonathan Corbet | 04f4ac9 | 2008-05-15 12:01:56 -0600 | [diff] [blame] | 1475 | if (!tape) { |
Borislav Petkov | cbba2fa | 2009-10-11 00:25:19 +0000 | [diff] [blame] | 1476 | mutex_unlock(&idetape_chrdev_mutex); |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 1477 | return -ENXIO; |
Jonathan Corbet | 04f4ac9 | 2008-05-15 12:01:56 -0600 | [diff] [blame] | 1478 | } |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 1479 | |
Borislav Petkov | e972d70 | 2009-07-17 23:55:16 +0000 | [diff] [blame] | 1480 | drive = tape->drive; |
| 1481 | filp->private_data = tape; |
| 1482 | |
| 1483 | ide_debug_log(IDE_DBG_FUNC, "enter"); |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 1484 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1485 | /* |
| 1486 | * We really want to do nonseekable_open(inode, filp); here, but some |
| 1487 | * versions of tar incorrectly call lseek on tapes and bail out if that |
| 1488 | * fails. So we disallow pread() and pwrite(), but permit lseeks. |
| 1489 | */ |
| 1490 | filp->f_mode &= ~(FMODE_PREAD | FMODE_PWRITE); |
| 1491 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1492 | |
Borislav Petkov | 49d8078 | 2009-06-07 15:37:06 +0200 | [diff] [blame] | 1493 | if (test_and_set_bit(ilog2(IDE_AFLAG_BUSY), &drive->atapi_flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1494 | retval = -EBUSY; |
| 1495 | goto out_put_tape; |
| 1496 | } |
| 1497 | |
| 1498 | retval = idetape_wait_ready(drive, 60 * HZ); |
| 1499 | if (retval) { |
Borislav Petkov | 49d8078 | 2009-06-07 15:37:06 +0200 | [diff] [blame] | 1500 | clear_bit(ilog2(IDE_AFLAG_BUSY), &drive->atapi_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1501 | printk(KERN_ERR "ide-tape: %s: drive not ready\n", tape->name); |
| 1502 | goto out_put_tape; |
| 1503 | } |
| 1504 | |
Borislav Petkov | 79ca743 | 2009-06-15 07:32:04 +0200 | [diff] [blame] | 1505 | ide_tape_read_position(drive); |
Borislav Petkov | 49d8078 | 2009-06-07 15:37:06 +0200 | [diff] [blame] | 1506 | if (!test_bit(ilog2(IDE_AFLAG_ADDRESS_VALID), &drive->atapi_flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1507 | (void)idetape_rewind_tape(drive); |
| 1508 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1509 | /* Read block size and write protect status from drive. */ |
Borislav Petkov | 3cffb9c | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 1510 | ide_tape_get_bsize_from_bdesc(drive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1511 | |
| 1512 | /* Set write protect flag if device is opened as read-only. */ |
| 1513 | if ((filp->f_flags & O_ACCMODE) == O_RDONLY) |
| 1514 | tape->write_prot = 1; |
| 1515 | else |
| 1516 | tape->write_prot = tape->drv_write_prot; |
| 1517 | |
| 1518 | /* Make sure drive isn't write protected if user wants to write. */ |
| 1519 | if (tape->write_prot) { |
| 1520 | if ((filp->f_flags & O_ACCMODE) == O_WRONLY || |
| 1521 | (filp->f_flags & O_ACCMODE) == O_RDWR) { |
Borislav Petkov | 49d8078 | 2009-06-07 15:37:06 +0200 | [diff] [blame] | 1522 | clear_bit(ilog2(IDE_AFLAG_BUSY), &drive->atapi_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1523 | retval = -EROFS; |
| 1524 | goto out_put_tape; |
| 1525 | } |
| 1526 | } |
| 1527 | |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 1528 | /* Lock the tape drive door so user can't eject. */ |
Borislav Petkov | 54abf37 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1529 | if (tape->chrdev_dir == IDETAPE_DIR_NONE) { |
Bartlomiej Zolnierkiewicz | 0578042 | 2008-10-10 22:39:38 +0200 | [diff] [blame] | 1530 | if (!ide_set_media_lock(drive, tape->disk, 1)) { |
Bartlomiej Zolnierkiewicz | 385a4b8 | 2008-10-10 22:39:37 +0200 | [diff] [blame] | 1531 | if (tape->door_locked != DOOR_EXPLICITLY_LOCKED) |
| 1532 | tape->door_locked = DOOR_LOCKED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1533 | } |
| 1534 | } |
Borislav Petkov | cbba2fa | 2009-10-11 00:25:19 +0000 | [diff] [blame] | 1535 | mutex_unlock(&idetape_chrdev_mutex); |
| 1536 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1537 | return 0; |
| 1538 | |
| 1539 | out_put_tape: |
| 1540 | ide_tape_put(tape); |
Borislav Petkov | cbba2fa | 2009-10-11 00:25:19 +0000 | [diff] [blame] | 1541 | |
| 1542 | mutex_unlock(&idetape_chrdev_mutex); |
| 1543 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1544 | return retval; |
| 1545 | } |
| 1546 | |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1547 | static void idetape_write_release(ide_drive_t *drive, unsigned int minor) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1548 | { |
| 1549 | idetape_tape_t *tape = drive->driver_data; |
| 1550 | |
Borislav Petkov | d9df937 | 2008-04-27 15:38:34 +0200 | [diff] [blame] | 1551 | ide_tape_flush_merge_buffer(drive); |
Tejun Heo | 963da55 | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 1552 | tape->buf = kmalloc(tape->buffer_size, GFP_KERNEL); |
| 1553 | if (tape->buf != NULL) { |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1554 | idetape_pad_zeros(drive, tape->blk_size * |
| 1555 | (tape->user_bs_factor - 1)); |
Tejun Heo | 963da55 | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 1556 | kfree(tape->buf); |
| 1557 | tape->buf = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1558 | } |
| 1559 | idetape_write_filemark(drive); |
| 1560 | idetape_flush_tape_buffers(drive); |
| 1561 | idetape_flush_tape_buffers(drive); |
| 1562 | } |
| 1563 | |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1564 | static int idetape_chrdev_release(struct inode *inode, struct file *filp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1565 | { |
Borislav Petkov | 5aeddf9 | 2008-10-13 21:39:34 +0200 | [diff] [blame] | 1566 | struct ide_tape_obj *tape = filp->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1567 | ide_drive_t *drive = tape->drive; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1568 | unsigned int minor = iminor(inode); |
| 1569 | |
Borislav Petkov | cbba2fa | 2009-10-11 00:25:19 +0000 | [diff] [blame] | 1570 | mutex_lock(&idetape_chrdev_mutex); |
| 1571 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1572 | tape = drive->driver_data; |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 1573 | |
Borislav Petkov | e972d70 | 2009-07-17 23:55:16 +0000 | [diff] [blame] | 1574 | ide_debug_log(IDE_DBG_FUNC, "enter"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1575 | |
Borislav Petkov | 54abf37 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1576 | if (tape->chrdev_dir == IDETAPE_DIR_WRITE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1577 | idetape_write_release(drive, minor); |
Borislav Petkov | 54abf37 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1578 | if (tape->chrdev_dir == IDETAPE_DIR_READ) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1579 | if (minor < 128) |
Borislav Petkov | ec0fdb0 | 2008-04-27 15:38:34 +0200 | [diff] [blame] | 1580 | ide_tape_discard_merge_buffer(drive, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1581 | } |
Borislav Petkov | f64eee7 | 2008-04-27 15:38:25 +0200 | [diff] [blame] | 1582 | |
Borislav Petkov | 49d8078 | 2009-06-07 15:37:06 +0200 | [diff] [blame] | 1583 | if (minor < 128 && test_bit(ilog2(IDE_AFLAG_MEDIUM_PRESENT), |
| 1584 | &drive->atapi_flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1585 | (void) idetape_rewind_tape(drive); |
Borislav Petkov | 49d8078 | 2009-06-07 15:37:06 +0200 | [diff] [blame] | 1586 | |
Borislav Petkov | 54abf37 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1587 | if (tape->chrdev_dir == IDETAPE_DIR_NONE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1588 | if (tape->door_locked == DOOR_LOCKED) { |
Bartlomiej Zolnierkiewicz | 0578042 | 2008-10-10 22:39:38 +0200 | [diff] [blame] | 1589 | if (!ide_set_media_lock(drive, tape->disk, 0)) |
Bartlomiej Zolnierkiewicz | 385a4b8 | 2008-10-10 22:39:37 +0200 | [diff] [blame] | 1590 | tape->door_locked = DOOR_UNLOCKED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1591 | } |
| 1592 | } |
Borislav Petkov | 49d8078 | 2009-06-07 15:37:06 +0200 | [diff] [blame] | 1593 | clear_bit(ilog2(IDE_AFLAG_BUSY), &drive->atapi_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1594 | ide_tape_put(tape); |
Borislav Petkov | cbba2fa | 2009-10-11 00:25:19 +0000 | [diff] [blame] | 1595 | |
| 1596 | mutex_unlock(&idetape_chrdev_mutex); |
| 1597 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1598 | return 0; |
| 1599 | } |
| 1600 | |
Borislav Petkov | 6d29c8f | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 1601 | static void idetape_get_inquiry_results(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1602 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1603 | idetape_tape_t *tape = drive->driver_data; |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1604 | struct ide_atapi_pc pc; |
Bartlomiej Zolnierkiewicz | 41fa9f8 | 2009-03-31 20:15:25 +0200 | [diff] [blame] | 1605 | u8 pc_buf[256]; |
Borislav Petkov | 801bd32 | 2008-09-27 19:32:17 +0200 | [diff] [blame] | 1606 | char fw_rev[4], vendor_id[8], product_id[16]; |
Borislav Petkov | 6d29c8f | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 1607 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1608 | idetape_create_inquiry_cmd(&pc); |
Borislav Petkov | b13345f | 2009-05-02 10:26:12 +0200 | [diff] [blame] | 1609 | if (ide_queue_pc_tail(drive, tape->disk, &pc, pc_buf, pc.req_xfer)) { |
Borislav Petkov | 6d29c8f | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 1610 | printk(KERN_ERR "ide-tape: %s: can't get INQUIRY results\n", |
| 1611 | tape->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1612 | return; |
| 1613 | } |
Borislav Petkov | b13345f | 2009-05-02 10:26:12 +0200 | [diff] [blame] | 1614 | memcpy(vendor_id, &pc_buf[8], 8); |
| 1615 | memcpy(product_id, &pc_buf[16], 16); |
| 1616 | memcpy(fw_rev, &pc_buf[32], 4); |
Borislav Petkov | 6d29c8f | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 1617 | |
Borislav Petkov | 801bd32 | 2008-09-27 19:32:17 +0200 | [diff] [blame] | 1618 | ide_fixstring(vendor_id, 8, 0); |
| 1619 | ide_fixstring(product_id, 16, 0); |
| 1620 | ide_fixstring(fw_rev, 4, 0); |
Borislav Petkov | 41f81d54 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1621 | |
Borislav Petkov | 801bd32 | 2008-09-27 19:32:17 +0200 | [diff] [blame] | 1622 | printk(KERN_INFO "ide-tape: %s <-> %s: %.8s %.16s rev %.4s\n", |
Borislav Petkov | 41f81d54 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1623 | drive->name, tape->name, vendor_id, product_id, fw_rev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1624 | } |
| 1625 | |
| 1626 | /* |
Borislav Petkov | b642201 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 1627 | * Ask the tape about its various parameters. In particular, we will adjust our |
| 1628 | * data transfer buffer size to the recommended value as returned by the tape. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1629 | */ |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1630 | static void idetape_get_mode_sense_results(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1631 | { |
| 1632 | idetape_tape_t *tape = drive->driver_data; |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1633 | struct ide_atapi_pc pc; |
Borislav Petkov | b13345f | 2009-05-02 10:26:12 +0200 | [diff] [blame] | 1634 | u8 buf[24], *caps; |
Borislav Petkov | b642201 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 1635 | u8 speed, max_speed; |
Borislav Petkov | 47314fa | 2008-02-02 19:56:48 +0100 | [diff] [blame] | 1636 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1637 | idetape_create_mode_sense_cmd(&pc, IDETAPE_CAPABILITIES_PAGE); |
Borislav Petkov | b13345f | 2009-05-02 10:26:12 +0200 | [diff] [blame] | 1638 | if (ide_queue_pc_tail(drive, tape->disk, &pc, buf, pc.req_xfer)) { |
Borislav Petkov | b642201 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 1639 | printk(KERN_ERR "ide-tape: Can't get tape parameters - assuming" |
| 1640 | " some default values\n"); |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1641 | tape->blk_size = 512; |
Borislav Petkov | b642201 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 1642 | put_unaligned(52, (u16 *)&tape->caps[12]); |
| 1643 | put_unaligned(540, (u16 *)&tape->caps[14]); |
| 1644 | put_unaligned(6*52, (u16 *)&tape->caps[16]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1645 | return; |
| 1646 | } |
Borislav Petkov | b13345f | 2009-05-02 10:26:12 +0200 | [diff] [blame] | 1647 | caps = buf + 4 + buf[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1648 | |
Borislav Petkov | b642201 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 1649 | /* convert to host order and save for later use */ |
Harvey Harrison | cd740ab | 2008-07-24 22:53:33 +0200 | [diff] [blame] | 1650 | speed = be16_to_cpup((__be16 *)&caps[14]); |
| 1651 | max_speed = be16_to_cpup((__be16 *)&caps[8]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1652 | |
Harvey Harrison | cd740ab | 2008-07-24 22:53:33 +0200 | [diff] [blame] | 1653 | *(u16 *)&caps[8] = max_speed; |
| 1654 | *(u16 *)&caps[12] = be16_to_cpup((__be16 *)&caps[12]); |
| 1655 | *(u16 *)&caps[14] = speed; |
| 1656 | *(u16 *)&caps[16] = be16_to_cpup((__be16 *)&caps[16]); |
Borislav Petkov | b642201 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 1657 | |
| 1658 | if (!speed) { |
| 1659 | printk(KERN_INFO "ide-tape: %s: invalid tape speed " |
| 1660 | "(assuming 650KB/sec)\n", drive->name); |
Harvey Harrison | cd740ab | 2008-07-24 22:53:33 +0200 | [diff] [blame] | 1661 | *(u16 *)&caps[14] = 650; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1662 | } |
Borislav Petkov | b642201 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 1663 | if (!max_speed) { |
| 1664 | printk(KERN_INFO "ide-tape: %s: invalid max_speed " |
| 1665 | "(assuming 650KB/sec)\n", drive->name); |
Harvey Harrison | cd740ab | 2008-07-24 22:53:33 +0200 | [diff] [blame] | 1666 | *(u16 *)&caps[8] = 650; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1667 | } |
| 1668 | |
Borislav Petkov | b642201 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 1669 | memcpy(&tape->caps, caps, 20); |
Bartlomiej Zolnierkiewicz | 0578042 | 2008-10-10 22:39:38 +0200 | [diff] [blame] | 1670 | |
| 1671 | /* device lacks locking support according to capabilities page */ |
| 1672 | if ((caps[6] & 1) == 0) |
Bartlomiej Zolnierkiewicz | 42619d3 | 2008-10-17 18:09:11 +0200 | [diff] [blame] | 1673 | drive->dev_flags &= ~IDE_DFLAG_DOORLOCKING; |
Bartlomiej Zolnierkiewicz | 0578042 | 2008-10-10 22:39:38 +0200 | [diff] [blame] | 1674 | |
Borislav Petkov | b642201 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 1675 | if (caps[7] & 0x02) |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1676 | tape->blk_size = 512; |
Borislav Petkov | b642201 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 1677 | else if (caps[7] & 0x04) |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1678 | tape->blk_size = 1024; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1679 | } |
| 1680 | |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 1681 | #ifdef CONFIG_IDE_PROC_FS |
Bartlomiej Zolnierkiewicz | 8185d5a | 2008-10-10 22:39:28 +0200 | [diff] [blame] | 1682 | #define ide_tape_devset_get(name, field) \ |
| 1683 | static int get_##name(ide_drive_t *drive) \ |
| 1684 | { \ |
| 1685 | idetape_tape_t *tape = drive->driver_data; \ |
| 1686 | return tape->field; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1687 | } |
Bartlomiej Zolnierkiewicz | 8185d5a | 2008-10-10 22:39:28 +0200 | [diff] [blame] | 1688 | |
| 1689 | #define ide_tape_devset_set(name, field) \ |
| 1690 | static int set_##name(ide_drive_t *drive, int arg) \ |
| 1691 | { \ |
| 1692 | idetape_tape_t *tape = drive->driver_data; \ |
| 1693 | tape->field = arg; \ |
| 1694 | return 0; \ |
| 1695 | } |
| 1696 | |
Elias Oltmanns | 92f1f8f | 2008-10-10 22:39:40 +0200 | [diff] [blame] | 1697 | #define ide_tape_devset_rw_field(_name, _field) \ |
Bartlomiej Zolnierkiewicz | 8185d5a | 2008-10-10 22:39:28 +0200 | [diff] [blame] | 1698 | ide_tape_devset_get(_name, _field) \ |
| 1699 | ide_tape_devset_set(_name, _field) \ |
Elias Oltmanns | 92f1f8f | 2008-10-10 22:39:40 +0200 | [diff] [blame] | 1700 | IDE_DEVSET(_name, DS_SYNC, get_##_name, set_##_name) |
Bartlomiej Zolnierkiewicz | 8185d5a | 2008-10-10 22:39:28 +0200 | [diff] [blame] | 1701 | |
Elias Oltmanns | 92f1f8f | 2008-10-10 22:39:40 +0200 | [diff] [blame] | 1702 | #define ide_tape_devset_r_field(_name, _field) \ |
Bartlomiej Zolnierkiewicz | 8185d5a | 2008-10-10 22:39:28 +0200 | [diff] [blame] | 1703 | ide_tape_devset_get(_name, _field) \ |
Elias Oltmanns | 92f1f8f | 2008-10-10 22:39:40 +0200 | [diff] [blame] | 1704 | IDE_DEVSET(_name, 0, get_##_name, NULL) |
Bartlomiej Zolnierkiewicz | 8185d5a | 2008-10-10 22:39:28 +0200 | [diff] [blame] | 1705 | |
| 1706 | static int mulf_tdsc(ide_drive_t *drive) { return 1000; } |
| 1707 | static int divf_tdsc(ide_drive_t *drive) { return HZ; } |
| 1708 | static int divf_buffer(ide_drive_t *drive) { return 2; } |
| 1709 | static int divf_buffer_size(ide_drive_t *drive) { return 1024; } |
| 1710 | |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame] | 1711 | ide_devset_rw_flag(dsc_overlap, IDE_DFLAG_DSC_OVERLAP); |
Bartlomiej Zolnierkiewicz | 8185d5a | 2008-10-10 22:39:28 +0200 | [diff] [blame] | 1712 | |
Elias Oltmanns | 92f1f8f | 2008-10-10 22:39:40 +0200 | [diff] [blame] | 1713 | ide_tape_devset_rw_field(tdsc, best_dsc_rw_freq); |
Bartlomiej Zolnierkiewicz | 8185d5a | 2008-10-10 22:39:28 +0200 | [diff] [blame] | 1714 | |
Elias Oltmanns | 92f1f8f | 2008-10-10 22:39:40 +0200 | [diff] [blame] | 1715 | ide_tape_devset_r_field(avg_speed, avg_speed); |
| 1716 | ide_tape_devset_r_field(speed, caps[14]); |
| 1717 | ide_tape_devset_r_field(buffer, caps[16]); |
| 1718 | ide_tape_devset_r_field(buffer_size, buffer_size); |
Bartlomiej Zolnierkiewicz | 8185d5a | 2008-10-10 22:39:28 +0200 | [diff] [blame] | 1719 | |
Elias Oltmanns | 92f1f8f | 2008-10-10 22:39:40 +0200 | [diff] [blame] | 1720 | static const struct ide_proc_devset idetape_settings[] = { |
| 1721 | __IDE_PROC_DEVSET(avg_speed, 0, 0xffff, NULL, NULL), |
| 1722 | __IDE_PROC_DEVSET(buffer, 0, 0xffff, NULL, divf_buffer), |
| 1723 | __IDE_PROC_DEVSET(buffer_size, 0, 0xffff, NULL, divf_buffer_size), |
Elias Oltmanns | 92f1f8f | 2008-10-10 22:39:40 +0200 | [diff] [blame] | 1724 | __IDE_PROC_DEVSET(dsc_overlap, 0, 1, NULL, NULL), |
| 1725 | __IDE_PROC_DEVSET(speed, 0, 0xffff, NULL, NULL), |
| 1726 | __IDE_PROC_DEVSET(tdsc, IDETAPE_DSC_RW_MIN, IDETAPE_DSC_RW_MAX, |
| 1727 | mulf_tdsc, divf_tdsc), |
Hannes Eder | 71bfc7a | 2009-03-05 16:10:56 +0100 | [diff] [blame] | 1728 | { NULL }, |
Bartlomiej Zolnierkiewicz | 8185d5a | 2008-10-10 22:39:28 +0200 | [diff] [blame] | 1729 | }; |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 1730 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1731 | |
| 1732 | /* |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 1733 | * The function below is called to: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1734 | * |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 1735 | * 1. Initialize our various state variables. |
| 1736 | * 2. Ask the tape for its capabilities. |
| 1737 | * 3. Allocate a buffer which will be used for data transfer. The buffer size |
| 1738 | * is chosen based on the recommendation which we received in step 2. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1739 | * |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 1740 | * Note that at this point ide.c already assigned us an irq, so that we can |
| 1741 | * queue requests here and wait for their completion. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1742 | */ |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1743 | static void idetape_setup(ide_drive_t *drive, idetape_tape_t *tape, int minor) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1744 | { |
Borislav Petkov | 83042b2 | 2008-04-27 15:38:27 +0200 | [diff] [blame] | 1745 | unsigned long t; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1746 | int speed; |
Borislav Petkov | f73850a | 2008-04-27 15:38:33 +0200 | [diff] [blame] | 1747 | int buffer_size; |
Borislav Petkov | b642201 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 1748 | u16 *ctl = (u16 *)&tape->caps[12]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1749 | |
Borislav Petkov | e972d70 | 2009-07-17 23:55:16 +0000 | [diff] [blame] | 1750 | ide_debug_log(IDE_DBG_FUNC, "minor: %d", minor); |
| 1751 | |
| 1752 | drive->pc_callback = ide_tape_callback; |
Borislav Petkov | 776bb02 | 2008-07-23 19:55:59 +0200 | [diff] [blame] | 1753 | |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame] | 1754 | drive->dev_flags |= IDE_DFLAG_DSC_OVERLAP; |
| 1755 | |
Bartlomiej Zolnierkiewicz | 4166c19 | 2008-02-01 23:09:30 +0100 | [diff] [blame] | 1756 | if (drive->hwif->host_flags & IDE_HFLAG_NO_DSC) { |
| 1757 | printk(KERN_INFO "ide-tape: %s: disabling DSC overlap\n", |
| 1758 | tape->name); |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame] | 1759 | drive->dev_flags &= ~IDE_DFLAG_DSC_OVERLAP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1760 | } |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame] | 1761 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1762 | /* Seagate Travan drives do not support DSC overlap. */ |
Bartlomiej Zolnierkiewicz | 4dde449 | 2008-10-10 22:39:19 +0200 | [diff] [blame] | 1763 | if (strstr((char *)&drive->id[ATA_ID_PROD], "Seagate STT3401")) |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame] | 1764 | drive->dev_flags &= ~IDE_DFLAG_DSC_OVERLAP; |
| 1765 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1766 | tape->minor = minor; |
| 1767 | tape->name[0] = 'h'; |
| 1768 | tape->name[1] = 't'; |
| 1769 | tape->name[2] = '0' + minor; |
Borislav Petkov | 54abf37 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1770 | tape->chrdev_dir = IDETAPE_DIR_NONE; |
Bartlomiej Zolnierkiewicz | 4dde449 | 2008-10-10 22:39:19 +0200 | [diff] [blame] | 1771 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1772 | idetape_get_inquiry_results(drive); |
| 1773 | idetape_get_mode_sense_results(drive); |
Borislav Petkov | 3cffb9c | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 1774 | ide_tape_get_bsize_from_bdesc(drive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1775 | tape->user_bs_factor = 1; |
Borislav Petkov | f73850a | 2008-04-27 15:38:33 +0200 | [diff] [blame] | 1776 | tape->buffer_size = *ctl * tape->blk_size; |
| 1777 | while (tape->buffer_size > 0xffff) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1778 | printk(KERN_NOTICE "ide-tape: decreasing stage size\n"); |
Borislav Petkov | b642201 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 1779 | *ctl /= 2; |
Borislav Petkov | f73850a | 2008-04-27 15:38:33 +0200 | [diff] [blame] | 1780 | tape->buffer_size = *ctl * tape->blk_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1781 | } |
Borislav Petkov | f73850a | 2008-04-27 15:38:33 +0200 | [diff] [blame] | 1782 | buffer_size = tape->buffer_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1783 | |
Borislav Petkov | 83042b2 | 2008-04-27 15:38:27 +0200 | [diff] [blame] | 1784 | /* select the "best" DSC read/write polling freq */ |
Borislav Petkov | b642201 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 1785 | speed = max(*(u16 *)&tape->caps[14], *(u16 *)&tape->caps[8]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1786 | |
Borislav Petkov | f73850a | 2008-04-27 15:38:33 +0200 | [diff] [blame] | 1787 | t = (IDETAPE_FIFO_THRESHOLD * tape->buffer_size * HZ) / (speed * 1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1788 | |
| 1789 | /* |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 1790 | * Ensure that the number we got makes sense; limit it within |
| 1791 | * IDETAPE_DSC_RW_MIN and IDETAPE_DSC_RW_MAX. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1792 | */ |
Harvey Harrison | a792bd5 | 2008-07-15 21:21:41 +0200 | [diff] [blame] | 1793 | tape->best_dsc_rw_freq = clamp_t(unsigned long, t, IDETAPE_DSC_RW_MIN, |
| 1794 | IDETAPE_DSC_RW_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1795 | printk(KERN_INFO "ide-tape: %s <-> %s: %dKBps, %d*%dkB buffer, " |
Nicholas Mc Guire | 8421596 | 2015-03-03 05:52:51 -0500 | [diff] [blame] | 1796 | "%ums tDSC%s\n", |
Borislav Petkov | b642201 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 1797 | drive->name, tape->name, *(u16 *)&tape->caps[14], |
Borislav Petkov | f73850a | 2008-04-27 15:38:33 +0200 | [diff] [blame] | 1798 | (*(u16 *)&tape->caps[16] * 512) / tape->buffer_size, |
| 1799 | tape->buffer_size / 1024, |
Nicholas Mc Guire | 8421596 | 2015-03-03 05:52:51 -0500 | [diff] [blame] | 1800 | jiffies_to_msecs(tape->best_dsc_rw_freq), |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame] | 1801 | (drive->dev_flags & IDE_DFLAG_USING_DMA) ? ", DMA" : ""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1802 | |
Bartlomiej Zolnierkiewicz | 1e874f4 | 2008-10-10 22:39:27 +0200 | [diff] [blame] | 1803 | ide_proc_register_driver(drive, tape->driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1804 | } |
| 1805 | |
Russell King | 4031bbe | 2006-01-06 11:41:00 +0000 | [diff] [blame] | 1806 | static void ide_tape_remove(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1807 | { |
| 1808 | idetape_tape_t *tape = drive->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1809 | |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 1810 | ide_proc_unregister_driver(drive, tape->driver); |
Bartlomiej Zolnierkiewicz | 8fed436 | 2009-02-25 20:28:24 +0100 | [diff] [blame] | 1811 | device_del(&tape->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1812 | ide_unregister_region(tape->disk); |
| 1813 | |
Bartlomiej Zolnierkiewicz | 8fed436 | 2009-02-25 20:28:24 +0100 | [diff] [blame] | 1814 | mutex_lock(&idetape_ref_mutex); |
| 1815 | put_device(&tape->dev); |
| 1816 | mutex_unlock(&idetape_ref_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1817 | } |
| 1818 | |
Bartlomiej Zolnierkiewicz | 8fed436 | 2009-02-25 20:28:24 +0100 | [diff] [blame] | 1819 | static void ide_tape_release(struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1820 | { |
Bartlomiej Zolnierkiewicz | 8fed436 | 2009-02-25 20:28:24 +0100 | [diff] [blame] | 1821 | struct ide_tape_obj *tape = to_ide_drv(dev, ide_tape_obj); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1822 | ide_drive_t *drive = tape->drive; |
| 1823 | struct gendisk *g = tape->disk; |
| 1824 | |
Tejun Heo | 963da55 | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 1825 | BUG_ON(tape->valid); |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 1826 | |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame] | 1827 | drive->dev_flags &= ~IDE_DFLAG_DSC_OVERLAP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1828 | drive->driver_data = NULL; |
Tony Jones | dbc1272 | 2007-09-25 02:03:03 +0200 | [diff] [blame] | 1829 | device_destroy(idetape_sysfs_class, MKDEV(IDETAPE_MAJOR, tape->minor)); |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1830 | device_destroy(idetape_sysfs_class, |
| 1831 | MKDEV(IDETAPE_MAJOR, tape->minor + 128)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1832 | idetape_devs[tape->minor] = NULL; |
| 1833 | g->private_data = NULL; |
| 1834 | put_disk(g); |
| 1835 | kfree(tape); |
| 1836 | } |
| 1837 | |
Bartlomiej Zolnierkiewicz | ecfd80e | 2007-05-10 00:01:09 +0200 | [diff] [blame] | 1838 | #ifdef CONFIG_IDE_PROC_FS |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 1839 | static int idetape_name_proc_show(struct seq_file *m, void *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1840 | { |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 1841 | ide_drive_t *drive = (ide_drive_t *) m->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1842 | idetape_tape_t *tape = drive->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1843 | |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 1844 | seq_printf(m, "%s\n", tape->name); |
| 1845 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1846 | } |
| 1847 | |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 1848 | static int idetape_name_proc_open(struct inode *inode, struct file *file) |
| 1849 | { |
Al Viro | d9dda78 | 2013-03-31 18:16:14 -0400 | [diff] [blame] | 1850 | return single_open(file, idetape_name_proc_show, PDE_DATA(inode)); |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 1851 | } |
| 1852 | |
| 1853 | static const struct file_operations idetape_name_proc_fops = { |
| 1854 | .owner = THIS_MODULE, |
| 1855 | .open = idetape_name_proc_open, |
| 1856 | .read = seq_read, |
| 1857 | .llseek = seq_lseek, |
| 1858 | .release = single_release, |
| 1859 | }; |
| 1860 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1861 | static ide_proc_entry_t idetape_proc[] = { |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 1862 | { "capacity", S_IFREG|S_IRUGO, &ide_capacity_proc_fops }, |
| 1863 | { "name", S_IFREG|S_IRUGO, &idetape_name_proc_fops }, |
| 1864 | {} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1865 | }; |
Bartlomiej Zolnierkiewicz | 79cb380 | 2008-10-17 18:09:13 +0200 | [diff] [blame] | 1866 | |
| 1867 | static ide_proc_entry_t *ide_tape_proc_entries(ide_drive_t *drive) |
| 1868 | { |
| 1869 | return idetape_proc; |
| 1870 | } |
| 1871 | |
| 1872 | static const struct ide_proc_devset *ide_tape_proc_devsets(ide_drive_t *drive) |
| 1873 | { |
| 1874 | return idetape_settings; |
| 1875 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1876 | #endif |
| 1877 | |
Russell King | 4031bbe | 2006-01-06 11:41:00 +0000 | [diff] [blame] | 1878 | static int ide_tape_probe(ide_drive_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1879 | |
Bartlomiej Zolnierkiewicz | 7f3c868 | 2009-01-06 17:20:53 +0100 | [diff] [blame] | 1880 | static struct ide_driver idetape_driver = { |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 1881 | .gen_driver = { |
Laurent Riffard | 4ef3b8f | 2005-11-18 22:15:40 +0100 | [diff] [blame] | 1882 | .owner = THIS_MODULE, |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 1883 | .name = "ide-tape", |
| 1884 | .bus = &ide_bus_type, |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 1885 | }, |
Russell King | 4031bbe | 2006-01-06 11:41:00 +0000 | [diff] [blame] | 1886 | .probe = ide_tape_probe, |
| 1887 | .remove = ide_tape_remove, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1888 | .version = IDETAPE_VERSION, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1889 | .do_request = idetape_do_request, |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 1890 | #ifdef CONFIG_IDE_PROC_FS |
Bartlomiej Zolnierkiewicz | 79cb380 | 2008-10-17 18:09:13 +0200 | [diff] [blame] | 1891 | .proc_entries = ide_tape_proc_entries, |
| 1892 | .proc_devsets = ide_tape_proc_devsets, |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 1893 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1894 | }; |
| 1895 | |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 1896 | /* Our character device supporting functions, passed to register_chrdev. */ |
Arjan van de Ven | 2b8693c | 2007-02-12 00:55:32 -0800 | [diff] [blame] | 1897 | static const struct file_operations idetape_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1898 | .owner = THIS_MODULE, |
| 1899 | .read = idetape_chrdev_read, |
| 1900 | .write = idetape_chrdev_write, |
Alan Cox | 05227ad | 2010-01-04 06:24:00 +0000 | [diff] [blame] | 1901 | .unlocked_ioctl = idetape_chrdev_ioctl, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1902 | .open = idetape_chrdev_open, |
| 1903 | .release = idetape_chrdev_release, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 1904 | .llseek = noop_llseek, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1905 | }; |
| 1906 | |
Al Viro | a4600f8 | 2008-03-02 10:27:58 -0500 | [diff] [blame] | 1907 | static int idetape_open(struct block_device *bdev, fmode_t mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1908 | { |
Arnd Bergmann | 6e9624b | 2010-08-07 18:25:34 +0200 | [diff] [blame] | 1909 | struct ide_tape_obj *tape; |
| 1910 | |
Arnd Bergmann | 2a48fc0 | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 1911 | mutex_lock(&ide_tape_mutex); |
Arnd Bergmann | 6e9624b | 2010-08-07 18:25:34 +0200 | [diff] [blame] | 1912 | tape = ide_tape_get(bdev->bd_disk, false, 0); |
Arnd Bergmann | 2a48fc0 | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 1913 | mutex_unlock(&ide_tape_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1914 | |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1915 | if (!tape) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1916 | return -ENXIO; |
| 1917 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1918 | return 0; |
| 1919 | } |
| 1920 | |
Al Viro | db2a144 | 2013-05-05 21:52:57 -0400 | [diff] [blame] | 1921 | static void idetape_release(struct gendisk *disk, fmode_t mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1922 | { |
Borislav Petkov | 5aeddf9 | 2008-10-13 21:39:34 +0200 | [diff] [blame] | 1923 | struct ide_tape_obj *tape = ide_drv_g(disk, ide_tape_obj); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1924 | |
Arnd Bergmann | 2a48fc0 | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 1925 | mutex_lock(&ide_tape_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1926 | ide_tape_put(tape); |
Arnd Bergmann | 2a48fc0 | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 1927 | mutex_unlock(&ide_tape_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1928 | } |
| 1929 | |
Al Viro | a4600f8 | 2008-03-02 10:27:58 -0500 | [diff] [blame] | 1930 | static int idetape_ioctl(struct block_device *bdev, fmode_t mode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1931 | unsigned int cmd, unsigned long arg) |
| 1932 | { |
Borislav Petkov | 5aeddf9 | 2008-10-13 21:39:34 +0200 | [diff] [blame] | 1933 | struct ide_tape_obj *tape = ide_drv_g(bdev->bd_disk, ide_tape_obj); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1934 | ide_drive_t *drive = tape->drive; |
Arnd Bergmann | 8a6cfeb | 2010-07-08 10:18:46 +0200 | [diff] [blame] | 1935 | int err; |
| 1936 | |
Arnd Bergmann | 2a48fc0 | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 1937 | mutex_lock(&ide_tape_mutex); |
Arnd Bergmann | 8a6cfeb | 2010-07-08 10:18:46 +0200 | [diff] [blame] | 1938 | err = generic_ide_ioctl(drive, bdev, cmd, arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1939 | if (err == -EINVAL) |
| 1940 | err = idetape_blkdev_ioctl(drive, cmd, arg); |
Arnd Bergmann | 2a48fc0 | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 1941 | mutex_unlock(&ide_tape_mutex); |
Arnd Bergmann | 8a6cfeb | 2010-07-08 10:18:46 +0200 | [diff] [blame] | 1942 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1943 | return err; |
| 1944 | } |
| 1945 | |
Alexey Dobriyan | 83d5cde | 2009-09-21 17:01:13 -0700 | [diff] [blame] | 1946 | static const struct block_device_operations idetape_block_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1947 | .owner = THIS_MODULE, |
Al Viro | a4600f8 | 2008-03-02 10:27:58 -0500 | [diff] [blame] | 1948 | .open = idetape_open, |
| 1949 | .release = idetape_release, |
Arnd Bergmann | 8a6cfeb | 2010-07-08 10:18:46 +0200 | [diff] [blame] | 1950 | .ioctl = idetape_ioctl, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1951 | }; |
| 1952 | |
Russell King | 4031bbe | 2006-01-06 11:41:00 +0000 | [diff] [blame] | 1953 | static int ide_tape_probe(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1954 | { |
| 1955 | idetape_tape_t *tape; |
| 1956 | struct gendisk *g; |
| 1957 | int minor; |
| 1958 | |
Borislav Petkov | e972d70 | 2009-07-17 23:55:16 +0000 | [diff] [blame] | 1959 | ide_debug_log(IDE_DBG_FUNC, "enter"); |
| 1960 | |
| 1961 | if (!strstr(DRV_NAME, drive->driver_req)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1962 | goto failed; |
Bartlomiej Zolnierkiewicz | 2a92466 | 2008-10-10 22:39:24 +0200 | [diff] [blame] | 1963 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1964 | if (drive->media != ide_tape) |
| 1965 | goto failed; |
Bartlomiej Zolnierkiewicz | 2a92466 | 2008-10-10 22:39:24 +0200 | [diff] [blame] | 1966 | |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame] | 1967 | if ((drive->dev_flags & IDE_DFLAG_ID_READ) && |
| 1968 | ide_check_atapi_device(drive, DRV_NAME) == 0) { |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1969 | printk(KERN_ERR "ide-tape: %s: not supported by this version of" |
| 1970 | " the driver\n", drive->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1971 | goto failed; |
| 1972 | } |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1973 | tape = kzalloc(sizeof(idetape_tape_t), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1974 | if (tape == NULL) { |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1975 | printk(KERN_ERR "ide-tape: %s: Can't allocate a tape struct\n", |
| 1976 | drive->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1977 | goto failed; |
| 1978 | } |
| 1979 | |
| 1980 | g = alloc_disk(1 << PARTN_BITS); |
| 1981 | if (!g) |
| 1982 | goto out_free_tape; |
| 1983 | |
| 1984 | ide_init_disk(g, drive); |
| 1985 | |
Bartlomiej Zolnierkiewicz | 8fed436 | 2009-02-25 20:28:24 +0100 | [diff] [blame] | 1986 | tape->dev.parent = &drive->gendev; |
| 1987 | tape->dev.release = ide_tape_release; |
Kees Cook | 02aa2a3 | 2013-07-03 15:04:56 -0700 | [diff] [blame] | 1988 | dev_set_name(&tape->dev, "%s", dev_name(&drive->gendev)); |
Bartlomiej Zolnierkiewicz | 8fed436 | 2009-02-25 20:28:24 +0100 | [diff] [blame] | 1989 | |
| 1990 | if (device_register(&tape->dev)) |
| 1991 | goto out_free_disk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1992 | |
| 1993 | tape->drive = drive; |
| 1994 | tape->driver = &idetape_driver; |
| 1995 | tape->disk = g; |
| 1996 | |
| 1997 | g->private_data = &tape->driver; |
| 1998 | |
| 1999 | drive->driver_data = tape; |
| 2000 | |
Arjan van de Ven | cf8b897 | 2006-03-23 03:00:45 -0800 | [diff] [blame] | 2001 | mutex_lock(&idetape_ref_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2002 | for (minor = 0; idetape_devs[minor]; minor++) |
| 2003 | ; |
| 2004 | idetape_devs[minor] = tape; |
Arjan van de Ven | cf8b897 | 2006-03-23 03:00:45 -0800 | [diff] [blame] | 2005 | mutex_unlock(&idetape_ref_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2006 | |
| 2007 | idetape_setup(drive, tape, minor); |
| 2008 | |
Greg Kroah-Hartman | 3ee074b | 2008-07-21 20:03:34 -0700 | [diff] [blame] | 2009 | device_create(idetape_sysfs_class, &drive->gendev, |
| 2010 | MKDEV(IDETAPE_MAJOR, minor), NULL, "%s", tape->name); |
| 2011 | device_create(idetape_sysfs_class, &drive->gendev, |
| 2012 | MKDEV(IDETAPE_MAJOR, minor + 128), NULL, |
| 2013 | "n%s", tape->name); |
Will Dyson | d5dee80 | 2005-09-16 02:55:07 -0700 | [diff] [blame] | 2014 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2015 | g->fops = &idetape_block_ops; |
| 2016 | ide_register_region(g); |
| 2017 | |
| 2018 | return 0; |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 2019 | |
Bartlomiej Zolnierkiewicz | 8fed436 | 2009-02-25 20:28:24 +0100 | [diff] [blame] | 2020 | out_free_disk: |
| 2021 | put_disk(g); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2022 | out_free_tape: |
| 2023 | kfree(tape); |
| 2024 | failed: |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 2025 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2026 | } |
| 2027 | |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2028 | static void __exit idetape_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2029 | { |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 2030 | driver_unregister(&idetape_driver.gen_driver); |
Will Dyson | d5dee80 | 2005-09-16 02:55:07 -0700 | [diff] [blame] | 2031 | class_destroy(idetape_sysfs_class); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2032 | unregister_chrdev(IDETAPE_MAJOR, "ht"); |
| 2033 | } |
| 2034 | |
Bartlomiej Zolnierkiewicz | 17514e8 | 2005-11-19 22:24:35 +0100 | [diff] [blame] | 2035 | static int __init idetape_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2036 | { |
Will Dyson | d5dee80 | 2005-09-16 02:55:07 -0700 | [diff] [blame] | 2037 | int error = 1; |
| 2038 | idetape_sysfs_class = class_create(THIS_MODULE, "ide_tape"); |
| 2039 | if (IS_ERR(idetape_sysfs_class)) { |
| 2040 | idetape_sysfs_class = NULL; |
| 2041 | printk(KERN_ERR "Unable to create sysfs class for ide tapes\n"); |
| 2042 | error = -EBUSY; |
| 2043 | goto out; |
| 2044 | } |
| 2045 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2046 | if (register_chrdev(IDETAPE_MAJOR, "ht", &idetape_fops)) { |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2047 | printk(KERN_ERR "ide-tape: Failed to register chrdev" |
| 2048 | " interface\n"); |
Will Dyson | d5dee80 | 2005-09-16 02:55:07 -0700 | [diff] [blame] | 2049 | error = -EBUSY; |
| 2050 | goto out_free_class; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2051 | } |
Will Dyson | d5dee80 | 2005-09-16 02:55:07 -0700 | [diff] [blame] | 2052 | |
| 2053 | error = driver_register(&idetape_driver.gen_driver); |
| 2054 | if (error) |
| 2055 | goto out_free_driver; |
| 2056 | |
| 2057 | return 0; |
| 2058 | |
| 2059 | out_free_driver: |
| 2060 | driver_unregister(&idetape_driver.gen_driver); |
| 2061 | out_free_class: |
| 2062 | class_destroy(idetape_sysfs_class); |
| 2063 | out: |
| 2064 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2065 | } |
| 2066 | |
Kay Sievers | 263756e | 2005-12-12 18:03:44 +0100 | [diff] [blame] | 2067 | MODULE_ALIAS("ide:*m-tape*"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2068 | module_init(idetape_init); |
| 2069 | module_exit(idetape_exit); |
| 2070 | MODULE_ALIAS_CHARDEV_MAJOR(IDETAPE_MAJOR); |
Borislav Petkov | 9c14576 | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2071 | MODULE_DESCRIPTION("ATAPI Streaming TAPE Driver"); |
| 2072 | MODULE_LICENSE("GPL"); |