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 #define MAJOR_NR ACSI_MAJOR
48 #include <linux/config.h>
49 #include <linux/module.h>
50 #include <linux/errno.h>
51 #include <linux/signal.h>
52 #include <linux/sched.h>
53 #include <linux/timer.h>
55 #include <linux/kernel.h>
56 #include <linux/genhd.h>
57 #include <linux/delay.h>
59 #include <linux/major.h>
60 #include <linux/blk.h>
61 #include <linux/malloc.h>
62 #include <linux/interrupt.h>
63 #include <scsi/scsi.h> /* for SCSI_IOCTL_GET_IDLUN */
64 typedef void Scsi_Device
; /* hack to avoid including scsi.h */
65 #include <scsi/scsi_ioctl.h>
66 #include <linux/hdreg.h> /* for HDIO_GETGEO */
67 #include <linux/blkpg.h>
69 #include <asm/setup.h>
70 #include <asm/pgtable.h>
71 #include <asm/system.h>
72 #include <asm/uaccess.h>
73 #include <asm/atarihw.h>
74 #include <asm/atariints.h>
75 #include <asm/atari_acsi.h>
76 #include <asm/atari_stdma.h>
77 #include <asm/atari_stram.h>
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 */
118 } acsi_info
[MAX_DEV
];
124 #define NO_SENSE 0x00
125 #define RECOVERED_ERROR 0x01
126 #define NOT_READY 0x02
127 #define MEDIUM_ERROR 0x03
128 #define HARDWARE_ERROR 0x04
129 #define ILLEGAL_REQUEST 0x05
130 #define UNIT_ATTENTION 0x06
131 #define DATA_PROTECT 0x07
132 #define BLANK_CHECK 0x08
133 #define COPY_ABORTED 0x0a
134 #define ABORTED_COMMAND 0x0b
135 #define VOLUME_OVERFLOW 0x0d
136 #define MISCOMPARE 0x0e
143 #define TYPE_DISK 0x00
144 #define TYPE_TAPE 0x01
145 #define TYPE_WORM 0x04
146 #define TYPE_ROM 0x05
147 #define TYPE_MOD 0x07
148 #define TYPE_NO_LUN 0x7f
150 /* The data returned by MODE SENSE differ between the old Atari
151 * hard disks and SCSI disks connected to ACSI. In the following, both
152 * formats are defined and some macros to operate on them potably.
156 unsigned long dummy
[2];
157 unsigned long sector_size
;
158 unsigned char format_code
;
159 #define ATARI_SENSE_FORMAT_FIX 1
160 #define ATARI_SENSE_FORMAT_CHNG 2
161 unsigned char cylinders_h
;
162 unsigned char cylinders_l
;
164 unsigned char reduced_h
;
165 unsigned char reduced_l
;
166 unsigned char precomp_h
;
167 unsigned char precomp_l
;
168 unsigned char landing_zone
;
169 unsigned char steprate
;
171 #define ATARI_SENSE_TYPE_FIXCHNG_MASK 4
172 #define ATARI_SENSE_TYPE_SOFTHARD_MASK 8
173 #define ATARI_SENSE_TYPE_FIX 4
174 #define ATARI_SENSE_TYPE_CHNG 0
175 #define ATARI_SENSE_TYPE_SOFT 0
176 #define ATARI_SENSE_TYPE_HARD 8
177 unsigned char sectors
;
180 #define ATARI_CAPACITY(sd) \
181 (((int)((sd).cylinders_h<<8)|(sd).cylinders_l) * \
182 (sd).heads * (sd).sectors)
186 unsigned char dummy1
;
187 unsigned char medium_type
;
188 unsigned char dummy2
;
189 unsigned char descriptor_size
;
190 unsigned long block_count
;
191 unsigned long sector_size
;
193 unsigned char page_code
;
194 unsigned char page_size
;
195 unsigned char page_flags
;
196 unsigned char qualifier
;
199 #define SCSI_CAPACITY(sd) ((sd).block_count & 0xffffff)
203 ATARI_SENSE_DATA atari
;
204 SCSI_SENSE_DATA scsi
;
207 #define SENSE_TYPE_UNKNOWN 0
208 #define SENSE_TYPE_ATARI 1
209 #define SENSE_TYPE_SCSI 2
211 #define SENSE_TYPE(sd) \
212 (((sd).atari.dummy[0] == 8 && \
213 ((sd).atari.format_code == 1 || \
214 (sd).atari.format_code == 2)) ? SENSE_TYPE_ATARI : \
215 ((sd).scsi.dummy1 >= 11) ? SENSE_TYPE_SCSI : \
218 #define CAPACITY(sd) \
219 (SENSE_TYPE(sd) == SENSE_TYPE_ATARI ? \
220 ATARI_CAPACITY((sd).atari) : \
221 SCSI_CAPACITY((sd).scsi))
223 #define SECTOR_SIZE(sd) \
224 (SENSE_TYPE(sd) == SENSE_TYPE_ATARI ? \
225 (sd).atari.sector_size : \
226 (sd).scsi.sector_size & 0xffffff)
228 /* Default size if capacity cannot be determined (1 GByte) */
229 #define DEFAULT_SIZE 0x1fffff
231 #define CARTRCH_STAT(dev,buf) \
232 (acsi_info[(dev)].old_atari_disk ? \
233 (((buf)[0] & 0x7f) == 0x28) : \
234 ((((buf)[0] & 0x70) == 0x70) ? \
235 (((buf)[2] & 0x0f) == 0x06) : \
236 (((buf)[0] & 0x0f) == 0x06))) \
238 /* These two are also exported to other drivers that work on the ACSI bus and
239 * need an ST-RAM buffer. */
241 unsigned long phys_acsi_buffer
;
243 static int NDevices
= 0;
244 static int acsi_sizes
[MAX_DEV
<<4] = { 0, };
245 static int acsi_blocksizes
[MAX_DEV
<<4] = { 0, };
246 static struct hd_struct acsi_part
[MAX_DEV
<<4] = { {0,0}, };
247 static int access_count
[MAX_DEV
] = { 0, };
248 static char busy
[MAX_DEV
] = { 0, };
249 static DECLARE_WAIT_QUEUE_HEAD(busy_wait
);
251 static int CurrentNReq
;
252 static int CurrentNSect
;
253 static char *CurrentBuffer
;
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 #define min(a,b) (((a)<(b))?(a):(b))
297 /* ACSI errors (from REQUEST SENSE); There are two tables, one for the
298 * old Atari disks and one for SCSI on ACSI disks.
304 } atari_acsi_errors
[] = {
305 { 0x00, "No error (??)" },
306 { 0x01, "No index pulses" },
307 { 0x02, "Seek not complete" },
308 { 0x03, "Write fault" },
309 { 0x04, "Drive not ready" },
310 { 0x06, "No Track 00 signal" },
311 { 0x10, "ECC error in ID field" },
312 { 0x11, "Uncorrectable data error" },
313 { 0x12, "ID field address mark not found" },
314 { 0x13, "Data field address mark not found" },
315 { 0x14, "Record not found" },
316 { 0x15, "Seek error" },
317 { 0x18, "Data check in no retry mode" },
318 { 0x19, "ECC error during verify" },
319 { 0x1a, "Access to bad block" },
320 { 0x1c, "Unformatted or bad format" },
321 { 0x20, "Invalid command" },
322 { 0x21, "Invalid block address" },
323 { 0x23, "Volume overflow" },
324 { 0x24, "Invalid argument" },
325 { 0x25, "Invalid drive number" },
326 { 0x26, "Byte zero parity check" },
327 { 0x28, "Cartride changed" },
328 { 0x2c, "Error count overflow" },
329 { 0x30, "Controller selftest failed" }
332 scsi_acsi_errors
[] = {
333 { 0x00, "No error (??)" },
334 { 0x01, "Recovered error" },
335 { 0x02, "Drive not ready" },
336 { 0x03, "Uncorrectable medium error" },
337 { 0x04, "Hardware error" },
338 { 0x05, "Illegal request" },
339 { 0x06, "Unit attention (Reset or cartridge changed)" },
340 { 0x07, "Data protection" },
341 { 0x08, "Blank check" },
342 { 0x0b, "Aborted Command" },
343 { 0x0d, "Volume overflow" }
348 /***************************** Prototypes *****************************/
350 static int acsicmd_dma( const char *cmd
, char *buffer
, int blocks
, int
352 static int acsi_reqsense( char *buffer
, int targ
, int lun
);
353 static void acsi_print_error( const unsigned char *errblk
, int dev
);
354 static void acsi_interrupt (int irq
, void *data
, struct pt_regs
*fp
);
355 static void unexpected_acsi_interrupt( void );
356 static void bad_rw_intr( void );
357 static void read_intr( void );
358 static void write_intr( void);
359 static void acsi_times_out( unsigned long dummy
);
360 static void copy_to_acsibuffer( void );
361 static void copy_from_acsibuffer( void );
362 static void do_end_requests( void );
363 static void do_acsi_request( void );
364 static void redo_acsi_request( void );
365 static int acsi_ioctl( struct inode
*inode
, struct file
*file
, unsigned int
366 cmd
, unsigned long arg
);
367 static int acsi_open( struct inode
* inode
, struct file
* filp
);
368 static int acsi_release( struct inode
* inode
, struct file
* file
);
369 static void acsi_prevent_removal( int target
, int flag
);
370 static int acsi_change_blk_size( int target
, int lun
);
371 static int acsi_mode_sense( int target
, int lun
, SENSE_DATA
*sd
);
372 static void acsi_geninit( struct gendisk
*gd
);
373 static int revalidate_acsidisk( int dev
, int maxusage
);
374 static int acsi_revalidate (dev_t
);
376 /************************* End of Prototypes **************************/
379 struct timer_list acsi_timer
= { NULL
, NULL
, 0, 0, acsi_times_out
};
382 #ifdef CONFIG_ATARI_SLM
384 extern int attach_slm( int target
, int lun
);
385 extern int slm_init( void );
391 /***********************************************************************
395 **********************************************************************/
399 * The following two functions wait for _IRQ to become Low or High,
400 * resp., with a timeout. The 'timeout' parameter is in jiffies
402 * If the functions are called with timer interrupts on (int level <
403 * 6), the timeout is based on the 'jiffies' variable to provide exact
404 * timeouts for device probing etc.
405 * If interrupts are disabled, the number of tries is based on the
406 * 'loops_per_sec' variable. A rough estimation is sufficient here...
411 __asm__ __volatile__ ( "movew %/sr,%0" : "=dm" (__sr) ); \
415 int acsi_wait_for_IRQ( unsigned timeout
)
419 unsigned long maxjif
= jiffies
+ timeout
;
420 while (time_before(jiffies
, maxjif
))
421 if (!(mfp
.par_dt_reg
& 0x20)) return( 1 );
424 long tries
= loops_per_sec
/ HZ
/ 8 * timeout
;
425 while( --tries
>= 0 )
426 if (!(mfp
.par_dt_reg
& 0x20)) return( 1 );
428 return( 0 ); /* timeout! */
432 int acsi_wait_for_noIRQ( unsigned timeout
)
436 unsigned long maxjif
= jiffies
+ timeout
;
437 while (time_before(jiffies
, maxjif
))
438 if (mfp
.par_dt_reg
& 0x20) return( 1 );
441 long tries
= loops_per_sec
* timeout
/ HZ
/ 8;
442 while( tries
-- >= 0 )
443 if (mfp
.par_dt_reg
& 0x20) return( 1 );
445 return( 0 ); /* timeout! */
448 static struct timeval start_time
;
451 acsi_delay_start(void)
453 do_gettimeofday(&start_time
);
456 /* wait from acsi_delay_start to now usec (<1E6) usec */
459 acsi_delay_end(long usec
)
461 struct timeval end_time
;
463 do_gettimeofday(&end_time
);
464 deltau
=end_time
.tv_usec
- start_time
.tv_usec
;
465 deltas
=end_time
.tv_sec
- start_time
.tv_sec
;
466 if (deltas
> 1 || deltas
< 0)
475 /* acsicmd_dma() sends an ACSI command and sets up the DMA to transfer
476 * 'blocks' blocks of 512 bytes from/to 'buffer'.
477 * Because the _IRQ signal is used for handshaking the command bytes,
478 * the ACSI interrupt has to be disabled in this function. If the end
479 * of the operation should be signalled by a real interrupt, it has to be
480 * reenabled afterwards.
483 static int acsicmd_dma( const char *cmd
, char *buffer
, int blocks
, int rwflag
, int enable
)
485 { unsigned long flags
, paddr
;
489 if (rwflag
|| *cmd
== 0x0a) {
490 printk( "ACSI: Write commands disabled!\n" );
495 rwflag
= rwflag
? 0x100 : 0;
496 paddr
= virt_to_phys( buffer
);
498 acsi_delay_end(COMMAND_DELAY
);
504 dma_wd
.dma_mode_status
= 0x88 | rwflag
;
507 /* set DMA address */
508 dma_wd
.dma_lo
= (unsigned char)paddr
;
511 dma_wd
.dma_md
= (unsigned char)paddr
;
514 if (ATARIHW_PRESENT(EXTD_DMA
))
515 st_dma_ext_dmahi
= (unsigned short)paddr
;
517 dma_wd
.dma_hi
= (unsigned char)paddr
;
519 restore_flags(flags
);
521 /* send the command bytes except the last */
522 for( i
= 0; i
< 5; ++i
) {
523 DMA_LONG_WRITE( *cmd
++, 0x8a | rwflag
);
525 if (!acsi_wait_for_IRQ( HZ
/2 )) return( 0 ); /* timeout */
528 /* Clear FIFO and switch DMA to correct direction */
529 dma_wd
.dma_mode_status
= 0x92 | (rwflag
^ 0x100);
531 dma_wd
.dma_mode_status
= 0x92 | rwflag
;
534 /* How many sectors for DMA */
535 dma_wd
.fdc_acces_seccount
= blocks
;
538 /* send last command byte */
539 dma_wd
.dma_mode_status
= 0x8a | rwflag
;
541 DMA_LONG_WRITE( *cmd
++, 0x0a | rwflag
);
551 * acsicmd_nodma() sends an ACSI command that requires no DMA.
554 int acsicmd_nodma( const char *cmd
, int enable
)
558 acsi_delay_end(COMMAND_DELAY
);
561 /* send first command byte */
562 dma_wd
.dma_mode_status
= 0x88;
564 DMA_LONG_WRITE( *cmd
++, 0x8a );
566 if (!acsi_wait_for_IRQ( HZ
/2 )) return( 0 ); /* timeout */
568 /* send the intermediate command bytes */
569 for( i
= 0; i
< 4; ++i
) {
570 DMA_LONG_WRITE( *cmd
++, 0x8a );
572 if (!acsi_wait_for_IRQ( HZ
/2 )) return( 0 ); /* timeout */
575 /* send last command byte */
576 DMA_LONG_WRITE( *cmd
++, 0x0a );
582 /* Note that the ACSI interrupt is still disabled after this
583 * function. If you want to get the IRQ delivered, enable it manually!
588 static int acsi_reqsense( char *buffer
, int targ
, int lun
)
591 CMDSET_TARG_LUN( reqsense_cmd
, targ
, lun
);
592 if (!acsicmd_dma( reqsense_cmd
, buffer
, 1, 0, 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 if (!acsicmd_nodma( reqsense_cmd
, 0 )) return( 0 );
599 if (!acsi_wait_for_IRQ( 10 )) return( 0 );
601 if (!acsicmd_nodma( reqsense_cmd
, 0 )) return( 0 );
602 if (!acsi_wait_for_IRQ( 10 )) return( 0 );
604 dma_cache_maintenance( virt_to_phys(buffer
), 16, 0 );
611 * ACSI status phase: get the status byte from the bus
613 * I've seen several times that a 0xff status is read, propably due to
614 * a timing error. In this case, the procedure is repeated after the
618 int acsi_getstatus( void )
624 if (!acsi_wait_for_IRQ( 100 )) {
628 dma_wd
.dma_mode_status
= 0x8a;
630 status
= dma_wd
.fdc_acces_seccount
;
631 if (status
!= 0xff) break;
633 printk("ACSI: skipping 0xff status byte\n" );
636 acsi_wait_for_noIRQ( 20 );
638 dma_wd
.dma_mode_status
= 0x80;
640 acsi_wait_for_noIRQ( 20 );
643 return( status
& 0x1f ); /* mask of the device# */
647 #if (defined(CONFIG_ATARI_SLM) || defined(CONFIG_ATARI_SLM_MODULE))
649 /* Receive data in an extended status phase. Needed by SLM printer. */
651 int acsi_extstatus( char *buffer
, int cnt
)
658 if (!acsi_wait_for_IRQ( 40 )) return( 0 );
659 dma_wd
.dma_mode_status
= 0x8a;
661 status
= dma_wd
.fdc_acces_seccount
;
663 *buffer
++ = status
& 0xff;
670 /* Finish an extended status phase */
672 void acsi_end_extstatus( void )
675 dma_wd
.dma_mode_status
= 0x80;
677 acsi_wait_for_noIRQ( 20 );
682 /* Send data in an extended command phase */
684 int acsi_extcmd( unsigned char *buffer
, int cnt
)
688 DMA_LONG_WRITE( *buffer
++, 0x8a );
690 if (!acsi_wait_for_IRQ( HZ
/2 )) return( 0 ); /* timeout */
698 static void acsi_print_error( const unsigned char *errblk
, int dev
)
700 { int atari_err
, i
, errcode
;
701 struct acsi_error
*arr
;
703 atari_err
= acsi_info
[dev
].old_atari_disk
;
705 errcode
= errblk
[0] & 0x7f;
707 if ((errblk
[0] & 0x70) == 0x70)
708 errcode
= errblk
[2] & 0x0f;
710 errcode
= errblk
[0] & 0x0f;
712 printk( KERN_ERR
"ACSI error 0x%02x", errcode
);
714 if (errblk
[0] & 0x80)
715 printk( " for sector %d",
716 ((errblk
[1] & 0x1f) << 16) |
717 (errblk
[2] << 8) | errblk
[0] );
719 arr
= atari_err
? atari_acsi_errors
: scsi_acsi_errors
;
720 i
= atari_err
? sizeof(atari_acsi_errors
)/sizeof(*atari_acsi_errors
) :
721 sizeof(scsi_acsi_errors
)/sizeof(*scsi_acsi_errors
);
723 for( --i
; i
>= 0; --i
)
724 if (arr
[i
].code
== errcode
) break;
726 printk( ": %s\n", arr
[i
].text
);
729 /*******************************************************************
731 * ACSI interrupt routine
732 * Test, if this is a ACSI interrupt and call the irq handler
733 * Otherwise ignore this interrupt.
735 *******************************************************************/
737 static void acsi_interrupt(int irq
, void *data
, struct pt_regs
*fp
)
739 { void (*acsi_irq_handler
)(void) = DEVICE_INTR
;
744 if (!acsi_irq_handler
)
745 acsi_irq_handler
= unexpected_acsi_interrupt
;
750 /******************************************************************
752 * The Interrupt handlers
754 *******************************************************************/
757 static void unexpected_acsi_interrupt( void )
760 printk( KERN_WARNING
"Unexpected ACSI interrupt\n" );
764 /* This function is called in case of errors. Because we cannot reset
765 * the ACSI bus or a single device, there is no other choice than
766 * retrying several times :-(
769 static void bad_rw_intr( void )
775 if (++CURRENT
->errors
>= MAX_ERRORS
)
777 /* Otherwise just retry */
781 static void read_intr( void )
785 status
= acsi_getstatus();
787 int dev
= DEVICE_NR(MINOR(CURRENT
->rq_dev
));
788 printk( KERN_ERR
"ad%c: ", dev
+'a' );
789 if (!acsi_reqsense( acsi_buffer
, acsi_info
[dev
].target
,
791 printk( "ACSI error and REQUEST SENSE failed (status=0x%02x)\n", status
);
793 acsi_print_error( acsi_buffer
, dev
);
794 if (CARTRCH_STAT( dev
, acsi_buffer
))
795 acsi_info
[dev
].changed
= 1;
803 dma_cache_maintenance( virt_to_phys(CurrentBuffer
), CurrentNSect
*512, 0 );
804 if (CurrentBuffer
== acsi_buffer
)
805 copy_from_acsibuffer();
812 static void write_intr(void)
816 status
= acsi_getstatus();
818 int dev
= DEVICE_NR(MINOR(CURRENT
->rq_dev
));
819 printk( KERN_ERR
"ad%c: ", dev
+'a' );
820 if (!acsi_reqsense( acsi_buffer
, acsi_info
[dev
].target
,
822 printk( "ACSI error and REQUEST SENSE failed (status=0x%02x)\n", status
);
824 acsi_print_error( acsi_buffer
, dev
);
825 if (CARTRCH_STAT( dev
, acsi_buffer
))
826 acsi_info
[dev
].changed
= 1;
838 static void acsi_times_out( unsigned long dummy
)
842 if (!DEVICE_INTR
) return;
845 printk( KERN_ERR
"ACSI timeout\n" );
846 if (!CURRENT
) return;
847 if (++CURRENT
->errors
>= MAX_ERRORS
) {
849 printk( KERN_ERR
"ACSI: too many errors.\n" );
859 /***********************************************************************
861 * Scatter-gather utility functions
863 ***********************************************************************/
866 static void copy_to_acsibuffer( void )
870 struct buffer_head
*bh
;
872 src
= CURRENT
->buffer
;
877 memcpy( dst
, src
, CurrentNSect
*512 );
879 for( i
= 0; i
< CurrentNReq
; ++i
) {
880 memcpy( dst
, src
, bh
->b_size
);
882 if ((bh
= bh
->b_reqnext
))
888 static void copy_from_acsibuffer( void )
892 struct buffer_head
*bh
;
894 dst
= CURRENT
->buffer
;
899 memcpy( dst
, src
, CurrentNSect
*512 );
901 for( i
= 0; i
< CurrentNReq
; ++i
) {
902 memcpy( dst
, src
, bh
->b_size
);
904 if ((bh
= bh
->b_reqnext
))
910 static void do_end_requests( void )
915 CURRENT
->nr_sectors
-= CurrentNSect
;
916 CURRENT
->current_nr_sectors
-= CurrentNSect
;
917 CURRENT
->sector
+= CurrentNSect
;
918 if (CURRENT
->nr_sectors
== 0)
922 for( i
= 0; i
< CurrentNReq
; ++i
) {
923 n
= CURRENT
->bh
->b_size
>> 9;
924 CURRENT
->nr_sectors
-= n
;
925 CURRENT
->current_nr_sectors
-= n
;
926 CURRENT
->sector
+= n
;
935 /***********************************************************************
937 * do_acsi_request and friends
939 ***********************************************************************/
941 static void do_acsi_request( void )
944 stdma_lock( acsi_interrupt
, NULL
);
949 static void redo_acsi_request( void )
951 { unsigned block
, dev
, target
, lun
, nsect
;
953 unsigned long pbuffer
;
954 struct buffer_head
*bh
;
956 if (CURRENT
&& CURRENT
->rq_status
== RQ_INACTIVE
) {
969 /* Another check here: An interrupt or timer event could have
970 * happened since the last check!
972 if (CURRENT
&& CURRENT
->rq_status
== RQ_INACTIVE
) {
989 if (MAJOR(CURRENT
->rq_dev
) != MAJOR_NR
)
990 panic(DEVICE_NAME
": request list destroyed");
992 if (!CURRENT
->bh
&& !buffer_locked(CURRENT
->bh
))
993 panic(DEVICE_NAME
": block not locked");
996 dev
= MINOR(CURRENT
->rq_dev
);
997 block
= CURRENT
->sector
;
998 if (DEVICE_NR(dev
) >= NDevices
||
999 block
+CURRENT
->nr_sectors
>= acsi_part
[dev
].nr_sects
) {
1001 printk( "ad%c: attempted access for blocks %d...%ld past end of device at block %ld.\n",
1003 block
, block
+ CURRENT
->nr_sectors
- 1,
1004 acsi_part
[dev
].nr_sects
);
1009 if (acsi_info
[DEVICE_NR(dev
)].changed
) {
1010 printk( KERN_NOTICE
"ad%c: request denied because cartridge has "
1011 "been changed.\n", DEVICE_NR(dev
)+'a' );
1016 block
+= acsi_part
[dev
].start_sect
;
1017 target
= acsi_info
[DEVICE_NR(dev
)].target
;
1018 lun
= acsi_info
[DEVICE_NR(dev
)].lun
;
1020 /* Find out how many sectors should be transferred from/to
1021 * consecutive buffers and thus can be done with a single command.
1023 buffer
= CURRENT
->buffer
;
1024 pbuffer
= virt_to_phys(buffer
);
1025 nsect
= CURRENT
->current_nr_sectors
;
1028 if ((bh
= CURRENT
->bh
) && bh
!= CURRENT
->bhtail
) {
1029 if (!STRAM_ADDR(pbuffer
)) {
1030 /* If transfer is done via the ACSI buffer anyway, we can
1031 * assemble as much bh's as fit in the buffer.
1033 while( (bh
= bh
->b_reqnext
) ) {
1034 if (nsect
+ (bh
->b_size
>>9) > ACSI_BUFFER_SECTORS
) break;
1035 nsect
+= bh
->b_size
>> 9;
1037 if (bh
== CURRENT
->bhtail
) break;
1039 buffer
= acsi_buffer
;
1040 pbuffer
= phys_acsi_buffer
;
1043 unsigned long pendadr
, pnewadr
;
1044 pendadr
= pbuffer
+ nsect
*512;
1045 while( (bh
= bh
->b_reqnext
) ) {
1046 pnewadr
= virt_to_phys(bh
->b_data
);
1047 if (!STRAM_ADDR(pnewadr
) || pendadr
!= pnewadr
) break;
1048 nsect
+= bh
->b_size
>> 9;
1049 pendadr
= pnewadr
+ bh
->b_size
;
1051 if (bh
== CURRENT
->bhtail
) break;
1056 if (!STRAM_ADDR(pbuffer
)) {
1057 buffer
= acsi_buffer
;
1058 pbuffer
= phys_acsi_buffer
;
1059 if (nsect
> ACSI_BUFFER_SECTORS
)
1060 nsect
= ACSI_BUFFER_SECTORS
;
1063 CurrentBuffer
= buffer
;
1064 CurrentNSect
= nsect
;
1066 if (CURRENT
->cmd
== WRITE
) {
1067 CMDSET_TARG_LUN( write_cmd
, target
, lun
);
1068 CMDSET_BLOCK( write_cmd
, block
);
1069 CMDSET_LEN( write_cmd
, nsect
);
1070 if (buffer
== acsi_buffer
)
1071 copy_to_acsibuffer();
1072 dma_cache_maintenance( pbuffer
, nsect
*512, 1 );
1073 SET_INTR(write_intr
);
1074 if (!acsicmd_dma( write_cmd
, buffer
, nsect
, 1, 1)) {
1076 printk( KERN_ERR
"ACSI (write): Timeout in command block\n" );
1083 if (CURRENT
->cmd
== READ
) {
1084 CMDSET_TARG_LUN( read_cmd
, target
, lun
);
1085 CMDSET_BLOCK( read_cmd
, block
);
1086 CMDSET_LEN( read_cmd
, nsect
);
1087 SET_INTR(read_intr
);
1088 if (!acsicmd_dma( read_cmd
, buffer
, nsect
, 0, 1)) {
1090 printk( KERN_ERR
"ACSI (read): Timeout in command block\n" );
1097 panic("unknown ACSI command");
1102 /***********************************************************************
1104 * Misc functions: ioctl, open, release, check_change, ...
1106 ***********************************************************************/
1109 static int acsi_ioctl( struct inode
*inode
, struct file
*file
,
1110 unsigned int cmd
, unsigned long arg
)
1115 dev
= DEVICE_NR(MINOR(inode
->i_rdev
));
1116 if (dev
>= NDevices
)
1120 /* HDIO_GETGEO is supported more for getting the partition's
1121 * start sector... */
1122 { struct hd_geometry
*geo
= (struct hd_geometry
*)arg
;
1123 /* just fake some geometry here, it's nonsense anyway; to make it
1124 * easy, use Adaptec's usual 64/32 mapping */
1125 put_user( 64, &geo
->heads
);
1126 put_user( 32, &geo
->sectors
);
1127 put_user( acsi_info
[dev
].size
>> 11, &geo
->cylinders
);
1128 put_user( acsi_part
[MINOR(inode
->i_rdev
)].start_sect
, &geo
->start
);
1132 case SCSI_IOCTL_GET_IDLUN
:
1133 /* SCSI compatible GET_IDLUN call to get target's ID and LUN number */
1134 put_user( acsi_info
[dev
].target
| (acsi_info
[dev
].lun
<< 8),
1135 &((Scsi_Idlun
*) arg
)->dev_id
);
1136 put_user( 0, &((Scsi_Idlun
*) arg
)->host_unique_id
);
1139 case BLKGETSIZE
: /* Return device size */
1140 return put_user(acsi_part
[MINOR(inode
->i_rdev
)].nr_sects
,
1147 return blk_ioctl(inode
->i_rdev
, cmd
, arg
);
1149 case BLKRRPART
: /* Re-read partition tables */
1150 if (!capable(CAP_SYS_ADMIN
))
1152 return revalidate_acsidisk(inode
->i_rdev
, 1);
1161 * Open a device, check for read-only and lock the medium if it is
1164 * Changes by Martin Rogge, 9th Aug 1995:
1165 * Check whether check_disk_change (and therefore revalidate_acsidisk)
1166 * was successful. They fail when there is no medium in the drive.
1168 * The problem of media being changed during an operation can be
1169 * ignored because of the prevent_removal code.
1171 * Added check for the validity of the device number.
1175 static int acsi_open( struct inode
* inode
, struct file
* filp
)
1178 struct acsi_info_struct
*aip
;
1180 device
= DEVICE_NR(MINOR(inode
->i_rdev
));
1181 if (device
>= NDevices
)
1183 aip
= &acsi_info
[device
];
1184 while (busy
[device
])
1185 sleep_on(&busy_wait
);
1187 if (access_count
[device
] == 0 && aip
->removable
) {
1189 aip
->changed
= 1; /* safety first */
1191 check_disk_change( inode
->i_rdev
);
1192 if (aip
->changed
) /* revalidate was not successful (no medium) */
1194 acsi_prevent_removal(device
, 1);
1196 access_count
[device
]++;
1199 if (filp
&& filp
->f_mode
) {
1200 check_disk_change( inode
->i_rdev
);
1201 if (filp
->f_mode
& 2) {
1202 if (aip
->read_only
) {
1203 acsi_release( inode
, filp
);
1213 * Releasing a block device means we sync() it, so that it can safely
1214 * be forgotten about...
1217 static int acsi_release( struct inode
* inode
, struct file
* file
)
1221 sync_dev(inode
->i_rdev
);
1223 device
= DEVICE_NR(MINOR(inode
->i_rdev
));
1224 if (--access_count
[device
] == 0 && acsi_info
[device
].removable
)
1225 acsi_prevent_removal(device
, 0);
1231 * Prevent or allow a media change for removable devices.
1234 static void acsi_prevent_removal(int device
, int flag
)
1236 stdma_lock( NULL
, NULL
);
1238 CMDSET_TARG_LUN(pa_med_rem_cmd
, acsi_info
[device
].target
,
1239 acsi_info
[device
].lun
);
1240 CMDSET_LEN( pa_med_rem_cmd
, flag
);
1242 if (acsicmd_nodma(pa_med_rem_cmd
, 0) && acsi_wait_for_IRQ(3*HZ
))
1244 /* Do not report errors -- some devices may not know this command. */
1250 static int acsi_media_change (dev_t dev
)
1252 int device
= DEVICE_NR(MINOR(dev
));
1253 struct acsi_info_struct
*aip
;
1255 aip
= &acsi_info
[device
];
1256 if (!aip
->removable
)
1260 /* We can be sure that the medium has been changed -- REQUEST
1261 * SENSE has reported this earlier.
1265 /* If the flag isn't set, make a test by reading block 0.
1266 * If errors happen, it seems to be better to say "changed"...
1268 stdma_lock( NULL
, NULL
);
1269 CMDSET_TARG_LUN(read_cmd
, aip
->target
, aip
->lun
);
1270 CMDSET_BLOCK( read_cmd
, 0 );
1271 CMDSET_LEN( read_cmd
, 1 );
1272 if (acsicmd_dma(read_cmd
, acsi_buffer
, 1, 0, 0) &&
1273 acsi_wait_for_IRQ(3*HZ
)) {
1274 if (acsi_getstatus()) {
1275 if (acsi_reqsense(acsi_buffer
, aip
->target
, aip
->lun
)) {
1276 if (CARTRCH_STAT(device
, acsi_buffer
))
1280 printk( KERN_ERR
"ad%c: REQUEST SENSE failed in test for "
1281 "medium change; assuming a change\n", device
+ 'a' );
1287 printk( KERN_ERR
"ad%c: Test for medium changed timed out; "
1288 "assuming a change\n", device
+ 'a');
1294 /* Now, after reading a block, the changed status is surely valid. */
1295 return aip
->changed
;
1299 static int acsi_change_blk_size( int target
, int lun
)
1303 for (i
=0; i
<12; i
++)
1307 acsi_buffer
[10] = 2;
1308 CMDSET_TARG_LUN( modeselect_cmd
, target
, lun
);
1310 if (!acsicmd_dma( modeselect_cmd
, acsi_buffer
, 1,1,0) ||
1311 !acsi_wait_for_IRQ( 3*HZ
) ||
1312 acsi_getstatus() != 0 ) {
1319 static int acsi_mode_sense( int target
, int lun
, SENSE_DATA
*sd
)
1324 CMDSET_TARG_LUN( modesense_cmd
, target
, lun
);
1325 for (page
=0; page
<4; page
++) {
1326 modesense_cmd
[2] = page
;
1327 if (!acsicmd_dma( modesense_cmd
, acsi_buffer
, 1, 0, 0 ) ||
1328 !acsi_wait_for_IRQ( 3*HZ
) ||
1332 /* read twice to jump over the second 16-byte border! */
1334 if (acsi_wait_for_noIRQ( 20 ) &&
1335 acsicmd_nodma( modesense_cmd
, 0 ) &&
1336 acsi_wait_for_IRQ( 3*HZ
) &&
1337 acsi_getstatus() == 0)
1344 dma_cache_maintenance( phys_acsi_buffer
, sizeof(SENSE_DATA
), 0 );
1345 *sd
= *(SENSE_DATA
*)acsi_buffer
;
1347 /* Validity check, depending on type of data */
1349 switch( SENSE_TYPE(*sd
) ) {
1351 case SENSE_TYPE_ATARI
:
1352 if (CAPACITY(*sd
) == 0)
1356 case SENSE_TYPE_SCSI
:
1357 if (sd
->scsi
.descriptor_size
!= 8)
1361 case SENSE_TYPE_UNKNOWN
:
1363 printk( KERN_ERR
"ACSI target %d, lun %d: Cannot interpret "
1364 "sense data\n", target
, lun
);
1370 printk( "Mode sense data for ACSI target %d, lun %d seem not valid:",
1372 for( i
= 0; i
< sizeof(SENSE_DATA
); ++i
)
1373 printk( "%02x ", (unsigned char)acsi_buffer
[i
] );
1385 /*******************************************************************
1389 ********************************************************************/
1392 static struct gendisk acsi_gendisk
= {
1393 MAJOR_NR
, /* Major number */
1394 "ad", /* Major name */
1395 4, /* Bits to shift to get real from partition */
1396 1 << 4, /* Number of partitions per real */
1397 MAX_DEV
, /* maximum number of real */
1399 NULL
, /* called from init_module() */
1401 acsi_geninit
, /* init function */
1403 acsi_part
, /* hd struct */
1404 acsi_sizes
, /* block sizes */
1406 (void *)acsi_info
, /* internal */
1410 #define MAX_SCSI_DEVICE_CODE 10
1412 static const char *const scsi_device_types
[MAX_SCSI_DEVICE_CODE
] =
1415 "Sequential-Access",
1426 static void print_inquiry(unsigned char *data
)
1430 printk(KERN_INFO
" Vendor: ");
1431 for (i
= 8; i
< 16; i
++)
1433 if (data
[i
] >= 0x20 && i
< data
[4] + 5)
1434 printk("%c", data
[i
]);
1440 for (i
= 16; i
< 32; i
++)
1442 if (data
[i
] >= 0x20 && i
< data
[4] + 5)
1443 printk("%c", data
[i
]);
1449 for (i
= 32; i
< 36; i
++)
1451 if (data
[i
] >= 0x20 && i
< data
[4] + 5)
1452 printk("%c", data
[i
]);
1461 printk(KERN_INFO
" Type: %s ", (i
< MAX_SCSI_DEVICE_CODE
1462 ? scsi_device_types
[i
]
1464 printk(" ANSI SCSI revision: %02x", data
[2] & 0x07);
1465 if ((data
[2] & 0x07) == 1 && (data
[3] & 0x0f) == 1)
1473 * Changes by Martin Rogge, 9th Aug 1995:
1474 * acsi_devinit has been taken out of acsi_geninit, because it needs
1475 * to be called from revalidate_acsidisk. The result of request sense
1476 * is now checked for DRIVE NOT READY.
1478 * The structure *aip is only valid when acsi_devinit returns
1484 #define DEV_UNKNOWN 1
1485 #define DEV_SUPPORTED 2
1488 static int acsi_devinit(struct acsi_info_struct
*aip
)
1490 int status
, got_inquiry
;
1492 unsigned char reqsense
, extsense
;
1494 /*****************************************************************/
1495 /* Do a TEST UNIT READY command to test the presence of a device */
1496 /*****************************************************************/
1498 CMDSET_TARG_LUN(tur_cmd
, aip
->target
, aip
->lun
);
1499 if (!acsicmd_nodma(tur_cmd
, 0)) {
1500 /* timed out -> no device here */
1502 printk("target %d lun %d: timeout\n", aip
->target
, aip
->lun
);
1507 /*************************/
1508 /* Read the ACSI status. */
1509 /*************************/
1511 status
= acsi_getstatus();
1513 if (status
== 0x12) {
1514 /* The SLM printer should be the only device that
1515 * responds with the error code in the status byte. In
1516 * correct status bytes, bit 4 is never set.
1518 printk( KERN_INFO
"Detected SLM printer at id %d lun %d\n",
1519 aip
->target
, aip
->lun
);
1522 /* ignore CHECK CONDITION, since some devices send a
1524 if ((status
& 0x1e) != 0x2) {
1526 printk("target %d lun %d: status %d\n",
1527 aip
->target
, aip
->lun
, status
);
1533 /*******************************/
1534 /* Do a REQUEST SENSE command. */
1535 /*******************************/
1537 if (!acsi_reqsense(acsi_buffer
, aip
->target
, aip
->lun
)) {
1538 printk( KERN_WARNING
"acsi_reqsense failed\n");
1540 acsi_buffer
[2] = UNIT_ATTENTION
;
1542 reqsense
= acsi_buffer
[0];
1543 extsense
= acsi_buffer
[2] & 0xf;
1545 if ((reqsense
& 0x70) == 0x70) { /* extended sense */
1546 if (extsense
!= UNIT_ATTENTION
&&
1547 extsense
!= NOT_READY
) {
1549 printk("target %d lun %d: extended sense %d\n",
1550 aip
->target
, aip
->lun
, extsense
);
1556 if (reqsense
& 0x7f) {
1558 printk("target %d lun %d: sense %d\n",
1559 aip
->target
, aip
->lun
, reqsense
);
1566 if (reqsense
== 0x4) { /* SH204 Bug workaround */
1568 printk("target %d lun %d status=0 sense=4\n",
1569 aip
->target
, aip
->lun
);
1574 /***********************************************************/
1575 /* Do an INQUIRY command to get more infos on this device. */
1576 /***********************************************************/
1578 /* Assume default values */
1581 aip
->old_atari_disk
= 0;
1582 aip
->changed
= (extsense
== NOT_READY
); /* medium inserted? */
1583 aip
->size
= DEFAULT_SIZE
;
1585 /* Fake inquiry result for old atari disks */
1586 memcpy(acsi_buffer
, "\000\000\001\000 Adaptec 40xx"
1588 CMDSET_TARG_LUN(inquiry_cmd
, aip
->target
, aip
->lun
);
1589 if (acsicmd_dma(inquiry_cmd
, acsi_buffer
, 1, 0, 0) &&
1590 acsi_getstatus() == 0) {
1591 acsicmd_nodma(inquiry_cmd
, 0);
1593 dma_cache_maintenance( phys_acsi_buffer
, 256, 0 );
1595 aip
->removable
= !!(acsi_buffer
[1] & 0x80);
1597 if (aip
->type
== NONE
) /* only at boot time */
1598 print_inquiry(acsi_buffer
);
1599 switch(acsi_buffer
[0]) {
1601 aip
->type
= HARDDISK
;
1610 /****************************/
1611 /* Do a MODE SENSE command. */
1612 /****************************/
1614 if (!acsi_mode_sense(aip
->target
, aip
->lun
, &sense
)) {
1615 printk( KERN_WARNING
"No mode sense data.\n" );
1618 if ((SECTOR_SIZE(sense
) != 512) &&
1619 ((aip
->type
!= CDROM
) ||
1620 !acsi_change_blk_size(aip
->target
, aip
->lun
) ||
1621 !acsi_mode_sense(aip
->target
, aip
->lun
, &sense
) ||
1622 (SECTOR_SIZE(sense
) != 512))) {
1623 printk( KERN_WARNING
"Sector size != 512 not supported.\n" );
1626 /* There are disks out there that claim to have 0 sectors... */
1627 if (CAPACITY(sense
))
1628 aip
->size
= CAPACITY(sense
); /* else keep DEFAULT_SIZE */
1629 if (!got_inquiry
&& SENSE_TYPE(sense
) == SENSE_TYPE_ATARI
) {
1630 /* If INQUIRY failed and the sense data suggest an old
1631 * Atari disk (SH20x, Megafile), the disk is not removable
1634 aip
->old_atari_disk
= 1;
1637 /******************/
1638 /* We've done it. */
1639 /******************/
1641 return DEV_SUPPORTED
;
1644 EXPORT_SYMBOL(acsi_delay_start
);
1645 EXPORT_SYMBOL(acsi_delay_end
);
1646 EXPORT_SYMBOL(acsi_wait_for_IRQ
);
1647 EXPORT_SYMBOL(acsi_wait_for_noIRQ
);
1648 EXPORT_SYMBOL(acsicmd_nodma
);
1649 EXPORT_SYMBOL(acsi_getstatus
);
1650 EXPORT_SYMBOL(acsi_buffer
);
1651 EXPORT_SYMBOL(phys_acsi_buffer
);
1653 #ifdef CONFIG_ATARI_SLM_MODULE
1654 void acsi_attach_SLMs( int (*attach_func
)( int, int ) );
1656 EXPORT_SYMBOL(acsi_extstatus
);
1657 EXPORT_SYMBOL(acsi_end_extstatus
);
1658 EXPORT_SYMBOL(acsi_extcmd
);
1659 EXPORT_SYMBOL(acsi_attach_SLMs
);
1661 /* to remember IDs of SLM devices, SLM module is loaded later
1662 * (index is target#, contents is lun#, -1 means "no SLM") */
1666 static void acsi_geninit( struct gendisk
*gd
)
1669 struct acsi_info_struct
*aip
;
1670 #ifdef CONFIG_ATARI_SLM
1674 printk( KERN_INFO
"Probing ACSI devices:\n" );
1676 #ifdef CONFIG_ATARI_SLM_MODULE
1677 for( i
= 0; i
< 8; ++i
)
1678 SLM_devices
[i
] = -1;
1680 stdma_lock(NULL
, NULL
);
1682 for (target
= 0; target
< 8 && NDevices
< MAX_DEV
; ++target
) {
1685 aip
= &acsi_info
[NDevices
];
1687 aip
->target
= target
;
1689 i
= acsi_devinit(aip
);
1692 printk( KERN_INFO
"Detected ");
1693 switch (aip
->type
) {
1702 printk(" ad%c at id %d lun %d ",
1703 'a' + NDevices
, target
, lun
);
1705 printk("(removable) ");
1707 printk("(read-only) ");
1708 if (aip
->size
== DEFAULT_SIZE
)
1709 printk(" unkown size, using default ");
1710 printk("%ld MByte\n",
1711 (aip
->size
*512+1024*1024/2)/(1024*1024));
1715 #ifdef CONFIG_ATARI_SLM
1716 n_slm
+= attach_slm( target
, lun
);
1719 #ifdef CONFIG_ATARI_SLM_MODULE
1720 SLM_devices
[target
] = lun
;
1723 /* neither of the above: fall through to unknown device */
1725 printk( KERN_INFO
"Detected unsupported device at "
1726 "id %d lun %d\n", target
, lun
);
1730 #ifdef CONFIG_ACSI_MULTI_LUN
1731 while (i
!= DEV_NONE
&& ++lun
< MAX_LUN
);
1737 /* reenable interrupt */
1741 #ifndef CONFIG_ATARI_SLM
1742 printk( KERN_INFO
"Found %d ACSI device(s) total.\n", NDevices
);
1744 printk( KERN_INFO
"Found %d ACSI device(s) and %d SLM printer(s) total.\n",
1748 for( i
= 0; i
< NDevices
; ++i
) {
1749 acsi_part
[i
<<4].start_sect
= 0;
1750 acsi_part
[i
<<4].nr_sects
= acsi_info
[i
].size
;
1752 acsi_gendisk
.nr_real
= NDevices
;
1753 for( i
= 0; i
< (MAX_DEV
<< 4); i
++ )
1754 acsi_blocksizes
[i
] = 1024;
1755 blksize_size
[MAJOR_NR
] = acsi_blocksizes
;
1758 #ifdef CONFIG_ATARI_SLM_MODULE
1759 /* call attach_slm() for each device that is a printer; needed for init of SLM
1760 * driver as a module, since it's not yet present if acsi.c is inited and thus
1761 * the bus gets scanned. */
1762 void acsi_attach_SLMs( int (*attach_func
)( int, int ) )
1766 for( i
= 0; i
< 8; ++i
)
1767 if (SLM_devices
[i
] >= 0)
1768 n
+= (*attach_func
)( i
, SLM_devices
[i
] );
1769 printk( KERN_INFO
"Found %d SLM printer(s) total.\n", n
);
1771 #endif /* CONFIG_ATARI_SLM_MODULE */
1773 static struct file_operations acsi_fops
= {
1774 NULL
, /* lseek - default */
1775 block_read
, /* read - general block-dev read */
1776 block_write
, /* write - general block-dev write */
1777 NULL
, /* readdir - bad */
1779 acsi_ioctl
, /* ioctl */
1781 acsi_open
, /* open */
1783 acsi_release
, /* release */
1784 block_fsync
, /* fsync */
1786 acsi_media_change
, /* media_change */
1787 acsi_revalidate
, /* revalidate */
1791 int acsi_init( void )
1794 if (!MACH_IS_ATARI
|| !ATARIHW_PRESENT(ACSI
))
1797 if (register_blkdev( MAJOR_NR
, "ad", &acsi_fops
)) {
1798 printk( KERN_ERR
"Unable to get major %d for ACSI\n", MAJOR_NR
);
1803 (char *)atari_stram_alloc( ACSI_BUFFER_SIZE
, NULL
, "acsi" ))) {
1804 printk( KERN_ERR
"Unable to get ACSI ST-Ram buffer.\n" );
1805 unregister_blkdev( MAJOR_NR
, "ad" );
1808 phys_acsi_buffer
= virt_to_phys( acsi_buffer
);
1809 STramMask
= ATARIHW_PRESENT(EXTD_DMA
) ? 0x00000000 : 0xff000000;
1811 blk_dev
[MAJOR_NR
].request_fn
= DEVICE_REQUEST
;
1812 read_ahead
[MAJOR_NR
] = 8; /* 8 sector (4kB) read-ahead */
1813 acsi_gendisk
.next
= gendisk_head
;
1814 gendisk_head
= &acsi_gendisk
;
1816 #ifdef CONFIG_ATARI_SLM
1817 return( slm_init() );
1825 int init_module(void)
1829 if ((err
= acsi_init()))
1831 printk( KERN_INFO
"ACSI driver loaded as module.\n");
1832 acsi_geninit( &(struct gendisk
){ 0,0,0,0,0,0,0,0,0,0,0 } );
1836 void cleanup_module(void)
1838 struct gendisk
** gdp
;
1840 del_timer( &acsi_timer
);
1841 blk_dev
[MAJOR_NR
].request_fn
= 0;
1842 atari_stram_free( acsi_buffer
);
1844 if (unregister_blkdev( MAJOR_NR
, "ad" ) != 0)
1845 printk( KERN_ERR
"acsi: cleanup_module failed\n");
1847 for (gdp
= &gendisk_head
; *gdp
; gdp
= &((*gdp
)->next
))
1848 if (*gdp
== &acsi_gendisk
)
1851 printk( KERN_ERR
"acsi: entry in disk chain missing!\n" );
1853 *gdp
= (*gdp
)->next
;
1857 #define DEVICE_BUSY busy[device]
1858 #define USAGE access_count[device]
1859 #define GENDISK_STRUCT acsi_gendisk
1862 * This routine is called to flush all partitions and partition tables
1863 * for a changed scsi disk, and then re-read the new partition table.
1864 * If we are revalidating a disk because of a media change, then we
1865 * enter with usage == 0. If we are using an ioctl, we automatically have
1866 * usage == 1 (we need an open channel to use an ioctl :-), so this
1869 * Changes by Martin Rogge, 9th Aug 1995:
1870 * got cd-roms to work by calling acsi_devinit. There are only two problems:
1871 * First, if there is no medium inserted, the status will remain "changed".
1872 * That is no problem at all, but our design of three-valued logic (medium
1873 * changed, medium not changed, no medium inserted).
1874 * Secondly the check could fail completely and the drive could deliver
1875 * nonsensical data, which could mess up the acsi_info[] structure. In
1876 * that case we try to make the entry safe.
1880 static int revalidate_acsidisk( int dev
, int maxusage
)
1883 struct gendisk
* gdev
;
1884 int max_p
, start
, i
;
1885 struct acsi_info_struct
*aip
;
1887 device
= DEVICE_NR(MINOR(dev
));
1888 aip
= &acsi_info
[device
];
1889 gdev
= &GENDISK_STRUCT
;
1892 if (DEVICE_BUSY
|| USAGE
> maxusage
) {
1899 max_p
= gdev
->max_p
;
1900 start
= device
<< gdev
->minor_shift
;
1902 for( i
= max_p
- 1; i
>= 0 ; i
-- ) {
1903 if (gdev
->part
[start
+ i
].nr_sects
!= 0) {
1904 kdev_t devp
= MKDEV(MAJOR_NR
, start
+ i
);
1905 struct super_block
*sb
= get_super(devp
);
1909 invalidate_inodes(sb
);
1910 invalidate_buffers(devp
);
1911 gdev
->part
[start
+ i
].nr_sects
= 0;
1913 gdev
->part
[start
+i
].start_sect
= 0;
1916 stdma_lock( NULL
, NULL
);
1918 if (acsi_devinit(aip
) != DEV_SUPPORTED
) {
1919 printk( KERN_ERR
"ACSI: revalidate failed for target %d lun %d\n",
1920 aip
->target
, aip
->lun
);
1924 aip
->changed
= 1; /* next acsi_open will try again... */
1930 gdev
->part
[start
].nr_sects
= aip
->size
;
1931 if (aip
->type
== HARDDISK
&& aip
->size
> 0)
1932 resetup_one_dev(gdev
, device
);
1935 wake_up(&busy_wait
);
1940 static int acsi_revalidate (dev_t dev
)
1942 return revalidate_acsidisk (dev
, 0);