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/timer.h>
51 #include <linux/kernel.h>
52 #include <linux/genhd.h>
53 #include <linux/delay.h>
55 #include <linux/major.h>
56 #include <linux/slab.h>
57 #include <linux/interrupt.h>
58 #include <scsi/scsi.h> /* for SCSI_IOCTL_GET_IDLUN */
59 #include <scsi/scsi_ioctl.h>
60 #include <linux/hdreg.h> /* for HDIO_GETGEO */
61 #include <linux/blkpg.h>
62 #include <linux/buffer_head.h>
63 #include <linux/blkdev.h>
65 #include <asm/setup.h>
66 #include <asm/pgtable.h>
67 #include <asm/system.h>
68 #include <asm/uaccess.h>
69 #include <asm/atarihw.h>
70 #include <asm/atariints.h>
71 #include <asm/atari_acsi.h>
72 #include <asm/atari_stdma.h>
73 #include <asm/atari_stram.h>
75 static void (*do_acsi
)(void) = NULL
;
76 static struct request_queue
*acsi_queue
;
77 #define QUEUE (acsi_queue)
78 #define CURRENT elv_next_request(acsi_queue)
84 #define MAX_ERRORS 8 /* Max read/write errors/sector */
85 #define MAX_LUN 8 /* Max LUNs per target */
88 #define ACSI_BUFFER_SIZE (16*1024) /* "normal" ACSI buffer size */
89 #define ACSI_BUFFER_MINSIZE (2048) /* min. buf size if ext. DMA */
90 #define ACSI_BUFFER_SIZE_ORDER 2 /* order size for above */
91 #define ACSI_BUFFER_MINSIZE_ORDER 0 /* order size for above */
92 #define ACSI_BUFFER_SECTORS (ACSI_BUFFER_SIZE/512)
94 #define ACSI_BUFFER_ORDER \
95 (ATARIHW_PRESENT(EXTD_DMA) ? \
96 ACSI_BUFFER_MINSIZE_ORDER : \
97 ACSI_BUFFER_SIZE_ORDER)
99 #define ACSI_TIMEOUT (4*HZ)
101 /* minimum delay between two commands */
103 #define COMMAND_DELAY 500
106 NONE
, HARDDISK
, CDROM
109 struct acsi_info_struct
{
110 ACSI_TYPE type
; /* type of device */
111 unsigned target
; /* target number */
112 unsigned lun
; /* LUN in target controller */
113 unsigned removable
: 1; /* Flag for removable media */
114 unsigned read_only
: 1; /* Flag for read only devices */
115 unsigned old_atari_disk
: 1; /* Is an old Atari disk */
116 unsigned changed
: 1; /* Medium has been changed */
117 unsigned long size
; /* #blocks */
119 } acsi_info
[MAX_DEV
];
125 #define NO_SENSE 0x00
126 #define RECOVERED_ERROR 0x01
127 #define NOT_READY 0x02
128 #define MEDIUM_ERROR 0x03
129 #define HARDWARE_ERROR 0x04
130 #define ILLEGAL_REQUEST 0x05
131 #define UNIT_ATTENTION 0x06
132 #define DATA_PROTECT 0x07
133 #define BLANK_CHECK 0x08
134 #define COPY_ABORTED 0x0a
135 #define ABORTED_COMMAND 0x0b
136 #define VOLUME_OVERFLOW 0x0d
137 #define MISCOMPARE 0x0e
144 #define TYPE_DISK 0x00
145 #define TYPE_TAPE 0x01
146 #define TYPE_WORM 0x04
147 #define TYPE_ROM 0x05
148 #define TYPE_MOD 0x07
149 #define TYPE_NO_LUN 0x7f
151 /* The data returned by MODE SENSE differ between the old Atari
152 * hard disks and SCSI disks connected to ACSI. In the following, both
153 * formats are defined and some macros to operate on them potably.
157 unsigned long dummy
[2];
158 unsigned long sector_size
;
159 unsigned char format_code
;
160 #define ATARI_SENSE_FORMAT_FIX 1
161 #define ATARI_SENSE_FORMAT_CHNG 2
162 unsigned char cylinders_h
;
163 unsigned char cylinders_l
;
165 unsigned char reduced_h
;
166 unsigned char reduced_l
;
167 unsigned char precomp_h
;
168 unsigned char precomp_l
;
169 unsigned char landing_zone
;
170 unsigned char steprate
;
172 #define ATARI_SENSE_TYPE_FIXCHNG_MASK 4
173 #define ATARI_SENSE_TYPE_SOFTHARD_MASK 8
174 #define ATARI_SENSE_TYPE_FIX 4
175 #define ATARI_SENSE_TYPE_CHNG 0
176 #define ATARI_SENSE_TYPE_SOFT 0
177 #define ATARI_SENSE_TYPE_HARD 8
178 unsigned char sectors
;
181 #define ATARI_CAPACITY(sd) \
182 (((int)((sd).cylinders_h<<8)|(sd).cylinders_l) * \
183 (sd).heads * (sd).sectors)
187 unsigned char dummy1
;
188 unsigned char medium_type
;
189 unsigned char dummy2
;
190 unsigned char descriptor_size
;
191 unsigned long block_count
;
192 unsigned long sector_size
;
194 unsigned char page_code
;
195 unsigned char page_size
;
196 unsigned char page_flags
;
197 unsigned char qualifier
;
200 #define SCSI_CAPACITY(sd) ((sd).block_count & 0xffffff)
204 ATARI_SENSE_DATA atari
;
205 SCSI_SENSE_DATA scsi
;
208 #define SENSE_TYPE_UNKNOWN 0
209 #define SENSE_TYPE_ATARI 1
210 #define SENSE_TYPE_SCSI 2
212 #define SENSE_TYPE(sd) \
213 (((sd).atari.dummy[0] == 8 && \
214 ((sd).atari.format_code == 1 || \
215 (sd).atari.format_code == 2)) ? SENSE_TYPE_ATARI : \
216 ((sd).scsi.dummy1 >= 11) ? SENSE_TYPE_SCSI : \
219 #define CAPACITY(sd) \
220 (SENSE_TYPE(sd) == SENSE_TYPE_ATARI ? \
221 ATARI_CAPACITY((sd).atari) : \
222 SCSI_CAPACITY((sd).scsi))
224 #define SECTOR_SIZE(sd) \
225 (SENSE_TYPE(sd) == SENSE_TYPE_ATARI ? \
226 (sd).atari.sector_size : \
227 (sd).scsi.sector_size & 0xffffff)
229 /* Default size if capacity cannot be determined (1 GByte) */
230 #define DEFAULT_SIZE 0x1fffff
232 #define CARTRCH_STAT(aip,buf) \
233 (aip->old_atari_disk ? \
234 (((buf)[0] & 0x7f) == 0x28) : \
235 ((((buf)[0] & 0x70) == 0x70) ? \
236 (((buf)[2] & 0x0f) == 0x06) : \
237 (((buf)[0] & 0x0f) == 0x06))) \
239 /* These two are also exported to other drivers that work on the ACSI bus and
240 * need an ST-RAM buffer. */
242 unsigned long phys_acsi_buffer
;
246 static int CurrentNReq
;
247 static int CurrentNSect
;
248 static char *CurrentBuffer
;
250 static DEFINE_SPINLOCK(acsi_lock
);
253 #define SET_TIMER() mod_timer(&acsi_timer, jiffies + ACSI_TIMEOUT)
254 #define CLEAR_TIMER() del_timer(&acsi_timer)
256 static unsigned long STramMask
;
257 #define STRAM_ADDR(a) (((a) & STramMask) == 0)
263 static char tur_cmd
[6] = { 0x00, 0, 0, 0, 0, 0 };
264 static char modesense_cmd
[6] = { 0x1a, 0, 0, 0, 24, 0 };
265 static char modeselect_cmd
[6] = { 0x15, 0, 0, 0, 12, 0 };
266 static char inquiry_cmd
[6] = { 0x12, 0, 0, 0,255, 0 };
267 static char reqsense_cmd
[6] = { 0x03, 0, 0, 0, 4, 0 };
268 static char read_cmd
[6] = { 0x08, 0, 0, 0, 0, 0 };
269 static char write_cmd
[6] = { 0x0a, 0, 0, 0, 0, 0 };
270 static char pa_med_rem_cmd
[6] = { 0x1e, 0, 0, 0, 0, 0 };
272 #define CMDSET_TARG_LUN(cmd,targ,lun) \
274 cmd[0] = (cmd[0] & ~0xe0) | (targ)<<5; \
275 cmd[1] = (cmd[1] & ~0xe0) | (lun)<<5; \
278 #define CMDSET_BLOCK(cmd,blk) \
280 unsigned long __blk = (blk); \
281 cmd[3] = __blk; __blk >>= 8; \
282 cmd[2] = __blk; __blk >>= 8; \
283 cmd[1] = (cmd[1] & 0xe0) | (__blk & 0x1f); \
286 #define CMDSET_LEN(cmd,len) \
291 /* ACSI errors (from REQUEST SENSE); There are two tables, one for the
292 * old Atari disks and one for SCSI on ACSI disks.
298 } atari_acsi_errors
[] = {
299 { 0x00, "No error (??)" },
300 { 0x01, "No index pulses" },
301 { 0x02, "Seek not complete" },
302 { 0x03, "Write fault" },
303 { 0x04, "Drive not ready" },
304 { 0x06, "No Track 00 signal" },
305 { 0x10, "ECC error in ID field" },
306 { 0x11, "Uncorrectable data error" },
307 { 0x12, "ID field address mark not found" },
308 { 0x13, "Data field address mark not found" },
309 { 0x14, "Record not found" },
310 { 0x15, "Seek error" },
311 { 0x18, "Data check in no retry mode" },
312 { 0x19, "ECC error during verify" },
313 { 0x1a, "Access to bad block" },
314 { 0x1c, "Unformatted or bad format" },
315 { 0x20, "Invalid command" },
316 { 0x21, "Invalid block address" },
317 { 0x23, "Volume overflow" },
318 { 0x24, "Invalid argument" },
319 { 0x25, "Invalid drive number" },
320 { 0x26, "Byte zero parity check" },
321 { 0x28, "Cartride changed" },
322 { 0x2c, "Error count overflow" },
323 { 0x30, "Controller selftest failed" }
326 scsi_acsi_errors
[] = {
327 { 0x00, "No error (??)" },
328 { 0x01, "Recovered error" },
329 { 0x02, "Drive not ready" },
330 { 0x03, "Uncorrectable medium error" },
331 { 0x04, "Hardware error" },
332 { 0x05, "Illegal request" },
333 { 0x06, "Unit attention (Reset or cartridge changed)" },
334 { 0x07, "Data protection" },
335 { 0x08, "Blank check" },
336 { 0x0b, "Aborted Command" },
337 { 0x0d, "Volume overflow" }
342 /***************************** Prototypes *****************************/
344 static int acsicmd_dma( const char *cmd
, char *buffer
, int blocks
, int
346 static int acsi_reqsense( char *buffer
, int targ
, int lun
);
347 static void acsi_print_error(const unsigned char *errblk
, struct acsi_info_struct
*aip
);
348 static irqreturn_t
acsi_interrupt (int irq
, void *data
);
349 static void unexpected_acsi_interrupt( void );
350 static void bad_rw_intr( void );
351 static void read_intr( void );
352 static void write_intr( void);
353 static void acsi_times_out( unsigned long dummy
);
354 static void copy_to_acsibuffer( void );
355 static void copy_from_acsibuffer( void );
356 static void do_end_requests( void );
357 static void do_acsi_request( request_queue_t
* );
358 static void redo_acsi_request( void );
359 static int acsi_ioctl( struct inode
*inode
, struct file
*file
, unsigned int
360 cmd
, unsigned long arg
);
361 static int acsi_open( struct inode
* inode
, struct file
* filp
);
362 static int acsi_release( struct inode
* inode
, struct file
* file
);
363 static void acsi_prevent_removal(struct acsi_info_struct
*aip
, int flag
);
364 static int acsi_change_blk_size( int target
, int lun
);
365 static int acsi_mode_sense( int target
, int lun
, SENSE_DATA
*sd
);
366 static int acsi_revalidate (struct gendisk
*disk
);
368 /************************* End of Prototypes **************************/
371 DEFINE_TIMER(acsi_timer
, acsi_times_out
, 0, 0);
374 #ifdef CONFIG_ATARI_SLM
376 extern int attach_slm( int target
, int lun
);
377 extern int slm_init( void );
383 /***********************************************************************
387 **********************************************************************/
391 * The following two functions wait for _IRQ to become Low or High,
392 * resp., with a timeout. The 'timeout' parameter is in jiffies
394 * If the functions are called with timer interrupts on (int level <
395 * 6), the timeout is based on the 'jiffies' variable to provide exact
396 * timeouts for device probing etc.
397 * If interrupts are disabled, the number of tries is based on the
398 * 'loops_per_jiffy' variable. A rough estimation is sufficient here...
403 __asm__ __volatile__ ( "movew %/sr,%0" : "=dm" (__sr) ); \
407 int acsi_wait_for_IRQ( unsigned timeout
)
411 unsigned long maxjif
= jiffies
+ timeout
;
412 while (time_before(jiffies
, maxjif
))
413 if (!(mfp
.par_dt_reg
& 0x20)) return( 1 );
416 long tries
= loops_per_jiffy
/ 8 * timeout
;
417 while( --tries
>= 0 )
418 if (!(mfp
.par_dt_reg
& 0x20)) return( 1 );
420 return( 0 ); /* timeout! */
424 int acsi_wait_for_noIRQ( unsigned timeout
)
428 unsigned long maxjif
= jiffies
+ timeout
;
429 while (time_before(jiffies
, maxjif
))
430 if (mfp
.par_dt_reg
& 0x20) return( 1 );
433 long tries
= loops_per_jiffy
* timeout
/ 8;
434 while( tries
-- >= 0 )
435 if (mfp
.par_dt_reg
& 0x20) return( 1 );
437 return( 0 ); /* timeout! */
440 static struct timeval start_time
;
443 acsi_delay_start(void)
445 do_gettimeofday(&start_time
);
448 /* wait from acsi_delay_start to now usec (<1E6) usec */
451 acsi_delay_end(long usec
)
453 struct timeval end_time
;
455 do_gettimeofday(&end_time
);
456 deltau
=end_time
.tv_usec
- start_time
.tv_usec
;
457 deltas
=end_time
.tv_sec
- start_time
.tv_sec
;
458 if (deltas
> 1 || deltas
< 0)
467 /* acsicmd_dma() sends an ACSI command and sets up the DMA to transfer
468 * 'blocks' blocks of 512 bytes from/to 'buffer'.
469 * Because the _IRQ signal is used for handshaking the command bytes,
470 * the ACSI interrupt has to be disabled in this function. If the end
471 * of the operation should be signalled by a real interrupt, it has to be
472 * reenabled afterwards.
475 static int acsicmd_dma( const char *cmd
, char *buffer
, int blocks
, int rwflag
, int enable
)
477 { unsigned long flags
, paddr
;
481 if (rwflag
|| *cmd
== 0x0a) {
482 printk( "ACSI: Write commands disabled!\n" );
487 rwflag
= rwflag
? 0x100 : 0;
488 paddr
= virt_to_phys( buffer
);
490 acsi_delay_end(COMMAND_DELAY
);
493 local_irq_save(flags
);
495 dma_wd
.dma_mode_status
= 0x88 | rwflag
;
498 /* set DMA address */
499 dma_wd
.dma_lo
= (unsigned char)paddr
;
502 dma_wd
.dma_md
= (unsigned char)paddr
;
505 if (ATARIHW_PRESENT(EXTD_DMA
))
506 st_dma_ext_dmahi
= (unsigned short)paddr
;
508 dma_wd
.dma_hi
= (unsigned char)paddr
;
510 local_irq_restore(flags
);
512 /* send the command bytes except the last */
513 for( i
= 0; i
< 5; ++i
) {
514 DMA_LONG_WRITE( *cmd
++, 0x8a | rwflag
);
516 if (!acsi_wait_for_IRQ( HZ
/2 )) return( 0 ); /* timeout */
519 /* Clear FIFO and switch DMA to correct direction */
520 dma_wd
.dma_mode_status
= 0x92 | (rwflag
^ 0x100);
522 dma_wd
.dma_mode_status
= 0x92 | rwflag
;
525 /* How many sectors for DMA */
526 dma_wd
.fdc_acces_seccount
= blocks
;
529 /* send last command byte */
530 dma_wd
.dma_mode_status
= 0x8a | rwflag
;
532 DMA_LONG_WRITE( *cmd
++, 0x0a | rwflag
);
542 * acsicmd_nodma() sends an ACSI command that requires no DMA.
545 int acsicmd_nodma( const char *cmd
, int enable
)
549 acsi_delay_end(COMMAND_DELAY
);
552 /* send first command byte */
553 dma_wd
.dma_mode_status
= 0x88;
555 DMA_LONG_WRITE( *cmd
++, 0x8a );
557 if (!acsi_wait_for_IRQ( HZ
/2 )) return( 0 ); /* timeout */
559 /* send the intermediate command bytes */
560 for( i
= 0; i
< 4; ++i
) {
561 DMA_LONG_WRITE( *cmd
++, 0x8a );
563 if (!acsi_wait_for_IRQ( HZ
/2 )) return( 0 ); /* timeout */
566 /* send last command byte */
567 DMA_LONG_WRITE( *cmd
++, 0x0a );
573 /* Note that the ACSI interrupt is still disabled after this
574 * function. If you want to get the IRQ delivered, enable it manually!
579 static int acsi_reqsense( char *buffer
, int targ
, int lun
)
582 CMDSET_TARG_LUN( reqsense_cmd
, targ
, lun
);
583 if (!acsicmd_dma( reqsense_cmd
, buffer
, 1, 0, 0 )) return( 0 );
584 if (!acsi_wait_for_IRQ( 10 )) return( 0 );
586 if (!acsicmd_nodma( reqsense_cmd
, 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 dma_cache_maintenance( virt_to_phys(buffer
), 16, 0 );
602 * ACSI status phase: get the status byte from the bus
604 * I've seen several times that a 0xff status is read, propably due to
605 * a timing error. In this case, the procedure is repeated after the
609 int acsi_getstatus( void )
615 if (!acsi_wait_for_IRQ( 100 )) {
619 dma_wd
.dma_mode_status
= 0x8a;
621 status
= dma_wd
.fdc_acces_seccount
;
622 if (status
!= 0xff) break;
624 printk("ACSI: skipping 0xff status byte\n" );
627 acsi_wait_for_noIRQ( 20 );
629 dma_wd
.dma_mode_status
= 0x80;
631 acsi_wait_for_noIRQ( 20 );
634 return( status
& 0x1f ); /* mask of the device# */
638 #if (defined(CONFIG_ATARI_SLM) || defined(CONFIG_ATARI_SLM_MODULE))
640 /* Receive data in an extended status phase. Needed by SLM printer. */
642 int acsi_extstatus( char *buffer
, int cnt
)
649 if (!acsi_wait_for_IRQ( 40 )) return( 0 );
650 dma_wd
.dma_mode_status
= 0x8a;
652 status
= dma_wd
.fdc_acces_seccount
;
654 *buffer
++ = status
& 0xff;
661 /* Finish an extended status phase */
663 void acsi_end_extstatus( void )
666 dma_wd
.dma_mode_status
= 0x80;
668 acsi_wait_for_noIRQ( 20 );
673 /* Send data in an extended command phase */
675 int acsi_extcmd( unsigned char *buffer
, int cnt
)
679 DMA_LONG_WRITE( *buffer
++, 0x8a );
681 if (!acsi_wait_for_IRQ( HZ
/2 )) return( 0 ); /* timeout */
689 static void acsi_print_error(const unsigned char *errblk
, struct acsi_info_struct
*aip
)
691 { int atari_err
, i
, errcode
;
692 struct acsi_error
*arr
;
694 atari_err
= aip
->old_atari_disk
;
696 errcode
= errblk
[0] & 0x7f;
698 if ((errblk
[0] & 0x70) == 0x70)
699 errcode
= errblk
[2] & 0x0f;
701 errcode
= errblk
[0] & 0x0f;
703 printk( KERN_ERR
"ACSI error 0x%02x", errcode
);
705 if (errblk
[0] & 0x80)
706 printk( " for sector %d",
707 ((errblk
[1] & 0x1f) << 16) |
708 (errblk
[2] << 8) | errblk
[0] );
710 arr
= atari_err
? atari_acsi_errors
: scsi_acsi_errors
;
711 i
= atari_err
? sizeof(atari_acsi_errors
)/sizeof(*atari_acsi_errors
) :
712 sizeof(scsi_acsi_errors
)/sizeof(*scsi_acsi_errors
);
714 for( --i
; i
>= 0; --i
)
715 if (arr
[i
].code
== errcode
) break;
717 printk( ": %s\n", arr
[i
].text
);
720 /*******************************************************************
722 * ACSI interrupt routine
723 * Test, if this is a ACSI interrupt and call the irq handler
724 * Otherwise ignore this interrupt.
726 *******************************************************************/
728 static irqreturn_t
acsi_interrupt(int irq
, void *data
)
730 { void (*acsi_irq_handler
)(void) = do_acsi
;
735 if (!acsi_irq_handler
)
736 acsi_irq_handler
= unexpected_acsi_interrupt
;
742 /******************************************************************
744 * The Interrupt handlers
746 *******************************************************************/
749 static void unexpected_acsi_interrupt( void )
752 printk( KERN_WARNING
"Unexpected ACSI interrupt\n" );
756 /* This function is called in case of errors. Because we cannot reset
757 * the ACSI bus or a single device, there is no other choice than
758 * retrying several times :-(
761 static void bad_rw_intr( void )
767 if (++CURRENT
->errors
>= MAX_ERRORS
)
768 end_request(CURRENT
, 0);
769 /* Otherwise just retry */
773 static void read_intr( void )
777 status
= acsi_getstatus();
779 struct gendisk
*disk
= CURRENT
->rq_disk
;
780 struct acsi_info_struct
*aip
= disk
->private_data
;
781 printk(KERN_ERR
"%s: ", disk
->disk_name
);
782 if (!acsi_reqsense(acsi_buffer
, aip
->target
, aip
->lun
))
783 printk( "ACSI error and REQUEST SENSE failed (status=0x%02x)\n", status
);
785 acsi_print_error(acsi_buffer
, aip
);
786 if (CARTRCH_STAT(aip
, acsi_buffer
))
795 dma_cache_maintenance( virt_to_phys(CurrentBuffer
), CurrentNSect
*512, 0 );
796 if (CurrentBuffer
== acsi_buffer
)
797 copy_from_acsibuffer();
804 static void write_intr(void)
808 status
= acsi_getstatus();
810 struct gendisk
*disk
= CURRENT
->rq_disk
;
811 struct acsi_info_struct
*aip
= disk
->private_data
;
812 printk( KERN_ERR
"%s: ", disk
->disk_name
);
813 if (!acsi_reqsense( acsi_buffer
, aip
->target
, aip
->lun
))
814 printk( "ACSI error and REQUEST SENSE failed (status=0x%02x)\n", status
);
816 acsi_print_error(acsi_buffer
, aip
);
817 if (CARTRCH_STAT(aip
, acsi_buffer
))
830 static void acsi_times_out( unsigned long dummy
)
834 if (!do_acsi
) return;
837 printk( KERN_ERR
"ACSI timeout\n" );
840 if (++CURRENT
->errors
>= MAX_ERRORS
) {
842 printk( KERN_ERR
"ACSI: too many errors.\n" );
844 end_request(CURRENT
, 0);
852 /***********************************************************************
854 * Scatter-gather utility functions
856 ***********************************************************************/
859 static void copy_to_acsibuffer( void )
863 struct buffer_head
*bh
;
865 src
= CURRENT
->buffer
;
870 memcpy( dst
, src
, CurrentNSect
*512 );
872 for( i
= 0; i
< CurrentNReq
; ++i
) {
873 memcpy( dst
, src
, bh
->b_size
);
875 if ((bh
= bh
->b_reqnext
))
881 static void copy_from_acsibuffer( void )
885 struct buffer_head
*bh
;
887 dst
= CURRENT
->buffer
;
892 memcpy( dst
, src
, CurrentNSect
*512 );
894 for( i
= 0; i
< CurrentNReq
; ++i
) {
895 memcpy( dst
, src
, bh
->b_size
);
897 if ((bh
= bh
->b_reqnext
))
903 static void do_end_requests( void )
908 CURRENT
->nr_sectors
-= CurrentNSect
;
909 CURRENT
->current_nr_sectors
-= CurrentNSect
;
910 CURRENT
->sector
+= CurrentNSect
;
911 if (CURRENT
->nr_sectors
== 0)
912 end_request(CURRENT
, 1);
915 for( i
= 0; i
< CurrentNReq
; ++i
) {
916 n
= CURRENT
->bh
->b_size
>> 9;
917 CURRENT
->nr_sectors
-= n
;
918 CURRENT
->current_nr_sectors
-= n
;
919 CURRENT
->sector
+= n
;
920 end_request(CURRENT
, 1);
928 /***********************************************************************
930 * do_acsi_request and friends
932 ***********************************************************************/
934 static void do_acsi_request( request_queue_t
* q
)
937 stdma_lock( acsi_interrupt
, NULL
);
942 static void redo_acsi_request( void )
944 unsigned block
, target
, lun
, nsect
;
946 unsigned long pbuffer
;
947 struct buffer_head
*bh
;
948 struct gendisk
*disk
;
949 struct acsi_info_struct
*aip
;
964 disk
= CURRENT
->rq_disk
;
965 aip
= disk
->private_data
;
967 if (!CURRENT
->bh
&& !buffer_locked(CURRENT
->bh
))
968 panic("ACSI: block not locked");
971 block
= CURRENT
->sector
;
972 if (block
+CURRENT
->nr_sectors
>= get_capacity(disk
)) {
974 printk( "%s: attempted access for blocks %d...%ld past end of device at block %ld.\n",
976 block
, block
+ CURRENT
->nr_sectors
- 1,
979 end_request(CURRENT
, 0);
983 printk( KERN_NOTICE
"%s: request denied because cartridge has "
984 "been changed.\n", disk
->disk_name
);
985 end_request(CURRENT
, 0);
989 target
= aip
->target
;
992 /* Find out how many sectors should be transferred from/to
993 * consecutive buffers and thus can be done with a single command.
995 buffer
= CURRENT
->buffer
;
996 pbuffer
= virt_to_phys(buffer
);
997 nsect
= CURRENT
->current_nr_sectors
;
1000 if ((bh
= CURRENT
->bh
) && bh
!= CURRENT
->bhtail
) {
1001 if (!STRAM_ADDR(pbuffer
)) {
1002 /* If transfer is done via the ACSI buffer anyway, we can
1003 * assemble as much bh's as fit in the buffer.
1005 while( (bh
= bh
->b_reqnext
) ) {
1006 if (nsect
+ (bh
->b_size
>>9) > ACSI_BUFFER_SECTORS
) break;
1007 nsect
+= bh
->b_size
>> 9;
1009 if (bh
== CURRENT
->bhtail
) break;
1011 buffer
= acsi_buffer
;
1012 pbuffer
= phys_acsi_buffer
;
1015 unsigned long pendadr
, pnewadr
;
1016 pendadr
= pbuffer
+ nsect
*512;
1017 while( (bh
= bh
->b_reqnext
) ) {
1018 pnewadr
= virt_to_phys(bh
->b_data
);
1019 if (!STRAM_ADDR(pnewadr
) || pendadr
!= pnewadr
) break;
1020 nsect
+= bh
->b_size
>> 9;
1021 pendadr
= pnewadr
+ bh
->b_size
;
1023 if (bh
== CURRENT
->bhtail
) break;
1028 if (!STRAM_ADDR(pbuffer
)) {
1029 buffer
= acsi_buffer
;
1030 pbuffer
= phys_acsi_buffer
;
1031 if (nsect
> ACSI_BUFFER_SECTORS
)
1032 nsect
= ACSI_BUFFER_SECTORS
;
1035 CurrentBuffer
= buffer
;
1036 CurrentNSect
= nsect
;
1038 if (rq_data_dir(CURRENT
) == WRITE
) {
1039 CMDSET_TARG_LUN( write_cmd
, target
, lun
);
1040 CMDSET_BLOCK( write_cmd
, block
);
1041 CMDSET_LEN( write_cmd
, nsect
);
1042 if (buffer
== acsi_buffer
)
1043 copy_to_acsibuffer();
1044 dma_cache_maintenance( pbuffer
, nsect
*512, 1 );
1045 do_acsi
= write_intr
;
1046 if (!acsicmd_dma( write_cmd
, buffer
, nsect
, 1, 1)) {
1048 printk( KERN_ERR
"ACSI (write): Timeout in command block\n" );
1055 if (rq_data_dir(CURRENT
) == READ
) {
1056 CMDSET_TARG_LUN( read_cmd
, target
, lun
);
1057 CMDSET_BLOCK( read_cmd
, block
);
1058 CMDSET_LEN( read_cmd
, nsect
);
1059 do_acsi
= read_intr
;
1060 if (!acsicmd_dma( read_cmd
, buffer
, nsect
, 0, 1)) {
1062 printk( KERN_ERR
"ACSI (read): Timeout in command block\n" );
1069 panic("unknown ACSI command");
1074 /***********************************************************************
1076 * Misc functions: ioctl, open, release, check_change, ...
1078 ***********************************************************************/
1080 static int acsi_getgeo(struct block_device
*bdev
, struct hd_geometry
*geo
)
1082 struct acsi_info_struct
*aip
= bdev
->bd_disk
->private_data
;
1085 * Just fake some geometry here, it's nonsense anyway
1086 * To make it easy, use Adaptec's usual 64/32 mapping
1090 geo
->cylinders
= aip
->size
>> 11;
1094 static int acsi_ioctl( struct inode
*inode
, struct file
*file
,
1095 unsigned int cmd
, unsigned long arg
)
1097 struct gendisk
*disk
= inode
->i_bdev
->bd_disk
;
1098 struct acsi_info_struct
*aip
= disk
->private_data
;
1100 case SCSI_IOCTL_GET_IDLUN
:
1101 /* SCSI compatible GET_IDLUN call to get target's ID and LUN number */
1102 put_user( aip
->target
| (aip
->lun
<< 8),
1103 &((Scsi_Idlun
*) arg
)->dev_id
);
1104 put_user( 0, &((Scsi_Idlun
*) arg
)->host_unique_id
);
1113 * Open a device, check for read-only and lock the medium if it is
1116 * Changes by Martin Rogge, 9th Aug 1995:
1117 * Check whether check_disk_change (and therefore revalidate_acsidisk)
1118 * was successful. They fail when there is no medium in the drive.
1120 * The problem of media being changed during an operation can be
1121 * ignored because of the prevent_removal code.
1123 * Added check for the validity of the device number.
1127 static int acsi_open( struct inode
* inode
, struct file
* filp
)
1129 struct gendisk
*disk
= inode
->i_bdev
->bd_disk
;
1130 struct acsi_info_struct
*aip
= disk
->private_data
;
1132 if (aip
->access_count
== 0 && aip
->removable
) {
1134 aip
->changed
= 1; /* safety first */
1136 check_disk_change( inode
->i_bdev
);
1137 if (aip
->changed
) /* revalidate was not successful (no medium) */
1139 acsi_prevent_removal(aip
, 1);
1141 aip
->access_count
++;
1143 if (filp
&& filp
->f_mode
) {
1144 check_disk_change( inode
->i_bdev
);
1145 if (filp
->f_mode
& 2) {
1146 if (aip
->read_only
) {
1147 acsi_release( inode
, filp
);
1157 * Releasing a block device means we sync() it, so that it can safely
1158 * be forgotten about...
1161 static int acsi_release( struct inode
* inode
, struct file
* file
)
1163 struct gendisk
*disk
= inode
->i_bdev
->bd_disk
;
1164 struct acsi_info_struct
*aip
= disk
->private_data
;
1165 if (--aip
->access_count
== 0 && aip
->removable
)
1166 acsi_prevent_removal(aip
, 0);
1171 * Prevent or allow a media change for removable devices.
1174 static void acsi_prevent_removal(struct acsi_info_struct
*aip
, int flag
)
1176 stdma_lock( NULL
, NULL
);
1178 CMDSET_TARG_LUN(pa_med_rem_cmd
, aip
->target
, aip
->lun
);
1179 CMDSET_LEN( pa_med_rem_cmd
, flag
);
1181 if (acsicmd_nodma(pa_med_rem_cmd
, 0) && acsi_wait_for_IRQ(3*HZ
))
1183 /* Do not report errors -- some devices may not know this command. */
1189 static int acsi_media_change(struct gendisk
*disk
)
1191 struct acsi_info_struct
*aip
= disk
->private_data
;
1193 if (!aip
->removable
)
1197 /* We can be sure that the medium has been changed -- REQUEST
1198 * SENSE has reported this earlier.
1202 /* If the flag isn't set, make a test by reading block 0.
1203 * If errors happen, it seems to be better to say "changed"...
1205 stdma_lock( NULL
, NULL
);
1206 CMDSET_TARG_LUN(read_cmd
, aip
->target
, aip
->lun
);
1207 CMDSET_BLOCK( read_cmd
, 0 );
1208 CMDSET_LEN( read_cmd
, 1 );
1209 if (acsicmd_dma(read_cmd
, acsi_buffer
, 1, 0, 0) &&
1210 acsi_wait_for_IRQ(3*HZ
)) {
1211 if (acsi_getstatus()) {
1212 if (acsi_reqsense(acsi_buffer
, aip
->target
, aip
->lun
)) {
1213 if (CARTRCH_STAT(aip
, acsi_buffer
))
1217 printk( KERN_ERR
"%s: REQUEST SENSE failed in test for "
1218 "medium change; assuming a change\n", disk
->disk_name
);
1224 printk( KERN_ERR
"%s: Test for medium changed timed out; "
1225 "assuming a change\n", disk
->disk_name
);
1231 /* Now, after reading a block, the changed status is surely valid. */
1232 return aip
->changed
;
1236 static int acsi_change_blk_size( int target
, int lun
)
1240 for (i
=0; i
<12; i
++)
1244 acsi_buffer
[10] = 2;
1245 CMDSET_TARG_LUN( modeselect_cmd
, target
, lun
);
1247 if (!acsicmd_dma( modeselect_cmd
, acsi_buffer
, 1,1,0) ||
1248 !acsi_wait_for_IRQ( 3*HZ
) ||
1249 acsi_getstatus() != 0 ) {
1256 static int acsi_mode_sense( int target
, int lun
, SENSE_DATA
*sd
)
1261 CMDSET_TARG_LUN( modesense_cmd
, target
, lun
);
1262 for (page
=0; page
<4; page
++) {
1263 modesense_cmd
[2] = page
;
1264 if (!acsicmd_dma( modesense_cmd
, acsi_buffer
, 1, 0, 0 ) ||
1265 !acsi_wait_for_IRQ( 3*HZ
) ||
1269 /* read twice to jump over the second 16-byte border! */
1271 if (acsi_wait_for_noIRQ( 20 ) &&
1272 acsicmd_nodma( modesense_cmd
, 0 ) &&
1273 acsi_wait_for_IRQ( 3*HZ
) &&
1274 acsi_getstatus() == 0)
1281 dma_cache_maintenance( phys_acsi_buffer
, sizeof(SENSE_DATA
), 0 );
1282 *sd
= *(SENSE_DATA
*)acsi_buffer
;
1284 /* Validity check, depending on type of data */
1286 switch( SENSE_TYPE(*sd
) ) {
1288 case SENSE_TYPE_ATARI
:
1289 if (CAPACITY(*sd
) == 0)
1293 case SENSE_TYPE_SCSI
:
1294 if (sd
->scsi
.descriptor_size
!= 8)
1298 case SENSE_TYPE_UNKNOWN
:
1300 printk( KERN_ERR
"ACSI target %d, lun %d: Cannot interpret "
1301 "sense data\n", target
, lun
);
1307 printk( "Mode sense data for ACSI target %d, lun %d seem not valid:",
1309 for( i
= 0; i
< sizeof(SENSE_DATA
); ++i
)
1310 printk( "%02x ", (unsigned char)acsi_buffer
[i
] );
1322 /*******************************************************************
1326 ********************************************************************/
1329 extern struct block_device_operations acsi_fops
;
1331 static struct gendisk
*acsi_gendisk
[MAX_DEV
];
1333 #define MAX_SCSI_DEVICE_CODE 10
1335 static const char *const scsi_device_types
[MAX_SCSI_DEVICE_CODE
] =
1338 "Sequential-Access",
1349 static void print_inquiry(unsigned char *data
)
1353 printk(KERN_INFO
" Vendor: ");
1354 for (i
= 8; i
< 16; i
++)
1356 if (data
[i
] >= 0x20 && i
< data
[4] + 5)
1357 printk("%c", data
[i
]);
1363 for (i
= 16; i
< 32; i
++)
1365 if (data
[i
] >= 0x20 && i
< data
[4] + 5)
1366 printk("%c", data
[i
]);
1372 for (i
= 32; i
< 36; i
++)
1374 if (data
[i
] >= 0x20 && i
< data
[4] + 5)
1375 printk("%c", data
[i
]);
1384 printk(KERN_INFO
" Type: %s ", (i
< MAX_SCSI_DEVICE_CODE
1385 ? scsi_device_types
[i
]
1387 printk(" ANSI SCSI revision: %02x", data
[2] & 0x07);
1388 if ((data
[2] & 0x07) == 1 && (data
[3] & 0x0f) == 1)
1396 * Changes by Martin Rogge, 9th Aug 1995:
1397 * acsi_devinit has been taken out of acsi_geninit, because it needs
1398 * to be called from revalidate_acsidisk. The result of request sense
1399 * is now checked for DRIVE NOT READY.
1401 * The structure *aip is only valid when acsi_devinit returns
1407 #define DEV_UNKNOWN 1
1408 #define DEV_SUPPORTED 2
1411 static int acsi_devinit(struct acsi_info_struct
*aip
)
1413 int status
, got_inquiry
;
1415 unsigned char reqsense
, extsense
;
1417 /*****************************************************************/
1418 /* Do a TEST UNIT READY command to test the presence of a device */
1419 /*****************************************************************/
1421 CMDSET_TARG_LUN(tur_cmd
, aip
->target
, aip
->lun
);
1422 if (!acsicmd_nodma(tur_cmd
, 0)) {
1423 /* timed out -> no device here */
1425 printk("target %d lun %d: timeout\n", aip
->target
, aip
->lun
);
1430 /*************************/
1431 /* Read the ACSI status. */
1432 /*************************/
1434 status
= acsi_getstatus();
1436 if (status
== 0x12) {
1437 /* The SLM printer should be the only device that
1438 * responds with the error code in the status byte. In
1439 * correct status bytes, bit 4 is never set.
1441 printk( KERN_INFO
"Detected SLM printer at id %d lun %d\n",
1442 aip
->target
, aip
->lun
);
1445 /* ignore CHECK CONDITION, since some devices send a
1447 if ((status
& 0x1e) != 0x2) {
1449 printk("target %d lun %d: status %d\n",
1450 aip
->target
, aip
->lun
, status
);
1456 /*******************************/
1457 /* Do a REQUEST SENSE command. */
1458 /*******************************/
1460 if (!acsi_reqsense(acsi_buffer
, aip
->target
, aip
->lun
)) {
1461 printk( KERN_WARNING
"acsi_reqsense failed\n");
1463 acsi_buffer
[2] = UNIT_ATTENTION
;
1465 reqsense
= acsi_buffer
[0];
1466 extsense
= acsi_buffer
[2] & 0xf;
1468 if ((reqsense
& 0x70) == 0x70) { /* extended sense */
1469 if (extsense
!= UNIT_ATTENTION
&&
1470 extsense
!= NOT_READY
) {
1472 printk("target %d lun %d: extended sense %d\n",
1473 aip
->target
, aip
->lun
, extsense
);
1479 if (reqsense
& 0x7f) {
1481 printk("target %d lun %d: sense %d\n",
1482 aip
->target
, aip
->lun
, reqsense
);
1489 if (reqsense
== 0x4) { /* SH204 Bug workaround */
1491 printk("target %d lun %d status=0 sense=4\n",
1492 aip
->target
, aip
->lun
);
1497 /***********************************************************/
1498 /* Do an INQUIRY command to get more infos on this device. */
1499 /***********************************************************/
1501 /* Assume default values */
1504 aip
->old_atari_disk
= 0;
1505 aip
->changed
= (extsense
== NOT_READY
); /* medium inserted? */
1506 aip
->size
= DEFAULT_SIZE
;
1508 /* Fake inquiry result for old atari disks */
1509 memcpy(acsi_buffer
, "\000\000\001\000 Adaptec 40xx"
1511 CMDSET_TARG_LUN(inquiry_cmd
, aip
->target
, aip
->lun
);
1512 if (acsicmd_dma(inquiry_cmd
, acsi_buffer
, 1, 0, 0) &&
1513 acsi_getstatus() == 0) {
1514 acsicmd_nodma(inquiry_cmd
, 0);
1516 dma_cache_maintenance( phys_acsi_buffer
, 256, 0 );
1518 aip
->removable
= !!(acsi_buffer
[1] & 0x80);
1520 if (aip
->type
== NONE
) /* only at boot time */
1521 print_inquiry(acsi_buffer
);
1522 switch(acsi_buffer
[0]) {
1524 aip
->type
= HARDDISK
;
1533 /****************************/
1534 /* Do a MODE SENSE command. */
1535 /****************************/
1537 if (!acsi_mode_sense(aip
->target
, aip
->lun
, &sense
)) {
1538 printk( KERN_WARNING
"No mode sense data.\n" );
1541 if ((SECTOR_SIZE(sense
) != 512) &&
1542 ((aip
->type
!= CDROM
) ||
1543 !acsi_change_blk_size(aip
->target
, aip
->lun
) ||
1544 !acsi_mode_sense(aip
->target
, aip
->lun
, &sense
) ||
1545 (SECTOR_SIZE(sense
) != 512))) {
1546 printk( KERN_WARNING
"Sector size != 512 not supported.\n" );
1549 /* There are disks out there that claim to have 0 sectors... */
1550 if (CAPACITY(sense
))
1551 aip
->size
= CAPACITY(sense
); /* else keep DEFAULT_SIZE */
1552 if (!got_inquiry
&& SENSE_TYPE(sense
) == SENSE_TYPE_ATARI
) {
1553 /* If INQUIRY failed and the sense data suggest an old
1554 * Atari disk (SH20x, Megafile), the disk is not removable
1557 aip
->old_atari_disk
= 1;
1560 /******************/
1561 /* We've done it. */
1562 /******************/
1564 return DEV_SUPPORTED
;
1567 EXPORT_SYMBOL(acsi_delay_start
);
1568 EXPORT_SYMBOL(acsi_delay_end
);
1569 EXPORT_SYMBOL(acsi_wait_for_IRQ
);
1570 EXPORT_SYMBOL(acsi_wait_for_noIRQ
);
1571 EXPORT_SYMBOL(acsicmd_nodma
);
1572 EXPORT_SYMBOL(acsi_getstatus
);
1573 EXPORT_SYMBOL(acsi_buffer
);
1574 EXPORT_SYMBOL(phys_acsi_buffer
);
1576 #ifdef CONFIG_ATARI_SLM_MODULE
1577 void acsi_attach_SLMs( int (*attach_func
)( int, int ) );
1579 EXPORT_SYMBOL(acsi_extstatus
);
1580 EXPORT_SYMBOL(acsi_end_extstatus
);
1581 EXPORT_SYMBOL(acsi_extcmd
);
1582 EXPORT_SYMBOL(acsi_attach_SLMs
);
1584 /* to remember IDs of SLM devices, SLM module is loaded later
1585 * (index is target#, contents is lun#, -1 means "no SLM") */
1589 static struct block_device_operations acsi_fops
= {
1590 .owner
= THIS_MODULE
,
1592 .release
= acsi_release
,
1593 .ioctl
= acsi_ioctl
,
1594 .getgeo
= acsi_getgeo
,
1595 .media_changed
= acsi_media_change
,
1596 .revalidate_disk
= acsi_revalidate
,
1599 #ifdef CONFIG_ATARI_SLM_MODULE
1600 /* call attach_slm() for each device that is a printer; needed for init of SLM
1601 * driver as a module, since it's not yet present if acsi.c is inited and thus
1602 * the bus gets scanned. */
1603 void acsi_attach_SLMs( int (*attach_func
)( int, int ) )
1607 for( i
= 0; i
< 8; ++i
)
1608 if (SLM_devices
[i
] >= 0)
1609 n
+= (*attach_func
)( i
, SLM_devices
[i
] );
1610 printk( KERN_INFO
"Found %d SLM printer(s) total.\n", n
);
1612 #endif /* CONFIG_ATARI_SLM_MODULE */
1615 int acsi_init( void )
1619 struct acsi_info_struct
*aip
;
1620 #ifdef CONFIG_ATARI_SLM
1623 if (!MACH_IS_ATARI
|| !ATARIHW_PRESENT(ACSI
))
1625 if (register_blkdev(ACSI_MAJOR
, "ad")) {
1630 (char *)atari_stram_alloc(ACSI_BUFFER_SIZE
, "acsi"))) {
1632 printk( KERN_ERR
"Unable to get ACSI ST-Ram buffer.\n" );
1635 phys_acsi_buffer
= virt_to_phys( acsi_buffer
);
1636 STramMask
= ATARIHW_PRESENT(EXTD_DMA
) ? 0x00000000 : 0xff000000;
1638 acsi_queue
= blk_init_queue(do_acsi_request
, &acsi_lock
);
1643 #ifdef CONFIG_ATARI_SLM
1649 printk( KERN_INFO
"Probing ACSI devices:\n" );
1651 #ifdef CONFIG_ATARI_SLM_MODULE
1652 for( i
= 0; i
< 8; ++i
)
1653 SLM_devices
[i
] = -1;
1655 stdma_lock(NULL
, NULL
);
1657 for (target
= 0; target
< 8 && NDevices
< MAX_DEV
; ++target
) {
1660 aip
= &acsi_info
[NDevices
];
1662 aip
->target
= target
;
1664 i
= acsi_devinit(aip
);
1667 printk( KERN_INFO
"Detected ");
1668 switch (aip
->type
) {
1677 printk(" ad%c at id %d lun %d ",
1678 'a' + NDevices
, target
, lun
);
1680 printk("(removable) ");
1682 printk("(read-only) ");
1683 if (aip
->size
== DEFAULT_SIZE
)
1684 printk(" unkown size, using default ");
1685 printk("%ld MByte\n",
1686 (aip
->size
*512+1024*1024/2)/(1024*1024));
1690 #ifdef CONFIG_ATARI_SLM
1691 n_slm
+= attach_slm( target
, lun
);
1694 #ifdef CONFIG_ATARI_SLM_MODULE
1695 SLM_devices
[target
] = lun
;
1698 /* neither of the above: fall through to unknown device */
1700 printk( KERN_INFO
"Detected unsupported device at "
1701 "id %d lun %d\n", target
, lun
);
1705 #ifdef CONFIG_ACSI_MULTI_LUN
1706 while (i
!= DEV_NONE
&& ++lun
< MAX_LUN
);
1712 /* reenable interrupt */
1716 #ifndef CONFIG_ATARI_SLM
1717 printk( KERN_INFO
"Found %d ACSI device(s) total.\n", NDevices
);
1719 printk( KERN_INFO
"Found %d ACSI device(s) and %d SLM printer(s) total.\n",
1723 for( i
= 0; i
< NDevices
; ++i
) {
1724 acsi_gendisk
[i
] = alloc_disk(16);
1725 if (!acsi_gendisk
[i
])
1729 for( i
= 0; i
< NDevices
; ++i
) {
1730 struct gendisk
*disk
= acsi_gendisk
[i
];
1731 sprintf(disk
->disk_name
, "ad%c", 'a'+i
);
1732 aip
= &acsi_info
[NDevices
];
1733 disk
->major
= ACSI_MAJOR
;
1734 disk
->first_minor
= i
<< 4;
1735 if (acsi_info
[i
].type
!= HARDDISK
)
1737 disk
->fops
= &acsi_fops
;
1738 disk
->private_data
= &acsi_info
[i
];
1739 set_capacity(disk
, acsi_info
[i
].size
);
1740 disk
->queue
= acsi_queue
;
1746 put_disk(acsi_gendisk
[i
]);
1748 blk_cleanup_queue(acsi_queue
);
1750 atari_stram_free( acsi_buffer
);
1752 unregister_blkdev( ACSI_MAJOR
, "ad" );
1760 MODULE_LICENSE("GPL");
1762 int init_module(void)
1766 if ((err
= acsi_init()))
1768 printk( KERN_INFO
"ACSI driver loaded as module.\n");
1772 void cleanup_module(void)
1775 del_timer( &acsi_timer
);
1776 blk_cleanup_queue(acsi_queue
);
1777 atari_stram_free( acsi_buffer
);
1779 if (unregister_blkdev( ACSI_MAJOR
, "ad" ) != 0)
1780 printk( KERN_ERR
"acsi: cleanup_module failed\n");
1782 for (i
= 0; i
< NDevices
; i
++) {
1783 del_gendisk(acsi_gendisk
[i
]);
1784 put_disk(acsi_gendisk
[i
]);
1790 * This routine is called to flush all partitions and partition tables
1791 * for a changed scsi disk, and then re-read the new partition table.
1792 * If we are revalidating a disk because of a media change, then we
1793 * enter with usage == 0. If we are using an ioctl, we automatically have
1794 * usage == 1 (we need an open channel to use an ioctl :-), so this
1797 * Changes by Martin Rogge, 9th Aug 1995:
1798 * got cd-roms to work by calling acsi_devinit. There are only two problems:
1799 * First, if there is no medium inserted, the status will remain "changed".
1800 * That is no problem at all, but our design of three-valued logic (medium
1801 * changed, medium not changed, no medium inserted).
1802 * Secondly the check could fail completely and the drive could deliver
1803 * nonsensical data, which could mess up the acsi_info[] structure. In
1804 * that case we try to make the entry safe.
1808 static int acsi_revalidate(struct gendisk
*disk
)
1810 struct acsi_info_struct
*aip
= disk
->private_data
;
1811 stdma_lock( NULL
, NULL
);
1812 if (acsi_devinit(aip
) != DEV_SUPPORTED
) {
1813 printk( KERN_ERR
"ACSI: revalidate failed for target %d lun %d\n",
1814 aip
->target
, aip
->lun
);
1818 aip
->changed
= 1; /* next acsi_open will try again... */
1823 set_capacity(disk
, aip
->size
);