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 typedef void Scsi_Device; /* hack to avoid including scsi.h */
62 #include <scsi/scsi_ioctl.h>
63 #include <linux/hdreg.h> /* for HDIO_GETGEO */
64 #include <linux/blkpg.h>
65 #include <linux/buffer_head.h>
66 #include <linux/blkdev.h>
68 #include <asm/setup.h>
69 #include <asm/pgtable.h>
70 #include <asm/system.h>
71 #include <asm/uaccess.h>
72 #include <asm/atarihw.h>
73 #include <asm/atariints.h>
74 #include <asm/atari_acsi.h>
75 #include <asm/atari_stdma.h>
76 #include <asm/atari_stram.h>
78 static void (*do_acsi)(void) = NULL;
79 static struct request_queue *acsi_queue;
80 #define QUEUE (acsi_queue)
81 #define CURRENT elv_next_request(acsi_queue)
87 #define MAX_ERRORS 8 /* Max read/write errors/sector */
88 #define MAX_LUN 8 /* Max LUNs per target */
91 #define ACSI_BUFFER_SIZE (16*1024) /* "normal" ACSI buffer size */
92 #define ACSI_BUFFER_MINSIZE (2048) /* min. buf size if ext. DMA */
93 #define ACSI_BUFFER_SIZE_ORDER 2 /* order size for above */
94 #define ACSI_BUFFER_MINSIZE_ORDER 0 /* order size for above */
95 #define ACSI_BUFFER_SECTORS (ACSI_BUFFER_SIZE/512)
97 #define ACSI_BUFFER_ORDER \
98 (ATARIHW_PRESENT(EXTD_DMA) ? \
99 ACSI_BUFFER_MINSIZE_ORDER : \
100 ACSI_BUFFER_SIZE_ORDER)
102 #define ACSI_TIMEOUT (4*HZ)
104 /* minimum delay between two commands */
106 #define COMMAND_DELAY 500
109 NONE, HARDDISK, CDROM
112 struct acsi_info_struct {
113 ACSI_TYPE type; /* type of device */
114 unsigned target; /* target number */
115 unsigned lun; /* LUN in target controller */
116 unsigned removable : 1; /* Flag for removable media */
117 unsigned read_only : 1; /* Flag for read only devices */
118 unsigned old_atari_disk : 1; /* Is an old Atari disk */
119 unsigned changed : 1; /* Medium has been changed */
120 unsigned long size; /* #blocks */
122 } acsi_info[MAX_DEV];
128 #define NO_SENSE 0x00
129 #define RECOVERED_ERROR 0x01
130 #define NOT_READY 0x02
131 #define MEDIUM_ERROR 0x03
132 #define HARDWARE_ERROR 0x04
133 #define ILLEGAL_REQUEST 0x05
134 #define UNIT_ATTENTION 0x06
135 #define DATA_PROTECT 0x07
136 #define BLANK_CHECK 0x08
137 #define COPY_ABORTED 0x0a
138 #define ABORTED_COMMAND 0x0b
139 #define VOLUME_OVERFLOW 0x0d
140 #define MISCOMPARE 0x0e
147 #define TYPE_DISK 0x00
148 #define TYPE_TAPE 0x01
149 #define TYPE_WORM 0x04
150 #define TYPE_ROM 0x05
151 #define TYPE_MOD 0x07
152 #define TYPE_NO_LUN 0x7f
154 /* The data returned by MODE SENSE differ between the old Atari
155 * hard disks and SCSI disks connected to ACSI. In the following, both
156 * formats are defined and some macros to operate on them potably.
160 unsigned long dummy[2];
161 unsigned long sector_size;
162 unsigned char format_code;
163 #define ATARI_SENSE_FORMAT_FIX 1
164 #define ATARI_SENSE_FORMAT_CHNG 2
165 unsigned char cylinders_h;
166 unsigned char cylinders_l;
168 unsigned char reduced_h;
169 unsigned char reduced_l;
170 unsigned char precomp_h;
171 unsigned char precomp_l;
172 unsigned char landing_zone;
173 unsigned char steprate;
175 #define ATARI_SENSE_TYPE_FIXCHNG_MASK 4
176 #define ATARI_SENSE_TYPE_SOFTHARD_MASK 8
177 #define ATARI_SENSE_TYPE_FIX 4
178 #define ATARI_SENSE_TYPE_CHNG 0
179 #define ATARI_SENSE_TYPE_SOFT 0
180 #define ATARI_SENSE_TYPE_HARD 8
181 unsigned char sectors;
184 #define ATARI_CAPACITY(sd) \
185 (((int)((sd).cylinders_h<<8)|(sd).cylinders_l) * \
186 (sd).heads * (sd).sectors)
190 unsigned char dummy1;
191 unsigned char medium_type;
192 unsigned char dummy2;
193 unsigned char descriptor_size;
194 unsigned long block_count;
195 unsigned long sector_size;
197 unsigned char page_code;
198 unsigned char page_size;
199 unsigned char page_flags;
200 unsigned char qualifier;
203 #define SCSI_CAPACITY(sd) ((sd).block_count & 0xffffff)
207 ATARI_SENSE_DATA atari;
208 SCSI_SENSE_DATA scsi;
211 #define SENSE_TYPE_UNKNOWN 0
212 #define SENSE_TYPE_ATARI 1
213 #define SENSE_TYPE_SCSI 2
215 #define SENSE_TYPE(sd) \
216 (((sd).atari.dummy[0] == 8 && \
217 ((sd).atari.format_code == 1 || \
218 (sd).atari.format_code == 2)) ? SENSE_TYPE_ATARI : \
219 ((sd).scsi.dummy1 >= 11) ? SENSE_TYPE_SCSI : \
222 #define CAPACITY(sd) \
223 (SENSE_TYPE(sd) == SENSE_TYPE_ATARI ? \
224 ATARI_CAPACITY((sd).atari) : \
225 SCSI_CAPACITY((sd).scsi))
227 #define SECTOR_SIZE(sd) \
228 (SENSE_TYPE(sd) == SENSE_TYPE_ATARI ? \
229 (sd).atari.sector_size : \
230 (sd).scsi.sector_size & 0xffffff)
232 /* Default size if capacity cannot be determined (1 GByte) */
233 #define DEFAULT_SIZE 0x1fffff
235 #define CARTRCH_STAT(aip,buf) \
236 (aip->old_atari_disk ? \
237 (((buf)[0] & 0x7f) == 0x28) : \
238 ((((buf)[0] & 0x70) == 0x70) ? \
239 (((buf)[2] & 0x0f) == 0x06) : \
240 (((buf)[0] & 0x0f) == 0x06))) \
242 /* These two are also exported to other drivers that work on the ACSI bus and
243 * need an ST-RAM buffer. */
245 unsigned long phys_acsi_buffer;
249 static int CurrentNReq;
250 static int CurrentNSect;
251 static char *CurrentBuffer;
253 static DEFINE_SPINLOCK(acsi_lock);
256 #define SET_TIMER() mod_timer(&acsi_timer, jiffies + ACSI_TIMEOUT)
257 #define CLEAR_TIMER() del_timer(&acsi_timer)
259 static unsigned long STramMask;
260 #define STRAM_ADDR(a) (((a) & STramMask) == 0)
266 static char tur_cmd[6] = { 0x00, 0, 0, 0, 0, 0 };
267 static char modesense_cmd[6] = { 0x1a, 0, 0, 0, 24, 0 };
268 static char modeselect_cmd[6] = { 0x15, 0, 0, 0, 12, 0 };
269 static char inquiry_cmd[6] = { 0x12, 0, 0, 0,255, 0 };
270 static char reqsense_cmd[6] = { 0x03, 0, 0, 0, 4, 0 };
271 static char read_cmd[6] = { 0x08, 0, 0, 0, 0, 0 };
272 static char write_cmd[6] = { 0x0a, 0, 0, 0, 0, 0 };
273 static char pa_med_rem_cmd[6] = { 0x1e, 0, 0, 0, 0, 0 };
275 #define CMDSET_TARG_LUN(cmd,targ,lun) \
277 cmd[0] = (cmd[0] & ~0xe0) | (targ)<<5; \
278 cmd[1] = (cmd[1] & ~0xe0) | (lun)<<5; \
281 #define CMDSET_BLOCK(cmd,blk) \
283 unsigned long __blk = (blk); \
284 cmd[3] = __blk; __blk >>= 8; \
285 cmd[2] = __blk; __blk >>= 8; \
286 cmd[1] = (cmd[1] & 0xe0) | (__blk & 0x1f); \
289 #define CMDSET_LEN(cmd,len) \
294 /* ACSI errors (from REQUEST SENSE); There are two tables, one for the
295 * old Atari disks and one for SCSI on ACSI disks.
301 } atari_acsi_errors[] = {
302 { 0x00, "No error (??)" },
303 { 0x01, "No index pulses" },
304 { 0x02, "Seek not complete" },
305 { 0x03, "Write fault" },
306 { 0x04, "Drive not ready" },
307 { 0x06, "No Track 00 signal" },
308 { 0x10, "ECC error in ID field" },
309 { 0x11, "Uncorrectable data error" },
310 { 0x12, "ID field address mark not found" },
311 { 0x13, "Data field address mark not found" },
312 { 0x14, "Record not found" },
313 { 0x15, "Seek error" },
314 { 0x18, "Data check in no retry mode" },
315 { 0x19, "ECC error during verify" },
316 { 0x1a, "Access to bad block" },
317 { 0x1c, "Unformatted or bad format" },
318 { 0x20, "Invalid command" },
319 { 0x21, "Invalid block address" },
320 { 0x23, "Volume overflow" },
321 { 0x24, "Invalid argument" },
322 { 0x25, "Invalid drive number" },
323 { 0x26, "Byte zero parity check" },
324 { 0x28, "Cartride changed" },
325 { 0x2c, "Error count overflow" },
326 { 0x30, "Controller selftest failed" }
329 scsi_acsi_errors[] = {
330 { 0x00, "No error (??)" },
331 { 0x01, "Recovered error" },
332 { 0x02, "Drive not ready" },
333 { 0x03, "Uncorrectable medium error" },
334 { 0x04, "Hardware error" },
335 { 0x05, "Illegal request" },
336 { 0x06, "Unit attention (Reset or cartridge changed)" },
337 { 0x07, "Data protection" },
338 { 0x08, "Blank check" },
339 { 0x0b, "Aborted Command" },
340 { 0x0d, "Volume overflow" }
345 /***************************** Prototypes *****************************/
347 static int acsicmd_dma( const char *cmd, char *buffer, int blocks, int
349 static int acsi_reqsense( char *buffer, int targ, int lun);
350 static void acsi_print_error(const unsigned char *errblk, struct acsi_info_struct *aip);
351 static irqreturn_t acsi_interrupt (int irq, void *data, struct pt_regs *fp);
352 static void unexpected_acsi_interrupt( void );
353 static void bad_rw_intr( void );
354 static void read_intr( void );
355 static void write_intr( void);
356 static void acsi_times_out( unsigned long dummy );
357 static void copy_to_acsibuffer( void );
358 static void copy_from_acsibuffer( void );
359 static void do_end_requests( void );
360 static void do_acsi_request( request_queue_t * );
361 static void redo_acsi_request( void );
362 static int acsi_ioctl( struct inode *inode, struct file *file, unsigned int
363 cmd, unsigned long arg );
364 static int acsi_open( struct inode * inode, struct file * filp );
365 static int acsi_release( struct inode * inode, struct file * file );
366 static void acsi_prevent_removal(struct acsi_info_struct *aip, int flag );
367 static int acsi_change_blk_size( int target, int lun);
368 static int acsi_mode_sense( int target, int lun, SENSE_DATA *sd );
369 static int acsi_revalidate (struct gendisk *disk);
371 /************************* End of Prototypes **************************/
374 DEFINE_TIMER(acsi_timer, acsi_times_out, 0, 0);
377 #ifdef CONFIG_ATARI_SLM
379 extern int attach_slm( int target, int lun );
380 extern int slm_init( void );
386 /***********************************************************************
390 **********************************************************************/
394 * The following two functions wait for _IRQ to become Low or High,
395 * resp., with a timeout. The 'timeout' parameter is in jiffies
397 * If the functions are called with timer interrupts on (int level <
398 * 6), the timeout is based on the 'jiffies' variable to provide exact
399 * timeouts for device probing etc.
400 * If interrupts are disabled, the number of tries is based on the
401 * 'loops_per_jiffy' variable. A rough estimation is sufficient here...
406 __asm__ __volatile__ ( "movew %/sr,%0" : "=dm" (__sr) ); \
410 int acsi_wait_for_IRQ( unsigned timeout )
414 unsigned long maxjif = jiffies + timeout;
415 while (time_before(jiffies, maxjif))
416 if (!(mfp.par_dt_reg & 0x20)) return( 1 );
419 long tries = loops_per_jiffy / 8 * timeout;
420 while( --tries >= 0 )
421 if (!(mfp.par_dt_reg & 0x20)) return( 1 );
423 return( 0 ); /* timeout! */
427 int acsi_wait_for_noIRQ( unsigned timeout )
431 unsigned long maxjif = jiffies + timeout;
432 while (time_before(jiffies, maxjif))
433 if (mfp.par_dt_reg & 0x20) return( 1 );
436 long tries = loops_per_jiffy * timeout / 8;
437 while( tries-- >= 0 )
438 if (mfp.par_dt_reg & 0x20) return( 1 );
440 return( 0 ); /* timeout! */
443 static struct timeval start_time;
446 acsi_delay_start(void)
448 do_gettimeofday(&start_time);
451 /* wait from acsi_delay_start to now usec (<1E6) usec */
454 acsi_delay_end(long usec)
456 struct timeval end_time;
458 do_gettimeofday(&end_time);
459 deltau=end_time.tv_usec - start_time.tv_usec;
460 deltas=end_time.tv_sec - start_time.tv_sec;
461 if (deltas > 1 || deltas < 0)
470 /* acsicmd_dma() sends an ACSI command and sets up the DMA to transfer
471 * 'blocks' blocks of 512 bytes from/to 'buffer'.
472 * Because the _IRQ signal is used for handshaking the command bytes,
473 * the ACSI interrupt has to be disabled in this function. If the end
474 * of the operation should be signalled by a real interrupt, it has to be
475 * reenabled afterwards.
478 static int acsicmd_dma( const char *cmd, char *buffer, int blocks, int rwflag, int enable)
480 { unsigned long flags, paddr;
484 if (rwflag || *cmd == 0x0a) {
485 printk( "ACSI: Write commands disabled!\n" );
490 rwflag = rwflag ? 0x100 : 0;
491 paddr = virt_to_phys( buffer );
493 acsi_delay_end(COMMAND_DELAY);
496 local_irq_save(flags);
498 dma_wd.dma_mode_status = 0x88 | rwflag;
501 /* set DMA address */
502 dma_wd.dma_lo = (unsigned char)paddr;
505 dma_wd.dma_md = (unsigned char)paddr;
508 if (ATARIHW_PRESENT(EXTD_DMA))
509 st_dma_ext_dmahi = (unsigned short)paddr;
511 dma_wd.dma_hi = (unsigned char)paddr;
513 local_irq_restore(flags);
515 /* send the command bytes except the last */
516 for( i = 0; i < 5; ++i ) {
517 DMA_LONG_WRITE( *cmd++, 0x8a | rwflag );
519 if (!acsi_wait_for_IRQ( HZ/2 )) return( 0 ); /* timeout */
522 /* Clear FIFO and switch DMA to correct direction */
523 dma_wd.dma_mode_status = 0x92 | (rwflag ^ 0x100);
525 dma_wd.dma_mode_status = 0x92 | rwflag;
528 /* How many sectors for DMA */
529 dma_wd.fdc_acces_seccount = blocks;
532 /* send last command byte */
533 dma_wd.dma_mode_status = 0x8a | rwflag;
535 DMA_LONG_WRITE( *cmd++, 0x0a | rwflag );
545 * acsicmd_nodma() sends an ACSI command that requires no DMA.
548 int acsicmd_nodma( const char *cmd, int enable)
552 acsi_delay_end(COMMAND_DELAY);
555 /* send first command byte */
556 dma_wd.dma_mode_status = 0x88;
558 DMA_LONG_WRITE( *cmd++, 0x8a );
560 if (!acsi_wait_for_IRQ( HZ/2 )) return( 0 ); /* timeout */
562 /* send the intermediate command bytes */
563 for( i = 0; i < 4; ++i ) {
564 DMA_LONG_WRITE( *cmd++, 0x8a );
566 if (!acsi_wait_for_IRQ( HZ/2 )) return( 0 ); /* timeout */
569 /* send last command byte */
570 DMA_LONG_WRITE( *cmd++, 0x0a );
576 /* Note that the ACSI interrupt is still disabled after this
577 * function. If you want to get the IRQ delivered, enable it manually!
582 static int acsi_reqsense( char *buffer, int targ, int lun)
585 CMDSET_TARG_LUN( reqsense_cmd, targ, lun);
586 if (!acsicmd_dma( reqsense_cmd, buffer, 1, 0, 0 )) return( 0 );
587 if (!acsi_wait_for_IRQ( 10 )) return( 0 );
589 if (!acsicmd_nodma( reqsense_cmd, 0 )) return( 0 );
590 if (!acsi_wait_for_IRQ( 10 )) return( 0 );
592 if (!acsicmd_nodma( reqsense_cmd, 0 )) return( 0 );
593 if (!acsi_wait_for_IRQ( 10 )) return( 0 );
595 if (!acsicmd_nodma( reqsense_cmd, 0 )) return( 0 );
596 if (!acsi_wait_for_IRQ( 10 )) return( 0 );
598 dma_cache_maintenance( virt_to_phys(buffer), 16, 0 );
605 * ACSI status phase: get the status byte from the bus
607 * I've seen several times that a 0xff status is read, propably due to
608 * a timing error. In this case, the procedure is repeated after the
612 int acsi_getstatus( void )
618 if (!acsi_wait_for_IRQ( 100 )) {
622 dma_wd.dma_mode_status = 0x8a;
624 status = dma_wd.fdc_acces_seccount;
625 if (status != 0xff) break;
627 printk("ACSI: skipping 0xff status byte\n" );
630 acsi_wait_for_noIRQ( 20 );
632 dma_wd.dma_mode_status = 0x80;
634 acsi_wait_for_noIRQ( 20 );
637 return( status & 0x1f ); /* mask of the device# */
641 #if (defined(CONFIG_ATARI_SLM) || defined(CONFIG_ATARI_SLM_MODULE))
643 /* Receive data in an extended status phase. Needed by SLM printer. */
645 int acsi_extstatus( char *buffer, int cnt )
652 if (!acsi_wait_for_IRQ( 40 )) return( 0 );
653 dma_wd.dma_mode_status = 0x8a;
655 status = dma_wd.fdc_acces_seccount;
657 *buffer++ = status & 0xff;
664 /* Finish an extended status phase */
666 void acsi_end_extstatus( void )
669 dma_wd.dma_mode_status = 0x80;
671 acsi_wait_for_noIRQ( 20 );
676 /* Send data in an extended command phase */
678 int acsi_extcmd( unsigned char *buffer, int cnt )
682 DMA_LONG_WRITE( *buffer++, 0x8a );
684 if (!acsi_wait_for_IRQ( HZ/2 )) return( 0 ); /* timeout */
692 static void acsi_print_error(const unsigned char *errblk, struct acsi_info_struct *aip)
694 { int atari_err, i, errcode;
695 struct acsi_error *arr;
697 atari_err = aip->old_atari_disk;
699 errcode = errblk[0] & 0x7f;
701 if ((errblk[0] & 0x70) == 0x70)
702 errcode = errblk[2] & 0x0f;
704 errcode = errblk[0] & 0x0f;
706 printk( KERN_ERR "ACSI error 0x%02x", errcode );
708 if (errblk[0] & 0x80)
709 printk( " for sector %d",
710 ((errblk[1] & 0x1f) << 16) |
711 (errblk[2] << 8) | errblk[0] );
713 arr = atari_err ? atari_acsi_errors : scsi_acsi_errors;
714 i = atari_err ? sizeof(atari_acsi_errors)/sizeof(*atari_acsi_errors) :
715 sizeof(scsi_acsi_errors)/sizeof(*scsi_acsi_errors);
717 for( --i; i >= 0; --i )
718 if (arr[i].code == errcode) break;
720 printk( ": %s\n", arr[i].text );
723 /*******************************************************************
725 * ACSI interrupt routine
726 * Test, if this is a ACSI interrupt and call the irq handler
727 * Otherwise ignore this interrupt.
729 *******************************************************************/
731 static irqreturn_t acsi_interrupt(int irq, void *data, struct pt_regs *fp )
733 { void (*acsi_irq_handler)(void) = do_acsi;
738 if (!acsi_irq_handler)
739 acsi_irq_handler = unexpected_acsi_interrupt;
745 /******************************************************************
747 * The Interrupt handlers
749 *******************************************************************/
752 static void unexpected_acsi_interrupt( void )
755 printk( KERN_WARNING "Unexpected ACSI interrupt\n" );
759 /* This function is called in case of errors. Because we cannot reset
760 * the ACSI bus or a single device, there is no other choice than
761 * retrying several times :-(
764 static void bad_rw_intr( void )
770 if (++CURRENT->errors >= MAX_ERRORS)
771 end_request(CURRENT, 0);
772 /* Otherwise just retry */
776 static void read_intr( void )
780 status = acsi_getstatus();
782 struct gendisk *disk = CURRENT->rq_disk;
783 struct acsi_info_struct *aip = disk->private_data;
784 printk(KERN_ERR "%s: ", disk->disk_name);
785 if (!acsi_reqsense(acsi_buffer, aip->target, aip->lun))
786 printk( "ACSI error and REQUEST SENSE failed (status=0x%02x)\n", status );
788 acsi_print_error(acsi_buffer, aip);
789 if (CARTRCH_STAT(aip, acsi_buffer))
798 dma_cache_maintenance( virt_to_phys(CurrentBuffer), CurrentNSect*512, 0 );
799 if (CurrentBuffer == acsi_buffer)
800 copy_from_acsibuffer();
807 static void write_intr(void)
811 status = acsi_getstatus();
813 struct gendisk *disk = CURRENT->rq_disk;
814 struct acsi_info_struct *aip = disk->private_data;
815 printk( KERN_ERR "%s: ", disk->disk_name);
816 if (!acsi_reqsense( acsi_buffer, aip->target, aip->lun))
817 printk( "ACSI error and REQUEST SENSE failed (status=0x%02x)\n", status );
819 acsi_print_error(acsi_buffer, aip);
820 if (CARTRCH_STAT(aip, acsi_buffer))
833 static void acsi_times_out( unsigned long dummy )
837 if (!do_acsi) return;
840 printk( KERN_ERR "ACSI timeout\n" );
843 if (++CURRENT->errors >= MAX_ERRORS) {
845 printk( KERN_ERR "ACSI: too many errors.\n" );
847 end_request(CURRENT, 0);
855 /***********************************************************************
857 * Scatter-gather utility functions
859 ***********************************************************************/
862 static void copy_to_acsibuffer( void )
866 struct buffer_head *bh;
868 src = CURRENT->buffer;
873 memcpy( dst, src, CurrentNSect*512 );
875 for( i = 0; i < CurrentNReq; ++i ) {
876 memcpy( dst, src, bh->b_size );
878 if ((bh = bh->b_reqnext))
884 static void copy_from_acsibuffer( void )
888 struct buffer_head *bh;
890 dst = CURRENT->buffer;
895 memcpy( dst, src, CurrentNSect*512 );
897 for( i = 0; i < CurrentNReq; ++i ) {
898 memcpy( dst, src, bh->b_size );
900 if ((bh = bh->b_reqnext))
906 static void do_end_requests( void )
911 CURRENT->nr_sectors -= CurrentNSect;
912 CURRENT->current_nr_sectors -= CurrentNSect;
913 CURRENT->sector += CurrentNSect;
914 if (CURRENT->nr_sectors == 0)
915 end_request(CURRENT, 1);
918 for( i = 0; i < CurrentNReq; ++i ) {
919 n = CURRENT->bh->b_size >> 9;
920 CURRENT->nr_sectors -= n;
921 CURRENT->current_nr_sectors -= n;
922 CURRENT->sector += n;
923 end_request(CURRENT, 1);
931 /***********************************************************************
933 * do_acsi_request and friends
935 ***********************************************************************/
937 static void do_acsi_request( request_queue_t * q )
940 stdma_lock( acsi_interrupt, NULL );
945 static void redo_acsi_request( void )
947 unsigned block, target, lun, nsect;
949 unsigned long pbuffer;
950 struct buffer_head *bh;
951 struct gendisk *disk;
952 struct acsi_info_struct *aip;
967 disk = CURRENT->rq_disk;
968 aip = disk->private_data;
970 if (!CURRENT->bh && !buffer_locked(CURRENT->bh))
971 panic("ACSI: block not locked");
974 block = CURRENT->sector;
975 if (block+CURRENT->nr_sectors >= get_capacity(disk)) {
977 printk( "%s: attempted access for blocks %d...%ld past end of device at block %ld.\n",
979 block, block + CURRENT->nr_sectors - 1,
982 end_request(CURRENT, 0);
986 printk( KERN_NOTICE "%s: request denied because cartridge has "
987 "been changed.\n", disk->disk_name);
988 end_request(CURRENT, 0);
992 target = aip->target;
995 /* Find out how many sectors should be transferred from/to
996 * consecutive buffers and thus can be done with a single command.
998 buffer = CURRENT->buffer;
999 pbuffer = virt_to_phys(buffer);
1000 nsect = CURRENT->current_nr_sectors;
1003 if ((bh = CURRENT->bh) && bh != CURRENT->bhtail) {
1004 if (!STRAM_ADDR(pbuffer)) {
1005 /* If transfer is done via the ACSI buffer anyway, we can
1006 * assemble as much bh's as fit in the buffer.
1008 while( (bh = bh->b_reqnext) ) {
1009 if (nsect + (bh->b_size>>9) > ACSI_BUFFER_SECTORS) break;
1010 nsect += bh->b_size >> 9;
1012 if (bh == CURRENT->bhtail) break;
1014 buffer = acsi_buffer;
1015 pbuffer = phys_acsi_buffer;
1018 unsigned long pendadr, pnewadr;
1019 pendadr = pbuffer + nsect*512;
1020 while( (bh = bh->b_reqnext) ) {
1021 pnewadr = virt_to_phys(bh->b_data);
1022 if (!STRAM_ADDR(pnewadr) || pendadr != pnewadr) break;
1023 nsect += bh->b_size >> 9;
1024 pendadr = pnewadr + bh->b_size;
1026 if (bh == CURRENT->bhtail) break;
1031 if (!STRAM_ADDR(pbuffer)) {
1032 buffer = acsi_buffer;
1033 pbuffer = phys_acsi_buffer;
1034 if (nsect > ACSI_BUFFER_SECTORS)
1035 nsect = ACSI_BUFFER_SECTORS;
1038 CurrentBuffer = buffer;
1039 CurrentNSect = nsect;
1041 if (rq_data_dir(CURRENT) == WRITE) {
1042 CMDSET_TARG_LUN( write_cmd, target, lun );
1043 CMDSET_BLOCK( write_cmd, block );
1044 CMDSET_LEN( write_cmd, nsect );
1045 if (buffer == acsi_buffer)
1046 copy_to_acsibuffer();
1047 dma_cache_maintenance( pbuffer, nsect*512, 1 );
1048 do_acsi = write_intr;
1049 if (!acsicmd_dma( write_cmd, buffer, nsect, 1, 1)) {
1051 printk( KERN_ERR "ACSI (write): Timeout in command block\n" );
1058 if (rq_data_dir(CURRENT) == READ) {
1059 CMDSET_TARG_LUN( read_cmd, target, lun );
1060 CMDSET_BLOCK( read_cmd, block );
1061 CMDSET_LEN( read_cmd, nsect );
1062 do_acsi = read_intr;
1063 if (!acsicmd_dma( read_cmd, buffer, nsect, 0, 1)) {
1065 printk( KERN_ERR "ACSI (read): Timeout in command block\n" );
1072 panic("unknown ACSI command");
1077 /***********************************************************************
1079 * Misc functions: ioctl, open, release, check_change, ...
1081 ***********************************************************************/
1084 static int acsi_ioctl( struct inode *inode, struct file *file,
1085 unsigned int cmd, unsigned long arg )
1087 struct gendisk *disk = inode->i_bdev->bd_disk;
1088 struct acsi_info_struct *aip = disk->private_data;
1091 /* HDIO_GETGEO is supported more for getting the partition's
1092 * start sector... */
1093 { struct hd_geometry *geo = (struct hd_geometry *)arg;
1094 /* just fake some geometry here, it's nonsense anyway; to make it
1095 * easy, use Adaptec's usual 64/32 mapping */
1096 put_user( 64, &geo->heads );
1097 put_user( 32, &geo->sectors );
1098 put_user( aip->size >> 11, &geo->cylinders );
1099 put_user(get_start_sect(inode->i_bdev), &geo->start);
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 .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 sprintf(disk->devfs_name, "ad/target%d/lun%d", aip->target, aip->lun);
1735 disk->major = ACSI_MAJOR;
1736 disk->first_minor = i << 4;
1737 if (acsi_info[i].type != HARDDISK) {
1739 strcat(disk->devfs_name, "/disc");
1741 disk->fops = &acsi_fops;
1742 disk->private_data = &acsi_info[i];
1743 set_capacity(disk, acsi_info[i].size);
1744 disk->queue = acsi_queue;
1750 put_disk(acsi_gendisk[i]);
1752 blk_cleanup_queue(acsi_queue);
1754 atari_stram_free( acsi_buffer );
1756 unregister_blkdev( ACSI_MAJOR, "ad" );
1764 MODULE_LICENSE("GPL");
1766 int init_module(void)
1770 if ((err = acsi_init()))
1772 printk( KERN_INFO "ACSI driver loaded as module.\n");
1776 void cleanup_module(void)
1779 del_timer( &acsi_timer );
1780 blk_cleanup_queue(acsi_queue);
1781 atari_stram_free( acsi_buffer );
1783 if (unregister_blkdev( ACSI_MAJOR, "ad" ) != 0)
1784 printk( KERN_ERR "acsi: cleanup_module failed\n");
1786 for (i = 0; i < NDevices; i++) {
1787 del_gendisk(acsi_gendisk[i]);
1788 put_disk(acsi_gendisk[i]);
1794 * This routine is called to flush all partitions and partition tables
1795 * for a changed scsi disk, and then re-read the new partition table.
1796 * If we are revalidating a disk because of a media change, then we
1797 * enter with usage == 0. If we are using an ioctl, we automatically have
1798 * usage == 1 (we need an open channel to use an ioctl :-), so this
1801 * Changes by Martin Rogge, 9th Aug 1995:
1802 * got cd-roms to work by calling acsi_devinit. There are only two problems:
1803 * First, if there is no medium inserted, the status will remain "changed".
1804 * That is no problem at all, but our design of three-valued logic (medium
1805 * changed, medium not changed, no medium inserted).
1806 * Secondly the check could fail completely and the drive could deliver
1807 * nonsensical data, which could mess up the acsi_info[] structure. In
1808 * that case we try to make the entry safe.
1812 static int acsi_revalidate(struct gendisk *disk)
1814 struct acsi_info_struct *aip = disk->private_data;
1815 stdma_lock( NULL, NULL );
1816 if (acsi_devinit(aip) != DEV_SUPPORTED) {
1817 printk( KERN_ERR "ACSI: revalidate failed for target %d lun %d\n",
1818 aip->target, aip->lun);
1822 aip->changed = 1; /* next acsi_open will try again... */
1827 set_capacity(disk, aip->size);