2 * linux/drivers/ide/pdc4030.c Version 0.90 May 27, 1999
4 * Copyright (C) 1995-1999 Linus Torvalds & authors (see below)
8 * Principal Author/Maintainer: peterd@pnd-pc.demon.co.uk
10 * This file provides support for the second port and cache of Promise
11 * IDE interfaces, e.g. DC4030VL, DC4030VL-1 and DC4030VL-2.
13 * Thanks are due to Mark Lord for advice and patiently answering stupid
14 * questions, and all those mugs^H^H^H^Hbrave souls who've tested this,
15 * especially Andre Hedrick.
17 * Version 0.01 Initial version, #include'd in ide.c rather than
18 * compiled separately.
19 * Reads use Promise commands, writes as before. Drives
20 * on second channel are read-only.
21 * Version 0.02 Writes working on second channel, reads on both
22 * channels. Writes fail under high load. Suspect
23 * transfers of >127 sectors don't work.
24 * Version 0.03 Brought into line with ide.c version 5.27.
25 * Other minor changes.
26 * Version 0.04 Updated for ide.c version 5.30
27 * Changed initialization strategy
28 * Version 0.05 Kernel integration. -ml
29 * Version 0.06 Ooops. Add hwgroup to direct call of ide_intr() -ml
30 * Version 0.07 Added support for DC4030 variants
31 * Secondary interface autodetection
32 * Version 0.08 Renamed to pdc4030.c
33 * Version 0.09 Obsolete - never released - did manual write request
34 * splitting before max_sectors[major][minor] available.
35 * Version 0.10 Updated for 2.1 series of kernels
36 * Version 0.11 Updated for 2.3 series of kernels
37 * Autodetection code added.
39 * Version 0.90 Transition to BETA code. No lost/unexpected interrupts
43 * Once you've compiled it in, you'll have to also enable the interface
44 * setup routine from the kernel command line, as in
46 * 'linux ide0=dc4030' or 'linux ide1=dc4030'
48 * It should now work as a second controller also ('ide1=dc4030') but only
49 * if you DON'T have BIOS V4.44, which has a bug. If you have this version
50 * and EPROM programming facilities, you need to fix 4 bytes:
65 * As of January 1999, Promise Technology Inc. have finally supplied me with
66 * some technical information which has shed a glimmer of light on some of the
67 * problems I was having, especially with writes.
69 * There are still problems with the robustness and efficiency of this driver
70 * because I still don't understand what the card is doing with interrupts.
76 #include <linux/types.h>
77 #include <linux/kernel.h>
78 #include <linux/delay.h>
79 #include <linux/timer.h>
81 #include <linux/ioport.h>
82 #include <linux/blkdev.h>
83 #include <linux/hdreg.h>
84 #include <linux/ide.h>
92 * promise_selectproc() is invoked by ide.c
93 * in preparation for access to the specified drive.
95 static void promise_selectproc (ide_drive_t
*drive
)
99 number
= (HWIF(drive
)->channel
<< 1) + drive
->select
.b
.unit
;
100 OUT_BYTE(number
,IDE_FEATURE_REG
);
104 * pdc4030_cmd handles the set of vendor specific commands that are initiated
105 * by command F0. They all have the same success/failure notification -
106 * 'P' (=0x50) on success, 'p' (=0x70) on failure.
108 int pdc4030_cmd(ide_drive_t
*drive
, byte cmd
)
110 unsigned long timeout
, timer
;
113 promise_selectproc(drive
); /* redundant? */
114 OUT_BYTE(0xF3,IDE_SECTOR_REG
);
115 OUT_BYTE(cmd
,IDE_SELECT_REG
);
116 OUT_BYTE(PROMISE_EXTENDED_COMMAND
,IDE_COMMAND_REG
);
120 if(time_after(jiffies
, timeout
)) {
121 return 2; /* device timed out */
123 /* This is out of delay_10ms() */
124 /* Delays at least 10ms to give interface a chance */
125 timer
= jiffies
+ (HZ
+ 99)/100 + 1;
126 while (time_after(timer
, jiffies
));
127 status_val
= IN_BYTE(IDE_SECTOR_REG
);
128 } while (status_val
!= 0x50 && status_val
!= 0x70);
130 if(status_val
== 0x50)
131 return 0; /* device returned success */
133 return 1; /* device returned failure */
137 * pdc4030_identify sends a vendor-specific IDENTIFY command to the drive
139 int pdc4030_identify(ide_drive_t
*drive
)
141 return pdc4030_cmd(drive
, PROMISE_IDENTIFY
);
144 int enable_promise_support
= 0;
146 void __init
init_pdc4030 (void)
148 enable_promise_support
= 1;
153 * Completes the setup of a Promise DC4030 controller card, once found.
155 int __init
setup_pdc4030 (ide_hwif_t
*hwif
)
159 struct dc_ident ident
;
161 ide_startstop_t startstop
;
165 drive
= &hwif
->drives
[0];
166 hwif2
= &ide_hwifs
[hwif
->index
+1];
167 if (hwif
->chipset
== ide_pdc4030
) /* we've already been found ! */
170 if (IN_BYTE(IDE_NSECTOR_REG
) == 0xFF || IN_BYTE(IDE_SECTOR_REG
) == 0xFF) {
174 OUT_BYTE(0x08,IDE_CONTROL_REG
);
175 if (pdc4030_cmd(drive
,PROMISE_GET_CONFIG
)) {
178 if (ide_wait_stat(&startstop
, drive
,DATA_READY
,BAD_W_STAT
,WAIT_DRQ
)) {
180 "%s: Failed Promise read config!\n",hwif
->name
);
183 ide_input_data(drive
,&ident
,SECTOR_WORDS
);
184 if (ident
.id
[1] != 'P' || ident
.id
[0] != 'T') {
187 printk(KERN_INFO
"%s: Promise caching controller, ",hwif
->name
);
189 case 0x43: printk("DC4030VL-2, "); break;
190 case 0x41: printk("DC4030VL-1, "); break;
191 case 0x40: printk("DC4030VL, "); break;
193 printk("unknown - type 0x%02x - please report!\n"
195 printk("Please e-mail the following data to "
196 "promise@pnd-pc.demon.co.uk along with\n"
197 "a description of your card and drives:\n");
198 for (i
=0; i
< 0x90; i
++) {
199 printk("%02x ", ((unsigned char *)&ident
)[i
]);
200 if ((i
& 0x0f) == 0x0f) printk("\n");
204 printk("%dKB cache, ",(int)ident
.cache_mem
);
206 case 0x00: hwif
->irq
= 14; break;
207 case 0x01: hwif
->irq
= 12; break;
208 default: hwif
->irq
= 15; break;
210 printk("on IRQ %d\n",hwif
->irq
);
213 * Once found and identified, we set up the next hwif in the array
214 * (hwif2 = ide_hwifs[hwif->index+1]) with the same io ports, irq
215 * and other settings as the main hwif. This gives us two "mated"
216 * hwifs pointing to the Promise card.
218 * We also have to shift the default values for the remaining
219 * interfaces "up by one" to make room for the second interface on the
220 * same set of values.
223 hwif
->chipset
= hwif2
->chipset
= ide_pdc4030
;
227 hwif
->selectproc
= hwif2
->selectproc
= &promise_selectproc
;
228 hwif
->serialized
= hwif2
->serialized
= 1;
230 /* Shift the remaining interfaces down by one */
231 for (i
=MAX_HWIFS
-1 ; i
> hwif
->index
+1 ; i
--) {
232 ide_hwif_t
*h
= &ide_hwifs
[i
];
235 printk(KERN_DEBUG
"Shifting i/f %d values to i/f %d\n",i
-1,i
);
237 ide_init_hwif_ports(&h
->hw
, (h
-1)->io_ports
[IDE_DATA_OFFSET
], 0, NULL
);
238 memcpy(h
->io_ports
, h
->hw
.io_ports
, sizeof(h
->io_ports
));
239 h
->noprobe
= (h
-1)->noprobe
;
241 ide_init_hwif_ports(&hwif2
->hw
, hwif
->io_ports
[IDE_DATA_OFFSET
], 0, NULL
);
242 memcpy(hwif2
->io_ports
, hwif
->hw
.io_ports
, sizeof(hwif2
->io_ports
));
243 hwif2
->irq
= hwif
->irq
;
244 hwif2
->hw
.irq
= hwif
->hw
.irq
= hwif
->irq
;
245 for (i
=0; i
<2 ; i
++) {
246 hwif
->drives
[i
].io_32bit
= 3;
247 hwif2
->drives
[i
].io_32bit
= 3;
248 hwif
->drives
[i
].keep_settings
= 1;
249 hwif2
->drives
[i
].keep_settings
= 1;
250 if (!ident
.current_tm
[i
].cyl
)
251 hwif
->drives
[i
].noprobe
= 1;
252 if (!ident
.current_tm
[i
+2].cyl
)
253 hwif2
->drives
[i
].noprobe
= 1;
260 * Tests for the presence of a DC4030 Promise card on this interface
261 * Returns: 1 if found, 0 if not found
263 int __init
detect_pdc4030(ide_hwif_t
*hwif
)
265 ide_drive_t
*drive
= &hwif
->drives
[0];
267 if (IDE_DATA_REG
== 0) { /* Skip test for non-existent interface */
270 OUT_BYTE(0xF3, IDE_SECTOR_REG
);
271 OUT_BYTE(0x14, IDE_SELECT_REG
);
272 OUT_BYTE(PROMISE_EXTENDED_COMMAND
, IDE_COMMAND_REG
);
276 if (IN_BYTE(IDE_ERROR_REG
) == 'P' &&
277 IN_BYTE(IDE_NSECTOR_REG
) == 'T' &&
278 IN_BYTE(IDE_SECTOR_REG
) == 'I') {
285 void __init
ide_probe_for_pdc4030(void)
290 if (enable_promise_support
== 0)
292 for (index
= 0; index
< MAX_HWIFS
; index
++) {
293 hwif
= &ide_hwifs
[index
];
294 if (hwif
->chipset
== ide_unknown
&& detect_pdc4030(hwif
)) {
303 * promise_read_intr() is the handler for disk read/multread interrupts
305 static ide_startstop_t
promise_read_intr (ide_drive_t
*drive
)
309 unsigned int sectors_left
, sectors_avail
, nsect
;
312 if (!OK_STAT(stat
=GET_STAT(),DATA_READY
,BAD_R_STAT
)) {
313 return ide_error(drive
, "promise_read_intr", stat
);
318 sectors_left
= IN_BYTE(IDE_NSECTOR_REG
);
319 IN_BYTE(IDE_SECTOR_REG
);
320 } while (IN_BYTE(IDE_NSECTOR_REG
) != sectors_left
);
321 rq
= HWGROUP(drive
)->rq
;
322 sectors_avail
= rq
->nr_sectors
- sectors_left
;
327 rq
= HWGROUP(drive
)->rq
;
328 nsect
= rq
->current_nr_sectors
;
329 if (nsect
> sectors_avail
)
330 nsect
= sectors_avail
;
331 sectors_avail
-= nsect
;
332 ide_input_data(drive
, rq
->buffer
, nsect
* SECTOR_WORDS
);
334 printk(KERN_DEBUG
"%s: promise_read: sectors(%ld-%ld), "
335 "buf=0x%08lx, rem=%ld\n", drive
->name
, rq
->sector
,
336 rq
->sector
+nsect
-1, (unsigned long) rq
->buffer
,
337 rq
->nr_sectors
-nsect
);
340 rq
->buffer
+= nsect
<<9;
342 rq
->nr_sectors
-= nsect
;
343 total_remaining
= rq
->nr_sectors
;
344 if ((rq
->current_nr_sectors
-= nsect
) <= 0) {
345 ide_end_request(1, HWGROUP(drive
));
348 * Now the data has been read in, do the following:
350 * if there are still sectors left in the request,
351 * if we know there are still sectors available from the interface,
352 * go back and read the next bit of the request.
353 * else if DRQ is asserted, there are more sectors available, so
354 * go back and find out how many, then read them in.
355 * else if BUSY is asserted, we are going to get an interrupt, so
356 * set the handler for the interrupt and just return
358 if (total_remaining
> 0) {
364 if (stat
& BUSY_STAT
) {
365 ide_set_handler (drive
, &promise_read_intr
, WAIT_CMD
, NULL
);
367 printk(KERN_DEBUG
"%s: promise_read: waiting for"
368 "interrupt\n", drive
->name
);
372 printk(KERN_ERR
"%s: Eeek! promise_read_intr: sectors left "
373 "!DRQ !BUSY\n", drive
->name
);
374 return ide_error(drive
, "promise read intr", stat
);
380 * promise_complete_pollfunc()
381 * This is the polling function for waiting (nicely!) until drive stops
382 * being busy. It is invoked at the end of a write, after the previous poll
385 * Once not busy, the end request is called.
387 static ide_startstop_t
promise_complete_pollfunc(ide_drive_t
*drive
)
389 ide_hwgroup_t
*hwgroup
= HWGROUP(drive
);
390 struct request
*rq
= hwgroup
->rq
;
393 if (GET_STAT() & BUSY_STAT
) {
394 if (time_before(jiffies
, hwgroup
->poll_timeout
)) {
395 ide_set_handler(drive
, &promise_complete_pollfunc
, HZ
/100, NULL
);
396 return ide_started
; /* continue polling... */
398 hwgroup
->poll_timeout
= 0;
399 printk(KERN_ERR
"%s: completion timeout - still busy!\n",
401 return ide_error(drive
, "busy timeout", GET_STAT());
404 hwgroup
->poll_timeout
= 0;
406 printk(KERN_DEBUG
"%s: Write complete - end_request\n", drive
->name
);
408 for (i
= rq
->nr_sectors
; i
> 0; ) {
409 i
-= rq
->current_nr_sectors
;
410 ide_end_request(1, hwgroup
);
416 * promise_write_pollfunc() is the handler for disk write completion polling.
418 static ide_startstop_t
promise_write_pollfunc (ide_drive_t
*drive
)
420 ide_hwgroup_t
*hwgroup
= HWGROUP(drive
);
422 if (IN_BYTE(IDE_NSECTOR_REG
) != 0) {
423 if (time_before(jiffies
, hwgroup
->poll_timeout
)) {
424 ide_set_handler (drive
, &promise_write_pollfunc
, HZ
/100, NULL
);
425 return ide_started
; /* continue polling... */
427 hwgroup
->poll_timeout
= 0;
428 printk(KERN_ERR
"%s: write timed-out!\n",drive
->name
);
429 return ide_error (drive
, "write timeout", GET_STAT());
433 * Now write out last 4 sectors and poll for not BUSY
435 ide_multwrite(drive
, 4);
436 hwgroup
->poll_timeout
= jiffies
+ WAIT_WORSTCASE
;
437 ide_set_handler(drive
, &promise_complete_pollfunc
, HZ
/100, NULL
);
439 printk(KERN_DEBUG
"%s: Done last 4 sectors - status = %02x\n",
440 drive
->name
, GET_STAT());
446 * promise_write() transfers a block of one or more sectors of data to a
447 * drive as part of a disk write operation. All but 4 sectors are transfered
448 * in the first attempt, then the interface is polled (nicely!) for completion
449 * before the final 4 sectors are transfered. There is no interrupt generated
450 * on writes (at least on the DC4030VL-2), we just have to poll for NOT BUSY.
452 static ide_startstop_t
promise_write (ide_drive_t
*drive
)
454 ide_hwgroup_t
*hwgroup
= HWGROUP(drive
);
455 struct request
*rq
= &hwgroup
->wrq
;
458 printk(KERN_DEBUG
"%s: promise_write: sectors(%ld-%ld), "
459 "buffer=0x%08x\n", drive
->name
, rq
->sector
,
460 rq
->sector
+ rq
->nr_sectors
- 1, (unsigned int)rq
->buffer
);
464 * If there are more than 4 sectors to transfer, do n-4 then go into
465 * the polling strategy as defined above.
467 if (rq
->nr_sectors
> 4) {
468 if (ide_multwrite(drive
, rq
->nr_sectors
- 4))
470 hwgroup
->poll_timeout
= jiffies
+ WAIT_WORSTCASE
;
471 ide_set_handler (drive
, &promise_write_pollfunc
, HZ
/100, NULL
);
475 * There are 4 or fewer sectors to transfer, do them all in one go
476 * and wait for NOT BUSY.
478 if (ide_multwrite(drive
, rq
->nr_sectors
))
480 hwgroup
->poll_timeout
= jiffies
+ WAIT_WORSTCASE
;
481 ide_set_handler(drive
, &promise_complete_pollfunc
, HZ
/100, NULL
);
483 printk(KERN_DEBUG
"%s: promise_write: <= 4 sectors, "
484 "status = %02x\n", drive
->name
, GET_STAT());
491 * do_pdc4030_io() is called from do_rw_disk, having had the block number
492 * already set up. It issues a READ or WRITE command to the Promise
493 * controller, assuming LBA has been used to set up the block number.
495 ide_startstop_t
do_pdc4030_io (ide_drive_t
*drive
, struct request
*rq
)
497 unsigned long timeout
;
500 if (rq
->cmd
== READ
) {
501 OUT_BYTE(PROMISE_READ
, IDE_COMMAND_REG
);
503 * The card's behaviour is odd at this point. If the data is
504 * available, DRQ will be true, and no interrupt will be
505 * generated by the card. If this is the case, we need to call the
506 * "interrupt" handler (promise_read_intr) directly. Otherwise, if
507 * an interrupt is going to occur, bit0 of the SELECT register will
508 * be high, so we can set the handler the just return and be interrupted.
509 * If neither of these is the case, we wait for up to 50ms (badly I'm
510 * afraid!) until one of them is.
512 timeout
= jiffies
+ HZ
/20; /* 50ms wait */
515 if (stat
& DRQ_STAT
) {
517 return promise_read_intr(drive
);
519 if (IN_BYTE(IDE_SELECT_REG
) & 0x01) {
521 printk(KERN_DEBUG
"%s: read: waiting for "
522 "interrupt\n", drive
->name
);
524 ide_set_handler(drive
, &promise_read_intr
, WAIT_CMD
, NULL
);
528 } while (time_before(jiffies
, timeout
));
530 printk(KERN_ERR
"%s: reading: No DRQ and not waiting - Odd!\n",
533 } else if (rq
->cmd
== WRITE
) {
534 ide_startstop_t startstop
;
535 OUT_BYTE(PROMISE_WRITE
, IDE_COMMAND_REG
);
536 if (ide_wait_stat(&startstop
, drive
, DATA_READY
, drive
->bad_wstat
, WAIT_DRQ
)) {
537 printk(KERN_ERR
"%s: no DRQ after issuing "
538 "PROMISE_WRITE\n", drive
->name
);
542 __cli(); /* local CPU only */
543 HWGROUP(drive
)->wrq
= *rq
; /* scratchpad */
544 return promise_write(drive
);
547 printk("KERN_WARNING %s: bad command: %d\n",
548 drive
->name
, rq
->cmd
);
549 ide_end_request(0, HWGROUP(drive
));