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/module.h>
47 #include <linux/errno.h>
48 #include <linux/signal.h>
49 #include <linux/sched.h>
50 #include <linux/timer.h>
52 #include <linux/kernel.h>
53 #include <linux/genhd.h>
54 #include <linux/delay.h>
56 #include <linux/major.h>
57 #include <linux/slab.h>
58 #include <linux/interrupt.h>
59 #include <scsi/scsi.h> /* for SCSI_IOCTL_GET_IDLUN */
60 #include <scsi/scsi_ioctl.h>
61 #include <linux/hdreg.h> /* for HDIO_GETGEO */
62 #include <linux/blkpg.h>
63 #include <linux/buffer_head.h>
64 #include <linux/blkdev.h>
66 #include <asm/setup.h>
67 #include <asm/pgtable.h>
68 #include <asm/system.h>
69 #include <asm/uaccess.h>
70 #include <asm/atarihw.h>
71 #include <asm/atariints.h>
72 #include <asm/atari_acsi.h>
73 #include <asm/atari_stdma.h>
74 #include <asm/atari_stram.h>
76 static void (*do_acsi)(void) = NULL;
77 static struct request_queue *acsi_queue;
78 #define QUEUE (acsi_queue)
79 #define CURRENT elv_next_request(acsi_queue)
85 #define MAX_ERRORS 8 /* Max read/write errors/sector */
86 #define MAX_LUN 8 /* Max LUNs per target */
89 #define ACSI_BUFFER_SIZE (16*1024) /* "normal" ACSI buffer size */
90 #define ACSI_BUFFER_MINSIZE (2048) /* min. buf size if ext. DMA */
91 #define ACSI_BUFFER_SIZE_ORDER 2 /* order size for above */
92 #define ACSI_BUFFER_MINSIZE_ORDER 0 /* order size for above */
93 #define ACSI_BUFFER_SECTORS (ACSI_BUFFER_SIZE/512)
95 #define ACSI_BUFFER_ORDER \
96 (ATARIHW_PRESENT(EXTD_DMA) ? \
97 ACSI_BUFFER_MINSIZE_ORDER : \
98 ACSI_BUFFER_SIZE_ORDER)
100 #define ACSI_TIMEOUT (4*HZ)
102 /* minimum delay between two commands */
104 #define COMMAND_DELAY 500
107 NONE, HARDDISK, CDROM
110 struct acsi_info_struct {
111 ACSI_TYPE type; /* type of device */
112 unsigned target; /* target number */
113 unsigned lun; /* LUN in target controller */
114 unsigned removable : 1; /* Flag for removable media */
115 unsigned read_only : 1; /* Flag for read only devices */
116 unsigned old_atari_disk : 1; /* Is an old Atari disk */
117 unsigned changed : 1; /* Medium has been changed */
118 unsigned long size; /* #blocks */
120 } acsi_info[MAX_DEV];
126 #define NO_SENSE 0x00
127 #define RECOVERED_ERROR 0x01
128 #define NOT_READY 0x02
129 #define MEDIUM_ERROR 0x03
130 #define HARDWARE_ERROR 0x04
131 #define ILLEGAL_REQUEST 0x05
132 #define UNIT_ATTENTION 0x06
133 #define DATA_PROTECT 0x07
134 #define BLANK_CHECK 0x08
135 #define COPY_ABORTED 0x0a
136 #define ABORTED_COMMAND 0x0b
137 #define VOLUME_OVERFLOW 0x0d
138 #define MISCOMPARE 0x0e
145 #define TYPE_DISK 0x00
146 #define TYPE_TAPE 0x01
147 #define TYPE_WORM 0x04
148 #define TYPE_ROM 0x05
149 #define TYPE_MOD 0x07
150 #define TYPE_NO_LUN 0x7f
152 /* The data returned by MODE SENSE differ between the old Atari
153 * hard disks and SCSI disks connected to ACSI. In the following, both
154 * formats are defined and some macros to operate on them potably.
158 unsigned long dummy[2];
159 unsigned long sector_size;
160 unsigned char format_code;
161 #define ATARI_SENSE_FORMAT_FIX 1
162 #define ATARI_SENSE_FORMAT_CHNG 2
163 unsigned char cylinders_h;
164 unsigned char cylinders_l;
166 unsigned char reduced_h;
167 unsigned char reduced_l;
168 unsigned char precomp_h;
169 unsigned char precomp_l;
170 unsigned char landing_zone;
171 unsigned char steprate;
173 #define ATARI_SENSE_TYPE_FIXCHNG_MASK 4
174 #define ATARI_SENSE_TYPE_SOFTHARD_MASK 8
175 #define ATARI_SENSE_TYPE_FIX 4
176 #define ATARI_SENSE_TYPE_CHNG 0
177 #define ATARI_SENSE_TYPE_SOFT 0
178 #define ATARI_SENSE_TYPE_HARD 8
179 unsigned char sectors;
182 #define ATARI_CAPACITY(sd) \
183 (((int)((sd).cylinders_h<<8)|(sd).cylinders_l) * \
184 (sd).heads * (sd).sectors)
188 unsigned char dummy1;
189 unsigned char medium_type;
190 unsigned char dummy2;
191 unsigned char descriptor_size;
192 unsigned long block_count;
193 unsigned long sector_size;
195 unsigned char page_code;
196 unsigned char page_size;
197 unsigned char page_flags;
198 unsigned char qualifier;
201 #define SCSI_CAPACITY(sd) ((sd).block_count & 0xffffff)
205 ATARI_SENSE_DATA atari;
206 SCSI_SENSE_DATA scsi;
209 #define SENSE_TYPE_UNKNOWN 0
210 #define SENSE_TYPE_ATARI 1
211 #define SENSE_TYPE_SCSI 2
213 #define SENSE_TYPE(sd) \
214 (((sd).atari.dummy[0] == 8 && \
215 ((sd).atari.format_code == 1 || \
216 (sd).atari.format_code == 2)) ? SENSE_TYPE_ATARI : \
217 ((sd).scsi.dummy1 >= 11) ? SENSE_TYPE_SCSI : \
220 #define CAPACITY(sd) \
221 (SENSE_TYPE(sd) == SENSE_TYPE_ATARI ? \
222 ATARI_CAPACITY((sd).atari) : \
223 SCSI_CAPACITY((sd).scsi))
225 #define SECTOR_SIZE(sd) \
226 (SENSE_TYPE(sd) == SENSE_TYPE_ATARI ? \
227 (sd).atari.sector_size : \
228 (sd).scsi.sector_size & 0xffffff)
230 /* Default size if capacity cannot be determined (1 GByte) */
231 #define DEFAULT_SIZE 0x1fffff
233 #define CARTRCH_STAT(aip,buf) \
234 (aip->old_atari_disk ? \
235 (((buf)[0] & 0x7f) == 0x28) : \
236 ((((buf)[0] & 0x70) == 0x70) ? \
237 (((buf)[2] & 0x0f) == 0x06) : \
238 (((buf)[0] & 0x0f) == 0x06))) \
240 /* These two are also exported to other drivers that work on the ACSI bus and
241 * need an ST-RAM buffer. */
243 unsigned long phys_acsi_buffer;
247 static int CurrentNReq;
248 static int CurrentNSect;
249 static char *CurrentBuffer;
251 static DEFINE_SPINLOCK(acsi_lock);
254 #define SET_TIMER() mod_timer(&acsi_timer, jiffies + ACSI_TIMEOUT)
255 #define CLEAR_TIMER() del_timer(&acsi_timer)
257 static unsigned long STramMask;
258 #define STRAM_ADDR(a) (((a) & STramMask) == 0)
264 static char tur_cmd[6] = { 0x00, 0, 0, 0, 0, 0 };
265 static char modesense_cmd[6] = { 0x1a, 0, 0, 0, 24, 0 };
266 static char modeselect_cmd[6] = { 0x15, 0, 0, 0, 12, 0 };
267 static char inquiry_cmd[6] = { 0x12, 0, 0, 0,255, 0 };
268 static char reqsense_cmd[6] = { 0x03, 0, 0, 0, 4, 0 };
269 static char read_cmd[6] = { 0x08, 0, 0, 0, 0, 0 };
270 static char write_cmd[6] = { 0x0a, 0, 0, 0, 0, 0 };
271 static char pa_med_rem_cmd[6] = { 0x1e, 0, 0, 0, 0, 0 };
273 #define CMDSET_TARG_LUN(cmd,targ,lun) \
275 cmd[0] = (cmd[0] & ~0xe0) | (targ)<<5; \
276 cmd[1] = (cmd[1] & ~0xe0) | (lun)<<5; \
279 #define CMDSET_BLOCK(cmd,blk) \
281 unsigned long __blk = (blk); \
282 cmd[3] = __blk; __blk >>= 8; \
283 cmd[2] = __blk; __blk >>= 8; \
284 cmd[1] = (cmd[1] & 0xe0) | (__blk & 0x1f); \
287 #define CMDSET_LEN(cmd,len) \
292 /* ACSI errors (from REQUEST SENSE); There are two tables, one for the
293 * old Atari disks and one for SCSI on ACSI disks.
299 } atari_acsi_errors[] = {
300 { 0x00, "No error (??)" },
301 { 0x01, "No index pulses" },
302 { 0x02, "Seek not complete" },
303 { 0x03, "Write fault" },
304 { 0x04, "Drive not ready" },
305 { 0x06, "No Track 00 signal" },
306 { 0x10, "ECC error in ID field" },
307 { 0x11, "Uncorrectable data error" },
308 { 0x12, "ID field address mark not found" },
309 { 0x13, "Data field address mark not found" },
310 { 0x14, "Record not found" },
311 { 0x15, "Seek error" },
312 { 0x18, "Data check in no retry mode" },
313 { 0x19, "ECC error during verify" },
314 { 0x1a, "Access to bad block" },
315 { 0x1c, "Unformatted or bad format" },
316 { 0x20, "Invalid command" },
317 { 0x21, "Invalid block address" },
318 { 0x23, "Volume overflow" },
319 { 0x24, "Invalid argument" },
320 { 0x25, "Invalid drive number" },
321 { 0x26, "Byte zero parity check" },
322 { 0x28, "Cartride changed" },
323 { 0x2c, "Error count overflow" },
324 { 0x30, "Controller selftest failed" }
327 scsi_acsi_errors[] = {
328 { 0x00, "No error (??)" },
329 { 0x01, "Recovered error" },
330 { 0x02, "Drive not ready" },
331 { 0x03, "Uncorrectable medium error" },
332 { 0x04, "Hardware error" },
333 { 0x05, "Illegal request" },
334 { 0x06, "Unit attention (Reset or cartridge changed)" },
335 { 0x07, "Data protection" },
336 { 0x08, "Blank check" },
337 { 0x0b, "Aborted Command" },
338 { 0x0d, "Volume overflow" }
343 /***************************** Prototypes *****************************/
345 static int acsicmd_dma( const char *cmd, char *buffer, int blocks, int
347 static int acsi_reqsense( char *buffer, int targ, int lun);
348 static void acsi_print_error(const unsigned char *errblk, struct acsi_info_struct *aip);
349 static irqreturn_t acsi_interrupt (int irq, void *data);
350 static void unexpected_acsi_interrupt( void );
351 static void bad_rw_intr( void );
352 static void read_intr( void );
353 static void write_intr( void);
354 static void acsi_times_out( unsigned long dummy );
355 static void copy_to_acsibuffer( void );
356 static void copy_from_acsibuffer( void );
357 static void do_end_requests( void );
358 static void do_acsi_request( request_queue_t * );
359 static void redo_acsi_request( void );
360 static int acsi_ioctl( struct inode *inode, struct file *file, unsigned int
361 cmd, unsigned long arg );
362 static int acsi_open( struct inode * inode, struct file * filp );
363 static int acsi_release( struct inode * inode, struct file * file );
364 static void acsi_prevent_removal(struct acsi_info_struct *aip, int flag );
365 static int acsi_change_blk_size( int target, int lun);
366 static int acsi_mode_sense( int target, int lun, SENSE_DATA *sd );
367 static int acsi_revalidate (struct gendisk *disk);
369 /************************* End of Prototypes **************************/
372 DEFINE_TIMER(acsi_timer, acsi_times_out, 0, 0);
375 #ifdef CONFIG_ATARI_SLM
377 extern int attach_slm( int target, int lun );
378 extern int slm_init( void );
384 /***********************************************************************
388 **********************************************************************/
392 * The following two functions wait for _IRQ to become Low or High,
393 * resp., with a timeout. The 'timeout' parameter is in jiffies
395 * If the functions are called with timer interrupts on (int level <
396 * 6), the timeout is based on the 'jiffies' variable to provide exact
397 * timeouts for device probing etc.
398 * If interrupts are disabled, the number of tries is based on the
399 * 'loops_per_jiffy' variable. A rough estimation is sufficient here...
404 __asm__ __volatile__ ( "movew %/sr,%0" : "=dm" (__sr) ); \
408 int acsi_wait_for_IRQ( unsigned timeout )
412 unsigned long maxjif = jiffies + timeout;
413 while (time_before(jiffies, maxjif))
414 if (!(mfp.par_dt_reg & 0x20)) return( 1 );
417 long tries = loops_per_jiffy / 8 * timeout;
418 while( --tries >= 0 )
419 if (!(mfp.par_dt_reg & 0x20)) return( 1 );
421 return( 0 ); /* timeout! */
425 int acsi_wait_for_noIRQ( unsigned timeout )
429 unsigned long maxjif = jiffies + timeout;
430 while (time_before(jiffies, maxjif))
431 if (mfp.par_dt_reg & 0x20) return( 1 );
434 long tries = loops_per_jiffy * timeout / 8;
435 while( tries-- >= 0 )
436 if (mfp.par_dt_reg & 0x20) return( 1 );
438 return( 0 ); /* timeout! */
441 static struct timeval start_time;
444 acsi_delay_start(void)
446 do_gettimeofday(&start_time);
449 /* wait from acsi_delay_start to now usec (<1E6) usec */
452 acsi_delay_end(long usec)
454 struct timeval end_time;
456 do_gettimeofday(&end_time);
457 deltau=end_time.tv_usec - start_time.tv_usec;
458 deltas=end_time.tv_sec - start_time.tv_sec;
459 if (deltas > 1 || deltas < 0)
468 /* acsicmd_dma() sends an ACSI command and sets up the DMA to transfer
469 * 'blocks' blocks of 512 bytes from/to 'buffer'.
470 * Because the _IRQ signal is used for handshaking the command bytes,
471 * the ACSI interrupt has to be disabled in this function. If the end
472 * of the operation should be signalled by a real interrupt, it has to be
473 * reenabled afterwards.
476 static int acsicmd_dma( const char *cmd, char *buffer, int blocks, int rwflag, int enable)
478 { unsigned long flags, paddr;
482 if (rwflag || *cmd == 0x0a) {
483 printk( "ACSI: Write commands disabled!\n" );
488 rwflag = rwflag ? 0x100 : 0;
489 paddr = virt_to_phys( buffer );
491 acsi_delay_end(COMMAND_DELAY);
494 local_irq_save(flags);
496 dma_wd.dma_mode_status = 0x88 | rwflag;
499 /* set DMA address */
500 dma_wd.dma_lo = (unsigned char)paddr;
503 dma_wd.dma_md = (unsigned char)paddr;
506 if (ATARIHW_PRESENT(EXTD_DMA))
507 st_dma_ext_dmahi = (unsigned short)paddr;
509 dma_wd.dma_hi = (unsigned char)paddr;
511 local_irq_restore(flags);
513 /* send the command bytes except the last */
514 for( i = 0; i < 5; ++i ) {
515 DMA_LONG_WRITE( *cmd++, 0x8a | rwflag );
517 if (!acsi_wait_for_IRQ( HZ/2 )) return( 0 ); /* timeout */
520 /* Clear FIFO and switch DMA to correct direction */
521 dma_wd.dma_mode_status = 0x92 | (rwflag ^ 0x100);
523 dma_wd.dma_mode_status = 0x92 | rwflag;
526 /* How many sectors for DMA */
527 dma_wd.fdc_acces_seccount = blocks;
530 /* send last command byte */
531 dma_wd.dma_mode_status = 0x8a | rwflag;
533 DMA_LONG_WRITE( *cmd++, 0x0a | rwflag );
543 * acsicmd_nodma() sends an ACSI command that requires no DMA.
546 int acsicmd_nodma( const char *cmd, int enable)
550 acsi_delay_end(COMMAND_DELAY);
553 /* send first command byte */
554 dma_wd.dma_mode_status = 0x88;
556 DMA_LONG_WRITE( *cmd++, 0x8a );
558 if (!acsi_wait_for_IRQ( HZ/2 )) return( 0 ); /* timeout */
560 /* send the intermediate command bytes */
561 for( i = 0; i < 4; ++i ) {
562 DMA_LONG_WRITE( *cmd++, 0x8a );
564 if (!acsi_wait_for_IRQ( HZ/2 )) return( 0 ); /* timeout */
567 /* send last command byte */
568 DMA_LONG_WRITE( *cmd++, 0x0a );
574 /* Note that the ACSI interrupt is still disabled after this
575 * function. If you want to get the IRQ delivered, enable it manually!
580 static int acsi_reqsense( char *buffer, int targ, int lun)
583 CMDSET_TARG_LUN( reqsense_cmd, targ, lun);
584 if (!acsicmd_dma( reqsense_cmd, buffer, 1, 0, 0 )) return( 0 );
585 if (!acsi_wait_for_IRQ( 10 )) return( 0 );
587 if (!acsicmd_nodma( reqsense_cmd, 0 )) return( 0 );
588 if (!acsi_wait_for_IRQ( 10 )) return( 0 );
590 if (!acsicmd_nodma( reqsense_cmd, 0 )) return( 0 );
591 if (!acsi_wait_for_IRQ( 10 )) return( 0 );
593 if (!acsicmd_nodma( reqsense_cmd, 0 )) return( 0 );
594 if (!acsi_wait_for_IRQ( 10 )) return( 0 );
596 dma_cache_maintenance( virt_to_phys(buffer), 16, 0 );
603 * ACSI status phase: get the status byte from the bus
605 * I've seen several times that a 0xff status is read, propably due to
606 * a timing error. In this case, the procedure is repeated after the
610 int acsi_getstatus( void )
616 if (!acsi_wait_for_IRQ( 100 )) {
620 dma_wd.dma_mode_status = 0x8a;
622 status = dma_wd.fdc_acces_seccount;
623 if (status != 0xff) break;
625 printk("ACSI: skipping 0xff status byte\n" );
628 acsi_wait_for_noIRQ( 20 );
630 dma_wd.dma_mode_status = 0x80;
632 acsi_wait_for_noIRQ( 20 );
635 return( status & 0x1f ); /* mask of the device# */
639 #if (defined(CONFIG_ATARI_SLM) || defined(CONFIG_ATARI_SLM_MODULE))
641 /* Receive data in an extended status phase. Needed by SLM printer. */
643 int acsi_extstatus( char *buffer, int cnt )
650 if (!acsi_wait_for_IRQ( 40 )) return( 0 );
651 dma_wd.dma_mode_status = 0x8a;
653 status = dma_wd.fdc_acces_seccount;
655 *buffer++ = status & 0xff;
662 /* Finish an extended status phase */
664 void acsi_end_extstatus( void )
667 dma_wd.dma_mode_status = 0x80;
669 acsi_wait_for_noIRQ( 20 );
674 /* Send data in an extended command phase */
676 int acsi_extcmd( unsigned char *buffer, int cnt )
680 DMA_LONG_WRITE( *buffer++, 0x8a );
682 if (!acsi_wait_for_IRQ( HZ/2 )) return( 0 ); /* timeout */
690 static void acsi_print_error(const unsigned char *errblk, struct acsi_info_struct *aip)
692 { int atari_err, i, errcode;
693 struct acsi_error *arr;
695 atari_err = aip->old_atari_disk;
697 errcode = errblk[0] & 0x7f;
699 if ((errblk[0] & 0x70) == 0x70)
700 errcode = errblk[2] & 0x0f;
702 errcode = errblk[0] & 0x0f;
704 printk( KERN_ERR "ACSI error 0x%02x", errcode );
706 if (errblk[0] & 0x80)
707 printk( " for sector %d",
708 ((errblk[1] & 0x1f) << 16) |
709 (errblk[2] << 8) | errblk[0] );
711 arr = atari_err ? atari_acsi_errors : scsi_acsi_errors;
712 i = atari_err ? sizeof(atari_acsi_errors)/sizeof(*atari_acsi_errors) :
713 sizeof(scsi_acsi_errors)/sizeof(*scsi_acsi_errors);
715 for( --i; i >= 0; --i )
716 if (arr[i].code == errcode) break;
718 printk( ": %s\n", arr[i].text );
721 /*******************************************************************
723 * ACSI interrupt routine
724 * Test, if this is a ACSI interrupt and call the irq handler
725 * Otherwise ignore this interrupt.
727 *******************************************************************/
729 static irqreturn_t acsi_interrupt(int irq, void *data )
731 { void (*acsi_irq_handler)(void) = do_acsi;
736 if (!acsi_irq_handler)
737 acsi_irq_handler = unexpected_acsi_interrupt;
743 /******************************************************************
745 * The Interrupt handlers
747 *******************************************************************/
750 static void unexpected_acsi_interrupt( void )
753 printk( KERN_WARNING "Unexpected ACSI interrupt\n" );
757 /* This function is called in case of errors. Because we cannot reset
758 * the ACSI bus or a single device, there is no other choice than
759 * retrying several times :-(
762 static void bad_rw_intr( void )
768 if (++CURRENT->errors >= MAX_ERRORS)
769 end_request(CURRENT, 0);
770 /* Otherwise just retry */
774 static void read_intr( void )
778 status = acsi_getstatus();
780 struct gendisk *disk = CURRENT->rq_disk;
781 struct acsi_info_struct *aip = disk->private_data;
782 printk(KERN_ERR "%s: ", disk->disk_name);
783 if (!acsi_reqsense(acsi_buffer, aip->target, aip->lun))
784 printk( "ACSI error and REQUEST SENSE failed (status=0x%02x)\n", status );
786 acsi_print_error(acsi_buffer, aip);
787 if (CARTRCH_STAT(aip, acsi_buffer))
796 dma_cache_maintenance( virt_to_phys(CurrentBuffer), CurrentNSect*512, 0 );
797 if (CurrentBuffer == acsi_buffer)
798 copy_from_acsibuffer();
805 static void write_intr(void)
809 status = acsi_getstatus();
811 struct gendisk *disk = CURRENT->rq_disk;
812 struct acsi_info_struct *aip = disk->private_data;
813 printk( KERN_ERR "%s: ", disk->disk_name);
814 if (!acsi_reqsense( acsi_buffer, aip->target, aip->lun))
815 printk( "ACSI error and REQUEST SENSE failed (status=0x%02x)\n", status );
817 acsi_print_error(acsi_buffer, aip);
818 if (CARTRCH_STAT(aip, acsi_buffer))
831 static void acsi_times_out( unsigned long dummy )
835 if (!do_acsi) return;
838 printk( KERN_ERR "ACSI timeout\n" );
841 if (++CURRENT->errors >= MAX_ERRORS) {
843 printk( KERN_ERR "ACSI: too many errors.\n" );
845 end_request(CURRENT, 0);
853 /***********************************************************************
855 * Scatter-gather utility functions
857 ***********************************************************************/
860 static void copy_to_acsibuffer( void )
864 struct buffer_head *bh;
866 src = CURRENT->buffer;
871 memcpy( dst, src, CurrentNSect*512 );
873 for( i = 0; i < CurrentNReq; ++i ) {
874 memcpy( dst, src, bh->b_size );
876 if ((bh = bh->b_reqnext))
882 static void copy_from_acsibuffer( void )
886 struct buffer_head *bh;
888 dst = CURRENT->buffer;
893 memcpy( dst, src, CurrentNSect*512 );
895 for( i = 0; i < CurrentNReq; ++i ) {
896 memcpy( dst, src, bh->b_size );
898 if ((bh = bh->b_reqnext))
904 static void do_end_requests( void )
909 CURRENT->nr_sectors -= CurrentNSect;
910 CURRENT->current_nr_sectors -= CurrentNSect;
911 CURRENT->sector += CurrentNSect;
912 if (CURRENT->nr_sectors == 0)
913 end_request(CURRENT, 1);
916 for( i = 0; i < CurrentNReq; ++i ) {
917 n = CURRENT->bh->b_size >> 9;
918 CURRENT->nr_sectors -= n;
919 CURRENT->current_nr_sectors -= n;
920 CURRENT->sector += n;
921 end_request(CURRENT, 1);
929 /***********************************************************************
931 * do_acsi_request and friends
933 ***********************************************************************/
935 static void do_acsi_request( request_queue_t * q )
938 stdma_lock( acsi_interrupt, NULL );
943 static void redo_acsi_request( void )
945 unsigned block, target, lun, nsect;
947 unsigned long pbuffer;
948 struct buffer_head *bh;
949 struct gendisk *disk;
950 struct acsi_info_struct *aip;
965 disk = CURRENT->rq_disk;
966 aip = disk->private_data;
968 if (!CURRENT->bh && !buffer_locked(CURRENT->bh))
969 panic("ACSI: block not locked");
972 block = CURRENT->sector;
973 if (block+CURRENT->nr_sectors >= get_capacity(disk)) {
975 printk( "%s: attempted access for blocks %d...%ld past end of device at block %ld.\n",
977 block, block + CURRENT->nr_sectors - 1,
980 end_request(CURRENT, 0);
984 printk( KERN_NOTICE "%s: request denied because cartridge has "
985 "been changed.\n", disk->disk_name);
986 end_request(CURRENT, 0);
990 target = aip->target;
993 /* Find out how many sectors should be transferred from/to
994 * consecutive buffers and thus can be done with a single command.
996 buffer = CURRENT->buffer;
997 pbuffer = virt_to_phys(buffer);
998 nsect = CURRENT->current_nr_sectors;
1001 if ((bh = CURRENT->bh) && bh != CURRENT->bhtail) {
1002 if (!STRAM_ADDR(pbuffer)) {
1003 /* If transfer is done via the ACSI buffer anyway, we can
1004 * assemble as much bh's as fit in the buffer.
1006 while( (bh = bh->b_reqnext) ) {
1007 if (nsect + (bh->b_size>>9) > ACSI_BUFFER_SECTORS) break;
1008 nsect += bh->b_size >> 9;
1010 if (bh == CURRENT->bhtail) break;
1012 buffer = acsi_buffer;
1013 pbuffer = phys_acsi_buffer;
1016 unsigned long pendadr, pnewadr;
1017 pendadr = pbuffer + nsect*512;
1018 while( (bh = bh->b_reqnext) ) {
1019 pnewadr = virt_to_phys(bh->b_data);
1020 if (!STRAM_ADDR(pnewadr) || pendadr != pnewadr) break;
1021 nsect += bh->b_size >> 9;
1022 pendadr = pnewadr + bh->b_size;
1024 if (bh == CURRENT->bhtail) break;
1029 if (!STRAM_ADDR(pbuffer)) {
1030 buffer = acsi_buffer;
1031 pbuffer = phys_acsi_buffer;
1032 if (nsect > ACSI_BUFFER_SECTORS)
1033 nsect = ACSI_BUFFER_SECTORS;
1036 CurrentBuffer = buffer;
1037 CurrentNSect = nsect;
1039 if (rq_data_dir(CURRENT) == WRITE) {
1040 CMDSET_TARG_LUN( write_cmd, target, lun );
1041 CMDSET_BLOCK( write_cmd, block );
1042 CMDSET_LEN( write_cmd, nsect );
1043 if (buffer == acsi_buffer)
1044 copy_to_acsibuffer();
1045 dma_cache_maintenance( pbuffer, nsect*512, 1 );
1046 do_acsi = write_intr;
1047 if (!acsicmd_dma( write_cmd, buffer, nsect, 1, 1)) {
1049 printk( KERN_ERR "ACSI (write): Timeout in command block\n" );
1056 if (rq_data_dir(CURRENT) == READ) {
1057 CMDSET_TARG_LUN( read_cmd, target, lun );
1058 CMDSET_BLOCK( read_cmd, block );
1059 CMDSET_LEN( read_cmd, nsect );
1060 do_acsi = read_intr;
1061 if (!acsicmd_dma( read_cmd, buffer, nsect, 0, 1)) {
1063 printk( KERN_ERR "ACSI (read): Timeout in command block\n" );
1070 panic("unknown ACSI command");
1075 /***********************************************************************
1077 * Misc functions: ioctl, open, release, check_change, ...
1079 ***********************************************************************/
1081 static int acsi_getgeo(struct block_device *bdev, struct hd_geometry *geo)
1083 struct acsi_info_struct *aip = bdev->bd_disk->private_data;
1086 * Just fake some geometry here, it's nonsense anyway
1087 * To make it easy, use Adaptec's usual 64/32 mapping
1091 geo->cylinders = aip->size >> 11;
1095 static int acsi_ioctl( struct inode *inode, struct file *file,
1096 unsigned int cmd, unsigned long arg )
1098 struct gendisk *disk = inode->i_bdev->bd_disk;
1099 struct acsi_info_struct *aip = disk->private_data;
1101 case SCSI_IOCTL_GET_IDLUN:
1102 /* SCSI compatible GET_IDLUN call to get target's ID and LUN number */
1103 put_user( aip->target | (aip->lun << 8),
1104 &((Scsi_Idlun *) arg)->dev_id );
1105 put_user( 0, &((Scsi_Idlun *) arg)->host_unique_id );
1114 * Open a device, check for read-only and lock the medium if it is
1117 * Changes by Martin Rogge, 9th Aug 1995:
1118 * Check whether check_disk_change (and therefore revalidate_acsidisk)
1119 * was successful. They fail when there is no medium in the drive.
1121 * The problem of media being changed during an operation can be
1122 * ignored because of the prevent_removal code.
1124 * Added check for the validity of the device number.
1128 static int acsi_open( struct inode * inode, struct file * filp )
1130 struct gendisk *disk = inode->i_bdev->bd_disk;
1131 struct acsi_info_struct *aip = disk->private_data;
1133 if (aip->access_count == 0 && aip->removable) {
1135 aip->changed = 1; /* safety first */
1137 check_disk_change( inode->i_bdev );
1138 if (aip->changed) /* revalidate was not successful (no medium) */
1140 acsi_prevent_removal(aip, 1);
1142 aip->access_count++;
1144 if (filp && filp->f_mode) {
1145 check_disk_change( inode->i_bdev );
1146 if (filp->f_mode & 2) {
1147 if (aip->read_only) {
1148 acsi_release( inode, filp );
1158 * Releasing a block device means we sync() it, so that it can safely
1159 * be forgotten about...
1162 static int acsi_release( struct inode * inode, struct file * file )
1164 struct gendisk *disk = inode->i_bdev->bd_disk;
1165 struct acsi_info_struct *aip = disk->private_data;
1166 if (--aip->access_count == 0 && aip->removable)
1167 acsi_prevent_removal(aip, 0);
1172 * Prevent or allow a media change for removable devices.
1175 static void acsi_prevent_removal(struct acsi_info_struct *aip, int flag)
1177 stdma_lock( NULL, NULL );
1179 CMDSET_TARG_LUN(pa_med_rem_cmd, aip->target, aip->lun);
1180 CMDSET_LEN( pa_med_rem_cmd, flag );
1182 if (acsicmd_nodma(pa_med_rem_cmd, 0) && acsi_wait_for_IRQ(3*HZ))
1184 /* Do not report errors -- some devices may not know this command. */
1190 static int acsi_media_change(struct gendisk *disk)
1192 struct acsi_info_struct *aip = disk->private_data;
1194 if (!aip->removable)
1198 /* We can be sure that the medium has been changed -- REQUEST
1199 * SENSE has reported this earlier.
1203 /* If the flag isn't set, make a test by reading block 0.
1204 * If errors happen, it seems to be better to say "changed"...
1206 stdma_lock( NULL, NULL );
1207 CMDSET_TARG_LUN(read_cmd, aip->target, aip->lun);
1208 CMDSET_BLOCK( read_cmd, 0 );
1209 CMDSET_LEN( read_cmd, 1 );
1210 if (acsicmd_dma(read_cmd, acsi_buffer, 1, 0, 0) &&
1211 acsi_wait_for_IRQ(3*HZ)) {
1212 if (acsi_getstatus()) {
1213 if (acsi_reqsense(acsi_buffer, aip->target, aip->lun)) {
1214 if (CARTRCH_STAT(aip, acsi_buffer))
1218 printk( KERN_ERR "%s: REQUEST SENSE failed in test for "
1219 "medium change; assuming a change\n", disk->disk_name );
1225 printk( KERN_ERR "%s: Test for medium changed timed out; "
1226 "assuming a change\n", disk->disk_name);
1232 /* Now, after reading a block, the changed status is surely valid. */
1233 return aip->changed;
1237 static int acsi_change_blk_size( int target, int lun)
1241 for (i=0; i<12; i++)
1245 acsi_buffer[10] = 2;
1246 CMDSET_TARG_LUN( modeselect_cmd, target, lun);
1248 if (!acsicmd_dma( modeselect_cmd, acsi_buffer, 1,1,0) ||
1249 !acsi_wait_for_IRQ( 3*HZ ) ||
1250 acsi_getstatus() != 0 ) {
1257 static int acsi_mode_sense( int target, int lun, SENSE_DATA *sd )
1262 CMDSET_TARG_LUN( modesense_cmd, target, lun );
1263 for (page=0; page<4; page++) {
1264 modesense_cmd[2] = page;
1265 if (!acsicmd_dma( modesense_cmd, acsi_buffer, 1, 0, 0 ) ||
1266 !acsi_wait_for_IRQ( 3*HZ ) ||
1270 /* read twice to jump over the second 16-byte border! */
1272 if (acsi_wait_for_noIRQ( 20 ) &&
1273 acsicmd_nodma( modesense_cmd, 0 ) &&
1274 acsi_wait_for_IRQ( 3*HZ ) &&
1275 acsi_getstatus() == 0)
1282 dma_cache_maintenance( phys_acsi_buffer, sizeof(SENSE_DATA), 0 );
1283 *sd = *(SENSE_DATA *)acsi_buffer;
1285 /* Validity check, depending on type of data */
1287 switch( SENSE_TYPE(*sd) ) {
1289 case SENSE_TYPE_ATARI:
1290 if (CAPACITY(*sd) == 0)
1294 case SENSE_TYPE_SCSI:
1295 if (sd->scsi.descriptor_size != 8)
1299 case SENSE_TYPE_UNKNOWN:
1301 printk( KERN_ERR "ACSI target %d, lun %d: Cannot interpret "
1302 "sense data\n", target, lun );
1308 printk( "Mode sense data for ACSI target %d, lun %d seem not valid:",
1310 for( i = 0; i < sizeof(SENSE_DATA); ++i )
1311 printk( "%02x ", (unsigned char)acsi_buffer[i] );
1323 /*******************************************************************
1327 ********************************************************************/
1330 extern struct block_device_operations acsi_fops;
1332 static struct gendisk *acsi_gendisk[MAX_DEV];
1334 #define MAX_SCSI_DEVICE_CODE 10
1336 static const char *const scsi_device_types[MAX_SCSI_DEVICE_CODE] =
1339 "Sequential-Access",
1350 static void print_inquiry(unsigned char *data)
1354 printk(KERN_INFO " Vendor: ");
1355 for (i = 8; i < 16; i++)
1357 if (data[i] >= 0x20 && i < data[4] + 5)
1358 printk("%c", data[i]);
1364 for (i = 16; i < 32; i++)
1366 if (data[i] >= 0x20 && i < data[4] + 5)
1367 printk("%c", data[i]);
1373 for (i = 32; i < 36; i++)
1375 if (data[i] >= 0x20 && i < data[4] + 5)
1376 printk("%c", data[i]);
1385 printk(KERN_INFO " Type: %s ", (i < MAX_SCSI_DEVICE_CODE
1386 ? scsi_device_types[i]
1388 printk(" ANSI SCSI revision: %02x", data[2] & 0x07);
1389 if ((data[2] & 0x07) == 1 && (data[3] & 0x0f) == 1)
1397 * Changes by Martin Rogge, 9th Aug 1995:
1398 * acsi_devinit has been taken out of acsi_geninit, because it needs
1399 * to be called from revalidate_acsidisk. The result of request sense
1400 * is now checked for DRIVE NOT READY.
1402 * The structure *aip is only valid when acsi_devinit returns
1408 #define DEV_UNKNOWN 1
1409 #define DEV_SUPPORTED 2
1412 static int acsi_devinit(struct acsi_info_struct *aip)
1414 int status, got_inquiry;
1416 unsigned char reqsense, extsense;
1418 /*****************************************************************/
1419 /* Do a TEST UNIT READY command to test the presence of a device */
1420 /*****************************************************************/
1422 CMDSET_TARG_LUN(tur_cmd, aip->target, aip->lun);
1423 if (!acsicmd_nodma(tur_cmd, 0)) {
1424 /* timed out -> no device here */
1426 printk("target %d lun %d: timeout\n", aip->target, aip->lun);
1431 /*************************/
1432 /* Read the ACSI status. */
1433 /*************************/
1435 status = acsi_getstatus();
1437 if (status == 0x12) {
1438 /* The SLM printer should be the only device that
1439 * responds with the error code in the status byte. In
1440 * correct status bytes, bit 4 is never set.
1442 printk( KERN_INFO "Detected SLM printer at id %d lun %d\n",
1443 aip->target, aip->lun);
1446 /* ignore CHECK CONDITION, since some devices send a
1448 if ((status & 0x1e) != 0x2) {
1450 printk("target %d lun %d: status %d\n",
1451 aip->target, aip->lun, status);
1457 /*******************************/
1458 /* Do a REQUEST SENSE command. */
1459 /*******************************/
1461 if (!acsi_reqsense(acsi_buffer, aip->target, aip->lun)) {
1462 printk( KERN_WARNING "acsi_reqsense failed\n");
1464 acsi_buffer[2] = UNIT_ATTENTION;
1466 reqsense = acsi_buffer[0];
1467 extsense = acsi_buffer[2] & 0xf;
1469 if ((reqsense & 0x70) == 0x70) { /* extended sense */
1470 if (extsense != UNIT_ATTENTION &&
1471 extsense != NOT_READY) {
1473 printk("target %d lun %d: extended sense %d\n",
1474 aip->target, aip->lun, extsense);
1480 if (reqsense & 0x7f) {
1482 printk("target %d lun %d: sense %d\n",
1483 aip->target, aip->lun, reqsense);
1490 if (reqsense == 0x4) { /* SH204 Bug workaround */
1492 printk("target %d lun %d status=0 sense=4\n",
1493 aip->target, aip->lun);
1498 /***********************************************************/
1499 /* Do an INQUIRY command to get more infos on this device. */
1500 /***********************************************************/
1502 /* Assume default values */
1505 aip->old_atari_disk = 0;
1506 aip->changed = (extsense == NOT_READY); /* medium inserted? */
1507 aip->size = DEFAULT_SIZE;
1509 /* Fake inquiry result for old atari disks */
1510 memcpy(acsi_buffer, "\000\000\001\000 Adaptec 40xx"
1512 CMDSET_TARG_LUN(inquiry_cmd, aip->target, aip->lun);
1513 if (acsicmd_dma(inquiry_cmd, acsi_buffer, 1, 0, 0) &&
1514 acsi_getstatus() == 0) {
1515 acsicmd_nodma(inquiry_cmd, 0);
1517 dma_cache_maintenance( phys_acsi_buffer, 256, 0 );
1519 aip->removable = !!(acsi_buffer[1] & 0x80);
1521 if (aip->type == NONE) /* only at boot time */
1522 print_inquiry(acsi_buffer);
1523 switch(acsi_buffer[0]) {
1525 aip->type = HARDDISK;
1534 /****************************/
1535 /* Do a MODE SENSE command. */
1536 /****************************/
1538 if (!acsi_mode_sense(aip->target, aip->lun, &sense)) {
1539 printk( KERN_WARNING "No mode sense data.\n" );
1542 if ((SECTOR_SIZE(sense) != 512) &&
1543 ((aip->type != CDROM) ||
1544 !acsi_change_blk_size(aip->target, aip->lun) ||
1545 !acsi_mode_sense(aip->target, aip->lun, &sense) ||
1546 (SECTOR_SIZE(sense) != 512))) {
1547 printk( KERN_WARNING "Sector size != 512 not supported.\n" );
1550 /* There are disks out there that claim to have 0 sectors... */
1551 if (CAPACITY(sense))
1552 aip->size = CAPACITY(sense); /* else keep DEFAULT_SIZE */
1553 if (!got_inquiry && SENSE_TYPE(sense) == SENSE_TYPE_ATARI) {
1554 /* If INQUIRY failed and the sense data suggest an old
1555 * Atari disk (SH20x, Megafile), the disk is not removable
1558 aip->old_atari_disk = 1;
1561 /******************/
1562 /* We've done it. */
1563 /******************/
1565 return DEV_SUPPORTED;
1568 EXPORT_SYMBOL(acsi_delay_start);
1569 EXPORT_SYMBOL(acsi_delay_end);
1570 EXPORT_SYMBOL(acsi_wait_for_IRQ);
1571 EXPORT_SYMBOL(acsi_wait_for_noIRQ);
1572 EXPORT_SYMBOL(acsicmd_nodma);
1573 EXPORT_SYMBOL(acsi_getstatus);
1574 EXPORT_SYMBOL(acsi_buffer);
1575 EXPORT_SYMBOL(phys_acsi_buffer);
1577 #ifdef CONFIG_ATARI_SLM_MODULE
1578 void acsi_attach_SLMs( int (*attach_func)( int, int ) );
1580 EXPORT_SYMBOL(acsi_extstatus);
1581 EXPORT_SYMBOL(acsi_end_extstatus);
1582 EXPORT_SYMBOL(acsi_extcmd);
1583 EXPORT_SYMBOL(acsi_attach_SLMs);
1585 /* to remember IDs of SLM devices, SLM module is loaded later
1586 * (index is target#, contents is lun#, -1 means "no SLM") */
1590 static struct block_device_operations acsi_fops = {
1591 .owner = THIS_MODULE,
1593 .release = acsi_release,
1594 .ioctl = acsi_ioctl,
1595 .getgeo = acsi_getgeo,
1596 .media_changed = acsi_media_change,
1597 .revalidate_disk= acsi_revalidate,
1600 #ifdef CONFIG_ATARI_SLM_MODULE
1601 /* call attach_slm() for each device that is a printer; needed for init of SLM
1602 * driver as a module, since it's not yet present if acsi.c is inited and thus
1603 * the bus gets scanned. */
1604 void acsi_attach_SLMs( int (*attach_func)( int, int ) )
1608 for( i = 0; i < 8; ++i )
1609 if (SLM_devices[i] >= 0)
1610 n += (*attach_func)( i, SLM_devices[i] );
1611 printk( KERN_INFO "Found %d SLM printer(s) total.\n", n );
1613 #endif /* CONFIG_ATARI_SLM_MODULE */
1616 int acsi_init( void )
1620 struct acsi_info_struct *aip;
1621 #ifdef CONFIG_ATARI_SLM
1624 if (!MACH_IS_ATARI || !ATARIHW_PRESENT(ACSI))
1626 if (register_blkdev(ACSI_MAJOR, "ad")) {
1631 (char *)atari_stram_alloc(ACSI_BUFFER_SIZE, "acsi"))) {
1633 printk( KERN_ERR "Unable to get ACSI ST-Ram buffer.\n" );
1636 phys_acsi_buffer = virt_to_phys( acsi_buffer );
1637 STramMask = ATARIHW_PRESENT(EXTD_DMA) ? 0x00000000 : 0xff000000;
1639 acsi_queue = blk_init_queue(do_acsi_request, &acsi_lock);
1644 #ifdef CONFIG_ATARI_SLM
1650 printk( KERN_INFO "Probing ACSI devices:\n" );
1652 #ifdef CONFIG_ATARI_SLM_MODULE
1653 for( i = 0; i < 8; ++i )
1654 SLM_devices[i] = -1;
1656 stdma_lock(NULL, NULL);
1658 for (target = 0; target < 8 && NDevices < MAX_DEV; ++target) {
1661 aip = &acsi_info[NDevices];
1663 aip->target = target;
1665 i = acsi_devinit(aip);
1668 printk( KERN_INFO "Detected ");
1669 switch (aip->type) {
1678 printk(" ad%c at id %d lun %d ",
1679 'a' + NDevices, target, lun);
1681 printk("(removable) ");
1683 printk("(read-only) ");
1684 if (aip->size == DEFAULT_SIZE)
1685 printk(" unkown size, using default ");
1686 printk("%ld MByte\n",
1687 (aip->size*512+1024*1024/2)/(1024*1024));
1691 #ifdef CONFIG_ATARI_SLM
1692 n_slm += attach_slm( target, lun );
1695 #ifdef CONFIG_ATARI_SLM_MODULE
1696 SLM_devices[target] = lun;
1699 /* neither of the above: fall through to unknown device */
1701 printk( KERN_INFO "Detected unsupported device at "
1702 "id %d lun %d\n", target, lun);
1706 #ifdef CONFIG_ACSI_MULTI_LUN
1707 while (i != DEV_NONE && ++lun < MAX_LUN);
1713 /* reenable interrupt */
1717 #ifndef CONFIG_ATARI_SLM
1718 printk( KERN_INFO "Found %d ACSI device(s) total.\n", NDevices );
1720 printk( KERN_INFO "Found %d ACSI device(s) and %d SLM printer(s) total.\n",
1724 for( i = 0; i < NDevices; ++i ) {
1725 acsi_gendisk[i] = alloc_disk(16);
1726 if (!acsi_gendisk[i])
1730 for( i = 0; i < NDevices; ++i ) {
1731 struct gendisk *disk = acsi_gendisk[i];
1732 sprintf(disk->disk_name, "ad%c", 'a'+i);
1733 aip = &acsi_info[NDevices];
1734 disk->major = ACSI_MAJOR;
1735 disk->first_minor = i << 4;
1736 if (acsi_info[i].type != HARDDISK)
1738 disk->fops = &acsi_fops;
1739 disk->private_data = &acsi_info[i];
1740 set_capacity(disk, acsi_info[i].size);
1741 disk->queue = acsi_queue;
1747 put_disk(acsi_gendisk[i]);
1749 blk_cleanup_queue(acsi_queue);
1751 atari_stram_free( acsi_buffer );
1753 unregister_blkdev( ACSI_MAJOR, "ad" );
1761 MODULE_LICENSE("GPL");
1763 int init_module(void)
1767 if ((err = acsi_init()))
1769 printk( KERN_INFO "ACSI driver loaded as module.\n");
1773 void cleanup_module(void)
1776 del_timer( &acsi_timer );
1777 blk_cleanup_queue(acsi_queue);
1778 atari_stram_free( acsi_buffer );
1780 if (unregister_blkdev( ACSI_MAJOR, "ad" ) != 0)
1781 printk( KERN_ERR "acsi: cleanup_module failed\n");
1783 for (i = 0; i < NDevices; i++) {
1784 del_gendisk(acsi_gendisk[i]);
1785 put_disk(acsi_gendisk[i]);
1791 * This routine is called to flush all partitions and partition tables
1792 * for a changed scsi disk, and then re-read the new partition table.
1793 * If we are revalidating a disk because of a media change, then we
1794 * enter with usage == 0. If we are using an ioctl, we automatically have
1795 * usage == 1 (we need an open channel to use an ioctl :-), so this
1798 * Changes by Martin Rogge, 9th Aug 1995:
1799 * got cd-roms to work by calling acsi_devinit. There are only two problems:
1800 * First, if there is no medium inserted, the status will remain "changed".
1801 * That is no problem at all, but our design of three-valued logic (medium
1802 * changed, medium not changed, no medium inserted).
1803 * Secondly the check could fail completely and the drive could deliver
1804 * nonsensical data, which could mess up the acsi_info[] structure. In
1805 * that case we try to make the entry safe.
1809 static int acsi_revalidate(struct gendisk *disk)
1811 struct acsi_info_struct *aip = disk->private_data;
1812 stdma_lock( NULL, NULL );
1813 if (acsi_devinit(aip) != DEV_SUPPORTED) {
1814 printk( KERN_ERR "ACSI: revalidate failed for target %d lun %d\n",
1815 aip->target, aip->lun);
1819 aip->changed = 1; /* next acsi_open will try again... */
1824 set_capacity(disk, aip->size);