2 * acsi.c -- Device driver for Atari ACSI hard disks
4 * Copyright 1994 Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de>
6 * Some parts are based on hd.c by Linus Torvalds
8 * This file is subject to the terms and conditions of the GNU General Public
9 * License. See the file COPYING in the main directory of this archive for
15 * Still to in this file:
16 * - If a command ends with an error status (!= 0), the following
17 * REQUEST SENSE commands (4 to fill the ST-DMA FIFO) are done by
18 * polling the _IRQ signal (not interrupt-driven). This should be
19 * avoided in future because it takes up a non-neglectible time in
20 * the interrupt service routine while interrupts are disabled.
21 * Maybe a timer interrupt will get lost :-(
27 * - All ACSI devices (disks, CD-ROMs, ...) use major number 28.
28 * Minors are organized like it is with SCSI: The upper 4 bits
29 * identify the device, the lower 4 bits the partition.
30 * The device numbers (the upper 4 bits) are given in the same
31 * order as the devices are found on the bus.
32 * - Up to 8 LUNs are supported for each target (if CONFIG_ACSI_MULTI_LUN
33 * is defined), but only a total of 16 devices (due to minor
34 * numbers...). Note that Atari allows only a maximum of 4 targets
35 * (i.e. controllers, not devices) on the ACSI bus!
36 * - A optimizing scheme similar to SCSI scatter-gather is implemented.
37 * - Removable media are supported. After a medium change to device
38 * is reinitialized (partition check etc.). Also, if the device
39 * knows the PREVENT/ALLOW MEDIUM REMOVAL command, the door should
40 * be locked and unlocked when mounting the first or unmounting the
41 * last filesystem on the device. The code is untested, because I
42 * don't have a removable hard disk.
46 #include <linux/config.h>
47 #include <linux/module.h>
48 #include <linux/errno.h>
49 #include <linux/signal.h>
50 #include <linux/sched.h>
51 #include <linux/timer.h>
53 #include <linux/kernel.h>
54 #include <linux/genhd.h>
55 #include <linux/delay.h>
57 #include <linux/major.h>
58 #include <linux/slab.h>
59 #include <linux/interrupt.h>
60 #include <scsi/scsi.h> /* for SCSI_IOCTL_GET_IDLUN */
61 #include <scsi/scsi_ioctl.h>
62 #include <linux/hdreg.h> /* for HDIO_GETGEO */
63 #include <linux/blkpg.h>
64 #include <linux/buffer_head.h>
65 #include <linux/blkdev.h>
67 #include <asm/setup.h>
68 #include <asm/pgtable.h>
69 #include <asm/system.h>
70 #include <asm/uaccess.h>
71 #include <asm/atarihw.h>
72 #include <asm/atariints.h>
73 #include <asm/atari_acsi.h>
74 #include <asm/atari_stdma.h>
75 #include <asm/atari_stram.h>
77 static void (*do_acsi)(void) = NULL;
78 static struct request_queue *acsi_queue;
79 #define QUEUE (acsi_queue)
80 #define CURRENT elv_next_request(acsi_queue)
86 #define MAX_ERRORS 8 /* Max read/write errors/sector */
87 #define MAX_LUN 8 /* Max LUNs per target */
90 #define ACSI_BUFFER_SIZE (16*1024) /* "normal" ACSI buffer size */
91 #define ACSI_BUFFER_MINSIZE (2048) /* min. buf size if ext. DMA */
92 #define ACSI_BUFFER_SIZE_ORDER 2 /* order size for above */
93 #define ACSI_BUFFER_MINSIZE_ORDER 0 /* order size for above */
94 #define ACSI_BUFFER_SECTORS (ACSI_BUFFER_SIZE/512)
96 #define ACSI_BUFFER_ORDER \
97 (ATARIHW_PRESENT(EXTD_DMA) ? \
98 ACSI_BUFFER_MINSIZE_ORDER : \
99 ACSI_BUFFER_SIZE_ORDER)
101 #define ACSI_TIMEOUT (4*HZ)
103 /* minimum delay between two commands */
105 #define COMMAND_DELAY 500
108 NONE, HARDDISK, CDROM
111 struct acsi_info_struct {
112 ACSI_TYPE type; /* type of device */
113 unsigned target; /* target number */
114 unsigned lun; /* LUN in target controller */
115 unsigned removable : 1; /* Flag for removable media */
116 unsigned read_only : 1; /* Flag for read only devices */
117 unsigned old_atari_disk : 1; /* Is an old Atari disk */
118 unsigned changed : 1; /* Medium has been changed */
119 unsigned long size; /* #blocks */
121 } acsi_info[MAX_DEV];
127 #define NO_SENSE 0x00
128 #define RECOVERED_ERROR 0x01
129 #define NOT_READY 0x02
130 #define MEDIUM_ERROR 0x03
131 #define HARDWARE_ERROR 0x04
132 #define ILLEGAL_REQUEST 0x05
133 #define UNIT_ATTENTION 0x06
134 #define DATA_PROTECT 0x07
135 #define BLANK_CHECK 0x08
136 #define COPY_ABORTED 0x0a
137 #define ABORTED_COMMAND 0x0b
138 #define VOLUME_OVERFLOW 0x0d
139 #define MISCOMPARE 0x0e
146 #define TYPE_DISK 0x00
147 #define TYPE_TAPE 0x01
148 #define TYPE_WORM 0x04
149 #define TYPE_ROM 0x05
150 #define TYPE_MOD 0x07
151 #define TYPE_NO_LUN 0x7f
153 /* The data returned by MODE SENSE differ between the old Atari
154 * hard disks and SCSI disks connected to ACSI. In the following, both
155 * formats are defined and some macros to operate on them potably.
159 unsigned long dummy[2];
160 unsigned long sector_size;
161 unsigned char format_code;
162 #define ATARI_SENSE_FORMAT_FIX 1
163 #define ATARI_SENSE_FORMAT_CHNG 2
164 unsigned char cylinders_h;
165 unsigned char cylinders_l;
167 unsigned char reduced_h;
168 unsigned char reduced_l;
169 unsigned char precomp_h;
170 unsigned char precomp_l;
171 unsigned char landing_zone;
172 unsigned char steprate;
174 #define ATARI_SENSE_TYPE_FIXCHNG_MASK 4
175 #define ATARI_SENSE_TYPE_SOFTHARD_MASK 8
176 #define ATARI_SENSE_TYPE_FIX 4
177 #define ATARI_SENSE_TYPE_CHNG 0
178 #define ATARI_SENSE_TYPE_SOFT 0
179 #define ATARI_SENSE_TYPE_HARD 8
180 unsigned char sectors;
183 #define ATARI_CAPACITY(sd) \
184 (((int)((sd).cylinders_h<<8)|(sd).cylinders_l) * \
185 (sd).heads * (sd).sectors)
189 unsigned char dummy1;
190 unsigned char medium_type;
191 unsigned char dummy2;
192 unsigned char descriptor_size;
193 unsigned long block_count;
194 unsigned long sector_size;
196 unsigned char page_code;
197 unsigned char page_size;
198 unsigned char page_flags;
199 unsigned char qualifier;
202 #define SCSI_CAPACITY(sd) ((sd).block_count & 0xffffff)
206 ATARI_SENSE_DATA atari;
207 SCSI_SENSE_DATA scsi;
210 #define SENSE_TYPE_UNKNOWN 0
211 #define SENSE_TYPE_ATARI 1
212 #define SENSE_TYPE_SCSI 2
214 #define SENSE_TYPE(sd) \
215 (((sd).atari.dummy[0] == 8 && \
216 ((sd).atari.format_code == 1 || \
217 (sd).atari.format_code == 2)) ? SENSE_TYPE_ATARI : \
218 ((sd).scsi.dummy1 >= 11) ? SENSE_TYPE_SCSI : \
221 #define CAPACITY(sd) \
222 (SENSE_TYPE(sd) == SENSE_TYPE_ATARI ? \
223 ATARI_CAPACITY((sd).atari) : \
224 SCSI_CAPACITY((sd).scsi))
226 #define SECTOR_SIZE(sd) \
227 (SENSE_TYPE(sd) == SENSE_TYPE_ATARI ? \
228 (sd).atari.sector_size : \
229 (sd).scsi.sector_size & 0xffffff)
231 /* Default size if capacity cannot be determined (1 GByte) */
232 #define DEFAULT_SIZE 0x1fffff
234 #define CARTRCH_STAT(aip,buf) \
235 (aip->old_atari_disk ? \
236 (((buf)[0] & 0x7f) == 0x28) : \
237 ((((buf)[0] & 0x70) == 0x70) ? \
238 (((buf)[2] & 0x0f) == 0x06) : \
239 (((buf)[0] & 0x0f) == 0x06))) \
241 /* These two are also exported to other drivers that work on the ACSI bus and
242 * need an ST-RAM buffer. */
244 unsigned long phys_acsi_buffer;
248 static int CurrentNReq;
249 static int CurrentNSect;
250 static char *CurrentBuffer;
252 static DEFINE_SPINLOCK(acsi_lock);
255 #define SET_TIMER() mod_timer(&acsi_timer, jiffies + ACSI_TIMEOUT)
256 #define CLEAR_TIMER() del_timer(&acsi_timer)
258 static unsigned long STramMask;
259 #define STRAM_ADDR(a) (((a) & STramMask) == 0)
265 static char tur_cmd[6] = { 0x00, 0, 0, 0, 0, 0 };
266 static char modesense_cmd[6] = { 0x1a, 0, 0, 0, 24, 0 };
267 static char modeselect_cmd[6] = { 0x15, 0, 0, 0, 12, 0 };
268 static char inquiry_cmd[6] = { 0x12, 0, 0, 0,255, 0 };
269 static char reqsense_cmd[6] = { 0x03, 0, 0, 0, 4, 0 };
270 static char read_cmd[6] = { 0x08, 0, 0, 0, 0, 0 };
271 static char write_cmd[6] = { 0x0a, 0, 0, 0, 0, 0 };
272 static char pa_med_rem_cmd[6] = { 0x1e, 0, 0, 0, 0, 0 };
274 #define CMDSET_TARG_LUN(cmd,targ,lun) \
276 cmd[0] = (cmd[0] & ~0xe0) | (targ)<<5; \
277 cmd[1] = (cmd[1] & ~0xe0) | (lun)<<5; \
280 #define CMDSET_BLOCK(cmd,blk) \
282 unsigned long __blk = (blk); \
283 cmd[3] = __blk; __blk >>= 8; \
284 cmd[2] = __blk; __blk >>= 8; \
285 cmd[1] = (cmd[1] & 0xe0) | (__blk & 0x1f); \
288 #define CMDSET_LEN(cmd,len) \
293 /* ACSI errors (from REQUEST SENSE); There are two tables, one for the
294 * old Atari disks and one for SCSI on ACSI disks.
300 } atari_acsi_errors[] = {
301 { 0x00, "No error (??)" },
302 { 0x01, "No index pulses" },
303 { 0x02, "Seek not complete" },
304 { 0x03, "Write fault" },
305 { 0x04, "Drive not ready" },
306 { 0x06, "No Track 00 signal" },
307 { 0x10, "ECC error in ID field" },
308 { 0x11, "Uncorrectable data error" },
309 { 0x12, "ID field address mark not found" },
310 { 0x13, "Data field address mark not found" },
311 { 0x14, "Record not found" },
312 { 0x15, "Seek error" },
313 { 0x18, "Data check in no retry mode" },
314 { 0x19, "ECC error during verify" },
315 { 0x1a, "Access to bad block" },
316 { 0x1c, "Unformatted or bad format" },
317 { 0x20, "Invalid command" },
318 { 0x21, "Invalid block address" },
319 { 0x23, "Volume overflow" },
320 { 0x24, "Invalid argument" },
321 { 0x25, "Invalid drive number" },
322 { 0x26, "Byte zero parity check" },
323 { 0x28, "Cartride changed" },
324 { 0x2c, "Error count overflow" },
325 { 0x30, "Controller selftest failed" }
328 scsi_acsi_errors[] = {
329 { 0x00, "No error (??)" },
330 { 0x01, "Recovered error" },
331 { 0x02, "Drive not ready" },
332 { 0x03, "Uncorrectable medium error" },
333 { 0x04, "Hardware error" },
334 { 0x05, "Illegal request" },
335 { 0x06, "Unit attention (Reset or cartridge changed)" },
336 { 0x07, "Data protection" },
337 { 0x08, "Blank check" },
338 { 0x0b, "Aborted Command" },
339 { 0x0d, "Volume overflow" }
344 /***************************** Prototypes *****************************/
346 static int acsicmd_dma( const char *cmd, char *buffer, int blocks, int
348 static int acsi_reqsense( char *buffer, int targ, int lun);
349 static void acsi_print_error(const unsigned char *errblk, struct acsi_info_struct *aip);
350 static irqreturn_t acsi_interrupt (int irq, void *data, struct pt_regs *fp);
351 static void unexpected_acsi_interrupt( void );
352 static void bad_rw_intr( void );
353 static void read_intr( void );
354 static void write_intr( void);
355 static void acsi_times_out( unsigned long dummy );
356 static void copy_to_acsibuffer( void );
357 static void copy_from_acsibuffer( void );
358 static void do_end_requests( void );
359 static void do_acsi_request( request_queue_t * );
360 static void redo_acsi_request( void );
361 static int acsi_ioctl( struct inode *inode, struct file *file, unsigned int
362 cmd, unsigned long arg );
363 static int acsi_open( struct inode * inode, struct file * filp );
364 static int acsi_release( struct inode * inode, struct file * file );
365 static void acsi_prevent_removal(struct acsi_info_struct *aip, int flag );
366 static int acsi_change_blk_size( int target, int lun);
367 static int acsi_mode_sense( int target, int lun, SENSE_DATA *sd );
368 static int acsi_revalidate (struct gendisk *disk);
370 /************************* End of Prototypes **************************/
373 DEFINE_TIMER(acsi_timer, acsi_times_out, 0, 0);
376 #ifdef CONFIG_ATARI_SLM
378 extern int attach_slm( int target, int lun );
379 extern int slm_init( void );
385 /***********************************************************************
389 **********************************************************************/
393 * The following two functions wait for _IRQ to become Low or High,
394 * resp., with a timeout. The 'timeout' parameter is in jiffies
396 * If the functions are called with timer interrupts on (int level <
397 * 6), the timeout is based on the 'jiffies' variable to provide exact
398 * timeouts for device probing etc.
399 * If interrupts are disabled, the number of tries is based on the
400 * 'loops_per_jiffy' variable. A rough estimation is sufficient here...
405 __asm__ __volatile__ ( "movew %/sr,%0" : "=dm" (__sr) ); \
409 int acsi_wait_for_IRQ( unsigned timeout )
413 unsigned long maxjif = jiffies + timeout;
414 while (time_before(jiffies, maxjif))
415 if (!(mfp.par_dt_reg & 0x20)) return( 1 );
418 long tries = loops_per_jiffy / 8 * timeout;
419 while( --tries >= 0 )
420 if (!(mfp.par_dt_reg & 0x20)) return( 1 );
422 return( 0 ); /* timeout! */
426 int acsi_wait_for_noIRQ( unsigned timeout )
430 unsigned long maxjif = jiffies + timeout;
431 while (time_before(jiffies, maxjif))
432 if (mfp.par_dt_reg & 0x20) return( 1 );
435 long tries = loops_per_jiffy * timeout / 8;
436 while( tries-- >= 0 )
437 if (mfp.par_dt_reg & 0x20) return( 1 );
439 return( 0 ); /* timeout! */
442 static struct timeval start_time;
445 acsi_delay_start(void)
447 do_gettimeofday(&start_time);
450 /* wait from acsi_delay_start to now usec (<1E6) usec */
453 acsi_delay_end(long usec)
455 struct timeval end_time;
457 do_gettimeofday(&end_time);
458 deltau=end_time.tv_usec - start_time.tv_usec;
459 deltas=end_time.tv_sec - start_time.tv_sec;
460 if (deltas > 1 || deltas < 0)
469 /* acsicmd_dma() sends an ACSI command and sets up the DMA to transfer
470 * 'blocks' blocks of 512 bytes from/to 'buffer'.
471 * Because the _IRQ signal is used for handshaking the command bytes,
472 * the ACSI interrupt has to be disabled in this function. If the end
473 * of the operation should be signalled by a real interrupt, it has to be
474 * reenabled afterwards.
477 static int acsicmd_dma( const char *cmd, char *buffer, int blocks, int rwflag, int enable)
479 { unsigned long flags, paddr;
483 if (rwflag || *cmd == 0x0a) {
484 printk( "ACSI: Write commands disabled!\n" );
489 rwflag = rwflag ? 0x100 : 0;
490 paddr = virt_to_phys( buffer );
492 acsi_delay_end(COMMAND_DELAY);
495 local_irq_save(flags);
497 dma_wd.dma_mode_status = 0x88 | rwflag;
500 /* set DMA address */
501 dma_wd.dma_lo = (unsigned char)paddr;
504 dma_wd.dma_md = (unsigned char)paddr;
507 if (ATARIHW_PRESENT(EXTD_DMA))
508 st_dma_ext_dmahi = (unsigned short)paddr;
510 dma_wd.dma_hi = (unsigned char)paddr;
512 local_irq_restore(flags);
514 /* send the command bytes except the last */
515 for( i = 0; i < 5; ++i ) {
516 DMA_LONG_WRITE( *cmd++, 0x8a | rwflag );
518 if (!acsi_wait_for_IRQ( HZ/2 )) return( 0 ); /* timeout */
521 /* Clear FIFO and switch DMA to correct direction */
522 dma_wd.dma_mode_status = 0x92 | (rwflag ^ 0x100);
524 dma_wd.dma_mode_status = 0x92 | rwflag;
527 /* How many sectors for DMA */
528 dma_wd.fdc_acces_seccount = blocks;
531 /* send last command byte */
532 dma_wd.dma_mode_status = 0x8a | rwflag;
534 DMA_LONG_WRITE( *cmd++, 0x0a | rwflag );
544 * acsicmd_nodma() sends an ACSI command that requires no DMA.
547 int acsicmd_nodma( const char *cmd, int enable)
551 acsi_delay_end(COMMAND_DELAY);
554 /* send first command byte */
555 dma_wd.dma_mode_status = 0x88;
557 DMA_LONG_WRITE( *cmd++, 0x8a );
559 if (!acsi_wait_for_IRQ( HZ/2 )) return( 0 ); /* timeout */
561 /* send the intermediate command bytes */
562 for( i = 0; i < 4; ++i ) {
563 DMA_LONG_WRITE( *cmd++, 0x8a );
565 if (!acsi_wait_for_IRQ( HZ/2 )) return( 0 ); /* timeout */
568 /* send last command byte */
569 DMA_LONG_WRITE( *cmd++, 0x0a );
575 /* Note that the ACSI interrupt is still disabled after this
576 * function. If you want to get the IRQ delivered, enable it manually!
581 static int acsi_reqsense( char *buffer, int targ, int lun)
584 CMDSET_TARG_LUN( reqsense_cmd, targ, lun);
585 if (!acsicmd_dma( reqsense_cmd, buffer, 1, 0, 0 )) return( 0 );
586 if (!acsi_wait_for_IRQ( 10 )) return( 0 );
588 if (!acsicmd_nodma( reqsense_cmd, 0 )) return( 0 );
589 if (!acsi_wait_for_IRQ( 10 )) return( 0 );
591 if (!acsicmd_nodma( reqsense_cmd, 0 )) return( 0 );
592 if (!acsi_wait_for_IRQ( 10 )) return( 0 );
594 if (!acsicmd_nodma( reqsense_cmd, 0 )) return( 0 );
595 if (!acsi_wait_for_IRQ( 10 )) return( 0 );
597 dma_cache_maintenance( virt_to_phys(buffer), 16, 0 );
604 * ACSI status phase: get the status byte from the bus
606 * I've seen several times that a 0xff status is read, propably due to
607 * a timing error. In this case, the procedure is repeated after the
611 int acsi_getstatus( void )
617 if (!acsi_wait_for_IRQ( 100 )) {
621 dma_wd.dma_mode_status = 0x8a;
623 status = dma_wd.fdc_acces_seccount;
624 if (status != 0xff) break;
626 printk("ACSI: skipping 0xff status byte\n" );
629 acsi_wait_for_noIRQ( 20 );
631 dma_wd.dma_mode_status = 0x80;
633 acsi_wait_for_noIRQ( 20 );
636 return( status & 0x1f ); /* mask of the device# */
640 #if (defined(CONFIG_ATARI_SLM) || defined(CONFIG_ATARI_SLM_MODULE))
642 /* Receive data in an extended status phase. Needed by SLM printer. */
644 int acsi_extstatus( char *buffer, int cnt )
651 if (!acsi_wait_for_IRQ( 40 )) return( 0 );
652 dma_wd.dma_mode_status = 0x8a;
654 status = dma_wd.fdc_acces_seccount;
656 *buffer++ = status & 0xff;
663 /* Finish an extended status phase */
665 void acsi_end_extstatus( void )
668 dma_wd.dma_mode_status = 0x80;
670 acsi_wait_for_noIRQ( 20 );
675 /* Send data in an extended command phase */
677 int acsi_extcmd( unsigned char *buffer, int cnt )
681 DMA_LONG_WRITE( *buffer++, 0x8a );
683 if (!acsi_wait_for_IRQ( HZ/2 )) return( 0 ); /* timeout */
691 static void acsi_print_error(const unsigned char *errblk, struct acsi_info_struct *aip)
693 { int atari_err, i, errcode;
694 struct acsi_error *arr;
696 atari_err = aip->old_atari_disk;
698 errcode = errblk[0] & 0x7f;
700 if ((errblk[0] & 0x70) == 0x70)
701 errcode = errblk[2] & 0x0f;
703 errcode = errblk[0] & 0x0f;
705 printk( KERN_ERR "ACSI error 0x%02x", errcode );
707 if (errblk[0] & 0x80)
708 printk( " for sector %d",
709 ((errblk[1] & 0x1f) << 16) |
710 (errblk[2] << 8) | errblk[0] );
712 arr = atari_err ? atari_acsi_errors : scsi_acsi_errors;
713 i = atari_err ? sizeof(atari_acsi_errors)/sizeof(*atari_acsi_errors) :
714 sizeof(scsi_acsi_errors)/sizeof(*scsi_acsi_errors);
716 for( --i; i >= 0; --i )
717 if (arr[i].code == errcode) break;
719 printk( ": %s\n", arr[i].text );
722 /*******************************************************************
724 * ACSI interrupt routine
725 * Test, if this is a ACSI interrupt and call the irq handler
726 * Otherwise ignore this interrupt.
728 *******************************************************************/
730 static irqreturn_t acsi_interrupt(int irq, void *data, struct pt_regs *fp )
732 { void (*acsi_irq_handler)(void) = do_acsi;
737 if (!acsi_irq_handler)
738 acsi_irq_handler = unexpected_acsi_interrupt;
744 /******************************************************************
746 * The Interrupt handlers
748 *******************************************************************/
751 static void unexpected_acsi_interrupt( void )
754 printk( KERN_WARNING "Unexpected ACSI interrupt\n" );
758 /* This function is called in case of errors. Because we cannot reset
759 * the ACSI bus or a single device, there is no other choice than
760 * retrying several times :-(
763 static void bad_rw_intr( void )
769 if (++CURRENT->errors >= MAX_ERRORS)
770 end_request(CURRENT, 0);
771 /* Otherwise just retry */
775 static void read_intr( void )
779 status = acsi_getstatus();
781 struct gendisk *disk = CURRENT->rq_disk;
782 struct acsi_info_struct *aip = disk->private_data;
783 printk(KERN_ERR "%s: ", disk->disk_name);
784 if (!acsi_reqsense(acsi_buffer, aip->target, aip->lun))
785 printk( "ACSI error and REQUEST SENSE failed (status=0x%02x)\n", status );
787 acsi_print_error(acsi_buffer, aip);
788 if (CARTRCH_STAT(aip, acsi_buffer))
797 dma_cache_maintenance( virt_to_phys(CurrentBuffer), CurrentNSect*512, 0 );
798 if (CurrentBuffer == acsi_buffer)
799 copy_from_acsibuffer();
806 static void write_intr(void)
810 status = acsi_getstatus();
812 struct gendisk *disk = CURRENT->rq_disk;
813 struct acsi_info_struct *aip = disk->private_data;
814 printk( KERN_ERR "%s: ", disk->disk_name);
815 if (!acsi_reqsense( acsi_buffer, aip->target, aip->lun))
816 printk( "ACSI error and REQUEST SENSE failed (status=0x%02x)\n", status );
818 acsi_print_error(acsi_buffer, aip);
819 if (CARTRCH_STAT(aip, acsi_buffer))
832 static void acsi_times_out( unsigned long dummy )
836 if (!do_acsi) return;
839 printk( KERN_ERR "ACSI timeout\n" );
842 if (++CURRENT->errors >= MAX_ERRORS) {
844 printk( KERN_ERR "ACSI: too many errors.\n" );
846 end_request(CURRENT, 0);
854 /***********************************************************************
856 * Scatter-gather utility functions
858 ***********************************************************************/
861 static void copy_to_acsibuffer( void )
865 struct buffer_head *bh;
867 src = CURRENT->buffer;
872 memcpy( dst, src, CurrentNSect*512 );
874 for( i = 0; i < CurrentNReq; ++i ) {
875 memcpy( dst, src, bh->b_size );
877 if ((bh = bh->b_reqnext))
883 static void copy_from_acsibuffer( void )
887 struct buffer_head *bh;
889 dst = CURRENT->buffer;
894 memcpy( dst, src, CurrentNSect*512 );
896 for( i = 0; i < CurrentNReq; ++i ) {
897 memcpy( dst, src, bh->b_size );
899 if ((bh = bh->b_reqnext))
905 static void do_end_requests( void )
910 CURRENT->nr_sectors -= CurrentNSect;
911 CURRENT->current_nr_sectors -= CurrentNSect;
912 CURRENT->sector += CurrentNSect;
913 if (CURRENT->nr_sectors == 0)
914 end_request(CURRENT, 1);
917 for( i = 0; i < CurrentNReq; ++i ) {
918 n = CURRENT->bh->b_size >> 9;
919 CURRENT->nr_sectors -= n;
920 CURRENT->current_nr_sectors -= n;
921 CURRENT->sector += n;
922 end_request(CURRENT, 1);
930 /***********************************************************************
932 * do_acsi_request and friends
934 ***********************************************************************/
936 static void do_acsi_request( request_queue_t * q )
939 stdma_lock( acsi_interrupt, NULL );
944 static void redo_acsi_request( void )
946 unsigned block, target, lun, nsect;
948 unsigned long pbuffer;
949 struct buffer_head *bh;
950 struct gendisk *disk;
951 struct acsi_info_struct *aip;
966 disk = CURRENT->rq_disk;
967 aip = disk->private_data;
969 if (!CURRENT->bh && !buffer_locked(CURRENT->bh))
970 panic("ACSI: block not locked");
973 block = CURRENT->sector;
974 if (block+CURRENT->nr_sectors >= get_capacity(disk)) {
976 printk( "%s: attempted access for blocks %d...%ld past end of device at block %ld.\n",
978 block, block + CURRENT->nr_sectors - 1,
981 end_request(CURRENT, 0);
985 printk( KERN_NOTICE "%s: request denied because cartridge has "
986 "been changed.\n", disk->disk_name);
987 end_request(CURRENT, 0);
991 target = aip->target;
994 /* Find out how many sectors should be transferred from/to
995 * consecutive buffers and thus can be done with a single command.
997 buffer = CURRENT->buffer;
998 pbuffer = virt_to_phys(buffer);
999 nsect = CURRENT->current_nr_sectors;
1002 if ((bh = CURRENT->bh) && bh != CURRENT->bhtail) {
1003 if (!STRAM_ADDR(pbuffer)) {
1004 /* If transfer is done via the ACSI buffer anyway, we can
1005 * assemble as much bh's as fit in the buffer.
1007 while( (bh = bh->b_reqnext) ) {
1008 if (nsect + (bh->b_size>>9) > ACSI_BUFFER_SECTORS) break;
1009 nsect += bh->b_size >> 9;
1011 if (bh == CURRENT->bhtail) break;
1013 buffer = acsi_buffer;
1014 pbuffer = phys_acsi_buffer;
1017 unsigned long pendadr, pnewadr;
1018 pendadr = pbuffer + nsect*512;
1019 while( (bh = bh->b_reqnext) ) {
1020 pnewadr = virt_to_phys(bh->b_data);
1021 if (!STRAM_ADDR(pnewadr) || pendadr != pnewadr) break;
1022 nsect += bh->b_size >> 9;
1023 pendadr = pnewadr + bh->b_size;
1025 if (bh == CURRENT->bhtail) break;
1030 if (!STRAM_ADDR(pbuffer)) {
1031 buffer = acsi_buffer;
1032 pbuffer = phys_acsi_buffer;
1033 if (nsect > ACSI_BUFFER_SECTORS)
1034 nsect = ACSI_BUFFER_SECTORS;
1037 CurrentBuffer = buffer;
1038 CurrentNSect = nsect;
1040 if (rq_data_dir(CURRENT) == WRITE) {
1041 CMDSET_TARG_LUN( write_cmd, target, lun );
1042 CMDSET_BLOCK( write_cmd, block );
1043 CMDSET_LEN( write_cmd, nsect );
1044 if (buffer == acsi_buffer)
1045 copy_to_acsibuffer();
1046 dma_cache_maintenance( pbuffer, nsect*512, 1 );
1047 do_acsi = write_intr;
1048 if (!acsicmd_dma( write_cmd, buffer, nsect, 1, 1)) {
1050 printk( KERN_ERR "ACSI (write): Timeout in command block\n" );
1057 if (rq_data_dir(CURRENT) == READ) {
1058 CMDSET_TARG_LUN( read_cmd, target, lun );
1059 CMDSET_BLOCK( read_cmd, block );
1060 CMDSET_LEN( read_cmd, nsect );
1061 do_acsi = read_intr;
1062 if (!acsicmd_dma( read_cmd, buffer, nsect, 0, 1)) {
1064 printk( KERN_ERR "ACSI (read): Timeout in command block\n" );
1071 panic("unknown ACSI command");
1076 /***********************************************************************
1078 * Misc functions: ioctl, open, release, check_change, ...
1080 ***********************************************************************/
1082 static int acsi_getgeo(struct block_device *bdev, struct hd_geometry *geo)
1084 struct acsi_info_struct *aip = bdev->bd_disk->private_data;
1087 * Just fake some geometry here, it's nonsense anyway
1088 * To make it easy, use Adaptec's usual 64/32 mapping
1092 geo->cylinders = aip->size >> 11;
1096 static int acsi_ioctl( struct inode *inode, struct file *file,
1097 unsigned int cmd, unsigned long arg )
1099 struct gendisk *disk = inode->i_bdev->bd_disk;
1100 struct acsi_info_struct *aip = disk->private_data;
1102 case SCSI_IOCTL_GET_IDLUN:
1103 /* SCSI compatible GET_IDLUN call to get target's ID and LUN number */
1104 put_user( aip->target | (aip->lun << 8),
1105 &((Scsi_Idlun *) arg)->dev_id );
1106 put_user( 0, &((Scsi_Idlun *) arg)->host_unique_id );
1115 * Open a device, check for read-only and lock the medium if it is
1118 * Changes by Martin Rogge, 9th Aug 1995:
1119 * Check whether check_disk_change (and therefore revalidate_acsidisk)
1120 * was successful. They fail when there is no medium in the drive.
1122 * The problem of media being changed during an operation can be
1123 * ignored because of the prevent_removal code.
1125 * Added check for the validity of the device number.
1129 static int acsi_open( struct inode * inode, struct file * filp )
1131 struct gendisk *disk = inode->i_bdev->bd_disk;
1132 struct acsi_info_struct *aip = disk->private_data;
1134 if (aip->access_count == 0 && aip->removable) {
1136 aip->changed = 1; /* safety first */
1138 check_disk_change( inode->i_bdev );
1139 if (aip->changed) /* revalidate was not successful (no medium) */
1141 acsi_prevent_removal(aip, 1);
1143 aip->access_count++;
1145 if (filp && filp->f_mode) {
1146 check_disk_change( inode->i_bdev );
1147 if (filp->f_mode & 2) {
1148 if (aip->read_only) {
1149 acsi_release( inode, filp );
1159 * Releasing a block device means we sync() it, so that it can safely
1160 * be forgotten about...
1163 static int acsi_release( struct inode * inode, struct file * file )
1165 struct gendisk *disk = inode->i_bdev->bd_disk;
1166 struct acsi_info_struct *aip = disk->private_data;
1167 if (--aip->access_count == 0 && aip->removable)
1168 acsi_prevent_removal(aip, 0);
1173 * Prevent or allow a media change for removable devices.
1176 static void acsi_prevent_removal(struct acsi_info_struct *aip, int flag)
1178 stdma_lock( NULL, NULL );
1180 CMDSET_TARG_LUN(pa_med_rem_cmd, aip->target, aip->lun);
1181 CMDSET_LEN( pa_med_rem_cmd, flag );
1183 if (acsicmd_nodma(pa_med_rem_cmd, 0) && acsi_wait_for_IRQ(3*HZ))
1185 /* Do not report errors -- some devices may not know this command. */
1191 static int acsi_media_change(struct gendisk *disk)
1193 struct acsi_info_struct *aip = disk->private_data;
1195 if (!aip->removable)
1199 /* We can be sure that the medium has been changed -- REQUEST
1200 * SENSE has reported this earlier.
1204 /* If the flag isn't set, make a test by reading block 0.
1205 * If errors happen, it seems to be better to say "changed"...
1207 stdma_lock( NULL, NULL );
1208 CMDSET_TARG_LUN(read_cmd, aip->target, aip->lun);
1209 CMDSET_BLOCK( read_cmd, 0 );
1210 CMDSET_LEN( read_cmd, 1 );
1211 if (acsicmd_dma(read_cmd, acsi_buffer, 1, 0, 0) &&
1212 acsi_wait_for_IRQ(3*HZ)) {
1213 if (acsi_getstatus()) {
1214 if (acsi_reqsense(acsi_buffer, aip->target, aip->lun)) {
1215 if (CARTRCH_STAT(aip, acsi_buffer))
1219 printk( KERN_ERR "%s: REQUEST SENSE failed in test for "
1220 "medium change; assuming a change\n", disk->disk_name );
1226 printk( KERN_ERR "%s: Test for medium changed timed out; "
1227 "assuming a change\n", disk->disk_name);
1233 /* Now, after reading a block, the changed status is surely valid. */
1234 return aip->changed;
1238 static int acsi_change_blk_size( int target, int lun)
1242 for (i=0; i<12; i++)
1246 acsi_buffer[10] = 2;
1247 CMDSET_TARG_LUN( modeselect_cmd, target, lun);
1249 if (!acsicmd_dma( modeselect_cmd, acsi_buffer, 1,1,0) ||
1250 !acsi_wait_for_IRQ( 3*HZ ) ||
1251 acsi_getstatus() != 0 ) {
1258 static int acsi_mode_sense( int target, int lun, SENSE_DATA *sd )
1263 CMDSET_TARG_LUN( modesense_cmd, target, lun );
1264 for (page=0; page<4; page++) {
1265 modesense_cmd[2] = page;
1266 if (!acsicmd_dma( modesense_cmd, acsi_buffer, 1, 0, 0 ) ||
1267 !acsi_wait_for_IRQ( 3*HZ ) ||
1271 /* read twice to jump over the second 16-byte border! */
1273 if (acsi_wait_for_noIRQ( 20 ) &&
1274 acsicmd_nodma( modesense_cmd, 0 ) &&
1275 acsi_wait_for_IRQ( 3*HZ ) &&
1276 acsi_getstatus() == 0)
1283 dma_cache_maintenance( phys_acsi_buffer, sizeof(SENSE_DATA), 0 );
1284 *sd = *(SENSE_DATA *)acsi_buffer;
1286 /* Validity check, depending on type of data */
1288 switch( SENSE_TYPE(*sd) ) {
1290 case SENSE_TYPE_ATARI:
1291 if (CAPACITY(*sd) == 0)
1295 case SENSE_TYPE_SCSI:
1296 if (sd->scsi.descriptor_size != 8)
1300 case SENSE_TYPE_UNKNOWN:
1302 printk( KERN_ERR "ACSI target %d, lun %d: Cannot interpret "
1303 "sense data\n", target, lun );
1309 printk( "Mode sense data for ACSI target %d, lun %d seem not valid:",
1311 for( i = 0; i < sizeof(SENSE_DATA); ++i )
1312 printk( "%02x ", (unsigned char)acsi_buffer[i] );
1324 /*******************************************************************
1328 ********************************************************************/
1331 extern struct block_device_operations acsi_fops;
1333 static struct gendisk *acsi_gendisk[MAX_DEV];
1335 #define MAX_SCSI_DEVICE_CODE 10
1337 static const char *const scsi_device_types[MAX_SCSI_DEVICE_CODE] =
1340 "Sequential-Access",
1351 static void print_inquiry(unsigned char *data)
1355 printk(KERN_INFO " Vendor: ");
1356 for (i = 8; i < 16; i++)
1358 if (data[i] >= 0x20 && i < data[4] + 5)
1359 printk("%c", data[i]);
1365 for (i = 16; i < 32; i++)
1367 if (data[i] >= 0x20 && i < data[4] + 5)
1368 printk("%c", data[i]);
1374 for (i = 32; i < 36; i++)
1376 if (data[i] >= 0x20 && i < data[4] + 5)
1377 printk("%c", data[i]);
1386 printk(KERN_INFO " Type: %s ", (i < MAX_SCSI_DEVICE_CODE
1387 ? scsi_device_types[i]
1389 printk(" ANSI SCSI revision: %02x", data[2] & 0x07);
1390 if ((data[2] & 0x07) == 1 && (data[3] & 0x0f) == 1)
1398 * Changes by Martin Rogge, 9th Aug 1995:
1399 * acsi_devinit has been taken out of acsi_geninit, because it needs
1400 * to be called from revalidate_acsidisk. The result of request sense
1401 * is now checked for DRIVE NOT READY.
1403 * The structure *aip is only valid when acsi_devinit returns
1409 #define DEV_UNKNOWN 1
1410 #define DEV_SUPPORTED 2
1413 static int acsi_devinit(struct acsi_info_struct *aip)
1415 int status, got_inquiry;
1417 unsigned char reqsense, extsense;
1419 /*****************************************************************/
1420 /* Do a TEST UNIT READY command to test the presence of a device */
1421 /*****************************************************************/
1423 CMDSET_TARG_LUN(tur_cmd, aip->target, aip->lun);
1424 if (!acsicmd_nodma(tur_cmd, 0)) {
1425 /* timed out -> no device here */
1427 printk("target %d lun %d: timeout\n", aip->target, aip->lun);
1432 /*************************/
1433 /* Read the ACSI status. */
1434 /*************************/
1436 status = acsi_getstatus();
1438 if (status == 0x12) {
1439 /* The SLM printer should be the only device that
1440 * responds with the error code in the status byte. In
1441 * correct status bytes, bit 4 is never set.
1443 printk( KERN_INFO "Detected SLM printer at id %d lun %d\n",
1444 aip->target, aip->lun);
1447 /* ignore CHECK CONDITION, since some devices send a
1449 if ((status & 0x1e) != 0x2) {
1451 printk("target %d lun %d: status %d\n",
1452 aip->target, aip->lun, status);
1458 /*******************************/
1459 /* Do a REQUEST SENSE command. */
1460 /*******************************/
1462 if (!acsi_reqsense(acsi_buffer, aip->target, aip->lun)) {
1463 printk( KERN_WARNING "acsi_reqsense failed\n");
1465 acsi_buffer[2] = UNIT_ATTENTION;
1467 reqsense = acsi_buffer[0];
1468 extsense = acsi_buffer[2] & 0xf;
1470 if ((reqsense & 0x70) == 0x70) { /* extended sense */
1471 if (extsense != UNIT_ATTENTION &&
1472 extsense != NOT_READY) {
1474 printk("target %d lun %d: extended sense %d\n",
1475 aip->target, aip->lun, extsense);
1481 if (reqsense & 0x7f) {
1483 printk("target %d lun %d: sense %d\n",
1484 aip->target, aip->lun, reqsense);
1491 if (reqsense == 0x4) { /* SH204 Bug workaround */
1493 printk("target %d lun %d status=0 sense=4\n",
1494 aip->target, aip->lun);
1499 /***********************************************************/
1500 /* Do an INQUIRY command to get more infos on this device. */
1501 /***********************************************************/
1503 /* Assume default values */
1506 aip->old_atari_disk = 0;
1507 aip->changed = (extsense == NOT_READY); /* medium inserted? */
1508 aip->size = DEFAULT_SIZE;
1510 /* Fake inquiry result for old atari disks */
1511 memcpy(acsi_buffer, "\000\000\001\000 Adaptec 40xx"
1513 CMDSET_TARG_LUN(inquiry_cmd, aip->target, aip->lun);
1514 if (acsicmd_dma(inquiry_cmd, acsi_buffer, 1, 0, 0) &&
1515 acsi_getstatus() == 0) {
1516 acsicmd_nodma(inquiry_cmd, 0);
1518 dma_cache_maintenance( phys_acsi_buffer, 256, 0 );
1520 aip->removable = !!(acsi_buffer[1] & 0x80);
1522 if (aip->type == NONE) /* only at boot time */
1523 print_inquiry(acsi_buffer);
1524 switch(acsi_buffer[0]) {
1526 aip->type = HARDDISK;
1535 /****************************/
1536 /* Do a MODE SENSE command. */
1537 /****************************/
1539 if (!acsi_mode_sense(aip->target, aip->lun, &sense)) {
1540 printk( KERN_WARNING "No mode sense data.\n" );
1543 if ((SECTOR_SIZE(sense) != 512) &&
1544 ((aip->type != CDROM) ||
1545 !acsi_change_blk_size(aip->target, aip->lun) ||
1546 !acsi_mode_sense(aip->target, aip->lun, &sense) ||
1547 (SECTOR_SIZE(sense) != 512))) {
1548 printk( KERN_WARNING "Sector size != 512 not supported.\n" );
1551 /* There are disks out there that claim to have 0 sectors... */
1552 if (CAPACITY(sense))
1553 aip->size = CAPACITY(sense); /* else keep DEFAULT_SIZE */
1554 if (!got_inquiry && SENSE_TYPE(sense) == SENSE_TYPE_ATARI) {
1555 /* If INQUIRY failed and the sense data suggest an old
1556 * Atari disk (SH20x, Megafile), the disk is not removable
1559 aip->old_atari_disk = 1;
1562 /******************/
1563 /* We've done it. */
1564 /******************/
1566 return DEV_SUPPORTED;
1569 EXPORT_SYMBOL(acsi_delay_start);
1570 EXPORT_SYMBOL(acsi_delay_end);
1571 EXPORT_SYMBOL(acsi_wait_for_IRQ);
1572 EXPORT_SYMBOL(acsi_wait_for_noIRQ);
1573 EXPORT_SYMBOL(acsicmd_nodma);
1574 EXPORT_SYMBOL(acsi_getstatus);
1575 EXPORT_SYMBOL(acsi_buffer);
1576 EXPORT_SYMBOL(phys_acsi_buffer);
1578 #ifdef CONFIG_ATARI_SLM_MODULE
1579 void acsi_attach_SLMs( int (*attach_func)( int, int ) );
1581 EXPORT_SYMBOL(acsi_extstatus);
1582 EXPORT_SYMBOL(acsi_end_extstatus);
1583 EXPORT_SYMBOL(acsi_extcmd);
1584 EXPORT_SYMBOL(acsi_attach_SLMs);
1586 /* to remember IDs of SLM devices, SLM module is loaded later
1587 * (index is target#, contents is lun#, -1 means "no SLM") */
1591 static struct block_device_operations acsi_fops = {
1592 .owner = THIS_MODULE,
1594 .release = acsi_release,
1595 .ioctl = acsi_ioctl,
1596 .getgeo = acsi_getgeo,
1597 .media_changed = acsi_media_change,
1598 .revalidate_disk= acsi_revalidate,
1601 #ifdef CONFIG_ATARI_SLM_MODULE
1602 /* call attach_slm() for each device that is a printer; needed for init of SLM
1603 * driver as a module, since it's not yet present if acsi.c is inited and thus
1604 * the bus gets scanned. */
1605 void acsi_attach_SLMs( int (*attach_func)( int, int ) )
1609 for( i = 0; i < 8; ++i )
1610 if (SLM_devices[i] >= 0)
1611 n += (*attach_func)( i, SLM_devices[i] );
1612 printk( KERN_INFO "Found %d SLM printer(s) total.\n", n );
1614 #endif /* CONFIG_ATARI_SLM_MODULE */
1617 int acsi_init( void )
1621 struct acsi_info_struct *aip;
1622 #ifdef CONFIG_ATARI_SLM
1625 if (!MACH_IS_ATARI || !ATARIHW_PRESENT(ACSI))
1627 if (register_blkdev(ACSI_MAJOR, "ad")) {
1632 (char *)atari_stram_alloc(ACSI_BUFFER_SIZE, "acsi"))) {
1634 printk( KERN_ERR "Unable to get ACSI ST-Ram buffer.\n" );
1637 phys_acsi_buffer = virt_to_phys( acsi_buffer );
1638 STramMask = ATARIHW_PRESENT(EXTD_DMA) ? 0x00000000 : 0xff000000;
1640 acsi_queue = blk_init_queue(do_acsi_request, &acsi_lock);
1645 #ifdef CONFIG_ATARI_SLM
1651 printk( KERN_INFO "Probing ACSI devices:\n" );
1653 #ifdef CONFIG_ATARI_SLM_MODULE
1654 for( i = 0; i < 8; ++i )
1655 SLM_devices[i] = -1;
1657 stdma_lock(NULL, NULL);
1659 for (target = 0; target < 8 && NDevices < MAX_DEV; ++target) {
1662 aip = &acsi_info[NDevices];
1664 aip->target = target;
1666 i = acsi_devinit(aip);
1669 printk( KERN_INFO "Detected ");
1670 switch (aip->type) {
1679 printk(" ad%c at id %d lun %d ",
1680 'a' + NDevices, target, lun);
1682 printk("(removable) ");
1684 printk("(read-only) ");
1685 if (aip->size == DEFAULT_SIZE)
1686 printk(" unkown size, using default ");
1687 printk("%ld MByte\n",
1688 (aip->size*512+1024*1024/2)/(1024*1024));
1692 #ifdef CONFIG_ATARI_SLM
1693 n_slm += attach_slm( target, lun );
1696 #ifdef CONFIG_ATARI_SLM_MODULE
1697 SLM_devices[target] = lun;
1700 /* neither of the above: fall through to unknown device */
1702 printk( KERN_INFO "Detected unsupported device at "
1703 "id %d lun %d\n", target, lun);
1707 #ifdef CONFIG_ACSI_MULTI_LUN
1708 while (i != DEV_NONE && ++lun < MAX_LUN);
1714 /* reenable interrupt */
1718 #ifndef CONFIG_ATARI_SLM
1719 printk( KERN_INFO "Found %d ACSI device(s) total.\n", NDevices );
1721 printk( KERN_INFO "Found %d ACSI device(s) and %d SLM printer(s) total.\n",
1725 for( i = 0; i < NDevices; ++i ) {
1726 acsi_gendisk[i] = alloc_disk(16);
1727 if (!acsi_gendisk[i])
1731 for( i = 0; i < NDevices; ++i ) {
1732 struct gendisk *disk = acsi_gendisk[i];
1733 sprintf(disk->disk_name, "ad%c", 'a'+i);
1734 aip = &acsi_info[NDevices];
1735 sprintf(disk->devfs_name, "ad/target%d/lun%d", aip->target, aip->lun);
1736 disk->major = ACSI_MAJOR;
1737 disk->first_minor = i << 4;
1738 if (acsi_info[i].type != HARDDISK) {
1740 strcat(disk->devfs_name, "/disc");
1742 disk->fops = &acsi_fops;
1743 disk->private_data = &acsi_info[i];
1744 set_capacity(disk, acsi_info[i].size);
1745 disk->queue = acsi_queue;
1751 put_disk(acsi_gendisk[i]);
1753 blk_cleanup_queue(acsi_queue);
1755 atari_stram_free( acsi_buffer );
1757 unregister_blkdev( ACSI_MAJOR, "ad" );
1765 MODULE_LICENSE("GPL");
1767 int init_module(void)
1771 if ((err = acsi_init()))
1773 printk( KERN_INFO "ACSI driver loaded as module.\n");
1777 void cleanup_module(void)
1780 del_timer( &acsi_timer );
1781 blk_cleanup_queue(acsi_queue);
1782 atari_stram_free( acsi_buffer );
1784 if (unregister_blkdev( ACSI_MAJOR, "ad" ) != 0)
1785 printk( KERN_ERR "acsi: cleanup_module failed\n");
1787 for (i = 0; i < NDevices; i++) {
1788 del_gendisk(acsi_gendisk[i]);
1789 put_disk(acsi_gendisk[i]);
1795 * This routine is called to flush all partitions and partition tables
1796 * for a changed scsi disk, and then re-read the new partition table.
1797 * If we are revalidating a disk because of a media change, then we
1798 * enter with usage == 0. If we are using an ioctl, we automatically have
1799 * usage == 1 (we need an open channel to use an ioctl :-), so this
1802 * Changes by Martin Rogge, 9th Aug 1995:
1803 * got cd-roms to work by calling acsi_devinit. There are only two problems:
1804 * First, if there is no medium inserted, the status will remain "changed".
1805 * That is no problem at all, but our design of three-valued logic (medium
1806 * changed, medium not changed, no medium inserted).
1807 * Secondly the check could fail completely and the drive could deliver
1808 * nonsensical data, which could mess up the acsi_info[] structure. In
1809 * that case we try to make the entry safe.
1813 static int acsi_revalidate(struct gendisk *disk)
1815 struct acsi_info_struct *aip = disk->private_data;
1816 stdma_lock( NULL, NULL );
1817 if (acsi_devinit(aip) != DEV_SUPPORTED) {
1818 printk( KERN_ERR "ACSI: revalidate failed for target %d lun %d\n",
1819 aip->target, aip->lun);
1823 aip->changed = 1; /* next acsi_open will try again... */
1828 set_capacity(disk, aip->size);