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) |
Christoph Hellwig | 82ed4db | 2017-01-27 09:46:29 +0100 | [diff] [blame] | 285 | scsi_req(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) && |
Christoph Hellwig | 82ed4db | 2017-01-27 09:46:29 +0100 | [diff] [blame] | 319 | (blk_rq_bytes(rq) - scsi_req(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 = |
Christoph Hellwig | 82ed4db | 2017-01-27 09:46:29 +0100 | [diff] [blame] | 351 | (blk_rq_bytes(rq) - scsi_req(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 | |
Christoph Hellwig | 82ed4db | 2017-01-27 09:46:29 +0100 | [diff] [blame] | 563 | memcpy(scsi_req(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; |
Christoph Hellwig | 82ed4db | 2017-01-27 09:46:29 +0100 | [diff] [blame] | 573 | struct scsi_request *req = scsi_req(rq); |
Bartlomiej Zolnierkiewicz | 22c525b | 2008-01-25 22:17:11 +0100 | [diff] [blame] | 574 | u8 stat; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | |
Borislav Petkov | e972d70 | 2009-07-17 23:55:16 +0000 | [diff] [blame] | 576 | ide_debug_log(IDE_DBG_RQ, "cmd: 0x%x, sector: %llu, nr_sectors: %u", |
Christoph Hellwig | 82ed4db | 2017-01-27 09:46:29 +0100 | [diff] [blame] | 577 | req->cmd[0], (unsigned long long)blk_rq_pos(rq), |
Borislav Petkov | e972d70 | 2009-07-17 23:55:16 +0000 | [diff] [blame] | 578 | blk_rq_sectors(rq)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | |
Christoph Hellwig | aebf526 | 2017-01-31 16:57:31 +0100 | [diff] [blame^] | 580 | BUG_ON(!blk_rq_is_private(rq)); |
Christoph Hellwig | 2f5a8e80 | 2017-01-31 16:57:30 +0100 | [diff] [blame] | 581 | BUG_ON(ide_req(rq)->type != ATA_PRIV_MISC && |
| 582 | ide_req(rq)->type != ATA_PRIV_SENSE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 584 | /* Retry a failed packet command */ |
Bartlomiej Zolnierkiewicz | 5e2040fd | 2009-03-27 12:46:34 +0100 | [diff] [blame] | 585 | if (drive->failed_pc && drive->pc->c[0] == REQUEST_SENSE) { |
| 586 | pc = drive->failed_pc; |
Bartlomiej Zolnierkiewicz | 28c7214 | 2008-07-15 21:21:59 +0200 | [diff] [blame] | 587 | goto out; |
| 588 | } |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 589 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | /* |
| 591 | * If the tape is still busy, postpone our request and service |
| 592 | * the other device meanwhile. |
| 593 | */ |
Bartlomiej Zolnierkiewicz | 374e042 | 2008-07-23 19:55:56 +0200 | [diff] [blame] | 594 | stat = hwif->tp_ops->read_status(hwif); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame] | 596 | if ((drive->dev_flags & IDE_DFLAG_DSC_OVERLAP) == 0 && |
Christoph Hellwig | 82ed4db | 2017-01-27 09:46:29 +0100 | [diff] [blame] | 597 | (req->cmd[13] & REQ_IDETAPE_PC2) == 0) |
Borislav Petkov | 626542c | 2009-06-07 15:37:05 +0200 | [diff] [blame] | 598 | drive->atapi_flags |= IDE_AFLAG_IGNORE_DSC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame] | 600 | if (drive->dev_flags & IDE_DFLAG_POST_RESET) { |
Borislav Petkov | 626542c | 2009-06-07 15:37:05 +0200 | [diff] [blame] | 601 | drive->atapi_flags |= IDE_AFLAG_IGNORE_DSC; |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame] | 602 | drive->dev_flags &= ~IDE_DFLAG_POST_RESET; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | } |
| 604 | |
Borislav Petkov | 626542c | 2009-06-07 15:37:05 +0200 | [diff] [blame] | 605 | if (!(drive->atapi_flags & IDE_AFLAG_IGNORE_DSC) && |
| 606 | !(stat & ATA_DSC)) { |
Borislav Petkov | 6f3848a | 2009-07-21 23:08:23 -0700 | [diff] [blame] | 607 | if (!tape->postponed_rq) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | tape->dsc_polling_start = jiffies; |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 609 | tape->dsc_poll_freq = tape->best_dsc_rw_freq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | tape->dsc_timeout = jiffies + IDETAPE_DSC_RW_TIMEOUT; |
| 611 | } else if (time_after(jiffies, tape->dsc_timeout)) { |
| 612 | printk(KERN_ERR "ide-tape: %s: DSC timeout\n", |
| 613 | tape->name); |
Christoph Hellwig | 82ed4db | 2017-01-27 09:46:29 +0100 | [diff] [blame] | 614 | if (req->cmd[13] & REQ_IDETAPE_PC2) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | idetape_media_access_finished(drive); |
| 616 | return ide_stopped; |
| 617 | } else { |
| 618 | return ide_do_reset(drive); |
| 619 | } |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 620 | } else if (time_after(jiffies, |
| 621 | tape->dsc_polling_start + |
| 622 | IDETAPE_DSC_MA_THRESHOLD)) |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 623 | tape->dsc_poll_freq = IDETAPE_DSC_MA_SLOW; |
Borislav Petkov | 6f3848a | 2009-07-21 23:08:23 -0700 | [diff] [blame] | 624 | ide_tape_stall_queue(drive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | return ide_stopped; |
Borislav Petkov | 6f3848a | 2009-07-21 23:08:23 -0700 | [diff] [blame] | 626 | } else { |
Borislav Petkov | 626542c | 2009-06-07 15:37:05 +0200 | [diff] [blame] | 627 | drive->atapi_flags &= ~IDE_AFLAG_IGNORE_DSC; |
Borislav Petkov | 6f3848a | 2009-07-21 23:08:23 -0700 | [diff] [blame] | 628 | tape->postponed_rq = false; |
| 629 | } |
Borislav Petkov | 626542c | 2009-06-07 15:37:05 +0200 | [diff] [blame] | 630 | |
Christoph Hellwig | 82ed4db | 2017-01-27 09:46:29 +0100 | [diff] [blame] | 631 | if (req->cmd[13] & REQ_IDETAPE_READ) { |
Bartlomiej Zolnierkiewicz | 2e8a6f8 | 2008-10-10 22:39:36 +0200 | [diff] [blame] | 632 | pc = &tape->queued_pc; |
Borislav Petkov | 0014c75 | 2008-07-23 19:56:00 +0200 | [diff] [blame] | 633 | ide_tape_create_rw_cmd(tape, pc, rq, READ_6); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | goto out; |
| 635 | } |
Christoph Hellwig | 82ed4db | 2017-01-27 09:46:29 +0100 | [diff] [blame] | 636 | if (req->cmd[13] & REQ_IDETAPE_WRITE) { |
Bartlomiej Zolnierkiewicz | 2e8a6f8 | 2008-10-10 22:39:36 +0200 | [diff] [blame] | 637 | pc = &tape->queued_pc; |
Borislav Petkov | 0014c75 | 2008-07-23 19:56:00 +0200 | [diff] [blame] | 638 | ide_tape_create_rw_cmd(tape, pc, rq, WRITE_6); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | goto out; |
| 640 | } |
Christoph Hellwig | 82ed4db | 2017-01-27 09:46:29 +0100 | [diff] [blame] | 641 | if (req->cmd[13] & REQ_IDETAPE_PC1) { |
Tejun Heo | c267cc1 | 2009-04-19 07:00:42 +0900 | [diff] [blame] | 642 | pc = (struct ide_atapi_pc *)rq->special; |
Christoph Hellwig | 82ed4db | 2017-01-27 09:46:29 +0100 | [diff] [blame] | 643 | req->cmd[13] &= ~(REQ_IDETAPE_PC1); |
| 644 | req->cmd[13] |= REQ_IDETAPE_PC2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | goto out; |
| 646 | } |
Christoph Hellwig | 82ed4db | 2017-01-27 09:46:29 +0100 | [diff] [blame] | 647 | if (req->cmd[13] & REQ_IDETAPE_PC2) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | idetape_media_access_finished(drive); |
| 649 | return ide_stopped; |
| 650 | } |
| 651 | BUG(); |
Bartlomiej Zolnierkiewicz | 28c7214 | 2008-07-15 21:21:59 +0200 | [diff] [blame] | 652 | |
Borislav Petkov | f2e3ab5 | 2008-07-23 19:56:01 +0200 | [diff] [blame] | 653 | out: |
Borislav Petkov | 6b544fc | 2009-04-19 07:00:42 +0900 | [diff] [blame] | 654 | /* prepare sense request for this command */ |
| 655 | ide_prep_sense(drive, rq); |
| 656 | |
Bartlomiej Zolnierkiewicz | b788ee9 | 2009-03-27 12:46:46 +0100 | [diff] [blame] | 657 | memset(&cmd, 0, sizeof(cmd)); |
| 658 | |
| 659 | if (rq_data_dir(rq)) |
| 660 | cmd.tf_flags |= IDE_TFLAG_WRITE; |
| 661 | |
| 662 | cmd.rq = rq; |
| 663 | |
Borislav Petkov | dfb7e62 | 2009-05-01 20:35:21 +0200 | [diff] [blame] | 664 | ide_init_sg_cmd(&cmd, blk_rq_bytes(rq)); |
Tejun Heo | 5c4be57 | 2009-04-19 07:00:42 +0900 | [diff] [blame] | 665 | ide_map_sg(drive, &cmd); |
| 666 | |
Bartlomiej Zolnierkiewicz | b788ee9 | 2009-03-27 12:46:46 +0100 | [diff] [blame] | 667 | return ide_tape_issue_pc(drive, &cmd, pc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | } |
| 669 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | /* |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 671 | * Write a filemark if write_filemark=1. Flush the device buffers without |
| 672 | * writing a filemark otherwise. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | */ |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 674 | static void idetape_create_write_filemark_cmd(ide_drive_t *drive, |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 675 | struct ide_atapi_pc *pc, int write_filemark) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | { |
Bartlomiej Zolnierkiewicz | 7bf7420 | 2008-10-10 22:39:37 +0200 | [diff] [blame] | 677 | ide_init_pc(pc); |
Borislav Petkov | 90699ce | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 678 | pc->c[0] = WRITE_FILEMARKS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | pc->c[4] = write_filemark; |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 680 | pc->flags |= PC_FLAG_WAIT_FOR_DSC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | } |
| 682 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | static int idetape_wait_ready(ide_drive_t *drive, unsigned long timeout) |
| 684 | { |
| 685 | idetape_tape_t *tape = drive->driver_data; |
Bartlomiej Zolnierkiewicz | 2ac07d9 | 2008-10-10 22:39:38 +0200 | [diff] [blame] | 686 | struct gendisk *disk = tape->disk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | int load_attempted = 0; |
| 688 | |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 689 | /* Wait for the tape to become ready */ |
Borislav Petkov | 49d8078 | 2009-06-07 15:37:06 +0200 | [diff] [blame] | 690 | set_bit(ilog2(IDE_AFLAG_MEDIUM_PRESENT), &drive->atapi_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | timeout += jiffies; |
| 692 | while (time_before(jiffies, timeout)) { |
Bartlomiej Zolnierkiewicz | de699ad | 2008-10-10 22:39:39 +0200 | [diff] [blame] | 693 | if (ide_do_test_unit_ready(drive, disk) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | return 0; |
| 695 | if ((tape->sense_key == 2 && tape->asc == 4 && tape->ascq == 2) |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 696 | || (tape->asc == 0x3A)) { |
| 697 | /* no media */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | if (load_attempted) |
| 699 | return -ENOMEDIUM; |
Bartlomiej Zolnierkiewicz | 0c8a6c7 | 2008-10-10 22:39:39 +0200 | [diff] [blame] | 700 | ide_do_start_stop(drive, disk, IDETAPE_LU_LOAD_MASK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | load_attempted = 1; |
| 702 | /* not about to be ready */ |
| 703 | } else if (!(tape->sense_key == 2 && tape->asc == 4 && |
| 704 | (tape->ascq == 1 || tape->ascq == 8))) |
| 705 | return -EIO; |
Nishanth Aravamudan | 80ce45f | 2005-09-10 00:27:08 -0700 | [diff] [blame] | 706 | msleep(100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | } |
| 708 | return -EIO; |
| 709 | } |
| 710 | |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 711 | static int idetape_flush_tape_buffers(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | { |
Bartlomiej Zolnierkiewicz | 2ac07d9 | 2008-10-10 22:39:38 +0200 | [diff] [blame] | 713 | struct ide_tape_obj *tape = drive->driver_data; |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 714 | struct ide_atapi_pc pc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | int rc; |
| 716 | |
| 717 | idetape_create_write_filemark_cmd(drive, &pc, 0); |
Borislav Petkov | b13345f | 2009-05-02 10:26:12 +0200 | [diff] [blame] | 718 | rc = ide_queue_pc_tail(drive, tape->disk, &pc, NULL, 0); |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 719 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | return rc; |
| 721 | idetape_wait_ready(drive, 60 * 5 * HZ); |
| 722 | return 0; |
| 723 | } |
| 724 | |
Borislav Petkov | 55ce3a1 | 2009-05-04 09:38:15 +0200 | [diff] [blame] | 725 | static int ide_tape_read_position(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | { |
| 727 | idetape_tape_t *tape = drive->driver_data; |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 728 | struct ide_atapi_pc pc; |
Borislav Petkov | 55ce3a1 | 2009-05-04 09:38:15 +0200 | [diff] [blame] | 729 | u8 buf[20]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | |
Borislav Petkov | e972d70 | 2009-07-17 23:55:16 +0000 | [diff] [blame] | 731 | ide_debug_log(IDE_DBG_FUNC, "enter"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | |
Borislav Petkov | 55ce3a1 | 2009-05-04 09:38:15 +0200 | [diff] [blame] | 733 | /* prep cmd */ |
| 734 | ide_init_pc(&pc); |
| 735 | pc.c[0] = READ_POSITION; |
| 736 | pc.req_xfer = 20; |
| 737 | |
| 738 | 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] | 739 | return -1; |
Borislav Petkov | 55ce3a1 | 2009-05-04 09:38:15 +0200 | [diff] [blame] | 740 | |
| 741 | if (!pc.error) { |
Borislav Petkov | e972d70 | 2009-07-17 23:55:16 +0000 | [diff] [blame] | 742 | ide_debug_log(IDE_DBG_FUNC, "BOP - %s", |
Borislav Petkov | 55ce3a1 | 2009-05-04 09:38:15 +0200 | [diff] [blame] | 743 | (buf[0] & 0x80) ? "Yes" : "No"); |
Borislav Petkov | e972d70 | 2009-07-17 23:55:16 +0000 | [diff] [blame] | 744 | ide_debug_log(IDE_DBG_FUNC, "EOP - %s", |
Borislav Petkov | 55ce3a1 | 2009-05-04 09:38:15 +0200 | [diff] [blame] | 745 | (buf[0] & 0x40) ? "Yes" : "No"); |
| 746 | |
| 747 | if (buf[0] & 0x4) { |
| 748 | printk(KERN_INFO "ide-tape: Block location is unknown" |
| 749 | "to the tape\n"); |
Bartlomiej Zolnierkiewicz | 8dcce40 | 2009-06-13 12:00:54 +0200 | [diff] [blame] | 750 | clear_bit(ilog2(IDE_AFLAG_ADDRESS_VALID), |
| 751 | &drive->atapi_flags); |
Borislav Petkov | 55ce3a1 | 2009-05-04 09:38:15 +0200 | [diff] [blame] | 752 | return -1; |
| 753 | } else { |
Borislav Petkov | e972d70 | 2009-07-17 23:55:16 +0000 | [diff] [blame] | 754 | ide_debug_log(IDE_DBG_FUNC, "Block Location: %u", |
| 755 | be32_to_cpup((__be32 *)&buf[4])); |
Borislav Petkov | 55ce3a1 | 2009-05-04 09:38:15 +0200 | [diff] [blame] | 756 | |
| 757 | tape->partition = buf[1]; |
| 758 | tape->first_frame = be32_to_cpup((__be32 *)&buf[4]); |
Bartlomiej Zolnierkiewicz | 8dcce40 | 2009-06-13 12:00:54 +0200 | [diff] [blame] | 759 | set_bit(ilog2(IDE_AFLAG_ADDRESS_VALID), |
| 760 | &drive->atapi_flags); |
Borislav Petkov | 55ce3a1 | 2009-05-04 09:38:15 +0200 | [diff] [blame] | 761 | } |
| 762 | } |
| 763 | |
| 764 | return tape->first_frame; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | } |
| 766 | |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 767 | static void idetape_create_locate_cmd(ide_drive_t *drive, |
| 768 | struct ide_atapi_pc *pc, |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 769 | unsigned int block, u8 partition, int skip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | { |
Bartlomiej Zolnierkiewicz | 7bf7420 | 2008-10-10 22:39:37 +0200 | [diff] [blame] | 771 | ide_init_pc(pc); |
Borislav Petkov | 90699ce | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 772 | pc->c[0] = POSITION_TO_ELEMENT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | pc->c[1] = 2; |
Borislav Petkov | 860ff5e | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 774 | put_unaligned(cpu_to_be32(block), (unsigned int *) &pc->c[3]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | pc->c[8] = partition; |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 776 | pc->flags |= PC_FLAG_WAIT_FOR_DSC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | } |
| 778 | |
Borislav Petkov | ec0fdb0 | 2008-04-27 15:38:34 +0200 | [diff] [blame] | 779 | static void __ide_tape_discard_merge_buffer(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | { |
| 781 | idetape_tape_t *tape = drive->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | |
Borislav Petkov | 54abf37 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 783 | if (tape->chrdev_dir != IDETAPE_DIR_READ) |
Borislav Petkov | 9798630 | 2008-04-27 15:38:34 +0200 | [diff] [blame] | 784 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | |
Borislav Petkov | 49d8078 | 2009-06-07 15:37:06 +0200 | [diff] [blame] | 786 | clear_bit(ilog2(IDE_AFLAG_FILEMARK), &drive->atapi_flags); |
Tejun Heo | 963da55 | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 787 | tape->valid = 0; |
| 788 | if (tape->buf != NULL) { |
| 789 | kfree(tape->buf); |
| 790 | tape->buf = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | } |
| 792 | |
Borislav Petkov | 54abf37 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 793 | tape->chrdev_dir = IDETAPE_DIR_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | } |
| 795 | |
| 796 | /* |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 797 | * Position the tape to the requested block using the LOCATE packet command. |
| 798 | * A READ POSITION command is then issued to check where we are positioned. Like |
| 799 | * all higher level operations, we queue the commands at the tail of the request |
| 800 | * queue and wait for their completion. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | */ |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 802 | static int idetape_position_tape(ide_drive_t *drive, unsigned int block, |
| 803 | u8 partition, int skip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | { |
| 805 | idetape_tape_t *tape = drive->driver_data; |
Bartlomiej Zolnierkiewicz | 2ac07d9 | 2008-10-10 22:39:38 +0200 | [diff] [blame] | 806 | struct gendisk *disk = tape->disk; |
Borislav Petkov | 55ce3a1 | 2009-05-04 09:38:15 +0200 | [diff] [blame] | 807 | int ret; |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 808 | struct ide_atapi_pc pc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | |
Borislav Petkov | 54abf37 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 810 | if (tape->chrdev_dir == IDETAPE_DIR_READ) |
Borislav Petkov | ec0fdb0 | 2008-04-27 15:38:34 +0200 | [diff] [blame] | 811 | __ide_tape_discard_merge_buffer(drive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | idetape_wait_ready(drive, 60 * 5 * HZ); |
| 813 | idetape_create_locate_cmd(drive, &pc, block, partition, skip); |
Borislav Petkov | 55ce3a1 | 2009-05-04 09:38:15 +0200 | [diff] [blame] | 814 | ret = ide_queue_pc_tail(drive, disk, &pc, NULL, 0); |
| 815 | if (ret) |
| 816 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | |
Borislav Petkov | 55ce3a1 | 2009-05-04 09:38:15 +0200 | [diff] [blame] | 818 | ret = ide_tape_read_position(drive); |
| 819 | if (ret < 0) |
| 820 | return ret; |
| 821 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | } |
| 823 | |
Borislav Petkov | ec0fdb0 | 2008-04-27 15:38:34 +0200 | [diff] [blame] | 824 | static void ide_tape_discard_merge_buffer(ide_drive_t *drive, |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 825 | int restore_position) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | { |
| 827 | idetape_tape_t *tape = drive->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | int seek, position; |
| 829 | |
Borislav Petkov | ec0fdb0 | 2008-04-27 15:38:34 +0200 | [diff] [blame] | 830 | __ide_tape_discard_merge_buffer(drive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | if (restore_position) { |
Borislav Petkov | 55ce3a1 | 2009-05-04 09:38:15 +0200 | [diff] [blame] | 832 | position = ide_tape_read_position(drive); |
Borislav Petkov | 9798630 | 2008-04-27 15:38:34 +0200 | [diff] [blame] | 833 | seek = position > 0 ? position : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | if (idetape_position_tape(drive, seek, 0, 0)) { |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 835 | printk(KERN_INFO "ide-tape: %s: position_tape failed in" |
Borislav Petkov | ec0fdb0 | 2008-04-27 15:38:34 +0200 | [diff] [blame] | 836 | " %s\n", tape->name, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | return; |
| 838 | } |
| 839 | } |
| 840 | } |
| 841 | |
| 842 | /* |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 843 | * Generate a read/write request for the block device interface and wait for it |
| 844 | * to be serviced. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | */ |
Tejun Heo | 6bb11dd | 2009-04-19 08:46:03 +0900 | [diff] [blame] | 846 | 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] | 847 | { |
| 848 | idetape_tape_t *tape = drive->driver_data; |
FUJITA Tomonori | 64ea1b4 | 2008-07-15 21:21:43 +0200 | [diff] [blame] | 849 | struct request *rq; |
Tejun Heo | 21d9c5d | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 850 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 | |
Borislav Petkov | e972d70 | 2009-07-17 23:55:16 +0000 | [diff] [blame] | 852 | ide_debug_log(IDE_DBG_FUNC, "cmd: 0x%x, size: %d", cmd, size); |
| 853 | |
Tejun Heo | 21d9c5d | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 854 | BUG_ON(cmd != REQ_IDETAPE_READ && cmd != REQ_IDETAPE_WRITE); |
Tejun Heo | 6bb11dd | 2009-04-19 08:46:03 +0900 | [diff] [blame] | 855 | BUG_ON(size < 0 || size % tape->blk_size); |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 856 | |
Christoph Hellwig | aebf526 | 2017-01-31 16:57:31 +0100 | [diff] [blame^] | 857 | rq = blk_get_request(drive->queue, REQ_OP_DRV_IN, __GFP_RECLAIM); |
Christoph Hellwig | 82ed4db | 2017-01-27 09:46:29 +0100 | [diff] [blame] | 858 | scsi_req_init(rq); |
Christoph Hellwig | 2f5a8e80 | 2017-01-31 16:57:30 +0100 | [diff] [blame] | 859 | ide_req(rq)->type = ATA_PRIV_MISC; |
Christoph Hellwig | 82ed4db | 2017-01-27 09:46:29 +0100 | [diff] [blame] | 860 | scsi_req(rq)->cmd[13] = cmd; |
FUJITA Tomonori | 64ea1b4 | 2008-07-15 21:21:43 +0200 | [diff] [blame] | 861 | rq->rq_disk = tape->disk; |
Linus Torvalds | c905959 | 2009-06-11 10:52:27 -0700 | [diff] [blame] | 862 | rq->__sector = tape->first_frame; |
Tejun Heo | 21d9c5d | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 863 | |
| 864 | if (size) { |
Tejun Heo | 963da55 | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 865 | ret = blk_rq_map_kern(drive->queue, rq, tape->buf, size, |
Mel Gorman | 71baba4 | 2015-11-06 16:28:28 -0800 | [diff] [blame] | 866 | __GFP_RECLAIM); |
Tejun Heo | 21d9c5d | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 867 | if (ret) |
| 868 | goto out_put; |
| 869 | } |
| 870 | |
FUJITA Tomonori | 64ea1b4 | 2008-07-15 21:21:43 +0200 | [diff] [blame] | 871 | blk_execute_rq(drive->queue, tape->disk, rq, 0); |
| 872 | |
Tejun Heo | 963da55 | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 873 | /* calculate the number of transferred bytes and update buffer state */ |
Christoph Hellwig | 82ed4db | 2017-01-27 09:46:29 +0100 | [diff] [blame] | 874 | size -= scsi_req(rq)->resid_len; |
Tejun Heo | 963da55 | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 875 | tape->cur = tape->buf; |
Tejun Heo | 21d9c5d | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 876 | if (cmd == REQ_IDETAPE_READ) |
Tejun Heo | 963da55 | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 877 | tape->valid = size; |
| 878 | else |
| 879 | tape->valid = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | |
Tejun Heo | 21d9c5d | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 881 | ret = size; |
| 882 | if (rq->errors == IDE_DRV_ERROR_GENERAL) |
| 883 | ret = -EIO; |
Tejun Heo | 21d9c5d | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 884 | out_put: |
| 885 | blk_put_request(rq); |
FUJITA Tomonori | 64ea1b4 | 2008-07-15 21:21:43 +0200 | [diff] [blame] | 886 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | } |
| 888 | |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 889 | static void idetape_create_inquiry_cmd(struct ide_atapi_pc *pc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 | { |
Bartlomiej Zolnierkiewicz | 7bf7420 | 2008-10-10 22:39:37 +0200 | [diff] [blame] | 891 | ide_init_pc(pc); |
Borislav Petkov | 90699ce | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 892 | pc->c[0] = INQUIRY; |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 893 | pc->c[4] = 254; |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 894 | pc->req_xfer = 254; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | } |
| 896 | |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 897 | static void idetape_create_rewind_cmd(ide_drive_t *drive, |
| 898 | struct ide_atapi_pc *pc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | { |
Bartlomiej Zolnierkiewicz | 7bf7420 | 2008-10-10 22:39:37 +0200 | [diff] [blame] | 900 | ide_init_pc(pc); |
Borislav Petkov | 90699ce | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 901 | pc->c[0] = REZERO_UNIT; |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 902 | pc->flags |= PC_FLAG_WAIT_FOR_DSC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | } |
| 904 | |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 905 | static void idetape_create_erase_cmd(struct ide_atapi_pc *pc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 | { |
Bartlomiej Zolnierkiewicz | 7bf7420 | 2008-10-10 22:39:37 +0200 | [diff] [blame] | 907 | ide_init_pc(pc); |
Borislav Petkov | 90699ce | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 908 | pc->c[0] = ERASE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | pc->c[1] = 1; |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 910 | pc->flags |= PC_FLAG_WAIT_FOR_DSC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 | } |
| 912 | |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 913 | 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] | 914 | { |
Bartlomiej Zolnierkiewicz | 7bf7420 | 2008-10-10 22:39:37 +0200 | [diff] [blame] | 915 | ide_init_pc(pc); |
Borislav Petkov | 90699ce | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 916 | pc->c[0] = SPACE; |
Borislav Petkov | 860ff5e | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 917 | put_unaligned(cpu_to_be32(count), (unsigned int *) &pc->c[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | pc->c[1] = cmd; |
Borislav Petkov | 346331f | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 919 | pc->flags |= PC_FLAG_WAIT_FOR_DSC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | } |
| 921 | |
Borislav Petkov | d9df937 | 2008-04-27 15:38:34 +0200 | [diff] [blame] | 922 | static void ide_tape_flush_merge_buffer(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | { |
| 924 | idetape_tape_t *tape = drive->driver_data; |
Borislav Petkov | 55a5d29 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 925 | |
Borislav Petkov | 54abf37 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 926 | if (tape->chrdev_dir != IDETAPE_DIR_WRITE) { |
Borislav Petkov | 077e3bd | 2008-04-27 15:38:34 +0200 | [diff] [blame] | 927 | printk(KERN_ERR "ide-tape: bug: Trying to empty merge buffer" |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 928 | " but we are not writing.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | return; |
| 930 | } |
Tejun Heo | 963da55 | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 931 | if (tape->buf) { |
Tejun Heo | 6bb11dd | 2009-04-19 08:46:03 +0900 | [diff] [blame] | 932 | size_t aligned = roundup(tape->valid, tape->blk_size); |
| 933 | |
| 934 | memset(tape->cur, 0, aligned - tape->valid); |
Tejun Heo | 07bd968 | 2009-04-19 08:46:03 +0900 | [diff] [blame] | 935 | idetape_queue_rw_tail(drive, REQ_IDETAPE_WRITE, aligned); |
Tejun Heo | 963da55 | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 936 | kfree(tape->buf); |
| 937 | tape->buf = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | } |
Borislav Petkov | 54abf37 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 939 | tape->chrdev_dir = IDETAPE_DIR_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | } |
| 941 | |
Tejun Heo | 88f1b94 | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 942 | static int idetape_init_rw(ide_drive_t *drive, int dir) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 943 | { |
| 944 | idetape_tape_t *tape = drive->driver_data; |
Tejun Heo | 88f1b94 | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 945 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | |
Tejun Heo | 88f1b94 | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 947 | BUG_ON(dir != IDETAPE_DIR_READ && dir != IDETAPE_DIR_WRITE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | |
Tejun Heo | 88f1b94 | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 949 | if (tape->chrdev_dir == dir) |
| 950 | return 0; |
| 951 | |
| 952 | if (tape->chrdev_dir == IDETAPE_DIR_READ) |
| 953 | ide_tape_discard_merge_buffer(drive, 1); |
| 954 | else if (tape->chrdev_dir == IDETAPE_DIR_WRITE) { |
| 955 | ide_tape_flush_merge_buffer(drive); |
| 956 | idetape_flush_tape_buffers(drive); |
| 957 | } |
| 958 | |
| 959 | if (tape->buf || tape->valid) { |
| 960 | printk(KERN_ERR "ide-tape: valid should be 0 now\n"); |
| 961 | tape->valid = 0; |
| 962 | } |
| 963 | |
| 964 | tape->buf = kmalloc(tape->buffer_size, GFP_KERNEL); |
| 965 | if (!tape->buf) |
| 966 | return -ENOMEM; |
| 967 | tape->chrdev_dir = dir; |
| 968 | tape->cur = tape->buf; |
| 969 | |
| 970 | /* |
| 971 | * Issue a 0 rw command to ensure that DSC handshake is |
| 972 | * switched from completion mode to buffer available mode. No |
| 973 | * point in issuing this if DSC overlap isn't supported, some |
| 974 | * drives (Seagate STT3401A) will return an error. |
| 975 | */ |
| 976 | if (drive->dev_flags & IDE_DFLAG_DSC_OVERLAP) { |
| 977 | int cmd = dir == IDETAPE_DIR_READ ? REQ_IDETAPE_READ |
| 978 | : REQ_IDETAPE_WRITE; |
| 979 | |
| 980 | rc = idetape_queue_rw_tail(drive, cmd, 0); |
| 981 | if (rc < 0) { |
| 982 | kfree(tape->buf); |
| 983 | tape->buf = NULL; |
| 984 | tape->chrdev_dir = IDETAPE_DIR_NONE; |
| 985 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 986 | } |
| 987 | } |
Borislav Petkov | 5e69bd9 | 2008-04-27 15:38:25 +0200 | [diff] [blame] | 988 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 989 | return 0; |
| 990 | } |
| 991 | |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 992 | static void idetape_pad_zeros(ide_drive_t *drive, int bcount) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 993 | { |
| 994 | idetape_tape_t *tape = drive->driver_data; |
Tejun Heo | 963da55 | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 995 | |
| 996 | memset(tape->buf, 0, tape->buffer_size); |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 997 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 998 | while (bcount) { |
Tejun Heo | 963da55 | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 999 | unsigned int count = min(tape->buffer_size, bcount); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1000 | |
Tejun Heo | 6bb11dd | 2009-04-19 08:46:03 +0900 | [diff] [blame] | 1001 | idetape_queue_rw_tail(drive, REQ_IDETAPE_WRITE, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | bcount -= count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1003 | } |
| 1004 | } |
| 1005 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1006 | /* |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 1007 | * Rewinds the tape to the Beginning Of the current Partition (BOP). We |
| 1008 | * currently support only one partition. |
| 1009 | */ |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1010 | static int idetape_rewind_tape(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1011 | { |
Bartlomiej Zolnierkiewicz | 2ac07d9 | 2008-10-10 22:39:38 +0200 | [diff] [blame] | 1012 | struct ide_tape_obj *tape = drive->driver_data; |
| 1013 | struct gendisk *disk = tape->disk; |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1014 | struct ide_atapi_pc pc; |
Borislav Petkov | 55ce3a1 | 2009-05-04 09:38:15 +0200 | [diff] [blame] | 1015 | int ret; |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 1016 | |
Borislav Petkov | e972d70 | 2009-07-17 23:55:16 +0000 | [diff] [blame] | 1017 | ide_debug_log(IDE_DBG_FUNC, "enter"); |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 1018 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | idetape_create_rewind_cmd(drive, &pc); |
Borislav Petkov | 55ce3a1 | 2009-05-04 09:38:15 +0200 | [diff] [blame] | 1020 | ret = ide_queue_pc_tail(drive, disk, &pc, NULL, 0); |
| 1021 | if (ret) |
| 1022 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 | |
Borislav Petkov | 55ce3a1 | 2009-05-04 09:38:15 +0200 | [diff] [blame] | 1024 | ret = ide_tape_read_position(drive); |
| 1025 | if (ret < 0) |
| 1026 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1027 | return 0; |
| 1028 | } |
| 1029 | |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 1030 | /* mtio.h compatible commands should be issued to the chrdev interface. */ |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1031 | static int idetape_blkdev_ioctl(ide_drive_t *drive, unsigned int cmd, |
| 1032 | unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1033 | { |
| 1034 | idetape_tape_t *tape = drive->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1035 | void __user *argp = (void __user *)arg; |
| 1036 | |
Borislav Petkov | d59823f | 2008-02-02 19:56:51 +0100 | [diff] [blame] | 1037 | struct idetape_config { |
| 1038 | int dsc_rw_frequency; |
| 1039 | int dsc_media_access_frequency; |
| 1040 | int nr_stages; |
| 1041 | } config; |
| 1042 | |
Borislav Petkov | e972d70 | 2009-07-17 23:55:16 +0000 | [diff] [blame] | 1043 | ide_debug_log(IDE_DBG_FUNC, "cmd: 0x%04x", cmd); |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 1044 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1045 | switch (cmd) { |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1046 | case 0x0340: |
| 1047 | if (copy_from_user(&config, argp, sizeof(config))) |
| 1048 | return -EFAULT; |
| 1049 | tape->best_dsc_rw_freq = config.dsc_rw_frequency; |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1050 | break; |
| 1051 | case 0x0350: |
Michael Buesch | 2fc2111 | 2009-07-19 09:15:19 +0000 | [diff] [blame] | 1052 | memset(&config, 0, sizeof(config)); |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1053 | config.dsc_rw_frequency = (int) tape->best_dsc_rw_freq; |
Borislav Petkov | 83042b2 | 2008-04-27 15:38:27 +0200 | [diff] [blame] | 1054 | config.nr_stages = 1; |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1055 | if (copy_to_user(argp, &config, sizeof(config))) |
| 1056 | return -EFAULT; |
| 1057 | break; |
| 1058 | default: |
| 1059 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1060 | } |
| 1061 | return 0; |
| 1062 | } |
| 1063 | |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1064 | static int idetape_space_over_filemarks(ide_drive_t *drive, short mt_op, |
| 1065 | int mt_count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1066 | { |
| 1067 | idetape_tape_t *tape = drive->driver_data; |
Bartlomiej Zolnierkiewicz | 2ac07d9 | 2008-10-10 22:39:38 +0200 | [diff] [blame] | 1068 | struct gendisk *disk = tape->disk; |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1069 | struct ide_atapi_pc pc; |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1070 | int retval, count = 0; |
Borislav Petkov | b642201 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 1071 | int sprev = !!(tape->caps[4] & 0x20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 | |
Borislav Petkov | e972d70 | 2009-07-17 23:55:16 +0000 | [diff] [blame] | 1073 | |
| 1074 | ide_debug_log(IDE_DBG_FUNC, "mt_op: %d, mt_count: %d", mt_op, mt_count); |
| 1075 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | if (mt_count == 0) |
| 1077 | return 0; |
| 1078 | if (MTBSF == mt_op || MTBSFM == mt_op) { |
Borislav Petkov | b642201 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 1079 | if (!sprev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1080 | return -EIO; |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1081 | mt_count = -mt_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1082 | } |
| 1083 | |
Borislav Petkov | 54abf37 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1084 | if (tape->chrdev_dir == IDETAPE_DIR_READ) { |
Tejun Heo | 963da55 | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 1085 | tape->valid = 0; |
Borislav Petkov | 49d8078 | 2009-06-07 15:37:06 +0200 | [diff] [blame] | 1086 | if (test_and_clear_bit(ilog2(IDE_AFLAG_FILEMARK), |
| 1087 | &drive->atapi_flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1088 | ++count; |
Borislav Petkov | ec0fdb0 | 2008-04-27 15:38:34 +0200 | [diff] [blame] | 1089 | ide_tape_discard_merge_buffer(drive, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1090 | } |
| 1091 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1092 | switch (mt_op) { |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1093 | case MTFSF: |
| 1094 | case MTBSF: |
| 1095 | idetape_create_space_cmd(&pc, mt_count - count, |
| 1096 | IDETAPE_SPACE_OVER_FILEMARK); |
Borislav Petkov | b13345f | 2009-05-02 10:26:12 +0200 | [diff] [blame] | 1097 | return ide_queue_pc_tail(drive, disk, &pc, NULL, 0); |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1098 | case MTFSFM: |
| 1099 | case MTBSFM: |
| 1100 | if (!sprev) |
| 1101 | return -EIO; |
| 1102 | retval = idetape_space_over_filemarks(drive, MTFSF, |
| 1103 | mt_count - count); |
| 1104 | if (retval) |
| 1105 | return retval; |
| 1106 | count = (MTBSFM == mt_op ? 1 : -1); |
| 1107 | return idetape_space_over_filemarks(drive, MTFSF, count); |
| 1108 | default: |
| 1109 | printk(KERN_ERR "ide-tape: MTIO operation %d not supported\n", |
| 1110 | mt_op); |
| 1111 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1112 | } |
| 1113 | } |
| 1114 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1115 | /* |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 1116 | * Our character device read / write functions. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1117 | * |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 1118 | * The tape is optimized to maximize throughput when it is transferring an |
| 1119 | * integral number of the "continuous transfer limit", which is a parameter of |
| 1120 | * the specific tape (26kB on my particular tape, 32kB for Onstream). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1121 | * |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 1122 | * As of version 1.3 of the driver, the character device provides an abstract |
| 1123 | * continuous view of the media - any mix of block sizes (even 1 byte) on the |
| 1124 | * same backup/restore procedure is supported. The driver will internally |
| 1125 | * convert the requests to the recommended transfer unit, so that an unmatch |
| 1126 | * between the user's block size to the recommended size will only result in a |
| 1127 | * (slightly) increased driver overhead, but will no longer hit performance. |
| 1128 | * This is not applicable to Onstream. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1129 | */ |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1130 | static ssize_t idetape_chrdev_read(struct file *file, char __user *buf, |
| 1131 | size_t count, loff_t *ppos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1132 | { |
Borislav Petkov | 5aeddf9 | 2008-10-13 21:39:34 +0200 | [diff] [blame] | 1133 | struct ide_tape_obj *tape = file->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1134 | ide_drive_t *drive = tape->drive; |
Tejun Heo | 07bd968 | 2009-04-19 08:46:03 +0900 | [diff] [blame] | 1135 | size_t done = 0; |
Daniel Walker | dcd9637 | 2006-06-25 05:47:37 -0700 | [diff] [blame] | 1136 | ssize_t ret = 0; |
Tejun Heo | 07bd968 | 2009-04-19 08:46:03 +0900 | [diff] [blame] | 1137 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1138 | |
Borislav Petkov | e972d70 | 2009-07-17 23:55:16 +0000 | [diff] [blame] | 1139 | ide_debug_log(IDE_DBG_FUNC, "count %Zd", count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1140 | |
Borislav Petkov | 54abf37 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1141 | if (tape->chrdev_dir != IDETAPE_DIR_READ) { |
Borislav Petkov | 49d8078 | 2009-06-07 15:37:06 +0200 | [diff] [blame] | 1142 | if (test_bit(ilog2(IDE_AFLAG_DETECT_BS), &drive->atapi_flags)) |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1143 | if (count > tape->blk_size && |
| 1144 | (count % tape->blk_size) == 0) |
| 1145 | tape->user_bs_factor = count / tape->blk_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1146 | } |
Tejun Heo | 07bd968 | 2009-04-19 08:46:03 +0900 | [diff] [blame] | 1147 | |
Tejun Heo | 88f1b94 | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 1148 | rc = idetape_init_rw(drive, IDETAPE_DIR_READ); |
Borislav Petkov | 8d06bfa | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 1149 | if (rc < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1150 | return rc; |
Tejun Heo | 07bd968 | 2009-04-19 08:46:03 +0900 | [diff] [blame] | 1151 | |
| 1152 | while (done < count) { |
| 1153 | size_t todo; |
| 1154 | |
| 1155 | /* refill if staging buffer is empty */ |
| 1156 | if (!tape->valid) { |
| 1157 | /* If we are at a filemark, nothing more to read */ |
Borislav Petkov | 49d8078 | 2009-06-07 15:37:06 +0200 | [diff] [blame] | 1158 | if (test_bit(ilog2(IDE_AFLAG_FILEMARK), |
| 1159 | &drive->atapi_flags)) |
Tejun Heo | 07bd968 | 2009-04-19 08:46:03 +0900 | [diff] [blame] | 1160 | break; |
| 1161 | /* read */ |
| 1162 | if (idetape_queue_rw_tail(drive, REQ_IDETAPE_READ, |
| 1163 | tape->buffer_size) <= 0) |
| 1164 | break; |
| 1165 | } |
| 1166 | |
| 1167 | /* copy out */ |
| 1168 | todo = min_t(size_t, count - done, tape->valid); |
| 1169 | if (copy_to_user(buf + done, tape->cur, todo)) |
Daniel Walker | dcd9637 | 2006-06-25 05:47:37 -0700 | [diff] [blame] | 1170 | ret = -EFAULT; |
Tejun Heo | 07bd968 | 2009-04-19 08:46:03 +0900 | [diff] [blame] | 1171 | |
| 1172 | tape->cur += todo; |
| 1173 | tape->valid -= todo; |
| 1174 | done += todo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1175 | } |
Tejun Heo | 07bd968 | 2009-04-19 08:46:03 +0900 | [diff] [blame] | 1176 | |
Borislav Petkov | 49d8078 | 2009-06-07 15:37:06 +0200 | [diff] [blame] | 1177 | if (!done && test_bit(ilog2(IDE_AFLAG_FILEMARK), &drive->atapi_flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1178 | idetape_space_over_filemarks(drive, MTFSF, 1); |
| 1179 | return 0; |
| 1180 | } |
Daniel Walker | dcd9637 | 2006-06-25 05:47:37 -0700 | [diff] [blame] | 1181 | |
Tejun Heo | 07bd968 | 2009-04-19 08:46:03 +0900 | [diff] [blame] | 1182 | return ret ? ret : done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1183 | } |
| 1184 | |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1185 | 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] | 1186 | size_t count, loff_t *ppos) |
| 1187 | { |
Borislav Petkov | 5aeddf9 | 2008-10-13 21:39:34 +0200 | [diff] [blame] | 1188 | struct ide_tape_obj *tape = file->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1189 | ide_drive_t *drive = tape->drive; |
Tejun Heo | 07bd968 | 2009-04-19 08:46:03 +0900 | [diff] [blame] | 1190 | size_t done = 0; |
Daniel Walker | dcd9637 | 2006-06-25 05:47:37 -0700 | [diff] [blame] | 1191 | ssize_t ret = 0; |
Tejun Heo | 88f1b94 | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 1192 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1193 | |
| 1194 | /* The drive is write protected. */ |
| 1195 | if (tape->write_prot) |
| 1196 | return -EACCES; |
| 1197 | |
Borislav Petkov | e972d70 | 2009-07-17 23:55:16 +0000 | [diff] [blame] | 1198 | ide_debug_log(IDE_DBG_FUNC, "count %Zd", count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1199 | |
| 1200 | /* Initialize write operation */ |
Tejun Heo | 88f1b94 | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 1201 | rc = idetape_init_rw(drive, IDETAPE_DIR_WRITE); |
| 1202 | if (rc < 0) |
| 1203 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1204 | |
Tejun Heo | 07bd968 | 2009-04-19 08:46:03 +0900 | [diff] [blame] | 1205 | while (done < count) { |
| 1206 | size_t todo; |
| 1207 | |
| 1208 | /* flush if staging buffer is full */ |
| 1209 | if (tape->valid == tape->buffer_size && |
| 1210 | idetape_queue_rw_tail(drive, REQ_IDETAPE_WRITE, |
| 1211 | tape->buffer_size) <= 0) |
| 1212 | return rc; |
| 1213 | |
| 1214 | /* copy in */ |
| 1215 | todo = min_t(size_t, count - done, |
| 1216 | tape->buffer_size - tape->valid); |
| 1217 | if (copy_from_user(tape->cur, buf + done, todo)) |
Daniel Walker | dcd9637 | 2006-06-25 05:47:37 -0700 | [diff] [blame] | 1218 | ret = -EFAULT; |
Tejun Heo | 07bd968 | 2009-04-19 08:46:03 +0900 | [diff] [blame] | 1219 | |
| 1220 | tape->cur += todo; |
| 1221 | tape->valid += todo; |
| 1222 | done += todo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1223 | } |
Tejun Heo | 07bd968 | 2009-04-19 08:46:03 +0900 | [diff] [blame] | 1224 | |
| 1225 | return ret ? ret : done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1226 | } |
| 1227 | |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1228 | static int idetape_write_filemark(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1229 | { |
Bartlomiej Zolnierkiewicz | 2ac07d9 | 2008-10-10 22:39:38 +0200 | [diff] [blame] | 1230 | struct ide_tape_obj *tape = drive->driver_data; |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1231 | struct ide_atapi_pc pc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1232 | |
| 1233 | /* Write a filemark */ |
| 1234 | idetape_create_write_filemark_cmd(drive, &pc, 1); |
Borislav Petkov | b13345f | 2009-05-02 10:26:12 +0200 | [diff] [blame] | 1235 | if (ide_queue_pc_tail(drive, tape->disk, &pc, NULL, 0)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1236 | printk(KERN_ERR "ide-tape: Couldn't write a filemark\n"); |
| 1237 | return -EIO; |
| 1238 | } |
| 1239 | return 0; |
| 1240 | } |
| 1241 | |
| 1242 | /* |
Borislav Petkov | d99c9da | 2008-02-02 19:56:51 +0100 | [diff] [blame] | 1243 | * Called from idetape_chrdev_ioctl when the general mtio MTIOCTOP ioctl is |
| 1244 | * requested. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1245 | * |
Borislav Petkov | d99c9da | 2008-02-02 19:56:51 +0100 | [diff] [blame] | 1246 | * Note: MTBSF and MTBSFM are not supported when the tape doesn't support |
| 1247 | * 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] | 1248 | * usually not supported. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1249 | * |
Borislav Petkov | d99c9da | 2008-02-02 19:56:51 +0100 | [diff] [blame] | 1250 | * The following commands are currently not supported: |
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 | * MTFSS, MTBSS, MTWSM, MTSETDENSITY, MTSETDRVBUFFER, MT_ST_BOOLEANS, |
| 1253 | * MT_ST_WRITE_THRESHOLD. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1254 | */ |
Borislav Petkov | d99c9da | 2008-02-02 19:56:51 +0100 | [diff] [blame] | 1255 | 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] | 1256 | { |
| 1257 | idetape_tape_t *tape = drive->driver_data; |
Bartlomiej Zolnierkiewicz | 2ac07d9 | 2008-10-10 22:39:38 +0200 | [diff] [blame] | 1258 | struct gendisk *disk = tape->disk; |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1259 | struct ide_atapi_pc pc; |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1260 | int i, retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1261 | |
Borislav Petkov | e972d70 | 2009-07-17 23:55:16 +0000 | [diff] [blame] | 1262 | ide_debug_log(IDE_DBG_FUNC, "MTIOCTOP ioctl: mt_op: %d, mt_count: %d", |
| 1263 | mt_op, mt_count); |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1264 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1265 | switch (mt_op) { |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1266 | case MTFSF: |
| 1267 | case MTFSFM: |
| 1268 | case MTBSF: |
| 1269 | case MTBSFM: |
| 1270 | if (!mt_count) |
| 1271 | return 0; |
| 1272 | return idetape_space_over_filemarks(drive, mt_op, mt_count); |
| 1273 | default: |
| 1274 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1275 | } |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1276 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1277 | switch (mt_op) { |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1278 | case MTWEOF: |
| 1279 | if (tape->write_prot) |
| 1280 | return -EACCES; |
Borislav Petkov | ec0fdb0 | 2008-04-27 15:38:34 +0200 | [diff] [blame] | 1281 | ide_tape_discard_merge_buffer(drive, 1); |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1282 | for (i = 0; i < mt_count; i++) { |
| 1283 | retval = idetape_write_filemark(drive); |
| 1284 | if (retval) |
| 1285 | return retval; |
| 1286 | } |
| 1287 | return 0; |
| 1288 | case MTREW: |
Borislav Petkov | ec0fdb0 | 2008-04-27 15:38:34 +0200 | [diff] [blame] | 1289 | ide_tape_discard_merge_buffer(drive, 0); |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1290 | if (idetape_rewind_tape(drive)) |
| 1291 | return -EIO; |
| 1292 | return 0; |
| 1293 | case MTLOAD: |
Borislav Petkov | ec0fdb0 | 2008-04-27 15:38:34 +0200 | [diff] [blame] | 1294 | ide_tape_discard_merge_buffer(drive, 0); |
Bartlomiej Zolnierkiewicz | 0c8a6c7 | 2008-10-10 22:39:39 +0200 | [diff] [blame] | 1295 | return ide_do_start_stop(drive, disk, IDETAPE_LU_LOAD_MASK); |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1296 | case MTUNLOAD: |
| 1297 | case MTOFFL: |
| 1298 | /* |
| 1299 | * If door is locked, attempt to unlock before |
| 1300 | * attempting to eject. |
| 1301 | */ |
| 1302 | if (tape->door_locked) { |
Bartlomiej Zolnierkiewicz | 0578042 | 2008-10-10 22:39:38 +0200 | [diff] [blame] | 1303 | if (!ide_set_media_lock(drive, disk, 0)) |
Bartlomiej Zolnierkiewicz | 385a4b8 | 2008-10-10 22:39:37 +0200 | [diff] [blame] | 1304 | tape->door_locked = DOOR_UNLOCKED; |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1305 | } |
Borislav Petkov | ec0fdb0 | 2008-04-27 15:38:34 +0200 | [diff] [blame] | 1306 | ide_tape_discard_merge_buffer(drive, 0); |
Bartlomiej Zolnierkiewicz | 0c8a6c7 | 2008-10-10 22:39:39 +0200 | [diff] [blame] | 1307 | retval = ide_do_start_stop(drive, disk, !IDETAPE_LU_LOAD_MASK); |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1308 | if (!retval) |
Borislav Petkov | 49d8078 | 2009-06-07 15:37:06 +0200 | [diff] [blame] | 1309 | clear_bit(ilog2(IDE_AFLAG_MEDIUM_PRESENT), |
| 1310 | &drive->atapi_flags); |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1311 | return retval; |
| 1312 | case MTNOP: |
Borislav Petkov | ec0fdb0 | 2008-04-27 15:38:34 +0200 | [diff] [blame] | 1313 | ide_tape_discard_merge_buffer(drive, 0); |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1314 | return idetape_flush_tape_buffers(drive); |
| 1315 | case MTRETEN: |
Borislav Petkov | ec0fdb0 | 2008-04-27 15:38:34 +0200 | [diff] [blame] | 1316 | ide_tape_discard_merge_buffer(drive, 0); |
Bartlomiej Zolnierkiewicz | 0c8a6c7 | 2008-10-10 22:39:39 +0200 | [diff] [blame] | 1317 | return ide_do_start_stop(drive, disk, |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1318 | IDETAPE_LU_RETENSION_MASK | IDETAPE_LU_LOAD_MASK); |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1319 | case MTEOM: |
| 1320 | idetape_create_space_cmd(&pc, 0, IDETAPE_SPACE_TO_EOD); |
Borislav Petkov | b13345f | 2009-05-02 10:26:12 +0200 | [diff] [blame] | 1321 | return ide_queue_pc_tail(drive, disk, &pc, NULL, 0); |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1322 | case MTERASE: |
| 1323 | (void)idetape_rewind_tape(drive); |
| 1324 | idetape_create_erase_cmd(&pc); |
Borislav Petkov | b13345f | 2009-05-02 10:26:12 +0200 | [diff] [blame] | 1325 | return ide_queue_pc_tail(drive, disk, &pc, NULL, 0); |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1326 | case MTSETBLK: |
| 1327 | if (mt_count) { |
| 1328 | if (mt_count < tape->blk_size || |
| 1329 | mt_count % tape->blk_size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1330 | return -EIO; |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1331 | tape->user_bs_factor = mt_count / tape->blk_size; |
Borislav Petkov | 49d8078 | 2009-06-07 15:37:06 +0200 | [diff] [blame] | 1332 | clear_bit(ilog2(IDE_AFLAG_DETECT_BS), |
| 1333 | &drive->atapi_flags); |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1334 | } else |
Borislav Petkov | 49d8078 | 2009-06-07 15:37:06 +0200 | [diff] [blame] | 1335 | set_bit(ilog2(IDE_AFLAG_DETECT_BS), |
| 1336 | &drive->atapi_flags); |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1337 | return 0; |
| 1338 | case MTSEEK: |
Borislav Petkov | ec0fdb0 | 2008-04-27 15:38:34 +0200 | [diff] [blame] | 1339 | ide_tape_discard_merge_buffer(drive, 0); |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1340 | return idetape_position_tape(drive, |
| 1341 | mt_count * tape->user_bs_factor, tape->partition, 0); |
| 1342 | case MTSETPART: |
Borislav Petkov | ec0fdb0 | 2008-04-27 15:38:34 +0200 | [diff] [blame] | 1343 | ide_tape_discard_merge_buffer(drive, 0); |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1344 | return idetape_position_tape(drive, 0, mt_count, 0); |
| 1345 | case MTFSR: |
| 1346 | case MTBSR: |
| 1347 | case MTLOCK: |
Bartlomiej Zolnierkiewicz | 0578042 | 2008-10-10 22:39:38 +0200 | [diff] [blame] | 1348 | retval = ide_set_media_lock(drive, disk, 1); |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1349 | if (retval) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1350 | return retval; |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1351 | tape->door_locked = DOOR_EXPLICITLY_LOCKED; |
| 1352 | return 0; |
| 1353 | case MTUNLOCK: |
Bartlomiej Zolnierkiewicz | 0578042 | 2008-10-10 22:39:38 +0200 | [diff] [blame] | 1354 | retval = ide_set_media_lock(drive, disk, 0); |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1355 | if (retval) |
| 1356 | return retval; |
| 1357 | tape->door_locked = DOOR_UNLOCKED; |
| 1358 | return 0; |
| 1359 | default: |
| 1360 | printk(KERN_ERR "ide-tape: MTIO operation %d not supported\n", |
| 1361 | mt_op); |
| 1362 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1363 | } |
| 1364 | } |
| 1365 | |
| 1366 | /* |
Borislav Petkov | d99c9da | 2008-02-02 19:56:51 +0100 | [diff] [blame] | 1367 | * Our character device ioctls. General mtio.h magnetic io commands are |
| 1368 | * supported here, and not in the corresponding block interface. Our own |
| 1369 | * ide-tape ioctls are supported on both interfaces. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1370 | */ |
Alan Cox | 05227ad | 2010-01-04 06:24:00 +0000 | [diff] [blame] | 1371 | static long do_idetape_chrdev_ioctl(struct file *file, |
Borislav Petkov | d99c9da | 2008-02-02 19:56:51 +0100 | [diff] [blame] | 1372 | unsigned int cmd, unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1373 | { |
Borislav Petkov | 5aeddf9 | 2008-10-13 21:39:34 +0200 | [diff] [blame] | 1374 | struct ide_tape_obj *tape = file->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1375 | ide_drive_t *drive = tape->drive; |
| 1376 | struct mtop mtop; |
| 1377 | struct mtget mtget; |
| 1378 | struct mtpos mtpos; |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1379 | int block_offset = 0, position = tape->first_frame; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1380 | void __user *argp = (void __user *)arg; |
| 1381 | |
Borislav Petkov | e972d70 | 2009-07-17 23:55:16 +0000 | [diff] [blame] | 1382 | ide_debug_log(IDE_DBG_FUNC, "cmd: 0x%x", cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1383 | |
Borislav Petkov | 54abf37 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1384 | if (tape->chrdev_dir == IDETAPE_DIR_WRITE) { |
Borislav Petkov | d9df937 | 2008-04-27 15:38:34 +0200 | [diff] [blame] | 1385 | ide_tape_flush_merge_buffer(drive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1386 | idetape_flush_tape_buffers(drive); |
| 1387 | } |
| 1388 | if (cmd == MTIOCGET || cmd == MTIOCPOS) { |
Tejun Heo | 963da55 | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 1389 | block_offset = tape->valid / |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1390 | (tape->blk_size * tape->user_bs_factor); |
Borislav Petkov | 55ce3a1 | 2009-05-04 09:38:15 +0200 | [diff] [blame] | 1391 | position = ide_tape_read_position(drive); |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1392 | if (position < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1393 | return -EIO; |
| 1394 | } |
| 1395 | switch (cmd) { |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1396 | case MTIOCTOP: |
| 1397 | if (copy_from_user(&mtop, argp, sizeof(struct mtop))) |
| 1398 | return -EFAULT; |
| 1399 | return idetape_mtioctop(drive, mtop.mt_op, mtop.mt_count); |
| 1400 | case MTIOCGET: |
| 1401 | memset(&mtget, 0, sizeof(struct mtget)); |
| 1402 | mtget.mt_type = MT_ISSCSI2; |
| 1403 | mtget.mt_blkno = position / tape->user_bs_factor - block_offset; |
| 1404 | mtget.mt_dsreg = |
| 1405 | ((tape->blk_size * tape->user_bs_factor) |
| 1406 | << MT_ST_BLKSIZE_SHIFT) & MT_ST_BLKSIZE_MASK; |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1407 | |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1408 | if (tape->drv_write_prot) |
| 1409 | mtget.mt_gstat |= GMT_WR_PROT(0xffffffff); |
| 1410 | |
| 1411 | if (copy_to_user(argp, &mtget, sizeof(struct mtget))) |
| 1412 | return -EFAULT; |
| 1413 | return 0; |
| 1414 | case MTIOCPOS: |
| 1415 | mtpos.mt_blkno = position / tape->user_bs_factor - block_offset; |
| 1416 | if (copy_to_user(argp, &mtpos, sizeof(struct mtpos))) |
| 1417 | return -EFAULT; |
| 1418 | return 0; |
| 1419 | default: |
| 1420 | if (tape->chrdev_dir == IDETAPE_DIR_READ) |
Borislav Petkov | ec0fdb0 | 2008-04-27 15:38:34 +0200 | [diff] [blame] | 1421 | ide_tape_discard_merge_buffer(drive, 1); |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1422 | return idetape_blkdev_ioctl(drive, cmd, arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1423 | } |
| 1424 | } |
| 1425 | |
Alan Cox | 05227ad | 2010-01-04 06:24:00 +0000 | [diff] [blame] | 1426 | static long idetape_chrdev_ioctl(struct file *file, |
| 1427 | unsigned int cmd, unsigned long arg) |
| 1428 | { |
| 1429 | long ret; |
Arnd Bergmann | 2a48fc0 | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 1430 | mutex_lock(&ide_tape_mutex); |
Alan Cox | 05227ad | 2010-01-04 06:24:00 +0000 | [diff] [blame] | 1431 | ret = do_idetape_chrdev_ioctl(file, cmd, arg); |
Arnd Bergmann | 2a48fc0 | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 1432 | mutex_unlock(&ide_tape_mutex); |
Alan Cox | 05227ad | 2010-01-04 06:24:00 +0000 | [diff] [blame] | 1433 | return ret; |
| 1434 | } |
| 1435 | |
Borislav Petkov | 3cffb9c | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 1436 | /* |
| 1437 | * Do a mode sense page 0 with block descriptor and if it succeeds set the tape |
| 1438 | * block size with the reported value. |
| 1439 | */ |
| 1440 | static void ide_tape_get_bsize_from_bdesc(ide_drive_t *drive) |
| 1441 | { |
| 1442 | idetape_tape_t *tape = drive->driver_data; |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1443 | struct ide_atapi_pc pc; |
Borislav Petkov | 837272b | 2009-05-04 09:48:57 +0200 | [diff] [blame] | 1444 | u8 buf[12]; |
Borislav Petkov | 3cffb9c | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 1445 | |
| 1446 | idetape_create_mode_sense_cmd(&pc, IDETAPE_BLOCK_DESCRIPTOR); |
Borislav Petkov | 837272b | 2009-05-04 09:48:57 +0200 | [diff] [blame] | 1447 | 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] | 1448 | printk(KERN_ERR "ide-tape: Can't get block descriptor\n"); |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1449 | if (tape->blk_size == 0) { |
Borislav Petkov | 3cffb9c | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 1450 | printk(KERN_WARNING "ide-tape: Cannot deal with zero " |
| 1451 | "block size, assuming 32k\n"); |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1452 | tape->blk_size = 32768; |
Borislav Petkov | 3cffb9c | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 1453 | } |
| 1454 | return; |
| 1455 | } |
Borislav Petkov | 837272b | 2009-05-04 09:48:57 +0200 | [diff] [blame] | 1456 | tape->blk_size = (buf[4 + 5] << 16) + |
| 1457 | (buf[4 + 6] << 8) + |
| 1458 | buf[4 + 7]; |
| 1459 | tape->drv_write_prot = (buf[2] & 0x80) >> 7; |
Borislav Petkov | e972d70 | 2009-07-17 23:55:16 +0000 | [diff] [blame] | 1460 | |
| 1461 | ide_debug_log(IDE_DBG_FUNC, "blk_size: %d, write_prot: %d", |
| 1462 | tape->blk_size, tape->drv_write_prot); |
Borislav Petkov | 3cffb9c | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 1463 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1464 | |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1465 | static int idetape_chrdev_open(struct inode *inode, struct file *filp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1466 | { |
| 1467 | unsigned int minor = iminor(inode), i = minor & ~0xc0; |
| 1468 | ide_drive_t *drive; |
| 1469 | idetape_tape_t *tape; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1470 | int retval; |
| 1471 | |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 1472 | if (i >= MAX_HWIFS * MAX_DRIVES) |
| 1473 | return -ENXIO; |
| 1474 | |
Borislav Petkov | cbba2fa | 2009-10-11 00:25:19 +0000 | [diff] [blame] | 1475 | mutex_lock(&idetape_chrdev_mutex); |
| 1476 | |
Borislav Petkov | 9d01e4c | 2009-06-08 22:03:03 +0200 | [diff] [blame] | 1477 | tape = ide_tape_get(NULL, true, i); |
Jonathan Corbet | 04f4ac9 | 2008-05-15 12:01:56 -0600 | [diff] [blame] | 1478 | if (!tape) { |
Borislav Petkov | cbba2fa | 2009-10-11 00:25:19 +0000 | [diff] [blame] | 1479 | mutex_unlock(&idetape_chrdev_mutex); |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 1480 | return -ENXIO; |
Jonathan Corbet | 04f4ac9 | 2008-05-15 12:01:56 -0600 | [diff] [blame] | 1481 | } |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 1482 | |
Borislav Petkov | e972d70 | 2009-07-17 23:55:16 +0000 | [diff] [blame] | 1483 | drive = tape->drive; |
| 1484 | filp->private_data = tape; |
| 1485 | |
| 1486 | ide_debug_log(IDE_DBG_FUNC, "enter"); |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 1487 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1488 | /* |
| 1489 | * We really want to do nonseekable_open(inode, filp); here, but some |
| 1490 | * versions of tar incorrectly call lseek on tapes and bail out if that |
| 1491 | * fails. So we disallow pread() and pwrite(), but permit lseeks. |
| 1492 | */ |
| 1493 | filp->f_mode &= ~(FMODE_PREAD | FMODE_PWRITE); |
| 1494 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1495 | |
Borislav Petkov | 49d8078 | 2009-06-07 15:37:06 +0200 | [diff] [blame] | 1496 | if (test_and_set_bit(ilog2(IDE_AFLAG_BUSY), &drive->atapi_flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1497 | retval = -EBUSY; |
| 1498 | goto out_put_tape; |
| 1499 | } |
| 1500 | |
| 1501 | retval = idetape_wait_ready(drive, 60 * HZ); |
| 1502 | if (retval) { |
Borislav Petkov | 49d8078 | 2009-06-07 15:37:06 +0200 | [diff] [blame] | 1503 | clear_bit(ilog2(IDE_AFLAG_BUSY), &drive->atapi_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1504 | printk(KERN_ERR "ide-tape: %s: drive not ready\n", tape->name); |
| 1505 | goto out_put_tape; |
| 1506 | } |
| 1507 | |
Borislav Petkov | 79ca743 | 2009-06-15 07:32:04 +0200 | [diff] [blame] | 1508 | ide_tape_read_position(drive); |
Borislav Petkov | 49d8078 | 2009-06-07 15:37:06 +0200 | [diff] [blame] | 1509 | if (!test_bit(ilog2(IDE_AFLAG_ADDRESS_VALID), &drive->atapi_flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1510 | (void)idetape_rewind_tape(drive); |
| 1511 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1512 | /* Read block size and write protect status from drive. */ |
Borislav Petkov | 3cffb9c | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 1513 | ide_tape_get_bsize_from_bdesc(drive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1514 | |
| 1515 | /* Set write protect flag if device is opened as read-only. */ |
| 1516 | if ((filp->f_flags & O_ACCMODE) == O_RDONLY) |
| 1517 | tape->write_prot = 1; |
| 1518 | else |
| 1519 | tape->write_prot = tape->drv_write_prot; |
| 1520 | |
| 1521 | /* Make sure drive isn't write protected if user wants to write. */ |
| 1522 | if (tape->write_prot) { |
| 1523 | if ((filp->f_flags & O_ACCMODE) == O_WRONLY || |
| 1524 | (filp->f_flags & O_ACCMODE) == O_RDWR) { |
Borislav Petkov | 49d8078 | 2009-06-07 15:37:06 +0200 | [diff] [blame] | 1525 | clear_bit(ilog2(IDE_AFLAG_BUSY), &drive->atapi_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1526 | retval = -EROFS; |
| 1527 | goto out_put_tape; |
| 1528 | } |
| 1529 | } |
| 1530 | |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 1531 | /* Lock the tape drive door so user can't eject. */ |
Borislav Petkov | 54abf37 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1532 | if (tape->chrdev_dir == IDETAPE_DIR_NONE) { |
Bartlomiej Zolnierkiewicz | 0578042 | 2008-10-10 22:39:38 +0200 | [diff] [blame] | 1533 | if (!ide_set_media_lock(drive, tape->disk, 1)) { |
Bartlomiej Zolnierkiewicz | 385a4b8 | 2008-10-10 22:39:37 +0200 | [diff] [blame] | 1534 | if (tape->door_locked != DOOR_EXPLICITLY_LOCKED) |
| 1535 | tape->door_locked = DOOR_LOCKED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1536 | } |
| 1537 | } |
Borislav Petkov | cbba2fa | 2009-10-11 00:25:19 +0000 | [diff] [blame] | 1538 | mutex_unlock(&idetape_chrdev_mutex); |
| 1539 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1540 | return 0; |
| 1541 | |
| 1542 | out_put_tape: |
| 1543 | ide_tape_put(tape); |
Borislav Petkov | cbba2fa | 2009-10-11 00:25:19 +0000 | [diff] [blame] | 1544 | |
| 1545 | mutex_unlock(&idetape_chrdev_mutex); |
| 1546 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1547 | return retval; |
| 1548 | } |
| 1549 | |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1550 | static void idetape_write_release(ide_drive_t *drive, unsigned int minor) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1551 | { |
| 1552 | idetape_tape_t *tape = drive->driver_data; |
| 1553 | |
Borislav Petkov | d9df937 | 2008-04-27 15:38:34 +0200 | [diff] [blame] | 1554 | ide_tape_flush_merge_buffer(drive); |
Tejun Heo | 963da55 | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 1555 | tape->buf = kmalloc(tape->buffer_size, GFP_KERNEL); |
| 1556 | if (tape->buf != NULL) { |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1557 | idetape_pad_zeros(drive, tape->blk_size * |
| 1558 | (tape->user_bs_factor - 1)); |
Tejun Heo | 963da55 | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 1559 | kfree(tape->buf); |
| 1560 | tape->buf = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1561 | } |
| 1562 | idetape_write_filemark(drive); |
| 1563 | idetape_flush_tape_buffers(drive); |
| 1564 | idetape_flush_tape_buffers(drive); |
| 1565 | } |
| 1566 | |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1567 | static int idetape_chrdev_release(struct inode *inode, struct file *filp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1568 | { |
Borislav Petkov | 5aeddf9 | 2008-10-13 21:39:34 +0200 | [diff] [blame] | 1569 | struct ide_tape_obj *tape = filp->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1570 | ide_drive_t *drive = tape->drive; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1571 | unsigned int minor = iminor(inode); |
| 1572 | |
Borislav Petkov | cbba2fa | 2009-10-11 00:25:19 +0000 | [diff] [blame] | 1573 | mutex_lock(&idetape_chrdev_mutex); |
| 1574 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1575 | tape = drive->driver_data; |
Borislav Petkov | 8004a8c | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 1576 | |
Borislav Petkov | e972d70 | 2009-07-17 23:55:16 +0000 | [diff] [blame] | 1577 | ide_debug_log(IDE_DBG_FUNC, "enter"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1578 | |
Borislav Petkov | 54abf37 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1579 | if (tape->chrdev_dir == IDETAPE_DIR_WRITE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1580 | idetape_write_release(drive, minor); |
Borislav Petkov | 54abf37 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1581 | if (tape->chrdev_dir == IDETAPE_DIR_READ) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1582 | if (minor < 128) |
Borislav Petkov | ec0fdb0 | 2008-04-27 15:38:34 +0200 | [diff] [blame] | 1583 | ide_tape_discard_merge_buffer(drive, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1584 | } |
Borislav Petkov | f64eee7 | 2008-04-27 15:38:25 +0200 | [diff] [blame] | 1585 | |
Borislav Petkov | 49d8078 | 2009-06-07 15:37:06 +0200 | [diff] [blame] | 1586 | if (minor < 128 && test_bit(ilog2(IDE_AFLAG_MEDIUM_PRESENT), |
| 1587 | &drive->atapi_flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1588 | (void) idetape_rewind_tape(drive); |
Borislav Petkov | 49d8078 | 2009-06-07 15:37:06 +0200 | [diff] [blame] | 1589 | |
Borislav Petkov | 54abf37 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1590 | if (tape->chrdev_dir == IDETAPE_DIR_NONE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1591 | if (tape->door_locked == DOOR_LOCKED) { |
Bartlomiej Zolnierkiewicz | 0578042 | 2008-10-10 22:39:38 +0200 | [diff] [blame] | 1592 | if (!ide_set_media_lock(drive, tape->disk, 0)) |
Bartlomiej Zolnierkiewicz | 385a4b8 | 2008-10-10 22:39:37 +0200 | [diff] [blame] | 1593 | tape->door_locked = DOOR_UNLOCKED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1594 | } |
| 1595 | } |
Borislav Petkov | 49d8078 | 2009-06-07 15:37:06 +0200 | [diff] [blame] | 1596 | clear_bit(ilog2(IDE_AFLAG_BUSY), &drive->atapi_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1597 | ide_tape_put(tape); |
Borislav Petkov | cbba2fa | 2009-10-11 00:25:19 +0000 | [diff] [blame] | 1598 | |
| 1599 | mutex_unlock(&idetape_chrdev_mutex); |
| 1600 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1601 | return 0; |
| 1602 | } |
| 1603 | |
Borislav Petkov | 6d29c8f | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 1604 | static void idetape_get_inquiry_results(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1605 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1606 | idetape_tape_t *tape = drive->driver_data; |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1607 | struct ide_atapi_pc pc; |
Bartlomiej Zolnierkiewicz | 41fa9f8 | 2009-03-31 20:15:25 +0200 | [diff] [blame] | 1608 | u8 pc_buf[256]; |
Borislav Petkov | 801bd32 | 2008-09-27 19:32:17 +0200 | [diff] [blame] | 1609 | char fw_rev[4], vendor_id[8], product_id[16]; |
Borislav Petkov | 6d29c8f | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 1610 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1611 | idetape_create_inquiry_cmd(&pc); |
Borislav Petkov | b13345f | 2009-05-02 10:26:12 +0200 | [diff] [blame] | 1612 | 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] | 1613 | printk(KERN_ERR "ide-tape: %s: can't get INQUIRY results\n", |
| 1614 | tape->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1615 | return; |
| 1616 | } |
Borislav Petkov | b13345f | 2009-05-02 10:26:12 +0200 | [diff] [blame] | 1617 | memcpy(vendor_id, &pc_buf[8], 8); |
| 1618 | memcpy(product_id, &pc_buf[16], 16); |
| 1619 | memcpy(fw_rev, &pc_buf[32], 4); |
Borislav Petkov | 6d29c8f | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 1620 | |
Borislav Petkov | 801bd32 | 2008-09-27 19:32:17 +0200 | [diff] [blame] | 1621 | ide_fixstring(vendor_id, 8, 0); |
| 1622 | ide_fixstring(product_id, 16, 0); |
| 1623 | ide_fixstring(fw_rev, 4, 0); |
Borislav Petkov | 41f81d54 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1624 | |
Borislav Petkov | 801bd32 | 2008-09-27 19:32:17 +0200 | [diff] [blame] | 1625 | printk(KERN_INFO "ide-tape: %s <-> %s: %.8s %.16s rev %.4s\n", |
Borislav Petkov | 41f81d54 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1626 | drive->name, tape->name, vendor_id, product_id, fw_rev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1627 | } |
| 1628 | |
| 1629 | /* |
Borislav Petkov | b642201 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 1630 | * Ask the tape about its various parameters. In particular, we will adjust our |
| 1631 | * 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] | 1632 | */ |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1633 | static void idetape_get_mode_sense_results(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1634 | { |
| 1635 | idetape_tape_t *tape = drive->driver_data; |
Borislav Petkov | d236d74 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1636 | struct ide_atapi_pc pc; |
Borislav Petkov | b13345f | 2009-05-02 10:26:12 +0200 | [diff] [blame] | 1637 | u8 buf[24], *caps; |
Borislav Petkov | b642201 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 1638 | u8 speed, max_speed; |
Borislav Petkov | 47314fa | 2008-02-02 19:56:48 +0100 | [diff] [blame] | 1639 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1640 | idetape_create_mode_sense_cmd(&pc, IDETAPE_CAPABILITIES_PAGE); |
Borislav Petkov | b13345f | 2009-05-02 10:26:12 +0200 | [diff] [blame] | 1641 | 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] | 1642 | printk(KERN_ERR "ide-tape: Can't get tape parameters - assuming" |
| 1643 | " some default values\n"); |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1644 | tape->blk_size = 512; |
Borislav Petkov | b642201 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 1645 | put_unaligned(52, (u16 *)&tape->caps[12]); |
| 1646 | put_unaligned(540, (u16 *)&tape->caps[14]); |
| 1647 | put_unaligned(6*52, (u16 *)&tape->caps[16]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1648 | return; |
| 1649 | } |
Borislav Petkov | b13345f | 2009-05-02 10:26:12 +0200 | [diff] [blame] | 1650 | caps = buf + 4 + buf[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1651 | |
Borislav Petkov | b642201 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 1652 | /* convert to host order and save for later use */ |
Harvey Harrison | cd740ab | 2008-07-24 22:53:33 +0200 | [diff] [blame] | 1653 | speed = be16_to_cpup((__be16 *)&caps[14]); |
| 1654 | max_speed = be16_to_cpup((__be16 *)&caps[8]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1655 | |
Harvey Harrison | cd740ab | 2008-07-24 22:53:33 +0200 | [diff] [blame] | 1656 | *(u16 *)&caps[8] = max_speed; |
| 1657 | *(u16 *)&caps[12] = be16_to_cpup((__be16 *)&caps[12]); |
| 1658 | *(u16 *)&caps[14] = speed; |
| 1659 | *(u16 *)&caps[16] = be16_to_cpup((__be16 *)&caps[16]); |
Borislav Petkov | b642201 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 1660 | |
| 1661 | if (!speed) { |
| 1662 | printk(KERN_INFO "ide-tape: %s: invalid tape speed " |
| 1663 | "(assuming 650KB/sec)\n", drive->name); |
Harvey Harrison | cd740ab | 2008-07-24 22:53:33 +0200 | [diff] [blame] | 1664 | *(u16 *)&caps[14] = 650; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1665 | } |
Borislav Petkov | b642201 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 1666 | if (!max_speed) { |
| 1667 | printk(KERN_INFO "ide-tape: %s: invalid max_speed " |
| 1668 | "(assuming 650KB/sec)\n", drive->name); |
Harvey Harrison | cd740ab | 2008-07-24 22:53:33 +0200 | [diff] [blame] | 1669 | *(u16 *)&caps[8] = 650; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1670 | } |
| 1671 | |
Borislav Petkov | b642201 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 1672 | memcpy(&tape->caps, caps, 20); |
Bartlomiej Zolnierkiewicz | 0578042 | 2008-10-10 22:39:38 +0200 | [diff] [blame] | 1673 | |
| 1674 | /* device lacks locking support according to capabilities page */ |
| 1675 | if ((caps[6] & 1) == 0) |
Bartlomiej Zolnierkiewicz | 42619d3 | 2008-10-17 18:09:11 +0200 | [diff] [blame] | 1676 | drive->dev_flags &= ~IDE_DFLAG_DOORLOCKING; |
Bartlomiej Zolnierkiewicz | 0578042 | 2008-10-10 22:39:38 +0200 | [diff] [blame] | 1677 | |
Borislav Petkov | b642201 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 1678 | if (caps[7] & 0x02) |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1679 | tape->blk_size = 512; |
Borislav Petkov | b642201 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 1680 | else if (caps[7] & 0x04) |
Borislav Petkov | 54bb207 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1681 | tape->blk_size = 1024; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1682 | } |
| 1683 | |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 1684 | #ifdef CONFIG_IDE_PROC_FS |
Bartlomiej Zolnierkiewicz | 8185d5a | 2008-10-10 22:39:28 +0200 | [diff] [blame] | 1685 | #define ide_tape_devset_get(name, field) \ |
| 1686 | static int get_##name(ide_drive_t *drive) \ |
| 1687 | { \ |
| 1688 | idetape_tape_t *tape = drive->driver_data; \ |
| 1689 | return tape->field; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1690 | } |
Bartlomiej Zolnierkiewicz | 8185d5a | 2008-10-10 22:39:28 +0200 | [diff] [blame] | 1691 | |
| 1692 | #define ide_tape_devset_set(name, field) \ |
| 1693 | static int set_##name(ide_drive_t *drive, int arg) \ |
| 1694 | { \ |
| 1695 | idetape_tape_t *tape = drive->driver_data; \ |
| 1696 | tape->field = arg; \ |
| 1697 | return 0; \ |
| 1698 | } |
| 1699 | |
Elias Oltmanns | 92f1f8f | 2008-10-10 22:39:40 +0200 | [diff] [blame] | 1700 | #define ide_tape_devset_rw_field(_name, _field) \ |
Bartlomiej Zolnierkiewicz | 8185d5a | 2008-10-10 22:39:28 +0200 | [diff] [blame] | 1701 | ide_tape_devset_get(_name, _field) \ |
| 1702 | ide_tape_devset_set(_name, _field) \ |
Elias Oltmanns | 92f1f8f | 2008-10-10 22:39:40 +0200 | [diff] [blame] | 1703 | IDE_DEVSET(_name, DS_SYNC, get_##_name, set_##_name) |
Bartlomiej Zolnierkiewicz | 8185d5a | 2008-10-10 22:39:28 +0200 | [diff] [blame] | 1704 | |
Elias Oltmanns | 92f1f8f | 2008-10-10 22:39:40 +0200 | [diff] [blame] | 1705 | #define ide_tape_devset_r_field(_name, _field) \ |
Bartlomiej Zolnierkiewicz | 8185d5a | 2008-10-10 22:39:28 +0200 | [diff] [blame] | 1706 | ide_tape_devset_get(_name, _field) \ |
Elias Oltmanns | 92f1f8f | 2008-10-10 22:39:40 +0200 | [diff] [blame] | 1707 | IDE_DEVSET(_name, 0, get_##_name, NULL) |
Bartlomiej Zolnierkiewicz | 8185d5a | 2008-10-10 22:39:28 +0200 | [diff] [blame] | 1708 | |
| 1709 | static int mulf_tdsc(ide_drive_t *drive) { return 1000; } |
| 1710 | static int divf_tdsc(ide_drive_t *drive) { return HZ; } |
| 1711 | static int divf_buffer(ide_drive_t *drive) { return 2; } |
| 1712 | static int divf_buffer_size(ide_drive_t *drive) { return 1024; } |
| 1713 | |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame] | 1714 | ide_devset_rw_flag(dsc_overlap, IDE_DFLAG_DSC_OVERLAP); |
Bartlomiej Zolnierkiewicz | 8185d5a | 2008-10-10 22:39:28 +0200 | [diff] [blame] | 1715 | |
Elias Oltmanns | 92f1f8f | 2008-10-10 22:39:40 +0200 | [diff] [blame] | 1716 | ide_tape_devset_rw_field(tdsc, best_dsc_rw_freq); |
Bartlomiej Zolnierkiewicz | 8185d5a | 2008-10-10 22:39:28 +0200 | [diff] [blame] | 1717 | |
Elias Oltmanns | 92f1f8f | 2008-10-10 22:39:40 +0200 | [diff] [blame] | 1718 | ide_tape_devset_r_field(avg_speed, avg_speed); |
| 1719 | ide_tape_devset_r_field(speed, caps[14]); |
| 1720 | ide_tape_devset_r_field(buffer, caps[16]); |
| 1721 | ide_tape_devset_r_field(buffer_size, buffer_size); |
Bartlomiej Zolnierkiewicz | 8185d5a | 2008-10-10 22:39:28 +0200 | [diff] [blame] | 1722 | |
Elias Oltmanns | 92f1f8f | 2008-10-10 22:39:40 +0200 | [diff] [blame] | 1723 | static const struct ide_proc_devset idetape_settings[] = { |
| 1724 | __IDE_PROC_DEVSET(avg_speed, 0, 0xffff, NULL, NULL), |
| 1725 | __IDE_PROC_DEVSET(buffer, 0, 0xffff, NULL, divf_buffer), |
| 1726 | __IDE_PROC_DEVSET(buffer_size, 0, 0xffff, NULL, divf_buffer_size), |
Elias Oltmanns | 92f1f8f | 2008-10-10 22:39:40 +0200 | [diff] [blame] | 1727 | __IDE_PROC_DEVSET(dsc_overlap, 0, 1, NULL, NULL), |
| 1728 | __IDE_PROC_DEVSET(speed, 0, 0xffff, NULL, NULL), |
| 1729 | __IDE_PROC_DEVSET(tdsc, IDETAPE_DSC_RW_MIN, IDETAPE_DSC_RW_MAX, |
| 1730 | mulf_tdsc, divf_tdsc), |
Hannes Eder | 71bfc7a | 2009-03-05 16:10:56 +0100 | [diff] [blame] | 1731 | { NULL }, |
Bartlomiej Zolnierkiewicz | 8185d5a | 2008-10-10 22:39:28 +0200 | [diff] [blame] | 1732 | }; |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 1733 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1734 | |
| 1735 | /* |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 1736 | * The function below is called to: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1737 | * |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 1738 | * 1. Initialize our various state variables. |
| 1739 | * 2. Ask the tape for its capabilities. |
| 1740 | * 3. Allocate a buffer which will be used for data transfer. The buffer size |
| 1741 | * is chosen based on the recommendation which we received in step 2. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1742 | * |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 1743 | * Note that at this point ide.c already assigned us an irq, so that we can |
| 1744 | * queue requests here and wait for their completion. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1745 | */ |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1746 | 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] | 1747 | { |
Borislav Petkov | 83042b2 | 2008-04-27 15:38:27 +0200 | [diff] [blame] | 1748 | unsigned long t; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1749 | int speed; |
Borislav Petkov | f73850a | 2008-04-27 15:38:33 +0200 | [diff] [blame] | 1750 | int buffer_size; |
Borislav Petkov | b642201 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 1751 | u16 *ctl = (u16 *)&tape->caps[12]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1752 | |
Borislav Petkov | e972d70 | 2009-07-17 23:55:16 +0000 | [diff] [blame] | 1753 | ide_debug_log(IDE_DBG_FUNC, "minor: %d", minor); |
| 1754 | |
| 1755 | drive->pc_callback = ide_tape_callback; |
Borislav Petkov | 776bb02 | 2008-07-23 19:55:59 +0200 | [diff] [blame] | 1756 | |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame] | 1757 | drive->dev_flags |= IDE_DFLAG_DSC_OVERLAP; |
| 1758 | |
Bartlomiej Zolnierkiewicz | 4166c19 | 2008-02-01 23:09:30 +0100 | [diff] [blame] | 1759 | if (drive->hwif->host_flags & IDE_HFLAG_NO_DSC) { |
| 1760 | printk(KERN_INFO "ide-tape: %s: disabling DSC overlap\n", |
| 1761 | tape->name); |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame] | 1762 | drive->dev_flags &= ~IDE_DFLAG_DSC_OVERLAP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1763 | } |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame] | 1764 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1765 | /* Seagate Travan drives do not support DSC overlap. */ |
Bartlomiej Zolnierkiewicz | 4dde449 | 2008-10-10 22:39:19 +0200 | [diff] [blame] | 1766 | if (strstr((char *)&drive->id[ATA_ID_PROD], "Seagate STT3401")) |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame] | 1767 | drive->dev_flags &= ~IDE_DFLAG_DSC_OVERLAP; |
| 1768 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1769 | tape->minor = minor; |
| 1770 | tape->name[0] = 'h'; |
| 1771 | tape->name[1] = 't'; |
| 1772 | tape->name[2] = '0' + minor; |
Borislav Petkov | 54abf37 | 2008-02-06 02:57:52 +0100 | [diff] [blame] | 1773 | tape->chrdev_dir = IDETAPE_DIR_NONE; |
Bartlomiej Zolnierkiewicz | 4dde449 | 2008-10-10 22:39:19 +0200 | [diff] [blame] | 1774 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1775 | idetape_get_inquiry_results(drive); |
| 1776 | idetape_get_mode_sense_results(drive); |
Borislav Petkov | 3cffb9c | 2008-02-02 19:56:50 +0100 | [diff] [blame] | 1777 | ide_tape_get_bsize_from_bdesc(drive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1778 | tape->user_bs_factor = 1; |
Borislav Petkov | f73850a | 2008-04-27 15:38:33 +0200 | [diff] [blame] | 1779 | tape->buffer_size = *ctl * tape->blk_size; |
| 1780 | while (tape->buffer_size > 0xffff) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1781 | printk(KERN_NOTICE "ide-tape: decreasing stage size\n"); |
Borislav Petkov | b642201 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 1782 | *ctl /= 2; |
Borislav Petkov | f73850a | 2008-04-27 15:38:33 +0200 | [diff] [blame] | 1783 | tape->buffer_size = *ctl * tape->blk_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1784 | } |
Borislav Petkov | f73850a | 2008-04-27 15:38:33 +0200 | [diff] [blame] | 1785 | buffer_size = tape->buffer_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1786 | |
Borislav Petkov | 83042b2 | 2008-04-27 15:38:27 +0200 | [diff] [blame] | 1787 | /* select the "best" DSC read/write polling freq */ |
Borislav Petkov | b642201 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 1788 | speed = max(*(u16 *)&tape->caps[14], *(u16 *)&tape->caps[8]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1789 | |
Borislav Petkov | f73850a | 2008-04-27 15:38:33 +0200 | [diff] [blame] | 1790 | t = (IDETAPE_FIFO_THRESHOLD * tape->buffer_size * HZ) / (speed * 1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1791 | |
| 1792 | /* |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 1793 | * Ensure that the number we got makes sense; limit it within |
| 1794 | * IDETAPE_DSC_RW_MIN and IDETAPE_DSC_RW_MAX. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1795 | */ |
Harvey Harrison | a792bd5 | 2008-07-15 21:21:41 +0200 | [diff] [blame] | 1796 | tape->best_dsc_rw_freq = clamp_t(unsigned long, t, IDETAPE_DSC_RW_MIN, |
| 1797 | IDETAPE_DSC_RW_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1798 | printk(KERN_INFO "ide-tape: %s <-> %s: %dKBps, %d*%dkB buffer, " |
Nicholas Mc Guire | 8421596 | 2015-03-03 05:52:51 -0500 | [diff] [blame] | 1799 | "%ums tDSC%s\n", |
Borislav Petkov | b642201 | 2008-02-02 19:56:49 +0100 | [diff] [blame] | 1800 | drive->name, tape->name, *(u16 *)&tape->caps[14], |
Borislav Petkov | f73850a | 2008-04-27 15:38:33 +0200 | [diff] [blame] | 1801 | (*(u16 *)&tape->caps[16] * 512) / tape->buffer_size, |
| 1802 | tape->buffer_size / 1024, |
Nicholas Mc Guire | 8421596 | 2015-03-03 05:52:51 -0500 | [diff] [blame] | 1803 | jiffies_to_msecs(tape->best_dsc_rw_freq), |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame] | 1804 | (drive->dev_flags & IDE_DFLAG_USING_DMA) ? ", DMA" : ""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1805 | |
Bartlomiej Zolnierkiewicz | 1e874f4 | 2008-10-10 22:39:27 +0200 | [diff] [blame] | 1806 | ide_proc_register_driver(drive, tape->driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1807 | } |
| 1808 | |
Russell King | 4031bbe | 2006-01-06 11:41:00 +0000 | [diff] [blame] | 1809 | static void ide_tape_remove(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1810 | { |
| 1811 | idetape_tape_t *tape = drive->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1812 | |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 1813 | ide_proc_unregister_driver(drive, tape->driver); |
Bartlomiej Zolnierkiewicz | 8fed436 | 2009-02-25 20:28:24 +0100 | [diff] [blame] | 1814 | device_del(&tape->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1815 | ide_unregister_region(tape->disk); |
| 1816 | |
Bartlomiej Zolnierkiewicz | 8fed436 | 2009-02-25 20:28:24 +0100 | [diff] [blame] | 1817 | mutex_lock(&idetape_ref_mutex); |
| 1818 | put_device(&tape->dev); |
| 1819 | mutex_unlock(&idetape_ref_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1820 | } |
| 1821 | |
Bartlomiej Zolnierkiewicz | 8fed436 | 2009-02-25 20:28:24 +0100 | [diff] [blame] | 1822 | static void ide_tape_release(struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1823 | { |
Bartlomiej Zolnierkiewicz | 8fed436 | 2009-02-25 20:28:24 +0100 | [diff] [blame] | 1824 | struct ide_tape_obj *tape = to_ide_drv(dev, ide_tape_obj); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1825 | ide_drive_t *drive = tape->drive; |
| 1826 | struct gendisk *g = tape->disk; |
| 1827 | |
Tejun Heo | 963da55 | 2009-04-19 08:46:02 +0900 | [diff] [blame] | 1828 | BUG_ON(tape->valid); |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 1829 | |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame] | 1830 | drive->dev_flags &= ~IDE_DFLAG_DSC_OVERLAP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1831 | drive->driver_data = NULL; |
Tony Jones | dbc1272 | 2007-09-25 02:03:03 +0200 | [diff] [blame] | 1832 | device_destroy(idetape_sysfs_class, MKDEV(IDETAPE_MAJOR, tape->minor)); |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1833 | device_destroy(idetape_sysfs_class, |
| 1834 | MKDEV(IDETAPE_MAJOR, tape->minor + 128)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1835 | idetape_devs[tape->minor] = NULL; |
| 1836 | g->private_data = NULL; |
| 1837 | put_disk(g); |
| 1838 | kfree(tape); |
| 1839 | } |
| 1840 | |
Bartlomiej Zolnierkiewicz | ecfd80e | 2007-05-10 00:01:09 +0200 | [diff] [blame] | 1841 | #ifdef CONFIG_IDE_PROC_FS |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 1842 | static int idetape_name_proc_show(struct seq_file *m, void *v) |
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 | ide_drive_t *drive = (ide_drive_t *) m->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1845 | idetape_tape_t *tape = drive->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1846 | |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 1847 | seq_printf(m, "%s\n", tape->name); |
| 1848 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1849 | } |
| 1850 | |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 1851 | static int idetape_name_proc_open(struct inode *inode, struct file *file) |
| 1852 | { |
Al Viro | d9dda78 | 2013-03-31 18:16:14 -0400 | [diff] [blame] | 1853 | return single_open(file, idetape_name_proc_show, PDE_DATA(inode)); |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 1854 | } |
| 1855 | |
| 1856 | static const struct file_operations idetape_name_proc_fops = { |
| 1857 | .owner = THIS_MODULE, |
| 1858 | .open = idetape_name_proc_open, |
| 1859 | .read = seq_read, |
| 1860 | .llseek = seq_lseek, |
| 1861 | .release = single_release, |
| 1862 | }; |
| 1863 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1864 | static ide_proc_entry_t idetape_proc[] = { |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 1865 | { "capacity", S_IFREG|S_IRUGO, &ide_capacity_proc_fops }, |
| 1866 | { "name", S_IFREG|S_IRUGO, &idetape_name_proc_fops }, |
| 1867 | {} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1868 | }; |
Bartlomiej Zolnierkiewicz | 79cb380 | 2008-10-17 18:09:13 +0200 | [diff] [blame] | 1869 | |
| 1870 | static ide_proc_entry_t *ide_tape_proc_entries(ide_drive_t *drive) |
| 1871 | { |
| 1872 | return idetape_proc; |
| 1873 | } |
| 1874 | |
| 1875 | static const struct ide_proc_devset *ide_tape_proc_devsets(ide_drive_t *drive) |
| 1876 | { |
| 1877 | return idetape_settings; |
| 1878 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1879 | #endif |
| 1880 | |
Russell King | 4031bbe | 2006-01-06 11:41:00 +0000 | [diff] [blame] | 1881 | static int ide_tape_probe(ide_drive_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1882 | |
Bartlomiej Zolnierkiewicz | 7f3c868 | 2009-01-06 17:20:53 +0100 | [diff] [blame] | 1883 | static struct ide_driver idetape_driver = { |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 1884 | .gen_driver = { |
Laurent Riffard | 4ef3b8f | 2005-11-18 22:15:40 +0100 | [diff] [blame] | 1885 | .owner = THIS_MODULE, |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 1886 | .name = "ide-tape", |
| 1887 | .bus = &ide_bus_type, |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 1888 | }, |
Russell King | 4031bbe | 2006-01-06 11:41:00 +0000 | [diff] [blame] | 1889 | .probe = ide_tape_probe, |
| 1890 | .remove = ide_tape_remove, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1891 | .version = IDETAPE_VERSION, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1892 | .do_request = idetape_do_request, |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 1893 | #ifdef CONFIG_IDE_PROC_FS |
Bartlomiej Zolnierkiewicz | 79cb380 | 2008-10-17 18:09:13 +0200 | [diff] [blame] | 1894 | .proc_entries = ide_tape_proc_entries, |
| 1895 | .proc_devsets = ide_tape_proc_devsets, |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 1896 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1897 | }; |
| 1898 | |
Borislav Petkov | 3c98bf3 | 2008-02-06 02:57:53 +0100 | [diff] [blame] | 1899 | /* Our character device supporting functions, passed to register_chrdev. */ |
Arjan van de Ven | 2b8693c | 2007-02-12 00:55:32 -0800 | [diff] [blame] | 1900 | static const struct file_operations idetape_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1901 | .owner = THIS_MODULE, |
| 1902 | .read = idetape_chrdev_read, |
| 1903 | .write = idetape_chrdev_write, |
Alan Cox | 05227ad | 2010-01-04 06:24:00 +0000 | [diff] [blame] | 1904 | .unlocked_ioctl = idetape_chrdev_ioctl, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1905 | .open = idetape_chrdev_open, |
| 1906 | .release = idetape_chrdev_release, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 1907 | .llseek = noop_llseek, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1908 | }; |
| 1909 | |
Al Viro | a4600f8 | 2008-03-02 10:27:58 -0500 | [diff] [blame] | 1910 | static int idetape_open(struct block_device *bdev, fmode_t mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1911 | { |
Arnd Bergmann | 6e9624b | 2010-08-07 18:25:34 +0200 | [diff] [blame] | 1912 | struct ide_tape_obj *tape; |
| 1913 | |
Arnd Bergmann | 2a48fc0 | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 1914 | mutex_lock(&ide_tape_mutex); |
Arnd Bergmann | 6e9624b | 2010-08-07 18:25:34 +0200 | [diff] [blame] | 1915 | tape = ide_tape_get(bdev->bd_disk, false, 0); |
Arnd Bergmann | 2a48fc0 | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 1916 | mutex_unlock(&ide_tape_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1917 | |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1918 | if (!tape) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1919 | return -ENXIO; |
| 1920 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1921 | return 0; |
| 1922 | } |
| 1923 | |
Al Viro | db2a144 | 2013-05-05 21:52:57 -0400 | [diff] [blame] | 1924 | static void idetape_release(struct gendisk *disk, fmode_t mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1925 | { |
Borislav Petkov | 5aeddf9 | 2008-10-13 21:39:34 +0200 | [diff] [blame] | 1926 | struct ide_tape_obj *tape = ide_drv_g(disk, ide_tape_obj); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1927 | |
Arnd Bergmann | 2a48fc0 | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 1928 | mutex_lock(&ide_tape_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1929 | ide_tape_put(tape); |
Arnd Bergmann | 2a48fc0 | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 1930 | mutex_unlock(&ide_tape_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1931 | } |
| 1932 | |
Al Viro | a4600f8 | 2008-03-02 10:27:58 -0500 | [diff] [blame] | 1933 | static int idetape_ioctl(struct block_device *bdev, fmode_t mode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1934 | unsigned int cmd, unsigned long arg) |
| 1935 | { |
Borislav Petkov | 5aeddf9 | 2008-10-13 21:39:34 +0200 | [diff] [blame] | 1936 | 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] | 1937 | ide_drive_t *drive = tape->drive; |
Arnd Bergmann | 8a6cfeb | 2010-07-08 10:18:46 +0200 | [diff] [blame] | 1938 | int err; |
| 1939 | |
Arnd Bergmann | 2a48fc0 | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 1940 | mutex_lock(&ide_tape_mutex); |
Arnd Bergmann | 8a6cfeb | 2010-07-08 10:18:46 +0200 | [diff] [blame] | 1941 | err = generic_ide_ioctl(drive, bdev, cmd, arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1942 | if (err == -EINVAL) |
| 1943 | err = idetape_blkdev_ioctl(drive, cmd, arg); |
Arnd Bergmann | 2a48fc0 | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 1944 | mutex_unlock(&ide_tape_mutex); |
Arnd Bergmann | 8a6cfeb | 2010-07-08 10:18:46 +0200 | [diff] [blame] | 1945 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1946 | return err; |
| 1947 | } |
| 1948 | |
Alexey Dobriyan | 83d5cde | 2009-09-21 17:01:13 -0700 | [diff] [blame] | 1949 | static const struct block_device_operations idetape_block_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1950 | .owner = THIS_MODULE, |
Al Viro | a4600f8 | 2008-03-02 10:27:58 -0500 | [diff] [blame] | 1951 | .open = idetape_open, |
| 1952 | .release = idetape_release, |
Arnd Bergmann | 8a6cfeb | 2010-07-08 10:18:46 +0200 | [diff] [blame] | 1953 | .ioctl = idetape_ioctl, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1954 | }; |
| 1955 | |
Russell King | 4031bbe | 2006-01-06 11:41:00 +0000 | [diff] [blame] | 1956 | static int ide_tape_probe(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1957 | { |
| 1958 | idetape_tape_t *tape; |
| 1959 | struct gendisk *g; |
| 1960 | int minor; |
| 1961 | |
Borislav Petkov | e972d70 | 2009-07-17 23:55:16 +0000 | [diff] [blame] | 1962 | ide_debug_log(IDE_DBG_FUNC, "enter"); |
| 1963 | |
| 1964 | if (!strstr(DRV_NAME, drive->driver_req)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1965 | goto failed; |
Bartlomiej Zolnierkiewicz | 2a92466 | 2008-10-10 22:39:24 +0200 | [diff] [blame] | 1966 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1967 | if (drive->media != ide_tape) |
| 1968 | goto failed; |
Bartlomiej Zolnierkiewicz | 2a92466 | 2008-10-10 22:39:24 +0200 | [diff] [blame] | 1969 | |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame] | 1970 | if ((drive->dev_flags & IDE_DFLAG_ID_READ) && |
| 1971 | ide_check_atapi_device(drive, DRV_NAME) == 0) { |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1972 | printk(KERN_ERR "ide-tape: %s: not supported by this version of" |
| 1973 | " the driver\n", drive->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1974 | goto failed; |
| 1975 | } |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1976 | tape = kzalloc(sizeof(idetape_tape_t), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1977 | if (tape == NULL) { |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 1978 | printk(KERN_ERR "ide-tape: %s: Can't allocate a tape struct\n", |
| 1979 | drive->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1980 | goto failed; |
| 1981 | } |
| 1982 | |
| 1983 | g = alloc_disk(1 << PARTN_BITS); |
| 1984 | if (!g) |
| 1985 | goto out_free_tape; |
| 1986 | |
| 1987 | ide_init_disk(g, drive); |
| 1988 | |
Bartlomiej Zolnierkiewicz | 8fed436 | 2009-02-25 20:28:24 +0100 | [diff] [blame] | 1989 | tape->dev.parent = &drive->gendev; |
| 1990 | tape->dev.release = ide_tape_release; |
Kees Cook | 02aa2a3 | 2013-07-03 15:04:56 -0700 | [diff] [blame] | 1991 | dev_set_name(&tape->dev, "%s", dev_name(&drive->gendev)); |
Bartlomiej Zolnierkiewicz | 8fed436 | 2009-02-25 20:28:24 +0100 | [diff] [blame] | 1992 | |
| 1993 | if (device_register(&tape->dev)) |
| 1994 | goto out_free_disk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1995 | |
| 1996 | tape->drive = drive; |
| 1997 | tape->driver = &idetape_driver; |
| 1998 | tape->disk = g; |
| 1999 | |
| 2000 | g->private_data = &tape->driver; |
| 2001 | |
| 2002 | drive->driver_data = tape; |
| 2003 | |
Arjan van de Ven | cf8b897 | 2006-03-23 03:00:45 -0800 | [diff] [blame] | 2004 | mutex_lock(&idetape_ref_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2005 | for (minor = 0; idetape_devs[minor]; minor++) |
| 2006 | ; |
| 2007 | idetape_devs[minor] = tape; |
Arjan van de Ven | cf8b897 | 2006-03-23 03:00:45 -0800 | [diff] [blame] | 2008 | mutex_unlock(&idetape_ref_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2009 | |
| 2010 | idetape_setup(drive, tape, minor); |
| 2011 | |
Greg Kroah-Hartman | 3ee074b | 2008-07-21 20:03:34 -0700 | [diff] [blame] | 2012 | device_create(idetape_sysfs_class, &drive->gendev, |
| 2013 | MKDEV(IDETAPE_MAJOR, minor), NULL, "%s", tape->name); |
| 2014 | device_create(idetape_sysfs_class, &drive->gendev, |
| 2015 | MKDEV(IDETAPE_MAJOR, minor + 128), NULL, |
| 2016 | "n%s", tape->name); |
Will Dyson | d5dee80 | 2005-09-16 02:55:07 -0700 | [diff] [blame] | 2017 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2018 | g->fops = &idetape_block_ops; |
| 2019 | ide_register_region(g); |
| 2020 | |
| 2021 | return 0; |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 2022 | |
Bartlomiej Zolnierkiewicz | 8fed436 | 2009-02-25 20:28:24 +0100 | [diff] [blame] | 2023 | out_free_disk: |
| 2024 | put_disk(g); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2025 | out_free_tape: |
| 2026 | kfree(tape); |
| 2027 | failed: |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 2028 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2029 | } |
| 2030 | |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2031 | static void __exit idetape_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2032 | { |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 2033 | driver_unregister(&idetape_driver.gen_driver); |
Will Dyson | d5dee80 | 2005-09-16 02:55:07 -0700 | [diff] [blame] | 2034 | class_destroy(idetape_sysfs_class); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2035 | unregister_chrdev(IDETAPE_MAJOR, "ht"); |
| 2036 | } |
| 2037 | |
Bartlomiej Zolnierkiewicz | 17514e8 | 2005-11-19 22:24:35 +0100 | [diff] [blame] | 2038 | static int __init idetape_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2039 | { |
Will Dyson | d5dee80 | 2005-09-16 02:55:07 -0700 | [diff] [blame] | 2040 | int error = 1; |
| 2041 | idetape_sysfs_class = class_create(THIS_MODULE, "ide_tape"); |
| 2042 | if (IS_ERR(idetape_sysfs_class)) { |
| 2043 | idetape_sysfs_class = NULL; |
| 2044 | printk(KERN_ERR "Unable to create sysfs class for ide tapes\n"); |
| 2045 | error = -EBUSY; |
| 2046 | goto out; |
| 2047 | } |
| 2048 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2049 | if (register_chrdev(IDETAPE_MAJOR, "ht", &idetape_fops)) { |
Borislav Petkov | 5a04cfa | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2050 | printk(KERN_ERR "ide-tape: Failed to register chrdev" |
| 2051 | " interface\n"); |
Will Dyson | d5dee80 | 2005-09-16 02:55:07 -0700 | [diff] [blame] | 2052 | error = -EBUSY; |
| 2053 | goto out_free_class; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2054 | } |
Will Dyson | d5dee80 | 2005-09-16 02:55:07 -0700 | [diff] [blame] | 2055 | |
| 2056 | error = driver_register(&idetape_driver.gen_driver); |
| 2057 | if (error) |
Alexey Khoroshilov | 79f18a0 | 2016-04-30 01:11:12 +0300 | [diff] [blame] | 2058 | goto out_free_chrdev; |
Will Dyson | d5dee80 | 2005-09-16 02:55:07 -0700 | [diff] [blame] | 2059 | |
| 2060 | return 0; |
| 2061 | |
Alexey Khoroshilov | 79f18a0 | 2016-04-30 01:11:12 +0300 | [diff] [blame] | 2062 | out_free_chrdev: |
| 2063 | unregister_chrdev(IDETAPE_MAJOR, "ht"); |
Will Dyson | d5dee80 | 2005-09-16 02:55:07 -0700 | [diff] [blame] | 2064 | out_free_class: |
| 2065 | class_destroy(idetape_sysfs_class); |
| 2066 | out: |
| 2067 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2068 | } |
| 2069 | |
Kay Sievers | 263756e | 2005-12-12 18:03:44 +0100 | [diff] [blame] | 2070 | MODULE_ALIAS("ide:*m-tape*"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2071 | module_init(idetape_init); |
| 2072 | module_exit(idetape_exit); |
| 2073 | MODULE_ALIAS_CHARDEV_MAJOR(IDETAPE_MAJOR); |
Borislav Petkov | 9c14576 | 2008-02-06 02:57:54 +0100 | [diff] [blame] | 2074 | MODULE_DESCRIPTION("ATAPI Streaming TAPE Driver"); |
| 2075 | MODULE_LICENSE("GPL"); |