diff options
Diffstat (limited to 'drivers/ide')
73 files changed, 50372 insertions, 0 deletions
diff --git a/drivers/ide/Kconfig b/drivers/ide/Kconfig new file mode 100644 index 000000000000..3ac0a535b4aa --- /dev/null +++ b/drivers/ide/Kconfig | |||
@@ -0,0 +1,1056 @@ | |||
1 | # | ||
2 | # IDE ATA ATAPI Block device driver configuration | ||
3 | # | ||
4 | # Andre Hedrick <andre@linux-ide.org> | ||
5 | # | ||
6 | |||
7 | menu "ATA/ATAPI/MFM/RLL support" | ||
8 | |||
9 | config IDE | ||
10 | tristate "ATA/ATAPI/MFM/RLL support" | ||
11 | ---help--- | ||
12 | If you say Y here, your kernel will be able to manage low cost mass | ||
13 | storage units such as ATA/(E)IDE and ATAPI units. The most common | ||
14 | cases are IDE hard drives and ATAPI CD-ROM drives. | ||
15 | |||
16 | If your system is pure SCSI and doesn't use these interfaces, you | ||
17 | can say N here. | ||
18 | |||
19 | Integrated Disk Electronics (IDE aka ATA-1) is a connecting standard | ||
20 | for mass storage units such as hard disks. It was designed by | ||
21 | Western Digital and Compaq Computer in 1984. It was then named | ||
22 | ST506. Quite a number of disks use the IDE interface. | ||
23 | |||
24 | AT Attachment (ATA) is the superset of the IDE specifications. | ||
25 | ST506 was also called ATA-1. | ||
26 | |||
27 | Fast-IDE is ATA-2 (also named Fast ATA), Enhanced IDE (EIDE) is | ||
28 | ATA-3. It provides support for larger disks (up to 8.4GB by means of | ||
29 | the LBA standard), more disks (4 instead of 2) and for other mass | ||
30 | storage units such as tapes and cdrom. UDMA/33 (aka UltraDMA/33) is | ||
31 | ATA-4 and provides faster (and more CPU friendly) transfer modes | ||
32 | than previous PIO (Programmed processor Input/Output) from previous | ||
33 | ATA/IDE standards by means of fast DMA controllers. | ||
34 | |||
35 | ATA Packet Interface (ATAPI) is a protocol used by EIDE tape and | ||
36 | CD-ROM drives, similar in many respects to the SCSI protocol. | ||
37 | |||
38 | SMART IDE (Self Monitoring, Analysis and Reporting Technology) was | ||
39 | designed in order to prevent data corruption and disk crash by | ||
40 | detecting pre hardware failure conditions (heat, access time, and | ||
41 | the like...). Disks built since June 1995 may follow this standard. | ||
42 | The kernel itself doesn't manage this; however there are quite a | ||
43 | number of user programs such as smart that can query the status of | ||
44 | SMART parameters from disk drives. | ||
45 | |||
46 | To compile this driver as a module, choose M here: the | ||
47 | module will be called ide. | ||
48 | |||
49 | For further information, please read <file:Documentation/ide.txt>. | ||
50 | |||
51 | If unsure, say Y. | ||
52 | |||
53 | if IDE | ||
54 | |||
55 | config IDE_MAX_HWIFS | ||
56 | int "Max IDE interfaces" | ||
57 | depends on ALPHA || SUPERH | ||
58 | default 4 | ||
59 | help | ||
60 | This is the maximum number of IDE hardware interfaces that will | ||
61 | be supported by the driver. Make sure it is at least as high as | ||
62 | the number of IDE interfaces in your system. | ||
63 | |||
64 | config BLK_DEV_IDE | ||
65 | tristate "Enhanced IDE/MFM/RLL disk/cdrom/tape/floppy support" | ||
66 | ---help--- | ||
67 | If you say Y here, you will use the full-featured IDE driver to | ||
68 | control up to ten ATA/IDE interfaces, each being able to serve a | ||
69 | "master" and a "slave" device, for a total of up to twenty ATA/IDE | ||
70 | disk/cdrom/tape/floppy drives. | ||
71 | |||
72 | Useful information about large (>540 MB) IDE disks, multiple | ||
73 | interfaces, what to do if ATA/IDE devices are not automatically | ||
74 | detected, sound card ATA/IDE ports, module support, and other | ||
75 | topics, is contained in <file:Documentation/ide.txt>. For detailed | ||
76 | information about hard drives, consult the Disk-HOWTO and the | ||
77 | Multi-Disk-HOWTO, available from | ||
78 | <http://www.tldp.org/docs.html#howto>. | ||
79 | |||
80 | To fine-tune ATA/IDE drive/interface parameters for improved | ||
81 | performance, look for the hdparm package at | ||
82 | <ftp://ibiblio.org/pub/Linux/system/hardware/>. | ||
83 | |||
84 | To compile this driver as a module, choose M here and read | ||
85 | <file:Documentation/ide.txt>. The module will be called ide-mod. | ||
86 | Do not compile this driver as a module if your root file system (the | ||
87 | one containing the directory /) is located on an IDE device. | ||
88 | |||
89 | If you have one or more IDE drives, say Y or M here. If your system | ||
90 | has no IDE drives, or if memory requirements are really tight, you | ||
91 | could say N here, and select the "Old hard disk driver" below | ||
92 | instead to save about 13 KB of memory in the kernel. | ||
93 | |||
94 | if BLK_DEV_IDE | ||
95 | |||
96 | comment "Please see Documentation/ide.txt for help/info on IDE drives" | ||
97 | |||
98 | config BLK_DEV_IDE_SATA | ||
99 | bool "Support for SATA (deprecated; conflicts with libata SATA driver)" | ||
100 | default n | ||
101 | ---help--- | ||
102 | There are two drivers for Serial ATA controllers. | ||
103 | |||
104 | The main driver, "libata", exists inside the SCSI subsystem | ||
105 | and supports most modern SATA controllers. | ||
106 | |||
107 | The IDE driver (which you are currently configuring) supports | ||
108 | a few first-generation SATA controllers. | ||
109 | |||
110 | In order to eliminate conflicts between the two subsystems, | ||
111 | this config option enables the IDE driver's SATA support. | ||
112 | Normally this is disabled, as it is preferred that libata | ||
113 | supports SATA controllers, and this (IDE) driver supports | ||
114 | PATA controllers. | ||
115 | |||
116 | If unsure, say N. | ||
117 | |||
118 | config BLK_DEV_HD_IDE | ||
119 | bool "Use old disk-only driver on primary interface" | ||
120 | depends on (X86 || SH_MPC1211) | ||
121 | ---help--- | ||
122 | There are two drivers for MFM/RLL/IDE disks. Most people use just | ||
123 | the new enhanced driver by itself. This option however installs the | ||
124 | old hard disk driver to control the primary IDE/disk interface in | ||
125 | the system, leaving the new enhanced IDE driver to take care of only | ||
126 | the 2nd/3rd/4th IDE interfaces. Doing this will prevent you from | ||
127 | having an IDE/ATAPI CD-ROM or tape drive connected to the primary | ||
128 | IDE interface. Choosing this option may be useful for older systems | ||
129 | which have MFM/RLL/ESDI controller+drives at the primary port | ||
130 | address (0x1f0), along with IDE drives at the secondary/3rd/4th port | ||
131 | addresses. | ||
132 | |||
133 | Normally, just say N here; you will then use the new driver for all | ||
134 | 4 interfaces. | ||
135 | |||
136 | config BLK_DEV_IDEDISK | ||
137 | tristate "Include IDE/ATA-2 DISK support" | ||
138 | ---help--- | ||
139 | This will include enhanced support for MFM/RLL/IDE hard disks. If | ||
140 | you have a MFM/RLL/IDE disk, and there is no special reason to use | ||
141 | the old hard disk driver instead, say Y. If you have an SCSI-only | ||
142 | system, you can say N here. | ||
143 | |||
144 | To compile this driver as a module, choose M here: the | ||
145 | module will be called ide-disk. | ||
146 | Do not compile this driver as a module if your root file system | ||
147 | (the one containing the directory /) is located on the IDE disk. | ||
148 | |||
149 | If unsure, say Y. | ||
150 | |||
151 | config IDEDISK_MULTI_MODE | ||
152 | bool "Use multi-mode by default" | ||
153 | help | ||
154 | If you get this error, try to say Y here: | ||
155 | |||
156 | hda: set_multmode: status=0x51 { DriveReady SeekComplete Error } | ||
157 | hda: set_multmode: error=0x04 { DriveStatusError } | ||
158 | |||
159 | If in doubt, say N. | ||
160 | |||
161 | config BLK_DEV_IDECS | ||
162 | tristate "PCMCIA IDE support" | ||
163 | depends on PCMCIA | ||
164 | help | ||
165 | Support for outboard IDE disks, tape drives, and CD-ROM drives | ||
166 | connected through a PCMCIA card. | ||
167 | |||
168 | config BLK_DEV_IDECD | ||
169 | tristate "Include IDE/ATAPI CDROM support" | ||
170 | ---help--- | ||
171 | If you have a CD-ROM drive using the ATAPI protocol, say Y. ATAPI is | ||
172 | a newer protocol used by IDE CD-ROM and TAPE drives, similar to the | ||
173 | SCSI protocol. Most new CD-ROM drives use ATAPI, including the | ||
174 | NEC-260, Mitsumi FX400, Sony 55E, and just about all non-SCSI | ||
175 | double(2X) or better speed drives. | ||
176 | |||
177 | If you say Y here, the CD-ROM drive will be identified at boot time | ||
178 | along with other IDE devices, as "hdb" or "hdc", or something | ||
179 | similar (check the boot messages with dmesg). If this is your only | ||
180 | CD-ROM drive, you can say N to all other CD-ROM options, but be sure | ||
181 | to say Y or M to "ISO 9660 CD-ROM file system support". | ||
182 | |||
183 | Note that older versions of LILO (LInux LOader) cannot properly deal | ||
184 | with IDE/ATAPI CD-ROMs, so install LILO 16 or higher, available from | ||
185 | <http://lilo.go.dyndns.org/>. | ||
186 | |||
187 | To compile this driver as a module, choose M here: the | ||
188 | module will be called ide-cd. | ||
189 | |||
190 | config BLK_DEV_IDETAPE | ||
191 | tristate "Include IDE/ATAPI TAPE support (EXPERIMENTAL)" | ||
192 | depends on EXPERIMENTAL | ||
193 | help | ||
194 | If you have an IDE tape drive using the ATAPI protocol, say Y. | ||
195 | ATAPI is a newer protocol used by IDE tape and CD-ROM drives, | ||
196 | similar to the SCSI protocol. If you have an SCSI tape drive | ||
197 | however, you can say N here. | ||
198 | |||
199 | You should also say Y if you have an OnStream DI-30 tape drive; this | ||
200 | will not work with the SCSI protocol, until there is support for the | ||
201 | SC-30 and SC-50 versions. | ||
202 | |||
203 | If you say Y here, the tape drive will be identified at boot time | ||
204 | along with other IDE devices, as "hdb" or "hdc", or something | ||
205 | similar, and will be mapped to a character device such as "ht0" | ||
206 | (check the boot messages with dmesg). Be sure to consult the | ||
207 | <file:drivers/ide/ide-tape.c> and <file:Documentation/ide.txt> files | ||
208 | for usage information. | ||
209 | |||
210 | To compile this driver as a module, choose M here: the | ||
211 | module will be called ide-tape. | ||
212 | |||
213 | config BLK_DEV_IDEFLOPPY | ||
214 | tristate "Include IDE/ATAPI FLOPPY support" | ||
215 | ---help--- | ||
216 | If you have an IDE floppy drive which uses the ATAPI protocol, | ||
217 | answer Y. ATAPI is a newer protocol used by IDE CD-ROM/tape/floppy | ||
218 | drives, similar to the SCSI protocol. | ||
219 | |||
220 | The LS-120 and the IDE/ATAPI Iomega ZIP drive are also supported by | ||
221 | this driver. For information about jumper settings and the question | ||
222 | of when a ZIP drive uses a partition table, see | ||
223 | <http://www.win.tue.nl/~aeb/linux/zip/zip-1.html>. | ||
224 | (ATAPI PD-CD/CDR drives are not supported by this driver; support | ||
225 | for PD-CD/CDR drives is available if you answer Y to | ||
226 | "SCSI emulation support", below). | ||
227 | |||
228 | If you say Y here, the FLOPPY drive will be identified along with | ||
229 | other IDE devices, as "hdb" or "hdc", or something similar (check | ||
230 | the boot messages with dmesg). | ||
231 | |||
232 | To compile this driver as a module, choose M here: the | ||
233 | module will be called ide-floppy. | ||
234 | |||
235 | config BLK_DEV_IDESCSI | ||
236 | tristate "SCSI emulation support" | ||
237 | depends on SCSI | ||
238 | ---help--- | ||
239 | WARNING: ide-scsi is no longer needed for cd writing applications! | ||
240 | The 2.6 kernel supports direct writing to ide-cd, which eliminates | ||
241 | the need for ide-scsi + the entire scsi stack just for writing a | ||
242 | cd. The new method is more efficient in every way. | ||
243 | |||
244 | This will provide SCSI host adapter emulation for IDE ATAPI devices, | ||
245 | and will allow you to use a SCSI device driver instead of a native | ||
246 | ATAPI driver. | ||
247 | |||
248 | This is useful if you have an ATAPI device for which no native | ||
249 | driver has been written (for example, an ATAPI PD-CD drive); | ||
250 | you can then use this emulation together with an appropriate SCSI | ||
251 | device driver. In order to do this, say Y here and to "SCSI support" | ||
252 | and "SCSI generic support", below. You must then provide the kernel | ||
253 | command line "hdx=ide-scsi" (try "man bootparam" or see the | ||
254 | documentation of your boot loader (lilo or loadlin) about how to | ||
255 | pass options to the kernel at boot time) for devices if you want the | ||
256 | native EIDE sub-drivers to skip over the native support, so that | ||
257 | this SCSI emulation can be used instead. | ||
258 | |||
259 | Note that this option does NOT allow you to attach SCSI devices to a | ||
260 | box that doesn't have a SCSI host adapter installed. | ||
261 | |||
262 | If both this SCSI emulation and native ATAPI support are compiled | ||
263 | into the kernel, the native support will be used. | ||
264 | |||
265 | config IDE_TASK_IOCTL | ||
266 | bool "IDE Taskfile Access" | ||
267 | help | ||
268 | This is a direct raw access to the media. It is a complex but | ||
269 | elegant solution to test and validate the domain of the hardware and | ||
270 | perform below the driver data recover if needed. This is the most | ||
271 | basic form of media-forensics. | ||
272 | |||
273 | If you are unsure, say N here. | ||
274 | |||
275 | comment "IDE chipset support/bugfixes" | ||
276 | |||
277 | config IDE_GENERIC | ||
278 | tristate "generic/default IDE chipset support" | ||
279 | default y | ||
280 | help | ||
281 | If unsure, say Y. | ||
282 | |||
283 | config BLK_DEV_CMD640 | ||
284 | bool "CMD640 chipset bugfix/support" | ||
285 | depends on X86 | ||
286 | ---help--- | ||
287 | The CMD-Technologies CMD640 IDE chip is used on many common 486 and | ||
288 | Pentium motherboards, usually in combination with a "Neptune" or | ||
289 | "SiS" chipset. Unfortunately, it has a number of rather nasty | ||
290 | design flaws that can cause severe data corruption under many common | ||
291 | conditions. Say Y here to include code which tries to automatically | ||
292 | detect and correct the problems under Linux. This option also | ||
293 | enables access to the secondary IDE ports in some CMD640 based | ||
294 | systems. | ||
295 | |||
296 | This driver will work automatically in PCI based systems (most new | ||
297 | systems have PCI slots). But if your system uses VESA local bus | ||
298 | (VLB) instead of PCI, you must also supply a kernel boot parameter | ||
299 | to enable the CMD640 bugfix/support: "ide0=cmd640_vlb". (Try "man | ||
300 | bootparam" or see the documentation of your boot loader about how to | ||
301 | pass options to the kernel.) | ||
302 | |||
303 | The CMD640 chip is also used on add-in cards by Acculogic, and on | ||
304 | the "CSA-6400E PCI to IDE controller" that some people have. For | ||
305 | details, read <file:Documentation/ide.txt>. | ||
306 | |||
307 | config BLK_DEV_CMD640_ENHANCED | ||
308 | bool "CMD640 enhanced support" | ||
309 | depends on BLK_DEV_CMD640 | ||
310 | help | ||
311 | This option includes support for setting/autotuning PIO modes and | ||
312 | prefetch on CMD640 IDE interfaces. For details, read | ||
313 | <file:Documentation/ide.txt>. If you have a CMD640 IDE interface | ||
314 | and your BIOS does not already do this for you, then say Y here. | ||
315 | Otherwise say N. | ||
316 | |||
317 | config BLK_DEV_IDEPNP | ||
318 | bool "PNP EIDE support" | ||
319 | depends on PNP | ||
320 | help | ||
321 | If you have a PnP (Plug and Play) compatible EIDE card and | ||
322 | would like the kernel to automatically detect and activate | ||
323 | it, say Y here. | ||
324 | |||
325 | config BLK_DEV_IDEPCI | ||
326 | bool "PCI IDE chipset support" if PCI | ||
327 | default BLK_DEV_IDEDMA_PMAC if PPC_PMAC && BLK_DEV_IDEDMA_PMAC | ||
328 | help | ||
329 | Say Y here for PCI systems which use IDE drive(s). | ||
330 | This option helps the IDE driver to automatically detect and | ||
331 | configure all PCI-based IDE interfaces in your system. | ||
332 | |||
333 | config IDEPCI_SHARE_IRQ | ||
334 | bool "Sharing PCI IDE interrupts support" | ||
335 | depends on PCI && BLK_DEV_IDEPCI | ||
336 | help | ||
337 | Some ATA/IDE chipsets have hardware support which allows for | ||
338 | sharing a single IRQ with other cards. To enable support for | ||
339 | this in the ATA/IDE driver, say Y here. | ||
340 | |||
341 | It is safe to say Y to this question, in most cases. | ||
342 | If unsure, say N. | ||
343 | |||
344 | config BLK_DEV_OFFBOARD | ||
345 | bool "Boot off-board chipsets first support" | ||
346 | depends on PCI && BLK_DEV_IDEPCI | ||
347 | help | ||
348 | Normally, IDE controllers built into the motherboard (on-board | ||
349 | controllers) are assigned to ide0 and ide1 while those on add-in PCI | ||
350 | cards (off-board controllers) are relegated to ide2 and ide3. | ||
351 | Answering Y here will allow you to reverse the situation, with | ||
352 | off-board controllers on ide0/1 and on-board controllers on ide2/3. | ||
353 | This can improve the usability of some boot managers such as lilo | ||
354 | when booting from a drive on an off-board controller. | ||
355 | |||
356 | If you say Y here, and you actually want to reverse the device scan | ||
357 | order as explained above, you also need to issue the kernel command | ||
358 | line option "ide=reverse". (Try "man bootparam" or see the | ||
359 | documentation of your boot loader (lilo or loadlin) about how to | ||
360 | pass options to the kernel at boot time.) | ||
361 | |||
362 | Note that, if you do this, the order of the hd* devices will be | ||
363 | rearranged which may require modification of fstab and other files. | ||
364 | |||
365 | If in doubt, say N. | ||
366 | |||
367 | config BLK_DEV_GENERIC | ||
368 | tristate "Generic PCI IDE Chipset Support" | ||
369 | depends on BLK_DEV_IDEPCI | ||
370 | |||
371 | config BLK_DEV_OPTI621 | ||
372 | tristate "OPTi 82C621 chipset enhanced support (EXPERIMENTAL)" | ||
373 | depends on PCI && BLK_DEV_IDEPCI && EXPERIMENTAL | ||
374 | help | ||
375 | This is a driver for the OPTi 82C621 EIDE controller. | ||
376 | Please read the comments at the top of <file:drivers/ide/pci/opti621.c>. | ||
377 | |||
378 | config BLK_DEV_RZ1000 | ||
379 | tristate "RZ1000 chipset bugfix/support" | ||
380 | depends on PCI && BLK_DEV_IDEPCI && X86 | ||
381 | help | ||
382 | The PC-Technologies RZ1000 IDE chip is used on many common 486 and | ||
383 | Pentium motherboards, usually along with the "Neptune" chipset. | ||
384 | Unfortunately, it has a rather nasty design flaw that can cause | ||
385 | severe data corruption under many conditions. Say Y here to include | ||
386 | code which automatically detects and corrects the problem under | ||
387 | Linux. This may slow disk throughput by a few percent, but at least | ||
388 | things will operate 100% reliably. | ||
389 | |||
390 | config BLK_DEV_SL82C105 | ||
391 | tristate "Winbond SL82c105 support" | ||
392 | depends on PCI && (PPC || ARM) && BLK_DEV_IDEPCI | ||
393 | help | ||
394 | If you have a Winbond SL82c105 IDE controller, say Y here to enable | ||
395 | special configuration for this chip. This is common on various CHRP | ||
396 | motherboards, but could be used elsewhere. If in doubt, say Y. | ||
397 | |||
398 | config BLK_DEV_IDEDMA_PCI | ||
399 | bool "Generic PCI bus-master DMA support" | ||
400 | depends on PCI && BLK_DEV_IDEPCI | ||
401 | ---help--- | ||
402 | If your PCI system uses IDE drive(s) (as opposed to SCSI, say) and | ||
403 | is capable of bus-master DMA operation (most Pentium PCI systems), | ||
404 | you will want to say Y here to reduce CPU overhead. You can then use | ||
405 | the "hdparm" utility to enable DMA for drives for which it was not | ||
406 | enabled automatically. By default, DMA is not enabled automatically | ||
407 | for these drives, but you can change that by saying Y to the | ||
408 | following question "Use DMA by default when available". You can get | ||
409 | the latest version of the hdparm utility from | ||
410 | <ftp://ibiblio.org/pub/Linux/system/hardware/>. | ||
411 | |||
412 | Read the comments at the beginning of <file:drivers/ide/ide-dma.c> | ||
413 | and the file <file:Documentation/ide.txt> for more information. | ||
414 | |||
415 | It is safe to say Y to this question. | ||
416 | |||
417 | if BLK_DEV_IDEDMA_PCI | ||
418 | |||
419 | config BLK_DEV_IDEDMA_FORCED | ||
420 | bool "Force enable legacy 2.0.X HOSTS to use DMA" | ||
421 | help | ||
422 | This is an old piece of lost code from Linux 2.0 Kernels. | ||
423 | |||
424 | Generally say N here. | ||
425 | |||
426 | config IDEDMA_PCI_AUTO | ||
427 | bool "Use PCI DMA by default when available" | ||
428 | ---help--- | ||
429 | Prior to kernel version 2.1.112, Linux used to automatically use | ||
430 | DMA for IDE drives and chipsets which support it. Due to concerns | ||
431 | about a couple of cases where buggy hardware may have caused damage, | ||
432 | the default is now to NOT use DMA automatically. To revert to the | ||
433 | previous behaviour, say Y to this question. | ||
434 | |||
435 | If you suspect your hardware is at all flakey, say N here. | ||
436 | Do NOT email the IDE kernel people regarding this issue! | ||
437 | |||
438 | It is normally safe to answer Y to this question unless your | ||
439 | motherboard uses a VIA VP2 chipset, in which case you should say N. | ||
440 | |||
441 | config IDEDMA_ONLYDISK | ||
442 | bool "Enable DMA only for disks " | ||
443 | depends on IDEDMA_PCI_AUTO | ||
444 | help | ||
445 | This is used if you know your ATAPI Devices are going to fail DMA | ||
446 | Transfers. | ||
447 | |||
448 | Generally say N here. | ||
449 | |||
450 | config BLK_DEV_AEC62XX | ||
451 | tristate "AEC62XX chipset support" | ||
452 | help | ||
453 | This driver adds explicit support for Acard AEC62xx (Artop ATP8xx) | ||
454 | IDE controllers. This allows the kernel to change PIO, DMA and UDMA | ||
455 | speeds and to configure the chip to optimum performance. | ||
456 | |||
457 | config BLK_DEV_ALI15X3 | ||
458 | tristate "ALI M15x3 chipset support" | ||
459 | help | ||
460 | This driver ensures (U)DMA support for ALI 1533, 1543 and 1543C | ||
461 | onboard chipsets. It also tests for Simplex mode and enables | ||
462 | normal dual channel support. | ||
463 | |||
464 | If you say Y here, you also need to say Y to "Use DMA by default | ||
465 | when available", above. Please read the comments at the top of | ||
466 | <file:drivers/ide/pci/alim15x3.c>. | ||
467 | |||
468 | If unsure, say N. | ||
469 | |||
470 | config WDC_ALI15X3 | ||
471 | bool "ALI M15x3 WDC support (DANGEROUS)" | ||
472 | depends on BLK_DEV_ALI15X3 | ||
473 | ---help--- | ||
474 | This allows for UltraDMA support for WDC drives that ignore CRC | ||
475 | checking. You are a fool for enabling this option, but there have | ||
476 | been requests. DO NOT COMPLAIN IF YOUR DRIVE HAS FS CORRUPTION, IF | ||
477 | YOU ENABLE THIS! No one will listen, just laugh for ignoring this | ||
478 | SERIOUS WARNING. | ||
479 | |||
480 | Using this option can allow WDC drives to run at ATA-4/5 transfer | ||
481 | rates with only an ATA-2 support structure. | ||
482 | |||
483 | SAY N! | ||
484 | |||
485 | config BLK_DEV_AMD74XX | ||
486 | tristate "AMD and nVidia IDE support" | ||
487 | help | ||
488 | This driver adds explicit support for AMD-7xx and AMD-8111 chips | ||
489 | and also for the nVidia nForce chip. This allows the kernel to | ||
490 | change PIO, DMA and UDMA speeds and to configure the chip to | ||
491 | optimum performance. | ||
492 | |||
493 | config BLK_DEV_ATIIXP | ||
494 | tristate "ATI IXP chipset IDE support" | ||
495 | depends on X86 | ||
496 | help | ||
497 | This driver adds explicit support for ATI IXP chipset. | ||
498 | This allows the kernel to change PIO, DMA and UDMA speeds | ||
499 | and to configure the chip to optimum performance. | ||
500 | |||
501 | Say Y here if you have an ATI IXP chipset IDE controller. | ||
502 | |||
503 | config BLK_DEV_CMD64X | ||
504 | tristate "CMD64{3|6|8|9} chipset support" | ||
505 | help | ||
506 | Say Y here if you have an IDE controller which uses any of these | ||
507 | chipsets: CMD643, CMD646, or CMD648. | ||
508 | |||
509 | config BLK_DEV_TRIFLEX | ||
510 | tristate "Compaq Triflex IDE support" | ||
511 | help | ||
512 | Say Y here if you have a Compaq Triflex IDE controller, such | ||
513 | as those commonly found on Compaq Pentium-Pro systems | ||
514 | |||
515 | config BLK_DEV_CY82C693 | ||
516 | tristate "CY82C693 chipset support" | ||
517 | help | ||
518 | This driver adds detection and support for the CY82C693 chipset | ||
519 | used on Digital's PC-Alpha 164SX boards. | ||
520 | |||
521 | If you say Y here, you need to say Y to "Use DMA by default | ||
522 | when available" as well. | ||
523 | |||
524 | config BLK_DEV_CS5520 | ||
525 | tristate "Cyrix CS5510/20 MediaGX chipset support (VERY EXPERIMENTAL)" | ||
526 | depends on EXPERIMENTAL | ||
527 | help | ||
528 | Include support for PIO tuning an virtual DMA on the Cyrix MediaGX | ||
529 | 5510/5520 chipset. This will automatically be detected and | ||
530 | configured if found. | ||
531 | |||
532 | It is safe to say Y to this question. | ||
533 | |||
534 | config BLK_DEV_CS5530 | ||
535 | tristate "Cyrix/National Semiconductor CS5530 MediaGX chipset support" | ||
536 | help | ||
537 | Include support for UDMA on the Cyrix MediaGX 5530 chipset. This | ||
538 | will automatically be detected and configured if found. | ||
539 | |||
540 | It is safe to say Y to this question. | ||
541 | |||
542 | config BLK_DEV_HPT34X | ||
543 | tristate "HPT34X chipset support" | ||
544 | help | ||
545 | This driver adds up to 4 more EIDE devices sharing a single | ||
546 | interrupt. The HPT343 chipset in its current form is a non-bootable | ||
547 | controller; the HPT345/HPT363 chipset is a bootable (needs BIOS FIX) | ||
548 | PCI UDMA controllers. This driver requires dynamic tuning of the | ||
549 | chipset during the ide-probe at boot time. It is reported to support | ||
550 | DVD II drives, by the manufacturer. | ||
551 | |||
552 | config HPT34X_AUTODMA | ||
553 | bool "HPT34X AUTODMA support (EXPERIMENTAL)" | ||
554 | depends on BLK_DEV_HPT34X && EXPERIMENTAL | ||
555 | help | ||
556 | This is a dangerous thing to attempt currently! Please read the | ||
557 | comments at the top of <file:drivers/ide/pci/hpt34x.c>. If you say Y | ||
558 | here, then say Y to "Use DMA by default when available" as well. | ||
559 | |||
560 | If unsure, say N. | ||
561 | |||
562 | config BLK_DEV_HPT366 | ||
563 | tristate "HPT36X/37X chipset support" | ||
564 | ---help--- | ||
565 | HPT366 is an Ultra DMA chipset for ATA-66. | ||
566 | HPT368 is an Ultra DMA chipset for ATA-66 RAID Based. | ||
567 | HPT370 is an Ultra DMA chipset for ATA-100. | ||
568 | HPT372 is an Ultra DMA chipset for ATA-100. | ||
569 | HPT374 is an Ultra DMA chipset for ATA-100. | ||
570 | |||
571 | This driver adds up to 4 more EIDE devices sharing a single | ||
572 | interrupt. | ||
573 | |||
574 | The HPT366 chipset in its current form is bootable. One solution | ||
575 | for this problem are special LILO commands for redirecting the | ||
576 | reference to device 0x80. The other solution is to say Y to "Boot | ||
577 | off-board chipsets first support" (CONFIG_BLK_DEV_OFFBOARD) unless | ||
578 | your mother board has the chipset natively mounted. Regardless one | ||
579 | should use the fore mentioned option and call at LILO or include | ||
580 | "ide=reverse" in LILO's append-line. | ||
581 | |||
582 | This driver requires dynamic tuning of the chipset during the | ||
583 | ide-probe at boot. It is reported to support DVD II drives, by the | ||
584 | manufacturer. | ||
585 | |||
586 | config BLK_DEV_SC1200 | ||
587 | tristate "National SCx200 chipset support" | ||
588 | help | ||
589 | This driver adds support for the built in IDE on the National | ||
590 | SCx200 series of embedded x86 "Geode" systems | ||
591 | |||
592 | config BLK_DEV_PIIX | ||
593 | tristate "Intel PIIXn chipsets support" | ||
594 | help | ||
595 | This driver adds explicit support for Intel PIIX and ICH chips | ||
596 | and also for the Efar Victory66 (slc90e66) chip. This allows | ||
597 | the kernel to change PIO, DMA and UDMA speeds and to configure | ||
598 | the chip to optimum performance. | ||
599 | |||
600 | config BLK_DEV_IT8172 | ||
601 | bool "IT8172 IDE support" | ||
602 | depends on (MIPS_ITE8172 || MIPS_IVR) | ||
603 | help | ||
604 | Say Y here to support the on-board IDE controller on the Integrated | ||
605 | Technology Express, Inc. ITE8172 SBC. Vendor page at | ||
606 | <http://www.ite.com.tw/ia/brief_it8172bsp.htm>; picture of the | ||
607 | board at <http://www.mvista.com/partners/semiconductor/ite.html>. | ||
608 | |||
609 | config BLK_DEV_NS87415 | ||
610 | tristate "NS87415 chipset support" | ||
611 | help | ||
612 | This driver adds detection and support for the NS87415 chip | ||
613 | (used in SPARC64, among others). | ||
614 | |||
615 | Please read the comments at the top of <file:drivers/ide/pci/ns87415.c>. | ||
616 | |||
617 | config BLK_DEV_PDC202XX_OLD | ||
618 | tristate "PROMISE PDC202{46|62|65|67} support" | ||
619 | help | ||
620 | Promise Ultra33 or PDC20246 | ||
621 | Promise Ultra66 or PDC20262 | ||
622 | Promise Ultra100 or PDC20265/PDC20267/PDC20268 | ||
623 | |||
624 | This driver adds up to 4 more EIDE devices sharing a single | ||
625 | interrupt. This add-on card is a bootable PCI UDMA controller. Since | ||
626 | multiple cards can be installed and there are BIOS ROM problems that | ||
627 | happen if the BIOS revisions of all installed cards (three-max) do | ||
628 | not match, the driver attempts to do dynamic tuning of the chipset | ||
629 | at boot-time for max-speed. Ultra33 BIOS 1.25 or newer is required | ||
630 | for more than one card. This card may require that you say Y to | ||
631 | "Special UDMA Feature". | ||
632 | |||
633 | If you say Y here, you need to say Y to "Use DMA by default when | ||
634 | available" as well. | ||
635 | |||
636 | Please read the comments at the top of | ||
637 | <file:drivers/ide/pci/pdc202xx_old.c>. | ||
638 | |||
639 | If unsure, say N. | ||
640 | |||
641 | config PDC202XX_BURST | ||
642 | bool "Special UDMA Feature" | ||
643 | depends on BLK_DEV_PDC202XX_OLD | ||
644 | help | ||
645 | This option causes the pdc202xx driver to enable UDMA modes on the | ||
646 | PDC202xx even when the PDC202xx BIOS has not done so. | ||
647 | |||
648 | It was originally designed for the PDC20246/Ultra33, whose BIOS will | ||
649 | only setup UDMA on the first two PDC20246 cards. It has also been | ||
650 | used succesfully on a PDC20265/Ultra100, allowing use of UDMA modes | ||
651 | when the PDC20265 BIOS has been disabled (for faster boot up). | ||
652 | |||
653 | Please read the comments at the top of | ||
654 | <file:drivers/ide/pci/pdc202xx_old.c>. | ||
655 | |||
656 | If unsure, say N. | ||
657 | |||
658 | config BLK_DEV_PDC202XX_NEW | ||
659 | tristate "PROMISE PDC202{68|69|70|71|75|76|77} support" | ||
660 | |||
661 | # FIXME - probably wants to be one for old and for new | ||
662 | config PDC202XX_FORCE | ||
663 | bool "Enable controller even if disabled by BIOS" | ||
664 | depends on BLK_DEV_PDC202XX_NEW | ||
665 | help | ||
666 | Enable the PDC202xx controller even if it has been disabled in the BIOS setup. | ||
667 | |||
668 | config BLK_DEV_SVWKS | ||
669 | tristate "ServerWorks OSB4/CSB5/CSB6 chipsets support" | ||
670 | help | ||
671 | This driver adds PIO/(U)DMA support for the ServerWorks OSB4/CSB5 | ||
672 | chipsets. | ||
673 | |||
674 | config BLK_DEV_SGIIOC4 | ||
675 | tristate "Silicon Graphics IOC4 chipset support" | ||
676 | depends on IA64_SGI_SN2 || IA64_GENERIC | ||
677 | help | ||
678 | This driver adds PIO & MultiMode DMA-2 support for the SGI IOC4 | ||
679 | chipset, which has one channel and can support two devices. | ||
680 | Please say Y here if you have an Altix System from SGI. | ||
681 | |||
682 | config BLK_DEV_SIIMAGE | ||
683 | tristate "Silicon Image chipset support" | ||
684 | help | ||
685 | This driver adds PIO/(U)DMA support for the SI CMD680 and SII | ||
686 | 3112 (Serial ATA) chips. | ||
687 | |||
688 | config BLK_DEV_SIS5513 | ||
689 | tristate "SiS5513 chipset support" | ||
690 | depends on X86 | ||
691 | ---help--- | ||
692 | This driver ensures (U)DMA support for SIS5513 chipset family based | ||
693 | mainboards. | ||
694 | |||
695 | The following chipsets are supported: | ||
696 | ATA16: SiS5511, SiS5513 | ||
697 | ATA33: SiS5591, SiS5597, SiS5598, SiS5600 | ||
698 | ATA66: SiS530, SiS540, SiS620, SiS630, SiS640 | ||
699 | ATA100: SiS635, SiS645, SiS650, SiS730, SiS735, SiS740, | ||
700 | SiS745, SiS750 | ||
701 | |||
702 | If you say Y here, you need to say Y to "Use DMA by default when | ||
703 | available" as well. | ||
704 | |||
705 | Please read the comments at the top of <file:drivers/ide/pci/sis5513.c>. | ||
706 | |||
707 | config BLK_DEV_SLC90E66 | ||
708 | tristate "SLC90E66 chipset support" | ||
709 | help | ||
710 | This driver ensures (U)DMA support for Victroy66 SouthBridges for | ||
711 | SMsC with Intel NorthBridges. This is an Ultra66 based chipset. | ||
712 | The nice thing about it is that you can mix Ultra/DMA/PIO devices | ||
713 | and it will handle timing cycles. Since this is an improved | ||
714 | look-a-like to the PIIX4 it should be a nice addition. | ||
715 | |||
716 | If you say Y here, you need to say Y to "Use DMA by default when | ||
717 | available" as well. | ||
718 | |||
719 | Please read the comments at the top of | ||
720 | <file:drivers/ide/pci/slc90e66.c>. | ||
721 | |||
722 | config BLK_DEV_TRM290 | ||
723 | tristate "Tekram TRM290 chipset support" | ||
724 | help | ||
725 | This driver adds support for bus master DMA transfers | ||
726 | using the Tekram TRM290 PCI IDE chip. Volunteers are | ||
727 | needed for further tweaking and development. | ||
728 | Please read the comments at the top of <file:drivers/ide/pci/trm290.c>. | ||
729 | |||
730 | config BLK_DEV_VIA82CXXX | ||
731 | tristate "VIA82CXXX chipset support" | ||
732 | help | ||
733 | This driver adds explicit support for VIA BusMastering IDE chips. | ||
734 | This allows the kernel to change PIO, DMA and UDMA speeds and to | ||
735 | configure the chip to optimum performance. | ||
736 | |||
737 | endif | ||
738 | |||
739 | config BLK_DEV_IDE_PMAC | ||
740 | bool "Builtin PowerMac IDE support" | ||
741 | depends on PPC_PMAC && IDE=y | ||
742 | help | ||
743 | This driver provides support for the built-in IDE controller on | ||
744 | most of the recent Apple Power Macintoshes and PowerBooks. | ||
745 | If unsure, say Y. | ||
746 | |||
747 | config BLK_DEV_IDE_PMAC_ATA100FIRST | ||
748 | bool "Probe internal ATA/100 (Kauai) first" | ||
749 | depends on BLK_DEV_IDE_PMAC | ||
750 | help | ||
751 | This option will cause the ATA/100 controller found in UniNorth2 | ||
752 | based machines (Windtunnel PowerMac, Aluminium PowerBooks, ...) | ||
753 | to be probed before the ATA/66 and ATA/33 controllers. Without | ||
754 | these, those machine used to have the hard disk on hdc and the | ||
755 | CD-ROM on hda. This option changes this to more natural hda for | ||
756 | hard disk and hdc for CD-ROM. | ||
757 | |||
758 | config BLK_DEV_IDEDMA_PMAC | ||
759 | bool "PowerMac IDE DMA support" | ||
760 | depends on BLK_DEV_IDE_PMAC | ||
761 | help | ||
762 | This option allows the driver for the built-in IDE controller on | ||
763 | Power Macintoshes and PowerBooks to use DMA (direct memory access) | ||
764 | to transfer data to and from memory. Saying Y is safe and improves | ||
765 | performance. | ||
766 | |||
767 | config BLK_DEV_IDE_PMAC_BLINK | ||
768 | bool "Blink laptop LED on drive activity" | ||
769 | depends on BLK_DEV_IDE_PMAC && ADB_PMU | ||
770 | help | ||
771 | This option enables the use of the sleep LED as a hard drive | ||
772 | activity LED. | ||
773 | |||
774 | config IDE_ARM | ||
775 | def_bool ARM && (ARCH_A5K || ARCH_CLPS7500 || ARCH_RPC || ARCH_SHARK) | ||
776 | |||
777 | config BLK_DEV_IDE_ICSIDE | ||
778 | tristate "ICS IDE interface support" | ||
779 | depends on ARM && ARCH_ACORN | ||
780 | help | ||
781 | On Acorn systems, say Y here if you wish to use the ICS IDE | ||
782 | interface card. This is not required for ICS partition support. | ||
783 | If you are unsure, say N to this. | ||
784 | |||
785 | config BLK_DEV_IDEDMA_ICS | ||
786 | bool "ICS DMA support" | ||
787 | depends on BLK_DEV_IDE_ICSIDE | ||
788 | help | ||
789 | Say Y here if you want to add DMA (Direct Memory Access) support to | ||
790 | the ICS IDE driver. | ||
791 | |||
792 | config IDEDMA_ICS_AUTO | ||
793 | bool "Use ICS DMA by default" | ||
794 | depends on BLK_DEV_IDEDMA_ICS | ||
795 | help | ||
796 | Prior to kernel version 2.1.112, Linux used to automatically use | ||
797 | DMA for IDE drives and chipsets which support it. Due to concerns | ||
798 | about a couple of cases where buggy hardware may have caused damage, | ||
799 | the default is now to NOT use DMA automatically. To revert to the | ||
800 | previous behaviour, say Y to this question. | ||
801 | |||
802 | If you suspect your hardware is at all flakey, say N here. | ||
803 | Do NOT email the IDE kernel people regarding this issue! | ||
804 | |||
805 | config BLK_DEV_IDE_RAPIDE | ||
806 | tristate "RapIDE interface support" | ||
807 | depends on ARM && ARCH_ACORN | ||
808 | help | ||
809 | Say Y here if you want to support the Yellowstone RapIDE controller | ||
810 | manufactured for use with Acorn computers. | ||
811 | |||
812 | config BLK_DEV_IDE_BAST | ||
813 | tristate "Simtec BAST / Thorcom VR1000 IDE support" | ||
814 | depends on ARM && (ARCH_BAST || MACH_VR1000) | ||
815 | help | ||
816 | Say Y here if you want to support the onboard IDE channels on the | ||
817 | Simtec BAST or the Thorcom VR1000 | ||
818 | |||
819 | config BLK_DEV_GAYLE | ||
820 | bool "Amiga Gayle IDE interface support" | ||
821 | depends on AMIGA | ||
822 | help | ||
823 | This is the IDE driver for the Amiga Gayle IDE interface. It supports | ||
824 | both the `A1200 style' and `A4000 style' of the Gayle IDE interface, | ||
825 | This includes builtin IDE interfaces on some Amiga models (A600, | ||
826 | A1200, A4000, and A4000T), and IDE interfaces on the Zorro expansion | ||
827 | bus (M-Tech E-Matrix 530 expansion card). | ||
828 | Say Y if you have an Amiga with a Gayle IDE interface and want to use | ||
829 | IDE devices (hard disks, CD-ROM drives, etc.) that are connected to | ||
830 | it. | ||
831 | Note that you also have to enable Zorro bus support if you want to | ||
832 | use Gayle IDE interfaces on the Zorro expansion bus. | ||
833 | |||
834 | config BLK_DEV_IDEDOUBLER | ||
835 | bool "Amiga IDE Doubler support (EXPERIMENTAL)" | ||
836 | depends on BLK_DEV_GAYLE && EXPERIMENTAL | ||
837 | ---help--- | ||
838 | This driver provides support for the so-called `IDE doublers' (made | ||
839 | by various manufacturers, e.g. Eyetech) that can be connected to the | ||
840 | builtin IDE interface of some Amiga models. Using such an IDE | ||
841 | doubler, you can connect up to four instead of two IDE devices on | ||
842 | the Amiga's builtin IDE interface. | ||
843 | |||
844 | Note that the normal Amiga Gayle IDE driver may not work correctly | ||
845 | if you have an IDE doubler and don't enable this driver! | ||
846 | |||
847 | Say Y if you have an IDE doubler. The driver is enabled at kernel | ||
848 | runtime using the "ide=doubler" kernel boot parameter. | ||
849 | |||
850 | config BLK_DEV_BUDDHA | ||
851 | bool "Buddha/Catweasel/X-Surf IDE interface support (EXPERIMENTAL)" | ||
852 | depends on ZORRO && EXPERIMENTAL | ||
853 | help | ||
854 | This is the IDE driver for the IDE interfaces on the Buddha, | ||
855 | Catweasel and X-Surf expansion boards. It supports up to two interfaces | ||
856 | on the Buddha, three on the Catweasel and two on the X-Surf. | ||
857 | |||
858 | Say Y if you have a Buddha or Catweasel expansion board and want to | ||
859 | use IDE devices (hard disks, CD-ROM drives, etc.) that are connected | ||
860 | to one of its IDE interfaces. | ||
861 | |||
862 | config BLK_DEV_FALCON_IDE | ||
863 | bool "Falcon IDE interface support" | ||
864 | depends on ATARI | ||
865 | help | ||
866 | This is the IDE driver for the builtin IDE interface on the Atari | ||
867 | Falcon. Say Y if you have a Falcon and want to use IDE devices (hard | ||
868 | disks, CD-ROM drives, etc.) that are connected to the builtin IDE | ||
869 | interface. | ||
870 | |||
871 | config BLK_DEV_MAC_IDE | ||
872 | bool "Macintosh Quadra/Powerbook IDE interface support" | ||
873 | depends on MAC | ||
874 | help | ||
875 | This is the IDE driver for the builtin IDE interface on some m68k | ||
876 | Macintosh models. It supports both the `Quadra style' (used in | ||
877 | Quadra/ Centris 630 and Performa 588 models) and `Powerbook style' | ||
878 | (used in the Powerbook 150 and 190 models) IDE interface. | ||
879 | |||
880 | Say Y if you have such an Macintosh model and want to use IDE | ||
881 | devices (hard disks, CD-ROM drives, etc.) that are connected to the | ||
882 | builtin IDE interface. | ||
883 | |||
884 | config BLK_DEV_Q40IDE | ||
885 | bool "Q40/Q60 IDE interface support" | ||
886 | depends on Q40 | ||
887 | help | ||
888 | Enable the on-board IDE controller in the Q40/Q60. This should | ||
889 | normally be on; disable it only if you are running a custom hard | ||
890 | drive subsystem through an expansion card. | ||
891 | |||
892 | config BLK_DEV_MPC8xx_IDE | ||
893 | bool "MPC8xx IDE support" | ||
894 | depends on 8xx | ||
895 | help | ||
896 | This option provides support for IDE on Motorola MPC8xx Systems. | ||
897 | Please see 'Type of MPC8xx IDE interface' for details. | ||
898 | |||
899 | If unsure, say N. | ||
900 | |||
901 | choice | ||
902 | prompt "Type of MPC8xx IDE interface" | ||
903 | depends on BLK_DEV_MPC8xx_IDE | ||
904 | default IDE_8xx_PCCARD | ||
905 | |||
906 | config IDE_8xx_PCCARD | ||
907 | bool "8xx_PCCARD" | ||
908 | ---help--- | ||
909 | Select how the IDE devices are connected to the MPC8xx system: | ||
910 | |||
911 | 8xx_PCCARD uses the 8xx internal PCMCIA interface in combination | ||
912 | with a PC Card (e.g. ARGOSY portable Hard Disk Adapter), | ||
913 | ATA PC Card HDDs or ATA PC Flash Cards (example: TQM8xxL | ||
914 | systems) | ||
915 | |||
916 | 8xx_DIRECT is used for directly connected IDE devices using the 8xx | ||
917 | internal PCMCIA interface (example: IVMS8 systems) | ||
918 | |||
919 | EXT_DIRECT is used for IDE devices directly connected to the 8xx | ||
920 | bus using some glue logic, but _not_ the 8xx internal | ||
921 | PCMCIA interface (example: IDIF860 systems) | ||
922 | |||
923 | config IDE_8xx_DIRECT | ||
924 | bool "8xx_DIRECT" | ||
925 | |||
926 | config IDE_EXT_DIRECT | ||
927 | bool "EXT_DIRECT" | ||
928 | |||
929 | endchoice | ||
930 | |||
931 | # no isa -> no vlb | ||
932 | config IDE_CHIPSETS | ||
933 | bool "Other IDE chipset support" | ||
934 | depends on ISA | ||
935 | ---help--- | ||
936 | Say Y here if you want to include enhanced support for various IDE | ||
937 | interface chipsets used on motherboards and add-on cards. You can | ||
938 | then pick your particular IDE chip from among the following options. | ||
939 | This enhanced support may be necessary for Linux to be able to | ||
940 | access the 3rd/4th drives in some systems. It may also enable | ||
941 | setting of higher speed I/O rates to improve system performance with | ||
942 | these chipsets. Most of these also require special kernel boot | ||
943 | parameters to actually turn on the support at runtime; you can find | ||
944 | a list of these in the file <file:Documentation/ide.txt>. | ||
945 | |||
946 | People with SCSI-only systems can say N here. | ||
947 | |||
948 | if IDE_CHIPSETS | ||
949 | |||
950 | comment "Note: most of these also require special kernel boot parameters" | ||
951 | |||
952 | config BLK_DEV_4DRIVES | ||
953 | bool "Generic 4 drives/port support" | ||
954 | help | ||
955 | Certain older chipsets, including the Tekram 690CD, use a single set | ||
956 | of I/O ports at 0x1f0 to control up to four drives, instead of the | ||
957 | customary two drives per port. Support for this can be enabled at | ||
958 | runtime using the "ide0=four" kernel boot parameter if you say Y | ||
959 | here. | ||
960 | |||
961 | config BLK_DEV_ALI14XX | ||
962 | tristate "ALI M14xx support" | ||
963 | help | ||
964 | This driver is enabled at runtime using the "ide0=ali14xx" kernel | ||
965 | boot parameter. It enables support for the secondary IDE interface | ||
966 | of the ALI M1439/1443/1445/1487/1489 chipsets, and permits faster | ||
967 | I/O speeds to be set as well. See the files | ||
968 | <file:Documentation/ide.txt> and <file:drivers/ide/legacy/ali14xx.c> for | ||
969 | more info. | ||
970 | |||
971 | config BLK_DEV_DTC2278 | ||
972 | tristate "DTC-2278 support" | ||
973 | help | ||
974 | This driver is enabled at runtime using the "ide0=dtc2278" kernel | ||
975 | boot parameter. It enables support for the secondary IDE interface | ||
976 | of the DTC-2278 card, and permits faster I/O speeds to be set as | ||
977 | well. See the <file:Documentation/ide.txt> and | ||
978 | <file:drivers/ide/legacy/dtc2278.c> files for more info. | ||
979 | |||
980 | config BLK_DEV_HT6560B | ||
981 | tristate "Holtek HT6560B support" | ||
982 | help | ||
983 | This driver is enabled at runtime using the "ide0=ht6560b" kernel | ||
984 | boot parameter. It enables support for the secondary IDE interface | ||
985 | of the Holtek card, and permits faster I/O speeds to be set as well. | ||
986 | See the <file:Documentation/ide.txt> and | ||
987 | <file:drivers/ide/legacy/ht6560b.c> files for more info. | ||
988 | |||
989 | config BLK_DEV_QD65XX | ||
990 | tristate "QDI QD65xx support" | ||
991 | help | ||
992 | This driver is enabled at runtime using the "ide0=qd65xx" kernel | ||
993 | boot parameter. It permits faster I/O speeds to be set. See the | ||
994 | <file:Documentation/ide.txt> and <file:drivers/ide/legacy/qd65xx.c> for | ||
995 | more info. | ||
996 | |||
997 | config BLK_DEV_UMC8672 | ||
998 | tristate "UMC-8672 support" | ||
999 | help | ||
1000 | This driver is enabled at runtime using the "ide0=umc8672" kernel | ||
1001 | boot parameter. It enables support for the secondary IDE interface | ||
1002 | of the UMC-8672, and permits faster I/O speeds to be set as well. | ||
1003 | See the files <file:Documentation/ide.txt> and | ||
1004 | <file:drivers/ide/legacy/umc8672.c> for more info. | ||
1005 | |||
1006 | endif | ||
1007 | |||
1008 | config BLK_DEV_IDEDMA | ||
1009 | def_bool BLK_DEV_IDEDMA_PCI || BLK_DEV_IDEDMA_PMAC || BLK_DEV_IDEDMA_ICS | ||
1010 | |||
1011 | config IDEDMA_IVB | ||
1012 | bool "IGNORE word93 Validation BITS" | ||
1013 | depends on BLK_DEV_IDEDMA_PCI || BLK_DEV_IDEDMA_PMAC || BLK_DEV_IDEDMA_ICS | ||
1014 | ---help--- | ||
1015 | There are unclear terms in ATA-4 and ATA-5 standards how certain | ||
1016 | hardware (an 80c ribbon) should be detected. Different interpretations | ||
1017 | of the standards have been released in hardware. This causes problems: | ||
1018 | for example, a host with Ultra Mode 4 (or higher) will not run | ||
1019 | in that mode with an 80c ribbon. | ||
1020 | |||
1021 | If you are experiencing compatibility or performance problems, you | ||
1022 | MAY try to answering Y here. However, it does not necessarily solve | ||
1023 | any of your problems, it could even cause more of them. | ||
1024 | |||
1025 | It is normally safe to answer Y; however, the default is N. | ||
1026 | |||
1027 | config IDEDMA_AUTO | ||
1028 | def_bool IDEDMA_PCI_AUTO || IDEDMA_ICS_AUTO | ||
1029 | |||
1030 | endif | ||
1031 | |||
1032 | config BLK_DEV_HD_ONLY | ||
1033 | bool "Old hard disk (MFM/RLL/IDE) driver" | ||
1034 | depends on BLK_DEV_IDE=n | ||
1035 | help | ||
1036 | There are two drivers for MFM/RLL/IDE hard disks. Most people use | ||
1037 | the newer enhanced driver, but this old one is still around for two | ||
1038 | reasons. Some older systems have strange timing problems and seem to | ||
1039 | work only with the old driver (which itself does not work with some | ||
1040 | newer systems). The other reason is that the old driver is smaller, | ||
1041 | since it lacks the enhanced functionality of the new one. This makes | ||
1042 | it a good choice for systems with very tight memory restrictions, or | ||
1043 | for systems with only older MFM/RLL/ESDI drives. Choosing the old | ||
1044 | driver can save 13 KB or so of kernel memory. | ||
1045 | |||
1046 | If you are unsure, then just choose the Enhanced IDE/MFM/RLL driver | ||
1047 | instead of this one. For more detailed information, read the | ||
1048 | Disk-HOWTO, available from | ||
1049 | <http://www.tldp.org/docs.html#howto>. | ||
1050 | |||
1051 | config BLK_DEV_HD | ||
1052 | def_bool BLK_DEV_HD_IDE || BLK_DEV_HD_ONLY | ||
1053 | |||
1054 | endif | ||
1055 | |||
1056 | endmenu | ||
diff --git a/drivers/ide/Makefile b/drivers/ide/Makefile new file mode 100644 index 000000000000..5be8ad6dc9ed --- /dev/null +++ b/drivers/ide/Makefile | |||
@@ -0,0 +1,54 @@ | |||
1 | # | ||
2 | # Makefile for the kernel ata, atapi, and ide block device drivers. | ||
3 | # | ||
4 | # 12 September 2000, Bartlomiej Zolnierkiewicz <bkz@linux-ide.org> | ||
5 | # Rewritten to use lists instead of if-statements. | ||
6 | # | ||
7 | # Note : at this point, these files are compiled on all systems. | ||
8 | # In the future, some of these should be built conditionally. | ||
9 | # | ||
10 | # First come modules that register themselves with the core | ||
11 | |||
12 | EXTRA_CFLAGS += -Idrivers/ide | ||
13 | |||
14 | obj-$(CONFIG_BLK_DEV_IDE) += pci/ | ||
15 | |||
16 | ide-core-y += ide.o ide-io.o ide-iops.o ide-lib.o ide-probe.o ide-taskfile.o | ||
17 | |||
18 | ide-core-$(CONFIG_BLK_DEV_CMD640) += pci/cmd640.o | ||
19 | |||
20 | # Core IDE code - must come before legacy | ||
21 | ide-core-$(CONFIG_BLK_DEV_IDEPCI) += setup-pci.o | ||
22 | ide-core-$(CONFIG_BLK_DEV_IDEDMA) += ide-dma.o | ||
23 | ide-core-$(CONFIG_BLK_DEV_IDE_TCQ) += ide-tcq.o | ||
24 | ide-core-$(CONFIG_PROC_FS) += ide-proc.o | ||
25 | ide-core-$(CONFIG_BLK_DEV_IDEPNP) += ide-pnp.o | ||
26 | |||
27 | # built-in only drivers from arm/ | ||
28 | ide-core-$(CONFIG_IDE_ARM) += arm/ide_arm.o | ||
29 | |||
30 | # built-in only drivers from legacy/ | ||
31 | ide-core-$(CONFIG_BLK_DEV_BUDDHA) += legacy/buddha.o | ||
32 | ide-core-$(CONFIG_BLK_DEV_FALCON_IDE) += legacy/falconide.o | ||
33 | ide-core-$(CONFIG_BLK_DEV_GAYLE) += legacy/gayle.o | ||
34 | ide-core-$(CONFIG_BLK_DEV_MAC_IDE) += legacy/macide.o | ||
35 | ide-core-$(CONFIG_BLK_DEV_Q40IDE) += legacy/q40ide.o | ||
36 | |||
37 | # built-in only drivers from ppc/ | ||
38 | ide-core-$(CONFIG_BLK_DEV_MPC8xx_IDE) += ppc/mpc8xx.o | ||
39 | ide-core-$(CONFIG_BLK_DEV_IDE_PMAC) += ppc/pmac.o | ||
40 | |||
41 | # built-in only drivers from h8300/ | ||
42 | ide-core-$(CONFIG_H8300) += h8300/ide-h8300.o | ||
43 | |||
44 | obj-$(CONFIG_BLK_DEV_IDE) += ide-core.o | ||
45 | obj-$(CONFIG_IDE_GENERIC) += ide-generic.o | ||
46 | |||
47 | obj-$(CONFIG_BLK_DEV_IDEDISK) += ide-disk.o | ||
48 | obj-$(CONFIG_BLK_DEV_IDECD) += ide-cd.o | ||
49 | obj-$(CONFIG_BLK_DEV_IDETAPE) += ide-tape.o | ||
50 | obj-$(CONFIG_BLK_DEV_IDEFLOPPY) += ide-floppy.o | ||
51 | |||
52 | obj-$(CONFIG_BLK_DEV_IDE) += legacy/ arm/ | ||
53 | obj-$(CONFIG_BLK_DEV_HD) += legacy/ | ||
54 | obj-$(CONFIG_ETRAX_IDE) += cris/ | ||
diff --git a/drivers/ide/arm/Makefile b/drivers/ide/arm/Makefile new file mode 100644 index 000000000000..6a78f0755f26 --- /dev/null +++ b/drivers/ide/arm/Makefile | |||
@@ -0,0 +1,6 @@ | |||
1 | |||
2 | obj-$(CONFIG_BLK_DEV_IDE_ICSIDE) += icside.o | ||
3 | obj-$(CONFIG_BLK_DEV_IDE_RAPIDE) += rapide.o | ||
4 | obj-$(CONFIG_BLK_DEV_IDE_BAST) += bast-ide.o | ||
5 | |||
6 | EXTRA_CFLAGS := -Idrivers/ide | ||
diff --git a/drivers/ide/arm/bast-ide.c b/drivers/ide/arm/bast-ide.c new file mode 100644 index 000000000000..9d474e5fd8dc --- /dev/null +++ b/drivers/ide/arm/bast-ide.c | |||
@@ -0,0 +1,71 @@ | |||
1 | /* linux/drivers/ide/arm/bast-ide.c | ||
2 | * | ||
3 | * Copyright (c) 2003-2004 Simtec Electronics | ||
4 | * Ben Dooks <ben@simtec.co.uk> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License version 2 as | ||
8 | * published by the Free Software Foundation. | ||
9 | * | ||
10 | */ | ||
11 | |||
12 | #include <linux/module.h> | ||
13 | #include <linux/errno.h> | ||
14 | #include <linux/ide.h> | ||
15 | #include <linux/init.h> | ||
16 | |||
17 | #include <asm/mach-types.h> | ||
18 | |||
19 | #include <asm/io.h> | ||
20 | #include <asm/irq.h> | ||
21 | #include <asm/arch/map.h> | ||
22 | #include <asm/arch/bast-map.h> | ||
23 | #include <asm/arch/bast-irq.h> | ||
24 | |||
25 | /* list of registered interfaces */ | ||
26 | static ide_hwif_t *ifs[2]; | ||
27 | |||
28 | static int __init | ||
29 | bastide_register(unsigned int base, unsigned int aux, int irq, | ||
30 | ide_hwif_t **hwif) | ||
31 | { | ||
32 | hw_regs_t hw; | ||
33 | int i; | ||
34 | |||
35 | memset(&hw, 0, sizeof(hw)); | ||
36 | |||
37 | base += BAST_IDE_CS; | ||
38 | aux += BAST_IDE_CS; | ||
39 | |||
40 | for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++) { | ||
41 | hw.io_ports[i] = (unsigned long)base; | ||
42 | base += 0x20; | ||
43 | } | ||
44 | |||
45 | hw.io_ports[IDE_CONTROL_OFFSET] = aux + (6 * 0x20); | ||
46 | hw.irq = irq; | ||
47 | |||
48 | ide_register_hw(&hw, hwif); | ||
49 | |||
50 | return 0; | ||
51 | } | ||
52 | |||
53 | static int __init bastide_init(void) | ||
54 | { | ||
55 | /* we can treat the VR1000 and the BAST the same */ | ||
56 | |||
57 | if (!(machine_is_bast() || machine_is_vr1000())) | ||
58 | return 0; | ||
59 | |||
60 | printk("BAST: IDE driver, (c) 2003-2004 Simtec Electronics\n"); | ||
61 | |||
62 | bastide_register(BAST_VA_IDEPRI, BAST_VA_IDEPRIAUX, IRQ_IDE0, &ifs[0]); | ||
63 | bastide_register(BAST_VA_IDESEC, BAST_VA_IDESECAUX, IRQ_IDE1, &ifs[1]); | ||
64 | return 0; | ||
65 | } | ||
66 | |||
67 | module_init(bastide_init); | ||
68 | |||
69 | MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>"); | ||
70 | MODULE_LICENSE("GPL"); | ||
71 | MODULE_DESCRIPTION("Simtec BAST / Thorcom VR1000 IDE driver"); | ||
diff --git a/drivers/ide/arm/icside.c b/drivers/ide/arm/icside.c new file mode 100644 index 000000000000..308897e57e4d --- /dev/null +++ b/drivers/ide/arm/icside.c | |||
@@ -0,0 +1,870 @@ | |||
1 | /* | ||
2 | * linux/drivers/ide/arm/icside.c | ||
3 | * | ||
4 | * Copyright (c) 1996-2004 Russell King. | ||
5 | * | ||
6 | * Please note that this platform does not support 32-bit IDE IO. | ||
7 | */ | ||
8 | |||
9 | #include <linux/config.h> | ||
10 | #include <linux/string.h> | ||
11 | #include <linux/module.h> | ||
12 | #include <linux/ioport.h> | ||
13 | #include <linux/slab.h> | ||
14 | #include <linux/blkdev.h> | ||
15 | #include <linux/errno.h> | ||
16 | #include <linux/hdreg.h> | ||
17 | #include <linux/ide.h> | ||
18 | #include <linux/dma-mapping.h> | ||
19 | #include <linux/device.h> | ||
20 | #include <linux/init.h> | ||
21 | #include <linux/scatterlist.h> | ||
22 | |||
23 | #include <asm/dma.h> | ||
24 | #include <asm/ecard.h> | ||
25 | #include <asm/io.h> | ||
26 | |||
27 | #define ICS_IDENT_OFFSET 0x2280 | ||
28 | |||
29 | #define ICS_ARCIN_V5_INTRSTAT 0x0000 | ||
30 | #define ICS_ARCIN_V5_INTROFFSET 0x0004 | ||
31 | #define ICS_ARCIN_V5_IDEOFFSET 0x2800 | ||
32 | #define ICS_ARCIN_V5_IDEALTOFFSET 0x2b80 | ||
33 | #define ICS_ARCIN_V5_IDESTEPPING 6 | ||
34 | |||
35 | #define ICS_ARCIN_V6_IDEOFFSET_1 0x2000 | ||
36 | #define ICS_ARCIN_V6_INTROFFSET_1 0x2200 | ||
37 | #define ICS_ARCIN_V6_INTRSTAT_1 0x2290 | ||
38 | #define ICS_ARCIN_V6_IDEALTOFFSET_1 0x2380 | ||
39 | #define ICS_ARCIN_V6_IDEOFFSET_2 0x3000 | ||
40 | #define ICS_ARCIN_V6_INTROFFSET_2 0x3200 | ||
41 | #define ICS_ARCIN_V6_INTRSTAT_2 0x3290 | ||
42 | #define ICS_ARCIN_V6_IDEALTOFFSET_2 0x3380 | ||
43 | #define ICS_ARCIN_V6_IDESTEPPING 6 | ||
44 | |||
45 | struct cardinfo { | ||
46 | unsigned int dataoffset; | ||
47 | unsigned int ctrloffset; | ||
48 | unsigned int stepping; | ||
49 | }; | ||
50 | |||
51 | static struct cardinfo icside_cardinfo_v5 = { | ||
52 | .dataoffset = ICS_ARCIN_V5_IDEOFFSET, | ||
53 | .ctrloffset = ICS_ARCIN_V5_IDEALTOFFSET, | ||
54 | .stepping = ICS_ARCIN_V5_IDESTEPPING, | ||
55 | }; | ||
56 | |||
57 | static struct cardinfo icside_cardinfo_v6_1 = { | ||
58 | .dataoffset = ICS_ARCIN_V6_IDEOFFSET_1, | ||
59 | .ctrloffset = ICS_ARCIN_V6_IDEALTOFFSET_1, | ||
60 | .stepping = ICS_ARCIN_V6_IDESTEPPING, | ||
61 | }; | ||
62 | |||
63 | static struct cardinfo icside_cardinfo_v6_2 = { | ||
64 | .dataoffset = ICS_ARCIN_V6_IDEOFFSET_2, | ||
65 | .ctrloffset = ICS_ARCIN_V6_IDEALTOFFSET_2, | ||
66 | .stepping = ICS_ARCIN_V6_IDESTEPPING, | ||
67 | }; | ||
68 | |||
69 | struct icside_state { | ||
70 | unsigned int channel; | ||
71 | unsigned int enabled; | ||
72 | void __iomem *irq_port; | ||
73 | void __iomem *ioc_base; | ||
74 | unsigned int type; | ||
75 | /* parent device... until the IDE core gets one of its own */ | ||
76 | struct device *dev; | ||
77 | ide_hwif_t *hwif[2]; | ||
78 | }; | ||
79 | |||
80 | #define ICS_TYPE_A3IN 0 | ||
81 | #define ICS_TYPE_A3USER 1 | ||
82 | #define ICS_TYPE_V6 3 | ||
83 | #define ICS_TYPE_V5 15 | ||
84 | #define ICS_TYPE_NOTYPE ((unsigned int)-1) | ||
85 | |||
86 | /* ---------------- Version 5 PCB Support Functions --------------------- */ | ||
87 | /* Prototype: icside_irqenable_arcin_v5 (struct expansion_card *ec, int irqnr) | ||
88 | * Purpose : enable interrupts from card | ||
89 | */ | ||
90 | static void icside_irqenable_arcin_v5 (struct expansion_card *ec, int irqnr) | ||
91 | { | ||
92 | struct icside_state *state = ec->irq_data; | ||
93 | |||
94 | writeb(0, state->irq_port + ICS_ARCIN_V5_INTROFFSET); | ||
95 | } | ||
96 | |||
97 | /* Prototype: icside_irqdisable_arcin_v5 (struct expansion_card *ec, int irqnr) | ||
98 | * Purpose : disable interrupts from card | ||
99 | */ | ||
100 | static void icside_irqdisable_arcin_v5 (struct expansion_card *ec, int irqnr) | ||
101 | { | ||
102 | struct icside_state *state = ec->irq_data; | ||
103 | |||
104 | readb(state->irq_port + ICS_ARCIN_V5_INTROFFSET); | ||
105 | } | ||
106 | |||
107 | static const expansioncard_ops_t icside_ops_arcin_v5 = { | ||
108 | .irqenable = icside_irqenable_arcin_v5, | ||
109 | .irqdisable = icside_irqdisable_arcin_v5, | ||
110 | }; | ||
111 | |||
112 | |||
113 | /* ---------------- Version 6 PCB Support Functions --------------------- */ | ||
114 | /* Prototype: icside_irqenable_arcin_v6 (struct expansion_card *ec, int irqnr) | ||
115 | * Purpose : enable interrupts from card | ||
116 | */ | ||
117 | static void icside_irqenable_arcin_v6 (struct expansion_card *ec, int irqnr) | ||
118 | { | ||
119 | struct icside_state *state = ec->irq_data; | ||
120 | void __iomem *base = state->irq_port; | ||
121 | |||
122 | state->enabled = 1; | ||
123 | |||
124 | switch (state->channel) { | ||
125 | case 0: | ||
126 | writeb(0, base + ICS_ARCIN_V6_INTROFFSET_1); | ||
127 | readb(base + ICS_ARCIN_V6_INTROFFSET_2); | ||
128 | break; | ||
129 | case 1: | ||
130 | writeb(0, base + ICS_ARCIN_V6_INTROFFSET_2); | ||
131 | readb(base + ICS_ARCIN_V6_INTROFFSET_1); | ||
132 | break; | ||
133 | } | ||
134 | } | ||
135 | |||
136 | /* Prototype: icside_irqdisable_arcin_v6 (struct expansion_card *ec, int irqnr) | ||
137 | * Purpose : disable interrupts from card | ||
138 | */ | ||
139 | static void icside_irqdisable_arcin_v6 (struct expansion_card *ec, int irqnr) | ||
140 | { | ||
141 | struct icside_state *state = ec->irq_data; | ||
142 | |||
143 | state->enabled = 0; | ||
144 | |||
145 | readb(state->irq_port + ICS_ARCIN_V6_INTROFFSET_1); | ||
146 | readb(state->irq_port + ICS_ARCIN_V6_INTROFFSET_2); | ||
147 | } | ||
148 | |||
149 | /* Prototype: icside_irqprobe(struct expansion_card *ec) | ||
150 | * Purpose : detect an active interrupt from card | ||
151 | */ | ||
152 | static int icside_irqpending_arcin_v6(struct expansion_card *ec) | ||
153 | { | ||
154 | struct icside_state *state = ec->irq_data; | ||
155 | |||
156 | return readb(state->irq_port + ICS_ARCIN_V6_INTRSTAT_1) & 1 || | ||
157 | readb(state->irq_port + ICS_ARCIN_V6_INTRSTAT_2) & 1; | ||
158 | } | ||
159 | |||
160 | static const expansioncard_ops_t icside_ops_arcin_v6 = { | ||
161 | .irqenable = icside_irqenable_arcin_v6, | ||
162 | .irqdisable = icside_irqdisable_arcin_v6, | ||
163 | .irqpending = icside_irqpending_arcin_v6, | ||
164 | }; | ||
165 | |||
166 | /* | ||
167 | * Handle routing of interrupts. This is called before | ||
168 | * we write the command to the drive. | ||
169 | */ | ||
170 | static void icside_maskproc(ide_drive_t *drive, int mask) | ||
171 | { | ||
172 | ide_hwif_t *hwif = HWIF(drive); | ||
173 | struct icside_state *state = hwif->hwif_data; | ||
174 | unsigned long flags; | ||
175 | |||
176 | local_irq_save(flags); | ||
177 | |||
178 | state->channel = hwif->channel; | ||
179 | |||
180 | if (state->enabled && !mask) { | ||
181 | switch (hwif->channel) { | ||
182 | case 0: | ||
183 | writeb(0, state->irq_port + ICS_ARCIN_V6_INTROFFSET_1); | ||
184 | readb(state->irq_port + ICS_ARCIN_V6_INTROFFSET_2); | ||
185 | break; | ||
186 | case 1: | ||
187 | writeb(0, state->irq_port + ICS_ARCIN_V6_INTROFFSET_2); | ||
188 | readb(state->irq_port + ICS_ARCIN_V6_INTROFFSET_1); | ||
189 | break; | ||
190 | } | ||
191 | } else { | ||
192 | readb(state->irq_port + ICS_ARCIN_V6_INTROFFSET_2); | ||
193 | readb(state->irq_port + ICS_ARCIN_V6_INTROFFSET_1); | ||
194 | } | ||
195 | |||
196 | local_irq_restore(flags); | ||
197 | } | ||
198 | |||
199 | #ifdef CONFIG_BLK_DEV_IDEDMA_ICS | ||
200 | |||
201 | #ifndef CONFIG_IDEDMA_ICS_AUTO | ||
202 | #warning CONFIG_IDEDMA_ICS_AUTO=n support is obsolete, and will be removed soon. | ||
203 | #endif | ||
204 | |||
205 | /* | ||
206 | * SG-DMA support. | ||
207 | * | ||
208 | * Similar to the BM-DMA, but we use the RiscPCs IOMD DMA controllers. | ||
209 | * There is only one DMA controller per card, which means that only | ||
210 | * one drive can be accessed at one time. NOTE! We do not enforce that | ||
211 | * here, but we rely on the main IDE driver spotting that both | ||
212 | * interfaces use the same IRQ, which should guarantee this. | ||
213 | */ | ||
214 | |||
215 | static void icside_build_sglist(ide_drive_t *drive, struct request *rq) | ||
216 | { | ||
217 | ide_hwif_t *hwif = drive->hwif; | ||
218 | struct icside_state *state = hwif->hwif_data; | ||
219 | struct scatterlist *sg = hwif->sg_table; | ||
220 | |||
221 | ide_map_sg(drive, rq); | ||
222 | |||
223 | if (rq_data_dir(rq) == READ) | ||
224 | hwif->sg_dma_direction = DMA_FROM_DEVICE; | ||
225 | else | ||
226 | hwif->sg_dma_direction = DMA_TO_DEVICE; | ||
227 | |||
228 | hwif->sg_nents = dma_map_sg(state->dev, sg, hwif->sg_nents, | ||
229 | hwif->sg_dma_direction); | ||
230 | } | ||
231 | |||
232 | /* | ||
233 | * Configure the IOMD to give the appropriate timings for the transfer | ||
234 | * mode being requested. We take the advice of the ATA standards, and | ||
235 | * calculate the cycle time based on the transfer mode, and the EIDE | ||
236 | * MW DMA specs that the drive provides in the IDENTIFY command. | ||
237 | * | ||
238 | * We have the following IOMD DMA modes to choose from: | ||
239 | * | ||
240 | * Type Active Recovery Cycle | ||
241 | * A 250 (250) 312 (550) 562 (800) | ||
242 | * B 187 250 437 | ||
243 | * C 125 (125) 125 (375) 250 (500) | ||
244 | * D 62 125 187 | ||
245 | * | ||
246 | * (figures in brackets are actual measured timings) | ||
247 | * | ||
248 | * However, we also need to take care of the read/write active and | ||
249 | * recovery timings: | ||
250 | * | ||
251 | * Read Write | ||
252 | * Mode Active -- Recovery -- Cycle IOMD type | ||
253 | * MW0 215 50 215 480 A | ||
254 | * MW1 80 50 50 150 C | ||
255 | * MW2 70 25 25 120 C | ||
256 | */ | ||
257 | static int icside_set_speed(ide_drive_t *drive, u8 xfer_mode) | ||
258 | { | ||
259 | int on = 0, cycle_time = 0, use_dma_info = 0; | ||
260 | |||
261 | /* | ||
262 | * Limit the transfer speed to MW_DMA_2. | ||
263 | */ | ||
264 | if (xfer_mode > XFER_MW_DMA_2) | ||
265 | xfer_mode = XFER_MW_DMA_2; | ||
266 | |||
267 | switch (xfer_mode) { | ||
268 | case XFER_MW_DMA_2: | ||
269 | cycle_time = 250; | ||
270 | use_dma_info = 1; | ||
271 | break; | ||
272 | |||
273 | case XFER_MW_DMA_1: | ||
274 | cycle_time = 250; | ||
275 | use_dma_info = 1; | ||
276 | break; | ||
277 | |||
278 | case XFER_MW_DMA_0: | ||
279 | cycle_time = 480; | ||
280 | break; | ||
281 | |||
282 | case XFER_SW_DMA_2: | ||
283 | case XFER_SW_DMA_1: | ||
284 | case XFER_SW_DMA_0: | ||
285 | cycle_time = 480; | ||
286 | break; | ||
287 | } | ||
288 | |||
289 | /* | ||
290 | * If we're going to be doing MW_DMA_1 or MW_DMA_2, we should | ||
291 | * take care to note the values in the ID... | ||
292 | */ | ||
293 | if (use_dma_info && drive->id->eide_dma_time > cycle_time) | ||
294 | cycle_time = drive->id->eide_dma_time; | ||
295 | |||
296 | drive->drive_data = cycle_time; | ||
297 | |||
298 | if (cycle_time && ide_config_drive_speed(drive, xfer_mode) == 0) | ||
299 | on = 1; | ||
300 | else | ||
301 | drive->drive_data = 480; | ||
302 | |||
303 | printk("%s: %s selected (peak %dMB/s)\n", drive->name, | ||
304 | ide_xfer_verbose(xfer_mode), 2000 / drive->drive_data); | ||
305 | |||
306 | drive->current_speed = xfer_mode; | ||
307 | |||
308 | return on; | ||
309 | } | ||
310 | |||
311 | static int icside_dma_host_off(ide_drive_t *drive) | ||
312 | { | ||
313 | return 0; | ||
314 | } | ||
315 | |||
316 | static int icside_dma_off_quietly(ide_drive_t *drive) | ||
317 | { | ||
318 | drive->using_dma = 0; | ||
319 | return icside_dma_host_off(drive); | ||
320 | } | ||
321 | |||
322 | static int icside_dma_host_on(ide_drive_t *drive) | ||
323 | { | ||
324 | return 0; | ||
325 | } | ||
326 | |||
327 | static int icside_dma_on(ide_drive_t *drive) | ||
328 | { | ||
329 | drive->using_dma = 1; | ||
330 | return icside_dma_host_on(drive); | ||
331 | } | ||
332 | |||
333 | static int icside_dma_check(ide_drive_t *drive) | ||
334 | { | ||
335 | struct hd_driveid *id = drive->id; | ||
336 | ide_hwif_t *hwif = HWIF(drive); | ||
337 | int xfer_mode = XFER_PIO_2; | ||
338 | int on; | ||
339 | |||
340 | if (!(id->capability & 1) || !hwif->autodma) | ||
341 | goto out; | ||
342 | |||
343 | /* | ||
344 | * Consult the list of known "bad" drives | ||
345 | */ | ||
346 | if (__ide_dma_bad_drive(drive)) | ||
347 | goto out; | ||
348 | |||
349 | /* | ||
350 | * Enable DMA on any drive that has multiword DMA | ||
351 | */ | ||
352 | if (id->field_valid & 2) { | ||
353 | xfer_mode = ide_dma_speed(drive, 0); | ||
354 | goto out; | ||
355 | } | ||
356 | |||
357 | /* | ||
358 | * Consult the list of known "good" drives | ||
359 | */ | ||
360 | if (__ide_dma_good_drive(drive)) { | ||
361 | if (id->eide_dma_time > 150) | ||
362 | goto out; | ||
363 | xfer_mode = XFER_MW_DMA_1; | ||
364 | } | ||
365 | |||
366 | out: | ||
367 | on = icside_set_speed(drive, xfer_mode); | ||
368 | |||
369 | if (on) | ||
370 | return icside_dma_on(drive); | ||
371 | else | ||
372 | return icside_dma_off_quietly(drive); | ||
373 | } | ||
374 | |||
375 | static int icside_dma_end(ide_drive_t *drive) | ||
376 | { | ||
377 | ide_hwif_t *hwif = HWIF(drive); | ||
378 | struct icside_state *state = hwif->hwif_data; | ||
379 | |||
380 | drive->waiting_for_dma = 0; | ||
381 | |||
382 | disable_dma(hwif->hw.dma); | ||
383 | |||
384 | /* Teardown mappings after DMA has completed. */ | ||
385 | dma_unmap_sg(state->dev, hwif->sg_table, hwif->sg_nents, | ||
386 | hwif->sg_dma_direction); | ||
387 | |||
388 | return get_dma_residue(hwif->hw.dma) != 0; | ||
389 | } | ||
390 | |||
391 | static void icside_dma_start(ide_drive_t *drive) | ||
392 | { | ||
393 | ide_hwif_t *hwif = HWIF(drive); | ||
394 | |||
395 | /* We can not enable DMA on both channels simultaneously. */ | ||
396 | BUG_ON(dma_channel_active(hwif->hw.dma)); | ||
397 | enable_dma(hwif->hw.dma); | ||
398 | } | ||
399 | |||
400 | static int icside_dma_setup(ide_drive_t *drive) | ||
401 | { | ||
402 | ide_hwif_t *hwif = HWIF(drive); | ||
403 | struct request *rq = hwif->hwgroup->rq; | ||
404 | unsigned int dma_mode; | ||
405 | |||
406 | if (rq_data_dir(rq)) | ||
407 | dma_mode = DMA_MODE_WRITE; | ||
408 | else | ||
409 | dma_mode = DMA_MODE_READ; | ||
410 | |||
411 | /* | ||
412 | * We can not enable DMA on both channels. | ||
413 | */ | ||
414 | BUG_ON(dma_channel_active(hwif->hw.dma)); | ||
415 | |||
416 | icside_build_sglist(drive, rq); | ||
417 | |||
418 | /* | ||
419 | * Ensure that we have the right interrupt routed. | ||
420 | */ | ||
421 | icside_maskproc(drive, 0); | ||
422 | |||
423 | /* | ||
424 | * Route the DMA signals to the correct interface. | ||
425 | */ | ||
426 | writeb(hwif->select_data, hwif->config_data); | ||
427 | |||
428 | /* | ||
429 | * Select the correct timing for this drive. | ||
430 | */ | ||
431 | set_dma_speed(hwif->hw.dma, drive->drive_data); | ||
432 | |||
433 | /* | ||
434 | * Tell the DMA engine about the SG table and | ||
435 | * data direction. | ||
436 | */ | ||
437 | set_dma_sg(hwif->hw.dma, hwif->sg_table, hwif->sg_nents); | ||
438 | set_dma_mode(hwif->hw.dma, dma_mode); | ||
439 | |||
440 | drive->waiting_for_dma = 1; | ||
441 | |||
442 | return 0; | ||
443 | } | ||
444 | |||
445 | static void icside_dma_exec_cmd(ide_drive_t *drive, u8 cmd) | ||
446 | { | ||
447 | /* issue cmd to drive */ | ||
448 | ide_execute_command(drive, cmd, ide_dma_intr, 2 * WAIT_CMD, NULL); | ||
449 | } | ||
450 | |||
451 | static int icside_dma_test_irq(ide_drive_t *drive) | ||
452 | { | ||
453 | ide_hwif_t *hwif = HWIF(drive); | ||
454 | struct icside_state *state = hwif->hwif_data; | ||
455 | |||
456 | return readb(state->irq_port + | ||
457 | (hwif->channel ? | ||
458 | ICS_ARCIN_V6_INTRSTAT_2 : | ||
459 | ICS_ARCIN_V6_INTRSTAT_1)) & 1; | ||
460 | } | ||
461 | |||
462 | static int icside_dma_timeout(ide_drive_t *drive) | ||
463 | { | ||
464 | printk(KERN_ERR "%s: DMA timeout occurred: ", drive->name); | ||
465 | |||
466 | if (icside_dma_test_irq(drive)) | ||
467 | return 0; | ||
468 | |||
469 | ide_dump_status(drive, "DMA timeout", | ||
470 | HWIF(drive)->INB(IDE_STATUS_REG)); | ||
471 | |||
472 | return icside_dma_end(drive); | ||
473 | } | ||
474 | |||
475 | static int icside_dma_lostirq(ide_drive_t *drive) | ||
476 | { | ||
477 | printk(KERN_ERR "%s: IRQ lost\n", drive->name); | ||
478 | return 1; | ||
479 | } | ||
480 | |||
481 | static void icside_dma_init(ide_hwif_t *hwif) | ||
482 | { | ||
483 | int autodma = 0; | ||
484 | |||
485 | #ifdef CONFIG_IDEDMA_ICS_AUTO | ||
486 | autodma = 1; | ||
487 | #endif | ||
488 | |||
489 | printk(" %s: SG-DMA", hwif->name); | ||
490 | |||
491 | hwif->atapi_dma = 1; | ||
492 | hwif->mwdma_mask = 7; /* MW0..2 */ | ||
493 | hwif->swdma_mask = 7; /* SW0..2 */ | ||
494 | |||
495 | hwif->dmatable_cpu = NULL; | ||
496 | hwif->dmatable_dma = 0; | ||
497 | hwif->speedproc = icside_set_speed; | ||
498 | hwif->autodma = autodma; | ||
499 | |||
500 | hwif->ide_dma_check = icside_dma_check; | ||
501 | hwif->ide_dma_host_off = icside_dma_host_off; | ||
502 | hwif->ide_dma_off_quietly = icside_dma_off_quietly; | ||
503 | hwif->ide_dma_host_on = icside_dma_host_on; | ||
504 | hwif->ide_dma_on = icside_dma_on; | ||
505 | hwif->dma_setup = icside_dma_setup; | ||
506 | hwif->dma_exec_cmd = icside_dma_exec_cmd; | ||
507 | hwif->dma_start = icside_dma_start; | ||
508 | hwif->ide_dma_end = icside_dma_end; | ||
509 | hwif->ide_dma_test_irq = icside_dma_test_irq; | ||
510 | hwif->ide_dma_timeout = icside_dma_timeout; | ||
511 | hwif->ide_dma_lostirq = icside_dma_lostirq; | ||
512 | |||
513 | hwif->drives[0].autodma = hwif->autodma; | ||
514 | hwif->drives[1].autodma = hwif->autodma; | ||
515 | |||
516 | printk(" capable%s\n", hwif->autodma ? ", auto-enable" : ""); | ||
517 | } | ||
518 | #else | ||
519 | #define icside_dma_init(hwif) (0) | ||
520 | #endif | ||
521 | |||
522 | static ide_hwif_t *icside_find_hwif(unsigned long dataport) | ||
523 | { | ||
524 | ide_hwif_t *hwif; | ||
525 | int index; | ||
526 | |||
527 | for (index = 0; index < MAX_HWIFS; ++index) { | ||
528 | hwif = &ide_hwifs[index]; | ||
529 | if (hwif->io_ports[IDE_DATA_OFFSET] == dataport) | ||
530 | goto found; | ||
531 | } | ||
532 | |||
533 | for (index = 0; index < MAX_HWIFS; ++index) { | ||
534 | hwif = &ide_hwifs[index]; | ||
535 | if (!hwif->io_ports[IDE_DATA_OFFSET]) | ||
536 | goto found; | ||
537 | } | ||
538 | |||
539 | hwif = NULL; | ||
540 | found: | ||
541 | return hwif; | ||
542 | } | ||
543 | |||
544 | static ide_hwif_t * | ||
545 | icside_setup(void __iomem *base, struct cardinfo *info, struct expansion_card *ec) | ||
546 | { | ||
547 | unsigned long port = (unsigned long)base + info->dataoffset; | ||
548 | ide_hwif_t *hwif; | ||
549 | |||
550 | hwif = icside_find_hwif(port); | ||
551 | if (hwif) { | ||
552 | int i; | ||
553 | |||
554 | memset(&hwif->hw, 0, sizeof(hw_regs_t)); | ||
555 | |||
556 | /* | ||
557 | * Ensure we're using MMIO | ||
558 | */ | ||
559 | default_hwif_mmiops(hwif); | ||
560 | hwif->mmio = 2; | ||
561 | |||
562 | for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++) { | ||
563 | hwif->hw.io_ports[i] = port; | ||
564 | hwif->io_ports[i] = port; | ||
565 | port += 1 << info->stepping; | ||
566 | } | ||
567 | hwif->hw.io_ports[IDE_CONTROL_OFFSET] = (unsigned long)base + info->ctrloffset; | ||
568 | hwif->io_ports[IDE_CONTROL_OFFSET] = (unsigned long)base + info->ctrloffset; | ||
569 | hwif->hw.irq = ec->irq; | ||
570 | hwif->irq = ec->irq; | ||
571 | hwif->noprobe = 0; | ||
572 | hwif->chipset = ide_acorn; | ||
573 | hwif->gendev.parent = &ec->dev; | ||
574 | } | ||
575 | |||
576 | return hwif; | ||
577 | } | ||
578 | |||
579 | static int __init | ||
580 | icside_register_v5(struct icside_state *state, struct expansion_card *ec) | ||
581 | { | ||
582 | ide_hwif_t *hwif; | ||
583 | void __iomem *base; | ||
584 | |||
585 | base = ioremap(ecard_resource_start(ec, ECARD_RES_MEMC), | ||
586 | ecard_resource_len(ec, ECARD_RES_MEMC)); | ||
587 | if (!base) | ||
588 | return -ENOMEM; | ||
589 | |||
590 | state->irq_port = base; | ||
591 | |||
592 | ec->irqaddr = base + ICS_ARCIN_V5_INTRSTAT; | ||
593 | ec->irqmask = 1; | ||
594 | ec->irq_data = state; | ||
595 | ec->ops = &icside_ops_arcin_v5; | ||
596 | |||
597 | /* | ||
598 | * Be on the safe side - disable interrupts | ||
599 | */ | ||
600 | icside_irqdisable_arcin_v5(ec, 0); | ||
601 | |||
602 | hwif = icside_setup(base, &icside_cardinfo_v5, ec); | ||
603 | if (!hwif) { | ||
604 | iounmap(base); | ||
605 | return -ENODEV; | ||
606 | } | ||
607 | |||
608 | state->hwif[0] = hwif; | ||
609 | |||
610 | probe_hwif_init(hwif); | ||
611 | create_proc_ide_interfaces(); | ||
612 | |||
613 | return 0; | ||
614 | } | ||
615 | |||
616 | static int __init | ||
617 | icside_register_v6(struct icside_state *state, struct expansion_card *ec) | ||
618 | { | ||
619 | ide_hwif_t *hwif, *mate; | ||
620 | void __iomem *ioc_base, *easi_base; | ||
621 | unsigned int sel = 0; | ||
622 | int ret; | ||
623 | |||
624 | ioc_base = ioremap(ecard_resource_start(ec, ECARD_RES_IOCFAST), | ||
625 | ecard_resource_len(ec, ECARD_RES_IOCFAST)); | ||
626 | if (!ioc_base) { | ||
627 | ret = -ENOMEM; | ||
628 | goto out; | ||
629 | } | ||
630 | |||
631 | easi_base = ioc_base; | ||
632 | |||
633 | if (ecard_resource_flags(ec, ECARD_RES_EASI)) { | ||
634 | easi_base = ioremap(ecard_resource_start(ec, ECARD_RES_EASI), | ||
635 | ecard_resource_len(ec, ECARD_RES_EASI)); | ||
636 | if (!easi_base) { | ||
637 | ret = -ENOMEM; | ||
638 | goto unmap_slot; | ||
639 | } | ||
640 | |||
641 | /* | ||
642 | * Enable access to the EASI region. | ||
643 | */ | ||
644 | sel = 1 << 5; | ||
645 | } | ||
646 | |||
647 | writeb(sel, ioc_base); | ||
648 | |||
649 | ec->irq_data = state; | ||
650 | ec->ops = &icside_ops_arcin_v6; | ||
651 | |||
652 | state->irq_port = easi_base; | ||
653 | state->ioc_base = ioc_base; | ||
654 | |||
655 | /* | ||
656 | * Be on the safe side - disable interrupts | ||
657 | */ | ||
658 | icside_irqdisable_arcin_v6(ec, 0); | ||
659 | |||
660 | /* | ||
661 | * Find and register the interfaces. | ||
662 | */ | ||
663 | hwif = icside_setup(easi_base, &icside_cardinfo_v6_1, ec); | ||
664 | mate = icside_setup(easi_base, &icside_cardinfo_v6_2, ec); | ||
665 | |||
666 | if (!hwif || !mate) { | ||
667 | ret = -ENODEV; | ||
668 | goto unmap_port; | ||
669 | } | ||
670 | |||
671 | state->hwif[0] = hwif; | ||
672 | state->hwif[1] = mate; | ||
673 | |||
674 | hwif->maskproc = icside_maskproc; | ||
675 | hwif->channel = 0; | ||
676 | hwif->hwif_data = state; | ||
677 | hwif->mate = mate; | ||
678 | hwif->serialized = 1; | ||
679 | hwif->config_data = (unsigned long)ioc_base; | ||
680 | hwif->select_data = sel; | ||
681 | hwif->hw.dma = ec->dma; | ||
682 | |||
683 | mate->maskproc = icside_maskproc; | ||
684 | mate->channel = 1; | ||
685 | mate->hwif_data = state; | ||
686 | mate->mate = hwif; | ||
687 | mate->serialized = 1; | ||
688 | mate->config_data = (unsigned long)ioc_base; | ||
689 | mate->select_data = sel | 1; | ||
690 | mate->hw.dma = ec->dma; | ||
691 | |||
692 | if (ec->dma != NO_DMA && !request_dma(ec->dma, hwif->name)) { | ||
693 | icside_dma_init(hwif); | ||
694 | icside_dma_init(mate); | ||
695 | } | ||
696 | |||
697 | probe_hwif_init(hwif); | ||
698 | probe_hwif_init(mate); | ||
699 | create_proc_ide_interfaces(); | ||
700 | |||
701 | return 0; | ||
702 | |||
703 | unmap_port: | ||
704 | if (easi_base != ioc_base) | ||
705 | iounmap(easi_base); | ||
706 | unmap_slot: | ||
707 | iounmap(ioc_base); | ||
708 | out: | ||
709 | return ret; | ||
710 | } | ||
711 | |||
712 | static int __devinit | ||
713 | icside_probe(struct expansion_card *ec, const struct ecard_id *id) | ||
714 | { | ||
715 | struct icside_state *state; | ||
716 | void __iomem *idmem; | ||
717 | int ret; | ||
718 | |||
719 | ret = ecard_request_resources(ec); | ||
720 | if (ret) | ||
721 | goto out; | ||
722 | |||
723 | state = kmalloc(sizeof(struct icside_state), GFP_KERNEL); | ||
724 | if (!state) { | ||
725 | ret = -ENOMEM; | ||
726 | goto release; | ||
727 | } | ||
728 | |||
729 | memset(state, 0, sizeof(state)); | ||
730 | state->type = ICS_TYPE_NOTYPE; | ||
731 | state->dev = &ec->dev; | ||
732 | |||
733 | idmem = ioremap(ecard_resource_start(ec, ECARD_RES_IOCFAST), | ||
734 | ecard_resource_len(ec, ECARD_RES_IOCFAST)); | ||
735 | if (idmem) { | ||
736 | unsigned int type; | ||
737 | |||
738 | type = readb(idmem + ICS_IDENT_OFFSET) & 1; | ||
739 | type |= (readb(idmem + ICS_IDENT_OFFSET + 4) & 1) << 1; | ||
740 | type |= (readb(idmem + ICS_IDENT_OFFSET + 8) & 1) << 2; | ||
741 | type |= (readb(idmem + ICS_IDENT_OFFSET + 12) & 1) << 3; | ||
742 | iounmap(idmem); | ||
743 | |||
744 | state->type = type; | ||
745 | } | ||
746 | |||
747 | switch (state->type) { | ||
748 | case ICS_TYPE_A3IN: | ||
749 | dev_warn(&ec->dev, "A3IN unsupported\n"); | ||
750 | ret = -ENODEV; | ||
751 | break; | ||
752 | |||
753 | case ICS_TYPE_A3USER: | ||
754 | dev_warn(&ec->dev, "A3USER unsupported\n"); | ||
755 | ret = -ENODEV; | ||
756 | break; | ||
757 | |||
758 | case ICS_TYPE_V5: | ||
759 | ret = icside_register_v5(state, ec); | ||
760 | break; | ||
761 | |||
762 | case ICS_TYPE_V6: | ||
763 | ret = icside_register_v6(state, ec); | ||
764 | break; | ||
765 | |||
766 | default: | ||
767 | dev_warn(&ec->dev, "unknown interface type\n"); | ||
768 | ret = -ENODEV; | ||
769 | break; | ||
770 | } | ||
771 | |||
772 | if (ret == 0) { | ||
773 | ecard_set_drvdata(ec, state); | ||
774 | goto out; | ||
775 | } | ||
776 | |||
777 | kfree(state); | ||
778 | release: | ||
779 | ecard_release_resources(ec); | ||
780 | out: | ||
781 | return ret; | ||
782 | } | ||
783 | |||
784 | static void __devexit icside_remove(struct expansion_card *ec) | ||
785 | { | ||
786 | struct icside_state *state = ecard_get_drvdata(ec); | ||
787 | |||
788 | switch (state->type) { | ||
789 | case ICS_TYPE_V5: | ||
790 | /* FIXME: tell IDE to stop using the interface */ | ||
791 | |||
792 | /* Disable interrupts */ | ||
793 | icside_irqdisable_arcin_v5(ec, 0); | ||
794 | break; | ||
795 | |||
796 | case ICS_TYPE_V6: | ||
797 | /* FIXME: tell IDE to stop using the interface */ | ||
798 | if (ec->dma != NO_DMA) | ||
799 | free_dma(ec->dma); | ||
800 | |||
801 | /* Disable interrupts */ | ||
802 | icside_irqdisable_arcin_v6(ec, 0); | ||
803 | |||
804 | /* Reset the ROM pointer/EASI selection */ | ||
805 | writeb(0, state->ioc_base); | ||
806 | break; | ||
807 | } | ||
808 | |||
809 | ecard_set_drvdata(ec, NULL); | ||
810 | ec->ops = NULL; | ||
811 | ec->irq_data = NULL; | ||
812 | |||
813 | if (state->ioc_base) | ||
814 | iounmap(state->ioc_base); | ||
815 | if (state->ioc_base != state->irq_port) | ||
816 | iounmap(state->irq_port); | ||
817 | |||
818 | kfree(state); | ||
819 | ecard_release_resources(ec); | ||
820 | } | ||
821 | |||
822 | static void icside_shutdown(struct expansion_card *ec) | ||
823 | { | ||
824 | struct icside_state *state = ecard_get_drvdata(ec); | ||
825 | unsigned long flags; | ||
826 | |||
827 | /* | ||
828 | * Disable interrupts from this card. We need to do | ||
829 | * this before disabling EASI since we may be accessing | ||
830 | * this register via that region. | ||
831 | */ | ||
832 | local_irq_save(flags); | ||
833 | ec->ops->irqdisable(ec, 0); | ||
834 | local_irq_restore(flags); | ||
835 | |||
836 | /* | ||
837 | * Reset the ROM pointer so that we can read the ROM | ||
838 | * after a soft reboot. This also disables access to | ||
839 | * the IDE taskfile via the EASI region. | ||
840 | */ | ||
841 | if (state->ioc_base) | ||
842 | writeb(0, state->ioc_base); | ||
843 | } | ||
844 | |||
845 | static const struct ecard_id icside_ids[] = { | ||
846 | { MANU_ICS, PROD_ICS_IDE }, | ||
847 | { MANU_ICS2, PROD_ICS2_IDE }, | ||
848 | { 0xffff, 0xffff } | ||
849 | }; | ||
850 | |||
851 | static struct ecard_driver icside_driver = { | ||
852 | .probe = icside_probe, | ||
853 | .remove = __devexit_p(icside_remove), | ||
854 | .shutdown = icside_shutdown, | ||
855 | .id_table = icside_ids, | ||
856 | .drv = { | ||
857 | .name = "icside", | ||
858 | }, | ||
859 | }; | ||
860 | |||
861 | static int __init icside_init(void) | ||
862 | { | ||
863 | return ecard_register_driver(&icside_driver); | ||
864 | } | ||
865 | |||
866 | MODULE_AUTHOR("Russell King <rmk@arm.linux.org.uk>"); | ||
867 | MODULE_LICENSE("GPL"); | ||
868 | MODULE_DESCRIPTION("ICS IDE driver"); | ||
869 | |||
870 | module_init(icside_init); | ||
diff --git a/drivers/ide/arm/ide_arm.c b/drivers/ide/arm/ide_arm.c new file mode 100644 index 000000000000..23488c4d1fcd --- /dev/null +++ b/drivers/ide/arm/ide_arm.c | |||
@@ -0,0 +1,43 @@ | |||
1 | /* | ||
2 | * ARM/ARM26 default IDE host driver | ||
3 | * | ||
4 | * Copyright (C) 2004 Bartlomiej Zolnierkiewicz | ||
5 | * Based on code by: Russell King, Ian Molton and Alexander Schulz. | ||
6 | * | ||
7 | * May be copied or modified under the terms of the GNU General Public License. | ||
8 | */ | ||
9 | |||
10 | #include <linux/kernel.h> | ||
11 | #include <linux/init.h> | ||
12 | #include <linux/ide.h> | ||
13 | |||
14 | #include <asm/mach-types.h> | ||
15 | #include <asm/irq.h> | ||
16 | |||
17 | #ifdef CONFIG_ARM26 | ||
18 | # define IDE_ARM_HOST (machine_is_a5k()) | ||
19 | #else | ||
20 | # define IDE_ARM_HOST (1) | ||
21 | #endif | ||
22 | |||
23 | #ifdef CONFIG_ARCH_CLPS7500 | ||
24 | # include <asm/arch/hardware.h> | ||
25 | # | ||
26 | # define IDE_ARM_IO (ISASLOT_IO + 0x1f0) | ||
27 | # define IDE_ARM_IRQ IRQ_ISA_14 | ||
28 | #else | ||
29 | # define IDE_ARM_IO 0x1f0 | ||
30 | # define IDE_ARM_IRQ IRQ_HARDDISK | ||
31 | #endif | ||
32 | |||
33 | void __init ide_arm_init(void) | ||
34 | { | ||
35 | if (IDE_ARM_HOST) { | ||
36 | hw_regs_t hw; | ||
37 | |||
38 | memset(&hw, 0, sizeof(hw)); | ||
39 | ide_std_init_ports(&hw, IDE_ARM_IO, IDE_ARM_IO + 0x206); | ||
40 | hw.irq = IDE_ARM_IRQ; | ||
41 | ide_register_hw(&hw, NULL); | ||
42 | } | ||
43 | } | ||
diff --git a/drivers/ide/arm/rapide.c b/drivers/ide/arm/rapide.c new file mode 100644 index 000000000000..3058217767d6 --- /dev/null +++ b/drivers/ide/arm/rapide.c | |||
@@ -0,0 +1,125 @@ | |||
1 | /* | ||
2 | * linux/drivers/ide/arm/rapide.c | ||
3 | * | ||
4 | * Copyright (c) 1996-2002 Russell King. | ||
5 | */ | ||
6 | |||
7 | #include <linux/module.h> | ||
8 | #include <linux/slab.h> | ||
9 | #include <linux/blkdev.h> | ||
10 | #include <linux/errno.h> | ||
11 | #include <linux/ide.h> | ||
12 | #include <linux/init.h> | ||
13 | |||
14 | #include <asm/ecard.h> | ||
15 | |||
16 | /* | ||
17 | * Something like this really should be in generic code, but isn't. | ||
18 | */ | ||
19 | static ide_hwif_t * | ||
20 | rapide_locate_hwif(void __iomem *base, void __iomem *ctrl, unsigned int sz, int irq) | ||
21 | { | ||
22 | unsigned long port = (unsigned long)base; | ||
23 | ide_hwif_t *hwif; | ||
24 | int index, i; | ||
25 | |||
26 | for (index = 0; index < MAX_HWIFS; ++index) { | ||
27 | hwif = ide_hwifs + index; | ||
28 | if (hwif->io_ports[IDE_DATA_OFFSET] == port) | ||
29 | goto found; | ||
30 | } | ||
31 | |||
32 | for (index = 0; index < MAX_HWIFS; ++index) { | ||
33 | hwif = ide_hwifs + index; | ||
34 | if (hwif->io_ports[IDE_DATA_OFFSET] == 0) | ||
35 | goto found; | ||
36 | } | ||
37 | |||
38 | return NULL; | ||
39 | |||
40 | found: | ||
41 | for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++) { | ||
42 | hwif->hw.io_ports[i] = port; | ||
43 | hwif->io_ports[i] = port; | ||
44 | port += sz; | ||
45 | } | ||
46 | hwif->hw.io_ports[IDE_CONTROL_OFFSET] = (unsigned long)ctrl; | ||
47 | hwif->io_ports[IDE_CONTROL_OFFSET] = (unsigned long)ctrl; | ||
48 | hwif->hw.irq = hwif->irq = irq; | ||
49 | hwif->mmio = 2; | ||
50 | default_hwif_mmiops(hwif); | ||
51 | |||
52 | return hwif; | ||
53 | } | ||
54 | |||
55 | static int __devinit | ||
56 | rapide_probe(struct expansion_card *ec, const struct ecard_id *id) | ||
57 | { | ||
58 | ide_hwif_t *hwif; | ||
59 | void __iomem *base; | ||
60 | int ret; | ||
61 | |||
62 | ret = ecard_request_resources(ec); | ||
63 | if (ret) | ||
64 | goto out; | ||
65 | |||
66 | base = ioremap(ecard_resource_start(ec, ECARD_RES_MEMC), | ||
67 | ecard_resource_len(ec, ECARD_RES_MEMC)); | ||
68 | if (!base) { | ||
69 | ret = -ENOMEM; | ||
70 | goto release; | ||
71 | } | ||
72 | |||
73 | hwif = rapide_locate_hwif(base, base + 0x818, 1 << 6, ec->irq); | ||
74 | if (hwif) { | ||
75 | hwif->hwif_data = base; | ||
76 | hwif->gendev.parent = &ec->dev; | ||
77 | hwif->noprobe = 0; | ||
78 | probe_hwif_init(hwif); | ||
79 | create_proc_ide_interfaces(); | ||
80 | ecard_set_drvdata(ec, hwif); | ||
81 | goto out; | ||
82 | } | ||
83 | |||
84 | iounmap(base); | ||
85 | release: | ||
86 | ecard_release_resources(ec); | ||
87 | out: | ||
88 | return ret; | ||
89 | } | ||
90 | |||
91 | static void __devexit rapide_remove(struct expansion_card *ec) | ||
92 | { | ||
93 | ide_hwif_t *hwif = ecard_get_drvdata(ec); | ||
94 | |||
95 | ecard_set_drvdata(ec, NULL); | ||
96 | |||
97 | /* there must be a better way */ | ||
98 | ide_unregister(hwif - ide_hwifs); | ||
99 | iounmap(hwif->hwif_data); | ||
100 | ecard_release_resources(ec); | ||
101 | } | ||
102 | |||
103 | static struct ecard_id rapide_ids[] = { | ||
104 | { MANU_YELLOWSTONE, PROD_YELLOWSTONE_RAPIDE32 }, | ||
105 | { 0xffff, 0xffff } | ||
106 | }; | ||
107 | |||
108 | static struct ecard_driver rapide_driver = { | ||
109 | .probe = rapide_probe, | ||
110 | .remove = __devexit_p(rapide_remove), | ||
111 | .id_table = rapide_ids, | ||
112 | .drv = { | ||
113 | .name = "rapide", | ||
114 | }, | ||
115 | }; | ||
116 | |||
117 | static int __init rapide_init(void) | ||
118 | { | ||
119 | return ecard_register_driver(&rapide_driver); | ||
120 | } | ||
121 | |||
122 | MODULE_LICENSE("GPL"); | ||
123 | MODULE_DESCRIPTION("Yellowstone RAPIDE driver"); | ||
124 | |||
125 | module_init(rapide_init); | ||
diff --git a/drivers/ide/cris/Makefile b/drivers/ide/cris/Makefile new file mode 100644 index 000000000000..fdc294325d00 --- /dev/null +++ b/drivers/ide/cris/Makefile | |||
@@ -0,0 +1,3 @@ | |||
1 | EXTRA_CFLAGS += -Idrivers/ide | ||
2 | |||
3 | obj-$(CONFIG_ETRAX_ARCH_V10) += ide-v10.o | ||
diff --git a/drivers/ide/cris/ide-v10.c b/drivers/ide/cris/ide-v10.c new file mode 100644 index 000000000000..5b40220d3ddc --- /dev/null +++ b/drivers/ide/cris/ide-v10.c | |||
@@ -0,0 +1,842 @@ | |||
1 | /* $Id: ide.c,v 1.4 2004/10/12 07:55:48 starvik Exp $ | ||
2 | * | ||
3 | * Etrax specific IDE functions, like init and PIO-mode setting etc. | ||
4 | * Almost the entire ide.c is used for the rest of the Etrax ATA driver. | ||
5 | * Copyright (c) 2000-2004 Axis Communications AB | ||
6 | * | ||
7 | * Authors: Bjorn Wesen (initial version) | ||
8 | * Mikael Starvik (pio setup stuff, Linux 2.6 port) | ||
9 | */ | ||
10 | |||
11 | /* Regarding DMA: | ||
12 | * | ||
13 | * There are two forms of DMA - "DMA handshaking" between the interface and the drive, | ||
14 | * and DMA between the memory and the interface. We can ALWAYS use the latter, since it's | ||
15 | * something built-in in the Etrax. However only some drives support the DMA-mode handshaking | ||
16 | * on the ATA-bus. The normal PC driver and Triton interface disables memory-if DMA when the | ||
17 | * device can't do DMA handshaking for some stupid reason. We don't need to do that. | ||
18 | */ | ||
19 | |||
20 | #undef REALLY_SLOW_IO /* most systems can safely undef this */ | ||
21 | |||
22 | #include <linux/config.h> | ||
23 | #include <linux/types.h> | ||
24 | #include <linux/kernel.h> | ||
25 | #include <linux/timer.h> | ||
26 | #include <linux/mm.h> | ||
27 | #include <linux/interrupt.h> | ||
28 | #include <linux/delay.h> | ||
29 | #include <linux/blkdev.h> | ||
30 | #include <linux/hdreg.h> | ||
31 | #include <linux/ide.h> | ||
32 | #include <linux/init.h> | ||
33 | #include <linux/scatterlist.h> | ||
34 | |||
35 | #include <asm/io.h> | ||
36 | #include <asm/arch/svinto.h> | ||
37 | #include <asm/dma.h> | ||
38 | |||
39 | /* number of Etrax DMA descriptors */ | ||
40 | #define MAX_DMA_DESCRS 64 | ||
41 | |||
42 | /* number of times to retry busy-flags when reading/writing IDE-registers | ||
43 | * this can't be too high because a hung harddisk might cause the watchdog | ||
44 | * to trigger (sometimes INB and OUTB are called with irq's disabled) | ||
45 | */ | ||
46 | |||
47 | #define IDE_REGISTER_TIMEOUT 300 | ||
48 | |||
49 | static int e100_read_command = 0; | ||
50 | |||
51 | #define LOWDB(x) | ||
52 | #define D(x) | ||
53 | |||
54 | static int e100_ide_build_dmatable (ide_drive_t *drive); | ||
55 | static ide_startstop_t etrax_dma_intr (ide_drive_t *drive); | ||
56 | |||
57 | void | ||
58 | etrax100_ide_outw(unsigned short data, unsigned long reg) { | ||
59 | int timeleft; | ||
60 | LOWDB(printk("ow: data 0x%x, reg 0x%x\n", data, reg)); | ||
61 | |||
62 | /* note the lack of handling any timeouts. we stop waiting, but we don't | ||
63 | * really notify anybody. | ||
64 | */ | ||
65 | |||
66 | timeleft = IDE_REGISTER_TIMEOUT; | ||
67 | /* wait for busy flag */ | ||
68 | while(timeleft && (*R_ATA_STATUS_DATA & IO_MASK(R_ATA_STATUS_DATA, busy))) | ||
69 | timeleft--; | ||
70 | |||
71 | /* | ||
72 | * Fall through at a timeout, so the ongoing command will be | ||
73 | * aborted by the write below, which is expected to be a dummy | ||
74 | * command to the command register. This happens when a faulty | ||
75 | * drive times out on a command. See comment on timeout in | ||
76 | * INB. | ||
77 | */ | ||
78 | if(!timeleft) | ||
79 | printk("ATA timeout reg 0x%lx := 0x%x\n", reg, data); | ||
80 | |||
81 | *R_ATA_CTRL_DATA = reg | data; /* write data to the drive's register */ | ||
82 | |||
83 | timeleft = IDE_REGISTER_TIMEOUT; | ||
84 | /* wait for transmitter ready */ | ||
85 | while(timeleft && !(*R_ATA_STATUS_DATA & | ||
86 | IO_MASK(R_ATA_STATUS_DATA, tr_rdy))) | ||
87 | timeleft--; | ||
88 | } | ||
89 | |||
90 | void | ||
91 | etrax100_ide_outb(unsigned char data, unsigned long reg) | ||
92 | { | ||
93 | etrax100_ide_outw(data, reg); | ||
94 | } | ||
95 | |||
96 | void | ||
97 | etrax100_ide_outbsync(ide_drive_t *drive, u8 addr, unsigned long port) | ||
98 | { | ||
99 | etrax100_ide_outw(addr, port); | ||
100 | } | ||
101 | |||
102 | unsigned short | ||
103 | etrax100_ide_inw(unsigned long reg) { | ||
104 | int status; | ||
105 | int timeleft; | ||
106 | |||
107 | timeleft = IDE_REGISTER_TIMEOUT; | ||
108 | /* wait for busy flag */ | ||
109 | while(timeleft && (*R_ATA_STATUS_DATA & IO_MASK(R_ATA_STATUS_DATA, busy))) | ||
110 | timeleft--; | ||
111 | |||
112 | if(!timeleft) { | ||
113 | /* | ||
114 | * If we're asked to read the status register, like for | ||
115 | * example when a command does not complete for an | ||
116 | * extended time, but the ATA interface is stuck in a | ||
117 | * busy state at the *ETRAX* ATA interface level (as has | ||
118 | * happened repeatedly with at least one bad disk), then | ||
119 | * the best thing to do is to pretend that we read | ||
120 | * "busy" in the status register, so the IDE driver will | ||
121 | * time-out, abort the ongoing command and perform a | ||
122 | * reset sequence. Note that the subsequent OUT_BYTE | ||
123 | * call will also timeout on busy, but as long as the | ||
124 | * write is still performed, everything will be fine. | ||
125 | */ | ||
126 | if ((reg & IO_MASK (R_ATA_CTRL_DATA, addr)) | ||
127 | == IO_FIELD (R_ATA_CTRL_DATA, addr, IDE_STATUS_OFFSET)) | ||
128 | return BUSY_STAT; | ||
129 | else | ||
130 | /* For other rare cases we assume 0 is good enough. */ | ||
131 | return 0; | ||
132 | } | ||
133 | |||
134 | *R_ATA_CTRL_DATA = reg | IO_STATE(R_ATA_CTRL_DATA, rw, read); /* read data */ | ||
135 | |||
136 | timeleft = IDE_REGISTER_TIMEOUT; | ||
137 | /* wait for available */ | ||
138 | while(timeleft && !((status = *R_ATA_STATUS_DATA) & | ||
139 | IO_MASK(R_ATA_STATUS_DATA, dav))) | ||
140 | timeleft--; | ||
141 | |||
142 | if(!timeleft) | ||
143 | return 0; | ||
144 | |||
145 | LOWDB(printk("inb: 0x%x from reg 0x%x\n", status & 0xff, reg)); | ||
146 | |||
147 | return (unsigned short)status; | ||
148 | } | ||
149 | |||
150 | unsigned char | ||
151 | etrax100_ide_inb(unsigned long reg) | ||
152 | { | ||
153 | return (unsigned char)etrax100_ide_inw(reg); | ||
154 | } | ||
155 | |||
156 | /* PIO timing (in R_ATA_CONFIG) | ||
157 | * | ||
158 | * _____________________________ | ||
159 | * ADDRESS : ________/ | ||
160 | * | ||
161 | * _______________ | ||
162 | * DIOR : ____________/ \__________ | ||
163 | * | ||
164 | * _______________ | ||
165 | * DATA : XXXXXXXXXXXXXXXX_______________XXXXXXXX | ||
166 | * | ||
167 | * | ||
168 | * DIOR is unbuffered while address and data is buffered. | ||
169 | * This creates two problems: | ||
170 | * 1. The DIOR pulse is to early (because it is unbuffered) | ||
171 | * 2. The rise time of DIOR is long | ||
172 | * | ||
173 | * There are at least three different plausible solutions | ||
174 | * 1. Use a pad capable of larger currents in Etrax | ||
175 | * 2. Use an external buffer | ||
176 | * 3. Make the strobe pulse longer | ||
177 | * | ||
178 | * Some of the strobe timings below are modified to compensate | ||
179 | * for this. This implies a slight performance decrease. | ||
180 | * | ||
181 | * THIS SHOULD NEVER BE CHANGED! | ||
182 | * | ||
183 | * TODO: Is this true for the latest LX boards still ? | ||
184 | */ | ||
185 | |||
186 | #define ATA_DMA2_STROBE 4 | ||
187 | #define ATA_DMA2_HOLD 0 | ||
188 | #define ATA_DMA1_STROBE 4 | ||
189 | #define ATA_DMA1_HOLD 1 | ||
190 | #define ATA_DMA0_STROBE 12 | ||
191 | #define ATA_DMA0_HOLD 9 | ||
192 | #define ATA_PIO4_SETUP 1 | ||
193 | #define ATA_PIO4_STROBE 5 | ||
194 | #define ATA_PIO4_HOLD 0 | ||
195 | #define ATA_PIO3_SETUP 1 | ||
196 | #define ATA_PIO3_STROBE 5 | ||
197 | #define ATA_PIO3_HOLD 1 | ||
198 | #define ATA_PIO2_SETUP 1 | ||
199 | #define ATA_PIO2_STROBE 6 | ||
200 | #define ATA_PIO2_HOLD 2 | ||
201 | #define ATA_PIO1_SETUP 2 | ||
202 | #define ATA_PIO1_STROBE 11 | ||
203 | #define ATA_PIO1_HOLD 4 | ||
204 | #define ATA_PIO0_SETUP 4 | ||
205 | #define ATA_PIO0_STROBE 19 | ||
206 | #define ATA_PIO0_HOLD 4 | ||
207 | |||
208 | static int e100_dma_check (ide_drive_t *drive); | ||
209 | static void e100_dma_start(ide_drive_t *drive); | ||
210 | static int e100_dma_end (ide_drive_t *drive); | ||
211 | static void e100_ide_input_data (ide_drive_t *drive, void *, unsigned int); | ||
212 | static void e100_ide_output_data (ide_drive_t *drive, void *, unsigned int); | ||
213 | static void e100_atapi_input_bytes(ide_drive_t *drive, void *, unsigned int); | ||
214 | static void e100_atapi_output_bytes(ide_drive_t *drive, void *, unsigned int); | ||
215 | static int e100_dma_off (ide_drive_t *drive); | ||
216 | |||
217 | |||
218 | /* | ||
219 | * good_dma_drives() lists the model names (from "hdparm -i") | ||
220 | * of drives which do not support mword2 DMA but which are | ||
221 | * known to work fine with this interface under Linux. | ||
222 | */ | ||
223 | |||
224 | const char *good_dma_drives[] = {"Micropolis 2112A", | ||
225 | "CONNER CTMA 4000", | ||
226 | "CONNER CTT8000-A", | ||
227 | NULL}; | ||
228 | |||
229 | static void tune_e100_ide(ide_drive_t *drive, byte pio) | ||
230 | { | ||
231 | pio = 4; | ||
232 | /* pio = ide_get_best_pio_mode(drive, pio, 4, NULL); */ | ||
233 | |||
234 | /* set pio mode! */ | ||
235 | |||
236 | switch(pio) { | ||
237 | case 0: | ||
238 | *R_ATA_CONFIG = ( IO_FIELD( R_ATA_CONFIG, enable, 1 ) | | ||
239 | IO_FIELD( R_ATA_CONFIG, dma_strobe, ATA_DMA2_STROBE ) | | ||
240 | IO_FIELD( R_ATA_CONFIG, dma_hold, ATA_DMA2_HOLD ) | | ||
241 | IO_FIELD( R_ATA_CONFIG, pio_setup, ATA_PIO0_SETUP ) | | ||
242 | IO_FIELD( R_ATA_CONFIG, pio_strobe, ATA_PIO0_STROBE ) | | ||
243 | IO_FIELD( R_ATA_CONFIG, pio_hold, ATA_PIO0_HOLD ) ); | ||
244 | break; | ||
245 | case 1: | ||
246 | *R_ATA_CONFIG = ( IO_FIELD( R_ATA_CONFIG, enable, 1 ) | | ||
247 | IO_FIELD( R_ATA_CONFIG, dma_strobe, ATA_DMA2_STROBE ) | | ||
248 | IO_FIELD( R_ATA_CONFIG, dma_hold, ATA_DMA2_HOLD ) | | ||
249 | IO_FIELD( R_ATA_CONFIG, pio_setup, ATA_PIO1_SETUP ) | | ||
250 | IO_FIELD( R_ATA_CONFIG, pio_strobe, ATA_PIO1_STROBE ) | | ||
251 | IO_FIELD( R_ATA_CONFIG, pio_hold, ATA_PIO1_HOLD ) ); | ||
252 | break; | ||
253 | case 2: | ||
254 | *R_ATA_CONFIG = ( IO_FIELD( R_ATA_CONFIG, enable, 1 ) | | ||
255 | IO_FIELD( R_ATA_CONFIG, dma_strobe, ATA_DMA2_STROBE ) | | ||
256 | IO_FIELD( R_ATA_CONFIG, dma_hold, ATA_DMA2_HOLD ) | | ||
257 | IO_FIELD( R_ATA_CONFIG, pio_setup, ATA_PIO2_SETUP ) | | ||
258 | IO_FIELD( R_ATA_CONFIG, pio_strobe, ATA_PIO2_STROBE ) | | ||
259 | IO_FIELD( R_ATA_CONFIG, pio_hold, ATA_PIO2_HOLD ) ); | ||
260 | break; | ||
261 | case 3: | ||
262 | *R_ATA_CONFIG = ( IO_FIELD( R_ATA_CONFIG, enable, 1 ) | | ||
263 | IO_FIELD( R_ATA_CONFIG, dma_strobe, ATA_DMA2_STROBE ) | | ||
264 | IO_FIELD( R_ATA_CONFIG, dma_hold, ATA_DMA2_HOLD ) | | ||
265 | IO_FIELD( R_ATA_CONFIG, pio_setup, ATA_PIO3_SETUP ) | | ||
266 | IO_FIELD( R_ATA_CONFIG, pio_strobe, ATA_PIO3_STROBE ) | | ||
267 | IO_FIELD( R_ATA_CONFIG, pio_hold, ATA_PIO3_HOLD ) ); | ||
268 | break; | ||
269 | case 4: | ||
270 | *R_ATA_CONFIG = ( IO_FIELD( R_ATA_CONFIG, enable, 1 ) | | ||
271 | IO_FIELD( R_ATA_CONFIG, dma_strobe, ATA_DMA2_STROBE ) | | ||
272 | IO_FIELD( R_ATA_CONFIG, dma_hold, ATA_DMA2_HOLD ) | | ||
273 | IO_FIELD( R_ATA_CONFIG, pio_setup, ATA_PIO4_SETUP ) | | ||
274 | IO_FIELD( R_ATA_CONFIG, pio_strobe, ATA_PIO4_STROBE ) | | ||
275 | IO_FIELD( R_ATA_CONFIG, pio_hold, ATA_PIO4_HOLD ) ); | ||
276 | break; | ||
277 | } | ||
278 | } | ||
279 | |||
280 | static int e100_dma_setup(ide_drive_t *drive) | ||
281 | { | ||
282 | struct request *rq = drive->hwif->hwgroup->rq; | ||
283 | |||
284 | if (rq_data_dir(rq)) { | ||
285 | e100_read_command = 0; | ||
286 | |||
287 | RESET_DMA(ATA_TX_DMA_NBR); /* sometimes the DMA channel get stuck so we need to do this */ | ||
288 | WAIT_DMA(ATA_TX_DMA_NBR); | ||
289 | } else { | ||
290 | e100_read_command = 1; | ||
291 | |||
292 | RESET_DMA(ATA_RX_DMA_NBR); /* sometimes the DMA channel get stuck so we need to do this */ | ||
293 | WAIT_DMA(ATA_RX_DMA_NBR); | ||
294 | } | ||
295 | |||
296 | /* set up the Etrax DMA descriptors */ | ||
297 | if (e100_ide_build_dmatable(drive)) { | ||
298 | ide_map_sg(drive, rq); | ||
299 | return 1; | ||
300 | } | ||
301 | |||
302 | return 0; | ||
303 | } | ||
304 | |||
305 | static void e100_dma_exec_cmd(ide_drive_t *drive, u8 command) | ||
306 | { | ||
307 | /* set the irq handler which will finish the request when DMA is done */ | ||
308 | ide_set_handler(drive, &etrax_dma_intr, WAIT_CMD, NULL); | ||
309 | |||
310 | /* issue cmd to drive */ | ||
311 | etrax100_ide_outb(command, IDE_COMMAND_REG); | ||
312 | } | ||
313 | |||
314 | void __init | ||
315 | init_e100_ide (void) | ||
316 | { | ||
317 | volatile unsigned int dummy; | ||
318 | int h; | ||
319 | |||
320 | printk("ide: ETRAX 100LX built-in ATA DMA controller\n"); | ||
321 | |||
322 | /* first fill in some stuff in the ide_hwifs fields */ | ||
323 | |||
324 | for(h = 0; h < MAX_HWIFS; h++) { | ||
325 | ide_hwif_t *hwif = &ide_hwifs[h]; | ||
326 | hwif->mmio = 2; | ||
327 | hwif->chipset = ide_etrax100; | ||
328 | hwif->tuneproc = &tune_e100_ide; | ||
329 | hwif->ata_input_data = &e100_ide_input_data; | ||
330 | hwif->ata_output_data = &e100_ide_output_data; | ||
331 | hwif->atapi_input_bytes = &e100_atapi_input_bytes; | ||
332 | hwif->atapi_output_bytes = &e100_atapi_output_bytes; | ||
333 | hwif->ide_dma_check = &e100_dma_check; | ||
334 | hwif->ide_dma_end = &e100_dma_end; | ||
335 | hwif->dma_setup = &e100_dma_setup; | ||
336 | hwif->dma_exec_cmd = &e100_dma_exec_cmd; | ||
337 | hwif->dma_start = &e100_dma_start; | ||
338 | hwif->OUTB = &etrax100_ide_outb; | ||
339 | hwif->OUTW = &etrax100_ide_outw; | ||
340 | hwif->OUTBSYNC = &etrax100_ide_outbsync; | ||
341 | hwif->INB = &etrax100_ide_inb; | ||
342 | hwif->INW = &etrax100_ide_inw; | ||
343 | hwif->ide_dma_off_quietly = &e100_dma_off; | ||
344 | } | ||
345 | |||
346 | /* actually reset and configure the etrax100 ide/ata interface */ | ||
347 | |||
348 | *R_ATA_CTRL_DATA = 0; | ||
349 | *R_ATA_TRANSFER_CNT = 0; | ||
350 | *R_ATA_CONFIG = 0; | ||
351 | |||
352 | genconfig_shadow = (genconfig_shadow & | ||
353 | ~IO_MASK(R_GEN_CONFIG, dma2) & | ||
354 | ~IO_MASK(R_GEN_CONFIG, dma3) & | ||
355 | ~IO_MASK(R_GEN_CONFIG, ata)) | | ||
356 | ( IO_STATE( R_GEN_CONFIG, dma3, ata ) | | ||
357 | IO_STATE( R_GEN_CONFIG, dma2, ata ) | | ||
358 | IO_STATE( R_GEN_CONFIG, ata, select ) ); | ||
359 | |||
360 | *R_GEN_CONFIG = genconfig_shadow; | ||
361 | |||
362 | /* pull the chosen /reset-line low */ | ||
363 | |||
364 | #ifdef CONFIG_ETRAX_IDE_G27_RESET | ||
365 | REG_SHADOW_SET(R_PORT_G_DATA, port_g_data_shadow, 27, 0); | ||
366 | #endif | ||
367 | #ifdef CONFIG_ETRAX_IDE_CSE1_16_RESET | ||
368 | REG_SHADOW_SET(port_cse1_addr, port_cse1_shadow, 16, 0); | ||
369 | #endif | ||
370 | #ifdef CONFIG_ETRAX_IDE_CSP0_8_RESET | ||
371 | REG_SHADOW_SET(port_csp0_addr, port_csp0_shadow, 8, 0); | ||
372 | #endif | ||
373 | #ifdef CONFIG_ETRAX_IDE_PB7_RESET | ||
374 | port_pb_dir_shadow = port_pb_dir_shadow | | ||
375 | IO_STATE(R_PORT_PB_DIR, dir7, output); | ||
376 | *R_PORT_PB_DIR = port_pb_dir_shadow; | ||
377 | REG_SHADOW_SET(R_PORT_PB_DATA, port_pb_data_shadow, 7, 1); | ||
378 | #endif | ||
379 | |||
380 | /* wait some */ | ||
381 | |||
382 | udelay(25); | ||
383 | |||
384 | /* de-assert bus-reset */ | ||
385 | |||
386 | #ifdef CONFIG_ETRAX_IDE_CSE1_16_RESET | ||
387 | REG_SHADOW_SET(port_cse1_addr, port_cse1_shadow, 16, 1); | ||
388 | #endif | ||
389 | #ifdef CONFIG_ETRAX_IDE_CSP0_8_RESET | ||
390 | REG_SHADOW_SET(port_csp0_addr, port_csp0_shadow, 8, 1); | ||
391 | #endif | ||
392 | #ifdef CONFIG_ETRAX_IDE_G27_RESET | ||
393 | REG_SHADOW_SET(R_PORT_G_DATA, port_g_data_shadow, 27, 1); | ||
394 | #endif | ||
395 | |||
396 | /* make a dummy read to set the ata controller in a proper state */ | ||
397 | dummy = *R_ATA_STATUS_DATA; | ||
398 | |||
399 | *R_ATA_CONFIG = ( IO_FIELD( R_ATA_CONFIG, enable, 1 ) | | ||
400 | IO_FIELD( R_ATA_CONFIG, dma_strobe, ATA_DMA2_STROBE ) | | ||
401 | IO_FIELD( R_ATA_CONFIG, dma_hold, ATA_DMA2_HOLD ) | | ||
402 | IO_FIELD( R_ATA_CONFIG, pio_setup, ATA_PIO4_SETUP ) | | ||
403 | IO_FIELD( R_ATA_CONFIG, pio_strobe, ATA_PIO4_STROBE ) | | ||
404 | IO_FIELD( R_ATA_CONFIG, pio_hold, ATA_PIO4_HOLD ) ); | ||
405 | |||
406 | *R_ATA_CTRL_DATA = ( IO_STATE( R_ATA_CTRL_DATA, rw, read) | | ||
407 | IO_FIELD( R_ATA_CTRL_DATA, addr, 1 ) ); | ||
408 | |||
409 | while(*R_ATA_STATUS_DATA & IO_MASK(R_ATA_STATUS_DATA, busy)); /* wait for busy flag*/ | ||
410 | |||
411 | *R_IRQ_MASK0_SET = ( IO_STATE( R_IRQ_MASK0_SET, ata_irq0, set ) | | ||
412 | IO_STATE( R_IRQ_MASK0_SET, ata_irq1, set ) | | ||
413 | IO_STATE( R_IRQ_MASK0_SET, ata_irq2, set ) | | ||
414 | IO_STATE( R_IRQ_MASK0_SET, ata_irq3, set ) ); | ||
415 | |||
416 | printk("ide: waiting %d seconds for drives to regain consciousness\n", | ||
417 | CONFIG_ETRAX_IDE_DELAY); | ||
418 | |||
419 | h = jiffies + (CONFIG_ETRAX_IDE_DELAY * HZ); | ||
420 | while(time_before(jiffies, h)) /* nothing */ ; | ||
421 | |||
422 | /* reset the dma channels we will use */ | ||
423 | |||
424 | RESET_DMA(ATA_TX_DMA_NBR); | ||
425 | RESET_DMA(ATA_RX_DMA_NBR); | ||
426 | WAIT_DMA(ATA_TX_DMA_NBR); | ||
427 | WAIT_DMA(ATA_RX_DMA_NBR); | ||
428 | |||
429 | } | ||
430 | |||
431 | static int e100_dma_off (ide_drive_t *drive) | ||
432 | { | ||
433 | return 0; | ||
434 | } | ||
435 | |||
436 | static etrax_dma_descr mydescr; | ||
437 | |||
438 | /* | ||
439 | * The following routines are mainly used by the ATAPI drivers. | ||
440 | * | ||
441 | * These routines will round up any request for an odd number of bytes, | ||
442 | * so if an odd bytecount is specified, be sure that there's at least one | ||
443 | * extra byte allocated for the buffer. | ||
444 | */ | ||
445 | static void | ||
446 | e100_atapi_input_bytes (ide_drive_t *drive, void *buffer, unsigned int bytecount) | ||
447 | { | ||
448 | unsigned long data_reg = IDE_DATA_REG; | ||
449 | |||
450 | D(printk("atapi_input_bytes, dreg 0x%x, buffer 0x%x, count %d\n", | ||
451 | data_reg, buffer, bytecount)); | ||
452 | |||
453 | if(bytecount & 1) { | ||
454 | printk("warning, odd bytecount in cdrom_in_bytes = %d.\n", bytecount); | ||
455 | bytecount++; /* to round off */ | ||
456 | } | ||
457 | |||
458 | /* make sure the DMA channel is available */ | ||
459 | RESET_DMA(ATA_RX_DMA_NBR); | ||
460 | WAIT_DMA(ATA_RX_DMA_NBR); | ||
461 | |||
462 | /* setup DMA descriptor */ | ||
463 | |||
464 | mydescr.sw_len = bytecount; | ||
465 | mydescr.ctrl = d_eol; | ||
466 | mydescr.buf = virt_to_phys(buffer); | ||
467 | |||
468 | /* start the dma channel */ | ||
469 | |||
470 | *R_DMA_CH3_FIRST = virt_to_phys(&mydescr); | ||
471 | *R_DMA_CH3_CMD = IO_STATE(R_DMA_CH3_CMD, cmd, start); | ||
472 | |||
473 | /* initiate a multi word dma read using PIO handshaking */ | ||
474 | |||
475 | *R_ATA_TRANSFER_CNT = IO_FIELD(R_ATA_TRANSFER_CNT, count, bytecount >> 1); | ||
476 | |||
477 | *R_ATA_CTRL_DATA = data_reg | | ||
478 | IO_STATE(R_ATA_CTRL_DATA, rw, read) | | ||
479 | IO_STATE(R_ATA_CTRL_DATA, src_dst, dma) | | ||
480 | IO_STATE(R_ATA_CTRL_DATA, handsh, pio) | | ||
481 | IO_STATE(R_ATA_CTRL_DATA, multi, on) | | ||
482 | IO_STATE(R_ATA_CTRL_DATA, dma_size, word); | ||
483 | |||
484 | /* wait for completion */ | ||
485 | |||
486 | LED_DISK_READ(1); | ||
487 | WAIT_DMA(ATA_RX_DMA_NBR); | ||
488 | LED_DISK_READ(0); | ||
489 | |||
490 | #if 0 | ||
491 | /* old polled transfer code | ||
492 | * this should be moved into a new function that can do polled | ||
493 | * transfers if DMA is not available | ||
494 | */ | ||
495 | |||
496 | /* initiate a multi word read */ | ||
497 | |||
498 | *R_ATA_TRANSFER_CNT = wcount << 1; | ||
499 | |||
500 | *R_ATA_CTRL_DATA = data_reg | | ||
501 | IO_STATE(R_ATA_CTRL_DATA, rw, read) | | ||
502 | IO_STATE(R_ATA_CTRL_DATA, src_dst, register) | | ||
503 | IO_STATE(R_ATA_CTRL_DATA, handsh, pio) | | ||
504 | IO_STATE(R_ATA_CTRL_DATA, multi, on) | | ||
505 | IO_STATE(R_ATA_CTRL_DATA, dma_size, word); | ||
506 | |||
507 | /* svinto has a latency until the busy bit actually is set */ | ||
508 | |||
509 | nop(); nop(); | ||
510 | nop(); nop(); | ||
511 | nop(); nop(); | ||
512 | nop(); nop(); | ||
513 | nop(); nop(); | ||
514 | |||
515 | /* unit should be busy during multi transfer */ | ||
516 | while((status = *R_ATA_STATUS_DATA) & IO_MASK(R_ATA_STATUS_DATA, busy)) { | ||
517 | while(!(status & IO_MASK(R_ATA_STATUS_DATA, dav))) | ||
518 | status = *R_ATA_STATUS_DATA; | ||
519 | *ptr++ = (unsigned short)(status & 0xffff); | ||
520 | } | ||
521 | #endif | ||
522 | } | ||
523 | |||
524 | static void | ||
525 | e100_atapi_output_bytes (ide_drive_t *drive, void *buffer, unsigned int bytecount) | ||
526 | { | ||
527 | unsigned long data_reg = IDE_DATA_REG; | ||
528 | |||
529 | D(printk("atapi_output_bytes, dreg 0x%x, buffer 0x%x, count %d\n", | ||
530 | data_reg, buffer, bytecount)); | ||
531 | |||
532 | if(bytecount & 1) { | ||
533 | printk("odd bytecount %d in atapi_out_bytes!\n", bytecount); | ||
534 | bytecount++; | ||
535 | } | ||
536 | |||
537 | /* make sure the DMA channel is available */ | ||
538 | RESET_DMA(ATA_TX_DMA_NBR); | ||
539 | WAIT_DMA(ATA_TX_DMA_NBR); | ||
540 | |||
541 | /* setup DMA descriptor */ | ||
542 | |||
543 | mydescr.sw_len = bytecount; | ||
544 | mydescr.ctrl = d_eol; | ||
545 | mydescr.buf = virt_to_phys(buffer); | ||
546 | |||
547 | /* start the dma channel */ | ||
548 | |||
549 | *R_DMA_CH2_FIRST = virt_to_phys(&mydescr); | ||
550 | *R_DMA_CH2_CMD = IO_STATE(R_DMA_CH2_CMD, cmd, start); | ||
551 | |||
552 | /* initiate a multi word dma write using PIO handshaking */ | ||
553 | |||
554 | *R_ATA_TRANSFER_CNT = IO_FIELD(R_ATA_TRANSFER_CNT, count, bytecount >> 1); | ||
555 | |||
556 | *R_ATA_CTRL_DATA = data_reg | | ||
557 | IO_STATE(R_ATA_CTRL_DATA, rw, write) | | ||
558 | IO_STATE(R_ATA_CTRL_DATA, src_dst, dma) | | ||
559 | IO_STATE(R_ATA_CTRL_DATA, handsh, pio) | | ||
560 | IO_STATE(R_ATA_CTRL_DATA, multi, on) | | ||
561 | IO_STATE(R_ATA_CTRL_DATA, dma_size, word); | ||
562 | |||
563 | /* wait for completion */ | ||
564 | |||
565 | LED_DISK_WRITE(1); | ||
566 | WAIT_DMA(ATA_TX_DMA_NBR); | ||
567 | LED_DISK_WRITE(0); | ||
568 | |||
569 | #if 0 | ||
570 | /* old polled write code - see comment in input_bytes */ | ||
571 | |||
572 | /* wait for busy flag */ | ||
573 | while(*R_ATA_STATUS_DATA & IO_MASK(R_ATA_STATUS_DATA, busy)); | ||
574 | |||
575 | /* initiate a multi word write */ | ||
576 | |||
577 | *R_ATA_TRANSFER_CNT = bytecount >> 1; | ||
578 | |||
579 | ctrl = data_reg | | ||
580 | IO_STATE(R_ATA_CTRL_DATA, rw, write) | | ||
581 | IO_STATE(R_ATA_CTRL_DATA, src_dst, register) | | ||
582 | IO_STATE(R_ATA_CTRL_DATA, handsh, pio) | | ||
583 | IO_STATE(R_ATA_CTRL_DATA, multi, on) | | ||
584 | IO_STATE(R_ATA_CTRL_DATA, dma_size, word); | ||
585 | |||
586 | LED_DISK_WRITE(1); | ||
587 | |||
588 | /* Etrax will set busy = 1 until the multi pio transfer has finished | ||
589 | * and tr_rdy = 1 after each successful word transfer. | ||
590 | * When the last byte has been transferred Etrax will first set tr_tdy = 1 | ||
591 | * and then busy = 0 (not in the same cycle). If we read busy before it | ||
592 | * has been set to 0 we will think that we should transfer more bytes | ||
593 | * and then tr_rdy would be 0 forever. This is solved by checking busy | ||
594 | * in the inner loop. | ||
595 | */ | ||
596 | |||
597 | do { | ||
598 | *R_ATA_CTRL_DATA = ctrl | *ptr++; | ||
599 | while(!(*R_ATA_STATUS_DATA & IO_MASK(R_ATA_STATUS_DATA, tr_rdy)) && | ||
600 | (*R_ATA_STATUS_DATA & IO_MASK(R_ATA_STATUS_DATA, busy))); | ||
601 | } while(*R_ATA_STATUS_DATA & IO_MASK(R_ATA_STATUS_DATA, busy)); | ||
602 | |||
603 | LED_DISK_WRITE(0); | ||
604 | #endif | ||
605 | |||
606 | } | ||
607 | |||
608 | /* | ||
609 | * This is used for most PIO data transfers *from* the IDE interface | ||
610 | */ | ||
611 | static void | ||
612 | e100_ide_input_data (ide_drive_t *drive, void *buffer, unsigned int wcount) | ||
613 | { | ||
614 | e100_atapi_input_bytes(drive, buffer, wcount << 2); | ||
615 | } | ||
616 | |||
617 | /* | ||
618 | * This is used for most PIO data transfers *to* the IDE interface | ||
619 | */ | ||
620 | static void | ||
621 | e100_ide_output_data (ide_drive_t *drive, void *buffer, unsigned int wcount) | ||
622 | { | ||
623 | e100_atapi_output_bytes(drive, buffer, wcount << 2); | ||
624 | } | ||
625 | |||
626 | /* we only have one DMA channel on the chip for ATA, so we can keep these statically */ | ||
627 | static etrax_dma_descr ata_descrs[MAX_DMA_DESCRS]; | ||
628 | static unsigned int ata_tot_size; | ||
629 | |||
630 | /* | ||
631 | * e100_ide_build_dmatable() prepares a dma request. | ||
632 | * Returns 0 if all went okay, returns 1 otherwise. | ||
633 | */ | ||
634 | static int e100_ide_build_dmatable (ide_drive_t *drive) | ||
635 | { | ||
636 | ide_hwif_t *hwif = HWIF(drive); | ||
637 | struct scatterlist* sg; | ||
638 | struct request *rq = HWGROUP(drive)->rq; | ||
639 | unsigned long size, addr; | ||
640 | unsigned int count = 0; | ||
641 | int i = 0; | ||
642 | |||
643 | sg = hwif->sg_table; | ||
644 | |||
645 | ata_tot_size = 0; | ||
646 | |||
647 | ide_map_sg(drive, rq); | ||
648 | |||
649 | i = hwif->sg_nents; | ||
650 | |||
651 | while(i) { | ||
652 | /* | ||
653 | * Determine addr and size of next buffer area. We assume that | ||
654 | * individual virtual buffers are always composed linearly in | ||
655 | * physical memory. For example, we assume that any 8kB buffer | ||
656 | * is always composed of two adjacent physical 4kB pages rather | ||
657 | * than two possibly non-adjacent physical 4kB pages. | ||
658 | */ | ||
659 | /* group sequential buffers into one large buffer */ | ||
660 | addr = page_to_phys(sg->page) + sg->offset; | ||
661 | size = sg_dma_len(sg); | ||
662 | while (sg++, --i) { | ||
663 | if ((addr + size) != page_to_phys(sg->page) + sg->offset) | ||
664 | break; | ||
665 | size += sg_dma_len(sg); | ||
666 | } | ||
667 | |||
668 | /* did we run out of descriptors? */ | ||
669 | |||
670 | if(count >= MAX_DMA_DESCRS) { | ||
671 | printk("%s: too few DMA descriptors\n", drive->name); | ||
672 | return 1; | ||
673 | } | ||
674 | |||
675 | /* however, this case is more difficult - R_ATA_TRANSFER_CNT cannot be more | ||
676 | than 65536 words per transfer, so in that case we need to either | ||
677 | 1) use a DMA interrupt to re-trigger R_ATA_TRANSFER_CNT and continue with | ||
678 | the descriptors, or | ||
679 | 2) simply do the request here, and get dma_intr to only ide_end_request on | ||
680 | those blocks that were actually set-up for transfer. | ||
681 | */ | ||
682 | |||
683 | if(ata_tot_size + size > 131072) { | ||
684 | printk("too large total ATA DMA request, %d + %d!\n", ata_tot_size, (int)size); | ||
685 | return 1; | ||
686 | } | ||
687 | |||
688 | /* If size > 65536 it has to be splitted into new descriptors. Since we don't handle | ||
689 | size > 131072 only one split is necessary */ | ||
690 | |||
691 | if(size > 65536) { | ||
692 | /* ok we want to do IO at addr, size bytes. set up a new descriptor entry */ | ||
693 | ata_descrs[count].sw_len = 0; /* 0 means 65536, this is a 16-bit field */ | ||
694 | ata_descrs[count].ctrl = 0; | ||
695 | ata_descrs[count].buf = addr; | ||
696 | ata_descrs[count].next = virt_to_phys(&ata_descrs[count + 1]); | ||
697 | count++; | ||
698 | ata_tot_size += 65536; | ||
699 | /* size and addr should refere to not handled data */ | ||
700 | size -= 65536; | ||
701 | addr += 65536; | ||
702 | } | ||
703 | /* ok we want to do IO at addr, size bytes. set up a new descriptor entry */ | ||
704 | if(size == 65536) { | ||
705 | ata_descrs[count].sw_len = 0; /* 0 means 65536, this is a 16-bit field */ | ||
706 | } else { | ||
707 | ata_descrs[count].sw_len = size; | ||
708 | } | ||
709 | ata_descrs[count].ctrl = 0; | ||
710 | ata_descrs[count].buf = addr; | ||
711 | ata_descrs[count].next = virt_to_phys(&ata_descrs[count + 1]); | ||
712 | count++; | ||
713 | ata_tot_size += size; | ||
714 | } | ||
715 | |||
716 | if (count) { | ||
717 | /* set the end-of-list flag on the last descriptor */ | ||
718 | ata_descrs[count - 1].ctrl |= d_eol; | ||
719 | /* return and say all is ok */ | ||
720 | return 0; | ||
721 | } | ||
722 | |||
723 | printk("%s: empty DMA table?\n", drive->name); | ||
724 | return 1; /* let the PIO routines handle this weirdness */ | ||
725 | } | ||
726 | |||
727 | static int config_drive_for_dma (ide_drive_t *drive) | ||
728 | { | ||
729 | const char **list; | ||
730 | struct hd_driveid *id = drive->id; | ||
731 | |||
732 | if (id && (id->capability & 1)) { | ||
733 | /* Enable DMA on any drive that supports mword2 DMA */ | ||
734 | if ((id->field_valid & 2) && (id->dma_mword & 0x404) == 0x404) { | ||
735 | drive->using_dma = 1; | ||
736 | return 0; /* DMA enabled */ | ||
737 | } | ||
738 | |||
739 | /* Consult the list of known "good" drives */ | ||
740 | list = good_dma_drives; | ||
741 | while (*list) { | ||
742 | if (!strcmp(*list++,id->model)) { | ||
743 | drive->using_dma = 1; | ||
744 | return 0; /* DMA enabled */ | ||
745 | } | ||
746 | } | ||
747 | } | ||
748 | return 1; /* DMA not enabled */ | ||
749 | } | ||
750 | |||
751 | /* | ||
752 | * etrax_dma_intr() is the handler for disk read/write DMA interrupts | ||
753 | */ | ||
754 | static ide_startstop_t etrax_dma_intr (ide_drive_t *drive) | ||
755 | { | ||
756 | LED_DISK_READ(0); | ||
757 | LED_DISK_WRITE(0); | ||
758 | |||
759 | return ide_dma_intr(drive); | ||
760 | } | ||
761 | |||
762 | /* | ||
763 | * Functions below initiates/aborts DMA read/write operations on a drive. | ||
764 | * | ||
765 | * The caller is assumed to have selected the drive and programmed the drive's | ||
766 | * sector address using CHS or LBA. All that remains is to prepare for DMA | ||
767 | * and then issue the actual read/write DMA/PIO command to the drive. | ||
768 | * | ||
769 | * Returns 0 if all went well. | ||
770 | * Returns 1 if DMA read/write could not be started, in which case | ||
771 | * the caller should revert to PIO for the current request. | ||
772 | */ | ||
773 | |||
774 | static int e100_dma_check(ide_drive_t *drive) | ||
775 | { | ||
776 | return config_drive_for_dma (drive); | ||
777 | } | ||
778 | |||
779 | static int e100_dma_end(ide_drive_t *drive) | ||
780 | { | ||
781 | /* TODO: check if something went wrong with the DMA */ | ||
782 | return 0; | ||
783 | } | ||
784 | |||
785 | static void e100_dma_start(ide_drive_t *drive) | ||
786 | { | ||
787 | if (e100_read_command) { | ||
788 | /* begin DMA */ | ||
789 | |||
790 | /* need to do this before RX DMA due to a chip bug | ||
791 | * it is enough to just flush the part of the cache that | ||
792 | * corresponds to the buffers we start, but since HD transfers | ||
793 | * usually are more than 8 kB, it is easier to optimize for the | ||
794 | * normal case and just flush the entire cache. its the only | ||
795 | * way to be sure! (OB movie quote) | ||
796 | */ | ||
797 | flush_etrax_cache(); | ||
798 | *R_DMA_CH3_FIRST = virt_to_phys(ata_descrs); | ||
799 | *R_DMA_CH3_CMD = IO_STATE(R_DMA_CH3_CMD, cmd, start); | ||
800 | |||
801 | /* initiate a multi word dma read using DMA handshaking */ | ||
802 | |||
803 | *R_ATA_TRANSFER_CNT = | ||
804 | IO_FIELD(R_ATA_TRANSFER_CNT, count, ata_tot_size >> 1); | ||
805 | |||
806 | *R_ATA_CTRL_DATA = | ||
807 | IO_FIELD(R_ATA_CTRL_DATA, data, IDE_DATA_REG) | | ||
808 | IO_STATE(R_ATA_CTRL_DATA, rw, read) | | ||
809 | IO_STATE(R_ATA_CTRL_DATA, src_dst, dma) | | ||
810 | IO_STATE(R_ATA_CTRL_DATA, handsh, dma) | | ||
811 | IO_STATE(R_ATA_CTRL_DATA, multi, on) | | ||
812 | IO_STATE(R_ATA_CTRL_DATA, dma_size, word); | ||
813 | |||
814 | LED_DISK_READ(1); | ||
815 | |||
816 | D(printk("dma read of %d bytes.\n", ata_tot_size)); | ||
817 | |||
818 | } else { | ||
819 | /* writing */ | ||
820 | /* begin DMA */ | ||
821 | |||
822 | *R_DMA_CH2_FIRST = virt_to_phys(ata_descrs); | ||
823 | *R_DMA_CH2_CMD = IO_STATE(R_DMA_CH2_CMD, cmd, start); | ||
824 | |||
825 | /* initiate a multi word dma write using DMA handshaking */ | ||
826 | |||
827 | *R_ATA_TRANSFER_CNT = | ||
828 | IO_FIELD(R_ATA_TRANSFER_CNT, count, ata_tot_size >> 1); | ||
829 | |||
830 | *R_ATA_CTRL_DATA = | ||
831 | IO_FIELD(R_ATA_CTRL_DATA, data, IDE_DATA_REG) | | ||
832 | IO_STATE(R_ATA_CTRL_DATA, rw, write) | | ||
833 | IO_STATE(R_ATA_CTRL_DATA, src_dst, dma) | | ||
834 | IO_STATE(R_ATA_CTRL_DATA, handsh, dma) | | ||
835 | IO_STATE(R_ATA_CTRL_DATA, multi, on) | | ||
836 | IO_STATE(R_ATA_CTRL_DATA, dma_size, word); | ||
837 | |||
838 | LED_DISK_WRITE(1); | ||
839 | |||
840 | D(printk("dma write of %d bytes.\n", ata_tot_size)); | ||
841 | } | ||
842 | } | ||
diff --git a/drivers/ide/h8300/ide-h8300.c b/drivers/ide/h8300/ide-h8300.c new file mode 100644 index 000000000000..fb91cb8bf2d2 --- /dev/null +++ b/drivers/ide/h8300/ide-h8300.c | |||
@@ -0,0 +1,119 @@ | |||
1 | /* | ||
2 | * drivers/ide/ide-h8300.c | ||
3 | * H8/300 generic IDE interface | ||
4 | */ | ||
5 | |||
6 | #include <linux/init.h> | ||
7 | #include <linux/ide.h> | ||
8 | #include <linux/config.h> | ||
9 | |||
10 | #include <asm/io.h> | ||
11 | #include <asm/irq.h> | ||
12 | |||
13 | #define bswap(d) \ | ||
14 | ({ \ | ||
15 | u16 r; \ | ||
16 | __asm__("mov.b %w1,r1h\n\t" \ | ||
17 | "mov.b %x1,r1l\n\t" \ | ||
18 | "mov.w r1,%0" \ | ||
19 | :"=r"(r) \ | ||
20 | :"r"(d) \ | ||
21 | :"er1"); \ | ||
22 | (r); \ | ||
23 | }) | ||
24 | |||
25 | static void mm_outw(u16 d, unsigned long a) | ||
26 | { | ||
27 | __asm__("mov.b %w0,r2h\n\t" | ||
28 | "mov.b %x0,r2l\n\t" | ||
29 | "mov.w r2,@%1" | ||
30 | : | ||
31 | :"r"(d),"r"(a) | ||
32 | :"er2"); | ||
33 | } | ||
34 | |||
35 | static u16 mm_inw(unsigned long a) | ||
36 | { | ||
37 | register u16 r __asm__("er0"); | ||
38 | __asm__("mov.w @%1,r2\n\t" | ||
39 | "mov.b r2l,%x0\n\t" | ||
40 | "mov.b r2h,%w0" | ||
41 | :"=r"(r) | ||
42 | :"r"(a) | ||
43 | :"er2"); | ||
44 | return r; | ||
45 | } | ||
46 | |||
47 | static void mm_outsw(unsigned long addr, void *buf, u32 len) | ||
48 | { | ||
49 | unsigned short *bp = (unsigned short *)buf; | ||
50 | for (; len > 0; len--, bp++) | ||
51 | *(volatile u16 *)addr = bswap(*bp); | ||
52 | } | ||
53 | |||
54 | static void mm_insw(unsigned long addr, void *buf, u32 len) | ||
55 | { | ||
56 | unsigned short *bp = (unsigned short *)buf; | ||
57 | for (; len > 0; len--, bp++) | ||
58 | *bp = bswap(*(volatile u16 *)addr); | ||
59 | } | ||
60 | |||
61 | #define H8300_IDE_GAP (2) | ||
62 | |||
63 | static inline void hw_setup(hw_regs_t *hw) | ||
64 | { | ||
65 | int i; | ||
66 | |||
67 | memset(hw, 0, sizeof(hw_regs_t)); | ||
68 | for (i = 0; i <= IDE_STATUS_OFFSET; i++) | ||
69 | hw->io_ports[i] = CONFIG_H8300_IDE_BASE + H8300_IDE_GAP*i; | ||
70 | hw->io_ports[IDE_CONTROL_OFFSET] = CONFIG_H8300_IDE_ALT; | ||
71 | hw->irq = EXT_IRQ0 + CONFIG_H8300_IDE_IRQ; | ||
72 | hw->dma = NO_DMA; | ||
73 | hw->chipset = ide_generic; | ||
74 | } | ||
75 | |||
76 | static inline void hwif_setup(ide_hwif_t *hwif) | ||
77 | { | ||
78 | default_hwif_iops(hwif); | ||
79 | |||
80 | hwif->mmio = 2; | ||
81 | hwif->OUTW = mm_outw; | ||
82 | hwif->OUTSW = mm_outsw; | ||
83 | hwif->INW = mm_inw; | ||
84 | hwif->INSW = mm_insw; | ||
85 | hwif->OUTL = NULL; | ||
86 | hwif->INL = NULL; | ||
87 | hwif->OUTSL = NULL; | ||
88 | hwif->INSL = NULL; | ||
89 | } | ||
90 | |||
91 | void __init h8300_ide_init(void) | ||
92 | { | ||
93 | hw_regs_t hw; | ||
94 | ide_hwif_t *hwif; | ||
95 | int idx; | ||
96 | |||
97 | if (!request_region(CONFIG_H8300_IDE_BASE, H8300_IDE_GAP*8, "ide-h8300")) | ||
98 | goto out_busy; | ||
99 | if (!request_region(CONFIG_H8300_IDE_ALT, H8300_IDE_GAP, "ide-h8300")) { | ||
100 | release_region(CONFIG_H8300_IDE_BASE, H8300_IDE_GAP*8); | ||
101 | goto out_busy; | ||
102 | } | ||
103 | |||
104 | hw_setup(&hw); | ||
105 | |||
106 | /* register if */ | ||
107 | idx = ide_register_hw(&hw, &hwif); | ||
108 | if (idx == -1) { | ||
109 | printk(KERN_ERR "ide-h8300: IDE I/F register failed\n"); | ||
110 | return; | ||
111 | } | ||
112 | |||
113 | hwif_setup(hwif); | ||
114 | printk(KERN_INFO "ide%d: H8/300 generic IDE interface\n", idx); | ||
115 | return; | ||
116 | |||
117 | out_busy: | ||
118 | printk(KERN_ERR "ide-h8300: IDE I/F resource already used.\n"); | ||
119 | } | ||
diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c new file mode 100644 index 000000000000..33a020faeabd --- /dev/null +++ b/drivers/ide/ide-cd.c | |||
@@ -0,0 +1,3524 @@ | |||
1 | /* | ||
2 | * linux/drivers/ide/ide-cd.c | ||
3 | * | ||
4 | * Copyright (C) 1994, 1995, 1996 scott snyder <snyder@fnald0.fnal.gov> | ||
5 | * Copyright (C) 1996-1998 Erik Andersen <andersee@debian.org> | ||
6 | * Copyright (C) 1998-2000 Jens Axboe <axboe@suse.de> | ||
7 | * | ||
8 | * May be copied or modified under the terms of the GNU General Public | ||
9 | * License. See linux/COPYING for more information. | ||
10 | * | ||
11 | * ATAPI CD-ROM driver. To be used with ide.c. | ||
12 | * See Documentation/cdrom/ide-cd for usage information. | ||
13 | * | ||
14 | * Suggestions are welcome. Patches that work are more welcome though. ;-) | ||
15 | * For those wishing to work on this driver, please be sure you download | ||
16 | * and comply with the latest Mt. Fuji (SFF8090 version 4) and ATAPI | ||
17 | * (SFF-8020i rev 2.6) standards. These documents can be obtained by | ||
18 | * anonymous ftp from: | ||
19 | * ftp://fission.dt.wdc.com/pub/standards/SFF_atapi/spec/SFF8020-r2.6/PS/8020r26.ps | ||
20 | * ftp://ftp.avc-pioneer.com/Mtfuji4/Spec/Fuji4r10.pdf | ||
21 | * | ||
22 | * Drives that deviate from these standards will be accommodated as much | ||
23 | * as possible via compile time or command-line options. Since I only have | ||
24 | * a few drives, you generally need to send me patches... | ||
25 | * | ||
26 | * ---------------------------------- | ||
27 | * TO DO LIST: | ||
28 | * -Make it so that Pioneer CD DR-A24X and friends don't get screwed up on | ||
29 | * boot | ||
30 | * | ||
31 | * ---------------------------------- | ||
32 | * 1.00 Oct 31, 1994 -- Initial version. | ||
33 | * 1.01 Nov 2, 1994 -- Fixed problem with starting request in | ||
34 | * cdrom_check_status. | ||
35 | * 1.03 Nov 25, 1994 -- leaving unmask_intr[] as a user-setting (as for disks) | ||
36 | * (from mlord) -- minor changes to cdrom_setup() | ||
37 | * -- renamed ide_dev_s to ide_drive_t, enable irq on command | ||
38 | * 2.00 Nov 27, 1994 -- Generalize packet command interface; | ||
39 | * add audio ioctls. | ||
40 | * 2.01 Dec 3, 1994 -- Rework packet command interface to handle devices | ||
41 | * which send an interrupt when ready for a command. | ||
42 | * 2.02 Dec 11, 1994 -- Cache the TOC in the driver. | ||
43 | * Don't use SCMD_PLAYAUDIO_TI; it's not included | ||
44 | * in the current version of ATAPI. | ||
45 | * Try to use LBA instead of track or MSF addressing | ||
46 | * when possible. | ||
47 | * Don't wait for READY_STAT. | ||
48 | * 2.03 Jan 10, 1995 -- Rewrite block read routines to handle block sizes | ||
49 | * other than 2k and to move multiple sectors in a | ||
50 | * single transaction. | ||
51 | * 2.04 Apr 21, 1995 -- Add work-around for Creative Labs CD220E drives. | ||
52 | * Thanks to Nick Saw <cwsaw@pts7.pts.mot.com> for | ||
53 | * help in figuring this out. Ditto for Acer and | ||
54 | * Aztech drives, which seem to have the same problem. | ||
55 | * 2.04b May 30, 1995 -- Fix to match changes in ide.c version 3.16 -ml | ||
56 | * 2.05 Jun 8, 1995 -- Don't attempt to retry after an illegal request | ||
57 | * or data protect error. | ||
58 | * Use HWIF and DEV_HWIF macros as in ide.c. | ||
59 | * Always try to do a request_sense after | ||
60 | * a failed command. | ||
61 | * Include an option to give textual descriptions | ||
62 | * of ATAPI errors. | ||
63 | * Fix a bug in handling the sector cache which | ||
64 | * showed up if the drive returned data in 512 byte | ||
65 | * blocks (like Pioneer drives). Thanks to | ||
66 | * Richard Hirst <srh@gpt.co.uk> for diagnosing this. | ||
67 | * Properly supply the page number field in the | ||
68 | * MODE_SELECT command. | ||
69 | * PLAYAUDIO12 is broken on the Aztech; work around it. | ||
70 | * 2.05x Aug 11, 1995 -- lots of data structure renaming/restructuring in ide.c | ||
71 | * (my apologies to Scott, but now ide-cd.c is independent) | ||
72 | * 3.00 Aug 22, 1995 -- Implement CDROMMULTISESSION ioctl. | ||
73 | * Implement CDROMREADAUDIO ioctl (UNTESTED). | ||
74 | * Use input_ide_data() and output_ide_data(). | ||
75 | * Add door locking. | ||
76 | * Fix usage count leak in cdrom_open, which happened | ||
77 | * when a read-write mount was attempted. | ||
78 | * Try to load the disk on open. | ||
79 | * Implement CDROMEJECT_SW ioctl (off by default). | ||
80 | * Read total cdrom capacity during open. | ||
81 | * Rearrange logic in cdrom_decode_status. Issue | ||
82 | * request sense commands for failed packet commands | ||
83 | * from here instead of from cdrom_queue_packet_command. | ||
84 | * Fix a race condition in retrieving error information. | ||
85 | * Suppress printing normal unit attention errors and | ||
86 | * some drive not ready errors. | ||
87 | * Implement CDROMVOLREAD ioctl. | ||
88 | * Implement CDROMREADMODE1/2 ioctls. | ||
89 | * Fix race condition in setting up interrupt handlers | ||
90 | * when the `serialize' option is used. | ||
91 | * 3.01 Sep 2, 1995 -- Fix ordering of reenabling interrupts in | ||
92 | * cdrom_queue_request. | ||
93 | * Another try at using ide_[input,output]_data. | ||
94 | * 3.02 Sep 16, 1995 -- Stick total disk capacity in partition table as well. | ||
95 | * Make VERBOSE_IDE_CD_ERRORS dump failed command again. | ||
96 | * Dump out more information for ILLEGAL REQUEST errs. | ||
97 | * Fix handling of errors occurring before the | ||
98 | * packet command is transferred. | ||
99 | * Fix transfers with odd bytelengths. | ||
100 | * 3.03 Oct 27, 1995 -- Some Creative drives have an id of just `CD'. | ||
101 | * `DCI-2S10' drives are broken too. | ||
102 | * 3.04 Nov 20, 1995 -- So are Vertos drives. | ||
103 | * 3.05 Dec 1, 1995 -- Changes to go with overhaul of ide.c and ide-tape.c | ||
104 | * 3.06 Dec 16, 1995 -- Add support needed for partitions. | ||
105 | * More workarounds for Vertos bugs (based on patches | ||
106 | * from Holger Dietze <dietze@aix520.informatik.uni-leipzig.de>). | ||
107 | * Try to eliminate byteorder assumptions. | ||
108 | * Use atapi_cdrom_subchnl struct definition. | ||
109 | * Add STANDARD_ATAPI compilation option. | ||
110 | * 3.07 Jan 29, 1996 -- More twiddling for broken drives: Sony 55D, | ||
111 | * Vertos 300. | ||
112 | * Add NO_DOOR_LOCKING configuration option. | ||
113 | * Handle drive_cmd requests w/NULL args (for hdparm -t). | ||
114 | * Work around sporadic Sony55e audio play problem. | ||
115 | * 3.07a Feb 11, 1996 -- check drive->id for NULL before dereferencing, to fix | ||
116 | * problem with "hde=cdrom" with no drive present. -ml | ||
117 | * 3.08 Mar 6, 1996 -- More Vertos workarounds. | ||
118 | * 3.09 Apr 5, 1996 -- Add CDROMCLOSETRAY ioctl. | ||
119 | * Switch to using MSF addressing for audio commands. | ||
120 | * Reformat to match kernel tabbing style. | ||
121 | * Add CDROM_GET_UPC ioctl. | ||
122 | * 3.10 Apr 10, 1996 -- Fix compilation error with STANDARD_ATAPI. | ||
123 | * 3.11 Apr 29, 1996 -- Patch from Heiko Eissfeldt <heiko@colossus.escape.de> | ||
124 | * to remove redundant verify_area calls. | ||
125 | * 3.12 May 7, 1996 -- Rudimentary changer support. Based on patches | ||
126 | * from Gerhard Zuber <zuber@berlin.snafu.de>. | ||
127 | * Let open succeed even if there's no loaded disc. | ||
128 | * 3.13 May 19, 1996 -- Fixes for changer code. | ||
129 | * 3.14 May 29, 1996 -- Add work-around for Vertos 600. | ||
130 | * (From Hennus Bergman <hennus@sky.ow.nl>.) | ||
131 | * 3.15 July 2, 1996 -- Added support for Sanyo 3 CD changers | ||
132 | * from Ben Galliart <bgallia@luc.edu> with | ||
133 | * special help from Jeff Lightfoot | ||
134 | * <jeffml@pobox.com> | ||
135 | * 3.15a July 9, 1996 -- Improved Sanyo 3 CD changer identification | ||
136 | * 3.16 Jul 28, 1996 -- Fix from Gadi to reduce kernel stack usage for ioctl. | ||
137 | * 3.17 Sep 17, 1996 -- Tweak audio reads for some drives. | ||
138 | * Start changing CDROMLOADFROMSLOT to CDROM_SELECT_DISC. | ||
139 | * 3.18 Oct 31, 1996 -- Added module and DMA support. | ||
140 | * | ||
141 | * | ||
142 | * 4.00 Nov 5, 1996 -- New ide-cd maintainer, | ||
143 | * Erik B. Andersen <andersee@debian.org> | ||
144 | * -- Newer Creative drives don't always set the error | ||
145 | * register correctly. Make sure we see media changes | ||
146 | * regardless. | ||
147 | * -- Integrate with generic cdrom driver. | ||
148 | * -- CDROMGETSPINDOWN and CDROMSETSPINDOWN ioctls, based on | ||
149 | * a patch from Ciro Cattuto <>. | ||
150 | * -- Call set_device_ro. | ||
151 | * -- Implement CDROMMECHANISMSTATUS and CDROMSLOTTABLE | ||
152 | * ioctls, based on patch by Erik Andersen | ||
153 | * -- Add some probes of drive capability during setup. | ||
154 | * | ||
155 | * 4.01 Nov 11, 1996 -- Split into ide-cd.c and ide-cd.h | ||
156 | * -- Removed CDROMMECHANISMSTATUS and CDROMSLOTTABLE | ||
157 | * ioctls in favor of a generalized approach | ||
158 | * using the generic cdrom driver. | ||
159 | * -- Fully integrated with the 2.1.X kernel. | ||
160 | * -- Other stuff that I forgot (lots of changes) | ||
161 | * | ||
162 | * 4.02 Dec 01, 1996 -- Applied patch from Gadi Oxman <gadio@netvision.net.il> | ||
163 | * to fix the drive door locking problems. | ||
164 | * | ||
165 | * 4.03 Dec 04, 1996 -- Added DSC overlap support. | ||
166 | * 4.04 Dec 29, 1996 -- Added CDROMREADRAW ioclt based on patch | ||
167 | * by Ales Makarov (xmakarov@sun.felk.cvut.cz) | ||
168 | * | ||
169 | * 4.05 Nov 20, 1997 -- Modified to print more drive info on init | ||
170 | * Minor other changes | ||
171 | * Fix errors on CDROMSTOP (If you have a "Dolphin", | ||
172 | * you must define IHAVEADOLPHIN) | ||
173 | * Added identifier so new Sanyo CD-changer works | ||
174 | * Better detection if door locking isn't supported | ||
175 | * | ||
176 | * 4.06 Dec 17, 1997 -- fixed endless "tray open" messages -ml | ||
177 | * 4.07 Dec 17, 1997 -- fallback to set pc->stat on "tray open" | ||
178 | * 4.08 Dec 18, 1997 -- spew less noise when tray is empty | ||
179 | * -- fix speed display for ACER 24X, 18X | ||
180 | * 4.09 Jan 04, 1998 -- fix handling of the last block so we return | ||
181 | * an end of file instead of an I/O error (Gadi) | ||
182 | * 4.10 Jan 24, 1998 -- fixed a bug so now changers can change to a new | ||
183 | * slot when there is no disc in the current slot. | ||
184 | * -- Fixed a memory leak where info->changer_info was | ||
185 | * malloc'ed but never free'd when closing the device. | ||
186 | * -- Cleaned up the global namespace a bit by making more | ||
187 | * functions static that should already have been. | ||
188 | * 4.11 Mar 12, 1998 -- Added support for the CDROM_SELECT_SPEED ioctl | ||
189 | * based on a patch for 2.0.33 by Jelle Foks | ||
190 | * <jelle@scintilla.utwente.nl>, a patch for 2.0.33 | ||
191 | * by Toni Giorgino <toni@pcape2.pi.infn.it>, the SCSI | ||
192 | * version, and my own efforts. -erik | ||
193 | * -- Fixed a stupid bug which egcs was kind enough to | ||
194 | * inform me of where "Illegal mode for this track" | ||
195 | * was never returned due to a comparison on data | ||
196 | * types of limited range. | ||
197 | * 4.12 Mar 29, 1998 -- Fixed bug in CDROM_SELECT_SPEED so write speed is | ||
198 | * now set ionly for CD-R and CD-RW drives. I had | ||
199 | * removed this support because it produced errors. | ||
200 | * It produced errors _only_ for non-writers. duh. | ||
201 | * 4.13 May 05, 1998 -- Suppress useless "in progress of becoming ready" | ||
202 | * messages, since this is not an error. | ||
203 | * -- Change error messages to be const | ||
204 | * -- Remove a "\t" which looks ugly in the syslogs | ||
205 | * 4.14 July 17, 1998 -- Change to pointing to .ps version of ATAPI spec | ||
206 | * since the .pdf version doesn't seem to work... | ||
207 | * -- Updated the TODO list to something more current. | ||
208 | * | ||
209 | * 4.15 Aug 25, 1998 -- Updated ide-cd.h to respect mechine endianess, | ||
210 | * patch thanks to "Eddie C. Dost" <ecd@skynet.be> | ||
211 | * | ||
212 | * 4.50 Oct 19, 1998 -- New maintainers! | ||
213 | * Jens Axboe <axboe@image.dk> | ||
214 | * Chris Zwilling <chris@cloudnet.com> | ||
215 | * | ||
216 | * 4.51 Dec 23, 1998 -- Jens Axboe <axboe@image.dk> | ||
217 | * - ide_cdrom_reset enabled since the ide subsystem | ||
218 | * handles resets fine now. <axboe@image.dk> | ||
219 | * - Transfer size fix for Samsung CD-ROMs, thanks to | ||
220 | * "Ville Hallik" <ville.hallik@mail.ee>. | ||
221 | * - other minor stuff. | ||
222 | * | ||
223 | * 4.52 Jan 19, 1999 -- Jens Axboe <axboe@image.dk> | ||
224 | * - Detect DVD-ROM/RAM drives | ||
225 | * | ||
226 | * 4.53 Feb 22, 1999 - Include other model Samsung and one Goldstar | ||
227 | * drive in transfer size limit. | ||
228 | * - Fix the I/O error when doing eject without a medium | ||
229 | * loaded on some drives. | ||
230 | * - CDROMREADMODE2 is now implemented through | ||
231 | * CDROMREADRAW, since many drives don't support | ||
232 | * MODE2 (even though ATAPI 2.6 says they must). | ||
233 | * - Added ignore parameter to ide-cd (as a module), eg | ||
234 | * insmod ide-cd ignore='hda hdb' | ||
235 | * Useful when using ide-cd in conjunction with | ||
236 | * ide-scsi. TODO: non-modular way of doing the | ||
237 | * same. | ||
238 | * | ||
239 | * 4.54 Aug 5, 1999 - Support for MMC2 class commands through the generic | ||
240 | * packet interface to cdrom.c. | ||
241 | * - Unified audio ioctl support, most of it. | ||
242 | * - cleaned up various deprecated verify_area(). | ||
243 | * - Added ide_cdrom_packet() as the interface for | ||
244 | * the Uniform generic_packet(). | ||
245 | * - bunch of other stuff, will fill in logs later. | ||
246 | * - report 1 slot for non-changers, like the other | ||
247 | * cd-rom drivers. don't report select disc for | ||
248 | * non-changers as well. | ||
249 | * - mask out audio playing, if the device can't do it. | ||
250 | * | ||
251 | * 4.55 Sep 1, 1999 - Eliminated the rest of the audio ioctls, except | ||
252 | * for CDROMREADTOC[ENTRY|HEADER]. Some of the drivers | ||
253 | * use this independently of the actual audio handling. | ||
254 | * They will disappear later when I get the time to | ||
255 | * do it cleanly. | ||
256 | * - Minimize the TOC reading - only do it when we | ||
257 | * know a media change has occurred. | ||
258 | * - Moved all the CDROMREADx ioctls to the Uniform layer. | ||
259 | * - Heiko Eissfeldt <heiko@colossus.escape.de> supplied | ||
260 | * some fixes for CDI. | ||
261 | * - CD-ROM leaving door locked fix from Andries | ||
262 | * Brouwer <Andries.Brouwer@cwi.nl> | ||
263 | * - Erik Andersen <andersen@xmission.com> unified | ||
264 | * commands across the various drivers and how | ||
265 | * sense errors are handled. | ||
266 | * | ||
267 | * 4.56 Sep 12, 1999 - Removed changer support - it is now in the | ||
268 | * Uniform layer. | ||
269 | * - Added partition based multisession handling. | ||
270 | * - Mode sense and mode select moved to the | ||
271 | * Uniform layer. | ||
272 | * - Fixed a problem with WPI CDS-32X drive - it | ||
273 | * failed the capabilities | ||
274 | * | ||
275 | * 4.57 Apr 7, 2000 - Fixed sense reporting. | ||
276 | * - Fixed possible oops in ide_cdrom_get_last_session() | ||
277 | * - Fix locking mania and make ide_cdrom_reset relock | ||
278 | * - Stop spewing errors to log when magicdev polls with | ||
279 | * TEST_UNIT_READY on some drives. | ||
280 | * - Various fixes from Tobias Ringstrom: | ||
281 | * tray if it was locked prior to the reset. | ||
282 | * - cdrom_read_capacity returns one frame too little. | ||
283 | * - Fix real capacity reporting. | ||
284 | * | ||
285 | * 4.58 May 1, 2000 - Clean up ACER50 stuff. | ||
286 | * - Fix small problem with ide_cdrom_capacity | ||
287 | * | ||
288 | * 4.59 Aug 11, 2000 - Fix changer problem in cdrom_read_toc, we weren't | ||
289 | * correctly sensing a disc change. | ||
290 | * - Rearranged some code | ||
291 | * - Use extended sense on drives that support it for | ||
292 | * correctly reporting tray status -- from | ||
293 | * Michael D Johnson <johnsom@orst.edu> | ||
294 | * 4.60 Dec 17, 2003 - Add mt rainier support | ||
295 | * - Bump timeout for packet commands, matches sr | ||
296 | * - Odd stuff | ||
297 | * 4.61 Jan 22, 2004 - support hardware sector sizes other than 2kB, | ||
298 | * Pascal Schmidt <der.eremit@email.de> | ||
299 | * | ||
300 | *************************************************************************/ | ||
301 | |||
302 | #define IDECD_VERSION "4.61" | ||
303 | |||
304 | #include <linux/config.h> | ||
305 | #include <linux/module.h> | ||
306 | #include <linux/types.h> | ||
307 | #include <linux/kernel.h> | ||
308 | #include <linux/delay.h> | ||
309 | #include <linux/timer.h> | ||
310 | #include <linux/slab.h> | ||
311 | #include <linux/interrupt.h> | ||
312 | #include <linux/errno.h> | ||
313 | #include <linux/cdrom.h> | ||
314 | #include <linux/ide.h> | ||
315 | #include <linux/completion.h> | ||
316 | |||
317 | #include <scsi/scsi.h> /* For SCSI -> ATAPI command conversion */ | ||
318 | |||
319 | #include <asm/irq.h> | ||
320 | #include <asm/io.h> | ||
321 | #include <asm/byteorder.h> | ||
322 | #include <asm/uaccess.h> | ||
323 | #include <asm/unaligned.h> | ||
324 | |||
325 | #include "ide-cd.h" | ||
326 | |||
327 | static DECLARE_MUTEX(idecd_ref_sem); | ||
328 | |||
329 | #define to_ide_cd(obj) container_of(obj, struct cdrom_info, kref) | ||
330 | |||
331 | #define ide_cd_g(disk) \ | ||
332 | container_of((disk)->private_data, struct cdrom_info, driver) | ||
333 | |||
334 | static struct cdrom_info *ide_cd_get(struct gendisk *disk) | ||
335 | { | ||
336 | struct cdrom_info *cd = NULL; | ||
337 | |||
338 | down(&idecd_ref_sem); | ||
339 | cd = ide_cd_g(disk); | ||
340 | if (cd) | ||
341 | kref_get(&cd->kref); | ||
342 | up(&idecd_ref_sem); | ||
343 | return cd; | ||
344 | } | ||
345 | |||
346 | static void ide_cd_release(struct kref *); | ||
347 | |||
348 | static void ide_cd_put(struct cdrom_info *cd) | ||
349 | { | ||
350 | down(&idecd_ref_sem); | ||
351 | kref_put(&cd->kref, ide_cd_release); | ||
352 | up(&idecd_ref_sem); | ||
353 | } | ||
354 | |||
355 | /**************************************************************************** | ||
356 | * Generic packet command support and error handling routines. | ||
357 | */ | ||
358 | |||
359 | /* Mark that we've seen a media change, and invalidate our internal | ||
360 | buffers. */ | ||
361 | static void cdrom_saw_media_change (ide_drive_t *drive) | ||
362 | { | ||
363 | struct cdrom_info *info = drive->driver_data; | ||
364 | |||
365 | CDROM_STATE_FLAGS (drive)->media_changed = 1; | ||
366 | CDROM_STATE_FLAGS (drive)->toc_valid = 0; | ||
367 | info->nsectors_buffered = 0; | ||
368 | } | ||
369 | |||
370 | static int cdrom_log_sense(ide_drive_t *drive, struct request *rq, | ||
371 | struct request_sense *sense) | ||
372 | { | ||
373 | int log = 0; | ||
374 | |||
375 | if (!sense || !rq || (rq->flags & REQ_QUIET)) | ||
376 | return 0; | ||
377 | |||
378 | switch (sense->sense_key) { | ||
379 | case NO_SENSE: case RECOVERED_ERROR: | ||
380 | break; | ||
381 | case NOT_READY: | ||
382 | /* | ||
383 | * don't care about tray state messages for | ||
384 | * e.g. capacity commands or in-progress or | ||
385 | * becoming ready | ||
386 | */ | ||
387 | if (sense->asc == 0x3a || sense->asc == 0x04) | ||
388 | break; | ||
389 | log = 1; | ||
390 | break; | ||
391 | case ILLEGAL_REQUEST: | ||
392 | /* | ||
393 | * don't log START_STOP unit with LoEj set, since | ||
394 | * we cannot reliably check if drive can auto-close | ||
395 | */ | ||
396 | if (rq->cmd[0] == GPCMD_START_STOP_UNIT && sense->asc == 0x24) | ||
397 | log = 0; | ||
398 | break; | ||
399 | case UNIT_ATTENTION: | ||
400 | /* | ||
401 | * Make good and sure we've seen this potential media | ||
402 | * change. Some drives (i.e. Creative) fail to present | ||
403 | * the correct sense key in the error register. | ||
404 | */ | ||
405 | cdrom_saw_media_change(drive); | ||
406 | break; | ||
407 | default: | ||
408 | log = 1; | ||
409 | break; | ||
410 | } | ||
411 | return log; | ||
412 | } | ||
413 | |||
414 | static | ||
415 | void cdrom_analyze_sense_data(ide_drive_t *drive, | ||
416 | struct request *failed_command, | ||
417 | struct request_sense *sense) | ||
418 | { | ||
419 | if (!cdrom_log_sense(drive, failed_command, sense)) | ||
420 | return; | ||
421 | |||
422 | /* | ||
423 | * If a read toc is executed for a CD-R or CD-RW medium where | ||
424 | * the first toc has not been recorded yet, it will fail with | ||
425 | * 05/24/00 (which is a confusing error) | ||
426 | */ | ||
427 | if (failed_command && failed_command->cmd[0] == GPCMD_READ_TOC_PMA_ATIP) | ||
428 | if (sense->sense_key == 0x05 && sense->asc == 0x24) | ||
429 | return; | ||
430 | |||
431 | #if VERBOSE_IDE_CD_ERRORS | ||
432 | { | ||
433 | int i; | ||
434 | const char *s; | ||
435 | char buf[80]; | ||
436 | |||
437 | printk ("ATAPI device %s:\n", drive->name); | ||
438 | if (sense->error_code==0x70) | ||
439 | printk(" Error: "); | ||
440 | else if (sense->error_code==0x71) | ||
441 | printk(" Deferred Error: "); | ||
442 | else if (sense->error_code == 0x7f) | ||
443 | printk(" Vendor-specific Error: "); | ||
444 | else | ||
445 | printk(" Unknown Error Type: "); | ||
446 | |||
447 | if (sense->sense_key < ARY_LEN(sense_key_texts)) | ||
448 | s = sense_key_texts[sense->sense_key]; | ||
449 | else | ||
450 | s = "bad sense key!"; | ||
451 | |||
452 | printk("%s -- (Sense key=0x%02x)\n", s, sense->sense_key); | ||
453 | |||
454 | if (sense->asc == 0x40) { | ||
455 | sprintf(buf, "Diagnostic failure on component 0x%02x", | ||
456 | sense->ascq); | ||
457 | s = buf; | ||
458 | } else { | ||
459 | int lo = 0, mid, hi = ARY_LEN(sense_data_texts); | ||
460 | unsigned long key = (sense->sense_key << 16); | ||
461 | key |= (sense->asc << 8); | ||
462 | if (!(sense->ascq >= 0x80 && sense->ascq <= 0xdd)) | ||
463 | key |= sense->ascq; | ||
464 | s = NULL; | ||
465 | |||
466 | while (hi > lo) { | ||
467 | mid = (lo + hi) / 2; | ||
468 | if (sense_data_texts[mid].asc_ascq == key || | ||
469 | sense_data_texts[mid].asc_ascq == (0xff0000|key)) { | ||
470 | s = sense_data_texts[mid].text; | ||
471 | break; | ||
472 | } | ||
473 | else if (sense_data_texts[mid].asc_ascq > key) | ||
474 | hi = mid; | ||
475 | else | ||
476 | lo = mid+1; | ||
477 | } | ||
478 | } | ||
479 | |||
480 | if (s == NULL) { | ||
481 | if (sense->asc > 0x80) | ||
482 | s = "(vendor-specific error)"; | ||
483 | else | ||
484 | s = "(reserved error code)"; | ||
485 | } | ||
486 | |||
487 | printk(KERN_ERR " %s -- (asc=0x%02x, ascq=0x%02x)\n", | ||
488 | s, sense->asc, sense->ascq); | ||
489 | |||
490 | if (failed_command != NULL) { | ||
491 | |||
492 | int lo=0, mid, hi= ARY_LEN (packet_command_texts); | ||
493 | s = NULL; | ||
494 | |||
495 | while (hi > lo) { | ||
496 | mid = (lo + hi) / 2; | ||
497 | if (packet_command_texts[mid].packet_command == | ||
498 | failed_command->cmd[0]) { | ||
499 | s = packet_command_texts[mid].text; | ||
500 | break; | ||
501 | } | ||
502 | if (packet_command_texts[mid].packet_command > | ||
503 | failed_command->cmd[0]) | ||
504 | hi = mid; | ||
505 | else | ||
506 | lo = mid+1; | ||
507 | } | ||
508 | |||
509 | printk (KERN_ERR " The failed \"%s\" packet command was: \n \"", s); | ||
510 | for (i=0; i<sizeof (failed_command->cmd); i++) | ||
511 | printk ("%02x ", failed_command->cmd[i]); | ||
512 | printk ("\"\n"); | ||
513 | } | ||
514 | |||
515 | /* The SKSV bit specifies validity of the sense_key_specific | ||
516 | * in the next two commands. It is bit 7 of the first byte. | ||
517 | * In the case of NOT_READY, if SKSV is set the drive can | ||
518 | * give us nice ETA readings. | ||
519 | */ | ||
520 | if (sense->sense_key == NOT_READY && (sense->sks[0] & 0x80)) { | ||
521 | int progress = (sense->sks[1] << 8 | sense->sks[2]) * 100; | ||
522 | printk(KERN_ERR " Command is %02d%% complete\n", progress / 0xffff); | ||
523 | |||
524 | } | ||
525 | |||
526 | if (sense->sense_key == ILLEGAL_REQUEST && | ||
527 | (sense->sks[0] & 0x80) != 0) { | ||
528 | printk(KERN_ERR " Error in %s byte %d", | ||
529 | (sense->sks[0] & 0x40) != 0 ? | ||
530 | "command packet" : "command data", | ||
531 | (sense->sks[1] << 8) + sense->sks[2]); | ||
532 | |||
533 | if ((sense->sks[0] & 0x40) != 0) | ||
534 | printk (" bit %d", sense->sks[0] & 0x07); | ||
535 | |||
536 | printk ("\n"); | ||
537 | } | ||
538 | } | ||
539 | |||
540 | #else /* not VERBOSE_IDE_CD_ERRORS */ | ||
541 | |||
542 | /* Suppress printing unit attention and `in progress of becoming ready' | ||
543 | errors when we're not being verbose. */ | ||
544 | |||
545 | if (sense->sense_key == UNIT_ATTENTION || | ||
546 | (sense->sense_key == NOT_READY && (sense->asc == 4 || | ||
547 | sense->asc == 0x3a))) | ||
548 | return; | ||
549 | |||
550 | printk(KERN_ERR "%s: error code: 0x%02x sense_key: 0x%02x asc: 0x%02x ascq: 0x%02x\n", | ||
551 | drive->name, | ||
552 | sense->error_code, sense->sense_key, | ||
553 | sense->asc, sense->ascq); | ||
554 | #endif /* not VERBOSE_IDE_CD_ERRORS */ | ||
555 | } | ||
556 | |||
557 | /* | ||
558 | * Initialize a ide-cd packet command request | ||
559 | */ | ||
560 | static void cdrom_prepare_request(ide_drive_t *drive, struct request *rq) | ||
561 | { | ||
562 | struct cdrom_info *cd = drive->driver_data; | ||
563 | |||
564 | ide_init_drive_cmd(rq); | ||
565 | rq->flags = REQ_PC; | ||
566 | rq->rq_disk = cd->disk; | ||
567 | } | ||
568 | |||
569 | static void cdrom_queue_request_sense(ide_drive_t *drive, void *sense, | ||
570 | struct request *failed_command) | ||
571 | { | ||
572 | struct cdrom_info *info = drive->driver_data; | ||
573 | struct request *rq = &info->request_sense_request; | ||
574 | |||
575 | if (sense == NULL) | ||
576 | sense = &info->sense_data; | ||
577 | |||
578 | /* stuff the sense request in front of our current request */ | ||
579 | cdrom_prepare_request(drive, rq); | ||
580 | |||
581 | rq->data = sense; | ||
582 | rq->cmd[0] = GPCMD_REQUEST_SENSE; | ||
583 | rq->cmd[4] = rq->data_len = 18; | ||
584 | |||
585 | rq->flags = REQ_SENSE; | ||
586 | |||
587 | /* NOTE! Save the failed command in "rq->buffer" */ | ||
588 | rq->buffer = (void *) failed_command; | ||
589 | |||
590 | (void) ide_do_drive_cmd(drive, rq, ide_preempt); | ||
591 | } | ||
592 | |||
593 | static void cdrom_end_request (ide_drive_t *drive, int uptodate) | ||
594 | { | ||
595 | struct request *rq = HWGROUP(drive)->rq; | ||
596 | int nsectors = rq->hard_cur_sectors; | ||
597 | |||
598 | if ((rq->flags & REQ_SENSE) && uptodate) { | ||
599 | /* | ||
600 | * For REQ_SENSE, "rq->buffer" points to the original failed | ||
601 | * request | ||
602 | */ | ||
603 | struct request *failed = (struct request *) rq->buffer; | ||
604 | struct cdrom_info *info = drive->driver_data; | ||
605 | void *sense = &info->sense_data; | ||
606 | unsigned long flags; | ||
607 | |||
608 | if (failed) { | ||
609 | if (failed->sense) { | ||
610 | sense = failed->sense; | ||
611 | failed->sense_len = rq->sense_len; | ||
612 | } | ||
613 | |||
614 | /* | ||
615 | * now end failed request | ||
616 | */ | ||
617 | spin_lock_irqsave(&ide_lock, flags); | ||
618 | end_that_request_chunk(failed, 0, failed->data_len); | ||
619 | end_that_request_last(failed); | ||
620 | spin_unlock_irqrestore(&ide_lock, flags); | ||
621 | } | ||
622 | |||
623 | cdrom_analyze_sense_data(drive, failed, sense); | ||
624 | } | ||
625 | |||
626 | if (!rq->current_nr_sectors && blk_fs_request(rq)) | ||
627 | uptodate = 1; | ||
628 | /* make sure it's fully ended */ | ||
629 | if (blk_pc_request(rq)) | ||
630 | nsectors = (rq->data_len + 511) >> 9; | ||
631 | if (!nsectors) | ||
632 | nsectors = 1; | ||
633 | |||
634 | ide_end_request(drive, uptodate, nsectors); | ||
635 | } | ||
636 | |||
637 | /* Returns 0 if the request should be continued. | ||
638 | Returns 1 if the request was ended. */ | ||
639 | static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret) | ||
640 | { | ||
641 | struct request *rq = HWGROUP(drive)->rq; | ||
642 | int stat, err, sense_key; | ||
643 | |||
644 | /* Check for errors. */ | ||
645 | stat = HWIF(drive)->INB(IDE_STATUS_REG); | ||
646 | if (stat_ret) | ||
647 | *stat_ret = stat; | ||
648 | |||
649 | if (OK_STAT(stat, good_stat, BAD_R_STAT)) | ||
650 | return 0; | ||
651 | |||
652 | /* Get the IDE error register. */ | ||
653 | err = HWIF(drive)->INB(IDE_ERROR_REG); | ||
654 | sense_key = err >> 4; | ||
655 | |||
656 | if (rq == NULL) { | ||
657 | printk("%s: missing rq in cdrom_decode_status\n", drive->name); | ||
658 | return 1; | ||
659 | } | ||
660 | |||
661 | if (rq->flags & REQ_SENSE) { | ||
662 | /* We got an error trying to get sense info | ||
663 | from the drive (probably while trying | ||
664 | to recover from a former error). Just give up. */ | ||
665 | |||
666 | rq->flags |= REQ_FAILED; | ||
667 | cdrom_end_request(drive, 0); | ||
668 | ide_error(drive, "request sense failure", stat); | ||
669 | return 1; | ||
670 | |||
671 | } else if (rq->flags & (REQ_PC | REQ_BLOCK_PC)) { | ||
672 | /* All other functions, except for READ. */ | ||
673 | unsigned long flags; | ||
674 | |||
675 | /* | ||
676 | * if we have an error, pass back CHECK_CONDITION as the | ||
677 | * scsi status byte | ||
678 | */ | ||
679 | if ((rq->flags & REQ_BLOCK_PC) && !rq->errors) | ||
680 | rq->errors = SAM_STAT_CHECK_CONDITION; | ||
681 | |||
682 | /* Check for tray open. */ | ||
683 | if (sense_key == NOT_READY) { | ||
684 | cdrom_saw_media_change (drive); | ||
685 | } else if (sense_key == UNIT_ATTENTION) { | ||
686 | /* Check for media change. */ | ||
687 | cdrom_saw_media_change (drive); | ||
688 | /*printk("%s: media changed\n",drive->name);*/ | ||
689 | return 0; | ||
690 | } else if (!(rq->flags & REQ_QUIET)) { | ||
691 | /* Otherwise, print an error. */ | ||
692 | ide_dump_status(drive, "packet command error", stat); | ||
693 | } | ||
694 | |||
695 | rq->flags |= REQ_FAILED; | ||
696 | |||
697 | /* | ||
698 | * instead of playing games with moving completions around, | ||
699 | * remove failed request completely and end it when the | ||
700 | * request sense has completed | ||
701 | */ | ||
702 | if (stat & ERR_STAT) { | ||
703 | spin_lock_irqsave(&ide_lock, flags); | ||
704 | blkdev_dequeue_request(rq); | ||
705 | HWGROUP(drive)->rq = NULL; | ||
706 | spin_unlock_irqrestore(&ide_lock, flags); | ||
707 | |||
708 | cdrom_queue_request_sense(drive, rq->sense, rq); | ||
709 | } else | ||
710 | cdrom_end_request(drive, 0); | ||
711 | |||
712 | } else if (blk_fs_request(rq)) { | ||
713 | int do_end_request = 0; | ||
714 | |||
715 | /* Handle errors from READ and WRITE requests. */ | ||
716 | |||
717 | if (blk_noretry_request(rq)) | ||
718 | do_end_request = 1; | ||
719 | |||
720 | if (sense_key == NOT_READY) { | ||
721 | /* Tray open. */ | ||
722 | if (rq_data_dir(rq) == READ) { | ||
723 | cdrom_saw_media_change (drive); | ||
724 | |||
725 | /* Fail the request. */ | ||
726 | printk ("%s: tray open\n", drive->name); | ||
727 | do_end_request = 1; | ||
728 | } else { | ||
729 | struct cdrom_info *info = drive->driver_data; | ||
730 | |||
731 | /* allow the drive 5 seconds to recover, some | ||
732 | * devices will return this error while flushing | ||
733 | * data from cache */ | ||
734 | if (!rq->errors) | ||
735 | info->write_timeout = jiffies + ATAPI_WAIT_WRITE_BUSY; | ||
736 | rq->errors = 1; | ||
737 | if (time_after(jiffies, info->write_timeout)) | ||
738 | do_end_request = 1; | ||
739 | else { | ||
740 | unsigned long flags; | ||
741 | |||
742 | /* | ||
743 | * take a breather relying on the | ||
744 | * unplug timer to kick us again | ||
745 | */ | ||
746 | spin_lock_irqsave(&ide_lock, flags); | ||
747 | blk_plug_device(drive->queue); | ||
748 | spin_unlock_irqrestore(&ide_lock,flags); | ||
749 | return 1; | ||
750 | } | ||
751 | } | ||
752 | } else if (sense_key == UNIT_ATTENTION) { | ||
753 | /* Media change. */ | ||
754 | cdrom_saw_media_change (drive); | ||
755 | |||
756 | /* Arrange to retry the request. | ||
757 | But be sure to give up if we've retried | ||
758 | too many times. */ | ||
759 | if (++rq->errors > ERROR_MAX) | ||
760 | do_end_request = 1; | ||
761 | } else if (sense_key == ILLEGAL_REQUEST || | ||
762 | sense_key == DATA_PROTECT) { | ||
763 | /* No point in retrying after an illegal | ||
764 | request or data protect error.*/ | ||
765 | ide_dump_status (drive, "command error", stat); | ||
766 | do_end_request = 1; | ||
767 | } else if (sense_key == MEDIUM_ERROR) { | ||
768 | /* No point in re-trying a zillion times on a bad | ||
769 | * sector... If we got here the error is not correctable */ | ||
770 | ide_dump_status (drive, "media error (bad sector)", stat); | ||
771 | do_end_request = 1; | ||
772 | } else if (sense_key == BLANK_CHECK) { | ||
773 | /* Disk appears blank ?? */ | ||
774 | ide_dump_status (drive, "media error (blank)", stat); | ||
775 | do_end_request = 1; | ||
776 | } else if ((err & ~ABRT_ERR) != 0) { | ||
777 | /* Go to the default handler | ||
778 | for other errors. */ | ||
779 | ide_error(drive, "cdrom_decode_status", stat); | ||
780 | return 1; | ||
781 | } else if ((++rq->errors > ERROR_MAX)) { | ||
782 | /* We've racked up too many retries. Abort. */ | ||
783 | do_end_request = 1; | ||
784 | } | ||
785 | |||
786 | if (do_end_request) | ||
787 | cdrom_end_request(drive, 0); | ||
788 | |||
789 | /* If we got a CHECK_CONDITION status, | ||
790 | queue a request sense command. */ | ||
791 | if ((stat & ERR_STAT) != 0) | ||
792 | cdrom_queue_request_sense(drive, NULL, NULL); | ||
793 | } else { | ||
794 | blk_dump_rq_flags(rq, "ide-cd: bad rq"); | ||
795 | cdrom_end_request(drive, 0); | ||
796 | } | ||
797 | |||
798 | /* Retry, or handle the next request. */ | ||
799 | return 1; | ||
800 | } | ||
801 | |||
802 | static int cdrom_timer_expiry(ide_drive_t *drive) | ||
803 | { | ||
804 | struct request *rq = HWGROUP(drive)->rq; | ||
805 | unsigned long wait = 0; | ||
806 | |||
807 | /* | ||
808 | * Some commands are *slow* and normally take a long time to | ||
809 | * complete. Usually we can use the ATAPI "disconnect" to bypass | ||
810 | * this, but not all commands/drives support that. Let | ||
811 | * ide_timer_expiry keep polling us for these. | ||
812 | */ | ||
813 | switch (rq->cmd[0]) { | ||
814 | case GPCMD_BLANK: | ||
815 | case GPCMD_FORMAT_UNIT: | ||
816 | case GPCMD_RESERVE_RZONE_TRACK: | ||
817 | case GPCMD_CLOSE_TRACK: | ||
818 | case GPCMD_FLUSH_CACHE: | ||
819 | wait = ATAPI_WAIT_PC; | ||
820 | break; | ||
821 | default: | ||
822 | if (!(rq->flags & REQ_QUIET)) | ||
823 | printk(KERN_INFO "ide-cd: cmd 0x%x timed out\n", rq->cmd[0]); | ||
824 | wait = 0; | ||
825 | break; | ||
826 | } | ||
827 | return wait; | ||
828 | } | ||
829 | |||
830 | /* Set up the device registers for transferring a packet command on DEV, | ||
831 | expecting to later transfer XFERLEN bytes. HANDLER is the routine | ||
832 | which actually transfers the command to the drive. If this is a | ||
833 | drq_interrupt device, this routine will arrange for HANDLER to be | ||
834 | called when the interrupt from the drive arrives. Otherwise, HANDLER | ||
835 | will be called immediately after the drive is prepared for the transfer. */ | ||
836 | |||
837 | static ide_startstop_t cdrom_start_packet_command(ide_drive_t *drive, | ||
838 | int xferlen, | ||
839 | ide_handler_t *handler) | ||
840 | { | ||
841 | ide_startstop_t startstop; | ||
842 | struct cdrom_info *info = drive->driver_data; | ||
843 | ide_hwif_t *hwif = drive->hwif; | ||
844 | |||
845 | /* Wait for the controller to be idle. */ | ||
846 | if (ide_wait_stat(&startstop, drive, 0, BUSY_STAT, WAIT_READY)) | ||
847 | return startstop; | ||
848 | |||
849 | if (info->dma) | ||
850 | info->dma = !hwif->dma_setup(drive); | ||
851 | |||
852 | /* Set up the controller registers. */ | ||
853 | /* FIXME: for Virtual DMA we must check harder */ | ||
854 | HWIF(drive)->OUTB(info->dma, IDE_FEATURE_REG); | ||
855 | HWIF(drive)->OUTB(0, IDE_IREASON_REG); | ||
856 | HWIF(drive)->OUTB(0, IDE_SECTOR_REG); | ||
857 | |||
858 | HWIF(drive)->OUTB(xferlen & 0xff, IDE_BCOUNTL_REG); | ||
859 | HWIF(drive)->OUTB(xferlen >> 8 , IDE_BCOUNTH_REG); | ||
860 | if (IDE_CONTROL_REG) | ||
861 | HWIF(drive)->OUTB(drive->ctl, IDE_CONTROL_REG); | ||
862 | |||
863 | if (CDROM_CONFIG_FLAGS (drive)->drq_interrupt) { | ||
864 | /* packet command */ | ||
865 | ide_execute_command(drive, WIN_PACKETCMD, handler, ATAPI_WAIT_PC, cdrom_timer_expiry); | ||
866 | return ide_started; | ||
867 | } else { | ||
868 | unsigned long flags; | ||
869 | |||
870 | /* packet command */ | ||
871 | spin_lock_irqsave(&ide_lock, flags); | ||
872 | hwif->OUTBSYNC(drive, WIN_PACKETCMD, IDE_COMMAND_REG); | ||
873 | ndelay(400); | ||
874 | spin_unlock_irqrestore(&ide_lock, flags); | ||
875 | |||
876 | return (*handler) (drive); | ||
877 | } | ||
878 | } | ||
879 | |||
880 | /* Send a packet command to DRIVE described by CMD_BUF and CMD_LEN. | ||
881 | The device registers must have already been prepared | ||
882 | by cdrom_start_packet_command. | ||
883 | HANDLER is the interrupt handler to call when the command completes | ||
884 | or there's data ready. */ | ||
885 | /* | ||
886 | * changed 5 parameters to 3 for dvd-ram | ||
887 | * struct packet_command *pc; now packet_command_t *pc; | ||
888 | */ | ||
889 | #define ATAPI_MIN_CDB_BYTES 12 | ||
890 | static ide_startstop_t cdrom_transfer_packet_command (ide_drive_t *drive, | ||
891 | struct request *rq, | ||
892 | ide_handler_t *handler) | ||
893 | { | ||
894 | ide_hwif_t *hwif = drive->hwif; | ||
895 | int cmd_len; | ||
896 | struct cdrom_info *info = drive->driver_data; | ||
897 | ide_startstop_t startstop; | ||
898 | |||
899 | if (CDROM_CONFIG_FLAGS(drive)->drq_interrupt) { | ||
900 | /* Here we should have been called after receiving an interrupt | ||
901 | from the device. DRQ should how be set. */ | ||
902 | |||
903 | /* Check for errors. */ | ||
904 | if (cdrom_decode_status(drive, DRQ_STAT, NULL)) | ||
905 | return ide_stopped; | ||
906 | } else { | ||
907 | /* Otherwise, we must wait for DRQ to get set. */ | ||
908 | if (ide_wait_stat(&startstop, drive, DRQ_STAT, | ||
909 | BUSY_STAT, WAIT_READY)) | ||
910 | return startstop; | ||
911 | } | ||
912 | |||
913 | /* Arm the interrupt handler. */ | ||
914 | ide_set_handler(drive, handler, rq->timeout, cdrom_timer_expiry); | ||
915 | |||
916 | /* ATAPI commands get padded out to 12 bytes minimum */ | ||
917 | cmd_len = COMMAND_SIZE(rq->cmd[0]); | ||
918 | if (cmd_len < ATAPI_MIN_CDB_BYTES) | ||
919 | cmd_len = ATAPI_MIN_CDB_BYTES; | ||
920 | |||
921 | /* Send the command to the device. */ | ||
922 | HWIF(drive)->atapi_output_bytes(drive, rq->cmd, cmd_len); | ||
923 | |||
924 | /* Start the DMA if need be */ | ||
925 | if (info->dma) | ||
926 | hwif->dma_start(drive); | ||
927 | |||
928 | return ide_started; | ||
929 | } | ||
930 | |||
931 | /**************************************************************************** | ||
932 | * Block read functions. | ||
933 | */ | ||
934 | |||
935 | /* | ||
936 | * Buffer up to SECTORS_TO_TRANSFER sectors from the drive in our sector | ||
937 | * buffer. Once the first sector is added, any subsequent sectors are | ||
938 | * assumed to be continuous (until the buffer is cleared). For the first | ||
939 | * sector added, SECTOR is its sector number. (SECTOR is then ignored until | ||
940 | * the buffer is cleared.) | ||
941 | */ | ||
942 | static void cdrom_buffer_sectors (ide_drive_t *drive, unsigned long sector, | ||
943 | int sectors_to_transfer) | ||
944 | { | ||
945 | struct cdrom_info *info = drive->driver_data; | ||
946 | |||
947 | /* Number of sectors to read into the buffer. */ | ||
948 | int sectors_to_buffer = min_t(int, sectors_to_transfer, | ||
949 | (SECTOR_BUFFER_SIZE >> SECTOR_BITS) - | ||
950 | info->nsectors_buffered); | ||
951 | |||
952 | char *dest; | ||
953 | |||
954 | /* If we couldn't get a buffer, don't try to buffer anything... */ | ||
955 | if (info->buffer == NULL) | ||
956 | sectors_to_buffer = 0; | ||
957 | |||
958 | /* If this is the first sector in the buffer, remember its number. */ | ||
959 | if (info->nsectors_buffered == 0) | ||
960 | info->sector_buffered = sector; | ||
961 | |||
962 | /* Read the data into the buffer. */ | ||
963 | dest = info->buffer + info->nsectors_buffered * SECTOR_SIZE; | ||
964 | while (sectors_to_buffer > 0) { | ||
965 | HWIF(drive)->atapi_input_bytes(drive, dest, SECTOR_SIZE); | ||
966 | --sectors_to_buffer; | ||
967 | --sectors_to_transfer; | ||
968 | ++info->nsectors_buffered; | ||
969 | dest += SECTOR_SIZE; | ||
970 | } | ||
971 | |||
972 | /* Throw away any remaining data. */ | ||
973 | while (sectors_to_transfer > 0) { | ||
974 | static char dum[SECTOR_SIZE]; | ||
975 | HWIF(drive)->atapi_input_bytes(drive, dum, sizeof (dum)); | ||
976 | --sectors_to_transfer; | ||
977 | } | ||
978 | } | ||
979 | |||
980 | /* | ||
981 | * Check the contents of the interrupt reason register from the cdrom | ||
982 | * and attempt to recover if there are problems. Returns 0 if everything's | ||
983 | * ok; nonzero if the request has been terminated. | ||
984 | */ | ||
985 | static inline | ||
986 | int cdrom_read_check_ireason (ide_drive_t *drive, int len, int ireason) | ||
987 | { | ||
988 | if (ireason == 2) | ||
989 | return 0; | ||
990 | else if (ireason == 0) { | ||
991 | /* Whoops... The drive is expecting to receive data from us! */ | ||
992 | printk(KERN_ERR "%s: read_intr: Drive wants to transfer data the " | ||
993 | "wrong way!\n", drive->name); | ||
994 | |||
995 | /* Throw some data at the drive so it doesn't hang | ||
996 | and quit this request. */ | ||
997 | while (len > 0) { | ||
998 | int dum = 0; | ||
999 | HWIF(drive)->atapi_output_bytes(drive, &dum, sizeof (dum)); | ||
1000 | len -= sizeof (dum); | ||
1001 | } | ||
1002 | } else if (ireason == 1) { | ||
1003 | /* Some drives (ASUS) seem to tell us that status | ||
1004 | * info is available. just get it and ignore. | ||
1005 | */ | ||
1006 | (void) HWIF(drive)->INB(IDE_STATUS_REG); | ||
1007 | return 0; | ||
1008 | } else { | ||
1009 | /* Drive wants a command packet, or invalid ireason... */ | ||
1010 | printk(KERN_ERR "%s: read_intr: bad interrupt reason %x\n", drive->name, | ||
1011 | ireason); | ||
1012 | } | ||
1013 | |||
1014 | cdrom_end_request(drive, 0); | ||
1015 | return -1; | ||
1016 | } | ||
1017 | |||
1018 | /* | ||
1019 | * Interrupt routine. Called when a read request has completed. | ||
1020 | */ | ||
1021 | static ide_startstop_t cdrom_read_intr (ide_drive_t *drive) | ||
1022 | { | ||
1023 | int stat; | ||
1024 | int ireason, len, sectors_to_transfer, nskip; | ||
1025 | struct cdrom_info *info = drive->driver_data; | ||
1026 | u8 lowcyl = 0, highcyl = 0; | ||
1027 | int dma = info->dma, dma_error = 0; | ||
1028 | |||
1029 | struct request *rq = HWGROUP(drive)->rq; | ||
1030 | |||
1031 | /* | ||
1032 | * handle dma case | ||
1033 | */ | ||
1034 | if (dma) { | ||
1035 | info->dma = 0; | ||
1036 | if ((dma_error = HWIF(drive)->ide_dma_end(drive))) | ||
1037 | __ide_dma_off(drive); | ||
1038 | } | ||
1039 | |||
1040 | if (cdrom_decode_status(drive, 0, &stat)) | ||
1041 | return ide_stopped; | ||
1042 | |||
1043 | if (dma) { | ||
1044 | if (!dma_error) { | ||
1045 | ide_end_request(drive, 1, rq->nr_sectors); | ||
1046 | return ide_stopped; | ||
1047 | } else | ||
1048 | return ide_error(drive, "dma error", stat); | ||
1049 | } | ||
1050 | |||
1051 | /* Read the interrupt reason and the transfer length. */ | ||
1052 | ireason = HWIF(drive)->INB(IDE_IREASON_REG) & 0x3; | ||
1053 | lowcyl = HWIF(drive)->INB(IDE_BCOUNTL_REG); | ||
1054 | highcyl = HWIF(drive)->INB(IDE_BCOUNTH_REG); | ||
1055 | |||
1056 | len = lowcyl + (256 * highcyl); | ||
1057 | |||
1058 | /* If DRQ is clear, the command has completed. */ | ||
1059 | if ((stat & DRQ_STAT) == 0) { | ||
1060 | /* If we're not done filling the current buffer, complain. | ||
1061 | Otherwise, complete the command normally. */ | ||
1062 | if (rq->current_nr_sectors > 0) { | ||
1063 | printk (KERN_ERR "%s: cdrom_read_intr: data underrun (%d blocks)\n", | ||
1064 | drive->name, rq->current_nr_sectors); | ||
1065 | rq->flags |= REQ_FAILED; | ||
1066 | cdrom_end_request(drive, 0); | ||
1067 | } else | ||
1068 | cdrom_end_request(drive, 1); | ||
1069 | return ide_stopped; | ||
1070 | } | ||
1071 | |||
1072 | /* Check that the drive is expecting to do the same thing we are. */ | ||
1073 | if (cdrom_read_check_ireason (drive, len, ireason)) | ||
1074 | return ide_stopped; | ||
1075 | |||
1076 | /* Assume that the drive will always provide data in multiples | ||
1077 | of at least SECTOR_SIZE, as it gets hairy to keep track | ||
1078 | of the transfers otherwise. */ | ||
1079 | if ((len % SECTOR_SIZE) != 0) { | ||
1080 | printk (KERN_ERR "%s: cdrom_read_intr: Bad transfer size %d\n", | ||
1081 | drive->name, len); | ||
1082 | if (CDROM_CONFIG_FLAGS(drive)->limit_nframes) | ||
1083 | printk (KERN_ERR " This drive is not supported by this version of the driver\n"); | ||
1084 | else { | ||
1085 | printk (KERN_ERR " Trying to limit transfer sizes\n"); | ||
1086 | CDROM_CONFIG_FLAGS(drive)->limit_nframes = 1; | ||
1087 | } | ||
1088 | cdrom_end_request(drive, 0); | ||
1089 | return ide_stopped; | ||
1090 | } | ||
1091 | |||
1092 | /* The number of sectors we need to read from the drive. */ | ||
1093 | sectors_to_transfer = len / SECTOR_SIZE; | ||
1094 | |||
1095 | /* First, figure out if we need to bit-bucket | ||
1096 | any of the leading sectors. */ | ||
1097 | nskip = min_t(int, rq->current_nr_sectors - bio_cur_sectors(rq->bio), sectors_to_transfer); | ||
1098 | |||
1099 | while (nskip > 0) { | ||
1100 | /* We need to throw away a sector. */ | ||
1101 | static char dum[SECTOR_SIZE]; | ||
1102 | HWIF(drive)->atapi_input_bytes(drive, dum, sizeof (dum)); | ||
1103 | |||
1104 | --rq->current_nr_sectors; | ||
1105 | --nskip; | ||
1106 | --sectors_to_transfer; | ||
1107 | } | ||
1108 | |||
1109 | /* Now loop while we still have data to read from the drive. */ | ||
1110 | while (sectors_to_transfer > 0) { | ||
1111 | int this_transfer; | ||
1112 | |||
1113 | /* If we've filled the present buffer but there's another | ||
1114 | chained buffer after it, move on. */ | ||
1115 | if (rq->current_nr_sectors == 0 && rq->nr_sectors) | ||
1116 | cdrom_end_request(drive, 1); | ||
1117 | |||
1118 | /* If the buffers are full, cache the rest of the data in our | ||
1119 | internal buffer. */ | ||
1120 | if (rq->current_nr_sectors == 0) { | ||
1121 | cdrom_buffer_sectors(drive, rq->sector, sectors_to_transfer); | ||
1122 | sectors_to_transfer = 0; | ||
1123 | } else { | ||
1124 | /* Transfer data to the buffers. | ||
1125 | Figure out how many sectors we can transfer | ||
1126 | to the current buffer. */ | ||
1127 | this_transfer = min_t(int, sectors_to_transfer, | ||
1128 | rq->current_nr_sectors); | ||
1129 | |||
1130 | /* Read this_transfer sectors | ||
1131 | into the current buffer. */ | ||
1132 | while (this_transfer > 0) { | ||
1133 | HWIF(drive)->atapi_input_bytes(drive, rq->buffer, SECTOR_SIZE); | ||
1134 | rq->buffer += SECTOR_SIZE; | ||
1135 | --rq->nr_sectors; | ||
1136 | --rq->current_nr_sectors; | ||
1137 | ++rq->sector; | ||
1138 | --this_transfer; | ||
1139 | --sectors_to_transfer; | ||
1140 | } | ||
1141 | } | ||
1142 | } | ||
1143 | |||
1144 | /* Done moving data! Wait for another interrupt. */ | ||
1145 | ide_set_handler(drive, &cdrom_read_intr, ATAPI_WAIT_PC, NULL); | ||
1146 | return ide_started; | ||
1147 | } | ||
1148 | |||
1149 | /* | ||
1150 | * Try to satisfy some of the current read request from our cached data. | ||
1151 | * Returns nonzero if the request has been completed, zero otherwise. | ||
1152 | */ | ||
1153 | static int cdrom_read_from_buffer (ide_drive_t *drive) | ||
1154 | { | ||
1155 | struct cdrom_info *info = drive->driver_data; | ||
1156 | struct request *rq = HWGROUP(drive)->rq; | ||
1157 | unsigned short sectors_per_frame; | ||
1158 | |||
1159 | sectors_per_frame = queue_hardsect_size(drive->queue) >> SECTOR_BITS; | ||
1160 | |||
1161 | /* Can't do anything if there's no buffer. */ | ||
1162 | if (info->buffer == NULL) return 0; | ||
1163 | |||
1164 | /* Loop while this request needs data and the next block is present | ||
1165 | in our cache. */ | ||
1166 | while (rq->nr_sectors > 0 && | ||
1167 | rq->sector >= info->sector_buffered && | ||
1168 | rq->sector < info->sector_buffered + info->nsectors_buffered) { | ||
1169 | if (rq->current_nr_sectors == 0) | ||
1170 | cdrom_end_request(drive, 1); | ||
1171 | |||
1172 | memcpy (rq->buffer, | ||
1173 | info->buffer + | ||
1174 | (rq->sector - info->sector_buffered) * SECTOR_SIZE, | ||
1175 | SECTOR_SIZE); | ||
1176 | rq->buffer += SECTOR_SIZE; | ||
1177 | --rq->current_nr_sectors; | ||
1178 | --rq->nr_sectors; | ||
1179 | ++rq->sector; | ||
1180 | } | ||
1181 | |||
1182 | /* If we've satisfied the current request, | ||
1183 | terminate it successfully. */ | ||
1184 | if (rq->nr_sectors == 0) { | ||
1185 | cdrom_end_request(drive, 1); | ||
1186 | return -1; | ||
1187 | } | ||
1188 | |||
1189 | /* Move on to the next buffer if needed. */ | ||
1190 | if (rq->current_nr_sectors == 0) | ||
1191 | cdrom_end_request(drive, 1); | ||
1192 | |||
1193 | /* If this condition does not hold, then the kluge i use to | ||
1194 | represent the number of sectors to skip at the start of a transfer | ||
1195 | will fail. I think that this will never happen, but let's be | ||
1196 | paranoid and check. */ | ||
1197 | if (rq->current_nr_sectors < bio_cur_sectors(rq->bio) && | ||
1198 | (rq->sector & (sectors_per_frame - 1))) { | ||
1199 | printk(KERN_ERR "%s: cdrom_read_from_buffer: buffer botch (%ld)\n", | ||
1200 | drive->name, (long)rq->sector); | ||
1201 | cdrom_end_request(drive, 0); | ||
1202 | return -1; | ||
1203 | } | ||
1204 | |||
1205 | return 0; | ||
1206 | } | ||
1207 | |||
1208 | /* | ||
1209 | * Routine to send a read packet command to the drive. | ||
1210 | * This is usually called directly from cdrom_start_read. | ||
1211 | * However, for drq_interrupt devices, it is called from an interrupt | ||
1212 | * when the drive is ready to accept the command. | ||
1213 | */ | ||
1214 | static ide_startstop_t cdrom_start_read_continuation (ide_drive_t *drive) | ||
1215 | { | ||
1216 | struct request *rq = HWGROUP(drive)->rq; | ||
1217 | unsigned short sectors_per_frame; | ||
1218 | int nskip; | ||
1219 | |||
1220 | sectors_per_frame = queue_hardsect_size(drive->queue) >> SECTOR_BITS; | ||
1221 | |||
1222 | /* If the requested sector doesn't start on a cdrom block boundary, | ||
1223 | we must adjust the start of the transfer so that it does, | ||
1224 | and remember to skip the first few sectors. | ||
1225 | If the CURRENT_NR_SECTORS field is larger than the size | ||
1226 | of the buffer, it will mean that we're to skip a number | ||
1227 | of sectors equal to the amount by which CURRENT_NR_SECTORS | ||
1228 | is larger than the buffer size. */ | ||
1229 | nskip = rq->sector & (sectors_per_frame - 1); | ||
1230 | if (nskip > 0) { | ||
1231 | /* Sanity check... */ | ||
1232 | if (rq->current_nr_sectors != bio_cur_sectors(rq->bio) && | ||
1233 | (rq->sector & (sectors_per_frame - 1))) { | ||
1234 | printk(KERN_ERR "%s: cdrom_start_read_continuation: buffer botch (%u)\n", | ||
1235 | drive->name, rq->current_nr_sectors); | ||
1236 | cdrom_end_request(drive, 0); | ||
1237 | return ide_stopped; | ||
1238 | } | ||
1239 | rq->current_nr_sectors += nskip; | ||
1240 | } | ||
1241 | |||
1242 | /* Set up the command */ | ||
1243 | rq->timeout = ATAPI_WAIT_PC; | ||
1244 | |||
1245 | /* Send the command to the drive and return. */ | ||
1246 | return cdrom_transfer_packet_command(drive, rq, &cdrom_read_intr); | ||
1247 | } | ||
1248 | |||
1249 | |||
1250 | #define IDECD_SEEK_THRESHOLD (1000) /* 1000 blocks */ | ||
1251 | #define IDECD_SEEK_TIMER (5 * WAIT_MIN_SLEEP) /* 100 ms */ | ||
1252 | #define IDECD_SEEK_TIMEOUT (2 * WAIT_CMD) /* 20 sec */ | ||
1253 | |||
1254 | static ide_startstop_t cdrom_seek_intr (ide_drive_t *drive) | ||
1255 | { | ||
1256 | struct cdrom_info *info = drive->driver_data; | ||
1257 | int stat; | ||
1258 | static int retry = 10; | ||
1259 | |||
1260 | if (cdrom_decode_status(drive, 0, &stat)) | ||
1261 | return ide_stopped; | ||
1262 | CDROM_CONFIG_FLAGS(drive)->seeking = 1; | ||
1263 | |||
1264 | if (retry && time_after(jiffies, info->start_seek + IDECD_SEEK_TIMER)) { | ||
1265 | if (--retry == 0) { | ||
1266 | /* | ||
1267 | * this condition is far too common, to bother | ||
1268 | * users about it | ||
1269 | */ | ||
1270 | /* printk("%s: disabled DSC seek overlap\n", drive->name);*/ | ||
1271 | drive->dsc_overlap = 0; | ||
1272 | } | ||
1273 | } | ||
1274 | return ide_stopped; | ||
1275 | } | ||
1276 | |||
1277 | static ide_startstop_t cdrom_start_seek_continuation (ide_drive_t *drive) | ||
1278 | { | ||
1279 | struct request *rq = HWGROUP(drive)->rq; | ||
1280 | sector_t frame = rq->sector; | ||
1281 | |||
1282 | sector_div(frame, queue_hardsect_size(drive->queue) >> SECTOR_BITS); | ||
1283 | |||
1284 | memset(rq->cmd, 0, sizeof(rq->cmd)); | ||
1285 | rq->cmd[0] = GPCMD_SEEK; | ||
1286 | put_unaligned(cpu_to_be32(frame), (unsigned int *) &rq->cmd[2]); | ||
1287 | |||
1288 | rq->timeout = ATAPI_WAIT_PC; | ||
1289 | return cdrom_transfer_packet_command(drive, rq, &cdrom_seek_intr); | ||
1290 | } | ||
1291 | |||
1292 | static ide_startstop_t cdrom_start_seek (ide_drive_t *drive, unsigned int block) | ||
1293 | { | ||
1294 | struct cdrom_info *info = drive->driver_data; | ||
1295 | |||
1296 | info->dma = 0; | ||
1297 | info->cmd = 0; | ||
1298 | info->start_seek = jiffies; | ||
1299 | return cdrom_start_packet_command(drive, 0, cdrom_start_seek_continuation); | ||
1300 | } | ||
1301 | |||
1302 | /* Fix up a possibly partially-processed request so that we can | ||
1303 | start it over entirely, or even put it back on the request queue. */ | ||
1304 | static void restore_request (struct request *rq) | ||
1305 | { | ||
1306 | if (rq->buffer != bio_data(rq->bio)) { | ||
1307 | sector_t n = (rq->buffer - (char *) bio_data(rq->bio)) / SECTOR_SIZE; | ||
1308 | |||
1309 | rq->buffer = bio_data(rq->bio); | ||
1310 | rq->nr_sectors += n; | ||
1311 | rq->sector -= n; | ||
1312 | } | ||
1313 | rq->hard_cur_sectors = rq->current_nr_sectors = bio_cur_sectors(rq->bio); | ||
1314 | rq->hard_nr_sectors = rq->nr_sectors; | ||
1315 | rq->hard_sector = rq->sector; | ||
1316 | rq->q->prep_rq_fn(rq->q, rq); | ||
1317 | } | ||
1318 | |||
1319 | /* | ||
1320 | * Start a read request from the CD-ROM. | ||
1321 | */ | ||
1322 | static ide_startstop_t cdrom_start_read (ide_drive_t *drive, unsigned int block) | ||
1323 | { | ||
1324 | struct cdrom_info *info = drive->driver_data; | ||
1325 | struct request *rq = HWGROUP(drive)->rq; | ||
1326 | unsigned short sectors_per_frame; | ||
1327 | |||
1328 | sectors_per_frame = queue_hardsect_size(drive->queue) >> SECTOR_BITS; | ||
1329 | |||
1330 | /* We may be retrying this request after an error. Fix up | ||
1331 | any weirdness which might be present in the request packet. */ | ||
1332 | restore_request(rq); | ||
1333 | |||
1334 | /* Satisfy whatever we can of this request from our cached sector. */ | ||
1335 | if (cdrom_read_from_buffer(drive)) | ||
1336 | return ide_stopped; | ||
1337 | |||
1338 | blk_attempt_remerge(drive->queue, rq); | ||
1339 | |||
1340 | /* Clear the local sector buffer. */ | ||
1341 | info->nsectors_buffered = 0; | ||
1342 | |||
1343 | /* use dma, if possible. */ | ||
1344 | info->dma = drive->using_dma; | ||
1345 | if ((rq->sector & (sectors_per_frame - 1)) || | ||
1346 | (rq->nr_sectors & (sectors_per_frame - 1))) | ||
1347 | info->dma = 0; | ||
1348 | |||
1349 | info->cmd = READ; | ||
1350 | |||
1351 | /* Start sending the read request to the drive. */ | ||
1352 | return cdrom_start_packet_command(drive, 32768, cdrom_start_read_continuation); | ||
1353 | } | ||
1354 | |||
1355 | /**************************************************************************** | ||
1356 | * Execute all other packet commands. | ||
1357 | */ | ||
1358 | |||
1359 | /* Interrupt routine for packet command completion. */ | ||
1360 | static ide_startstop_t cdrom_pc_intr (ide_drive_t *drive) | ||
1361 | { | ||
1362 | int ireason, len, thislen; | ||
1363 | struct request *rq = HWGROUP(drive)->rq; | ||
1364 | u8 lowcyl = 0, highcyl = 0; | ||
1365 | int stat; | ||
1366 | |||
1367 | /* Check for errors. */ | ||
1368 | if (cdrom_decode_status(drive, 0, &stat)) | ||
1369 | return ide_stopped; | ||
1370 | |||
1371 | /* Read the interrupt reason and the transfer length. */ | ||
1372 | ireason = HWIF(drive)->INB(IDE_IREASON_REG); | ||
1373 | lowcyl = HWIF(drive)->INB(IDE_BCOUNTL_REG); | ||
1374 | highcyl = HWIF(drive)->INB(IDE_BCOUNTH_REG); | ||
1375 | |||
1376 | len = lowcyl + (256 * highcyl); | ||
1377 | |||
1378 | /* If DRQ is clear, the command has completed. | ||
1379 | Complain if we still have data left to transfer. */ | ||
1380 | if ((stat & DRQ_STAT) == 0) { | ||
1381 | /* Some of the trailing request sense fields are optional, and | ||
1382 | some drives don't send them. Sigh. */ | ||
1383 | if (rq->cmd[0] == GPCMD_REQUEST_SENSE && | ||
1384 | rq->data_len > 0 && | ||
1385 | rq->data_len <= 5) { | ||
1386 | while (rq->data_len > 0) { | ||
1387 | *(unsigned char *)rq->data++ = 0; | ||
1388 | --rq->data_len; | ||
1389 | } | ||
1390 | } | ||
1391 | |||
1392 | if (rq->data_len == 0) | ||
1393 | cdrom_end_request(drive, 1); | ||
1394 | else { | ||
1395 | /* Comment this out, because this always happens | ||
1396 | right after a reset occurs, and it is annoying to | ||
1397 | always print expected stuff. */ | ||
1398 | /* | ||
1399 | printk ("%s: cdrom_pc_intr: data underrun %d\n", | ||
1400 | drive->name, pc->buflen); | ||
1401 | */ | ||
1402 | rq->flags |= REQ_FAILED; | ||
1403 | cdrom_end_request(drive, 0); | ||
1404 | } | ||
1405 | return ide_stopped; | ||
1406 | } | ||
1407 | |||
1408 | /* Figure out how much data to transfer. */ | ||
1409 | thislen = rq->data_len; | ||
1410 | if (thislen > len) thislen = len; | ||
1411 | |||
1412 | /* The drive wants to be written to. */ | ||
1413 | if ((ireason & 3) == 0) { | ||
1414 | if (!rq->data) { | ||
1415 | blk_dump_rq_flags(rq, "cdrom_pc_intr, write"); | ||
1416 | goto confused; | ||
1417 | } | ||
1418 | /* Transfer the data. */ | ||
1419 | HWIF(drive)->atapi_output_bytes(drive, rq->data, thislen); | ||
1420 | |||
1421 | /* If we haven't moved enough data to satisfy the drive, | ||
1422 | add some padding. */ | ||
1423 | while (len > thislen) { | ||
1424 | int dum = 0; | ||
1425 | HWIF(drive)->atapi_output_bytes(drive, &dum, sizeof(dum)); | ||
1426 | len -= sizeof(dum); | ||
1427 | } | ||
1428 | |||
1429 | /* Keep count of how much data we've moved. */ | ||
1430 | rq->data += thislen; | ||
1431 | rq->data_len -= thislen; | ||
1432 | } | ||
1433 | |||
1434 | /* Same drill for reading. */ | ||
1435 | else if ((ireason & 3) == 2) { | ||
1436 | if (!rq->data) { | ||
1437 | blk_dump_rq_flags(rq, "cdrom_pc_intr, write"); | ||
1438 | goto confused; | ||
1439 | } | ||
1440 | /* Transfer the data. */ | ||
1441 | HWIF(drive)->atapi_input_bytes(drive, rq->data, thislen); | ||
1442 | |||
1443 | /* If we haven't moved enough data to satisfy the drive, | ||
1444 | add some padding. */ | ||
1445 | while (len > thislen) { | ||
1446 | int dum = 0; | ||
1447 | HWIF(drive)->atapi_input_bytes(drive, &dum, sizeof(dum)); | ||
1448 | len -= sizeof(dum); | ||
1449 | } | ||
1450 | |||
1451 | /* Keep count of how much data we've moved. */ | ||
1452 | rq->data += thislen; | ||
1453 | rq->data_len -= thislen; | ||
1454 | |||
1455 | if (rq->flags & REQ_SENSE) | ||
1456 | rq->sense_len += thislen; | ||
1457 | } else { | ||
1458 | confused: | ||
1459 | printk (KERN_ERR "%s: cdrom_pc_intr: The drive " | ||
1460 | "appears confused (ireason = 0x%02x)\n", | ||
1461 | drive->name, ireason); | ||
1462 | rq->flags |= REQ_FAILED; | ||
1463 | } | ||
1464 | |||
1465 | /* Now we wait for another interrupt. */ | ||
1466 | ide_set_handler(drive, &cdrom_pc_intr, ATAPI_WAIT_PC, cdrom_timer_expiry); | ||
1467 | return ide_started; | ||
1468 | } | ||
1469 | |||
1470 | static ide_startstop_t cdrom_do_pc_continuation (ide_drive_t *drive) | ||
1471 | { | ||
1472 | struct request *rq = HWGROUP(drive)->rq; | ||
1473 | |||
1474 | if (!rq->timeout) | ||
1475 | rq->timeout = ATAPI_WAIT_PC; | ||
1476 | |||
1477 | /* Send the command to the drive and return. */ | ||
1478 | return cdrom_transfer_packet_command(drive, rq, &cdrom_pc_intr); | ||
1479 | } | ||
1480 | |||
1481 | |||
1482 | static ide_startstop_t cdrom_do_packet_command (ide_drive_t *drive) | ||
1483 | { | ||
1484 | int len; | ||
1485 | struct request *rq = HWGROUP(drive)->rq; | ||
1486 | struct cdrom_info *info = drive->driver_data; | ||
1487 | |||
1488 | info->dma = 0; | ||
1489 | info->cmd = 0; | ||
1490 | rq->flags &= ~REQ_FAILED; | ||
1491 | len = rq->data_len; | ||
1492 | |||
1493 | /* Start sending the command to the drive. */ | ||
1494 | return cdrom_start_packet_command(drive, len, cdrom_do_pc_continuation); | ||
1495 | } | ||
1496 | |||
1497 | |||
1498 | static | ||
1499 | int cdrom_queue_packet_command(ide_drive_t *drive, struct request *rq) | ||
1500 | { | ||
1501 | struct request_sense sense; | ||
1502 | int retries = 10; | ||
1503 | unsigned int flags = rq->flags; | ||
1504 | |||
1505 | if (rq->sense == NULL) | ||
1506 | rq->sense = &sense; | ||
1507 | |||
1508 | /* Start of retry loop. */ | ||
1509 | do { | ||
1510 | int error; | ||
1511 | unsigned long time = jiffies; | ||
1512 | rq->flags = flags; | ||
1513 | |||
1514 | error = ide_do_drive_cmd(drive, rq, ide_wait); | ||
1515 | time = jiffies - time; | ||
1516 | |||
1517 | /* FIXME: we should probably abort/retry or something | ||
1518 | * in case of failure */ | ||
1519 | if (rq->flags & REQ_FAILED) { | ||
1520 | /* The request failed. Retry if it was due to a unit | ||
1521 | attention status | ||
1522 | (usually means media was changed). */ | ||
1523 | struct request_sense *reqbuf = rq->sense; | ||
1524 | |||
1525 | if (reqbuf->sense_key == UNIT_ATTENTION) | ||
1526 | cdrom_saw_media_change(drive); | ||
1527 | else if (reqbuf->sense_key == NOT_READY && | ||
1528 | reqbuf->asc == 4 && reqbuf->ascq != 4) { | ||
1529 | /* The drive is in the process of loading | ||
1530 | a disk. Retry, but wait a little to give | ||
1531 | the drive time to complete the load. */ | ||
1532 | ssleep(2); | ||
1533 | } else { | ||
1534 | /* Otherwise, don't retry. */ | ||
1535 | retries = 0; | ||
1536 | } | ||
1537 | --retries; | ||
1538 | } | ||
1539 | |||
1540 | /* End of retry loop. */ | ||
1541 | } while ((rq->flags & REQ_FAILED) && retries >= 0); | ||
1542 | |||
1543 | /* Return an error if the command failed. */ | ||
1544 | return (rq->flags & REQ_FAILED) ? -EIO : 0; | ||
1545 | } | ||
1546 | |||
1547 | /* | ||
1548 | * Write handling | ||
1549 | */ | ||
1550 | static inline int cdrom_write_check_ireason(ide_drive_t *drive, int len, int ireason) | ||
1551 | { | ||
1552 | /* Two notes about IDE interrupt reason here - 0 means that | ||
1553 | * the drive wants to receive data from us, 2 means that | ||
1554 | * the drive is expecting to transfer data to us. | ||
1555 | */ | ||
1556 | if (ireason == 0) | ||
1557 | return 0; | ||
1558 | else if (ireason == 2) { | ||
1559 | /* Whoops... The drive wants to send data. */ | ||
1560 | printk(KERN_ERR "%s: write_intr: wrong transfer direction!\n", | ||
1561 | drive->name); | ||
1562 | |||
1563 | while (len > 0) { | ||
1564 | int dum = 0; | ||
1565 | HWIF(drive)->atapi_input_bytes(drive, &dum, sizeof(dum)); | ||
1566 | len -= sizeof(dum); | ||
1567 | } | ||
1568 | } else { | ||
1569 | /* Drive wants a command packet, or invalid ireason... */ | ||
1570 | printk(KERN_ERR "%s: write_intr: bad interrupt reason %x\n", | ||
1571 | drive->name, ireason); | ||
1572 | } | ||
1573 | |||
1574 | cdrom_end_request(drive, 0); | ||
1575 | return 1; | ||
1576 | } | ||
1577 | |||
1578 | static void post_transform_command(struct request *req) | ||
1579 | { | ||
1580 | u8 *c = req->cmd; | ||
1581 | char *ibuf; | ||
1582 | |||
1583 | if (!blk_pc_request(req)) | ||
1584 | return; | ||
1585 | |||
1586 | if (req->bio) | ||
1587 | ibuf = bio_data(req->bio); | ||
1588 | else | ||
1589 | ibuf = req->data; | ||
1590 | |||
1591 | if (!ibuf) | ||
1592 | return; | ||
1593 | |||
1594 | /* | ||
1595 | * set ansi-revision and response data as atapi | ||
1596 | */ | ||
1597 | if (c[0] == GPCMD_INQUIRY) { | ||
1598 | ibuf[2] |= 2; | ||
1599 | ibuf[3] = (ibuf[3] & 0xf0) | 2; | ||
1600 | } | ||
1601 | } | ||
1602 | |||
1603 | typedef void (xfer_func_t)(ide_drive_t *, void *, u32); | ||
1604 | |||
1605 | /* | ||
1606 | * best way to deal with dma that is not sector aligned right now... note | ||
1607 | * that in this path we are not using ->data or ->buffer at all. this irs | ||
1608 | * can replace cdrom_pc_intr, cdrom_read_intr, and cdrom_write_intr in the | ||
1609 | * future. | ||
1610 | */ | ||
1611 | static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive) | ||
1612 | { | ||
1613 | struct cdrom_info *info = drive->driver_data; | ||
1614 | struct request *rq = HWGROUP(drive)->rq; | ||
1615 | int dma_error, dma, stat, ireason, len, thislen; | ||
1616 | u8 lowcyl, highcyl; | ||
1617 | xfer_func_t *xferfunc; | ||
1618 | unsigned long flags; | ||
1619 | |||
1620 | /* Check for errors. */ | ||
1621 | dma_error = 0; | ||
1622 | dma = info->dma; | ||
1623 | if (dma) { | ||
1624 | info->dma = 0; | ||
1625 | dma_error = HWIF(drive)->ide_dma_end(drive); | ||
1626 | } | ||
1627 | |||
1628 | if (cdrom_decode_status(drive, 0, &stat)) | ||
1629 | return ide_stopped; | ||
1630 | |||
1631 | /* | ||
1632 | * using dma, transfer is complete now | ||
1633 | */ | ||
1634 | if (dma) { | ||
1635 | if (dma_error) { | ||
1636 | printk(KERN_ERR "ide-cd: dma error\n"); | ||
1637 | __ide_dma_off(drive); | ||
1638 | return ide_error(drive, "dma error", stat); | ||
1639 | } | ||
1640 | |||
1641 | end_that_request_chunk(rq, 1, rq->data_len); | ||
1642 | rq->data_len = 0; | ||
1643 | goto end_request; | ||
1644 | } | ||
1645 | |||
1646 | /* | ||
1647 | * ok we fall to pio :/ | ||
1648 | */ | ||
1649 | ireason = HWIF(drive)->INB(IDE_IREASON_REG) & 0x3; | ||
1650 | lowcyl = HWIF(drive)->INB(IDE_BCOUNTL_REG); | ||
1651 | highcyl = HWIF(drive)->INB(IDE_BCOUNTH_REG); | ||
1652 | |||
1653 | len = lowcyl + (256 * highcyl); | ||
1654 | thislen = rq->data_len; | ||
1655 | if (thislen > len) | ||
1656 | thislen = len; | ||
1657 | |||
1658 | /* | ||
1659 | * If DRQ is clear, the command has completed. | ||
1660 | */ | ||
1661 | if ((stat & DRQ_STAT) == 0) | ||
1662 | goto end_request; | ||
1663 | |||
1664 | /* | ||
1665 | * check which way to transfer data | ||
1666 | */ | ||
1667 | if (rq_data_dir(rq) == WRITE) { | ||
1668 | /* | ||
1669 | * write to drive | ||
1670 | */ | ||
1671 | if (cdrom_write_check_ireason(drive, len, ireason)) | ||
1672 | return ide_stopped; | ||
1673 | |||
1674 | xferfunc = HWIF(drive)->atapi_output_bytes; | ||
1675 | } else { | ||
1676 | /* | ||
1677 | * read from drive | ||
1678 | */ | ||
1679 | if (cdrom_read_check_ireason(drive, len, ireason)) | ||
1680 | return ide_stopped; | ||
1681 | |||
1682 | xferfunc = HWIF(drive)->atapi_input_bytes; | ||
1683 | } | ||
1684 | |||
1685 | /* | ||
1686 | * transfer data | ||
1687 | */ | ||
1688 | while (thislen > 0) { | ||
1689 | int blen = blen = rq->data_len; | ||
1690 | char *ptr = rq->data; | ||
1691 | |||
1692 | /* | ||
1693 | * bio backed? | ||
1694 | */ | ||
1695 | if (rq->bio) { | ||
1696 | ptr = bio_data(rq->bio); | ||
1697 | blen = bio_iovec(rq->bio)->bv_len; | ||
1698 | } | ||
1699 | |||
1700 | if (!ptr) { | ||
1701 | printk(KERN_ERR "%s: confused, missing data\n", drive->name); | ||
1702 | break; | ||
1703 | } | ||
1704 | |||
1705 | if (blen > thislen) | ||
1706 | blen = thislen; | ||
1707 | |||
1708 | xferfunc(drive, ptr, blen); | ||
1709 | |||
1710 | thislen -= blen; | ||
1711 | len -= blen; | ||
1712 | rq->data_len -= blen; | ||
1713 | |||
1714 | if (rq->bio) | ||
1715 | end_that_request_chunk(rq, 1, blen); | ||
1716 | else | ||
1717 | rq->data += blen; | ||
1718 | } | ||
1719 | |||
1720 | /* | ||
1721 | * pad, if necessary | ||
1722 | */ | ||
1723 | if (len > 0) { | ||
1724 | while (len > 0) { | ||
1725 | int pad = 0; | ||
1726 | |||
1727 | xferfunc(drive, &pad, sizeof(pad)); | ||
1728 | len -= sizeof(pad); | ||
1729 | } | ||
1730 | } | ||
1731 | |||
1732 | if (HWGROUP(drive)->handler != NULL) | ||
1733 | BUG(); | ||
1734 | |||
1735 | ide_set_handler(drive, cdrom_newpc_intr, rq->timeout, NULL); | ||
1736 | return ide_started; | ||
1737 | |||
1738 | end_request: | ||
1739 | if (!rq->data_len) | ||
1740 | post_transform_command(rq); | ||
1741 | |||
1742 | spin_lock_irqsave(&ide_lock, flags); | ||
1743 | blkdev_dequeue_request(rq); | ||
1744 | end_that_request_last(rq); | ||
1745 | HWGROUP(drive)->rq = NULL; | ||
1746 | spin_unlock_irqrestore(&ide_lock, flags); | ||
1747 | return ide_stopped; | ||
1748 | } | ||
1749 | |||
1750 | static ide_startstop_t cdrom_write_intr(ide_drive_t *drive) | ||
1751 | { | ||
1752 | int stat, ireason, len, sectors_to_transfer, uptodate; | ||
1753 | struct cdrom_info *info = drive->driver_data; | ||
1754 | int dma_error = 0, dma = info->dma; | ||
1755 | u8 lowcyl = 0, highcyl = 0; | ||
1756 | |||
1757 | struct request *rq = HWGROUP(drive)->rq; | ||
1758 | |||
1759 | /* Check for errors. */ | ||
1760 | if (dma) { | ||
1761 | info->dma = 0; | ||
1762 | if ((dma_error = HWIF(drive)->ide_dma_end(drive))) { | ||
1763 | printk(KERN_ERR "ide-cd: write dma error\n"); | ||
1764 | __ide_dma_off(drive); | ||
1765 | } | ||
1766 | } | ||
1767 | |||
1768 | if (cdrom_decode_status(drive, 0, &stat)) | ||
1769 | return ide_stopped; | ||
1770 | |||
1771 | /* | ||
1772 | * using dma, transfer is complete now | ||
1773 | */ | ||
1774 | if (dma) { | ||
1775 | if (dma_error) | ||
1776 | return ide_error(drive, "dma error", stat); | ||
1777 | |||
1778 | ide_end_request(drive, 1, rq->nr_sectors); | ||
1779 | return ide_stopped; | ||
1780 | } | ||
1781 | |||
1782 | /* Read the interrupt reason and the transfer length. */ | ||
1783 | ireason = HWIF(drive)->INB(IDE_IREASON_REG); | ||
1784 | lowcyl = HWIF(drive)->INB(IDE_BCOUNTL_REG); | ||
1785 | highcyl = HWIF(drive)->INB(IDE_BCOUNTH_REG); | ||
1786 | |||
1787 | len = lowcyl + (256 * highcyl); | ||
1788 | |||
1789 | /* If DRQ is clear, the command has completed. */ | ||
1790 | if ((stat & DRQ_STAT) == 0) { | ||
1791 | /* If we're not done writing, complain. | ||
1792 | * Otherwise, complete the command normally. | ||
1793 | */ | ||
1794 | uptodate = 1; | ||
1795 | if (rq->current_nr_sectors > 0) { | ||
1796 | printk(KERN_ERR "%s: write_intr: data underrun (%d blocks)\n", | ||
1797 | drive->name, rq->current_nr_sectors); | ||
1798 | uptodate = 0; | ||
1799 | } | ||
1800 | cdrom_end_request(drive, uptodate); | ||
1801 | return ide_stopped; | ||
1802 | } | ||
1803 | |||
1804 | /* Check that the drive is expecting to do the same thing we are. */ | ||
1805 | if (cdrom_write_check_ireason(drive, len, ireason)) | ||
1806 | return ide_stopped; | ||
1807 | |||
1808 | sectors_to_transfer = len / SECTOR_SIZE; | ||
1809 | |||
1810 | /* | ||
1811 | * now loop and write out the data | ||
1812 | */ | ||
1813 | while (sectors_to_transfer > 0) { | ||
1814 | int this_transfer; | ||
1815 | |||
1816 | if (!rq->current_nr_sectors) { | ||
1817 | printk(KERN_ERR "ide-cd: write_intr: oops\n"); | ||
1818 | break; | ||
1819 | } | ||
1820 | |||
1821 | /* | ||
1822 | * Figure out how many sectors we can transfer | ||
1823 | */ | ||
1824 | this_transfer = min_t(int, sectors_to_transfer, rq->current_nr_sectors); | ||
1825 | |||
1826 | while (this_transfer > 0) { | ||
1827 | HWIF(drive)->atapi_output_bytes(drive, rq->buffer, SECTOR_SIZE); | ||
1828 | rq->buffer += SECTOR_SIZE; | ||
1829 | --rq->nr_sectors; | ||
1830 | --rq->current_nr_sectors; | ||
1831 | ++rq->sector; | ||
1832 | --this_transfer; | ||
1833 | --sectors_to_transfer; | ||
1834 | } | ||
1835 | |||
1836 | /* | ||
1837 | * current buffer complete, move on | ||
1838 | */ | ||
1839 | if (rq->current_nr_sectors == 0 && rq->nr_sectors) | ||
1840 | cdrom_end_request(drive, 1); | ||
1841 | } | ||
1842 | |||
1843 | /* re-arm handler */ | ||
1844 | ide_set_handler(drive, &cdrom_write_intr, ATAPI_WAIT_PC, NULL); | ||
1845 | return ide_started; | ||
1846 | } | ||
1847 | |||
1848 | static ide_startstop_t cdrom_start_write_cont(ide_drive_t *drive) | ||
1849 | { | ||
1850 | struct request *rq = HWGROUP(drive)->rq; | ||
1851 | |||
1852 | #if 0 /* the immediate bit */ | ||
1853 | rq->cmd[1] = 1 << 3; | ||
1854 | #endif | ||
1855 | rq->timeout = ATAPI_WAIT_PC; | ||
1856 | |||
1857 | return cdrom_transfer_packet_command(drive, rq, cdrom_write_intr); | ||
1858 | } | ||
1859 | |||
1860 | static ide_startstop_t cdrom_start_write(ide_drive_t *drive, struct request *rq) | ||
1861 | { | ||
1862 | struct cdrom_info *info = drive->driver_data; | ||
1863 | struct gendisk *g = info->disk; | ||
1864 | unsigned short sectors_per_frame = queue_hardsect_size(drive->queue) >> SECTOR_BITS; | ||
1865 | |||
1866 | /* | ||
1867 | * writes *must* be hardware frame aligned | ||
1868 | */ | ||
1869 | if ((rq->nr_sectors & (sectors_per_frame - 1)) || | ||
1870 | (rq->sector & (sectors_per_frame - 1))) { | ||
1871 | cdrom_end_request(drive, 0); | ||
1872 | return ide_stopped; | ||
1873 | } | ||
1874 | |||
1875 | /* | ||
1876 | * disk has become write protected | ||
1877 | */ | ||
1878 | if (g->policy) { | ||
1879 | cdrom_end_request(drive, 0); | ||
1880 | return ide_stopped; | ||
1881 | } | ||
1882 | |||
1883 | /* | ||
1884 | * for dvd-ram and such media, it's a really big deal to get | ||
1885 | * big writes all the time. so scour the queue and attempt to | ||
1886 | * remerge requests, often the plugging will not have had time | ||
1887 | * to do this properly | ||
1888 | */ | ||
1889 | blk_attempt_remerge(drive->queue, rq); | ||
1890 | |||
1891 | info->nsectors_buffered = 0; | ||
1892 | |||
1893 | /* use dma, if possible. we don't need to check more, since we | ||
1894 | * know that the transfer is always (at least!) frame aligned */ | ||
1895 | info->dma = drive->using_dma ? 1 : 0; | ||
1896 | info->cmd = WRITE; | ||
1897 | |||
1898 | info->devinfo.media_written = 1; | ||
1899 | |||
1900 | /* Start sending the write request to the drive. */ | ||
1901 | return cdrom_start_packet_command(drive, 32768, cdrom_start_write_cont); | ||
1902 | } | ||
1903 | |||
1904 | static ide_startstop_t cdrom_do_newpc_cont(ide_drive_t *drive) | ||
1905 | { | ||
1906 | struct request *rq = HWGROUP(drive)->rq; | ||
1907 | |||
1908 | if (!rq->timeout) | ||
1909 | rq->timeout = ATAPI_WAIT_PC; | ||
1910 | |||
1911 | return cdrom_transfer_packet_command(drive, rq, cdrom_newpc_intr); | ||
1912 | } | ||
1913 | |||
1914 | static ide_startstop_t cdrom_do_block_pc(ide_drive_t *drive, struct request *rq) | ||
1915 | { | ||
1916 | struct cdrom_info *info = drive->driver_data; | ||
1917 | |||
1918 | rq->flags |= REQ_QUIET; | ||
1919 | |||
1920 | info->dma = 0; | ||
1921 | info->cmd = 0; | ||
1922 | |||
1923 | /* | ||
1924 | * sg request | ||
1925 | */ | ||
1926 | if (rq->bio) { | ||
1927 | int mask = drive->queue->dma_alignment; | ||
1928 | unsigned long addr = (unsigned long) page_address(bio_page(rq->bio)); | ||
1929 | |||
1930 | info->cmd = rq_data_dir(rq); | ||
1931 | info->dma = drive->using_dma; | ||
1932 | |||
1933 | /* | ||
1934 | * check if dma is safe | ||
1935 | */ | ||
1936 | if ((rq->data_len & mask) || (addr & mask)) | ||
1937 | info->dma = 0; | ||
1938 | } | ||
1939 | |||
1940 | /* Start sending the command to the drive. */ | ||
1941 | return cdrom_start_packet_command(drive, rq->data_len, cdrom_do_newpc_cont); | ||
1942 | } | ||
1943 | |||
1944 | /**************************************************************************** | ||
1945 | * cdrom driver request routine. | ||
1946 | */ | ||
1947 | static ide_startstop_t | ||
1948 | ide_do_rw_cdrom (ide_drive_t *drive, struct request *rq, sector_t block) | ||
1949 | { | ||
1950 | ide_startstop_t action; | ||
1951 | struct cdrom_info *info = drive->driver_data; | ||
1952 | |||
1953 | if (blk_fs_request(rq)) { | ||
1954 | if (CDROM_CONFIG_FLAGS(drive)->seeking) { | ||
1955 | unsigned long elapsed = jiffies - info->start_seek; | ||
1956 | int stat = HWIF(drive)->INB(IDE_STATUS_REG); | ||
1957 | |||
1958 | if ((stat & SEEK_STAT) != SEEK_STAT) { | ||
1959 | if (elapsed < IDECD_SEEK_TIMEOUT) { | ||
1960 | ide_stall_queue(drive, IDECD_SEEK_TIMER); | ||
1961 | return ide_stopped; | ||
1962 | } | ||
1963 | printk (KERN_ERR "%s: DSC timeout\n", drive->name); | ||
1964 | } | ||
1965 | CDROM_CONFIG_FLAGS(drive)->seeking = 0; | ||
1966 | } | ||
1967 | if ((rq_data_dir(rq) == READ) && IDE_LARGE_SEEK(info->last_block, block, IDECD_SEEK_THRESHOLD) && drive->dsc_overlap) { | ||
1968 | action = cdrom_start_seek(drive, block); | ||
1969 | } else { | ||
1970 | if (rq_data_dir(rq) == READ) | ||
1971 | action = cdrom_start_read(drive, block); | ||
1972 | else | ||
1973 | action = cdrom_start_write(drive, rq); | ||
1974 | } | ||
1975 | info->last_block = block; | ||
1976 | return action; | ||
1977 | } else if (rq->flags & (REQ_PC | REQ_SENSE)) { | ||
1978 | return cdrom_do_packet_command(drive); | ||
1979 | } else if (rq->flags & REQ_BLOCK_PC) { | ||
1980 | return cdrom_do_block_pc(drive, rq); | ||
1981 | } else if (rq->flags & REQ_SPECIAL) { | ||
1982 | /* | ||
1983 | * right now this can only be a reset... | ||
1984 | */ | ||
1985 | cdrom_end_request(drive, 1); | ||
1986 | return ide_stopped; | ||
1987 | } | ||
1988 | |||
1989 | blk_dump_rq_flags(rq, "ide-cd bad flags"); | ||
1990 | cdrom_end_request(drive, 0); | ||
1991 | return ide_stopped; | ||
1992 | } | ||
1993 | |||
1994 | |||
1995 | |||
1996 | /**************************************************************************** | ||
1997 | * Ioctl handling. | ||
1998 | * | ||
1999 | * Routines which queue packet commands take as a final argument a pointer | ||
2000 | * to a request_sense struct. If execution of the command results | ||
2001 | * in an error with a CHECK CONDITION status, this structure will be filled | ||
2002 | * with the results of the subsequent request sense command. The pointer | ||
2003 | * can also be NULL, in which case no sense information is returned. | ||
2004 | */ | ||
2005 | |||
2006 | #if ! STANDARD_ATAPI | ||
2007 | static inline | ||
2008 | int bin2bcd (int x) | ||
2009 | { | ||
2010 | return (x%10) | ((x/10) << 4); | ||
2011 | } | ||
2012 | |||
2013 | |||
2014 | static inline | ||
2015 | int bcd2bin (int x) | ||
2016 | { | ||
2017 | return (x >> 4) * 10 + (x & 0x0f); | ||
2018 | } | ||
2019 | |||
2020 | static | ||
2021 | void msf_from_bcd (struct atapi_msf *msf) | ||
2022 | { | ||
2023 | msf->minute = bcd2bin (msf->minute); | ||
2024 | msf->second = bcd2bin (msf->second); | ||
2025 | msf->frame = bcd2bin (msf->frame); | ||
2026 | } | ||
2027 | |||
2028 | #endif /* not STANDARD_ATAPI */ | ||
2029 | |||
2030 | |||
2031 | static inline | ||
2032 | void lba_to_msf (int lba, byte *m, byte *s, byte *f) | ||
2033 | { | ||
2034 | lba += CD_MSF_OFFSET; | ||
2035 | lba &= 0xffffff; /* negative lbas use only 24 bits */ | ||
2036 | *m = lba / (CD_SECS * CD_FRAMES); | ||
2037 | lba %= (CD_SECS * CD_FRAMES); | ||
2038 | *s = lba / CD_FRAMES; | ||
2039 | *f = lba % CD_FRAMES; | ||
2040 | } | ||
2041 | |||
2042 | |||
2043 | static inline | ||
2044 | int msf_to_lba (byte m, byte s, byte f) | ||
2045 | { | ||
2046 | return (((m * CD_SECS) + s) * CD_FRAMES + f) - CD_MSF_OFFSET; | ||
2047 | } | ||
2048 | |||
2049 | static int cdrom_check_status(ide_drive_t *drive, struct request_sense *sense) | ||
2050 | { | ||
2051 | struct request req; | ||
2052 | struct cdrom_info *info = drive->driver_data; | ||
2053 | struct cdrom_device_info *cdi = &info->devinfo; | ||
2054 | |||
2055 | cdrom_prepare_request(drive, &req); | ||
2056 | |||
2057 | req.sense = sense; | ||
2058 | req.cmd[0] = GPCMD_TEST_UNIT_READY; | ||
2059 | req.flags |= REQ_QUIET; | ||
2060 | |||
2061 | #if ! STANDARD_ATAPI | ||
2062 | /* the Sanyo 3 CD changer uses byte 7 of TEST_UNIT_READY to | ||
2063 | switch CDs instead of supporting the LOAD_UNLOAD opcode */ | ||
2064 | |||
2065 | req.cmd[7] = cdi->sanyo_slot % 3; | ||
2066 | #endif /* not STANDARD_ATAPI */ | ||
2067 | |||
2068 | return cdrom_queue_packet_command(drive, &req); | ||
2069 | } | ||
2070 | |||
2071 | |||
2072 | /* Lock the door if LOCKFLAG is nonzero; unlock it otherwise. */ | ||
2073 | static int | ||
2074 | cdrom_lockdoor(ide_drive_t *drive, int lockflag, struct request_sense *sense) | ||
2075 | { | ||
2076 | struct request_sense my_sense; | ||
2077 | struct request req; | ||
2078 | int stat; | ||
2079 | |||
2080 | if (sense == NULL) | ||
2081 | sense = &my_sense; | ||
2082 | |||
2083 | /* If the drive cannot lock the door, just pretend. */ | ||
2084 | if (CDROM_CONFIG_FLAGS(drive)->no_doorlock) { | ||
2085 | stat = 0; | ||
2086 | } else { | ||
2087 | cdrom_prepare_request(drive, &req); | ||
2088 | req.sense = sense; | ||
2089 | req.cmd[0] = GPCMD_PREVENT_ALLOW_MEDIUM_REMOVAL; | ||
2090 | req.cmd[4] = lockflag ? 1 : 0; | ||
2091 | stat = cdrom_queue_packet_command(drive, &req); | ||
2092 | } | ||
2093 | |||
2094 | /* If we got an illegal field error, the drive | ||
2095 | probably cannot lock the door. */ | ||
2096 | if (stat != 0 && | ||
2097 | sense->sense_key == ILLEGAL_REQUEST && | ||
2098 | (sense->asc == 0x24 || sense->asc == 0x20)) { | ||
2099 | printk (KERN_ERR "%s: door locking not supported\n", | ||
2100 | drive->name); | ||
2101 | CDROM_CONFIG_FLAGS(drive)->no_doorlock = 1; | ||
2102 | stat = 0; | ||
2103 | } | ||
2104 | |||
2105 | /* no medium, that's alright. */ | ||
2106 | if (stat != 0 && sense->sense_key == NOT_READY && sense->asc == 0x3a) | ||
2107 | stat = 0; | ||
2108 | |||
2109 | if (stat == 0) | ||
2110 | CDROM_STATE_FLAGS(drive)->door_locked = lockflag; | ||
2111 | |||
2112 | return stat; | ||
2113 | } | ||
2114 | |||
2115 | |||
2116 | /* Eject the disk if EJECTFLAG is 0. | ||
2117 | If EJECTFLAG is 1, try to reload the disk. */ | ||
2118 | static int cdrom_eject(ide_drive_t *drive, int ejectflag, | ||
2119 | struct request_sense *sense) | ||
2120 | { | ||
2121 | struct request req; | ||
2122 | char loej = 0x02; | ||
2123 | |||
2124 | if (CDROM_CONFIG_FLAGS(drive)->no_eject && !ejectflag) | ||
2125 | return -EDRIVE_CANT_DO_THIS; | ||
2126 | |||
2127 | /* reload fails on some drives, if the tray is locked */ | ||
2128 | if (CDROM_STATE_FLAGS(drive)->door_locked && ejectflag) | ||
2129 | return 0; | ||
2130 | |||
2131 | cdrom_prepare_request(drive, &req); | ||
2132 | |||
2133 | /* only tell drive to close tray if open, if it can do that */ | ||
2134 | if (ejectflag && !CDROM_CONFIG_FLAGS(drive)->close_tray) | ||
2135 | loej = 0; | ||
2136 | |||
2137 | req.sense = sense; | ||
2138 | req.cmd[0] = GPCMD_START_STOP_UNIT; | ||
2139 | req.cmd[4] = loej | (ejectflag != 0); | ||
2140 | return cdrom_queue_packet_command(drive, &req); | ||
2141 | } | ||
2142 | |||
2143 | static int cdrom_read_capacity(ide_drive_t *drive, unsigned long *capacity, | ||
2144 | unsigned long *sectors_per_frame, | ||
2145 | struct request_sense *sense) | ||
2146 | { | ||
2147 | struct { | ||
2148 | __u32 lba; | ||
2149 | __u32 blocklen; | ||
2150 | } capbuf; | ||
2151 | |||
2152 | int stat; | ||
2153 | struct request req; | ||
2154 | |||
2155 | cdrom_prepare_request(drive, &req); | ||
2156 | |||
2157 | req.sense = sense; | ||
2158 | req.cmd[0] = GPCMD_READ_CDVD_CAPACITY; | ||
2159 | req.data = (char *)&capbuf; | ||
2160 | req.data_len = sizeof(capbuf); | ||
2161 | |||
2162 | stat = cdrom_queue_packet_command(drive, &req); | ||
2163 | if (stat == 0) { | ||
2164 | *capacity = 1 + be32_to_cpu(capbuf.lba); | ||
2165 | *sectors_per_frame = | ||
2166 | be32_to_cpu(capbuf.blocklen) >> SECTOR_BITS; | ||
2167 | } | ||
2168 | |||
2169 | return stat; | ||
2170 | } | ||
2171 | |||
2172 | static int cdrom_read_tocentry(ide_drive_t *drive, int trackno, int msf_flag, | ||
2173 | int format, char *buf, int buflen, | ||
2174 | struct request_sense *sense) | ||
2175 | { | ||
2176 | struct request req; | ||
2177 | |||
2178 | cdrom_prepare_request(drive, &req); | ||
2179 | |||
2180 | req.sense = sense; | ||
2181 | req.data = buf; | ||
2182 | req.data_len = buflen; | ||
2183 | req.flags |= REQ_QUIET; | ||
2184 | req.cmd[0] = GPCMD_READ_TOC_PMA_ATIP; | ||
2185 | req.cmd[6] = trackno; | ||
2186 | req.cmd[7] = (buflen >> 8); | ||
2187 | req.cmd[8] = (buflen & 0xff); | ||
2188 | req.cmd[9] = (format << 6); | ||
2189 | |||
2190 | if (msf_flag) | ||
2191 | req.cmd[1] = 2; | ||
2192 | |||
2193 | return cdrom_queue_packet_command(drive, &req); | ||
2194 | } | ||
2195 | |||
2196 | |||
2197 | /* Try to read the entire TOC for the disk into our internal buffer. */ | ||
2198 | static int cdrom_read_toc(ide_drive_t *drive, struct request_sense *sense) | ||
2199 | { | ||
2200 | int stat, ntracks, i; | ||
2201 | struct cdrom_info *info = drive->driver_data; | ||
2202 | struct cdrom_device_info *cdi = &info->devinfo; | ||
2203 | struct atapi_toc *toc = info->toc; | ||
2204 | struct { | ||
2205 | struct atapi_toc_header hdr; | ||
2206 | struct atapi_toc_entry ent; | ||
2207 | } ms_tmp; | ||
2208 | long last_written; | ||
2209 | unsigned long sectors_per_frame = SECTORS_PER_FRAME; | ||
2210 | |||
2211 | if (toc == NULL) { | ||
2212 | /* Try to allocate space. */ | ||
2213 | toc = (struct atapi_toc *) kmalloc (sizeof (struct atapi_toc), | ||
2214 | GFP_KERNEL); | ||
2215 | info->toc = toc; | ||
2216 | if (toc == NULL) { | ||
2217 | printk (KERN_ERR "%s: No cdrom TOC buffer!\n", drive->name); | ||
2218 | return -ENOMEM; | ||
2219 | } | ||
2220 | } | ||
2221 | |||
2222 | /* Check to see if the existing data is still valid. | ||
2223 | If it is, just return. */ | ||
2224 | (void) cdrom_check_status(drive, sense); | ||
2225 | |||
2226 | if (CDROM_STATE_FLAGS(drive)->toc_valid) | ||
2227 | return 0; | ||
2228 | |||
2229 | /* Try to get the total cdrom capacity and sector size. */ | ||
2230 | stat = cdrom_read_capacity(drive, &toc->capacity, §ors_per_frame, | ||
2231 | sense); | ||
2232 | if (stat) | ||
2233 | toc->capacity = 0x1fffff; | ||
2234 | |||
2235 | set_capacity(info->disk, toc->capacity * sectors_per_frame); | ||
2236 | blk_queue_hardsect_size(drive->queue, | ||
2237 | sectors_per_frame << SECTOR_BITS); | ||
2238 | |||
2239 | /* First read just the header, so we know how long the TOC is. */ | ||
2240 | stat = cdrom_read_tocentry(drive, 0, 1, 0, (char *) &toc->hdr, | ||
2241 | sizeof(struct atapi_toc_header), sense); | ||
2242 | if (stat) return stat; | ||
2243 | |||
2244 | #if ! STANDARD_ATAPI | ||
2245 | if (CDROM_CONFIG_FLAGS(drive)->toctracks_as_bcd) { | ||
2246 | toc->hdr.first_track = bcd2bin(toc->hdr.first_track); | ||
2247 | toc->hdr.last_track = bcd2bin(toc->hdr.last_track); | ||
2248 | } | ||
2249 | #endif /* not STANDARD_ATAPI */ | ||
2250 | |||
2251 | ntracks = toc->hdr.last_track - toc->hdr.first_track + 1; | ||
2252 | if (ntracks <= 0) | ||
2253 | return -EIO; | ||
2254 | if (ntracks > MAX_TRACKS) | ||
2255 | ntracks = MAX_TRACKS; | ||
2256 | |||
2257 | /* Now read the whole schmeer. */ | ||
2258 | stat = cdrom_read_tocentry(drive, toc->hdr.first_track, 1, 0, | ||
2259 | (char *)&toc->hdr, | ||
2260 | sizeof(struct atapi_toc_header) + | ||
2261 | (ntracks + 1) * | ||
2262 | sizeof(struct atapi_toc_entry), sense); | ||
2263 | |||
2264 | if (stat && toc->hdr.first_track > 1) { | ||
2265 | /* Cds with CDI tracks only don't have any TOC entries, | ||
2266 | despite of this the returned values are | ||
2267 | first_track == last_track = number of CDI tracks + 1, | ||
2268 | so that this case is indistinguishable from the same | ||
2269 | layout plus an additional audio track. | ||
2270 | If we get an error for the regular case, we assume | ||
2271 | a CDI without additional audio tracks. In this case | ||
2272 | the readable TOC is empty (CDI tracks are not included) | ||
2273 | and only holds the Leadout entry. Heiko Eißfeldt */ | ||
2274 | ntracks = 0; | ||
2275 | stat = cdrom_read_tocentry(drive, CDROM_LEADOUT, 1, 0, | ||
2276 | (char *)&toc->hdr, | ||
2277 | sizeof(struct atapi_toc_header) + | ||
2278 | (ntracks + 1) * | ||
2279 | sizeof(struct atapi_toc_entry), | ||
2280 | sense); | ||
2281 | if (stat) { | ||
2282 | return stat; | ||
2283 | } | ||
2284 | #if ! STANDARD_ATAPI | ||
2285 | if (CDROM_CONFIG_FLAGS(drive)->toctracks_as_bcd) { | ||
2286 | toc->hdr.first_track = bin2bcd(CDROM_LEADOUT); | ||
2287 | toc->hdr.last_track = bin2bcd(CDROM_LEADOUT); | ||
2288 | } else | ||
2289 | #endif /* not STANDARD_ATAPI */ | ||
2290 | { | ||
2291 | toc->hdr.first_track = CDROM_LEADOUT; | ||
2292 | toc->hdr.last_track = CDROM_LEADOUT; | ||
2293 | } | ||
2294 | } | ||
2295 | |||
2296 | if (stat) | ||
2297 | return stat; | ||
2298 | |||
2299 | toc->hdr.toc_length = ntohs (toc->hdr.toc_length); | ||
2300 | |||
2301 | #if ! STANDARD_ATAPI | ||
2302 | if (CDROM_CONFIG_FLAGS(drive)->toctracks_as_bcd) { | ||
2303 | toc->hdr.first_track = bcd2bin(toc->hdr.first_track); | ||
2304 | toc->hdr.last_track = bcd2bin(toc->hdr.last_track); | ||
2305 | } | ||
2306 | #endif /* not STANDARD_ATAPI */ | ||
2307 | |||
2308 | for (i=0; i<=ntracks; i++) { | ||
2309 | #if ! STANDARD_ATAPI | ||
2310 | if (CDROM_CONFIG_FLAGS(drive)->tocaddr_as_bcd) { | ||
2311 | if (CDROM_CONFIG_FLAGS(drive)->toctracks_as_bcd) | ||
2312 | toc->ent[i].track = bcd2bin(toc->ent[i].track); | ||
2313 | msf_from_bcd(&toc->ent[i].addr.msf); | ||
2314 | } | ||
2315 | #endif /* not STANDARD_ATAPI */ | ||
2316 | toc->ent[i].addr.lba = msf_to_lba (toc->ent[i].addr.msf.minute, | ||
2317 | toc->ent[i].addr.msf.second, | ||
2318 | toc->ent[i].addr.msf.frame); | ||
2319 | } | ||
2320 | |||
2321 | /* Read the multisession information. */ | ||
2322 | if (toc->hdr.first_track != CDROM_LEADOUT) { | ||
2323 | /* Read the multisession information. */ | ||
2324 | stat = cdrom_read_tocentry(drive, 0, 0, 1, (char *)&ms_tmp, | ||
2325 | sizeof(ms_tmp), sense); | ||
2326 | if (stat) return stat; | ||
2327 | |||
2328 | toc->last_session_lba = be32_to_cpu(ms_tmp.ent.addr.lba); | ||
2329 | } else { | ||
2330 | ms_tmp.hdr.first_track = ms_tmp.hdr.last_track = CDROM_LEADOUT; | ||
2331 | toc->last_session_lba = msf_to_lba(0, 2, 0); /* 0m 2s 0f */ | ||
2332 | } | ||
2333 | |||
2334 | #if ! STANDARD_ATAPI | ||
2335 | if (CDROM_CONFIG_FLAGS(drive)->tocaddr_as_bcd) { | ||
2336 | /* Re-read multisession information using MSF format */ | ||
2337 | stat = cdrom_read_tocentry(drive, 0, 1, 1, (char *)&ms_tmp, | ||
2338 | sizeof(ms_tmp), sense); | ||
2339 | if (stat) | ||
2340 | return stat; | ||
2341 | |||
2342 | msf_from_bcd (&ms_tmp.ent.addr.msf); | ||
2343 | toc->last_session_lba = msf_to_lba(ms_tmp.ent.addr.msf.minute, | ||
2344 | ms_tmp.ent.addr.msf.second, | ||
2345 | ms_tmp.ent.addr.msf.frame); | ||
2346 | } | ||
2347 | #endif /* not STANDARD_ATAPI */ | ||
2348 | |||
2349 | toc->xa_flag = (ms_tmp.hdr.first_track != ms_tmp.hdr.last_track); | ||
2350 | |||
2351 | /* Now try to get the total cdrom capacity. */ | ||
2352 | stat = cdrom_get_last_written(cdi, &last_written); | ||
2353 | if (!stat && (last_written > toc->capacity)) { | ||
2354 | toc->capacity = last_written; | ||
2355 | set_capacity(info->disk, toc->capacity * sectors_per_frame); | ||
2356 | } | ||
2357 | |||
2358 | /* Remember that we've read this stuff. */ | ||
2359 | CDROM_STATE_FLAGS(drive)->toc_valid = 1; | ||
2360 | |||
2361 | return 0; | ||
2362 | } | ||
2363 | |||
2364 | |||
2365 | static int cdrom_read_subchannel(ide_drive_t *drive, int format, char *buf, | ||
2366 | int buflen, struct request_sense *sense) | ||
2367 | { | ||
2368 | struct request req; | ||
2369 | |||
2370 | cdrom_prepare_request(drive, &req); | ||
2371 | |||
2372 | req.sense = sense; | ||
2373 | req.data = buf; | ||
2374 | req.data_len = buflen; | ||
2375 | req.cmd[0] = GPCMD_READ_SUBCHANNEL; | ||
2376 | req.cmd[1] = 2; /* MSF addressing */ | ||
2377 | req.cmd[2] = 0x40; /* request subQ data */ | ||
2378 | req.cmd[3] = format; | ||
2379 | req.cmd[7] = (buflen >> 8); | ||
2380 | req.cmd[8] = (buflen & 0xff); | ||
2381 | return cdrom_queue_packet_command(drive, &req); | ||
2382 | } | ||
2383 | |||
2384 | /* ATAPI cdrom drives are free to select the speed you request or any slower | ||
2385 | rate :-( Requesting too fast a speed will _not_ produce an error. */ | ||
2386 | static int cdrom_select_speed(ide_drive_t *drive, int speed, | ||
2387 | struct request_sense *sense) | ||
2388 | { | ||
2389 | struct request req; | ||
2390 | cdrom_prepare_request(drive, &req); | ||
2391 | |||
2392 | req.sense = sense; | ||
2393 | if (speed == 0) | ||
2394 | speed = 0xffff; /* set to max */ | ||
2395 | else | ||
2396 | speed *= 177; /* Nx to kbytes/s */ | ||
2397 | |||
2398 | req.cmd[0] = GPCMD_SET_SPEED; | ||
2399 | /* Read Drive speed in kbytes/second MSB */ | ||
2400 | req.cmd[2] = (speed >> 8) & 0xff; | ||
2401 | /* Read Drive speed in kbytes/second LSB */ | ||
2402 | req.cmd[3] = speed & 0xff; | ||
2403 | if (CDROM_CONFIG_FLAGS(drive)->cd_r || | ||
2404 | CDROM_CONFIG_FLAGS(drive)->cd_rw || | ||
2405 | CDROM_CONFIG_FLAGS(drive)->dvd_r) { | ||
2406 | /* Write Drive speed in kbytes/second MSB */ | ||
2407 | req.cmd[4] = (speed >> 8) & 0xff; | ||
2408 | /* Write Drive speed in kbytes/second LSB */ | ||
2409 | req.cmd[5] = speed & 0xff; | ||
2410 | } | ||
2411 | |||
2412 | return cdrom_queue_packet_command(drive, &req); | ||
2413 | } | ||
2414 | |||
2415 | static int cdrom_play_audio(ide_drive_t *drive, int lba_start, int lba_end) | ||
2416 | { | ||
2417 | struct request_sense sense; | ||
2418 | struct request req; | ||
2419 | |||
2420 | cdrom_prepare_request(drive, &req); | ||
2421 | |||
2422 | req.sense = &sense; | ||
2423 | req.cmd[0] = GPCMD_PLAY_AUDIO_MSF; | ||
2424 | lba_to_msf(lba_start, &req.cmd[3], &req.cmd[4], &req.cmd[5]); | ||
2425 | lba_to_msf(lba_end-1, &req.cmd[6], &req.cmd[7], &req.cmd[8]); | ||
2426 | |||
2427 | return cdrom_queue_packet_command(drive, &req); | ||
2428 | } | ||
2429 | |||
2430 | static int cdrom_get_toc_entry(ide_drive_t *drive, int track, | ||
2431 | struct atapi_toc_entry **ent) | ||
2432 | { | ||
2433 | struct cdrom_info *info = drive->driver_data; | ||
2434 | struct atapi_toc *toc = info->toc; | ||
2435 | int ntracks; | ||
2436 | |||
2437 | /* | ||
2438 | * don't serve cached data, if the toc isn't valid | ||
2439 | */ | ||
2440 | if (!CDROM_STATE_FLAGS(drive)->toc_valid) | ||
2441 | return -EINVAL; | ||
2442 | |||
2443 | /* Check validity of requested track number. */ | ||
2444 | ntracks = toc->hdr.last_track - toc->hdr.first_track + 1; | ||
2445 | if (toc->hdr.first_track == CDROM_LEADOUT) ntracks = 0; | ||
2446 | if (track == CDROM_LEADOUT) | ||
2447 | *ent = &toc->ent[ntracks]; | ||
2448 | else if (track < toc->hdr.first_track || | ||
2449 | track > toc->hdr.last_track) | ||
2450 | return -EINVAL; | ||
2451 | else | ||
2452 | *ent = &toc->ent[track - toc->hdr.first_track]; | ||
2453 | |||
2454 | return 0; | ||
2455 | } | ||
2456 | |||
2457 | /* the generic packet interface to cdrom.c */ | ||
2458 | static int ide_cdrom_packet(struct cdrom_device_info *cdi, | ||
2459 | struct packet_command *cgc) | ||
2460 | { | ||
2461 | struct request req; | ||
2462 | ide_drive_t *drive = (ide_drive_t*) cdi->handle; | ||
2463 | |||
2464 | if (cgc->timeout <= 0) | ||
2465 | cgc->timeout = ATAPI_WAIT_PC; | ||
2466 | |||
2467 | /* here we queue the commands from the uniform CD-ROM | ||
2468 | layer. the packet must be complete, as we do not | ||
2469 | touch it at all. */ | ||
2470 | cdrom_prepare_request(drive, &req); | ||
2471 | memcpy(req.cmd, cgc->cmd, CDROM_PACKET_SIZE); | ||
2472 | if (cgc->sense) | ||
2473 | memset(cgc->sense, 0, sizeof(struct request_sense)); | ||
2474 | req.data = cgc->buffer; | ||
2475 | req.data_len = cgc->buflen; | ||
2476 | req.timeout = cgc->timeout; | ||
2477 | |||
2478 | if (cgc->quiet) | ||
2479 | req.flags |= REQ_QUIET; | ||
2480 | |||
2481 | req.sense = cgc->sense; | ||
2482 | cgc->stat = cdrom_queue_packet_command(drive, &req); | ||
2483 | if (!cgc->stat) | ||
2484 | cgc->buflen -= req.data_len; | ||
2485 | return cgc->stat; | ||
2486 | } | ||
2487 | |||
2488 | static | ||
2489 | int ide_cdrom_dev_ioctl (struct cdrom_device_info *cdi, | ||
2490 | unsigned int cmd, unsigned long arg) | ||
2491 | { | ||
2492 | struct packet_command cgc; | ||
2493 | char buffer[16]; | ||
2494 | int stat; | ||
2495 | |||
2496 | init_cdrom_command(&cgc, buffer, sizeof(buffer), CGC_DATA_UNKNOWN); | ||
2497 | |||
2498 | /* These will be moved into the Uniform layer shortly... */ | ||
2499 | switch (cmd) { | ||
2500 | case CDROMSETSPINDOWN: { | ||
2501 | char spindown; | ||
2502 | |||
2503 | if (copy_from_user(&spindown, (void __user *) arg, sizeof(char))) | ||
2504 | return -EFAULT; | ||
2505 | |||
2506 | if ((stat = cdrom_mode_sense(cdi, &cgc, GPMODE_CDROM_PAGE, 0))) | ||
2507 | return stat; | ||
2508 | |||
2509 | buffer[11] = (buffer[11] & 0xf0) | (spindown & 0x0f); | ||
2510 | |||
2511 | return cdrom_mode_select(cdi, &cgc); | ||
2512 | } | ||
2513 | |||
2514 | case CDROMGETSPINDOWN: { | ||
2515 | char spindown; | ||
2516 | |||
2517 | if ((stat = cdrom_mode_sense(cdi, &cgc, GPMODE_CDROM_PAGE, 0))) | ||
2518 | return stat; | ||
2519 | |||
2520 | spindown = buffer[11] & 0x0f; | ||
2521 | |||
2522 | if (copy_to_user((void __user *) arg, &spindown, sizeof (char))) | ||
2523 | return -EFAULT; | ||
2524 | |||
2525 | return 0; | ||
2526 | } | ||
2527 | |||
2528 | default: | ||
2529 | return -EINVAL; | ||
2530 | } | ||
2531 | |||
2532 | } | ||
2533 | |||
2534 | static | ||
2535 | int ide_cdrom_audio_ioctl (struct cdrom_device_info *cdi, | ||
2536 | unsigned int cmd, void *arg) | ||
2537 | |||
2538 | { | ||
2539 | ide_drive_t *drive = (ide_drive_t*) cdi->handle; | ||
2540 | struct cdrom_info *info = drive->driver_data; | ||
2541 | int stat; | ||
2542 | |||
2543 | switch (cmd) { | ||
2544 | /* | ||
2545 | * emulate PLAY_AUDIO_TI command with PLAY_AUDIO_10, since | ||
2546 | * atapi doesn't support it | ||
2547 | */ | ||
2548 | case CDROMPLAYTRKIND: { | ||
2549 | unsigned long lba_start, lba_end; | ||
2550 | struct cdrom_ti *ti = (struct cdrom_ti *)arg; | ||
2551 | struct atapi_toc_entry *first_toc, *last_toc; | ||
2552 | |||
2553 | stat = cdrom_get_toc_entry(drive, ti->cdti_trk0, &first_toc); | ||
2554 | if (stat) | ||
2555 | return stat; | ||
2556 | |||
2557 | stat = cdrom_get_toc_entry(drive, ti->cdti_trk1, &last_toc); | ||
2558 | if (stat) | ||
2559 | return stat; | ||
2560 | |||
2561 | if (ti->cdti_trk1 != CDROM_LEADOUT) | ||
2562 | ++last_toc; | ||
2563 | lba_start = first_toc->addr.lba; | ||
2564 | lba_end = last_toc->addr.lba; | ||
2565 | |||
2566 | if (lba_end <= lba_start) | ||
2567 | return -EINVAL; | ||
2568 | |||
2569 | return cdrom_play_audio(drive, lba_start, lba_end); | ||
2570 | } | ||
2571 | |||
2572 | case CDROMREADTOCHDR: { | ||
2573 | struct cdrom_tochdr *tochdr = (struct cdrom_tochdr *) arg; | ||
2574 | struct atapi_toc *toc; | ||
2575 | |||
2576 | /* Make sure our saved TOC is valid. */ | ||
2577 | stat = cdrom_read_toc(drive, NULL); | ||
2578 | if (stat) return stat; | ||
2579 | |||
2580 | toc = info->toc; | ||
2581 | tochdr->cdth_trk0 = toc->hdr.first_track; | ||
2582 | tochdr->cdth_trk1 = toc->hdr.last_track; | ||
2583 | |||
2584 | return 0; | ||
2585 | } | ||
2586 | |||
2587 | case CDROMREADTOCENTRY: { | ||
2588 | struct cdrom_tocentry *tocentry = (struct cdrom_tocentry*) arg; | ||
2589 | struct atapi_toc_entry *toce; | ||
2590 | |||
2591 | stat = cdrom_get_toc_entry(drive, tocentry->cdte_track, &toce); | ||
2592 | if (stat) return stat; | ||
2593 | |||
2594 | tocentry->cdte_ctrl = toce->control; | ||
2595 | tocentry->cdte_adr = toce->adr; | ||
2596 | if (tocentry->cdte_format == CDROM_MSF) { | ||
2597 | lba_to_msf (toce->addr.lba, | ||
2598 | &tocentry->cdte_addr.msf.minute, | ||
2599 | &tocentry->cdte_addr.msf.second, | ||
2600 | &tocentry->cdte_addr.msf.frame); | ||
2601 | } else | ||
2602 | tocentry->cdte_addr.lba = toce->addr.lba; | ||
2603 | |||
2604 | return 0; | ||
2605 | } | ||
2606 | |||
2607 | default: | ||
2608 | return -EINVAL; | ||
2609 | } | ||
2610 | } | ||
2611 | |||
2612 | static | ||
2613 | int ide_cdrom_reset (struct cdrom_device_info *cdi) | ||
2614 | { | ||
2615 | ide_drive_t *drive = (ide_drive_t*) cdi->handle; | ||
2616 | struct request_sense sense; | ||
2617 | struct request req; | ||
2618 | int ret; | ||
2619 | |||
2620 | cdrom_prepare_request(drive, &req); | ||
2621 | req.flags = REQ_SPECIAL | REQ_QUIET; | ||
2622 | ret = ide_do_drive_cmd(drive, &req, ide_wait); | ||
2623 | |||
2624 | /* | ||
2625 | * A reset will unlock the door. If it was previously locked, | ||
2626 | * lock it again. | ||
2627 | */ | ||
2628 | if (CDROM_STATE_FLAGS(drive)->door_locked) | ||
2629 | (void) cdrom_lockdoor(drive, 1, &sense); | ||
2630 | |||
2631 | return ret; | ||
2632 | } | ||
2633 | |||
2634 | |||
2635 | static | ||
2636 | int ide_cdrom_tray_move (struct cdrom_device_info *cdi, int position) | ||
2637 | { | ||
2638 | ide_drive_t *drive = (ide_drive_t*) cdi->handle; | ||
2639 | struct request_sense sense; | ||
2640 | |||
2641 | if (position) { | ||
2642 | int stat = cdrom_lockdoor(drive, 0, &sense); | ||
2643 | if (stat) return stat; | ||
2644 | } | ||
2645 | |||
2646 | return cdrom_eject(drive, !position, &sense); | ||
2647 | } | ||
2648 | |||
2649 | static | ||
2650 | int ide_cdrom_lock_door (struct cdrom_device_info *cdi, int lock) | ||
2651 | { | ||
2652 | ide_drive_t *drive = (ide_drive_t*) cdi->handle; | ||
2653 | return cdrom_lockdoor(drive, lock, NULL); | ||
2654 | } | ||
2655 | |||
2656 | static | ||
2657 | int ide_cdrom_select_speed (struct cdrom_device_info *cdi, int speed) | ||
2658 | { | ||
2659 | ide_drive_t *drive = (ide_drive_t*) cdi->handle; | ||
2660 | struct request_sense sense; | ||
2661 | int stat; | ||
2662 | |||
2663 | if ((stat = cdrom_select_speed(drive, speed, &sense)) < 0) | ||
2664 | return stat; | ||
2665 | |||
2666 | cdi->speed = CDROM_STATE_FLAGS(drive)->current_speed; | ||
2667 | return 0; | ||
2668 | } | ||
2669 | |||
2670 | /* | ||
2671 | * add logic to try GET_EVENT command first to check for media and tray | ||
2672 | * status. this should be supported by newer cd-r/w and all DVD etc | ||
2673 | * drives | ||
2674 | */ | ||
2675 | static | ||
2676 | int ide_cdrom_drive_status (struct cdrom_device_info *cdi, int slot_nr) | ||
2677 | { | ||
2678 | ide_drive_t *drive = (ide_drive_t*) cdi->handle; | ||
2679 | struct media_event_desc med; | ||
2680 | struct request_sense sense; | ||
2681 | int stat; | ||
2682 | |||
2683 | if (slot_nr != CDSL_CURRENT) | ||
2684 | return -EINVAL; | ||
2685 | |||
2686 | stat = cdrom_check_status(drive, &sense); | ||
2687 | if (!stat || sense.sense_key == UNIT_ATTENTION) | ||
2688 | return CDS_DISC_OK; | ||
2689 | |||
2690 | if (!cdrom_get_media_event(cdi, &med)) { | ||
2691 | if (med.media_present) | ||
2692 | return CDS_DISC_OK; | ||
2693 | else if (med.door_open) | ||
2694 | return CDS_TRAY_OPEN; | ||
2695 | else | ||
2696 | return CDS_NO_DISC; | ||
2697 | } | ||
2698 | |||
2699 | if (sense.sense_key == NOT_READY && sense.asc == 0x04 && sense.ascq == 0x04) | ||
2700 | return CDS_DISC_OK; | ||
2701 | |||
2702 | /* | ||
2703 | * If not using Mt Fuji extended media tray reports, | ||
2704 | * just return TRAY_OPEN since ATAPI doesn't provide | ||
2705 | * any other way to detect this... | ||
2706 | */ | ||
2707 | if (sense.sense_key == NOT_READY) { | ||
2708 | if (sense.asc == 0x3a) { | ||
2709 | if (sense.ascq == 1) | ||
2710 | return CDS_NO_DISC; | ||
2711 | else if (sense.ascq == 0 || sense.ascq == 2) | ||
2712 | return CDS_TRAY_OPEN; | ||
2713 | } | ||
2714 | } | ||
2715 | |||
2716 | return CDS_DRIVE_NOT_READY; | ||
2717 | } | ||
2718 | |||
2719 | static | ||
2720 | int ide_cdrom_get_last_session (struct cdrom_device_info *cdi, | ||
2721 | struct cdrom_multisession *ms_info) | ||
2722 | { | ||
2723 | struct atapi_toc *toc; | ||
2724 | ide_drive_t *drive = (ide_drive_t*) cdi->handle; | ||
2725 | struct cdrom_info *info = drive->driver_data; | ||
2726 | struct request_sense sense; | ||
2727 | int ret; | ||
2728 | |||
2729 | if (!CDROM_STATE_FLAGS(drive)->toc_valid || info->toc == NULL) | ||
2730 | if ((ret = cdrom_read_toc(drive, &sense))) | ||
2731 | return ret; | ||
2732 | |||
2733 | toc = info->toc; | ||
2734 | ms_info->addr.lba = toc->last_session_lba; | ||
2735 | ms_info->xa_flag = toc->xa_flag; | ||
2736 | |||
2737 | return 0; | ||
2738 | } | ||
2739 | |||
2740 | static | ||
2741 | int ide_cdrom_get_mcn (struct cdrom_device_info *cdi, | ||
2742 | struct cdrom_mcn *mcn_info) | ||
2743 | { | ||
2744 | int stat; | ||
2745 | char mcnbuf[24]; | ||
2746 | ide_drive_t *drive = (ide_drive_t*) cdi->handle; | ||
2747 | |||
2748 | /* get MCN */ | ||
2749 | if ((stat = cdrom_read_subchannel(drive, 2, mcnbuf, sizeof (mcnbuf), NULL))) | ||
2750 | return stat; | ||
2751 | |||
2752 | memcpy (mcn_info->medium_catalog_number, mcnbuf+9, | ||
2753 | sizeof (mcn_info->medium_catalog_number)-1); | ||
2754 | mcn_info->medium_catalog_number[sizeof (mcn_info->medium_catalog_number)-1] | ||
2755 | = '\0'; | ||
2756 | |||
2757 | return 0; | ||
2758 | } | ||
2759 | |||
2760 | |||
2761 | |||
2762 | /**************************************************************************** | ||
2763 | * Other driver requests (open, close, check media change). | ||
2764 | */ | ||
2765 | |||
2766 | static | ||
2767 | int ide_cdrom_check_media_change_real (struct cdrom_device_info *cdi, | ||
2768 | int slot_nr) | ||
2769 | { | ||
2770 | ide_drive_t *drive = (ide_drive_t*) cdi->handle; | ||
2771 | int retval; | ||
2772 | |||
2773 | if (slot_nr == CDSL_CURRENT) { | ||
2774 | (void) cdrom_check_status(drive, NULL); | ||
2775 | retval = CDROM_STATE_FLAGS(drive)->media_changed; | ||
2776 | CDROM_STATE_FLAGS(drive)->media_changed = 0; | ||
2777 | return retval; | ||
2778 | } else { | ||
2779 | return -EINVAL; | ||
2780 | } | ||
2781 | } | ||
2782 | |||
2783 | |||
2784 | static | ||
2785 | int ide_cdrom_open_real (struct cdrom_device_info *cdi, int purpose) | ||
2786 | { | ||
2787 | return 0; | ||
2788 | } | ||
2789 | |||
2790 | /* | ||
2791 | * Close down the device. Invalidate all cached blocks. | ||
2792 | */ | ||
2793 | |||
2794 | static | ||
2795 | void ide_cdrom_release_real (struct cdrom_device_info *cdi) | ||
2796 | { | ||
2797 | ide_drive_t *drive = cdi->handle; | ||
2798 | |||
2799 | if (!cdi->use_count) | ||
2800 | CDROM_STATE_FLAGS(drive)->toc_valid = 0; | ||
2801 | } | ||
2802 | |||
2803 | |||
2804 | |||
2805 | /**************************************************************************** | ||
2806 | * Device initialization. | ||
2807 | */ | ||
2808 | static struct cdrom_device_ops ide_cdrom_dops = { | ||
2809 | .open = ide_cdrom_open_real, | ||
2810 | .release = ide_cdrom_release_real, | ||
2811 | .drive_status = ide_cdrom_drive_status, | ||
2812 | .media_changed = ide_cdrom_check_media_change_real, | ||
2813 | .tray_move = ide_cdrom_tray_move, | ||
2814 | .lock_door = ide_cdrom_lock_door, | ||
2815 | .select_speed = ide_cdrom_select_speed, | ||
2816 | .get_last_session = ide_cdrom_get_last_session, | ||
2817 | .get_mcn = ide_cdrom_get_mcn, | ||
2818 | .reset = ide_cdrom_reset, | ||
2819 | .audio_ioctl = ide_cdrom_audio_ioctl, | ||
2820 | .dev_ioctl = ide_cdrom_dev_ioctl, | ||
2821 | .capability = CDC_CLOSE_TRAY | CDC_OPEN_TRAY | CDC_LOCK | | ||
2822 | CDC_SELECT_SPEED | CDC_SELECT_DISC | | ||
2823 | CDC_MULTI_SESSION | CDC_MCN | | ||
2824 | CDC_MEDIA_CHANGED | CDC_PLAY_AUDIO | CDC_RESET | | ||
2825 | CDC_IOCTLS | CDC_DRIVE_STATUS | CDC_CD_R | | ||
2826 | CDC_CD_RW | CDC_DVD | CDC_DVD_R| CDC_DVD_RAM | | ||
2827 | CDC_GENERIC_PACKET | CDC_MO_DRIVE | CDC_MRW | | ||
2828 | CDC_MRW_W | CDC_RAM, | ||
2829 | .generic_packet = ide_cdrom_packet, | ||
2830 | }; | ||
2831 | |||
2832 | static int ide_cdrom_register (ide_drive_t *drive, int nslots) | ||
2833 | { | ||
2834 | struct cdrom_info *info = drive->driver_data; | ||
2835 | struct cdrom_device_info *devinfo = &info->devinfo; | ||
2836 | |||
2837 | devinfo->ops = &ide_cdrom_dops; | ||
2838 | devinfo->mask = 0; | ||
2839 | devinfo->speed = CDROM_STATE_FLAGS(drive)->current_speed; | ||
2840 | devinfo->capacity = nslots; | ||
2841 | devinfo->handle = (void *) drive; | ||
2842 | strcpy(devinfo->name, drive->name); | ||
2843 | |||
2844 | /* set capability mask to match the probe. */ | ||
2845 | if (!CDROM_CONFIG_FLAGS(drive)->cd_r) | ||
2846 | devinfo->mask |= CDC_CD_R; | ||
2847 | if (!CDROM_CONFIG_FLAGS(drive)->cd_rw) | ||
2848 | devinfo->mask |= CDC_CD_RW; | ||
2849 | if (!CDROM_CONFIG_FLAGS(drive)->dvd) | ||
2850 | devinfo->mask |= CDC_DVD; | ||
2851 | if (!CDROM_CONFIG_FLAGS(drive)->dvd_r) | ||
2852 | devinfo->mask |= CDC_DVD_R; | ||
2853 | if (!CDROM_CONFIG_FLAGS(drive)->dvd_ram) | ||
2854 | devinfo->mask |= CDC_DVD_RAM; | ||
2855 | if (!CDROM_CONFIG_FLAGS(drive)->is_changer) | ||
2856 | devinfo->mask |= CDC_SELECT_DISC; | ||
2857 | if (!CDROM_CONFIG_FLAGS(drive)->audio_play) | ||
2858 | devinfo->mask |= CDC_PLAY_AUDIO; | ||
2859 | if (!CDROM_CONFIG_FLAGS(drive)->close_tray) | ||
2860 | devinfo->mask |= CDC_CLOSE_TRAY; | ||
2861 | if (!CDROM_CONFIG_FLAGS(drive)->mo_drive) | ||
2862 | devinfo->mask |= CDC_MO_DRIVE; | ||
2863 | |||
2864 | devinfo->disk = info->disk; | ||
2865 | return register_cdrom(devinfo); | ||
2866 | } | ||
2867 | |||
2868 | static | ||
2869 | int ide_cdrom_get_capabilities(ide_drive_t *drive, struct atapi_capabilities_page *cap) | ||
2870 | { | ||
2871 | struct cdrom_info *info = drive->driver_data; | ||
2872 | struct cdrom_device_info *cdi = &info->devinfo; | ||
2873 | struct packet_command cgc; | ||
2874 | int stat, attempts = 3, size = sizeof(*cap); | ||
2875 | |||
2876 | /* | ||
2877 | * ACER50 (and others?) require the full spec length mode sense | ||
2878 | * page capabilities size, but older drives break. | ||
2879 | */ | ||
2880 | if (!(!strcmp(drive->id->model, "ATAPI CD ROM DRIVE 50X MAX") || | ||
2881 | !strcmp(drive->id->model, "WPI CDS-32X"))) | ||
2882 | size -= sizeof(cap->pad); | ||
2883 | |||
2884 | init_cdrom_command(&cgc, cap, size, CGC_DATA_UNKNOWN); | ||
2885 | do { /* we seem to get stat=0x01,err=0x00 the first time (??) */ | ||
2886 | stat = cdrom_mode_sense(cdi, &cgc, GPMODE_CAPABILITIES_PAGE, 0); | ||
2887 | if (!stat) | ||
2888 | break; | ||
2889 | } while (--attempts); | ||
2890 | return stat; | ||
2891 | } | ||
2892 | |||
2893 | static | ||
2894 | int ide_cdrom_probe_capabilities (ide_drive_t *drive) | ||
2895 | { | ||
2896 | struct cdrom_info *info = drive->driver_data; | ||
2897 | struct cdrom_device_info *cdi = &info->devinfo; | ||
2898 | struct atapi_capabilities_page cap; | ||
2899 | int nslots = 1; | ||
2900 | |||
2901 | if (drive->media == ide_optical) { | ||
2902 | CDROM_CONFIG_FLAGS(drive)->mo_drive = 1; | ||
2903 | CDROM_CONFIG_FLAGS(drive)->ram = 1; | ||
2904 | printk(KERN_ERR "%s: ATAPI magneto-optical drive\n", drive->name); | ||
2905 | return nslots; | ||
2906 | } | ||
2907 | |||
2908 | if (CDROM_CONFIG_FLAGS(drive)->nec260 || | ||
2909 | !strcmp(drive->id->model,"STINGRAY 8422 IDE 8X CD-ROM 7-27-95")) { | ||
2910 | CDROM_CONFIG_FLAGS(drive)->no_eject = 0; | ||
2911 | CDROM_CONFIG_FLAGS(drive)->audio_play = 1; | ||
2912 | return nslots; | ||
2913 | } | ||
2914 | |||
2915 | /* | ||
2916 | * we have to cheat a little here. the packet will eventually | ||
2917 | * be queued with ide_cdrom_packet(), which extracts the | ||
2918 | * drive from cdi->handle. Since this device hasn't been | ||
2919 | * registered with the Uniform layer yet, it can't do this. | ||
2920 | * Same goes for cdi->ops. | ||
2921 | */ | ||
2922 | cdi->handle = (ide_drive_t *) drive; | ||
2923 | cdi->ops = &ide_cdrom_dops; | ||
2924 | |||
2925 | if (ide_cdrom_get_capabilities(drive, &cap)) | ||
2926 | return 0; | ||
2927 | |||
2928 | if (cap.lock == 0) | ||
2929 | CDROM_CONFIG_FLAGS(drive)->no_doorlock = 1; | ||
2930 | if (cap.eject) | ||
2931 | CDROM_CONFIG_FLAGS(drive)->no_eject = 0; | ||
2932 | if (cap.cd_r_write) | ||
2933 | CDROM_CONFIG_FLAGS(drive)->cd_r = 1; | ||
2934 | if (cap.cd_rw_write) { | ||
2935 | CDROM_CONFIG_FLAGS(drive)->cd_rw = 1; | ||
2936 | CDROM_CONFIG_FLAGS(drive)->ram = 1; | ||
2937 | } | ||
2938 | if (cap.test_write) | ||
2939 | CDROM_CONFIG_FLAGS(drive)->test_write = 1; | ||
2940 | if (cap.dvd_ram_read || cap.dvd_r_read || cap.dvd_rom) | ||
2941 | CDROM_CONFIG_FLAGS(drive)->dvd = 1; | ||
2942 | if (cap.dvd_ram_write) { | ||
2943 | CDROM_CONFIG_FLAGS(drive)->dvd_ram = 1; | ||
2944 | CDROM_CONFIG_FLAGS(drive)->ram = 1; | ||
2945 | } | ||
2946 | if (cap.dvd_r_write) | ||
2947 | CDROM_CONFIG_FLAGS(drive)->dvd_r = 1; | ||
2948 | if (cap.audio_play) | ||
2949 | CDROM_CONFIG_FLAGS(drive)->audio_play = 1; | ||
2950 | if (cap.mechtype == mechtype_caddy || cap.mechtype == mechtype_popup) | ||
2951 | CDROM_CONFIG_FLAGS(drive)->close_tray = 0; | ||
2952 | |||
2953 | /* Some drives used by Apple don't advertise audio play | ||
2954 | * but they do support reading TOC & audio datas | ||
2955 | */ | ||
2956 | if (strcmp(drive->id->model, "MATSHITADVD-ROM SR-8187") == 0 || | ||
2957 | strcmp(drive->id->model, "MATSHITADVD-ROM SR-8186") == 0 || | ||
2958 | strcmp(drive->id->model, "MATSHITADVD-ROM SR-8176") == 0 || | ||
2959 | strcmp(drive->id->model, "MATSHITADVD-ROM SR-8174") == 0) | ||
2960 | CDROM_CONFIG_FLAGS(drive)->audio_play = 1; | ||
2961 | |||
2962 | #if ! STANDARD_ATAPI | ||
2963 | if (cdi->sanyo_slot > 0) { | ||
2964 | CDROM_CONFIG_FLAGS(drive)->is_changer = 1; | ||
2965 | nslots = 3; | ||
2966 | } | ||
2967 | |||
2968 | else | ||
2969 | #endif /* not STANDARD_ATAPI */ | ||
2970 | if (cap.mechtype == mechtype_individual_changer || | ||
2971 | cap.mechtype == mechtype_cartridge_changer) { | ||
2972 | if ((nslots = cdrom_number_of_slots(cdi)) > 1) { | ||
2973 | CDROM_CONFIG_FLAGS(drive)->is_changer = 1; | ||
2974 | CDROM_CONFIG_FLAGS(drive)->supp_disc_present = 1; | ||
2975 | } | ||
2976 | } | ||
2977 | |||
2978 | /* The ACER/AOpen 24X cdrom has the speed fields byte-swapped */ | ||
2979 | if (!drive->id->model[0] && | ||
2980 | !strncmp(drive->id->fw_rev, "241N", 4)) { | ||
2981 | CDROM_STATE_FLAGS(drive)->current_speed = | ||
2982 | (((unsigned int)cap.curspeed) + (176/2)) / 176; | ||
2983 | CDROM_CONFIG_FLAGS(drive)->max_speed = | ||
2984 | (((unsigned int)cap.maxspeed) + (176/2)) / 176; | ||
2985 | } else { | ||
2986 | CDROM_STATE_FLAGS(drive)->current_speed = | ||
2987 | (ntohs(cap.curspeed) + (176/2)) / 176; | ||
2988 | CDROM_CONFIG_FLAGS(drive)->max_speed = | ||
2989 | (ntohs(cap.maxspeed) + (176/2)) / 176; | ||
2990 | } | ||
2991 | |||
2992 | /* don't print speed if the drive reported 0. | ||
2993 | */ | ||
2994 | printk(KERN_INFO "%s: ATAPI", drive->name); | ||
2995 | if (CDROM_CONFIG_FLAGS(drive)->max_speed) | ||
2996 | printk(" %dX", CDROM_CONFIG_FLAGS(drive)->max_speed); | ||
2997 | printk(" %s", CDROM_CONFIG_FLAGS(drive)->dvd ? "DVD-ROM" : "CD-ROM"); | ||
2998 | |||
2999 | if (CDROM_CONFIG_FLAGS(drive)->dvd_r|CDROM_CONFIG_FLAGS(drive)->dvd_ram) | ||
3000 | printk(" DVD%s%s", | ||
3001 | (CDROM_CONFIG_FLAGS(drive)->dvd_r)? "-R" : "", | ||
3002 | (CDROM_CONFIG_FLAGS(drive)->dvd_ram)? "-RAM" : ""); | ||
3003 | |||
3004 | if (CDROM_CONFIG_FLAGS(drive)->cd_r|CDROM_CONFIG_FLAGS(drive)->cd_rw) | ||
3005 | printk(" CD%s%s", | ||
3006 | (CDROM_CONFIG_FLAGS(drive)->cd_r)? "-R" : "", | ||
3007 | (CDROM_CONFIG_FLAGS(drive)->cd_rw)? "/RW" : ""); | ||
3008 | |||
3009 | if (CDROM_CONFIG_FLAGS(drive)->is_changer) | ||
3010 | printk(" changer w/%d slots", nslots); | ||
3011 | else | ||
3012 | printk(" drive"); | ||
3013 | |||
3014 | printk(", %dkB Cache", be16_to_cpu(cap.buffer_size)); | ||
3015 | |||
3016 | if (drive->using_dma) | ||
3017 | ide_dma_verbose(drive); | ||
3018 | |||
3019 | printk("\n"); | ||
3020 | |||
3021 | return nslots; | ||
3022 | } | ||
3023 | |||
3024 | static void ide_cdrom_add_settings(ide_drive_t *drive) | ||
3025 | { | ||
3026 | ide_add_setting(drive, "dsc_overlap", SETTING_RW, -1, -1, TYPE_BYTE, 0, 1, 1, 1, &drive->dsc_overlap, NULL); | ||
3027 | } | ||
3028 | |||
3029 | /* | ||
3030 | * standard prep_rq_fn that builds 10 byte cmds | ||
3031 | */ | ||
3032 | static int ide_cdrom_prep_fs(request_queue_t *q, struct request *rq) | ||
3033 | { | ||
3034 | int hard_sect = queue_hardsect_size(q); | ||
3035 | long block = (long)rq->hard_sector / (hard_sect >> 9); | ||
3036 | unsigned long blocks = rq->hard_nr_sectors / (hard_sect >> 9); | ||
3037 | |||
3038 | memset(rq->cmd, 0, sizeof(rq->cmd)); | ||
3039 | |||
3040 | if (rq_data_dir(rq) == READ) | ||
3041 | rq->cmd[0] = GPCMD_READ_10; | ||
3042 | else | ||
3043 | rq->cmd[0] = GPCMD_WRITE_10; | ||
3044 | |||
3045 | /* | ||
3046 | * fill in lba | ||
3047 | */ | ||
3048 | rq->cmd[2] = (block >> 24) & 0xff; | ||
3049 | rq->cmd[3] = (block >> 16) & 0xff; | ||
3050 | rq->cmd[4] = (block >> 8) & 0xff; | ||
3051 | rq->cmd[5] = block & 0xff; | ||
3052 | |||
3053 | /* | ||
3054 | * and transfer length | ||
3055 | */ | ||
3056 | rq->cmd[7] = (blocks >> 8) & 0xff; | ||
3057 | rq->cmd[8] = blocks & 0xff; | ||
3058 | rq->cmd_len = 10; | ||
3059 | return BLKPREP_OK; | ||
3060 | } | ||
3061 | |||
3062 | /* | ||
3063 | * Most of the SCSI commands are supported directly by ATAPI devices. | ||
3064 | * This transform handles the few exceptions. | ||
3065 | */ | ||
3066 | static int ide_cdrom_prep_pc(struct request *rq) | ||
3067 | { | ||
3068 | u8 *c = rq->cmd; | ||
3069 | |||
3070 | /* | ||
3071 | * Transform 6-byte read/write commands to the 10-byte version | ||
3072 | */ | ||
3073 | if (c[0] == READ_6 || c[0] == WRITE_6) { | ||
3074 | c[8] = c[4]; | ||
3075 | c[5] = c[3]; | ||
3076 | c[4] = c[2]; | ||
3077 | c[3] = c[1] & 0x1f; | ||
3078 | c[2] = 0; | ||
3079 | c[1] &= 0xe0; | ||
3080 | c[0] += (READ_10 - READ_6); | ||
3081 | rq->cmd_len = 10; | ||
3082 | return BLKPREP_OK; | ||
3083 | } | ||
3084 | |||
3085 | /* | ||
3086 | * it's silly to pretend we understand 6-byte sense commands, just | ||
3087 | * reject with ILLEGAL_REQUEST and the caller should take the | ||
3088 | * appropriate action | ||
3089 | */ | ||
3090 | if (c[0] == MODE_SENSE || c[0] == MODE_SELECT) { | ||
3091 | rq->errors = ILLEGAL_REQUEST; | ||
3092 | return BLKPREP_KILL; | ||
3093 | } | ||
3094 | |||
3095 | return BLKPREP_OK; | ||
3096 | } | ||
3097 | |||
3098 | static int ide_cdrom_prep_fn(request_queue_t *q, struct request *rq) | ||
3099 | { | ||
3100 | if (rq->flags & REQ_CMD) | ||
3101 | return ide_cdrom_prep_fs(q, rq); | ||
3102 | else if (rq->flags & REQ_BLOCK_PC) | ||
3103 | return ide_cdrom_prep_pc(rq); | ||
3104 | |||
3105 | return 0; | ||
3106 | } | ||
3107 | |||
3108 | static | ||
3109 | int ide_cdrom_setup (ide_drive_t *drive) | ||
3110 | { | ||
3111 | struct cdrom_info *info = drive->driver_data; | ||
3112 | struct cdrom_device_info *cdi = &info->devinfo; | ||
3113 | int nslots; | ||
3114 | |||
3115 | blk_queue_prep_rq(drive->queue, ide_cdrom_prep_fn); | ||
3116 | blk_queue_dma_alignment(drive->queue, 31); | ||
3117 | drive->queue->unplug_delay = (1 * HZ) / 1000; | ||
3118 | if (!drive->queue->unplug_delay) | ||
3119 | drive->queue->unplug_delay = 1; | ||
3120 | |||
3121 | drive->special.all = 0; | ||
3122 | |||
3123 | CDROM_STATE_FLAGS(drive)->media_changed = 1; | ||
3124 | CDROM_STATE_FLAGS(drive)->toc_valid = 0; | ||
3125 | CDROM_STATE_FLAGS(drive)->door_locked = 0; | ||
3126 | |||
3127 | #if NO_DOOR_LOCKING | ||
3128 | CDROM_CONFIG_FLAGS(drive)->no_doorlock = 1; | ||
3129 | #else | ||
3130 | CDROM_CONFIG_FLAGS(drive)->no_doorlock = 0; | ||
3131 | #endif | ||
3132 | |||
3133 | CDROM_CONFIG_FLAGS(drive)->drq_interrupt = ((drive->id->config & 0x0060) == 0x20); | ||
3134 | CDROM_CONFIG_FLAGS(drive)->is_changer = 0; | ||
3135 | CDROM_CONFIG_FLAGS(drive)->cd_r = 0; | ||
3136 | CDROM_CONFIG_FLAGS(drive)->cd_rw = 0; | ||
3137 | CDROM_CONFIG_FLAGS(drive)->test_write = 0; | ||
3138 | CDROM_CONFIG_FLAGS(drive)->dvd = 0; | ||
3139 | CDROM_CONFIG_FLAGS(drive)->dvd_r = 0; | ||
3140 | CDROM_CONFIG_FLAGS(drive)->dvd_ram = 0; | ||
3141 | CDROM_CONFIG_FLAGS(drive)->no_eject = 1; | ||
3142 | CDROM_CONFIG_FLAGS(drive)->supp_disc_present = 0; | ||
3143 | CDROM_CONFIG_FLAGS(drive)->audio_play = 0; | ||
3144 | CDROM_CONFIG_FLAGS(drive)->close_tray = 1; | ||
3145 | |||
3146 | /* limit transfer size per interrupt. */ | ||
3147 | CDROM_CONFIG_FLAGS(drive)->limit_nframes = 0; | ||
3148 | /* a testament to the nice quality of Samsung drives... */ | ||
3149 | if (!strcmp(drive->id->model, "SAMSUNG CD-ROM SCR-2430")) | ||
3150 | CDROM_CONFIG_FLAGS(drive)->limit_nframes = 1; | ||
3151 | else if (!strcmp(drive->id->model, "SAMSUNG CD-ROM SCR-2432")) | ||
3152 | CDROM_CONFIG_FLAGS(drive)->limit_nframes = 1; | ||
3153 | /* the 3231 model does not support the SET_CD_SPEED command */ | ||
3154 | else if (!strcmp(drive->id->model, "SAMSUNG CD-ROM SCR-3231")) | ||
3155 | cdi->mask |= CDC_SELECT_SPEED; | ||
3156 | |||
3157 | #if ! STANDARD_ATAPI | ||
3158 | /* by default Sanyo 3 CD changer support is turned off and | ||
3159 | ATAPI Rev 2.2+ standard support for CD changers is used */ | ||
3160 | cdi->sanyo_slot = 0; | ||
3161 | |||
3162 | CDROM_CONFIG_FLAGS(drive)->nec260 = 0; | ||
3163 | CDROM_CONFIG_FLAGS(drive)->toctracks_as_bcd = 0; | ||
3164 | CDROM_CONFIG_FLAGS(drive)->tocaddr_as_bcd = 0; | ||
3165 | CDROM_CONFIG_FLAGS(drive)->playmsf_as_bcd = 0; | ||
3166 | CDROM_CONFIG_FLAGS(drive)->subchan_as_bcd = 0; | ||
3167 | |||
3168 | if (strcmp (drive->id->model, "V003S0DS") == 0 && | ||
3169 | drive->id->fw_rev[4] == '1' && | ||
3170 | drive->id->fw_rev[6] <= '2') { | ||
3171 | /* Vertos 300. | ||
3172 | Some versions of this drive like to talk BCD. */ | ||
3173 | CDROM_CONFIG_FLAGS(drive)->toctracks_as_bcd = 1; | ||
3174 | CDROM_CONFIG_FLAGS(drive)->tocaddr_as_bcd = 1; | ||
3175 | CDROM_CONFIG_FLAGS(drive)->playmsf_as_bcd = 1; | ||
3176 | CDROM_CONFIG_FLAGS(drive)->subchan_as_bcd = 1; | ||
3177 | } | ||
3178 | |||
3179 | else if (strcmp (drive->id->model, "V006E0DS") == 0 && | ||
3180 | drive->id->fw_rev[4] == '1' && | ||
3181 | drive->id->fw_rev[6] <= '2') { | ||
3182 | /* Vertos 600 ESD. */ | ||
3183 | CDROM_CONFIG_FLAGS(drive)->toctracks_as_bcd = 1; | ||
3184 | } | ||
3185 | else if (strcmp(drive->id->model, "NEC CD-ROM DRIVE:260") == 0 && | ||
3186 | strncmp(drive->id->fw_rev, "1.01", 4) == 0) { /* FIXME */ | ||
3187 | /* Old NEC260 (not R). | ||
3188 | This drive was released before the 1.2 version | ||
3189 | of the spec. */ | ||
3190 | CDROM_CONFIG_FLAGS(drive)->tocaddr_as_bcd = 1; | ||
3191 | CDROM_CONFIG_FLAGS(drive)->playmsf_as_bcd = 1; | ||
3192 | CDROM_CONFIG_FLAGS(drive)->subchan_as_bcd = 1; | ||
3193 | CDROM_CONFIG_FLAGS(drive)->nec260 = 1; | ||
3194 | } | ||
3195 | else if (strcmp(drive->id->model, "WEARNES CDD-120") == 0 && | ||
3196 | strncmp(drive->id->fw_rev, "A1.1", 4) == 0) { /* FIXME */ | ||
3197 | /* Wearnes */ | ||
3198 | CDROM_CONFIG_FLAGS(drive)->playmsf_as_bcd = 1; | ||
3199 | CDROM_CONFIG_FLAGS(drive)->subchan_as_bcd = 1; | ||
3200 | } | ||
3201 | /* Sanyo 3 CD changer uses a non-standard command | ||
3202 | for CD changing */ | ||
3203 | else if ((strcmp(drive->id->model, "CD-ROM CDR-C3 G") == 0) || | ||
3204 | (strcmp(drive->id->model, "CD-ROM CDR-C3G") == 0) || | ||
3205 | (strcmp(drive->id->model, "CD-ROM CDR_C36") == 0)) { | ||
3206 | /* uses CD in slot 0 when value is set to 3 */ | ||
3207 | cdi->sanyo_slot = 3; | ||
3208 | } | ||
3209 | #endif /* not STANDARD_ATAPI */ | ||
3210 | |||
3211 | info->toc = NULL; | ||
3212 | info->buffer = NULL; | ||
3213 | info->sector_buffered = 0; | ||
3214 | info->nsectors_buffered = 0; | ||
3215 | info->changer_info = NULL; | ||
3216 | info->last_block = 0; | ||
3217 | info->start_seek = 0; | ||
3218 | |||
3219 | nslots = ide_cdrom_probe_capabilities (drive); | ||
3220 | |||
3221 | /* | ||
3222 | * set correct block size | ||
3223 | */ | ||
3224 | blk_queue_hardsect_size(drive->queue, CD_FRAMESIZE); | ||
3225 | |||
3226 | if (drive->autotune == IDE_TUNE_DEFAULT || | ||
3227 | drive->autotune == IDE_TUNE_AUTO) | ||
3228 | drive->dsc_overlap = (drive->next != drive); | ||
3229 | #if 0 | ||
3230 | drive->dsc_overlap = (HWIF(drive)->no_dsc) ? 0 : 1; | ||
3231 | if (HWIF(drive)->no_dsc) { | ||
3232 | printk(KERN_INFO "ide-cd: %s: disabling DSC overlap\n", | ||
3233 | drive->name); | ||
3234 | drive->dsc_overlap = 0; | ||
3235 | } | ||
3236 | #endif | ||
3237 | |||
3238 | if (ide_cdrom_register(drive, nslots)) { | ||
3239 | printk (KERN_ERR "%s: ide_cdrom_setup failed to register device with the cdrom driver.\n", drive->name); | ||
3240 | info->devinfo.handle = NULL; | ||
3241 | return 1; | ||
3242 | } | ||
3243 | ide_cdrom_add_settings(drive); | ||
3244 | return 0; | ||
3245 | } | ||
3246 | |||
3247 | static | ||
3248 | sector_t ide_cdrom_capacity (ide_drive_t *drive) | ||
3249 | { | ||
3250 | unsigned long capacity, sectors_per_frame; | ||
3251 | |||
3252 | if (cdrom_read_capacity(drive, &capacity, §ors_per_frame, NULL)) | ||
3253 | return 0; | ||
3254 | |||
3255 | return capacity * sectors_per_frame; | ||
3256 | } | ||
3257 | |||
3258 | static | ||
3259 | int ide_cdrom_cleanup(ide_drive_t *drive) | ||
3260 | { | ||
3261 | struct cdrom_info *info = drive->driver_data; | ||
3262 | |||
3263 | if (ide_unregister_subdriver(drive)) { | ||
3264 | printk(KERN_ERR "%s: %s: failed to ide_unregister_subdriver\n", | ||
3265 | __FUNCTION__, drive->name); | ||
3266 | return 1; | ||
3267 | } | ||
3268 | |||
3269 | del_gendisk(info->disk); | ||
3270 | |||
3271 | ide_cd_put(info); | ||
3272 | |||
3273 | return 0; | ||
3274 | } | ||
3275 | |||
3276 | static void ide_cd_release(struct kref *kref) | ||
3277 | { | ||
3278 | struct cdrom_info *info = to_ide_cd(kref); | ||
3279 | struct cdrom_device_info *devinfo = &info->devinfo; | ||
3280 | ide_drive_t *drive = info->drive; | ||
3281 | struct gendisk *g = info->disk; | ||
3282 | |||
3283 | if (info->buffer != NULL) | ||
3284 | kfree(info->buffer); | ||
3285 | if (info->toc != NULL) | ||
3286 | kfree(info->toc); | ||
3287 | if (info->changer_info != NULL) | ||
3288 | kfree(info->changer_info); | ||
3289 | if (devinfo->handle == drive && unregister_cdrom(devinfo)) | ||
3290 | printk(KERN_ERR "%s: %s failed to unregister device from the cdrom " | ||
3291 | "driver.\n", __FUNCTION__, drive->name); | ||
3292 | drive->dsc_overlap = 0; | ||
3293 | drive->driver_data = NULL; | ||
3294 | blk_queue_prep_rq(drive->queue, NULL); | ||
3295 | g->private_data = NULL; | ||
3296 | put_disk(g); | ||
3297 | kfree(info); | ||
3298 | } | ||
3299 | |||
3300 | static int ide_cdrom_attach (ide_drive_t *drive); | ||
3301 | |||
3302 | #ifdef CONFIG_PROC_FS | ||
3303 | static int proc_idecd_read_capacity | ||
3304 | (char *page, char **start, off_t off, int count, int *eof, void *data) | ||
3305 | { | ||
3306 | ide_drive_t*drive = (ide_drive_t *)data; | ||
3307 | int len; | ||
3308 | |||
3309 | len = sprintf(page,"%llu\n", (long long)ide_cdrom_capacity(drive)); | ||
3310 | PROC_IDE_READ_RETURN(page,start,off,count,eof,len); | ||
3311 | } | ||
3312 | |||
3313 | static ide_proc_entry_t idecd_proc[] = { | ||
3314 | { "capacity", S_IFREG|S_IRUGO, proc_idecd_read_capacity, NULL }, | ||
3315 | { NULL, 0, NULL, NULL } | ||
3316 | }; | ||
3317 | #else | ||
3318 | # define idecd_proc NULL | ||
3319 | #endif | ||
3320 | |||
3321 | static ide_driver_t ide_cdrom_driver = { | ||
3322 | .owner = THIS_MODULE, | ||
3323 | .name = "ide-cdrom", | ||
3324 | .version = IDECD_VERSION, | ||
3325 | .media = ide_cdrom, | ||
3326 | .busy = 0, | ||
3327 | .supports_dsc_overlap = 1, | ||
3328 | .cleanup = ide_cdrom_cleanup, | ||
3329 | .do_request = ide_do_rw_cdrom, | ||
3330 | .end_request = ide_end_request, | ||
3331 | .error = __ide_error, | ||
3332 | .abort = __ide_abort, | ||
3333 | .proc = idecd_proc, | ||
3334 | .attach = ide_cdrom_attach, | ||
3335 | .drives = LIST_HEAD_INIT(ide_cdrom_driver.drives), | ||
3336 | }; | ||
3337 | |||
3338 | static int idecd_open(struct inode * inode, struct file * file) | ||
3339 | { | ||
3340 | struct gendisk *disk = inode->i_bdev->bd_disk; | ||
3341 | struct cdrom_info *info; | ||
3342 | ide_drive_t *drive; | ||
3343 | int rc = -ENOMEM; | ||
3344 | |||
3345 | if (!(info = ide_cd_get(disk))) | ||
3346 | return -ENXIO; | ||
3347 | |||
3348 | drive = info->drive; | ||
3349 | |||
3350 | drive->usage++; | ||
3351 | |||
3352 | if (!info->buffer) | ||
3353 | info->buffer = kmalloc(SECTOR_BUFFER_SIZE, | ||
3354 | GFP_KERNEL|__GFP_REPEAT); | ||
3355 | if (!info->buffer || (rc = cdrom_open(&info->devinfo, inode, file))) | ||
3356 | drive->usage--; | ||
3357 | |||
3358 | if (rc < 0) | ||
3359 | ide_cd_put(info); | ||
3360 | |||
3361 | return rc; | ||
3362 | } | ||
3363 | |||
3364 | static int idecd_release(struct inode * inode, struct file * file) | ||
3365 | { | ||
3366 | struct gendisk *disk = inode->i_bdev->bd_disk; | ||
3367 | struct cdrom_info *info = ide_cd_g(disk); | ||
3368 | ide_drive_t *drive = info->drive; | ||
3369 | |||
3370 | cdrom_release (&info->devinfo, file); | ||
3371 | drive->usage--; | ||
3372 | |||
3373 | ide_cd_put(info); | ||
3374 | |||
3375 | return 0; | ||
3376 | } | ||
3377 | |||
3378 | static int idecd_ioctl (struct inode *inode, struct file *file, | ||
3379 | unsigned int cmd, unsigned long arg) | ||
3380 | { | ||
3381 | struct block_device *bdev = inode->i_bdev; | ||
3382 | struct cdrom_info *info = ide_cd_g(bdev->bd_disk); | ||
3383 | int err; | ||
3384 | |||
3385 | err = generic_ide_ioctl(info->drive, file, bdev, cmd, arg); | ||
3386 | if (err == -EINVAL) | ||
3387 | err = cdrom_ioctl(file, &info->devinfo, inode, cmd, arg); | ||
3388 | |||
3389 | return err; | ||
3390 | } | ||
3391 | |||
3392 | static int idecd_media_changed(struct gendisk *disk) | ||
3393 | { | ||
3394 | struct cdrom_info *info = ide_cd_g(disk); | ||
3395 | return cdrom_media_changed(&info->devinfo); | ||
3396 | } | ||
3397 | |||
3398 | static int idecd_revalidate_disk(struct gendisk *disk) | ||
3399 | { | ||
3400 | struct cdrom_info *info = ide_cd_g(disk); | ||
3401 | struct request_sense sense; | ||
3402 | cdrom_read_toc(info->drive, &sense); | ||
3403 | return 0; | ||
3404 | } | ||
3405 | |||
3406 | static struct block_device_operations idecd_ops = { | ||
3407 | .owner = THIS_MODULE, | ||
3408 | .open = idecd_open, | ||
3409 | .release = idecd_release, | ||
3410 | .ioctl = idecd_ioctl, | ||
3411 | .media_changed = idecd_media_changed, | ||
3412 | .revalidate_disk= idecd_revalidate_disk | ||
3413 | }; | ||
3414 | |||
3415 | /* options */ | ||
3416 | static char *ignore = NULL; | ||
3417 | |||
3418 | module_param(ignore, charp, 0400); | ||
3419 | MODULE_DESCRIPTION("ATAPI CD-ROM Driver"); | ||
3420 | |||
3421 | static int ide_cdrom_attach (ide_drive_t *drive) | ||
3422 | { | ||
3423 | struct cdrom_info *info; | ||
3424 | struct gendisk *g; | ||
3425 | struct request_sense sense; | ||
3426 | |||
3427 | if (!strstr("ide-cdrom", drive->driver_req)) | ||
3428 | goto failed; | ||
3429 | if (!drive->present) | ||
3430 | goto failed; | ||
3431 | if (drive->media != ide_cdrom && drive->media != ide_optical) | ||
3432 | goto failed; | ||
3433 | /* skip drives that we were told to ignore */ | ||
3434 | if (ignore != NULL) { | ||
3435 | if (strstr(ignore, drive->name)) { | ||
3436 | printk(KERN_INFO "ide-cd: ignoring drive %s\n", drive->name); | ||
3437 | goto failed; | ||
3438 | } | ||
3439 | } | ||
3440 | if (drive->scsi) { | ||
3441 | printk(KERN_INFO "ide-cd: passing drive %s to ide-scsi emulation.\n", drive->name); | ||
3442 | goto failed; | ||
3443 | } | ||
3444 | info = (struct cdrom_info *) kmalloc (sizeof (struct cdrom_info), GFP_KERNEL); | ||
3445 | if (info == NULL) { | ||
3446 | printk(KERN_ERR "%s: Can't allocate a cdrom structure\n", drive->name); | ||
3447 | goto failed; | ||
3448 | } | ||
3449 | |||
3450 | g = alloc_disk(1 << PARTN_BITS); | ||
3451 | if (!g) | ||
3452 | goto out_free_cd; | ||
3453 | |||
3454 | ide_init_disk(g, drive); | ||
3455 | |||
3456 | if (ide_register_subdriver(drive, &ide_cdrom_driver)) { | ||
3457 | printk(KERN_ERR "%s: Failed to register the driver with ide.c\n", | ||
3458 | drive->name); | ||
3459 | goto out_put_disk; | ||
3460 | } | ||
3461 | memset(info, 0, sizeof (struct cdrom_info)); | ||
3462 | |||
3463 | kref_init(&info->kref); | ||
3464 | |||
3465 | info->drive = drive; | ||
3466 | info->driver = &ide_cdrom_driver; | ||
3467 | info->disk = g; | ||
3468 | |||
3469 | g->private_data = &info->driver; | ||
3470 | |||
3471 | drive->driver_data = info; | ||
3472 | |||
3473 | DRIVER(drive)->busy++; | ||
3474 | g->minors = 1; | ||
3475 | snprintf(g->devfs_name, sizeof(g->devfs_name), | ||
3476 | "%s/cd", drive->devfs_name); | ||
3477 | g->driverfs_dev = &drive->gendev; | ||
3478 | g->flags = GENHD_FL_CD | GENHD_FL_REMOVABLE; | ||
3479 | if (ide_cdrom_setup(drive)) { | ||
3480 | struct cdrom_device_info *devinfo = &info->devinfo; | ||
3481 | DRIVER(drive)->busy--; | ||
3482 | ide_unregister_subdriver(drive); | ||
3483 | if (info->buffer != NULL) | ||
3484 | kfree(info->buffer); | ||
3485 | if (info->toc != NULL) | ||
3486 | kfree(info->toc); | ||
3487 | if (info->changer_info != NULL) | ||
3488 | kfree(info->changer_info); | ||
3489 | if (devinfo->handle == drive && unregister_cdrom(devinfo)) | ||
3490 | printk (KERN_ERR "%s: ide_cdrom_cleanup failed to unregister device from the cdrom driver.\n", drive->name); | ||
3491 | kfree(info); | ||
3492 | drive->driver_data = NULL; | ||
3493 | goto failed; | ||
3494 | } | ||
3495 | DRIVER(drive)->busy--; | ||
3496 | |||
3497 | cdrom_read_toc(drive, &sense); | ||
3498 | g->fops = &idecd_ops; | ||
3499 | g->flags |= GENHD_FL_REMOVABLE; | ||
3500 | add_disk(g); | ||
3501 | return 0; | ||
3502 | |||
3503 | out_put_disk: | ||
3504 | put_disk(g); | ||
3505 | out_free_cd: | ||
3506 | kfree(info); | ||
3507 | failed: | ||
3508 | return 1; | ||
3509 | } | ||
3510 | |||
3511 | static void __exit ide_cdrom_exit(void) | ||
3512 | { | ||
3513 | ide_unregister_driver(&ide_cdrom_driver); | ||
3514 | } | ||
3515 | |||
3516 | static int ide_cdrom_init(void) | ||
3517 | { | ||
3518 | ide_register_driver(&ide_cdrom_driver); | ||
3519 | return 0; | ||
3520 | } | ||
3521 | |||
3522 | module_init(ide_cdrom_init); | ||
3523 | module_exit(ide_cdrom_exit); | ||
3524 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/ide/ide-cd.h b/drivers/ide/ide-cd.h new file mode 100644 index 000000000000..7ca3e5afc665 --- /dev/null +++ b/drivers/ide/ide-cd.h | |||
@@ -0,0 +1,746 @@ | |||
1 | /* | ||
2 | * linux/drivers/ide/ide_cd.h | ||
3 | * | ||
4 | * Copyright (C) 1996-98 Erik Andersen | ||
5 | * Copyright (C) 1998-2000 Jens Axboe | ||
6 | */ | ||
7 | #ifndef _IDE_CD_H | ||
8 | #define _IDE_CD_H | ||
9 | |||
10 | #include <linux/cdrom.h> | ||
11 | #include <asm/byteorder.h> | ||
12 | |||
13 | /* Turn this on to have the driver print out the meanings of the | ||
14 | ATAPI error codes. This will use up additional kernel-space | ||
15 | memory, though. */ | ||
16 | |||
17 | #ifndef VERBOSE_IDE_CD_ERRORS | ||
18 | #define VERBOSE_IDE_CD_ERRORS 1 | ||
19 | #endif | ||
20 | |||
21 | |||
22 | /* Turning this on will remove code to work around various nonstandard | ||
23 | ATAPI implementations. If you know your drive follows the standard, | ||
24 | this will give you a slightly smaller kernel. */ | ||
25 | |||
26 | #ifndef STANDARD_ATAPI | ||
27 | #define STANDARD_ATAPI 0 | ||
28 | #endif | ||
29 | |||
30 | |||
31 | /* Turning this on will disable the door-locking functionality. | ||
32 | This is apparently needed for supermount. */ | ||
33 | |||
34 | #ifndef NO_DOOR_LOCKING | ||
35 | #define NO_DOOR_LOCKING 0 | ||
36 | #endif | ||
37 | |||
38 | /* | ||
39 | * typical timeout for packet command | ||
40 | */ | ||
41 | #define ATAPI_WAIT_PC (60 * HZ) | ||
42 | #define ATAPI_WAIT_WRITE_BUSY (10 * HZ) | ||
43 | |||
44 | /************************************************************************/ | ||
45 | |||
46 | #define SECTOR_BITS 9 | ||
47 | #ifndef SECTOR_SIZE | ||
48 | #define SECTOR_SIZE (1 << SECTOR_BITS) | ||
49 | #endif | ||
50 | #define SECTORS_PER_FRAME (CD_FRAMESIZE >> SECTOR_BITS) | ||
51 | #define SECTOR_BUFFER_SIZE (CD_FRAMESIZE * 32) | ||
52 | #define SECTORS_BUFFER (SECTOR_BUFFER_SIZE >> SECTOR_BITS) | ||
53 | #define SECTORS_MAX (131072 >> SECTOR_BITS) | ||
54 | |||
55 | #define BLOCKS_PER_FRAME (CD_FRAMESIZE / BLOCK_SIZE) | ||
56 | |||
57 | /* special command codes for strategy routine. */ | ||
58 | #define PACKET_COMMAND 4315 | ||
59 | #define REQUEST_SENSE_COMMAND 4316 | ||
60 | #define RESET_DRIVE_COMMAND 4317 | ||
61 | |||
62 | |||
63 | /* Configuration flags. These describe the capabilities of the drive. | ||
64 | They generally do not change after initialization, unless we learn | ||
65 | more about the drive from stuff failing. */ | ||
66 | struct ide_cd_config_flags { | ||
67 | __u8 drq_interrupt : 1; /* Device sends an interrupt when ready | ||
68 | for a packet command. */ | ||
69 | __u8 no_doorlock : 1; /* Drive cannot lock the door. */ | ||
70 | __u8 no_eject : 1; /* Drive cannot eject the disc. */ | ||
71 | __u8 nec260 : 1; /* Drive is a pre-1.2 NEC 260 drive. */ | ||
72 | __u8 playmsf_as_bcd : 1; /* PLAYMSF command takes BCD args. */ | ||
73 | __u8 tocaddr_as_bcd : 1; /* TOC addresses are in BCD. */ | ||
74 | __u8 toctracks_as_bcd : 1; /* TOC track numbers are in BCD. */ | ||
75 | __u8 subchan_as_bcd : 1; /* Subchannel info is in BCD. */ | ||
76 | __u8 is_changer : 1; /* Drive is a changer. */ | ||
77 | __u8 cd_r : 1; /* Drive can write to CD-R media . */ | ||
78 | __u8 cd_rw : 1; /* Drive can write to CD-R/W media . */ | ||
79 | __u8 dvd : 1; /* Drive is a DVD-ROM */ | ||
80 | __u8 dvd_r : 1; /* Drive can write DVD-R */ | ||
81 | __u8 dvd_ram : 1; /* Drive can write DVD-RAM */ | ||
82 | __u8 ram : 1; /* generic WRITE (dvd-ram/mrw) */ | ||
83 | __u8 test_write : 1; /* Drive can fake writes */ | ||
84 | __u8 supp_disc_present : 1; /* Changer can report exact contents | ||
85 | of slots. */ | ||
86 | __u8 limit_nframes : 1; /* Drive does not provide data in | ||
87 | multiples of SECTOR_SIZE when more | ||
88 | than one interrupt is needed. */ | ||
89 | __u8 seeking : 1; /* Seeking in progress */ | ||
90 | __u8 audio_play : 1; /* can do audio related commands */ | ||
91 | __u8 close_tray : 1; /* can close the tray */ | ||
92 | __u8 writing : 1; /* pseudo write in progress */ | ||
93 | __u8 mo_drive : 1; /* drive is an MO device */ | ||
94 | __u8 reserved : 2; | ||
95 | byte max_speed; /* Max speed of the drive */ | ||
96 | }; | ||
97 | #define CDROM_CONFIG_FLAGS(drive) (&(((struct cdrom_info *)(drive->driver_data))->config_flags)) | ||
98 | |||
99 | |||
100 | /* State flags. These give information about the current state of the | ||
101 | drive, and will change during normal operation. */ | ||
102 | struct ide_cd_state_flags { | ||
103 | __u8 media_changed : 1; /* Driver has noticed a media change. */ | ||
104 | __u8 toc_valid : 1; /* Saved TOC information is current. */ | ||
105 | __u8 door_locked : 1; /* We think that the drive door is locked. */ | ||
106 | __u8 writing : 1; /* the drive is currently writing */ | ||
107 | __u8 reserved : 4; | ||
108 | byte current_speed; /* Current speed of the drive */ | ||
109 | }; | ||
110 | |||
111 | #define CDROM_STATE_FLAGS(drive) (&(((struct cdrom_info *)(drive->driver_data))->state_flags)) | ||
112 | |||
113 | /* Structure of a MSF cdrom address. */ | ||
114 | struct atapi_msf { | ||
115 | byte reserved; | ||
116 | byte minute; | ||
117 | byte second; | ||
118 | byte frame; | ||
119 | }; | ||
120 | |||
121 | /* Space to hold the disk TOC. */ | ||
122 | #define MAX_TRACKS 99 | ||
123 | struct atapi_toc_header { | ||
124 | unsigned short toc_length; | ||
125 | byte first_track; | ||
126 | byte last_track; | ||
127 | }; | ||
128 | |||
129 | struct atapi_toc_entry { | ||
130 | byte reserved1; | ||
131 | #if defined(__BIG_ENDIAN_BITFIELD) | ||
132 | __u8 adr : 4; | ||
133 | __u8 control : 4; | ||
134 | #elif defined(__LITTLE_ENDIAN_BITFIELD) | ||
135 | __u8 control : 4; | ||
136 | __u8 adr : 4; | ||
137 | #else | ||
138 | #error "Please fix <asm/byteorder.h>" | ||
139 | #endif | ||
140 | byte track; | ||
141 | byte reserved2; | ||
142 | union { | ||
143 | unsigned lba; | ||
144 | struct atapi_msf msf; | ||
145 | } addr; | ||
146 | }; | ||
147 | |||
148 | struct atapi_toc { | ||
149 | int last_session_lba; | ||
150 | int xa_flag; | ||
151 | unsigned long capacity; | ||
152 | struct atapi_toc_header hdr; | ||
153 | struct atapi_toc_entry ent[MAX_TRACKS+1]; | ||
154 | /* One extra for the leadout. */ | ||
155 | }; | ||
156 | |||
157 | |||
158 | /* This structure is annoyingly close to, but not identical with, | ||
159 | the cdrom_subchnl structure from cdrom.h. */ | ||
160 | struct atapi_cdrom_subchnl { | ||
161 | u_char acdsc_reserved; | ||
162 | u_char acdsc_audiostatus; | ||
163 | u_short acdsc_length; | ||
164 | u_char acdsc_format; | ||
165 | |||
166 | #if defined(__BIG_ENDIAN_BITFIELD) | ||
167 | u_char acdsc_ctrl: 4; | ||
168 | u_char acdsc_adr: 4; | ||
169 | #elif defined(__LITTLE_ENDIAN_BITFIELD) | ||
170 | u_char acdsc_adr: 4; | ||
171 | u_char acdsc_ctrl: 4; | ||
172 | #else | ||
173 | #error "Please fix <asm/byteorder.h>" | ||
174 | #endif | ||
175 | u_char acdsc_trk; | ||
176 | u_char acdsc_ind; | ||
177 | union { | ||
178 | struct atapi_msf msf; | ||
179 | int lba; | ||
180 | } acdsc_absaddr; | ||
181 | union { | ||
182 | struct atapi_msf msf; | ||
183 | int lba; | ||
184 | } acdsc_reladdr; | ||
185 | }; | ||
186 | |||
187 | |||
188 | |||
189 | /* This should probably go into cdrom.h along with the other | ||
190 | * generic stuff now in the Mt. Fuji spec. | ||
191 | */ | ||
192 | struct atapi_capabilities_page { | ||
193 | struct mode_page_header header; | ||
194 | #if defined(__BIG_ENDIAN_BITFIELD) | ||
195 | __u8 parameters_saveable : 1; | ||
196 | __u8 reserved1 : 1; | ||
197 | __u8 page_code : 6; | ||
198 | #elif defined(__LITTLE_ENDIAN_BITFIELD) | ||
199 | __u8 page_code : 6; | ||
200 | __u8 reserved1 : 1; | ||
201 | __u8 parameters_saveable : 1; | ||
202 | #else | ||
203 | #error "Please fix <asm/byteorder.h>" | ||
204 | #endif | ||
205 | |||
206 | byte page_length; | ||
207 | |||
208 | #if defined(__BIG_ENDIAN_BITFIELD) | ||
209 | __u8 reserved2 : 2; | ||
210 | /* Drive supports reading of DVD-RAM discs */ | ||
211 | __u8 dvd_ram_read : 1; | ||
212 | /* Drive supports reading of DVD-R discs */ | ||
213 | __u8 dvd_r_read : 1; | ||
214 | /* Drive supports reading of DVD-ROM discs */ | ||
215 | __u8 dvd_rom : 1; | ||
216 | /* Drive supports reading CD-R discs with addressing method 2 */ | ||
217 | __u8 method2 : 1; /* reserved in 1.2 */ | ||
218 | /* Drive can read from CD-R/W (CD-E) discs (orange book, part III) */ | ||
219 | __u8 cd_rw_read : 1; /* reserved in 1.2 */ | ||
220 | /* Drive supports read from CD-R discs (orange book, part II) */ | ||
221 | __u8 cd_r_read : 1; /* reserved in 1.2 */ | ||
222 | #elif defined(__LITTLE_ENDIAN_BITFIELD) | ||
223 | /* Drive supports read from CD-R discs (orange book, part II) */ | ||
224 | __u8 cd_r_read : 1; /* reserved in 1.2 */ | ||
225 | /* Drive can read from CD-R/W (CD-E) discs (orange book, part III) */ | ||
226 | __u8 cd_rw_read : 1; /* reserved in 1.2 */ | ||
227 | /* Drive supports reading CD-R discs with addressing method 2 */ | ||
228 | __u8 method2 : 1; | ||
229 | /* Drive supports reading of DVD-ROM discs */ | ||
230 | __u8 dvd_rom : 1; | ||
231 | /* Drive supports reading of DVD-R discs */ | ||
232 | __u8 dvd_r_read : 1; | ||
233 | /* Drive supports reading of DVD-RAM discs */ | ||
234 | __u8 dvd_ram_read : 1; | ||
235 | __u8 reserved2 : 2; | ||
236 | #else | ||
237 | #error "Please fix <asm/byteorder.h>" | ||
238 | #endif | ||
239 | |||
240 | #if defined(__BIG_ENDIAN_BITFIELD) | ||
241 | __u8 reserved3 : 2; | ||
242 | /* Drive can write DVD-RAM discs */ | ||
243 | __u8 dvd_ram_write : 1; | ||
244 | /* Drive can write DVD-R discs */ | ||
245 | __u8 dvd_r_write : 1; | ||
246 | __u8 reserved3a : 1; | ||
247 | /* Drive can fake writes */ | ||
248 | __u8 test_write : 1; | ||
249 | /* Drive can write to CD-R/W (CD-E) discs (orange book, part III) */ | ||
250 | __u8 cd_rw_write : 1; /* reserved in 1.2 */ | ||
251 | /* Drive supports write to CD-R discs (orange book, part II) */ | ||
252 | __u8 cd_r_write : 1; /* reserved in 1.2 */ | ||
253 | #elif defined(__LITTLE_ENDIAN_BITFIELD) | ||
254 | /* Drive can write to CD-R discs (orange book, part II) */ | ||
255 | __u8 cd_r_write : 1; /* reserved in 1.2 */ | ||
256 | /* Drive can write to CD-R/W (CD-E) discs (orange book, part III) */ | ||
257 | __u8 cd_rw_write : 1; /* reserved in 1.2 */ | ||
258 | /* Drive can fake writes */ | ||
259 | __u8 test_write : 1; | ||
260 | __u8 reserved3a : 1; | ||
261 | /* Drive can write DVD-R discs */ | ||
262 | __u8 dvd_r_write : 1; | ||
263 | /* Drive can write DVD-RAM discs */ | ||
264 | __u8 dvd_ram_write : 1; | ||
265 | __u8 reserved3 : 2; | ||
266 | #else | ||
267 | #error "Please fix <asm/byteorder.h>" | ||
268 | #endif | ||
269 | |||
270 | #if defined(__BIG_ENDIAN_BITFIELD) | ||
271 | __u8 reserved4 : 1; | ||
272 | /* Drive can read multisession discs. */ | ||
273 | __u8 multisession : 1; | ||
274 | /* Drive can read mode 2, form 2 data. */ | ||
275 | __u8 mode2_form2 : 1; | ||
276 | /* Drive can read mode 2, form 1 (XA) data. */ | ||
277 | __u8 mode2_form1 : 1; | ||
278 | /* Drive supports digital output on port 2. */ | ||
279 | __u8 digport2 : 1; | ||
280 | /* Drive supports digital output on port 1. */ | ||
281 | __u8 digport1 : 1; | ||
282 | /* Drive can deliver a composite audio/video data stream. */ | ||
283 | __u8 composite : 1; | ||
284 | /* Drive supports audio play operations. */ | ||
285 | __u8 audio_play : 1; | ||
286 | #elif defined(__LITTLE_ENDIAN_BITFIELD) | ||
287 | /* Drive supports audio play operations. */ | ||
288 | __u8 audio_play : 1; | ||
289 | /* Drive can deliver a composite audio/video data stream. */ | ||
290 | __u8 composite : 1; | ||
291 | /* Drive supports digital output on port 1. */ | ||
292 | __u8 digport1 : 1; | ||
293 | /* Drive supports digital output on port 2. */ | ||
294 | __u8 digport2 : 1; | ||
295 | /* Drive can read mode 2, form 1 (XA) data. */ | ||
296 | __u8 mode2_form1 : 1; | ||
297 | /* Drive can read mode 2, form 2 data. */ | ||
298 | __u8 mode2_form2 : 1; | ||
299 | /* Drive can read multisession discs. */ | ||
300 | __u8 multisession : 1; | ||
301 | __u8 reserved4 : 1; | ||
302 | #else | ||
303 | #error "Please fix <asm/byteorder.h>" | ||
304 | #endif | ||
305 | |||
306 | #if defined(__BIG_ENDIAN_BITFIELD) | ||
307 | __u8 reserved5 : 1; | ||
308 | /* Drive can return Media Catalog Number (UPC) info. */ | ||
309 | __u8 upc : 1; | ||
310 | /* Drive can return International Standard Recording Code info. */ | ||
311 | __u8 isrc : 1; | ||
312 | /* Drive supports C2 error pointers. */ | ||
313 | __u8 c2_pointers : 1; | ||
314 | /* R-W data will be returned deinterleaved and error corrected. */ | ||
315 | __u8 rw_corr : 1; | ||
316 | /* Subchannel reads can return combined R-W information. */ | ||
317 | __u8 rw_supported : 1; | ||
318 | /* Drive can continue a read cdda operation from a loss of streaming.*/ | ||
319 | __u8 cdda_accurate : 1; | ||
320 | /* Drive can read Red Book audio data. */ | ||
321 | __u8 cdda : 1; | ||
322 | #elif defined(__LITTLE_ENDIAN_BITFIELD) | ||
323 | /* Drive can read Red Book audio data. */ | ||
324 | __u8 cdda : 1; | ||
325 | /* Drive can continue a read cdda operation from a loss of streaming.*/ | ||
326 | __u8 cdda_accurate : 1; | ||
327 | /* Subchannel reads can return combined R-W information. */ | ||
328 | __u8 rw_supported : 1; | ||
329 | /* R-W data will be returned deinterleaved and error corrected. */ | ||
330 | __u8 rw_corr : 1; | ||
331 | /* Drive supports C2 error pointers. */ | ||
332 | __u8 c2_pointers : 1; | ||
333 | /* Drive can return International Standard Recording Code info. */ | ||
334 | __u8 isrc : 1; | ||
335 | /* Drive can return Media Catalog Number (UPC) info. */ | ||
336 | __u8 upc : 1; | ||
337 | __u8 reserved5 : 1; | ||
338 | #else | ||
339 | #error "Please fix <asm/byteorder.h>" | ||
340 | #endif | ||
341 | |||
342 | #if defined(__BIG_ENDIAN_BITFIELD) | ||
343 | /* Drive mechanism types. */ | ||
344 | mechtype_t mechtype : 3; | ||
345 | __u8 reserved6 : 1; | ||
346 | /* Drive can eject a disc or changer cartridge. */ | ||
347 | __u8 eject : 1; | ||
348 | /* State of prevent/allow jumper. */ | ||
349 | __u8 prevent_jumper : 1; | ||
350 | /* Present state of door lock. */ | ||
351 | __u8 lock_state : 1; | ||
352 | /* Drive can lock the door. */ | ||
353 | __u8 lock : 1; | ||
354 | #elif defined(__LITTLE_ENDIAN_BITFIELD) | ||
355 | |||
356 | /* Drive can lock the door. */ | ||
357 | __u8 lock : 1; | ||
358 | /* Present state of door lock. */ | ||
359 | __u8 lock_state : 1; | ||
360 | /* State of prevent/allow jumper. */ | ||
361 | __u8 prevent_jumper : 1; | ||
362 | /* Drive can eject a disc or changer cartridge. */ | ||
363 | __u8 eject : 1; | ||
364 | __u8 reserved6 : 1; | ||
365 | /* Drive mechanism types. */ | ||
366 | mechtype_t mechtype : 3; | ||
367 | #else | ||
368 | #error "Please fix <asm/byteorder.h>" | ||
369 | #endif | ||
370 | |||
371 | #if defined(__BIG_ENDIAN_BITFIELD) | ||
372 | __u8 reserved7 : 4; | ||
373 | /* Drive supports software slot selection. */ | ||
374 | __u8 sss : 1; /* reserved in 1.2 */ | ||
375 | /* Changer can report exact contents of slots. */ | ||
376 | __u8 disc_present : 1; /* reserved in 1.2 */ | ||
377 | /* Audio for each channel can be muted independently. */ | ||
378 | __u8 separate_mute : 1; | ||
379 | /* Audio level for each channel can be controlled independently. */ | ||
380 | __u8 separate_volume : 1; | ||
381 | #elif defined(__LITTLE_ENDIAN_BITFIELD) | ||
382 | |||
383 | /* Audio level for each channel can be controlled independently. */ | ||
384 | __u8 separate_volume : 1; | ||
385 | /* Audio for each channel can be muted independently. */ | ||
386 | __u8 separate_mute : 1; | ||
387 | /* Changer can report exact contents of slots. */ | ||
388 | __u8 disc_present : 1; /* reserved in 1.2 */ | ||
389 | /* Drive supports software slot selection. */ | ||
390 | __u8 sss : 1; /* reserved in 1.2 */ | ||
391 | __u8 reserved7 : 4; | ||
392 | #else | ||
393 | #error "Please fix <asm/byteorder.h>" | ||
394 | #endif | ||
395 | |||
396 | /* Note: the following four fields are returned in big-endian form. */ | ||
397 | /* Maximum speed (in kB/s). */ | ||
398 | unsigned short maxspeed; | ||
399 | /* Number of discrete volume levels. */ | ||
400 | unsigned short n_vol_levels; | ||
401 | /* Size of cache in drive, in kB. */ | ||
402 | unsigned short buffer_size; | ||
403 | /* Current speed (in kB/s). */ | ||
404 | unsigned short curspeed; | ||
405 | char pad[4]; | ||
406 | }; | ||
407 | |||
408 | |||
409 | struct atapi_mechstat_header { | ||
410 | #if defined(__BIG_ENDIAN_BITFIELD) | ||
411 | __u8 fault : 1; | ||
412 | __u8 changer_state : 2; | ||
413 | __u8 curslot : 5; | ||
414 | #elif defined(__LITTLE_ENDIAN_BITFIELD) | ||
415 | __u8 curslot : 5; | ||
416 | __u8 changer_state : 2; | ||
417 | __u8 fault : 1; | ||
418 | #else | ||
419 | #error "Please fix <asm/byteorder.h>" | ||
420 | #endif | ||
421 | |||
422 | #if defined(__BIG_ENDIAN_BITFIELD) | ||
423 | __u8 mech_state : 3; | ||
424 | __u8 door_open : 1; | ||
425 | __u8 reserved1 : 4; | ||
426 | #elif defined(__LITTLE_ENDIAN_BITFIELD) | ||
427 | __u8 reserved1 : 4; | ||
428 | __u8 door_open : 1; | ||
429 | __u8 mech_state : 3; | ||
430 | #else | ||
431 | #error "Please fix <asm/byteorder.h>" | ||
432 | #endif | ||
433 | |||
434 | byte curlba[3]; | ||
435 | byte nslots; | ||
436 | __u16 slot_tablelen; | ||
437 | }; | ||
438 | |||
439 | |||
440 | struct atapi_slot { | ||
441 | #if defined(__BIG_ENDIAN_BITFIELD) | ||
442 | __u8 disc_present : 1; | ||
443 | __u8 reserved1 : 6; | ||
444 | __u8 change : 1; | ||
445 | #elif defined(__LITTLE_ENDIAN_BITFIELD) | ||
446 | __u8 change : 1; | ||
447 | __u8 reserved1 : 6; | ||
448 | __u8 disc_present : 1; | ||
449 | #else | ||
450 | #error "Please fix <asm/byteorder.h>" | ||
451 | #endif | ||
452 | |||
453 | byte reserved2[3]; | ||
454 | }; | ||
455 | |||
456 | struct atapi_changer_info { | ||
457 | struct atapi_mechstat_header hdr; | ||
458 | struct atapi_slot slots[0]; | ||
459 | }; | ||
460 | |||
461 | /* Extra per-device info for cdrom drives. */ | ||
462 | struct cdrom_info { | ||
463 | ide_drive_t *drive; | ||
464 | ide_driver_t *driver; | ||
465 | struct gendisk *disk; | ||
466 | struct kref kref; | ||
467 | |||
468 | /* Buffer for table of contents. NULL if we haven't allocated | ||
469 | a TOC buffer for this device yet. */ | ||
470 | |||
471 | struct atapi_toc *toc; | ||
472 | |||
473 | unsigned long sector_buffered; | ||
474 | unsigned long nsectors_buffered; | ||
475 | unsigned char *buffer; | ||
476 | |||
477 | /* The result of the last successful request sense command | ||
478 | on this device. */ | ||
479 | struct request_sense sense_data; | ||
480 | |||
481 | struct request request_sense_request; | ||
482 | int dma; | ||
483 | int cmd; | ||
484 | unsigned long last_block; | ||
485 | unsigned long start_seek; | ||
486 | /* Buffer to hold mechanism status and changer slot table. */ | ||
487 | struct atapi_changer_info *changer_info; | ||
488 | |||
489 | struct ide_cd_config_flags config_flags; | ||
490 | struct ide_cd_state_flags state_flags; | ||
491 | |||
492 | /* Per-device info needed by cdrom.c generic driver. */ | ||
493 | struct cdrom_device_info devinfo; | ||
494 | |||
495 | unsigned long write_timeout; | ||
496 | }; | ||
497 | |||
498 | /**************************************************************************** | ||
499 | * Descriptions of ATAPI error codes. | ||
500 | */ | ||
501 | |||
502 | #define ARY_LEN(a) ((sizeof(a) / sizeof(a[0]))) | ||
503 | |||
504 | /* This stuff should be in cdrom.h, since it is now generic... */ | ||
505 | |||
506 | /* ATAPI sense keys (from table 140 of ATAPI 2.6) */ | ||
507 | #define NO_SENSE 0x00 | ||
508 | #define RECOVERED_ERROR 0x01 | ||
509 | #define NOT_READY 0x02 | ||
510 | #define MEDIUM_ERROR 0x03 | ||
511 | #define HARDWARE_ERROR 0x04 | ||
512 | #define ILLEGAL_REQUEST 0x05 | ||
513 | #define UNIT_ATTENTION 0x06 | ||
514 | #define DATA_PROTECT 0x07 | ||
515 | #define BLANK_CHECK 0x08 | ||
516 | #define ABORTED_COMMAND 0x0b | ||
517 | #define MISCOMPARE 0x0e | ||
518 | |||
519 | |||
520 | |||
521 | /* This stuff should be in cdrom.h, since it is now generic... */ | ||
522 | #if VERBOSE_IDE_CD_ERRORS | ||
523 | |||
524 | /* The generic packet command opcodes for CD/DVD Logical Units, | ||
525 | * From Table 57 of the SFF8090 Ver. 3 (Mt. Fuji) draft standard. */ | ||
526 | static const struct { | ||
527 | unsigned short packet_command; | ||
528 | const char * const text; | ||
529 | } packet_command_texts[] = { | ||
530 | { GPCMD_TEST_UNIT_READY, "Test Unit Ready" }, | ||
531 | { GPCMD_REQUEST_SENSE, "Request Sense" }, | ||
532 | { GPCMD_FORMAT_UNIT, "Format Unit" }, | ||
533 | { GPCMD_INQUIRY, "Inquiry" }, | ||
534 | { GPCMD_START_STOP_UNIT, "Start/Stop Unit" }, | ||
535 | { GPCMD_PREVENT_ALLOW_MEDIUM_REMOVAL, "Prevent/Allow Medium Removal" }, | ||
536 | { GPCMD_READ_FORMAT_CAPACITIES, "Read Format Capacities" }, | ||
537 | { GPCMD_READ_CDVD_CAPACITY, "Read Cd/Dvd Capacity" }, | ||
538 | { GPCMD_READ_10, "Read 10" }, | ||
539 | { GPCMD_WRITE_10, "Write 10" }, | ||
540 | { GPCMD_SEEK, "Seek" }, | ||
541 | { GPCMD_WRITE_AND_VERIFY_10, "Write and Verify 10" }, | ||
542 | { GPCMD_VERIFY_10, "Verify 10" }, | ||
543 | { GPCMD_FLUSH_CACHE, "Flush Cache" }, | ||
544 | { GPCMD_READ_SUBCHANNEL, "Read Subchannel" }, | ||
545 | { GPCMD_READ_TOC_PMA_ATIP, "Read Table of Contents" }, | ||
546 | { GPCMD_READ_HEADER, "Read Header" }, | ||
547 | { GPCMD_PLAY_AUDIO_10, "Play Audio 10" }, | ||
548 | { GPCMD_GET_CONFIGURATION, "Get Configuration" }, | ||
549 | { GPCMD_PLAY_AUDIO_MSF, "Play Audio MSF" }, | ||
550 | { GPCMD_PLAYAUDIO_TI, "Play Audio TrackIndex" }, | ||
551 | { GPCMD_GET_EVENT_STATUS_NOTIFICATION, "Get Event Status Notification" }, | ||
552 | { GPCMD_PAUSE_RESUME, "Pause/Resume" }, | ||
553 | { GPCMD_STOP_PLAY_SCAN, "Stop Play/Scan" }, | ||
554 | { GPCMD_READ_DISC_INFO, "Read Disc Info" }, | ||
555 | { GPCMD_READ_TRACK_RZONE_INFO, "Read Track Rzone Info" }, | ||
556 | { GPCMD_RESERVE_RZONE_TRACK, "Reserve Rzone Track" }, | ||
557 | { GPCMD_SEND_OPC, "Send OPC" }, | ||
558 | { GPCMD_MODE_SELECT_10, "Mode Select 10" }, | ||
559 | { GPCMD_REPAIR_RZONE_TRACK, "Repair Rzone Track" }, | ||
560 | { GPCMD_MODE_SENSE_10, "Mode Sense 10" }, | ||
561 | { GPCMD_CLOSE_TRACK, "Close Track" }, | ||
562 | { GPCMD_BLANK, "Blank" }, | ||
563 | { GPCMD_SEND_EVENT, "Send Event" }, | ||
564 | { GPCMD_SEND_KEY, "Send Key" }, | ||
565 | { GPCMD_REPORT_KEY, "Report Key" }, | ||
566 | { GPCMD_LOAD_UNLOAD, "Load/Unload" }, | ||
567 | { GPCMD_SET_READ_AHEAD, "Set Read-ahead" }, | ||
568 | { GPCMD_READ_12, "Read 12" }, | ||
569 | { GPCMD_GET_PERFORMANCE, "Get Performance" }, | ||
570 | { GPCMD_SEND_DVD_STRUCTURE, "Send DVD Structure" }, | ||
571 | { GPCMD_READ_DVD_STRUCTURE, "Read DVD Structure" }, | ||
572 | { GPCMD_SET_STREAMING, "Set Streaming" }, | ||
573 | { GPCMD_READ_CD_MSF, "Read CD MSF" }, | ||
574 | { GPCMD_SCAN, "Scan" }, | ||
575 | { GPCMD_SET_SPEED, "Set Speed" }, | ||
576 | { GPCMD_PLAY_CD, "Play CD" }, | ||
577 | { GPCMD_MECHANISM_STATUS, "Mechanism Status" }, | ||
578 | { GPCMD_READ_CD, "Read CD" }, | ||
579 | }; | ||
580 | |||
581 | |||
582 | |||
583 | /* From Table 303 of the SFF8090 Ver. 3 (Mt. Fuji) draft standard. */ | ||
584 | static const char * const sense_key_texts[16] = { | ||
585 | "No sense data", | ||
586 | "Recovered error", | ||
587 | "Not ready", | ||
588 | "Medium error", | ||
589 | "Hardware error", | ||
590 | "Illegal request", | ||
591 | "Unit attention", | ||
592 | "Data protect", | ||
593 | "Blank check", | ||
594 | "(reserved)", | ||
595 | "(reserved)", | ||
596 | "Aborted command", | ||
597 | "(reserved)", | ||
598 | "(reserved)", | ||
599 | "Miscompare", | ||
600 | "(reserved)", | ||
601 | }; | ||
602 | |||
603 | /* From Table 304 of the SFF8090 Ver. 3 (Mt. Fuji) draft standard. */ | ||
604 | static const struct { | ||
605 | unsigned long asc_ascq; | ||
606 | const char * const text; | ||
607 | } sense_data_texts[] = { | ||
608 | { 0x000000, "No additional sense information" }, | ||
609 | { 0x000011, "Play operation in progress" }, | ||
610 | { 0x000012, "Play operation paused" }, | ||
611 | { 0x000013, "Play operation successfully completed" }, | ||
612 | { 0x000014, "Play operation stopped due to error" }, | ||
613 | { 0x000015, "No current audio status to return" }, | ||
614 | { 0x010c0a, "Write error - padding blocks added" }, | ||
615 | { 0x011700, "Recovered data with no error correction applied" }, | ||
616 | { 0x011701, "Recovered data with retries" }, | ||
617 | { 0x011702, "Recovered data with positive head offset" }, | ||
618 | { 0x011703, "Recovered data with negative head offset" }, | ||
619 | { 0x011704, "Recovered data with retries and/or CIRC applied" }, | ||
620 | { 0x011705, "Recovered data using previous sector ID" }, | ||
621 | { 0x011800, "Recovered data with error correction applied" }, | ||
622 | { 0x011801, "Recovered data with error correction and retries applied"}, | ||
623 | { 0x011802, "Recovered data - the data was auto-reallocated" }, | ||
624 | { 0x011803, "Recovered data with CIRC" }, | ||
625 | { 0x011804, "Recovered data with L-EC" }, | ||
626 | { 0x015d00, | ||
627 | "Failure prediction threshold exceeded - Predicted logical unit failure" }, | ||
628 | { 0x015d01, | ||
629 | "Failure prediction threshold exceeded - Predicted media failure" }, | ||
630 | { 0x015dff, "Failure prediction threshold exceeded - False" }, | ||
631 | { 0x017301, "Power calibration area almost full" }, | ||
632 | { 0x020400, "Logical unit not ready - cause not reportable" }, | ||
633 | /* Following is misspelled in ATAPI 2.6, _and_ in Mt. Fuji */ | ||
634 | { 0x020401, | ||
635 | "Logical unit not ready - in progress [sic] of becoming ready" }, | ||
636 | { 0x020402, "Logical unit not ready - initializing command required" }, | ||
637 | { 0x020403, "Logical unit not ready - manual intervention required" }, | ||
638 | { 0x020404, "Logical unit not ready - format in progress" }, | ||
639 | { 0x020407, "Logical unit not ready - operation in progress" }, | ||
640 | { 0x020408, "Logical unit not ready - long write in progress" }, | ||
641 | { 0x020600, "No reference position found (media may be upside down)" }, | ||
642 | { 0x023000, "Incompatible medium installed" }, | ||
643 | { 0x023a00, "Medium not present" }, | ||
644 | { 0x025300, "Media load or eject failed" }, | ||
645 | { 0x025700, "Unable to recover table of contents" }, | ||
646 | { 0x030300, "Peripheral device write fault" }, | ||
647 | { 0x030301, "No write current" }, | ||
648 | { 0x030302, "Excessive write errors" }, | ||
649 | { 0x030c00, "Write error" }, | ||
650 | { 0x030c01, "Write error - Recovered with auto reallocation" }, | ||
651 | { 0x030c02, "Write error - auto reallocation failed" }, | ||
652 | { 0x030c03, "Write error - recommend reassignment" }, | ||
653 | { 0x030c04, "Compression check miscompare error" }, | ||
654 | { 0x030c05, "Data expansion occurred during compress" }, | ||
655 | { 0x030c06, "Block not compressible" }, | ||
656 | { 0x030c07, "Write error - recovery needed" }, | ||
657 | { 0x030c08, "Write error - recovery failed" }, | ||
658 | { 0x030c09, "Write error - loss of streaming" }, | ||
659 | { 0x031100, "Unrecovered read error" }, | ||
660 | { 0x031106, "CIRC unrecovered error" }, | ||
661 | { 0x033101, "Format command failed" }, | ||
662 | { 0x033200, "No defect spare location available" }, | ||
663 | { 0x033201, "Defect list update failure" }, | ||
664 | { 0x035100, "Erase failure" }, | ||
665 | { 0x037200, "Session fixation error" }, | ||
666 | { 0x037201, "Session fixation error writin lead-in" }, | ||
667 | { 0x037202, "Session fixation error writin lead-out" }, | ||
668 | { 0x037300, "CD control error" }, | ||
669 | { 0x037302, "Power calibration area is full" }, | ||
670 | { 0x037303, "Power calibration area error" }, | ||
671 | { 0x037304, "Program memory area / RMA update failure" }, | ||
672 | { 0x037305, "Program memory area / RMA is full" }, | ||
673 | { 0x037306, "Program memory area / RMA is (almost) full" }, | ||
674 | |||
675 | { 0x040200, "No seek complete" }, | ||
676 | { 0x040300, "Write fault" }, | ||
677 | { 0x040900, "Track following error" }, | ||
678 | { 0x040901, "Tracking servo failure" }, | ||
679 | { 0x040902, "Focus servo failure" }, | ||
680 | { 0x040903, "Spindle servo failure" }, | ||
681 | { 0x041500, "Random positioning error" }, | ||
682 | { 0x041501, "Mechanical positioning or changer error" }, | ||
683 | { 0x041502, "Positioning error detected by read of medium" }, | ||
684 | { 0x043c00, "Mechanical positioning or changer error" }, | ||
685 | { 0x044000, "Diagnostic failure on component (ASCQ)" }, | ||
686 | { 0x044400, "Internal CD/DVD logical unit failure" }, | ||
687 | { 0x04b600, "Media load mechanism failed" }, | ||
688 | { 0x051a00, "Parameter list length error" }, | ||
689 | { 0x052000, "Invalid command operation code" }, | ||
690 | { 0x052100, "Logical block address out of range" }, | ||
691 | { 0x052102, "Invalid address for write" }, | ||
692 | { 0x052400, "Invalid field in command packet" }, | ||
693 | { 0x052600, "Invalid field in parameter list" }, | ||
694 | { 0x052601, "Parameter not supported" }, | ||
695 | { 0x052602, "Parameter value invalid" }, | ||
696 | { 0x052700, "Write protected media" }, | ||
697 | { 0x052c00, "Command sequence error" }, | ||
698 | { 0x052c03, "Current program area is not empty" }, | ||
699 | { 0x052c04, "Current program area is empty" }, | ||
700 | { 0x053001, "Cannot read medium - unknown format" }, | ||
701 | { 0x053002, "Cannot read medium - incompatible format" }, | ||
702 | { 0x053900, "Saving parameters not supported" }, | ||
703 | { 0x054e00, "Overlapped commands attempted" }, | ||
704 | { 0x055302, "Medium removal prevented" }, | ||
705 | { 0x055500, "System resource failure" }, | ||
706 | { 0x056300, "End of user area encountered on this track" }, | ||
707 | { 0x056400, "Illegal mode for this track or incompatible medium" }, | ||
708 | { 0x056f00, "Copy protection key exchange failure - Authentication failure" }, | ||
709 | { 0x056f01, "Copy protection key exchange failure - Key not present" }, | ||
710 | { 0x056f02, "Copy protection key exchange failure - Key not established" }, | ||
711 | { 0x056f03, "Read of scrambled sector without authentication" }, | ||
712 | { 0x056f04, "Media region code is mismatched to logical unit" }, | ||
713 | { 0x056f05, "Drive region must be permanent / region reset count error" }, | ||
714 | { 0x057203, "Session fixation error - incomplete track in session" }, | ||
715 | { 0x057204, "Empty or partially written reserved track" }, | ||
716 | { 0x057205, "No more RZONE reservations are allowed" }, | ||
717 | { 0x05bf00, "Loss of streaming" }, | ||
718 | { 0x062800, "Not ready to ready transition, medium may have changed" }, | ||
719 | { 0x062900, "Power on, reset or hardware reset occurred" }, | ||
720 | { 0x062a00, "Parameters changed" }, | ||
721 | { 0x062a01, "Mode parameters changed" }, | ||
722 | { 0x062e00, "Insufficient time for operation" }, | ||
723 | { 0x063f00, "Logical unit operating conditions have changed" }, | ||
724 | { 0x063f01, "Microcode has been changed" }, | ||
725 | { 0x065a00, "Operator request or state change input (unspecified)" }, | ||
726 | { 0x065a01, "Operator medium removal request" }, | ||
727 | { 0x0bb900, "Play operation aborted" }, | ||
728 | |||
729 | /* Here we use 0xff for the key (not a valid key) to signify | ||
730 | * that these can have _any_ key value associated with them... */ | ||
731 | { 0xff0401, "Logical unit is in process of becoming ready" }, | ||
732 | { 0xff0400, "Logical unit not ready, cause not reportable" }, | ||
733 | { 0xff0402, "Logical unit not ready, initializing command required" }, | ||
734 | { 0xff0403, "Logical unit not ready, manual intervention required" }, | ||
735 | { 0xff0500, "Logical unit does not respond to selection" }, | ||
736 | { 0xff0800, "Logical unit communication failure" }, | ||
737 | { 0xff0802, "Logical unit communication parity error" }, | ||
738 | { 0xff0801, "Logical unit communication time-out" }, | ||
739 | { 0xff2500, "Logical unit not supported" }, | ||
740 | { 0xff4c00, "Logical unit failed self-configuration" }, | ||
741 | { 0xff3e00, "Logical unit has not self-configured yet" }, | ||
742 | }; | ||
743 | #endif | ||
744 | |||
745 | |||
746 | #endif /* _IDE_CD_H */ | ||
diff --git a/drivers/ide/ide-disk.c b/drivers/ide/ide-disk.c new file mode 100644 index 000000000000..5d54f7756100 --- /dev/null +++ b/drivers/ide/ide-disk.c | |||
@@ -0,0 +1,1280 @@ | |||
1 | /* | ||
2 | * linux/drivers/ide/ide-disk.c Version 1.18 Mar 05, 2003 | ||
3 | * | ||
4 | * Copyright (C) 1994-1998 Linus Torvalds & authors (see below) | ||
5 | * Copyright (C) 1998-2002 Linux ATA Development | ||
6 | * Andre Hedrick <andre@linux-ide.org> | ||
7 | * Copyright (C) 2003 Red Hat <alan@redhat.com> | ||
8 | */ | ||
9 | |||
10 | /* | ||
11 | * Mostly written by Mark Lord <mlord@pobox.com> | ||
12 | * and Gadi Oxman <gadio@netvision.net.il> | ||
13 | * and Andre Hedrick <andre@linux-ide.org> | ||
14 | * | ||
15 | * This is the IDE/ATA disk driver, as evolved from hd.c and ide.c. | ||
16 | * | ||
17 | * Version 1.00 move disk only code from ide.c to ide-disk.c | ||
18 | * support optional byte-swapping of all data | ||
19 | * Version 1.01 fix previous byte-swapping code | ||
20 | * Version 1.02 remove ", LBA" from drive identification msgs | ||
21 | * Version 1.03 fix display of id->buf_size for big-endian | ||
22 | * Version 1.04 add /proc configurable settings and S.M.A.R.T support | ||
23 | * Version 1.05 add capacity support for ATA3 >= 8GB | ||
24 | * Version 1.06 get boot-up messages to show full cyl count | ||
25 | * Version 1.07 disable door-locking if it fails | ||
26 | * Version 1.08 fixed CHS/LBA translations for ATA4 > 8GB, | ||
27 | * process of adding new ATA4 compliance. | ||
28 | * fixed problems in allowing fdisk to see | ||
29 | * the entire disk. | ||
30 | * Version 1.09 added increment of rq->sector in ide_multwrite | ||
31 | * added UDMA 3/4 reporting | ||
32 | * Version 1.10 request queue changes, Ultra DMA 100 | ||
33 | * Version 1.11 added 48-bit lba | ||
34 | * Version 1.12 adding taskfile io access method | ||
35 | * Version 1.13 added standby and flush-cache for notifier | ||
36 | * Version 1.14 added acoustic-wcache | ||
37 | * Version 1.15 convert all calls to ide_raw_taskfile | ||
38 | * since args will return register content. | ||
39 | * Version 1.16 added suspend-resume-checkpower | ||
40 | * Version 1.17 do flush on standy, do flush on ATA < ATA6 | ||
41 | * fix wcache setup. | ||
42 | */ | ||
43 | |||
44 | #define IDEDISK_VERSION "1.18" | ||
45 | |||
46 | #undef REALLY_SLOW_IO /* most systems can safely undef this */ | ||
47 | |||
48 | //#define DEBUG | ||
49 | |||
50 | #include <linux/config.h> | ||
51 | #include <linux/module.h> | ||
52 | #include <linux/types.h> | ||
53 | #include <linux/string.h> | ||
54 | #include <linux/kernel.h> | ||
55 | #include <linux/timer.h> | ||
56 | #include <linux/mm.h> | ||
57 | #include <linux/interrupt.h> | ||
58 | #include <linux/major.h> | ||
59 | #include <linux/errno.h> | ||
60 | #include <linux/genhd.h> | ||
61 | #include <linux/slab.h> | ||
62 | #include <linux/delay.h> | ||
63 | |||
64 | #define _IDE_DISK | ||
65 | |||
66 | #include <linux/ide.h> | ||
67 | |||
68 | #include <asm/byteorder.h> | ||
69 | #include <asm/irq.h> | ||
70 | #include <asm/uaccess.h> | ||
71 | #include <asm/io.h> | ||
72 | #include <asm/div64.h> | ||
73 | |||
74 | struct ide_disk_obj { | ||
75 | ide_drive_t *drive; | ||
76 | ide_driver_t *driver; | ||
77 | struct gendisk *disk; | ||
78 | struct kref kref; | ||
79 | }; | ||
80 | |||
81 | static DECLARE_MUTEX(idedisk_ref_sem); | ||
82 | |||
83 | #define to_ide_disk(obj) container_of(obj, struct ide_disk_obj, kref) | ||
84 | |||
85 | #define ide_disk_g(disk) \ | ||
86 | container_of((disk)->private_data, struct ide_disk_obj, driver) | ||
87 | |||
88 | static struct ide_disk_obj *ide_disk_get(struct gendisk *disk) | ||
89 | { | ||
90 | struct ide_disk_obj *idkp = NULL; | ||
91 | |||
92 | down(&idedisk_ref_sem); | ||
93 | idkp = ide_disk_g(disk); | ||
94 | if (idkp) | ||
95 | kref_get(&idkp->kref); | ||
96 | up(&idedisk_ref_sem); | ||
97 | return idkp; | ||
98 | } | ||
99 | |||
100 | static void ide_disk_release(struct kref *); | ||
101 | |||
102 | static void ide_disk_put(struct ide_disk_obj *idkp) | ||
103 | { | ||
104 | down(&idedisk_ref_sem); | ||
105 | kref_put(&idkp->kref, ide_disk_release); | ||
106 | up(&idedisk_ref_sem); | ||
107 | } | ||
108 | |||
109 | /* | ||
110 | * lba_capacity_is_ok() performs a sanity check on the claimed "lba_capacity" | ||
111 | * value for this drive (from its reported identification information). | ||
112 | * | ||
113 | * Returns: 1 if lba_capacity looks sensible | ||
114 | * 0 otherwise | ||
115 | * | ||
116 | * It is called only once for each drive. | ||
117 | */ | ||
118 | static int lba_capacity_is_ok (struct hd_driveid *id) | ||
119 | { | ||
120 | unsigned long lba_sects, chs_sects, head, tail; | ||
121 | |||
122 | /* | ||
123 | * The ATA spec tells large drives to return | ||
124 | * C/H/S = 16383/16/63 independent of their size. | ||
125 | * Some drives can be jumpered to use 15 heads instead of 16. | ||
126 | * Some drives can be jumpered to use 4092 cyls instead of 16383. | ||
127 | */ | ||
128 | if ((id->cyls == 16383 | ||
129 | || (id->cyls == 4092 && id->cur_cyls == 16383)) && | ||
130 | id->sectors == 63 && | ||
131 | (id->heads == 15 || id->heads == 16) && | ||
132 | (id->lba_capacity >= 16383*63*id->heads)) | ||
133 | return 1; | ||
134 | |||
135 | lba_sects = id->lba_capacity; | ||
136 | chs_sects = id->cyls * id->heads * id->sectors; | ||
137 | |||
138 | /* perform a rough sanity check on lba_sects: within 10% is OK */ | ||
139 | if ((lba_sects - chs_sects) < chs_sects/10) | ||
140 | return 1; | ||
141 | |||
142 | /* some drives have the word order reversed */ | ||
143 | head = ((lba_sects >> 16) & 0xffff); | ||
144 | tail = (lba_sects & 0xffff); | ||
145 | lba_sects = (head | (tail << 16)); | ||
146 | if ((lba_sects - chs_sects) < chs_sects/10) { | ||
147 | id->lba_capacity = lba_sects; | ||
148 | return 1; /* lba_capacity is (now) good */ | ||
149 | } | ||
150 | |||
151 | return 0; /* lba_capacity value may be bad */ | ||
152 | } | ||
153 | |||
154 | /* | ||
155 | * __ide_do_rw_disk() issues READ and WRITE commands to a disk, | ||
156 | * using LBA if supported, or CHS otherwise, to address sectors. | ||
157 | */ | ||
158 | static ide_startstop_t __ide_do_rw_disk(ide_drive_t *drive, struct request *rq, sector_t block) | ||
159 | { | ||
160 | ide_hwif_t *hwif = HWIF(drive); | ||
161 | unsigned int dma = drive->using_dma; | ||
162 | u8 lba48 = (drive->addressing == 1) ? 1 : 0; | ||
163 | task_ioreg_t command = WIN_NOP; | ||
164 | ata_nsector_t nsectors; | ||
165 | |||
166 | nsectors.all = (u16) rq->nr_sectors; | ||
167 | |||
168 | if (hwif->no_lba48_dma && lba48 && dma) { | ||
169 | if (block + rq->nr_sectors > 1ULL << 28) | ||
170 | dma = 0; | ||
171 | else | ||
172 | lba48 = 0; | ||
173 | } | ||
174 | |||
175 | if (!dma) { | ||
176 | ide_init_sg_cmd(drive, rq); | ||
177 | ide_map_sg(drive, rq); | ||
178 | } | ||
179 | |||
180 | if (IDE_CONTROL_REG) | ||
181 | hwif->OUTB(drive->ctl, IDE_CONTROL_REG); | ||
182 | |||
183 | /* FIXME: SELECT_MASK(drive, 0) ? */ | ||
184 | |||
185 | if (drive->select.b.lba) { | ||
186 | if (lba48) { | ||
187 | task_ioreg_t tasklets[10]; | ||
188 | |||
189 | pr_debug("%s: LBA=0x%012llx\n", drive->name, block); | ||
190 | |||
191 | tasklets[0] = 0; | ||
192 | tasklets[1] = 0; | ||
193 | tasklets[2] = nsectors.b.low; | ||
194 | tasklets[3] = nsectors.b.high; | ||
195 | tasklets[4] = (task_ioreg_t) block; | ||
196 | tasklets[5] = (task_ioreg_t) (block>>8); | ||
197 | tasklets[6] = (task_ioreg_t) (block>>16); | ||
198 | tasklets[7] = (task_ioreg_t) (block>>24); | ||
199 | if (sizeof(block) == 4) { | ||
200 | tasklets[8] = (task_ioreg_t) 0; | ||
201 | tasklets[9] = (task_ioreg_t) 0; | ||
202 | } else { | ||
203 | tasklets[8] = (task_ioreg_t)((u64)block >> 32); | ||
204 | tasklets[9] = (task_ioreg_t)((u64)block >> 40); | ||
205 | } | ||
206 | #ifdef DEBUG | ||
207 | printk("%s: 0x%02x%02x 0x%02x%02x%02x%02x%02x%02x\n", | ||
208 | drive->name, tasklets[3], tasklets[2], | ||
209 | tasklets[9], tasklets[8], tasklets[7], | ||
210 | tasklets[6], tasklets[5], tasklets[4]); | ||
211 | #endif | ||
212 | hwif->OUTB(tasklets[1], IDE_FEATURE_REG); | ||
213 | hwif->OUTB(tasklets[3], IDE_NSECTOR_REG); | ||
214 | hwif->OUTB(tasklets[7], IDE_SECTOR_REG); | ||
215 | hwif->OUTB(tasklets[8], IDE_LCYL_REG); | ||
216 | hwif->OUTB(tasklets[9], IDE_HCYL_REG); | ||
217 | |||
218 | hwif->OUTB(tasklets[0], IDE_FEATURE_REG); | ||
219 | hwif->OUTB(tasklets[2], IDE_NSECTOR_REG); | ||
220 | hwif->OUTB(tasklets[4], IDE_SECTOR_REG); | ||
221 | hwif->OUTB(tasklets[5], IDE_LCYL_REG); | ||
222 | hwif->OUTB(tasklets[6], IDE_HCYL_REG); | ||
223 | hwif->OUTB(0x00|drive->select.all,IDE_SELECT_REG); | ||
224 | } else { | ||
225 | hwif->OUTB(0x00, IDE_FEATURE_REG); | ||
226 | hwif->OUTB(nsectors.b.low, IDE_NSECTOR_REG); | ||
227 | hwif->OUTB(block, IDE_SECTOR_REG); | ||
228 | hwif->OUTB(block>>=8, IDE_LCYL_REG); | ||
229 | hwif->OUTB(block>>=8, IDE_HCYL_REG); | ||
230 | hwif->OUTB(((block>>8)&0x0f)|drive->select.all,IDE_SELECT_REG); | ||
231 | } | ||
232 | } else { | ||
233 | unsigned int sect,head,cyl,track; | ||
234 | track = (int)block / drive->sect; | ||
235 | sect = (int)block % drive->sect + 1; | ||
236 | hwif->OUTB(sect, IDE_SECTOR_REG); | ||
237 | head = track % drive->head; | ||
238 | cyl = track / drive->head; | ||
239 | |||
240 | pr_debug("%s: CHS=%u/%u/%u\n", drive->name, cyl, head, sect); | ||
241 | |||
242 | hwif->OUTB(0x00, IDE_FEATURE_REG); | ||
243 | hwif->OUTB(nsectors.b.low, IDE_NSECTOR_REG); | ||
244 | hwif->OUTB(cyl, IDE_LCYL_REG); | ||
245 | hwif->OUTB(cyl>>8, IDE_HCYL_REG); | ||
246 | hwif->OUTB(head|drive->select.all,IDE_SELECT_REG); | ||
247 | } | ||
248 | |||
249 | if (dma) { | ||
250 | if (!hwif->dma_setup(drive)) { | ||
251 | if (rq_data_dir(rq)) { | ||
252 | command = lba48 ? WIN_WRITEDMA_EXT : WIN_WRITEDMA; | ||
253 | if (drive->vdma) | ||
254 | command = lba48 ? WIN_WRITE_EXT: WIN_WRITE; | ||
255 | } else { | ||
256 | command = lba48 ? WIN_READDMA_EXT : WIN_READDMA; | ||
257 | if (drive->vdma) | ||
258 | command = lba48 ? WIN_READ_EXT: WIN_READ; | ||
259 | } | ||
260 | hwif->dma_exec_cmd(drive, command); | ||
261 | hwif->dma_start(drive); | ||
262 | return ide_started; | ||
263 | } | ||
264 | /* fallback to PIO */ | ||
265 | ide_init_sg_cmd(drive, rq); | ||
266 | } | ||
267 | |||
268 | if (rq_data_dir(rq) == READ) { | ||
269 | |||
270 | if (drive->mult_count) { | ||
271 | hwif->data_phase = TASKFILE_MULTI_IN; | ||
272 | command = lba48 ? WIN_MULTREAD_EXT : WIN_MULTREAD; | ||
273 | } else { | ||
274 | hwif->data_phase = TASKFILE_IN; | ||
275 | command = lba48 ? WIN_READ_EXT : WIN_READ; | ||
276 | } | ||
277 | |||
278 | ide_execute_command(drive, command, &task_in_intr, WAIT_CMD, NULL); | ||
279 | return ide_started; | ||
280 | } else { | ||
281 | if (drive->mult_count) { | ||
282 | hwif->data_phase = TASKFILE_MULTI_OUT; | ||
283 | command = lba48 ? WIN_MULTWRITE_EXT : WIN_MULTWRITE; | ||
284 | } else { | ||
285 | hwif->data_phase = TASKFILE_OUT; | ||
286 | command = lba48 ? WIN_WRITE_EXT : WIN_WRITE; | ||
287 | } | ||
288 | |||
289 | /* FIXME: ->OUTBSYNC ? */ | ||
290 | hwif->OUTB(command, IDE_COMMAND_REG); | ||
291 | |||
292 | return pre_task_out_intr(drive, rq); | ||
293 | } | ||
294 | } | ||
295 | |||
296 | /* | ||
297 | * 268435455 == 137439 MB or 28bit limit | ||
298 | * 320173056 == 163929 MB or 48bit addressing | ||
299 | * 1073741822 == 549756 MB or 48bit addressing fake drive | ||
300 | */ | ||
301 | |||
302 | static ide_startstop_t ide_do_rw_disk (ide_drive_t *drive, struct request *rq, sector_t block) | ||
303 | { | ||
304 | ide_hwif_t *hwif = HWIF(drive); | ||
305 | |||
306 | BUG_ON(drive->blocked); | ||
307 | |||
308 | if (!blk_fs_request(rq)) { | ||
309 | blk_dump_rq_flags(rq, "ide_do_rw_disk - bad command"); | ||
310 | ide_end_request(drive, 0, 0); | ||
311 | return ide_stopped; | ||
312 | } | ||
313 | |||
314 | pr_debug("%s: %sing: block=%llu, sectors=%lu, buffer=0x%08lx\n", | ||
315 | drive->name, rq_data_dir(rq) == READ ? "read" : "writ", | ||
316 | block, rq->nr_sectors, (unsigned long)rq->buffer); | ||
317 | |||
318 | if (hwif->rw_disk) | ||
319 | hwif->rw_disk(drive, rq); | ||
320 | |||
321 | return __ide_do_rw_disk(drive, rq, block); | ||
322 | } | ||
323 | |||
324 | /* | ||
325 | * Queries for true maximum capacity of the drive. | ||
326 | * Returns maximum LBA address (> 0) of the drive, 0 if failed. | ||
327 | */ | ||
328 | static unsigned long idedisk_read_native_max_address(ide_drive_t *drive) | ||
329 | { | ||
330 | ide_task_t args; | ||
331 | unsigned long addr = 0; | ||
332 | |||
333 | /* Create IDE/ATA command request structure */ | ||
334 | memset(&args, 0, sizeof(ide_task_t)); | ||
335 | args.tfRegister[IDE_SELECT_OFFSET] = 0x40; | ||
336 | args.tfRegister[IDE_COMMAND_OFFSET] = WIN_READ_NATIVE_MAX; | ||
337 | args.command_type = IDE_DRIVE_TASK_NO_DATA; | ||
338 | args.handler = &task_no_data_intr; | ||
339 | /* submit command request */ | ||
340 | ide_raw_taskfile(drive, &args, NULL); | ||
341 | |||
342 | /* if OK, compute maximum address value */ | ||
343 | if ((args.tfRegister[IDE_STATUS_OFFSET] & 0x01) == 0) { | ||
344 | addr = ((args.tfRegister[IDE_SELECT_OFFSET] & 0x0f) << 24) | ||
345 | | ((args.tfRegister[ IDE_HCYL_OFFSET] ) << 16) | ||
346 | | ((args.tfRegister[ IDE_LCYL_OFFSET] ) << 8) | ||
347 | | ((args.tfRegister[IDE_SECTOR_OFFSET] )); | ||
348 | addr++; /* since the return value is (maxlba - 1), we add 1 */ | ||
349 | } | ||
350 | return addr; | ||
351 | } | ||
352 | |||
353 | static unsigned long long idedisk_read_native_max_address_ext(ide_drive_t *drive) | ||
354 | { | ||
355 | ide_task_t args; | ||
356 | unsigned long long addr = 0; | ||
357 | |||
358 | /* Create IDE/ATA command request structure */ | ||
359 | memset(&args, 0, sizeof(ide_task_t)); | ||
360 | |||
361 | args.tfRegister[IDE_SELECT_OFFSET] = 0x40; | ||
362 | args.tfRegister[IDE_COMMAND_OFFSET] = WIN_READ_NATIVE_MAX_EXT; | ||
363 | args.command_type = IDE_DRIVE_TASK_NO_DATA; | ||
364 | args.handler = &task_no_data_intr; | ||
365 | /* submit command request */ | ||
366 | ide_raw_taskfile(drive, &args, NULL); | ||
367 | |||
368 | /* if OK, compute maximum address value */ | ||
369 | if ((args.tfRegister[IDE_STATUS_OFFSET] & 0x01) == 0) { | ||
370 | u32 high = (args.hobRegister[IDE_HCYL_OFFSET] << 16) | | ||
371 | (args.hobRegister[IDE_LCYL_OFFSET] << 8) | | ||
372 | args.hobRegister[IDE_SECTOR_OFFSET]; | ||
373 | u32 low = ((args.tfRegister[IDE_HCYL_OFFSET])<<16) | | ||
374 | ((args.tfRegister[IDE_LCYL_OFFSET])<<8) | | ||
375 | (args.tfRegister[IDE_SECTOR_OFFSET]); | ||
376 | addr = ((__u64)high << 24) | low; | ||
377 | addr++; /* since the return value is (maxlba - 1), we add 1 */ | ||
378 | } | ||
379 | return addr; | ||
380 | } | ||
381 | |||
382 | /* | ||
383 | * Sets maximum virtual LBA address of the drive. | ||
384 | * Returns new maximum virtual LBA address (> 0) or 0 on failure. | ||
385 | */ | ||
386 | static unsigned long idedisk_set_max_address(ide_drive_t *drive, unsigned long addr_req) | ||
387 | { | ||
388 | ide_task_t args; | ||
389 | unsigned long addr_set = 0; | ||
390 | |||
391 | addr_req--; | ||
392 | /* Create IDE/ATA command request structure */ | ||
393 | memset(&args, 0, sizeof(ide_task_t)); | ||
394 | args.tfRegister[IDE_SECTOR_OFFSET] = ((addr_req >> 0) & 0xff); | ||
395 | args.tfRegister[IDE_LCYL_OFFSET] = ((addr_req >> 8) & 0xff); | ||
396 | args.tfRegister[IDE_HCYL_OFFSET] = ((addr_req >> 16) & 0xff); | ||
397 | args.tfRegister[IDE_SELECT_OFFSET] = ((addr_req >> 24) & 0x0f) | 0x40; | ||
398 | args.tfRegister[IDE_COMMAND_OFFSET] = WIN_SET_MAX; | ||
399 | args.command_type = IDE_DRIVE_TASK_NO_DATA; | ||
400 | args.handler = &task_no_data_intr; | ||
401 | /* submit command request */ | ||
402 | ide_raw_taskfile(drive, &args, NULL); | ||
403 | /* if OK, read new maximum address value */ | ||
404 | if ((args.tfRegister[IDE_STATUS_OFFSET] & 0x01) == 0) { | ||
405 | addr_set = ((args.tfRegister[IDE_SELECT_OFFSET] & 0x0f) << 24) | ||
406 | | ((args.tfRegister[ IDE_HCYL_OFFSET] ) << 16) | ||
407 | | ((args.tfRegister[ IDE_LCYL_OFFSET] ) << 8) | ||
408 | | ((args.tfRegister[IDE_SECTOR_OFFSET] )); | ||
409 | addr_set++; | ||
410 | } | ||
411 | return addr_set; | ||
412 | } | ||
413 | |||
414 | static unsigned long long idedisk_set_max_address_ext(ide_drive_t *drive, unsigned long long addr_req) | ||
415 | { | ||
416 | ide_task_t args; | ||
417 | unsigned long long addr_set = 0; | ||
418 | |||
419 | addr_req--; | ||
420 | /* Create IDE/ATA command request structure */ | ||
421 | memset(&args, 0, sizeof(ide_task_t)); | ||
422 | args.tfRegister[IDE_SECTOR_OFFSET] = ((addr_req >> 0) & 0xff); | ||
423 | args.tfRegister[IDE_LCYL_OFFSET] = ((addr_req >>= 8) & 0xff); | ||
424 | args.tfRegister[IDE_HCYL_OFFSET] = ((addr_req >>= 8) & 0xff); | ||
425 | args.tfRegister[IDE_SELECT_OFFSET] = 0x40; | ||
426 | args.tfRegister[IDE_COMMAND_OFFSET] = WIN_SET_MAX_EXT; | ||
427 | args.hobRegister[IDE_SECTOR_OFFSET] = (addr_req >>= 8) & 0xff; | ||
428 | args.hobRegister[IDE_LCYL_OFFSET] = (addr_req >>= 8) & 0xff; | ||
429 | args.hobRegister[IDE_HCYL_OFFSET] = (addr_req >>= 8) & 0xff; | ||
430 | args.hobRegister[IDE_SELECT_OFFSET] = 0x40; | ||
431 | args.hobRegister[IDE_CONTROL_OFFSET_HOB]= (drive->ctl|0x80); | ||
432 | args.command_type = IDE_DRIVE_TASK_NO_DATA; | ||
433 | args.handler = &task_no_data_intr; | ||
434 | /* submit command request */ | ||
435 | ide_raw_taskfile(drive, &args, NULL); | ||
436 | /* if OK, compute maximum address value */ | ||
437 | if ((args.tfRegister[IDE_STATUS_OFFSET] & 0x01) == 0) { | ||
438 | u32 high = (args.hobRegister[IDE_HCYL_OFFSET] << 16) | | ||
439 | (args.hobRegister[IDE_LCYL_OFFSET] << 8) | | ||
440 | args.hobRegister[IDE_SECTOR_OFFSET]; | ||
441 | u32 low = ((args.tfRegister[IDE_HCYL_OFFSET])<<16) | | ||
442 | ((args.tfRegister[IDE_LCYL_OFFSET])<<8) | | ||
443 | (args.tfRegister[IDE_SECTOR_OFFSET]); | ||
444 | addr_set = ((__u64)high << 24) | low; | ||
445 | addr_set++; | ||
446 | } | ||
447 | return addr_set; | ||
448 | } | ||
449 | |||
450 | static unsigned long long sectors_to_MB(unsigned long long n) | ||
451 | { | ||
452 | n <<= 9; /* make it bytes */ | ||
453 | do_div(n, 1000000); /* make it MB */ | ||
454 | return n; | ||
455 | } | ||
456 | |||
457 | /* | ||
458 | * Bits 10 of command_set_1 and cfs_enable_1 must be equal, | ||
459 | * so on non-buggy drives we need test only one. | ||
460 | * However, we should also check whether these fields are valid. | ||
461 | */ | ||
462 | static inline int idedisk_supports_hpa(const struct hd_driveid *id) | ||
463 | { | ||
464 | return (id->command_set_1 & 0x0400) && (id->cfs_enable_1 & 0x0400); | ||
465 | } | ||
466 | |||
467 | /* | ||
468 | * The same here. | ||
469 | */ | ||
470 | static inline int idedisk_supports_lba48(const struct hd_driveid *id) | ||
471 | { | ||
472 | return (id->command_set_2 & 0x0400) && (id->cfs_enable_2 & 0x0400) | ||
473 | && id->lba_capacity_2; | ||
474 | } | ||
475 | |||
476 | static inline void idedisk_check_hpa(ide_drive_t *drive) | ||
477 | { | ||
478 | unsigned long long capacity, set_max; | ||
479 | int lba48 = idedisk_supports_lba48(drive->id); | ||
480 | |||
481 | capacity = drive->capacity64; | ||
482 | if (lba48) | ||
483 | set_max = idedisk_read_native_max_address_ext(drive); | ||
484 | else | ||
485 | set_max = idedisk_read_native_max_address(drive); | ||
486 | |||
487 | if (set_max <= capacity) | ||
488 | return; | ||
489 | |||
490 | printk(KERN_INFO "%s: Host Protected Area detected.\n" | ||
491 | "\tcurrent capacity is %llu sectors (%llu MB)\n" | ||
492 | "\tnative capacity is %llu sectors (%llu MB)\n", | ||
493 | drive->name, | ||
494 | capacity, sectors_to_MB(capacity), | ||
495 | set_max, sectors_to_MB(set_max)); | ||
496 | |||
497 | if (lba48) | ||
498 | set_max = idedisk_set_max_address_ext(drive, set_max); | ||
499 | else | ||
500 | set_max = idedisk_set_max_address(drive, set_max); | ||
501 | if (set_max) { | ||
502 | drive->capacity64 = set_max; | ||
503 | printk(KERN_INFO "%s: Host Protected Area disabled.\n", | ||
504 | drive->name); | ||
505 | } | ||
506 | } | ||
507 | |||
508 | /* | ||
509 | * Compute drive->capacity, the full capacity of the drive | ||
510 | * Called with drive->id != NULL. | ||
511 | * | ||
512 | * To compute capacity, this uses either of | ||
513 | * | ||
514 | * 1. CHS value set by user (whatever user sets will be trusted) | ||
515 | * 2. LBA value from target drive (require new ATA feature) | ||
516 | * 3. LBA value from system BIOS (new one is OK, old one may break) | ||
517 | * 4. CHS value from system BIOS (traditional style) | ||
518 | * | ||
519 | * in above order (i.e., if value of higher priority is available, | ||
520 | * reset will be ignored). | ||
521 | */ | ||
522 | static void init_idedisk_capacity (ide_drive_t *drive) | ||
523 | { | ||
524 | struct hd_driveid *id = drive->id; | ||
525 | /* | ||
526 | * If this drive supports the Host Protected Area feature set, | ||
527 | * then we may need to change our opinion about the drive's capacity. | ||
528 | */ | ||
529 | int hpa = idedisk_supports_hpa(id); | ||
530 | |||
531 | if (idedisk_supports_lba48(id)) { | ||
532 | /* drive speaks 48-bit LBA */ | ||
533 | drive->select.b.lba = 1; | ||
534 | drive->capacity64 = id->lba_capacity_2; | ||
535 | if (hpa) | ||
536 | idedisk_check_hpa(drive); | ||
537 | } else if ((id->capability & 2) && lba_capacity_is_ok(id)) { | ||
538 | /* drive speaks 28-bit LBA */ | ||
539 | drive->select.b.lba = 1; | ||
540 | drive->capacity64 = id->lba_capacity; | ||
541 | if (hpa) | ||
542 | idedisk_check_hpa(drive); | ||
543 | } else { | ||
544 | /* drive speaks boring old 28-bit CHS */ | ||
545 | drive->capacity64 = drive->cyl * drive->head * drive->sect; | ||
546 | } | ||
547 | } | ||
548 | |||
549 | static sector_t idedisk_capacity (ide_drive_t *drive) | ||
550 | { | ||
551 | return drive->capacity64 - drive->sect0; | ||
552 | } | ||
553 | |||
554 | #ifdef CONFIG_PROC_FS | ||
555 | |||
556 | static int smart_enable(ide_drive_t *drive) | ||
557 | { | ||
558 | ide_task_t args; | ||
559 | |||
560 | memset(&args, 0, sizeof(ide_task_t)); | ||
561 | args.tfRegister[IDE_FEATURE_OFFSET] = SMART_ENABLE; | ||
562 | args.tfRegister[IDE_LCYL_OFFSET] = SMART_LCYL_PASS; | ||
563 | args.tfRegister[IDE_HCYL_OFFSET] = SMART_HCYL_PASS; | ||
564 | args.tfRegister[IDE_COMMAND_OFFSET] = WIN_SMART; | ||
565 | args.command_type = IDE_DRIVE_TASK_NO_DATA; | ||
566 | args.handler = &task_no_data_intr; | ||
567 | return ide_raw_taskfile(drive, &args, NULL); | ||
568 | } | ||
569 | |||
570 | static int get_smart_values(ide_drive_t *drive, u8 *buf) | ||
571 | { | ||
572 | ide_task_t args; | ||
573 | |||
574 | memset(&args, 0, sizeof(ide_task_t)); | ||
575 | args.tfRegister[IDE_FEATURE_OFFSET] = SMART_READ_VALUES; | ||
576 | args.tfRegister[IDE_NSECTOR_OFFSET] = 0x01; | ||
577 | args.tfRegister[IDE_LCYL_OFFSET] = SMART_LCYL_PASS; | ||
578 | args.tfRegister[IDE_HCYL_OFFSET] = SMART_HCYL_PASS; | ||
579 | args.tfRegister[IDE_COMMAND_OFFSET] = WIN_SMART; | ||
580 | args.command_type = IDE_DRIVE_TASK_IN; | ||
581 | args.data_phase = TASKFILE_IN; | ||
582 | args.handler = &task_in_intr; | ||
583 | (void) smart_enable(drive); | ||
584 | return ide_raw_taskfile(drive, &args, buf); | ||
585 | } | ||
586 | |||
587 | static int get_smart_thresholds(ide_drive_t *drive, u8 *buf) | ||
588 | { | ||
589 | ide_task_t args; | ||
590 | memset(&args, 0, sizeof(ide_task_t)); | ||
591 | args.tfRegister[IDE_FEATURE_OFFSET] = SMART_READ_THRESHOLDS; | ||
592 | args.tfRegister[IDE_NSECTOR_OFFSET] = 0x01; | ||
593 | args.tfRegister[IDE_LCYL_OFFSET] = SMART_LCYL_PASS; | ||
594 | args.tfRegister[IDE_HCYL_OFFSET] = SMART_HCYL_PASS; | ||
595 | args.tfRegister[IDE_COMMAND_OFFSET] = WIN_SMART; | ||
596 | args.command_type = IDE_DRIVE_TASK_IN; | ||
597 | args.data_phase = TASKFILE_IN; | ||
598 | args.handler = &task_in_intr; | ||
599 | (void) smart_enable(drive); | ||
600 | return ide_raw_taskfile(drive, &args, buf); | ||
601 | } | ||
602 | |||
603 | static int proc_idedisk_read_cache | ||
604 | (char *page, char **start, off_t off, int count, int *eof, void *data) | ||
605 | { | ||
606 | ide_drive_t *drive = (ide_drive_t *) data; | ||
607 | char *out = page; | ||
608 | int len; | ||
609 | |||
610 | if (drive->id_read) | ||
611 | len = sprintf(out,"%i\n", drive->id->buf_size / 2); | ||
612 | else | ||
613 | len = sprintf(out,"(none)\n"); | ||
614 | PROC_IDE_READ_RETURN(page,start,off,count,eof,len); | ||
615 | } | ||
616 | |||
617 | static int proc_idedisk_read_capacity | ||
618 | (char *page, char **start, off_t off, int count, int *eof, void *data) | ||
619 | { | ||
620 | ide_drive_t*drive = (ide_drive_t *)data; | ||
621 | int len; | ||
622 | |||
623 | len = sprintf(page,"%llu\n", (long long)idedisk_capacity(drive)); | ||
624 | PROC_IDE_READ_RETURN(page,start,off,count,eof,len); | ||
625 | } | ||
626 | |||
627 | static int proc_idedisk_read_smart_thresholds | ||
628 | (char *page, char **start, off_t off, int count, int *eof, void *data) | ||
629 | { | ||
630 | ide_drive_t *drive = (ide_drive_t *)data; | ||
631 | int len = 0, i = 0; | ||
632 | |||
633 | if (!get_smart_thresholds(drive, page)) { | ||
634 | unsigned short *val = (unsigned short *) page; | ||
635 | char *out = ((char *)val) + (SECTOR_WORDS * 4); | ||
636 | page = out; | ||
637 | do { | ||
638 | out += sprintf(out, "%04x%c", le16_to_cpu(*val), (++i & 7) ? ' ' : '\n'); | ||
639 | val += 1; | ||
640 | } while (i < (SECTOR_WORDS * 2)); | ||
641 | len = out - page; | ||
642 | } | ||
643 | PROC_IDE_READ_RETURN(page,start,off,count,eof,len); | ||
644 | } | ||
645 | |||
646 | static int proc_idedisk_read_smart_values | ||
647 | (char *page, char **start, off_t off, int count, int *eof, void *data) | ||
648 | { | ||
649 | ide_drive_t *drive = (ide_drive_t *)data; | ||
650 | int len = 0, i = 0; | ||
651 | |||
652 | if (!get_smart_values(drive, page)) { | ||
653 | unsigned short *val = (unsigned short *) page; | ||
654 | char *out = ((char *)val) + (SECTOR_WORDS * 4); | ||
655 | page = out; | ||
656 | do { | ||
657 | out += sprintf(out, "%04x%c", le16_to_cpu(*val), (++i & 7) ? ' ' : '\n'); | ||
658 | val += 1; | ||
659 | } while (i < (SECTOR_WORDS * 2)); | ||
660 | len = out - page; | ||
661 | } | ||
662 | PROC_IDE_READ_RETURN(page,start,off,count,eof,len); | ||
663 | } | ||
664 | |||
665 | static ide_proc_entry_t idedisk_proc[] = { | ||
666 | { "cache", S_IFREG|S_IRUGO, proc_idedisk_read_cache, NULL }, | ||
667 | { "capacity", S_IFREG|S_IRUGO, proc_idedisk_read_capacity, NULL }, | ||
668 | { "geometry", S_IFREG|S_IRUGO, proc_ide_read_geometry, NULL }, | ||
669 | { "smart_values", S_IFREG|S_IRUSR, proc_idedisk_read_smart_values, NULL }, | ||
670 | { "smart_thresholds", S_IFREG|S_IRUSR, proc_idedisk_read_smart_thresholds, NULL }, | ||
671 | { NULL, 0, NULL, NULL } | ||
672 | }; | ||
673 | |||
674 | #else | ||
675 | |||
676 | #define idedisk_proc NULL | ||
677 | |||
678 | #endif /* CONFIG_PROC_FS */ | ||
679 | |||
680 | static void idedisk_end_flush(request_queue_t *q, struct request *flush_rq) | ||
681 | { | ||
682 | ide_drive_t *drive = q->queuedata; | ||
683 | struct request *rq = flush_rq->end_io_data; | ||
684 | int good_sectors = rq->hard_nr_sectors; | ||
685 | int bad_sectors; | ||
686 | sector_t sector; | ||
687 | |||
688 | if (flush_rq->errors & ABRT_ERR) { | ||
689 | printk(KERN_ERR "%s: barrier support doesn't work\n", drive->name); | ||
690 | blk_queue_ordered(drive->queue, QUEUE_ORDERED_NONE); | ||
691 | blk_queue_issue_flush_fn(drive->queue, NULL); | ||
692 | good_sectors = 0; | ||
693 | } else if (flush_rq->errors) { | ||
694 | good_sectors = 0; | ||
695 | if (blk_barrier_preflush(rq)) { | ||
696 | sector = ide_get_error_location(drive,flush_rq->buffer); | ||
697 | if ((sector >= rq->hard_sector) && | ||
698 | (sector < rq->hard_sector + rq->hard_nr_sectors)) | ||
699 | good_sectors = sector - rq->hard_sector; | ||
700 | } | ||
701 | } | ||
702 | |||
703 | if (flush_rq->errors) | ||
704 | printk(KERN_ERR "%s: failed barrier write: " | ||
705 | "sector=%Lx(good=%d/bad=%d)\n", | ||
706 | drive->name, (unsigned long long)rq->sector, | ||
707 | good_sectors, | ||
708 | (int) (rq->hard_nr_sectors-good_sectors)); | ||
709 | |||
710 | bad_sectors = rq->hard_nr_sectors - good_sectors; | ||
711 | |||
712 | if (good_sectors) | ||
713 | __ide_end_request(drive, rq, 1, good_sectors); | ||
714 | if (bad_sectors) | ||
715 | __ide_end_request(drive, rq, 0, bad_sectors); | ||
716 | } | ||
717 | |||
718 | static int idedisk_prepare_flush(request_queue_t *q, struct request *rq) | ||
719 | { | ||
720 | ide_drive_t *drive = q->queuedata; | ||
721 | |||
722 | if (!drive->wcache) | ||
723 | return 0; | ||
724 | |||
725 | memset(rq->cmd, 0, sizeof(rq->cmd)); | ||
726 | |||
727 | if (ide_id_has_flush_cache_ext(drive->id) && | ||
728 | (drive->capacity64 >= (1UL << 28))) | ||
729 | rq->cmd[0] = WIN_FLUSH_CACHE_EXT; | ||
730 | else | ||
731 | rq->cmd[0] = WIN_FLUSH_CACHE; | ||
732 | |||
733 | |||
734 | rq->flags |= REQ_DRIVE_TASK | REQ_SOFTBARRIER; | ||
735 | rq->buffer = rq->cmd; | ||
736 | return 1; | ||
737 | } | ||
738 | |||
739 | static int idedisk_issue_flush(request_queue_t *q, struct gendisk *disk, | ||
740 | sector_t *error_sector) | ||
741 | { | ||
742 | ide_drive_t *drive = q->queuedata; | ||
743 | struct request *rq; | ||
744 | int ret; | ||
745 | |||
746 | if (!drive->wcache) | ||
747 | return 0; | ||
748 | |||
749 | rq = blk_get_request(q, WRITE, __GFP_WAIT); | ||
750 | |||
751 | idedisk_prepare_flush(q, rq); | ||
752 | |||
753 | ret = blk_execute_rq(q, disk, rq); | ||
754 | |||
755 | /* | ||
756 | * if we failed and caller wants error offset, get it | ||
757 | */ | ||
758 | if (ret && error_sector) | ||
759 | *error_sector = ide_get_error_location(drive, rq->cmd); | ||
760 | |||
761 | blk_put_request(rq); | ||
762 | return ret; | ||
763 | } | ||
764 | |||
765 | /* | ||
766 | * This is tightly woven into the driver->do_special can not touch. | ||
767 | * DON'T do it again until a total personality rewrite is committed. | ||
768 | */ | ||
769 | static int set_multcount(ide_drive_t *drive, int arg) | ||
770 | { | ||
771 | struct request rq; | ||
772 | |||
773 | if (drive->special.b.set_multmode) | ||
774 | return -EBUSY; | ||
775 | ide_init_drive_cmd (&rq); | ||
776 | rq.flags = REQ_DRIVE_CMD; | ||
777 | drive->mult_req = arg; | ||
778 | drive->special.b.set_multmode = 1; | ||
779 | (void) ide_do_drive_cmd (drive, &rq, ide_wait); | ||
780 | return (drive->mult_count == arg) ? 0 : -EIO; | ||
781 | } | ||
782 | |||
783 | static int set_nowerr(ide_drive_t *drive, int arg) | ||
784 | { | ||
785 | if (ide_spin_wait_hwgroup(drive)) | ||
786 | return -EBUSY; | ||
787 | drive->nowerr = arg; | ||
788 | drive->bad_wstat = arg ? BAD_R_STAT : BAD_W_STAT; | ||
789 | spin_unlock_irq(&ide_lock); | ||
790 | return 0; | ||
791 | } | ||
792 | |||
793 | static int write_cache(ide_drive_t *drive, int arg) | ||
794 | { | ||
795 | ide_task_t args; | ||
796 | int err; | ||
797 | |||
798 | if (!ide_id_has_flush_cache(drive->id)) | ||
799 | return 1; | ||
800 | |||
801 | memset(&args, 0, sizeof(ide_task_t)); | ||
802 | args.tfRegister[IDE_FEATURE_OFFSET] = (arg) ? | ||
803 | SETFEATURES_EN_WCACHE : SETFEATURES_DIS_WCACHE; | ||
804 | args.tfRegister[IDE_COMMAND_OFFSET] = WIN_SETFEATURES; | ||
805 | args.command_type = IDE_DRIVE_TASK_NO_DATA; | ||
806 | args.handler = &task_no_data_intr; | ||
807 | |||
808 | err = ide_raw_taskfile(drive, &args, NULL); | ||
809 | if (err) | ||
810 | return err; | ||
811 | |||
812 | drive->wcache = arg; | ||
813 | return 0; | ||
814 | } | ||
815 | |||
816 | static int do_idedisk_flushcache (ide_drive_t *drive) | ||
817 | { | ||
818 | ide_task_t args; | ||
819 | |||
820 | memset(&args, 0, sizeof(ide_task_t)); | ||
821 | if (ide_id_has_flush_cache_ext(drive->id)) | ||
822 | args.tfRegister[IDE_COMMAND_OFFSET] = WIN_FLUSH_CACHE_EXT; | ||
823 | else | ||
824 | args.tfRegister[IDE_COMMAND_OFFSET] = WIN_FLUSH_CACHE; | ||
825 | args.command_type = IDE_DRIVE_TASK_NO_DATA; | ||
826 | args.handler = &task_no_data_intr; | ||
827 | return ide_raw_taskfile(drive, &args, NULL); | ||
828 | } | ||
829 | |||
830 | static int set_acoustic (ide_drive_t *drive, int arg) | ||
831 | { | ||
832 | ide_task_t args; | ||
833 | |||
834 | memset(&args, 0, sizeof(ide_task_t)); | ||
835 | args.tfRegister[IDE_FEATURE_OFFSET] = (arg) ? SETFEATURES_EN_AAM : | ||
836 | SETFEATURES_DIS_AAM; | ||
837 | args.tfRegister[IDE_NSECTOR_OFFSET] = arg; | ||
838 | args.tfRegister[IDE_COMMAND_OFFSET] = WIN_SETFEATURES; | ||
839 | args.command_type = IDE_DRIVE_TASK_NO_DATA; | ||
840 | args.handler = &task_no_data_intr; | ||
841 | ide_raw_taskfile(drive, &args, NULL); | ||
842 | drive->acoustic = arg; | ||
843 | return 0; | ||
844 | } | ||
845 | |||
846 | /* | ||
847 | * drive->addressing: | ||
848 | * 0: 28-bit | ||
849 | * 1: 48-bit | ||
850 | * 2: 48-bit capable doing 28-bit | ||
851 | */ | ||
852 | static int set_lba_addressing(ide_drive_t *drive, int arg) | ||
853 | { | ||
854 | drive->addressing = 0; | ||
855 | |||
856 | if (HWIF(drive)->no_lba48) | ||
857 | return 0; | ||
858 | |||
859 | if (!idedisk_supports_lba48(drive->id)) | ||
860 | return -EIO; | ||
861 | drive->addressing = arg; | ||
862 | return 0; | ||
863 | } | ||
864 | |||
865 | static void idedisk_add_settings(ide_drive_t *drive) | ||
866 | { | ||
867 | struct hd_driveid *id = drive->id; | ||
868 | |||
869 | ide_add_setting(drive, "bios_cyl", SETTING_RW, -1, -1, TYPE_INT, 0, 65535, 1, 1, &drive->bios_cyl, NULL); | ||
870 | ide_add_setting(drive, "bios_head", SETTING_RW, -1, -1, TYPE_BYTE, 0, 255, 1, 1, &drive->bios_head, NULL); | ||
871 | ide_add_setting(drive, "bios_sect", SETTING_RW, -1, -1, TYPE_BYTE, 0, 63, 1, 1, &drive->bios_sect, NULL); | ||
872 | ide_add_setting(drive, "address", SETTING_RW, HDIO_GET_ADDRESS, HDIO_SET_ADDRESS, TYPE_INTA, 0, 2, 1, 1, &drive->addressing, set_lba_addressing); | ||
873 | ide_add_setting(drive, "bswap", SETTING_READ, -1, -1, TYPE_BYTE, 0, 1, 1, 1, &drive->bswap, NULL); | ||
874 | ide_add_setting(drive, "multcount", id ? SETTING_RW : SETTING_READ, HDIO_GET_MULTCOUNT, HDIO_SET_MULTCOUNT, TYPE_BYTE, 0, id ? id->max_multsect : 0, 1, 1, &drive->mult_count, set_multcount); | ||
875 | ide_add_setting(drive, "nowerr", SETTING_RW, HDIO_GET_NOWERR, HDIO_SET_NOWERR, TYPE_BYTE, 0, 1, 1, 1, &drive->nowerr, set_nowerr); | ||
876 | ide_add_setting(drive, "lun", SETTING_RW, -1, -1, TYPE_INT, 0, 7, 1, 1, &drive->lun, NULL); | ||
877 | ide_add_setting(drive, "wcache", SETTING_RW, HDIO_GET_WCACHE, HDIO_SET_WCACHE, TYPE_BYTE, 0, 1, 1, 1, &drive->wcache, write_cache); | ||
878 | ide_add_setting(drive, "acoustic", SETTING_RW, HDIO_GET_ACOUSTIC, HDIO_SET_ACOUSTIC, TYPE_BYTE, 0, 254, 1, 1, &drive->acoustic, set_acoustic); | ||
879 | ide_add_setting(drive, "failures", SETTING_RW, -1, -1, TYPE_INT, 0, 65535, 1, 1, &drive->failures, NULL); | ||
880 | ide_add_setting(drive, "max_failures", SETTING_RW, -1, -1, TYPE_INT, 0, 65535, 1, 1, &drive->max_failures, NULL); | ||
881 | } | ||
882 | |||
883 | static void idedisk_setup (ide_drive_t *drive) | ||
884 | { | ||
885 | struct hd_driveid *id = drive->id; | ||
886 | unsigned long long capacity; | ||
887 | int barrier; | ||
888 | |||
889 | idedisk_add_settings(drive); | ||
890 | |||
891 | if (drive->id_read == 0) | ||
892 | return; | ||
893 | |||
894 | /* | ||
895 | * CompactFlash cards and their brethern look just like hard drives | ||
896 | * to us, but they are removable and don't have a doorlock mechanism. | ||
897 | */ | ||
898 | if (drive->removable && !(drive->is_flash)) { | ||
899 | /* | ||
900 | * Removable disks (eg. SYQUEST); ignore 'WD' drives | ||
901 | */ | ||
902 | if (id->model[0] != 'W' || id->model[1] != 'D') { | ||
903 | drive->doorlocking = 1; | ||
904 | } | ||
905 | } | ||
906 | |||
907 | (void)set_lba_addressing(drive, 1); | ||
908 | |||
909 | if (drive->addressing == 1) { | ||
910 | ide_hwif_t *hwif = HWIF(drive); | ||
911 | int max_s = 2048; | ||
912 | |||
913 | if (max_s > hwif->rqsize) | ||
914 | max_s = hwif->rqsize; | ||
915 | |||
916 | blk_queue_max_sectors(drive->queue, max_s); | ||
917 | } | ||
918 | |||
919 | printk(KERN_INFO "%s: max request size: %dKiB\n", drive->name, drive->queue->max_sectors / 2); | ||
920 | |||
921 | /* calculate drive capacity, and select LBA if possible */ | ||
922 | init_idedisk_capacity (drive); | ||
923 | |||
924 | /* limit drive capacity to 137GB if LBA48 cannot be used */ | ||
925 | if (drive->addressing == 0 && drive->capacity64 > 1ULL << 28) { | ||
926 | printk(KERN_WARNING "%s: cannot use LBA48 - full capacity " | ||
927 | "%llu sectors (%llu MB)\n", | ||
928 | drive->name, (unsigned long long)drive->capacity64, | ||
929 | sectors_to_MB(drive->capacity64)); | ||
930 | drive->capacity64 = 1ULL << 28; | ||
931 | } | ||
932 | |||
933 | if (drive->hwif->no_lba48_dma && drive->addressing) { | ||
934 | if (drive->capacity64 > 1ULL << 28) { | ||
935 | printk(KERN_INFO "%s: cannot use LBA48 DMA - PIO mode will" | ||
936 | " be used for accessing sectors > %u\n", | ||
937 | drive->name, 1 << 28); | ||
938 | } else | ||
939 | drive->addressing = 0; | ||
940 | } | ||
941 | |||
942 | /* | ||
943 | * if possible, give fdisk access to more of the drive, | ||
944 | * by correcting bios_cyls: | ||
945 | */ | ||
946 | capacity = idedisk_capacity (drive); | ||
947 | if (!drive->forced_geom) { | ||
948 | |||
949 | if (idedisk_supports_lba48(drive->id)) { | ||
950 | /* compatibility */ | ||
951 | drive->bios_sect = 63; | ||
952 | drive->bios_head = 255; | ||
953 | } | ||
954 | |||
955 | if (drive->bios_sect && drive->bios_head) { | ||
956 | unsigned int cap0 = capacity; /* truncate to 32 bits */ | ||
957 | unsigned int cylsz, cyl; | ||
958 | |||
959 | if (cap0 != capacity) | ||
960 | drive->bios_cyl = 65535; | ||
961 | else { | ||
962 | cylsz = drive->bios_sect * drive->bios_head; | ||
963 | cyl = cap0 / cylsz; | ||
964 | if (cyl > 65535) | ||
965 | cyl = 65535; | ||
966 | if (cyl > drive->bios_cyl) | ||
967 | drive->bios_cyl = cyl; | ||
968 | } | ||
969 | } | ||
970 | } | ||
971 | printk(KERN_INFO "%s: %llu sectors (%llu MB)", | ||
972 | drive->name, capacity, sectors_to_MB(capacity)); | ||
973 | |||
974 | /* Only print cache size when it was specified */ | ||
975 | if (id->buf_size) | ||
976 | printk (" w/%dKiB Cache", id->buf_size/2); | ||
977 | |||
978 | printk(", CHS=%d/%d/%d", | ||
979 | drive->bios_cyl, drive->bios_head, drive->bios_sect); | ||
980 | if (drive->using_dma) | ||
981 | ide_dma_verbose(drive); | ||
982 | printk("\n"); | ||
983 | |||
984 | drive->no_io_32bit = id->dword_io ? 1 : 0; | ||
985 | |||
986 | /* write cache enabled? */ | ||
987 | if ((id->csfo & 1) || (id->cfs_enable_1 & (1 << 5))) | ||
988 | drive->wcache = 1; | ||
989 | |||
990 | write_cache(drive, 1); | ||
991 | |||
992 | /* | ||
993 | * We must avoid issuing commands a drive does not understand | ||
994 | * or we may crash it. We check flush cache is supported. We also | ||
995 | * check we have the LBA48 flush cache if the drive capacity is | ||
996 | * too large. By this time we have trimmed the drive capacity if | ||
997 | * LBA48 is not available so we don't need to recheck that. | ||
998 | */ | ||
999 | barrier = 0; | ||
1000 | if (ide_id_has_flush_cache(id)) | ||
1001 | barrier = 1; | ||
1002 | if (drive->addressing == 1) { | ||
1003 | /* Can't issue the correct flush ? */ | ||
1004 | if (capacity > (1ULL << 28) && !ide_id_has_flush_cache_ext(id)) | ||
1005 | barrier = 0; | ||
1006 | } | ||
1007 | |||
1008 | printk(KERN_INFO "%s: cache flushes %ssupported\n", | ||
1009 | drive->name, barrier ? "" : "not "); | ||
1010 | if (barrier) { | ||
1011 | blk_queue_ordered(drive->queue, QUEUE_ORDERED_FLUSH); | ||
1012 | drive->queue->prepare_flush_fn = idedisk_prepare_flush; | ||
1013 | drive->queue->end_flush_fn = idedisk_end_flush; | ||
1014 | blk_queue_issue_flush_fn(drive->queue, idedisk_issue_flush); | ||
1015 | } | ||
1016 | } | ||
1017 | |||
1018 | static void ide_cacheflush_p(ide_drive_t *drive) | ||
1019 | { | ||
1020 | if (!drive->wcache || !ide_id_has_flush_cache(drive->id)) | ||
1021 | return; | ||
1022 | |||
1023 | if (do_idedisk_flushcache(drive)) | ||
1024 | printk(KERN_INFO "%s: wcache flush failed!\n", drive->name); | ||
1025 | } | ||
1026 | |||
1027 | static int idedisk_cleanup (ide_drive_t *drive) | ||
1028 | { | ||
1029 | struct ide_disk_obj *idkp = drive->driver_data; | ||
1030 | struct gendisk *g = idkp->disk; | ||
1031 | |||
1032 | ide_cacheflush_p(drive); | ||
1033 | if (ide_unregister_subdriver(drive)) | ||
1034 | return 1; | ||
1035 | del_gendisk(g); | ||
1036 | |||
1037 | ide_disk_put(idkp); | ||
1038 | |||
1039 | return 0; | ||
1040 | } | ||
1041 | |||
1042 | static void ide_disk_release(struct kref *kref) | ||
1043 | { | ||
1044 | struct ide_disk_obj *idkp = to_ide_disk(kref); | ||
1045 | ide_drive_t *drive = idkp->drive; | ||
1046 | struct gendisk *g = idkp->disk; | ||
1047 | |||
1048 | drive->driver_data = NULL; | ||
1049 | drive->devfs_name[0] = '\0'; | ||
1050 | g->private_data = NULL; | ||
1051 | put_disk(g); | ||
1052 | kfree(idkp); | ||
1053 | } | ||
1054 | |||
1055 | static int idedisk_attach(ide_drive_t *drive); | ||
1056 | |||
1057 | static void ide_device_shutdown(struct device *dev) | ||
1058 | { | ||
1059 | ide_drive_t *drive = container_of(dev, ide_drive_t, gendev); | ||
1060 | |||
1061 | #ifdef CONFIG_ALPHA | ||
1062 | /* On Alpha, halt(8) doesn't actually turn the machine off, | ||
1063 | it puts you into the sort of firmware monitor. Typically, | ||
1064 | it's used to boot another kernel image, so it's not much | ||
1065 | different from reboot(8). Therefore, we don't need to | ||
1066 | spin down the disk in this case, especially since Alpha | ||
1067 | firmware doesn't handle disks in standby mode properly. | ||
1068 | On the other hand, it's reasonably safe to turn the power | ||
1069 | off when the shutdown process reaches the firmware prompt, | ||
1070 | as the firmware initialization takes rather long time - | ||
1071 | at least 10 seconds, which should be sufficient for | ||
1072 | the disk to expire its write cache. */ | ||
1073 | if (system_state != SYSTEM_POWER_OFF) { | ||
1074 | #else | ||
1075 | if (system_state == SYSTEM_RESTART) { | ||
1076 | #endif | ||
1077 | ide_cacheflush_p(drive); | ||
1078 | return; | ||
1079 | } | ||
1080 | |||
1081 | printk("Shutdown: %s\n", drive->name); | ||
1082 | dev->bus->suspend(dev, PMSG_SUSPEND); | ||
1083 | } | ||
1084 | |||
1085 | /* | ||
1086 | * IDE subdriver functions, registered with ide.c | ||
1087 | */ | ||
1088 | static ide_driver_t idedisk_driver = { | ||
1089 | .owner = THIS_MODULE, | ||
1090 | .gen_driver = { | ||
1091 | .shutdown = ide_device_shutdown, | ||
1092 | }, | ||
1093 | .name = "ide-disk", | ||
1094 | .version = IDEDISK_VERSION, | ||
1095 | .media = ide_disk, | ||
1096 | .busy = 0, | ||
1097 | .supports_dsc_overlap = 0, | ||
1098 | .cleanup = idedisk_cleanup, | ||
1099 | .do_request = ide_do_rw_disk, | ||
1100 | .end_request = ide_end_request, | ||
1101 | .error = __ide_error, | ||
1102 | .abort = __ide_abort, | ||
1103 | .proc = idedisk_proc, | ||
1104 | .attach = idedisk_attach, | ||
1105 | .drives = LIST_HEAD_INIT(idedisk_driver.drives), | ||
1106 | }; | ||
1107 | |||
1108 | static int idedisk_open(struct inode *inode, struct file *filp) | ||
1109 | { | ||
1110 | struct gendisk *disk = inode->i_bdev->bd_disk; | ||
1111 | struct ide_disk_obj *idkp; | ||
1112 | ide_drive_t *drive; | ||
1113 | |||
1114 | if (!(idkp = ide_disk_get(disk))) | ||
1115 | return -ENXIO; | ||
1116 | |||
1117 | drive = idkp->drive; | ||
1118 | |||
1119 | drive->usage++; | ||
1120 | if (drive->removable && drive->usage == 1) { | ||
1121 | ide_task_t args; | ||
1122 | memset(&args, 0, sizeof(ide_task_t)); | ||
1123 | args.tfRegister[IDE_COMMAND_OFFSET] = WIN_DOORLOCK; | ||
1124 | args.command_type = IDE_DRIVE_TASK_NO_DATA; | ||
1125 | args.handler = &task_no_data_intr; | ||
1126 | check_disk_change(inode->i_bdev); | ||
1127 | /* | ||
1128 | * Ignore the return code from door_lock, | ||
1129 | * since the open() has already succeeded, | ||
1130 | * and the door_lock is irrelevant at this point. | ||
1131 | */ | ||
1132 | if (drive->doorlocking && ide_raw_taskfile(drive, &args, NULL)) | ||
1133 | drive->doorlocking = 0; | ||
1134 | } | ||
1135 | return 0; | ||
1136 | } | ||
1137 | |||
1138 | static int idedisk_release(struct inode *inode, struct file *filp) | ||
1139 | { | ||
1140 | struct gendisk *disk = inode->i_bdev->bd_disk; | ||
1141 | struct ide_disk_obj *idkp = ide_disk_g(disk); | ||
1142 | ide_drive_t *drive = idkp->drive; | ||
1143 | |||
1144 | if (drive->usage == 1) | ||
1145 | ide_cacheflush_p(drive); | ||
1146 | if (drive->removable && drive->usage == 1) { | ||
1147 | ide_task_t args; | ||
1148 | memset(&args, 0, sizeof(ide_task_t)); | ||
1149 | args.tfRegister[IDE_COMMAND_OFFSET] = WIN_DOORUNLOCK; | ||
1150 | args.command_type = IDE_DRIVE_TASK_NO_DATA; | ||
1151 | args.handler = &task_no_data_intr; | ||
1152 | if (drive->doorlocking && ide_raw_taskfile(drive, &args, NULL)) | ||
1153 | drive->doorlocking = 0; | ||
1154 | } | ||
1155 | drive->usage--; | ||
1156 | |||
1157 | ide_disk_put(idkp); | ||
1158 | |||
1159 | return 0; | ||
1160 | } | ||
1161 | |||
1162 | static int idedisk_ioctl(struct inode *inode, struct file *file, | ||
1163 | unsigned int cmd, unsigned long arg) | ||
1164 | { | ||
1165 | struct block_device *bdev = inode->i_bdev; | ||
1166 | struct ide_disk_obj *idkp = ide_disk_g(bdev->bd_disk); | ||
1167 | return generic_ide_ioctl(idkp->drive, file, bdev, cmd, arg); | ||
1168 | } | ||
1169 | |||
1170 | static int idedisk_media_changed(struct gendisk *disk) | ||
1171 | { | ||
1172 | struct ide_disk_obj *idkp = ide_disk_g(disk); | ||
1173 | ide_drive_t *drive = idkp->drive; | ||
1174 | |||
1175 | /* do not scan partitions twice if this is a removable device */ | ||
1176 | if (drive->attach) { | ||
1177 | drive->attach = 0; | ||
1178 | return 0; | ||
1179 | } | ||
1180 | /* if removable, always assume it was changed */ | ||
1181 | return drive->removable; | ||
1182 | } | ||
1183 | |||
1184 | static int idedisk_revalidate_disk(struct gendisk *disk) | ||
1185 | { | ||
1186 | struct ide_disk_obj *idkp = ide_disk_g(disk); | ||
1187 | set_capacity(disk, idedisk_capacity(idkp->drive)); | ||
1188 | return 0; | ||
1189 | } | ||
1190 | |||
1191 | static struct block_device_operations idedisk_ops = { | ||
1192 | .owner = THIS_MODULE, | ||
1193 | .open = idedisk_open, | ||
1194 | .release = idedisk_release, | ||
1195 | .ioctl = idedisk_ioctl, | ||
1196 | .media_changed = idedisk_media_changed, | ||
1197 | .revalidate_disk= idedisk_revalidate_disk | ||
1198 | }; | ||
1199 | |||
1200 | MODULE_DESCRIPTION("ATA DISK Driver"); | ||
1201 | |||
1202 | static int idedisk_attach(ide_drive_t *drive) | ||
1203 | { | ||
1204 | struct ide_disk_obj *idkp; | ||
1205 | struct gendisk *g; | ||
1206 | |||
1207 | /* strstr("foo", "") is non-NULL */ | ||
1208 | if (!strstr("ide-disk", drive->driver_req)) | ||
1209 | goto failed; | ||
1210 | if (!drive->present) | ||
1211 | goto failed; | ||
1212 | if (drive->media != ide_disk) | ||
1213 | goto failed; | ||
1214 | |||
1215 | idkp = kmalloc(sizeof(*idkp), GFP_KERNEL); | ||
1216 | if (!idkp) | ||
1217 | goto failed; | ||
1218 | |||
1219 | g = alloc_disk(1 << PARTN_BITS); | ||
1220 | if (!g) | ||
1221 | goto out_free_idkp; | ||
1222 | |||
1223 | ide_init_disk(g, drive); | ||
1224 | |||
1225 | if (ide_register_subdriver(drive, &idedisk_driver)) { | ||
1226 | printk (KERN_ERR "ide-disk: %s: Failed to register the driver with ide.c\n", drive->name); | ||
1227 | goto out_put_disk; | ||
1228 | } | ||
1229 | |||
1230 | memset(idkp, 0, sizeof(*idkp)); | ||
1231 | |||
1232 | kref_init(&idkp->kref); | ||
1233 | |||
1234 | idkp->drive = drive; | ||
1235 | idkp->driver = &idedisk_driver; | ||
1236 | idkp->disk = g; | ||
1237 | |||
1238 | g->private_data = &idkp->driver; | ||
1239 | |||
1240 | drive->driver_data = idkp; | ||
1241 | |||
1242 | DRIVER(drive)->busy++; | ||
1243 | idedisk_setup(drive); | ||
1244 | if ((!drive->head || drive->head > 16) && !drive->select.b.lba) { | ||
1245 | printk(KERN_ERR "%s: INVALID GEOMETRY: %d PHYSICAL HEADS?\n", | ||
1246 | drive->name, drive->head); | ||
1247 | drive->attach = 0; | ||
1248 | } else | ||
1249 | drive->attach = 1; | ||
1250 | DRIVER(drive)->busy--; | ||
1251 | g->minors = 1 << PARTN_BITS; | ||
1252 | strcpy(g->devfs_name, drive->devfs_name); | ||
1253 | g->driverfs_dev = &drive->gendev; | ||
1254 | g->flags = drive->removable ? GENHD_FL_REMOVABLE : 0; | ||
1255 | set_capacity(g, idedisk_capacity(drive)); | ||
1256 | g->fops = &idedisk_ops; | ||
1257 | add_disk(g); | ||
1258 | return 0; | ||
1259 | |||
1260 | out_put_disk: | ||
1261 | put_disk(g); | ||
1262 | out_free_idkp: | ||
1263 | kfree(idkp); | ||
1264 | failed: | ||
1265 | return 1; | ||
1266 | } | ||
1267 | |||
1268 | static void __exit idedisk_exit (void) | ||
1269 | { | ||
1270 | ide_unregister_driver(&idedisk_driver); | ||
1271 | } | ||
1272 | |||
1273 | static int idedisk_init (void) | ||
1274 | { | ||
1275 | return ide_register_driver(&idedisk_driver); | ||
1276 | } | ||
1277 | |||
1278 | module_init(idedisk_init); | ||
1279 | module_exit(idedisk_exit); | ||
1280 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/ide/ide-dma.c b/drivers/ide/ide-dma.c new file mode 100644 index 000000000000..2d2eefb610dd --- /dev/null +++ b/drivers/ide/ide-dma.c | |||
@@ -0,0 +1,959 @@ | |||
1 | /* | ||
2 | * linux/drivers/ide/ide-dma.c Version 4.10 June 9, 2000 | ||
3 | * | ||
4 | * Copyright (c) 1999-2000 Andre Hedrick <andre@linux-ide.org> | ||
5 | * May be copied or modified under the terms of the GNU General Public License | ||
6 | */ | ||
7 | |||
8 | /* | ||
9 | * Special Thanks to Mark for his Six years of work. | ||
10 | * | ||
11 | * Copyright (c) 1995-1998 Mark Lord | ||
12 | * May be copied or modified under the terms of the GNU General Public License | ||
13 | */ | ||
14 | |||
15 | /* | ||
16 | * This module provides support for the bus-master IDE DMA functions | ||
17 | * of various PCI chipsets, including the Intel PIIX (i82371FB for | ||
18 | * the 430 FX chipset), the PIIX3 (i82371SB for the 430 HX/VX and | ||
19 | * 440 chipsets), and the PIIX4 (i82371AB for the 430 TX chipset) | ||
20 | * ("PIIX" stands for "PCI ISA IDE Xcellerator"). | ||
21 | * | ||
22 | * Pretty much the same code works for other IDE PCI bus-mastering chipsets. | ||
23 | * | ||
24 | * DMA is supported for all IDE devices (disk drives, cdroms, tapes, floppies). | ||
25 | * | ||
26 | * By default, DMA support is prepared for use, but is currently enabled only | ||
27 | * for drives which already have DMA enabled (UltraDMA or mode 2 multi/single), | ||
28 | * or which are recognized as "good" (see table below). Drives with only mode0 | ||
29 | * or mode1 (multi/single) DMA should also work with this chipset/driver | ||
30 | * (eg. MC2112A) but are not enabled by default. | ||
31 | * | ||
32 | * Use "hdparm -i" to view modes supported by a given drive. | ||
33 | * | ||
34 | * The hdparm-3.5 (or later) utility can be used for manually enabling/disabling | ||
35 | * DMA support, but must be (re-)compiled against this kernel version or later. | ||
36 | * | ||
37 | * To enable DMA, use "hdparm -d1 /dev/hd?" on a per-drive basis after booting. | ||
38 | * If problems arise, ide.c will disable DMA operation after a few retries. | ||
39 | * This error recovery mechanism works and has been extremely well exercised. | ||
40 | * | ||
41 | * IDE drives, depending on their vintage, may support several different modes | ||
42 | * of DMA operation. The boot-time modes are indicated with a "*" in | ||
43 | * the "hdparm -i" listing, and can be changed with *knowledgeable* use of | ||
44 | * the "hdparm -X" feature. There is seldom a need to do this, as drives | ||
45 | * normally power-up with their "best" PIO/DMA modes enabled. | ||
46 | * | ||
47 | * Testing has been done with a rather extensive number of drives, | ||
48 | * with Quantum & Western Digital models generally outperforming the pack, | ||
49 | * and Fujitsu & Conner (and some Seagate which are really Conner) drives | ||
50 | * showing more lackluster throughput. | ||
51 | * | ||
52 | * Keep an eye on /var/adm/messages for "DMA disabled" messages. | ||
53 | * | ||
54 | * Some people have reported trouble with Intel Zappa motherboards. | ||
55 | * This can be fixed by upgrading the AMI BIOS to version 1.00.04.BS0, | ||
56 | * available from ftp://ftp.intel.com/pub/bios/10004bs0.exe | ||
57 | * (thanks to Glen Morrell <glen@spin.Stanford.edu> for researching this). | ||
58 | * | ||
59 | * Thanks to "Christopher J. Reimer" <reimer@doe.carleton.ca> for | ||
60 | * fixing the problem with the BIOS on some Acer motherboards. | ||
61 | * | ||
62 | * Thanks to "Benoit Poulot-Cazajous" <poulot@chorus.fr> for testing | ||
63 | * "TX" chipset compatibility and for providing patches for the "TX" chipset. | ||
64 | * | ||
65 | * Thanks to Christian Brunner <chb@muc.de> for taking a good first crack | ||
66 | * at generic DMA -- his patches were referred to when preparing this code. | ||
67 | * | ||
68 | * Most importantly, thanks to Robert Bringman <rob@mars.trion.com> | ||
69 | * for supplying a Promise UDMA board & WD UDMA drive for this work! | ||
70 | * | ||
71 | * And, yes, Intel Zappa boards really *do* use both PIIX IDE ports. | ||
72 | * | ||
73 | * ATA-66/100 and recovery functions, I forgot the rest...... | ||
74 | * | ||
75 | */ | ||
76 | |||
77 | #include <linux/config.h> | ||
78 | #include <linux/module.h> | ||
79 | #include <linux/types.h> | ||
80 | #include <linux/kernel.h> | ||
81 | #include <linux/timer.h> | ||
82 | #include <linux/mm.h> | ||
83 | #include <linux/interrupt.h> | ||
84 | #include <linux/pci.h> | ||
85 | #include <linux/init.h> | ||
86 | #include <linux/ide.h> | ||
87 | #include <linux/delay.h> | ||
88 | #include <linux/scatterlist.h> | ||
89 | |||
90 | #include <asm/io.h> | ||
91 | #include <asm/irq.h> | ||
92 | |||
93 | struct drive_list_entry { | ||
94 | const char *id_model; | ||
95 | const char *id_firmware; | ||
96 | }; | ||
97 | |||
98 | static const struct drive_list_entry drive_whitelist [] = { | ||
99 | |||
100 | { "Micropolis 2112A" , "ALL" }, | ||
101 | { "CONNER CTMA 4000" , "ALL" }, | ||
102 | { "CONNER CTT8000-A" , "ALL" }, | ||
103 | { "ST34342A" , "ALL" }, | ||
104 | { NULL , NULL } | ||
105 | }; | ||
106 | |||
107 | static const struct drive_list_entry drive_blacklist [] = { | ||
108 | |||
109 | { "WDC AC11000H" , "ALL" }, | ||
110 | { "WDC AC22100H" , "ALL" }, | ||
111 | { "WDC AC32500H" , "ALL" }, | ||
112 | { "WDC AC33100H" , "ALL" }, | ||
113 | { "WDC AC31600H" , "ALL" }, | ||
114 | { "WDC AC32100H" , "24.09P07" }, | ||
115 | { "WDC AC23200L" , "21.10N21" }, | ||
116 | { "Compaq CRD-8241B" , "ALL" }, | ||
117 | { "CRD-8400B" , "ALL" }, | ||
118 | { "CRD-8480B", "ALL" }, | ||
119 | { "CRD-8482B", "ALL" }, | ||
120 | { "CRD-84" , "ALL" }, | ||
121 | { "SanDisk SDP3B" , "ALL" }, | ||
122 | { "SanDisk SDP3B-64" , "ALL" }, | ||
123 | { "SANYO CD-ROM CRD" , "ALL" }, | ||
124 | { "HITACHI CDR-8" , "ALL" }, | ||
125 | { "HITACHI CDR-8335" , "ALL" }, | ||
126 | { "HITACHI CDR-8435" , "ALL" }, | ||
127 | { "Toshiba CD-ROM XM-6202B" , "ALL" }, | ||
128 | { "CD-532E-A" , "ALL" }, | ||
129 | { "E-IDE CD-ROM CR-840", "ALL" }, | ||
130 | { "CD-ROM Drive/F5A", "ALL" }, | ||
131 | { "WPI CDD-820", "ALL" }, | ||
132 | { "SAMSUNG CD-ROM SC-148C", "ALL" }, | ||
133 | { "SAMSUNG CD-ROM SC", "ALL" }, | ||
134 | { "SanDisk SDP3B-64" , "ALL" }, | ||
135 | { "SAMSUNG CD-ROM SN-124", "ALL" }, | ||
136 | { "ATAPI CD-ROM DRIVE 40X MAXIMUM", "ALL" }, | ||
137 | { "_NEC DV5800A", "ALL" }, | ||
138 | { NULL , NULL } | ||
139 | |||
140 | }; | ||
141 | |||
142 | /** | ||
143 | * in_drive_list - look for drive in black/white list | ||
144 | * @id: drive identifier | ||
145 | * @drive_table: list to inspect | ||
146 | * | ||
147 | * Look for a drive in the blacklist and the whitelist tables | ||
148 | * Returns 1 if the drive is found in the table. | ||
149 | */ | ||
150 | |||
151 | static int in_drive_list(struct hd_driveid *id, const struct drive_list_entry *drive_table) | ||
152 | { | ||
153 | for ( ; drive_table->id_model ; drive_table++) | ||
154 | if ((!strcmp(drive_table->id_model, id->model)) && | ||
155 | ((strstr(drive_table->id_firmware, id->fw_rev)) || | ||
156 | (!strcmp(drive_table->id_firmware, "ALL")))) | ||
157 | return 1; | ||
158 | return 0; | ||
159 | } | ||
160 | |||
161 | /** | ||
162 | * ide_dma_intr - IDE DMA interrupt handler | ||
163 | * @drive: the drive the interrupt is for | ||
164 | * | ||
165 | * Handle an interrupt completing a read/write DMA transfer on an | ||
166 | * IDE device | ||
167 | */ | ||
168 | |||
169 | ide_startstop_t ide_dma_intr (ide_drive_t *drive) | ||
170 | { | ||
171 | u8 stat = 0, dma_stat = 0; | ||
172 | |||
173 | dma_stat = HWIF(drive)->ide_dma_end(drive); | ||
174 | stat = HWIF(drive)->INB(IDE_STATUS_REG); /* get drive status */ | ||
175 | if (OK_STAT(stat,DRIVE_READY,drive->bad_wstat|DRQ_STAT)) { | ||
176 | if (!dma_stat) { | ||
177 | struct request *rq = HWGROUP(drive)->rq; | ||
178 | |||
179 | if (rq->rq_disk) { | ||
180 | ide_driver_t *drv; | ||
181 | |||
182 | drv = *(ide_driver_t **)rq->rq_disk->private_data;; | ||
183 | drv->end_request(drive, 1, rq->nr_sectors); | ||
184 | } else | ||
185 | ide_end_request(drive, 1, rq->nr_sectors); | ||
186 | return ide_stopped; | ||
187 | } | ||
188 | printk(KERN_ERR "%s: dma_intr: bad DMA status (dma_stat=%x)\n", | ||
189 | drive->name, dma_stat); | ||
190 | } | ||
191 | return ide_error(drive, "dma_intr", stat); | ||
192 | } | ||
193 | |||
194 | EXPORT_SYMBOL_GPL(ide_dma_intr); | ||
195 | |||
196 | #ifdef CONFIG_BLK_DEV_IDEDMA_PCI | ||
197 | /** | ||
198 | * ide_build_sglist - map IDE scatter gather for DMA I/O | ||
199 | * @drive: the drive to build the DMA table for | ||
200 | * @rq: the request holding the sg list | ||
201 | * | ||
202 | * Perform the PCI mapping magic necessary to access the source or | ||
203 | * target buffers of a request via PCI DMA. The lower layers of the | ||
204 | * kernel provide the necessary cache management so that we can | ||
205 | * operate in a portable fashion | ||
206 | */ | ||
207 | |||
208 | int ide_build_sglist(ide_drive_t *drive, struct request *rq) | ||
209 | { | ||
210 | ide_hwif_t *hwif = HWIF(drive); | ||
211 | struct scatterlist *sg = hwif->sg_table; | ||
212 | |||
213 | if ((rq->flags & REQ_DRIVE_TASKFILE) && rq->nr_sectors > 256) | ||
214 | BUG(); | ||
215 | |||
216 | ide_map_sg(drive, rq); | ||
217 | |||
218 | if (rq_data_dir(rq) == READ) | ||
219 | hwif->sg_dma_direction = PCI_DMA_FROMDEVICE; | ||
220 | else | ||
221 | hwif->sg_dma_direction = PCI_DMA_TODEVICE; | ||
222 | |||
223 | return pci_map_sg(hwif->pci_dev, sg, hwif->sg_nents, hwif->sg_dma_direction); | ||
224 | } | ||
225 | |||
226 | EXPORT_SYMBOL_GPL(ide_build_sglist); | ||
227 | |||
228 | /** | ||
229 | * ide_build_dmatable - build IDE DMA table | ||
230 | * | ||
231 | * ide_build_dmatable() prepares a dma request. We map the command | ||
232 | * to get the pci bus addresses of the buffers and then build up | ||
233 | * the PRD table that the IDE layer wants to be fed. The code | ||
234 | * knows about the 64K wrap bug in the CS5530. | ||
235 | * | ||
236 | * Returns the number of built PRD entries if all went okay, | ||
237 | * returns 0 otherwise. | ||
238 | * | ||
239 | * May also be invoked from trm290.c | ||
240 | */ | ||
241 | |||
242 | int ide_build_dmatable (ide_drive_t *drive, struct request *rq) | ||
243 | { | ||
244 | ide_hwif_t *hwif = HWIF(drive); | ||
245 | unsigned int *table = hwif->dmatable_cpu; | ||
246 | unsigned int is_trm290 = (hwif->chipset == ide_trm290) ? 1 : 0; | ||
247 | unsigned int count = 0; | ||
248 | int i; | ||
249 | struct scatterlist *sg; | ||
250 | |||
251 | hwif->sg_nents = i = ide_build_sglist(drive, rq); | ||
252 | |||
253 | if (!i) | ||
254 | return 0; | ||
255 | |||
256 | sg = hwif->sg_table; | ||
257 | while (i) { | ||
258 | u32 cur_addr; | ||
259 | u32 cur_len; | ||
260 | |||
261 | cur_addr = sg_dma_address(sg); | ||
262 | cur_len = sg_dma_len(sg); | ||
263 | |||
264 | /* | ||
265 | * Fill in the dma table, without crossing any 64kB boundaries. | ||
266 | * Most hardware requires 16-bit alignment of all blocks, | ||
267 | * but the trm290 requires 32-bit alignment. | ||
268 | */ | ||
269 | |||
270 | while (cur_len) { | ||
271 | if (count++ >= PRD_ENTRIES) { | ||
272 | printk(KERN_ERR "%s: DMA table too small\n", drive->name); | ||
273 | goto use_pio_instead; | ||
274 | } else { | ||
275 | u32 xcount, bcount = 0x10000 - (cur_addr & 0xffff); | ||
276 | |||
277 | if (bcount > cur_len) | ||
278 | bcount = cur_len; | ||
279 | *table++ = cpu_to_le32(cur_addr); | ||
280 | xcount = bcount & 0xffff; | ||
281 | if (is_trm290) | ||
282 | xcount = ((xcount >> 2) - 1) << 16; | ||
283 | if (xcount == 0x0000) { | ||
284 | /* | ||
285 | * Most chipsets correctly interpret a length of 0x0000 as 64KB, | ||
286 | * but at least one (e.g. CS5530) misinterprets it as zero (!). | ||
287 | * So here we break the 64KB entry into two 32KB entries instead. | ||
288 | */ | ||
289 | if (count++ >= PRD_ENTRIES) { | ||
290 | printk(KERN_ERR "%s: DMA table too small\n", drive->name); | ||
291 | goto use_pio_instead; | ||
292 | } | ||
293 | *table++ = cpu_to_le32(0x8000); | ||
294 | *table++ = cpu_to_le32(cur_addr + 0x8000); | ||
295 | xcount = 0x8000; | ||
296 | } | ||
297 | *table++ = cpu_to_le32(xcount); | ||
298 | cur_addr += bcount; | ||
299 | cur_len -= bcount; | ||
300 | } | ||
301 | } | ||
302 | |||
303 | sg++; | ||
304 | i--; | ||
305 | } | ||
306 | |||
307 | if (count) { | ||
308 | if (!is_trm290) | ||
309 | *--table |= cpu_to_le32(0x80000000); | ||
310 | return count; | ||
311 | } | ||
312 | printk(KERN_ERR "%s: empty DMA table?\n", drive->name); | ||
313 | use_pio_instead: | ||
314 | pci_unmap_sg(hwif->pci_dev, | ||
315 | hwif->sg_table, | ||
316 | hwif->sg_nents, | ||
317 | hwif->sg_dma_direction); | ||
318 | return 0; /* revert to PIO for this request */ | ||
319 | } | ||
320 | |||
321 | EXPORT_SYMBOL_GPL(ide_build_dmatable); | ||
322 | |||
323 | /** | ||
324 | * ide_destroy_dmatable - clean up DMA mapping | ||
325 | * @drive: The drive to unmap | ||
326 | * | ||
327 | * Teardown mappings after DMA has completed. This must be called | ||
328 | * after the completion of each use of ide_build_dmatable and before | ||
329 | * the next use of ide_build_dmatable. Failure to do so will cause | ||
330 | * an oops as only one mapping can be live for each target at a given | ||
331 | * time. | ||
332 | */ | ||
333 | |||
334 | void ide_destroy_dmatable (ide_drive_t *drive) | ||
335 | { | ||
336 | struct pci_dev *dev = HWIF(drive)->pci_dev; | ||
337 | struct scatterlist *sg = HWIF(drive)->sg_table; | ||
338 | int nents = HWIF(drive)->sg_nents; | ||
339 | |||
340 | pci_unmap_sg(dev, sg, nents, HWIF(drive)->sg_dma_direction); | ||
341 | } | ||
342 | |||
343 | EXPORT_SYMBOL_GPL(ide_destroy_dmatable); | ||
344 | |||
345 | /** | ||
346 | * config_drive_for_dma - attempt to activate IDE DMA | ||
347 | * @drive: the drive to place in DMA mode | ||
348 | * | ||
349 | * If the drive supports at least mode 2 DMA or UDMA of any kind | ||
350 | * then attempt to place it into DMA mode. Drives that are known to | ||
351 | * support DMA but predate the DMA properties or that are known | ||
352 | * to have DMA handling bugs are also set up appropriately based | ||
353 | * on the good/bad drive lists. | ||
354 | */ | ||
355 | |||
356 | static int config_drive_for_dma (ide_drive_t *drive) | ||
357 | { | ||
358 | struct hd_driveid *id = drive->id; | ||
359 | ide_hwif_t *hwif = HWIF(drive); | ||
360 | |||
361 | if ((id->capability & 1) && hwif->autodma) { | ||
362 | /* | ||
363 | * Enable DMA on any drive that has | ||
364 | * UltraDMA (mode 0/1/2/3/4/5/6) enabled | ||
365 | */ | ||
366 | if ((id->field_valid & 4) && ((id->dma_ultra >> 8) & 0x7f)) | ||
367 | return hwif->ide_dma_on(drive); | ||
368 | /* | ||
369 | * Enable DMA on any drive that has mode2 DMA | ||
370 | * (multi or single) enabled | ||
371 | */ | ||
372 | if (id->field_valid & 2) /* regular DMA */ | ||
373 | if ((id->dma_mword & 0x404) == 0x404 || | ||
374 | (id->dma_1word & 0x404) == 0x404) | ||
375 | return hwif->ide_dma_on(drive); | ||
376 | |||
377 | /* Consult the list of known "good" drives */ | ||
378 | if (__ide_dma_good_drive(drive)) | ||
379 | return hwif->ide_dma_on(drive); | ||
380 | } | ||
381 | // if (hwif->tuneproc != NULL) hwif->tuneproc(drive, 255); | ||
382 | return hwif->ide_dma_off_quietly(drive); | ||
383 | } | ||
384 | |||
385 | /** | ||
386 | * dma_timer_expiry - handle a DMA timeout | ||
387 | * @drive: Drive that timed out | ||
388 | * | ||
389 | * An IDE DMA transfer timed out. In the event of an error we ask | ||
390 | * the driver to resolve the problem, if a DMA transfer is still | ||
391 | * in progress we continue to wait (arguably we need to add a | ||
392 | * secondary 'I don't care what the drive thinks' timeout here) | ||
393 | * Finally if we have an interrupt we let it complete the I/O. | ||
394 | * But only one time - we clear expiry and if it's still not | ||
395 | * completed after WAIT_CMD, we error and retry in PIO. | ||
396 | * This can occur if an interrupt is lost or due to hang or bugs. | ||
397 | */ | ||
398 | |||
399 | static int dma_timer_expiry (ide_drive_t *drive) | ||
400 | { | ||
401 | ide_hwif_t *hwif = HWIF(drive); | ||
402 | u8 dma_stat = hwif->INB(hwif->dma_status); | ||
403 | |||
404 | printk(KERN_WARNING "%s: dma_timer_expiry: dma status == 0x%02x\n", | ||
405 | drive->name, dma_stat); | ||
406 | |||
407 | if ((dma_stat & 0x18) == 0x18) /* BUSY Stupid Early Timer !! */ | ||
408 | return WAIT_CMD; | ||
409 | |||
410 | HWGROUP(drive)->expiry = NULL; /* one free ride for now */ | ||
411 | |||
412 | /* 1 dmaing, 2 error, 4 intr */ | ||
413 | if (dma_stat & 2) /* ERROR */ | ||
414 | return -1; | ||
415 | |||
416 | if (dma_stat & 1) /* DMAing */ | ||
417 | return WAIT_CMD; | ||
418 | |||
419 | if (dma_stat & 4) /* Got an Interrupt */ | ||
420 | return WAIT_CMD; | ||
421 | |||
422 | return 0; /* Status is unknown -- reset the bus */ | ||
423 | } | ||
424 | |||
425 | /** | ||
426 | * __ide_dma_host_off - Generic DMA kill | ||
427 | * @drive: drive to control | ||
428 | * | ||
429 | * Perform the generic IDE controller DMA off operation. This | ||
430 | * works for most IDE bus mastering controllers | ||
431 | */ | ||
432 | |||
433 | int __ide_dma_host_off (ide_drive_t *drive) | ||
434 | { | ||
435 | ide_hwif_t *hwif = HWIF(drive); | ||
436 | u8 unit = (drive->select.b.unit & 0x01); | ||
437 | u8 dma_stat = hwif->INB(hwif->dma_status); | ||
438 | |||
439 | hwif->OUTB((dma_stat & ~(1<<(5+unit))), hwif->dma_status); | ||
440 | return 0; | ||
441 | } | ||
442 | |||
443 | EXPORT_SYMBOL(__ide_dma_host_off); | ||
444 | |||
445 | /** | ||
446 | * __ide_dma_host_off_quietly - Generic DMA kill | ||
447 | * @drive: drive to control | ||
448 | * | ||
449 | * Turn off the current DMA on this IDE controller. | ||
450 | */ | ||
451 | |||
452 | int __ide_dma_off_quietly (ide_drive_t *drive) | ||
453 | { | ||
454 | drive->using_dma = 0; | ||
455 | ide_toggle_bounce(drive, 0); | ||
456 | |||
457 | if (HWIF(drive)->ide_dma_host_off(drive)) | ||
458 | return 1; | ||
459 | |||
460 | return 0; | ||
461 | } | ||
462 | |||
463 | EXPORT_SYMBOL(__ide_dma_off_quietly); | ||
464 | #endif /* CONFIG_BLK_DEV_IDEDMA_PCI */ | ||
465 | |||
466 | /** | ||
467 | * __ide_dma_off - disable DMA on a device | ||
468 | * @drive: drive to disable DMA on | ||
469 | * | ||
470 | * Disable IDE DMA for a device on this IDE controller. | ||
471 | * Inform the user that DMA has been disabled. | ||
472 | */ | ||
473 | |||
474 | int __ide_dma_off (ide_drive_t *drive) | ||
475 | { | ||
476 | printk(KERN_INFO "%s: DMA disabled\n", drive->name); | ||
477 | return HWIF(drive)->ide_dma_off_quietly(drive); | ||
478 | } | ||
479 | |||
480 | EXPORT_SYMBOL(__ide_dma_off); | ||
481 | |||
482 | #ifdef CONFIG_BLK_DEV_IDEDMA_PCI | ||
483 | /** | ||
484 | * __ide_dma_host_on - Enable DMA on a host | ||
485 | * @drive: drive to enable for DMA | ||
486 | * | ||
487 | * Enable DMA on an IDE controller following generic bus mastering | ||
488 | * IDE controller behaviour | ||
489 | */ | ||
490 | |||
491 | int __ide_dma_host_on (ide_drive_t *drive) | ||
492 | { | ||
493 | if (drive->using_dma) { | ||
494 | ide_hwif_t *hwif = HWIF(drive); | ||
495 | u8 unit = (drive->select.b.unit & 0x01); | ||
496 | u8 dma_stat = hwif->INB(hwif->dma_status); | ||
497 | |||
498 | hwif->OUTB((dma_stat|(1<<(5+unit))), hwif->dma_status); | ||
499 | return 0; | ||
500 | } | ||
501 | return 1; | ||
502 | } | ||
503 | |||
504 | EXPORT_SYMBOL(__ide_dma_host_on); | ||
505 | |||
506 | /** | ||
507 | * __ide_dma_on - Enable DMA on a device | ||
508 | * @drive: drive to enable DMA on | ||
509 | * | ||
510 | * Enable IDE DMA for a device on this IDE controller. | ||
511 | */ | ||
512 | |||
513 | int __ide_dma_on (ide_drive_t *drive) | ||
514 | { | ||
515 | /* consult the list of known "bad" drives */ | ||
516 | if (__ide_dma_bad_drive(drive)) | ||
517 | return 1; | ||
518 | |||
519 | drive->using_dma = 1; | ||
520 | ide_toggle_bounce(drive, 1); | ||
521 | |||
522 | if (HWIF(drive)->ide_dma_host_on(drive)) | ||
523 | return 1; | ||
524 | |||
525 | return 0; | ||
526 | } | ||
527 | |||
528 | EXPORT_SYMBOL(__ide_dma_on); | ||
529 | |||
530 | /** | ||
531 | * __ide_dma_check - check DMA setup | ||
532 | * @drive: drive to check | ||
533 | * | ||
534 | * Don't use - due for extermination | ||
535 | */ | ||
536 | |||
537 | int __ide_dma_check (ide_drive_t *drive) | ||
538 | { | ||
539 | return config_drive_for_dma(drive); | ||
540 | } | ||
541 | |||
542 | EXPORT_SYMBOL(__ide_dma_check); | ||
543 | |||
544 | /** | ||
545 | * ide_dma_setup - begin a DMA phase | ||
546 | * @drive: target device | ||
547 | * | ||
548 | * Build an IDE DMA PRD (IDE speak for scatter gather table) | ||
549 | * and then set up the DMA transfer registers for a device | ||
550 | * that follows generic IDE PCI DMA behaviour. Controllers can | ||
551 | * override this function if they need to | ||
552 | * | ||
553 | * Returns 0 on success. If a PIO fallback is required then 1 | ||
554 | * is returned. | ||
555 | */ | ||
556 | |||
557 | int ide_dma_setup(ide_drive_t *drive) | ||
558 | { | ||
559 | ide_hwif_t *hwif = drive->hwif; | ||
560 | struct request *rq = HWGROUP(drive)->rq; | ||
561 | unsigned int reading; | ||
562 | u8 dma_stat; | ||
563 | |||
564 | if (rq_data_dir(rq)) | ||
565 | reading = 0; | ||
566 | else | ||
567 | reading = 1 << 3; | ||
568 | |||
569 | /* fall back to pio! */ | ||
570 | if (!ide_build_dmatable(drive, rq)) { | ||
571 | ide_map_sg(drive, rq); | ||
572 | return 1; | ||
573 | } | ||
574 | |||
575 | /* PRD table */ | ||
576 | hwif->OUTL(hwif->dmatable_dma, hwif->dma_prdtable); | ||
577 | |||
578 | /* specify r/w */ | ||
579 | hwif->OUTB(reading, hwif->dma_command); | ||
580 | |||
581 | /* read dma_status for INTR & ERROR flags */ | ||
582 | dma_stat = hwif->INB(hwif->dma_status); | ||
583 | |||
584 | /* clear INTR & ERROR flags */ | ||
585 | hwif->OUTB(dma_stat|6, hwif->dma_status); | ||
586 | drive->waiting_for_dma = 1; | ||
587 | return 0; | ||
588 | } | ||
589 | |||
590 | EXPORT_SYMBOL_GPL(ide_dma_setup); | ||
591 | |||
592 | static void ide_dma_exec_cmd(ide_drive_t *drive, u8 command) | ||
593 | { | ||
594 | /* issue cmd to drive */ | ||
595 | ide_execute_command(drive, command, &ide_dma_intr, 2*WAIT_CMD, dma_timer_expiry); | ||
596 | } | ||
597 | |||
598 | void ide_dma_start(ide_drive_t *drive) | ||
599 | { | ||
600 | ide_hwif_t *hwif = HWIF(drive); | ||
601 | u8 dma_cmd = hwif->INB(hwif->dma_command); | ||
602 | |||
603 | /* Note that this is done *after* the cmd has | ||
604 | * been issued to the drive, as per the BM-IDE spec. | ||
605 | * The Promise Ultra33 doesn't work correctly when | ||
606 | * we do this part before issuing the drive cmd. | ||
607 | */ | ||
608 | /* start DMA */ | ||
609 | hwif->OUTB(dma_cmd|1, hwif->dma_command); | ||
610 | hwif->dma = 1; | ||
611 | wmb(); | ||
612 | } | ||
613 | |||
614 | EXPORT_SYMBOL_GPL(ide_dma_start); | ||
615 | |||
616 | /* returns 1 on error, 0 otherwise */ | ||
617 | int __ide_dma_end (ide_drive_t *drive) | ||
618 | { | ||
619 | ide_hwif_t *hwif = HWIF(drive); | ||
620 | u8 dma_stat = 0, dma_cmd = 0; | ||
621 | |||
622 | drive->waiting_for_dma = 0; | ||
623 | /* get dma_command mode */ | ||
624 | dma_cmd = hwif->INB(hwif->dma_command); | ||
625 | /* stop DMA */ | ||
626 | hwif->OUTB(dma_cmd&~1, hwif->dma_command); | ||
627 | /* get DMA status */ | ||
628 | dma_stat = hwif->INB(hwif->dma_status); | ||
629 | /* clear the INTR & ERROR bits */ | ||
630 | hwif->OUTB(dma_stat|6, hwif->dma_status); | ||
631 | /* purge DMA mappings */ | ||
632 | ide_destroy_dmatable(drive); | ||
633 | /* verify good DMA status */ | ||
634 | hwif->dma = 0; | ||
635 | wmb(); | ||
636 | return (dma_stat & 7) != 4 ? (0x10 | dma_stat) : 0; | ||
637 | } | ||
638 | |||
639 | EXPORT_SYMBOL(__ide_dma_end); | ||
640 | |||
641 | /* returns 1 if dma irq issued, 0 otherwise */ | ||
642 | static int __ide_dma_test_irq(ide_drive_t *drive) | ||
643 | { | ||
644 | ide_hwif_t *hwif = HWIF(drive); | ||
645 | u8 dma_stat = hwif->INB(hwif->dma_status); | ||
646 | |||
647 | #if 0 /* do not set unless you know what you are doing */ | ||
648 | if (dma_stat & 4) { | ||
649 | u8 stat = hwif->INB(IDE_STATUS_REG); | ||
650 | hwif->OUTB(hwif->dma_status, dma_stat & 0xE4); | ||
651 | } | ||
652 | #endif | ||
653 | /* return 1 if INTR asserted */ | ||
654 | if ((dma_stat & 4) == 4) | ||
655 | return 1; | ||
656 | if (!drive->waiting_for_dma) | ||
657 | printk(KERN_WARNING "%s: (%s) called while not waiting\n", | ||
658 | drive->name, __FUNCTION__); | ||
659 | return 0; | ||
660 | } | ||
661 | #endif /* CONFIG_BLK_DEV_IDEDMA_PCI */ | ||
662 | |||
663 | int __ide_dma_bad_drive (ide_drive_t *drive) | ||
664 | { | ||
665 | struct hd_driveid *id = drive->id; | ||
666 | |||
667 | int blacklist = in_drive_list(id, drive_blacklist); | ||
668 | if (blacklist) { | ||
669 | printk(KERN_WARNING "%s: Disabling (U)DMA for %s (blacklisted)\n", | ||
670 | drive->name, id->model); | ||
671 | return blacklist; | ||
672 | } | ||
673 | return 0; | ||
674 | } | ||
675 | |||
676 | EXPORT_SYMBOL(__ide_dma_bad_drive); | ||
677 | |||
678 | int __ide_dma_good_drive (ide_drive_t *drive) | ||
679 | { | ||
680 | struct hd_driveid *id = drive->id; | ||
681 | return in_drive_list(id, drive_whitelist); | ||
682 | } | ||
683 | |||
684 | EXPORT_SYMBOL(__ide_dma_good_drive); | ||
685 | |||
686 | int ide_use_dma(ide_drive_t *drive) | ||
687 | { | ||
688 | struct hd_driveid *id = drive->id; | ||
689 | ide_hwif_t *hwif = drive->hwif; | ||
690 | |||
691 | /* consult the list of known "bad" drives */ | ||
692 | if (__ide_dma_bad_drive(drive)) | ||
693 | return 0; | ||
694 | |||
695 | /* capable of UltraDMA modes */ | ||
696 | if (id->field_valid & 4) { | ||
697 | if (hwif->ultra_mask & id->dma_ultra) | ||
698 | return 1; | ||
699 | } | ||
700 | |||
701 | /* capable of regular DMA modes */ | ||
702 | if (id->field_valid & 2) { | ||
703 | if (hwif->mwdma_mask & id->dma_mword) | ||
704 | return 1; | ||
705 | if (hwif->swdma_mask & id->dma_1word) | ||
706 | return 1; | ||
707 | } | ||
708 | |||
709 | /* consult the list of known "good" drives */ | ||
710 | if (__ide_dma_good_drive(drive) && id->eide_dma_time < 150) | ||
711 | return 1; | ||
712 | |||
713 | return 0; | ||
714 | } | ||
715 | |||
716 | EXPORT_SYMBOL_GPL(ide_use_dma); | ||
717 | |||
718 | void ide_dma_verbose(ide_drive_t *drive) | ||
719 | { | ||
720 | struct hd_driveid *id = drive->id; | ||
721 | ide_hwif_t *hwif = HWIF(drive); | ||
722 | |||
723 | if (id->field_valid & 4) { | ||
724 | if ((id->dma_ultra >> 8) && (id->dma_mword >> 8)) | ||
725 | goto bug_dma_off; | ||
726 | if (id->dma_ultra & ((id->dma_ultra >> 8) & hwif->ultra_mask)) { | ||
727 | if (((id->dma_ultra >> 11) & 0x1F) && | ||
728 | eighty_ninty_three(drive)) { | ||
729 | if ((id->dma_ultra >> 15) & 1) { | ||
730 | printk(", UDMA(mode 7)"); | ||
731 | } else if ((id->dma_ultra >> 14) & 1) { | ||
732 | printk(", UDMA(133)"); | ||
733 | } else if ((id->dma_ultra >> 13) & 1) { | ||
734 | printk(", UDMA(100)"); | ||
735 | } else if ((id->dma_ultra >> 12) & 1) { | ||
736 | printk(", UDMA(66)"); | ||
737 | } else if ((id->dma_ultra >> 11) & 1) { | ||
738 | printk(", UDMA(44)"); | ||
739 | } else | ||
740 | goto mode_two; | ||
741 | } else { | ||
742 | mode_two: | ||
743 | if ((id->dma_ultra >> 10) & 1) { | ||
744 | printk(", UDMA(33)"); | ||
745 | } else if ((id->dma_ultra >> 9) & 1) { | ||
746 | printk(", UDMA(25)"); | ||
747 | } else if ((id->dma_ultra >> 8) & 1) { | ||
748 | printk(", UDMA(16)"); | ||
749 | } | ||
750 | } | ||
751 | } else { | ||
752 | printk(", (U)DMA"); /* Can be BIOS-enabled! */ | ||
753 | } | ||
754 | } else if (id->field_valid & 2) { | ||
755 | if ((id->dma_mword >> 8) && (id->dma_1word >> 8)) | ||
756 | goto bug_dma_off; | ||
757 | printk(", DMA"); | ||
758 | } else if (id->field_valid & 1) { | ||
759 | printk(", BUG"); | ||
760 | } | ||
761 | return; | ||
762 | bug_dma_off: | ||
763 | printk(", BUG DMA OFF"); | ||
764 | hwif->ide_dma_off_quietly(drive); | ||
765 | return; | ||
766 | } | ||
767 | |||
768 | EXPORT_SYMBOL(ide_dma_verbose); | ||
769 | |||
770 | #ifdef CONFIG_BLK_DEV_IDEDMA_PCI | ||
771 | int __ide_dma_lostirq (ide_drive_t *drive) | ||
772 | { | ||
773 | printk("%s: DMA interrupt recovery\n", drive->name); | ||
774 | return 1; | ||
775 | } | ||
776 | |||
777 | EXPORT_SYMBOL(__ide_dma_lostirq); | ||
778 | |||
779 | int __ide_dma_timeout (ide_drive_t *drive) | ||
780 | { | ||
781 | printk(KERN_ERR "%s: timeout waiting for DMA\n", drive->name); | ||
782 | if (HWIF(drive)->ide_dma_test_irq(drive)) | ||
783 | return 0; | ||
784 | |||
785 | return HWIF(drive)->ide_dma_end(drive); | ||
786 | } | ||
787 | |||
788 | EXPORT_SYMBOL(__ide_dma_timeout); | ||
789 | |||
790 | /* | ||
791 | * Needed for allowing full modular support of ide-driver | ||
792 | */ | ||
793 | static int ide_release_dma_engine(ide_hwif_t *hwif) | ||
794 | { | ||
795 | if (hwif->dmatable_cpu) { | ||
796 | pci_free_consistent(hwif->pci_dev, | ||
797 | PRD_ENTRIES * PRD_BYTES, | ||
798 | hwif->dmatable_cpu, | ||
799 | hwif->dmatable_dma); | ||
800 | hwif->dmatable_cpu = NULL; | ||
801 | } | ||
802 | return 1; | ||
803 | } | ||
804 | |||
805 | static int ide_release_iomio_dma(ide_hwif_t *hwif) | ||
806 | { | ||
807 | if ((hwif->dma_extra) && (hwif->channel == 0)) | ||
808 | release_region((hwif->dma_base + 16), hwif->dma_extra); | ||
809 | release_region(hwif->dma_base, 8); | ||
810 | if (hwif->dma_base2) | ||
811 | release_region(hwif->dma_base, 8); | ||
812 | return 1; | ||
813 | } | ||
814 | |||
815 | /* | ||
816 | * Needed for allowing full modular support of ide-driver | ||
817 | */ | ||
818 | int ide_release_dma (ide_hwif_t *hwif) | ||
819 | { | ||
820 | if (hwif->mmio == 2) | ||
821 | return 1; | ||
822 | if (hwif->chipset == ide_etrax100) | ||
823 | return 1; | ||
824 | |||
825 | ide_release_dma_engine(hwif); | ||
826 | return ide_release_iomio_dma(hwif); | ||
827 | } | ||
828 | |||
829 | static int ide_allocate_dma_engine(ide_hwif_t *hwif) | ||
830 | { | ||
831 | hwif->dmatable_cpu = pci_alloc_consistent(hwif->pci_dev, | ||
832 | PRD_ENTRIES * PRD_BYTES, | ||
833 | &hwif->dmatable_dma); | ||
834 | |||
835 | if (hwif->dmatable_cpu) | ||
836 | return 0; | ||
837 | |||
838 | printk(KERN_ERR "%s: -- Error, unable to allocate%s DMA table(s).\n", | ||
839 | hwif->cds->name, !hwif->dmatable_cpu ? " CPU" : ""); | ||
840 | |||
841 | ide_release_dma_engine(hwif); | ||
842 | return 1; | ||
843 | } | ||
844 | |||
845 | static int ide_mapped_mmio_dma(ide_hwif_t *hwif, unsigned long base, unsigned int ports) | ||
846 | { | ||
847 | printk(KERN_INFO " %s: MMIO-DMA ", hwif->name); | ||
848 | |||
849 | hwif->dma_base = base; | ||
850 | if (hwif->cds->extra && hwif->channel == 0) | ||
851 | hwif->dma_extra = hwif->cds->extra; | ||
852 | |||
853 | if(hwif->mate) | ||
854 | hwif->dma_master = (hwif->channel) ? hwif->mate->dma_base : base; | ||
855 | else | ||
856 | hwif->dma_master = base; | ||
857 | return 0; | ||
858 | } | ||
859 | |||
860 | static int ide_iomio_dma(ide_hwif_t *hwif, unsigned long base, unsigned int ports) | ||
861 | { | ||
862 | printk(KERN_INFO " %s: BM-DMA at 0x%04lx-0x%04lx", | ||
863 | hwif->name, base, base + ports - 1); | ||
864 | if (!request_region(base, ports, hwif->name)) { | ||
865 | printk(" -- Error, ports in use.\n"); | ||
866 | return 1; | ||
867 | } | ||
868 | hwif->dma_base = base; | ||
869 | if ((hwif->cds->extra) && (hwif->channel == 0)) { | ||
870 | request_region(base+16, hwif->cds->extra, hwif->cds->name); | ||
871 | hwif->dma_extra = hwif->cds->extra; | ||
872 | } | ||
873 | |||
874 | if(hwif->mate) | ||
875 | hwif->dma_master = (hwif->channel) ? hwif->mate->dma_base : base; | ||
876 | else | ||
877 | hwif->dma_master = base; | ||
878 | if (hwif->dma_base2) { | ||
879 | if (!request_region(hwif->dma_base2, ports, hwif->name)) | ||
880 | { | ||
881 | printk(" -- Error, secondary ports in use.\n"); | ||
882 | release_region(base, ports); | ||
883 | return 1; | ||
884 | } | ||
885 | } | ||
886 | return 0; | ||
887 | } | ||
888 | |||
889 | static int ide_dma_iobase(ide_hwif_t *hwif, unsigned long base, unsigned int ports) | ||
890 | { | ||
891 | if (hwif->mmio == 2) | ||
892 | return ide_mapped_mmio_dma(hwif, base,ports); | ||
893 | BUG_ON(hwif->mmio == 1); | ||
894 | return ide_iomio_dma(hwif, base, ports); | ||
895 | } | ||
896 | |||
897 | /* | ||
898 | * This can be called for a dynamically installed interface. Don't __init it | ||
899 | */ | ||
900 | void ide_setup_dma (ide_hwif_t *hwif, unsigned long dma_base, unsigned int num_ports) | ||
901 | { | ||
902 | if (ide_dma_iobase(hwif, dma_base, num_ports)) | ||
903 | return; | ||
904 | |||
905 | if (ide_allocate_dma_engine(hwif)) { | ||
906 | ide_release_dma(hwif); | ||
907 | return; | ||
908 | } | ||
909 | |||
910 | if (!(hwif->dma_command)) | ||
911 | hwif->dma_command = hwif->dma_base; | ||
912 | if (!(hwif->dma_vendor1)) | ||
913 | hwif->dma_vendor1 = (hwif->dma_base + 1); | ||
914 | if (!(hwif->dma_status)) | ||
915 | hwif->dma_status = (hwif->dma_base + 2); | ||
916 | if (!(hwif->dma_vendor3)) | ||
917 | hwif->dma_vendor3 = (hwif->dma_base + 3); | ||
918 | if (!(hwif->dma_prdtable)) | ||
919 | hwif->dma_prdtable = (hwif->dma_base + 4); | ||
920 | |||
921 | if (!hwif->ide_dma_off_quietly) | ||
922 | hwif->ide_dma_off_quietly = &__ide_dma_off_quietly; | ||
923 | if (!hwif->ide_dma_host_off) | ||
924 | hwif->ide_dma_host_off = &__ide_dma_host_off; | ||
925 | if (!hwif->ide_dma_on) | ||
926 | hwif->ide_dma_on = &__ide_dma_on; | ||
927 | if (!hwif->ide_dma_host_on) | ||
928 | hwif->ide_dma_host_on = &__ide_dma_host_on; | ||
929 | if (!hwif->ide_dma_check) | ||
930 | hwif->ide_dma_check = &__ide_dma_check; | ||
931 | if (!hwif->dma_setup) | ||
932 | hwif->dma_setup = &ide_dma_setup; | ||
933 | if (!hwif->dma_exec_cmd) | ||
934 | hwif->dma_exec_cmd = &ide_dma_exec_cmd; | ||
935 | if (!hwif->dma_start) | ||
936 | hwif->dma_start = &ide_dma_start; | ||
937 | if (!hwif->ide_dma_end) | ||
938 | hwif->ide_dma_end = &__ide_dma_end; | ||
939 | if (!hwif->ide_dma_test_irq) | ||
940 | hwif->ide_dma_test_irq = &__ide_dma_test_irq; | ||
941 | if (!hwif->ide_dma_timeout) | ||
942 | hwif->ide_dma_timeout = &__ide_dma_timeout; | ||
943 | if (!hwif->ide_dma_lostirq) | ||
944 | hwif->ide_dma_lostirq = &__ide_dma_lostirq; | ||
945 | |||
946 | if (hwif->chipset != ide_trm290) { | ||
947 | u8 dma_stat = hwif->INB(hwif->dma_status); | ||
948 | printk(", BIOS settings: %s:%s, %s:%s", | ||
949 | hwif->drives[0].name, (dma_stat & 0x20) ? "DMA" : "pio", | ||
950 | hwif->drives[1].name, (dma_stat & 0x40) ? "DMA" : "pio"); | ||
951 | } | ||
952 | printk("\n"); | ||
953 | |||
954 | if (!(hwif->dma_master)) | ||
955 | BUG(); | ||
956 | } | ||
957 | |||
958 | EXPORT_SYMBOL_GPL(ide_setup_dma); | ||
959 | #endif /* CONFIG_BLK_DEV_IDEDMA_PCI */ | ||
diff --git a/drivers/ide/ide-floppy.c b/drivers/ide/ide-floppy.c new file mode 100644 index 000000000000..36c0b74a4e45 --- /dev/null +++ b/drivers/ide/ide-floppy.c | |||
@@ -0,0 +1,2211 @@ | |||
1 | /* | ||
2 | * linux/drivers/ide/ide-floppy.c Version 0.99 Feb 24 2002 | ||
3 | * | ||
4 | * Copyright (C) 1996 - 1999 Gadi Oxman <gadio@netvision.net.il> | ||
5 | * Copyright (C) 2000 - 2002 Paul Bristow <paul@paulbristow.net> | ||
6 | */ | ||
7 | |||
8 | /* | ||
9 | * IDE ATAPI floppy driver. | ||
10 | * | ||
11 | * The driver currently doesn't have any fancy features, just the bare | ||
12 | * minimum read/write support. | ||
13 | * | ||
14 | * This driver supports the following IDE floppy drives: | ||
15 | * | ||
16 | * LS-120/240 SuperDisk | ||
17 | * Iomega Zip 100/250 | ||
18 | * Iomega PC Card Clik!/PocketZip | ||
19 | * | ||
20 | * Many thanks to Lode Leroy <Lode.Leroy@www.ibase.be>, who tested so many | ||
21 | * ALPHA patches to this driver on an EASYSTOR LS-120 ATAPI floppy drive. | ||
22 | * | ||
23 | * Ver 0.1 Oct 17 96 Initial test version, mostly based on ide-tape.c. | ||
24 | * Ver 0.2 Oct 31 96 Minor changes. | ||
25 | * Ver 0.3 Dec 2 96 Fixed error recovery bug. | ||
26 | * Ver 0.4 Jan 26 97 Add support for the HDIO_GETGEO ioctl. | ||
27 | * Ver 0.5 Feb 21 97 Add partitions support. | ||
28 | * Use the minimum of the LBA and CHS capacities. | ||
29 | * Avoid hwgroup->rq == NULL on the last irq. | ||
30 | * Fix potential null dereferencing with DEBUG_LOG. | ||
31 | * Ver 0.8 Dec 7 97 Increase irq timeout from 10 to 50 seconds. | ||
32 | * Add media write-protect detection. | ||
33 | * Issue START command only if TEST UNIT READY fails. | ||
34 | * Add work-around for IOMEGA ZIP revision 21.D. | ||
35 | * Remove idefloppy_get_capabilities(). | ||
36 | * Ver 0.9 Jul 4 99 Fix a bug which might have caused the number of | ||
37 | * bytes requested on each interrupt to be zero. | ||
38 | * Thanks to <shanos@es.co.nz> for pointing this out. | ||
39 | * Ver 0.9.sv Jan 6 01 Sam Varshavchik <mrsam@courier-mta.com> | ||
40 | * Implement low level formatting. Reimplemented | ||
41 | * IDEFLOPPY_CAPABILITIES_PAGE, since we need the srfp | ||
42 | * bit. My LS-120 drive barfs on | ||
43 | * IDEFLOPPY_CAPABILITIES_PAGE, but maybe it's just me. | ||
44 | * Compromise by not reporting a failure to get this | ||
45 | * mode page. Implemented four IOCTLs in order to | ||
46 | * implement formatting. IOCTls begin with 0x4600, | ||
47 | * 0x46 is 'F' as in Format. | ||
48 | * Jan 9 01 Userland option to select format verify. | ||
49 | * Added PC_SUPPRESS_ERROR flag - some idefloppy drives | ||
50 | * do not implement IDEFLOPPY_CAPABILITIES_PAGE, and | ||
51 | * return a sense error. Suppress error reporting in | ||
52 | * this particular case in order to avoid spurious | ||
53 | * errors in syslog. The culprit is | ||
54 | * idefloppy_get_capability_page(), so move it to | ||
55 | * idefloppy_begin_format() so that it's not used | ||
56 | * unless absolutely necessary. | ||
57 | * If drive does not support format progress indication | ||
58 | * monitor the dsc bit in the status register. | ||
59 | * Also, O_NDELAY on open will allow the device to be | ||
60 | * opened without a disk available. This can be used to | ||
61 | * open an unformatted disk, or get the device capacity. | ||
62 | * Ver 0.91 Dec 11 99 Added IOMEGA Clik! drive support by | ||
63 | * <paul@paulbristow.net> | ||
64 | * Ver 0.92 Oct 22 00 Paul Bristow became official maintainer for this | ||
65 | * driver. Included Powerbook internal zip kludge. | ||
66 | * Ver 0.93 Oct 24 00 Fixed bugs for Clik! drive | ||
67 | * no disk on insert and disk change now works | ||
68 | * Ver 0.94 Oct 27 00 Tidied up to remove strstr(Clik) everywhere | ||
69 | * Ver 0.95 Nov 7 00 Brought across to kernel 2.4 | ||
70 | * Ver 0.96 Jan 7 01 Actually in line with release version of 2.4.0 | ||
71 | * including set_bit patch from Rusty Russell | ||
72 | * Ver 0.97 Jul 22 01 Merge 0.91-0.96 onto 0.9.sv for ac series | ||
73 | * Ver 0.97.sv Aug 3 01 Backported from 2.4.7-ac3 | ||
74 | * Ver 0.98 Oct 26 01 Split idefloppy_transfer_pc into two pieces to | ||
75 | * fix a lost interrupt problem. It appears the busy | ||
76 | * bit was being deasserted by my IOMEGA ATAPI ZIP 100 | ||
77 | * drive before the drive was actually ready. | ||
78 | * Ver 0.98a Oct 29 01 Expose delay value so we can play. | ||
79 | * Ver 0.99 Feb 24 02 Remove duplicate code, modify clik! detection code | ||
80 | * to support new PocketZip drives | ||
81 | */ | ||
82 | |||
83 | #define IDEFLOPPY_VERSION "0.99.newide" | ||
84 | |||
85 | #include <linux/config.h> | ||
86 | #include <linux/module.h> | ||
87 | #include <linux/types.h> | ||
88 | #include <linux/string.h> | ||
89 | #include <linux/kernel.h> | ||
90 | #include <linux/delay.h> | ||
91 | #include <linux/timer.h> | ||
92 | #include <linux/mm.h> | ||
93 | #include <linux/interrupt.h> | ||
94 | #include <linux/major.h> | ||
95 | #include <linux/errno.h> | ||
96 | #include <linux/genhd.h> | ||
97 | #include <linux/slab.h> | ||
98 | #include <linux/cdrom.h> | ||
99 | #include <linux/ide.h> | ||
100 | #include <linux/bitops.h> | ||
101 | |||
102 | #include <asm/byteorder.h> | ||
103 | #include <asm/irq.h> | ||
104 | #include <asm/uaccess.h> | ||
105 | #include <asm/io.h> | ||
106 | #include <asm/unaligned.h> | ||
107 | |||
108 | /* | ||
109 | * The following are used to debug the driver. | ||
110 | */ | ||
111 | #define IDEFLOPPY_DEBUG_LOG 0 | ||
112 | #define IDEFLOPPY_DEBUG_INFO 0 | ||
113 | #define IDEFLOPPY_DEBUG_BUGS 1 | ||
114 | |||
115 | /* #define IDEFLOPPY_DEBUG(fmt, args...) printk(KERN_INFO fmt, ## args) */ | ||
116 | #define IDEFLOPPY_DEBUG( fmt, args... ) | ||
117 | |||
118 | #if IDEFLOPPY_DEBUG_LOG | ||
119 | #define debug_log printk | ||
120 | #else | ||
121 | #define debug_log(fmt, args... ) do {} while(0) | ||
122 | #endif | ||
123 | |||
124 | |||
125 | /* | ||
126 | * Some drives require a longer irq timeout. | ||
127 | */ | ||
128 | #define IDEFLOPPY_WAIT_CMD (5 * WAIT_CMD) | ||
129 | |||
130 | /* | ||
131 | * After each failed packet command we issue a request sense command | ||
132 | * and retry the packet command IDEFLOPPY_MAX_PC_RETRIES times. | ||
133 | */ | ||
134 | #define IDEFLOPPY_MAX_PC_RETRIES 3 | ||
135 | |||
136 | /* | ||
137 | * With each packet command, we allocate a buffer of | ||
138 | * IDEFLOPPY_PC_BUFFER_SIZE bytes. | ||
139 | */ | ||
140 | #define IDEFLOPPY_PC_BUFFER_SIZE 256 | ||
141 | |||
142 | /* | ||
143 | * In various places in the driver, we need to allocate storage | ||
144 | * for packet commands and requests, which will remain valid while | ||
145 | * we leave the driver to wait for an interrupt or a timeout event. | ||
146 | */ | ||
147 | #define IDEFLOPPY_PC_STACK (10 + IDEFLOPPY_MAX_PC_RETRIES) | ||
148 | |||
149 | /* | ||
150 | * Our view of a packet command. | ||
151 | */ | ||
152 | typedef struct idefloppy_packet_command_s { | ||
153 | u8 c[12]; /* Actual packet bytes */ | ||
154 | int retries; /* On each retry, we increment retries */ | ||
155 | int error; /* Error code */ | ||
156 | int request_transfer; /* Bytes to transfer */ | ||
157 | int actually_transferred; /* Bytes actually transferred */ | ||
158 | int buffer_size; /* Size of our data buffer */ | ||
159 | int b_count; /* Missing/Available data on the current buffer */ | ||
160 | struct request *rq; /* The corresponding request */ | ||
161 | u8 *buffer; /* Data buffer */ | ||
162 | u8 *current_position; /* Pointer into the above buffer */ | ||
163 | void (*callback) (ide_drive_t *); /* Called when this packet command is completed */ | ||
164 | u8 pc_buffer[IDEFLOPPY_PC_BUFFER_SIZE]; /* Temporary buffer */ | ||
165 | unsigned long flags; /* Status/Action bit flags: long for set_bit */ | ||
166 | } idefloppy_pc_t; | ||
167 | |||
168 | /* | ||
169 | * Packet command flag bits. | ||
170 | */ | ||
171 | #define PC_ABORT 0 /* Set when an error is considered normal - We won't retry */ | ||
172 | #define PC_DMA_RECOMMENDED 2 /* 1 when we prefer to use DMA if possible */ | ||
173 | #define PC_DMA_IN_PROGRESS 3 /* 1 while DMA in progress */ | ||
174 | #define PC_DMA_ERROR 4 /* 1 when encountered problem during DMA */ | ||
175 | #define PC_WRITING 5 /* Data direction */ | ||
176 | |||
177 | #define PC_SUPPRESS_ERROR 6 /* Suppress error reporting */ | ||
178 | |||
179 | /* | ||
180 | * Removable Block Access Capabilities Page | ||
181 | */ | ||
182 | typedef struct { | ||
183 | #if defined(__LITTLE_ENDIAN_BITFIELD) | ||
184 | unsigned page_code :6; /* Page code - Should be 0x1b */ | ||
185 | unsigned reserved1_6 :1; /* Reserved */ | ||
186 | unsigned ps :1; /* Should be 0 */ | ||
187 | #elif defined(__BIG_ENDIAN_BITFIELD) | ||
188 | unsigned ps :1; /* Should be 0 */ | ||
189 | unsigned reserved1_6 :1; /* Reserved */ | ||
190 | unsigned page_code :6; /* Page code - Should be 0x1b */ | ||
191 | #else | ||
192 | #error "Bitfield endianness not defined! Check your byteorder.h" | ||
193 | #endif | ||
194 | u8 page_length; /* Page Length - Should be 0xa */ | ||
195 | #if defined(__LITTLE_ENDIAN_BITFIELD) | ||
196 | unsigned reserved2 :6; | ||
197 | unsigned srfp :1; /* Supports reporting progress of format */ | ||
198 | unsigned sflp :1; /* System floppy type device */ | ||
199 | unsigned tlun :3; /* Total logical units supported by the device */ | ||
200 | unsigned reserved3 :3; | ||
201 | unsigned sml :1; /* Single / Multiple lun supported */ | ||
202 | unsigned ncd :1; /* Non cd optical device */ | ||
203 | #elif defined(__BIG_ENDIAN_BITFIELD) | ||
204 | unsigned sflp :1; /* System floppy type device */ | ||
205 | unsigned srfp :1; /* Supports reporting progress of format */ | ||
206 | unsigned reserved2 :6; | ||
207 | unsigned ncd :1; /* Non cd optical device */ | ||
208 | unsigned sml :1; /* Single / Multiple lun supported */ | ||
209 | unsigned reserved3 :3; | ||
210 | unsigned tlun :3; /* Total logical units supported by the device */ | ||
211 | #else | ||
212 | #error "Bitfield endianness not defined! Check your byteorder.h" | ||
213 | #endif | ||
214 | u8 reserved[8]; | ||
215 | } idefloppy_capabilities_page_t; | ||
216 | |||
217 | /* | ||
218 | * Flexible disk page. | ||
219 | */ | ||
220 | typedef struct { | ||
221 | #if defined(__LITTLE_ENDIAN_BITFIELD) | ||
222 | unsigned page_code :6; /* Page code - Should be 0x5 */ | ||
223 | unsigned reserved1_6 :1; /* Reserved */ | ||
224 | unsigned ps :1; /* The device is capable of saving the page */ | ||
225 | #elif defined(__BIG_ENDIAN_BITFIELD) | ||
226 | unsigned ps :1; /* The device is capable of saving the page */ | ||
227 | unsigned reserved1_6 :1; /* Reserved */ | ||
228 | unsigned page_code :6; /* Page code - Should be 0x5 */ | ||
229 | #else | ||
230 | #error "Bitfield endianness not defined! Check your byteorder.h" | ||
231 | #endif | ||
232 | u8 page_length; /* Page Length - Should be 0x1e */ | ||
233 | u16 transfer_rate; /* In kilobits per second */ | ||
234 | u8 heads, sectors; /* Number of heads, Number of sectors per track */ | ||
235 | u16 sector_size; /* Byes per sector */ | ||
236 | u16 cyls; /* Number of cylinders */ | ||
237 | u8 reserved10[10]; | ||
238 | u8 motor_delay; /* Motor off delay */ | ||
239 | u8 reserved21[7]; | ||
240 | u16 rpm; /* Rotations per minute */ | ||
241 | u8 reserved30[2]; | ||
242 | } idefloppy_flexible_disk_page_t; | ||
243 | |||
244 | /* | ||
245 | * Format capacity | ||
246 | */ | ||
247 | typedef struct { | ||
248 | u8 reserved[3]; | ||
249 | u8 length; /* Length of the following descriptors in bytes */ | ||
250 | } idefloppy_capacity_header_t; | ||
251 | |||
252 | typedef struct { | ||
253 | u32 blocks; /* Number of blocks */ | ||
254 | #if defined(__LITTLE_ENDIAN_BITFIELD) | ||
255 | unsigned dc :2; /* Descriptor Code */ | ||
256 | unsigned reserved :6; | ||
257 | #elif defined(__BIG_ENDIAN_BITFIELD) | ||
258 | unsigned reserved :6; | ||
259 | unsigned dc :2; /* Descriptor Code */ | ||
260 | #else | ||
261 | #error "Bitfield endianness not defined! Check your byteorder.h" | ||
262 | #endif | ||
263 | u8 length_msb; /* Block Length (MSB)*/ | ||
264 | u16 length; /* Block Length */ | ||
265 | } idefloppy_capacity_descriptor_t; | ||
266 | |||
267 | #define CAPACITY_INVALID 0x00 | ||
268 | #define CAPACITY_UNFORMATTED 0x01 | ||
269 | #define CAPACITY_CURRENT 0x02 | ||
270 | #define CAPACITY_NO_CARTRIDGE 0x03 | ||
271 | |||
272 | /* | ||
273 | * Most of our global data which we need to save even as we leave the | ||
274 | * driver due to an interrupt or a timer event is stored in a variable | ||
275 | * of type idefloppy_floppy_t, defined below. | ||
276 | */ | ||
277 | typedef struct ide_floppy_obj { | ||
278 | ide_drive_t *drive; | ||
279 | ide_driver_t *driver; | ||
280 | struct gendisk *disk; | ||
281 | struct kref kref; | ||
282 | |||
283 | /* Current packet command */ | ||
284 | idefloppy_pc_t *pc; | ||
285 | /* Last failed packet command */ | ||
286 | idefloppy_pc_t *failed_pc; | ||
287 | /* Packet command stack */ | ||
288 | idefloppy_pc_t pc_stack[IDEFLOPPY_PC_STACK]; | ||
289 | /* Next free packet command storage space */ | ||
290 | int pc_stack_index; | ||
291 | struct request rq_stack[IDEFLOPPY_PC_STACK]; | ||
292 | /* We implement a circular array */ | ||
293 | int rq_stack_index; | ||
294 | |||
295 | /* | ||
296 | * Last error information | ||
297 | */ | ||
298 | u8 sense_key, asc, ascq; | ||
299 | /* delay this long before sending packet command */ | ||
300 | u8 ticks; | ||
301 | int progress_indication; | ||
302 | |||
303 | /* | ||
304 | * Device information | ||
305 | */ | ||
306 | /* Current format */ | ||
307 | int blocks, block_size, bs_factor; | ||
308 | /* Last format capacity */ | ||
309 | idefloppy_capacity_descriptor_t capacity; | ||
310 | /* Copy of the flexible disk page */ | ||
311 | idefloppy_flexible_disk_page_t flexible_disk_page; | ||
312 | /* Write protect */ | ||
313 | int wp; | ||
314 | /* Supports format progress report */ | ||
315 | int srfp; | ||
316 | /* Status/Action flags */ | ||
317 | unsigned long flags; | ||
318 | } idefloppy_floppy_t; | ||
319 | |||
320 | #define IDEFLOPPY_TICKS_DELAY 3 /* default delay for ZIP 100 */ | ||
321 | |||
322 | /* | ||
323 | * Floppy flag bits values. | ||
324 | */ | ||
325 | #define IDEFLOPPY_DRQ_INTERRUPT 0 /* DRQ interrupt device */ | ||
326 | #define IDEFLOPPY_MEDIA_CHANGED 1 /* Media may have changed */ | ||
327 | #define IDEFLOPPY_USE_READ12 2 /* Use READ12/WRITE12 or READ10/WRITE10 */ | ||
328 | #define IDEFLOPPY_FORMAT_IN_PROGRESS 3 /* Format in progress */ | ||
329 | #define IDEFLOPPY_CLIK_DRIVE 4 /* Avoid commands not supported in Clik drive */ | ||
330 | #define IDEFLOPPY_ZIP_DRIVE 5 /* Requires BH algorithm for packets */ | ||
331 | |||
332 | /* | ||
333 | * ATAPI floppy drive packet commands | ||
334 | */ | ||
335 | #define IDEFLOPPY_FORMAT_UNIT_CMD 0x04 | ||
336 | #define IDEFLOPPY_INQUIRY_CMD 0x12 | ||
337 | #define IDEFLOPPY_MODE_SELECT_CMD 0x55 | ||
338 | #define IDEFLOPPY_MODE_SENSE_CMD 0x5a | ||
339 | #define IDEFLOPPY_READ10_CMD 0x28 | ||
340 | #define IDEFLOPPY_READ12_CMD 0xa8 | ||
341 | #define IDEFLOPPY_READ_CAPACITY_CMD 0x23 | ||
342 | #define IDEFLOPPY_REQUEST_SENSE_CMD 0x03 | ||
343 | #define IDEFLOPPY_PREVENT_REMOVAL_CMD 0x1e | ||
344 | #define IDEFLOPPY_SEEK_CMD 0x2b | ||
345 | #define IDEFLOPPY_START_STOP_CMD 0x1b | ||
346 | #define IDEFLOPPY_TEST_UNIT_READY_CMD 0x00 | ||
347 | #define IDEFLOPPY_VERIFY_CMD 0x2f | ||
348 | #define IDEFLOPPY_WRITE10_CMD 0x2a | ||
349 | #define IDEFLOPPY_WRITE12_CMD 0xaa | ||
350 | #define IDEFLOPPY_WRITE_VERIFY_CMD 0x2e | ||
351 | |||
352 | /* | ||
353 | * Defines for the mode sense command | ||
354 | */ | ||
355 | #define MODE_SENSE_CURRENT 0x00 | ||
356 | #define MODE_SENSE_CHANGEABLE 0x01 | ||
357 | #define MODE_SENSE_DEFAULT 0x02 | ||
358 | #define MODE_SENSE_SAVED 0x03 | ||
359 | |||
360 | /* | ||
361 | * IOCTLs used in low-level formatting. | ||
362 | */ | ||
363 | |||
364 | #define IDEFLOPPY_IOCTL_FORMAT_SUPPORTED 0x4600 | ||
365 | #define IDEFLOPPY_IOCTL_FORMAT_GET_CAPACITY 0x4601 | ||
366 | #define IDEFLOPPY_IOCTL_FORMAT_START 0x4602 | ||
367 | #define IDEFLOPPY_IOCTL_FORMAT_GET_PROGRESS 0x4603 | ||
368 | |||
369 | #if 0 | ||
370 | /* | ||
371 | * Special requests for our block device strategy routine. | ||
372 | */ | ||
373 | #define IDEFLOPPY_FIRST_RQ 90 | ||
374 | |||
375 | /* | ||
376 | * IDEFLOPPY_PC_RQ is used to queue a packet command in the request queue. | ||
377 | */ | ||
378 | #define IDEFLOPPY_PC_RQ 90 | ||
379 | |||
380 | #define IDEFLOPPY_LAST_RQ 90 | ||
381 | |||
382 | /* | ||
383 | * A macro which can be used to check if a given request command | ||
384 | * originated in the driver or in the buffer cache layer. | ||
385 | */ | ||
386 | #define IDEFLOPPY_RQ_CMD(cmd) ((cmd >= IDEFLOPPY_FIRST_RQ) && (cmd <= IDEFLOPPY_LAST_RQ)) | ||
387 | |||
388 | #endif | ||
389 | |||
390 | /* | ||
391 | * Error codes which are returned in rq->errors to the higher part | ||
392 | * of the driver. | ||
393 | */ | ||
394 | #define IDEFLOPPY_ERROR_GENERAL 101 | ||
395 | |||
396 | /* | ||
397 | * The following is used to format the general configuration word of | ||
398 | * the ATAPI IDENTIFY DEVICE command. | ||
399 | */ | ||
400 | struct idefloppy_id_gcw { | ||
401 | #if defined(__LITTLE_ENDIAN_BITFIELD) | ||
402 | unsigned packet_size :2; /* Packet Size */ | ||
403 | unsigned reserved234 :3; /* Reserved */ | ||
404 | unsigned drq_type :2; /* Command packet DRQ type */ | ||
405 | unsigned removable :1; /* Removable media */ | ||
406 | unsigned device_type :5; /* Device type */ | ||
407 | unsigned reserved13 :1; /* Reserved */ | ||
408 | unsigned protocol :2; /* Protocol type */ | ||
409 | #elif defined(__BIG_ENDIAN_BITFIELD) | ||
410 | unsigned protocol :2; /* Protocol type */ | ||
411 | unsigned reserved13 :1; /* Reserved */ | ||
412 | unsigned device_type :5; /* Device type */ | ||
413 | unsigned removable :1; /* Removable media */ | ||
414 | unsigned drq_type :2; /* Command packet DRQ type */ | ||
415 | unsigned reserved234 :3; /* Reserved */ | ||
416 | unsigned packet_size :2; /* Packet Size */ | ||
417 | #else | ||
418 | #error "Bitfield endianness not defined! Check your byteorder.h" | ||
419 | #endif | ||
420 | }; | ||
421 | |||
422 | /* | ||
423 | * INQUIRY packet command - Data Format | ||
424 | */ | ||
425 | typedef struct { | ||
426 | #if defined(__LITTLE_ENDIAN_BITFIELD) | ||
427 | unsigned device_type :5; /* Peripheral Device Type */ | ||
428 | unsigned reserved0_765 :3; /* Peripheral Qualifier - Reserved */ | ||
429 | unsigned reserved1_6t0 :7; /* Reserved */ | ||
430 | unsigned rmb :1; /* Removable Medium Bit */ | ||
431 | unsigned ansi_version :3; /* ANSI Version */ | ||
432 | unsigned ecma_version :3; /* ECMA Version */ | ||
433 | unsigned iso_version :2; /* ISO Version */ | ||
434 | unsigned response_format :4; /* Response Data Format */ | ||
435 | unsigned reserved3_45 :2; /* Reserved */ | ||
436 | unsigned reserved3_6 :1; /* TrmIOP - Reserved */ | ||
437 | unsigned reserved3_7 :1; /* AENC - Reserved */ | ||
438 | #elif defined(__BIG_ENDIAN_BITFIELD) | ||
439 | unsigned reserved0_765 :3; /* Peripheral Qualifier - Reserved */ | ||
440 | unsigned device_type :5; /* Peripheral Device Type */ | ||
441 | unsigned rmb :1; /* Removable Medium Bit */ | ||
442 | unsigned reserved1_6t0 :7; /* Reserved */ | ||
443 | unsigned iso_version :2; /* ISO Version */ | ||
444 | unsigned ecma_version :3; /* ECMA Version */ | ||
445 | unsigned ansi_version :3; /* ANSI Version */ | ||
446 | unsigned reserved3_7 :1; /* AENC - Reserved */ | ||
447 | unsigned reserved3_6 :1; /* TrmIOP - Reserved */ | ||
448 | unsigned reserved3_45 :2; /* Reserved */ | ||
449 | unsigned response_format :4; /* Response Data Format */ | ||
450 | #else | ||
451 | #error "Bitfield endianness not defined! Check your byteorder.h" | ||
452 | #endif | ||
453 | u8 additional_length; /* Additional Length (total_length-4) */ | ||
454 | u8 rsv5, rsv6, rsv7; /* Reserved */ | ||
455 | u8 vendor_id[8]; /* Vendor Identification */ | ||
456 | u8 product_id[16]; /* Product Identification */ | ||
457 | u8 revision_level[4]; /* Revision Level */ | ||
458 | u8 vendor_specific[20]; /* Vendor Specific - Optional */ | ||
459 | u8 reserved56t95[40]; /* Reserved - Optional */ | ||
460 | /* Additional information may be returned */ | ||
461 | } idefloppy_inquiry_result_t; | ||
462 | |||
463 | /* | ||
464 | * REQUEST SENSE packet command result - Data Format. | ||
465 | */ | ||
466 | typedef struct { | ||
467 | #if defined(__LITTLE_ENDIAN_BITFIELD) | ||
468 | unsigned error_code :7; /* Current error (0x70) */ | ||
469 | unsigned valid :1; /* The information field conforms to SFF-8070i */ | ||
470 | u8 reserved1 :8; /* Reserved */ | ||
471 | unsigned sense_key :4; /* Sense Key */ | ||
472 | unsigned reserved2_4 :1; /* Reserved */ | ||
473 | unsigned ili :1; /* Incorrect Length Indicator */ | ||
474 | unsigned reserved2_67 :2; | ||
475 | #elif defined(__BIG_ENDIAN_BITFIELD) | ||
476 | unsigned valid :1; /* The information field conforms to SFF-8070i */ | ||
477 | unsigned error_code :7; /* Current error (0x70) */ | ||
478 | u8 reserved1 :8; /* Reserved */ | ||
479 | unsigned reserved2_67 :2; | ||
480 | unsigned ili :1; /* Incorrect Length Indicator */ | ||
481 | unsigned reserved2_4 :1; /* Reserved */ | ||
482 | unsigned sense_key :4; /* Sense Key */ | ||
483 | #else | ||
484 | #error "Bitfield endianness not defined! Check your byteorder.h" | ||
485 | #endif | ||
486 | u32 information __attribute__ ((packed)); | ||
487 | u8 asl; /* Additional sense length (n-7) */ | ||
488 | u32 command_specific; /* Additional command specific information */ | ||
489 | u8 asc; /* Additional Sense Code */ | ||
490 | u8 ascq; /* Additional Sense Code Qualifier */ | ||
491 | u8 replaceable_unit_code; /* Field Replaceable Unit Code */ | ||
492 | u8 sksv[3]; | ||
493 | u8 pad[2]; /* Padding to 20 bytes */ | ||
494 | } idefloppy_request_sense_result_t; | ||
495 | |||
496 | /* | ||
497 | * Pages of the SELECT SENSE / MODE SENSE packet commands. | ||
498 | */ | ||
499 | #define IDEFLOPPY_CAPABILITIES_PAGE 0x1b | ||
500 | #define IDEFLOPPY_FLEXIBLE_DISK_PAGE 0x05 | ||
501 | |||
502 | /* | ||
503 | * Mode Parameter Header for the MODE SENSE packet command | ||
504 | */ | ||
505 | typedef struct { | ||
506 | u16 mode_data_length; /* Length of the following data transfer */ | ||
507 | u8 medium_type; /* Medium Type */ | ||
508 | #if defined(__LITTLE_ENDIAN_BITFIELD) | ||
509 | unsigned reserved3 :7; | ||
510 | unsigned wp :1; /* Write protect */ | ||
511 | #elif defined(__BIG_ENDIAN_BITFIELD) | ||
512 | unsigned wp :1; /* Write protect */ | ||
513 | unsigned reserved3 :7; | ||
514 | #else | ||
515 | #error "Bitfield endianness not defined! Check your byteorder.h" | ||
516 | #endif | ||
517 | u8 reserved[4]; | ||
518 | } idefloppy_mode_parameter_header_t; | ||
519 | |||
520 | static DECLARE_MUTEX(idefloppy_ref_sem); | ||
521 | |||
522 | #define to_ide_floppy(obj) container_of(obj, struct ide_floppy_obj, kref) | ||
523 | |||
524 | #define ide_floppy_g(disk) \ | ||
525 | container_of((disk)->private_data, struct ide_floppy_obj, driver) | ||
526 | |||
527 | static struct ide_floppy_obj *ide_floppy_get(struct gendisk *disk) | ||
528 | { | ||
529 | struct ide_floppy_obj *floppy = NULL; | ||
530 | |||
531 | down(&idefloppy_ref_sem); | ||
532 | floppy = ide_floppy_g(disk); | ||
533 | if (floppy) | ||
534 | kref_get(&floppy->kref); | ||
535 | up(&idefloppy_ref_sem); | ||
536 | return floppy; | ||
537 | } | ||
538 | |||
539 | static void ide_floppy_release(struct kref *); | ||
540 | |||
541 | static void ide_floppy_put(struct ide_floppy_obj *floppy) | ||
542 | { | ||
543 | down(&idefloppy_ref_sem); | ||
544 | kref_put(&floppy->kref, ide_floppy_release); | ||
545 | up(&idefloppy_ref_sem); | ||
546 | } | ||
547 | |||
548 | /* | ||
549 | * Too bad. The drive wants to send us data which we are not ready to accept. | ||
550 | * Just throw it away. | ||
551 | */ | ||
552 | static void idefloppy_discard_data (ide_drive_t *drive, unsigned int bcount) | ||
553 | { | ||
554 | while (bcount--) | ||
555 | (void) HWIF(drive)->INB(IDE_DATA_REG); | ||
556 | } | ||
557 | |||
558 | #if IDEFLOPPY_DEBUG_BUGS | ||
559 | static void idefloppy_write_zeros (ide_drive_t *drive, unsigned int bcount) | ||
560 | { | ||
561 | while (bcount--) | ||
562 | HWIF(drive)->OUTB(0, IDE_DATA_REG); | ||
563 | } | ||
564 | #endif /* IDEFLOPPY_DEBUG_BUGS */ | ||
565 | |||
566 | |||
567 | /* | ||
568 | * idefloppy_do_end_request is used to finish servicing a request. | ||
569 | * | ||
570 | * For read/write requests, we will call ide_end_request to pass to the | ||
571 | * next buffer. | ||
572 | */ | ||
573 | static int idefloppy_do_end_request(ide_drive_t *drive, int uptodate, int nsecs) | ||
574 | { | ||
575 | idefloppy_floppy_t *floppy = drive->driver_data; | ||
576 | struct request *rq = HWGROUP(drive)->rq; | ||
577 | int error; | ||
578 | |||
579 | debug_log(KERN_INFO "Reached idefloppy_end_request\n"); | ||
580 | |||
581 | switch (uptodate) { | ||
582 | case 0: error = IDEFLOPPY_ERROR_GENERAL; break; | ||
583 | case 1: error = 0; break; | ||
584 | default: error = uptodate; | ||
585 | } | ||
586 | if (error) | ||
587 | floppy->failed_pc = NULL; | ||
588 | /* Why does this happen? */ | ||
589 | if (!rq) | ||
590 | return 0; | ||
591 | if (!(rq->flags & REQ_SPECIAL)) { //if (!IDEFLOPPY_RQ_CMD (rq->cmd)) { | ||
592 | /* our real local end request function */ | ||
593 | ide_end_request(drive, uptodate, nsecs); | ||
594 | return 0; | ||
595 | } | ||
596 | rq->errors = error; | ||
597 | /* fixme: need to move this local also */ | ||
598 | ide_end_drive_cmd(drive, 0, 0); | ||
599 | return 0; | ||
600 | } | ||
601 | |||
602 | static void idefloppy_input_buffers (ide_drive_t *drive, idefloppy_pc_t *pc, unsigned int bcount) | ||
603 | { | ||
604 | struct request *rq = pc->rq; | ||
605 | struct bio_vec *bvec; | ||
606 | struct bio *bio; | ||
607 | unsigned long flags; | ||
608 | char *data; | ||
609 | int count, i, done = 0; | ||
610 | |||
611 | rq_for_each_bio(bio, rq) { | ||
612 | bio_for_each_segment(bvec, bio, i) { | ||
613 | if (!bcount) | ||
614 | break; | ||
615 | |||
616 | count = min(bvec->bv_len, bcount); | ||
617 | |||
618 | data = bvec_kmap_irq(bvec, &flags); | ||
619 | drive->hwif->atapi_input_bytes(drive, data, count); | ||
620 | bvec_kunmap_irq(data, &flags); | ||
621 | |||
622 | bcount -= count; | ||
623 | pc->b_count += count; | ||
624 | done += count; | ||
625 | } | ||
626 | } | ||
627 | |||
628 | idefloppy_do_end_request(drive, 1, done >> 9); | ||
629 | |||
630 | if (bcount) { | ||
631 | printk(KERN_ERR "%s: leftover data in idefloppy_input_buffers, bcount == %d\n", drive->name, bcount); | ||
632 | idefloppy_discard_data(drive, bcount); | ||
633 | } | ||
634 | } | ||
635 | |||
636 | static void idefloppy_output_buffers (ide_drive_t *drive, idefloppy_pc_t *pc, unsigned int bcount) | ||
637 | { | ||
638 | struct request *rq = pc->rq; | ||
639 | struct bio *bio; | ||
640 | struct bio_vec *bvec; | ||
641 | unsigned long flags; | ||
642 | int count, i, done = 0; | ||
643 | char *data; | ||
644 | |||
645 | rq_for_each_bio(bio, rq) { | ||
646 | bio_for_each_segment(bvec, bio, i) { | ||
647 | if (!bcount) | ||
648 | break; | ||
649 | |||
650 | count = min(bvec->bv_len, bcount); | ||
651 | |||
652 | data = bvec_kmap_irq(bvec, &flags); | ||
653 | drive->hwif->atapi_output_bytes(drive, data, count); | ||
654 | bvec_kunmap_irq(data, &flags); | ||
655 | |||
656 | bcount -= count; | ||
657 | pc->b_count += count; | ||
658 | done += count; | ||
659 | } | ||
660 | } | ||
661 | |||
662 | idefloppy_do_end_request(drive, 1, done >> 9); | ||
663 | |||
664 | if (bcount) { | ||
665 | printk(KERN_ERR "%s: leftover data in idefloppy_output_buffers, bcount == %d\n", drive->name, bcount); | ||
666 | idefloppy_write_zeros(drive, bcount); | ||
667 | } | ||
668 | } | ||
669 | |||
670 | static void idefloppy_update_buffers (ide_drive_t *drive, idefloppy_pc_t *pc) | ||
671 | { | ||
672 | struct request *rq = pc->rq; | ||
673 | struct bio *bio = rq->bio; | ||
674 | |||
675 | while ((bio = rq->bio) != NULL) | ||
676 | idefloppy_do_end_request(drive, 1, 0); | ||
677 | } | ||
678 | |||
679 | /* | ||
680 | * idefloppy_queue_pc_head generates a new packet command request in front | ||
681 | * of the request queue, before the current request, so that it will be | ||
682 | * processed immediately, on the next pass through the driver. | ||
683 | */ | ||
684 | static void idefloppy_queue_pc_head (ide_drive_t *drive,idefloppy_pc_t *pc,struct request *rq) | ||
685 | { | ||
686 | struct ide_floppy_obj *floppy = drive->driver_data; | ||
687 | |||
688 | ide_init_drive_cmd(rq); | ||
689 | rq->buffer = (char *) pc; | ||
690 | rq->flags = REQ_SPECIAL; //rq->cmd = IDEFLOPPY_PC_RQ; | ||
691 | rq->rq_disk = floppy->disk; | ||
692 | (void) ide_do_drive_cmd(drive, rq, ide_preempt); | ||
693 | } | ||
694 | |||
695 | static idefloppy_pc_t *idefloppy_next_pc_storage (ide_drive_t *drive) | ||
696 | { | ||
697 | idefloppy_floppy_t *floppy = drive->driver_data; | ||
698 | |||
699 | if (floppy->pc_stack_index == IDEFLOPPY_PC_STACK) | ||
700 | floppy->pc_stack_index=0; | ||
701 | return (&floppy->pc_stack[floppy->pc_stack_index++]); | ||
702 | } | ||
703 | |||
704 | static struct request *idefloppy_next_rq_storage (ide_drive_t *drive) | ||
705 | { | ||
706 | idefloppy_floppy_t *floppy = drive->driver_data; | ||
707 | |||
708 | if (floppy->rq_stack_index == IDEFLOPPY_PC_STACK) | ||
709 | floppy->rq_stack_index = 0; | ||
710 | return (&floppy->rq_stack[floppy->rq_stack_index++]); | ||
711 | } | ||
712 | |||
713 | /* | ||
714 | * idefloppy_analyze_error is called on each failed packet command retry | ||
715 | * to analyze the request sense. | ||
716 | */ | ||
717 | static void idefloppy_analyze_error (ide_drive_t *drive,idefloppy_request_sense_result_t *result) | ||
718 | { | ||
719 | idefloppy_floppy_t *floppy = drive->driver_data; | ||
720 | |||
721 | floppy->sense_key = result->sense_key; | ||
722 | floppy->asc = result->asc; | ||
723 | floppy->ascq = result->ascq; | ||
724 | floppy->progress_indication = result->sksv[0] & 0x80 ? | ||
725 | (u16)get_unaligned((u16 *)(result->sksv+1)):0x10000; | ||
726 | if (floppy->failed_pc) | ||
727 | debug_log(KERN_INFO "ide-floppy: pc = %x, sense key = %x, " | ||
728 | "asc = %x, ascq = %x\n", floppy->failed_pc->c[0], | ||
729 | result->sense_key, result->asc, result->ascq); | ||
730 | else | ||
731 | debug_log(KERN_INFO "ide-floppy: sense key = %x, asc = %x, " | ||
732 | "ascq = %x\n", result->sense_key, | ||
733 | result->asc, result->ascq); | ||
734 | } | ||
735 | |||
736 | static void idefloppy_request_sense_callback (ide_drive_t *drive) | ||
737 | { | ||
738 | idefloppy_floppy_t *floppy = drive->driver_data; | ||
739 | |||
740 | debug_log(KERN_INFO "ide-floppy: Reached %s\n", __FUNCTION__); | ||
741 | |||
742 | if (!floppy->pc->error) { | ||
743 | idefloppy_analyze_error(drive,(idefloppy_request_sense_result_t *) floppy->pc->buffer); | ||
744 | idefloppy_do_end_request(drive, 1, 0); | ||
745 | } else { | ||
746 | printk(KERN_ERR "Error in REQUEST SENSE itself - Aborting request!\n"); | ||
747 | idefloppy_do_end_request(drive, 0, 0); | ||
748 | } | ||
749 | } | ||
750 | |||
751 | /* | ||
752 | * General packet command callback function. | ||
753 | */ | ||
754 | static void idefloppy_pc_callback (ide_drive_t *drive) | ||
755 | { | ||
756 | idefloppy_floppy_t *floppy = drive->driver_data; | ||
757 | |||
758 | debug_log(KERN_INFO "ide-floppy: Reached %s\n", __FUNCTION__); | ||
759 | |||
760 | idefloppy_do_end_request(drive, floppy->pc->error ? 0 : 1, 0); | ||
761 | } | ||
762 | |||
763 | /* | ||
764 | * idefloppy_init_pc initializes a packet command. | ||
765 | */ | ||
766 | static void idefloppy_init_pc (idefloppy_pc_t *pc) | ||
767 | { | ||
768 | memset(pc->c, 0, 12); | ||
769 | pc->retries = 0; | ||
770 | pc->flags = 0; | ||
771 | pc->request_transfer = 0; | ||
772 | pc->buffer = pc->pc_buffer; | ||
773 | pc->buffer_size = IDEFLOPPY_PC_BUFFER_SIZE; | ||
774 | pc->callback = &idefloppy_pc_callback; | ||
775 | } | ||
776 | |||
777 | static void idefloppy_create_request_sense_cmd (idefloppy_pc_t *pc) | ||
778 | { | ||
779 | idefloppy_init_pc(pc); | ||
780 | pc->c[0] = IDEFLOPPY_REQUEST_SENSE_CMD; | ||
781 | pc->c[4] = 255; | ||
782 | pc->request_transfer = 18; | ||
783 | pc->callback = &idefloppy_request_sense_callback; | ||
784 | } | ||
785 | |||
786 | /* | ||
787 | * idefloppy_retry_pc is called when an error was detected during the | ||
788 | * last packet command. We queue a request sense packet command in | ||
789 | * the head of the request list. | ||
790 | */ | ||
791 | static void idefloppy_retry_pc (ide_drive_t *drive) | ||
792 | { | ||
793 | idefloppy_pc_t *pc; | ||
794 | struct request *rq; | ||
795 | atapi_error_t error; | ||
796 | |||
797 | error.all = HWIF(drive)->INB(IDE_ERROR_REG); | ||
798 | pc = idefloppy_next_pc_storage(drive); | ||
799 | rq = idefloppy_next_rq_storage(drive); | ||
800 | idefloppy_create_request_sense_cmd(pc); | ||
801 | idefloppy_queue_pc_head(drive, pc, rq); | ||
802 | } | ||
803 | |||
804 | /* | ||
805 | * idefloppy_pc_intr is the usual interrupt handler which will be called | ||
806 | * during a packet command. | ||
807 | */ | ||
808 | static ide_startstop_t idefloppy_pc_intr (ide_drive_t *drive) | ||
809 | { | ||
810 | idefloppy_floppy_t *floppy = drive->driver_data; | ||
811 | atapi_status_t status; | ||
812 | atapi_bcount_t bcount; | ||
813 | atapi_ireason_t ireason; | ||
814 | idefloppy_pc_t *pc = floppy->pc; | ||
815 | struct request *rq = pc->rq; | ||
816 | unsigned int temp; | ||
817 | |||
818 | debug_log(KERN_INFO "ide-floppy: Reached %s interrupt handler\n", | ||
819 | __FUNCTION__); | ||
820 | |||
821 | if (test_bit(PC_DMA_IN_PROGRESS, &pc->flags)) { | ||
822 | if (HWIF(drive)->ide_dma_end(drive)) { | ||
823 | set_bit(PC_DMA_ERROR, &pc->flags); | ||
824 | } else { | ||
825 | pc->actually_transferred = pc->request_transfer; | ||
826 | idefloppy_update_buffers(drive, pc); | ||
827 | } | ||
828 | debug_log(KERN_INFO "ide-floppy: DMA finished\n"); | ||
829 | } | ||
830 | |||
831 | /* Clear the interrupt */ | ||
832 | status.all = HWIF(drive)->INB(IDE_STATUS_REG); | ||
833 | |||
834 | if (!status.b.drq) { /* No more interrupts */ | ||
835 | debug_log(KERN_INFO "Packet command completed, %d bytes " | ||
836 | "transferred\n", pc->actually_transferred); | ||
837 | clear_bit(PC_DMA_IN_PROGRESS, &pc->flags); | ||
838 | |||
839 | local_irq_enable(); | ||
840 | |||
841 | if (status.b.check || test_bit(PC_DMA_ERROR, &pc->flags)) { | ||
842 | /* Error detected */ | ||
843 | debug_log(KERN_INFO "ide-floppy: %s: I/O error\n", | ||
844 | drive->name); | ||
845 | rq->errors++; | ||
846 | if (pc->c[0] == IDEFLOPPY_REQUEST_SENSE_CMD) { | ||
847 | printk(KERN_ERR "ide-floppy: I/O error in " | ||
848 | "request sense command\n"); | ||
849 | return ide_do_reset(drive); | ||
850 | } | ||
851 | /* Retry operation */ | ||
852 | idefloppy_retry_pc(drive); | ||
853 | /* queued, but not started */ | ||
854 | return ide_stopped; | ||
855 | } | ||
856 | pc->error = 0; | ||
857 | if (floppy->failed_pc == pc) | ||
858 | floppy->failed_pc = NULL; | ||
859 | /* Command finished - Call the callback function */ | ||
860 | pc->callback(drive); | ||
861 | return ide_stopped; | ||
862 | } | ||
863 | |||
864 | if (test_and_clear_bit(PC_DMA_IN_PROGRESS, &pc->flags)) { | ||
865 | printk(KERN_ERR "ide-floppy: The floppy wants to issue " | ||
866 | "more interrupts in DMA mode\n"); | ||
867 | (void)__ide_dma_off(drive); | ||
868 | return ide_do_reset(drive); | ||
869 | } | ||
870 | |||
871 | /* Get the number of bytes to transfer */ | ||
872 | bcount.b.high = HWIF(drive)->INB(IDE_BCOUNTH_REG); | ||
873 | bcount.b.low = HWIF(drive)->INB(IDE_BCOUNTL_REG); | ||
874 | /* on this interrupt */ | ||
875 | ireason.all = HWIF(drive)->INB(IDE_IREASON_REG); | ||
876 | |||
877 | if (ireason.b.cod) { | ||
878 | printk(KERN_ERR "ide-floppy: CoD != 0 in idefloppy_pc_intr\n"); | ||
879 | return ide_do_reset(drive); | ||
880 | } | ||
881 | if (ireason.b.io == test_bit(PC_WRITING, &pc->flags)) { | ||
882 | /* Hopefully, we will never get here */ | ||
883 | printk(KERN_ERR "ide-floppy: We wanted to %s, ", | ||
884 | ireason.b.io ? "Write":"Read"); | ||
885 | printk(KERN_ERR "but the floppy wants us to %s !\n", | ||
886 | ireason.b.io ? "Read":"Write"); | ||
887 | return ide_do_reset(drive); | ||
888 | } | ||
889 | if (!test_bit(PC_WRITING, &pc->flags)) { | ||
890 | /* Reading - Check that we have enough space */ | ||
891 | temp = pc->actually_transferred + bcount.all; | ||
892 | if (temp > pc->request_transfer) { | ||
893 | if (temp > pc->buffer_size) { | ||
894 | printk(KERN_ERR "ide-floppy: The floppy wants " | ||
895 | "to send us more data than expected " | ||
896 | "- discarding data\n"); | ||
897 | idefloppy_discard_data(drive,bcount.all); | ||
898 | if (HWGROUP(drive)->handler != NULL) | ||
899 | BUG(); | ||
900 | ide_set_handler(drive, | ||
901 | &idefloppy_pc_intr, | ||
902 | IDEFLOPPY_WAIT_CMD, | ||
903 | NULL); | ||
904 | return ide_started; | ||
905 | } | ||
906 | debug_log(KERN_NOTICE "ide-floppy: The floppy wants to " | ||
907 | "send us more data than expected - " | ||
908 | "allowing transfer\n"); | ||
909 | } | ||
910 | } | ||
911 | if (test_bit(PC_WRITING, &pc->flags)) { | ||
912 | if (pc->buffer != NULL) | ||
913 | /* Write the current buffer */ | ||
914 | HWIF(drive)->atapi_output_bytes(drive, | ||
915 | pc->current_position, | ||
916 | bcount.all); | ||
917 | else | ||
918 | idefloppy_output_buffers(drive, pc, bcount.all); | ||
919 | } else { | ||
920 | if (pc->buffer != NULL) | ||
921 | /* Read the current buffer */ | ||
922 | HWIF(drive)->atapi_input_bytes(drive, | ||
923 | pc->current_position, | ||
924 | bcount.all); | ||
925 | else | ||
926 | idefloppy_input_buffers(drive, pc, bcount.all); | ||
927 | } | ||
928 | /* Update the current position */ | ||
929 | pc->actually_transferred += bcount.all; | ||
930 | pc->current_position += bcount.all; | ||
931 | |||
932 | if (HWGROUP(drive)->handler != NULL) | ||
933 | BUG(); | ||
934 | ide_set_handler(drive, &idefloppy_pc_intr, IDEFLOPPY_WAIT_CMD, NULL); /* And set the interrupt handler again */ | ||
935 | return ide_started; | ||
936 | } | ||
937 | |||
938 | /* | ||
939 | * This is the original routine that did the packet transfer. | ||
940 | * It fails at high speeds on the Iomega ZIP drive, so there's a slower version | ||
941 | * for that drive below. The algorithm is chosen based on drive type | ||
942 | */ | ||
943 | static ide_startstop_t idefloppy_transfer_pc (ide_drive_t *drive) | ||
944 | { | ||
945 | ide_startstop_t startstop; | ||
946 | idefloppy_floppy_t *floppy = drive->driver_data; | ||
947 | atapi_ireason_t ireason; | ||
948 | |||
949 | if (ide_wait_stat(&startstop, drive, DRQ_STAT, BUSY_STAT, WAIT_READY)) { | ||
950 | printk(KERN_ERR "ide-floppy: Strange, packet command " | ||
951 | "initiated yet DRQ isn't asserted\n"); | ||
952 | return startstop; | ||
953 | } | ||
954 | ireason.all = HWIF(drive)->INB(IDE_IREASON_REG); | ||
955 | if (!ireason.b.cod || ireason.b.io) { | ||
956 | printk(KERN_ERR "ide-floppy: (IO,CoD) != (0,1) while " | ||
957 | "issuing a packet command\n"); | ||
958 | return ide_do_reset(drive); | ||
959 | } | ||
960 | if (HWGROUP(drive)->handler != NULL) | ||
961 | BUG(); | ||
962 | /* Set the interrupt routine */ | ||
963 | ide_set_handler(drive, &idefloppy_pc_intr, IDEFLOPPY_WAIT_CMD, NULL); | ||
964 | /* Send the actual packet */ | ||
965 | HWIF(drive)->atapi_output_bytes(drive, floppy->pc->c, 12); | ||
966 | return ide_started; | ||
967 | } | ||
968 | |||
969 | |||
970 | /* | ||
971 | * What we have here is a classic case of a top half / bottom half | ||
972 | * interrupt service routine. In interrupt mode, the device sends | ||
973 | * an interrupt to signal it's ready to receive a packet. However, | ||
974 | * we need to delay about 2-3 ticks before issuing the packet or we | ||
975 | * gets in trouble. | ||
976 | * | ||
977 | * So, follow carefully. transfer_pc1 is called as an interrupt (or | ||
978 | * directly). In either case, when the device says it's ready for a | ||
979 | * packet, we schedule the packet transfer to occur about 2-3 ticks | ||
980 | * later in transfer_pc2. | ||
981 | */ | ||
982 | static int idefloppy_transfer_pc2 (ide_drive_t *drive) | ||
983 | { | ||
984 | idefloppy_floppy_t *floppy = drive->driver_data; | ||
985 | |||
986 | /* Send the actual packet */ | ||
987 | HWIF(drive)->atapi_output_bytes(drive, floppy->pc->c, 12); | ||
988 | /* Timeout for the packet command */ | ||
989 | return IDEFLOPPY_WAIT_CMD; | ||
990 | } | ||
991 | |||
992 | static ide_startstop_t idefloppy_transfer_pc1 (ide_drive_t *drive) | ||
993 | { | ||
994 | idefloppy_floppy_t *floppy = drive->driver_data; | ||
995 | ide_startstop_t startstop; | ||
996 | atapi_ireason_t ireason; | ||
997 | |||
998 | if (ide_wait_stat(&startstop, drive, DRQ_STAT, BUSY_STAT, WAIT_READY)) { | ||
999 | printk(KERN_ERR "ide-floppy: Strange, packet command " | ||
1000 | "initiated yet DRQ isn't asserted\n"); | ||
1001 | return startstop; | ||
1002 | } | ||
1003 | ireason.all = HWIF(drive)->INB(IDE_IREASON_REG); | ||
1004 | if (!ireason.b.cod || ireason.b.io) { | ||
1005 | printk(KERN_ERR "ide-floppy: (IO,CoD) != (0,1) " | ||
1006 | "while issuing a packet command\n"); | ||
1007 | return ide_do_reset(drive); | ||
1008 | } | ||
1009 | /* | ||
1010 | * The following delay solves a problem with ATAPI Zip 100 drives | ||
1011 | * where the Busy flag was apparently being deasserted before the | ||
1012 | * unit was ready to receive data. This was happening on a | ||
1013 | * 1200 MHz Athlon system. 10/26/01 25msec is too short, | ||
1014 | * 40 and 50msec work well. idefloppy_pc_intr will not be actually | ||
1015 | * used until after the packet is moved in about 50 msec. | ||
1016 | */ | ||
1017 | if (HWGROUP(drive)->handler != NULL) | ||
1018 | BUG(); | ||
1019 | ide_set_handler(drive, | ||
1020 | &idefloppy_pc_intr, /* service routine for packet command */ | ||
1021 | floppy->ticks, /* wait this long before "failing" */ | ||
1022 | &idefloppy_transfer_pc2); /* fail == transfer_pc2 */ | ||
1023 | return ide_started; | ||
1024 | } | ||
1025 | |||
1026 | /** | ||
1027 | * idefloppy_should_report_error() | ||
1028 | * | ||
1029 | * Supresses error messages resulting from Medium not present | ||
1030 | */ | ||
1031 | static inline int idefloppy_should_report_error(idefloppy_floppy_t *floppy) | ||
1032 | { | ||
1033 | if (floppy->sense_key == 0x02 && | ||
1034 | floppy->asc == 0x3a && | ||
1035 | floppy->ascq == 0x00) | ||
1036 | return 0; | ||
1037 | return 1; | ||
1038 | } | ||
1039 | |||
1040 | /* | ||
1041 | * Issue a packet command | ||
1042 | */ | ||
1043 | static ide_startstop_t idefloppy_issue_pc (ide_drive_t *drive, idefloppy_pc_t *pc) | ||
1044 | { | ||
1045 | idefloppy_floppy_t *floppy = drive->driver_data; | ||
1046 | ide_hwif_t *hwif = drive->hwif; | ||
1047 | atapi_feature_t feature; | ||
1048 | atapi_bcount_t bcount; | ||
1049 | ide_handler_t *pkt_xfer_routine; | ||
1050 | |||
1051 | #if IDEFLOPPY_DEBUG_BUGS | ||
1052 | if (floppy->pc->c[0] == IDEFLOPPY_REQUEST_SENSE_CMD && | ||
1053 | pc->c[0] == IDEFLOPPY_REQUEST_SENSE_CMD) { | ||
1054 | printk(KERN_ERR "ide-floppy: possible ide-floppy.c bug - " | ||
1055 | "Two request sense in serial were issued\n"); | ||
1056 | } | ||
1057 | #endif /* IDEFLOPPY_DEBUG_BUGS */ | ||
1058 | |||
1059 | if (floppy->failed_pc == NULL && | ||
1060 | pc->c[0] != IDEFLOPPY_REQUEST_SENSE_CMD) | ||
1061 | floppy->failed_pc = pc; | ||
1062 | /* Set the current packet command */ | ||
1063 | floppy->pc = pc; | ||
1064 | |||
1065 | if (pc->retries > IDEFLOPPY_MAX_PC_RETRIES || | ||
1066 | test_bit(PC_ABORT, &pc->flags)) { | ||
1067 | /* | ||
1068 | * We will "abort" retrying a packet command in case | ||
1069 | * a legitimate error code was received. | ||
1070 | */ | ||
1071 | if (!test_bit(PC_ABORT, &pc->flags)) { | ||
1072 | if (!test_bit(PC_SUPPRESS_ERROR, &pc->flags)) { | ||
1073 | if (idefloppy_should_report_error(floppy)) | ||
1074 | printk(KERN_ERR "ide-floppy: %s: I/O error, " | ||
1075 | "pc = %2x, key = %2x, " | ||
1076 | "asc = %2x, ascq = %2x\n", | ||
1077 | drive->name, pc->c[0], | ||
1078 | floppy->sense_key, | ||
1079 | floppy->asc, floppy->ascq); | ||
1080 | } | ||
1081 | /* Giving up */ | ||
1082 | pc->error = IDEFLOPPY_ERROR_GENERAL; | ||
1083 | } | ||
1084 | floppy->failed_pc = NULL; | ||
1085 | pc->callback(drive); | ||
1086 | return ide_stopped; | ||
1087 | } | ||
1088 | |||
1089 | debug_log(KERN_INFO "Retry number - %d\n",pc->retries); | ||
1090 | |||
1091 | pc->retries++; | ||
1092 | /* We haven't transferred any data yet */ | ||
1093 | pc->actually_transferred = 0; | ||
1094 | pc->current_position = pc->buffer; | ||
1095 | bcount.all = min(pc->request_transfer, 63 * 1024); | ||
1096 | |||
1097 | if (test_and_clear_bit(PC_DMA_ERROR, &pc->flags)) { | ||
1098 | (void)__ide_dma_off(drive); | ||
1099 | } | ||
1100 | feature.all = 0; | ||
1101 | |||
1102 | if (test_bit(PC_DMA_RECOMMENDED, &pc->flags) && drive->using_dma) | ||
1103 | feature.b.dma = !hwif->dma_setup(drive); | ||
1104 | |||
1105 | if (IDE_CONTROL_REG) | ||
1106 | HWIF(drive)->OUTB(drive->ctl, IDE_CONTROL_REG); | ||
1107 | /* Use PIO/DMA */ | ||
1108 | HWIF(drive)->OUTB(feature.all, IDE_FEATURE_REG); | ||
1109 | HWIF(drive)->OUTB(bcount.b.high, IDE_BCOUNTH_REG); | ||
1110 | HWIF(drive)->OUTB(bcount.b.low, IDE_BCOUNTL_REG); | ||
1111 | HWIF(drive)->OUTB(drive->select.all, IDE_SELECT_REG); | ||
1112 | |||
1113 | if (feature.b.dma) { /* Begin DMA, if necessary */ | ||
1114 | set_bit(PC_DMA_IN_PROGRESS, &pc->flags); | ||
1115 | hwif->dma_start(drive); | ||
1116 | } | ||
1117 | |||
1118 | /* Can we transfer the packet when we get the interrupt or wait? */ | ||
1119 | if (test_bit(IDEFLOPPY_ZIP_DRIVE, &floppy->flags)) { | ||
1120 | /* wait */ | ||
1121 | pkt_xfer_routine = &idefloppy_transfer_pc1; | ||
1122 | } else { | ||
1123 | /* immediate */ | ||
1124 | pkt_xfer_routine = &idefloppy_transfer_pc; | ||
1125 | } | ||
1126 | |||
1127 | if (test_bit (IDEFLOPPY_DRQ_INTERRUPT, &floppy->flags)) { | ||
1128 | /* Issue the packet command */ | ||
1129 | ide_execute_command(drive, WIN_PACKETCMD, | ||
1130 | pkt_xfer_routine, | ||
1131 | IDEFLOPPY_WAIT_CMD, | ||
1132 | NULL); | ||
1133 | return ide_started; | ||
1134 | } else { | ||
1135 | /* Issue the packet command */ | ||
1136 | HWIF(drive)->OUTB(WIN_PACKETCMD, IDE_COMMAND_REG); | ||
1137 | return (*pkt_xfer_routine) (drive); | ||
1138 | } | ||
1139 | } | ||
1140 | |||
1141 | static void idefloppy_rw_callback (ide_drive_t *drive) | ||
1142 | { | ||
1143 | debug_log(KERN_INFO "ide-floppy: Reached idefloppy_rw_callback\n"); | ||
1144 | |||
1145 | idefloppy_do_end_request(drive, 1, 0); | ||
1146 | return; | ||
1147 | } | ||
1148 | |||
1149 | static void idefloppy_create_prevent_cmd (idefloppy_pc_t *pc, int prevent) | ||
1150 | { | ||
1151 | debug_log(KERN_INFO "ide-floppy: creating prevent removal command, " | ||
1152 | "prevent = %d\n", prevent); | ||
1153 | |||
1154 | idefloppy_init_pc(pc); | ||
1155 | pc->c[0] = IDEFLOPPY_PREVENT_REMOVAL_CMD; | ||
1156 | pc->c[4] = prevent; | ||
1157 | } | ||
1158 | |||
1159 | static void idefloppy_create_read_capacity_cmd (idefloppy_pc_t *pc) | ||
1160 | { | ||
1161 | idefloppy_init_pc(pc); | ||
1162 | pc->c[0] = IDEFLOPPY_READ_CAPACITY_CMD; | ||
1163 | pc->c[7] = 255; | ||
1164 | pc->c[8] = 255; | ||
1165 | pc->request_transfer = 255; | ||
1166 | } | ||
1167 | |||
1168 | static void idefloppy_create_format_unit_cmd (idefloppy_pc_t *pc, int b, int l, | ||
1169 | int flags) | ||
1170 | { | ||
1171 | idefloppy_init_pc(pc); | ||
1172 | pc->c[0] = IDEFLOPPY_FORMAT_UNIT_CMD; | ||
1173 | pc->c[1] = 0x17; | ||
1174 | |||
1175 | memset(pc->buffer, 0, 12); | ||
1176 | pc->buffer[1] = 0xA2; | ||
1177 | /* Default format list header, u8 1: FOV/DCRT/IMM bits set */ | ||
1178 | |||
1179 | if (flags & 1) /* Verify bit on... */ | ||
1180 | pc->buffer[1] ^= 0x20; /* ... turn off DCRT bit */ | ||
1181 | pc->buffer[3] = 8; | ||
1182 | |||
1183 | put_unaligned(htonl(b), (unsigned int *)(&pc->buffer[4])); | ||
1184 | put_unaligned(htonl(l), (unsigned int *)(&pc->buffer[8])); | ||
1185 | pc->buffer_size=12; | ||
1186 | set_bit(PC_WRITING, &pc->flags); | ||
1187 | } | ||
1188 | |||
1189 | /* | ||
1190 | * A mode sense command is used to "sense" floppy parameters. | ||
1191 | */ | ||
1192 | static void idefloppy_create_mode_sense_cmd (idefloppy_pc_t *pc, u8 page_code, u8 type) | ||
1193 | { | ||
1194 | u16 length = sizeof(idefloppy_mode_parameter_header_t); | ||
1195 | |||
1196 | idefloppy_init_pc(pc); | ||
1197 | pc->c[0] = IDEFLOPPY_MODE_SENSE_CMD; | ||
1198 | pc->c[1] = 0; | ||
1199 | pc->c[2] = page_code + (type << 6); | ||
1200 | |||
1201 | switch (page_code) { | ||
1202 | case IDEFLOPPY_CAPABILITIES_PAGE: | ||
1203 | length += 12; | ||
1204 | break; | ||
1205 | case IDEFLOPPY_FLEXIBLE_DISK_PAGE: | ||
1206 | length += 32; | ||
1207 | break; | ||
1208 | default: | ||
1209 | printk(KERN_ERR "ide-floppy: unsupported page code " | ||
1210 | "in create_mode_sense_cmd\n"); | ||
1211 | } | ||
1212 | put_unaligned(htons(length), (u16 *) &pc->c[7]); | ||
1213 | pc->request_transfer = length; | ||
1214 | } | ||
1215 | |||
1216 | static void idefloppy_create_start_stop_cmd (idefloppy_pc_t *pc, int start) | ||
1217 | { | ||
1218 | idefloppy_init_pc(pc); | ||
1219 | pc->c[0] = IDEFLOPPY_START_STOP_CMD; | ||
1220 | pc->c[4] = start; | ||
1221 | } | ||
1222 | |||
1223 | static void idefloppy_create_test_unit_ready_cmd(idefloppy_pc_t *pc) | ||
1224 | { | ||
1225 | idefloppy_init_pc(pc); | ||
1226 | pc->c[0] = IDEFLOPPY_TEST_UNIT_READY_CMD; | ||
1227 | } | ||
1228 | |||
1229 | static void idefloppy_create_rw_cmd (idefloppy_floppy_t *floppy, idefloppy_pc_t *pc, struct request *rq, unsigned long sector) | ||
1230 | { | ||
1231 | int block = sector / floppy->bs_factor; | ||
1232 | int blocks = rq->nr_sectors / floppy->bs_factor; | ||
1233 | int cmd = rq_data_dir(rq); | ||
1234 | |||
1235 | debug_log("create_rw1%d_cmd: block == %d, blocks == %d\n", | ||
1236 | 2 * test_bit (IDEFLOPPY_USE_READ12, &floppy->flags), | ||
1237 | block, blocks); | ||
1238 | |||
1239 | idefloppy_init_pc(pc); | ||
1240 | if (test_bit(IDEFLOPPY_USE_READ12, &floppy->flags)) { | ||
1241 | pc->c[0] = cmd == READ ? IDEFLOPPY_READ12_CMD : IDEFLOPPY_WRITE12_CMD; | ||
1242 | put_unaligned(htonl(blocks), (unsigned int *) &pc->c[6]); | ||
1243 | } else { | ||
1244 | pc->c[0] = cmd == READ ? IDEFLOPPY_READ10_CMD : IDEFLOPPY_WRITE10_CMD; | ||
1245 | put_unaligned(htons(blocks), (unsigned short *) &pc->c[7]); | ||
1246 | } | ||
1247 | put_unaligned(htonl(block), (unsigned int *) &pc->c[2]); | ||
1248 | pc->callback = &idefloppy_rw_callback; | ||
1249 | pc->rq = rq; | ||
1250 | pc->b_count = cmd == READ ? 0 : rq->bio->bi_size; | ||
1251 | if (rq->flags & REQ_RW) | ||
1252 | set_bit(PC_WRITING, &pc->flags); | ||
1253 | pc->buffer = NULL; | ||
1254 | pc->request_transfer = pc->buffer_size = blocks * floppy->block_size; | ||
1255 | set_bit(PC_DMA_RECOMMENDED, &pc->flags); | ||
1256 | } | ||
1257 | |||
1258 | static int | ||
1259 | idefloppy_blockpc_cmd(idefloppy_floppy_t *floppy, idefloppy_pc_t *pc, struct request *rq) | ||
1260 | { | ||
1261 | /* | ||
1262 | * just support eject for now, it would not be hard to make the | ||
1263 | * REQ_BLOCK_PC support fully-featured | ||
1264 | */ | ||
1265 | if (rq->cmd[0] != IDEFLOPPY_START_STOP_CMD) | ||
1266 | return 1; | ||
1267 | |||
1268 | idefloppy_init_pc(pc); | ||
1269 | memcpy(pc->c, rq->cmd, sizeof(pc->c)); | ||
1270 | return 0; | ||
1271 | } | ||
1272 | |||
1273 | /* | ||
1274 | * idefloppy_do_request is our request handling function. | ||
1275 | */ | ||
1276 | static ide_startstop_t idefloppy_do_request (ide_drive_t *drive, struct request *rq, sector_t block_s) | ||
1277 | { | ||
1278 | idefloppy_floppy_t *floppy = drive->driver_data; | ||
1279 | idefloppy_pc_t *pc; | ||
1280 | unsigned long block = (unsigned long)block_s; | ||
1281 | |||
1282 | debug_log(KERN_INFO "rq_status: %d, dev: %s, flags: %lx, errors: %d\n", | ||
1283 | rq->rq_status, | ||
1284 | rq->rq_disk ? rq->rq_disk->disk_name ? "?", | ||
1285 | rq->flags, rq->errors); | ||
1286 | debug_log(KERN_INFO "sector: %ld, nr_sectors: %ld, " | ||
1287 | "current_nr_sectors: %d\n", (long)rq->sector, | ||
1288 | rq->nr_sectors, rq->current_nr_sectors); | ||
1289 | |||
1290 | if (rq->errors >= ERROR_MAX) { | ||
1291 | if (floppy->failed_pc != NULL) { | ||
1292 | if (idefloppy_should_report_error(floppy)) | ||
1293 | printk(KERN_ERR "ide-floppy: %s: I/O error, pc = %2x," | ||
1294 | " key = %2x, asc = %2x, ascq = %2x\n", | ||
1295 | drive->name, floppy->failed_pc->c[0], | ||
1296 | floppy->sense_key, floppy->asc, floppy->ascq); | ||
1297 | } | ||
1298 | else | ||
1299 | printk(KERN_ERR "ide-floppy: %s: I/O error\n", | ||
1300 | drive->name); | ||
1301 | idefloppy_do_end_request(drive, 0, 0); | ||
1302 | return ide_stopped; | ||
1303 | } | ||
1304 | if (rq->flags & REQ_CMD) { | ||
1305 | if (((long)rq->sector % floppy->bs_factor) || | ||
1306 | (rq->nr_sectors % floppy->bs_factor)) { | ||
1307 | printk("%s: unsupported r/w request size\n", | ||
1308 | drive->name); | ||
1309 | idefloppy_do_end_request(drive, 0, 0); | ||
1310 | return ide_stopped; | ||
1311 | } | ||
1312 | pc = idefloppy_next_pc_storage(drive); | ||
1313 | idefloppy_create_rw_cmd(floppy, pc, rq, block); | ||
1314 | } else if (rq->flags & REQ_SPECIAL) { | ||
1315 | pc = (idefloppy_pc_t *) rq->buffer; | ||
1316 | } else if (rq->flags & REQ_BLOCK_PC) { | ||
1317 | pc = idefloppy_next_pc_storage(drive); | ||
1318 | if (idefloppy_blockpc_cmd(floppy, pc, rq)) { | ||
1319 | idefloppy_do_end_request(drive, 0, 0); | ||
1320 | return ide_stopped; | ||
1321 | } | ||
1322 | } else { | ||
1323 | blk_dump_rq_flags(rq, | ||
1324 | "ide-floppy: unsupported command in queue"); | ||
1325 | idefloppy_do_end_request(drive, 0, 0); | ||
1326 | return ide_stopped; | ||
1327 | } | ||
1328 | |||
1329 | pc->rq = rq; | ||
1330 | return idefloppy_issue_pc(drive, pc); | ||
1331 | } | ||
1332 | |||
1333 | /* | ||
1334 | * idefloppy_queue_pc_tail adds a special packet command request to the | ||
1335 | * tail of the request queue, and waits for it to be serviced. | ||
1336 | */ | ||
1337 | static int idefloppy_queue_pc_tail (ide_drive_t *drive,idefloppy_pc_t *pc) | ||
1338 | { | ||
1339 | struct ide_floppy_obj *floppy = drive->driver_data; | ||
1340 | struct request rq; | ||
1341 | |||
1342 | ide_init_drive_cmd (&rq); | ||
1343 | rq.buffer = (char *) pc; | ||
1344 | rq.flags = REQ_SPECIAL; // rq.cmd = IDEFLOPPY_PC_RQ; | ||
1345 | rq.rq_disk = floppy->disk; | ||
1346 | |||
1347 | return ide_do_drive_cmd(drive, &rq, ide_wait); | ||
1348 | } | ||
1349 | |||
1350 | /* | ||
1351 | * Look at the flexible disk page parameters. We will ignore the CHS | ||
1352 | * capacity parameters and use the LBA parameters instead. | ||
1353 | */ | ||
1354 | static int idefloppy_get_flexible_disk_page (ide_drive_t *drive) | ||
1355 | { | ||
1356 | idefloppy_floppy_t *floppy = drive->driver_data; | ||
1357 | idefloppy_pc_t pc; | ||
1358 | idefloppy_mode_parameter_header_t *header; | ||
1359 | idefloppy_flexible_disk_page_t *page; | ||
1360 | int capacity, lba_capacity; | ||
1361 | |||
1362 | idefloppy_create_mode_sense_cmd(&pc, IDEFLOPPY_FLEXIBLE_DISK_PAGE, MODE_SENSE_CURRENT); | ||
1363 | if (idefloppy_queue_pc_tail(drive,&pc)) { | ||
1364 | printk(KERN_ERR "ide-floppy: Can't get flexible disk " | ||
1365 | "page parameters\n"); | ||
1366 | return 1; | ||
1367 | } | ||
1368 | header = (idefloppy_mode_parameter_header_t *) pc.buffer; | ||
1369 | floppy->wp = header->wp; | ||
1370 | set_disk_ro(floppy->disk, floppy->wp); | ||
1371 | page = (idefloppy_flexible_disk_page_t *) (header + 1); | ||
1372 | |||
1373 | page->transfer_rate = ntohs(page->transfer_rate); | ||
1374 | page->sector_size = ntohs(page->sector_size); | ||
1375 | page->cyls = ntohs(page->cyls); | ||
1376 | page->rpm = ntohs(page->rpm); | ||
1377 | capacity = page->cyls * page->heads * page->sectors * page->sector_size; | ||
1378 | if (memcmp (page, &floppy->flexible_disk_page, sizeof (idefloppy_flexible_disk_page_t))) | ||
1379 | printk(KERN_INFO "%s: %dkB, %d/%d/%d CHS, %d kBps, " | ||
1380 | "%d sector size, %d rpm\n", | ||
1381 | drive->name, capacity / 1024, page->cyls, | ||
1382 | page->heads, page->sectors, | ||
1383 | page->transfer_rate / 8, page->sector_size, page->rpm); | ||
1384 | |||
1385 | floppy->flexible_disk_page = *page; | ||
1386 | drive->bios_cyl = page->cyls; | ||
1387 | drive->bios_head = page->heads; | ||
1388 | drive->bios_sect = page->sectors; | ||
1389 | lba_capacity = floppy->blocks * floppy->block_size; | ||
1390 | if (capacity < lba_capacity) { | ||
1391 | printk(KERN_NOTICE "%s: The disk reports a capacity of %d " | ||
1392 | "bytes, but the drive only handles %d\n", | ||
1393 | drive->name, lba_capacity, capacity); | ||
1394 | floppy->blocks = floppy->block_size ? capacity / floppy->block_size : 0; | ||
1395 | } | ||
1396 | return 0; | ||
1397 | } | ||
1398 | |||
1399 | static int idefloppy_get_capability_page(ide_drive_t *drive) | ||
1400 | { | ||
1401 | idefloppy_floppy_t *floppy = drive->driver_data; | ||
1402 | idefloppy_pc_t pc; | ||
1403 | idefloppy_mode_parameter_header_t *header; | ||
1404 | idefloppy_capabilities_page_t *page; | ||
1405 | |||
1406 | floppy->srfp = 0; | ||
1407 | idefloppy_create_mode_sense_cmd(&pc, IDEFLOPPY_CAPABILITIES_PAGE, | ||
1408 | MODE_SENSE_CURRENT); | ||
1409 | |||
1410 | set_bit(PC_SUPPRESS_ERROR, &pc.flags); | ||
1411 | if (idefloppy_queue_pc_tail(drive,&pc)) { | ||
1412 | return 1; | ||
1413 | } | ||
1414 | |||
1415 | header = (idefloppy_mode_parameter_header_t *) pc.buffer; | ||
1416 | page= (idefloppy_capabilities_page_t *)(header+1); | ||
1417 | floppy->srfp = page->srfp; | ||
1418 | return (0); | ||
1419 | } | ||
1420 | |||
1421 | /* | ||
1422 | * Determine if a media is present in the floppy drive, and if so, | ||
1423 | * its LBA capacity. | ||
1424 | */ | ||
1425 | static int idefloppy_get_capacity (ide_drive_t *drive) | ||
1426 | { | ||
1427 | idefloppy_floppy_t *floppy = drive->driver_data; | ||
1428 | idefloppy_pc_t pc; | ||
1429 | idefloppy_capacity_header_t *header; | ||
1430 | idefloppy_capacity_descriptor_t *descriptor; | ||
1431 | int i, descriptors, rc = 1, blocks, length; | ||
1432 | |||
1433 | drive->bios_cyl = 0; | ||
1434 | drive->bios_head = drive->bios_sect = 0; | ||
1435 | floppy->blocks = floppy->bs_factor = 0; | ||
1436 | set_capacity(floppy->disk, 0); | ||
1437 | |||
1438 | idefloppy_create_read_capacity_cmd(&pc); | ||
1439 | if (idefloppy_queue_pc_tail(drive, &pc)) { | ||
1440 | printk(KERN_ERR "ide-floppy: Can't get floppy parameters\n"); | ||
1441 | return 1; | ||
1442 | } | ||
1443 | header = (idefloppy_capacity_header_t *) pc.buffer; | ||
1444 | descriptors = header->length / sizeof(idefloppy_capacity_descriptor_t); | ||
1445 | descriptor = (idefloppy_capacity_descriptor_t *) (header + 1); | ||
1446 | |||
1447 | for (i = 0; i < descriptors; i++, descriptor++) { | ||
1448 | blocks = descriptor->blocks = ntohl(descriptor->blocks); | ||
1449 | length = descriptor->length = ntohs(descriptor->length); | ||
1450 | |||
1451 | if (!i) | ||
1452 | { | ||
1453 | switch (descriptor->dc) { | ||
1454 | /* Clik! drive returns this instead of CAPACITY_CURRENT */ | ||
1455 | case CAPACITY_UNFORMATTED: | ||
1456 | if (!test_bit(IDEFLOPPY_CLIK_DRIVE, &floppy->flags)) | ||
1457 | /* | ||
1458 | * If it is not a clik drive, break out | ||
1459 | * (maintains previous driver behaviour) | ||
1460 | */ | ||
1461 | break; | ||
1462 | case CAPACITY_CURRENT: | ||
1463 | /* Normal Zip/LS-120 disks */ | ||
1464 | if (memcmp(descriptor, &floppy->capacity, sizeof (idefloppy_capacity_descriptor_t))) | ||
1465 | printk(KERN_INFO "%s: %dkB, %d blocks, %d " | ||
1466 | "sector size\n", drive->name, | ||
1467 | blocks * length / 1024, blocks, length); | ||
1468 | floppy->capacity = *descriptor; | ||
1469 | if (!length || length % 512) { | ||
1470 | printk(KERN_NOTICE "%s: %d bytes block size " | ||
1471 | "not supported\n", drive->name, length); | ||
1472 | } else { | ||
1473 | floppy->blocks = blocks; | ||
1474 | floppy->block_size = length; | ||
1475 | if ((floppy->bs_factor = length / 512) != 1) | ||
1476 | printk(KERN_NOTICE "%s: warning: non " | ||
1477 | "512 bytes block size not " | ||
1478 | "fully supported\n", | ||
1479 | drive->name); | ||
1480 | rc = 0; | ||
1481 | } | ||
1482 | break; | ||
1483 | case CAPACITY_NO_CARTRIDGE: | ||
1484 | /* | ||
1485 | * This is a KERN_ERR so it appears on screen | ||
1486 | * for the user to see | ||
1487 | */ | ||
1488 | printk(KERN_ERR "%s: No disk in drive\n", drive->name); | ||
1489 | break; | ||
1490 | case CAPACITY_INVALID: | ||
1491 | printk(KERN_ERR "%s: Invalid capacity for disk " | ||
1492 | "in drive\n", drive->name); | ||
1493 | break; | ||
1494 | } | ||
1495 | } | ||
1496 | if (!i) { | ||
1497 | debug_log( "Descriptor 0 Code: %d\n", | ||
1498 | descriptor->dc); | ||
1499 | } | ||
1500 | debug_log( "Descriptor %d: %dkB, %d blocks, %d " | ||
1501 | "sector size\n", i, blocks * length / 1024, blocks, | ||
1502 | length); | ||
1503 | } | ||
1504 | |||
1505 | /* Clik! disk does not support get_flexible_disk_page */ | ||
1506 | if (!test_bit(IDEFLOPPY_CLIK_DRIVE, &floppy->flags)) { | ||
1507 | (void) idefloppy_get_flexible_disk_page(drive); | ||
1508 | } | ||
1509 | |||
1510 | set_capacity(floppy->disk, floppy->blocks * floppy->bs_factor); | ||
1511 | return rc; | ||
1512 | } | ||
1513 | |||
1514 | /* | ||
1515 | ** Obtain the list of formattable capacities. | ||
1516 | ** Very similar to idefloppy_get_capacity, except that we push the capacity | ||
1517 | ** descriptors to userland, instead of our own structures. | ||
1518 | ** | ||
1519 | ** Userland gives us the following structure: | ||
1520 | ** | ||
1521 | ** struct idefloppy_format_capacities { | ||
1522 | ** int nformats; | ||
1523 | ** struct { | ||
1524 | ** int nblocks; | ||
1525 | ** int blocksize; | ||
1526 | ** } formats[]; | ||
1527 | ** } ; | ||
1528 | ** | ||
1529 | ** userland initializes nformats to the number of allocated formats[] | ||
1530 | ** records. On exit we set nformats to the number of records we've | ||
1531 | ** actually initialized. | ||
1532 | ** | ||
1533 | */ | ||
1534 | |||
1535 | static int idefloppy_get_format_capacities(ide_drive_t *drive, int __user *arg) | ||
1536 | { | ||
1537 | idefloppy_pc_t pc; | ||
1538 | idefloppy_capacity_header_t *header; | ||
1539 | idefloppy_capacity_descriptor_t *descriptor; | ||
1540 | int i, descriptors, blocks, length; | ||
1541 | int u_array_size; | ||
1542 | int u_index; | ||
1543 | int __user *argp; | ||
1544 | |||
1545 | if (get_user(u_array_size, arg)) | ||
1546 | return (-EFAULT); | ||
1547 | |||
1548 | if (u_array_size <= 0) | ||
1549 | return (-EINVAL); | ||
1550 | |||
1551 | idefloppy_create_read_capacity_cmd(&pc); | ||
1552 | if (idefloppy_queue_pc_tail(drive, &pc)) { | ||
1553 | printk(KERN_ERR "ide-floppy: Can't get floppy parameters\n"); | ||
1554 | return (-EIO); | ||
1555 | } | ||
1556 | header = (idefloppy_capacity_header_t *) pc.buffer; | ||
1557 | descriptors = header->length / | ||
1558 | sizeof(idefloppy_capacity_descriptor_t); | ||
1559 | descriptor = (idefloppy_capacity_descriptor_t *) (header + 1); | ||
1560 | |||
1561 | u_index = 0; | ||
1562 | argp = arg + 1; | ||
1563 | |||
1564 | /* | ||
1565 | ** We always skip the first capacity descriptor. That's the | ||
1566 | ** current capacity. We are interested in the remaining descriptors, | ||
1567 | ** the formattable capacities. | ||
1568 | */ | ||
1569 | |||
1570 | for (i=0; i<descriptors; i++, descriptor++) { | ||
1571 | if (u_index >= u_array_size) | ||
1572 | break; /* User-supplied buffer too small */ | ||
1573 | if (i == 0) | ||
1574 | continue; /* Skip the first descriptor */ | ||
1575 | |||
1576 | blocks = ntohl(descriptor->blocks); | ||
1577 | length = ntohs(descriptor->length); | ||
1578 | |||
1579 | if (put_user(blocks, argp)) | ||
1580 | return(-EFAULT); | ||
1581 | ++argp; | ||
1582 | |||
1583 | if (put_user(length, argp)) | ||
1584 | return (-EFAULT); | ||
1585 | ++argp; | ||
1586 | |||
1587 | ++u_index; | ||
1588 | } | ||
1589 | |||
1590 | if (put_user(u_index, arg)) | ||
1591 | return (-EFAULT); | ||
1592 | return (0); | ||
1593 | } | ||
1594 | |||
1595 | /* | ||
1596 | ** Send ATAPI_FORMAT_UNIT to the drive. | ||
1597 | ** | ||
1598 | ** Userland gives us the following structure: | ||
1599 | ** | ||
1600 | ** struct idefloppy_format_command { | ||
1601 | ** int nblocks; | ||
1602 | ** int blocksize; | ||
1603 | ** int flags; | ||
1604 | ** } ; | ||
1605 | ** | ||
1606 | ** flags is a bitmask, currently, the only defined flag is: | ||
1607 | ** | ||
1608 | ** 0x01 - verify media after format. | ||
1609 | */ | ||
1610 | |||
1611 | static int idefloppy_begin_format(ide_drive_t *drive, int __user *arg) | ||
1612 | { | ||
1613 | int blocks; | ||
1614 | int length; | ||
1615 | int flags; | ||
1616 | idefloppy_pc_t pc; | ||
1617 | |||
1618 | if (get_user(blocks, arg) || | ||
1619 | get_user(length, arg+1) || | ||
1620 | get_user(flags, arg+2)) { | ||
1621 | return (-EFAULT); | ||
1622 | } | ||
1623 | |||
1624 | /* Get the SFRP bit */ | ||
1625 | (void) idefloppy_get_capability_page(drive); | ||
1626 | idefloppy_create_format_unit_cmd(&pc, blocks, length, flags); | ||
1627 | if (idefloppy_queue_pc_tail(drive, &pc)) { | ||
1628 | return (-EIO); | ||
1629 | } | ||
1630 | |||
1631 | return (0); | ||
1632 | } | ||
1633 | |||
1634 | /* | ||
1635 | ** Get ATAPI_FORMAT_UNIT progress indication. | ||
1636 | ** | ||
1637 | ** Userland gives a pointer to an int. The int is set to a progresss | ||
1638 | ** indicator 0-65536, with 65536=100%. | ||
1639 | ** | ||
1640 | ** If the drive does not support format progress indication, we just check | ||
1641 | ** the dsc bit, and return either 0 or 65536. | ||
1642 | */ | ||
1643 | |||
1644 | static int idefloppy_get_format_progress(ide_drive_t *drive, int __user *arg) | ||
1645 | { | ||
1646 | idefloppy_floppy_t *floppy = drive->driver_data; | ||
1647 | idefloppy_pc_t pc; | ||
1648 | int progress_indication = 0x10000; | ||
1649 | |||
1650 | if (floppy->srfp) { | ||
1651 | idefloppy_create_request_sense_cmd(&pc); | ||
1652 | if (idefloppy_queue_pc_tail(drive, &pc)) { | ||
1653 | return (-EIO); | ||
1654 | } | ||
1655 | |||
1656 | if (floppy->sense_key == 2 && | ||
1657 | floppy->asc == 4 && | ||
1658 | floppy->ascq == 4) { | ||
1659 | progress_indication = floppy->progress_indication; | ||
1660 | } | ||
1661 | /* Else assume format_unit has finished, and we're | ||
1662 | ** at 0x10000 */ | ||
1663 | } else { | ||
1664 | atapi_status_t status; | ||
1665 | unsigned long flags; | ||
1666 | |||
1667 | local_irq_save(flags); | ||
1668 | status.all = HWIF(drive)->INB(IDE_STATUS_REG); | ||
1669 | local_irq_restore(flags); | ||
1670 | |||
1671 | progress_indication = !status.b.dsc ? 0 : 0x10000; | ||
1672 | } | ||
1673 | if (put_user(progress_indication, arg)) | ||
1674 | return (-EFAULT); | ||
1675 | |||
1676 | return (0); | ||
1677 | } | ||
1678 | |||
1679 | /* | ||
1680 | * Return the current floppy capacity. | ||
1681 | */ | ||
1682 | static sector_t idefloppy_capacity (ide_drive_t *drive) | ||
1683 | { | ||
1684 | idefloppy_floppy_t *floppy = drive->driver_data; | ||
1685 | unsigned long capacity = floppy->blocks * floppy->bs_factor; | ||
1686 | |||
1687 | return capacity; | ||
1688 | } | ||
1689 | |||
1690 | /* | ||
1691 | * idefloppy_identify_device checks if we can support a drive, | ||
1692 | * based on the ATAPI IDENTIFY command results. | ||
1693 | */ | ||
1694 | static int idefloppy_identify_device (ide_drive_t *drive,struct hd_driveid *id) | ||
1695 | { | ||
1696 | struct idefloppy_id_gcw gcw; | ||
1697 | #if IDEFLOPPY_DEBUG_INFO | ||
1698 | u16 mask,i; | ||
1699 | char buffer[80]; | ||
1700 | #endif /* IDEFLOPPY_DEBUG_INFO */ | ||
1701 | |||
1702 | *((u16 *) &gcw) = id->config; | ||
1703 | |||
1704 | #ifdef CONFIG_PPC | ||
1705 | /* kludge for Apple PowerBook internal zip */ | ||
1706 | if ((gcw.device_type == 5) && | ||
1707 | !strstr(id->model, "CD-ROM") && | ||
1708 | strstr(id->model, "ZIP")) | ||
1709 | gcw.device_type = 0; | ||
1710 | #endif | ||
1711 | |||
1712 | #if IDEFLOPPY_DEBUG_INFO | ||
1713 | printk(KERN_INFO "Dumping ATAPI Identify Device floppy parameters\n"); | ||
1714 | switch (gcw.protocol) { | ||
1715 | case 0: case 1: sprintf(buffer, "ATA");break; | ||
1716 | case 2: sprintf(buffer, "ATAPI");break; | ||
1717 | case 3: sprintf(buffer, "Reserved (Unknown to ide-floppy)");break; | ||
1718 | } | ||
1719 | printk(KERN_INFO "Protocol Type: %s\n", buffer); | ||
1720 | switch (gcw.device_type) { | ||
1721 | case 0: sprintf(buffer, "Direct-access Device");break; | ||
1722 | case 1: sprintf(buffer, "Streaming Tape Device");break; | ||
1723 | case 2: case 3: case 4: sprintf (buffer, "Reserved");break; | ||
1724 | case 5: sprintf(buffer, "CD-ROM Device");break; | ||
1725 | case 6: sprintf(buffer, "Reserved"); | ||
1726 | case 7: sprintf(buffer, "Optical memory Device");break; | ||
1727 | case 0x1f: sprintf(buffer, "Unknown or no Device type");break; | ||
1728 | default: sprintf(buffer, "Reserved"); | ||
1729 | } | ||
1730 | printk(KERN_INFO "Device Type: %x - %s\n", gcw.device_type, buffer); | ||
1731 | printk(KERN_INFO "Removable: %s\n",gcw.removable ? "Yes":"No"); | ||
1732 | switch (gcw.drq_type) { | ||
1733 | case 0: sprintf(buffer, "Microprocessor DRQ");break; | ||
1734 | case 1: sprintf(buffer, "Interrupt DRQ");break; | ||
1735 | case 2: sprintf(buffer, "Accelerated DRQ");break; | ||
1736 | case 3: sprintf(buffer, "Reserved");break; | ||
1737 | } | ||
1738 | printk(KERN_INFO "Command Packet DRQ Type: %s\n", buffer); | ||
1739 | switch (gcw.packet_size) { | ||
1740 | case 0: sprintf(buffer, "12 bytes");break; | ||
1741 | case 1: sprintf(buffer, "16 bytes");break; | ||
1742 | default: sprintf(buffer, "Reserved");break; | ||
1743 | } | ||
1744 | printk(KERN_INFO "Command Packet Size: %s\n", buffer); | ||
1745 | printk(KERN_INFO "Model: %.40s\n",id->model); | ||
1746 | printk(KERN_INFO "Firmware Revision: %.8s\n",id->fw_rev); | ||
1747 | printk(KERN_INFO "Serial Number: %.20s\n",id->serial_no); | ||
1748 | printk(KERN_INFO "Write buffer size(?): %d bytes\n",id->buf_size*512); | ||
1749 | printk(KERN_INFO "DMA: %s",id->capability & 0x01 ? "Yes\n":"No\n"); | ||
1750 | printk(KERN_INFO "LBA: %s",id->capability & 0x02 ? "Yes\n":"No\n"); | ||
1751 | printk(KERN_INFO "IORDY can be disabled: %s",id->capability & 0x04 ? "Yes\n":"No\n"); | ||
1752 | printk(KERN_INFO "IORDY supported: %s",id->capability & 0x08 ? "Yes\n":"Unknown\n"); | ||
1753 | printk(KERN_INFO "ATAPI overlap supported: %s",id->capability & 0x20 ? "Yes\n":"No\n"); | ||
1754 | printk(KERN_INFO "PIO Cycle Timing Category: %d\n",id->tPIO); | ||
1755 | printk(KERN_INFO "DMA Cycle Timing Category: %d\n",id->tDMA); | ||
1756 | printk(KERN_INFO "Single Word DMA supported modes:\n"); | ||
1757 | for (i=0,mask=1;i<8;i++,mask=mask << 1) { | ||
1758 | if (id->dma_1word & mask) | ||
1759 | printk(KERN_INFO " Mode %d%s\n", i, | ||
1760 | (id->dma_1word & (mask << 8)) ? " (active)" : ""); | ||
1761 | } | ||
1762 | printk(KERN_INFO "Multi Word DMA supported modes:\n"); | ||
1763 | for (i=0,mask=1;i<8;i++,mask=mask << 1) { | ||
1764 | if (id->dma_mword & mask) | ||
1765 | printk(KERN_INFO " Mode %d%s\n", i, | ||
1766 | (id->dma_mword & (mask << 8)) ? " (active)" : ""); | ||
1767 | } | ||
1768 | if (id->field_valid & 0x0002) { | ||
1769 | printk(KERN_INFO "Enhanced PIO Modes: %s\n", | ||
1770 | id->eide_pio_modes & 1 ? "Mode 3":"None"); | ||
1771 | if (id->eide_dma_min == 0) | ||
1772 | sprintf(buffer, "Not supported"); | ||
1773 | else | ||
1774 | sprintf(buffer, "%d ns",id->eide_dma_min); | ||
1775 | printk(KERN_INFO "Minimum Multi-word DMA cycle per word: %s\n", buffer); | ||
1776 | if (id->eide_dma_time == 0) | ||
1777 | sprintf(buffer, "Not supported"); | ||
1778 | else | ||
1779 | sprintf(buffer, "%d ns",id->eide_dma_time); | ||
1780 | printk(KERN_INFO "Manufacturer\'s Recommended Multi-word cycle: %s\n", buffer); | ||
1781 | if (id->eide_pio == 0) | ||
1782 | sprintf(buffer, "Not supported"); | ||
1783 | else | ||
1784 | sprintf(buffer, "%d ns",id->eide_pio); | ||
1785 | printk(KERN_INFO "Minimum PIO cycle without IORDY: %s\n", | ||
1786 | buffer); | ||
1787 | if (id->eide_pio_iordy == 0) | ||
1788 | sprintf(buffer, "Not supported"); | ||
1789 | else | ||
1790 | sprintf(buffer, "%d ns",id->eide_pio_iordy); | ||
1791 | printk(KERN_INFO "Minimum PIO cycle with IORDY: %s\n", buffer); | ||
1792 | } else | ||
1793 | printk(KERN_INFO "According to the device, fields 64-70 are not valid.\n"); | ||
1794 | #endif /* IDEFLOPPY_DEBUG_INFO */ | ||
1795 | |||
1796 | if (gcw.protocol != 2) | ||
1797 | printk(KERN_ERR "ide-floppy: Protocol is not ATAPI\n"); | ||
1798 | else if (gcw.device_type != 0) | ||
1799 | printk(KERN_ERR "ide-floppy: Device type is not set to floppy\n"); | ||
1800 | else if (!gcw.removable) | ||
1801 | printk(KERN_ERR "ide-floppy: The removable flag is not set\n"); | ||
1802 | else if (gcw.drq_type == 3) { | ||
1803 | printk(KERN_ERR "ide-floppy: Sorry, DRQ type %d not supported\n", gcw.drq_type); | ||
1804 | } else if (gcw.packet_size != 0) { | ||
1805 | printk(KERN_ERR "ide-floppy: Packet size is not 12 bytes long\n"); | ||
1806 | } else | ||
1807 | return 1; | ||
1808 | return 0; | ||
1809 | } | ||
1810 | |||
1811 | static void idefloppy_add_settings(ide_drive_t *drive) | ||
1812 | { | ||
1813 | idefloppy_floppy_t *floppy = drive->driver_data; | ||
1814 | |||
1815 | /* | ||
1816 | * drive setting name read/write ioctl ioctl data type min max mul_factor div_factor data pointer set function | ||
1817 | */ | ||
1818 | ide_add_setting(drive, "bios_cyl", SETTING_RW, -1, -1, TYPE_INT, 0, 1023, 1, 1, &drive->bios_cyl, NULL); | ||
1819 | ide_add_setting(drive, "bios_head", SETTING_RW, -1, -1, TYPE_BYTE, 0, 255, 1, 1, &drive->bios_head, NULL); | ||
1820 | ide_add_setting(drive, "bios_sect", SETTING_RW, -1, -1, TYPE_BYTE, 0, 63, 1, 1, &drive->bios_sect, NULL); | ||
1821 | ide_add_setting(drive, "ticks", SETTING_RW, -1, -1, TYPE_BYTE, 0, 255, 1, 1, &floppy->ticks, NULL); | ||
1822 | } | ||
1823 | |||
1824 | /* | ||
1825 | * Driver initialization. | ||
1826 | */ | ||
1827 | static void idefloppy_setup (ide_drive_t *drive, idefloppy_floppy_t *floppy) | ||
1828 | { | ||
1829 | struct idefloppy_id_gcw gcw; | ||
1830 | |||
1831 | *((u16 *) &gcw) = drive->id->config; | ||
1832 | floppy->pc = floppy->pc_stack; | ||
1833 | if (gcw.drq_type == 1) | ||
1834 | set_bit(IDEFLOPPY_DRQ_INTERRUPT, &floppy->flags); | ||
1835 | /* | ||
1836 | * We used to check revisions here. At this point however | ||
1837 | * I'm giving up. Just assume they are all broken, its easier. | ||
1838 | * | ||
1839 | * The actual reason for the workarounds was likely | ||
1840 | * a driver bug after all rather than a firmware bug, | ||
1841 | * and the workaround below used to hide it. It should | ||
1842 | * be fixed as of version 1.9, but to be on the safe side | ||
1843 | * we'll leave the limitation below for the 2.2.x tree. | ||
1844 | */ | ||
1845 | |||
1846 | if (!strncmp(drive->id->model, "IOMEGA ZIP 100 ATAPI", 20)) { | ||
1847 | set_bit(IDEFLOPPY_ZIP_DRIVE, &floppy->flags); | ||
1848 | /* This value will be visible in the /proc/ide/hdx/settings */ | ||
1849 | floppy->ticks = IDEFLOPPY_TICKS_DELAY; | ||
1850 | blk_queue_max_sectors(drive->queue, 64); | ||
1851 | } | ||
1852 | |||
1853 | /* | ||
1854 | * Guess what? The IOMEGA Clik! drive also needs the | ||
1855 | * above fix. It makes nasty clicking noises without | ||
1856 | * it, so please don't remove this. | ||
1857 | */ | ||
1858 | if (strncmp(drive->id->model, "IOMEGA Clik!", 11) == 0) { | ||
1859 | blk_queue_max_sectors(drive->queue, 64); | ||
1860 | set_bit(IDEFLOPPY_CLIK_DRIVE, &floppy->flags); | ||
1861 | } | ||
1862 | |||
1863 | |||
1864 | (void) idefloppy_get_capacity(drive); | ||
1865 | idefloppy_add_settings(drive); | ||
1866 | } | ||
1867 | |||
1868 | static int idefloppy_cleanup (ide_drive_t *drive) | ||
1869 | { | ||
1870 | idefloppy_floppy_t *floppy = drive->driver_data; | ||
1871 | struct gendisk *g = floppy->disk; | ||
1872 | |||
1873 | if (ide_unregister_subdriver(drive)) | ||
1874 | return 1; | ||
1875 | |||
1876 | del_gendisk(g); | ||
1877 | |||
1878 | ide_floppy_put(floppy); | ||
1879 | |||
1880 | return 0; | ||
1881 | } | ||
1882 | |||
1883 | static void ide_floppy_release(struct kref *kref) | ||
1884 | { | ||
1885 | struct ide_floppy_obj *floppy = to_ide_floppy(kref); | ||
1886 | ide_drive_t *drive = floppy->drive; | ||
1887 | struct gendisk *g = floppy->disk; | ||
1888 | |||
1889 | drive->driver_data = NULL; | ||
1890 | g->private_data = NULL; | ||
1891 | put_disk(g); | ||
1892 | kfree(floppy); | ||
1893 | } | ||
1894 | |||
1895 | #ifdef CONFIG_PROC_FS | ||
1896 | |||
1897 | static int proc_idefloppy_read_capacity | ||
1898 | (char *page, char **start, off_t off, int count, int *eof, void *data) | ||
1899 | { | ||
1900 | ide_drive_t*drive = (ide_drive_t *)data; | ||
1901 | int len; | ||
1902 | |||
1903 | len = sprintf(page,"%llu\n", (long long)idefloppy_capacity(drive)); | ||
1904 | PROC_IDE_READ_RETURN(page,start,off,count,eof,len); | ||
1905 | } | ||
1906 | |||
1907 | static ide_proc_entry_t idefloppy_proc[] = { | ||
1908 | { "capacity", S_IFREG|S_IRUGO, proc_idefloppy_read_capacity, NULL }, | ||
1909 | { "geometry", S_IFREG|S_IRUGO, proc_ide_read_geometry, NULL }, | ||
1910 | { NULL, 0, NULL, NULL } | ||
1911 | }; | ||
1912 | |||
1913 | #else | ||
1914 | |||
1915 | #define idefloppy_proc NULL | ||
1916 | |||
1917 | #endif /* CONFIG_PROC_FS */ | ||
1918 | |||
1919 | static int idefloppy_attach(ide_drive_t *drive); | ||
1920 | |||
1921 | /* | ||
1922 | * IDE subdriver functions, registered with ide.c | ||
1923 | */ | ||
1924 | static ide_driver_t idefloppy_driver = { | ||
1925 | .owner = THIS_MODULE, | ||
1926 | .name = "ide-floppy", | ||
1927 | .version = IDEFLOPPY_VERSION, | ||
1928 | .media = ide_floppy, | ||
1929 | .busy = 0, | ||
1930 | .supports_dsc_overlap = 0, | ||
1931 | .cleanup = idefloppy_cleanup, | ||
1932 | .do_request = idefloppy_do_request, | ||
1933 | .end_request = idefloppy_do_end_request, | ||
1934 | .error = __ide_error, | ||
1935 | .abort = __ide_abort, | ||
1936 | .proc = idefloppy_proc, | ||
1937 | .attach = idefloppy_attach, | ||
1938 | .drives = LIST_HEAD_INIT(idefloppy_driver.drives), | ||
1939 | }; | ||
1940 | |||
1941 | static int idefloppy_open(struct inode *inode, struct file *filp) | ||
1942 | { | ||
1943 | struct gendisk *disk = inode->i_bdev->bd_disk; | ||
1944 | struct ide_floppy_obj *floppy; | ||
1945 | ide_drive_t *drive; | ||
1946 | idefloppy_pc_t pc; | ||
1947 | int ret = 0; | ||
1948 | |||
1949 | debug_log(KERN_INFO "Reached idefloppy_open\n"); | ||
1950 | |||
1951 | if (!(floppy = ide_floppy_get(disk))) | ||
1952 | return -ENXIO; | ||
1953 | |||
1954 | drive = floppy->drive; | ||
1955 | |||
1956 | drive->usage++; | ||
1957 | |||
1958 | if (drive->usage == 1) { | ||
1959 | clear_bit(IDEFLOPPY_FORMAT_IN_PROGRESS, &floppy->flags); | ||
1960 | /* Just in case */ | ||
1961 | |||
1962 | idefloppy_create_test_unit_ready_cmd(&pc); | ||
1963 | if (idefloppy_queue_pc_tail(drive, &pc)) { | ||
1964 | idefloppy_create_start_stop_cmd(&pc, 1); | ||
1965 | (void) idefloppy_queue_pc_tail(drive, &pc); | ||
1966 | } | ||
1967 | |||
1968 | if (idefloppy_get_capacity (drive) | ||
1969 | && (filp->f_flags & O_NDELAY) == 0 | ||
1970 | /* | ||
1971 | ** Allow O_NDELAY to open a drive without a disk, or with | ||
1972 | ** an unreadable disk, so that we can get the format | ||
1973 | ** capacity of the drive or begin the format - Sam | ||
1974 | */ | ||
1975 | ) { | ||
1976 | drive->usage--; | ||
1977 | ret = -EIO; | ||
1978 | goto out_put_floppy; | ||
1979 | } | ||
1980 | |||
1981 | if (floppy->wp && (filp->f_mode & 2)) { | ||
1982 | drive->usage--; | ||
1983 | ret = -EROFS; | ||
1984 | goto out_put_floppy; | ||
1985 | } | ||
1986 | set_bit(IDEFLOPPY_MEDIA_CHANGED, &floppy->flags); | ||
1987 | /* IOMEGA Clik! drives do not support lock/unlock commands */ | ||
1988 | if (!test_bit(IDEFLOPPY_CLIK_DRIVE, &floppy->flags)) { | ||
1989 | idefloppy_create_prevent_cmd(&pc, 1); | ||
1990 | (void) idefloppy_queue_pc_tail(drive, &pc); | ||
1991 | } | ||
1992 | check_disk_change(inode->i_bdev); | ||
1993 | } else if (test_bit(IDEFLOPPY_FORMAT_IN_PROGRESS, &floppy->flags)) { | ||
1994 | drive->usage--; | ||
1995 | ret = -EBUSY; | ||
1996 | goto out_put_floppy; | ||
1997 | } | ||
1998 | return 0; | ||
1999 | |||
2000 | out_put_floppy: | ||
2001 | ide_floppy_put(floppy); | ||
2002 | return ret; | ||
2003 | } | ||
2004 | |||
2005 | static int idefloppy_release(struct inode *inode, struct file *filp) | ||
2006 | { | ||
2007 | struct gendisk *disk = inode->i_bdev->bd_disk; | ||
2008 | struct ide_floppy_obj *floppy = ide_floppy_g(disk); | ||
2009 | ide_drive_t *drive = floppy->drive; | ||
2010 | idefloppy_pc_t pc; | ||
2011 | |||
2012 | debug_log(KERN_INFO "Reached idefloppy_release\n"); | ||
2013 | |||
2014 | if (drive->usage == 1) { | ||
2015 | /* IOMEGA Clik! drives do not support lock/unlock commands */ | ||
2016 | if (!test_bit(IDEFLOPPY_CLIK_DRIVE, &floppy->flags)) { | ||
2017 | idefloppy_create_prevent_cmd(&pc, 0); | ||
2018 | (void) idefloppy_queue_pc_tail(drive, &pc); | ||
2019 | } | ||
2020 | |||
2021 | clear_bit(IDEFLOPPY_FORMAT_IN_PROGRESS, &floppy->flags); | ||
2022 | } | ||
2023 | drive->usage--; | ||
2024 | |||
2025 | ide_floppy_put(floppy); | ||
2026 | |||
2027 | return 0; | ||
2028 | } | ||
2029 | |||
2030 | static int idefloppy_ioctl(struct inode *inode, struct file *file, | ||
2031 | unsigned int cmd, unsigned long arg) | ||
2032 | { | ||
2033 | struct block_device *bdev = inode->i_bdev; | ||
2034 | struct ide_floppy_obj *floppy = ide_floppy_g(bdev->bd_disk); | ||
2035 | ide_drive_t *drive = floppy->drive; | ||
2036 | void __user *argp = (void __user *)arg; | ||
2037 | int err = generic_ide_ioctl(drive, file, bdev, cmd, arg); | ||
2038 | int prevent = (arg) ? 1 : 0; | ||
2039 | idefloppy_pc_t pc; | ||
2040 | if (err != -EINVAL) | ||
2041 | return err; | ||
2042 | |||
2043 | switch (cmd) { | ||
2044 | case CDROMEJECT: | ||
2045 | prevent = 0; | ||
2046 | /* fall through */ | ||
2047 | case CDROM_LOCKDOOR: | ||
2048 | if (drive->usage > 1) | ||
2049 | return -EBUSY; | ||
2050 | |||
2051 | /* The IOMEGA Clik! Drive doesn't support this command - no room for an eject mechanism */ | ||
2052 | if (!test_bit(IDEFLOPPY_CLIK_DRIVE, &floppy->flags)) { | ||
2053 | idefloppy_create_prevent_cmd(&pc, prevent); | ||
2054 | (void) idefloppy_queue_pc_tail(drive, &pc); | ||
2055 | } | ||
2056 | if (cmd == CDROMEJECT) { | ||
2057 | idefloppy_create_start_stop_cmd(&pc, 2); | ||
2058 | (void) idefloppy_queue_pc_tail(drive, &pc); | ||
2059 | } | ||
2060 | return 0; | ||
2061 | case IDEFLOPPY_IOCTL_FORMAT_SUPPORTED: | ||
2062 | return 0; | ||
2063 | case IDEFLOPPY_IOCTL_FORMAT_GET_CAPACITY: | ||
2064 | return idefloppy_get_format_capacities(drive, argp); | ||
2065 | case IDEFLOPPY_IOCTL_FORMAT_START: | ||
2066 | |||
2067 | if (!(file->f_mode & 2)) | ||
2068 | return -EPERM; | ||
2069 | |||
2070 | if (drive->usage > 1) { | ||
2071 | /* Don't format if someone is using the disk */ | ||
2072 | |||
2073 | clear_bit(IDEFLOPPY_FORMAT_IN_PROGRESS, | ||
2074 | &floppy->flags); | ||
2075 | return -EBUSY; | ||
2076 | } | ||
2077 | |||
2078 | set_bit(IDEFLOPPY_FORMAT_IN_PROGRESS, &floppy->flags); | ||
2079 | |||
2080 | err = idefloppy_begin_format(drive, argp); | ||
2081 | if (err) | ||
2082 | clear_bit(IDEFLOPPY_FORMAT_IN_PROGRESS, &floppy->flags); | ||
2083 | return err; | ||
2084 | /* | ||
2085 | ** Note, the bit will be cleared when the device is | ||
2086 | ** closed. This is the cleanest way to handle the | ||
2087 | ** situation where the drive does not support | ||
2088 | ** format progress reporting. | ||
2089 | */ | ||
2090 | case IDEFLOPPY_IOCTL_FORMAT_GET_PROGRESS: | ||
2091 | return idefloppy_get_format_progress(drive, argp); | ||
2092 | } | ||
2093 | return -EINVAL; | ||
2094 | } | ||
2095 | |||
2096 | static int idefloppy_media_changed(struct gendisk *disk) | ||
2097 | { | ||
2098 | struct ide_floppy_obj *floppy = ide_floppy_g(disk); | ||
2099 | ide_drive_t *drive = floppy->drive; | ||
2100 | |||
2101 | /* do not scan partitions twice if this is a removable device */ | ||
2102 | if (drive->attach) { | ||
2103 | drive->attach = 0; | ||
2104 | return 0; | ||
2105 | } | ||
2106 | return test_and_clear_bit(IDEFLOPPY_MEDIA_CHANGED, &floppy->flags); | ||
2107 | } | ||
2108 | |||
2109 | static int idefloppy_revalidate_disk(struct gendisk *disk) | ||
2110 | { | ||
2111 | struct ide_floppy_obj *floppy = ide_floppy_g(disk); | ||
2112 | set_capacity(disk, idefloppy_capacity(floppy->drive)); | ||
2113 | return 0; | ||
2114 | } | ||
2115 | |||
2116 | static struct block_device_operations idefloppy_ops = { | ||
2117 | .owner = THIS_MODULE, | ||
2118 | .open = idefloppy_open, | ||
2119 | .release = idefloppy_release, | ||
2120 | .ioctl = idefloppy_ioctl, | ||
2121 | .media_changed = idefloppy_media_changed, | ||
2122 | .revalidate_disk= idefloppy_revalidate_disk | ||
2123 | }; | ||
2124 | |||
2125 | static int idefloppy_attach (ide_drive_t *drive) | ||
2126 | { | ||
2127 | idefloppy_floppy_t *floppy; | ||
2128 | struct gendisk *g; | ||
2129 | |||
2130 | if (!strstr("ide-floppy", drive->driver_req)) | ||
2131 | goto failed; | ||
2132 | if (!drive->present) | ||
2133 | goto failed; | ||
2134 | if (drive->media != ide_floppy) | ||
2135 | goto failed; | ||
2136 | if (!idefloppy_identify_device (drive, drive->id)) { | ||
2137 | printk (KERN_ERR "ide-floppy: %s: not supported by this version of ide-floppy\n", drive->name); | ||
2138 | goto failed; | ||
2139 | } | ||
2140 | if (drive->scsi) { | ||
2141 | printk("ide-floppy: passing drive %s to ide-scsi emulation.\n", drive->name); | ||
2142 | goto failed; | ||
2143 | } | ||
2144 | if ((floppy = (idefloppy_floppy_t *) kmalloc (sizeof (idefloppy_floppy_t), GFP_KERNEL)) == NULL) { | ||
2145 | printk (KERN_ERR "ide-floppy: %s: Can't allocate a floppy structure\n", drive->name); | ||
2146 | goto failed; | ||
2147 | } | ||
2148 | |||
2149 | g = alloc_disk(1 << PARTN_BITS); | ||
2150 | if (!g) | ||
2151 | goto out_free_floppy; | ||
2152 | |||
2153 | ide_init_disk(g, drive); | ||
2154 | |||
2155 | if (ide_register_subdriver(drive, &idefloppy_driver)) { | ||
2156 | printk (KERN_ERR "ide-floppy: %s: Failed to register the driver with ide.c\n", drive->name); | ||
2157 | goto out_put_disk; | ||
2158 | } | ||
2159 | |||
2160 | memset(floppy, 0, sizeof(*floppy)); | ||
2161 | |||
2162 | kref_init(&floppy->kref); | ||
2163 | |||
2164 | floppy->drive = drive; | ||
2165 | floppy->driver = &idefloppy_driver; | ||
2166 | floppy->disk = g; | ||
2167 | |||
2168 | g->private_data = &floppy->driver; | ||
2169 | |||
2170 | drive->driver_data = floppy; | ||
2171 | |||
2172 | DRIVER(drive)->busy++; | ||
2173 | idefloppy_setup (drive, floppy); | ||
2174 | DRIVER(drive)->busy--; | ||
2175 | g->minors = 1 << PARTN_BITS; | ||
2176 | g->driverfs_dev = &drive->gendev; | ||
2177 | strcpy(g->devfs_name, drive->devfs_name); | ||
2178 | g->flags = drive->removable ? GENHD_FL_REMOVABLE : 0; | ||
2179 | g->fops = &idefloppy_ops; | ||
2180 | drive->attach = 1; | ||
2181 | add_disk(g); | ||
2182 | return 0; | ||
2183 | |||
2184 | out_put_disk: | ||
2185 | put_disk(g); | ||
2186 | out_free_floppy: | ||
2187 | kfree(floppy); | ||
2188 | failed: | ||
2189 | return 1; | ||
2190 | } | ||
2191 | |||
2192 | MODULE_DESCRIPTION("ATAPI FLOPPY Driver"); | ||
2193 | |||
2194 | static void __exit idefloppy_exit (void) | ||
2195 | { | ||
2196 | ide_unregister_driver(&idefloppy_driver); | ||
2197 | } | ||
2198 | |||
2199 | /* | ||
2200 | * idefloppy_init will register the driver for each floppy. | ||
2201 | */ | ||
2202 | static int idefloppy_init (void) | ||
2203 | { | ||
2204 | printk("ide-floppy driver " IDEFLOPPY_VERSION "\n"); | ||
2205 | ide_register_driver(&idefloppy_driver); | ||
2206 | return 0; | ||
2207 | } | ||
2208 | |||
2209 | module_init(idefloppy_init); | ||
2210 | module_exit(idefloppy_exit); | ||
2211 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/ide/ide-generic.c b/drivers/ide/ide-generic.c new file mode 100644 index 000000000000..99fd56151131 --- /dev/null +++ b/drivers/ide/ide-generic.c | |||
@@ -0,0 +1,32 @@ | |||
1 | /* | ||
2 | * generic/default IDE host driver | ||
3 | * | ||
4 | * Copyright (C) 2004 Bartlomiej Zolnierkiewicz | ||
5 | * This code was split off from ide.c. See it for original copyrights. | ||
6 | * | ||
7 | * May be copied or modified under the terms of the GNU General Public License. | ||
8 | */ | ||
9 | |||
10 | #include <linux/kernel.h> | ||
11 | #include <linux/init.h> | ||
12 | #include <linux/module.h> | ||
13 | #include <linux/ide.h> | ||
14 | |||
15 | static int __init ide_generic_init(void) | ||
16 | { | ||
17 | if (ide_hwifs[0].io_ports[IDE_DATA_OFFSET]) | ||
18 | ide_get_lock(NULL, NULL); /* for atari only */ | ||
19 | |||
20 | (void)ideprobe_init(); | ||
21 | |||
22 | if (ide_hwifs[0].io_ports[IDE_DATA_OFFSET]) | ||
23 | ide_release_lock(); /* for atari only */ | ||
24 | |||
25 | create_proc_ide_interfaces(); | ||
26 | |||
27 | return 0; | ||
28 | } | ||
29 | |||
30 | module_init(ide_generic_init); | ||
31 | |||
32 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/ide/ide-io.c b/drivers/ide/ide-io.c new file mode 100644 index 000000000000..248e3cc8b352 --- /dev/null +++ b/drivers/ide/ide-io.c | |||
@@ -0,0 +1,1681 @@ | |||
1 | /* | ||
2 | * IDE I/O functions | ||
3 | * | ||
4 | * Basic PIO and command management functionality. | ||
5 | * | ||
6 | * This code was split off from ide.c. See ide.c for history and original | ||
7 | * copyrights. | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or modify it | ||
10 | * under the terms of the GNU General Public License as published by the | ||
11 | * Free Software Foundation; either version 2, or (at your option) any | ||
12 | * later version. | ||
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, but | ||
15 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
17 | * General Public License for more details. | ||
18 | * | ||
19 | * For the avoidance of doubt the "preferred form" of this code is one which | ||
20 | * is in an open non patent encumbered format. Where cryptographic key signing | ||
21 | * forms part of the process of creating an executable the information | ||
22 | * including keys needed to generate an equivalently functional executable | ||
23 | * are deemed to be part of the source code. | ||
24 | */ | ||
25 | |||
26 | |||
27 | #include <linux/config.h> | ||
28 | #include <linux/module.h> | ||
29 | #include <linux/types.h> | ||
30 | #include <linux/string.h> | ||
31 | #include <linux/kernel.h> | ||
32 | #include <linux/timer.h> | ||
33 | #include <linux/mm.h> | ||
34 | #include <linux/interrupt.h> | ||
35 | #include <linux/major.h> | ||
36 | #include <linux/errno.h> | ||
37 | #include <linux/genhd.h> | ||
38 | #include <linux/blkpg.h> | ||
39 | #include <linux/slab.h> | ||
40 | #include <linux/init.h> | ||
41 | #include <linux/pci.h> | ||
42 | #include <linux/delay.h> | ||
43 | #include <linux/ide.h> | ||
44 | #include <linux/completion.h> | ||
45 | #include <linux/reboot.h> | ||
46 | #include <linux/cdrom.h> | ||
47 | #include <linux/seq_file.h> | ||
48 | #include <linux/device.h> | ||
49 | #include <linux/kmod.h> | ||
50 | #include <linux/scatterlist.h> | ||
51 | |||
52 | #include <asm/byteorder.h> | ||
53 | #include <asm/irq.h> | ||
54 | #include <asm/uaccess.h> | ||
55 | #include <asm/io.h> | ||
56 | #include <asm/bitops.h> | ||
57 | |||
58 | int __ide_end_request(ide_drive_t *drive, struct request *rq, int uptodate, | ||
59 | int nr_sectors) | ||
60 | { | ||
61 | int ret = 1; | ||
62 | |||
63 | BUG_ON(!(rq->flags & REQ_STARTED)); | ||
64 | |||
65 | /* | ||
66 | * if failfast is set on a request, override number of sectors and | ||
67 | * complete the whole request right now | ||
68 | */ | ||
69 | if (blk_noretry_request(rq) && end_io_error(uptodate)) | ||
70 | nr_sectors = rq->hard_nr_sectors; | ||
71 | |||
72 | if (!blk_fs_request(rq) && end_io_error(uptodate) && !rq->errors) | ||
73 | rq->errors = -EIO; | ||
74 | |||
75 | /* | ||
76 | * decide whether to reenable DMA -- 3 is a random magic for now, | ||
77 | * if we DMA timeout more than 3 times, just stay in PIO | ||
78 | */ | ||
79 | if (drive->state == DMA_PIO_RETRY && drive->retry_pio <= 3) { | ||
80 | drive->state = 0; | ||
81 | HWGROUP(drive)->hwif->ide_dma_on(drive); | ||
82 | } | ||
83 | |||
84 | if (!end_that_request_first(rq, uptodate, nr_sectors)) { | ||
85 | add_disk_randomness(rq->rq_disk); | ||
86 | |||
87 | if (blk_rq_tagged(rq)) | ||
88 | blk_queue_end_tag(drive->queue, rq); | ||
89 | |||
90 | blkdev_dequeue_request(rq); | ||
91 | HWGROUP(drive)->rq = NULL; | ||
92 | end_that_request_last(rq); | ||
93 | ret = 0; | ||
94 | } | ||
95 | return ret; | ||
96 | } | ||
97 | EXPORT_SYMBOL(__ide_end_request); | ||
98 | |||
99 | /** | ||
100 | * ide_end_request - complete an IDE I/O | ||
101 | * @drive: IDE device for the I/O | ||
102 | * @uptodate: | ||
103 | * @nr_sectors: number of sectors completed | ||
104 | * | ||
105 | * This is our end_request wrapper function. We complete the I/O | ||
106 | * update random number input and dequeue the request, which if | ||
107 | * it was tagged may be out of order. | ||
108 | */ | ||
109 | |||
110 | int ide_end_request (ide_drive_t *drive, int uptodate, int nr_sectors) | ||
111 | { | ||
112 | struct request *rq; | ||
113 | unsigned long flags; | ||
114 | int ret = 1; | ||
115 | |||
116 | spin_lock_irqsave(&ide_lock, flags); | ||
117 | rq = HWGROUP(drive)->rq; | ||
118 | |||
119 | if (!nr_sectors) | ||
120 | nr_sectors = rq->hard_cur_sectors; | ||
121 | |||
122 | if (blk_complete_barrier_rq_locked(drive->queue, rq, nr_sectors)) | ||
123 | ret = rq->nr_sectors != 0; | ||
124 | else | ||
125 | ret = __ide_end_request(drive, rq, uptodate, nr_sectors); | ||
126 | |||
127 | spin_unlock_irqrestore(&ide_lock, flags); | ||
128 | return ret; | ||
129 | } | ||
130 | EXPORT_SYMBOL(ide_end_request); | ||
131 | |||
132 | /* | ||
133 | * Power Management state machine. This one is rather trivial for now, | ||
134 | * we should probably add more, like switching back to PIO on suspend | ||
135 | * to help some BIOSes, re-do the door locking on resume, etc... | ||
136 | */ | ||
137 | |||
138 | enum { | ||
139 | ide_pm_flush_cache = ide_pm_state_start_suspend, | ||
140 | idedisk_pm_standby, | ||
141 | |||
142 | idedisk_pm_idle = ide_pm_state_start_resume, | ||
143 | ide_pm_restore_dma, | ||
144 | }; | ||
145 | |||
146 | static void ide_complete_power_step(ide_drive_t *drive, struct request *rq, u8 stat, u8 error) | ||
147 | { | ||
148 | if (drive->media != ide_disk) | ||
149 | return; | ||
150 | |||
151 | switch (rq->pm->pm_step) { | ||
152 | case ide_pm_flush_cache: /* Suspend step 1 (flush cache) complete */ | ||
153 | if (rq->pm->pm_state == 4) | ||
154 | rq->pm->pm_step = ide_pm_state_completed; | ||
155 | else | ||
156 | rq->pm->pm_step = idedisk_pm_standby; | ||
157 | break; | ||
158 | case idedisk_pm_standby: /* Suspend step 2 (standby) complete */ | ||
159 | rq->pm->pm_step = ide_pm_state_completed; | ||
160 | break; | ||
161 | case idedisk_pm_idle: /* Resume step 1 (idle) complete */ | ||
162 | rq->pm->pm_step = ide_pm_restore_dma; | ||
163 | break; | ||
164 | } | ||
165 | } | ||
166 | |||
167 | static ide_startstop_t ide_start_power_step(ide_drive_t *drive, struct request *rq) | ||
168 | { | ||
169 | ide_task_t *args = rq->special; | ||
170 | |||
171 | memset(args, 0, sizeof(*args)); | ||
172 | |||
173 | if (drive->media != ide_disk) { | ||
174 | /* skip idedisk_pm_idle for ATAPI devices */ | ||
175 | if (rq->pm->pm_step == idedisk_pm_idle) | ||
176 | rq->pm->pm_step = ide_pm_restore_dma; | ||
177 | } | ||
178 | |||
179 | switch (rq->pm->pm_step) { | ||
180 | case ide_pm_flush_cache: /* Suspend step 1 (flush cache) */ | ||
181 | if (drive->media != ide_disk) | ||
182 | break; | ||
183 | /* Not supported? Switch to next step now. */ | ||
184 | if (!drive->wcache || !ide_id_has_flush_cache(drive->id)) { | ||
185 | ide_complete_power_step(drive, rq, 0, 0); | ||
186 | return ide_stopped; | ||
187 | } | ||
188 | if (ide_id_has_flush_cache_ext(drive->id)) | ||
189 | args->tfRegister[IDE_COMMAND_OFFSET] = WIN_FLUSH_CACHE_EXT; | ||
190 | else | ||
191 | args->tfRegister[IDE_COMMAND_OFFSET] = WIN_FLUSH_CACHE; | ||
192 | args->command_type = IDE_DRIVE_TASK_NO_DATA; | ||
193 | args->handler = &task_no_data_intr; | ||
194 | return do_rw_taskfile(drive, args); | ||
195 | |||
196 | case idedisk_pm_standby: /* Suspend step 2 (standby) */ | ||
197 | args->tfRegister[IDE_COMMAND_OFFSET] = WIN_STANDBYNOW1; | ||
198 | args->command_type = IDE_DRIVE_TASK_NO_DATA; | ||
199 | args->handler = &task_no_data_intr; | ||
200 | return do_rw_taskfile(drive, args); | ||
201 | |||
202 | case idedisk_pm_idle: /* Resume step 1 (idle) */ | ||
203 | args->tfRegister[IDE_COMMAND_OFFSET] = WIN_IDLEIMMEDIATE; | ||
204 | args->command_type = IDE_DRIVE_TASK_NO_DATA; | ||
205 | args->handler = task_no_data_intr; | ||
206 | return do_rw_taskfile(drive, args); | ||
207 | |||
208 | case ide_pm_restore_dma: /* Resume step 2 (restore DMA) */ | ||
209 | /* | ||
210 | * Right now, all we do is call hwif->ide_dma_check(drive), | ||
211 | * we could be smarter and check for current xfer_speed | ||
212 | * in struct drive etc... | ||
213 | */ | ||
214 | if ((drive->id->capability & 1) == 0) | ||
215 | break; | ||
216 | if (drive->hwif->ide_dma_check == NULL) | ||
217 | break; | ||
218 | drive->hwif->ide_dma_check(drive); | ||
219 | break; | ||
220 | } | ||
221 | rq->pm->pm_step = ide_pm_state_completed; | ||
222 | return ide_stopped; | ||
223 | } | ||
224 | |||
225 | /** | ||
226 | * ide_complete_pm_request - end the current Power Management request | ||
227 | * @drive: target drive | ||
228 | * @rq: request | ||
229 | * | ||
230 | * This function cleans up the current PM request and stops the queue | ||
231 | * if necessary. | ||
232 | */ | ||
233 | static void ide_complete_pm_request (ide_drive_t *drive, struct request *rq) | ||
234 | { | ||
235 | unsigned long flags; | ||
236 | |||
237 | #ifdef DEBUG_PM | ||
238 | printk("%s: completing PM request, %s\n", drive->name, | ||
239 | blk_pm_suspend_request(rq) ? "suspend" : "resume"); | ||
240 | #endif | ||
241 | spin_lock_irqsave(&ide_lock, flags); | ||
242 | if (blk_pm_suspend_request(rq)) { | ||
243 | blk_stop_queue(drive->queue); | ||
244 | } else { | ||
245 | drive->blocked = 0; | ||
246 | blk_start_queue(drive->queue); | ||
247 | } | ||
248 | blkdev_dequeue_request(rq); | ||
249 | HWGROUP(drive)->rq = NULL; | ||
250 | end_that_request_last(rq); | ||
251 | spin_unlock_irqrestore(&ide_lock, flags); | ||
252 | } | ||
253 | |||
254 | /* | ||
255 | * FIXME: probably move this somewhere else, name is bad too :) | ||
256 | */ | ||
257 | u64 ide_get_error_location(ide_drive_t *drive, char *args) | ||
258 | { | ||
259 | u32 high, low; | ||
260 | u8 hcyl, lcyl, sect; | ||
261 | u64 sector; | ||
262 | |||
263 | high = 0; | ||
264 | hcyl = args[5]; | ||
265 | lcyl = args[4]; | ||
266 | sect = args[3]; | ||
267 | |||
268 | if (ide_id_has_flush_cache_ext(drive->id)) { | ||
269 | low = (hcyl << 16) | (lcyl << 8) | sect; | ||
270 | HWIF(drive)->OUTB(drive->ctl|0x80, IDE_CONTROL_REG); | ||
271 | high = ide_read_24(drive); | ||
272 | } else { | ||
273 | u8 cur = HWIF(drive)->INB(IDE_SELECT_REG); | ||
274 | if (cur & 0x40) { | ||
275 | high = cur & 0xf; | ||
276 | low = (hcyl << 16) | (lcyl << 8) | sect; | ||
277 | } else { | ||
278 | low = hcyl * drive->head * drive->sect; | ||
279 | low += lcyl * drive->sect; | ||
280 | low += sect - 1; | ||
281 | } | ||
282 | } | ||
283 | |||
284 | sector = ((u64) high << 24) | low; | ||
285 | return sector; | ||
286 | } | ||
287 | EXPORT_SYMBOL(ide_get_error_location); | ||
288 | |||
289 | /** | ||
290 | * ide_end_drive_cmd - end an explicit drive command | ||
291 | * @drive: command | ||
292 | * @stat: status bits | ||
293 | * @err: error bits | ||
294 | * | ||
295 | * Clean up after success/failure of an explicit drive command. | ||
296 | * These get thrown onto the queue so they are synchronized with | ||
297 | * real I/O operations on the drive. | ||
298 | * | ||
299 | * In LBA48 mode we have to read the register set twice to get | ||
300 | * all the extra information out. | ||
301 | */ | ||
302 | |||
303 | void ide_end_drive_cmd (ide_drive_t *drive, u8 stat, u8 err) | ||
304 | { | ||
305 | ide_hwif_t *hwif = HWIF(drive); | ||
306 | unsigned long flags; | ||
307 | struct request *rq; | ||
308 | |||
309 | spin_lock_irqsave(&ide_lock, flags); | ||
310 | rq = HWGROUP(drive)->rq; | ||
311 | spin_unlock_irqrestore(&ide_lock, flags); | ||
312 | |||
313 | if (rq->flags & REQ_DRIVE_CMD) { | ||
314 | u8 *args = (u8 *) rq->buffer; | ||
315 | if (rq->errors == 0) | ||
316 | rq->errors = !OK_STAT(stat,READY_STAT,BAD_STAT); | ||
317 | |||
318 | if (args) { | ||
319 | args[0] = stat; | ||
320 | args[1] = err; | ||
321 | args[2] = hwif->INB(IDE_NSECTOR_REG); | ||
322 | } | ||
323 | } else if (rq->flags & REQ_DRIVE_TASK) { | ||
324 | u8 *args = (u8 *) rq->buffer; | ||
325 | if (rq->errors == 0) | ||
326 | rq->errors = !OK_STAT(stat,READY_STAT,BAD_STAT); | ||
327 | |||
328 | if (args) { | ||
329 | args[0] = stat; | ||
330 | args[1] = err; | ||
331 | args[2] = hwif->INB(IDE_NSECTOR_REG); | ||
332 | args[3] = hwif->INB(IDE_SECTOR_REG); | ||
333 | args[4] = hwif->INB(IDE_LCYL_REG); | ||
334 | args[5] = hwif->INB(IDE_HCYL_REG); | ||
335 | args[6] = hwif->INB(IDE_SELECT_REG); | ||
336 | } | ||
337 | } else if (rq->flags & REQ_DRIVE_TASKFILE) { | ||
338 | ide_task_t *args = (ide_task_t *) rq->special; | ||
339 | if (rq->errors == 0) | ||
340 | rq->errors = !OK_STAT(stat,READY_STAT,BAD_STAT); | ||
341 | |||
342 | if (args) { | ||
343 | if (args->tf_in_flags.b.data) { | ||
344 | u16 data = hwif->INW(IDE_DATA_REG); | ||
345 | args->tfRegister[IDE_DATA_OFFSET] = (data) & 0xFF; | ||
346 | args->hobRegister[IDE_DATA_OFFSET] = (data >> 8) & 0xFF; | ||
347 | } | ||
348 | args->tfRegister[IDE_ERROR_OFFSET] = err; | ||
349 | /* be sure we're looking at the low order bits */ | ||
350 | hwif->OUTB(drive->ctl & ~0x80, IDE_CONTROL_REG); | ||
351 | args->tfRegister[IDE_NSECTOR_OFFSET] = hwif->INB(IDE_NSECTOR_REG); | ||
352 | args->tfRegister[IDE_SECTOR_OFFSET] = hwif->INB(IDE_SECTOR_REG); | ||
353 | args->tfRegister[IDE_LCYL_OFFSET] = hwif->INB(IDE_LCYL_REG); | ||
354 | args->tfRegister[IDE_HCYL_OFFSET] = hwif->INB(IDE_HCYL_REG); | ||
355 | args->tfRegister[IDE_SELECT_OFFSET] = hwif->INB(IDE_SELECT_REG); | ||
356 | args->tfRegister[IDE_STATUS_OFFSET] = stat; | ||
357 | |||
358 | if (drive->addressing == 1) { | ||
359 | hwif->OUTB(drive->ctl|0x80, IDE_CONTROL_REG); | ||
360 | args->hobRegister[IDE_FEATURE_OFFSET] = hwif->INB(IDE_FEATURE_REG); | ||
361 | args->hobRegister[IDE_NSECTOR_OFFSET] = hwif->INB(IDE_NSECTOR_REG); | ||
362 | args->hobRegister[IDE_SECTOR_OFFSET] = hwif->INB(IDE_SECTOR_REG); | ||
363 | args->hobRegister[IDE_LCYL_OFFSET] = hwif->INB(IDE_LCYL_REG); | ||
364 | args->hobRegister[IDE_HCYL_OFFSET] = hwif->INB(IDE_HCYL_REG); | ||
365 | } | ||
366 | } | ||
367 | } else if (blk_pm_request(rq)) { | ||
368 | #ifdef DEBUG_PM | ||
369 | printk("%s: complete_power_step(step: %d, stat: %x, err: %x)\n", | ||
370 | drive->name, rq->pm->pm_step, stat, err); | ||
371 | #endif | ||
372 | ide_complete_power_step(drive, rq, stat, err); | ||
373 | if (rq->pm->pm_step == ide_pm_state_completed) | ||
374 | ide_complete_pm_request(drive, rq); | ||
375 | return; | ||
376 | } | ||
377 | |||
378 | spin_lock_irqsave(&ide_lock, flags); | ||
379 | blkdev_dequeue_request(rq); | ||
380 | HWGROUP(drive)->rq = NULL; | ||
381 | rq->errors = err; | ||
382 | end_that_request_last(rq); | ||
383 | spin_unlock_irqrestore(&ide_lock, flags); | ||
384 | } | ||
385 | |||
386 | EXPORT_SYMBOL(ide_end_drive_cmd); | ||
387 | |||
388 | /** | ||
389 | * try_to_flush_leftover_data - flush junk | ||
390 | * @drive: drive to flush | ||
391 | * | ||
392 | * try_to_flush_leftover_data() is invoked in response to a drive | ||
393 | * unexpectedly having its DRQ_STAT bit set. As an alternative to | ||
394 | * resetting the drive, this routine tries to clear the condition | ||
395 | * by read a sector's worth of data from the drive. Of course, | ||
396 | * this may not help if the drive is *waiting* for data from *us*. | ||
397 | */ | ||
398 | static void try_to_flush_leftover_data (ide_drive_t *drive) | ||
399 | { | ||
400 | int i = (drive->mult_count ? drive->mult_count : 1) * SECTOR_WORDS; | ||
401 | |||
402 | if (drive->media != ide_disk) | ||
403 | return; | ||
404 | while (i > 0) { | ||
405 | u32 buffer[16]; | ||
406 | u32 wcount = (i > 16) ? 16 : i; | ||
407 | |||
408 | i -= wcount; | ||
409 | HWIF(drive)->ata_input_data(drive, buffer, wcount); | ||
410 | } | ||
411 | } | ||
412 | |||
413 | static void ide_kill_rq(ide_drive_t *drive, struct request *rq) | ||
414 | { | ||
415 | if (rq->rq_disk) { | ||
416 | ide_driver_t *drv; | ||
417 | |||
418 | drv = *(ide_driver_t **)rq->rq_disk->private_data; | ||
419 | drv->end_request(drive, 0, 0); | ||
420 | } else | ||
421 | ide_end_request(drive, 0, 0); | ||
422 | } | ||
423 | |||
424 | static ide_startstop_t ide_ata_error(ide_drive_t *drive, struct request *rq, u8 stat, u8 err) | ||
425 | { | ||
426 | ide_hwif_t *hwif = drive->hwif; | ||
427 | |||
428 | if (stat & BUSY_STAT || ((stat & WRERR_STAT) && !drive->nowerr)) { | ||
429 | /* other bits are useless when BUSY */ | ||
430 | rq->errors |= ERROR_RESET; | ||
431 | } else if (stat & ERR_STAT) { | ||
432 | /* err has different meaning on cdrom and tape */ | ||
433 | if (err == ABRT_ERR) { | ||
434 | if (drive->select.b.lba && | ||
435 | /* some newer drives don't support WIN_SPECIFY */ | ||
436 | hwif->INB(IDE_COMMAND_REG) == WIN_SPECIFY) | ||
437 | return ide_stopped; | ||
438 | } else if ((err & BAD_CRC) == BAD_CRC) { | ||
439 | /* UDMA crc error, just retry the operation */ | ||
440 | drive->crc_count++; | ||
441 | } else if (err & (BBD_ERR | ECC_ERR)) { | ||
442 | /* retries won't help these */ | ||
443 | rq->errors = ERROR_MAX; | ||
444 | } else if (err & TRK0_ERR) { | ||
445 | /* help it find track zero */ | ||
446 | rq->errors |= ERROR_RECAL; | ||
447 | } | ||
448 | } | ||
449 | |||
450 | if ((stat & DRQ_STAT) && rq_data_dir(rq) == READ) | ||
451 | try_to_flush_leftover_data(drive); | ||
452 | |||
453 | if (hwif->INB(IDE_STATUS_REG) & (BUSY_STAT|DRQ_STAT)) | ||
454 | /* force an abort */ | ||
455 | hwif->OUTB(WIN_IDLEIMMEDIATE, IDE_COMMAND_REG); | ||
456 | |||
457 | if (rq->errors >= ERROR_MAX || blk_noretry_request(rq)) | ||
458 | ide_kill_rq(drive, rq); | ||
459 | else { | ||
460 | if ((rq->errors & ERROR_RESET) == ERROR_RESET) { | ||
461 | ++rq->errors; | ||
462 | return ide_do_reset(drive); | ||
463 | } | ||
464 | if ((rq->errors & ERROR_RECAL) == ERROR_RECAL) | ||
465 | drive->special.b.recalibrate = 1; | ||
466 | ++rq->errors; | ||
467 | } | ||
468 | return ide_stopped; | ||
469 | } | ||
470 | |||
471 | static ide_startstop_t ide_atapi_error(ide_drive_t *drive, struct request *rq, u8 stat, u8 err) | ||
472 | { | ||
473 | ide_hwif_t *hwif = drive->hwif; | ||
474 | |||
475 | if (stat & BUSY_STAT || ((stat & WRERR_STAT) && !drive->nowerr)) { | ||
476 | /* other bits are useless when BUSY */ | ||
477 | rq->errors |= ERROR_RESET; | ||
478 | } else { | ||
479 | /* add decoding error stuff */ | ||
480 | } | ||
481 | |||
482 | if (hwif->INB(IDE_STATUS_REG) & (BUSY_STAT|DRQ_STAT)) | ||
483 | /* force an abort */ | ||
484 | hwif->OUTB(WIN_IDLEIMMEDIATE, IDE_COMMAND_REG); | ||
485 | |||
486 | if (rq->errors >= ERROR_MAX) { | ||
487 | ide_kill_rq(drive, rq); | ||
488 | } else { | ||
489 | if ((rq->errors & ERROR_RESET) == ERROR_RESET) { | ||
490 | ++rq->errors; | ||
491 | return ide_do_reset(drive); | ||
492 | } | ||
493 | ++rq->errors; | ||
494 | } | ||
495 | |||
496 | return ide_stopped; | ||
497 | } | ||
498 | |||
499 | ide_startstop_t | ||
500 | __ide_error(ide_drive_t *drive, struct request *rq, u8 stat, u8 err) | ||
501 | { | ||
502 | if (drive->media == ide_disk) | ||
503 | return ide_ata_error(drive, rq, stat, err); | ||
504 | return ide_atapi_error(drive, rq, stat, err); | ||
505 | } | ||
506 | |||
507 | EXPORT_SYMBOL_GPL(__ide_error); | ||
508 | |||
509 | /** | ||
510 | * ide_error - handle an error on the IDE | ||
511 | * @drive: drive the error occurred on | ||
512 | * @msg: message to report | ||
513 | * @stat: status bits | ||
514 | * | ||
515 | * ide_error() takes action based on the error returned by the drive. | ||
516 | * For normal I/O that may well include retries. We deal with | ||
517 | * both new-style (taskfile) and old style command handling here. | ||
518 | * In the case of taskfile command handling there is work left to | ||
519 | * do | ||
520 | */ | ||
521 | |||
522 | ide_startstop_t ide_error (ide_drive_t *drive, const char *msg, u8 stat) | ||
523 | { | ||
524 | struct request *rq; | ||
525 | u8 err; | ||
526 | |||
527 | err = ide_dump_status(drive, msg, stat); | ||
528 | |||
529 | if ((rq = HWGROUP(drive)->rq) == NULL) | ||
530 | return ide_stopped; | ||
531 | |||
532 | /* retry only "normal" I/O: */ | ||
533 | if (rq->flags & (REQ_DRIVE_CMD | REQ_DRIVE_TASK | REQ_DRIVE_TASKFILE)) { | ||
534 | rq->errors = 1; | ||
535 | ide_end_drive_cmd(drive, stat, err); | ||
536 | return ide_stopped; | ||
537 | } | ||
538 | |||
539 | if (rq->rq_disk) { | ||
540 | ide_driver_t *drv; | ||
541 | |||
542 | drv = *(ide_driver_t **)rq->rq_disk->private_data; | ||
543 | return drv->error(drive, rq, stat, err); | ||
544 | } else | ||
545 | return __ide_error(drive, rq, stat, err); | ||
546 | } | ||
547 | |||
548 | EXPORT_SYMBOL_GPL(ide_error); | ||
549 | |||
550 | ide_startstop_t __ide_abort(ide_drive_t *drive, struct request *rq) | ||
551 | { | ||
552 | if (drive->media != ide_disk) | ||
553 | rq->errors |= ERROR_RESET; | ||
554 | |||
555 | ide_kill_rq(drive, rq); | ||
556 | |||
557 | return ide_stopped; | ||
558 | } | ||
559 | |||
560 | EXPORT_SYMBOL_GPL(__ide_abort); | ||
561 | |||
562 | /** | ||
563 | * ide_abort - abort pending IDE operatins | ||
564 | * @drive: drive the error occurred on | ||
565 | * @msg: message to report | ||
566 | * | ||
567 | * ide_abort kills and cleans up when we are about to do a | ||
568 | * host initiated reset on active commands. Longer term we | ||
569 | * want handlers to have sensible abort handling themselves | ||
570 | * | ||
571 | * This differs fundamentally from ide_error because in | ||
572 | * this case the command is doing just fine when we | ||
573 | * blow it away. | ||
574 | */ | ||
575 | |||
576 | ide_startstop_t ide_abort(ide_drive_t *drive, const char *msg) | ||
577 | { | ||
578 | struct request *rq; | ||
579 | |||
580 | if (drive == NULL || (rq = HWGROUP(drive)->rq) == NULL) | ||
581 | return ide_stopped; | ||
582 | |||
583 | /* retry only "normal" I/O: */ | ||
584 | if (rq->flags & (REQ_DRIVE_CMD | REQ_DRIVE_TASK | REQ_DRIVE_TASKFILE)) { | ||
585 | rq->errors = 1; | ||
586 | ide_end_drive_cmd(drive, BUSY_STAT, 0); | ||
587 | return ide_stopped; | ||
588 | } | ||
589 | |||
590 | if (rq->rq_disk) { | ||
591 | ide_driver_t *drv; | ||
592 | |||
593 | drv = *(ide_driver_t **)rq->rq_disk->private_data; | ||
594 | return drv->abort(drive, rq); | ||
595 | } else | ||
596 | return __ide_abort(drive, rq); | ||
597 | } | ||
598 | |||
599 | /** | ||
600 | * ide_cmd - issue a simple drive command | ||
601 | * @drive: drive the command is for | ||
602 | * @cmd: command byte | ||
603 | * @nsect: sector byte | ||
604 | * @handler: handler for the command completion | ||
605 | * | ||
606 | * Issue a simple drive command with interrupts. | ||
607 | * The drive must be selected beforehand. | ||
608 | */ | ||
609 | |||
610 | static void ide_cmd (ide_drive_t *drive, u8 cmd, u8 nsect, | ||
611 | ide_handler_t *handler) | ||
612 | { | ||
613 | ide_hwif_t *hwif = HWIF(drive); | ||
614 | if (IDE_CONTROL_REG) | ||
615 | hwif->OUTB(drive->ctl,IDE_CONTROL_REG); /* clear nIEN */ | ||
616 | SELECT_MASK(drive,0); | ||
617 | hwif->OUTB(nsect,IDE_NSECTOR_REG); | ||
618 | ide_execute_command(drive, cmd, handler, WAIT_CMD, NULL); | ||
619 | } | ||
620 | |||
621 | /** | ||
622 | * drive_cmd_intr - drive command completion interrupt | ||
623 | * @drive: drive the completion interrupt occurred on | ||
624 | * | ||
625 | * drive_cmd_intr() is invoked on completion of a special DRIVE_CMD. | ||
626 | * We do any necessary daya reading and then wait for the drive to | ||
627 | * go non busy. At that point we may read the error data and complete | ||
628 | * the request | ||
629 | */ | ||
630 | |||
631 | static ide_startstop_t drive_cmd_intr (ide_drive_t *drive) | ||
632 | { | ||
633 | struct request *rq = HWGROUP(drive)->rq; | ||
634 | ide_hwif_t *hwif = HWIF(drive); | ||
635 | u8 *args = (u8 *) rq->buffer; | ||
636 | u8 stat = hwif->INB(IDE_STATUS_REG); | ||
637 | int retries = 10; | ||
638 | |||
639 | local_irq_enable(); | ||
640 | if ((stat & DRQ_STAT) && args && args[3]) { | ||
641 | u8 io_32bit = drive->io_32bit; | ||
642 | drive->io_32bit = 0; | ||
643 | hwif->ata_input_data(drive, &args[4], args[3] * SECTOR_WORDS); | ||
644 | drive->io_32bit = io_32bit; | ||
645 | while (((stat = hwif->INB(IDE_STATUS_REG)) & BUSY_STAT) && retries--) | ||
646 | udelay(100); | ||
647 | } | ||
648 | |||
649 | if (!OK_STAT(stat, READY_STAT, BAD_STAT)) | ||
650 | return ide_error(drive, "drive_cmd", stat); | ||
651 | /* calls ide_end_drive_cmd */ | ||
652 | ide_end_drive_cmd(drive, stat, hwif->INB(IDE_ERROR_REG)); | ||
653 | return ide_stopped; | ||
654 | } | ||
655 | |||
656 | static void ide_init_specify_cmd(ide_drive_t *drive, ide_task_t *task) | ||
657 | { | ||
658 | task->tfRegister[IDE_NSECTOR_OFFSET] = drive->sect; | ||
659 | task->tfRegister[IDE_SECTOR_OFFSET] = drive->sect; | ||
660 | task->tfRegister[IDE_LCYL_OFFSET] = drive->cyl; | ||
661 | task->tfRegister[IDE_HCYL_OFFSET] = drive->cyl>>8; | ||
662 | task->tfRegister[IDE_SELECT_OFFSET] = ((drive->head-1)|drive->select.all)&0xBF; | ||
663 | task->tfRegister[IDE_COMMAND_OFFSET] = WIN_SPECIFY; | ||
664 | |||
665 | task->handler = &set_geometry_intr; | ||
666 | } | ||
667 | |||
668 | static void ide_init_restore_cmd(ide_drive_t *drive, ide_task_t *task) | ||
669 | { | ||
670 | task->tfRegister[IDE_NSECTOR_OFFSET] = drive->sect; | ||
671 | task->tfRegister[IDE_COMMAND_OFFSET] = WIN_RESTORE; | ||
672 | |||
673 | task->handler = &recal_intr; | ||
674 | } | ||
675 | |||
676 | static void ide_init_setmult_cmd(ide_drive_t *drive, ide_task_t *task) | ||
677 | { | ||
678 | task->tfRegister[IDE_NSECTOR_OFFSET] = drive->mult_req; | ||
679 | task->tfRegister[IDE_COMMAND_OFFSET] = WIN_SETMULT; | ||
680 | |||
681 | task->handler = &set_multmode_intr; | ||
682 | } | ||
683 | |||
684 | static ide_startstop_t ide_disk_special(ide_drive_t *drive) | ||
685 | { | ||
686 | special_t *s = &drive->special; | ||
687 | ide_task_t args; | ||
688 | |||
689 | memset(&args, 0, sizeof(ide_task_t)); | ||
690 | args.command_type = IDE_DRIVE_TASK_NO_DATA; | ||
691 | |||
692 | if (s->b.set_geometry) { | ||
693 | s->b.set_geometry = 0; | ||
694 | ide_init_specify_cmd(drive, &args); | ||
695 | } else if (s->b.recalibrate) { | ||
696 | s->b.recalibrate = 0; | ||
697 | ide_init_restore_cmd(drive, &args); | ||
698 | } else if (s->b.set_multmode) { | ||
699 | s->b.set_multmode = 0; | ||
700 | if (drive->mult_req > drive->id->max_multsect) | ||
701 | drive->mult_req = drive->id->max_multsect; | ||
702 | ide_init_setmult_cmd(drive, &args); | ||
703 | } else if (s->all) { | ||
704 | int special = s->all; | ||
705 | s->all = 0; | ||
706 | printk(KERN_ERR "%s: bad special flag: 0x%02x\n", drive->name, special); | ||
707 | return ide_stopped; | ||
708 | } | ||
709 | |||
710 | do_rw_taskfile(drive, &args); | ||
711 | |||
712 | return ide_started; | ||
713 | } | ||
714 | |||
715 | /** | ||
716 | * do_special - issue some special commands | ||
717 | * @drive: drive the command is for | ||
718 | * | ||
719 | * do_special() is used to issue WIN_SPECIFY, WIN_RESTORE, and WIN_SETMULT | ||
720 | * commands to a drive. It used to do much more, but has been scaled | ||
721 | * back. | ||
722 | */ | ||
723 | |||
724 | static ide_startstop_t do_special (ide_drive_t *drive) | ||
725 | { | ||
726 | special_t *s = &drive->special; | ||
727 | |||
728 | #ifdef DEBUG | ||
729 | printk("%s: do_special: 0x%02x\n", drive->name, s->all); | ||
730 | #endif | ||
731 | if (s->b.set_tune) { | ||
732 | s->b.set_tune = 0; | ||
733 | if (HWIF(drive)->tuneproc != NULL) | ||
734 | HWIF(drive)->tuneproc(drive, drive->tune_req); | ||
735 | return ide_stopped; | ||
736 | } else { | ||
737 | if (drive->media == ide_disk) | ||
738 | return ide_disk_special(drive); | ||
739 | |||
740 | s->all = 0; | ||
741 | drive->mult_req = 0; | ||
742 | return ide_stopped; | ||
743 | } | ||
744 | } | ||
745 | |||
746 | void ide_map_sg(ide_drive_t *drive, struct request *rq) | ||
747 | { | ||
748 | ide_hwif_t *hwif = drive->hwif; | ||
749 | struct scatterlist *sg = hwif->sg_table; | ||
750 | |||
751 | if (hwif->sg_mapped) /* needed by ide-scsi */ | ||
752 | return; | ||
753 | |||
754 | if ((rq->flags & REQ_DRIVE_TASKFILE) == 0) { | ||
755 | hwif->sg_nents = blk_rq_map_sg(drive->queue, rq, sg); | ||
756 | } else { | ||
757 | sg_init_one(sg, rq->buffer, rq->nr_sectors * SECTOR_SIZE); | ||
758 | hwif->sg_nents = 1; | ||
759 | } | ||
760 | } | ||
761 | |||
762 | EXPORT_SYMBOL_GPL(ide_map_sg); | ||
763 | |||
764 | void ide_init_sg_cmd(ide_drive_t *drive, struct request *rq) | ||
765 | { | ||
766 | ide_hwif_t *hwif = drive->hwif; | ||
767 | |||
768 | hwif->nsect = hwif->nleft = rq->nr_sectors; | ||
769 | hwif->cursg = hwif->cursg_ofs = 0; | ||
770 | } | ||
771 | |||
772 | EXPORT_SYMBOL_GPL(ide_init_sg_cmd); | ||
773 | |||
774 | /** | ||
775 | * execute_drive_command - issue special drive command | ||
776 | * @drive: the drive to issue th command on | ||
777 | * @rq: the request structure holding the command | ||
778 | * | ||
779 | * execute_drive_cmd() issues a special drive command, usually | ||
780 | * initiated by ioctl() from the external hdparm program. The | ||
781 | * command can be a drive command, drive task or taskfile | ||
782 | * operation. Weirdly you can call it with NULL to wait for | ||
783 | * all commands to finish. Don't do this as that is due to change | ||
784 | */ | ||
785 | |||
786 | static ide_startstop_t execute_drive_cmd (ide_drive_t *drive, | ||
787 | struct request *rq) | ||
788 | { | ||
789 | ide_hwif_t *hwif = HWIF(drive); | ||
790 | if (rq->flags & REQ_DRIVE_TASKFILE) { | ||
791 | ide_task_t *args = rq->special; | ||
792 | |||
793 | if (!args) | ||
794 | goto done; | ||
795 | |||
796 | hwif->data_phase = args->data_phase; | ||
797 | |||
798 | switch (hwif->data_phase) { | ||
799 | case TASKFILE_MULTI_OUT: | ||
800 | case TASKFILE_OUT: | ||
801 | case TASKFILE_MULTI_IN: | ||
802 | case TASKFILE_IN: | ||
803 | ide_init_sg_cmd(drive, rq); | ||
804 | ide_map_sg(drive, rq); | ||
805 | default: | ||
806 | break; | ||
807 | } | ||
808 | |||
809 | if (args->tf_out_flags.all != 0) | ||
810 | return flagged_taskfile(drive, args); | ||
811 | return do_rw_taskfile(drive, args); | ||
812 | } else if (rq->flags & REQ_DRIVE_TASK) { | ||
813 | u8 *args = rq->buffer; | ||
814 | u8 sel; | ||
815 | |||
816 | if (!args) | ||
817 | goto done; | ||
818 | #ifdef DEBUG | ||
819 | printk("%s: DRIVE_TASK_CMD ", drive->name); | ||
820 | printk("cmd=0x%02x ", args[0]); | ||
821 | printk("fr=0x%02x ", args[1]); | ||
822 | printk("ns=0x%02x ", args[2]); | ||
823 | printk("sc=0x%02x ", args[3]); | ||
824 | printk("lcyl=0x%02x ", args[4]); | ||
825 | printk("hcyl=0x%02x ", args[5]); | ||
826 | printk("sel=0x%02x\n", args[6]); | ||
827 | #endif | ||
828 | hwif->OUTB(args[1], IDE_FEATURE_REG); | ||
829 | hwif->OUTB(args[3], IDE_SECTOR_REG); | ||
830 | hwif->OUTB(args[4], IDE_LCYL_REG); | ||
831 | hwif->OUTB(args[5], IDE_HCYL_REG); | ||
832 | sel = (args[6] & ~0x10); | ||
833 | if (drive->select.b.unit) | ||
834 | sel |= 0x10; | ||
835 | hwif->OUTB(sel, IDE_SELECT_REG); | ||
836 | ide_cmd(drive, args[0], args[2], &drive_cmd_intr); | ||
837 | return ide_started; | ||
838 | } else if (rq->flags & REQ_DRIVE_CMD) { | ||
839 | u8 *args = rq->buffer; | ||
840 | |||
841 | if (!args) | ||
842 | goto done; | ||
843 | #ifdef DEBUG | ||
844 | printk("%s: DRIVE_CMD ", drive->name); | ||
845 | printk("cmd=0x%02x ", args[0]); | ||
846 | printk("sc=0x%02x ", args[1]); | ||
847 | printk("fr=0x%02x ", args[2]); | ||
848 | printk("xx=0x%02x\n", args[3]); | ||
849 | #endif | ||
850 | if (args[0] == WIN_SMART) { | ||
851 | hwif->OUTB(0x4f, IDE_LCYL_REG); | ||
852 | hwif->OUTB(0xc2, IDE_HCYL_REG); | ||
853 | hwif->OUTB(args[2],IDE_FEATURE_REG); | ||
854 | hwif->OUTB(args[1],IDE_SECTOR_REG); | ||
855 | ide_cmd(drive, args[0], args[3], &drive_cmd_intr); | ||
856 | return ide_started; | ||
857 | } | ||
858 | hwif->OUTB(args[2],IDE_FEATURE_REG); | ||
859 | ide_cmd(drive, args[0], args[1], &drive_cmd_intr); | ||
860 | return ide_started; | ||
861 | } | ||
862 | |||
863 | done: | ||
864 | /* | ||
865 | * NULL is actually a valid way of waiting for | ||
866 | * all current requests to be flushed from the queue. | ||
867 | */ | ||
868 | #ifdef DEBUG | ||
869 | printk("%s: DRIVE_CMD (null)\n", drive->name); | ||
870 | #endif | ||
871 | ide_end_drive_cmd(drive, | ||
872 | hwif->INB(IDE_STATUS_REG), | ||
873 | hwif->INB(IDE_ERROR_REG)); | ||
874 | return ide_stopped; | ||
875 | } | ||
876 | |||
877 | /** | ||
878 | * start_request - start of I/O and command issuing for IDE | ||
879 | * | ||
880 | * start_request() initiates handling of a new I/O request. It | ||
881 | * accepts commands and I/O (read/write) requests. It also does | ||
882 | * the final remapping for weird stuff like EZDrive. Once | ||
883 | * device mapper can work sector level the EZDrive stuff can go away | ||
884 | * | ||
885 | * FIXME: this function needs a rename | ||
886 | */ | ||
887 | |||
888 | static ide_startstop_t start_request (ide_drive_t *drive, struct request *rq) | ||
889 | { | ||
890 | ide_startstop_t startstop; | ||
891 | sector_t block; | ||
892 | |||
893 | BUG_ON(!(rq->flags & REQ_STARTED)); | ||
894 | |||
895 | #ifdef DEBUG | ||
896 | printk("%s: start_request: current=0x%08lx\n", | ||
897 | HWIF(drive)->name, (unsigned long) rq); | ||
898 | #endif | ||
899 | |||
900 | /* bail early if we've exceeded max_failures */ | ||
901 | if (drive->max_failures && (drive->failures > drive->max_failures)) { | ||
902 | goto kill_rq; | ||
903 | } | ||
904 | |||
905 | block = rq->sector; | ||
906 | if (blk_fs_request(rq) && | ||
907 | (drive->media == ide_disk || drive->media == ide_floppy)) { | ||
908 | block += drive->sect0; | ||
909 | } | ||
910 | /* Yecch - this will shift the entire interval, | ||
911 | possibly killing some innocent following sector */ | ||
912 | if (block == 0 && drive->remap_0_to_1 == 1) | ||
913 | block = 1; /* redirect MBR access to EZ-Drive partn table */ | ||
914 | |||
915 | if (blk_pm_suspend_request(rq) && | ||
916 | rq->pm->pm_step == ide_pm_state_start_suspend) | ||
917 | /* Mark drive blocked when starting the suspend sequence. */ | ||
918 | drive->blocked = 1; | ||
919 | else if (blk_pm_resume_request(rq) && | ||
920 | rq->pm->pm_step == ide_pm_state_start_resume) { | ||
921 | /* | ||
922 | * The first thing we do on wakeup is to wait for BSY bit to | ||
923 | * go away (with a looong timeout) as a drive on this hwif may | ||
924 | * just be POSTing itself. | ||
925 | * We do that before even selecting as the "other" device on | ||
926 | * the bus may be broken enough to walk on our toes at this | ||
927 | * point. | ||
928 | */ | ||
929 | int rc; | ||
930 | #ifdef DEBUG_PM | ||
931 | printk("%s: Wakeup request inited, waiting for !BSY...\n", drive->name); | ||
932 | #endif | ||
933 | rc = ide_wait_not_busy(HWIF(drive), 35000); | ||
934 | if (rc) | ||
935 | printk(KERN_WARNING "%s: bus not ready on wakeup\n", drive->name); | ||
936 | SELECT_DRIVE(drive); | ||
937 | HWIF(drive)->OUTB(8, HWIF(drive)->io_ports[IDE_CONTROL_OFFSET]); | ||
938 | rc = ide_wait_not_busy(HWIF(drive), 10000); | ||
939 | if (rc) | ||
940 | printk(KERN_WARNING "%s: drive not ready on wakeup\n", drive->name); | ||
941 | } | ||
942 | |||
943 | SELECT_DRIVE(drive); | ||
944 | if (ide_wait_stat(&startstop, drive, drive->ready_stat, BUSY_STAT|DRQ_STAT, WAIT_READY)) { | ||
945 | printk(KERN_ERR "%s: drive not ready for command\n", drive->name); | ||
946 | return startstop; | ||
947 | } | ||
948 | if (!drive->special.all) { | ||
949 | ide_driver_t *drv; | ||
950 | |||
951 | if (rq->flags & (REQ_DRIVE_CMD | REQ_DRIVE_TASK)) | ||
952 | return execute_drive_cmd(drive, rq); | ||
953 | else if (rq->flags & REQ_DRIVE_TASKFILE) | ||
954 | return execute_drive_cmd(drive, rq); | ||
955 | else if (blk_pm_request(rq)) { | ||
956 | #ifdef DEBUG_PM | ||
957 | printk("%s: start_power_step(step: %d)\n", | ||
958 | drive->name, rq->pm->pm_step); | ||
959 | #endif | ||
960 | startstop = ide_start_power_step(drive, rq); | ||
961 | if (startstop == ide_stopped && | ||
962 | rq->pm->pm_step == ide_pm_state_completed) | ||
963 | ide_complete_pm_request(drive, rq); | ||
964 | return startstop; | ||
965 | } | ||
966 | |||
967 | drv = *(ide_driver_t **)rq->rq_disk->private_data; | ||
968 | return drv->do_request(drive, rq, block); | ||
969 | } | ||
970 | return do_special(drive); | ||
971 | kill_rq: | ||
972 | ide_kill_rq(drive, rq); | ||
973 | return ide_stopped; | ||
974 | } | ||
975 | |||
976 | /** | ||
977 | * ide_stall_queue - pause an IDE device | ||
978 | * @drive: drive to stall | ||
979 | * @timeout: time to stall for (jiffies) | ||
980 | * | ||
981 | * ide_stall_queue() can be used by a drive to give excess bandwidth back | ||
982 | * to the hwgroup by sleeping for timeout jiffies. | ||
983 | */ | ||
984 | |||
985 | void ide_stall_queue (ide_drive_t *drive, unsigned long timeout) | ||
986 | { | ||
987 | if (timeout > WAIT_WORSTCASE) | ||
988 | timeout = WAIT_WORSTCASE; | ||
989 | drive->sleep = timeout + jiffies; | ||
990 | drive->sleeping = 1; | ||
991 | } | ||
992 | |||
993 | EXPORT_SYMBOL(ide_stall_queue); | ||
994 | |||
995 | #define WAKEUP(drive) ((drive)->service_start + 2 * (drive)->service_time) | ||
996 | |||
997 | /** | ||
998 | * choose_drive - select a drive to service | ||
999 | * @hwgroup: hardware group to select on | ||
1000 | * | ||
1001 | * choose_drive() selects the next drive which will be serviced. | ||
1002 | * This is necessary because the IDE layer can't issue commands | ||
1003 | * to both drives on the same cable, unlike SCSI. | ||
1004 | */ | ||
1005 | |||
1006 | static inline ide_drive_t *choose_drive (ide_hwgroup_t *hwgroup) | ||
1007 | { | ||
1008 | ide_drive_t *drive, *best; | ||
1009 | |||
1010 | repeat: | ||
1011 | best = NULL; | ||
1012 | drive = hwgroup->drive; | ||
1013 | |||
1014 | /* | ||
1015 | * drive is doing pre-flush, ordered write, post-flush sequence. even | ||
1016 | * though that is 3 requests, it must be seen as a single transaction. | ||
1017 | * we must not preempt this drive until that is complete | ||
1018 | */ | ||
1019 | if (blk_queue_flushing(drive->queue)) { | ||
1020 | /* | ||
1021 | * small race where queue could get replugged during | ||
1022 | * the 3-request flush cycle, just yank the plug since | ||
1023 | * we want it to finish asap | ||
1024 | */ | ||
1025 | blk_remove_plug(drive->queue); | ||
1026 | return drive; | ||
1027 | } | ||
1028 | |||
1029 | do { | ||
1030 | if ((!drive->sleeping || time_after_eq(jiffies, drive->sleep)) | ||
1031 | && !elv_queue_empty(drive->queue)) { | ||
1032 | if (!best | ||
1033 | || (drive->sleeping && (!best->sleeping || time_before(drive->sleep, best->sleep))) | ||
1034 | || (!best->sleeping && time_before(WAKEUP(drive), WAKEUP(best)))) | ||
1035 | { | ||
1036 | if (!blk_queue_plugged(drive->queue)) | ||
1037 | best = drive; | ||
1038 | } | ||
1039 | } | ||
1040 | } while ((drive = drive->next) != hwgroup->drive); | ||
1041 | if (best && best->nice1 && !best->sleeping && best != hwgroup->drive && best->service_time > WAIT_MIN_SLEEP) { | ||
1042 | long t = (signed long)(WAKEUP(best) - jiffies); | ||
1043 | if (t >= WAIT_MIN_SLEEP) { | ||
1044 | /* | ||
1045 | * We *may* have some time to spare, but first let's see if | ||
1046 | * someone can potentially benefit from our nice mood today.. | ||
1047 | */ | ||
1048 | drive = best->next; | ||
1049 | do { | ||
1050 | if (!drive->sleeping | ||
1051 | && time_before(jiffies - best->service_time, WAKEUP(drive)) | ||
1052 | && time_before(WAKEUP(drive), jiffies + t)) | ||
1053 | { | ||
1054 | ide_stall_queue(best, min_t(long, t, 10 * WAIT_MIN_SLEEP)); | ||
1055 | goto repeat; | ||
1056 | } | ||
1057 | } while ((drive = drive->next) != best); | ||
1058 | } | ||
1059 | } | ||
1060 | return best; | ||
1061 | } | ||
1062 | |||
1063 | /* | ||
1064 | * Issue a new request to a drive from hwgroup | ||
1065 | * Caller must have already done spin_lock_irqsave(&ide_lock, ..); | ||
1066 | * | ||
1067 | * A hwgroup is a serialized group of IDE interfaces. Usually there is | ||
1068 | * exactly one hwif (interface) per hwgroup, but buggy controllers (eg. CMD640) | ||
1069 | * may have both interfaces in a single hwgroup to "serialize" access. | ||
1070 | * Or possibly multiple ISA interfaces can share a common IRQ by being grouped | ||
1071 | * together into one hwgroup for serialized access. | ||
1072 | * | ||
1073 | * Note also that several hwgroups can end up sharing a single IRQ, | ||
1074 | * possibly along with many other devices. This is especially common in | ||
1075 | * PCI-based systems with off-board IDE controller cards. | ||
1076 | * | ||
1077 | * The IDE driver uses the single global ide_lock spinlock to protect | ||
1078 | * access to the request queues, and to protect the hwgroup->busy flag. | ||
1079 | * | ||
1080 | * The first thread into the driver for a particular hwgroup sets the | ||
1081 | * hwgroup->busy flag to indicate that this hwgroup is now active, | ||
1082 | * and then initiates processing of the top request from the request queue. | ||
1083 | * | ||
1084 | * Other threads attempting entry notice the busy setting, and will simply | ||
1085 | * queue their new requests and exit immediately. Note that hwgroup->busy | ||
1086 | * remains set even when the driver is merely awaiting the next interrupt. | ||
1087 | * Thus, the meaning is "this hwgroup is busy processing a request". | ||
1088 | * | ||
1089 | * When processing of a request completes, the completing thread or IRQ-handler | ||
1090 | * will start the next request from the queue. If no more work remains, | ||
1091 | * the driver will clear the hwgroup->busy flag and exit. | ||
1092 | * | ||
1093 | * The ide_lock (spinlock) is used to protect all access to the | ||
1094 | * hwgroup->busy flag, but is otherwise not needed for most processing in | ||
1095 | * the driver. This makes the driver much more friendlier to shared IRQs | ||
1096 | * than previous designs, while remaining 100% (?) SMP safe and capable. | ||
1097 | */ | ||
1098 | static void ide_do_request (ide_hwgroup_t *hwgroup, int masked_irq) | ||
1099 | { | ||
1100 | ide_drive_t *drive; | ||
1101 | ide_hwif_t *hwif; | ||
1102 | struct request *rq; | ||
1103 | ide_startstop_t startstop; | ||
1104 | |||
1105 | /* for atari only: POSSIBLY BROKEN HERE(?) */ | ||
1106 | ide_get_lock(ide_intr, hwgroup); | ||
1107 | |||
1108 | /* caller must own ide_lock */ | ||
1109 | BUG_ON(!irqs_disabled()); | ||
1110 | |||
1111 | while (!hwgroup->busy) { | ||
1112 | hwgroup->busy = 1; | ||
1113 | drive = choose_drive(hwgroup); | ||
1114 | if (drive == NULL) { | ||
1115 | int sleeping = 0; | ||
1116 | unsigned long sleep = 0; /* shut up, gcc */ | ||
1117 | hwgroup->rq = NULL; | ||
1118 | drive = hwgroup->drive; | ||
1119 | do { | ||
1120 | if (drive->sleeping && (!sleeping || time_before(drive->sleep, sleep))) { | ||
1121 | sleeping = 1; | ||
1122 | sleep = drive->sleep; | ||
1123 | } | ||
1124 | } while ((drive = drive->next) != hwgroup->drive); | ||
1125 | if (sleeping) { | ||
1126 | /* | ||
1127 | * Take a short snooze, and then wake up this hwgroup again. | ||
1128 | * This gives other hwgroups on the same a chance to | ||
1129 | * play fairly with us, just in case there are big differences | ||
1130 | * in relative throughputs.. don't want to hog the cpu too much. | ||
1131 | */ | ||
1132 | if (time_before(sleep, jiffies + WAIT_MIN_SLEEP)) | ||
1133 | sleep = jiffies + WAIT_MIN_SLEEP; | ||
1134 | #if 1 | ||
1135 | if (timer_pending(&hwgroup->timer)) | ||
1136 | printk(KERN_CRIT "ide_set_handler: timer already active\n"); | ||
1137 | #endif | ||
1138 | /* so that ide_timer_expiry knows what to do */ | ||
1139 | hwgroup->sleeping = 1; | ||
1140 | mod_timer(&hwgroup->timer, sleep); | ||
1141 | /* we purposely leave hwgroup->busy==1 | ||
1142 | * while sleeping */ | ||
1143 | } else { | ||
1144 | /* Ugly, but how can we sleep for the lock | ||
1145 | * otherwise? perhaps from tq_disk? | ||
1146 | */ | ||
1147 | |||
1148 | /* for atari only */ | ||
1149 | ide_release_lock(); | ||
1150 | hwgroup->busy = 0; | ||
1151 | } | ||
1152 | |||
1153 | /* no more work for this hwgroup (for now) */ | ||
1154 | return; | ||
1155 | } | ||
1156 | hwif = HWIF(drive); | ||
1157 | if (hwgroup->hwif->sharing_irq && | ||
1158 | hwif != hwgroup->hwif && | ||
1159 | hwif->io_ports[IDE_CONTROL_OFFSET]) { | ||
1160 | /* set nIEN for previous hwif */ | ||
1161 | SELECT_INTERRUPT(drive); | ||
1162 | } | ||
1163 | hwgroup->hwif = hwif; | ||
1164 | hwgroup->drive = drive; | ||
1165 | drive->sleeping = 0; | ||
1166 | drive->service_start = jiffies; | ||
1167 | |||
1168 | if (blk_queue_plugged(drive->queue)) { | ||
1169 | printk(KERN_ERR "ide: huh? queue was plugged!\n"); | ||
1170 | break; | ||
1171 | } | ||
1172 | |||
1173 | /* | ||
1174 | * we know that the queue isn't empty, but this can happen | ||
1175 | * if the q->prep_rq_fn() decides to kill a request | ||
1176 | */ | ||
1177 | rq = elv_next_request(drive->queue); | ||
1178 | if (!rq) { | ||
1179 | hwgroup->busy = 0; | ||
1180 | break; | ||
1181 | } | ||
1182 | |||
1183 | /* | ||
1184 | * Sanity: don't accept a request that isn't a PM request | ||
1185 | * if we are currently power managed. This is very important as | ||
1186 | * blk_stop_queue() doesn't prevent the elv_next_request() | ||
1187 | * above to return us whatever is in the queue. Since we call | ||
1188 | * ide_do_request() ourselves, we end up taking requests while | ||
1189 | * the queue is blocked... | ||
1190 | * | ||
1191 | * We let requests forced at head of queue with ide-preempt | ||
1192 | * though. I hope that doesn't happen too much, hopefully not | ||
1193 | * unless the subdriver triggers such a thing in its own PM | ||
1194 | * state machine. | ||
1195 | */ | ||
1196 | if (drive->blocked && !blk_pm_request(rq) && !(rq->flags & REQ_PREEMPT)) { | ||
1197 | /* We clear busy, there should be no pending ATA command at this point. */ | ||
1198 | hwgroup->busy = 0; | ||
1199 | break; | ||
1200 | } | ||
1201 | |||
1202 | hwgroup->rq = rq; | ||
1203 | |||
1204 | /* | ||
1205 | * Some systems have trouble with IDE IRQs arriving while | ||
1206 | * the driver is still setting things up. So, here we disable | ||
1207 | * the IRQ used by this interface while the request is being started. | ||
1208 | * This may look bad at first, but pretty much the same thing | ||
1209 | * happens anyway when any interrupt comes in, IDE or otherwise | ||
1210 | * -- the kernel masks the IRQ while it is being handled. | ||
1211 | */ | ||
1212 | if (masked_irq != IDE_NO_IRQ && hwif->irq != masked_irq) | ||
1213 | disable_irq_nosync(hwif->irq); | ||
1214 | spin_unlock(&ide_lock); | ||
1215 | local_irq_enable(); | ||
1216 | /* allow other IRQs while we start this request */ | ||
1217 | startstop = start_request(drive, rq); | ||
1218 | spin_lock_irq(&ide_lock); | ||
1219 | if (masked_irq != IDE_NO_IRQ && hwif->irq != masked_irq) | ||
1220 | enable_irq(hwif->irq); | ||
1221 | if (startstop == ide_stopped) | ||
1222 | hwgroup->busy = 0; | ||
1223 | } | ||
1224 | } | ||
1225 | |||
1226 | /* | ||
1227 | * Passes the stuff to ide_do_request | ||
1228 | */ | ||
1229 | void do_ide_request(request_queue_t *q) | ||
1230 | { | ||
1231 | ide_drive_t *drive = q->queuedata; | ||
1232 | |||
1233 | ide_do_request(HWGROUP(drive), IDE_NO_IRQ); | ||
1234 | } | ||
1235 | |||
1236 | /* | ||
1237 | * un-busy the hwgroup etc, and clear any pending DMA status. we want to | ||
1238 | * retry the current request in pio mode instead of risking tossing it | ||
1239 | * all away | ||
1240 | */ | ||
1241 | static ide_startstop_t ide_dma_timeout_retry(ide_drive_t *drive, int error) | ||
1242 | { | ||
1243 | ide_hwif_t *hwif = HWIF(drive); | ||
1244 | struct request *rq; | ||
1245 | ide_startstop_t ret = ide_stopped; | ||
1246 | |||
1247 | /* | ||
1248 | * end current dma transaction | ||
1249 | */ | ||
1250 | |||
1251 | if (error < 0) { | ||
1252 | printk(KERN_WARNING "%s: DMA timeout error\n", drive->name); | ||
1253 | (void)HWIF(drive)->ide_dma_end(drive); | ||
1254 | ret = ide_error(drive, "dma timeout error", | ||
1255 | hwif->INB(IDE_STATUS_REG)); | ||
1256 | } else { | ||
1257 | printk(KERN_WARNING "%s: DMA timeout retry\n", drive->name); | ||
1258 | (void) hwif->ide_dma_timeout(drive); | ||
1259 | } | ||
1260 | |||
1261 | /* | ||
1262 | * disable dma for now, but remember that we did so because of | ||
1263 | * a timeout -- we'll reenable after we finish this next request | ||
1264 | * (or rather the first chunk of it) in pio. | ||
1265 | */ | ||
1266 | drive->retry_pio++; | ||
1267 | drive->state = DMA_PIO_RETRY; | ||
1268 | (void) hwif->ide_dma_off_quietly(drive); | ||
1269 | |||
1270 | /* | ||
1271 | * un-busy drive etc (hwgroup->busy is cleared on return) and | ||
1272 | * make sure request is sane | ||
1273 | */ | ||
1274 | rq = HWGROUP(drive)->rq; | ||
1275 | HWGROUP(drive)->rq = NULL; | ||
1276 | |||
1277 | rq->errors = 0; | ||
1278 | |||
1279 | if (!rq->bio) | ||
1280 | goto out; | ||
1281 | |||
1282 | rq->sector = rq->bio->bi_sector; | ||
1283 | rq->current_nr_sectors = bio_iovec(rq->bio)->bv_len >> 9; | ||
1284 | rq->hard_cur_sectors = rq->current_nr_sectors; | ||
1285 | rq->buffer = bio_data(rq->bio); | ||
1286 | out: | ||
1287 | return ret; | ||
1288 | } | ||
1289 | |||
1290 | /** | ||
1291 | * ide_timer_expiry - handle lack of an IDE interrupt | ||
1292 | * @data: timer callback magic (hwgroup) | ||
1293 | * | ||
1294 | * An IDE command has timed out before the expected drive return | ||
1295 | * occurred. At this point we attempt to clean up the current | ||
1296 | * mess. If the current handler includes an expiry handler then | ||
1297 | * we invoke the expiry handler, and providing it is happy the | ||
1298 | * work is done. If that fails we apply generic recovery rules | ||
1299 | * invoking the handler and checking the drive DMA status. We | ||
1300 | * have an excessively incestuous relationship with the DMA | ||
1301 | * logic that wants cleaning up. | ||
1302 | */ | ||
1303 | |||
1304 | void ide_timer_expiry (unsigned long data) | ||
1305 | { | ||
1306 | ide_hwgroup_t *hwgroup = (ide_hwgroup_t *) data; | ||
1307 | ide_handler_t *handler; | ||
1308 | ide_expiry_t *expiry; | ||
1309 | unsigned long flags; | ||
1310 | unsigned long wait = -1; | ||
1311 | |||
1312 | spin_lock_irqsave(&ide_lock, flags); | ||
1313 | |||
1314 | if ((handler = hwgroup->handler) == NULL) { | ||
1315 | /* | ||
1316 | * Either a marginal timeout occurred | ||
1317 | * (got the interrupt just as timer expired), | ||
1318 | * or we were "sleeping" to give other devices a chance. | ||
1319 | * Either way, we don't really want to complain about anything. | ||
1320 | */ | ||
1321 | if (hwgroup->sleeping) { | ||
1322 | hwgroup->sleeping = 0; | ||
1323 | hwgroup->busy = 0; | ||
1324 | } | ||
1325 | } else { | ||
1326 | ide_drive_t *drive = hwgroup->drive; | ||
1327 | if (!drive) { | ||
1328 | printk(KERN_ERR "ide_timer_expiry: hwgroup->drive was NULL\n"); | ||
1329 | hwgroup->handler = NULL; | ||
1330 | } else { | ||
1331 | ide_hwif_t *hwif; | ||
1332 | ide_startstop_t startstop = ide_stopped; | ||
1333 | if (!hwgroup->busy) { | ||
1334 | hwgroup->busy = 1; /* paranoia */ | ||
1335 | printk(KERN_ERR "%s: ide_timer_expiry: hwgroup->busy was 0 ??\n", drive->name); | ||
1336 | } | ||
1337 | if ((expiry = hwgroup->expiry) != NULL) { | ||
1338 | /* continue */ | ||
1339 | if ((wait = expiry(drive)) > 0) { | ||
1340 | /* reset timer */ | ||
1341 | hwgroup->timer.expires = jiffies + wait; | ||
1342 | add_timer(&hwgroup->timer); | ||
1343 | spin_unlock_irqrestore(&ide_lock, flags); | ||
1344 | return; | ||
1345 | } | ||
1346 | } | ||
1347 | hwgroup->handler = NULL; | ||
1348 | /* | ||
1349 | * We need to simulate a real interrupt when invoking | ||
1350 | * the handler() function, which means we need to | ||
1351 | * globally mask the specific IRQ: | ||
1352 | */ | ||
1353 | spin_unlock(&ide_lock); | ||
1354 | hwif = HWIF(drive); | ||
1355 | #if DISABLE_IRQ_NOSYNC | ||
1356 | disable_irq_nosync(hwif->irq); | ||
1357 | #else | ||
1358 | /* disable_irq_nosync ?? */ | ||
1359 | disable_irq(hwif->irq); | ||
1360 | #endif /* DISABLE_IRQ_NOSYNC */ | ||
1361 | /* local CPU only, | ||
1362 | * as if we were handling an interrupt */ | ||
1363 | local_irq_disable(); | ||
1364 | if (hwgroup->polling) { | ||
1365 | startstop = handler(drive); | ||
1366 | } else if (drive_is_ready(drive)) { | ||
1367 | if (drive->waiting_for_dma) | ||
1368 | (void) hwgroup->hwif->ide_dma_lostirq(drive); | ||
1369 | (void)ide_ack_intr(hwif); | ||
1370 | printk(KERN_WARNING "%s: lost interrupt\n", drive->name); | ||
1371 | startstop = handler(drive); | ||
1372 | } else { | ||
1373 | if (drive->waiting_for_dma) { | ||
1374 | startstop = ide_dma_timeout_retry(drive, wait); | ||
1375 | } else | ||
1376 | startstop = | ||
1377 | ide_error(drive, "irq timeout", hwif->INB(IDE_STATUS_REG)); | ||
1378 | } | ||
1379 | drive->service_time = jiffies - drive->service_start; | ||
1380 | spin_lock_irq(&ide_lock); | ||
1381 | enable_irq(hwif->irq); | ||
1382 | if (startstop == ide_stopped) | ||
1383 | hwgroup->busy = 0; | ||
1384 | } | ||
1385 | } | ||
1386 | ide_do_request(hwgroup, IDE_NO_IRQ); | ||
1387 | spin_unlock_irqrestore(&ide_lock, flags); | ||
1388 | } | ||
1389 | |||
1390 | /** | ||
1391 | * unexpected_intr - handle an unexpected IDE interrupt | ||
1392 | * @irq: interrupt line | ||
1393 | * @hwgroup: hwgroup being processed | ||
1394 | * | ||
1395 | * There's nothing really useful we can do with an unexpected interrupt, | ||
1396 | * other than reading the status register (to clear it), and logging it. | ||
1397 | * There should be no way that an irq can happen before we're ready for it, | ||
1398 | * so we needn't worry much about losing an "important" interrupt here. | ||
1399 | * | ||
1400 | * On laptops (and "green" PCs), an unexpected interrupt occurs whenever | ||
1401 | * the drive enters "idle", "standby", or "sleep" mode, so if the status | ||
1402 | * looks "good", we just ignore the interrupt completely. | ||
1403 | * | ||
1404 | * This routine assumes __cli() is in effect when called. | ||
1405 | * | ||
1406 | * If an unexpected interrupt happens on irq15 while we are handling irq14 | ||
1407 | * and if the two interfaces are "serialized" (CMD640), then it looks like | ||
1408 | * we could screw up by interfering with a new request being set up for | ||
1409 | * irq15. | ||
1410 | * | ||
1411 | * In reality, this is a non-issue. The new command is not sent unless | ||
1412 | * the drive is ready to accept one, in which case we know the drive is | ||
1413 | * not trying to interrupt us. And ide_set_handler() is always invoked | ||
1414 | * before completing the issuance of any new drive command, so we will not | ||
1415 | * be accidentally invoked as a result of any valid command completion | ||
1416 | * interrupt. | ||
1417 | * | ||
1418 | * Note that we must walk the entire hwgroup here. We know which hwif | ||
1419 | * is doing the current command, but we don't know which hwif burped | ||
1420 | * mysteriously. | ||
1421 | */ | ||
1422 | |||
1423 | static void unexpected_intr (int irq, ide_hwgroup_t *hwgroup) | ||
1424 | { | ||
1425 | u8 stat; | ||
1426 | ide_hwif_t *hwif = hwgroup->hwif; | ||
1427 | |||
1428 | /* | ||
1429 | * handle the unexpected interrupt | ||
1430 | */ | ||
1431 | do { | ||
1432 | if (hwif->irq == irq) { | ||
1433 | stat = hwif->INB(hwif->io_ports[IDE_STATUS_OFFSET]); | ||
1434 | if (!OK_STAT(stat, READY_STAT, BAD_STAT)) { | ||
1435 | /* Try to not flood the console with msgs */ | ||
1436 | static unsigned long last_msgtime, count; | ||
1437 | ++count; | ||
1438 | if (time_after(jiffies, last_msgtime + HZ)) { | ||
1439 | last_msgtime = jiffies; | ||
1440 | printk(KERN_ERR "%s%s: unexpected interrupt, " | ||
1441 | "status=0x%02x, count=%ld\n", | ||
1442 | hwif->name, | ||
1443 | (hwif->next==hwgroup->hwif) ? "" : "(?)", stat, count); | ||
1444 | } | ||
1445 | } | ||
1446 | } | ||
1447 | } while ((hwif = hwif->next) != hwgroup->hwif); | ||
1448 | } | ||
1449 | |||
1450 | /** | ||
1451 | * ide_intr - default IDE interrupt handler | ||
1452 | * @irq: interrupt number | ||
1453 | * @dev_id: hwif group | ||
1454 | * @regs: unused weirdness from the kernel irq layer | ||
1455 | * | ||
1456 | * This is the default IRQ handler for the IDE layer. You should | ||
1457 | * not need to override it. If you do be aware it is subtle in | ||
1458 | * places | ||
1459 | * | ||
1460 | * hwgroup->hwif is the interface in the group currently performing | ||
1461 | * a command. hwgroup->drive is the drive and hwgroup->handler is | ||
1462 | * the IRQ handler to call. As we issue a command the handlers | ||
1463 | * step through multiple states, reassigning the handler to the | ||
1464 | * next step in the process. Unlike a smart SCSI controller IDE | ||
1465 | * expects the main processor to sequence the various transfer | ||
1466 | * stages. We also manage a poll timer to catch up with most | ||
1467 | * timeout situations. There are still a few where the handlers | ||
1468 | * don't ever decide to give up. | ||
1469 | * | ||
1470 | * The handler eventually returns ide_stopped to indicate the | ||
1471 | * request completed. At this point we issue the next request | ||
1472 | * on the hwgroup and the process begins again. | ||
1473 | */ | ||
1474 | |||
1475 | irqreturn_t ide_intr (int irq, void *dev_id, struct pt_regs *regs) | ||
1476 | { | ||
1477 | unsigned long flags; | ||
1478 | ide_hwgroup_t *hwgroup = (ide_hwgroup_t *)dev_id; | ||
1479 | ide_hwif_t *hwif; | ||
1480 | ide_drive_t *drive; | ||
1481 | ide_handler_t *handler; | ||
1482 | ide_startstop_t startstop; | ||
1483 | |||
1484 | spin_lock_irqsave(&ide_lock, flags); | ||
1485 | hwif = hwgroup->hwif; | ||
1486 | |||
1487 | if (!ide_ack_intr(hwif)) { | ||
1488 | spin_unlock_irqrestore(&ide_lock, flags); | ||
1489 | return IRQ_NONE; | ||
1490 | } | ||
1491 | |||
1492 | if ((handler = hwgroup->handler) == NULL || hwgroup->polling) { | ||
1493 | /* | ||
1494 | * Not expecting an interrupt from this drive. | ||
1495 | * That means this could be: | ||
1496 | * (1) an interrupt from another PCI device | ||
1497 | * sharing the same PCI INT# as us. | ||
1498 | * or (2) a drive just entered sleep or standby mode, | ||
1499 | * and is interrupting to let us know. | ||
1500 | * or (3) a spurious interrupt of unknown origin. | ||
1501 | * | ||
1502 | * For PCI, we cannot tell the difference, | ||
1503 | * so in that case we just ignore it and hope it goes away. | ||
1504 | * | ||
1505 | * FIXME: unexpected_intr should be hwif-> then we can | ||
1506 | * remove all the ifdef PCI crap | ||
1507 | */ | ||
1508 | #ifdef CONFIG_BLK_DEV_IDEPCI | ||
1509 | if (hwif->pci_dev && !hwif->pci_dev->vendor) | ||
1510 | #endif /* CONFIG_BLK_DEV_IDEPCI */ | ||
1511 | { | ||
1512 | /* | ||
1513 | * Probably not a shared PCI interrupt, | ||
1514 | * so we can safely try to do something about it: | ||
1515 | */ | ||
1516 | unexpected_intr(irq, hwgroup); | ||
1517 | #ifdef CONFIG_BLK_DEV_IDEPCI | ||
1518 | } else { | ||
1519 | /* | ||
1520 | * Whack the status register, just in case | ||
1521 | * we have a leftover pending IRQ. | ||
1522 | */ | ||
1523 | (void) hwif->INB(hwif->io_ports[IDE_STATUS_OFFSET]); | ||
1524 | #endif /* CONFIG_BLK_DEV_IDEPCI */ | ||
1525 | } | ||
1526 | spin_unlock_irqrestore(&ide_lock, flags); | ||
1527 | return IRQ_NONE; | ||
1528 | } | ||
1529 | drive = hwgroup->drive; | ||
1530 | if (!drive) { | ||
1531 | /* | ||
1532 | * This should NEVER happen, and there isn't much | ||
1533 | * we could do about it here. | ||
1534 | * | ||
1535 | * [Note - this can occur if the drive is hot unplugged] | ||
1536 | */ | ||
1537 | spin_unlock_irqrestore(&ide_lock, flags); | ||
1538 | return IRQ_HANDLED; | ||
1539 | } | ||
1540 | if (!drive_is_ready(drive)) { | ||
1541 | /* | ||
1542 | * This happens regularly when we share a PCI IRQ with | ||
1543 | * another device. Unfortunately, it can also happen | ||
1544 | * with some buggy drives that trigger the IRQ before | ||
1545 | * their status register is up to date. Hopefully we have | ||
1546 | * enough advance overhead that the latter isn't a problem. | ||
1547 | */ | ||
1548 | spin_unlock_irqrestore(&ide_lock, flags); | ||
1549 | return IRQ_NONE; | ||
1550 | } | ||
1551 | if (!hwgroup->busy) { | ||
1552 | hwgroup->busy = 1; /* paranoia */ | ||
1553 | printk(KERN_ERR "%s: ide_intr: hwgroup->busy was 0 ??\n", drive->name); | ||
1554 | } | ||
1555 | hwgroup->handler = NULL; | ||
1556 | del_timer(&hwgroup->timer); | ||
1557 | spin_unlock(&ide_lock); | ||
1558 | |||
1559 | if (drive->unmask) | ||
1560 | local_irq_enable(); | ||
1561 | /* service this interrupt, may set handler for next interrupt */ | ||
1562 | startstop = handler(drive); | ||
1563 | spin_lock_irq(&ide_lock); | ||
1564 | |||
1565 | /* | ||
1566 | * Note that handler() may have set things up for another | ||
1567 | * interrupt to occur soon, but it cannot happen until | ||
1568 | * we exit from this routine, because it will be the | ||
1569 | * same irq as is currently being serviced here, and Linux | ||
1570 | * won't allow another of the same (on any CPU) until we return. | ||
1571 | */ | ||
1572 | drive->service_time = jiffies - drive->service_start; | ||
1573 | if (startstop == ide_stopped) { | ||
1574 | if (hwgroup->handler == NULL) { /* paranoia */ | ||
1575 | hwgroup->busy = 0; | ||
1576 | ide_do_request(hwgroup, hwif->irq); | ||
1577 | } else { | ||
1578 | printk(KERN_ERR "%s: ide_intr: huh? expected NULL handler " | ||
1579 | "on exit\n", drive->name); | ||
1580 | } | ||
1581 | } | ||
1582 | spin_unlock_irqrestore(&ide_lock, flags); | ||
1583 | return IRQ_HANDLED; | ||
1584 | } | ||
1585 | |||
1586 | /** | ||
1587 | * ide_init_drive_cmd - initialize a drive command request | ||
1588 | * @rq: request object | ||
1589 | * | ||
1590 | * Initialize a request before we fill it in and send it down to | ||
1591 | * ide_do_drive_cmd. Commands must be set up by this function. Right | ||
1592 | * now it doesn't do a lot, but if that changes abusers will have a | ||
1593 | * nasty suprise. | ||
1594 | */ | ||
1595 | |||
1596 | void ide_init_drive_cmd (struct request *rq) | ||
1597 | { | ||
1598 | memset(rq, 0, sizeof(*rq)); | ||
1599 | rq->flags = REQ_DRIVE_CMD; | ||
1600 | rq->ref_count = 1; | ||
1601 | } | ||
1602 | |||
1603 | EXPORT_SYMBOL(ide_init_drive_cmd); | ||
1604 | |||
1605 | /** | ||
1606 | * ide_do_drive_cmd - issue IDE special command | ||
1607 | * @drive: device to issue command | ||
1608 | * @rq: request to issue | ||
1609 | * @action: action for processing | ||
1610 | * | ||
1611 | * This function issues a special IDE device request | ||
1612 | * onto the request queue. | ||
1613 | * | ||
1614 | * If action is ide_wait, then the rq is queued at the end of the | ||
1615 | * request queue, and the function sleeps until it has been processed. | ||
1616 | * This is for use when invoked from an ioctl handler. | ||
1617 | * | ||
1618 | * If action is ide_preempt, then the rq is queued at the head of | ||
1619 | * the request queue, displacing the currently-being-processed | ||
1620 | * request and this function returns immediately without waiting | ||
1621 | * for the new rq to be completed. This is VERY DANGEROUS, and is | ||
1622 | * intended for careful use by the ATAPI tape/cdrom driver code. | ||
1623 | * | ||
1624 | * If action is ide_next, then the rq is queued immediately after | ||
1625 | * the currently-being-processed-request (if any), and the function | ||
1626 | * returns without waiting for the new rq to be completed. As above, | ||
1627 | * This is VERY DANGEROUS, and is intended for careful use by the | ||
1628 | * ATAPI tape/cdrom driver code. | ||
1629 | * | ||
1630 | * If action is ide_end, then the rq is queued at the end of the | ||
1631 | * request queue, and the function returns immediately without waiting | ||
1632 | * for the new rq to be completed. This is again intended for careful | ||
1633 | * use by the ATAPI tape/cdrom driver code. | ||
1634 | */ | ||
1635 | |||
1636 | int ide_do_drive_cmd (ide_drive_t *drive, struct request *rq, ide_action_t action) | ||
1637 | { | ||
1638 | unsigned long flags; | ||
1639 | ide_hwgroup_t *hwgroup = HWGROUP(drive); | ||
1640 | DECLARE_COMPLETION(wait); | ||
1641 | int where = ELEVATOR_INSERT_BACK, err; | ||
1642 | int must_wait = (action == ide_wait || action == ide_head_wait); | ||
1643 | |||
1644 | rq->errors = 0; | ||
1645 | rq->rq_status = RQ_ACTIVE; | ||
1646 | |||
1647 | /* | ||
1648 | * we need to hold an extra reference to request for safe inspection | ||
1649 | * after completion | ||
1650 | */ | ||
1651 | if (must_wait) { | ||
1652 | rq->ref_count++; | ||
1653 | rq->waiting = &wait; | ||
1654 | rq->end_io = blk_end_sync_rq; | ||
1655 | } | ||
1656 | |||
1657 | spin_lock_irqsave(&ide_lock, flags); | ||
1658 | if (action == ide_preempt) | ||
1659 | hwgroup->rq = NULL; | ||
1660 | if (action == ide_preempt || action == ide_head_wait) { | ||
1661 | where = ELEVATOR_INSERT_FRONT; | ||
1662 | rq->flags |= REQ_PREEMPT; | ||
1663 | } | ||
1664 | __elv_add_request(drive->queue, rq, where, 0); | ||
1665 | ide_do_request(hwgroup, IDE_NO_IRQ); | ||
1666 | spin_unlock_irqrestore(&ide_lock, flags); | ||
1667 | |||
1668 | err = 0; | ||
1669 | if (must_wait) { | ||
1670 | wait_for_completion(&wait); | ||
1671 | rq->waiting = NULL; | ||
1672 | if (rq->errors) | ||
1673 | err = -EIO; | ||
1674 | |||
1675 | blk_put_request(rq); | ||
1676 | } | ||
1677 | |||
1678 | return err; | ||
1679 | } | ||
1680 | |||
1681 | EXPORT_SYMBOL(ide_do_drive_cmd); | ||
diff --git a/drivers/ide/ide-iops.c b/drivers/ide/ide-iops.c new file mode 100644 index 000000000000..53024942a7eb --- /dev/null +++ b/drivers/ide/ide-iops.c | |||
@@ -0,0 +1,1285 @@ | |||
1 | /* | ||
2 | * linux/drivers/ide/ide-iops.c Version 0.37 Mar 05, 2003 | ||
3 | * | ||
4 | * Copyright (C) 2000-2002 Andre Hedrick <andre@linux-ide.org> | ||
5 | * Copyright (C) 2003 Red Hat <alan@redhat.com> | ||
6 | * | ||
7 | */ | ||
8 | |||
9 | #include <linux/config.h> | ||
10 | #include <linux/module.h> | ||
11 | #include <linux/types.h> | ||
12 | #include <linux/string.h> | ||
13 | #include <linux/kernel.h> | ||
14 | #include <linux/timer.h> | ||
15 | #include <linux/mm.h> | ||
16 | #include <linux/interrupt.h> | ||
17 | #include <linux/major.h> | ||
18 | #include <linux/errno.h> | ||
19 | #include <linux/genhd.h> | ||
20 | #include <linux/blkpg.h> | ||
21 | #include <linux/slab.h> | ||
22 | #include <linux/pci.h> | ||
23 | #include <linux/delay.h> | ||
24 | #include <linux/hdreg.h> | ||
25 | #include <linux/ide.h> | ||
26 | #include <linux/bitops.h> | ||
27 | |||
28 | #include <asm/byteorder.h> | ||
29 | #include <asm/irq.h> | ||
30 | #include <asm/uaccess.h> | ||
31 | #include <asm/io.h> | ||
32 | |||
33 | /* | ||
34 | * Conventional PIO operations for ATA devices | ||
35 | */ | ||
36 | |||
37 | static u8 ide_inb (unsigned long port) | ||
38 | { | ||
39 | return (u8) inb(port); | ||
40 | } | ||
41 | |||
42 | static u16 ide_inw (unsigned long port) | ||
43 | { | ||
44 | return (u16) inw(port); | ||
45 | } | ||
46 | |||
47 | static void ide_insw (unsigned long port, void *addr, u32 count) | ||
48 | { | ||
49 | insw(port, addr, count); | ||
50 | } | ||
51 | |||
52 | static u32 ide_inl (unsigned long port) | ||
53 | { | ||
54 | return (u32) inl(port); | ||
55 | } | ||
56 | |||
57 | static void ide_insl (unsigned long port, void *addr, u32 count) | ||
58 | { | ||
59 | insl(port, addr, count); | ||
60 | } | ||
61 | |||
62 | static void ide_outb (u8 val, unsigned long port) | ||
63 | { | ||
64 | outb(val, port); | ||
65 | } | ||
66 | |||
67 | static void ide_outbsync (ide_drive_t *drive, u8 addr, unsigned long port) | ||
68 | { | ||
69 | outb(addr, port); | ||
70 | } | ||
71 | |||
72 | static void ide_outw (u16 val, unsigned long port) | ||
73 | { | ||
74 | outw(val, port); | ||
75 | } | ||
76 | |||
77 | static void ide_outsw (unsigned long port, void *addr, u32 count) | ||
78 | { | ||
79 | outsw(port, addr, count); | ||
80 | } | ||
81 | |||
82 | static void ide_outl (u32 val, unsigned long port) | ||
83 | { | ||
84 | outl(val, port); | ||
85 | } | ||
86 | |||
87 | static void ide_outsl (unsigned long port, void *addr, u32 count) | ||
88 | { | ||
89 | outsl(port, addr, count); | ||
90 | } | ||
91 | |||
92 | void default_hwif_iops (ide_hwif_t *hwif) | ||
93 | { | ||
94 | hwif->OUTB = ide_outb; | ||
95 | hwif->OUTBSYNC = ide_outbsync; | ||
96 | hwif->OUTW = ide_outw; | ||
97 | hwif->OUTL = ide_outl; | ||
98 | hwif->OUTSW = ide_outsw; | ||
99 | hwif->OUTSL = ide_outsl; | ||
100 | hwif->INB = ide_inb; | ||
101 | hwif->INW = ide_inw; | ||
102 | hwif->INL = ide_inl; | ||
103 | hwif->INSW = ide_insw; | ||
104 | hwif->INSL = ide_insl; | ||
105 | } | ||
106 | |||
107 | EXPORT_SYMBOL(default_hwif_iops); | ||
108 | |||
109 | /* | ||
110 | * MMIO operations, typically used for SATA controllers | ||
111 | */ | ||
112 | |||
113 | static u8 ide_mm_inb (unsigned long port) | ||
114 | { | ||
115 | return (u8) readb((void __iomem *) port); | ||
116 | } | ||
117 | |||
118 | static u16 ide_mm_inw (unsigned long port) | ||
119 | { | ||
120 | return (u16) readw((void __iomem *) port); | ||
121 | } | ||
122 | |||
123 | static void ide_mm_insw (unsigned long port, void *addr, u32 count) | ||
124 | { | ||
125 | __ide_mm_insw((void __iomem *) port, addr, count); | ||
126 | } | ||
127 | |||
128 | static u32 ide_mm_inl (unsigned long port) | ||
129 | { | ||
130 | return (u32) readl((void __iomem *) port); | ||
131 | } | ||
132 | |||
133 | static void ide_mm_insl (unsigned long port, void *addr, u32 count) | ||
134 | { | ||
135 | __ide_mm_insl((void __iomem *) port, addr, count); | ||
136 | } | ||
137 | |||
138 | static void ide_mm_outb (u8 value, unsigned long port) | ||
139 | { | ||
140 | writeb(value, (void __iomem *) port); | ||
141 | } | ||
142 | |||
143 | static void ide_mm_outbsync (ide_drive_t *drive, u8 value, unsigned long port) | ||
144 | { | ||
145 | writeb(value, (void __iomem *) port); | ||
146 | } | ||
147 | |||
148 | static void ide_mm_outw (u16 value, unsigned long port) | ||
149 | { | ||
150 | writew(value, (void __iomem *) port); | ||
151 | } | ||
152 | |||
153 | static void ide_mm_outsw (unsigned long port, void *addr, u32 count) | ||
154 | { | ||
155 | __ide_mm_outsw((void __iomem *) port, addr, count); | ||
156 | } | ||
157 | |||
158 | static void ide_mm_outl (u32 value, unsigned long port) | ||
159 | { | ||
160 | writel(value, (void __iomem *) port); | ||
161 | } | ||
162 | |||
163 | static void ide_mm_outsl (unsigned long port, void *addr, u32 count) | ||
164 | { | ||
165 | __ide_mm_outsl((void __iomem *) port, addr, count); | ||
166 | } | ||
167 | |||
168 | void default_hwif_mmiops (ide_hwif_t *hwif) | ||
169 | { | ||
170 | hwif->OUTB = ide_mm_outb; | ||
171 | /* Most systems will need to override OUTBSYNC, alas however | ||
172 | this one is controller specific! */ | ||
173 | hwif->OUTBSYNC = ide_mm_outbsync; | ||
174 | hwif->OUTW = ide_mm_outw; | ||
175 | hwif->OUTL = ide_mm_outl; | ||
176 | hwif->OUTSW = ide_mm_outsw; | ||
177 | hwif->OUTSL = ide_mm_outsl; | ||
178 | hwif->INB = ide_mm_inb; | ||
179 | hwif->INW = ide_mm_inw; | ||
180 | hwif->INL = ide_mm_inl; | ||
181 | hwif->INSW = ide_mm_insw; | ||
182 | hwif->INSL = ide_mm_insl; | ||
183 | } | ||
184 | |||
185 | EXPORT_SYMBOL(default_hwif_mmiops); | ||
186 | |||
187 | u32 ide_read_24 (ide_drive_t *drive) | ||
188 | { | ||
189 | u8 hcyl = HWIF(drive)->INB(IDE_HCYL_REG); | ||
190 | u8 lcyl = HWIF(drive)->INB(IDE_LCYL_REG); | ||
191 | u8 sect = HWIF(drive)->INB(IDE_SECTOR_REG); | ||
192 | return (hcyl<<16)|(lcyl<<8)|sect; | ||
193 | } | ||
194 | |||
195 | void SELECT_DRIVE (ide_drive_t *drive) | ||
196 | { | ||
197 | if (HWIF(drive)->selectproc) | ||
198 | HWIF(drive)->selectproc(drive); | ||
199 | HWIF(drive)->OUTB(drive->select.all, IDE_SELECT_REG); | ||
200 | } | ||
201 | |||
202 | EXPORT_SYMBOL(SELECT_DRIVE); | ||
203 | |||
204 | void SELECT_INTERRUPT (ide_drive_t *drive) | ||
205 | { | ||
206 | if (HWIF(drive)->intrproc) | ||
207 | HWIF(drive)->intrproc(drive); | ||
208 | else | ||
209 | HWIF(drive)->OUTB(drive->ctl|2, IDE_CONTROL_REG); | ||
210 | } | ||
211 | |||
212 | void SELECT_MASK (ide_drive_t *drive, int mask) | ||
213 | { | ||
214 | if (HWIF(drive)->maskproc) | ||
215 | HWIF(drive)->maskproc(drive, mask); | ||
216 | } | ||
217 | |||
218 | void QUIRK_LIST (ide_drive_t *drive) | ||
219 | { | ||
220 | if (HWIF(drive)->quirkproc) | ||
221 | drive->quirk_list = HWIF(drive)->quirkproc(drive); | ||
222 | } | ||
223 | |||
224 | /* | ||
225 | * Some localbus EIDE interfaces require a special access sequence | ||
226 | * when using 32-bit I/O instructions to transfer data. We call this | ||
227 | * the "vlb_sync" sequence, which consists of three successive reads | ||
228 | * of the sector count register location, with interrupts disabled | ||
229 | * to ensure that the reads all happen together. | ||
230 | */ | ||
231 | static void ata_vlb_sync(ide_drive_t *drive, unsigned long port) | ||
232 | { | ||
233 | (void) HWIF(drive)->INB(port); | ||
234 | (void) HWIF(drive)->INB(port); | ||
235 | (void) HWIF(drive)->INB(port); | ||
236 | } | ||
237 | |||
238 | /* | ||
239 | * This is used for most PIO data transfers *from* the IDE interface | ||
240 | */ | ||
241 | static void ata_input_data(ide_drive_t *drive, void *buffer, u32 wcount) | ||
242 | { | ||
243 | ide_hwif_t *hwif = HWIF(drive); | ||
244 | u8 io_32bit = drive->io_32bit; | ||
245 | |||
246 | if (io_32bit) { | ||
247 | if (io_32bit & 2) { | ||
248 | unsigned long flags; | ||
249 | local_irq_save(flags); | ||
250 | ata_vlb_sync(drive, IDE_NSECTOR_REG); | ||
251 | hwif->INSL(IDE_DATA_REG, buffer, wcount); | ||
252 | local_irq_restore(flags); | ||
253 | } else | ||
254 | hwif->INSL(IDE_DATA_REG, buffer, wcount); | ||
255 | } else { | ||
256 | hwif->INSW(IDE_DATA_REG, buffer, wcount<<1); | ||
257 | } | ||
258 | } | ||
259 | |||
260 | /* | ||
261 | * This is used for most PIO data transfers *to* the IDE interface | ||
262 | */ | ||
263 | static void ata_output_data(ide_drive_t *drive, void *buffer, u32 wcount) | ||
264 | { | ||
265 | ide_hwif_t *hwif = HWIF(drive); | ||
266 | u8 io_32bit = drive->io_32bit; | ||
267 | |||
268 | if (io_32bit) { | ||
269 | if (io_32bit & 2) { | ||
270 | unsigned long flags; | ||
271 | local_irq_save(flags); | ||
272 | ata_vlb_sync(drive, IDE_NSECTOR_REG); | ||
273 | hwif->OUTSL(IDE_DATA_REG, buffer, wcount); | ||
274 | local_irq_restore(flags); | ||
275 | } else | ||
276 | hwif->OUTSL(IDE_DATA_REG, buffer, wcount); | ||
277 | } else { | ||
278 | hwif->OUTSW(IDE_DATA_REG, buffer, wcount<<1); | ||
279 | } | ||
280 | } | ||
281 | |||
282 | /* | ||
283 | * The following routines are mainly used by the ATAPI drivers. | ||
284 | * | ||
285 | * These routines will round up any request for an odd number of bytes, | ||
286 | * so if an odd bytecount is specified, be sure that there's at least one | ||
287 | * extra byte allocated for the buffer. | ||
288 | */ | ||
289 | |||
290 | static void atapi_input_bytes(ide_drive_t *drive, void *buffer, u32 bytecount) | ||
291 | { | ||
292 | ide_hwif_t *hwif = HWIF(drive); | ||
293 | |||
294 | ++bytecount; | ||
295 | #if defined(CONFIG_ATARI) || defined(CONFIG_Q40) | ||
296 | if (MACH_IS_ATARI || MACH_IS_Q40) { | ||
297 | /* Atari has a byte-swapped IDE interface */ | ||
298 | insw_swapw(IDE_DATA_REG, buffer, bytecount / 2); | ||
299 | return; | ||
300 | } | ||
301 | #endif /* CONFIG_ATARI || CONFIG_Q40 */ | ||
302 | hwif->ata_input_data(drive, buffer, bytecount / 4); | ||
303 | if ((bytecount & 0x03) >= 2) | ||
304 | hwif->INSW(IDE_DATA_REG, ((u8 *)buffer)+(bytecount & ~0x03), 1); | ||
305 | } | ||
306 | |||
307 | static void atapi_output_bytes(ide_drive_t *drive, void *buffer, u32 bytecount) | ||
308 | { | ||
309 | ide_hwif_t *hwif = HWIF(drive); | ||
310 | |||
311 | ++bytecount; | ||
312 | #if defined(CONFIG_ATARI) || defined(CONFIG_Q40) | ||
313 | if (MACH_IS_ATARI || MACH_IS_Q40) { | ||
314 | /* Atari has a byte-swapped IDE interface */ | ||
315 | outsw_swapw(IDE_DATA_REG, buffer, bytecount / 2); | ||
316 | return; | ||
317 | } | ||
318 | #endif /* CONFIG_ATARI || CONFIG_Q40 */ | ||
319 | hwif->ata_output_data(drive, buffer, bytecount / 4); | ||
320 | if ((bytecount & 0x03) >= 2) | ||
321 | hwif->OUTSW(IDE_DATA_REG, ((u8*)buffer)+(bytecount & ~0x03), 1); | ||
322 | } | ||
323 | |||
324 | void default_hwif_transport(ide_hwif_t *hwif) | ||
325 | { | ||
326 | hwif->ata_input_data = ata_input_data; | ||
327 | hwif->ata_output_data = ata_output_data; | ||
328 | hwif->atapi_input_bytes = atapi_input_bytes; | ||
329 | hwif->atapi_output_bytes = atapi_output_bytes; | ||
330 | } | ||
331 | |||
332 | EXPORT_SYMBOL(default_hwif_transport); | ||
333 | |||
334 | /* | ||
335 | * Beginning of Taskfile OPCODE Library and feature sets. | ||
336 | */ | ||
337 | void ide_fix_driveid (struct hd_driveid *id) | ||
338 | { | ||
339 | #ifndef __LITTLE_ENDIAN | ||
340 | # ifdef __BIG_ENDIAN | ||
341 | int i; | ||
342 | u16 *stringcast; | ||
343 | |||
344 | id->config = __le16_to_cpu(id->config); | ||
345 | id->cyls = __le16_to_cpu(id->cyls); | ||
346 | id->reserved2 = __le16_to_cpu(id->reserved2); | ||
347 | id->heads = __le16_to_cpu(id->heads); | ||
348 | id->track_bytes = __le16_to_cpu(id->track_bytes); | ||
349 | id->sector_bytes = __le16_to_cpu(id->sector_bytes); | ||
350 | id->sectors = __le16_to_cpu(id->sectors); | ||
351 | id->vendor0 = __le16_to_cpu(id->vendor0); | ||
352 | id->vendor1 = __le16_to_cpu(id->vendor1); | ||
353 | id->vendor2 = __le16_to_cpu(id->vendor2); | ||
354 | stringcast = (u16 *)&id->serial_no[0]; | ||
355 | for (i = 0; i < (20/2); i++) | ||
356 | stringcast[i] = __le16_to_cpu(stringcast[i]); | ||
357 | id->buf_type = __le16_to_cpu(id->buf_type); | ||
358 | id->buf_size = __le16_to_cpu(id->buf_size); | ||
359 | id->ecc_bytes = __le16_to_cpu(id->ecc_bytes); | ||
360 | stringcast = (u16 *)&id->fw_rev[0]; | ||
361 | for (i = 0; i < (8/2); i++) | ||
362 | stringcast[i] = __le16_to_cpu(stringcast[i]); | ||
363 | stringcast = (u16 *)&id->model[0]; | ||
364 | for (i = 0; i < (40/2); i++) | ||
365 | stringcast[i] = __le16_to_cpu(stringcast[i]); | ||
366 | id->dword_io = __le16_to_cpu(id->dword_io); | ||
367 | id->reserved50 = __le16_to_cpu(id->reserved50); | ||
368 | id->field_valid = __le16_to_cpu(id->field_valid); | ||
369 | id->cur_cyls = __le16_to_cpu(id->cur_cyls); | ||
370 | id->cur_heads = __le16_to_cpu(id->cur_heads); | ||
371 | id->cur_sectors = __le16_to_cpu(id->cur_sectors); | ||
372 | id->cur_capacity0 = __le16_to_cpu(id->cur_capacity0); | ||
373 | id->cur_capacity1 = __le16_to_cpu(id->cur_capacity1); | ||
374 | id->lba_capacity = __le32_to_cpu(id->lba_capacity); | ||
375 | id->dma_1word = __le16_to_cpu(id->dma_1word); | ||
376 | id->dma_mword = __le16_to_cpu(id->dma_mword); | ||
377 | id->eide_pio_modes = __le16_to_cpu(id->eide_pio_modes); | ||
378 | id->eide_dma_min = __le16_to_cpu(id->eide_dma_min); | ||
379 | id->eide_dma_time = __le16_to_cpu(id->eide_dma_time); | ||
380 | id->eide_pio = __le16_to_cpu(id->eide_pio); | ||
381 | id->eide_pio_iordy = __le16_to_cpu(id->eide_pio_iordy); | ||
382 | for (i = 0; i < 2; ++i) | ||
383 | id->words69_70[i] = __le16_to_cpu(id->words69_70[i]); | ||
384 | for (i = 0; i < 4; ++i) | ||
385 | id->words71_74[i] = __le16_to_cpu(id->words71_74[i]); | ||
386 | id->queue_depth = __le16_to_cpu(id->queue_depth); | ||
387 | for (i = 0; i < 4; ++i) | ||
388 | id->words76_79[i] = __le16_to_cpu(id->words76_79[i]); | ||
389 | id->major_rev_num = __le16_to_cpu(id->major_rev_num); | ||
390 | id->minor_rev_num = __le16_to_cpu(id->minor_rev_num); | ||
391 | id->command_set_1 = __le16_to_cpu(id->command_set_1); | ||
392 | id->command_set_2 = __le16_to_cpu(id->command_set_2); | ||
393 | id->cfsse = __le16_to_cpu(id->cfsse); | ||
394 | id->cfs_enable_1 = __le16_to_cpu(id->cfs_enable_1); | ||
395 | id->cfs_enable_2 = __le16_to_cpu(id->cfs_enable_2); | ||
396 | id->csf_default = __le16_to_cpu(id->csf_default); | ||
397 | id->dma_ultra = __le16_to_cpu(id->dma_ultra); | ||
398 | id->trseuc = __le16_to_cpu(id->trseuc); | ||
399 | id->trsEuc = __le16_to_cpu(id->trsEuc); | ||
400 | id->CurAPMvalues = __le16_to_cpu(id->CurAPMvalues); | ||
401 | id->mprc = __le16_to_cpu(id->mprc); | ||
402 | id->hw_config = __le16_to_cpu(id->hw_config); | ||
403 | id->acoustic = __le16_to_cpu(id->acoustic); | ||
404 | id->msrqs = __le16_to_cpu(id->msrqs); | ||
405 | id->sxfert = __le16_to_cpu(id->sxfert); | ||
406 | id->sal = __le16_to_cpu(id->sal); | ||
407 | id->spg = __le32_to_cpu(id->spg); | ||
408 | id->lba_capacity_2 = __le64_to_cpu(id->lba_capacity_2); | ||
409 | for (i = 0; i < 22; i++) | ||
410 | id->words104_125[i] = __le16_to_cpu(id->words104_125[i]); | ||
411 | id->last_lun = __le16_to_cpu(id->last_lun); | ||
412 | id->word127 = __le16_to_cpu(id->word127); | ||
413 | id->dlf = __le16_to_cpu(id->dlf); | ||
414 | id->csfo = __le16_to_cpu(id->csfo); | ||
415 | for (i = 0; i < 26; i++) | ||
416 | id->words130_155[i] = __le16_to_cpu(id->words130_155[i]); | ||
417 | id->word156 = __le16_to_cpu(id->word156); | ||
418 | for (i = 0; i < 3; i++) | ||
419 | id->words157_159[i] = __le16_to_cpu(id->words157_159[i]); | ||
420 | id->cfa_power = __le16_to_cpu(id->cfa_power); | ||
421 | for (i = 0; i < 14; i++) | ||
422 | id->words161_175[i] = __le16_to_cpu(id->words161_175[i]); | ||
423 | for (i = 0; i < 31; i++) | ||
424 | id->words176_205[i] = __le16_to_cpu(id->words176_205[i]); | ||
425 | for (i = 0; i < 48; i++) | ||
426 | id->words206_254[i] = __le16_to_cpu(id->words206_254[i]); | ||
427 | id->integrity_word = __le16_to_cpu(id->integrity_word); | ||
428 | # else | ||
429 | # error "Please fix <asm/byteorder.h>" | ||
430 | # endif | ||
431 | #endif | ||
432 | } | ||
433 | |||
434 | /* FIXME: exported for use by the USB storage (isd200.c) code only */ | ||
435 | EXPORT_SYMBOL(ide_fix_driveid); | ||
436 | |||
437 | void ide_fixstring (u8 *s, const int bytecount, const int byteswap) | ||
438 | { | ||
439 | u8 *p = s, *end = &s[bytecount & ~1]; /* bytecount must be even */ | ||
440 | |||
441 | if (byteswap) { | ||
442 | /* convert from big-endian to host byte order */ | ||
443 | for (p = end ; p != s;) { | ||
444 | unsigned short *pp = (unsigned short *) (p -= 2); | ||
445 | *pp = ntohs(*pp); | ||
446 | } | ||
447 | } | ||
448 | /* strip leading blanks */ | ||
449 | while (s != end && *s == ' ') | ||
450 | ++s; | ||
451 | /* compress internal blanks and strip trailing blanks */ | ||
452 | while (s != end && *s) { | ||
453 | if (*s++ != ' ' || (s != end && *s && *s != ' ')) | ||
454 | *p++ = *(s-1); | ||
455 | } | ||
456 | /* wipe out trailing garbage */ | ||
457 | while (p != end) | ||
458 | *p++ = '\0'; | ||
459 | } | ||
460 | |||
461 | EXPORT_SYMBOL(ide_fixstring); | ||
462 | |||
463 | /* | ||
464 | * Needed for PCI irq sharing | ||
465 | */ | ||
466 | int drive_is_ready (ide_drive_t *drive) | ||
467 | { | ||
468 | ide_hwif_t *hwif = HWIF(drive); | ||
469 | u8 stat = 0; | ||
470 | |||
471 | if (drive->waiting_for_dma) | ||
472 | return hwif->ide_dma_test_irq(drive); | ||
473 | |||
474 | #if 0 | ||
475 | /* need to guarantee 400ns since last command was issued */ | ||
476 | udelay(1); | ||
477 | #endif | ||
478 | |||
479 | #ifdef CONFIG_IDEPCI_SHARE_IRQ | ||
480 | /* | ||
481 | * We do a passive status test under shared PCI interrupts on | ||
482 | * cards that truly share the ATA side interrupt, but may also share | ||
483 | * an interrupt with another pci card/device. We make no assumptions | ||
484 | * about possible isa-pnp and pci-pnp issues yet. | ||
485 | */ | ||
486 | if (IDE_CONTROL_REG) | ||
487 | stat = hwif->INB(IDE_ALTSTATUS_REG); | ||
488 | else | ||
489 | #endif /* CONFIG_IDEPCI_SHARE_IRQ */ | ||
490 | /* Note: this may clear a pending IRQ!! */ | ||
491 | stat = hwif->INB(IDE_STATUS_REG); | ||
492 | |||
493 | if (stat & BUSY_STAT) | ||
494 | /* drive busy: definitely not interrupting */ | ||
495 | return 0; | ||
496 | |||
497 | /* drive ready: *might* be interrupting */ | ||
498 | return 1; | ||
499 | } | ||
500 | |||
501 | EXPORT_SYMBOL(drive_is_ready); | ||
502 | |||
503 | /* | ||
504 | * Global for All, and taken from ide-pmac.c. Can be called | ||
505 | * with spinlock held & IRQs disabled, so don't schedule ! | ||
506 | */ | ||
507 | int wait_for_ready (ide_drive_t *drive, int timeout) | ||
508 | { | ||
509 | ide_hwif_t *hwif = HWIF(drive); | ||
510 | u8 stat = 0; | ||
511 | |||
512 | while(--timeout) { | ||
513 | stat = hwif->INB(IDE_STATUS_REG); | ||
514 | if (!(stat & BUSY_STAT)) { | ||
515 | if (drive->ready_stat == 0) | ||
516 | break; | ||
517 | else if ((stat & drive->ready_stat)||(stat & ERR_STAT)) | ||
518 | break; | ||
519 | } | ||
520 | mdelay(1); | ||
521 | } | ||
522 | if ((stat & ERR_STAT) || timeout <= 0) { | ||
523 | if (stat & ERR_STAT) { | ||
524 | printk(KERN_ERR "%s: wait_for_ready, " | ||
525 | "error status: %x\n", drive->name, stat); | ||
526 | } | ||
527 | return 1; | ||
528 | } | ||
529 | return 0; | ||
530 | } | ||
531 | |||
532 | EXPORT_SYMBOL(wait_for_ready); | ||
533 | |||
534 | /* | ||
535 | * This routine busy-waits for the drive status to be not "busy". | ||
536 | * It then checks the status for all of the "good" bits and none | ||
537 | * of the "bad" bits, and if all is okay it returns 0. All other | ||
538 | * cases return 1 after invoking ide_error() -- caller should just return. | ||
539 | * | ||
540 | * This routine should get fixed to not hog the cpu during extra long waits.. | ||
541 | * That could be done by busy-waiting for the first jiffy or two, and then | ||
542 | * setting a timer to wake up at half second intervals thereafter, | ||
543 | * until timeout is achieved, before timing out. | ||
544 | */ | ||
545 | int ide_wait_stat (ide_startstop_t *startstop, ide_drive_t *drive, u8 good, u8 bad, unsigned long timeout) | ||
546 | { | ||
547 | ide_hwif_t *hwif = HWIF(drive); | ||
548 | u8 stat; | ||
549 | int i; | ||
550 | unsigned long flags; | ||
551 | |||
552 | /* bail early if we've exceeded max_failures */ | ||
553 | if (drive->max_failures && (drive->failures > drive->max_failures)) { | ||
554 | *startstop = ide_stopped; | ||
555 | return 1; | ||
556 | } | ||
557 | |||
558 | udelay(1); /* spec allows drive 400ns to assert "BUSY" */ | ||
559 | if ((stat = hwif->INB(IDE_STATUS_REG)) & BUSY_STAT) { | ||
560 | local_irq_set(flags); | ||
561 | timeout += jiffies; | ||
562 | while ((stat = hwif->INB(IDE_STATUS_REG)) & BUSY_STAT) { | ||
563 | if (time_after(jiffies, timeout)) { | ||
564 | /* | ||
565 | * One last read after the timeout in case | ||
566 | * heavy interrupt load made us not make any | ||
567 | * progress during the timeout.. | ||
568 | */ | ||
569 | stat = hwif->INB(IDE_STATUS_REG); | ||
570 | if (!(stat & BUSY_STAT)) | ||
571 | break; | ||
572 | |||
573 | local_irq_restore(flags); | ||
574 | *startstop = ide_error(drive, "status timeout", stat); | ||
575 | return 1; | ||
576 | } | ||
577 | } | ||
578 | local_irq_restore(flags); | ||
579 | } | ||
580 | /* | ||
581 | * Allow status to settle, then read it again. | ||
582 | * A few rare drives vastly violate the 400ns spec here, | ||
583 | * so we'll wait up to 10usec for a "good" status | ||
584 | * rather than expensively fail things immediately. | ||
585 | * This fix courtesy of Matthew Faupel & Niccolo Rigacci. | ||
586 | */ | ||
587 | for (i = 0; i < 10; i++) { | ||
588 | udelay(1); | ||
589 | if (OK_STAT((stat = hwif->INB(IDE_STATUS_REG)), good, bad)) | ||
590 | return 0; | ||
591 | } | ||
592 | *startstop = ide_error(drive, "status error", stat); | ||
593 | return 1; | ||
594 | } | ||
595 | |||
596 | EXPORT_SYMBOL(ide_wait_stat); | ||
597 | |||
598 | /* | ||
599 | * All hosts that use the 80c ribbon must use! | ||
600 | * The name is derived from upper byte of word 93 and the 80c ribbon. | ||
601 | */ | ||
602 | u8 eighty_ninty_three (ide_drive_t *drive) | ||
603 | { | ||
604 | #if 0 | ||
605 | if (!HWIF(drive)->udma_four) | ||
606 | return 0; | ||
607 | |||
608 | if (drive->id->major_rev_num) { | ||
609 | int hssbd = 0; | ||
610 | int i; | ||
611 | /* | ||
612 | * Determine highest Supported SPEC | ||
613 | */ | ||
614 | for (i=1; i<=15; i++) | ||
615 | if (drive->id->major_rev_num & (1<<i)) | ||
616 | hssbd++; | ||
617 | |||
618 | switch (hssbd) { | ||
619 | case 7: | ||
620 | case 6: | ||
621 | case 5: | ||
622 | /* ATA-4 and older do not support above Ultra 33 */ | ||
623 | default: | ||
624 | return 0; | ||
625 | } | ||
626 | } | ||
627 | |||
628 | return ((u8) ( | ||
629 | #ifndef CONFIG_IDEDMA_IVB | ||
630 | (drive->id->hw_config & 0x4000) && | ||
631 | #endif /* CONFIG_IDEDMA_IVB */ | ||
632 | (drive->id->hw_config & 0x6000)) ? 1 : 0); | ||
633 | |||
634 | #else | ||
635 | |||
636 | return ((u8) ((HWIF(drive)->udma_four) && | ||
637 | #ifndef CONFIG_IDEDMA_IVB | ||
638 | (drive->id->hw_config & 0x4000) && | ||
639 | #endif /* CONFIG_IDEDMA_IVB */ | ||
640 | (drive->id->hw_config & 0x6000)) ? 1 : 0); | ||
641 | #endif | ||
642 | } | ||
643 | |||
644 | EXPORT_SYMBOL(eighty_ninty_three); | ||
645 | |||
646 | int ide_ata66_check (ide_drive_t *drive, ide_task_t *args) | ||
647 | { | ||
648 | if ((args->tfRegister[IDE_COMMAND_OFFSET] == WIN_SETFEATURES) && | ||
649 | (args->tfRegister[IDE_SECTOR_OFFSET] > XFER_UDMA_2) && | ||
650 | (args->tfRegister[IDE_FEATURE_OFFSET] == SETFEATURES_XFER)) { | ||
651 | #ifndef CONFIG_IDEDMA_IVB | ||
652 | if ((drive->id->hw_config & 0x6000) == 0) { | ||
653 | #else /* !CONFIG_IDEDMA_IVB */ | ||
654 | if (((drive->id->hw_config & 0x2000) == 0) || | ||
655 | ((drive->id->hw_config & 0x4000) == 0)) { | ||
656 | #endif /* CONFIG_IDEDMA_IVB */ | ||
657 | printk("%s: Speed warnings UDMA 3/4/5 is not " | ||
658 | "functional.\n", drive->name); | ||
659 | return 1; | ||
660 | } | ||
661 | if (!HWIF(drive)->udma_four) { | ||
662 | printk("%s: Speed warnings UDMA 3/4/5 is not " | ||
663 | "functional.\n", | ||
664 | HWIF(drive)->name); | ||
665 | return 1; | ||
666 | } | ||
667 | } | ||
668 | return 0; | ||
669 | } | ||
670 | |||
671 | /* | ||
672 | * Backside of HDIO_DRIVE_CMD call of SETFEATURES_XFER. | ||
673 | * 1 : Safe to update drive->id DMA registers. | ||
674 | * 0 : OOPs not allowed. | ||
675 | */ | ||
676 | int set_transfer (ide_drive_t *drive, ide_task_t *args) | ||
677 | { | ||
678 | if ((args->tfRegister[IDE_COMMAND_OFFSET] == WIN_SETFEATURES) && | ||
679 | (args->tfRegister[IDE_SECTOR_OFFSET] >= XFER_SW_DMA_0) && | ||
680 | (args->tfRegister[IDE_FEATURE_OFFSET] == SETFEATURES_XFER) && | ||
681 | (drive->id->dma_ultra || | ||
682 | drive->id->dma_mword || | ||
683 | drive->id->dma_1word)) | ||
684 | return 1; | ||
685 | |||
686 | return 0; | ||
687 | } | ||
688 | |||
689 | #ifdef CONFIG_BLK_DEV_IDEDMA | ||
690 | static u8 ide_auto_reduce_xfer (ide_drive_t *drive) | ||
691 | { | ||
692 | if (!drive->crc_count) | ||
693 | return drive->current_speed; | ||
694 | drive->crc_count = 0; | ||
695 | |||
696 | switch(drive->current_speed) { | ||
697 | case XFER_UDMA_7: return XFER_UDMA_6; | ||
698 | case XFER_UDMA_6: return XFER_UDMA_5; | ||
699 | case XFER_UDMA_5: return XFER_UDMA_4; | ||
700 | case XFER_UDMA_4: return XFER_UDMA_3; | ||
701 | case XFER_UDMA_3: return XFER_UDMA_2; | ||
702 | case XFER_UDMA_2: return XFER_UDMA_1; | ||
703 | case XFER_UDMA_1: return XFER_UDMA_0; | ||
704 | /* | ||
705 | * OOPS we do not goto non Ultra DMA modes | ||
706 | * without iCRC's available we force | ||
707 | * the system to PIO and make the user | ||
708 | * invoke the ATA-1 ATA-2 DMA modes. | ||
709 | */ | ||
710 | case XFER_UDMA_0: | ||
711 | default: return XFER_PIO_4; | ||
712 | } | ||
713 | } | ||
714 | #endif /* CONFIG_BLK_DEV_IDEDMA */ | ||
715 | |||
716 | /* | ||
717 | * Update the | ||
718 | */ | ||
719 | int ide_driveid_update (ide_drive_t *drive) | ||
720 | { | ||
721 | ide_hwif_t *hwif = HWIF(drive); | ||
722 | struct hd_driveid *id; | ||
723 | #if 0 | ||
724 | id = kmalloc(SECTOR_WORDS*4, GFP_ATOMIC); | ||
725 | if (!id) | ||
726 | return 0; | ||
727 | |||
728 | taskfile_lib_get_identify(drive, (char *)&id); | ||
729 | |||
730 | ide_fix_driveid(id); | ||
731 | if (id) { | ||
732 | drive->id->dma_ultra = id->dma_ultra; | ||
733 | drive->id->dma_mword = id->dma_mword; | ||
734 | drive->id->dma_1word = id->dma_1word; | ||
735 | /* anything more ? */ | ||
736 | kfree(id); | ||
737 | } | ||
738 | return 1; | ||
739 | #else | ||
740 | /* | ||
741 | * Re-read drive->id for possible DMA mode | ||
742 | * change (copied from ide-probe.c) | ||
743 | */ | ||
744 | unsigned long timeout, flags; | ||
745 | |||
746 | SELECT_MASK(drive, 1); | ||
747 | if (IDE_CONTROL_REG) | ||
748 | hwif->OUTB(drive->ctl,IDE_CONTROL_REG); | ||
749 | msleep(50); | ||
750 | hwif->OUTB(WIN_IDENTIFY, IDE_COMMAND_REG); | ||
751 | timeout = jiffies + WAIT_WORSTCASE; | ||
752 | do { | ||
753 | if (time_after(jiffies, timeout)) { | ||
754 | SELECT_MASK(drive, 0); | ||
755 | return 0; /* drive timed-out */ | ||
756 | } | ||
757 | msleep(50); /* give drive a breather */ | ||
758 | } while (hwif->INB(IDE_ALTSTATUS_REG) & BUSY_STAT); | ||
759 | msleep(50); /* wait for IRQ and DRQ_STAT */ | ||
760 | if (!OK_STAT(hwif->INB(IDE_STATUS_REG),DRQ_STAT,BAD_R_STAT)) { | ||
761 | SELECT_MASK(drive, 0); | ||
762 | printk("%s: CHECK for good STATUS\n", drive->name); | ||
763 | return 0; | ||
764 | } | ||
765 | local_irq_save(flags); | ||
766 | SELECT_MASK(drive, 0); | ||
767 | id = kmalloc(SECTOR_WORDS*4, GFP_ATOMIC); | ||
768 | if (!id) { | ||
769 | local_irq_restore(flags); | ||
770 | return 0; | ||
771 | } | ||
772 | ata_input_data(drive, id, SECTOR_WORDS); | ||
773 | (void) hwif->INB(IDE_STATUS_REG); /* clear drive IRQ */ | ||
774 | local_irq_enable(); | ||
775 | local_irq_restore(flags); | ||
776 | ide_fix_driveid(id); | ||
777 | if (id) { | ||
778 | drive->id->dma_ultra = id->dma_ultra; | ||
779 | drive->id->dma_mword = id->dma_mword; | ||
780 | drive->id->dma_1word = id->dma_1word; | ||
781 | /* anything more ? */ | ||
782 | kfree(id); | ||
783 | } | ||
784 | |||
785 | return 1; | ||
786 | #endif | ||
787 | } | ||
788 | |||
789 | /* | ||
790 | * Similar to ide_wait_stat(), except it never calls ide_error internally. | ||
791 | * This is a kludge to handle the new ide_config_drive_speed() function, | ||
792 | * and should not otherwise be used anywhere. Eventually, the tuneproc's | ||
793 | * should be updated to return ide_startstop_t, in which case we can get | ||
794 | * rid of this abomination again. :) -ml | ||
795 | * | ||
796 | * It is gone.......... | ||
797 | * | ||
798 | * const char *msg == consider adding for verbose errors. | ||
799 | */ | ||
800 | int ide_config_drive_speed (ide_drive_t *drive, u8 speed) | ||
801 | { | ||
802 | ide_hwif_t *hwif = HWIF(drive); | ||
803 | int i, error = 1; | ||
804 | u8 stat; | ||
805 | |||
806 | // while (HWGROUP(drive)->busy) | ||
807 | // msleep(50); | ||
808 | |||
809 | #ifdef CONFIG_BLK_DEV_IDEDMA | ||
810 | if (hwif->ide_dma_check) /* check if host supports DMA */ | ||
811 | hwif->ide_dma_host_off(drive); | ||
812 | #endif | ||
813 | |||
814 | /* | ||
815 | * Don't use ide_wait_cmd here - it will | ||
816 | * attempt to set_geometry and recalibrate, | ||
817 | * but for some reason these don't work at | ||
818 | * this point (lost interrupt). | ||
819 | */ | ||
820 | /* | ||
821 | * Select the drive, and issue the SETFEATURES command | ||
822 | */ | ||
823 | disable_irq_nosync(hwif->irq); | ||
824 | |||
825 | /* | ||
826 | * FIXME: we race against the running IRQ here if | ||
827 | * this is called from non IRQ context. If we use | ||
828 | * disable_irq() we hang on the error path. Work | ||
829 | * is needed. | ||
830 | */ | ||
831 | |||
832 | udelay(1); | ||
833 | SELECT_DRIVE(drive); | ||
834 | SELECT_MASK(drive, 0); | ||
835 | udelay(1); | ||
836 | if (IDE_CONTROL_REG) | ||
837 | hwif->OUTB(drive->ctl | 2, IDE_CONTROL_REG); | ||
838 | hwif->OUTB(speed, IDE_NSECTOR_REG); | ||
839 | hwif->OUTB(SETFEATURES_XFER, IDE_FEATURE_REG); | ||
840 | hwif->OUTB(WIN_SETFEATURES, IDE_COMMAND_REG); | ||
841 | if ((IDE_CONTROL_REG) && (drive->quirk_list == 2)) | ||
842 | hwif->OUTB(drive->ctl, IDE_CONTROL_REG); | ||
843 | udelay(1); | ||
844 | /* | ||
845 | * Wait for drive to become non-BUSY | ||
846 | */ | ||
847 | if ((stat = hwif->INB(IDE_STATUS_REG)) & BUSY_STAT) { | ||
848 | unsigned long flags, timeout; | ||
849 | local_irq_set(flags); | ||
850 | timeout = jiffies + WAIT_CMD; | ||
851 | while ((stat = hwif->INB(IDE_STATUS_REG)) & BUSY_STAT) { | ||
852 | if (time_after(jiffies, timeout)) | ||
853 | break; | ||
854 | } | ||
855 | local_irq_restore(flags); | ||
856 | } | ||
857 | |||
858 | /* | ||
859 | * Allow status to settle, then read it again. | ||
860 | * A few rare drives vastly violate the 400ns spec here, | ||
861 | * so we'll wait up to 10usec for a "good" status | ||
862 | * rather than expensively fail things immediately. | ||
863 | * This fix courtesy of Matthew Faupel & Niccolo Rigacci. | ||
864 | */ | ||
865 | for (i = 0; i < 10; i++) { | ||
866 | udelay(1); | ||
867 | if (OK_STAT((stat = hwif->INB(IDE_STATUS_REG)), DRIVE_READY, BUSY_STAT|DRQ_STAT|ERR_STAT)) { | ||
868 | error = 0; | ||
869 | break; | ||
870 | } | ||
871 | } | ||
872 | |||
873 | SELECT_MASK(drive, 0); | ||
874 | |||
875 | enable_irq(hwif->irq); | ||
876 | |||
877 | if (error) { | ||
878 | (void) ide_dump_status(drive, "set_drive_speed_status", stat); | ||
879 | return error; | ||
880 | } | ||
881 | |||
882 | drive->id->dma_ultra &= ~0xFF00; | ||
883 | drive->id->dma_mword &= ~0x0F00; | ||
884 | drive->id->dma_1word &= ~0x0F00; | ||
885 | |||
886 | #ifdef CONFIG_BLK_DEV_IDEDMA | ||
887 | if (speed >= XFER_SW_DMA_0) | ||
888 | hwif->ide_dma_host_on(drive); | ||
889 | else if (hwif->ide_dma_check) /* check if host supports DMA */ | ||
890 | hwif->ide_dma_off_quietly(drive); | ||
891 | #endif | ||
892 | |||
893 | switch(speed) { | ||
894 | case XFER_UDMA_7: drive->id->dma_ultra |= 0x8080; break; | ||
895 | case XFER_UDMA_6: drive->id->dma_ultra |= 0x4040; break; | ||
896 | case XFER_UDMA_5: drive->id->dma_ultra |= 0x2020; break; | ||
897 | case XFER_UDMA_4: drive->id->dma_ultra |= 0x1010; break; | ||
898 | case XFER_UDMA_3: drive->id->dma_ultra |= 0x0808; break; | ||
899 | case XFER_UDMA_2: drive->id->dma_ultra |= 0x0404; break; | ||
900 | case XFER_UDMA_1: drive->id->dma_ultra |= 0x0202; break; | ||
901 | case XFER_UDMA_0: drive->id->dma_ultra |= 0x0101; break; | ||
902 | case XFER_MW_DMA_2: drive->id->dma_mword |= 0x0404; break; | ||
903 | case XFER_MW_DMA_1: drive->id->dma_mword |= 0x0202; break; | ||
904 | case XFER_MW_DMA_0: drive->id->dma_mword |= 0x0101; break; | ||
905 | case XFER_SW_DMA_2: drive->id->dma_1word |= 0x0404; break; | ||
906 | case XFER_SW_DMA_1: drive->id->dma_1word |= 0x0202; break; | ||
907 | case XFER_SW_DMA_0: drive->id->dma_1word |= 0x0101; break; | ||
908 | default: break; | ||
909 | } | ||
910 | if (!drive->init_speed) | ||
911 | drive->init_speed = speed; | ||
912 | drive->current_speed = speed; | ||
913 | return error; | ||
914 | } | ||
915 | |||
916 | EXPORT_SYMBOL(ide_config_drive_speed); | ||
917 | |||
918 | |||
919 | /* | ||
920 | * This should get invoked any time we exit the driver to | ||
921 | * wait for an interrupt response from a drive. handler() points | ||
922 | * at the appropriate code to handle the next interrupt, and a | ||
923 | * timer is started to prevent us from waiting forever in case | ||
924 | * something goes wrong (see the ide_timer_expiry() handler later on). | ||
925 | * | ||
926 | * See also ide_execute_command | ||
927 | */ | ||
928 | static void __ide_set_handler (ide_drive_t *drive, ide_handler_t *handler, | ||
929 | unsigned int timeout, ide_expiry_t *expiry) | ||
930 | { | ||
931 | ide_hwgroup_t *hwgroup = HWGROUP(drive); | ||
932 | |||
933 | if (hwgroup->handler != NULL) { | ||
934 | printk(KERN_CRIT "%s: ide_set_handler: handler not null; " | ||
935 | "old=%p, new=%p\n", | ||
936 | drive->name, hwgroup->handler, handler); | ||
937 | } | ||
938 | hwgroup->handler = handler; | ||
939 | hwgroup->expiry = expiry; | ||
940 | hwgroup->timer.expires = jiffies + timeout; | ||
941 | add_timer(&hwgroup->timer); | ||
942 | } | ||
943 | |||
944 | void ide_set_handler (ide_drive_t *drive, ide_handler_t *handler, | ||
945 | unsigned int timeout, ide_expiry_t *expiry) | ||
946 | { | ||
947 | unsigned long flags; | ||
948 | spin_lock_irqsave(&ide_lock, flags); | ||
949 | __ide_set_handler(drive, handler, timeout, expiry); | ||
950 | spin_unlock_irqrestore(&ide_lock, flags); | ||
951 | } | ||
952 | |||
953 | EXPORT_SYMBOL(ide_set_handler); | ||
954 | |||
955 | /** | ||
956 | * ide_execute_command - execute an IDE command | ||
957 | * @drive: IDE drive to issue the command against | ||
958 | * @command: command byte to write | ||
959 | * @handler: handler for next phase | ||
960 | * @timeout: timeout for command | ||
961 | * @expiry: handler to run on timeout | ||
962 | * | ||
963 | * Helper function to issue an IDE command. This handles the | ||
964 | * atomicity requirements, command timing and ensures that the | ||
965 | * handler and IRQ setup do not race. All IDE command kick off | ||
966 | * should go via this function or do equivalent locking. | ||
967 | */ | ||
968 | |||
969 | void ide_execute_command(ide_drive_t *drive, task_ioreg_t cmd, ide_handler_t *handler, unsigned timeout, ide_expiry_t *expiry) | ||
970 | { | ||
971 | unsigned long flags; | ||
972 | ide_hwgroup_t *hwgroup = HWGROUP(drive); | ||
973 | ide_hwif_t *hwif = HWIF(drive); | ||
974 | |||
975 | spin_lock_irqsave(&ide_lock, flags); | ||
976 | |||
977 | if(hwgroup->handler) | ||
978 | BUG(); | ||
979 | hwgroup->handler = handler; | ||
980 | hwgroup->expiry = expiry; | ||
981 | hwgroup->timer.expires = jiffies + timeout; | ||
982 | add_timer(&hwgroup->timer); | ||
983 | hwif->OUTBSYNC(drive, cmd, IDE_COMMAND_REG); | ||
984 | /* Drive takes 400nS to respond, we must avoid the IRQ being | ||
985 | serviced before that. | ||
986 | |||
987 | FIXME: we could skip this delay with care on non shared | ||
988 | devices | ||
989 | */ | ||
990 | ndelay(400); | ||
991 | spin_unlock_irqrestore(&ide_lock, flags); | ||
992 | } | ||
993 | |||
994 | EXPORT_SYMBOL(ide_execute_command); | ||
995 | |||
996 | |||
997 | /* needed below */ | ||
998 | static ide_startstop_t do_reset1 (ide_drive_t *, int); | ||
999 | |||
1000 | /* | ||
1001 | * atapi_reset_pollfunc() gets invoked to poll the interface for completion every 50ms | ||
1002 | * during an atapi drive reset operation. If the drive has not yet responded, | ||
1003 | * and we have not yet hit our maximum waiting time, then the timer is restarted | ||
1004 | * for another 50ms. | ||
1005 | */ | ||
1006 | static ide_startstop_t atapi_reset_pollfunc (ide_drive_t *drive) | ||
1007 | { | ||
1008 | ide_hwgroup_t *hwgroup = HWGROUP(drive); | ||
1009 | ide_hwif_t *hwif = HWIF(drive); | ||
1010 | u8 stat; | ||
1011 | |||
1012 | SELECT_DRIVE(drive); | ||
1013 | udelay (10); | ||
1014 | |||
1015 | if (OK_STAT(stat = hwif->INB(IDE_STATUS_REG), 0, BUSY_STAT)) { | ||
1016 | printk("%s: ATAPI reset complete\n", drive->name); | ||
1017 | } else { | ||
1018 | if (time_before(jiffies, hwgroup->poll_timeout)) { | ||
1019 | if (HWGROUP(drive)->handler != NULL) | ||
1020 | BUG(); | ||
1021 | ide_set_handler(drive, &atapi_reset_pollfunc, HZ/20, NULL); | ||
1022 | /* continue polling */ | ||
1023 | return ide_started; | ||
1024 | } | ||
1025 | /* end of polling */ | ||
1026 | hwgroup->polling = 0; | ||
1027 | printk("%s: ATAPI reset timed-out, status=0x%02x\n", | ||
1028 | drive->name, stat); | ||
1029 | /* do it the old fashioned way */ | ||
1030 | return do_reset1(drive, 1); | ||
1031 | } | ||
1032 | /* done polling */ | ||
1033 | hwgroup->polling = 0; | ||
1034 | return ide_stopped; | ||
1035 | } | ||
1036 | |||
1037 | /* | ||
1038 | * reset_pollfunc() gets invoked to poll the interface for completion every 50ms | ||
1039 | * during an ide reset operation. If the drives have not yet responded, | ||
1040 | * and we have not yet hit our maximum waiting time, then the timer is restarted | ||
1041 | * for another 50ms. | ||
1042 | */ | ||
1043 | static ide_startstop_t reset_pollfunc (ide_drive_t *drive) | ||
1044 | { | ||
1045 | ide_hwgroup_t *hwgroup = HWGROUP(drive); | ||
1046 | ide_hwif_t *hwif = HWIF(drive); | ||
1047 | u8 tmp; | ||
1048 | |||
1049 | if (hwif->reset_poll != NULL) { | ||
1050 | if (hwif->reset_poll(drive)) { | ||
1051 | printk(KERN_ERR "%s: host reset_poll failure for %s.\n", | ||
1052 | hwif->name, drive->name); | ||
1053 | return ide_stopped; | ||
1054 | } | ||
1055 | } | ||
1056 | |||
1057 | if (!OK_STAT(tmp = hwif->INB(IDE_STATUS_REG), 0, BUSY_STAT)) { | ||
1058 | if (time_before(jiffies, hwgroup->poll_timeout)) { | ||
1059 | if (HWGROUP(drive)->handler != NULL) | ||
1060 | BUG(); | ||
1061 | ide_set_handler(drive, &reset_pollfunc, HZ/20, NULL); | ||
1062 | /* continue polling */ | ||
1063 | return ide_started; | ||
1064 | } | ||
1065 | printk("%s: reset timed-out, status=0x%02x\n", hwif->name, tmp); | ||
1066 | drive->failures++; | ||
1067 | } else { | ||
1068 | printk("%s: reset: ", hwif->name); | ||
1069 | if ((tmp = hwif->INB(IDE_ERROR_REG)) == 1) { | ||
1070 | printk("success\n"); | ||
1071 | drive->failures = 0; | ||
1072 | } else { | ||
1073 | drive->failures++; | ||
1074 | printk("master: "); | ||
1075 | switch (tmp & 0x7f) { | ||
1076 | case 1: printk("passed"); | ||
1077 | break; | ||
1078 | case 2: printk("formatter device error"); | ||
1079 | break; | ||
1080 | case 3: printk("sector buffer error"); | ||
1081 | break; | ||
1082 | case 4: printk("ECC circuitry error"); | ||
1083 | break; | ||
1084 | case 5: printk("controlling MPU error"); | ||
1085 | break; | ||
1086 | default:printk("error (0x%02x?)", tmp); | ||
1087 | } | ||
1088 | if (tmp & 0x80) | ||
1089 | printk("; slave: failed"); | ||
1090 | printk("\n"); | ||
1091 | } | ||
1092 | } | ||
1093 | hwgroup->polling = 0; /* done polling */ | ||
1094 | return ide_stopped; | ||
1095 | } | ||
1096 | |||
1097 | static void check_dma_crc(ide_drive_t *drive) | ||
1098 | { | ||
1099 | #ifdef CONFIG_BLK_DEV_IDEDMA | ||
1100 | if (drive->crc_count) { | ||
1101 | (void) HWIF(drive)->ide_dma_off_quietly(drive); | ||
1102 | ide_set_xfer_rate(drive, ide_auto_reduce_xfer(drive)); | ||
1103 | if (drive->current_speed >= XFER_SW_DMA_0) | ||
1104 | (void) HWIF(drive)->ide_dma_on(drive); | ||
1105 | } else | ||
1106 | (void)__ide_dma_off(drive); | ||
1107 | #endif | ||
1108 | } | ||
1109 | |||
1110 | static void ide_disk_pre_reset(ide_drive_t *drive) | ||
1111 | { | ||
1112 | int legacy = (drive->id->cfs_enable_2 & 0x0400) ? 0 : 1; | ||
1113 | |||
1114 | drive->special.all = 0; | ||
1115 | drive->special.b.set_geometry = legacy; | ||
1116 | drive->special.b.recalibrate = legacy; | ||
1117 | if (OK_TO_RESET_CONTROLLER) | ||
1118 | drive->mult_count = 0; | ||
1119 | if (!drive->keep_settings && !drive->using_dma) | ||
1120 | drive->mult_req = 0; | ||
1121 | if (drive->mult_req != drive->mult_count) | ||
1122 | drive->special.b.set_multmode = 1; | ||
1123 | } | ||
1124 | |||
1125 | static void pre_reset(ide_drive_t *drive) | ||
1126 | { | ||
1127 | if (drive->media == ide_disk) | ||
1128 | ide_disk_pre_reset(drive); | ||
1129 | else | ||
1130 | drive->post_reset = 1; | ||
1131 | |||
1132 | if (!drive->keep_settings) { | ||
1133 | if (drive->using_dma) { | ||
1134 | check_dma_crc(drive); | ||
1135 | } else { | ||
1136 | drive->unmask = 0; | ||
1137 | drive->io_32bit = 0; | ||
1138 | } | ||
1139 | return; | ||
1140 | } | ||
1141 | if (drive->using_dma) | ||
1142 | check_dma_crc(drive); | ||
1143 | |||
1144 | if (HWIF(drive)->pre_reset != NULL) | ||
1145 | HWIF(drive)->pre_reset(drive); | ||
1146 | |||
1147 | } | ||
1148 | |||
1149 | /* | ||
1150 | * do_reset1() attempts to recover a confused drive by resetting it. | ||
1151 | * Unfortunately, resetting a disk drive actually resets all devices on | ||
1152 | * the same interface, so it can really be thought of as resetting the | ||
1153 | * interface rather than resetting the drive. | ||
1154 | * | ||
1155 | * ATAPI devices have their own reset mechanism which allows them to be | ||
1156 | * individually reset without clobbering other devices on the same interface. | ||
1157 | * | ||
1158 | * Unfortunately, the IDE interface does not generate an interrupt to let | ||
1159 | * us know when the reset operation has finished, so we must poll for this. | ||
1160 | * Equally poor, though, is the fact that this may a very long time to complete, | ||
1161 | * (up to 30 seconds worstcase). So, instead of busy-waiting here for it, | ||
1162 | * we set a timer to poll at 50ms intervals. | ||
1163 | */ | ||
1164 | static ide_startstop_t do_reset1 (ide_drive_t *drive, int do_not_try_atapi) | ||
1165 | { | ||
1166 | unsigned int unit; | ||
1167 | unsigned long flags; | ||
1168 | ide_hwif_t *hwif; | ||
1169 | ide_hwgroup_t *hwgroup; | ||
1170 | |||
1171 | spin_lock_irqsave(&ide_lock, flags); | ||
1172 | hwif = HWIF(drive); | ||
1173 | hwgroup = HWGROUP(drive); | ||
1174 | |||
1175 | /* We must not reset with running handlers */ | ||
1176 | if(hwgroup->handler != NULL) | ||
1177 | BUG(); | ||
1178 | |||
1179 | /* For an ATAPI device, first try an ATAPI SRST. */ | ||
1180 | if (drive->media != ide_disk && !do_not_try_atapi) { | ||
1181 | pre_reset(drive); | ||
1182 | SELECT_DRIVE(drive); | ||
1183 | udelay (20); | ||
1184 | hwif->OUTB(WIN_SRST, IDE_COMMAND_REG); | ||
1185 | hwgroup->poll_timeout = jiffies + WAIT_WORSTCASE; | ||
1186 | hwgroup->polling = 1; | ||
1187 | __ide_set_handler(drive, &atapi_reset_pollfunc, HZ/20, NULL); | ||
1188 | spin_unlock_irqrestore(&ide_lock, flags); | ||
1189 | return ide_started; | ||
1190 | } | ||
1191 | |||
1192 | /* | ||
1193 | * First, reset any device state data we were maintaining | ||
1194 | * for any of the drives on this interface. | ||
1195 | */ | ||
1196 | for (unit = 0; unit < MAX_DRIVES; ++unit) | ||
1197 | pre_reset(&hwif->drives[unit]); | ||
1198 | |||
1199 | #if OK_TO_RESET_CONTROLLER | ||
1200 | if (!IDE_CONTROL_REG) { | ||
1201 | spin_unlock_irqrestore(&ide_lock, flags); | ||
1202 | return ide_stopped; | ||
1203 | } | ||
1204 | |||
1205 | /* | ||
1206 | * Note that we also set nIEN while resetting the device, | ||
1207 | * to mask unwanted interrupts from the interface during the reset. | ||
1208 | * However, due to the design of PC hardware, this will cause an | ||
1209 | * immediate interrupt due to the edge transition it produces. | ||
1210 | * This single interrupt gives us a "fast poll" for drives that | ||
1211 | * recover from reset very quickly, saving us the first 50ms wait time. | ||
1212 | */ | ||
1213 | /* set SRST and nIEN */ | ||
1214 | hwif->OUTBSYNC(drive, drive->ctl|6,IDE_CONTROL_REG); | ||
1215 | /* more than enough time */ | ||
1216 | udelay(10); | ||
1217 | if (drive->quirk_list == 2) { | ||
1218 | /* clear SRST and nIEN */ | ||
1219 | hwif->OUTBSYNC(drive, drive->ctl, IDE_CONTROL_REG); | ||
1220 | } else { | ||
1221 | /* clear SRST, leave nIEN */ | ||
1222 | hwif->OUTBSYNC(drive, drive->ctl|2, IDE_CONTROL_REG); | ||
1223 | } | ||
1224 | /* more than enough time */ | ||
1225 | udelay(10); | ||
1226 | hwgroup->poll_timeout = jiffies + WAIT_WORSTCASE; | ||
1227 | hwgroup->polling = 1; | ||
1228 | __ide_set_handler(drive, &reset_pollfunc, HZ/20, NULL); | ||
1229 | |||
1230 | /* | ||
1231 | * Some weird controller like resetting themselves to a strange | ||
1232 | * state when the disks are reset this way. At least, the Winbond | ||
1233 | * 553 documentation says that | ||
1234 | */ | ||
1235 | if (hwif->resetproc != NULL) { | ||
1236 | hwif->resetproc(drive); | ||
1237 | } | ||
1238 | |||
1239 | #endif /* OK_TO_RESET_CONTROLLER */ | ||
1240 | |||
1241 | spin_unlock_irqrestore(&ide_lock, flags); | ||
1242 | return ide_started; | ||
1243 | } | ||
1244 | |||
1245 | /* | ||
1246 | * ide_do_reset() is the entry point to the drive/interface reset code. | ||
1247 | */ | ||
1248 | |||
1249 | ide_startstop_t ide_do_reset (ide_drive_t *drive) | ||
1250 | { | ||
1251 | return do_reset1(drive, 0); | ||
1252 | } | ||
1253 | |||
1254 | EXPORT_SYMBOL(ide_do_reset); | ||
1255 | |||
1256 | /* | ||
1257 | * ide_wait_not_busy() waits for the currently selected device on the hwif | ||
1258 | * to report a non-busy status, see comments in probe_hwif(). | ||
1259 | */ | ||
1260 | int ide_wait_not_busy(ide_hwif_t *hwif, unsigned long timeout) | ||
1261 | { | ||
1262 | u8 stat = 0; | ||
1263 | |||
1264 | while(timeout--) { | ||
1265 | /* | ||
1266 | * Turn this into a schedule() sleep once I'm sure | ||
1267 | * about locking issues (2.5 work ?). | ||
1268 | */ | ||
1269 | mdelay(1); | ||
1270 | stat = hwif->INB(hwif->io_ports[IDE_STATUS_OFFSET]); | ||
1271 | if ((stat & BUSY_STAT) == 0) | ||
1272 | return 0; | ||
1273 | /* | ||
1274 | * Assume a value of 0xff means nothing is connected to | ||
1275 | * the interface and it doesn't implement the pull-down | ||
1276 | * resistor on D7. | ||
1277 | */ | ||
1278 | if (stat == 0xff) | ||
1279 | return -ENODEV; | ||
1280 | } | ||
1281 | return -EBUSY; | ||
1282 | } | ||
1283 | |||
1284 | EXPORT_SYMBOL_GPL(ide_wait_not_busy); | ||
1285 | |||
diff --git a/drivers/ide/ide-lib.c b/drivers/ide/ide-lib.c new file mode 100644 index 000000000000..6806d407e9c1 --- /dev/null +++ b/drivers/ide/ide-lib.c | |||
@@ -0,0 +1,622 @@ | |||
1 | #include <linux/config.h> | ||
2 | #include <linux/module.h> | ||
3 | #include <linux/types.h> | ||
4 | #include <linux/string.h> | ||
5 | #include <linux/kernel.h> | ||
6 | #include <linux/timer.h> | ||
7 | #include <linux/mm.h> | ||
8 | #include <linux/interrupt.h> | ||
9 | #include <linux/major.h> | ||
10 | #include <linux/errno.h> | ||
11 | #include <linux/genhd.h> | ||
12 | #include <linux/blkpg.h> | ||
13 | #include <linux/slab.h> | ||
14 | #include <linux/pci.h> | ||
15 | #include <linux/delay.h> | ||
16 | #include <linux/hdreg.h> | ||
17 | #include <linux/ide.h> | ||
18 | #include <linux/bitops.h> | ||
19 | |||
20 | #include <asm/byteorder.h> | ||
21 | #include <asm/irq.h> | ||
22 | #include <asm/uaccess.h> | ||
23 | #include <asm/io.h> | ||
24 | |||
25 | /* | ||
26 | * IDE library routines. These are plug in code that most | ||
27 | * drivers can use but occasionally may be weird enough | ||
28 | * to want to do their own thing with | ||
29 | * | ||
30 | * Add common non I/O op stuff here. Make sure it has proper | ||
31 | * kernel-doc function headers or your patch will be rejected | ||
32 | */ | ||
33 | |||
34 | |||
35 | /** | ||
36 | * ide_xfer_verbose - return IDE mode names | ||
37 | * @xfer_rate: rate to name | ||
38 | * | ||
39 | * Returns a constant string giving the name of the mode | ||
40 | * requested. | ||
41 | */ | ||
42 | |||
43 | char *ide_xfer_verbose (u8 xfer_rate) | ||
44 | { | ||
45 | switch(xfer_rate) { | ||
46 | case XFER_UDMA_7: return("UDMA 7"); | ||
47 | case XFER_UDMA_6: return("UDMA 6"); | ||
48 | case XFER_UDMA_5: return("UDMA 5"); | ||
49 | case XFER_UDMA_4: return("UDMA 4"); | ||
50 | case XFER_UDMA_3: return("UDMA 3"); | ||
51 | case XFER_UDMA_2: return("UDMA 2"); | ||
52 | case XFER_UDMA_1: return("UDMA 1"); | ||
53 | case XFER_UDMA_0: return("UDMA 0"); | ||
54 | case XFER_MW_DMA_2: return("MW DMA 2"); | ||
55 | case XFER_MW_DMA_1: return("MW DMA 1"); | ||
56 | case XFER_MW_DMA_0: return("MW DMA 0"); | ||
57 | case XFER_SW_DMA_2: return("SW DMA 2"); | ||
58 | case XFER_SW_DMA_1: return("SW DMA 1"); | ||
59 | case XFER_SW_DMA_0: return("SW DMA 0"); | ||
60 | case XFER_PIO_4: return("PIO 4"); | ||
61 | case XFER_PIO_3: return("PIO 3"); | ||
62 | case XFER_PIO_2: return("PIO 2"); | ||
63 | case XFER_PIO_1: return("PIO 1"); | ||
64 | case XFER_PIO_0: return("PIO 0"); | ||
65 | case XFER_PIO_SLOW: return("PIO SLOW"); | ||
66 | default: return("XFER ERROR"); | ||
67 | } | ||
68 | } | ||
69 | |||
70 | EXPORT_SYMBOL(ide_xfer_verbose); | ||
71 | |||
72 | /** | ||
73 | * ide_dma_speed - compute DMA speed | ||
74 | * @drive: drive | ||
75 | * @mode; intended mode | ||
76 | * | ||
77 | * Checks the drive capabilities and returns the speed to use | ||
78 | * for the transfer. Returns -1 if the requested mode is unknown | ||
79 | * (eg PIO) | ||
80 | */ | ||
81 | |||
82 | u8 ide_dma_speed(ide_drive_t *drive, u8 mode) | ||
83 | { | ||
84 | struct hd_driveid *id = drive->id; | ||
85 | ide_hwif_t *hwif = HWIF(drive); | ||
86 | u8 speed = 0; | ||
87 | |||
88 | if (drive->media != ide_disk && hwif->atapi_dma == 0) | ||
89 | return 0; | ||
90 | |||
91 | switch(mode) { | ||
92 | case 0x04: | ||
93 | if ((id->dma_ultra & 0x0040) && | ||
94 | (id->dma_ultra & hwif->ultra_mask)) | ||
95 | { speed = XFER_UDMA_6; break; } | ||
96 | case 0x03: | ||
97 | if ((id->dma_ultra & 0x0020) && | ||
98 | (id->dma_ultra & hwif->ultra_mask)) | ||
99 | { speed = XFER_UDMA_5; break; } | ||
100 | case 0x02: | ||
101 | if ((id->dma_ultra & 0x0010) && | ||
102 | (id->dma_ultra & hwif->ultra_mask)) | ||
103 | { speed = XFER_UDMA_4; break; } | ||
104 | if ((id->dma_ultra & 0x0008) && | ||
105 | (id->dma_ultra & hwif->ultra_mask)) | ||
106 | { speed = XFER_UDMA_3; break; } | ||
107 | case 0x01: | ||
108 | if ((id->dma_ultra & 0x0004) && | ||
109 | (id->dma_ultra & hwif->ultra_mask)) | ||
110 | { speed = XFER_UDMA_2; break; } | ||
111 | if ((id->dma_ultra & 0x0002) && | ||
112 | (id->dma_ultra & hwif->ultra_mask)) | ||
113 | { speed = XFER_UDMA_1; break; } | ||
114 | if ((id->dma_ultra & 0x0001) && | ||
115 | (id->dma_ultra & hwif->ultra_mask)) | ||
116 | { speed = XFER_UDMA_0; break; } | ||
117 | case 0x00: | ||
118 | if ((id->dma_mword & 0x0004) && | ||
119 | (id->dma_mword & hwif->mwdma_mask)) | ||
120 | { speed = XFER_MW_DMA_2; break; } | ||
121 | if ((id->dma_mword & 0x0002) && | ||
122 | (id->dma_mword & hwif->mwdma_mask)) | ||
123 | { speed = XFER_MW_DMA_1; break; } | ||
124 | if ((id->dma_mword & 0x0001) && | ||
125 | (id->dma_mword & hwif->mwdma_mask)) | ||
126 | { speed = XFER_MW_DMA_0; break; } | ||
127 | if ((id->dma_1word & 0x0004) && | ||
128 | (id->dma_1word & hwif->swdma_mask)) | ||
129 | { speed = XFER_SW_DMA_2; break; } | ||
130 | if ((id->dma_1word & 0x0002) && | ||
131 | (id->dma_1word & hwif->swdma_mask)) | ||
132 | { speed = XFER_SW_DMA_1; break; } | ||
133 | if ((id->dma_1word & 0x0001) && | ||
134 | (id->dma_1word & hwif->swdma_mask)) | ||
135 | { speed = XFER_SW_DMA_0; break; } | ||
136 | } | ||
137 | |||
138 | // printk("%s: %s: mode 0x%02x, speed 0x%02x\n", | ||
139 | // __FUNCTION__, drive->name, mode, speed); | ||
140 | |||
141 | return speed; | ||
142 | } | ||
143 | |||
144 | EXPORT_SYMBOL(ide_dma_speed); | ||
145 | |||
146 | |||
147 | /** | ||
148 | * ide_rate_filter - return best speed for mode | ||
149 | * @mode: modes available | ||
150 | * @speed: desired speed | ||
151 | * | ||
152 | * Given the available DMA/UDMA mode this function returns | ||
153 | * the best available speed at or below the speed requested. | ||
154 | */ | ||
155 | |||
156 | u8 ide_rate_filter (u8 mode, u8 speed) | ||
157 | { | ||
158 | #ifdef CONFIG_BLK_DEV_IDEDMA | ||
159 | static u8 speed_max[] = { | ||
160 | XFER_MW_DMA_2, XFER_UDMA_2, XFER_UDMA_4, | ||
161 | XFER_UDMA_5, XFER_UDMA_6 | ||
162 | }; | ||
163 | |||
164 | // printk("%s: mode 0x%02x, speed 0x%02x\n", __FUNCTION__, mode, speed); | ||
165 | |||
166 | /* So that we remember to update this if new modes appear */ | ||
167 | if (mode > 4) | ||
168 | BUG(); | ||
169 | return min(speed, speed_max[mode]); | ||
170 | #else /* !CONFIG_BLK_DEV_IDEDMA */ | ||
171 | return min(speed, (u8)XFER_PIO_4); | ||
172 | #endif /* CONFIG_BLK_DEV_IDEDMA */ | ||
173 | } | ||
174 | |||
175 | EXPORT_SYMBOL(ide_rate_filter); | ||
176 | |||
177 | int ide_dma_enable (ide_drive_t *drive) | ||
178 | { | ||
179 | ide_hwif_t *hwif = HWIF(drive); | ||
180 | struct hd_driveid *id = drive->id; | ||
181 | |||
182 | return ((int) ((((id->dma_ultra >> 8) & hwif->ultra_mask) || | ||
183 | ((id->dma_mword >> 8) & hwif->mwdma_mask) || | ||
184 | ((id->dma_1word >> 8) & hwif->swdma_mask)) ? 1 : 0)); | ||
185 | } | ||
186 | |||
187 | EXPORT_SYMBOL(ide_dma_enable); | ||
188 | |||
189 | /* | ||
190 | * Standard (generic) timings for PIO modes, from ATA2 specification. | ||
191 | * These timings are for access to the IDE data port register *only*. | ||
192 | * Some drives may specify a mode, while also specifying a different | ||
193 | * value for cycle_time (from drive identification data). | ||
194 | */ | ||
195 | const ide_pio_timings_t ide_pio_timings[6] = { | ||
196 | { 70, 165, 600 }, /* PIO Mode 0 */ | ||
197 | { 50, 125, 383 }, /* PIO Mode 1 */ | ||
198 | { 30, 100, 240 }, /* PIO Mode 2 */ | ||
199 | { 30, 80, 180 }, /* PIO Mode 3 with IORDY */ | ||
200 | { 25, 70, 120 }, /* PIO Mode 4 with IORDY */ | ||
201 | { 20, 50, 100 } /* PIO Mode 5 with IORDY (nonstandard) */ | ||
202 | }; | ||
203 | |||
204 | EXPORT_SYMBOL_GPL(ide_pio_timings); | ||
205 | |||
206 | /* | ||
207 | * Shared data/functions for determining best PIO mode for an IDE drive. | ||
208 | * Most of this stuff originally lived in cmd640.c, and changes to the | ||
209 | * ide_pio_blacklist[] table should be made with EXTREME CAUTION to avoid | ||
210 | * breaking the fragile cmd640.c support. | ||
211 | */ | ||
212 | |||
213 | /* | ||
214 | * Black list. Some drives incorrectly report their maximal PIO mode, | ||
215 | * at least in respect to CMD640. Here we keep info on some known drives. | ||
216 | */ | ||
217 | static struct ide_pio_info { | ||
218 | const char *name; | ||
219 | int pio; | ||
220 | } ide_pio_blacklist [] = { | ||
221 | /* { "Conner Peripherals 1275MB - CFS1275A", 4 }, */ | ||
222 | { "Conner Peripherals 540MB - CFS540A", 3 }, | ||
223 | |||
224 | { "WDC AC2700", 3 }, | ||
225 | { "WDC AC2540", 3 }, | ||
226 | { "WDC AC2420", 3 }, | ||
227 | { "WDC AC2340", 3 }, | ||
228 | { "WDC AC2250", 0 }, | ||
229 | { "WDC AC2200", 0 }, | ||
230 | { "WDC AC21200", 4 }, | ||
231 | { "WDC AC2120", 0 }, | ||
232 | { "WDC AC2850", 3 }, | ||
233 | { "WDC AC1270", 3 }, | ||
234 | { "WDC AC1170", 1 }, | ||
235 | { "WDC AC1210", 1 }, | ||
236 | { "WDC AC280", 0 }, | ||
237 | /* { "WDC AC21000", 4 }, */ | ||
238 | { "WDC AC31000", 3 }, | ||
239 | { "WDC AC31200", 3 }, | ||
240 | /* { "WDC AC31600", 4 }, */ | ||
241 | |||
242 | { "Maxtor 7131 AT", 1 }, | ||
243 | { "Maxtor 7171 AT", 1 }, | ||
244 | { "Maxtor 7213 AT", 1 }, | ||
245 | { "Maxtor 7245 AT", 1 }, | ||
246 | { "Maxtor 7345 AT", 1 }, | ||
247 | { "Maxtor 7546 AT", 3 }, | ||
248 | { "Maxtor 7540 AV", 3 }, | ||
249 | |||
250 | { "SAMSUNG SHD-3121A", 1 }, | ||
251 | { "SAMSUNG SHD-3122A", 1 }, | ||
252 | { "SAMSUNG SHD-3172A", 1 }, | ||
253 | |||
254 | /* { "ST51080A", 4 }, | ||
255 | * { "ST51270A", 4 }, | ||
256 | * { "ST31220A", 4 }, | ||
257 | * { "ST31640A", 4 }, | ||
258 | * { "ST32140A", 4 }, | ||
259 | * { "ST3780A", 4 }, | ||
260 | */ | ||
261 | { "ST5660A", 3 }, | ||
262 | { "ST3660A", 3 }, | ||
263 | { "ST3630A", 3 }, | ||
264 | { "ST3655A", 3 }, | ||
265 | { "ST3391A", 3 }, | ||
266 | { "ST3390A", 1 }, | ||
267 | { "ST3600A", 1 }, | ||
268 | { "ST3290A", 0 }, | ||
269 | { "ST3144A", 0 }, | ||
270 | { "ST3491A", 1 }, /* reports 3, should be 1 or 2 (depending on */ | ||
271 | /* drive) according to Seagates FIND-ATA program */ | ||
272 | |||
273 | { "QUANTUM ELS127A", 0 }, | ||
274 | { "QUANTUM ELS170A", 0 }, | ||
275 | { "QUANTUM LPS240A", 0 }, | ||
276 | { "QUANTUM LPS210A", 3 }, | ||
277 | { "QUANTUM LPS270A", 3 }, | ||
278 | { "QUANTUM LPS365A", 3 }, | ||
279 | { "QUANTUM LPS540A", 3 }, | ||
280 | { "QUANTUM LIGHTNING 540A", 3 }, | ||
281 | { "QUANTUM LIGHTNING 730A", 3 }, | ||
282 | |||
283 | { "QUANTUM FIREBALL_540", 3 }, /* Older Quantum Fireballs don't work */ | ||
284 | { "QUANTUM FIREBALL_640", 3 }, | ||
285 | { "QUANTUM FIREBALL_1080", 3 }, | ||
286 | { "QUANTUM FIREBALL_1280", 3 }, | ||
287 | { NULL, 0 } | ||
288 | }; | ||
289 | |||
290 | /** | ||
291 | * ide_scan_pio_blacklist - check for a blacklisted drive | ||
292 | * @model: Drive model string | ||
293 | * | ||
294 | * This routine searches the ide_pio_blacklist for an entry | ||
295 | * matching the start/whole of the supplied model name. | ||
296 | * | ||
297 | * Returns -1 if no match found. | ||
298 | * Otherwise returns the recommended PIO mode from ide_pio_blacklist[]. | ||
299 | */ | ||
300 | |||
301 | static int ide_scan_pio_blacklist (char *model) | ||
302 | { | ||
303 | struct ide_pio_info *p; | ||
304 | |||
305 | for (p = ide_pio_blacklist; p->name != NULL; p++) { | ||
306 | if (strncmp(p->name, model, strlen(p->name)) == 0) | ||
307 | return p->pio; | ||
308 | } | ||
309 | return -1; | ||
310 | } | ||
311 | |||
312 | /** | ||
313 | * ide_get_best_pio_mode - get PIO mode from drive | ||
314 | * @driver: drive to consider | ||
315 | * @mode_wanted: preferred mode | ||
316 | * @max_mode: highest allowed | ||
317 | * @d: pio data | ||
318 | * | ||
319 | * This routine returns the recommended PIO settings for a given drive, | ||
320 | * based on the drive->id information and the ide_pio_blacklist[]. | ||
321 | * This is used by most chipset support modules when "auto-tuning". | ||
322 | * | ||
323 | * Drive PIO mode auto selection | ||
324 | */ | ||
325 | |||
326 | u8 ide_get_best_pio_mode (ide_drive_t *drive, u8 mode_wanted, u8 max_mode, ide_pio_data_t *d) | ||
327 | { | ||
328 | int pio_mode; | ||
329 | int cycle_time = 0; | ||
330 | int use_iordy = 0; | ||
331 | struct hd_driveid* id = drive->id; | ||
332 | int overridden = 0; | ||
333 | int blacklisted = 0; | ||
334 | |||
335 | if (mode_wanted != 255) { | ||
336 | pio_mode = mode_wanted; | ||
337 | } else if (!drive->id) { | ||
338 | pio_mode = 0; | ||
339 | } else if ((pio_mode = ide_scan_pio_blacklist(id->model)) != -1) { | ||
340 | overridden = 1; | ||
341 | blacklisted = 1; | ||
342 | use_iordy = (pio_mode > 2); | ||
343 | } else { | ||
344 | pio_mode = id->tPIO; | ||
345 | if (pio_mode > 2) { /* 2 is maximum allowed tPIO value */ | ||
346 | pio_mode = 2; | ||
347 | overridden = 1; | ||
348 | } | ||
349 | if (id->field_valid & 2) { /* drive implements ATA2? */ | ||
350 | if (id->capability & 8) { /* drive supports use_iordy? */ | ||
351 | use_iordy = 1; | ||
352 | cycle_time = id->eide_pio_iordy; | ||
353 | if (id->eide_pio_modes & 7) { | ||
354 | overridden = 0; | ||
355 | if (id->eide_pio_modes & 4) | ||
356 | pio_mode = 5; | ||
357 | else if (id->eide_pio_modes & 2) | ||
358 | pio_mode = 4; | ||
359 | else | ||
360 | pio_mode = 3; | ||
361 | } | ||
362 | } else { | ||
363 | cycle_time = id->eide_pio; | ||
364 | } | ||
365 | } | ||
366 | |||
367 | #if 0 | ||
368 | if (drive->id->major_rev_num & 0x0004) printk("ATA-2 "); | ||
369 | #endif | ||
370 | |||
371 | /* | ||
372 | * Conservative "downgrade" for all pre-ATA2 drives | ||
373 | */ | ||
374 | if (pio_mode && pio_mode < 4) { | ||
375 | pio_mode--; | ||
376 | overridden = 1; | ||
377 | #if 0 | ||
378 | use_iordy = (pio_mode > 2); | ||
379 | #endif | ||
380 | if (cycle_time && cycle_time < ide_pio_timings[pio_mode].cycle_time) | ||
381 | cycle_time = 0; /* use standard timing */ | ||
382 | } | ||
383 | } | ||
384 | if (pio_mode > max_mode) { | ||
385 | pio_mode = max_mode; | ||
386 | cycle_time = 0; | ||
387 | } | ||
388 | if (d) { | ||
389 | d->pio_mode = pio_mode; | ||
390 | d->cycle_time = cycle_time ? cycle_time : ide_pio_timings[pio_mode].cycle_time; | ||
391 | d->use_iordy = use_iordy; | ||
392 | d->overridden = overridden; | ||
393 | d->blacklisted = blacklisted; | ||
394 | } | ||
395 | return pio_mode; | ||
396 | } | ||
397 | |||
398 | EXPORT_SYMBOL_GPL(ide_get_best_pio_mode); | ||
399 | |||
400 | /** | ||
401 | * ide_toggle_bounce - handle bounce buffering | ||
402 | * @drive: drive to update | ||
403 | * @on: on/off boolean | ||
404 | * | ||
405 | * Enable or disable bounce buffering for the device. Drives move | ||
406 | * between PIO and DMA and that changes the rules we need. | ||
407 | */ | ||
408 | |||
409 | void ide_toggle_bounce(ide_drive_t *drive, int on) | ||
410 | { | ||
411 | u64 addr = BLK_BOUNCE_HIGH; /* dma64_addr_t */ | ||
412 | |||
413 | if (on && drive->media == ide_disk) { | ||
414 | if (!PCI_DMA_BUS_IS_PHYS) | ||
415 | addr = BLK_BOUNCE_ANY; | ||
416 | else if (HWIF(drive)->pci_dev) | ||
417 | addr = HWIF(drive)->pci_dev->dma_mask; | ||
418 | } | ||
419 | |||
420 | if (drive->queue) | ||
421 | blk_queue_bounce_limit(drive->queue, addr); | ||
422 | } | ||
423 | |||
424 | /** | ||
425 | * ide_set_xfer_rate - set transfer rate | ||
426 | * @drive: drive to set | ||
427 | * @speed: speed to attempt to set | ||
428 | * | ||
429 | * General helper for setting the speed of an IDE device. This | ||
430 | * function knows about user enforced limits from the configuration | ||
431 | * which speedproc() does not. High level drivers should never | ||
432 | * invoke speedproc() directly. | ||
433 | */ | ||
434 | |||
435 | int ide_set_xfer_rate(ide_drive_t *drive, u8 rate) | ||
436 | { | ||
437 | #ifndef CONFIG_BLK_DEV_IDEDMA | ||
438 | rate = min(rate, (u8) XFER_PIO_4); | ||
439 | #endif | ||
440 | if(HWIF(drive)->speedproc) | ||
441 | return HWIF(drive)->speedproc(drive, rate); | ||
442 | else | ||
443 | return -1; | ||
444 | } | ||
445 | |||
446 | EXPORT_SYMBOL_GPL(ide_set_xfer_rate); | ||
447 | |||
448 | static void ide_dump_opcode(ide_drive_t *drive) | ||
449 | { | ||
450 | struct request *rq; | ||
451 | u8 opcode = 0; | ||
452 | int found = 0; | ||
453 | |||
454 | spin_lock(&ide_lock); | ||
455 | rq = NULL; | ||
456 | if (HWGROUP(drive)) | ||
457 | rq = HWGROUP(drive)->rq; | ||
458 | spin_unlock(&ide_lock); | ||
459 | if (!rq) | ||
460 | return; | ||
461 | if (rq->flags & (REQ_DRIVE_CMD | REQ_DRIVE_TASK)) { | ||
462 | char *args = rq->buffer; | ||
463 | if (args) { | ||
464 | opcode = args[0]; | ||
465 | found = 1; | ||
466 | } | ||
467 | } else if (rq->flags & REQ_DRIVE_TASKFILE) { | ||
468 | ide_task_t *args = rq->special; | ||
469 | if (args) { | ||
470 | task_struct_t *tf = (task_struct_t *) args->tfRegister; | ||
471 | opcode = tf->command; | ||
472 | found = 1; | ||
473 | } | ||
474 | } | ||
475 | |||
476 | printk("ide: failed opcode was: "); | ||
477 | if (!found) | ||
478 | printk("unknown\n"); | ||
479 | else | ||
480 | printk("0x%02x\n", opcode); | ||
481 | } | ||
482 | |||
483 | static u8 ide_dump_ata_status(ide_drive_t *drive, const char *msg, u8 stat) | ||
484 | { | ||
485 | ide_hwif_t *hwif = HWIF(drive); | ||
486 | unsigned long flags; | ||
487 | u8 err = 0; | ||
488 | |||
489 | local_irq_set(flags); | ||
490 | printk("%s: %s: status=0x%02x", drive->name, msg, stat); | ||
491 | printk(" { "); | ||
492 | if (stat & BUSY_STAT) | ||
493 | printk("Busy "); | ||
494 | else { | ||
495 | if (stat & READY_STAT) printk("DriveReady "); | ||
496 | if (stat & WRERR_STAT) printk("DeviceFault "); | ||
497 | if (stat & SEEK_STAT) printk("SeekComplete "); | ||
498 | if (stat & DRQ_STAT) printk("DataRequest "); | ||
499 | if (stat & ECC_STAT) printk("CorrectedError "); | ||
500 | if (stat & INDEX_STAT) printk("Index "); | ||
501 | if (stat & ERR_STAT) printk("Error "); | ||
502 | } | ||
503 | printk("}"); | ||
504 | printk("\n"); | ||
505 | if ((stat & (BUSY_STAT|ERR_STAT)) == ERR_STAT) { | ||
506 | err = hwif->INB(IDE_ERROR_REG); | ||
507 | printk("%s: %s: error=0x%02x", drive->name, msg, err); | ||
508 | printk(" { "); | ||
509 | if (err & ABRT_ERR) printk("DriveStatusError "); | ||
510 | if (err & ICRC_ERR) | ||
511 | printk("Bad%s ", (err & ABRT_ERR) ? "CRC" : "Sector"); | ||
512 | if (err & ECC_ERR) printk("UncorrectableError "); | ||
513 | if (err & ID_ERR) printk("SectorIdNotFound "); | ||
514 | if (err & TRK0_ERR) printk("TrackZeroNotFound "); | ||
515 | if (err & MARK_ERR) printk("AddrMarkNotFound "); | ||
516 | printk("}"); | ||
517 | if ((err & (BBD_ERR | ABRT_ERR)) == BBD_ERR || | ||
518 | (err & (ECC_ERR|ID_ERR|MARK_ERR))) { | ||
519 | if (drive->addressing == 1) { | ||
520 | __u64 sectors = 0; | ||
521 | u32 low = 0, high = 0; | ||
522 | low = ide_read_24(drive); | ||
523 | hwif->OUTB(drive->ctl|0x80, IDE_CONTROL_REG); | ||
524 | high = ide_read_24(drive); | ||
525 | sectors = ((__u64)high << 24) | low; | ||
526 | printk(", LBAsect=%llu, high=%d, low=%d", | ||
527 | (unsigned long long) sectors, | ||
528 | high, low); | ||
529 | } else { | ||
530 | u8 cur = hwif->INB(IDE_SELECT_REG); | ||
531 | if (cur & 0x40) { /* using LBA? */ | ||
532 | printk(", LBAsect=%ld", (unsigned long) | ||
533 | ((cur&0xf)<<24) | ||
534 | |(hwif->INB(IDE_HCYL_REG)<<16) | ||
535 | |(hwif->INB(IDE_LCYL_REG)<<8) | ||
536 | | hwif->INB(IDE_SECTOR_REG)); | ||
537 | } else { | ||
538 | printk(", CHS=%d/%d/%d", | ||
539 | (hwif->INB(IDE_HCYL_REG)<<8) + | ||
540 | hwif->INB(IDE_LCYL_REG), | ||
541 | cur & 0xf, | ||
542 | hwif->INB(IDE_SECTOR_REG)); | ||
543 | } | ||
544 | } | ||
545 | if (HWGROUP(drive) && HWGROUP(drive)->rq) | ||
546 | printk(", sector=%llu", | ||
547 | (unsigned long long)HWGROUP(drive)->rq->sector); | ||
548 | } | ||
549 | } | ||
550 | printk("\n"); | ||
551 | ide_dump_opcode(drive); | ||
552 | local_irq_restore(flags); | ||
553 | return err; | ||
554 | } | ||
555 | |||
556 | /** | ||
557 | * ide_dump_atapi_status - print human readable atapi status | ||
558 | * @drive: drive that status applies to | ||
559 | * @msg: text message to print | ||
560 | * @stat: status byte to decode | ||
561 | * | ||
562 | * Error reporting, in human readable form (luxurious, but a memory hog). | ||
563 | */ | ||
564 | |||
565 | static u8 ide_dump_atapi_status(ide_drive_t *drive, const char *msg, u8 stat) | ||
566 | { | ||
567 | unsigned long flags; | ||
568 | |||
569 | atapi_status_t status; | ||
570 | atapi_error_t error; | ||
571 | |||
572 | status.all = stat; | ||
573 | error.all = 0; | ||
574 | local_irq_set(flags); | ||
575 | printk("%s: %s: status=0x%02x { ", drive->name, msg, stat); | ||
576 | if (status.b.bsy) | ||
577 | printk("Busy "); | ||
578 | else { | ||
579 | if (status.b.drdy) printk("DriveReady "); | ||
580 | if (status.b.df) printk("DeviceFault "); | ||
581 | if (status.b.dsc) printk("SeekComplete "); | ||
582 | if (status.b.drq) printk("DataRequest "); | ||
583 | if (status.b.corr) printk("CorrectedError "); | ||
584 | if (status.b.idx) printk("Index "); | ||
585 | if (status.b.check) printk("Error "); | ||
586 | } | ||
587 | printk("}\n"); | ||
588 | if (status.b.check && !status.b.bsy) { | ||
589 | error.all = HWIF(drive)->INB(IDE_ERROR_REG); | ||
590 | printk("%s: %s: error=0x%02x { ", drive->name, msg, error.all); | ||
591 | if (error.b.ili) printk("IllegalLengthIndication "); | ||
592 | if (error.b.eom) printk("EndOfMedia "); | ||
593 | if (error.b.abrt) printk("AbortedCommand "); | ||
594 | if (error.b.mcr) printk("MediaChangeRequested "); | ||
595 | if (error.b.sense_key) printk("LastFailedSense=0x%02x ", | ||
596 | error.b.sense_key); | ||
597 | printk("}\n"); | ||
598 | } | ||
599 | ide_dump_opcode(drive); | ||
600 | local_irq_restore(flags); | ||
601 | return error.all; | ||
602 | } | ||
603 | |||
604 | /** | ||
605 | * ide_dump_status - translate ATA/ATAPI error | ||
606 | * @drive: drive the error occured on | ||
607 | * @msg: information string | ||
608 | * @stat: status byte | ||
609 | * | ||
610 | * Error reporting, in human readable form (luxurious, but a memory hog). | ||
611 | * Combines the drive name, message and status byte to provide a | ||
612 | * user understandable explanation of the device error. | ||
613 | */ | ||
614 | |||
615 | u8 ide_dump_status(ide_drive_t *drive, const char *msg, u8 stat) | ||
616 | { | ||
617 | if (drive->media == ide_disk) | ||
618 | return ide_dump_ata_status(drive, msg, stat); | ||
619 | return ide_dump_atapi_status(drive, msg, stat); | ||
620 | } | ||
621 | |||
622 | EXPORT_SYMBOL(ide_dump_status); | ||
diff --git a/drivers/ide/ide-pnp.c b/drivers/ide/ide-pnp.c new file mode 100644 index 000000000000..df7d1504f84e --- /dev/null +++ b/drivers/ide/ide-pnp.c | |||
@@ -0,0 +1,75 @@ | |||
1 | /* | ||
2 | * linux/drivers/ide/ide-pnp.c | ||
3 | * | ||
4 | * This file provides autodetection for ISA PnP IDE interfaces. | ||
5 | * It was tested with "ESS ES1868 Plug and Play AudioDrive" IDE interface. | ||
6 | * | ||
7 | * Copyright (C) 2000 Andrey Panin <pazke@donpac.ru> | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or modify | ||
10 | * it under the terms of the GNU General Public License as published by | ||
11 | * the Free Software Foundation; either version 2, or (at your option) | ||
12 | * any later version. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License | ||
15 | * (for example /usr/src/linux/COPYING); if not, write to the Free | ||
16 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
17 | */ | ||
18 | |||
19 | #include <linux/init.h> | ||
20 | #include <linux/pnp.h> | ||
21 | #include <linux/ide.h> | ||
22 | |||
23 | /* Add your devices here :)) */ | ||
24 | static struct pnp_device_id idepnp_devices[] = { | ||
25 | /* Generic ESDI/IDE/ATA compatible hard disk controller */ | ||
26 | {.id = "PNP0600", .driver_data = 0}, | ||
27 | {.id = ""} | ||
28 | }; | ||
29 | |||
30 | static int idepnp_probe(struct pnp_dev * dev, const struct pnp_device_id *dev_id) | ||
31 | { | ||
32 | hw_regs_t hw; | ||
33 | ide_hwif_t *hwif; | ||
34 | int index; | ||
35 | |||
36 | if (!(pnp_port_valid(dev, 0) && pnp_port_valid(dev, 1) && pnp_irq_valid(dev, 0))) | ||
37 | return -1; | ||
38 | |||
39 | memset(&hw, 0, sizeof(hw)); | ||
40 | ide_std_init_ports(&hw, pnp_port_start(dev, 0), | ||
41 | pnp_port_start(dev, 1)); | ||
42 | hw.irq = pnp_irq(dev, 0); | ||
43 | hw.dma = NO_DMA; | ||
44 | |||
45 | index = ide_register_hw(&hw, &hwif); | ||
46 | |||
47 | if (index != -1) { | ||
48 | printk(KERN_INFO "ide%d: generic PnP IDE interface\n", index); | ||
49 | pnp_set_drvdata(dev,hwif); | ||
50 | return 0; | ||
51 | } | ||
52 | |||
53 | return -1; | ||
54 | } | ||
55 | |||
56 | static void idepnp_remove(struct pnp_dev * dev) | ||
57 | { | ||
58 | ide_hwif_t *hwif = pnp_get_drvdata(dev); | ||
59 | if (hwif) { | ||
60 | ide_unregister(hwif->index); | ||
61 | } else | ||
62 | printk(KERN_ERR "idepnp: Unable to remove device, please report.\n"); | ||
63 | } | ||
64 | |||
65 | static struct pnp_driver idepnp_driver = { | ||
66 | .name = "ide", | ||
67 | .id_table = idepnp_devices, | ||
68 | .probe = idepnp_probe, | ||
69 | .remove = idepnp_remove, | ||
70 | }; | ||
71 | |||
72 | void __init pnpide_init(void) | ||
73 | { | ||
74 | pnp_register_driver(&idepnp_driver); | ||
75 | } | ||
diff --git a/drivers/ide/ide-probe.c b/drivers/ide/ide-probe.c new file mode 100644 index 000000000000..554473a95cf7 --- /dev/null +++ b/drivers/ide/ide-probe.c | |||
@@ -0,0 +1,1421 @@ | |||
1 | /* | ||
2 | * linux/drivers/ide/ide-probe.c Version 1.11 Mar 05, 2003 | ||
3 | * | ||
4 | * Copyright (C) 1994-1998 Linus Torvalds & authors (see below) | ||
5 | */ | ||
6 | |||
7 | /* | ||
8 | * Mostly written by Mark Lord <mlord@pobox.com> | ||
9 | * and Gadi Oxman <gadio@netvision.net.il> | ||
10 | * and Andre Hedrick <andre@linux-ide.org> | ||
11 | * | ||
12 | * See linux/MAINTAINERS for address of current maintainer. | ||
13 | * | ||
14 | * This is the IDE probe module, as evolved from hd.c and ide.c. | ||
15 | * | ||
16 | * Version 1.00 move drive probing code from ide.c to ide-probe.c | ||
17 | * Version 1.01 fix compilation problem for m68k | ||
18 | * Version 1.02 increase WAIT_PIDENTIFY to avoid CD-ROM locking at boot | ||
19 | * by Andrea Arcangeli | ||
20 | * Version 1.03 fix for (hwif->chipset == ide_4drives) | ||
21 | * Version 1.04 fixed buggy treatments of known flash memory cards | ||
22 | * | ||
23 | * Version 1.05 fix for (hwif->chipset == ide_pdc4030) | ||
24 | * added ide6/7/8/9 | ||
25 | * allowed for secondary flash card to be detectable | ||
26 | * with new flag : drive->ata_flash : 1; | ||
27 | * Version 1.06 stream line request queue and prep for cascade project. | ||
28 | * Version 1.07 max_sect <= 255; slower disks would get behind and | ||
29 | * then fall over when they get to 256. Paul G. | ||
30 | * Version 1.10 Update set for new IDE. drive->id is now always | ||
31 | * valid after probe time even with noprobe | ||
32 | */ | ||
33 | |||
34 | #undef REALLY_SLOW_IO /* most systems can safely undef this */ | ||
35 | |||
36 | #include <linux/config.h> | ||
37 | #include <linux/module.h> | ||
38 | #include <linux/types.h> | ||
39 | #include <linux/string.h> | ||
40 | #include <linux/kernel.h> | ||
41 | #include <linux/timer.h> | ||
42 | #include <linux/mm.h> | ||
43 | #include <linux/interrupt.h> | ||
44 | #include <linux/major.h> | ||
45 | #include <linux/errno.h> | ||
46 | #include <linux/genhd.h> | ||
47 | #include <linux/slab.h> | ||
48 | #include <linux/delay.h> | ||
49 | #include <linux/ide.h> | ||
50 | #include <linux/spinlock.h> | ||
51 | #include <linux/kmod.h> | ||
52 | #include <linux/pci.h> | ||
53 | |||
54 | #include <asm/byteorder.h> | ||
55 | #include <asm/irq.h> | ||
56 | #include <asm/uaccess.h> | ||
57 | #include <asm/io.h> | ||
58 | |||
59 | /** | ||
60 | * generic_id - add a generic drive id | ||
61 | * @drive: drive to make an ID block for | ||
62 | * | ||
63 | * Add a fake id field to the drive we are passed. This allows | ||
64 | * use to skip a ton of NULL checks (which people always miss) | ||
65 | * and make drive properties unconditional outside of this file | ||
66 | */ | ||
67 | |||
68 | static void generic_id(ide_drive_t *drive) | ||
69 | { | ||
70 | drive->id->cyls = drive->cyl; | ||
71 | drive->id->heads = drive->head; | ||
72 | drive->id->sectors = drive->sect; | ||
73 | drive->id->cur_cyls = drive->cyl; | ||
74 | drive->id->cur_heads = drive->head; | ||
75 | drive->id->cur_sectors = drive->sect; | ||
76 | } | ||
77 | |||
78 | static void ide_disk_init_chs(ide_drive_t *drive) | ||
79 | { | ||
80 | struct hd_driveid *id = drive->id; | ||
81 | |||
82 | /* Extract geometry if we did not already have one for the drive */ | ||
83 | if (!drive->cyl || !drive->head || !drive->sect) { | ||
84 | drive->cyl = drive->bios_cyl = id->cyls; | ||
85 | drive->head = drive->bios_head = id->heads; | ||
86 | drive->sect = drive->bios_sect = id->sectors; | ||
87 | } | ||
88 | |||
89 | /* Handle logical geometry translation by the drive */ | ||
90 | if ((id->field_valid & 1) && id->cur_cyls && | ||
91 | id->cur_heads && (id->cur_heads <= 16) && id->cur_sectors) { | ||
92 | drive->cyl = id->cur_cyls; | ||
93 | drive->head = id->cur_heads; | ||
94 | drive->sect = id->cur_sectors; | ||
95 | } | ||
96 | |||
97 | /* Use physical geometry if what we have still makes no sense */ | ||
98 | if (drive->head > 16 && id->heads && id->heads <= 16) { | ||
99 | drive->cyl = id->cyls; | ||
100 | drive->head = id->heads; | ||
101 | drive->sect = id->sectors; | ||
102 | } | ||
103 | } | ||
104 | |||
105 | static void ide_disk_init_mult_count(ide_drive_t *drive) | ||
106 | { | ||
107 | struct hd_driveid *id = drive->id; | ||
108 | |||
109 | drive->mult_count = 0; | ||
110 | if (id->max_multsect) { | ||
111 | #ifdef CONFIG_IDEDISK_MULTI_MODE | ||
112 | id->multsect = ((id->max_multsect/2) > 1) ? id->max_multsect : 0; | ||
113 | id->multsect_valid = id->multsect ? 1 : 0; | ||
114 | drive->mult_req = id->multsect_valid ? id->max_multsect : INITIAL_MULT_COUNT; | ||
115 | drive->special.b.set_multmode = drive->mult_req ? 1 : 0; | ||
116 | #else /* original, pre IDE-NFG, per request of AC */ | ||
117 | drive->mult_req = INITIAL_MULT_COUNT; | ||
118 | if (drive->mult_req > id->max_multsect) | ||
119 | drive->mult_req = id->max_multsect; | ||
120 | if (drive->mult_req || ((id->multsect_valid & 1) && id->multsect)) | ||
121 | drive->special.b.set_multmode = 1; | ||
122 | #endif | ||
123 | } | ||
124 | } | ||
125 | |||
126 | /** | ||
127 | * drive_is_flashcard - check for compact flash | ||
128 | * @drive: drive to check | ||
129 | * | ||
130 | * CompactFlash cards and their brethern pretend to be removable | ||
131 | * hard disks, except: | ||
132 | * (1) they never have a slave unit, and | ||
133 | * (2) they don't have doorlock mechanisms. | ||
134 | * This test catches them, and is invoked elsewhere when setting | ||
135 | * appropriate config bits. | ||
136 | * | ||
137 | * FIXME: This treatment is probably applicable for *all* PCMCIA (PC CARD) | ||
138 | * devices, so in linux 2.3.x we should change this to just treat all | ||
139 | * PCMCIA drives this way, and get rid of the model-name tests below | ||
140 | * (too big of an interface change for 2.4.x). | ||
141 | * At that time, we might also consider parameterizing the timeouts and | ||
142 | * retries, since these are MUCH faster than mechanical drives. -M.Lord | ||
143 | */ | ||
144 | |||
145 | static inline int drive_is_flashcard (ide_drive_t *drive) | ||
146 | { | ||
147 | struct hd_driveid *id = drive->id; | ||
148 | |||
149 | if (drive->removable) { | ||
150 | if (id->config == 0x848a) return 1; /* CompactFlash */ | ||
151 | if (!strncmp(id->model, "KODAK ATA_FLASH", 15) /* Kodak */ | ||
152 | || !strncmp(id->model, "Hitachi CV", 10) /* Hitachi */ | ||
153 | || !strncmp(id->model, "SunDisk SDCFB", 13) /* old SanDisk */ | ||
154 | || !strncmp(id->model, "SanDisk SDCFB", 13) /* SanDisk */ | ||
155 | || !strncmp(id->model, "HAGIWARA HPC", 12) /* Hagiwara */ | ||
156 | || !strncmp(id->model, "LEXAR ATA_FLASH", 15) /* Lexar */ | ||
157 | || !strncmp(id->model, "ATA_FLASH", 9)) /* Simple Tech */ | ||
158 | { | ||
159 | return 1; /* yes, it is a flash memory card */ | ||
160 | } | ||
161 | } | ||
162 | return 0; /* no, it is not a flash memory card */ | ||
163 | } | ||
164 | |||
165 | /** | ||
166 | * do_identify - identify a drive | ||
167 | * @drive: drive to identify | ||
168 | * @cmd: command used | ||
169 | * | ||
170 | * Called when we have issued a drive identify command to | ||
171 | * read and parse the results. This function is run with | ||
172 | * interrupts disabled. | ||
173 | */ | ||
174 | |||
175 | static inline void do_identify (ide_drive_t *drive, u8 cmd) | ||
176 | { | ||
177 | ide_hwif_t *hwif = HWIF(drive); | ||
178 | int bswap = 1; | ||
179 | struct hd_driveid *id; | ||
180 | |||
181 | id = drive->id; | ||
182 | /* read 512 bytes of id info */ | ||
183 | hwif->ata_input_data(drive, id, SECTOR_WORDS); | ||
184 | |||
185 | drive->id_read = 1; | ||
186 | local_irq_enable(); | ||
187 | ide_fix_driveid(id); | ||
188 | |||
189 | #if defined (CONFIG_SCSI_EATA_DMA) || defined (CONFIG_SCSI_EATA_PIO) || defined (CONFIG_SCSI_EATA) | ||
190 | /* | ||
191 | * EATA SCSI controllers do a hardware ATA emulation: | ||
192 | * Ignore them if there is a driver for them available. | ||
193 | */ | ||
194 | if ((id->model[0] == 'P' && id->model[1] == 'M') || | ||
195 | (id->model[0] == 'S' && id->model[1] == 'K')) { | ||
196 | printk("%s: EATA SCSI HBA %.10s\n", drive->name, id->model); | ||
197 | goto err_misc; | ||
198 | } | ||
199 | #endif /* CONFIG_SCSI_EATA_DMA || CONFIG_SCSI_EATA_PIO */ | ||
200 | |||
201 | /* | ||
202 | * WIN_IDENTIFY returns little-endian info, | ||
203 | * WIN_PIDENTIFY *usually* returns little-endian info. | ||
204 | */ | ||
205 | if (cmd == WIN_PIDENTIFY) { | ||
206 | if ((id->model[0] == 'N' && id->model[1] == 'E') /* NEC */ | ||
207 | || (id->model[0] == 'F' && id->model[1] == 'X') /* Mitsumi */ | ||
208 | || (id->model[0] == 'P' && id->model[1] == 'i'))/* Pioneer */ | ||
209 | /* Vertos drives may still be weird */ | ||
210 | bswap ^= 1; | ||
211 | } | ||
212 | ide_fixstring(id->model, sizeof(id->model), bswap); | ||
213 | ide_fixstring(id->fw_rev, sizeof(id->fw_rev), bswap); | ||
214 | ide_fixstring(id->serial_no, sizeof(id->serial_no), bswap); | ||
215 | |||
216 | if (strstr(id->model, "E X A B Y T E N E S T")) | ||
217 | goto err_misc; | ||
218 | |||
219 | /* we depend on this a lot! */ | ||
220 | id->model[sizeof(id->model)-1] = '\0'; | ||
221 | printk("%s: %s, ", drive->name, id->model); | ||
222 | drive->present = 1; | ||
223 | drive->dead = 0; | ||
224 | |||
225 | /* | ||
226 | * Check for an ATAPI device | ||
227 | */ | ||
228 | if (cmd == WIN_PIDENTIFY) { | ||
229 | u8 type = (id->config >> 8) & 0x1f; | ||
230 | printk("ATAPI "); | ||
231 | switch (type) { | ||
232 | case ide_floppy: | ||
233 | if (!strstr(id->model, "CD-ROM")) { | ||
234 | if (!strstr(id->model, "oppy") && | ||
235 | !strstr(id->model, "poyp") && | ||
236 | !strstr(id->model, "ZIP")) | ||
237 | printk("cdrom or floppy?, assuming "); | ||
238 | if (drive->media != ide_cdrom) { | ||
239 | printk ("FLOPPY"); | ||
240 | drive->removable = 1; | ||
241 | break; | ||
242 | } | ||
243 | } | ||
244 | /* Early cdrom models used zero */ | ||
245 | type = ide_cdrom; | ||
246 | case ide_cdrom: | ||
247 | drive->removable = 1; | ||
248 | #ifdef CONFIG_PPC | ||
249 | /* kludge for Apple PowerBook internal zip */ | ||
250 | if (!strstr(id->model, "CD-ROM") && | ||
251 | strstr(id->model, "ZIP")) { | ||
252 | printk ("FLOPPY"); | ||
253 | type = ide_floppy; | ||
254 | break; | ||
255 | } | ||
256 | #endif | ||
257 | printk ("CD/DVD-ROM"); | ||
258 | break; | ||
259 | case ide_tape: | ||
260 | printk ("TAPE"); | ||
261 | break; | ||
262 | case ide_optical: | ||
263 | printk ("OPTICAL"); | ||
264 | drive->removable = 1; | ||
265 | break; | ||
266 | default: | ||
267 | printk("UNKNOWN (type %d)", type); | ||
268 | break; | ||
269 | } | ||
270 | printk (" drive\n"); | ||
271 | drive->media = type; | ||
272 | /* an ATAPI device ignores DRDY */ | ||
273 | drive->ready_stat = 0; | ||
274 | return; | ||
275 | } | ||
276 | |||
277 | /* | ||
278 | * Not an ATAPI device: looks like a "regular" hard disk | ||
279 | */ | ||
280 | if (id->config & (1<<7)) | ||
281 | drive->removable = 1; | ||
282 | |||
283 | if (drive_is_flashcard(drive)) | ||
284 | drive->is_flash = 1; | ||
285 | drive->media = ide_disk; | ||
286 | printk("%s DISK drive\n", (drive->is_flash) ? "CFA" : "ATA" ); | ||
287 | QUIRK_LIST(drive); | ||
288 | return; | ||
289 | |||
290 | err_misc: | ||
291 | kfree(id); | ||
292 | drive->present = 0; | ||
293 | return; | ||
294 | } | ||
295 | |||
296 | /** | ||
297 | * actual_try_to_identify - send ata/atapi identify | ||
298 | * @drive: drive to identify | ||
299 | * @cmd: command to use | ||
300 | * | ||
301 | * try_to_identify() sends an ATA(PI) IDENTIFY request to a drive | ||
302 | * and waits for a response. It also monitors irqs while this is | ||
303 | * happening, in hope of automatically determining which one is | ||
304 | * being used by the interface. | ||
305 | * | ||
306 | * Returns: 0 device was identified | ||
307 | * 1 device timed-out (no response to identify request) | ||
308 | * 2 device aborted the command (refused to identify itself) | ||
309 | */ | ||
310 | |||
311 | static int actual_try_to_identify (ide_drive_t *drive, u8 cmd) | ||
312 | { | ||
313 | ide_hwif_t *hwif = HWIF(drive); | ||
314 | int rc; | ||
315 | unsigned long hd_status; | ||
316 | unsigned long timeout; | ||
317 | u8 s = 0, a = 0; | ||
318 | |||
319 | /* take a deep breath */ | ||
320 | msleep(50); | ||
321 | |||
322 | if (IDE_CONTROL_REG) { | ||
323 | a = hwif->INB(IDE_ALTSTATUS_REG); | ||
324 | s = hwif->INB(IDE_STATUS_REG); | ||
325 | if ((a ^ s) & ~INDEX_STAT) { | ||
326 | printk(KERN_INFO "%s: probing with STATUS(0x%02x) instead of " | ||
327 | "ALTSTATUS(0x%02x)\n", drive->name, s, a); | ||
328 | /* ancient Seagate drives, broken interfaces */ | ||
329 | hd_status = IDE_STATUS_REG; | ||
330 | } else { | ||
331 | /* use non-intrusive polling */ | ||
332 | hd_status = IDE_ALTSTATUS_REG; | ||
333 | } | ||
334 | } else | ||
335 | hd_status = IDE_STATUS_REG; | ||
336 | |||
337 | /* set features register for atapi | ||
338 | * identify command to be sure of reply | ||
339 | */ | ||
340 | if ((cmd == WIN_PIDENTIFY)) | ||
341 | /* disable dma & overlap */ | ||
342 | hwif->OUTB(0, IDE_FEATURE_REG); | ||
343 | |||
344 | /* ask drive for ID */ | ||
345 | hwif->OUTB(cmd, IDE_COMMAND_REG); | ||
346 | |||
347 | timeout = ((cmd == WIN_IDENTIFY) ? WAIT_WORSTCASE : WAIT_PIDENTIFY) / 2; | ||
348 | timeout += jiffies; | ||
349 | do { | ||
350 | if (time_after(jiffies, timeout)) { | ||
351 | /* drive timed-out */ | ||
352 | return 1; | ||
353 | } | ||
354 | /* give drive a breather */ | ||
355 | msleep(50); | ||
356 | } while ((hwif->INB(hd_status)) & BUSY_STAT); | ||
357 | |||
358 | /* wait for IRQ and DRQ_STAT */ | ||
359 | msleep(50); | ||
360 | if (OK_STAT((hwif->INB(IDE_STATUS_REG)), DRQ_STAT, BAD_R_STAT)) { | ||
361 | unsigned long flags; | ||
362 | |||
363 | /* local CPU only; some systems need this */ | ||
364 | local_irq_save(flags); | ||
365 | /* drive returned ID */ | ||
366 | do_identify(drive, cmd); | ||
367 | /* drive responded with ID */ | ||
368 | rc = 0; | ||
369 | /* clear drive IRQ */ | ||
370 | (void) hwif->INB(IDE_STATUS_REG); | ||
371 | local_irq_restore(flags); | ||
372 | } else { | ||
373 | /* drive refused ID */ | ||
374 | rc = 2; | ||
375 | } | ||
376 | return rc; | ||
377 | } | ||
378 | |||
379 | /** | ||
380 | * try_to_identify - try to identify a drive | ||
381 | * @drive: drive to probe | ||
382 | * @cmd: command to use | ||
383 | * | ||
384 | * Issue the identify command and then do IRQ probing to | ||
385 | * complete the identification when needed by finding the | ||
386 | * IRQ the drive is attached to | ||
387 | */ | ||
388 | |||
389 | static int try_to_identify (ide_drive_t *drive, u8 cmd) | ||
390 | { | ||
391 | ide_hwif_t *hwif = HWIF(drive); | ||
392 | int retval; | ||
393 | int autoprobe = 0; | ||
394 | unsigned long cookie = 0; | ||
395 | |||
396 | /* | ||
397 | * Disable device irq unless we need to | ||
398 | * probe for it. Otherwise we'll get spurious | ||
399 | * interrupts during the identify-phase that | ||
400 | * the irq handler isn't expecting. | ||
401 | */ | ||
402 | if (IDE_CONTROL_REG) { | ||
403 | u8 ctl = drive->ctl | 2; | ||
404 | if (!hwif->irq) { | ||
405 | autoprobe = 1; | ||
406 | cookie = probe_irq_on(); | ||
407 | /* enable device irq */ | ||
408 | ctl &= ~2; | ||
409 | } | ||
410 | hwif->OUTB(ctl, IDE_CONTROL_REG); | ||
411 | } | ||
412 | |||
413 | retval = actual_try_to_identify(drive, cmd); | ||
414 | |||
415 | if (autoprobe) { | ||
416 | int irq; | ||
417 | /* mask device irq */ | ||
418 | hwif->OUTB(drive->ctl|2, IDE_CONTROL_REG); | ||
419 | /* clear drive IRQ */ | ||
420 | (void) hwif->INB(IDE_STATUS_REG); | ||
421 | udelay(5); | ||
422 | irq = probe_irq_off(cookie); | ||
423 | if (!hwif->irq) { | ||
424 | if (irq > 0) { | ||
425 | hwif->irq = irq; | ||
426 | } else { | ||
427 | /* Mmmm.. multiple IRQs.. | ||
428 | * don't know which was ours | ||
429 | */ | ||
430 | printk("%s: IRQ probe failed (0x%lx)\n", | ||
431 | drive->name, cookie); | ||
432 | } | ||
433 | } | ||
434 | } | ||
435 | return retval; | ||
436 | } | ||
437 | |||
438 | |||
439 | /** | ||
440 | * do_probe - probe an IDE device | ||
441 | * @drive: drive to probe | ||
442 | * @cmd: command to use | ||
443 | * | ||
444 | * do_probe() has the difficult job of finding a drive if it exists, | ||
445 | * without getting hung up if it doesn't exist, without trampling on | ||
446 | * ethernet cards, and without leaving any IRQs dangling to haunt us later. | ||
447 | * | ||
448 | * If a drive is "known" to exist (from CMOS or kernel parameters), | ||
449 | * but does not respond right away, the probe will "hang in there" | ||
450 | * for the maximum wait time (about 30 seconds), otherwise it will | ||
451 | * exit much more quickly. | ||
452 | * | ||
453 | * Returns: 0 device was identified | ||
454 | * 1 device timed-out (no response to identify request) | ||
455 | * 2 device aborted the command (refused to identify itself) | ||
456 | * 3 bad status from device (possible for ATAPI drives) | ||
457 | * 4 probe was not attempted because failure was obvious | ||
458 | */ | ||
459 | |||
460 | static int do_probe (ide_drive_t *drive, u8 cmd) | ||
461 | { | ||
462 | int rc; | ||
463 | ide_hwif_t *hwif = HWIF(drive); | ||
464 | |||
465 | if (drive->present) { | ||
466 | /* avoid waiting for inappropriate probes */ | ||
467 | if ((drive->media != ide_disk) && (cmd == WIN_IDENTIFY)) | ||
468 | return 4; | ||
469 | } | ||
470 | #ifdef DEBUG | ||
471 | printk("probing for %s: present=%d, media=%d, probetype=%s\n", | ||
472 | drive->name, drive->present, drive->media, | ||
473 | (cmd == WIN_IDENTIFY) ? "ATA" : "ATAPI"); | ||
474 | #endif | ||
475 | |||
476 | /* needed for some systems | ||
477 | * (e.g. crw9624 as drive0 with disk as slave) | ||
478 | */ | ||
479 | msleep(50); | ||
480 | SELECT_DRIVE(drive); | ||
481 | msleep(50); | ||
482 | if (hwif->INB(IDE_SELECT_REG) != drive->select.all && !drive->present) { | ||
483 | if (drive->select.b.unit != 0) { | ||
484 | /* exit with drive0 selected */ | ||
485 | SELECT_DRIVE(&hwif->drives[0]); | ||
486 | /* allow BUSY_STAT to assert & clear */ | ||
487 | msleep(50); | ||
488 | } | ||
489 | /* no i/f present: mmm.. this should be a 4 -ml */ | ||
490 | return 3; | ||
491 | } | ||
492 | |||
493 | if (OK_STAT((hwif->INB(IDE_STATUS_REG)), READY_STAT, BUSY_STAT) || | ||
494 | drive->present || cmd == WIN_PIDENTIFY) { | ||
495 | /* send cmd and wait */ | ||
496 | if ((rc = try_to_identify(drive, cmd))) { | ||
497 | /* failed: try again */ | ||
498 | rc = try_to_identify(drive,cmd); | ||
499 | } | ||
500 | if (hwif->INB(IDE_STATUS_REG) == (BUSY_STAT|READY_STAT)) | ||
501 | return 4; | ||
502 | |||
503 | if ((rc == 1 && cmd == WIN_PIDENTIFY) && | ||
504 | ((drive->autotune == IDE_TUNE_DEFAULT) || | ||
505 | (drive->autotune == IDE_TUNE_AUTO))) { | ||
506 | unsigned long timeout; | ||
507 | printk("%s: no response (status = 0x%02x), " | ||
508 | "resetting drive\n", drive->name, | ||
509 | hwif->INB(IDE_STATUS_REG)); | ||
510 | msleep(50); | ||
511 | hwif->OUTB(drive->select.all, IDE_SELECT_REG); | ||
512 | msleep(50); | ||
513 | hwif->OUTB(WIN_SRST, IDE_COMMAND_REG); | ||
514 | timeout = jiffies; | ||
515 | while (((hwif->INB(IDE_STATUS_REG)) & BUSY_STAT) && | ||
516 | time_before(jiffies, timeout + WAIT_WORSTCASE)) | ||
517 | msleep(50); | ||
518 | rc = try_to_identify(drive, cmd); | ||
519 | } | ||
520 | if (rc == 1) | ||
521 | printk("%s: no response (status = 0x%02x)\n", | ||
522 | drive->name, hwif->INB(IDE_STATUS_REG)); | ||
523 | /* ensure drive irq is clear */ | ||
524 | (void) hwif->INB(IDE_STATUS_REG); | ||
525 | } else { | ||
526 | /* not present or maybe ATAPI */ | ||
527 | rc = 3; | ||
528 | } | ||
529 | if (drive->select.b.unit != 0) { | ||
530 | /* exit with drive0 selected */ | ||
531 | SELECT_DRIVE(&hwif->drives[0]); | ||
532 | msleep(50); | ||
533 | /* ensure drive irq is clear */ | ||
534 | (void) hwif->INB(IDE_STATUS_REG); | ||
535 | } | ||
536 | return rc; | ||
537 | } | ||
538 | |||
539 | /* | ||
540 | * | ||
541 | */ | ||
542 | static void enable_nest (ide_drive_t *drive) | ||
543 | { | ||
544 | ide_hwif_t *hwif = HWIF(drive); | ||
545 | unsigned long timeout; | ||
546 | |||
547 | printk("%s: enabling %s -- ", hwif->name, drive->id->model); | ||
548 | SELECT_DRIVE(drive); | ||
549 | msleep(50); | ||
550 | hwif->OUTB(EXABYTE_ENABLE_NEST, IDE_COMMAND_REG); | ||
551 | timeout = jiffies + WAIT_WORSTCASE; | ||
552 | do { | ||
553 | if (time_after(jiffies, timeout)) { | ||
554 | printk("failed (timeout)\n"); | ||
555 | return; | ||
556 | } | ||
557 | msleep(50); | ||
558 | } while ((hwif->INB(IDE_STATUS_REG)) & BUSY_STAT); | ||
559 | |||
560 | msleep(50); | ||
561 | |||
562 | if (!OK_STAT((hwif->INB(IDE_STATUS_REG)), 0, BAD_STAT)) { | ||
563 | printk("failed (status = 0x%02x)\n", hwif->INB(IDE_STATUS_REG)); | ||
564 | } else { | ||
565 | printk("success\n"); | ||
566 | } | ||
567 | |||
568 | /* if !(success||timed-out) */ | ||
569 | if (do_probe(drive, WIN_IDENTIFY) >= 2) { | ||
570 | /* look for ATAPI device */ | ||
571 | (void) do_probe(drive, WIN_PIDENTIFY); | ||
572 | } | ||
573 | } | ||
574 | |||
575 | /** | ||
576 | * probe_for_drives - upper level drive probe | ||
577 | * @drive: drive to probe for | ||
578 | * | ||
579 | * probe_for_drive() tests for existence of a given drive using do_probe() | ||
580 | * and presents things to the user as needed. | ||
581 | * | ||
582 | * Returns: 0 no device was found | ||
583 | * 1 device was found (note: drive->present might | ||
584 | * still be 0) | ||
585 | */ | ||
586 | |||
587 | static inline u8 probe_for_drive (ide_drive_t *drive) | ||
588 | { | ||
589 | /* | ||
590 | * In order to keep things simple we have an id | ||
591 | * block for all drives at all times. If the device | ||
592 | * is pre ATA or refuses ATA/ATAPI identify we | ||
593 | * will add faked data to this. | ||
594 | * | ||
595 | * Also note that 0 everywhere means "can't do X" | ||
596 | */ | ||
597 | |||
598 | drive->id = kmalloc(SECTOR_WORDS *4, GFP_KERNEL); | ||
599 | drive->id_read = 0; | ||
600 | if(drive->id == NULL) | ||
601 | { | ||
602 | printk(KERN_ERR "ide: out of memory for id data.\n"); | ||
603 | return 0; | ||
604 | } | ||
605 | memset(drive->id, 0, SECTOR_WORDS * 4); | ||
606 | strcpy(drive->id->model, "UNKNOWN"); | ||
607 | |||
608 | /* skip probing? */ | ||
609 | if (!drive->noprobe) | ||
610 | { | ||
611 | /* if !(success||timed-out) */ | ||
612 | if (do_probe(drive, WIN_IDENTIFY) >= 2) { | ||
613 | /* look for ATAPI device */ | ||
614 | (void) do_probe(drive, WIN_PIDENTIFY); | ||
615 | } | ||
616 | if (strstr(drive->id->model, "E X A B Y T E N E S T")) | ||
617 | enable_nest(drive); | ||
618 | if (!drive->present) | ||
619 | /* drive not found */ | ||
620 | return 0; | ||
621 | |||
622 | /* identification failed? */ | ||
623 | if (!drive->id_read) { | ||
624 | if (drive->media == ide_disk) { | ||
625 | printk(KERN_INFO "%s: non-IDE drive, CHS=%d/%d/%d\n", | ||
626 | drive->name, drive->cyl, | ||
627 | drive->head, drive->sect); | ||
628 | } else if (drive->media == ide_cdrom) { | ||
629 | printk(KERN_INFO "%s: ATAPI cdrom (?)\n", drive->name); | ||
630 | } else { | ||
631 | /* nuke it */ | ||
632 | printk(KERN_WARNING "%s: Unknown device on bus refused identification. Ignoring.\n", drive->name); | ||
633 | drive->present = 0; | ||
634 | } | ||
635 | } | ||
636 | /* drive was found */ | ||
637 | } | ||
638 | if(!drive->present) | ||
639 | return 0; | ||
640 | /* The drive wasn't being helpful. Add generic info only */ | ||
641 | if (drive->id_read == 0) { | ||
642 | generic_id(drive); | ||
643 | return 1; | ||
644 | } | ||
645 | |||
646 | if (drive->media == ide_disk) { | ||
647 | ide_disk_init_chs(drive); | ||
648 | ide_disk_init_mult_count(drive); | ||
649 | } | ||
650 | |||
651 | return drive->present; | ||
652 | } | ||
653 | |||
654 | static void hwif_release_dev (struct device *dev) | ||
655 | { | ||
656 | ide_hwif_t *hwif = container_of(dev, ide_hwif_t, gendev); | ||
657 | |||
658 | up(&hwif->gendev_rel_sem); | ||
659 | } | ||
660 | |||
661 | static void hwif_register (ide_hwif_t *hwif) | ||
662 | { | ||
663 | /* register with global device tree */ | ||
664 | strlcpy(hwif->gendev.bus_id,hwif->name,BUS_ID_SIZE); | ||
665 | hwif->gendev.driver_data = hwif; | ||
666 | if (hwif->gendev.parent == NULL) { | ||
667 | if (hwif->pci_dev) | ||
668 | hwif->gendev.parent = &hwif->pci_dev->dev; | ||
669 | else | ||
670 | /* Would like to do = &device_legacy */ | ||
671 | hwif->gendev.parent = NULL; | ||
672 | } | ||
673 | hwif->gendev.release = hwif_release_dev; | ||
674 | device_register(&hwif->gendev); | ||
675 | } | ||
676 | |||
677 | static int wait_hwif_ready(ide_hwif_t *hwif) | ||
678 | { | ||
679 | int rc; | ||
680 | |||
681 | printk(KERN_DEBUG "Probing IDE interface %s...\n", hwif->name); | ||
682 | |||
683 | /* Let HW settle down a bit from whatever init state we | ||
684 | * come from */ | ||
685 | mdelay(2); | ||
686 | |||
687 | /* Wait for BSY bit to go away, spec timeout is 30 seconds, | ||
688 | * I know of at least one disk who takes 31 seconds, I use 35 | ||
689 | * here to be safe | ||
690 | */ | ||
691 | rc = ide_wait_not_busy(hwif, 35000); | ||
692 | if (rc) | ||
693 | return rc; | ||
694 | |||
695 | /* Now make sure both master & slave are ready */ | ||
696 | SELECT_DRIVE(&hwif->drives[0]); | ||
697 | hwif->OUTB(8, hwif->io_ports[IDE_CONTROL_OFFSET]); | ||
698 | mdelay(2); | ||
699 | rc = ide_wait_not_busy(hwif, 10000); | ||
700 | if (rc) | ||
701 | return rc; | ||
702 | SELECT_DRIVE(&hwif->drives[1]); | ||
703 | hwif->OUTB(8, hwif->io_ports[IDE_CONTROL_OFFSET]); | ||
704 | mdelay(2); | ||
705 | rc = ide_wait_not_busy(hwif, 10000); | ||
706 | |||
707 | /* Exit function with master reselected (let's be sane) */ | ||
708 | SELECT_DRIVE(&hwif->drives[0]); | ||
709 | |||
710 | return rc; | ||
711 | } | ||
712 | |||
713 | /** | ||
714 | * ide_undecoded_slave - look for bad CF adapters | ||
715 | * @hwif: interface | ||
716 | * | ||
717 | * Analyse the drives on the interface and attempt to decide if we | ||
718 | * have the same drive viewed twice. This occurs with crap CF adapters | ||
719 | * and PCMCIA sometimes. | ||
720 | */ | ||
721 | |||
722 | void ide_undecoded_slave(ide_hwif_t *hwif) | ||
723 | { | ||
724 | ide_drive_t *drive0 = &hwif->drives[0]; | ||
725 | ide_drive_t *drive1 = &hwif->drives[1]; | ||
726 | |||
727 | if (drive0->present == 0 || drive1->present == 0) | ||
728 | return; | ||
729 | |||
730 | /* If the models don't match they are not the same product */ | ||
731 | if (strcmp(drive0->id->model, drive1->id->model)) | ||
732 | return; | ||
733 | |||
734 | /* Serial numbers do not match */ | ||
735 | if (strncmp(drive0->id->serial_no, drive1->id->serial_no, 20)) | ||
736 | return; | ||
737 | |||
738 | /* No serial number, thankfully very rare for CF */ | ||
739 | if (drive0->id->serial_no[0] == 0) | ||
740 | return; | ||
741 | |||
742 | /* Appears to be an IDE flash adapter with decode bugs */ | ||
743 | printk(KERN_WARNING "ide-probe: ignoring undecoded slave\n"); | ||
744 | |||
745 | drive1->present = 0; | ||
746 | } | ||
747 | |||
748 | EXPORT_SYMBOL_GPL(ide_undecoded_slave); | ||
749 | |||
750 | /* | ||
751 | * This routine only knows how to look for drive units 0 and 1 | ||
752 | * on an interface, so any setting of MAX_DRIVES > 2 won't work here. | ||
753 | */ | ||
754 | static void probe_hwif(ide_hwif_t *hwif) | ||
755 | { | ||
756 | unsigned int unit; | ||
757 | unsigned long flags; | ||
758 | unsigned int irqd; | ||
759 | |||
760 | if (hwif->noprobe) | ||
761 | return; | ||
762 | |||
763 | if ((hwif->chipset != ide_4drives || !hwif->mate || !hwif->mate->present) && | ||
764 | (ide_hwif_request_regions(hwif))) { | ||
765 | u16 msgout = 0; | ||
766 | for (unit = 0; unit < MAX_DRIVES; ++unit) { | ||
767 | ide_drive_t *drive = &hwif->drives[unit]; | ||
768 | if (drive->present) { | ||
769 | drive->present = 0; | ||
770 | printk(KERN_ERR "%s: ERROR, PORTS ALREADY IN USE\n", | ||
771 | drive->name); | ||
772 | msgout = 1; | ||
773 | } | ||
774 | } | ||
775 | if (!msgout) | ||
776 | printk(KERN_ERR "%s: ports already in use, skipping probe\n", | ||
777 | hwif->name); | ||
778 | return; | ||
779 | } | ||
780 | |||
781 | /* | ||
782 | * We must always disable IRQ, as probe_for_drive will assert IRQ, but | ||
783 | * we'll install our IRQ driver much later... | ||
784 | */ | ||
785 | irqd = hwif->irq; | ||
786 | if (irqd) | ||
787 | disable_irq(hwif->irq); | ||
788 | |||
789 | local_irq_set(flags); | ||
790 | |||
791 | /* This is needed on some PPCs and a bunch of BIOS-less embedded | ||
792 | * platforms. Typical cases are: | ||
793 | * | ||
794 | * - The firmware hard reset the disk before booting the kernel, | ||
795 | * the drive is still doing it's poweron-reset sequence, that | ||
796 | * can take up to 30 seconds | ||
797 | * - The firmware does nothing (or no firmware), the device is | ||
798 | * still in POST state (same as above actually). | ||
799 | * - Some CD/DVD/Writer combo drives tend to drive the bus during | ||
800 | * their reset sequence even when they are non-selected slave | ||
801 | * devices, thus preventing discovery of the main HD | ||
802 | * | ||
803 | * Doing this wait-for-busy should not harm any existing configuration | ||
804 | * (at least things won't be worse than what current code does, that | ||
805 | * is blindly go & talk to the drive) and fix some issues like the | ||
806 | * above. | ||
807 | * | ||
808 | * BenH. | ||
809 | */ | ||
810 | if (wait_hwif_ready(hwif) == -EBUSY) | ||
811 | printk(KERN_DEBUG "%s: Wait for ready failed before probe !\n", hwif->name); | ||
812 | |||
813 | /* | ||
814 | * Second drive should only exist if first drive was found, | ||
815 | * but a lot of cdrom drives are configured as single slaves. | ||
816 | */ | ||
817 | for (unit = 0; unit < MAX_DRIVES; ++unit) { | ||
818 | ide_drive_t *drive = &hwif->drives[unit]; | ||
819 | drive->dn = (hwif->channel ? 2 : 0) + unit; | ||
820 | (void) probe_for_drive(drive); | ||
821 | if (drive->present && !hwif->present) { | ||
822 | hwif->present = 1; | ||
823 | if (hwif->chipset != ide_4drives || | ||
824 | !hwif->mate || | ||
825 | !hwif->mate->present) { | ||
826 | hwif_register(hwif); | ||
827 | } | ||
828 | } | ||
829 | } | ||
830 | if (hwif->io_ports[IDE_CONTROL_OFFSET] && hwif->reset) { | ||
831 | unsigned long timeout = jiffies + WAIT_WORSTCASE; | ||
832 | u8 stat; | ||
833 | |||
834 | printk(KERN_WARNING "%s: reset\n", hwif->name); | ||
835 | hwif->OUTB(12, hwif->io_ports[IDE_CONTROL_OFFSET]); | ||
836 | udelay(10); | ||
837 | hwif->OUTB(8, hwif->io_ports[IDE_CONTROL_OFFSET]); | ||
838 | do { | ||
839 | msleep(50); | ||
840 | stat = hwif->INB(hwif->io_ports[IDE_STATUS_OFFSET]); | ||
841 | } while ((stat & BUSY_STAT) && time_after(timeout, jiffies)); | ||
842 | |||
843 | } | ||
844 | local_irq_restore(flags); | ||
845 | /* | ||
846 | * Use cached IRQ number. It might be (and is...) changed by probe | ||
847 | * code above | ||
848 | */ | ||
849 | if (irqd) | ||
850 | enable_irq(irqd); | ||
851 | |||
852 | if (!hwif->present) { | ||
853 | ide_hwif_release_regions(hwif); | ||
854 | return; | ||
855 | } | ||
856 | |||
857 | for (unit = 0; unit < MAX_DRIVES; ++unit) { | ||
858 | ide_drive_t *drive = &hwif->drives[unit]; | ||
859 | |||
860 | if (drive->present) { | ||
861 | if (hwif->tuneproc != NULL && | ||
862 | drive->autotune == IDE_TUNE_AUTO) | ||
863 | /* auto-tune PIO mode */ | ||
864 | hwif->tuneproc(drive, 255); | ||
865 | |||
866 | if (drive->autotune != IDE_TUNE_DEFAULT && | ||
867 | drive->autotune != IDE_TUNE_AUTO) | ||
868 | continue; | ||
869 | |||
870 | drive->nice1 = 1; | ||
871 | |||
872 | /* | ||
873 | * MAJOR HACK BARF :-/ | ||
874 | * | ||
875 | * FIXME: chipsets own this cruft! | ||
876 | */ | ||
877 | /* | ||
878 | * Move here to prevent module loading clashing. | ||
879 | */ | ||
880 | // drive->autodma = hwif->autodma; | ||
881 | if (hwif->ide_dma_check) { | ||
882 | /* | ||
883 | * Force DMAing for the beginning of the check. | ||
884 | * Some chipsets appear to do interesting | ||
885 | * things, if not checked and cleared. | ||
886 | * PARANOIA!!! | ||
887 | */ | ||
888 | hwif->ide_dma_off_quietly(drive); | ||
889 | #ifdef CONFIG_IDEDMA_ONLYDISK | ||
890 | if (drive->media == ide_disk) | ||
891 | #endif | ||
892 | hwif->ide_dma_check(drive); | ||
893 | } | ||
894 | } | ||
895 | } | ||
896 | } | ||
897 | |||
898 | static int hwif_init(ide_hwif_t *hwif); | ||
899 | |||
900 | int probe_hwif_init_with_fixup(ide_hwif_t *hwif, void (*fixup)(ide_hwif_t *hwif)) | ||
901 | { | ||
902 | probe_hwif(hwif); | ||
903 | |||
904 | if (fixup) | ||
905 | fixup(hwif); | ||
906 | |||
907 | if (!hwif_init(hwif)) { | ||
908 | printk(KERN_INFO "%s: failed to initialize IDE interface\n", | ||
909 | hwif->name); | ||
910 | return -1; | ||
911 | } | ||
912 | |||
913 | if (hwif->present) { | ||
914 | u16 unit = 0; | ||
915 | for (unit = 0; unit < MAX_DRIVES; ++unit) { | ||
916 | ide_drive_t *drive = &hwif->drives[unit]; | ||
917 | /* For now don't attach absent drives, we may | ||
918 | want them on default or a new "empty" class | ||
919 | for hotplug reprobing ? */ | ||
920 | if (drive->present) { | ||
921 | ata_attach(drive); | ||
922 | } | ||
923 | } | ||
924 | } | ||
925 | return 0; | ||
926 | } | ||
927 | |||
928 | int probe_hwif_init(ide_hwif_t *hwif) | ||
929 | { | ||
930 | return probe_hwif_init_with_fixup(hwif, NULL); | ||
931 | } | ||
932 | |||
933 | EXPORT_SYMBOL(probe_hwif_init); | ||
934 | |||
935 | #if MAX_HWIFS > 1 | ||
936 | /* | ||
937 | * save_match() is used to simplify logic in init_irq() below. | ||
938 | * | ||
939 | * A loophole here is that we may not know about a particular | ||
940 | * hwif's irq until after that hwif is actually probed/initialized.. | ||
941 | * This could be a problem for the case where an hwif is on a | ||
942 | * dual interface that requires serialization (eg. cmd640) and another | ||
943 | * hwif using one of the same irqs is initialized beforehand. | ||
944 | * | ||
945 | * This routine detects and reports such situations, but does not fix them. | ||
946 | */ | ||
947 | static void save_match(ide_hwif_t *hwif, ide_hwif_t *new, ide_hwif_t **match) | ||
948 | { | ||
949 | ide_hwif_t *m = *match; | ||
950 | |||
951 | if (m && m->hwgroup && m->hwgroup != new->hwgroup) { | ||
952 | if (!new->hwgroup) | ||
953 | return; | ||
954 | printk("%s: potential irq problem with %s and %s\n", | ||
955 | hwif->name, new->name, m->name); | ||
956 | } | ||
957 | if (!m || m->irq != hwif->irq) /* don't undo a prior perfect match */ | ||
958 | *match = new; | ||
959 | } | ||
960 | #endif /* MAX_HWIFS > 1 */ | ||
961 | |||
962 | /* | ||
963 | * init request queue | ||
964 | */ | ||
965 | static int ide_init_queue(ide_drive_t *drive) | ||
966 | { | ||
967 | request_queue_t *q; | ||
968 | ide_hwif_t *hwif = HWIF(drive); | ||
969 | int max_sectors = 256; | ||
970 | int max_sg_entries = PRD_ENTRIES; | ||
971 | |||
972 | /* | ||
973 | * Our default set up assumes the normal IDE case, | ||
974 | * that is 64K segmenting, standard PRD setup | ||
975 | * and LBA28. Some drivers then impose their own | ||
976 | * limits and LBA48 we could raise it but as yet | ||
977 | * do not. | ||
978 | */ | ||
979 | |||
980 | q = blk_init_queue(do_ide_request, &ide_lock); | ||
981 | if (!q) | ||
982 | return 1; | ||
983 | |||
984 | q->queuedata = drive; | ||
985 | blk_queue_segment_boundary(q, 0xffff); | ||
986 | |||
987 | if (!hwif->rqsize) { | ||
988 | if (hwif->no_lba48 || hwif->no_lba48_dma) | ||
989 | hwif->rqsize = 256; | ||
990 | else | ||
991 | hwif->rqsize = 65536; | ||
992 | } | ||
993 | if (hwif->rqsize < max_sectors) | ||
994 | max_sectors = hwif->rqsize; | ||
995 | blk_queue_max_sectors(q, max_sectors); | ||
996 | |||
997 | #ifdef CONFIG_PCI | ||
998 | /* When we have an IOMMU, we may have a problem where pci_map_sg() | ||
999 | * creates segments that don't completely match our boundary | ||
1000 | * requirements and thus need to be broken up again. Because it | ||
1001 | * doesn't align properly either, we may actually have to break up | ||
1002 | * to more segments than what was we got in the first place, a max | ||
1003 | * worst case is twice as many. | ||
1004 | * This will be fixed once we teach pci_map_sg() about our boundary | ||
1005 | * requirements, hopefully soon. *FIXME* | ||
1006 | */ | ||
1007 | if (!PCI_DMA_BUS_IS_PHYS) | ||
1008 | max_sg_entries >>= 1; | ||
1009 | #endif /* CONFIG_PCI */ | ||
1010 | |||
1011 | blk_queue_max_hw_segments(q, max_sg_entries); | ||
1012 | blk_queue_max_phys_segments(q, max_sg_entries); | ||
1013 | |||
1014 | /* assign drive queue */ | ||
1015 | drive->queue = q; | ||
1016 | |||
1017 | /* needs drive->queue to be set */ | ||
1018 | ide_toggle_bounce(drive, 1); | ||
1019 | |||
1020 | /* enable led activity for disk drives only */ | ||
1021 | if (drive->media == ide_disk && hwif->led_act) | ||
1022 | blk_queue_activity_fn(q, hwif->led_act, drive); | ||
1023 | |||
1024 | return 0; | ||
1025 | } | ||
1026 | |||
1027 | /* | ||
1028 | * This routine sets up the irq for an ide interface, and creates a new | ||
1029 | * hwgroup for the irq/hwif if none was previously assigned. | ||
1030 | * | ||
1031 | * Much of the code is for correctly detecting/handling irq sharing | ||
1032 | * and irq serialization situations. This is somewhat complex because | ||
1033 | * it handles static as well as dynamic (PCMCIA) IDE interfaces. | ||
1034 | * | ||
1035 | * The SA_INTERRUPT in sa_flags means ide_intr() is always entered with | ||
1036 | * interrupts completely disabled. This can be bad for interrupt latency, | ||
1037 | * but anything else has led to problems on some machines. We re-enable | ||
1038 | * interrupts as much as we can safely do in most places. | ||
1039 | */ | ||
1040 | static int init_irq (ide_hwif_t *hwif) | ||
1041 | { | ||
1042 | unsigned int index; | ||
1043 | ide_hwgroup_t *hwgroup; | ||
1044 | ide_hwif_t *match = NULL; | ||
1045 | |||
1046 | |||
1047 | BUG_ON(in_interrupt()); | ||
1048 | BUG_ON(irqs_disabled()); | ||
1049 | down(&ide_cfg_sem); | ||
1050 | hwif->hwgroup = NULL; | ||
1051 | #if MAX_HWIFS > 1 | ||
1052 | /* | ||
1053 | * Group up with any other hwifs that share our irq(s). | ||
1054 | */ | ||
1055 | for (index = 0; index < MAX_HWIFS; index++) { | ||
1056 | ide_hwif_t *h = &ide_hwifs[index]; | ||
1057 | if (h->hwgroup) { /* scan only initialized hwif's */ | ||
1058 | if (hwif->irq == h->irq) { | ||
1059 | hwif->sharing_irq = h->sharing_irq = 1; | ||
1060 | if (hwif->chipset != ide_pci || | ||
1061 | h->chipset != ide_pci) { | ||
1062 | save_match(hwif, h, &match); | ||
1063 | } | ||
1064 | } | ||
1065 | if (hwif->serialized) { | ||
1066 | if (hwif->mate && hwif->mate->irq == h->irq) | ||
1067 | save_match(hwif, h, &match); | ||
1068 | } | ||
1069 | if (h->serialized) { | ||
1070 | if (h->mate && hwif->irq == h->mate->irq) | ||
1071 | save_match(hwif, h, &match); | ||
1072 | } | ||
1073 | } | ||
1074 | } | ||
1075 | #endif /* MAX_HWIFS > 1 */ | ||
1076 | /* | ||
1077 | * If we are still without a hwgroup, then form a new one | ||
1078 | */ | ||
1079 | if (match) { | ||
1080 | hwgroup = match->hwgroup; | ||
1081 | hwif->hwgroup = hwgroup; | ||
1082 | /* | ||
1083 | * Link us into the hwgroup. | ||
1084 | * This must be done early, do ensure that unexpected_intr | ||
1085 | * can find the hwif and prevent irq storms. | ||
1086 | * No drives are attached to the new hwif, choose_drive | ||
1087 | * can't do anything stupid (yet). | ||
1088 | * Add ourself as the 2nd entry to the hwgroup->hwif | ||
1089 | * linked list, the first entry is the hwif that owns | ||
1090 | * hwgroup->handler - do not change that. | ||
1091 | */ | ||
1092 | spin_lock_irq(&ide_lock); | ||
1093 | hwif->next = hwgroup->hwif->next; | ||
1094 | hwgroup->hwif->next = hwif; | ||
1095 | spin_unlock_irq(&ide_lock); | ||
1096 | } else { | ||
1097 | hwgroup = kmalloc(sizeof(ide_hwgroup_t),GFP_KERNEL); | ||
1098 | if (!hwgroup) | ||
1099 | goto out_up; | ||
1100 | |||
1101 | hwif->hwgroup = hwgroup; | ||
1102 | |||
1103 | memset(hwgroup, 0, sizeof(ide_hwgroup_t)); | ||
1104 | hwgroup->hwif = hwif->next = hwif; | ||
1105 | hwgroup->rq = NULL; | ||
1106 | hwgroup->handler = NULL; | ||
1107 | hwgroup->drive = NULL; | ||
1108 | hwgroup->busy = 0; | ||
1109 | init_timer(&hwgroup->timer); | ||
1110 | hwgroup->timer.function = &ide_timer_expiry; | ||
1111 | hwgroup->timer.data = (unsigned long) hwgroup; | ||
1112 | } | ||
1113 | |||
1114 | /* | ||
1115 | * Allocate the irq, if not already obtained for another hwif | ||
1116 | */ | ||
1117 | if (!match || match->irq != hwif->irq) { | ||
1118 | int sa = SA_INTERRUPT; | ||
1119 | #if defined(__mc68000__) || defined(CONFIG_APUS) | ||
1120 | sa = SA_SHIRQ; | ||
1121 | #endif /* __mc68000__ || CONFIG_APUS */ | ||
1122 | |||
1123 | if (IDE_CHIPSET_IS_PCI(hwif->chipset)) { | ||
1124 | sa = SA_SHIRQ; | ||
1125 | #ifndef CONFIG_IDEPCI_SHARE_IRQ | ||
1126 | sa |= SA_INTERRUPT; | ||
1127 | #endif /* CONFIG_IDEPCI_SHARE_IRQ */ | ||
1128 | } | ||
1129 | |||
1130 | if (hwif->io_ports[IDE_CONTROL_OFFSET]) | ||
1131 | /* clear nIEN */ | ||
1132 | hwif->OUTB(0x08, hwif->io_ports[IDE_CONTROL_OFFSET]); | ||
1133 | |||
1134 | if (request_irq(hwif->irq,&ide_intr,sa,hwif->name,hwgroup)) | ||
1135 | goto out_unlink; | ||
1136 | } | ||
1137 | |||
1138 | /* | ||
1139 | * For any present drive: | ||
1140 | * - allocate the block device queue | ||
1141 | * - link drive into the hwgroup | ||
1142 | */ | ||
1143 | for (index = 0; index < MAX_DRIVES; ++index) { | ||
1144 | ide_drive_t *drive = &hwif->drives[index]; | ||
1145 | if (!drive->present) | ||
1146 | continue; | ||
1147 | if (ide_init_queue(drive)) { | ||
1148 | printk(KERN_ERR "ide: failed to init %s\n",drive->name); | ||
1149 | continue; | ||
1150 | } | ||
1151 | spin_lock_irq(&ide_lock); | ||
1152 | if (!hwgroup->drive) { | ||
1153 | /* first drive for hwgroup. */ | ||
1154 | drive->next = drive; | ||
1155 | hwgroup->drive = drive; | ||
1156 | hwgroup->hwif = HWIF(hwgroup->drive); | ||
1157 | } else { | ||
1158 | drive->next = hwgroup->drive->next; | ||
1159 | hwgroup->drive->next = drive; | ||
1160 | } | ||
1161 | spin_unlock_irq(&ide_lock); | ||
1162 | } | ||
1163 | |||
1164 | #if !defined(__mc68000__) && !defined(CONFIG_APUS) && !defined(__sparc__) | ||
1165 | printk("%s at 0x%03lx-0x%03lx,0x%03lx on irq %d", hwif->name, | ||
1166 | hwif->io_ports[IDE_DATA_OFFSET], | ||
1167 | hwif->io_ports[IDE_DATA_OFFSET]+7, | ||
1168 | hwif->io_ports[IDE_CONTROL_OFFSET], hwif->irq); | ||
1169 | #elif defined(__sparc__) | ||
1170 | printk("%s at 0x%03lx-0x%03lx,0x%03lx on irq %s", hwif->name, | ||
1171 | hwif->io_ports[IDE_DATA_OFFSET], | ||
1172 | hwif->io_ports[IDE_DATA_OFFSET]+7, | ||
1173 | hwif->io_ports[IDE_CONTROL_OFFSET], __irq_itoa(hwif->irq)); | ||
1174 | #else | ||
1175 | printk("%s at 0x%08lx on irq %d", hwif->name, | ||
1176 | hwif->io_ports[IDE_DATA_OFFSET], hwif->irq); | ||
1177 | #endif /* __mc68000__ && CONFIG_APUS */ | ||
1178 | if (match) | ||
1179 | printk(" (%sed with %s)", | ||
1180 | hwif->sharing_irq ? "shar" : "serializ", match->name); | ||
1181 | printk("\n"); | ||
1182 | up(&ide_cfg_sem); | ||
1183 | return 0; | ||
1184 | out_unlink: | ||
1185 | spin_lock_irq(&ide_lock); | ||
1186 | if (hwif->next == hwif) { | ||
1187 | BUG_ON(match); | ||
1188 | BUG_ON(hwgroup->hwif != hwif); | ||
1189 | kfree(hwgroup); | ||
1190 | } else { | ||
1191 | ide_hwif_t *g; | ||
1192 | g = hwgroup->hwif; | ||
1193 | while (g->next != hwif) | ||
1194 | g = g->next; | ||
1195 | g->next = hwif->next; | ||
1196 | if (hwgroup->hwif == hwif) { | ||
1197 | /* Impossible. */ | ||
1198 | printk(KERN_ERR "Duh. Uninitialized hwif listed as active hwif.\n"); | ||
1199 | hwgroup->hwif = g; | ||
1200 | } | ||
1201 | BUG_ON(hwgroup->hwif == hwif); | ||
1202 | } | ||
1203 | spin_unlock_irq(&ide_lock); | ||
1204 | out_up: | ||
1205 | up(&ide_cfg_sem); | ||
1206 | return 1; | ||
1207 | } | ||
1208 | |||
1209 | static int ata_lock(dev_t dev, void *data) | ||
1210 | { | ||
1211 | /* FIXME: we want to pin hwif down */ | ||
1212 | return 0; | ||
1213 | } | ||
1214 | |||
1215 | static struct kobject *ata_probe(dev_t dev, int *part, void *data) | ||
1216 | { | ||
1217 | ide_hwif_t *hwif = data; | ||
1218 | int unit = *part >> PARTN_BITS; | ||
1219 | ide_drive_t *drive = &hwif->drives[unit]; | ||
1220 | if (!drive->present) | ||
1221 | return NULL; | ||
1222 | |||
1223 | if (drive->media == ide_disk) | ||
1224 | request_module("ide-disk"); | ||
1225 | if (drive->scsi) | ||
1226 | request_module("ide-scsi"); | ||
1227 | if (drive->media == ide_cdrom || drive->media == ide_optical) | ||
1228 | request_module("ide-cd"); | ||
1229 | if (drive->media == ide_tape) | ||
1230 | request_module("ide-tape"); | ||
1231 | if (drive->media == ide_floppy) | ||
1232 | request_module("ide-floppy"); | ||
1233 | |||
1234 | return NULL; | ||
1235 | } | ||
1236 | |||
1237 | static struct kobject *exact_match(dev_t dev, int *part, void *data) | ||
1238 | { | ||
1239 | struct gendisk *p = data; | ||
1240 | *part &= (1 << PARTN_BITS) - 1; | ||
1241 | return &p->kobj; | ||
1242 | } | ||
1243 | |||
1244 | static int exact_lock(dev_t dev, void *data) | ||
1245 | { | ||
1246 | struct gendisk *p = data; | ||
1247 | |||
1248 | if (!get_disk(p)) | ||
1249 | return -1; | ||
1250 | return 0; | ||
1251 | } | ||
1252 | |||
1253 | void ide_register_region(struct gendisk *disk) | ||
1254 | { | ||
1255 | blk_register_region(MKDEV(disk->major, disk->first_minor), | ||
1256 | disk->minors, NULL, exact_match, exact_lock, disk); | ||
1257 | } | ||
1258 | |||
1259 | EXPORT_SYMBOL_GPL(ide_register_region); | ||
1260 | |||
1261 | void ide_unregister_region(struct gendisk *disk) | ||
1262 | { | ||
1263 | blk_unregister_region(MKDEV(disk->major, disk->first_minor), | ||
1264 | disk->minors); | ||
1265 | } | ||
1266 | |||
1267 | EXPORT_SYMBOL_GPL(ide_unregister_region); | ||
1268 | |||
1269 | void ide_init_disk(struct gendisk *disk, ide_drive_t *drive) | ||
1270 | { | ||
1271 | ide_hwif_t *hwif = drive->hwif; | ||
1272 | unsigned int unit = (drive->select.all >> 4) & 1; | ||
1273 | |||
1274 | disk->major = hwif->major; | ||
1275 | disk->first_minor = unit << PARTN_BITS; | ||
1276 | sprintf(disk->disk_name, "hd%c", 'a' + hwif->index * MAX_DRIVES + unit); | ||
1277 | disk->queue = drive->queue; | ||
1278 | } | ||
1279 | |||
1280 | EXPORT_SYMBOL_GPL(ide_init_disk); | ||
1281 | |||
1282 | static void drive_release_dev (struct device *dev) | ||
1283 | { | ||
1284 | ide_drive_t *drive = container_of(dev, ide_drive_t, gendev); | ||
1285 | |||
1286 | up(&drive->gendev_rel_sem); | ||
1287 | } | ||
1288 | |||
1289 | /* | ||
1290 | * init_gendisk() (as opposed to ide_geninit) is called for each major device, | ||
1291 | * after probing for drives, to allocate partition tables and other data | ||
1292 | * structures needed for the routines in genhd.c. ide_geninit() gets called | ||
1293 | * somewhat later, during the partition check. | ||
1294 | */ | ||
1295 | static void init_gendisk (ide_hwif_t *hwif) | ||
1296 | { | ||
1297 | unsigned int unit; | ||
1298 | |||
1299 | for (unit = 0; unit < MAX_DRIVES; ++unit) { | ||
1300 | ide_drive_t * drive = &hwif->drives[unit]; | ||
1301 | ide_add_generic_settings(drive); | ||
1302 | snprintf(drive->gendev.bus_id,BUS_ID_SIZE,"%u.%u", | ||
1303 | hwif->index,unit); | ||
1304 | drive->gendev.parent = &hwif->gendev; | ||
1305 | drive->gendev.bus = &ide_bus_type; | ||
1306 | drive->gendev.driver_data = drive; | ||
1307 | drive->gendev.release = drive_release_dev; | ||
1308 | if (drive->present) { | ||
1309 | device_register(&drive->gendev); | ||
1310 | sprintf(drive->devfs_name, "ide/host%d/bus%d/target%d/lun%d", | ||
1311 | (hwif->channel && hwif->mate) ? | ||
1312 | hwif->mate->index : hwif->index, | ||
1313 | hwif->channel, unit, drive->lun); | ||
1314 | } | ||
1315 | } | ||
1316 | blk_register_region(MKDEV(hwif->major, 0), MAX_DRIVES << PARTN_BITS, | ||
1317 | THIS_MODULE, ata_probe, ata_lock, hwif); | ||
1318 | } | ||
1319 | |||
1320 | static int hwif_init(ide_hwif_t *hwif) | ||
1321 | { | ||
1322 | int old_irq; | ||
1323 | |||
1324 | /* Return success if no device is connected */ | ||
1325 | if (!hwif->present) | ||
1326 | return 1; | ||
1327 | |||
1328 | if (!hwif->irq) { | ||
1329 | if (!(hwif->irq = ide_default_irq(hwif->io_ports[IDE_DATA_OFFSET]))) | ||
1330 | { | ||
1331 | printk("%s: DISABLED, NO IRQ\n", hwif->name); | ||
1332 | return (hwif->present = 0); | ||
1333 | } | ||
1334 | } | ||
1335 | #ifdef CONFIG_BLK_DEV_HD | ||
1336 | if (hwif->irq == HD_IRQ && hwif->io_ports[IDE_DATA_OFFSET] != HD_DATA) { | ||
1337 | printk("%s: CANNOT SHARE IRQ WITH OLD " | ||
1338 | "HARDDISK DRIVER (hd.c)\n", hwif->name); | ||
1339 | return (hwif->present = 0); | ||
1340 | } | ||
1341 | #endif /* CONFIG_BLK_DEV_HD */ | ||
1342 | |||
1343 | /* we set it back to 1 if all is ok below */ | ||
1344 | hwif->present = 0; | ||
1345 | |||
1346 | if (register_blkdev(hwif->major, hwif->name)) | ||
1347 | return 0; | ||
1348 | |||
1349 | if (!hwif->sg_max_nents) | ||
1350 | hwif->sg_max_nents = PRD_ENTRIES; | ||
1351 | |||
1352 | hwif->sg_table = kmalloc(sizeof(struct scatterlist)*hwif->sg_max_nents, | ||
1353 | GFP_KERNEL); | ||
1354 | if (!hwif->sg_table) { | ||
1355 | printk(KERN_ERR "%s: unable to allocate SG table.\n", hwif->name); | ||
1356 | goto out; | ||
1357 | } | ||
1358 | |||
1359 | if (init_irq(hwif) == 0) | ||
1360 | goto done; | ||
1361 | |||
1362 | old_irq = hwif->irq; | ||
1363 | /* | ||
1364 | * It failed to initialise. Find the default IRQ for | ||
1365 | * this port and try that. | ||
1366 | */ | ||
1367 | if (!(hwif->irq = ide_default_irq(hwif->io_ports[IDE_DATA_OFFSET]))) { | ||
1368 | printk("%s: Disabled unable to get IRQ %d.\n", | ||
1369 | hwif->name, old_irq); | ||
1370 | goto out; | ||
1371 | } | ||
1372 | if (init_irq(hwif)) { | ||
1373 | printk("%s: probed IRQ %d and default IRQ %d failed.\n", | ||
1374 | hwif->name, old_irq, hwif->irq); | ||
1375 | goto out; | ||
1376 | } | ||
1377 | printk("%s: probed IRQ %d failed, using default.\n", | ||
1378 | hwif->name, hwif->irq); | ||
1379 | |||
1380 | done: | ||
1381 | init_gendisk(hwif); | ||
1382 | hwif->present = 1; /* success */ | ||
1383 | return 1; | ||
1384 | |||
1385 | out: | ||
1386 | unregister_blkdev(hwif->major, hwif->name); | ||
1387 | return 0; | ||
1388 | } | ||
1389 | |||
1390 | int ideprobe_init (void) | ||
1391 | { | ||
1392 | unsigned int index; | ||
1393 | int probe[MAX_HWIFS]; | ||
1394 | |||
1395 | memset(probe, 0, MAX_HWIFS * sizeof(int)); | ||
1396 | for (index = 0; index < MAX_HWIFS; ++index) | ||
1397 | probe[index] = !ide_hwifs[index].present; | ||
1398 | |||
1399 | for (index = 0; index < MAX_HWIFS; ++index) | ||
1400 | if (probe[index]) | ||
1401 | probe_hwif(&ide_hwifs[index]); | ||
1402 | for (index = 0; index < MAX_HWIFS; ++index) | ||
1403 | if (probe[index]) | ||
1404 | hwif_init(&ide_hwifs[index]); | ||
1405 | for (index = 0; index < MAX_HWIFS; ++index) { | ||
1406 | if (probe[index]) { | ||
1407 | ide_hwif_t *hwif = &ide_hwifs[index]; | ||
1408 | int unit; | ||
1409 | if (!hwif->present) | ||
1410 | continue; | ||
1411 | if (hwif->chipset == ide_unknown || hwif->chipset == ide_forced) | ||
1412 | hwif->chipset = ide_generic; | ||
1413 | for (unit = 0; unit < MAX_DRIVES; ++unit) | ||
1414 | if (hwif->drives[unit].present) | ||
1415 | ata_attach(&hwif->drives[unit]); | ||
1416 | } | ||
1417 | } | ||
1418 | return 0; | ||
1419 | } | ||
1420 | |||
1421 | EXPORT_SYMBOL_GPL(ideprobe_init); | ||
diff --git a/drivers/ide/ide-proc.c b/drivers/ide/ide-proc.c new file mode 100644 index 000000000000..bdff5ac58053 --- /dev/null +++ b/drivers/ide/ide-proc.c | |||
@@ -0,0 +1,521 @@ | |||
1 | /* | ||
2 | * linux/drivers/ide/ide-proc.c Version 1.05 Mar 05, 2003 | ||
3 | * | ||
4 | * Copyright (C) 1997-1998 Mark Lord | ||
5 | * Copyright (C) 2003 Red Hat <alan@redhat.com> | ||
6 | */ | ||
7 | |||
8 | /* | ||
9 | * This is the /proc/ide/ filesystem implementation. | ||
10 | * | ||
11 | * Drive/Driver settings can be retrieved by reading the drive's | ||
12 | * "settings" files. e.g. "cat /proc/ide0/hda/settings" | ||
13 | * To write a new value "val" into a specific setting "name", use: | ||
14 | * echo "name:val" >/proc/ide/ide0/hda/settings | ||
15 | * | ||
16 | * Also useful, "cat /proc/ide0/hda/[identify, smart_values, | ||
17 | * smart_thresholds, capabilities]" will issue an IDENTIFY / | ||
18 | * PACKET_IDENTIFY / SMART_READ_VALUES / SMART_READ_THRESHOLDS / | ||
19 | * SENSE CAPABILITIES command to /dev/hda, and then dump out the | ||
20 | * returned data as 256 16-bit words. The "hdparm" utility will | ||
21 | * be updated someday soon to use this mechanism. | ||
22 | * | ||
23 | */ | ||
24 | |||
25 | #include <linux/config.h> | ||
26 | #include <linux/module.h> | ||
27 | |||
28 | #include <asm/uaccess.h> | ||
29 | #include <linux/errno.h> | ||
30 | #include <linux/sched.h> | ||
31 | #include <linux/proc_fs.h> | ||
32 | #include <linux/stat.h> | ||
33 | #include <linux/mm.h> | ||
34 | #include <linux/pci.h> | ||
35 | #include <linux/ctype.h> | ||
36 | #include <linux/hdreg.h> | ||
37 | #include <linux/ide.h> | ||
38 | #include <linux/seq_file.h> | ||
39 | |||
40 | #include <asm/io.h> | ||
41 | |||
42 | static int proc_ide_read_imodel | ||
43 | (char *page, char **start, off_t off, int count, int *eof, void *data) | ||
44 | { | ||
45 | ide_hwif_t *hwif = (ide_hwif_t *) data; | ||
46 | int len; | ||
47 | const char *name; | ||
48 | |||
49 | /* | ||
50 | * Neither ide_unknown nor ide_forced should be set at this point. | ||
51 | */ | ||
52 | switch (hwif->chipset) { | ||
53 | case ide_generic: name = "generic"; break; | ||
54 | case ide_pci: name = "pci"; break; | ||
55 | case ide_cmd640: name = "cmd640"; break; | ||
56 | case ide_dtc2278: name = "dtc2278"; break; | ||
57 | case ide_ali14xx: name = "ali14xx"; break; | ||
58 | case ide_qd65xx: name = "qd65xx"; break; | ||
59 | case ide_umc8672: name = "umc8672"; break; | ||
60 | case ide_ht6560b: name = "ht6560b"; break; | ||
61 | case ide_rz1000: name = "rz1000"; break; | ||
62 | case ide_trm290: name = "trm290"; break; | ||
63 | case ide_cmd646: name = "cmd646"; break; | ||
64 | case ide_cy82c693: name = "cy82c693"; break; | ||
65 | case ide_4drives: name = "4drives"; break; | ||
66 | case ide_pmac: name = "mac-io"; break; | ||
67 | default: name = "(unknown)"; break; | ||
68 | } | ||
69 | len = sprintf(page, "%s\n", name); | ||
70 | PROC_IDE_READ_RETURN(page,start,off,count,eof,len); | ||
71 | } | ||
72 | |||
73 | static int proc_ide_read_mate | ||
74 | (char *page, char **start, off_t off, int count, int *eof, void *data) | ||
75 | { | ||
76 | ide_hwif_t *hwif = (ide_hwif_t *) data; | ||
77 | int len; | ||
78 | |||
79 | if (hwif && hwif->mate && hwif->mate->present) | ||
80 | len = sprintf(page, "%s\n", hwif->mate->name); | ||
81 | else | ||
82 | len = sprintf(page, "(none)\n"); | ||
83 | PROC_IDE_READ_RETURN(page,start,off,count,eof,len); | ||
84 | } | ||
85 | |||
86 | static int proc_ide_read_channel | ||
87 | (char *page, char **start, off_t off, int count, int *eof, void *data) | ||
88 | { | ||
89 | ide_hwif_t *hwif = (ide_hwif_t *) data; | ||
90 | int len; | ||
91 | |||
92 | page[0] = hwif->channel ? '1' : '0'; | ||
93 | page[1] = '\n'; | ||
94 | len = 2; | ||
95 | PROC_IDE_READ_RETURN(page,start,off,count,eof,len); | ||
96 | } | ||
97 | |||
98 | static int proc_ide_read_identify | ||
99 | (char *page, char **start, off_t off, int count, int *eof, void *data) | ||
100 | { | ||
101 | ide_drive_t *drive = (ide_drive_t *)data; | ||
102 | int len = 0, i = 0; | ||
103 | int err = 0; | ||
104 | |||
105 | len = sprintf(page, "\n"); | ||
106 | |||
107 | if (drive) { | ||
108 | unsigned short *val = (unsigned short *) page; | ||
109 | |||
110 | err = taskfile_lib_get_identify(drive, page); | ||
111 | if (!err) { | ||
112 | char *out = ((char *)page) + (SECTOR_WORDS * 4); | ||
113 | page = out; | ||
114 | do { | ||
115 | out += sprintf(out, "%04x%c", | ||
116 | le16_to_cpu(*val), (++i & 7) ? ' ' : '\n'); | ||
117 | val += 1; | ||
118 | } while (i < (SECTOR_WORDS * 2)); | ||
119 | len = out - page; | ||
120 | } | ||
121 | } | ||
122 | PROC_IDE_READ_RETURN(page,start,off,count,eof,len); | ||
123 | } | ||
124 | |||
125 | static void proc_ide_settings_warn(void) | ||
126 | { | ||
127 | static int warned = 0; | ||
128 | |||
129 | if (warned) | ||
130 | return; | ||
131 | |||
132 | printk(KERN_WARNING "Warning: /proc/ide/hd?/settings interface is " | ||
133 | "obsolete, and will be removed soon!\n"); | ||
134 | warned = 1; | ||
135 | } | ||
136 | |||
137 | static int proc_ide_read_settings | ||
138 | (char *page, char **start, off_t off, int count, int *eof, void *data) | ||
139 | { | ||
140 | ide_drive_t *drive = (ide_drive_t *) data; | ||
141 | ide_settings_t *setting = (ide_settings_t *) drive->settings; | ||
142 | char *out = page; | ||
143 | int len, rc, mul_factor, div_factor; | ||
144 | |||
145 | proc_ide_settings_warn(); | ||
146 | |||
147 | down(&ide_setting_sem); | ||
148 | out += sprintf(out, "name\t\t\tvalue\t\tmin\t\tmax\t\tmode\n"); | ||
149 | out += sprintf(out, "----\t\t\t-----\t\t---\t\t---\t\t----\n"); | ||
150 | while(setting) { | ||
151 | mul_factor = setting->mul_factor; | ||
152 | div_factor = setting->div_factor; | ||
153 | out += sprintf(out, "%-24s", setting->name); | ||
154 | if ((rc = ide_read_setting(drive, setting)) >= 0) | ||
155 | out += sprintf(out, "%-16d", rc * mul_factor / div_factor); | ||
156 | else | ||
157 | out += sprintf(out, "%-16s", "write-only"); | ||
158 | out += sprintf(out, "%-16d%-16d", (setting->min * mul_factor + div_factor - 1) / div_factor, setting->max * mul_factor / div_factor); | ||
159 | if (setting->rw & SETTING_READ) | ||
160 | out += sprintf(out, "r"); | ||
161 | if (setting->rw & SETTING_WRITE) | ||
162 | out += sprintf(out, "w"); | ||
163 | out += sprintf(out, "\n"); | ||
164 | setting = setting->next; | ||
165 | } | ||
166 | len = out - page; | ||
167 | up(&ide_setting_sem); | ||
168 | PROC_IDE_READ_RETURN(page,start,off,count,eof,len); | ||
169 | } | ||
170 | |||
171 | #define MAX_LEN 30 | ||
172 | |||
173 | static int proc_ide_write_settings(struct file *file, const char __user *buffer, | ||
174 | unsigned long count, void *data) | ||
175 | { | ||
176 | ide_drive_t *drive = (ide_drive_t *) data; | ||
177 | char name[MAX_LEN + 1]; | ||
178 | int for_real = 0; | ||
179 | unsigned long n; | ||
180 | ide_settings_t *setting; | ||
181 | char *buf, *s; | ||
182 | |||
183 | if (!capable(CAP_SYS_ADMIN)) | ||
184 | return -EACCES; | ||
185 | |||
186 | proc_ide_settings_warn(); | ||
187 | |||
188 | if (count >= PAGE_SIZE) | ||
189 | return -EINVAL; | ||
190 | |||
191 | s = buf = (char *)__get_free_page(GFP_USER); | ||
192 | if (!buf) | ||
193 | return -ENOMEM; | ||
194 | |||
195 | if (copy_from_user(buf, buffer, count)) { | ||
196 | free_page((unsigned long)buf); | ||
197 | return -EFAULT; | ||
198 | } | ||
199 | |||
200 | buf[count] = '\0'; | ||
201 | |||
202 | /* | ||
203 | * Skip over leading whitespace | ||
204 | */ | ||
205 | while (count && isspace(*s)) { | ||
206 | --count; | ||
207 | ++s; | ||
208 | } | ||
209 | /* | ||
210 | * Do one full pass to verify all parameters, | ||
211 | * then do another to actually write the new settings. | ||
212 | */ | ||
213 | do { | ||
214 | char *p = s; | ||
215 | n = count; | ||
216 | while (n > 0) { | ||
217 | unsigned val; | ||
218 | char *q = p; | ||
219 | |||
220 | while (n > 0 && *p != ':') { | ||
221 | --n; | ||
222 | p++; | ||
223 | } | ||
224 | if (*p != ':') | ||
225 | goto parse_error; | ||
226 | if (p - q > MAX_LEN) | ||
227 | goto parse_error; | ||
228 | memcpy(name, q, p - q); | ||
229 | name[p - q] = 0; | ||
230 | |||
231 | if (n > 0) { | ||
232 | --n; | ||
233 | p++; | ||
234 | } else | ||
235 | goto parse_error; | ||
236 | |||
237 | val = simple_strtoul(p, &q, 10); | ||
238 | n -= q - p; | ||
239 | p = q; | ||
240 | if (n > 0 && !isspace(*p)) | ||
241 | goto parse_error; | ||
242 | while (n > 0 && isspace(*p)) { | ||
243 | --n; | ||
244 | ++p; | ||
245 | } | ||
246 | |||
247 | down(&ide_setting_sem); | ||
248 | setting = ide_find_setting_by_name(drive, name); | ||
249 | if (!setting) | ||
250 | { | ||
251 | up(&ide_setting_sem); | ||
252 | goto parse_error; | ||
253 | } | ||
254 | if (for_real) | ||
255 | ide_write_setting(drive, setting, val * setting->div_factor / setting->mul_factor); | ||
256 | up(&ide_setting_sem); | ||
257 | } | ||
258 | } while (!for_real++); | ||
259 | free_page((unsigned long)buf); | ||
260 | return count; | ||
261 | parse_error: | ||
262 | free_page((unsigned long)buf); | ||
263 | printk("proc_ide_write_settings(): parse error\n"); | ||
264 | return -EINVAL; | ||
265 | } | ||
266 | |||
267 | int proc_ide_read_capacity | ||
268 | (char *page, char **start, off_t off, int count, int *eof, void *data) | ||
269 | { | ||
270 | int len = sprintf(page,"%llu\n", (long long)0x7fffffff); | ||
271 | PROC_IDE_READ_RETURN(page,start,off,count,eof,len); | ||
272 | } | ||
273 | |||
274 | EXPORT_SYMBOL_GPL(proc_ide_read_capacity); | ||
275 | |||
276 | int proc_ide_read_geometry | ||
277 | (char *page, char **start, off_t off, int count, int *eof, void *data) | ||
278 | { | ||
279 | ide_drive_t *drive = (ide_drive_t *) data; | ||
280 | char *out = page; | ||
281 | int len; | ||
282 | |||
283 | out += sprintf(out,"physical %d/%d/%d\n", | ||
284 | drive->cyl, drive->head, drive->sect); | ||
285 | out += sprintf(out,"logical %d/%d/%d\n", | ||
286 | drive->bios_cyl, drive->bios_head, drive->bios_sect); | ||
287 | |||
288 | len = out - page; | ||
289 | PROC_IDE_READ_RETURN(page,start,off,count,eof,len); | ||
290 | } | ||
291 | |||
292 | EXPORT_SYMBOL(proc_ide_read_geometry); | ||
293 | |||
294 | static int proc_ide_read_dmodel | ||
295 | (char *page, char **start, off_t off, int count, int *eof, void *data) | ||
296 | { | ||
297 | ide_drive_t *drive = (ide_drive_t *) data; | ||
298 | struct hd_driveid *id = drive->id; | ||
299 | int len; | ||
300 | |||
301 | len = sprintf(page, "%.40s\n", | ||
302 | (id && id->model[0]) ? (char *)id->model : "(none)"); | ||
303 | PROC_IDE_READ_RETURN(page,start,off,count,eof,len); | ||
304 | } | ||
305 | |||
306 | static int proc_ide_read_driver | ||
307 | (char *page, char **start, off_t off, int count, int *eof, void *data) | ||
308 | { | ||
309 | ide_drive_t *drive = (ide_drive_t *) data; | ||
310 | ide_driver_t *driver = drive->driver; | ||
311 | int len; | ||
312 | |||
313 | if (driver) { | ||
314 | len = sprintf(page, "%s version %s\n", | ||
315 | driver->name, driver->version); | ||
316 | } else | ||
317 | len = sprintf(page, "ide-default version 0.9.newide\n"); | ||
318 | PROC_IDE_READ_RETURN(page,start,off,count,eof,len); | ||
319 | } | ||
320 | |||
321 | static int proc_ide_write_driver | ||
322 | (struct file *file, const char __user *buffer, unsigned long count, void *data) | ||
323 | { | ||
324 | ide_drive_t *drive = (ide_drive_t *) data; | ||
325 | char name[32]; | ||
326 | |||
327 | if (!capable(CAP_SYS_ADMIN)) | ||
328 | return -EACCES; | ||
329 | if (count > 31) | ||
330 | count = 31; | ||
331 | if (copy_from_user(name, buffer, count)) | ||
332 | return -EFAULT; | ||
333 | name[count] = '\0'; | ||
334 | if (ide_replace_subdriver(drive, name)) | ||
335 | return -EINVAL; | ||
336 | return count; | ||
337 | } | ||
338 | |||
339 | static int proc_ide_read_media | ||
340 | (char *page, char **start, off_t off, int count, int *eof, void *data) | ||
341 | { | ||
342 | ide_drive_t *drive = (ide_drive_t *) data; | ||
343 | const char *media; | ||
344 | int len; | ||
345 | |||
346 | switch (drive->media) { | ||
347 | case ide_disk: media = "disk\n"; | ||
348 | break; | ||
349 | case ide_cdrom: media = "cdrom\n"; | ||
350 | break; | ||
351 | case ide_tape: media = "tape\n"; | ||
352 | break; | ||
353 | case ide_floppy:media = "floppy\n"; | ||
354 | break; | ||
355 | default: media = "UNKNOWN\n"; | ||
356 | break; | ||
357 | } | ||
358 | strcpy(page,media); | ||
359 | len = strlen(media); | ||
360 | PROC_IDE_READ_RETURN(page,start,off,count,eof,len); | ||
361 | } | ||
362 | |||
363 | static ide_proc_entry_t generic_drive_entries[] = { | ||
364 | { "driver", S_IFREG|S_IRUGO, proc_ide_read_driver, proc_ide_write_driver }, | ||
365 | { "identify", S_IFREG|S_IRUSR, proc_ide_read_identify, NULL }, | ||
366 | { "media", S_IFREG|S_IRUGO, proc_ide_read_media, NULL }, | ||
367 | { "model", S_IFREG|S_IRUGO, proc_ide_read_dmodel, NULL }, | ||
368 | { "settings", S_IFREG|S_IRUSR|S_IWUSR,proc_ide_read_settings, proc_ide_write_settings }, | ||
369 | { NULL, 0, NULL, NULL } | ||
370 | }; | ||
371 | |||
372 | void ide_add_proc_entries(struct proc_dir_entry *dir, ide_proc_entry_t *p, void *data) | ||
373 | { | ||
374 | struct proc_dir_entry *ent; | ||
375 | |||
376 | if (!dir || !p) | ||
377 | return; | ||
378 | while (p->name != NULL) { | ||
379 | ent = create_proc_entry(p->name, p->mode, dir); | ||
380 | if (!ent) return; | ||
381 | ent->nlink = 1; | ||
382 | ent->data = data; | ||
383 | ent->read_proc = p->read_proc; | ||
384 | ent->write_proc = p->write_proc; | ||
385 | p++; | ||
386 | } | ||
387 | } | ||
388 | |||
389 | void ide_remove_proc_entries(struct proc_dir_entry *dir, ide_proc_entry_t *p) | ||
390 | { | ||
391 | if (!dir || !p) | ||
392 | return; | ||
393 | while (p->name != NULL) { | ||
394 | remove_proc_entry(p->name, dir); | ||
395 | p++; | ||
396 | } | ||
397 | } | ||
398 | |||
399 | static void create_proc_ide_drives(ide_hwif_t *hwif) | ||
400 | { | ||
401 | int d; | ||
402 | struct proc_dir_entry *ent; | ||
403 | struct proc_dir_entry *parent = hwif->proc; | ||
404 | char name[64]; | ||
405 | |||
406 | for (d = 0; d < MAX_DRIVES; d++) { | ||
407 | ide_drive_t *drive = &hwif->drives[d]; | ||
408 | |||
409 | if (!drive->present) | ||
410 | continue; | ||
411 | if (drive->proc) | ||
412 | continue; | ||
413 | |||
414 | drive->proc = proc_mkdir(drive->name, parent); | ||
415 | if (drive->proc) | ||
416 | ide_add_proc_entries(drive->proc, generic_drive_entries, drive); | ||
417 | sprintf(name,"ide%d/%s", (drive->name[2]-'a')/2, drive->name); | ||
418 | ent = proc_symlink(drive->name, proc_ide_root, name); | ||
419 | if (!ent) return; | ||
420 | } | ||
421 | } | ||
422 | |||
423 | static void destroy_proc_ide_device(ide_hwif_t *hwif, ide_drive_t *drive) | ||
424 | { | ||
425 | if (drive->proc) { | ||
426 | ide_remove_proc_entries(drive->proc, generic_drive_entries); | ||
427 | remove_proc_entry(drive->name, proc_ide_root); | ||
428 | remove_proc_entry(drive->name, hwif->proc); | ||
429 | drive->proc = NULL; | ||
430 | } | ||
431 | } | ||
432 | |||
433 | static void destroy_proc_ide_drives(ide_hwif_t *hwif) | ||
434 | { | ||
435 | int d; | ||
436 | |||
437 | for (d = 0; d < MAX_DRIVES; d++) { | ||
438 | ide_drive_t *drive = &hwif->drives[d]; | ||
439 | if (drive->proc) | ||
440 | destroy_proc_ide_device(hwif, drive); | ||
441 | } | ||
442 | } | ||
443 | |||
444 | static ide_proc_entry_t hwif_entries[] = { | ||
445 | { "channel", S_IFREG|S_IRUGO, proc_ide_read_channel, NULL }, | ||
446 | { "mate", S_IFREG|S_IRUGO, proc_ide_read_mate, NULL }, | ||
447 | { "model", S_IFREG|S_IRUGO, proc_ide_read_imodel, NULL }, | ||
448 | { NULL, 0, NULL, NULL } | ||
449 | }; | ||
450 | |||
451 | void create_proc_ide_interfaces(void) | ||
452 | { | ||
453 | int h; | ||
454 | |||
455 | for (h = 0; h < MAX_HWIFS; h++) { | ||
456 | ide_hwif_t *hwif = &ide_hwifs[h]; | ||
457 | |||
458 | if (!hwif->present) | ||
459 | continue; | ||
460 | if (!hwif->proc) { | ||
461 | hwif->proc = proc_mkdir(hwif->name, proc_ide_root); | ||
462 | if (!hwif->proc) | ||
463 | return; | ||
464 | ide_add_proc_entries(hwif->proc, hwif_entries, hwif); | ||
465 | } | ||
466 | create_proc_ide_drives(hwif); | ||
467 | } | ||
468 | } | ||
469 | |||
470 | EXPORT_SYMBOL(create_proc_ide_interfaces); | ||
471 | |||
472 | #ifdef CONFIG_BLK_DEV_IDEPCI | ||
473 | void ide_pci_create_host_proc(const char *name, get_info_t *get_info) | ||
474 | { | ||
475 | create_proc_info_entry(name, 0, proc_ide_root, get_info); | ||
476 | } | ||
477 | |||
478 | EXPORT_SYMBOL_GPL(ide_pci_create_host_proc); | ||
479 | #endif | ||
480 | |||
481 | void destroy_proc_ide_interface(ide_hwif_t *hwif) | ||
482 | { | ||
483 | if (hwif->proc) { | ||
484 | destroy_proc_ide_drives(hwif); | ||
485 | ide_remove_proc_entries(hwif->proc, hwif_entries); | ||
486 | remove_proc_entry(hwif->name, proc_ide_root); | ||
487 | hwif->proc = NULL; | ||
488 | } | ||
489 | } | ||
490 | |||
491 | extern struct seq_operations ide_drivers_op; | ||
492 | static int ide_drivers_open(struct inode *inode, struct file *file) | ||
493 | { | ||
494 | return seq_open(file, &ide_drivers_op); | ||
495 | } | ||
496 | static struct file_operations ide_drivers_operations = { | ||
497 | .open = ide_drivers_open, | ||
498 | .read = seq_read, | ||
499 | .llseek = seq_lseek, | ||
500 | .release = seq_release, | ||
501 | }; | ||
502 | |||
503 | void proc_ide_create(void) | ||
504 | { | ||
505 | struct proc_dir_entry *entry; | ||
506 | |||
507 | if (!proc_ide_root) | ||
508 | return; | ||
509 | |||
510 | create_proc_ide_interfaces(); | ||
511 | |||
512 | entry = create_proc_entry("drivers", 0, proc_ide_root); | ||
513 | if (entry) | ||
514 | entry->proc_fops = &ide_drivers_operations; | ||
515 | } | ||
516 | |||
517 | void proc_ide_destroy(void) | ||
518 | { | ||
519 | remove_proc_entry("ide/drivers", proc_ide_root); | ||
520 | remove_proc_entry("ide", NULL); | ||
521 | } | ||
diff --git a/drivers/ide/ide-tape.c b/drivers/ide/ide-tape.c new file mode 100644 index 000000000000..482544854985 --- /dev/null +++ b/drivers/ide/ide-tape.c | |||
@@ -0,0 +1,4937 @@ | |||
1 | /* | ||
2 | * linux/drivers/ide/ide-tape.c Version 1.19 Nov, 2003 | ||
3 | * | ||
4 | * Copyright (C) 1995 - 1999 Gadi Oxman <gadio@netvision.net.il> | ||
5 | * | ||
6 | * $Header$ | ||
7 | * | ||
8 | * This driver was constructed as a student project in the software laboratory | ||
9 | * of the faculty of electrical engineering in the Technion - Israel's | ||
10 | * Institute Of Technology, with the guide of Avner Lottem and Dr. Ilana David. | ||
11 | * | ||
12 | * It is hereby placed under the terms of the GNU general public license. | ||
13 | * (See linux/COPYING). | ||
14 | */ | ||
15 | |||
16 | /* | ||
17 | * IDE ATAPI streaming tape driver. | ||
18 | * | ||
19 | * This driver is a part of the Linux ide driver and works in co-operation | ||
20 | * with linux/drivers/block/ide.c. | ||
21 | * | ||
22 | * The driver, in co-operation with ide.c, basically traverses the | ||
23 | * request-list for the block device interface. The character device | ||
24 | * interface, on the other hand, creates new requests, adds them | ||
25 | * to the request-list of the block device, and waits for their completion. | ||
26 | * | ||
27 | * Pipelined operation mode is now supported on both reads and writes. | ||
28 | * | ||
29 | * The block device major and minor numbers are determined from the | ||
30 | * tape's relative position in the ide interfaces, as explained in ide.c. | ||
31 | * | ||
32 | * The character device interface consists of the following devices: | ||
33 | * | ||
34 | * ht0 major 37, minor 0 first IDE tape, rewind on close. | ||
35 | * ht1 major 37, minor 1 second IDE tape, rewind on close. | ||
36 | * ... | ||
37 | * nht0 major 37, minor 128 first IDE tape, no rewind on close. | ||
38 | * nht1 major 37, minor 129 second IDE tape, no rewind on close. | ||
39 | * ... | ||
40 | * | ||
41 | * Run linux/scripts/MAKEDEV.ide to create the above entries. | ||
42 | * | ||
43 | * The general magnetic tape commands compatible interface, as defined by | ||
44 | * include/linux/mtio.h, is accessible through the character device. | ||
45 | * | ||
46 | * General ide driver configuration options, such as the interrupt-unmask | ||
47 | * flag, can be configured by issuing an ioctl to the block device interface, | ||
48 | * as any other ide device. | ||
49 | * | ||
50 | * Our own ide-tape ioctl's can be issued to either the block device or | ||
51 | * the character device interface. | ||
52 | * | ||
53 | * Maximal throughput with minimal bus load will usually be achieved in the | ||
54 | * following scenario: | ||
55 | * | ||
56 | * 1. ide-tape is operating in the pipelined operation mode. | ||
57 | * 2. No buffering is performed by the user backup program. | ||
58 | * | ||
59 | * Testing was done with a 2 GB CONNER CTMA 4000 IDE ATAPI Streaming Tape Drive. | ||
60 | * | ||
61 | * Ver 0.1 Nov 1 95 Pre-working code :-) | ||
62 | * Ver 0.2 Nov 23 95 A short backup (few megabytes) and restore procedure | ||
63 | * was successful ! (Using tar cvf ... on the block | ||
64 | * device interface). | ||
65 | * A longer backup resulted in major swapping, bad | ||
66 | * overall Linux performance and eventually failed as | ||
67 | * we received non serial read-ahead requests from the | ||
68 | * buffer cache. | ||
69 | * Ver 0.3 Nov 28 95 Long backups are now possible, thanks to the | ||
70 | * character device interface. Linux's responsiveness | ||
71 | * and performance doesn't seem to be much affected | ||
72 | * from the background backup procedure. | ||
73 | * Some general mtio.h magnetic tape operations are | ||
74 | * now supported by our character device. As a result, | ||
75 | * popular tape utilities are starting to work with | ||
76 | * ide tapes :-) | ||
77 | * The following configurations were tested: | ||
78 | * 1. An IDE ATAPI TAPE shares the same interface | ||
79 | * and irq with an IDE ATAPI CDROM. | ||
80 | * 2. An IDE ATAPI TAPE shares the same interface | ||
81 | * and irq with a normal IDE disk. | ||
82 | * Both configurations seemed to work just fine ! | ||
83 | * However, to be on the safe side, it is meanwhile | ||
84 | * recommended to give the IDE TAPE its own interface | ||
85 | * and irq. | ||
86 | * The one thing which needs to be done here is to | ||
87 | * add a "request postpone" feature to ide.c, | ||
88 | * so that we won't have to wait for the tape to finish | ||
89 | * performing a long media access (DSC) request (such | ||
90 | * as a rewind) before we can access the other device | ||
91 | * on the same interface. This effect doesn't disturb | ||
92 | * normal operation most of the time because read/write | ||
93 | * requests are relatively fast, and once we are | ||
94 | * performing one tape r/w request, a lot of requests | ||
95 | * from the other device can be queued and ide.c will | ||
96 | * service all of them after this single tape request. | ||
97 | * Ver 1.0 Dec 11 95 Integrated into Linux 1.3.46 development tree. | ||
98 | * On each read / write request, we now ask the drive | ||
99 | * if we can transfer a constant number of bytes | ||
100 | * (a parameter of the drive) only to its buffers, | ||
101 | * without causing actual media access. If we can't, | ||
102 | * we just wait until we can by polling the DSC bit. | ||
103 | * This ensures that while we are not transferring | ||
104 | * more bytes than the constant referred to above, the | ||
105 | * interrupt latency will not become too high and | ||
106 | * we won't cause an interrupt timeout, as happened | ||
107 | * occasionally in the previous version. | ||
108 | * While polling for DSC, the current request is | ||
109 | * postponed and ide.c is free to handle requests from | ||
110 | * the other device. This is handled transparently to | ||
111 | * ide.c. The hwgroup locking method which was used | ||
112 | * in the previous version was removed. | ||
113 | * Use of new general features which are provided by | ||
114 | * ide.c for use with atapi devices. | ||
115 | * (Programming done by Mark Lord) | ||
116 | * Few potential bug fixes (Again, suggested by Mark) | ||
117 | * Single character device data transfers are now | ||
118 | * not limited in size, as they were before. | ||
119 | * We are asking the tape about its recommended | ||
120 | * transfer unit and send a larger data transfer | ||
121 | * as several transfers of the above size. | ||
122 | * For best results, use an integral number of this | ||
123 | * basic unit (which is shown during driver | ||
124 | * initialization). I will soon add an ioctl to get | ||
125 | * this important parameter. | ||
126 | * Our data transfer buffer is allocated on startup, | ||
127 | * rather than before each data transfer. This should | ||
128 | * ensure that we will indeed have a data buffer. | ||
129 | * Ver 1.1 Dec 14 95 Fixed random problems which occurred when the tape | ||
130 | * shared an interface with another device. | ||
131 | * (poll_for_dsc was a complete mess). | ||
132 | * Removed some old (non-active) code which had | ||
133 | * to do with supporting buffer cache originated | ||
134 | * requests. | ||
135 | * The block device interface can now be opened, so | ||
136 | * that general ide driver features like the unmask | ||
137 | * interrupts flag can be selected with an ioctl. | ||
138 | * This is the only use of the block device interface. | ||
139 | * New fast pipelined operation mode (currently only on | ||
140 | * writes). When using the pipelined mode, the | ||
141 | * throughput can potentially reach the maximum | ||
142 | * tape supported throughput, regardless of the | ||
143 | * user backup program. On my tape drive, it sometimes | ||
144 | * boosted performance by a factor of 2. Pipelined | ||
145 | * mode is enabled by default, but since it has a few | ||
146 | * downfalls as well, you may want to disable it. | ||
147 | * A short explanation of the pipelined operation mode | ||
148 | * is available below. | ||
149 | * Ver 1.2 Jan 1 96 Eliminated pipelined mode race condition. | ||
150 | * Added pipeline read mode. As a result, restores | ||
151 | * are now as fast as backups. | ||
152 | * Optimized shared interface behavior. The new behavior | ||
153 | * typically results in better IDE bus efficiency and | ||
154 | * higher tape throughput. | ||
155 | * Pre-calculation of the expected read/write request | ||
156 | * service time, based on the tape's parameters. In | ||
157 | * the pipelined operation mode, this allows us to | ||
158 | * adjust our polling frequency to a much lower value, | ||
159 | * and thus to dramatically reduce our load on Linux, | ||
160 | * without any decrease in performance. | ||
161 | * Implemented additional mtio.h operations. | ||
162 | * The recommended user block size is returned by | ||
163 | * the MTIOCGET ioctl. | ||
164 | * Additional minor changes. | ||
165 | * Ver 1.3 Feb 9 96 Fixed pipelined read mode bug which prevented the | ||
166 | * use of some block sizes during a restore procedure. | ||
167 | * The character device interface will now present a | ||
168 | * continuous view of the media - any mix of block sizes | ||
169 | * during a backup/restore procedure is supported. The | ||
170 | * driver will buffer the requests internally and | ||
171 | * convert them to the tape's recommended transfer | ||
172 | * unit, making performance almost independent of the | ||
173 | * chosen user block size. | ||
174 | * Some improvements in error recovery. | ||
175 | * By cooperating with ide-dma.c, bus mastering DMA can | ||
176 | * now sometimes be used with IDE tape drives as well. | ||
177 | * Bus mastering DMA has the potential to dramatically | ||
178 | * reduce the CPU's overhead when accessing the device, | ||
179 | * and can be enabled by using hdparm -d1 on the tape's | ||
180 | * block device interface. For more info, read the | ||
181 | * comments in ide-dma.c. | ||
182 | * Ver 1.4 Mar 13 96 Fixed serialize support. | ||
183 | * Ver 1.5 Apr 12 96 Fixed shared interface operation, broken in 1.3.85. | ||
184 | * Fixed pipelined read mode inefficiency. | ||
185 | * Fixed nasty null dereferencing bug. | ||
186 | * Ver 1.6 Aug 16 96 Fixed FPU usage in the driver. | ||
187 | * Fixed end of media bug. | ||
188 | * Ver 1.7 Sep 10 96 Minor changes for the CONNER CTT8000-A model. | ||
189 | * Ver 1.8 Sep 26 96 Attempt to find a better balance between good | ||
190 | * interactive response and high system throughput. | ||
191 | * Ver 1.9 Nov 5 96 Automatically cross encountered filemarks rather | ||
192 | * than requiring an explicit FSF command. | ||
193 | * Abort pending requests at end of media. | ||
194 | * MTTELL was sometimes returning incorrect results. | ||
195 | * Return the real block size in the MTIOCGET ioctl. | ||
196 | * Some error recovery bug fixes. | ||
197 | * Ver 1.10 Nov 5 96 Major reorganization. | ||
198 | * Reduced CPU overhead a bit by eliminating internal | ||
199 | * bounce buffers. | ||
200 | * Added module support. | ||
201 | * Added multiple tape drives support. | ||
202 | * Added partition support. | ||
203 | * Rewrote DSC handling. | ||
204 | * Some portability fixes. | ||
205 | * Removed ide-tape.h. | ||
206 | * Additional minor changes. | ||
207 | * Ver 1.11 Dec 2 96 Bug fix in previous DSC timeout handling. | ||
208 | * Use ide_stall_queue() for DSC overlap. | ||
209 | * Use the maximum speed rather than the current speed | ||
210 | * to compute the request service time. | ||
211 | * Ver 1.12 Dec 7 97 Fix random memory overwriting and/or last block data | ||
212 | * corruption, which could occur if the total number | ||
213 | * of bytes written to the tape was not an integral | ||
214 | * number of tape blocks. | ||
215 | * Add support for INTERRUPT DRQ devices. | ||
216 | * Ver 1.13 Jan 2 98 Add "speed == 0" work-around for HP COLORADO 5GB | ||
217 | * Ver 1.14 Dec 30 98 Partial fixes for the Sony/AIWA tape drives. | ||
218 | * Replace cli()/sti() with hwgroup spinlocks. | ||
219 | * Ver 1.15 Mar 25 99 Fix SMP race condition by replacing hwgroup | ||
220 | * spinlock with private per-tape spinlock. | ||
221 | * Ver 1.16 Sep 1 99 Add OnStream tape support. | ||
222 | * Abort read pipeline on EOD. | ||
223 | * Wait for the tape to become ready in case it returns | ||
224 | * "in the process of becoming ready" on open(). | ||
225 | * Fix zero padding of the last written block in | ||
226 | * case the tape block size is larger than PAGE_SIZE. | ||
227 | * Decrease the default disconnection time to tn. | ||
228 | * Ver 1.16e Oct 3 99 Minor fixes. | ||
229 | * Ver 1.16e1 Oct 13 99 Patches by Arnold Niessen, | ||
230 | * niessen@iae.nl / arnold.niessen@philips.com | ||
231 | * GO-1) Undefined code in idetape_read_position | ||
232 | * according to Gadi's email | ||
233 | * AJN-1) Minor fix asc == 11 should be asc == 0x11 | ||
234 | * in idetape_issue_packet_command (did effect | ||
235 | * debugging output only) | ||
236 | * AJN-2) Added more debugging output, and | ||
237 | * added ide-tape: where missing. I would also | ||
238 | * like to add tape->name where possible | ||
239 | * AJN-3) Added different debug_level's | ||
240 | * via /proc/ide/hdc/settings | ||
241 | * "debug_level" determines amount of debugging output; | ||
242 | * can be changed using /proc/ide/hdx/settings | ||
243 | * 0 : almost no debugging output | ||
244 | * 1 : 0+output errors only | ||
245 | * 2 : 1+output all sensekey/asc | ||
246 | * 3 : 2+follow all chrdev related procedures | ||
247 | * 4 : 3+follow all procedures | ||
248 | * 5 : 4+include pc_stack rq_stack info | ||
249 | * 6 : 5+USE_COUNT updates | ||
250 | * AJN-4) Fixed timeout for retension in idetape_queue_pc_tail | ||
251 | * from 5 to 10 minutes | ||
252 | * AJN-5) Changed maximum number of blocks to skip when | ||
253 | * reading tapes with multiple consecutive write | ||
254 | * errors from 100 to 1000 in idetape_get_logical_blk | ||
255 | * Proposed changes to code: | ||
256 | * 1) output "logical_blk_num" via /proc | ||
257 | * 2) output "current_operation" via /proc | ||
258 | * 3) Either solve or document the fact that `mt rewind' is | ||
259 | * required after reading from /dev/nhtx to be | ||
260 | * able to rmmod the idetape module; | ||
261 | * Also, sometimes an application finishes but the | ||
262 | * device remains `busy' for some time. Same cause ? | ||
263 | * Proposed changes to release-notes: | ||
264 | * 4) write a simple `quickstart' section in the | ||
265 | * release notes; I volunteer if you don't want to | ||
266 | * 5) include a pointer to video4linux in the doc | ||
267 | * to stimulate video applications | ||
268 | * 6) release notes lines 331 and 362: explain what happens | ||
269 | * if the application data rate is higher than 1100 KB/s; | ||
270 | * similar approach to lower-than-500 kB/s ? | ||
271 | * 7) 6.6 Comparison; wouldn't it be better to allow different | ||
272 | * strategies for read and write ? | ||
273 | * Wouldn't it be better to control the tape buffer | ||
274 | * contents instead of the bandwidth ? | ||
275 | * 8) line 536: replace will by would (if I understand | ||
276 | * this section correctly, a hypothetical and unwanted situation | ||
277 | * is being described) | ||
278 | * Ver 1.16f Dec 15 99 Change place of the secondary OnStream header frames. | ||
279 | * Ver 1.17 Nov 2000 / Jan 2001 Marcel Mol, marcel@mesa.nl | ||
280 | * - Add idetape_onstream_mode_sense_tape_parameter_page | ||
281 | * function to get tape capacity in frames: tape->capacity. | ||
282 | * - Add support for DI-50 drives( or any DI- drive). | ||
283 | * - 'workaround' for read error/blank block around block 3000. | ||
284 | * - Implement Early warning for end of media for Onstream. | ||
285 | * - Cosmetic code changes for readability. | ||
286 | * - Idetape_position_tape should not use SKIP bit during | ||
287 | * Onstream read recovery. | ||
288 | * - Add capacity, logical_blk_num and first/last_frame_position | ||
289 | * to /proc/ide/hd?/settings. | ||
290 | * - Module use count was gone in the Linux 2.4 driver. | ||
291 | * Ver 1.17a Apr 2001 Willem Riede osst@riede.org | ||
292 | * - Get drive's actual block size from mode sense block descriptor | ||
293 | * - Limit size of pipeline | ||
294 | * Ver 1.17b Oct 2002 Alan Stern <stern@rowland.harvard.edu> | ||
295 | * Changed IDETAPE_MIN_PIPELINE_STAGES to 1 and actually used | ||
296 | * it in the code! | ||
297 | * Actually removed aborted stages in idetape_abort_pipeline | ||
298 | * instead of just changing the command code. | ||
299 | * Made the transfer byte count for Request Sense equal to the | ||
300 | * actual length of the data transfer. | ||
301 | * Changed handling of partial data transfers: they do not | ||
302 | * cause DMA errors. | ||
303 | * Moved initiation of DMA transfers to the correct place. | ||
304 | * Removed reference to unallocated memory. | ||
305 | * Made __idetape_discard_read_pipeline return the number of | ||
306 | * sectors skipped, not the number of stages. | ||
307 | * Replaced errant kfree() calls with __idetape_kfree_stage(). | ||
308 | * Fixed off-by-one error in testing the pipeline length. | ||
309 | * Fixed handling of filemarks in the read pipeline. | ||
310 | * Small code optimization for MTBSF and MTBSFM ioctls. | ||
311 | * Don't try to unlock the door during device close if is | ||
312 | * already unlocked! | ||
313 | * Cosmetic fixes to miscellaneous debugging output messages. | ||
314 | * Set the minimum /proc/ide/hd?/settings values for "pipeline", | ||
315 | * "pipeline_min", and "pipeline_max" to 1. | ||
316 | * | ||
317 | * Here are some words from the first releases of hd.c, which are quoted | ||
318 | * in ide.c and apply here as well: | ||
319 | * | ||
320 | * | Special care is recommended. Have Fun! | ||
321 | * | ||
322 | */ | ||
323 | |||
324 | /* | ||
325 | * An overview of the pipelined operation mode. | ||
326 | * | ||
327 | * In the pipelined write mode, we will usually just add requests to our | ||
328 | * pipeline and return immediately, before we even start to service them. The | ||
329 | * user program will then have enough time to prepare the next request while | ||
330 | * we are still busy servicing previous requests. In the pipelined read mode, | ||
331 | * the situation is similar - we add read-ahead requests into the pipeline, | ||
332 | * before the user even requested them. | ||
333 | * | ||
334 | * The pipeline can be viewed as a "safety net" which will be activated when | ||
335 | * the system load is high and prevents the user backup program from keeping up | ||
336 | * with the current tape speed. At this point, the pipeline will get | ||
337 | * shorter and shorter but the tape will still be streaming at the same speed. | ||
338 | * Assuming we have enough pipeline stages, the system load will hopefully | ||
339 | * decrease before the pipeline is completely empty, and the backup program | ||
340 | * will be able to "catch up" and refill the pipeline again. | ||
341 | * | ||
342 | * When using the pipelined mode, it would be best to disable any type of | ||
343 | * buffering done by the user program, as ide-tape already provides all the | ||
344 | * benefits in the kernel, where it can be done in a more efficient way. | ||
345 | * As we will usually not block the user program on a request, the most | ||
346 | * efficient user code will then be a simple read-write-read-... cycle. | ||
347 | * Any additional logic will usually just slow down the backup process. | ||
348 | * | ||
349 | * Using the pipelined mode, I get a constant over 400 KBps throughput, | ||
350 | * which seems to be the maximum throughput supported by my tape. | ||
351 | * | ||
352 | * However, there are some downfalls: | ||
353 | * | ||
354 | * 1. We use memory (for data buffers) in proportional to the number | ||
355 | * of pipeline stages (each stage is about 26 KB with my tape). | ||
356 | * 2. In the pipelined write mode, we cheat and postpone error codes | ||
357 | * to the user task. In read mode, the actual tape position | ||
358 | * will be a bit further than the last requested block. | ||
359 | * | ||
360 | * Concerning (1): | ||
361 | * | ||
362 | * 1. We allocate stages dynamically only when we need them. When | ||
363 | * we don't need them, we don't consume additional memory. In | ||
364 | * case we can't allocate stages, we just manage without them | ||
365 | * (at the expense of decreased throughput) so when Linux is | ||
366 | * tight in memory, we will not pose additional difficulties. | ||
367 | * | ||
368 | * 2. The maximum number of stages (which is, in fact, the maximum | ||
369 | * amount of memory) which we allocate is limited by the compile | ||
370 | * time parameter IDETAPE_MAX_PIPELINE_STAGES. | ||
371 | * | ||
372 | * 3. The maximum number of stages is a controlled parameter - We | ||
373 | * don't start from the user defined maximum number of stages | ||
374 | * but from the lower IDETAPE_MIN_PIPELINE_STAGES (again, we | ||
375 | * will not even allocate this amount of stages if the user | ||
376 | * program can't handle the speed). We then implement a feedback | ||
377 | * loop which checks if the pipeline is empty, and if it is, we | ||
378 | * increase the maximum number of stages as necessary until we | ||
379 | * reach the optimum value which just manages to keep the tape | ||
380 | * busy with minimum allocated memory or until we reach | ||
381 | * IDETAPE_MAX_PIPELINE_STAGES. | ||
382 | * | ||
383 | * Concerning (2): | ||
384 | * | ||
385 | * In pipelined write mode, ide-tape can not return accurate error codes | ||
386 | * to the user program since we usually just add the request to the | ||
387 | * pipeline without waiting for it to be serviced. In case an error | ||
388 | * occurs, I will report it on the next user request. | ||
389 | * | ||
390 | * In the pipelined read mode, subsequent read requests or forward | ||
391 | * filemark spacing will perform correctly, as we preserve all blocks | ||
392 | * and filemarks which we encountered during our excess read-ahead. | ||
393 | * | ||
394 | * For accurate tape positioning and error reporting, disabling | ||
395 | * pipelined mode might be the best option. | ||
396 | * | ||
397 | * You can enable/disable/tune the pipelined operation mode by adjusting | ||
398 | * the compile time parameters below. | ||
399 | */ | ||
400 | |||
401 | /* | ||
402 | * Possible improvements. | ||
403 | * | ||
404 | * 1. Support for the ATAPI overlap protocol. | ||
405 | * | ||
406 | * In order to maximize bus throughput, we currently use the DSC | ||
407 | * overlap method which enables ide.c to service requests from the | ||
408 | * other device while the tape is busy executing a command. The | ||
409 | * DSC overlap method involves polling the tape's status register | ||
410 | * for the DSC bit, and servicing the other device while the tape | ||
411 | * isn't ready. | ||
412 | * | ||
413 | * In the current QIC development standard (December 1995), | ||
414 | * it is recommended that new tape drives will *in addition* | ||
415 | * implement the ATAPI overlap protocol, which is used for the | ||
416 | * same purpose - efficient use of the IDE bus, but is interrupt | ||
417 | * driven and thus has much less CPU overhead. | ||
418 | * | ||
419 | * ATAPI overlap is likely to be supported in most new ATAPI | ||
420 | * devices, including new ATAPI cdroms, and thus provides us | ||
421 | * a method by which we can achieve higher throughput when | ||
422 | * sharing a (fast) ATA-2 disk with any (slow) new ATAPI device. | ||
423 | */ | ||
424 | |||
425 | #define IDETAPE_VERSION "1.19" | ||
426 | |||
427 | #include <linux/config.h> | ||
428 | #include <linux/module.h> | ||
429 | #include <linux/types.h> | ||
430 | #include <linux/string.h> | ||
431 | #include <linux/kernel.h> | ||
432 | #include <linux/delay.h> | ||
433 | #include <linux/timer.h> | ||
434 | #include <linux/mm.h> | ||
435 | #include <linux/interrupt.h> | ||
436 | #include <linux/major.h> | ||
437 | #include <linux/devfs_fs_kernel.h> | ||
438 | #include <linux/errno.h> | ||
439 | #include <linux/genhd.h> | ||
440 | #include <linux/slab.h> | ||
441 | #include <linux/pci.h> | ||
442 | #include <linux/ide.h> | ||
443 | #include <linux/smp_lock.h> | ||
444 | #include <linux/completion.h> | ||
445 | #include <linux/bitops.h> | ||
446 | |||
447 | #include <asm/byteorder.h> | ||
448 | #include <asm/irq.h> | ||
449 | #include <asm/uaccess.h> | ||
450 | #include <asm/io.h> | ||
451 | #include <asm/unaligned.h> | ||
452 | |||
453 | /* | ||
454 | * partition | ||
455 | */ | ||
456 | typedef struct os_partition_s { | ||
457 | __u8 partition_num; | ||
458 | __u8 par_desc_ver; | ||
459 | __u16 wrt_pass_cntr; | ||
460 | __u32 first_frame_addr; | ||
461 | __u32 last_frame_addr; | ||
462 | __u32 eod_frame_addr; | ||
463 | } os_partition_t; | ||
464 | |||
465 | /* | ||
466 | * DAT entry | ||
467 | */ | ||
468 | typedef struct os_dat_entry_s { | ||
469 | __u32 blk_sz; | ||
470 | __u16 blk_cnt; | ||
471 | __u8 flags; | ||
472 | __u8 reserved; | ||
473 | } os_dat_entry_t; | ||
474 | |||
475 | /* | ||
476 | * DAT | ||
477 | */ | ||
478 | #define OS_DAT_FLAGS_DATA (0xc) | ||
479 | #define OS_DAT_FLAGS_MARK (0x1) | ||
480 | |||
481 | typedef struct os_dat_s { | ||
482 | __u8 dat_sz; | ||
483 | __u8 reserved1; | ||
484 | __u8 entry_cnt; | ||
485 | __u8 reserved3; | ||
486 | os_dat_entry_t dat_list[16]; | ||
487 | } os_dat_t; | ||
488 | |||
489 | #include <linux/mtio.h> | ||
490 | |||
491 | /**************************** Tunable parameters *****************************/ | ||
492 | |||
493 | |||
494 | /* | ||
495 | * Pipelined mode parameters. | ||
496 | * | ||
497 | * We try to use the minimum number of stages which is enough to | ||
498 | * keep the tape constantly streaming. To accomplish that, we implement | ||
499 | * a feedback loop around the maximum number of stages: | ||
500 | * | ||
501 | * We start from MIN maximum stages (we will not even use MIN stages | ||
502 | * if we don't need them), increment it by RATE*(MAX-MIN) | ||
503 | * whenever we sense that the pipeline is empty, until we reach | ||
504 | * the optimum value or until we reach MAX. | ||
505 | * | ||
506 | * Setting the following parameter to 0 is illegal: the pipelined mode | ||
507 | * cannot be disabled (calculate_speeds() divides by tape->max_stages.) | ||
508 | */ | ||
509 | #define IDETAPE_MIN_PIPELINE_STAGES 1 | ||
510 | #define IDETAPE_MAX_PIPELINE_STAGES 400 | ||
511 | #define IDETAPE_INCREASE_STAGES_RATE 20 | ||
512 | |||
513 | /* | ||
514 | * The following are used to debug the driver: | ||
515 | * | ||
516 | * Setting IDETAPE_DEBUG_INFO to 1 will report device capabilities. | ||
517 | * Setting IDETAPE_DEBUG_LOG to 1 will log driver flow control. | ||
518 | * Setting IDETAPE_DEBUG_BUGS to 1 will enable self-sanity checks in | ||
519 | * some places. | ||
520 | * | ||
521 | * Setting them to 0 will restore normal operation mode: | ||
522 | * | ||
523 | * 1. Disable logging normal successful operations. | ||
524 | * 2. Disable self-sanity checks. | ||
525 | * 3. Errors will still be logged, of course. | ||
526 | * | ||
527 | * All the #if DEBUG code will be removed some day, when the driver | ||
528 | * is verified to be stable enough. This will make it much more | ||
529 | * esthetic. | ||
530 | */ | ||
531 | #define IDETAPE_DEBUG_INFO 0 | ||
532 | #define IDETAPE_DEBUG_LOG 0 | ||
533 | #define IDETAPE_DEBUG_BUGS 1 | ||
534 | |||
535 | /* | ||
536 | * After each failed packet command we issue a request sense command | ||
537 | * and retry the packet command IDETAPE_MAX_PC_RETRIES times. | ||
538 | * | ||
539 | * Setting IDETAPE_MAX_PC_RETRIES to 0 will disable retries. | ||
540 | */ | ||
541 | #define IDETAPE_MAX_PC_RETRIES 3 | ||
542 | |||
543 | /* | ||
544 | * With each packet command, we allocate a buffer of | ||
545 | * IDETAPE_PC_BUFFER_SIZE bytes. This is used for several packet | ||
546 | * commands (Not for READ/WRITE commands). | ||
547 | */ | ||
548 | #define IDETAPE_PC_BUFFER_SIZE 256 | ||
549 | |||
550 | /* | ||
551 | * In various places in the driver, we need to allocate storage | ||
552 | * for packet commands and requests, which will remain valid while | ||
553 | * we leave the driver to wait for an interrupt or a timeout event. | ||
554 | */ | ||
555 | #define IDETAPE_PC_STACK (10 + IDETAPE_MAX_PC_RETRIES) | ||
556 | |||
557 | /* | ||
558 | * Some drives (for example, Seagate STT3401A Travan) require a very long | ||
559 | * timeout, because they don't return an interrupt or clear their busy bit | ||
560 | * until after the command completes (even retension commands). | ||
561 | */ | ||
562 | #define IDETAPE_WAIT_CMD (900*HZ) | ||
563 | |||
564 | /* | ||
565 | * The following parameter is used to select the point in the internal | ||
566 | * tape fifo in which we will start to refill the buffer. Decreasing | ||
567 | * the following parameter will improve the system's latency and | ||
568 | * interactive response, while using a high value might improve sytem | ||
569 | * throughput. | ||
570 | */ | ||
571 | #define IDETAPE_FIFO_THRESHOLD 2 | ||
572 | |||
573 | /* | ||
574 | * DSC polling parameters. | ||
575 | * | ||
576 | * Polling for DSC (a single bit in the status register) is a very | ||
577 | * important function in ide-tape. There are two cases in which we | ||
578 | * poll for DSC: | ||
579 | * | ||
580 | * 1. Before a read/write packet command, to ensure that we | ||
581 | * can transfer data from/to the tape's data buffers, without | ||
582 | * causing an actual media access. In case the tape is not | ||
583 | * ready yet, we take out our request from the device | ||
584 | * request queue, so that ide.c will service requests from | ||
585 | * the other device on the same interface meanwhile. | ||
586 | * | ||
587 | * 2. After the successful initialization of a "media access | ||
588 | * packet command", which is a command which can take a long | ||
589 | * time to complete (it can be several seconds or even an hour). | ||
590 | * | ||
591 | * Again, we postpone our request in the middle to free the bus | ||
592 | * for the other device. The polling frequency here should be | ||
593 | * lower than the read/write frequency since those media access | ||
594 | * commands are slow. We start from a "fast" frequency - | ||
595 | * IDETAPE_DSC_MA_FAST (one second), and if we don't receive DSC | ||
596 | * after IDETAPE_DSC_MA_THRESHOLD (5 minutes), we switch it to a | ||
597 | * lower frequency - IDETAPE_DSC_MA_SLOW (1 minute). | ||
598 | * | ||
599 | * We also set a timeout for the timer, in case something goes wrong. | ||
600 | * The timeout should be longer then the maximum execution time of a | ||
601 | * tape operation. | ||
602 | */ | ||
603 | |||
604 | /* | ||
605 | * DSC timings. | ||
606 | */ | ||
607 | #define IDETAPE_DSC_RW_MIN 5*HZ/100 /* 50 msec */ | ||
608 | #define IDETAPE_DSC_RW_MAX 40*HZ/100 /* 400 msec */ | ||
609 | #define IDETAPE_DSC_RW_TIMEOUT 2*60*HZ /* 2 minutes */ | ||
610 | #define IDETAPE_DSC_MA_FAST 2*HZ /* 2 seconds */ | ||
611 | #define IDETAPE_DSC_MA_THRESHOLD 5*60*HZ /* 5 minutes */ | ||
612 | #define IDETAPE_DSC_MA_SLOW 30*HZ /* 30 seconds */ | ||
613 | #define IDETAPE_DSC_MA_TIMEOUT 2*60*60*HZ /* 2 hours */ | ||
614 | |||
615 | /*************************** End of tunable parameters ***********************/ | ||
616 | |||
617 | /* | ||
618 | * Debugging/Performance analysis | ||
619 | * | ||
620 | * I/O trace support | ||
621 | */ | ||
622 | #define USE_IOTRACE 0 | ||
623 | #if USE_IOTRACE | ||
624 | #include <linux/io_trace.h> | ||
625 | #define IO_IDETAPE_FIFO 500 | ||
626 | #endif | ||
627 | |||
628 | /* | ||
629 | * Read/Write error simulation | ||
630 | */ | ||
631 | #define SIMULATE_ERRORS 0 | ||
632 | |||
633 | /* | ||
634 | * For general magnetic tape device compatibility. | ||
635 | */ | ||
636 | typedef enum { | ||
637 | idetape_direction_none, | ||
638 | idetape_direction_read, | ||
639 | idetape_direction_write | ||
640 | } idetape_chrdev_direction_t; | ||
641 | |||
642 | struct idetape_bh { | ||
643 | unsigned short b_size; | ||
644 | atomic_t b_count; | ||
645 | struct idetape_bh *b_reqnext; | ||
646 | char *b_data; | ||
647 | }; | ||
648 | |||
649 | /* | ||
650 | * Our view of a packet command. | ||
651 | */ | ||
652 | typedef struct idetape_packet_command_s { | ||
653 | u8 c[12]; /* Actual packet bytes */ | ||
654 | int retries; /* On each retry, we increment retries */ | ||
655 | int error; /* Error code */ | ||
656 | int request_transfer; /* Bytes to transfer */ | ||
657 | int actually_transferred; /* Bytes actually transferred */ | ||
658 | int buffer_size; /* Size of our data buffer */ | ||
659 | struct idetape_bh *bh; | ||
660 | char *b_data; | ||
661 | int b_count; | ||
662 | u8 *buffer; /* Data buffer */ | ||
663 | u8 *current_position; /* Pointer into the above buffer */ | ||
664 | ide_startstop_t (*callback) (ide_drive_t *); /* Called when this packet command is completed */ | ||
665 | u8 pc_buffer[IDETAPE_PC_BUFFER_SIZE]; /* Temporary buffer */ | ||
666 | unsigned long flags; /* Status/Action bit flags: long for set_bit */ | ||
667 | } idetape_pc_t; | ||
668 | |||
669 | /* | ||
670 | * Packet command flag bits. | ||
671 | */ | ||
672 | /* Set when an error is considered normal - We won't retry */ | ||
673 | #define PC_ABORT 0 | ||
674 | /* 1 When polling for DSC on a media access command */ | ||
675 | #define PC_WAIT_FOR_DSC 1 | ||
676 | /* 1 when we prefer to use DMA if possible */ | ||
677 | #define PC_DMA_RECOMMENDED 2 | ||
678 | /* 1 while DMA in progress */ | ||
679 | #define PC_DMA_IN_PROGRESS 3 | ||
680 | /* 1 when encountered problem during DMA */ | ||
681 | #define PC_DMA_ERROR 4 | ||
682 | /* Data direction */ | ||
683 | #define PC_WRITING 5 | ||
684 | |||
685 | /* | ||
686 | * Capabilities and Mechanical Status Page | ||
687 | */ | ||
688 | typedef struct { | ||
689 | unsigned page_code :6; /* Page code - Should be 0x2a */ | ||
690 | __u8 reserved0_6 :1; | ||
691 | __u8 ps :1; /* parameters saveable */ | ||
692 | __u8 page_length; /* Page Length - Should be 0x12 */ | ||
693 | __u8 reserved2, reserved3; | ||
694 | unsigned ro :1; /* Read Only Mode */ | ||
695 | unsigned reserved4_1234 :4; | ||
696 | unsigned sprev :1; /* Supports SPACE in the reverse direction */ | ||
697 | unsigned reserved4_67 :2; | ||
698 | unsigned reserved5_012 :3; | ||
699 | unsigned efmt :1; /* Supports ERASE command initiated formatting */ | ||
700 | unsigned reserved5_4 :1; | ||
701 | unsigned qfa :1; /* Supports the QFA two partition formats */ | ||
702 | unsigned reserved5_67 :2; | ||
703 | unsigned lock :1; /* Supports locking the volume */ | ||
704 | unsigned locked :1; /* The volume is locked */ | ||
705 | unsigned prevent :1; /* The device defaults in the prevent state after power up */ | ||
706 | unsigned eject :1; /* The device can eject the volume */ | ||
707 | __u8 disconnect :1; /* The device can break request > ctl */ | ||
708 | __u8 reserved6_5 :1; | ||
709 | unsigned ecc :1; /* Supports error correction */ | ||
710 | unsigned cmprs :1; /* Supports data compression */ | ||
711 | unsigned reserved7_0 :1; | ||
712 | unsigned blk512 :1; /* Supports 512 bytes block size */ | ||
713 | unsigned blk1024 :1; /* Supports 1024 bytes block size */ | ||
714 | unsigned reserved7_3_6 :4; | ||
715 | unsigned blk32768 :1; /* slowb - the device restricts the byte count for PIO */ | ||
716 | /* transfers for slow buffer memory ??? */ | ||
717 | /* Also 32768 block size in some cases */ | ||
718 | __u16 max_speed; /* Maximum speed supported in KBps */ | ||
719 | __u8 reserved10, reserved11; | ||
720 | __u16 ctl; /* Continuous Transfer Limit in blocks */ | ||
721 | __u16 speed; /* Current Speed, in KBps */ | ||
722 | __u16 buffer_size; /* Buffer Size, in 512 bytes */ | ||
723 | __u8 reserved18, reserved19; | ||
724 | } idetape_capabilities_page_t; | ||
725 | |||
726 | /* | ||
727 | * Block Size Page | ||
728 | */ | ||
729 | typedef struct { | ||
730 | unsigned page_code :6; /* Page code - Should be 0x30 */ | ||
731 | unsigned reserved1_6 :1; | ||
732 | unsigned ps :1; | ||
733 | __u8 page_length; /* Page Length - Should be 2 */ | ||
734 | __u8 reserved2; | ||
735 | unsigned play32 :1; | ||
736 | unsigned play32_5 :1; | ||
737 | unsigned reserved2_23 :2; | ||
738 | unsigned record32 :1; | ||
739 | unsigned record32_5 :1; | ||
740 | unsigned reserved2_6 :1; | ||
741 | unsigned one :1; | ||
742 | } idetape_block_size_page_t; | ||
743 | |||
744 | /* | ||
745 | * A pipeline stage. | ||
746 | */ | ||
747 | typedef struct idetape_stage_s { | ||
748 | struct request rq; /* The corresponding request */ | ||
749 | struct idetape_bh *bh; /* The data buffers */ | ||
750 | struct idetape_stage_s *next; /* Pointer to the next stage */ | ||
751 | } idetape_stage_t; | ||
752 | |||
753 | /* | ||
754 | * REQUEST SENSE packet command result - Data Format. | ||
755 | */ | ||
756 | typedef struct { | ||
757 | unsigned error_code :7; /* Current of deferred errors */ | ||
758 | unsigned valid :1; /* The information field conforms to QIC-157C */ | ||
759 | __u8 reserved1 :8; /* Segment Number - Reserved */ | ||
760 | unsigned sense_key :4; /* Sense Key */ | ||
761 | unsigned reserved2_4 :1; /* Reserved */ | ||
762 | unsigned ili :1; /* Incorrect Length Indicator */ | ||
763 | unsigned eom :1; /* End Of Medium */ | ||
764 | unsigned filemark :1; /* Filemark */ | ||
765 | __u32 information __attribute__ ((packed)); | ||
766 | __u8 asl; /* Additional sense length (n-7) */ | ||
767 | __u32 command_specific; /* Additional command specific information */ | ||
768 | __u8 asc; /* Additional Sense Code */ | ||
769 | __u8 ascq; /* Additional Sense Code Qualifier */ | ||
770 | __u8 replaceable_unit_code; /* Field Replaceable Unit Code */ | ||
771 | unsigned sk_specific1 :7; /* Sense Key Specific */ | ||
772 | unsigned sksv :1; /* Sense Key Specific information is valid */ | ||
773 | __u8 sk_specific2; /* Sense Key Specific */ | ||
774 | __u8 sk_specific3; /* Sense Key Specific */ | ||
775 | __u8 pad[2]; /* Padding to 20 bytes */ | ||
776 | } idetape_request_sense_result_t; | ||
777 | |||
778 | |||
779 | /* | ||
780 | * Most of our global data which we need to save even as we leave the | ||
781 | * driver due to an interrupt or a timer event is stored in a variable | ||
782 | * of type idetape_tape_t, defined below. | ||
783 | */ | ||
784 | typedef struct ide_tape_obj { | ||
785 | ide_drive_t *drive; | ||
786 | ide_driver_t *driver; | ||
787 | struct gendisk *disk; | ||
788 | struct kref kref; | ||
789 | |||
790 | /* | ||
791 | * Since a typical character device operation requires more | ||
792 | * than one packet command, we provide here enough memory | ||
793 | * for the maximum of interconnected packet commands. | ||
794 | * The packet commands are stored in the circular array pc_stack. | ||
795 | * pc_stack_index points to the last used entry, and warps around | ||
796 | * to the start when we get to the last array entry. | ||
797 | * | ||
798 | * pc points to the current processed packet command. | ||
799 | * | ||
800 | * failed_pc points to the last failed packet command, or contains | ||
801 | * NULL if we do not need to retry any packet command. This is | ||
802 | * required since an additional packet command is needed before the | ||
803 | * retry, to get detailed information on what went wrong. | ||
804 | */ | ||
805 | /* Current packet command */ | ||
806 | idetape_pc_t *pc; | ||
807 | /* Last failed packet command */ | ||
808 | idetape_pc_t *failed_pc; | ||
809 | /* Packet command stack */ | ||
810 | idetape_pc_t pc_stack[IDETAPE_PC_STACK]; | ||
811 | /* Next free packet command storage space */ | ||
812 | int pc_stack_index; | ||
813 | struct request rq_stack[IDETAPE_PC_STACK]; | ||
814 | /* We implement a circular array */ | ||
815 | int rq_stack_index; | ||
816 | |||
817 | /* | ||
818 | * DSC polling variables. | ||
819 | * | ||
820 | * While polling for DSC we use postponed_rq to postpone the | ||
821 | * current request so that ide.c will be able to service | ||
822 | * pending requests on the other device. Note that at most | ||
823 | * we will have only one DSC (usually data transfer) request | ||
824 | * in the device request queue. Additional requests can be | ||
825 | * queued in our internal pipeline, but they will be visible | ||
826 | * to ide.c only one at a time. | ||
827 | */ | ||
828 | struct request *postponed_rq; | ||
829 | /* The time in which we started polling for DSC */ | ||
830 | unsigned long dsc_polling_start; | ||
831 | /* Timer used to poll for dsc */ | ||
832 | struct timer_list dsc_timer; | ||
833 | /* Read/Write dsc polling frequency */ | ||
834 | unsigned long best_dsc_rw_frequency; | ||
835 | /* The current polling frequency */ | ||
836 | unsigned long dsc_polling_frequency; | ||
837 | /* Maximum waiting time */ | ||
838 | unsigned long dsc_timeout; | ||
839 | |||
840 | /* | ||
841 | * Read position information | ||
842 | */ | ||
843 | u8 partition; | ||
844 | /* Current block */ | ||
845 | unsigned int first_frame_position; | ||
846 | unsigned int last_frame_position; | ||
847 | unsigned int blocks_in_buffer; | ||
848 | |||
849 | /* | ||
850 | * Last error information | ||
851 | */ | ||
852 | u8 sense_key, asc, ascq; | ||
853 | |||
854 | /* | ||
855 | * Character device operation | ||
856 | */ | ||
857 | unsigned int minor; | ||
858 | /* device name */ | ||
859 | char name[4]; | ||
860 | /* Current character device data transfer direction */ | ||
861 | idetape_chrdev_direction_t chrdev_direction; | ||
862 | |||
863 | /* | ||
864 | * Device information | ||
865 | */ | ||
866 | /* Usually 512 or 1024 bytes */ | ||
867 | unsigned short tape_block_size; | ||
868 | int user_bs_factor; | ||
869 | /* Copy of the tape's Capabilities and Mechanical Page */ | ||
870 | idetape_capabilities_page_t capabilities; | ||
871 | |||
872 | /* | ||
873 | * Active data transfer request parameters. | ||
874 | * | ||
875 | * At most, there is only one ide-tape originated data transfer | ||
876 | * request in the device request queue. This allows ide.c to | ||
877 | * easily service requests from the other device when we | ||
878 | * postpone our active request. In the pipelined operation | ||
879 | * mode, we use our internal pipeline structure to hold | ||
880 | * more data requests. | ||
881 | * | ||
882 | * The data buffer size is chosen based on the tape's | ||
883 | * recommendation. | ||
884 | */ | ||
885 | /* Pointer to the request which is waiting in the device request queue */ | ||
886 | struct request *active_data_request; | ||
887 | /* Data buffer size (chosen based on the tape's recommendation */ | ||
888 | int stage_size; | ||
889 | idetape_stage_t *merge_stage; | ||
890 | int merge_stage_size; | ||
891 | struct idetape_bh *bh; | ||
892 | char *b_data; | ||
893 | int b_count; | ||
894 | |||
895 | /* | ||
896 | * Pipeline parameters. | ||
897 | * | ||
898 | * To accomplish non-pipelined mode, we simply set the following | ||
899 | * variables to zero (or NULL, where appropriate). | ||
900 | */ | ||
901 | /* Number of currently used stages */ | ||
902 | int nr_stages; | ||
903 | /* Number of pending stages */ | ||
904 | int nr_pending_stages; | ||
905 | /* We will not allocate more than this number of stages */ | ||
906 | int max_stages, min_pipeline, max_pipeline; | ||
907 | /* The first stage which will be removed from the pipeline */ | ||
908 | idetape_stage_t *first_stage; | ||
909 | /* The currently active stage */ | ||
910 | idetape_stage_t *active_stage; | ||
911 | /* Will be serviced after the currently active request */ | ||
912 | idetape_stage_t *next_stage; | ||
913 | /* New requests will be added to the pipeline here */ | ||
914 | idetape_stage_t *last_stage; | ||
915 | /* Optional free stage which we can use */ | ||
916 | idetape_stage_t *cache_stage; | ||
917 | int pages_per_stage; | ||
918 | /* Wasted space in each stage */ | ||
919 | int excess_bh_size; | ||
920 | |||
921 | /* Status/Action flags: long for set_bit */ | ||
922 | unsigned long flags; | ||
923 | /* protects the ide-tape queue */ | ||
924 | spinlock_t spinlock; | ||
925 | |||
926 | /* | ||
927 | * Measures average tape speed | ||
928 | */ | ||
929 | unsigned long avg_time; | ||
930 | int avg_size; | ||
931 | int avg_speed; | ||
932 | |||
933 | /* last sense information */ | ||
934 | idetape_request_sense_result_t sense; | ||
935 | |||
936 | char vendor_id[10]; | ||
937 | char product_id[18]; | ||
938 | char firmware_revision[6]; | ||
939 | int firmware_revision_num; | ||
940 | |||
941 | /* the door is currently locked */ | ||
942 | int door_locked; | ||
943 | /* the tape hardware is write protected */ | ||
944 | char drv_write_prot; | ||
945 | /* the tape is write protected (hardware or opened as read-only) */ | ||
946 | char write_prot; | ||
947 | |||
948 | /* | ||
949 | * Limit the number of times a request can | ||
950 | * be postponed, to avoid an infinite postpone | ||
951 | * deadlock. | ||
952 | */ | ||
953 | /* request postpone count limit */ | ||
954 | int postpone_cnt; | ||
955 | |||
956 | /* | ||
957 | * Measures number of frames: | ||
958 | * | ||
959 | * 1. written/read to/from the driver pipeline (pipeline_head). | ||
960 | * 2. written/read to/from the tape buffers (idetape_bh). | ||
961 | * 3. written/read by the tape to/from the media (tape_head). | ||
962 | */ | ||
963 | int pipeline_head; | ||
964 | int buffer_head; | ||
965 | int tape_head; | ||
966 | int last_tape_head; | ||
967 | |||
968 | /* | ||
969 | * Speed control at the tape buffers input/output | ||
970 | */ | ||
971 | unsigned long insert_time; | ||
972 | int insert_size; | ||
973 | int insert_speed; | ||
974 | int max_insert_speed; | ||
975 | int measure_insert_time; | ||
976 | |||
977 | /* | ||
978 | * Measure tape still time, in milliseconds | ||
979 | */ | ||
980 | unsigned long tape_still_time_begin; | ||
981 | int tape_still_time; | ||
982 | |||
983 | /* | ||
984 | * Speed regulation negative feedback loop | ||
985 | */ | ||
986 | int speed_control; | ||
987 | int pipeline_head_speed; | ||
988 | int controlled_pipeline_head_speed; | ||
989 | int uncontrolled_pipeline_head_speed; | ||
990 | int controlled_last_pipeline_head; | ||
991 | int uncontrolled_last_pipeline_head; | ||
992 | unsigned long uncontrolled_pipeline_head_time; | ||
993 | unsigned long controlled_pipeline_head_time; | ||
994 | int controlled_previous_pipeline_head; | ||
995 | int uncontrolled_previous_pipeline_head; | ||
996 | unsigned long controlled_previous_head_time; | ||
997 | unsigned long uncontrolled_previous_head_time; | ||
998 | int restart_speed_control_req; | ||
999 | |||
1000 | /* | ||
1001 | * Debug_level determines amount of debugging output; | ||
1002 | * can be changed using /proc/ide/hdx/settings | ||
1003 | * 0 : almost no debugging output | ||
1004 | * 1 : 0+output errors only | ||
1005 | * 2 : 1+output all sensekey/asc | ||
1006 | * 3 : 2+follow all chrdev related procedures | ||
1007 | * 4 : 3+follow all procedures | ||
1008 | * 5 : 4+include pc_stack rq_stack info | ||
1009 | * 6 : 5+USE_COUNT updates | ||
1010 | */ | ||
1011 | int debug_level; | ||
1012 | } idetape_tape_t; | ||
1013 | |||
1014 | static DECLARE_MUTEX(idetape_ref_sem); | ||
1015 | |||
1016 | #define to_ide_tape(obj) container_of(obj, struct ide_tape_obj, kref) | ||
1017 | |||
1018 | #define ide_tape_g(disk) \ | ||
1019 | container_of((disk)->private_data, struct ide_tape_obj, driver) | ||
1020 | |||
1021 | static struct ide_tape_obj *ide_tape_get(struct gendisk *disk) | ||
1022 | { | ||
1023 | struct ide_tape_obj *tape = NULL; | ||
1024 | |||
1025 | down(&idetape_ref_sem); | ||
1026 | tape = ide_tape_g(disk); | ||
1027 | if (tape) | ||
1028 | kref_get(&tape->kref); | ||
1029 | up(&idetape_ref_sem); | ||
1030 | return tape; | ||
1031 | } | ||
1032 | |||
1033 | static void ide_tape_release(struct kref *); | ||
1034 | |||
1035 | static void ide_tape_put(struct ide_tape_obj *tape) | ||
1036 | { | ||
1037 | down(&idetape_ref_sem); | ||
1038 | kref_put(&tape->kref, ide_tape_release); | ||
1039 | up(&idetape_ref_sem); | ||
1040 | } | ||
1041 | |||
1042 | /* | ||
1043 | * Tape door status | ||
1044 | */ | ||
1045 | #define DOOR_UNLOCKED 0 | ||
1046 | #define DOOR_LOCKED 1 | ||
1047 | #define DOOR_EXPLICITLY_LOCKED 2 | ||
1048 | |||
1049 | /* | ||
1050 | * Tape flag bits values. | ||
1051 | */ | ||
1052 | #define IDETAPE_IGNORE_DSC 0 | ||
1053 | #define IDETAPE_ADDRESS_VALID 1 /* 0 When the tape position is unknown */ | ||
1054 | #define IDETAPE_BUSY 2 /* Device already opened */ | ||
1055 | #define IDETAPE_PIPELINE_ERROR 3 /* Error detected in a pipeline stage */ | ||
1056 | #define IDETAPE_DETECT_BS 4 /* Attempt to auto-detect the current user block size */ | ||
1057 | #define IDETAPE_FILEMARK 5 /* Currently on a filemark */ | ||
1058 | #define IDETAPE_DRQ_INTERRUPT 6 /* DRQ interrupt device */ | ||
1059 | #define IDETAPE_READ_ERROR 7 | ||
1060 | #define IDETAPE_PIPELINE_ACTIVE 8 /* pipeline active */ | ||
1061 | /* 0 = no tape is loaded, so we don't rewind after ejecting */ | ||
1062 | #define IDETAPE_MEDIUM_PRESENT 9 | ||
1063 | |||
1064 | /* | ||
1065 | * Supported ATAPI tape drives packet commands | ||
1066 | */ | ||
1067 | #define IDETAPE_TEST_UNIT_READY_CMD 0x00 | ||
1068 | #define IDETAPE_REWIND_CMD 0x01 | ||
1069 | #define IDETAPE_REQUEST_SENSE_CMD 0x03 | ||
1070 | #define IDETAPE_READ_CMD 0x08 | ||
1071 | #define IDETAPE_WRITE_CMD 0x0a | ||
1072 | #define IDETAPE_WRITE_FILEMARK_CMD 0x10 | ||
1073 | #define IDETAPE_SPACE_CMD 0x11 | ||
1074 | #define IDETAPE_INQUIRY_CMD 0x12 | ||
1075 | #define IDETAPE_ERASE_CMD 0x19 | ||
1076 | #define IDETAPE_MODE_SENSE_CMD 0x1a | ||
1077 | #define IDETAPE_MODE_SELECT_CMD 0x15 | ||
1078 | #define IDETAPE_LOAD_UNLOAD_CMD 0x1b | ||
1079 | #define IDETAPE_PREVENT_CMD 0x1e | ||
1080 | #define IDETAPE_LOCATE_CMD 0x2b | ||
1081 | #define IDETAPE_READ_POSITION_CMD 0x34 | ||
1082 | #define IDETAPE_READ_BUFFER_CMD 0x3c | ||
1083 | #define IDETAPE_SET_SPEED_CMD 0xbb | ||
1084 | |||
1085 | /* | ||
1086 | * Some defines for the READ BUFFER command | ||
1087 | */ | ||
1088 | #define IDETAPE_RETRIEVE_FAULTY_BLOCK 6 | ||
1089 | |||
1090 | /* | ||
1091 | * Some defines for the SPACE command | ||
1092 | */ | ||
1093 | #define IDETAPE_SPACE_OVER_FILEMARK 1 | ||
1094 | #define IDETAPE_SPACE_TO_EOD 3 | ||
1095 | |||
1096 | /* | ||
1097 | * Some defines for the LOAD UNLOAD command | ||
1098 | */ | ||
1099 | #define IDETAPE_LU_LOAD_MASK 1 | ||
1100 | #define IDETAPE_LU_RETENSION_MASK 2 | ||
1101 | #define IDETAPE_LU_EOT_MASK 4 | ||
1102 | |||
1103 | /* | ||
1104 | * Special requests for our block device strategy routine. | ||
1105 | * | ||
1106 | * In order to service a character device command, we add special | ||
1107 | * requests to the tail of our block device request queue and wait | ||
1108 | * for their completion. | ||
1109 | */ | ||
1110 | |||
1111 | enum { | ||
1112 | REQ_IDETAPE_PC1 = (1 << 0), /* packet command (first stage) */ | ||
1113 | REQ_IDETAPE_PC2 = (1 << 1), /* packet command (second stage) */ | ||
1114 | REQ_IDETAPE_READ = (1 << 2), | ||
1115 | REQ_IDETAPE_WRITE = (1 << 3), | ||
1116 | REQ_IDETAPE_READ_BUFFER = (1 << 4), | ||
1117 | }; | ||
1118 | |||
1119 | /* | ||
1120 | * Error codes which are returned in rq->errors to the higher part | ||
1121 | * of the driver. | ||
1122 | */ | ||
1123 | #define IDETAPE_ERROR_GENERAL 101 | ||
1124 | #define IDETAPE_ERROR_FILEMARK 102 | ||
1125 | #define IDETAPE_ERROR_EOD 103 | ||
1126 | |||
1127 | /* | ||
1128 | * The following is used to format the general configuration word of | ||
1129 | * the ATAPI IDENTIFY DEVICE command. | ||
1130 | */ | ||
1131 | struct idetape_id_gcw { | ||
1132 | unsigned packet_size :2; /* Packet Size */ | ||
1133 | unsigned reserved234 :3; /* Reserved */ | ||
1134 | unsigned drq_type :2; /* Command packet DRQ type */ | ||
1135 | unsigned removable :1; /* Removable media */ | ||
1136 | unsigned device_type :5; /* Device type */ | ||
1137 | unsigned reserved13 :1; /* Reserved */ | ||
1138 | unsigned protocol :2; /* Protocol type */ | ||
1139 | }; | ||
1140 | |||
1141 | /* | ||
1142 | * INQUIRY packet command - Data Format (From Table 6-8 of QIC-157C) | ||
1143 | */ | ||
1144 | typedef struct { | ||
1145 | unsigned device_type :5; /* Peripheral Device Type */ | ||
1146 | unsigned reserved0_765 :3; /* Peripheral Qualifier - Reserved */ | ||
1147 | unsigned reserved1_6t0 :7; /* Reserved */ | ||
1148 | unsigned rmb :1; /* Removable Medium Bit */ | ||
1149 | unsigned ansi_version :3; /* ANSI Version */ | ||
1150 | unsigned ecma_version :3; /* ECMA Version */ | ||
1151 | unsigned iso_version :2; /* ISO Version */ | ||
1152 | unsigned response_format :4; /* Response Data Format */ | ||
1153 | unsigned reserved3_45 :2; /* Reserved */ | ||
1154 | unsigned reserved3_6 :1; /* TrmIOP - Reserved */ | ||
1155 | unsigned reserved3_7 :1; /* AENC - Reserved */ | ||
1156 | __u8 additional_length; /* Additional Length (total_length-4) */ | ||
1157 | __u8 rsv5, rsv6, rsv7; /* Reserved */ | ||
1158 | __u8 vendor_id[8]; /* Vendor Identification */ | ||
1159 | __u8 product_id[16]; /* Product Identification */ | ||
1160 | __u8 revision_level[4]; /* Revision Level */ | ||
1161 | __u8 vendor_specific[20]; /* Vendor Specific - Optional */ | ||
1162 | __u8 reserved56t95[40]; /* Reserved - Optional */ | ||
1163 | /* Additional information may be returned */ | ||
1164 | } idetape_inquiry_result_t; | ||
1165 | |||
1166 | /* | ||
1167 | * READ POSITION packet command - Data Format (From Table 6-57) | ||
1168 | */ | ||
1169 | typedef struct { | ||
1170 | unsigned reserved0_10 :2; /* Reserved */ | ||
1171 | unsigned bpu :1; /* Block Position Unknown */ | ||
1172 | unsigned reserved0_543 :3; /* Reserved */ | ||
1173 | unsigned eop :1; /* End Of Partition */ | ||
1174 | unsigned bop :1; /* Beginning Of Partition */ | ||
1175 | u8 partition; /* Partition Number */ | ||
1176 | u8 reserved2, reserved3; /* Reserved */ | ||
1177 | u32 first_block; /* First Block Location */ | ||
1178 | u32 last_block; /* Last Block Location (Optional) */ | ||
1179 | u8 reserved12; /* Reserved */ | ||
1180 | u8 blocks_in_buffer[3]; /* Blocks In Buffer - (Optional) */ | ||
1181 | u32 bytes_in_buffer; /* Bytes In Buffer (Optional) */ | ||
1182 | } idetape_read_position_result_t; | ||
1183 | |||
1184 | /* | ||
1185 | * Follows structures which are related to the SELECT SENSE / MODE SENSE | ||
1186 | * packet commands. Those packet commands are still not supported | ||
1187 | * by ide-tape. | ||
1188 | */ | ||
1189 | #define IDETAPE_BLOCK_DESCRIPTOR 0 | ||
1190 | #define IDETAPE_CAPABILITIES_PAGE 0x2a | ||
1191 | #define IDETAPE_PARAMTR_PAGE 0x2b /* Onstream DI-x0 only */ | ||
1192 | #define IDETAPE_BLOCK_SIZE_PAGE 0x30 | ||
1193 | #define IDETAPE_BUFFER_FILLING_PAGE 0x33 | ||
1194 | |||
1195 | /* | ||
1196 | * Mode Parameter Header for the MODE SENSE packet command | ||
1197 | */ | ||
1198 | typedef struct { | ||
1199 | __u8 mode_data_length; /* Length of the following data transfer */ | ||
1200 | __u8 medium_type; /* Medium Type */ | ||
1201 | __u8 dsp; /* Device Specific Parameter */ | ||
1202 | __u8 bdl; /* Block Descriptor Length */ | ||
1203 | #if 0 | ||
1204 | /* data transfer page */ | ||
1205 | __u8 page_code :6; | ||
1206 | __u8 reserved0_6 :1; | ||
1207 | __u8 ps :1; /* parameters saveable */ | ||
1208 | __u8 page_length; /* page Length == 0x02 */ | ||
1209 | __u8 reserved2; | ||
1210 | __u8 read32k :1; /* 32k blk size (data only) */ | ||
1211 | __u8 read32k5 :1; /* 32.5k blk size (data&AUX) */ | ||
1212 | __u8 reserved3_23 :2; | ||
1213 | __u8 write32k :1; /* 32k blk size (data only) */ | ||
1214 | __u8 write32k5 :1; /* 32.5k blk size (data&AUX) */ | ||
1215 | __u8 reserved3_6 :1; | ||
1216 | __u8 streaming :1; /* streaming mode enable */ | ||
1217 | #endif | ||
1218 | } idetape_mode_parameter_header_t; | ||
1219 | |||
1220 | /* | ||
1221 | * Mode Parameter Block Descriptor the MODE SENSE packet command | ||
1222 | * | ||
1223 | * Support for block descriptors is optional. | ||
1224 | */ | ||
1225 | typedef struct { | ||
1226 | __u8 density_code; /* Medium density code */ | ||
1227 | __u8 blocks[3]; /* Number of blocks */ | ||
1228 | __u8 reserved4; /* Reserved */ | ||
1229 | __u8 length[3]; /* Block Length */ | ||
1230 | } idetape_parameter_block_descriptor_t; | ||
1231 | |||
1232 | /* | ||
1233 | * The Data Compression Page, as returned by the MODE SENSE packet command. | ||
1234 | */ | ||
1235 | typedef struct { | ||
1236 | unsigned page_code :6; /* Page Code - Should be 0xf */ | ||
1237 | unsigned reserved0 :1; /* Reserved */ | ||
1238 | unsigned ps :1; | ||
1239 | __u8 page_length; /* Page Length - Should be 14 */ | ||
1240 | unsigned reserved2 :6; /* Reserved */ | ||
1241 | unsigned dcc :1; /* Data Compression Capable */ | ||
1242 | unsigned dce :1; /* Data Compression Enable */ | ||
1243 | unsigned reserved3 :5; /* Reserved */ | ||
1244 | unsigned red :2; /* Report Exception on Decompression */ | ||
1245 | unsigned dde :1; /* Data Decompression Enable */ | ||
1246 | __u32 ca; /* Compression Algorithm */ | ||
1247 | __u32 da; /* Decompression Algorithm */ | ||
1248 | __u8 reserved[4]; /* Reserved */ | ||
1249 | } idetape_data_compression_page_t; | ||
1250 | |||
1251 | /* | ||
1252 | * The Medium Partition Page, as returned by the MODE SENSE packet command. | ||
1253 | */ | ||
1254 | typedef struct { | ||
1255 | unsigned page_code :6; /* Page Code - Should be 0x11 */ | ||
1256 | unsigned reserved1_6 :1; /* Reserved */ | ||
1257 | unsigned ps :1; | ||
1258 | __u8 page_length; /* Page Length - Should be 6 */ | ||
1259 | __u8 map; /* Maximum Additional Partitions - Should be 0 */ | ||
1260 | __u8 apd; /* Additional Partitions Defined - Should be 0 */ | ||
1261 | unsigned reserved4_012 :3; /* Reserved */ | ||
1262 | unsigned psum :2; /* Should be 0 */ | ||
1263 | unsigned idp :1; /* Should be 0 */ | ||
1264 | unsigned sdp :1; /* Should be 0 */ | ||
1265 | unsigned fdp :1; /* Fixed Data Partitions */ | ||
1266 | __u8 mfr; /* Medium Format Recognition */ | ||
1267 | __u8 reserved[2]; /* Reserved */ | ||
1268 | } idetape_medium_partition_page_t; | ||
1269 | |||
1270 | /* | ||
1271 | * Run time configurable parameters. | ||
1272 | */ | ||
1273 | typedef struct { | ||
1274 | int dsc_rw_frequency; | ||
1275 | int dsc_media_access_frequency; | ||
1276 | int nr_stages; | ||
1277 | } idetape_config_t; | ||
1278 | |||
1279 | /* | ||
1280 | * The variables below are used for the character device interface. | ||
1281 | * Additional state variables are defined in our ide_drive_t structure. | ||
1282 | */ | ||
1283 | static struct ide_tape_obj * idetape_devs[MAX_HWIFS * MAX_DRIVES]; | ||
1284 | |||
1285 | #define ide_tape_f(file) ((file)->private_data) | ||
1286 | |||
1287 | static struct ide_tape_obj *ide_tape_chrdev_get(unsigned int i) | ||
1288 | { | ||
1289 | struct ide_tape_obj *tape = NULL; | ||
1290 | |||
1291 | down(&idetape_ref_sem); | ||
1292 | tape = idetape_devs[i]; | ||
1293 | if (tape) | ||
1294 | kref_get(&tape->kref); | ||
1295 | up(&idetape_ref_sem); | ||
1296 | return tape; | ||
1297 | } | ||
1298 | |||
1299 | /* | ||
1300 | * Function declarations | ||
1301 | * | ||
1302 | */ | ||
1303 | static int idetape_chrdev_release (struct inode *inode, struct file *filp); | ||
1304 | static void idetape_write_release (ide_drive_t *drive, unsigned int minor); | ||
1305 | |||
1306 | /* | ||
1307 | * Too bad. The drive wants to send us data which we are not ready to accept. | ||
1308 | * Just throw it away. | ||
1309 | */ | ||
1310 | static void idetape_discard_data (ide_drive_t *drive, unsigned int bcount) | ||
1311 | { | ||
1312 | while (bcount--) | ||
1313 | (void) HWIF(drive)->INB(IDE_DATA_REG); | ||
1314 | } | ||
1315 | |||
1316 | static void idetape_input_buffers (ide_drive_t *drive, idetape_pc_t *pc, unsigned int bcount) | ||
1317 | { | ||
1318 | struct idetape_bh *bh = pc->bh; | ||
1319 | int count; | ||
1320 | |||
1321 | while (bcount) { | ||
1322 | #if IDETAPE_DEBUG_BUGS | ||
1323 | if (bh == NULL) { | ||
1324 | printk(KERN_ERR "ide-tape: bh == NULL in " | ||
1325 | "idetape_input_buffers\n"); | ||
1326 | idetape_discard_data(drive, bcount); | ||
1327 | return; | ||
1328 | } | ||
1329 | #endif /* IDETAPE_DEBUG_BUGS */ | ||
1330 | count = min((unsigned int)(bh->b_size - atomic_read(&bh->b_count)), bcount); | ||
1331 | HWIF(drive)->atapi_input_bytes(drive, bh->b_data + atomic_read(&bh->b_count), count); | ||
1332 | bcount -= count; | ||
1333 | atomic_add(count, &bh->b_count); | ||
1334 | if (atomic_read(&bh->b_count) == bh->b_size) { | ||
1335 | bh = bh->b_reqnext; | ||
1336 | if (bh) | ||
1337 | atomic_set(&bh->b_count, 0); | ||
1338 | } | ||
1339 | } | ||
1340 | pc->bh = bh; | ||
1341 | } | ||
1342 | |||
1343 | static void idetape_output_buffers (ide_drive_t *drive, idetape_pc_t *pc, unsigned int bcount) | ||
1344 | { | ||
1345 | struct idetape_bh *bh = pc->bh; | ||
1346 | int count; | ||
1347 | |||
1348 | while (bcount) { | ||
1349 | #if IDETAPE_DEBUG_BUGS | ||
1350 | if (bh == NULL) { | ||
1351 | printk(KERN_ERR "ide-tape: bh == NULL in " | ||
1352 | "idetape_output_buffers\n"); | ||
1353 | return; | ||
1354 | } | ||
1355 | #endif /* IDETAPE_DEBUG_BUGS */ | ||
1356 | count = min((unsigned int)pc->b_count, (unsigned int)bcount); | ||
1357 | HWIF(drive)->atapi_output_bytes(drive, pc->b_data, count); | ||
1358 | bcount -= count; | ||
1359 | pc->b_data += count; | ||
1360 | pc->b_count -= count; | ||
1361 | if (!pc->b_count) { | ||
1362 | pc->bh = bh = bh->b_reqnext; | ||
1363 | if (bh) { | ||
1364 | pc->b_data = bh->b_data; | ||
1365 | pc->b_count = atomic_read(&bh->b_count); | ||
1366 | } | ||
1367 | } | ||
1368 | } | ||
1369 | } | ||
1370 | |||
1371 | static void idetape_update_buffers (idetape_pc_t *pc) | ||
1372 | { | ||
1373 | struct idetape_bh *bh = pc->bh; | ||
1374 | int count; | ||
1375 | unsigned int bcount = pc->actually_transferred; | ||
1376 | |||
1377 | if (test_bit(PC_WRITING, &pc->flags)) | ||
1378 | return; | ||
1379 | while (bcount) { | ||
1380 | #if IDETAPE_DEBUG_BUGS | ||
1381 | if (bh == NULL) { | ||
1382 | printk(KERN_ERR "ide-tape: bh == NULL in " | ||
1383 | "idetape_update_buffers\n"); | ||
1384 | return; | ||
1385 | } | ||
1386 | #endif /* IDETAPE_DEBUG_BUGS */ | ||
1387 | count = min((unsigned int)bh->b_size, (unsigned int)bcount); | ||
1388 | atomic_set(&bh->b_count, count); | ||
1389 | if (atomic_read(&bh->b_count) == bh->b_size) | ||
1390 | bh = bh->b_reqnext; | ||
1391 | bcount -= count; | ||
1392 | } | ||
1393 | pc->bh = bh; | ||
1394 | } | ||
1395 | |||
1396 | /* | ||
1397 | * idetape_next_pc_storage returns a pointer to a place in which we can | ||
1398 | * safely store a packet command, even though we intend to leave the | ||
1399 | * driver. A storage space for a maximum of IDETAPE_PC_STACK packet | ||
1400 | * commands is allocated at initialization time. | ||
1401 | */ | ||
1402 | static idetape_pc_t *idetape_next_pc_storage (ide_drive_t *drive) | ||
1403 | { | ||
1404 | idetape_tape_t *tape = drive->driver_data; | ||
1405 | |||
1406 | #if IDETAPE_DEBUG_LOG | ||
1407 | if (tape->debug_level >= 5) | ||
1408 | printk(KERN_INFO "ide-tape: pc_stack_index=%d\n", | ||
1409 | tape->pc_stack_index); | ||
1410 | #endif /* IDETAPE_DEBUG_LOG */ | ||
1411 | if (tape->pc_stack_index == IDETAPE_PC_STACK) | ||
1412 | tape->pc_stack_index=0; | ||
1413 | return (&tape->pc_stack[tape->pc_stack_index++]); | ||
1414 | } | ||
1415 | |||
1416 | /* | ||
1417 | * idetape_next_rq_storage is used along with idetape_next_pc_storage. | ||
1418 | * Since we queue packet commands in the request queue, we need to | ||
1419 | * allocate a request, along with the allocation of a packet command. | ||
1420 | */ | ||
1421 | |||
1422 | /************************************************************** | ||
1423 | * * | ||
1424 | * This should get fixed to use kmalloc(.., GFP_ATOMIC) * | ||
1425 | * followed later on by kfree(). -ml * | ||
1426 | * * | ||
1427 | **************************************************************/ | ||
1428 | |||
1429 | static struct request *idetape_next_rq_storage (ide_drive_t *drive) | ||
1430 | { | ||
1431 | idetape_tape_t *tape = drive->driver_data; | ||
1432 | |||
1433 | #if IDETAPE_DEBUG_LOG | ||
1434 | if (tape->debug_level >= 5) | ||
1435 | printk(KERN_INFO "ide-tape: rq_stack_index=%d\n", | ||
1436 | tape->rq_stack_index); | ||
1437 | #endif /* IDETAPE_DEBUG_LOG */ | ||
1438 | if (tape->rq_stack_index == IDETAPE_PC_STACK) | ||
1439 | tape->rq_stack_index=0; | ||
1440 | return (&tape->rq_stack[tape->rq_stack_index++]); | ||
1441 | } | ||
1442 | |||
1443 | /* | ||
1444 | * idetape_init_pc initializes a packet command. | ||
1445 | */ | ||
1446 | static void idetape_init_pc (idetape_pc_t *pc) | ||
1447 | { | ||
1448 | memset(pc->c, 0, 12); | ||
1449 | pc->retries = 0; | ||
1450 | pc->flags = 0; | ||
1451 | pc->request_transfer = 0; | ||
1452 | pc->buffer = pc->pc_buffer; | ||
1453 | pc->buffer_size = IDETAPE_PC_BUFFER_SIZE; | ||
1454 | pc->bh = NULL; | ||
1455 | pc->b_data = NULL; | ||
1456 | } | ||
1457 | |||
1458 | /* | ||
1459 | * idetape_analyze_error is called on each failed packet command retry | ||
1460 | * to analyze the request sense. We currently do not utilize this | ||
1461 | * information. | ||
1462 | */ | ||
1463 | static void idetape_analyze_error (ide_drive_t *drive, idetape_request_sense_result_t *result) | ||
1464 | { | ||
1465 | idetape_tape_t *tape = drive->driver_data; | ||
1466 | idetape_pc_t *pc = tape->failed_pc; | ||
1467 | |||
1468 | tape->sense = *result; | ||
1469 | tape->sense_key = result->sense_key; | ||
1470 | tape->asc = result->asc; | ||
1471 | tape->ascq = result->ascq; | ||
1472 | #if IDETAPE_DEBUG_LOG | ||
1473 | /* | ||
1474 | * Without debugging, we only log an error if we decided to | ||
1475 | * give up retrying. | ||
1476 | */ | ||
1477 | if (tape->debug_level >= 1) | ||
1478 | printk(KERN_INFO "ide-tape: pc = %x, sense key = %x, " | ||
1479 | "asc = %x, ascq = %x\n", | ||
1480 | pc->c[0], result->sense_key, | ||
1481 | result->asc, result->ascq); | ||
1482 | #endif /* IDETAPE_DEBUG_LOG */ | ||
1483 | |||
1484 | /* | ||
1485 | * Correct pc->actually_transferred by asking the tape. | ||
1486 | */ | ||
1487 | if (test_bit(PC_DMA_ERROR, &pc->flags)) { | ||
1488 | pc->actually_transferred = pc->request_transfer - tape->tape_block_size * ntohl(get_unaligned(&result->information)); | ||
1489 | idetape_update_buffers(pc); | ||
1490 | } | ||
1491 | |||
1492 | /* | ||
1493 | * If error was the result of a zero-length read or write command, | ||
1494 | * with sense key=5, asc=0x22, ascq=0, let it slide. Some drives | ||
1495 | * (i.e. Seagate STT3401A Travan) don't support 0-length read/writes. | ||
1496 | */ | ||
1497 | if ((pc->c[0] == IDETAPE_READ_CMD || pc->c[0] == IDETAPE_WRITE_CMD) | ||
1498 | && pc->c[4] == 0 && pc->c[3] == 0 && pc->c[2] == 0) { /* length==0 */ | ||
1499 | if (result->sense_key == 5) { | ||
1500 | /* don't report an error, everything's ok */ | ||
1501 | pc->error = 0; | ||
1502 | /* don't retry read/write */ | ||
1503 | set_bit(PC_ABORT, &pc->flags); | ||
1504 | } | ||
1505 | } | ||
1506 | if (pc->c[0] == IDETAPE_READ_CMD && result->filemark) { | ||
1507 | pc->error = IDETAPE_ERROR_FILEMARK; | ||
1508 | set_bit(PC_ABORT, &pc->flags); | ||
1509 | } | ||
1510 | if (pc->c[0] == IDETAPE_WRITE_CMD) { | ||
1511 | if (result->eom || | ||
1512 | (result->sense_key == 0xd && result->asc == 0x0 && | ||
1513 | result->ascq == 0x2)) { | ||
1514 | pc->error = IDETAPE_ERROR_EOD; | ||
1515 | set_bit(PC_ABORT, &pc->flags); | ||
1516 | } | ||
1517 | } | ||
1518 | if (pc->c[0] == IDETAPE_READ_CMD || pc->c[0] == IDETAPE_WRITE_CMD) { | ||
1519 | if (result->sense_key == 8) { | ||
1520 | pc->error = IDETAPE_ERROR_EOD; | ||
1521 | set_bit(PC_ABORT, &pc->flags); | ||
1522 | } | ||
1523 | if (!test_bit(PC_ABORT, &pc->flags) && | ||
1524 | pc->actually_transferred) | ||
1525 | pc->retries = IDETAPE_MAX_PC_RETRIES + 1; | ||
1526 | } | ||
1527 | } | ||
1528 | |||
1529 | /* | ||
1530 | * idetape_active_next_stage will declare the next stage as "active". | ||
1531 | */ | ||
1532 | static void idetape_active_next_stage (ide_drive_t *drive) | ||
1533 | { | ||
1534 | idetape_tape_t *tape = drive->driver_data; | ||
1535 | idetape_stage_t *stage = tape->next_stage; | ||
1536 | struct request *rq = &stage->rq; | ||
1537 | |||
1538 | #if IDETAPE_DEBUG_LOG | ||
1539 | if (tape->debug_level >= 4) | ||
1540 | printk(KERN_INFO "ide-tape: Reached idetape_active_next_stage\n"); | ||
1541 | #endif /* IDETAPE_DEBUG_LOG */ | ||
1542 | #if IDETAPE_DEBUG_BUGS | ||
1543 | if (stage == NULL) { | ||
1544 | printk(KERN_ERR "ide-tape: bug: Trying to activate a non existing stage\n"); | ||
1545 | return; | ||
1546 | } | ||
1547 | #endif /* IDETAPE_DEBUG_BUGS */ | ||
1548 | |||
1549 | rq->rq_disk = tape->disk; | ||
1550 | rq->buffer = NULL; | ||
1551 | rq->special = (void *)stage->bh; | ||
1552 | tape->active_data_request = rq; | ||
1553 | tape->active_stage = stage; | ||
1554 | tape->next_stage = stage->next; | ||
1555 | } | ||
1556 | |||
1557 | /* | ||
1558 | * idetape_increase_max_pipeline_stages is a part of the feedback | ||
1559 | * loop which tries to find the optimum number of stages. In the | ||
1560 | * feedback loop, we are starting from a minimum maximum number of | ||
1561 | * stages, and if we sense that the pipeline is empty, we try to | ||
1562 | * increase it, until we reach the user compile time memory limit. | ||
1563 | */ | ||
1564 | static void idetape_increase_max_pipeline_stages (ide_drive_t *drive) | ||
1565 | { | ||
1566 | idetape_tape_t *tape = drive->driver_data; | ||
1567 | int increase = (tape->max_pipeline - tape->min_pipeline) / 10; | ||
1568 | |||
1569 | #if IDETAPE_DEBUG_LOG | ||
1570 | if (tape->debug_level >= 4) | ||
1571 | printk (KERN_INFO "ide-tape: Reached idetape_increase_max_pipeline_stages\n"); | ||
1572 | #endif /* IDETAPE_DEBUG_LOG */ | ||
1573 | |||
1574 | tape->max_stages += max(increase, 1); | ||
1575 | tape->max_stages = max(tape->max_stages, tape->min_pipeline); | ||
1576 | tape->max_stages = min(tape->max_stages, tape->max_pipeline); | ||
1577 | } | ||
1578 | |||
1579 | /* | ||
1580 | * idetape_kfree_stage calls kfree to completely free a stage, along with | ||
1581 | * its related buffers. | ||
1582 | */ | ||
1583 | static void __idetape_kfree_stage (idetape_stage_t *stage) | ||
1584 | { | ||
1585 | struct idetape_bh *prev_bh, *bh = stage->bh; | ||
1586 | int size; | ||
1587 | |||
1588 | while (bh != NULL) { | ||
1589 | if (bh->b_data != NULL) { | ||
1590 | size = (int) bh->b_size; | ||
1591 | while (size > 0) { | ||
1592 | free_page((unsigned long) bh->b_data); | ||
1593 | size -= PAGE_SIZE; | ||
1594 | bh->b_data += PAGE_SIZE; | ||
1595 | } | ||
1596 | } | ||
1597 | prev_bh = bh; | ||
1598 | bh = bh->b_reqnext; | ||
1599 | kfree(prev_bh); | ||
1600 | } | ||
1601 | kfree(stage); | ||
1602 | } | ||
1603 | |||
1604 | static void idetape_kfree_stage (idetape_tape_t *tape, idetape_stage_t *stage) | ||
1605 | { | ||
1606 | __idetape_kfree_stage(stage); | ||
1607 | } | ||
1608 | |||
1609 | /* | ||
1610 | * idetape_remove_stage_head removes tape->first_stage from the pipeline. | ||
1611 | * The caller should avoid race conditions. | ||
1612 | */ | ||
1613 | static void idetape_remove_stage_head (ide_drive_t *drive) | ||
1614 | { | ||
1615 | idetape_tape_t *tape = drive->driver_data; | ||
1616 | idetape_stage_t *stage; | ||
1617 | |||
1618 | #if IDETAPE_DEBUG_LOG | ||
1619 | if (tape->debug_level >= 4) | ||
1620 | printk(KERN_INFO "ide-tape: Reached idetape_remove_stage_head\n"); | ||
1621 | #endif /* IDETAPE_DEBUG_LOG */ | ||
1622 | #if IDETAPE_DEBUG_BUGS | ||
1623 | if (tape->first_stage == NULL) { | ||
1624 | printk(KERN_ERR "ide-tape: bug: tape->first_stage is NULL\n"); | ||
1625 | return; | ||
1626 | } | ||
1627 | if (tape->active_stage == tape->first_stage) { | ||
1628 | printk(KERN_ERR "ide-tape: bug: Trying to free our active pipeline stage\n"); | ||
1629 | return; | ||
1630 | } | ||
1631 | #endif /* IDETAPE_DEBUG_BUGS */ | ||
1632 | stage = tape->first_stage; | ||
1633 | tape->first_stage = stage->next; | ||
1634 | idetape_kfree_stage(tape, stage); | ||
1635 | tape->nr_stages--; | ||
1636 | if (tape->first_stage == NULL) { | ||
1637 | tape->last_stage = NULL; | ||
1638 | #if IDETAPE_DEBUG_BUGS | ||
1639 | if (tape->next_stage != NULL) | ||
1640 | printk(KERN_ERR "ide-tape: bug: tape->next_stage != NULL\n"); | ||
1641 | if (tape->nr_stages) | ||
1642 | printk(KERN_ERR "ide-tape: bug: nr_stages should be 0 now\n"); | ||
1643 | #endif /* IDETAPE_DEBUG_BUGS */ | ||
1644 | } | ||
1645 | } | ||
1646 | |||
1647 | /* | ||
1648 | * This will free all the pipeline stages starting from new_last_stage->next | ||
1649 | * to the end of the list, and point tape->last_stage to new_last_stage. | ||
1650 | */ | ||
1651 | static void idetape_abort_pipeline(ide_drive_t *drive, | ||
1652 | idetape_stage_t *new_last_stage) | ||
1653 | { | ||
1654 | idetape_tape_t *tape = drive->driver_data; | ||
1655 | idetape_stage_t *stage = new_last_stage->next; | ||
1656 | idetape_stage_t *nstage; | ||
1657 | |||
1658 | #if IDETAPE_DEBUG_LOG | ||
1659 | if (tape->debug_level >= 4) | ||
1660 | printk(KERN_INFO "ide-tape: %s: idetape_abort_pipeline called\n", tape->name); | ||
1661 | #endif | ||
1662 | while (stage) { | ||
1663 | nstage = stage->next; | ||
1664 | idetape_kfree_stage(tape, stage); | ||
1665 | --tape->nr_stages; | ||
1666 | --tape->nr_pending_stages; | ||
1667 | stage = nstage; | ||
1668 | } | ||
1669 | if (new_last_stage) | ||
1670 | new_last_stage->next = NULL; | ||
1671 | tape->last_stage = new_last_stage; | ||
1672 | tape->next_stage = NULL; | ||
1673 | } | ||
1674 | |||
1675 | /* | ||
1676 | * idetape_end_request is used to finish servicing a request, and to | ||
1677 | * insert a pending pipeline request into the main device queue. | ||
1678 | */ | ||
1679 | static int idetape_end_request(ide_drive_t *drive, int uptodate, int nr_sects) | ||
1680 | { | ||
1681 | struct request *rq = HWGROUP(drive)->rq; | ||
1682 | idetape_tape_t *tape = drive->driver_data; | ||
1683 | unsigned long flags; | ||
1684 | int error; | ||
1685 | int remove_stage = 0; | ||
1686 | idetape_stage_t *active_stage; | ||
1687 | |||
1688 | #if IDETAPE_DEBUG_LOG | ||
1689 | if (tape->debug_level >= 4) | ||
1690 | printk(KERN_INFO "ide-tape: Reached idetape_end_request\n"); | ||
1691 | #endif /* IDETAPE_DEBUG_LOG */ | ||
1692 | |||
1693 | switch (uptodate) { | ||
1694 | case 0: error = IDETAPE_ERROR_GENERAL; break; | ||
1695 | case 1: error = 0; break; | ||
1696 | default: error = uptodate; | ||
1697 | } | ||
1698 | rq->errors = error; | ||
1699 | if (error) | ||
1700 | tape->failed_pc = NULL; | ||
1701 | |||
1702 | spin_lock_irqsave(&tape->spinlock, flags); | ||
1703 | |||
1704 | /* The request was a pipelined data transfer request */ | ||
1705 | if (tape->active_data_request == rq) { | ||
1706 | active_stage = tape->active_stage; | ||
1707 | tape->active_stage = NULL; | ||
1708 | tape->active_data_request = NULL; | ||
1709 | tape->nr_pending_stages--; | ||
1710 | if (rq->cmd[0] & REQ_IDETAPE_WRITE) { | ||
1711 | remove_stage = 1; | ||
1712 | if (error) { | ||
1713 | set_bit(IDETAPE_PIPELINE_ERROR, &tape->flags); | ||
1714 | if (error == IDETAPE_ERROR_EOD) | ||
1715 | idetape_abort_pipeline(drive, active_stage); | ||
1716 | } | ||
1717 | } else if (rq->cmd[0] & REQ_IDETAPE_READ) { | ||
1718 | if (error == IDETAPE_ERROR_EOD) { | ||
1719 | set_bit(IDETAPE_PIPELINE_ERROR, &tape->flags); | ||
1720 | idetape_abort_pipeline(drive, active_stage); | ||
1721 | } | ||
1722 | } | ||
1723 | if (tape->next_stage != NULL) { | ||
1724 | idetape_active_next_stage(drive); | ||
1725 | |||
1726 | /* | ||
1727 | * Insert the next request into the request queue. | ||
1728 | */ | ||
1729 | (void) ide_do_drive_cmd(drive, tape->active_data_request, ide_end); | ||
1730 | } else if (!error) { | ||
1731 | idetape_increase_max_pipeline_stages(drive); | ||
1732 | } | ||
1733 | } | ||
1734 | ide_end_drive_cmd(drive, 0, 0); | ||
1735 | // blkdev_dequeue_request(rq); | ||
1736 | // drive->rq = NULL; | ||
1737 | // end_that_request_last(rq); | ||
1738 | |||
1739 | if (remove_stage) | ||
1740 | idetape_remove_stage_head(drive); | ||
1741 | if (tape->active_data_request == NULL) | ||
1742 | clear_bit(IDETAPE_PIPELINE_ACTIVE, &tape->flags); | ||
1743 | spin_unlock_irqrestore(&tape->spinlock, flags); | ||
1744 | return 0; | ||
1745 | } | ||
1746 | |||
1747 | static ide_startstop_t idetape_request_sense_callback (ide_drive_t *drive) | ||
1748 | { | ||
1749 | idetape_tape_t *tape = drive->driver_data; | ||
1750 | |||
1751 | #if IDETAPE_DEBUG_LOG | ||
1752 | if (tape->debug_level >= 4) | ||
1753 | printk(KERN_INFO "ide-tape: Reached idetape_request_sense_callback\n"); | ||
1754 | #endif /* IDETAPE_DEBUG_LOG */ | ||
1755 | if (!tape->pc->error) { | ||
1756 | idetape_analyze_error(drive, (idetape_request_sense_result_t *) tape->pc->buffer); | ||
1757 | idetape_end_request(drive, 1, 0); | ||
1758 | } else { | ||
1759 | printk(KERN_ERR "ide-tape: Error in REQUEST SENSE itself - Aborting request!\n"); | ||
1760 | idetape_end_request(drive, 0, 0); | ||
1761 | } | ||
1762 | return ide_stopped; | ||
1763 | } | ||
1764 | |||
1765 | static void idetape_create_request_sense_cmd (idetape_pc_t *pc) | ||
1766 | { | ||
1767 | idetape_init_pc(pc); | ||
1768 | pc->c[0] = IDETAPE_REQUEST_SENSE_CMD; | ||
1769 | pc->c[4] = 20; | ||
1770 | pc->request_transfer = 20; | ||
1771 | pc->callback = &idetape_request_sense_callback; | ||
1772 | } | ||
1773 | |||
1774 | static void idetape_init_rq(struct request *rq, u8 cmd) | ||
1775 | { | ||
1776 | memset(rq, 0, sizeof(*rq)); | ||
1777 | rq->flags = REQ_SPECIAL; | ||
1778 | rq->cmd[0] = cmd; | ||
1779 | } | ||
1780 | |||
1781 | /* | ||
1782 | * idetape_queue_pc_head generates a new packet command request in front | ||
1783 | * of the request queue, before the current request, so that it will be | ||
1784 | * processed immediately, on the next pass through the driver. | ||
1785 | * | ||
1786 | * idetape_queue_pc_head is called from the request handling part of | ||
1787 | * the driver (the "bottom" part). Safe storage for the request should | ||
1788 | * be allocated with idetape_next_pc_storage and idetape_next_rq_storage | ||
1789 | * before calling idetape_queue_pc_head. | ||
1790 | * | ||
1791 | * Memory for those requests is pre-allocated at initialization time, and | ||
1792 | * is limited to IDETAPE_PC_STACK requests. We assume that we have enough | ||
1793 | * space for the maximum possible number of inter-dependent packet commands. | ||
1794 | * | ||
1795 | * The higher level of the driver - The ioctl handler and the character | ||
1796 | * device handling functions should queue request to the lower level part | ||
1797 | * and wait for their completion using idetape_queue_pc_tail or | ||
1798 | * idetape_queue_rw_tail. | ||
1799 | */ | ||
1800 | static void idetape_queue_pc_head (ide_drive_t *drive, idetape_pc_t *pc,struct request *rq) | ||
1801 | { | ||
1802 | struct ide_tape_obj *tape = drive->driver_data; | ||
1803 | |||
1804 | idetape_init_rq(rq, REQ_IDETAPE_PC1); | ||
1805 | rq->buffer = (char *) pc; | ||
1806 | rq->rq_disk = tape->disk; | ||
1807 | (void) ide_do_drive_cmd(drive, rq, ide_preempt); | ||
1808 | } | ||
1809 | |||
1810 | /* | ||
1811 | * idetape_retry_pc is called when an error was detected during the | ||
1812 | * last packet command. We queue a request sense packet command in | ||
1813 | * the head of the request list. | ||
1814 | */ | ||
1815 | static ide_startstop_t idetape_retry_pc (ide_drive_t *drive) | ||
1816 | { | ||
1817 | idetape_tape_t *tape = drive->driver_data; | ||
1818 | idetape_pc_t *pc; | ||
1819 | struct request *rq; | ||
1820 | atapi_error_t error; | ||
1821 | |||
1822 | error.all = HWIF(drive)->INB(IDE_ERROR_REG); | ||
1823 | pc = idetape_next_pc_storage(drive); | ||
1824 | rq = idetape_next_rq_storage(drive); | ||
1825 | idetape_create_request_sense_cmd(pc); | ||
1826 | set_bit(IDETAPE_IGNORE_DSC, &tape->flags); | ||
1827 | idetape_queue_pc_head(drive, pc, rq); | ||
1828 | return ide_stopped; | ||
1829 | } | ||
1830 | |||
1831 | /* | ||
1832 | * idetape_postpone_request postpones the current request so that | ||
1833 | * ide.c will be able to service requests from another device on | ||
1834 | * the same hwgroup while we are polling for DSC. | ||
1835 | */ | ||
1836 | static void idetape_postpone_request (ide_drive_t *drive) | ||
1837 | { | ||
1838 | idetape_tape_t *tape = drive->driver_data; | ||
1839 | |||
1840 | #if IDETAPE_DEBUG_LOG | ||
1841 | if (tape->debug_level >= 4) | ||
1842 | printk(KERN_INFO "ide-tape: idetape_postpone_request\n"); | ||
1843 | #endif | ||
1844 | tape->postponed_rq = HWGROUP(drive)->rq; | ||
1845 | ide_stall_queue(drive, tape->dsc_polling_frequency); | ||
1846 | } | ||
1847 | |||
1848 | /* | ||
1849 | * idetape_pc_intr is the usual interrupt handler which will be called | ||
1850 | * during a packet command. We will transfer some of the data (as | ||
1851 | * requested by the drive) and will re-point interrupt handler to us. | ||
1852 | * When data transfer is finished, we will act according to the | ||
1853 | * algorithm described before idetape_issue_packet_command. | ||
1854 | * | ||
1855 | */ | ||
1856 | static ide_startstop_t idetape_pc_intr (ide_drive_t *drive) | ||
1857 | { | ||
1858 | ide_hwif_t *hwif = drive->hwif; | ||
1859 | idetape_tape_t *tape = drive->driver_data; | ||
1860 | atapi_status_t status; | ||
1861 | atapi_bcount_t bcount; | ||
1862 | atapi_ireason_t ireason; | ||
1863 | idetape_pc_t *pc = tape->pc; | ||
1864 | |||
1865 | unsigned int temp; | ||
1866 | #if SIMULATE_ERRORS | ||
1867 | static int error_sim_count = 0; | ||
1868 | #endif | ||
1869 | |||
1870 | #if IDETAPE_DEBUG_LOG | ||
1871 | if (tape->debug_level >= 4) | ||
1872 | printk(KERN_INFO "ide-tape: Reached idetape_pc_intr " | ||
1873 | "interrupt handler\n"); | ||
1874 | #endif /* IDETAPE_DEBUG_LOG */ | ||
1875 | |||
1876 | /* Clear the interrupt */ | ||
1877 | status.all = HWIF(drive)->INB(IDE_STATUS_REG); | ||
1878 | |||
1879 | if (test_bit(PC_DMA_IN_PROGRESS, &pc->flags)) { | ||
1880 | if (HWIF(drive)->ide_dma_end(drive) || status.b.check) { | ||
1881 | /* | ||
1882 | * A DMA error is sometimes expected. For example, | ||
1883 | * if the tape is crossing a filemark during a | ||
1884 | * READ command, it will issue an irq and position | ||
1885 | * itself before the filemark, so that only a partial | ||
1886 | * data transfer will occur (which causes the DMA | ||
1887 | * error). In that case, we will later ask the tape | ||
1888 | * how much bytes of the original request were | ||
1889 | * actually transferred (we can't receive that | ||
1890 | * information from the DMA engine on most chipsets). | ||
1891 | */ | ||
1892 | |||
1893 | /* | ||
1894 | * On the contrary, a DMA error is never expected; | ||
1895 | * it usually indicates a hardware error or abort. | ||
1896 | * If the tape crosses a filemark during a READ | ||
1897 | * command, it will issue an irq and position itself | ||
1898 | * after the filemark (not before). Only a partial | ||
1899 | * data transfer will occur, but no DMA error. | ||
1900 | * (AS, 19 Apr 2001) | ||
1901 | */ | ||
1902 | set_bit(PC_DMA_ERROR, &pc->flags); | ||
1903 | } else { | ||
1904 | pc->actually_transferred = pc->request_transfer; | ||
1905 | idetape_update_buffers(pc); | ||
1906 | } | ||
1907 | #if IDETAPE_DEBUG_LOG | ||
1908 | if (tape->debug_level >= 4) | ||
1909 | printk(KERN_INFO "ide-tape: DMA finished\n"); | ||
1910 | #endif /* IDETAPE_DEBUG_LOG */ | ||
1911 | } | ||
1912 | |||
1913 | /* No more interrupts */ | ||
1914 | if (!status.b.drq) { | ||
1915 | #if IDETAPE_DEBUG_LOG | ||
1916 | if (tape->debug_level >= 2) | ||
1917 | printk(KERN_INFO "ide-tape: Packet command completed, %d bytes transferred\n", pc->actually_transferred); | ||
1918 | #endif /* IDETAPE_DEBUG_LOG */ | ||
1919 | clear_bit(PC_DMA_IN_PROGRESS, &pc->flags); | ||
1920 | |||
1921 | local_irq_enable(); | ||
1922 | |||
1923 | #if SIMULATE_ERRORS | ||
1924 | if ((pc->c[0] == IDETAPE_WRITE_CMD || | ||
1925 | pc->c[0] == IDETAPE_READ_CMD) && | ||
1926 | (++error_sim_count % 100) == 0) { | ||
1927 | printk(KERN_INFO "ide-tape: %s: simulating error\n", | ||
1928 | tape->name); | ||
1929 | status.b.check = 1; | ||
1930 | } | ||
1931 | #endif | ||
1932 | if (status.b.check && pc->c[0] == IDETAPE_REQUEST_SENSE_CMD) | ||
1933 | status.b.check = 0; | ||
1934 | if (status.b.check || test_bit(PC_DMA_ERROR, &pc->flags)) { /* Error detected */ | ||
1935 | #if IDETAPE_DEBUG_LOG | ||
1936 | if (tape->debug_level >= 1) | ||
1937 | printk(KERN_INFO "ide-tape: %s: I/O error\n", | ||
1938 | tape->name); | ||
1939 | #endif /* IDETAPE_DEBUG_LOG */ | ||
1940 | if (pc->c[0] == IDETAPE_REQUEST_SENSE_CMD) { | ||
1941 | printk(KERN_ERR "ide-tape: I/O error in request sense command\n"); | ||
1942 | return ide_do_reset(drive); | ||
1943 | } | ||
1944 | #if IDETAPE_DEBUG_LOG | ||
1945 | if (tape->debug_level >= 1) | ||
1946 | printk(KERN_INFO "ide-tape: [cmd %x]: check condition\n", pc->c[0]); | ||
1947 | #endif | ||
1948 | /* Retry operation */ | ||
1949 | return idetape_retry_pc(drive); | ||
1950 | } | ||
1951 | pc->error = 0; | ||
1952 | if (test_bit(PC_WAIT_FOR_DSC, &pc->flags) && | ||
1953 | !status.b.dsc) { | ||
1954 | /* Media access command */ | ||
1955 | tape->dsc_polling_start = jiffies; | ||
1956 | tape->dsc_polling_frequency = IDETAPE_DSC_MA_FAST; | ||
1957 | tape->dsc_timeout = jiffies + IDETAPE_DSC_MA_TIMEOUT; | ||
1958 | /* Allow ide.c to handle other requests */ | ||
1959 | idetape_postpone_request(drive); | ||
1960 | return ide_stopped; | ||
1961 | } | ||
1962 | if (tape->failed_pc == pc) | ||
1963 | tape->failed_pc = NULL; | ||
1964 | /* Command finished - Call the callback function */ | ||
1965 | return pc->callback(drive); | ||
1966 | } | ||
1967 | if (test_and_clear_bit(PC_DMA_IN_PROGRESS, &pc->flags)) { | ||
1968 | printk(KERN_ERR "ide-tape: The tape wants to issue more " | ||
1969 | "interrupts in DMA mode\n"); | ||
1970 | printk(KERN_ERR "ide-tape: DMA disabled, reverting to PIO\n"); | ||
1971 | (void)__ide_dma_off(drive); | ||
1972 | return ide_do_reset(drive); | ||
1973 | } | ||
1974 | /* Get the number of bytes to transfer on this interrupt. */ | ||
1975 | bcount.b.high = hwif->INB(IDE_BCOUNTH_REG); | ||
1976 | bcount.b.low = hwif->INB(IDE_BCOUNTL_REG); | ||
1977 | |||
1978 | ireason.all = hwif->INB(IDE_IREASON_REG); | ||
1979 | |||
1980 | if (ireason.b.cod) { | ||
1981 | printk(KERN_ERR "ide-tape: CoD != 0 in idetape_pc_intr\n"); | ||
1982 | return ide_do_reset(drive); | ||
1983 | } | ||
1984 | if (ireason.b.io == test_bit(PC_WRITING, &pc->flags)) { | ||
1985 | /* Hopefully, we will never get here */ | ||
1986 | printk(KERN_ERR "ide-tape: We wanted to %s, ", | ||
1987 | ireason.b.io ? "Write":"Read"); | ||
1988 | printk(KERN_ERR "ide-tape: but the tape wants us to %s !\n", | ||
1989 | ireason.b.io ? "Read":"Write"); | ||
1990 | return ide_do_reset(drive); | ||
1991 | } | ||
1992 | if (!test_bit(PC_WRITING, &pc->flags)) { | ||
1993 | /* Reading - Check that we have enough space */ | ||
1994 | temp = pc->actually_transferred + bcount.all; | ||
1995 | if (temp > pc->request_transfer) { | ||
1996 | if (temp > pc->buffer_size) { | ||
1997 | printk(KERN_ERR "ide-tape: The tape wants to send us more data than expected - discarding data\n"); | ||
1998 | idetape_discard_data(drive, bcount.all); | ||
1999 | ide_set_handler(drive, &idetape_pc_intr, IDETAPE_WAIT_CMD, NULL); | ||
2000 | return ide_started; | ||
2001 | } | ||
2002 | #if IDETAPE_DEBUG_LOG | ||
2003 | if (tape->debug_level >= 2) | ||
2004 | printk(KERN_NOTICE "ide-tape: The tape wants to send us more data than expected - allowing transfer\n"); | ||
2005 | #endif /* IDETAPE_DEBUG_LOG */ | ||
2006 | } | ||
2007 | } | ||
2008 | if (test_bit(PC_WRITING, &pc->flags)) { | ||
2009 | if (pc->bh != NULL) | ||
2010 | idetape_output_buffers(drive, pc, bcount.all); | ||
2011 | else | ||
2012 | /* Write the current buffer */ | ||
2013 | HWIF(drive)->atapi_output_bytes(drive, pc->current_position, bcount.all); | ||
2014 | } else { | ||
2015 | if (pc->bh != NULL) | ||
2016 | idetape_input_buffers(drive, pc, bcount.all); | ||
2017 | else | ||
2018 | /* Read the current buffer */ | ||
2019 | HWIF(drive)->atapi_input_bytes(drive, pc->current_position, bcount.all); | ||
2020 | } | ||
2021 | /* Update the current position */ | ||
2022 | pc->actually_transferred += bcount.all; | ||
2023 | pc->current_position += bcount.all; | ||
2024 | #if IDETAPE_DEBUG_LOG | ||
2025 | if (tape->debug_level >= 2) | ||
2026 | printk(KERN_INFO "ide-tape: [cmd %x] transferred %d bytes on that interrupt\n", pc->c[0], bcount.all); | ||
2027 | #endif | ||
2028 | /* And set the interrupt handler again */ | ||
2029 | ide_set_handler(drive, &idetape_pc_intr, IDETAPE_WAIT_CMD, NULL); | ||
2030 | return ide_started; | ||
2031 | } | ||
2032 | |||
2033 | /* | ||
2034 | * Packet Command Interface | ||
2035 | * | ||
2036 | * The current Packet Command is available in tape->pc, and will not | ||
2037 | * change until we finish handling it. Each packet command is associated | ||
2038 | * with a callback function that will be called when the command is | ||
2039 | * finished. | ||
2040 | * | ||
2041 | * The handling will be done in three stages: | ||
2042 | * | ||
2043 | * 1. idetape_issue_packet_command will send the packet command to the | ||
2044 | * drive, and will set the interrupt handler to idetape_pc_intr. | ||
2045 | * | ||
2046 | * 2. On each interrupt, idetape_pc_intr will be called. This step | ||
2047 | * will be repeated until the device signals us that no more | ||
2048 | * interrupts will be issued. | ||
2049 | * | ||
2050 | * 3. ATAPI Tape media access commands have immediate status with a | ||
2051 | * delayed process. In case of a successful initiation of a | ||
2052 | * media access packet command, the DSC bit will be set when the | ||
2053 | * actual execution of the command is finished. | ||
2054 | * Since the tape drive will not issue an interrupt, we have to | ||
2055 | * poll for this event. In this case, we define the request as | ||
2056 | * "low priority request" by setting rq_status to | ||
2057 | * IDETAPE_RQ_POSTPONED, set a timer to poll for DSC and exit | ||
2058 | * the driver. | ||
2059 | * | ||
2060 | * ide.c will then give higher priority to requests which | ||
2061 | * originate from the other device, until will change rq_status | ||
2062 | * to RQ_ACTIVE. | ||
2063 | * | ||
2064 | * 4. When the packet command is finished, it will be checked for errors. | ||
2065 | * | ||
2066 | * 5. In case an error was found, we queue a request sense packet | ||
2067 | * command in front of the request queue and retry the operation | ||
2068 | * up to IDETAPE_MAX_PC_RETRIES times. | ||
2069 | * | ||
2070 | * 6. In case no error was found, or we decided to give up and not | ||
2071 | * to retry again, the callback function will be called and then | ||
2072 | * we will handle the next request. | ||
2073 | * | ||
2074 | */ | ||
2075 | static ide_startstop_t idetape_transfer_pc(ide_drive_t *drive) | ||
2076 | { | ||
2077 | ide_hwif_t *hwif = drive->hwif; | ||
2078 | idetape_tape_t *tape = drive->driver_data; | ||
2079 | idetape_pc_t *pc = tape->pc; | ||
2080 | atapi_ireason_t ireason; | ||
2081 | int retries = 100; | ||
2082 | ide_startstop_t startstop; | ||
2083 | |||
2084 | if (ide_wait_stat(&startstop,drive,DRQ_STAT,BUSY_STAT,WAIT_READY)) { | ||
2085 | printk(KERN_ERR "ide-tape: Strange, packet command initiated yet DRQ isn't asserted\n"); | ||
2086 | return startstop; | ||
2087 | } | ||
2088 | ireason.all = hwif->INB(IDE_IREASON_REG); | ||
2089 | while (retries-- && (!ireason.b.cod || ireason.b.io)) { | ||
2090 | printk(KERN_ERR "ide-tape: (IO,CoD != (0,1) while issuing " | ||
2091 | "a packet command, retrying\n"); | ||
2092 | udelay(100); | ||
2093 | ireason.all = hwif->INB(IDE_IREASON_REG); | ||
2094 | if (retries == 0) { | ||
2095 | printk(KERN_ERR "ide-tape: (IO,CoD != (0,1) while " | ||
2096 | "issuing a packet command, ignoring\n"); | ||
2097 | ireason.b.cod = 1; | ||
2098 | ireason.b.io = 0; | ||
2099 | } | ||
2100 | } | ||
2101 | if (!ireason.b.cod || ireason.b.io) { | ||
2102 | printk(KERN_ERR "ide-tape: (IO,CoD) != (0,1) while issuing " | ||
2103 | "a packet command\n"); | ||
2104 | return ide_do_reset(drive); | ||
2105 | } | ||
2106 | /* Set the interrupt routine */ | ||
2107 | ide_set_handler(drive, &idetape_pc_intr, IDETAPE_WAIT_CMD, NULL); | ||
2108 | #ifdef CONFIG_BLK_DEV_IDEDMA | ||
2109 | /* Begin DMA, if necessary */ | ||
2110 | if (test_bit(PC_DMA_IN_PROGRESS, &pc->flags)) | ||
2111 | hwif->dma_start(drive); | ||
2112 | #endif | ||
2113 | /* Send the actual packet */ | ||
2114 | HWIF(drive)->atapi_output_bytes(drive, pc->c, 12); | ||
2115 | return ide_started; | ||
2116 | } | ||
2117 | |||
2118 | static ide_startstop_t idetape_issue_packet_command (ide_drive_t *drive, idetape_pc_t *pc) | ||
2119 | { | ||
2120 | ide_hwif_t *hwif = drive->hwif; | ||
2121 | idetape_tape_t *tape = drive->driver_data; | ||
2122 | atapi_bcount_t bcount; | ||
2123 | int dma_ok = 0; | ||
2124 | |||
2125 | #if IDETAPE_DEBUG_BUGS | ||
2126 | if (tape->pc->c[0] == IDETAPE_REQUEST_SENSE_CMD && | ||
2127 | pc->c[0] == IDETAPE_REQUEST_SENSE_CMD) { | ||
2128 | printk(KERN_ERR "ide-tape: possible ide-tape.c bug - " | ||
2129 | "Two request sense in serial were issued\n"); | ||
2130 | } | ||
2131 | #endif /* IDETAPE_DEBUG_BUGS */ | ||
2132 | |||
2133 | if (tape->failed_pc == NULL && pc->c[0] != IDETAPE_REQUEST_SENSE_CMD) | ||
2134 | tape->failed_pc = pc; | ||
2135 | /* Set the current packet command */ | ||
2136 | tape->pc = pc; | ||
2137 | |||
2138 | if (pc->retries > IDETAPE_MAX_PC_RETRIES || | ||
2139 | test_bit(PC_ABORT, &pc->flags)) { | ||
2140 | /* | ||
2141 | * We will "abort" retrying a packet command in case | ||
2142 | * a legitimate error code was received (crossing a | ||
2143 | * filemark, or end of the media, for example). | ||
2144 | */ | ||
2145 | if (!test_bit(PC_ABORT, &pc->flags)) { | ||
2146 | if (!(pc->c[0] == IDETAPE_TEST_UNIT_READY_CMD && | ||
2147 | tape->sense_key == 2 && tape->asc == 4 && | ||
2148 | (tape->ascq == 1 || tape->ascq == 8))) { | ||
2149 | printk(KERN_ERR "ide-tape: %s: I/O error, " | ||
2150 | "pc = %2x, key = %2x, " | ||
2151 | "asc = %2x, ascq = %2x\n", | ||
2152 | tape->name, pc->c[0], | ||
2153 | tape->sense_key, tape->asc, | ||
2154 | tape->ascq); | ||
2155 | } | ||
2156 | /* Giving up */ | ||
2157 | pc->error = IDETAPE_ERROR_GENERAL; | ||
2158 | } | ||
2159 | tape->failed_pc = NULL; | ||
2160 | return pc->callback(drive); | ||
2161 | } | ||
2162 | #if IDETAPE_DEBUG_LOG | ||
2163 | if (tape->debug_level >= 2) | ||
2164 | printk(KERN_INFO "ide-tape: Retry number - %d, cmd = %02X\n", pc->retries, pc->c[0]); | ||
2165 | #endif /* IDETAPE_DEBUG_LOG */ | ||
2166 | |||
2167 | pc->retries++; | ||
2168 | /* We haven't transferred any data yet */ | ||
2169 | pc->actually_transferred = 0; | ||
2170 | pc->current_position = pc->buffer; | ||
2171 | /* Request to transfer the entire buffer at once */ | ||
2172 | bcount.all = pc->request_transfer; | ||
2173 | |||
2174 | if (test_and_clear_bit(PC_DMA_ERROR, &pc->flags)) { | ||
2175 | printk(KERN_WARNING "ide-tape: DMA disabled, " | ||
2176 | "reverting to PIO\n"); | ||
2177 | (void)__ide_dma_off(drive); | ||
2178 | } | ||
2179 | if (test_bit(PC_DMA_RECOMMENDED, &pc->flags) && drive->using_dma) | ||
2180 | dma_ok = !hwif->dma_setup(drive); | ||
2181 | |||
2182 | if (IDE_CONTROL_REG) | ||
2183 | hwif->OUTB(drive->ctl, IDE_CONTROL_REG); | ||
2184 | hwif->OUTB(dma_ok ? 1 : 0, IDE_FEATURE_REG); /* Use PIO/DMA */ | ||
2185 | hwif->OUTB(bcount.b.high, IDE_BCOUNTH_REG); | ||
2186 | hwif->OUTB(bcount.b.low, IDE_BCOUNTL_REG); | ||
2187 | hwif->OUTB(drive->select.all, IDE_SELECT_REG); | ||
2188 | if (dma_ok) /* Will begin DMA later */ | ||
2189 | set_bit(PC_DMA_IN_PROGRESS, &pc->flags); | ||
2190 | if (test_bit(IDETAPE_DRQ_INTERRUPT, &tape->flags)) { | ||
2191 | ide_set_handler(drive, &idetape_transfer_pc, IDETAPE_WAIT_CMD, NULL); | ||
2192 | hwif->OUTB(WIN_PACKETCMD, IDE_COMMAND_REG); | ||
2193 | return ide_started; | ||
2194 | } else { | ||
2195 | hwif->OUTB(WIN_PACKETCMD, IDE_COMMAND_REG); | ||
2196 | return idetape_transfer_pc(drive); | ||
2197 | } | ||
2198 | } | ||
2199 | |||
2200 | /* | ||
2201 | * General packet command callback function. | ||
2202 | */ | ||
2203 | static ide_startstop_t idetape_pc_callback (ide_drive_t *drive) | ||
2204 | { | ||
2205 | idetape_tape_t *tape = drive->driver_data; | ||
2206 | |||
2207 | #if IDETAPE_DEBUG_LOG | ||
2208 | if (tape->debug_level >= 4) | ||
2209 | printk(KERN_INFO "ide-tape: Reached idetape_pc_callback\n"); | ||
2210 | #endif /* IDETAPE_DEBUG_LOG */ | ||
2211 | |||
2212 | idetape_end_request(drive, tape->pc->error ? 0 : 1, 0); | ||
2213 | return ide_stopped; | ||
2214 | } | ||
2215 | |||
2216 | /* | ||
2217 | * A mode sense command is used to "sense" tape parameters. | ||
2218 | */ | ||
2219 | static void idetape_create_mode_sense_cmd (idetape_pc_t *pc, u8 page_code) | ||
2220 | { | ||
2221 | idetape_init_pc(pc); | ||
2222 | pc->c[0] = IDETAPE_MODE_SENSE_CMD; | ||
2223 | if (page_code != IDETAPE_BLOCK_DESCRIPTOR) | ||
2224 | pc->c[1] = 8; /* DBD = 1 - Don't return block descriptors */ | ||
2225 | pc->c[2] = page_code; | ||
2226 | /* | ||
2227 | * Changed pc->c[3] to 0 (255 will at best return unused info). | ||
2228 | * | ||
2229 | * For SCSI this byte is defined as subpage instead of high byte | ||
2230 | * of length and some IDE drives seem to interpret it this way | ||
2231 | * and return an error when 255 is used. | ||
2232 | */ | ||
2233 | pc->c[3] = 0; | ||
2234 | pc->c[4] = 255; /* (We will just discard data in that case) */ | ||
2235 | if (page_code == IDETAPE_BLOCK_DESCRIPTOR) | ||
2236 | pc->request_transfer = 12; | ||
2237 | else if (page_code == IDETAPE_CAPABILITIES_PAGE) | ||
2238 | pc->request_transfer = 24; | ||
2239 | else | ||
2240 | pc->request_transfer = 50; | ||
2241 | pc->callback = &idetape_pc_callback; | ||
2242 | } | ||
2243 | |||
2244 | static void calculate_speeds(ide_drive_t *drive) | ||
2245 | { | ||
2246 | idetape_tape_t *tape = drive->driver_data; | ||
2247 | int full = 125, empty = 75; | ||
2248 | |||
2249 | if (time_after(jiffies, tape->controlled_pipeline_head_time + 120 * HZ)) { | ||
2250 | tape->controlled_previous_pipeline_head = tape->controlled_last_pipeline_head; | ||
2251 | tape->controlled_previous_head_time = tape->controlled_pipeline_head_time; | ||
2252 | tape->controlled_last_pipeline_head = tape->pipeline_head; | ||
2253 | tape->controlled_pipeline_head_time = jiffies; | ||
2254 | } | ||
2255 | if (time_after(jiffies, tape->controlled_pipeline_head_time + 60 * HZ)) | ||
2256 | tape->controlled_pipeline_head_speed = (tape->pipeline_head - tape->controlled_last_pipeline_head) * 32 * HZ / (jiffies - tape->controlled_pipeline_head_time); | ||
2257 | else if (time_after(jiffies, tape->controlled_previous_head_time)) | ||
2258 | tape->controlled_pipeline_head_speed = (tape->pipeline_head - tape->controlled_previous_pipeline_head) * 32 * HZ / (jiffies - tape->controlled_previous_head_time); | ||
2259 | |||
2260 | if (tape->nr_pending_stages < tape->max_stages /*- 1 */) { | ||
2261 | /* -1 for read mode error recovery */ | ||
2262 | if (time_after(jiffies, tape->uncontrolled_previous_head_time + 10 * HZ)) { | ||
2263 | tape->uncontrolled_pipeline_head_time = jiffies; | ||
2264 | tape->uncontrolled_pipeline_head_speed = (tape->pipeline_head - tape->uncontrolled_previous_pipeline_head) * 32 * HZ / (jiffies - tape->uncontrolled_previous_head_time); | ||
2265 | } | ||
2266 | } else { | ||
2267 | tape->uncontrolled_previous_head_time = jiffies; | ||
2268 | tape->uncontrolled_previous_pipeline_head = tape->pipeline_head; | ||
2269 | if (time_after(jiffies, tape->uncontrolled_pipeline_head_time + 30 * HZ)) { | ||
2270 | tape->uncontrolled_pipeline_head_time = jiffies; | ||
2271 | } | ||
2272 | } | ||
2273 | tape->pipeline_head_speed = max(tape->uncontrolled_pipeline_head_speed, tape->controlled_pipeline_head_speed); | ||
2274 | if (tape->speed_control == 0) { | ||
2275 | tape->max_insert_speed = 5000; | ||
2276 | } else if (tape->speed_control == 1) { | ||
2277 | if (tape->nr_pending_stages >= tape->max_stages / 2) | ||
2278 | tape->max_insert_speed = tape->pipeline_head_speed + | ||
2279 | (1100 - tape->pipeline_head_speed) * 2 * (tape->nr_pending_stages - tape->max_stages / 2) / tape->max_stages; | ||
2280 | else | ||
2281 | tape->max_insert_speed = 500 + | ||
2282 | (tape->pipeline_head_speed - 500) * 2 * tape->nr_pending_stages / tape->max_stages; | ||
2283 | if (tape->nr_pending_stages >= tape->max_stages * 99 / 100) | ||
2284 | tape->max_insert_speed = 5000; | ||
2285 | } else if (tape->speed_control == 2) { | ||
2286 | tape->max_insert_speed = tape->pipeline_head_speed * empty / 100 + | ||
2287 | (tape->pipeline_head_speed * full / 100 - tape->pipeline_head_speed * empty / 100) * tape->nr_pending_stages / tape->max_stages; | ||
2288 | } else | ||
2289 | tape->max_insert_speed = tape->speed_control; | ||
2290 | tape->max_insert_speed = max(tape->max_insert_speed, 500); | ||
2291 | } | ||
2292 | |||
2293 | static ide_startstop_t idetape_media_access_finished (ide_drive_t *drive) | ||
2294 | { | ||
2295 | idetape_tape_t *tape = drive->driver_data; | ||
2296 | idetape_pc_t *pc = tape->pc; | ||
2297 | atapi_status_t status; | ||
2298 | |||
2299 | status.all = HWIF(drive)->INB(IDE_STATUS_REG); | ||
2300 | if (status.b.dsc) { | ||
2301 | if (status.b.check) { | ||
2302 | /* Error detected */ | ||
2303 | if (pc->c[0] != IDETAPE_TEST_UNIT_READY_CMD) | ||
2304 | printk(KERN_ERR "ide-tape: %s: I/O error, ", | ||
2305 | tape->name); | ||
2306 | /* Retry operation */ | ||
2307 | return idetape_retry_pc(drive); | ||
2308 | } | ||
2309 | pc->error = 0; | ||
2310 | if (tape->failed_pc == pc) | ||
2311 | tape->failed_pc = NULL; | ||
2312 | } else { | ||
2313 | pc->error = IDETAPE_ERROR_GENERAL; | ||
2314 | tape->failed_pc = NULL; | ||
2315 | } | ||
2316 | return pc->callback(drive); | ||
2317 | } | ||
2318 | |||
2319 | static ide_startstop_t idetape_rw_callback (ide_drive_t *drive) | ||
2320 | { | ||
2321 | idetape_tape_t *tape = drive->driver_data; | ||
2322 | struct request *rq = HWGROUP(drive)->rq; | ||
2323 | int blocks = tape->pc->actually_transferred / tape->tape_block_size; | ||
2324 | |||
2325 | tape->avg_size += blocks * tape->tape_block_size; | ||
2326 | tape->insert_size += blocks * tape->tape_block_size; | ||
2327 | if (tape->insert_size > 1024 * 1024) | ||
2328 | tape->measure_insert_time = 1; | ||
2329 | if (tape->measure_insert_time) { | ||
2330 | tape->measure_insert_time = 0; | ||
2331 | tape->insert_time = jiffies; | ||
2332 | tape->insert_size = 0; | ||
2333 | } | ||
2334 | if (time_after(jiffies, tape->insert_time)) | ||
2335 | tape->insert_speed = tape->insert_size / 1024 * HZ / (jiffies - tape->insert_time); | ||
2336 | if (jiffies - tape->avg_time >= HZ) { | ||
2337 | tape->avg_speed = tape->avg_size * HZ / (jiffies - tape->avg_time) / 1024; | ||
2338 | tape->avg_size = 0; | ||
2339 | tape->avg_time = jiffies; | ||
2340 | } | ||
2341 | |||
2342 | #if IDETAPE_DEBUG_LOG | ||
2343 | if (tape->debug_level >= 4) | ||
2344 | printk(KERN_INFO "ide-tape: Reached idetape_rw_callback\n"); | ||
2345 | #endif /* IDETAPE_DEBUG_LOG */ | ||
2346 | |||
2347 | tape->first_frame_position += blocks; | ||
2348 | rq->current_nr_sectors -= blocks; | ||
2349 | |||
2350 | if (!tape->pc->error) | ||
2351 | idetape_end_request(drive, 1, 0); | ||
2352 | else | ||
2353 | idetape_end_request(drive, tape->pc->error, 0); | ||
2354 | return ide_stopped; | ||
2355 | } | ||
2356 | |||
2357 | static void idetape_create_read_cmd(idetape_tape_t *tape, idetape_pc_t *pc, unsigned int length, struct idetape_bh *bh) | ||
2358 | { | ||
2359 | idetape_init_pc(pc); | ||
2360 | pc->c[0] = IDETAPE_READ_CMD; | ||
2361 | put_unaligned(htonl(length), (unsigned int *) &pc->c[1]); | ||
2362 | pc->c[1] = 1; | ||
2363 | pc->callback = &idetape_rw_callback; | ||
2364 | pc->bh = bh; | ||
2365 | atomic_set(&bh->b_count, 0); | ||
2366 | pc->buffer = NULL; | ||
2367 | pc->request_transfer = pc->buffer_size = length * tape->tape_block_size; | ||
2368 | if (pc->request_transfer == tape->stage_size) | ||
2369 | set_bit(PC_DMA_RECOMMENDED, &pc->flags); | ||
2370 | } | ||
2371 | |||
2372 | static void idetape_create_read_buffer_cmd(idetape_tape_t *tape, idetape_pc_t *pc, unsigned int length, struct idetape_bh *bh) | ||
2373 | { | ||
2374 | int size = 32768; | ||
2375 | struct idetape_bh *p = bh; | ||
2376 | |||
2377 | idetape_init_pc(pc); | ||
2378 | pc->c[0] = IDETAPE_READ_BUFFER_CMD; | ||
2379 | pc->c[1] = IDETAPE_RETRIEVE_FAULTY_BLOCK; | ||
2380 | pc->c[7] = size >> 8; | ||
2381 | pc->c[8] = size & 0xff; | ||
2382 | pc->callback = &idetape_pc_callback; | ||
2383 | pc->bh = bh; | ||
2384 | atomic_set(&bh->b_count, 0); | ||
2385 | pc->buffer = NULL; | ||
2386 | while (p) { | ||
2387 | atomic_set(&p->b_count, 0); | ||
2388 | p = p->b_reqnext; | ||
2389 | } | ||
2390 | pc->request_transfer = pc->buffer_size = size; | ||
2391 | } | ||
2392 | |||
2393 | static void idetape_create_write_cmd(idetape_tape_t *tape, idetape_pc_t *pc, unsigned int length, struct idetape_bh *bh) | ||
2394 | { | ||
2395 | idetape_init_pc(pc); | ||
2396 | pc->c[0] = IDETAPE_WRITE_CMD; | ||
2397 | put_unaligned(htonl(length), (unsigned int *) &pc->c[1]); | ||
2398 | pc->c[1] = 1; | ||
2399 | pc->callback = &idetape_rw_callback; | ||
2400 | set_bit(PC_WRITING, &pc->flags); | ||
2401 | pc->bh = bh; | ||
2402 | pc->b_data = bh->b_data; | ||
2403 | pc->b_count = atomic_read(&bh->b_count); | ||
2404 | pc->buffer = NULL; | ||
2405 | pc->request_transfer = pc->buffer_size = length * tape->tape_block_size; | ||
2406 | if (pc->request_transfer == tape->stage_size) | ||
2407 | set_bit(PC_DMA_RECOMMENDED, &pc->flags); | ||
2408 | } | ||
2409 | |||
2410 | /* | ||
2411 | * idetape_do_request is our request handling function. | ||
2412 | */ | ||
2413 | static ide_startstop_t idetape_do_request(ide_drive_t *drive, | ||
2414 | struct request *rq, sector_t block) | ||
2415 | { | ||
2416 | idetape_tape_t *tape = drive->driver_data; | ||
2417 | idetape_pc_t *pc = NULL; | ||
2418 | struct request *postponed_rq = tape->postponed_rq; | ||
2419 | atapi_status_t status; | ||
2420 | |||
2421 | #if IDETAPE_DEBUG_LOG | ||
2422 | #if 0 | ||
2423 | if (tape->debug_level >= 5) | ||
2424 | printk(KERN_INFO "ide-tape: rq_status: %d, " | ||
2425 | "dev: %s, cmd: %ld, errors: %d\n", rq->rq_status, | ||
2426 | rq->rq_disk->disk_name, rq->cmd[0], rq->errors); | ||
2427 | #endif | ||
2428 | if (tape->debug_level >= 2) | ||
2429 | printk(KERN_INFO "ide-tape: sector: %ld, " | ||
2430 | "nr_sectors: %ld, current_nr_sectors: %d\n", | ||
2431 | rq->sector, rq->nr_sectors, rq->current_nr_sectors); | ||
2432 | #endif /* IDETAPE_DEBUG_LOG */ | ||
2433 | |||
2434 | if ((rq->flags & REQ_SPECIAL) == 0) { | ||
2435 | /* | ||
2436 | * We do not support buffer cache originated requests. | ||
2437 | */ | ||
2438 | printk(KERN_NOTICE "ide-tape: %s: Unsupported request in " | ||
2439 | "request queue (%ld)\n", drive->name, rq->flags); | ||
2440 | ide_end_request(drive, 0, 0); | ||
2441 | return ide_stopped; | ||
2442 | } | ||
2443 | |||
2444 | /* | ||
2445 | * Retry a failed packet command | ||
2446 | */ | ||
2447 | if (tape->failed_pc != NULL && | ||
2448 | tape->pc->c[0] == IDETAPE_REQUEST_SENSE_CMD) { | ||
2449 | return idetape_issue_packet_command(drive, tape->failed_pc); | ||
2450 | } | ||
2451 | #if IDETAPE_DEBUG_BUGS | ||
2452 | if (postponed_rq != NULL) | ||
2453 | if (rq != postponed_rq) { | ||
2454 | printk(KERN_ERR "ide-tape: ide-tape.c bug - " | ||
2455 | "Two DSC requests were queued\n"); | ||
2456 | idetape_end_request(drive, 0, 0); | ||
2457 | return ide_stopped; | ||
2458 | } | ||
2459 | #endif /* IDETAPE_DEBUG_BUGS */ | ||
2460 | |||
2461 | tape->postponed_rq = NULL; | ||
2462 | |||
2463 | /* | ||
2464 | * If the tape is still busy, postpone our request and service | ||
2465 | * the other device meanwhile. | ||
2466 | */ | ||
2467 | status.all = HWIF(drive)->INB(IDE_STATUS_REG); | ||
2468 | |||
2469 | if (!drive->dsc_overlap && !(rq->cmd[0] & REQ_IDETAPE_PC2)) | ||
2470 | set_bit(IDETAPE_IGNORE_DSC, &tape->flags); | ||
2471 | |||
2472 | if (drive->post_reset == 1) { | ||
2473 | set_bit(IDETAPE_IGNORE_DSC, &tape->flags); | ||
2474 | drive->post_reset = 0; | ||
2475 | } | ||
2476 | |||
2477 | if (tape->tape_still_time > 100 && tape->tape_still_time < 200) | ||
2478 | tape->measure_insert_time = 1; | ||
2479 | if (time_after(jiffies, tape->insert_time)) | ||
2480 | tape->insert_speed = tape->insert_size / 1024 * HZ / (jiffies - tape->insert_time); | ||
2481 | calculate_speeds(drive); | ||
2482 | if (!test_and_clear_bit(IDETAPE_IGNORE_DSC, &tape->flags) && | ||
2483 | !status.b.dsc) { | ||
2484 | if (postponed_rq == NULL) { | ||
2485 | tape->dsc_polling_start = jiffies; | ||
2486 | tape->dsc_polling_frequency = tape->best_dsc_rw_frequency; | ||
2487 | tape->dsc_timeout = jiffies + IDETAPE_DSC_RW_TIMEOUT; | ||
2488 | } else if (time_after(jiffies, tape->dsc_timeout)) { | ||
2489 | printk(KERN_ERR "ide-tape: %s: DSC timeout\n", | ||
2490 | tape->name); | ||
2491 | if (rq->cmd[0] & REQ_IDETAPE_PC2) { | ||
2492 | idetape_media_access_finished(drive); | ||
2493 | return ide_stopped; | ||
2494 | } else { | ||
2495 | return ide_do_reset(drive); | ||
2496 | } | ||
2497 | } else if (jiffies - tape->dsc_polling_start > IDETAPE_DSC_MA_THRESHOLD) | ||
2498 | tape->dsc_polling_frequency = IDETAPE_DSC_MA_SLOW; | ||
2499 | idetape_postpone_request(drive); | ||
2500 | return ide_stopped; | ||
2501 | } | ||
2502 | if (rq->cmd[0] & REQ_IDETAPE_READ) { | ||
2503 | tape->buffer_head++; | ||
2504 | #if USE_IOTRACE | ||
2505 | IO_trace(IO_IDETAPE_FIFO, tape->pipeline_head, tape->buffer_head, tape->tape_head, tape->minor); | ||
2506 | #endif | ||
2507 | tape->postpone_cnt = 0; | ||
2508 | pc = idetape_next_pc_storage(drive); | ||
2509 | idetape_create_read_cmd(tape, pc, rq->current_nr_sectors, (struct idetape_bh *)rq->special); | ||
2510 | goto out; | ||
2511 | } | ||
2512 | if (rq->cmd[0] & REQ_IDETAPE_WRITE) { | ||
2513 | tape->buffer_head++; | ||
2514 | #if USE_IOTRACE | ||
2515 | IO_trace(IO_IDETAPE_FIFO, tape->pipeline_head, tape->buffer_head, tape->tape_head, tape->minor); | ||
2516 | #endif | ||
2517 | tape->postpone_cnt = 0; | ||
2518 | pc = idetape_next_pc_storage(drive); | ||
2519 | idetape_create_write_cmd(tape, pc, rq->current_nr_sectors, (struct idetape_bh *)rq->special); | ||
2520 | goto out; | ||
2521 | } | ||
2522 | if (rq->cmd[0] & REQ_IDETAPE_READ_BUFFER) { | ||
2523 | tape->postpone_cnt = 0; | ||
2524 | pc = idetape_next_pc_storage(drive); | ||
2525 | idetape_create_read_buffer_cmd(tape, pc, rq->current_nr_sectors, (struct idetape_bh *)rq->special); | ||
2526 | goto out; | ||
2527 | } | ||
2528 | if (rq->cmd[0] & REQ_IDETAPE_PC1) { | ||
2529 | pc = (idetape_pc_t *) rq->buffer; | ||
2530 | rq->cmd[0] &= ~(REQ_IDETAPE_PC1); | ||
2531 | rq->cmd[0] |= REQ_IDETAPE_PC2; | ||
2532 | goto out; | ||
2533 | } | ||
2534 | if (rq->cmd[0] & REQ_IDETAPE_PC2) { | ||
2535 | idetape_media_access_finished(drive); | ||
2536 | return ide_stopped; | ||
2537 | } | ||
2538 | BUG(); | ||
2539 | out: | ||
2540 | return idetape_issue_packet_command(drive, pc); | ||
2541 | } | ||
2542 | |||
2543 | /* | ||
2544 | * Pipeline related functions | ||
2545 | */ | ||
2546 | static inline int idetape_pipeline_active (idetape_tape_t *tape) | ||
2547 | { | ||
2548 | int rc1, rc2; | ||
2549 | |||
2550 | rc1 = test_bit(IDETAPE_PIPELINE_ACTIVE, &tape->flags); | ||
2551 | rc2 = (tape->active_data_request != NULL); | ||
2552 | return rc1; | ||
2553 | } | ||
2554 | |||
2555 | /* | ||
2556 | * idetape_kmalloc_stage uses __get_free_page to allocate a pipeline | ||
2557 | * stage, along with all the necessary small buffers which together make | ||
2558 | * a buffer of size tape->stage_size (or a bit more). We attempt to | ||
2559 | * combine sequential pages as much as possible. | ||
2560 | * | ||
2561 | * Returns a pointer to the new allocated stage, or NULL if we | ||
2562 | * can't (or don't want to) allocate a stage. | ||
2563 | * | ||
2564 | * Pipeline stages are optional and are used to increase performance. | ||
2565 | * If we can't allocate them, we'll manage without them. | ||
2566 | */ | ||
2567 | static idetape_stage_t *__idetape_kmalloc_stage (idetape_tape_t *tape, int full, int clear) | ||
2568 | { | ||
2569 | idetape_stage_t *stage; | ||
2570 | struct idetape_bh *prev_bh, *bh; | ||
2571 | int pages = tape->pages_per_stage; | ||
2572 | char *b_data = NULL; | ||
2573 | |||
2574 | if ((stage = (idetape_stage_t *) kmalloc (sizeof (idetape_stage_t),GFP_KERNEL)) == NULL) | ||
2575 | return NULL; | ||
2576 | stage->next = NULL; | ||
2577 | |||
2578 | bh = stage->bh = (struct idetape_bh *)kmalloc(sizeof(struct idetape_bh), GFP_KERNEL); | ||
2579 | if (bh == NULL) | ||
2580 | goto abort; | ||
2581 | bh->b_reqnext = NULL; | ||
2582 | if ((bh->b_data = (char *) __get_free_page (GFP_KERNEL)) == NULL) | ||
2583 | goto abort; | ||
2584 | if (clear) | ||
2585 | memset(bh->b_data, 0, PAGE_SIZE); | ||
2586 | bh->b_size = PAGE_SIZE; | ||
2587 | atomic_set(&bh->b_count, full ? bh->b_size : 0); | ||
2588 | |||
2589 | while (--pages) { | ||
2590 | if ((b_data = (char *) __get_free_page (GFP_KERNEL)) == NULL) | ||
2591 | goto abort; | ||
2592 | if (clear) | ||
2593 | memset(b_data, 0, PAGE_SIZE); | ||
2594 | if (bh->b_data == b_data + PAGE_SIZE) { | ||
2595 | bh->b_size += PAGE_SIZE; | ||
2596 | bh->b_data -= PAGE_SIZE; | ||
2597 | if (full) | ||
2598 | atomic_add(PAGE_SIZE, &bh->b_count); | ||
2599 | continue; | ||
2600 | } | ||
2601 | if (b_data == bh->b_data + bh->b_size) { | ||
2602 | bh->b_size += PAGE_SIZE; | ||
2603 | if (full) | ||
2604 | atomic_add(PAGE_SIZE, &bh->b_count); | ||
2605 | continue; | ||
2606 | } | ||
2607 | prev_bh = bh; | ||
2608 | if ((bh = (struct idetape_bh *)kmalloc(sizeof(struct idetape_bh), GFP_KERNEL)) == NULL) { | ||
2609 | free_page((unsigned long) b_data); | ||
2610 | goto abort; | ||
2611 | } | ||
2612 | bh->b_reqnext = NULL; | ||
2613 | bh->b_data = b_data; | ||
2614 | bh->b_size = PAGE_SIZE; | ||
2615 | atomic_set(&bh->b_count, full ? bh->b_size : 0); | ||
2616 | prev_bh->b_reqnext = bh; | ||
2617 | } | ||
2618 | bh->b_size -= tape->excess_bh_size; | ||
2619 | if (full) | ||
2620 | atomic_sub(tape->excess_bh_size, &bh->b_count); | ||
2621 | return stage; | ||
2622 | abort: | ||
2623 | __idetape_kfree_stage(stage); | ||
2624 | return NULL; | ||
2625 | } | ||
2626 | |||
2627 | static idetape_stage_t *idetape_kmalloc_stage (idetape_tape_t *tape) | ||
2628 | { | ||
2629 | idetape_stage_t *cache_stage = tape->cache_stage; | ||
2630 | |||
2631 | #if IDETAPE_DEBUG_LOG | ||
2632 | if (tape->debug_level >= 4) | ||
2633 | printk(KERN_INFO "ide-tape: Reached idetape_kmalloc_stage\n"); | ||
2634 | #endif /* IDETAPE_DEBUG_LOG */ | ||
2635 | |||
2636 | if (tape->nr_stages >= tape->max_stages) | ||
2637 | return NULL; | ||
2638 | if (cache_stage != NULL) { | ||
2639 | tape->cache_stage = NULL; | ||
2640 | return cache_stage; | ||
2641 | } | ||
2642 | return __idetape_kmalloc_stage(tape, 0, 0); | ||
2643 | } | ||
2644 | |||
2645 | static void idetape_copy_stage_from_user (idetape_tape_t *tape, idetape_stage_t *stage, const char __user *buf, int n) | ||
2646 | { | ||
2647 | struct idetape_bh *bh = tape->bh; | ||
2648 | int count; | ||
2649 | |||
2650 | while (n) { | ||
2651 | #if IDETAPE_DEBUG_BUGS | ||
2652 | if (bh == NULL) { | ||
2653 | printk(KERN_ERR "ide-tape: bh == NULL in " | ||
2654 | "idetape_copy_stage_from_user\n"); | ||
2655 | return; | ||
2656 | } | ||
2657 | #endif /* IDETAPE_DEBUG_BUGS */ | ||
2658 | count = min((unsigned int)(bh->b_size - atomic_read(&bh->b_count)), (unsigned int)n); | ||
2659 | copy_from_user(bh->b_data + atomic_read(&bh->b_count), buf, count); | ||
2660 | n -= count; | ||
2661 | atomic_add(count, &bh->b_count); | ||
2662 | buf += count; | ||
2663 | if (atomic_read(&bh->b_count) == bh->b_size) { | ||
2664 | bh = bh->b_reqnext; | ||
2665 | if (bh) | ||
2666 | atomic_set(&bh->b_count, 0); | ||
2667 | } | ||
2668 | } | ||
2669 | tape->bh = bh; | ||
2670 | } | ||
2671 | |||
2672 | static void idetape_copy_stage_to_user (idetape_tape_t *tape, char __user *buf, idetape_stage_t *stage, int n) | ||
2673 | { | ||
2674 | struct idetape_bh *bh = tape->bh; | ||
2675 | int count; | ||
2676 | |||
2677 | while (n) { | ||
2678 | #if IDETAPE_DEBUG_BUGS | ||
2679 | if (bh == NULL) { | ||
2680 | printk(KERN_ERR "ide-tape: bh == NULL in " | ||
2681 | "idetape_copy_stage_to_user\n"); | ||
2682 | return; | ||
2683 | } | ||
2684 | #endif /* IDETAPE_DEBUG_BUGS */ | ||
2685 | count = min(tape->b_count, n); | ||
2686 | copy_to_user(buf, tape->b_data, count); | ||
2687 | n -= count; | ||
2688 | tape->b_data += count; | ||
2689 | tape->b_count -= count; | ||
2690 | buf += count; | ||
2691 | if (!tape->b_count) { | ||
2692 | tape->bh = bh = bh->b_reqnext; | ||
2693 | if (bh) { | ||
2694 | tape->b_data = bh->b_data; | ||
2695 | tape->b_count = atomic_read(&bh->b_count); | ||
2696 | } | ||
2697 | } | ||
2698 | } | ||
2699 | } | ||
2700 | |||
2701 | static void idetape_init_merge_stage (idetape_tape_t *tape) | ||
2702 | { | ||
2703 | struct idetape_bh *bh = tape->merge_stage->bh; | ||
2704 | |||
2705 | tape->bh = bh; | ||
2706 | if (tape->chrdev_direction == idetape_direction_write) | ||
2707 | atomic_set(&bh->b_count, 0); | ||
2708 | else { | ||
2709 | tape->b_data = bh->b_data; | ||
2710 | tape->b_count = atomic_read(&bh->b_count); | ||
2711 | } | ||
2712 | } | ||
2713 | |||
2714 | static void idetape_switch_buffers (idetape_tape_t *tape, idetape_stage_t *stage) | ||
2715 | { | ||
2716 | struct idetape_bh *tmp; | ||
2717 | |||
2718 | tmp = stage->bh; | ||
2719 | stage->bh = tape->merge_stage->bh; | ||
2720 | tape->merge_stage->bh = tmp; | ||
2721 | idetape_init_merge_stage(tape); | ||
2722 | } | ||
2723 | |||
2724 | /* | ||
2725 | * idetape_add_stage_tail adds a new stage at the end of the pipeline. | ||
2726 | */ | ||
2727 | static void idetape_add_stage_tail (ide_drive_t *drive,idetape_stage_t *stage) | ||
2728 | { | ||
2729 | idetape_tape_t *tape = drive->driver_data; | ||
2730 | unsigned long flags; | ||
2731 | |||
2732 | #if IDETAPE_DEBUG_LOG | ||
2733 | if (tape->debug_level >= 4) | ||
2734 | printk (KERN_INFO "ide-tape: Reached idetape_add_stage_tail\n"); | ||
2735 | #endif /* IDETAPE_DEBUG_LOG */ | ||
2736 | spin_lock_irqsave(&tape->spinlock, flags); | ||
2737 | stage->next = NULL; | ||
2738 | if (tape->last_stage != NULL) | ||
2739 | tape->last_stage->next=stage; | ||
2740 | else | ||
2741 | tape->first_stage = tape->next_stage=stage; | ||
2742 | tape->last_stage = stage; | ||
2743 | if (tape->next_stage == NULL) | ||
2744 | tape->next_stage = tape->last_stage; | ||
2745 | tape->nr_stages++; | ||
2746 | tape->nr_pending_stages++; | ||
2747 | spin_unlock_irqrestore(&tape->spinlock, flags); | ||
2748 | } | ||
2749 | |||
2750 | /* | ||
2751 | * idetape_wait_for_request installs a completion in a pending request | ||
2752 | * and sleeps until it is serviced. | ||
2753 | * | ||
2754 | * The caller should ensure that the request will not be serviced | ||
2755 | * before we install the completion (usually by disabling interrupts). | ||
2756 | */ | ||
2757 | static void idetape_wait_for_request (ide_drive_t *drive, struct request *rq) | ||
2758 | { | ||
2759 | DECLARE_COMPLETION(wait); | ||
2760 | idetape_tape_t *tape = drive->driver_data; | ||
2761 | |||
2762 | #if IDETAPE_DEBUG_BUGS | ||
2763 | if (rq == NULL || (rq->flags & REQ_SPECIAL) == 0) { | ||
2764 | printk (KERN_ERR "ide-tape: bug: Trying to sleep on non-valid request\n"); | ||
2765 | return; | ||
2766 | } | ||
2767 | #endif /* IDETAPE_DEBUG_BUGS */ | ||
2768 | rq->waiting = &wait; | ||
2769 | rq->end_io = blk_end_sync_rq; | ||
2770 | spin_unlock_irq(&tape->spinlock); | ||
2771 | wait_for_completion(&wait); | ||
2772 | /* The stage and its struct request have been deallocated */ | ||
2773 | spin_lock_irq(&tape->spinlock); | ||
2774 | } | ||
2775 | |||
2776 | static ide_startstop_t idetape_read_position_callback (ide_drive_t *drive) | ||
2777 | { | ||
2778 | idetape_tape_t *tape = drive->driver_data; | ||
2779 | idetape_read_position_result_t *result; | ||
2780 | |||
2781 | #if IDETAPE_DEBUG_LOG | ||
2782 | if (tape->debug_level >= 4) | ||
2783 | printk(KERN_INFO "ide-tape: Reached idetape_read_position_callback\n"); | ||
2784 | #endif /* IDETAPE_DEBUG_LOG */ | ||
2785 | |||
2786 | if (!tape->pc->error) { | ||
2787 | result = (idetape_read_position_result_t *) tape->pc->buffer; | ||
2788 | #if IDETAPE_DEBUG_LOG | ||
2789 | if (tape->debug_level >= 2) | ||
2790 | printk(KERN_INFO "ide-tape: BOP - %s\n",result->bop ? "Yes":"No"); | ||
2791 | if (tape->debug_level >= 2) | ||
2792 | printk(KERN_INFO "ide-tape: EOP - %s\n",result->eop ? "Yes":"No"); | ||
2793 | #endif /* IDETAPE_DEBUG_LOG */ | ||
2794 | if (result->bpu) { | ||
2795 | printk(KERN_INFO "ide-tape: Block location is unknown to the tape\n"); | ||
2796 | clear_bit(IDETAPE_ADDRESS_VALID, &tape->flags); | ||
2797 | idetape_end_request(drive, 0, 0); | ||
2798 | } else { | ||
2799 | #if IDETAPE_DEBUG_LOG | ||
2800 | if (tape->debug_level >= 2) | ||
2801 | printk(KERN_INFO "ide-tape: Block Location - %u\n", ntohl(result->first_block)); | ||
2802 | #endif /* IDETAPE_DEBUG_LOG */ | ||
2803 | tape->partition = result->partition; | ||
2804 | tape->first_frame_position = ntohl(result->first_block); | ||
2805 | tape->last_frame_position = ntohl(result->last_block); | ||
2806 | tape->blocks_in_buffer = result->blocks_in_buffer[2]; | ||
2807 | set_bit(IDETAPE_ADDRESS_VALID, &tape->flags); | ||
2808 | idetape_end_request(drive, 1, 0); | ||
2809 | } | ||
2810 | } else { | ||
2811 | idetape_end_request(drive, 0, 0); | ||
2812 | } | ||
2813 | return ide_stopped; | ||
2814 | } | ||
2815 | |||
2816 | /* | ||
2817 | * idetape_create_write_filemark_cmd will: | ||
2818 | * | ||
2819 | * 1. Write a filemark if write_filemark=1. | ||
2820 | * 2. Flush the device buffers without writing a filemark | ||
2821 | * if write_filemark=0. | ||
2822 | * | ||
2823 | */ | ||
2824 | static void idetape_create_write_filemark_cmd (ide_drive_t *drive, idetape_pc_t *pc,int write_filemark) | ||
2825 | { | ||
2826 | idetape_init_pc(pc); | ||
2827 | pc->c[0] = IDETAPE_WRITE_FILEMARK_CMD; | ||
2828 | pc->c[4] = write_filemark; | ||
2829 | set_bit(PC_WAIT_FOR_DSC, &pc->flags); | ||
2830 | pc->callback = &idetape_pc_callback; | ||
2831 | } | ||
2832 | |||
2833 | static void idetape_create_test_unit_ready_cmd(idetape_pc_t *pc) | ||
2834 | { | ||
2835 | idetape_init_pc(pc); | ||
2836 | pc->c[0] = IDETAPE_TEST_UNIT_READY_CMD; | ||
2837 | pc->callback = &idetape_pc_callback; | ||
2838 | } | ||
2839 | |||
2840 | /* | ||
2841 | * idetape_queue_pc_tail is based on the following functions: | ||
2842 | * | ||
2843 | * ide_do_drive_cmd from ide.c | ||
2844 | * cdrom_queue_request and cdrom_queue_packet_command from ide-cd.c | ||
2845 | * | ||
2846 | * We add a special packet command request to the tail of the request | ||
2847 | * queue, and wait for it to be serviced. | ||
2848 | * | ||
2849 | * This is not to be called from within the request handling part | ||
2850 | * of the driver ! We allocate here data in the stack, and it is valid | ||
2851 | * until the request is finished. This is not the case for the bottom | ||
2852 | * part of the driver, where we are always leaving the functions to wait | ||
2853 | * for an interrupt or a timer event. | ||
2854 | * | ||
2855 | * From the bottom part of the driver, we should allocate safe memory | ||
2856 | * using idetape_next_pc_storage and idetape_next_rq_storage, and add | ||
2857 | * the request to the request list without waiting for it to be serviced ! | ||
2858 | * In that case, we usually use idetape_queue_pc_head. | ||
2859 | */ | ||
2860 | static int __idetape_queue_pc_tail (ide_drive_t *drive, idetape_pc_t *pc) | ||
2861 | { | ||
2862 | struct ide_tape_obj *tape = drive->driver_data; | ||
2863 | struct request rq; | ||
2864 | |||
2865 | idetape_init_rq(&rq, REQ_IDETAPE_PC1); | ||
2866 | rq.buffer = (char *) pc; | ||
2867 | rq.rq_disk = tape->disk; | ||
2868 | return ide_do_drive_cmd(drive, &rq, ide_wait); | ||
2869 | } | ||
2870 | |||
2871 | static void idetape_create_load_unload_cmd (ide_drive_t *drive, idetape_pc_t *pc,int cmd) | ||
2872 | { | ||
2873 | idetape_init_pc(pc); | ||
2874 | pc->c[0] = IDETAPE_LOAD_UNLOAD_CMD; | ||
2875 | pc->c[4] = cmd; | ||
2876 | set_bit(PC_WAIT_FOR_DSC, &pc->flags); | ||
2877 | pc->callback = &idetape_pc_callback; | ||
2878 | } | ||
2879 | |||
2880 | static int idetape_wait_ready(ide_drive_t *drive, unsigned long timeout) | ||
2881 | { | ||
2882 | idetape_tape_t *tape = drive->driver_data; | ||
2883 | idetape_pc_t pc; | ||
2884 | int load_attempted = 0; | ||
2885 | |||
2886 | /* | ||
2887 | * Wait for the tape to become ready | ||
2888 | */ | ||
2889 | set_bit(IDETAPE_MEDIUM_PRESENT, &tape->flags); | ||
2890 | timeout += jiffies; | ||
2891 | while (time_before(jiffies, timeout)) { | ||
2892 | idetape_create_test_unit_ready_cmd(&pc); | ||
2893 | if (!__idetape_queue_pc_tail(drive, &pc)) | ||
2894 | return 0; | ||
2895 | if ((tape->sense_key == 2 && tape->asc == 4 && tape->ascq == 2) | ||
2896 | || (tape->asc == 0x3A)) { /* no media */ | ||
2897 | if (load_attempted) | ||
2898 | return -ENOMEDIUM; | ||
2899 | idetape_create_load_unload_cmd(drive, &pc, IDETAPE_LU_LOAD_MASK); | ||
2900 | __idetape_queue_pc_tail(drive, &pc); | ||
2901 | load_attempted = 1; | ||
2902 | /* not about to be ready */ | ||
2903 | } else if (!(tape->sense_key == 2 && tape->asc == 4 && | ||
2904 | (tape->ascq == 1 || tape->ascq == 8))) | ||
2905 | return -EIO; | ||
2906 | current->state = TASK_INTERRUPTIBLE; | ||
2907 | schedule_timeout(HZ / 10); | ||
2908 | } | ||
2909 | return -EIO; | ||
2910 | } | ||
2911 | |||
2912 | static int idetape_queue_pc_tail (ide_drive_t *drive,idetape_pc_t *pc) | ||
2913 | { | ||
2914 | return __idetape_queue_pc_tail(drive, pc); | ||
2915 | } | ||
2916 | |||
2917 | static int idetape_flush_tape_buffers (ide_drive_t *drive) | ||
2918 | { | ||
2919 | idetape_pc_t pc; | ||
2920 | int rc; | ||
2921 | |||
2922 | idetape_create_write_filemark_cmd(drive, &pc, 0); | ||
2923 | if ((rc = idetape_queue_pc_tail(drive, &pc))) | ||
2924 | return rc; | ||
2925 | idetape_wait_ready(drive, 60 * 5 * HZ); | ||
2926 | return 0; | ||
2927 | } | ||
2928 | |||
2929 | static void idetape_create_read_position_cmd (idetape_pc_t *pc) | ||
2930 | { | ||
2931 | idetape_init_pc(pc); | ||
2932 | pc->c[0] = IDETAPE_READ_POSITION_CMD; | ||
2933 | pc->request_transfer = 20; | ||
2934 | pc->callback = &idetape_read_position_callback; | ||
2935 | } | ||
2936 | |||
2937 | static int idetape_read_position (ide_drive_t *drive) | ||
2938 | { | ||
2939 | idetape_tape_t *tape = drive->driver_data; | ||
2940 | idetape_pc_t pc; | ||
2941 | int position; | ||
2942 | |||
2943 | #if IDETAPE_DEBUG_LOG | ||
2944 | if (tape->debug_level >= 4) | ||
2945 | printk(KERN_INFO "ide-tape: Reached idetape_read_position\n"); | ||
2946 | #endif /* IDETAPE_DEBUG_LOG */ | ||
2947 | |||
2948 | idetape_create_read_position_cmd(&pc); | ||
2949 | if (idetape_queue_pc_tail(drive, &pc)) | ||
2950 | return -1; | ||
2951 | position = tape->first_frame_position; | ||
2952 | return position; | ||
2953 | } | ||
2954 | |||
2955 | static void idetape_create_locate_cmd (ide_drive_t *drive, idetape_pc_t *pc, unsigned int block, u8 partition, int skip) | ||
2956 | { | ||
2957 | idetape_init_pc(pc); | ||
2958 | pc->c[0] = IDETAPE_LOCATE_CMD; | ||
2959 | pc->c[1] = 2; | ||
2960 | put_unaligned(htonl(block), (unsigned int *) &pc->c[3]); | ||
2961 | pc->c[8] = partition; | ||
2962 | set_bit(PC_WAIT_FOR_DSC, &pc->flags); | ||
2963 | pc->callback = &idetape_pc_callback; | ||
2964 | } | ||
2965 | |||
2966 | static int idetape_create_prevent_cmd (ide_drive_t *drive, idetape_pc_t *pc, int prevent) | ||
2967 | { | ||
2968 | idetape_tape_t *tape = drive->driver_data; | ||
2969 | |||
2970 | if (!tape->capabilities.lock) | ||
2971 | return 0; | ||
2972 | |||
2973 | idetape_init_pc(pc); | ||
2974 | pc->c[0] = IDETAPE_PREVENT_CMD; | ||
2975 | pc->c[4] = prevent; | ||
2976 | pc->callback = &idetape_pc_callback; | ||
2977 | return 1; | ||
2978 | } | ||
2979 | |||
2980 | static int __idetape_discard_read_pipeline (ide_drive_t *drive) | ||
2981 | { | ||
2982 | idetape_tape_t *tape = drive->driver_data; | ||
2983 | unsigned long flags; | ||
2984 | int cnt; | ||
2985 | |||
2986 | if (tape->chrdev_direction != idetape_direction_read) | ||
2987 | return 0; | ||
2988 | |||
2989 | /* Remove merge stage. */ | ||
2990 | cnt = tape->merge_stage_size / tape->tape_block_size; | ||
2991 | if (test_and_clear_bit(IDETAPE_FILEMARK, &tape->flags)) | ||
2992 | ++cnt; /* Filemarks count as 1 sector */ | ||
2993 | tape->merge_stage_size = 0; | ||
2994 | if (tape->merge_stage != NULL) { | ||
2995 | __idetape_kfree_stage(tape->merge_stage); | ||
2996 | tape->merge_stage = NULL; | ||
2997 | } | ||
2998 | |||
2999 | /* Clear pipeline flags. */ | ||
3000 | clear_bit(IDETAPE_PIPELINE_ERROR, &tape->flags); | ||
3001 | tape->chrdev_direction = idetape_direction_none; | ||
3002 | |||
3003 | /* Remove pipeline stages. */ | ||
3004 | if (tape->first_stage == NULL) | ||
3005 | return 0; | ||
3006 | |||
3007 | spin_lock_irqsave(&tape->spinlock, flags); | ||
3008 | tape->next_stage = NULL; | ||
3009 | if (idetape_pipeline_active(tape)) | ||
3010 | idetape_wait_for_request(drive, tape->active_data_request); | ||
3011 | spin_unlock_irqrestore(&tape->spinlock, flags); | ||
3012 | |||
3013 | while (tape->first_stage != NULL) { | ||
3014 | struct request *rq_ptr = &tape->first_stage->rq; | ||
3015 | |||
3016 | cnt += rq_ptr->nr_sectors - rq_ptr->current_nr_sectors; | ||
3017 | if (rq_ptr->errors == IDETAPE_ERROR_FILEMARK) | ||
3018 | ++cnt; | ||
3019 | idetape_remove_stage_head(drive); | ||
3020 | } | ||
3021 | tape->nr_pending_stages = 0; | ||
3022 | tape->max_stages = tape->min_pipeline; | ||
3023 | return cnt; | ||
3024 | } | ||
3025 | |||
3026 | /* | ||
3027 | * idetape_position_tape positions the tape to the requested block | ||
3028 | * using the LOCATE packet command. A READ POSITION command is then | ||
3029 | * issued to check where we are positioned. | ||
3030 | * | ||
3031 | * Like all higher level operations, we queue the commands at the tail | ||
3032 | * of the request queue and wait for their completion. | ||
3033 | * | ||
3034 | */ | ||
3035 | static int idetape_position_tape (ide_drive_t *drive, unsigned int block, u8 partition, int skip) | ||
3036 | { | ||
3037 | idetape_tape_t *tape = drive->driver_data; | ||
3038 | int retval; | ||
3039 | idetape_pc_t pc; | ||
3040 | |||
3041 | if (tape->chrdev_direction == idetape_direction_read) | ||
3042 | __idetape_discard_read_pipeline(drive); | ||
3043 | idetape_wait_ready(drive, 60 * 5 * HZ); | ||
3044 | idetape_create_locate_cmd(drive, &pc, block, partition, skip); | ||
3045 | retval = idetape_queue_pc_tail(drive, &pc); | ||
3046 | if (retval) | ||
3047 | return (retval); | ||
3048 | |||
3049 | idetape_create_read_position_cmd(&pc); | ||
3050 | return (idetape_queue_pc_tail(drive, &pc)); | ||
3051 | } | ||
3052 | |||
3053 | static void idetape_discard_read_pipeline (ide_drive_t *drive, int restore_position) | ||
3054 | { | ||
3055 | idetape_tape_t *tape = drive->driver_data; | ||
3056 | int cnt; | ||
3057 | int seek, position; | ||
3058 | |||
3059 | cnt = __idetape_discard_read_pipeline(drive); | ||
3060 | if (restore_position) { | ||
3061 | position = idetape_read_position(drive); | ||
3062 | seek = position > cnt ? position - cnt : 0; | ||
3063 | if (idetape_position_tape(drive, seek, 0, 0)) { | ||
3064 | printk(KERN_INFO "ide-tape: %s: position_tape failed in discard_pipeline()\n", tape->name); | ||
3065 | return; | ||
3066 | } | ||
3067 | } | ||
3068 | } | ||
3069 | |||
3070 | /* | ||
3071 | * idetape_queue_rw_tail generates a read/write request for the block | ||
3072 | * device interface and wait for it to be serviced. | ||
3073 | */ | ||
3074 | static int idetape_queue_rw_tail(ide_drive_t *drive, int cmd, int blocks, struct idetape_bh *bh) | ||
3075 | { | ||
3076 | idetape_tape_t *tape = drive->driver_data; | ||
3077 | struct request rq; | ||
3078 | |||
3079 | #if IDETAPE_DEBUG_LOG | ||
3080 | if (tape->debug_level >= 2) | ||
3081 | printk(KERN_INFO "ide-tape: idetape_queue_rw_tail: cmd=%d\n",cmd); | ||
3082 | #endif /* IDETAPE_DEBUG_LOG */ | ||
3083 | #if IDETAPE_DEBUG_BUGS | ||
3084 | if (idetape_pipeline_active(tape)) { | ||
3085 | printk(KERN_ERR "ide-tape: bug: the pipeline is active in idetape_queue_rw_tail\n"); | ||
3086 | return (0); | ||
3087 | } | ||
3088 | #endif /* IDETAPE_DEBUG_BUGS */ | ||
3089 | |||
3090 | idetape_init_rq(&rq, cmd); | ||
3091 | rq.rq_disk = tape->disk; | ||
3092 | rq.special = (void *)bh; | ||
3093 | rq.sector = tape->first_frame_position; | ||
3094 | rq.nr_sectors = rq.current_nr_sectors = blocks; | ||
3095 | (void) ide_do_drive_cmd(drive, &rq, ide_wait); | ||
3096 | |||
3097 | if ((cmd & (REQ_IDETAPE_READ | REQ_IDETAPE_WRITE)) == 0) | ||
3098 | return 0; | ||
3099 | |||
3100 | if (tape->merge_stage) | ||
3101 | idetape_init_merge_stage(tape); | ||
3102 | if (rq.errors == IDETAPE_ERROR_GENERAL) | ||
3103 | return -EIO; | ||
3104 | return (tape->tape_block_size * (blocks-rq.current_nr_sectors)); | ||
3105 | } | ||
3106 | |||
3107 | /* | ||
3108 | * idetape_insert_pipeline_into_queue is used to start servicing the | ||
3109 | * pipeline stages, starting from tape->next_stage. | ||
3110 | */ | ||
3111 | static void idetape_insert_pipeline_into_queue (ide_drive_t *drive) | ||
3112 | { | ||
3113 | idetape_tape_t *tape = drive->driver_data; | ||
3114 | |||
3115 | if (tape->next_stage == NULL) | ||
3116 | return; | ||
3117 | if (!idetape_pipeline_active(tape)) { | ||
3118 | set_bit(IDETAPE_PIPELINE_ACTIVE, &tape->flags); | ||
3119 | idetape_active_next_stage(drive); | ||
3120 | (void) ide_do_drive_cmd(drive, tape->active_data_request, ide_end); | ||
3121 | } | ||
3122 | } | ||
3123 | |||
3124 | static void idetape_create_inquiry_cmd (idetape_pc_t *pc) | ||
3125 | { | ||
3126 | idetape_init_pc(pc); | ||
3127 | pc->c[0] = IDETAPE_INQUIRY_CMD; | ||
3128 | pc->c[4] = pc->request_transfer = 254; | ||
3129 | pc->callback = &idetape_pc_callback; | ||
3130 | } | ||
3131 | |||
3132 | static void idetape_create_rewind_cmd (ide_drive_t *drive, idetape_pc_t *pc) | ||
3133 | { | ||
3134 | idetape_init_pc(pc); | ||
3135 | pc->c[0] = IDETAPE_REWIND_CMD; | ||
3136 | set_bit(PC_WAIT_FOR_DSC, &pc->flags); | ||
3137 | pc->callback = &idetape_pc_callback; | ||
3138 | } | ||
3139 | |||
3140 | #if 0 | ||
3141 | static void idetape_create_mode_select_cmd (idetape_pc_t *pc, int length) | ||
3142 | { | ||
3143 | idetape_init_pc(pc); | ||
3144 | set_bit(PC_WRITING, &pc->flags); | ||
3145 | pc->c[0] = IDETAPE_MODE_SELECT_CMD; | ||
3146 | pc->c[1] = 0x10; | ||
3147 | put_unaligned(htons(length), (unsigned short *) &pc->c[3]); | ||
3148 | pc->request_transfer = 255; | ||
3149 | pc->callback = &idetape_pc_callback; | ||
3150 | } | ||
3151 | #endif | ||
3152 | |||
3153 | static void idetape_create_erase_cmd (idetape_pc_t *pc) | ||
3154 | { | ||
3155 | idetape_init_pc(pc); | ||
3156 | pc->c[0] = IDETAPE_ERASE_CMD; | ||
3157 | pc->c[1] = 1; | ||
3158 | set_bit(PC_WAIT_FOR_DSC, &pc->flags); | ||
3159 | pc->callback = &idetape_pc_callback; | ||
3160 | } | ||
3161 | |||
3162 | static void idetape_create_space_cmd (idetape_pc_t *pc,int count, u8 cmd) | ||
3163 | { | ||
3164 | idetape_init_pc(pc); | ||
3165 | pc->c[0] = IDETAPE_SPACE_CMD; | ||
3166 | put_unaligned(htonl(count), (unsigned int *) &pc->c[1]); | ||
3167 | pc->c[1] = cmd; | ||
3168 | set_bit(PC_WAIT_FOR_DSC, &pc->flags); | ||
3169 | pc->callback = &idetape_pc_callback; | ||
3170 | } | ||
3171 | |||
3172 | static void idetape_wait_first_stage (ide_drive_t *drive) | ||
3173 | { | ||
3174 | idetape_tape_t *tape = drive->driver_data; | ||
3175 | unsigned long flags; | ||
3176 | |||
3177 | if (tape->first_stage == NULL) | ||
3178 | return; | ||
3179 | spin_lock_irqsave(&tape->spinlock, flags); | ||
3180 | if (tape->active_stage == tape->first_stage) | ||
3181 | idetape_wait_for_request(drive, tape->active_data_request); | ||
3182 | spin_unlock_irqrestore(&tape->spinlock, flags); | ||
3183 | } | ||
3184 | |||
3185 | /* | ||
3186 | * idetape_add_chrdev_write_request tries to add a character device | ||
3187 | * originated write request to our pipeline. In case we don't succeed, | ||
3188 | * we revert to non-pipelined operation mode for this request. | ||
3189 | * | ||
3190 | * 1. Try to allocate a new pipeline stage. | ||
3191 | * 2. If we can't, wait for more and more requests to be serviced | ||
3192 | * and try again each time. | ||
3193 | * 3. If we still can't allocate a stage, fallback to | ||
3194 | * non-pipelined operation mode for this request. | ||
3195 | */ | ||
3196 | static int idetape_add_chrdev_write_request (ide_drive_t *drive, int blocks) | ||
3197 | { | ||
3198 | idetape_tape_t *tape = drive->driver_data; | ||
3199 | idetape_stage_t *new_stage; | ||
3200 | unsigned long flags; | ||
3201 | struct request *rq; | ||
3202 | |||
3203 | #if IDETAPE_DEBUG_LOG | ||
3204 | if (tape->debug_level >= 3) | ||
3205 | printk(KERN_INFO "ide-tape: Reached idetape_add_chrdev_write_request\n"); | ||
3206 | #endif /* IDETAPE_DEBUG_LOG */ | ||
3207 | |||
3208 | /* | ||
3209 | * Attempt to allocate a new stage. | ||
3210 | * Pay special attention to possible race conditions. | ||
3211 | */ | ||
3212 | while ((new_stage = idetape_kmalloc_stage(tape)) == NULL) { | ||
3213 | spin_lock_irqsave(&tape->spinlock, flags); | ||
3214 | if (idetape_pipeline_active(tape)) { | ||
3215 | idetape_wait_for_request(drive, tape->active_data_request); | ||
3216 | spin_unlock_irqrestore(&tape->spinlock, flags); | ||
3217 | } else { | ||
3218 | spin_unlock_irqrestore(&tape->spinlock, flags); | ||
3219 | idetape_insert_pipeline_into_queue(drive); | ||
3220 | if (idetape_pipeline_active(tape)) | ||
3221 | continue; | ||
3222 | /* | ||
3223 | * Linux is short on memory. Fallback to | ||
3224 | * non-pipelined operation mode for this request. | ||
3225 | */ | ||
3226 | return idetape_queue_rw_tail(drive, REQ_IDETAPE_WRITE, blocks, tape->merge_stage->bh); | ||
3227 | } | ||
3228 | } | ||
3229 | rq = &new_stage->rq; | ||
3230 | idetape_init_rq(rq, REQ_IDETAPE_WRITE); | ||
3231 | /* Doesn't actually matter - We always assume sequential access */ | ||
3232 | rq->sector = tape->first_frame_position; | ||
3233 | rq->nr_sectors = rq->current_nr_sectors = blocks; | ||
3234 | |||
3235 | idetape_switch_buffers(tape, new_stage); | ||
3236 | idetape_add_stage_tail(drive, new_stage); | ||
3237 | tape->pipeline_head++; | ||
3238 | #if USE_IOTRACE | ||
3239 | IO_trace(IO_IDETAPE_FIFO, tape->pipeline_head, tape->buffer_head, tape->tape_head, tape->minor); | ||
3240 | #endif | ||
3241 | calculate_speeds(drive); | ||
3242 | |||
3243 | /* | ||
3244 | * Estimate whether the tape has stopped writing by checking | ||
3245 | * if our write pipeline is currently empty. If we are not | ||
3246 | * writing anymore, wait for the pipeline to be full enough | ||
3247 | * (90%) before starting to service requests, so that we will | ||
3248 | * be able to keep up with the higher speeds of the tape. | ||
3249 | */ | ||
3250 | if (!idetape_pipeline_active(tape)) { | ||
3251 | if (tape->nr_stages >= tape->max_stages * 9 / 10 || | ||
3252 | tape->nr_stages >= tape->max_stages - tape->uncontrolled_pipeline_head_speed * 3 * 1024 / tape->tape_block_size) { | ||
3253 | tape->measure_insert_time = 1; | ||
3254 | tape->insert_time = jiffies; | ||
3255 | tape->insert_size = 0; | ||
3256 | tape->insert_speed = 0; | ||
3257 | idetape_insert_pipeline_into_queue(drive); | ||
3258 | } | ||
3259 | } | ||
3260 | if (test_and_clear_bit(IDETAPE_PIPELINE_ERROR, &tape->flags)) | ||
3261 | /* Return a deferred error */ | ||
3262 | return -EIO; | ||
3263 | return blocks; | ||
3264 | } | ||
3265 | |||
3266 | /* | ||
3267 | * idetape_wait_for_pipeline will wait until all pending pipeline | ||
3268 | * requests are serviced. Typically called on device close. | ||
3269 | */ | ||
3270 | static void idetape_wait_for_pipeline (ide_drive_t *drive) | ||
3271 | { | ||
3272 | idetape_tape_t *tape = drive->driver_data; | ||
3273 | unsigned long flags; | ||
3274 | |||
3275 | while (tape->next_stage || idetape_pipeline_active(tape)) { | ||
3276 | idetape_insert_pipeline_into_queue(drive); | ||
3277 | spin_lock_irqsave(&tape->spinlock, flags); | ||
3278 | if (idetape_pipeline_active(tape)) | ||
3279 | idetape_wait_for_request(drive, tape->active_data_request); | ||
3280 | spin_unlock_irqrestore(&tape->spinlock, flags); | ||
3281 | } | ||
3282 | } | ||
3283 | |||
3284 | static void idetape_empty_write_pipeline (ide_drive_t *drive) | ||
3285 | { | ||
3286 | idetape_tape_t *tape = drive->driver_data; | ||
3287 | int blocks, min; | ||
3288 | struct idetape_bh *bh; | ||
3289 | |||
3290 | #if IDETAPE_DEBUG_BUGS | ||
3291 | if (tape->chrdev_direction != idetape_direction_write) { | ||
3292 | printk(KERN_ERR "ide-tape: bug: Trying to empty write pipeline, but we are not writing.\n"); | ||
3293 | return; | ||
3294 | } | ||
3295 | if (tape->merge_stage_size > tape->stage_size) { | ||
3296 | printk(KERN_ERR "ide-tape: bug: merge_buffer too big\n"); | ||
3297 | tape->merge_stage_size = tape->stage_size; | ||
3298 | } | ||
3299 | #endif /* IDETAPE_DEBUG_BUGS */ | ||
3300 | if (tape->merge_stage_size) { | ||
3301 | blocks = tape->merge_stage_size / tape->tape_block_size; | ||
3302 | if (tape->merge_stage_size % tape->tape_block_size) { | ||
3303 | unsigned int i; | ||
3304 | |||
3305 | blocks++; | ||
3306 | i = tape->tape_block_size - tape->merge_stage_size % tape->tape_block_size; | ||
3307 | bh = tape->bh->b_reqnext; | ||
3308 | while (bh) { | ||
3309 | atomic_set(&bh->b_count, 0); | ||
3310 | bh = bh->b_reqnext; | ||
3311 | } | ||
3312 | bh = tape->bh; | ||
3313 | while (i) { | ||
3314 | if (bh == NULL) { | ||
3315 | |||
3316 | printk(KERN_INFO "ide-tape: bug, bh NULL\n"); | ||
3317 | break; | ||
3318 | } | ||
3319 | min = min(i, (unsigned int)(bh->b_size - atomic_read(&bh->b_count))); | ||
3320 | memset(bh->b_data + atomic_read(&bh->b_count), 0, min); | ||
3321 | atomic_add(min, &bh->b_count); | ||
3322 | i -= min; | ||
3323 | bh = bh->b_reqnext; | ||
3324 | } | ||
3325 | } | ||
3326 | (void) idetape_add_chrdev_write_request(drive, blocks); | ||
3327 | tape->merge_stage_size = 0; | ||
3328 | } | ||
3329 | idetape_wait_for_pipeline(drive); | ||
3330 | if (tape->merge_stage != NULL) { | ||
3331 | __idetape_kfree_stage(tape->merge_stage); | ||
3332 | tape->merge_stage = NULL; | ||
3333 | } | ||
3334 | clear_bit(IDETAPE_PIPELINE_ERROR, &tape->flags); | ||
3335 | tape->chrdev_direction = idetape_direction_none; | ||
3336 | |||
3337 | /* | ||
3338 | * On the next backup, perform the feedback loop again. | ||
3339 | * (I don't want to keep sense information between backups, | ||
3340 | * as some systems are constantly on, and the system load | ||
3341 | * can be totally different on the next backup). | ||
3342 | */ | ||
3343 | tape->max_stages = tape->min_pipeline; | ||
3344 | #if IDETAPE_DEBUG_BUGS | ||
3345 | if (tape->first_stage != NULL || | ||
3346 | tape->next_stage != NULL || | ||
3347 | tape->last_stage != NULL || | ||
3348 | tape->nr_stages != 0) { | ||
3349 | printk(KERN_ERR "ide-tape: ide-tape pipeline bug, " | ||
3350 | "first_stage %p, next_stage %p, " | ||
3351 | "last_stage %p, nr_stages %d\n", | ||
3352 | tape->first_stage, tape->next_stage, | ||
3353 | tape->last_stage, tape->nr_stages); | ||
3354 | } | ||
3355 | #endif /* IDETAPE_DEBUG_BUGS */ | ||
3356 | } | ||
3357 | |||
3358 | static void idetape_restart_speed_control (ide_drive_t *drive) | ||
3359 | { | ||
3360 | idetape_tape_t *tape = drive->driver_data; | ||
3361 | |||
3362 | tape->restart_speed_control_req = 0; | ||
3363 | tape->pipeline_head = 0; | ||
3364 | tape->controlled_last_pipeline_head = tape->uncontrolled_last_pipeline_head = 0; | ||
3365 | tape->controlled_previous_pipeline_head = tape->uncontrolled_previous_pipeline_head = 0; | ||
3366 | tape->pipeline_head_speed = tape->controlled_pipeline_head_speed = 5000; | ||
3367 | tape->uncontrolled_pipeline_head_speed = 0; | ||
3368 | tape->controlled_pipeline_head_time = tape->uncontrolled_pipeline_head_time = jiffies; | ||
3369 | tape->controlled_previous_head_time = tape->uncontrolled_previous_head_time = jiffies; | ||
3370 | } | ||
3371 | |||
3372 | static int idetape_initiate_read (ide_drive_t *drive, int max_stages) | ||
3373 | { | ||
3374 | idetape_tape_t *tape = drive->driver_data; | ||
3375 | idetape_stage_t *new_stage; | ||
3376 | struct request rq; | ||
3377 | int bytes_read; | ||
3378 | int blocks = tape->capabilities.ctl; | ||
3379 | |||
3380 | /* Initialize read operation */ | ||
3381 | if (tape->chrdev_direction != idetape_direction_read) { | ||
3382 | if (tape->chrdev_direction == idetape_direction_write) { | ||
3383 | idetape_empty_write_pipeline(drive); | ||
3384 | idetape_flush_tape_buffers(drive); | ||
3385 | } | ||
3386 | #if IDETAPE_DEBUG_BUGS | ||
3387 | if (tape->merge_stage || tape->merge_stage_size) { | ||
3388 | printk (KERN_ERR "ide-tape: merge_stage_size should be 0 now\n"); | ||
3389 | tape->merge_stage_size = 0; | ||
3390 | } | ||
3391 | #endif /* IDETAPE_DEBUG_BUGS */ | ||
3392 | if ((tape->merge_stage = __idetape_kmalloc_stage(tape, 0, 0)) == NULL) | ||
3393 | return -ENOMEM; | ||
3394 | tape->chrdev_direction = idetape_direction_read; | ||
3395 | |||
3396 | /* | ||
3397 | * Issue a read 0 command to ensure that DSC handshake | ||
3398 | * is switched from completion mode to buffer available | ||
3399 | * mode. | ||
3400 | * No point in issuing this if DSC overlap isn't supported, | ||
3401 | * some drives (Seagate STT3401A) will return an error. | ||
3402 | */ | ||
3403 | if (drive->dsc_overlap) { | ||
3404 | bytes_read = idetape_queue_rw_tail(drive, REQ_IDETAPE_READ, 0, tape->merge_stage->bh); | ||
3405 | if (bytes_read < 0) { | ||
3406 | __idetape_kfree_stage(tape->merge_stage); | ||
3407 | tape->merge_stage = NULL; | ||
3408 | tape->chrdev_direction = idetape_direction_none; | ||
3409 | return bytes_read; | ||
3410 | } | ||
3411 | } | ||
3412 | } | ||
3413 | if (tape->restart_speed_control_req) | ||
3414 | idetape_restart_speed_control(drive); | ||
3415 | idetape_init_rq(&rq, REQ_IDETAPE_READ); | ||
3416 | rq.sector = tape->first_frame_position; | ||
3417 | rq.nr_sectors = rq.current_nr_sectors = blocks; | ||
3418 | if (!test_bit(IDETAPE_PIPELINE_ERROR, &tape->flags) && | ||
3419 | tape->nr_stages < max_stages) { | ||
3420 | new_stage = idetape_kmalloc_stage(tape); | ||
3421 | while (new_stage != NULL) { | ||
3422 | new_stage->rq = rq; | ||
3423 | idetape_add_stage_tail(drive, new_stage); | ||
3424 | if (tape->nr_stages >= max_stages) | ||
3425 | break; | ||
3426 | new_stage = idetape_kmalloc_stage(tape); | ||
3427 | } | ||
3428 | } | ||
3429 | if (!idetape_pipeline_active(tape)) { | ||
3430 | if (tape->nr_pending_stages >= 3 * max_stages / 4) { | ||
3431 | tape->measure_insert_time = 1; | ||
3432 | tape->insert_time = jiffies; | ||
3433 | tape->insert_size = 0; | ||
3434 | tape->insert_speed = 0; | ||
3435 | idetape_insert_pipeline_into_queue(drive); | ||
3436 | } | ||
3437 | } | ||
3438 | return 0; | ||
3439 | } | ||
3440 | |||
3441 | /* | ||
3442 | * idetape_add_chrdev_read_request is called from idetape_chrdev_read | ||
3443 | * to service a character device read request and add read-ahead | ||
3444 | * requests to our pipeline. | ||
3445 | */ | ||
3446 | static int idetape_add_chrdev_read_request (ide_drive_t *drive,int blocks) | ||
3447 | { | ||
3448 | idetape_tape_t *tape = drive->driver_data; | ||
3449 | unsigned long flags; | ||
3450 | struct request *rq_ptr; | ||
3451 | int bytes_read; | ||
3452 | |||
3453 | #if IDETAPE_DEBUG_LOG | ||
3454 | if (tape->debug_level >= 4) | ||
3455 | printk(KERN_INFO "ide-tape: Reached idetape_add_chrdev_read_request, %d blocks\n", blocks); | ||
3456 | #endif /* IDETAPE_DEBUG_LOG */ | ||
3457 | |||
3458 | /* | ||
3459 | * If we are at a filemark, return a read length of 0 | ||
3460 | */ | ||
3461 | if (test_bit(IDETAPE_FILEMARK, &tape->flags)) | ||
3462 | return 0; | ||
3463 | |||
3464 | /* | ||
3465 | * Wait for the next block to be available at the head | ||
3466 | * of the pipeline | ||
3467 | */ | ||
3468 | idetape_initiate_read(drive, tape->max_stages); | ||
3469 | if (tape->first_stage == NULL) { | ||
3470 | if (test_bit(IDETAPE_PIPELINE_ERROR, &tape->flags)) | ||
3471 | return 0; | ||
3472 | return idetape_queue_rw_tail(drive, REQ_IDETAPE_READ, blocks, tape->merge_stage->bh); | ||
3473 | } | ||
3474 | idetape_wait_first_stage(drive); | ||
3475 | rq_ptr = &tape->first_stage->rq; | ||
3476 | bytes_read = tape->tape_block_size * (rq_ptr->nr_sectors - rq_ptr->current_nr_sectors); | ||
3477 | rq_ptr->nr_sectors = rq_ptr->current_nr_sectors = 0; | ||
3478 | |||
3479 | |||
3480 | if (rq_ptr->errors == IDETAPE_ERROR_EOD) | ||
3481 | return 0; | ||
3482 | else { | ||
3483 | idetape_switch_buffers(tape, tape->first_stage); | ||
3484 | if (rq_ptr->errors == IDETAPE_ERROR_FILEMARK) | ||
3485 | set_bit(IDETAPE_FILEMARK, &tape->flags); | ||
3486 | spin_lock_irqsave(&tape->spinlock, flags); | ||
3487 | idetape_remove_stage_head(drive); | ||
3488 | spin_unlock_irqrestore(&tape->spinlock, flags); | ||
3489 | tape->pipeline_head++; | ||
3490 | #if USE_IOTRACE | ||
3491 | IO_trace(IO_IDETAPE_FIFO, tape->pipeline_head, tape->buffer_head, tape->tape_head, tape->minor); | ||
3492 | #endif | ||
3493 | calculate_speeds(drive); | ||
3494 | } | ||
3495 | #if IDETAPE_DEBUG_BUGS | ||
3496 | if (bytes_read > blocks * tape->tape_block_size) { | ||
3497 | printk(KERN_ERR "ide-tape: bug: trying to return more bytes than requested\n"); | ||
3498 | bytes_read = blocks * tape->tape_block_size; | ||
3499 | } | ||
3500 | #endif /* IDETAPE_DEBUG_BUGS */ | ||
3501 | return (bytes_read); | ||
3502 | } | ||
3503 | |||
3504 | static void idetape_pad_zeros (ide_drive_t *drive, int bcount) | ||
3505 | { | ||
3506 | idetape_tape_t *tape = drive->driver_data; | ||
3507 | struct idetape_bh *bh; | ||
3508 | int blocks; | ||
3509 | |||
3510 | while (bcount) { | ||
3511 | unsigned int count; | ||
3512 | |||
3513 | bh = tape->merge_stage->bh; | ||
3514 | count = min(tape->stage_size, bcount); | ||
3515 | bcount -= count; | ||
3516 | blocks = count / tape->tape_block_size; | ||
3517 | while (count) { | ||
3518 | atomic_set(&bh->b_count, min(count, (unsigned int)bh->b_size)); | ||
3519 | memset(bh->b_data, 0, atomic_read(&bh->b_count)); | ||
3520 | count -= atomic_read(&bh->b_count); | ||
3521 | bh = bh->b_reqnext; | ||
3522 | } | ||
3523 | idetape_queue_rw_tail(drive, REQ_IDETAPE_WRITE, blocks, tape->merge_stage->bh); | ||
3524 | } | ||
3525 | } | ||
3526 | |||
3527 | static int idetape_pipeline_size (ide_drive_t *drive) | ||
3528 | { | ||
3529 | idetape_tape_t *tape = drive->driver_data; | ||
3530 | idetape_stage_t *stage; | ||
3531 | struct request *rq; | ||
3532 | int size = 0; | ||
3533 | |||
3534 | idetape_wait_for_pipeline(drive); | ||
3535 | stage = tape->first_stage; | ||
3536 | while (stage != NULL) { | ||
3537 | rq = &stage->rq; | ||
3538 | size += tape->tape_block_size * (rq->nr_sectors-rq->current_nr_sectors); | ||
3539 | if (rq->errors == IDETAPE_ERROR_FILEMARK) | ||
3540 | size += tape->tape_block_size; | ||
3541 | stage = stage->next; | ||
3542 | } | ||
3543 | size += tape->merge_stage_size; | ||
3544 | return size; | ||
3545 | } | ||
3546 | |||
3547 | /* | ||
3548 | * Rewinds the tape to the Beginning Of the current Partition (BOP). | ||
3549 | * | ||
3550 | * We currently support only one partition. | ||
3551 | */ | ||
3552 | static int idetape_rewind_tape (ide_drive_t *drive) | ||
3553 | { | ||
3554 | int retval; | ||
3555 | idetape_pc_t pc; | ||
3556 | #if IDETAPE_DEBUG_LOG | ||
3557 | idetape_tape_t *tape = drive->driver_data; | ||
3558 | if (tape->debug_level >= 2) | ||
3559 | printk(KERN_INFO "ide-tape: Reached idetape_rewind_tape\n"); | ||
3560 | #endif /* IDETAPE_DEBUG_LOG */ | ||
3561 | |||
3562 | idetape_create_rewind_cmd(drive, &pc); | ||
3563 | retval = idetape_queue_pc_tail(drive, &pc); | ||
3564 | if (retval) | ||
3565 | return retval; | ||
3566 | |||
3567 | idetape_create_read_position_cmd(&pc); | ||
3568 | retval = idetape_queue_pc_tail(drive, &pc); | ||
3569 | if (retval) | ||
3570 | return retval; | ||
3571 | return 0; | ||
3572 | } | ||
3573 | |||
3574 | /* | ||
3575 | * Our special ide-tape ioctl's. | ||
3576 | * | ||
3577 | * Currently there aren't any ioctl's. | ||
3578 | * mtio.h compatible commands should be issued to the character device | ||
3579 | * interface. | ||
3580 | */ | ||
3581 | static int idetape_blkdev_ioctl(ide_drive_t *drive, unsigned int cmd, unsigned long arg) | ||
3582 | { | ||
3583 | idetape_tape_t *tape = drive->driver_data; | ||
3584 | idetape_config_t config; | ||
3585 | void __user *argp = (void __user *)arg; | ||
3586 | |||
3587 | #if IDETAPE_DEBUG_LOG | ||
3588 | if (tape->debug_level >= 4) | ||
3589 | printk(KERN_INFO "ide-tape: Reached idetape_blkdev_ioctl\n"); | ||
3590 | #endif /* IDETAPE_DEBUG_LOG */ | ||
3591 | switch (cmd) { | ||
3592 | case 0x0340: | ||
3593 | if (copy_from_user(&config, argp, sizeof (idetape_config_t))) | ||
3594 | return -EFAULT; | ||
3595 | tape->best_dsc_rw_frequency = config.dsc_rw_frequency; | ||
3596 | tape->max_stages = config.nr_stages; | ||
3597 | break; | ||
3598 | case 0x0350: | ||
3599 | config.dsc_rw_frequency = (int) tape->best_dsc_rw_frequency; | ||
3600 | config.nr_stages = tape->max_stages; | ||
3601 | if (copy_to_user(argp, &config, sizeof (idetape_config_t))) | ||
3602 | return -EFAULT; | ||
3603 | break; | ||
3604 | default: | ||
3605 | return -EIO; | ||
3606 | } | ||
3607 | return 0; | ||
3608 | } | ||
3609 | |||
3610 | /* | ||
3611 | * idetape_space_over_filemarks is now a bit more complicated than just | ||
3612 | * passing the command to the tape since we may have crossed some | ||
3613 | * filemarks during our pipelined read-ahead mode. | ||
3614 | * | ||
3615 | * As a minor side effect, the pipeline enables us to support MTFSFM when | ||
3616 | * the filemark is in our internal pipeline even if the tape doesn't | ||
3617 | * support spacing over filemarks in the reverse direction. | ||
3618 | */ | ||
3619 | static int idetape_space_over_filemarks (ide_drive_t *drive,short mt_op,int mt_count) | ||
3620 | { | ||
3621 | idetape_tape_t *tape = drive->driver_data; | ||
3622 | idetape_pc_t pc; | ||
3623 | unsigned long flags; | ||
3624 | int retval,count=0; | ||
3625 | |||
3626 | if (mt_count == 0) | ||
3627 | return 0; | ||
3628 | if (MTBSF == mt_op || MTBSFM == mt_op) { | ||
3629 | if (!tape->capabilities.sprev) | ||
3630 | return -EIO; | ||
3631 | mt_count = - mt_count; | ||
3632 | } | ||
3633 | |||
3634 | if (tape->chrdev_direction == idetape_direction_read) { | ||
3635 | /* | ||
3636 | * We have a read-ahead buffer. Scan it for crossed | ||
3637 | * filemarks. | ||
3638 | */ | ||
3639 | tape->merge_stage_size = 0; | ||
3640 | if (test_and_clear_bit(IDETAPE_FILEMARK, &tape->flags)) | ||
3641 | ++count; | ||
3642 | while (tape->first_stage != NULL) { | ||
3643 | if (count == mt_count) { | ||
3644 | if (mt_op == MTFSFM) | ||
3645 | set_bit(IDETAPE_FILEMARK, &tape->flags); | ||
3646 | return 0; | ||
3647 | } | ||
3648 | spin_lock_irqsave(&tape->spinlock, flags); | ||
3649 | if (tape->first_stage == tape->active_stage) { | ||
3650 | /* | ||
3651 | * We have reached the active stage in the read pipeline. | ||
3652 | * There is no point in allowing the drive to continue | ||
3653 | * reading any farther, so we stop the pipeline. | ||
3654 | * | ||
3655 | * This section should be moved to a separate subroutine, | ||
3656 | * because a similar function is performed in | ||
3657 | * __idetape_discard_read_pipeline(), for example. | ||
3658 | */ | ||
3659 | tape->next_stage = NULL; | ||
3660 | spin_unlock_irqrestore(&tape->spinlock, flags); | ||
3661 | idetape_wait_first_stage(drive); | ||
3662 | tape->next_stage = tape->first_stage->next; | ||
3663 | } else | ||
3664 | spin_unlock_irqrestore(&tape->spinlock, flags); | ||
3665 | if (tape->first_stage->rq.errors == IDETAPE_ERROR_FILEMARK) | ||
3666 | ++count; | ||
3667 | idetape_remove_stage_head(drive); | ||
3668 | } | ||
3669 | idetape_discard_read_pipeline(drive, 0); | ||
3670 | } | ||
3671 | |||
3672 | /* | ||
3673 | * The filemark was not found in our internal pipeline. | ||
3674 | * Now we can issue the space command. | ||
3675 | */ | ||
3676 | switch (mt_op) { | ||
3677 | case MTFSF: | ||
3678 | case MTBSF: | ||
3679 | idetape_create_space_cmd(&pc,mt_count-count,IDETAPE_SPACE_OVER_FILEMARK); | ||
3680 | return (idetape_queue_pc_tail(drive, &pc)); | ||
3681 | case MTFSFM: | ||
3682 | case MTBSFM: | ||
3683 | if (!tape->capabilities.sprev) | ||
3684 | return (-EIO); | ||
3685 | retval = idetape_space_over_filemarks(drive, MTFSF, mt_count-count); | ||
3686 | if (retval) return (retval); | ||
3687 | count = (MTBSFM == mt_op ? 1 : -1); | ||
3688 | return (idetape_space_over_filemarks(drive, MTFSF, count)); | ||
3689 | default: | ||
3690 | printk(KERN_ERR "ide-tape: MTIO operation %d not supported\n",mt_op); | ||
3691 | return (-EIO); | ||
3692 | } | ||
3693 | } | ||
3694 | |||
3695 | |||
3696 | /* | ||
3697 | * Our character device read / write functions. | ||
3698 | * | ||
3699 | * The tape is optimized to maximize throughput when it is transferring | ||
3700 | * an integral number of the "continuous transfer limit", which is | ||
3701 | * a parameter of the specific tape (26 KB on my particular tape). | ||
3702 | * (32 kB for Onstream) | ||
3703 | * | ||
3704 | * As of version 1.3 of the driver, the character device provides an | ||
3705 | * abstract continuous view of the media - any mix of block sizes (even 1 | ||
3706 | * byte) on the same backup/restore procedure is supported. The driver | ||
3707 | * will internally convert the requests to the recommended transfer unit, | ||
3708 | * so that an unmatch between the user's block size to the recommended | ||
3709 | * size will only result in a (slightly) increased driver overhead, but | ||
3710 | * will no longer hit performance. | ||
3711 | * This is not applicable to Onstream. | ||
3712 | */ | ||
3713 | static ssize_t idetape_chrdev_read (struct file *file, char __user *buf, | ||
3714 | size_t count, loff_t *ppos) | ||
3715 | { | ||
3716 | struct ide_tape_obj *tape = ide_tape_f(file); | ||
3717 | ide_drive_t *drive = tape->drive; | ||
3718 | ssize_t bytes_read,temp, actually_read = 0, rc; | ||
3719 | |||
3720 | #if IDETAPE_DEBUG_LOG | ||
3721 | if (tape->debug_level >= 3) | ||
3722 | printk(KERN_INFO "ide-tape: Reached idetape_chrdev_read, count %Zd\n", count); | ||
3723 | #endif /* IDETAPE_DEBUG_LOG */ | ||
3724 | |||
3725 | if (tape->chrdev_direction != idetape_direction_read) { | ||
3726 | if (test_bit(IDETAPE_DETECT_BS, &tape->flags)) | ||
3727 | if (count > tape->tape_block_size && | ||
3728 | (count % tape->tape_block_size) == 0) | ||
3729 | tape->user_bs_factor = count / tape->tape_block_size; | ||
3730 | } | ||
3731 | if ((rc = idetape_initiate_read(drive, tape->max_stages)) < 0) | ||
3732 | return rc; | ||
3733 | if (count == 0) | ||
3734 | return (0); | ||
3735 | if (tape->merge_stage_size) { | ||
3736 | actually_read = min((unsigned int)(tape->merge_stage_size), (unsigned int)count); | ||
3737 | idetape_copy_stage_to_user(tape, buf, tape->merge_stage, actually_read); | ||
3738 | buf += actually_read; | ||
3739 | tape->merge_stage_size -= actually_read; | ||
3740 | count -= actually_read; | ||
3741 | } | ||
3742 | while (count >= tape->stage_size) { | ||
3743 | bytes_read = idetape_add_chrdev_read_request(drive, tape->capabilities.ctl); | ||
3744 | if (bytes_read <= 0) | ||
3745 | goto finish; | ||
3746 | idetape_copy_stage_to_user(tape, buf, tape->merge_stage, bytes_read); | ||
3747 | buf += bytes_read; | ||
3748 | count -= bytes_read; | ||
3749 | actually_read += bytes_read; | ||
3750 | } | ||
3751 | if (count) { | ||
3752 | bytes_read = idetape_add_chrdev_read_request(drive, tape->capabilities.ctl); | ||
3753 | if (bytes_read <= 0) | ||
3754 | goto finish; | ||
3755 | temp = min((unsigned long)count, (unsigned long)bytes_read); | ||
3756 | idetape_copy_stage_to_user(tape, buf, tape->merge_stage, temp); | ||
3757 | actually_read += temp; | ||
3758 | tape->merge_stage_size = bytes_read-temp; | ||
3759 | } | ||
3760 | finish: | ||
3761 | if (!actually_read && test_bit(IDETAPE_FILEMARK, &tape->flags)) { | ||
3762 | #if IDETAPE_DEBUG_LOG | ||
3763 | if (tape->debug_level >= 2) | ||
3764 | printk(KERN_INFO "ide-tape: %s: spacing over filemark\n", tape->name); | ||
3765 | #endif | ||
3766 | idetape_space_over_filemarks(drive, MTFSF, 1); | ||
3767 | return 0; | ||
3768 | } | ||
3769 | return actually_read; | ||
3770 | } | ||
3771 | |||
3772 | static ssize_t idetape_chrdev_write (struct file *file, const char __user *buf, | ||
3773 | size_t count, loff_t *ppos) | ||
3774 | { | ||
3775 | struct ide_tape_obj *tape = ide_tape_f(file); | ||
3776 | ide_drive_t *drive = tape->drive; | ||
3777 | ssize_t retval, actually_written = 0; | ||
3778 | |||
3779 | /* The drive is write protected. */ | ||
3780 | if (tape->write_prot) | ||
3781 | return -EACCES; | ||
3782 | |||
3783 | #if IDETAPE_DEBUG_LOG | ||
3784 | if (tape->debug_level >= 3) | ||
3785 | printk(KERN_INFO "ide-tape: Reached idetape_chrdev_write, " | ||
3786 | "count %Zd\n", count); | ||
3787 | #endif /* IDETAPE_DEBUG_LOG */ | ||
3788 | |||
3789 | /* Initialize write operation */ | ||
3790 | if (tape->chrdev_direction != idetape_direction_write) { | ||
3791 | if (tape->chrdev_direction == idetape_direction_read) | ||
3792 | idetape_discard_read_pipeline(drive, 1); | ||
3793 | #if IDETAPE_DEBUG_BUGS | ||
3794 | if (tape->merge_stage || tape->merge_stage_size) { | ||
3795 | printk(KERN_ERR "ide-tape: merge_stage_size " | ||
3796 | "should be 0 now\n"); | ||
3797 | tape->merge_stage_size = 0; | ||
3798 | } | ||
3799 | #endif /* IDETAPE_DEBUG_BUGS */ | ||
3800 | if ((tape->merge_stage = __idetape_kmalloc_stage(tape, 0, 0)) == NULL) | ||
3801 | return -ENOMEM; | ||
3802 | tape->chrdev_direction = idetape_direction_write; | ||
3803 | idetape_init_merge_stage(tape); | ||
3804 | |||
3805 | /* | ||
3806 | * Issue a write 0 command to ensure that DSC handshake | ||
3807 | * is switched from completion mode to buffer available | ||
3808 | * mode. | ||
3809 | * No point in issuing this if DSC overlap isn't supported, | ||
3810 | * some drives (Seagate STT3401A) will return an error. | ||
3811 | */ | ||
3812 | if (drive->dsc_overlap) { | ||
3813 | retval = idetape_queue_rw_tail(drive, REQ_IDETAPE_WRITE, 0, tape->merge_stage->bh); | ||
3814 | if (retval < 0) { | ||
3815 | __idetape_kfree_stage(tape->merge_stage); | ||
3816 | tape->merge_stage = NULL; | ||
3817 | tape->chrdev_direction = idetape_direction_none; | ||
3818 | return retval; | ||
3819 | } | ||
3820 | } | ||
3821 | } | ||
3822 | if (count == 0) | ||
3823 | return (0); | ||
3824 | if (tape->restart_speed_control_req) | ||
3825 | idetape_restart_speed_control(drive); | ||
3826 | if (tape->merge_stage_size) { | ||
3827 | #if IDETAPE_DEBUG_BUGS | ||
3828 | if (tape->merge_stage_size >= tape->stage_size) { | ||
3829 | printk(KERN_ERR "ide-tape: bug: merge buffer too big\n"); | ||
3830 | tape->merge_stage_size = 0; | ||
3831 | } | ||
3832 | #endif /* IDETAPE_DEBUG_BUGS */ | ||
3833 | actually_written = min((unsigned int)(tape->stage_size - tape->merge_stage_size), (unsigned int)count); | ||
3834 | idetape_copy_stage_from_user(tape, tape->merge_stage, buf, actually_written); | ||
3835 | buf += actually_written; | ||
3836 | tape->merge_stage_size += actually_written; | ||
3837 | count -= actually_written; | ||
3838 | |||
3839 | if (tape->merge_stage_size == tape->stage_size) { | ||
3840 | tape->merge_stage_size = 0; | ||
3841 | retval = idetape_add_chrdev_write_request(drive, tape->capabilities.ctl); | ||
3842 | if (retval <= 0) | ||
3843 | return (retval); | ||
3844 | } | ||
3845 | } | ||
3846 | while (count >= tape->stage_size) { | ||
3847 | idetape_copy_stage_from_user(tape, tape->merge_stage, buf, tape->stage_size); | ||
3848 | buf += tape->stage_size; | ||
3849 | count -= tape->stage_size; | ||
3850 | retval = idetape_add_chrdev_write_request(drive, tape->capabilities.ctl); | ||
3851 | actually_written += tape->stage_size; | ||
3852 | if (retval <= 0) | ||
3853 | return (retval); | ||
3854 | } | ||
3855 | if (count) { | ||
3856 | actually_written += count; | ||
3857 | idetape_copy_stage_from_user(tape, tape->merge_stage, buf, count); | ||
3858 | tape->merge_stage_size += count; | ||
3859 | } | ||
3860 | return (actually_written); | ||
3861 | } | ||
3862 | |||
3863 | static int idetape_write_filemark (ide_drive_t *drive) | ||
3864 | { | ||
3865 | idetape_pc_t pc; | ||
3866 | |||
3867 | /* Write a filemark */ | ||
3868 | idetape_create_write_filemark_cmd(drive, &pc, 1); | ||
3869 | if (idetape_queue_pc_tail(drive, &pc)) { | ||
3870 | printk(KERN_ERR "ide-tape: Couldn't write a filemark\n"); | ||
3871 | return -EIO; | ||
3872 | } | ||
3873 | return 0; | ||
3874 | } | ||
3875 | |||
3876 | /* | ||
3877 | * idetape_mtioctop is called from idetape_chrdev_ioctl when | ||
3878 | * the general mtio MTIOCTOP ioctl is requested. | ||
3879 | * | ||
3880 | * We currently support the following mtio.h operations: | ||
3881 | * | ||
3882 | * MTFSF - Space over mt_count filemarks in the positive direction. | ||
3883 | * The tape is positioned after the last spaced filemark. | ||
3884 | * | ||
3885 | * MTFSFM - Same as MTFSF, but the tape is positioned before the | ||
3886 | * last filemark. | ||
3887 | * | ||
3888 | * MTBSF - Steps background over mt_count filemarks, tape is | ||
3889 | * positioned before the last filemark. | ||
3890 | * | ||
3891 | * MTBSFM - Like MTBSF, only tape is positioned after the last filemark. | ||
3892 | * | ||
3893 | * Note: | ||
3894 | * | ||
3895 | * MTBSF and MTBSFM are not supported when the tape doesn't | ||
3896 | * support spacing over filemarks in the reverse direction. | ||
3897 | * In this case, MTFSFM is also usually not supported (it is | ||
3898 | * supported in the rare case in which we crossed the filemark | ||
3899 | * during our read-ahead pipelined operation mode). | ||
3900 | * | ||
3901 | * MTWEOF - Writes mt_count filemarks. Tape is positioned after | ||
3902 | * the last written filemark. | ||
3903 | * | ||
3904 | * MTREW - Rewinds tape. | ||
3905 | * | ||
3906 | * MTLOAD - Loads the tape. | ||
3907 | * | ||
3908 | * MTOFFL - Puts the tape drive "Offline": Rewinds the tape and | ||
3909 | * MTUNLOAD prevents further access until the media is replaced. | ||
3910 | * | ||
3911 | * MTNOP - Flushes tape buffers. | ||
3912 | * | ||
3913 | * MTRETEN - Retension media. This typically consists of one end | ||
3914 | * to end pass on the media. | ||
3915 | * | ||
3916 | * MTEOM - Moves to the end of recorded data. | ||
3917 | * | ||
3918 | * MTERASE - Erases tape. | ||
3919 | * | ||
3920 | * MTSETBLK - Sets the user block size to mt_count bytes. If | ||
3921 | * mt_count is 0, we will attempt to autodetect | ||
3922 | * the block size. | ||
3923 | * | ||
3924 | * MTSEEK - Positions the tape in a specific block number, where | ||
3925 | * each block is assumed to contain which user_block_size | ||
3926 | * bytes. | ||
3927 | * | ||
3928 | * MTSETPART - Switches to another tape partition. | ||
3929 | * | ||
3930 | * MTLOCK - Locks the tape door. | ||
3931 | * | ||
3932 | * MTUNLOCK - Unlocks the tape door. | ||
3933 | * | ||
3934 | * The following commands are currently not supported: | ||
3935 | * | ||
3936 | * MTFSS, MTBSS, MTWSM, MTSETDENSITY, | ||
3937 | * MTSETDRVBUFFER, MT_ST_BOOLEANS, MT_ST_WRITE_THRESHOLD. | ||
3938 | */ | ||
3939 | static int idetape_mtioctop (ide_drive_t *drive,short mt_op,int mt_count) | ||
3940 | { | ||
3941 | idetape_tape_t *tape = drive->driver_data; | ||
3942 | idetape_pc_t pc; | ||
3943 | int i,retval; | ||
3944 | |||
3945 | #if IDETAPE_DEBUG_LOG | ||
3946 | if (tape->debug_level >= 1) | ||
3947 | printk(KERN_INFO "ide-tape: Handling MTIOCTOP ioctl: " | ||
3948 | "mt_op=%d, mt_count=%d\n", mt_op, mt_count); | ||
3949 | #endif /* IDETAPE_DEBUG_LOG */ | ||
3950 | /* | ||
3951 | * Commands which need our pipelined read-ahead stages. | ||
3952 | */ | ||
3953 | switch (mt_op) { | ||
3954 | case MTFSF: | ||
3955 | case MTFSFM: | ||
3956 | case MTBSF: | ||
3957 | case MTBSFM: | ||
3958 | if (!mt_count) | ||
3959 | return (0); | ||
3960 | return (idetape_space_over_filemarks(drive,mt_op,mt_count)); | ||
3961 | default: | ||
3962 | break; | ||
3963 | } | ||
3964 | switch (mt_op) { | ||
3965 | case MTWEOF: | ||
3966 | if (tape->write_prot) | ||
3967 | return -EACCES; | ||
3968 | idetape_discard_read_pipeline(drive, 1); | ||
3969 | for (i = 0; i < mt_count; i++) { | ||
3970 | retval = idetape_write_filemark(drive); | ||
3971 | if (retval) | ||
3972 | return retval; | ||
3973 | } | ||
3974 | return (0); | ||
3975 | case MTREW: | ||
3976 | idetape_discard_read_pipeline(drive, 0); | ||
3977 | if (idetape_rewind_tape(drive)) | ||
3978 | return -EIO; | ||
3979 | return 0; | ||
3980 | case MTLOAD: | ||
3981 | idetape_discard_read_pipeline(drive, 0); | ||
3982 | idetape_create_load_unload_cmd(drive, &pc, IDETAPE_LU_LOAD_MASK); | ||
3983 | return (idetape_queue_pc_tail(drive, &pc)); | ||
3984 | case MTUNLOAD: | ||
3985 | case MTOFFL: | ||
3986 | /* | ||
3987 | * If door is locked, attempt to unlock before | ||
3988 | * attempting to eject. | ||
3989 | */ | ||
3990 | if (tape->door_locked) { | ||
3991 | if (idetape_create_prevent_cmd(drive, &pc, 0)) | ||
3992 | if (!idetape_queue_pc_tail(drive, &pc)) | ||
3993 | tape->door_locked = DOOR_UNLOCKED; | ||
3994 | } | ||
3995 | idetape_discard_read_pipeline(drive, 0); | ||
3996 | idetape_create_load_unload_cmd(drive, &pc,!IDETAPE_LU_LOAD_MASK); | ||
3997 | retval = idetape_queue_pc_tail(drive, &pc); | ||
3998 | if (!retval) | ||
3999 | clear_bit(IDETAPE_MEDIUM_PRESENT, &tape->flags); | ||
4000 | return retval; | ||
4001 | case MTNOP: | ||
4002 | idetape_discard_read_pipeline(drive, 0); | ||
4003 | return (idetape_flush_tape_buffers(drive)); | ||
4004 | case MTRETEN: | ||
4005 | idetape_discard_read_pipeline(drive, 0); | ||
4006 | idetape_create_load_unload_cmd(drive, &pc,IDETAPE_LU_RETENSION_MASK | IDETAPE_LU_LOAD_MASK); | ||
4007 | return (idetape_queue_pc_tail(drive, &pc)); | ||
4008 | case MTEOM: | ||
4009 | idetape_create_space_cmd(&pc, 0, IDETAPE_SPACE_TO_EOD); | ||
4010 | return (idetape_queue_pc_tail(drive, &pc)); | ||
4011 | case MTERASE: | ||
4012 | (void) idetape_rewind_tape(drive); | ||
4013 | idetape_create_erase_cmd(&pc); | ||
4014 | return (idetape_queue_pc_tail(drive, &pc)); | ||
4015 | case MTSETBLK: | ||
4016 | if (mt_count) { | ||
4017 | if (mt_count < tape->tape_block_size || mt_count % tape->tape_block_size) | ||
4018 | return -EIO; | ||
4019 | tape->user_bs_factor = mt_count / tape->tape_block_size; | ||
4020 | clear_bit(IDETAPE_DETECT_BS, &tape->flags); | ||
4021 | } else | ||
4022 | set_bit(IDETAPE_DETECT_BS, &tape->flags); | ||
4023 | return 0; | ||
4024 | case MTSEEK: | ||
4025 | idetape_discard_read_pipeline(drive, 0); | ||
4026 | return idetape_position_tape(drive, mt_count * tape->user_bs_factor, tape->partition, 0); | ||
4027 | case MTSETPART: | ||
4028 | idetape_discard_read_pipeline(drive, 0); | ||
4029 | return (idetape_position_tape(drive, 0, mt_count, 0)); | ||
4030 | case MTFSR: | ||
4031 | case MTBSR: | ||
4032 | case MTLOCK: | ||
4033 | if (!idetape_create_prevent_cmd(drive, &pc, 1)) | ||
4034 | return 0; | ||
4035 | retval = idetape_queue_pc_tail(drive, &pc); | ||
4036 | if (retval) return retval; | ||
4037 | tape->door_locked = DOOR_EXPLICITLY_LOCKED; | ||
4038 | return 0; | ||
4039 | case MTUNLOCK: | ||
4040 | if (!idetape_create_prevent_cmd(drive, &pc, 0)) | ||
4041 | return 0; | ||
4042 | retval = idetape_queue_pc_tail(drive, &pc); | ||
4043 | if (retval) return retval; | ||
4044 | tape->door_locked = DOOR_UNLOCKED; | ||
4045 | return 0; | ||
4046 | default: | ||
4047 | printk(KERN_ERR "ide-tape: MTIO operation %d not " | ||
4048 | "supported\n", mt_op); | ||
4049 | return (-EIO); | ||
4050 | } | ||
4051 | } | ||
4052 | |||
4053 | /* | ||
4054 | * Our character device ioctls. | ||
4055 | * | ||
4056 | * General mtio.h magnetic io commands are supported here, and not in | ||
4057 | * the corresponding block interface. | ||
4058 | * | ||
4059 | * The following ioctls are supported: | ||
4060 | * | ||
4061 | * MTIOCTOP - Refer to idetape_mtioctop for detailed description. | ||
4062 | * | ||
4063 | * MTIOCGET - The mt_dsreg field in the returned mtget structure | ||
4064 | * will be set to (user block size in bytes << | ||
4065 | * MT_ST_BLKSIZE_SHIFT) & MT_ST_BLKSIZE_MASK. | ||
4066 | * | ||
4067 | * The mt_blkno is set to the current user block number. | ||
4068 | * The other mtget fields are not supported. | ||
4069 | * | ||
4070 | * MTIOCPOS - The current tape "block position" is returned. We | ||
4071 | * assume that each block contains user_block_size | ||
4072 | * bytes. | ||
4073 | * | ||
4074 | * Our own ide-tape ioctls are supported on both interfaces. | ||
4075 | */ | ||
4076 | static int idetape_chrdev_ioctl (struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) | ||
4077 | { | ||
4078 | struct ide_tape_obj *tape = ide_tape_f(file); | ||
4079 | ide_drive_t *drive = tape->drive; | ||
4080 | struct mtop mtop; | ||
4081 | struct mtget mtget; | ||
4082 | struct mtpos mtpos; | ||
4083 | int block_offset = 0, position = tape->first_frame_position; | ||
4084 | void __user *argp = (void __user *)arg; | ||
4085 | |||
4086 | #if IDETAPE_DEBUG_LOG | ||
4087 | if (tape->debug_level >= 3) | ||
4088 | printk(KERN_INFO "ide-tape: Reached idetape_chrdev_ioctl, " | ||
4089 | "cmd=%u\n", cmd); | ||
4090 | #endif /* IDETAPE_DEBUG_LOG */ | ||
4091 | |||
4092 | tape->restart_speed_control_req = 1; | ||
4093 | if (tape->chrdev_direction == idetape_direction_write) { | ||
4094 | idetape_empty_write_pipeline(drive); | ||
4095 | idetape_flush_tape_buffers(drive); | ||
4096 | } | ||
4097 | if (cmd == MTIOCGET || cmd == MTIOCPOS) { | ||
4098 | block_offset = idetape_pipeline_size(drive) / (tape->tape_block_size * tape->user_bs_factor); | ||
4099 | if ((position = idetape_read_position(drive)) < 0) | ||
4100 | return -EIO; | ||
4101 | } | ||
4102 | switch (cmd) { | ||
4103 | case MTIOCTOP: | ||
4104 | if (copy_from_user(&mtop, argp, sizeof (struct mtop))) | ||
4105 | return -EFAULT; | ||
4106 | return (idetape_mtioctop(drive,mtop.mt_op,mtop.mt_count)); | ||
4107 | case MTIOCGET: | ||
4108 | memset(&mtget, 0, sizeof (struct mtget)); | ||
4109 | mtget.mt_type = MT_ISSCSI2; | ||
4110 | mtget.mt_blkno = position / tape->user_bs_factor - block_offset; | ||
4111 | mtget.mt_dsreg = ((tape->tape_block_size * tape->user_bs_factor) << MT_ST_BLKSIZE_SHIFT) & MT_ST_BLKSIZE_MASK; | ||
4112 | if (tape->drv_write_prot) { | ||
4113 | mtget.mt_gstat |= GMT_WR_PROT(0xffffffff); | ||
4114 | } | ||
4115 | if (copy_to_user(argp, &mtget, sizeof(struct mtget))) | ||
4116 | return -EFAULT; | ||
4117 | return 0; | ||
4118 | case MTIOCPOS: | ||
4119 | mtpos.mt_blkno = position / tape->user_bs_factor - block_offset; | ||
4120 | if (copy_to_user(argp, &mtpos, sizeof(struct mtpos))) | ||
4121 | return -EFAULT; | ||
4122 | return 0; | ||
4123 | default: | ||
4124 | if (tape->chrdev_direction == idetape_direction_read) | ||
4125 | idetape_discard_read_pipeline(drive, 1); | ||
4126 | return idetape_blkdev_ioctl(drive, cmd, arg); | ||
4127 | } | ||
4128 | } | ||
4129 | |||
4130 | static void idetape_get_blocksize_from_block_descriptor(ide_drive_t *drive); | ||
4131 | |||
4132 | /* | ||
4133 | * Our character device open function. | ||
4134 | */ | ||
4135 | static int idetape_chrdev_open (struct inode *inode, struct file *filp) | ||
4136 | { | ||
4137 | unsigned int minor = iminor(inode), i = minor & ~0xc0; | ||
4138 | ide_drive_t *drive; | ||
4139 | idetape_tape_t *tape; | ||
4140 | idetape_pc_t pc; | ||
4141 | int retval; | ||
4142 | |||
4143 | /* | ||
4144 | * We really want to do nonseekable_open(inode, filp); here, but some | ||
4145 | * versions of tar incorrectly call lseek on tapes and bail out if that | ||
4146 | * fails. So we disallow pread() and pwrite(), but permit lseeks. | ||
4147 | */ | ||
4148 | filp->f_mode &= ~(FMODE_PREAD | FMODE_PWRITE); | ||
4149 | |||
4150 | #if IDETAPE_DEBUG_LOG | ||
4151 | printk(KERN_INFO "ide-tape: Reached idetape_chrdev_open\n"); | ||
4152 | #endif /* IDETAPE_DEBUG_LOG */ | ||
4153 | |||
4154 | if (i >= MAX_HWIFS * MAX_DRIVES) | ||
4155 | return -ENXIO; | ||
4156 | |||
4157 | if (!(tape = ide_tape_chrdev_get(i))) | ||
4158 | return -ENXIO; | ||
4159 | |||
4160 | drive = tape->drive; | ||
4161 | |||
4162 | filp->private_data = tape; | ||
4163 | |||
4164 | if (test_and_set_bit(IDETAPE_BUSY, &tape->flags)) { | ||
4165 | retval = -EBUSY; | ||
4166 | goto out_put_tape; | ||
4167 | } | ||
4168 | |||
4169 | retval = idetape_wait_ready(drive, 60 * HZ); | ||
4170 | if (retval) { | ||
4171 | clear_bit(IDETAPE_BUSY, &tape->flags); | ||
4172 | printk(KERN_ERR "ide-tape: %s: drive not ready\n", tape->name); | ||
4173 | goto out_put_tape; | ||
4174 | } | ||
4175 | |||
4176 | idetape_read_position(drive); | ||
4177 | if (!test_bit(IDETAPE_ADDRESS_VALID, &tape->flags)) | ||
4178 | (void)idetape_rewind_tape(drive); | ||
4179 | |||
4180 | if (tape->chrdev_direction != idetape_direction_read) | ||
4181 | clear_bit(IDETAPE_PIPELINE_ERROR, &tape->flags); | ||
4182 | |||
4183 | /* Read block size and write protect status from drive. */ | ||
4184 | idetape_get_blocksize_from_block_descriptor(drive); | ||
4185 | |||
4186 | /* Set write protect flag if device is opened as read-only. */ | ||
4187 | if ((filp->f_flags & O_ACCMODE) == O_RDONLY) | ||
4188 | tape->write_prot = 1; | ||
4189 | else | ||
4190 | tape->write_prot = tape->drv_write_prot; | ||
4191 | |||
4192 | /* Make sure drive isn't write protected if user wants to write. */ | ||
4193 | if (tape->write_prot) { | ||
4194 | if ((filp->f_flags & O_ACCMODE) == O_WRONLY || | ||
4195 | (filp->f_flags & O_ACCMODE) == O_RDWR) { | ||
4196 | clear_bit(IDETAPE_BUSY, &tape->flags); | ||
4197 | retval = -EROFS; | ||
4198 | goto out_put_tape; | ||
4199 | } | ||
4200 | } | ||
4201 | |||
4202 | /* | ||
4203 | * Lock the tape drive door so user can't eject. | ||
4204 | */ | ||
4205 | if (tape->chrdev_direction == idetape_direction_none) { | ||
4206 | if (idetape_create_prevent_cmd(drive, &pc, 1)) { | ||
4207 | if (!idetape_queue_pc_tail(drive, &pc)) { | ||
4208 | if (tape->door_locked != DOOR_EXPLICITLY_LOCKED) | ||
4209 | tape->door_locked = DOOR_LOCKED; | ||
4210 | } | ||
4211 | } | ||
4212 | } | ||
4213 | idetape_restart_speed_control(drive); | ||
4214 | tape->restart_speed_control_req = 0; | ||
4215 | return 0; | ||
4216 | |||
4217 | out_put_tape: | ||
4218 | ide_tape_put(tape); | ||
4219 | return retval; | ||
4220 | } | ||
4221 | |||
4222 | static void idetape_write_release (ide_drive_t *drive, unsigned int minor) | ||
4223 | { | ||
4224 | idetape_tape_t *tape = drive->driver_data; | ||
4225 | |||
4226 | idetape_empty_write_pipeline(drive); | ||
4227 | tape->merge_stage = __idetape_kmalloc_stage(tape, 1, 0); | ||
4228 | if (tape->merge_stage != NULL) { | ||
4229 | idetape_pad_zeros(drive, tape->tape_block_size * (tape->user_bs_factor - 1)); | ||
4230 | __idetape_kfree_stage(tape->merge_stage); | ||
4231 | tape->merge_stage = NULL; | ||
4232 | } | ||
4233 | idetape_write_filemark(drive); | ||
4234 | idetape_flush_tape_buffers(drive); | ||
4235 | idetape_flush_tape_buffers(drive); | ||
4236 | } | ||
4237 | |||
4238 | /* | ||
4239 | * Our character device release function. | ||
4240 | */ | ||
4241 | static int idetape_chrdev_release (struct inode *inode, struct file *filp) | ||
4242 | { | ||
4243 | struct ide_tape_obj *tape = ide_tape_f(filp); | ||
4244 | ide_drive_t *drive = tape->drive; | ||
4245 | idetape_pc_t pc; | ||
4246 | unsigned int minor = iminor(inode); | ||
4247 | |||
4248 | lock_kernel(); | ||
4249 | tape = drive->driver_data; | ||
4250 | #if IDETAPE_DEBUG_LOG | ||
4251 | if (tape->debug_level >= 3) | ||
4252 | printk(KERN_INFO "ide-tape: Reached idetape_chrdev_release\n"); | ||
4253 | #endif /* IDETAPE_DEBUG_LOG */ | ||
4254 | |||
4255 | if (tape->chrdev_direction == idetape_direction_write) | ||
4256 | idetape_write_release(drive, minor); | ||
4257 | if (tape->chrdev_direction == idetape_direction_read) { | ||
4258 | if (minor < 128) | ||
4259 | idetape_discard_read_pipeline(drive, 1); | ||
4260 | else | ||
4261 | idetape_wait_for_pipeline(drive); | ||
4262 | } | ||
4263 | if (tape->cache_stage != NULL) { | ||
4264 | __idetape_kfree_stage(tape->cache_stage); | ||
4265 | tape->cache_stage = NULL; | ||
4266 | } | ||
4267 | if (minor < 128 && test_bit(IDETAPE_MEDIUM_PRESENT, &tape->flags)) | ||
4268 | (void) idetape_rewind_tape(drive); | ||
4269 | if (tape->chrdev_direction == idetape_direction_none) { | ||
4270 | if (tape->door_locked == DOOR_LOCKED) { | ||
4271 | if (idetape_create_prevent_cmd(drive, &pc, 0)) { | ||
4272 | if (!idetape_queue_pc_tail(drive, &pc)) | ||
4273 | tape->door_locked = DOOR_UNLOCKED; | ||
4274 | } | ||
4275 | } | ||
4276 | } | ||
4277 | clear_bit(IDETAPE_BUSY, &tape->flags); | ||
4278 | ide_tape_put(tape); | ||
4279 | unlock_kernel(); | ||
4280 | return 0; | ||
4281 | } | ||
4282 | |||
4283 | /* | ||
4284 | * idetape_identify_device is called to check the contents of the | ||
4285 | * ATAPI IDENTIFY command results. We return: | ||
4286 | * | ||
4287 | * 1 If the tape can be supported by us, based on the information | ||
4288 | * we have so far. | ||
4289 | * | ||
4290 | * 0 If this tape driver is not currently supported by us. | ||
4291 | */ | ||
4292 | static int idetape_identify_device (ide_drive_t *drive) | ||
4293 | { | ||
4294 | struct idetape_id_gcw gcw; | ||
4295 | struct hd_driveid *id = drive->id; | ||
4296 | #if IDETAPE_DEBUG_INFO | ||
4297 | unsigned short mask,i; | ||
4298 | #endif /* IDETAPE_DEBUG_INFO */ | ||
4299 | |||
4300 | if (drive->id_read == 0) | ||
4301 | return 1; | ||
4302 | |||
4303 | *((unsigned short *) &gcw) = id->config; | ||
4304 | |||
4305 | #if IDETAPE_DEBUG_INFO | ||
4306 | printk(KERN_INFO "ide-tape: Dumping ATAPI Identify Device tape parameters\n"); | ||
4307 | printk(KERN_INFO "ide-tape: Protocol Type: "); | ||
4308 | switch (gcw.protocol) { | ||
4309 | case 0: case 1: printk("ATA\n");break; | ||
4310 | case 2: printk("ATAPI\n");break; | ||
4311 | case 3: printk("Reserved (Unknown to ide-tape)\n");break; | ||
4312 | } | ||
4313 | printk(KERN_INFO "ide-tape: Device Type: %x - ",gcw.device_type); | ||
4314 | switch (gcw.device_type) { | ||
4315 | case 0: printk("Direct-access Device\n");break; | ||
4316 | case 1: printk("Streaming Tape Device\n");break; | ||
4317 | case 2: case 3: case 4: printk("Reserved\n");break; | ||
4318 | case 5: printk("CD-ROM Device\n");break; | ||
4319 | case 6: printk("Reserved\n"); | ||
4320 | case 7: printk("Optical memory Device\n");break; | ||
4321 | case 0x1f: printk("Unknown or no Device type\n");break; | ||
4322 | default: printk("Reserved\n"); | ||
4323 | } | ||
4324 | printk(KERN_INFO "ide-tape: Removable: %s",gcw.removable ? "Yes\n":"No\n"); | ||
4325 | printk(KERN_INFO "ide-tape: Command Packet DRQ Type: "); | ||
4326 | switch (gcw.drq_type) { | ||
4327 | case 0: printk("Microprocessor DRQ\n");break; | ||
4328 | case 1: printk("Interrupt DRQ\n");break; | ||
4329 | case 2: printk("Accelerated DRQ\n");break; | ||
4330 | case 3: printk("Reserved\n");break; | ||
4331 | } | ||
4332 | printk(KERN_INFO "ide-tape: Command Packet Size: "); | ||
4333 | switch (gcw.packet_size) { | ||
4334 | case 0: printk("12 bytes\n");break; | ||
4335 | case 1: printk("16 bytes\n");break; | ||
4336 | default: printk("Reserved\n");break; | ||
4337 | } | ||
4338 | printk(KERN_INFO "ide-tape: Model: %.40s\n",id->model); | ||
4339 | printk(KERN_INFO "ide-tape: Firmware Revision: %.8s\n",id->fw_rev); | ||
4340 | printk(KERN_INFO "ide-tape: Serial Number: %.20s\n",id->serial_no); | ||
4341 | printk(KERN_INFO "ide-tape: Write buffer size: %d bytes\n",id->buf_size*512); | ||
4342 | printk(KERN_INFO "ide-tape: DMA: %s",id->capability & 0x01 ? "Yes\n":"No\n"); | ||
4343 | printk(KERN_INFO "ide-tape: LBA: %s",id->capability & 0x02 ? "Yes\n":"No\n"); | ||
4344 | printk(KERN_INFO "ide-tape: IORDY can be disabled: %s",id->capability & 0x04 ? "Yes\n":"No\n"); | ||
4345 | printk(KERN_INFO "ide-tape: IORDY supported: %s",id->capability & 0x08 ? "Yes\n":"Unknown\n"); | ||
4346 | printk(KERN_INFO "ide-tape: ATAPI overlap supported: %s",id->capability & 0x20 ? "Yes\n":"No\n"); | ||
4347 | printk(KERN_INFO "ide-tape: PIO Cycle Timing Category: %d\n",id->tPIO); | ||
4348 | printk(KERN_INFO "ide-tape: DMA Cycle Timing Category: %d\n",id->tDMA); | ||
4349 | printk(KERN_INFO "ide-tape: Single Word DMA supported modes: "); | ||
4350 | for (i=0,mask=1;i<8;i++,mask=mask << 1) { | ||
4351 | if (id->dma_1word & mask) | ||
4352 | printk("%d ",i); | ||
4353 | if (id->dma_1word & (mask << 8)) | ||
4354 | printk("(active) "); | ||
4355 | } | ||
4356 | printk("\n"); | ||
4357 | printk(KERN_INFO "ide-tape: Multi Word DMA supported modes: "); | ||
4358 | for (i=0,mask=1;i<8;i++,mask=mask << 1) { | ||
4359 | if (id->dma_mword & mask) | ||
4360 | printk("%d ",i); | ||
4361 | if (id->dma_mword & (mask << 8)) | ||
4362 | printk("(active) "); | ||
4363 | } | ||
4364 | printk("\n"); | ||
4365 | if (id->field_valid & 0x0002) { | ||
4366 | printk(KERN_INFO "ide-tape: Enhanced PIO Modes: %s\n", | ||
4367 | id->eide_pio_modes & 1 ? "Mode 3":"None"); | ||
4368 | printk(KERN_INFO "ide-tape: Minimum Multi-word DMA cycle per word: "); | ||
4369 | if (id->eide_dma_min == 0) | ||
4370 | printk("Not supported\n"); | ||
4371 | else | ||
4372 | printk("%d ns\n",id->eide_dma_min); | ||
4373 | |||
4374 | printk(KERN_INFO "ide-tape: Manufacturer\'s Recommended Multi-word cycle: "); | ||
4375 | if (id->eide_dma_time == 0) | ||
4376 | printk("Not supported\n"); | ||
4377 | else | ||
4378 | printk("%d ns\n",id->eide_dma_time); | ||
4379 | |||
4380 | printk(KERN_INFO "ide-tape: Minimum PIO cycle without IORDY: "); | ||
4381 | if (id->eide_pio == 0) | ||
4382 | printk("Not supported\n"); | ||
4383 | else | ||
4384 | printk("%d ns\n",id->eide_pio); | ||
4385 | |||
4386 | printk(KERN_INFO "ide-tape: Minimum PIO cycle with IORDY: "); | ||
4387 | if (id->eide_pio_iordy == 0) | ||
4388 | printk("Not supported\n"); | ||
4389 | else | ||
4390 | printk("%d ns\n",id->eide_pio_iordy); | ||
4391 | |||
4392 | } else | ||
4393 | printk(KERN_INFO "ide-tape: According to the device, fields 64-70 are not valid.\n"); | ||
4394 | #endif /* IDETAPE_DEBUG_INFO */ | ||
4395 | |||
4396 | /* Check that we can support this device */ | ||
4397 | |||
4398 | if (gcw.protocol !=2 ) | ||
4399 | printk(KERN_ERR "ide-tape: Protocol is not ATAPI\n"); | ||
4400 | else if (gcw.device_type != 1) | ||
4401 | printk(KERN_ERR "ide-tape: Device type is not set to tape\n"); | ||
4402 | else if (!gcw.removable) | ||
4403 | printk(KERN_ERR "ide-tape: The removable flag is not set\n"); | ||
4404 | else if (gcw.packet_size != 0) { | ||
4405 | printk(KERN_ERR "ide-tape: Packet size is not 12 bytes long\n"); | ||
4406 | if (gcw.packet_size == 1) | ||
4407 | printk(KERN_ERR "ide-tape: Sorry, padding to 16 bytes is still not supported\n"); | ||
4408 | } else | ||
4409 | return 1; | ||
4410 | return 0; | ||
4411 | } | ||
4412 | |||
4413 | /* | ||
4414 | * Use INQUIRY to get the firmware revision | ||
4415 | */ | ||
4416 | static void idetape_get_inquiry_results (ide_drive_t *drive) | ||
4417 | { | ||
4418 | char *r; | ||
4419 | idetape_tape_t *tape = drive->driver_data; | ||
4420 | idetape_pc_t pc; | ||
4421 | idetape_inquiry_result_t *inquiry; | ||
4422 | |||
4423 | idetape_create_inquiry_cmd(&pc); | ||
4424 | if (idetape_queue_pc_tail(drive, &pc)) { | ||
4425 | printk(KERN_ERR "ide-tape: %s: can't get INQUIRY results\n", tape->name); | ||
4426 | return; | ||
4427 | } | ||
4428 | inquiry = (idetape_inquiry_result_t *) pc.buffer; | ||
4429 | memcpy(tape->vendor_id, inquiry->vendor_id, 8); | ||
4430 | memcpy(tape->product_id, inquiry->product_id, 16); | ||
4431 | memcpy(tape->firmware_revision, inquiry->revision_level, 4); | ||
4432 | ide_fixstring(tape->vendor_id, 10, 0); | ||
4433 | ide_fixstring(tape->product_id, 18, 0); | ||
4434 | ide_fixstring(tape->firmware_revision, 6, 0); | ||
4435 | r = tape->firmware_revision; | ||
4436 | if (*(r + 1) == '.') | ||
4437 | tape->firmware_revision_num = (*r - '0') * 100 + (*(r + 2) - '0') * 10 + *(r + 3) - '0'; | ||
4438 | printk(KERN_INFO "ide-tape: %s <-> %s: %s %s rev %s\n", drive->name, tape->name, tape->vendor_id, tape->product_id, tape->firmware_revision); | ||
4439 | } | ||
4440 | |||
4441 | /* | ||
4442 | * idetape_get_mode_sense_results asks the tape about its various | ||
4443 | * parameters. In particular, we will adjust our data transfer buffer | ||
4444 | * size to the recommended value as returned by the tape. | ||
4445 | */ | ||
4446 | static void idetape_get_mode_sense_results (ide_drive_t *drive) | ||
4447 | { | ||
4448 | idetape_tape_t *tape = drive->driver_data; | ||
4449 | idetape_pc_t pc; | ||
4450 | idetape_mode_parameter_header_t *header; | ||
4451 | idetape_capabilities_page_t *capabilities; | ||
4452 | |||
4453 | idetape_create_mode_sense_cmd(&pc, IDETAPE_CAPABILITIES_PAGE); | ||
4454 | if (idetape_queue_pc_tail(drive, &pc)) { | ||
4455 | printk(KERN_ERR "ide-tape: Can't get tape parameters - assuming some default values\n"); | ||
4456 | tape->tape_block_size = 512; | ||
4457 | tape->capabilities.ctl = 52; | ||
4458 | tape->capabilities.speed = 450; | ||
4459 | tape->capabilities.buffer_size = 6 * 52; | ||
4460 | return; | ||
4461 | } | ||
4462 | header = (idetape_mode_parameter_header_t *) pc.buffer; | ||
4463 | capabilities = (idetape_capabilities_page_t *) (pc.buffer + sizeof(idetape_mode_parameter_header_t) + header->bdl); | ||
4464 | |||
4465 | capabilities->max_speed = ntohs(capabilities->max_speed); | ||
4466 | capabilities->ctl = ntohs(capabilities->ctl); | ||
4467 | capabilities->speed = ntohs(capabilities->speed); | ||
4468 | capabilities->buffer_size = ntohs(capabilities->buffer_size); | ||
4469 | |||
4470 | if (!capabilities->speed) { | ||
4471 | printk(KERN_INFO "ide-tape: %s: overriding capabilities->speed (assuming 650KB/sec)\n", drive->name); | ||
4472 | capabilities->speed = 650; | ||
4473 | } | ||
4474 | if (!capabilities->max_speed) { | ||
4475 | printk(KERN_INFO "ide-tape: %s: overriding capabilities->max_speed (assuming 650KB/sec)\n", drive->name); | ||
4476 | capabilities->max_speed = 650; | ||
4477 | } | ||
4478 | |||
4479 | tape->capabilities = *capabilities; /* Save us a copy */ | ||
4480 | if (capabilities->blk512) | ||
4481 | tape->tape_block_size = 512; | ||
4482 | else if (capabilities->blk1024) | ||
4483 | tape->tape_block_size = 1024; | ||
4484 | |||
4485 | #if IDETAPE_DEBUG_INFO | ||
4486 | printk(KERN_INFO "ide-tape: Dumping the results of the MODE SENSE packet command\n"); | ||
4487 | printk(KERN_INFO "ide-tape: Mode Parameter Header:\n"); | ||
4488 | printk(KERN_INFO "ide-tape: Mode Data Length - %d\n",header->mode_data_length); | ||
4489 | printk(KERN_INFO "ide-tape: Medium Type - %d\n",header->medium_type); | ||
4490 | printk(KERN_INFO "ide-tape: Device Specific Parameter - %d\n",header->dsp); | ||
4491 | printk(KERN_INFO "ide-tape: Block Descriptor Length - %d\n",header->bdl); | ||
4492 | |||
4493 | printk(KERN_INFO "ide-tape: Capabilities and Mechanical Status Page:\n"); | ||
4494 | printk(KERN_INFO "ide-tape: Page code - %d\n",capabilities->page_code); | ||
4495 | printk(KERN_INFO "ide-tape: Page length - %d\n",capabilities->page_length); | ||
4496 | printk(KERN_INFO "ide-tape: Read only - %s\n",capabilities->ro ? "Yes":"No"); | ||
4497 | printk(KERN_INFO "ide-tape: Supports reverse space - %s\n",capabilities->sprev ? "Yes":"No"); | ||
4498 | printk(KERN_INFO "ide-tape: Supports erase initiated formatting - %s\n",capabilities->efmt ? "Yes":"No"); | ||
4499 | printk(KERN_INFO "ide-tape: Supports QFA two Partition format - %s\n",capabilities->qfa ? "Yes":"No"); | ||
4500 | printk(KERN_INFO "ide-tape: Supports locking the medium - %s\n",capabilities->lock ? "Yes":"No"); | ||
4501 | printk(KERN_INFO "ide-tape: The volume is currently locked - %s\n",capabilities->locked ? "Yes":"No"); | ||
4502 | printk(KERN_INFO "ide-tape: The device defaults in the prevent state - %s\n",capabilities->prevent ? "Yes":"No"); | ||
4503 | printk(KERN_INFO "ide-tape: Supports ejecting the medium - %s\n",capabilities->eject ? "Yes":"No"); | ||
4504 | printk(KERN_INFO "ide-tape: Supports error correction - %s\n",capabilities->ecc ? "Yes":"No"); | ||
4505 | printk(KERN_INFO "ide-tape: Supports data compression - %s\n",capabilities->cmprs ? "Yes":"No"); | ||
4506 | printk(KERN_INFO "ide-tape: Supports 512 bytes block size - %s\n",capabilities->blk512 ? "Yes":"No"); | ||
4507 | printk(KERN_INFO "ide-tape: Supports 1024 bytes block size - %s\n",capabilities->blk1024 ? "Yes":"No"); | ||
4508 | printk(KERN_INFO "ide-tape: Supports 32768 bytes block size / Restricted byte count for PIO transfers - %s\n",capabilities->blk32768 ? "Yes":"No"); | ||
4509 | printk(KERN_INFO "ide-tape: Maximum supported speed in KBps - %d\n",capabilities->max_speed); | ||
4510 | printk(KERN_INFO "ide-tape: Continuous transfer limits in blocks - %d\n",capabilities->ctl); | ||
4511 | printk(KERN_INFO "ide-tape: Current speed in KBps - %d\n",capabilities->speed); | ||
4512 | printk(KERN_INFO "ide-tape: Buffer size - %d\n",capabilities->buffer_size*512); | ||
4513 | #endif /* IDETAPE_DEBUG_INFO */ | ||
4514 | } | ||
4515 | |||
4516 | /* | ||
4517 | * ide_get_blocksize_from_block_descriptor does a mode sense page 0 with block descriptor | ||
4518 | * and if it succeeds sets the tape block size with the reported value | ||
4519 | */ | ||
4520 | static void idetape_get_blocksize_from_block_descriptor(ide_drive_t *drive) | ||
4521 | { | ||
4522 | |||
4523 | idetape_tape_t *tape = drive->driver_data; | ||
4524 | idetape_pc_t pc; | ||
4525 | idetape_mode_parameter_header_t *header; | ||
4526 | idetape_parameter_block_descriptor_t *block_descrp; | ||
4527 | |||
4528 | idetape_create_mode_sense_cmd(&pc, IDETAPE_BLOCK_DESCRIPTOR); | ||
4529 | if (idetape_queue_pc_tail(drive, &pc)) { | ||
4530 | printk(KERN_ERR "ide-tape: Can't get block descriptor\n"); | ||
4531 | if (tape->tape_block_size == 0) { | ||
4532 | printk(KERN_WARNING "ide-tape: Cannot deal with zero block size, assume 32k\n"); | ||
4533 | tape->tape_block_size = 32768; | ||
4534 | } | ||
4535 | return; | ||
4536 | } | ||
4537 | header = (idetape_mode_parameter_header_t *) pc.buffer; | ||
4538 | block_descrp = (idetape_parameter_block_descriptor_t *) (pc.buffer + sizeof(idetape_mode_parameter_header_t)); | ||
4539 | tape->tape_block_size =( block_descrp->length[0]<<16) + (block_descrp->length[1]<<8) + block_descrp->length[2]; | ||
4540 | tape->drv_write_prot = (header->dsp & 0x80) >> 7; | ||
4541 | |||
4542 | #if IDETAPE_DEBUG_INFO | ||
4543 | printk(KERN_INFO "ide-tape: Adjusted block size - %d\n", tape->tape_block_size); | ||
4544 | #endif /* IDETAPE_DEBUG_INFO */ | ||
4545 | } | ||
4546 | static void idetape_add_settings (ide_drive_t *drive) | ||
4547 | { | ||
4548 | idetape_tape_t *tape = drive->driver_data; | ||
4549 | |||
4550 | /* | ||
4551 | * drive setting name read/write ioctl ioctl data type min max mul_factor div_factor data pointer set function | ||
4552 | */ | ||
4553 | ide_add_setting(drive, "buffer", SETTING_READ, -1, -1, TYPE_SHORT, 0, 0xffff, 1, 2, &tape->capabilities.buffer_size, NULL); | ||
4554 | ide_add_setting(drive, "pipeline_min", SETTING_RW, -1, -1, TYPE_INT, 1, 0xffff, tape->stage_size / 1024, 1, &tape->min_pipeline, NULL); | ||
4555 | ide_add_setting(drive, "pipeline", SETTING_RW, -1, -1, TYPE_INT, 1, 0xffff, tape->stage_size / 1024, 1, &tape->max_stages, NULL); | ||
4556 | ide_add_setting(drive, "pipeline_max", SETTING_RW, -1, -1, TYPE_INT, 1, 0xffff, tape->stage_size / 1024, 1, &tape->max_pipeline, NULL); | ||
4557 | ide_add_setting(drive, "pipeline_used",SETTING_READ, -1, -1, TYPE_INT, 0, 0xffff, tape->stage_size / 1024, 1, &tape->nr_stages, NULL); | ||
4558 | ide_add_setting(drive, "pipeline_pending",SETTING_READ,-1, -1, TYPE_INT, 0, 0xffff, tape->stage_size / 1024, 1, &tape->nr_pending_stages, NULL); | ||
4559 | ide_add_setting(drive, "speed", SETTING_READ, -1, -1, TYPE_SHORT, 0, 0xffff, 1, 1, &tape->capabilities.speed, NULL); | ||
4560 | ide_add_setting(drive, "stage", SETTING_READ, -1, -1, TYPE_INT, 0, 0xffff, 1, 1024, &tape->stage_size, NULL); | ||
4561 | ide_add_setting(drive, "tdsc", SETTING_RW, -1, -1, TYPE_INT, IDETAPE_DSC_RW_MIN, IDETAPE_DSC_RW_MAX, 1000, HZ, &tape->best_dsc_rw_frequency, NULL); | ||
4562 | ide_add_setting(drive, "dsc_overlap", SETTING_RW, -1, -1, TYPE_BYTE, 0, 1, 1, 1, &drive->dsc_overlap, NULL); | ||
4563 | ide_add_setting(drive, "pipeline_head_speed_c",SETTING_READ, -1, -1, TYPE_INT, 0, 0xffff, 1, 1, &tape->controlled_pipeline_head_speed, NULL); | ||
4564 | ide_add_setting(drive, "pipeline_head_speed_u",SETTING_READ, -1, -1, TYPE_INT, 0, 0xffff, 1, 1, &tape->uncontrolled_pipeline_head_speed, NULL); | ||
4565 | ide_add_setting(drive, "avg_speed", SETTING_READ, -1, -1, TYPE_INT, 0, 0xffff, 1, 1, &tape->avg_speed, NULL); | ||
4566 | ide_add_setting(drive, "debug_level",SETTING_RW, -1, -1, TYPE_INT, 0, 0xffff, 1, 1, &tape->debug_level, NULL); | ||
4567 | } | ||
4568 | |||
4569 | /* | ||
4570 | * ide_setup is called to: | ||
4571 | * | ||
4572 | * 1. Initialize our various state variables. | ||
4573 | * 2. Ask the tape for its capabilities. | ||
4574 | * 3. Allocate a buffer which will be used for data | ||
4575 | * transfer. The buffer size is chosen based on | ||
4576 | * the recommendation which we received in step (2). | ||
4577 | * | ||
4578 | * Note that at this point ide.c already assigned us an irq, so that | ||
4579 | * we can queue requests here and wait for their completion. | ||
4580 | */ | ||
4581 | static void idetape_setup (ide_drive_t *drive, idetape_tape_t *tape, int minor) | ||
4582 | { | ||
4583 | unsigned long t1, tmid, tn, t; | ||
4584 | int speed; | ||
4585 | struct idetape_id_gcw gcw; | ||
4586 | int stage_size; | ||
4587 | struct sysinfo si; | ||
4588 | |||
4589 | spin_lock_init(&tape->spinlock); | ||
4590 | drive->dsc_overlap = 1; | ||
4591 | #ifdef CONFIG_BLK_DEV_IDEPCI | ||
4592 | if (HWIF(drive)->pci_dev != NULL) { | ||
4593 | /* | ||
4594 | * These two ide-pci host adapters appear to need DSC overlap disabled. | ||
4595 | * This probably needs further analysis. | ||
4596 | */ | ||
4597 | if ((HWIF(drive)->pci_dev->device == PCI_DEVICE_ID_ARTOP_ATP850UF) || | ||
4598 | (HWIF(drive)->pci_dev->device == PCI_DEVICE_ID_TTI_HPT343)) { | ||
4599 | printk(KERN_INFO "ide-tape: %s: disabling DSC overlap\n", tape->name); | ||
4600 | drive->dsc_overlap = 0; | ||
4601 | } | ||
4602 | } | ||
4603 | #endif /* CONFIG_BLK_DEV_IDEPCI */ | ||
4604 | /* Seagate Travan drives do not support DSC overlap. */ | ||
4605 | if (strstr(drive->id->model, "Seagate STT3401")) | ||
4606 | drive->dsc_overlap = 0; | ||
4607 | tape->minor = minor; | ||
4608 | tape->name[0] = 'h'; | ||
4609 | tape->name[1] = 't'; | ||
4610 | tape->name[2] = '0' + minor; | ||
4611 | tape->chrdev_direction = idetape_direction_none; | ||
4612 | tape->pc = tape->pc_stack; | ||
4613 | tape->max_insert_speed = 10000; | ||
4614 | tape->speed_control = 1; | ||
4615 | *((unsigned short *) &gcw) = drive->id->config; | ||
4616 | if (gcw.drq_type == 1) | ||
4617 | set_bit(IDETAPE_DRQ_INTERRUPT, &tape->flags); | ||
4618 | |||
4619 | tape->min_pipeline = tape->max_pipeline = tape->max_stages = 10; | ||
4620 | |||
4621 | idetape_get_inquiry_results(drive); | ||
4622 | idetape_get_mode_sense_results(drive); | ||
4623 | idetape_get_blocksize_from_block_descriptor(drive); | ||
4624 | tape->user_bs_factor = 1; | ||
4625 | tape->stage_size = tape->capabilities.ctl * tape->tape_block_size; | ||
4626 | while (tape->stage_size > 0xffff) { | ||
4627 | printk(KERN_NOTICE "ide-tape: decreasing stage size\n"); | ||
4628 | tape->capabilities.ctl /= 2; | ||
4629 | tape->stage_size = tape->capabilities.ctl * tape->tape_block_size; | ||
4630 | } | ||
4631 | stage_size = tape->stage_size; | ||
4632 | tape->pages_per_stage = stage_size / PAGE_SIZE; | ||
4633 | if (stage_size % PAGE_SIZE) { | ||
4634 | tape->pages_per_stage++; | ||
4635 | tape->excess_bh_size = PAGE_SIZE - stage_size % PAGE_SIZE; | ||
4636 | } | ||
4637 | |||
4638 | /* | ||
4639 | * Select the "best" DSC read/write polling frequency | ||
4640 | * and pipeline size. | ||
4641 | */ | ||
4642 | speed = max(tape->capabilities.speed, tape->capabilities.max_speed); | ||
4643 | |||
4644 | tape->max_stages = speed * 1000 * 10 / tape->stage_size; | ||
4645 | |||
4646 | /* | ||
4647 | * Limit memory use for pipeline to 10% of physical memory | ||
4648 | */ | ||
4649 | si_meminfo(&si); | ||
4650 | if (tape->max_stages * tape->stage_size > si.totalram * si.mem_unit / 10) | ||
4651 | tape->max_stages = si.totalram * si.mem_unit / (10 * tape->stage_size); | ||
4652 | tape->max_stages = min(tape->max_stages, IDETAPE_MAX_PIPELINE_STAGES); | ||
4653 | tape->min_pipeline = min(tape->max_stages, IDETAPE_MIN_PIPELINE_STAGES); | ||
4654 | tape->max_pipeline = min(tape->max_stages * 2, IDETAPE_MAX_PIPELINE_STAGES); | ||
4655 | if (tape->max_stages == 0) | ||
4656 | tape->max_stages = tape->min_pipeline = tape->max_pipeline = 1; | ||
4657 | |||
4658 | t1 = (tape->stage_size * HZ) / (speed * 1000); | ||
4659 | tmid = (tape->capabilities.buffer_size * 32 * HZ) / (speed * 125); | ||
4660 | tn = (IDETAPE_FIFO_THRESHOLD * tape->stage_size * HZ) / (speed * 1000); | ||
4661 | |||
4662 | if (tape->max_stages) | ||
4663 | t = tn; | ||
4664 | else | ||
4665 | t = t1; | ||
4666 | |||
4667 | /* | ||
4668 | * Ensure that the number we got makes sense; limit | ||
4669 | * it within IDETAPE_DSC_RW_MIN and IDETAPE_DSC_RW_MAX. | ||
4670 | */ | ||
4671 | tape->best_dsc_rw_frequency = max_t(unsigned long, min_t(unsigned long, t, IDETAPE_DSC_RW_MAX), IDETAPE_DSC_RW_MIN); | ||
4672 | printk(KERN_INFO "ide-tape: %s <-> %s: %dKBps, %d*%dkB buffer, " | ||
4673 | "%dkB pipeline, %lums tDSC%s\n", | ||
4674 | drive->name, tape->name, tape->capabilities.speed, | ||
4675 | (tape->capabilities.buffer_size * 512) / tape->stage_size, | ||
4676 | tape->stage_size / 1024, | ||
4677 | tape->max_stages * tape->stage_size / 1024, | ||
4678 | tape->best_dsc_rw_frequency * 1000 / HZ, | ||
4679 | drive->using_dma ? ", DMA":""); | ||
4680 | |||
4681 | idetape_add_settings(drive); | ||
4682 | } | ||
4683 | |||
4684 | static int idetape_cleanup (ide_drive_t *drive) | ||
4685 | { | ||
4686 | idetape_tape_t *tape = drive->driver_data; | ||
4687 | unsigned long flags; | ||
4688 | |||
4689 | spin_lock_irqsave(&ide_lock, flags); | ||
4690 | if (test_bit(IDETAPE_BUSY, &tape->flags) || drive->usage || | ||
4691 | tape->first_stage != NULL || tape->merge_stage_size) { | ||
4692 | spin_unlock_irqrestore(&ide_lock, flags); | ||
4693 | return 1; | ||
4694 | } | ||
4695 | |||
4696 | spin_unlock_irqrestore(&ide_lock, flags); | ||
4697 | DRIVER(drive)->busy = 0; | ||
4698 | (void) ide_unregister_subdriver(drive); | ||
4699 | |||
4700 | ide_unregister_region(tape->disk); | ||
4701 | |||
4702 | ide_tape_put(tape); | ||
4703 | |||
4704 | return 0; | ||
4705 | } | ||
4706 | |||
4707 | static void ide_tape_release(struct kref *kref) | ||
4708 | { | ||
4709 | struct ide_tape_obj *tape = to_ide_tape(kref); | ||
4710 | ide_drive_t *drive = tape->drive; | ||
4711 | struct gendisk *g = tape->disk; | ||
4712 | |||
4713 | drive->dsc_overlap = 0; | ||
4714 | drive->driver_data = NULL; | ||
4715 | devfs_remove("%s/mt", drive->devfs_name); | ||
4716 | devfs_remove("%s/mtn", drive->devfs_name); | ||
4717 | devfs_unregister_tape(g->number); | ||
4718 | idetape_devs[tape->minor] = NULL; | ||
4719 | g->private_data = NULL; | ||
4720 | put_disk(g); | ||
4721 | kfree(tape); | ||
4722 | } | ||
4723 | |||
4724 | #ifdef CONFIG_PROC_FS | ||
4725 | |||
4726 | static int proc_idetape_read_name | ||
4727 | (char *page, char **start, off_t off, int count, int *eof, void *data) | ||
4728 | { | ||
4729 | ide_drive_t *drive = (ide_drive_t *) data; | ||
4730 | idetape_tape_t *tape = drive->driver_data; | ||
4731 | char *out = page; | ||
4732 | int len; | ||
4733 | |||
4734 | len = sprintf(out, "%s\n", tape->name); | ||
4735 | PROC_IDE_READ_RETURN(page, start, off, count, eof, len); | ||
4736 | } | ||
4737 | |||
4738 | static ide_proc_entry_t idetape_proc[] = { | ||
4739 | { "capacity", S_IFREG|S_IRUGO, proc_ide_read_capacity, NULL }, | ||
4740 | { "name", S_IFREG|S_IRUGO, proc_idetape_read_name, NULL }, | ||
4741 | { NULL, 0, NULL, NULL } | ||
4742 | }; | ||
4743 | |||
4744 | #else | ||
4745 | |||
4746 | #define idetape_proc NULL | ||
4747 | |||
4748 | #endif | ||
4749 | |||
4750 | static int idetape_attach(ide_drive_t *drive); | ||
4751 | |||
4752 | /* | ||
4753 | * IDE subdriver functions, registered with ide.c | ||
4754 | */ | ||
4755 | static ide_driver_t idetape_driver = { | ||
4756 | .owner = THIS_MODULE, | ||
4757 | .name = "ide-tape", | ||
4758 | .version = IDETAPE_VERSION, | ||
4759 | .media = ide_tape, | ||
4760 | .busy = 1, | ||
4761 | .supports_dsc_overlap = 1, | ||
4762 | .cleanup = idetape_cleanup, | ||
4763 | .do_request = idetape_do_request, | ||
4764 | .end_request = idetape_end_request, | ||
4765 | .error = __ide_error, | ||
4766 | .abort = __ide_abort, | ||
4767 | .proc = idetape_proc, | ||
4768 | .attach = idetape_attach, | ||
4769 | .drives = LIST_HEAD_INIT(idetape_driver.drives), | ||
4770 | }; | ||
4771 | |||
4772 | /* | ||
4773 | * Our character device supporting functions, passed to register_chrdev. | ||
4774 | */ | ||
4775 | static struct file_operations idetape_fops = { | ||
4776 | .owner = THIS_MODULE, | ||
4777 | .read = idetape_chrdev_read, | ||
4778 | .write = idetape_chrdev_write, | ||
4779 | .ioctl = idetape_chrdev_ioctl, | ||
4780 | .open = idetape_chrdev_open, | ||
4781 | .release = idetape_chrdev_release, | ||
4782 | }; | ||
4783 | |||
4784 | static int idetape_open(struct inode *inode, struct file *filp) | ||
4785 | { | ||
4786 | struct gendisk *disk = inode->i_bdev->bd_disk; | ||
4787 | struct ide_tape_obj *tape; | ||
4788 | ide_drive_t *drive; | ||
4789 | |||
4790 | if (!(tape = ide_tape_get(disk))) | ||
4791 | return -ENXIO; | ||
4792 | |||
4793 | drive = tape->drive; | ||
4794 | |||
4795 | drive->usage++; | ||
4796 | |||
4797 | return 0; | ||
4798 | } | ||
4799 | |||
4800 | static int idetape_release(struct inode *inode, struct file *filp) | ||
4801 | { | ||
4802 | struct gendisk *disk = inode->i_bdev->bd_disk; | ||
4803 | struct ide_tape_obj *tape = ide_tape_g(disk); | ||
4804 | ide_drive_t *drive = tape->drive; | ||
4805 | |||
4806 | drive->usage--; | ||
4807 | |||
4808 | ide_tape_put(tape); | ||
4809 | |||
4810 | return 0; | ||
4811 | } | ||
4812 | |||
4813 | static int idetape_ioctl(struct inode *inode, struct file *file, | ||
4814 | unsigned int cmd, unsigned long arg) | ||
4815 | { | ||
4816 | struct block_device *bdev = inode->i_bdev; | ||
4817 | struct ide_tape_obj *tape = ide_tape_g(bdev->bd_disk); | ||
4818 | ide_drive_t *drive = tape->drive; | ||
4819 | int err = generic_ide_ioctl(drive, file, bdev, cmd, arg); | ||
4820 | if (err == -EINVAL) | ||
4821 | err = idetape_blkdev_ioctl(drive, cmd, arg); | ||
4822 | return err; | ||
4823 | } | ||
4824 | |||
4825 | static struct block_device_operations idetape_block_ops = { | ||
4826 | .owner = THIS_MODULE, | ||
4827 | .open = idetape_open, | ||
4828 | .release = idetape_release, | ||
4829 | .ioctl = idetape_ioctl, | ||
4830 | }; | ||
4831 | |||
4832 | static int idetape_attach (ide_drive_t *drive) | ||
4833 | { | ||
4834 | idetape_tape_t *tape; | ||
4835 | struct gendisk *g; | ||
4836 | int minor; | ||
4837 | |||
4838 | if (!strstr("ide-tape", drive->driver_req)) | ||
4839 | goto failed; | ||
4840 | if (!drive->present) | ||
4841 | goto failed; | ||
4842 | if (drive->media != ide_tape) | ||
4843 | goto failed; | ||
4844 | if (!idetape_identify_device (drive)) { | ||
4845 | printk(KERN_ERR "ide-tape: %s: not supported by this version of ide-tape\n", drive->name); | ||
4846 | goto failed; | ||
4847 | } | ||
4848 | if (drive->scsi) { | ||
4849 | printk("ide-tape: passing drive %s to ide-scsi emulation.\n", drive->name); | ||
4850 | goto failed; | ||
4851 | } | ||
4852 | if (strstr(drive->id->model, "OnStream DI-")) { | ||
4853 | printk(KERN_WARNING "ide-tape: Use drive %s with ide-scsi emulation and osst.\n", drive->name); | ||
4854 | printk(KERN_WARNING "ide-tape: OnStream support will be removed soon from ide-tape!\n"); | ||
4855 | } | ||
4856 | tape = (idetape_tape_t *) kmalloc (sizeof (idetape_tape_t), GFP_KERNEL); | ||
4857 | if (tape == NULL) { | ||
4858 | printk(KERN_ERR "ide-tape: %s: Can't allocate a tape structure\n", drive->name); | ||
4859 | goto failed; | ||
4860 | } | ||
4861 | |||
4862 | g = alloc_disk(1 << PARTN_BITS); | ||
4863 | if (!g) | ||
4864 | goto out_free_tape; | ||
4865 | |||
4866 | ide_init_disk(g, drive); | ||
4867 | |||
4868 | if (ide_register_subdriver(drive, &idetape_driver)) { | ||
4869 | printk(KERN_ERR "ide-tape: %s: Failed to register the driver with ide.c\n", drive->name); | ||
4870 | goto out_put_disk; | ||
4871 | } | ||
4872 | |||
4873 | memset(tape, 0, sizeof(*tape)); | ||
4874 | |||
4875 | kref_init(&tape->kref); | ||
4876 | |||
4877 | tape->drive = drive; | ||
4878 | tape->driver = &idetape_driver; | ||
4879 | tape->disk = g; | ||
4880 | |||
4881 | g->private_data = &tape->driver; | ||
4882 | |||
4883 | drive->driver_data = tape; | ||
4884 | |||
4885 | down(&idetape_ref_sem); | ||
4886 | for (minor = 0; idetape_devs[minor]; minor++) | ||
4887 | ; | ||
4888 | idetape_devs[minor] = tape; | ||
4889 | up(&idetape_ref_sem); | ||
4890 | |||
4891 | idetape_setup(drive, tape, minor); | ||
4892 | |||
4893 | devfs_mk_cdev(MKDEV(HWIF(drive)->major, minor), | ||
4894 | S_IFCHR | S_IRUGO | S_IWUGO, | ||
4895 | "%s/mt", drive->devfs_name); | ||
4896 | devfs_mk_cdev(MKDEV(HWIF(drive)->major, minor + 128), | ||
4897 | S_IFCHR | S_IRUGO | S_IWUGO, | ||
4898 | "%s/mtn", drive->devfs_name); | ||
4899 | |||
4900 | g->number = devfs_register_tape(drive->devfs_name); | ||
4901 | g->fops = &idetape_block_ops; | ||
4902 | ide_register_region(g); | ||
4903 | |||
4904 | return 0; | ||
4905 | out_put_disk: | ||
4906 | put_disk(g); | ||
4907 | out_free_tape: | ||
4908 | kfree(tape); | ||
4909 | failed: | ||
4910 | return 1; | ||
4911 | } | ||
4912 | |||
4913 | MODULE_DESCRIPTION("ATAPI Streaming TAPE Driver"); | ||
4914 | MODULE_LICENSE("GPL"); | ||
4915 | |||
4916 | static void __exit idetape_exit (void) | ||
4917 | { | ||
4918 | ide_unregister_driver(&idetape_driver); | ||
4919 | unregister_chrdev(IDETAPE_MAJOR, "ht"); | ||
4920 | } | ||
4921 | |||
4922 | /* | ||
4923 | * idetape_init will register the driver for each tape. | ||
4924 | */ | ||
4925 | static int idetape_init (void) | ||
4926 | { | ||
4927 | if (register_chrdev(IDETAPE_MAJOR, "ht", &idetape_fops)) { | ||
4928 | printk(KERN_ERR "ide-tape: Failed to register character device interface\n"); | ||
4929 | return -EBUSY; | ||
4930 | } | ||
4931 | ide_register_driver(&idetape_driver); | ||
4932 | return 0; | ||
4933 | } | ||
4934 | |||
4935 | module_init(idetape_init); | ||
4936 | module_exit(idetape_exit); | ||
4937 | MODULE_ALIAS_CHARDEV_MAJOR(IDETAPE_MAJOR); | ||
diff --git a/drivers/ide/ide-taskfile.c b/drivers/ide/ide-taskfile.c new file mode 100644 index 000000000000..d04f62ab5de1 --- /dev/null +++ b/drivers/ide/ide-taskfile.c | |||
@@ -0,0 +1,884 @@ | |||
1 | /* | ||
2 | * linux/drivers/ide/ide-taskfile.c Version 0.38 March 05, 2003 | ||
3 | * | ||
4 | * Copyright (C) 2000-2002 Michael Cornwell <cornwell@acm.org> | ||
5 | * Copyright (C) 2000-2002 Andre Hedrick <andre@linux-ide.org> | ||
6 | * Copyright (C) 2001-2002 Klaus Smolin | ||
7 | * IBM Storage Technology Division | ||
8 | * Copyright (C) 2003-2004 Bartlomiej Zolnierkiewicz | ||
9 | * | ||
10 | * The big the bad and the ugly. | ||
11 | * | ||
12 | * Problems to be fixed because of BH interface or the lack therefore. | ||
13 | * | ||
14 | * Fill me in stupid !!! | ||
15 | * | ||
16 | * HOST: | ||
17 | * General refers to the Controller and Driver "pair". | ||
18 | * DATA HANDLER: | ||
19 | * Under the context of Linux it generally refers to an interrupt handler. | ||
20 | * However, it correctly describes the 'HOST' | ||
21 | * DATA BLOCK: | ||
22 | * The amount of data needed to be transfered as predefined in the | ||
23 | * setup of the device. | ||
24 | * STORAGE ATOMIC: | ||
25 | * The 'DATA BLOCK' associated to the 'DATA HANDLER', and can be as | ||
26 | * small as a single sector or as large as the entire command block | ||
27 | * request. | ||
28 | */ | ||
29 | |||
30 | #include <linux/config.h> | ||
31 | #include <linux/module.h> | ||
32 | #include <linux/types.h> | ||
33 | #include <linux/string.h> | ||
34 | #include <linux/kernel.h> | ||
35 | #include <linux/timer.h> | ||
36 | #include <linux/mm.h> | ||
37 | #include <linux/interrupt.h> | ||
38 | #include <linux/major.h> | ||
39 | #include <linux/errno.h> | ||
40 | #include <linux/genhd.h> | ||
41 | #include <linux/blkpg.h> | ||
42 | #include <linux/slab.h> | ||
43 | #include <linux/pci.h> | ||
44 | #include <linux/delay.h> | ||
45 | #include <linux/hdreg.h> | ||
46 | #include <linux/ide.h> | ||
47 | #include <linux/bitops.h> | ||
48 | |||
49 | #include <asm/byteorder.h> | ||
50 | #include <asm/irq.h> | ||
51 | #include <asm/uaccess.h> | ||
52 | #include <asm/io.h> | ||
53 | |||
54 | #define DEBUG_TASKFILE 0 /* unset when fixed */ | ||
55 | |||
56 | static void ata_bswap_data (void *buffer, int wcount) | ||
57 | { | ||
58 | u16 *p = buffer; | ||
59 | |||
60 | while (wcount--) { | ||
61 | *p = *p << 8 | *p >> 8; p++; | ||
62 | *p = *p << 8 | *p >> 8; p++; | ||
63 | } | ||
64 | } | ||
65 | |||
66 | static void taskfile_input_data(ide_drive_t *drive, void *buffer, u32 wcount) | ||
67 | { | ||
68 | HWIF(drive)->ata_input_data(drive, buffer, wcount); | ||
69 | if (drive->bswap) | ||
70 | ata_bswap_data(buffer, wcount); | ||
71 | } | ||
72 | |||
73 | static void taskfile_output_data(ide_drive_t *drive, void *buffer, u32 wcount) | ||
74 | { | ||
75 | if (drive->bswap) { | ||
76 | ata_bswap_data(buffer, wcount); | ||
77 | HWIF(drive)->ata_output_data(drive, buffer, wcount); | ||
78 | ata_bswap_data(buffer, wcount); | ||
79 | } else { | ||
80 | HWIF(drive)->ata_output_data(drive, buffer, wcount); | ||
81 | } | ||
82 | } | ||
83 | |||
84 | int taskfile_lib_get_identify (ide_drive_t *drive, u8 *buf) | ||
85 | { | ||
86 | ide_task_t args; | ||
87 | memset(&args, 0, sizeof(ide_task_t)); | ||
88 | args.tfRegister[IDE_NSECTOR_OFFSET] = 0x01; | ||
89 | if (drive->media == ide_disk) | ||
90 | args.tfRegister[IDE_COMMAND_OFFSET] = WIN_IDENTIFY; | ||
91 | else | ||
92 | args.tfRegister[IDE_COMMAND_OFFSET] = WIN_PIDENTIFY; | ||
93 | args.command_type = IDE_DRIVE_TASK_IN; | ||
94 | args.data_phase = TASKFILE_IN; | ||
95 | args.handler = &task_in_intr; | ||
96 | return ide_raw_taskfile(drive, &args, buf); | ||
97 | } | ||
98 | |||
99 | ide_startstop_t do_rw_taskfile (ide_drive_t *drive, ide_task_t *task) | ||
100 | { | ||
101 | ide_hwif_t *hwif = HWIF(drive); | ||
102 | task_struct_t *taskfile = (task_struct_t *) task->tfRegister; | ||
103 | hob_struct_t *hobfile = (hob_struct_t *) task->hobRegister; | ||
104 | u8 HIHI = (drive->addressing == 1) ? 0xE0 : 0xEF; | ||
105 | |||
106 | /* ALL Command Block Executions SHALL clear nIEN, unless otherwise */ | ||
107 | if (IDE_CONTROL_REG) { | ||
108 | /* clear nIEN */ | ||
109 | hwif->OUTB(drive->ctl, IDE_CONTROL_REG); | ||
110 | } | ||
111 | SELECT_MASK(drive, 0); | ||
112 | |||
113 | if (drive->addressing == 1) { | ||
114 | hwif->OUTB(hobfile->feature, IDE_FEATURE_REG); | ||
115 | hwif->OUTB(hobfile->sector_count, IDE_NSECTOR_REG); | ||
116 | hwif->OUTB(hobfile->sector_number, IDE_SECTOR_REG); | ||
117 | hwif->OUTB(hobfile->low_cylinder, IDE_LCYL_REG); | ||
118 | hwif->OUTB(hobfile->high_cylinder, IDE_HCYL_REG); | ||
119 | } | ||
120 | |||
121 | hwif->OUTB(taskfile->feature, IDE_FEATURE_REG); | ||
122 | hwif->OUTB(taskfile->sector_count, IDE_NSECTOR_REG); | ||
123 | hwif->OUTB(taskfile->sector_number, IDE_SECTOR_REG); | ||
124 | hwif->OUTB(taskfile->low_cylinder, IDE_LCYL_REG); | ||
125 | hwif->OUTB(taskfile->high_cylinder, IDE_HCYL_REG); | ||
126 | |||
127 | hwif->OUTB((taskfile->device_head & HIHI) | drive->select.all, IDE_SELECT_REG); | ||
128 | |||
129 | if (task->handler != NULL) { | ||
130 | if (task->prehandler != NULL) { | ||
131 | hwif->OUTBSYNC(drive, taskfile->command, IDE_COMMAND_REG); | ||
132 | ndelay(400); /* FIXME */ | ||
133 | return task->prehandler(drive, task->rq); | ||
134 | } | ||
135 | ide_execute_command(drive, taskfile->command, task->handler, WAIT_WORSTCASE, NULL); | ||
136 | return ide_started; | ||
137 | } | ||
138 | |||
139 | if (!drive->using_dma) | ||
140 | return ide_stopped; | ||
141 | |||
142 | switch (taskfile->command) { | ||
143 | case WIN_WRITEDMA_ONCE: | ||
144 | case WIN_WRITEDMA: | ||
145 | case WIN_WRITEDMA_EXT: | ||
146 | case WIN_READDMA_ONCE: | ||
147 | case WIN_READDMA: | ||
148 | case WIN_READDMA_EXT: | ||
149 | case WIN_IDENTIFY_DMA: | ||
150 | if (!hwif->dma_setup(drive)) { | ||
151 | hwif->dma_exec_cmd(drive, taskfile->command); | ||
152 | hwif->dma_start(drive); | ||
153 | return ide_started; | ||
154 | } | ||
155 | break; | ||
156 | default: | ||
157 | if (task->handler == NULL) | ||
158 | return ide_stopped; | ||
159 | } | ||
160 | |||
161 | return ide_stopped; | ||
162 | } | ||
163 | |||
164 | EXPORT_SYMBOL(do_rw_taskfile); | ||
165 | |||
166 | /* | ||
167 | * set_multmode_intr() is invoked on completion of a WIN_SETMULT cmd. | ||
168 | */ | ||
169 | ide_startstop_t set_multmode_intr (ide_drive_t *drive) | ||
170 | { | ||
171 | ide_hwif_t *hwif = HWIF(drive); | ||
172 | u8 stat; | ||
173 | |||
174 | if (OK_STAT(stat = hwif->INB(IDE_STATUS_REG),READY_STAT,BAD_STAT)) { | ||
175 | drive->mult_count = drive->mult_req; | ||
176 | } else { | ||
177 | drive->mult_req = drive->mult_count = 0; | ||
178 | drive->special.b.recalibrate = 1; | ||
179 | (void) ide_dump_status(drive, "set_multmode", stat); | ||
180 | } | ||
181 | return ide_stopped; | ||
182 | } | ||
183 | |||
184 | /* | ||
185 | * set_geometry_intr() is invoked on completion of a WIN_SPECIFY cmd. | ||
186 | */ | ||
187 | ide_startstop_t set_geometry_intr (ide_drive_t *drive) | ||
188 | { | ||
189 | ide_hwif_t *hwif = HWIF(drive); | ||
190 | int retries = 5; | ||
191 | u8 stat; | ||
192 | |||
193 | while (((stat = hwif->INB(IDE_STATUS_REG)) & BUSY_STAT) && retries--) | ||
194 | udelay(10); | ||
195 | |||
196 | if (OK_STAT(stat, READY_STAT, BAD_STAT)) | ||
197 | return ide_stopped; | ||
198 | |||
199 | if (stat & (ERR_STAT|DRQ_STAT)) | ||
200 | return ide_error(drive, "set_geometry_intr", stat); | ||
201 | |||
202 | if (HWGROUP(drive)->handler != NULL) | ||
203 | BUG(); | ||
204 | ide_set_handler(drive, &set_geometry_intr, WAIT_WORSTCASE, NULL); | ||
205 | return ide_started; | ||
206 | } | ||
207 | |||
208 | /* | ||
209 | * recal_intr() is invoked on completion of a WIN_RESTORE (recalibrate) cmd. | ||
210 | */ | ||
211 | ide_startstop_t recal_intr (ide_drive_t *drive) | ||
212 | { | ||
213 | ide_hwif_t *hwif = HWIF(drive); | ||
214 | u8 stat; | ||
215 | |||
216 | if (!OK_STAT(stat = hwif->INB(IDE_STATUS_REG), READY_STAT, BAD_STAT)) | ||
217 | return ide_error(drive, "recal_intr", stat); | ||
218 | return ide_stopped; | ||
219 | } | ||
220 | |||
221 | /* | ||
222 | * Handler for commands without a data phase | ||
223 | */ | ||
224 | ide_startstop_t task_no_data_intr (ide_drive_t *drive) | ||
225 | { | ||
226 | ide_task_t *args = HWGROUP(drive)->rq->special; | ||
227 | ide_hwif_t *hwif = HWIF(drive); | ||
228 | u8 stat; | ||
229 | |||
230 | local_irq_enable(); | ||
231 | if (!OK_STAT(stat = hwif->INB(IDE_STATUS_REG),READY_STAT,BAD_STAT)) { | ||
232 | return ide_error(drive, "task_no_data_intr", stat); | ||
233 | /* calls ide_end_drive_cmd */ | ||
234 | } | ||
235 | if (args) | ||
236 | ide_end_drive_cmd(drive, stat, hwif->INB(IDE_ERROR_REG)); | ||
237 | |||
238 | return ide_stopped; | ||
239 | } | ||
240 | |||
241 | EXPORT_SYMBOL(task_no_data_intr); | ||
242 | |||
243 | static u8 wait_drive_not_busy(ide_drive_t *drive) | ||
244 | { | ||
245 | ide_hwif_t *hwif = HWIF(drive); | ||
246 | int retries = 100; | ||
247 | u8 stat; | ||
248 | |||
249 | /* | ||
250 | * Last sector was transfered, wait until drive is ready. | ||
251 | * This can take up to 10 usec, but we will wait max 1 ms | ||
252 | * (drive_cmd_intr() waits that long). | ||
253 | */ | ||
254 | while (((stat = hwif->INB(IDE_STATUS_REG)) & BUSY_STAT) && retries--) | ||
255 | udelay(10); | ||
256 | |||
257 | if (!retries) | ||
258 | printk(KERN_ERR "%s: drive still BUSY!\n", drive->name); | ||
259 | |||
260 | return stat; | ||
261 | } | ||
262 | |||
263 | static void ide_pio_sector(ide_drive_t *drive, unsigned int write) | ||
264 | { | ||
265 | ide_hwif_t *hwif = drive->hwif; | ||
266 | struct scatterlist *sg = hwif->sg_table; | ||
267 | struct page *page; | ||
268 | #ifdef CONFIG_HIGHMEM | ||
269 | unsigned long flags; | ||
270 | #endif | ||
271 | unsigned int offset; | ||
272 | u8 *buf; | ||
273 | |||
274 | page = sg[hwif->cursg].page; | ||
275 | offset = sg[hwif->cursg].offset + hwif->cursg_ofs * SECTOR_SIZE; | ||
276 | |||
277 | /* get the current page and offset */ | ||
278 | page = nth_page(page, (offset >> PAGE_SHIFT)); | ||
279 | offset %= PAGE_SIZE; | ||
280 | |||
281 | #ifdef CONFIG_HIGHMEM | ||
282 | local_irq_save(flags); | ||
283 | #endif | ||
284 | buf = kmap_atomic(page, KM_BIO_SRC_IRQ) + offset; | ||
285 | |||
286 | hwif->nleft--; | ||
287 | hwif->cursg_ofs++; | ||
288 | |||
289 | if ((hwif->cursg_ofs * SECTOR_SIZE) == sg[hwif->cursg].length) { | ||
290 | hwif->cursg++; | ||
291 | hwif->cursg_ofs = 0; | ||
292 | } | ||
293 | |||
294 | /* do the actual data transfer */ | ||
295 | if (write) | ||
296 | taskfile_output_data(drive, buf, SECTOR_WORDS); | ||
297 | else | ||
298 | taskfile_input_data(drive, buf, SECTOR_WORDS); | ||
299 | |||
300 | kunmap_atomic(buf, KM_BIO_SRC_IRQ); | ||
301 | #ifdef CONFIG_HIGHMEM | ||
302 | local_irq_restore(flags); | ||
303 | #endif | ||
304 | } | ||
305 | |||
306 | static void ide_pio_multi(ide_drive_t *drive, unsigned int write) | ||
307 | { | ||
308 | unsigned int nsect; | ||
309 | |||
310 | nsect = min_t(unsigned int, drive->hwif->nleft, drive->mult_count); | ||
311 | while (nsect--) | ||
312 | ide_pio_sector(drive, write); | ||
313 | } | ||
314 | |||
315 | static inline void ide_pio_datablock(ide_drive_t *drive, struct request *rq, | ||
316 | unsigned int write) | ||
317 | { | ||
318 | if (rq->bio) /* fs request */ | ||
319 | rq->errors = 0; | ||
320 | |||
321 | switch (drive->hwif->data_phase) { | ||
322 | case TASKFILE_MULTI_IN: | ||
323 | case TASKFILE_MULTI_OUT: | ||
324 | ide_pio_multi(drive, write); | ||
325 | break; | ||
326 | default: | ||
327 | ide_pio_sector(drive, write); | ||
328 | break; | ||
329 | } | ||
330 | } | ||
331 | |||
332 | static ide_startstop_t task_error(ide_drive_t *drive, struct request *rq, | ||
333 | const char *s, u8 stat) | ||
334 | { | ||
335 | if (rq->bio) { | ||
336 | ide_hwif_t *hwif = drive->hwif; | ||
337 | int sectors = hwif->nsect - hwif->nleft; | ||
338 | |||
339 | switch (hwif->data_phase) { | ||
340 | case TASKFILE_IN: | ||
341 | if (hwif->nleft) | ||
342 | break; | ||
343 | /* fall through */ | ||
344 | case TASKFILE_OUT: | ||
345 | sectors--; | ||
346 | break; | ||
347 | case TASKFILE_MULTI_IN: | ||
348 | if (hwif->nleft) | ||
349 | break; | ||
350 | /* fall through */ | ||
351 | case TASKFILE_MULTI_OUT: | ||
352 | sectors -= drive->mult_count; | ||
353 | default: | ||
354 | break; | ||
355 | } | ||
356 | |||
357 | if (sectors > 0) { | ||
358 | ide_driver_t *drv; | ||
359 | |||
360 | drv = *(ide_driver_t **)rq->rq_disk->private_data; | ||
361 | drv->end_request(drive, 1, sectors); | ||
362 | } | ||
363 | } | ||
364 | return ide_error(drive, s, stat); | ||
365 | } | ||
366 | |||
367 | static void task_end_request(ide_drive_t *drive, struct request *rq, u8 stat) | ||
368 | { | ||
369 | if (rq->flags & REQ_DRIVE_TASKFILE) { | ||
370 | ide_task_t *task = rq->special; | ||
371 | |||
372 | if (task->tf_out_flags.all) { | ||
373 | u8 err = drive->hwif->INB(IDE_ERROR_REG); | ||
374 | ide_end_drive_cmd(drive, stat, err); | ||
375 | return; | ||
376 | } | ||
377 | } | ||
378 | |||
379 | ide_end_request(drive, 1, rq->hard_nr_sectors); | ||
380 | } | ||
381 | |||
382 | /* | ||
383 | * Handler for command with PIO data-in phase (Read/Read Multiple). | ||
384 | */ | ||
385 | ide_startstop_t task_in_intr (ide_drive_t *drive) | ||
386 | { | ||
387 | ide_hwif_t *hwif = drive->hwif; | ||
388 | struct request *rq = HWGROUP(drive)->rq; | ||
389 | u8 stat = hwif->INB(IDE_STATUS_REG); | ||
390 | |||
391 | /* new way for dealing with premature shared PCI interrupts */ | ||
392 | if (!OK_STAT(stat, DATA_READY, BAD_R_STAT)) { | ||
393 | if (stat & (ERR_STAT | DRQ_STAT)) | ||
394 | return task_error(drive, rq, __FUNCTION__, stat); | ||
395 | /* No data yet, so wait for another IRQ. */ | ||
396 | ide_set_handler(drive, &task_in_intr, WAIT_WORSTCASE, NULL); | ||
397 | return ide_started; | ||
398 | } | ||
399 | |||
400 | ide_pio_datablock(drive, rq, 0); | ||
401 | |||
402 | /* If it was the last datablock check status and finish transfer. */ | ||
403 | if (!hwif->nleft) { | ||
404 | stat = wait_drive_not_busy(drive); | ||
405 | if (!OK_STAT(stat, 0, BAD_R_STAT)) | ||
406 | return task_error(drive, rq, __FUNCTION__, stat); | ||
407 | task_end_request(drive, rq, stat); | ||
408 | return ide_stopped; | ||
409 | } | ||
410 | |||
411 | /* Still data left to transfer. */ | ||
412 | ide_set_handler(drive, &task_in_intr, WAIT_WORSTCASE, NULL); | ||
413 | |||
414 | return ide_started; | ||
415 | } | ||
416 | EXPORT_SYMBOL(task_in_intr); | ||
417 | |||
418 | /* | ||
419 | * Handler for command with PIO data-out phase (Write/Write Multiple). | ||
420 | */ | ||
421 | static ide_startstop_t task_out_intr (ide_drive_t *drive) | ||
422 | { | ||
423 | ide_hwif_t *hwif = drive->hwif; | ||
424 | struct request *rq = HWGROUP(drive)->rq; | ||
425 | u8 stat = hwif->INB(IDE_STATUS_REG); | ||
426 | |||
427 | if (!OK_STAT(stat, DRIVE_READY, drive->bad_wstat)) | ||
428 | return task_error(drive, rq, __FUNCTION__, stat); | ||
429 | |||
430 | /* Deal with unexpected ATA data phase. */ | ||
431 | if (((stat & DRQ_STAT) == 0) ^ !hwif->nleft) | ||
432 | return task_error(drive, rq, __FUNCTION__, stat); | ||
433 | |||
434 | if (!hwif->nleft) { | ||
435 | task_end_request(drive, rq, stat); | ||
436 | return ide_stopped; | ||
437 | } | ||
438 | |||
439 | /* Still data left to transfer. */ | ||
440 | ide_pio_datablock(drive, rq, 1); | ||
441 | ide_set_handler(drive, &task_out_intr, WAIT_WORSTCASE, NULL); | ||
442 | |||
443 | return ide_started; | ||
444 | } | ||
445 | |||
446 | ide_startstop_t pre_task_out_intr (ide_drive_t *drive, struct request *rq) | ||
447 | { | ||
448 | ide_startstop_t startstop; | ||
449 | |||
450 | if (ide_wait_stat(&startstop, drive, DATA_READY, | ||
451 | drive->bad_wstat, WAIT_DRQ)) { | ||
452 | printk(KERN_ERR "%s: no DRQ after issuing %sWRITE%s\n", | ||
453 | drive->name, | ||
454 | drive->hwif->data_phase ? "MULT" : "", | ||
455 | drive->addressing ? "_EXT" : ""); | ||
456 | return startstop; | ||
457 | } | ||
458 | |||
459 | if (!drive->unmask) | ||
460 | local_irq_disable(); | ||
461 | |||
462 | ide_set_handler(drive, &task_out_intr, WAIT_WORSTCASE, NULL); | ||
463 | ide_pio_datablock(drive, rq, 1); | ||
464 | |||
465 | return ide_started; | ||
466 | } | ||
467 | EXPORT_SYMBOL(pre_task_out_intr); | ||
468 | |||
469 | static int ide_diag_taskfile(ide_drive_t *drive, ide_task_t *args, unsigned long data_size, u8 *buf) | ||
470 | { | ||
471 | struct request rq; | ||
472 | |||
473 | memset(&rq, 0, sizeof(rq)); | ||
474 | rq.flags = REQ_DRIVE_TASKFILE; | ||
475 | rq.buffer = buf; | ||
476 | |||
477 | /* | ||
478 | * (ks) We transfer currently only whole sectors. | ||
479 | * This is suffient for now. But, it would be great, | ||
480 | * if we would find a solution to transfer any size. | ||
481 | * To support special commands like READ LONG. | ||
482 | */ | ||
483 | if (args->command_type != IDE_DRIVE_TASK_NO_DATA) { | ||
484 | if (data_size == 0) | ||
485 | rq.nr_sectors = (args->hobRegister[IDE_NSECTOR_OFFSET] << 8) | args->tfRegister[IDE_NSECTOR_OFFSET]; | ||
486 | else | ||
487 | rq.nr_sectors = data_size / SECTOR_SIZE; | ||
488 | |||
489 | if (!rq.nr_sectors) { | ||
490 | printk(KERN_ERR "%s: in/out command without data\n", | ||
491 | drive->name); | ||
492 | return -EFAULT; | ||
493 | } | ||
494 | |||
495 | rq.hard_nr_sectors = rq.nr_sectors; | ||
496 | rq.hard_cur_sectors = rq.current_nr_sectors = rq.nr_sectors; | ||
497 | |||
498 | if (args->command_type == IDE_DRIVE_TASK_RAW_WRITE) | ||
499 | rq.flags |= REQ_RW; | ||
500 | } | ||
501 | |||
502 | rq.special = args; | ||
503 | return ide_do_drive_cmd(drive, &rq, ide_wait); | ||
504 | } | ||
505 | |||
506 | int ide_raw_taskfile (ide_drive_t *drive, ide_task_t *args, u8 *buf) | ||
507 | { | ||
508 | return ide_diag_taskfile(drive, args, 0, buf); | ||
509 | } | ||
510 | |||
511 | EXPORT_SYMBOL(ide_raw_taskfile); | ||
512 | |||
513 | int ide_taskfile_ioctl (ide_drive_t *drive, unsigned int cmd, unsigned long arg) | ||
514 | { | ||
515 | ide_task_request_t *req_task; | ||
516 | ide_task_t args; | ||
517 | u8 *outbuf = NULL; | ||
518 | u8 *inbuf = NULL; | ||
519 | task_ioreg_t *argsptr = args.tfRegister; | ||
520 | task_ioreg_t *hobsptr = args.hobRegister; | ||
521 | int err = 0; | ||
522 | int tasksize = sizeof(struct ide_task_request_s); | ||
523 | int taskin = 0; | ||
524 | int taskout = 0; | ||
525 | u8 io_32bit = drive->io_32bit; | ||
526 | char __user *buf = (char __user *)arg; | ||
527 | |||
528 | // printk("IDE Taskfile ...\n"); | ||
529 | |||
530 | req_task = kmalloc(tasksize, GFP_KERNEL); | ||
531 | if (req_task == NULL) return -ENOMEM; | ||
532 | memset(req_task, 0, tasksize); | ||
533 | if (copy_from_user(req_task, buf, tasksize)) { | ||
534 | kfree(req_task); | ||
535 | return -EFAULT; | ||
536 | } | ||
537 | |||
538 | taskout = (int) req_task->out_size; | ||
539 | taskin = (int) req_task->in_size; | ||
540 | |||
541 | if (taskout) { | ||
542 | int outtotal = tasksize; | ||
543 | outbuf = kmalloc(taskout, GFP_KERNEL); | ||
544 | if (outbuf == NULL) { | ||
545 | err = -ENOMEM; | ||
546 | goto abort; | ||
547 | } | ||
548 | memset(outbuf, 0, taskout); | ||
549 | if (copy_from_user(outbuf, buf + outtotal, taskout)) { | ||
550 | err = -EFAULT; | ||
551 | goto abort; | ||
552 | } | ||
553 | } | ||
554 | |||
555 | if (taskin) { | ||
556 | int intotal = tasksize + taskout; | ||
557 | inbuf = kmalloc(taskin, GFP_KERNEL); | ||
558 | if (inbuf == NULL) { | ||
559 | err = -ENOMEM; | ||
560 | goto abort; | ||
561 | } | ||
562 | memset(inbuf, 0, taskin); | ||
563 | if (copy_from_user(inbuf, buf + intotal, taskin)) { | ||
564 | err = -EFAULT; | ||
565 | goto abort; | ||
566 | } | ||
567 | } | ||
568 | |||
569 | memset(&args, 0, sizeof(ide_task_t)); | ||
570 | memcpy(argsptr, req_task->io_ports, HDIO_DRIVE_TASK_HDR_SIZE); | ||
571 | memcpy(hobsptr, req_task->hob_ports, HDIO_DRIVE_HOB_HDR_SIZE); | ||
572 | |||
573 | args.tf_in_flags = req_task->in_flags; | ||
574 | args.tf_out_flags = req_task->out_flags; | ||
575 | args.data_phase = req_task->data_phase; | ||
576 | args.command_type = req_task->req_cmd; | ||
577 | |||
578 | drive->io_32bit = 0; | ||
579 | switch(req_task->data_phase) { | ||
580 | case TASKFILE_OUT_DMAQ: | ||
581 | case TASKFILE_OUT_DMA: | ||
582 | err = ide_diag_taskfile(drive, &args, taskout, outbuf); | ||
583 | break; | ||
584 | case TASKFILE_IN_DMAQ: | ||
585 | case TASKFILE_IN_DMA: | ||
586 | err = ide_diag_taskfile(drive, &args, taskin, inbuf); | ||
587 | break; | ||
588 | case TASKFILE_MULTI_OUT: | ||
589 | if (!drive->mult_count) { | ||
590 | /* (hs): give up if multcount is not set */ | ||
591 | printk(KERN_ERR "%s: %s Multimode Write " \ | ||
592 | "multcount is not set\n", | ||
593 | drive->name, __FUNCTION__); | ||
594 | err = -EPERM; | ||
595 | goto abort; | ||
596 | } | ||
597 | /* fall through */ | ||
598 | case TASKFILE_OUT: | ||
599 | args.prehandler = &pre_task_out_intr; | ||
600 | args.handler = &task_out_intr; | ||
601 | err = ide_diag_taskfile(drive, &args, taskout, outbuf); | ||
602 | break; | ||
603 | case TASKFILE_MULTI_IN: | ||
604 | if (!drive->mult_count) { | ||
605 | /* (hs): give up if multcount is not set */ | ||
606 | printk(KERN_ERR "%s: %s Multimode Read failure " \ | ||
607 | "multcount is not set\n", | ||
608 | drive->name, __FUNCTION__); | ||
609 | err = -EPERM; | ||
610 | goto abort; | ||
611 | } | ||
612 | /* fall through */ | ||
613 | case TASKFILE_IN: | ||
614 | args.handler = &task_in_intr; | ||
615 | err = ide_diag_taskfile(drive, &args, taskin, inbuf); | ||
616 | break; | ||
617 | case TASKFILE_NO_DATA: | ||
618 | args.handler = &task_no_data_intr; | ||
619 | err = ide_diag_taskfile(drive, &args, 0, NULL); | ||
620 | break; | ||
621 | default: | ||
622 | err = -EFAULT; | ||
623 | goto abort; | ||
624 | } | ||
625 | |||
626 | memcpy(req_task->io_ports, &(args.tfRegister), HDIO_DRIVE_TASK_HDR_SIZE); | ||
627 | memcpy(req_task->hob_ports, &(args.hobRegister), HDIO_DRIVE_HOB_HDR_SIZE); | ||
628 | req_task->in_flags = args.tf_in_flags; | ||
629 | req_task->out_flags = args.tf_out_flags; | ||
630 | |||
631 | if (copy_to_user(buf, req_task, tasksize)) { | ||
632 | err = -EFAULT; | ||
633 | goto abort; | ||
634 | } | ||
635 | if (taskout) { | ||
636 | int outtotal = tasksize; | ||
637 | if (copy_to_user(buf + outtotal, outbuf, taskout)) { | ||
638 | err = -EFAULT; | ||
639 | goto abort; | ||
640 | } | ||
641 | } | ||
642 | if (taskin) { | ||
643 | int intotal = tasksize + taskout; | ||
644 | if (copy_to_user(buf + intotal, inbuf, taskin)) { | ||
645 | err = -EFAULT; | ||
646 | goto abort; | ||
647 | } | ||
648 | } | ||
649 | abort: | ||
650 | kfree(req_task); | ||
651 | if (outbuf != NULL) | ||
652 | kfree(outbuf); | ||
653 | if (inbuf != NULL) | ||
654 | kfree(inbuf); | ||
655 | |||
656 | // printk("IDE Taskfile ioctl ended. rc = %i\n", err); | ||
657 | |||
658 | drive->io_32bit = io_32bit; | ||
659 | |||
660 | return err; | ||
661 | } | ||
662 | |||
663 | int ide_wait_cmd (ide_drive_t *drive, u8 cmd, u8 nsect, u8 feature, u8 sectors, u8 *buf) | ||
664 | { | ||
665 | struct request rq; | ||
666 | u8 buffer[4]; | ||
667 | |||
668 | if (!buf) | ||
669 | buf = buffer; | ||
670 | memset(buf, 0, 4 + SECTOR_WORDS * 4 * sectors); | ||
671 | ide_init_drive_cmd(&rq); | ||
672 | rq.buffer = buf; | ||
673 | *buf++ = cmd; | ||
674 | *buf++ = nsect; | ||
675 | *buf++ = feature; | ||
676 | *buf++ = sectors; | ||
677 | return ide_do_drive_cmd(drive, &rq, ide_wait); | ||
678 | } | ||
679 | |||
680 | /* | ||
681 | * FIXME : this needs to map into at taskfile. <andre@linux-ide.org> | ||
682 | */ | ||
683 | int ide_cmd_ioctl (ide_drive_t *drive, unsigned int cmd, unsigned long arg) | ||
684 | { | ||
685 | int err = 0; | ||
686 | u8 args[4], *argbuf = args; | ||
687 | u8 xfer_rate = 0; | ||
688 | int argsize = 4; | ||
689 | ide_task_t tfargs; | ||
690 | |||
691 | if (NULL == (void *) arg) { | ||
692 | struct request rq; | ||
693 | ide_init_drive_cmd(&rq); | ||
694 | return ide_do_drive_cmd(drive, &rq, ide_wait); | ||
695 | } | ||
696 | |||
697 | if (copy_from_user(args, (void __user *)arg, 4)) | ||
698 | return -EFAULT; | ||
699 | |||
700 | memset(&tfargs, 0, sizeof(ide_task_t)); | ||
701 | tfargs.tfRegister[IDE_FEATURE_OFFSET] = args[2]; | ||
702 | tfargs.tfRegister[IDE_NSECTOR_OFFSET] = args[3]; | ||
703 | tfargs.tfRegister[IDE_SECTOR_OFFSET] = args[1]; | ||
704 | tfargs.tfRegister[IDE_LCYL_OFFSET] = 0x00; | ||
705 | tfargs.tfRegister[IDE_HCYL_OFFSET] = 0x00; | ||
706 | tfargs.tfRegister[IDE_SELECT_OFFSET] = 0x00; | ||
707 | tfargs.tfRegister[IDE_COMMAND_OFFSET] = args[0]; | ||
708 | |||
709 | if (args[3]) { | ||
710 | argsize = 4 + (SECTOR_WORDS * 4 * args[3]); | ||
711 | argbuf = kmalloc(argsize, GFP_KERNEL); | ||
712 | if (argbuf == NULL) | ||
713 | return -ENOMEM; | ||
714 | memcpy(argbuf, args, 4); | ||
715 | } | ||
716 | if (set_transfer(drive, &tfargs)) { | ||
717 | xfer_rate = args[1]; | ||
718 | if (ide_ata66_check(drive, &tfargs)) | ||
719 | goto abort; | ||
720 | } | ||
721 | |||
722 | err = ide_wait_cmd(drive, args[0], args[1], args[2], args[3], argbuf); | ||
723 | |||
724 | if (!err && xfer_rate) { | ||
725 | /* active-retuning-calls future */ | ||
726 | ide_set_xfer_rate(drive, xfer_rate); | ||
727 | ide_driveid_update(drive); | ||
728 | } | ||
729 | abort: | ||
730 | if (copy_to_user((void __user *)arg, argbuf, argsize)) | ||
731 | err = -EFAULT; | ||
732 | if (argsize > 4) | ||
733 | kfree(argbuf); | ||
734 | return err; | ||
735 | } | ||
736 | |||
737 | static int ide_wait_cmd_task(ide_drive_t *drive, u8 *buf) | ||
738 | { | ||
739 | struct request rq; | ||
740 | |||
741 | ide_init_drive_cmd(&rq); | ||
742 | rq.flags = REQ_DRIVE_TASK; | ||
743 | rq.buffer = buf; | ||
744 | return ide_do_drive_cmd(drive, &rq, ide_wait); | ||
745 | } | ||
746 | |||
747 | /* | ||
748 | * FIXME : this needs to map into at taskfile. <andre@linux-ide.org> | ||
749 | */ | ||
750 | int ide_task_ioctl (ide_drive_t *drive, unsigned int cmd, unsigned long arg) | ||
751 | { | ||
752 | void __user *p = (void __user *)arg; | ||
753 | int err = 0; | ||
754 | u8 args[7], *argbuf = args; | ||
755 | int argsize = 7; | ||
756 | |||
757 | if (copy_from_user(args, p, 7)) | ||
758 | return -EFAULT; | ||
759 | err = ide_wait_cmd_task(drive, argbuf); | ||
760 | if (copy_to_user(p, argbuf, argsize)) | ||
761 | err = -EFAULT; | ||
762 | return err; | ||
763 | } | ||
764 | |||
765 | /* | ||
766 | * NOTICE: This is additions from IBM to provide a discrete interface, | ||
767 | * for selective taskregister access operations. Nice JOB Klaus!!! | ||
768 | * Glad to be able to work and co-develop this with you and IBM. | ||
769 | */ | ||
770 | ide_startstop_t flagged_taskfile (ide_drive_t *drive, ide_task_t *task) | ||
771 | { | ||
772 | ide_hwif_t *hwif = HWIF(drive); | ||
773 | task_struct_t *taskfile = (task_struct_t *) task->tfRegister; | ||
774 | hob_struct_t *hobfile = (hob_struct_t *) task->hobRegister; | ||
775 | #if DEBUG_TASKFILE | ||
776 | u8 status; | ||
777 | #endif | ||
778 | |||
779 | if (task->data_phase == TASKFILE_MULTI_IN || | ||
780 | task->data_phase == TASKFILE_MULTI_OUT) { | ||
781 | if (!drive->mult_count) { | ||
782 | printk(KERN_ERR "%s: multimode not set!\n", drive->name); | ||
783 | return ide_stopped; | ||
784 | } | ||
785 | } | ||
786 | |||
787 | /* | ||
788 | * (ks) Check taskfile in/out flags. | ||
789 | * If set, then execute as it is defined. | ||
790 | * If not set, then define default settings. | ||
791 | * The default values are: | ||
792 | * write and read all taskfile registers (except data) | ||
793 | * write and read the hob registers (sector,nsector,lcyl,hcyl) | ||
794 | */ | ||
795 | if (task->tf_out_flags.all == 0) { | ||
796 | task->tf_out_flags.all = IDE_TASKFILE_STD_OUT_FLAGS; | ||
797 | if (drive->addressing == 1) | ||
798 | task->tf_out_flags.all |= (IDE_HOB_STD_OUT_FLAGS << 8); | ||
799 | } | ||
800 | |||
801 | if (task->tf_in_flags.all == 0) { | ||
802 | task->tf_in_flags.all = IDE_TASKFILE_STD_IN_FLAGS; | ||
803 | if (drive->addressing == 1) | ||
804 | task->tf_in_flags.all |= (IDE_HOB_STD_IN_FLAGS << 8); | ||
805 | } | ||
806 | |||
807 | /* ALL Command Block Executions SHALL clear nIEN, unless otherwise */ | ||
808 | if (IDE_CONTROL_REG) | ||
809 | /* clear nIEN */ | ||
810 | hwif->OUTB(drive->ctl, IDE_CONTROL_REG); | ||
811 | SELECT_MASK(drive, 0); | ||
812 | |||
813 | #if DEBUG_TASKFILE | ||
814 | status = hwif->INB(IDE_STATUS_REG); | ||
815 | if (status & 0x80) { | ||
816 | printk("flagged_taskfile -> Bad status. Status = %02x. wait 100 usec ...\n", status); | ||
817 | udelay(100); | ||
818 | status = hwif->INB(IDE_STATUS_REG); | ||
819 | printk("flagged_taskfile -> Status = %02x\n", status); | ||
820 | } | ||
821 | #endif | ||
822 | |||
823 | if (task->tf_out_flags.b.data) { | ||
824 | u16 data = taskfile->data + (hobfile->data << 8); | ||
825 | hwif->OUTW(data, IDE_DATA_REG); | ||
826 | } | ||
827 | |||
828 | /* (ks) send hob registers first */ | ||
829 | if (task->tf_out_flags.b.nsector_hob) | ||
830 | hwif->OUTB(hobfile->sector_count, IDE_NSECTOR_REG); | ||
831 | if (task->tf_out_flags.b.sector_hob) | ||
832 | hwif->OUTB(hobfile->sector_number, IDE_SECTOR_REG); | ||
833 | if (task->tf_out_flags.b.lcyl_hob) | ||
834 | hwif->OUTB(hobfile->low_cylinder, IDE_LCYL_REG); | ||
835 | if (task->tf_out_flags.b.hcyl_hob) | ||
836 | hwif->OUTB(hobfile->high_cylinder, IDE_HCYL_REG); | ||
837 | |||
838 | /* (ks) Send now the standard registers */ | ||
839 | if (task->tf_out_flags.b.error_feature) | ||
840 | hwif->OUTB(taskfile->feature, IDE_FEATURE_REG); | ||
841 | /* refers to number of sectors to transfer */ | ||
842 | if (task->tf_out_flags.b.nsector) | ||
843 | hwif->OUTB(taskfile->sector_count, IDE_NSECTOR_REG); | ||
844 | /* refers to sector offset or start sector */ | ||
845 | if (task->tf_out_flags.b.sector) | ||
846 | hwif->OUTB(taskfile->sector_number, IDE_SECTOR_REG); | ||
847 | if (task->tf_out_flags.b.lcyl) | ||
848 | hwif->OUTB(taskfile->low_cylinder, IDE_LCYL_REG); | ||
849 | if (task->tf_out_flags.b.hcyl) | ||
850 | hwif->OUTB(taskfile->high_cylinder, IDE_HCYL_REG); | ||
851 | |||
852 | /* | ||
853 | * (ks) In the flagged taskfile approch, we will use all specified | ||
854 | * registers and the register value will not be changed, except the | ||
855 | * select bit (master/slave) in the drive_head register. We must make | ||
856 | * sure that the desired drive is selected. | ||
857 | */ | ||
858 | hwif->OUTB(taskfile->device_head | drive->select.all, IDE_SELECT_REG); | ||
859 | switch(task->data_phase) { | ||
860 | |||
861 | case TASKFILE_OUT_DMAQ: | ||
862 | case TASKFILE_OUT_DMA: | ||
863 | case TASKFILE_IN_DMAQ: | ||
864 | case TASKFILE_IN_DMA: | ||
865 | hwif->dma_setup(drive); | ||
866 | hwif->dma_exec_cmd(drive, taskfile->command); | ||
867 | hwif->dma_start(drive); | ||
868 | break; | ||
869 | |||
870 | default: | ||
871 | if (task->handler == NULL) | ||
872 | return ide_stopped; | ||
873 | |||
874 | /* Issue the command */ | ||
875 | if (task->prehandler) { | ||
876 | hwif->OUTBSYNC(drive, taskfile->command, IDE_COMMAND_REG); | ||
877 | ndelay(400); /* FIXME */ | ||
878 | return task->prehandler(drive, task->rq); | ||
879 | } | ||
880 | ide_execute_command(drive, taskfile->command, task->handler, WAIT_WORSTCASE, NULL); | ||
881 | } | ||
882 | |||
883 | return ide_started; | ||
884 | } | ||
diff --git a/drivers/ide/ide-timing.h b/drivers/ide/ide-timing.h new file mode 100644 index 000000000000..c1196ce15b4d --- /dev/null +++ b/drivers/ide/ide-timing.h | |||
@@ -0,0 +1,281 @@ | |||
1 | #ifndef _IDE_TIMING_H | ||
2 | #define _IDE_TIMING_H | ||
3 | |||
4 | /* | ||
5 | * $Id: ide-timing.h,v 1.6 2001/12/23 22:47:56 vojtech Exp $ | ||
6 | * | ||
7 | * Copyright (c) 1999-2001 Vojtech Pavlik | ||
8 | */ | ||
9 | |||
10 | /* | ||
11 | * This program is free software; you can redistribute it and/or modify | ||
12 | * it under the terms of the GNU General Public License as published by | ||
13 | * the Free Software Foundation; either version 2 of the License, or | ||
14 | * (at your option) any later version. | ||
15 | * | ||
16 | * This program is distributed in the hope that it will be useful, | ||
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
19 | * GNU General Public License for more details. | ||
20 | * | ||
21 | * You should have received a copy of the GNU General Public License | ||
22 | * along with this program; if not, write to the Free Software | ||
23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
24 | * | ||
25 | * Should you need to contact me, the author, you can do so either by | ||
26 | * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail: | ||
27 | * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic | ||
28 | */ | ||
29 | |||
30 | #include <linux/hdreg.h> | ||
31 | |||
32 | #define XFER_PIO_5 0x0d | ||
33 | #define XFER_UDMA_SLOW 0x4f | ||
34 | |||
35 | struct ide_timing { | ||
36 | short mode; | ||
37 | short setup; /* t1 */ | ||
38 | short act8b; /* t2 for 8-bit io */ | ||
39 | short rec8b; /* t2i for 8-bit io */ | ||
40 | short cyc8b; /* t0 for 8-bit io */ | ||
41 | short active; /* t2 or tD */ | ||
42 | short recover; /* t2i or tK */ | ||
43 | short cycle; /* t0 */ | ||
44 | short udma; /* t2CYCTYP/2 */ | ||
45 | }; | ||
46 | |||
47 | /* | ||
48 | * PIO 0-5, MWDMA 0-2 and UDMA 0-6 timings (in nanoseconds). | ||
49 | * These were taken from ATA/ATAPI-6 standard, rev 0a, except | ||
50 | * for PIO 5, which is a nonstandard extension and UDMA6, which | ||
51 | * is currently supported only by Maxtor drives. | ||
52 | */ | ||
53 | |||
54 | static struct ide_timing ide_timing[] = { | ||
55 | |||
56 | { XFER_UDMA_6, 0, 0, 0, 0, 0, 0, 0, 15 }, | ||
57 | { XFER_UDMA_5, 0, 0, 0, 0, 0, 0, 0, 20 }, | ||
58 | { XFER_UDMA_4, 0, 0, 0, 0, 0, 0, 0, 30 }, | ||
59 | { XFER_UDMA_3, 0, 0, 0, 0, 0, 0, 0, 45 }, | ||
60 | |||
61 | { XFER_UDMA_2, 0, 0, 0, 0, 0, 0, 0, 60 }, | ||
62 | { XFER_UDMA_1, 0, 0, 0, 0, 0, 0, 0, 80 }, | ||
63 | { XFER_UDMA_0, 0, 0, 0, 0, 0, 0, 0, 120 }, | ||
64 | |||
65 | { XFER_UDMA_SLOW, 0, 0, 0, 0, 0, 0, 0, 150 }, | ||
66 | |||
67 | { XFER_MW_DMA_2, 25, 0, 0, 0, 70, 25, 120, 0 }, | ||
68 | { XFER_MW_DMA_1, 45, 0, 0, 0, 80, 50, 150, 0 }, | ||
69 | { XFER_MW_DMA_0, 60, 0, 0, 0, 215, 215, 480, 0 }, | ||
70 | |||
71 | { XFER_SW_DMA_2, 60, 0, 0, 0, 120, 120, 240, 0 }, | ||
72 | { XFER_SW_DMA_1, 90, 0, 0, 0, 240, 240, 480, 0 }, | ||
73 | { XFER_SW_DMA_0, 120, 0, 0, 0, 480, 480, 960, 0 }, | ||
74 | |||
75 | { XFER_PIO_5, 20, 50, 30, 100, 50, 30, 100, 0 }, | ||
76 | { XFER_PIO_4, 25, 70, 25, 120, 70, 25, 120, 0 }, | ||
77 | { XFER_PIO_3, 30, 80, 70, 180, 80, 70, 180, 0 }, | ||
78 | |||
79 | { XFER_PIO_2, 30, 290, 40, 330, 100, 90, 240, 0 }, | ||
80 | { XFER_PIO_1, 50, 290, 93, 383, 125, 100, 383, 0 }, | ||
81 | { XFER_PIO_0, 70, 290, 240, 600, 165, 150, 600, 0 }, | ||
82 | |||
83 | { XFER_PIO_SLOW, 120, 290, 240, 960, 290, 240, 960, 0 }, | ||
84 | |||
85 | { -1 } | ||
86 | }; | ||
87 | |||
88 | #define IDE_TIMING_SETUP 0x01 | ||
89 | #define IDE_TIMING_ACT8B 0x02 | ||
90 | #define IDE_TIMING_REC8B 0x04 | ||
91 | #define IDE_TIMING_CYC8B 0x08 | ||
92 | #define IDE_TIMING_8BIT 0x0e | ||
93 | #define IDE_TIMING_ACTIVE 0x10 | ||
94 | #define IDE_TIMING_RECOVER 0x20 | ||
95 | #define IDE_TIMING_CYCLE 0x40 | ||
96 | #define IDE_TIMING_UDMA 0x80 | ||
97 | #define IDE_TIMING_ALL 0xff | ||
98 | |||
99 | #define MIN(a,b) ((a)<(b)?(a):(b)) | ||
100 | #define MAX(a,b) ((a)>(b)?(a):(b)) | ||
101 | #define FIT(v,min,max) MAX(MIN(v,max),min) | ||
102 | #define ENOUGH(v,unit) (((v)-1)/(unit)+1) | ||
103 | #define EZ(v,unit) ((v)?ENOUGH(v,unit):0) | ||
104 | |||
105 | #define XFER_MODE 0xf0 | ||
106 | #define XFER_UDMA_133 0x48 | ||
107 | #define XFER_UDMA_100 0x44 | ||
108 | #define XFER_UDMA_66 0x42 | ||
109 | #define XFER_UDMA 0x40 | ||
110 | #define XFER_MWDMA 0x20 | ||
111 | #define XFER_SWDMA 0x10 | ||
112 | #define XFER_EPIO 0x01 | ||
113 | #define XFER_PIO 0x00 | ||
114 | |||
115 | static short ide_find_best_mode(ide_drive_t *drive, int map) | ||
116 | { | ||
117 | struct hd_driveid *id = drive->id; | ||
118 | short best = 0; | ||
119 | |||
120 | if (!id) | ||
121 | return XFER_PIO_SLOW; | ||
122 | |||
123 | if ((map & XFER_UDMA) && (id->field_valid & 4)) { /* Want UDMA and UDMA bitmap valid */ | ||
124 | |||
125 | if ((map & XFER_UDMA_133) == XFER_UDMA_133) | ||
126 | if ((best = (id->dma_ultra & 0x0040) ? XFER_UDMA_6 : 0)) return best; | ||
127 | |||
128 | if ((map & XFER_UDMA_100) == XFER_UDMA_100) | ||
129 | if ((best = (id->dma_ultra & 0x0020) ? XFER_UDMA_5 : 0)) return best; | ||
130 | |||
131 | if ((map & XFER_UDMA_66) == XFER_UDMA_66) | ||
132 | if ((best = (id->dma_ultra & 0x0010) ? XFER_UDMA_4 : | ||
133 | (id->dma_ultra & 0x0008) ? XFER_UDMA_3 : 0)) return best; | ||
134 | |||
135 | if ((best = (id->dma_ultra & 0x0004) ? XFER_UDMA_2 : | ||
136 | (id->dma_ultra & 0x0002) ? XFER_UDMA_1 : | ||
137 | (id->dma_ultra & 0x0001) ? XFER_UDMA_0 : 0)) return best; | ||
138 | } | ||
139 | |||
140 | if ((map & XFER_MWDMA) && (id->field_valid & 2)) { /* Want MWDMA and drive has EIDE fields */ | ||
141 | |||
142 | if ((best = (id->dma_mword & 0x0004) ? XFER_MW_DMA_2 : | ||
143 | (id->dma_mword & 0x0002) ? XFER_MW_DMA_1 : | ||
144 | (id->dma_mword & 0x0001) ? XFER_MW_DMA_0 : 0)) return best; | ||
145 | } | ||
146 | |||
147 | if (map & XFER_SWDMA) { /* Want SWDMA */ | ||
148 | |||
149 | if (id->field_valid & 2) { /* EIDE SWDMA */ | ||
150 | |||
151 | if ((best = (id->dma_1word & 0x0004) ? XFER_SW_DMA_2 : | ||
152 | (id->dma_1word & 0x0002) ? XFER_SW_DMA_1 : | ||
153 | (id->dma_1word & 0x0001) ? XFER_SW_DMA_0 : 0)) return best; | ||
154 | } | ||
155 | |||
156 | if (id->capability & 1) { /* Pre-EIDE style SWDMA */ | ||
157 | |||
158 | if ((best = (id->tDMA == 2) ? XFER_SW_DMA_2 : | ||
159 | (id->tDMA == 1) ? XFER_SW_DMA_1 : | ||
160 | (id->tDMA == 0) ? XFER_SW_DMA_0 : 0)) return best; | ||
161 | } | ||
162 | } | ||
163 | |||
164 | |||
165 | if ((map & XFER_EPIO) && (id->field_valid & 2)) { /* EIDE PIO modes */ | ||
166 | |||
167 | if ((best = (drive->id->eide_pio_modes & 4) ? XFER_PIO_5 : | ||
168 | (drive->id->eide_pio_modes & 2) ? XFER_PIO_4 : | ||
169 | (drive->id->eide_pio_modes & 1) ? XFER_PIO_3 : 0)) return best; | ||
170 | } | ||
171 | |||
172 | return (drive->id->tPIO == 2) ? XFER_PIO_2 : | ||
173 | (drive->id->tPIO == 1) ? XFER_PIO_1 : | ||
174 | (drive->id->tPIO == 0) ? XFER_PIO_0 : XFER_PIO_SLOW; | ||
175 | } | ||
176 | |||
177 | static void ide_timing_quantize(struct ide_timing *t, struct ide_timing *q, int T, int UT) | ||
178 | { | ||
179 | q->setup = EZ(t->setup * 1000, T); | ||
180 | q->act8b = EZ(t->act8b * 1000, T); | ||
181 | q->rec8b = EZ(t->rec8b * 1000, T); | ||
182 | q->cyc8b = EZ(t->cyc8b * 1000, T); | ||
183 | q->active = EZ(t->active * 1000, T); | ||
184 | q->recover = EZ(t->recover * 1000, T); | ||
185 | q->cycle = EZ(t->cycle * 1000, T); | ||
186 | q->udma = EZ(t->udma * 1000, UT); | ||
187 | } | ||
188 | |||
189 | static void ide_timing_merge(struct ide_timing *a, struct ide_timing *b, struct ide_timing *m, unsigned int what) | ||
190 | { | ||
191 | if (what & IDE_TIMING_SETUP ) m->setup = MAX(a->setup, b->setup); | ||
192 | if (what & IDE_TIMING_ACT8B ) m->act8b = MAX(a->act8b, b->act8b); | ||
193 | if (what & IDE_TIMING_REC8B ) m->rec8b = MAX(a->rec8b, b->rec8b); | ||
194 | if (what & IDE_TIMING_CYC8B ) m->cyc8b = MAX(a->cyc8b, b->cyc8b); | ||
195 | if (what & IDE_TIMING_ACTIVE ) m->active = MAX(a->active, b->active); | ||
196 | if (what & IDE_TIMING_RECOVER) m->recover = MAX(a->recover, b->recover); | ||
197 | if (what & IDE_TIMING_CYCLE ) m->cycle = MAX(a->cycle, b->cycle); | ||
198 | if (what & IDE_TIMING_UDMA ) m->udma = MAX(a->udma, b->udma); | ||
199 | } | ||
200 | |||
201 | static struct ide_timing* ide_timing_find_mode(short speed) | ||
202 | { | ||
203 | struct ide_timing *t; | ||
204 | |||
205 | for (t = ide_timing; t->mode != speed; t++) | ||
206 | if (t->mode < 0) | ||
207 | return NULL; | ||
208 | return t; | ||
209 | } | ||
210 | |||
211 | static int ide_timing_compute(ide_drive_t *drive, short speed, struct ide_timing *t, int T, int UT) | ||
212 | { | ||
213 | struct hd_driveid *id = drive->id; | ||
214 | struct ide_timing *s, p; | ||
215 | |||
216 | /* | ||
217 | * Find the mode. | ||
218 | */ | ||
219 | |||
220 | if (!(s = ide_timing_find_mode(speed))) | ||
221 | return -EINVAL; | ||
222 | |||
223 | /* | ||
224 | * If the drive is an EIDE drive, it can tell us it needs extended | ||
225 | * PIO/MWDMA cycle timing. | ||
226 | */ | ||
227 | |||
228 | if (id && id->field_valid & 2) { /* EIDE drive */ | ||
229 | |||
230 | memset(&p, 0, sizeof(p)); | ||
231 | |||
232 | switch (speed & XFER_MODE) { | ||
233 | |||
234 | case XFER_PIO: | ||
235 | if (speed <= XFER_PIO_2) p.cycle = p.cyc8b = id->eide_pio; | ||
236 | else p.cycle = p.cyc8b = id->eide_pio_iordy; | ||
237 | break; | ||
238 | |||
239 | case XFER_MWDMA: | ||
240 | p.cycle = id->eide_dma_min; | ||
241 | break; | ||
242 | } | ||
243 | |||
244 | ide_timing_merge(&p, t, t, IDE_TIMING_CYCLE | IDE_TIMING_CYC8B); | ||
245 | } | ||
246 | |||
247 | /* | ||
248 | * Convert the timing to bus clock counts. | ||
249 | */ | ||
250 | |||
251 | ide_timing_quantize(s, t, T, UT); | ||
252 | |||
253 | /* | ||
254 | * Even in DMA/UDMA modes we still use PIO access for IDENTIFY, S.M.A.R.T | ||
255 | * and some other commands. We have to ensure that the DMA cycle timing is | ||
256 | * slower/equal than the fastest PIO timing. | ||
257 | */ | ||
258 | |||
259 | if ((speed & XFER_MODE) != XFER_PIO) { | ||
260 | ide_timing_compute(drive, ide_find_best_mode(drive, XFER_PIO | XFER_EPIO), &p, T, UT); | ||
261 | ide_timing_merge(&p, t, t, IDE_TIMING_ALL); | ||
262 | } | ||
263 | |||
264 | /* | ||
265 | * Lenghten active & recovery time so that cycle time is correct. | ||
266 | */ | ||
267 | |||
268 | if (t->act8b + t->rec8b < t->cyc8b) { | ||
269 | t->act8b += (t->cyc8b - (t->act8b + t->rec8b)) / 2; | ||
270 | t->rec8b = t->cyc8b - t->act8b; | ||
271 | } | ||
272 | |||
273 | if (t->active + t->recover < t->cycle) { | ||
274 | t->active += (t->cycle - (t->active + t->recover)) / 2; | ||
275 | t->recover = t->cycle - t->active; | ||
276 | } | ||
277 | |||
278 | return 0; | ||
279 | } | ||
280 | |||
281 | #endif | ||
diff --git a/drivers/ide/ide.c b/drivers/ide/ide.c new file mode 100644 index 000000000000..973dec799b5c --- /dev/null +++ b/drivers/ide/ide.c | |||
@@ -0,0 +1,2269 @@ | |||
1 | /* | ||
2 | * linux/drivers/ide/ide.c Version 7.00beta2 Mar 05 2003 | ||
3 | * | ||
4 | * Copyright (C) 1994-1998 Linus Torvalds & authors (see below) | ||
5 | */ | ||
6 | |||
7 | /* | ||
8 | * Mostly written by Mark Lord <mlord@pobox.com> | ||
9 | * and Gadi Oxman <gadio@netvision.net.il> | ||
10 | * and Andre Hedrick <andre@linux-ide.org> | ||
11 | * | ||
12 | * See linux/MAINTAINERS for address of current maintainer. | ||
13 | * | ||
14 | * This is the multiple IDE interface driver, as evolved from hd.c. | ||
15 | * It supports up to MAX_HWIFS IDE interfaces, on one or more IRQs | ||
16 | * (usually 14 & 15). | ||
17 | * There can be up to two drives per interface, as per the ATA-2 spec. | ||
18 | * | ||
19 | * Primary: ide0, port 0x1f0; major=3; hda is minor=0; hdb is minor=64 | ||
20 | * Secondary: ide1, port 0x170; major=22; hdc is minor=0; hdd is minor=64 | ||
21 | * Tertiary: ide2, port 0x???; major=33; hde is minor=0; hdf is minor=64 | ||
22 | * Quaternary: ide3, port 0x???; major=34; hdg is minor=0; hdh is minor=64 | ||
23 | * ... | ||
24 | * | ||
25 | * From hd.c: | ||
26 | * | | ||
27 | * | It traverses the request-list, using interrupts to jump between functions. | ||
28 | * | As nearly all functions can be called within interrupts, we may not sleep. | ||
29 | * | Special care is recommended. Have Fun! | ||
30 | * | | ||
31 | * | modified by Drew Eckhardt to check nr of hd's from the CMOS. | ||
32 | * | | ||
33 | * | Thanks to Branko Lankester, lankeste@fwi.uva.nl, who found a bug | ||
34 | * | in the early extended-partition checks and added DM partitions. | ||
35 | * | | ||
36 | * | Early work on error handling by Mika Liljeberg (liljeber@cs.Helsinki.FI). | ||
37 | * | | ||
38 | * | IRQ-unmask, drive-id, multiple-mode, support for ">16 heads", | ||
39 | * | and general streamlining by Mark Lord (mlord@pobox.com). | ||
40 | * | ||
41 | * October, 1994 -- Complete line-by-line overhaul for linux 1.1.x, by: | ||
42 | * | ||
43 | * Mark Lord (mlord@pobox.com) (IDE Perf.Pkg) | ||
44 | * Delman Lee (delman@ieee.org) ("Mr. atdisk2") | ||
45 | * Scott Snyder (snyder@fnald0.fnal.gov) (ATAPI IDE cd-rom) | ||
46 | * | ||
47 | * This was a rewrite of just about everything from hd.c, though some original | ||
48 | * code is still sprinkled about. Think of it as a major evolution, with | ||
49 | * inspiration from lots of linux users, esp. hamish@zot.apana.org.au | ||
50 | * | ||
51 | * Version 1.0 ALPHA initial code, primary i/f working okay | ||
52 | * Version 1.3 BETA dual i/f on shared irq tested & working! | ||
53 | * Version 1.4 BETA added auto probing for irq(s) | ||
54 | * Version 1.5 BETA added ALPHA (untested) support for IDE cd-roms, | ||
55 | * ... | ||
56 | * Version 5.50 allow values as small as 20 for idebus= | ||
57 | * Version 5.51 force non io_32bit in drive_cmd_intr() | ||
58 | * change delay_10ms() to delay_50ms() to fix problems | ||
59 | * Version 5.52 fix incorrect invalidation of removable devices | ||
60 | * add "hdx=slow" command line option | ||
61 | * Version 5.60 start to modularize the driver; the disk and ATAPI | ||
62 | * drivers can be compiled as loadable modules. | ||
63 | * move IDE probe code to ide-probe.c | ||
64 | * move IDE disk code to ide-disk.c | ||
65 | * add support for generic IDE device subdrivers | ||
66 | * add m68k code from Geert Uytterhoeven | ||
67 | * probe all interfaces by default | ||
68 | * add ioctl to (re)probe an interface | ||
69 | * Version 6.00 use per device request queues | ||
70 | * attempt to optimize shared hwgroup performance | ||
71 | * add ioctl to manually adjust bandwidth algorithms | ||
72 | * add kerneld support for the probe module | ||
73 | * fix bug in ide_error() | ||
74 | * fix bug in the first ide_get_lock() call for Atari | ||
75 | * don't flush leftover data for ATAPI devices | ||
76 | * Version 6.01 clear hwgroup->active while the hwgroup sleeps | ||
77 | * support HDIO_GETGEO for floppies | ||
78 | * Version 6.02 fix ide_ack_intr() call | ||
79 | * check partition table on floppies | ||
80 | * Version 6.03 handle bad status bit sequencing in ide_wait_stat() | ||
81 | * Version 6.10 deleted old entries from this list of updates | ||
82 | * replaced triton.c with ide-dma.c generic PCI DMA | ||
83 | * added support for BIOS-enabled UltraDMA | ||
84 | * rename all "promise" things to "pdc4030" | ||
85 | * fix EZ-DRIVE handling on small disks | ||
86 | * Version 6.11 fix probe error in ide_scan_devices() | ||
87 | * fix ancient "jiffies" polling bugs | ||
88 | * mask all hwgroup interrupts on each irq entry | ||
89 | * Version 6.12 integrate ioctl and proc interfaces | ||
90 | * fix parsing of "idex=" command line parameter | ||
91 | * Version 6.13 add support for ide4/ide5 courtesy rjones@orchestream.com | ||
92 | * Version 6.14 fixed IRQ sharing among PCI devices | ||
93 | * Version 6.15 added SMP awareness to IDE drivers | ||
94 | * Version 6.16 fixed various bugs; even more SMP friendly | ||
95 | * Version 6.17 fix for newest EZ-Drive problem | ||
96 | * Version 6.18 default unpartitioned-disk translation now "BIOS LBA" | ||
97 | * Version 6.19 Re-design for a UNIFORM driver for all platforms, | ||
98 | * model based on suggestions from Russell King and | ||
99 | * Geert Uytterhoeven | ||
100 | * Promise DC4030VL now supported. | ||
101 | * add support for ide6/ide7 | ||
102 | * delay_50ms() changed to ide_delay_50ms() and exported. | ||
103 | * Version 6.20 Added/Fixed Generic ATA-66 support and hwif detection. | ||
104 | * Added hdx=flash to allow for second flash disk | ||
105 | * detection w/o the hang loop. | ||
106 | * Added support for ide8/ide9 | ||
107 | * Added idex=ata66 for the quirky chipsets that are | ||
108 | * ATA-66 compliant, but have yet to determine a method | ||
109 | * of verification of the 80c cable presence. | ||
110 | * Specifically Promise's PDC20262 chipset. | ||
111 | * Version 6.21 Fixing/Fixed SMP spinlock issue with insight from an old | ||
112 | * hat that clarified original low level driver design. | ||
113 | * Version 6.30 Added SMP support; fixed multmode issues. -ml | ||
114 | * Version 6.31 Debug Share INTR's and request queue streaming | ||
115 | * Native ATA-100 support | ||
116 | * Prep for Cascades Project | ||
117 | * Version 7.00alpha First named revision of ide rearrange | ||
118 | * | ||
119 | * Some additional driver compile-time options are in ./include/linux/ide.h | ||
120 | * | ||
121 | * To do, in likely order of completion: | ||
122 | * - modify kernel to obtain BIOS geometry for drives on 2nd/3rd/4th i/f | ||
123 | * | ||
124 | */ | ||
125 | |||
126 | #define REVISION "Revision: 7.00alpha2" | ||
127 | #define VERSION "Id: ide.c 7.00a2 20020906" | ||
128 | |||
129 | #undef REALLY_SLOW_IO /* most systems can safely undef this */ | ||
130 | |||
131 | #define _IDE_C /* Tell ide.h it's really us */ | ||
132 | |||
133 | #include <linux/config.h> | ||
134 | #include <linux/module.h> | ||
135 | #include <linux/types.h> | ||
136 | #include <linux/string.h> | ||
137 | #include <linux/kernel.h> | ||
138 | #include <linux/timer.h> | ||
139 | #include <linux/mm.h> | ||
140 | #include <linux/interrupt.h> | ||
141 | #include <linux/major.h> | ||
142 | #include <linux/errno.h> | ||
143 | #include <linux/genhd.h> | ||
144 | #include <linux/blkpg.h> | ||
145 | #include <linux/slab.h> | ||
146 | #include <linux/init.h> | ||
147 | #include <linux/pci.h> | ||
148 | #include <linux/delay.h> | ||
149 | #include <linux/ide.h> | ||
150 | #include <linux/devfs_fs_kernel.h> | ||
151 | #include <linux/completion.h> | ||
152 | #include <linux/reboot.h> | ||
153 | #include <linux/cdrom.h> | ||
154 | #include <linux/seq_file.h> | ||
155 | #include <linux/device.h> | ||
156 | #include <linux/bitops.h> | ||
157 | |||
158 | #include <asm/byteorder.h> | ||
159 | #include <asm/irq.h> | ||
160 | #include <asm/uaccess.h> | ||
161 | #include <asm/io.h> | ||
162 | |||
163 | |||
164 | /* default maximum number of failures */ | ||
165 | #define IDE_DEFAULT_MAX_FAILURES 1 | ||
166 | |||
167 | static const u8 ide_hwif_to_major[] = { IDE0_MAJOR, IDE1_MAJOR, | ||
168 | IDE2_MAJOR, IDE3_MAJOR, | ||
169 | IDE4_MAJOR, IDE5_MAJOR, | ||
170 | IDE6_MAJOR, IDE7_MAJOR, | ||
171 | IDE8_MAJOR, IDE9_MAJOR }; | ||
172 | |||
173 | static int idebus_parameter; /* holds the "idebus=" parameter */ | ||
174 | static int system_bus_speed; /* holds what we think is VESA/PCI bus speed */ | ||
175 | static int initializing; /* set while initializing built-in drivers */ | ||
176 | |||
177 | DECLARE_MUTEX(ide_cfg_sem); | ||
178 | __cacheline_aligned_in_smp DEFINE_SPINLOCK(ide_lock); | ||
179 | |||
180 | #ifdef CONFIG_BLK_DEV_IDEPCI | ||
181 | static int ide_scan_direction; /* THIS was formerly 2.2.x pci=reverse */ | ||
182 | #endif | ||
183 | |||
184 | #ifdef CONFIG_IDEDMA_AUTO | ||
185 | int noautodma = 0; | ||
186 | #else | ||
187 | int noautodma = 1; | ||
188 | #endif | ||
189 | |||
190 | EXPORT_SYMBOL(noautodma); | ||
191 | |||
192 | /* | ||
193 | * This is declared extern in ide.h, for access by other IDE modules: | ||
194 | */ | ||
195 | ide_hwif_t ide_hwifs[MAX_HWIFS]; /* master data repository */ | ||
196 | |||
197 | EXPORT_SYMBOL(ide_hwifs); | ||
198 | |||
199 | static struct list_head ide_drives = LIST_HEAD_INIT(ide_drives); | ||
200 | |||
201 | /* | ||
202 | * Do not even *think* about calling this! | ||
203 | */ | ||
204 | static void init_hwif_data(ide_hwif_t *hwif, unsigned int index) | ||
205 | { | ||
206 | unsigned int unit; | ||
207 | |||
208 | /* bulk initialize hwif & drive info with zeros */ | ||
209 | memset(hwif, 0, sizeof(ide_hwif_t)); | ||
210 | |||
211 | /* fill in any non-zero initial values */ | ||
212 | hwif->index = index; | ||
213 | hwif->major = ide_hwif_to_major[index]; | ||
214 | |||
215 | hwif->name[0] = 'i'; | ||
216 | hwif->name[1] = 'd'; | ||
217 | hwif->name[2] = 'e'; | ||
218 | hwif->name[3] = '0' + index; | ||
219 | |||
220 | hwif->bus_state = BUSSTATE_ON; | ||
221 | |||
222 | hwif->atapi_dma = 0; /* disable all atapi dma */ | ||
223 | hwif->ultra_mask = 0x80; /* disable all ultra */ | ||
224 | hwif->mwdma_mask = 0x80; /* disable all mwdma */ | ||
225 | hwif->swdma_mask = 0x80; /* disable all swdma */ | ||
226 | |||
227 | sema_init(&hwif->gendev_rel_sem, 0); | ||
228 | |||
229 | default_hwif_iops(hwif); | ||
230 | default_hwif_transport(hwif); | ||
231 | for (unit = 0; unit < MAX_DRIVES; ++unit) { | ||
232 | ide_drive_t *drive = &hwif->drives[unit]; | ||
233 | |||
234 | drive->media = ide_disk; | ||
235 | drive->select.all = (unit<<4)|0xa0; | ||
236 | drive->hwif = hwif; | ||
237 | drive->ctl = 0x08; | ||
238 | drive->ready_stat = READY_STAT; | ||
239 | drive->bad_wstat = BAD_W_STAT; | ||
240 | drive->special.b.recalibrate = 1; | ||
241 | drive->special.b.set_geometry = 1; | ||
242 | drive->name[0] = 'h'; | ||
243 | drive->name[1] = 'd'; | ||
244 | drive->name[2] = 'a' + (index * MAX_DRIVES) + unit; | ||
245 | drive->max_failures = IDE_DEFAULT_MAX_FAILURES; | ||
246 | drive->using_dma = 0; | ||
247 | drive->is_flash = 0; | ||
248 | drive->vdma = 0; | ||
249 | INIT_LIST_HEAD(&drive->list); | ||
250 | sema_init(&drive->gendev_rel_sem, 0); | ||
251 | } | ||
252 | } | ||
253 | |||
254 | static void init_hwif_default(ide_hwif_t *hwif, unsigned int index) | ||
255 | { | ||
256 | hw_regs_t hw; | ||
257 | |||
258 | memset(&hw, 0, sizeof(hw_regs_t)); | ||
259 | |||
260 | ide_init_hwif_ports(&hw, ide_default_io_base(index), 0, &hwif->irq); | ||
261 | |||
262 | memcpy(&hwif->hw, &hw, sizeof(hw)); | ||
263 | memcpy(hwif->io_ports, hw.io_ports, sizeof(hw.io_ports)); | ||
264 | |||
265 | hwif->noprobe = !hwif->io_ports[IDE_DATA_OFFSET]; | ||
266 | #ifdef CONFIG_BLK_DEV_HD | ||
267 | if (hwif->io_ports[IDE_DATA_OFFSET] == HD_DATA) | ||
268 | hwif->noprobe = 1; /* may be overridden by ide_setup() */ | ||
269 | #endif | ||
270 | } | ||
271 | |||
272 | extern void ide_arm_init(void); | ||
273 | |||
274 | /* | ||
275 | * init_ide_data() sets reasonable default values into all fields | ||
276 | * of all instances of the hwifs and drives, but only on the first call. | ||
277 | * Subsequent calls have no effect (they don't wipe out anything). | ||
278 | * | ||
279 | * This routine is normally called at driver initialization time, | ||
280 | * but may also be called MUCH earlier during kernel "command-line" | ||
281 | * parameter processing. As such, we cannot depend on any other parts | ||
282 | * of the kernel (such as memory allocation) to be functioning yet. | ||
283 | * | ||
284 | * This is too bad, as otherwise we could dynamically allocate the | ||
285 | * ide_drive_t structs as needed, rather than always consuming memory | ||
286 | * for the max possible number (MAX_HWIFS * MAX_DRIVES) of them. | ||
287 | * | ||
288 | * FIXME: We should stuff the setup data into __init and copy the | ||
289 | * relevant hwifs/allocate them properly during boot. | ||
290 | */ | ||
291 | #define MAGIC_COOKIE 0x12345678 | ||
292 | static void __init init_ide_data (void) | ||
293 | { | ||
294 | ide_hwif_t *hwif; | ||
295 | unsigned int index; | ||
296 | static unsigned long magic_cookie = MAGIC_COOKIE; | ||
297 | |||
298 | if (magic_cookie != MAGIC_COOKIE) | ||
299 | return; /* already initialized */ | ||
300 | magic_cookie = 0; | ||
301 | |||
302 | /* Initialise all interface structures */ | ||
303 | for (index = 0; index < MAX_HWIFS; ++index) { | ||
304 | hwif = &ide_hwifs[index]; | ||
305 | init_hwif_data(hwif, index); | ||
306 | init_hwif_default(hwif, index); | ||
307 | #if !defined(CONFIG_PPC32) || !defined(CONFIG_PCI) | ||
308 | hwif->irq = hwif->hw.irq = | ||
309 | ide_init_default_irq(hwif->io_ports[IDE_DATA_OFFSET]); | ||
310 | #endif | ||
311 | } | ||
312 | #ifdef CONFIG_IDE_ARM | ||
313 | initializing = 1; | ||
314 | ide_arm_init(); | ||
315 | initializing = 0; | ||
316 | #endif | ||
317 | } | ||
318 | |||
319 | /** | ||
320 | * ide_system_bus_speed - guess bus speed | ||
321 | * | ||
322 | * ide_system_bus_speed() returns what we think is the system VESA/PCI | ||
323 | * bus speed (in MHz). This is used for calculating interface PIO timings. | ||
324 | * The default is 40 for known PCI systems, 50 otherwise. | ||
325 | * The "idebus=xx" parameter can be used to override this value. | ||
326 | * The actual value to be used is computed/displayed the first time | ||
327 | * through. Drivers should only use this as a last resort. | ||
328 | * | ||
329 | * Returns a guessed speed in MHz. | ||
330 | */ | ||
331 | |||
332 | static int ide_system_bus_speed(void) | ||
333 | { | ||
334 | #ifdef CONFIG_PCI | ||
335 | static struct pci_device_id pci_default[] = { | ||
336 | { PCI_DEVICE(PCI_ANY_ID, PCI_ANY_ID) }, | ||
337 | { } | ||
338 | }; | ||
339 | #else | ||
340 | #define pci_default 0 | ||
341 | #endif /* CONFIG_PCI */ | ||
342 | |||
343 | if (!system_bus_speed) { | ||
344 | if (idebus_parameter) { | ||
345 | /* user supplied value */ | ||
346 | system_bus_speed = idebus_parameter; | ||
347 | } else if (pci_dev_present(pci_default)) { | ||
348 | /* safe default value for PCI */ | ||
349 | system_bus_speed = 33; | ||
350 | } else { | ||
351 | /* safe default value for VESA and PCI */ | ||
352 | system_bus_speed = 50; | ||
353 | } | ||
354 | printk(KERN_INFO "ide: Assuming %dMHz system bus speed " | ||
355 | "for PIO modes%s\n", system_bus_speed, | ||
356 | idebus_parameter ? "" : "; override with idebus=xx"); | ||
357 | } | ||
358 | return system_bus_speed; | ||
359 | } | ||
360 | |||
361 | /* | ||
362 | * drives_lock protects the list of drives, drivers_lock the | ||
363 | * list of drivers. Currently nobody takes both at once. | ||
364 | */ | ||
365 | |||
366 | static DEFINE_SPINLOCK(drives_lock); | ||
367 | static DEFINE_SPINLOCK(drivers_lock); | ||
368 | static LIST_HEAD(drivers); | ||
369 | |||
370 | /* Iterator for the driver list. */ | ||
371 | |||
372 | static void *m_start(struct seq_file *m, loff_t *pos) | ||
373 | { | ||
374 | struct list_head *p; | ||
375 | loff_t l = *pos; | ||
376 | spin_lock(&drivers_lock); | ||
377 | list_for_each(p, &drivers) | ||
378 | if (!l--) | ||
379 | return list_entry(p, ide_driver_t, drivers); | ||
380 | return NULL; | ||
381 | } | ||
382 | |||
383 | static void *m_next(struct seq_file *m, void *v, loff_t *pos) | ||
384 | { | ||
385 | struct list_head *p = ((ide_driver_t *)v)->drivers.next; | ||
386 | (*pos)++; | ||
387 | return p==&drivers ? NULL : list_entry(p, ide_driver_t, drivers); | ||
388 | } | ||
389 | |||
390 | static void m_stop(struct seq_file *m, void *v) | ||
391 | { | ||
392 | spin_unlock(&drivers_lock); | ||
393 | } | ||
394 | |||
395 | static int show_driver(struct seq_file *m, void *v) | ||
396 | { | ||
397 | ide_driver_t *driver = v; | ||
398 | seq_printf(m, "%s version %s\n", driver->name, driver->version); | ||
399 | return 0; | ||
400 | } | ||
401 | |||
402 | struct seq_operations ide_drivers_op = { | ||
403 | .start = m_start, | ||
404 | .next = m_next, | ||
405 | .stop = m_stop, | ||
406 | .show = show_driver | ||
407 | }; | ||
408 | |||
409 | #ifdef CONFIG_PROC_FS | ||
410 | struct proc_dir_entry *proc_ide_root; | ||
411 | #endif | ||
412 | |||
413 | static struct resource* hwif_request_region(ide_hwif_t *hwif, | ||
414 | unsigned long addr, int num) | ||
415 | { | ||
416 | struct resource *res = request_region(addr, num, hwif->name); | ||
417 | |||
418 | if (!res) | ||
419 | printk(KERN_ERR "%s: I/O resource 0x%lX-0x%lX not free.\n", | ||
420 | hwif->name, addr, addr+num-1); | ||
421 | return res; | ||
422 | } | ||
423 | |||
424 | /** | ||
425 | * ide_hwif_request_regions - request resources for IDE | ||
426 | * @hwif: interface to use | ||
427 | * | ||
428 | * Requests all the needed resources for an interface. | ||
429 | * Right now core IDE code does this work which is deeply wrong. | ||
430 | * MMIO leaves it to the controller driver, | ||
431 | * PIO will migrate this way over time. | ||
432 | */ | ||
433 | |||
434 | int ide_hwif_request_regions(ide_hwif_t *hwif) | ||
435 | { | ||
436 | unsigned long addr; | ||
437 | unsigned int i; | ||
438 | |||
439 | if (hwif->mmio == 2) | ||
440 | return 0; | ||
441 | BUG_ON(hwif->mmio == 1); | ||
442 | addr = hwif->io_ports[IDE_CONTROL_OFFSET]; | ||
443 | if (addr && !hwif_request_region(hwif, addr, 1)) | ||
444 | goto control_region_busy; | ||
445 | hwif->straight8 = 0; | ||
446 | addr = hwif->io_ports[IDE_DATA_OFFSET]; | ||
447 | if ((addr | 7) == hwif->io_ports[IDE_STATUS_OFFSET]) { | ||
448 | if (!hwif_request_region(hwif, addr, 8)) | ||
449 | goto data_region_busy; | ||
450 | hwif->straight8 = 1; | ||
451 | return 0; | ||
452 | } | ||
453 | for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++) { | ||
454 | addr = hwif->io_ports[i]; | ||
455 | if (!hwif_request_region(hwif, addr, 1)) { | ||
456 | while (--i) | ||
457 | release_region(addr, 1); | ||
458 | goto data_region_busy; | ||
459 | } | ||
460 | } | ||
461 | return 0; | ||
462 | |||
463 | data_region_busy: | ||
464 | addr = hwif->io_ports[IDE_CONTROL_OFFSET]; | ||
465 | if (addr) | ||
466 | release_region(addr, 1); | ||
467 | control_region_busy: | ||
468 | /* If any errors are return, we drop the hwif interface. */ | ||
469 | return -EBUSY; | ||
470 | } | ||
471 | |||
472 | /** | ||
473 | * ide_hwif_release_regions - free IDE resources | ||
474 | * | ||
475 | * Note that we only release the standard ports, | ||
476 | * and do not even try to handle any extra ports | ||
477 | * allocated for weird IDE interface chipsets. | ||
478 | * | ||
479 | * Note also that we don't yet handle mmio resources here. More | ||
480 | * importantly our caller should be doing this so we need to | ||
481 | * restructure this as a helper function for drivers. | ||
482 | */ | ||
483 | |||
484 | void ide_hwif_release_regions(ide_hwif_t *hwif) | ||
485 | { | ||
486 | u32 i = 0; | ||
487 | |||
488 | if (hwif->mmio == 2) | ||
489 | return; | ||
490 | if (hwif->io_ports[IDE_CONTROL_OFFSET]) | ||
491 | release_region(hwif->io_ports[IDE_CONTROL_OFFSET], 1); | ||
492 | if (hwif->straight8) { | ||
493 | release_region(hwif->io_ports[IDE_DATA_OFFSET], 8); | ||
494 | return; | ||
495 | } | ||
496 | for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++) | ||
497 | if (hwif->io_ports[i]) | ||
498 | release_region(hwif->io_ports[i], 1); | ||
499 | } | ||
500 | |||
501 | /** | ||
502 | * ide_hwif_restore - restore hwif to template | ||
503 | * @hwif: hwif to update | ||
504 | * @tmp_hwif: template | ||
505 | * | ||
506 | * Restore hwif to a previous state by copying most settngs | ||
507 | * from the template. | ||
508 | */ | ||
509 | |||
510 | static void ide_hwif_restore(ide_hwif_t *hwif, ide_hwif_t *tmp_hwif) | ||
511 | { | ||
512 | hwif->hwgroup = tmp_hwif->hwgroup; | ||
513 | |||
514 | hwif->gendev.parent = tmp_hwif->gendev.parent; | ||
515 | |||
516 | hwif->proc = tmp_hwif->proc; | ||
517 | |||
518 | hwif->major = tmp_hwif->major; | ||
519 | hwif->straight8 = tmp_hwif->straight8; | ||
520 | hwif->bus_state = tmp_hwif->bus_state; | ||
521 | |||
522 | hwif->atapi_dma = tmp_hwif->atapi_dma; | ||
523 | hwif->ultra_mask = tmp_hwif->ultra_mask; | ||
524 | hwif->mwdma_mask = tmp_hwif->mwdma_mask; | ||
525 | hwif->swdma_mask = tmp_hwif->swdma_mask; | ||
526 | |||
527 | hwif->chipset = tmp_hwif->chipset; | ||
528 | hwif->hold = tmp_hwif->hold; | ||
529 | |||
530 | #ifdef CONFIG_BLK_DEV_IDEPCI | ||
531 | hwif->pci_dev = tmp_hwif->pci_dev; | ||
532 | hwif->cds = tmp_hwif->cds; | ||
533 | #endif | ||
534 | |||
535 | hwif->tuneproc = tmp_hwif->tuneproc; | ||
536 | hwif->speedproc = tmp_hwif->speedproc; | ||
537 | hwif->selectproc = tmp_hwif->selectproc; | ||
538 | hwif->reset_poll = tmp_hwif->reset_poll; | ||
539 | hwif->pre_reset = tmp_hwif->pre_reset; | ||
540 | hwif->resetproc = tmp_hwif->resetproc; | ||
541 | hwif->intrproc = tmp_hwif->intrproc; | ||
542 | hwif->maskproc = tmp_hwif->maskproc; | ||
543 | hwif->quirkproc = tmp_hwif->quirkproc; | ||
544 | hwif->busproc = tmp_hwif->busproc; | ||
545 | |||
546 | hwif->ata_input_data = tmp_hwif->ata_input_data; | ||
547 | hwif->ata_output_data = tmp_hwif->ata_output_data; | ||
548 | hwif->atapi_input_bytes = tmp_hwif->atapi_input_bytes; | ||
549 | hwif->atapi_output_bytes = tmp_hwif->atapi_output_bytes; | ||
550 | |||
551 | hwif->dma_setup = tmp_hwif->dma_setup; | ||
552 | hwif->dma_exec_cmd = tmp_hwif->dma_exec_cmd; | ||
553 | hwif->dma_start = tmp_hwif->dma_start; | ||
554 | hwif->ide_dma_end = tmp_hwif->ide_dma_end; | ||
555 | hwif->ide_dma_check = tmp_hwif->ide_dma_check; | ||
556 | hwif->ide_dma_on = tmp_hwif->ide_dma_on; | ||
557 | hwif->ide_dma_off_quietly = tmp_hwif->ide_dma_off_quietly; | ||
558 | hwif->ide_dma_test_irq = tmp_hwif->ide_dma_test_irq; | ||
559 | hwif->ide_dma_host_on = tmp_hwif->ide_dma_host_on; | ||
560 | hwif->ide_dma_host_off = tmp_hwif->ide_dma_host_off; | ||
561 | hwif->ide_dma_lostirq = tmp_hwif->ide_dma_lostirq; | ||
562 | hwif->ide_dma_timeout = tmp_hwif->ide_dma_timeout; | ||
563 | |||
564 | hwif->OUTB = tmp_hwif->OUTB; | ||
565 | hwif->OUTBSYNC = tmp_hwif->OUTBSYNC; | ||
566 | hwif->OUTW = tmp_hwif->OUTW; | ||
567 | hwif->OUTL = tmp_hwif->OUTL; | ||
568 | hwif->OUTSW = tmp_hwif->OUTSW; | ||
569 | hwif->OUTSL = tmp_hwif->OUTSL; | ||
570 | |||
571 | hwif->INB = tmp_hwif->INB; | ||
572 | hwif->INW = tmp_hwif->INW; | ||
573 | hwif->INL = tmp_hwif->INL; | ||
574 | hwif->INSW = tmp_hwif->INSW; | ||
575 | hwif->INSL = tmp_hwif->INSL; | ||
576 | |||
577 | hwif->sg_max_nents = tmp_hwif->sg_max_nents; | ||
578 | |||
579 | hwif->mmio = tmp_hwif->mmio; | ||
580 | hwif->rqsize = tmp_hwif->rqsize; | ||
581 | hwif->no_lba48 = tmp_hwif->no_lba48; | ||
582 | |||
583 | #ifndef CONFIG_BLK_DEV_IDECS | ||
584 | hwif->irq = tmp_hwif->irq; | ||
585 | #endif | ||
586 | |||
587 | hwif->dma_base = tmp_hwif->dma_base; | ||
588 | hwif->dma_master = tmp_hwif->dma_master; | ||
589 | hwif->dma_command = tmp_hwif->dma_command; | ||
590 | hwif->dma_vendor1 = tmp_hwif->dma_vendor1; | ||
591 | hwif->dma_status = tmp_hwif->dma_status; | ||
592 | hwif->dma_vendor3 = tmp_hwif->dma_vendor3; | ||
593 | hwif->dma_prdtable = tmp_hwif->dma_prdtable; | ||
594 | |||
595 | hwif->dma_extra = tmp_hwif->dma_extra; | ||
596 | hwif->config_data = tmp_hwif->config_data; | ||
597 | hwif->select_data = tmp_hwif->select_data; | ||
598 | hwif->autodma = tmp_hwif->autodma; | ||
599 | hwif->udma_four = tmp_hwif->udma_four; | ||
600 | hwif->no_dsc = tmp_hwif->no_dsc; | ||
601 | |||
602 | hwif->hwif_data = tmp_hwif->hwif_data; | ||
603 | } | ||
604 | |||
605 | /** | ||
606 | * ide_unregister - free an ide interface | ||
607 | * @index: index of interface (will change soon to a pointer) | ||
608 | * | ||
609 | * Perform the final unregister of an IDE interface. At the moment | ||
610 | * we don't refcount interfaces so this will also get split up. | ||
611 | * | ||
612 | * Locking: | ||
613 | * The caller must not hold the IDE locks | ||
614 | * The drive present/vanishing is not yet properly locked | ||
615 | * Take care with the callbacks. These have been split to avoid | ||
616 | * deadlocking the IDE layer. The shutdown callback is called | ||
617 | * before we take the lock and free resources. It is up to the | ||
618 | * caller to be sure there is no pending I/O here, and that | ||
619 | * the interfce will not be reopened (present/vanishing locking | ||
620 | * isnt yet done btw). After we commit to the final kill we | ||
621 | * call the cleanup callback with the ide locks held. | ||
622 | * | ||
623 | * Unregister restores the hwif structures to the default state. | ||
624 | * This is raving bonkers. | ||
625 | */ | ||
626 | |||
627 | void ide_unregister(unsigned int index) | ||
628 | { | ||
629 | ide_drive_t *drive; | ||
630 | ide_hwif_t *hwif, *g; | ||
631 | static ide_hwif_t tmp_hwif; /* protected by ide_cfg_sem */ | ||
632 | ide_hwgroup_t *hwgroup; | ||
633 | int irq_count = 0, unit, i; | ||
634 | |||
635 | BUG_ON(index >= MAX_HWIFS); | ||
636 | |||
637 | BUG_ON(in_interrupt()); | ||
638 | BUG_ON(irqs_disabled()); | ||
639 | down(&ide_cfg_sem); | ||
640 | spin_lock_irq(&ide_lock); | ||
641 | hwif = &ide_hwifs[index]; | ||
642 | if (!hwif->present) | ||
643 | goto abort; | ||
644 | for (unit = 0; unit < MAX_DRIVES; ++unit) { | ||
645 | drive = &hwif->drives[unit]; | ||
646 | if (!drive->present) | ||
647 | continue; | ||
648 | if (drive->usage || DRIVER(drive)->busy) | ||
649 | goto abort; | ||
650 | drive->dead = 1; | ||
651 | } | ||
652 | hwif->present = 0; | ||
653 | |||
654 | spin_unlock_irq(&ide_lock); | ||
655 | |||
656 | for (unit = 0; unit < MAX_DRIVES; ++unit) { | ||
657 | drive = &hwif->drives[unit]; | ||
658 | if (!drive->present) | ||
659 | continue; | ||
660 | DRIVER(drive)->cleanup(drive); | ||
661 | } | ||
662 | |||
663 | destroy_proc_ide_interface(hwif); | ||
664 | |||
665 | hwgroup = hwif->hwgroup; | ||
666 | /* | ||
667 | * free the irq if we were the only hwif using it | ||
668 | */ | ||
669 | g = hwgroup->hwif; | ||
670 | do { | ||
671 | if (g->irq == hwif->irq) | ||
672 | ++irq_count; | ||
673 | g = g->next; | ||
674 | } while (g != hwgroup->hwif); | ||
675 | if (irq_count == 1) | ||
676 | free_irq(hwif->irq, hwgroup); | ||
677 | |||
678 | spin_lock_irq(&ide_lock); | ||
679 | /* | ||
680 | * Note that we only release the standard ports, | ||
681 | * and do not even try to handle any extra ports | ||
682 | * allocated for weird IDE interface chipsets. | ||
683 | */ | ||
684 | ide_hwif_release_regions(hwif); | ||
685 | |||
686 | /* | ||
687 | * Remove us from the hwgroup, and free | ||
688 | * the hwgroup if we were the only member | ||
689 | */ | ||
690 | for (i = 0; i < MAX_DRIVES; ++i) { | ||
691 | drive = &hwif->drives[i]; | ||
692 | if (drive->devfs_name[0] != '\0') { | ||
693 | devfs_remove(drive->devfs_name); | ||
694 | drive->devfs_name[0] = '\0'; | ||
695 | } | ||
696 | if (!drive->present) | ||
697 | continue; | ||
698 | if (drive == drive->next) { | ||
699 | /* special case: last drive from hwgroup. */ | ||
700 | BUG_ON(hwgroup->drive != drive); | ||
701 | hwgroup->drive = NULL; | ||
702 | } else { | ||
703 | ide_drive_t *walk; | ||
704 | |||
705 | walk = hwgroup->drive; | ||
706 | while (walk->next != drive) | ||
707 | walk = walk->next; | ||
708 | walk->next = drive->next; | ||
709 | if (hwgroup->drive == drive) { | ||
710 | hwgroup->drive = drive->next; | ||
711 | hwgroup->hwif = HWIF(hwgroup->drive); | ||
712 | } | ||
713 | } | ||
714 | BUG_ON(hwgroup->drive == drive); | ||
715 | if (drive->id != NULL) { | ||
716 | kfree(drive->id); | ||
717 | drive->id = NULL; | ||
718 | } | ||
719 | drive->present = 0; | ||
720 | /* Messed up locking ... */ | ||
721 | spin_unlock_irq(&ide_lock); | ||
722 | blk_cleanup_queue(drive->queue); | ||
723 | device_unregister(&drive->gendev); | ||
724 | down(&drive->gendev_rel_sem); | ||
725 | spin_lock_irq(&ide_lock); | ||
726 | drive->queue = NULL; | ||
727 | } | ||
728 | if (hwif->next == hwif) { | ||
729 | BUG_ON(hwgroup->hwif != hwif); | ||
730 | kfree(hwgroup); | ||
731 | } else { | ||
732 | /* There is another interface in hwgroup. | ||
733 | * Unlink us, and set hwgroup->drive and ->hwif to | ||
734 | * something sane. | ||
735 | */ | ||
736 | g = hwgroup->hwif; | ||
737 | while (g->next != hwif) | ||
738 | g = g->next; | ||
739 | g->next = hwif->next; | ||
740 | if (hwgroup->hwif == hwif) { | ||
741 | /* Chose a random hwif for hwgroup->hwif. | ||
742 | * It's guaranteed that there are no drives | ||
743 | * left in the hwgroup. | ||
744 | */ | ||
745 | BUG_ON(hwgroup->drive != NULL); | ||
746 | hwgroup->hwif = g; | ||
747 | } | ||
748 | BUG_ON(hwgroup->hwif == hwif); | ||
749 | } | ||
750 | |||
751 | /* More messed up locking ... */ | ||
752 | spin_unlock_irq(&ide_lock); | ||
753 | device_unregister(&hwif->gendev); | ||
754 | down(&hwif->gendev_rel_sem); | ||
755 | |||
756 | /* | ||
757 | * Remove us from the kernel's knowledge | ||
758 | */ | ||
759 | blk_unregister_region(MKDEV(hwif->major, 0), MAX_DRIVES<<PARTN_BITS); | ||
760 | kfree(hwif->sg_table); | ||
761 | unregister_blkdev(hwif->major, hwif->name); | ||
762 | spin_lock_irq(&ide_lock); | ||
763 | |||
764 | if (hwif->dma_base) { | ||
765 | (void) ide_release_dma(hwif); | ||
766 | |||
767 | hwif->dma_base = 0; | ||
768 | hwif->dma_master = 0; | ||
769 | hwif->dma_command = 0; | ||
770 | hwif->dma_vendor1 = 0; | ||
771 | hwif->dma_status = 0; | ||
772 | hwif->dma_vendor3 = 0; | ||
773 | hwif->dma_prdtable = 0; | ||
774 | } | ||
775 | |||
776 | /* copy original settings */ | ||
777 | tmp_hwif = *hwif; | ||
778 | |||
779 | /* restore hwif data to pristine status */ | ||
780 | init_hwif_data(hwif, index); | ||
781 | init_hwif_default(hwif, index); | ||
782 | |||
783 | ide_hwif_restore(hwif, &tmp_hwif); | ||
784 | |||
785 | abort: | ||
786 | spin_unlock_irq(&ide_lock); | ||
787 | up(&ide_cfg_sem); | ||
788 | } | ||
789 | |||
790 | EXPORT_SYMBOL(ide_unregister); | ||
791 | |||
792 | |||
793 | /** | ||
794 | * ide_setup_ports - set up IDE interface ports | ||
795 | * @hw: register descriptions | ||
796 | * @base: base register | ||
797 | * @offsets: table of register offsets | ||
798 | * @ctrl: control register | ||
799 | * @ack_irq: IRQ ack | ||
800 | * @irq: interrupt lie | ||
801 | * | ||
802 | * Setup hw_regs_t structure described by parameters. You | ||
803 | * may set up the hw structure yourself OR use this routine to | ||
804 | * do it for you. This is basically a helper | ||
805 | * | ||
806 | */ | ||
807 | |||
808 | void ide_setup_ports ( hw_regs_t *hw, | ||
809 | unsigned long base, int *offsets, | ||
810 | unsigned long ctrl, unsigned long intr, | ||
811 | ide_ack_intr_t *ack_intr, | ||
812 | /* | ||
813 | * ide_io_ops_t *iops, | ||
814 | */ | ||
815 | int irq) | ||
816 | { | ||
817 | int i; | ||
818 | |||
819 | for (i = 0; i < IDE_NR_PORTS; i++) { | ||
820 | if (offsets[i] == -1) { | ||
821 | switch(i) { | ||
822 | case IDE_CONTROL_OFFSET: | ||
823 | hw->io_ports[i] = ctrl; | ||
824 | break; | ||
825 | #if defined(CONFIG_AMIGA) || defined(CONFIG_MAC) | ||
826 | case IDE_IRQ_OFFSET: | ||
827 | hw->io_ports[i] = intr; | ||
828 | break; | ||
829 | #endif /* (CONFIG_AMIGA) || (CONFIG_MAC) */ | ||
830 | default: | ||
831 | hw->io_ports[i] = 0; | ||
832 | break; | ||
833 | } | ||
834 | } else { | ||
835 | hw->io_ports[i] = base + offsets[i]; | ||
836 | } | ||
837 | } | ||
838 | hw->irq = irq; | ||
839 | hw->dma = NO_DMA; | ||
840 | hw->ack_intr = ack_intr; | ||
841 | /* | ||
842 | * hw->iops = iops; | ||
843 | */ | ||
844 | } | ||
845 | |||
846 | /** | ||
847 | * ide_register_hw_with_fixup - register IDE interface | ||
848 | * @hw: hardware registers | ||
849 | * @hwifp: pointer to returned hwif | ||
850 | * @fixup: fixup function | ||
851 | * | ||
852 | * Register an IDE interface, specifying exactly the registers etc. | ||
853 | * Set init=1 iff calling before probes have taken place. | ||
854 | * | ||
855 | * Returns -1 on error. | ||
856 | */ | ||
857 | |||
858 | int ide_register_hw_with_fixup(hw_regs_t *hw, ide_hwif_t **hwifp, void(*fixup)(ide_hwif_t *hwif)) | ||
859 | { | ||
860 | int index, retry = 1; | ||
861 | ide_hwif_t *hwif; | ||
862 | |||
863 | do { | ||
864 | for (index = 0; index < MAX_HWIFS; ++index) { | ||
865 | hwif = &ide_hwifs[index]; | ||
866 | if (hwif->hw.io_ports[IDE_DATA_OFFSET] == hw->io_ports[IDE_DATA_OFFSET]) | ||
867 | goto found; | ||
868 | } | ||
869 | for (index = 0; index < MAX_HWIFS; ++index) { | ||
870 | hwif = &ide_hwifs[index]; | ||
871 | if (hwif->hold) | ||
872 | continue; | ||
873 | if ((!hwif->present && !hwif->mate && !initializing) || | ||
874 | (!hwif->hw.io_ports[IDE_DATA_OFFSET] && initializing)) | ||
875 | goto found; | ||
876 | } | ||
877 | for (index = 0; index < MAX_HWIFS; index++) | ||
878 | ide_unregister(index); | ||
879 | } while (retry--); | ||
880 | return -1; | ||
881 | found: | ||
882 | if (hwif->present) | ||
883 | ide_unregister(index); | ||
884 | else if (!hwif->hold) { | ||
885 | init_hwif_data(hwif, index); | ||
886 | init_hwif_default(hwif, index); | ||
887 | } | ||
888 | if (hwif->present) | ||
889 | return -1; | ||
890 | memcpy(&hwif->hw, hw, sizeof(*hw)); | ||
891 | memcpy(hwif->io_ports, hwif->hw.io_ports, sizeof(hwif->hw.io_ports)); | ||
892 | hwif->irq = hw->irq; | ||
893 | hwif->noprobe = 0; | ||
894 | hwif->chipset = hw->chipset; | ||
895 | |||
896 | if (!initializing) { | ||
897 | probe_hwif_init_with_fixup(hwif, fixup); | ||
898 | create_proc_ide_interfaces(); | ||
899 | } | ||
900 | |||
901 | if (hwifp) | ||
902 | *hwifp = hwif; | ||
903 | |||
904 | return (initializing || hwif->present) ? index : -1; | ||
905 | } | ||
906 | |||
907 | EXPORT_SYMBOL(ide_register_hw_with_fixup); | ||
908 | |||
909 | int ide_register_hw(hw_regs_t *hw, ide_hwif_t **hwifp) | ||
910 | { | ||
911 | return ide_register_hw_with_fixup(hw, hwifp, NULL); | ||
912 | } | ||
913 | |||
914 | EXPORT_SYMBOL(ide_register_hw); | ||
915 | |||
916 | /* | ||
917 | * Locks for IDE setting functionality | ||
918 | */ | ||
919 | |||
920 | DECLARE_MUTEX(ide_setting_sem); | ||
921 | |||
922 | /** | ||
923 | * __ide_add_setting - add an ide setting option | ||
924 | * @drive: drive to use | ||
925 | * @name: setting name | ||
926 | * @rw: true if the function is read write | ||
927 | * @read_ioctl: function to call on read | ||
928 | * @write_ioctl: function to call on write | ||
929 | * @data_type: type of data | ||
930 | * @min: range minimum | ||
931 | * @max: range maximum | ||
932 | * @mul_factor: multiplication scale | ||
933 | * @div_factor: divison scale | ||
934 | * @data: private data field | ||
935 | * @set: setting | ||
936 | * @auto_remove: setting auto removal flag | ||
937 | * | ||
938 | * Removes the setting named from the device if it is present. | ||
939 | * The function takes the settings_lock to protect against | ||
940 | * parallel changes. This function must not be called from IRQ | ||
941 | * context. Returns 0 on success or -1 on failure. | ||
942 | * | ||
943 | * BUGS: This code is seriously over-engineered. There is also | ||
944 | * magic about how the driver specific features are setup. If | ||
945 | * a driver is attached we assume the driver settings are auto | ||
946 | * remove. | ||
947 | */ | ||
948 | |||
949 | static int __ide_add_setting(ide_drive_t *drive, const char *name, int rw, int read_ioctl, int write_ioctl, int data_type, int min, int max, int mul_factor, int div_factor, void *data, ide_procset_t *set, int auto_remove) | ||
950 | { | ||
951 | ide_settings_t **p = (ide_settings_t **) &drive->settings, *setting = NULL; | ||
952 | |||
953 | down(&ide_setting_sem); | ||
954 | while ((*p) && strcmp((*p)->name, name) < 0) | ||
955 | p = &((*p)->next); | ||
956 | if ((setting = kmalloc(sizeof(*setting), GFP_KERNEL)) == NULL) | ||
957 | goto abort; | ||
958 | memset(setting, 0, sizeof(*setting)); | ||
959 | if ((setting->name = kmalloc(strlen(name) + 1, GFP_KERNEL)) == NULL) | ||
960 | goto abort; | ||
961 | strcpy(setting->name, name); | ||
962 | setting->rw = rw; | ||
963 | setting->read_ioctl = read_ioctl; | ||
964 | setting->write_ioctl = write_ioctl; | ||
965 | setting->data_type = data_type; | ||
966 | setting->min = min; | ||
967 | setting->max = max; | ||
968 | setting->mul_factor = mul_factor; | ||
969 | setting->div_factor = div_factor; | ||
970 | setting->data = data; | ||
971 | setting->set = set; | ||
972 | |||
973 | setting->next = *p; | ||
974 | if (auto_remove) | ||
975 | setting->auto_remove = 1; | ||
976 | *p = setting; | ||
977 | up(&ide_setting_sem); | ||
978 | return 0; | ||
979 | abort: | ||
980 | up(&ide_setting_sem); | ||
981 | if (setting) | ||
982 | kfree(setting); | ||
983 | return -1; | ||
984 | } | ||
985 | |||
986 | int ide_add_setting(ide_drive_t *drive, const char *name, int rw, int read_ioctl, int write_ioctl, int data_type, int min, int max, int mul_factor, int div_factor, void *data, ide_procset_t *set) | ||
987 | { | ||
988 | return __ide_add_setting(drive, name, rw, read_ioctl, write_ioctl, data_type, min, max, mul_factor, div_factor, data, set, 1); | ||
989 | } | ||
990 | |||
991 | EXPORT_SYMBOL(ide_add_setting); | ||
992 | |||
993 | /** | ||
994 | * __ide_remove_setting - remove an ide setting option | ||
995 | * @drive: drive to use | ||
996 | * @name: setting name | ||
997 | * | ||
998 | * Removes the setting named from the device if it is present. | ||
999 | * The caller must hold the setting semaphore. | ||
1000 | */ | ||
1001 | |||
1002 | static void __ide_remove_setting (ide_drive_t *drive, char *name) | ||
1003 | { | ||
1004 | ide_settings_t **p, *setting; | ||
1005 | |||
1006 | p = (ide_settings_t **) &drive->settings; | ||
1007 | |||
1008 | while ((*p) && strcmp((*p)->name, name)) | ||
1009 | p = &((*p)->next); | ||
1010 | if ((setting = (*p)) == NULL) | ||
1011 | return; | ||
1012 | |||
1013 | (*p) = setting->next; | ||
1014 | |||
1015 | kfree(setting->name); | ||
1016 | kfree(setting); | ||
1017 | } | ||
1018 | |||
1019 | /** | ||
1020 | * ide_find_setting_by_ioctl - find a drive specific ioctl | ||
1021 | * @drive: drive to scan | ||
1022 | * @cmd: ioctl command to handle | ||
1023 | * | ||
1024 | * Scan's the device setting table for a matching entry and returns | ||
1025 | * this or NULL if no entry is found. The caller must hold the | ||
1026 | * setting semaphore | ||
1027 | */ | ||
1028 | |||
1029 | static ide_settings_t *ide_find_setting_by_ioctl (ide_drive_t *drive, int cmd) | ||
1030 | { | ||
1031 | ide_settings_t *setting = drive->settings; | ||
1032 | |||
1033 | while (setting) { | ||
1034 | if (setting->read_ioctl == cmd || setting->write_ioctl == cmd) | ||
1035 | break; | ||
1036 | setting = setting->next; | ||
1037 | } | ||
1038 | |||
1039 | return setting; | ||
1040 | } | ||
1041 | |||
1042 | /** | ||
1043 | * ide_find_setting_by_name - find a drive specific setting | ||
1044 | * @drive: drive to scan | ||
1045 | * @name: setting name | ||
1046 | * | ||
1047 | * Scan's the device setting table for a matching entry and returns | ||
1048 | * this or NULL if no entry is found. The caller must hold the | ||
1049 | * setting semaphore | ||
1050 | */ | ||
1051 | |||
1052 | ide_settings_t *ide_find_setting_by_name (ide_drive_t *drive, char *name) | ||
1053 | { | ||
1054 | ide_settings_t *setting = drive->settings; | ||
1055 | |||
1056 | while (setting) { | ||
1057 | if (strcmp(setting->name, name) == 0) | ||
1058 | break; | ||
1059 | setting = setting->next; | ||
1060 | } | ||
1061 | return setting; | ||
1062 | } | ||
1063 | |||
1064 | /** | ||
1065 | * auto_remove_settings - remove driver specific settings | ||
1066 | * @drive: drive | ||
1067 | * | ||
1068 | * Automatically remove all the driver specific settings for this | ||
1069 | * drive. This function may sleep and must not be called from IRQ | ||
1070 | * context. The caller must hold ide_setting_sem. | ||
1071 | */ | ||
1072 | |||
1073 | static void auto_remove_settings (ide_drive_t *drive) | ||
1074 | { | ||
1075 | ide_settings_t *setting; | ||
1076 | repeat: | ||
1077 | setting = drive->settings; | ||
1078 | while (setting) { | ||
1079 | if (setting->auto_remove) { | ||
1080 | __ide_remove_setting(drive, setting->name); | ||
1081 | goto repeat; | ||
1082 | } | ||
1083 | setting = setting->next; | ||
1084 | } | ||
1085 | } | ||
1086 | |||
1087 | /** | ||
1088 | * ide_read_setting - read an IDE setting | ||
1089 | * @drive: drive to read from | ||
1090 | * @setting: drive setting | ||
1091 | * | ||
1092 | * Read a drive setting and return the value. The caller | ||
1093 | * must hold the ide_setting_sem when making this call. | ||
1094 | * | ||
1095 | * BUGS: the data return and error are the same return value | ||
1096 | * so an error -EINVAL and true return of the same value cannot | ||
1097 | * be told apart | ||
1098 | */ | ||
1099 | |||
1100 | int ide_read_setting (ide_drive_t *drive, ide_settings_t *setting) | ||
1101 | { | ||
1102 | int val = -EINVAL; | ||
1103 | unsigned long flags; | ||
1104 | |||
1105 | if ((setting->rw & SETTING_READ)) { | ||
1106 | spin_lock_irqsave(&ide_lock, flags); | ||
1107 | switch(setting->data_type) { | ||
1108 | case TYPE_BYTE: | ||
1109 | val = *((u8 *) setting->data); | ||
1110 | break; | ||
1111 | case TYPE_SHORT: | ||
1112 | val = *((u16 *) setting->data); | ||
1113 | break; | ||
1114 | case TYPE_INT: | ||
1115 | case TYPE_INTA: | ||
1116 | val = *((u32 *) setting->data); | ||
1117 | break; | ||
1118 | } | ||
1119 | spin_unlock_irqrestore(&ide_lock, flags); | ||
1120 | } | ||
1121 | return val; | ||
1122 | } | ||
1123 | |||
1124 | /** | ||
1125 | * ide_spin_wait_hwgroup - wait for group | ||
1126 | * @drive: drive in the group | ||
1127 | * | ||
1128 | * Wait for an IDE device group to go non busy and then return | ||
1129 | * holding the ide_lock which guards the hwgroup->busy status | ||
1130 | * and right to use it. | ||
1131 | */ | ||
1132 | |||
1133 | int ide_spin_wait_hwgroup (ide_drive_t *drive) | ||
1134 | { | ||
1135 | ide_hwgroup_t *hwgroup = HWGROUP(drive); | ||
1136 | unsigned long timeout = jiffies + (3 * HZ); | ||
1137 | |||
1138 | spin_lock_irq(&ide_lock); | ||
1139 | |||
1140 | while (hwgroup->busy) { | ||
1141 | unsigned long lflags; | ||
1142 | spin_unlock_irq(&ide_lock); | ||
1143 | local_irq_set(lflags); | ||
1144 | if (time_after(jiffies, timeout)) { | ||
1145 | local_irq_restore(lflags); | ||
1146 | printk(KERN_ERR "%s: channel busy\n", drive->name); | ||
1147 | return -EBUSY; | ||
1148 | } | ||
1149 | local_irq_restore(lflags); | ||
1150 | spin_lock_irq(&ide_lock); | ||
1151 | } | ||
1152 | return 0; | ||
1153 | } | ||
1154 | |||
1155 | EXPORT_SYMBOL(ide_spin_wait_hwgroup); | ||
1156 | |||
1157 | /** | ||
1158 | * ide_write_setting - read an IDE setting | ||
1159 | * @drive: drive to read from | ||
1160 | * @setting: drive setting | ||
1161 | * @val: value | ||
1162 | * | ||
1163 | * Write a drive setting if it is possible. The caller | ||
1164 | * must hold the ide_setting_sem when making this call. | ||
1165 | * | ||
1166 | * BUGS: the data return and error are the same return value | ||
1167 | * so an error -EINVAL and true return of the same value cannot | ||
1168 | * be told apart | ||
1169 | * | ||
1170 | * FIXME: This should be changed to enqueue a special request | ||
1171 | * to the driver to change settings, and then wait on a sema for completion. | ||
1172 | * The current scheme of polling is kludgy, though safe enough. | ||
1173 | */ | ||
1174 | |||
1175 | int ide_write_setting (ide_drive_t *drive, ide_settings_t *setting, int val) | ||
1176 | { | ||
1177 | int i; | ||
1178 | u32 *p; | ||
1179 | |||
1180 | if (!capable(CAP_SYS_ADMIN)) | ||
1181 | return -EACCES; | ||
1182 | if (!(setting->rw & SETTING_WRITE)) | ||
1183 | return -EPERM; | ||
1184 | if (val < setting->min || val > setting->max) | ||
1185 | return -EINVAL; | ||
1186 | if (setting->set) | ||
1187 | return setting->set(drive, val); | ||
1188 | if (ide_spin_wait_hwgroup(drive)) | ||
1189 | return -EBUSY; | ||
1190 | switch (setting->data_type) { | ||
1191 | case TYPE_BYTE: | ||
1192 | *((u8 *) setting->data) = val; | ||
1193 | break; | ||
1194 | case TYPE_SHORT: | ||
1195 | *((u16 *) setting->data) = val; | ||
1196 | break; | ||
1197 | case TYPE_INT: | ||
1198 | *((u32 *) setting->data) = val; | ||
1199 | break; | ||
1200 | case TYPE_INTA: | ||
1201 | p = (u32 *) setting->data; | ||
1202 | for (i = 0; i < 1 << PARTN_BITS; i++, p++) | ||
1203 | *p = val; | ||
1204 | break; | ||
1205 | } | ||
1206 | spin_unlock_irq(&ide_lock); | ||
1207 | return 0; | ||
1208 | } | ||
1209 | |||
1210 | static int set_io_32bit(ide_drive_t *drive, int arg) | ||
1211 | { | ||
1212 | drive->io_32bit = arg; | ||
1213 | #ifdef CONFIG_BLK_DEV_DTC2278 | ||
1214 | if (HWIF(drive)->chipset == ide_dtc2278) | ||
1215 | HWIF(drive)->drives[!drive->select.b.unit].io_32bit = arg; | ||
1216 | #endif /* CONFIG_BLK_DEV_DTC2278 */ | ||
1217 | return 0; | ||
1218 | } | ||
1219 | |||
1220 | static int set_using_dma (ide_drive_t *drive, int arg) | ||
1221 | { | ||
1222 | #ifdef CONFIG_BLK_DEV_IDEDMA | ||
1223 | if (!drive->id || !(drive->id->capability & 1)) | ||
1224 | return -EPERM; | ||
1225 | if (HWIF(drive)->ide_dma_check == NULL) | ||
1226 | return -EPERM; | ||
1227 | if (arg) { | ||
1228 | if (HWIF(drive)->ide_dma_check(drive)) return -EIO; | ||
1229 | if (HWIF(drive)->ide_dma_on(drive)) return -EIO; | ||
1230 | } else { | ||
1231 | if (__ide_dma_off(drive)) | ||
1232 | return -EIO; | ||
1233 | } | ||
1234 | return 0; | ||
1235 | #else | ||
1236 | return -EPERM; | ||
1237 | #endif | ||
1238 | } | ||
1239 | |||
1240 | static int set_pio_mode (ide_drive_t *drive, int arg) | ||
1241 | { | ||
1242 | struct request rq; | ||
1243 | |||
1244 | if (!HWIF(drive)->tuneproc) | ||
1245 | return -ENOSYS; | ||
1246 | if (drive->special.b.set_tune) | ||
1247 | return -EBUSY; | ||
1248 | ide_init_drive_cmd(&rq); | ||
1249 | drive->tune_req = (u8) arg; | ||
1250 | drive->special.b.set_tune = 1; | ||
1251 | (void) ide_do_drive_cmd(drive, &rq, ide_wait); | ||
1252 | return 0; | ||
1253 | } | ||
1254 | |||
1255 | static int set_xfer_rate (ide_drive_t *drive, int arg) | ||
1256 | { | ||
1257 | int err = ide_wait_cmd(drive, | ||
1258 | WIN_SETFEATURES, (u8) arg, | ||
1259 | SETFEATURES_XFER, 0, NULL); | ||
1260 | |||
1261 | if (!err && arg) { | ||
1262 | ide_set_xfer_rate(drive, (u8) arg); | ||
1263 | ide_driveid_update(drive); | ||
1264 | } | ||
1265 | return err; | ||
1266 | } | ||
1267 | |||
1268 | /** | ||
1269 | * ide_add_generic_settings - generic ide settings | ||
1270 | * @drive: drive being configured | ||
1271 | * | ||
1272 | * Add the generic parts of the system settings to the /proc files and | ||
1273 | * ioctls for this IDE device. The caller must not be holding the | ||
1274 | * ide_setting_sem. | ||
1275 | */ | ||
1276 | |||
1277 | void ide_add_generic_settings (ide_drive_t *drive) | ||
1278 | { | ||
1279 | /* | ||
1280 | * drive setting name read/write access read ioctl write ioctl data type min max mul_factor div_factor data pointer set function | ||
1281 | */ | ||
1282 | __ide_add_setting(drive, "io_32bit", drive->no_io_32bit ? SETTING_READ : SETTING_RW, HDIO_GET_32BIT, HDIO_SET_32BIT, TYPE_BYTE, 0, 1 + (SUPPORT_VLB_SYNC << 1), 1, 1, &drive->io_32bit, set_io_32bit, 0); | ||
1283 | __ide_add_setting(drive, "keepsettings", SETTING_RW, HDIO_GET_KEEPSETTINGS, HDIO_SET_KEEPSETTINGS, TYPE_BYTE, 0, 1, 1, 1, &drive->keep_settings, NULL, 0); | ||
1284 | __ide_add_setting(drive, "nice1", SETTING_RW, -1, -1, TYPE_BYTE, 0, 1, 1, 1, &drive->nice1, NULL, 0); | ||
1285 | __ide_add_setting(drive, "pio_mode", SETTING_WRITE, -1, HDIO_SET_PIO_MODE, TYPE_BYTE, 0, 255, 1, 1, NULL, set_pio_mode, 0); | ||
1286 | __ide_add_setting(drive, "unmaskirq", drive->no_unmask ? SETTING_READ : SETTING_RW, HDIO_GET_UNMASKINTR, HDIO_SET_UNMASKINTR, TYPE_BYTE, 0, 1, 1, 1, &drive->unmask, NULL, 0); | ||
1287 | __ide_add_setting(drive, "using_dma", SETTING_RW, HDIO_GET_DMA, HDIO_SET_DMA, TYPE_BYTE, 0, 1, 1, 1, &drive->using_dma, set_using_dma, 0); | ||
1288 | __ide_add_setting(drive, "init_speed", SETTING_RW, -1, -1, TYPE_BYTE, 0, 70, 1, 1, &drive->init_speed, NULL, 0); | ||
1289 | __ide_add_setting(drive, "current_speed", SETTING_RW, -1, -1, TYPE_BYTE, 0, 70, 1, 1, &drive->current_speed, set_xfer_rate, 0); | ||
1290 | __ide_add_setting(drive, "number", SETTING_RW, -1, -1, TYPE_BYTE, 0, 3, 1, 1, &drive->dn, NULL, 0); | ||
1291 | } | ||
1292 | |||
1293 | /** | ||
1294 | * system_bus_clock - clock guess | ||
1295 | * | ||
1296 | * External version of the bus clock guess used by very old IDE drivers | ||
1297 | * for things like VLB timings. Should not be used. | ||
1298 | */ | ||
1299 | |||
1300 | int system_bus_clock (void) | ||
1301 | { | ||
1302 | return((int) ((!system_bus_speed) ? ide_system_bus_speed() : system_bus_speed )); | ||
1303 | } | ||
1304 | |||
1305 | EXPORT_SYMBOL(system_bus_clock); | ||
1306 | |||
1307 | /* | ||
1308 | * Locking is badly broken here - since way back. That sucker is | ||
1309 | * root-only, but that's not an excuse... The real question is what | ||
1310 | * exclusion rules do we want here. | ||
1311 | */ | ||
1312 | int ide_replace_subdriver (ide_drive_t *drive, const char *driver) | ||
1313 | { | ||
1314 | if (!drive->present || drive->usage || drive->dead) | ||
1315 | goto abort; | ||
1316 | if (DRIVER(drive)->cleanup(drive)) | ||
1317 | goto abort; | ||
1318 | strlcpy(drive->driver_req, driver, sizeof(drive->driver_req)); | ||
1319 | if (ata_attach(drive)) { | ||
1320 | spin_lock(&drives_lock); | ||
1321 | list_del_init(&drive->list); | ||
1322 | spin_unlock(&drives_lock); | ||
1323 | drive->driver_req[0] = 0; | ||
1324 | ata_attach(drive); | ||
1325 | } else { | ||
1326 | drive->driver_req[0] = 0; | ||
1327 | } | ||
1328 | if (drive->driver && !strcmp(drive->driver->name, driver)) | ||
1329 | return 0; | ||
1330 | abort: | ||
1331 | return 1; | ||
1332 | } | ||
1333 | |||
1334 | /** | ||
1335 | * ata_attach - attach an ATA/ATAPI device | ||
1336 | * @drive: drive to attach | ||
1337 | * | ||
1338 | * Takes a drive that is as yet not assigned to any midlayer IDE | ||
1339 | * driver (or is assigned to the default driver) and figures out | ||
1340 | * which driver would like to own it. If nobody claims the drive | ||
1341 | * then it is automatically attached to the default driver used for | ||
1342 | * unclaimed objects. | ||
1343 | * | ||
1344 | * A return of zero indicates attachment to a driver, of one | ||
1345 | * attachment to the default driver. | ||
1346 | * | ||
1347 | * Takes drivers_lock. | ||
1348 | */ | ||
1349 | |||
1350 | int ata_attach(ide_drive_t *drive) | ||
1351 | { | ||
1352 | struct list_head *p; | ||
1353 | spin_lock(&drivers_lock); | ||
1354 | list_for_each(p, &drivers) { | ||
1355 | ide_driver_t *driver = list_entry(p, ide_driver_t, drivers); | ||
1356 | if (!try_module_get(driver->owner)) | ||
1357 | continue; | ||
1358 | spin_unlock(&drivers_lock); | ||
1359 | if (driver->attach(drive) == 0) { | ||
1360 | module_put(driver->owner); | ||
1361 | drive->gendev.driver = &driver->gen_driver; | ||
1362 | return 0; | ||
1363 | } | ||
1364 | spin_lock(&drivers_lock); | ||
1365 | module_put(driver->owner); | ||
1366 | } | ||
1367 | drive->gendev.driver = NULL; | ||
1368 | spin_unlock(&drivers_lock); | ||
1369 | if (ide_register_subdriver(drive, NULL)) | ||
1370 | panic("ide: default attach failed"); | ||
1371 | return 1; | ||
1372 | } | ||
1373 | |||
1374 | static int generic_ide_suspend(struct device *dev, pm_message_t state) | ||
1375 | { | ||
1376 | ide_drive_t *drive = dev->driver_data; | ||
1377 | struct request rq; | ||
1378 | struct request_pm_state rqpm; | ||
1379 | ide_task_t args; | ||
1380 | |||
1381 | memset(&rq, 0, sizeof(rq)); | ||
1382 | memset(&rqpm, 0, sizeof(rqpm)); | ||
1383 | memset(&args, 0, sizeof(args)); | ||
1384 | rq.flags = REQ_PM_SUSPEND; | ||
1385 | rq.special = &args; | ||
1386 | rq.pm = &rqpm; | ||
1387 | rqpm.pm_step = ide_pm_state_start_suspend; | ||
1388 | rqpm.pm_state = state; | ||
1389 | |||
1390 | return ide_do_drive_cmd(drive, &rq, ide_wait); | ||
1391 | } | ||
1392 | |||
1393 | static int generic_ide_resume(struct device *dev) | ||
1394 | { | ||
1395 | ide_drive_t *drive = dev->driver_data; | ||
1396 | struct request rq; | ||
1397 | struct request_pm_state rqpm; | ||
1398 | ide_task_t args; | ||
1399 | |||
1400 | memset(&rq, 0, sizeof(rq)); | ||
1401 | memset(&rqpm, 0, sizeof(rqpm)); | ||
1402 | memset(&args, 0, sizeof(args)); | ||
1403 | rq.flags = REQ_PM_RESUME; | ||
1404 | rq.special = &args; | ||
1405 | rq.pm = &rqpm; | ||
1406 | rqpm.pm_step = ide_pm_state_start_resume; | ||
1407 | rqpm.pm_state = 0; | ||
1408 | |||
1409 | return ide_do_drive_cmd(drive, &rq, ide_head_wait); | ||
1410 | } | ||
1411 | |||
1412 | int generic_ide_ioctl(ide_drive_t *drive, struct file *file, struct block_device *bdev, | ||
1413 | unsigned int cmd, unsigned long arg) | ||
1414 | { | ||
1415 | ide_settings_t *setting; | ||
1416 | ide_driver_t *drv; | ||
1417 | int err = 0; | ||
1418 | void __user *p = (void __user *)arg; | ||
1419 | |||
1420 | down(&ide_setting_sem); | ||
1421 | if ((setting = ide_find_setting_by_ioctl(drive, cmd)) != NULL) { | ||
1422 | if (cmd == setting->read_ioctl) { | ||
1423 | err = ide_read_setting(drive, setting); | ||
1424 | up(&ide_setting_sem); | ||
1425 | return err >= 0 ? put_user(err, (long __user *)arg) : err; | ||
1426 | } else { | ||
1427 | if (bdev != bdev->bd_contains) | ||
1428 | err = -EINVAL; | ||
1429 | else | ||
1430 | err = ide_write_setting(drive, setting, arg); | ||
1431 | up(&ide_setting_sem); | ||
1432 | return err; | ||
1433 | } | ||
1434 | } | ||
1435 | up(&ide_setting_sem); | ||
1436 | |||
1437 | switch (cmd) { | ||
1438 | case HDIO_GETGEO: | ||
1439 | { | ||
1440 | struct hd_geometry geom; | ||
1441 | if (!p || (drive->media != ide_disk && drive->media != ide_floppy)) return -EINVAL; | ||
1442 | geom.heads = drive->bios_head; | ||
1443 | geom.sectors = drive->bios_sect; | ||
1444 | geom.cylinders = (u16)drive->bios_cyl; /* truncate */ | ||
1445 | geom.start = get_start_sect(bdev); | ||
1446 | if (copy_to_user(p, &geom, sizeof(struct hd_geometry))) | ||
1447 | return -EFAULT; | ||
1448 | return 0; | ||
1449 | } | ||
1450 | |||
1451 | case HDIO_OBSOLETE_IDENTITY: | ||
1452 | case HDIO_GET_IDENTITY: | ||
1453 | if (bdev != bdev->bd_contains) | ||
1454 | return -EINVAL; | ||
1455 | if (drive->id_read == 0) | ||
1456 | return -ENOMSG; | ||
1457 | if (copy_to_user(p, drive->id, (cmd == HDIO_GET_IDENTITY) ? sizeof(*drive->id) : 142)) | ||
1458 | return -EFAULT; | ||
1459 | return 0; | ||
1460 | |||
1461 | case HDIO_GET_NICE: | ||
1462 | return put_user(drive->dsc_overlap << IDE_NICE_DSC_OVERLAP | | ||
1463 | drive->atapi_overlap << IDE_NICE_ATAPI_OVERLAP | | ||
1464 | drive->nice0 << IDE_NICE_0 | | ||
1465 | drive->nice1 << IDE_NICE_1 | | ||
1466 | drive->nice2 << IDE_NICE_2, | ||
1467 | (long __user *) arg); | ||
1468 | |||
1469 | #ifdef CONFIG_IDE_TASK_IOCTL | ||
1470 | case HDIO_DRIVE_TASKFILE: | ||
1471 | if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO)) | ||
1472 | return -EACCES; | ||
1473 | switch(drive->media) { | ||
1474 | case ide_disk: | ||
1475 | return ide_taskfile_ioctl(drive, cmd, arg); | ||
1476 | default: | ||
1477 | return -ENOMSG; | ||
1478 | } | ||
1479 | #endif /* CONFIG_IDE_TASK_IOCTL */ | ||
1480 | |||
1481 | case HDIO_DRIVE_CMD: | ||
1482 | if (!capable(CAP_SYS_RAWIO)) | ||
1483 | return -EACCES; | ||
1484 | return ide_cmd_ioctl(drive, cmd, arg); | ||
1485 | |||
1486 | case HDIO_DRIVE_TASK: | ||
1487 | if (!capable(CAP_SYS_RAWIO)) | ||
1488 | return -EACCES; | ||
1489 | return ide_task_ioctl(drive, cmd, arg); | ||
1490 | |||
1491 | case HDIO_SCAN_HWIF: | ||
1492 | { | ||
1493 | hw_regs_t hw; | ||
1494 | int args[3]; | ||
1495 | if (!capable(CAP_SYS_RAWIO)) return -EACCES; | ||
1496 | if (copy_from_user(args, p, 3 * sizeof(int))) | ||
1497 | return -EFAULT; | ||
1498 | memset(&hw, 0, sizeof(hw)); | ||
1499 | ide_init_hwif_ports(&hw, (unsigned long) args[0], | ||
1500 | (unsigned long) args[1], NULL); | ||
1501 | hw.irq = args[2]; | ||
1502 | if (ide_register_hw(&hw, NULL) == -1) | ||
1503 | return -EIO; | ||
1504 | return 0; | ||
1505 | } | ||
1506 | case HDIO_UNREGISTER_HWIF: | ||
1507 | if (!capable(CAP_SYS_RAWIO)) return -EACCES; | ||
1508 | /* (arg > MAX_HWIFS) checked in function */ | ||
1509 | ide_unregister(arg); | ||
1510 | return 0; | ||
1511 | case HDIO_SET_NICE: | ||
1512 | if (!capable(CAP_SYS_ADMIN)) return -EACCES; | ||
1513 | if (arg != (arg & ((1 << IDE_NICE_DSC_OVERLAP) | (1 << IDE_NICE_1)))) | ||
1514 | return -EPERM; | ||
1515 | drive->dsc_overlap = (arg >> IDE_NICE_DSC_OVERLAP) & 1; | ||
1516 | drv = *(ide_driver_t **)bdev->bd_disk->private_data; | ||
1517 | if (drive->dsc_overlap && !drv->supports_dsc_overlap) { | ||
1518 | drive->dsc_overlap = 0; | ||
1519 | return -EPERM; | ||
1520 | } | ||
1521 | drive->nice1 = (arg >> IDE_NICE_1) & 1; | ||
1522 | return 0; | ||
1523 | case HDIO_DRIVE_RESET: | ||
1524 | { | ||
1525 | unsigned long flags; | ||
1526 | if (!capable(CAP_SYS_ADMIN)) return -EACCES; | ||
1527 | |||
1528 | /* | ||
1529 | * Abort the current command on the | ||
1530 | * group if there is one, taking | ||
1531 | * care not to allow anything else | ||
1532 | * to be queued and to die on the | ||
1533 | * spot if we miss one somehow | ||
1534 | */ | ||
1535 | |||
1536 | spin_lock_irqsave(&ide_lock, flags); | ||
1537 | |||
1538 | ide_abort(drive, "drive reset"); | ||
1539 | |||
1540 | if(HWGROUP(drive)->handler) | ||
1541 | BUG(); | ||
1542 | |||
1543 | /* Ensure nothing gets queued after we | ||
1544 | drop the lock. Reset will clear the busy */ | ||
1545 | |||
1546 | HWGROUP(drive)->busy = 1; | ||
1547 | spin_unlock_irqrestore(&ide_lock, flags); | ||
1548 | (void) ide_do_reset(drive); | ||
1549 | |||
1550 | return 0; | ||
1551 | } | ||
1552 | |||
1553 | case CDROMEJECT: | ||
1554 | case CDROMCLOSETRAY: | ||
1555 | return scsi_cmd_ioctl(file, bdev->bd_disk, cmd, p); | ||
1556 | |||
1557 | case HDIO_GET_BUSSTATE: | ||
1558 | if (!capable(CAP_SYS_ADMIN)) | ||
1559 | return -EACCES; | ||
1560 | if (put_user(HWIF(drive)->bus_state, (long __user *)arg)) | ||
1561 | return -EFAULT; | ||
1562 | return 0; | ||
1563 | |||
1564 | case HDIO_SET_BUSSTATE: | ||
1565 | if (!capable(CAP_SYS_ADMIN)) | ||
1566 | return -EACCES; | ||
1567 | if (HWIF(drive)->busproc) | ||
1568 | return HWIF(drive)->busproc(drive, (int)arg); | ||
1569 | return -EOPNOTSUPP; | ||
1570 | default: | ||
1571 | return -EINVAL; | ||
1572 | } | ||
1573 | } | ||
1574 | |||
1575 | EXPORT_SYMBOL(generic_ide_ioctl); | ||
1576 | |||
1577 | /* | ||
1578 | * stridx() returns the offset of c within s, | ||
1579 | * or -1 if c is '\0' or not found within s. | ||
1580 | */ | ||
1581 | static int __init stridx (const char *s, char c) | ||
1582 | { | ||
1583 | char *i = strchr(s, c); | ||
1584 | return (i && c) ? i - s : -1; | ||
1585 | } | ||
1586 | |||
1587 | /* | ||
1588 | * match_parm() does parsing for ide_setup(): | ||
1589 | * | ||
1590 | * 1. the first char of s must be '='. | ||
1591 | * 2. if the remainder matches one of the supplied keywords, | ||
1592 | * the index (1 based) of the keyword is negated and returned. | ||
1593 | * 3. if the remainder is a series of no more than max_vals numbers | ||
1594 | * separated by commas, the numbers are saved in vals[] and a | ||
1595 | * count of how many were saved is returned. Base10 is assumed, | ||
1596 | * and base16 is allowed when prefixed with "0x". | ||
1597 | * 4. otherwise, zero is returned. | ||
1598 | */ | ||
1599 | static int __init match_parm (char *s, const char *keywords[], int vals[], int max_vals) | ||
1600 | { | ||
1601 | static const char *decimal = "0123456789"; | ||
1602 | static const char *hex = "0123456789abcdef"; | ||
1603 | int i, n; | ||
1604 | |||
1605 | if (*s++ == '=') { | ||
1606 | /* | ||
1607 | * Try matching against the supplied keywords, | ||
1608 | * and return -(index+1) if we match one | ||
1609 | */ | ||
1610 | if (keywords != NULL) { | ||
1611 | for (i = 0; *keywords != NULL; ++i) { | ||
1612 | if (!strcmp(s, *keywords++)) | ||
1613 | return -(i+1); | ||
1614 | } | ||
1615 | } | ||
1616 | /* | ||
1617 | * Look for a series of no more than "max_vals" | ||
1618 | * numeric values separated by commas, in base10, | ||
1619 | * or base16 when prefixed with "0x". | ||
1620 | * Return a count of how many were found. | ||
1621 | */ | ||
1622 | for (n = 0; (i = stridx(decimal, *s)) >= 0;) { | ||
1623 | vals[n] = i; | ||
1624 | while ((i = stridx(decimal, *++s)) >= 0) | ||
1625 | vals[n] = (vals[n] * 10) + i; | ||
1626 | if (*s == 'x' && !vals[n]) { | ||
1627 | while ((i = stridx(hex, *++s)) >= 0) | ||
1628 | vals[n] = (vals[n] * 0x10) + i; | ||
1629 | } | ||
1630 | if (++n == max_vals) | ||
1631 | break; | ||
1632 | if (*s == ',' || *s == ';') | ||
1633 | ++s; | ||
1634 | } | ||
1635 | if (!*s) | ||
1636 | return n; | ||
1637 | } | ||
1638 | return 0; /* zero = nothing matched */ | ||
1639 | } | ||
1640 | |||
1641 | #ifdef CONFIG_BLK_DEV_ALI14XX | ||
1642 | static int __initdata probe_ali14xx; | ||
1643 | extern int ali14xx_init(void); | ||
1644 | #endif | ||
1645 | #ifdef CONFIG_BLK_DEV_UMC8672 | ||
1646 | static int __initdata probe_umc8672; | ||
1647 | extern int umc8672_init(void); | ||
1648 | #endif | ||
1649 | #ifdef CONFIG_BLK_DEV_DTC2278 | ||
1650 | static int __initdata probe_dtc2278; | ||
1651 | extern int dtc2278_init(void); | ||
1652 | #endif | ||
1653 | #ifdef CONFIG_BLK_DEV_HT6560B | ||
1654 | static int __initdata probe_ht6560b; | ||
1655 | extern int ht6560b_init(void); | ||
1656 | #endif | ||
1657 | #ifdef CONFIG_BLK_DEV_QD65XX | ||
1658 | static int __initdata probe_qd65xx; | ||
1659 | extern int qd65xx_init(void); | ||
1660 | #endif | ||
1661 | |||
1662 | static int __initdata is_chipset_set[MAX_HWIFS]; | ||
1663 | |||
1664 | /* | ||
1665 | * ide_setup() gets called VERY EARLY during initialization, | ||
1666 | * to handle kernel "command line" strings beginning with "hdx=" or "ide". | ||
1667 | * | ||
1668 | * Remember to update Documentation/ide.txt if you change something here. | ||
1669 | */ | ||
1670 | static int __init ide_setup(char *s) | ||
1671 | { | ||
1672 | int i, vals[3]; | ||
1673 | ide_hwif_t *hwif; | ||
1674 | ide_drive_t *drive; | ||
1675 | unsigned int hw, unit; | ||
1676 | const char max_drive = 'a' + ((MAX_HWIFS * MAX_DRIVES) - 1); | ||
1677 | const char max_hwif = '0' + (MAX_HWIFS - 1); | ||
1678 | |||
1679 | |||
1680 | if (strncmp(s,"hd",2) == 0 && s[2] == '=') /* hd= is for hd.c */ | ||
1681 | return 0; /* driver and not us */ | ||
1682 | |||
1683 | if (strncmp(s,"ide",3) && strncmp(s,"idebus",6) && strncmp(s,"hd",2)) | ||
1684 | return 0; | ||
1685 | |||
1686 | printk(KERN_INFO "ide_setup: %s", s); | ||
1687 | init_ide_data (); | ||
1688 | |||
1689 | #ifdef CONFIG_BLK_DEV_IDEDOUBLER | ||
1690 | if (!strcmp(s, "ide=doubler")) { | ||
1691 | extern int ide_doubler; | ||
1692 | |||
1693 | printk(" : Enabled support for IDE doublers\n"); | ||
1694 | ide_doubler = 1; | ||
1695 | return 1; | ||
1696 | } | ||
1697 | #endif /* CONFIG_BLK_DEV_IDEDOUBLER */ | ||
1698 | |||
1699 | if (!strcmp(s, "ide=nodma")) { | ||
1700 | printk(" : Prevented DMA\n"); | ||
1701 | noautodma = 1; | ||
1702 | return 1; | ||
1703 | } | ||
1704 | |||
1705 | #ifdef CONFIG_BLK_DEV_IDEPCI | ||
1706 | if (!strcmp(s, "ide=reverse")) { | ||
1707 | ide_scan_direction = 1; | ||
1708 | printk(" : Enabled support for IDE inverse scan order.\n"); | ||
1709 | return 1; | ||
1710 | } | ||
1711 | #endif /* CONFIG_BLK_DEV_IDEPCI */ | ||
1712 | |||
1713 | /* | ||
1714 | * Look for drive options: "hdx=" | ||
1715 | */ | ||
1716 | if (s[0] == 'h' && s[1] == 'd' && s[2] >= 'a' && s[2] <= max_drive) { | ||
1717 | const char *hd_words[] = { | ||
1718 | "none", "noprobe", "nowerr", "cdrom", "serialize", | ||
1719 | "autotune", "noautotune", "minus8", "swapdata", "bswap", | ||
1720 | "minus11", "remap", "remap63", "scsi", NULL }; | ||
1721 | unit = s[2] - 'a'; | ||
1722 | hw = unit / MAX_DRIVES; | ||
1723 | unit = unit % MAX_DRIVES; | ||
1724 | hwif = &ide_hwifs[hw]; | ||
1725 | drive = &hwif->drives[unit]; | ||
1726 | if (strncmp(s + 4, "ide-", 4) == 0) { | ||
1727 | strlcpy(drive->driver_req, s + 4, sizeof(drive->driver_req)); | ||
1728 | goto done; | ||
1729 | } | ||
1730 | switch (match_parm(&s[3], hd_words, vals, 3)) { | ||
1731 | case -1: /* "none" */ | ||
1732 | case -2: /* "noprobe" */ | ||
1733 | drive->noprobe = 1; | ||
1734 | goto done; | ||
1735 | case -3: /* "nowerr" */ | ||
1736 | drive->bad_wstat = BAD_R_STAT; | ||
1737 | hwif->noprobe = 0; | ||
1738 | goto done; | ||
1739 | case -4: /* "cdrom" */ | ||
1740 | drive->present = 1; | ||
1741 | drive->media = ide_cdrom; | ||
1742 | /* an ATAPI device ignores DRDY */ | ||
1743 | drive->ready_stat = 0; | ||
1744 | hwif->noprobe = 0; | ||
1745 | goto done; | ||
1746 | case -5: /* "serialize" */ | ||
1747 | printk(" -- USE \"ide%d=serialize\" INSTEAD", hw); | ||
1748 | goto do_serialize; | ||
1749 | case -6: /* "autotune" */ | ||
1750 | drive->autotune = IDE_TUNE_AUTO; | ||
1751 | goto obsolete_option; | ||
1752 | case -7: /* "noautotune" */ | ||
1753 | drive->autotune = IDE_TUNE_NOAUTO; | ||
1754 | goto obsolete_option; | ||
1755 | case -9: /* "swapdata" */ | ||
1756 | case -10: /* "bswap" */ | ||
1757 | drive->bswap = 1; | ||
1758 | goto done; | ||
1759 | case -12: /* "remap" */ | ||
1760 | drive->remap_0_to_1 = 1; | ||
1761 | goto done; | ||
1762 | case -13: /* "remap63" */ | ||
1763 | drive->sect0 = 63; | ||
1764 | goto done; | ||
1765 | case -14: /* "scsi" */ | ||
1766 | drive->scsi = 1; | ||
1767 | goto done; | ||
1768 | case 3: /* cyl,head,sect */ | ||
1769 | drive->media = ide_disk; | ||
1770 | drive->ready_stat = READY_STAT; | ||
1771 | drive->cyl = drive->bios_cyl = vals[0]; | ||
1772 | drive->head = drive->bios_head = vals[1]; | ||
1773 | drive->sect = drive->bios_sect = vals[2]; | ||
1774 | drive->present = 1; | ||
1775 | drive->forced_geom = 1; | ||
1776 | hwif->noprobe = 0; | ||
1777 | goto done; | ||
1778 | default: | ||
1779 | goto bad_option; | ||
1780 | } | ||
1781 | } | ||
1782 | |||
1783 | if (s[0] != 'i' || s[1] != 'd' || s[2] != 'e') | ||
1784 | goto bad_option; | ||
1785 | /* | ||
1786 | * Look for bus speed option: "idebus=" | ||
1787 | */ | ||
1788 | if (s[3] == 'b' && s[4] == 'u' && s[5] == 's') { | ||
1789 | if (match_parm(&s[6], NULL, vals, 1) != 1) | ||
1790 | goto bad_option; | ||
1791 | if (vals[0] >= 20 && vals[0] <= 66) { | ||
1792 | idebus_parameter = vals[0]; | ||
1793 | } else | ||
1794 | printk(" -- BAD BUS SPEED! Expected value from 20 to 66"); | ||
1795 | goto done; | ||
1796 | } | ||
1797 | /* | ||
1798 | * Look for interface options: "idex=" | ||
1799 | */ | ||
1800 | if (s[3] >= '0' && s[3] <= max_hwif) { | ||
1801 | /* | ||
1802 | * Be VERY CAREFUL changing this: note hardcoded indexes below | ||
1803 | * (-8, -9, -10) are reserved to ease the hardcoding. | ||
1804 | */ | ||
1805 | static const char *ide_words[] = { | ||
1806 | "noprobe", "serialize", "autotune", "noautotune", | ||
1807 | "reset", "dma", "ata66", "minus8", "minus9", | ||
1808 | "minus10", "four", "qd65xx", "ht6560b", "cmd640_vlb", | ||
1809 | "dtc2278", "umc8672", "ali14xx", NULL }; | ||
1810 | hw = s[3] - '0'; | ||
1811 | hwif = &ide_hwifs[hw]; | ||
1812 | i = match_parm(&s[4], ide_words, vals, 3); | ||
1813 | |||
1814 | /* | ||
1815 | * Cryptic check to ensure chipset not already set for hwif. | ||
1816 | * Note: we can't depend on hwif->chipset here. | ||
1817 | */ | ||
1818 | if ((i >= -18 && i <= -11) || (i > 0 && i <= 3)) { | ||
1819 | /* chipset already specified */ | ||
1820 | if (is_chipset_set[hw]) | ||
1821 | goto bad_option; | ||
1822 | if (i > -18 && i <= -11) { | ||
1823 | /* these drivers are for "ide0=" only */ | ||
1824 | if (hw != 0) | ||
1825 | goto bad_hwif; | ||
1826 | /* chipset already specified for 2nd port */ | ||
1827 | if (is_chipset_set[hw+1]) | ||
1828 | goto bad_option; | ||
1829 | } | ||
1830 | is_chipset_set[hw] = 1; | ||
1831 | printk("\n"); | ||
1832 | } | ||
1833 | |||
1834 | switch (i) { | ||
1835 | #ifdef CONFIG_BLK_DEV_ALI14XX | ||
1836 | case -17: /* "ali14xx" */ | ||
1837 | probe_ali14xx = 1; | ||
1838 | goto done; | ||
1839 | #endif | ||
1840 | #ifdef CONFIG_BLK_DEV_UMC8672 | ||
1841 | case -16: /* "umc8672" */ | ||
1842 | probe_umc8672 = 1; | ||
1843 | goto done; | ||
1844 | #endif | ||
1845 | #ifdef CONFIG_BLK_DEV_DTC2278 | ||
1846 | case -15: /* "dtc2278" */ | ||
1847 | probe_dtc2278 = 1; | ||
1848 | goto done; | ||
1849 | #endif | ||
1850 | #ifdef CONFIG_BLK_DEV_CMD640 | ||
1851 | case -14: /* "cmd640_vlb" */ | ||
1852 | { | ||
1853 | extern int cmd640_vlb; /* flag for cmd640.c */ | ||
1854 | cmd640_vlb = 1; | ||
1855 | goto done; | ||
1856 | } | ||
1857 | #endif | ||
1858 | #ifdef CONFIG_BLK_DEV_HT6560B | ||
1859 | case -13: /* "ht6560b" */ | ||
1860 | probe_ht6560b = 1; | ||
1861 | goto done; | ||
1862 | #endif | ||
1863 | #ifdef CONFIG_BLK_DEV_QD65XX | ||
1864 | case -12: /* "qd65xx" */ | ||
1865 | probe_qd65xx = 1; | ||
1866 | goto done; | ||
1867 | #endif | ||
1868 | #ifdef CONFIG_BLK_DEV_4DRIVES | ||
1869 | case -11: /* "four" drives on one set of ports */ | ||
1870 | { | ||
1871 | ide_hwif_t *mate = &ide_hwifs[hw^1]; | ||
1872 | mate->drives[0].select.all ^= 0x20; | ||
1873 | mate->drives[1].select.all ^= 0x20; | ||
1874 | hwif->chipset = mate->chipset = ide_4drives; | ||
1875 | mate->irq = hwif->irq; | ||
1876 | memcpy(mate->io_ports, hwif->io_ports, sizeof(hwif->io_ports)); | ||
1877 | goto do_serialize; | ||
1878 | } | ||
1879 | #endif /* CONFIG_BLK_DEV_4DRIVES */ | ||
1880 | case -10: /* minus10 */ | ||
1881 | case -9: /* minus9 */ | ||
1882 | case -8: /* minus8 */ | ||
1883 | goto bad_option; | ||
1884 | case -7: /* ata66 */ | ||
1885 | #ifdef CONFIG_BLK_DEV_IDEPCI | ||
1886 | hwif->udma_four = 1; | ||
1887 | goto obsolete_option; | ||
1888 | #else | ||
1889 | goto bad_hwif; | ||
1890 | #endif | ||
1891 | case -6: /* dma */ | ||
1892 | hwif->autodma = 1; | ||
1893 | goto obsolete_option; | ||
1894 | case -5: /* "reset" */ | ||
1895 | hwif->reset = 1; | ||
1896 | goto obsolete_option; | ||
1897 | case -4: /* "noautotune" */ | ||
1898 | hwif->drives[0].autotune = IDE_TUNE_NOAUTO; | ||
1899 | hwif->drives[1].autotune = IDE_TUNE_NOAUTO; | ||
1900 | goto obsolete_option; | ||
1901 | case -3: /* "autotune" */ | ||
1902 | hwif->drives[0].autotune = IDE_TUNE_AUTO; | ||
1903 | hwif->drives[1].autotune = IDE_TUNE_AUTO; | ||
1904 | goto obsolete_option; | ||
1905 | case -2: /* "serialize" */ | ||
1906 | do_serialize: | ||
1907 | hwif->mate = &ide_hwifs[hw^1]; | ||
1908 | hwif->mate->mate = hwif; | ||
1909 | hwif->serialized = hwif->mate->serialized = 1; | ||
1910 | goto obsolete_option; | ||
1911 | |||
1912 | case -1: /* "noprobe" */ | ||
1913 | hwif->noprobe = 1; | ||
1914 | goto done; | ||
1915 | |||
1916 | case 1: /* base */ | ||
1917 | vals[1] = vals[0] + 0x206; /* default ctl */ | ||
1918 | case 2: /* base,ctl */ | ||
1919 | vals[2] = 0; /* default irq = probe for it */ | ||
1920 | case 3: /* base,ctl,irq */ | ||
1921 | hwif->hw.irq = vals[2]; | ||
1922 | ide_init_hwif_ports(&hwif->hw, (unsigned long) vals[0], (unsigned long) vals[1], &hwif->irq); | ||
1923 | memcpy(hwif->io_ports, hwif->hw.io_ports, sizeof(hwif->io_ports)); | ||
1924 | hwif->irq = vals[2]; | ||
1925 | hwif->noprobe = 0; | ||
1926 | hwif->chipset = ide_forced; | ||
1927 | goto obsolete_option; | ||
1928 | |||
1929 | case 0: goto bad_option; | ||
1930 | default: | ||
1931 | printk(" -- SUPPORT NOT CONFIGURED IN THIS KERNEL\n"); | ||
1932 | return 1; | ||
1933 | } | ||
1934 | } | ||
1935 | bad_option: | ||
1936 | printk(" -- BAD OPTION\n"); | ||
1937 | return 1; | ||
1938 | obsolete_option: | ||
1939 | printk(" -- OBSOLETE OPTION, WILL BE REMOVED SOON!\n"); | ||
1940 | return 1; | ||
1941 | bad_hwif: | ||
1942 | printk("-- NOT SUPPORTED ON ide%d", hw); | ||
1943 | done: | ||
1944 | printk("\n"); | ||
1945 | return 1; | ||
1946 | } | ||
1947 | |||
1948 | extern void pnpide_init(void); | ||
1949 | extern void h8300_ide_init(void); | ||
1950 | |||
1951 | /* | ||
1952 | * probe_for_hwifs() finds/initializes "known" IDE interfaces | ||
1953 | */ | ||
1954 | static void __init probe_for_hwifs (void) | ||
1955 | { | ||
1956 | #ifdef CONFIG_BLK_DEV_IDEPCI | ||
1957 | ide_scan_pcibus(ide_scan_direction); | ||
1958 | #endif /* CONFIG_BLK_DEV_IDEPCI */ | ||
1959 | |||
1960 | #ifdef CONFIG_ETRAX_IDE | ||
1961 | { | ||
1962 | extern void init_e100_ide(void); | ||
1963 | init_e100_ide(); | ||
1964 | } | ||
1965 | #endif /* CONFIG_ETRAX_IDE */ | ||
1966 | #ifdef CONFIG_BLK_DEV_CMD640 | ||
1967 | { | ||
1968 | extern void ide_probe_for_cmd640x(void); | ||
1969 | ide_probe_for_cmd640x(); | ||
1970 | } | ||
1971 | #endif /* CONFIG_BLK_DEV_CMD640 */ | ||
1972 | #ifdef CONFIG_BLK_DEV_IDE_PMAC | ||
1973 | { | ||
1974 | extern void pmac_ide_probe(void); | ||
1975 | pmac_ide_probe(); | ||
1976 | } | ||
1977 | #endif /* CONFIG_BLK_DEV_IDE_PMAC */ | ||
1978 | #ifdef CONFIG_BLK_DEV_GAYLE | ||
1979 | { | ||
1980 | extern void gayle_init(void); | ||
1981 | gayle_init(); | ||
1982 | } | ||
1983 | #endif /* CONFIG_BLK_DEV_GAYLE */ | ||
1984 | #ifdef CONFIG_BLK_DEV_FALCON_IDE | ||
1985 | { | ||
1986 | extern void falconide_init(void); | ||
1987 | falconide_init(); | ||
1988 | } | ||
1989 | #endif /* CONFIG_BLK_DEV_FALCON_IDE */ | ||
1990 | #ifdef CONFIG_BLK_DEV_MAC_IDE | ||
1991 | { | ||
1992 | extern void macide_init(void); | ||
1993 | macide_init(); | ||
1994 | } | ||
1995 | #endif /* CONFIG_BLK_DEV_MAC_IDE */ | ||
1996 | #ifdef CONFIG_BLK_DEV_Q40IDE | ||
1997 | { | ||
1998 | extern void q40ide_init(void); | ||
1999 | q40ide_init(); | ||
2000 | } | ||
2001 | #endif /* CONFIG_BLK_DEV_Q40IDE */ | ||
2002 | #ifdef CONFIG_BLK_DEV_BUDDHA | ||
2003 | { | ||
2004 | extern void buddha_init(void); | ||
2005 | buddha_init(); | ||
2006 | } | ||
2007 | #endif /* CONFIG_BLK_DEV_BUDDHA */ | ||
2008 | #ifdef CONFIG_BLK_DEV_IDEPNP | ||
2009 | pnpide_init(); | ||
2010 | #endif | ||
2011 | #ifdef CONFIG_H8300 | ||
2012 | h8300_ide_init(); | ||
2013 | #endif | ||
2014 | } | ||
2015 | |||
2016 | int ide_register_subdriver(ide_drive_t *drive, ide_driver_t *driver) | ||
2017 | { | ||
2018 | unsigned long flags; | ||
2019 | |||
2020 | spin_lock_irqsave(&ide_lock, flags); | ||
2021 | if (!drive->present || drive->driver != NULL || | ||
2022 | drive->usage || drive->dead) { | ||
2023 | spin_unlock_irqrestore(&ide_lock, flags); | ||
2024 | return 1; | ||
2025 | } | ||
2026 | drive->driver = driver; | ||
2027 | spin_unlock_irqrestore(&ide_lock, flags); | ||
2028 | spin_lock(&drives_lock); | ||
2029 | list_add_tail(&drive->list, driver ? &driver->drives : &ide_drives); | ||
2030 | spin_unlock(&drives_lock); | ||
2031 | // printk(KERN_INFO "%s: attached %s driver.\n", drive->name, driver->name); | ||
2032 | #ifdef CONFIG_PROC_FS | ||
2033 | if (driver) | ||
2034 | ide_add_proc_entries(drive->proc, driver->proc, drive); | ||
2035 | #endif | ||
2036 | return 0; | ||
2037 | } | ||
2038 | |||
2039 | EXPORT_SYMBOL(ide_register_subdriver); | ||
2040 | |||
2041 | /** | ||
2042 | * ide_unregister_subdriver - disconnect drive from driver | ||
2043 | * @drive: drive to unplug | ||
2044 | * | ||
2045 | * Disconnect a drive from the driver it was attached to and then | ||
2046 | * clean up the various proc files and other objects attached to it. | ||
2047 | * | ||
2048 | * Takes ide_setting_sem, ide_lock and drives_lock. | ||
2049 | * Caller must hold none of the locks. | ||
2050 | * | ||
2051 | * No locking versus subdriver unload because we are moving to the | ||
2052 | * default driver anyway. Wants double checking. | ||
2053 | */ | ||
2054 | |||
2055 | int ide_unregister_subdriver (ide_drive_t *drive) | ||
2056 | { | ||
2057 | unsigned long flags; | ||
2058 | |||
2059 | down(&ide_setting_sem); | ||
2060 | spin_lock_irqsave(&ide_lock, flags); | ||
2061 | if (drive->usage || drive->driver == NULL || DRIVER(drive)->busy) { | ||
2062 | spin_unlock_irqrestore(&ide_lock, flags); | ||
2063 | up(&ide_setting_sem); | ||
2064 | return 1; | ||
2065 | } | ||
2066 | #ifdef CONFIG_PROC_FS | ||
2067 | ide_remove_proc_entries(drive->proc, DRIVER(drive)->proc); | ||
2068 | #endif | ||
2069 | auto_remove_settings(drive); | ||
2070 | drive->driver = NULL; | ||
2071 | spin_unlock_irqrestore(&ide_lock, flags); | ||
2072 | up(&ide_setting_sem); | ||
2073 | spin_lock(&drives_lock); | ||
2074 | list_del_init(&drive->list); | ||
2075 | spin_unlock(&drives_lock); | ||
2076 | /* drive will be added to &ide_drives in ata_attach() */ | ||
2077 | return 0; | ||
2078 | } | ||
2079 | |||
2080 | EXPORT_SYMBOL(ide_unregister_subdriver); | ||
2081 | |||
2082 | static int ide_drive_remove(struct device * dev) | ||
2083 | { | ||
2084 | ide_drive_t * drive = container_of(dev,ide_drive_t,gendev); | ||
2085 | DRIVER(drive)->cleanup(drive); | ||
2086 | return 0; | ||
2087 | } | ||
2088 | |||
2089 | /** | ||
2090 | * ide_register_driver - register IDE device driver | ||
2091 | * @driver: the IDE device driver | ||
2092 | * | ||
2093 | * Register a new device driver and then scan the devices | ||
2094 | * on the IDE bus in case any should be attached to the | ||
2095 | * driver we have just registered. If so attach them. | ||
2096 | * | ||
2097 | * Takes drivers_lock and drives_lock. | ||
2098 | */ | ||
2099 | |||
2100 | int ide_register_driver(ide_driver_t *driver) | ||
2101 | { | ||
2102 | struct list_head list; | ||
2103 | struct list_head *list_loop; | ||
2104 | struct list_head *tmp_storage; | ||
2105 | |||
2106 | spin_lock(&drivers_lock); | ||
2107 | list_add(&driver->drivers, &drivers); | ||
2108 | spin_unlock(&drivers_lock); | ||
2109 | |||
2110 | INIT_LIST_HEAD(&list); | ||
2111 | spin_lock(&drives_lock); | ||
2112 | list_splice_init(&ide_drives, &list); | ||
2113 | spin_unlock(&drives_lock); | ||
2114 | |||
2115 | list_for_each_safe(list_loop, tmp_storage, &list) { | ||
2116 | ide_drive_t *drive = container_of(list_loop, ide_drive_t, list); | ||
2117 | list_del_init(&drive->list); | ||
2118 | if (drive->present) | ||
2119 | ata_attach(drive); | ||
2120 | } | ||
2121 | driver->gen_driver.name = (char *) driver->name; | ||
2122 | driver->gen_driver.bus = &ide_bus_type; | ||
2123 | driver->gen_driver.remove = ide_drive_remove; | ||
2124 | return driver_register(&driver->gen_driver); | ||
2125 | } | ||
2126 | |||
2127 | EXPORT_SYMBOL(ide_register_driver); | ||
2128 | |||
2129 | /** | ||
2130 | * ide_unregister_driver - unregister IDE device driver | ||
2131 | * @driver: the IDE device driver | ||
2132 | * | ||
2133 | * Called when a driver module is being unloaded. We reattach any | ||
2134 | * devices to whatever driver claims them next (typically the default | ||
2135 | * driver). | ||
2136 | * | ||
2137 | * Takes drivers_lock and called functions will take ide_setting_sem. | ||
2138 | */ | ||
2139 | |||
2140 | void ide_unregister_driver(ide_driver_t *driver) | ||
2141 | { | ||
2142 | ide_drive_t *drive; | ||
2143 | |||
2144 | spin_lock(&drivers_lock); | ||
2145 | list_del(&driver->drivers); | ||
2146 | spin_unlock(&drivers_lock); | ||
2147 | |||
2148 | driver_unregister(&driver->gen_driver); | ||
2149 | |||
2150 | while(!list_empty(&driver->drives)) { | ||
2151 | drive = list_entry(driver->drives.next, ide_drive_t, list); | ||
2152 | if (driver->cleanup(drive)) { | ||
2153 | printk(KERN_ERR "%s: cleanup_module() called while still busy\n", drive->name); | ||
2154 | BUG(); | ||
2155 | } | ||
2156 | ata_attach(drive); | ||
2157 | } | ||
2158 | } | ||
2159 | |||
2160 | EXPORT_SYMBOL(ide_unregister_driver); | ||
2161 | |||
2162 | /* | ||
2163 | * Probe module | ||
2164 | */ | ||
2165 | |||
2166 | EXPORT_SYMBOL(ide_lock); | ||
2167 | |||
2168 | struct bus_type ide_bus_type = { | ||
2169 | .name = "ide", | ||
2170 | .suspend = generic_ide_suspend, | ||
2171 | .resume = generic_ide_resume, | ||
2172 | }; | ||
2173 | |||
2174 | /* | ||
2175 | * This is gets invoked once during initialization, to set *everything* up | ||
2176 | */ | ||
2177 | static int __init ide_init(void) | ||
2178 | { | ||
2179 | printk(KERN_INFO "Uniform Multi-Platform E-IDE driver " REVISION "\n"); | ||
2180 | devfs_mk_dir("ide"); | ||
2181 | system_bus_speed = ide_system_bus_speed(); | ||
2182 | |||
2183 | bus_register(&ide_bus_type); | ||
2184 | |||
2185 | init_ide_data(); | ||
2186 | |||
2187 | #ifdef CONFIG_PROC_FS | ||
2188 | proc_ide_root = proc_mkdir("ide", NULL); | ||
2189 | #endif | ||
2190 | |||
2191 | #ifdef CONFIG_BLK_DEV_ALI14XX | ||
2192 | if (probe_ali14xx) | ||
2193 | (void)ali14xx_init(); | ||
2194 | #endif | ||
2195 | #ifdef CONFIG_BLK_DEV_UMC8672 | ||
2196 | if (probe_umc8672) | ||
2197 | (void)umc8672_init(); | ||
2198 | #endif | ||
2199 | #ifdef CONFIG_BLK_DEV_DTC2278 | ||
2200 | if (probe_dtc2278) | ||
2201 | (void)dtc2278_init(); | ||
2202 | #endif | ||
2203 | #ifdef CONFIG_BLK_DEV_HT6560B | ||
2204 | if (probe_ht6560b) | ||
2205 | (void)ht6560b_init(); | ||
2206 | #endif | ||
2207 | #ifdef CONFIG_BLK_DEV_QD65XX | ||
2208 | if (probe_qd65xx) | ||
2209 | (void)qd65xx_init(); | ||
2210 | #endif | ||
2211 | |||
2212 | initializing = 1; | ||
2213 | /* Probe for special PCI and other "known" interface chipsets. */ | ||
2214 | probe_for_hwifs(); | ||
2215 | initializing = 0; | ||
2216 | |||
2217 | #ifdef CONFIG_PROC_FS | ||
2218 | proc_ide_create(); | ||
2219 | #endif | ||
2220 | return 0; | ||
2221 | } | ||
2222 | |||
2223 | #ifdef MODULE | ||
2224 | static char *options = NULL; | ||
2225 | module_param(options, charp, 0); | ||
2226 | MODULE_LICENSE("GPL"); | ||
2227 | |||
2228 | static void __init parse_options (char *line) | ||
2229 | { | ||
2230 | char *next = line; | ||
2231 | |||
2232 | if (line == NULL || !*line) | ||
2233 | return; | ||
2234 | while ((line = next) != NULL) { | ||
2235 | if ((next = strchr(line,' ')) != NULL) | ||
2236 | *next++ = 0; | ||
2237 | if (!ide_setup(line)) | ||
2238 | printk (KERN_INFO "Unknown option '%s'\n", line); | ||
2239 | } | ||
2240 | } | ||
2241 | |||
2242 | int init_module (void) | ||
2243 | { | ||
2244 | parse_options(options); | ||
2245 | return ide_init(); | ||
2246 | } | ||
2247 | |||
2248 | void cleanup_module (void) | ||
2249 | { | ||
2250 | int index; | ||
2251 | |||
2252 | for (index = 0; index < MAX_HWIFS; ++index) | ||
2253 | ide_unregister(index); | ||
2254 | |||
2255 | #ifdef CONFIG_PROC_FS | ||
2256 | proc_ide_destroy(); | ||
2257 | #endif | ||
2258 | devfs_remove("ide"); | ||
2259 | |||
2260 | bus_unregister(&ide_bus_type); | ||
2261 | } | ||
2262 | |||
2263 | #else /* !MODULE */ | ||
2264 | |||
2265 | __setup("", ide_setup); | ||
2266 | |||
2267 | module_init(ide_init); | ||
2268 | |||
2269 | #endif /* MODULE */ | ||
diff --git a/drivers/ide/legacy/Makefile b/drivers/ide/legacy/Makefile new file mode 100644 index 000000000000..c7971061767e --- /dev/null +++ b/drivers/ide/legacy/Makefile | |||
@@ -0,0 +1,13 @@ | |||
1 | |||
2 | obj-$(CONFIG_BLK_DEV_ALI14XX) += ali14xx.o | ||
3 | obj-$(CONFIG_BLK_DEV_DTC2278) += dtc2278.o | ||
4 | obj-$(CONFIG_BLK_DEV_HT6560B) += ht6560b.o | ||
5 | obj-$(CONFIG_BLK_DEV_QD65XX) += qd65xx.o | ||
6 | obj-$(CONFIG_BLK_DEV_UMC8672) += umc8672.o | ||
7 | |||
8 | obj-$(CONFIG_BLK_DEV_IDECS) += ide-cs.o | ||
9 | |||
10 | # Last of all | ||
11 | obj-$(CONFIG_BLK_DEV_HD) += hd.o | ||
12 | |||
13 | EXTRA_CFLAGS := -Idrivers/ide | ||
diff --git a/drivers/ide/legacy/ali14xx.c b/drivers/ide/legacy/ali14xx.c new file mode 100644 index 000000000000..fb88711812e6 --- /dev/null +++ b/drivers/ide/legacy/ali14xx.c | |||
@@ -0,0 +1,253 @@ | |||
1 | /* | ||
2 | * linux/drivers/ide/legacy/ali14xx.c Version 0.03 Feb 09, 1996 | ||
3 | * | ||
4 | * Copyright (C) 1996 Linus Torvalds & author (see below) | ||
5 | */ | ||
6 | |||
7 | /* | ||
8 | * ALI M14xx chipset EIDE controller | ||
9 | * | ||
10 | * Works for ALI M1439/1443/1445/1487/1489 chipsets. | ||
11 | * | ||
12 | * Adapted from code developed by derekn@vw.ece.cmu.edu. -ml | ||
13 | * Derek's notes follow: | ||
14 | * | ||
15 | * I think the code should be pretty understandable, | ||
16 | * but I'll be happy to (try to) answer questions. | ||
17 | * | ||
18 | * The critical part is in the setupDrive function. The initRegisters | ||
19 | * function doesn't seem to be necessary, but the DOS driver does it, so | ||
20 | * I threw it in. | ||
21 | * | ||
22 | * I've only tested this on my system, which only has one disk. I posted | ||
23 | * it to comp.sys.linux.hardware, so maybe some other people will try it | ||
24 | * out. | ||
25 | * | ||
26 | * Derek Noonburg (derekn@ece.cmu.edu) | ||
27 | * 95-sep-26 | ||
28 | * | ||
29 | * Update 96-jul-13: | ||
30 | * | ||
31 | * I've since upgraded to two disks and a CD-ROM, with no trouble, and | ||
32 | * I've also heard from several others who have used it successfully. | ||
33 | * This driver appears to work with both the 1443/1445 and the 1487/1489 | ||
34 | * chipsets. I've added support for PIO mode 4 for the 1487. This | ||
35 | * seems to work just fine on the 1443 also, although I'm not sure it's | ||
36 | * advertised as supporting mode 4. (I've been running a WDC AC21200 in | ||
37 | * mode 4 for a while now with no trouble.) -Derek | ||
38 | */ | ||
39 | |||
40 | #undef REALLY_SLOW_IO /* most systems can safely undef this */ | ||
41 | |||
42 | #include <linux/module.h> | ||
43 | #include <linux/config.h> | ||
44 | #include <linux/types.h> | ||
45 | #include <linux/kernel.h> | ||
46 | #include <linux/delay.h> | ||
47 | #include <linux/timer.h> | ||
48 | #include <linux/mm.h> | ||
49 | #include <linux/ioport.h> | ||
50 | #include <linux/blkdev.h> | ||
51 | #include <linux/hdreg.h> | ||
52 | #include <linux/ide.h> | ||
53 | #include <linux/init.h> | ||
54 | |||
55 | #include <asm/io.h> | ||
56 | |||
57 | /* port addresses for auto-detection */ | ||
58 | #define ALI_NUM_PORTS 4 | ||
59 | static int ports[ALI_NUM_PORTS] __initdata = {0x074, 0x0f4, 0x034, 0x0e4}; | ||
60 | |||
61 | /* register initialization data */ | ||
62 | typedef struct { u8 reg, data; } RegInitializer; | ||
63 | |||
64 | static RegInitializer initData[] __initdata = { | ||
65 | {0x01, 0x0f}, {0x02, 0x00}, {0x03, 0x00}, {0x04, 0x00}, | ||
66 | {0x05, 0x00}, {0x06, 0x00}, {0x07, 0x2b}, {0x0a, 0x0f}, | ||
67 | {0x25, 0x00}, {0x26, 0x00}, {0x27, 0x00}, {0x28, 0x00}, | ||
68 | {0x29, 0x00}, {0x2a, 0x00}, {0x2f, 0x00}, {0x2b, 0x00}, | ||
69 | {0x2c, 0x00}, {0x2d, 0x00}, {0x2e, 0x00}, {0x30, 0x00}, | ||
70 | {0x31, 0x00}, {0x32, 0x00}, {0x33, 0x00}, {0x34, 0xff}, | ||
71 | {0x35, 0x03}, {0x00, 0x00} | ||
72 | }; | ||
73 | |||
74 | #define ALI_MAX_PIO 4 | ||
75 | |||
76 | /* timing parameter registers for each drive */ | ||
77 | static struct { u8 reg1, reg2, reg3, reg4; } regTab[4] = { | ||
78 | {0x03, 0x26, 0x04, 0x27}, /* drive 0 */ | ||
79 | {0x05, 0x28, 0x06, 0x29}, /* drive 1 */ | ||
80 | {0x2b, 0x30, 0x2c, 0x31}, /* drive 2 */ | ||
81 | {0x2d, 0x32, 0x2e, 0x33}, /* drive 3 */ | ||
82 | }; | ||
83 | |||
84 | static int basePort; /* base port address */ | ||
85 | static int regPort; /* port for register number */ | ||
86 | static int dataPort; /* port for register data */ | ||
87 | static u8 regOn; /* output to base port to access registers */ | ||
88 | static u8 regOff; /* output to base port to close registers */ | ||
89 | |||
90 | /*------------------------------------------------------------------------*/ | ||
91 | |||
92 | /* | ||
93 | * Read a controller register. | ||
94 | */ | ||
95 | static inline u8 inReg (u8 reg) | ||
96 | { | ||
97 | outb_p(reg, regPort); | ||
98 | return inb(dataPort); | ||
99 | } | ||
100 | |||
101 | /* | ||
102 | * Write a controller register. | ||
103 | */ | ||
104 | static void outReg (u8 data, u8 reg) | ||
105 | { | ||
106 | outb_p(reg, regPort); | ||
107 | outb_p(data, dataPort); | ||
108 | } | ||
109 | |||
110 | /* | ||
111 | * Set PIO mode for the specified drive. | ||
112 | * This function computes timing parameters | ||
113 | * and sets controller registers accordingly. | ||
114 | */ | ||
115 | static void ali14xx_tune_drive (ide_drive_t *drive, u8 pio) | ||
116 | { | ||
117 | int driveNum; | ||
118 | int time1, time2; | ||
119 | u8 param1, param2, param3, param4; | ||
120 | unsigned long flags; | ||
121 | ide_pio_data_t d; | ||
122 | int bus_speed = system_bus_clock(); | ||
123 | |||
124 | pio = ide_get_best_pio_mode(drive, pio, ALI_MAX_PIO, &d); | ||
125 | |||
126 | /* calculate timing, according to PIO mode */ | ||
127 | time1 = d.cycle_time; | ||
128 | time2 = ide_pio_timings[pio].active_time; | ||
129 | param3 = param1 = (time2 * bus_speed + 999) / 1000; | ||
130 | param4 = param2 = (time1 * bus_speed + 999) / 1000 - param1; | ||
131 | if (pio < 3) { | ||
132 | param3 += 8; | ||
133 | param4 += 8; | ||
134 | } | ||
135 | printk(KERN_DEBUG "%s: PIO mode%d, t1=%dns, t2=%dns, cycles = %d+%d, %d+%d\n", | ||
136 | drive->name, pio, time1, time2, param1, param2, param3, param4); | ||
137 | |||
138 | /* stuff timing parameters into controller registers */ | ||
139 | driveNum = (HWIF(drive)->index << 1) + drive->select.b.unit; | ||
140 | spin_lock_irqsave(&ide_lock, flags); | ||
141 | outb_p(regOn, basePort); | ||
142 | outReg(param1, regTab[driveNum].reg1); | ||
143 | outReg(param2, regTab[driveNum].reg2); | ||
144 | outReg(param3, regTab[driveNum].reg3); | ||
145 | outReg(param4, regTab[driveNum].reg4); | ||
146 | outb_p(regOff, basePort); | ||
147 | spin_unlock_irqrestore(&ide_lock, flags); | ||
148 | } | ||
149 | |||
150 | /* | ||
151 | * Auto-detect the IDE controller port. | ||
152 | */ | ||
153 | static int __init findPort (void) | ||
154 | { | ||
155 | int i; | ||
156 | u8 t; | ||
157 | unsigned long flags; | ||
158 | |||
159 | local_irq_save(flags); | ||
160 | for (i = 0; i < ALI_NUM_PORTS; ++i) { | ||
161 | basePort = ports[i]; | ||
162 | regOff = inb(basePort); | ||
163 | for (regOn = 0x30; regOn <= 0x33; ++regOn) { | ||
164 | outb_p(regOn, basePort); | ||
165 | if (inb(basePort) == regOn) { | ||
166 | regPort = basePort + 4; | ||
167 | dataPort = basePort + 8; | ||
168 | t = inReg(0) & 0xf0; | ||
169 | outb_p(regOff, basePort); | ||
170 | local_irq_restore(flags); | ||
171 | if (t != 0x50) | ||
172 | return 0; | ||
173 | return 1; /* success */ | ||
174 | } | ||
175 | } | ||
176 | outb_p(regOff, basePort); | ||
177 | } | ||
178 | local_irq_restore(flags); | ||
179 | return 0; | ||
180 | } | ||
181 | |||
182 | /* | ||
183 | * Initialize controller registers with default values. | ||
184 | */ | ||
185 | static int __init initRegisters (void) { | ||
186 | RegInitializer *p; | ||
187 | u8 t; | ||
188 | unsigned long flags; | ||
189 | |||
190 | local_irq_save(flags); | ||
191 | outb_p(regOn, basePort); | ||
192 | for (p = initData; p->reg != 0; ++p) | ||
193 | outReg(p->data, p->reg); | ||
194 | outb_p(0x01, regPort); | ||
195 | t = inb(regPort) & 0x01; | ||
196 | outb_p(regOff, basePort); | ||
197 | local_irq_restore(flags); | ||
198 | return t; | ||
199 | } | ||
200 | |||
201 | static int __init ali14xx_probe(void) | ||
202 | { | ||
203 | ide_hwif_t *hwif, *mate; | ||
204 | |||
205 | printk(KERN_DEBUG "ali14xx: base=0x%03x, regOn=0x%02x.\n", | ||
206 | basePort, regOn); | ||
207 | |||
208 | /* initialize controller registers */ | ||
209 | if (!initRegisters()) { | ||
210 | printk(KERN_ERR "ali14xx: Chip initialization failed.\n"); | ||
211 | return 1; | ||
212 | } | ||
213 | |||
214 | hwif = &ide_hwifs[0]; | ||
215 | mate = &ide_hwifs[1]; | ||
216 | |||
217 | hwif->chipset = ide_ali14xx; | ||
218 | hwif->tuneproc = &ali14xx_tune_drive; | ||
219 | hwif->mate = mate; | ||
220 | |||
221 | mate->chipset = ide_ali14xx; | ||
222 | mate->tuneproc = &ali14xx_tune_drive; | ||
223 | mate->mate = hwif; | ||
224 | mate->channel = 1; | ||
225 | |||
226 | probe_hwif_init(hwif); | ||
227 | probe_hwif_init(mate); | ||
228 | |||
229 | create_proc_ide_interfaces(); | ||
230 | |||
231 | return 0; | ||
232 | } | ||
233 | |||
234 | /* Can be called directly from ide.c. */ | ||
235 | int __init ali14xx_init(void) | ||
236 | { | ||
237 | /* auto-detect IDE controller port */ | ||
238 | if (findPort()) { | ||
239 | if (ali14xx_probe()) | ||
240 | return -ENODEV; | ||
241 | return 0; | ||
242 | } | ||
243 | printk(KERN_ERR "ali14xx: not found.\n"); | ||
244 | return -ENODEV; | ||
245 | } | ||
246 | |||
247 | #ifdef MODULE | ||
248 | module_init(ali14xx_init); | ||
249 | #endif | ||
250 | |||
251 | MODULE_AUTHOR("see local file"); | ||
252 | MODULE_DESCRIPTION("support of ALI 14XX IDE chipsets"); | ||
253 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/ide/legacy/buddha.c b/drivers/ide/legacy/buddha.c new file mode 100644 index 000000000000..0391a3122878 --- /dev/null +++ b/drivers/ide/legacy/buddha.c | |||
@@ -0,0 +1,235 @@ | |||
1 | /* | ||
2 | * linux/drivers/ide/legacy/buddha.c -- Amiga Buddha, Catweasel and X-Surf IDE Driver | ||
3 | * | ||
4 | * Copyright (C) 1997, 2001 by Geert Uytterhoeven and others | ||
5 | * | ||
6 | * This driver was written based on the specifications in README.buddha and | ||
7 | * the X-Surf info from Inside_XSurf.txt available at | ||
8 | * http://www.jschoenfeld.com | ||
9 | * | ||
10 | * This file is subject to the terms and conditions of the GNU General Public | ||
11 | * License. See the file COPYING in the main directory of this archive for | ||
12 | * more details. | ||
13 | * | ||
14 | * TODO: | ||
15 | * - test it :-) | ||
16 | * - tune the timings using the speed-register | ||
17 | */ | ||
18 | |||
19 | #include <linux/types.h> | ||
20 | #include <linux/mm.h> | ||
21 | #include <linux/interrupt.h> | ||
22 | #include <linux/blkdev.h> | ||
23 | #include <linux/hdreg.h> | ||
24 | #include <linux/zorro.h> | ||
25 | #include <linux/ide.h> | ||
26 | #include <linux/init.h> | ||
27 | |||
28 | #include <asm/amigahw.h> | ||
29 | #include <asm/amigaints.h> | ||
30 | |||
31 | |||
32 | /* | ||
33 | * The Buddha has 2 IDE interfaces, the Catweasel has 3, X-Surf has 2 | ||
34 | */ | ||
35 | |||
36 | #define BUDDHA_NUM_HWIFS 2 | ||
37 | #define CATWEASEL_NUM_HWIFS 3 | ||
38 | #define XSURF_NUM_HWIFS 2 | ||
39 | |||
40 | /* | ||
41 | * Bases of the IDE interfaces (relative to the board address) | ||
42 | */ | ||
43 | |||
44 | #define BUDDHA_BASE1 0x800 | ||
45 | #define BUDDHA_BASE2 0xa00 | ||
46 | #define BUDDHA_BASE3 0xc00 | ||
47 | |||
48 | #define XSURF_BASE1 0xb000 /* 2.5" Interface */ | ||
49 | #define XSURF_BASE2 0xd000 /* 3.5" Interface */ | ||
50 | |||
51 | static u_int buddha_bases[CATWEASEL_NUM_HWIFS] __initdata = { | ||
52 | BUDDHA_BASE1, BUDDHA_BASE2, BUDDHA_BASE3 | ||
53 | }; | ||
54 | |||
55 | static u_int xsurf_bases[XSURF_NUM_HWIFS] __initdata = { | ||
56 | XSURF_BASE1, XSURF_BASE2 | ||
57 | }; | ||
58 | |||
59 | |||
60 | /* | ||
61 | * Offsets from one of the above bases | ||
62 | */ | ||
63 | |||
64 | #define BUDDHA_DATA 0x00 | ||
65 | #define BUDDHA_ERROR 0x06 /* see err-bits */ | ||
66 | #define BUDDHA_NSECTOR 0x0a /* nr of sectors to read/write */ | ||
67 | #define BUDDHA_SECTOR 0x0e /* starting sector */ | ||
68 | #define BUDDHA_LCYL 0x12 /* starting cylinder */ | ||
69 | #define BUDDHA_HCYL 0x16 /* high byte of starting cyl */ | ||
70 | #define BUDDHA_SELECT 0x1a /* 101dhhhh , d=drive, hhhh=head */ | ||
71 | #define BUDDHA_STATUS 0x1e /* see status-bits */ | ||
72 | #define BUDDHA_CONTROL 0x11a | ||
73 | #define XSURF_CONTROL -1 /* X-Surf has no CS1* (Control/AltStat) */ | ||
74 | |||
75 | static int buddha_offsets[IDE_NR_PORTS] __initdata = { | ||
76 | BUDDHA_DATA, BUDDHA_ERROR, BUDDHA_NSECTOR, BUDDHA_SECTOR, BUDDHA_LCYL, | ||
77 | BUDDHA_HCYL, BUDDHA_SELECT, BUDDHA_STATUS, BUDDHA_CONTROL, -1 | ||
78 | }; | ||
79 | |||
80 | static int xsurf_offsets[IDE_NR_PORTS] __initdata = { | ||
81 | BUDDHA_DATA, BUDDHA_ERROR, BUDDHA_NSECTOR, BUDDHA_SECTOR, BUDDHA_LCYL, | ||
82 | BUDDHA_HCYL, BUDDHA_SELECT, BUDDHA_STATUS, XSURF_CONTROL, -1 | ||
83 | }; | ||
84 | |||
85 | /* | ||
86 | * Other registers | ||
87 | */ | ||
88 | |||
89 | #define BUDDHA_IRQ1 0xf00 /* MSB = 1, Harddisk is source of */ | ||
90 | #define BUDDHA_IRQ2 0xf40 /* interrupt */ | ||
91 | #define BUDDHA_IRQ3 0xf80 | ||
92 | |||
93 | #define XSURF_IRQ1 0x7e | ||
94 | #define XSURF_IRQ2 0x7e | ||
95 | |||
96 | static int buddha_irqports[CATWEASEL_NUM_HWIFS] __initdata = { | ||
97 | BUDDHA_IRQ1, BUDDHA_IRQ2, BUDDHA_IRQ3 | ||
98 | }; | ||
99 | |||
100 | static int xsurf_irqports[XSURF_NUM_HWIFS] __initdata = { | ||
101 | XSURF_IRQ1, XSURF_IRQ2 | ||
102 | }; | ||
103 | |||
104 | #define BUDDHA_IRQ_MR 0xfc0 /* master interrupt enable */ | ||
105 | |||
106 | |||
107 | /* | ||
108 | * Board information | ||
109 | */ | ||
110 | |||
111 | typedef enum BuddhaType_Enum { | ||
112 | BOARD_BUDDHA, BOARD_CATWEASEL, BOARD_XSURF | ||
113 | } BuddhaType; | ||
114 | |||
115 | |||
116 | /* | ||
117 | * Check and acknowledge the interrupt status | ||
118 | */ | ||
119 | |||
120 | static int buddha_ack_intr(ide_hwif_t *hwif) | ||
121 | { | ||
122 | unsigned char ch; | ||
123 | |||
124 | ch = z_readb(hwif->io_ports[IDE_IRQ_OFFSET]); | ||
125 | if (!(ch & 0x80)) | ||
126 | return 0; | ||
127 | return 1; | ||
128 | } | ||
129 | |||
130 | static int xsurf_ack_intr(ide_hwif_t *hwif) | ||
131 | { | ||
132 | unsigned char ch; | ||
133 | |||
134 | ch = z_readb(hwif->io_ports[IDE_IRQ_OFFSET]); | ||
135 | /* X-Surf needs a 0 written to IRQ register to ensure ISA bit A11 stays at 0 */ | ||
136 | z_writeb(0, hwif->io_ports[IDE_IRQ_OFFSET]); | ||
137 | if (!(ch & 0x80)) | ||
138 | return 0; | ||
139 | return 1; | ||
140 | } | ||
141 | |||
142 | /* | ||
143 | * Probe for a Buddha or Catweasel IDE interface | ||
144 | */ | ||
145 | |||
146 | void __init buddha_init(void) | ||
147 | { | ||
148 | hw_regs_t hw; | ||
149 | ide_hwif_t *hwif; | ||
150 | int i, index; | ||
151 | |||
152 | struct zorro_dev *z = NULL; | ||
153 | u_long buddha_board = 0; | ||
154 | BuddhaType type; | ||
155 | int buddha_num_hwifs; | ||
156 | |||
157 | while ((z = zorro_find_device(ZORRO_WILDCARD, z))) { | ||
158 | unsigned long board; | ||
159 | if (z->id == ZORRO_PROD_INDIVIDUAL_COMPUTERS_BUDDHA) { | ||
160 | buddha_num_hwifs = BUDDHA_NUM_HWIFS; | ||
161 | type=BOARD_BUDDHA; | ||
162 | } else if (z->id == ZORRO_PROD_INDIVIDUAL_COMPUTERS_CATWEASEL) { | ||
163 | buddha_num_hwifs = CATWEASEL_NUM_HWIFS; | ||
164 | type=BOARD_CATWEASEL; | ||
165 | } else if (z->id == ZORRO_PROD_INDIVIDUAL_COMPUTERS_X_SURF) { | ||
166 | buddha_num_hwifs = XSURF_NUM_HWIFS; | ||
167 | type=BOARD_XSURF; | ||
168 | } else | ||
169 | continue; | ||
170 | |||
171 | board = z->resource.start; | ||
172 | |||
173 | /* | ||
174 | * FIXME: we now have selectable mmio v/s iomio transports. | ||
175 | */ | ||
176 | |||
177 | if(type != BOARD_XSURF) { | ||
178 | if (!request_mem_region(board+BUDDHA_BASE1, 0x800, "IDE")) | ||
179 | continue; | ||
180 | } else { | ||
181 | if (!request_mem_region(board+XSURF_BASE1, 0x1000, "IDE")) | ||
182 | continue; | ||
183 | if (!request_mem_region(board+XSURF_BASE2, 0x1000, "IDE")) | ||
184 | goto fail_base2; | ||
185 | if (!request_mem_region(board+XSURF_IRQ1, 0x8, "IDE")) { | ||
186 | release_mem_region(board+XSURF_BASE2, 0x1000); | ||
187 | fail_base2: | ||
188 | release_mem_region(board+XSURF_BASE1, 0x1000); | ||
189 | continue; | ||
190 | } | ||
191 | } | ||
192 | buddha_board = ZTWO_VADDR(board); | ||
193 | |||
194 | /* write to BUDDHA_IRQ_MR to enable the board IRQ */ | ||
195 | /* X-Surf doesn't have this. IRQs are always on */ | ||
196 | if (type != BOARD_XSURF) | ||
197 | z_writeb(0, buddha_board+BUDDHA_IRQ_MR); | ||
198 | |||
199 | for(i=0;i<buddha_num_hwifs;i++) { | ||
200 | if(type != BOARD_XSURF) { | ||
201 | ide_setup_ports(&hw, (buddha_board+buddha_bases[i]), | ||
202 | buddha_offsets, 0, | ||
203 | (buddha_board+buddha_irqports[i]), | ||
204 | buddha_ack_intr, | ||
205 | // budda_iops, | ||
206 | IRQ_AMIGA_PORTS); | ||
207 | } else { | ||
208 | ide_setup_ports(&hw, (buddha_board+xsurf_bases[i]), | ||
209 | xsurf_offsets, 0, | ||
210 | (buddha_board+xsurf_irqports[i]), | ||
211 | xsurf_ack_intr, | ||
212 | // xsurf_iops, | ||
213 | IRQ_AMIGA_PORTS); | ||
214 | } | ||
215 | |||
216 | index = ide_register_hw(&hw, &hwif); | ||
217 | if (index != -1) { | ||
218 | hwif->mmio = 2; | ||
219 | printk("ide%d: ", index); | ||
220 | switch(type) { | ||
221 | case BOARD_BUDDHA: | ||
222 | printk("Buddha"); | ||
223 | break; | ||
224 | case BOARD_CATWEASEL: | ||
225 | printk("Catweasel"); | ||
226 | break; | ||
227 | case BOARD_XSURF: | ||
228 | printk("X-Surf"); | ||
229 | break; | ||
230 | } | ||
231 | printk(" IDE interface\n"); | ||
232 | } | ||
233 | } | ||
234 | } | ||
235 | } | ||
diff --git a/drivers/ide/legacy/dtc2278.c b/drivers/ide/legacy/dtc2278.c new file mode 100644 index 000000000000..20eb5b872ca9 --- /dev/null +++ b/drivers/ide/legacy/dtc2278.c | |||
@@ -0,0 +1,165 @@ | |||
1 | /* | ||
2 | * linux/drivers/ide/legacy/dtc2278.c Version 0.02 Feb 10, 1996 | ||
3 | * | ||
4 | * Copyright (C) 1996 Linus Torvalds & author (see below) | ||
5 | */ | ||
6 | |||
7 | #undef REALLY_SLOW_IO /* most systems can safely undef this */ | ||
8 | |||
9 | #include <linux/module.h> | ||
10 | #include <linux/config.h> | ||
11 | #include <linux/types.h> | ||
12 | #include <linux/kernel.h> | ||
13 | #include <linux/delay.h> | ||
14 | #include <linux/timer.h> | ||
15 | #include <linux/mm.h> | ||
16 | #include <linux/ioport.h> | ||
17 | #include <linux/blkdev.h> | ||
18 | #include <linux/hdreg.h> | ||
19 | #include <linux/ide.h> | ||
20 | #include <linux/init.h> | ||
21 | |||
22 | #include <asm/io.h> | ||
23 | |||
24 | /* | ||
25 | * Changing this #undef to #define may solve start up problems in some systems. | ||
26 | */ | ||
27 | #undef ALWAYS_SET_DTC2278_PIO_MODE | ||
28 | |||
29 | /* | ||
30 | * From: andy@cercle.cts.com (Dyan Wile) | ||
31 | * | ||
32 | * Below is a patch for DTC-2278 - alike software-programmable controllers | ||
33 | * The code enables the secondary IDE controller and the PIO4 (3?) timings on | ||
34 | * the primary (EIDE). You may probably have to enable the 32-bit support to | ||
35 | * get the full speed. You better get the disk interrupts disabled ( hdparm -u0 | ||
36 | * /dev/hd.. ) for the drives connected to the EIDE interface. (I get my | ||
37 | * filesystem corrupted with -u1, but under heavy disk load only :-) | ||
38 | * | ||
39 | * This card is now forced to use the "serialize" feature, | ||
40 | * and irq-unmasking is disallowed. If io_32bit is enabled, | ||
41 | * it must be done for BOTH drives on each interface. | ||
42 | * | ||
43 | * This code was written for the DTC2278E, but might work with any of these: | ||
44 | * | ||
45 | * DTC2278S has only a single IDE interface. | ||
46 | * DTC2278D has two IDE interfaces and is otherwise identical to the S version. | ||
47 | * DTC2278E also has serial ports and a printer port | ||
48 | * DTC2278EB: has onboard BIOS, and "works like a charm" -- Kent Bradford <kent@theory.caltech.edu> | ||
49 | * | ||
50 | * There may be a fourth controller type. The S and D versions use the | ||
51 | * Winbond chip, and I think the E version does also. | ||
52 | * | ||
53 | */ | ||
54 | |||
55 | static void sub22 (char b, char c) | ||
56 | { | ||
57 | int i; | ||
58 | |||
59 | for(i = 0; i < 3; ++i) { | ||
60 | inb(0x3f6); | ||
61 | outb_p(b,0xb0); | ||
62 | inb(0x3f6); | ||
63 | outb_p(c,0xb4); | ||
64 | inb(0x3f6); | ||
65 | if(inb(0xb4) == c) { | ||
66 | outb_p(7,0xb0); | ||
67 | inb(0x3f6); | ||
68 | return; /* success */ | ||
69 | } | ||
70 | } | ||
71 | } | ||
72 | |||
73 | static void tune_dtc2278 (ide_drive_t *drive, u8 pio) | ||
74 | { | ||
75 | unsigned long flags; | ||
76 | |||
77 | pio = ide_get_best_pio_mode(drive, pio, 4, NULL); | ||
78 | |||
79 | if (pio >= 3) { | ||
80 | spin_lock_irqsave(&ide_lock, flags); | ||
81 | /* | ||
82 | * This enables PIO mode4 (3?) on the first interface | ||
83 | */ | ||
84 | sub22(1,0xc3); | ||
85 | sub22(0,0xa0); | ||
86 | spin_unlock_irqrestore(&ide_lock, flags); | ||
87 | } else { | ||
88 | /* we don't know how to set it back again.. */ | ||
89 | } | ||
90 | |||
91 | /* | ||
92 | * 32bit I/O has to be enabled for *both* drives at the same time. | ||
93 | */ | ||
94 | drive->io_32bit = 1; | ||
95 | HWIF(drive)->drives[!drive->select.b.unit].io_32bit = 1; | ||
96 | } | ||
97 | |||
98 | static int __init probe_dtc2278(void) | ||
99 | { | ||
100 | unsigned long flags; | ||
101 | ide_hwif_t *hwif, *mate; | ||
102 | |||
103 | hwif = &ide_hwifs[0]; | ||
104 | mate = &ide_hwifs[1]; | ||
105 | |||
106 | if (hwif->chipset != ide_unknown || mate->chipset != ide_unknown) | ||
107 | return 1; | ||
108 | |||
109 | local_irq_save(flags); | ||
110 | /* | ||
111 | * This enables the second interface | ||
112 | */ | ||
113 | outb_p(4,0xb0); | ||
114 | inb(0x3f6); | ||
115 | outb_p(0x20,0xb4); | ||
116 | inb(0x3f6); | ||
117 | #ifdef ALWAYS_SET_DTC2278_PIO_MODE | ||
118 | /* | ||
119 | * This enables PIO mode4 (3?) on the first interface | ||
120 | * and may solve start-up problems for some people. | ||
121 | */ | ||
122 | sub22(1,0xc3); | ||
123 | sub22(0,0xa0); | ||
124 | #endif | ||
125 | local_irq_restore(flags); | ||
126 | |||
127 | hwif->serialized = 1; | ||
128 | hwif->chipset = ide_dtc2278; | ||
129 | hwif->tuneproc = &tune_dtc2278; | ||
130 | hwif->drives[0].no_unmask = 1; | ||
131 | hwif->drives[1].no_unmask = 1; | ||
132 | hwif->mate = mate; | ||
133 | |||
134 | mate->serialized = 1; | ||
135 | mate->chipset = ide_dtc2278; | ||
136 | mate->drives[0].no_unmask = 1; | ||
137 | mate->drives[1].no_unmask = 1; | ||
138 | mate->mate = hwif; | ||
139 | mate->channel = 1; | ||
140 | |||
141 | probe_hwif_init(hwif); | ||
142 | probe_hwif_init(mate); | ||
143 | |||
144 | create_proc_ide_interfaces(); | ||
145 | |||
146 | return 0; | ||
147 | } | ||
148 | |||
149 | /* Can be called directly from ide.c. */ | ||
150 | int __init dtc2278_init(void) | ||
151 | { | ||
152 | if (probe_dtc2278()) { | ||
153 | printk(KERN_ERR "dtc2278: ide interfaces already in use!\n"); | ||
154 | return -EBUSY; | ||
155 | } | ||
156 | return 0; | ||
157 | } | ||
158 | |||
159 | #ifdef MODULE | ||
160 | module_init(dtc2278_init); | ||
161 | #endif | ||
162 | |||
163 | MODULE_AUTHOR("See Local File"); | ||
164 | MODULE_DESCRIPTION("support of DTC-2278 VLB IDE chipsets"); | ||
165 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/ide/legacy/falconide.c b/drivers/ide/legacy/falconide.c new file mode 100644 index 000000000000..a9f2cd5bb81e --- /dev/null +++ b/drivers/ide/legacy/falconide.c | |||
@@ -0,0 +1,78 @@ | |||
1 | /* | ||
2 | * linux/drivers/ide/legacy/falconide.c -- Atari Falcon IDE Driver | ||
3 | * | ||
4 | * Created 12 Jul 1997 by Geert Uytterhoeven | ||
5 | * | ||
6 | * This file is subject to the terms and conditions of the GNU General Public | ||
7 | * License. See the file COPYING in the main directory of this archive for | ||
8 | * more details. | ||
9 | */ | ||
10 | |||
11 | #include <linux/types.h> | ||
12 | #include <linux/mm.h> | ||
13 | #include <linux/interrupt.h> | ||
14 | #include <linux/blkdev.h> | ||
15 | #include <linux/hdreg.h> | ||
16 | #include <linux/ide.h> | ||
17 | #include <linux/init.h> | ||
18 | |||
19 | #include <asm/setup.h> | ||
20 | #include <asm/atarihw.h> | ||
21 | #include <asm/atariints.h> | ||
22 | #include <asm/atari_stdma.h> | ||
23 | |||
24 | |||
25 | /* | ||
26 | * Base of the IDE interface | ||
27 | */ | ||
28 | |||
29 | #define ATA_HD_BASE 0xfff00000 | ||
30 | |||
31 | /* | ||
32 | * Offsets from the above base | ||
33 | */ | ||
34 | |||
35 | #define ATA_HD_DATA 0x00 | ||
36 | #define ATA_HD_ERROR 0x05 /* see err-bits */ | ||
37 | #define ATA_HD_NSECTOR 0x09 /* nr of sectors to read/write */ | ||
38 | #define ATA_HD_SECTOR 0x0d /* starting sector */ | ||
39 | #define ATA_HD_LCYL 0x11 /* starting cylinder */ | ||
40 | #define ATA_HD_HCYL 0x15 /* high byte of starting cyl */ | ||
41 | #define ATA_HD_SELECT 0x19 /* 101dhhhh , d=drive, hhhh=head */ | ||
42 | #define ATA_HD_STATUS 0x1d /* see status-bits */ | ||
43 | #define ATA_HD_CONTROL 0x39 | ||
44 | |||
45 | static int falconide_offsets[IDE_NR_PORTS] __initdata = { | ||
46 | ATA_HD_DATA, ATA_HD_ERROR, ATA_HD_NSECTOR, ATA_HD_SECTOR, ATA_HD_LCYL, | ||
47 | ATA_HD_HCYL, ATA_HD_SELECT, ATA_HD_STATUS, ATA_HD_CONTROL, -1 | ||
48 | }; | ||
49 | |||
50 | |||
51 | /* | ||
52 | * falconide_intr_lock is used to obtain access to the IDE interrupt, | ||
53 | * which is shared between several drivers. | ||
54 | */ | ||
55 | |||
56 | int falconide_intr_lock; | ||
57 | |||
58 | |||
59 | /* | ||
60 | * Probe for a Falcon IDE interface | ||
61 | */ | ||
62 | |||
63 | void __init falconide_init(void) | ||
64 | { | ||
65 | if (MACH_IS_ATARI && ATARIHW_PRESENT(IDE)) { | ||
66 | hw_regs_t hw; | ||
67 | int index; | ||
68 | |||
69 | ide_setup_ports(&hw, ATA_HD_BASE, falconide_offsets, | ||
70 | 0, 0, NULL, | ||
71 | // falconide_iops, | ||
72 | IRQ_MFP_IDE); | ||
73 | index = ide_register_hw(&hw, NULL); | ||
74 | |||
75 | if (index != -1) | ||
76 | printk("ide%d: Falcon IDE interface\n", index); | ||
77 | } | ||
78 | } | ||
diff --git a/drivers/ide/legacy/gayle.c b/drivers/ide/legacy/gayle.c new file mode 100644 index 000000000000..3fac3e9ec47d --- /dev/null +++ b/drivers/ide/legacy/gayle.c | |||
@@ -0,0 +1,186 @@ | |||
1 | /* | ||
2 | * linux/drivers/ide/legacy/gayle.c -- Amiga Gayle IDE Driver | ||
3 | * | ||
4 | * Created 9 Jul 1997 by Geert Uytterhoeven | ||
5 | * | ||
6 | * This file is subject to the terms and conditions of the GNU General Public | ||
7 | * License. See the file COPYING in the main directory of this archive for | ||
8 | * more details. | ||
9 | */ | ||
10 | |||
11 | #include <linux/config.h> | ||
12 | #include <linux/types.h> | ||
13 | #include <linux/mm.h> | ||
14 | #include <linux/interrupt.h> | ||
15 | #include <linux/blkdev.h> | ||
16 | #include <linux/hdreg.h> | ||
17 | #include <linux/ide.h> | ||
18 | #include <linux/init.h> | ||
19 | #include <linux/zorro.h> | ||
20 | |||
21 | #include <asm/setup.h> | ||
22 | #include <asm/amigahw.h> | ||
23 | #include <asm/amigaints.h> | ||
24 | #include <asm/amigayle.h> | ||
25 | |||
26 | |||
27 | /* | ||
28 | * Bases of the IDE interfaces | ||
29 | */ | ||
30 | |||
31 | #define GAYLE_BASE_4000 0xdd2020 /* A4000/A4000T */ | ||
32 | #define GAYLE_BASE_1200 0xda0000 /* A1200/A600 and E-Matrix 530 */ | ||
33 | |||
34 | /* | ||
35 | * Offsets from one of the above bases | ||
36 | */ | ||
37 | |||
38 | #define GAYLE_DATA 0x00 | ||
39 | #define GAYLE_ERROR 0x06 /* see err-bits */ | ||
40 | #define GAYLE_NSECTOR 0x0a /* nr of sectors to read/write */ | ||
41 | #define GAYLE_SECTOR 0x0e /* starting sector */ | ||
42 | #define GAYLE_LCYL 0x12 /* starting cylinder */ | ||
43 | #define GAYLE_HCYL 0x16 /* high byte of starting cyl */ | ||
44 | #define GAYLE_SELECT 0x1a /* 101dhhhh , d=drive, hhhh=head */ | ||
45 | #define GAYLE_STATUS 0x1e /* see status-bits */ | ||
46 | #define GAYLE_CONTROL 0x101a | ||
47 | |||
48 | static int gayle_offsets[IDE_NR_PORTS] __initdata = { | ||
49 | GAYLE_DATA, GAYLE_ERROR, GAYLE_NSECTOR, GAYLE_SECTOR, GAYLE_LCYL, | ||
50 | GAYLE_HCYL, GAYLE_SELECT, GAYLE_STATUS, -1, -1 | ||
51 | }; | ||
52 | |||
53 | |||
54 | /* | ||
55 | * These are at different offsets from the base | ||
56 | */ | ||
57 | |||
58 | #define GAYLE_IRQ_4000 0xdd3020 /* MSB = 1, Harddisk is source of */ | ||
59 | #define GAYLE_IRQ_1200 0xda9000 /* interrupt */ | ||
60 | |||
61 | |||
62 | /* | ||
63 | * Offset of the secondary port for IDE doublers | ||
64 | * Note that GAYLE_CONTROL is NOT available then! | ||
65 | */ | ||
66 | |||
67 | #define GAYLE_NEXT_PORT 0x1000 | ||
68 | |||
69 | #ifndef CONFIG_BLK_DEV_IDEDOUBLER | ||
70 | #define GAYLE_NUM_HWIFS 1 | ||
71 | #define GAYLE_NUM_PROBE_HWIFS GAYLE_NUM_HWIFS | ||
72 | #define GAYLE_HAS_CONTROL_REG 1 | ||
73 | #define GAYLE_IDEREG_SIZE 0x2000 | ||
74 | #else /* CONFIG_BLK_DEV_IDEDOUBLER */ | ||
75 | #define GAYLE_NUM_HWIFS 2 | ||
76 | #define GAYLE_NUM_PROBE_HWIFS (ide_doubler ? GAYLE_NUM_HWIFS : \ | ||
77 | GAYLE_NUM_HWIFS-1) | ||
78 | #define GAYLE_HAS_CONTROL_REG (!ide_doubler) | ||
79 | #define GAYLE_IDEREG_SIZE (ide_doubler ? 0x1000 : 0x2000) | ||
80 | int ide_doubler = 0; /* support IDE doublers? */ | ||
81 | #endif /* CONFIG_BLK_DEV_IDEDOUBLER */ | ||
82 | |||
83 | |||
84 | /* | ||
85 | * Check and acknowledge the interrupt status | ||
86 | */ | ||
87 | |||
88 | static int gayle_ack_intr_a4000(ide_hwif_t *hwif) | ||
89 | { | ||
90 | unsigned char ch; | ||
91 | |||
92 | ch = z_readb(hwif->io_ports[IDE_IRQ_OFFSET]); | ||
93 | if (!(ch & GAYLE_IRQ_IDE)) | ||
94 | return 0; | ||
95 | return 1; | ||
96 | } | ||
97 | |||
98 | static int gayle_ack_intr_a1200(ide_hwif_t *hwif) | ||
99 | { | ||
100 | unsigned char ch; | ||
101 | |||
102 | ch = z_readb(hwif->io_ports[IDE_IRQ_OFFSET]); | ||
103 | if (!(ch & GAYLE_IRQ_IDE)) | ||
104 | return 0; | ||
105 | (void)z_readb(hwif->io_ports[IDE_STATUS_OFFSET]); | ||
106 | z_writeb(0x7c, hwif->io_ports[IDE_IRQ_OFFSET]); | ||
107 | return 1; | ||
108 | } | ||
109 | |||
110 | /* | ||
111 | * Probe for a Gayle IDE interface (and optionally for an IDE doubler) | ||
112 | */ | ||
113 | |||
114 | void __init gayle_init(void) | ||
115 | { | ||
116 | int a4000, i; | ||
117 | |||
118 | if (!MACH_IS_AMIGA) | ||
119 | return; | ||
120 | |||
121 | if ((a4000 = AMIGAHW_PRESENT(A4000_IDE)) || AMIGAHW_PRESENT(A1200_IDE)) | ||
122 | goto found; | ||
123 | |||
124 | #ifdef CONFIG_ZORRO | ||
125 | if (zorro_find_device(ZORRO_PROD_MTEC_VIPER_MK_V_E_MATRIX_530_SCSI_IDE, | ||
126 | NULL)) | ||
127 | goto found; | ||
128 | #endif | ||
129 | return; | ||
130 | |||
131 | found: | ||
132 | for (i = 0; i < GAYLE_NUM_PROBE_HWIFS; i++) { | ||
133 | unsigned long base, ctrlport, irqport; | ||
134 | ide_ack_intr_t *ack_intr; | ||
135 | hw_regs_t hw; | ||
136 | ide_hwif_t *hwif; | ||
137 | int index; | ||
138 | unsigned long phys_base, res_start, res_n; | ||
139 | |||
140 | if (a4000) { | ||
141 | phys_base = GAYLE_BASE_4000; | ||
142 | irqport = (unsigned long)ZTWO_VADDR(GAYLE_IRQ_4000); | ||
143 | ack_intr = gayle_ack_intr_a4000; | ||
144 | } else { | ||
145 | phys_base = GAYLE_BASE_1200; | ||
146 | irqport = (unsigned long)ZTWO_VADDR(GAYLE_IRQ_1200); | ||
147 | ack_intr = gayle_ack_intr_a1200; | ||
148 | } | ||
149 | /* | ||
150 | * FIXME: we now have selectable modes between mmio v/s iomio | ||
151 | */ | ||
152 | |||
153 | phys_base += i*GAYLE_NEXT_PORT; | ||
154 | |||
155 | res_start = ((unsigned long)phys_base) & ~(GAYLE_NEXT_PORT-1); | ||
156 | res_n = GAYLE_IDEREG_SIZE; | ||
157 | |||
158 | if (!request_mem_region(res_start, res_n, "IDE")) | ||
159 | continue; | ||
160 | |||
161 | base = (unsigned long)ZTWO_VADDR(phys_base); | ||
162 | ctrlport = GAYLE_HAS_CONTROL_REG ? (base + GAYLE_CONTROL) : 0; | ||
163 | |||
164 | ide_setup_ports(&hw, base, gayle_offsets, | ||
165 | ctrlport, irqport, ack_intr, | ||
166 | // &gayle_iops, | ||
167 | IRQ_AMIGA_PORTS); | ||
168 | |||
169 | index = ide_register_hw(&hw, &hwif); | ||
170 | if (index != -1) { | ||
171 | hwif->mmio = 2; | ||
172 | switch (i) { | ||
173 | case 0: | ||
174 | printk("ide%d: Gayle IDE interface (A%d style)\n", index, | ||
175 | a4000 ? 4000 : 1200); | ||
176 | break; | ||
177 | #ifdef CONFIG_BLK_DEV_IDEDOUBLER | ||
178 | case 1: | ||
179 | printk("ide%d: IDE doubler\n", index); | ||
180 | break; | ||
181 | #endif /* CONFIG_BLK_DEV_IDEDOUBLER */ | ||
182 | } | ||
183 | } else | ||
184 | release_mem_region(res_start, res_n); | ||
185 | } | ||
186 | } | ||
diff --git a/drivers/ide/legacy/hd.c b/drivers/ide/legacy/hd.c new file mode 100644 index 000000000000..c4090550ec13 --- /dev/null +++ b/drivers/ide/legacy/hd.c | |||
@@ -0,0 +1,864 @@ | |||
1 | /* | ||
2 | * Copyright (C) 1991, 1992 Linus Torvalds | ||
3 | * | ||
4 | * This is the low-level hd interrupt support. It traverses the | ||
5 | * request-list, using interrupts to jump between functions. As | ||
6 | * all the functions are called within interrupts, we may not | ||
7 | * sleep. Special care is recommended. | ||
8 | * | ||
9 | * modified by Drew Eckhardt to check nr of hd's from the CMOS. | ||
10 | * | ||
11 | * Thanks to Branko Lankester, lankeste@fwi.uva.nl, who found a bug | ||
12 | * in the early extended-partition checks and added DM partitions | ||
13 | * | ||
14 | * IRQ-unmask, drive-id, multiple-mode, support for ">16 heads", | ||
15 | * and general streamlining by Mark Lord. | ||
16 | * | ||
17 | * Removed 99% of above. Use Mark's ide driver for those options. | ||
18 | * This is now a lightweight ST-506 driver. (Paul Gortmaker) | ||
19 | * | ||
20 | * Modified 1995 Russell King for ARM processor. | ||
21 | * | ||
22 | * Bugfix: max_sectors must be <= 255 or the wheels tend to come | ||
23 | * off in a hurry once you queue things up - Paul G. 02/2001 | ||
24 | */ | ||
25 | |||
26 | /* Uncomment the following if you want verbose error reports. */ | ||
27 | /* #define VERBOSE_ERRORS */ | ||
28 | |||
29 | #include <linux/blkdev.h> | ||
30 | #include <linux/errno.h> | ||
31 | #include <linux/signal.h> | ||
32 | #include <linux/interrupt.h> | ||
33 | #include <linux/timer.h> | ||
34 | #include <linux/fs.h> | ||
35 | #include <linux/kernel.h> | ||
36 | #include <linux/genhd.h> | ||
37 | #include <linux/slab.h> | ||
38 | #include <linux/string.h> | ||
39 | #include <linux/ioport.h> | ||
40 | #include <linux/mc146818rtc.h> /* CMOS defines */ | ||
41 | #include <linux/init.h> | ||
42 | #include <linux/blkpg.h> | ||
43 | #include <linux/hdreg.h> | ||
44 | |||
45 | #define REALLY_SLOW_IO | ||
46 | #include <asm/system.h> | ||
47 | #include <asm/io.h> | ||
48 | #include <asm/uaccess.h> | ||
49 | |||
50 | #ifdef __arm__ | ||
51 | #undef HD_IRQ | ||
52 | #endif | ||
53 | #include <asm/irq.h> | ||
54 | #ifdef __arm__ | ||
55 | #define HD_IRQ IRQ_HARDDISK | ||
56 | #endif | ||
57 | |||
58 | /* Hd controller regster ports */ | ||
59 | |||
60 | #define HD_DATA 0x1f0 /* _CTL when writing */ | ||
61 | #define HD_ERROR 0x1f1 /* see err-bits */ | ||
62 | #define HD_NSECTOR 0x1f2 /* nr of sectors to read/write */ | ||
63 | #define HD_SECTOR 0x1f3 /* starting sector */ | ||
64 | #define HD_LCYL 0x1f4 /* starting cylinder */ | ||
65 | #define HD_HCYL 0x1f5 /* high byte of starting cyl */ | ||
66 | #define HD_CURRENT 0x1f6 /* 101dhhhh , d=drive, hhhh=head */ | ||
67 | #define HD_STATUS 0x1f7 /* see status-bits */ | ||
68 | #define HD_FEATURE HD_ERROR /* same io address, read=error, write=feature */ | ||
69 | #define HD_PRECOMP HD_FEATURE /* obsolete use of this port - predates IDE */ | ||
70 | #define HD_COMMAND HD_STATUS /* same io address, read=status, write=cmd */ | ||
71 | |||
72 | #define HD_CMD 0x3f6 /* used for resets */ | ||
73 | #define HD_ALTSTATUS 0x3f6 /* same as HD_STATUS but doesn't clear irq */ | ||
74 | |||
75 | /* Bits of HD_STATUS */ | ||
76 | #define ERR_STAT 0x01 | ||
77 | #define INDEX_STAT 0x02 | ||
78 | #define ECC_STAT 0x04 /* Corrected error */ | ||
79 | #define DRQ_STAT 0x08 | ||
80 | #define SEEK_STAT 0x10 | ||
81 | #define SERVICE_STAT SEEK_STAT | ||
82 | #define WRERR_STAT 0x20 | ||
83 | #define READY_STAT 0x40 | ||
84 | #define BUSY_STAT 0x80 | ||
85 | |||
86 | /* Bits for HD_ERROR */ | ||
87 | #define MARK_ERR 0x01 /* Bad address mark */ | ||
88 | #define TRK0_ERR 0x02 /* couldn't find track 0 */ | ||
89 | #define ABRT_ERR 0x04 /* Command aborted */ | ||
90 | #define MCR_ERR 0x08 /* media change request */ | ||
91 | #define ID_ERR 0x10 /* ID field not found */ | ||
92 | #define MC_ERR 0x20 /* media changed */ | ||
93 | #define ECC_ERR 0x40 /* Uncorrectable ECC error */ | ||
94 | #define BBD_ERR 0x80 /* pre-EIDE meaning: block marked bad */ | ||
95 | #define ICRC_ERR 0x80 /* new meaning: CRC error during transfer */ | ||
96 | |||
97 | static DEFINE_SPINLOCK(hd_lock); | ||
98 | static struct request_queue *hd_queue; | ||
99 | |||
100 | #define MAJOR_NR HD_MAJOR | ||
101 | #define QUEUE (hd_queue) | ||
102 | #define CURRENT elv_next_request(hd_queue) | ||
103 | |||
104 | #define TIMEOUT_VALUE (6*HZ) | ||
105 | #define HD_DELAY 0 | ||
106 | |||
107 | #define MAX_ERRORS 16 /* Max read/write errors/sector */ | ||
108 | #define RESET_FREQ 8 /* Reset controller every 8th retry */ | ||
109 | #define RECAL_FREQ 4 /* Recalibrate every 4th retry */ | ||
110 | #define MAX_HD 2 | ||
111 | |||
112 | #define STAT_OK (READY_STAT|SEEK_STAT) | ||
113 | #define OK_STATUS(s) (((s)&(STAT_OK|(BUSY_STAT|WRERR_STAT|ERR_STAT)))==STAT_OK) | ||
114 | |||
115 | static void recal_intr(void); | ||
116 | static void bad_rw_intr(void); | ||
117 | |||
118 | static int reset; | ||
119 | static int hd_error; | ||
120 | |||
121 | /* | ||
122 | * This struct defines the HD's and their types. | ||
123 | */ | ||
124 | struct hd_i_struct { | ||
125 | unsigned int head,sect,cyl,wpcom,lzone,ctl; | ||
126 | int unit; | ||
127 | int recalibrate; | ||
128 | int special_op; | ||
129 | }; | ||
130 | |||
131 | #ifdef HD_TYPE | ||
132 | static struct hd_i_struct hd_info[] = { HD_TYPE }; | ||
133 | static int NR_HD = ((sizeof (hd_info))/(sizeof (struct hd_i_struct))); | ||
134 | #else | ||
135 | static struct hd_i_struct hd_info[MAX_HD]; | ||
136 | static int NR_HD; | ||
137 | #endif | ||
138 | |||
139 | static struct gendisk *hd_gendisk[MAX_HD]; | ||
140 | |||
141 | static struct timer_list device_timer; | ||
142 | |||
143 | #define TIMEOUT_VALUE (6*HZ) | ||
144 | |||
145 | #define SET_TIMER \ | ||
146 | do { \ | ||
147 | mod_timer(&device_timer, jiffies + TIMEOUT_VALUE); \ | ||
148 | } while (0) | ||
149 | |||
150 | static void (*do_hd)(void) = NULL; | ||
151 | #define SET_HANDLER(x) \ | ||
152 | if ((do_hd = (x)) != NULL) \ | ||
153 | SET_TIMER; \ | ||
154 | else \ | ||
155 | del_timer(&device_timer); | ||
156 | |||
157 | |||
158 | #if (HD_DELAY > 0) | ||
159 | unsigned long last_req; | ||
160 | |||
161 | unsigned long read_timer(void) | ||
162 | { | ||
163 | extern spinlock_t i8253_lock; | ||
164 | unsigned long t, flags; | ||
165 | int i; | ||
166 | |||
167 | spin_lock_irqsave(&i8253_lock, flags); | ||
168 | t = jiffies * 11932; | ||
169 | outb_p(0, 0x43); | ||
170 | i = inb_p(0x40); | ||
171 | i |= inb(0x40) << 8; | ||
172 | spin_unlock_irqrestore(&i8253_lock, flags); | ||
173 | return(t - i); | ||
174 | } | ||
175 | #endif | ||
176 | |||
177 | static void __init hd_setup(char *str, int *ints) | ||
178 | { | ||
179 | int hdind = 0; | ||
180 | |||
181 | if (ints[0] != 3) | ||
182 | return; | ||
183 | if (hd_info[0].head != 0) | ||
184 | hdind=1; | ||
185 | hd_info[hdind].head = ints[2]; | ||
186 | hd_info[hdind].sect = ints[3]; | ||
187 | hd_info[hdind].cyl = ints[1]; | ||
188 | hd_info[hdind].wpcom = 0; | ||
189 | hd_info[hdind].lzone = ints[1]; | ||
190 | hd_info[hdind].ctl = (ints[2] > 8 ? 8 : 0); | ||
191 | NR_HD = hdind+1; | ||
192 | } | ||
193 | |||
194 | static void dump_status (const char *msg, unsigned int stat) | ||
195 | { | ||
196 | char *name = "hd?"; | ||
197 | if (CURRENT) | ||
198 | name = CURRENT->rq_disk->disk_name; | ||
199 | |||
200 | #ifdef VERBOSE_ERRORS | ||
201 | printk("%s: %s: status=0x%02x { ", name, msg, stat & 0xff); | ||
202 | if (stat & BUSY_STAT) printk("Busy "); | ||
203 | if (stat & READY_STAT) printk("DriveReady "); | ||
204 | if (stat & WRERR_STAT) printk("WriteFault "); | ||
205 | if (stat & SEEK_STAT) printk("SeekComplete "); | ||
206 | if (stat & DRQ_STAT) printk("DataRequest "); | ||
207 | if (stat & ECC_STAT) printk("CorrectedError "); | ||
208 | if (stat & INDEX_STAT) printk("Index "); | ||
209 | if (stat & ERR_STAT) printk("Error "); | ||
210 | printk("}\n"); | ||
211 | if ((stat & ERR_STAT) == 0) { | ||
212 | hd_error = 0; | ||
213 | } else { | ||
214 | hd_error = inb(HD_ERROR); | ||
215 | printk("%s: %s: error=0x%02x { ", name, msg, hd_error & 0xff); | ||
216 | if (hd_error & BBD_ERR) printk("BadSector "); | ||
217 | if (hd_error & ECC_ERR) printk("UncorrectableError "); | ||
218 | if (hd_error & ID_ERR) printk("SectorIdNotFound "); | ||
219 | if (hd_error & ABRT_ERR) printk("DriveStatusError "); | ||
220 | if (hd_error & TRK0_ERR) printk("TrackZeroNotFound "); | ||
221 | if (hd_error & MARK_ERR) printk("AddrMarkNotFound "); | ||
222 | printk("}"); | ||
223 | if (hd_error & (BBD_ERR|ECC_ERR|ID_ERR|MARK_ERR)) { | ||
224 | printk(", CHS=%d/%d/%d", (inb(HD_HCYL)<<8) + inb(HD_LCYL), | ||
225 | inb(HD_CURRENT) & 0xf, inb(HD_SECTOR)); | ||
226 | if (CURRENT) | ||
227 | printk(", sector=%ld", CURRENT->sector); | ||
228 | } | ||
229 | printk("\n"); | ||
230 | } | ||
231 | #else | ||
232 | printk("%s: %s: status=0x%02x.\n", name, msg, stat & 0xff); | ||
233 | if ((stat & ERR_STAT) == 0) { | ||
234 | hd_error = 0; | ||
235 | } else { | ||
236 | hd_error = inb(HD_ERROR); | ||
237 | printk("%s: %s: error=0x%02x.\n", name, msg, hd_error & 0xff); | ||
238 | } | ||
239 | #endif | ||
240 | } | ||
241 | |||
242 | static void check_status(void) | ||
243 | { | ||
244 | int i = inb_p(HD_STATUS); | ||
245 | |||
246 | if (!OK_STATUS(i)) { | ||
247 | dump_status("check_status", i); | ||
248 | bad_rw_intr(); | ||
249 | } | ||
250 | } | ||
251 | |||
252 | static int controller_busy(void) | ||
253 | { | ||
254 | int retries = 100000; | ||
255 | unsigned char status; | ||
256 | |||
257 | do { | ||
258 | status = inb_p(HD_STATUS); | ||
259 | } while ((status & BUSY_STAT) && --retries); | ||
260 | return status; | ||
261 | } | ||
262 | |||
263 | static int status_ok(void) | ||
264 | { | ||
265 | unsigned char status = inb_p(HD_STATUS); | ||
266 | |||
267 | if (status & BUSY_STAT) | ||
268 | return 1; /* Ancient, but does it make sense??? */ | ||
269 | if (status & WRERR_STAT) | ||
270 | return 0; | ||
271 | if (!(status & READY_STAT)) | ||
272 | return 0; | ||
273 | if (!(status & SEEK_STAT)) | ||
274 | return 0; | ||
275 | return 1; | ||
276 | } | ||
277 | |||
278 | static int controller_ready(unsigned int drive, unsigned int head) | ||
279 | { | ||
280 | int retry = 100; | ||
281 | |||
282 | do { | ||
283 | if (controller_busy() & BUSY_STAT) | ||
284 | return 0; | ||
285 | outb_p(0xA0 | (drive<<4) | head, HD_CURRENT); | ||
286 | if (status_ok()) | ||
287 | return 1; | ||
288 | } while (--retry); | ||
289 | return 0; | ||
290 | } | ||
291 | |||
292 | |||
293 | static void hd_out(struct hd_i_struct *disk, | ||
294 | unsigned int nsect, | ||
295 | unsigned int sect, | ||
296 | unsigned int head, | ||
297 | unsigned int cyl, | ||
298 | unsigned int cmd, | ||
299 | void (*intr_addr)(void)) | ||
300 | { | ||
301 | unsigned short port; | ||
302 | |||
303 | #if (HD_DELAY > 0) | ||
304 | while (read_timer() - last_req < HD_DELAY) | ||
305 | /* nothing */; | ||
306 | #endif | ||
307 | if (reset) | ||
308 | return; | ||
309 | if (!controller_ready(disk->unit, head)) { | ||
310 | reset = 1; | ||
311 | return; | ||
312 | } | ||
313 | SET_HANDLER(intr_addr); | ||
314 | outb_p(disk->ctl,HD_CMD); | ||
315 | port=HD_DATA; | ||
316 | outb_p(disk->wpcom>>2,++port); | ||
317 | outb_p(nsect,++port); | ||
318 | outb_p(sect,++port); | ||
319 | outb_p(cyl,++port); | ||
320 | outb_p(cyl>>8,++port); | ||
321 | outb_p(0xA0|(disk->unit<<4)|head,++port); | ||
322 | outb_p(cmd,++port); | ||
323 | } | ||
324 | |||
325 | static void hd_request (void); | ||
326 | |||
327 | static int drive_busy(void) | ||
328 | { | ||
329 | unsigned int i; | ||
330 | unsigned char c; | ||
331 | |||
332 | for (i = 0; i < 500000 ; i++) { | ||
333 | c = inb_p(HD_STATUS); | ||
334 | if ((c & (BUSY_STAT | READY_STAT | SEEK_STAT)) == STAT_OK) | ||
335 | return 0; | ||
336 | } | ||
337 | dump_status("reset timed out", c); | ||
338 | return 1; | ||
339 | } | ||
340 | |||
341 | static void reset_controller(void) | ||
342 | { | ||
343 | int i; | ||
344 | |||
345 | outb_p(4,HD_CMD); | ||
346 | for(i = 0; i < 1000; i++) barrier(); | ||
347 | outb_p(hd_info[0].ctl & 0x0f,HD_CMD); | ||
348 | for(i = 0; i < 1000; i++) barrier(); | ||
349 | if (drive_busy()) | ||
350 | printk("hd: controller still busy\n"); | ||
351 | else if ((hd_error = inb(HD_ERROR)) != 1) | ||
352 | printk("hd: controller reset failed: %02x\n",hd_error); | ||
353 | } | ||
354 | |||
355 | static void reset_hd(void) | ||
356 | { | ||
357 | static int i; | ||
358 | |||
359 | repeat: | ||
360 | if (reset) { | ||
361 | reset = 0; | ||
362 | i = -1; | ||
363 | reset_controller(); | ||
364 | } else { | ||
365 | check_status(); | ||
366 | if (reset) | ||
367 | goto repeat; | ||
368 | } | ||
369 | if (++i < NR_HD) { | ||
370 | struct hd_i_struct *disk = &hd_info[i]; | ||
371 | disk->special_op = disk->recalibrate = 1; | ||
372 | hd_out(disk,disk->sect,disk->sect,disk->head-1, | ||
373 | disk->cyl,WIN_SPECIFY,&reset_hd); | ||
374 | if (reset) | ||
375 | goto repeat; | ||
376 | } else | ||
377 | hd_request(); | ||
378 | } | ||
379 | |||
380 | /* | ||
381 | * Ok, don't know what to do with the unexpected interrupts: on some machines | ||
382 | * doing a reset and a retry seems to result in an eternal loop. Right now I | ||
383 | * ignore it, and just set the timeout. | ||
384 | * | ||
385 | * On laptops (and "green" PCs), an unexpected interrupt occurs whenever the | ||
386 | * drive enters "idle", "standby", or "sleep" mode, so if the status looks | ||
387 | * "good", we just ignore the interrupt completely. | ||
388 | */ | ||
389 | static void unexpected_hd_interrupt(void) | ||
390 | { | ||
391 | unsigned int stat = inb_p(HD_STATUS); | ||
392 | |||
393 | if (stat & (BUSY_STAT|DRQ_STAT|ECC_STAT|ERR_STAT)) { | ||
394 | dump_status ("unexpected interrupt", stat); | ||
395 | SET_TIMER; | ||
396 | } | ||
397 | } | ||
398 | |||
399 | /* | ||
400 | * bad_rw_intr() now tries to be a bit smarter and does things | ||
401 | * according to the error returned by the controller. | ||
402 | * -Mika Liljeberg (liljeber@cs.Helsinki.FI) | ||
403 | */ | ||
404 | static void bad_rw_intr(void) | ||
405 | { | ||
406 | struct request *req = CURRENT; | ||
407 | if (req != NULL) { | ||
408 | struct hd_i_struct *disk = req->rq_disk->private_data; | ||
409 | if (++req->errors >= MAX_ERRORS || (hd_error & BBD_ERR)) { | ||
410 | end_request(req, 0); | ||
411 | disk->special_op = disk->recalibrate = 1; | ||
412 | } else if (req->errors % RESET_FREQ == 0) | ||
413 | reset = 1; | ||
414 | else if ((hd_error & TRK0_ERR) || req->errors % RECAL_FREQ == 0) | ||
415 | disk->special_op = disk->recalibrate = 1; | ||
416 | /* Otherwise just retry */ | ||
417 | } | ||
418 | } | ||
419 | |||
420 | static inline int wait_DRQ(void) | ||
421 | { | ||
422 | int retries = 100000, stat; | ||
423 | |||
424 | while (--retries > 0) | ||
425 | if ((stat = inb_p(HD_STATUS)) & DRQ_STAT) | ||
426 | return 0; | ||
427 | dump_status("wait_DRQ", stat); | ||
428 | return -1; | ||
429 | } | ||
430 | |||
431 | static void read_intr(void) | ||
432 | { | ||
433 | struct request *req; | ||
434 | int i, retries = 100000; | ||
435 | |||
436 | do { | ||
437 | i = (unsigned) inb_p(HD_STATUS); | ||
438 | if (i & BUSY_STAT) | ||
439 | continue; | ||
440 | if (!OK_STATUS(i)) | ||
441 | break; | ||
442 | if (i & DRQ_STAT) | ||
443 | goto ok_to_read; | ||
444 | } while (--retries > 0); | ||
445 | dump_status("read_intr", i); | ||
446 | bad_rw_intr(); | ||
447 | hd_request(); | ||
448 | return; | ||
449 | ok_to_read: | ||
450 | req = CURRENT; | ||
451 | insw(HD_DATA,req->buffer,256); | ||
452 | req->sector++; | ||
453 | req->buffer += 512; | ||
454 | req->errors = 0; | ||
455 | i = --req->nr_sectors; | ||
456 | --req->current_nr_sectors; | ||
457 | #ifdef DEBUG | ||
458 | printk("%s: read: sector %ld, remaining = %ld, buffer=%p\n", | ||
459 | req->rq_disk->disk_name, req->sector, req->nr_sectors, | ||
460 | req->buffer+512)); | ||
461 | #endif | ||
462 | if (req->current_nr_sectors <= 0) | ||
463 | end_request(req, 1); | ||
464 | if (i > 0) { | ||
465 | SET_HANDLER(&read_intr); | ||
466 | return; | ||
467 | } | ||
468 | (void) inb_p(HD_STATUS); | ||
469 | #if (HD_DELAY > 0) | ||
470 | last_req = read_timer(); | ||
471 | #endif | ||
472 | if (elv_next_request(QUEUE)) | ||
473 | hd_request(); | ||
474 | return; | ||
475 | } | ||
476 | |||
477 | static void write_intr(void) | ||
478 | { | ||
479 | struct request *req = CURRENT; | ||
480 | int i; | ||
481 | int retries = 100000; | ||
482 | |||
483 | do { | ||
484 | i = (unsigned) inb_p(HD_STATUS); | ||
485 | if (i & BUSY_STAT) | ||
486 | continue; | ||
487 | if (!OK_STATUS(i)) | ||
488 | break; | ||
489 | if ((req->nr_sectors <= 1) || (i & DRQ_STAT)) | ||
490 | goto ok_to_write; | ||
491 | } while (--retries > 0); | ||
492 | dump_status("write_intr", i); | ||
493 | bad_rw_intr(); | ||
494 | hd_request(); | ||
495 | return; | ||
496 | ok_to_write: | ||
497 | req->sector++; | ||
498 | i = --req->nr_sectors; | ||
499 | --req->current_nr_sectors; | ||
500 | req->buffer += 512; | ||
501 | if (!i || (req->bio && req->current_nr_sectors <= 0)) | ||
502 | end_request(req, 1); | ||
503 | if (i > 0) { | ||
504 | SET_HANDLER(&write_intr); | ||
505 | outsw(HD_DATA,req->buffer,256); | ||
506 | local_irq_enable(); | ||
507 | } else { | ||
508 | #if (HD_DELAY > 0) | ||
509 | last_req = read_timer(); | ||
510 | #endif | ||
511 | hd_request(); | ||
512 | } | ||
513 | return; | ||
514 | } | ||
515 | |||
516 | static void recal_intr(void) | ||
517 | { | ||
518 | check_status(); | ||
519 | #if (HD_DELAY > 0) | ||
520 | last_req = read_timer(); | ||
521 | #endif | ||
522 | hd_request(); | ||
523 | } | ||
524 | |||
525 | /* | ||
526 | * This is another of the error-routines I don't know what to do with. The | ||
527 | * best idea seems to just set reset, and start all over again. | ||
528 | */ | ||
529 | static void hd_times_out(unsigned long dummy) | ||
530 | { | ||
531 | char *name; | ||
532 | |||
533 | do_hd = NULL; | ||
534 | |||
535 | if (!CURRENT) | ||
536 | return; | ||
537 | |||
538 | disable_irq(HD_IRQ); | ||
539 | local_irq_enable(); | ||
540 | reset = 1; | ||
541 | name = CURRENT->rq_disk->disk_name; | ||
542 | printk("%s: timeout\n", name); | ||
543 | if (++CURRENT->errors >= MAX_ERRORS) { | ||
544 | #ifdef DEBUG | ||
545 | printk("%s: too many errors\n", name); | ||
546 | #endif | ||
547 | end_request(CURRENT, 0); | ||
548 | } | ||
549 | local_irq_disable(); | ||
550 | hd_request(); | ||
551 | enable_irq(HD_IRQ); | ||
552 | } | ||
553 | |||
554 | static int do_special_op(struct hd_i_struct *disk, struct request *req) | ||
555 | { | ||
556 | if (disk->recalibrate) { | ||
557 | disk->recalibrate = 0; | ||
558 | hd_out(disk,disk->sect,0,0,0,WIN_RESTORE,&recal_intr); | ||
559 | return reset; | ||
560 | } | ||
561 | if (disk->head > 16) { | ||
562 | printk ("%s: cannot handle device with more than 16 heads - giving up\n", req->rq_disk->disk_name); | ||
563 | end_request(req, 0); | ||
564 | } | ||
565 | disk->special_op = 0; | ||
566 | return 1; | ||
567 | } | ||
568 | |||
569 | /* | ||
570 | * The driver enables interrupts as much as possible. In order to do this, | ||
571 | * (a) the device-interrupt is disabled before entering hd_request(), | ||
572 | * and (b) the timeout-interrupt is disabled before the sti(). | ||
573 | * | ||
574 | * Interrupts are still masked (by default) whenever we are exchanging | ||
575 | * data/cmds with a drive, because some drives seem to have very poor | ||
576 | * tolerance for latency during I/O. The IDE driver has support to unmask | ||
577 | * interrupts for non-broken hardware, so use that driver if required. | ||
578 | */ | ||
579 | static void hd_request(void) | ||
580 | { | ||
581 | unsigned int block, nsect, sec, track, head, cyl; | ||
582 | struct hd_i_struct *disk; | ||
583 | struct request *req; | ||
584 | |||
585 | if (do_hd) | ||
586 | return; | ||
587 | repeat: | ||
588 | del_timer(&device_timer); | ||
589 | local_irq_enable(); | ||
590 | |||
591 | req = CURRENT; | ||
592 | if (!req) { | ||
593 | do_hd = NULL; | ||
594 | return; | ||
595 | } | ||
596 | |||
597 | if (reset) { | ||
598 | local_irq_disable(); | ||
599 | reset_hd(); | ||
600 | return; | ||
601 | } | ||
602 | disk = req->rq_disk->private_data; | ||
603 | block = req->sector; | ||
604 | nsect = req->nr_sectors; | ||
605 | if (block >= get_capacity(req->rq_disk) || | ||
606 | ((block+nsect) > get_capacity(req->rq_disk))) { | ||
607 | printk("%s: bad access: block=%d, count=%d\n", | ||
608 | req->rq_disk->disk_name, block, nsect); | ||
609 | end_request(req, 0); | ||
610 | goto repeat; | ||
611 | } | ||
612 | |||
613 | if (disk->special_op) { | ||
614 | if (do_special_op(disk, req)) | ||
615 | goto repeat; | ||
616 | return; | ||
617 | } | ||
618 | sec = block % disk->sect + 1; | ||
619 | track = block / disk->sect; | ||
620 | head = track % disk->head; | ||
621 | cyl = track / disk->head; | ||
622 | #ifdef DEBUG | ||
623 | printk("%s: %sing: CHS=%d/%d/%d, sectors=%d, buffer=%p\n", | ||
624 | req->rq_disk->disk_name, (req->cmd == READ)?"read":"writ", | ||
625 | cyl, head, sec, nsect, req->buffer); | ||
626 | #endif | ||
627 | if (req->flags & REQ_CMD) { | ||
628 | switch (rq_data_dir(req)) { | ||
629 | case READ: | ||
630 | hd_out(disk,nsect,sec,head,cyl,WIN_READ,&read_intr); | ||
631 | if (reset) | ||
632 | goto repeat; | ||
633 | break; | ||
634 | case WRITE: | ||
635 | hd_out(disk,nsect,sec,head,cyl,WIN_WRITE,&write_intr); | ||
636 | if (reset) | ||
637 | goto repeat; | ||
638 | if (wait_DRQ()) { | ||
639 | bad_rw_intr(); | ||
640 | goto repeat; | ||
641 | } | ||
642 | outsw(HD_DATA,req->buffer,256); | ||
643 | break; | ||
644 | default: | ||
645 | printk("unknown hd-command\n"); | ||
646 | end_request(req, 0); | ||
647 | break; | ||
648 | } | ||
649 | } | ||
650 | } | ||
651 | |||
652 | static void do_hd_request (request_queue_t * q) | ||
653 | { | ||
654 | disable_irq(HD_IRQ); | ||
655 | hd_request(); | ||
656 | enable_irq(HD_IRQ); | ||
657 | } | ||
658 | |||
659 | static int hd_ioctl(struct inode * inode, struct file * file, | ||
660 | unsigned int cmd, unsigned long arg) | ||
661 | { | ||
662 | struct hd_i_struct *disk = inode->i_bdev->bd_disk->private_data; | ||
663 | struct hd_geometry __user *loc = (struct hd_geometry __user *) arg; | ||
664 | struct hd_geometry g; | ||
665 | |||
666 | if (cmd != HDIO_GETGEO) | ||
667 | return -EINVAL; | ||
668 | if (!loc) | ||
669 | return -EINVAL; | ||
670 | g.heads = disk->head; | ||
671 | g.sectors = disk->sect; | ||
672 | g.cylinders = disk->cyl; | ||
673 | g.start = get_start_sect(inode->i_bdev); | ||
674 | return copy_to_user(loc, &g, sizeof g) ? -EFAULT : 0; | ||
675 | } | ||
676 | |||
677 | /* | ||
678 | * Releasing a block device means we sync() it, so that it can safely | ||
679 | * be forgotten about... | ||
680 | */ | ||
681 | |||
682 | static irqreturn_t hd_interrupt(int irq, void *dev_id, struct pt_regs *regs) | ||
683 | { | ||
684 | void (*handler)(void) = do_hd; | ||
685 | |||
686 | do_hd = NULL; | ||
687 | del_timer(&device_timer); | ||
688 | if (!handler) | ||
689 | handler = unexpected_hd_interrupt; | ||
690 | handler(); | ||
691 | local_irq_enable(); | ||
692 | return IRQ_HANDLED; | ||
693 | } | ||
694 | |||
695 | static struct block_device_operations hd_fops = { | ||
696 | .ioctl = hd_ioctl, | ||
697 | }; | ||
698 | |||
699 | /* | ||
700 | * This is the hard disk IRQ description. The SA_INTERRUPT in sa_flags | ||
701 | * means we run the IRQ-handler with interrupts disabled: this is bad for | ||
702 | * interrupt latency, but anything else has led to problems on some | ||
703 | * machines. | ||
704 | * | ||
705 | * We enable interrupts in some of the routines after making sure it's | ||
706 | * safe. | ||
707 | */ | ||
708 | |||
709 | static int __init hd_init(void) | ||
710 | { | ||
711 | int drive; | ||
712 | |||
713 | if (register_blkdev(MAJOR_NR,"hd")) | ||
714 | return -1; | ||
715 | |||
716 | hd_queue = blk_init_queue(do_hd_request, &hd_lock); | ||
717 | if (!hd_queue) { | ||
718 | unregister_blkdev(MAJOR_NR,"hd"); | ||
719 | return -ENOMEM; | ||
720 | } | ||
721 | |||
722 | blk_queue_max_sectors(hd_queue, 255); | ||
723 | init_timer(&device_timer); | ||
724 | device_timer.function = hd_times_out; | ||
725 | blk_queue_hardsect_size(hd_queue, 512); | ||
726 | |||
727 | #ifdef __i386__ | ||
728 | if (!NR_HD) { | ||
729 | extern struct drive_info drive_info; | ||
730 | unsigned char *BIOS = (unsigned char *) &drive_info; | ||
731 | unsigned long flags; | ||
732 | int cmos_disks; | ||
733 | |||
734 | for (drive=0 ; drive<2 ; drive++) { | ||
735 | hd_info[drive].cyl = *(unsigned short *) BIOS; | ||
736 | hd_info[drive].head = *(2+BIOS); | ||
737 | hd_info[drive].wpcom = *(unsigned short *) (5+BIOS); | ||
738 | hd_info[drive].ctl = *(8+BIOS); | ||
739 | hd_info[drive].lzone = *(unsigned short *) (12+BIOS); | ||
740 | hd_info[drive].sect = *(14+BIOS); | ||
741 | #ifdef does_not_work_for_everybody_with_scsi_but_helps_ibm_vp | ||
742 | if (hd_info[drive].cyl && NR_HD == drive) | ||
743 | NR_HD++; | ||
744 | #endif | ||
745 | BIOS += 16; | ||
746 | } | ||
747 | |||
748 | /* | ||
749 | We query CMOS about hard disks : it could be that | ||
750 | we have a SCSI/ESDI/etc controller that is BIOS | ||
751 | compatible with ST-506, and thus showing up in our | ||
752 | BIOS table, but not register compatible, and therefore | ||
753 | not present in CMOS. | ||
754 | |||
755 | Furthermore, we will assume that our ST-506 drives | ||
756 | <if any> are the primary drives in the system, and | ||
757 | the ones reflected as drive 1 or 2. | ||
758 | |||
759 | The first drive is stored in the high nibble of CMOS | ||
760 | byte 0x12, the second in the low nibble. This will be | ||
761 | either a 4 bit drive type or 0xf indicating use byte 0x19 | ||
762 | for an 8 bit type, drive 1, 0x1a for drive 2 in CMOS. | ||
763 | |||
764 | Needless to say, a non-zero value means we have | ||
765 | an AT controller hard disk for that drive. | ||
766 | |||
767 | Currently the rtc_lock is a bit academic since this | ||
768 | driver is non-modular, but someday... ? Paul G. | ||
769 | */ | ||
770 | |||
771 | spin_lock_irqsave(&rtc_lock, flags); | ||
772 | cmos_disks = CMOS_READ(0x12); | ||
773 | spin_unlock_irqrestore(&rtc_lock, flags); | ||
774 | |||
775 | if (cmos_disks & 0xf0) { | ||
776 | if (cmos_disks & 0x0f) | ||
777 | NR_HD = 2; | ||
778 | else | ||
779 | NR_HD = 1; | ||
780 | } | ||
781 | } | ||
782 | #endif /* __i386__ */ | ||
783 | #ifdef __arm__ | ||
784 | if (!NR_HD) { | ||
785 | /* We don't know anything about the drive. This means | ||
786 | * that you *MUST* specify the drive parameters to the | ||
787 | * kernel yourself. | ||
788 | */ | ||
789 | printk("hd: no drives specified - use hd=cyl,head,sectors" | ||
790 | " on kernel command line\n"); | ||
791 | } | ||
792 | #endif | ||
793 | if (!NR_HD) | ||
794 | goto out; | ||
795 | |||
796 | for (drive=0 ; drive < NR_HD ; drive++) { | ||
797 | struct gendisk *disk = alloc_disk(64); | ||
798 | struct hd_i_struct *p = &hd_info[drive]; | ||
799 | if (!disk) | ||
800 | goto Enomem; | ||
801 | disk->major = MAJOR_NR; | ||
802 | disk->first_minor = drive << 6; | ||
803 | disk->fops = &hd_fops; | ||
804 | sprintf(disk->disk_name, "hd%c", 'a'+drive); | ||
805 | disk->private_data = p; | ||
806 | set_capacity(disk, p->head * p->sect * p->cyl); | ||
807 | disk->queue = hd_queue; | ||
808 | p->unit = drive; | ||
809 | hd_gendisk[drive] = disk; | ||
810 | printk ("%s: %luMB, CHS=%d/%d/%d\n", | ||
811 | disk->disk_name, (unsigned long)get_capacity(disk)/2048, | ||
812 | p->cyl, p->head, p->sect); | ||
813 | } | ||
814 | |||
815 | if (request_irq(HD_IRQ, hd_interrupt, SA_INTERRUPT, "hd", NULL)) { | ||
816 | printk("hd: unable to get IRQ%d for the hard disk driver\n", | ||
817 | HD_IRQ); | ||
818 | goto out1; | ||
819 | } | ||
820 | if (!request_region(HD_DATA, 8, "hd")) { | ||
821 | printk(KERN_WARNING "hd: port 0x%x busy\n", HD_DATA); | ||
822 | goto out2; | ||
823 | } | ||
824 | if (!request_region(HD_CMD, 1, "hd(cmd)")) { | ||
825 | printk(KERN_WARNING "hd: port 0x%x busy\n", HD_CMD); | ||
826 | goto out3; | ||
827 | } | ||
828 | |||
829 | /* Let them fly */ | ||
830 | for(drive=0; drive < NR_HD; drive++) | ||
831 | add_disk(hd_gendisk[drive]); | ||
832 | |||
833 | return 0; | ||
834 | |||
835 | out3: | ||
836 | release_region(HD_DATA, 8); | ||
837 | out2: | ||
838 | free_irq(HD_IRQ, NULL); | ||
839 | out1: | ||
840 | for (drive = 0; drive < NR_HD; drive++) | ||
841 | put_disk(hd_gendisk[drive]); | ||
842 | NR_HD = 0; | ||
843 | out: | ||
844 | del_timer(&device_timer); | ||
845 | unregister_blkdev(MAJOR_NR,"hd"); | ||
846 | blk_cleanup_queue(hd_queue); | ||
847 | return -1; | ||
848 | Enomem: | ||
849 | while (drive--) | ||
850 | put_disk(hd_gendisk[drive]); | ||
851 | goto out; | ||
852 | } | ||
853 | |||
854 | static int parse_hd_setup (char *line) { | ||
855 | int ints[6]; | ||
856 | |||
857 | (void) get_options(line, ARRAY_SIZE(ints), ints); | ||
858 | hd_setup(NULL, ints); | ||
859 | |||
860 | return 1; | ||
861 | } | ||
862 | __setup("hd=", parse_hd_setup); | ||
863 | |||
864 | module_init(hd_init); | ||
diff --git a/drivers/ide/legacy/ht6560b.c b/drivers/ide/legacy/ht6560b.c new file mode 100644 index 000000000000..a77fb249d5cf --- /dev/null +++ b/drivers/ide/legacy/ht6560b.c | |||
@@ -0,0 +1,370 @@ | |||
1 | /* | ||
2 | * linux/drivers/ide/legacy/ht6560b.c Version 0.07 Feb 1, 2000 | ||
3 | * | ||
4 | * Copyright (C) 1995-2000 Linus Torvalds & author (see below) | ||
5 | */ | ||
6 | |||
7 | /* | ||
8 | * | ||
9 | * Version 0.01 Initial version hacked out of ide.c | ||
10 | * | ||
11 | * Version 0.02 Added support for PIO modes, auto-tune | ||
12 | * | ||
13 | * Version 0.03 Some cleanups | ||
14 | * | ||
15 | * Version 0.05 PIO mode cycle timings auto-tune using bus-speed | ||
16 | * | ||
17 | * Version 0.06 Prefetch mode now defaults no OFF. To set | ||
18 | * prefetch mode OFF/ON use "hdparm -p8/-p9". | ||
19 | * Unmask irq is disabled when prefetch mode | ||
20 | * is enabled. | ||
21 | * | ||
22 | * Version 0.07 Trying to fix CD-ROM detection problem. | ||
23 | * "Prefetch" mode bit OFF for ide disks and | ||
24 | * ON for anything else. | ||
25 | * | ||
26 | * | ||
27 | * HT-6560B EIDE-controller support | ||
28 | * To activate controller support use kernel parameter "ide0=ht6560b". | ||
29 | * Use hdparm utility to enable PIO mode support. | ||
30 | * | ||
31 | * Author: Mikko Ala-Fossi <maf@iki.fi> | ||
32 | * Jan Evert van Grootheest <janevert@iae.nl> | ||
33 | * | ||
34 | * Try: http://www.maf.iki.fi/~maf/ht6560b/ | ||
35 | */ | ||
36 | |||
37 | #define HT6560B_VERSION "v0.07" | ||
38 | |||
39 | #undef REALLY_SLOW_IO /* most systems can safely undef this */ | ||
40 | |||
41 | #include <linux/module.h> | ||
42 | #include <linux/config.h> | ||
43 | #include <linux/types.h> | ||
44 | #include <linux/kernel.h> | ||
45 | #include <linux/delay.h> | ||
46 | #include <linux/timer.h> | ||
47 | #include <linux/mm.h> | ||
48 | #include <linux/ioport.h> | ||
49 | #include <linux/blkdev.h> | ||
50 | #include <linux/hdreg.h> | ||
51 | #include <linux/ide.h> | ||
52 | #include <linux/init.h> | ||
53 | |||
54 | #include <asm/io.h> | ||
55 | |||
56 | /* #define DEBUG */ /* remove comments for DEBUG messages */ | ||
57 | |||
58 | /* | ||
59 | * The special i/o-port that HT-6560B uses to configuration: | ||
60 | * bit0 (0x01): "1" selects secondary interface | ||
61 | * bit2 (0x04): "1" enables FIFO function | ||
62 | * bit5 (0x20): "1" enables prefetched data read function (???) | ||
63 | * | ||
64 | * The special i/o-port that HT-6560A uses to configuration: | ||
65 | * bit0 (0x01): "1" selects secondary interface | ||
66 | * bit1 (0x02): "1" enables prefetched data read function | ||
67 | * bit2 (0x04): "0" enables multi-master system (?) | ||
68 | * bit3 (0x08): "1" 3 cycle time, "0" 2 cycle time (?) | ||
69 | */ | ||
70 | #define HT_CONFIG_PORT 0x3e6 | ||
71 | #define HT_CONFIG(drivea) (u8)(((drivea)->drive_data & 0xff00) >> 8) | ||
72 | /* | ||
73 | * FIFO + PREFETCH (both a/b-model) | ||
74 | */ | ||
75 | #define HT_CONFIG_DEFAULT 0x1c /* no prefetch */ | ||
76 | /* #define HT_CONFIG_DEFAULT 0x3c */ /* with prefetch */ | ||
77 | #define HT_SECONDARY_IF 0x01 | ||
78 | #define HT_PREFETCH_MODE 0x20 | ||
79 | |||
80 | /* | ||
81 | * ht6560b Timing values: | ||
82 | * | ||
83 | * I reviewed some assembler source listings of htide drivers and found | ||
84 | * out how they setup those cycle time interfacing values, as they at Holtek | ||
85 | * call them. IDESETUP.COM that is supplied with the drivers figures out | ||
86 | * optimal values and fetches those values to drivers. I found out that | ||
87 | * they use IDE_SELECT_REG to fetch timings to the ide board right after | ||
88 | * interface switching. After that it was quite easy to add code to | ||
89 | * ht6560b.c. | ||
90 | * | ||
91 | * IDESETUP.COM gave me values 0x24, 0x45, 0xaa, 0xff that worked fine | ||
92 | * for hda and hdc. But hdb needed higher values to work, so I guess | ||
93 | * that sometimes it is necessary to give higher value than IDESETUP | ||
94 | * gives. [see cmd640.c for an extreme example of this. -ml] | ||
95 | * | ||
96 | * Perhaps I should explain something about these timing values: | ||
97 | * The higher nibble of value is the Recovery Time (rt) and the lower nibble | ||
98 | * of the value is the Active Time (at). Minimum value 2 is the fastest and | ||
99 | * the maximum value 15 is the slowest. Default values should be 15 for both. | ||
100 | * So 0x24 means 2 for rt and 4 for at. Each of the drives should have | ||
101 | * both values, and IDESETUP gives automatically rt=15 st=15 for CDROMs or | ||
102 | * similar. If value is too small there will be all sorts of failures. | ||
103 | * | ||
104 | * Timing byte consists of | ||
105 | * High nibble: Recovery Cycle Time (rt) | ||
106 | * The valid values range from 2 to 15. The default is 15. | ||
107 | * | ||
108 | * Low nibble: Active Cycle Time (at) | ||
109 | * The valid values range from 2 to 15. The default is 15. | ||
110 | * | ||
111 | * You can obtain optimized timing values by running Holtek IDESETUP.COM | ||
112 | * for DOS. DOS drivers get their timing values from command line, where | ||
113 | * the first value is the Recovery Time and the second value is the | ||
114 | * Active Time for each drive. Smaller value gives higher speed. | ||
115 | * In case of failures you should probably fall back to a higher value. | ||
116 | */ | ||
117 | #define HT_TIMING(drivea) (u8)((drivea)->drive_data & 0x00ff) | ||
118 | #define HT_TIMING_DEFAULT 0xff | ||
119 | |||
120 | /* | ||
121 | * This routine handles interface switching for the peculiar hardware design | ||
122 | * on the F.G.I./Holtek HT-6560B VLB IDE interface. | ||
123 | * The HT-6560B can only enable one IDE port at a time, and requires a | ||
124 | * silly sequence (below) whenever we switch between primary and secondary. | ||
125 | */ | ||
126 | |||
127 | /* | ||
128 | * This routine is invoked from ide.c to prepare for access to a given drive. | ||
129 | */ | ||
130 | static void ht6560b_selectproc (ide_drive_t *drive) | ||
131 | { | ||
132 | unsigned long flags; | ||
133 | static u8 current_select = 0; | ||
134 | static u8 current_timing = 0; | ||
135 | u8 select, timing; | ||
136 | |||
137 | local_irq_save(flags); | ||
138 | |||
139 | select = HT_CONFIG(drive); | ||
140 | timing = HT_TIMING(drive); | ||
141 | |||
142 | if (select != current_select || timing != current_timing) { | ||
143 | current_select = select; | ||
144 | current_timing = timing; | ||
145 | if (drive->media != ide_disk || !drive->present) | ||
146 | select |= HT_PREFETCH_MODE; | ||
147 | (void) HWIF(drive)->INB(HT_CONFIG_PORT); | ||
148 | (void) HWIF(drive)->INB(HT_CONFIG_PORT); | ||
149 | (void) HWIF(drive)->INB(HT_CONFIG_PORT); | ||
150 | (void) HWIF(drive)->INB(HT_CONFIG_PORT); | ||
151 | HWIF(drive)->OUTB(select, HT_CONFIG_PORT); | ||
152 | /* | ||
153 | * Set timing for this drive: | ||
154 | */ | ||
155 | HWIF(drive)->OUTB(timing, IDE_SELECT_REG); | ||
156 | (void) HWIF(drive)->INB(IDE_STATUS_REG); | ||
157 | #ifdef DEBUG | ||
158 | printk("ht6560b: %s: select=%#x timing=%#x\n", | ||
159 | drive->name, select, timing); | ||
160 | #endif | ||
161 | } | ||
162 | local_irq_restore(flags); | ||
163 | } | ||
164 | |||
165 | /* | ||
166 | * Autodetection and initialization of ht6560b | ||
167 | */ | ||
168 | static int __init try_to_init_ht6560b(void) | ||
169 | { | ||
170 | u8 orig_value; | ||
171 | int i; | ||
172 | |||
173 | /* Autodetect ht6560b */ | ||
174 | if ((orig_value = inb(HT_CONFIG_PORT)) == 0xff) | ||
175 | return 0; | ||
176 | |||
177 | for (i=3;i>0;i--) { | ||
178 | outb(0x00, HT_CONFIG_PORT); | ||
179 | if (!( (~inb(HT_CONFIG_PORT)) & 0x3f )) { | ||
180 | outb(orig_value, HT_CONFIG_PORT); | ||
181 | return 0; | ||
182 | } | ||
183 | } | ||
184 | outb(0x00, HT_CONFIG_PORT); | ||
185 | if ((~inb(HT_CONFIG_PORT))& 0x3f) { | ||
186 | outb(orig_value, HT_CONFIG_PORT); | ||
187 | return 0; | ||
188 | } | ||
189 | /* | ||
190 | * Ht6560b autodetected | ||
191 | */ | ||
192 | outb(HT_CONFIG_DEFAULT, HT_CONFIG_PORT); | ||
193 | outb(HT_TIMING_DEFAULT, 0x1f6); /* IDE_SELECT_REG */ | ||
194 | (void) inb(0x1f7); /* IDE_STATUS_REG */ | ||
195 | |||
196 | printk("\nht6560b " HT6560B_VERSION | ||
197 | ": chipset detected and initialized" | ||
198 | #ifdef DEBUG | ||
199 | " with debug enabled" | ||
200 | #endif | ||
201 | ); | ||
202 | return 1; | ||
203 | } | ||
204 | |||
205 | static u8 ht_pio2timings(ide_drive_t *drive, u8 pio) | ||
206 | { | ||
207 | int active_time, recovery_time; | ||
208 | int active_cycles, recovery_cycles; | ||
209 | ide_pio_data_t d; | ||
210 | int bus_speed = system_bus_clock(); | ||
211 | |||
212 | if (pio) { | ||
213 | pio = ide_get_best_pio_mode(drive, pio, 5, &d); | ||
214 | |||
215 | /* | ||
216 | * Just like opti621.c we try to calculate the | ||
217 | * actual cycle time for recovery and activity | ||
218 | * according system bus speed. | ||
219 | */ | ||
220 | active_time = ide_pio_timings[pio].active_time; | ||
221 | recovery_time = d.cycle_time | ||
222 | - active_time | ||
223 | - ide_pio_timings[pio].setup_time; | ||
224 | /* | ||
225 | * Cycle times should be Vesa bus cycles | ||
226 | */ | ||
227 | active_cycles = (active_time * bus_speed + 999) / 1000; | ||
228 | recovery_cycles = (recovery_time * bus_speed + 999) / 1000; | ||
229 | /* | ||
230 | * Upper and lower limits | ||
231 | */ | ||
232 | if (active_cycles < 2) active_cycles = 2; | ||
233 | if (recovery_cycles < 2) recovery_cycles = 2; | ||
234 | if (active_cycles > 15) active_cycles = 15; | ||
235 | if (recovery_cycles > 15) recovery_cycles = 0; /* 0==16 */ | ||
236 | |||
237 | #ifdef DEBUG | ||
238 | printk("ht6560b: drive %s setting pio=%d recovery=%d (%dns) active=%d (%dns)\n", drive->name, pio, recovery_cycles, recovery_time, active_cycles, active_time); | ||
239 | #endif | ||
240 | |||
241 | return (u8)((recovery_cycles << 4) | active_cycles); | ||
242 | } else { | ||
243 | |||
244 | #ifdef DEBUG | ||
245 | printk("ht6560b: drive %s setting pio=0\n", drive->name); | ||
246 | #endif | ||
247 | |||
248 | return HT_TIMING_DEFAULT; /* default setting */ | ||
249 | } | ||
250 | } | ||
251 | |||
252 | /* | ||
253 | * Enable/Disable so called prefetch mode | ||
254 | */ | ||
255 | static void ht_set_prefetch(ide_drive_t *drive, u8 state) | ||
256 | { | ||
257 | unsigned long flags; | ||
258 | int t = HT_PREFETCH_MODE << 8; | ||
259 | |||
260 | spin_lock_irqsave(&ide_lock, flags); | ||
261 | |||
262 | /* | ||
263 | * Prefetch mode and unmask irq seems to conflict | ||
264 | */ | ||
265 | if (state) { | ||
266 | drive->drive_data |= t; /* enable prefetch mode */ | ||
267 | drive->no_unmask = 1; | ||
268 | drive->unmask = 0; | ||
269 | } else { | ||
270 | drive->drive_data &= ~t; /* disable prefetch mode */ | ||
271 | drive->no_unmask = 0; | ||
272 | } | ||
273 | |||
274 | spin_unlock_irqrestore(&ide_lock, flags); | ||
275 | |||
276 | #ifdef DEBUG | ||
277 | printk("ht6560b: drive %s prefetch mode %sabled\n", drive->name, (state ? "en" : "dis")); | ||
278 | #endif | ||
279 | } | ||
280 | |||
281 | static void tune_ht6560b (ide_drive_t *drive, u8 pio) | ||
282 | { | ||
283 | unsigned long flags; | ||
284 | u8 timing; | ||
285 | |||
286 | switch (pio) { | ||
287 | case 8: /* set prefetch off */ | ||
288 | case 9: /* set prefetch on */ | ||
289 | ht_set_prefetch(drive, pio & 1); | ||
290 | return; | ||
291 | } | ||
292 | |||
293 | timing = ht_pio2timings(drive, pio); | ||
294 | |||
295 | spin_lock_irqsave(&ide_lock, flags); | ||
296 | |||
297 | drive->drive_data &= 0xff00; | ||
298 | drive->drive_data |= timing; | ||
299 | |||
300 | spin_unlock_irqrestore(&ide_lock, flags); | ||
301 | |||
302 | #ifdef DEBUG | ||
303 | printk("ht6560b: drive %s tuned to pio mode %#x timing=%#x\n", drive->name, pio, timing); | ||
304 | #endif | ||
305 | } | ||
306 | |||
307 | /* Can be called directly from ide.c. */ | ||
308 | int __init ht6560b_init(void) | ||
309 | { | ||
310 | ide_hwif_t *hwif, *mate; | ||
311 | int t; | ||
312 | |||
313 | hwif = &ide_hwifs[0]; | ||
314 | mate = &ide_hwifs[1]; | ||
315 | |||
316 | if (!request_region(HT_CONFIG_PORT, 1, hwif->name)) { | ||
317 | printk(KERN_NOTICE "%s: HT_CONFIG_PORT not found\n", | ||
318 | __FUNCTION__); | ||
319 | return -ENODEV; | ||
320 | } | ||
321 | |||
322 | if (!try_to_init_ht6560b()) { | ||
323 | printk(KERN_NOTICE "%s: HBA not found\n", __FUNCTION__); | ||
324 | goto release_region; | ||
325 | } | ||
326 | |||
327 | hwif->chipset = ide_ht6560b; | ||
328 | hwif->selectproc = &ht6560b_selectproc; | ||
329 | hwif->tuneproc = &tune_ht6560b; | ||
330 | hwif->serialized = 1; /* is this needed? */ | ||
331 | hwif->mate = mate; | ||
332 | |||
333 | mate->chipset = ide_ht6560b; | ||
334 | mate->selectproc = &ht6560b_selectproc; | ||
335 | mate->tuneproc = &tune_ht6560b; | ||
336 | mate->serialized = 1; /* is this needed? */ | ||
337 | mate->mate = hwif; | ||
338 | mate->channel = 1; | ||
339 | |||
340 | /* | ||
341 | * Setting default configurations for drives | ||
342 | */ | ||
343 | t = (HT_CONFIG_DEFAULT << 8); | ||
344 | t |= HT_TIMING_DEFAULT; | ||
345 | hwif->drives[0].drive_data = t; | ||
346 | hwif->drives[1].drive_data = t; | ||
347 | |||
348 | t |= (HT_SECONDARY_IF << 8); | ||
349 | mate->drives[0].drive_data = t; | ||
350 | mate->drives[1].drive_data = t; | ||
351 | |||
352 | probe_hwif_init(hwif); | ||
353 | probe_hwif_init(mate); | ||
354 | |||
355 | create_proc_ide_interfaces(); | ||
356 | |||
357 | return 0; | ||
358 | |||
359 | release_region: | ||
360 | release_region(HT_CONFIG_PORT, 1); | ||
361 | return -ENODEV; | ||
362 | } | ||
363 | |||
364 | #ifdef MODULE | ||
365 | module_init(ht6560b_init); | ||
366 | #endif | ||
367 | |||
368 | MODULE_AUTHOR("See Local File"); | ||
369 | MODULE_DESCRIPTION("HT-6560B EIDE-controller support"); | ||
370 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/ide/legacy/ide-cs.c b/drivers/ide/legacy/ide-cs.c new file mode 100644 index 000000000000..e20327e54b1a --- /dev/null +++ b/drivers/ide/legacy/ide-cs.c | |||
@@ -0,0 +1,481 @@ | |||
1 | /*====================================================================== | ||
2 | |||
3 | A driver for PCMCIA IDE/ATA disk cards | ||
4 | |||
5 | ide-cs.c 1.3 2002/10/26 05:45:31 | ||
6 | |||
7 | The contents of this file are subject to the Mozilla Public | ||
8 | License Version 1.1 (the "License"); you may not use this file | ||
9 | except in compliance with the License. You may obtain a copy of | ||
10 | the License at http://www.mozilla.org/MPL/ | ||
11 | |||
12 | Software distributed under the License is distributed on an "AS | ||
13 | IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or | ||
14 | implied. See the License for the specific language governing | ||
15 | rights and limitations under the License. | ||
16 | |||
17 | The initial developer of the original code is David A. Hinds | ||
18 | <dahinds@users.sourceforge.net>. Portions created by David A. Hinds | ||
19 | are Copyright (C) 1999 David A. Hinds. All Rights Reserved. | ||
20 | |||
21 | Alternatively, the contents of this file may be used under the | ||
22 | terms of the GNU General Public License version 2 (the "GPL"), in | ||
23 | which case the provisions of the GPL are applicable instead of the | ||
24 | above. If you wish to allow the use of your version of this file | ||
25 | only under the terms of the GPL and not to allow others to use | ||
26 | your version of this file under the MPL, indicate your decision | ||
27 | by deleting the provisions above and replace them with the notice | ||
28 | and other provisions required by the GPL. If you do not delete | ||
29 | the provisions above, a recipient may use your version of this | ||
30 | file under either the MPL or the GPL. | ||
31 | |||
32 | ======================================================================*/ | ||
33 | |||
34 | #include <linux/module.h> | ||
35 | #include <linux/kernel.h> | ||
36 | #include <linux/init.h> | ||
37 | #include <linux/sched.h> | ||
38 | #include <linux/ptrace.h> | ||
39 | #include <linux/slab.h> | ||
40 | #include <linux/string.h> | ||
41 | #include <linux/timer.h> | ||
42 | #include <linux/ioport.h> | ||
43 | #include <linux/ide.h> | ||
44 | #include <linux/hdreg.h> | ||
45 | #include <linux/major.h> | ||
46 | #include <asm/io.h> | ||
47 | #include <asm/system.h> | ||
48 | |||
49 | #include <pcmcia/version.h> | ||
50 | #include <pcmcia/cs_types.h> | ||
51 | #include <pcmcia/cs.h> | ||
52 | #include <pcmcia/cistpl.h> | ||
53 | #include <pcmcia/ds.h> | ||
54 | #include <pcmcia/cisreg.h> | ||
55 | #include <pcmcia/ciscode.h> | ||
56 | |||
57 | /*====================================================================*/ | ||
58 | |||
59 | /* Module parameters */ | ||
60 | |||
61 | MODULE_AUTHOR("David Hinds <dahinds@users.sourceforge.net>"); | ||
62 | MODULE_DESCRIPTION("PCMCIA ATA/IDE card driver"); | ||
63 | MODULE_LICENSE("Dual MPL/GPL"); | ||
64 | |||
65 | #define INT_MODULE_PARM(n, v) static int n = v; module_param(n, int, 0) | ||
66 | |||
67 | #ifdef PCMCIA_DEBUG | ||
68 | INT_MODULE_PARM(pc_debug, PCMCIA_DEBUG); | ||
69 | #define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args) | ||
70 | static char *version = | ||
71 | "ide-cs.c 1.3 2002/10/26 05:45:31 (David Hinds)"; | ||
72 | #else | ||
73 | #define DEBUG(n, args...) | ||
74 | #endif | ||
75 | |||
76 | /*====================================================================*/ | ||
77 | |||
78 | static const char ide_major[] = { | ||
79 | IDE0_MAJOR, IDE1_MAJOR, IDE2_MAJOR, IDE3_MAJOR, | ||
80 | IDE4_MAJOR, IDE5_MAJOR | ||
81 | }; | ||
82 | |||
83 | typedef struct ide_info_t { | ||
84 | dev_link_t link; | ||
85 | int ndev; | ||
86 | dev_node_t node; | ||
87 | int hd; | ||
88 | } ide_info_t; | ||
89 | |||
90 | static void ide_release(dev_link_t *); | ||
91 | static int ide_event(event_t event, int priority, | ||
92 | event_callback_args_t *args); | ||
93 | |||
94 | static dev_info_t dev_info = "ide-cs"; | ||
95 | |||
96 | static dev_link_t *ide_attach(void); | ||
97 | static void ide_detach(dev_link_t *); | ||
98 | |||
99 | static dev_link_t *dev_list = NULL; | ||
100 | |||
101 | /*====================================================================== | ||
102 | |||
103 | ide_attach() creates an "instance" of the driver, allocating | ||
104 | local data structures for one device. The device is registered | ||
105 | with Card Services. | ||
106 | |||
107 | ======================================================================*/ | ||
108 | |||
109 | static dev_link_t *ide_attach(void) | ||
110 | { | ||
111 | ide_info_t *info; | ||
112 | dev_link_t *link; | ||
113 | client_reg_t client_reg; | ||
114 | int ret; | ||
115 | |||
116 | DEBUG(0, "ide_attach()\n"); | ||
117 | |||
118 | /* Create new ide device */ | ||
119 | info = kmalloc(sizeof(*info), GFP_KERNEL); | ||
120 | if (!info) return NULL; | ||
121 | memset(info, 0, sizeof(*info)); | ||
122 | link = &info->link; link->priv = info; | ||
123 | |||
124 | link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO; | ||
125 | link->io.Attributes2 = IO_DATA_PATH_WIDTH_8; | ||
126 | link->io.IOAddrLines = 3; | ||
127 | link->irq.Attributes = IRQ_TYPE_EXCLUSIVE; | ||
128 | link->irq.IRQInfo1 = IRQ_LEVEL_ID; | ||
129 | link->conf.Attributes = CONF_ENABLE_IRQ; | ||
130 | link->conf.Vcc = 50; | ||
131 | link->conf.IntType = INT_MEMORY_AND_IO; | ||
132 | |||
133 | /* Register with Card Services */ | ||
134 | link->next = dev_list; | ||
135 | dev_list = link; | ||
136 | client_reg.dev_info = &dev_info; | ||
137 | client_reg.EventMask = | ||
138 | CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL | | ||
139 | CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET | | ||
140 | CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME; | ||
141 | client_reg.event_handler = &ide_event; | ||
142 | client_reg.Version = 0x0210; | ||
143 | client_reg.event_callback_args.client_data = link; | ||
144 | ret = pcmcia_register_client(&link->handle, &client_reg); | ||
145 | if (ret != CS_SUCCESS) { | ||
146 | cs_error(link->handle, RegisterClient, ret); | ||
147 | ide_detach(link); | ||
148 | return NULL; | ||
149 | } | ||
150 | |||
151 | return link; | ||
152 | } /* ide_attach */ | ||
153 | |||
154 | /*====================================================================== | ||
155 | |||
156 | This deletes a driver "instance". The device is de-registered | ||
157 | with Card Services. If it has been released, all local data | ||
158 | structures are freed. Otherwise, the structures will be freed | ||
159 | when the device is released. | ||
160 | |||
161 | ======================================================================*/ | ||
162 | |||
163 | static void ide_detach(dev_link_t *link) | ||
164 | { | ||
165 | dev_link_t **linkp; | ||
166 | int ret; | ||
167 | |||
168 | DEBUG(0, "ide_detach(0x%p)\n", link); | ||
169 | |||
170 | /* Locate device structure */ | ||
171 | for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) | ||
172 | if (*linkp == link) break; | ||
173 | if (*linkp == NULL) | ||
174 | return; | ||
175 | |||
176 | if (link->state & DEV_CONFIG) | ||
177 | ide_release(link); | ||
178 | |||
179 | if (link->handle) { | ||
180 | ret = pcmcia_deregister_client(link->handle); | ||
181 | if (ret != CS_SUCCESS) | ||
182 | cs_error(link->handle, DeregisterClient, ret); | ||
183 | } | ||
184 | |||
185 | /* Unlink, free device structure */ | ||
186 | *linkp = link->next; | ||
187 | kfree(link->priv); | ||
188 | |||
189 | } /* ide_detach */ | ||
190 | |||
191 | static int idecs_register(unsigned long io, unsigned long ctl, unsigned long irq) | ||
192 | { | ||
193 | hw_regs_t hw; | ||
194 | memset(&hw, 0, sizeof(hw)); | ||
195 | ide_init_hwif_ports(&hw, io, ctl, NULL); | ||
196 | hw.irq = irq; | ||
197 | hw.chipset = ide_pci; | ||
198 | return ide_register_hw_with_fixup(&hw, NULL, ide_undecoded_slave); | ||
199 | } | ||
200 | |||
201 | /*====================================================================== | ||
202 | |||
203 | ide_config() is scheduled to run after a CARD_INSERTION event | ||
204 | is received, to configure the PCMCIA socket, and to make the | ||
205 | ide device available to the system. | ||
206 | |||
207 | ======================================================================*/ | ||
208 | |||
209 | #define CS_CHECK(fn, ret) \ | ||
210 | do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) | ||
211 | |||
212 | static void ide_config(dev_link_t *link) | ||
213 | { | ||
214 | client_handle_t handle = link->handle; | ||
215 | ide_info_t *info = link->priv; | ||
216 | tuple_t tuple; | ||
217 | struct { | ||
218 | u_short buf[128]; | ||
219 | cisparse_t parse; | ||
220 | config_info_t conf; | ||
221 | cistpl_cftable_entry_t dflt; | ||
222 | } *stk = NULL; | ||
223 | cistpl_cftable_entry_t *cfg; | ||
224 | int i, pass, last_ret = 0, last_fn = 0, hd, is_kme = 0; | ||
225 | unsigned long io_base, ctl_base; | ||
226 | |||
227 | DEBUG(0, "ide_config(0x%p)\n", link); | ||
228 | |||
229 | stk = kmalloc(sizeof(*stk), GFP_KERNEL); | ||
230 | if (!stk) goto err_mem; | ||
231 | memset(stk, 0, sizeof(*stk)); | ||
232 | cfg = &stk->parse.cftable_entry; | ||
233 | |||
234 | tuple.TupleData = (cisdata_t *)&stk->buf; | ||
235 | tuple.TupleOffset = 0; | ||
236 | tuple.TupleDataMax = 255; | ||
237 | tuple.Attributes = 0; | ||
238 | tuple.DesiredTuple = CISTPL_CONFIG; | ||
239 | CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); | ||
240 | CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); | ||
241 | CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &stk->parse)); | ||
242 | link->conf.ConfigBase = stk->parse.config.base; | ||
243 | link->conf.Present = stk->parse.config.rmask[0]; | ||
244 | |||
245 | tuple.DesiredTuple = CISTPL_MANFID; | ||
246 | if (!pcmcia_get_first_tuple(handle, &tuple) && | ||
247 | !pcmcia_get_tuple_data(handle, &tuple) && | ||
248 | !pcmcia_parse_tuple(handle, &tuple, &stk->parse)) | ||
249 | is_kme = ((stk->parse.manfid.manf == MANFID_KME) && | ||
250 | ((stk->parse.manfid.card == PRODID_KME_KXLC005_A) || | ||
251 | (stk->parse.manfid.card == PRODID_KME_KXLC005_B))); | ||
252 | |||
253 | /* Configure card */ | ||
254 | link->state |= DEV_CONFIG; | ||
255 | |||
256 | /* Not sure if this is right... look up the current Vcc */ | ||
257 | CS_CHECK(GetConfigurationInfo, pcmcia_get_configuration_info(handle, &stk->conf)); | ||
258 | link->conf.Vcc = stk->conf.Vcc; | ||
259 | |||
260 | pass = io_base = ctl_base = 0; | ||
261 | tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; | ||
262 | tuple.Attributes = 0; | ||
263 | CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); | ||
264 | while (1) { | ||
265 | if (pcmcia_get_tuple_data(handle, &tuple) != 0) goto next_entry; | ||
266 | if (pcmcia_parse_tuple(handle, &tuple, &stk->parse) != 0) goto next_entry; | ||
267 | |||
268 | /* Check for matching Vcc, unless we're desperate */ | ||
269 | if (!pass) { | ||
270 | if (cfg->vcc.present & (1 << CISTPL_POWER_VNOM)) { | ||
271 | if (stk->conf.Vcc != cfg->vcc.param[CISTPL_POWER_VNOM] / 10000) | ||
272 | goto next_entry; | ||
273 | } else if (stk->dflt.vcc.present & (1 << CISTPL_POWER_VNOM)) { | ||
274 | if (stk->conf.Vcc != stk->dflt.vcc.param[CISTPL_POWER_VNOM] / 10000) | ||
275 | goto next_entry; | ||
276 | } | ||
277 | } | ||
278 | |||
279 | if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM)) | ||
280 | link->conf.Vpp1 = link->conf.Vpp2 = | ||
281 | cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000; | ||
282 | else if (stk->dflt.vpp1.present & (1 << CISTPL_POWER_VNOM)) | ||
283 | link->conf.Vpp1 = link->conf.Vpp2 = | ||
284 | stk->dflt.vpp1.param[CISTPL_POWER_VNOM] / 10000; | ||
285 | |||
286 | if ((cfg->io.nwin > 0) || (stk->dflt.io.nwin > 0)) { | ||
287 | cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &stk->dflt.io; | ||
288 | link->conf.ConfigIndex = cfg->index; | ||
289 | link->io.BasePort1 = io->win[0].base; | ||
290 | link->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK; | ||
291 | if (!(io->flags & CISTPL_IO_16BIT)) | ||
292 | link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; | ||
293 | if (io->nwin == 2) { | ||
294 | link->io.NumPorts1 = 8; | ||
295 | link->io.BasePort2 = io->win[1].base; | ||
296 | link->io.NumPorts2 = (is_kme) ? 2 : 1; | ||
297 | if (pcmcia_request_io(link->handle, &link->io) != 0) | ||
298 | goto next_entry; | ||
299 | io_base = link->io.BasePort1; | ||
300 | ctl_base = link->io.BasePort2; | ||
301 | } else if ((io->nwin == 1) && (io->win[0].len >= 16)) { | ||
302 | link->io.NumPorts1 = io->win[0].len; | ||
303 | link->io.NumPorts2 = 0; | ||
304 | if (pcmcia_request_io(link->handle, &link->io) != 0) | ||
305 | goto next_entry; | ||
306 | io_base = link->io.BasePort1; | ||
307 | ctl_base = link->io.BasePort1 + 0x0e; | ||
308 | } else goto next_entry; | ||
309 | /* If we've got this far, we're done */ | ||
310 | break; | ||
311 | } | ||
312 | |||
313 | next_entry: | ||
314 | if (cfg->flags & CISTPL_CFTABLE_DEFAULT) | ||
315 | memcpy(&stk->dflt, cfg, sizeof(stk->dflt)); | ||
316 | if (pass) { | ||
317 | CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(handle, &tuple)); | ||
318 | } else if (pcmcia_get_next_tuple(handle, &tuple) != 0) { | ||
319 | CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); | ||
320 | memset(&stk->dflt, 0, sizeof(stk->dflt)); | ||
321 | pass++; | ||
322 | } | ||
323 | } | ||
324 | |||
325 | CS_CHECK(RequestIRQ, pcmcia_request_irq(handle, &link->irq)); | ||
326 | CS_CHECK(RequestConfiguration, pcmcia_request_configuration(handle, &link->conf)); | ||
327 | |||
328 | /* disable drive interrupts during IDE probe */ | ||
329 | outb(0x02, ctl_base); | ||
330 | |||
331 | /* special setup for KXLC005 card */ | ||
332 | if (is_kme) | ||
333 | outb(0x81, ctl_base+1); | ||
334 | |||
335 | /* retry registration in case device is still spinning up */ | ||
336 | for (hd = -1, i = 0; i < 10; i++) { | ||
337 | hd = idecs_register(io_base, ctl_base, link->irq.AssignedIRQ); | ||
338 | if (hd >= 0) break; | ||
339 | if (link->io.NumPorts1 == 0x20) { | ||
340 | outb(0x02, ctl_base + 0x10); | ||
341 | hd = idecs_register(io_base + 0x10, ctl_base + 0x10, | ||
342 | link->irq.AssignedIRQ); | ||
343 | if (hd >= 0) { | ||
344 | io_base += 0x10; | ||
345 | ctl_base += 0x10; | ||
346 | break; | ||
347 | } | ||
348 | } | ||
349 | __set_current_state(TASK_UNINTERRUPTIBLE); | ||
350 | schedule_timeout(HZ/10); | ||
351 | } | ||
352 | |||
353 | if (hd < 0) { | ||
354 | printk(KERN_NOTICE "ide-cs: ide_register() at 0x%3lx & 0x%3lx" | ||
355 | ", irq %u failed\n", io_base, ctl_base, | ||
356 | link->irq.AssignedIRQ); | ||
357 | goto failed; | ||
358 | } | ||
359 | |||
360 | info->ndev = 1; | ||
361 | sprintf(info->node.dev_name, "hd%c", 'a' + (hd * 2)); | ||
362 | info->node.major = ide_major[hd]; | ||
363 | info->node.minor = 0; | ||
364 | info->hd = hd; | ||
365 | link->dev = &info->node; | ||
366 | printk(KERN_INFO "ide-cs: %s: Vcc = %d.%d, Vpp = %d.%d\n", | ||
367 | info->node.dev_name, link->conf.Vcc / 10, link->conf.Vcc % 10, | ||
368 | link->conf.Vpp1 / 10, link->conf.Vpp1 % 10); | ||
369 | |||
370 | link->state &= ~DEV_CONFIG_PENDING; | ||
371 | kfree(stk); | ||
372 | return; | ||
373 | |||
374 | err_mem: | ||
375 | printk(KERN_NOTICE "ide-cs: ide_config failed memory allocation\n"); | ||
376 | goto failed; | ||
377 | |||
378 | cs_failed: | ||
379 | cs_error(link->handle, last_fn, last_ret); | ||
380 | failed: | ||
381 | kfree(stk); | ||
382 | ide_release(link); | ||
383 | link->state &= ~DEV_CONFIG_PENDING; | ||
384 | } /* ide_config */ | ||
385 | |||
386 | /*====================================================================== | ||
387 | |||
388 | After a card is removed, ide_release() will unregister the net | ||
389 | device, and release the PCMCIA configuration. If the device is | ||
390 | still open, this will be postponed until it is closed. | ||
391 | |||
392 | ======================================================================*/ | ||
393 | |||
394 | void ide_release(dev_link_t *link) | ||
395 | { | ||
396 | ide_info_t *info = link->priv; | ||
397 | |||
398 | DEBUG(0, "ide_release(0x%p)\n", link); | ||
399 | |||
400 | if (info->ndev) { | ||
401 | /* FIXME: if this fails we need to queue the cleanup somehow | ||
402 | -- need to investigate the required PCMCIA magic */ | ||
403 | ide_unregister(info->hd); | ||
404 | } | ||
405 | info->ndev = 0; | ||
406 | link->dev = NULL; | ||
407 | |||
408 | pcmcia_release_configuration(link->handle); | ||
409 | pcmcia_release_io(link->handle, &link->io); | ||
410 | pcmcia_release_irq(link->handle, &link->irq); | ||
411 | |||
412 | link->state &= ~DEV_CONFIG; | ||
413 | |||
414 | } /* ide_release */ | ||
415 | |||
416 | /*====================================================================== | ||
417 | |||
418 | The card status event handler. Mostly, this schedules other | ||
419 | stuff to run after an event is received. A CARD_REMOVAL event | ||
420 | also sets some flags to discourage the ide drivers from | ||
421 | talking to the ports. | ||
422 | |||
423 | ======================================================================*/ | ||
424 | |||
425 | int ide_event(event_t event, int priority, | ||
426 | event_callback_args_t *args) | ||
427 | { | ||
428 | dev_link_t *link = args->client_data; | ||
429 | |||
430 | DEBUG(1, "ide_event(0x%06x)\n", event); | ||
431 | |||
432 | switch (event) { | ||
433 | case CS_EVENT_CARD_REMOVAL: | ||
434 | link->state &= ~DEV_PRESENT; | ||
435 | if (link->state & DEV_CONFIG) | ||
436 | ide_release(link); | ||
437 | break; | ||
438 | case CS_EVENT_CARD_INSERTION: | ||
439 | link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; | ||
440 | ide_config(link); | ||
441 | break; | ||
442 | case CS_EVENT_PM_SUSPEND: | ||
443 | link->state |= DEV_SUSPEND; | ||
444 | /* Fall through... */ | ||
445 | case CS_EVENT_RESET_PHYSICAL: | ||
446 | if (link->state & DEV_CONFIG) | ||
447 | pcmcia_release_configuration(link->handle); | ||
448 | break; | ||
449 | case CS_EVENT_PM_RESUME: | ||
450 | link->state &= ~DEV_SUSPEND; | ||
451 | /* Fall through... */ | ||
452 | case CS_EVENT_CARD_RESET: | ||
453 | if (DEV_OK(link)) | ||
454 | pcmcia_request_configuration(link->handle, &link->conf); | ||
455 | break; | ||
456 | } | ||
457 | return 0; | ||
458 | } /* ide_event */ | ||
459 | |||
460 | static struct pcmcia_driver ide_cs_driver = { | ||
461 | .owner = THIS_MODULE, | ||
462 | .drv = { | ||
463 | .name = "ide-cs", | ||
464 | }, | ||
465 | .attach = ide_attach, | ||
466 | .detach = ide_detach, | ||
467 | }; | ||
468 | |||
469 | static int __init init_ide_cs(void) | ||
470 | { | ||
471 | return pcmcia_register_driver(&ide_cs_driver); | ||
472 | } | ||
473 | |||
474 | static void __exit exit_ide_cs(void) | ||
475 | { | ||
476 | pcmcia_unregister_driver(&ide_cs_driver); | ||
477 | BUG_ON(dev_list != NULL); | ||
478 | } | ||
479 | |||
480 | module_init(init_ide_cs); | ||
481 | module_exit(exit_ide_cs); | ||
diff --git a/drivers/ide/legacy/macide.c b/drivers/ide/legacy/macide.c new file mode 100644 index 000000000000..90cac609d9cf --- /dev/null +++ b/drivers/ide/legacy/macide.c | |||
@@ -0,0 +1,155 @@ | |||
1 | /* | ||
2 | * linux/drivers/ide/legacy/macide.c -- Macintosh IDE Driver | ||
3 | * | ||
4 | * Copyright (C) 1998 by Michael Schmitz | ||
5 | * | ||
6 | * This driver was written based on information obtained from the MacOS IDE | ||
7 | * driver binary by Mikael Forselius | ||
8 | * | ||
9 | * This file is subject to the terms and conditions of the GNU General Public | ||
10 | * License. See the file COPYING in the main directory of this archive for | ||
11 | * more details. | ||
12 | */ | ||
13 | |||
14 | #include <linux/config.h> | ||
15 | #include <linux/types.h> | ||
16 | #include <linux/mm.h> | ||
17 | #include <linux/interrupt.h> | ||
18 | #include <linux/blkdev.h> | ||
19 | #include <linux/hdreg.h> | ||
20 | #include <linux/delay.h> | ||
21 | #include <linux/ide.h> | ||
22 | |||
23 | #include <asm/machw.h> | ||
24 | #include <asm/macintosh.h> | ||
25 | #include <asm/macints.h> | ||
26 | #include <asm/mac_baboon.h> | ||
27 | |||
28 | #define IDE_BASE 0x50F1A000 /* Base address of IDE controller */ | ||
29 | |||
30 | /* | ||
31 | * Generic IDE registers as offsets from the base | ||
32 | * These match MkLinux so they should be correct. | ||
33 | */ | ||
34 | |||
35 | #define IDE_DATA 0x00 | ||
36 | #define IDE_ERROR 0x04 /* see err-bits */ | ||
37 | #define IDE_NSECTOR 0x08 /* nr of sectors to read/write */ | ||
38 | #define IDE_SECTOR 0x0c /* starting sector */ | ||
39 | #define IDE_LCYL 0x10 /* starting cylinder */ | ||
40 | #define IDE_HCYL 0x14 /* high byte of starting cyl */ | ||
41 | #define IDE_SELECT 0x18 /* 101dhhhh , d=drive, hhhh=head */ | ||
42 | #define IDE_STATUS 0x1c /* see status-bits */ | ||
43 | #define IDE_CONTROL 0x38 /* control/altstatus */ | ||
44 | |||
45 | /* | ||
46 | * Mac-specific registers | ||
47 | */ | ||
48 | |||
49 | /* | ||
50 | * this register is odd; it doesn't seem to do much and it's | ||
51 | * not word-aligned like virtually every other hardware register | ||
52 | * on the Mac... | ||
53 | */ | ||
54 | |||
55 | #define IDE_IFR 0x101 /* (0x101) IDE interrupt flags on Quadra: | ||
56 | * | ||
57 | * Bit 0+1: some interrupt flags | ||
58 | * Bit 2+3: some interrupt enable | ||
59 | * Bit 4: ?? | ||
60 | * Bit 5: IDE interrupt flag (any hwif) | ||
61 | * Bit 6: maybe IDE interrupt enable (any hwif) ?? | ||
62 | * Bit 7: Any interrupt condition | ||
63 | */ | ||
64 | |||
65 | volatile unsigned char *ide_ifr = (unsigned char *) (IDE_BASE + IDE_IFR); | ||
66 | |||
67 | static int macide_offsets[IDE_NR_PORTS] = { | ||
68 | IDE_DATA, IDE_ERROR, IDE_NSECTOR, IDE_SECTOR, IDE_LCYL, | ||
69 | IDE_HCYL, IDE_SELECT, IDE_STATUS, IDE_CONTROL | ||
70 | }; | ||
71 | |||
72 | int macide_ack_intr(ide_hwif_t* hwif) | ||
73 | { | ||
74 | if (*ide_ifr & 0x20) { | ||
75 | *ide_ifr &= ~0x20; | ||
76 | return 1; | ||
77 | } | ||
78 | return 0; | ||
79 | } | ||
80 | |||
81 | #ifdef CONFIG_BLK_DEV_MAC_MEDIABAY | ||
82 | static void macide_mediabay_interrupt(int irq, void *dev_id, struct pt_regs *regs) | ||
83 | { | ||
84 | int state = baboon->mb_status & 0x04; | ||
85 | |||
86 | printk(KERN_INFO "macide: media bay %s detected\n", state? "removal":"insertion"); | ||
87 | } | ||
88 | #endif | ||
89 | |||
90 | /* | ||
91 | * Probe for a Macintosh IDE interface | ||
92 | */ | ||
93 | |||
94 | void macide_init(void) | ||
95 | { | ||
96 | hw_regs_t hw; | ||
97 | ide_hwif_t *hwif; | ||
98 | int index = -1; | ||
99 | |||
100 | switch (macintosh_config->ide_type) { | ||
101 | case MAC_IDE_QUADRA: | ||
102 | ide_setup_ports(&hw, IDE_BASE, macide_offsets, | ||
103 | 0, 0, macide_ack_intr, | ||
104 | // quadra_ide_iops, | ||
105 | IRQ_NUBUS_F); | ||
106 | index = ide_register_hw(&hw, &hwif); | ||
107 | break; | ||
108 | case MAC_IDE_PB: | ||
109 | ide_setup_ports(&hw, IDE_BASE, macide_offsets, | ||
110 | 0, 0, macide_ack_intr, | ||
111 | // macide_pb_iops, | ||
112 | IRQ_NUBUS_C); | ||
113 | index = ide_register_hw(&hw, &hwif); | ||
114 | break; | ||
115 | case MAC_IDE_BABOON: | ||
116 | ide_setup_ports(&hw, BABOON_BASE, macide_offsets, | ||
117 | 0, 0, NULL, | ||
118 | // macide_baboon_iops, | ||
119 | IRQ_BABOON_1); | ||
120 | index = ide_register_hw(&hw, &hwif); | ||
121 | if (index == -1) break; | ||
122 | if (macintosh_config->ident == MAC_MODEL_PB190) { | ||
123 | |||
124 | /* Fix breakage in ide-disk.c: drive capacity */ | ||
125 | /* is not initialized for drives without a */ | ||
126 | /* hardware ID, and we can't get that without */ | ||
127 | /* probing the drive which freezes a 190. */ | ||
128 | |||
129 | ide_drive_t *drive = &ide_hwifs[index].drives[0]; | ||
130 | drive->capacity64 = drive->cyl*drive->head*drive->sect; | ||
131 | |||
132 | #ifdef CONFIG_BLK_DEV_MAC_MEDIABAY | ||
133 | request_irq(IRQ_BABOON_2, macide_mediabay_interrupt, | ||
134 | IRQ_FLG_FAST, "mediabay", | ||
135 | macide_mediabay_interrupt); | ||
136 | #endif | ||
137 | } | ||
138 | break; | ||
139 | |||
140 | default: | ||
141 | return; | ||
142 | } | ||
143 | |||
144 | if (index != -1) { | ||
145 | hwif->mmio = 2; | ||
146 | if (macintosh_config->ide_type == MAC_IDE_QUADRA) | ||
147 | printk(KERN_INFO "ide%d: Macintosh Quadra IDE interface\n", index); | ||
148 | else if (macintosh_config->ide_type == MAC_IDE_PB) | ||
149 | printk(KERN_INFO "ide%d: Macintosh Powerbook IDE interface\n", index); | ||
150 | else if (macintosh_config->ide_type == MAC_IDE_BABOON) | ||
151 | printk(KERN_INFO "ide%d: Macintosh Powerbook Baboon IDE interface\n", index); | ||
152 | else | ||
153 | printk(KERN_INFO "ide%d: Unknown Macintosh IDE interface\n", index); | ||
154 | } | ||
155 | } | ||
diff --git a/drivers/ide/legacy/q40ide.c b/drivers/ide/legacy/q40ide.c new file mode 100644 index 000000000000..2a78b792f7fb --- /dev/null +++ b/drivers/ide/legacy/q40ide.c | |||
@@ -0,0 +1,150 @@ | |||
1 | /* | ||
2 | * linux/drivers/ide/legacy/q40ide.c -- Q40 I/O port IDE Driver | ||
3 | * | ||
4 | * (c) Richard Zidlicky | ||
5 | * | ||
6 | * This file is subject to the terms and conditions of the GNU General Public | ||
7 | * License. See the file COPYING in the main directory of this archive for | ||
8 | * more details. | ||
9 | * | ||
10 | * | ||
11 | */ | ||
12 | |||
13 | #include <linux/types.h> | ||
14 | #include <linux/mm.h> | ||
15 | #include <linux/interrupt.h> | ||
16 | #include <linux/blkdev.h> | ||
17 | #include <linux/hdreg.h> | ||
18 | |||
19 | #include <linux/ide.h> | ||
20 | |||
21 | /* | ||
22 | * Bases of the IDE interfaces | ||
23 | */ | ||
24 | |||
25 | #define Q40IDE_NUM_HWIFS 2 | ||
26 | |||
27 | #define PCIDE_BASE1 0x1f0 | ||
28 | #define PCIDE_BASE2 0x170 | ||
29 | #define PCIDE_BASE3 0x1e8 | ||
30 | #define PCIDE_BASE4 0x168 | ||
31 | #define PCIDE_BASE5 0x1e0 | ||
32 | #define PCIDE_BASE6 0x160 | ||
33 | |||
34 | static const unsigned long pcide_bases[Q40IDE_NUM_HWIFS] = { | ||
35 | PCIDE_BASE1, PCIDE_BASE2, /* PCIDE_BASE3, PCIDE_BASE4 , PCIDE_BASE5, | ||
36 | PCIDE_BASE6 */ | ||
37 | }; | ||
38 | |||
39 | |||
40 | /* | ||
41 | * Offsets from one of the above bases | ||
42 | */ | ||
43 | |||
44 | /* used to do addr translation here but it is easier to do in setup ports */ | ||
45 | /*#define IDE_OFF_B(x) ((unsigned long)Q40_ISA_IO_B((IDE_##x##_OFFSET)))*/ | ||
46 | |||
47 | #define IDE_OFF_B(x) ((unsigned long)((IDE_##x##_OFFSET))) | ||
48 | #define IDE_OFF_W(x) ((unsigned long)((IDE_##x##_OFFSET))) | ||
49 | |||
50 | static const int pcide_offsets[IDE_NR_PORTS] = { | ||
51 | IDE_OFF_W(DATA), IDE_OFF_B(ERROR), IDE_OFF_B(NSECTOR), IDE_OFF_B(SECTOR), | ||
52 | IDE_OFF_B(LCYL), IDE_OFF_B(HCYL), 6 /*IDE_OFF_B(CURRENT)*/, IDE_OFF_B(STATUS), | ||
53 | 518/*IDE_OFF(CMD)*/ | ||
54 | }; | ||
55 | |||
56 | static int q40ide_default_irq(unsigned long base) | ||
57 | { | ||
58 | switch (base) { | ||
59 | case 0x1f0: return 14; | ||
60 | case 0x170: return 15; | ||
61 | case 0x1e8: return 11; | ||
62 | default: | ||
63 | return 0; | ||
64 | } | ||
65 | } | ||
66 | |||
67 | |||
68 | /* | ||
69 | * This is very similar to ide_setup_ports except that addresses | ||
70 | * are pretranslated for q40 ISA access | ||
71 | */ | ||
72 | void q40_ide_setup_ports ( hw_regs_t *hw, | ||
73 | unsigned long base, int *offsets, | ||
74 | unsigned long ctrl, unsigned long intr, | ||
75 | ide_ack_intr_t *ack_intr, | ||
76 | /* | ||
77 | * ide_io_ops_t *iops, | ||
78 | */ | ||
79 | int irq) | ||
80 | { | ||
81 | int i; | ||
82 | |||
83 | for (i = 0; i < IDE_NR_PORTS; i++) { | ||
84 | /* BIG FAT WARNING: | ||
85 | assumption: only DATA port is ever used in 16 bit mode */ | ||
86 | if ( i==0 ) | ||
87 | hw->io_ports[i] = Q40_ISA_IO_W(base + offsets[i]); | ||
88 | else | ||
89 | hw->io_ports[i] = Q40_ISA_IO_B(base + offsets[i]); | ||
90 | } | ||
91 | |||
92 | hw->irq = irq; | ||
93 | hw->dma = NO_DMA; | ||
94 | hw->ack_intr = ack_intr; | ||
95 | /* | ||
96 | * hw->iops = iops; | ||
97 | */ | ||
98 | } | ||
99 | |||
100 | |||
101 | |||
102 | /* | ||
103 | * the static array is needed to have the name reported in /proc/ioports, | ||
104 | * hwif->name unfortunately isn´t available yet | ||
105 | */ | ||
106 | static const char *q40_ide_names[Q40IDE_NUM_HWIFS]={ | ||
107 | "ide0", "ide1" | ||
108 | }; | ||
109 | |||
110 | /* | ||
111 | * Probe for Q40 IDE interfaces | ||
112 | */ | ||
113 | |||
114 | void q40ide_init(void) | ||
115 | { | ||
116 | int i; | ||
117 | ide_hwif_t *hwif; | ||
118 | int index; | ||
119 | const char *name; | ||
120 | |||
121 | if (!MACH_IS_Q40) | ||
122 | return ; | ||
123 | |||
124 | for (i = 0; i < Q40IDE_NUM_HWIFS; i++) { | ||
125 | hw_regs_t hw; | ||
126 | |||
127 | name = q40_ide_names[i]; | ||
128 | if (!request_region(pcide_bases[i], 8, name)) { | ||
129 | printk("could not reserve ports %lx-%lx for %s\n", | ||
130 | pcide_bases[i],pcide_bases[i]+8,name); | ||
131 | continue; | ||
132 | } | ||
133 | if (!request_region(pcide_bases[i]+0x206, 1, name)) { | ||
134 | printk("could not reserve port %lx for %s\n", | ||
135 | pcide_bases[i]+0x206,name); | ||
136 | release_region(pcide_bases[i], 8); | ||
137 | continue; | ||
138 | } | ||
139 | q40_ide_setup_ports(&hw,(unsigned long) pcide_bases[i], (int *)pcide_offsets, | ||
140 | pcide_bases[i]+0x206, | ||
141 | 0, NULL, | ||
142 | // m68kide_iops, | ||
143 | q40ide_default_irq(pcide_bases[i])); | ||
144 | index = ide_register_hw(&hw, &hwif); | ||
145 | // **FIXME** | ||
146 | if (index != -1) | ||
147 | hwif->mmio = 2; | ||
148 | } | ||
149 | } | ||
150 | |||
diff --git a/drivers/ide/legacy/qd65xx.c b/drivers/ide/legacy/qd65xx.c new file mode 100644 index 000000000000..563fab0098be --- /dev/null +++ b/drivers/ide/legacy/qd65xx.c | |||
@@ -0,0 +1,511 @@ | |||
1 | /* | ||
2 | * linux/drivers/ide/legacy/qd65xx.c Version 0.07 Sep 30, 2001 | ||
3 | * | ||
4 | * Copyright (C) 1996-2001 Linus Torvalds & author (see below) | ||
5 | */ | ||
6 | |||
7 | /* | ||
8 | * Version 0.03 Cleaned auto-tune, added probe | ||
9 | * Version 0.04 Added second channel tuning | ||
10 | * Version 0.05 Enhanced tuning ; added qd6500 support | ||
11 | * Version 0.06 Added dos driver's list | ||
12 | * Version 0.07 Second channel bug fix | ||
13 | * | ||
14 | * QDI QD6500/QD6580 EIDE controller fast support | ||
15 | * | ||
16 | * Please set local bus speed using kernel parameter idebus | ||
17 | * for example, "idebus=33" stands for 33Mhz VLbus | ||
18 | * To activate controller support, use "ide0=qd65xx" | ||
19 | * To enable tuning, use "ide0=autotune" | ||
20 | * To enable second channel tuning (qd6580 only), use "ide1=autotune" | ||
21 | */ | ||
22 | |||
23 | /* | ||
24 | * Rewritten from the work of Colten Edwards <pje120@cs.usask.ca> by | ||
25 | * Samuel Thibault <samuel.thibault@fnac.net> | ||
26 | */ | ||
27 | |||
28 | #undef REALLY_SLOW_IO /* most systems can safely undef this */ | ||
29 | |||
30 | #include <linux/module.h> | ||
31 | #include <linux/config.h> | ||
32 | #include <linux/types.h> | ||
33 | #include <linux/kernel.h> | ||
34 | #include <linux/delay.h> | ||
35 | #include <linux/timer.h> | ||
36 | #include <linux/mm.h> | ||
37 | #include <linux/ioport.h> | ||
38 | #include <linux/blkdev.h> | ||
39 | #include <linux/hdreg.h> | ||
40 | #include <linux/ide.h> | ||
41 | #include <linux/init.h> | ||
42 | #include <asm/system.h> | ||
43 | #include <asm/io.h> | ||
44 | |||
45 | #include "qd65xx.h" | ||
46 | |||
47 | /* | ||
48 | * I/O ports are 0x30-0x31 (and 0x32-0x33 for qd6580) | ||
49 | * or 0xb0-0xb1 (and 0xb2-0xb3 for qd6580) | ||
50 | * -- qd6500 is a single IDE interface | ||
51 | * -- qd6580 is a dual IDE interface | ||
52 | * | ||
53 | * More research on qd6580 being done by willmore@cig.mot.com (David) | ||
54 | * More Information given by Petr Soucek (petr@ryston.cz) | ||
55 | * http://www.ryston.cz/petr/vlb | ||
56 | */ | ||
57 | |||
58 | /* | ||
59 | * base: Timer1 | ||
60 | * | ||
61 | * | ||
62 | * base+0x01: Config (R/O) | ||
63 | * | ||
64 | * bit 0: ide baseport: 1 = 0x1f0 ; 0 = 0x170 (only useful for qd6500) | ||
65 | * bit 1: qd65xx baseport: 1 = 0xb0 ; 0 = 0x30 | ||
66 | * bit 2: ID3: bus speed: 1 = <=33MHz ; 0 = >33MHz | ||
67 | * bit 3: qd6500: 1 = disabled, 0 = enabled | ||
68 | * qd6580: 1 | ||
69 | * upper nibble: | ||
70 | * qd6500: 1100 | ||
71 | * qd6580: either 1010 or 0101 | ||
72 | * | ||
73 | * | ||
74 | * base+0x02: Timer2 (qd6580 only) | ||
75 | * | ||
76 | * | ||
77 | * base+0x03: Control (qd6580 only) | ||
78 | * | ||
79 | * bits 0-3 must always be set 1 | ||
80 | * bit 4 must be set 1, but is set 0 by dos driver while measuring vlb clock | ||
81 | * bit 0 : 1 = Only primary port enabled : channel 0 for hda, channel 1 for hdb | ||
82 | * 0 = Primary and Secondary ports enabled : channel 0 for hda & hdb | ||
83 | * channel 1 for hdc & hdd | ||
84 | * bit 1 : 1 = only disks on primary port | ||
85 | * 0 = disks & ATAPI devices on primary port | ||
86 | * bit 2-4 : always 0 | ||
87 | * bit 5 : status, but of what ? | ||
88 | * bit 6 : always set 1 by dos driver | ||
89 | * bit 7 : set 1 for non-ATAPI devices on primary port | ||
90 | * (maybe read-ahead and post-write buffer ?) | ||
91 | */ | ||
92 | |||
93 | static int timings[4]={-1,-1,-1,-1}; /* stores current timing for each timer */ | ||
94 | |||
95 | static void qd_write_reg (u8 content, unsigned long reg) | ||
96 | { | ||
97 | unsigned long flags; | ||
98 | |||
99 | spin_lock_irqsave(&ide_lock, flags); | ||
100 | outb(content,reg); | ||
101 | spin_unlock_irqrestore(&ide_lock, flags); | ||
102 | } | ||
103 | |||
104 | static u8 __init qd_read_reg (unsigned long reg) | ||
105 | { | ||
106 | unsigned long flags; | ||
107 | u8 read; | ||
108 | |||
109 | spin_lock_irqsave(&ide_lock, flags); | ||
110 | read = inb(reg); | ||
111 | spin_unlock_irqrestore(&ide_lock, flags); | ||
112 | return read; | ||
113 | } | ||
114 | |||
115 | /* | ||
116 | * qd_select: | ||
117 | * | ||
118 | * This routine is invoked from ide.c to prepare for access to a given drive. | ||
119 | */ | ||
120 | |||
121 | static void qd_select (ide_drive_t *drive) | ||
122 | { | ||
123 | u8 index = (( (QD_TIMREG(drive)) & 0x80 ) >> 7) | | ||
124 | (QD_TIMREG(drive) & 0x02); | ||
125 | |||
126 | if (timings[index] != QD_TIMING(drive)) | ||
127 | qd_write_reg(timings[index] = QD_TIMING(drive), QD_TIMREG(drive)); | ||
128 | } | ||
129 | |||
130 | /* | ||
131 | * qd6500_compute_timing | ||
132 | * | ||
133 | * computes the timing value where | ||
134 | * lower nibble represents active time, in count of VLB clocks | ||
135 | * upper nibble represents recovery time, in count of VLB clocks | ||
136 | */ | ||
137 | |||
138 | static u8 qd6500_compute_timing (ide_hwif_t *hwif, int active_time, int recovery_time) | ||
139 | { | ||
140 | u8 active_cycle,recovery_cycle; | ||
141 | |||
142 | if (system_bus_clock()<=33) { | ||
143 | active_cycle = 9 - IDE_IN(active_time * system_bus_clock() / 1000 + 1, 2, 9); | ||
144 | recovery_cycle = 15 - IDE_IN(recovery_time * system_bus_clock() / 1000 + 1, 0, 15); | ||
145 | } else { | ||
146 | active_cycle = 8 - IDE_IN(active_time * system_bus_clock() / 1000 + 1, 1, 8); | ||
147 | recovery_cycle = 18 - IDE_IN(recovery_time * system_bus_clock() / 1000 + 1, 3, 18); | ||
148 | } | ||
149 | |||
150 | return((recovery_cycle<<4) | 0x08 | active_cycle); | ||
151 | } | ||
152 | |||
153 | /* | ||
154 | * qd6580_compute_timing | ||
155 | * | ||
156 | * idem for qd6580 | ||
157 | */ | ||
158 | |||
159 | static u8 qd6580_compute_timing (int active_time, int recovery_time) | ||
160 | { | ||
161 | u8 active_cycle = 17 - IDE_IN(active_time * system_bus_clock() / 1000 + 1, 2, 17); | ||
162 | u8 recovery_cycle = 15 - IDE_IN(recovery_time * system_bus_clock() / 1000 + 1, 2, 15); | ||
163 | |||
164 | return((recovery_cycle<<4) | active_cycle); | ||
165 | } | ||
166 | |||
167 | /* | ||
168 | * qd_find_disk_type | ||
169 | * | ||
170 | * tries to find timing from dos driver's table | ||
171 | */ | ||
172 | |||
173 | static int qd_find_disk_type (ide_drive_t *drive, | ||
174 | int *active_time, int *recovery_time) | ||
175 | { | ||
176 | struct qd65xx_timing_s *p; | ||
177 | char model[40]; | ||
178 | |||
179 | if (!*drive->id->model) return 0; | ||
180 | |||
181 | strncpy(model,drive->id->model,40); | ||
182 | ide_fixstring(model,40,1); /* byte-swap */ | ||
183 | |||
184 | for (p = qd65xx_timing ; p->offset != -1 ; p++) { | ||
185 | if (!strncmp(p->model, model+p->offset, 4)) { | ||
186 | printk(KERN_DEBUG "%s: listed !\n", drive->name); | ||
187 | *active_time = p->active; | ||
188 | *recovery_time = p->recovery; | ||
189 | return 1; | ||
190 | } | ||
191 | } | ||
192 | return 0; | ||
193 | } | ||
194 | |||
195 | /* | ||
196 | * qd_timing_ok: | ||
197 | * | ||
198 | * check whether timings don't conflict | ||
199 | */ | ||
200 | |||
201 | static int qd_timing_ok (ide_drive_t drives[]) | ||
202 | { | ||
203 | return (IDE_IMPLY(drives[0].present && drives[1].present, | ||
204 | IDE_IMPLY(QD_TIMREG(drives) == QD_TIMREG(drives+1), | ||
205 | QD_TIMING(drives) == QD_TIMING(drives+1)))); | ||
206 | /* if same timing register, must be same timing */ | ||
207 | } | ||
208 | |||
209 | /* | ||
210 | * qd_set_timing: | ||
211 | * | ||
212 | * records the timing, and enables selectproc as needed | ||
213 | */ | ||
214 | |||
215 | static void qd_set_timing (ide_drive_t *drive, u8 timing) | ||
216 | { | ||
217 | ide_hwif_t *hwif = HWIF(drive); | ||
218 | |||
219 | drive->drive_data &= 0xff00; | ||
220 | drive->drive_data |= timing; | ||
221 | if (qd_timing_ok(hwif->drives)) { | ||
222 | qd_select(drive); /* selects once */ | ||
223 | hwif->selectproc = NULL; | ||
224 | } else | ||
225 | hwif->selectproc = &qd_select; | ||
226 | |||
227 | printk(KERN_DEBUG "%s: %#x\n", drive->name, timing); | ||
228 | } | ||
229 | |||
230 | /* | ||
231 | * qd6500_tune_drive | ||
232 | */ | ||
233 | |||
234 | static void qd6500_tune_drive (ide_drive_t *drive, u8 pio) | ||
235 | { | ||
236 | int active_time = 175; | ||
237 | int recovery_time = 415; /* worst case values from the dos driver */ | ||
238 | |||
239 | if (drive->id && !qd_find_disk_type(drive, &active_time, &recovery_time) | ||
240 | && drive->id->tPIO && (drive->id->field_valid & 0x02) | ||
241 | && drive->id->eide_pio >= 240) { | ||
242 | |||
243 | printk(KERN_INFO "%s: PIO mode%d\n", drive->name, | ||
244 | drive->id->tPIO); | ||
245 | active_time = 110; | ||
246 | recovery_time = drive->id->eide_pio - 120; | ||
247 | } | ||
248 | |||
249 | qd_set_timing(drive, qd6500_compute_timing(HWIF(drive), active_time, recovery_time)); | ||
250 | } | ||
251 | |||
252 | /* | ||
253 | * qd6580_tune_drive | ||
254 | */ | ||
255 | |||
256 | static void qd6580_tune_drive (ide_drive_t *drive, u8 pio) | ||
257 | { | ||
258 | ide_pio_data_t d; | ||
259 | int base = HWIF(drive)->select_data; | ||
260 | int active_time = 175; | ||
261 | int recovery_time = 415; /* worst case values from the dos driver */ | ||
262 | |||
263 | if (drive->id && !qd_find_disk_type(drive, &active_time, &recovery_time)) { | ||
264 | pio = ide_get_best_pio_mode(drive, pio, 255, &d); | ||
265 | pio = min_t(u8, pio, 4); | ||
266 | |||
267 | switch (pio) { | ||
268 | case 0: break; | ||
269 | case 3: | ||
270 | if (d.cycle_time >= 110) { | ||
271 | active_time = 86; | ||
272 | recovery_time = d.cycle_time - 102; | ||
273 | } else | ||
274 | printk(KERN_WARNING "%s: Strange recovery time !\n",drive->name); | ||
275 | break; | ||
276 | case 4: | ||
277 | if (d.cycle_time >= 69) { | ||
278 | active_time = 70; | ||
279 | recovery_time = d.cycle_time - 61; | ||
280 | } else | ||
281 | printk(KERN_WARNING "%s: Strange recovery time !\n",drive->name); | ||
282 | break; | ||
283 | default: | ||
284 | if (d.cycle_time >= 180) { | ||
285 | active_time = 110; | ||
286 | recovery_time = d.cycle_time - 120; | ||
287 | } else { | ||
288 | active_time = ide_pio_timings[pio].active_time; | ||
289 | recovery_time = d.cycle_time | ||
290 | -active_time; | ||
291 | } | ||
292 | } | ||
293 | printk(KERN_INFO "%s: PIO mode%d\n", drive->name,pio); | ||
294 | } | ||
295 | |||
296 | if (!HWIF(drive)->channel && drive->media != ide_disk) { | ||
297 | qd_write_reg(0x5f, QD_CONTROL_PORT); | ||
298 | printk(KERN_WARNING "%s: ATAPI: disabled read-ahead FIFO " | ||
299 | "and post-write buffer on %s.\n", | ||
300 | drive->name, HWIF(drive)->name); | ||
301 | } | ||
302 | |||
303 | qd_set_timing(drive, qd6580_compute_timing(active_time, recovery_time)); | ||
304 | } | ||
305 | |||
306 | /* | ||
307 | * qd_testreg | ||
308 | * | ||
309 | * tests if the given port is a register | ||
310 | */ | ||
311 | |||
312 | static int __init qd_testreg(int port) | ||
313 | { | ||
314 | u8 savereg; | ||
315 | u8 readreg; | ||
316 | unsigned long flags; | ||
317 | |||
318 | spin_lock_irqsave(&ide_lock, flags); | ||
319 | savereg = inb_p(port); | ||
320 | outb_p(QD_TESTVAL, port); /* safe value */ | ||
321 | readreg = inb_p(port); | ||
322 | outb(savereg, port); | ||
323 | spin_unlock_irqrestore(&ide_lock, flags); | ||
324 | |||
325 | if (savereg == QD_TESTVAL) { | ||
326 | printk(KERN_ERR "Outch ! the probe for qd65xx isn't reliable !\n"); | ||
327 | printk(KERN_ERR "Please contact maintainers to tell about your hardware\n"); | ||
328 | printk(KERN_ERR "Assuming qd65xx is not present.\n"); | ||
329 | return 1; | ||
330 | } | ||
331 | |||
332 | return (readreg != QD_TESTVAL); | ||
333 | } | ||
334 | |||
335 | /* | ||
336 | * qd_setup: | ||
337 | * | ||
338 | * called to setup an ata channel : adjusts attributes & links for tuning | ||
339 | */ | ||
340 | |||
341 | static void __init qd_setup(ide_hwif_t *hwif, int base, int config, | ||
342 | unsigned int data0, unsigned int data1, | ||
343 | void (*tuneproc) (ide_drive_t *, u8 pio)) | ||
344 | { | ||
345 | hwif->chipset = ide_qd65xx; | ||
346 | hwif->channel = hwif->index; | ||
347 | hwif->select_data = base; | ||
348 | hwif->config_data = config; | ||
349 | hwif->drives[0].drive_data = data0; | ||
350 | hwif->drives[1].drive_data = data1; | ||
351 | hwif->drives[0].io_32bit = | ||
352 | hwif->drives[1].io_32bit = 1; | ||
353 | hwif->tuneproc = tuneproc; | ||
354 | probe_hwif_init(hwif); | ||
355 | } | ||
356 | |||
357 | /* | ||
358 | * qd_unsetup: | ||
359 | * | ||
360 | * called to unsetup an ata channel : back to default values, unlinks tuning | ||
361 | */ | ||
362 | /* | ||
363 | static void __exit qd_unsetup(ide_hwif_t *hwif) | ||
364 | { | ||
365 | u8 config = hwif->config_data; | ||
366 | int base = hwif->select_data; | ||
367 | void *tuneproc = (void *) hwif->tuneproc; | ||
368 | |||
369 | if (hwif->chipset != ide_qd65xx) | ||
370 | return; | ||
371 | |||
372 | printk(KERN_NOTICE "%s: back to defaults\n", hwif->name); | ||
373 | |||
374 | hwif->selectproc = NULL; | ||
375 | hwif->tuneproc = NULL; | ||
376 | |||
377 | if (tuneproc == (void *) qd6500_tune_drive) { | ||
378 | // will do it for both | ||
379 | qd_write_reg(QD6500_DEF_DATA, QD_TIMREG(&hwif->drives[0])); | ||
380 | } else if (tuneproc == (void *) qd6580_tune_drive) { | ||
381 | if (QD_CONTROL(hwif) & QD_CONTR_SEC_DISABLED) { | ||
382 | qd_write_reg(QD6580_DEF_DATA, QD_TIMREG(&hwif->drives[0])); | ||
383 | qd_write_reg(QD6580_DEF_DATA2, QD_TIMREG(&hwif->drives[1])); | ||
384 | } else { | ||
385 | qd_write_reg(hwif->channel ? QD6580_DEF_DATA2 : QD6580_DEF_DATA, QD_TIMREG(&hwif->drives[0])); | ||
386 | } | ||
387 | } else { | ||
388 | printk(KERN_WARNING "Unknown qd65xx tuning fonction !\n"); | ||
389 | printk(KERN_WARNING "keeping settings !\n"); | ||
390 | } | ||
391 | } | ||
392 | */ | ||
393 | |||
394 | /* | ||
395 | * qd_probe: | ||
396 | * | ||
397 | * looks at the specified baseport, and if qd found, registers & initialises it | ||
398 | * return 1 if another qd may be probed | ||
399 | */ | ||
400 | |||
401 | static int __init qd_probe(int base) | ||
402 | { | ||
403 | ide_hwif_t *hwif; | ||
404 | u8 config; | ||
405 | u8 unit; | ||
406 | |||
407 | config = qd_read_reg(QD_CONFIG_PORT); | ||
408 | |||
409 | if (! ((config & QD_CONFIG_BASEPORT) >> 1 == (base == 0xb0)) ) | ||
410 | return 1; | ||
411 | |||
412 | unit = ! (config & QD_CONFIG_IDE_BASEPORT); | ||
413 | |||
414 | if ((config & 0xf0) == QD_CONFIG_QD6500) { | ||
415 | |||
416 | if (qd_testreg(base)) return 1; /* bad register */ | ||
417 | |||
418 | /* qd6500 found */ | ||
419 | |||
420 | hwif = &ide_hwifs[unit]; | ||
421 | printk(KERN_NOTICE "%s: qd6500 at %#x\n", hwif->name, base); | ||
422 | printk(KERN_DEBUG "qd6500: config=%#x, ID3=%u\n", | ||
423 | config, QD_ID3); | ||
424 | |||
425 | if (config & QD_CONFIG_DISABLED) { | ||
426 | printk(KERN_WARNING "qd6500 is disabled !\n"); | ||
427 | return 1; | ||
428 | } | ||
429 | |||
430 | qd_setup(hwif, base, config, QD6500_DEF_DATA, QD6500_DEF_DATA, | ||
431 | &qd6500_tune_drive); | ||
432 | |||
433 | create_proc_ide_interfaces(); | ||
434 | |||
435 | return 1; | ||
436 | } | ||
437 | |||
438 | if (((config & 0xf0) == QD_CONFIG_QD6580_A) || | ||
439 | ((config & 0xf0) == QD_CONFIG_QD6580_B)) { | ||
440 | |||
441 | u8 control; | ||
442 | |||
443 | if (qd_testreg(base) || qd_testreg(base+0x02)) return 1; | ||
444 | /* bad registers */ | ||
445 | |||
446 | /* qd6580 found */ | ||
447 | |||
448 | control = qd_read_reg(QD_CONTROL_PORT); | ||
449 | |||
450 | printk(KERN_NOTICE "qd6580 at %#x\n", base); | ||
451 | printk(KERN_DEBUG "qd6580: config=%#x, control=%#x, ID3=%u\n", | ||
452 | config, control, QD_ID3); | ||
453 | |||
454 | if (control & QD_CONTR_SEC_DISABLED) { | ||
455 | /* secondary disabled */ | ||
456 | |||
457 | hwif = &ide_hwifs[unit]; | ||
458 | printk(KERN_INFO "%s: qd6580: single IDE board\n", | ||
459 | hwif->name); | ||
460 | qd_setup(hwif, base, config | (control << 8), | ||
461 | QD6580_DEF_DATA, QD6580_DEF_DATA2, | ||
462 | &qd6580_tune_drive); | ||
463 | qd_write_reg(QD_DEF_CONTR,QD_CONTROL_PORT); | ||
464 | |||
465 | create_proc_ide_interfaces(); | ||
466 | |||
467 | return 1; | ||
468 | } else { | ||
469 | ide_hwif_t *mate; | ||
470 | |||
471 | hwif = &ide_hwifs[0]; | ||
472 | mate = &ide_hwifs[1]; | ||
473 | /* secondary enabled */ | ||
474 | printk(KERN_INFO "%s&%s: qd6580: dual IDE board\n", | ||
475 | hwif->name, mate->name); | ||
476 | |||
477 | qd_setup(hwif, base, config | (control << 8), | ||
478 | QD6580_DEF_DATA, QD6580_DEF_DATA, | ||
479 | &qd6580_tune_drive); | ||
480 | qd_setup(mate, base, config | (control << 8), | ||
481 | QD6580_DEF_DATA2, QD6580_DEF_DATA2, | ||
482 | &qd6580_tune_drive); | ||
483 | qd_write_reg(QD_DEF_CONTR,QD_CONTROL_PORT); | ||
484 | |||
485 | create_proc_ide_interfaces(); | ||
486 | |||
487 | return 0; /* no other qd65xx possible */ | ||
488 | } | ||
489 | } | ||
490 | /* no qd65xx found */ | ||
491 | return 1; | ||
492 | } | ||
493 | |||
494 | /* Can be called directly from ide.c. */ | ||
495 | int __init qd65xx_init(void) | ||
496 | { | ||
497 | if (qd_probe(0x30)) | ||
498 | qd_probe(0xb0); | ||
499 | if (ide_hwifs[0].chipset != ide_qd65xx && | ||
500 | ide_hwifs[1].chipset != ide_qd65xx) | ||
501 | return -ENODEV; | ||
502 | return 0; | ||
503 | } | ||
504 | |||
505 | #ifdef MODULE | ||
506 | module_init(qd65xx_init); | ||
507 | #endif | ||
508 | |||
509 | MODULE_AUTHOR("Samuel Thibault"); | ||
510 | MODULE_DESCRIPTION("support of qd65xx vlb ide chipset"); | ||
511 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/ide/legacy/qd65xx.h b/drivers/ide/legacy/qd65xx.h new file mode 100644 index 000000000000..633a42456ef6 --- /dev/null +++ b/drivers/ide/legacy/qd65xx.h | |||
@@ -0,0 +1,140 @@ | |||
1 | /* | ||
2 | * linux/drivers/ide/legacy/qd65xx.h | ||
3 | * | ||
4 | * Copyright (c) 2000 Linus Torvalds & authors | ||
5 | */ | ||
6 | |||
7 | /* | ||
8 | * Authors: Petr Soucek <petr@ryston.cz> | ||
9 | * Samuel Thibault <samuel.thibault@fnac.net> | ||
10 | */ | ||
11 | |||
12 | /* truncates a in [b,c] */ | ||
13 | #define IDE_IN(a,b,c) ( ((a)<(b)) ? (b) : ( (a)>(c) ? (c) : (a)) ) | ||
14 | |||
15 | #define IDE_IMPLY(a,b) ((!(a)) || (b)) | ||
16 | |||
17 | #define QD_TIM1_PORT (base) | ||
18 | #define QD_CONFIG_PORT (base+0x01) | ||
19 | #define QD_TIM2_PORT (base+0x02) | ||
20 | #define QD_CONTROL_PORT (base+0x03) | ||
21 | |||
22 | #define QD_CONFIG_IDE_BASEPORT 0x01 | ||
23 | #define QD_CONFIG_BASEPORT 0x02 | ||
24 | #define QD_CONFIG_ID3 0x04 | ||
25 | #define QD_CONFIG_DISABLED 0x08 | ||
26 | #define QD_CONFIG_QD6500 0xc0 | ||
27 | #define QD_CONFIG_QD6580_A 0xa0 | ||
28 | #define QD_CONFIG_QD6580_B 0x50 | ||
29 | |||
30 | #define QD_CONTR_SEC_DISABLED 0x01 | ||
31 | |||
32 | #define QD_ID3 ((config & QD_CONFIG_ID3)!=0) | ||
33 | |||
34 | #define QD_CONFIG(hwif) ((hwif)->config_data & 0x00ff) | ||
35 | #define QD_CONTROL(hwif) (((hwif)->config_data & 0xff00) >> 8) | ||
36 | |||
37 | #define QD_TIMING(drive) (byte)(((drive)->drive_data) & 0x00ff) | ||
38 | #define QD_TIMREG(drive) (byte)((((drive)->drive_data) & 0xff00) >> 8) | ||
39 | |||
40 | #define QD6500_DEF_DATA ((QD_TIM1_PORT<<8) | (QD_ID3 ? 0x0c : 0x08)) | ||
41 | #define QD6580_DEF_DATA ((QD_TIM1_PORT<<8) | (QD_ID3 ? 0x0a : 0x00)) | ||
42 | #define QD6580_DEF_DATA2 ((QD_TIM2_PORT<<8) | (QD_ID3 ? 0x0a : 0x00)) | ||
43 | #define QD_DEF_CONTR (0x40 | ((control & 0x02) ? 0x9f : 0x1f)) | ||
44 | |||
45 | #define QD_TESTVAL 0x19 /* safe value */ | ||
46 | |||
47 | /* Drive specific timing taken from DOS driver v3.7 */ | ||
48 | |||
49 | static struct qd65xx_timing_s { | ||
50 | s8 offset; /* ofset from the beginning of Model Number" */ | ||
51 | char model[4]; /* 4 chars from Model number, no conversion */ | ||
52 | s16 active; /* active time */ | ||
53 | s16 recovery; /* recovery time */ | ||
54 | } qd65xx_timing [] = { | ||
55 | { 30, "2040", 110, 225 }, /* Conner CP30204 */ | ||
56 | { 30, "2045", 135, 225 }, /* Conner CP30254 */ | ||
57 | { 30, "1040", 155, 325 }, /* Conner CP30104 */ | ||
58 | { 30, "1047", 135, 265 }, /* Conner CP30174 */ | ||
59 | { 30, "5344", 135, 225 }, /* Conner CP3544 */ | ||
60 | { 30, "01 4", 175, 405 }, /* Conner CP-3104 */ | ||
61 | { 27, "C030", 175, 375 }, /* Conner CP3000 */ | ||
62 | { 8, "PL42", 110, 295 }, /* Quantum LP240 */ | ||
63 | { 8, "PL21", 110, 315 }, /* Quantum LP120 */ | ||
64 | { 8, "PL25", 175, 385 }, /* Quantum LP52 */ | ||
65 | { 4, "PA24", 110, 285 }, /* WD Piranha SP4200 */ | ||
66 | { 6, "2200", 110, 260 }, /* WD Caviar AC2200 */ | ||
67 | { 6, "3204", 110, 235 }, /* WD Caviar AC2340 */ | ||
68 | { 6, "1202", 110, 265 }, /* WD Caviar AC2120 */ | ||
69 | { 0, "DS3-", 135, 315 }, /* Teac SD340 */ | ||
70 | { 8, "KM32", 175, 355 }, /* Toshiba MK234 */ | ||
71 | { 2, "53A1", 175, 355 }, /* Seagate ST351A */ | ||
72 | { 2, "4108", 175, 295 }, /* Seagate ST1480A */ | ||
73 | { 2, "1344", 175, 335 }, /* Seagate ST3144A */ | ||
74 | { 6, "7 12", 110, 225 }, /* Maxtor 7213A */ | ||
75 | { 30, "02F4", 145, 295 }, /* Conner 3204F */ | ||
76 | { 2, "1302", 175, 335 }, /* Seagate ST3120A */ | ||
77 | { 2, "2334", 145, 265 }, /* Seagate ST3243A */ | ||
78 | { 2, "2338", 145, 275 }, /* Seagate ST3283A */ | ||
79 | { 2, "3309", 145, 275 }, /* Seagate ST3390A */ | ||
80 | { 2, "5305", 145, 275 }, /* Seagate ST3550A */ | ||
81 | { 2, "4100", 175, 295 }, /* Seagate ST1400A */ | ||
82 | { 2, "4110", 175, 295 }, /* Seagate ST1401A */ | ||
83 | { 2, "6300", 135, 265 }, /* Seagate ST3600A */ | ||
84 | { 2, "5300", 135, 265 }, /* Seagate ST3500A */ | ||
85 | { 6, "7 31", 135, 225 }, /* Maxtor 7131 AT */ | ||
86 | { 6, "7 43", 115, 265 }, /* Maxtor 7345 AT */ | ||
87 | { 6, "7 42", 110, 255 }, /* Maxtor 7245 AT */ | ||
88 | { 6, "3 04", 135, 265 }, /* Maxtor 340 AT */ | ||
89 | { 6, "61 0", 135, 285 }, /* WD AC160 */ | ||
90 | { 6, "1107", 135, 235 }, /* WD AC1170 */ | ||
91 | { 6, "2101", 110, 220 }, /* WD AC1210 */ | ||
92 | { 6, "4202", 135, 245 }, /* WD AC2420 */ | ||
93 | { 6, "41 0", 175, 355 }, /* WD Caviar 140 */ | ||
94 | { 6, "82 0", 175, 355 }, /* WD Caviar 280 */ | ||
95 | { 8, "PL01", 175, 375 }, /* Quantum LP105 */ | ||
96 | { 8, "PL25", 110, 295 }, /* Quantum LP525 */ | ||
97 | { 10, "4S 2", 175, 385 }, /* Quantum ELS42 */ | ||
98 | { 10, "8S 5", 175, 385 }, /* Quantum ELS85 */ | ||
99 | { 10, "1S72", 175, 385 }, /* Quantum ELS127 */ | ||
100 | { 10, "1S07", 175, 385 }, /* Quantum ELS170 */ | ||
101 | { 8, "ZE42", 135, 295 }, /* Quantum EZ240 */ | ||
102 | { 8, "ZE21", 175, 385 }, /* Quantum EZ127 */ | ||
103 | { 8, "ZE58", 175, 385 }, /* Quantum EZ85 */ | ||
104 | { 8, "ZE24", 175, 385 }, /* Quantum EZ42 */ | ||
105 | { 27, "C036", 155, 325 }, /* Conner CP30064 */ | ||
106 | { 27, "C038", 155, 325 }, /* Conner CP30084 */ | ||
107 | { 6, "2205", 110, 255 }, /* WDC AC2250 */ | ||
108 | { 2, " CHA", 140, 415 }, /* WDC AH series; WDC AH260, WDC */ | ||
109 | { 2, " CLA", 140, 415 }, /* WDC AL series: WDC AL2120, 2170, */ | ||
110 | { 4, "UC41", 140, 415 }, /* WDC CU140 */ | ||
111 | { 6, "1207", 130, 275 }, /* WDC AC2170 */ | ||
112 | { 6, "2107", 130, 275 }, /* WDC AC1270 */ | ||
113 | { 6, "5204", 130, 275 }, /* WDC AC2540 */ | ||
114 | { 30, "3004", 110, 235 }, /* Conner CP30340 */ | ||
115 | { 30, "0345", 135, 255 }, /* Conner CP30544 */ | ||
116 | { 12, "12A3", 175, 320 }, /* MAXTOR LXT-213A */ | ||
117 | { 12, "43A0", 145, 240 }, /* MAXTOR LXT-340A */ | ||
118 | { 6, "7 21", 180, 290 }, /* Maxtor 7120 AT */ | ||
119 | { 6, "7 71", 135, 240 }, /* Maxtor 7170 AT */ | ||
120 | { 12, "45\0000", 110, 205 }, /* MAXTOR MXT-540 */ | ||
121 | { 8, "PL11", 180, 290 }, /* QUANTUM LP110A */ | ||
122 | { 8, "OG21", 150, 275 }, /* QUANTUM GO120 */ | ||
123 | { 12, "42A5", 175, 320 }, /* MAXTOR LXT-245A */ | ||
124 | { 2, "2309", 175, 295 }, /* ST3290A */ | ||
125 | { 2, "3358", 180, 310 }, /* ST3385A */ | ||
126 | { 2, "6355", 180, 310 }, /* ST3655A */ | ||
127 | { 2, "1900", 175, 270 }, /* ST9100A */ | ||
128 | { 2, "1954", 175, 270 }, /* ST9145A */ | ||
129 | { 2, "1909", 175, 270 }, /* ST9190AG */ | ||
130 | { 2, "2953", 175, 270 }, /* ST9235A */ | ||
131 | { 2, "1359", 175, 270 }, /* ST3195A */ | ||
132 | { 24, "3R11", 175, 290 }, /* ALPS ELECTRIC Co.,LTD, DR311C */ | ||
133 | { 0, "2M26", 175, 215 }, /* M262XT-0Ah */ | ||
134 | { 4, "2253", 175, 300 }, /* HP C2235A */ | ||
135 | { 4, "-32A", 145, 245 }, /* H3133-A2 */ | ||
136 | { 30, "0326", 150, 270 }, /* Samsung Electronics 120MB */ | ||
137 | { 30, "3044", 110, 195 }, /* Conner CFA340A */ | ||
138 | { 30, "43A0", 110, 195 }, /* Conner CFA340A */ | ||
139 | { -1, " ", 175, 415 } /* unknown disk name */ | ||
140 | }; | ||
diff --git a/drivers/ide/legacy/umc8672.c b/drivers/ide/legacy/umc8672.c new file mode 100644 index 000000000000..cdbdb2ff9f15 --- /dev/null +++ b/drivers/ide/legacy/umc8672.c | |||
@@ -0,0 +1,183 @@ | |||
1 | /* | ||
2 | * linux/drivers/ide/legacy/umc8672.c Version 0.05 Jul 31, 1996 | ||
3 | * | ||
4 | * Copyright (C) 1995-1996 Linus Torvalds & author (see below) | ||
5 | */ | ||
6 | |||
7 | /* | ||
8 | * Principal Author/Maintainer: PODIEN@hml2.atlas.de (Wolfram Podien) | ||
9 | * | ||
10 | * This file provides support for the advanced features | ||
11 | * of the UMC 8672 IDE interface. | ||
12 | * | ||
13 | * Version 0.01 Initial version, hacked out of ide.c, | ||
14 | * and #include'd rather than compiled separately. | ||
15 | * This will get cleaned up in a subsequent release. | ||
16 | * | ||
17 | * Version 0.02 now configs/compiles separate from ide.c -ml | ||
18 | * Version 0.03 enhanced auto-tune, fix display bug | ||
19 | * Version 0.05 replace sti() with restore_flags() -ml | ||
20 | * add detection of possible race condition -ml | ||
21 | */ | ||
22 | |||
23 | /* | ||
24 | * VLB Controller Support from | ||
25 | * Wolfram Podien | ||
26 | * Rohoefe 3 | ||
27 | * D28832 Achim | ||
28 | * Germany | ||
29 | * | ||
30 | * To enable UMC8672 support there must a lilo line like | ||
31 | * append="ide0=umc8672"... | ||
32 | * To set the speed according to the abilities of the hardware there must be a | ||
33 | * line like | ||
34 | * #define UMC_DRIVE0 11 | ||
35 | * in the beginning of the driver, which sets the speed of drive 0 to 11 (there | ||
36 | * are some lines present). 0 - 11 are allowed speed values. These values are | ||
37 | * the results from the DOS speed test program supplied from UMC. 11 is the | ||
38 | * highest speed (about PIO mode 3) | ||
39 | */ | ||
40 | #define REALLY_SLOW_IO /* some systems can safely undef this */ | ||
41 | |||
42 | #include <linux/module.h> | ||
43 | #include <linux/config.h> | ||
44 | #include <linux/types.h> | ||
45 | #include <linux/kernel.h> | ||
46 | #include <linux/delay.h> | ||
47 | #include <linux/timer.h> | ||
48 | #include <linux/mm.h> | ||
49 | #include <linux/ioport.h> | ||
50 | #include <linux/blkdev.h> | ||
51 | #include <linux/hdreg.h> | ||
52 | #include <linux/ide.h> | ||
53 | #include <linux/init.h> | ||
54 | |||
55 | #include <asm/io.h> | ||
56 | |||
57 | /* | ||
58 | * Default speeds. These can be changed with "auto-tune" and/or hdparm. | ||
59 | */ | ||
60 | #define UMC_DRIVE0 1 /* DOS measured drive speeds */ | ||
61 | #define UMC_DRIVE1 1 /* 0 to 11 allowed */ | ||
62 | #define UMC_DRIVE2 1 /* 11 = Fastest Speed */ | ||
63 | #define UMC_DRIVE3 1 /* In case of crash reduce speed */ | ||
64 | |||
65 | static u8 current_speeds[4] = {UMC_DRIVE0, UMC_DRIVE1, UMC_DRIVE2, UMC_DRIVE3}; | ||
66 | static const u8 pio_to_umc [5] = {0,3,7,10,11}; /* rough guesses */ | ||
67 | |||
68 | /* 0 1 2 3 4 5 6 7 8 9 10 11 */ | ||
69 | static const u8 speedtab [3][12] = { | ||
70 | {0xf, 0xb, 0x2, 0x2, 0x2, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1 }, | ||
71 | {0x3, 0x2, 0x2, 0x2, 0x2, 0x2, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1 }, | ||
72 | {0xff,0xcb,0xc0,0x58,0x36,0x33,0x23,0x22,0x21,0x11,0x10,0x0}}; | ||
73 | |||
74 | static void out_umc (char port,char wert) | ||
75 | { | ||
76 | outb_p(port,0x108); | ||
77 | outb_p(wert,0x109); | ||
78 | } | ||
79 | |||
80 | static inline u8 in_umc (char port) | ||
81 | { | ||
82 | outb_p(port,0x108); | ||
83 | return inb_p(0x109); | ||
84 | } | ||
85 | |||
86 | static void umc_set_speeds (u8 speeds[]) | ||
87 | { | ||
88 | int i, tmp; | ||
89 | |||
90 | outb_p(0x5A,0x108); /* enable umc */ | ||
91 | |||
92 | out_umc (0xd7,(speedtab[0][speeds[2]] | (speedtab[0][speeds[3]]<<4))); | ||
93 | out_umc (0xd6,(speedtab[0][speeds[0]] | (speedtab[0][speeds[1]]<<4))); | ||
94 | tmp = 0; | ||
95 | for (i = 3; i >= 0; i--) { | ||
96 | tmp = (tmp << 2) | speedtab[1][speeds[i]]; | ||
97 | } | ||
98 | out_umc (0xdc,tmp); | ||
99 | for (i = 0;i < 4; i++) { | ||
100 | out_umc (0xd0+i,speedtab[2][speeds[i]]); | ||
101 | out_umc (0xd8+i,speedtab[2][speeds[i]]); | ||
102 | } | ||
103 | outb_p(0xa5,0x108); /* disable umc */ | ||
104 | |||
105 | printk ("umc8672: drive speeds [0 to 11]: %d %d %d %d\n", | ||
106 | speeds[0], speeds[1], speeds[2], speeds[3]); | ||
107 | } | ||
108 | |||
109 | static void tune_umc (ide_drive_t *drive, u8 pio) | ||
110 | { | ||
111 | unsigned long flags; | ||
112 | ide_hwgroup_t *hwgroup = ide_hwifs[HWIF(drive)->index^1].hwgroup; | ||
113 | |||
114 | pio = ide_get_best_pio_mode(drive, pio, 4, NULL); | ||
115 | printk("%s: setting umc8672 to PIO mode%d (speed %d)\n", | ||
116 | drive->name, pio, pio_to_umc[pio]); | ||
117 | spin_lock_irqsave(&ide_lock, flags); | ||
118 | if (hwgroup && hwgroup->handler != NULL) { | ||
119 | printk(KERN_ERR "umc8672: other interface is busy: exiting tune_umc()\n"); | ||
120 | } else { | ||
121 | current_speeds[drive->name[2] - 'a'] = pio_to_umc[pio]; | ||
122 | umc_set_speeds (current_speeds); | ||
123 | } | ||
124 | spin_unlock_irqrestore(&ide_lock, flags); | ||
125 | } | ||
126 | |||
127 | static int __init umc8672_probe(void) | ||
128 | { | ||
129 | unsigned long flags; | ||
130 | ide_hwif_t *hwif, *mate; | ||
131 | |||
132 | if (!request_region(0x108, 2, "umc8672")) { | ||
133 | printk(KERN_ERR "umc8672: ports 0x108-0x109 already in use.\n"); | ||
134 | return 1; | ||
135 | } | ||
136 | local_irq_save(flags); | ||
137 | outb_p(0x5A,0x108); /* enable umc */ | ||
138 | if (in_umc (0xd5) != 0xa0) { | ||
139 | local_irq_restore(flags); | ||
140 | printk(KERN_ERR "umc8672: not found\n"); | ||
141 | release_region(0x108, 2); | ||
142 | return 1; | ||
143 | } | ||
144 | outb_p(0xa5,0x108); /* disable umc */ | ||
145 | |||
146 | umc_set_speeds (current_speeds); | ||
147 | local_irq_restore(flags); | ||
148 | |||
149 | hwif = &ide_hwifs[0]; | ||
150 | mate = &ide_hwifs[1]; | ||
151 | |||
152 | hwif->chipset = ide_umc8672; | ||
153 | hwif->tuneproc = &tune_umc; | ||
154 | hwif->mate = mate; | ||
155 | |||
156 | mate->chipset = ide_umc8672; | ||
157 | mate->tuneproc = &tune_umc; | ||
158 | mate->mate = hwif; | ||
159 | mate->channel = 1; | ||
160 | |||
161 | probe_hwif_init(hwif); | ||
162 | probe_hwif_init(mate); | ||
163 | |||
164 | create_proc_ide_interfaces(); | ||
165 | |||
166 | return 0; | ||
167 | } | ||
168 | |||
169 | /* Can be called directly from ide.c. */ | ||
170 | int __init umc8672_init(void) | ||
171 | { | ||
172 | if (umc8672_probe()) | ||
173 | return -ENODEV; | ||
174 | return 0; | ||
175 | } | ||
176 | |||
177 | #ifdef MODULE | ||
178 | module_init(umc8672_init); | ||
179 | #endif | ||
180 | |||
181 | MODULE_AUTHOR("Wolfram Podien"); | ||
182 | MODULE_DESCRIPTION("Support for UMC 8672 IDE chipset"); | ||
183 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/ide/pci/Makefile b/drivers/ide/pci/Makefile new file mode 100644 index 000000000000..55e6e553e497 --- /dev/null +++ b/drivers/ide/pci/Makefile | |||
@@ -0,0 +1,34 @@ | |||
1 | |||
2 | obj-$(CONFIG_BLK_DEV_AEC62XX) += aec62xx.o | ||
3 | obj-$(CONFIG_BLK_DEV_ALI15X3) += alim15x3.o | ||
4 | obj-$(CONFIG_BLK_DEV_AMD74XX) += amd74xx.o | ||
5 | obj-$(CONFIG_BLK_DEV_ATIIXP) += atiixp.o | ||
6 | obj-$(CONFIG_BLK_DEV_CMD64X) += cmd64x.o | ||
7 | obj-$(CONFIG_BLK_DEV_CS5520) += cs5520.o | ||
8 | obj-$(CONFIG_BLK_DEV_CS5530) += cs5530.o | ||
9 | obj-$(CONFIG_BLK_DEV_SC1200) += sc1200.o | ||
10 | obj-$(CONFIG_BLK_DEV_CY82C693) += cy82c693.o | ||
11 | obj-$(CONFIG_BLK_DEV_HPT34X) += hpt34x.o | ||
12 | obj-$(CONFIG_BLK_DEV_HPT366) += hpt366.o | ||
13 | #obj-$(CONFIG_BLK_DEV_HPT37X) += hpt37x.o | ||
14 | obj-$(CONFIG_BLK_DEV_IT8172) += it8172.o | ||
15 | obj-$(CONFIG_BLK_DEV_NS87415) += ns87415.o | ||
16 | obj-$(CONFIG_BLK_DEV_OPTI621) += opti621.o | ||
17 | obj-$(CONFIG_BLK_DEV_PDC202XX_OLD) += pdc202xx_old.o | ||
18 | obj-$(CONFIG_BLK_DEV_PDC202XX_NEW) += pdc202xx_new.o | ||
19 | obj-$(CONFIG_BLK_DEV_PIIX) += piix.o | ||
20 | obj-$(CONFIG_BLK_DEV_RZ1000) += rz1000.o | ||
21 | obj-$(CONFIG_BLK_DEV_SVWKS) += serverworks.o | ||
22 | obj-$(CONFIG_BLK_DEV_SGIIOC4) += sgiioc4.o | ||
23 | obj-$(CONFIG_BLK_DEV_SIIMAGE) += siimage.o | ||
24 | obj-$(CONFIG_BLK_DEV_SIS5513) += sis5513.o | ||
25 | obj-$(CONFIG_BLK_DEV_SL82C105) += sl82c105.o | ||
26 | obj-$(CONFIG_BLK_DEV_SLC90E66) += slc90e66.o | ||
27 | obj-$(CONFIG_BLK_DEV_TRIFLEX) += triflex.o | ||
28 | obj-$(CONFIG_BLK_DEV_TRM290) += trm290.o | ||
29 | obj-$(CONFIG_BLK_DEV_VIA82CXXX) += via82cxxx.o | ||
30 | |||
31 | # Must appear at the end of the block | ||
32 | obj-$(CONFIG_BLK_DEV_GENERIC) += generic.o | ||
33 | |||
34 | EXTRA_CFLAGS := -Idrivers/ide | ||
diff --git a/drivers/ide/pci/aec62xx.c b/drivers/ide/pci/aec62xx.c new file mode 100644 index 000000000000..52cadc005d72 --- /dev/null +++ b/drivers/ide/pci/aec62xx.c | |||
@@ -0,0 +1,485 @@ | |||
1 | /* | ||
2 | * linux/drivers/ide/pci/aec62xx.c Version 0.11 March 27, 2002 | ||
3 | * | ||
4 | * Copyright (C) 1999-2002 Andre Hedrick <andre@linux-ide.org> | ||
5 | * | ||
6 | */ | ||
7 | |||
8 | #include <linux/module.h> | ||
9 | #include <linux/config.h> | ||
10 | #include <linux/types.h> | ||
11 | #include <linux/pci.h> | ||
12 | #include <linux/delay.h> | ||
13 | #include <linux/hdreg.h> | ||
14 | #include <linux/ide.h> | ||
15 | #include <linux/init.h> | ||
16 | |||
17 | #include <asm/io.h> | ||
18 | |||
19 | struct chipset_bus_clock_list_entry { | ||
20 | u8 xfer_speed; | ||
21 | u8 chipset_settings; | ||
22 | u8 ultra_settings; | ||
23 | }; | ||
24 | |||
25 | static struct chipset_bus_clock_list_entry aec6xxx_33_base [] = { | ||
26 | { XFER_UDMA_6, 0x31, 0x07 }, | ||
27 | { XFER_UDMA_5, 0x31, 0x06 }, | ||
28 | { XFER_UDMA_4, 0x31, 0x05 }, | ||
29 | { XFER_UDMA_3, 0x31, 0x04 }, | ||
30 | { XFER_UDMA_2, 0x31, 0x03 }, | ||
31 | { XFER_UDMA_1, 0x31, 0x02 }, | ||
32 | { XFER_UDMA_0, 0x31, 0x01 }, | ||
33 | |||
34 | { XFER_MW_DMA_2, 0x31, 0x00 }, | ||
35 | { XFER_MW_DMA_1, 0x31, 0x00 }, | ||
36 | { XFER_MW_DMA_0, 0x0a, 0x00 }, | ||
37 | { XFER_PIO_4, 0x31, 0x00 }, | ||
38 | { XFER_PIO_3, 0x33, 0x00 }, | ||
39 | { XFER_PIO_2, 0x08, 0x00 }, | ||
40 | { XFER_PIO_1, 0x0a, 0x00 }, | ||
41 | { XFER_PIO_0, 0x00, 0x00 }, | ||
42 | { 0, 0x00, 0x00 } | ||
43 | }; | ||
44 | |||
45 | static struct chipset_bus_clock_list_entry aec6xxx_34_base [] = { | ||
46 | { XFER_UDMA_6, 0x41, 0x06 }, | ||
47 | { XFER_UDMA_5, 0x41, 0x05 }, | ||
48 | { XFER_UDMA_4, 0x41, 0x04 }, | ||
49 | { XFER_UDMA_3, 0x41, 0x03 }, | ||
50 | { XFER_UDMA_2, 0x41, 0x02 }, | ||
51 | { XFER_UDMA_1, 0x41, 0x01 }, | ||
52 | { XFER_UDMA_0, 0x41, 0x01 }, | ||
53 | |||
54 | { XFER_MW_DMA_2, 0x41, 0x00 }, | ||
55 | { XFER_MW_DMA_1, 0x42, 0x00 }, | ||
56 | { XFER_MW_DMA_0, 0x7a, 0x00 }, | ||
57 | { XFER_PIO_4, 0x41, 0x00 }, | ||
58 | { XFER_PIO_3, 0x43, 0x00 }, | ||
59 | { XFER_PIO_2, 0x78, 0x00 }, | ||
60 | { XFER_PIO_1, 0x7a, 0x00 }, | ||
61 | { XFER_PIO_0, 0x70, 0x00 }, | ||
62 | { 0, 0x00, 0x00 } | ||
63 | }; | ||
64 | |||
65 | #define BUSCLOCK(D) \ | ||
66 | ((struct chipset_bus_clock_list_entry *) pci_get_drvdata((D))) | ||
67 | |||
68 | #if 0 | ||
69 | if (dev->device == PCI_DEVICE_ID_ARTOP_ATP850UF) { | ||
70 | (void) pci_read_config_byte(dev, 0x54, &art); | ||
71 | p += sprintf(p, "DMA Mode: %s(%s)", | ||
72 | (c0&0x20)?((art&0x03)?"UDMA":" DMA"):" PIO", | ||
73 | (art&0x02)?"2":(art&0x01)?"1":"0"); | ||
74 | p += sprintf(p, " %s(%s)", | ||
75 | (c0&0x40)?((art&0x0c)?"UDMA":" DMA"):" PIO", | ||
76 | (art&0x08)?"2":(art&0x04)?"1":"0"); | ||
77 | p += sprintf(p, " %s(%s)", | ||
78 | (c1&0x20)?((art&0x30)?"UDMA":" DMA"):" PIO", | ||
79 | (art&0x20)?"2":(art&0x10)?"1":"0"); | ||
80 | p += sprintf(p, " %s(%s)\n", | ||
81 | (c1&0x40)?((art&0xc0)?"UDMA":" DMA"):" PIO", | ||
82 | (art&0x80)?"2":(art&0x40)?"1":"0"); | ||
83 | } else { | ||
84 | #endif | ||
85 | |||
86 | /* | ||
87 | * TO DO: active tuning and correction of cards without a bios. | ||
88 | */ | ||
89 | static u8 pci_bus_clock_list (u8 speed, struct chipset_bus_clock_list_entry * chipset_table) | ||
90 | { | ||
91 | for ( ; chipset_table->xfer_speed ; chipset_table++) | ||
92 | if (chipset_table->xfer_speed == speed) { | ||
93 | return chipset_table->chipset_settings; | ||
94 | } | ||
95 | return chipset_table->chipset_settings; | ||
96 | } | ||
97 | |||
98 | static u8 pci_bus_clock_list_ultra (u8 speed, struct chipset_bus_clock_list_entry * chipset_table) | ||
99 | { | ||
100 | for ( ; chipset_table->xfer_speed ; chipset_table++) | ||
101 | if (chipset_table->xfer_speed == speed) { | ||
102 | return chipset_table->ultra_settings; | ||
103 | } | ||
104 | return chipset_table->ultra_settings; | ||
105 | } | ||
106 | |||
107 | static u8 aec62xx_ratemask (ide_drive_t *drive) | ||
108 | { | ||
109 | ide_hwif_t *hwif = HWIF(drive); | ||
110 | u8 mode; | ||
111 | |||
112 | switch(hwif->pci_dev->device) { | ||
113 | case PCI_DEVICE_ID_ARTOP_ATP865: | ||
114 | case PCI_DEVICE_ID_ARTOP_ATP865R: | ||
115 | #if 0 | ||
116 | mode = (hwif->INB(hwif->dma_master) & 0x10) ? 4 : 3; | ||
117 | #else | ||
118 | mode = (hwif->INB(((hwif->channel) ? | ||
119 | hwif->mate->dma_status : | ||
120 | hwif->dma_status)) & 0x10) ? 4 : 3; | ||
121 | #endif | ||
122 | break; | ||
123 | case PCI_DEVICE_ID_ARTOP_ATP860: | ||
124 | case PCI_DEVICE_ID_ARTOP_ATP860R: | ||
125 | mode = 2; | ||
126 | break; | ||
127 | case PCI_DEVICE_ID_ARTOP_ATP850UF: | ||
128 | default: | ||
129 | return 1; | ||
130 | } | ||
131 | |||
132 | if (!eighty_ninty_three(drive)) | ||
133 | mode = min(mode, (u8)1); | ||
134 | return mode; | ||
135 | } | ||
136 | |||
137 | static int aec6210_tune_chipset (ide_drive_t *drive, u8 xferspeed) | ||
138 | { | ||
139 | ide_hwif_t *hwif = HWIF(drive); | ||
140 | struct pci_dev *dev = hwif->pci_dev; | ||
141 | u16 d_conf = 0; | ||
142 | u8 speed = ide_rate_filter(aec62xx_ratemask(drive), xferspeed); | ||
143 | u8 ultra = 0, ultra_conf = 0; | ||
144 | u8 tmp0 = 0, tmp1 = 0, tmp2 = 0; | ||
145 | unsigned long flags; | ||
146 | |||
147 | local_irq_save(flags); | ||
148 | /* 0x40|(2*drive->dn): Active, 0x41|(2*drive->dn): Recovery */ | ||
149 | pci_read_config_word(dev, 0x40|(2*drive->dn), &d_conf); | ||
150 | tmp0 = pci_bus_clock_list(speed, BUSCLOCK(dev)); | ||
151 | d_conf = ((tmp0 & 0xf0) << 4) | (tmp0 & 0xf); | ||
152 | pci_write_config_word(dev, 0x40|(2*drive->dn), d_conf); | ||
153 | |||
154 | tmp1 = 0x00; | ||
155 | tmp2 = 0x00; | ||
156 | pci_read_config_byte(dev, 0x54, &ultra); | ||
157 | tmp1 = ((0x00 << (2*drive->dn)) | (ultra & ~(3 << (2*drive->dn)))); | ||
158 | ultra_conf = pci_bus_clock_list_ultra(speed, BUSCLOCK(dev)); | ||
159 | tmp2 = ((ultra_conf << (2*drive->dn)) | (tmp1 & ~(3 << (2*drive->dn)))); | ||
160 | pci_write_config_byte(dev, 0x54, tmp2); | ||
161 | local_irq_restore(flags); | ||
162 | return(ide_config_drive_speed(drive, speed)); | ||
163 | } | ||
164 | |||
165 | static int aec6260_tune_chipset (ide_drive_t *drive, u8 xferspeed) | ||
166 | { | ||
167 | ide_hwif_t *hwif = HWIF(drive); | ||
168 | struct pci_dev *dev = hwif->pci_dev; | ||
169 | u8 speed = ide_rate_filter(aec62xx_ratemask(drive), xferspeed); | ||
170 | u8 unit = (drive->select.b.unit & 0x01); | ||
171 | u8 tmp1 = 0, tmp2 = 0; | ||
172 | u8 ultra = 0, drive_conf = 0, ultra_conf = 0; | ||
173 | unsigned long flags; | ||
174 | |||
175 | local_irq_save(flags); | ||
176 | /* high 4-bits: Active, low 4-bits: Recovery */ | ||
177 | pci_read_config_byte(dev, 0x40|drive->dn, &drive_conf); | ||
178 | drive_conf = pci_bus_clock_list(speed, BUSCLOCK(dev)); | ||
179 | pci_write_config_byte(dev, 0x40|drive->dn, drive_conf); | ||
180 | |||
181 | pci_read_config_byte(dev, (0x44|hwif->channel), &ultra); | ||
182 | tmp1 = ((0x00 << (4*unit)) | (ultra & ~(7 << (4*unit)))); | ||
183 | ultra_conf = pci_bus_clock_list_ultra(speed, BUSCLOCK(dev)); | ||
184 | tmp2 = ((ultra_conf << (4*unit)) | (tmp1 & ~(7 << (4*unit)))); | ||
185 | pci_write_config_byte(dev, (0x44|hwif->channel), tmp2); | ||
186 | local_irq_restore(flags); | ||
187 | return(ide_config_drive_speed(drive, speed)); | ||
188 | } | ||
189 | |||
190 | static int aec62xx_tune_chipset (ide_drive_t *drive, u8 speed) | ||
191 | { | ||
192 | switch (HWIF(drive)->pci_dev->device) { | ||
193 | case PCI_DEVICE_ID_ARTOP_ATP865: | ||
194 | case PCI_DEVICE_ID_ARTOP_ATP865R: | ||
195 | case PCI_DEVICE_ID_ARTOP_ATP860: | ||
196 | case PCI_DEVICE_ID_ARTOP_ATP860R: | ||
197 | return ((int) aec6260_tune_chipset(drive, speed)); | ||
198 | case PCI_DEVICE_ID_ARTOP_ATP850UF: | ||
199 | return ((int) aec6210_tune_chipset(drive, speed)); | ||
200 | default: | ||
201 | return -1; | ||
202 | } | ||
203 | } | ||
204 | |||
205 | static int config_chipset_for_dma (ide_drive_t *drive) | ||
206 | { | ||
207 | u8 speed = ide_dma_speed(drive, aec62xx_ratemask(drive)); | ||
208 | |||
209 | if (!(speed)) | ||
210 | return 0; | ||
211 | |||
212 | (void) aec62xx_tune_chipset(drive, speed); | ||
213 | return ide_dma_enable(drive); | ||
214 | } | ||
215 | |||
216 | static void aec62xx_tune_drive (ide_drive_t *drive, u8 pio) | ||
217 | { | ||
218 | u8 speed = 0; | ||
219 | u8 new_pio = XFER_PIO_0 + ide_get_best_pio_mode(drive, 255, 5, NULL); | ||
220 | |||
221 | switch(pio) { | ||
222 | case 5: speed = new_pio; break; | ||
223 | case 4: speed = XFER_PIO_4; break; | ||
224 | case 3: speed = XFER_PIO_3; break; | ||
225 | case 2: speed = XFER_PIO_2; break; | ||
226 | case 1: speed = XFER_PIO_1; break; | ||
227 | default: speed = XFER_PIO_0; break; | ||
228 | } | ||
229 | (void) aec62xx_tune_chipset(drive, speed); | ||
230 | } | ||
231 | |||
232 | static int aec62xx_config_drive_xfer_rate (ide_drive_t *drive) | ||
233 | { | ||
234 | ide_hwif_t *hwif = HWIF(drive); | ||
235 | struct hd_driveid *id = drive->id; | ||
236 | |||
237 | if ((id->capability & 1) && drive->autodma) { | ||
238 | |||
239 | if (ide_use_dma(drive)) { | ||
240 | if (config_chipset_for_dma(drive)) | ||
241 | return hwif->ide_dma_on(drive); | ||
242 | } | ||
243 | |||
244 | goto fast_ata_pio; | ||
245 | |||
246 | } else if ((id->capability & 8) || (id->field_valid & 2)) { | ||
247 | fast_ata_pio: | ||
248 | aec62xx_tune_drive(drive, 5); | ||
249 | return hwif->ide_dma_off_quietly(drive); | ||
250 | } | ||
251 | /* IORDY not supported */ | ||
252 | return 0; | ||
253 | } | ||
254 | |||
255 | static int aec62xx_irq_timeout (ide_drive_t *drive) | ||
256 | { | ||
257 | ide_hwif_t *hwif = HWIF(drive); | ||
258 | struct pci_dev *dev = hwif->pci_dev; | ||
259 | |||
260 | switch(dev->device) { | ||
261 | case PCI_DEVICE_ID_ARTOP_ATP860: | ||
262 | case PCI_DEVICE_ID_ARTOP_ATP860R: | ||
263 | case PCI_DEVICE_ID_ARTOP_ATP865: | ||
264 | case PCI_DEVICE_ID_ARTOP_ATP865R: | ||
265 | printk(" AEC62XX time out "); | ||
266 | #if 0 | ||
267 | { | ||
268 | int i = 0; | ||
269 | u8 reg49h = 0; | ||
270 | pci_read_config_byte(HWIF(drive)->pci_dev, 0x49, ®49h); | ||
271 | for (i=0;i<256;i++) | ||
272 | pci_write_config_byte(HWIF(drive)->pci_dev, 0x49, reg49h|0x10); | ||
273 | pci_write_config_byte(HWIF(drive)->pci_dev, 0x49, reg49h & ~0x10); | ||
274 | } | ||
275 | return 0; | ||
276 | #endif | ||
277 | default: | ||
278 | break; | ||
279 | } | ||
280 | #if 0 | ||
281 | { | ||
282 | ide_hwif_t *hwif = HWIF(drive); | ||
283 | struct pci_dev *dev = hwif->pci_dev; | ||
284 | u8 tmp1 = 0, tmp2 = 0, mode6 = 0; | ||
285 | |||
286 | pci_read_config_byte(dev, 0x44, &tmp1); | ||
287 | pci_read_config_byte(dev, 0x45, &tmp2); | ||
288 | printk(" AEC6280 r44=%x r45=%x ",tmp1,tmp2); | ||
289 | mode6 = HWIF(drive)->INB(((hwif->channel) ? | ||
290 | hwif->mate->dma_status : | ||
291 | hwif->dma_status)); | ||
292 | printk(" AEC6280 133=%x ", (mode6 & 0x10)); | ||
293 | } | ||
294 | #endif | ||
295 | return 0; | ||
296 | } | ||
297 | |||
298 | static unsigned int __devinit init_chipset_aec62xx(struct pci_dev *dev, const char *name) | ||
299 | { | ||
300 | int bus_speed = system_bus_clock(); | ||
301 | |||
302 | if (dev->resource[PCI_ROM_RESOURCE].start) { | ||
303 | pci_write_config_dword(dev, PCI_ROM_ADDRESS, dev->resource[PCI_ROM_RESOURCE].start | PCI_ROM_ADDRESS_ENABLE); | ||
304 | printk(KERN_INFO "%s: ROM enabled at 0x%08lx\n", name, dev->resource[PCI_ROM_RESOURCE].start); | ||
305 | } | ||
306 | |||
307 | if (bus_speed <= 33) | ||
308 | pci_set_drvdata(dev, (void *) aec6xxx_33_base); | ||
309 | else | ||
310 | pci_set_drvdata(dev, (void *) aec6xxx_34_base); | ||
311 | |||
312 | return dev->irq; | ||
313 | } | ||
314 | |||
315 | static void __devinit init_hwif_aec62xx(ide_hwif_t *hwif) | ||
316 | { | ||
317 | hwif->autodma = 0; | ||
318 | hwif->tuneproc = &aec62xx_tune_drive; | ||
319 | hwif->speedproc = &aec62xx_tune_chipset; | ||
320 | |||
321 | if (hwif->pci_dev->device == PCI_DEVICE_ID_ARTOP_ATP850UF) { | ||
322 | hwif->serialized = hwif->channel; | ||
323 | hwif->no_dsc = 1; | ||
324 | } | ||
325 | |||
326 | if (hwif->mate) | ||
327 | hwif->mate->serialized = hwif->serialized; | ||
328 | |||
329 | if (!hwif->dma_base) { | ||
330 | hwif->drives[0].autotune = 1; | ||
331 | hwif->drives[1].autotune = 1; | ||
332 | return; | ||
333 | } | ||
334 | |||
335 | hwif->ultra_mask = 0x7f; | ||
336 | hwif->mwdma_mask = 0x07; | ||
337 | hwif->swdma_mask = 0x07; | ||
338 | |||
339 | hwif->ide_dma_check = &aec62xx_config_drive_xfer_rate; | ||
340 | hwif->ide_dma_lostirq = &aec62xx_irq_timeout; | ||
341 | hwif->ide_dma_timeout = &aec62xx_irq_timeout; | ||
342 | if (!noautodma) | ||
343 | hwif->autodma = 1; | ||
344 | hwif->drives[0].autodma = hwif->autodma; | ||
345 | hwif->drives[1].autodma = hwif->autodma; | ||
346 | } | ||
347 | |||
348 | static void __devinit init_dma_aec62xx(ide_hwif_t *hwif, unsigned long dmabase) | ||
349 | { | ||
350 | struct pci_dev *dev = hwif->pci_dev; | ||
351 | |||
352 | if (dev->device == PCI_DEVICE_ID_ARTOP_ATP850UF) { | ||
353 | u8 reg54h = 0; | ||
354 | unsigned long flags; | ||
355 | |||
356 | spin_lock_irqsave(&ide_lock, flags); | ||
357 | pci_read_config_byte(dev, 0x54, ®54h); | ||
358 | pci_write_config_byte(dev, 0x54, reg54h & ~(hwif->channel ? 0xF0 : 0x0F)); | ||
359 | spin_unlock_irqrestore(&ide_lock, flags); | ||
360 | } else { | ||
361 | u8 ata66 = 0; | ||
362 | pci_read_config_byte(hwif->pci_dev, 0x49, &ata66); | ||
363 | if (!(hwif->udma_four)) | ||
364 | hwif->udma_four = (ata66&(hwif->channel?0x02:0x01))?0:1; | ||
365 | } | ||
366 | |||
367 | ide_setup_dma(hwif, dmabase, 8); | ||
368 | } | ||
369 | |||
370 | static int __devinit init_setup_aec62xx(struct pci_dev *dev, ide_pci_device_t *d) | ||
371 | { | ||
372 | return ide_setup_pci_device(dev, d); | ||
373 | } | ||
374 | |||
375 | static int __devinit init_setup_aec6x80(struct pci_dev *dev, ide_pci_device_t *d) | ||
376 | { | ||
377 | unsigned long bar4reg = pci_resource_start(dev, 4); | ||
378 | |||
379 | if (inb(bar4reg+2) & 0x10) { | ||
380 | strcpy(d->name, "AEC6880"); | ||
381 | if (dev->device == PCI_DEVICE_ID_ARTOP_ATP865R) | ||
382 | strcpy(d->name, "AEC6880R"); | ||
383 | } else { | ||
384 | strcpy(d->name, "AEC6280"); | ||
385 | if (dev->device == PCI_DEVICE_ID_ARTOP_ATP865R) | ||
386 | strcpy(d->name, "AEC6280R"); | ||
387 | } | ||
388 | |||
389 | return ide_setup_pci_device(dev, d); | ||
390 | } | ||
391 | |||
392 | static ide_pci_device_t aec62xx_chipsets[] __devinitdata = { | ||
393 | { /* 0 */ | ||
394 | .name = "AEC6210", | ||
395 | .init_setup = init_setup_aec62xx, | ||
396 | .init_chipset = init_chipset_aec62xx, | ||
397 | .init_hwif = init_hwif_aec62xx, | ||
398 | .init_dma = init_dma_aec62xx, | ||
399 | .channels = 2, | ||
400 | .autodma = AUTODMA, | ||
401 | .enablebits = {{0x4a,0x02,0x02}, {0x4a,0x04,0x04}}, | ||
402 | .bootable = OFF_BOARD, | ||
403 | },{ /* 1 */ | ||
404 | .name = "AEC6260", | ||
405 | .init_setup = init_setup_aec62xx, | ||
406 | .init_chipset = init_chipset_aec62xx, | ||
407 | .init_hwif = init_hwif_aec62xx, | ||
408 | .init_dma = init_dma_aec62xx, | ||
409 | .channels = 2, | ||
410 | .autodma = NOAUTODMA, | ||
411 | .bootable = OFF_BOARD, | ||
412 | },{ /* 2 */ | ||
413 | .name = "AEC6260R", | ||
414 | .init_setup = init_setup_aec62xx, | ||
415 | .init_chipset = init_chipset_aec62xx, | ||
416 | .init_hwif = init_hwif_aec62xx, | ||
417 | .init_dma = init_dma_aec62xx, | ||
418 | .channels = 2, | ||
419 | .autodma = AUTODMA, | ||
420 | .enablebits = {{0x4a,0x02,0x02}, {0x4a,0x04,0x04}}, | ||
421 | .bootable = NEVER_BOARD, | ||
422 | },{ /* 3 */ | ||
423 | .name = "AEC6X80", | ||
424 | .init_setup = init_setup_aec6x80, | ||
425 | .init_chipset = init_chipset_aec62xx, | ||
426 | .init_hwif = init_hwif_aec62xx, | ||
427 | .init_dma = init_dma_aec62xx, | ||
428 | .channels = 2, | ||
429 | .autodma = AUTODMA, | ||
430 | .bootable = OFF_BOARD, | ||
431 | },{ /* 4 */ | ||
432 | .name = "AEC6X80R", | ||
433 | .init_setup = init_setup_aec6x80, | ||
434 | .init_chipset = init_chipset_aec62xx, | ||
435 | .init_hwif = init_hwif_aec62xx, | ||
436 | .init_dma = init_dma_aec62xx, | ||
437 | .channels = 2, | ||
438 | .autodma = AUTODMA, | ||
439 | .enablebits = {{0x4a,0x02,0x02}, {0x4a,0x04,0x04}}, | ||
440 | .bootable = OFF_BOARD, | ||
441 | } | ||
442 | }; | ||
443 | |||
444 | /** | ||
445 | * aec62xx_init_one - called when a AEC is found | ||
446 | * @dev: the aec62xx device | ||
447 | * @id: the matching pci id | ||
448 | * | ||
449 | * Called when the PCI registration layer (or the IDE initialization) | ||
450 | * finds a device matching our IDE device tables. | ||
451 | */ | ||
452 | |||
453 | static int __devinit aec62xx_init_one(struct pci_dev *dev, const struct pci_device_id *id) | ||
454 | { | ||
455 | ide_pci_device_t *d = &aec62xx_chipsets[id->driver_data]; | ||
456 | |||
457 | return d->init_setup(dev, d); | ||
458 | } | ||
459 | |||
460 | static struct pci_device_id aec62xx_pci_tbl[] = { | ||
461 | { PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_ATP850UF, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, | ||
462 | { PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_ATP860, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 }, | ||
463 | { PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_ATP860R, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2 }, | ||
464 | { PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_ATP865, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3 }, | ||
465 | { PCI_VENDOR_ID_ARTOP, PCI_DEVICE_ID_ARTOP_ATP865R, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4 }, | ||
466 | { 0, }, | ||
467 | }; | ||
468 | MODULE_DEVICE_TABLE(pci, aec62xx_pci_tbl); | ||
469 | |||
470 | static struct pci_driver driver = { | ||
471 | .name = "AEC62xx_IDE", | ||
472 | .id_table = aec62xx_pci_tbl, | ||
473 | .probe = aec62xx_init_one, | ||
474 | }; | ||
475 | |||
476 | static int aec62xx_ide_init(void) | ||
477 | { | ||
478 | return ide_pci_register_driver(&driver); | ||
479 | } | ||
480 | |||
481 | module_init(aec62xx_ide_init); | ||
482 | |||
483 | MODULE_AUTHOR("Andre Hedrick"); | ||
484 | MODULE_DESCRIPTION("PCI driver module for ARTOP AEC62xx IDE"); | ||
485 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/ide/pci/alim15x3.c b/drivers/ide/pci/alim15x3.c new file mode 100644 index 000000000000..67efb38a9f6c --- /dev/null +++ b/drivers/ide/pci/alim15x3.c | |||
@@ -0,0 +1,913 @@ | |||
1 | /* | ||
2 | * linux/drivers/ide/pci/alim15x3.c Version 0.17 2003/01/02 | ||
3 | * | ||
4 | * Copyright (C) 1998-2000 Michel Aubry, Maintainer | ||
5 | * Copyright (C) 1998-2000 Andrzej Krzysztofowicz, Maintainer | ||
6 | * Copyright (C) 1999-2000 CJ, cjtsai@ali.com.tw, Maintainer | ||
7 | * | ||
8 | * Copyright (C) 1998-2000 Andre Hedrick (andre@linux-ide.org) | ||
9 | * May be copied or modified under the terms of the GNU General Public License | ||
10 | * Copyright (C) 2002 Alan Cox <alan@redhat.com> | ||
11 | * ALi (now ULi M5228) support by Clear Zhang <Clear.Zhang@ali.com.tw> | ||
12 | * | ||
13 | * (U)DMA capable version of ali 1533/1543(C), 1535(D) | ||
14 | * | ||
15 | ********************************************************************** | ||
16 | * 9/7/99 --Parts from the above author are included and need to be | ||
17 | * converted into standard interface, once I finish the thought. | ||
18 | * | ||
19 | * Recent changes | ||
20 | * Don't use LBA48 mode on ALi <= 0xC4 | ||
21 | * Don't poke 0x79 with a non ALi northbridge | ||
22 | * Don't flip undefined bits on newer chipsets (fix Fujitsu laptop hang) | ||
23 | * Allow UDMA6 on revisions > 0xC4 | ||
24 | * | ||
25 | * Documentation | ||
26 | * Chipset documentation available under NDA only | ||
27 | * | ||
28 | */ | ||
29 | |||
30 | #include <linux/config.h> | ||
31 | #include <linux/module.h> | ||
32 | #include <linux/types.h> | ||
33 | #include <linux/kernel.h> | ||
34 | #include <linux/pci.h> | ||
35 | #include <linux/delay.h> | ||
36 | #include <linux/hdreg.h> | ||
37 | #include <linux/ide.h> | ||
38 | #include <linux/init.h> | ||
39 | |||
40 | #include <asm/io.h> | ||
41 | |||
42 | #define DISPLAY_ALI_TIMINGS | ||
43 | |||
44 | /* | ||
45 | * ALi devices are not plug in. Otherwise these static values would | ||
46 | * need to go. They ought to go away anyway | ||
47 | */ | ||
48 | |||
49 | static u8 m5229_revision; | ||
50 | static u8 chip_is_1543c_e; | ||
51 | static struct pci_dev *isa_dev; | ||
52 | |||
53 | #if defined(DISPLAY_ALI_TIMINGS) && defined(CONFIG_PROC_FS) | ||
54 | #include <linux/stat.h> | ||
55 | #include <linux/proc_fs.h> | ||
56 | |||
57 | static u8 ali_proc = 0; | ||
58 | |||
59 | static struct pci_dev *bmide_dev; | ||
60 | |||
61 | static char *fifo[4] = { | ||
62 | "FIFO Off", | ||
63 | "FIFO On ", | ||
64 | "DMA mode", | ||
65 | "PIO mode" }; | ||
66 | |||
67 | static char *udmaT[8] = { | ||
68 | "1.5T", | ||
69 | " 2T", | ||
70 | "2.5T", | ||
71 | " 3T", | ||
72 | "3.5T", | ||
73 | " 4T", | ||
74 | " 6T", | ||
75 | " 8T" | ||
76 | }; | ||
77 | |||
78 | static char *channel_status[8] = { | ||
79 | "OK ", | ||
80 | "busy ", | ||
81 | "DRQ ", | ||
82 | "DRQ busy ", | ||
83 | "error ", | ||
84 | "error busy ", | ||
85 | "error DRQ ", | ||
86 | "error DRQ busy" | ||
87 | }; | ||
88 | |||
89 | /** | ||
90 | * ali_get_info - generate proc file for ALi IDE | ||
91 | * @buffer: buffer to fill | ||
92 | * @addr: address of user start in buffer | ||
93 | * @offset: offset into 'file' | ||
94 | * @count: buffer count | ||
95 | * | ||
96 | * Walks the Ali devices and outputs summary data on the tuning and | ||
97 | * anything else that will help with debugging | ||
98 | */ | ||
99 | |||
100 | static int ali_get_info (char *buffer, char **addr, off_t offset, int count) | ||
101 | { | ||
102 | unsigned long bibma; | ||
103 | u8 reg53h, reg5xh, reg5yh, reg5xh1, reg5yh1, c0, c1, rev, tmp; | ||
104 | char *q, *p = buffer; | ||
105 | |||
106 | /* fetch rev. */ | ||
107 | pci_read_config_byte(bmide_dev, 0x08, &rev); | ||
108 | if (rev >= 0xc1) /* M1543C or newer */ | ||
109 | udmaT[7] = " ???"; | ||
110 | else | ||
111 | fifo[3] = " ??? "; | ||
112 | |||
113 | /* first fetch bibma: */ | ||
114 | |||
115 | bibma = pci_resource_start(bmide_dev, 4); | ||
116 | |||
117 | /* | ||
118 | * at that point bibma+0x2 et bibma+0xa are byte | ||
119 | * registers to investigate: | ||
120 | */ | ||
121 | c0 = inb(bibma + 0x02); | ||
122 | c1 = inb(bibma + 0x0a); | ||
123 | |||
124 | p += sprintf(p, | ||
125 | "\n Ali M15x3 Chipset.\n"); | ||
126 | p += sprintf(p, | ||
127 | " ------------------\n"); | ||
128 | pci_read_config_byte(bmide_dev, 0x78, ®53h); | ||
129 | p += sprintf(p, "PCI Clock: %d.\n", reg53h); | ||
130 | |||
131 | pci_read_config_byte(bmide_dev, 0x53, ®53h); | ||
132 | p += sprintf(p, | ||
133 | "CD_ROM FIFO:%s, CD_ROM DMA:%s\n", | ||
134 | (reg53h & 0x02) ? "Yes" : "No ", | ||
135 | (reg53h & 0x01) ? "Yes" : "No " ); | ||
136 | pci_read_config_byte(bmide_dev, 0x74, ®53h); | ||
137 | p += sprintf(p, | ||
138 | "FIFO Status: contains %d Words, runs%s%s\n\n", | ||
139 | (reg53h & 0x3f), | ||
140 | (reg53h & 0x40) ? " OVERWR" : "", | ||
141 | (reg53h & 0x80) ? " OVERRD." : "." ); | ||
142 | |||
143 | p += sprintf(p, | ||
144 | "-------------------primary channel" | ||
145 | "-------------------secondary channel" | ||
146 | "---------\n\n"); | ||
147 | |||
148 | pci_read_config_byte(bmide_dev, 0x09, ®53h); | ||
149 | p += sprintf(p, | ||
150 | "channel status: %s" | ||
151 | " %s\n", | ||
152 | (reg53h & 0x20) ? "On " : "Off", | ||
153 | (reg53h & 0x10) ? "On " : "Off" ); | ||
154 | |||
155 | p += sprintf(p, | ||
156 | "both channels togth: %s" | ||
157 | " %s\n", | ||
158 | (c0&0x80) ? "No " : "Yes", | ||
159 | (c1&0x80) ? "No " : "Yes" ); | ||
160 | |||
161 | pci_read_config_byte(bmide_dev, 0x76, ®53h); | ||
162 | p += sprintf(p, | ||
163 | "Channel state: %s %s\n", | ||
164 | channel_status[reg53h & 0x07], | ||
165 | channel_status[(reg53h & 0x70) >> 4] ); | ||
166 | |||
167 | pci_read_config_byte(bmide_dev, 0x58, ®5xh); | ||
168 | pci_read_config_byte(bmide_dev, 0x5c, ®5yh); | ||
169 | p += sprintf(p, | ||
170 | "Add. Setup Timing: %dT" | ||
171 | " %dT\n", | ||
172 | (reg5xh & 0x07) ? (reg5xh & 0x07) : 8, | ||
173 | (reg5yh & 0x07) ? (reg5yh & 0x07) : 8 ); | ||
174 | |||
175 | pci_read_config_byte(bmide_dev, 0x59, ®5xh); | ||
176 | pci_read_config_byte(bmide_dev, 0x5d, ®5yh); | ||
177 | p += sprintf(p, | ||
178 | "Command Act. Count: %dT" | ||
179 | " %dT\n" | ||
180 | "Command Rec. Count: %dT" | ||
181 | " %dT\n\n", | ||
182 | (reg5xh & 0x70) ? ((reg5xh & 0x70) >> 4) : 8, | ||
183 | (reg5yh & 0x70) ? ((reg5yh & 0x70) >> 4) : 8, | ||
184 | (reg5xh & 0x0f) ? (reg5xh & 0x0f) : 16, | ||
185 | (reg5yh & 0x0f) ? (reg5yh & 0x0f) : 16 ); | ||
186 | |||
187 | p += sprintf(p, | ||
188 | "----------------drive0-----------drive1" | ||
189 | "------------drive0-----------drive1------\n\n"); | ||
190 | p += sprintf(p, | ||
191 | "DMA enabled: %s %s" | ||
192 | " %s %s\n", | ||
193 | (c0&0x20) ? "Yes" : "No ", | ||
194 | (c0&0x40) ? "Yes" : "No ", | ||
195 | (c1&0x20) ? "Yes" : "No ", | ||
196 | (c1&0x40) ? "Yes" : "No " ); | ||
197 | |||
198 | pci_read_config_byte(bmide_dev, 0x54, ®5xh); | ||
199 | pci_read_config_byte(bmide_dev, 0x55, ®5yh); | ||
200 | q = "FIFO threshold: %2d Words %2d Words" | ||
201 | " %2d Words %2d Words\n"; | ||
202 | if (rev < 0xc1) { | ||
203 | if ((rev == 0x20) && | ||
204 | (pci_read_config_byte(bmide_dev, 0x4f, &tmp), (tmp &= 0x20))) { | ||
205 | p += sprintf(p, q, 8, 8, 8, 8); | ||
206 | } else { | ||
207 | p += sprintf(p, q, | ||
208 | (reg5xh & 0x03) + 12, | ||
209 | ((reg5xh & 0x30)>>4) + 12, | ||
210 | (reg5yh & 0x03) + 12, | ||
211 | ((reg5yh & 0x30)>>4) + 12 ); | ||
212 | } | ||
213 | } else { | ||
214 | int t1 = (tmp = (reg5xh & 0x03)) ? (tmp << 3) : 4; | ||
215 | int t2 = (tmp = ((reg5xh & 0x30)>>4)) ? (tmp << 3) : 4; | ||
216 | int t3 = (tmp = (reg5yh & 0x03)) ? (tmp << 3) : 4; | ||
217 | int t4 = (tmp = ((reg5yh & 0x30)>>4)) ? (tmp << 3) : 4; | ||
218 | p += sprintf(p, q, t1, t2, t3, t4); | ||
219 | } | ||
220 | |||
221 | #if 0 | ||
222 | p += sprintf(p, | ||
223 | "FIFO threshold: %2d Words %2d Words" | ||
224 | " %2d Words %2d Words\n", | ||
225 | (reg5xh & 0x03) + 12, | ||
226 | ((reg5xh & 0x30)>>4) + 12, | ||
227 | (reg5yh & 0x03) + 12, | ||
228 | ((reg5yh & 0x30)>>4) + 12 ); | ||
229 | #endif | ||
230 | |||
231 | p += sprintf(p, | ||
232 | "FIFO mode: %s %s %s %s\n", | ||
233 | fifo[((reg5xh & 0x0c) >> 2)], | ||
234 | fifo[((reg5xh & 0xc0) >> 6)], | ||
235 | fifo[((reg5yh & 0x0c) >> 2)], | ||
236 | fifo[((reg5yh & 0xc0) >> 6)] ); | ||
237 | |||
238 | pci_read_config_byte(bmide_dev, 0x5a, ®5xh); | ||
239 | pci_read_config_byte(bmide_dev, 0x5b, ®5xh1); | ||
240 | pci_read_config_byte(bmide_dev, 0x5e, ®5yh); | ||
241 | pci_read_config_byte(bmide_dev, 0x5f, ®5yh1); | ||
242 | |||
243 | p += sprintf(p,/* | ||
244 | "------------------drive0-----------drive1" | ||
245 | "------------drive0-----------drive1------\n")*/ | ||
246 | "Dt RW act. Cnt %2dT %2dT" | ||
247 | " %2dT %2dT\n" | ||
248 | "Dt RW rec. Cnt %2dT %2dT" | ||
249 | " %2dT %2dT\n\n", | ||
250 | (reg5xh & 0x70) ? ((reg5xh & 0x70) >> 4) : 8, | ||
251 | (reg5xh1 & 0x70) ? ((reg5xh1 & 0x70) >> 4) : 8, | ||
252 | (reg5yh & 0x70) ? ((reg5yh & 0x70) >> 4) : 8, | ||
253 | (reg5yh1 & 0x70) ? ((reg5yh1 & 0x70) >> 4) : 8, | ||
254 | (reg5xh & 0x0f) ? (reg5xh & 0x0f) : 16, | ||
255 | (reg5xh1 & 0x0f) ? (reg5xh1 & 0x0f) : 16, | ||
256 | (reg5yh & 0x0f) ? (reg5yh & 0x0f) : 16, | ||
257 | (reg5yh1 & 0x0f) ? (reg5yh1 & 0x0f) : 16 ); | ||
258 | |||
259 | p += sprintf(p, | ||
260 | "-----------------------------------UDMA Timings" | ||
261 | "--------------------------------\n\n"); | ||
262 | |||
263 | pci_read_config_byte(bmide_dev, 0x56, ®5xh); | ||
264 | pci_read_config_byte(bmide_dev, 0x57, ®5yh); | ||
265 | p += sprintf(p, | ||
266 | "UDMA: %s %s" | ||
267 | " %s %s\n" | ||
268 | "UDMA timings: %s %s" | ||
269 | " %s %s\n\n", | ||
270 | (reg5xh & 0x08) ? "OK" : "No", | ||
271 | (reg5xh & 0x80) ? "OK" : "No", | ||
272 | (reg5yh & 0x08) ? "OK" : "No", | ||
273 | (reg5yh & 0x80) ? "OK" : "No", | ||
274 | udmaT[(reg5xh & 0x07)], | ||
275 | udmaT[(reg5xh & 0x70) >> 4], | ||
276 | udmaT[reg5yh & 0x07], | ||
277 | udmaT[(reg5yh & 0x70) >> 4] ); | ||
278 | |||
279 | return p-buffer; /* => must be less than 4k! */ | ||
280 | } | ||
281 | #endif /* defined(DISPLAY_ALI_TIMINGS) && defined(CONFIG_PROC_FS) */ | ||
282 | |||
283 | /** | ||
284 | * ali15x3_tune_drive - set up a drive | ||
285 | * @drive: drive to tune | ||
286 | * @pio: unused | ||
287 | * | ||
288 | * Select the best PIO timing for the drive in question. Then | ||
289 | * program the controller for this drive set up | ||
290 | */ | ||
291 | |||
292 | static void ali15x3_tune_drive (ide_drive_t *drive, u8 pio) | ||
293 | { | ||
294 | ide_pio_data_t d; | ||
295 | ide_hwif_t *hwif = HWIF(drive); | ||
296 | struct pci_dev *dev = hwif->pci_dev; | ||
297 | int s_time, a_time, c_time; | ||
298 | u8 s_clc, a_clc, r_clc; | ||
299 | unsigned long flags; | ||
300 | int bus_speed = system_bus_clock(); | ||
301 | int port = hwif->channel ? 0x5c : 0x58; | ||
302 | int portFIFO = hwif->channel ? 0x55 : 0x54; | ||
303 | u8 cd_dma_fifo = 0; | ||
304 | int unit = drive->select.b.unit & 1; | ||
305 | |||
306 | pio = ide_get_best_pio_mode(drive, pio, 5, &d); | ||
307 | s_time = ide_pio_timings[pio].setup_time; | ||
308 | a_time = ide_pio_timings[pio].active_time; | ||
309 | if ((s_clc = (s_time * bus_speed + 999) / 1000) >= 8) | ||
310 | s_clc = 0; | ||
311 | if ((a_clc = (a_time * bus_speed + 999) / 1000) >= 8) | ||
312 | a_clc = 0; | ||
313 | c_time = ide_pio_timings[pio].cycle_time; | ||
314 | |||
315 | #if 0 | ||
316 | if ((r_clc = ((c_time - s_time - a_time) * bus_speed + 999) / 1000) >= 16) | ||
317 | r_clc = 0; | ||
318 | #endif | ||
319 | |||
320 | if (!(r_clc = (c_time * bus_speed + 999) / 1000 - a_clc - s_clc)) { | ||
321 | r_clc = 1; | ||
322 | } else { | ||
323 | if (r_clc >= 16) | ||
324 | r_clc = 0; | ||
325 | } | ||
326 | local_irq_save(flags); | ||
327 | |||
328 | /* | ||
329 | * PIO mode => ATA FIFO on, ATAPI FIFO off | ||
330 | */ | ||
331 | pci_read_config_byte(dev, portFIFO, &cd_dma_fifo); | ||
332 | if (drive->media==ide_disk) { | ||
333 | if (unit) { | ||
334 | pci_write_config_byte(dev, portFIFO, (cd_dma_fifo & 0x0F) | 0x50); | ||
335 | } else { | ||
336 | pci_write_config_byte(dev, portFIFO, (cd_dma_fifo & 0xF0) | 0x05); | ||
337 | } | ||
338 | } else { | ||
339 | if (unit) { | ||
340 | pci_write_config_byte(dev, portFIFO, cd_dma_fifo & 0x0F); | ||
341 | } else { | ||
342 | pci_write_config_byte(dev, portFIFO, cd_dma_fifo & 0xF0); | ||
343 | } | ||
344 | } | ||
345 | |||
346 | pci_write_config_byte(dev, port, s_clc); | ||
347 | pci_write_config_byte(dev, port+drive->select.b.unit+2, (a_clc << 4) | r_clc); | ||
348 | local_irq_restore(flags); | ||
349 | |||
350 | /* | ||
351 | * setup active rec | ||
352 | * { 70, 165, 365 }, PIO Mode 0 | ||
353 | * { 50, 125, 208 }, PIO Mode 1 | ||
354 | * { 30, 100, 110 }, PIO Mode 2 | ||
355 | * { 30, 80, 70 }, PIO Mode 3 with IORDY | ||
356 | * { 25, 70, 25 }, PIO Mode 4 with IORDY ns | ||
357 | * { 20, 50, 30 } PIO Mode 5 with IORDY (nonstandard) | ||
358 | */ | ||
359 | |||
360 | } | ||
361 | |||
362 | /** | ||
363 | * ali15x3_can_ultra - check for ultra DMA support | ||
364 | * @drive: drive to do the check | ||
365 | * | ||
366 | * Check the drive and controller revisions. Return 0 if UDMA is | ||
367 | * not available, or 1 if UDMA can be used. The actual rules for | ||
368 | * the ALi are | ||
369 | * No UDMA on revisions <= 0x20 | ||
370 | * Disk only for revisions < 0xC2 | ||
371 | * Not WDC drives for revisions < 0xC2 | ||
372 | * | ||
373 | * FIXME: WDC ifdef needs to die | ||
374 | */ | ||
375 | |||
376 | static u8 ali15x3_can_ultra (ide_drive_t *drive) | ||
377 | { | ||
378 | #ifndef CONFIG_WDC_ALI15X3 | ||
379 | struct hd_driveid *id = drive->id; | ||
380 | #endif /* CONFIG_WDC_ALI15X3 */ | ||
381 | |||
382 | if (m5229_revision <= 0x20) { | ||
383 | return 0; | ||
384 | } else if ((m5229_revision < 0xC2) && | ||
385 | #ifndef CONFIG_WDC_ALI15X3 | ||
386 | ((chip_is_1543c_e && strstr(id->model, "WDC ")) || | ||
387 | (drive->media!=ide_disk))) { | ||
388 | #else /* CONFIG_WDC_ALI15X3 */ | ||
389 | (drive->media!=ide_disk)) { | ||
390 | #endif /* CONFIG_WDC_ALI15X3 */ | ||
391 | return 0; | ||
392 | } else { | ||
393 | return 1; | ||
394 | } | ||
395 | } | ||
396 | |||
397 | /** | ||
398 | * ali15x3_ratemask - generate DMA mode list | ||
399 | * @drive: drive to compute against | ||
400 | * | ||
401 | * Generate a list of the available DMA modes for the drive. | ||
402 | * FIXME: this function contains lots of bogus masking we can dump | ||
403 | * | ||
404 | * Return the highest available mode (UDMA33, UDMA66, UDMA100,..) | ||
405 | */ | ||
406 | |||
407 | static u8 ali15x3_ratemask (ide_drive_t *drive) | ||
408 | { | ||
409 | u8 mode = 0, can_ultra = ali15x3_can_ultra(drive); | ||
410 | |||
411 | if (m5229_revision > 0xC4 && can_ultra) { | ||
412 | mode = 4; | ||
413 | } else if (m5229_revision == 0xC4 && can_ultra) { | ||
414 | mode = 3; | ||
415 | } else if (m5229_revision >= 0xC2 && can_ultra) { | ||
416 | mode = 2; | ||
417 | } else if (can_ultra) { | ||
418 | return 1; | ||
419 | } else { | ||
420 | return 0; | ||
421 | } | ||
422 | |||
423 | /* | ||
424 | * If the drive sees no suitable cable then UDMA 33 | ||
425 | * is the highest permitted mode | ||
426 | */ | ||
427 | |||
428 | if (!eighty_ninty_three(drive)) | ||
429 | mode = min(mode, (u8)1); | ||
430 | return mode; | ||
431 | } | ||
432 | |||
433 | /** | ||
434 | * ali15x3_tune_chipset - set up chiset for new speed | ||
435 | * @drive: drive to configure for | ||
436 | * @xferspeed: desired speed | ||
437 | * | ||
438 | * Configure the hardware for the desired IDE transfer mode. | ||
439 | * We also do the needed drive configuration through helpers | ||
440 | */ | ||
441 | |||
442 | static int ali15x3_tune_chipset (ide_drive_t *drive, u8 xferspeed) | ||
443 | { | ||
444 | ide_hwif_t *hwif = HWIF(drive); | ||
445 | struct pci_dev *dev = hwif->pci_dev; | ||
446 | u8 speed = ide_rate_filter(ali15x3_ratemask(drive), xferspeed); | ||
447 | u8 speed1 = speed; | ||
448 | u8 unit = (drive->select.b.unit & 0x01); | ||
449 | u8 tmpbyte = 0x00; | ||
450 | int m5229_udma = (hwif->channel) ? 0x57 : 0x56; | ||
451 | |||
452 | if (speed == XFER_UDMA_6) | ||
453 | speed1 = 0x47; | ||
454 | |||
455 | if (speed < XFER_UDMA_0) { | ||
456 | u8 ultra_enable = (unit) ? 0x7f : 0xf7; | ||
457 | /* | ||
458 | * clear "ultra enable" bit | ||
459 | */ | ||
460 | pci_read_config_byte(dev, m5229_udma, &tmpbyte); | ||
461 | tmpbyte &= ultra_enable; | ||
462 | pci_write_config_byte(dev, m5229_udma, tmpbyte); | ||
463 | |||
464 | if (speed < XFER_SW_DMA_0) | ||
465 | ali15x3_tune_drive(drive, speed); | ||
466 | } else { | ||
467 | pci_read_config_byte(dev, m5229_udma, &tmpbyte); | ||
468 | tmpbyte &= (0x0f << ((1-unit) << 2)); | ||
469 | /* | ||
470 | * enable ultra dma and set timing | ||
471 | */ | ||
472 | tmpbyte |= ((0x08 | ((4-speed1)&0x07)) << (unit << 2)); | ||
473 | pci_write_config_byte(dev, m5229_udma, tmpbyte); | ||
474 | if (speed >= XFER_UDMA_3) { | ||
475 | pci_read_config_byte(dev, 0x4b, &tmpbyte); | ||
476 | tmpbyte |= 1; | ||
477 | pci_write_config_byte(dev, 0x4b, tmpbyte); | ||
478 | } | ||
479 | } | ||
480 | return (ide_config_drive_speed(drive, speed)); | ||
481 | } | ||
482 | |||
483 | |||
484 | /** | ||
485 | * config_chipset_for_dma - set up DMA mode | ||
486 | * @drive: drive to configure for | ||
487 | * | ||
488 | * Place a drive into DMA mode and tune the chipset for | ||
489 | * the selected speed. | ||
490 | * | ||
491 | * Returns true if DMA mode can be used | ||
492 | */ | ||
493 | |||
494 | static int config_chipset_for_dma (ide_drive_t *drive) | ||
495 | { | ||
496 | u8 speed = ide_dma_speed(drive, ali15x3_ratemask(drive)); | ||
497 | |||
498 | if (!(speed)) | ||
499 | return 0; | ||
500 | |||
501 | (void) ali15x3_tune_chipset(drive, speed); | ||
502 | return ide_dma_enable(drive); | ||
503 | } | ||
504 | |||
505 | /** | ||
506 | * ali15x3_config_drive_for_dma - configure for DMA | ||
507 | * @drive: drive to configure | ||
508 | * | ||
509 | * Configure a drive for DMA operation. If DMA is not possible we | ||
510 | * drop the drive into PIO mode instead. | ||
511 | * | ||
512 | * FIXME: exactly what are we trying to return here | ||
513 | */ | ||
514 | |||
515 | static int ali15x3_config_drive_for_dma(ide_drive_t *drive) | ||
516 | { | ||
517 | ide_hwif_t *hwif = HWIF(drive); | ||
518 | struct hd_driveid *id = drive->id; | ||
519 | |||
520 | if ((m5229_revision<=0x20) && (drive->media!=ide_disk)) | ||
521 | return hwif->ide_dma_off_quietly(drive); | ||
522 | |||
523 | drive->init_speed = 0; | ||
524 | |||
525 | if ((id != NULL) && ((id->capability & 1) != 0) && drive->autodma) { | ||
526 | /* Consult the list of known "bad" drives */ | ||
527 | if (__ide_dma_bad_drive(drive)) | ||
528 | goto ata_pio; | ||
529 | if ((id->field_valid & 4) && (m5229_revision >= 0xC2)) { | ||
530 | if (id->dma_ultra & hwif->ultra_mask) { | ||
531 | /* Force if Capable UltraDMA */ | ||
532 | int dma = config_chipset_for_dma(drive); | ||
533 | if ((id->field_valid & 2) && !dma) | ||
534 | goto try_dma_modes; | ||
535 | } | ||
536 | } else if (id->field_valid & 2) { | ||
537 | try_dma_modes: | ||
538 | if ((id->dma_mword & hwif->mwdma_mask) || | ||
539 | (id->dma_1word & hwif->swdma_mask)) { | ||
540 | /* Force if Capable regular DMA modes */ | ||
541 | if (!config_chipset_for_dma(drive)) | ||
542 | goto no_dma_set; | ||
543 | } | ||
544 | } else if (__ide_dma_good_drive(drive) && | ||
545 | (id->eide_dma_time < 150)) { | ||
546 | /* Consult the list of known "good" drives */ | ||
547 | if (!config_chipset_for_dma(drive)) | ||
548 | goto no_dma_set; | ||
549 | } else { | ||
550 | goto ata_pio; | ||
551 | } | ||
552 | } else { | ||
553 | ata_pio: | ||
554 | hwif->tuneproc(drive, 255); | ||
555 | no_dma_set: | ||
556 | return hwif->ide_dma_off_quietly(drive); | ||
557 | } | ||
558 | return hwif->ide_dma_on(drive); | ||
559 | } | ||
560 | |||
561 | /** | ||
562 | * ali15x3_dma_setup - begin a DMA phase | ||
563 | * @drive: target device | ||
564 | * | ||
565 | * Returns 1 if the DMA cannot be performed, zero on success. | ||
566 | */ | ||
567 | |||
568 | static int ali15x3_dma_setup(ide_drive_t *drive) | ||
569 | { | ||
570 | if (m5229_revision < 0xC2 && drive->media != ide_disk) { | ||
571 | if (rq_data_dir(drive->hwif->hwgroup->rq)) | ||
572 | return 1; /* try PIO instead of DMA */ | ||
573 | } | ||
574 | return ide_dma_setup(drive); | ||
575 | } | ||
576 | |||
577 | /** | ||
578 | * init_chipset_ali15x3 - Initialise an ALi IDE controller | ||
579 | * @dev: PCI device | ||
580 | * @name: Name of the controller | ||
581 | * | ||
582 | * This function initializes the ALI IDE controller and where | ||
583 | * appropriate also sets up the 1533 southbridge. | ||
584 | */ | ||
585 | |||
586 | static unsigned int __init init_chipset_ali15x3 (struct pci_dev *dev, const char *name) | ||
587 | { | ||
588 | unsigned long flags; | ||
589 | u8 tmpbyte; | ||
590 | struct pci_dev *north = pci_find_slot(0, PCI_DEVFN(0,0)); | ||
591 | |||
592 | pci_read_config_byte(dev, PCI_REVISION_ID, &m5229_revision); | ||
593 | |||
594 | isa_dev = pci_find_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1533, NULL); | ||
595 | |||
596 | #if defined(DISPLAY_ALI_TIMINGS) && defined(CONFIG_PROC_FS) | ||
597 | if (!ali_proc) { | ||
598 | ali_proc = 1; | ||
599 | bmide_dev = dev; | ||
600 | ide_pci_create_host_proc("ali", ali_get_info); | ||
601 | } | ||
602 | #endif /* defined(DISPLAY_ALI_TIMINGS) && defined(CONFIG_PROC_FS) */ | ||
603 | |||
604 | local_irq_save(flags); | ||
605 | |||
606 | if (m5229_revision < 0xC2) { | ||
607 | /* | ||
608 | * revision 0x20 (1543-E, 1543-F) | ||
609 | * revision 0xC0, 0xC1 (1543C-C, 1543C-D, 1543C-E) | ||
610 | * clear CD-ROM DMA write bit, m5229, 0x4b, bit 7 | ||
611 | */ | ||
612 | pci_read_config_byte(dev, 0x4b, &tmpbyte); | ||
613 | /* | ||
614 | * clear bit 7 | ||
615 | */ | ||
616 | pci_write_config_byte(dev, 0x4b, tmpbyte & 0x7F); | ||
617 | local_irq_restore(flags); | ||
618 | return 0; | ||
619 | } | ||
620 | |||
621 | /* | ||
622 | * 1543C-B?, 1535, 1535D, 1553 | ||
623 | * Note 1: not all "motherboard" support this detection | ||
624 | * Note 2: if no udma 66 device, the detection may "error". | ||
625 | * but in this case, we will not set the device to | ||
626 | * ultra 66, the detection result is not important | ||
627 | */ | ||
628 | |||
629 | /* | ||
630 | * enable "Cable Detection", m5229, 0x4b, bit3 | ||
631 | */ | ||
632 | pci_read_config_byte(dev, 0x4b, &tmpbyte); | ||
633 | pci_write_config_byte(dev, 0x4b, tmpbyte | 0x08); | ||
634 | |||
635 | /* | ||
636 | * We should only tune the 1533 enable if we are using an ALi | ||
637 | * North bridge. We might have no north found on some zany | ||
638 | * box without a device at 0:0.0. The ALi bridge will be at | ||
639 | * 0:0.0 so if we didn't find one we know what is cooking. | ||
640 | */ | ||
641 | if (north && north->vendor != PCI_VENDOR_ID_AL) { | ||
642 | local_irq_restore(flags); | ||
643 | return 0; | ||
644 | } | ||
645 | |||
646 | if (m5229_revision < 0xC5 && isa_dev) | ||
647 | { | ||
648 | /* | ||
649 | * set south-bridge's enable bit, m1533, 0x79 | ||
650 | */ | ||
651 | |||
652 | pci_read_config_byte(isa_dev, 0x79, &tmpbyte); | ||
653 | if (m5229_revision == 0xC2) { | ||
654 | /* | ||
655 | * 1543C-B0 (m1533, 0x79, bit 2) | ||
656 | */ | ||
657 | pci_write_config_byte(isa_dev, 0x79, tmpbyte | 0x04); | ||
658 | } else if (m5229_revision >= 0xC3) { | ||
659 | /* | ||
660 | * 1553/1535 (m1533, 0x79, bit 1) | ||
661 | */ | ||
662 | pci_write_config_byte(isa_dev, 0x79, tmpbyte | 0x02); | ||
663 | } | ||
664 | } | ||
665 | local_irq_restore(flags); | ||
666 | return 0; | ||
667 | } | ||
668 | |||
669 | /** | ||
670 | * ata66_ali15x3 - check for UDMA 66 support | ||
671 | * @hwif: IDE interface | ||
672 | * | ||
673 | * This checks if the controller and the cable are capable | ||
674 | * of UDMA66 transfers. It doesn't check the drives. | ||
675 | * But see note 2 below! | ||
676 | * | ||
677 | * FIXME: frobs bits that are not defined on newer ALi devicea | ||
678 | */ | ||
679 | |||
680 | static unsigned int __init ata66_ali15x3 (ide_hwif_t *hwif) | ||
681 | { | ||
682 | struct pci_dev *dev = hwif->pci_dev; | ||
683 | unsigned int ata66 = 0; | ||
684 | u8 cable_80_pin[2] = { 0, 0 }; | ||
685 | |||
686 | unsigned long flags; | ||
687 | u8 tmpbyte; | ||
688 | |||
689 | local_irq_save(flags); | ||
690 | |||
691 | if (m5229_revision >= 0xC2) { | ||
692 | /* | ||
693 | * Ultra66 cable detection (from Host View) | ||
694 | * m5229, 0x4a, bit0: primary, bit1: secondary 80 pin | ||
695 | */ | ||
696 | pci_read_config_byte(dev, 0x4a, &tmpbyte); | ||
697 | /* | ||
698 | * 0x4a, bit0 is 0 => primary channel | ||
699 | * has 80-pin (from host view) | ||
700 | */ | ||
701 | if (!(tmpbyte & 0x01)) cable_80_pin[0] = 1; | ||
702 | /* | ||
703 | * 0x4a, bit1 is 0 => secondary channel | ||
704 | * has 80-pin (from host view) | ||
705 | */ | ||
706 | if (!(tmpbyte & 0x02)) cable_80_pin[1] = 1; | ||
707 | /* | ||
708 | * Allow ata66 if cable of current channel has 80 pins | ||
709 | */ | ||
710 | ata66 = (hwif->channel)?cable_80_pin[1]:cable_80_pin[0]; | ||
711 | } else { | ||
712 | /* | ||
713 | * check m1533, 0x5e, bit 1~4 == 1001 => & 00011110 = 00010010 | ||
714 | */ | ||
715 | pci_read_config_byte(isa_dev, 0x5e, &tmpbyte); | ||
716 | chip_is_1543c_e = ((tmpbyte & 0x1e) == 0x12) ? 1: 0; | ||
717 | } | ||
718 | |||
719 | /* | ||
720 | * CD_ROM DMA on (m5229, 0x53, bit0) | ||
721 | * Enable this bit even if we want to use PIO | ||
722 | * PIO FIFO off (m5229, 0x53, bit1) | ||
723 | * The hardware will use 0x54h and 0x55h to control PIO FIFO | ||
724 | * (Not on later devices it seems) | ||
725 | * | ||
726 | * 0x53 changes meaning on later revs - we must no touch | ||
727 | * bit 1 on them. Need to check if 0x20 is the right break | ||
728 | */ | ||
729 | |||
730 | pci_read_config_byte(dev, 0x53, &tmpbyte); | ||
731 | |||
732 | if(m5229_revision <= 0x20) | ||
733 | tmpbyte = (tmpbyte & (~0x02)) | 0x01; | ||
734 | else | ||
735 | tmpbyte |= 0x01; | ||
736 | |||
737 | pci_write_config_byte(dev, 0x53, tmpbyte); | ||
738 | |||
739 | local_irq_restore(flags); | ||
740 | |||
741 | return(ata66); | ||
742 | } | ||
743 | |||
744 | /** | ||
745 | * init_hwif_common_ali15x3 - Set up ALI IDE hardware | ||
746 | * @hwif: IDE interface | ||
747 | * | ||
748 | * Initialize the IDE structure side of the ALi 15x3 driver. | ||
749 | */ | ||
750 | |||
751 | static void __init init_hwif_common_ali15x3 (ide_hwif_t *hwif) | ||
752 | { | ||
753 | hwif->autodma = 0; | ||
754 | hwif->tuneproc = &ali15x3_tune_drive; | ||
755 | hwif->speedproc = &ali15x3_tune_chipset; | ||
756 | |||
757 | /* don't use LBA48 DMA on ALi devices before rev 0xC5 */ | ||
758 | hwif->no_lba48_dma = (m5229_revision <= 0xC4) ? 1 : 0; | ||
759 | |||
760 | if (!hwif->dma_base) { | ||
761 | hwif->drives[0].autotune = 1; | ||
762 | hwif->drives[1].autotune = 1; | ||
763 | return; | ||
764 | } | ||
765 | |||
766 | hwif->atapi_dma = 1; | ||
767 | |||
768 | if (m5229_revision > 0x20) | ||
769 | hwif->ultra_mask = 0x7f; | ||
770 | hwif->mwdma_mask = 0x07; | ||
771 | hwif->swdma_mask = 0x07; | ||
772 | |||
773 | if (m5229_revision >= 0x20) { | ||
774 | /* | ||
775 | * M1543C or newer for DMAing | ||
776 | */ | ||
777 | hwif->ide_dma_check = &ali15x3_config_drive_for_dma; | ||
778 | hwif->dma_setup = &ali15x3_dma_setup; | ||
779 | if (!noautodma) | ||
780 | hwif->autodma = 1; | ||
781 | if (!(hwif->udma_four)) | ||
782 | hwif->udma_four = ata66_ali15x3(hwif); | ||
783 | } | ||
784 | hwif->drives[0].autodma = hwif->autodma; | ||
785 | hwif->drives[1].autodma = hwif->autodma; | ||
786 | } | ||
787 | |||
788 | /** | ||
789 | * init_hwif_ali15x3 - Initialize the ALI IDE x86 stuff | ||
790 | * @hwif: interface to configure | ||
791 | * | ||
792 | * Obtain the IRQ tables for an ALi based IDE solution on the PC | ||
793 | * class platforms. This part of the code isn't applicable to the | ||
794 | * Sparc systems | ||
795 | */ | ||
796 | |||
797 | static void __init init_hwif_ali15x3 (ide_hwif_t *hwif) | ||
798 | { | ||
799 | u8 ideic, inmir; | ||
800 | s8 irq_routing_table[] = { -1, 9, 3, 10, 4, 5, 7, 6, | ||
801 | 1, 11, 0, 12, 0, 14, 0, 15 }; | ||
802 | int irq = -1; | ||
803 | |||
804 | if (hwif->pci_dev->device == PCI_DEVICE_ID_AL_M5229) | ||
805 | hwif->irq = hwif->channel ? 15 : 14; | ||
806 | |||
807 | if (isa_dev) { | ||
808 | /* | ||
809 | * read IDE interface control | ||
810 | */ | ||
811 | pci_read_config_byte(isa_dev, 0x58, &ideic); | ||
812 | |||
813 | /* bit0, bit1 */ | ||
814 | ideic = ideic & 0x03; | ||
815 | |||
816 | /* get IRQ for IDE Controller */ | ||
817 | if ((hwif->channel && ideic == 0x03) || | ||
818 | (!hwif->channel && !ideic)) { | ||
819 | /* | ||
820 | * get SIRQ1 routing table | ||
821 | */ | ||
822 | pci_read_config_byte(isa_dev, 0x44, &inmir); | ||
823 | inmir = inmir & 0x0f; | ||
824 | irq = irq_routing_table[inmir]; | ||
825 | } else if (hwif->channel && !(ideic & 0x01)) { | ||
826 | /* | ||
827 | * get SIRQ2 routing table | ||
828 | */ | ||
829 | pci_read_config_byte(isa_dev, 0x75, &inmir); | ||
830 | inmir = inmir & 0x0f; | ||
831 | irq = irq_routing_table[inmir]; | ||
832 | } | ||
833 | if(irq >= 0) | ||
834 | hwif->irq = irq; | ||
835 | } | ||
836 | |||
837 | init_hwif_common_ali15x3(hwif); | ||
838 | } | ||
839 | |||
840 | /** | ||
841 | * init_dma_ali15x3 - set up DMA on ALi15x3 | ||
842 | * @hwif: IDE interface | ||
843 | * @dmabase: DMA interface base PCI address | ||
844 | * | ||
845 | * Set up the DMA functionality on the ALi 15x3. For the ALi | ||
846 | * controllers this is generic so we can let the generic code do | ||
847 | * the actual work. | ||
848 | */ | ||
849 | |||
850 | static void __init init_dma_ali15x3 (ide_hwif_t *hwif, unsigned long dmabase) | ||
851 | { | ||
852 | if (m5229_revision < 0x20) | ||
853 | return; | ||
854 | if (!(hwif->channel)) | ||
855 | hwif->OUTB(hwif->INB(dmabase+2) & 0x60, dmabase+2); | ||
856 | ide_setup_dma(hwif, dmabase, 8); | ||
857 | } | ||
858 | |||
859 | static ide_pci_device_t ali15x3_chipset __devinitdata = { | ||
860 | .name = "ALI15X3", | ||
861 | .init_chipset = init_chipset_ali15x3, | ||
862 | .init_hwif = init_hwif_ali15x3, | ||
863 | .init_dma = init_dma_ali15x3, | ||
864 | .channels = 2, | ||
865 | .autodma = AUTODMA, | ||
866 | .bootable = ON_BOARD, | ||
867 | }; | ||
868 | |||
869 | /** | ||
870 | * alim15x3_init_one - set up an ALi15x3 IDE controller | ||
871 | * @dev: PCI device to set up | ||
872 | * | ||
873 | * Perform the actual set up for an ALi15x3 that has been found by the | ||
874 | * hot plug layer. | ||
875 | */ | ||
876 | |||
877 | static int __devinit alim15x3_init_one(struct pci_dev *dev, const struct pci_device_id *id) | ||
878 | { | ||
879 | ide_pci_device_t *d = &ali15x3_chipset; | ||
880 | |||
881 | if(pci_find_device(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RS100, NULL)) | ||
882 | printk(KERN_ERR "Warning: ATI Radeon IGP Northbridge is not yet fully tested.\n"); | ||
883 | |||
884 | #if defined(CONFIG_SPARC64) | ||
885 | d->init_hwif = init_hwif_common_ali15x3; | ||
886 | #endif /* CONFIG_SPARC64 */ | ||
887 | return ide_setup_pci_device(dev, d); | ||
888 | } | ||
889 | |||
890 | |||
891 | static struct pci_device_id alim15x3_pci_tbl[] = { | ||
892 | { PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M5229, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, | ||
893 | { PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M5228, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, | ||
894 | { 0, }, | ||
895 | }; | ||
896 | MODULE_DEVICE_TABLE(pci, alim15x3_pci_tbl); | ||
897 | |||
898 | static struct pci_driver driver = { | ||
899 | .name = "ALI15x3_IDE", | ||
900 | .id_table = alim15x3_pci_tbl, | ||
901 | .probe = alim15x3_init_one, | ||
902 | }; | ||
903 | |||
904 | static int ali15x3_ide_init(void) | ||
905 | { | ||
906 | return ide_pci_register_driver(&driver); | ||
907 | } | ||
908 | |||
909 | module_init(ali15x3_ide_init); | ||
910 | |||
911 | MODULE_AUTHOR("Michael Aubry, Andrzej Krzysztofowicz, CJ, Andre Hedrick, Alan Cox"); | ||
912 | MODULE_DESCRIPTION("PCI driver module for ALi 15x3 IDE"); | ||
913 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/ide/pci/amd74xx.c b/drivers/ide/pci/amd74xx.c new file mode 100644 index 000000000000..47225e324356 --- /dev/null +++ b/drivers/ide/pci/amd74xx.c | |||
@@ -0,0 +1,543 @@ | |||
1 | /* | ||
2 | * Version 2.13 | ||
3 | * | ||
4 | * AMD 755/756/766/8111 and nVidia nForce/2/2s/3/3s/CK804/MCP04 | ||
5 | * IDE driver for Linux. | ||
6 | * | ||
7 | * Copyright (c) 2000-2002 Vojtech Pavlik | ||
8 | * | ||
9 | * Based on the work of: | ||
10 | * Andre Hedrick | ||
11 | */ | ||
12 | |||
13 | /* | ||
14 | * This program is free software; you can redistribute it and/or modify it | ||
15 | * under the terms of the GNU General Public License version 2 as published by | ||
16 | * the Free Software Foundation. | ||
17 | */ | ||
18 | |||
19 | #include <linux/config.h> | ||
20 | #include <linux/module.h> | ||
21 | #include <linux/kernel.h> | ||
22 | #include <linux/ioport.h> | ||
23 | #include <linux/blkdev.h> | ||
24 | #include <linux/pci.h> | ||
25 | #include <linux/init.h> | ||
26 | #include <linux/ide.h> | ||
27 | #include <asm/io.h> | ||
28 | |||
29 | #include "ide-timing.h" | ||
30 | |||
31 | #define DISPLAY_AMD_TIMINGS | ||
32 | |||
33 | #define AMD_IDE_ENABLE (0x00 + amd_config->base) | ||
34 | #define AMD_IDE_CONFIG (0x01 + amd_config->base) | ||
35 | #define AMD_CABLE_DETECT (0x02 + amd_config->base) | ||
36 | #define AMD_DRIVE_TIMING (0x08 + amd_config->base) | ||
37 | #define AMD_8BIT_TIMING (0x0e + amd_config->base) | ||
38 | #define AMD_ADDRESS_SETUP (0x0c + amd_config->base) | ||
39 | #define AMD_UDMA_TIMING (0x10 + amd_config->base) | ||
40 | |||
41 | #define AMD_UDMA 0x07 | ||
42 | #define AMD_UDMA_33 0x01 | ||
43 | #define AMD_UDMA_66 0x02 | ||
44 | #define AMD_UDMA_100 0x03 | ||
45 | #define AMD_UDMA_133 0x04 | ||
46 | #define AMD_CHECK_SWDMA 0x08 | ||
47 | #define AMD_BAD_SWDMA 0x10 | ||
48 | #define AMD_BAD_FIFO 0x20 | ||
49 | #define AMD_CHECK_SERENADE 0x40 | ||
50 | |||
51 | /* | ||
52 | * AMD SouthBridge chips. | ||
53 | */ | ||
54 | |||
55 | static struct amd_ide_chip { | ||
56 | unsigned short id; | ||
57 | unsigned long base; | ||
58 | unsigned char flags; | ||
59 | } amd_ide_chips[] = { | ||
60 | { PCI_DEVICE_ID_AMD_COBRA_7401, 0x40, AMD_UDMA_33 | AMD_BAD_SWDMA }, | ||
61 | { PCI_DEVICE_ID_AMD_VIPER_7409, 0x40, AMD_UDMA_66 | AMD_CHECK_SWDMA }, | ||
62 | { PCI_DEVICE_ID_AMD_VIPER_7411, 0x40, AMD_UDMA_100 | AMD_BAD_FIFO }, | ||
63 | { PCI_DEVICE_ID_AMD_OPUS_7441, 0x40, AMD_UDMA_100 }, | ||
64 | { PCI_DEVICE_ID_AMD_8111_IDE, 0x40, AMD_UDMA_133 | AMD_CHECK_SERENADE }, | ||
65 | { PCI_DEVICE_ID_NVIDIA_NFORCE_IDE, 0x50, AMD_UDMA_100 }, | ||
66 | { PCI_DEVICE_ID_NVIDIA_NFORCE2_IDE, 0x50, AMD_UDMA_133 }, | ||
67 | { PCI_DEVICE_ID_NVIDIA_NFORCE2S_IDE, 0x50, AMD_UDMA_133 }, | ||
68 | { PCI_DEVICE_ID_NVIDIA_NFORCE2S_SATA, 0x50, AMD_UDMA_133 }, | ||
69 | { PCI_DEVICE_ID_NVIDIA_NFORCE3_IDE, 0x50, AMD_UDMA_133 }, | ||
70 | { PCI_DEVICE_ID_NVIDIA_NFORCE3S_IDE, 0x50, AMD_UDMA_133 }, | ||
71 | { PCI_DEVICE_ID_NVIDIA_NFORCE3S_SATA, 0x50, AMD_UDMA_133 }, | ||
72 | { PCI_DEVICE_ID_NVIDIA_NFORCE3S_SATA2, 0x50, AMD_UDMA_133 }, | ||
73 | { PCI_DEVICE_ID_NVIDIA_NFORCE_CK804_IDE, 0x50, AMD_UDMA_133 }, | ||
74 | { PCI_DEVICE_ID_NVIDIA_NFORCE_MCP04_IDE, 0x50, AMD_UDMA_133 }, | ||
75 | { 0 } | ||
76 | }; | ||
77 | |||
78 | static struct amd_ide_chip *amd_config; | ||
79 | static ide_pci_device_t *amd_chipset; | ||
80 | static unsigned int amd_80w; | ||
81 | static unsigned int amd_clock; | ||
82 | |||
83 | static char *amd_dma[] = { "MWDMA16", "UDMA33", "UDMA66", "UDMA100", "UDMA133" }; | ||
84 | static unsigned char amd_cyc2udma[] = { 6, 6, 5, 4, 0, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 7 }; | ||
85 | |||
86 | /* | ||
87 | * AMD /proc entry. | ||
88 | */ | ||
89 | |||
90 | #ifdef CONFIG_PROC_FS | ||
91 | |||
92 | #include <linux/stat.h> | ||
93 | #include <linux/proc_fs.h> | ||
94 | |||
95 | static u8 amd74xx_proc; | ||
96 | |||
97 | static unsigned char amd_udma2cyc[] = { 4, 6, 8, 10, 3, 2, 1, 15 }; | ||
98 | static unsigned long amd_base; | ||
99 | static struct pci_dev *bmide_dev; | ||
100 | extern int (*amd74xx_display_info)(char *, char **, off_t, int); /* ide-proc.c */ | ||
101 | |||
102 | #define amd_print(format, arg...) p += sprintf(p, format "\n" , ## arg) | ||
103 | #define amd_print_drive(name, format, arg...)\ | ||
104 | p += sprintf(p, name); for (i = 0; i < 4; i++) p += sprintf(p, format, ## arg); p += sprintf(p, "\n"); | ||
105 | |||
106 | static int amd74xx_get_info(char *buffer, char **addr, off_t offset, int count) | ||
107 | { | ||
108 | int speed[4], cycle[4], setup[4], active[4], recover[4], den[4], | ||
109 | uen[4], udma[4], active8b[4], recover8b[4]; | ||
110 | struct pci_dev *dev = bmide_dev; | ||
111 | unsigned int v, u, i; | ||
112 | unsigned short c, w; | ||
113 | unsigned char t; | ||
114 | int len; | ||
115 | char *p = buffer; | ||
116 | |||
117 | amd_print("----------AMD BusMastering IDE Configuration----------------"); | ||
118 | |||
119 | amd_print("Driver Version: 2.13"); | ||
120 | amd_print("South Bridge: %s", pci_name(bmide_dev)); | ||
121 | |||
122 | pci_read_config_byte(dev, PCI_REVISION_ID, &t); | ||
123 | amd_print("Revision: IDE %#x", t); | ||
124 | amd_print("Highest DMA rate: %s", amd_dma[amd_config->flags & AMD_UDMA]); | ||
125 | |||
126 | amd_print("BM-DMA base: %#lx", amd_base); | ||
127 | amd_print("PCI clock: %d.%dMHz", amd_clock / 1000, amd_clock / 100 % 10); | ||
128 | |||
129 | amd_print("-----------------------Primary IDE-------Secondary IDE------"); | ||
130 | |||
131 | pci_read_config_byte(dev, AMD_IDE_CONFIG, &t); | ||
132 | amd_print("Prefetch Buffer: %10s%20s", (t & 0x80) ? "yes" : "no", (t & 0x20) ? "yes" : "no"); | ||
133 | amd_print("Post Write Buffer: %10s%20s", (t & 0x40) ? "yes" : "no", (t & 0x10) ? "yes" : "no"); | ||
134 | |||
135 | pci_read_config_byte(dev, AMD_IDE_ENABLE, &t); | ||
136 | amd_print("Enabled: %10s%20s", (t & 0x02) ? "yes" : "no", (t & 0x01) ? "yes" : "no"); | ||
137 | |||
138 | c = inb(amd_base + 0x02) | (inb(amd_base + 0x0a) << 8); | ||
139 | amd_print("Simplex only: %10s%20s", (c & 0x80) ? "yes" : "no", (c & 0x8000) ? "yes" : "no"); | ||
140 | |||
141 | amd_print("Cable Type: %10s%20s", (amd_80w & 1) ? "80w" : "40w", (amd_80w & 2) ? "80w" : "40w"); | ||
142 | |||
143 | if (!amd_clock) | ||
144 | return p - buffer; | ||
145 | |||
146 | amd_print("-------------------drive0----drive1----drive2----drive3-----"); | ||
147 | |||
148 | pci_read_config_byte(dev, AMD_ADDRESS_SETUP, &t); | ||
149 | pci_read_config_dword(dev, AMD_DRIVE_TIMING, &v); | ||
150 | pci_read_config_word(dev, AMD_8BIT_TIMING, &w); | ||
151 | pci_read_config_dword(dev, AMD_UDMA_TIMING, &u); | ||
152 | |||
153 | for (i = 0; i < 4; i++) { | ||
154 | setup[i] = ((t >> ((3 - i) << 1)) & 0x3) + 1; | ||
155 | recover8b[i] = ((w >> ((1 - (i >> 1)) << 3)) & 0xf) + 1; | ||
156 | active8b[i] = ((w >> (((1 - (i >> 1)) << 3) + 4)) & 0xf) + 1; | ||
157 | active[i] = ((v >> (((3 - i) << 3) + 4)) & 0xf) + 1; | ||
158 | recover[i] = ((v >> ((3 - i) << 3)) & 0xf) + 1; | ||
159 | |||
160 | udma[i] = amd_udma2cyc[((u >> ((3 - i) << 3)) & 0x7)]; | ||
161 | uen[i] = ((u >> ((3 - i) << 3)) & 0x40) ? 1 : 0; | ||
162 | den[i] = (c & ((i & 1) ? 0x40 : 0x20) << ((i & 2) << 2)); | ||
163 | |||
164 | if (den[i] && uen[i] && udma[i] == 1) { | ||
165 | speed[i] = amd_clock * 3; | ||
166 | cycle[i] = 666666 / amd_clock; | ||
167 | continue; | ||
168 | } | ||
169 | |||
170 | if (den[i] && uen[i] && udma[i] == 15) { | ||
171 | speed[i] = amd_clock * 4; | ||
172 | cycle[i] = 500000 / amd_clock; | ||
173 | continue; | ||
174 | } | ||
175 | |||
176 | speed[i] = 4 * amd_clock / ((den[i] && uen[i]) ? udma[i] : (active[i] + recover[i]) * 2); | ||
177 | cycle[i] = 1000000 * ((den[i] && uen[i]) ? udma[i] : (active[i] + recover[i]) * 2) / amd_clock / 2; | ||
178 | } | ||
179 | |||
180 | amd_print_drive("Transfer Mode: ", "%10s", den[i] ? (uen[i] ? "UDMA" : "DMA") : "PIO"); | ||
181 | |||
182 | amd_print_drive("Address Setup: ", "%8dns", 1000000 * setup[i] / amd_clock); | ||
183 | amd_print_drive("Cmd Active: ", "%8dns", 1000000 * active8b[i] / amd_clock); | ||
184 | amd_print_drive("Cmd Recovery: ", "%8dns", 1000000 * recover8b[i] / amd_clock); | ||
185 | amd_print_drive("Data Active: ", "%8dns", 1000000 * active[i] / amd_clock); | ||
186 | amd_print_drive("Data Recovery: ", "%8dns", 1000000 * recover[i] / amd_clock); | ||
187 | amd_print_drive("Cycle Time: ", "%8dns", cycle[i]); | ||
188 | amd_print_drive("Transfer Rate: ", "%4d.%dMB/s", speed[i] / 1000, speed[i] / 100 % 10); | ||
189 | |||
190 | /* hoping p - buffer is less than 4K... */ | ||
191 | len = (p - buffer) - offset; | ||
192 | *addr = buffer + offset; | ||
193 | |||
194 | return len > count ? count : len; | ||
195 | } | ||
196 | |||
197 | #endif | ||
198 | |||
199 | /* | ||
200 | * amd_set_speed() writes timing values to the chipset registers | ||
201 | */ | ||
202 | |||
203 | static void amd_set_speed(struct pci_dev *dev, unsigned char dn, struct ide_timing *timing) | ||
204 | { | ||
205 | unsigned char t; | ||
206 | |||
207 | pci_read_config_byte(dev, AMD_ADDRESS_SETUP, &t); | ||
208 | t = (t & ~(3 << ((3 - dn) << 1))) | ((FIT(timing->setup, 1, 4) - 1) << ((3 - dn) << 1)); | ||
209 | pci_write_config_byte(dev, AMD_ADDRESS_SETUP, t); | ||
210 | |||
211 | pci_write_config_byte(dev, AMD_8BIT_TIMING + (1 - (dn >> 1)), | ||
212 | ((FIT(timing->act8b, 1, 16) - 1) << 4) | (FIT(timing->rec8b, 1, 16) - 1)); | ||
213 | |||
214 | pci_write_config_byte(dev, AMD_DRIVE_TIMING + (3 - dn), | ||
215 | ((FIT(timing->active, 1, 16) - 1) << 4) | (FIT(timing->recover, 1, 16) - 1)); | ||
216 | |||
217 | switch (amd_config->flags & AMD_UDMA) { | ||
218 | case AMD_UDMA_33: t = timing->udma ? (0xc0 | (FIT(timing->udma, 2, 5) - 2)) : 0x03; break; | ||
219 | case AMD_UDMA_66: t = timing->udma ? (0xc0 | amd_cyc2udma[FIT(timing->udma, 2, 10)]) : 0x03; break; | ||
220 | case AMD_UDMA_100: t = timing->udma ? (0xc0 | amd_cyc2udma[FIT(timing->udma, 1, 10)]) : 0x03; break; | ||
221 | case AMD_UDMA_133: t = timing->udma ? (0xc0 | amd_cyc2udma[FIT(timing->udma, 1, 15)]) : 0x03; break; | ||
222 | default: return; | ||
223 | } | ||
224 | |||
225 | pci_write_config_byte(dev, AMD_UDMA_TIMING + (3 - dn), t); | ||
226 | } | ||
227 | |||
228 | /* | ||
229 | * amd_set_drive() computes timing values configures the drive and | ||
230 | * the chipset to a desired transfer mode. It also can be called | ||
231 | * by upper layers. | ||
232 | */ | ||
233 | |||
234 | static int amd_set_drive(ide_drive_t *drive, u8 speed) | ||
235 | { | ||
236 | ide_drive_t *peer = HWIF(drive)->drives + (~drive->dn & 1); | ||
237 | struct ide_timing t, p; | ||
238 | int T, UT; | ||
239 | |||
240 | if (speed != XFER_PIO_SLOW && speed != drive->current_speed) | ||
241 | if (ide_config_drive_speed(drive, speed)) | ||
242 | printk(KERN_WARNING "ide%d: Drive %d didn't accept speed setting. Oh, well.\n", | ||
243 | drive->dn >> 1, drive->dn & 1); | ||
244 | |||
245 | T = 1000000000 / amd_clock; | ||
246 | UT = T / min_t(int, max_t(int, amd_config->flags & AMD_UDMA, 1), 2); | ||
247 | |||
248 | ide_timing_compute(drive, speed, &t, T, UT); | ||
249 | |||
250 | if (peer->present) { | ||
251 | ide_timing_compute(peer, peer->current_speed, &p, T, UT); | ||
252 | ide_timing_merge(&p, &t, &t, IDE_TIMING_8BIT); | ||
253 | } | ||
254 | |||
255 | if (speed == XFER_UDMA_5 && amd_clock <= 33333) t.udma = 1; | ||
256 | if (speed == XFER_UDMA_6 && amd_clock <= 33333) t.udma = 15; | ||
257 | |||
258 | amd_set_speed(HWIF(drive)->pci_dev, drive->dn, &t); | ||
259 | |||
260 | if (!drive->init_speed) | ||
261 | drive->init_speed = speed; | ||
262 | drive->current_speed = speed; | ||
263 | |||
264 | return 0; | ||
265 | } | ||
266 | |||
267 | /* | ||
268 | * amd74xx_tune_drive() is a callback from upper layers for | ||
269 | * PIO-only tuning. | ||
270 | */ | ||
271 | |||
272 | static void amd74xx_tune_drive(ide_drive_t *drive, u8 pio) | ||
273 | { | ||
274 | if (pio == 255) { | ||
275 | amd_set_drive(drive, ide_find_best_mode(drive, XFER_PIO | XFER_EPIO)); | ||
276 | return; | ||
277 | } | ||
278 | |||
279 | amd_set_drive(drive, XFER_PIO_0 + min_t(byte, pio, 5)); | ||
280 | } | ||
281 | |||
282 | /* | ||
283 | * amd74xx_dmaproc() is a callback from upper layers that can do | ||
284 | * a lot, but we use it for DMA/PIO tuning only, delegating everything | ||
285 | * else to the default ide_dmaproc(). | ||
286 | */ | ||
287 | |||
288 | static int amd74xx_ide_dma_check(ide_drive_t *drive) | ||
289 | { | ||
290 | int w80 = HWIF(drive)->udma_four; | ||
291 | |||
292 | u8 speed = ide_find_best_mode(drive, | ||
293 | XFER_PIO | XFER_EPIO | XFER_MWDMA | XFER_UDMA | | ||
294 | ((amd_config->flags & AMD_BAD_SWDMA) ? 0 : XFER_SWDMA) | | ||
295 | (w80 && (amd_config->flags & AMD_UDMA) >= AMD_UDMA_66 ? XFER_UDMA_66 : 0) | | ||
296 | (w80 && (amd_config->flags & AMD_UDMA) >= AMD_UDMA_100 ? XFER_UDMA_100 : 0) | | ||
297 | (w80 && (amd_config->flags & AMD_UDMA) >= AMD_UDMA_133 ? XFER_UDMA_133 : 0)); | ||
298 | |||
299 | amd_set_drive(drive, speed); | ||
300 | |||
301 | if (drive->autodma && (speed & XFER_MODE) != XFER_PIO) | ||
302 | return HWIF(drive)->ide_dma_on(drive); | ||
303 | return HWIF(drive)->ide_dma_off_quietly(drive); | ||
304 | } | ||
305 | |||
306 | /* | ||
307 | * The initialization callback. Here we determine the IDE chip type | ||
308 | * and initialize its drive independent registers. | ||
309 | */ | ||
310 | |||
311 | static unsigned int __init init_chipset_amd74xx(struct pci_dev *dev, const char *name) | ||
312 | { | ||
313 | unsigned char t; | ||
314 | unsigned int u; | ||
315 | int i; | ||
316 | |||
317 | /* | ||
318 | * Check for bad SWDMA. | ||
319 | */ | ||
320 | |||
321 | if (amd_config->flags & AMD_CHECK_SWDMA) { | ||
322 | pci_read_config_byte(dev, PCI_REVISION_ID, &t); | ||
323 | if (t <= 7) | ||
324 | amd_config->flags |= AMD_BAD_SWDMA; | ||
325 | } | ||
326 | |||
327 | /* | ||
328 | * Check 80-wire cable presence. | ||
329 | */ | ||
330 | |||
331 | switch (amd_config->flags & AMD_UDMA) { | ||
332 | |||
333 | case AMD_UDMA_133: | ||
334 | case AMD_UDMA_100: | ||
335 | pci_read_config_byte(dev, AMD_CABLE_DETECT, &t); | ||
336 | pci_read_config_dword(dev, AMD_UDMA_TIMING, &u); | ||
337 | amd_80w = ((t & 0x3) ? 1 : 0) | ((t & 0xc) ? 2 : 0); | ||
338 | for (i = 24; i >= 0; i -= 8) | ||
339 | if (((u >> i) & 4) && !(amd_80w & (1 << (1 - (i >> 4))))) { | ||
340 | printk(KERN_WARNING "%s: BIOS didn't set cable bits correctly. Enabling workaround.\n", | ||
341 | amd_chipset->name); | ||
342 | amd_80w |= (1 << (1 - (i >> 4))); | ||
343 | } | ||
344 | break; | ||
345 | |||
346 | case AMD_UDMA_66: | ||
347 | pci_read_config_dword(dev, AMD_UDMA_TIMING, &u); | ||
348 | for (i = 24; i >= 0; i -= 8) | ||
349 | if ((u >> i) & 4) | ||
350 | amd_80w |= (1 << (1 - (i >> 4))); | ||
351 | break; | ||
352 | } | ||
353 | |||
354 | /* | ||
355 | * Take care of prefetch & postwrite. | ||
356 | */ | ||
357 | |||
358 | pci_read_config_byte(dev, AMD_IDE_CONFIG, &t); | ||
359 | pci_write_config_byte(dev, AMD_IDE_CONFIG, | ||
360 | (amd_config->flags & AMD_BAD_FIFO) ? (t & 0x0f) : (t | 0xf0)); | ||
361 | |||
362 | /* | ||
363 | * Take care of incorrectly wired Serenade mainboards. | ||
364 | */ | ||
365 | |||
366 | if ((amd_config->flags & AMD_CHECK_SERENADE) && | ||
367 | dev->subsystem_vendor == PCI_VENDOR_ID_AMD && | ||
368 | dev->subsystem_device == PCI_DEVICE_ID_AMD_SERENADE) | ||
369 | amd_config->flags = AMD_UDMA_100; | ||
370 | |||
371 | /* | ||
372 | * Determine the system bus clock. | ||
373 | */ | ||
374 | |||
375 | amd_clock = system_bus_clock() * 1000; | ||
376 | |||
377 | switch (amd_clock) { | ||
378 | case 33000: amd_clock = 33333; break; | ||
379 | case 37000: amd_clock = 37500; break; | ||
380 | case 41000: amd_clock = 41666; break; | ||
381 | } | ||
382 | |||
383 | if (amd_clock < 20000 || amd_clock > 50000) { | ||
384 | printk(KERN_WARNING "%s: User given PCI clock speed impossible (%d), using 33 MHz instead.\n", | ||
385 | amd_chipset->name, amd_clock); | ||
386 | printk(KERN_WARNING "%s: Use ide0=ata66 if you want to assume 80-wire cable\n", | ||
387 | amd_chipset->name); | ||
388 | amd_clock = 33333; | ||
389 | } | ||
390 | |||
391 | /* | ||
392 | * Print the boot message. | ||
393 | */ | ||
394 | |||
395 | pci_read_config_byte(dev, PCI_REVISION_ID, &t); | ||
396 | printk(KERN_INFO "%s: %s (rev %02x) %s controller\n", | ||
397 | amd_chipset->name, pci_name(dev), t, amd_dma[amd_config->flags & AMD_UDMA]); | ||
398 | |||
399 | /* | ||
400 | * Register /proc/ide/amd74xx entry | ||
401 | */ | ||
402 | |||
403 | #if defined(DISPLAY_AMD_TIMINGS) && defined(CONFIG_PROC_FS) | ||
404 | if (!amd74xx_proc) { | ||
405 | amd_base = pci_resource_start(dev, 4); | ||
406 | bmide_dev = dev; | ||
407 | ide_pci_create_host_proc("amd74xx", amd74xx_get_info); | ||
408 | amd74xx_proc = 1; | ||
409 | } | ||
410 | #endif /* DISPLAY_AMD_TIMINGS && CONFIG_PROC_FS */ | ||
411 | |||
412 | return dev->irq; | ||
413 | } | ||
414 | |||
415 | static void __init init_hwif_amd74xx(ide_hwif_t *hwif) | ||
416 | { | ||
417 | int i; | ||
418 | |||
419 | if (hwif->irq == 0) /* 0 is bogus but will do for now */ | ||
420 | hwif->irq = pci_get_legacy_ide_irq(hwif->pci_dev, hwif->channel); | ||
421 | |||
422 | hwif->autodma = 0; | ||
423 | |||
424 | hwif->tuneproc = &amd74xx_tune_drive; | ||
425 | hwif->speedproc = &amd_set_drive; | ||
426 | |||
427 | for (i = 0; i < 2; i++) { | ||
428 | hwif->drives[i].io_32bit = 1; | ||
429 | hwif->drives[i].unmask = 1; | ||
430 | hwif->drives[i].autotune = 1; | ||
431 | hwif->drives[i].dn = hwif->channel * 2 + i; | ||
432 | } | ||
433 | |||
434 | if (!hwif->dma_base) | ||
435 | return; | ||
436 | |||
437 | hwif->atapi_dma = 1; | ||
438 | hwif->ultra_mask = 0x7f; | ||
439 | hwif->mwdma_mask = 0x07; | ||
440 | hwif->swdma_mask = 0x07; | ||
441 | |||
442 | if (!hwif->udma_four) | ||
443 | hwif->udma_four = (amd_80w >> hwif->channel) & 1; | ||
444 | hwif->ide_dma_check = &amd74xx_ide_dma_check; | ||
445 | if (!noautodma) | ||
446 | hwif->autodma = 1; | ||
447 | hwif->drives[0].autodma = hwif->autodma; | ||
448 | hwif->drives[1].autodma = hwif->autodma; | ||
449 | } | ||
450 | |||
451 | #define DECLARE_AMD_DEV(name_str) \ | ||
452 | { \ | ||
453 | .name = name_str, \ | ||
454 | .init_chipset = init_chipset_amd74xx, \ | ||
455 | .init_hwif = init_hwif_amd74xx, \ | ||
456 | .channels = 2, \ | ||
457 | .autodma = AUTODMA, \ | ||
458 | .enablebits = {{0x40,0x02,0x02}, {0x40,0x01,0x01}}, \ | ||
459 | .bootable = ON_BOARD, \ | ||
460 | } | ||
461 | |||
462 | #define DECLARE_NV_DEV(name_str) \ | ||
463 | { \ | ||
464 | .name = name_str, \ | ||
465 | .init_chipset = init_chipset_amd74xx, \ | ||
466 | .init_hwif = init_hwif_amd74xx, \ | ||
467 | .channels = 2, \ | ||
468 | .autodma = AUTODMA, \ | ||
469 | .enablebits = {{0x50,0x02,0x02}, {0x50,0x01,0x01}}, \ | ||
470 | .bootable = ON_BOARD, \ | ||
471 | } | ||
472 | |||
473 | static ide_pci_device_t amd74xx_chipsets[] __devinitdata = { | ||
474 | /* 0 */ DECLARE_AMD_DEV("AMD7401"), | ||
475 | /* 1 */ DECLARE_AMD_DEV("AMD7409"), | ||
476 | /* 2 */ DECLARE_AMD_DEV("AMD7411"), | ||
477 | /* 3 */ DECLARE_AMD_DEV("AMD7441"), | ||
478 | /* 4 */ DECLARE_AMD_DEV("AMD8111"), | ||
479 | |||
480 | /* 5 */ DECLARE_NV_DEV("NFORCE"), | ||
481 | /* 6 */ DECLARE_NV_DEV("NFORCE2"), | ||
482 | /* 7 */ DECLARE_NV_DEV("NFORCE2-U400R"), | ||
483 | /* 8 */ DECLARE_NV_DEV("NFORCE2-U400R-SATA"), | ||
484 | /* 9 */ DECLARE_NV_DEV("NFORCE3-150"), | ||
485 | /* 10 */ DECLARE_NV_DEV("NFORCE3-250"), | ||
486 | /* 11 */ DECLARE_NV_DEV("NFORCE3-250-SATA"), | ||
487 | /* 12 */ DECLARE_NV_DEV("NFORCE3-250-SATA2"), | ||
488 | /* 13 */ DECLARE_NV_DEV("NFORCE-CK804"), | ||
489 | /* 14 */ DECLARE_NV_DEV("NFORCE-MCP04"), | ||
490 | }; | ||
491 | |||
492 | static int __devinit amd74xx_probe(struct pci_dev *dev, const struct pci_device_id *id) | ||
493 | { | ||
494 | amd_chipset = amd74xx_chipsets + id->driver_data; | ||
495 | amd_config = amd_ide_chips + id->driver_data; | ||
496 | if (dev->device != amd_config->id) { | ||
497 | printk(KERN_ERR "%s: assertion 0x%02x == 0x%02x failed !\n", | ||
498 | pci_name(dev), dev->device, amd_config->id); | ||
499 | return -ENODEV; | ||
500 | } | ||
501 | return ide_setup_pci_device(dev, amd_chipset); | ||
502 | } | ||
503 | |||
504 | static struct pci_device_id amd74xx_pci_tbl[] = { | ||
505 | { PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_COBRA_7401, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, | ||
506 | { PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_VIPER_7409, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 }, | ||
507 | { PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_VIPER_7411, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2 }, | ||
508 | { PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_OPUS_7441, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3 }, | ||
509 | { PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8111_IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4 }, | ||
510 | { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5 }, | ||
511 | { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE2_IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 6 }, | ||
512 | { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE2S_IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 7 }, | ||
513 | #ifdef CONFIG_BLK_DEV_IDE_SATA | ||
514 | { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE2S_SATA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 8 }, | ||
515 | #endif | ||
516 | { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE3_IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 9 }, | ||
517 | { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE3S_IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 10 }, | ||
518 | #ifdef CONFIG_BLK_DEV_IDE_SATA | ||
519 | { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE3S_SATA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 11 }, | ||
520 | { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE3S_SATA2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 12 }, | ||
521 | #endif | ||
522 | { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_CK804_IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 13 }, | ||
523 | { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP04_IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 14 }, | ||
524 | { 0, }, | ||
525 | }; | ||
526 | MODULE_DEVICE_TABLE(pci, amd74xx_pci_tbl); | ||
527 | |||
528 | static struct pci_driver driver = { | ||
529 | .name = "AMD_IDE", | ||
530 | .id_table = amd74xx_pci_tbl, | ||
531 | .probe = amd74xx_probe, | ||
532 | }; | ||
533 | |||
534 | static int amd74xx_ide_init(void) | ||
535 | { | ||
536 | return ide_pci_register_driver(&driver); | ||
537 | } | ||
538 | |||
539 | module_init(amd74xx_ide_init); | ||
540 | |||
541 | MODULE_AUTHOR("Vojtech Pavlik"); | ||
542 | MODULE_DESCRIPTION("AMD PCI IDE driver"); | ||
543 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/ide/pci/atiixp.c b/drivers/ide/pci/atiixp.c new file mode 100644 index 000000000000..df9ee9a78435 --- /dev/null +++ b/drivers/ide/pci/atiixp.c | |||
@@ -0,0 +1,370 @@ | |||
1 | /* | ||
2 | * linux/drivers/ide/pci/atiixp.c Version 0.01-bart2 Feb. 26, 2004 | ||
3 | * | ||
4 | * Copyright (C) 2003 ATI Inc. <hyu@ati.com> | ||
5 | * Copyright (C) 2004 Bartlomiej Zolnierkiewicz | ||
6 | * | ||
7 | */ | ||
8 | |||
9 | #include <linux/config.h> | ||
10 | #include <linux/types.h> | ||
11 | #include <linux/module.h> | ||
12 | #include <linux/kernel.h> | ||
13 | #include <linux/ioport.h> | ||
14 | #include <linux/pci.h> | ||
15 | #include <linux/hdreg.h> | ||
16 | #include <linux/ide.h> | ||
17 | #include <linux/delay.h> | ||
18 | #include <linux/init.h> | ||
19 | |||
20 | #include <asm/io.h> | ||
21 | |||
22 | #define ATIIXP_IDE_PIO_TIMING 0x40 | ||
23 | #define ATIIXP_IDE_MDMA_TIMING 0x44 | ||
24 | #define ATIIXP_IDE_PIO_CONTROL 0x48 | ||
25 | #define ATIIXP_IDE_PIO_MODE 0x4a | ||
26 | #define ATIIXP_IDE_UDMA_CONTROL 0x54 | ||
27 | #define ATIIXP_IDE_UDMA_MODE 0x56 | ||
28 | |||
29 | typedef struct { | ||
30 | u8 command_width; | ||
31 | u8 recover_width; | ||
32 | } atiixp_ide_timing; | ||
33 | |||
34 | static atiixp_ide_timing pio_timing[] = { | ||
35 | { 0x05, 0x0d }, | ||
36 | { 0x04, 0x07 }, | ||
37 | { 0x03, 0x04 }, | ||
38 | { 0x02, 0x02 }, | ||
39 | { 0x02, 0x00 }, | ||
40 | }; | ||
41 | |||
42 | static atiixp_ide_timing mdma_timing[] = { | ||
43 | { 0x07, 0x07 }, | ||
44 | { 0x02, 0x01 }, | ||
45 | { 0x02, 0x00 }, | ||
46 | }; | ||
47 | |||
48 | static int save_mdma_mode[4]; | ||
49 | |||
50 | /** | ||
51 | * atiixp_ratemask - compute rate mask for ATIIXP IDE | ||
52 | * @drive: IDE drive to compute for | ||
53 | * | ||
54 | * Returns the available modes for the ATIIXP IDE controller. | ||
55 | */ | ||
56 | |||
57 | static u8 atiixp_ratemask(ide_drive_t *drive) | ||
58 | { | ||
59 | u8 mode = 3; | ||
60 | |||
61 | if (!eighty_ninty_three(drive)) | ||
62 | mode = min(mode, (u8)1); | ||
63 | return mode; | ||
64 | } | ||
65 | |||
66 | /** | ||
67 | * atiixp_dma_2_pio - return the PIO mode matching DMA | ||
68 | * @xfer_rate: transfer speed | ||
69 | * | ||
70 | * Returns the nearest equivalent PIO timing for the PIO or DMA | ||
71 | * mode requested by the controller. | ||
72 | */ | ||
73 | |||
74 | static u8 atiixp_dma_2_pio(u8 xfer_rate) { | ||
75 | switch(xfer_rate) { | ||
76 | case XFER_UDMA_6: | ||
77 | case XFER_UDMA_5: | ||
78 | case XFER_UDMA_4: | ||
79 | case XFER_UDMA_3: | ||
80 | case XFER_UDMA_2: | ||
81 | case XFER_UDMA_1: | ||
82 | case XFER_UDMA_0: | ||
83 | case XFER_MW_DMA_2: | ||
84 | case XFER_PIO_4: | ||
85 | return 4; | ||
86 | case XFER_MW_DMA_1: | ||
87 | case XFER_PIO_3: | ||
88 | return 3; | ||
89 | case XFER_SW_DMA_2: | ||
90 | case XFER_PIO_2: | ||
91 | return 2; | ||
92 | case XFER_MW_DMA_0: | ||
93 | case XFER_SW_DMA_1: | ||
94 | case XFER_SW_DMA_0: | ||
95 | case XFER_PIO_1: | ||
96 | case XFER_PIO_0: | ||
97 | case XFER_PIO_SLOW: | ||
98 | default: | ||
99 | return 0; | ||
100 | } | ||
101 | } | ||
102 | |||
103 | static int atiixp_ide_dma_host_on(ide_drive_t *drive) | ||
104 | { | ||
105 | struct pci_dev *dev = drive->hwif->pci_dev; | ||
106 | unsigned long flags; | ||
107 | u16 tmp16; | ||
108 | |||
109 | spin_lock_irqsave(&ide_lock, flags); | ||
110 | |||
111 | pci_read_config_word(dev, ATIIXP_IDE_UDMA_CONTROL, &tmp16); | ||
112 | if (save_mdma_mode[drive->dn]) | ||
113 | tmp16 &= ~(1 << drive->dn); | ||
114 | else | ||
115 | tmp16 |= (1 << drive->dn); | ||
116 | pci_write_config_word(dev, ATIIXP_IDE_UDMA_CONTROL, tmp16); | ||
117 | |||
118 | spin_unlock_irqrestore(&ide_lock, flags); | ||
119 | |||
120 | return __ide_dma_host_on(drive); | ||
121 | } | ||
122 | |||
123 | static int atiixp_ide_dma_host_off(ide_drive_t *drive) | ||
124 | { | ||
125 | struct pci_dev *dev = drive->hwif->pci_dev; | ||
126 | unsigned long flags; | ||
127 | u16 tmp16; | ||
128 | |||
129 | spin_lock_irqsave(&ide_lock, flags); | ||
130 | |||
131 | pci_read_config_word(dev, ATIIXP_IDE_UDMA_CONTROL, &tmp16); | ||
132 | tmp16 &= ~(1 << drive->dn); | ||
133 | pci_write_config_word(dev, ATIIXP_IDE_UDMA_CONTROL, tmp16); | ||
134 | |||
135 | spin_unlock_irqrestore(&ide_lock, flags); | ||
136 | |||
137 | return __ide_dma_host_off(drive); | ||
138 | } | ||
139 | |||
140 | /** | ||
141 | * atiixp_tune_drive - tune a drive attached to a ATIIXP | ||
142 | * @drive: drive to tune | ||
143 | * @pio: desired PIO mode | ||
144 | * | ||
145 | * Set the interface PIO mode. | ||
146 | */ | ||
147 | |||
148 | static void atiixp_tuneproc(ide_drive_t *drive, u8 pio) | ||
149 | { | ||
150 | struct pci_dev *dev = drive->hwif->pci_dev; | ||
151 | unsigned long flags; | ||
152 | int timing_shift = (drive->dn & 2) ? 16 : 0 + (drive->dn & 1) ? 0 : 8; | ||
153 | u32 pio_timing_data; | ||
154 | u16 pio_mode_data; | ||
155 | |||
156 | spin_lock_irqsave(&ide_lock, flags); | ||
157 | |||
158 | pci_read_config_word(dev, ATIIXP_IDE_PIO_MODE, &pio_mode_data); | ||
159 | pio_mode_data &= ~(0x07 << (drive->dn * 4)); | ||
160 | pio_mode_data |= (pio << (drive->dn * 4)); | ||
161 | pci_write_config_word(dev, ATIIXP_IDE_PIO_MODE, pio_mode_data); | ||
162 | |||
163 | pci_read_config_dword(dev, ATIIXP_IDE_PIO_TIMING, &pio_timing_data); | ||
164 | pio_timing_data &= ~(0xff << timing_shift); | ||
165 | pio_timing_data |= (pio_timing[pio].recover_width << timing_shift) | | ||
166 | (pio_timing[pio].command_width << (timing_shift + 4)); | ||
167 | pci_write_config_dword(dev, ATIIXP_IDE_PIO_TIMING, pio_timing_data); | ||
168 | |||
169 | spin_unlock_irqrestore(&ide_lock, flags); | ||
170 | } | ||
171 | |||
172 | /** | ||
173 | * atiixp_tune_chipset - tune a ATIIXP interface | ||
174 | * @drive: IDE drive to tune | ||
175 | * @xferspeed: speed to configure | ||
176 | * | ||
177 | * Set a ATIIXP interface channel to the desired speeds. This involves | ||
178 | * requires the right timing data into the ATIIXP configuration space | ||
179 | * then setting the drive parameters appropriately | ||
180 | */ | ||
181 | |||
182 | static int atiixp_speedproc(ide_drive_t *drive, u8 xferspeed) | ||
183 | { | ||
184 | struct pci_dev *dev = drive->hwif->pci_dev; | ||
185 | unsigned long flags; | ||
186 | int timing_shift = (drive->dn & 2) ? 16 : 0 + (drive->dn & 1) ? 0 : 8; | ||
187 | u32 tmp32; | ||
188 | u16 tmp16; | ||
189 | u8 speed, pio; | ||
190 | |||
191 | speed = ide_rate_filter(atiixp_ratemask(drive), xferspeed); | ||
192 | |||
193 | spin_lock_irqsave(&ide_lock, flags); | ||
194 | |||
195 | save_mdma_mode[drive->dn] = 0; | ||
196 | if (speed >= XFER_UDMA_0) { | ||
197 | pci_read_config_word(dev, ATIIXP_IDE_UDMA_MODE, &tmp16); | ||
198 | tmp16 &= ~(0x07 << (drive->dn * 4)); | ||
199 | tmp16 |= ((speed & 0x07) << (drive->dn * 4)); | ||
200 | pci_write_config_word(dev, ATIIXP_IDE_UDMA_MODE, tmp16); | ||
201 | } else { | ||
202 | if ((speed >= XFER_MW_DMA_0) && (speed <= XFER_MW_DMA_2)) { | ||
203 | save_mdma_mode[drive->dn] = speed; | ||
204 | pci_read_config_dword(dev, ATIIXP_IDE_MDMA_TIMING, &tmp32); | ||
205 | tmp32 &= ~(0xff << timing_shift); | ||
206 | tmp32 |= (mdma_timing[speed & 0x03].recover_width << timing_shift) | | ||
207 | (mdma_timing[speed & 0x03].command_width << (timing_shift + 4)); | ||
208 | pci_write_config_dword(dev, ATIIXP_IDE_MDMA_TIMING, tmp32); | ||
209 | } | ||
210 | } | ||
211 | |||
212 | spin_unlock_irqrestore(&ide_lock, flags); | ||
213 | |||
214 | if (speed >= XFER_SW_DMA_0) | ||
215 | pio = atiixp_dma_2_pio(speed); | ||
216 | else | ||
217 | pio = speed - XFER_PIO_0; | ||
218 | |||
219 | atiixp_tuneproc(drive, pio); | ||
220 | |||
221 | return ide_config_drive_speed(drive, speed); | ||
222 | } | ||
223 | |||
224 | /** | ||
225 | * atiixp_config_drive_for_dma - configure drive for DMA | ||
226 | * @drive: IDE drive to configure | ||
227 | * | ||
228 | * Set up a ATIIXP interface channel for the best available speed. | ||
229 | * We prefer UDMA if it is available and then MWDMA. If DMA is | ||
230 | * not available we switch to PIO and return 0. | ||
231 | */ | ||
232 | |||
233 | static int atiixp_config_drive_for_dma(ide_drive_t *drive) | ||
234 | { | ||
235 | u8 speed = ide_dma_speed(drive, atiixp_ratemask(drive)); | ||
236 | |||
237 | /* If no DMA speed was available then disable DMA and use PIO. */ | ||
238 | if (!speed) { | ||
239 | u8 tspeed = ide_get_best_pio_mode(drive, 255, 5, NULL); | ||
240 | speed = atiixp_dma_2_pio(XFER_PIO_0 + tspeed) + XFER_PIO_0; | ||
241 | } | ||
242 | |||
243 | (void) atiixp_speedproc(drive, speed); | ||
244 | return ide_dma_enable(drive); | ||
245 | } | ||
246 | |||
247 | /** | ||
248 | * atiixp_dma_check - set up an IDE device | ||
249 | * @drive: IDE drive to configure | ||
250 | * | ||
251 | * Set up the ATIIXP interface for the best available speed on this | ||
252 | * interface, preferring DMA to PIO. | ||
253 | */ | ||
254 | |||
255 | static int atiixp_dma_check(ide_drive_t *drive) | ||
256 | { | ||
257 | ide_hwif_t *hwif = HWIF(drive); | ||
258 | struct hd_driveid *id = drive->id; | ||
259 | u8 tspeed, speed; | ||
260 | |||
261 | drive->init_speed = 0; | ||
262 | |||
263 | if ((id->capability & 1) && drive->autodma) { | ||
264 | |||
265 | if (ide_use_dma(drive)) { | ||
266 | if (atiixp_config_drive_for_dma(drive)) | ||
267 | return hwif->ide_dma_on(drive); | ||
268 | } | ||
269 | |||
270 | goto fast_ata_pio; | ||
271 | |||
272 | } else if ((id->capability & 8) || (id->field_valid & 2)) { | ||
273 | fast_ata_pio: | ||
274 | tspeed = ide_get_best_pio_mode(drive, 255, 5, NULL); | ||
275 | speed = atiixp_dma_2_pio(XFER_PIO_0 + tspeed) + XFER_PIO_0; | ||
276 | hwif->speedproc(drive, speed); | ||
277 | return hwif->ide_dma_off_quietly(drive); | ||
278 | } | ||
279 | /* IORDY not supported */ | ||
280 | return 0; | ||
281 | } | ||
282 | |||
283 | /** | ||
284 | * init_hwif_atiixp - fill in the hwif for the ATIIXP | ||
285 | * @hwif: IDE interface | ||
286 | * | ||
287 | * Set up the ide_hwif_t for the ATIIXP interface according to the | ||
288 | * capabilities of the hardware. | ||
289 | */ | ||
290 | |||
291 | static void __devinit init_hwif_atiixp(ide_hwif_t *hwif) | ||
292 | { | ||
293 | if (!hwif->irq) | ||
294 | hwif->irq = hwif->channel ? 15 : 14; | ||
295 | |||
296 | hwif->autodma = 0; | ||
297 | hwif->tuneproc = &atiixp_tuneproc; | ||
298 | hwif->speedproc = &atiixp_speedproc; | ||
299 | hwif->drives[0].autotune = 1; | ||
300 | hwif->drives[1].autotune = 1; | ||
301 | |||
302 | if (!hwif->dma_base) | ||
303 | return; | ||
304 | |||
305 | hwif->atapi_dma = 1; | ||
306 | hwif->ultra_mask = 0x3f; | ||
307 | hwif->mwdma_mask = 0x06; | ||
308 | hwif->swdma_mask = 0x04; | ||
309 | |||
310 | /* FIXME: proper cable detection needed */ | ||
311 | hwif->udma_four = 1; | ||
312 | hwif->ide_dma_host_on = &atiixp_ide_dma_host_on; | ||
313 | hwif->ide_dma_host_off = &atiixp_ide_dma_host_off; | ||
314 | hwif->ide_dma_check = &atiixp_dma_check; | ||
315 | if (!noautodma) | ||
316 | hwif->autodma = 1; | ||
317 | |||
318 | hwif->drives[1].autodma = hwif->autodma; | ||
319 | hwif->drives[0].autodma = hwif->autodma; | ||
320 | } | ||
321 | |||
322 | static ide_pci_device_t atiixp_pci_info[] __devinitdata = { | ||
323 | { /* 0 */ | ||
324 | .name = "ATIIXP", | ||
325 | .init_hwif = init_hwif_atiixp, | ||
326 | .channels = 2, | ||
327 | .autodma = AUTODMA, | ||
328 | .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}}, | ||
329 | .bootable = ON_BOARD, | ||
330 | } | ||
331 | }; | ||
332 | |||
333 | /** | ||
334 | * atiixp_init_one - called when a ATIIXP is found | ||
335 | * @dev: the atiixp device | ||
336 | * @id: the matching pci id | ||
337 | * | ||
338 | * Called when the PCI registration layer (or the IDE initialization) | ||
339 | * finds a device matching our IDE device tables. | ||
340 | */ | ||
341 | |||
342 | static int __devinit atiixp_init_one(struct pci_dev *dev, const struct pci_device_id *id) | ||
343 | { | ||
344 | return ide_setup_pci_device(dev, &atiixp_pci_info[id->driver_data]); | ||
345 | } | ||
346 | |||
347 | static struct pci_device_id atiixp_pci_tbl[] = { | ||
348 | { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP200_IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, | ||
349 | { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP300_IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, | ||
350 | { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP400_IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, | ||
351 | { 0, }, | ||
352 | }; | ||
353 | MODULE_DEVICE_TABLE(pci, atiixp_pci_tbl); | ||
354 | |||
355 | static struct pci_driver driver = { | ||
356 | .name = "ATIIXP_IDE", | ||
357 | .id_table = atiixp_pci_tbl, | ||
358 | .probe = atiixp_init_one, | ||
359 | }; | ||
360 | |||
361 | static int atiixp_ide_init(void) | ||
362 | { | ||
363 | return ide_pci_register_driver(&driver); | ||
364 | } | ||
365 | |||
366 | module_init(atiixp_ide_init); | ||
367 | |||
368 | MODULE_AUTHOR("HUI YU"); | ||
369 | MODULE_DESCRIPTION("PCI driver module for ATI IXP IDE"); | ||
370 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/ide/pci/cmd640.c b/drivers/ide/pci/cmd640.c new file mode 100644 index 000000000000..92a2b7caed58 --- /dev/null +++ b/drivers/ide/pci/cmd640.c | |||
@@ -0,0 +1,879 @@ | |||
1 | /* | ||
2 | * linux/drivers/ide/pci/cmd640.c Version 1.02 Sep 01, 1996 | ||
3 | * | ||
4 | * Copyright (C) 1995-1996 Linus Torvalds & authors (see below) | ||
5 | */ | ||
6 | |||
7 | /* | ||
8 | * Original authors: abramov@cecmow.enet.dec.com (Igor Abramov) | ||
9 | * mlord@pobox.com (Mark Lord) | ||
10 | * | ||
11 | * See linux/MAINTAINERS for address of current maintainer. | ||
12 | * | ||
13 | * This file provides support for the advanced features and bugs | ||
14 | * of IDE interfaces using the CMD Technologies 0640 IDE interface chip. | ||
15 | * | ||
16 | * These chips are basically fucked by design, and getting this driver | ||
17 | * to work on every motherboard design that uses this screwed chip seems | ||
18 | * bloody well impossible. However, we're still trying. | ||
19 | * | ||
20 | * Version 0.97 worked for everybody. | ||
21 | * | ||
22 | * User feedback is essential. Many thanks to the beta test team: | ||
23 | * | ||
24 | * A.Hartgers@stud.tue.nl, JZDQC@CUNYVM.CUNY.edu, abramov@cecmow.enet.dec.com, | ||
25 | * bardj@utopia.ppp.sn.no, bart@gaga.tue.nl, bbol001@cs.auckland.ac.nz, | ||
26 | * chrisc@dbass.demon.co.uk, dalecki@namu26.Num.Math.Uni-Goettingen.de, | ||
27 | * derekn@vw.ece.cmu.edu, florian@btp2x3.phy.uni-bayreuth.de, | ||
28 | * flynn@dei.unipd.it, gadio@netvision.net.il, godzilla@futuris.net, | ||
29 | * j@pobox.com, jkemp1@mises.uni-paderborn.de, jtoppe@hiwaay.net, | ||
30 | * kerouac@ssnet.com, meskes@informatik.rwth-aachen.de, hzoli@cs.elte.hu, | ||
31 | * peter@udgaard.isgtec.com, phil@tazenda.demon.co.uk, roadcapw@cfw.com, | ||
32 | * s0033las@sun10.vsz.bme.hu, schaffer@tam.cornell.edu, sjd@slip.net, | ||
33 | * steve@ei.org, ulrpeg@bigcomm.gun.de, ism@tardis.ed.ac.uk, mack@cray.com | ||
34 | * liug@mama.indstate.edu, and others. | ||
35 | * | ||
36 | * Version 0.01 Initial version, hacked out of ide.c, | ||
37 | * and #include'd rather than compiled separately. | ||
38 | * This will get cleaned up in a subsequent release. | ||
39 | * | ||
40 | * Version 0.02 Fixes for vlb initialization code, enable prefetch | ||
41 | * for versions 'B' and 'C' of chip by default, | ||
42 | * some code cleanup. | ||
43 | * | ||
44 | * Version 0.03 Added reset of secondary interface, | ||
45 | * and black list for devices which are not compatible | ||
46 | * with prefetch mode. Separate function for setting | ||
47 | * prefetch is added, possibly it will be called some | ||
48 | * day from ioctl processing code. | ||
49 | * | ||
50 | * Version 0.04 Now configs/compiles separate from ide.c | ||
51 | * | ||
52 | * Version 0.05 Major rewrite of interface timing code. | ||
53 | * Added new function cmd640_set_mode to set PIO mode | ||
54 | * from ioctl call. New drives added to black list. | ||
55 | * | ||
56 | * Version 0.06 More code cleanup. Prefetch is enabled only for | ||
57 | * detected hard drives, not included in prefetch | ||
58 | * black list. | ||
59 | * | ||
60 | * Version 0.07 Changed to more conservative drive tuning policy. | ||
61 | * Unknown drives, which report PIO < 4 are set to | ||
62 | * (reported_PIO - 1) if it is supported, or to PIO0. | ||
63 | * List of known drives extended by info provided by | ||
64 | * CMD at their ftp site. | ||
65 | * | ||
66 | * Version 0.08 Added autotune/noautotune support. | ||
67 | * | ||
68 | * Version 0.09 Try to be smarter about 2nd port enabling. | ||
69 | * Version 0.10 Be nice and don't reset 2nd port. | ||
70 | * Version 0.11 Try to handle more weird situations. | ||
71 | * | ||
72 | * Version 0.12 Lots of bug fixes from Laszlo Peter | ||
73 | * irq unmasking disabled for reliability. | ||
74 | * try to be even smarter about the second port. | ||
75 | * tidy up source code formatting. | ||
76 | * Version 0.13 permit irq unmasking again. | ||
77 | * Version 0.90 massive code cleanup, some bugs fixed. | ||
78 | * defaults all drives to PIO mode0, prefetch off. | ||
79 | * autotune is OFF by default, with compile time flag. | ||
80 | * prefetch can be turned OFF/ON using "hdparm -p8/-p9" | ||
81 | * (requires hdparm-3.1 or newer) | ||
82 | * Version 0.91 first release to linux-kernel list. | ||
83 | * Version 0.92 move initial reg dump to separate callable function | ||
84 | * change "readahead" to "prefetch" to avoid confusion | ||
85 | * Version 0.95 respect original BIOS timings unless autotuning. | ||
86 | * tons of code cleanup and rearrangement. | ||
87 | * added CONFIG_BLK_DEV_CMD640_ENHANCED option | ||
88 | * prevent use of unmask when prefetch is on | ||
89 | * Version 0.96 prevent use of io_32bit when prefetch is off | ||
90 | * Version 0.97 fix VLB secondary interface for sjd@slip.net | ||
91 | * other minor tune-ups: 0.96 was very good. | ||
92 | * Version 0.98 ignore PCI version when disabled by BIOS | ||
93 | * Version 0.99 display setup/active/recovery clocks with PIO mode | ||
94 | * Version 1.00 Mmm.. cannot depend on PCMD_ENA in all systems | ||
95 | * Version 1.01 slow/fast devsel can be selected with "hdparm -p6/-p7" | ||
96 | * ("fast" is necessary for 32bit I/O in some systems) | ||
97 | * Version 1.02 fix bug that resulted in slow "setup times" | ||
98 | * (patch courtesy of Zoltan Hidvegi) | ||
99 | */ | ||
100 | |||
101 | #undef REALLY_SLOW_IO /* most systems can safely undef this */ | ||
102 | #define CMD640_PREFETCH_MASKS 1 | ||
103 | |||
104 | //#define CMD640_DUMP_REGS | ||
105 | |||
106 | #include <linux/config.h> | ||
107 | #include <linux/types.h> | ||
108 | #include <linux/kernel.h> | ||
109 | #include <linux/delay.h> | ||
110 | #include <linux/timer.h> | ||
111 | #include <linux/mm.h> | ||
112 | #include <linux/ioport.h> | ||
113 | #include <linux/blkdev.h> | ||
114 | #include <linux/hdreg.h> | ||
115 | #include <linux/ide.h> | ||
116 | #include <linux/init.h> | ||
117 | |||
118 | #include <asm/io.h> | ||
119 | |||
120 | /* | ||
121 | * This flag is set in ide.c by the parameter: ide0=cmd640_vlb | ||
122 | */ | ||
123 | int cmd640_vlb = 0; | ||
124 | |||
125 | /* | ||
126 | * CMD640 specific registers definition. | ||
127 | */ | ||
128 | |||
129 | #define VID 0x00 | ||
130 | #define DID 0x02 | ||
131 | #define PCMD 0x04 | ||
132 | #define PCMD_ENA 0x01 | ||
133 | #define PSTTS 0x06 | ||
134 | #define REVID 0x08 | ||
135 | #define PROGIF 0x09 | ||
136 | #define SUBCL 0x0a | ||
137 | #define BASCL 0x0b | ||
138 | #define BaseA0 0x10 | ||
139 | #define BaseA1 0x14 | ||
140 | #define BaseA2 0x18 | ||
141 | #define BaseA3 0x1c | ||
142 | #define INTLINE 0x3c | ||
143 | #define INPINE 0x3d | ||
144 | |||
145 | #define CFR 0x50 | ||
146 | #define CFR_DEVREV 0x03 | ||
147 | #define CFR_IDE01INTR 0x04 | ||
148 | #define CFR_DEVID 0x18 | ||
149 | #define CFR_AT_VESA_078h 0x20 | ||
150 | #define CFR_DSA1 0x40 | ||
151 | #define CFR_DSA0 0x80 | ||
152 | |||
153 | #define CNTRL 0x51 | ||
154 | #define CNTRL_DIS_RA0 0x40 | ||
155 | #define CNTRL_DIS_RA1 0x80 | ||
156 | #define CNTRL_ENA_2ND 0x08 | ||
157 | |||
158 | #define CMDTIM 0x52 | ||
159 | #define ARTTIM0 0x53 | ||
160 | #define DRWTIM0 0x54 | ||
161 | #define ARTTIM1 0x55 | ||
162 | #define DRWTIM1 0x56 | ||
163 | #define ARTTIM23 0x57 | ||
164 | #define ARTTIM23_DIS_RA2 0x04 | ||
165 | #define ARTTIM23_DIS_RA3 0x08 | ||
166 | #define DRWTIM23 0x58 | ||
167 | #define BRST 0x59 | ||
168 | |||
169 | /* | ||
170 | * Registers and masks for easy access by drive index: | ||
171 | */ | ||
172 | static u8 prefetch_regs[4] = {CNTRL, CNTRL, ARTTIM23, ARTTIM23}; | ||
173 | static u8 prefetch_masks[4] = {CNTRL_DIS_RA0, CNTRL_DIS_RA1, ARTTIM23_DIS_RA2, ARTTIM23_DIS_RA3}; | ||
174 | |||
175 | #ifdef CONFIG_BLK_DEV_CMD640_ENHANCED | ||
176 | |||
177 | static u8 arttim_regs[4] = {ARTTIM0, ARTTIM1, ARTTIM23, ARTTIM23}; | ||
178 | static u8 drwtim_regs[4] = {DRWTIM0, DRWTIM1, DRWTIM23, DRWTIM23}; | ||
179 | |||
180 | /* | ||
181 | * Current cmd640 timing values for each drive. | ||
182 | * The defaults for each are the slowest possible timings. | ||
183 | */ | ||
184 | static u8 setup_counts[4] = {4, 4, 4, 4}; /* Address setup count (in clocks) */ | ||
185 | static u8 active_counts[4] = {16, 16, 16, 16}; /* Active count (encoded) */ | ||
186 | static u8 recovery_counts[4] = {16, 16, 16, 16}; /* Recovery count (encoded) */ | ||
187 | |||
188 | #endif /* CONFIG_BLK_DEV_CMD640_ENHANCED */ | ||
189 | |||
190 | /* | ||
191 | * These are initialized to point at the devices we control | ||
192 | */ | ||
193 | static ide_hwif_t *cmd_hwif0, *cmd_hwif1; | ||
194 | static ide_drive_t *cmd_drives[4]; | ||
195 | |||
196 | /* | ||
197 | * Interface to access cmd640x registers | ||
198 | */ | ||
199 | static unsigned int cmd640_key; | ||
200 | static void (*__put_cmd640_reg)(u16 reg, u8 val); | ||
201 | static u8 (*__get_cmd640_reg)(u16 reg); | ||
202 | |||
203 | /* | ||
204 | * This is read from the CFR reg, and is used in several places. | ||
205 | */ | ||
206 | static unsigned int cmd640_chip_version; | ||
207 | |||
208 | /* | ||
209 | * The CMD640x chip does not support DWORD config write cycles, but some | ||
210 | * of the BIOSes use them to implement the config services. | ||
211 | * Therefore, we must use direct IO instead. | ||
212 | */ | ||
213 | |||
214 | /* PCI method 1 access */ | ||
215 | |||
216 | static void put_cmd640_reg_pci1 (u16 reg, u8 val) | ||
217 | { | ||
218 | outl_p((reg & 0xfc) | cmd640_key, 0xcf8); | ||
219 | outb_p(val, (reg & 3) | 0xcfc); | ||
220 | } | ||
221 | |||
222 | static u8 get_cmd640_reg_pci1 (u16 reg) | ||
223 | { | ||
224 | outl_p((reg & 0xfc) | cmd640_key, 0xcf8); | ||
225 | return inb_p((reg & 3) | 0xcfc); | ||
226 | } | ||
227 | |||
228 | /* PCI method 2 access (from CMD datasheet) */ | ||
229 | |||
230 | static void put_cmd640_reg_pci2 (u16 reg, u8 val) | ||
231 | { | ||
232 | outb_p(0x10, 0xcf8); | ||
233 | outb_p(val, cmd640_key + reg); | ||
234 | outb_p(0, 0xcf8); | ||
235 | } | ||
236 | |||
237 | static u8 get_cmd640_reg_pci2 (u16 reg) | ||
238 | { | ||
239 | u8 b; | ||
240 | |||
241 | outb_p(0x10, 0xcf8); | ||
242 | b = inb_p(cmd640_key + reg); | ||
243 | outb_p(0, 0xcf8); | ||
244 | return b; | ||
245 | } | ||
246 | |||
247 | /* VLB access */ | ||
248 | |||
249 | static void put_cmd640_reg_vlb (u16 reg, u8 val) | ||
250 | { | ||
251 | outb_p(reg, cmd640_key); | ||
252 | outb_p(val, cmd640_key + 4); | ||
253 | } | ||
254 | |||
255 | static u8 get_cmd640_reg_vlb (u16 reg) | ||
256 | { | ||
257 | outb_p(reg, cmd640_key); | ||
258 | return inb_p(cmd640_key + 4); | ||
259 | } | ||
260 | |||
261 | static u8 get_cmd640_reg(u16 reg) | ||
262 | { | ||
263 | u8 b; | ||
264 | unsigned long flags; | ||
265 | |||
266 | spin_lock_irqsave(&ide_lock, flags); | ||
267 | b = __get_cmd640_reg(reg); | ||
268 | spin_unlock_irqrestore(&ide_lock, flags); | ||
269 | return b; | ||
270 | } | ||
271 | |||
272 | static void put_cmd640_reg(u16 reg, u8 val) | ||
273 | { | ||
274 | unsigned long flags; | ||
275 | |||
276 | spin_lock_irqsave(&ide_lock, flags); | ||
277 | __put_cmd640_reg(reg,val); | ||
278 | spin_unlock_irqrestore(&ide_lock, flags); | ||
279 | } | ||
280 | |||
281 | static int __init match_pci_cmd640_device (void) | ||
282 | { | ||
283 | const u8 ven_dev[4] = {0x95, 0x10, 0x40, 0x06}; | ||
284 | unsigned int i; | ||
285 | for (i = 0; i < 4; i++) { | ||
286 | if (get_cmd640_reg(i) != ven_dev[i]) | ||
287 | return 0; | ||
288 | } | ||
289 | #ifdef STUPIDLY_TRUST_BROKEN_PCMD_ENA_BIT | ||
290 | if ((get_cmd640_reg(PCMD) & PCMD_ENA) == 0) { | ||
291 | printk("ide: cmd640 on PCI disabled by BIOS\n"); | ||
292 | return 0; | ||
293 | } | ||
294 | #endif /* STUPIDLY_TRUST_BROKEN_PCMD_ENA_BIT */ | ||
295 | return 1; /* success */ | ||
296 | } | ||
297 | |||
298 | /* | ||
299 | * Probe for CMD640x -- pci method 1 | ||
300 | */ | ||
301 | static int __init probe_for_cmd640_pci1 (void) | ||
302 | { | ||
303 | __get_cmd640_reg = get_cmd640_reg_pci1; | ||
304 | __put_cmd640_reg = put_cmd640_reg_pci1; | ||
305 | for (cmd640_key = 0x80000000; | ||
306 | cmd640_key <= 0x8000f800; | ||
307 | cmd640_key += 0x800) { | ||
308 | if (match_pci_cmd640_device()) | ||
309 | return 1; /* success */ | ||
310 | } | ||
311 | return 0; | ||
312 | } | ||
313 | |||
314 | /* | ||
315 | * Probe for CMD640x -- pci method 2 | ||
316 | */ | ||
317 | static int __init probe_for_cmd640_pci2 (void) | ||
318 | { | ||
319 | __get_cmd640_reg = get_cmd640_reg_pci2; | ||
320 | __put_cmd640_reg = put_cmd640_reg_pci2; | ||
321 | for (cmd640_key = 0xc000; cmd640_key <= 0xcf00; cmd640_key += 0x100) { | ||
322 | if (match_pci_cmd640_device()) | ||
323 | return 1; /* success */ | ||
324 | } | ||
325 | return 0; | ||
326 | } | ||
327 | |||
328 | /* | ||
329 | * Probe for CMD640x -- vlb | ||
330 | */ | ||
331 | static int __init probe_for_cmd640_vlb (void) | ||
332 | { | ||
333 | u8 b; | ||
334 | |||
335 | __get_cmd640_reg = get_cmd640_reg_vlb; | ||
336 | __put_cmd640_reg = put_cmd640_reg_vlb; | ||
337 | cmd640_key = 0x178; | ||
338 | b = get_cmd640_reg(CFR); | ||
339 | if (b == 0xff || b == 0x00 || (b & CFR_AT_VESA_078h)) { | ||
340 | cmd640_key = 0x78; | ||
341 | b = get_cmd640_reg(CFR); | ||
342 | if (b == 0xff || b == 0x00 || !(b & CFR_AT_VESA_078h)) | ||
343 | return 0; | ||
344 | } | ||
345 | return 1; /* success */ | ||
346 | } | ||
347 | |||
348 | /* | ||
349 | * Returns 1 if an IDE interface/drive exists at 0x170, | ||
350 | * Returns 0 otherwise. | ||
351 | */ | ||
352 | static int __init secondary_port_responding (void) | ||
353 | { | ||
354 | unsigned long flags; | ||
355 | |||
356 | spin_lock_irqsave(&ide_lock, flags); | ||
357 | |||
358 | outb_p(0x0a, 0x170 + IDE_SELECT_OFFSET); /* select drive0 */ | ||
359 | udelay(100); | ||
360 | if ((inb_p(0x170 + IDE_SELECT_OFFSET) & 0x1f) != 0x0a) { | ||
361 | outb_p(0x1a, 0x170 + IDE_SELECT_OFFSET); /* select drive1 */ | ||
362 | udelay(100); | ||
363 | if ((inb_p(0x170 + IDE_SELECT_OFFSET) & 0x1f) != 0x1a) { | ||
364 | spin_unlock_irqrestore(&ide_lock, flags); | ||
365 | return 0; /* nothing responded */ | ||
366 | } | ||
367 | } | ||
368 | spin_unlock_irqrestore(&ide_lock, flags); | ||
369 | return 1; /* success */ | ||
370 | } | ||
371 | |||
372 | #ifdef CMD640_DUMP_REGS | ||
373 | /* | ||
374 | * Dump out all cmd640 registers. May be called from ide.c | ||
375 | */ | ||
376 | static void cmd640_dump_regs (void) | ||
377 | { | ||
378 | unsigned int reg = cmd640_vlb ? 0x50 : 0x00; | ||
379 | |||
380 | /* Dump current state of chip registers */ | ||
381 | printk("ide: cmd640 internal register dump:"); | ||
382 | for (; reg <= 0x59; reg++) { | ||
383 | if (!(reg & 0x0f)) | ||
384 | printk("\n%04x:", reg); | ||
385 | printk(" %02x", get_cmd640_reg(reg)); | ||
386 | } | ||
387 | printk("\n"); | ||
388 | } | ||
389 | #endif | ||
390 | |||
391 | /* | ||
392 | * Check whether prefetch is on for a drive, | ||
393 | * and initialize the unmask flags for safe operation. | ||
394 | */ | ||
395 | static void __init check_prefetch (unsigned int index) | ||
396 | { | ||
397 | ide_drive_t *drive = cmd_drives[index]; | ||
398 | u8 b = get_cmd640_reg(prefetch_regs[index]); | ||
399 | |||
400 | if (b & prefetch_masks[index]) { /* is prefetch off? */ | ||
401 | drive->no_unmask = 0; | ||
402 | drive->no_io_32bit = 1; | ||
403 | drive->io_32bit = 0; | ||
404 | } else { | ||
405 | #if CMD640_PREFETCH_MASKS | ||
406 | drive->no_unmask = 1; | ||
407 | drive->unmask = 0; | ||
408 | #endif | ||
409 | drive->no_io_32bit = 0; | ||
410 | } | ||
411 | } | ||
412 | |||
413 | /* | ||
414 | * Figure out which devices we control | ||
415 | */ | ||
416 | static void __init setup_device_ptrs (void) | ||
417 | { | ||
418 | unsigned int i; | ||
419 | |||
420 | cmd_hwif0 = &ide_hwifs[0]; /* default, if not found below */ | ||
421 | cmd_hwif1 = &ide_hwifs[1]; /* default, if not found below */ | ||
422 | for (i = 0; i < MAX_HWIFS; i++) { | ||
423 | ide_hwif_t *hwif = &ide_hwifs[i]; | ||
424 | if (hwif->chipset == ide_unknown || hwif->chipset == ide_forced) { | ||
425 | if (hwif->io_ports[IDE_DATA_OFFSET] == 0x1f0) | ||
426 | cmd_hwif0 = hwif; | ||
427 | else if (hwif->io_ports[IDE_DATA_OFFSET] == 0x170) | ||
428 | cmd_hwif1 = hwif; | ||
429 | } | ||
430 | } | ||
431 | cmd_drives[0] = &cmd_hwif0->drives[0]; | ||
432 | cmd_drives[1] = &cmd_hwif0->drives[1]; | ||
433 | cmd_drives[2] = &cmd_hwif1->drives[0]; | ||
434 | cmd_drives[3] = &cmd_hwif1->drives[1]; | ||
435 | } | ||
436 | |||
437 | #ifdef CONFIG_BLK_DEV_CMD640_ENHANCED | ||
438 | |||
439 | /* | ||
440 | * Sets prefetch mode for a drive. | ||
441 | */ | ||
442 | static void set_prefetch_mode (unsigned int index, int mode) | ||
443 | { | ||
444 | ide_drive_t *drive = cmd_drives[index]; | ||
445 | int reg = prefetch_regs[index]; | ||
446 | u8 b; | ||
447 | unsigned long flags; | ||
448 | |||
449 | spin_lock_irqsave(&ide_lock, flags); | ||
450 | b = __get_cmd640_reg(reg); | ||
451 | if (mode) { /* want prefetch on? */ | ||
452 | #if CMD640_PREFETCH_MASKS | ||
453 | drive->no_unmask = 1; | ||
454 | drive->unmask = 0; | ||
455 | #endif | ||
456 | drive->no_io_32bit = 0; | ||
457 | b &= ~prefetch_masks[index]; /* enable prefetch */ | ||
458 | } else { | ||
459 | drive->no_unmask = 0; | ||
460 | drive->no_io_32bit = 1; | ||
461 | drive->io_32bit = 0; | ||
462 | b |= prefetch_masks[index]; /* disable prefetch */ | ||
463 | } | ||
464 | __put_cmd640_reg(reg, b); | ||
465 | spin_unlock_irqrestore(&ide_lock, flags); | ||
466 | } | ||
467 | |||
468 | /* | ||
469 | * Dump out current drive clocks settings | ||
470 | */ | ||
471 | static void display_clocks (unsigned int index) | ||
472 | { | ||
473 | u8 active_count, recovery_count; | ||
474 | |||
475 | active_count = active_counts[index]; | ||
476 | if (active_count == 1) | ||
477 | ++active_count; | ||
478 | recovery_count = recovery_counts[index]; | ||
479 | if (active_count > 3 && recovery_count == 1) | ||
480 | ++recovery_count; | ||
481 | if (cmd640_chip_version > 1) | ||
482 | recovery_count += 1; /* cmd640b uses (count + 1)*/ | ||
483 | printk(", clocks=%d/%d/%d\n", setup_counts[index], active_count, recovery_count); | ||
484 | } | ||
485 | |||
486 | /* | ||
487 | * Pack active and recovery counts into single byte representation | ||
488 | * used by controller | ||
489 | */ | ||
490 | inline static u8 pack_nibbles (u8 upper, u8 lower) | ||
491 | { | ||
492 | return ((upper & 0x0f) << 4) | (lower & 0x0f); | ||
493 | } | ||
494 | |||
495 | /* | ||
496 | * This routine retrieves the initial drive timings from the chipset. | ||
497 | */ | ||
498 | static void __init retrieve_drive_counts (unsigned int index) | ||
499 | { | ||
500 | u8 b; | ||
501 | |||
502 | /* | ||
503 | * Get the internal setup timing, and convert to clock count | ||
504 | */ | ||
505 | b = get_cmd640_reg(arttim_regs[index]) & ~0x3f; | ||
506 | switch (b) { | ||
507 | case 0x00: b = 4; break; | ||
508 | case 0x80: b = 3; break; | ||
509 | case 0x40: b = 2; break; | ||
510 | default: b = 5; break; | ||
511 | } | ||
512 | setup_counts[index] = b; | ||
513 | |||
514 | /* | ||
515 | * Get the active/recovery counts | ||
516 | */ | ||
517 | b = get_cmd640_reg(drwtim_regs[index]); | ||
518 | active_counts[index] = (b >> 4) ? (b >> 4) : 0x10; | ||
519 | recovery_counts[index] = (b & 0x0f) ? (b & 0x0f) : 0x10; | ||
520 | } | ||
521 | |||
522 | |||
523 | /* | ||
524 | * This routine writes the prepared setup/active/recovery counts | ||
525 | * for a drive into the cmd640 chipset registers to active them. | ||
526 | */ | ||
527 | static void program_drive_counts (unsigned int index) | ||
528 | { | ||
529 | unsigned long flags; | ||
530 | u8 setup_count = setup_counts[index]; | ||
531 | u8 active_count = active_counts[index]; | ||
532 | u8 recovery_count = recovery_counts[index]; | ||
533 | |||
534 | /* | ||
535 | * Set up address setup count and drive read/write timing registers. | ||
536 | * Primary interface has individual count/timing registers for | ||
537 | * each drive. Secondary interface has one common set of registers, | ||
538 | * so we merge the timings, using the slowest value for each timing. | ||
539 | */ | ||
540 | if (index > 1) { | ||
541 | unsigned int mate; | ||
542 | if (cmd_drives[mate = index ^ 1]->present) { | ||
543 | if (setup_count < setup_counts[mate]) | ||
544 | setup_count = setup_counts[mate]; | ||
545 | if (active_count < active_counts[mate]) | ||
546 | active_count = active_counts[mate]; | ||
547 | if (recovery_count < recovery_counts[mate]) | ||
548 | recovery_count = recovery_counts[mate]; | ||
549 | } | ||
550 | } | ||
551 | |||
552 | /* | ||
553 | * Convert setup_count to internal chipset representation | ||
554 | */ | ||
555 | switch (setup_count) { | ||
556 | case 4: setup_count = 0x00; break; | ||
557 | case 3: setup_count = 0x80; break; | ||
558 | case 1: | ||
559 | case 2: setup_count = 0x40; break; | ||
560 | default: setup_count = 0xc0; /* case 5 */ | ||
561 | } | ||
562 | |||
563 | /* | ||
564 | * Now that everything is ready, program the new timings | ||
565 | */ | ||
566 | spin_lock_irqsave(&ide_lock, flags); | ||
567 | /* | ||
568 | * Program the address_setup clocks into ARTTIM reg, | ||
569 | * and then the active/recovery counts into the DRWTIM reg | ||
570 | * (this converts counts of 16 into counts of zero -- okay). | ||
571 | */ | ||
572 | setup_count |= __get_cmd640_reg(arttim_regs[index]) & 0x3f; | ||
573 | __put_cmd640_reg(arttim_regs[index], setup_count); | ||
574 | __put_cmd640_reg(drwtim_regs[index], pack_nibbles(active_count, recovery_count)); | ||
575 | spin_unlock_irqrestore(&ide_lock, flags); | ||
576 | } | ||
577 | |||
578 | /* | ||
579 | * Set a specific pio_mode for a drive | ||
580 | */ | ||
581 | static void cmd640_set_mode (unsigned int index, u8 pio_mode, unsigned int cycle_time) | ||
582 | { | ||
583 | int setup_time, active_time, recovery_time, clock_time; | ||
584 | u8 setup_count, active_count, recovery_count, recovery_count2, cycle_count; | ||
585 | int bus_speed = system_bus_clock(); | ||
586 | |||
587 | if (pio_mode > 5) | ||
588 | pio_mode = 5; | ||
589 | setup_time = ide_pio_timings[pio_mode].setup_time; | ||
590 | active_time = ide_pio_timings[pio_mode].active_time; | ||
591 | recovery_time = cycle_time - (setup_time + active_time); | ||
592 | clock_time = 1000 / bus_speed; | ||
593 | cycle_count = (cycle_time + clock_time - 1) / clock_time; | ||
594 | |||
595 | setup_count = (setup_time + clock_time - 1) / clock_time; | ||
596 | |||
597 | active_count = (active_time + clock_time - 1) / clock_time; | ||
598 | if (active_count < 2) | ||
599 | active_count = 2; /* minimum allowed by cmd640 */ | ||
600 | |||
601 | recovery_count = (recovery_time + clock_time - 1) / clock_time; | ||
602 | recovery_count2 = cycle_count - (setup_count + active_count); | ||
603 | if (recovery_count2 > recovery_count) | ||
604 | recovery_count = recovery_count2; | ||
605 | if (recovery_count < 2) | ||
606 | recovery_count = 2; /* minimum allowed by cmd640 */ | ||
607 | if (recovery_count > 17) { | ||
608 | active_count += recovery_count - 17; | ||
609 | recovery_count = 17; | ||
610 | } | ||
611 | if (active_count > 16) | ||
612 | active_count = 16; /* maximum allowed by cmd640 */ | ||
613 | if (cmd640_chip_version > 1) | ||
614 | recovery_count -= 1; /* cmd640b uses (count + 1)*/ | ||
615 | if (recovery_count > 16) | ||
616 | recovery_count = 16; /* maximum allowed by cmd640 */ | ||
617 | |||
618 | setup_counts[index] = setup_count; | ||
619 | active_counts[index] = active_count; | ||
620 | recovery_counts[index] = recovery_count; | ||
621 | |||
622 | /* | ||
623 | * In a perfect world, we might set the drive pio mode here | ||
624 | * (using WIN_SETFEATURE) before continuing. | ||
625 | * | ||
626 | * But we do not, because: | ||
627 | * 1) this is the wrong place to do it (proper is do_special() in ide.c) | ||
628 | * 2) in practice this is rarely, if ever, necessary | ||
629 | */ | ||
630 | program_drive_counts (index); | ||
631 | } | ||
632 | |||
633 | /* | ||
634 | * Drive PIO mode selection: | ||
635 | */ | ||
636 | static void cmd640_tune_drive (ide_drive_t *drive, u8 mode_wanted) | ||
637 | { | ||
638 | u8 b; | ||
639 | ide_pio_data_t d; | ||
640 | unsigned int index = 0; | ||
641 | |||
642 | while (drive != cmd_drives[index]) { | ||
643 | if (++index > 3) { | ||
644 | printk("%s: bad news in cmd640_tune_drive\n", drive->name); | ||
645 | return; | ||
646 | } | ||
647 | } | ||
648 | switch (mode_wanted) { | ||
649 | case 6: /* set fast-devsel off */ | ||
650 | case 7: /* set fast-devsel on */ | ||
651 | mode_wanted &= 1; | ||
652 | b = get_cmd640_reg(CNTRL) & ~0x27; | ||
653 | if (mode_wanted) | ||
654 | b |= 0x27; | ||
655 | put_cmd640_reg(CNTRL, b); | ||
656 | printk("%s: %sabled cmd640 fast host timing (devsel)\n", drive->name, mode_wanted ? "en" : "dis"); | ||
657 | return; | ||
658 | |||
659 | case 8: /* set prefetch off */ | ||
660 | case 9: /* set prefetch on */ | ||
661 | mode_wanted &= 1; | ||
662 | set_prefetch_mode(index, mode_wanted); | ||
663 | printk("%s: %sabled cmd640 prefetch\n", drive->name, mode_wanted ? "en" : "dis"); | ||
664 | return; | ||
665 | } | ||
666 | |||
667 | (void) ide_get_best_pio_mode (drive, mode_wanted, 5, &d); | ||
668 | cmd640_set_mode (index, d.pio_mode, d.cycle_time); | ||
669 | |||
670 | printk ("%s: selected cmd640 PIO mode%d (%dns)%s", | ||
671 | drive->name, | ||
672 | d.pio_mode, | ||
673 | d.cycle_time, | ||
674 | d.overridden ? " (overriding vendor mode)" : ""); | ||
675 | display_clocks(index); | ||
676 | return; | ||
677 | } | ||
678 | |||
679 | #endif /* CONFIG_BLK_DEV_CMD640_ENHANCED */ | ||
680 | |||
681 | static int pci_conf1(void) | ||
682 | { | ||
683 | u32 tmp; | ||
684 | unsigned long flags; | ||
685 | |||
686 | spin_lock_irqsave(&ide_lock, flags); | ||
687 | outb(0x01, 0xCFB); | ||
688 | tmp = inl(0xCF8); | ||
689 | outl(0x80000000, 0xCF8); | ||
690 | if (inl(0xCF8) == 0x80000000) { | ||
691 | outl(tmp, 0xCF8); | ||
692 | spin_unlock_irqrestore(&ide_lock, flags); | ||
693 | return 1; | ||
694 | } | ||
695 | outl(tmp, 0xCF8); | ||
696 | spin_unlock_irqrestore(&ide_lock, flags); | ||
697 | return 0; | ||
698 | } | ||
699 | |||
700 | static int pci_conf2(void) | ||
701 | { | ||
702 | unsigned long flags; | ||
703 | |||
704 | spin_lock_irqsave(&ide_lock, flags); | ||
705 | outb(0x00, 0xCFB); | ||
706 | outb(0x00, 0xCF8); | ||
707 | outb(0x00, 0xCFA); | ||
708 | if (inb(0xCF8) == 0x00 && inb(0xCF8) == 0x00) { | ||
709 | spin_unlock_irqrestore(&ide_lock, flags); | ||
710 | return 1; | ||
711 | } | ||
712 | spin_unlock_irqrestore(&ide_lock, flags); | ||
713 | return 0; | ||
714 | } | ||
715 | |||
716 | /* | ||
717 | * Probe for a cmd640 chipset, and initialize it if found. Called from ide.c | ||
718 | */ | ||
719 | int __init ide_probe_for_cmd640x (void) | ||
720 | { | ||
721 | #ifdef CONFIG_BLK_DEV_CMD640_ENHANCED | ||
722 | int second_port_toggled = 0; | ||
723 | #endif /* CONFIG_BLK_DEV_CMD640_ENHANCED */ | ||
724 | int second_port_cmd640 = 0; | ||
725 | const char *bus_type, *port2; | ||
726 | unsigned int index; | ||
727 | u8 b, cfr; | ||
728 | |||
729 | if (cmd640_vlb && probe_for_cmd640_vlb()) { | ||
730 | bus_type = "VLB"; | ||
731 | } else { | ||
732 | cmd640_vlb = 0; | ||
733 | /* Find out what kind of PCI probing is supported otherwise | ||
734 | Justin Gibbs will sulk.. */ | ||
735 | if (pci_conf1() && probe_for_cmd640_pci1()) | ||
736 | bus_type = "PCI (type1)"; | ||
737 | else if (pci_conf2() && probe_for_cmd640_pci2()) | ||
738 | bus_type = "PCI (type2)"; | ||
739 | else | ||
740 | return 0; | ||
741 | } | ||
742 | /* | ||
743 | * Undocumented magic (there is no 0x5b reg in specs) | ||
744 | */ | ||
745 | put_cmd640_reg(0x5b, 0xbd); | ||
746 | if (get_cmd640_reg(0x5b) != 0xbd) { | ||
747 | printk(KERN_ERR "ide: cmd640 init failed: wrong value in reg 0x5b\n"); | ||
748 | return 0; | ||
749 | } | ||
750 | put_cmd640_reg(0x5b, 0); | ||
751 | |||
752 | #ifdef CMD640_DUMP_REGS | ||
753 | cmd640_dump_regs(); | ||
754 | #endif | ||
755 | |||
756 | /* | ||
757 | * Documented magic begins here | ||
758 | */ | ||
759 | cfr = get_cmd640_reg(CFR); | ||
760 | cmd640_chip_version = cfr & CFR_DEVREV; | ||
761 | if (cmd640_chip_version == 0) { | ||
762 | printk ("ide: bad cmd640 revision: %d\n", cmd640_chip_version); | ||
763 | return 0; | ||
764 | } | ||
765 | |||
766 | /* | ||
767 | * Initialize data for primary port | ||
768 | */ | ||
769 | setup_device_ptrs (); | ||
770 | printk("%s: buggy cmd640%c interface on %s, config=0x%02x\n", | ||
771 | cmd_hwif0->name, 'a' + cmd640_chip_version - 1, bus_type, cfr); | ||
772 | cmd_hwif0->chipset = ide_cmd640; | ||
773 | #ifdef CONFIG_BLK_DEV_CMD640_ENHANCED | ||
774 | cmd_hwif0->tuneproc = &cmd640_tune_drive; | ||
775 | #endif /* CONFIG_BLK_DEV_CMD640_ENHANCED */ | ||
776 | |||
777 | /* | ||
778 | * Ensure compatibility by always using the slowest timings | ||
779 | * for access to the drive's command register block, | ||
780 | * and reset the prefetch burstsize to default (512 bytes). | ||
781 | * | ||
782 | * Maybe we need a way to NOT do these on *some* systems? | ||
783 | */ | ||
784 | put_cmd640_reg(CMDTIM, 0); | ||
785 | put_cmd640_reg(BRST, 0x40); | ||
786 | |||
787 | /* | ||
788 | * Try to enable the secondary interface, if not already enabled | ||
789 | */ | ||
790 | if (cmd_hwif1->noprobe) { | ||
791 | port2 = "not probed"; | ||
792 | } else { | ||
793 | b = get_cmd640_reg(CNTRL); | ||
794 | if (secondary_port_responding()) { | ||
795 | if ((b & CNTRL_ENA_2ND)) { | ||
796 | second_port_cmd640 = 1; | ||
797 | port2 = "okay"; | ||
798 | } else if (cmd640_vlb) { | ||
799 | second_port_cmd640 = 1; | ||
800 | port2 = "alive"; | ||
801 | } else | ||
802 | port2 = "not cmd640"; | ||
803 | } else { | ||
804 | put_cmd640_reg(CNTRL, b ^ CNTRL_ENA_2ND); /* toggle the bit */ | ||
805 | if (secondary_port_responding()) { | ||
806 | second_port_cmd640 = 1; | ||
807 | #ifdef CONFIG_BLK_DEV_CMD640_ENHANCED | ||
808 | second_port_toggled = 1; | ||
809 | #endif /* CONFIG_BLK_DEV_CMD640_ENHANCED */ | ||
810 | port2 = "enabled"; | ||
811 | } else { | ||
812 | put_cmd640_reg(CNTRL, b); /* restore original setting */ | ||
813 | port2 = "not responding"; | ||
814 | } | ||
815 | } | ||
816 | } | ||
817 | |||
818 | /* | ||
819 | * Initialize data for secondary cmd640 port, if enabled | ||
820 | */ | ||
821 | if (second_port_cmd640) { | ||
822 | cmd_hwif0->serialized = 1; | ||
823 | cmd_hwif1->serialized = 1; | ||
824 | cmd_hwif1->chipset = ide_cmd640; | ||
825 | cmd_hwif0->mate = cmd_hwif1; | ||
826 | cmd_hwif1->mate = cmd_hwif0; | ||
827 | cmd_hwif1->channel = 1; | ||
828 | #ifdef CONFIG_BLK_DEV_CMD640_ENHANCED | ||
829 | cmd_hwif1->tuneproc = &cmd640_tune_drive; | ||
830 | #endif /* CONFIG_BLK_DEV_CMD640_ENHANCED */ | ||
831 | } | ||
832 | printk(KERN_INFO "%s: %sserialized, secondary interface %s\n", cmd_hwif1->name, | ||
833 | cmd_hwif0->serialized ? "" : "not ", port2); | ||
834 | |||
835 | /* | ||
836 | * Establish initial timings/prefetch for all drives. | ||
837 | * Do not unnecessarily disturb any prior BIOS setup of these. | ||
838 | */ | ||
839 | for (index = 0; index < (2 + (second_port_cmd640 << 1)); index++) { | ||
840 | ide_drive_t *drive = cmd_drives[index]; | ||
841 | #ifdef CONFIG_BLK_DEV_CMD640_ENHANCED | ||
842 | if (drive->autotune || ((index > 1) && second_port_toggled)) { | ||
843 | /* | ||
844 | * Reset timing to the slowest speed and turn off prefetch. | ||
845 | * This way, the drive identify code has a better chance. | ||
846 | */ | ||
847 | setup_counts [index] = 4; /* max possible */ | ||
848 | active_counts [index] = 16; /* max possible */ | ||
849 | recovery_counts [index] = 16; /* max possible */ | ||
850 | program_drive_counts (index); | ||
851 | set_prefetch_mode (index, 0); | ||
852 | printk("cmd640: drive%d timings/prefetch cleared\n", index); | ||
853 | } else { | ||
854 | /* | ||
855 | * Record timings/prefetch without changing them. | ||
856 | * This preserves any prior BIOS setup. | ||
857 | */ | ||
858 | retrieve_drive_counts (index); | ||
859 | check_prefetch (index); | ||
860 | printk("cmd640: drive%d timings/prefetch(%s) preserved", | ||
861 | index, drive->no_io_32bit ? "off" : "on"); | ||
862 | display_clocks(index); | ||
863 | } | ||
864 | #else | ||
865 | /* | ||
866 | * Set the drive unmask flags to match the prefetch setting | ||
867 | */ | ||
868 | check_prefetch (index); | ||
869 | printk("cmd640: drive%d timings/prefetch(%s) preserved\n", | ||
870 | index, drive->no_io_32bit ? "off" : "on"); | ||
871 | #endif /* CONFIG_BLK_DEV_CMD640_ENHANCED */ | ||
872 | } | ||
873 | |||
874 | #ifdef CMD640_DUMP_REGS | ||
875 | cmd640_dump_regs(); | ||
876 | #endif | ||
877 | return 1; | ||
878 | } | ||
879 | |||
diff --git a/drivers/ide/pci/cmd64x.c b/drivers/ide/pci/cmd64x.c new file mode 100644 index 000000000000..3de9ab897e42 --- /dev/null +++ b/drivers/ide/pci/cmd64x.c | |||
@@ -0,0 +1,821 @@ | |||
1 | /* $Id: cmd64x.c,v 1.21 2000/01/30 23:23:16 | ||
2 | * | ||
3 | * linux/drivers/ide/pci/cmd64x.c Version 1.30 Sept 10, 2002 | ||
4 | * | ||
5 | * cmd64x.c: Enable interrupts at initialization time on Ultra/PCI machines. | ||
6 | * Note, this driver is not used at all on other systems because | ||
7 | * there the "BIOS" has done all of the following already. | ||
8 | * Due to massive hardware bugs, UltraDMA is only supported | ||
9 | * on the 646U2 and not on the 646U. | ||
10 | * | ||
11 | * Copyright (C) 1998 Eddie C. Dost (ecd@skynet.be) | ||
12 | * Copyright (C) 1998 David S. Miller (davem@redhat.com) | ||
13 | * | ||
14 | * Copyright (C) 1999-2002 Andre Hedrick <andre@linux-ide.org> | ||
15 | */ | ||
16 | |||
17 | #include <linux/config.h> | ||
18 | #include <linux/module.h> | ||
19 | #include <linux/types.h> | ||
20 | #include <linux/pci.h> | ||
21 | #include <linux/delay.h> | ||
22 | #include <linux/hdreg.h> | ||
23 | #include <linux/ide.h> | ||
24 | #include <linux/init.h> | ||
25 | |||
26 | #include <asm/io.h> | ||
27 | |||
28 | #define DISPLAY_CMD64X_TIMINGS | ||
29 | |||
30 | #define CMD_DEBUG 0 | ||
31 | |||
32 | #if CMD_DEBUG | ||
33 | #define cmdprintk(x...) printk(x) | ||
34 | #else | ||
35 | #define cmdprintk(x...) | ||
36 | #endif | ||
37 | |||
38 | /* | ||
39 | * CMD64x specific registers definition. | ||
40 | */ | ||
41 | #define CFR 0x50 | ||
42 | #define CFR_INTR_CH0 0x02 | ||
43 | #define CNTRL 0x51 | ||
44 | #define CNTRL_DIS_RA0 0x40 | ||
45 | #define CNTRL_DIS_RA1 0x80 | ||
46 | #define CNTRL_ENA_2ND 0x08 | ||
47 | |||
48 | #define CMDTIM 0x52 | ||
49 | #define ARTTIM0 0x53 | ||
50 | #define DRWTIM0 0x54 | ||
51 | #define ARTTIM1 0x55 | ||
52 | #define DRWTIM1 0x56 | ||
53 | #define ARTTIM23 0x57 | ||
54 | #define ARTTIM23_DIS_RA2 0x04 | ||
55 | #define ARTTIM23_DIS_RA3 0x08 | ||
56 | #define ARTTIM23_INTR_CH1 0x10 | ||
57 | #define ARTTIM2 0x57 | ||
58 | #define ARTTIM3 0x57 | ||
59 | #define DRWTIM23 0x58 | ||
60 | #define DRWTIM2 0x58 | ||
61 | #define BRST 0x59 | ||
62 | #define DRWTIM3 0x5b | ||
63 | |||
64 | #define BMIDECR0 0x70 | ||
65 | #define MRDMODE 0x71 | ||
66 | #define MRDMODE_INTR_CH0 0x04 | ||
67 | #define MRDMODE_INTR_CH1 0x08 | ||
68 | #define MRDMODE_BLK_CH0 0x10 | ||
69 | #define MRDMODE_BLK_CH1 0x20 | ||
70 | #define BMIDESR0 0x72 | ||
71 | #define UDIDETCR0 0x73 | ||
72 | #define DTPR0 0x74 | ||
73 | #define BMIDECR1 0x78 | ||
74 | #define BMIDECSR 0x79 | ||
75 | #define BMIDESR1 0x7A | ||
76 | #define UDIDETCR1 0x7B | ||
77 | #define DTPR1 0x7C | ||
78 | |||
79 | #if defined(DISPLAY_CMD64X_TIMINGS) && defined(CONFIG_PROC_FS) | ||
80 | #include <linux/stat.h> | ||
81 | #include <linux/proc_fs.h> | ||
82 | |||
83 | static u8 cmd64x_proc = 0; | ||
84 | |||
85 | #define CMD_MAX_DEVS 5 | ||
86 | |||
87 | static struct pci_dev *cmd_devs[CMD_MAX_DEVS]; | ||
88 | static int n_cmd_devs; | ||
89 | |||
90 | static char * print_cmd64x_get_info (char *buf, struct pci_dev *dev, int index) | ||
91 | { | ||
92 | char *p = buf; | ||
93 | |||
94 | u8 reg53 = 0, reg54 = 0, reg55 = 0, reg56 = 0; /* primary */ | ||
95 | u8 reg57 = 0, reg58 = 0, reg5b; /* secondary */ | ||
96 | u8 reg72 = 0, reg73 = 0; /* primary */ | ||
97 | u8 reg7a = 0, reg7b = 0; /* secondary */ | ||
98 | u8 reg50 = 0, reg71 = 0; /* extra */ | ||
99 | |||
100 | p += sprintf(p, "\nController: %d\n", index); | ||
101 | p += sprintf(p, "CMD%x Chipset.\n", dev->device); | ||
102 | (void) pci_read_config_byte(dev, CFR, ®50); | ||
103 | (void) pci_read_config_byte(dev, ARTTIM0, ®53); | ||
104 | (void) pci_read_config_byte(dev, DRWTIM0, ®54); | ||
105 | (void) pci_read_config_byte(dev, ARTTIM1, ®55); | ||
106 | (void) pci_read_config_byte(dev, DRWTIM1, ®56); | ||
107 | (void) pci_read_config_byte(dev, ARTTIM2, ®57); | ||
108 | (void) pci_read_config_byte(dev, DRWTIM2, ®58); | ||
109 | (void) pci_read_config_byte(dev, DRWTIM3, ®5b); | ||
110 | (void) pci_read_config_byte(dev, MRDMODE, ®71); | ||
111 | (void) pci_read_config_byte(dev, BMIDESR0, ®72); | ||
112 | (void) pci_read_config_byte(dev, UDIDETCR0, ®73); | ||
113 | (void) pci_read_config_byte(dev, BMIDESR1, ®7a); | ||
114 | (void) pci_read_config_byte(dev, UDIDETCR1, ®7b); | ||
115 | |||
116 | p += sprintf(p, "--------------- Primary Channel " | ||
117 | "---------------- Secondary Channel " | ||
118 | "-------------\n"); | ||
119 | p += sprintf(p, " %sabled " | ||
120 | " %sabled\n", | ||
121 | (reg72&0x80)?"dis":" en", | ||
122 | (reg7a&0x80)?"dis":" en"); | ||
123 | p += sprintf(p, "--------------- drive0 " | ||
124 | "--------- drive1 -------- drive0 " | ||
125 | "---------- drive1 ------\n"); | ||
126 | p += sprintf(p, "DMA enabled: %s %s" | ||
127 | " %s %s\n", | ||
128 | (reg72&0x20)?"yes":"no ", (reg72&0x40)?"yes":"no ", | ||
129 | (reg7a&0x20)?"yes":"no ", (reg7a&0x40)?"yes":"no "); | ||
130 | |||
131 | p += sprintf(p, "DMA Mode: %s(%s) %s(%s)", | ||
132 | (reg72&0x20)?((reg73&0x01)?"UDMA":" DMA"):" PIO", | ||
133 | (reg72&0x20)?( | ||
134 | ((reg73&0x30)==0x30)?(((reg73&0x35)==0x35)?"3":"0"): | ||
135 | ((reg73&0x20)==0x20)?(((reg73&0x25)==0x25)?"3":"1"): | ||
136 | ((reg73&0x10)==0x10)?(((reg73&0x15)==0x15)?"4":"2"): | ||
137 | ((reg73&0x00)==0x00)?(((reg73&0x05)==0x05)?"5":"2"): | ||
138 | "X"):"?", | ||
139 | (reg72&0x40)?((reg73&0x02)?"UDMA":" DMA"):" PIO", | ||
140 | (reg72&0x40)?( | ||
141 | ((reg73&0xC0)==0xC0)?(((reg73&0xC5)==0xC5)?"3":"0"): | ||
142 | ((reg73&0x80)==0x80)?(((reg73&0x85)==0x85)?"3":"1"): | ||
143 | ((reg73&0x40)==0x40)?(((reg73&0x4A)==0x4A)?"4":"2"): | ||
144 | ((reg73&0x00)==0x00)?(((reg73&0x0A)==0x0A)?"5":"2"): | ||
145 | "X"):"?"); | ||
146 | p += sprintf(p, " %s(%s) %s(%s)\n", | ||
147 | (reg7a&0x20)?((reg7b&0x01)?"UDMA":" DMA"):" PIO", | ||
148 | (reg7a&0x20)?( | ||
149 | ((reg7b&0x30)==0x30)?(((reg7b&0x35)==0x35)?"3":"0"): | ||
150 | ((reg7b&0x20)==0x20)?(((reg7b&0x25)==0x25)?"3":"1"): | ||
151 | ((reg7b&0x10)==0x10)?(((reg7b&0x15)==0x15)?"4":"2"): | ||
152 | ((reg7b&0x00)==0x00)?(((reg7b&0x05)==0x05)?"5":"2"): | ||
153 | "X"):"?", | ||
154 | (reg7a&0x40)?((reg7b&0x02)?"UDMA":" DMA"):" PIO", | ||
155 | (reg7a&0x40)?( | ||
156 | ((reg7b&0xC0)==0xC0)?(((reg7b&0xC5)==0xC5)?"3":"0"): | ||
157 | ((reg7b&0x80)==0x80)?(((reg7b&0x85)==0x85)?"3":"1"): | ||
158 | ((reg7b&0x40)==0x40)?(((reg7b&0x4A)==0x4A)?"4":"2"): | ||
159 | ((reg7b&0x00)==0x00)?(((reg7b&0x0A)==0x0A)?"5":"2"): | ||
160 | "X"):"?" ); | ||
161 | p += sprintf(p, "PIO Mode: %s %s" | ||
162 | " %s %s\n", | ||
163 | "?", "?", "?", "?"); | ||
164 | p += sprintf(p, " %s %s\n", | ||
165 | (reg50 & CFR_INTR_CH0) ? "interrupting" : "polling ", | ||
166 | (reg57 & ARTTIM23_INTR_CH1) ? "interrupting" : "polling"); | ||
167 | p += sprintf(p, " %s %s\n", | ||
168 | (reg71 & MRDMODE_INTR_CH0) ? "pending" : "clear ", | ||
169 | (reg71 & MRDMODE_INTR_CH1) ? "pending" : "clear"); | ||
170 | p += sprintf(p, " %s %s\n", | ||
171 | (reg71 & MRDMODE_BLK_CH0) ? "blocked" : "enabled", | ||
172 | (reg71 & MRDMODE_BLK_CH1) ? "blocked" : "enabled"); | ||
173 | |||
174 | return (char *)p; | ||
175 | } | ||
176 | |||
177 | static int cmd64x_get_info (char *buffer, char **addr, off_t offset, int count) | ||
178 | { | ||
179 | char *p = buffer; | ||
180 | int i; | ||
181 | |||
182 | p += sprintf(p, "\n"); | ||
183 | for (i = 0; i < n_cmd_devs; i++) { | ||
184 | struct pci_dev *dev = cmd_devs[i]; | ||
185 | p = print_cmd64x_get_info(p, dev, i); | ||
186 | } | ||
187 | return p-buffer; /* => must be less than 4k! */ | ||
188 | } | ||
189 | |||
190 | #endif /* defined(DISPLAY_CMD64X_TIMINGS) && defined(CONFIG_PROC_FS) */ | ||
191 | |||
192 | /* | ||
193 | * Registers and masks for easy access by drive index: | ||
194 | */ | ||
195 | #if 0 | ||
196 | static u8 prefetch_regs[4] = {CNTRL, CNTRL, ARTTIM23, ARTTIM23}; | ||
197 | static u8 prefetch_masks[4] = {CNTRL_DIS_RA0, CNTRL_DIS_RA1, ARTTIM23_DIS_RA2, ARTTIM23_DIS_RA3}; | ||
198 | #endif | ||
199 | |||
200 | /* | ||
201 | * This routine writes the prepared setup/active/recovery counts | ||
202 | * for a drive into the cmd646 chipset registers to active them. | ||
203 | */ | ||
204 | static void program_drive_counts (ide_drive_t *drive, int setup_count, int active_count, int recovery_count) | ||
205 | { | ||
206 | unsigned long flags; | ||
207 | struct pci_dev *dev = HWIF(drive)->pci_dev; | ||
208 | ide_drive_t *drives = HWIF(drive)->drives; | ||
209 | u8 temp_b; | ||
210 | static const u8 setup_counts[] = {0x40, 0x40, 0x40, 0x80, 0, 0xc0}; | ||
211 | static const u8 recovery_counts[] = | ||
212 | {15, 15, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0}; | ||
213 | static const u8 arttim_regs[2][2] = { | ||
214 | { ARTTIM0, ARTTIM1 }, | ||
215 | { ARTTIM23, ARTTIM23 } | ||
216 | }; | ||
217 | static const u8 drwtim_regs[2][2] = { | ||
218 | { DRWTIM0, DRWTIM1 }, | ||
219 | { DRWTIM2, DRWTIM3 } | ||
220 | }; | ||
221 | int channel = (int) HWIF(drive)->channel; | ||
222 | int slave = (drives != drive); /* Is this really the best way to determine this?? */ | ||
223 | |||
224 | cmdprintk("program_drive_count parameters = s(%d),a(%d),r(%d),p(%d)\n", | ||
225 | setup_count, active_count, recovery_count, drive->present); | ||
226 | /* | ||
227 | * Set up address setup count registers. | ||
228 | * Primary interface has individual count/timing registers for | ||
229 | * each drive. Secondary interface has one common set of registers, | ||
230 | * for address setup so we merge these timings, using the slowest | ||
231 | * value. | ||
232 | */ | ||
233 | if (channel) { | ||
234 | drive->drive_data = setup_count; | ||
235 | setup_count = max(drives[0].drive_data, | ||
236 | drives[1].drive_data); | ||
237 | cmdprintk("Secondary interface, setup_count = %d\n", | ||
238 | setup_count); | ||
239 | } | ||
240 | |||
241 | /* | ||
242 | * Convert values to internal chipset representation | ||
243 | */ | ||
244 | setup_count = (setup_count > 5) ? 0xc0 : (int) setup_counts[setup_count]; | ||
245 | active_count &= 0xf; /* Remember, max value is 16 */ | ||
246 | recovery_count = (int) recovery_counts[recovery_count]; | ||
247 | |||
248 | cmdprintk("Final values = %d,%d,%d\n", | ||
249 | setup_count, active_count, recovery_count); | ||
250 | |||
251 | /* | ||
252 | * Now that everything is ready, program the new timings | ||
253 | */ | ||
254 | local_irq_save(flags); | ||
255 | /* | ||
256 | * Program the address_setup clocks into ARTTIM reg, | ||
257 | * and then the active/recovery counts into the DRWTIM reg | ||
258 | */ | ||
259 | (void) pci_read_config_byte(dev, arttim_regs[channel][slave], &temp_b); | ||
260 | (void) pci_write_config_byte(dev, arttim_regs[channel][slave], | ||
261 | ((u8) setup_count) | (temp_b & 0x3f)); | ||
262 | (void) pci_write_config_byte(dev, drwtim_regs[channel][slave], | ||
263 | (u8) ((active_count << 4) | recovery_count)); | ||
264 | cmdprintk ("Write %x to %x\n", | ||
265 | ((u8) setup_count) | (temp_b & 0x3f), | ||
266 | arttim_regs[channel][slave]); | ||
267 | cmdprintk ("Write %x to %x\n", | ||
268 | (u8) ((active_count << 4) | recovery_count), | ||
269 | drwtim_regs[channel][slave]); | ||
270 | local_irq_restore(flags); | ||
271 | } | ||
272 | |||
273 | /* | ||
274 | * Attempts to set the interface PIO mode. | ||
275 | * The preferred method of selecting PIO modes (e.g. mode 4) is | ||
276 | * "echo 'piomode:4' > /proc/ide/hdx/settings". Special cases are | ||
277 | * 8: prefetch off, 9: prefetch on, 255: auto-select best mode. | ||
278 | * Called with 255 at boot time. | ||
279 | */ | ||
280 | |||
281 | static void cmd64x_tuneproc (ide_drive_t *drive, u8 mode_wanted) | ||
282 | { | ||
283 | int setup_time, active_time, recovery_time; | ||
284 | int clock_time, pio_mode, cycle_time; | ||
285 | u8 recovery_count2, cycle_count; | ||
286 | int setup_count, active_count, recovery_count; | ||
287 | int bus_speed = system_bus_clock(); | ||
288 | /*byte b;*/ | ||
289 | ide_pio_data_t d; | ||
290 | |||
291 | switch (mode_wanted) { | ||
292 | case 8: /* set prefetch off */ | ||
293 | case 9: /* set prefetch on */ | ||
294 | mode_wanted &= 1; | ||
295 | /*set_prefetch_mode(index, mode_wanted);*/ | ||
296 | cmdprintk("%s: %sabled cmd640 prefetch\n", | ||
297 | drive->name, mode_wanted ? "en" : "dis"); | ||
298 | return; | ||
299 | } | ||
300 | |||
301 | mode_wanted = ide_get_best_pio_mode (drive, mode_wanted, 5, &d); | ||
302 | pio_mode = d.pio_mode; | ||
303 | cycle_time = d.cycle_time; | ||
304 | |||
305 | /* | ||
306 | * I copied all this complicated stuff from cmd640.c and made a few | ||
307 | * minor changes. For now I am just going to pray that it is correct. | ||
308 | */ | ||
309 | if (pio_mode > 5) | ||
310 | pio_mode = 5; | ||
311 | setup_time = ide_pio_timings[pio_mode].setup_time; | ||
312 | active_time = ide_pio_timings[pio_mode].active_time; | ||
313 | recovery_time = cycle_time - (setup_time + active_time); | ||
314 | clock_time = 1000 / bus_speed; | ||
315 | cycle_count = (cycle_time + clock_time - 1) / clock_time; | ||
316 | |||
317 | setup_count = (setup_time + clock_time - 1) / clock_time; | ||
318 | |||
319 | active_count = (active_time + clock_time - 1) / clock_time; | ||
320 | |||
321 | recovery_count = (recovery_time + clock_time - 1) / clock_time; | ||
322 | recovery_count2 = cycle_count - (setup_count + active_count); | ||
323 | if (recovery_count2 > recovery_count) | ||
324 | recovery_count = recovery_count2; | ||
325 | if (recovery_count > 16) { | ||
326 | active_count += recovery_count - 16; | ||
327 | recovery_count = 16; | ||
328 | } | ||
329 | if (active_count > 16) | ||
330 | active_count = 16; /* maximum allowed by cmd646 */ | ||
331 | |||
332 | /* | ||
333 | * In a perfect world, we might set the drive pio mode here | ||
334 | * (using WIN_SETFEATURE) before continuing. | ||
335 | * | ||
336 | * But we do not, because: | ||
337 | * 1) this is the wrong place to do it | ||
338 | * (proper is do_special() in ide.c) | ||
339 | * 2) in practice this is rarely, if ever, necessary | ||
340 | */ | ||
341 | program_drive_counts (drive, setup_count, active_count, recovery_count); | ||
342 | |||
343 | cmdprintk("%s: selected cmd646 PIO mode%d : %d (%dns)%s, " | ||
344 | "clocks=%d/%d/%d\n", | ||
345 | drive->name, pio_mode, mode_wanted, cycle_time, | ||
346 | d.overridden ? " (overriding vendor mode)" : "", | ||
347 | setup_count, active_count, recovery_count); | ||
348 | } | ||
349 | |||
350 | static u8 cmd64x_ratemask (ide_drive_t *drive) | ||
351 | { | ||
352 | struct pci_dev *dev = HWIF(drive)->pci_dev; | ||
353 | u8 mode = 0; | ||
354 | |||
355 | switch(dev->device) { | ||
356 | case PCI_DEVICE_ID_CMD_649: | ||
357 | mode = 3; | ||
358 | break; | ||
359 | case PCI_DEVICE_ID_CMD_648: | ||
360 | mode = 2; | ||
361 | break; | ||
362 | case PCI_DEVICE_ID_CMD_643: | ||
363 | return 0; | ||
364 | |||
365 | case PCI_DEVICE_ID_CMD_646: | ||
366 | { | ||
367 | unsigned int class_rev = 0; | ||
368 | pci_read_config_dword(dev, | ||
369 | PCI_CLASS_REVISION, &class_rev); | ||
370 | class_rev &= 0xff; | ||
371 | /* | ||
372 | * UltraDMA only supported on PCI646U and PCI646U2, which | ||
373 | * correspond to revisions 0x03, 0x05 and 0x07 respectively. | ||
374 | * Actually, although the CMD tech support people won't | ||
375 | * tell me the details, the 0x03 revision cannot support | ||
376 | * UDMA correctly without hardware modifications, and even | ||
377 | * then it only works with Quantum disks due to some | ||
378 | * hold time assumptions in the 646U part which are fixed | ||
379 | * in the 646U2. | ||
380 | * | ||
381 | * So we only do UltraDMA on revision 0x05 and 0x07 chipsets. | ||
382 | */ | ||
383 | switch(class_rev) { | ||
384 | case 0x07: | ||
385 | case 0x05: | ||
386 | return 1; | ||
387 | case 0x03: | ||
388 | case 0x01: | ||
389 | default: | ||
390 | return 0; | ||
391 | } | ||
392 | } | ||
393 | } | ||
394 | if (!eighty_ninty_three(drive)) | ||
395 | mode = min(mode, (u8)1); | ||
396 | return mode; | ||
397 | } | ||
398 | |||
399 | static void config_cmd64x_chipset_for_pio (ide_drive_t *drive, u8 set_speed) | ||
400 | { | ||
401 | u8 speed = 0x00; | ||
402 | u8 set_pio = ide_get_best_pio_mode(drive, 4, 5, NULL); | ||
403 | |||
404 | cmd64x_tuneproc(drive, set_pio); | ||
405 | speed = XFER_PIO_0 + set_pio; | ||
406 | if (set_speed) | ||
407 | (void) ide_config_drive_speed(drive, speed); | ||
408 | } | ||
409 | |||
410 | static void config_chipset_for_pio (ide_drive_t *drive, u8 set_speed) | ||
411 | { | ||
412 | config_cmd64x_chipset_for_pio(drive, set_speed); | ||
413 | } | ||
414 | |||
415 | static int cmd64x_tune_chipset (ide_drive_t *drive, u8 xferspeed) | ||
416 | { | ||
417 | ide_hwif_t *hwif = HWIF(drive); | ||
418 | struct pci_dev *dev = hwif->pci_dev; | ||
419 | |||
420 | u8 unit = (drive->select.b.unit & 0x01); | ||
421 | u8 regU = 0, pciU = (hwif->channel) ? UDIDETCR1 : UDIDETCR0; | ||
422 | u8 regD = 0, pciD = (hwif->channel) ? BMIDESR1 : BMIDESR0; | ||
423 | |||
424 | u8 speed = ide_rate_filter(cmd64x_ratemask(drive), xferspeed); | ||
425 | |||
426 | if (speed > XFER_PIO_4) { | ||
427 | (void) pci_read_config_byte(dev, pciD, ®D); | ||
428 | (void) pci_read_config_byte(dev, pciU, ®U); | ||
429 | regD &= ~(unit ? 0x40 : 0x20); | ||
430 | regU &= ~(unit ? 0xCA : 0x35); | ||
431 | (void) pci_write_config_byte(dev, pciD, regD); | ||
432 | (void) pci_write_config_byte(dev, pciU, regU); | ||
433 | (void) pci_read_config_byte(dev, pciD, ®D); | ||
434 | (void) pci_read_config_byte(dev, pciU, ®U); | ||
435 | } | ||
436 | |||
437 | switch(speed) { | ||
438 | case XFER_UDMA_5: regU |= (unit ? 0x0A : 0x05); break; | ||
439 | case XFER_UDMA_4: regU |= (unit ? 0x4A : 0x15); break; | ||
440 | case XFER_UDMA_3: regU |= (unit ? 0x8A : 0x25); break; | ||
441 | case XFER_UDMA_2: regU |= (unit ? 0x42 : 0x11); break; | ||
442 | case XFER_UDMA_1: regU |= (unit ? 0x82 : 0x21); break; | ||
443 | case XFER_UDMA_0: regU |= (unit ? 0xC2 : 0x31); break; | ||
444 | case XFER_MW_DMA_2: regD |= (unit ? 0x40 : 0x10); break; | ||
445 | case XFER_MW_DMA_1: regD |= (unit ? 0x80 : 0x20); break; | ||
446 | case XFER_MW_DMA_0: regD |= (unit ? 0xC0 : 0x30); break; | ||
447 | case XFER_SW_DMA_2: regD |= (unit ? 0x40 : 0x10); break; | ||
448 | case XFER_SW_DMA_1: regD |= (unit ? 0x80 : 0x20); break; | ||
449 | case XFER_SW_DMA_0: regD |= (unit ? 0xC0 : 0x30); break; | ||
450 | case XFER_PIO_4: cmd64x_tuneproc(drive, 4); break; | ||
451 | case XFER_PIO_3: cmd64x_tuneproc(drive, 3); break; | ||
452 | case XFER_PIO_2: cmd64x_tuneproc(drive, 2); break; | ||
453 | case XFER_PIO_1: cmd64x_tuneproc(drive, 1); break; | ||
454 | case XFER_PIO_0: cmd64x_tuneproc(drive, 0); break; | ||
455 | |||
456 | default: | ||
457 | return 1; | ||
458 | } | ||
459 | |||
460 | if (speed > XFER_PIO_4) { | ||
461 | (void) pci_write_config_byte(dev, pciU, regU); | ||
462 | regD |= (unit ? 0x40 : 0x20); | ||
463 | (void) pci_write_config_byte(dev, pciD, regD); | ||
464 | } | ||
465 | |||
466 | return (ide_config_drive_speed(drive, speed)); | ||
467 | } | ||
468 | |||
469 | static int config_chipset_for_dma (ide_drive_t *drive) | ||
470 | { | ||
471 | u8 speed = ide_dma_speed(drive, cmd64x_ratemask(drive)); | ||
472 | |||
473 | config_chipset_for_pio(drive, !speed); | ||
474 | |||
475 | if (!speed) | ||
476 | return 0; | ||
477 | |||
478 | if(ide_set_xfer_rate(drive, speed)) | ||
479 | return 0; | ||
480 | |||
481 | if (!drive->init_speed) | ||
482 | drive->init_speed = speed; | ||
483 | |||
484 | return ide_dma_enable(drive); | ||
485 | } | ||
486 | |||
487 | static int cmd64x_config_drive_for_dma (ide_drive_t *drive) | ||
488 | { | ||
489 | ide_hwif_t *hwif = HWIF(drive); | ||
490 | struct hd_driveid *id = drive->id; | ||
491 | |||
492 | if ((id != NULL) && ((id->capability & 1) != 0) && drive->autodma) { | ||
493 | |||
494 | if (ide_use_dma(drive)) { | ||
495 | if (config_chipset_for_dma(drive)) | ||
496 | return hwif->ide_dma_on(drive); | ||
497 | } | ||
498 | |||
499 | goto fast_ata_pio; | ||
500 | |||
501 | } else if ((id->capability & 8) || (id->field_valid & 2)) { | ||
502 | fast_ata_pio: | ||
503 | config_chipset_for_pio(drive, 1); | ||
504 | return hwif->ide_dma_off_quietly(drive); | ||
505 | } | ||
506 | /* IORDY not supported */ | ||
507 | return 0; | ||
508 | } | ||
509 | |||
510 | static int cmd64x_alt_dma_status (struct pci_dev *dev) | ||
511 | { | ||
512 | switch(dev->device) { | ||
513 | case PCI_DEVICE_ID_CMD_648: | ||
514 | case PCI_DEVICE_ID_CMD_649: | ||
515 | return 1; | ||
516 | default: | ||
517 | break; | ||
518 | } | ||
519 | return 0; | ||
520 | } | ||
521 | |||
522 | static int cmd64x_ide_dma_end (ide_drive_t *drive) | ||
523 | { | ||
524 | u8 dma_stat = 0, dma_cmd = 0; | ||
525 | ide_hwif_t *hwif = HWIF(drive); | ||
526 | struct pci_dev *dev = hwif->pci_dev; | ||
527 | |||
528 | drive->waiting_for_dma = 0; | ||
529 | /* read DMA command state */ | ||
530 | dma_cmd = hwif->INB(hwif->dma_command); | ||
531 | /* stop DMA */ | ||
532 | hwif->OUTB((dma_cmd & ~1), hwif->dma_command); | ||
533 | /* get DMA status */ | ||
534 | dma_stat = hwif->INB(hwif->dma_status); | ||
535 | /* clear the INTR & ERROR bits */ | ||
536 | hwif->OUTB(dma_stat|6, hwif->dma_status); | ||
537 | if (cmd64x_alt_dma_status(dev)) { | ||
538 | u8 dma_intr = 0; | ||
539 | u8 dma_mask = (hwif->channel) ? ARTTIM23_INTR_CH1 : | ||
540 | CFR_INTR_CH0; | ||
541 | u8 dma_reg = (hwif->channel) ? ARTTIM2 : CFR; | ||
542 | (void) pci_read_config_byte(dev, dma_reg, &dma_intr); | ||
543 | /* clear the INTR bit */ | ||
544 | (void) pci_write_config_byte(dev, dma_reg, dma_intr|dma_mask); | ||
545 | } | ||
546 | /* purge DMA mappings */ | ||
547 | ide_destroy_dmatable(drive); | ||
548 | /* verify good DMA status */ | ||
549 | return (dma_stat & 7) != 4; | ||
550 | } | ||
551 | |||
552 | static int cmd64x_ide_dma_test_irq (ide_drive_t *drive) | ||
553 | { | ||
554 | ide_hwif_t *hwif = HWIF(drive); | ||
555 | struct pci_dev *dev = hwif->pci_dev; | ||
556 | u8 dma_alt_stat = 0, mask = (hwif->channel) ? MRDMODE_INTR_CH1 : | ||
557 | MRDMODE_INTR_CH0; | ||
558 | u8 dma_stat = hwif->INB(hwif->dma_status); | ||
559 | |||
560 | (void) pci_read_config_byte(dev, MRDMODE, &dma_alt_stat); | ||
561 | #ifdef DEBUG | ||
562 | printk("%s: dma_stat: 0x%02x dma_alt_stat: " | ||
563 | "0x%02x mask: 0x%02x\n", drive->name, | ||
564 | dma_stat, dma_alt_stat, mask); | ||
565 | #endif | ||
566 | if (!(dma_alt_stat & mask)) | ||
567 | return 0; | ||
568 | |||
569 | /* return 1 if INTR asserted */ | ||
570 | if ((dma_stat & 4) == 4) | ||
571 | return 1; | ||
572 | |||
573 | return 0; | ||
574 | } | ||
575 | |||
576 | /* | ||
577 | * ASUS P55T2P4D with CMD646 chipset revision 0x01 requires the old | ||
578 | * event order for DMA transfers. | ||
579 | */ | ||
580 | |||
581 | static int cmd646_1_ide_dma_end (ide_drive_t *drive) | ||
582 | { | ||
583 | ide_hwif_t *hwif = HWIF(drive); | ||
584 | u8 dma_stat = 0, dma_cmd = 0; | ||
585 | |||
586 | drive->waiting_for_dma = 0; | ||
587 | /* get DMA status */ | ||
588 | dma_stat = hwif->INB(hwif->dma_status); | ||
589 | /* read DMA command state */ | ||
590 | dma_cmd = hwif->INB(hwif->dma_command); | ||
591 | /* stop DMA */ | ||
592 | hwif->OUTB((dma_cmd & ~1), hwif->dma_command); | ||
593 | /* clear the INTR & ERROR bits */ | ||
594 | hwif->OUTB(dma_stat|6, hwif->dma_status); | ||
595 | /* and free any DMA resources */ | ||
596 | ide_destroy_dmatable(drive); | ||
597 | /* verify good DMA status */ | ||
598 | return (dma_stat & 7) != 4; | ||
599 | } | ||
600 | |||
601 | static unsigned int __devinit init_chipset_cmd64x(struct pci_dev *dev, const char *name) | ||
602 | { | ||
603 | u32 class_rev = 0; | ||
604 | u8 mrdmode = 0; | ||
605 | |||
606 | pci_read_config_dword(dev, PCI_CLASS_REVISION, &class_rev); | ||
607 | class_rev &= 0xff; | ||
608 | |||
609 | #ifdef __i386__ | ||
610 | if (dev->resource[PCI_ROM_RESOURCE].start) { | ||
611 | pci_write_config_byte(dev, PCI_ROM_ADDRESS, dev->resource[PCI_ROM_RESOURCE].start | PCI_ROM_ADDRESS_ENABLE); | ||
612 | printk(KERN_INFO "%s: ROM enabled at 0x%08lx\n", name, dev->resource[PCI_ROM_RESOURCE].start); | ||
613 | } | ||
614 | #endif | ||
615 | |||
616 | switch(dev->device) { | ||
617 | case PCI_DEVICE_ID_CMD_643: | ||
618 | break; | ||
619 | case PCI_DEVICE_ID_CMD_646: | ||
620 | printk(KERN_INFO "%s: chipset revision 0x%02X, ", name, class_rev); | ||
621 | switch(class_rev) { | ||
622 | case 0x07: | ||
623 | case 0x05: | ||
624 | printk("UltraDMA Capable"); | ||
625 | break; | ||
626 | case 0x03: | ||
627 | printk("MultiWord DMA Force Limited"); | ||
628 | break; | ||
629 | case 0x01: | ||
630 | default: | ||
631 | printk("MultiWord DMA Limited, IRQ workaround enabled"); | ||
632 | break; | ||
633 | } | ||
634 | printk("\n"); | ||
635 | break; | ||
636 | case PCI_DEVICE_ID_CMD_648: | ||
637 | case PCI_DEVICE_ID_CMD_649: | ||
638 | break; | ||
639 | default: | ||
640 | break; | ||
641 | } | ||
642 | |||
643 | /* Set a good latency timer and cache line size value. */ | ||
644 | (void) pci_write_config_byte(dev, PCI_LATENCY_TIMER, 64); | ||
645 | /* FIXME: pci_set_master() to ensure a good latency timer value */ | ||
646 | |||
647 | /* Setup interrupts. */ | ||
648 | (void) pci_read_config_byte(dev, MRDMODE, &mrdmode); | ||
649 | mrdmode &= ~(0x30); | ||
650 | (void) pci_write_config_byte(dev, MRDMODE, mrdmode); | ||
651 | |||
652 | /* Use MEMORY READ LINE for reads. | ||
653 | * NOTE: Although not mentioned in the PCI0646U specs, | ||
654 | * these bits are write only and won't be read | ||
655 | * back as set or not. The PCI0646U2 specs clarify | ||
656 | * this point. | ||
657 | */ | ||
658 | (void) pci_write_config_byte(dev, MRDMODE, mrdmode | 0x02); | ||
659 | |||
660 | /* Set reasonable active/recovery/address-setup values. */ | ||
661 | (void) pci_write_config_byte(dev, ARTTIM0, 0x40); | ||
662 | (void) pci_write_config_byte(dev, DRWTIM0, 0x3f); | ||
663 | (void) pci_write_config_byte(dev, ARTTIM1, 0x40); | ||
664 | (void) pci_write_config_byte(dev, DRWTIM1, 0x3f); | ||
665 | #ifdef __i386__ | ||
666 | (void) pci_write_config_byte(dev, ARTTIM23, 0x1c); | ||
667 | #else | ||
668 | (void) pci_write_config_byte(dev, ARTTIM23, 0x5c); | ||
669 | #endif | ||
670 | (void) pci_write_config_byte(dev, DRWTIM23, 0x3f); | ||
671 | (void) pci_write_config_byte(dev, DRWTIM3, 0x3f); | ||
672 | #ifdef CONFIG_PPC | ||
673 | (void) pci_write_config_byte(dev, UDIDETCR0, 0xf0); | ||
674 | #endif /* CONFIG_PPC */ | ||
675 | |||
676 | #if defined(DISPLAY_CMD64X_TIMINGS) && defined(CONFIG_PROC_FS) | ||
677 | |||
678 | cmd_devs[n_cmd_devs++] = dev; | ||
679 | |||
680 | if (!cmd64x_proc) { | ||
681 | cmd64x_proc = 1; | ||
682 | ide_pci_create_host_proc("cmd64x", cmd64x_get_info); | ||
683 | } | ||
684 | #endif /* DISPLAY_CMD64X_TIMINGS && CONFIG_PROC_FS */ | ||
685 | |||
686 | return 0; | ||
687 | } | ||
688 | |||
689 | static unsigned int __devinit ata66_cmd64x(ide_hwif_t *hwif) | ||
690 | { | ||
691 | u8 ata66 = 0, mask = (hwif->channel) ? 0x02 : 0x01; | ||
692 | |||
693 | switch(hwif->pci_dev->device) { | ||
694 | case PCI_DEVICE_ID_CMD_643: | ||
695 | case PCI_DEVICE_ID_CMD_646: | ||
696 | return ata66; | ||
697 | default: | ||
698 | break; | ||
699 | } | ||
700 | pci_read_config_byte(hwif->pci_dev, BMIDECSR, &ata66); | ||
701 | return (ata66 & mask) ? 1 : 0; | ||
702 | } | ||
703 | |||
704 | static void __devinit init_hwif_cmd64x(ide_hwif_t *hwif) | ||
705 | { | ||
706 | struct pci_dev *dev = hwif->pci_dev; | ||
707 | unsigned int class_rev; | ||
708 | |||
709 | hwif->autodma = 0; | ||
710 | pci_read_config_dword(dev, PCI_CLASS_REVISION, &class_rev); | ||
711 | class_rev &= 0xff; | ||
712 | |||
713 | hwif->tuneproc = &cmd64x_tuneproc; | ||
714 | hwif->speedproc = &cmd64x_tune_chipset; | ||
715 | |||
716 | if (!hwif->dma_base) { | ||
717 | hwif->drives[0].autotune = 1; | ||
718 | hwif->drives[1].autotune = 1; | ||
719 | return; | ||
720 | } | ||
721 | |||
722 | hwif->atapi_dma = 1; | ||
723 | |||
724 | hwif->ultra_mask = 0x3f; | ||
725 | hwif->mwdma_mask = 0x07; | ||
726 | hwif->swdma_mask = 0x07; | ||
727 | |||
728 | if (dev->device == PCI_DEVICE_ID_CMD_643) | ||
729 | hwif->ultra_mask = 0x80; | ||
730 | if (dev->device == PCI_DEVICE_ID_CMD_646) | ||
731 | hwif->ultra_mask = (class_rev > 0x04) ? 0x07 : 0x80; | ||
732 | if (dev->device == PCI_DEVICE_ID_CMD_648) | ||
733 | hwif->ultra_mask = 0x1f; | ||
734 | |||
735 | hwif->ide_dma_check = &cmd64x_config_drive_for_dma; | ||
736 | if (!(hwif->udma_four)) | ||
737 | hwif->udma_four = ata66_cmd64x(hwif); | ||
738 | |||
739 | if (dev->device == PCI_DEVICE_ID_CMD_646) { | ||
740 | hwif->chipset = ide_cmd646; | ||
741 | if (class_rev == 0x01) { | ||
742 | hwif->ide_dma_end = &cmd646_1_ide_dma_end; | ||
743 | } else { | ||
744 | hwif->ide_dma_end = &cmd64x_ide_dma_end; | ||
745 | hwif->ide_dma_test_irq = &cmd64x_ide_dma_test_irq; | ||
746 | } | ||
747 | } else { | ||
748 | hwif->ide_dma_end = &cmd64x_ide_dma_end; | ||
749 | hwif->ide_dma_test_irq = &cmd64x_ide_dma_test_irq; | ||
750 | } | ||
751 | |||
752 | |||
753 | if (!noautodma) | ||
754 | hwif->autodma = 1; | ||
755 | hwif->drives[0].autodma = hwif->autodma; | ||
756 | hwif->drives[1].autodma = hwif->autodma; | ||
757 | } | ||
758 | |||
759 | static ide_pci_device_t cmd64x_chipsets[] __devinitdata = { | ||
760 | { /* 0 */ | ||
761 | .name = "CMD643", | ||
762 | .init_chipset = init_chipset_cmd64x, | ||
763 | .init_hwif = init_hwif_cmd64x, | ||
764 | .channels = 2, | ||
765 | .autodma = AUTODMA, | ||
766 | .bootable = ON_BOARD, | ||
767 | },{ /* 1 */ | ||
768 | .name = "CMD646", | ||
769 | .init_chipset = init_chipset_cmd64x, | ||
770 | .init_hwif = init_hwif_cmd64x, | ||
771 | .channels = 2, | ||
772 | .autodma = AUTODMA, | ||
773 | .enablebits = {{0x00,0x00,0x00}, {0x51,0x80,0x80}}, | ||
774 | .bootable = ON_BOARD, | ||
775 | },{ /* 2 */ | ||
776 | .name = "CMD648", | ||
777 | .init_chipset = init_chipset_cmd64x, | ||
778 | .init_hwif = init_hwif_cmd64x, | ||
779 | .channels = 2, | ||
780 | .autodma = AUTODMA, | ||
781 | .bootable = ON_BOARD, | ||
782 | },{ /* 3 */ | ||
783 | .name = "CMD649", | ||
784 | .init_chipset = init_chipset_cmd64x, | ||
785 | .init_hwif = init_hwif_cmd64x, | ||
786 | .channels = 2, | ||
787 | .autodma = AUTODMA, | ||
788 | .bootable = ON_BOARD, | ||
789 | } | ||
790 | }; | ||
791 | |||
792 | static int __devinit cmd64x_init_one(struct pci_dev *dev, const struct pci_device_id *id) | ||
793 | { | ||
794 | return ide_setup_pci_device(dev, &cmd64x_chipsets[id->driver_data]); | ||
795 | } | ||
796 | |||
797 | static struct pci_device_id cmd64x_pci_tbl[] = { | ||
798 | { PCI_VENDOR_ID_CMD, PCI_DEVICE_ID_CMD_643, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, | ||
799 | { PCI_VENDOR_ID_CMD, PCI_DEVICE_ID_CMD_646, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1}, | ||
800 | { PCI_VENDOR_ID_CMD, PCI_DEVICE_ID_CMD_648, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2}, | ||
801 | { PCI_VENDOR_ID_CMD, PCI_DEVICE_ID_CMD_649, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3}, | ||
802 | { 0, }, | ||
803 | }; | ||
804 | MODULE_DEVICE_TABLE(pci, cmd64x_pci_tbl); | ||
805 | |||
806 | static struct pci_driver driver = { | ||
807 | .name = "CMD64x_IDE", | ||
808 | .id_table = cmd64x_pci_tbl, | ||
809 | .probe = cmd64x_init_one, | ||
810 | }; | ||
811 | |||
812 | static int cmd64x_ide_init(void) | ||
813 | { | ||
814 | return ide_pci_register_driver(&driver); | ||
815 | } | ||
816 | |||
817 | module_init(cmd64x_ide_init); | ||
818 | |||
819 | MODULE_AUTHOR("Eddie Dost, David Miller, Andre Hedrick"); | ||
820 | MODULE_DESCRIPTION("PCI driver module for CMD64x IDE"); | ||
821 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/ide/pci/cs5520.c b/drivers/ide/pci/cs5520.c new file mode 100644 index 000000000000..7dc24682d197 --- /dev/null +++ b/drivers/ide/pci/cs5520.c | |||
@@ -0,0 +1,274 @@ | |||
1 | /* | ||
2 | * IDE tuning and bus mastering support for the CS5510/CS5520 | ||
3 | * chipsets | ||
4 | * | ||
5 | * The CS5510/CS5520 are slightly unusual devices. Unlike the | ||
6 | * typical IDE controllers they do bus mastering with the drive in | ||
7 | * PIO mode and smarter silicon. | ||
8 | * | ||
9 | * The practical upshot of this is that we must always tune the | ||
10 | * drive for the right PIO mode. We must also ignore all the blacklists | ||
11 | * and the drive bus mastering DMA information. | ||
12 | * | ||
13 | * *** This driver is strictly experimental *** | ||
14 | * | ||
15 | * (c) Copyright Red Hat Inc 2002 | ||
16 | * | ||
17 | * This program is free software; you can redistribute it and/or modify it | ||
18 | * under the terms of the GNU General Public License as published by the | ||
19 | * Free Software Foundation; either version 2, or (at your option) any | ||
20 | * later version. | ||
21 | * | ||
22 | * This program is distributed in the hope that it will be useful, but | ||
23 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
25 | * General Public License for more details. | ||
26 | * | ||
27 | * For the avoidance of doubt the "preferred form" of this code is one which | ||
28 | * is in an open non patent encumbered format. Where cryptographic key signing | ||
29 | * forms part of the process of creating an executable the information | ||
30 | * including keys needed to generate an equivalently functional executable | ||
31 | * are deemed to be part of the source code. | ||
32 | * | ||
33 | */ | ||
34 | |||
35 | #include <linux/config.h> | ||
36 | #include <linux/module.h> | ||
37 | #include <linux/types.h> | ||
38 | #include <linux/kernel.h> | ||
39 | #include <linux/delay.h> | ||
40 | #include <linux/timer.h> | ||
41 | #include <linux/mm.h> | ||
42 | #include <linux/ioport.h> | ||
43 | #include <linux/blkdev.h> | ||
44 | #include <linux/hdreg.h> | ||
45 | |||
46 | #include <linux/interrupt.h> | ||
47 | #include <linux/init.h> | ||
48 | #include <linux/pci.h> | ||
49 | #include <linux/ide.h> | ||
50 | #include <linux/dma-mapping.h> | ||
51 | |||
52 | #include <asm/io.h> | ||
53 | #include <asm/irq.h> | ||
54 | |||
55 | struct pio_clocks | ||
56 | { | ||
57 | int address; | ||
58 | int assert; | ||
59 | int recovery; | ||
60 | }; | ||
61 | |||
62 | static struct pio_clocks cs5520_pio_clocks[]={ | ||
63 | {3, 6, 11}, | ||
64 | {2, 5, 6}, | ||
65 | {1, 4, 3}, | ||
66 | {1, 3, 2}, | ||
67 | {1, 2, 1} | ||
68 | }; | ||
69 | |||
70 | static int cs5520_tune_chipset(ide_drive_t *drive, u8 xferspeed) | ||
71 | { | ||
72 | ide_hwif_t *hwif = HWIF(drive); | ||
73 | struct pci_dev *pdev = hwif->pci_dev; | ||
74 | u8 speed = min((u8)XFER_PIO_4, xferspeed); | ||
75 | int pio = speed; | ||
76 | u8 reg; | ||
77 | int controller = drive->dn > 1 ? 1 : 0; | ||
78 | int error; | ||
79 | |||
80 | switch(speed) | ||
81 | { | ||
82 | case XFER_PIO_4: | ||
83 | case XFER_PIO_3: | ||
84 | case XFER_PIO_2: | ||
85 | case XFER_PIO_1: | ||
86 | case XFER_PIO_0: | ||
87 | pio -= XFER_PIO_0; | ||
88 | break; | ||
89 | default: | ||
90 | pio = 0; | ||
91 | printk(KERN_ERR "cs55x0: bad ide timing.\n"); | ||
92 | } | ||
93 | |||
94 | printk("PIO clocking = %d\n", pio); | ||
95 | |||
96 | /* FIXME: if DMA = 1 do we need to set the DMA bit here ? */ | ||
97 | |||
98 | /* 8bit CAT/CRT - 8bit command timing for channel */ | ||
99 | pci_write_config_byte(pdev, 0x62 + controller, | ||
100 | (cs5520_pio_clocks[pio].recovery << 4) | | ||
101 | (cs5520_pio_clocks[pio].assert)); | ||
102 | |||
103 | /* 0x64 - 16bit Primary, 0x68 - 16bit Secondary */ | ||
104 | |||
105 | /* FIXME: should these use address ? */ | ||
106 | /* Data read timing */ | ||
107 | pci_write_config_byte(pdev, 0x64 + 4*controller + (drive->dn&1), | ||
108 | (cs5520_pio_clocks[pio].recovery << 4) | | ||
109 | (cs5520_pio_clocks[pio].assert)); | ||
110 | /* Write command timing */ | ||
111 | pci_write_config_byte(pdev, 0x66 + 4*controller + (drive->dn&1), | ||
112 | (cs5520_pio_clocks[pio].recovery << 4) | | ||
113 | (cs5520_pio_clocks[pio].assert)); | ||
114 | |||
115 | /* Set the DMA enable/disable flag */ | ||
116 | reg = inb(hwif->dma_base + 0x02 + 8*controller); | ||
117 | reg |= 1<<((drive->dn&1)+5); | ||
118 | outb(reg, hwif->dma_base + 0x02 + 8*controller); | ||
119 | |||
120 | error = ide_config_drive_speed(drive, speed); | ||
121 | /* ATAPI is harder so leave it for now */ | ||
122 | if(!error && drive->media == ide_disk) | ||
123 | error = hwif->ide_dma_on(drive); | ||
124 | |||
125 | return error; | ||
126 | } | ||
127 | |||
128 | static void cs5520_tune_drive(ide_drive_t *drive, u8 pio) | ||
129 | { | ||
130 | pio = ide_get_best_pio_mode(drive, pio, 4, NULL); | ||
131 | cs5520_tune_chipset(drive, (XFER_PIO_0 + pio)); | ||
132 | } | ||
133 | |||
134 | static int cs5520_config_drive_xfer_rate(ide_drive_t *drive) | ||
135 | { | ||
136 | ide_hwif_t *hwif = HWIF(drive); | ||
137 | |||
138 | /* Tune the drive for PIO modes up to PIO 4 */ | ||
139 | cs5520_tune_drive(drive, 4); | ||
140 | /* Then tell the core to use DMA operations */ | ||
141 | return hwif->ide_dma_on(drive); | ||
142 | } | ||
143 | |||
144 | /* | ||
145 | * We provide a callback for our nonstandard DMA location | ||
146 | */ | ||
147 | |||
148 | static void __devinit cs5520_init_setup_dma(struct pci_dev *dev, ide_pci_device_t *d, ide_hwif_t *hwif) | ||
149 | { | ||
150 | unsigned long bmide = pci_resource_start(dev, 2); /* Not the usual 4 */ | ||
151 | if(hwif->mate && hwif->mate->dma_base) /* Second channel at primary + 8 */ | ||
152 | bmide += 8; | ||
153 | ide_setup_dma(hwif, bmide, 8); | ||
154 | } | ||
155 | |||
156 | /* | ||
157 | * We wrap the DMA activate to set the vdma flag. This is needed | ||
158 | * so that the IDE DMA layer issues PIO not DMA commands over the | ||
159 | * DMA channel | ||
160 | */ | ||
161 | |||
162 | static int cs5520_dma_on(ide_drive_t *drive) | ||
163 | { | ||
164 | drive->vdma = 1; | ||
165 | return 0; | ||
166 | } | ||
167 | |||
168 | static void __devinit init_hwif_cs5520(ide_hwif_t *hwif) | ||
169 | { | ||
170 | hwif->tuneproc = &cs5520_tune_drive; | ||
171 | hwif->speedproc = &cs5520_tune_chipset; | ||
172 | hwif->ide_dma_check = &cs5520_config_drive_xfer_rate; | ||
173 | hwif->ide_dma_on = &cs5520_dma_on; | ||
174 | |||
175 | if(!noautodma) | ||
176 | hwif->autodma = 1; | ||
177 | |||
178 | if(!hwif->dma_base) | ||
179 | { | ||
180 | hwif->drives[0].autotune = 1; | ||
181 | hwif->drives[1].autotune = 1; | ||
182 | return; | ||
183 | } | ||
184 | |||
185 | hwif->atapi_dma = 0; | ||
186 | hwif->ultra_mask = 0; | ||
187 | hwif->swdma_mask = 0; | ||
188 | hwif->mwdma_mask = 0; | ||
189 | |||
190 | hwif->drives[0].autodma = hwif->autodma; | ||
191 | hwif->drives[1].autodma = hwif->autodma; | ||
192 | } | ||
193 | |||
194 | #define DECLARE_CS_DEV(name_str) \ | ||
195 | { \ | ||
196 | .name = name_str, \ | ||
197 | .init_setup_dma = cs5520_init_setup_dma, \ | ||
198 | .init_hwif = init_hwif_cs5520, \ | ||
199 | .channels = 2, \ | ||
200 | .autodma = AUTODMA, \ | ||
201 | .bootable = ON_BOARD, \ | ||
202 | .flags = IDEPCI_FLAG_ISA_PORTS, \ | ||
203 | } | ||
204 | |||
205 | static ide_pci_device_t cyrix_chipsets[] __devinitdata = { | ||
206 | /* 0 */ DECLARE_CS_DEV("Cyrix 5510"), | ||
207 | /* 1 */ DECLARE_CS_DEV("Cyrix 5520") | ||
208 | }; | ||
209 | |||
210 | /* | ||
211 | * The 5510/5520 are a bit weird. They don't quite set up the way | ||
212 | * the PCI helper layer expects so we must do much of the set up | ||
213 | * work longhand. | ||
214 | */ | ||
215 | |||
216 | static int __devinit cs5520_init_one(struct pci_dev *dev, const struct pci_device_id *id) | ||
217 | { | ||
218 | ata_index_t index; | ||
219 | ide_pci_device_t *d = &cyrix_chipsets[id->driver_data]; | ||
220 | |||
221 | ide_setup_pci_noise(dev, d); | ||
222 | |||
223 | /* We must not grab the entire device, it has 'ISA' space in its | ||
224 | BARS too and we will freak out other bits of the kernel */ | ||
225 | if(pci_enable_device_bars(dev, 1<<2)) | ||
226 | { | ||
227 | printk(KERN_WARNING "%s: Unable to enable 55x0.\n", d->name); | ||
228 | return 1; | ||
229 | } | ||
230 | pci_set_master(dev); | ||
231 | if (pci_set_dma_mask(dev, DMA_32BIT_MASK)) { | ||
232 | printk(KERN_WARNING "cs5520: No suitable DMA available.\n"); | ||
233 | return -ENODEV; | ||
234 | } | ||
235 | |||
236 | index.all = 0xf0f0; | ||
237 | |||
238 | /* | ||
239 | * Now the chipset is configured we can let the core | ||
240 | * do all the device setup for us | ||
241 | */ | ||
242 | |||
243 | ide_pci_setup_ports(dev, d, 14, &index); | ||
244 | |||
245 | if((index.b.low & 0xf0) != 0xf0) | ||
246 | probe_hwif_init(&ide_hwifs[index.b.low]); | ||
247 | if((index.b.high & 0xf0) != 0xf0) | ||
248 | probe_hwif_init(&ide_hwifs[index.b.high]); | ||
249 | return 0; | ||
250 | } | ||
251 | |||
252 | static struct pci_device_id cs5520_pci_tbl[] = { | ||
253 | { PCI_VENDOR_ID_CYRIX, PCI_DEVICE_ID_CYRIX_5510, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, | ||
254 | { PCI_VENDOR_ID_CYRIX, PCI_DEVICE_ID_CYRIX_5520, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1}, | ||
255 | { 0, }, | ||
256 | }; | ||
257 | MODULE_DEVICE_TABLE(pci, cs5520_pci_tbl); | ||
258 | |||
259 | static struct pci_driver driver = { | ||
260 | .name = "Cyrix_IDE", | ||
261 | .id_table = cs5520_pci_tbl, | ||
262 | .probe = cs5520_init_one, | ||
263 | }; | ||
264 | |||
265 | static int cs5520_ide_init(void) | ||
266 | { | ||
267 | return ide_pci_register_driver(&driver); | ||
268 | } | ||
269 | |||
270 | module_init(cs5520_ide_init); | ||
271 | |||
272 | MODULE_AUTHOR("Alan Cox"); | ||
273 | MODULE_DESCRIPTION("PCI driver module for Cyrix 5510/5520 IDE"); | ||
274 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/ide/pci/cs5530.c b/drivers/ide/pci/cs5530.c new file mode 100644 index 000000000000..0381961db263 --- /dev/null +++ b/drivers/ide/pci/cs5530.c | |||
@@ -0,0 +1,384 @@ | |||
1 | /* | ||
2 | * linux/drivers/ide/pci/cs5530.c Version 0.7 Sept 10, 2002 | ||
3 | * | ||
4 | * Copyright (C) 2000 Andre Hedrick <andre@linux-ide.org> | ||
5 | * Ditto of GNU General Public License. | ||
6 | * | ||
7 | * Copyright (C) 2000 Mark Lord <mlord@pobox.com> | ||
8 | * May be copied or modified under the terms of the GNU General Public License | ||
9 | * | ||
10 | * Development of this chipset driver was funded | ||
11 | * by the nice folks at National Semiconductor. | ||
12 | * | ||
13 | * Documentation: | ||
14 | * CS5530 documentation available from National Semiconductor. | ||
15 | */ | ||
16 | |||
17 | #include <linux/config.h> | ||
18 | #include <linux/module.h> | ||
19 | #include <linux/types.h> | ||
20 | #include <linux/kernel.h> | ||
21 | #include <linux/delay.h> | ||
22 | #include <linux/timer.h> | ||
23 | #include <linux/mm.h> | ||
24 | #include <linux/ioport.h> | ||
25 | #include <linux/blkdev.h> | ||
26 | #include <linux/hdreg.h> | ||
27 | #include <linux/interrupt.h> | ||
28 | #include <linux/pci.h> | ||
29 | #include <linux/init.h> | ||
30 | #include <linux/ide.h> | ||
31 | #include <asm/io.h> | ||
32 | #include <asm/irq.h> | ||
33 | |||
34 | /** | ||
35 | * cs5530_xfer_set_mode - set a new transfer mode at the drive | ||
36 | * @drive: drive to tune | ||
37 | * @mode: new mode | ||
38 | * | ||
39 | * Logging wrapper to the IDE driver speed configuration. This can | ||
40 | * probably go away now. | ||
41 | */ | ||
42 | |||
43 | static int cs5530_set_xfer_mode (ide_drive_t *drive, u8 mode) | ||
44 | { | ||
45 | printk(KERN_DEBUG "%s: cs5530_set_xfer_mode(%s)\n", | ||
46 | drive->name, ide_xfer_verbose(mode)); | ||
47 | return (ide_config_drive_speed(drive, mode)); | ||
48 | } | ||
49 | |||
50 | /* | ||
51 | * Here are the standard PIO mode 0-4 timings for each "format". | ||
52 | * Format-0 uses fast data reg timings, with slower command reg timings. | ||
53 | * Format-1 uses fast timings for all registers, but won't work with all drives. | ||
54 | */ | ||
55 | static unsigned int cs5530_pio_timings[2][5] = { | ||
56 | {0x00009172, 0x00012171, 0x00020080, 0x00032010, 0x00040010}, | ||
57 | {0xd1329172, 0x71212171, 0x30200080, 0x20102010, 0x00100010} | ||
58 | }; | ||
59 | |||
60 | /* | ||
61 | * After chip reset, the PIO timings are set to 0x0000e132, which is not valid. | ||
62 | */ | ||
63 | #define CS5530_BAD_PIO(timings) (((timings)&~0x80000000)==0x0000e132) | ||
64 | #define CS5530_BASEREG(hwif) (((hwif)->dma_base & ~0xf) + ((hwif)->channel ? 0x30 : 0x20)) | ||
65 | |||
66 | /** | ||
67 | * cs5530_tuneproc - select/set PIO modes | ||
68 | * | ||
69 | * cs5530_tuneproc() handles selection/setting of PIO modes | ||
70 | * for both the chipset and drive. | ||
71 | * | ||
72 | * The ide_init_cs5530() routine guarantees that all drives | ||
73 | * will have valid default PIO timings set up before we get here. | ||
74 | */ | ||
75 | |||
76 | static void cs5530_tuneproc (ide_drive_t *drive, u8 pio) /* pio=255 means "autotune" */ | ||
77 | { | ||
78 | ide_hwif_t *hwif = HWIF(drive); | ||
79 | unsigned int format; | ||
80 | unsigned long basereg = CS5530_BASEREG(hwif); | ||
81 | static u8 modes[5] = { XFER_PIO_0, XFER_PIO_1, XFER_PIO_2, XFER_PIO_3, XFER_PIO_4}; | ||
82 | |||
83 | pio = ide_get_best_pio_mode(drive, pio, 4, NULL); | ||
84 | if (!cs5530_set_xfer_mode(drive, modes[pio])) { | ||
85 | format = (hwif->INL(basereg+4) >> 31) & 1; | ||
86 | hwif->OUTL(cs5530_pio_timings[format][pio], | ||
87 | basereg+(drive->select.b.unit<<3)); | ||
88 | } | ||
89 | } | ||
90 | |||
91 | /** | ||
92 | * cs5530_config_dma - select/set DMA and UDMA modes | ||
93 | * @drive: drive to tune | ||
94 | * | ||
95 | * cs5530_config_dma() handles selection/setting of DMA/UDMA modes | ||
96 | * for both the chipset and drive. The CS5530 has limitations about | ||
97 | * mixing DMA/UDMA on the same cable. | ||
98 | */ | ||
99 | |||
100 | static int cs5530_config_dma (ide_drive_t *drive) | ||
101 | { | ||
102 | int udma_ok = 1, mode = 0; | ||
103 | ide_hwif_t *hwif = HWIF(drive); | ||
104 | int unit = drive->select.b.unit; | ||
105 | ide_drive_t *mate = &hwif->drives[unit^1]; | ||
106 | struct hd_driveid *id = drive->id; | ||
107 | unsigned int reg, timings; | ||
108 | unsigned long basereg; | ||
109 | |||
110 | /* | ||
111 | * Default to DMA-off in case we run into trouble here. | ||
112 | */ | ||
113 | hwif->ide_dma_off_quietly(drive); | ||
114 | /* turn off DMA while we fiddle */ | ||
115 | hwif->ide_dma_host_off(drive); | ||
116 | /* clear DMA_capable bit */ | ||
117 | |||
118 | /* | ||
119 | * The CS5530 specifies that two drives sharing a cable cannot | ||
120 | * mix UDMA/MDMA. It has to be one or the other, for the pair, | ||
121 | * though different timings can still be chosen for each drive. | ||
122 | * We could set the appropriate timing bits on the fly, | ||
123 | * but that might be a bit confusing. So, for now we statically | ||
124 | * handle this requirement by looking at our mate drive to see | ||
125 | * what it is capable of, before choosing a mode for our own drive. | ||
126 | * | ||
127 | * Note: This relies on the fact we never fail from UDMA to MWDMA_2 | ||
128 | * but instead drop to PIO | ||
129 | */ | ||
130 | if (mate->present) { | ||
131 | struct hd_driveid *mateid = mate->id; | ||
132 | if (mateid && (mateid->capability & 1) && | ||
133 | !__ide_dma_bad_drive(mate)) { | ||
134 | if ((mateid->field_valid & 4) && | ||
135 | (mateid->dma_ultra & 7)) | ||
136 | udma_ok = 1; | ||
137 | else if ((mateid->field_valid & 2) && | ||
138 | (mateid->dma_mword & 7)) | ||
139 | udma_ok = 0; | ||
140 | else | ||
141 | udma_ok = 1; | ||
142 | } | ||
143 | } | ||
144 | |||
145 | /* | ||
146 | * Now see what the current drive is capable of, | ||
147 | * selecting UDMA only if the mate said it was ok. | ||
148 | */ | ||
149 | if (id && (id->capability & 1) && drive->autodma && | ||
150 | !__ide_dma_bad_drive(drive)) { | ||
151 | if (udma_ok && (id->field_valid & 4) && (id->dma_ultra & 7)) { | ||
152 | if (id->dma_ultra & 4) | ||
153 | mode = XFER_UDMA_2; | ||
154 | else if (id->dma_ultra & 2) | ||
155 | mode = XFER_UDMA_1; | ||
156 | else if (id->dma_ultra & 1) | ||
157 | mode = XFER_UDMA_0; | ||
158 | } | ||
159 | if (!mode && (id->field_valid & 2) && (id->dma_mword & 7)) { | ||
160 | if (id->dma_mword & 4) | ||
161 | mode = XFER_MW_DMA_2; | ||
162 | else if (id->dma_mword & 2) | ||
163 | mode = XFER_MW_DMA_1; | ||
164 | else if (id->dma_mword & 1) | ||
165 | mode = XFER_MW_DMA_0; | ||
166 | } | ||
167 | } | ||
168 | |||
169 | /* | ||
170 | * Tell the drive to switch to the new mode; abort on failure. | ||
171 | */ | ||
172 | if (!mode || cs5530_set_xfer_mode(drive, mode)) | ||
173 | return 1; /* failure */ | ||
174 | |||
175 | /* | ||
176 | * Now tune the chipset to match the drive: | ||
177 | */ | ||
178 | switch (mode) { | ||
179 | case XFER_UDMA_0: timings = 0x00921250; break; | ||
180 | case XFER_UDMA_1: timings = 0x00911140; break; | ||
181 | case XFER_UDMA_2: timings = 0x00911030; break; | ||
182 | case XFER_MW_DMA_0: timings = 0x00077771; break; | ||
183 | case XFER_MW_DMA_1: timings = 0x00012121; break; | ||
184 | case XFER_MW_DMA_2: timings = 0x00002020; break; | ||
185 | default: | ||
186 | printk(KERN_ERR "%s: cs5530_config_dma: huh? mode=%02x\n", | ||
187 | drive->name, mode); | ||
188 | return 1; /* failure */ | ||
189 | } | ||
190 | basereg = CS5530_BASEREG(hwif); | ||
191 | reg = hwif->INL(basereg+4); /* get drive0 config register */ | ||
192 | timings |= reg & 0x80000000; /* preserve PIO format bit */ | ||
193 | if (unit == 0) { /* are we configuring drive0? */ | ||
194 | hwif->OUTL(timings, basereg+4); /* write drive0 config register */ | ||
195 | } else { | ||
196 | if (timings & 0x00100000) | ||
197 | reg |= 0x00100000; /* enable UDMA timings for both drives */ | ||
198 | else | ||
199 | reg &= ~0x00100000; /* disable UDMA timings for both drives */ | ||
200 | hwif->OUTL(reg, basereg+4); /* write drive0 config register */ | ||
201 | hwif->OUTL(timings, basereg+12); /* write drive1 config register */ | ||
202 | } | ||
203 | (void) hwif->ide_dma_host_on(drive); | ||
204 | /* set DMA_capable bit */ | ||
205 | |||
206 | /* | ||
207 | * Finally, turn DMA on in software, and exit. | ||
208 | */ | ||
209 | return hwif->ide_dma_on(drive); /* success */ | ||
210 | } | ||
211 | |||
212 | /** | ||
213 | * init_chipset_5530 - set up 5530 bridge | ||
214 | * @dev: PCI device | ||
215 | * @name: device name | ||
216 | * | ||
217 | * Initialize the cs5530 bridge for reliable IDE DMA operation. | ||
218 | */ | ||
219 | |||
220 | static unsigned int __init init_chipset_cs5530 (struct pci_dev *dev, const char *name) | ||
221 | { | ||
222 | struct pci_dev *master_0 = NULL, *cs5530_0 = NULL; | ||
223 | unsigned long flags; | ||
224 | |||
225 | dev = NULL; | ||
226 | while ((dev = pci_find_device(PCI_VENDOR_ID_CYRIX, PCI_ANY_ID, dev)) != NULL) { | ||
227 | switch (dev->device) { | ||
228 | case PCI_DEVICE_ID_CYRIX_PCI_MASTER: | ||
229 | master_0 = dev; | ||
230 | break; | ||
231 | case PCI_DEVICE_ID_CYRIX_5530_LEGACY: | ||
232 | cs5530_0 = dev; | ||
233 | break; | ||
234 | } | ||
235 | } | ||
236 | if (!master_0) { | ||
237 | printk(KERN_ERR "%s: unable to locate PCI MASTER function\n", name); | ||
238 | return 0; | ||
239 | } | ||
240 | if (!cs5530_0) { | ||
241 | printk(KERN_ERR "%s: unable to locate CS5530 LEGACY function\n", name); | ||
242 | return 0; | ||
243 | } | ||
244 | |||
245 | spin_lock_irqsave(&ide_lock, flags); | ||
246 | /* all CPUs (there should only be one CPU with this chipset) */ | ||
247 | |||
248 | /* | ||
249 | * Enable BusMaster and MemoryWriteAndInvalidate for the cs5530: | ||
250 | * --> OR 0x14 into 16-bit PCI COMMAND reg of function 0 of the cs5530 | ||
251 | */ | ||
252 | |||
253 | pci_set_master(cs5530_0); | ||
254 | pci_set_mwi(cs5530_0); | ||
255 | |||
256 | /* | ||
257 | * Set PCI CacheLineSize to 16-bytes: | ||
258 | * --> Write 0x04 into 8-bit PCI CACHELINESIZE reg of function 0 of the cs5530 | ||
259 | */ | ||
260 | |||
261 | pci_write_config_byte(cs5530_0, PCI_CACHE_LINE_SIZE, 0x04); | ||
262 | |||
263 | /* | ||
264 | * Disable trapping of UDMA register accesses (Win98 hack): | ||
265 | * --> Write 0x5006 into 16-bit reg at offset 0xd0 of function 0 of the cs5530 | ||
266 | */ | ||
267 | |||
268 | pci_write_config_word(cs5530_0, 0xd0, 0x5006); | ||
269 | |||
270 | /* | ||
271 | * Bit-1 at 0x40 enables MemoryWriteAndInvalidate on internal X-bus: | ||
272 | * The other settings are what is necessary to get the register | ||
273 | * into a sane state for IDE DMA operation. | ||
274 | */ | ||
275 | |||
276 | pci_write_config_byte(master_0, 0x40, 0x1e); | ||
277 | |||
278 | /* | ||
279 | * Set max PCI burst size (16-bytes seems to work best): | ||
280 | * 16bytes: set bit-1 at 0x41 (reg value of 0x16) | ||
281 | * all others: clear bit-1 at 0x41, and do: | ||
282 | * 128bytes: OR 0x00 at 0x41 | ||
283 | * 256bytes: OR 0x04 at 0x41 | ||
284 | * 512bytes: OR 0x08 at 0x41 | ||
285 | * 1024bytes: OR 0x0c at 0x41 | ||
286 | */ | ||
287 | |||
288 | pci_write_config_byte(master_0, 0x41, 0x14); | ||
289 | |||
290 | /* | ||
291 | * These settings are necessary to get the chip | ||
292 | * into a sane state for IDE DMA operation. | ||
293 | */ | ||
294 | |||
295 | pci_write_config_byte(master_0, 0x42, 0x00); | ||
296 | pci_write_config_byte(master_0, 0x43, 0xc1); | ||
297 | |||
298 | spin_unlock_irqrestore(&ide_lock, flags); | ||
299 | |||
300 | return 0; | ||
301 | } | ||
302 | |||
303 | /** | ||
304 | * init_hwif_cs5530 - initialise an IDE channel | ||
305 | * @hwif: IDE to initialize | ||
306 | * | ||
307 | * This gets invoked by the IDE driver once for each channel. It | ||
308 | * performs channel-specific pre-initialization before drive probing. | ||
309 | */ | ||
310 | |||
311 | static void __init init_hwif_cs5530 (ide_hwif_t *hwif) | ||
312 | { | ||
313 | unsigned long basereg; | ||
314 | u32 d0_timings; | ||
315 | hwif->autodma = 0; | ||
316 | |||
317 | if (hwif->mate) | ||
318 | hwif->serialized = hwif->mate->serialized = 1; | ||
319 | |||
320 | hwif->tuneproc = &cs5530_tuneproc; | ||
321 | basereg = CS5530_BASEREG(hwif); | ||
322 | d0_timings = hwif->INL(basereg+0); | ||
323 | if (CS5530_BAD_PIO(d0_timings)) { | ||
324 | /* PIO timings not initialized? */ | ||
325 | hwif->OUTL(cs5530_pio_timings[(d0_timings>>31)&1][0], basereg+0); | ||
326 | if (!hwif->drives[0].autotune) | ||
327 | hwif->drives[0].autotune = 1; | ||
328 | /* needs autotuning later */ | ||
329 | } | ||
330 | if (CS5530_BAD_PIO(hwif->INL(basereg+8))) { | ||
331 | /* PIO timings not initialized? */ | ||
332 | hwif->OUTL(cs5530_pio_timings[(d0_timings>>31)&1][0], basereg+8); | ||
333 | if (!hwif->drives[1].autotune) | ||
334 | hwif->drives[1].autotune = 1; | ||
335 | /* needs autotuning later */ | ||
336 | } | ||
337 | |||
338 | hwif->atapi_dma = 1; | ||
339 | hwif->ultra_mask = 0x07; | ||
340 | hwif->mwdma_mask = 0x07; | ||
341 | |||
342 | hwif->ide_dma_check = &cs5530_config_dma; | ||
343 | if (!noautodma) | ||
344 | hwif->autodma = 1; | ||
345 | hwif->drives[0].autodma = hwif->autodma; | ||
346 | hwif->drives[1].autodma = hwif->autodma; | ||
347 | } | ||
348 | |||
349 | static ide_pci_device_t cs5530_chipset __devinitdata = { | ||
350 | .name = "CS5530", | ||
351 | .init_chipset = init_chipset_cs5530, | ||
352 | .init_hwif = init_hwif_cs5530, | ||
353 | .channels = 2, | ||
354 | .autodma = AUTODMA, | ||
355 | .bootable = ON_BOARD, | ||
356 | }; | ||
357 | |||
358 | static int __devinit cs5530_init_one(struct pci_dev *dev, const struct pci_device_id *id) | ||
359 | { | ||
360 | return ide_setup_pci_device(dev, &cs5530_chipset); | ||
361 | } | ||
362 | |||
363 | static struct pci_device_id cs5530_pci_tbl[] = { | ||
364 | { PCI_VENDOR_ID_CYRIX, PCI_DEVICE_ID_CYRIX_5530_IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, | ||
365 | { 0, }, | ||
366 | }; | ||
367 | MODULE_DEVICE_TABLE(pci, cs5530_pci_tbl); | ||
368 | |||
369 | static struct pci_driver driver = { | ||
370 | .name = "CS5530 IDE", | ||
371 | .id_table = cs5530_pci_tbl, | ||
372 | .probe = cs5530_init_one, | ||
373 | }; | ||
374 | |||
375 | static int cs5530_ide_init(void) | ||
376 | { | ||
377 | return ide_pci_register_driver(&driver); | ||
378 | } | ||
379 | |||
380 | module_init(cs5530_ide_init); | ||
381 | |||
382 | MODULE_AUTHOR("Mark Lord"); | ||
383 | MODULE_DESCRIPTION("PCI driver module for Cyrix/NS 5530 IDE"); | ||
384 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/ide/pci/cy82c693.c b/drivers/ide/pci/cy82c693.c new file mode 100644 index 000000000000..80d67e99ccb5 --- /dev/null +++ b/drivers/ide/pci/cy82c693.c | |||
@@ -0,0 +1,531 @@ | |||
1 | /* | ||
2 | * linux/drivers/ide/pci/cy82c693.c Version 0.40 Sep. 10, 2002 | ||
3 | * | ||
4 | * Copyright (C) 1998-2000 Andreas S. Krebs (akrebs@altavista.net), Maintainer | ||
5 | * Copyright (C) 1998-2002 Andre Hedrick <andre@linux-ide.org>, Integrator | ||
6 | * | ||
7 | * CYPRESS CY82C693 chipset IDE controller | ||
8 | * | ||
9 | * The CY82C693 chipset is used on Digital's PC-Alpha 164SX boards. | ||
10 | * Writing the driver was quite simple, since most of the job is | ||
11 | * done by the generic pci-ide support. | ||
12 | * The hard part was finding the CY82C693's datasheet on Cypress's | ||
13 | * web page :-(. But Altavista solved this problem :-). | ||
14 | * | ||
15 | * | ||
16 | * Notes: | ||
17 | * - I recently got a 16.8G IBM DTTA, so I was able to test it with | ||
18 | * a large and fast disk - the results look great, so I'd say the | ||
19 | * driver is working fine :-) | ||
20 | * hdparm -t reports 8.17 MB/sec at about 6% CPU usage for the DTTA | ||
21 | * - this is my first linux driver, so there's probably a lot of room | ||
22 | * for optimizations and bug fixing, so feel free to do it. | ||
23 | * - use idebus=xx parameter to set PCI bus speed - needed to calc | ||
24 | * timings for PIO modes (default will be 40) | ||
25 | * - if using PIO mode it's a good idea to set the PIO mode and | ||
26 | * 32-bit I/O support (if possible), e.g. hdparm -p2 -c1 /dev/hda | ||
27 | * - I had some problems with my IBM DHEA with PIO modes < 2 | ||
28 | * (lost interrupts) ????? | ||
29 | * - first tests with DMA look okay, they seem to work, but there is a | ||
30 | * problem with sound - the BusMaster IDE TimeOut should fixed this | ||
31 | * | ||
32 | * Ancient History: | ||
33 | * AMH@1999-08-24: v0.34 init_cy82c693_chip moved to pci_init_cy82c693 | ||
34 | * ASK@1999-01-23: v0.33 made a few minor code clean ups | ||
35 | * removed DMA clock speed setting by default | ||
36 | * added boot message | ||
37 | * ASK@1998-11-01: v0.32 added support to set BusMaster IDE TimeOut | ||
38 | * added support to set DMA Controller Clock Speed | ||
39 | * ASK@1998-10-31: v0.31 fixed problem with setting to high DMA modes | ||
40 | * on some drives. | ||
41 | * ASK@1998-10-29: v0.3 added support to set DMA modes | ||
42 | * ASK@1998-10-28: v0.2 added support to set PIO modes | ||
43 | * ASK@1998-10-27: v0.1 first version - chipset detection | ||
44 | * | ||
45 | */ | ||
46 | |||
47 | #include <linux/config.h> | ||
48 | #include <linux/module.h> | ||
49 | #include <linux/types.h> | ||
50 | #include <linux/pci.h> | ||
51 | #include <linux/delay.h> | ||
52 | #include <linux/ide.h> | ||
53 | #include <linux/init.h> | ||
54 | |||
55 | #include <asm/io.h> | ||
56 | |||
57 | /* the current version */ | ||
58 | #define CY82_VERSION "CY82C693U driver v0.34 99-13-12 Andreas S. Krebs (akrebs@altavista.net)" | ||
59 | |||
60 | /* | ||
61 | * The following are used to debug the driver. | ||
62 | */ | ||
63 | #define CY82C693_DEBUG_LOGS 0 | ||
64 | #define CY82C693_DEBUG_INFO 0 | ||
65 | |||
66 | /* define CY82C693_SETDMA_CLOCK to set DMA Controller Clock Speed to ATCLK */ | ||
67 | #undef CY82C693_SETDMA_CLOCK | ||
68 | |||
69 | /* | ||
70 | * NOTE: the value for busmaster timeout is tricky and I got it by | ||
71 | * trial and error! By using a to low value will cause DMA timeouts | ||
72 | * and drop IDE performance, and by using a to high value will cause | ||
73 | * audio playback to scatter. | ||
74 | * If you know a better value or how to calc it, please let me know. | ||
75 | */ | ||
76 | |||
77 | /* twice the value written in cy82c693ub datasheet */ | ||
78 | #define BUSMASTER_TIMEOUT 0x50 | ||
79 | /* | ||
80 | * the value above was tested on my machine and it seems to work okay | ||
81 | */ | ||
82 | |||
83 | /* here are the offset definitions for the registers */ | ||
84 | #define CY82_IDE_CMDREG 0x04 | ||
85 | #define CY82_IDE_ADDRSETUP 0x48 | ||
86 | #define CY82_IDE_MASTER_IOR 0x4C | ||
87 | #define CY82_IDE_MASTER_IOW 0x4D | ||
88 | #define CY82_IDE_SLAVE_IOR 0x4E | ||
89 | #define CY82_IDE_SLAVE_IOW 0x4F | ||
90 | #define CY82_IDE_MASTER_8BIT 0x50 | ||
91 | #define CY82_IDE_SLAVE_8BIT 0x51 | ||
92 | |||
93 | #define CY82_INDEX_PORT 0x22 | ||
94 | #define CY82_DATA_PORT 0x23 | ||
95 | |||
96 | #define CY82_INDEX_CTRLREG1 0x01 | ||
97 | #define CY82_INDEX_CHANNEL0 0x30 | ||
98 | #define CY82_INDEX_CHANNEL1 0x31 | ||
99 | #define CY82_INDEX_TIMEOUT 0x32 | ||
100 | |||
101 | /* the max PIO mode - from datasheet */ | ||
102 | #define CY82C693_MAX_PIO 4 | ||
103 | |||
104 | /* the min and max PCI bus speed in MHz - from datasheet */ | ||
105 | #define CY82C963_MIN_BUS_SPEED 25 | ||
106 | #define CY82C963_MAX_BUS_SPEED 33 | ||
107 | |||
108 | /* the struct for the PIO mode timings */ | ||
109 | typedef struct pio_clocks_s { | ||
110 | u8 address_time; /* Address setup (clocks) */ | ||
111 | u8 time_16r; /* clocks for 16bit IOR (0xF0=Active/data, 0x0F=Recovery) */ | ||
112 | u8 time_16w; /* clocks for 16bit IOW (0xF0=Active/data, 0x0F=Recovery) */ | ||
113 | u8 time_8; /* clocks for 8bit (0xF0=Active/data, 0x0F=Recovery) */ | ||
114 | } pio_clocks_t; | ||
115 | |||
116 | /* | ||
117 | * calc clocks using bus_speed | ||
118 | * returns (rounded up) time in bus clocks for time in ns | ||
119 | */ | ||
120 | static int calc_clk (int time, int bus_speed) | ||
121 | { | ||
122 | int clocks; | ||
123 | |||
124 | clocks = (time*bus_speed+999)/1000 -1; | ||
125 | |||
126 | if (clocks < 0) | ||
127 | clocks = 0; | ||
128 | |||
129 | if (clocks > 0x0F) | ||
130 | clocks = 0x0F; | ||
131 | |||
132 | return clocks; | ||
133 | } | ||
134 | |||
135 | /* | ||
136 | * compute the values for the clock registers for PIO | ||
137 | * mode and pci_clk [MHz] speed | ||
138 | * | ||
139 | * NOTE: for mode 0,1 and 2 drives 8-bit IDE command control registers are used | ||
140 | * for mode 3 and 4 drives 8 and 16-bit timings are the same | ||
141 | * | ||
142 | */ | ||
143 | static void compute_clocks (u8 pio, pio_clocks_t *p_pclk) | ||
144 | { | ||
145 | int clk1, clk2; | ||
146 | int bus_speed = system_bus_clock(); /* get speed of PCI bus */ | ||
147 | |||
148 | /* we don't check against CY82C693's min and max speed, | ||
149 | * so you can play with the idebus=xx parameter | ||
150 | */ | ||
151 | |||
152 | if (pio > CY82C693_MAX_PIO) | ||
153 | pio = CY82C693_MAX_PIO; | ||
154 | |||
155 | /* let's calc the address setup time clocks */ | ||
156 | p_pclk->address_time = (u8)calc_clk(ide_pio_timings[pio].setup_time, bus_speed); | ||
157 | |||
158 | /* let's calc the active and recovery time clocks */ | ||
159 | clk1 = calc_clk(ide_pio_timings[pio].active_time, bus_speed); | ||
160 | |||
161 | /* calc recovery timing */ | ||
162 | clk2 = ide_pio_timings[pio].cycle_time - | ||
163 | ide_pio_timings[pio].active_time - | ||
164 | ide_pio_timings[pio].setup_time; | ||
165 | |||
166 | clk2 = calc_clk(clk2, bus_speed); | ||
167 | |||
168 | clk1 = (clk1<<4)|clk2; /* combine active and recovery clocks */ | ||
169 | |||
170 | /* note: we use the same values for 16bit IOR and IOW | ||
171 | * those are all the same, since I don't have other | ||
172 | * timings than those from ide-lib.c | ||
173 | */ | ||
174 | |||
175 | p_pclk->time_16r = (u8)clk1; | ||
176 | p_pclk->time_16w = (u8)clk1; | ||
177 | |||
178 | /* what are good values for 8bit ?? */ | ||
179 | p_pclk->time_8 = (u8)clk1; | ||
180 | } | ||
181 | |||
182 | /* | ||
183 | * set DMA mode a specific channel for CY82C693 | ||
184 | */ | ||
185 | |||
186 | static void cy82c693_dma_enable (ide_drive_t *drive, int mode, int single) | ||
187 | { | ||
188 | u8 index = 0, data = 0; | ||
189 | |||
190 | if (mode>2) /* make sure we set a valid mode */ | ||
191 | mode = 2; | ||
192 | |||
193 | if (mode > drive->id->tDMA) /* to be absolutly sure we have a valid mode */ | ||
194 | mode = drive->id->tDMA; | ||
195 | |||
196 | index = (HWIF(drive)->channel==0) ? CY82_INDEX_CHANNEL0 : CY82_INDEX_CHANNEL1; | ||
197 | |||
198 | #if CY82C693_DEBUG_LOGS | ||
199 | /* for debug let's show the previous values */ | ||
200 | |||
201 | HWIF(drive)->OUTB(index, CY82_INDEX_PORT); | ||
202 | data = HWIF(drive)->INB(CY82_DATA_PORT); | ||
203 | |||
204 | printk (KERN_INFO "%s (ch=%d, dev=%d): DMA mode is %d (single=%d)\n", | ||
205 | drive->name, HWIF(drive)->channel, drive->select.b.unit, | ||
206 | (data&0x3), ((data>>2)&1)); | ||
207 | #endif /* CY82C693_DEBUG_LOGS */ | ||
208 | |||
209 | data = (u8)mode|(u8)(single<<2); | ||
210 | |||
211 | HWIF(drive)->OUTB(index, CY82_INDEX_PORT); | ||
212 | HWIF(drive)->OUTB(data, CY82_DATA_PORT); | ||
213 | |||
214 | #if CY82C693_DEBUG_INFO | ||
215 | printk(KERN_INFO "%s (ch=%d, dev=%d): set DMA mode to %d (single=%d)\n", | ||
216 | drive->name, HWIF(drive)->channel, drive->select.b.unit, | ||
217 | mode, single); | ||
218 | #endif /* CY82C693_DEBUG_INFO */ | ||
219 | |||
220 | /* | ||
221 | * note: below we set the value for Bus Master IDE TimeOut Register | ||
222 | * I'm not absolutly sure what this does, but it solved my problem | ||
223 | * with IDE DMA and sound, so I now can play sound and work with | ||
224 | * my IDE driver at the same time :-) | ||
225 | * | ||
226 | * If you know the correct (best) value for this register please | ||
227 | * let me know - ASK | ||
228 | */ | ||
229 | |||
230 | data = BUSMASTER_TIMEOUT; | ||
231 | HWIF(drive)->OUTB(CY82_INDEX_TIMEOUT, CY82_INDEX_PORT); | ||
232 | HWIF(drive)->OUTB(data, CY82_DATA_PORT); | ||
233 | |||
234 | #if CY82C693_DEBUG_INFO | ||
235 | printk (KERN_INFO "%s: Set IDE Bus Master TimeOut Register to 0x%X\n", | ||
236 | drive->name, data); | ||
237 | #endif /* CY82C693_DEBUG_INFO */ | ||
238 | } | ||
239 | |||
240 | /* | ||
241 | * used to set DMA mode for CY82C693 (single and multi modes) | ||
242 | */ | ||
243 | static int cy82c693_ide_dma_on (ide_drive_t *drive) | ||
244 | { | ||
245 | struct hd_driveid *id = drive->id; | ||
246 | |||
247 | #if CY82C693_DEBUG_INFO | ||
248 | printk (KERN_INFO "dma_on: %s\n", drive->name); | ||
249 | #endif /* CY82C693_DEBUG_INFO */ | ||
250 | |||
251 | if (id != NULL) { | ||
252 | /* Enable DMA on any drive that has DMA | ||
253 | * (multi or single) enabled | ||
254 | */ | ||
255 | if (id->field_valid & 2) { /* regular DMA */ | ||
256 | int mmode, smode; | ||
257 | |||
258 | mmode = id->dma_mword & (id->dma_mword >> 8); | ||
259 | smode = id->dma_1word & (id->dma_1word >> 8); | ||
260 | |||
261 | if (mmode != 0) { | ||
262 | /* enable multi */ | ||
263 | cy82c693_dma_enable(drive, (mmode >> 1), 0); | ||
264 | } else if (smode != 0) { | ||
265 | /* enable single */ | ||
266 | cy82c693_dma_enable(drive, (smode >> 1), 1); | ||
267 | } | ||
268 | } | ||
269 | } | ||
270 | return __ide_dma_on(drive); | ||
271 | } | ||
272 | |||
273 | /* | ||
274 | * tune ide drive - set PIO mode | ||
275 | */ | ||
276 | static void cy82c693_tune_drive (ide_drive_t *drive, u8 pio) | ||
277 | { | ||
278 | ide_hwif_t *hwif = HWIF(drive); | ||
279 | struct pci_dev *dev = hwif->pci_dev; | ||
280 | pio_clocks_t pclk; | ||
281 | unsigned int addrCtrl; | ||
282 | |||
283 | /* select primary or secondary channel */ | ||
284 | if (hwif->index > 0) { /* drive is on the secondary channel */ | ||
285 | dev = pci_find_slot(dev->bus->number, dev->devfn+1); | ||
286 | if (!dev) { | ||
287 | printk(KERN_ERR "%s: tune_drive: " | ||
288 | "Cannot find secondary interface!\n", | ||
289 | drive->name); | ||
290 | return; | ||
291 | } | ||
292 | } | ||
293 | |||
294 | #if CY82C693_DEBUG_LOGS | ||
295 | /* for debug let's show the register values */ | ||
296 | |||
297 | if (drive->select.b.unit == 0) { | ||
298 | /* | ||
299 | * get master drive registers | ||
300 | * address setup control register | ||
301 | * is 32 bit !!! | ||
302 | */ | ||
303 | pci_read_config_dword(dev, CY82_IDE_ADDRSETUP, &addrCtrl); | ||
304 | addrCtrl &= 0x0F; | ||
305 | |||
306 | /* now let's get the remaining registers */ | ||
307 | pci_read_config_byte(dev, CY82_IDE_MASTER_IOR, &pclk.time_16r); | ||
308 | pci_read_config_byte(dev, CY82_IDE_MASTER_IOW, &pclk.time_16w); | ||
309 | pci_read_config_byte(dev, CY82_IDE_MASTER_8BIT, &pclk.time_8); | ||
310 | } else { | ||
311 | /* | ||
312 | * set slave drive registers | ||
313 | * address setup control register | ||
314 | * is 32 bit !!! | ||
315 | */ | ||
316 | pci_read_config_dword(dev, CY82_IDE_ADDRSETUP, &addrCtrl); | ||
317 | |||
318 | addrCtrl &= 0xF0; | ||
319 | addrCtrl >>= 4; | ||
320 | |||
321 | /* now let's get the remaining registers */ | ||
322 | pci_read_config_byte(dev, CY82_IDE_SLAVE_IOR, &pclk.time_16r); | ||
323 | pci_read_config_byte(dev, CY82_IDE_SLAVE_IOW, &pclk.time_16w); | ||
324 | pci_read_config_byte(dev, CY82_IDE_SLAVE_8BIT, &pclk.time_8); | ||
325 | } | ||
326 | |||
327 | printk(KERN_INFO "%s (ch=%d, dev=%d): PIO timing is " | ||
328 | "(addr=0x%X, ior=0x%X, iow=0x%X, 8bit=0x%X)\n", | ||
329 | drive->name, hwif->channel, drive->select.b.unit, | ||
330 | addrCtrl, pclk.time_16r, pclk.time_16w, pclk.time_8); | ||
331 | #endif /* CY82C693_DEBUG_LOGS */ | ||
332 | |||
333 | /* first let's calc the pio modes */ | ||
334 | pio = ide_get_best_pio_mode(drive, pio, CY82C693_MAX_PIO, NULL); | ||
335 | |||
336 | #if CY82C693_DEBUG_INFO | ||
337 | printk (KERN_INFO "%s: Selected PIO mode %d\n", drive->name, pio); | ||
338 | #endif /* CY82C693_DEBUG_INFO */ | ||
339 | |||
340 | /* let's calc the values for this PIO mode */ | ||
341 | compute_clocks(pio, &pclk); | ||
342 | |||
343 | /* now let's write the clocks registers */ | ||
344 | if (drive->select.b.unit == 0) { | ||
345 | /* | ||
346 | * set master drive | ||
347 | * address setup control register | ||
348 | * is 32 bit !!! | ||
349 | */ | ||
350 | pci_read_config_dword(dev, CY82_IDE_ADDRSETUP, &addrCtrl); | ||
351 | |||
352 | addrCtrl &= (~0xF); | ||
353 | addrCtrl |= (unsigned int)pclk.address_time; | ||
354 | pci_write_config_dword(dev, CY82_IDE_ADDRSETUP, addrCtrl); | ||
355 | |||
356 | /* now let's set the remaining registers */ | ||
357 | pci_write_config_byte(dev, CY82_IDE_MASTER_IOR, pclk.time_16r); | ||
358 | pci_write_config_byte(dev, CY82_IDE_MASTER_IOW, pclk.time_16w); | ||
359 | pci_write_config_byte(dev, CY82_IDE_MASTER_8BIT, pclk.time_8); | ||
360 | |||
361 | addrCtrl &= 0xF; | ||
362 | } else { | ||
363 | /* | ||
364 | * set slave drive | ||
365 | * address setup control register | ||
366 | * is 32 bit !!! | ||
367 | */ | ||
368 | pci_read_config_dword(dev, CY82_IDE_ADDRSETUP, &addrCtrl); | ||
369 | |||
370 | addrCtrl &= (~0xF0); | ||
371 | addrCtrl |= ((unsigned int)pclk.address_time<<4); | ||
372 | pci_write_config_dword(dev, CY82_IDE_ADDRSETUP, addrCtrl); | ||
373 | |||
374 | /* now let's set the remaining registers */ | ||
375 | pci_write_config_byte(dev, CY82_IDE_SLAVE_IOR, pclk.time_16r); | ||
376 | pci_write_config_byte(dev, CY82_IDE_SLAVE_IOW, pclk.time_16w); | ||
377 | pci_write_config_byte(dev, CY82_IDE_SLAVE_8BIT, pclk.time_8); | ||
378 | |||
379 | addrCtrl >>= 4; | ||
380 | addrCtrl &= 0xF; | ||
381 | } | ||
382 | |||
383 | #if CY82C693_DEBUG_INFO | ||
384 | printk(KERN_INFO "%s (ch=%d, dev=%d): set PIO timing to " | ||
385 | "(addr=0x%X, ior=0x%X, iow=0x%X, 8bit=0x%X)\n", | ||
386 | drive->name, hwif->channel, drive->select.b.unit, | ||
387 | addrCtrl, pclk.time_16r, pclk.time_16w, pclk.time_8); | ||
388 | #endif /* CY82C693_DEBUG_INFO */ | ||
389 | } | ||
390 | |||
391 | /* | ||
392 | * this function is called during init and is used to setup the cy82c693 chip | ||
393 | */ | ||
394 | static unsigned int __init init_chipset_cy82c693(struct pci_dev *dev, const char *name) | ||
395 | { | ||
396 | if (PCI_FUNC(dev->devfn) != 1) | ||
397 | return 0; | ||
398 | |||
399 | #ifdef CY82C693_SETDMA_CLOCK | ||
400 | u8 data = 0; | ||
401 | #endif /* CY82C693_SETDMA_CLOCK */ | ||
402 | |||
403 | /* write info about this verion of the driver */ | ||
404 | printk(KERN_INFO CY82_VERSION "\n"); | ||
405 | |||
406 | #ifdef CY82C693_SETDMA_CLOCK | ||
407 | /* okay let's set the DMA clock speed */ | ||
408 | |||
409 | outb(CY82_INDEX_CTRLREG1, CY82_INDEX_PORT); | ||
410 | data = inb(CY82_DATA_PORT); | ||
411 | |||
412 | #if CY82C693_DEBUG_INFO | ||
413 | printk(KERN_INFO "%s: Peripheral Configuration Register: 0x%X\n", | ||
414 | name, data); | ||
415 | #endif /* CY82C693_DEBUG_INFO */ | ||
416 | |||
417 | /* | ||
418 | * for some reason sometimes the DMA controller | ||
419 | * speed is set to ATCLK/2 ???? - we fix this here | ||
420 | * | ||
421 | * note: i don't know what causes this strange behaviour, | ||
422 | * but even changing the dma speed doesn't solve it :-( | ||
423 | * the ide performance is still only half the normal speed | ||
424 | * | ||
425 | * if anybody knows what goes wrong with my machine, please | ||
426 | * let me know - ASK | ||
427 | */ | ||
428 | |||
429 | data |= 0x03; | ||
430 | |||
431 | outb(CY82_INDEX_CTRLREG1, CY82_INDEX_PORT); | ||
432 | outb(data, CY82_DATA_PORT); | ||
433 | |||
434 | #if CY82C693_DEBUG_INFO | ||
435 | printk (KERN_INFO "%s: New Peripheral Configuration Register: 0x%X\n", | ||
436 | name, data); | ||
437 | #endif /* CY82C693_DEBUG_INFO */ | ||
438 | |||
439 | #endif /* CY82C693_SETDMA_CLOCK */ | ||
440 | return 0; | ||
441 | } | ||
442 | |||
443 | /* | ||
444 | * the init function - called for each ide channel once | ||
445 | */ | ||
446 | static void __init init_hwif_cy82c693(ide_hwif_t *hwif) | ||
447 | { | ||
448 | hwif->autodma = 0; | ||
449 | |||
450 | hwif->chipset = ide_cy82c693; | ||
451 | hwif->tuneproc = &cy82c693_tune_drive; | ||
452 | |||
453 | if (!hwif->dma_base) { | ||
454 | hwif->drives[0].autotune = 1; | ||
455 | hwif->drives[1].autotune = 1; | ||
456 | return; | ||
457 | } | ||
458 | |||
459 | hwif->atapi_dma = 1; | ||
460 | hwif->mwdma_mask = 0x04; | ||
461 | hwif->swdma_mask = 0x04; | ||
462 | |||
463 | hwif->ide_dma_on = &cy82c693_ide_dma_on; | ||
464 | if (!noautodma) | ||
465 | hwif->autodma = 1; | ||
466 | hwif->drives[0].autodma = hwif->autodma; | ||
467 | hwif->drives[1].autodma = hwif->autodma; | ||
468 | } | ||
469 | |||
470 | static __initdata ide_hwif_t *primary; | ||
471 | |||
472 | void __init init_iops_cy82c693(ide_hwif_t *hwif) | ||
473 | { | ||
474 | if (PCI_FUNC(hwif->pci_dev->devfn) == 1) | ||
475 | primary = hwif; | ||
476 | else { | ||
477 | hwif->mate = primary; | ||
478 | hwif->channel = 1; | ||
479 | } | ||
480 | } | ||
481 | |||
482 | static ide_pci_device_t cy82c693_chipsets[] __devinitdata = { | ||
483 | { /* 0 */ | ||
484 | .name = "CY82C693", | ||
485 | .init_chipset = init_chipset_cy82c693, | ||
486 | .init_iops = init_iops_cy82c693, | ||
487 | .init_hwif = init_hwif_cy82c693, | ||
488 | .channels = 1, | ||
489 | .autodma = AUTODMA, | ||
490 | .bootable = ON_BOARD, | ||
491 | } | ||
492 | }; | ||
493 | |||
494 | static int __devinit cy82c693_init_one(struct pci_dev *dev, const struct pci_device_id *id) | ||
495 | { | ||
496 | ide_pci_device_t *d = &cy82c693_chipsets[id->driver_data]; | ||
497 | struct pci_dev *dev2; | ||
498 | int ret = -ENODEV; | ||
499 | |||
500 | /* CY82C693 is more than only a IDE controller. | ||
501 | Function 1 is primary IDE channel, function 2 - secondary. */ | ||
502 | if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE && | ||
503 | PCI_FUNC(dev->devfn) == 1) { | ||
504 | dev2 = pci_find_slot(dev->bus->number, dev->devfn + 1); | ||
505 | ret = ide_setup_pci_devices(dev, dev2, d); | ||
506 | } | ||
507 | return ret; | ||
508 | } | ||
509 | |||
510 | static struct pci_device_id cy82c693_pci_tbl[] = { | ||
511 | { PCI_VENDOR_ID_CONTAQ, PCI_DEVICE_ID_CONTAQ_82C693, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, | ||
512 | { 0, }, | ||
513 | }; | ||
514 | MODULE_DEVICE_TABLE(pci, cy82c693_pci_tbl); | ||
515 | |||
516 | static struct pci_driver driver = { | ||
517 | .name = "Cypress_IDE", | ||
518 | .id_table = cy82c693_pci_tbl, | ||
519 | .probe = cy82c693_init_one, | ||
520 | }; | ||
521 | |||
522 | static int cy82c693_ide_init(void) | ||
523 | { | ||
524 | return ide_pci_register_driver(&driver); | ||
525 | } | ||
526 | |||
527 | module_init(cy82c693_ide_init); | ||
528 | |||
529 | MODULE_AUTHOR("Andreas Krebs, Andre Hedrick"); | ||
530 | MODULE_DESCRIPTION("PCI driver module for the Cypress CY82C693 IDE"); | ||
531 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/ide/pci/generic.c b/drivers/ide/pci/generic.c new file mode 100644 index 000000000000..4565cc311ff3 --- /dev/null +++ b/drivers/ide/pci/generic.c | |||
@@ -0,0 +1,232 @@ | |||
1 | /* | ||
2 | * linux/drivers/ide/pci/generic.c Version 0.11 December 30, 2002 | ||
3 | * | ||
4 | * Copyright (C) 2001-2002 Andre Hedrick <andre@linux-ide.org> | ||
5 | * Portions (C) Copyright 2002 Red Hat Inc <alan@redhat.com> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify it | ||
8 | * under the terms of the GNU General Public License as published by the | ||
9 | * Free Software Foundation; either version 2, or (at your option) any | ||
10 | * later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, but | ||
13 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
15 | * General Public License for more details. | ||
16 | * | ||
17 | * For the avoidance of doubt the "preferred form" of this code is one which | ||
18 | * is in an open non patent encumbered format. Where cryptographic key signing | ||
19 | * forms part of the process of creating an executable the information | ||
20 | * including keys needed to generate an equivalently functional executable | ||
21 | * are deemed to be part of the source code. | ||
22 | */ | ||
23 | |||
24 | #undef REALLY_SLOW_IO /* most systems can safely undef this */ | ||
25 | |||
26 | #include <linux/config.h> /* for CONFIG_BLK_DEV_IDEPCI */ | ||
27 | #include <linux/types.h> | ||
28 | #include <linux/module.h> | ||
29 | #include <linux/kernel.h> | ||
30 | #include <linux/delay.h> | ||
31 | #include <linux/timer.h> | ||
32 | #include <linux/mm.h> | ||
33 | #include <linux/ioport.h> | ||
34 | #include <linux/blkdev.h> | ||
35 | #include <linux/hdreg.h> | ||
36 | #include <linux/pci.h> | ||
37 | #include <linux/ide.h> | ||
38 | #include <linux/init.h> | ||
39 | |||
40 | #include <asm/io.h> | ||
41 | |||
42 | static void __devinit init_hwif_generic (ide_hwif_t *hwif) | ||
43 | { | ||
44 | switch(hwif->pci_dev->device) { | ||
45 | case PCI_DEVICE_ID_UMC_UM8673F: | ||
46 | case PCI_DEVICE_ID_UMC_UM8886A: | ||
47 | case PCI_DEVICE_ID_UMC_UM8886BF: | ||
48 | hwif->irq = hwif->channel ? 15 : 14; | ||
49 | break; | ||
50 | default: | ||
51 | break; | ||
52 | } | ||
53 | |||
54 | if (!(hwif->dma_base)) | ||
55 | return; | ||
56 | |||
57 | hwif->atapi_dma = 1; | ||
58 | hwif->ultra_mask = 0x7f; | ||
59 | hwif->mwdma_mask = 0x07; | ||
60 | hwif->swdma_mask = 0x07; | ||
61 | |||
62 | if (!noautodma) | ||
63 | hwif->autodma = 1; | ||
64 | hwif->drives[0].autodma = hwif->autodma; | ||
65 | hwif->drives[1].autodma = hwif->autodma; | ||
66 | } | ||
67 | |||
68 | #if 0 | ||
69 | /* Logic to add back later on */ | ||
70 | |||
71 | if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE) { | ||
72 | ide_pci_device_t *unknown = unknown_chipset; | ||
73 | init_setup_unknown(dev, unknown); | ||
74 | return 1; | ||
75 | } | ||
76 | return 0; | ||
77 | #endif | ||
78 | |||
79 | static ide_pci_device_t generic_chipsets[] __devinitdata = { | ||
80 | { /* 0 */ | ||
81 | .name = "NS87410", | ||
82 | .init_hwif = init_hwif_generic, | ||
83 | .channels = 2, | ||
84 | .autodma = AUTODMA, | ||
85 | .enablebits = {{0x43,0x08,0x08}, {0x47,0x08,0x08}}, | ||
86 | .bootable = ON_BOARD, | ||
87 | },{ /* 1 */ | ||
88 | .name = "SAMURAI", | ||
89 | .init_hwif = init_hwif_generic, | ||
90 | .channels = 2, | ||
91 | .autodma = AUTODMA, | ||
92 | .bootable = ON_BOARD, | ||
93 | },{ /* 2 */ | ||
94 | .name = "HT6565", | ||
95 | .init_hwif = init_hwif_generic, | ||
96 | .channels = 2, | ||
97 | .autodma = AUTODMA, | ||
98 | .bootable = ON_BOARD, | ||
99 | },{ /* 3 */ | ||
100 | .name = "UM8673F", | ||
101 | .init_hwif = init_hwif_generic, | ||
102 | .channels = 2, | ||
103 | .autodma = NODMA, | ||
104 | .bootable = ON_BOARD, | ||
105 | },{ /* 4 */ | ||
106 | .name = "UM8886A", | ||
107 | .init_hwif = init_hwif_generic, | ||
108 | .channels = 2, | ||
109 | .autodma = NODMA, | ||
110 | .bootable = ON_BOARD, | ||
111 | },{ /* 5 */ | ||
112 | .name = "UM8886BF", | ||
113 | .init_hwif = init_hwif_generic, | ||
114 | .channels = 2, | ||
115 | .autodma = NODMA, | ||
116 | .bootable = ON_BOARD, | ||
117 | },{ /* 6 */ | ||
118 | .name = "HINT_IDE", | ||
119 | .init_hwif = init_hwif_generic, | ||
120 | .channels = 2, | ||
121 | .autodma = AUTODMA, | ||
122 | .bootable = ON_BOARD, | ||
123 | },{ /* 7 */ | ||
124 | .name = "VIA_IDE", | ||
125 | .init_hwif = init_hwif_generic, | ||
126 | .channels = 2, | ||
127 | .autodma = NOAUTODMA, | ||
128 | .bootable = ON_BOARD, | ||
129 | },{ /* 8 */ | ||
130 | .name = "OPTI621V", | ||
131 | .init_hwif = init_hwif_generic, | ||
132 | .channels = 2, | ||
133 | .autodma = NOAUTODMA, | ||
134 | .bootable = ON_BOARD, | ||
135 | },{ /* 9 */ | ||
136 | .name = "VIA8237SATA", | ||
137 | .init_hwif = init_hwif_generic, | ||
138 | .channels = 2, | ||
139 | .autodma = AUTODMA, | ||
140 | .bootable = OFF_BOARD, | ||
141 | },{ /* 10 */ | ||
142 | .name = "Piccolo0102", | ||
143 | .init_hwif = init_hwif_generic, | ||
144 | .channels = 2, | ||
145 | .autodma = NOAUTODMA, | ||
146 | .bootable = ON_BOARD, | ||
147 | },{ /* 11 */ | ||
148 | .name = "Piccolo0103", | ||
149 | .init_hwif = init_hwif_generic, | ||
150 | .channels = 2, | ||
151 | .autodma = NOAUTODMA, | ||
152 | .bootable = ON_BOARD, | ||
153 | },{ /* 12 */ | ||
154 | .name = "Piccolo0105", | ||
155 | .init_hwif = init_hwif_generic, | ||
156 | .channels = 2, | ||
157 | .autodma = NOAUTODMA, | ||
158 | .bootable = ON_BOARD, | ||
159 | } | ||
160 | }; | ||
161 | |||
162 | /** | ||
163 | * generic_init_one - called when a PIIX is found | ||
164 | * @dev: the generic device | ||
165 | * @id: the matching pci id | ||
166 | * | ||
167 | * Called when the PCI registration layer (or the IDE initialization) | ||
168 | * finds a device matching our IDE device tables. | ||
169 | */ | ||
170 | |||
171 | static int __devinit generic_init_one(struct pci_dev *dev, const struct pci_device_id *id) | ||
172 | { | ||
173 | ide_pci_device_t *d = &generic_chipsets[id->driver_data]; | ||
174 | u16 command; | ||
175 | int ret = -ENODEV; | ||
176 | |||
177 | if (dev->vendor == PCI_VENDOR_ID_UMC && | ||
178 | dev->device == PCI_DEVICE_ID_UMC_UM8886A && | ||
179 | (!(PCI_FUNC(dev->devfn) & 1))) | ||
180 | goto out; /* UM8886A/BF pair */ | ||
181 | |||
182 | if (dev->vendor == PCI_VENDOR_ID_OPTI && | ||
183 | dev->device == PCI_DEVICE_ID_OPTI_82C558 && | ||
184 | (!(PCI_FUNC(dev->devfn) & 1))) | ||
185 | goto out; | ||
186 | |||
187 | pci_read_config_word(dev, PCI_COMMAND, &command); | ||
188 | if (!(command & PCI_COMMAND_IO)) { | ||
189 | printk(KERN_INFO "Skipping disabled %s IDE controller.\n", d->name); | ||
190 | goto out; | ||
191 | } | ||
192 | ret = ide_setup_pci_device(dev, d); | ||
193 | out: | ||
194 | return ret; | ||
195 | } | ||
196 | |||
197 | static struct pci_device_id generic_pci_tbl[] = { | ||
198 | { PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_87410, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, | ||
199 | { PCI_VENDOR_ID_PCTECH, PCI_DEVICE_ID_PCTECH_SAMURAI_IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1}, | ||
200 | { PCI_VENDOR_ID_HOLTEK, PCI_DEVICE_ID_HOLTEK_6565, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2}, | ||
201 | { PCI_VENDOR_ID_UMC, PCI_DEVICE_ID_UMC_UM8673F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3}, | ||
202 | { PCI_VENDOR_ID_UMC, PCI_DEVICE_ID_UMC_UM8886A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4}, | ||
203 | { PCI_VENDOR_ID_UMC, PCI_DEVICE_ID_UMC_UM8886BF, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5}, | ||
204 | { PCI_VENDOR_ID_HINT, PCI_DEVICE_ID_HINT_VXPROII_IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 6}, | ||
205 | { PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C561, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 7}, | ||
206 | { PCI_VENDOR_ID_OPTI, PCI_DEVICE_ID_OPTI_82C558, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 8}, | ||
207 | #ifdef CONFIG_BLK_DEV_IDE_SATA | ||
208 | { PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237_SATA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 9}, | ||
209 | #endif | ||
210 | { PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 10}, | ||
211 | { PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 11}, | ||
212 | { PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 12}, | ||
213 | { 0, }, | ||
214 | }; | ||
215 | MODULE_DEVICE_TABLE(pci, generic_pci_tbl); | ||
216 | |||
217 | static struct pci_driver driver = { | ||
218 | .name = "PCI_IDE", | ||
219 | .id_table = generic_pci_tbl, | ||
220 | .probe = generic_init_one, | ||
221 | }; | ||
222 | |||
223 | static int generic_ide_init(void) | ||
224 | { | ||
225 | return ide_pci_register_driver(&driver); | ||
226 | } | ||
227 | |||
228 | module_init(generic_ide_init); | ||
229 | |||
230 | MODULE_AUTHOR("Andre Hedrick"); | ||
231 | MODULE_DESCRIPTION("PCI driver module for generic PCI IDE"); | ||
232 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/ide/pci/hpt34x.c b/drivers/ide/pci/hpt34x.c new file mode 100644 index 000000000000..bbde46279984 --- /dev/null +++ b/drivers/ide/pci/hpt34x.c | |||
@@ -0,0 +1,278 @@ | |||
1 | /* | ||
2 | * linux/drivers/ide/pci/hpt34x.c Version 0.40 Sept 10, 2002 | ||
3 | * | ||
4 | * Copyright (C) 1998-2000 Andre Hedrick <andre@linux-ide.org> | ||
5 | * May be copied or modified under the terms of the GNU General Public License | ||
6 | * | ||
7 | * | ||
8 | * 00:12.0 Unknown mass storage controller: | ||
9 | * Triones Technologies, Inc. | ||
10 | * Unknown device 0003 (rev 01) | ||
11 | * | ||
12 | * hde: UDMA 2 (0x0000 0x0002) (0x0000 0x0010) | ||
13 | * hdf: UDMA 2 (0x0002 0x0012) (0x0010 0x0030) | ||
14 | * hde: DMA 2 (0x0000 0x0002) (0x0000 0x0010) | ||
15 | * hdf: DMA 2 (0x0002 0x0012) (0x0010 0x0030) | ||
16 | * hdg: DMA 1 (0x0012 0x0052) (0x0030 0x0070) | ||
17 | * hdh: DMA 1 (0x0052 0x0252) (0x0070 0x00f0) | ||
18 | * | ||
19 | * ide-pci.c reference | ||
20 | * | ||
21 | * Since there are two cards that report almost identically, | ||
22 | * the only discernable difference is the values reported in pcicmd. | ||
23 | * Booting-BIOS card or HPT363 :: pcicmd == 0x07 | ||
24 | * Non-bootable card or HPT343 :: pcicmd == 0x05 | ||
25 | */ | ||
26 | |||
27 | #include <linux/config.h> | ||
28 | #include <linux/module.h> | ||
29 | #include <linux/types.h> | ||
30 | #include <linux/kernel.h> | ||
31 | #include <linux/delay.h> | ||
32 | #include <linux/timer.h> | ||
33 | #include <linux/mm.h> | ||
34 | #include <linux/ioport.h> | ||
35 | #include <linux/blkdev.h> | ||
36 | #include <linux/hdreg.h> | ||
37 | #include <linux/interrupt.h> | ||
38 | #include <linux/pci.h> | ||
39 | #include <linux/init.h> | ||
40 | #include <linux/ide.h> | ||
41 | |||
42 | #include <asm/io.h> | ||
43 | #include <asm/irq.h> | ||
44 | |||
45 | #define HPT343_DEBUG_DRIVE_INFO 0 | ||
46 | |||
47 | static u8 hpt34x_ratemask (ide_drive_t *drive) | ||
48 | { | ||
49 | return 1; | ||
50 | } | ||
51 | |||
52 | static void hpt34x_clear_chipset (ide_drive_t *drive) | ||
53 | { | ||
54 | struct pci_dev *dev = HWIF(drive)->pci_dev; | ||
55 | u32 reg1 = 0, tmp1 = 0, reg2 = 0, tmp2 = 0; | ||
56 | |||
57 | pci_read_config_dword(dev, 0x44, ®1); | ||
58 | pci_read_config_dword(dev, 0x48, ®2); | ||
59 | tmp1 = ((0x00 << (3*drive->dn)) | (reg1 & ~(7 << (3*drive->dn)))); | ||
60 | tmp2 = (reg2 & ~(0x11 << drive->dn)); | ||
61 | pci_write_config_dword(dev, 0x44, tmp1); | ||
62 | pci_write_config_dword(dev, 0x48, tmp2); | ||
63 | } | ||
64 | |||
65 | static int hpt34x_tune_chipset (ide_drive_t *drive, u8 xferspeed) | ||
66 | { | ||
67 | struct pci_dev *dev = HWIF(drive)->pci_dev; | ||
68 | u8 speed = ide_rate_filter(hpt34x_ratemask(drive), xferspeed); | ||
69 | u32 reg1= 0, tmp1 = 0, reg2 = 0, tmp2 = 0; | ||
70 | u8 hi_speed, lo_speed; | ||
71 | |||
72 | hi_speed = speed >> 4; | ||
73 | lo_speed = speed & 0x0f; | ||
74 | |||
75 | if (hi_speed & 7) { | ||
76 | hi_speed = (hi_speed & 4) ? 0x01 : 0x10; | ||
77 | } else { | ||
78 | lo_speed <<= 5; | ||
79 | lo_speed >>= 5; | ||
80 | } | ||
81 | |||
82 | pci_read_config_dword(dev, 0x44, ®1); | ||
83 | pci_read_config_dword(dev, 0x48, ®2); | ||
84 | tmp1 = ((lo_speed << (3*drive->dn)) | (reg1 & ~(7 << (3*drive->dn)))); | ||
85 | tmp2 = ((hi_speed << drive->dn) | reg2); | ||
86 | pci_write_config_dword(dev, 0x44, tmp1); | ||
87 | pci_write_config_dword(dev, 0x48, tmp2); | ||
88 | |||
89 | #if HPT343_DEBUG_DRIVE_INFO | ||
90 | printk("%s: %s drive%d (0x%04x 0x%04x) (0x%04x 0x%04x)" \ | ||
91 | " (0x%02x 0x%02x)\n", | ||
92 | drive->name, ide_xfer_verbose(speed), | ||
93 | drive->dn, reg1, tmp1, reg2, tmp2, | ||
94 | hi_speed, lo_speed); | ||
95 | #endif /* HPT343_DEBUG_DRIVE_INFO */ | ||
96 | |||
97 | return(ide_config_drive_speed(drive, speed)); | ||
98 | } | ||
99 | |||
100 | static void hpt34x_tune_drive (ide_drive_t *drive, u8 pio) | ||
101 | { | ||
102 | pio = ide_get_best_pio_mode(drive, pio, 5, NULL); | ||
103 | hpt34x_clear_chipset(drive); | ||
104 | (void) hpt34x_tune_chipset(drive, (XFER_PIO_0 + pio)); | ||
105 | } | ||
106 | |||
107 | /* | ||
108 | * This allows the configuration of ide_pci chipset registers | ||
109 | * for cards that learn about the drive's UDMA, DMA, PIO capabilities | ||
110 | * after the drive is reported by the OS. Initially for designed for | ||
111 | * HPT343 UDMA chipset by HighPoint|Triones Technologies, Inc. | ||
112 | */ | ||
113 | |||
114 | static int config_chipset_for_dma (ide_drive_t *drive) | ||
115 | { | ||
116 | u8 speed = ide_dma_speed(drive, hpt34x_ratemask(drive)); | ||
117 | |||
118 | if (!(speed)) | ||
119 | return 0; | ||
120 | |||
121 | hpt34x_clear_chipset(drive); | ||
122 | (void) hpt34x_tune_chipset(drive, speed); | ||
123 | return ide_dma_enable(drive); | ||
124 | } | ||
125 | |||
126 | static int hpt34x_config_drive_xfer_rate (ide_drive_t *drive) | ||
127 | { | ||
128 | ide_hwif_t *hwif = HWIF(drive); | ||
129 | struct hd_driveid *id = drive->id; | ||
130 | |||
131 | drive->init_speed = 0; | ||
132 | |||
133 | if (id && (id->capability & 1) && drive->autodma) { | ||
134 | |||
135 | if (ide_use_dma(drive)) { | ||
136 | if (config_chipset_for_dma(drive)) | ||
137 | #ifndef CONFIG_HPT34X_AUTODMA | ||
138 | return hwif->ide_dma_off_quietly(drive); | ||
139 | #else | ||
140 | return hwif->ide_dma_on(drive); | ||
141 | #endif | ||
142 | } | ||
143 | |||
144 | goto fast_ata_pio; | ||
145 | |||
146 | } else if ((id->capability & 8) || (id->field_valid & 2)) { | ||
147 | fast_ata_pio: | ||
148 | hpt34x_tune_drive(drive, 255); | ||
149 | return hwif->ide_dma_off_quietly(drive); | ||
150 | } | ||
151 | /* IORDY not supported */ | ||
152 | return 0; | ||
153 | } | ||
154 | |||
155 | /* | ||
156 | * If the BIOS does not set the IO base addaress to XX00, 343 will fail. | ||
157 | */ | ||
158 | #define HPT34X_PCI_INIT_REG 0x80 | ||
159 | |||
160 | static unsigned int __devinit init_chipset_hpt34x(struct pci_dev *dev, const char *name) | ||
161 | { | ||
162 | int i = 0; | ||
163 | unsigned long hpt34xIoBase = pci_resource_start(dev, 4); | ||
164 | unsigned long hpt_addr[4] = { 0x20, 0x34, 0x28, 0x3c }; | ||
165 | unsigned long hpt_addr_len[4] = { 7, 3, 7, 3 }; | ||
166 | u16 cmd; | ||
167 | unsigned long flags; | ||
168 | |||
169 | local_irq_save(flags); | ||
170 | |||
171 | pci_write_config_byte(dev, HPT34X_PCI_INIT_REG, 0x00); | ||
172 | pci_read_config_word(dev, PCI_COMMAND, &cmd); | ||
173 | |||
174 | if (cmd & PCI_COMMAND_MEMORY) { | ||
175 | if (pci_resource_start(dev, PCI_ROM_RESOURCE)) { | ||
176 | pci_write_config_byte(dev, PCI_ROM_ADDRESS, | ||
177 | dev->resource[PCI_ROM_RESOURCE].start | PCI_ROM_ADDRESS_ENABLE); | ||
178 | printk(KERN_INFO "HPT345: ROM enabled at 0x%08lx\n", | ||
179 | dev->resource[PCI_ROM_RESOURCE].start); | ||
180 | } | ||
181 | pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0xF0); | ||
182 | } else { | ||
183 | pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x20); | ||
184 | } | ||
185 | |||
186 | /* | ||
187 | * Since 20-23 can be assigned and are R/W, we correct them. | ||
188 | */ | ||
189 | pci_write_config_word(dev, PCI_COMMAND, cmd & ~PCI_COMMAND_IO); | ||
190 | for(i=0; i<4; i++) { | ||
191 | dev->resource[i].start = (hpt34xIoBase + hpt_addr[i]); | ||
192 | dev->resource[i].end = dev->resource[i].start + hpt_addr_len[i]; | ||
193 | dev->resource[i].flags = IORESOURCE_IO; | ||
194 | pci_write_config_dword(dev, | ||
195 | (PCI_BASE_ADDRESS_0 + (i * 4)), | ||
196 | dev->resource[i].start); | ||
197 | } | ||
198 | pci_write_config_word(dev, PCI_COMMAND, cmd); | ||
199 | |||
200 | local_irq_restore(flags); | ||
201 | |||
202 | return dev->irq; | ||
203 | } | ||
204 | |||
205 | static void __devinit init_hwif_hpt34x(ide_hwif_t *hwif) | ||
206 | { | ||
207 | u16 pcicmd = 0; | ||
208 | |||
209 | hwif->autodma = 0; | ||
210 | |||
211 | hwif->tuneproc = &hpt34x_tune_drive; | ||
212 | hwif->speedproc = &hpt34x_tune_chipset; | ||
213 | hwif->no_dsc = 1; | ||
214 | hwif->drives[0].autotune = 1; | ||
215 | hwif->drives[1].autotune = 1; | ||
216 | |||
217 | pci_read_config_word(hwif->pci_dev, PCI_COMMAND, &pcicmd); | ||
218 | |||
219 | if (!hwif->dma_base) | ||
220 | return; | ||
221 | |||
222 | hwif->ultra_mask = 0x07; | ||
223 | hwif->mwdma_mask = 0x07; | ||
224 | hwif->swdma_mask = 0x07; | ||
225 | |||
226 | hwif->ide_dma_check = &hpt34x_config_drive_xfer_rate; | ||
227 | if (!noautodma) | ||
228 | hwif->autodma = (pcicmd & PCI_COMMAND_MEMORY) ? 1 : 0; | ||
229 | hwif->drives[0].autodma = hwif->autodma; | ||
230 | hwif->drives[1].autodma = hwif->autodma; | ||
231 | } | ||
232 | |||
233 | static ide_pci_device_t hpt34x_chipset __devinitdata = { | ||
234 | .name = "HPT34X", | ||
235 | .init_chipset = init_chipset_hpt34x, | ||
236 | .init_hwif = init_hwif_hpt34x, | ||
237 | .channels = 2, | ||
238 | .autodma = NOAUTODMA, | ||
239 | .bootable = NEVER_BOARD, | ||
240 | .extra = 16 | ||
241 | }; | ||
242 | |||
243 | static int __devinit hpt34x_init_one(struct pci_dev *dev, const struct pci_device_id *id) | ||
244 | { | ||
245 | ide_pci_device_t *d = &hpt34x_chipset; | ||
246 | static char *chipset_names[] = {"HPT343", "HPT345"}; | ||
247 | u16 pcicmd = 0; | ||
248 | |||
249 | pci_read_config_word(dev, PCI_COMMAND, &pcicmd); | ||
250 | |||
251 | d->name = chipset_names[(pcicmd & PCI_COMMAND_MEMORY) ? 1 : 0]; | ||
252 | d->bootable = (pcicmd & PCI_COMMAND_MEMORY) ? OFF_BOARD : NEVER_BOARD; | ||
253 | |||
254 | return ide_setup_pci_device(dev, d); | ||
255 | } | ||
256 | |||
257 | static struct pci_device_id hpt34x_pci_tbl[] = { | ||
258 | { PCI_VENDOR_ID_TTI, PCI_DEVICE_ID_TTI_HPT343, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, | ||
259 | { 0, }, | ||
260 | }; | ||
261 | MODULE_DEVICE_TABLE(pci, hpt34x_pci_tbl); | ||
262 | |||
263 | static struct pci_driver driver = { | ||
264 | .name = "HPT34x_IDE", | ||
265 | .id_table = hpt34x_pci_tbl, | ||
266 | .probe = hpt34x_init_one, | ||
267 | }; | ||
268 | |||
269 | static int hpt34x_ide_init(void) | ||
270 | { | ||
271 | return ide_pci_register_driver(&driver); | ||
272 | } | ||
273 | |||
274 | module_init(hpt34x_ide_init); | ||
275 | |||
276 | MODULE_AUTHOR("Andre Hedrick"); | ||
277 | MODULE_DESCRIPTION("PCI driver module for Highpoint 34x IDE"); | ||
278 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/ide/pci/hpt366.c b/drivers/ide/pci/hpt366.c new file mode 100644 index 000000000000..c8ee0b8c0292 --- /dev/null +++ b/drivers/ide/pci/hpt366.c | |||
@@ -0,0 +1,1745 @@ | |||
1 | /* | ||
2 | * linux/drivers/ide/pci/hpt366.c Version 0.36 April 25, 2003 | ||
3 | * | ||
4 | * Copyright (C) 1999-2003 Andre Hedrick <andre@linux-ide.org> | ||
5 | * Portions Copyright (C) 2001 Sun Microsystems, Inc. | ||
6 | * Portions Copyright (C) 2003 Red Hat Inc | ||
7 | * | ||
8 | * Thanks to HighPoint Technologies for their assistance, and hardware. | ||
9 | * Special Thanks to Jon Burchmore in SanDiego for the deep pockets, his | ||
10 | * donation of an ABit BP6 mainboard, processor, and memory acellerated | ||
11 | * development and support. | ||
12 | * | ||
13 | * Note that final HPT370 support was done by force extraction of GPL. | ||
14 | * | ||
15 | * - add function for getting/setting power status of drive | ||
16 | * - the HPT370's state machine can get confused. reset it before each dma | ||
17 | * xfer to prevent that from happening. | ||
18 | * - reset state engine whenever we get an error. | ||
19 | * - check for busmaster state at end of dma. | ||
20 | * - use new highpoint timings. | ||
21 | * - detect bus speed using highpoint register. | ||
22 | * - use pll if we don't have a clock table. added a 66MHz table that's | ||
23 | * just 2x the 33MHz table. | ||
24 | * - removed turnaround. NOTE: we never want to switch between pll and | ||
25 | * pci clocks as the chip can glitch in those cases. the highpoint | ||
26 | * approved workaround slows everything down too much to be useful. in | ||
27 | * addition, we would have to serialize access to each chip. | ||
28 | * Adrian Sun <a.sun@sun.com> | ||
29 | * | ||
30 | * add drive timings for 66MHz PCI bus, | ||
31 | * fix ATA Cable signal detection, fix incorrect /proc info | ||
32 | * add /proc display for per-drive PIO/DMA/UDMA mode and | ||
33 | * per-channel ATA-33/66 Cable detect. | ||
34 | * Duncan Laurie <void@sun.com> | ||
35 | * | ||
36 | * fixup /proc output for multiple controllers | ||
37 | * Tim Hockin <thockin@sun.com> | ||
38 | * | ||
39 | * On hpt366: | ||
40 | * Reset the hpt366 on error, reset on dma | ||
41 | * Fix disabling Fast Interrupt hpt366. | ||
42 | * Mike Waychison <crlf@sun.com> | ||
43 | * | ||
44 | * Added support for 372N clocking and clock switching. The 372N needs | ||
45 | * different clocks on read/write. This requires overloading rw_disk and | ||
46 | * other deeply crazy things. Thanks to <http://www.hoerstreich.de> for | ||
47 | * keeping me sane. | ||
48 | * Alan Cox <alan@redhat.com> | ||
49 | * | ||
50 | */ | ||
51 | |||
52 | |||
53 | #include <linux/config.h> | ||
54 | #include <linux/types.h> | ||
55 | #include <linux/module.h> | ||
56 | #include <linux/kernel.h> | ||
57 | #include <linux/delay.h> | ||
58 | #include <linux/timer.h> | ||
59 | #include <linux/mm.h> | ||
60 | #include <linux/ioport.h> | ||
61 | #include <linux/blkdev.h> | ||
62 | #include <linux/hdreg.h> | ||
63 | |||
64 | #include <linux/interrupt.h> | ||
65 | #include <linux/pci.h> | ||
66 | #include <linux/init.h> | ||
67 | #include <linux/ide.h> | ||
68 | |||
69 | #include <asm/uaccess.h> | ||
70 | #include <asm/io.h> | ||
71 | #include <asm/irq.h> | ||
72 | |||
73 | /* various tuning parameters */ | ||
74 | #define HPT_RESET_STATE_ENGINE | ||
75 | #undef HPT_DELAY_INTERRUPT | ||
76 | #undef HPT_SERIALIZE_IO | ||
77 | |||
78 | static const char *quirk_drives[] = { | ||
79 | "QUANTUM FIREBALLlct08 08", | ||
80 | "QUANTUM FIREBALLP KA6.4", | ||
81 | "QUANTUM FIREBALLP LM20.4", | ||
82 | "QUANTUM FIREBALLP LM20.5", | ||
83 | NULL | ||
84 | }; | ||
85 | |||
86 | static const char *bad_ata100_5[] = { | ||
87 | "IBM-DTLA-307075", | ||
88 | "IBM-DTLA-307060", | ||
89 | "IBM-DTLA-307045", | ||
90 | "IBM-DTLA-307030", | ||
91 | "IBM-DTLA-307020", | ||
92 | "IBM-DTLA-307015", | ||
93 | "IBM-DTLA-305040", | ||
94 | "IBM-DTLA-305030", | ||
95 | "IBM-DTLA-305020", | ||
96 | "IC35L010AVER07-0", | ||
97 | "IC35L020AVER07-0", | ||
98 | "IC35L030AVER07-0", | ||
99 | "IC35L040AVER07-0", | ||
100 | "IC35L060AVER07-0", | ||
101 | "WDC AC310200R", | ||
102 | NULL | ||
103 | }; | ||
104 | |||
105 | static const char *bad_ata66_4[] = { | ||
106 | "IBM-DTLA-307075", | ||
107 | "IBM-DTLA-307060", | ||
108 | "IBM-DTLA-307045", | ||
109 | "IBM-DTLA-307030", | ||
110 | "IBM-DTLA-307020", | ||
111 | "IBM-DTLA-307015", | ||
112 | "IBM-DTLA-305040", | ||
113 | "IBM-DTLA-305030", | ||
114 | "IBM-DTLA-305020", | ||
115 | "IC35L010AVER07-0", | ||
116 | "IC35L020AVER07-0", | ||
117 | "IC35L030AVER07-0", | ||
118 | "IC35L040AVER07-0", | ||
119 | "IC35L060AVER07-0", | ||
120 | "WDC AC310200R", | ||
121 | NULL | ||
122 | }; | ||
123 | |||
124 | static const char *bad_ata66_3[] = { | ||
125 | "WDC AC310200R", | ||
126 | NULL | ||
127 | }; | ||
128 | |||
129 | static const char *bad_ata33[] = { | ||
130 | "Maxtor 92720U8", "Maxtor 92040U6", "Maxtor 91360U4", "Maxtor 91020U3", "Maxtor 90845U3", "Maxtor 90650U2", | ||
131 | "Maxtor 91360D8", "Maxtor 91190D7", "Maxtor 91020D6", "Maxtor 90845D5", "Maxtor 90680D4", "Maxtor 90510D3", "Maxtor 90340D2", | ||
132 | "Maxtor 91152D8", "Maxtor 91008D7", "Maxtor 90845D6", "Maxtor 90840D6", "Maxtor 90720D5", "Maxtor 90648D5", "Maxtor 90576D4", | ||
133 | "Maxtor 90510D4", | ||
134 | "Maxtor 90432D3", "Maxtor 90288D2", "Maxtor 90256D2", | ||
135 | "Maxtor 91000D8", "Maxtor 90910D8", "Maxtor 90875D7", "Maxtor 90840D7", "Maxtor 90750D6", "Maxtor 90625D5", "Maxtor 90500D4", | ||
136 | "Maxtor 91728D8", "Maxtor 91512D7", "Maxtor 91303D6", "Maxtor 91080D5", "Maxtor 90845D4", "Maxtor 90680D4", "Maxtor 90648D3", "Maxtor 90432D2", | ||
137 | NULL | ||
138 | }; | ||
139 | |||
140 | struct chipset_bus_clock_list_entry { | ||
141 | u8 xfer_speed; | ||
142 | unsigned int chipset_settings; | ||
143 | }; | ||
144 | |||
145 | /* key for bus clock timings | ||
146 | * bit | ||
147 | * 0:3 data_high_time. inactive time of DIOW_/DIOR_ for PIO and MW | ||
148 | * DMA. cycles = value + 1 | ||
149 | * 4:8 data_low_time. active time of DIOW_/DIOR_ for PIO and MW | ||
150 | * DMA. cycles = value + 1 | ||
151 | * 9:12 cmd_high_time. inactive time of DIOW_/DIOR_ during task file | ||
152 | * register access. | ||
153 | * 13:17 cmd_low_time. active time of DIOW_/DIOR_ during task file | ||
154 | * register access. | ||
155 | * 18:21 udma_cycle_time. clock freq and clock cycles for UDMA xfer. | ||
156 | * during task file register access. | ||
157 | * 22:24 pre_high_time. time to initialize 1st cycle for PIO and MW DMA | ||
158 | * xfer. | ||
159 | * 25:27 cmd_pre_high_time. time to initialize 1st PIO cycle for task | ||
160 | * register access. | ||
161 | * 28 UDMA enable | ||
162 | * 29 DMA enable | ||
163 | * 30 PIO_MST enable. if set, the chip is in bus master mode during | ||
164 | * PIO. | ||
165 | * 31 FIFO enable. | ||
166 | */ | ||
167 | static struct chipset_bus_clock_list_entry forty_base_hpt366[] = { | ||
168 | { XFER_UDMA_4, 0x900fd943 }, | ||
169 | { XFER_UDMA_3, 0x900ad943 }, | ||
170 | { XFER_UDMA_2, 0x900bd943 }, | ||
171 | { XFER_UDMA_1, 0x9008d943 }, | ||
172 | { XFER_UDMA_0, 0x9008d943 }, | ||
173 | |||
174 | { XFER_MW_DMA_2, 0xa008d943 }, | ||
175 | { XFER_MW_DMA_1, 0xa010d955 }, | ||
176 | { XFER_MW_DMA_0, 0xa010d9fc }, | ||
177 | |||
178 | { XFER_PIO_4, 0xc008d963 }, | ||
179 | { XFER_PIO_3, 0xc010d974 }, | ||
180 | { XFER_PIO_2, 0xc010d997 }, | ||
181 | { XFER_PIO_1, 0xc010d9c7 }, | ||
182 | { XFER_PIO_0, 0xc018d9d9 }, | ||
183 | { 0, 0x0120d9d9 } | ||
184 | }; | ||
185 | |||
186 | static struct chipset_bus_clock_list_entry thirty_three_base_hpt366[] = { | ||
187 | { XFER_UDMA_4, 0x90c9a731 }, | ||
188 | { XFER_UDMA_3, 0x90cfa731 }, | ||
189 | { XFER_UDMA_2, 0x90caa731 }, | ||
190 | { XFER_UDMA_1, 0x90cba731 }, | ||
191 | { XFER_UDMA_0, 0x90c8a731 }, | ||
192 | |||
193 | { XFER_MW_DMA_2, 0xa0c8a731 }, | ||
194 | { XFER_MW_DMA_1, 0xa0c8a732 }, /* 0xa0c8a733 */ | ||
195 | { XFER_MW_DMA_0, 0xa0c8a797 }, | ||
196 | |||
197 | { XFER_PIO_4, 0xc0c8a731 }, | ||
198 | { XFER_PIO_3, 0xc0c8a742 }, | ||
199 | { XFER_PIO_2, 0xc0d0a753 }, | ||
200 | { XFER_PIO_1, 0xc0d0a7a3 }, /* 0xc0d0a793 */ | ||
201 | { XFER_PIO_0, 0xc0d0a7aa }, /* 0xc0d0a7a7 */ | ||
202 | { 0, 0x0120a7a7 } | ||
203 | }; | ||
204 | |||
205 | static struct chipset_bus_clock_list_entry twenty_five_base_hpt366[] = { | ||
206 | { XFER_UDMA_4, 0x90c98521 }, | ||
207 | { XFER_UDMA_3, 0x90cf8521 }, | ||
208 | { XFER_UDMA_2, 0x90cf8521 }, | ||
209 | { XFER_UDMA_1, 0x90cb8521 }, | ||
210 | { XFER_UDMA_0, 0x90cb8521 }, | ||
211 | |||
212 | { XFER_MW_DMA_2, 0xa0ca8521 }, | ||
213 | { XFER_MW_DMA_1, 0xa0ca8532 }, | ||
214 | { XFER_MW_DMA_0, 0xa0ca8575 }, | ||
215 | |||
216 | { XFER_PIO_4, 0xc0ca8521 }, | ||
217 | { XFER_PIO_3, 0xc0ca8532 }, | ||
218 | { XFER_PIO_2, 0xc0ca8542 }, | ||
219 | { XFER_PIO_1, 0xc0d08572 }, | ||
220 | { XFER_PIO_0, 0xc0d08585 }, | ||
221 | { 0, 0x01208585 } | ||
222 | }; | ||
223 | |||
224 | /* from highpoint documentation. these are old values */ | ||
225 | static struct chipset_bus_clock_list_entry thirty_three_base_hpt370[] = { | ||
226 | /* { XFER_UDMA_5, 0x1A85F442, 0x16454e31 }, */ | ||
227 | { XFER_UDMA_5, 0x16454e31 }, | ||
228 | { XFER_UDMA_4, 0x16454e31 }, | ||
229 | { XFER_UDMA_3, 0x166d4e31 }, | ||
230 | { XFER_UDMA_2, 0x16494e31 }, | ||
231 | { XFER_UDMA_1, 0x164d4e31 }, | ||
232 | { XFER_UDMA_0, 0x16514e31 }, | ||
233 | |||
234 | { XFER_MW_DMA_2, 0x26514e21 }, | ||
235 | { XFER_MW_DMA_1, 0x26514e33 }, | ||
236 | { XFER_MW_DMA_0, 0x26514e97 }, | ||
237 | |||
238 | { XFER_PIO_4, 0x06514e21 }, | ||
239 | { XFER_PIO_3, 0x06514e22 }, | ||
240 | { XFER_PIO_2, 0x06514e33 }, | ||
241 | { XFER_PIO_1, 0x06914e43 }, | ||
242 | { XFER_PIO_0, 0x06914e57 }, | ||
243 | { 0, 0x06514e57 } | ||
244 | }; | ||
245 | |||
246 | static struct chipset_bus_clock_list_entry sixty_six_base_hpt370[] = { | ||
247 | { XFER_UDMA_5, 0x14846231 }, | ||
248 | { XFER_UDMA_4, 0x14886231 }, | ||
249 | { XFER_UDMA_3, 0x148c6231 }, | ||
250 | { XFER_UDMA_2, 0x148c6231 }, | ||
251 | { XFER_UDMA_1, 0x14906231 }, | ||
252 | { XFER_UDMA_0, 0x14986231 }, | ||
253 | |||
254 | { XFER_MW_DMA_2, 0x26514e21 }, | ||
255 | { XFER_MW_DMA_1, 0x26514e33 }, | ||
256 | { XFER_MW_DMA_0, 0x26514e97 }, | ||
257 | |||
258 | { XFER_PIO_4, 0x06514e21 }, | ||
259 | { XFER_PIO_3, 0x06514e22 }, | ||
260 | { XFER_PIO_2, 0x06514e33 }, | ||
261 | { XFER_PIO_1, 0x06914e43 }, | ||
262 | { XFER_PIO_0, 0x06914e57 }, | ||
263 | { 0, 0x06514e57 } | ||
264 | }; | ||
265 | |||
266 | /* these are the current (4 sep 2001) timings from highpoint */ | ||
267 | static struct chipset_bus_clock_list_entry thirty_three_base_hpt370a[] = { | ||
268 | { XFER_UDMA_5, 0x12446231 }, | ||
269 | { XFER_UDMA_4, 0x12446231 }, | ||
270 | { XFER_UDMA_3, 0x126c6231 }, | ||
271 | { XFER_UDMA_2, 0x12486231 }, | ||
272 | { XFER_UDMA_1, 0x124c6233 }, | ||
273 | { XFER_UDMA_0, 0x12506297 }, | ||
274 | |||
275 | { XFER_MW_DMA_2, 0x22406c31 }, | ||
276 | { XFER_MW_DMA_1, 0x22406c33 }, | ||
277 | { XFER_MW_DMA_0, 0x22406c97 }, | ||
278 | |||
279 | { XFER_PIO_4, 0x06414e31 }, | ||
280 | { XFER_PIO_3, 0x06414e42 }, | ||
281 | { XFER_PIO_2, 0x06414e53 }, | ||
282 | { XFER_PIO_1, 0x06814e93 }, | ||
283 | { XFER_PIO_0, 0x06814ea7 }, | ||
284 | { 0, 0x06814ea7 } | ||
285 | }; | ||
286 | |||
287 | /* 2x 33MHz timings */ | ||
288 | static struct chipset_bus_clock_list_entry sixty_six_base_hpt370a[] = { | ||
289 | { XFER_UDMA_5, 0x1488e673 }, | ||
290 | { XFER_UDMA_4, 0x1488e673 }, | ||
291 | { XFER_UDMA_3, 0x1498e673 }, | ||
292 | { XFER_UDMA_2, 0x1490e673 }, | ||
293 | { XFER_UDMA_1, 0x1498e677 }, | ||
294 | { XFER_UDMA_0, 0x14a0e73f }, | ||
295 | |||
296 | { XFER_MW_DMA_2, 0x2480fa73 }, | ||
297 | { XFER_MW_DMA_1, 0x2480fa77 }, | ||
298 | { XFER_MW_DMA_0, 0x2480fb3f }, | ||
299 | |||
300 | { XFER_PIO_4, 0x0c82be73 }, | ||
301 | { XFER_PIO_3, 0x0c82be95 }, | ||
302 | { XFER_PIO_2, 0x0c82beb7 }, | ||
303 | { XFER_PIO_1, 0x0d02bf37 }, | ||
304 | { XFER_PIO_0, 0x0d02bf5f }, | ||
305 | { 0, 0x0d02bf5f } | ||
306 | }; | ||
307 | |||
308 | static struct chipset_bus_clock_list_entry fifty_base_hpt370a[] = { | ||
309 | { XFER_UDMA_5, 0x12848242 }, | ||
310 | { XFER_UDMA_4, 0x12ac8242 }, | ||
311 | { XFER_UDMA_3, 0x128c8242 }, | ||
312 | { XFER_UDMA_2, 0x120c8242 }, | ||
313 | { XFER_UDMA_1, 0x12148254 }, | ||
314 | { XFER_UDMA_0, 0x121882ea }, | ||
315 | |||
316 | { XFER_MW_DMA_2, 0x22808242 }, | ||
317 | { XFER_MW_DMA_1, 0x22808254 }, | ||
318 | { XFER_MW_DMA_0, 0x228082ea }, | ||
319 | |||
320 | { XFER_PIO_4, 0x0a81f442 }, | ||
321 | { XFER_PIO_3, 0x0a81f443 }, | ||
322 | { XFER_PIO_2, 0x0a81f454 }, | ||
323 | { XFER_PIO_1, 0x0ac1f465 }, | ||
324 | { XFER_PIO_0, 0x0ac1f48a }, | ||
325 | { 0, 0x0ac1f48a } | ||
326 | }; | ||
327 | |||
328 | static struct chipset_bus_clock_list_entry thirty_three_base_hpt372[] = { | ||
329 | { XFER_UDMA_6, 0x1c81dc62 }, | ||
330 | { XFER_UDMA_5, 0x1c6ddc62 }, | ||
331 | { XFER_UDMA_4, 0x1c8ddc62 }, | ||
332 | { XFER_UDMA_3, 0x1c8edc62 }, /* checkme */ | ||
333 | { XFER_UDMA_2, 0x1c91dc62 }, | ||
334 | { XFER_UDMA_1, 0x1c9adc62 }, /* checkme */ | ||
335 | { XFER_UDMA_0, 0x1c82dc62 }, /* checkme */ | ||
336 | |||
337 | { XFER_MW_DMA_2, 0x2c829262 }, | ||
338 | { XFER_MW_DMA_1, 0x2c829266 }, /* checkme */ | ||
339 | { XFER_MW_DMA_0, 0x2c82922e }, /* checkme */ | ||
340 | |||
341 | { XFER_PIO_4, 0x0c829c62 }, | ||
342 | { XFER_PIO_3, 0x0c829c84 }, | ||
343 | { XFER_PIO_2, 0x0c829ca6 }, | ||
344 | { XFER_PIO_1, 0x0d029d26 }, | ||
345 | { XFER_PIO_0, 0x0d029d5e }, | ||
346 | { 0, 0x0d029d5e } | ||
347 | }; | ||
348 | |||
349 | static struct chipset_bus_clock_list_entry fifty_base_hpt372[] = { | ||
350 | { XFER_UDMA_5, 0x12848242 }, | ||
351 | { XFER_UDMA_4, 0x12ac8242 }, | ||
352 | { XFER_UDMA_3, 0x128c8242 }, | ||
353 | { XFER_UDMA_2, 0x120c8242 }, | ||
354 | { XFER_UDMA_1, 0x12148254 }, | ||
355 | { XFER_UDMA_0, 0x121882ea }, | ||
356 | |||
357 | { XFER_MW_DMA_2, 0x22808242 }, | ||
358 | { XFER_MW_DMA_1, 0x22808254 }, | ||
359 | { XFER_MW_DMA_0, 0x228082ea }, | ||
360 | |||
361 | { XFER_PIO_4, 0x0a81f442 }, | ||
362 | { XFER_PIO_3, 0x0a81f443 }, | ||
363 | { XFER_PIO_2, 0x0a81f454 }, | ||
364 | { XFER_PIO_1, 0x0ac1f465 }, | ||
365 | { XFER_PIO_0, 0x0ac1f48a }, | ||
366 | { 0, 0x0a81f443 } | ||
367 | }; | ||
368 | |||
369 | static struct chipset_bus_clock_list_entry sixty_six_base_hpt372[] = { | ||
370 | { XFER_UDMA_6, 0x1c869c62 }, | ||
371 | { XFER_UDMA_5, 0x1cae9c62 }, | ||
372 | { XFER_UDMA_4, 0x1c8a9c62 }, | ||
373 | { XFER_UDMA_3, 0x1c8e9c62 }, | ||
374 | { XFER_UDMA_2, 0x1c929c62 }, | ||
375 | { XFER_UDMA_1, 0x1c9a9c62 }, | ||
376 | { XFER_UDMA_0, 0x1c829c62 }, | ||
377 | |||
378 | { XFER_MW_DMA_2, 0x2c829c62 }, | ||
379 | { XFER_MW_DMA_1, 0x2c829c66 }, | ||
380 | { XFER_MW_DMA_0, 0x2c829d2e }, | ||
381 | |||
382 | { XFER_PIO_4, 0x0c829c62 }, | ||
383 | { XFER_PIO_3, 0x0c829c84 }, | ||
384 | { XFER_PIO_2, 0x0c829ca6 }, | ||
385 | { XFER_PIO_1, 0x0d029d26 }, | ||
386 | { XFER_PIO_0, 0x0d029d5e }, | ||
387 | { 0, 0x0d029d26 } | ||
388 | }; | ||
389 | |||
390 | static struct chipset_bus_clock_list_entry thirty_three_base_hpt374[] = { | ||
391 | { XFER_UDMA_6, 0x12808242 }, | ||
392 | { XFER_UDMA_5, 0x12848242 }, | ||
393 | { XFER_UDMA_4, 0x12ac8242 }, | ||
394 | { XFER_UDMA_3, 0x128c8242 }, | ||
395 | { XFER_UDMA_2, 0x120c8242 }, | ||
396 | { XFER_UDMA_1, 0x12148254 }, | ||
397 | { XFER_UDMA_0, 0x121882ea }, | ||
398 | |||
399 | { XFER_MW_DMA_2, 0x22808242 }, | ||
400 | { XFER_MW_DMA_1, 0x22808254 }, | ||
401 | { XFER_MW_DMA_0, 0x228082ea }, | ||
402 | |||
403 | { XFER_PIO_4, 0x0a81f442 }, | ||
404 | { XFER_PIO_3, 0x0a81f443 }, | ||
405 | { XFER_PIO_2, 0x0a81f454 }, | ||
406 | { XFER_PIO_1, 0x0ac1f465 }, | ||
407 | { XFER_PIO_0, 0x0ac1f48a }, | ||
408 | { 0, 0x06814e93 } | ||
409 | }; | ||
410 | |||
411 | /* FIXME: 50MHz timings for HPT374 */ | ||
412 | |||
413 | #if 0 | ||
414 | static struct chipset_bus_clock_list_entry sixty_six_base_hpt374[] = { | ||
415 | { XFER_UDMA_6, 0x12406231 }, /* checkme */ | ||
416 | { XFER_UDMA_5, 0x12446231 }, /* 0x14846231 */ | ||
417 | { XFER_UDMA_4, 0x16814ea7 }, /* 0x14886231 */ | ||
418 | { XFER_UDMA_3, 0x16814ea7 }, /* 0x148c6231 */ | ||
419 | { XFER_UDMA_2, 0x16814ea7 }, /* 0x148c6231 */ | ||
420 | { XFER_UDMA_1, 0x16814ea7 }, /* 0x14906231 */ | ||
421 | { XFER_UDMA_0, 0x16814ea7 }, /* 0x14986231 */ | ||
422 | { XFER_MW_DMA_2, 0x16814ea7 }, /* 0x26514e21 */ | ||
423 | { XFER_MW_DMA_1, 0x16814ea7 }, /* 0x26514e97 */ | ||
424 | { XFER_MW_DMA_0, 0x16814ea7 }, /* 0x26514e97 */ | ||
425 | { XFER_PIO_4, 0x06814ea7 }, /* 0x06514e21 */ | ||
426 | { XFER_PIO_3, 0x06814ea7 }, /* 0x06514e22 */ | ||
427 | { XFER_PIO_2, 0x06814ea7 }, /* 0x06514e33 */ | ||
428 | { XFER_PIO_1, 0x06814ea7 }, /* 0x06914e43 */ | ||
429 | { XFER_PIO_0, 0x06814ea7 }, /* 0x06914e57 */ | ||
430 | { 0, 0x06814ea7 } | ||
431 | }; | ||
432 | #endif | ||
433 | |||
434 | #define HPT366_DEBUG_DRIVE_INFO 0 | ||
435 | #define HPT374_ALLOW_ATA133_6 0 | ||
436 | #define HPT371_ALLOW_ATA133_6 0 | ||
437 | #define HPT302_ALLOW_ATA133_6 0 | ||
438 | #define HPT372_ALLOW_ATA133_6 1 | ||
439 | #define HPT370_ALLOW_ATA100_5 1 | ||
440 | #define HPT366_ALLOW_ATA66_4 1 | ||
441 | #define HPT366_ALLOW_ATA66_3 1 | ||
442 | #define HPT366_MAX_DEVS 8 | ||
443 | |||
444 | #define F_LOW_PCI_33 0x23 | ||
445 | #define F_LOW_PCI_40 0x29 | ||
446 | #define F_LOW_PCI_50 0x2d | ||
447 | #define F_LOW_PCI_66 0x42 | ||
448 | |||
449 | /* FIXME: compare with driver's code before removing */ | ||
450 | #if 0 | ||
451 | if (hpt_minimum_revision(dev, 3)) { | ||
452 | u8 cbl; | ||
453 | cbl = inb(iobase + 0x7b); | ||
454 | outb(cbl | 1, iobase + 0x7b); | ||
455 | outb(cbl & ~1, iobase + 0x7b); | ||
456 | cbl = inb(iobase + 0x7a); | ||
457 | p += sprintf(p, "Cable: ATA-%d" | ||
458 | " ATA-%d\n", | ||
459 | (cbl & 0x02) ? 33 : 66, | ||
460 | (cbl & 0x01) ? 33 : 66); | ||
461 | p += sprintf(p, "\n"); | ||
462 | } | ||
463 | { | ||
464 | u8 c2, c3; | ||
465 | /* older revs don't have these registers mapped | ||
466 | * into io space */ | ||
467 | pci_read_config_byte(dev, 0x43, &c0); | ||
468 | pci_read_config_byte(dev, 0x47, &c1); | ||
469 | pci_read_config_byte(dev, 0x4b, &c2); | ||
470 | pci_read_config_byte(dev, 0x4f, &c3); | ||
471 | |||
472 | p += sprintf(p, "Mode: %s %s" | ||
473 | " %s %s\n", | ||
474 | (c0 & 0x10) ? "UDMA" : (c0 & 0x20) ? "DMA " : | ||
475 | (c0 & 0x80) ? "PIO " : "off ", | ||
476 | (c1 & 0x10) ? "UDMA" : (c1 & 0x20) ? "DMA " : | ||
477 | (c1 & 0x80) ? "PIO " : "off ", | ||
478 | (c2 & 0x10) ? "UDMA" : (c2 & 0x20) ? "DMA " : | ||
479 | (c2 & 0x80) ? "PIO " : "off ", | ||
480 | (c3 & 0x10) ? "UDMA" : (c3 & 0x20) ? "DMA " : | ||
481 | (c3 & 0x80) ? "PIO " : "off "); | ||
482 | } | ||
483 | } | ||
484 | #endif | ||
485 | |||
486 | static u32 hpt_revision (struct pci_dev *dev) | ||
487 | { | ||
488 | u32 class_rev; | ||
489 | pci_read_config_dword(dev, PCI_CLASS_REVISION, &class_rev); | ||
490 | class_rev &= 0xff; | ||
491 | |||
492 | switch(dev->device) { | ||
493 | /* Remap new 372N onto 372 */ | ||
494 | case PCI_DEVICE_ID_TTI_HPT372N: | ||
495 | class_rev = PCI_DEVICE_ID_TTI_HPT372; break; | ||
496 | case PCI_DEVICE_ID_TTI_HPT374: | ||
497 | class_rev = PCI_DEVICE_ID_TTI_HPT374; break; | ||
498 | case PCI_DEVICE_ID_TTI_HPT371: | ||
499 | class_rev = PCI_DEVICE_ID_TTI_HPT371; break; | ||
500 | case PCI_DEVICE_ID_TTI_HPT302: | ||
501 | class_rev = PCI_DEVICE_ID_TTI_HPT302; break; | ||
502 | case PCI_DEVICE_ID_TTI_HPT372: | ||
503 | class_rev = PCI_DEVICE_ID_TTI_HPT372; break; | ||
504 | default: | ||
505 | break; | ||
506 | } | ||
507 | return class_rev; | ||
508 | } | ||
509 | |||
510 | static u32 hpt_minimum_revision (struct pci_dev *dev, int revision) | ||
511 | { | ||
512 | unsigned int class_rev = hpt_revision(dev); | ||
513 | revision--; | ||
514 | return ((int) (class_rev > revision) ? 1 : 0); | ||
515 | } | ||
516 | |||
517 | static int check_in_drive_lists(ide_drive_t *drive, const char **list); | ||
518 | |||
519 | static u8 hpt3xx_ratemask (ide_drive_t *drive) | ||
520 | { | ||
521 | struct pci_dev *dev = HWIF(drive)->pci_dev; | ||
522 | u8 mode = 0; | ||
523 | |||
524 | if (hpt_minimum_revision(dev, 8)) { /* HPT374 */ | ||
525 | mode = (HPT374_ALLOW_ATA133_6) ? 4 : 3; | ||
526 | } else if (hpt_minimum_revision(dev, 7)) { /* HPT371 */ | ||
527 | mode = (HPT371_ALLOW_ATA133_6) ? 4 : 3; | ||
528 | } else if (hpt_minimum_revision(dev, 6)) { /* HPT302 */ | ||
529 | mode = (HPT302_ALLOW_ATA133_6) ? 4 : 3; | ||
530 | } else if (hpt_minimum_revision(dev, 5)) { /* HPT372 */ | ||
531 | mode = (HPT372_ALLOW_ATA133_6) ? 4 : 3; | ||
532 | } else if (hpt_minimum_revision(dev, 4)) { /* HPT370A */ | ||
533 | mode = (HPT370_ALLOW_ATA100_5) ? 3 : 2; | ||
534 | } else if (hpt_minimum_revision(dev, 3)) { /* HPT370 */ | ||
535 | mode = (HPT370_ALLOW_ATA100_5) ? 3 : 2; | ||
536 | mode = (check_in_drive_lists(drive, bad_ata33)) ? 0 : mode; | ||
537 | } else { /* HPT366 and HPT368 */ | ||
538 | mode = (check_in_drive_lists(drive, bad_ata33)) ? 0 : 2; | ||
539 | } | ||
540 | if (!eighty_ninty_three(drive) && (mode)) | ||
541 | mode = min(mode, (u8)1); | ||
542 | return mode; | ||
543 | } | ||
544 | |||
545 | /* | ||
546 | * Note for the future; the SATA hpt37x we must set | ||
547 | * either PIO or UDMA modes 0,4,5 | ||
548 | */ | ||
549 | |||
550 | static u8 hpt3xx_ratefilter (ide_drive_t *drive, u8 speed) | ||
551 | { | ||
552 | struct pci_dev *dev = HWIF(drive)->pci_dev; | ||
553 | u8 mode = hpt3xx_ratemask(drive); | ||
554 | |||
555 | if (drive->media != ide_disk) | ||
556 | return min(speed, (u8)XFER_PIO_4); | ||
557 | |||
558 | switch(mode) { | ||
559 | case 0x04: | ||
560 | speed = min(speed, (u8)XFER_UDMA_6); | ||
561 | break; | ||
562 | case 0x03: | ||
563 | speed = min(speed, (u8)XFER_UDMA_5); | ||
564 | if (hpt_minimum_revision(dev, 5)) | ||
565 | break; | ||
566 | if (check_in_drive_lists(drive, bad_ata100_5)) | ||
567 | speed = min(speed, (u8)XFER_UDMA_4); | ||
568 | break; | ||
569 | case 0x02: | ||
570 | speed = min(speed, (u8)XFER_UDMA_4); | ||
571 | /* | ||
572 | * CHECK ME, Does this need to be set to 5 ?? | ||
573 | */ | ||
574 | if (hpt_minimum_revision(dev, 3)) | ||
575 | break; | ||
576 | if ((check_in_drive_lists(drive, bad_ata66_4)) || | ||
577 | (!(HPT366_ALLOW_ATA66_4))) | ||
578 | speed = min(speed, (u8)XFER_UDMA_3); | ||
579 | if ((check_in_drive_lists(drive, bad_ata66_3)) || | ||
580 | (!(HPT366_ALLOW_ATA66_3))) | ||
581 | speed = min(speed, (u8)XFER_UDMA_2); | ||
582 | break; | ||
583 | case 0x01: | ||
584 | speed = min(speed, (u8)XFER_UDMA_2); | ||
585 | /* | ||
586 | * CHECK ME, Does this need to be set to 5 ?? | ||
587 | */ | ||
588 | if (hpt_minimum_revision(dev, 3)) | ||
589 | break; | ||
590 | if (check_in_drive_lists(drive, bad_ata33)) | ||
591 | speed = min(speed, (u8)XFER_MW_DMA_2); | ||
592 | break; | ||
593 | case 0x00: | ||
594 | default: | ||
595 | speed = min(speed, (u8)XFER_MW_DMA_2); | ||
596 | break; | ||
597 | } | ||
598 | return speed; | ||
599 | } | ||
600 | |||
601 | static int check_in_drive_lists (ide_drive_t *drive, const char **list) | ||
602 | { | ||
603 | struct hd_driveid *id = drive->id; | ||
604 | |||
605 | if (quirk_drives == list) { | ||
606 | while (*list) | ||
607 | if (strstr(id->model, *list++)) | ||
608 | return 1; | ||
609 | } else { | ||
610 | while (*list) | ||
611 | if (!strcmp(*list++,id->model)) | ||
612 | return 1; | ||
613 | } | ||
614 | return 0; | ||
615 | } | ||
616 | |||
617 | static unsigned int pci_bus_clock_list (u8 speed, struct chipset_bus_clock_list_entry * chipset_table) | ||
618 | { | ||
619 | for ( ; chipset_table->xfer_speed ; chipset_table++) | ||
620 | if (chipset_table->xfer_speed == speed) | ||
621 | return chipset_table->chipset_settings; | ||
622 | return chipset_table->chipset_settings; | ||
623 | } | ||
624 | |||
625 | static int hpt36x_tune_chipset(ide_drive_t *drive, u8 xferspeed) | ||
626 | { | ||
627 | struct pci_dev *dev = HWIF(drive)->pci_dev; | ||
628 | u8 speed = hpt3xx_ratefilter(drive, xferspeed); | ||
629 | // u8 speed = ide_rate_filter(hpt3xx_ratemask(drive), xferspeed); | ||
630 | u8 regtime = (drive->select.b.unit & 0x01) ? 0x44 : 0x40; | ||
631 | u8 regfast = (HWIF(drive)->channel) ? 0x55 : 0x51; | ||
632 | u8 drive_fast = 0; | ||
633 | u32 reg1 = 0, reg2 = 0; | ||
634 | |||
635 | /* | ||
636 | * Disable the "fast interrupt" prediction. | ||
637 | */ | ||
638 | pci_read_config_byte(dev, regfast, &drive_fast); | ||
639 | #if 0 | ||
640 | if (drive_fast & 0x02) | ||
641 | pci_write_config_byte(dev, regfast, drive_fast & ~0x20); | ||
642 | #else | ||
643 | if (drive_fast & 0x80) | ||
644 | pci_write_config_byte(dev, regfast, drive_fast & ~0x80); | ||
645 | #endif | ||
646 | |||
647 | reg2 = pci_bus_clock_list(speed, | ||
648 | (struct chipset_bus_clock_list_entry *) pci_get_drvdata(dev)); | ||
649 | /* | ||
650 | * Disable on-chip PIO FIFO/buffer | ||
651 | * (to avoid problems handling I/O errors later) | ||
652 | */ | ||
653 | pci_read_config_dword(dev, regtime, ®1); | ||
654 | if (speed >= XFER_MW_DMA_0) { | ||
655 | reg2 = (reg2 & ~0xc0000000) | (reg1 & 0xc0000000); | ||
656 | } else { | ||
657 | reg2 = (reg2 & ~0x30070000) | (reg1 & 0x30070000); | ||
658 | } | ||
659 | reg2 &= ~0x80000000; | ||
660 | |||
661 | pci_write_config_dword(dev, regtime, reg2); | ||
662 | |||
663 | return ide_config_drive_speed(drive, speed); | ||
664 | } | ||
665 | |||
666 | static int hpt370_tune_chipset(ide_drive_t *drive, u8 xferspeed) | ||
667 | { | ||
668 | struct pci_dev *dev = HWIF(drive)->pci_dev; | ||
669 | u8 speed = hpt3xx_ratefilter(drive, xferspeed); | ||
670 | // u8 speed = ide_rate_filter(hpt3xx_ratemask(drive), xferspeed); | ||
671 | u8 regfast = (HWIF(drive)->channel) ? 0x55 : 0x51; | ||
672 | u8 drive_pci = 0x40 + (drive->dn * 4); | ||
673 | u8 new_fast = 0, drive_fast = 0; | ||
674 | u32 list_conf = 0, drive_conf = 0; | ||
675 | u32 conf_mask = (speed >= XFER_MW_DMA_0) ? 0xc0000000 : 0x30070000; | ||
676 | |||
677 | /* | ||
678 | * Disable the "fast interrupt" prediction. | ||
679 | * don't holdoff on interrupts. (== 0x01 despite what the docs say) | ||
680 | */ | ||
681 | pci_read_config_byte(dev, regfast, &drive_fast); | ||
682 | new_fast = drive_fast; | ||
683 | if (new_fast & 0x02) | ||
684 | new_fast &= ~0x02; | ||
685 | |||
686 | #ifdef HPT_DELAY_INTERRUPT | ||
687 | if (new_fast & 0x01) | ||
688 | new_fast &= ~0x01; | ||
689 | #else | ||
690 | if ((new_fast & 0x01) == 0) | ||
691 | new_fast |= 0x01; | ||
692 | #endif | ||
693 | if (new_fast != drive_fast) | ||
694 | pci_write_config_byte(dev, regfast, new_fast); | ||
695 | |||
696 | list_conf = pci_bus_clock_list(speed, | ||
697 | (struct chipset_bus_clock_list_entry *) | ||
698 | pci_get_drvdata(dev)); | ||
699 | |||
700 | pci_read_config_dword(dev, drive_pci, &drive_conf); | ||
701 | list_conf = (list_conf & ~conf_mask) | (drive_conf & conf_mask); | ||
702 | |||
703 | if (speed < XFER_MW_DMA_0) { | ||
704 | list_conf &= ~0x80000000; /* Disable on-chip PIO FIFO/buffer */ | ||
705 | } | ||
706 | |||
707 | pci_write_config_dword(dev, drive_pci, list_conf); | ||
708 | |||
709 | return ide_config_drive_speed(drive, speed); | ||
710 | } | ||
711 | |||
712 | static int hpt372_tune_chipset(ide_drive_t *drive, u8 xferspeed) | ||
713 | { | ||
714 | struct pci_dev *dev = HWIF(drive)->pci_dev; | ||
715 | u8 speed = hpt3xx_ratefilter(drive, xferspeed); | ||
716 | // u8 speed = ide_rate_filter(hpt3xx_ratemask(drive), xferspeed); | ||
717 | u8 regfast = (HWIF(drive)->channel) ? 0x55 : 0x51; | ||
718 | u8 drive_fast = 0, drive_pci = 0x40 + (drive->dn * 4); | ||
719 | u32 list_conf = 0, drive_conf = 0; | ||
720 | u32 conf_mask = (speed >= XFER_MW_DMA_0) ? 0xc0000000 : 0x30070000; | ||
721 | |||
722 | /* | ||
723 | * Disable the "fast interrupt" prediction. | ||
724 | * don't holdoff on interrupts. (== 0x01 despite what the docs say) | ||
725 | */ | ||
726 | pci_read_config_byte(dev, regfast, &drive_fast); | ||
727 | drive_fast &= ~0x07; | ||
728 | pci_write_config_byte(dev, regfast, drive_fast); | ||
729 | |||
730 | list_conf = pci_bus_clock_list(speed, | ||
731 | (struct chipset_bus_clock_list_entry *) | ||
732 | pci_get_drvdata(dev)); | ||
733 | pci_read_config_dword(dev, drive_pci, &drive_conf); | ||
734 | list_conf = (list_conf & ~conf_mask) | (drive_conf & conf_mask); | ||
735 | if (speed < XFER_MW_DMA_0) | ||
736 | list_conf &= ~0x80000000; /* Disable on-chip PIO FIFO/buffer */ | ||
737 | pci_write_config_dword(dev, drive_pci, list_conf); | ||
738 | |||
739 | return ide_config_drive_speed(drive, speed); | ||
740 | } | ||
741 | |||
742 | static int hpt3xx_tune_chipset (ide_drive_t *drive, u8 speed) | ||
743 | { | ||
744 | struct pci_dev *dev = HWIF(drive)->pci_dev; | ||
745 | |||
746 | if (hpt_minimum_revision(dev, 8)) | ||
747 | return hpt372_tune_chipset(drive, speed); /* not a typo */ | ||
748 | #if 0 | ||
749 | else if (hpt_minimum_revision(dev, 7)) | ||
750 | hpt371_tune_chipset(drive, speed); | ||
751 | else if (hpt_minimum_revision(dev, 6)) | ||
752 | hpt302_tune_chipset(drive, speed); | ||
753 | #endif | ||
754 | else if (hpt_minimum_revision(dev, 5)) | ||
755 | return hpt372_tune_chipset(drive, speed); | ||
756 | else if (hpt_minimum_revision(dev, 3)) | ||
757 | return hpt370_tune_chipset(drive, speed); | ||
758 | else /* hpt368: hpt_minimum_revision(dev, 2) */ | ||
759 | return hpt36x_tune_chipset(drive, speed); | ||
760 | } | ||
761 | |||
762 | static void hpt3xx_tune_drive (ide_drive_t *drive, u8 pio) | ||
763 | { | ||
764 | pio = ide_get_best_pio_mode(drive, 255, pio, NULL); | ||
765 | (void) hpt3xx_tune_chipset(drive, (XFER_PIO_0 + pio)); | ||
766 | } | ||
767 | |||
768 | /* | ||
769 | * This allows the configuration of ide_pci chipset registers | ||
770 | * for cards that learn about the drive's UDMA, DMA, PIO capabilities | ||
771 | * after the drive is reported by the OS. Initially for designed for | ||
772 | * HPT366 UDMA chipset by HighPoint|Triones Technologies, Inc. | ||
773 | * | ||
774 | * check_in_drive_lists(drive, bad_ata66_4) | ||
775 | * check_in_drive_lists(drive, bad_ata66_3) | ||
776 | * check_in_drive_lists(drive, bad_ata33) | ||
777 | * | ||
778 | */ | ||
779 | static int config_chipset_for_dma (ide_drive_t *drive) | ||
780 | { | ||
781 | u8 speed = ide_dma_speed(drive, hpt3xx_ratemask(drive)); | ||
782 | |||
783 | if (!(speed)) | ||
784 | return 0; | ||
785 | |||
786 | (void) hpt3xx_tune_chipset(drive, speed); | ||
787 | return ide_dma_enable(drive); | ||
788 | } | ||
789 | |||
790 | static int hpt3xx_quirkproc (ide_drive_t *drive) | ||
791 | { | ||
792 | return ((int) check_in_drive_lists(drive, quirk_drives)); | ||
793 | } | ||
794 | |||
795 | static void hpt3xx_intrproc (ide_drive_t *drive) | ||
796 | { | ||
797 | ide_hwif_t *hwif = HWIF(drive); | ||
798 | |||
799 | if (drive->quirk_list) | ||
800 | return; | ||
801 | /* drives in the quirk_list may not like intr setups/cleanups */ | ||
802 | hwif->OUTB(drive->ctl|2, IDE_CONTROL_REG); | ||
803 | } | ||
804 | |||
805 | static void hpt3xx_maskproc (ide_drive_t *drive, int mask) | ||
806 | { | ||
807 | struct pci_dev *dev = HWIF(drive)->pci_dev; | ||
808 | |||
809 | if (drive->quirk_list) { | ||
810 | if (hpt_minimum_revision(dev,3)) { | ||
811 | u8 reg5a = 0; | ||
812 | pci_read_config_byte(dev, 0x5a, ®5a); | ||
813 | if (((reg5a & 0x10) >> 4) != mask) | ||
814 | pci_write_config_byte(dev, 0x5a, mask ? (reg5a | 0x10) : (reg5a & ~0x10)); | ||
815 | } else { | ||
816 | if (mask) { | ||
817 | disable_irq(HWIF(drive)->irq); | ||
818 | } else { | ||
819 | enable_irq(HWIF(drive)->irq); | ||
820 | } | ||
821 | } | ||
822 | } else { | ||
823 | if (IDE_CONTROL_REG) | ||
824 | HWIF(drive)->OUTB(mask ? (drive->ctl | 2) : | ||
825 | (drive->ctl & ~2), | ||
826 | IDE_CONTROL_REG); | ||
827 | } | ||
828 | } | ||
829 | |||
830 | static int hpt366_config_drive_xfer_rate (ide_drive_t *drive) | ||
831 | { | ||
832 | ide_hwif_t *hwif = HWIF(drive); | ||
833 | struct hd_driveid *id = drive->id; | ||
834 | |||
835 | drive->init_speed = 0; | ||
836 | |||
837 | if (id && (id->capability & 1) && drive->autodma) { | ||
838 | |||
839 | if (ide_use_dma(drive)) { | ||
840 | if (config_chipset_for_dma(drive)) | ||
841 | return hwif->ide_dma_on(drive); | ||
842 | } | ||
843 | |||
844 | goto fast_ata_pio; | ||
845 | |||
846 | } else if ((id->capability & 8) || (id->field_valid & 2)) { | ||
847 | fast_ata_pio: | ||
848 | hpt3xx_tune_drive(drive, 5); | ||
849 | return hwif->ide_dma_off_quietly(drive); | ||
850 | } | ||
851 | /* IORDY not supported */ | ||
852 | return 0; | ||
853 | } | ||
854 | |||
855 | /* | ||
856 | * This is specific to the HPT366 UDMA bios chipset | ||
857 | * by HighPoint|Triones Technologies, Inc. | ||
858 | */ | ||
859 | static int hpt366_ide_dma_lostirq (ide_drive_t *drive) | ||
860 | { | ||
861 | struct pci_dev *dev = HWIF(drive)->pci_dev; | ||
862 | u8 reg50h = 0, reg52h = 0, reg5ah = 0; | ||
863 | |||
864 | pci_read_config_byte(dev, 0x50, ®50h); | ||
865 | pci_read_config_byte(dev, 0x52, ®52h); | ||
866 | pci_read_config_byte(dev, 0x5a, ®5ah); | ||
867 | printk("%s: (%s) reg50h=0x%02x, reg52h=0x%02x, reg5ah=0x%02x\n", | ||
868 | drive->name, __FUNCTION__, reg50h, reg52h, reg5ah); | ||
869 | if (reg5ah & 0x10) | ||
870 | pci_write_config_byte(dev, 0x5a, reg5ah & ~0x10); | ||
871 | #if 0 | ||
872 | /* how about we flush and reset, mmmkay? */ | ||
873 | pci_write_config_byte(dev, 0x51, 0x1F); | ||
874 | /* fall through to a reset */ | ||
875 | case dma_start: | ||
876 | case ide_dma_end: | ||
877 | /* reset the chips state over and over.. */ | ||
878 | pci_write_config_byte(dev, 0x51, 0x13); | ||
879 | #endif | ||
880 | return __ide_dma_lostirq(drive); | ||
881 | } | ||
882 | |||
883 | static void hpt370_clear_engine (ide_drive_t *drive) | ||
884 | { | ||
885 | u8 regstate = HWIF(drive)->channel ? 0x54 : 0x50; | ||
886 | pci_write_config_byte(HWIF(drive)->pci_dev, regstate, 0x37); | ||
887 | udelay(10); | ||
888 | } | ||
889 | |||
890 | static void hpt370_ide_dma_start(ide_drive_t *drive) | ||
891 | { | ||
892 | #ifdef HPT_RESET_STATE_ENGINE | ||
893 | hpt370_clear_engine(drive); | ||
894 | #endif | ||
895 | ide_dma_start(drive); | ||
896 | } | ||
897 | |||
898 | static int hpt370_ide_dma_end (ide_drive_t *drive) | ||
899 | { | ||
900 | ide_hwif_t *hwif = HWIF(drive); | ||
901 | u8 dma_stat = hwif->INB(hwif->dma_status); | ||
902 | |||
903 | if (dma_stat & 0x01) { | ||
904 | /* wait a little */ | ||
905 | udelay(20); | ||
906 | dma_stat = hwif->INB(hwif->dma_status); | ||
907 | } | ||
908 | if ((dma_stat & 0x01) != 0) | ||
909 | /* fallthrough */ | ||
910 | (void) HWIF(drive)->ide_dma_timeout(drive); | ||
911 | |||
912 | return __ide_dma_end(drive); | ||
913 | } | ||
914 | |||
915 | static void hpt370_lostirq_timeout (ide_drive_t *drive) | ||
916 | { | ||
917 | ide_hwif_t *hwif = HWIF(drive); | ||
918 | u8 bfifo = 0, reginfo = hwif->channel ? 0x56 : 0x52; | ||
919 | u8 dma_stat = 0, dma_cmd = 0; | ||
920 | |||
921 | pci_read_config_byte(HWIF(drive)->pci_dev, reginfo, &bfifo); | ||
922 | printk("%s: %d bytes in FIFO\n", drive->name, bfifo); | ||
923 | hpt370_clear_engine(drive); | ||
924 | /* get dma command mode */ | ||
925 | dma_cmd = hwif->INB(hwif->dma_command); | ||
926 | /* stop dma */ | ||
927 | hwif->OUTB(dma_cmd & ~0x1, hwif->dma_command); | ||
928 | dma_stat = hwif->INB(hwif->dma_status); | ||
929 | /* clear errors */ | ||
930 | hwif->OUTB(dma_stat | 0x6, hwif->dma_status); | ||
931 | } | ||
932 | |||
933 | static int hpt370_ide_dma_timeout (ide_drive_t *drive) | ||
934 | { | ||
935 | hpt370_lostirq_timeout(drive); | ||
936 | hpt370_clear_engine(drive); | ||
937 | return __ide_dma_timeout(drive); | ||
938 | } | ||
939 | |||
940 | static int hpt370_ide_dma_lostirq (ide_drive_t *drive) | ||
941 | { | ||
942 | hpt370_lostirq_timeout(drive); | ||
943 | hpt370_clear_engine(drive); | ||
944 | return __ide_dma_lostirq(drive); | ||
945 | } | ||
946 | |||
947 | /* returns 1 if DMA IRQ issued, 0 otherwise */ | ||
948 | static int hpt374_ide_dma_test_irq(ide_drive_t *drive) | ||
949 | { | ||
950 | ide_hwif_t *hwif = HWIF(drive); | ||
951 | u16 bfifo = 0; | ||
952 | u8 reginfo = hwif->channel ? 0x56 : 0x52; | ||
953 | u8 dma_stat; | ||
954 | |||
955 | pci_read_config_word(hwif->pci_dev, reginfo, &bfifo); | ||
956 | if (bfifo & 0x1FF) { | ||
957 | // printk("%s: %d bytes in FIFO\n", drive->name, bfifo); | ||
958 | return 0; | ||
959 | } | ||
960 | |||
961 | dma_stat = hwif->INB(hwif->dma_status); | ||
962 | /* return 1 if INTR asserted */ | ||
963 | if ((dma_stat & 4) == 4) | ||
964 | return 1; | ||
965 | |||
966 | if (!drive->waiting_for_dma) | ||
967 | printk(KERN_WARNING "%s: (%s) called while not waiting\n", | ||
968 | drive->name, __FUNCTION__); | ||
969 | return 0; | ||
970 | } | ||
971 | |||
972 | static int hpt374_ide_dma_end (ide_drive_t *drive) | ||
973 | { | ||
974 | struct pci_dev *dev = HWIF(drive)->pci_dev; | ||
975 | ide_hwif_t *hwif = HWIF(drive); | ||
976 | u8 msc_stat = 0, mscreg = hwif->channel ? 0x54 : 0x50; | ||
977 | u8 bwsr_stat = 0, bwsr_mask = hwif->channel ? 0x02 : 0x01; | ||
978 | |||
979 | pci_read_config_byte(dev, 0x6a, &bwsr_stat); | ||
980 | pci_read_config_byte(dev, mscreg, &msc_stat); | ||
981 | if ((bwsr_stat & bwsr_mask) == bwsr_mask) | ||
982 | pci_write_config_byte(dev, mscreg, msc_stat|0x30); | ||
983 | return __ide_dma_end(drive); | ||
984 | } | ||
985 | |||
986 | /** | ||
987 | * hpt372n_set_clock - perform clock switching dance | ||
988 | * @drive: Drive to switch | ||
989 | * @mode: Switching mode (0x21 for write, 0x23 otherwise) | ||
990 | * | ||
991 | * Switch the DPLL clock on the HPT372N devices. This is a | ||
992 | * right mess. | ||
993 | */ | ||
994 | |||
995 | static void hpt372n_set_clock(ide_drive_t *drive, int mode) | ||
996 | { | ||
997 | ide_hwif_t *hwif = HWIF(drive); | ||
998 | |||
999 | /* FIXME: should we check for DMA active and BUG() */ | ||
1000 | /* Tristate the bus */ | ||
1001 | outb(0x80, hwif->dma_base+0x73); | ||
1002 | outb(0x80, hwif->dma_base+0x77); | ||
1003 | |||
1004 | /* Switch clock and reset channels */ | ||
1005 | outb(mode, hwif->dma_base+0x7B); | ||
1006 | outb(0xC0, hwif->dma_base+0x79); | ||
1007 | |||
1008 | /* Reset state machines */ | ||
1009 | outb(0x37, hwif->dma_base+0x70); | ||
1010 | outb(0x37, hwif->dma_base+0x74); | ||
1011 | |||
1012 | /* Complete reset */ | ||
1013 | outb(0x00, hwif->dma_base+0x79); | ||
1014 | |||
1015 | /* Reconnect channels to bus */ | ||
1016 | outb(0x00, hwif->dma_base+0x73); | ||
1017 | outb(0x00, hwif->dma_base+0x77); | ||
1018 | } | ||
1019 | |||
1020 | /** | ||
1021 | * hpt372n_rw_disk - prepare for I/O | ||
1022 | * @drive: drive for command | ||
1023 | * @rq: block request structure | ||
1024 | * | ||
1025 | * This is called when a disk I/O is issued to the 372N. | ||
1026 | * We need it because of the clock switching. | ||
1027 | */ | ||
1028 | |||
1029 | static void hpt372n_rw_disk(ide_drive_t *drive, struct request *rq) | ||
1030 | { | ||
1031 | ide_hwif_t *hwif = drive->hwif; | ||
1032 | int wantclock; | ||
1033 | |||
1034 | wantclock = rq_data_dir(rq) ? 0x23 : 0x21; | ||
1035 | |||
1036 | if (hwif->config_data != wantclock) { | ||
1037 | hpt372n_set_clock(drive, wantclock); | ||
1038 | hwif->config_data = wantclock; | ||
1039 | } | ||
1040 | } | ||
1041 | |||
1042 | /* | ||
1043 | * Since SUN Cobalt is attempting to do this operation, I should disclose | ||
1044 | * this has been a long time ago Thu Jul 27 16:40:57 2000 was the patch date | ||
1045 | * HOTSWAP ATA Infrastructure. | ||
1046 | */ | ||
1047 | |||
1048 | static void hpt3xx_reset (ide_drive_t *drive) | ||
1049 | { | ||
1050 | #if 0 | ||
1051 | unsigned long high_16 = pci_resource_start(HWIF(drive)->pci_dev, 4); | ||
1052 | u8 reset = (HWIF(drive)->channel) ? 0x80 : 0x40; | ||
1053 | u8 reg59h = 0; | ||
1054 | |||
1055 | pci_read_config_byte(HWIF(drive)->pci_dev, 0x59, ®59h); | ||
1056 | pci_write_config_byte(HWIF(drive)->pci_dev, 0x59, reg59h|reset); | ||
1057 | pci_write_config_byte(HWIF(drive)->pci_dev, 0x59, reg59h); | ||
1058 | #endif | ||
1059 | } | ||
1060 | |||
1061 | static int hpt3xx_tristate (ide_drive_t * drive, int state) | ||
1062 | { | ||
1063 | ide_hwif_t *hwif = HWIF(drive); | ||
1064 | struct pci_dev *dev = hwif->pci_dev; | ||
1065 | u8 reg59h = 0, reset = (hwif->channel) ? 0x80 : 0x40; | ||
1066 | u8 regXXh = 0, state_reg= (hwif->channel) ? 0x57 : 0x53; | ||
1067 | |||
1068 | // hwif->bus_state = state; | ||
1069 | |||
1070 | pci_read_config_byte(dev, 0x59, ®59h); | ||
1071 | pci_read_config_byte(dev, state_reg, ®XXh); | ||
1072 | |||
1073 | if (state) { | ||
1074 | (void) ide_do_reset(drive); | ||
1075 | pci_write_config_byte(dev, state_reg, regXXh|0x80); | ||
1076 | pci_write_config_byte(dev, 0x59, reg59h|reset); | ||
1077 | } else { | ||
1078 | pci_write_config_byte(dev, 0x59, reg59h & ~(reset)); | ||
1079 | pci_write_config_byte(dev, state_reg, regXXh & ~(0x80)); | ||
1080 | (void) ide_do_reset(drive); | ||
1081 | } | ||
1082 | return 0; | ||
1083 | } | ||
1084 | |||
1085 | /* | ||
1086 | * set/get power state for a drive. | ||
1087 | * turning the power off does the following things: | ||
1088 | * 1) soft-reset the drive | ||
1089 | * 2) tri-states the ide bus | ||
1090 | * | ||
1091 | * when we turn things back on, we need to re-initialize things. | ||
1092 | */ | ||
1093 | #define TRISTATE_BIT 0x8000 | ||
1094 | static int hpt370_busproc(ide_drive_t * drive, int state) | ||
1095 | { | ||
1096 | ide_hwif_t *hwif = HWIF(drive); | ||
1097 | struct pci_dev *dev = hwif->pci_dev; | ||
1098 | u8 tristate = 0, resetmask = 0, bus_reg = 0; | ||
1099 | u16 tri_reg; | ||
1100 | |||
1101 | hwif->bus_state = state; | ||
1102 | |||
1103 | if (hwif->channel) { | ||
1104 | /* secondary channel */ | ||
1105 | tristate = 0x56; | ||
1106 | resetmask = 0x80; | ||
1107 | } else { | ||
1108 | /* primary channel */ | ||
1109 | tristate = 0x52; | ||
1110 | resetmask = 0x40; | ||
1111 | } | ||
1112 | |||
1113 | /* grab status */ | ||
1114 | pci_read_config_word(dev, tristate, &tri_reg); | ||
1115 | pci_read_config_byte(dev, 0x59, &bus_reg); | ||
1116 | |||
1117 | /* set the state. we don't set it if we don't need to do so. | ||
1118 | * make sure that the drive knows that it has failed if it's off */ | ||
1119 | switch (state) { | ||
1120 | case BUSSTATE_ON: | ||
1121 | hwif->drives[0].failures = 0; | ||
1122 | hwif->drives[1].failures = 0; | ||
1123 | if ((bus_reg & resetmask) == 0) | ||
1124 | return 0; | ||
1125 | tri_reg &= ~TRISTATE_BIT; | ||
1126 | bus_reg &= ~resetmask; | ||
1127 | break; | ||
1128 | case BUSSTATE_OFF: | ||
1129 | hwif->drives[0].failures = hwif->drives[0].max_failures + 1; | ||
1130 | hwif->drives[1].failures = hwif->drives[1].max_failures + 1; | ||
1131 | if ((tri_reg & TRISTATE_BIT) == 0 && (bus_reg & resetmask)) | ||
1132 | return 0; | ||
1133 | tri_reg &= ~TRISTATE_BIT; | ||
1134 | bus_reg |= resetmask; | ||
1135 | break; | ||
1136 | case BUSSTATE_TRISTATE: | ||
1137 | hwif->drives[0].failures = hwif->drives[0].max_failures + 1; | ||
1138 | hwif->drives[1].failures = hwif->drives[1].max_failures + 1; | ||
1139 | if ((tri_reg & TRISTATE_BIT) && (bus_reg & resetmask)) | ||
1140 | return 0; | ||
1141 | tri_reg |= TRISTATE_BIT; | ||
1142 | bus_reg |= resetmask; | ||
1143 | break; | ||
1144 | } | ||
1145 | pci_write_config_byte(dev, 0x59, bus_reg); | ||
1146 | pci_write_config_word(dev, tristate, tri_reg); | ||
1147 | |||
1148 | return 0; | ||
1149 | } | ||
1150 | |||
1151 | static int __devinit init_hpt37x(struct pci_dev *dev) | ||
1152 | { | ||
1153 | int adjust, i; | ||
1154 | u16 freq; | ||
1155 | u32 pll; | ||
1156 | u8 reg5bh; | ||
1157 | u8 reg5ah = 0; | ||
1158 | unsigned long dmabase = pci_resource_start(dev, 4); | ||
1159 | u8 did, rid; | ||
1160 | int is_372n = 0; | ||
1161 | |||
1162 | pci_read_config_byte(dev, 0x5a, ®5ah); | ||
1163 | /* interrupt force enable */ | ||
1164 | pci_write_config_byte(dev, 0x5a, (reg5ah & ~0x10)); | ||
1165 | |||
1166 | if(dmabase) | ||
1167 | { | ||
1168 | did = inb(dmabase + 0x22); | ||
1169 | rid = inb(dmabase + 0x28); | ||
1170 | |||
1171 | if((did == 4 && rid == 6) || (did == 5 && rid > 1)) | ||
1172 | is_372n = 1; | ||
1173 | } | ||
1174 | |||
1175 | /* | ||
1176 | * default to pci clock. make sure MA15/16 are set to output | ||
1177 | * to prevent drives having problems with 40-pin cables. | ||
1178 | */ | ||
1179 | pci_write_config_byte(dev, 0x5b, 0x23); | ||
1180 | |||
1181 | /* | ||
1182 | * set up the PLL. we need to adjust it so that it's stable. | ||
1183 | * freq = Tpll * 192 / Tpci | ||
1184 | * | ||
1185 | * Todo. For non x86 should probably check the dword is | ||
1186 | * set to 0xABCDExxx indicating the BIOS saved f_CNT | ||
1187 | */ | ||
1188 | pci_read_config_word(dev, 0x78, &freq); | ||
1189 | freq &= 0x1FF; | ||
1190 | |||
1191 | /* | ||
1192 | * The 372N uses different PCI clock information and has | ||
1193 | * some other complications | ||
1194 | * On PCI33 timing we must clock switch | ||
1195 | * On PCI66 timing we must NOT use the PCI clock | ||
1196 | * | ||
1197 | * Currently we always set up the PLL for the 372N | ||
1198 | */ | ||
1199 | |||
1200 | pci_set_drvdata(dev, NULL); | ||
1201 | |||
1202 | if(is_372n) | ||
1203 | { | ||
1204 | printk(KERN_INFO "hpt: HPT372N detected, using 372N timing.\n"); | ||
1205 | if(freq < 0x55) | ||
1206 | pll = F_LOW_PCI_33; | ||
1207 | else if(freq < 0x70) | ||
1208 | pll = F_LOW_PCI_40; | ||
1209 | else if(freq < 0x7F) | ||
1210 | pll = F_LOW_PCI_50; | ||
1211 | else | ||
1212 | pll = F_LOW_PCI_66; | ||
1213 | |||
1214 | printk(KERN_INFO "FREQ: %d PLL: %d\n", freq, pll); | ||
1215 | |||
1216 | /* We always use the pll not the PCI clock on 372N */ | ||
1217 | } | ||
1218 | else | ||
1219 | { | ||
1220 | if(freq < 0x9C) | ||
1221 | pll = F_LOW_PCI_33; | ||
1222 | else if(freq < 0xb0) | ||
1223 | pll = F_LOW_PCI_40; | ||
1224 | else if(freq <0xc8) | ||
1225 | pll = F_LOW_PCI_50; | ||
1226 | else | ||
1227 | pll = F_LOW_PCI_66; | ||
1228 | |||
1229 | if (pll == F_LOW_PCI_33) { | ||
1230 | if (hpt_minimum_revision(dev,8)) | ||
1231 | pci_set_drvdata(dev, (void *) thirty_three_base_hpt374); | ||
1232 | else if (hpt_minimum_revision(dev,5)) | ||
1233 | pci_set_drvdata(dev, (void *) thirty_three_base_hpt372); | ||
1234 | else if (hpt_minimum_revision(dev,4)) | ||
1235 | pci_set_drvdata(dev, (void *) thirty_three_base_hpt370a); | ||
1236 | else | ||
1237 | pci_set_drvdata(dev, (void *) thirty_three_base_hpt370); | ||
1238 | printk("HPT37X: using 33MHz PCI clock\n"); | ||
1239 | } else if (pll == F_LOW_PCI_40) { | ||
1240 | /* Unsupported */ | ||
1241 | } else if (pll == F_LOW_PCI_50) { | ||
1242 | if (hpt_minimum_revision(dev,8)) | ||
1243 | pci_set_drvdata(dev, (void *) fifty_base_hpt370a); | ||
1244 | else if (hpt_minimum_revision(dev,5)) | ||
1245 | pci_set_drvdata(dev, (void *) fifty_base_hpt372); | ||
1246 | else if (hpt_minimum_revision(dev,4)) | ||
1247 | pci_set_drvdata(dev, (void *) fifty_base_hpt370a); | ||
1248 | else | ||
1249 | pci_set_drvdata(dev, (void *) fifty_base_hpt370a); | ||
1250 | printk("HPT37X: using 50MHz PCI clock\n"); | ||
1251 | } else { | ||
1252 | if (hpt_minimum_revision(dev,8)) | ||
1253 | { | ||
1254 | printk(KERN_ERR "HPT37x: 66MHz timings are not supported.\n"); | ||
1255 | } | ||
1256 | else if (hpt_minimum_revision(dev,5)) | ||
1257 | pci_set_drvdata(dev, (void *) sixty_six_base_hpt372); | ||
1258 | else if (hpt_minimum_revision(dev,4)) | ||
1259 | pci_set_drvdata(dev, (void *) sixty_six_base_hpt370a); | ||
1260 | else | ||
1261 | pci_set_drvdata(dev, (void *) sixty_six_base_hpt370); | ||
1262 | printk("HPT37X: using 66MHz PCI clock\n"); | ||
1263 | } | ||
1264 | } | ||
1265 | |||
1266 | /* | ||
1267 | * only try the pll if we don't have a table for the clock | ||
1268 | * speed that we're running at. NOTE: the internal PLL will | ||
1269 | * result in slow reads when using a 33MHz PCI clock. we also | ||
1270 | * don't like to use the PLL because it will cause glitches | ||
1271 | * on PRST/SRST when the HPT state engine gets reset. | ||
1272 | */ | ||
1273 | if (pci_get_drvdata(dev)) | ||
1274 | goto init_hpt37X_done; | ||
1275 | |||
1276 | /* | ||
1277 | * adjust PLL based upon PCI clock, enable it, and wait for | ||
1278 | * stabilization. | ||
1279 | */ | ||
1280 | adjust = 0; | ||
1281 | freq = (pll < F_LOW_PCI_50) ? 2 : 4; | ||
1282 | while (adjust++ < 6) { | ||
1283 | pci_write_config_dword(dev, 0x5c, (freq + pll) << 16 | | ||
1284 | pll | 0x100); | ||
1285 | |||
1286 | /* wait for clock stabilization */ | ||
1287 | for (i = 0; i < 0x50000; i++) { | ||
1288 | pci_read_config_byte(dev, 0x5b, ®5bh); | ||
1289 | if (reg5bh & 0x80) { | ||
1290 | /* spin looking for the clock to destabilize */ | ||
1291 | for (i = 0; i < 0x1000; ++i) { | ||
1292 | pci_read_config_byte(dev, 0x5b, | ||
1293 | ®5bh); | ||
1294 | if ((reg5bh & 0x80) == 0) | ||
1295 | goto pll_recal; | ||
1296 | } | ||
1297 | pci_read_config_dword(dev, 0x5c, &pll); | ||
1298 | pci_write_config_dword(dev, 0x5c, | ||
1299 | pll & ~0x100); | ||
1300 | pci_write_config_byte(dev, 0x5b, 0x21); | ||
1301 | if (hpt_minimum_revision(dev,8)) | ||
1302 | pci_set_drvdata(dev, (void *) fifty_base_hpt370a); | ||
1303 | else if (hpt_minimum_revision(dev,5)) | ||
1304 | pci_set_drvdata(dev, (void *) fifty_base_hpt372); | ||
1305 | else if (hpt_minimum_revision(dev,4)) | ||
1306 | pci_set_drvdata(dev, (void *) fifty_base_hpt370a); | ||
1307 | else | ||
1308 | pci_set_drvdata(dev, (void *) fifty_base_hpt370a); | ||
1309 | printk("HPT37X: using 50MHz internal PLL\n"); | ||
1310 | goto init_hpt37X_done; | ||
1311 | } | ||
1312 | } | ||
1313 | pll_recal: | ||
1314 | if (adjust & 1) | ||
1315 | pll -= (adjust >> 1); | ||
1316 | else | ||
1317 | pll += (adjust >> 1); | ||
1318 | } | ||
1319 | |||
1320 | init_hpt37X_done: | ||
1321 | /* reset state engine */ | ||
1322 | pci_write_config_byte(dev, 0x50, 0x37); | ||
1323 | pci_write_config_byte(dev, 0x54, 0x37); | ||
1324 | udelay(100); | ||
1325 | return 0; | ||
1326 | } | ||
1327 | |||
1328 | static int __devinit init_hpt366(struct pci_dev *dev) | ||
1329 | { | ||
1330 | u32 reg1 = 0; | ||
1331 | u8 drive_fast = 0; | ||
1332 | |||
1333 | /* | ||
1334 | * Disable the "fast interrupt" prediction. | ||
1335 | */ | ||
1336 | pci_read_config_byte(dev, 0x51, &drive_fast); | ||
1337 | if (drive_fast & 0x80) | ||
1338 | pci_write_config_byte(dev, 0x51, drive_fast & ~0x80); | ||
1339 | pci_read_config_dword(dev, 0x40, ®1); | ||
1340 | |||
1341 | /* detect bus speed by looking at control reg timing: */ | ||
1342 | switch((reg1 >> 8) & 7) { | ||
1343 | case 5: | ||
1344 | pci_set_drvdata(dev, (void *) forty_base_hpt366); | ||
1345 | break; | ||
1346 | case 9: | ||
1347 | pci_set_drvdata(dev, (void *) twenty_five_base_hpt366); | ||
1348 | break; | ||
1349 | case 7: | ||
1350 | default: | ||
1351 | pci_set_drvdata(dev, (void *) thirty_three_base_hpt366); | ||
1352 | break; | ||
1353 | } | ||
1354 | |||
1355 | if (!pci_get_drvdata(dev)) | ||
1356 | { | ||
1357 | printk(KERN_ERR "hpt366: unknown bus timing.\n"); | ||
1358 | pci_set_drvdata(dev, NULL); | ||
1359 | } | ||
1360 | return 0; | ||
1361 | } | ||
1362 | |||
1363 | static unsigned int __devinit init_chipset_hpt366(struct pci_dev *dev, const char *name) | ||
1364 | { | ||
1365 | int ret = 0; | ||
1366 | u8 test = 0; | ||
1367 | |||
1368 | if (dev->resource[PCI_ROM_RESOURCE].start) | ||
1369 | pci_write_config_byte(dev, PCI_ROM_ADDRESS, | ||
1370 | dev->resource[PCI_ROM_RESOURCE].start | PCI_ROM_ADDRESS_ENABLE); | ||
1371 | |||
1372 | pci_read_config_byte(dev, PCI_CACHE_LINE_SIZE, &test); | ||
1373 | if (test != (L1_CACHE_BYTES / 4)) | ||
1374 | pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, | ||
1375 | (L1_CACHE_BYTES / 4)); | ||
1376 | |||
1377 | pci_read_config_byte(dev, PCI_LATENCY_TIMER, &test); | ||
1378 | if (test != 0x78) | ||
1379 | pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x78); | ||
1380 | |||
1381 | pci_read_config_byte(dev, PCI_MIN_GNT, &test); | ||
1382 | if (test != 0x08) | ||
1383 | pci_write_config_byte(dev, PCI_MIN_GNT, 0x08); | ||
1384 | |||
1385 | pci_read_config_byte(dev, PCI_MAX_LAT, &test); | ||
1386 | if (test != 0x08) | ||
1387 | pci_write_config_byte(dev, PCI_MAX_LAT, 0x08); | ||
1388 | |||
1389 | if (hpt_minimum_revision(dev, 3)) { | ||
1390 | ret = init_hpt37x(dev); | ||
1391 | } else { | ||
1392 | ret =init_hpt366(dev); | ||
1393 | } | ||
1394 | if (ret) | ||
1395 | return ret; | ||
1396 | |||
1397 | return dev->irq; | ||
1398 | } | ||
1399 | |||
1400 | static void __devinit init_hwif_hpt366(ide_hwif_t *hwif) | ||
1401 | { | ||
1402 | struct pci_dev *dev = hwif->pci_dev; | ||
1403 | u8 ata66 = 0, regmask = (hwif->channel) ? 0x01 : 0x02; | ||
1404 | u8 did, rid; | ||
1405 | unsigned long dmabase = hwif->dma_base; | ||
1406 | int is_372n = 0; | ||
1407 | |||
1408 | if(dmabase) | ||
1409 | { | ||
1410 | did = inb(dmabase + 0x22); | ||
1411 | rid = inb(dmabase + 0x28); | ||
1412 | |||
1413 | if((did == 4 && rid == 6) || (did == 5 && rid > 1)) | ||
1414 | is_372n = 1; | ||
1415 | } | ||
1416 | |||
1417 | hwif->tuneproc = &hpt3xx_tune_drive; | ||
1418 | hwif->speedproc = &hpt3xx_tune_chipset; | ||
1419 | hwif->quirkproc = &hpt3xx_quirkproc; | ||
1420 | hwif->intrproc = &hpt3xx_intrproc; | ||
1421 | hwif->maskproc = &hpt3xx_maskproc; | ||
1422 | |||
1423 | if(is_372n) | ||
1424 | hwif->rw_disk = &hpt372n_rw_disk; | ||
1425 | |||
1426 | /* | ||
1427 | * The HPT37x uses the CBLID pins as outputs for MA15/MA16 | ||
1428 | * address lines to access an external eeprom. To read valid | ||
1429 | * cable detect state the pins must be enabled as inputs. | ||
1430 | */ | ||
1431 | if (hpt_minimum_revision(dev, 8) && PCI_FUNC(dev->devfn) & 1) { | ||
1432 | /* | ||
1433 | * HPT374 PCI function 1 | ||
1434 | * - set bit 15 of reg 0x52 to enable TCBLID as input | ||
1435 | * - set bit 15 of reg 0x56 to enable FCBLID as input | ||
1436 | */ | ||
1437 | u16 mcr3, mcr6; | ||
1438 | pci_read_config_word(dev, 0x52, &mcr3); | ||
1439 | pci_read_config_word(dev, 0x56, &mcr6); | ||
1440 | pci_write_config_word(dev, 0x52, mcr3 | 0x8000); | ||
1441 | pci_write_config_word(dev, 0x56, mcr6 | 0x8000); | ||
1442 | /* now read cable id register */ | ||
1443 | pci_read_config_byte(dev, 0x5a, &ata66); | ||
1444 | pci_write_config_word(dev, 0x52, mcr3); | ||
1445 | pci_write_config_word(dev, 0x56, mcr6); | ||
1446 | } else if (hpt_minimum_revision(dev, 3)) { | ||
1447 | /* | ||
1448 | * HPT370/372 and 374 pcifn 0 | ||
1449 | * - clear bit 0 of 0x5b to enable P/SCBLID as inputs | ||
1450 | */ | ||
1451 | u8 scr2; | ||
1452 | pci_read_config_byte(dev, 0x5b, &scr2); | ||
1453 | pci_write_config_byte(dev, 0x5b, scr2 & ~1); | ||
1454 | /* now read cable id register */ | ||
1455 | pci_read_config_byte(dev, 0x5a, &ata66); | ||
1456 | pci_write_config_byte(dev, 0x5b, scr2); | ||
1457 | } else { | ||
1458 | pci_read_config_byte(dev, 0x5a, &ata66); | ||
1459 | } | ||
1460 | |||
1461 | #ifdef DEBUG | ||
1462 | printk("HPT366: reg5ah=0x%02x ATA-%s Cable Port%d\n", | ||
1463 | ata66, (ata66 & regmask) ? "33" : "66", | ||
1464 | PCI_FUNC(hwif->pci_dev->devfn)); | ||
1465 | #endif /* DEBUG */ | ||
1466 | |||
1467 | #ifdef HPT_SERIALIZE_IO | ||
1468 | /* serialize access to this device */ | ||
1469 | if (hwif->mate) | ||
1470 | hwif->serialized = hwif->mate->serialized = 1; | ||
1471 | #endif | ||
1472 | |||
1473 | if (hpt_minimum_revision(dev,3)) { | ||
1474 | u8 reg5ah = 0; | ||
1475 | pci_write_config_byte(dev, 0x5a, reg5ah & ~0x10); | ||
1476 | /* | ||
1477 | * set up ioctl for power status. | ||
1478 | * note: power affects both | ||
1479 | * drives on each channel | ||
1480 | */ | ||
1481 | hwif->resetproc = &hpt3xx_reset; | ||
1482 | hwif->busproc = &hpt370_busproc; | ||
1483 | // hwif->drives[0].autotune = hwif->drives[1].autotune = 1; | ||
1484 | } else if (hpt_minimum_revision(dev,2)) { | ||
1485 | hwif->resetproc = &hpt3xx_reset; | ||
1486 | hwif->busproc = &hpt3xx_tristate; | ||
1487 | } else { | ||
1488 | hwif->resetproc = &hpt3xx_reset; | ||
1489 | hwif->busproc = &hpt3xx_tristate; | ||
1490 | } | ||
1491 | |||
1492 | if (!hwif->dma_base) { | ||
1493 | hwif->drives[0].autotune = 1; | ||
1494 | hwif->drives[1].autotune = 1; | ||
1495 | return; | ||
1496 | } | ||
1497 | |||
1498 | hwif->ultra_mask = 0x7f; | ||
1499 | hwif->mwdma_mask = 0x07; | ||
1500 | |||
1501 | if (!(hwif->udma_four)) | ||
1502 | hwif->udma_four = ((ata66 & regmask) ? 0 : 1); | ||
1503 | hwif->ide_dma_check = &hpt366_config_drive_xfer_rate; | ||
1504 | |||
1505 | if (hpt_minimum_revision(dev,8)) { | ||
1506 | hwif->ide_dma_test_irq = &hpt374_ide_dma_test_irq; | ||
1507 | hwif->ide_dma_end = &hpt374_ide_dma_end; | ||
1508 | } else if (hpt_minimum_revision(dev,5)) { | ||
1509 | hwif->ide_dma_test_irq = &hpt374_ide_dma_test_irq; | ||
1510 | hwif->ide_dma_end = &hpt374_ide_dma_end; | ||
1511 | } else if (hpt_minimum_revision(dev,3)) { | ||
1512 | hwif->dma_start = &hpt370_ide_dma_start; | ||
1513 | hwif->ide_dma_end = &hpt370_ide_dma_end; | ||
1514 | hwif->ide_dma_timeout = &hpt370_ide_dma_timeout; | ||
1515 | hwif->ide_dma_lostirq = &hpt370_ide_dma_lostirq; | ||
1516 | } else if (hpt_minimum_revision(dev,2)) | ||
1517 | hwif->ide_dma_lostirq = &hpt366_ide_dma_lostirq; | ||
1518 | else | ||
1519 | hwif->ide_dma_lostirq = &hpt366_ide_dma_lostirq; | ||
1520 | |||
1521 | if (!noautodma) | ||
1522 | hwif->autodma = 1; | ||
1523 | hwif->drives[0].autodma = hwif->autodma; | ||
1524 | hwif->drives[1].autodma = hwif->autodma; | ||
1525 | } | ||
1526 | |||
1527 | static void __devinit init_dma_hpt366(ide_hwif_t *hwif, unsigned long dmabase) | ||
1528 | { | ||
1529 | u8 masterdma = 0, slavedma = 0; | ||
1530 | u8 dma_new = 0, dma_old = 0; | ||
1531 | u8 primary = hwif->channel ? 0x4b : 0x43; | ||
1532 | u8 secondary = hwif->channel ? 0x4f : 0x47; | ||
1533 | unsigned long flags; | ||
1534 | |||
1535 | if (!dmabase) | ||
1536 | return; | ||
1537 | |||
1538 | if(pci_get_drvdata(hwif->pci_dev) == NULL) | ||
1539 | { | ||
1540 | printk(KERN_WARNING "hpt: no known IDE timings, disabling DMA.\n"); | ||
1541 | return; | ||
1542 | } | ||
1543 | |||
1544 | dma_old = hwif->INB(dmabase+2); | ||
1545 | |||
1546 | local_irq_save(flags); | ||
1547 | |||
1548 | dma_new = dma_old; | ||
1549 | pci_read_config_byte(hwif->pci_dev, primary, &masterdma); | ||
1550 | pci_read_config_byte(hwif->pci_dev, secondary, &slavedma); | ||
1551 | |||
1552 | if (masterdma & 0x30) dma_new |= 0x20; | ||
1553 | if (slavedma & 0x30) dma_new |= 0x40; | ||
1554 | if (dma_new != dma_old) | ||
1555 | hwif->OUTB(dma_new, dmabase+2); | ||
1556 | |||
1557 | local_irq_restore(flags); | ||
1558 | |||
1559 | ide_setup_dma(hwif, dmabase, 8); | ||
1560 | } | ||
1561 | |||
1562 | static int __devinit init_setup_hpt374(struct pci_dev *dev, ide_pci_device_t *d) | ||
1563 | { | ||
1564 | struct pci_dev *findev = NULL; | ||
1565 | |||
1566 | if (PCI_FUNC(dev->devfn) & 1) | ||
1567 | return -ENODEV; | ||
1568 | |||
1569 | while ((findev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, findev)) != NULL) { | ||
1570 | if ((findev->vendor == dev->vendor) && | ||
1571 | (findev->device == dev->device) && | ||
1572 | ((findev->devfn - dev->devfn) == 1) && | ||
1573 | (PCI_FUNC(findev->devfn) & 1)) { | ||
1574 | if (findev->irq != dev->irq) { | ||
1575 | /* FIXME: we need a core pci_set_interrupt() */ | ||
1576 | findev->irq = dev->irq; | ||
1577 | printk(KERN_WARNING "%s: pci-config space interrupt " | ||
1578 | "fixed.\n", d->name); | ||
1579 | } | ||
1580 | return ide_setup_pci_devices(dev, findev, d); | ||
1581 | } | ||
1582 | } | ||
1583 | return ide_setup_pci_device(dev, d); | ||
1584 | } | ||
1585 | |||
1586 | static int __devinit init_setup_hpt37x(struct pci_dev *dev, ide_pci_device_t *d) | ||
1587 | { | ||
1588 | return ide_setup_pci_device(dev, d); | ||
1589 | } | ||
1590 | |||
1591 | static int __devinit init_setup_hpt366(struct pci_dev *dev, ide_pci_device_t *d) | ||
1592 | { | ||
1593 | struct pci_dev *findev = NULL; | ||
1594 | u8 pin1 = 0, pin2 = 0; | ||
1595 | unsigned int class_rev; | ||
1596 | char *chipset_names[] = {"HPT366", "HPT366", "HPT368", | ||
1597 | "HPT370", "HPT370A", "HPT372", | ||
1598 | "HPT372N" }; | ||
1599 | |||
1600 | if (PCI_FUNC(dev->devfn) & 1) | ||
1601 | return -ENODEV; | ||
1602 | |||
1603 | pci_read_config_dword(dev, PCI_CLASS_REVISION, &class_rev); | ||
1604 | class_rev &= 0xff; | ||
1605 | |||
1606 | if(dev->device == PCI_DEVICE_ID_TTI_HPT372N) | ||
1607 | class_rev = 6; | ||
1608 | |||
1609 | if(class_rev <= 6) | ||
1610 | d->name = chipset_names[class_rev]; | ||
1611 | |||
1612 | switch(class_rev) { | ||
1613 | case 6: | ||
1614 | case 5: | ||
1615 | case 4: | ||
1616 | case 3: | ||
1617 | goto init_single; | ||
1618 | default: | ||
1619 | break; | ||
1620 | } | ||
1621 | |||
1622 | d->channels = 1; | ||
1623 | |||
1624 | pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin1); | ||
1625 | while ((findev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, findev)) != NULL) { | ||
1626 | if ((findev->vendor == dev->vendor) && | ||
1627 | (findev->device == dev->device) && | ||
1628 | ((findev->devfn - dev->devfn) == 1) && | ||
1629 | (PCI_FUNC(findev->devfn) & 1)) { | ||
1630 | pci_read_config_byte(findev, PCI_INTERRUPT_PIN, &pin2); | ||
1631 | if ((pin1 != pin2) && (dev->irq == findev->irq)) { | ||
1632 | d->bootable = ON_BOARD; | ||
1633 | printk("%s: onboard version of chipset, " | ||
1634 | "pin1=%d pin2=%d\n", d->name, | ||
1635 | pin1, pin2); | ||
1636 | } | ||
1637 | return ide_setup_pci_devices(dev, findev, d); | ||
1638 | } | ||
1639 | } | ||
1640 | init_single: | ||
1641 | return ide_setup_pci_device(dev, d); | ||
1642 | } | ||
1643 | |||
1644 | static ide_pci_device_t hpt366_chipsets[] __devinitdata = { | ||
1645 | { /* 0 */ | ||
1646 | .name = "HPT366", | ||
1647 | .init_setup = init_setup_hpt366, | ||
1648 | .init_chipset = init_chipset_hpt366, | ||
1649 | .init_hwif = init_hwif_hpt366, | ||
1650 | .init_dma = init_dma_hpt366, | ||
1651 | .channels = 2, | ||
1652 | .autodma = AUTODMA, | ||
1653 | .bootable = OFF_BOARD, | ||
1654 | .extra = 240 | ||
1655 | },{ /* 1 */ | ||
1656 | .name = "HPT372A", | ||
1657 | .init_setup = init_setup_hpt37x, | ||
1658 | .init_chipset = init_chipset_hpt366, | ||
1659 | .init_hwif = init_hwif_hpt366, | ||
1660 | .init_dma = init_dma_hpt366, | ||
1661 | .channels = 2, | ||
1662 | .autodma = AUTODMA, | ||
1663 | .bootable = OFF_BOARD, | ||
1664 | },{ /* 2 */ | ||
1665 | .name = "HPT302", | ||
1666 | .init_setup = init_setup_hpt37x, | ||
1667 | .init_chipset = init_chipset_hpt366, | ||
1668 | .init_hwif = init_hwif_hpt366, | ||
1669 | .init_dma = init_dma_hpt366, | ||
1670 | .channels = 2, | ||
1671 | .autodma = AUTODMA, | ||
1672 | .bootable = OFF_BOARD, | ||
1673 | },{ /* 3 */ | ||
1674 | .name = "HPT371", | ||
1675 | .init_setup = init_setup_hpt37x, | ||
1676 | .init_chipset = init_chipset_hpt366, | ||
1677 | .init_hwif = init_hwif_hpt366, | ||
1678 | .init_dma = init_dma_hpt366, | ||
1679 | .channels = 2, | ||
1680 | .autodma = AUTODMA, | ||
1681 | .bootable = OFF_BOARD, | ||
1682 | },{ /* 4 */ | ||
1683 | .name = "HPT374", | ||
1684 | .init_setup = init_setup_hpt374, | ||
1685 | .init_chipset = init_chipset_hpt366, | ||
1686 | .init_hwif = init_hwif_hpt366, | ||
1687 | .init_dma = init_dma_hpt366, | ||
1688 | .channels = 2, /* 4 */ | ||
1689 | .autodma = AUTODMA, | ||
1690 | .bootable = OFF_BOARD, | ||
1691 | },{ /* 5 */ | ||
1692 | .name = "HPT372N", | ||
1693 | .init_setup = init_setup_hpt37x, | ||
1694 | .init_chipset = init_chipset_hpt366, | ||
1695 | .init_hwif = init_hwif_hpt366, | ||
1696 | .init_dma = init_dma_hpt366, | ||
1697 | .channels = 2, /* 4 */ | ||
1698 | .autodma = AUTODMA, | ||
1699 | .bootable = OFF_BOARD, | ||
1700 | } | ||
1701 | }; | ||
1702 | |||
1703 | /** | ||
1704 | * hpt366_init_one - called when an HPT366 is found | ||
1705 | * @dev: the hpt366 device | ||
1706 | * @id: the matching pci id | ||
1707 | * | ||
1708 | * Called when the PCI registration layer (or the IDE initialization) | ||
1709 | * finds a device matching our IDE device tables. | ||
1710 | */ | ||
1711 | |||
1712 | static int __devinit hpt366_init_one(struct pci_dev *dev, const struct pci_device_id *id) | ||
1713 | { | ||
1714 | ide_pci_device_t *d = &hpt366_chipsets[id->driver_data]; | ||
1715 | |||
1716 | return d->init_setup(dev, d); | ||
1717 | } | ||
1718 | |||
1719 | static struct pci_device_id hpt366_pci_tbl[] = { | ||
1720 | { PCI_VENDOR_ID_TTI, PCI_DEVICE_ID_TTI_HPT366, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, | ||
1721 | { PCI_VENDOR_ID_TTI, PCI_DEVICE_ID_TTI_HPT372, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1}, | ||
1722 | { PCI_VENDOR_ID_TTI, PCI_DEVICE_ID_TTI_HPT302, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2}, | ||
1723 | { PCI_VENDOR_ID_TTI, PCI_DEVICE_ID_TTI_HPT371, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3}, | ||
1724 | { PCI_VENDOR_ID_TTI, PCI_DEVICE_ID_TTI_HPT374, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4}, | ||
1725 | { PCI_VENDOR_ID_TTI, PCI_DEVICE_ID_TTI_HPT372N, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5}, | ||
1726 | { 0, }, | ||
1727 | }; | ||
1728 | MODULE_DEVICE_TABLE(pci, hpt366_pci_tbl); | ||
1729 | |||
1730 | static struct pci_driver driver = { | ||
1731 | .name = "HPT366_IDE", | ||
1732 | .id_table = hpt366_pci_tbl, | ||
1733 | .probe = hpt366_init_one, | ||
1734 | }; | ||
1735 | |||
1736 | static int hpt366_ide_init(void) | ||
1737 | { | ||
1738 | return ide_pci_register_driver(&driver); | ||
1739 | } | ||
1740 | |||
1741 | module_init(hpt366_ide_init); | ||
1742 | |||
1743 | MODULE_AUTHOR("Andre Hedrick"); | ||
1744 | MODULE_DESCRIPTION("PCI driver module for Highpoint HPT366 IDE"); | ||
1745 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/ide/pci/it8172.c b/drivers/ide/pci/it8172.c new file mode 100644 index 000000000000..631927cf17d4 --- /dev/null +++ b/drivers/ide/pci/it8172.c | |||
@@ -0,0 +1,308 @@ | |||
1 | /* | ||
2 | * | ||
3 | * BRIEF MODULE DESCRIPTION | ||
4 | * IT8172 IDE controller support | ||
5 | * | ||
6 | * Copyright 2000 MontaVista Software Inc. | ||
7 | * Author: MontaVista Software, Inc. | ||
8 | * stevel@mvista.com or source@mvista.com | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or modify it | ||
11 | * under the terms of the GNU General Public License as published by the | ||
12 | * Free Software Foundation; either version 2 of the License, or (at your | ||
13 | * option) any later version. | ||
14 | * | ||
15 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED | ||
16 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | ||
17 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN | ||
18 | * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | ||
21 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
22 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
25 | * | ||
26 | * You should have received a copy of the GNU General Public License along | ||
27 | * with this program; if not, write to the Free Software Foundation, Inc., | ||
28 | * 675 Mass Ave, Cambridge, MA 02139, USA. | ||
29 | */ | ||
30 | |||
31 | #include <linux/config.h> | ||
32 | #include <linux/module.h> | ||
33 | #include <linux/types.h> | ||
34 | #include <linux/kernel.h> | ||
35 | #include <linux/ioport.h> | ||
36 | #include <linux/pci.h> | ||
37 | #include <linux/hdreg.h> | ||
38 | #include <linux/ide.h> | ||
39 | #include <linux/delay.h> | ||
40 | #include <linux/init.h> | ||
41 | |||
42 | #include <asm/io.h> | ||
43 | #include <asm/it8172/it8172_int.h> | ||
44 | |||
45 | /* | ||
46 | * Prototypes | ||
47 | */ | ||
48 | static u8 it8172_ratemask (ide_drive_t *drive) | ||
49 | { | ||
50 | return 1; | ||
51 | } | ||
52 | |||
53 | static void it8172_tune_drive (ide_drive_t *drive, u8 pio) | ||
54 | { | ||
55 | ide_hwif_t *hwif = HWIF(drive); | ||
56 | struct pci_dev *dev = hwif->pci_dev; | ||
57 | int is_slave = (&hwif->drives[1] == drive); | ||
58 | unsigned long flags; | ||
59 | u16 drive_enables; | ||
60 | u32 drive_timing; | ||
61 | |||
62 | pio = ide_get_best_pio_mode(drive, pio, 4, NULL); | ||
63 | spin_lock_irqsave(&ide_lock, flags); | ||
64 | pci_read_config_word(dev, 0x40, &drive_enables); | ||
65 | pci_read_config_dword(dev, 0x44, &drive_timing); | ||
66 | |||
67 | /* | ||
68 | * FIX! The DIOR/DIOW pulse width and recovery times in port 0x44 | ||
69 | * are being left at the default values of 8 PCI clocks (242 nsec | ||
70 | * for a 33 MHz clock). These can be safely shortened at higher | ||
71 | * PIO modes. The DIOR/DIOW pulse width and recovery times only | ||
72 | * apply to PIO modes, not to the DMA modes. | ||
73 | */ | ||
74 | |||
75 | /* | ||
76 | * Enable port 0x44. The IT8172G spec is confused; it calls | ||
77 | * this register the "Slave IDE Timing Register", but in fact, | ||
78 | * it controls timing for both master and slave drives. | ||
79 | */ | ||
80 | drive_enables |= 0x4000; | ||
81 | |||
82 | if (is_slave) { | ||
83 | drive_enables &= 0xc006; | ||
84 | if (pio > 1) | ||
85 | /* enable prefetch and IORDY sample-point */ | ||
86 | drive_enables |= 0x0060; | ||
87 | } else { | ||
88 | drive_enables &= 0xc060; | ||
89 | if (pio > 1) | ||
90 | /* enable prefetch and IORDY sample-point */ | ||
91 | drive_enables |= 0x0006; | ||
92 | } | ||
93 | |||
94 | pci_write_config_word(dev, 0x40, drive_enables); | ||
95 | spin_unlock_irqrestore(&ide_lock, flags); | ||
96 | } | ||
97 | |||
98 | static u8 it8172_dma_2_pio (u8 xfer_rate) | ||
99 | { | ||
100 | switch(xfer_rate) { | ||
101 | case XFER_UDMA_5: | ||
102 | case XFER_UDMA_4: | ||
103 | case XFER_UDMA_3: | ||
104 | case XFER_UDMA_2: | ||
105 | case XFER_UDMA_1: | ||
106 | case XFER_UDMA_0: | ||
107 | case XFER_MW_DMA_2: | ||
108 | case XFER_PIO_4: | ||
109 | return 4; | ||
110 | case XFER_MW_DMA_1: | ||
111 | case XFER_PIO_3: | ||
112 | return 3; | ||
113 | case XFER_SW_DMA_2: | ||
114 | case XFER_PIO_2: | ||
115 | return 2; | ||
116 | case XFER_MW_DMA_0: | ||
117 | case XFER_SW_DMA_1: | ||
118 | case XFER_SW_DMA_0: | ||
119 | case XFER_PIO_1: | ||
120 | case XFER_PIO_0: | ||
121 | case XFER_PIO_SLOW: | ||
122 | default: | ||
123 | return 0; | ||
124 | } | ||
125 | } | ||
126 | |||
127 | static int it8172_tune_chipset (ide_drive_t *drive, u8 xferspeed) | ||
128 | { | ||
129 | ide_hwif_t *hwif = HWIF(drive); | ||
130 | struct pci_dev *dev = hwif->pci_dev; | ||
131 | u8 speed = ide_rate_filter(it8172_ratemask(drive), xferspeed); | ||
132 | int a_speed = 3 << (drive->dn * 4); | ||
133 | int u_flag = 1 << drive->dn; | ||
134 | int u_speed = 0; | ||
135 | u8 reg48, reg4a; | ||
136 | |||
137 | pci_read_config_byte(dev, 0x48, ®48); | ||
138 | pci_read_config_byte(dev, 0x4a, ®4a); | ||
139 | |||
140 | /* | ||
141 | * Setting the DMA cycle time to 2 or 3 PCI clocks (60 and 91 nsec | ||
142 | * at 33 MHz PCI clock) seems to cause BadCRC errors during DMA | ||
143 | * transfers on some drives, even though both numbers meet the minimum | ||
144 | * ATAPI-4 spec of 73 and 54 nsec for UDMA 1 and 2 respectively. | ||
145 | * So the faster times are just commented out here. The good news is | ||
146 | * that the slower cycle time has very little affect on transfer | ||
147 | * performance. | ||
148 | */ | ||
149 | |||
150 | switch(speed) { | ||
151 | case XFER_UDMA_4: | ||
152 | case XFER_UDMA_2: //u_speed = 2 << (drive->dn * 4); break; | ||
153 | case XFER_UDMA_5: | ||
154 | case XFER_UDMA_3: | ||
155 | case XFER_UDMA_1: //u_speed = 1 << (drive->dn * 4); break; | ||
156 | case XFER_UDMA_0: u_speed = 0 << (drive->dn * 4); break; | ||
157 | case XFER_MW_DMA_2: | ||
158 | case XFER_MW_DMA_1: | ||
159 | case XFER_MW_DMA_0: | ||
160 | case XFER_SW_DMA_2: break; | ||
161 | case XFER_PIO_4: | ||
162 | case XFER_PIO_3: | ||
163 | case XFER_PIO_2: | ||
164 | case XFER_PIO_0: break; | ||
165 | default: return -1; | ||
166 | } | ||
167 | |||
168 | if (speed >= XFER_UDMA_0) { | ||
169 | pci_write_config_byte(dev, 0x48, reg48 | u_flag); | ||
170 | reg4a &= ~a_speed; | ||
171 | pci_write_config_byte(dev, 0x4a, reg4a | u_speed); | ||
172 | } else { | ||
173 | pci_write_config_byte(dev, 0x48, reg48 & ~u_flag); | ||
174 | pci_write_config_byte(dev, 0x4a, reg4a & ~a_speed); | ||
175 | } | ||
176 | |||
177 | it8172_tune_drive(drive, it8172_dma_2_pio(speed)); | ||
178 | return (ide_config_drive_speed(drive, speed)); | ||
179 | } | ||
180 | |||
181 | static int it8172_config_chipset_for_dma (ide_drive_t *drive) | ||
182 | { | ||
183 | u8 speed = ide_dma_speed(drive, it8172_ratemask(drive)); | ||
184 | |||
185 | if (!(speed)) { | ||
186 | u8 tspeed = ide_get_best_pio_mode(drive, 255, 4, NULL); | ||
187 | speed = it8172_dma_2_pio(XFER_PIO_0 + tspeed); | ||
188 | } | ||
189 | |||
190 | (void) it8172_tune_chipset(drive, speed); | ||
191 | return ide_dma_enable(drive); | ||
192 | } | ||
193 | |||
194 | static int it8172_config_drive_xfer_rate (ide_drive_t *drive) | ||
195 | { | ||
196 | ide_hwif_t *hwif = HWIF(drive); | ||
197 | struct hd_driveid *id = drive->id; | ||
198 | |||
199 | drive->init_speed = 0; | ||
200 | |||
201 | if (id && (id->capability & 1) && drive->autodma) { | ||
202 | |||
203 | if (ide_use_dma(drive)) { | ||
204 | if (it8172_config_chipset_for_dma(drive)) | ||
205 | return hwif->ide_dma_on(drive); | ||
206 | } | ||
207 | |||
208 | goto fast_ata_pio; | ||
209 | |||
210 | } else if ((id->capability & 8) || (id->field_valid & 2)) { | ||
211 | fast_ata_pio: | ||
212 | it8172_tune_drive(drive, 5); | ||
213 | return hwif->ide_dma_off_quietly(drive); | ||
214 | } | ||
215 | /* IORDY not supported */ | ||
216 | return 0; | ||
217 | } | ||
218 | |||
219 | static unsigned int __init init_chipset_it8172 (struct pci_dev *dev, const char *name) | ||
220 | { | ||
221 | unsigned char progif; | ||
222 | |||
223 | /* | ||
224 | * Place both IDE interfaces into PCI "native" mode | ||
225 | */ | ||
226 | pci_read_config_byte(dev, PCI_CLASS_PROG, &progif); | ||
227 | pci_write_config_byte(dev, PCI_CLASS_PROG, progif | 0x05); | ||
228 | |||
229 | return IT8172_IDE_IRQ; | ||
230 | } | ||
231 | |||
232 | |||
233 | static void __init init_hwif_it8172 (ide_hwif_t *hwif) | ||
234 | { | ||
235 | struct pci_dev* dev = hwif->pci_dev; | ||
236 | unsigned long cmdBase, ctrlBase; | ||
237 | |||
238 | hwif->autodma = 0; | ||
239 | hwif->tuneproc = &it8172_tune_drive; | ||
240 | hwif->speedproc = &it8172_tune_chipset; | ||
241 | |||
242 | cmdBase = dev->resource[0].start; | ||
243 | ctrlBase = dev->resource[1].start; | ||
244 | |||
245 | ide_init_hwif_ports(&hwif->hw, cmdBase, ctrlBase | 2, NULL); | ||
246 | memcpy(hwif->io_ports, hwif->hw.io_ports, sizeof(hwif->io_ports)); | ||
247 | hwif->noprobe = 0; | ||
248 | |||
249 | if (!hwif->dma_base) { | ||
250 | hwif->drives[0].autotune = 1; | ||
251 | hwif->drives[1].autotune = 1; | ||
252 | return; | ||
253 | } | ||
254 | |||
255 | hwif->atapi_dma = 1; | ||
256 | hwif->ultra_mask = 0x07; | ||
257 | hwif->mwdma_mask = 0x06; | ||
258 | hwif->swdma_mask = 0x04; | ||
259 | |||
260 | hwif->ide_dma_check = &it8172_config_drive_xfer_rate; | ||
261 | if (!noautodma) | ||
262 | hwif->autodma = 1; | ||
263 | hwif->drives[0].autodma = hwif->autodma; | ||
264 | hwif->drives[1].autodma = hwif->autodma; | ||
265 | } | ||
266 | |||
267 | static ide_pci_device_t it8172_chipsets[] __devinitdata = { | ||
268 | { /* 0 */ | ||
269 | .name = "IT8172G", | ||
270 | .init_chipset = init_chipset_it8172, | ||
271 | .init_hwif = init_hwif_it8172, | ||
272 | .channels = 2, | ||
273 | .autodma = AUTODMA, | ||
274 | .enablebits = {{0x00,0x00,0x00}, {0x40,0x00,0x01}}, | ||
275 | .bootable = ON_BOARD, | ||
276 | } | ||
277 | }; | ||
278 | |||
279 | static int __devinit it8172_init_one(struct pci_dev *dev, const struct pci_device_id *id) | ||
280 | { | ||
281 | if ((!(PCI_FUNC(dev->devfn) & 1) || | ||
282 | (!((dev->class >> 8) == PCI_CLASS_STORAGE_IDE)))) | ||
283 | return -ENODEV; /* IT8172 is more than an IDE controller */ | ||
284 | return ide_setup_pci_device(dev, &it8172_chipsets[id->driver_data]); | ||
285 | } | ||
286 | |||
287 | static struct pci_device_id it8172_pci_tbl[] = { | ||
288 | { PCI_VENDOR_ID_ITE, PCI_DEVICE_ID_ITE_IT8172G, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, | ||
289 | { 0, }, | ||
290 | }; | ||
291 | MODULE_DEVICE_TABLE(pci, it8172_pci_tbl); | ||
292 | |||
293 | static struct pci_driver driver = { | ||
294 | .name = "IT8172_IDE", | ||
295 | .id_table = it8172_pci_tbl, | ||
296 | .probe = it8172_init_one, | ||
297 | }; | ||
298 | |||
299 | static int it8172_ide_init(void) | ||
300 | { | ||
301 | return ide_pci_register_driver(&driver); | ||
302 | } | ||
303 | |||
304 | module_init(it8172_ide_init); | ||
305 | |||
306 | MODULE_AUTHOR("SteveL@mvista.com"); | ||
307 | MODULE_DESCRIPTION("PCI driver module for ITE 8172 IDE"); | ||
308 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/ide/pci/ns87415.c b/drivers/ide/pci/ns87415.c new file mode 100644 index 000000000000..205a32fbc2f0 --- /dev/null +++ b/drivers/ide/pci/ns87415.c | |||
@@ -0,0 +1,315 @@ | |||
1 | /* | ||
2 | * linux/drivers/ide/pci/ns87415.c Version 2.00 Sep. 10, 2002 | ||
3 | * | ||
4 | * Copyright (C) 1997-1998 Mark Lord <mlord@pobox.com> | ||
5 | * Copyright (C) 1998 Eddie C. Dost <ecd@skynet.be> | ||
6 | * Copyright (C) 1999-2000 Andre Hedrick <andre@linux-ide.org> | ||
7 | * Copyright (C) 2004 Grant Grundler <grundler at parisc-linux.org> | ||
8 | * | ||
9 | * Inspired by an earlier effort from David S. Miller <davem@redhat.com> | ||
10 | */ | ||
11 | |||
12 | #include <linux/config.h> | ||
13 | #include <linux/module.h> | ||
14 | #include <linux/types.h> | ||
15 | #include <linux/kernel.h> | ||
16 | #include <linux/timer.h> | ||
17 | #include <linux/mm.h> | ||
18 | #include <linux/ioport.h> | ||
19 | #include <linux/interrupt.h> | ||
20 | #include <linux/blkdev.h> | ||
21 | #include <linux/hdreg.h> | ||
22 | #include <linux/pci.h> | ||
23 | #include <linux/delay.h> | ||
24 | #include <linux/ide.h> | ||
25 | #include <linux/init.h> | ||
26 | |||
27 | #include <asm/io.h> | ||
28 | |||
29 | #ifdef CONFIG_SUPERIO | ||
30 | /* SUPERIO 87560 is a PoS chip that NatSem denies exists. | ||
31 | * Unfortunately, it's built-in on all Astro-based PA-RISC workstations | ||
32 | * which use the integrated NS87514 cell for CD-ROM support. | ||
33 | * i.e we have to support for CD-ROM installs. | ||
34 | * See drivers/parisc/superio.c for more gory details. | ||
35 | */ | ||
36 | #include <asm/superio.h> | ||
37 | |||
38 | static unsigned long superio_ide_status[2]; | ||
39 | static unsigned long superio_ide_select[2]; | ||
40 | static unsigned long superio_ide_dma_status[2]; | ||
41 | |||
42 | #define SUPERIO_IDE_MAX_RETRIES 25 | ||
43 | |||
44 | /* Because of a defect in Super I/O, all reads of the PCI DMA status | ||
45 | * registers, IDE status register and the IDE select register need to be | ||
46 | * retried | ||
47 | */ | ||
48 | static u8 superio_ide_inb (unsigned long port) | ||
49 | { | ||
50 | if (port == superio_ide_status[0] || | ||
51 | port == superio_ide_status[1] || | ||
52 | port == superio_ide_select[0] || | ||
53 | port == superio_ide_select[1] || | ||
54 | port == superio_ide_dma_status[0] || | ||
55 | port == superio_ide_dma_status[1]) { | ||
56 | u8 tmp; | ||
57 | int retries = SUPERIO_IDE_MAX_RETRIES; | ||
58 | |||
59 | /* printk(" [ reading port 0x%x with retry ] ", port); */ | ||
60 | |||
61 | do { | ||
62 | tmp = inb(port); | ||
63 | if (tmp == 0) | ||
64 | udelay(50); | ||
65 | } while (tmp == 0 && retries-- > 0); | ||
66 | |||
67 | return tmp; | ||
68 | } | ||
69 | |||
70 | return inb(port); | ||
71 | } | ||
72 | |||
73 | static void __devinit superio_ide_init_iops (struct hwif_s *hwif) | ||
74 | { | ||
75 | u32 base, dmabase; | ||
76 | u8 tmp; | ||
77 | struct pci_dev *pdev = hwif->pci_dev; | ||
78 | u8 port = hwif->channel; | ||
79 | |||
80 | base = pci_resource_start(pdev, port * 2) & ~3; | ||
81 | dmabase = pci_resource_start(pdev, 4) & ~3; | ||
82 | |||
83 | superio_ide_status[port] = base + IDE_STATUS_OFFSET; | ||
84 | superio_ide_select[port] = base + IDE_SELECT_OFFSET; | ||
85 | superio_ide_dma_status[port] = dmabase + (!port ? 2 : 0xa); | ||
86 | |||
87 | /* Clear error/interrupt, enable dma */ | ||
88 | tmp = superio_ide_inb(superio_ide_dma_status[port]); | ||
89 | outb(tmp | 0x66, superio_ide_dma_status[port]); | ||
90 | |||
91 | /* We need to override inb to workaround a SuperIO errata */ | ||
92 | hwif->INB = superio_ide_inb; | ||
93 | } | ||
94 | |||
95 | static void __devinit init_iops_ns87415(ide_hwif_t *hwif) | ||
96 | { | ||
97 | if (PCI_SLOT(hwif->pci_dev->devfn) == 0xE) { | ||
98 | /* Built-in - assume it's under superio. */ | ||
99 | superio_ide_init_iops(hwif); | ||
100 | } | ||
101 | } | ||
102 | #endif | ||
103 | |||
104 | static unsigned int ns87415_count = 0, ns87415_control[MAX_HWIFS] = { 0 }; | ||
105 | |||
106 | /* | ||
107 | * This routine either enables/disables (according to drive->present) | ||
108 | * the IRQ associated with the port (HWIF(drive)), | ||
109 | * and selects either PIO or DMA handshaking for the next I/O operation. | ||
110 | */ | ||
111 | static void ns87415_prepare_drive (ide_drive_t *drive, unsigned int use_dma) | ||
112 | { | ||
113 | ide_hwif_t *hwif = HWIF(drive); | ||
114 | unsigned int bit, other, new, *old = (unsigned int *) hwif->select_data; | ||
115 | struct pci_dev *dev = hwif->pci_dev; | ||
116 | unsigned long flags; | ||
117 | |||
118 | local_irq_save(flags); | ||
119 | new = *old; | ||
120 | |||
121 | /* Adjust IRQ enable bit */ | ||
122 | bit = 1 << (8 + hwif->channel); | ||
123 | new = drive->present ? (new & ~bit) : (new | bit); | ||
124 | |||
125 | /* Select PIO or DMA, DMA may only be selected for one drive/channel. */ | ||
126 | bit = 1 << (20 + drive->select.b.unit + (hwif->channel << 1)); | ||
127 | other = 1 << (20 + (1 - drive->select.b.unit) + (hwif->channel << 1)); | ||
128 | new = use_dma ? ((new & ~other) | bit) : (new & ~bit); | ||
129 | |||
130 | if (new != *old) { | ||
131 | unsigned char stat; | ||
132 | |||
133 | /* | ||
134 | * Don't change DMA engine settings while Write Buffers | ||
135 | * are busy. | ||
136 | */ | ||
137 | (void) pci_read_config_byte(dev, 0x43, &stat); | ||
138 | while (stat & 0x03) { | ||
139 | udelay(1); | ||
140 | (void) pci_read_config_byte(dev, 0x43, &stat); | ||
141 | } | ||
142 | |||
143 | *old = new; | ||
144 | (void) pci_write_config_dword(dev, 0x40, new); | ||
145 | |||
146 | /* | ||
147 | * And let things settle... | ||
148 | */ | ||
149 | udelay(10); | ||
150 | } | ||
151 | |||
152 | local_irq_restore(flags); | ||
153 | } | ||
154 | |||
155 | static void ns87415_selectproc (ide_drive_t *drive) | ||
156 | { | ||
157 | ns87415_prepare_drive (drive, drive->using_dma); | ||
158 | } | ||
159 | |||
160 | static int ns87415_ide_dma_end (ide_drive_t *drive) | ||
161 | { | ||
162 | ide_hwif_t *hwif = HWIF(drive); | ||
163 | u8 dma_stat = 0, dma_cmd = 0; | ||
164 | |||
165 | drive->waiting_for_dma = 0; | ||
166 | dma_stat = hwif->INB(hwif->dma_status); | ||
167 | /* get dma command mode */ | ||
168 | dma_cmd = hwif->INB(hwif->dma_command); | ||
169 | /* stop DMA */ | ||
170 | hwif->OUTB(dma_cmd & ~1, hwif->dma_command); | ||
171 | /* from ERRATA: clear the INTR & ERROR bits */ | ||
172 | dma_cmd = hwif->INB(hwif->dma_command); | ||
173 | hwif->OUTB(dma_cmd|6, hwif->dma_command); | ||
174 | /* and free any DMA resources */ | ||
175 | ide_destroy_dmatable(drive); | ||
176 | /* verify good DMA status */ | ||
177 | return (dma_stat & 7) != 4; | ||
178 | } | ||
179 | |||
180 | static int ns87415_ide_dma_setup(ide_drive_t *drive) | ||
181 | { | ||
182 | /* select DMA xfer */ | ||
183 | ns87415_prepare_drive(drive, 1); | ||
184 | if (!ide_dma_setup(drive)) | ||
185 | return 0; | ||
186 | /* DMA failed: select PIO xfer */ | ||
187 | ns87415_prepare_drive(drive, 0); | ||
188 | return 1; | ||
189 | } | ||
190 | |||
191 | static int ns87415_ide_dma_check (ide_drive_t *drive) | ||
192 | { | ||
193 | if (drive->media != ide_disk) | ||
194 | return HWIF(drive)->ide_dma_off_quietly(drive); | ||
195 | return __ide_dma_check(drive); | ||
196 | } | ||
197 | |||
198 | static void __init init_hwif_ns87415 (ide_hwif_t *hwif) | ||
199 | { | ||
200 | struct pci_dev *dev = hwif->pci_dev; | ||
201 | unsigned int ctrl, using_inta; | ||
202 | u8 progif; | ||
203 | #ifdef __sparc_v9__ | ||
204 | int timeout; | ||
205 | u8 stat; | ||
206 | #endif | ||
207 | |||
208 | hwif->autodma = 0; | ||
209 | hwif->selectproc = &ns87415_selectproc; | ||
210 | |||
211 | /* | ||
212 | * We cannot probe for IRQ: both ports share common IRQ on INTA. | ||
213 | * Also, leave IRQ masked during drive probing, to prevent infinite | ||
214 | * interrupts from a potentially floating INTA.. | ||
215 | * | ||
216 | * IRQs get unmasked in selectproc when drive is first used. | ||
217 | */ | ||
218 | (void) pci_read_config_dword(dev, 0x40, &ctrl); | ||
219 | (void) pci_read_config_byte(dev, 0x09, &progif); | ||
220 | /* is irq in "native" mode? */ | ||
221 | using_inta = progif & (1 << (hwif->channel << 1)); | ||
222 | if (!using_inta) | ||
223 | using_inta = ctrl & (1 << (4 + hwif->channel)); | ||
224 | if (hwif->mate) { | ||
225 | hwif->select_data = hwif->mate->select_data; | ||
226 | } else { | ||
227 | hwif->select_data = (unsigned long) | ||
228 | &ns87415_control[ns87415_count++]; | ||
229 | ctrl |= (1 << 8) | (1 << 9); /* mask both IRQs */ | ||
230 | if (using_inta) | ||
231 | ctrl &= ~(1 << 6); /* unmask INTA */ | ||
232 | *((unsigned int *)hwif->select_data) = ctrl; | ||
233 | (void) pci_write_config_dword(dev, 0x40, ctrl); | ||
234 | |||
235 | /* | ||
236 | * Set prefetch size to 512 bytes for both ports, | ||
237 | * but don't turn on/off prefetching here. | ||
238 | */ | ||
239 | pci_write_config_byte(dev, 0x55, 0xee); | ||
240 | |||
241 | #ifdef __sparc_v9__ | ||
242 | /* | ||
243 | * XXX: Reset the device, if we don't it will not respond | ||
244 | * to SELECT_DRIVE() properly during first probe_hwif(). | ||
245 | */ | ||
246 | timeout = 10000; | ||
247 | hwif->OUTB(12, hwif->io_ports[IDE_CONTROL_OFFSET]); | ||
248 | udelay(10); | ||
249 | hwif->OUTB(8, hwif->io_ports[IDE_CONTROL_OFFSET]); | ||
250 | do { | ||
251 | udelay(50); | ||
252 | stat = hwif->INB(hwif->io_ports[IDE_STATUS_OFFSET]); | ||
253 | if (stat == 0xff) | ||
254 | break; | ||
255 | } while ((stat & BUSY_STAT) && --timeout); | ||
256 | #endif | ||
257 | } | ||
258 | |||
259 | if (!using_inta) | ||
260 | hwif->irq = ide_default_irq(hwif->io_ports[IDE_DATA_OFFSET]); | ||
261 | else if (!hwif->irq && hwif->mate && hwif->mate->irq) | ||
262 | hwif->irq = hwif->mate->irq; /* share IRQ with mate */ | ||
263 | |||
264 | if (!hwif->dma_base) | ||
265 | return; | ||
266 | |||
267 | hwif->OUTB(0x60, hwif->dma_status); | ||
268 | hwif->dma_setup = &ns87415_ide_dma_setup; | ||
269 | hwif->ide_dma_check = &ns87415_ide_dma_check; | ||
270 | hwif->ide_dma_end = &ns87415_ide_dma_end; | ||
271 | |||
272 | if (!noautodma) | ||
273 | hwif->autodma = 1; | ||
274 | hwif->drives[0].autodma = hwif->autodma; | ||
275 | hwif->drives[1].autodma = hwif->autodma; | ||
276 | } | ||
277 | |||
278 | static ide_pci_device_t ns87415_chipset __devinitdata = { | ||
279 | .name = "NS87415", | ||
280 | #ifdef CONFIG_SUPERIO | ||
281 | .init_iops = init_iops_ns87415, | ||
282 | #endif | ||
283 | .init_hwif = init_hwif_ns87415, | ||
284 | .channels = 2, | ||
285 | .autodma = AUTODMA, | ||
286 | .bootable = ON_BOARD, | ||
287 | }; | ||
288 | |||
289 | static int __devinit ns87415_init_one(struct pci_dev *dev, const struct pci_device_id *id) | ||
290 | { | ||
291 | return ide_setup_pci_device(dev, &ns87415_chipset); | ||
292 | } | ||
293 | |||
294 | static struct pci_device_id ns87415_pci_tbl[] = { | ||
295 | { PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_87415, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, | ||
296 | { 0, }, | ||
297 | }; | ||
298 | MODULE_DEVICE_TABLE(pci, ns87415_pci_tbl); | ||
299 | |||
300 | static struct pci_driver driver = { | ||
301 | .name = "NS87415_IDE", | ||
302 | .id_table = ns87415_pci_tbl, | ||
303 | .probe = ns87415_init_one, | ||
304 | }; | ||
305 | |||
306 | static int ns87415_ide_init(void) | ||
307 | { | ||
308 | return ide_pci_register_driver(&driver); | ||
309 | } | ||
310 | |||
311 | module_init(ns87415_ide_init); | ||
312 | |||
313 | MODULE_AUTHOR("Mark Lord, Eddie Dost, Andre Hedrick"); | ||
314 | MODULE_DESCRIPTION("PCI driver module for NS87415 IDE"); | ||
315 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/ide/pci/opti621.c b/drivers/ide/pci/opti621.c new file mode 100644 index 000000000000..cf4fd91d396a --- /dev/null +++ b/drivers/ide/pci/opti621.c | |||
@@ -0,0 +1,394 @@ | |||
1 | /* | ||
2 | * linux/drivers/ide/pci/opti621.c Version 0.7 Sept 10, 2002 | ||
3 | * | ||
4 | * Copyright (C) 1996-1998 Linus Torvalds & authors (see below) | ||
5 | */ | ||
6 | |||
7 | /* | ||
8 | * Authors: | ||
9 | * Jaromir Koutek <miri@punknet.cz>, | ||
10 | * Jan Harkes <jaharkes@cwi.nl>, | ||
11 | * Mark Lord <mlord@pobox.com> | ||
12 | * Some parts of code are from ali14xx.c and from rz1000.c. | ||
13 | * | ||
14 | * OPTi is trademark of OPTi, Octek is trademark of Octek. | ||
15 | * | ||
16 | * I used docs from OPTi databook, from ftp.opti.com, file 9123-0002.ps | ||
17 | * and disassembled/traced setupvic.exe (DOS program). | ||
18 | * It increases kernel code about 2 kB. | ||
19 | * I don't have this card no more, but I hope I can get some in case | ||
20 | * of needed development. | ||
21 | * My card is Octek PIDE 1.01 (on card) or OPTiViC (program). | ||
22 | * It has a place for a secondary connector in circuit, but nothing | ||
23 | * is there. Also BIOS says no address for | ||
24 | * secondary controller (see bellow in ide_init_opti621). | ||
25 | * I've only tested this on my system, which only has one disk. | ||
26 | * It's Western Digital WDAC2850, with PIO mode 3. The PCI bus | ||
27 | * is at 20 MHz (I have DX2/80, I tried PCI at 40, but I got random | ||
28 | * lockups). I tried the OCTEK double speed CD-ROM and | ||
29 | * it does not work! But I can't boot DOS also, so it's probably | ||
30 | * hardware fault. I have connected Conner 80MB, the Seagate 850MB (no | ||
31 | * problems) and Seagate 1GB (as slave, WD as master). My experiences | ||
32 | * with the third, 1GB drive: I got 3MB/s (hdparm), but sometimes | ||
33 | * it slows to about 100kB/s! I don't know why and I have | ||
34 | * not this drive now, so I can't try it again. | ||
35 | * I write this driver because I lost the paper ("manual") with | ||
36 | * settings of jumpers on the card and I have to boot Linux with | ||
37 | * Loadlin except LILO, cause I have to run the setupvic.exe program | ||
38 | * already or I get disk errors (my test: rpm -Vf | ||
39 | * /usr/X11R6/bin/XF86_SVGA - or any big file). | ||
40 | * Some numbers from hdparm -t /dev/hda: | ||
41 | * Timing buffer-cache reads: 32 MB in 3.02 seconds =10.60 MB/sec | ||
42 | * Timing buffered disk reads: 16 MB in 5.52 seconds = 2.90 MB/sec | ||
43 | * I have 4 Megs/s before, but I don't know why (maybe changes | ||
44 | * in hdparm test). | ||
45 | * After release of 0.1, I got some successful reports, so it might work. | ||
46 | * | ||
47 | * The main problem with OPTi is that some timings for master | ||
48 | * and slave must be the same. For example, if you have master | ||
49 | * PIO 3 and slave PIO 0, driver have to set some timings of | ||
50 | * master for PIO 0. Second problem is that opti621_tune_drive | ||
51 | * got only one drive to set, but have to set both drives. | ||
52 | * This is solved in compute_pios. If you don't set | ||
53 | * the second drive, compute_pios use ide_get_best_pio_mode | ||
54 | * for autoselect mode (you can change it to PIO 0, if you want). | ||
55 | * If you then set the second drive to another PIO, the old value | ||
56 | * (automatically selected) will be overrided by yours. | ||
57 | * There is a 25/33MHz switch in configuration | ||
58 | * register, but driver is written for use at any frequency which get | ||
59 | * (use idebus=xx to select PCI bus speed). | ||
60 | * Use ide0=autotune for automatical tune of the PIO modes. | ||
61 | * If you get strange results, do not use this and set PIO manually | ||
62 | * by hdparm. | ||
63 | * | ||
64 | * Version 0.1, Nov 8, 1996 | ||
65 | * by Jaromir Koutek, for 2.1.8. | ||
66 | * Initial version of driver. | ||
67 | * | ||
68 | * Version 0.2 | ||
69 | * Number 0.2 skipped. | ||
70 | * | ||
71 | * Version 0.3, Nov 29, 1997 | ||
72 | * by Mark Lord (probably), for 2.1.68 | ||
73 | * Updates for use with new IDE block driver. | ||
74 | * | ||
75 | * Version 0.4, Dec 14, 1997 | ||
76 | * by Jan Harkes | ||
77 | * Fixed some errors and cleaned the code. | ||
78 | * | ||
79 | * Version 0.5, Jan 2, 1998 | ||
80 | * by Jaromir Koutek | ||
81 | * Updates for use with (again) new IDE block driver. | ||
82 | * Update of documentation. | ||
83 | * | ||
84 | * Version 0.6, Jan 2, 1999 | ||
85 | * by Jaromir Koutek | ||
86 | * Reversed to version 0.3 of the driver, because | ||
87 | * 0.5 doesn't work. | ||
88 | */ | ||
89 | |||
90 | #undef REALLY_SLOW_IO /* most systems can safely undef this */ | ||
91 | #define OPTI621_DEBUG /* define for debug messages */ | ||
92 | |||
93 | #include <linux/types.h> | ||
94 | #include <linux/module.h> | ||
95 | #include <linux/kernel.h> | ||
96 | #include <linux/delay.h> | ||
97 | #include <linux/timer.h> | ||
98 | #include <linux/mm.h> | ||
99 | #include <linux/ioport.h> | ||
100 | #include <linux/blkdev.h> | ||
101 | #include <linux/pci.h> | ||
102 | #include <linux/hdreg.h> | ||
103 | #include <linux/ide.h> | ||
104 | |||
105 | #include <asm/io.h> | ||
106 | |||
107 | #define OPTI621_MAX_PIO 3 | ||
108 | /* In fact, I do not have any PIO 4 drive | ||
109 | * (address: 25 ns, data: 70 ns, recovery: 35 ns), | ||
110 | * but OPTi 82C621 is programmable and it can do (minimal values): | ||
111 | * on 40MHz PCI bus (pulse 25 ns): | ||
112 | * address: 25 ns, data: 25 ns, recovery: 50 ns; | ||
113 | * on 20MHz PCI bus (pulse 50 ns): | ||
114 | * address: 50 ns, data: 50 ns, recovery: 100 ns. | ||
115 | */ | ||
116 | |||
117 | /* #define READ_PREFETCH 0 */ | ||
118 | /* Uncomment for disable read prefetch. | ||
119 | * There is some readprefetch capatibility in hdparm, | ||
120 | * but when I type hdparm -P 1 /dev/hda, I got errors | ||
121 | * and till reset drive is inaccessible. | ||
122 | * This (hw) read prefetch is safe on my drive. | ||
123 | */ | ||
124 | |||
125 | #ifndef READ_PREFETCH | ||
126 | #define READ_PREFETCH 0x40 /* read prefetch is enabled */ | ||
127 | #endif /* else read prefetch is disabled */ | ||
128 | |||
129 | #define READ_REG 0 /* index of Read cycle timing register */ | ||
130 | #define WRITE_REG 1 /* index of Write cycle timing register */ | ||
131 | #define CNTRL_REG 3 /* index of Control register */ | ||
132 | #define STRAP_REG 5 /* index of Strap register */ | ||
133 | #define MISC_REG 6 /* index of Miscellaneous register */ | ||
134 | |||
135 | static int reg_base; | ||
136 | |||
137 | #define PIO_NOT_EXIST 254 | ||
138 | #define PIO_DONT_KNOW 255 | ||
139 | |||
140 | /* there are stored pio numbers from other calls of opti621_tune_drive */ | ||
141 | static void compute_pios(ide_drive_t *drive, u8 pio) | ||
142 | /* Store values into drive->drive_data | ||
143 | * second_contr - 0 for primary controller, 1 for secondary | ||
144 | * slave_drive - 0 -> pio is for master, 1 -> pio is for slave | ||
145 | * pio - PIO mode for selected drive (for other we don't know) | ||
146 | */ | ||
147 | { | ||
148 | int d; | ||
149 | ide_hwif_t *hwif = HWIF(drive); | ||
150 | |||
151 | drive->drive_data = ide_get_best_pio_mode(drive, pio, OPTI621_MAX_PIO, NULL); | ||
152 | for (d = 0; d < 2; ++d) { | ||
153 | drive = &hwif->drives[d]; | ||
154 | if (drive->present) { | ||
155 | if (drive->drive_data == PIO_DONT_KNOW) | ||
156 | drive->drive_data = ide_get_best_pio_mode(drive, 255, OPTI621_MAX_PIO, NULL); | ||
157 | #ifdef OPTI621_DEBUG | ||
158 | printk("%s: Selected PIO mode %d\n", | ||
159 | drive->name, drive->drive_data); | ||
160 | #endif | ||
161 | } else { | ||
162 | drive->drive_data = PIO_NOT_EXIST; | ||
163 | } | ||
164 | } | ||
165 | } | ||
166 | |||
167 | static int cmpt_clk(int time, int bus_speed) | ||
168 | /* Returns (rounded up) time in clocks for time in ns, | ||
169 | * with bus_speed in MHz. | ||
170 | * Example: bus_speed = 40 MHz, time = 80 ns | ||
171 | * 1000/40 = 25 ns (clk value), | ||
172 | * 80/25 = 3.2, rounded up to 4 (I hope ;-)). | ||
173 | * Use idebus=xx to select right frequency. | ||
174 | */ | ||
175 | { | ||
176 | return ((time*bus_speed+999)/1000); | ||
177 | } | ||
178 | |||
179 | static void write_reg(ide_hwif_t *hwif, u8 value, int reg) | ||
180 | /* Write value to register reg, base of register | ||
181 | * is at reg_base (0x1f0 primary, 0x170 secondary, | ||
182 | * if not changed by PCI configuration). | ||
183 | * This is from setupvic.exe program. | ||
184 | */ | ||
185 | { | ||
186 | hwif->INW(reg_base+1); | ||
187 | hwif->INW(reg_base+1); | ||
188 | hwif->OUTB(3, reg_base+2); | ||
189 | hwif->OUTB(value, reg_base+reg); | ||
190 | hwif->OUTB(0x83, reg_base+2); | ||
191 | } | ||
192 | |||
193 | static u8 read_reg(ide_hwif_t *hwif, int reg) | ||
194 | /* Read value from register reg, base of register | ||
195 | * is at reg_base (0x1f0 primary, 0x170 secondary, | ||
196 | * if not changed by PCI configuration). | ||
197 | * This is from setupvic.exe program. | ||
198 | */ | ||
199 | { | ||
200 | u8 ret = 0; | ||
201 | |||
202 | hwif->INW(reg_base+1); | ||
203 | hwif->INW(reg_base+1); | ||
204 | hwif->OUTB(3, reg_base+2); | ||
205 | ret = hwif->INB(reg_base+reg); | ||
206 | hwif->OUTB(0x83, reg_base+2); | ||
207 | return ret; | ||
208 | } | ||
209 | |||
210 | typedef struct pio_clocks_s { | ||
211 | int address_time; /* Address setup (clocks) */ | ||
212 | int data_time; /* Active/data pulse (clocks) */ | ||
213 | int recovery_time; /* Recovery time (clocks) */ | ||
214 | } pio_clocks_t; | ||
215 | |||
216 | static void compute_clocks(int pio, pio_clocks_t *clks) | ||
217 | { | ||
218 | if (pio != PIO_NOT_EXIST) { | ||
219 | int adr_setup, data_pls; | ||
220 | int bus_speed = system_bus_clock(); | ||
221 | |||
222 | adr_setup = ide_pio_timings[pio].setup_time; | ||
223 | data_pls = ide_pio_timings[pio].active_time; | ||
224 | clks->address_time = cmpt_clk(adr_setup, bus_speed); | ||
225 | clks->data_time = cmpt_clk(data_pls, bus_speed); | ||
226 | clks->recovery_time = cmpt_clk(ide_pio_timings[pio].cycle_time | ||
227 | - adr_setup-data_pls, bus_speed); | ||
228 | if (clks->address_time<1) clks->address_time = 1; | ||
229 | if (clks->address_time>4) clks->address_time = 4; | ||
230 | if (clks->data_time<1) clks->data_time = 1; | ||
231 | if (clks->data_time>16) clks->data_time = 16; | ||
232 | if (clks->recovery_time<2) clks->recovery_time = 2; | ||
233 | if (clks->recovery_time>17) clks->recovery_time = 17; | ||
234 | } else { | ||
235 | clks->address_time = 1; | ||
236 | clks->data_time = 1; | ||
237 | clks->recovery_time = 2; | ||
238 | /* minimal values */ | ||
239 | } | ||
240 | |||
241 | } | ||
242 | |||
243 | /* Main tune procedure, called from tuneproc. */ | ||
244 | static void opti621_tune_drive (ide_drive_t *drive, u8 pio) | ||
245 | { | ||
246 | /* primary and secondary drives share some registers, | ||
247 | * so we have to program both drives | ||
248 | */ | ||
249 | unsigned long flags; | ||
250 | u8 pio1 = 0, pio2 = 0; | ||
251 | pio_clocks_t first, second; | ||
252 | int ax, drdy; | ||
253 | u8 cycle1, cycle2, misc; | ||
254 | ide_hwif_t *hwif = HWIF(drive); | ||
255 | |||
256 | /* sets drive->drive_data for both drives */ | ||
257 | compute_pios(drive, pio); | ||
258 | pio1 = hwif->drives[0].drive_data; | ||
259 | pio2 = hwif->drives[1].drive_data; | ||
260 | |||
261 | compute_clocks(pio1, &first); | ||
262 | compute_clocks(pio2, &second); | ||
263 | |||
264 | /* ax = max(a1,a2) */ | ||
265 | ax = (first.address_time < second.address_time) ? second.address_time : first.address_time; | ||
266 | |||
267 | drdy = 2; /* DRDY is default 2 (by OPTi Databook) */ | ||
268 | |||
269 | cycle1 = ((first.data_time-1)<<4) | (first.recovery_time-2); | ||
270 | cycle2 = ((second.data_time-1)<<4) | (second.recovery_time-2); | ||
271 | misc = READ_PREFETCH | ((ax-1)<<4) | ((drdy-2)<<1); | ||
272 | |||
273 | #ifdef OPTI621_DEBUG | ||
274 | printk("%s: master: address: %d, data: %d, " | ||
275 | "recovery: %d, drdy: %d [clk]\n", | ||
276 | hwif->name, ax, first.data_time, | ||
277 | first.recovery_time, drdy); | ||
278 | printk("%s: slave: address: %d, data: %d, " | ||
279 | "recovery: %d, drdy: %d [clk]\n", | ||
280 | hwif->name, ax, second.data_time, | ||
281 | second.recovery_time, drdy); | ||
282 | #endif | ||
283 | |||
284 | spin_lock_irqsave(&ide_lock, flags); | ||
285 | |||
286 | reg_base = hwif->io_ports[IDE_DATA_OFFSET]; | ||
287 | |||
288 | /* allow Register-B */ | ||
289 | hwif->OUTB(0xc0, reg_base+CNTRL_REG); | ||
290 | /* hmm, setupvic.exe does this ;-) */ | ||
291 | hwif->OUTB(0xff, reg_base+5); | ||
292 | /* if reads 0xff, adapter not exist? */ | ||
293 | (void) hwif->INB(reg_base+CNTRL_REG); | ||
294 | /* if reads 0xc0, no interface exist? */ | ||
295 | read_reg(hwif, CNTRL_REG); | ||
296 | /* read version, probably 0 */ | ||
297 | read_reg(hwif, STRAP_REG); | ||
298 | |||
299 | /* program primary drive */ | ||
300 | /* select Index-0 for Register-A */ | ||
301 | write_reg(hwif, 0, MISC_REG); | ||
302 | /* set read cycle timings */ | ||
303 | write_reg(hwif, cycle1, READ_REG); | ||
304 | /* set write cycle timings */ | ||
305 | write_reg(hwif, cycle1, WRITE_REG); | ||
306 | |||
307 | /* program secondary drive */ | ||
308 | /* select Index-1 for Register-B */ | ||
309 | write_reg(hwif, 1, MISC_REG); | ||
310 | /* set read cycle timings */ | ||
311 | write_reg(hwif, cycle2, READ_REG); | ||
312 | /* set write cycle timings */ | ||
313 | write_reg(hwif, cycle2, WRITE_REG); | ||
314 | |||
315 | /* use Register-A for drive 0 */ | ||
316 | /* use Register-B for drive 1 */ | ||
317 | write_reg(hwif, 0x85, CNTRL_REG); | ||
318 | |||
319 | /* set address setup, DRDY timings, */ | ||
320 | /* and read prefetch for both drives */ | ||
321 | write_reg(hwif, misc, MISC_REG); | ||
322 | |||
323 | spin_unlock_irqrestore(&ide_lock, flags); | ||
324 | } | ||
325 | |||
326 | /* | ||
327 | * init_hwif_opti621() is called once for each hwif found at boot. | ||
328 | */ | ||
329 | static void __init init_hwif_opti621 (ide_hwif_t *hwif) | ||
330 | { | ||
331 | hwif->autodma = 0; | ||
332 | hwif->drives[0].drive_data = PIO_DONT_KNOW; | ||
333 | hwif->drives[1].drive_data = PIO_DONT_KNOW; | ||
334 | hwif->tuneproc = &opti621_tune_drive; | ||
335 | |||
336 | if (!(hwif->dma_base)) | ||
337 | return; | ||
338 | |||
339 | hwif->atapi_dma = 1; | ||
340 | hwif->mwdma_mask = 0x07; | ||
341 | hwif->swdma_mask = 0x07; | ||
342 | |||
343 | if (!noautodma) | ||
344 | hwif->autodma = 1; | ||
345 | hwif->drives[0].autodma = hwif->autodma; | ||
346 | hwif->drives[1].autodma = hwif->autodma; | ||
347 | } | ||
348 | |||
349 | static ide_pci_device_t opti621_chipsets[] __devinitdata = { | ||
350 | { /* 0 */ | ||
351 | .name = "OPTI621", | ||
352 | .init_hwif = init_hwif_opti621, | ||
353 | .channels = 2, | ||
354 | .autodma = AUTODMA, | ||
355 | .enablebits = {{0x45,0x80,0x00}, {0x40,0x08,0x00}}, | ||
356 | .bootable = ON_BOARD, | ||
357 | },{ /* 1 */ | ||
358 | .name = "OPTI621X", | ||
359 | .init_hwif = init_hwif_opti621, | ||
360 | .channels = 2, | ||
361 | .autodma = AUTODMA, | ||
362 | .enablebits = {{0x45,0x80,0x00}, {0x40,0x08,0x00}}, | ||
363 | .bootable = ON_BOARD, | ||
364 | } | ||
365 | }; | ||
366 | |||
367 | static int __devinit opti621_init_one(struct pci_dev *dev, const struct pci_device_id *id) | ||
368 | { | ||
369 | return ide_setup_pci_device(dev, &opti621_chipsets[id->driver_data]); | ||
370 | } | ||
371 | |||
372 | static struct pci_device_id opti621_pci_tbl[] = { | ||
373 | { PCI_VENDOR_ID_OPTI, PCI_DEVICE_ID_OPTI_82C621, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, | ||
374 | { PCI_VENDOR_ID_OPTI, PCI_DEVICE_ID_OPTI_82C825, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1}, | ||
375 | { 0, }, | ||
376 | }; | ||
377 | MODULE_DEVICE_TABLE(pci, opti621_pci_tbl); | ||
378 | |||
379 | static struct pci_driver driver = { | ||
380 | .name = "Opti621_IDE", | ||
381 | .id_table = opti621_pci_tbl, | ||
382 | .probe = opti621_init_one, | ||
383 | }; | ||
384 | |||
385 | static int opti621_ide_init(void) | ||
386 | { | ||
387 | return ide_pci_register_driver(&driver); | ||
388 | } | ||
389 | |||
390 | module_init(opti621_ide_init); | ||
391 | |||
392 | MODULE_AUTHOR("Jaromir Koutek, Jan Harkes, Mark Lord"); | ||
393 | MODULE_DESCRIPTION("PCI driver module for Opti621 IDE"); | ||
394 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/ide/pci/pdc202xx_new.c b/drivers/ide/pci/pdc202xx_new.c new file mode 100644 index 000000000000..211641a54398 --- /dev/null +++ b/drivers/ide/pci/pdc202xx_new.c | |||
@@ -0,0 +1,508 @@ | |||
1 | /* | ||
2 | * Promise TX2/TX4/TX2000/133 IDE driver | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or | ||
5 | * modify it under the terms of the GNU General Public License | ||
6 | * as published by the Free Software Foundation; either version | ||
7 | * 2 of the License, or (at your option) any later version. | ||
8 | * | ||
9 | * Split from: | ||
10 | * linux/drivers/ide/pdc202xx.c Version 0.35 Mar. 30, 2002 | ||
11 | * Copyright (C) 1998-2002 Andre Hedrick <andre@linux-ide.org> | ||
12 | * Portions Copyright (C) 1999 Promise Technology, Inc. | ||
13 | * Author: Frank Tiernan (frankt@promise.com) | ||
14 | * Released under terms of General Public License | ||
15 | */ | ||
16 | |||
17 | #include <linux/config.h> | ||
18 | #include <linux/module.h> | ||
19 | #include <linux/types.h> | ||
20 | #include <linux/kernel.h> | ||
21 | #include <linux/delay.h> | ||
22 | #include <linux/timer.h> | ||
23 | #include <linux/mm.h> | ||
24 | #include <linux/ioport.h> | ||
25 | #include <linux/blkdev.h> | ||
26 | #include <linux/hdreg.h> | ||
27 | #include <linux/interrupt.h> | ||
28 | #include <linux/pci.h> | ||
29 | #include <linux/init.h> | ||
30 | #include <linux/ide.h> | ||
31 | |||
32 | #include <asm/io.h> | ||
33 | #include <asm/irq.h> | ||
34 | |||
35 | #ifdef CONFIG_PPC_PMAC | ||
36 | #include <asm/prom.h> | ||
37 | #include <asm/pci-bridge.h> | ||
38 | #endif | ||
39 | |||
40 | #define PDC202_DEBUG_CABLE 0 | ||
41 | |||
42 | const static char *pdc_quirk_drives[] = { | ||
43 | "QUANTUM FIREBALLlct08 08", | ||
44 | "QUANTUM FIREBALLP KA6.4", | ||
45 | "QUANTUM FIREBALLP KA9.1", | ||
46 | "QUANTUM FIREBALLP LM20.4", | ||
47 | "QUANTUM FIREBALLP KX13.6", | ||
48 | "QUANTUM FIREBALLP KX20.5", | ||
49 | "QUANTUM FIREBALLP KX27.3", | ||
50 | "QUANTUM FIREBALLP LM20.5", | ||
51 | NULL | ||
52 | }; | ||
53 | |||
54 | #define set_2regs(a, b) \ | ||
55 | do { \ | ||
56 | hwif->OUTB((a + adj), indexreg); \ | ||
57 | hwif->OUTB(b, datareg); \ | ||
58 | } while(0) | ||
59 | |||
60 | #define set_ultra(a, b, c) \ | ||
61 | do { \ | ||
62 | set_2regs(0x10,(a)); \ | ||
63 | set_2regs(0x11,(b)); \ | ||
64 | set_2regs(0x12,(c)); \ | ||
65 | } while(0) | ||
66 | |||
67 | #define set_ata2(a, b) \ | ||
68 | do { \ | ||
69 | set_2regs(0x0e,(a)); \ | ||
70 | set_2regs(0x0f,(b)); \ | ||
71 | } while(0) | ||
72 | |||
73 | #define set_pio(a, b, c) \ | ||
74 | do { \ | ||
75 | set_2regs(0x0c,(a)); \ | ||
76 | set_2regs(0x0d,(b)); \ | ||
77 | set_2regs(0x13,(c)); \ | ||
78 | } while(0) | ||
79 | |||
80 | static u8 pdcnew_ratemask (ide_drive_t *drive) | ||
81 | { | ||
82 | u8 mode; | ||
83 | |||
84 | switch(HWIF(drive)->pci_dev->device) { | ||
85 | case PCI_DEVICE_ID_PROMISE_20277: | ||
86 | case PCI_DEVICE_ID_PROMISE_20276: | ||
87 | case PCI_DEVICE_ID_PROMISE_20275: | ||
88 | case PCI_DEVICE_ID_PROMISE_20271: | ||
89 | case PCI_DEVICE_ID_PROMISE_20269: | ||
90 | mode = 4; | ||
91 | break; | ||
92 | case PCI_DEVICE_ID_PROMISE_20270: | ||
93 | case PCI_DEVICE_ID_PROMISE_20268: | ||
94 | mode = 3; | ||
95 | break; | ||
96 | default: | ||
97 | return 0; | ||
98 | } | ||
99 | if (!eighty_ninty_three(drive)) | ||
100 | mode = min(mode, (u8)1); | ||
101 | return mode; | ||
102 | } | ||
103 | |||
104 | static int check_in_drive_lists (ide_drive_t *drive, const char **list) | ||
105 | { | ||
106 | struct hd_driveid *id = drive->id; | ||
107 | |||
108 | if (pdc_quirk_drives == list) { | ||
109 | while (*list) { | ||
110 | if (strstr(id->model, *list++)) { | ||
111 | return 2; | ||
112 | } | ||
113 | } | ||
114 | } else { | ||
115 | while (*list) { | ||
116 | if (!strcmp(*list++,id->model)) { | ||
117 | return 1; | ||
118 | } | ||
119 | } | ||
120 | } | ||
121 | return 0; | ||
122 | } | ||
123 | |||
124 | static int pdcnew_new_tune_chipset (ide_drive_t *drive, u8 xferspeed) | ||
125 | { | ||
126 | ide_hwif_t *hwif = HWIF(drive); | ||
127 | unsigned long indexreg = hwif->dma_vendor1; | ||
128 | unsigned long datareg = hwif->dma_vendor3; | ||
129 | u8 thold = 0x10; | ||
130 | u8 adj = (drive->dn%2) ? 0x08 : 0x00; | ||
131 | u8 speed = ide_rate_filter(pdcnew_ratemask(drive), xferspeed); | ||
132 | |||
133 | if (speed == XFER_UDMA_2) { | ||
134 | hwif->OUTB((thold + adj), indexreg); | ||
135 | hwif->OUTB((hwif->INB(datareg) & 0x7f), datareg); | ||
136 | } | ||
137 | |||
138 | switch (speed) { | ||
139 | case XFER_UDMA_7: | ||
140 | speed = XFER_UDMA_6; | ||
141 | case XFER_UDMA_6: set_ultra(0x1a, 0x01, 0xcb); break; | ||
142 | case XFER_UDMA_5: set_ultra(0x1a, 0x02, 0xcb); break; | ||
143 | case XFER_UDMA_4: set_ultra(0x1a, 0x03, 0xcd); break; | ||
144 | case XFER_UDMA_3: set_ultra(0x1a, 0x05, 0xcd); break; | ||
145 | case XFER_UDMA_2: set_ultra(0x2a, 0x07, 0xcd); break; | ||
146 | case XFER_UDMA_1: set_ultra(0x3a, 0x0a, 0xd0); break; | ||
147 | case XFER_UDMA_0: set_ultra(0x4a, 0x0f, 0xd5); break; | ||
148 | case XFER_MW_DMA_2: set_ata2(0x69, 0x25); break; | ||
149 | case XFER_MW_DMA_1: set_ata2(0x6b, 0x27); break; | ||
150 | case XFER_MW_DMA_0: set_ata2(0xdf, 0x5f); break; | ||
151 | case XFER_PIO_4: set_pio(0x23, 0x09, 0x25); break; | ||
152 | case XFER_PIO_3: set_pio(0x27, 0x0d, 0x35); break; | ||
153 | case XFER_PIO_2: set_pio(0x23, 0x26, 0x64); break; | ||
154 | case XFER_PIO_1: set_pio(0x46, 0x29, 0xa4); break; | ||
155 | case XFER_PIO_0: set_pio(0xfb, 0x2b, 0xac); break; | ||
156 | default: | ||
157 | ; | ||
158 | } | ||
159 | |||
160 | return (ide_config_drive_speed(drive, speed)); | ||
161 | } | ||
162 | |||
163 | /* 0 1 2 3 4 5 6 7 8 | ||
164 | * 960, 480, 390, 300, 240, 180, 120, 90, 60 | ||
165 | * 180, 150, 120, 90, 60 | ||
166 | * DMA_Speed | ||
167 | * 180, 120, 90, 90, 90, 60, 30 | ||
168 | * 11, 5, 4, 3, 2, 1, 0 | ||
169 | */ | ||
170 | static void pdcnew_tune_drive(ide_drive_t *drive, u8 pio) | ||
171 | { | ||
172 | u8 speed; | ||
173 | |||
174 | if (pio == 5) pio = 4; | ||
175 | speed = XFER_PIO_0 + ide_get_best_pio_mode(drive, 255, pio, NULL); | ||
176 | |||
177 | (void)pdcnew_new_tune_chipset(drive, speed); | ||
178 | } | ||
179 | |||
180 | static u8 pdcnew_new_cable_detect (ide_hwif_t *hwif) | ||
181 | { | ||
182 | hwif->OUTB(0x0b, hwif->dma_vendor1); | ||
183 | return ((u8)((hwif->INB(hwif->dma_vendor3) & 0x04))); | ||
184 | } | ||
185 | static int config_chipset_for_dma (ide_drive_t *drive) | ||
186 | { | ||
187 | struct hd_driveid *id = drive->id; | ||
188 | ide_hwif_t *hwif = HWIF(drive); | ||
189 | u8 speed = -1; | ||
190 | u8 cable; | ||
191 | |||
192 | u8 ultra_66 = ((id->dma_ultra & 0x0010) || | ||
193 | (id->dma_ultra & 0x0008)) ? 1 : 0; | ||
194 | |||
195 | cable = pdcnew_new_cable_detect(hwif); | ||
196 | |||
197 | if (ultra_66 && cable) { | ||
198 | printk(KERN_WARNING "Warning: %s channel requires an 80-pin cable for operation.\n", hwif->channel ? "Secondary":"Primary"); | ||
199 | printk(KERN_WARNING "%s reduced to Ultra33 mode.\n", drive->name); | ||
200 | } | ||
201 | |||
202 | if (drive->media != ide_disk) | ||
203 | return 0; | ||
204 | if (id->capability & 4) { /* IORDY_EN & PREFETCH_EN */ | ||
205 | hwif->OUTB((0x13 + ((drive->dn%2) ? 0x08 : 0x00)), hwif->dma_vendor1); | ||
206 | hwif->OUTB((hwif->INB(hwif->dma_vendor3)|0x03), hwif->dma_vendor3); | ||
207 | } | ||
208 | |||
209 | speed = ide_dma_speed(drive, pdcnew_ratemask(drive)); | ||
210 | |||
211 | if (!(speed)) { | ||
212 | hwif->tuneproc(drive, 5); | ||
213 | return 0; | ||
214 | } | ||
215 | |||
216 | (void) hwif->speedproc(drive, speed); | ||
217 | return ide_dma_enable(drive); | ||
218 | } | ||
219 | |||
220 | static int pdcnew_config_drive_xfer_rate (ide_drive_t *drive) | ||
221 | { | ||
222 | ide_hwif_t *hwif = HWIF(drive); | ||
223 | struct hd_driveid *id = drive->id; | ||
224 | |||
225 | drive->init_speed = 0; | ||
226 | |||
227 | if (id && (id->capability & 1) && drive->autodma) { | ||
228 | |||
229 | if (ide_use_dma(drive)) { | ||
230 | if (config_chipset_for_dma(drive)) | ||
231 | return hwif->ide_dma_on(drive); | ||
232 | } | ||
233 | |||
234 | goto fast_ata_pio; | ||
235 | |||
236 | } else if ((id->capability & 8) || (id->field_valid & 2)) { | ||
237 | fast_ata_pio: | ||
238 | hwif->tuneproc(drive, 5); | ||
239 | return hwif->ide_dma_off_quietly(drive); | ||
240 | } | ||
241 | /* IORDY not supported */ | ||
242 | return 0; | ||
243 | } | ||
244 | |||
245 | static int pdcnew_quirkproc (ide_drive_t *drive) | ||
246 | { | ||
247 | return ((int) check_in_drive_lists(drive, pdc_quirk_drives)); | ||
248 | } | ||
249 | |||
250 | static int pdcnew_ide_dma_lostirq(ide_drive_t *drive) | ||
251 | { | ||
252 | if (HWIF(drive)->resetproc != NULL) | ||
253 | HWIF(drive)->resetproc(drive); | ||
254 | return __ide_dma_lostirq(drive); | ||
255 | } | ||
256 | |||
257 | static int pdcnew_ide_dma_timeout(ide_drive_t *drive) | ||
258 | { | ||
259 | if (HWIF(drive)->resetproc != NULL) | ||
260 | HWIF(drive)->resetproc(drive); | ||
261 | return __ide_dma_timeout(drive); | ||
262 | } | ||
263 | |||
264 | static void pdcnew_new_reset (ide_drive_t *drive) | ||
265 | { | ||
266 | /* | ||
267 | * Deleted this because it is redundant from the caller. | ||
268 | */ | ||
269 | printk(KERN_WARNING "PDC202XX: %s channel reset.\n", | ||
270 | HWIF(drive)->channel ? "Secondary" : "Primary"); | ||
271 | } | ||
272 | |||
273 | #ifdef CONFIG_PPC_PMAC | ||
274 | static void __devinit apple_kiwi_init(struct pci_dev *pdev) | ||
275 | { | ||
276 | struct device_node *np = pci_device_to_OF_node(pdev); | ||
277 | unsigned int class_rev = 0; | ||
278 | void __iomem *mmio; | ||
279 | u8 conf; | ||
280 | |||
281 | if (np == NULL || !device_is_compatible(np, "kiwi-root")) | ||
282 | return; | ||
283 | |||
284 | pci_read_config_dword(pdev, PCI_CLASS_REVISION, &class_rev); | ||
285 | class_rev &= 0xff; | ||
286 | |||
287 | if (class_rev >= 0x03) { | ||
288 | /* Setup chip magic config stuff (from darwin) */ | ||
289 | pci_read_config_byte(pdev, 0x40, &conf); | ||
290 | pci_write_config_byte(pdev, 0x40, conf | 0x01); | ||
291 | } | ||
292 | mmio = ioremap(pci_resource_start(pdev, 5), | ||
293 | pci_resource_len(pdev, 5)); | ||
294 | |||
295 | /* Setup some PLL stuffs */ | ||
296 | switch (pdev->device) { | ||
297 | case PCI_DEVICE_ID_PROMISE_20270: | ||
298 | writew(0x0d2b, mmio + 0x1202); | ||
299 | mdelay(30); | ||
300 | break; | ||
301 | case PCI_DEVICE_ID_PROMISE_20271: | ||
302 | writew(0x0826, mmio + 0x1202); | ||
303 | mdelay(30); | ||
304 | break; | ||
305 | } | ||
306 | |||
307 | iounmap(mmio); | ||
308 | } | ||
309 | #endif /* CONFIG_PPC_PMAC */ | ||
310 | |||
311 | static unsigned int __devinit init_chipset_pdcnew(struct pci_dev *dev, const char *name) | ||
312 | { | ||
313 | if (dev->resource[PCI_ROM_RESOURCE].start) { | ||
314 | pci_write_config_dword(dev, PCI_ROM_ADDRESS, | ||
315 | dev->resource[PCI_ROM_RESOURCE].start | PCI_ROM_ADDRESS_ENABLE); | ||
316 | printk(KERN_INFO "%s: ROM enabled at 0x%08lx\n", | ||
317 | name, dev->resource[PCI_ROM_RESOURCE].start); | ||
318 | } | ||
319 | |||
320 | #ifdef CONFIG_PPC_PMAC | ||
321 | apple_kiwi_init(dev); | ||
322 | #endif | ||
323 | |||
324 | return dev->irq; | ||
325 | } | ||
326 | |||
327 | static void __devinit init_hwif_pdc202new(ide_hwif_t *hwif) | ||
328 | { | ||
329 | hwif->autodma = 0; | ||
330 | |||
331 | hwif->tuneproc = &pdcnew_tune_drive; | ||
332 | hwif->quirkproc = &pdcnew_quirkproc; | ||
333 | hwif->speedproc = &pdcnew_new_tune_chipset; | ||
334 | hwif->resetproc = &pdcnew_new_reset; | ||
335 | |||
336 | hwif->drives[0].autotune = hwif->drives[1].autotune = 1; | ||
337 | |||
338 | hwif->ultra_mask = 0x7f; | ||
339 | hwif->mwdma_mask = 0x07; | ||
340 | |||
341 | hwif->ide_dma_check = &pdcnew_config_drive_xfer_rate; | ||
342 | hwif->ide_dma_lostirq = &pdcnew_ide_dma_lostirq; | ||
343 | hwif->ide_dma_timeout = &pdcnew_ide_dma_timeout; | ||
344 | if (!(hwif->udma_four)) | ||
345 | hwif->udma_four = (pdcnew_new_cable_detect(hwif)) ? 0 : 1; | ||
346 | if (!noautodma) | ||
347 | hwif->autodma = 1; | ||
348 | hwif->drives[0].autodma = hwif->drives[1].autodma = hwif->autodma; | ||
349 | #if PDC202_DEBUG_CABLE | ||
350 | printk(KERN_DEBUG "%s: %s-pin cable\n", | ||
351 | hwif->name, hwif->udma_four ? "80" : "40"); | ||
352 | #endif /* PDC202_DEBUG_CABLE */ | ||
353 | } | ||
354 | |||
355 | static int __devinit init_setup_pdcnew(struct pci_dev *dev, ide_pci_device_t *d) | ||
356 | { | ||
357 | return ide_setup_pci_device(dev, d); | ||
358 | } | ||
359 | |||
360 | static int __devinit init_setup_pdc20270(struct pci_dev *dev, | ||
361 | ide_pci_device_t *d) | ||
362 | { | ||
363 | struct pci_dev *findev = NULL; | ||
364 | |||
365 | if ((dev->bus->self && | ||
366 | dev->bus->self->vendor == PCI_VENDOR_ID_DEC) && | ||
367 | (dev->bus->self->device == PCI_DEVICE_ID_DEC_21150)) { | ||
368 | if (PCI_SLOT(dev->devfn) & 2) | ||
369 | return -ENODEV; | ||
370 | d->extra = 0; | ||
371 | while ((findev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, findev)) != NULL) { | ||
372 | if ((findev->vendor == dev->vendor) && | ||
373 | (findev->device == dev->device) && | ||
374 | (PCI_SLOT(findev->devfn) & 2)) { | ||
375 | if (findev->irq != dev->irq) { | ||
376 | findev->irq = dev->irq; | ||
377 | } | ||
378 | return ide_setup_pci_devices(dev, findev, d); | ||
379 | } | ||
380 | } | ||
381 | } | ||
382 | return ide_setup_pci_device(dev, d); | ||
383 | } | ||
384 | |||
385 | static int __devinit init_setup_pdc20276(struct pci_dev *dev, | ||
386 | ide_pci_device_t *d) | ||
387 | { | ||
388 | if ((dev->bus->self) && | ||
389 | (dev->bus->self->vendor == PCI_VENDOR_ID_INTEL) && | ||
390 | ((dev->bus->self->device == PCI_DEVICE_ID_INTEL_I960) || | ||
391 | (dev->bus->self->device == PCI_DEVICE_ID_INTEL_I960RM))) { | ||
392 | printk(KERN_INFO "ide: Skipping Promise PDC20276 " | ||
393 | "attached to I2O RAID controller.\n"); | ||
394 | return -ENODEV; | ||
395 | } | ||
396 | return ide_setup_pci_device(dev, d); | ||
397 | } | ||
398 | |||
399 | static ide_pci_device_t pdcnew_chipsets[] __devinitdata = { | ||
400 | { /* 0 */ | ||
401 | .name = "PDC20268", | ||
402 | .init_setup = init_setup_pdcnew, | ||
403 | .init_chipset = init_chipset_pdcnew, | ||
404 | .init_hwif = init_hwif_pdc202new, | ||
405 | .channels = 2, | ||
406 | .autodma = AUTODMA, | ||
407 | .bootable = OFF_BOARD, | ||
408 | },{ /* 1 */ | ||
409 | .name = "PDC20269", | ||
410 | .init_setup = init_setup_pdcnew, | ||
411 | .init_chipset = init_chipset_pdcnew, | ||
412 | .init_hwif = init_hwif_pdc202new, | ||
413 | .channels = 2, | ||
414 | .autodma = AUTODMA, | ||
415 | .bootable = OFF_BOARD, | ||
416 | },{ /* 2 */ | ||
417 | .name = "PDC20270", | ||
418 | .init_setup = init_setup_pdc20270, | ||
419 | .init_chipset = init_chipset_pdcnew, | ||
420 | .init_hwif = init_hwif_pdc202new, | ||
421 | .channels = 2, | ||
422 | .autodma = AUTODMA, | ||
423 | #ifndef CONFIG_PDC202XX_FORCE | ||
424 | .enablebits = {{0x50,0x02,0x02}, {0x50,0x04,0x04}}, | ||
425 | #endif | ||
426 | .bootable = OFF_BOARD, | ||
427 | },{ /* 3 */ | ||
428 | .name = "PDC20271", | ||
429 | .init_setup = init_setup_pdcnew, | ||
430 | .init_chipset = init_chipset_pdcnew, | ||
431 | .init_hwif = init_hwif_pdc202new, | ||
432 | .channels = 2, | ||
433 | .autodma = AUTODMA, | ||
434 | .bootable = OFF_BOARD, | ||
435 | },{ /* 4 */ | ||
436 | .name = "PDC20275", | ||
437 | .init_setup = init_setup_pdcnew, | ||
438 | .init_chipset = init_chipset_pdcnew, | ||
439 | .init_hwif = init_hwif_pdc202new, | ||
440 | .channels = 2, | ||
441 | .autodma = AUTODMA, | ||
442 | .bootable = OFF_BOARD, | ||
443 | },{ /* 5 */ | ||
444 | .name = "PDC20276", | ||
445 | .init_setup = init_setup_pdc20276, | ||
446 | .init_chipset = init_chipset_pdcnew, | ||
447 | .init_hwif = init_hwif_pdc202new, | ||
448 | .channels = 2, | ||
449 | .autodma = AUTODMA, | ||
450 | #ifndef CONFIG_PDC202XX_FORCE | ||
451 | .enablebits = {{0x50,0x02,0x02}, {0x50,0x04,0x04}}, | ||
452 | #endif | ||
453 | .bootable = OFF_BOARD, | ||
454 | },{ /* 6 */ | ||
455 | .name = "PDC20277", | ||
456 | .init_setup = init_setup_pdcnew, | ||
457 | .init_chipset = init_chipset_pdcnew, | ||
458 | .init_hwif = init_hwif_pdc202new, | ||
459 | .channels = 2, | ||
460 | .autodma = AUTODMA, | ||
461 | .bootable = OFF_BOARD, | ||
462 | } | ||
463 | }; | ||
464 | |||
465 | /** | ||
466 | * pdc202new_init_one - called when a pdc202xx is found | ||
467 | * @dev: the pdc202new device | ||
468 | * @id: the matching pci id | ||
469 | * | ||
470 | * Called when the PCI registration layer (or the IDE initialization) | ||
471 | * finds a device matching our IDE device tables. | ||
472 | */ | ||
473 | |||
474 | static int __devinit pdc202new_init_one(struct pci_dev *dev, const struct pci_device_id *id) | ||
475 | { | ||
476 | ide_pci_device_t *d = &pdcnew_chipsets[id->driver_data]; | ||
477 | |||
478 | return d->init_setup(dev, d); | ||
479 | } | ||
480 | |||
481 | static struct pci_device_id pdc202new_pci_tbl[] = { | ||
482 | { PCI_VENDOR_ID_PROMISE, PCI_DEVICE_ID_PROMISE_20268, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, | ||
483 | { PCI_VENDOR_ID_PROMISE, PCI_DEVICE_ID_PROMISE_20269, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1}, | ||
484 | { PCI_VENDOR_ID_PROMISE, PCI_DEVICE_ID_PROMISE_20270, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2}, | ||
485 | { PCI_VENDOR_ID_PROMISE, PCI_DEVICE_ID_PROMISE_20271, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3}, | ||
486 | { PCI_VENDOR_ID_PROMISE, PCI_DEVICE_ID_PROMISE_20275, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4}, | ||
487 | { PCI_VENDOR_ID_PROMISE, PCI_DEVICE_ID_PROMISE_20276, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5}, | ||
488 | { PCI_VENDOR_ID_PROMISE, PCI_DEVICE_ID_PROMISE_20277, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 6}, | ||
489 | { 0, }, | ||
490 | }; | ||
491 | MODULE_DEVICE_TABLE(pci, pdc202new_pci_tbl); | ||
492 | |||
493 | static struct pci_driver driver = { | ||
494 | .name = "Promise_IDE", | ||
495 | .id_table = pdc202new_pci_tbl, | ||
496 | .probe = pdc202new_init_one, | ||
497 | }; | ||
498 | |||
499 | static int pdc202new_ide_init(void) | ||
500 | { | ||
501 | return ide_pci_register_driver(&driver); | ||
502 | } | ||
503 | |||
504 | module_init(pdc202new_ide_init); | ||
505 | |||
506 | MODULE_AUTHOR("Andre Hedrick, Frank Tiernan"); | ||
507 | MODULE_DESCRIPTION("PCI driver module for Promise PDC20268 and higher"); | ||
508 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/ide/pci/pdc202xx_old.c b/drivers/ide/pci/pdc202xx_old.c new file mode 100644 index 000000000000..ad9d95817f95 --- /dev/null +++ b/drivers/ide/pci/pdc202xx_old.c | |||
@@ -0,0 +1,892 @@ | |||
1 | /* | ||
2 | * linux/drivers/ide/pci/pdc202xx_old.c Version 0.36 Sept 11, 2002 | ||
3 | * | ||
4 | * Copyright (C) 1998-2002 Andre Hedrick <andre@linux-ide.org> | ||
5 | * | ||
6 | * Promise Ultra33 cards with BIOS v1.20 through 1.28 will need this | ||
7 | * compiled into the kernel if you have more than one card installed. | ||
8 | * Note that BIOS v1.29 is reported to fix the problem. Since this is | ||
9 | * safe chipset tuning, including this support is harmless | ||
10 | * | ||
11 | * Promise Ultra66 cards with BIOS v1.11 this | ||
12 | * compiled into the kernel if you have more than one card installed. | ||
13 | * | ||
14 | * Promise Ultra100 cards. | ||
15 | * | ||
16 | * The latest chipset code will support the following :: | ||
17 | * Three Ultra33 controllers and 12 drives. | ||
18 | * 8 are UDMA supported and 4 are limited to DMA mode 2 multi-word. | ||
19 | * The 8/4 ratio is a BIOS code limit by promise. | ||
20 | * | ||
21 | * UNLESS you enable "CONFIG_PDC202XX_BURST" | ||
22 | * | ||
23 | */ | ||
24 | |||
25 | /* | ||
26 | * Portions Copyright (C) 1999 Promise Technology, Inc. | ||
27 | * Author: Frank Tiernan (frankt@promise.com) | ||
28 | * Released under terms of General Public License | ||
29 | */ | ||
30 | |||
31 | #include <linux/config.h> | ||
32 | #include <linux/types.h> | ||
33 | #include <linux/module.h> | ||
34 | #include <linux/kernel.h> | ||
35 | #include <linux/delay.h> | ||
36 | #include <linux/timer.h> | ||
37 | #include <linux/mm.h> | ||
38 | #include <linux/ioport.h> | ||
39 | #include <linux/blkdev.h> | ||
40 | #include <linux/hdreg.h> | ||
41 | #include <linux/interrupt.h> | ||
42 | #include <linux/pci.h> | ||
43 | #include <linux/init.h> | ||
44 | #include <linux/ide.h> | ||
45 | |||
46 | #include <asm/io.h> | ||
47 | #include <asm/irq.h> | ||
48 | |||
49 | #define PDC202_DEBUG_CABLE 0 | ||
50 | #define PDC202XX_DEBUG_DRIVE_INFO 0 | ||
51 | |||
52 | static const char *pdc_quirk_drives[] = { | ||
53 | "QUANTUM FIREBALLlct08 08", | ||
54 | "QUANTUM FIREBALLP KA6.4", | ||
55 | "QUANTUM FIREBALLP KA9.1", | ||
56 | "QUANTUM FIREBALLP LM20.4", | ||
57 | "QUANTUM FIREBALLP KX13.6", | ||
58 | "QUANTUM FIREBALLP KX20.5", | ||
59 | "QUANTUM FIREBALLP KX27.3", | ||
60 | "QUANTUM FIREBALLP LM20.5", | ||
61 | NULL | ||
62 | }; | ||
63 | |||
64 | /* A Register */ | ||
65 | #define SYNC_ERRDY_EN 0xC0 | ||
66 | |||
67 | #define SYNC_IN 0x80 /* control bit, different for master vs. slave drives */ | ||
68 | #define ERRDY_EN 0x40 /* control bit, different for master vs. slave drives */ | ||
69 | #define IORDY_EN 0x20 /* PIO: IOREADY */ | ||
70 | #define PREFETCH_EN 0x10 /* PIO: PREFETCH */ | ||
71 | |||
72 | #define PA3 0x08 /* PIO"A" timing */ | ||
73 | #define PA2 0x04 /* PIO"A" timing */ | ||
74 | #define PA1 0x02 /* PIO"A" timing */ | ||
75 | #define PA0 0x01 /* PIO"A" timing */ | ||
76 | |||
77 | /* B Register */ | ||
78 | |||
79 | #define MB2 0x80 /* DMA"B" timing */ | ||
80 | #define MB1 0x40 /* DMA"B" timing */ | ||
81 | #define MB0 0x20 /* DMA"B" timing */ | ||
82 | |||
83 | #define PB4 0x10 /* PIO_FORCE 1:0 */ | ||
84 | |||
85 | #define PB3 0x08 /* PIO"B" timing */ /* PIO flow Control mode */ | ||
86 | #define PB2 0x04 /* PIO"B" timing */ /* PIO 4 */ | ||
87 | #define PB1 0x02 /* PIO"B" timing */ /* PIO 3 half */ | ||
88 | #define PB0 0x01 /* PIO"B" timing */ /* PIO 3 other half */ | ||
89 | |||
90 | /* C Register */ | ||
91 | #define IORDYp_NO_SPEED 0x4F | ||
92 | #define SPEED_DIS 0x0F | ||
93 | |||
94 | #define DMARQp 0x80 | ||
95 | #define IORDYp 0x40 | ||
96 | #define DMAR_EN 0x20 | ||
97 | #define DMAW_EN 0x10 | ||
98 | |||
99 | #define MC3 0x08 /* DMA"C" timing */ | ||
100 | #define MC2 0x04 /* DMA"C" timing */ | ||
101 | #define MC1 0x02 /* DMA"C" timing */ | ||
102 | #define MC0 0x01 /* DMA"C" timing */ | ||
103 | |||
104 | #if 0 | ||
105 | unsigned long bibma = pci_resource_start(dev, 4); | ||
106 | u8 hi = 0, lo = 0; | ||
107 | |||
108 | u8 sc1c = inb_p((u16)bibma + 0x1c); | ||
109 | u8 sc1e = inb_p((u16)bibma + 0x1e); | ||
110 | u8 sc1f = inb_p((u16)bibma + 0x1f); | ||
111 | |||
112 | p += sprintf(p, "Host Mode : %s\n", | ||
113 | (sc1f & 0x08) ? "Tri-Stated" : "Normal"); | ||
114 | p += sprintf(p, "Bus Clocking : %s\n", | ||
115 | ((sc1f & 0xC0) == 0xC0) ? "100 External" : | ||
116 | ((sc1f & 0x80) == 0x80) ? "66 External" : | ||
117 | ((sc1f & 0x40) == 0x40) ? "33 External" : "33 PCI Internal"); | ||
118 | p += sprintf(p, "IO pad select : %s mA\n", | ||
119 | ((sc1c & 0x03) == 0x03) ? "10" : | ||
120 | ((sc1c & 0x02) == 0x02) ? "8" : | ||
121 | ((sc1c & 0x01) == 0x01) ? "6" : | ||
122 | ((sc1c & 0x00) == 0x00) ? "4" : "??"); | ||
123 | hi = sc1e >> 4; | ||
124 | lo = sc1e & 0xf; | ||
125 | p += sprintf(p, "Status Polling Period : %d\n", hi); | ||
126 | p += sprintf(p, "Interrupt Check Status Polling Delay : %d\n", lo); | ||
127 | #endif | ||
128 | |||
129 | static u8 pdc202xx_ratemask (ide_drive_t *drive) | ||
130 | { | ||
131 | u8 mode; | ||
132 | |||
133 | switch(HWIF(drive)->pci_dev->device) { | ||
134 | case PCI_DEVICE_ID_PROMISE_20267: | ||
135 | case PCI_DEVICE_ID_PROMISE_20265: | ||
136 | mode = 3; | ||
137 | break; | ||
138 | case PCI_DEVICE_ID_PROMISE_20263: | ||
139 | case PCI_DEVICE_ID_PROMISE_20262: | ||
140 | mode = 2; | ||
141 | break; | ||
142 | case PCI_DEVICE_ID_PROMISE_20246: | ||
143 | return 1; | ||
144 | default: | ||
145 | return 0; | ||
146 | } | ||
147 | if (!eighty_ninty_three(drive)) | ||
148 | mode = min(mode, (u8)1); | ||
149 | return mode; | ||
150 | } | ||
151 | |||
152 | static int check_in_drive_lists (ide_drive_t *drive, const char **list) | ||
153 | { | ||
154 | struct hd_driveid *id = drive->id; | ||
155 | |||
156 | if (pdc_quirk_drives == list) { | ||
157 | while (*list) { | ||
158 | if (strstr(id->model, *list++)) { | ||
159 | return 2; | ||
160 | } | ||
161 | } | ||
162 | } else { | ||
163 | while (*list) { | ||
164 | if (!strcmp(*list++,id->model)) { | ||
165 | return 1; | ||
166 | } | ||
167 | } | ||
168 | } | ||
169 | return 0; | ||
170 | } | ||
171 | |||
172 | static int pdc202xx_tune_chipset (ide_drive_t *drive, u8 xferspeed) | ||
173 | { | ||
174 | ide_hwif_t *hwif = HWIF(drive); | ||
175 | struct pci_dev *dev = hwif->pci_dev; | ||
176 | u8 drive_pci = 0x60 + (drive->dn << 2); | ||
177 | u8 speed = ide_rate_filter(pdc202xx_ratemask(drive), xferspeed); | ||
178 | |||
179 | u32 drive_conf; | ||
180 | u8 AP, BP, CP, DP; | ||
181 | u8 TA = 0, TB = 0, TC = 0; | ||
182 | |||
183 | if ((drive->media != ide_disk) && (speed < XFER_SW_DMA_0)) | ||
184 | return -1; | ||
185 | |||
186 | pci_read_config_dword(dev, drive_pci, &drive_conf); | ||
187 | pci_read_config_byte(dev, (drive_pci), &AP); | ||
188 | pci_read_config_byte(dev, (drive_pci)|0x01, &BP); | ||
189 | pci_read_config_byte(dev, (drive_pci)|0x02, &CP); | ||
190 | pci_read_config_byte(dev, (drive_pci)|0x03, &DP); | ||
191 | |||
192 | if (speed < XFER_SW_DMA_0) { | ||
193 | if ((AP & 0x0F) || (BP & 0x07)) { | ||
194 | /* clear PIO modes of lower 8421 bits of A Register */ | ||
195 | pci_write_config_byte(dev, (drive_pci), AP &~0x0F); | ||
196 | pci_read_config_byte(dev, (drive_pci), &AP); | ||
197 | |||
198 | /* clear PIO modes of lower 421 bits of B Register */ | ||
199 | pci_write_config_byte(dev, (drive_pci)|0x01, BP &~0x07); | ||
200 | pci_read_config_byte(dev, (drive_pci)|0x01, &BP); | ||
201 | |||
202 | pci_read_config_byte(dev, (drive_pci), &AP); | ||
203 | pci_read_config_byte(dev, (drive_pci)|0x01, &BP); | ||
204 | } | ||
205 | } else { | ||
206 | if ((BP & 0xF0) && (CP & 0x0F)) { | ||
207 | /* clear DMA modes of upper 842 bits of B Register */ | ||
208 | /* clear PIO forced mode upper 1 bit of B Register */ | ||
209 | pci_write_config_byte(dev, (drive_pci)|0x01, BP &~0xF0); | ||
210 | pci_read_config_byte(dev, (drive_pci)|0x01, &BP); | ||
211 | |||
212 | /* clear DMA modes of lower 8421 bits of C Register */ | ||
213 | pci_write_config_byte(dev, (drive_pci)|0x02, CP &~0x0F); | ||
214 | pci_read_config_byte(dev, (drive_pci)|0x02, &CP); | ||
215 | } | ||
216 | } | ||
217 | |||
218 | pci_read_config_byte(dev, (drive_pci), &AP); | ||
219 | pci_read_config_byte(dev, (drive_pci)|0x01, &BP); | ||
220 | pci_read_config_byte(dev, (drive_pci)|0x02, &CP); | ||
221 | |||
222 | switch(speed) { | ||
223 | case XFER_UDMA_6: speed = XFER_UDMA_5; | ||
224 | case XFER_UDMA_5: | ||
225 | case XFER_UDMA_4: TB = 0x20; TC = 0x01; break; | ||
226 | case XFER_UDMA_2: TB = 0x20; TC = 0x01; break; | ||
227 | case XFER_UDMA_3: | ||
228 | case XFER_UDMA_1: TB = 0x40; TC = 0x02; break; | ||
229 | case XFER_UDMA_0: | ||
230 | case XFER_MW_DMA_2: TB = 0x60; TC = 0x03; break; | ||
231 | case XFER_MW_DMA_1: TB = 0x60; TC = 0x04; break; | ||
232 | case XFER_MW_DMA_0: | ||
233 | case XFER_SW_DMA_2: TB = 0x60; TC = 0x05; break; | ||
234 | case XFER_SW_DMA_1: TB = 0x80; TC = 0x06; break; | ||
235 | case XFER_SW_DMA_0: TB = 0xC0; TC = 0x0B; break; | ||
236 | case XFER_PIO_4: TA = 0x01; TB = 0x04; break; | ||
237 | case XFER_PIO_3: TA = 0x02; TB = 0x06; break; | ||
238 | case XFER_PIO_2: TA = 0x03; TB = 0x08; break; | ||
239 | case XFER_PIO_1: TA = 0x05; TB = 0x0C; break; | ||
240 | case XFER_PIO_0: | ||
241 | default: TA = 0x09; TB = 0x13; break; | ||
242 | } | ||
243 | |||
244 | if (speed < XFER_SW_DMA_0) { | ||
245 | pci_write_config_byte(dev, (drive_pci), AP|TA); | ||
246 | pci_write_config_byte(dev, (drive_pci)|0x01, BP|TB); | ||
247 | } else { | ||
248 | pci_write_config_byte(dev, (drive_pci)|0x01, BP|TB); | ||
249 | pci_write_config_byte(dev, (drive_pci)|0x02, CP|TC); | ||
250 | } | ||
251 | |||
252 | #if PDC202XX_DEBUG_DRIVE_INFO | ||
253 | printk(KERN_DEBUG "%s: %s drive%d 0x%08x ", | ||
254 | drive->name, ide_xfer_verbose(speed), | ||
255 | drive->dn, drive_conf); | ||
256 | pci_read_config_dword(dev, drive_pci, &drive_conf); | ||
257 | printk("0x%08x\n", drive_conf); | ||
258 | #endif /* PDC202XX_DEBUG_DRIVE_INFO */ | ||
259 | |||
260 | return (ide_config_drive_speed(drive, speed)); | ||
261 | } | ||
262 | |||
263 | |||
264 | /* 0 1 2 3 4 5 6 7 8 | ||
265 | * 960, 480, 390, 300, 240, 180, 120, 90, 60 | ||
266 | * 180, 150, 120, 90, 60 | ||
267 | * DMA_Speed | ||
268 | * 180, 120, 90, 90, 90, 60, 30 | ||
269 | * 11, 5, 4, 3, 2, 1, 0 | ||
270 | */ | ||
271 | static void config_chipset_for_pio (ide_drive_t *drive, u8 pio) | ||
272 | { | ||
273 | u8 speed = 0; | ||
274 | |||
275 | if (pio == 5) pio = 4; | ||
276 | speed = XFER_PIO_0 + ide_get_best_pio_mode(drive, 255, pio, NULL); | ||
277 | |||
278 | pdc202xx_tune_chipset(drive, speed); | ||
279 | } | ||
280 | |||
281 | static u8 pdc202xx_old_cable_detect (ide_hwif_t *hwif) | ||
282 | { | ||
283 | u16 CIS = 0, mask = (hwif->channel) ? (1<<11) : (1<<10); | ||
284 | pci_read_config_word(hwif->pci_dev, 0x50, &CIS); | ||
285 | return (CIS & mask) ? 1 : 0; | ||
286 | } | ||
287 | |||
288 | /* | ||
289 | * Set the control register to use the 66MHz system | ||
290 | * clock for UDMA 3/4/5 mode operation when necessary. | ||
291 | * | ||
292 | * It may also be possible to leave the 66MHz clock on | ||
293 | * and readjust the timing parameters. | ||
294 | */ | ||
295 | static void pdc_old_enable_66MHz_clock(ide_hwif_t *hwif) | ||
296 | { | ||
297 | unsigned long clock_reg = hwif->dma_master + 0x11; | ||
298 | u8 clock = hwif->INB(clock_reg); | ||
299 | |||
300 | hwif->OUTB(clock | (hwif->channel ? 0x08 : 0x02), clock_reg); | ||
301 | } | ||
302 | |||
303 | static void pdc_old_disable_66MHz_clock(ide_hwif_t *hwif) | ||
304 | { | ||
305 | unsigned long clock_reg = hwif->dma_master + 0x11; | ||
306 | u8 clock = hwif->INB(clock_reg); | ||
307 | |||
308 | hwif->OUTB(clock & ~(hwif->channel ? 0x08 : 0x02), clock_reg); | ||
309 | } | ||
310 | |||
311 | static int config_chipset_for_dma (ide_drive_t *drive) | ||
312 | { | ||
313 | struct hd_driveid *id = drive->id; | ||
314 | ide_hwif_t *hwif = HWIF(drive); | ||
315 | struct pci_dev *dev = hwif->pci_dev; | ||
316 | u32 drive_conf = 0; | ||
317 | u8 drive_pci = 0x60 + (drive->dn << 2); | ||
318 | u8 test1 = 0, test2 = 0, speed = -1; | ||
319 | u8 AP = 0, cable = 0; | ||
320 | |||
321 | u8 ultra_66 = ((id->dma_ultra & 0x0010) || | ||
322 | (id->dma_ultra & 0x0008)) ? 1 : 0; | ||
323 | |||
324 | if (dev->device != PCI_DEVICE_ID_PROMISE_20246) | ||
325 | cable = pdc202xx_old_cable_detect(hwif); | ||
326 | else | ||
327 | ultra_66 = 0; | ||
328 | |||
329 | if (ultra_66 && cable) { | ||
330 | printk(KERN_WARNING "Warning: %s channel requires an 80-pin cable for operation.\n", hwif->channel ? "Secondary":"Primary"); | ||
331 | printk(KERN_WARNING "%s reduced to Ultra33 mode.\n", drive->name); | ||
332 | } | ||
333 | |||
334 | if (dev->device != PCI_DEVICE_ID_PROMISE_20246) | ||
335 | pdc_old_disable_66MHz_clock(drive->hwif); | ||
336 | |||
337 | drive_pci = 0x60 + (drive->dn << 2); | ||
338 | pci_read_config_dword(dev, drive_pci, &drive_conf); | ||
339 | if ((drive_conf != 0x004ff304) && (drive_conf != 0x004ff3c4)) | ||
340 | goto chipset_is_set; | ||
341 | |||
342 | pci_read_config_byte(dev, drive_pci, &test1); | ||
343 | if (!(test1 & SYNC_ERRDY_EN)) { | ||
344 | if (drive->select.b.unit & 0x01) { | ||
345 | pci_read_config_byte(dev, drive_pci - 4, &test2); | ||
346 | if ((test2 & SYNC_ERRDY_EN) && | ||
347 | !(test1 & SYNC_ERRDY_EN)) { | ||
348 | pci_write_config_byte(dev, drive_pci, | ||
349 | test1|SYNC_ERRDY_EN); | ||
350 | } | ||
351 | } else { | ||
352 | pci_write_config_byte(dev, drive_pci, | ||
353 | test1|SYNC_ERRDY_EN); | ||
354 | } | ||
355 | } | ||
356 | |||
357 | chipset_is_set: | ||
358 | |||
359 | if (drive->media == ide_disk) { | ||
360 | pci_read_config_byte(dev, (drive_pci), &AP); | ||
361 | if (id->capability & 4) /* IORDY_EN */ | ||
362 | pci_write_config_byte(dev, (drive_pci), AP|IORDY_EN); | ||
363 | pci_read_config_byte(dev, (drive_pci), &AP); | ||
364 | if (drive->media == ide_disk) /* PREFETCH_EN */ | ||
365 | pci_write_config_byte(dev, (drive_pci), AP|PREFETCH_EN); | ||
366 | } | ||
367 | |||
368 | speed = ide_dma_speed(drive, pdc202xx_ratemask(drive)); | ||
369 | |||
370 | if (!(speed)) { | ||
371 | /* restore original pci-config space */ | ||
372 | pci_write_config_dword(dev, drive_pci, drive_conf); | ||
373 | hwif->tuneproc(drive, 5); | ||
374 | return 0; | ||
375 | } | ||
376 | |||
377 | (void) hwif->speedproc(drive, speed); | ||
378 | return ide_dma_enable(drive); | ||
379 | } | ||
380 | |||
381 | static int pdc202xx_config_drive_xfer_rate (ide_drive_t *drive) | ||
382 | { | ||
383 | ide_hwif_t *hwif = HWIF(drive); | ||
384 | struct hd_driveid *id = drive->id; | ||
385 | |||
386 | drive->init_speed = 0; | ||
387 | |||
388 | if (id && (id->capability & 1) && drive->autodma) { | ||
389 | |||
390 | if (ide_use_dma(drive)) { | ||
391 | if (config_chipset_for_dma(drive)) | ||
392 | return hwif->ide_dma_on(drive); | ||
393 | } | ||
394 | |||
395 | goto fast_ata_pio; | ||
396 | |||
397 | } else if ((id->capability & 8) || (id->field_valid & 2)) { | ||
398 | fast_ata_pio: | ||
399 | hwif->tuneproc(drive, 5); | ||
400 | return hwif->ide_dma_off_quietly(drive); | ||
401 | } | ||
402 | /* IORDY not supported */ | ||
403 | return 0; | ||
404 | } | ||
405 | |||
406 | static int pdc202xx_quirkproc (ide_drive_t *drive) | ||
407 | { | ||
408 | return ((int) check_in_drive_lists(drive, pdc_quirk_drives)); | ||
409 | } | ||
410 | |||
411 | static void pdc202xx_old_ide_dma_start(ide_drive_t *drive) | ||
412 | { | ||
413 | if (drive->current_speed > XFER_UDMA_2) | ||
414 | pdc_old_enable_66MHz_clock(drive->hwif); | ||
415 | if (drive->addressing == 1) { | ||
416 | struct request *rq = HWGROUP(drive)->rq; | ||
417 | ide_hwif_t *hwif = HWIF(drive); | ||
418 | // struct pci_dev *dev = hwif->pci_dev; | ||
419 | // unsgned long high_16 = pci_resource_start(dev, 4); | ||
420 | unsigned long high_16 = hwif->dma_master; | ||
421 | unsigned long atapi_reg = high_16 + (hwif->channel ? 0x24 : 0x20); | ||
422 | u32 word_count = 0; | ||
423 | u8 clock = hwif->INB(high_16 + 0x11); | ||
424 | |||
425 | hwif->OUTB(clock|(hwif->channel ? 0x08 : 0x02), high_16+0x11); | ||
426 | word_count = (rq->nr_sectors << 8); | ||
427 | word_count = (rq_data_dir(rq) == READ) ? | ||
428 | word_count | 0x05000000 : | ||
429 | word_count | 0x06000000; | ||
430 | hwif->OUTL(word_count, atapi_reg); | ||
431 | } | ||
432 | ide_dma_start(drive); | ||
433 | } | ||
434 | |||
435 | static int pdc202xx_old_ide_dma_end(ide_drive_t *drive) | ||
436 | { | ||
437 | if (drive->addressing == 1) { | ||
438 | ide_hwif_t *hwif = HWIF(drive); | ||
439 | // unsigned long high_16 = pci_resource_start(hwif->pci_dev, 4); | ||
440 | unsigned long high_16 = hwif->dma_master; | ||
441 | unsigned long atapi_reg = high_16 + (hwif->channel ? 0x24 : 0x20); | ||
442 | u8 clock = 0; | ||
443 | |||
444 | hwif->OUTL(0, atapi_reg); /* zero out extra */ | ||
445 | clock = hwif->INB(high_16 + 0x11); | ||
446 | hwif->OUTB(clock & ~(hwif->channel ? 0x08:0x02), high_16+0x11); | ||
447 | } | ||
448 | if (drive->current_speed > XFER_UDMA_2) | ||
449 | pdc_old_disable_66MHz_clock(drive->hwif); | ||
450 | return __ide_dma_end(drive); | ||
451 | } | ||
452 | |||
453 | static int pdc202xx_old_ide_dma_test_irq(ide_drive_t *drive) | ||
454 | { | ||
455 | ide_hwif_t *hwif = HWIF(drive); | ||
456 | // struct pci_dev *dev = hwif->pci_dev; | ||
457 | // unsigned long high_16 = pci_resource_start(dev, 4); | ||
458 | unsigned long high_16 = hwif->dma_master; | ||
459 | u8 dma_stat = hwif->INB(hwif->dma_status); | ||
460 | u8 sc1d = hwif->INB((high_16 + 0x001d)); | ||
461 | |||
462 | if (hwif->channel) { | ||
463 | /* bit7: Error, bit6: Interrupting, bit5: FIFO Full, bit4: FIFO Empty */ | ||
464 | if ((sc1d & 0x50) == 0x50) | ||
465 | goto somebody_else; | ||
466 | else if ((sc1d & 0x40) == 0x40) | ||
467 | return (dma_stat & 4) == 4; | ||
468 | } else { | ||
469 | /* bit3: Error, bit2: Interrupting, bit1: FIFO Full, bit0: FIFO Empty */ | ||
470 | if ((sc1d & 0x05) == 0x05) | ||
471 | goto somebody_else; | ||
472 | else if ((sc1d & 0x04) == 0x04) | ||
473 | return (dma_stat & 4) == 4; | ||
474 | } | ||
475 | somebody_else: | ||
476 | return (dma_stat & 4) == 4; /* return 1 if INTR asserted */ | ||
477 | } | ||
478 | |||
479 | static int pdc202xx_ide_dma_lostirq(ide_drive_t *drive) | ||
480 | { | ||
481 | if (HWIF(drive)->resetproc != NULL) | ||
482 | HWIF(drive)->resetproc(drive); | ||
483 | return __ide_dma_lostirq(drive); | ||
484 | } | ||
485 | |||
486 | static int pdc202xx_ide_dma_timeout(ide_drive_t *drive) | ||
487 | { | ||
488 | if (HWIF(drive)->resetproc != NULL) | ||
489 | HWIF(drive)->resetproc(drive); | ||
490 | return __ide_dma_timeout(drive); | ||
491 | } | ||
492 | |||
493 | static void pdc202xx_reset_host (ide_hwif_t *hwif) | ||
494 | { | ||
495 | #ifdef CONFIG_BLK_DEV_IDEDMA | ||
496 | // unsigned long high_16 = hwif->dma_base - (8*(hwif->channel)); | ||
497 | unsigned long high_16 = hwif->dma_master; | ||
498 | #else /* !CONFIG_BLK_DEV_IDEDMA */ | ||
499 | unsigned long high_16 = pci_resource_start(hwif->pci_dev, 4); | ||
500 | #endif /* CONFIG_BLK_DEV_IDEDMA */ | ||
501 | u8 udma_speed_flag = hwif->INB(high_16|0x001f); | ||
502 | |||
503 | hwif->OUTB((udma_speed_flag | 0x10), (high_16|0x001f)); | ||
504 | mdelay(100); | ||
505 | hwif->OUTB((udma_speed_flag & ~0x10), (high_16|0x001f)); | ||
506 | mdelay(2000); /* 2 seconds ?! */ | ||
507 | |||
508 | printk(KERN_WARNING "PDC202XX: %s channel reset.\n", | ||
509 | hwif->channel ? "Secondary" : "Primary"); | ||
510 | } | ||
511 | |||
512 | static void pdc202xx_reset (ide_drive_t *drive) | ||
513 | { | ||
514 | ide_hwif_t *hwif = HWIF(drive); | ||
515 | ide_hwif_t *mate = hwif->mate; | ||
516 | |||
517 | pdc202xx_reset_host(hwif); | ||
518 | pdc202xx_reset_host(mate); | ||
519 | #if 0 | ||
520 | /* | ||
521 | * FIXME: Have to kick all the drives again :-/ | ||
522 | * What a pain in the ACE! | ||
523 | */ | ||
524 | if (hwif->present) { | ||
525 | u16 hunit = 0; | ||
526 | for (hunit = 0; hunit < MAX_DRIVES; ++hunit) { | ||
527 | ide_drive_t *hdrive = &hwif->drives[hunit]; | ||
528 | if (hdrive->present) { | ||
529 | if (hwif->ide_dma_check) | ||
530 | hwif->ide_dma_check(hdrive); | ||
531 | else | ||
532 | hwif->tuneproc(hdrive, 5); | ||
533 | } | ||
534 | } | ||
535 | } | ||
536 | if (mate->present) { | ||
537 | u16 munit = 0; | ||
538 | for (munit = 0; munit < MAX_DRIVES; ++munit) { | ||
539 | ide_drive_t *mdrive = &mate->drives[munit]; | ||
540 | if (mdrive->present) { | ||
541 | if (mate->ide_dma_check) | ||
542 | mate->ide_dma_check(mdrive); | ||
543 | else | ||
544 | mate->tuneproc(mdrive, 5); | ||
545 | } | ||
546 | } | ||
547 | } | ||
548 | #else | ||
549 | hwif->tuneproc(drive, 5); | ||
550 | #endif | ||
551 | } | ||
552 | |||
553 | /* | ||
554 | * Since SUN Cobalt is attempting to do this operation, I should disclose | ||
555 | * this has been a long time ago Thu Jul 27 16:40:57 2000 was the patch date | ||
556 | * HOTSWAP ATA Infrastructure. | ||
557 | */ | ||
558 | static int pdc202xx_tristate (ide_drive_t * drive, int state) | ||
559 | { | ||
560 | ide_hwif_t *hwif = HWIF(drive); | ||
561 | // unsigned long high_16 = hwif->dma_base - (8*(hwif->channel)); | ||
562 | unsigned long high_16 = hwif->dma_master; | ||
563 | u8 sc1f = hwif->INB(high_16|0x001f); | ||
564 | |||
565 | if (!hwif) | ||
566 | return -EINVAL; | ||
567 | |||
568 | // hwif->bus_state = state; | ||
569 | |||
570 | if (state) { | ||
571 | hwif->OUTB(sc1f | 0x08, (high_16|0x001f)); | ||
572 | } else { | ||
573 | hwif->OUTB(sc1f & ~0x08, (high_16|0x001f)); | ||
574 | } | ||
575 | return 0; | ||
576 | } | ||
577 | |||
578 | static unsigned int __devinit init_chipset_pdc202xx(struct pci_dev *dev, const char *name) | ||
579 | { | ||
580 | if (dev->resource[PCI_ROM_RESOURCE].start) { | ||
581 | pci_write_config_dword(dev, PCI_ROM_ADDRESS, | ||
582 | dev->resource[PCI_ROM_RESOURCE].start | PCI_ROM_ADDRESS_ENABLE); | ||
583 | printk(KERN_INFO "%s: ROM enabled at 0x%08lx\n", | ||
584 | name, dev->resource[PCI_ROM_RESOURCE].start); | ||
585 | } | ||
586 | |||
587 | /* | ||
588 | * software reset - this is required because the bios | ||
589 | * will set UDMA timing on if the hdd supports it. The | ||
590 | * user may want to turn udma off. A bug in the pdc20262 | ||
591 | * is that it cannot handle a downgrade in timing from | ||
592 | * UDMA to DMA. Disk accesses after issuing a set | ||
593 | * feature command will result in errors. A software | ||
594 | * reset leaves the timing registers intact, | ||
595 | * but resets the drives. | ||
596 | */ | ||
597 | #if 0 | ||
598 | if ((dev->device == PCI_DEVICE_ID_PROMISE_20267) || | ||
599 | (dev->device == PCI_DEVICE_ID_PROMISE_20265) || | ||
600 | (dev->device == PCI_DEVICE_ID_PROMISE_20263) || | ||
601 | (dev->device == PCI_DEVICE_ID_PROMISE_20262)) { | ||
602 | unsigned long high_16 = pci_resource_start(dev, 4); | ||
603 | byte udma_speed_flag = inb(high_16 + 0x001f); | ||
604 | outb(udma_speed_flag | 0x10, high_16 + 0x001f); | ||
605 | mdelay(100); | ||
606 | outb(udma_speed_flag & ~0x10, high_16 + 0x001f); | ||
607 | mdelay(2000); /* 2 seconds ?! */ | ||
608 | } | ||
609 | |||
610 | #endif | ||
611 | return dev->irq; | ||
612 | } | ||
613 | |||
614 | static void __devinit init_hwif_pdc202xx(ide_hwif_t *hwif) | ||
615 | { | ||
616 | struct pci_dev *dev = hwif->pci_dev; | ||
617 | |||
618 | /* PDC20265 has problems with large LBA48 requests */ | ||
619 | if ((dev->device == PCI_DEVICE_ID_PROMISE_20267) || | ||
620 | (dev->device == PCI_DEVICE_ID_PROMISE_20265)) | ||
621 | hwif->rqsize = 256; | ||
622 | |||
623 | hwif->autodma = 0; | ||
624 | hwif->tuneproc = &config_chipset_for_pio; | ||
625 | hwif->quirkproc = &pdc202xx_quirkproc; | ||
626 | |||
627 | if (hwif->pci_dev->device != PCI_DEVICE_ID_PROMISE_20246) { | ||
628 | hwif->busproc = &pdc202xx_tristate; | ||
629 | hwif->resetproc = &pdc202xx_reset; | ||
630 | } | ||
631 | |||
632 | hwif->speedproc = &pdc202xx_tune_chipset; | ||
633 | |||
634 | hwif->drives[0].autotune = hwif->drives[1].autotune = 1; | ||
635 | |||
636 | hwif->ultra_mask = 0x3f; | ||
637 | hwif->mwdma_mask = 0x07; | ||
638 | hwif->swdma_mask = 0x07; | ||
639 | |||
640 | hwif->ide_dma_check = &pdc202xx_config_drive_xfer_rate; | ||
641 | hwif->ide_dma_lostirq = &pdc202xx_ide_dma_lostirq; | ||
642 | hwif->ide_dma_timeout = &pdc202xx_ide_dma_timeout; | ||
643 | |||
644 | if (hwif->pci_dev->device != PCI_DEVICE_ID_PROMISE_20246) { | ||
645 | if (!(hwif->udma_four)) | ||
646 | hwif->udma_four = (pdc202xx_old_cable_detect(hwif)) ? 0 : 1; | ||
647 | hwif->dma_start = &pdc202xx_old_ide_dma_start; | ||
648 | hwif->ide_dma_end = &pdc202xx_old_ide_dma_end; | ||
649 | } | ||
650 | hwif->ide_dma_test_irq = &pdc202xx_old_ide_dma_test_irq; | ||
651 | |||
652 | if (!noautodma) | ||
653 | hwif->autodma = 1; | ||
654 | hwif->drives[0].autodma = hwif->drives[1].autodma = hwif->autodma; | ||
655 | #if PDC202_DEBUG_CABLE | ||
656 | printk(KERN_DEBUG "%s: %s-pin cable\n", | ||
657 | hwif->name, hwif->udma_four ? "80" : "40"); | ||
658 | #endif /* PDC202_DEBUG_CABLE */ | ||
659 | } | ||
660 | |||
661 | static void __devinit init_dma_pdc202xx(ide_hwif_t *hwif, unsigned long dmabase) | ||
662 | { | ||
663 | u8 udma_speed_flag = 0, primary_mode = 0, secondary_mode = 0; | ||
664 | |||
665 | if (hwif->channel) { | ||
666 | ide_setup_dma(hwif, dmabase, 8); | ||
667 | return; | ||
668 | } | ||
669 | |||
670 | udma_speed_flag = hwif->INB((dmabase|0x1f)); | ||
671 | primary_mode = hwif->INB((dmabase|0x1a)); | ||
672 | secondary_mode = hwif->INB((dmabase|0x1b)); | ||
673 | printk(KERN_INFO "%s: (U)DMA Burst Bit %sABLED " \ | ||
674 | "Primary %s Mode " \ | ||
675 | "Secondary %s Mode.\n", hwif->cds->name, | ||
676 | (udma_speed_flag & 1) ? "EN" : "DIS", | ||
677 | (primary_mode & 1) ? "MASTER" : "PCI", | ||
678 | (secondary_mode & 1) ? "MASTER" : "PCI" ); | ||
679 | |||
680 | #ifdef CONFIG_PDC202XX_BURST | ||
681 | if (!(udma_speed_flag & 1)) { | ||
682 | printk(KERN_INFO "%s: FORCING BURST BIT 0x%02x->0x%02x ", | ||
683 | hwif->cds->name, udma_speed_flag, | ||
684 | (udma_speed_flag|1)); | ||
685 | hwif->OUTB(udma_speed_flag|1,(dmabase|0x1f)); | ||
686 | printk("%sACTIVE\n", | ||
687 | (hwif->INB(dmabase|0x1f)&1) ? "":"IN"); | ||
688 | } | ||
689 | #endif /* CONFIG_PDC202XX_BURST */ | ||
690 | #ifdef CONFIG_PDC202XX_MASTER | ||
691 | if (!(primary_mode & 1)) { | ||
692 | printk(KERN_INFO "%s: FORCING PRIMARY MODE BIT " | ||
693 | "0x%02x -> 0x%02x ", hwif->cds->name, | ||
694 | primary_mode, (primary_mode|1)); | ||
695 | hwif->OUTB(primary_mode|1, (dmabase|0x1a)); | ||
696 | printk("%s\n", | ||
697 | (hwif->INB((dmabase|0x1a)) & 1) ? "MASTER" : "PCI"); | ||
698 | } | ||
699 | |||
700 | if (!(secondary_mode & 1)) { | ||
701 | printk(KERN_INFO "%s: FORCING SECONDARY MODE BIT " | ||
702 | "0x%02x -> 0x%02x ", hwif->cds->name, | ||
703 | secondary_mode, (secondary_mode|1)); | ||
704 | hwif->OUTB(secondary_mode|1, (dmabase|0x1b)); | ||
705 | printk("%s\n", | ||
706 | (hwif->INB((dmabase|0x1b)) & 1) ? "MASTER" : "PCI"); | ||
707 | } | ||
708 | #endif /* CONFIG_PDC202XX_MASTER */ | ||
709 | |||
710 | ide_setup_dma(hwif, dmabase, 8); | ||
711 | } | ||
712 | |||
713 | static int __devinit init_setup_pdc202ata4(struct pci_dev *dev, | ||
714 | ide_pci_device_t *d) | ||
715 | { | ||
716 | if ((dev->class >> 8) != PCI_CLASS_STORAGE_IDE) { | ||
717 | u8 irq = 0, irq2 = 0; | ||
718 | pci_read_config_byte(dev, PCI_INTERRUPT_LINE, &irq); | ||
719 | /* 0xbc */ | ||
720 | pci_read_config_byte(dev, (PCI_INTERRUPT_LINE)|0x80, &irq2); | ||
721 | if (irq != irq2) { | ||
722 | pci_write_config_byte(dev, | ||
723 | (PCI_INTERRUPT_LINE)|0x80, irq); /* 0xbc */ | ||
724 | printk(KERN_INFO "%s: pci-config space interrupt " | ||
725 | "mirror fixed.\n", d->name); | ||
726 | } | ||
727 | } | ||
728 | |||
729 | #if 0 | ||
730 | if (dev->device == PCI_DEVICE_ID_PROMISE_20262) | ||
731 | if (e->reg && (pci_read_config_byte(dev, e->reg, &tmp) || | ||
732 | (tmp & e->mask) != e->val)) | ||
733 | |||
734 | if (d->enablebits[0].reg != d->enablebits[1].reg) { | ||
735 | d->enablebits[0].reg = d->enablebits[1].reg; | ||
736 | d->enablebits[0].mask = d->enablebits[1].mask; | ||
737 | d->enablebits[0].val = d->enablebits[1].val; | ||
738 | } | ||
739 | #endif | ||
740 | |||
741 | return ide_setup_pci_device(dev, d); | ||
742 | } | ||
743 | |||
744 | static int __devinit init_setup_pdc20265(struct pci_dev *dev, | ||
745 | ide_pci_device_t *d) | ||
746 | { | ||
747 | if ((dev->bus->self) && | ||
748 | (dev->bus->self->vendor == PCI_VENDOR_ID_INTEL) && | ||
749 | ((dev->bus->self->device == PCI_DEVICE_ID_INTEL_I960) || | ||
750 | (dev->bus->self->device == PCI_DEVICE_ID_INTEL_I960RM))) { | ||
751 | printk(KERN_INFO "ide: Skipping Promise PDC20265 " | ||
752 | "attached to I2O RAID controller.\n"); | ||
753 | return -ENODEV; | ||
754 | } | ||
755 | |||
756 | #if 0 | ||
757 | { | ||
758 | u8 pri = 0, sec = 0; | ||
759 | |||
760 | if (e->reg && (pci_read_config_byte(dev, e->reg, &tmp) || | ||
761 | (tmp & e->mask) != e->val)) | ||
762 | |||
763 | if (d->enablebits[0].reg != d->enablebits[1].reg) { | ||
764 | d->enablebits[0].reg = d->enablebits[1].reg; | ||
765 | d->enablebits[0].mask = d->enablebits[1].mask; | ||
766 | d->enablebits[0].val = d->enablebits[1].val; | ||
767 | } | ||
768 | } | ||
769 | #endif | ||
770 | |||
771 | return ide_setup_pci_device(dev, d); | ||
772 | } | ||
773 | |||
774 | static int __devinit init_setup_pdc202xx(struct pci_dev *dev, | ||
775 | ide_pci_device_t *d) | ||
776 | { | ||
777 | return ide_setup_pci_device(dev, d); | ||
778 | } | ||
779 | |||
780 | static ide_pci_device_t pdc202xx_chipsets[] __devinitdata = { | ||
781 | { /* 0 */ | ||
782 | .name = "PDC20246", | ||
783 | .init_setup = init_setup_pdc202ata4, | ||
784 | .init_chipset = init_chipset_pdc202xx, | ||
785 | .init_hwif = init_hwif_pdc202xx, | ||
786 | .init_dma = init_dma_pdc202xx, | ||
787 | .channels = 2, | ||
788 | .autodma = AUTODMA, | ||
789 | #ifndef CONFIG_PDC202XX_FORCE | ||
790 | .enablebits = {{0x50,0x02,0x02}, {0x50,0x04,0x04}}, | ||
791 | #endif | ||
792 | .bootable = OFF_BOARD, | ||
793 | .extra = 16, | ||
794 | },{ /* 1 */ | ||
795 | .name = "PDC20262", | ||
796 | .init_setup = init_setup_pdc202ata4, | ||
797 | .init_chipset = init_chipset_pdc202xx, | ||
798 | .init_hwif = init_hwif_pdc202xx, | ||
799 | .init_dma = init_dma_pdc202xx, | ||
800 | .channels = 2, | ||
801 | .autodma = AUTODMA, | ||
802 | #ifndef CONFIG_PDC202XX_FORCE | ||
803 | .enablebits = {{0x50,0x02,0x02}, {0x50,0x04,0x04}}, | ||
804 | #endif | ||
805 | .bootable = OFF_BOARD, | ||
806 | .extra = 48, | ||
807 | .flags = IDEPCI_FLAG_FORCE_PDC, | ||
808 | },{ /* 2 */ | ||
809 | .name = "PDC20263", | ||
810 | .init_setup = init_setup_pdc202ata4, | ||
811 | .init_chipset = init_chipset_pdc202xx, | ||
812 | .init_hwif = init_hwif_pdc202xx, | ||
813 | .init_dma = init_dma_pdc202xx, | ||
814 | .channels = 2, | ||
815 | .autodma = AUTODMA, | ||
816 | #ifndef CONFIG_PDC202XX_FORCE | ||
817 | .enablebits = {{0x50,0x02,0x02}, {0x50,0x04,0x04}}, | ||
818 | #endif | ||
819 | .bootable = OFF_BOARD, | ||
820 | .extra = 48, | ||
821 | },{ /* 3 */ | ||
822 | .name = "PDC20265", | ||
823 | .init_setup = init_setup_pdc20265, | ||
824 | .init_chipset = init_chipset_pdc202xx, | ||
825 | .init_hwif = init_hwif_pdc202xx, | ||
826 | .init_dma = init_dma_pdc202xx, | ||
827 | .channels = 2, | ||
828 | .autodma = AUTODMA, | ||
829 | #ifndef CONFIG_PDC202XX_FORCE | ||
830 | .enablebits = {{0x50,0x02,0x02}, {0x50,0x04,0x04}}, | ||
831 | #endif | ||
832 | .bootable = OFF_BOARD, | ||
833 | .extra = 48, | ||
834 | .flags = IDEPCI_FLAG_FORCE_PDC, | ||
835 | },{ /* 4 */ | ||
836 | .name = "PDC20267", | ||
837 | .init_setup = init_setup_pdc202xx, | ||
838 | .init_chipset = init_chipset_pdc202xx, | ||
839 | .init_hwif = init_hwif_pdc202xx, | ||
840 | .init_dma = init_dma_pdc202xx, | ||
841 | .channels = 2, | ||
842 | .autodma = AUTODMA, | ||
843 | #ifndef CONFIG_PDC202XX_FORCE | ||
844 | .enablebits = {{0x50,0x02,0x02}, {0x50,0x04,0x04}}, | ||
845 | #endif | ||
846 | .bootable = OFF_BOARD, | ||
847 | .extra = 48, | ||
848 | } | ||
849 | }; | ||
850 | |||
851 | /** | ||
852 | * pdc202xx_init_one - called when a PDC202xx is found | ||
853 | * @dev: the pdc202xx device | ||
854 | * @id: the matching pci id | ||
855 | * | ||
856 | * Called when the PCI registration layer (or the IDE initialization) | ||
857 | * finds a device matching our IDE device tables. | ||
858 | */ | ||
859 | |||
860 | static int __devinit pdc202xx_init_one(struct pci_dev *dev, const struct pci_device_id *id) | ||
861 | { | ||
862 | ide_pci_device_t *d = &pdc202xx_chipsets[id->driver_data]; | ||
863 | |||
864 | return d->init_setup(dev, d); | ||
865 | } | ||
866 | |||
867 | static struct pci_device_id pdc202xx_pci_tbl[] = { | ||
868 | { PCI_VENDOR_ID_PROMISE, PCI_DEVICE_ID_PROMISE_20246, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, | ||
869 | { PCI_VENDOR_ID_PROMISE, PCI_DEVICE_ID_PROMISE_20262, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1}, | ||
870 | { PCI_VENDOR_ID_PROMISE, PCI_DEVICE_ID_PROMISE_20263, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2}, | ||
871 | { PCI_VENDOR_ID_PROMISE, PCI_DEVICE_ID_PROMISE_20265, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3}, | ||
872 | { PCI_VENDOR_ID_PROMISE, PCI_DEVICE_ID_PROMISE_20267, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4}, | ||
873 | { 0, }, | ||
874 | }; | ||
875 | MODULE_DEVICE_TABLE(pci, pdc202xx_pci_tbl); | ||
876 | |||
877 | static struct pci_driver driver = { | ||
878 | .name = "Promise_Old_IDE", | ||
879 | .id_table = pdc202xx_pci_tbl, | ||
880 | .probe = pdc202xx_init_one, | ||
881 | }; | ||
882 | |||
883 | static int pdc202xx_ide_init(void) | ||
884 | { | ||
885 | return ide_pci_register_driver(&driver); | ||
886 | } | ||
887 | |||
888 | module_init(pdc202xx_ide_init); | ||
889 | |||
890 | MODULE_AUTHOR("Andre Hedrick, Frank Tiernan"); | ||
891 | MODULE_DESCRIPTION("PCI driver module for older Promise IDE"); | ||
892 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/ide/pci/piix.c b/drivers/ide/pci/piix.c new file mode 100644 index 000000000000..b5a20ae1ef3e --- /dev/null +++ b/drivers/ide/pci/piix.c | |||
@@ -0,0 +1,670 @@ | |||
1 | /* | ||
2 | * linux/drivers/ide/pci/piix.c Version 0.44 March 20, 2003 | ||
3 | * | ||
4 | * Copyright (C) 1998-1999 Andrzej Krzysztofowicz, Author and Maintainer | ||
5 | * Copyright (C) 1998-2000 Andre Hedrick <andre@linux-ide.org> | ||
6 | * Copyright (C) 2003 Red Hat Inc <alan@redhat.com> | ||
7 | * | ||
8 | * May be copied or modified under the terms of the GNU General Public License | ||
9 | * | ||
10 | * PIO mode setting function for Intel chipsets. | ||
11 | * For use instead of BIOS settings. | ||
12 | * | ||
13 | * 40-41 | ||
14 | * 42-43 | ||
15 | * | ||
16 | * 41 | ||
17 | * 43 | ||
18 | * | ||
19 | * | PIO 0 | c0 | 80 | 0 | piix_tune_drive(drive, 0); | ||
20 | * | PIO 2 | SW2 | d0 | 90 | 4 | piix_tune_drive(drive, 2); | ||
21 | * | PIO 3 | MW1 | e1 | a1 | 9 | piix_tune_drive(drive, 3); | ||
22 | * | PIO 4 | MW2 | e3 | a3 | b | piix_tune_drive(drive, 4); | ||
23 | * | ||
24 | * sitre = word40 & 0x4000; primary | ||
25 | * sitre = word42 & 0x4000; secondary | ||
26 | * | ||
27 | * 44 8421|8421 hdd|hdb | ||
28 | * | ||
29 | * 48 8421 hdd|hdc|hdb|hda udma enabled | ||
30 | * | ||
31 | * 0001 hda | ||
32 | * 0010 hdb | ||
33 | * 0100 hdc | ||
34 | * 1000 hdd | ||
35 | * | ||
36 | * 4a 84|21 hdb|hda | ||
37 | * 4b 84|21 hdd|hdc | ||
38 | * | ||
39 | * ata-33/82371AB | ||
40 | * ata-33/82371EB | ||
41 | * ata-33/82801AB ata-66/82801AA | ||
42 | * 00|00 udma 0 00|00 reserved | ||
43 | * 01|01 udma 1 01|01 udma 3 | ||
44 | * 10|10 udma 2 10|10 udma 4 | ||
45 | * 11|11 reserved 11|11 reserved | ||
46 | * | ||
47 | * 54 8421|8421 ata66 drive|ata66 enable | ||
48 | * | ||
49 | * pci_read_config_word(HWIF(drive)->pci_dev, 0x40, ®40); | ||
50 | * pci_read_config_word(HWIF(drive)->pci_dev, 0x42, ®42); | ||
51 | * pci_read_config_word(HWIF(drive)->pci_dev, 0x44, ®44); | ||
52 | * pci_read_config_byte(HWIF(drive)->pci_dev, 0x48, ®48); | ||
53 | * pci_read_config_word(HWIF(drive)->pci_dev, 0x4a, ®4a); | ||
54 | * pci_read_config_byte(HWIF(drive)->pci_dev, 0x54, ®54); | ||
55 | * | ||
56 | * Documentation | ||
57 | * Publically available from Intel web site. Errata documentation | ||
58 | * is also publically available. As an aide to anyone hacking on this | ||
59 | * driver the list of errata that are relevant is below.going back to | ||
60 | * PIIX4. Older device documentation is now a bit tricky to find. | ||
61 | * | ||
62 | * Errata of note: | ||
63 | * | ||
64 | * Unfixable | ||
65 | * PIIX4 errata #9 - Only on ultra obscure hw | ||
66 | * ICH3 errata #13 - Not observed to affect real hw | ||
67 | * by Intel | ||
68 | * | ||
69 | * Things we must deal with | ||
70 | * PIIX4 errata #10 - BM IDE hang with non UDMA | ||
71 | * (must stop/start dma to recover) | ||
72 | * 440MX errata #15 - As PIIX4 errata #10 | ||
73 | * PIIX4 errata #15 - Must not read control registers | ||
74 | * during a PIO transfer | ||
75 | * 440MX errata #13 - As PIIX4 errata #15 | ||
76 | * ICH2 errata #21 - DMA mode 0 doesn't work right | ||
77 | * ICH0/1 errata #55 - As ICH2 errata #21 | ||
78 | * ICH2 spec c #9 - Extra operations needed to handle | ||
79 | * drive hotswap [NOT YET SUPPORTED] | ||
80 | * ICH2 spec c #20 - IDE PRD must not cross a 64K boundary | ||
81 | * and must be dword aligned | ||
82 | * ICH2 spec c #24 - UDMA mode 4,5 t85/86 should be 6ns not 3.3 | ||
83 | * | ||
84 | * Should have been BIOS fixed: | ||
85 | * 450NX: errata #19 - DMA hangs on old 450NX | ||
86 | * 450NX: errata #20 - DMA hangs on old 450NX | ||
87 | * 450NX: errata #25 - Corruption with DMA on old 450NX | ||
88 | * ICH3 errata #15 - IDE deadlock under high load | ||
89 | * (BIOS must set dev 31 fn 0 bit 23) | ||
90 | * ICH3 errata #18 - Don't use native mode | ||
91 | */ | ||
92 | |||
93 | #include <linux/config.h> | ||
94 | #include <linux/types.h> | ||
95 | #include <linux/module.h> | ||
96 | #include <linux/kernel.h> | ||
97 | #include <linux/ioport.h> | ||
98 | #include <linux/pci.h> | ||
99 | #include <linux/hdreg.h> | ||
100 | #include <linux/ide.h> | ||
101 | #include <linux/delay.h> | ||
102 | #include <linux/init.h> | ||
103 | |||
104 | #include <asm/io.h> | ||
105 | |||
106 | static int no_piix_dma; | ||
107 | |||
108 | /** | ||
109 | * piix_ratemask - compute rate mask for PIIX IDE | ||
110 | * @drive: IDE drive to compute for | ||
111 | * | ||
112 | * Returns the available modes for the PIIX IDE controller. | ||
113 | */ | ||
114 | |||
115 | static u8 piix_ratemask (ide_drive_t *drive) | ||
116 | { | ||
117 | struct pci_dev *dev = HWIF(drive)->pci_dev; | ||
118 | u8 mode; | ||
119 | |||
120 | switch(dev->device) { | ||
121 | case PCI_DEVICE_ID_INTEL_82801EB_1: | ||
122 | mode = 3; | ||
123 | break; | ||
124 | /* UDMA 100 capable */ | ||
125 | case PCI_DEVICE_ID_INTEL_82801BA_8: | ||
126 | case PCI_DEVICE_ID_INTEL_82801BA_9: | ||
127 | case PCI_DEVICE_ID_INTEL_82801CA_10: | ||
128 | case PCI_DEVICE_ID_INTEL_82801CA_11: | ||
129 | case PCI_DEVICE_ID_INTEL_82801E_11: | ||
130 | case PCI_DEVICE_ID_INTEL_82801DB_1: | ||
131 | case PCI_DEVICE_ID_INTEL_82801DB_10: | ||
132 | case PCI_DEVICE_ID_INTEL_82801DB_11: | ||
133 | case PCI_DEVICE_ID_INTEL_82801EB_11: | ||
134 | case PCI_DEVICE_ID_INTEL_ESB_2: | ||
135 | case PCI_DEVICE_ID_INTEL_ICH6_19: | ||
136 | case PCI_DEVICE_ID_INTEL_ICH7_21: | ||
137 | mode = 3; | ||
138 | break; | ||
139 | /* UDMA 66 capable */ | ||
140 | case PCI_DEVICE_ID_INTEL_82801AA_1: | ||
141 | case PCI_DEVICE_ID_INTEL_82372FB_1: | ||
142 | mode = 2; | ||
143 | break; | ||
144 | /* UDMA 33 capable */ | ||
145 | case PCI_DEVICE_ID_INTEL_82371AB: | ||
146 | case PCI_DEVICE_ID_INTEL_82443MX_1: | ||
147 | case PCI_DEVICE_ID_INTEL_82451NX: | ||
148 | case PCI_DEVICE_ID_INTEL_82801AB_1: | ||
149 | return 1; | ||
150 | /* Non UDMA capable (MWDMA2) */ | ||
151 | case PCI_DEVICE_ID_INTEL_82371SB_1: | ||
152 | case PCI_DEVICE_ID_INTEL_82371FB_1: | ||
153 | case PCI_DEVICE_ID_INTEL_82371FB_0: | ||
154 | case PCI_DEVICE_ID_INTEL_82371MX: | ||
155 | default: | ||
156 | return 0; | ||
157 | } | ||
158 | |||
159 | /* | ||
160 | * If we are UDMA66 capable fall back to UDMA33 | ||
161 | * if the drive cannot see an 80pin cable. | ||
162 | */ | ||
163 | if (!eighty_ninty_three(drive)) | ||
164 | mode = min(mode, (u8)1); | ||
165 | return mode; | ||
166 | } | ||
167 | |||
168 | /** | ||
169 | * piix_dma_2_pio - return the PIO mode matching DMA | ||
170 | * @xfer_rate: transfer speed | ||
171 | * | ||
172 | * Returns the nearest equivalent PIO timing for the PIO or DMA | ||
173 | * mode requested by the controller. | ||
174 | */ | ||
175 | |||
176 | static u8 piix_dma_2_pio (u8 xfer_rate) { | ||
177 | switch(xfer_rate) { | ||
178 | case XFER_UDMA_6: | ||
179 | case XFER_UDMA_5: | ||
180 | case XFER_UDMA_4: | ||
181 | case XFER_UDMA_3: | ||
182 | case XFER_UDMA_2: | ||
183 | case XFER_UDMA_1: | ||
184 | case XFER_UDMA_0: | ||
185 | case XFER_MW_DMA_2: | ||
186 | case XFER_PIO_4: | ||
187 | return 4; | ||
188 | case XFER_MW_DMA_1: | ||
189 | case XFER_PIO_3: | ||
190 | return 3; | ||
191 | case XFER_SW_DMA_2: | ||
192 | case XFER_PIO_2: | ||
193 | return 2; | ||
194 | case XFER_MW_DMA_0: | ||
195 | case XFER_SW_DMA_1: | ||
196 | case XFER_SW_DMA_0: | ||
197 | case XFER_PIO_1: | ||
198 | case XFER_PIO_0: | ||
199 | case XFER_PIO_SLOW: | ||
200 | default: | ||
201 | return 0; | ||
202 | } | ||
203 | } | ||
204 | |||
205 | /** | ||
206 | * piix_tune_drive - tune a drive attached to a PIIX | ||
207 | * @drive: drive to tune | ||
208 | * @pio: desired PIO mode | ||
209 | * | ||
210 | * Set the interface PIO mode based upon the settings done by AMI BIOS | ||
211 | * (might be useful if drive is not registered in CMOS for any reason). | ||
212 | */ | ||
213 | static void piix_tune_drive (ide_drive_t *drive, u8 pio) | ||
214 | { | ||
215 | ide_hwif_t *hwif = HWIF(drive); | ||
216 | struct pci_dev *dev = hwif->pci_dev; | ||
217 | int is_slave = (&hwif->drives[1] == drive); | ||
218 | int master_port = hwif->channel ? 0x42 : 0x40; | ||
219 | int slave_port = 0x44; | ||
220 | unsigned long flags; | ||
221 | u16 master_data; | ||
222 | u8 slave_data; | ||
223 | /* ISP RTC */ | ||
224 | u8 timings[][2] = { { 0, 0 }, | ||
225 | { 0, 0 }, | ||
226 | { 1, 0 }, | ||
227 | { 2, 1 }, | ||
228 | { 2, 3 }, }; | ||
229 | |||
230 | pio = ide_get_best_pio_mode(drive, pio, 5, NULL); | ||
231 | spin_lock_irqsave(&ide_lock, flags); | ||
232 | pci_read_config_word(dev, master_port, &master_data); | ||
233 | if (is_slave) { | ||
234 | master_data = master_data | 0x4000; | ||
235 | if (pio > 1) | ||
236 | /* enable PPE, IE and TIME */ | ||
237 | master_data = master_data | 0x0070; | ||
238 | pci_read_config_byte(dev, slave_port, &slave_data); | ||
239 | slave_data = slave_data & (hwif->channel ? 0x0f : 0xf0); | ||
240 | slave_data = slave_data | (((timings[pio][0] << 2) | timings[pio][1]) << (hwif->channel ? 4 : 0)); | ||
241 | } else { | ||
242 | master_data = master_data & 0xccf8; | ||
243 | if (pio > 1) | ||
244 | /* enable PPE, IE and TIME */ | ||
245 | master_data = master_data | 0x0007; | ||
246 | master_data = master_data | (timings[pio][0] << 12) | (timings[pio][1] << 8); | ||
247 | } | ||
248 | pci_write_config_word(dev, master_port, master_data); | ||
249 | if (is_slave) | ||
250 | pci_write_config_byte(dev, slave_port, slave_data); | ||
251 | spin_unlock_irqrestore(&ide_lock, flags); | ||
252 | } | ||
253 | |||
254 | /** | ||
255 | * piix_tune_chipset - tune a PIIX interface | ||
256 | * @drive: IDE drive to tune | ||
257 | * @xferspeed: speed to configure | ||
258 | * | ||
259 | * Set a PIIX interface channel to the desired speeds. This involves | ||
260 | * requires the right timing data into the PIIX configuration space | ||
261 | * then setting the drive parameters appropriately | ||
262 | */ | ||
263 | |||
264 | static int piix_tune_chipset (ide_drive_t *drive, u8 xferspeed) | ||
265 | { | ||
266 | ide_hwif_t *hwif = HWIF(drive); | ||
267 | struct pci_dev *dev = hwif->pci_dev; | ||
268 | u8 maslave = hwif->channel ? 0x42 : 0x40; | ||
269 | u8 speed = ide_rate_filter(piix_ratemask(drive), xferspeed); | ||
270 | int a_speed = 3 << (drive->dn * 4); | ||
271 | int u_flag = 1 << drive->dn; | ||
272 | int v_flag = 0x01 << drive->dn; | ||
273 | int w_flag = 0x10 << drive->dn; | ||
274 | int u_speed = 0; | ||
275 | int sitre; | ||
276 | u16 reg4042, reg4a; | ||
277 | u8 reg48, reg54, reg55; | ||
278 | |||
279 | pci_read_config_word(dev, maslave, ®4042); | ||
280 | sitre = (reg4042 & 0x4000) ? 1 : 0; | ||
281 | pci_read_config_byte(dev, 0x48, ®48); | ||
282 | pci_read_config_word(dev, 0x4a, ®4a); | ||
283 | pci_read_config_byte(dev, 0x54, ®54); | ||
284 | pci_read_config_byte(dev, 0x55, ®55); | ||
285 | |||
286 | switch(speed) { | ||
287 | case XFER_UDMA_4: | ||
288 | case XFER_UDMA_2: u_speed = 2 << (drive->dn * 4); break; | ||
289 | case XFER_UDMA_5: | ||
290 | case XFER_UDMA_3: | ||
291 | case XFER_UDMA_1: u_speed = 1 << (drive->dn * 4); break; | ||
292 | case XFER_UDMA_0: u_speed = 0 << (drive->dn * 4); break; | ||
293 | case XFER_MW_DMA_2: | ||
294 | case XFER_MW_DMA_1: | ||
295 | case XFER_SW_DMA_2: break; | ||
296 | case XFER_PIO_4: | ||
297 | case XFER_PIO_3: | ||
298 | case XFER_PIO_2: | ||
299 | case XFER_PIO_0: break; | ||
300 | default: return -1; | ||
301 | } | ||
302 | |||
303 | if (speed >= XFER_UDMA_0) { | ||
304 | if (!(reg48 & u_flag)) | ||
305 | pci_write_config_byte(dev, 0x48, reg48 | u_flag); | ||
306 | if (speed == XFER_UDMA_5) { | ||
307 | pci_write_config_byte(dev, 0x55, (u8) reg55|w_flag); | ||
308 | } else { | ||
309 | pci_write_config_byte(dev, 0x55, (u8) reg55 & ~w_flag); | ||
310 | } | ||
311 | if ((reg4a & a_speed) != u_speed) | ||
312 | pci_write_config_word(dev, 0x4a, (reg4a & ~a_speed) | u_speed); | ||
313 | if (speed > XFER_UDMA_2) { | ||
314 | if (!(reg54 & v_flag)) | ||
315 | pci_write_config_byte(dev, 0x54, reg54 | v_flag); | ||
316 | } else | ||
317 | pci_write_config_byte(dev, 0x54, reg54 & ~v_flag); | ||
318 | } else { | ||
319 | if (reg48 & u_flag) | ||
320 | pci_write_config_byte(dev, 0x48, reg48 & ~u_flag); | ||
321 | if (reg4a & a_speed) | ||
322 | pci_write_config_word(dev, 0x4a, reg4a & ~a_speed); | ||
323 | if (reg54 & v_flag) | ||
324 | pci_write_config_byte(dev, 0x54, reg54 & ~v_flag); | ||
325 | if (reg55 & w_flag) | ||
326 | pci_write_config_byte(dev, 0x55, (u8) reg55 & ~w_flag); | ||
327 | } | ||
328 | |||
329 | piix_tune_drive(drive, piix_dma_2_pio(speed)); | ||
330 | return (ide_config_drive_speed(drive, speed)); | ||
331 | } | ||
332 | |||
333 | /** | ||
334 | * piix_faulty_dma0 - check for DMA0 errata | ||
335 | * @hwif: IDE interface to check | ||
336 | * | ||
337 | * If an ICH/ICH0/ICH2 interface is is operating in multi-word | ||
338 | * DMA mode with 600nS cycle time the IDE PIO prefetch buffer will | ||
339 | * inadvertently provide an extra piece of secondary data to the primary | ||
340 | * device resulting in data corruption. | ||
341 | * | ||
342 | * With such a device this test function returns true. This allows | ||
343 | * our tuning code to follow Intel recommendations and use PIO on | ||
344 | * such devices. | ||
345 | */ | ||
346 | |||
347 | static int piix_faulty_dma0(ide_hwif_t *hwif) | ||
348 | { | ||
349 | switch(hwif->pci_dev->device) | ||
350 | { | ||
351 | case PCI_DEVICE_ID_INTEL_82801AA_1: /* ICH */ | ||
352 | case PCI_DEVICE_ID_INTEL_82801AB_1: /* ICH0 */ | ||
353 | case PCI_DEVICE_ID_INTEL_82801BA_8: /* ICH2 */ | ||
354 | case PCI_DEVICE_ID_INTEL_82801BA_9: /* ICH2 */ | ||
355 | return 1; | ||
356 | } | ||
357 | return 0; | ||
358 | } | ||
359 | |||
360 | /** | ||
361 | * piix_config_drive_for_dma - configure drive for DMA | ||
362 | * @drive: IDE drive to configure | ||
363 | * | ||
364 | * Set up a PIIX interface channel for the best available speed. | ||
365 | * We prefer UDMA if it is available and then MWDMA. If DMA is | ||
366 | * not available we switch to PIO and return 0. | ||
367 | */ | ||
368 | |||
369 | static int piix_config_drive_for_dma (ide_drive_t *drive) | ||
370 | { | ||
371 | u8 speed = ide_dma_speed(drive, piix_ratemask(drive)); | ||
372 | |||
373 | /* Some ICH devices cannot support DMA mode 0 */ | ||
374 | if(speed == XFER_MW_DMA_0 && piix_faulty_dma0(HWIF(drive))) | ||
375 | speed = 0; | ||
376 | |||
377 | /* If no DMA speed was available or the chipset has DMA bugs | ||
378 | then disable DMA and use PIO */ | ||
379 | |||
380 | if (!speed || no_piix_dma) { | ||
381 | u8 tspeed = ide_get_best_pio_mode(drive, 255, 5, NULL); | ||
382 | speed = piix_dma_2_pio(XFER_PIO_0 + tspeed); | ||
383 | } | ||
384 | |||
385 | (void) piix_tune_chipset(drive, speed); | ||
386 | return ide_dma_enable(drive); | ||
387 | } | ||
388 | |||
389 | /** | ||
390 | * piix_config_drive_xfer_rate - set up an IDE device | ||
391 | * @drive: IDE drive to configure | ||
392 | * | ||
393 | * Set up the PIIX interface for the best available speed on this | ||
394 | * interface, preferring DMA to PIO. | ||
395 | */ | ||
396 | |||
397 | static int piix_config_drive_xfer_rate (ide_drive_t *drive) | ||
398 | { | ||
399 | ide_hwif_t *hwif = HWIF(drive); | ||
400 | struct hd_driveid *id = drive->id; | ||
401 | |||
402 | drive->init_speed = 0; | ||
403 | |||
404 | if ((id->capability & 1) && drive->autodma) { | ||
405 | |||
406 | if (ide_use_dma(drive)) { | ||
407 | if (piix_config_drive_for_dma(drive)) | ||
408 | return hwif->ide_dma_on(drive); | ||
409 | } | ||
410 | |||
411 | goto fast_ata_pio; | ||
412 | |||
413 | } else if ((id->capability & 8) || (id->field_valid & 2)) { | ||
414 | fast_ata_pio: | ||
415 | /* Find best PIO mode. */ | ||
416 | hwif->tuneproc(drive, 255); | ||
417 | return hwif->ide_dma_off_quietly(drive); | ||
418 | } | ||
419 | /* IORDY not supported */ | ||
420 | return 0; | ||
421 | } | ||
422 | |||
423 | /** | ||
424 | * init_chipset_piix - set up the PIIX chipset | ||
425 | * @dev: PCI device to set up | ||
426 | * @name: Name of the device | ||
427 | * | ||
428 | * Initialize the PCI device as required. For the PIIX this turns | ||
429 | * out to be nice and simple | ||
430 | */ | ||
431 | |||
432 | static unsigned int __devinit init_chipset_piix (struct pci_dev *dev, const char *name) | ||
433 | { | ||
434 | switch(dev->device) { | ||
435 | case PCI_DEVICE_ID_INTEL_82801EB_1: | ||
436 | case PCI_DEVICE_ID_INTEL_82801AA_1: | ||
437 | case PCI_DEVICE_ID_INTEL_82801AB_1: | ||
438 | case PCI_DEVICE_ID_INTEL_82801BA_8: | ||
439 | case PCI_DEVICE_ID_INTEL_82801BA_9: | ||
440 | case PCI_DEVICE_ID_INTEL_82801CA_10: | ||
441 | case PCI_DEVICE_ID_INTEL_82801CA_11: | ||
442 | case PCI_DEVICE_ID_INTEL_82801DB_1: | ||
443 | case PCI_DEVICE_ID_INTEL_82801DB_10: | ||
444 | case PCI_DEVICE_ID_INTEL_82801DB_11: | ||
445 | case PCI_DEVICE_ID_INTEL_82801EB_11: | ||
446 | case PCI_DEVICE_ID_INTEL_82801E_11: | ||
447 | case PCI_DEVICE_ID_INTEL_ESB_2: | ||
448 | case PCI_DEVICE_ID_INTEL_ICH6_19: | ||
449 | case PCI_DEVICE_ID_INTEL_ICH7_21: | ||
450 | { | ||
451 | unsigned int extra = 0; | ||
452 | pci_read_config_dword(dev, 0x54, &extra); | ||
453 | pci_write_config_dword(dev, 0x54, extra|0x400); | ||
454 | } | ||
455 | default: | ||
456 | break; | ||
457 | } | ||
458 | |||
459 | return 0; | ||
460 | } | ||
461 | |||
462 | /** | ||
463 | * init_hwif_piix - fill in the hwif for the PIIX | ||
464 | * @hwif: IDE interface | ||
465 | * | ||
466 | * Set up the ide_hwif_t for the PIIX interface according to the | ||
467 | * capabilities of the hardware. | ||
468 | */ | ||
469 | |||
470 | static void __devinit init_hwif_piix(ide_hwif_t *hwif) | ||
471 | { | ||
472 | u8 reg54h = 0, reg55h = 0, ata66 = 0; | ||
473 | u8 mask = hwif->channel ? 0xc0 : 0x30; | ||
474 | |||
475 | #ifndef CONFIG_IA64 | ||
476 | if (!hwif->irq) | ||
477 | hwif->irq = hwif->channel ? 15 : 14; | ||
478 | #endif /* CONFIG_IA64 */ | ||
479 | |||
480 | if (hwif->pci_dev->device == PCI_DEVICE_ID_INTEL_82371MX) { | ||
481 | /* This is a painful system best to let it self tune for now */ | ||
482 | return; | ||
483 | } | ||
484 | |||
485 | hwif->autodma = 0; | ||
486 | hwif->tuneproc = &piix_tune_drive; | ||
487 | hwif->speedproc = &piix_tune_chipset; | ||
488 | hwif->drives[0].autotune = 1; | ||
489 | hwif->drives[1].autotune = 1; | ||
490 | |||
491 | if (!hwif->dma_base) | ||
492 | return; | ||
493 | |||
494 | hwif->atapi_dma = 1; | ||
495 | hwif->ultra_mask = 0x3f; | ||
496 | hwif->mwdma_mask = 0x06; | ||
497 | hwif->swdma_mask = 0x04; | ||
498 | |||
499 | switch(hwif->pci_dev->device) { | ||
500 | case PCI_DEVICE_ID_INTEL_82371MX: | ||
501 | hwif->mwdma_mask = 0x80; | ||
502 | hwif->swdma_mask = 0x80; | ||
503 | case PCI_DEVICE_ID_INTEL_82371FB_0: | ||
504 | case PCI_DEVICE_ID_INTEL_82371FB_1: | ||
505 | case PCI_DEVICE_ID_INTEL_82371SB_1: | ||
506 | hwif->ultra_mask = 0x80; | ||
507 | break; | ||
508 | case PCI_DEVICE_ID_INTEL_82371AB: | ||
509 | case PCI_DEVICE_ID_INTEL_82443MX_1: | ||
510 | case PCI_DEVICE_ID_INTEL_82451NX: | ||
511 | case PCI_DEVICE_ID_INTEL_82801AB_1: | ||
512 | hwif->ultra_mask = 0x07; | ||
513 | break; | ||
514 | default: | ||
515 | pci_read_config_byte(hwif->pci_dev, 0x54, ®54h); | ||
516 | pci_read_config_byte(hwif->pci_dev, 0x55, ®55h); | ||
517 | ata66 = (reg54h & mask) ? 1 : 0; | ||
518 | break; | ||
519 | } | ||
520 | |||
521 | if (!(hwif->udma_four)) | ||
522 | hwif->udma_four = ata66; | ||
523 | hwif->ide_dma_check = &piix_config_drive_xfer_rate; | ||
524 | if (!noautodma) | ||
525 | hwif->autodma = 1; | ||
526 | |||
527 | hwif->drives[1].autodma = hwif->autodma; | ||
528 | hwif->drives[0].autodma = hwif->autodma; | ||
529 | } | ||
530 | |||
531 | #define DECLARE_PIIX_DEV(name_str) \ | ||
532 | { \ | ||
533 | .name = name_str, \ | ||
534 | .init_chipset = init_chipset_piix, \ | ||
535 | .init_hwif = init_hwif_piix, \ | ||
536 | .channels = 2, \ | ||
537 | .autodma = AUTODMA, \ | ||
538 | .enablebits = {{0x41,0x80,0x80}, {0x43,0x80,0x80}}, \ | ||
539 | .bootable = ON_BOARD, \ | ||
540 | } | ||
541 | |||
542 | static ide_pci_device_t piix_pci_info[] __devinitdata = { | ||
543 | /* 0 */ DECLARE_PIIX_DEV("PIIXa"), | ||
544 | /* 1 */ DECLARE_PIIX_DEV("PIIXb"), | ||
545 | |||
546 | { /* 2 */ | ||
547 | .name = "MPIIX", | ||
548 | .init_hwif = init_hwif_piix, | ||
549 | .channels = 2, | ||
550 | .autodma = NODMA, | ||
551 | .enablebits = {{0x6D,0x80,0x80}, {0x6F,0x80,0x80}}, | ||
552 | .bootable = ON_BOARD, | ||
553 | }, | ||
554 | |||
555 | /* 3 */ DECLARE_PIIX_DEV("PIIX3"), | ||
556 | /* 4 */ DECLARE_PIIX_DEV("PIIX4"), | ||
557 | /* 5 */ DECLARE_PIIX_DEV("ICH0"), | ||
558 | /* 6 */ DECLARE_PIIX_DEV("PIIX4"), | ||
559 | /* 7 */ DECLARE_PIIX_DEV("ICH"), | ||
560 | /* 8 */ DECLARE_PIIX_DEV("PIIX4"), | ||
561 | /* 9 */ DECLARE_PIIX_DEV("PIIX4"), | ||
562 | /* 10 */ DECLARE_PIIX_DEV("ICH2"), | ||
563 | /* 11 */ DECLARE_PIIX_DEV("ICH2M"), | ||
564 | /* 12 */ DECLARE_PIIX_DEV("ICH3M"), | ||
565 | /* 13 */ DECLARE_PIIX_DEV("ICH3"), | ||
566 | /* 14 */ DECLARE_PIIX_DEV("ICH4"), | ||
567 | /* 15 */ DECLARE_PIIX_DEV("ICH5"), | ||
568 | /* 16 */ DECLARE_PIIX_DEV("C-ICH"), | ||
569 | /* 17 */ DECLARE_PIIX_DEV("ICH4"), | ||
570 | /* 18 */ DECLARE_PIIX_DEV("ICH5-SATA"), | ||
571 | /* 19 */ DECLARE_PIIX_DEV("ICH5"), | ||
572 | /* 20 */ DECLARE_PIIX_DEV("ICH6"), | ||
573 | /* 21 */ DECLARE_PIIX_DEV("ICH7"), | ||
574 | /* 22 */ DECLARE_PIIX_DEV("ICH4"), | ||
575 | }; | ||
576 | |||
577 | /** | ||
578 | * piix_init_one - called when a PIIX is found | ||
579 | * @dev: the piix device | ||
580 | * @id: the matching pci id | ||
581 | * | ||
582 | * Called when the PCI registration layer (or the IDE initialization) | ||
583 | * finds a device matching our IDE device tables. | ||
584 | */ | ||
585 | |||
586 | static int __devinit piix_init_one(struct pci_dev *dev, const struct pci_device_id *id) | ||
587 | { | ||
588 | ide_pci_device_t *d = &piix_pci_info[id->driver_data]; | ||
589 | |||
590 | return ide_setup_pci_device(dev, d); | ||
591 | } | ||
592 | |||
593 | /** | ||
594 | * piix_check_450nx - Check for problem 450NX setup | ||
595 | * | ||
596 | * Check for the present of 450NX errata #19 and errata #25. If | ||
597 | * they are found, disable use of DMA IDE | ||
598 | */ | ||
599 | |||
600 | static void __devinit piix_check_450nx(void) | ||
601 | { | ||
602 | struct pci_dev *pdev = NULL; | ||
603 | u16 cfg; | ||
604 | u8 rev; | ||
605 | while((pdev=pci_find_device(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82454NX, pdev))!=NULL) | ||
606 | { | ||
607 | /* Look for 450NX PXB. Check for problem configurations | ||
608 | A PCI quirk checks bit 6 already */ | ||
609 | pci_read_config_byte(pdev, PCI_REVISION_ID, &rev); | ||
610 | pci_read_config_word(pdev, 0x41, &cfg); | ||
611 | /* Only on the original revision: IDE DMA can hang */ | ||
612 | if(rev == 0x00) | ||
613 | no_piix_dma = 1; | ||
614 | /* On all revisions below 5 PXB bus lock must be disabled for IDE */ | ||
615 | else if(cfg & (1<<14) && rev < 5) | ||
616 | no_piix_dma = 2; | ||
617 | } | ||
618 | if(no_piix_dma) | ||
619 | printk(KERN_WARNING "piix: 450NX errata present, disabling IDE DMA.\n"); | ||
620 | if(no_piix_dma == 2) | ||
621 | printk(KERN_WARNING "piix: A BIOS update may resolve this.\n"); | ||
622 | } | ||
623 | |||
624 | static struct pci_device_id piix_pci_tbl[] = { | ||
625 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371FB_0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, | ||
626 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371FB_1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1}, | ||
627 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371MX, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2}, | ||
628 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371SB_1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3}, | ||
629 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4}, | ||
630 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5}, | ||
631 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443MX_1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 6}, | ||
632 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 7}, | ||
633 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82372FB_1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 8}, | ||
634 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82451NX, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 9}, | ||
635 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_9, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 10}, | ||
636 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_8, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 11}, | ||
637 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_10,PCI_ANY_ID, PCI_ANY_ID, 0, 0, 12}, | ||
638 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_11,PCI_ANY_ID, PCI_ANY_ID, 0, 0, 13}, | ||
639 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_11,PCI_ANY_ID, PCI_ANY_ID, 0, 0, 14}, | ||
640 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_11,PCI_ANY_ID, PCI_ANY_ID, 0, 0, 15}, | ||
641 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801E_11, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 16}, | ||
642 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_10,PCI_ANY_ID, PCI_ANY_ID, 0, 0, 17}, | ||
643 | #ifdef CONFIG_BLK_DEV_IDE_SATA | ||
644 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 18}, | ||
645 | #endif | ||
646 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB_2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 19}, | ||
647 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_19, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 20}, | ||
648 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7_21, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 21}, | ||
649 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 22}, | ||
650 | { 0, }, | ||
651 | }; | ||
652 | MODULE_DEVICE_TABLE(pci, piix_pci_tbl); | ||
653 | |||
654 | static struct pci_driver driver = { | ||
655 | .name = "PIIX_IDE", | ||
656 | .id_table = piix_pci_tbl, | ||
657 | .probe = piix_init_one, | ||
658 | }; | ||
659 | |||
660 | static int __init piix_ide_init(void) | ||
661 | { | ||
662 | piix_check_450nx(); | ||
663 | return ide_pci_register_driver(&driver); | ||
664 | } | ||
665 | |||
666 | module_init(piix_ide_init); | ||
667 | |||
668 | MODULE_AUTHOR("Andre Hedrick, Andrzej Krzysztofowicz"); | ||
669 | MODULE_DESCRIPTION("PCI driver module for Intel PIIX IDE"); | ||
670 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/ide/pci/rz1000.c b/drivers/ide/pci/rz1000.c new file mode 100644 index 000000000000..608cd7609072 --- /dev/null +++ b/drivers/ide/pci/rz1000.c | |||
@@ -0,0 +1,91 @@ | |||
1 | /* | ||
2 | * linux/drivers/ide/pci/rz1000.c Version 0.06 January 12, 2003 | ||
3 | * | ||
4 | * Copyright (C) 1995-1998 Linus Torvalds & author (see below) | ||
5 | */ | ||
6 | |||
7 | /* | ||
8 | * Principal Author: mlord@pobox.com (Mark Lord) | ||
9 | * | ||
10 | * See linux/MAINTAINERS for address of current maintainer. | ||
11 | * | ||
12 | * This file provides support for disabling the buggy read-ahead | ||
13 | * mode of the RZ1000 IDE chipset, commonly used on Intel motherboards. | ||
14 | * | ||
15 | * Dunno if this fixes both ports, or only the primary port (?). | ||
16 | */ | ||
17 | |||
18 | #undef REALLY_SLOW_IO /* most systems can safely undef this */ | ||
19 | |||
20 | #include <linux/config.h> /* for CONFIG_BLK_DEV_IDEPCI */ | ||
21 | #include <linux/types.h> | ||
22 | #include <linux/module.h> | ||
23 | #include <linux/kernel.h> | ||
24 | #include <linux/delay.h> | ||
25 | #include <linux/timer.h> | ||
26 | #include <linux/mm.h> | ||
27 | #include <linux/ioport.h> | ||
28 | #include <linux/blkdev.h> | ||
29 | #include <linux/hdreg.h> | ||
30 | #include <linux/pci.h> | ||
31 | #include <linux/ide.h> | ||
32 | #include <linux/init.h> | ||
33 | |||
34 | #include <asm/io.h> | ||
35 | |||
36 | static void __devinit init_hwif_rz1000 (ide_hwif_t *hwif) | ||
37 | { | ||
38 | u16 reg; | ||
39 | struct pci_dev *dev = hwif->pci_dev; | ||
40 | |||
41 | hwif->chipset = ide_rz1000; | ||
42 | if (!pci_read_config_word (dev, 0x40, ®) && | ||
43 | !pci_write_config_word(dev, 0x40, reg & 0xdfff)) { | ||
44 | printk(KERN_INFO "%s: disabled chipset read-ahead " | ||
45 | "(buggy RZ1000/RZ1001)\n", hwif->name); | ||
46 | } else { | ||
47 | hwif->serialized = 1; | ||
48 | hwif->drives[0].no_unmask = 1; | ||
49 | hwif->drives[1].no_unmask = 1; | ||
50 | printk(KERN_INFO "%s: serialized, disabled unmasking " | ||
51 | "(buggy RZ1000/RZ1001)\n", hwif->name); | ||
52 | } | ||
53 | } | ||
54 | |||
55 | static ide_pci_device_t rz1000_chipset __devinitdata = { | ||
56 | .name = "RZ100x", | ||
57 | .init_hwif = init_hwif_rz1000, | ||
58 | .channels = 2, | ||
59 | .autodma = NODMA, | ||
60 | .bootable = ON_BOARD, | ||
61 | }; | ||
62 | |||
63 | static int __devinit rz1000_init_one(struct pci_dev *dev, const struct pci_device_id *id) | ||
64 | { | ||
65 | return ide_setup_pci_device(dev, &rz1000_chipset); | ||
66 | } | ||
67 | |||
68 | static struct pci_device_id rz1000_pci_tbl[] = { | ||
69 | { PCI_VENDOR_ID_PCTECH, PCI_DEVICE_ID_PCTECH_RZ1000, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, | ||
70 | { PCI_VENDOR_ID_PCTECH, PCI_DEVICE_ID_PCTECH_RZ1001, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, | ||
71 | { 0, }, | ||
72 | }; | ||
73 | MODULE_DEVICE_TABLE(pci, rz1000_pci_tbl); | ||
74 | |||
75 | static struct pci_driver driver = { | ||
76 | .name = "RZ1000_IDE", | ||
77 | .id_table = rz1000_pci_tbl, | ||
78 | .probe = rz1000_init_one, | ||
79 | }; | ||
80 | |||
81 | static int rz1000_ide_init(void) | ||
82 | { | ||
83 | return ide_pci_register_driver(&driver); | ||
84 | } | ||
85 | |||
86 | module_init(rz1000_ide_init); | ||
87 | |||
88 | MODULE_AUTHOR("Andre Hedrick"); | ||
89 | MODULE_DESCRIPTION("PCI driver module for RZ1000 IDE"); | ||
90 | MODULE_LICENSE("GPL"); | ||
91 | |||
diff --git a/drivers/ide/pci/sc1200.c b/drivers/ide/pci/sc1200.c new file mode 100644 index 000000000000..84fda21e4dbd --- /dev/null +++ b/drivers/ide/pci/sc1200.c | |||
@@ -0,0 +1,518 @@ | |||
1 | /* | ||
2 | * linux/drivers/ide/pci/sc1200.c Version 0.91 28-Jan-2003 | ||
3 | * | ||
4 | * Copyright (C) 2000-2002 Mark Lord <mlord@pobox.com> | ||
5 | * May be copied or modified under the terms of the GNU General Public License | ||
6 | * | ||
7 | * Development of this chipset driver was funded | ||
8 | * by the nice folks at National Semiconductor. | ||
9 | * | ||
10 | * Documentation: | ||
11 | * Available from National Semiconductor | ||
12 | */ | ||
13 | |||
14 | #include <linux/config.h> | ||
15 | #include <linux/module.h> | ||
16 | #include <linux/types.h> | ||
17 | #include <linux/kernel.h> | ||
18 | #include <linux/delay.h> | ||
19 | #include <linux/timer.h> | ||
20 | #include <linux/mm.h> | ||
21 | #include <linux/ioport.h> | ||
22 | #include <linux/blkdev.h> | ||
23 | #include <linux/hdreg.h> | ||
24 | #include <linux/interrupt.h> | ||
25 | #include <linux/pci.h> | ||
26 | #include <linux/init.h> | ||
27 | #include <linux/ide.h> | ||
28 | #include <linux/pm.h> | ||
29 | #include <asm/io.h> | ||
30 | #include <asm/irq.h> | ||
31 | |||
32 | #define SC1200_REV_A 0x00 | ||
33 | #define SC1200_REV_B1 0x01 | ||
34 | #define SC1200_REV_B3 0x02 | ||
35 | #define SC1200_REV_C1 0x03 | ||
36 | #define SC1200_REV_D1 0x04 | ||
37 | |||
38 | #define PCI_CLK_33 0x00 | ||
39 | #define PCI_CLK_48 0x01 | ||
40 | #define PCI_CLK_66 0x02 | ||
41 | #define PCI_CLK_33A 0x03 | ||
42 | |||
43 | static unsigned short sc1200_get_pci_clock (void) | ||
44 | { | ||
45 | unsigned char chip_id, silicon_revision; | ||
46 | unsigned int pci_clock; | ||
47 | /* | ||
48 | * Check the silicon revision, as not all versions of the chip | ||
49 | * have the register with the fast PCI bus timings. | ||
50 | */ | ||
51 | chip_id = inb (0x903c); | ||
52 | silicon_revision = inb (0x903d); | ||
53 | |||
54 | // Read the fast pci clock frequency | ||
55 | if (chip_id == 0x04 && silicon_revision < SC1200_REV_B1) { | ||
56 | pci_clock = PCI_CLK_33; | ||
57 | } else { | ||
58 | // check clock generator configuration (cfcc) | ||
59 | // the clock is in bits 8 and 9 of this word | ||
60 | |||
61 | pci_clock = inw (0x901e); | ||
62 | pci_clock >>= 8; | ||
63 | pci_clock &= 0x03; | ||
64 | if (pci_clock == PCI_CLK_33A) | ||
65 | pci_clock = PCI_CLK_33; | ||
66 | } | ||
67 | return pci_clock; | ||
68 | } | ||
69 | |||
70 | extern char *ide_xfer_verbose (byte xfer_rate); | ||
71 | |||
72 | /* | ||
73 | * Set a new transfer mode at the drive | ||
74 | */ | ||
75 | static int sc1200_set_xfer_mode (ide_drive_t *drive, byte mode) | ||
76 | { | ||
77 | printk("%s: sc1200_set_xfer_mode(%s)\n", drive->name, ide_xfer_verbose(mode)); | ||
78 | return ide_config_drive_speed(drive, mode); | ||
79 | } | ||
80 | |||
81 | /* | ||
82 | * Here are the standard PIO mode 0-4 timings for each "format". | ||
83 | * Format-0 uses fast data reg timings, with slower command reg timings. | ||
84 | * Format-1 uses fast timings for all registers, but won't work with all drives. | ||
85 | */ | ||
86 | static const unsigned int sc1200_pio_timings[4][5] = | ||
87 | {{0x00009172, 0x00012171, 0x00020080, 0x00032010, 0x00040010}, // format0 33Mhz | ||
88 | {0xd1329172, 0x71212171, 0x30200080, 0x20102010, 0x00100010}, // format1, 33Mhz | ||
89 | {0xfaa3f4f3, 0xc23232b2, 0x513101c1, 0x31213121, 0x10211021}, // format1, 48Mhz | ||
90 | {0xfff4fff4, 0xf35353d3, 0x814102f1, 0x42314231, 0x11311131}}; // format1, 66Mhz | ||
91 | |||
92 | /* | ||
93 | * After chip reset, the PIO timings are set to 0x00009172, which is not valid. | ||
94 | */ | ||
95 | //#define SC1200_BAD_PIO(timings) (((timings)&~0x80000000)==0x00009172) | ||
96 | |||
97 | static int sc1200_autoselect_dma_mode (ide_drive_t *drive) | ||
98 | { | ||
99 | int udma_ok = 1, mode = 0; | ||
100 | ide_hwif_t *hwif = HWIF(drive); | ||
101 | int unit = drive->select.b.unit; | ||
102 | ide_drive_t *mate = &hwif->drives[unit^1]; | ||
103 | struct hd_driveid *id = drive->id; | ||
104 | |||
105 | /* | ||
106 | * The SC1200 specifies that two drives sharing a cable cannot | ||
107 | * mix UDMA/MDMA. It has to be one or the other, for the pair, | ||
108 | * though different timings can still be chosen for each drive. | ||
109 | * We could set the appropriate timing bits on the fly, | ||
110 | * but that might be a bit confusing. So, for now we statically | ||
111 | * handle this requirement by looking at our mate drive to see | ||
112 | * what it is capable of, before choosing a mode for our own drive. | ||
113 | */ | ||
114 | if (mate->present) { | ||
115 | struct hd_driveid *mateid = mate->id; | ||
116 | if (mateid && (mateid->capability & 1) && !__ide_dma_bad_drive(mate)) { | ||
117 | if ((mateid->field_valid & 4) && (mateid->dma_ultra & 7)) | ||
118 | udma_ok = 1; | ||
119 | else if ((mateid->field_valid & 2) && (mateid->dma_mword & 7)) | ||
120 | udma_ok = 0; | ||
121 | else | ||
122 | udma_ok = 1; | ||
123 | } | ||
124 | } | ||
125 | /* | ||
126 | * Now see what the current drive is capable of, | ||
127 | * selecting UDMA only if the mate said it was ok. | ||
128 | */ | ||
129 | if (id && (id->capability & 1) && hwif->autodma && !__ide_dma_bad_drive(drive)) { | ||
130 | if (udma_ok && (id->field_valid & 4) && (id->dma_ultra & 7)) { | ||
131 | if (id->dma_ultra & 4) | ||
132 | mode = XFER_UDMA_2; | ||
133 | else if (id->dma_ultra & 2) | ||
134 | mode = XFER_UDMA_1; | ||
135 | else if (id->dma_ultra & 1) | ||
136 | mode = XFER_UDMA_0; | ||
137 | } | ||
138 | if (!mode && (id->field_valid & 2) && (id->dma_mword & 7)) { | ||
139 | if (id->dma_mword & 4) | ||
140 | mode = XFER_MW_DMA_2; | ||
141 | else if (id->dma_mword & 2) | ||
142 | mode = XFER_MW_DMA_1; | ||
143 | else if (id->dma_mword & 1) | ||
144 | mode = XFER_MW_DMA_0; | ||
145 | } | ||
146 | } | ||
147 | return mode; | ||
148 | } | ||
149 | |||
150 | /* | ||
151 | * sc1200_config_dma2() handles selection/setting of DMA/UDMA modes | ||
152 | * for both the chipset and drive. | ||
153 | */ | ||
154 | static int sc1200_config_dma2 (ide_drive_t *drive, int mode) | ||
155 | { | ||
156 | ide_hwif_t *hwif = HWIF(drive); | ||
157 | int unit = drive->select.b.unit; | ||
158 | unsigned int reg, timings; | ||
159 | unsigned short pci_clock; | ||
160 | unsigned int basereg = hwif->channel ? 0x50 : 0x40; | ||
161 | |||
162 | /* | ||
163 | * Default to DMA-off in case we run into trouble here. | ||
164 | */ | ||
165 | hwif->ide_dma_off_quietly(drive); /* turn off DMA while we fiddle */ | ||
166 | outb(inb(hwif->dma_base+2)&~(unit?0x40:0x20), hwif->dma_base+2); /* clear DMA_capable bit */ | ||
167 | |||
168 | /* | ||
169 | * Tell the drive to switch to the new mode; abort on failure. | ||
170 | */ | ||
171 | if (!mode || sc1200_set_xfer_mode(drive, mode)) { | ||
172 | printk("SC1200: set xfer mode failure\n"); | ||
173 | return 1; /* failure */ | ||
174 | } | ||
175 | |||
176 | pci_clock = sc1200_get_pci_clock(); | ||
177 | |||
178 | /* | ||
179 | * Now tune the chipset to match the drive: | ||
180 | * | ||
181 | * Note that each DMA mode has several timings associated with it. | ||
182 | * The correct timing depends on the fast PCI clock freq. | ||
183 | */ | ||
184 | timings = 0; | ||
185 | switch (mode) { | ||
186 | case XFER_UDMA_0: | ||
187 | switch (pci_clock) { | ||
188 | case PCI_CLK_33: timings = 0x00921250; break; | ||
189 | case PCI_CLK_48: timings = 0x00932470; break; | ||
190 | case PCI_CLK_66: timings = 0x009436a1; break; | ||
191 | } | ||
192 | break; | ||
193 | case XFER_UDMA_1: | ||
194 | switch (pci_clock) { | ||
195 | case PCI_CLK_33: timings = 0x00911140; break; | ||
196 | case PCI_CLK_48: timings = 0x00922260; break; | ||
197 | case PCI_CLK_66: timings = 0x00933481; break; | ||
198 | } | ||
199 | break; | ||
200 | case XFER_UDMA_2: | ||
201 | switch (pci_clock) { | ||
202 | case PCI_CLK_33: timings = 0x00911030; break; | ||
203 | case PCI_CLK_48: timings = 0x00922140; break; | ||
204 | case PCI_CLK_66: timings = 0x00923261; break; | ||
205 | } | ||
206 | break; | ||
207 | case XFER_MW_DMA_0: | ||
208 | switch (pci_clock) { | ||
209 | case PCI_CLK_33: timings = 0x00077771; break; | ||
210 | case PCI_CLK_48: timings = 0x000bbbb2; break; | ||
211 | case PCI_CLK_66: timings = 0x000ffff3; break; | ||
212 | } | ||
213 | break; | ||
214 | case XFER_MW_DMA_1: | ||
215 | switch (pci_clock) { | ||
216 | case PCI_CLK_33: timings = 0x00012121; break; | ||
217 | case PCI_CLK_48: timings = 0x00024241; break; | ||
218 | case PCI_CLK_66: timings = 0x00035352; break; | ||
219 | } | ||
220 | break; | ||
221 | case XFER_MW_DMA_2: | ||
222 | switch (pci_clock) { | ||
223 | case PCI_CLK_33: timings = 0x00002020; break; | ||
224 | case PCI_CLK_48: timings = 0x00013131; break; | ||
225 | case PCI_CLK_66: timings = 0x00015151; break; | ||
226 | } | ||
227 | break; | ||
228 | } | ||
229 | |||
230 | if (timings == 0) { | ||
231 | printk("%s: sc1200_config_dma: huh? mode=%02x clk=%x \n", drive->name, mode, pci_clock); | ||
232 | return 1; /* failure */ | ||
233 | } | ||
234 | |||
235 | if (unit == 0) { /* are we configuring drive0? */ | ||
236 | pci_read_config_dword(hwif->pci_dev, basereg+4, ®); | ||
237 | timings |= reg & 0x80000000; /* preserve PIO format bit */ | ||
238 | pci_write_config_dword(hwif->pci_dev, basereg+4, timings); | ||
239 | } else { | ||
240 | pci_write_config_dword(hwif->pci_dev, basereg+12, timings); | ||
241 | } | ||
242 | |||
243 | outb(inb(hwif->dma_base+2)|(unit?0x40:0x20), hwif->dma_base+2); /* set DMA_capable bit */ | ||
244 | |||
245 | /* | ||
246 | * Finally, turn DMA on in software, and exit. | ||
247 | */ | ||
248 | return hwif->ide_dma_on(drive); /* success */ | ||
249 | } | ||
250 | |||
251 | /* | ||
252 | * sc1200_config_dma() handles selection/setting of DMA/UDMA modes | ||
253 | * for both the chipset and drive. | ||
254 | */ | ||
255 | static int sc1200_config_dma (ide_drive_t *drive) | ||
256 | { | ||
257 | return sc1200_config_dma2(drive, sc1200_autoselect_dma_mode(drive)); | ||
258 | } | ||
259 | |||
260 | |||
261 | /* Replacement for the standard ide_dma_end action in | ||
262 | * dma_proc. | ||
263 | * | ||
264 | * returns 1 on error, 0 otherwise | ||
265 | */ | ||
266 | static int sc1200_ide_dma_end (ide_drive_t *drive) | ||
267 | { | ||
268 | ide_hwif_t *hwif = HWIF(drive); | ||
269 | unsigned long dma_base = hwif->dma_base; | ||
270 | byte dma_stat; | ||
271 | |||
272 | dma_stat = inb(dma_base+2); /* get DMA status */ | ||
273 | |||
274 | if (!(dma_stat & 4)) | ||
275 | printk(" ide_dma_end dma_stat=%0x err=%x newerr=%x\n", | ||
276 | dma_stat, ((dma_stat&7)!=4), ((dma_stat&2)==2)); | ||
277 | |||
278 | outb(dma_stat|0x1b, dma_base+2); /* clear the INTR & ERROR bits */ | ||
279 | outb(inb(dma_base)&~1, dma_base); /* !! DO THIS HERE !! stop DMA */ | ||
280 | |||
281 | drive->waiting_for_dma = 0; | ||
282 | ide_destroy_dmatable(drive); /* purge DMA mappings */ | ||
283 | |||
284 | return (dma_stat & 7) != 4; /* verify good DMA status */ | ||
285 | } | ||
286 | |||
287 | /* | ||
288 | * sc1200_tuneproc() handles selection/setting of PIO modes | ||
289 | * for both the chipset and drive. | ||
290 | * | ||
291 | * All existing BIOSs for this chipset guarantee that all drives | ||
292 | * will have valid default PIO timings set up before we get here. | ||
293 | */ | ||
294 | static void sc1200_tuneproc (ide_drive_t *drive, byte pio) /* mode=255 means "autotune" */ | ||
295 | { | ||
296 | ide_hwif_t *hwif = HWIF(drive); | ||
297 | unsigned int format; | ||
298 | static byte modes[5] = {XFER_PIO_0, XFER_PIO_1, XFER_PIO_2, XFER_PIO_3, XFER_PIO_4}; | ||
299 | int mode = -1; | ||
300 | |||
301 | switch (pio) { | ||
302 | case 200: mode = XFER_UDMA_0; break; | ||
303 | case 201: mode = XFER_UDMA_1; break; | ||
304 | case 202: mode = XFER_UDMA_2; break; | ||
305 | case 100: mode = XFER_MW_DMA_0; break; | ||
306 | case 101: mode = XFER_MW_DMA_1; break; | ||
307 | case 102: mode = XFER_MW_DMA_2; break; | ||
308 | } | ||
309 | if (mode != -1) { | ||
310 | printk("SC1200: %s: changing (U)DMA mode\n", drive->name); | ||
311 | (void)sc1200_config_dma2(drive, mode); | ||
312 | return; | ||
313 | } | ||
314 | |||
315 | pio = ide_get_best_pio_mode(drive, pio, 4, NULL); | ||
316 | printk("SC1200: %s: setting PIO mode%d\n", drive->name, pio); | ||
317 | if (!sc1200_set_xfer_mode(drive, modes[pio])) { | ||
318 | unsigned int basereg = hwif->channel ? 0x50 : 0x40; | ||
319 | pci_read_config_dword (hwif->pci_dev, basereg+4, &format); | ||
320 | format = (format >> 31) & 1; | ||
321 | if (format) | ||
322 | format += sc1200_get_pci_clock(); | ||
323 | pci_write_config_dword(hwif->pci_dev, basereg + (drive->select.b.unit << 3), sc1200_pio_timings[format][pio]); | ||
324 | } | ||
325 | } | ||
326 | |||
327 | static ide_hwif_t *lookup_pci_dev (ide_hwif_t *prev, struct pci_dev *dev) | ||
328 | { | ||
329 | int h; | ||
330 | |||
331 | for (h = 0; h < MAX_HWIFS; h++) { | ||
332 | ide_hwif_t *hwif = &ide_hwifs[h]; | ||
333 | if (prev) { | ||
334 | if (hwif == prev) | ||
335 | prev = NULL; // found previous, now look for next match | ||
336 | } else { | ||
337 | if (hwif && hwif->pci_dev == dev) | ||
338 | return hwif; // found next match | ||
339 | } | ||
340 | } | ||
341 | return NULL; // not found | ||
342 | } | ||
343 | |||
344 | typedef struct sc1200_saved_state_s { | ||
345 | __u32 regs[4]; | ||
346 | } sc1200_saved_state_t; | ||
347 | |||
348 | |||
349 | static int sc1200_suspend (struct pci_dev *dev, u32 state) | ||
350 | { | ||
351 | ide_hwif_t *hwif = NULL; | ||
352 | |||
353 | printk("SC1200: suspend(%u)\n", state); | ||
354 | |||
355 | if (state == 0) { | ||
356 | // we only save state when going from full power to less | ||
357 | |||
358 | // | ||
359 | // Loop over all interfaces that are part of this PCI device: | ||
360 | // | ||
361 | while ((hwif = lookup_pci_dev(hwif, dev)) != NULL) { | ||
362 | sc1200_saved_state_t *ss; | ||
363 | unsigned int basereg, r; | ||
364 | // | ||
365 | // allocate a permanent save area, if not already allocated | ||
366 | // | ||
367 | ss = (sc1200_saved_state_t *)hwif->config_data; | ||
368 | if (ss == NULL) { | ||
369 | ss = kmalloc(sizeof(sc1200_saved_state_t), GFP_KERNEL); | ||
370 | if (ss == NULL) | ||
371 | return -ENOMEM; | ||
372 | hwif->config_data = (unsigned long)ss; | ||
373 | } | ||
374 | ss = (sc1200_saved_state_t *)hwif->config_data; | ||
375 | // | ||
376 | // Save timing registers: this may be unnecessary if | ||
377 | // BIOS also does it | ||
378 | // | ||
379 | basereg = hwif->channel ? 0x50 : 0x40; | ||
380 | for (r = 0; r < 4; ++r) { | ||
381 | pci_read_config_dword (hwif->pci_dev, basereg + (r<<2), &ss->regs[r]); | ||
382 | } | ||
383 | } | ||
384 | } | ||
385 | |||
386 | /* You don't need to iterate over disks -- sysfs should have done that for you already */ | ||
387 | |||
388 | pci_disable_device(dev); | ||
389 | pci_set_power_state(dev,state); | ||
390 | dev->current_state = state; | ||
391 | return 0; | ||
392 | } | ||
393 | |||
394 | static int sc1200_resume (struct pci_dev *dev) | ||
395 | { | ||
396 | ide_hwif_t *hwif = NULL; | ||
397 | |||
398 | printk("SC1200: resume\n"); | ||
399 | pci_set_power_state(dev,0); // bring chip back from sleep state | ||
400 | dev->current_state = 0; | ||
401 | pci_enable_device(dev); | ||
402 | // | ||
403 | // loop over all interfaces that are part of this pci device: | ||
404 | // | ||
405 | while ((hwif = lookup_pci_dev(hwif, dev)) != NULL) { | ||
406 | unsigned int basereg, r, d, format; | ||
407 | sc1200_saved_state_t *ss = (sc1200_saved_state_t *)hwif->config_data; | ||
408 | printk("%s: SC1200: resume\n", hwif->name); | ||
409 | |||
410 | // | ||
411 | // Restore timing registers: this may be unnecessary if BIOS also does it | ||
412 | // | ||
413 | basereg = hwif->channel ? 0x50 : 0x40; | ||
414 | if (ss != NULL) { | ||
415 | for (r = 0; r < 4; ++r) { | ||
416 | pci_write_config_dword(hwif->pci_dev, basereg + (r<<2), ss->regs[r]); | ||
417 | } | ||
418 | } | ||
419 | // | ||
420 | // Re-program drive PIO modes | ||
421 | // | ||
422 | pci_read_config_dword(hwif->pci_dev, basereg+4, &format); | ||
423 | format = (format >> 31) & 1; | ||
424 | if (format) | ||
425 | format += sc1200_get_pci_clock(); | ||
426 | for (d = 0; d < 2; ++d) { | ||
427 | ide_drive_t *drive = &(hwif->drives[d]); | ||
428 | if (drive->present) { | ||
429 | unsigned int pio, timings; | ||
430 | pci_read_config_dword(hwif->pci_dev, basereg+(drive->select.b.unit << 3), &timings); | ||
431 | for (pio = 0; pio <= 4; ++pio) { | ||
432 | if (sc1200_pio_timings[format][pio] == timings) | ||
433 | break; | ||
434 | } | ||
435 | if (pio > 4) | ||
436 | pio = 255; /* autotune */ | ||
437 | (void)sc1200_tuneproc(drive, pio); | ||
438 | } | ||
439 | } | ||
440 | // | ||
441 | // Re-program drive DMA modes | ||
442 | // | ||
443 | for (d = 0; d < MAX_DRIVES; ++d) { | ||
444 | ide_drive_t *drive = &(hwif->drives[d]); | ||
445 | if (drive->present && !__ide_dma_bad_drive(drive)) { | ||
446 | int was_using_dma = drive->using_dma; | ||
447 | hwif->ide_dma_off_quietly(drive); | ||
448 | sc1200_config_dma(drive); | ||
449 | if (!was_using_dma && drive->using_dma) { | ||
450 | hwif->ide_dma_off_quietly(drive); | ||
451 | } | ||
452 | } | ||
453 | } | ||
454 | } | ||
455 | return 0; | ||
456 | } | ||
457 | |||
458 | /* | ||
459 | * This gets invoked by the IDE driver once for each channel, | ||
460 | * and performs channel-specific pre-initialization before drive probing. | ||
461 | */ | ||
462 | static void __init init_hwif_sc1200 (ide_hwif_t *hwif) | ||
463 | { | ||
464 | if (hwif->mate) | ||
465 | hwif->serialized = hwif->mate->serialized = 1; | ||
466 | hwif->autodma = 0; | ||
467 | if (hwif->dma_base) { | ||
468 | hwif->ide_dma_check = &sc1200_config_dma; | ||
469 | hwif->ide_dma_end = &sc1200_ide_dma_end; | ||
470 | if (!noautodma) | ||
471 | hwif->autodma = 1; | ||
472 | hwif->tuneproc = &sc1200_tuneproc; | ||
473 | } | ||
474 | hwif->atapi_dma = 1; | ||
475 | hwif->ultra_mask = 0x07; | ||
476 | hwif->mwdma_mask = 0x07; | ||
477 | |||
478 | hwif->drives[0].autodma = hwif->autodma; | ||
479 | hwif->drives[1].autodma = hwif->autodma; | ||
480 | } | ||
481 | |||
482 | static ide_pci_device_t sc1200_chipset __devinitdata = { | ||
483 | .name = "SC1200", | ||
484 | .init_hwif = init_hwif_sc1200, | ||
485 | .channels = 2, | ||
486 | .autodma = AUTODMA, | ||
487 | .bootable = ON_BOARD, | ||
488 | }; | ||
489 | |||
490 | static int __devinit sc1200_init_one(struct pci_dev *dev, const struct pci_device_id *id) | ||
491 | { | ||
492 | return ide_setup_pci_device(dev, &sc1200_chipset); | ||
493 | } | ||
494 | |||
495 | static struct pci_device_id sc1200_pci_tbl[] = { | ||
496 | { PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_SCx200_IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, | ||
497 | { 0, }, | ||
498 | }; | ||
499 | MODULE_DEVICE_TABLE(pci, sc1200_pci_tbl); | ||
500 | |||
501 | static struct pci_driver driver = { | ||
502 | .name = "SC1200_IDE", | ||
503 | .id_table = sc1200_pci_tbl, | ||
504 | .probe = sc1200_init_one, | ||
505 | .suspend = sc1200_suspend, | ||
506 | .resume = sc1200_resume, | ||
507 | }; | ||
508 | |||
509 | static int sc1200_ide_init(void) | ||
510 | { | ||
511 | return ide_pci_register_driver(&driver); | ||
512 | } | ||
513 | |||
514 | module_init(sc1200_ide_init); | ||
515 | |||
516 | MODULE_AUTHOR("Mark Lord"); | ||
517 | MODULE_DESCRIPTION("PCI driver module for NS SC1200 IDE"); | ||
518 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/ide/pci/serverworks.c b/drivers/ide/pci/serverworks.c new file mode 100644 index 000000000000..82a1103b2413 --- /dev/null +++ b/drivers/ide/pci/serverworks.c | |||
@@ -0,0 +1,675 @@ | |||
1 | /* | ||
2 | * linux/drivers/ide/pci/serverworks.c Version 0.8 25 Ebr 2003 | ||
3 | * | ||
4 | * Copyright (C) 1998-2000 Michel Aubry | ||
5 | * Copyright (C) 1998-2000 Andrzej Krzysztofowicz | ||
6 | * Copyright (C) 1998-2000 Andre Hedrick <andre@linux-ide.org> | ||
7 | * Portions copyright (c) 2001 Sun Microsystems | ||
8 | * | ||
9 | * | ||
10 | * RCC/ServerWorks IDE driver for Linux | ||
11 | * | ||
12 | * OSB4: `Open South Bridge' IDE Interface (fn 1) | ||
13 | * supports UDMA mode 2 (33 MB/s) | ||
14 | * | ||
15 | * CSB5: `Champion South Bridge' IDE Interface (fn 1) | ||
16 | * all revisions support UDMA mode 4 (66 MB/s) | ||
17 | * revision A2.0 and up support UDMA mode 5 (100 MB/s) | ||
18 | * | ||
19 | * *** The CSB5 does not provide ANY register *** | ||
20 | * *** to detect 80-conductor cable presence. *** | ||
21 | * | ||
22 | * CSB6: `Champion South Bridge' IDE Interface (optional: third channel) | ||
23 | * | ||
24 | * Documentation: | ||
25 | * Available under NDA only. Errata info very hard to get. | ||
26 | * | ||
27 | */ | ||
28 | |||
29 | #include <linux/config.h> | ||
30 | #include <linux/types.h> | ||
31 | #include <linux/module.h> | ||
32 | #include <linux/kernel.h> | ||
33 | #include <linux/ioport.h> | ||
34 | #include <linux/pci.h> | ||
35 | #include <linux/hdreg.h> | ||
36 | #include <linux/ide.h> | ||
37 | #include <linux/init.h> | ||
38 | #include <linux/delay.h> | ||
39 | |||
40 | #include <asm/io.h> | ||
41 | |||
42 | #define SVWKS_CSB5_REVISION_NEW 0x92 /* min PCI_REVISION_ID for UDMA5 (A2.0) */ | ||
43 | #define SVWKS_CSB6_REVISION 0xa0 /* min PCI_REVISION_ID for UDMA4 (A1.0) */ | ||
44 | |||
45 | /* Seagate Barracuda ATA IV Family drives in UDMA mode 5 | ||
46 | * can overrun their FIFOs when used with the CSB5 */ | ||
47 | static const char *svwks_bad_ata100[] = { | ||
48 | "ST320011A", | ||
49 | "ST340016A", | ||
50 | "ST360021A", | ||
51 | "ST380021A", | ||
52 | NULL | ||
53 | }; | ||
54 | |||
55 | static u8 svwks_revision = 0; | ||
56 | static struct pci_dev *isa_dev; | ||
57 | |||
58 | static int check_in_drive_lists (ide_drive_t *drive, const char **list) | ||
59 | { | ||
60 | while (*list) | ||
61 | if (!strcmp(*list++, drive->id->model)) | ||
62 | return 1; | ||
63 | return 0; | ||
64 | } | ||
65 | |||
66 | static u8 svwks_ratemask (ide_drive_t *drive) | ||
67 | { | ||
68 | struct pci_dev *dev = HWIF(drive)->pci_dev; | ||
69 | u8 mode; | ||
70 | |||
71 | if (!svwks_revision) | ||
72 | pci_read_config_byte(dev, PCI_REVISION_ID, &svwks_revision); | ||
73 | |||
74 | if (dev->device == PCI_DEVICE_ID_SERVERWORKS_OSB4IDE) { | ||
75 | u32 reg = 0; | ||
76 | if (isa_dev) | ||
77 | pci_read_config_dword(isa_dev, 0x64, ®); | ||
78 | |||
79 | /* | ||
80 | * Don't enable UDMA on disk devices for the moment | ||
81 | */ | ||
82 | if(drive->media == ide_disk) | ||
83 | return 0; | ||
84 | /* Check the OSB4 DMA33 enable bit */ | ||
85 | return ((reg & 0x00004000) == 0x00004000) ? 1 : 0; | ||
86 | } else if (svwks_revision < SVWKS_CSB5_REVISION_NEW) { | ||
87 | return 1; | ||
88 | } else if (svwks_revision >= SVWKS_CSB5_REVISION_NEW) { | ||
89 | u8 btr = 0; | ||
90 | pci_read_config_byte(dev, 0x5A, &btr); | ||
91 | mode = btr & 0x3; | ||
92 | if (!eighty_ninty_three(drive)) | ||
93 | mode = min(mode, (u8)1); | ||
94 | /* If someone decides to do UDMA133 on CSB5 the same | ||
95 | issue will bite so be inclusive */ | ||
96 | if (mode > 2 && check_in_drive_lists(drive, svwks_bad_ata100)) | ||
97 | mode = 2; | ||
98 | } | ||
99 | if (((dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE) || | ||
100 | (dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2)) && | ||
101 | (!(PCI_FUNC(dev->devfn) & 1))) | ||
102 | mode = 2; | ||
103 | return mode; | ||
104 | } | ||
105 | |||
106 | static u8 svwks_csb_check (struct pci_dev *dev) | ||
107 | { | ||
108 | switch (dev->device) { | ||
109 | case PCI_DEVICE_ID_SERVERWORKS_CSB5IDE: | ||
110 | case PCI_DEVICE_ID_SERVERWORKS_CSB6IDE: | ||
111 | case PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2: | ||
112 | return 1; | ||
113 | default: | ||
114 | break; | ||
115 | } | ||
116 | return 0; | ||
117 | } | ||
118 | static int svwks_tune_chipset (ide_drive_t *drive, u8 xferspeed) | ||
119 | { | ||
120 | u8 udma_modes[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 }; | ||
121 | u8 dma_modes[] = { 0x77, 0x21, 0x20 }; | ||
122 | u8 pio_modes[] = { 0x5d, 0x47, 0x34, 0x22, 0x20 }; | ||
123 | u8 drive_pci[] = { 0x41, 0x40, 0x43, 0x42 }; | ||
124 | u8 drive_pci2[] = { 0x45, 0x44, 0x47, 0x46 }; | ||
125 | |||
126 | ide_hwif_t *hwif = HWIF(drive); | ||
127 | struct pci_dev *dev = hwif->pci_dev; | ||
128 | u8 speed; | ||
129 | u8 pio = ide_get_best_pio_mode(drive, 255, 5, NULL); | ||
130 | u8 unit = (drive->select.b.unit & 0x01); | ||
131 | u8 csb5 = svwks_csb_check(dev); | ||
132 | u8 ultra_enable = 0, ultra_timing = 0; | ||
133 | u8 dma_timing = 0, pio_timing = 0; | ||
134 | u16 csb5_pio = 0; | ||
135 | |||
136 | if (xferspeed == 255) /* PIO auto-tuning */ | ||
137 | speed = XFER_PIO_0 + pio; | ||
138 | else | ||
139 | speed = ide_rate_filter(svwks_ratemask(drive), xferspeed); | ||
140 | |||
141 | /* If we are about to put a disk into UDMA mode we screwed up. | ||
142 | Our code assumes we never _ever_ do this on an OSB4 */ | ||
143 | |||
144 | if(dev->device == PCI_DEVICE_ID_SERVERWORKS_OSB4 && | ||
145 | drive->media == ide_disk && speed >= XFER_UDMA_0) | ||
146 | BUG(); | ||
147 | |||
148 | pci_read_config_byte(dev, drive_pci[drive->dn], &pio_timing); | ||
149 | pci_read_config_byte(dev, drive_pci2[drive->dn], &dma_timing); | ||
150 | pci_read_config_byte(dev, (0x56|hwif->channel), &ultra_timing); | ||
151 | pci_read_config_word(dev, 0x4A, &csb5_pio); | ||
152 | pci_read_config_byte(dev, 0x54, &ultra_enable); | ||
153 | |||
154 | /* Per Specified Design by OEM, and ASIC Architect */ | ||
155 | if ((dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE) || | ||
156 | (dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2)) { | ||
157 | if (!drive->init_speed) { | ||
158 | u8 dma_stat = hwif->INB(hwif->dma_status); | ||
159 | |||
160 | dma_pio: | ||
161 | if (((ultra_enable << (7-drive->dn) & 0x80) == 0x80) && | ||
162 | ((dma_stat & (1<<(5+unit))) == (1<<(5+unit)))) { | ||
163 | drive->current_speed = drive->init_speed = XFER_UDMA_0 + udma_modes[(ultra_timing >> (4*unit)) & ~(0xF0)]; | ||
164 | return 0; | ||
165 | } else if ((dma_timing) && | ||
166 | ((dma_stat&(1<<(5+unit)))==(1<<(5+unit)))) { | ||
167 | u8 dmaspeed = dma_timing; | ||
168 | |||
169 | dma_timing &= ~0xFF; | ||
170 | if ((dmaspeed & 0x20) == 0x20) | ||
171 | dmaspeed = XFER_MW_DMA_2; | ||
172 | else if ((dmaspeed & 0x21) == 0x21) | ||
173 | dmaspeed = XFER_MW_DMA_1; | ||
174 | else if ((dmaspeed & 0x77) == 0x77) | ||
175 | dmaspeed = XFER_MW_DMA_0; | ||
176 | else | ||
177 | goto dma_pio; | ||
178 | drive->current_speed = drive->init_speed = dmaspeed; | ||
179 | return 0; | ||
180 | } else if (pio_timing) { | ||
181 | u8 piospeed = pio_timing; | ||
182 | |||
183 | pio_timing &= ~0xFF; | ||
184 | if ((piospeed & 0x20) == 0x20) | ||
185 | piospeed = XFER_PIO_4; | ||
186 | else if ((piospeed & 0x22) == 0x22) | ||
187 | piospeed = XFER_PIO_3; | ||
188 | else if ((piospeed & 0x34) == 0x34) | ||
189 | piospeed = XFER_PIO_2; | ||
190 | else if ((piospeed & 0x47) == 0x47) | ||
191 | piospeed = XFER_PIO_1; | ||
192 | else if ((piospeed & 0x5d) == 0x5d) | ||
193 | piospeed = XFER_PIO_0; | ||
194 | else | ||
195 | goto oem_setup_failed; | ||
196 | drive->current_speed = drive->init_speed = piospeed; | ||
197 | return 0; | ||
198 | } | ||
199 | } | ||
200 | } | ||
201 | |||
202 | oem_setup_failed: | ||
203 | |||
204 | pio_timing &= ~0xFF; | ||
205 | dma_timing &= ~0xFF; | ||
206 | ultra_timing &= ~(0x0F << (4*unit)); | ||
207 | ultra_enable &= ~(0x01 << drive->dn); | ||
208 | csb5_pio &= ~(0x0F << (4*drive->dn)); | ||
209 | |||
210 | switch(speed) { | ||
211 | case XFER_PIO_4: | ||
212 | case XFER_PIO_3: | ||
213 | case XFER_PIO_2: | ||
214 | case XFER_PIO_1: | ||
215 | case XFER_PIO_0: | ||
216 | pio_timing |= pio_modes[speed - XFER_PIO_0]; | ||
217 | csb5_pio |= ((speed - XFER_PIO_0) << (4*drive->dn)); | ||
218 | break; | ||
219 | |||
220 | case XFER_MW_DMA_2: | ||
221 | case XFER_MW_DMA_1: | ||
222 | case XFER_MW_DMA_0: | ||
223 | pio_timing |= pio_modes[pio]; | ||
224 | csb5_pio |= (pio << (4*drive->dn)); | ||
225 | dma_timing |= dma_modes[speed - XFER_MW_DMA_0]; | ||
226 | break; | ||
227 | |||
228 | case XFER_UDMA_5: | ||
229 | case XFER_UDMA_4: | ||
230 | case XFER_UDMA_3: | ||
231 | case XFER_UDMA_2: | ||
232 | case XFER_UDMA_1: | ||
233 | case XFER_UDMA_0: | ||
234 | pio_timing |= pio_modes[pio]; | ||
235 | csb5_pio |= (pio << (4*drive->dn)); | ||
236 | dma_timing |= dma_modes[2]; | ||
237 | ultra_timing |= ((udma_modes[speed - XFER_UDMA_0]) << (4*unit)); | ||
238 | ultra_enable |= (0x01 << drive->dn); | ||
239 | default: | ||
240 | break; | ||
241 | } | ||
242 | |||
243 | pci_write_config_byte(dev, drive_pci[drive->dn], pio_timing); | ||
244 | if (csb5) | ||
245 | pci_write_config_word(dev, 0x4A, csb5_pio); | ||
246 | |||
247 | pci_write_config_byte(dev, drive_pci2[drive->dn], dma_timing); | ||
248 | pci_write_config_byte(dev, (0x56|hwif->channel), ultra_timing); | ||
249 | pci_write_config_byte(dev, 0x54, ultra_enable); | ||
250 | |||
251 | return (ide_config_drive_speed(drive, speed)); | ||
252 | } | ||
253 | |||
254 | static void config_chipset_for_pio (ide_drive_t *drive) | ||
255 | { | ||
256 | u16 eide_pio_timing[6] = {960, 480, 240, 180, 120, 90}; | ||
257 | u16 xfer_pio = drive->id->eide_pio_modes; | ||
258 | u8 timing, speed, pio; | ||
259 | |||
260 | pio = ide_get_best_pio_mode(drive, 255, 5, NULL); | ||
261 | |||
262 | if (xfer_pio > 4) | ||
263 | xfer_pio = 0; | ||
264 | |||
265 | if (drive->id->eide_pio_iordy > 0) | ||
266 | for (xfer_pio = 5; | ||
267 | xfer_pio>0 && | ||
268 | drive->id->eide_pio_iordy>eide_pio_timing[xfer_pio]; | ||
269 | xfer_pio--); | ||
270 | else | ||
271 | xfer_pio = (drive->id->eide_pio_modes & 4) ? 0x05 : | ||
272 | (drive->id->eide_pio_modes & 2) ? 0x04 : | ||
273 | (drive->id->eide_pio_modes & 1) ? 0x03 : | ||
274 | (drive->id->tPIO & 2) ? 0x02 : | ||
275 | (drive->id->tPIO & 1) ? 0x01 : xfer_pio; | ||
276 | |||
277 | timing = (xfer_pio >= pio) ? xfer_pio : pio; | ||
278 | |||
279 | switch(timing) { | ||
280 | case 4: speed = XFER_PIO_4;break; | ||
281 | case 3: speed = XFER_PIO_3;break; | ||
282 | case 2: speed = XFER_PIO_2;break; | ||
283 | case 1: speed = XFER_PIO_1;break; | ||
284 | default: | ||
285 | speed = (!drive->id->tPIO) ? XFER_PIO_0 : XFER_PIO_SLOW; | ||
286 | break; | ||
287 | } | ||
288 | (void) svwks_tune_chipset(drive, speed); | ||
289 | drive->current_speed = speed; | ||
290 | } | ||
291 | |||
292 | static void svwks_tune_drive (ide_drive_t *drive, u8 pio) | ||
293 | { | ||
294 | if(pio == 255) | ||
295 | (void) svwks_tune_chipset(drive, 255); | ||
296 | else | ||
297 | (void) svwks_tune_chipset(drive, (XFER_PIO_0 + pio)); | ||
298 | } | ||
299 | |||
300 | static int config_chipset_for_dma (ide_drive_t *drive) | ||
301 | { | ||
302 | u8 speed = ide_dma_speed(drive, svwks_ratemask(drive)); | ||
303 | |||
304 | if (!(speed)) | ||
305 | speed = XFER_PIO_0 + ide_get_best_pio_mode(drive, 255, 5, NULL); | ||
306 | |||
307 | (void) svwks_tune_chipset(drive, speed); | ||
308 | return ide_dma_enable(drive); | ||
309 | } | ||
310 | |||
311 | static int svwks_config_drive_xfer_rate (ide_drive_t *drive) | ||
312 | { | ||
313 | ide_hwif_t *hwif = HWIF(drive); | ||
314 | struct hd_driveid *id = drive->id; | ||
315 | |||
316 | drive->init_speed = 0; | ||
317 | |||
318 | if ((id->capability & 1) && drive->autodma) { | ||
319 | |||
320 | if (ide_use_dma(drive)) { | ||
321 | if (config_chipset_for_dma(drive)) | ||
322 | return hwif->ide_dma_on(drive); | ||
323 | } | ||
324 | |||
325 | goto fast_ata_pio; | ||
326 | |||
327 | } else if ((id->capability & 8) || (id->field_valid & 2)) { | ||
328 | fast_ata_pio: | ||
329 | config_chipset_for_pio(drive); | ||
330 | // hwif->tuneproc(drive, 5); | ||
331 | return hwif->ide_dma_off_quietly(drive); | ||
332 | } | ||
333 | /* IORDY not supported */ | ||
334 | return 0; | ||
335 | } | ||
336 | |||
337 | /* This can go soon */ | ||
338 | |||
339 | static int svwks_ide_dma_end (ide_drive_t *drive) | ||
340 | { | ||
341 | return __ide_dma_end(drive); | ||
342 | } | ||
343 | |||
344 | static unsigned int __devinit init_chipset_svwks (struct pci_dev *dev, const char *name) | ||
345 | { | ||
346 | unsigned int reg; | ||
347 | u8 btr; | ||
348 | |||
349 | /* save revision id to determine DMA capability */ | ||
350 | pci_read_config_byte(dev, PCI_REVISION_ID, &svwks_revision); | ||
351 | |||
352 | /* force Master Latency Timer value to 64 PCICLKs */ | ||
353 | pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x40); | ||
354 | |||
355 | /* OSB4 : South Bridge and IDE */ | ||
356 | if (dev->device == PCI_DEVICE_ID_SERVERWORKS_OSB4IDE) { | ||
357 | isa_dev = pci_find_device(PCI_VENDOR_ID_SERVERWORKS, | ||
358 | PCI_DEVICE_ID_SERVERWORKS_OSB4, NULL); | ||
359 | if (isa_dev) { | ||
360 | pci_read_config_dword(isa_dev, 0x64, ®); | ||
361 | reg &= ~0x00002000; /* disable 600ns interrupt mask */ | ||
362 | if(!(reg & 0x00004000)) | ||
363 | printk(KERN_DEBUG "%s: UDMA not BIOS enabled.\n", name); | ||
364 | reg |= 0x00004000; /* enable UDMA/33 support */ | ||
365 | pci_write_config_dword(isa_dev, 0x64, reg); | ||
366 | } | ||
367 | } | ||
368 | |||
369 | /* setup CSB5/CSB6 : South Bridge and IDE option RAID */ | ||
370 | else if ((dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB5IDE) || | ||
371 | (dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE) || | ||
372 | (dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2)) { | ||
373 | |||
374 | /* Third Channel Test */ | ||
375 | if (!(PCI_FUNC(dev->devfn) & 1)) { | ||
376 | struct pci_dev * findev = NULL; | ||
377 | u32 reg4c = 0; | ||
378 | findev = pci_find_device(PCI_VENDOR_ID_SERVERWORKS, | ||
379 | PCI_DEVICE_ID_SERVERWORKS_CSB5, NULL); | ||
380 | if (findev) { | ||
381 | pci_read_config_dword(findev, 0x4C, ®4c); | ||
382 | reg4c &= ~0x000007FF; | ||
383 | reg4c |= 0x00000040; | ||
384 | reg4c |= 0x00000020; | ||
385 | pci_write_config_dword(findev, 0x4C, reg4c); | ||
386 | } | ||
387 | outb_p(0x06, 0x0c00); | ||
388 | dev->irq = inb_p(0x0c01); | ||
389 | #if 0 | ||
390 | printk("%s: device class (0x%04x)\n", | ||
391 | name, dev->class); | ||
392 | if ((dev->class >> 8) != PCI_CLASS_STORAGE_IDE) { | ||
393 | dev->class &= ~0x000F0F00; | ||
394 | // dev->class |= ~0x00000400; | ||
395 | dev->class |= ~0x00010100; | ||
396 | /**/ | ||
397 | } | ||
398 | #endif | ||
399 | } else { | ||
400 | struct pci_dev * findev = NULL; | ||
401 | u8 reg41 = 0; | ||
402 | |||
403 | findev = pci_find_device(PCI_VENDOR_ID_SERVERWORKS, | ||
404 | PCI_DEVICE_ID_SERVERWORKS_CSB6, NULL); | ||
405 | if (findev) { | ||
406 | pci_read_config_byte(findev, 0x41, ®41); | ||
407 | reg41 &= ~0x40; | ||
408 | pci_write_config_byte(findev, 0x41, reg41); | ||
409 | } | ||
410 | /* | ||
411 | * This is a device pin issue on CSB6. | ||
412 | * Since there will be a future raid mode, | ||
413 | * early versions of the chipset require the | ||
414 | * interrupt pin to be set, and it is a compatibility | ||
415 | * mode issue. | ||
416 | */ | ||
417 | if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE) | ||
418 | dev->irq = 0; | ||
419 | } | ||
420 | // pci_read_config_dword(dev, 0x40, &pioreg) | ||
421 | // pci_write_config_dword(dev, 0x40, 0x99999999); | ||
422 | // pci_read_config_dword(dev, 0x44, &dmareg); | ||
423 | // pci_write_config_dword(dev, 0x44, 0xFFFFFFFF); | ||
424 | /* setup the UDMA Control register | ||
425 | * | ||
426 | * 1. clear bit 6 to enable DMA | ||
427 | * 2. enable DMA modes with bits 0-1 | ||
428 | * 00 : legacy | ||
429 | * 01 : udma2 | ||
430 | * 10 : udma2/udma4 | ||
431 | * 11 : udma2/udma4/udma5 | ||
432 | */ | ||
433 | pci_read_config_byte(dev, 0x5A, &btr); | ||
434 | btr &= ~0x40; | ||
435 | if (!(PCI_FUNC(dev->devfn) & 1)) | ||
436 | btr |= 0x2; | ||
437 | else | ||
438 | btr |= (svwks_revision >= SVWKS_CSB5_REVISION_NEW) ? 0x3 : 0x2; | ||
439 | pci_write_config_byte(dev, 0x5A, btr); | ||
440 | } | ||
441 | |||
442 | return (dev->irq) ? dev->irq : 0; | ||
443 | } | ||
444 | |||
445 | static unsigned int __init ata66_svwks_svwks (ide_hwif_t *hwif) | ||
446 | { | ||
447 | return 1; | ||
448 | } | ||
449 | |||
450 | /* On Dell PowerEdge servers with a CSB5/CSB6, the top two bits | ||
451 | * of the subsystem device ID indicate presence of an 80-pin cable. | ||
452 | * Bit 15 clear = secondary IDE channel does not have 80-pin cable. | ||
453 | * Bit 15 set = secondary IDE channel has 80-pin cable. | ||
454 | * Bit 14 clear = primary IDE channel does not have 80-pin cable. | ||
455 | * Bit 14 set = primary IDE channel has 80-pin cable. | ||
456 | */ | ||
457 | static unsigned int __init ata66_svwks_dell (ide_hwif_t *hwif) | ||
458 | { | ||
459 | struct pci_dev *dev = hwif->pci_dev; | ||
460 | if (dev->subsystem_vendor == PCI_VENDOR_ID_DELL && | ||
461 | dev->vendor == PCI_VENDOR_ID_SERVERWORKS && | ||
462 | (dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB5IDE || | ||
463 | dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE)) | ||
464 | return ((1 << (hwif->channel + 14)) & | ||
465 | dev->subsystem_device) ? 1 : 0; | ||
466 | return 0; | ||
467 | } | ||
468 | |||
469 | /* Sun Cobalt Alpine hardware avoids the 80-pin cable | ||
470 | * detect issue by attaching the drives directly to the board. | ||
471 | * This check follows the Dell precedent (how scary is that?!) | ||
472 | * | ||
473 | * WARNING: this only works on Alpine hardware! | ||
474 | */ | ||
475 | static unsigned int __init ata66_svwks_cobalt (ide_hwif_t *hwif) | ||
476 | { | ||
477 | struct pci_dev *dev = hwif->pci_dev; | ||
478 | if (dev->subsystem_vendor == PCI_VENDOR_ID_SUN && | ||
479 | dev->vendor == PCI_VENDOR_ID_SERVERWORKS && | ||
480 | dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB5IDE) | ||
481 | return ((1 << (hwif->channel + 14)) & | ||
482 | dev->subsystem_device) ? 1 : 0; | ||
483 | return 0; | ||
484 | } | ||
485 | |||
486 | static unsigned int __init ata66_svwks (ide_hwif_t *hwif) | ||
487 | { | ||
488 | struct pci_dev *dev = hwif->pci_dev; | ||
489 | |||
490 | /* Per Specified Design by OEM, and ASIC Architect */ | ||
491 | if ((dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE) || | ||
492 | (dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2)) | ||
493 | return 1; | ||
494 | |||
495 | /* Server Works */ | ||
496 | if (dev->subsystem_vendor == PCI_VENDOR_ID_SERVERWORKS) | ||
497 | return ata66_svwks_svwks (hwif); | ||
498 | |||
499 | /* Dell PowerEdge */ | ||
500 | if (dev->subsystem_vendor == PCI_VENDOR_ID_DELL) | ||
501 | return ata66_svwks_dell (hwif); | ||
502 | |||
503 | /* Cobalt Alpine */ | ||
504 | if (dev->subsystem_vendor == PCI_VENDOR_ID_SUN) | ||
505 | return ata66_svwks_cobalt (hwif); | ||
506 | |||
507 | return 0; | ||
508 | } | ||
509 | |||
510 | #undef CAN_SW_DMA | ||
511 | static void __devinit init_hwif_svwks (ide_hwif_t *hwif) | ||
512 | { | ||
513 | u8 dma_stat = 0; | ||
514 | |||
515 | if (!hwif->irq) | ||
516 | hwif->irq = hwif->channel ? 15 : 14; | ||
517 | |||
518 | hwif->tuneproc = &svwks_tune_drive; | ||
519 | hwif->speedproc = &svwks_tune_chipset; | ||
520 | |||
521 | hwif->atapi_dma = 1; | ||
522 | |||
523 | if (hwif->pci_dev->device != PCI_DEVICE_ID_SERVERWORKS_OSB4IDE) | ||
524 | hwif->ultra_mask = 0x3f; | ||
525 | |||
526 | hwif->mwdma_mask = 0x07; | ||
527 | #ifdef CAN_SW_DMA | ||
528 | hwif->swdma_mask = 0x07; | ||
529 | #endif /* CAN_SW_DMA */ | ||
530 | |||
531 | hwif->autodma = 0; | ||
532 | |||
533 | if (!hwif->dma_base) { | ||
534 | hwif->drives[0].autotune = 1; | ||
535 | hwif->drives[1].autotune = 1; | ||
536 | return; | ||
537 | } | ||
538 | |||
539 | hwif->ide_dma_check = &svwks_config_drive_xfer_rate; | ||
540 | if (hwif->pci_dev->device == PCI_DEVICE_ID_SERVERWORKS_OSB4IDE) | ||
541 | hwif->ide_dma_end = &svwks_ide_dma_end; | ||
542 | else if (!(hwif->udma_four)) | ||
543 | hwif->udma_four = ata66_svwks(hwif); | ||
544 | if (!noautodma) | ||
545 | hwif->autodma = 1; | ||
546 | |||
547 | dma_stat = hwif->INB(hwif->dma_status); | ||
548 | hwif->drives[0].autodma = (dma_stat & 0x20); | ||
549 | hwif->drives[1].autodma = (dma_stat & 0x40); | ||
550 | hwif->drives[0].autotune = (!(dma_stat & 0x20)); | ||
551 | hwif->drives[1].autotune = (!(dma_stat & 0x40)); | ||
552 | // hwif->drives[0].autodma = hwif->autodma; | ||
553 | // hwif->drives[1].autodma = hwif->autodma; | ||
554 | } | ||
555 | |||
556 | /* | ||
557 | * We allow the BM-DMA driver to only work on enabled interfaces. | ||
558 | */ | ||
559 | static void __devinit init_dma_svwks (ide_hwif_t *hwif, unsigned long dmabase) | ||
560 | { | ||
561 | struct pci_dev *dev = hwif->pci_dev; | ||
562 | |||
563 | if (((dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE) || | ||
564 | (dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2)) && | ||
565 | (!(PCI_FUNC(dev->devfn) & 1)) && (hwif->channel)) | ||
566 | return; | ||
567 | |||
568 | ide_setup_dma(hwif, dmabase, 8); | ||
569 | } | ||
570 | |||
571 | static int __devinit init_setup_svwks (struct pci_dev *dev, ide_pci_device_t *d) | ||
572 | { | ||
573 | return ide_setup_pci_device(dev, d); | ||
574 | } | ||
575 | |||
576 | static int __init init_setup_csb6 (struct pci_dev *dev, ide_pci_device_t *d) | ||
577 | { | ||
578 | if (!(PCI_FUNC(dev->devfn) & 1)) { | ||
579 | d->bootable = NEVER_BOARD; | ||
580 | if (dev->resource[0].start == 0x01f1) | ||
581 | d->bootable = ON_BOARD; | ||
582 | } | ||
583 | #if 0 | ||
584 | if ((IDE_PCI_DEVID_EQ(d->devid, DEVID_CSB6) && | ||
585 | (!(PCI_FUNC(dev->devfn) & 1))) | ||
586 | d->autodma = AUTODMA; | ||
587 | #endif | ||
588 | |||
589 | d->channels = ((dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE || | ||
590 | dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2) && | ||
591 | (!(PCI_FUNC(dev->devfn) & 1))) ? 1 : 2; | ||
592 | |||
593 | return ide_setup_pci_device(dev, d); | ||
594 | } | ||
595 | |||
596 | static ide_pci_device_t serverworks_chipsets[] __devinitdata = { | ||
597 | { /* 0 */ | ||
598 | .name = "SvrWks OSB4", | ||
599 | .init_setup = init_setup_svwks, | ||
600 | .init_chipset = init_chipset_svwks, | ||
601 | .init_hwif = init_hwif_svwks, | ||
602 | .channels = 2, | ||
603 | .autodma = AUTODMA, | ||
604 | .bootable = ON_BOARD, | ||
605 | },{ /* 1 */ | ||
606 | .name = "SvrWks CSB5", | ||
607 | .init_setup = init_setup_svwks, | ||
608 | .init_chipset = init_chipset_svwks, | ||
609 | .init_hwif = init_hwif_svwks, | ||
610 | .init_dma = init_dma_svwks, | ||
611 | .channels = 2, | ||
612 | .autodma = AUTODMA, | ||
613 | .bootable = ON_BOARD, | ||
614 | },{ /* 2 */ | ||
615 | .name = "SvrWks CSB6", | ||
616 | .init_setup = init_setup_csb6, | ||
617 | .init_chipset = init_chipset_svwks, | ||
618 | .init_hwif = init_hwif_svwks, | ||
619 | .init_dma = init_dma_svwks, | ||
620 | .channels = 2, | ||
621 | .autodma = AUTODMA, | ||
622 | .bootable = ON_BOARD, | ||
623 | },{ /* 3 */ | ||
624 | .name = "SvrWks CSB6", | ||
625 | .init_setup = init_setup_csb6, | ||
626 | .init_chipset = init_chipset_svwks, | ||
627 | .init_hwif = init_hwif_svwks, | ||
628 | .init_dma = init_dma_svwks, | ||
629 | .channels = 1, /* 2 */ | ||
630 | .autodma = AUTODMA, | ||
631 | .bootable = ON_BOARD, | ||
632 | } | ||
633 | }; | ||
634 | |||
635 | /** | ||
636 | * svwks_init_one - called when a OSB/CSB is found | ||
637 | * @dev: the svwks device | ||
638 | * @id: the matching pci id | ||
639 | * | ||
640 | * Called when the PCI registration layer (or the IDE initialization) | ||
641 | * finds a device matching our IDE device tables. | ||
642 | */ | ||
643 | |||
644 | static int __devinit svwks_init_one(struct pci_dev *dev, const struct pci_device_id *id) | ||
645 | { | ||
646 | ide_pci_device_t *d = &serverworks_chipsets[id->driver_data]; | ||
647 | |||
648 | return d->init_setup(dev, d); | ||
649 | } | ||
650 | |||
651 | static struct pci_device_id svwks_pci_tbl[] = { | ||
652 | { PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_OSB4IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, | ||
653 | { PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB5IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1}, | ||
654 | { PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB6IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2}, | ||
655 | { PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3}, | ||
656 | { 0, }, | ||
657 | }; | ||
658 | MODULE_DEVICE_TABLE(pci, svwks_pci_tbl); | ||
659 | |||
660 | static struct pci_driver driver = { | ||
661 | .name = "Serverworks_IDE", | ||
662 | .id_table = svwks_pci_tbl, | ||
663 | .probe = svwks_init_one, | ||
664 | }; | ||
665 | |||
666 | static int svwks_ide_init(void) | ||
667 | { | ||
668 | return ide_pci_register_driver(&driver); | ||
669 | } | ||
670 | |||
671 | module_init(svwks_ide_init); | ||
672 | |||
673 | MODULE_AUTHOR("Michael Aubry. Andrzej Krzysztofowicz, Andre Hedrick"); | ||
674 | MODULE_DESCRIPTION("PCI driver module for Serverworks OSB4/CSB5/CSB6 IDE"); | ||
675 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/ide/pci/sgiioc4.c b/drivers/ide/pci/sgiioc4.c new file mode 100644 index 000000000000..4651a22bf12e --- /dev/null +++ b/drivers/ide/pci/sgiioc4.c | |||
@@ -0,0 +1,728 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2003 Silicon Graphics, Inc. All Rights Reserved. | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify it | ||
5 | * under the terms of version 2 of the GNU General Public License | ||
6 | * as published by the Free Software Foundation. | ||
7 | * | ||
8 | * This program is distributed in the hope that it would be useful, but | ||
9 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
11 | * | ||
12 | * You should have received a copy of the GNU General Public | ||
13 | * License along with this program; if not, write the Free Software | ||
14 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. | ||
15 | * | ||
16 | * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, | ||
17 | * Mountain View, CA 94043, or: | ||
18 | * | ||
19 | * http://www.sgi.com | ||
20 | * | ||
21 | * For further information regarding this notice, see: | ||
22 | * | ||
23 | * http://oss.sgi.com/projects/GenInfo/NoticeExplan | ||
24 | */ | ||
25 | |||
26 | #include <linux/module.h> | ||
27 | #include <linux/types.h> | ||
28 | #include <linux/pci.h> | ||
29 | #include <linux/delay.h> | ||
30 | #include <linux/hdreg.h> | ||
31 | #include <linux/init.h> | ||
32 | #include <linux/kernel.h> | ||
33 | #include <linux/timer.h> | ||
34 | #include <linux/mm.h> | ||
35 | #include <linux/ioport.h> | ||
36 | #include <linux/blkdev.h> | ||
37 | #include <linux/ioc4_common.h> | ||
38 | #include <asm/io.h> | ||
39 | |||
40 | #include <linux/ide.h> | ||
41 | |||
42 | /* IOC4 Specific Definitions */ | ||
43 | #define IOC4_CMD_OFFSET 0x100 | ||
44 | #define IOC4_CTRL_OFFSET 0x120 | ||
45 | #define IOC4_DMA_OFFSET 0x140 | ||
46 | #define IOC4_INTR_OFFSET 0x0 | ||
47 | |||
48 | #define IOC4_TIMING 0x00 | ||
49 | #define IOC4_DMA_PTR_L 0x01 | ||
50 | #define IOC4_DMA_PTR_H 0x02 | ||
51 | #define IOC4_DMA_ADDR_L 0x03 | ||
52 | #define IOC4_DMA_ADDR_H 0x04 | ||
53 | #define IOC4_BC_DEV 0x05 | ||
54 | #define IOC4_BC_MEM 0x06 | ||
55 | #define IOC4_DMA_CTRL 0x07 | ||
56 | #define IOC4_DMA_END_ADDR 0x08 | ||
57 | |||
58 | /* Bits in the IOC4 Control/Status Register */ | ||
59 | #define IOC4_S_DMA_START 0x01 | ||
60 | #define IOC4_S_DMA_STOP 0x02 | ||
61 | #define IOC4_S_DMA_DIR 0x04 | ||
62 | #define IOC4_S_DMA_ACTIVE 0x08 | ||
63 | #define IOC4_S_DMA_ERROR 0x10 | ||
64 | #define IOC4_ATA_MEMERR 0x02 | ||
65 | |||
66 | /* Read/Write Directions */ | ||
67 | #define IOC4_DMA_WRITE 0x04 | ||
68 | #define IOC4_DMA_READ 0x00 | ||
69 | |||
70 | /* Interrupt Register Offsets */ | ||
71 | #define IOC4_INTR_REG 0x03 | ||
72 | #define IOC4_INTR_SET 0x05 | ||
73 | #define IOC4_INTR_CLEAR 0x07 | ||
74 | |||
75 | #define IOC4_IDE_CACHELINE_SIZE 128 | ||
76 | #define IOC4_CMD_CTL_BLK_SIZE 0x20 | ||
77 | #define IOC4_SUPPORTED_FIRMWARE_REV 46 | ||
78 | |||
79 | typedef struct { | ||
80 | u32 timing_reg0; | ||
81 | u32 timing_reg1; | ||
82 | u32 low_mem_ptr; | ||
83 | u32 high_mem_ptr; | ||
84 | u32 low_mem_addr; | ||
85 | u32 high_mem_addr; | ||
86 | u32 dev_byte_count; | ||
87 | u32 mem_byte_count; | ||
88 | u32 status; | ||
89 | } ioc4_dma_regs_t; | ||
90 | |||
91 | /* Each Physical Region Descriptor Entry size is 16 bytes (2 * 64 bits) */ | ||
92 | /* IOC4 has only 1 IDE channel */ | ||
93 | #define IOC4_PRD_BYTES 16 | ||
94 | #define IOC4_PRD_ENTRIES (PAGE_SIZE /(4*IOC4_PRD_BYTES)) | ||
95 | |||
96 | |||
97 | static void | ||
98 | sgiioc4_init_hwif_ports(hw_regs_t * hw, unsigned long data_port, | ||
99 | unsigned long ctrl_port, unsigned long irq_port) | ||
100 | { | ||
101 | unsigned long reg = data_port; | ||
102 | int i; | ||
103 | |||
104 | /* Registers are word (32 bit) aligned */ | ||
105 | for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++) | ||
106 | hw->io_ports[i] = reg + i * 4; | ||
107 | |||
108 | if (ctrl_port) | ||
109 | hw->io_ports[IDE_CONTROL_OFFSET] = ctrl_port; | ||
110 | |||
111 | if (irq_port) | ||
112 | hw->io_ports[IDE_IRQ_OFFSET] = irq_port; | ||
113 | } | ||
114 | |||
115 | static void | ||
116 | sgiioc4_maskproc(ide_drive_t * drive, int mask) | ||
117 | { | ||
118 | ide_hwif_t *hwif = HWIF(drive); | ||
119 | hwif->OUTB(mask ? (drive->ctl | 2) : (drive->ctl & ~2), | ||
120 | IDE_CONTROL_REG); | ||
121 | } | ||
122 | |||
123 | |||
124 | static int | ||
125 | sgiioc4_checkirq(ide_hwif_t * hwif) | ||
126 | { | ||
127 | u8 intr_reg = | ||
128 | hwif->INL(hwif->io_ports[IDE_IRQ_OFFSET] + IOC4_INTR_REG * 4); | ||
129 | |||
130 | if (intr_reg & 0x03) | ||
131 | return 1; | ||
132 | |||
133 | return 0; | ||
134 | } | ||
135 | |||
136 | |||
137 | static int | ||
138 | sgiioc4_clearirq(ide_drive_t * drive) | ||
139 | { | ||
140 | u32 intr_reg; | ||
141 | ide_hwif_t *hwif = HWIF(drive); | ||
142 | unsigned long other_ir = | ||
143 | hwif->io_ports[IDE_IRQ_OFFSET] + (IOC4_INTR_REG << 2); | ||
144 | |||
145 | /* Code to check for PCI error conditions */ | ||
146 | intr_reg = hwif->INL(other_ir); | ||
147 | if (intr_reg & 0x03) { /* Valid IOC4-IDE interrupt */ | ||
148 | /* | ||
149 | * Using hwif->INB to read the IDE_STATUS_REG has a side effect | ||
150 | * of clearing the interrupt. The first read should clear it | ||
151 | * if it is set. The second read should return a "clear" status | ||
152 | * if it got cleared. If not, then spin for a bit trying to | ||
153 | * clear it. | ||
154 | */ | ||
155 | u8 stat = hwif->INB(IDE_STATUS_REG); | ||
156 | int count = 0; | ||
157 | stat = hwif->INB(IDE_STATUS_REG); | ||
158 | while ((stat & 0x80) && (count++ < 100)) { | ||
159 | udelay(1); | ||
160 | stat = hwif->INB(IDE_STATUS_REG); | ||
161 | } | ||
162 | |||
163 | if (intr_reg & 0x02) { | ||
164 | /* Error when transferring DMA data on PCI bus */ | ||
165 | u32 pci_err_addr_low, pci_err_addr_high, | ||
166 | pci_stat_cmd_reg; | ||
167 | |||
168 | pci_err_addr_low = | ||
169 | hwif->INL(hwif->io_ports[IDE_IRQ_OFFSET]); | ||
170 | pci_err_addr_high = | ||
171 | hwif->INL(hwif->io_ports[IDE_IRQ_OFFSET] + 4); | ||
172 | pci_read_config_dword(hwif->pci_dev, PCI_COMMAND, | ||
173 | &pci_stat_cmd_reg); | ||
174 | printk(KERN_ERR | ||
175 | "%s(%s) : PCI Bus Error when doing DMA:" | ||
176 | " status-cmd reg is 0x%x\n", | ||
177 | __FUNCTION__, drive->name, pci_stat_cmd_reg); | ||
178 | printk(KERN_ERR | ||
179 | "%s(%s) : PCI Error Address is 0x%x%x\n", | ||
180 | __FUNCTION__, drive->name, | ||
181 | pci_err_addr_high, pci_err_addr_low); | ||
182 | /* Clear the PCI Error indicator */ | ||
183 | pci_write_config_dword(hwif->pci_dev, PCI_COMMAND, | ||
184 | 0x00000146); | ||
185 | } | ||
186 | |||
187 | /* Clear the Interrupt, Error bits on the IOC4 */ | ||
188 | hwif->OUTL(0x03, other_ir); | ||
189 | |||
190 | intr_reg = hwif->INL(other_ir); | ||
191 | } | ||
192 | |||
193 | return intr_reg & 3; | ||
194 | } | ||
195 | |||
196 | static void sgiioc4_ide_dma_start(ide_drive_t * drive) | ||
197 | { | ||
198 | ide_hwif_t *hwif = HWIF(drive); | ||
199 | unsigned int reg = hwif->INL(hwif->dma_base + IOC4_DMA_CTRL * 4); | ||
200 | unsigned int temp_reg = reg | IOC4_S_DMA_START; | ||
201 | |||
202 | hwif->OUTL(temp_reg, hwif->dma_base + IOC4_DMA_CTRL * 4); | ||
203 | } | ||
204 | |||
205 | static u32 | ||
206 | sgiioc4_ide_dma_stop(ide_hwif_t *hwif, u64 dma_base) | ||
207 | { | ||
208 | u32 ioc4_dma; | ||
209 | int count; | ||
210 | |||
211 | count = 0; | ||
212 | ioc4_dma = hwif->INL(dma_base + IOC4_DMA_CTRL * 4); | ||
213 | while ((ioc4_dma & IOC4_S_DMA_STOP) && (count++ < 200)) { | ||
214 | udelay(1); | ||
215 | ioc4_dma = hwif->INL(dma_base + IOC4_DMA_CTRL * 4); | ||
216 | } | ||
217 | return ioc4_dma; | ||
218 | } | ||
219 | |||
220 | /* Stops the IOC4 DMA Engine */ | ||
221 | static int | ||
222 | sgiioc4_ide_dma_end(ide_drive_t * drive) | ||
223 | { | ||
224 | u32 ioc4_dma, bc_dev, bc_mem, num, valid = 0, cnt = 0; | ||
225 | ide_hwif_t *hwif = HWIF(drive); | ||
226 | u64 dma_base = hwif->dma_base; | ||
227 | int dma_stat = 0; | ||
228 | unsigned long *ending_dma = (unsigned long *) hwif->dma_base2; | ||
229 | |||
230 | hwif->OUTL(IOC4_S_DMA_STOP, dma_base + IOC4_DMA_CTRL * 4); | ||
231 | |||
232 | ioc4_dma = sgiioc4_ide_dma_stop(hwif, dma_base); | ||
233 | |||
234 | if (ioc4_dma & IOC4_S_DMA_STOP) { | ||
235 | printk(KERN_ERR | ||
236 | "%s(%s): IOC4 DMA STOP bit is still 1 :" | ||
237 | "ioc4_dma_reg 0x%x\n", | ||
238 | __FUNCTION__, drive->name, ioc4_dma); | ||
239 | dma_stat = 1; | ||
240 | } | ||
241 | |||
242 | /* | ||
243 | * The IOC4 will DMA 1's to the ending dma area to indicate that | ||
244 | * previous data DMA is complete. This is necessary because of relaxed | ||
245 | * ordering between register reads and DMA writes on the Altix. | ||
246 | */ | ||
247 | while ((cnt++ < 200) && (!valid)) { | ||
248 | for (num = 0; num < 16; num++) { | ||
249 | if (ending_dma[num]) { | ||
250 | valid = 1; | ||
251 | break; | ||
252 | } | ||
253 | } | ||
254 | udelay(1); | ||
255 | } | ||
256 | if (!valid) { | ||
257 | printk(KERN_ERR "%s(%s) : DMA incomplete\n", __FUNCTION__, | ||
258 | drive->name); | ||
259 | dma_stat = 1; | ||
260 | } | ||
261 | |||
262 | bc_dev = hwif->INL(dma_base + IOC4_BC_DEV * 4); | ||
263 | bc_mem = hwif->INL(dma_base + IOC4_BC_MEM * 4); | ||
264 | |||
265 | if ((bc_dev & 0x01FF) || (bc_mem & 0x1FF)) { | ||
266 | if (bc_dev > bc_mem + 8) { | ||
267 | printk(KERN_ERR | ||
268 | "%s(%s): WARNING!! byte_count_dev %d " | ||
269 | "!= byte_count_mem %d\n", | ||
270 | __FUNCTION__, drive->name, bc_dev, bc_mem); | ||
271 | } | ||
272 | } | ||
273 | |||
274 | drive->waiting_for_dma = 0; | ||
275 | ide_destroy_dmatable(drive); | ||
276 | |||
277 | return dma_stat; | ||
278 | } | ||
279 | |||
280 | static int | ||
281 | sgiioc4_ide_dma_check(ide_drive_t * drive) | ||
282 | { | ||
283 | if (ide_config_drive_speed(drive, XFER_MW_DMA_2) != 0) { | ||
284 | printk(KERN_INFO | ||
285 | "Couldnot set %s in Multimode-2 DMA mode | " | ||
286 | "Drive %s using PIO instead\n", | ||
287 | drive->name, drive->name); | ||
288 | drive->using_dma = 0; | ||
289 | } else | ||
290 | drive->using_dma = 1; | ||
291 | |||
292 | return 0; | ||
293 | } | ||
294 | |||
295 | static int | ||
296 | sgiioc4_ide_dma_on(ide_drive_t * drive) | ||
297 | { | ||
298 | drive->using_dma = 1; | ||
299 | |||
300 | return HWIF(drive)->ide_dma_host_on(drive); | ||
301 | } | ||
302 | |||
303 | static int | ||
304 | sgiioc4_ide_dma_off_quietly(ide_drive_t * drive) | ||
305 | { | ||
306 | drive->using_dma = 0; | ||
307 | |||
308 | return HWIF(drive)->ide_dma_host_off(drive); | ||
309 | } | ||
310 | |||
311 | /* returns 1 if dma irq issued, 0 otherwise */ | ||
312 | static int | ||
313 | sgiioc4_ide_dma_test_irq(ide_drive_t * drive) | ||
314 | { | ||
315 | return sgiioc4_checkirq(HWIF(drive)); | ||
316 | } | ||
317 | |||
318 | static int | ||
319 | sgiioc4_ide_dma_host_on(ide_drive_t * drive) | ||
320 | { | ||
321 | if (drive->using_dma) | ||
322 | return 0; | ||
323 | |||
324 | return 1; | ||
325 | } | ||
326 | |||
327 | static int | ||
328 | sgiioc4_ide_dma_host_off(ide_drive_t * drive) | ||
329 | { | ||
330 | sgiioc4_clearirq(drive); | ||
331 | |||
332 | return 0; | ||
333 | } | ||
334 | |||
335 | static int | ||
336 | sgiioc4_ide_dma_lostirq(ide_drive_t * drive) | ||
337 | { | ||
338 | HWIF(drive)->resetproc(drive); | ||
339 | |||
340 | return __ide_dma_lostirq(drive); | ||
341 | } | ||
342 | |||
343 | static void | ||
344 | sgiioc4_resetproc(ide_drive_t * drive) | ||
345 | { | ||
346 | sgiioc4_ide_dma_end(drive); | ||
347 | sgiioc4_clearirq(drive); | ||
348 | } | ||
349 | |||
350 | static u8 | ||
351 | sgiioc4_INB(unsigned long port) | ||
352 | { | ||
353 | u8 reg = (u8) inb(port); | ||
354 | |||
355 | if ((port & 0xFFF) == 0x11C) { /* Status register of IOC4 */ | ||
356 | if (reg & 0x51) { /* Not busy...check for interrupt */ | ||
357 | unsigned long other_ir = port - 0x110; | ||
358 | unsigned int intr_reg = (u32) inl(other_ir); | ||
359 | |||
360 | /* Clear the Interrupt, Error bits on the IOC4 */ | ||
361 | if (intr_reg & 0x03) { | ||
362 | outl(0x03, other_ir); | ||
363 | intr_reg = (u32) inl(other_ir); | ||
364 | } | ||
365 | } | ||
366 | } | ||
367 | |||
368 | return reg; | ||
369 | } | ||
370 | |||
371 | /* Creates a dma map for the scatter-gather list entries */ | ||
372 | static void __devinit | ||
373 | ide_dma_sgiioc4(ide_hwif_t * hwif, unsigned long dma_base) | ||
374 | { | ||
375 | int num_ports = sizeof (ioc4_dma_regs_t); | ||
376 | |||
377 | printk(KERN_INFO "%s: BM-DMA at 0x%04lx-0x%04lx\n", hwif->name, | ||
378 | dma_base, dma_base + num_ports - 1); | ||
379 | |||
380 | if (!request_region(dma_base, num_ports, hwif->name)) { | ||
381 | printk(KERN_ERR | ||
382 | "%s(%s) -- ERROR, Addresses 0x%p to 0x%p " | ||
383 | "ALREADY in use\n", | ||
384 | __FUNCTION__, hwif->name, (void *) dma_base, | ||
385 | (void *) dma_base + num_ports - 1); | ||
386 | goto dma_alloc_failure; | ||
387 | } | ||
388 | |||
389 | hwif->dma_base = dma_base; | ||
390 | hwif->dmatable_cpu = pci_alloc_consistent(hwif->pci_dev, | ||
391 | IOC4_PRD_ENTRIES * IOC4_PRD_BYTES, | ||
392 | &hwif->dmatable_dma); | ||
393 | |||
394 | if (!hwif->dmatable_cpu) | ||
395 | goto dma_alloc_failure; | ||
396 | |||
397 | hwif->sg_max_nents = IOC4_PRD_ENTRIES; | ||
398 | |||
399 | hwif->dma_base2 = (unsigned long) | ||
400 | pci_alloc_consistent(hwif->pci_dev, | ||
401 | IOC4_IDE_CACHELINE_SIZE, | ||
402 | (dma_addr_t *) &(hwif->dma_status)); | ||
403 | |||
404 | if (!hwif->dma_base2) | ||
405 | goto dma_base2alloc_failure; | ||
406 | |||
407 | return; | ||
408 | |||
409 | dma_base2alloc_failure: | ||
410 | pci_free_consistent(hwif->pci_dev, | ||
411 | IOC4_PRD_ENTRIES * IOC4_PRD_BYTES, | ||
412 | hwif->dmatable_cpu, hwif->dmatable_dma); | ||
413 | printk(KERN_INFO | ||
414 | "%s() -- Error! Unable to allocate DMA Maps for drive %s\n", | ||
415 | __FUNCTION__, hwif->name); | ||
416 | printk(KERN_INFO | ||
417 | "Changing from DMA to PIO mode for Drive %s\n", hwif->name); | ||
418 | |||
419 | dma_alloc_failure: | ||
420 | /* Disable DMA because we couldnot allocate any DMA maps */ | ||
421 | hwif->autodma = 0; | ||
422 | hwif->atapi_dma = 0; | ||
423 | } | ||
424 | |||
425 | /* Initializes the IOC4 DMA Engine */ | ||
426 | static void | ||
427 | sgiioc4_configure_for_dma(int dma_direction, ide_drive_t * drive) | ||
428 | { | ||
429 | u32 ioc4_dma; | ||
430 | ide_hwif_t *hwif = HWIF(drive); | ||
431 | u64 dma_base = hwif->dma_base; | ||
432 | u32 dma_addr, ending_dma_addr; | ||
433 | |||
434 | ioc4_dma = hwif->INL(dma_base + IOC4_DMA_CTRL * 4); | ||
435 | |||
436 | if (ioc4_dma & IOC4_S_DMA_ACTIVE) { | ||
437 | printk(KERN_WARNING | ||
438 | "%s(%s):Warning!! DMA from previous transfer was still active\n", | ||
439 | __FUNCTION__, drive->name); | ||
440 | hwif->OUTL(IOC4_S_DMA_STOP, dma_base + IOC4_DMA_CTRL * 4); | ||
441 | ioc4_dma = sgiioc4_ide_dma_stop(hwif, dma_base); | ||
442 | |||
443 | if (ioc4_dma & IOC4_S_DMA_STOP) | ||
444 | printk(KERN_ERR | ||
445 | "%s(%s) : IOC4 Dma STOP bit is still 1\n", | ||
446 | __FUNCTION__, drive->name); | ||
447 | } | ||
448 | |||
449 | ioc4_dma = hwif->INL(dma_base + IOC4_DMA_CTRL * 4); | ||
450 | if (ioc4_dma & IOC4_S_DMA_ERROR) { | ||
451 | printk(KERN_WARNING | ||
452 | "%s(%s) : Warning!! - DMA Error during Previous" | ||
453 | " transfer | status 0x%x\n", | ||
454 | __FUNCTION__, drive->name, ioc4_dma); | ||
455 | hwif->OUTL(IOC4_S_DMA_STOP, dma_base + IOC4_DMA_CTRL * 4); | ||
456 | ioc4_dma = sgiioc4_ide_dma_stop(hwif, dma_base); | ||
457 | |||
458 | if (ioc4_dma & IOC4_S_DMA_STOP) | ||
459 | printk(KERN_ERR | ||
460 | "%s(%s) : IOC4 DMA STOP bit is still 1\n", | ||
461 | __FUNCTION__, drive->name); | ||
462 | } | ||
463 | |||
464 | /* Address of the Scatter Gather List */ | ||
465 | dma_addr = cpu_to_le32(hwif->dmatable_dma); | ||
466 | hwif->OUTL(dma_addr, dma_base + IOC4_DMA_PTR_L * 4); | ||
467 | |||
468 | /* Address of the Ending DMA */ | ||
469 | memset((unsigned int *) hwif->dma_base2, 0, IOC4_IDE_CACHELINE_SIZE); | ||
470 | ending_dma_addr = cpu_to_le32(hwif->dma_status); | ||
471 | hwif->OUTL(ending_dma_addr, dma_base + IOC4_DMA_END_ADDR * 4); | ||
472 | |||
473 | hwif->OUTL(dma_direction, dma_base + IOC4_DMA_CTRL * 4); | ||
474 | drive->waiting_for_dma = 1; | ||
475 | } | ||
476 | |||
477 | /* IOC4 Scatter Gather list Format */ | ||
478 | /* 128 Bit entries to support 64 bit addresses in the future */ | ||
479 | /* The Scatter Gather list Entry should be in the BIG-ENDIAN Format */ | ||
480 | /* --------------------------------------------------------------------- */ | ||
481 | /* | Upper 32 bits - Zero | Lower 32 bits- address | */ | ||
482 | /* --------------------------------------------------------------------- */ | ||
483 | /* | Upper 32 bits - Zero |EOL| 15 unused | 16 Bit Length| */ | ||
484 | /* --------------------------------------------------------------------- */ | ||
485 | /* Creates the scatter gather list, DMA Table */ | ||
486 | static unsigned int | ||
487 | sgiioc4_build_dma_table(ide_drive_t * drive, struct request *rq, int ddir) | ||
488 | { | ||
489 | ide_hwif_t *hwif = HWIF(drive); | ||
490 | unsigned int *table = hwif->dmatable_cpu; | ||
491 | unsigned int count = 0, i = 1; | ||
492 | struct scatterlist *sg; | ||
493 | |||
494 | hwif->sg_nents = i = ide_build_sglist(drive, rq); | ||
495 | |||
496 | if (!i) | ||
497 | return 0; /* sglist of length Zero */ | ||
498 | |||
499 | sg = hwif->sg_table; | ||
500 | while (i && sg_dma_len(sg)) { | ||
501 | dma_addr_t cur_addr; | ||
502 | int cur_len; | ||
503 | cur_addr = sg_dma_address(sg); | ||
504 | cur_len = sg_dma_len(sg); | ||
505 | |||
506 | while (cur_len) { | ||
507 | if (count++ >= IOC4_PRD_ENTRIES) { | ||
508 | printk(KERN_WARNING | ||
509 | "%s: DMA table too small\n", | ||
510 | drive->name); | ||
511 | goto use_pio_instead; | ||
512 | } else { | ||
513 | u32 xcount, bcount = | ||
514 | 0x10000 - (cur_addr & 0xffff); | ||
515 | |||
516 | if (bcount > cur_len) | ||
517 | bcount = cur_len; | ||
518 | |||
519 | /* put the addr, length in | ||
520 | * the IOC4 dma-table format */ | ||
521 | *table = 0x0; | ||
522 | table++; | ||
523 | *table = cpu_to_be32(cur_addr); | ||
524 | table++; | ||
525 | *table = 0x0; | ||
526 | table++; | ||
527 | |||
528 | xcount = bcount & 0xffff; | ||
529 | *table = cpu_to_be32(xcount); | ||
530 | table++; | ||
531 | |||
532 | cur_addr += bcount; | ||
533 | cur_len -= bcount; | ||
534 | } | ||
535 | } | ||
536 | |||
537 | sg++; | ||
538 | i--; | ||
539 | } | ||
540 | |||
541 | if (count) { | ||
542 | table--; | ||
543 | *table |= cpu_to_be32(0x80000000); | ||
544 | return count; | ||
545 | } | ||
546 | |||
547 | use_pio_instead: | ||
548 | pci_unmap_sg(hwif->pci_dev, hwif->sg_table, hwif->sg_nents, | ||
549 | hwif->sg_dma_direction); | ||
550 | |||
551 | return 0; /* revert to PIO for this request */ | ||
552 | } | ||
553 | |||
554 | static int sgiioc4_ide_dma_setup(ide_drive_t *drive) | ||
555 | { | ||
556 | struct request *rq = HWGROUP(drive)->rq; | ||
557 | unsigned int count = 0; | ||
558 | int ddir; | ||
559 | |||
560 | if (rq_data_dir(rq)) | ||
561 | ddir = PCI_DMA_TODEVICE; | ||
562 | else | ||
563 | ddir = PCI_DMA_FROMDEVICE; | ||
564 | |||
565 | if (!(count = sgiioc4_build_dma_table(drive, rq, ddir))) { | ||
566 | /* try PIO instead of DMA */ | ||
567 | ide_map_sg(drive, rq); | ||
568 | return 1; | ||
569 | } | ||
570 | |||
571 | if (rq_data_dir(rq)) | ||
572 | /* Writes TO the IOC4 FROM Main Memory */ | ||
573 | ddir = IOC4_DMA_READ; | ||
574 | else | ||
575 | /* Writes FROM the IOC4 TO Main Memory */ | ||
576 | ddir = IOC4_DMA_WRITE; | ||
577 | |||
578 | sgiioc4_configure_for_dma(ddir, drive); | ||
579 | |||
580 | return 0; | ||
581 | } | ||
582 | |||
583 | static void __devinit | ||
584 | ide_init_sgiioc4(ide_hwif_t * hwif) | ||
585 | { | ||
586 | hwif->mmio = 2; | ||
587 | hwif->autodma = 1; | ||
588 | hwif->atapi_dma = 1; | ||
589 | hwif->ultra_mask = 0x0; /* Disable Ultra DMA */ | ||
590 | hwif->mwdma_mask = 0x2; /* Multimode-2 DMA */ | ||
591 | hwif->swdma_mask = 0x2; | ||
592 | hwif->tuneproc = NULL; /* Sets timing for PIO mode */ | ||
593 | hwif->speedproc = NULL; /* Sets timing for DMA &/or PIO modes */ | ||
594 | hwif->selectproc = NULL;/* Use the default routine to select drive */ | ||
595 | hwif->reset_poll = NULL;/* No HBA specific reset_poll needed */ | ||
596 | hwif->pre_reset = NULL; /* No HBA specific pre_set needed */ | ||
597 | hwif->resetproc = &sgiioc4_resetproc;/* Reset DMA engine, | ||
598 | clear interrupts */ | ||
599 | hwif->intrproc = NULL; /* Enable or Disable interrupt from drive */ | ||
600 | hwif->maskproc = &sgiioc4_maskproc; /* Mask on/off NIEN register */ | ||
601 | hwif->quirkproc = NULL; | ||
602 | hwif->busproc = NULL; | ||
603 | |||
604 | hwif->dma_setup = &sgiioc4_ide_dma_setup; | ||
605 | hwif->dma_start = &sgiioc4_ide_dma_start; | ||
606 | hwif->ide_dma_end = &sgiioc4_ide_dma_end; | ||
607 | hwif->ide_dma_check = &sgiioc4_ide_dma_check; | ||
608 | hwif->ide_dma_on = &sgiioc4_ide_dma_on; | ||
609 | hwif->ide_dma_off_quietly = &sgiioc4_ide_dma_off_quietly; | ||
610 | hwif->ide_dma_test_irq = &sgiioc4_ide_dma_test_irq; | ||
611 | hwif->ide_dma_host_on = &sgiioc4_ide_dma_host_on; | ||
612 | hwif->ide_dma_host_off = &sgiioc4_ide_dma_host_off; | ||
613 | hwif->ide_dma_lostirq = &sgiioc4_ide_dma_lostirq; | ||
614 | hwif->ide_dma_timeout = &__ide_dma_timeout; | ||
615 | hwif->INB = &sgiioc4_INB; | ||
616 | } | ||
617 | |||
618 | static int __devinit | ||
619 | sgiioc4_ide_setup_pci_device(struct pci_dev *dev, ide_pci_device_t * d) | ||
620 | { | ||
621 | unsigned long base, ctl, dma_base, irqport; | ||
622 | ide_hwif_t *hwif; | ||
623 | int h; | ||
624 | |||
625 | for (h = 0; h < MAX_HWIFS; ++h) { | ||
626 | hwif = &ide_hwifs[h]; | ||
627 | /* Find an empty HWIF */ | ||
628 | if (hwif->chipset == ide_unknown) | ||
629 | break; | ||
630 | } | ||
631 | |||
632 | /* Get the CmdBlk and CtrlBlk Base Registers */ | ||
633 | base = pci_resource_start(dev, 0) + IOC4_CMD_OFFSET; | ||
634 | ctl = pci_resource_start(dev, 0) + IOC4_CTRL_OFFSET; | ||
635 | irqport = pci_resource_start(dev, 0) + IOC4_INTR_OFFSET; | ||
636 | dma_base = pci_resource_start(dev, 0) + IOC4_DMA_OFFSET; | ||
637 | |||
638 | if (!request_region(base, IOC4_CMD_CTL_BLK_SIZE, hwif->name)) { | ||
639 | printk(KERN_ERR | ||
640 | "%s : %s -- ERROR, Port Addresses " | ||
641 | "0x%p to 0x%p ALREADY in use\n", | ||
642 | __FUNCTION__, hwif->name, (void *) base, | ||
643 | (void *) base + IOC4_CMD_CTL_BLK_SIZE); | ||
644 | return -ENOMEM; | ||
645 | } | ||
646 | |||
647 | if (hwif->io_ports[IDE_DATA_OFFSET] != base) { | ||
648 | /* Initialize the IO registers */ | ||
649 | sgiioc4_init_hwif_ports(&hwif->hw, base, ctl, irqport); | ||
650 | memcpy(hwif->io_ports, hwif->hw.io_ports, | ||
651 | sizeof (hwif->io_ports)); | ||
652 | hwif->noprobe = !hwif->io_ports[IDE_DATA_OFFSET]; | ||
653 | } | ||
654 | |||
655 | hwif->irq = dev->irq; | ||
656 | hwif->chipset = ide_pci; | ||
657 | hwif->pci_dev = dev; | ||
658 | hwif->channel = 0; /* Single Channel chip */ | ||
659 | hwif->cds = (struct ide_pci_device_s *) d; | ||
660 | hwif->gendev.parent = &dev->dev;/* setup proper ancestral information */ | ||
661 | |||
662 | /* Initializing chipset IRQ Registers */ | ||
663 | hwif->OUTL(0x03, irqport + IOC4_INTR_SET * 4); | ||
664 | |||
665 | ide_init_sgiioc4(hwif); | ||
666 | |||
667 | if (dma_base) | ||
668 | ide_dma_sgiioc4(hwif, dma_base); | ||
669 | else | ||
670 | printk(KERN_INFO "%s: %s Bus-Master DMA disabled\n", | ||
671 | hwif->name, d->name); | ||
672 | |||
673 | if (probe_hwif_init(hwif)) | ||
674 | return -EIO; | ||
675 | |||
676 | /* Create /proc/ide entries */ | ||
677 | create_proc_ide_interfaces(); | ||
678 | |||
679 | return 0; | ||
680 | } | ||
681 | |||
682 | static unsigned int __devinit | ||
683 | pci_init_sgiioc4(struct pci_dev *dev, ide_pci_device_t * d) | ||
684 | { | ||
685 | unsigned int class_rev; | ||
686 | int ret; | ||
687 | |||
688 | pci_read_config_dword(dev, PCI_CLASS_REVISION, &class_rev); | ||
689 | class_rev &= 0xff; | ||
690 | printk(KERN_INFO "%s: IDE controller at PCI slot %s, revision %d\n", | ||
691 | d->name, pci_name(dev), class_rev); | ||
692 | if (class_rev < IOC4_SUPPORTED_FIRMWARE_REV) { | ||
693 | printk(KERN_ERR "Skipping %s IDE controller in slot %s: " | ||
694 | "firmware is obsolete - please upgrade to revision" | ||
695 | "46 or higher\n", d->name, pci_name(dev)); | ||
696 | ret = -EAGAIN; | ||
697 | goto out; | ||
698 | } | ||
699 | ret = sgiioc4_ide_setup_pci_device(dev, d); | ||
700 | out: | ||
701 | return ret; | ||
702 | } | ||
703 | |||
704 | static ide_pci_device_t sgiioc4_chipsets[] __devinitdata = { | ||
705 | { | ||
706 | /* Channel 0 */ | ||
707 | .name = "SGIIOC4", | ||
708 | .init_hwif = ide_init_sgiioc4, | ||
709 | .init_dma = ide_dma_sgiioc4, | ||
710 | .channels = 1, | ||
711 | .autodma = AUTODMA, | ||
712 | /* SGI IOC4 doesn't have enablebits. */ | ||
713 | .bootable = ON_BOARD, | ||
714 | } | ||
715 | }; | ||
716 | |||
717 | int | ||
718 | ioc4_ide_attach_one(struct pci_dev *dev, const struct pci_device_id *id) | ||
719 | { | ||
720 | return pci_init_sgiioc4(dev, &sgiioc4_chipsets[id->driver_data]); | ||
721 | } | ||
722 | |||
723 | |||
724 | MODULE_AUTHOR("Aniket Malatpure - Silicon Graphics Inc. (SGI)"); | ||
725 | MODULE_DESCRIPTION("IDE PCI driver module for SGI IOC4 Base-IO Card"); | ||
726 | MODULE_LICENSE("GPL"); | ||
727 | |||
728 | EXPORT_SYMBOL(ioc4_ide_attach_one); | ||
diff --git a/drivers/ide/pci/siimage.c b/drivers/ide/pci/siimage.c new file mode 100644 index 000000000000..2b9961b88135 --- /dev/null +++ b/drivers/ide/pci/siimage.c | |||
@@ -0,0 +1,1133 @@ | |||
1 | /* | ||
2 | * linux/drivers/ide/pci/siimage.c Version 1.07 Nov 30, 2003 | ||
3 | * | ||
4 | * Copyright (C) 2001-2002 Andre Hedrick <andre@linux-ide.org> | ||
5 | * Copyright (C) 2003 Red Hat <alan@redhat.com> | ||
6 | * | ||
7 | * May be copied or modified under the terms of the GNU General Public License | ||
8 | * | ||
9 | * Documentation available under NDA only | ||
10 | * | ||
11 | * | ||
12 | * FAQ Items: | ||
13 | * If you are using Marvell SATA-IDE adapters with Maxtor drives | ||
14 | * ensure the system is set up for ATA100/UDMA5 not UDMA6. | ||
15 | * | ||
16 | * If you are using WD drives with SATA bridges you must set the | ||
17 | * drive to "Single". "Master" will hang | ||
18 | * | ||
19 | * If you have strange problems with nVidia chipset systems please | ||
20 | * see the SI support documentation and update your system BIOS | ||
21 | * if neccessary | ||
22 | */ | ||
23 | |||
24 | #include <linux/config.h> | ||
25 | #include <linux/types.h> | ||
26 | #include <linux/module.h> | ||
27 | #include <linux/pci.h> | ||
28 | #include <linux/delay.h> | ||
29 | #include <linux/hdreg.h> | ||
30 | #include <linux/ide.h> | ||
31 | #include <linux/init.h> | ||
32 | |||
33 | #include <asm/io.h> | ||
34 | |||
35 | #undef SIIMAGE_VIRTUAL_DMAPIO | ||
36 | #undef SIIMAGE_LARGE_DMA | ||
37 | |||
38 | /** | ||
39 | * pdev_is_sata - check if device is SATA | ||
40 | * @pdev: PCI device to check | ||
41 | * | ||
42 | * Returns true if this is a SATA controller | ||
43 | */ | ||
44 | |||
45 | static int pdev_is_sata(struct pci_dev *pdev) | ||
46 | { | ||
47 | switch(pdev->device) | ||
48 | { | ||
49 | case PCI_DEVICE_ID_SII_3112: | ||
50 | case PCI_DEVICE_ID_SII_1210SA: | ||
51 | return 1; | ||
52 | case PCI_DEVICE_ID_SII_680: | ||
53 | return 0; | ||
54 | } | ||
55 | BUG(); | ||
56 | return 0; | ||
57 | } | ||
58 | |||
59 | /** | ||
60 | * is_sata - check if hwif is SATA | ||
61 | * @hwif: interface to check | ||
62 | * | ||
63 | * Returns true if this is a SATA controller | ||
64 | */ | ||
65 | |||
66 | static inline int is_sata(ide_hwif_t *hwif) | ||
67 | { | ||
68 | return pdev_is_sata(hwif->pci_dev); | ||
69 | } | ||
70 | |||
71 | /** | ||
72 | * siimage_selreg - return register base | ||
73 | * @hwif: interface | ||
74 | * @r: config offset | ||
75 | * | ||
76 | * Turn a config register offset into the right address in either | ||
77 | * PCI space or MMIO space to access the control register in question | ||
78 | * Thankfully this is a configuration operation so isnt performance | ||
79 | * criticial. | ||
80 | */ | ||
81 | |||
82 | static unsigned long siimage_selreg(ide_hwif_t *hwif, int r) | ||
83 | { | ||
84 | unsigned long base = (unsigned long)hwif->hwif_data; | ||
85 | base += 0xA0 + r; | ||
86 | if(hwif->mmio) | ||
87 | base += (hwif->channel << 6); | ||
88 | else | ||
89 | base += (hwif->channel << 4); | ||
90 | return base; | ||
91 | } | ||
92 | |||
93 | /** | ||
94 | * siimage_seldev - return register base | ||
95 | * @hwif: interface | ||
96 | * @r: config offset | ||
97 | * | ||
98 | * Turn a config register offset into the right address in either | ||
99 | * PCI space or MMIO space to access the control register in question | ||
100 | * including accounting for the unit shift. | ||
101 | */ | ||
102 | |||
103 | static inline unsigned long siimage_seldev(ide_drive_t *drive, int r) | ||
104 | { | ||
105 | ide_hwif_t *hwif = HWIF(drive); | ||
106 | unsigned long base = (unsigned long)hwif->hwif_data; | ||
107 | base += 0xA0 + r; | ||
108 | if(hwif->mmio) | ||
109 | base += (hwif->channel << 6); | ||
110 | else | ||
111 | base += (hwif->channel << 4); | ||
112 | base |= drive->select.b.unit << drive->select.b.unit; | ||
113 | return base; | ||
114 | } | ||
115 | |||
116 | /** | ||
117 | * siimage_ratemask - Compute available modes | ||
118 | * @drive: IDE drive | ||
119 | * | ||
120 | * Compute the available speeds for the devices on the interface. | ||
121 | * For the CMD680 this depends on the clocking mode (scsc), for the | ||
122 | * SI3312 SATA controller life is a bit simpler. Enforce UDMA33 | ||
123 | * as a limit if there is no 80pin cable present. | ||
124 | */ | ||
125 | |||
126 | static byte siimage_ratemask (ide_drive_t *drive) | ||
127 | { | ||
128 | ide_hwif_t *hwif = HWIF(drive); | ||
129 | u8 mode = 0, scsc = 0; | ||
130 | unsigned long base = (unsigned long) hwif->hwif_data; | ||
131 | |||
132 | if (hwif->mmio) | ||
133 | scsc = hwif->INB(base + 0x4A); | ||
134 | else | ||
135 | pci_read_config_byte(hwif->pci_dev, 0x8A, &scsc); | ||
136 | |||
137 | if(is_sata(hwif)) | ||
138 | { | ||
139 | if(strstr(drive->id->model, "Maxtor")) | ||
140 | return 3; | ||
141 | return 4; | ||
142 | } | ||
143 | |||
144 | if ((scsc & 0x30) == 0x10) /* 133 */ | ||
145 | mode = 4; | ||
146 | else if ((scsc & 0x30) == 0x20) /* 2xPCI */ | ||
147 | mode = 4; | ||
148 | else if ((scsc & 0x30) == 0x00) /* 100 */ | ||
149 | mode = 3; | ||
150 | else /* Disabled ? */ | ||
151 | BUG(); | ||
152 | |||
153 | if (!eighty_ninty_three(drive)) | ||
154 | mode = min(mode, (u8)1); | ||
155 | return mode; | ||
156 | } | ||
157 | |||
158 | /** | ||
159 | * siimage_taskfile_timing - turn timing data to a mode | ||
160 | * @hwif: interface to query | ||
161 | * | ||
162 | * Read the timing data for the interface and return the | ||
163 | * mode that is being used. | ||
164 | */ | ||
165 | |||
166 | static byte siimage_taskfile_timing (ide_hwif_t *hwif) | ||
167 | { | ||
168 | u16 timing = 0x328a; | ||
169 | unsigned long addr = siimage_selreg(hwif, 2); | ||
170 | |||
171 | if (hwif->mmio) | ||
172 | timing = hwif->INW(addr); | ||
173 | else | ||
174 | pci_read_config_word(hwif->pci_dev, addr, &timing); | ||
175 | |||
176 | switch (timing) { | ||
177 | case 0x10c1: return 4; | ||
178 | case 0x10c3: return 3; | ||
179 | case 0x1104: | ||
180 | case 0x1281: return 2; | ||
181 | case 0x2283: return 1; | ||
182 | case 0x328a: | ||
183 | default: return 0; | ||
184 | } | ||
185 | } | ||
186 | |||
187 | /** | ||
188 | * simmage_tuneproc - tune a drive | ||
189 | * @drive: drive to tune | ||
190 | * @mode_wanted: the target operating mode | ||
191 | * | ||
192 | * Load the timing settings for this device mode into the | ||
193 | * controller. If we are in PIO mode 3 or 4 turn on IORDY | ||
194 | * monitoring (bit 9). The TF timing is bits 31:16 | ||
195 | */ | ||
196 | |||
197 | static void siimage_tuneproc (ide_drive_t *drive, byte mode_wanted) | ||
198 | { | ||
199 | ide_hwif_t *hwif = HWIF(drive); | ||
200 | u32 speedt = 0; | ||
201 | u16 speedp = 0; | ||
202 | unsigned long addr = siimage_seldev(drive, 0x04); | ||
203 | unsigned long tfaddr = siimage_selreg(hwif, 0x02); | ||
204 | |||
205 | /* cheat for now and use the docs */ | ||
206 | switch(mode_wanted) { | ||
207 | case 4: | ||
208 | speedp = 0x10c1; | ||
209 | speedt = 0x10c1; | ||
210 | break; | ||
211 | case 3: | ||
212 | speedp = 0x10C3; | ||
213 | speedt = 0x10C3; | ||
214 | break; | ||
215 | case 2: | ||
216 | speedp = 0x1104; | ||
217 | speedt = 0x1281; | ||
218 | break; | ||
219 | case 1: | ||
220 | speedp = 0x2283; | ||
221 | speedt = 0x1281; | ||
222 | break; | ||
223 | case 0: | ||
224 | default: | ||
225 | speedp = 0x328A; | ||
226 | speedt = 0x328A; | ||
227 | break; | ||
228 | } | ||
229 | if (hwif->mmio) | ||
230 | { | ||
231 | hwif->OUTW(speedt, addr); | ||
232 | hwif->OUTW(speedp, tfaddr); | ||
233 | /* Now set up IORDY */ | ||
234 | if(mode_wanted == 3 || mode_wanted == 4) | ||
235 | hwif->OUTW(hwif->INW(tfaddr-2)|0x200, tfaddr-2); | ||
236 | else | ||
237 | hwif->OUTW(hwif->INW(tfaddr-2)&~0x200, tfaddr-2); | ||
238 | } | ||
239 | else | ||
240 | { | ||
241 | pci_write_config_word(hwif->pci_dev, addr, speedp); | ||
242 | pci_write_config_word(hwif->pci_dev, tfaddr, speedt); | ||
243 | pci_read_config_word(hwif->pci_dev, tfaddr-2, &speedp); | ||
244 | speedp &= ~0x200; | ||
245 | /* Set IORDY for mode 3 or 4 */ | ||
246 | if(mode_wanted == 3 || mode_wanted == 4) | ||
247 | speedp |= 0x200; | ||
248 | pci_write_config_word(hwif->pci_dev, tfaddr-2, speedp); | ||
249 | } | ||
250 | } | ||
251 | |||
252 | /** | ||
253 | * config_siimage_chipset_for_pio - set drive timings | ||
254 | * @drive: drive to tune | ||
255 | * @speed we want | ||
256 | * | ||
257 | * Compute the best pio mode we can for a given device. Also honour | ||
258 | * the timings for the driver when dealing with mixed devices. Some | ||
259 | * of this is ugly but its all wrapped up here | ||
260 | * | ||
261 | * The SI680 can also do VDMA - we need to start using that | ||
262 | * | ||
263 | * FIXME: we use the BIOS channel timings to avoid driving the task | ||
264 | * files too fast at the disk. We need to compute the master/slave | ||
265 | * drive PIO mode properly so that we can up the speed on a hotplug | ||
266 | * system. | ||
267 | */ | ||
268 | |||
269 | static void config_siimage_chipset_for_pio (ide_drive_t *drive, byte set_speed) | ||
270 | { | ||
271 | u8 channel_timings = siimage_taskfile_timing(HWIF(drive)); | ||
272 | u8 speed = 0, set_pio = ide_get_best_pio_mode(drive, 4, 5, NULL); | ||
273 | |||
274 | /* WARNING PIO timing mess is going to happen b/w devices, argh */ | ||
275 | if ((channel_timings != set_pio) && (set_pio > channel_timings)) | ||
276 | set_pio = channel_timings; | ||
277 | |||
278 | siimage_tuneproc(drive, set_pio); | ||
279 | speed = XFER_PIO_0 + set_pio; | ||
280 | if (set_speed) | ||
281 | (void) ide_config_drive_speed(drive, speed); | ||
282 | } | ||
283 | |||
284 | static void config_chipset_for_pio (ide_drive_t *drive, byte set_speed) | ||
285 | { | ||
286 | config_siimage_chipset_for_pio(drive, set_speed); | ||
287 | } | ||
288 | |||
289 | /** | ||
290 | * siimage_tune_chipset - set controller timings | ||
291 | * @drive: Drive to set up | ||
292 | * @xferspeed: speed we want to achieve | ||
293 | * | ||
294 | * Tune the SII chipset for the desired mode. If we can't achieve | ||
295 | * the desired mode then tune for a lower one, but ultimately | ||
296 | * make the thing work. | ||
297 | */ | ||
298 | |||
299 | static int siimage_tune_chipset (ide_drive_t *drive, byte xferspeed) | ||
300 | { | ||
301 | u8 ultra6[] = { 0x0F, 0x0B, 0x07, 0x05, 0x03, 0x02, 0x01 }; | ||
302 | u8 ultra5[] = { 0x0C, 0x07, 0x05, 0x04, 0x02, 0x01 }; | ||
303 | u16 dma[] = { 0x2208, 0x10C2, 0x10C1 }; | ||
304 | |||
305 | ide_hwif_t *hwif = HWIF(drive); | ||
306 | u16 ultra = 0, multi = 0; | ||
307 | u8 mode = 0, unit = drive->select.b.unit; | ||
308 | u8 speed = ide_rate_filter(siimage_ratemask(drive), xferspeed); | ||
309 | unsigned long base = (unsigned long)hwif->hwif_data; | ||
310 | u8 scsc = 0, addr_mask = ((hwif->channel) ? | ||
311 | ((hwif->mmio) ? 0xF4 : 0x84) : | ||
312 | ((hwif->mmio) ? 0xB4 : 0x80)); | ||
313 | |||
314 | unsigned long ma = siimage_seldev(drive, 0x08); | ||
315 | unsigned long ua = siimage_seldev(drive, 0x0C); | ||
316 | |||
317 | if (hwif->mmio) { | ||
318 | scsc = hwif->INB(base + 0x4A); | ||
319 | mode = hwif->INB(base + addr_mask); | ||
320 | multi = hwif->INW(ma); | ||
321 | ultra = hwif->INW(ua); | ||
322 | } else { | ||
323 | pci_read_config_byte(hwif->pci_dev, 0x8A, &scsc); | ||
324 | pci_read_config_byte(hwif->pci_dev, addr_mask, &mode); | ||
325 | pci_read_config_word(hwif->pci_dev, ma, &multi); | ||
326 | pci_read_config_word(hwif->pci_dev, ua, &ultra); | ||
327 | } | ||
328 | |||
329 | mode &= ~((unit) ? 0x30 : 0x03); | ||
330 | ultra &= ~0x3F; | ||
331 | scsc = ((scsc & 0x30) == 0x00) ? 0 : 1; | ||
332 | |||
333 | scsc = is_sata(hwif) ? 1 : scsc; | ||
334 | |||
335 | switch(speed) { | ||
336 | case XFER_PIO_4: | ||
337 | case XFER_PIO_3: | ||
338 | case XFER_PIO_2: | ||
339 | case XFER_PIO_1: | ||
340 | case XFER_PIO_0: | ||
341 | siimage_tuneproc(drive, (speed - XFER_PIO_0)); | ||
342 | mode |= ((unit) ? 0x10 : 0x01); | ||
343 | break; | ||
344 | case XFER_MW_DMA_2: | ||
345 | case XFER_MW_DMA_1: | ||
346 | case XFER_MW_DMA_0: | ||
347 | multi = dma[speed - XFER_MW_DMA_0]; | ||
348 | mode |= ((unit) ? 0x20 : 0x02); | ||
349 | config_siimage_chipset_for_pio(drive, 0); | ||
350 | break; | ||
351 | case XFER_UDMA_6: | ||
352 | case XFER_UDMA_5: | ||
353 | case XFER_UDMA_4: | ||
354 | case XFER_UDMA_3: | ||
355 | case XFER_UDMA_2: | ||
356 | case XFER_UDMA_1: | ||
357 | case XFER_UDMA_0: | ||
358 | multi = dma[2]; | ||
359 | ultra |= ((scsc) ? (ultra6[speed - XFER_UDMA_0]) : | ||
360 | (ultra5[speed - XFER_UDMA_0])); | ||
361 | mode |= ((unit) ? 0x30 : 0x03); | ||
362 | config_siimage_chipset_for_pio(drive, 0); | ||
363 | break; | ||
364 | default: | ||
365 | return 1; | ||
366 | } | ||
367 | |||
368 | if (hwif->mmio) { | ||
369 | hwif->OUTB(mode, base + addr_mask); | ||
370 | hwif->OUTW(multi, ma); | ||
371 | hwif->OUTW(ultra, ua); | ||
372 | } else { | ||
373 | pci_write_config_byte(hwif->pci_dev, addr_mask, mode); | ||
374 | pci_write_config_word(hwif->pci_dev, ma, multi); | ||
375 | pci_write_config_word(hwif->pci_dev, ua, ultra); | ||
376 | } | ||
377 | return (ide_config_drive_speed(drive, speed)); | ||
378 | } | ||
379 | |||
380 | /** | ||
381 | * config_chipset_for_dma - configure for DMA | ||
382 | * @drive: drive to configure | ||
383 | * | ||
384 | * Called by the IDE layer when it wants the timings set up. | ||
385 | * For the CMD680 we also need to set up the PIO timings and | ||
386 | * enable DMA. | ||
387 | */ | ||
388 | |||
389 | static int config_chipset_for_dma (ide_drive_t *drive) | ||
390 | { | ||
391 | u8 speed = ide_dma_speed(drive, siimage_ratemask(drive)); | ||
392 | |||
393 | config_chipset_for_pio(drive, !speed); | ||
394 | |||
395 | if (!speed) | ||
396 | return 0; | ||
397 | |||
398 | if (ide_set_xfer_rate(drive, speed)) | ||
399 | return 0; | ||
400 | |||
401 | if (!drive->init_speed) | ||
402 | drive->init_speed = speed; | ||
403 | |||
404 | return ide_dma_enable(drive); | ||
405 | } | ||
406 | |||
407 | /** | ||
408 | * siimage_configure_drive_for_dma - set up for DMA transfers | ||
409 | * @drive: drive we are going to set up | ||
410 | * | ||
411 | * Set up the drive for DMA, tune the controller and drive as | ||
412 | * required. If the drive isn't suitable for DMA or we hit | ||
413 | * other problems then we will drop down to PIO and set up | ||
414 | * PIO appropriately | ||
415 | */ | ||
416 | |||
417 | static int siimage_config_drive_for_dma (ide_drive_t *drive) | ||
418 | { | ||
419 | ide_hwif_t *hwif = HWIF(drive); | ||
420 | struct hd_driveid *id = drive->id; | ||
421 | |||
422 | if ((id->capability & 1) != 0 && drive->autodma) { | ||
423 | |||
424 | if (ide_use_dma(drive)) { | ||
425 | if (config_chipset_for_dma(drive)) | ||
426 | return hwif->ide_dma_on(drive); | ||
427 | } | ||
428 | |||
429 | goto fast_ata_pio; | ||
430 | |||
431 | } else if ((id->capability & 8) || (id->field_valid & 2)) { | ||
432 | fast_ata_pio: | ||
433 | config_chipset_for_pio(drive, 1); | ||
434 | return hwif->ide_dma_off_quietly(drive); | ||
435 | } | ||
436 | /* IORDY not supported */ | ||
437 | return 0; | ||
438 | } | ||
439 | |||
440 | /* returns 1 if dma irq issued, 0 otherwise */ | ||
441 | static int siimage_io_ide_dma_test_irq (ide_drive_t *drive) | ||
442 | { | ||
443 | ide_hwif_t *hwif = HWIF(drive); | ||
444 | u8 dma_altstat = 0; | ||
445 | unsigned long addr = siimage_selreg(hwif, 1); | ||
446 | |||
447 | /* return 1 if INTR asserted */ | ||
448 | if ((hwif->INB(hwif->dma_status) & 4) == 4) | ||
449 | return 1; | ||
450 | |||
451 | /* return 1 if Device INTR asserted */ | ||
452 | pci_read_config_byte(hwif->pci_dev, addr, &dma_altstat); | ||
453 | if (dma_altstat & 8) | ||
454 | return 0; //return 1; | ||
455 | return 0; | ||
456 | } | ||
457 | |||
458 | #if 0 | ||
459 | /** | ||
460 | * siimage_mmio_ide_dma_count - DMA bytes done | ||
461 | * @drive | ||
462 | * | ||
463 | * If we are doing VDMA the CMD680 requires a little bit | ||
464 | * of more careful handling and we have to read the counts | ||
465 | * off ourselves. For non VDMA life is normal. | ||
466 | */ | ||
467 | |||
468 | static int siimage_mmio_ide_dma_count (ide_drive_t *drive) | ||
469 | { | ||
470 | #ifdef SIIMAGE_VIRTUAL_DMAPIO | ||
471 | struct request *rq = HWGROUP(drive)->rq; | ||
472 | ide_hwif_t *hwif = HWIF(drive); | ||
473 | u32 count = (rq->nr_sectors * SECTOR_SIZE); | ||
474 | u32 rcount = 0; | ||
475 | unsigned long addr = siimage_selreg(hwif, 0x1C); | ||
476 | |||
477 | hwif->OUTL(count, addr); | ||
478 | rcount = hwif->INL(addr); | ||
479 | |||
480 | printk("\n%s: count = %d, rcount = %d, nr_sectors = %lu\n", | ||
481 | drive->name, count, rcount, rq->nr_sectors); | ||
482 | |||
483 | #endif /* SIIMAGE_VIRTUAL_DMAPIO */ | ||
484 | return __ide_dma_count(drive); | ||
485 | } | ||
486 | #endif | ||
487 | |||
488 | /** | ||
489 | * siimage_mmio_ide_dma_test_irq - check we caused an IRQ | ||
490 | * @drive: drive we are testing | ||
491 | * | ||
492 | * Check if we caused an IDE DMA interrupt. We may also have caused | ||
493 | * SATA status interrupts, if so we clean them up and continue. | ||
494 | */ | ||
495 | |||
496 | static int siimage_mmio_ide_dma_test_irq (ide_drive_t *drive) | ||
497 | { | ||
498 | ide_hwif_t *hwif = HWIF(drive); | ||
499 | unsigned long base = (unsigned long)hwif->hwif_data; | ||
500 | unsigned long addr = siimage_selreg(hwif, 0x1); | ||
501 | |||
502 | if (SATA_ERROR_REG) { | ||
503 | u32 ext_stat = hwif->INL(base + 0x10); | ||
504 | u8 watchdog = 0; | ||
505 | if (ext_stat & ((hwif->channel) ? 0x40 : 0x10)) { | ||
506 | u32 sata_error = hwif->INL(SATA_ERROR_REG); | ||
507 | hwif->OUTL(sata_error, SATA_ERROR_REG); | ||
508 | watchdog = (sata_error & 0x00680000) ? 1 : 0; | ||
509 | #if 1 | ||
510 | printk(KERN_WARNING "%s: sata_error = 0x%08x, " | ||
511 | "watchdog = %d, %s\n", | ||
512 | drive->name, sata_error, watchdog, | ||
513 | __FUNCTION__); | ||
514 | #endif | ||
515 | |||
516 | } else { | ||
517 | watchdog = (ext_stat & 0x8000) ? 1 : 0; | ||
518 | } | ||
519 | ext_stat >>= 16; | ||
520 | |||
521 | if (!(ext_stat & 0x0404) && !watchdog) | ||
522 | return 0; | ||
523 | } | ||
524 | |||
525 | /* return 1 if INTR asserted */ | ||
526 | if ((hwif->INB(hwif->dma_status) & 0x04) == 0x04) | ||
527 | return 1; | ||
528 | |||
529 | /* return 1 if Device INTR asserted */ | ||
530 | if ((hwif->INB(addr) & 8) == 8) | ||
531 | return 0; //return 1; | ||
532 | |||
533 | return 0; | ||
534 | } | ||
535 | |||
536 | /** | ||
537 | * siimage_busproc - bus isolation ioctl | ||
538 | * @drive: drive to isolate/restore | ||
539 | * @state: bus state to set | ||
540 | * | ||
541 | * Used by the SII3112 to handle bus isolation. As this is a | ||
542 | * SATA controller the work required is quite limited, we | ||
543 | * just have to clean up the statistics | ||
544 | */ | ||
545 | |||
546 | static int siimage_busproc (ide_drive_t * drive, int state) | ||
547 | { | ||
548 | ide_hwif_t *hwif = HWIF(drive); | ||
549 | u32 stat_config = 0; | ||
550 | unsigned long addr = siimage_selreg(hwif, 0); | ||
551 | |||
552 | if (hwif->mmio) { | ||
553 | stat_config = hwif->INL(addr); | ||
554 | } else | ||
555 | pci_read_config_dword(hwif->pci_dev, addr, &stat_config); | ||
556 | |||
557 | switch (state) { | ||
558 | case BUSSTATE_ON: | ||
559 | hwif->drives[0].failures = 0; | ||
560 | hwif->drives[1].failures = 0; | ||
561 | break; | ||
562 | case BUSSTATE_OFF: | ||
563 | hwif->drives[0].failures = hwif->drives[0].max_failures + 1; | ||
564 | hwif->drives[1].failures = hwif->drives[1].max_failures + 1; | ||
565 | break; | ||
566 | case BUSSTATE_TRISTATE: | ||
567 | hwif->drives[0].failures = hwif->drives[0].max_failures + 1; | ||
568 | hwif->drives[1].failures = hwif->drives[1].max_failures + 1; | ||
569 | break; | ||
570 | default: | ||
571 | return -EINVAL; | ||
572 | } | ||
573 | hwif->bus_state = state; | ||
574 | return 0; | ||
575 | } | ||
576 | |||
577 | /** | ||
578 | * siimage_reset_poll - wait for sata reset | ||
579 | * @drive: drive we are resetting | ||
580 | * | ||
581 | * Poll the SATA phy and see whether it has come back from the dead | ||
582 | * yet. | ||
583 | */ | ||
584 | |||
585 | static int siimage_reset_poll (ide_drive_t *drive) | ||
586 | { | ||
587 | if (SATA_STATUS_REG) { | ||
588 | ide_hwif_t *hwif = HWIF(drive); | ||
589 | |||
590 | if ((hwif->INL(SATA_STATUS_REG) & 0x03) != 0x03) { | ||
591 | printk(KERN_WARNING "%s: reset phy dead, status=0x%08x\n", | ||
592 | hwif->name, hwif->INL(SATA_STATUS_REG)); | ||
593 | HWGROUP(drive)->polling = 0; | ||
594 | return ide_started; | ||
595 | } | ||
596 | return 0; | ||
597 | } else { | ||
598 | return 0; | ||
599 | } | ||
600 | } | ||
601 | |||
602 | /** | ||
603 | * siimage_pre_reset - reset hook | ||
604 | * @drive: IDE device being reset | ||
605 | * | ||
606 | * For the SATA devices we need to handle recalibration/geometry | ||
607 | * differently | ||
608 | */ | ||
609 | |||
610 | static void siimage_pre_reset (ide_drive_t *drive) | ||
611 | { | ||
612 | if (drive->media != ide_disk) | ||
613 | return; | ||
614 | |||
615 | if (is_sata(HWIF(drive))) | ||
616 | { | ||
617 | drive->special.b.set_geometry = 0; | ||
618 | drive->special.b.recalibrate = 0; | ||
619 | } | ||
620 | } | ||
621 | |||
622 | /** | ||
623 | * siimage_reset - reset a device on an siimage controller | ||
624 | * @drive: drive to reset | ||
625 | * | ||
626 | * Perform a controller level reset fo the device. For | ||
627 | * SATA we must also check the PHY. | ||
628 | */ | ||
629 | |||
630 | static void siimage_reset (ide_drive_t *drive) | ||
631 | { | ||
632 | ide_hwif_t *hwif = HWIF(drive); | ||
633 | u8 reset = 0; | ||
634 | unsigned long addr = siimage_selreg(hwif, 0); | ||
635 | |||
636 | if (hwif->mmio) { | ||
637 | reset = hwif->INB(addr); | ||
638 | hwif->OUTB((reset|0x03), addr); | ||
639 | /* FIXME:posting */ | ||
640 | udelay(25); | ||
641 | hwif->OUTB(reset, addr); | ||
642 | (void) hwif->INB(addr); | ||
643 | } else { | ||
644 | pci_read_config_byte(hwif->pci_dev, addr, &reset); | ||
645 | pci_write_config_byte(hwif->pci_dev, addr, reset|0x03); | ||
646 | udelay(25); | ||
647 | pci_write_config_byte(hwif->pci_dev, addr, reset); | ||
648 | pci_read_config_byte(hwif->pci_dev, addr, &reset); | ||
649 | } | ||
650 | |||
651 | if (SATA_STATUS_REG) { | ||
652 | u32 sata_stat = hwif->INL(SATA_STATUS_REG); | ||
653 | printk(KERN_WARNING "%s: reset phy, status=0x%08x, %s\n", | ||
654 | hwif->name, sata_stat, __FUNCTION__); | ||
655 | if (!(sata_stat)) { | ||
656 | printk(KERN_WARNING "%s: reset phy dead, status=0x%08x\n", | ||
657 | hwif->name, sata_stat); | ||
658 | drive->failures++; | ||
659 | } | ||
660 | } | ||
661 | |||
662 | } | ||
663 | |||
664 | /** | ||
665 | * proc_reports_siimage - add siimage controller to proc | ||
666 | * @dev: PCI device | ||
667 | * @clocking: SCSC value | ||
668 | * @name: controller name | ||
669 | * | ||
670 | * Report the clocking mode of the controller and add it to | ||
671 | * the /proc interface layer | ||
672 | */ | ||
673 | |||
674 | static void proc_reports_siimage (struct pci_dev *dev, u8 clocking, const char *name) | ||
675 | { | ||
676 | if (!pdev_is_sata(dev)) { | ||
677 | printk(KERN_INFO "%s: BASE CLOCK ", name); | ||
678 | clocking &= 0x03; | ||
679 | switch (clocking) { | ||
680 | case 0x03: printk("DISABLED!\n"); break; | ||
681 | case 0x02: printk("== 2X PCI\n"); break; | ||
682 | case 0x01: printk("== 133\n"); break; | ||
683 | case 0x00: printk("== 100\n"); break; | ||
684 | } | ||
685 | } | ||
686 | } | ||
687 | |||
688 | /** | ||
689 | * setup_mmio_siimage - switch an SI controller into MMIO | ||
690 | * @dev: PCI device we are configuring | ||
691 | * @name: device name | ||
692 | * | ||
693 | * Attempt to put the device into mmio mode. There are some slight | ||
694 | * complications here with certain systems where the mmio bar isnt | ||
695 | * mapped so we have to be sure we can fall back to I/O. | ||
696 | */ | ||
697 | |||
698 | static unsigned int setup_mmio_siimage (struct pci_dev *dev, const char *name) | ||
699 | { | ||
700 | unsigned long bar5 = pci_resource_start(dev, 5); | ||
701 | unsigned long barsize = pci_resource_len(dev, 5); | ||
702 | u8 tmpbyte = 0; | ||
703 | void __iomem *ioaddr; | ||
704 | |||
705 | /* | ||
706 | * Drop back to PIO if we can't map the mmio. Some | ||
707 | * systems seem to get terminally confused in the PCI | ||
708 | * spaces. | ||
709 | */ | ||
710 | |||
711 | if(!request_mem_region(bar5, barsize, name)) | ||
712 | { | ||
713 | printk(KERN_WARNING "siimage: IDE controller MMIO ports not available.\n"); | ||
714 | return 0; | ||
715 | } | ||
716 | |||
717 | ioaddr = ioremap(bar5, barsize); | ||
718 | |||
719 | if (ioaddr == NULL) | ||
720 | { | ||
721 | release_mem_region(bar5, barsize); | ||
722 | return 0; | ||
723 | } | ||
724 | |||
725 | pci_set_master(dev); | ||
726 | pci_set_drvdata(dev, (void *) ioaddr); | ||
727 | |||
728 | if (pdev_is_sata(dev)) { | ||
729 | writel(0, ioaddr + 0x148); | ||
730 | writel(0, ioaddr + 0x1C8); | ||
731 | } | ||
732 | |||
733 | writeb(0, ioaddr + 0xB4); | ||
734 | writeb(0, ioaddr + 0xF4); | ||
735 | tmpbyte = readb(ioaddr + 0x4A); | ||
736 | |||
737 | switch(tmpbyte & 0x30) { | ||
738 | case 0x00: | ||
739 | /* In 100 MHz clocking, try and switch to 133 */ | ||
740 | writeb(tmpbyte|0x10, ioaddr + 0x4A); | ||
741 | break; | ||
742 | case 0x10: | ||
743 | /* On 133Mhz clocking */ | ||
744 | break; | ||
745 | case 0x20: | ||
746 | /* On PCIx2 clocking */ | ||
747 | break; | ||
748 | case 0x30: | ||
749 | /* Clocking is disabled */ | ||
750 | /* 133 clock attempt to force it on */ | ||
751 | writeb(tmpbyte & ~0x20, ioaddr + 0x4A); | ||
752 | break; | ||
753 | } | ||
754 | |||
755 | writeb( 0x72, ioaddr + 0xA1); | ||
756 | writew( 0x328A, ioaddr + 0xA2); | ||
757 | writel(0x62DD62DD, ioaddr + 0xA4); | ||
758 | writel(0x43924392, ioaddr + 0xA8); | ||
759 | writel(0x40094009, ioaddr + 0xAC); | ||
760 | writeb( 0x72, ioaddr + 0xE1); | ||
761 | writew( 0x328A, ioaddr + 0xE2); | ||
762 | writel(0x62DD62DD, ioaddr + 0xE4); | ||
763 | writel(0x43924392, ioaddr + 0xE8); | ||
764 | writel(0x40094009, ioaddr + 0xEC); | ||
765 | |||
766 | if (pdev_is_sata(dev)) { | ||
767 | writel(0xFFFF0000, ioaddr + 0x108); | ||
768 | writel(0xFFFF0000, ioaddr + 0x188); | ||
769 | writel(0x00680000, ioaddr + 0x148); | ||
770 | writel(0x00680000, ioaddr + 0x1C8); | ||
771 | } | ||
772 | |||
773 | tmpbyte = readb(ioaddr + 0x4A); | ||
774 | |||
775 | proc_reports_siimage(dev, (tmpbyte>>4), name); | ||
776 | return 1; | ||
777 | } | ||
778 | |||
779 | /** | ||
780 | * init_chipset_siimage - set up an SI device | ||
781 | * @dev: PCI device | ||
782 | * @name: device name | ||
783 | * | ||
784 | * Perform the initial PCI set up for this device. Attempt to switch | ||
785 | * to 133MHz clocking if the system isn't already set up to do it. | ||
786 | */ | ||
787 | |||
788 | static unsigned int __devinit init_chipset_siimage(struct pci_dev *dev, const char *name) | ||
789 | { | ||
790 | u32 class_rev = 0; | ||
791 | u8 tmpbyte = 0; | ||
792 | u8 BA5_EN = 0; | ||
793 | |||
794 | pci_read_config_dword(dev, PCI_CLASS_REVISION, &class_rev); | ||
795 | class_rev &= 0xff; | ||
796 | pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, (class_rev) ? 1 : 255); | ||
797 | |||
798 | pci_read_config_byte(dev, 0x8A, &BA5_EN); | ||
799 | if ((BA5_EN & 0x01) || (pci_resource_start(dev, 5))) { | ||
800 | if (setup_mmio_siimage(dev, name)) { | ||
801 | return 0; | ||
802 | } | ||
803 | } | ||
804 | |||
805 | pci_write_config_byte(dev, 0x80, 0x00); | ||
806 | pci_write_config_byte(dev, 0x84, 0x00); | ||
807 | pci_read_config_byte(dev, 0x8A, &tmpbyte); | ||
808 | switch(tmpbyte & 0x30) { | ||
809 | case 0x00: | ||
810 | /* 133 clock attempt to force it on */ | ||
811 | pci_write_config_byte(dev, 0x8A, tmpbyte|0x10); | ||
812 | case 0x30: | ||
813 | /* if clocking is disabled */ | ||
814 | /* 133 clock attempt to force it on */ | ||
815 | pci_write_config_byte(dev, 0x8A, tmpbyte & ~0x20); | ||
816 | case 0x10: | ||
817 | /* 133 already */ | ||
818 | break; | ||
819 | case 0x20: | ||
820 | /* BIOS set PCI x2 clocking */ | ||
821 | break; | ||
822 | } | ||
823 | |||
824 | pci_read_config_byte(dev, 0x8A, &tmpbyte); | ||
825 | |||
826 | pci_write_config_byte(dev, 0xA1, 0x72); | ||
827 | pci_write_config_word(dev, 0xA2, 0x328A); | ||
828 | pci_write_config_dword(dev, 0xA4, 0x62DD62DD); | ||
829 | pci_write_config_dword(dev, 0xA8, 0x43924392); | ||
830 | pci_write_config_dword(dev, 0xAC, 0x40094009); | ||
831 | pci_write_config_byte(dev, 0xB1, 0x72); | ||
832 | pci_write_config_word(dev, 0xB2, 0x328A); | ||
833 | pci_write_config_dword(dev, 0xB4, 0x62DD62DD); | ||
834 | pci_write_config_dword(dev, 0xB8, 0x43924392); | ||
835 | pci_write_config_dword(dev, 0xBC, 0x40094009); | ||
836 | |||
837 | proc_reports_siimage(dev, (tmpbyte>>4), name); | ||
838 | return 0; | ||
839 | } | ||
840 | |||
841 | /** | ||
842 | * init_mmio_iops_siimage - set up the iops for MMIO | ||
843 | * @hwif: interface to set up | ||
844 | * | ||
845 | * The basic setup here is fairly simple, we can use standard MMIO | ||
846 | * operations. However we do have to set the taskfile register offsets | ||
847 | * by hand as there isnt a standard defined layout for them this | ||
848 | * time. | ||
849 | * | ||
850 | * The hardware supports buffered taskfiles and also some rather nice | ||
851 | * extended PRD tables. Unfortunately right now we don't. | ||
852 | */ | ||
853 | |||
854 | static void __devinit init_mmio_iops_siimage(ide_hwif_t *hwif) | ||
855 | { | ||
856 | struct pci_dev *dev = hwif->pci_dev; | ||
857 | void *addr = pci_get_drvdata(dev); | ||
858 | u8 ch = hwif->channel; | ||
859 | hw_regs_t hw; | ||
860 | unsigned long base; | ||
861 | |||
862 | /* | ||
863 | * Fill in the basic HWIF bits | ||
864 | */ | ||
865 | |||
866 | default_hwif_mmiops(hwif); | ||
867 | hwif->hwif_data = addr; | ||
868 | |||
869 | /* | ||
870 | * Now set up the hw. We have to do this ourselves as | ||
871 | * the MMIO layout isnt the same as the the standard port | ||
872 | * based I/O | ||
873 | */ | ||
874 | |||
875 | memset(&hw, 0, sizeof(hw_regs_t)); | ||
876 | |||
877 | base = (unsigned long)addr; | ||
878 | if (ch) | ||
879 | base += 0xC0; | ||
880 | else | ||
881 | base += 0x80; | ||
882 | |||
883 | /* | ||
884 | * The buffered task file doesn't have status/control | ||
885 | * so we can't currently use it sanely since we want to | ||
886 | * use LBA48 mode. | ||
887 | */ | ||
888 | // base += 0x10; | ||
889 | // hwif->no_lba48 = 1; | ||
890 | |||
891 | hw.io_ports[IDE_DATA_OFFSET] = base; | ||
892 | hw.io_ports[IDE_ERROR_OFFSET] = base + 1; | ||
893 | hw.io_ports[IDE_NSECTOR_OFFSET] = base + 2; | ||
894 | hw.io_ports[IDE_SECTOR_OFFSET] = base + 3; | ||
895 | hw.io_ports[IDE_LCYL_OFFSET] = base + 4; | ||
896 | hw.io_ports[IDE_HCYL_OFFSET] = base + 5; | ||
897 | hw.io_ports[IDE_SELECT_OFFSET] = base + 6; | ||
898 | hw.io_ports[IDE_STATUS_OFFSET] = base + 7; | ||
899 | hw.io_ports[IDE_CONTROL_OFFSET] = base + 10; | ||
900 | |||
901 | hw.io_ports[IDE_IRQ_OFFSET] = 0; | ||
902 | |||
903 | if (pdev_is_sata(dev)) { | ||
904 | base = (unsigned long)addr; | ||
905 | if (ch) | ||
906 | base += 0x80; | ||
907 | hwif->sata_scr[SATA_STATUS_OFFSET] = base + 0x104; | ||
908 | hwif->sata_scr[SATA_ERROR_OFFSET] = base + 0x108; | ||
909 | hwif->sata_scr[SATA_CONTROL_OFFSET] = base + 0x100; | ||
910 | hwif->sata_misc[SATA_MISC_OFFSET] = base + 0x140; | ||
911 | hwif->sata_misc[SATA_PHY_OFFSET] = base + 0x144; | ||
912 | hwif->sata_misc[SATA_IEN_OFFSET] = base + 0x148; | ||
913 | } | ||
914 | |||
915 | hw.irq = hwif->pci_dev->irq; | ||
916 | |||
917 | memcpy(&hwif->hw, &hw, sizeof(hw)); | ||
918 | memcpy(hwif->io_ports, hwif->hw.io_ports, sizeof(hwif->hw.io_ports)); | ||
919 | |||
920 | hwif->irq = hw.irq; | ||
921 | |||
922 | base = (unsigned long) addr; | ||
923 | |||
924 | #ifdef SIIMAGE_LARGE_DMA | ||
925 | /* Watch the brackets - even Ken and Dennis get some language design wrong */ | ||
926 | hwif->dma_base = base + (ch ? 0x18 : 0x10); | ||
927 | hwif->dma_base2 = base + (ch ? 0x08 : 0x00); | ||
928 | hwif->dma_prdtable = hwif->dma_base2 + 4; | ||
929 | #else /* ! SIIMAGE_LARGE_DMA */ | ||
930 | hwif->dma_base = base + (ch ? 0x08 : 0x00); | ||
931 | hwif->dma_base2 = base + (ch ? 0x18 : 0x10); | ||
932 | #endif /* SIIMAGE_LARGE_DMA */ | ||
933 | hwif->mmio = 2; | ||
934 | } | ||
935 | |||
936 | static int is_dev_seagate_sata(ide_drive_t *drive) | ||
937 | { | ||
938 | const char *s = &drive->id->model[0]; | ||
939 | unsigned len; | ||
940 | |||
941 | if (!drive->present) | ||
942 | return 0; | ||
943 | |||
944 | len = strnlen(s, sizeof(drive->id->model)); | ||
945 | |||
946 | if ((len > 4) && (!memcmp(s, "ST", 2))) { | ||
947 | if ((!memcmp(s + len - 2, "AS", 2)) || | ||
948 | (!memcmp(s + len - 3, "ASL", 3))) { | ||
949 | printk(KERN_INFO "%s: applying pessimistic Seagate " | ||
950 | "errata fix\n", drive->name); | ||
951 | return 1; | ||
952 | } | ||
953 | } | ||
954 | return 0; | ||
955 | } | ||
956 | |||
957 | /** | ||
958 | * siimage_fixup - post probe fixups | ||
959 | * @hwif: interface to fix up | ||
960 | * | ||
961 | * Called after drive probe we use this to decide whether the | ||
962 | * Seagate fixup must be applied. This used to be in init_iops but | ||
963 | * that can occur before we know what drives are present. | ||
964 | */ | ||
965 | |||
966 | static void __devinit siimage_fixup(ide_hwif_t *hwif) | ||
967 | { | ||
968 | /* Try and raise the rqsize */ | ||
969 | if (!is_sata(hwif) || !is_dev_seagate_sata(&hwif->drives[0])) | ||
970 | hwif->rqsize = 128; | ||
971 | } | ||
972 | |||
973 | /** | ||
974 | * init_iops_siimage - set up iops | ||
975 | * @hwif: interface to set up | ||
976 | * | ||
977 | * Do the basic setup for the SIIMAGE hardware interface | ||
978 | * and then do the MMIO setup if we can. This is the first | ||
979 | * look in we get for setting up the hwif so that we | ||
980 | * can get the iops right before using them. | ||
981 | */ | ||
982 | |||
983 | static void __devinit init_iops_siimage(ide_hwif_t *hwif) | ||
984 | { | ||
985 | struct pci_dev *dev = hwif->pci_dev; | ||
986 | u32 class_rev = 0; | ||
987 | |||
988 | pci_read_config_dword(dev, PCI_CLASS_REVISION, &class_rev); | ||
989 | class_rev &= 0xff; | ||
990 | |||
991 | hwif->hwif_data = NULL; | ||
992 | |||
993 | /* Pessimal until we finish probing */ | ||
994 | hwif->rqsize = 15; | ||
995 | |||
996 | if (pci_get_drvdata(dev) == NULL) | ||
997 | return; | ||
998 | init_mmio_iops_siimage(hwif); | ||
999 | } | ||
1000 | |||
1001 | /** | ||
1002 | * ata66_siimage - check for 80 pin cable | ||
1003 | * @hwif: interface to check | ||
1004 | * | ||
1005 | * Check for the presence of an ATA66 capable cable on the | ||
1006 | * interface. | ||
1007 | */ | ||
1008 | |||
1009 | static unsigned int __devinit ata66_siimage(ide_hwif_t *hwif) | ||
1010 | { | ||
1011 | unsigned long addr = siimage_selreg(hwif, 0); | ||
1012 | if (pci_get_drvdata(hwif->pci_dev) == NULL) { | ||
1013 | u8 ata66 = 0; | ||
1014 | pci_read_config_byte(hwif->pci_dev, addr, &ata66); | ||
1015 | return (ata66 & 0x01) ? 1 : 0; | ||
1016 | } | ||
1017 | |||
1018 | return (hwif->INB(addr) & 0x01) ? 1 : 0; | ||
1019 | } | ||
1020 | |||
1021 | /** | ||
1022 | * init_hwif_siimage - set up hwif structs | ||
1023 | * @hwif: interface to set up | ||
1024 | * | ||
1025 | * We do the basic set up of the interface structure. The SIIMAGE | ||
1026 | * requires several custom handlers so we override the default | ||
1027 | * ide DMA handlers appropriately | ||
1028 | */ | ||
1029 | |||
1030 | static void __devinit init_hwif_siimage(ide_hwif_t *hwif) | ||
1031 | { | ||
1032 | hwif->autodma = 0; | ||
1033 | |||
1034 | hwif->resetproc = &siimage_reset; | ||
1035 | hwif->speedproc = &siimage_tune_chipset; | ||
1036 | hwif->tuneproc = &siimage_tuneproc; | ||
1037 | hwif->reset_poll = &siimage_reset_poll; | ||
1038 | hwif->pre_reset = &siimage_pre_reset; | ||
1039 | |||
1040 | if(is_sata(hwif)) | ||
1041 | hwif->busproc = &siimage_busproc; | ||
1042 | |||
1043 | if (!hwif->dma_base) { | ||
1044 | hwif->drives[0].autotune = 1; | ||
1045 | hwif->drives[1].autotune = 1; | ||
1046 | return; | ||
1047 | } | ||
1048 | |||
1049 | hwif->ultra_mask = 0x7f; | ||
1050 | hwif->mwdma_mask = 0x07; | ||
1051 | hwif->swdma_mask = 0x07; | ||
1052 | |||
1053 | if (!is_sata(hwif)) | ||
1054 | hwif->atapi_dma = 1; | ||
1055 | |||
1056 | hwif->ide_dma_check = &siimage_config_drive_for_dma; | ||
1057 | if (!(hwif->udma_four)) | ||
1058 | hwif->udma_four = ata66_siimage(hwif); | ||
1059 | |||
1060 | if (hwif->mmio) { | ||
1061 | hwif->ide_dma_test_irq = &siimage_mmio_ide_dma_test_irq; | ||
1062 | } else { | ||
1063 | hwif->ide_dma_test_irq = & siimage_io_ide_dma_test_irq; | ||
1064 | } | ||
1065 | |||
1066 | /* | ||
1067 | * The BIOS often doesn't set up DMA on this controller | ||
1068 | * so we always do it. | ||
1069 | */ | ||
1070 | |||
1071 | hwif->autodma = 1; | ||
1072 | hwif->drives[0].autodma = hwif->autodma; | ||
1073 | hwif->drives[1].autodma = hwif->autodma; | ||
1074 | } | ||
1075 | |||
1076 | #define DECLARE_SII_DEV(name_str) \ | ||
1077 | { \ | ||
1078 | .name = name_str, \ | ||
1079 | .init_chipset = init_chipset_siimage, \ | ||
1080 | .init_iops = init_iops_siimage, \ | ||
1081 | .init_hwif = init_hwif_siimage, \ | ||
1082 | .fixup = siimage_fixup, \ | ||
1083 | .channels = 2, \ | ||
1084 | .autodma = AUTODMA, \ | ||
1085 | .bootable = ON_BOARD, \ | ||
1086 | } | ||
1087 | |||
1088 | static ide_pci_device_t siimage_chipsets[] __devinitdata = { | ||
1089 | /* 0 */ DECLARE_SII_DEV("SiI680"), | ||
1090 | /* 1 */ DECLARE_SII_DEV("SiI3112 Serial ATA"), | ||
1091 | /* 2 */ DECLARE_SII_DEV("Adaptec AAR-1210SA") | ||
1092 | }; | ||
1093 | |||
1094 | /** | ||
1095 | * siimage_init_one - pci layer discovery entry | ||
1096 | * @dev: PCI device | ||
1097 | * @id: ident table entry | ||
1098 | * | ||
1099 | * Called by the PCI code when it finds an SI680 or SI3112 controller. | ||
1100 | * We then use the IDE PCI generic helper to do most of the work. | ||
1101 | */ | ||
1102 | |||
1103 | static int __devinit siimage_init_one(struct pci_dev *dev, const struct pci_device_id *id) | ||
1104 | { | ||
1105 | return ide_setup_pci_device(dev, &siimage_chipsets[id->driver_data]); | ||
1106 | } | ||
1107 | |||
1108 | static struct pci_device_id siimage_pci_tbl[] = { | ||
1109 | { PCI_VENDOR_ID_CMD, PCI_DEVICE_ID_SII_680, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, | ||
1110 | #ifdef CONFIG_BLK_DEV_IDE_SATA | ||
1111 | { PCI_VENDOR_ID_CMD, PCI_DEVICE_ID_SII_3112, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1}, | ||
1112 | { PCI_VENDOR_ID_CMD, PCI_DEVICE_ID_SII_1210SA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2}, | ||
1113 | #endif | ||
1114 | { 0, }, | ||
1115 | }; | ||
1116 | MODULE_DEVICE_TABLE(pci, siimage_pci_tbl); | ||
1117 | |||
1118 | static struct pci_driver driver = { | ||
1119 | .name = "SiI_IDE", | ||
1120 | .id_table = siimage_pci_tbl, | ||
1121 | .probe = siimage_init_one, | ||
1122 | }; | ||
1123 | |||
1124 | static int siimage_ide_init(void) | ||
1125 | { | ||
1126 | return ide_pci_register_driver(&driver); | ||
1127 | } | ||
1128 | |||
1129 | module_init(siimage_ide_init); | ||
1130 | |||
1131 | MODULE_AUTHOR("Andre Hedrick, Alan Cox"); | ||
1132 | MODULE_DESCRIPTION("PCI driver module for SiI IDE"); | ||
1133 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/ide/pci/sis5513.c b/drivers/ide/pci/sis5513.c new file mode 100644 index 000000000000..9d70ba5ea59b --- /dev/null +++ b/drivers/ide/pci/sis5513.c | |||
@@ -0,0 +1,984 @@ | |||
1 | /* | ||
2 | * linux/drivers/ide/pci/sis5513.c Version 0.16ac+vp Jun 18, 2003 | ||
3 | * | ||
4 | * Copyright (C) 1999-2000 Andre Hedrick <andre@linux-ide.org> | ||
5 | * Copyright (C) 2002 Lionel Bouton <Lionel.Bouton@inet6.fr>, Maintainer | ||
6 | * Copyright (C) 2003 Vojtech Pavlik <vojtech@suse.cz> | ||
7 | * May be copied or modified under the terms of the GNU General Public License | ||
8 | * | ||
9 | * | ||
10 | * Thanks : | ||
11 | * | ||
12 | * SiS Taiwan : for direct support and hardware. | ||
13 | * Daniela Engert : for initial ATA100 advices and numerous others. | ||
14 | * John Fremlin, Manfred Spraul, Dave Morgan, Peter Kjellerstedt : | ||
15 | * for checking code correctness, providing patches. | ||
16 | * | ||
17 | * | ||
18 | * Original tests and design on the SiS620 chipset. | ||
19 | * ATA100 tests and design on the SiS735 chipset. | ||
20 | * ATA16/33 support from specs | ||
21 | * ATA133 support for SiS961/962 by L.C. Chang <lcchang@sis.com.tw> | ||
22 | * ATA133 961/962/963 fixes by Vojtech Pavlik <vojtech@suse.cz> | ||
23 | * | ||
24 | * Documentation: | ||
25 | * SiS chipset documentation available under NDA to companies only | ||
26 | * (not to individuals). | ||
27 | */ | ||
28 | |||
29 | /* | ||
30 | * The original SiS5513 comes from a SiS5511/55112/5513 chipset. The original | ||
31 | * SiS5513 was also used in the SiS5596/5513 chipset. Thus if we see a SiS5511 | ||
32 | * or SiS5596, we can assume we see the first MWDMA-16 capable SiS5513 chip. | ||
33 | * | ||
34 | * Later SiS chipsets integrated the 5513 functionality into the NorthBridge, | ||
35 | * starting with SiS5571 and up to SiS745. The PCI ID didn't change, though. We | ||
36 | * can figure out that we have a more modern and more capable 5513 by looking | ||
37 | * for the respective NorthBridge IDs. | ||
38 | * | ||
39 | * Even later (96x family) SiS chipsets use the MuTIOL link and place the 5513 | ||
40 | * into the SouthBrige. Here we cannot rely on looking up the NorthBridge PCI | ||
41 | * ID, while the now ATA-133 capable 5513 still has the same PCI ID. | ||
42 | * Fortunately the 5513 can be 'unmasked' by fiddling with some config space | ||
43 | * bits, changing its device id to the true one - 5517 for 961 and 5518 for | ||
44 | * 962/963. | ||
45 | */ | ||
46 | |||
47 | #include <linux/config.h> | ||
48 | #include <linux/types.h> | ||
49 | #include <linux/module.h> | ||
50 | #include <linux/kernel.h> | ||
51 | #include <linux/delay.h> | ||
52 | #include <linux/timer.h> | ||
53 | #include <linux/mm.h> | ||
54 | #include <linux/ioport.h> | ||
55 | #include <linux/blkdev.h> | ||
56 | #include <linux/hdreg.h> | ||
57 | |||
58 | #include <linux/interrupt.h> | ||
59 | #include <linux/pci.h> | ||
60 | #include <linux/init.h> | ||
61 | #include <linux/ide.h> | ||
62 | |||
63 | #include <asm/irq.h> | ||
64 | |||
65 | #include "ide-timing.h" | ||
66 | |||
67 | #define DISPLAY_SIS_TIMINGS | ||
68 | |||
69 | /* registers layout and init values are chipset family dependant */ | ||
70 | |||
71 | #define ATA_16 0x01 | ||
72 | #define ATA_33 0x02 | ||
73 | #define ATA_66 0x03 | ||
74 | #define ATA_100a 0x04 // SiS730/SiS550 is ATA100 with ATA66 layout | ||
75 | #define ATA_100 0x05 | ||
76 | #define ATA_133a 0x06 // SiS961b with 133 support | ||
77 | #define ATA_133 0x07 // SiS962/963 | ||
78 | |||
79 | static u8 chipset_family; | ||
80 | |||
81 | /* | ||
82 | * Devices supported | ||
83 | */ | ||
84 | static const struct { | ||
85 | const char *name; | ||
86 | u16 host_id; | ||
87 | u8 chipset_family; | ||
88 | u8 flags; | ||
89 | } SiSHostChipInfo[] = { | ||
90 | { "SiS745", PCI_DEVICE_ID_SI_745, ATA_100 }, | ||
91 | { "SiS735", PCI_DEVICE_ID_SI_735, ATA_100 }, | ||
92 | { "SiS733", PCI_DEVICE_ID_SI_733, ATA_100 }, | ||
93 | { "SiS635", PCI_DEVICE_ID_SI_635, ATA_100 }, | ||
94 | { "SiS633", PCI_DEVICE_ID_SI_633, ATA_100 }, | ||
95 | |||
96 | { "SiS730", PCI_DEVICE_ID_SI_730, ATA_100a }, | ||
97 | { "SiS550", PCI_DEVICE_ID_SI_550, ATA_100a }, | ||
98 | |||
99 | { "SiS640", PCI_DEVICE_ID_SI_640, ATA_66 }, | ||
100 | { "SiS630", PCI_DEVICE_ID_SI_630, ATA_66 }, | ||
101 | { "SiS620", PCI_DEVICE_ID_SI_620, ATA_66 }, | ||
102 | { "SiS540", PCI_DEVICE_ID_SI_540, ATA_66 }, | ||
103 | { "SiS530", PCI_DEVICE_ID_SI_530, ATA_66 }, | ||
104 | |||
105 | { "SiS5600", PCI_DEVICE_ID_SI_5600, ATA_33 }, | ||
106 | { "SiS5598", PCI_DEVICE_ID_SI_5598, ATA_33 }, | ||
107 | { "SiS5597", PCI_DEVICE_ID_SI_5597, ATA_33 }, | ||
108 | { "SiS5591/2", PCI_DEVICE_ID_SI_5591, ATA_33 }, | ||
109 | { "SiS5582", PCI_DEVICE_ID_SI_5582, ATA_33 }, | ||
110 | { "SiS5581", PCI_DEVICE_ID_SI_5581, ATA_33 }, | ||
111 | |||
112 | { "SiS5596", PCI_DEVICE_ID_SI_5596, ATA_16 }, | ||
113 | { "SiS5571", PCI_DEVICE_ID_SI_5571, ATA_16 }, | ||
114 | { "SiS551x", PCI_DEVICE_ID_SI_5511, ATA_16 }, | ||
115 | }; | ||
116 | |||
117 | /* Cycle time bits and values vary across chip dma capabilities | ||
118 | These three arrays hold the register layout and the values to set. | ||
119 | Indexed by chipset_family and (dma_mode - XFER_UDMA_0) */ | ||
120 | |||
121 | /* {0, ATA_16, ATA_33, ATA_66, ATA_100a, ATA_100, ATA_133} */ | ||
122 | static u8 cycle_time_offset[] = {0,0,5,4,4,0,0}; | ||
123 | static u8 cycle_time_range[] = {0,0,2,3,3,4,4}; | ||
124 | static u8 cycle_time_value[][XFER_UDMA_6 - XFER_UDMA_0 + 1] = { | ||
125 | {0,0,0,0,0,0,0}, /* no udma */ | ||
126 | {0,0,0,0,0,0,0}, /* no udma */ | ||
127 | {3,2,1,0,0,0,0}, /* ATA_33 */ | ||
128 | {7,5,3,2,1,0,0}, /* ATA_66 */ | ||
129 | {7,5,3,2,1,0,0}, /* ATA_100a (730 specific), differences are on cycle_time range and offset */ | ||
130 | {11,7,5,4,2,1,0}, /* ATA_100 */ | ||
131 | {15,10,7,5,3,2,1}, /* ATA_133a (earliest 691 southbridges) */ | ||
132 | {15,10,7,5,3,2,1}, /* ATA_133 */ | ||
133 | }; | ||
134 | /* CRC Valid Setup Time vary across IDE clock setting 33/66/100/133 | ||
135 | See SiS962 data sheet for more detail */ | ||
136 | static u8 cvs_time_value[][XFER_UDMA_6 - XFER_UDMA_0 + 1] = { | ||
137 | {0,0,0,0,0,0,0}, /* no udma */ | ||
138 | {0,0,0,0,0,0,0}, /* no udma */ | ||
139 | {2,1,1,0,0,0,0}, | ||
140 | {4,3,2,1,0,0,0}, | ||
141 | {4,3,2,1,0,0,0}, | ||
142 | {6,4,3,1,1,1,0}, | ||
143 | {9,6,4,2,2,2,2}, | ||
144 | {9,6,4,2,2,2,2}, | ||
145 | }; | ||
146 | /* Initialize time, Active time, Recovery time vary across | ||
147 | IDE clock settings. These 3 arrays hold the register value | ||
148 | for PIO0/1/2/3/4 and DMA0/1/2 mode in order */ | ||
149 | static u8 ini_time_value[][8] = { | ||
150 | {0,0,0,0,0,0,0,0}, | ||
151 | {0,0,0,0,0,0,0,0}, | ||
152 | {2,1,0,0,0,1,0,0}, | ||
153 | {4,3,1,1,1,3,1,1}, | ||
154 | {4,3,1,1,1,3,1,1}, | ||
155 | {6,4,2,2,2,4,2,2}, | ||
156 | {9,6,3,3,3,6,3,3}, | ||
157 | {9,6,3,3,3,6,3,3}, | ||
158 | }; | ||
159 | static u8 act_time_value[][8] = { | ||
160 | {0,0,0,0,0,0,0,0}, | ||
161 | {0,0,0,0,0,0,0,0}, | ||
162 | {9,9,9,2,2,7,2,2}, | ||
163 | {19,19,19,5,4,14,5,4}, | ||
164 | {19,19,19,5,4,14,5,4}, | ||
165 | {28,28,28,7,6,21,7,6}, | ||
166 | {38,38,38,10,9,28,10,9}, | ||
167 | {38,38,38,10,9,28,10,9}, | ||
168 | }; | ||
169 | static u8 rco_time_value[][8] = { | ||
170 | {0,0,0,0,0,0,0,0}, | ||
171 | {0,0,0,0,0,0,0,0}, | ||
172 | {9,2,0,2,0,7,1,1}, | ||
173 | {19,5,1,5,2,16,3,2}, | ||
174 | {19,5,1,5,2,16,3,2}, | ||
175 | {30,9,3,9,4,25,6,4}, | ||
176 | {40,12,4,12,5,34,12,5}, | ||
177 | {40,12,4,12,5,34,12,5}, | ||
178 | }; | ||
179 | |||
180 | /* | ||
181 | * Printing configuration | ||
182 | */ | ||
183 | /* Used for chipset type printing at boot time */ | ||
184 | static char* chipset_capability[] = { | ||
185 | "ATA", "ATA 16", | ||
186 | "ATA 33", "ATA 66", | ||
187 | "ATA 100 (1st gen)", "ATA 100 (2nd gen)", | ||
188 | "ATA 133 (1st gen)", "ATA 133 (2nd gen)" | ||
189 | }; | ||
190 | |||
191 | #if defined(DISPLAY_SIS_TIMINGS) && defined(CONFIG_PROC_FS) | ||
192 | #include <linux/stat.h> | ||
193 | #include <linux/proc_fs.h> | ||
194 | |||
195 | static u8 sis_proc = 0; | ||
196 | |||
197 | static struct pci_dev *bmide_dev; | ||
198 | |||
199 | static char* cable_type[] = { | ||
200 | "80 pins", | ||
201 | "40 pins" | ||
202 | }; | ||
203 | |||
204 | static char* recovery_time[] ={ | ||
205 | "12 PCICLK", "1 PCICLK", | ||
206 | "2 PCICLK", "3 PCICLK", | ||
207 | "4 PCICLK", "5 PCICLCK", | ||
208 | "6 PCICLK", "7 PCICLCK", | ||
209 | "8 PCICLK", "9 PCICLCK", | ||
210 | "10 PCICLK", "11 PCICLK", | ||
211 | "13 PCICLK", "14 PCICLK", | ||
212 | "15 PCICLK", "15 PCICLK" | ||
213 | }; | ||
214 | |||
215 | static char* active_time[] = { | ||
216 | "8 PCICLK", "1 PCICLCK", | ||
217 | "2 PCICLK", "3 PCICLK", | ||
218 | "4 PCICLK", "5 PCICLK", | ||
219 | "6 PCICLK", "12 PCICLK" | ||
220 | }; | ||
221 | |||
222 | static char* cycle_time[] = { | ||
223 | "Reserved", "2 CLK", | ||
224 | "3 CLK", "4 CLK", | ||
225 | "5 CLK", "6 CLK", | ||
226 | "7 CLK", "8 CLK", | ||
227 | "9 CLK", "10 CLK", | ||
228 | "11 CLK", "12 CLK", | ||
229 | "13 CLK", "14 CLK", | ||
230 | "15 CLK", "16 CLK" | ||
231 | }; | ||
232 | |||
233 | /* Generic add master or slave info function */ | ||
234 | static char* get_drives_info (char *buffer, u8 pos) | ||
235 | { | ||
236 | u8 reg00, reg01, reg10, reg11; /* timing registers */ | ||
237 | u32 regdw0, regdw1; | ||
238 | char* p = buffer; | ||
239 | |||
240 | /* Postwrite/Prefetch */ | ||
241 | if (chipset_family < ATA_133) { | ||
242 | pci_read_config_byte(bmide_dev, 0x4b, ®00); | ||
243 | p += sprintf(p, "Drive %d: Postwrite %s \t \t Postwrite %s\n", | ||
244 | pos, (reg00 & (0x10 << pos)) ? "Enabled" : "Disabled", | ||
245 | (reg00 & (0x40 << pos)) ? "Enabled" : "Disabled"); | ||
246 | p += sprintf(p, " Prefetch %s \t \t Prefetch %s\n", | ||
247 | (reg00 & (0x01 << pos)) ? "Enabled" : "Disabled", | ||
248 | (reg00 & (0x04 << pos)) ? "Enabled" : "Disabled"); | ||
249 | pci_read_config_byte(bmide_dev, 0x40+2*pos, ®00); | ||
250 | pci_read_config_byte(bmide_dev, 0x41+2*pos, ®01); | ||
251 | pci_read_config_byte(bmide_dev, 0x44+2*pos, ®10); | ||
252 | pci_read_config_byte(bmide_dev, 0x45+2*pos, ®11); | ||
253 | } else { | ||
254 | u32 reg54h; | ||
255 | u8 drive_pci = 0x40; | ||
256 | pci_read_config_dword(bmide_dev, 0x54, ®54h); | ||
257 | if (reg54h & 0x40000000) { | ||
258 | // Configuration space remapped to 0x70 | ||
259 | drive_pci = 0x70; | ||
260 | } | ||
261 | pci_read_config_dword(bmide_dev, (unsigned long)drive_pci+4*pos, ®dw0); | ||
262 | pci_read_config_dword(bmide_dev, (unsigned long)drive_pci+4*pos+8, ®dw1); | ||
263 | |||
264 | p += sprintf(p, "Drive %d:\n", pos); | ||
265 | } | ||
266 | |||
267 | |||
268 | /* UDMA */ | ||
269 | if (chipset_family >= ATA_133) { | ||
270 | p += sprintf(p, " UDMA %s \t \t \t UDMA %s\n", | ||
271 | (regdw0 & 0x04) ? "Enabled" : "Disabled", | ||
272 | (regdw1 & 0x04) ? "Enabled" : "Disabled"); | ||
273 | p += sprintf(p, " UDMA Cycle Time %s \t UDMA Cycle Time %s\n", | ||
274 | cycle_time[(regdw0 & 0xF0) >> 4], | ||
275 | cycle_time[(regdw1 & 0xF0) >> 4]); | ||
276 | } else if (chipset_family >= ATA_33) { | ||
277 | p += sprintf(p, " UDMA %s \t \t \t UDMA %s\n", | ||
278 | (reg01 & 0x80) ? "Enabled" : "Disabled", | ||
279 | (reg11 & 0x80) ? "Enabled" : "Disabled"); | ||
280 | |||
281 | p += sprintf(p, " UDMA Cycle Time "); | ||
282 | switch(chipset_family) { | ||
283 | case ATA_33: p += sprintf(p, cycle_time[(reg01 & 0x60) >> 5]); break; | ||
284 | case ATA_66: | ||
285 | case ATA_100a: p += sprintf(p, cycle_time[(reg01 & 0x70) >> 4]); break; | ||
286 | case ATA_100: | ||
287 | case ATA_133a: p += sprintf(p, cycle_time[reg01 & 0x0F]); break; | ||
288 | default: p += sprintf(p, "?"); break; | ||
289 | } | ||
290 | p += sprintf(p, " \t UDMA Cycle Time "); | ||
291 | switch(chipset_family) { | ||
292 | case ATA_33: p += sprintf(p, cycle_time[(reg11 & 0x60) >> 5]); break; | ||
293 | case ATA_66: | ||
294 | case ATA_100a: p += sprintf(p, cycle_time[(reg11 & 0x70) >> 4]); break; | ||
295 | case ATA_100: | ||
296 | case ATA_133a: p += sprintf(p, cycle_time[reg11 & 0x0F]); break; | ||
297 | default: p += sprintf(p, "?"); break; | ||
298 | } | ||
299 | p += sprintf(p, "\n"); | ||
300 | } | ||
301 | |||
302 | |||
303 | if (chipset_family < ATA_133) { /* else case TODO */ | ||
304 | |||
305 | /* Data Active */ | ||
306 | p += sprintf(p, " Data Active Time "); | ||
307 | switch(chipset_family) { | ||
308 | case ATA_16: /* confirmed */ | ||
309 | case ATA_33: | ||
310 | case ATA_66: | ||
311 | case ATA_100a: p += sprintf(p, active_time[reg01 & 0x07]); break; | ||
312 | case ATA_100: | ||
313 | case ATA_133a: p += sprintf(p, active_time[(reg00 & 0x70) >> 4]); break; | ||
314 | default: p += sprintf(p, "?"); break; | ||
315 | } | ||
316 | p += sprintf(p, " \t Data Active Time "); | ||
317 | switch(chipset_family) { | ||
318 | case ATA_16: | ||
319 | case ATA_33: | ||
320 | case ATA_66: | ||
321 | case ATA_100a: p += sprintf(p, active_time[reg11 & 0x07]); break; | ||
322 | case ATA_100: | ||
323 | case ATA_133a: p += sprintf(p, active_time[(reg10 & 0x70) >> 4]); break; | ||
324 | default: p += sprintf(p, "?"); break; | ||
325 | } | ||
326 | p += sprintf(p, "\n"); | ||
327 | |||
328 | /* Data Recovery */ | ||
329 | /* warning: may need (reg&0x07) for pre ATA66 chips */ | ||
330 | p += sprintf(p, " Data Recovery Time %s \t Data Recovery Time %s\n", | ||
331 | recovery_time[reg00 & 0x0f], recovery_time[reg10 & 0x0f]); | ||
332 | } | ||
333 | |||
334 | return p; | ||
335 | } | ||
336 | |||
337 | static char* get_masters_info(char* buffer) | ||
338 | { | ||
339 | return get_drives_info(buffer, 0); | ||
340 | } | ||
341 | |||
342 | static char* get_slaves_info(char* buffer) | ||
343 | { | ||
344 | return get_drives_info(buffer, 1); | ||
345 | } | ||
346 | |||
347 | /* Main get_info, called on /proc/ide/sis reads */ | ||
348 | static int sis_get_info (char *buffer, char **addr, off_t offset, int count) | ||
349 | { | ||
350 | char *p = buffer; | ||
351 | int len; | ||
352 | u8 reg; | ||
353 | u16 reg2, reg3; | ||
354 | |||
355 | p += sprintf(p, "\nSiS 5513 "); | ||
356 | switch(chipset_family) { | ||
357 | case ATA_16: p += sprintf(p, "DMA 16"); break; | ||
358 | case ATA_33: p += sprintf(p, "Ultra 33"); break; | ||
359 | case ATA_66: p += sprintf(p, "Ultra 66"); break; | ||
360 | case ATA_100a: | ||
361 | case ATA_100: p += sprintf(p, "Ultra 100"); break; | ||
362 | case ATA_133a: | ||
363 | case ATA_133: p += sprintf(p, "Ultra 133"); break; | ||
364 | default: p+= sprintf(p, "Unknown???"); break; | ||
365 | } | ||
366 | p += sprintf(p, " chipset\n"); | ||
367 | p += sprintf(p, "--------------- Primary Channel " | ||
368 | "---------------- Secondary Channel " | ||
369 | "-------------\n"); | ||
370 | |||
371 | /* Status */ | ||
372 | pci_read_config_byte(bmide_dev, 0x4a, ®); | ||
373 | if (chipset_family == ATA_133) { | ||
374 | pci_read_config_word(bmide_dev, 0x50, ®2); | ||
375 | pci_read_config_word(bmide_dev, 0x52, ®3); | ||
376 | } | ||
377 | p += sprintf(p, "Channel Status: "); | ||
378 | if (chipset_family < ATA_66) { | ||
379 | p += sprintf(p, "%s \t \t \t \t %s\n", | ||
380 | (reg & 0x04) ? "On" : "Off", | ||
381 | (reg & 0x02) ? "On" : "Off"); | ||
382 | } else if (chipset_family < ATA_133) { | ||
383 | p += sprintf(p, "%s \t \t \t \t %s \n", | ||
384 | (reg & 0x02) ? "On" : "Off", | ||
385 | (reg & 0x04) ? "On" : "Off"); | ||
386 | } else { /* ATA_133 */ | ||
387 | p += sprintf(p, "%s \t \t \t \t %s \n", | ||
388 | (reg2 & 0x02) ? "On" : "Off", | ||
389 | (reg3 & 0x02) ? "On" : "Off"); | ||
390 | } | ||
391 | |||
392 | /* Operation Mode */ | ||
393 | pci_read_config_byte(bmide_dev, 0x09, ®); | ||
394 | p += sprintf(p, "Operation Mode: %s \t \t \t %s \n", | ||
395 | (reg & 0x01) ? "Native" : "Compatible", | ||
396 | (reg & 0x04) ? "Native" : "Compatible"); | ||
397 | |||
398 | /* 80-pin cable ? */ | ||
399 | if (chipset_family >= ATA_133) { | ||
400 | p += sprintf(p, "Cable Type: %s \t \t \t %s\n", | ||
401 | (reg2 & 0x01) ? cable_type[1] : cable_type[0], | ||
402 | (reg3 & 0x01) ? cable_type[1] : cable_type[0]); | ||
403 | } else if (chipset_family > ATA_33) { | ||
404 | pci_read_config_byte(bmide_dev, 0x48, ®); | ||
405 | p += sprintf(p, "Cable Type: %s \t \t \t %s\n", | ||
406 | (reg & 0x10) ? cable_type[1] : cable_type[0], | ||
407 | (reg & 0x20) ? cable_type[1] : cable_type[0]); | ||
408 | } | ||
409 | |||
410 | /* Prefetch Count */ | ||
411 | if (chipset_family < ATA_133) { | ||
412 | pci_read_config_word(bmide_dev, 0x4c, ®2); | ||
413 | pci_read_config_word(bmide_dev, 0x4e, ®3); | ||
414 | p += sprintf(p, "Prefetch Count: %d \t \t \t \t %d\n", | ||
415 | reg2, reg3); | ||
416 | } | ||
417 | |||
418 | p = get_masters_info(p); | ||
419 | p = get_slaves_info(p); | ||
420 | |||
421 | len = (p - buffer) - offset; | ||
422 | *addr = buffer + offset; | ||
423 | |||
424 | return len > count ? count : len; | ||
425 | } | ||
426 | #endif /* defined(DISPLAY_SIS_TIMINGS) && defined(CONFIG_PROC_FS) */ | ||
427 | |||
428 | static u8 sis5513_ratemask (ide_drive_t *drive) | ||
429 | { | ||
430 | u8 rates[] = { 0, 0, 1, 2, 3, 3, 4, 4 }; | ||
431 | u8 mode = rates[chipset_family]; | ||
432 | |||
433 | if (!eighty_ninty_three(drive)) | ||
434 | mode = min(mode, (u8)1); | ||
435 | return mode; | ||
436 | } | ||
437 | |||
438 | /* | ||
439 | * Configuration functions | ||
440 | */ | ||
441 | /* Enables per-drive prefetch and postwrite */ | ||
442 | static void config_drive_art_rwp (ide_drive_t *drive) | ||
443 | { | ||
444 | ide_hwif_t *hwif = HWIF(drive); | ||
445 | struct pci_dev *dev = hwif->pci_dev; | ||
446 | |||
447 | u8 reg4bh = 0; | ||
448 | u8 rw_prefetch = (0x11 << drive->dn); | ||
449 | |||
450 | if (drive->media != ide_disk) | ||
451 | return; | ||
452 | pci_read_config_byte(dev, 0x4b, ®4bh); | ||
453 | |||
454 | if ((reg4bh & rw_prefetch) != rw_prefetch) | ||
455 | pci_write_config_byte(dev, 0x4b, reg4bh|rw_prefetch); | ||
456 | } | ||
457 | |||
458 | |||
459 | /* Set per-drive active and recovery time */ | ||
460 | static void config_art_rwp_pio (ide_drive_t *drive, u8 pio) | ||
461 | { | ||
462 | ide_hwif_t *hwif = HWIF(drive); | ||
463 | struct pci_dev *dev = hwif->pci_dev; | ||
464 | |||
465 | u8 timing, drive_pci, test1, test2; | ||
466 | |||
467 | u16 eide_pio_timing[6] = {600, 390, 240, 180, 120, 90}; | ||
468 | u16 xfer_pio = drive->id->eide_pio_modes; | ||
469 | |||
470 | config_drive_art_rwp(drive); | ||
471 | pio = ide_get_best_pio_mode(drive, 255, pio, NULL); | ||
472 | |||
473 | if (xfer_pio> 4) | ||
474 | xfer_pio = 0; | ||
475 | |||
476 | if (drive->id->eide_pio_iordy > 0) { | ||
477 | for (xfer_pio = 5; | ||
478 | (xfer_pio > 0) && | ||
479 | (drive->id->eide_pio_iordy > eide_pio_timing[xfer_pio]); | ||
480 | xfer_pio--); | ||
481 | } else { | ||
482 | xfer_pio = (drive->id->eide_pio_modes & 4) ? 0x05 : | ||
483 | (drive->id->eide_pio_modes & 2) ? 0x04 : | ||
484 | (drive->id->eide_pio_modes & 1) ? 0x03 : xfer_pio; | ||
485 | } | ||
486 | |||
487 | timing = (xfer_pio >= pio) ? xfer_pio : pio; | ||
488 | |||
489 | /* In pre ATA_133 case, drives sit at 0x40 + 4*drive->dn */ | ||
490 | drive_pci = 0x40; | ||
491 | /* In SiS962 case drives sit at (0x40 or 0x70) + 8*drive->dn) */ | ||
492 | if (chipset_family >= ATA_133) { | ||
493 | u32 reg54h; | ||
494 | pci_read_config_dword(dev, 0x54, ®54h); | ||
495 | if (reg54h & 0x40000000) drive_pci = 0x70; | ||
496 | drive_pci += ((drive->dn)*0x4); | ||
497 | } else { | ||
498 | drive_pci += ((drive->dn)*0x2); | ||
499 | } | ||
500 | |||
501 | /* register layout changed with newer ATA100 chips */ | ||
502 | if (chipset_family < ATA_100) { | ||
503 | pci_read_config_byte(dev, drive_pci, &test1); | ||
504 | pci_read_config_byte(dev, drive_pci+1, &test2); | ||
505 | |||
506 | /* Clear active and recovery timings */ | ||
507 | test1 &= ~0x0F; | ||
508 | test2 &= ~0x07; | ||
509 | |||
510 | switch(timing) { | ||
511 | case 4: test1 |= 0x01; test2 |= 0x03; break; | ||
512 | case 3: test1 |= 0x03; test2 |= 0x03; break; | ||
513 | case 2: test1 |= 0x04; test2 |= 0x04; break; | ||
514 | case 1: test1 |= 0x07; test2 |= 0x06; break; | ||
515 | default: break; | ||
516 | } | ||
517 | pci_write_config_byte(dev, drive_pci, test1); | ||
518 | pci_write_config_byte(dev, drive_pci+1, test2); | ||
519 | } else if (chipset_family < ATA_133) { | ||
520 | switch(timing) { /* active recovery | ||
521 | v v */ | ||
522 | case 4: test1 = 0x30|0x01; break; | ||
523 | case 3: test1 = 0x30|0x03; break; | ||
524 | case 2: test1 = 0x40|0x04; break; | ||
525 | case 1: test1 = 0x60|0x07; break; | ||
526 | default: break; | ||
527 | } | ||
528 | pci_write_config_byte(dev, drive_pci, test1); | ||
529 | } else { /* ATA_133 */ | ||
530 | u32 test3; | ||
531 | pci_read_config_dword(dev, drive_pci, &test3); | ||
532 | test3 &= 0xc0c00fff; | ||
533 | if (test3 & 0x08) { | ||
534 | test3 |= (unsigned long)ini_time_value[ATA_133][timing] << 12; | ||
535 | test3 |= (unsigned long)act_time_value[ATA_133][timing] << 16; | ||
536 | test3 |= (unsigned long)rco_time_value[ATA_133][timing] << 24; | ||
537 | } else { | ||
538 | test3 |= (unsigned long)ini_time_value[ATA_100][timing] << 12; | ||
539 | test3 |= (unsigned long)act_time_value[ATA_100][timing] << 16; | ||
540 | test3 |= (unsigned long)rco_time_value[ATA_100][timing] << 24; | ||
541 | } | ||
542 | pci_write_config_dword(dev, drive_pci, test3); | ||
543 | } | ||
544 | } | ||
545 | |||
546 | static int config_chipset_for_pio (ide_drive_t *drive, u8 pio) | ||
547 | { | ||
548 | if (pio == 255) | ||
549 | pio = ide_find_best_mode(drive, XFER_PIO | XFER_EPIO) - XFER_PIO_0; | ||
550 | config_art_rwp_pio(drive, pio); | ||
551 | return ide_config_drive_speed(drive, XFER_PIO_0 + min_t(u8, pio, 4)); | ||
552 | } | ||
553 | |||
554 | static int sis5513_tune_chipset (ide_drive_t *drive, u8 xferspeed) | ||
555 | { | ||
556 | ide_hwif_t *hwif = HWIF(drive); | ||
557 | struct pci_dev *dev = hwif->pci_dev; | ||
558 | |||
559 | u8 drive_pci, reg, speed; | ||
560 | u32 regdw; | ||
561 | |||
562 | speed = ide_rate_filter(sis5513_ratemask(drive), xferspeed); | ||
563 | |||
564 | /* See config_art_rwp_pio for drive pci config registers */ | ||
565 | drive_pci = 0x40; | ||
566 | if (chipset_family >= ATA_133) { | ||
567 | u32 reg54h; | ||
568 | pci_read_config_dword(dev, 0x54, ®54h); | ||
569 | if (reg54h & 0x40000000) drive_pci = 0x70; | ||
570 | drive_pci += ((drive->dn)*0x4); | ||
571 | pci_read_config_dword(dev, (unsigned long)drive_pci, ®dw); | ||
572 | /* Disable UDMA bit for non UDMA modes on UDMA chips */ | ||
573 | if (speed < XFER_UDMA_0) { | ||
574 | regdw &= 0xfffffffb; | ||
575 | pci_write_config_dword(dev, (unsigned long)drive_pci, regdw); | ||
576 | } | ||
577 | |||
578 | } else { | ||
579 | drive_pci += ((drive->dn)*0x2); | ||
580 | pci_read_config_byte(dev, drive_pci+1, ®); | ||
581 | /* Disable UDMA bit for non UDMA modes on UDMA chips */ | ||
582 | if ((speed < XFER_UDMA_0) && (chipset_family > ATA_16)) { | ||
583 | reg &= 0x7F; | ||
584 | pci_write_config_byte(dev, drive_pci+1, reg); | ||
585 | } | ||
586 | } | ||
587 | |||
588 | /* Config chip for mode */ | ||
589 | switch(speed) { | ||
590 | case XFER_UDMA_6: | ||
591 | case XFER_UDMA_5: | ||
592 | case XFER_UDMA_4: | ||
593 | case XFER_UDMA_3: | ||
594 | case XFER_UDMA_2: | ||
595 | case XFER_UDMA_1: | ||
596 | case XFER_UDMA_0: | ||
597 | if (chipset_family >= ATA_133) { | ||
598 | regdw |= 0x04; | ||
599 | regdw &= 0xfffff00f; | ||
600 | /* check if ATA133 enable */ | ||
601 | if (regdw & 0x08) { | ||
602 | regdw |= (unsigned long)cycle_time_value[ATA_133][speed-XFER_UDMA_0] << 4; | ||
603 | regdw |= (unsigned long)cvs_time_value[ATA_133][speed-XFER_UDMA_0] << 8; | ||
604 | } else { | ||
605 | /* if ATA133 disable, we should not set speed above UDMA5 */ | ||
606 | if (speed > XFER_UDMA_5) | ||
607 | speed = XFER_UDMA_5; | ||
608 | regdw |= (unsigned long)cycle_time_value[ATA_100][speed-XFER_UDMA_0] << 4; | ||
609 | regdw |= (unsigned long)cvs_time_value[ATA_100][speed-XFER_UDMA_0] << 8; | ||
610 | } | ||
611 | pci_write_config_dword(dev, (unsigned long)drive_pci, regdw); | ||
612 | } else { | ||
613 | /* Force the UDMA bit on if we want to use UDMA */ | ||
614 | reg |= 0x80; | ||
615 | /* clean reg cycle time bits */ | ||
616 | reg &= ~((0xFF >> (8 - cycle_time_range[chipset_family])) | ||
617 | << cycle_time_offset[chipset_family]); | ||
618 | /* set reg cycle time bits */ | ||
619 | reg |= cycle_time_value[chipset_family][speed-XFER_UDMA_0] | ||
620 | << cycle_time_offset[chipset_family]; | ||
621 | pci_write_config_byte(dev, drive_pci+1, reg); | ||
622 | } | ||
623 | break; | ||
624 | case XFER_MW_DMA_2: | ||
625 | case XFER_MW_DMA_1: | ||
626 | case XFER_MW_DMA_0: | ||
627 | case XFER_SW_DMA_2: | ||
628 | case XFER_SW_DMA_1: | ||
629 | case XFER_SW_DMA_0: | ||
630 | break; | ||
631 | case XFER_PIO_4: return((int) config_chipset_for_pio(drive, 4)); | ||
632 | case XFER_PIO_3: return((int) config_chipset_for_pio(drive, 3)); | ||
633 | case XFER_PIO_2: return((int) config_chipset_for_pio(drive, 2)); | ||
634 | case XFER_PIO_1: return((int) config_chipset_for_pio(drive, 1)); | ||
635 | case XFER_PIO_0: | ||
636 | default: return((int) config_chipset_for_pio(drive, 0)); | ||
637 | } | ||
638 | |||
639 | return ((int) ide_config_drive_speed(drive, speed)); | ||
640 | } | ||
641 | |||
642 | static void sis5513_tune_drive (ide_drive_t *drive, u8 pio) | ||
643 | { | ||
644 | (void) config_chipset_for_pio(drive, pio); | ||
645 | } | ||
646 | |||
647 | /* | ||
648 | * ((id->hw_config & 0x4000|0x2000) && (HWIF(drive)->udma_four)) | ||
649 | */ | ||
650 | static int config_chipset_for_dma (ide_drive_t *drive) | ||
651 | { | ||
652 | u8 speed = ide_dma_speed(drive, sis5513_ratemask(drive)); | ||
653 | |||
654 | #ifdef DEBUG | ||
655 | printk("SIS5513: config_chipset_for_dma, drive %d, ultra %x\n", | ||
656 | drive->dn, drive->id->dma_ultra); | ||
657 | #endif | ||
658 | |||
659 | if (!(speed)) | ||
660 | return 0; | ||
661 | |||
662 | sis5513_tune_chipset(drive, speed); | ||
663 | return ide_dma_enable(drive); | ||
664 | } | ||
665 | |||
666 | static int sis5513_config_drive_xfer_rate (ide_drive_t *drive) | ||
667 | { | ||
668 | ide_hwif_t *hwif = HWIF(drive); | ||
669 | struct hd_driveid *id = drive->id; | ||
670 | |||
671 | drive->init_speed = 0; | ||
672 | |||
673 | if (id && (id->capability & 1) && drive->autodma) { | ||
674 | |||
675 | if (ide_use_dma(drive)) { | ||
676 | if (config_chipset_for_dma(drive)) | ||
677 | return hwif->ide_dma_on(drive); | ||
678 | } | ||
679 | |||
680 | goto fast_ata_pio; | ||
681 | |||
682 | } else if ((id->capability & 8) || (id->field_valid & 2)) { | ||
683 | fast_ata_pio: | ||
684 | sis5513_tune_drive(drive, 5); | ||
685 | return hwif->ide_dma_off_quietly(drive); | ||
686 | } | ||
687 | /* IORDY not supported */ | ||
688 | return 0; | ||
689 | } | ||
690 | |||
691 | /* initiates/aborts (U)DMA read/write operations on a drive. */ | ||
692 | static int sis5513_config_xfer_rate (ide_drive_t *drive) | ||
693 | { | ||
694 | config_drive_art_rwp(drive); | ||
695 | config_art_rwp_pio(drive, 5); | ||
696 | return sis5513_config_drive_xfer_rate(drive); | ||
697 | } | ||
698 | |||
699 | /* | ||
700 | Future simpler config_xfer_rate : | ||
701 | When ide_find_best_mode is made bad-drive aware | ||
702 | - remove config_drive_xfer_rate and config_chipset_for_dma, | ||
703 | - replace config_xfer_rate with the following | ||
704 | |||
705 | static int sis5513_config_xfer_rate (ide_drive_t *drive) | ||
706 | { | ||
707 | u16 w80 = HWIF(drive)->udma_four; | ||
708 | u16 speed; | ||
709 | |||
710 | config_drive_art_rwp(drive); | ||
711 | config_art_rwp_pio(drive, 5); | ||
712 | |||
713 | speed = ide_find_best_mode(drive, | ||
714 | XFER_PIO | XFER_EPIO | XFER_SWDMA | XFER_MWDMA | | ||
715 | (chipset_family >= ATA_33 ? XFER_UDMA : 0) | | ||
716 | (w80 && chipset_family >= ATA_66 ? XFER_UDMA_66 : 0) | | ||
717 | (w80 && chipset_family >= ATA_100a ? XFER_UDMA_100 : 0) | | ||
718 | (w80 && chipset_family >= ATA_133a ? XFER_UDMA_133 : 0)); | ||
719 | |||
720 | sis5513_tune_chipset(drive, speed); | ||
721 | |||
722 | if (drive->autodma && (speed & XFER_MODE) != XFER_PIO) | ||
723 | return HWIF(drive)->ide_dma_on(drive); | ||
724 | return HWIF(drive)->ide_dma_off_quietly(drive); | ||
725 | } | ||
726 | */ | ||
727 | |||
728 | /* Chip detection and general config */ | ||
729 | static unsigned int __init init_chipset_sis5513 (struct pci_dev *dev, const char *name) | ||
730 | { | ||
731 | struct pci_dev *host; | ||
732 | int i = 0; | ||
733 | |||
734 | chipset_family = 0; | ||
735 | |||
736 | for (i = 0; i < ARRAY_SIZE(SiSHostChipInfo) && !chipset_family; i++) { | ||
737 | |||
738 | host = pci_find_device(PCI_VENDOR_ID_SI, SiSHostChipInfo[i].host_id, NULL); | ||
739 | |||
740 | if (!host) | ||
741 | continue; | ||
742 | |||
743 | chipset_family = SiSHostChipInfo[i].chipset_family; | ||
744 | |||
745 | /* Special case for SiS630 : 630S/ET is ATA_100a */ | ||
746 | if (SiSHostChipInfo[i].host_id == PCI_DEVICE_ID_SI_630) { | ||
747 | u8 hostrev; | ||
748 | pci_read_config_byte(host, PCI_REVISION_ID, &hostrev); | ||
749 | if (hostrev >= 0x30) | ||
750 | chipset_family = ATA_100a; | ||
751 | } | ||
752 | |||
753 | printk(KERN_INFO "SIS5513: %s %s controller\n", | ||
754 | SiSHostChipInfo[i].name, chipset_capability[chipset_family]); | ||
755 | } | ||
756 | |||
757 | if (!chipset_family) { /* Belongs to pci-quirks */ | ||
758 | |||
759 | u32 idemisc; | ||
760 | u16 trueid; | ||
761 | |||
762 | /* Disable ID masking and register remapping */ | ||
763 | pci_read_config_dword(dev, 0x54, &idemisc); | ||
764 | pci_write_config_dword(dev, 0x54, (idemisc & 0x7fffffff)); | ||
765 | pci_read_config_word(dev, PCI_DEVICE_ID, &trueid); | ||
766 | pci_write_config_dword(dev, 0x54, idemisc); | ||
767 | |||
768 | if (trueid == 0x5518) { | ||
769 | printk(KERN_INFO "SIS5513: SiS 962/963 MuTIOL IDE UDMA133 controller\n"); | ||
770 | chipset_family = ATA_133; | ||
771 | |||
772 | /* Check for 5513 compability mapping | ||
773 | * We must use this, else the port enabled code will fail, | ||
774 | * as it expects the enablebits at 0x4a. | ||
775 | */ | ||
776 | if ((idemisc & 0x40000000) == 0) { | ||
777 | pci_write_config_dword(dev, 0x54, idemisc | 0x40000000); | ||
778 | printk(KERN_INFO "SIS5513: Switching to 5513 register mapping\n"); | ||
779 | } | ||
780 | } | ||
781 | } | ||
782 | |||
783 | if (!chipset_family) { /* Belongs to pci-quirks */ | ||
784 | |||
785 | struct pci_dev *lpc_bridge; | ||
786 | u16 trueid; | ||
787 | u8 prefctl; | ||
788 | u8 idecfg; | ||
789 | u8 sbrev; | ||
790 | |||
791 | pci_read_config_byte(dev, 0x4a, &idecfg); | ||
792 | pci_write_config_byte(dev, 0x4a, idecfg | 0x10); | ||
793 | pci_read_config_word(dev, PCI_DEVICE_ID, &trueid); | ||
794 | pci_write_config_byte(dev, 0x4a, idecfg); | ||
795 | |||
796 | if (trueid == 0x5517) { /* SiS 961/961B */ | ||
797 | |||
798 | lpc_bridge = pci_find_slot(0x00, 0x10); /* Bus 0, Dev 2, Fn 0 */ | ||
799 | pci_read_config_byte(lpc_bridge, PCI_REVISION_ID, &sbrev); | ||
800 | pci_read_config_byte(dev, 0x49, &prefctl); | ||
801 | |||
802 | if (sbrev == 0x10 && (prefctl & 0x80)) { | ||
803 | printk(KERN_INFO "SIS5513: SiS 961B MuTIOL IDE UDMA133 controller\n"); | ||
804 | chipset_family = ATA_133a; | ||
805 | } else { | ||
806 | printk(KERN_INFO "SIS5513: SiS 961 MuTIOL IDE UDMA100 controller\n"); | ||
807 | chipset_family = ATA_100; | ||
808 | } | ||
809 | } | ||
810 | } | ||
811 | |||
812 | if (!chipset_family) | ||
813 | return -1; | ||
814 | |||
815 | /* Make general config ops here | ||
816 | 1/ tell IDE channels to operate in Compatibility mode only | ||
817 | 2/ tell old chips to allow per drive IDE timings */ | ||
818 | |||
819 | { | ||
820 | u8 reg; | ||
821 | u16 regw; | ||
822 | |||
823 | switch(chipset_family) { | ||
824 | case ATA_133: | ||
825 | /* SiS962 operation mode */ | ||
826 | pci_read_config_word(dev, 0x50, ®w); | ||
827 | if (regw & 0x08) | ||
828 | pci_write_config_word(dev, 0x50, regw&0xfff7); | ||
829 | pci_read_config_word(dev, 0x52, ®w); | ||
830 | if (regw & 0x08) | ||
831 | pci_write_config_word(dev, 0x52, regw&0xfff7); | ||
832 | break; | ||
833 | case ATA_133a: | ||
834 | case ATA_100: | ||
835 | /* Fixup latency */ | ||
836 | pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x80); | ||
837 | /* Set compatibility bit */ | ||
838 | pci_read_config_byte(dev, 0x49, ®); | ||
839 | if (!(reg & 0x01)) { | ||
840 | pci_write_config_byte(dev, 0x49, reg|0x01); | ||
841 | } | ||
842 | break; | ||
843 | case ATA_100a: | ||
844 | case ATA_66: | ||
845 | /* Fixup latency */ | ||
846 | pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x10); | ||
847 | |||
848 | /* On ATA_66 chips the bit was elsewhere */ | ||
849 | pci_read_config_byte(dev, 0x52, ®); | ||
850 | if (!(reg & 0x04)) { | ||
851 | pci_write_config_byte(dev, 0x52, reg|0x04); | ||
852 | } | ||
853 | break; | ||
854 | case ATA_33: | ||
855 | /* On ATA_33 we didn't have a single bit to set */ | ||
856 | pci_read_config_byte(dev, 0x09, ®); | ||
857 | if ((reg & 0x0f) != 0x00) { | ||
858 | pci_write_config_byte(dev, 0x09, reg&0xf0); | ||
859 | } | ||
860 | case ATA_16: | ||
861 | /* force per drive recovery and active timings | ||
862 | needed on ATA_33 and below chips */ | ||
863 | pci_read_config_byte(dev, 0x52, ®); | ||
864 | if (!(reg & 0x08)) { | ||
865 | pci_write_config_byte(dev, 0x52, reg|0x08); | ||
866 | } | ||
867 | break; | ||
868 | } | ||
869 | |||
870 | #if defined(DISPLAY_SIS_TIMINGS) && defined(CONFIG_PROC_FS) | ||
871 | if (!sis_proc) { | ||
872 | sis_proc = 1; | ||
873 | bmide_dev = dev; | ||
874 | ide_pci_create_host_proc("sis", sis_get_info); | ||
875 | } | ||
876 | #endif | ||
877 | } | ||
878 | |||
879 | return 0; | ||
880 | } | ||
881 | |||
882 | static unsigned int __init ata66_sis5513 (ide_hwif_t *hwif) | ||
883 | { | ||
884 | u8 ata66 = 0; | ||
885 | |||
886 | if (chipset_family >= ATA_133) { | ||
887 | u16 regw = 0; | ||
888 | u16 reg_addr = hwif->channel ? 0x52: 0x50; | ||
889 | pci_read_config_word(hwif->pci_dev, reg_addr, ®w); | ||
890 | ata66 = (regw & 0x8000) ? 0 : 1; | ||
891 | } else if (chipset_family >= ATA_66) { | ||
892 | u8 reg48h = 0; | ||
893 | u8 mask = hwif->channel ? 0x20 : 0x10; | ||
894 | pci_read_config_byte(hwif->pci_dev, 0x48, ®48h); | ||
895 | ata66 = (reg48h & mask) ? 0 : 1; | ||
896 | } | ||
897 | return ata66; | ||
898 | } | ||
899 | |||
900 | static void __init init_hwif_sis5513 (ide_hwif_t *hwif) | ||
901 | { | ||
902 | hwif->autodma = 0; | ||
903 | |||
904 | if (!hwif->irq) | ||
905 | hwif->irq = hwif->channel ? 15 : 14; | ||
906 | |||
907 | hwif->tuneproc = &sis5513_tune_drive; | ||
908 | hwif->speedproc = &sis5513_tune_chipset; | ||
909 | |||
910 | if (!(hwif->dma_base)) { | ||
911 | hwif->drives[0].autotune = 1; | ||
912 | hwif->drives[1].autotune = 1; | ||
913 | return; | ||
914 | } | ||
915 | |||
916 | hwif->atapi_dma = 1; | ||
917 | hwif->ultra_mask = 0x7f; | ||
918 | hwif->mwdma_mask = 0x07; | ||
919 | hwif->swdma_mask = 0x07; | ||
920 | |||
921 | if (!chipset_family) | ||
922 | return; | ||
923 | |||
924 | if (!(hwif->udma_four)) | ||
925 | hwif->udma_four = ata66_sis5513(hwif); | ||
926 | |||
927 | if (chipset_family > ATA_16) { | ||
928 | hwif->ide_dma_check = &sis5513_config_xfer_rate; | ||
929 | if (!noautodma) | ||
930 | hwif->autodma = 1; | ||
931 | } | ||
932 | hwif->drives[0].autodma = hwif->autodma; | ||
933 | hwif->drives[1].autodma = hwif->autodma; | ||
934 | return; | ||
935 | } | ||
936 | |||
937 | static ide_pci_device_t sis5513_chipset __devinitdata = { | ||
938 | .name = "SIS5513", | ||
939 | .init_chipset = init_chipset_sis5513, | ||
940 | .init_hwif = init_hwif_sis5513, | ||
941 | .channels = 2, | ||
942 | .autodma = NOAUTODMA, | ||
943 | .enablebits = {{0x4a,0x02,0x02}, {0x4a,0x04,0x04}}, | ||
944 | .bootable = ON_BOARD, | ||
945 | }; | ||
946 | |||
947 | static int __devinit sis5513_init_one(struct pci_dev *dev, const struct pci_device_id *id) | ||
948 | { | ||
949 | return ide_setup_pci_device(dev, &sis5513_chipset); | ||
950 | } | ||
951 | |||
952 | static struct pci_device_id sis5513_pci_tbl[] = { | ||
953 | { PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_5513, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, | ||
954 | { PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_5518, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, | ||
955 | { 0, }, | ||
956 | }; | ||
957 | MODULE_DEVICE_TABLE(pci, sis5513_pci_tbl); | ||
958 | |||
959 | static struct pci_driver driver = { | ||
960 | .name = "SIS_IDE", | ||
961 | .id_table = sis5513_pci_tbl, | ||
962 | .probe = sis5513_init_one, | ||
963 | }; | ||
964 | |||
965 | static int sis5513_ide_init(void) | ||
966 | { | ||
967 | return ide_pci_register_driver(&driver); | ||
968 | } | ||
969 | |||
970 | module_init(sis5513_ide_init); | ||
971 | |||
972 | MODULE_AUTHOR("Lionel Bouton, L C Chang, Andre Hedrick, Vojtech Pavlik"); | ||
973 | MODULE_DESCRIPTION("PCI driver module for SIS IDE"); | ||
974 | MODULE_LICENSE("GPL"); | ||
975 | |||
976 | /* | ||
977 | * TODO: | ||
978 | * - CLEANUP | ||
979 | * - Use drivers/ide/ide-timing.h ! | ||
980 | * - More checks in the config registers (force values instead of | ||
981 | * relying on the BIOS setting them correctly). | ||
982 | * - Further optimisations ? | ||
983 | * . for example ATA66+ regs 0x48 & 0x4A | ||
984 | */ | ||
diff --git a/drivers/ide/pci/sl82c105.c b/drivers/ide/pci/sl82c105.c new file mode 100644 index 000000000000..1d970a0de21a --- /dev/null +++ b/drivers/ide/pci/sl82c105.c | |||
@@ -0,0 +1,516 @@ | |||
1 | /* | ||
2 | * linux/drivers/ide/pci/sl82c105.c | ||
3 | * | ||
4 | * SL82C105/Winbond 553 IDE driver | ||
5 | * | ||
6 | * Maintainer unknown. | ||
7 | * | ||
8 | * Drive tuning added from Rebel.com's kernel sources | ||
9 | * -- Russell King (15/11/98) linux@arm.linux.org.uk | ||
10 | * | ||
11 | * Merge in Russell's HW workarounds, fix various problems | ||
12 | * with the timing registers setup. | ||
13 | * -- Benjamin Herrenschmidt (01/11/03) benh@kernel.crashing.org | ||
14 | */ | ||
15 | |||
16 | #include <linux/config.h> | ||
17 | #include <linux/types.h> | ||
18 | #include <linux/module.h> | ||
19 | #include <linux/kernel.h> | ||
20 | #include <linux/timer.h> | ||
21 | #include <linux/mm.h> | ||
22 | #include <linux/ioport.h> | ||
23 | #include <linux/interrupt.h> | ||
24 | #include <linux/blkdev.h> | ||
25 | #include <linux/hdreg.h> | ||
26 | #include <linux/pci.h> | ||
27 | #include <linux/ide.h> | ||
28 | |||
29 | #include <asm/io.h> | ||
30 | #include <asm/dma.h> | ||
31 | |||
32 | #undef DEBUG | ||
33 | |||
34 | #ifdef DEBUG | ||
35 | #define DBG(arg) printk arg | ||
36 | #else | ||
37 | #define DBG(fmt,...) | ||
38 | #endif | ||
39 | /* | ||
40 | * SL82C105 PCI config register 0x40 bits. | ||
41 | */ | ||
42 | #define CTRL_IDE_IRQB (1 << 30) | ||
43 | #define CTRL_IDE_IRQA (1 << 28) | ||
44 | #define CTRL_LEGIRQ (1 << 11) | ||
45 | #define CTRL_P1F16 (1 << 5) | ||
46 | #define CTRL_P1EN (1 << 4) | ||
47 | #define CTRL_P0F16 (1 << 1) | ||
48 | #define CTRL_P0EN (1 << 0) | ||
49 | |||
50 | /* | ||
51 | * Convert a PIO mode and cycle time to the required on/off | ||
52 | * times for the interface. This has protection against run-away | ||
53 | * timings. | ||
54 | */ | ||
55 | static unsigned int get_timing_sl82c105(ide_pio_data_t *p) | ||
56 | { | ||
57 | unsigned int cmd_on; | ||
58 | unsigned int cmd_off; | ||
59 | |||
60 | cmd_on = (ide_pio_timings[p->pio_mode].active_time + 29) / 30; | ||
61 | cmd_off = (p->cycle_time - 30 * cmd_on + 29) / 30; | ||
62 | |||
63 | if (cmd_on > 32) | ||
64 | cmd_on = 32; | ||
65 | if (cmd_on == 0) | ||
66 | cmd_on = 1; | ||
67 | |||
68 | if (cmd_off > 32) | ||
69 | cmd_off = 32; | ||
70 | if (cmd_off == 0) | ||
71 | cmd_off = 1; | ||
72 | |||
73 | return (cmd_on - 1) << 8 | (cmd_off - 1) | (p->use_iordy ? 0x40 : 0x00); | ||
74 | } | ||
75 | |||
76 | /* | ||
77 | * Configure the drive and chipset for PIO | ||
78 | */ | ||
79 | static void config_for_pio(ide_drive_t *drive, int pio, int report, int chipset_only) | ||
80 | { | ||
81 | ide_hwif_t *hwif = HWIF(drive); | ||
82 | struct pci_dev *dev = hwif->pci_dev; | ||
83 | ide_pio_data_t p; | ||
84 | u16 drv_ctrl = 0x909; | ||
85 | unsigned int xfer_mode, reg; | ||
86 | |||
87 | DBG(("config_for_pio(drive:%s, pio:%d, report:%d, chipset_only:%d)\n", | ||
88 | drive->name, pio, report, chipset_only)); | ||
89 | |||
90 | reg = (hwif->channel ? 0x4c : 0x44) + (drive->select.b.unit ? 4 : 0); | ||
91 | |||
92 | pio = ide_get_best_pio_mode(drive, pio, 5, &p); | ||
93 | |||
94 | xfer_mode = XFER_PIO_0 + pio; | ||
95 | |||
96 | if (chipset_only || ide_config_drive_speed(drive, xfer_mode) == 0) { | ||
97 | drv_ctrl = get_timing_sl82c105(&p); | ||
98 | drive->pio_speed = xfer_mode; | ||
99 | } else | ||
100 | drive->pio_speed = XFER_PIO_0; | ||
101 | |||
102 | if (drive->using_dma == 0) { | ||
103 | /* | ||
104 | * If we are actually using MW DMA, then we can not | ||
105 | * reprogram the interface drive control register. | ||
106 | */ | ||
107 | pci_write_config_word(dev, reg, drv_ctrl); | ||
108 | pci_read_config_word(dev, reg, &drv_ctrl); | ||
109 | |||
110 | if (report) { | ||
111 | printk("%s: selected %s (%dns) (%04X)\n", drive->name, | ||
112 | ide_xfer_verbose(xfer_mode), p.cycle_time, drv_ctrl); | ||
113 | } | ||
114 | } | ||
115 | } | ||
116 | |||
117 | /* | ||
118 | * Configure the drive and the chipset for DMA | ||
119 | */ | ||
120 | static int config_for_dma (ide_drive_t *drive) | ||
121 | { | ||
122 | ide_hwif_t *hwif = HWIF(drive); | ||
123 | struct pci_dev *dev = hwif->pci_dev; | ||
124 | unsigned int reg; | ||
125 | |||
126 | DBG(("config_for_dma(drive:%s)\n", drive->name)); | ||
127 | |||
128 | reg = (hwif->channel ? 0x4c : 0x44) + (drive->select.b.unit ? 4 : 0); | ||
129 | |||
130 | if (ide_config_drive_speed(drive, XFER_MW_DMA_2) != 0) | ||
131 | return 1; | ||
132 | |||
133 | pci_write_config_word(dev, reg, 0x0240); | ||
134 | |||
135 | return 0; | ||
136 | } | ||
137 | |||
138 | /* | ||
139 | * Check to see if the drive and | ||
140 | * chipset is capable of DMA mode | ||
141 | */ | ||
142 | |||
143 | static int sl82c105_check_drive (ide_drive_t *drive) | ||
144 | { | ||
145 | ide_hwif_t *hwif = HWIF(drive); | ||
146 | |||
147 | DBG(("sl82c105_check_drive(drive:%s)\n", drive->name)); | ||
148 | |||
149 | do { | ||
150 | struct hd_driveid *id = drive->id; | ||
151 | |||
152 | if (!drive->autodma) | ||
153 | break; | ||
154 | |||
155 | if (!id || !(id->capability & 1)) | ||
156 | break; | ||
157 | |||
158 | /* Consult the list of known "bad" drives */ | ||
159 | if (__ide_dma_bad_drive(drive)) | ||
160 | break; | ||
161 | |||
162 | if (id->field_valid & 2) { | ||
163 | if ((id->dma_mword & hwif->mwdma_mask) || | ||
164 | (id->dma_1word & hwif->swdma_mask)) | ||
165 | return hwif->ide_dma_on(drive); | ||
166 | } | ||
167 | |||
168 | if (__ide_dma_good_drive(drive)) | ||
169 | return hwif->ide_dma_on(drive); | ||
170 | } while (0); | ||
171 | |||
172 | return hwif->ide_dma_off_quietly(drive); | ||
173 | } | ||
174 | |||
175 | /* | ||
176 | * The SL82C105 holds off all IDE interrupts while in DMA mode until | ||
177 | * all DMA activity is completed. Sometimes this causes problems (eg, | ||
178 | * when the drive wants to report an error condition). | ||
179 | * | ||
180 | * 0x7e is a "chip testing" register. Bit 2 resets the DMA controller | ||
181 | * state machine. We need to kick this to work around various bugs. | ||
182 | */ | ||
183 | static inline void sl82c105_reset_host(struct pci_dev *dev) | ||
184 | { | ||
185 | u16 val; | ||
186 | |||
187 | pci_read_config_word(dev, 0x7e, &val); | ||
188 | pci_write_config_word(dev, 0x7e, val | (1 << 2)); | ||
189 | pci_write_config_word(dev, 0x7e, val & ~(1 << 2)); | ||
190 | } | ||
191 | |||
192 | /* | ||
193 | * If we get an IRQ timeout, it might be that the DMA state machine | ||
194 | * got confused. Fix from Todd Inglett. Details from Winbond. | ||
195 | * | ||
196 | * This function is called when the IDE timer expires, the drive | ||
197 | * indicates that it is READY, and we were waiting for DMA to complete. | ||
198 | */ | ||
199 | static int sl82c105_ide_dma_lost_irq(ide_drive_t *drive) | ||
200 | { | ||
201 | ide_hwif_t *hwif = HWIF(drive); | ||
202 | struct pci_dev *dev = hwif->pci_dev; | ||
203 | u32 val, mask = hwif->channel ? CTRL_IDE_IRQB : CTRL_IDE_IRQA; | ||
204 | unsigned long dma_base = hwif->dma_base; | ||
205 | |||
206 | printk("sl82c105: lost IRQ: resetting host\n"); | ||
207 | |||
208 | /* | ||
209 | * Check the raw interrupt from the drive. | ||
210 | */ | ||
211 | pci_read_config_dword(dev, 0x40, &val); | ||
212 | if (val & mask) | ||
213 | printk("sl82c105: drive was requesting IRQ, but host lost it\n"); | ||
214 | |||
215 | /* | ||
216 | * Was DMA enabled? If so, disable it - we're resetting the | ||
217 | * host. The IDE layer will be handling the drive for us. | ||
218 | */ | ||
219 | val = hwif->INB(dma_base); | ||
220 | if (val & 1) { | ||
221 | outb(val & ~1, dma_base); | ||
222 | printk("sl82c105: DMA was enabled\n"); | ||
223 | } | ||
224 | |||
225 | sl82c105_reset_host(dev); | ||
226 | |||
227 | /* ide_dmaproc would return 1, so we do as well */ | ||
228 | return 1; | ||
229 | } | ||
230 | |||
231 | /* | ||
232 | * ATAPI devices can cause the SL82C105 DMA state machine to go gaga. | ||
233 | * Winbond recommend that the DMA state machine is reset prior to | ||
234 | * setting the bus master DMA enable bit. | ||
235 | * | ||
236 | * The generic IDE core will have disabled the BMEN bit before this | ||
237 | * function is called. | ||
238 | */ | ||
239 | static void sl82c105_ide_dma_start(ide_drive_t *drive) | ||
240 | { | ||
241 | ide_hwif_t *hwif = HWIF(drive); | ||
242 | struct pci_dev *dev = hwif->pci_dev; | ||
243 | |||
244 | sl82c105_reset_host(dev); | ||
245 | ide_dma_start(drive); | ||
246 | } | ||
247 | |||
248 | static int sl82c105_ide_dma_timeout(ide_drive_t *drive) | ||
249 | { | ||
250 | ide_hwif_t *hwif = HWIF(drive); | ||
251 | struct pci_dev *dev = hwif->pci_dev; | ||
252 | |||
253 | DBG(("sl82c105_ide_dma_timeout(drive:%s)\n", drive->name)); | ||
254 | |||
255 | sl82c105_reset_host(dev); | ||
256 | return __ide_dma_timeout(drive); | ||
257 | } | ||
258 | |||
259 | static int sl82c105_ide_dma_on (ide_drive_t *drive) | ||
260 | { | ||
261 | DBG(("sl82c105_ide_dma_on(drive:%s)\n", drive->name)); | ||
262 | |||
263 | if (config_for_dma(drive)) { | ||
264 | config_for_pio(drive, 4, 0, 0); | ||
265 | return HWIF(drive)->ide_dma_off_quietly(drive); | ||
266 | } | ||
267 | printk(KERN_INFO "%s: DMA enabled\n", drive->name); | ||
268 | return __ide_dma_on(drive); | ||
269 | } | ||
270 | |||
271 | static int sl82c105_ide_dma_off_quietly (ide_drive_t *drive) | ||
272 | { | ||
273 | u8 speed = XFER_PIO_0; | ||
274 | int rc; | ||
275 | |||
276 | DBG(("sl82c105_ide_dma_off_quietly(drive:%s)\n", drive->name)); | ||
277 | |||
278 | rc = __ide_dma_off_quietly(drive); | ||
279 | if (drive->pio_speed) | ||
280 | speed = drive->pio_speed - XFER_PIO_0; | ||
281 | config_for_pio(drive, speed, 0, 1); | ||
282 | drive->current_speed = drive->pio_speed; | ||
283 | |||
284 | return rc; | ||
285 | } | ||
286 | |||
287 | /* | ||
288 | * Ok, that is nasty, but we must make sure the DMA timings | ||
289 | * won't be used for a PIO access. The solution here is | ||
290 | * to make sure the 16 bits mode is diabled on the channel | ||
291 | * when DMA is enabled, thus causing the chip to use PIO0 | ||
292 | * timings for those operations. | ||
293 | */ | ||
294 | static void sl82c105_selectproc(ide_drive_t *drive) | ||
295 | { | ||
296 | ide_hwif_t *hwif = HWIF(drive); | ||
297 | struct pci_dev *dev = hwif->pci_dev; | ||
298 | u32 val, old, mask; | ||
299 | |||
300 | //DBG(("sl82c105_selectproc(drive:%s)\n", drive->name)); | ||
301 | |||
302 | mask = hwif->channel ? CTRL_P1F16 : CTRL_P0F16; | ||
303 | old = val = *((u32 *)&hwif->hwif_data); | ||
304 | if (drive->using_dma) | ||
305 | val &= ~mask; | ||
306 | else | ||
307 | val |= mask; | ||
308 | if (old != val) { | ||
309 | pci_write_config_dword(dev, 0x40, val); | ||
310 | *((u32 *)&hwif->hwif_data) = val; | ||
311 | } | ||
312 | } | ||
313 | |||
314 | /* | ||
315 | * ATA reset will clear the 16 bits mode in the control | ||
316 | * register, we need to update our cache | ||
317 | */ | ||
318 | static void sl82c105_resetproc(ide_drive_t *drive) | ||
319 | { | ||
320 | ide_hwif_t *hwif = HWIF(drive); | ||
321 | struct pci_dev *dev = hwif->pci_dev; | ||
322 | u32 val; | ||
323 | |||
324 | DBG(("sl82c105_resetproc(drive:%s)\n", drive->name)); | ||
325 | |||
326 | pci_read_config_dword(dev, 0x40, &val); | ||
327 | *((u32 *)&hwif->hwif_data) = val; | ||
328 | } | ||
329 | |||
330 | /* | ||
331 | * We only deal with PIO mode here - DMA mode 'using_dma' is not | ||
332 | * initialised at the point that this function is called. | ||
333 | */ | ||
334 | static void tune_sl82c105(ide_drive_t *drive, u8 pio) | ||
335 | { | ||
336 | DBG(("tune_sl82c105(drive:%s)\n", drive->name)); | ||
337 | |||
338 | config_for_pio(drive, pio, 1, 0); | ||
339 | |||
340 | /* | ||
341 | * We support 32-bit I/O on this interface, and it | ||
342 | * doesn't have problems with interrupts. | ||
343 | */ | ||
344 | drive->io_32bit = 1; | ||
345 | drive->unmask = 1; | ||
346 | } | ||
347 | |||
348 | /* | ||
349 | * Return the revision of the Winbond bridge | ||
350 | * which this function is part of. | ||
351 | */ | ||
352 | static unsigned int sl82c105_bridge_revision(struct pci_dev *dev) | ||
353 | { | ||
354 | struct pci_dev *bridge; | ||
355 | u8 rev; | ||
356 | |||
357 | /* | ||
358 | * The bridge should be part of the same device, but function 0. | ||
359 | */ | ||
360 | bridge = pci_find_slot(dev->bus->number, | ||
361 | PCI_DEVFN(PCI_SLOT(dev->devfn), 0)); | ||
362 | if (!bridge) | ||
363 | return -1; | ||
364 | |||
365 | /* | ||
366 | * Make sure it is a Winbond 553 and is an ISA bridge. | ||
367 | */ | ||
368 | if (bridge->vendor != PCI_VENDOR_ID_WINBOND || | ||
369 | bridge->device != PCI_DEVICE_ID_WINBOND_83C553 || | ||
370 | bridge->class >> 8 != PCI_CLASS_BRIDGE_ISA) | ||
371 | return -1; | ||
372 | |||
373 | /* | ||
374 | * We need to find function 0's revision, not function 1 | ||
375 | */ | ||
376 | pci_read_config_byte(bridge, PCI_REVISION_ID, &rev); | ||
377 | |||
378 | return rev; | ||
379 | } | ||
380 | |||
381 | /* | ||
382 | * Enable the PCI device | ||
383 | * | ||
384 | * --BenH: It's arch fixup code that should enable channels that | ||
385 | * have not been enabled by firmware. I decided we can still enable | ||
386 | * channel 0 here at least, but channel 1 has to be enabled by | ||
387 | * firmware or arch code. We still set both to 16 bits mode. | ||
388 | */ | ||
389 | static unsigned int __init init_chipset_sl82c105(struct pci_dev *dev, const char *msg) | ||
390 | { | ||
391 | u32 val; | ||
392 | |||
393 | DBG(("init_chipset_sl82c105()\n")); | ||
394 | |||
395 | pci_read_config_dword(dev, 0x40, &val); | ||
396 | val |= CTRL_P0EN | CTRL_P0F16 | CTRL_P1F16; | ||
397 | pci_write_config_dword(dev, 0x40, val); | ||
398 | |||
399 | return dev->irq; | ||
400 | } | ||
401 | |||
402 | static void __init init_dma_sl82c105(ide_hwif_t *hwif, unsigned long dma_base) | ||
403 | { | ||
404 | unsigned int rev; | ||
405 | u8 dma_state; | ||
406 | |||
407 | DBG(("init_dma_sl82c105(hwif: ide%d, dma_base: 0x%08x)\n", hwif->index, dma_base)); | ||
408 | |||
409 | hwif->autodma = 0; | ||
410 | |||
411 | if (!dma_base) | ||
412 | return; | ||
413 | |||
414 | dma_state = hwif->INB(dma_base + 2); | ||
415 | rev = sl82c105_bridge_revision(hwif->pci_dev); | ||
416 | if (rev <= 5) { | ||
417 | printk(" %s: Winbond 553 bridge revision %d, BM-DMA disabled\n", | ||
418 | hwif->name, rev); | ||
419 | dma_state &= ~0x60; | ||
420 | } else { | ||
421 | dma_state |= 0x60; | ||
422 | if (!noautodma) | ||
423 | hwif->autodma = 1; | ||
424 | } | ||
425 | hwif->OUTB(dma_state, dma_base + 2); | ||
426 | |||
427 | ide_setup_dma(hwif, dma_base, 8); | ||
428 | } | ||
429 | |||
430 | /* | ||
431 | * Initialise the chip | ||
432 | */ | ||
433 | |||
434 | static void __init init_hwif_sl82c105(ide_hwif_t *hwif) | ||
435 | { | ||
436 | struct pci_dev *dev = hwif->pci_dev; | ||
437 | u32 val; | ||
438 | |||
439 | DBG(("init_hwif_sl82c105(hwif: ide%d)\n", hwif->index)); | ||
440 | |||
441 | hwif->tuneproc = tune_sl82c105; | ||
442 | hwif->selectproc = sl82c105_selectproc; | ||
443 | hwif->resetproc = sl82c105_resetproc; | ||
444 | |||
445 | /* Default to PIO 0 for fallback unless tuned otherwise, | ||
446 | * we always autotune PIO, this is done before DMA is | ||
447 | * checked, so there is no risk of accidentally disabling | ||
448 | * DMA | ||
449 | */ | ||
450 | hwif->drives[0].pio_speed = XFER_PIO_0; | ||
451 | hwif->drives[0].autotune = 1; | ||
452 | hwif->drives[1].pio_speed = XFER_PIO_1; | ||
453 | hwif->drives[1].autotune = 1; | ||
454 | |||
455 | pci_read_config_dword(dev, 0x40, &val); | ||
456 | *((u32 *)&hwif->hwif_data) = val; | ||
457 | |||
458 | if (!hwif->dma_base) | ||
459 | return; | ||
460 | |||
461 | hwif->atapi_dma = 1; | ||
462 | hwif->mwdma_mask = 0x07; | ||
463 | hwif->swdma_mask = 0x07; | ||
464 | |||
465 | #ifdef CONFIG_BLK_DEV_IDEDMA | ||
466 | hwif->ide_dma_check = &sl82c105_check_drive; | ||
467 | hwif->ide_dma_on = &sl82c105_ide_dma_on; | ||
468 | hwif->ide_dma_off_quietly = &sl82c105_ide_dma_off_quietly; | ||
469 | hwif->ide_dma_lostirq = &sl82c105_ide_dma_lost_irq; | ||
470 | hwif->dma_start = &sl82c105_ide_dma_start; | ||
471 | hwif->ide_dma_timeout = &sl82c105_ide_dma_timeout; | ||
472 | |||
473 | if (!noautodma) | ||
474 | hwif->autodma = 1; | ||
475 | hwif->drives[0].autodma = hwif->autodma; | ||
476 | hwif->drives[1].autodma = hwif->autodma; | ||
477 | #endif /* CONFIG_BLK_DEV_IDEDMA */ | ||
478 | } | ||
479 | |||
480 | static ide_pci_device_t sl82c105_chipset __devinitdata = { | ||
481 | .name = "W82C105", | ||
482 | .init_chipset = init_chipset_sl82c105, | ||
483 | .init_hwif = init_hwif_sl82c105, | ||
484 | .init_dma = init_dma_sl82c105, | ||
485 | .channels = 2, | ||
486 | .autodma = NOAUTODMA, | ||
487 | .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}}, | ||
488 | .bootable = ON_BOARD, | ||
489 | }; | ||
490 | |||
491 | static int __devinit sl82c105_init_one(struct pci_dev *dev, const struct pci_device_id *id) | ||
492 | { | ||
493 | return ide_setup_pci_device(dev, &sl82c105_chipset); | ||
494 | } | ||
495 | |||
496 | static struct pci_device_id sl82c105_pci_tbl[] = { | ||
497 | { PCI_VENDOR_ID_WINBOND, PCI_DEVICE_ID_WINBOND_82C105, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, | ||
498 | { 0, }, | ||
499 | }; | ||
500 | MODULE_DEVICE_TABLE(pci, sl82c105_pci_tbl); | ||
501 | |||
502 | static struct pci_driver driver = { | ||
503 | .name = "W82C105_IDE", | ||
504 | .id_table = sl82c105_pci_tbl, | ||
505 | .probe = sl82c105_init_one, | ||
506 | }; | ||
507 | |||
508 | static int sl82c105_ide_init(void) | ||
509 | { | ||
510 | return ide_pci_register_driver(&driver); | ||
511 | } | ||
512 | |||
513 | module_init(sl82c105_ide_init); | ||
514 | |||
515 | MODULE_DESCRIPTION("PCI driver module for W82C105 IDE"); | ||
516 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/ide/pci/slc90e66.c b/drivers/ide/pci/slc90e66.c new file mode 100644 index 000000000000..7fbf36342f73 --- /dev/null +++ b/drivers/ide/pci/slc90e66.c | |||
@@ -0,0 +1,273 @@ | |||
1 | /* | ||
2 | * linux/drivers/ide/pci/slc90e66.c Version 0.11 September 11, 2002 | ||
3 | * | ||
4 | * Copyright (C) 2000-2002 Andre Hedrick <andre@linux-ide.org> | ||
5 | * | ||
6 | * This a look-a-like variation of the ICH0 PIIX4 Ultra-66, | ||
7 | * but this keeps the ISA-Bridge and slots alive. | ||
8 | * | ||
9 | */ | ||
10 | |||
11 | #include <linux/config.h> | ||
12 | #include <linux/types.h> | ||
13 | #include <linux/module.h> | ||
14 | #include <linux/kernel.h> | ||
15 | #include <linux/ioport.h> | ||
16 | #include <linux/pci.h> | ||
17 | #include <linux/hdreg.h> | ||
18 | #include <linux/ide.h> | ||
19 | #include <linux/delay.h> | ||
20 | #include <linux/init.h> | ||
21 | |||
22 | #include <asm/io.h> | ||
23 | |||
24 | static u8 slc90e66_ratemask (ide_drive_t *drive) | ||
25 | { | ||
26 | u8 mode = 2; | ||
27 | |||
28 | if (!eighty_ninty_three(drive)) | ||
29 | mode = min(mode, (u8)1); | ||
30 | return mode; | ||
31 | } | ||
32 | |||
33 | static u8 slc90e66_dma_2_pio (u8 xfer_rate) { | ||
34 | switch(xfer_rate) { | ||
35 | case XFER_UDMA_4: | ||
36 | case XFER_UDMA_3: | ||
37 | case XFER_UDMA_2: | ||
38 | case XFER_UDMA_1: | ||
39 | case XFER_UDMA_0: | ||
40 | case XFER_MW_DMA_2: | ||
41 | case XFER_PIO_4: | ||
42 | return 4; | ||
43 | case XFER_MW_DMA_1: | ||
44 | case XFER_PIO_3: | ||
45 | return 3; | ||
46 | case XFER_SW_DMA_2: | ||
47 | case XFER_PIO_2: | ||
48 | return 2; | ||
49 | case XFER_MW_DMA_0: | ||
50 | case XFER_SW_DMA_1: | ||
51 | case XFER_SW_DMA_0: | ||
52 | case XFER_PIO_1: | ||
53 | case XFER_PIO_0: | ||
54 | case XFER_PIO_SLOW: | ||
55 | default: | ||
56 | return 0; | ||
57 | } | ||
58 | } | ||
59 | |||
60 | /* | ||
61 | * Based on settings done by AMI BIOS | ||
62 | * (might be useful if drive is not registered in CMOS for any reason). | ||
63 | */ | ||
64 | static void slc90e66_tune_drive (ide_drive_t *drive, u8 pio) | ||
65 | { | ||
66 | ide_hwif_t *hwif = HWIF(drive); | ||
67 | struct pci_dev *dev = hwif->pci_dev; | ||
68 | int is_slave = (&hwif->drives[1] == drive); | ||
69 | int master_port = hwif->channel ? 0x42 : 0x40; | ||
70 | int slave_port = 0x44; | ||
71 | unsigned long flags; | ||
72 | u16 master_data; | ||
73 | u8 slave_data; | ||
74 | /* ISP RTC */ | ||
75 | u8 timings[][2] = { { 0, 0 }, | ||
76 | { 0, 0 }, | ||
77 | { 1, 0 }, | ||
78 | { 2, 1 }, | ||
79 | { 2, 3 }, }; | ||
80 | |||
81 | pio = ide_get_best_pio_mode(drive, pio, 5, NULL); | ||
82 | spin_lock_irqsave(&ide_lock, flags); | ||
83 | pci_read_config_word(dev, master_port, &master_data); | ||
84 | if (is_slave) { | ||
85 | master_data = master_data | 0x4000; | ||
86 | if (pio > 1) | ||
87 | /* enable PPE, IE and TIME */ | ||
88 | master_data = master_data | 0x0070; | ||
89 | pci_read_config_byte(dev, slave_port, &slave_data); | ||
90 | slave_data = slave_data & (hwif->channel ? 0x0f : 0xf0); | ||
91 | slave_data = slave_data | (((timings[pio][0] << 2) | timings[pio][1]) << (hwif->channel ? 4 : 0)); | ||
92 | } else { | ||
93 | master_data = master_data & 0xccf8; | ||
94 | if (pio > 1) | ||
95 | /* enable PPE, IE and TIME */ | ||
96 | master_data = master_data | 0x0007; | ||
97 | master_data = master_data | (timings[pio][0] << 12) | (timings[pio][1] << 8); | ||
98 | } | ||
99 | pci_write_config_word(dev, master_port, master_data); | ||
100 | if (is_slave) | ||
101 | pci_write_config_byte(dev, slave_port, slave_data); | ||
102 | spin_unlock_irqrestore(&ide_lock, flags); | ||
103 | } | ||
104 | |||
105 | static int slc90e66_tune_chipset (ide_drive_t *drive, u8 xferspeed) | ||
106 | { | ||
107 | ide_hwif_t *hwif = HWIF(drive); | ||
108 | struct pci_dev *dev = hwif->pci_dev; | ||
109 | u8 maslave = hwif->channel ? 0x42 : 0x40; | ||
110 | u8 speed = ide_rate_filter(slc90e66_ratemask(drive), xferspeed); | ||
111 | int sitre = 0, a_speed = 7 << (drive->dn * 4); | ||
112 | int u_speed = 0, u_flag = 1 << drive->dn; | ||
113 | u16 reg4042, reg44, reg48, reg4a; | ||
114 | |||
115 | pci_read_config_word(dev, maslave, ®4042); | ||
116 | sitre = (reg4042 & 0x4000) ? 1 : 0; | ||
117 | pci_read_config_word(dev, 0x44, ®44); | ||
118 | pci_read_config_word(dev, 0x48, ®48); | ||
119 | pci_read_config_word(dev, 0x4a, ®4a); | ||
120 | |||
121 | switch(speed) { | ||
122 | #ifdef CONFIG_BLK_DEV_IDEDMA | ||
123 | case XFER_UDMA_4: u_speed = 4 << (drive->dn * 4); break; | ||
124 | case XFER_UDMA_3: u_speed = 3 << (drive->dn * 4); break; | ||
125 | case XFER_UDMA_2: u_speed = 2 << (drive->dn * 4); break; | ||
126 | case XFER_UDMA_1: u_speed = 1 << (drive->dn * 4); break; | ||
127 | case XFER_UDMA_0: u_speed = 0 << (drive->dn * 4); break; | ||
128 | case XFER_MW_DMA_2: | ||
129 | case XFER_MW_DMA_1: | ||
130 | case XFER_SW_DMA_2: break; | ||
131 | #endif /* CONFIG_BLK_DEV_IDEDMA */ | ||
132 | case XFER_PIO_4: | ||
133 | case XFER_PIO_3: | ||
134 | case XFER_PIO_2: | ||
135 | case XFER_PIO_0: break; | ||
136 | default: return -1; | ||
137 | } | ||
138 | |||
139 | if (speed >= XFER_UDMA_0) { | ||
140 | if (!(reg48 & u_flag)) | ||
141 | pci_write_config_word(dev, 0x48, reg48|u_flag); | ||
142 | /* FIXME: (reg4a & a_speed) ? */ | ||
143 | if ((reg4a & u_speed) != u_speed) { | ||
144 | pci_write_config_word(dev, 0x4a, reg4a & ~a_speed); | ||
145 | pci_read_config_word(dev, 0x4a, ®4a); | ||
146 | pci_write_config_word(dev, 0x4a, reg4a|u_speed); | ||
147 | } | ||
148 | } else { | ||
149 | if (reg48 & u_flag) | ||
150 | pci_write_config_word(dev, 0x48, reg48 & ~u_flag); | ||
151 | if (reg4a & a_speed) | ||
152 | pci_write_config_word(dev, 0x4a, reg4a & ~a_speed); | ||
153 | } | ||
154 | |||
155 | slc90e66_tune_drive(drive, slc90e66_dma_2_pio(speed)); | ||
156 | return (ide_config_drive_speed(drive, speed)); | ||
157 | } | ||
158 | |||
159 | #ifdef CONFIG_BLK_DEV_IDEDMA | ||
160 | static int slc90e66_config_drive_for_dma (ide_drive_t *drive) | ||
161 | { | ||
162 | u8 speed = ide_dma_speed(drive, slc90e66_ratemask(drive)); | ||
163 | |||
164 | if (!(speed)) { | ||
165 | u8 tspeed = ide_get_best_pio_mode(drive, 255, 5, NULL); | ||
166 | speed = slc90e66_dma_2_pio(XFER_PIO_0 + tspeed); | ||
167 | } | ||
168 | |||
169 | (void) slc90e66_tune_chipset(drive, speed); | ||
170 | return ide_dma_enable(drive); | ||
171 | } | ||
172 | |||
173 | static int slc90e66_config_drive_xfer_rate (ide_drive_t *drive) | ||
174 | { | ||
175 | ide_hwif_t *hwif = HWIF(drive); | ||
176 | struct hd_driveid *id = drive->id; | ||
177 | |||
178 | drive->init_speed = 0; | ||
179 | |||
180 | if (id && (id->capability & 1) && drive->autodma) { | ||
181 | |||
182 | if (ide_use_dma(drive)) { | ||
183 | if (slc90e66_config_drive_for_dma(drive)) | ||
184 | return hwif->ide_dma_on(drive); | ||
185 | } | ||
186 | |||
187 | goto fast_ata_pio; | ||
188 | |||
189 | } else if ((id->capability & 8) || (id->field_valid & 2)) { | ||
190 | fast_ata_pio: | ||
191 | hwif->tuneproc(drive, 5); | ||
192 | return hwif->ide_dma_off_quietly(drive); | ||
193 | } | ||
194 | /* IORDY not supported */ | ||
195 | return 0; | ||
196 | } | ||
197 | #endif /* CONFIG_BLK_DEV_IDEDMA */ | ||
198 | |||
199 | static void __init init_hwif_slc90e66 (ide_hwif_t *hwif) | ||
200 | { | ||
201 | u8 reg47 = 0; | ||
202 | u8 mask = hwif->channel ? 0x01 : 0x02; /* bit0:Primary */ | ||
203 | |||
204 | hwif->autodma = 0; | ||
205 | |||
206 | if (!hwif->irq) | ||
207 | hwif->irq = hwif->channel ? 15 : 14; | ||
208 | |||
209 | hwif->speedproc = &slc90e66_tune_chipset; | ||
210 | hwif->tuneproc = &slc90e66_tune_drive; | ||
211 | |||
212 | pci_read_config_byte(hwif->pci_dev, 0x47, ®47); | ||
213 | |||
214 | if (!hwif->dma_base) { | ||
215 | hwif->drives[0].autotune = 1; | ||
216 | hwif->drives[1].autotune = 1; | ||
217 | return; | ||
218 | } | ||
219 | |||
220 | hwif->atapi_dma = 1; | ||
221 | hwif->ultra_mask = 0x1f; | ||
222 | hwif->mwdma_mask = 0x07; | ||
223 | hwif->swdma_mask = 0x07; | ||
224 | |||
225 | #ifdef CONFIG_BLK_DEV_IDEDMA | ||
226 | if (!(hwif->udma_four)) | ||
227 | /* bit[0(1)]: 0:80, 1:40 */ | ||
228 | hwif->udma_four = (reg47 & mask) ? 0 : 1; | ||
229 | |||
230 | hwif->ide_dma_check = &slc90e66_config_drive_xfer_rate; | ||
231 | if (!noautodma) | ||
232 | hwif->autodma = 1; | ||
233 | hwif->drives[0].autodma = hwif->autodma; | ||
234 | hwif->drives[1].autodma = hwif->autodma; | ||
235 | #endif /* !CONFIG_BLK_DEV_IDEDMA */ | ||
236 | } | ||
237 | |||
238 | static ide_pci_device_t slc90e66_chipset __devinitdata = { | ||
239 | .name = "SLC90E66", | ||
240 | .init_hwif = init_hwif_slc90e66, | ||
241 | .channels = 2, | ||
242 | .autodma = AUTODMA, | ||
243 | .enablebits = {{0x41,0x80,0x80}, {0x43,0x80,0x80}}, | ||
244 | .bootable = ON_BOARD, | ||
245 | }; | ||
246 | |||
247 | static int __devinit slc90e66_init_one(struct pci_dev *dev, const struct pci_device_id *id) | ||
248 | { | ||
249 | return ide_setup_pci_device(dev, &slc90e66_chipset); | ||
250 | } | ||
251 | |||
252 | static struct pci_device_id slc90e66_pci_tbl[] = { | ||
253 | { PCI_VENDOR_ID_EFAR, PCI_DEVICE_ID_EFAR_SLC90E66_1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, | ||
254 | { 0, }, | ||
255 | }; | ||
256 | MODULE_DEVICE_TABLE(pci, slc90e66_pci_tbl); | ||
257 | |||
258 | static struct pci_driver driver = { | ||
259 | .name = "SLC90e66_IDE", | ||
260 | .id_table = slc90e66_pci_tbl, | ||
261 | .probe = slc90e66_init_one, | ||
262 | }; | ||
263 | |||
264 | static int slc90e66_ide_init(void) | ||
265 | { | ||
266 | return ide_pci_register_driver(&driver); | ||
267 | } | ||
268 | |||
269 | module_init(slc90e66_ide_init); | ||
270 | |||
271 | MODULE_AUTHOR("Andre Hedrick"); | ||
272 | MODULE_DESCRIPTION("PCI driver module for SLC90E66 IDE"); | ||
273 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/ide/pci/triflex.c b/drivers/ide/pci/triflex.c new file mode 100644 index 000000000000..a1df2bfe3631 --- /dev/null +++ b/drivers/ide/pci/triflex.c | |||
@@ -0,0 +1,188 @@ | |||
1 | /* | ||
2 | * triflex.c | ||
3 | * | ||
4 | * IDE Chipset driver for the Compaq TriFlex IDE controller. | ||
5 | * | ||
6 | * Known to work with the Compaq Workstation 5x00 series. | ||
7 | * | ||
8 | * Copyright (C) 2002 Hewlett-Packard Development Group, L.P. | ||
9 | * Author: Torben Mathiasen <torben.mathiasen@hp.com> | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or modify | ||
12 | * it under the terms of the GNU General Public License version 2 as | ||
13 | * published by the Free Software Foundation. | ||
14 | * | ||
15 | * This program is distributed in the hope that it will be useful, | ||
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
18 | * GNU General Public License for more details. | ||
19 | * | ||
20 | * You should have received a copy of the GNU General Public License | ||
21 | * along with this program; if not, write to the Free Software | ||
22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
23 | * | ||
24 | * Loosely based on the piix & svwks drivers. | ||
25 | * | ||
26 | * Documentation: | ||
27 | * Not publically available. | ||
28 | */ | ||
29 | |||
30 | #include <linux/config.h> | ||
31 | #include <linux/types.h> | ||
32 | #include <linux/module.h> | ||
33 | #include <linux/kernel.h> | ||
34 | #include <linux/delay.h> | ||
35 | #include <linux/timer.h> | ||
36 | #include <linux/mm.h> | ||
37 | #include <linux/ioport.h> | ||
38 | #include <linux/blkdev.h> | ||
39 | #include <linux/hdreg.h> | ||
40 | #include <linux/pci.h> | ||
41 | #include <linux/ide.h> | ||
42 | #include <linux/init.h> | ||
43 | |||
44 | static int triflex_tune_chipset(ide_drive_t *drive, u8 xferspeed) | ||
45 | { | ||
46 | ide_hwif_t *hwif = HWIF(drive); | ||
47 | struct pci_dev *dev = hwif->pci_dev; | ||
48 | u8 channel_offset = hwif->channel ? 0x74 : 0x70; | ||
49 | u16 timing = 0; | ||
50 | u32 triflex_timings = 0; | ||
51 | u8 unit = (drive->select.b.unit & 0x01); | ||
52 | u8 speed = ide_rate_filter(0, xferspeed); | ||
53 | |||
54 | pci_read_config_dword(dev, channel_offset, &triflex_timings); | ||
55 | |||
56 | switch(speed) { | ||
57 | case XFER_MW_DMA_2: | ||
58 | timing = 0x0103; | ||
59 | break; | ||
60 | case XFER_MW_DMA_1: | ||
61 | timing = 0x0203; | ||
62 | break; | ||
63 | case XFER_MW_DMA_0: | ||
64 | timing = 0x0808; | ||
65 | break; | ||
66 | case XFER_SW_DMA_2: | ||
67 | case XFER_SW_DMA_1: | ||
68 | case XFER_SW_DMA_0: | ||
69 | timing = 0x0f0f; | ||
70 | break; | ||
71 | case XFER_PIO_4: | ||
72 | timing = 0x0202; | ||
73 | break; | ||
74 | case XFER_PIO_3: | ||
75 | timing = 0x0204; | ||
76 | break; | ||
77 | case XFER_PIO_2: | ||
78 | timing = 0x0404; | ||
79 | break; | ||
80 | case XFER_PIO_1: | ||
81 | timing = 0x0508; | ||
82 | break; | ||
83 | case XFER_PIO_0: | ||
84 | timing = 0x0808; | ||
85 | break; | ||
86 | default: | ||
87 | return -1; | ||
88 | } | ||
89 | |||
90 | triflex_timings &= ~(0xFFFF << (16 * unit)); | ||
91 | triflex_timings |= (timing << (16 * unit)); | ||
92 | |||
93 | pci_write_config_dword(dev, channel_offset, triflex_timings); | ||
94 | |||
95 | return (ide_config_drive_speed(drive, speed)); | ||
96 | } | ||
97 | |||
98 | static void triflex_tune_drive(ide_drive_t *drive, u8 pio) | ||
99 | { | ||
100 | int use_pio = ide_get_best_pio_mode(drive, pio, 4, NULL); | ||
101 | (void) triflex_tune_chipset(drive, (XFER_PIO_0 + use_pio)); | ||
102 | } | ||
103 | |||
104 | static int triflex_config_drive_for_dma(ide_drive_t *drive) | ||
105 | { | ||
106 | int speed = ide_dma_speed(drive, 0); /* No ultra speeds */ | ||
107 | |||
108 | if (!speed) { | ||
109 | u8 pspeed = ide_get_best_pio_mode(drive, 255, 4, NULL); | ||
110 | speed = XFER_PIO_0 + pspeed; | ||
111 | } | ||
112 | |||
113 | (void) triflex_tune_chipset(drive, speed); | ||
114 | return ide_dma_enable(drive); | ||
115 | } | ||
116 | |||
117 | static int triflex_config_drive_xfer_rate(ide_drive_t *drive) | ||
118 | { | ||
119 | ide_hwif_t *hwif = HWIF(drive); | ||
120 | struct hd_driveid *id = drive->id; | ||
121 | |||
122 | if ((id->capability & 1) && drive->autodma) { | ||
123 | if (ide_use_dma(drive)) { | ||
124 | if (triflex_config_drive_for_dma(drive)) | ||
125 | return hwif->ide_dma_on(drive); | ||
126 | } | ||
127 | } | ||
128 | |||
129 | hwif->tuneproc(drive, 255); | ||
130 | return hwif->ide_dma_off_quietly(drive); | ||
131 | } | ||
132 | |||
133 | static void __init init_hwif_triflex(ide_hwif_t *hwif) | ||
134 | { | ||
135 | hwif->tuneproc = &triflex_tune_drive; | ||
136 | hwif->speedproc = &triflex_tune_chipset; | ||
137 | |||
138 | hwif->atapi_dma = 1; | ||
139 | hwif->mwdma_mask = 0x07; | ||
140 | hwif->swdma_mask = 0x07; | ||
141 | hwif->ide_dma_check = &triflex_config_drive_xfer_rate; | ||
142 | |||
143 | if (!noautodma) | ||
144 | hwif->autodma = 1; | ||
145 | hwif->drives[0].autodma = hwif->autodma; | ||
146 | hwif->drives[1].autodma = hwif->autodma; | ||
147 | } | ||
148 | |||
149 | static ide_pci_device_t triflex_device __devinitdata = { | ||
150 | .name = "TRIFLEX", | ||
151 | .init_hwif = init_hwif_triflex, | ||
152 | .channels = 2, | ||
153 | .autodma = AUTODMA, | ||
154 | .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}}, | ||
155 | .bootable = ON_BOARD, | ||
156 | }; | ||
157 | |||
158 | static int __devinit triflex_init_one(struct pci_dev *dev, | ||
159 | const struct pci_device_id *id) | ||
160 | { | ||
161 | return ide_setup_pci_device(dev, &triflex_device); | ||
162 | } | ||
163 | |||
164 | static struct pci_device_id triflex_pci_tbl[] = { | ||
165 | { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_TRIFLEX_IDE, | ||
166 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, | ||
167 | { 0, }, | ||
168 | }; | ||
169 | MODULE_DEVICE_TABLE(pci, triflex_pci_tbl); | ||
170 | |||
171 | static struct pci_driver driver = { | ||
172 | .name = "TRIFLEX_IDE", | ||
173 | .id_table = triflex_pci_tbl, | ||
174 | .probe = triflex_init_one, | ||
175 | }; | ||
176 | |||
177 | static int triflex_ide_init(void) | ||
178 | { | ||
179 | return ide_pci_register_driver(&driver); | ||
180 | } | ||
181 | |||
182 | module_init(triflex_ide_init); | ||
183 | |||
184 | MODULE_AUTHOR("Torben Mathiasen"); | ||
185 | MODULE_DESCRIPTION("PCI driver module for Compaq Triflex IDE"); | ||
186 | MODULE_LICENSE("GPL"); | ||
187 | |||
188 | |||
diff --git a/drivers/ide/pci/trm290.c b/drivers/ide/pci/trm290.c new file mode 100644 index 000000000000..8b5eea5405ef --- /dev/null +++ b/drivers/ide/pci/trm290.c | |||
@@ -0,0 +1,369 @@ | |||
1 | /* | ||
2 | * linux/drivers/ide/pci/trm290.c Version 1.02 Mar. 18, 2000 | ||
3 | * | ||
4 | * Copyright (c) 1997-1998 Mark Lord | ||
5 | * May be copied or modified under the terms of the GNU General Public License | ||
6 | * | ||
7 | * June 22, 2004 - get rid of check_region | ||
8 | * Jesper Juhl <juhl-lkml@dif.dk> | ||
9 | * | ||
10 | */ | ||
11 | |||
12 | /* | ||
13 | * This module provides support for the bus-master IDE DMA function | ||
14 | * of the Tekram TRM290 chip, used on a variety of PCI IDE add-on boards, | ||
15 | * including a "Precision Instruments" board. The TRM290 pre-dates | ||
16 | * the sff-8038 standard (ide-dma.c) by a few months, and differs | ||
17 | * significantly enough to warrant separate routines for some functions, | ||
18 | * while re-using others from ide-dma.c. | ||
19 | * | ||
20 | * EXPERIMENTAL! It works for me (a sample of one). | ||
21 | * | ||
22 | * Works reliably for me in DMA mode (READs only), | ||
23 | * DMA WRITEs are disabled by default (see #define below); | ||
24 | * | ||
25 | * DMA is not enabled automatically for this chipset, | ||
26 | * but can be turned on manually (with "hdparm -d1") at run time. | ||
27 | * | ||
28 | * I need volunteers with "spare" drives for further testing | ||
29 | * and development, and maybe to help figure out the peculiarities. | ||
30 | * Even knowing the registers (below), some things behave strangely. | ||
31 | */ | ||
32 | |||
33 | #define TRM290_NO_DMA_WRITES /* DMA writes seem unreliable sometimes */ | ||
34 | |||
35 | /* | ||
36 | * TRM-290 PCI-IDE2 Bus Master Chip | ||
37 | * ================================ | ||
38 | * The configuration registers are addressed in normal I/O port space | ||
39 | * and are used as follows: | ||
40 | * | ||
41 | * trm290_base depends on jumper settings, and is probed for by ide-dma.c | ||
42 | * | ||
43 | * trm290_base+2 when WRITTEN: chiptest register (byte, write-only) | ||
44 | * bit7 must always be written as "1" | ||
45 | * bits6-2 undefined | ||
46 | * bit1 1=legacy_compatible_mode, 0=native_pci_mode | ||
47 | * bit0 1=test_mode, 0=normal(default) | ||
48 | * | ||
49 | * trm290_base+2 when READ: status register (byte, read-only) | ||
50 | * bits7-2 undefined | ||
51 | * bit1 channel0 busmaster interrupt status 0=none, 1=asserted | ||
52 | * bit0 channel0 interrupt status 0=none, 1=asserted | ||
53 | * | ||
54 | * trm290_base+3 Interrupt mask register | ||
55 | * bits7-5 undefined | ||
56 | * bit4 legacy_header: 1=present, 0=absent | ||
57 | * bit3 channel1 busmaster interrupt status 0=none, 1=asserted (read only) | ||
58 | * bit2 channel1 interrupt status 0=none, 1=asserted (read only) | ||
59 | * bit1 channel1 interrupt mask: 1=masked, 0=unmasked(default) | ||
60 | * bit0 channel0 interrupt mask: 1=masked, 0=unmasked(default) | ||
61 | * | ||
62 | * trm290_base+1 "CPR" Config Pointer Register (byte) | ||
63 | * bit7 1=autoincrement CPR bits 2-0 after each access of CDR | ||
64 | * bit6 1=min. 1 wait-state posted write cycle (default), 0=0 wait-state | ||
65 | * bit5 0=enabled master burst access (default), 1=disable (write only) | ||
66 | * bit4 PCI DEVSEL# timing select: 1=medium(default), 0=fast | ||
67 | * bit3 0=primary IDE channel, 1=secondary IDE channel | ||
68 | * bits2-0 register index for accesses through CDR port | ||
69 | * | ||
70 | * trm290_base+0 "CDR" Config Data Register (word) | ||
71 | * two sets of seven config registers, | ||
72 | * selected by CPR bit 3 (channel) and CPR bits 2-0 (index 0 to 6), | ||
73 | * each index defined below: | ||
74 | * | ||
75 | * Index-0 Base address register for command block (word) | ||
76 | * defaults: 0x1f0 for primary, 0x170 for secondary | ||
77 | * | ||
78 | * Index-1 general config register (byte) | ||
79 | * bit7 1=DMA enable, 0=DMA disable | ||
80 | * bit6 1=activate IDE_RESET, 0=no action (default) | ||
81 | * bit5 1=enable IORDY, 0=disable IORDY (default) | ||
82 | * bit4 0=16-bit data port(default), 1=8-bit (XT) data port | ||
83 | * bit3 interrupt polarity: 1=active_low, 0=active_high(default) | ||
84 | * bit2 power-saving-mode(?): 1=enable, 0=disable(default) (write only) | ||
85 | * bit1 bus_master_mode(?): 1=enable, 0=disable(default) | ||
86 | * bit0 enable_io_ports: 1=enable(default), 0=disable | ||
87 | * | ||
88 | * Index-2 read-ahead counter preload bits 0-7 (byte, write only) | ||
89 | * bits7-0 bits7-0 of readahead count | ||
90 | * | ||
91 | * Index-3 read-ahead config register (byte, write only) | ||
92 | * bit7 1=enable_readahead, 0=disable_readahead(default) | ||
93 | * bit6 1=clear_FIFO, 0=no_action | ||
94 | * bit5 undefined | ||
95 | * bit4 mode4 timing control: 1=enable, 0=disable(default) | ||
96 | * bit3 undefined | ||
97 | * bit2 undefined | ||
98 | * bits1-0 bits9-8 of read-ahead count | ||
99 | * | ||
100 | * Index-4 base address register for control block (word) | ||
101 | * defaults: 0x3f6 for primary, 0x376 for secondary | ||
102 | * | ||
103 | * Index-5 data port timings (shared by both drives) (byte) | ||
104 | * standard PCI "clk" (clock) counts, default value = 0xf5 | ||
105 | * | ||
106 | * bits7-6 setup time: 00=1clk, 01=2clk, 10=3clk, 11=4clk | ||
107 | * bits5-3 hold time: 000=1clk, 001=2clk, 010=3clk, | ||
108 | * 011=4clk, 100=5clk, 101=6clk, | ||
109 | * 110=8clk, 111=12clk | ||
110 | * bits2-0 active time: 000=2clk, 001=3clk, 010=4clk, | ||
111 | * 011=5clk, 100=6clk, 101=8clk, | ||
112 | * 110=12clk, 111=16clk | ||
113 | * | ||
114 | * Index-6 command/control port timings (shared by both drives) (byte) | ||
115 | * same layout as Index-5, default value = 0xde | ||
116 | * | ||
117 | * Suggested CDR programming for PIO mode0 (600ns): | ||
118 | * 0x01f0,0x21,0xff,0x80,0x03f6,0xf5,0xde ; primary | ||
119 | * 0x0170,0x21,0xff,0x80,0x0376,0xf5,0xde ; secondary | ||
120 | * | ||
121 | * Suggested CDR programming for PIO mode3 (180ns): | ||
122 | * 0x01f0,0x21,0xff,0x80,0x03f6,0x09,0xde ; primary | ||
123 | * 0x0170,0x21,0xff,0x80,0x0376,0x09,0xde ; secondary | ||
124 | * | ||
125 | * Suggested CDR programming for PIO mode4 (120ns): | ||
126 | * 0x01f0,0x21,0xff,0x80,0x03f6,0x00,0xde ; primary | ||
127 | * 0x0170,0x21,0xff,0x80,0x0376,0x00,0xde ; secondary | ||
128 | * | ||
129 | */ | ||
130 | |||
131 | #include <linux/config.h> | ||
132 | #include <linux/types.h> | ||
133 | #include <linux/module.h> | ||
134 | #include <linux/kernel.h> | ||
135 | #include <linux/mm.h> | ||
136 | #include <linux/ioport.h> | ||
137 | #include <linux/interrupt.h> | ||
138 | #include <linux/blkdev.h> | ||
139 | #include <linux/init.h> | ||
140 | #include <linux/hdreg.h> | ||
141 | #include <linux/pci.h> | ||
142 | #include <linux/delay.h> | ||
143 | #include <linux/ide.h> | ||
144 | |||
145 | #include <asm/io.h> | ||
146 | |||
147 | static void trm290_prepare_drive (ide_drive_t *drive, unsigned int use_dma) | ||
148 | { | ||
149 | ide_hwif_t *hwif = HWIF(drive); | ||
150 | u16 reg = 0; | ||
151 | unsigned long flags; | ||
152 | |||
153 | /* select PIO or DMA */ | ||
154 | reg = use_dma ? (0x21 | 0x82) : (0x21 & ~0x82); | ||
155 | |||
156 | local_irq_save(flags); | ||
157 | |||
158 | if (reg != hwif->select_data) { | ||
159 | hwif->select_data = reg; | ||
160 | /* set PIO/DMA */ | ||
161 | hwif->OUTB(0x51|(hwif->channel<<3), hwif->config_data+1); | ||
162 | hwif->OUTW(reg & 0xff, hwif->config_data); | ||
163 | } | ||
164 | |||
165 | /* enable IRQ if not probing */ | ||
166 | if (drive->present) { | ||
167 | reg = hwif->INW(hwif->config_data + 3); | ||
168 | reg &= 0x13; | ||
169 | reg &= ~(1 << hwif->channel); | ||
170 | hwif->OUTW(reg, hwif->config_data+3); | ||
171 | } | ||
172 | |||
173 | local_irq_restore(flags); | ||
174 | } | ||
175 | |||
176 | static void trm290_selectproc (ide_drive_t *drive) | ||
177 | { | ||
178 | trm290_prepare_drive(drive, drive->using_dma); | ||
179 | } | ||
180 | |||
181 | #ifdef CONFIG_BLK_DEV_IDEDMA | ||
182 | static void trm290_ide_dma_exec_cmd(ide_drive_t *drive, u8 command) | ||
183 | { | ||
184 | ide_hwif_t *hwif = HWIF(drive); | ||
185 | |||
186 | if (HWGROUP(drive)->handler != NULL) /* paranoia check */ | ||
187 | BUG(); | ||
188 | ide_set_handler(drive, &ide_dma_intr, WAIT_CMD, NULL); | ||
189 | /* issue cmd to drive */ | ||
190 | hwif->OUTB(command, IDE_COMMAND_REG); | ||
191 | } | ||
192 | |||
193 | static int trm290_ide_dma_setup(ide_drive_t *drive) | ||
194 | { | ||
195 | ide_hwif_t *hwif = drive->hwif; | ||
196 | struct request *rq = hwif->hwgroup->rq; | ||
197 | unsigned int count, rw; | ||
198 | |||
199 | if (rq_data_dir(rq)) { | ||
200 | #ifdef TRM290_NO_DMA_WRITES | ||
201 | /* always use PIO for writes */ | ||
202 | trm290_prepare_drive(drive, 0); /* select PIO xfer */ | ||
203 | return 1; | ||
204 | #endif | ||
205 | rw = 1; | ||
206 | } else | ||
207 | rw = 2; | ||
208 | |||
209 | if (!(count = ide_build_dmatable(drive, rq))) { | ||
210 | /* try PIO instead of DMA */ | ||
211 | trm290_prepare_drive(drive, 0); /* select PIO xfer */ | ||
212 | return 1; | ||
213 | } | ||
214 | /* select DMA xfer */ | ||
215 | trm290_prepare_drive(drive, 1); | ||
216 | hwif->OUTL(hwif->dmatable_dma|rw, hwif->dma_command); | ||
217 | drive->waiting_for_dma = 1; | ||
218 | /* start DMA */ | ||
219 | hwif->OUTW((count * 2) - 1, hwif->dma_status); | ||
220 | return 0; | ||
221 | } | ||
222 | |||
223 | static void trm290_ide_dma_start(ide_drive_t *drive) | ||
224 | { | ||
225 | } | ||
226 | |||
227 | static int trm290_ide_dma_end (ide_drive_t *drive) | ||
228 | { | ||
229 | ide_hwif_t *hwif = HWIF(drive); | ||
230 | u16 status = 0; | ||
231 | |||
232 | drive->waiting_for_dma = 0; | ||
233 | /* purge DMA mappings */ | ||
234 | ide_destroy_dmatable(drive); | ||
235 | status = hwif->INW(hwif->dma_status); | ||
236 | return (status != 0x00ff); | ||
237 | } | ||
238 | |||
239 | static int trm290_ide_dma_test_irq (ide_drive_t *drive) | ||
240 | { | ||
241 | ide_hwif_t *hwif = HWIF(drive); | ||
242 | u16 status = 0; | ||
243 | |||
244 | status = hwif->INW(hwif->dma_status); | ||
245 | return (status == 0x00ff); | ||
246 | } | ||
247 | #endif /* CONFIG_BLK_DEV_IDEDMA */ | ||
248 | |||
249 | /* | ||
250 | * Invoked from ide-dma.c at boot time. | ||
251 | */ | ||
252 | static void __devinit init_hwif_trm290(ide_hwif_t *hwif) | ||
253 | { | ||
254 | unsigned int cfgbase = 0; | ||
255 | unsigned long flags; | ||
256 | u8 reg = 0; | ||
257 | struct pci_dev *dev = hwif->pci_dev; | ||
258 | |||
259 | hwif->no_lba48 = 1; | ||
260 | hwif->chipset = ide_trm290; | ||
261 | cfgbase = pci_resource_start(dev, 4); | ||
262 | if ((dev->class & 5) && cfgbase) { | ||
263 | hwif->config_data = cfgbase; | ||
264 | printk(KERN_INFO "TRM290: chip config base at 0x%04lx\n", | ||
265 | hwif->config_data); | ||
266 | } else { | ||
267 | hwif->config_data = 0x3df0; | ||
268 | printk(KERN_INFO "TRM290: using default config base at 0x%04lx\n", | ||
269 | hwif->config_data); | ||
270 | } | ||
271 | |||
272 | local_irq_save(flags); | ||
273 | /* put config reg into first byte of hwif->select_data */ | ||
274 | hwif->OUTB(0x51|(hwif->channel<<3), hwif->config_data+1); | ||
275 | /* select PIO as default */ | ||
276 | hwif->select_data = 0x21; | ||
277 | hwif->OUTB(hwif->select_data, hwif->config_data); | ||
278 | /* get IRQ info */ | ||
279 | reg = hwif->INB(hwif->config_data+3); | ||
280 | /* mask IRQs for both ports */ | ||
281 | reg = (reg & 0x10) | 0x03; | ||
282 | hwif->OUTB(reg, hwif->config_data+3); | ||
283 | local_irq_restore(flags); | ||
284 | |||
285 | if ((reg & 0x10)) | ||
286 | /* legacy mode */ | ||
287 | hwif->irq = hwif->channel ? 15 : 14; | ||
288 | else if (!hwif->irq && hwif->mate && hwif->mate->irq) | ||
289 | /* sharing IRQ with mate */ | ||
290 | hwif->irq = hwif->mate->irq; | ||
291 | |||
292 | ide_setup_dma(hwif, (hwif->config_data + 4) ^ (hwif->channel ? 0x0080 : 0x0000), 3); | ||
293 | |||
294 | #ifdef CONFIG_BLK_DEV_IDEDMA | ||
295 | hwif->dma_setup = &trm290_ide_dma_setup; | ||
296 | hwif->dma_exec_cmd = &trm290_ide_dma_exec_cmd; | ||
297 | hwif->dma_start = &trm290_ide_dma_start; | ||
298 | hwif->ide_dma_end = &trm290_ide_dma_end; | ||
299 | hwif->ide_dma_test_irq = &trm290_ide_dma_test_irq; | ||
300 | #endif /* CONFIG_BLK_DEV_IDEDMA */ | ||
301 | |||
302 | hwif->selectproc = &trm290_selectproc; | ||
303 | hwif->autodma = 0; /* play it safe for now */ | ||
304 | hwif->drives[0].autodma = hwif->autodma; | ||
305 | hwif->drives[1].autodma = hwif->autodma; | ||
306 | #if 1 | ||
307 | { | ||
308 | /* | ||
309 | * My trm290-based card doesn't seem to work with all possible values | ||
310 | * for the control basereg, so this kludge ensures that we use only | ||
311 | * values that are known to work. Ugh. -ml | ||
312 | */ | ||
313 | u16 new, old, compat = hwif->channel ? 0x374 : 0x3f4; | ||
314 | static u16 next_offset = 0; | ||
315 | u8 old_mask; | ||
316 | |||
317 | hwif->OUTB(0x54|(hwif->channel<<3), hwif->config_data+1); | ||
318 | old = hwif->INW(hwif->config_data); | ||
319 | old &= ~1; | ||
320 | old_mask = hwif->INB(old+2); | ||
321 | if (old != compat && old_mask == 0xff) { | ||
322 | /* leave lower 10 bits untouched */ | ||
323 | compat += (next_offset += 0x400); | ||
324 | hwif->io_ports[IDE_CONTROL_OFFSET] = compat + 2; | ||
325 | hwif->OUTW(compat|1, hwif->config_data); | ||
326 | new = hwif->INW(hwif->config_data); | ||
327 | printk(KERN_INFO "%s: control basereg workaround: " | ||
328 | "old=0x%04x, new=0x%04x\n", | ||
329 | hwif->name, old, new & ~1); | ||
330 | } | ||
331 | } | ||
332 | #endif | ||
333 | } | ||
334 | |||
335 | static ide_pci_device_t trm290_chipset __devinitdata = { | ||
336 | .name = "TRM290", | ||
337 | .init_hwif = init_hwif_trm290, | ||
338 | .channels = 2, | ||
339 | .autodma = NOAUTODMA, | ||
340 | .bootable = ON_BOARD, | ||
341 | }; | ||
342 | |||
343 | static int __devinit trm290_init_one(struct pci_dev *dev, const struct pci_device_id *id) | ||
344 | { | ||
345 | return ide_setup_pci_device(dev, &trm290_chipset); | ||
346 | } | ||
347 | |||
348 | static struct pci_device_id trm290_pci_tbl[] = { | ||
349 | { PCI_VENDOR_ID_TEKRAM, PCI_DEVICE_ID_TEKRAM_DC290, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, | ||
350 | { 0, }, | ||
351 | }; | ||
352 | MODULE_DEVICE_TABLE(pci, trm290_pci_tbl); | ||
353 | |||
354 | static struct pci_driver driver = { | ||
355 | .name = "TRM290_IDE", | ||
356 | .id_table = trm290_pci_tbl, | ||
357 | .probe = trm290_init_one, | ||
358 | }; | ||
359 | |||
360 | static int trm290_ide_init(void) | ||
361 | { | ||
362 | return ide_pci_register_driver(&driver); | ||
363 | } | ||
364 | |||
365 | module_init(trm290_ide_init); | ||
366 | |||
367 | MODULE_AUTHOR("Mark Lord"); | ||
368 | MODULE_DESCRIPTION("PCI driver module for Tekram TRM290 IDE"); | ||
369 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/ide/pci/via82cxxx.c b/drivers/ide/pci/via82cxxx.c new file mode 100644 index 000000000000..069dbffe2116 --- /dev/null +++ b/drivers/ide/pci/via82cxxx.c | |||
@@ -0,0 +1,656 @@ | |||
1 | /* | ||
2 | * | ||
3 | * Version 3.38 | ||
4 | * | ||
5 | * VIA IDE driver for Linux. Supported southbridges: | ||
6 | * | ||
7 | * vt82c576, vt82c586, vt82c586a, vt82c586b, vt82c596a, vt82c596b, | ||
8 | * vt82c686, vt82c686a, vt82c686b, vt8231, vt8233, vt8233c, vt8233a, | ||
9 | * vt8235, vt8237 | ||
10 | * | ||
11 | * Copyright (c) 2000-2002 Vojtech Pavlik | ||
12 | * | ||
13 | * Based on the work of: | ||
14 | * Michel Aubry | ||
15 | * Jeff Garzik | ||
16 | * Andre Hedrick | ||
17 | * | ||
18 | * Documentation: | ||
19 | * Obsolete device documentation publically available from via.com.tw | ||
20 | * Current device documentation available under NDA only | ||
21 | */ | ||
22 | |||
23 | /* | ||
24 | * This program is free software; you can redistribute it and/or modify it | ||
25 | * under the terms of the GNU General Public License version 2 as published by | ||
26 | * the Free Software Foundation. | ||
27 | */ | ||
28 | |||
29 | #include <linux/config.h> | ||
30 | #include <linux/module.h> | ||
31 | #include <linux/kernel.h> | ||
32 | #include <linux/ioport.h> | ||
33 | #include <linux/blkdev.h> | ||
34 | #include <linux/pci.h> | ||
35 | #include <linux/init.h> | ||
36 | #include <linux/ide.h> | ||
37 | #include <asm/io.h> | ||
38 | |||
39 | #ifdef CONFIG_PPC_MULTIPLATFORM | ||
40 | #include <asm/processor.h> | ||
41 | #endif | ||
42 | |||
43 | #include "ide-timing.h" | ||
44 | |||
45 | #define DISPLAY_VIA_TIMINGS | ||
46 | |||
47 | #define VIA_IDE_ENABLE 0x40 | ||
48 | #define VIA_IDE_CONFIG 0x41 | ||
49 | #define VIA_FIFO_CONFIG 0x43 | ||
50 | #define VIA_MISC_1 0x44 | ||
51 | #define VIA_MISC_2 0x45 | ||
52 | #define VIA_MISC_3 0x46 | ||
53 | #define VIA_DRIVE_TIMING 0x48 | ||
54 | #define VIA_8BIT_TIMING 0x4e | ||
55 | #define VIA_ADDRESS_SETUP 0x4c | ||
56 | #define VIA_UDMA_TIMING 0x50 | ||
57 | |||
58 | #define VIA_UDMA 0x007 | ||
59 | #define VIA_UDMA_NONE 0x000 | ||
60 | #define VIA_UDMA_33 0x001 | ||
61 | #define VIA_UDMA_66 0x002 | ||
62 | #define VIA_UDMA_100 0x003 | ||
63 | #define VIA_UDMA_133 0x004 | ||
64 | #define VIA_BAD_PREQ 0x010 /* Crashes if PREQ# till DDACK# set */ | ||
65 | #define VIA_BAD_CLK66 0x020 /* 66 MHz clock doesn't work correctly */ | ||
66 | #define VIA_SET_FIFO 0x040 /* Needs to have FIFO split set */ | ||
67 | #define VIA_NO_UNMASK 0x080 /* Doesn't work with IRQ unmasking on */ | ||
68 | #define VIA_BAD_ID 0x100 /* Has wrong vendor ID (0x1107) */ | ||
69 | #define VIA_BAD_AST 0x200 /* Don't touch Address Setup Timing */ | ||
70 | |||
71 | /* | ||
72 | * VIA SouthBridge chips. | ||
73 | */ | ||
74 | |||
75 | static struct via_isa_bridge { | ||
76 | char *name; | ||
77 | u16 id; | ||
78 | u8 rev_min; | ||
79 | u8 rev_max; | ||
80 | u16 flags; | ||
81 | } via_isa_bridges[] = { | ||
82 | { "vt8237", PCI_DEVICE_ID_VIA_8237, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST }, | ||
83 | { "vt8235", PCI_DEVICE_ID_VIA_8235, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST }, | ||
84 | { "vt8233a", PCI_DEVICE_ID_VIA_8233A, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST }, | ||
85 | { "vt8233c", PCI_DEVICE_ID_VIA_8233C_0, 0x00, 0x2f, VIA_UDMA_100 }, | ||
86 | { "vt8233", PCI_DEVICE_ID_VIA_8233_0, 0x00, 0x2f, VIA_UDMA_100 }, | ||
87 | { "vt8231", PCI_DEVICE_ID_VIA_8231, 0x00, 0x2f, VIA_UDMA_100 }, | ||
88 | { "vt82c686b", PCI_DEVICE_ID_VIA_82C686, 0x40, 0x4f, VIA_UDMA_100 }, | ||
89 | { "vt82c686a", PCI_DEVICE_ID_VIA_82C686, 0x10, 0x2f, VIA_UDMA_66 }, | ||
90 | { "vt82c686", PCI_DEVICE_ID_VIA_82C686, 0x00, 0x0f, VIA_UDMA_33 | VIA_BAD_CLK66 }, | ||
91 | { "vt82c596b", PCI_DEVICE_ID_VIA_82C596, 0x10, 0x2f, VIA_UDMA_66 }, | ||
92 | { "vt82c596a", PCI_DEVICE_ID_VIA_82C596, 0x00, 0x0f, VIA_UDMA_33 | VIA_BAD_CLK66 }, | ||
93 | { "vt82c586b", PCI_DEVICE_ID_VIA_82C586_0, 0x47, 0x4f, VIA_UDMA_33 | VIA_SET_FIFO }, | ||
94 | { "vt82c586b", PCI_DEVICE_ID_VIA_82C586_0, 0x40, 0x46, VIA_UDMA_33 | VIA_SET_FIFO | VIA_BAD_PREQ }, | ||
95 | { "vt82c586b", PCI_DEVICE_ID_VIA_82C586_0, 0x30, 0x3f, VIA_UDMA_33 | VIA_SET_FIFO }, | ||
96 | { "vt82c586a", PCI_DEVICE_ID_VIA_82C586_0, 0x20, 0x2f, VIA_UDMA_33 | VIA_SET_FIFO }, | ||
97 | { "vt82c586", PCI_DEVICE_ID_VIA_82C586_0, 0x00, 0x0f, VIA_UDMA_NONE | VIA_SET_FIFO }, | ||
98 | { "vt82c576", PCI_DEVICE_ID_VIA_82C576, 0x00, 0x2f, VIA_UDMA_NONE | VIA_SET_FIFO | VIA_NO_UNMASK }, | ||
99 | { "vt82c576", PCI_DEVICE_ID_VIA_82C576, 0x00, 0x2f, VIA_UDMA_NONE | VIA_SET_FIFO | VIA_NO_UNMASK | VIA_BAD_ID }, | ||
100 | { NULL } | ||
101 | }; | ||
102 | |||
103 | static struct via_isa_bridge *via_config; | ||
104 | static unsigned int via_80w; | ||
105 | static unsigned int via_clock; | ||
106 | static char *via_dma[] = { "MWDMA16", "UDMA33", "UDMA66", "UDMA100", "UDMA133" }; | ||
107 | |||
108 | /* | ||
109 | * VIA /proc entry. | ||
110 | */ | ||
111 | |||
112 | #if defined(DISPLAY_VIA_TIMINGS) && defined(CONFIG_PROC_FS) | ||
113 | |||
114 | #include <linux/stat.h> | ||
115 | #include <linux/proc_fs.h> | ||
116 | |||
117 | static u8 via_proc = 0; | ||
118 | static unsigned long via_base; | ||
119 | static struct pci_dev *bmide_dev, *isa_dev; | ||
120 | |||
121 | static char *via_control3[] = { "No limit", "64", "128", "192" }; | ||
122 | |||
123 | #define via_print(format, arg...) p += sprintf(p, format "\n" , ## arg) | ||
124 | #define via_print_drive(name, format, arg...)\ | ||
125 | p += sprintf(p, name); for (i = 0; i < 4; i++) p += sprintf(p, format, ## arg); p += sprintf(p, "\n"); | ||
126 | |||
127 | |||
128 | /** | ||
129 | * via_get_info - generate via /proc file | ||
130 | * @buffer: buffer for data | ||
131 | * @addr: set to start of data to use | ||
132 | * @offset: current file offset | ||
133 | * @count: size of read | ||
134 | * | ||
135 | * Fills in buffer with the debugging/configuration information for | ||
136 | * the VIA chipset tuning and attached drives | ||
137 | */ | ||
138 | |||
139 | static int via_get_info(char *buffer, char **addr, off_t offset, int count) | ||
140 | { | ||
141 | int speed[4], cycle[4], setup[4], active[4], recover[4], den[4], | ||
142 | uen[4], udma[4], umul[4], active8b[4], recover8b[4]; | ||
143 | struct pci_dev *dev = bmide_dev; | ||
144 | unsigned int v, u, i; | ||
145 | int len; | ||
146 | u16 c, w; | ||
147 | u8 t, x; | ||
148 | char *p = buffer; | ||
149 | |||
150 | via_print("----------VIA BusMastering IDE Configuration" | ||
151 | "----------------"); | ||
152 | |||
153 | via_print("Driver Version: 3.38"); | ||
154 | via_print("South Bridge: VIA %s", | ||
155 | via_config->name); | ||
156 | |||
157 | pci_read_config_byte(isa_dev, PCI_REVISION_ID, &t); | ||
158 | pci_read_config_byte(dev, PCI_REVISION_ID, &x); | ||
159 | via_print("Revision: ISA %#x IDE %#x", t, x); | ||
160 | via_print("Highest DMA rate: %s", | ||
161 | via_dma[via_config->flags & VIA_UDMA]); | ||
162 | |||
163 | via_print("BM-DMA base: %#lx", via_base); | ||
164 | via_print("PCI clock: %d.%dMHz", | ||
165 | via_clock / 1000, via_clock / 100 % 10); | ||
166 | |||
167 | pci_read_config_byte(dev, VIA_MISC_1, &t); | ||
168 | via_print("Master Read Cycle IRDY: %dws", | ||
169 | (t & 64) >> 6); | ||
170 | via_print("Master Write Cycle IRDY: %dws", | ||
171 | (t & 32) >> 5); | ||
172 | via_print("BM IDE Status Register Read Retry: %s", | ||
173 | (t & 8) ? "yes" : "no"); | ||
174 | |||
175 | pci_read_config_byte(dev, VIA_MISC_3, &t); | ||
176 | via_print("Max DRDY Pulse Width: %s%s", | ||
177 | via_control3[(t & 0x03)], (t & 0x03) ? " PCI clocks" : ""); | ||
178 | |||
179 | via_print("-----------------------Primary IDE" | ||
180 | "-------Secondary IDE------"); | ||
181 | via_print("Read DMA FIFO flush: %10s%20s", | ||
182 | (t & 0x80) ? "yes" : "no", (t & 0x40) ? "yes" : "no"); | ||
183 | via_print("End Sector FIFO flush: %10s%20s", | ||
184 | (t & 0x20) ? "yes" : "no", (t & 0x10) ? "yes" : "no"); | ||
185 | |||
186 | pci_read_config_byte(dev, VIA_IDE_CONFIG, &t); | ||
187 | via_print("Prefetch Buffer: %10s%20s", | ||
188 | (t & 0x80) ? "yes" : "no", (t & 0x20) ? "yes" : "no"); | ||
189 | via_print("Post Write Buffer: %10s%20s", | ||
190 | (t & 0x40) ? "yes" : "no", (t & 0x10) ? "yes" : "no"); | ||
191 | |||
192 | pci_read_config_byte(dev, VIA_IDE_ENABLE, &t); | ||
193 | via_print("Enabled: %10s%20s", | ||
194 | (t & 0x02) ? "yes" : "no", (t & 0x01) ? "yes" : "no"); | ||
195 | |||
196 | c = inb(via_base + 0x02) | (inb(via_base + 0x0a) << 8); | ||
197 | via_print("Simplex only: %10s%20s", | ||
198 | (c & 0x80) ? "yes" : "no", (c & 0x8000) ? "yes" : "no"); | ||
199 | |||
200 | via_print("Cable Type: %10s%20s", | ||
201 | (via_80w & 1) ? "80w" : "40w", (via_80w & 2) ? "80w" : "40w"); | ||
202 | |||
203 | via_print("-------------------drive0----drive1" | ||
204 | "----drive2----drive3-----"); | ||
205 | |||
206 | pci_read_config_byte(dev, VIA_ADDRESS_SETUP, &t); | ||
207 | pci_read_config_dword(dev, VIA_DRIVE_TIMING, &v); | ||
208 | pci_read_config_word(dev, VIA_8BIT_TIMING, &w); | ||
209 | |||
210 | if (via_config->flags & VIA_UDMA) | ||
211 | pci_read_config_dword(dev, VIA_UDMA_TIMING, &u); | ||
212 | else u = 0; | ||
213 | |||
214 | for (i = 0; i < 4; i++) { | ||
215 | |||
216 | setup[i] = ((t >> ((3 - i) << 1)) & 0x3) + 1; | ||
217 | recover8b[i] = ((w >> ((1 - (i >> 1)) << 3)) & 0xf) + 1; | ||
218 | active8b[i] = ((w >> (((1 - (i >> 1)) << 3) + 4)) & 0xf) + 1; | ||
219 | active[i] = ((v >> (((3 - i) << 3) + 4)) & 0xf) + 1; | ||
220 | recover[i] = ((v >> ((3 - i) << 3)) & 0xf) + 1; | ||
221 | udma[i] = ((u >> ((3 - i) << 3)) & 0x7) + 2; | ||
222 | umul[i] = ((u >> (((3 - i) & 2) << 3)) & 0x8) ? 1 : 2; | ||
223 | uen[i] = ((u >> ((3 - i) << 3)) & 0x20); | ||
224 | den[i] = (c & ((i & 1) ? 0x40 : 0x20) << ((i & 2) << 2)); | ||
225 | |||
226 | speed[i] = 2 * via_clock / (active[i] + recover[i]); | ||
227 | cycle[i] = 1000000 * (active[i] + recover[i]) / via_clock; | ||
228 | |||
229 | if (!uen[i] || !den[i]) | ||
230 | continue; | ||
231 | |||
232 | switch (via_config->flags & VIA_UDMA) { | ||
233 | |||
234 | case VIA_UDMA_33: | ||
235 | speed[i] = 2 * via_clock / udma[i]; | ||
236 | cycle[i] = 1000000 * udma[i] / via_clock; | ||
237 | break; | ||
238 | |||
239 | case VIA_UDMA_66: | ||
240 | speed[i] = 4 * via_clock / (udma[i] * umul[i]); | ||
241 | cycle[i] = 500000 * (udma[i] * umul[i]) / via_clock; | ||
242 | break; | ||
243 | |||
244 | case VIA_UDMA_100: | ||
245 | speed[i] = 6 * via_clock / udma[i]; | ||
246 | cycle[i] = 333333 * udma[i] / via_clock; | ||
247 | break; | ||
248 | |||
249 | case VIA_UDMA_133: | ||
250 | speed[i] = 8 * via_clock / udma[i]; | ||
251 | cycle[i] = 250000 * udma[i] / via_clock; | ||
252 | break; | ||
253 | } | ||
254 | } | ||
255 | |||
256 | via_print_drive("Transfer Mode: ", "%10s", | ||
257 | den[i] ? (uen[i] ? "UDMA" : "DMA") : "PIO"); | ||
258 | |||
259 | via_print_drive("Address Setup: ", "%8dns", | ||
260 | 1000000 * setup[i] / via_clock); | ||
261 | via_print_drive("Cmd Active: ", "%8dns", | ||
262 | 1000000 * active8b[i] / via_clock); | ||
263 | via_print_drive("Cmd Recovery: ", "%8dns", | ||
264 | 1000000 * recover8b[i] / via_clock); | ||
265 | via_print_drive("Data Active: ", "%8dns", | ||
266 | 1000000 * active[i] / via_clock); | ||
267 | via_print_drive("Data Recovery: ", "%8dns", | ||
268 | 1000000 * recover[i] / via_clock); | ||
269 | via_print_drive("Cycle Time: ", "%8dns", | ||
270 | cycle[i]); | ||
271 | via_print_drive("Transfer Rate: ", "%4d.%dMB/s", | ||
272 | speed[i] / 1000, speed[i] / 100 % 10); | ||
273 | |||
274 | /* hoping it is less than 4K... */ | ||
275 | len = (p - buffer) - offset; | ||
276 | *addr = buffer + offset; | ||
277 | |||
278 | return len > count ? count : len; | ||
279 | } | ||
280 | |||
281 | #endif /* DISPLAY_VIA_TIMINGS && CONFIG_PROC_FS */ | ||
282 | |||
283 | /** | ||
284 | * via_set_speed - write timing registers | ||
285 | * @dev: PCI device | ||
286 | * @dn: device | ||
287 | * @timing: IDE timing data to use | ||
288 | * | ||
289 | * via_set_speed writes timing values to the chipset registers | ||
290 | */ | ||
291 | |||
292 | static void via_set_speed(struct pci_dev *dev, u8 dn, struct ide_timing *timing) | ||
293 | { | ||
294 | u8 t; | ||
295 | |||
296 | if (~via_config->flags & VIA_BAD_AST) { | ||
297 | pci_read_config_byte(dev, VIA_ADDRESS_SETUP, &t); | ||
298 | t = (t & ~(3 << ((3 - dn) << 1))) | ((FIT(timing->setup, 1, 4) - 1) << ((3 - dn) << 1)); | ||
299 | pci_write_config_byte(dev, VIA_ADDRESS_SETUP, t); | ||
300 | } | ||
301 | |||
302 | pci_write_config_byte(dev, VIA_8BIT_TIMING + (1 - (dn >> 1)), | ||
303 | ((FIT(timing->act8b, 1, 16) - 1) << 4) | (FIT(timing->rec8b, 1, 16) - 1)); | ||
304 | |||
305 | pci_write_config_byte(dev, VIA_DRIVE_TIMING + (3 - dn), | ||
306 | ((FIT(timing->active, 1, 16) - 1) << 4) | (FIT(timing->recover, 1, 16) - 1)); | ||
307 | |||
308 | switch (via_config->flags & VIA_UDMA) { | ||
309 | case VIA_UDMA_33: t = timing->udma ? (0xe0 | (FIT(timing->udma, 2, 5) - 2)) : 0x03; break; | ||
310 | case VIA_UDMA_66: t = timing->udma ? (0xe8 | (FIT(timing->udma, 2, 9) - 2)) : 0x0f; break; | ||
311 | case VIA_UDMA_100: t = timing->udma ? (0xe0 | (FIT(timing->udma, 2, 9) - 2)) : 0x07; break; | ||
312 | case VIA_UDMA_133: t = timing->udma ? (0xe0 | (FIT(timing->udma, 2, 9) - 2)) : 0x07; break; | ||
313 | default: return; | ||
314 | } | ||
315 | |||
316 | pci_write_config_byte(dev, VIA_UDMA_TIMING + (3 - dn), t); | ||
317 | } | ||
318 | |||
319 | /** | ||
320 | * via_set_drive - configure transfer mode | ||
321 | * @drive: Drive to set up | ||
322 | * @speed: desired speed | ||
323 | * | ||
324 | * via_set_drive() computes timing values configures the drive and | ||
325 | * the chipset to a desired transfer mode. It also can be called | ||
326 | * by upper layers. | ||
327 | */ | ||
328 | |||
329 | static int via_set_drive(ide_drive_t *drive, u8 speed) | ||
330 | { | ||
331 | ide_drive_t *peer = HWIF(drive)->drives + (~drive->dn & 1); | ||
332 | struct ide_timing t, p; | ||
333 | unsigned int T, UT; | ||
334 | |||
335 | if (speed != XFER_PIO_SLOW) | ||
336 | ide_config_drive_speed(drive, speed); | ||
337 | |||
338 | T = 1000000000 / via_clock; | ||
339 | |||
340 | switch (via_config->flags & VIA_UDMA) { | ||
341 | case VIA_UDMA_33: UT = T; break; | ||
342 | case VIA_UDMA_66: UT = T/2; break; | ||
343 | case VIA_UDMA_100: UT = T/3; break; | ||
344 | case VIA_UDMA_133: UT = T/4; break; | ||
345 | default: UT = T; | ||
346 | } | ||
347 | |||
348 | ide_timing_compute(drive, speed, &t, T, UT); | ||
349 | |||
350 | if (peer->present) { | ||
351 | ide_timing_compute(peer, peer->current_speed, &p, T, UT); | ||
352 | ide_timing_merge(&p, &t, &t, IDE_TIMING_8BIT); | ||
353 | } | ||
354 | |||
355 | via_set_speed(HWIF(drive)->pci_dev, drive->dn, &t); | ||
356 | |||
357 | if (!drive->init_speed) | ||
358 | drive->init_speed = speed; | ||
359 | drive->current_speed = speed; | ||
360 | |||
361 | return 0; | ||
362 | } | ||
363 | |||
364 | /** | ||
365 | * via82cxxx_tune_drive - PIO setup | ||
366 | * @drive: drive to set up | ||
367 | * @pio: mode to use (255 for 'best possible') | ||
368 | * | ||
369 | * A callback from the upper layers for PIO-only tuning. | ||
370 | */ | ||
371 | |||
372 | static void via82cxxx_tune_drive(ide_drive_t *drive, u8 pio) | ||
373 | { | ||
374 | if (pio == 255) { | ||
375 | via_set_drive(drive, | ||
376 | ide_find_best_mode(drive, XFER_PIO | XFER_EPIO)); | ||
377 | return; | ||
378 | } | ||
379 | |||
380 | via_set_drive(drive, XFER_PIO_0 + min_t(u8, pio, 5)); | ||
381 | } | ||
382 | |||
383 | /** | ||
384 | * via82cxxx_ide_dma_check - set up for DMA if possible | ||
385 | * @drive: IDE drive to set up | ||
386 | * | ||
387 | * Set up the drive for the highest supported speed considering the | ||
388 | * driver, controller and cable | ||
389 | */ | ||
390 | |||
391 | static int via82cxxx_ide_dma_check (ide_drive_t *drive) | ||
392 | { | ||
393 | u16 w80 = HWIF(drive)->udma_four; | ||
394 | |||
395 | u16 speed = ide_find_best_mode(drive, | ||
396 | XFER_PIO | XFER_EPIO | XFER_SWDMA | XFER_MWDMA | | ||
397 | (via_config->flags & VIA_UDMA ? XFER_UDMA : 0) | | ||
398 | (w80 && (via_config->flags & VIA_UDMA) >= VIA_UDMA_66 ? XFER_UDMA_66 : 0) | | ||
399 | (w80 && (via_config->flags & VIA_UDMA) >= VIA_UDMA_100 ? XFER_UDMA_100 : 0) | | ||
400 | (w80 && (via_config->flags & VIA_UDMA) >= VIA_UDMA_133 ? XFER_UDMA_133 : 0)); | ||
401 | |||
402 | via_set_drive(drive, speed); | ||
403 | |||
404 | if (drive->autodma && (speed & XFER_MODE) != XFER_PIO) | ||
405 | return HWIF(drive)->ide_dma_on(drive); | ||
406 | return HWIF(drive)->ide_dma_off_quietly(drive); | ||
407 | } | ||
408 | |||
409 | /** | ||
410 | * init_chipset_via82cxxx - initialization handler | ||
411 | * @dev: PCI device | ||
412 | * @name: Name of interface | ||
413 | * | ||
414 | * The initialization callback. Here we determine the IDE chip type | ||
415 | * and initialize its drive independent registers. | ||
416 | */ | ||
417 | |||
418 | static unsigned int __init init_chipset_via82cxxx(struct pci_dev *dev, const char *name) | ||
419 | { | ||
420 | struct pci_dev *isa = NULL; | ||
421 | u8 t, v; | ||
422 | unsigned int u; | ||
423 | int i; | ||
424 | |||
425 | /* | ||
426 | * Find the ISA bridge to see how good the IDE is. | ||
427 | */ | ||
428 | |||
429 | for (via_config = via_isa_bridges; via_config->id; via_config++) | ||
430 | if ((isa = pci_find_device(PCI_VENDOR_ID_VIA + | ||
431 | !!(via_config->flags & VIA_BAD_ID), | ||
432 | via_config->id, NULL))) { | ||
433 | |||
434 | pci_read_config_byte(isa, PCI_REVISION_ID, &t); | ||
435 | if (t >= via_config->rev_min && | ||
436 | t <= via_config->rev_max) | ||
437 | break; | ||
438 | } | ||
439 | |||
440 | if (!via_config->id) { | ||
441 | printk(KERN_WARNING "VP_IDE: Unknown VIA SouthBridge, disabling DMA.\n"); | ||
442 | return -ENODEV; | ||
443 | } | ||
444 | |||
445 | /* | ||
446 | * Check 80-wire cable presence and setup Clk66. | ||
447 | */ | ||
448 | |||
449 | switch (via_config->flags & VIA_UDMA) { | ||
450 | |||
451 | case VIA_UDMA_66: | ||
452 | /* Enable Clk66 */ | ||
453 | pci_read_config_dword(dev, VIA_UDMA_TIMING, &u); | ||
454 | pci_write_config_dword(dev, VIA_UDMA_TIMING, u|0x80008); | ||
455 | for (i = 24; i >= 0; i -= 8) | ||
456 | if (((u >> (i & 16)) & 8) && | ||
457 | ((u >> i) & 0x20) && | ||
458 | (((u >> i) & 7) < 2)) { | ||
459 | /* | ||
460 | * 2x PCI clock and | ||
461 | * UDMA w/ < 3T/cycle | ||
462 | */ | ||
463 | via_80w |= (1 << (1 - (i >> 4))); | ||
464 | } | ||
465 | break; | ||
466 | |||
467 | case VIA_UDMA_100: | ||
468 | pci_read_config_dword(dev, VIA_UDMA_TIMING, &u); | ||
469 | for (i = 24; i >= 0; i -= 8) | ||
470 | if (((u >> i) & 0x10) || | ||
471 | (((u >> i) & 0x20) && | ||
472 | (((u >> i) & 7) < 4))) { | ||
473 | /* BIOS 80-wire bit or | ||
474 | * UDMA w/ < 60ns/cycle | ||
475 | */ | ||
476 | via_80w |= (1 << (1 - (i >> 4))); | ||
477 | } | ||
478 | break; | ||
479 | |||
480 | case VIA_UDMA_133: | ||
481 | pci_read_config_dword(dev, VIA_UDMA_TIMING, &u); | ||
482 | for (i = 24; i >= 0; i -= 8) | ||
483 | if (((u >> i) & 0x10) || | ||
484 | (((u >> i) & 0x20) && | ||
485 | (((u >> i) & 7) < 6))) { | ||
486 | /* BIOS 80-wire bit or | ||
487 | * UDMA w/ < 60ns/cycle | ||
488 | */ | ||
489 | via_80w |= (1 << (1 - (i >> 4))); | ||
490 | } | ||
491 | break; | ||
492 | |||
493 | } | ||
494 | |||
495 | /* Disable Clk66 */ | ||
496 | if (via_config->flags & VIA_BAD_CLK66) { | ||
497 | /* Would cause trouble on 596a and 686 */ | ||
498 | pci_read_config_dword(dev, VIA_UDMA_TIMING, &u); | ||
499 | pci_write_config_dword(dev, VIA_UDMA_TIMING, u & ~0x80008); | ||
500 | } | ||
501 | |||
502 | /* | ||
503 | * Check whether interfaces are enabled. | ||
504 | */ | ||
505 | |||
506 | pci_read_config_byte(dev, VIA_IDE_ENABLE, &v); | ||
507 | |||
508 | /* | ||
509 | * Set up FIFO sizes and thresholds. | ||
510 | */ | ||
511 | |||
512 | pci_read_config_byte(dev, VIA_FIFO_CONFIG, &t); | ||
513 | |||
514 | /* Disable PREQ# till DDACK# */ | ||
515 | if (via_config->flags & VIA_BAD_PREQ) { | ||
516 | /* Would crash on 586b rev 41 */ | ||
517 | t &= 0x7f; | ||
518 | } | ||
519 | |||
520 | /* Fix FIFO split between channels */ | ||
521 | if (via_config->flags & VIA_SET_FIFO) { | ||
522 | t &= (t & 0x9f); | ||
523 | switch (v & 3) { | ||
524 | case 2: t |= 0x00; break; /* 16 on primary */ | ||
525 | case 1: t |= 0x60; break; /* 16 on secondary */ | ||
526 | case 3: t |= 0x20; break; /* 8 pri 8 sec */ | ||
527 | } | ||
528 | } | ||
529 | |||
530 | pci_write_config_byte(dev, VIA_FIFO_CONFIG, t); | ||
531 | |||
532 | /* | ||
533 | * Determine system bus clock. | ||
534 | */ | ||
535 | |||
536 | via_clock = system_bus_clock() * 1000; | ||
537 | |||
538 | switch (via_clock) { | ||
539 | case 33000: via_clock = 33333; break; | ||
540 | case 37000: via_clock = 37500; break; | ||
541 | case 41000: via_clock = 41666; break; | ||
542 | } | ||
543 | |||
544 | if (via_clock < 20000 || via_clock > 50000) { | ||
545 | printk(KERN_WARNING "VP_IDE: User given PCI clock speed " | ||
546 | "impossible (%d), using 33 MHz instead.\n", via_clock); | ||
547 | printk(KERN_WARNING "VP_IDE: Use ide0=ata66 if you want " | ||
548 | "to assume 80-wire cable.\n"); | ||
549 | via_clock = 33333; | ||
550 | } | ||
551 | |||
552 | /* | ||
553 | * Print the boot message. | ||
554 | */ | ||
555 | |||
556 | pci_read_config_byte(isa, PCI_REVISION_ID, &t); | ||
557 | printk(KERN_INFO "VP_IDE: VIA %s (rev %02x) IDE %s " | ||
558 | "controller on pci%s\n", | ||
559 | via_config->name, t, | ||
560 | via_dma[via_config->flags & VIA_UDMA], | ||
561 | pci_name(dev)); | ||
562 | |||
563 | /* | ||
564 | * Setup /proc/ide/via entry. | ||
565 | */ | ||
566 | |||
567 | #if defined(DISPLAY_VIA_TIMINGS) && defined(CONFIG_PROC_FS) | ||
568 | if (!via_proc) { | ||
569 | via_base = pci_resource_start(dev, 4); | ||
570 | bmide_dev = dev; | ||
571 | isa_dev = isa; | ||
572 | ide_pci_create_host_proc("via", via_get_info); | ||
573 | via_proc = 1; | ||
574 | } | ||
575 | #endif /* DISPLAY_VIA_TIMINGS && CONFIG_PROC_FS */ | ||
576 | return 0; | ||
577 | } | ||
578 | |||
579 | static void __init init_hwif_via82cxxx(ide_hwif_t *hwif) | ||
580 | { | ||
581 | int i; | ||
582 | |||
583 | hwif->autodma = 0; | ||
584 | |||
585 | hwif->tuneproc = &via82cxxx_tune_drive; | ||
586 | hwif->speedproc = &via_set_drive; | ||
587 | |||
588 | |||
589 | #if defined(CONFIG_PPC_MULTIPLATFORM) && defined(CONFIG_PPC32) | ||
590 | if(_machine == _MACH_chrp && _chrp_type == _CHRP_Pegasos) { | ||
591 | hwif->irq = hwif->channel ? 15 : 14; | ||
592 | } | ||
593 | #endif | ||
594 | |||
595 | for (i = 0; i < 2; i++) { | ||
596 | hwif->drives[i].io_32bit = 1; | ||
597 | hwif->drives[i].unmask = (via_config->flags & VIA_NO_UNMASK) ? 0 : 1; | ||
598 | hwif->drives[i].autotune = 1; | ||
599 | hwif->drives[i].dn = hwif->channel * 2 + i; | ||
600 | } | ||
601 | |||
602 | if (!hwif->dma_base) | ||
603 | return; | ||
604 | |||
605 | hwif->atapi_dma = 1; | ||
606 | hwif->ultra_mask = 0x7f; | ||
607 | hwif->mwdma_mask = 0x07; | ||
608 | hwif->swdma_mask = 0x07; | ||
609 | |||
610 | if (!hwif->udma_four) | ||
611 | hwif->udma_four = (via_80w >> hwif->channel) & 1; | ||
612 | hwif->ide_dma_check = &via82cxxx_ide_dma_check; | ||
613 | if (!noautodma) | ||
614 | hwif->autodma = 1; | ||
615 | hwif->drives[0].autodma = hwif->autodma; | ||
616 | hwif->drives[1].autodma = hwif->autodma; | ||
617 | } | ||
618 | |||
619 | static ide_pci_device_t via82cxxx_chipset __devinitdata = { | ||
620 | .name = "VP_IDE", | ||
621 | .init_chipset = init_chipset_via82cxxx, | ||
622 | .init_hwif = init_hwif_via82cxxx, | ||
623 | .channels = 2, | ||
624 | .autodma = NOAUTODMA, | ||
625 | .enablebits = {{0x40,0x02,0x02}, {0x40,0x01,0x01}}, | ||
626 | .bootable = ON_BOARD, | ||
627 | }; | ||
628 | |||
629 | static int __devinit via_init_one(struct pci_dev *dev, const struct pci_device_id *id) | ||
630 | { | ||
631 | return ide_setup_pci_device(dev, &via82cxxx_chipset); | ||
632 | } | ||
633 | |||
634 | static struct pci_device_id via_pci_tbl[] = { | ||
635 | { PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C576_1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, | ||
636 | { PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C586_1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, | ||
637 | { 0, }, | ||
638 | }; | ||
639 | MODULE_DEVICE_TABLE(pci, via_pci_tbl); | ||
640 | |||
641 | static struct pci_driver driver = { | ||
642 | .name = "VIA_IDE", | ||
643 | .id_table = via_pci_tbl, | ||
644 | .probe = via_init_one, | ||
645 | }; | ||
646 | |||
647 | static int via_ide_init(void) | ||
648 | { | ||
649 | return ide_pci_register_driver(&driver); | ||
650 | } | ||
651 | |||
652 | module_init(via_ide_init); | ||
653 | |||
654 | MODULE_AUTHOR("Vojtech Pavlik, Michel Aubry, Jeff Garzik, Andre Hedrick"); | ||
655 | MODULE_DESCRIPTION("PCI driver module for VIA IDE"); | ||
656 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/ide/ppc/mpc8xx.c b/drivers/ide/ppc/mpc8xx.c new file mode 100644 index 000000000000..b80c6135ae93 --- /dev/null +++ b/drivers/ide/ppc/mpc8xx.c | |||
@@ -0,0 +1,855 @@ | |||
1 | /* | ||
2 | * linux/drivers/ide/ppc/ide-m8xx.c | ||
3 | * | ||
4 | * Copyright (C) 2000, 2001 Wolfgang Denk, wd@denx.de | ||
5 | * Modified for direct IDE interface | ||
6 | * by Thomas Lange, thomas@corelatus.com | ||
7 | * Modified for direct IDE interface on 8xx without using the PCMCIA | ||
8 | * controller | ||
9 | * by Steven.Scholz@imc-berlin.de | ||
10 | * Moved out of arch/ppc/kernel/m8xx_setup.c, other minor cleanups | ||
11 | * by Mathew Locke <mattl@mvista.com> | ||
12 | */ | ||
13 | |||
14 | #include <linux/config.h> | ||
15 | #include <linux/errno.h> | ||
16 | #include <linux/sched.h> | ||
17 | #include <linux/kernel.h> | ||
18 | #include <linux/mm.h> | ||
19 | #include <linux/stddef.h> | ||
20 | #include <linux/unistd.h> | ||
21 | #include <linux/ptrace.h> | ||
22 | #include <linux/slab.h> | ||
23 | #include <linux/user.h> | ||
24 | #include <linux/a.out.h> | ||
25 | #include <linux/tty.h> | ||
26 | #include <linux/major.h> | ||
27 | #include <linux/interrupt.h> | ||
28 | #include <linux/reboot.h> | ||
29 | #include <linux/init.h> | ||
30 | #include <linux/ioport.h> | ||
31 | #include <linux/ide.h> | ||
32 | #include <linux/bootmem.h> | ||
33 | |||
34 | #include <asm/mpc8xx.h> | ||
35 | #include <asm/mmu.h> | ||
36 | #include <asm/processor.h> | ||
37 | #include <asm/residual.h> | ||
38 | #include <asm/io.h> | ||
39 | #include <asm/pgtable.h> | ||
40 | #include <asm/ide.h> | ||
41 | #include <asm/8xx_immap.h> | ||
42 | #include <asm/machdep.h> | ||
43 | #include <asm/irq.h> | ||
44 | |||
45 | static int identify (volatile u8 *p); | ||
46 | static void print_fixed (volatile u8 *p); | ||
47 | static void print_funcid (int func); | ||
48 | static int check_ide_device (unsigned long base); | ||
49 | |||
50 | static void ide_interrupt_ack (void *dev); | ||
51 | static void m8xx_ide_tuneproc(ide_drive_t *drive, u8 pio); | ||
52 | |||
53 | typedef struct ide_ioport_desc { | ||
54 | unsigned long base_off; /* Offset to PCMCIA memory */ | ||
55 | unsigned long reg_off[IDE_NR_PORTS]; /* controller register offsets */ | ||
56 | int irq; /* IRQ */ | ||
57 | } ide_ioport_desc_t; | ||
58 | |||
59 | ide_ioport_desc_t ioport_dsc[MAX_HWIFS] = { | ||
60 | #ifdef IDE0_BASE_OFFSET | ||
61 | { IDE0_BASE_OFFSET, | ||
62 | { | ||
63 | IDE0_DATA_REG_OFFSET, | ||
64 | IDE0_ERROR_REG_OFFSET, | ||
65 | IDE0_NSECTOR_REG_OFFSET, | ||
66 | IDE0_SECTOR_REG_OFFSET, | ||
67 | IDE0_LCYL_REG_OFFSET, | ||
68 | IDE0_HCYL_REG_OFFSET, | ||
69 | IDE0_SELECT_REG_OFFSET, | ||
70 | IDE0_STATUS_REG_OFFSET, | ||
71 | IDE0_CONTROL_REG_OFFSET, | ||
72 | IDE0_IRQ_REG_OFFSET, | ||
73 | }, | ||
74 | IDE0_INTERRUPT, | ||
75 | }, | ||
76 | #ifdef IDE1_BASE_OFFSET | ||
77 | { IDE1_BASE_OFFSET, | ||
78 | { | ||
79 | IDE1_DATA_REG_OFFSET, | ||
80 | IDE1_ERROR_REG_OFFSET, | ||
81 | IDE1_NSECTOR_REG_OFFSET, | ||
82 | IDE1_SECTOR_REG_OFFSET, | ||
83 | IDE1_LCYL_REG_OFFSET, | ||
84 | IDE1_HCYL_REG_OFFSET, | ||
85 | IDE1_SELECT_REG_OFFSET, | ||
86 | IDE1_STATUS_REG_OFFSET, | ||
87 | IDE1_CONTROL_REG_OFFSET, | ||
88 | IDE1_IRQ_REG_OFFSET, | ||
89 | }, | ||
90 | IDE1_INTERRUPT, | ||
91 | }, | ||
92 | #endif /* IDE1_BASE_OFFSET */ | ||
93 | #endif /* IDE0_BASE_OFFSET */ | ||
94 | }; | ||
95 | |||
96 | ide_pio_timings_t ide_pio_clocks[6]; | ||
97 | int hold_time[6] = {30, 20, 15, 10, 10, 10 }; /* PIO Mode 5 with IORDY (nonstandard) */ | ||
98 | |||
99 | /* | ||
100 | * Warning: only 1 (ONE) PCMCIA slot supported here, | ||
101 | * which must be correctly initialized by the firmware (PPCBoot). | ||
102 | */ | ||
103 | static int _slot_ = -1; /* will be read from PCMCIA registers */ | ||
104 | |||
105 | /* Make clock cycles and always round up */ | ||
106 | #define PCMCIA_MK_CLKS( t, T ) (( (t) * ((T)/1000000) + 999U ) / 1000U ) | ||
107 | |||
108 | |||
109 | |||
110 | /* | ||
111 | * IDE stuff. | ||
112 | */ | ||
113 | static int | ||
114 | m8xx_ide_default_irq(unsigned long base) | ||
115 | { | ||
116 | #ifdef CONFIG_BLK_DEV_MPC8xx_IDE | ||
117 | if (base >= MAX_HWIFS) | ||
118 | return 0; | ||
119 | |||
120 | printk("[%d] m8xx_ide_default_irq %d\n",__LINE__,ioport_dsc[base].irq); | ||
121 | |||
122 | return (ioport_dsc[base].irq); | ||
123 | #else | ||
124 | return 9; | ||
125 | #endif | ||
126 | } | ||
127 | |||
128 | static unsigned long | ||
129 | m8xx_ide_default_io_base(int index) | ||
130 | { | ||
131 | return index; | ||
132 | } | ||
133 | |||
134 | #define M8XX_PCMCIA_CD2(slot) (0x10000000 >> (slot << 4)) | ||
135 | #define M8XX_PCMCIA_CD1(slot) (0x08000000 >> (slot << 4)) | ||
136 | |||
137 | /* | ||
138 | * The TQM850L hardware has two pins swapped! Grrrrgh! | ||
139 | */ | ||
140 | #ifdef CONFIG_TQM850L | ||
141 | #define __MY_PCMCIA_GCRX_CXRESET PCMCIA_GCRX_CXOE | ||
142 | #define __MY_PCMCIA_GCRX_CXOE PCMCIA_GCRX_CXRESET | ||
143 | #else | ||
144 | #define __MY_PCMCIA_GCRX_CXRESET PCMCIA_GCRX_CXRESET | ||
145 | #define __MY_PCMCIA_GCRX_CXOE PCMCIA_GCRX_CXOE | ||
146 | #endif | ||
147 | |||
148 | #if defined(CONFIG_BLK_DEV_MPC8xx_IDE) && defined(CONFIG_IDE_8xx_PCCARD) | ||
149 | #define PCMCIA_SCHLVL IDE0_INTERRUPT /* Status Change Interrupt Level */ | ||
150 | static int pcmcia_schlvl = PCMCIA_SCHLVL; | ||
151 | #endif | ||
152 | |||
153 | /* | ||
154 | * See include/linux/ide.h for definition of hw_regs_t (p, base) | ||
155 | */ | ||
156 | |||
157 | /* | ||
158 | * m8xx_ide_init_hwif_ports for a direct IDE interface _using_ | ||
159 | */ | ||
160 | #if defined(CONFIG_IDE_8xx_PCCARD) || defined(CONFIG_IDE_8xx_DIRECT) | ||
161 | static void | ||
162 | m8xx_ide_init_hwif_ports(hw_regs_t *hw, unsigned long data_port, | ||
163 | unsigned long ctrl_port, int *irq) | ||
164 | { | ||
165 | unsigned long *p = hw->io_ports; | ||
166 | int i; | ||
167 | |||
168 | typedef struct { | ||
169 | ulong br; | ||
170 | ulong or; | ||
171 | } pcmcia_win_t; | ||
172 | volatile pcmcia_win_t *win; | ||
173 | volatile pcmconf8xx_t *pcmp; | ||
174 | |||
175 | uint *pgcrx; | ||
176 | u32 pcmcia_phy_base; | ||
177 | u32 pcmcia_phy_end; | ||
178 | static unsigned long pcmcia_base = 0; | ||
179 | unsigned long base; | ||
180 | |||
181 | *p = 0; | ||
182 | if (irq) | ||
183 | *irq = 0; | ||
184 | |||
185 | pcmp = (pcmconf8xx_t *)(&(((immap_t *)IMAP_ADDR)->im_pcmcia)); | ||
186 | |||
187 | if (!pcmcia_base) { | ||
188 | /* | ||
189 | * Read out PCMCIA registers. Since the reset values | ||
190 | * are undefined, we sure hope that they have been | ||
191 | * set up by firmware | ||
192 | */ | ||
193 | |||
194 | /* Scan all registers for valid settings */ | ||
195 | pcmcia_phy_base = 0xFFFFFFFF; | ||
196 | pcmcia_phy_end = 0; | ||
197 | /* br0 is start of brX and orX regs */ | ||
198 | win = (pcmcia_win_t *) \ | ||
199 | (&(((immap_t *)IMAP_ADDR)->im_pcmcia.pcmc_pbr0)); | ||
200 | for (i = 0; i < 8; i++) { | ||
201 | if (win->or & 1) { /* This bank is marked as valid */ | ||
202 | if (win->br < pcmcia_phy_base) { | ||
203 | pcmcia_phy_base = win->br; | ||
204 | } | ||
205 | if ((win->br + PCMCIA_MEM_SIZE) > pcmcia_phy_end) { | ||
206 | pcmcia_phy_end = win->br + PCMCIA_MEM_SIZE; | ||
207 | } | ||
208 | /* Check which slot that has been defined */ | ||
209 | _slot_ = (win->or >> 2) & 1; | ||
210 | |||
211 | } /* Valid bank */ | ||
212 | win++; | ||
213 | } /* for */ | ||
214 | |||
215 | printk ("PCMCIA slot %c: phys mem %08x...%08x (size %08x)\n", | ||
216 | 'A' + _slot_, | ||
217 | pcmcia_phy_base, pcmcia_phy_end, | ||
218 | pcmcia_phy_end - pcmcia_phy_base); | ||
219 | |||
220 | pcmcia_base=(unsigned long)ioremap(pcmcia_phy_base, | ||
221 | pcmcia_phy_end-pcmcia_phy_base); | ||
222 | |||
223 | #ifdef DEBUG | ||
224 | printk ("PCMCIA virt base: %08lx\n", pcmcia_base); | ||
225 | #endif | ||
226 | /* Compute clock cycles for PIO timings */ | ||
227 | for (i=0; i<6; ++i) { | ||
228 | bd_t *binfo = (bd_t *)__res; | ||
229 | |||
230 | hold_time[i] = | ||
231 | PCMCIA_MK_CLKS (hold_time[i], | ||
232 | binfo->bi_busfreq); | ||
233 | ide_pio_clocks[i].setup_time = | ||
234 | PCMCIA_MK_CLKS (ide_pio_timings[i].setup_time, | ||
235 | binfo->bi_busfreq); | ||
236 | ide_pio_clocks[i].active_time = | ||
237 | PCMCIA_MK_CLKS (ide_pio_timings[i].active_time, | ||
238 | binfo->bi_busfreq); | ||
239 | ide_pio_clocks[i].cycle_time = | ||
240 | PCMCIA_MK_CLKS (ide_pio_timings[i].cycle_time, | ||
241 | binfo->bi_busfreq); | ||
242 | #if 0 | ||
243 | printk ("PIO mode %d timings: %d/%d/%d => %d/%d/%d\n", | ||
244 | i, | ||
245 | ide_pio_clocks[i].setup_time, | ||
246 | ide_pio_clocks[i].active_time, | ||
247 | ide_pio_clocks[i].hold_time, | ||
248 | ide_pio_clocks[i].cycle_time, | ||
249 | ide_pio_timings[i].setup_time, | ||
250 | ide_pio_timings[i].active_time, | ||
251 | ide_pio_timings[i].hold_time, | ||
252 | ide_pio_timings[i].cycle_time); | ||
253 | #endif | ||
254 | } | ||
255 | } | ||
256 | |||
257 | if (data_port >= MAX_HWIFS) | ||
258 | return; | ||
259 | |||
260 | if (_slot_ == -1) { | ||
261 | printk ("PCMCIA slot has not been defined! Using A as default\n"); | ||
262 | _slot_ = 0; | ||
263 | } | ||
264 | |||
265 | #ifdef CONFIG_IDE_8xx_PCCARD | ||
266 | |||
267 | #ifdef DEBUG | ||
268 | printk ("PIPR = 0x%08X slot %c ==> mask = 0x%X\n", | ||
269 | pcmp->pcmc_pipr, | ||
270 | 'A' + _slot_, | ||
271 | M8XX_PCMCIA_CD1(_slot_) | M8XX_PCMCIA_CD2(_slot_) ); | ||
272 | #endif /* DEBUG */ | ||
273 | |||
274 | if (pcmp->pcmc_pipr & (M8XX_PCMCIA_CD1(_slot_)|M8XX_PCMCIA_CD2(_slot_))) { | ||
275 | printk ("No card in slot %c: PIPR=%08x\n", | ||
276 | 'A' + _slot_, (u32) pcmp->pcmc_pipr); | ||
277 | return; /* No card in slot */ | ||
278 | } | ||
279 | |||
280 | check_ide_device (pcmcia_base); | ||
281 | |||
282 | #endif /* CONFIG_IDE_8xx_PCCARD */ | ||
283 | |||
284 | base = pcmcia_base + ioport_dsc[data_port].base_off; | ||
285 | #ifdef DEBUG | ||
286 | printk ("base: %08x + %08x = %08x\n", | ||
287 | pcmcia_base, ioport_dsc[data_port].base_off, base); | ||
288 | #endif | ||
289 | |||
290 | for (i = 0; i < IDE_NR_PORTS; ++i) { | ||
291 | #ifdef DEBUG | ||
292 | printk ("port[%d]: %08x + %08x = %08x\n", | ||
293 | i, | ||
294 | base, | ||
295 | ioport_dsc[data_port].reg_off[i], | ||
296 | i, base + ioport_dsc[data_port].reg_off[i]); | ||
297 | #endif | ||
298 | *p++ = base + ioport_dsc[data_port].reg_off[i]; | ||
299 | } | ||
300 | |||
301 | if (irq) { | ||
302 | #ifdef CONFIG_IDE_8xx_PCCARD | ||
303 | unsigned int reg; | ||
304 | |||
305 | *irq = ioport_dsc[data_port].irq; | ||
306 | if (_slot_) | ||
307 | pgcrx = &((immap_t *) IMAP_ADDR)->im_pcmcia.pcmc_pgcrb; | ||
308 | else | ||
309 | pgcrx = &((immap_t *) IMAP_ADDR)->im_pcmcia.pcmc_pgcra; | ||
310 | |||
311 | reg = *pgcrx; | ||
312 | reg |= mk_int_int_mask (pcmcia_schlvl) << 24; | ||
313 | reg |= mk_int_int_mask (pcmcia_schlvl) << 16; | ||
314 | *pgcrx = reg; | ||
315 | #else /* direct connected IDE drive, i.e. external IRQ, not the PCMCIA irq */ | ||
316 | *irq = ioport_dsc[data_port].irq; | ||
317 | #endif /* CONFIG_IDE_8xx_PCCARD */ | ||
318 | } | ||
319 | |||
320 | /* register routine to tune PIO mode */ | ||
321 | ide_hwifs[data_port].tuneproc = m8xx_ide_tuneproc; | ||
322 | |||
323 | hw->ack_intr = (ide_ack_intr_t *) ide_interrupt_ack; | ||
324 | /* Enable Harddisk Interrupt, | ||
325 | * and make it edge sensitive | ||
326 | */ | ||
327 | /* (11-18) Set edge detect for irq, no wakeup from low power mode */ | ||
328 | ((immap_t *)IMAP_ADDR)->im_siu_conf.sc_siel |= | ||
329 | (0x80000000 >> ioport_dsc[data_port].irq); | ||
330 | |||
331 | #ifdef CONFIG_IDE_8xx_PCCARD | ||
332 | /* Make sure we don't get garbage irq */ | ||
333 | ((immap_t *) IMAP_ADDR)->im_pcmcia.pcmc_pscr = 0xFFFF; | ||
334 | |||
335 | /* Enable falling edge irq */ | ||
336 | pcmp->pcmc_per = 0x100000 >> (16 * _slot_); | ||
337 | #endif /* CONFIG_IDE_8xx_PCCARD */ | ||
338 | } /* m8xx_ide_init_hwif_ports() using 8xx internal PCMCIA interface */ | ||
339 | #endif /* CONFIG_IDE_8xx_PCCARD || CONFIG_IDE_8xx_DIRECT */ | ||
340 | |||
341 | /* | ||
342 | * m8xx_ide_init_hwif_ports for a direct IDE interface _not_ using | ||
343 | * MPC8xx's internal PCMCIA interface | ||
344 | */ | ||
345 | #if defined(CONFIG_IDE_EXT_DIRECT) | ||
346 | void m8xx_ide_init_hwif_ports (hw_regs_t *hw, | ||
347 | unsigned long data_port, unsigned long ctrl_port, int *irq) | ||
348 | { | ||
349 | unsigned long *p = hw->io_ports; | ||
350 | int i; | ||
351 | |||
352 | u32 ide_phy_base; | ||
353 | u32 ide_phy_end; | ||
354 | static unsigned long ide_base = 0; | ||
355 | unsigned long base; | ||
356 | |||
357 | *p = 0; | ||
358 | if (irq) | ||
359 | *irq = 0; | ||
360 | |||
361 | if (!ide_base) { | ||
362 | |||
363 | /* TODO: | ||
364 | * - add code to read ORx, BRx | ||
365 | */ | ||
366 | ide_phy_base = CFG_ATA_BASE_ADDR; | ||
367 | ide_phy_end = CFG_ATA_BASE_ADDR + 0x200; | ||
368 | |||
369 | printk ("IDE phys mem : %08x...%08x (size %08x)\n", | ||
370 | ide_phy_base, ide_phy_end, | ||
371 | ide_phy_end - ide_phy_base); | ||
372 | |||
373 | ide_base=(unsigned long)ioremap(ide_phy_base, | ||
374 | ide_phy_end-ide_phy_base); | ||
375 | |||
376 | #ifdef DEBUG | ||
377 | printk ("IDE virt base: %08lx\n", ide_base); | ||
378 | #endif | ||
379 | } | ||
380 | |||
381 | if (data_port >= MAX_HWIFS) | ||
382 | return; | ||
383 | |||
384 | base = ide_base + ioport_dsc[data_port].base_off; | ||
385 | #ifdef DEBUG | ||
386 | printk ("base: %08x + %08x = %08x\n", | ||
387 | ide_base, ioport_dsc[data_port].base_off, base); | ||
388 | #endif | ||
389 | |||
390 | for (i = 0; i < IDE_NR_PORTS; ++i) { | ||
391 | #ifdef DEBUG | ||
392 | printk ("port[%d]: %08x + %08x = %08x\n", | ||
393 | i, | ||
394 | base, | ||
395 | ioport_dsc[data_port].reg_off[i], | ||
396 | i, base + ioport_dsc[data_port].reg_off[i]); | ||
397 | #endif | ||
398 | *p++ = base + ioport_dsc[data_port].reg_off[i]; | ||
399 | } | ||
400 | |||
401 | if (irq) { | ||
402 | /* direct connected IDE drive, i.e. external IRQ */ | ||
403 | *irq = ioport_dsc[data_port].irq; | ||
404 | } | ||
405 | |||
406 | /* register routine to tune PIO mode */ | ||
407 | ide_hwifs[data_port].tuneproc = m8xx_ide_tuneproc; | ||
408 | |||
409 | hw->ack_intr = (ide_ack_intr_t *) ide_interrupt_ack; | ||
410 | /* Enable Harddisk Interrupt, | ||
411 | * and make it edge sensitive | ||
412 | */ | ||
413 | /* (11-18) Set edge detect for irq, no wakeup from low power mode */ | ||
414 | ((immap_t *) IMAP_ADDR)->im_siu_conf.sc_siel |= | ||
415 | (0x80000000 >> ioport_dsc[data_port].irq); | ||
416 | } /* m8xx_ide_init_hwif_ports() for CONFIG_IDE_8xx_DIRECT */ | ||
417 | |||
418 | #endif /* CONFIG_IDE_8xx_DIRECT */ | ||
419 | |||
420 | |||
421 | /* -------------------------------------------------------------------- */ | ||
422 | |||
423 | |||
424 | /* PCMCIA Timing */ | ||
425 | #ifndef PCMCIA_SHT | ||
426 | #define PCMCIA_SHT(t) ((t & 0x0F)<<16) /* Strobe Hold Time */ | ||
427 | #define PCMCIA_SST(t) ((t & 0x0F)<<12) /* Strobe Setup Time */ | ||
428 | #define PCMCIA_SL(t) ((t==32) ? 0 : ((t & 0x1F)<<7)) /* Strobe Length */ | ||
429 | #endif | ||
430 | |||
431 | |||
432 | /* Calculate PIO timings */ | ||
433 | static void | ||
434 | m8xx_ide_tuneproc(ide_drive_t *drive, u8 pio) | ||
435 | { | ||
436 | ide_pio_data_t d; | ||
437 | #if defined(CONFIG_IDE_8xx_PCCARD) || defined(CONFIG_IDE_8xx_DIRECT) | ||
438 | volatile pcmconf8xx_t *pcmp; | ||
439 | ulong timing, mask, reg; | ||
440 | #endif | ||
441 | |||
442 | pio = ide_get_best_pio_mode(drive, pio, 4, &d); | ||
443 | |||
444 | #if 1 | ||
445 | printk("%s[%d] %s: best PIO mode: %d\n", | ||
446 | __FILE__,__LINE__,__FUNCTION__, pio); | ||
447 | #endif | ||
448 | |||
449 | #if defined(CONFIG_IDE_8xx_PCCARD) || defined(CONFIG_IDE_8xx_DIRECT) | ||
450 | pcmp = (pcmconf8xx_t *)(&(((immap_t *)IMAP_ADDR)->im_pcmcia)); | ||
451 | |||
452 | mask = ~(PCMCIA_SHT(0xFF) | PCMCIA_SST(0xFF) | PCMCIA_SL(0xFF)); | ||
453 | |||
454 | timing = PCMCIA_SHT(hold_time[pio] ) | ||
455 | | PCMCIA_SST(ide_pio_clocks[pio].setup_time ) | ||
456 | | PCMCIA_SL (ide_pio_clocks[pio].active_time) | ||
457 | ; | ||
458 | |||
459 | #if 1 | ||
460 | printk ("Setting timing bits 0x%08lx in PCMCIA controller\n", timing); | ||
461 | #endif | ||
462 | if ((reg = pcmp->pcmc_por0 & mask) != 0) | ||
463 | pcmp->pcmc_por0 = reg | timing; | ||
464 | |||
465 | if ((reg = pcmp->pcmc_por1 & mask) != 0) | ||
466 | pcmp->pcmc_por1 = reg | timing; | ||
467 | |||
468 | if ((reg = pcmp->pcmc_por2 & mask) != 0) | ||
469 | pcmp->pcmc_por2 = reg | timing; | ||
470 | |||
471 | if ((reg = pcmp->pcmc_por3 & mask) != 0) | ||
472 | pcmp->pcmc_por3 = reg | timing; | ||
473 | |||
474 | if ((reg = pcmp->pcmc_por4 & mask) != 0) | ||
475 | pcmp->pcmc_por4 = reg | timing; | ||
476 | |||
477 | if ((reg = pcmp->pcmc_por5 & mask) != 0) | ||
478 | pcmp->pcmc_por5 = reg | timing; | ||
479 | |||
480 | if ((reg = pcmp->pcmc_por6 & mask) != 0) | ||
481 | pcmp->pcmc_por6 = reg | timing; | ||
482 | |||
483 | if ((reg = pcmp->pcmc_por7 & mask) != 0) | ||
484 | pcmp->pcmc_por7 = reg | timing; | ||
485 | |||
486 | #elif defined(CONFIG_IDE_EXT_DIRECT) | ||
487 | |||
488 | printk("%s[%d] %s: not implemented yet!\n", | ||
489 | __FILE__,__LINE__,__FUNCTION__); | ||
490 | #endif /* defined(CONFIG_IDE_8xx_PCCARD) || defined(CONFIG_IDE_8xx_PCMCIA */ | ||
491 | } | ||
492 | |||
493 | static void | ||
494 | ide_interrupt_ack (void *dev) | ||
495 | { | ||
496 | #ifdef CONFIG_IDE_8xx_PCCARD | ||
497 | u_int pscr, pipr; | ||
498 | |||
499 | #if (PCMCIA_SOCKETS_NO == 2) | ||
500 | u_int _slot_; | ||
501 | #endif | ||
502 | |||
503 | /* get interrupt sources */ | ||
504 | |||
505 | pscr = ((volatile immap_t *)IMAP_ADDR)->im_pcmcia.pcmc_pscr; | ||
506 | pipr = ((volatile immap_t *)IMAP_ADDR)->im_pcmcia.pcmc_pipr; | ||
507 | |||
508 | /* | ||
509 | * report only if both card detect signals are the same | ||
510 | * not too nice done, | ||
511 | * we depend on that CD2 is the bit to the left of CD1... | ||
512 | */ | ||
513 | |||
514 | if(_slot_==-1){ | ||
515 | printk("PCMCIA slot has not been defined! Using A as default\n"); | ||
516 | _slot_=0; | ||
517 | } | ||
518 | |||
519 | if(((pipr & M8XX_PCMCIA_CD2(_slot_)) >> 1) ^ | ||
520 | (pipr & M8XX_PCMCIA_CD1(_slot_)) ) { | ||
521 | printk ("card detect interrupt\n"); | ||
522 | } | ||
523 | /* clear the interrupt sources */ | ||
524 | ((immap_t *)IMAP_ADDR)->im_pcmcia.pcmc_pscr = pscr; | ||
525 | |||
526 | #else /* ! CONFIG_IDE_8xx_PCCARD */ | ||
527 | /* | ||
528 | * Only CONFIG_IDE_8xx_PCCARD is using the interrupt of the | ||
529 | * MPC8xx's PCMCIA controller, so there is nothing to be done here | ||
530 | * for CONFIG_IDE_8xx_DIRECT and CONFIG_IDE_EXT_DIRECT. | ||
531 | * The interrupt is handled somewhere else. -- Steven | ||
532 | */ | ||
533 | #endif /* CONFIG_IDE_8xx_PCCARD */ | ||
534 | } | ||
535 | |||
536 | |||
537 | |||
538 | /* | ||
539 | * CIS Tupel codes | ||
540 | */ | ||
541 | #define CISTPL_NULL 0x00 | ||
542 | #define CISTPL_DEVICE 0x01 | ||
543 | #define CISTPL_LONGLINK_CB 0x02 | ||
544 | #define CISTPL_INDIRECT 0x03 | ||
545 | #define CISTPL_CONFIG_CB 0x04 | ||
546 | #define CISTPL_CFTABLE_ENTRY_CB 0x05 | ||
547 | #define CISTPL_LONGLINK_MFC 0x06 | ||
548 | #define CISTPL_BAR 0x07 | ||
549 | #define CISTPL_PWR_MGMNT 0x08 | ||
550 | #define CISTPL_EXTDEVICE 0x09 | ||
551 | #define CISTPL_CHECKSUM 0x10 | ||
552 | #define CISTPL_LONGLINK_A 0x11 | ||
553 | #define CISTPL_LONGLINK_C 0x12 | ||
554 | #define CISTPL_LINKTARGET 0x13 | ||
555 | #define CISTPL_NO_LINK 0x14 | ||
556 | #define CISTPL_VERS_1 0x15 | ||
557 | #define CISTPL_ALTSTR 0x16 | ||
558 | #define CISTPL_DEVICE_A 0x17 | ||
559 | #define CISTPL_JEDEC_C 0x18 | ||
560 | #define CISTPL_JEDEC_A 0x19 | ||
561 | #define CISTPL_CONFIG 0x1a | ||
562 | #define CISTPL_CFTABLE_ENTRY 0x1b | ||
563 | #define CISTPL_DEVICE_OC 0x1c | ||
564 | #define CISTPL_DEVICE_OA 0x1d | ||
565 | #define CISTPL_DEVICE_GEO 0x1e | ||
566 | #define CISTPL_DEVICE_GEO_A 0x1f | ||
567 | #define CISTPL_MANFID 0x20 | ||
568 | #define CISTPL_FUNCID 0x21 | ||
569 | #define CISTPL_FUNCE 0x22 | ||
570 | #define CISTPL_SWIL 0x23 | ||
571 | #define CISTPL_END 0xff | ||
572 | |||
573 | /* | ||
574 | * CIS Function ID codes | ||
575 | */ | ||
576 | #define CISTPL_FUNCID_MULTI 0x00 | ||
577 | #define CISTPL_FUNCID_MEMORY 0x01 | ||
578 | #define CISTPL_FUNCID_SERIAL 0x02 | ||
579 | #define CISTPL_FUNCID_PARALLEL 0x03 | ||
580 | #define CISTPL_FUNCID_FIXED 0x04 | ||
581 | #define CISTPL_FUNCID_VIDEO 0x05 | ||
582 | #define CISTPL_FUNCID_NETWORK 0x06 | ||
583 | #define CISTPL_FUNCID_AIMS 0x07 | ||
584 | #define CISTPL_FUNCID_SCSI 0x08 | ||
585 | |||
586 | /* | ||
587 | * Fixed Disk FUNCE codes | ||
588 | */ | ||
589 | #define CISTPL_IDE_INTERFACE 0x01 | ||
590 | |||
591 | #define CISTPL_FUNCE_IDE_IFACE 0x01 | ||
592 | #define CISTPL_FUNCE_IDE_MASTER 0x02 | ||
593 | #define CISTPL_FUNCE_IDE_SLAVE 0x03 | ||
594 | |||
595 | /* First feature byte */ | ||
596 | #define CISTPL_IDE_SILICON 0x04 | ||
597 | #define CISTPL_IDE_UNIQUE 0x08 | ||
598 | #define CISTPL_IDE_DUAL 0x10 | ||
599 | |||
600 | /* Second feature byte */ | ||
601 | #define CISTPL_IDE_HAS_SLEEP 0x01 | ||
602 | #define CISTPL_IDE_HAS_STANDBY 0x02 | ||
603 | #define CISTPL_IDE_HAS_IDLE 0x04 | ||
604 | #define CISTPL_IDE_LOW_POWER 0x08 | ||
605 | #define CISTPL_IDE_REG_INHIBIT 0x10 | ||
606 | #define CISTPL_IDE_HAS_INDEX 0x20 | ||
607 | #define CISTPL_IDE_IOIS16 0x40 | ||
608 | |||
609 | |||
610 | /* -------------------------------------------------------------------- */ | ||
611 | |||
612 | |||
613 | #define MAX_TUPEL_SZ 512 | ||
614 | #define MAX_FEATURES 4 | ||
615 | |||
616 | static int check_ide_device (unsigned long base) | ||
617 | { | ||
618 | volatile u8 *ident = NULL; | ||
619 | volatile u8 *feature_p[MAX_FEATURES]; | ||
620 | volatile u8 *p, *start; | ||
621 | int n_features = 0; | ||
622 | u8 func_id = ~0; | ||
623 | u8 code, len; | ||
624 | unsigned short config_base = 0; | ||
625 | int found = 0; | ||
626 | int i; | ||
627 | |||
628 | #ifdef DEBUG | ||
629 | printk ("PCMCIA MEM: %08lX\n", base); | ||
630 | #endif | ||
631 | start = p = (volatile u8 *) base; | ||
632 | |||
633 | while ((p - start) < MAX_TUPEL_SZ) { | ||
634 | |||
635 | code = *p; p += 2; | ||
636 | |||
637 | if (code == 0xFF) { /* End of chain */ | ||
638 | break; | ||
639 | } | ||
640 | |||
641 | len = *p; p += 2; | ||
642 | #ifdef DEBUG_PCMCIA | ||
643 | { volatile u8 *q = p; | ||
644 | printk ("\nTuple code %02x length %d\n\tData:", | ||
645 | code, len); | ||
646 | |||
647 | for (i = 0; i < len; ++i) { | ||
648 | printk (" %02x", *q); | ||
649 | q+= 2; | ||
650 | } | ||
651 | } | ||
652 | #endif /* DEBUG_PCMCIA */ | ||
653 | switch (code) { | ||
654 | case CISTPL_VERS_1: | ||
655 | ident = p + 4; | ||
656 | break; | ||
657 | case CISTPL_FUNCID: | ||
658 | func_id = *p; | ||
659 | break; | ||
660 | case CISTPL_FUNCE: | ||
661 | if (n_features < MAX_FEATURES) | ||
662 | feature_p[n_features++] = p; | ||
663 | break; | ||
664 | case CISTPL_CONFIG: | ||
665 | config_base = (*(p+6) << 8) + (*(p+4)); | ||
666 | default: | ||
667 | break; | ||
668 | } | ||
669 | p += 2 * len; | ||
670 | } | ||
671 | |||
672 | found = identify (ident); | ||
673 | |||
674 | if (func_id != ((u8)~0)) { | ||
675 | print_funcid (func_id); | ||
676 | |||
677 | if (func_id == CISTPL_FUNCID_FIXED) | ||
678 | found = 1; | ||
679 | else | ||
680 | return (1); /* no disk drive */ | ||
681 | } | ||
682 | |||
683 | for (i=0; i<n_features; ++i) { | ||
684 | print_fixed (feature_p[i]); | ||
685 | } | ||
686 | |||
687 | if (!found) { | ||
688 | printk ("unknown card type\n"); | ||
689 | return (1); | ||
690 | } | ||
691 | |||
692 | /* set level mode irq and I/O mapped device in config reg*/ | ||
693 | *((u8 *)(base + config_base)) = 0x41; | ||
694 | |||
695 | return (0); | ||
696 | } | ||
697 | |||
698 | /* ------------------------------------------------------------------------- */ | ||
699 | |||
700 | static void print_funcid (int func) | ||
701 | { | ||
702 | switch (func) { | ||
703 | case CISTPL_FUNCID_MULTI: | ||
704 | printk (" Multi-Function"); | ||
705 | break; | ||
706 | case CISTPL_FUNCID_MEMORY: | ||
707 | printk (" Memory"); | ||
708 | break; | ||
709 | case CISTPL_FUNCID_SERIAL: | ||
710 | printk (" Serial Port"); | ||
711 | break; | ||
712 | case CISTPL_FUNCID_PARALLEL: | ||
713 | printk (" Parallel Port"); | ||
714 | break; | ||
715 | case CISTPL_FUNCID_FIXED: | ||
716 | printk (" Fixed Disk"); | ||
717 | break; | ||
718 | case CISTPL_FUNCID_VIDEO: | ||
719 | printk (" Video Adapter"); | ||
720 | break; | ||
721 | case CISTPL_FUNCID_NETWORK: | ||
722 | printk (" Network Adapter"); | ||
723 | break; | ||
724 | case CISTPL_FUNCID_AIMS: | ||
725 | printk (" AIMS Card"); | ||
726 | break; | ||
727 | case CISTPL_FUNCID_SCSI: | ||
728 | printk (" SCSI Adapter"); | ||
729 | break; | ||
730 | default: | ||
731 | printk (" Unknown"); | ||
732 | break; | ||
733 | } | ||
734 | printk (" Card\n"); | ||
735 | } | ||
736 | |||
737 | /* ------------------------------------------------------------------------- */ | ||
738 | |||
739 | static void print_fixed (volatile u8 *p) | ||
740 | { | ||
741 | if (p == NULL) | ||
742 | return; | ||
743 | |||
744 | switch (*p) { | ||
745 | case CISTPL_FUNCE_IDE_IFACE: | ||
746 | { u8 iface = *(p+2); | ||
747 | |||
748 | printk ((iface == CISTPL_IDE_INTERFACE) ? " IDE" : " unknown"); | ||
749 | printk (" interface "); | ||
750 | break; | ||
751 | } | ||
752 | case CISTPL_FUNCE_IDE_MASTER: | ||
753 | case CISTPL_FUNCE_IDE_SLAVE: | ||
754 | { u8 f1 = *(p+2); | ||
755 | u8 f2 = *(p+4); | ||
756 | |||
757 | printk ((f1 & CISTPL_IDE_SILICON) ? " [silicon]" : " [rotating]"); | ||
758 | |||
759 | if (f1 & CISTPL_IDE_UNIQUE) | ||
760 | printk (" [unique]"); | ||
761 | |||
762 | printk ((f1 & CISTPL_IDE_DUAL) ? " [dual]" : " [single]"); | ||
763 | |||
764 | if (f2 & CISTPL_IDE_HAS_SLEEP) | ||
765 | printk (" [sleep]"); | ||
766 | |||
767 | if (f2 & CISTPL_IDE_HAS_STANDBY) | ||
768 | printk (" [standby]"); | ||
769 | |||
770 | if (f2 & CISTPL_IDE_HAS_IDLE) | ||
771 | printk (" [idle]"); | ||
772 | |||
773 | if (f2 & CISTPL_IDE_LOW_POWER) | ||
774 | printk (" [low power]"); | ||
775 | |||
776 | if (f2 & CISTPL_IDE_REG_INHIBIT) | ||
777 | printk (" [reg inhibit]"); | ||
778 | |||
779 | if (f2 & CISTPL_IDE_HAS_INDEX) | ||
780 | printk (" [index]"); | ||
781 | |||
782 | if (f2 & CISTPL_IDE_IOIS16) | ||
783 | printk (" [IOis16]"); | ||
784 | |||
785 | break; | ||
786 | } | ||
787 | } | ||
788 | printk ("\n"); | ||
789 | } | ||
790 | |||
791 | /* ------------------------------------------------------------------------- */ | ||
792 | |||
793 | |||
794 | #define MAX_IDENT_CHARS 64 | ||
795 | #define MAX_IDENT_FIELDS 4 | ||
796 | |||
797 | static u8 *known_cards[] = { | ||
798 | "ARGOSY PnPIDE D5", | ||
799 | NULL | ||
800 | }; | ||
801 | |||
802 | static int identify (volatile u8 *p) | ||
803 | { | ||
804 | u8 id_str[MAX_IDENT_CHARS]; | ||
805 | u8 data; | ||
806 | u8 *t; | ||
807 | u8 **card; | ||
808 | int i, done; | ||
809 | |||
810 | if (p == NULL) | ||
811 | return (0); /* Don't know */ | ||
812 | |||
813 | t = id_str; | ||
814 | done =0; | ||
815 | |||
816 | for (i=0; i<=4 && !done; ++i, p+=2) { | ||
817 | while ((data = *p) != '\0') { | ||
818 | if (data == 0xFF) { | ||
819 | done = 1; | ||
820 | break; | ||
821 | } | ||
822 | *t++ = data; | ||
823 | if (t == &id_str[MAX_IDENT_CHARS-1]) { | ||
824 | done = 1; | ||
825 | break; | ||
826 | } | ||
827 | p += 2; | ||
828 | } | ||
829 | if (!done) | ||
830 | *t++ = ' '; | ||
831 | } | ||
832 | *t = '\0'; | ||
833 | while (--t > id_str) { | ||
834 | if (*t == ' ') | ||
835 | *t = '\0'; | ||
836 | else | ||
837 | break; | ||
838 | } | ||
839 | printk ("Card ID: %s\n", id_str); | ||
840 | |||
841 | for (card=known_cards; *card; ++card) { | ||
842 | if (strcmp(*card, id_str) == 0) { /* found! */ | ||
843 | return (1); | ||
844 | } | ||
845 | } | ||
846 | |||
847 | return (0); /* don't know */ | ||
848 | } | ||
849 | |||
850 | void m8xx_ide_init(void) | ||
851 | { | ||
852 | ppc_ide_md.default_irq = m8xx_ide_default_irq; | ||
853 | ppc_ide_md.default_io_base = m8xx_ide_default_io_base; | ||
854 | ppc_ide_md.ide_init_hwif = m8xx_ide_init_hwif_ports; | ||
855 | } | ||
diff --git a/drivers/ide/ppc/pmac.c b/drivers/ide/ppc/pmac.c new file mode 100644 index 000000000000..6dc273a81327 --- /dev/null +++ b/drivers/ide/ppc/pmac.c | |||
@@ -0,0 +1,2208 @@ | |||
1 | /* | ||
2 | * linux/drivers/ide/ide-pmac.c | ||
3 | * | ||
4 | * Support for IDE interfaces on PowerMacs. | ||
5 | * These IDE interfaces are memory-mapped and have a DBDMA channel | ||
6 | * for doing DMA. | ||
7 | * | ||
8 | * Copyright (C) 1998-2003 Paul Mackerras & Ben. Herrenschmidt | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or | ||
11 | * modify it under the terms of the GNU General Public License | ||
12 | * as published by the Free Software Foundation; either version | ||
13 | * 2 of the License, or (at your option) any later version. | ||
14 | * | ||
15 | * Some code taken from drivers/ide/ide-dma.c: | ||
16 | * | ||
17 | * Copyright (c) 1995-1998 Mark Lord | ||
18 | * | ||
19 | * TODO: - Use pre-calculated (kauai) timing tables all the time and | ||
20 | * get rid of the "rounded" tables used previously, so we have the | ||
21 | * same table format for all controllers and can then just have one | ||
22 | * big table | ||
23 | * | ||
24 | */ | ||
25 | #include <linux/config.h> | ||
26 | #include <linux/types.h> | ||
27 | #include <linux/kernel.h> | ||
28 | #include <linux/sched.h> | ||
29 | #include <linux/init.h> | ||
30 | #include <linux/delay.h> | ||
31 | #include <linux/ide.h> | ||
32 | #include <linux/notifier.h> | ||
33 | #include <linux/reboot.h> | ||
34 | #include <linux/pci.h> | ||
35 | #include <linux/adb.h> | ||
36 | #include <linux/pmu.h> | ||
37 | #include <linux/scatterlist.h> | ||
38 | |||
39 | #include <asm/prom.h> | ||
40 | #include <asm/io.h> | ||
41 | #include <asm/dbdma.h> | ||
42 | #include <asm/ide.h> | ||
43 | #include <asm/pci-bridge.h> | ||
44 | #include <asm/machdep.h> | ||
45 | #include <asm/pmac_feature.h> | ||
46 | #include <asm/sections.h> | ||
47 | #include <asm/irq.h> | ||
48 | |||
49 | #ifndef CONFIG_PPC64 | ||
50 | #include <asm/mediabay.h> | ||
51 | #endif | ||
52 | |||
53 | #include "ide-timing.h" | ||
54 | |||
55 | #undef IDE_PMAC_DEBUG | ||
56 | |||
57 | #define DMA_WAIT_TIMEOUT 50 | ||
58 | |||
59 | typedef struct pmac_ide_hwif { | ||
60 | unsigned long regbase; | ||
61 | int irq; | ||
62 | int kind; | ||
63 | int aapl_bus_id; | ||
64 | unsigned cable_80 : 1; | ||
65 | unsigned mediabay : 1; | ||
66 | unsigned broken_dma : 1; | ||
67 | unsigned broken_dma_warn : 1; | ||
68 | struct device_node* node; | ||
69 | struct macio_dev *mdev; | ||
70 | u32 timings[4]; | ||
71 | volatile u32 __iomem * *kauai_fcr; | ||
72 | #ifdef CONFIG_BLK_DEV_IDEDMA_PMAC | ||
73 | /* Those fields are duplicating what is in hwif. We currently | ||
74 | * can't use the hwif ones because of some assumptions that are | ||
75 | * beeing done by the generic code about the kind of dma controller | ||
76 | * and format of the dma table. This will have to be fixed though. | ||
77 | */ | ||
78 | volatile struct dbdma_regs __iomem * dma_regs; | ||
79 | struct dbdma_cmd* dma_table_cpu; | ||
80 | #endif | ||
81 | |||
82 | } pmac_ide_hwif_t; | ||
83 | |||
84 | static pmac_ide_hwif_t pmac_ide[MAX_HWIFS] __pmacdata; | ||
85 | static int pmac_ide_count; | ||
86 | |||
87 | enum { | ||
88 | controller_ohare, /* OHare based */ | ||
89 | controller_heathrow, /* Heathrow/Paddington */ | ||
90 | controller_kl_ata3, /* KeyLargo ATA-3 */ | ||
91 | controller_kl_ata4, /* KeyLargo ATA-4 */ | ||
92 | controller_un_ata6, /* UniNorth2 ATA-6 */ | ||
93 | controller_k2_ata6, /* K2 ATA-6 */ | ||
94 | controller_sh_ata6, /* Shasta ATA-6 */ | ||
95 | }; | ||
96 | |||
97 | static const char* model_name[] = { | ||
98 | "OHare ATA", /* OHare based */ | ||
99 | "Heathrow ATA", /* Heathrow/Paddington */ | ||
100 | "KeyLargo ATA-3", /* KeyLargo ATA-3 (MDMA only) */ | ||
101 | "KeyLargo ATA-4", /* KeyLargo ATA-4 (UDMA/66) */ | ||
102 | "UniNorth ATA-6", /* UniNorth2 ATA-6 (UDMA/100) */ | ||
103 | "K2 ATA-6", /* K2 ATA-6 (UDMA/100) */ | ||
104 | "Shasta ATA-6", /* Shasta ATA-6 (UDMA/133) */ | ||
105 | }; | ||
106 | |||
107 | /* | ||
108 | * Extra registers, both 32-bit little-endian | ||
109 | */ | ||
110 | #define IDE_TIMING_CONFIG 0x200 | ||
111 | #define IDE_INTERRUPT 0x300 | ||
112 | |||
113 | /* Kauai (U2) ATA has different register setup */ | ||
114 | #define IDE_KAUAI_PIO_CONFIG 0x200 | ||
115 | #define IDE_KAUAI_ULTRA_CONFIG 0x210 | ||
116 | #define IDE_KAUAI_POLL_CONFIG 0x220 | ||
117 | |||
118 | /* | ||
119 | * Timing configuration register definitions | ||
120 | */ | ||
121 | |||
122 | /* Number of IDE_SYSCLK_NS ticks, argument is in nanoseconds */ | ||
123 | #define SYSCLK_TICKS(t) (((t) + IDE_SYSCLK_NS - 1) / IDE_SYSCLK_NS) | ||
124 | #define SYSCLK_TICKS_66(t) (((t) + IDE_SYSCLK_66_NS - 1) / IDE_SYSCLK_66_NS) | ||
125 | #define IDE_SYSCLK_NS 30 /* 33Mhz cell */ | ||
126 | #define IDE_SYSCLK_66_NS 15 /* 66Mhz cell */ | ||
127 | |||
128 | /* 133Mhz cell, found in shasta. | ||
129 | * See comments about 100 Mhz Uninorth 2... | ||
130 | * Note that PIO_MASK and MDMA_MASK seem to overlap | ||
131 | */ | ||
132 | #define TR_133_PIOREG_PIO_MASK 0xff000fff | ||
133 | #define TR_133_PIOREG_MDMA_MASK 0x00fff800 | ||
134 | #define TR_133_UDMAREG_UDMA_MASK 0x0003ffff | ||
135 | #define TR_133_UDMAREG_UDMA_EN 0x00000001 | ||
136 | |||
137 | /* 100Mhz cell, found in Uninorth 2. I don't have much infos about | ||
138 | * this one yet, it appears as a pci device (106b/0033) on uninorth | ||
139 | * internal PCI bus and it's clock is controlled like gem or fw. It | ||
140 | * appears to be an evolution of keylargo ATA4 with a timing register | ||
141 | * extended to 2 32bits registers and a similar DBDMA channel. Other | ||
142 | * registers seem to exist but I can't tell much about them. | ||
143 | * | ||
144 | * So far, I'm using pre-calculated tables for this extracted from | ||
145 | * the values used by the MacOS X driver. | ||
146 | * | ||
147 | * The "PIO" register controls PIO and MDMA timings, the "ULTRA" | ||
148 | * register controls the UDMA timings. At least, it seems bit 0 | ||
149 | * of this one enables UDMA vs. MDMA, and bits 4..7 are the | ||
150 | * cycle time in units of 10ns. Bits 8..15 are used by I don't | ||
151 | * know their meaning yet | ||
152 | */ | ||
153 | #define TR_100_PIOREG_PIO_MASK 0xff000fff | ||
154 | #define TR_100_PIOREG_MDMA_MASK 0x00fff000 | ||
155 | #define TR_100_UDMAREG_UDMA_MASK 0x0000ffff | ||
156 | #define TR_100_UDMAREG_UDMA_EN 0x00000001 | ||
157 | |||
158 | |||
159 | /* 66Mhz cell, found in KeyLargo. Can do ultra mode 0 to 2 on | ||
160 | * 40 connector cable and to 4 on 80 connector one. | ||
161 | * Clock unit is 15ns (66Mhz) | ||
162 | * | ||
163 | * 3 Values can be programmed: | ||
164 | * - Write data setup, which appears to match the cycle time. They | ||
165 | * also call it DIOW setup. | ||
166 | * - Ready to pause time (from spec) | ||
167 | * - Address setup. That one is weird. I don't see where exactly | ||
168 | * it fits in UDMA cycles, I got it's name from an obscure piece | ||
169 | * of commented out code in Darwin. They leave it to 0, we do as | ||
170 | * well, despite a comment that would lead to think it has a | ||
171 | * min value of 45ns. | ||
172 | * Apple also add 60ns to the write data setup (or cycle time ?) on | ||
173 | * reads. | ||
174 | */ | ||
175 | #define TR_66_UDMA_MASK 0xfff00000 | ||
176 | #define TR_66_UDMA_EN 0x00100000 /* Enable Ultra mode for DMA */ | ||
177 | #define TR_66_UDMA_ADDRSETUP_MASK 0xe0000000 /* Address setup */ | ||
178 | #define TR_66_UDMA_ADDRSETUP_SHIFT 29 | ||
179 | #define TR_66_UDMA_RDY2PAUS_MASK 0x1e000000 /* Ready 2 pause time */ | ||
180 | #define TR_66_UDMA_RDY2PAUS_SHIFT 25 | ||
181 | #define TR_66_UDMA_WRDATASETUP_MASK 0x01e00000 /* Write data setup time */ | ||
182 | #define TR_66_UDMA_WRDATASETUP_SHIFT 21 | ||
183 | #define TR_66_MDMA_MASK 0x000ffc00 | ||
184 | #define TR_66_MDMA_RECOVERY_MASK 0x000f8000 | ||
185 | #define TR_66_MDMA_RECOVERY_SHIFT 15 | ||
186 | #define TR_66_MDMA_ACCESS_MASK 0x00007c00 | ||
187 | #define TR_66_MDMA_ACCESS_SHIFT 10 | ||
188 | #define TR_66_PIO_MASK 0x000003ff | ||
189 | #define TR_66_PIO_RECOVERY_MASK 0x000003e0 | ||
190 | #define TR_66_PIO_RECOVERY_SHIFT 5 | ||
191 | #define TR_66_PIO_ACCESS_MASK 0x0000001f | ||
192 | #define TR_66_PIO_ACCESS_SHIFT 0 | ||
193 | |||
194 | /* 33Mhz cell, found in OHare, Heathrow (& Paddington) and KeyLargo | ||
195 | * Can do pio & mdma modes, clock unit is 30ns (33Mhz) | ||
196 | * | ||
197 | * The access time and recovery time can be programmed. Some older | ||
198 | * Darwin code base limit OHare to 150ns cycle time. I decided to do | ||
199 | * the same here fore safety against broken old hardware ;) | ||
200 | * The HalfTick bit, when set, adds half a clock (15ns) to the access | ||
201 | * time and removes one from recovery. It's not supported on KeyLargo | ||
202 | * implementation afaik. The E bit appears to be set for PIO mode 0 and | ||
203 | * is used to reach long timings used in this mode. | ||
204 | */ | ||
205 | #define TR_33_MDMA_MASK 0x003ff800 | ||
206 | #define TR_33_MDMA_RECOVERY_MASK 0x001f0000 | ||
207 | #define TR_33_MDMA_RECOVERY_SHIFT 16 | ||
208 | #define TR_33_MDMA_ACCESS_MASK 0x0000f800 | ||
209 | #define TR_33_MDMA_ACCESS_SHIFT 11 | ||
210 | #define TR_33_MDMA_HALFTICK 0x00200000 | ||
211 | #define TR_33_PIO_MASK 0x000007ff | ||
212 | #define TR_33_PIO_E 0x00000400 | ||
213 | #define TR_33_PIO_RECOVERY_MASK 0x000003e0 | ||
214 | #define TR_33_PIO_RECOVERY_SHIFT 5 | ||
215 | #define TR_33_PIO_ACCESS_MASK 0x0000001f | ||
216 | #define TR_33_PIO_ACCESS_SHIFT 0 | ||
217 | |||
218 | /* | ||
219 | * Interrupt register definitions | ||
220 | */ | ||
221 | #define IDE_INTR_DMA 0x80000000 | ||
222 | #define IDE_INTR_DEVICE 0x40000000 | ||
223 | |||
224 | /* | ||
225 | * FCR Register on Kauai. Not sure what bit 0x4 is ... | ||
226 | */ | ||
227 | #define KAUAI_FCR_UATA_MAGIC 0x00000004 | ||
228 | #define KAUAI_FCR_UATA_RESET_N 0x00000002 | ||
229 | #define KAUAI_FCR_UATA_ENABLE 0x00000001 | ||
230 | |||
231 | #ifdef CONFIG_BLK_DEV_IDEDMA_PMAC | ||
232 | |||
233 | /* Rounded Multiword DMA timings | ||
234 | * | ||
235 | * I gave up finding a generic formula for all controller | ||
236 | * types and instead, built tables based on timing values | ||
237 | * used by Apple in Darwin's implementation. | ||
238 | */ | ||
239 | struct mdma_timings_t { | ||
240 | int accessTime; | ||
241 | int recoveryTime; | ||
242 | int cycleTime; | ||
243 | }; | ||
244 | |||
245 | struct mdma_timings_t mdma_timings_33[] __pmacdata = | ||
246 | { | ||
247 | { 240, 240, 480 }, | ||
248 | { 180, 180, 360 }, | ||
249 | { 135, 135, 270 }, | ||
250 | { 120, 120, 240 }, | ||
251 | { 105, 105, 210 }, | ||
252 | { 90, 90, 180 }, | ||
253 | { 75, 75, 150 }, | ||
254 | { 75, 45, 120 }, | ||
255 | { 0, 0, 0 } | ||
256 | }; | ||
257 | |||
258 | struct mdma_timings_t mdma_timings_33k[] __pmacdata = | ||
259 | { | ||
260 | { 240, 240, 480 }, | ||
261 | { 180, 180, 360 }, | ||
262 | { 150, 150, 300 }, | ||
263 | { 120, 120, 240 }, | ||
264 | { 90, 120, 210 }, | ||
265 | { 90, 90, 180 }, | ||
266 | { 90, 60, 150 }, | ||
267 | { 90, 30, 120 }, | ||
268 | { 0, 0, 0 } | ||
269 | }; | ||
270 | |||
271 | struct mdma_timings_t mdma_timings_66[] __pmacdata = | ||
272 | { | ||
273 | { 240, 240, 480 }, | ||
274 | { 180, 180, 360 }, | ||
275 | { 135, 135, 270 }, | ||
276 | { 120, 120, 240 }, | ||
277 | { 105, 105, 210 }, | ||
278 | { 90, 90, 180 }, | ||
279 | { 90, 75, 165 }, | ||
280 | { 75, 45, 120 }, | ||
281 | { 0, 0, 0 } | ||
282 | }; | ||
283 | |||
284 | /* KeyLargo ATA-4 Ultra DMA timings (rounded) */ | ||
285 | struct { | ||
286 | int addrSetup; /* ??? */ | ||
287 | int rdy2pause; | ||
288 | int wrDataSetup; | ||
289 | } kl66_udma_timings[] __pmacdata = | ||
290 | { | ||
291 | { 0, 180, 120 }, /* Mode 0 */ | ||
292 | { 0, 150, 90 }, /* 1 */ | ||
293 | { 0, 120, 60 }, /* 2 */ | ||
294 | { 0, 90, 45 }, /* 3 */ | ||
295 | { 0, 90, 30 } /* 4 */ | ||
296 | }; | ||
297 | |||
298 | /* UniNorth 2 ATA/100 timings */ | ||
299 | struct kauai_timing { | ||
300 | int cycle_time; | ||
301 | u32 timing_reg; | ||
302 | }; | ||
303 | |||
304 | static struct kauai_timing kauai_pio_timings[] __pmacdata = | ||
305 | { | ||
306 | { 930 , 0x08000fff }, | ||
307 | { 600 , 0x08000a92 }, | ||
308 | { 383 , 0x0800060f }, | ||
309 | { 360 , 0x08000492 }, | ||
310 | { 330 , 0x0800048f }, | ||
311 | { 300 , 0x080003cf }, | ||
312 | { 270 , 0x080003cc }, | ||
313 | { 240 , 0x0800038b }, | ||
314 | { 239 , 0x0800030c }, | ||
315 | { 180 , 0x05000249 }, | ||
316 | { 120 , 0x04000148 } | ||
317 | }; | ||
318 | |||
319 | static struct kauai_timing kauai_mdma_timings[] __pmacdata = | ||
320 | { | ||
321 | { 1260 , 0x00fff000 }, | ||
322 | { 480 , 0x00618000 }, | ||
323 | { 360 , 0x00492000 }, | ||
324 | { 270 , 0x0038e000 }, | ||
325 | { 240 , 0x0030c000 }, | ||
326 | { 210 , 0x002cb000 }, | ||
327 | { 180 , 0x00249000 }, | ||
328 | { 150 , 0x00209000 }, | ||
329 | { 120 , 0x00148000 }, | ||
330 | { 0 , 0 }, | ||
331 | }; | ||
332 | |||
333 | static struct kauai_timing kauai_udma_timings[] __pmacdata = | ||
334 | { | ||
335 | { 120 , 0x000070c0 }, | ||
336 | { 90 , 0x00005d80 }, | ||
337 | { 60 , 0x00004a60 }, | ||
338 | { 45 , 0x00003a50 }, | ||
339 | { 30 , 0x00002a30 }, | ||
340 | { 20 , 0x00002921 }, | ||
341 | { 0 , 0 }, | ||
342 | }; | ||
343 | |||
344 | static struct kauai_timing shasta_pio_timings[] __pmacdata = | ||
345 | { | ||
346 | { 930 , 0x08000fff }, | ||
347 | { 600 , 0x0A000c97 }, | ||
348 | { 383 , 0x07000712 }, | ||
349 | { 360 , 0x040003cd }, | ||
350 | { 330 , 0x040003cd }, | ||
351 | { 300 , 0x040003cd }, | ||
352 | { 270 , 0x040003cd }, | ||
353 | { 240 , 0x040003cd }, | ||
354 | { 239 , 0x040003cd }, | ||
355 | { 180 , 0x0400028b }, | ||
356 | { 120 , 0x0400010a } | ||
357 | }; | ||
358 | |||
359 | static struct kauai_timing shasta_mdma_timings[] __pmacdata = | ||
360 | { | ||
361 | { 1260 , 0x00fff000 }, | ||
362 | { 480 , 0x00820800 }, | ||
363 | { 360 , 0x00820800 }, | ||
364 | { 270 , 0x00820800 }, | ||
365 | { 240 , 0x00820800 }, | ||
366 | { 210 , 0x00820800 }, | ||
367 | { 180 , 0x00820800 }, | ||
368 | { 150 , 0x0028b000 }, | ||
369 | { 120 , 0x001ca000 }, | ||
370 | { 0 , 0 }, | ||
371 | }; | ||
372 | |||
373 | static struct kauai_timing shasta_udma133_timings[] __pmacdata = | ||
374 | { | ||
375 | { 120 , 0x00035901, }, | ||
376 | { 90 , 0x000348b1, }, | ||
377 | { 60 , 0x00033881, }, | ||
378 | { 45 , 0x00033861, }, | ||
379 | { 30 , 0x00033841, }, | ||
380 | { 20 , 0x00033031, }, | ||
381 | { 15 , 0x00033021, }, | ||
382 | { 0 , 0 }, | ||
383 | }; | ||
384 | |||
385 | |||
386 | static inline u32 | ||
387 | kauai_lookup_timing(struct kauai_timing* table, int cycle_time) | ||
388 | { | ||
389 | int i; | ||
390 | |||
391 | for (i=0; table[i].cycle_time; i++) | ||
392 | if (cycle_time > table[i+1].cycle_time) | ||
393 | return table[i].timing_reg; | ||
394 | return 0; | ||
395 | } | ||
396 | |||
397 | /* allow up to 256 DBDMA commands per xfer */ | ||
398 | #define MAX_DCMDS 256 | ||
399 | |||
400 | /* | ||
401 | * Wait 1s for disk to answer on IDE bus after a hard reset | ||
402 | * of the device (via GPIO/FCR). | ||
403 | * | ||
404 | * Some devices seem to "pollute" the bus even after dropping | ||
405 | * the BSY bit (typically some combo drives slave on the UDMA | ||
406 | * bus) after a hard reset. Since we hard reset all drives on | ||
407 | * KeyLargo ATA66, we have to keep that delay around. I may end | ||
408 | * up not hard resetting anymore on these and keep the delay only | ||
409 | * for older interfaces instead (we have to reset when coming | ||
410 | * from MacOS...) --BenH. | ||
411 | */ | ||
412 | #define IDE_WAKEUP_DELAY (1*HZ) | ||
413 | |||
414 | static void pmac_ide_setup_dma(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif); | ||
415 | static int pmac_ide_build_dmatable(ide_drive_t *drive, struct request *rq); | ||
416 | static int pmac_ide_tune_chipset(ide_drive_t *drive, u8 speed); | ||
417 | static void pmac_ide_tuneproc(ide_drive_t *drive, u8 pio); | ||
418 | static void pmac_ide_selectproc(ide_drive_t *drive); | ||
419 | static void pmac_ide_kauai_selectproc(ide_drive_t *drive); | ||
420 | |||
421 | #endif /* CONFIG_BLK_DEV_IDEDMA_PMAC */ | ||
422 | |||
423 | /* | ||
424 | * Below is the code for blinking the laptop LED along with hard | ||
425 | * disk activity. | ||
426 | */ | ||
427 | |||
428 | #ifdef CONFIG_BLK_DEV_IDE_PMAC_BLINK | ||
429 | |||
430 | /* Set to 50ms minimum led-on time (also used to limit frequency | ||
431 | * of requests sent to the PMU | ||
432 | */ | ||
433 | #define PMU_HD_BLINK_TIME (HZ/50) | ||
434 | |||
435 | static struct adb_request pmu_blink_on, pmu_blink_off; | ||
436 | static spinlock_t pmu_blink_lock; | ||
437 | static unsigned long pmu_blink_stoptime; | ||
438 | static int pmu_blink_ledstate; | ||
439 | static struct timer_list pmu_blink_timer; | ||
440 | static int pmu_ide_blink_enabled; | ||
441 | |||
442 | |||
443 | static void | ||
444 | pmu_hd_blink_timeout(unsigned long data) | ||
445 | { | ||
446 | unsigned long flags; | ||
447 | |||
448 | spin_lock_irqsave(&pmu_blink_lock, flags); | ||
449 | |||
450 | /* We may have been triggered again in a racy way, check | ||
451 | * that we really want to switch it off | ||
452 | */ | ||
453 | if (time_after(pmu_blink_stoptime, jiffies)) | ||
454 | goto done; | ||
455 | |||
456 | /* Previous req. not complete, try 100ms more */ | ||
457 | if (pmu_blink_off.complete == 0) | ||
458 | mod_timer(&pmu_blink_timer, jiffies + PMU_HD_BLINK_TIME); | ||
459 | else if (pmu_blink_ledstate) { | ||
460 | pmu_request(&pmu_blink_off, NULL, 4, 0xee, 4, 0, 0); | ||
461 | pmu_blink_ledstate = 0; | ||
462 | } | ||
463 | done: | ||
464 | spin_unlock_irqrestore(&pmu_blink_lock, flags); | ||
465 | } | ||
466 | |||
467 | static void | ||
468 | pmu_hd_kick_blink(void *data, int rw) | ||
469 | { | ||
470 | unsigned long flags; | ||
471 | |||
472 | pmu_blink_stoptime = jiffies + PMU_HD_BLINK_TIME; | ||
473 | wmb(); | ||
474 | mod_timer(&pmu_blink_timer, pmu_blink_stoptime); | ||
475 | /* Fast path when LED is already ON */ | ||
476 | if (pmu_blink_ledstate == 1) | ||
477 | return; | ||
478 | spin_lock_irqsave(&pmu_blink_lock, flags); | ||
479 | if (pmu_blink_on.complete && !pmu_blink_ledstate) { | ||
480 | pmu_request(&pmu_blink_on, NULL, 4, 0xee, 4, 0, 1); | ||
481 | pmu_blink_ledstate = 1; | ||
482 | } | ||
483 | spin_unlock_irqrestore(&pmu_blink_lock, flags); | ||
484 | } | ||
485 | |||
486 | static int | ||
487 | pmu_hd_blink_init(void) | ||
488 | { | ||
489 | struct device_node *dt; | ||
490 | const char *model; | ||
491 | |||
492 | /* Currently, I only enable this feature on KeyLargo based laptops, | ||
493 | * older laptops may support it (at least heathrow/paddington) but | ||
494 | * I don't feel like loading those venerable old machines with so | ||
495 | * much additional interrupt & PMU activity... | ||
496 | */ | ||
497 | if (pmu_get_model() != PMU_KEYLARGO_BASED) | ||
498 | return 0; | ||
499 | |||
500 | dt = find_devices("device-tree"); | ||
501 | if (dt == NULL) | ||
502 | return 0; | ||
503 | model = (const char *)get_property(dt, "model", NULL); | ||
504 | if (model == NULL) | ||
505 | return 0; | ||
506 | if (strncmp(model, "PowerBook", strlen("PowerBook")) != 0 && | ||
507 | strncmp(model, "iBook", strlen("iBook")) != 0) | ||
508 | return 0; | ||
509 | |||
510 | pmu_blink_on.complete = 1; | ||
511 | pmu_blink_off.complete = 1; | ||
512 | spin_lock_init(&pmu_blink_lock); | ||
513 | init_timer(&pmu_blink_timer); | ||
514 | pmu_blink_timer.function = pmu_hd_blink_timeout; | ||
515 | |||
516 | return 1; | ||
517 | } | ||
518 | |||
519 | #endif /* CONFIG_BLK_DEV_IDE_PMAC_BLINK */ | ||
520 | |||
521 | /* | ||
522 | * N.B. this can't be an initfunc, because the media-bay task can | ||
523 | * call ide_[un]register at any time. | ||
524 | */ | ||
525 | void __pmac | ||
526 | pmac_ide_init_hwif_ports(hw_regs_t *hw, | ||
527 | unsigned long data_port, unsigned long ctrl_port, | ||
528 | int *irq) | ||
529 | { | ||
530 | int i, ix; | ||
531 | |||
532 | if (data_port == 0) | ||
533 | return; | ||
534 | |||
535 | for (ix = 0; ix < MAX_HWIFS; ++ix) | ||
536 | if (data_port == pmac_ide[ix].regbase) | ||
537 | break; | ||
538 | |||
539 | if (ix >= MAX_HWIFS) { | ||
540 | /* Probably a PCI interface... */ | ||
541 | for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; ++i) | ||
542 | hw->io_ports[i] = data_port + i - IDE_DATA_OFFSET; | ||
543 | hw->io_ports[IDE_CONTROL_OFFSET] = ctrl_port; | ||
544 | return; | ||
545 | } | ||
546 | |||
547 | for (i = 0; i < 8; ++i) | ||
548 | hw->io_ports[i] = data_port + i * 0x10; | ||
549 | hw->io_ports[8] = data_port + 0x160; | ||
550 | |||
551 | if (irq != NULL) | ||
552 | *irq = pmac_ide[ix].irq; | ||
553 | } | ||
554 | |||
555 | #define PMAC_IDE_REG(x) ((void __iomem *)(IDE_DATA_REG+(x))) | ||
556 | |||
557 | /* | ||
558 | * Apply the timings of the proper unit (master/slave) to the shared | ||
559 | * timing register when selecting that unit. This version is for | ||
560 | * ASICs with a single timing register | ||
561 | */ | ||
562 | static void __pmac | ||
563 | pmac_ide_selectproc(ide_drive_t *drive) | ||
564 | { | ||
565 | pmac_ide_hwif_t* pmif = (pmac_ide_hwif_t *)HWIF(drive)->hwif_data; | ||
566 | |||
567 | if (pmif == NULL) | ||
568 | return; | ||
569 | |||
570 | if (drive->select.b.unit & 0x01) | ||
571 | writel(pmif->timings[1], PMAC_IDE_REG(IDE_TIMING_CONFIG)); | ||
572 | else | ||
573 | writel(pmif->timings[0], PMAC_IDE_REG(IDE_TIMING_CONFIG)); | ||
574 | (void)readl(PMAC_IDE_REG(IDE_TIMING_CONFIG)); | ||
575 | } | ||
576 | |||
577 | /* | ||
578 | * Apply the timings of the proper unit (master/slave) to the shared | ||
579 | * timing register when selecting that unit. This version is for | ||
580 | * ASICs with a dual timing register (Kauai) | ||
581 | */ | ||
582 | static void __pmac | ||
583 | pmac_ide_kauai_selectproc(ide_drive_t *drive) | ||
584 | { | ||
585 | pmac_ide_hwif_t* pmif = (pmac_ide_hwif_t *)HWIF(drive)->hwif_data; | ||
586 | |||
587 | if (pmif == NULL) | ||
588 | return; | ||
589 | |||
590 | if (drive->select.b.unit & 0x01) { | ||
591 | writel(pmif->timings[1], PMAC_IDE_REG(IDE_KAUAI_PIO_CONFIG)); | ||
592 | writel(pmif->timings[3], PMAC_IDE_REG(IDE_KAUAI_ULTRA_CONFIG)); | ||
593 | } else { | ||
594 | writel(pmif->timings[0], PMAC_IDE_REG(IDE_KAUAI_PIO_CONFIG)); | ||
595 | writel(pmif->timings[2], PMAC_IDE_REG(IDE_KAUAI_ULTRA_CONFIG)); | ||
596 | } | ||
597 | (void)readl(PMAC_IDE_REG(IDE_KAUAI_PIO_CONFIG)); | ||
598 | } | ||
599 | |||
600 | /* | ||
601 | * Force an update of controller timing values for a given drive | ||
602 | */ | ||
603 | static void __pmac | ||
604 | pmac_ide_do_update_timings(ide_drive_t *drive) | ||
605 | { | ||
606 | pmac_ide_hwif_t* pmif = (pmac_ide_hwif_t *)HWIF(drive)->hwif_data; | ||
607 | |||
608 | if (pmif == NULL) | ||
609 | return; | ||
610 | |||
611 | if (pmif->kind == controller_sh_ata6 || | ||
612 | pmif->kind == controller_un_ata6 || | ||
613 | pmif->kind == controller_k2_ata6) | ||
614 | pmac_ide_kauai_selectproc(drive); | ||
615 | else | ||
616 | pmac_ide_selectproc(drive); | ||
617 | } | ||
618 | |||
619 | static void | ||
620 | pmac_outbsync(ide_drive_t *drive, u8 value, unsigned long port) | ||
621 | { | ||
622 | u32 tmp; | ||
623 | |||
624 | writeb(value, (void __iomem *) port); | ||
625 | tmp = readl(PMAC_IDE_REG(IDE_TIMING_CONFIG)); | ||
626 | } | ||
627 | |||
628 | /* | ||
629 | * Send the SET_FEATURE IDE command to the drive and update drive->id with | ||
630 | * the new state. We currently don't use the generic routine as it used to | ||
631 | * cause various trouble, especially with older mediabays. | ||
632 | * This code is sometimes triggering a spurrious interrupt though, I need | ||
633 | * to sort that out sooner or later and see if I can finally get the | ||
634 | * common version to work properly in all cases | ||
635 | */ | ||
636 | static int __pmac | ||
637 | pmac_ide_do_setfeature(ide_drive_t *drive, u8 command) | ||
638 | { | ||
639 | ide_hwif_t *hwif = HWIF(drive); | ||
640 | int result = 1; | ||
641 | |||
642 | disable_irq_nosync(hwif->irq); | ||
643 | udelay(1); | ||
644 | SELECT_DRIVE(drive); | ||
645 | SELECT_MASK(drive, 0); | ||
646 | udelay(1); | ||
647 | /* Get rid of pending error state */ | ||
648 | (void) hwif->INB(IDE_STATUS_REG); | ||
649 | /* Timeout bumped for some powerbooks */ | ||
650 | if (wait_for_ready(drive, 2000)) { | ||
651 | /* Timeout bumped for some powerbooks */ | ||
652 | printk(KERN_ERR "%s: pmac_ide_do_setfeature disk not ready " | ||
653 | "before SET_FEATURE!\n", drive->name); | ||
654 | goto out; | ||
655 | } | ||
656 | udelay(10); | ||
657 | hwif->OUTB(drive->ctl | 2, IDE_CONTROL_REG); | ||
658 | hwif->OUTB(command, IDE_NSECTOR_REG); | ||
659 | hwif->OUTB(SETFEATURES_XFER, IDE_FEATURE_REG); | ||
660 | hwif->OUTBSYNC(drive, WIN_SETFEATURES, IDE_COMMAND_REG); | ||
661 | udelay(1); | ||
662 | /* Timeout bumped for some powerbooks */ | ||
663 | result = wait_for_ready(drive, 2000); | ||
664 | hwif->OUTB(drive->ctl, IDE_CONTROL_REG); | ||
665 | if (result) | ||
666 | printk(KERN_ERR "%s: pmac_ide_do_setfeature disk not ready " | ||
667 | "after SET_FEATURE !\n", drive->name); | ||
668 | out: | ||
669 | SELECT_MASK(drive, 0); | ||
670 | if (result == 0) { | ||
671 | drive->id->dma_ultra &= ~0xFF00; | ||
672 | drive->id->dma_mword &= ~0x0F00; | ||
673 | drive->id->dma_1word &= ~0x0F00; | ||
674 | switch(command) { | ||
675 | case XFER_UDMA_7: | ||
676 | drive->id->dma_ultra |= 0x8080; break; | ||
677 | case XFER_UDMA_6: | ||
678 | drive->id->dma_ultra |= 0x4040; break; | ||
679 | case XFER_UDMA_5: | ||
680 | drive->id->dma_ultra |= 0x2020; break; | ||
681 | case XFER_UDMA_4: | ||
682 | drive->id->dma_ultra |= 0x1010; break; | ||
683 | case XFER_UDMA_3: | ||
684 | drive->id->dma_ultra |= 0x0808; break; | ||
685 | case XFER_UDMA_2: | ||
686 | drive->id->dma_ultra |= 0x0404; break; | ||
687 | case XFER_UDMA_1: | ||
688 | drive->id->dma_ultra |= 0x0202; break; | ||
689 | case XFER_UDMA_0: | ||
690 | drive->id->dma_ultra |= 0x0101; break; | ||
691 | case XFER_MW_DMA_2: | ||
692 | drive->id->dma_mword |= 0x0404; break; | ||
693 | case XFER_MW_DMA_1: | ||
694 | drive->id->dma_mword |= 0x0202; break; | ||
695 | case XFER_MW_DMA_0: | ||
696 | drive->id->dma_mword |= 0x0101; break; | ||
697 | case XFER_SW_DMA_2: | ||
698 | drive->id->dma_1word |= 0x0404; break; | ||
699 | case XFER_SW_DMA_1: | ||
700 | drive->id->dma_1word |= 0x0202; break; | ||
701 | case XFER_SW_DMA_0: | ||
702 | drive->id->dma_1word |= 0x0101; break; | ||
703 | default: break; | ||
704 | } | ||
705 | } | ||
706 | enable_irq(hwif->irq); | ||
707 | return result; | ||
708 | } | ||
709 | |||
710 | /* | ||
711 | * Old tuning functions (called on hdparm -p), sets up drive PIO timings | ||
712 | */ | ||
713 | static void __pmac | ||
714 | pmac_ide_tuneproc(ide_drive_t *drive, u8 pio) | ||
715 | { | ||
716 | ide_pio_data_t d; | ||
717 | u32 *timings; | ||
718 | unsigned accessTicks, recTicks; | ||
719 | unsigned accessTime, recTime; | ||
720 | pmac_ide_hwif_t* pmif = (pmac_ide_hwif_t *)HWIF(drive)->hwif_data; | ||
721 | |||
722 | if (pmif == NULL) | ||
723 | return; | ||
724 | |||
725 | /* which drive is it ? */ | ||
726 | timings = &pmif->timings[drive->select.b.unit & 0x01]; | ||
727 | |||
728 | pio = ide_get_best_pio_mode(drive, pio, 4, &d); | ||
729 | |||
730 | switch (pmif->kind) { | ||
731 | case controller_sh_ata6: { | ||
732 | /* 133Mhz cell */ | ||
733 | u32 tr = kauai_lookup_timing(shasta_pio_timings, d.cycle_time); | ||
734 | if (tr == 0) | ||
735 | return; | ||
736 | *timings = ((*timings) & ~TR_133_PIOREG_PIO_MASK) | tr; | ||
737 | break; | ||
738 | } | ||
739 | case controller_un_ata6: | ||
740 | case controller_k2_ata6: { | ||
741 | /* 100Mhz cell */ | ||
742 | u32 tr = kauai_lookup_timing(kauai_pio_timings, d.cycle_time); | ||
743 | if (tr == 0) | ||
744 | return; | ||
745 | *timings = ((*timings) & ~TR_100_PIOREG_PIO_MASK) | tr; | ||
746 | break; | ||
747 | } | ||
748 | case controller_kl_ata4: | ||
749 | /* 66Mhz cell */ | ||
750 | recTime = d.cycle_time - ide_pio_timings[pio].active_time | ||
751 | - ide_pio_timings[pio].setup_time; | ||
752 | recTime = max(recTime, 150U); | ||
753 | accessTime = ide_pio_timings[pio].active_time; | ||
754 | accessTime = max(accessTime, 150U); | ||
755 | accessTicks = SYSCLK_TICKS_66(accessTime); | ||
756 | accessTicks = min(accessTicks, 0x1fU); | ||
757 | recTicks = SYSCLK_TICKS_66(recTime); | ||
758 | recTicks = min(recTicks, 0x1fU); | ||
759 | *timings = ((*timings) & ~TR_66_PIO_MASK) | | ||
760 | (accessTicks << TR_66_PIO_ACCESS_SHIFT) | | ||
761 | (recTicks << TR_66_PIO_RECOVERY_SHIFT); | ||
762 | break; | ||
763 | default: { | ||
764 | /* 33Mhz cell */ | ||
765 | int ebit = 0; | ||
766 | recTime = d.cycle_time - ide_pio_timings[pio].active_time | ||
767 | - ide_pio_timings[pio].setup_time; | ||
768 | recTime = max(recTime, 150U); | ||
769 | accessTime = ide_pio_timings[pio].active_time; | ||
770 | accessTime = max(accessTime, 150U); | ||
771 | accessTicks = SYSCLK_TICKS(accessTime); | ||
772 | accessTicks = min(accessTicks, 0x1fU); | ||
773 | accessTicks = max(accessTicks, 4U); | ||
774 | recTicks = SYSCLK_TICKS(recTime); | ||
775 | recTicks = min(recTicks, 0x1fU); | ||
776 | recTicks = max(recTicks, 5U) - 4; | ||
777 | if (recTicks > 9) { | ||
778 | recTicks--; /* guess, but it's only for PIO0, so... */ | ||
779 | ebit = 1; | ||
780 | } | ||
781 | *timings = ((*timings) & ~TR_33_PIO_MASK) | | ||
782 | (accessTicks << TR_33_PIO_ACCESS_SHIFT) | | ||
783 | (recTicks << TR_33_PIO_RECOVERY_SHIFT); | ||
784 | if (ebit) | ||
785 | *timings |= TR_33_PIO_E; | ||
786 | break; | ||
787 | } | ||
788 | } | ||
789 | |||
790 | #ifdef IDE_PMAC_DEBUG | ||
791 | printk(KERN_ERR "%s: Set PIO timing for mode %d, reg: 0x%08x\n", | ||
792 | drive->name, pio, *timings); | ||
793 | #endif | ||
794 | |||
795 | if (drive->select.all == HWIF(drive)->INB(IDE_SELECT_REG)) | ||
796 | pmac_ide_do_update_timings(drive); | ||
797 | } | ||
798 | |||
799 | #ifdef CONFIG_BLK_DEV_IDEDMA_PMAC | ||
800 | |||
801 | /* | ||
802 | * Calculate KeyLargo ATA/66 UDMA timings | ||
803 | */ | ||
804 | static int __pmac | ||
805 | set_timings_udma_ata4(u32 *timings, u8 speed) | ||
806 | { | ||
807 | unsigned rdyToPauseTicks, wrDataSetupTicks, addrTicks; | ||
808 | |||
809 | if (speed > XFER_UDMA_4) | ||
810 | return 1; | ||
811 | |||
812 | rdyToPauseTicks = SYSCLK_TICKS_66(kl66_udma_timings[speed & 0xf].rdy2pause); | ||
813 | wrDataSetupTicks = SYSCLK_TICKS_66(kl66_udma_timings[speed & 0xf].wrDataSetup); | ||
814 | addrTicks = SYSCLK_TICKS_66(kl66_udma_timings[speed & 0xf].addrSetup); | ||
815 | |||
816 | *timings = ((*timings) & ~(TR_66_UDMA_MASK | TR_66_MDMA_MASK)) | | ||
817 | (wrDataSetupTicks << TR_66_UDMA_WRDATASETUP_SHIFT) | | ||
818 | (rdyToPauseTicks << TR_66_UDMA_RDY2PAUS_SHIFT) | | ||
819 | (addrTicks <<TR_66_UDMA_ADDRSETUP_SHIFT) | | ||
820 | TR_66_UDMA_EN; | ||
821 | #ifdef IDE_PMAC_DEBUG | ||
822 | printk(KERN_ERR "ide_pmac: Set UDMA timing for mode %d, reg: 0x%08x\n", | ||
823 | speed & 0xf, *timings); | ||
824 | #endif | ||
825 | |||
826 | return 0; | ||
827 | } | ||
828 | |||
829 | /* | ||
830 | * Calculate Kauai ATA/100 UDMA timings | ||
831 | */ | ||
832 | static int __pmac | ||
833 | set_timings_udma_ata6(u32 *pio_timings, u32 *ultra_timings, u8 speed) | ||
834 | { | ||
835 | struct ide_timing *t = ide_timing_find_mode(speed); | ||
836 | u32 tr; | ||
837 | |||
838 | if (speed > XFER_UDMA_5 || t == NULL) | ||
839 | return 1; | ||
840 | tr = kauai_lookup_timing(kauai_udma_timings, (int)t->udma); | ||
841 | if (tr == 0) | ||
842 | return 1; | ||
843 | *ultra_timings = ((*ultra_timings) & ~TR_100_UDMAREG_UDMA_MASK) | tr; | ||
844 | *ultra_timings = (*ultra_timings) | TR_100_UDMAREG_UDMA_EN; | ||
845 | |||
846 | return 0; | ||
847 | } | ||
848 | |||
849 | /* | ||
850 | * Calculate Shasta ATA/133 UDMA timings | ||
851 | */ | ||
852 | static int __pmac | ||
853 | set_timings_udma_shasta(u32 *pio_timings, u32 *ultra_timings, u8 speed) | ||
854 | { | ||
855 | struct ide_timing *t = ide_timing_find_mode(speed); | ||
856 | u32 tr; | ||
857 | |||
858 | if (speed > XFER_UDMA_6 || t == NULL) | ||
859 | return 1; | ||
860 | tr = kauai_lookup_timing(shasta_udma133_timings, (int)t->udma); | ||
861 | if (tr == 0) | ||
862 | return 1; | ||
863 | *ultra_timings = ((*ultra_timings) & ~TR_133_UDMAREG_UDMA_MASK) | tr; | ||
864 | *ultra_timings = (*ultra_timings) | TR_133_UDMAREG_UDMA_EN; | ||
865 | |||
866 | return 0; | ||
867 | } | ||
868 | |||
869 | /* | ||
870 | * Calculate MDMA timings for all cells | ||
871 | */ | ||
872 | static int __pmac | ||
873 | set_timings_mdma(ide_drive_t *drive, int intf_type, u32 *timings, u32 *timings2, | ||
874 | u8 speed, int drive_cycle_time) | ||
875 | { | ||
876 | int cycleTime, accessTime = 0, recTime = 0; | ||
877 | unsigned accessTicks, recTicks; | ||
878 | struct mdma_timings_t* tm = NULL; | ||
879 | int i; | ||
880 | |||
881 | /* Get default cycle time for mode */ | ||
882 | switch(speed & 0xf) { | ||
883 | case 0: cycleTime = 480; break; | ||
884 | case 1: cycleTime = 150; break; | ||
885 | case 2: cycleTime = 120; break; | ||
886 | default: | ||
887 | return 1; | ||
888 | } | ||
889 | /* Adjust for drive */ | ||
890 | if (drive_cycle_time && drive_cycle_time > cycleTime) | ||
891 | cycleTime = drive_cycle_time; | ||
892 | /* OHare limits according to some old Apple sources */ | ||
893 | if ((intf_type == controller_ohare) && (cycleTime < 150)) | ||
894 | cycleTime = 150; | ||
895 | /* Get the proper timing array for this controller */ | ||
896 | switch(intf_type) { | ||
897 | case controller_sh_ata6: | ||
898 | case controller_un_ata6: | ||
899 | case controller_k2_ata6: | ||
900 | break; | ||
901 | case controller_kl_ata4: | ||
902 | tm = mdma_timings_66; | ||
903 | break; | ||
904 | case controller_kl_ata3: | ||
905 | tm = mdma_timings_33k; | ||
906 | break; | ||
907 | default: | ||
908 | tm = mdma_timings_33; | ||
909 | break; | ||
910 | } | ||
911 | if (tm != NULL) { | ||
912 | /* Lookup matching access & recovery times */ | ||
913 | i = -1; | ||
914 | for (;;) { | ||
915 | if (tm[i+1].cycleTime < cycleTime) | ||
916 | break; | ||
917 | i++; | ||
918 | } | ||
919 | if (i < 0) | ||
920 | return 1; | ||
921 | cycleTime = tm[i].cycleTime; | ||
922 | accessTime = tm[i].accessTime; | ||
923 | recTime = tm[i].recoveryTime; | ||
924 | |||
925 | #ifdef IDE_PMAC_DEBUG | ||
926 | printk(KERN_ERR "%s: MDMA, cycleTime: %d, accessTime: %d, recTime: %d\n", | ||
927 | drive->name, cycleTime, accessTime, recTime); | ||
928 | #endif | ||
929 | } | ||
930 | switch(intf_type) { | ||
931 | case controller_sh_ata6: { | ||
932 | /* 133Mhz cell */ | ||
933 | u32 tr = kauai_lookup_timing(shasta_mdma_timings, cycleTime); | ||
934 | if (tr == 0) | ||
935 | return 1; | ||
936 | *timings = ((*timings) & ~TR_133_PIOREG_MDMA_MASK) | tr; | ||
937 | *timings2 = (*timings2) & ~TR_133_UDMAREG_UDMA_EN; | ||
938 | } | ||
939 | case controller_un_ata6: | ||
940 | case controller_k2_ata6: { | ||
941 | /* 100Mhz cell */ | ||
942 | u32 tr = kauai_lookup_timing(kauai_mdma_timings, cycleTime); | ||
943 | if (tr == 0) | ||
944 | return 1; | ||
945 | *timings = ((*timings) & ~TR_100_PIOREG_MDMA_MASK) | tr; | ||
946 | *timings2 = (*timings2) & ~TR_100_UDMAREG_UDMA_EN; | ||
947 | } | ||
948 | break; | ||
949 | case controller_kl_ata4: | ||
950 | /* 66Mhz cell */ | ||
951 | accessTicks = SYSCLK_TICKS_66(accessTime); | ||
952 | accessTicks = min(accessTicks, 0x1fU); | ||
953 | accessTicks = max(accessTicks, 0x1U); | ||
954 | recTicks = SYSCLK_TICKS_66(recTime); | ||
955 | recTicks = min(recTicks, 0x1fU); | ||
956 | recTicks = max(recTicks, 0x3U); | ||
957 | /* Clear out mdma bits and disable udma */ | ||
958 | *timings = ((*timings) & ~(TR_66_MDMA_MASK | TR_66_UDMA_MASK)) | | ||
959 | (accessTicks << TR_66_MDMA_ACCESS_SHIFT) | | ||
960 | (recTicks << TR_66_MDMA_RECOVERY_SHIFT); | ||
961 | break; | ||
962 | case controller_kl_ata3: | ||
963 | /* 33Mhz cell on KeyLargo */ | ||
964 | accessTicks = SYSCLK_TICKS(accessTime); | ||
965 | accessTicks = max(accessTicks, 1U); | ||
966 | accessTicks = min(accessTicks, 0x1fU); | ||
967 | accessTime = accessTicks * IDE_SYSCLK_NS; | ||
968 | recTicks = SYSCLK_TICKS(recTime); | ||
969 | recTicks = max(recTicks, 1U); | ||
970 | recTicks = min(recTicks, 0x1fU); | ||
971 | *timings = ((*timings) & ~TR_33_MDMA_MASK) | | ||
972 | (accessTicks << TR_33_MDMA_ACCESS_SHIFT) | | ||
973 | (recTicks << TR_33_MDMA_RECOVERY_SHIFT); | ||
974 | break; | ||
975 | default: { | ||
976 | /* 33Mhz cell on others */ | ||
977 | int halfTick = 0; | ||
978 | int origAccessTime = accessTime; | ||
979 | int origRecTime = recTime; | ||
980 | |||
981 | accessTicks = SYSCLK_TICKS(accessTime); | ||
982 | accessTicks = max(accessTicks, 1U); | ||
983 | accessTicks = min(accessTicks, 0x1fU); | ||
984 | accessTime = accessTicks * IDE_SYSCLK_NS; | ||
985 | recTicks = SYSCLK_TICKS(recTime); | ||
986 | recTicks = max(recTicks, 2U) - 1; | ||
987 | recTicks = min(recTicks, 0x1fU); | ||
988 | recTime = (recTicks + 1) * IDE_SYSCLK_NS; | ||
989 | if ((accessTicks > 1) && | ||
990 | ((accessTime - IDE_SYSCLK_NS/2) >= origAccessTime) && | ||
991 | ((recTime - IDE_SYSCLK_NS/2) >= origRecTime)) { | ||
992 | halfTick = 1; | ||
993 | accessTicks--; | ||
994 | } | ||
995 | *timings = ((*timings) & ~TR_33_MDMA_MASK) | | ||
996 | (accessTicks << TR_33_MDMA_ACCESS_SHIFT) | | ||
997 | (recTicks << TR_33_MDMA_RECOVERY_SHIFT); | ||
998 | if (halfTick) | ||
999 | *timings |= TR_33_MDMA_HALFTICK; | ||
1000 | } | ||
1001 | } | ||
1002 | #ifdef IDE_PMAC_DEBUG | ||
1003 | printk(KERN_ERR "%s: Set MDMA timing for mode %d, reg: 0x%08x\n", | ||
1004 | drive->name, speed & 0xf, *timings); | ||
1005 | #endif | ||
1006 | return 0; | ||
1007 | } | ||
1008 | #endif /* #ifdef CONFIG_BLK_DEV_IDEDMA_PMAC */ | ||
1009 | |||
1010 | /* | ||
1011 | * Speedproc. This function is called by the core to set any of the standard | ||
1012 | * timing (PIO, MDMA or UDMA) to both the drive and the controller. | ||
1013 | * You may notice we don't use this function on normal "dma check" operation, | ||
1014 | * our dedicated function is more precise as it uses the drive provided | ||
1015 | * cycle time value. We should probably fix this one to deal with that too... | ||
1016 | */ | ||
1017 | static int __pmac | ||
1018 | pmac_ide_tune_chipset (ide_drive_t *drive, byte speed) | ||
1019 | { | ||
1020 | int unit = (drive->select.b.unit & 0x01); | ||
1021 | int ret = 0; | ||
1022 | pmac_ide_hwif_t* pmif = (pmac_ide_hwif_t *)HWIF(drive)->hwif_data; | ||
1023 | u32 *timings, *timings2; | ||
1024 | |||
1025 | if (pmif == NULL) | ||
1026 | return 1; | ||
1027 | |||
1028 | timings = &pmif->timings[unit]; | ||
1029 | timings2 = &pmif->timings[unit+2]; | ||
1030 | |||
1031 | switch(speed) { | ||
1032 | #ifdef CONFIG_BLK_DEV_IDEDMA_PMAC | ||
1033 | case XFER_UDMA_6: | ||
1034 | if (pmif->kind != controller_sh_ata6) | ||
1035 | return 1; | ||
1036 | case XFER_UDMA_5: | ||
1037 | if (pmif->kind != controller_un_ata6 && | ||
1038 | pmif->kind != controller_k2_ata6 && | ||
1039 | pmif->kind != controller_sh_ata6) | ||
1040 | return 1; | ||
1041 | case XFER_UDMA_4: | ||
1042 | case XFER_UDMA_3: | ||
1043 | if (HWIF(drive)->udma_four == 0) | ||
1044 | return 1; | ||
1045 | case XFER_UDMA_2: | ||
1046 | case XFER_UDMA_1: | ||
1047 | case XFER_UDMA_0: | ||
1048 | if (pmif->kind == controller_kl_ata4) | ||
1049 | ret = set_timings_udma_ata4(timings, speed); | ||
1050 | else if (pmif->kind == controller_un_ata6 | ||
1051 | || pmif->kind == controller_k2_ata6) | ||
1052 | ret = set_timings_udma_ata6(timings, timings2, speed); | ||
1053 | else if (pmif->kind == controller_sh_ata6) | ||
1054 | ret = set_timings_udma_shasta(timings, timings2, speed); | ||
1055 | else | ||
1056 | ret = 1; | ||
1057 | break; | ||
1058 | case XFER_MW_DMA_2: | ||
1059 | case XFER_MW_DMA_1: | ||
1060 | case XFER_MW_DMA_0: | ||
1061 | ret = set_timings_mdma(drive, pmif->kind, timings, timings2, speed, 0); | ||
1062 | break; | ||
1063 | case XFER_SW_DMA_2: | ||
1064 | case XFER_SW_DMA_1: | ||
1065 | case XFER_SW_DMA_0: | ||
1066 | return 1; | ||
1067 | #endif /* CONFIG_BLK_DEV_IDEDMA_PMAC */ | ||
1068 | case XFER_PIO_4: | ||
1069 | case XFER_PIO_3: | ||
1070 | case XFER_PIO_2: | ||
1071 | case XFER_PIO_1: | ||
1072 | case XFER_PIO_0: | ||
1073 | pmac_ide_tuneproc(drive, speed & 0x07); | ||
1074 | break; | ||
1075 | default: | ||
1076 | ret = 1; | ||
1077 | } | ||
1078 | if (ret) | ||
1079 | return ret; | ||
1080 | |||
1081 | ret = pmac_ide_do_setfeature(drive, speed); | ||
1082 | if (ret) | ||
1083 | return ret; | ||
1084 | |||
1085 | pmac_ide_do_update_timings(drive); | ||
1086 | drive->current_speed = speed; | ||
1087 | |||
1088 | return 0; | ||
1089 | } | ||
1090 | |||
1091 | /* | ||
1092 | * Blast some well known "safe" values to the timing registers at init or | ||
1093 | * wakeup from sleep time, before we do real calculation | ||
1094 | */ | ||
1095 | static void __pmac | ||
1096 | sanitize_timings(pmac_ide_hwif_t *pmif) | ||
1097 | { | ||
1098 | unsigned int value, value2 = 0; | ||
1099 | |||
1100 | switch(pmif->kind) { | ||
1101 | case controller_sh_ata6: | ||
1102 | value = 0x0a820c97; | ||
1103 | value2 = 0x00033031; | ||
1104 | break; | ||
1105 | case controller_un_ata6: | ||
1106 | case controller_k2_ata6: | ||
1107 | value = 0x08618a92; | ||
1108 | value2 = 0x00002921; | ||
1109 | break; | ||
1110 | case controller_kl_ata4: | ||
1111 | value = 0x0008438c; | ||
1112 | break; | ||
1113 | case controller_kl_ata3: | ||
1114 | value = 0x00084526; | ||
1115 | break; | ||
1116 | case controller_heathrow: | ||
1117 | case controller_ohare: | ||
1118 | default: | ||
1119 | value = 0x00074526; | ||
1120 | break; | ||
1121 | } | ||
1122 | pmif->timings[0] = pmif->timings[1] = value; | ||
1123 | pmif->timings[2] = pmif->timings[3] = value2; | ||
1124 | } | ||
1125 | |||
1126 | unsigned long __pmac | ||
1127 | pmac_ide_get_base(int index) | ||
1128 | { | ||
1129 | return pmac_ide[index].regbase; | ||
1130 | } | ||
1131 | |||
1132 | int __pmac | ||
1133 | pmac_ide_check_base(unsigned long base) | ||
1134 | { | ||
1135 | int ix; | ||
1136 | |||
1137 | for (ix = 0; ix < MAX_HWIFS; ++ix) | ||
1138 | if (base == pmac_ide[ix].regbase) | ||
1139 | return ix; | ||
1140 | return -1; | ||
1141 | } | ||
1142 | |||
1143 | int __pmac | ||
1144 | pmac_ide_get_irq(unsigned long base) | ||
1145 | { | ||
1146 | int ix; | ||
1147 | |||
1148 | for (ix = 0; ix < MAX_HWIFS; ++ix) | ||
1149 | if (base == pmac_ide[ix].regbase) | ||
1150 | return pmac_ide[ix].irq; | ||
1151 | return 0; | ||
1152 | } | ||
1153 | |||
1154 | static int ide_majors[] __pmacdata = { 3, 22, 33, 34, 56, 57 }; | ||
1155 | |||
1156 | dev_t __init | ||
1157 | pmac_find_ide_boot(char *bootdevice, int n) | ||
1158 | { | ||
1159 | int i; | ||
1160 | |||
1161 | /* | ||
1162 | * Look through the list of IDE interfaces for this one. | ||
1163 | */ | ||
1164 | for (i = 0; i < pmac_ide_count; ++i) { | ||
1165 | char *name; | ||
1166 | if (!pmac_ide[i].node || !pmac_ide[i].node->full_name) | ||
1167 | continue; | ||
1168 | name = pmac_ide[i].node->full_name; | ||
1169 | if (memcmp(name, bootdevice, n) == 0 && name[n] == 0) { | ||
1170 | /* XXX should cope with the 2nd drive as well... */ | ||
1171 | return MKDEV(ide_majors[i], 0); | ||
1172 | } | ||
1173 | } | ||
1174 | |||
1175 | return 0; | ||
1176 | } | ||
1177 | |||
1178 | /* Suspend call back, should be called after the child devices | ||
1179 | * have actually been suspended | ||
1180 | */ | ||
1181 | static int | ||
1182 | pmac_ide_do_suspend(ide_hwif_t *hwif) | ||
1183 | { | ||
1184 | pmac_ide_hwif_t *pmif = (pmac_ide_hwif_t *)hwif->hwif_data; | ||
1185 | |||
1186 | /* We clear the timings */ | ||
1187 | pmif->timings[0] = 0; | ||
1188 | pmif->timings[1] = 0; | ||
1189 | |||
1190 | #ifdef CONFIG_BLK_DEV_IDE_PMAC_BLINK | ||
1191 | /* Note: This code will be called for every hwif, thus we'll | ||
1192 | * try several time to stop the LED blinker timer, but that | ||
1193 | * should be harmless | ||
1194 | */ | ||
1195 | if (pmu_ide_blink_enabled) { | ||
1196 | unsigned long flags; | ||
1197 | |||
1198 | /* Make sure we don't hit the PMU blink */ | ||
1199 | spin_lock_irqsave(&pmu_blink_lock, flags); | ||
1200 | if (pmu_blink_ledstate) | ||
1201 | del_timer(&pmu_blink_timer); | ||
1202 | pmu_blink_ledstate = 0; | ||
1203 | spin_unlock_irqrestore(&pmu_blink_lock, flags); | ||
1204 | } | ||
1205 | #endif /* CONFIG_BLK_DEV_IDE_PMAC_BLINK */ | ||
1206 | |||
1207 | /* The media bay will handle itself just fine */ | ||
1208 | if (pmif->mediabay) | ||
1209 | return 0; | ||
1210 | |||
1211 | /* Kauai has bus control FCRs directly here */ | ||
1212 | if (pmif->kauai_fcr) { | ||
1213 | u32 fcr = readl(pmif->kauai_fcr); | ||
1214 | fcr &= ~(KAUAI_FCR_UATA_RESET_N | KAUAI_FCR_UATA_ENABLE); | ||
1215 | writel(fcr, pmif->kauai_fcr); | ||
1216 | } | ||
1217 | |||
1218 | /* Disable the bus on older machines and the cell on kauai */ | ||
1219 | ppc_md.feature_call(PMAC_FTR_IDE_ENABLE, pmif->node, pmif->aapl_bus_id, | ||
1220 | 0); | ||
1221 | |||
1222 | return 0; | ||
1223 | } | ||
1224 | |||
1225 | /* Resume call back, should be called before the child devices | ||
1226 | * are resumed | ||
1227 | */ | ||
1228 | static int | ||
1229 | pmac_ide_do_resume(ide_hwif_t *hwif) | ||
1230 | { | ||
1231 | pmac_ide_hwif_t *pmif = (pmac_ide_hwif_t *)hwif->hwif_data; | ||
1232 | |||
1233 | /* Hard reset & re-enable controller (do we really need to reset ? -BenH) */ | ||
1234 | if (!pmif->mediabay) { | ||
1235 | ppc_md.feature_call(PMAC_FTR_IDE_RESET, pmif->node, pmif->aapl_bus_id, 1); | ||
1236 | ppc_md.feature_call(PMAC_FTR_IDE_ENABLE, pmif->node, pmif->aapl_bus_id, 1); | ||
1237 | msleep(10); | ||
1238 | ppc_md.feature_call(PMAC_FTR_IDE_RESET, pmif->node, pmif->aapl_bus_id, 0); | ||
1239 | msleep(jiffies_to_msecs(IDE_WAKEUP_DELAY)); | ||
1240 | |||
1241 | /* Kauai has it different */ | ||
1242 | if (pmif->kauai_fcr) { | ||
1243 | u32 fcr = readl(pmif->kauai_fcr); | ||
1244 | fcr |= KAUAI_FCR_UATA_RESET_N | KAUAI_FCR_UATA_ENABLE; | ||
1245 | writel(fcr, pmif->kauai_fcr); | ||
1246 | } | ||
1247 | } | ||
1248 | |||
1249 | /* Sanitize drive timings */ | ||
1250 | sanitize_timings(pmif); | ||
1251 | |||
1252 | return 0; | ||
1253 | } | ||
1254 | |||
1255 | /* | ||
1256 | * Setup, register & probe an IDE channel driven by this driver, this is | ||
1257 | * called by one of the 2 probe functions (macio or PCI). Note that a channel | ||
1258 | * that ends up beeing free of any device is not kept around by this driver | ||
1259 | * (it is kept in 2.4). This introduce an interface numbering change on some | ||
1260 | * rare machines unfortunately, but it's better this way. | ||
1261 | */ | ||
1262 | static int | ||
1263 | pmac_ide_setup_device(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif) | ||
1264 | { | ||
1265 | struct device_node *np = pmif->node; | ||
1266 | int *bidp, i; | ||
1267 | |||
1268 | pmif->cable_80 = 0; | ||
1269 | pmif->broken_dma = pmif->broken_dma_warn = 0; | ||
1270 | if (device_is_compatible(np, "shasta-ata")) | ||
1271 | pmif->kind = controller_sh_ata6; | ||
1272 | else if (device_is_compatible(np, "kauai-ata")) | ||
1273 | pmif->kind = controller_un_ata6; | ||
1274 | else if (device_is_compatible(np, "K2-UATA")) | ||
1275 | pmif->kind = controller_k2_ata6; | ||
1276 | else if (device_is_compatible(np, "keylargo-ata")) { | ||
1277 | if (strcmp(np->name, "ata-4") == 0) | ||
1278 | pmif->kind = controller_kl_ata4; | ||
1279 | else | ||
1280 | pmif->kind = controller_kl_ata3; | ||
1281 | } else if (device_is_compatible(np, "heathrow-ata")) | ||
1282 | pmif->kind = controller_heathrow; | ||
1283 | else { | ||
1284 | pmif->kind = controller_ohare; | ||
1285 | pmif->broken_dma = 1; | ||
1286 | } | ||
1287 | |||
1288 | bidp = (int *)get_property(np, "AAPL,bus-id", NULL); | ||
1289 | pmif->aapl_bus_id = bidp ? *bidp : 0; | ||
1290 | |||
1291 | /* Get cable type from device-tree */ | ||
1292 | if (pmif->kind == controller_kl_ata4 || pmif->kind == controller_un_ata6 | ||
1293 | || pmif->kind == controller_k2_ata6 | ||
1294 | || pmif->kind == controller_sh_ata6) { | ||
1295 | char* cable = get_property(np, "cable-type", NULL); | ||
1296 | if (cable && !strncmp(cable, "80-", 3)) | ||
1297 | pmif->cable_80 = 1; | ||
1298 | } | ||
1299 | /* G5's seem to have incorrect cable type in device-tree. Let's assume | ||
1300 | * they have a 80 conductor cable, this seem to be always the case unless | ||
1301 | * the user mucked around | ||
1302 | */ | ||
1303 | if (device_is_compatible(np, "K2-UATA") || | ||
1304 | device_is_compatible(np, "shasta-ata")) | ||
1305 | pmif->cable_80 = 1; | ||
1306 | |||
1307 | /* On Kauai-type controllers, we make sure the FCR is correct */ | ||
1308 | if (pmif->kauai_fcr) | ||
1309 | writel(KAUAI_FCR_UATA_MAGIC | | ||
1310 | KAUAI_FCR_UATA_RESET_N | | ||
1311 | KAUAI_FCR_UATA_ENABLE, pmif->kauai_fcr); | ||
1312 | |||
1313 | pmif->mediabay = 0; | ||
1314 | |||
1315 | /* Make sure we have sane timings */ | ||
1316 | sanitize_timings(pmif); | ||
1317 | |||
1318 | #ifndef CONFIG_PPC64 | ||
1319 | /* XXX FIXME: Media bay stuff need re-organizing */ | ||
1320 | if (np->parent && np->parent->name | ||
1321 | && strcasecmp(np->parent->name, "media-bay") == 0) { | ||
1322 | #ifdef CONFIG_PMAC_PBOOK | ||
1323 | media_bay_set_ide_infos(np->parent, pmif->regbase, pmif->irq, hwif->index); | ||
1324 | #endif /* CONFIG_PMAC_PBOOK */ | ||
1325 | pmif->mediabay = 1; | ||
1326 | if (!bidp) | ||
1327 | pmif->aapl_bus_id = 1; | ||
1328 | } else if (pmif->kind == controller_ohare) { | ||
1329 | /* The code below is having trouble on some ohare machines | ||
1330 | * (timing related ?). Until I can put my hand on one of these | ||
1331 | * units, I keep the old way | ||
1332 | */ | ||
1333 | ppc_md.feature_call(PMAC_FTR_IDE_ENABLE, np, 0, 1); | ||
1334 | } else | ||
1335 | #endif | ||
1336 | { | ||
1337 | /* This is necessary to enable IDE when net-booting */ | ||
1338 | ppc_md.feature_call(PMAC_FTR_IDE_RESET, np, pmif->aapl_bus_id, 1); | ||
1339 | ppc_md.feature_call(PMAC_FTR_IDE_ENABLE, np, pmif->aapl_bus_id, 1); | ||
1340 | msleep(10); | ||
1341 | ppc_md.feature_call(PMAC_FTR_IDE_RESET, np, pmif->aapl_bus_id, 0); | ||
1342 | msleep(jiffies_to_msecs(IDE_WAKEUP_DELAY)); | ||
1343 | } | ||
1344 | |||
1345 | /* Setup MMIO ops */ | ||
1346 | default_hwif_mmiops(hwif); | ||
1347 | hwif->OUTBSYNC = pmac_outbsync; | ||
1348 | |||
1349 | /* Tell common code _not_ to mess with resources */ | ||
1350 | hwif->mmio = 2; | ||
1351 | hwif->hwif_data = pmif; | ||
1352 | pmac_ide_init_hwif_ports(&hwif->hw, pmif->regbase, 0, &hwif->irq); | ||
1353 | memcpy(hwif->io_ports, hwif->hw.io_ports, sizeof(hwif->io_ports)); | ||
1354 | hwif->chipset = ide_pmac; | ||
1355 | hwif->noprobe = !hwif->io_ports[IDE_DATA_OFFSET] || pmif->mediabay; | ||
1356 | hwif->hold = pmif->mediabay; | ||
1357 | hwif->udma_four = pmif->cable_80; | ||
1358 | hwif->drives[0].unmask = 1; | ||
1359 | hwif->drives[1].unmask = 1; | ||
1360 | hwif->tuneproc = pmac_ide_tuneproc; | ||
1361 | if (pmif->kind == controller_un_ata6 | ||
1362 | || pmif->kind == controller_k2_ata6 | ||
1363 | || pmif->kind == controller_sh_ata6) | ||
1364 | hwif->selectproc = pmac_ide_kauai_selectproc; | ||
1365 | else | ||
1366 | hwif->selectproc = pmac_ide_selectproc; | ||
1367 | hwif->speedproc = pmac_ide_tune_chipset; | ||
1368 | |||
1369 | #ifdef CONFIG_BLK_DEV_IDE_PMAC_BLINK | ||
1370 | pmu_ide_blink_enabled = pmu_hd_blink_init(); | ||
1371 | |||
1372 | if (pmu_ide_blink_enabled) | ||
1373 | hwif->led_act = pmu_hd_kick_blink; | ||
1374 | #endif | ||
1375 | |||
1376 | printk(KERN_INFO "ide%d: Found Apple %s controller, bus ID %d%s, irq %d\n", | ||
1377 | hwif->index, model_name[pmif->kind], pmif->aapl_bus_id, | ||
1378 | pmif->mediabay ? " (mediabay)" : "", hwif->irq); | ||
1379 | |||
1380 | #ifdef CONFIG_PMAC_PBOOK | ||
1381 | if (pmif->mediabay && check_media_bay_by_base(pmif->regbase, MB_CD) == 0) | ||
1382 | hwif->noprobe = 0; | ||
1383 | #endif /* CONFIG_PMAC_PBOOK */ | ||
1384 | |||
1385 | hwif->sg_max_nents = MAX_DCMDS; | ||
1386 | |||
1387 | #ifdef CONFIG_BLK_DEV_IDEDMA_PMAC | ||
1388 | /* has a DBDMA controller channel */ | ||
1389 | if (pmif->dma_regs) | ||
1390 | pmac_ide_setup_dma(pmif, hwif); | ||
1391 | #endif /* CONFIG_BLK_DEV_IDEDMA_PMAC */ | ||
1392 | |||
1393 | /* We probe the hwif now */ | ||
1394 | probe_hwif_init(hwif); | ||
1395 | |||
1396 | /* The code IDE code will have set hwif->present if we have devices attached, | ||
1397 | * if we don't, the discard the interface except if we are on a media bay slot | ||
1398 | */ | ||
1399 | if (!hwif->present && !pmif->mediabay) { | ||
1400 | printk(KERN_INFO "ide%d: Bus empty, interface released.\n", | ||
1401 | hwif->index); | ||
1402 | default_hwif_iops(hwif); | ||
1403 | for (i = IDE_DATA_OFFSET; i <= IDE_CONTROL_OFFSET; ++i) | ||
1404 | hwif->io_ports[i] = 0; | ||
1405 | hwif->chipset = ide_unknown; | ||
1406 | hwif->noprobe = 1; | ||
1407 | return -ENODEV; | ||
1408 | } | ||
1409 | |||
1410 | return 0; | ||
1411 | } | ||
1412 | |||
1413 | /* | ||
1414 | * Attach to a macio probed interface | ||
1415 | */ | ||
1416 | static int __devinit | ||
1417 | pmac_ide_macio_attach(struct macio_dev *mdev, const struct of_match *match) | ||
1418 | { | ||
1419 | void __iomem *base; | ||
1420 | unsigned long regbase; | ||
1421 | int irq; | ||
1422 | ide_hwif_t *hwif; | ||
1423 | pmac_ide_hwif_t *pmif; | ||
1424 | int i, rc; | ||
1425 | |||
1426 | i = 0; | ||
1427 | while (i < MAX_HWIFS && (ide_hwifs[i].io_ports[IDE_DATA_OFFSET] != 0 | ||
1428 | || pmac_ide[i].node != NULL)) | ||
1429 | ++i; | ||
1430 | if (i >= MAX_HWIFS) { | ||
1431 | printk(KERN_ERR "ide-pmac: MacIO interface attach with no slot\n"); | ||
1432 | printk(KERN_ERR " %s\n", mdev->ofdev.node->full_name); | ||
1433 | return -ENODEV; | ||
1434 | } | ||
1435 | |||
1436 | pmif = &pmac_ide[i]; | ||
1437 | hwif = &ide_hwifs[i]; | ||
1438 | |||
1439 | if (mdev->ofdev.node->n_addrs == 0) { | ||
1440 | printk(KERN_WARNING "ide%d: no address for %s\n", | ||
1441 | i, mdev->ofdev.node->full_name); | ||
1442 | return -ENXIO; | ||
1443 | } | ||
1444 | |||
1445 | /* Request memory resource for IO ports */ | ||
1446 | if (macio_request_resource(mdev, 0, "ide-pmac (ports)")) { | ||
1447 | printk(KERN_ERR "ide%d: can't request mmio resource !\n", i); | ||
1448 | return -EBUSY; | ||
1449 | } | ||
1450 | |||
1451 | /* XXX This is bogus. Should be fixed in the registry by checking | ||
1452 | * the kind of host interrupt controller, a bit like gatwick | ||
1453 | * fixes in irq.c. That works well enough for the single case | ||
1454 | * where that happens though... | ||
1455 | */ | ||
1456 | if (macio_irq_count(mdev) == 0) { | ||
1457 | printk(KERN_WARNING "ide%d: no intrs for device %s, using 13\n", | ||
1458 | i, mdev->ofdev.node->full_name); | ||
1459 | irq = 13; | ||
1460 | } else | ||
1461 | irq = macio_irq(mdev, 0); | ||
1462 | |||
1463 | base = ioremap(macio_resource_start(mdev, 0), 0x400); | ||
1464 | regbase = (unsigned long) base; | ||
1465 | |||
1466 | hwif->pci_dev = mdev->bus->pdev; | ||
1467 | hwif->gendev.parent = &mdev->ofdev.dev; | ||
1468 | |||
1469 | pmif->mdev = mdev; | ||
1470 | pmif->node = mdev->ofdev.node; | ||
1471 | pmif->regbase = regbase; | ||
1472 | pmif->irq = irq; | ||
1473 | pmif->kauai_fcr = NULL; | ||
1474 | #ifdef CONFIG_BLK_DEV_IDEDMA_PMAC | ||
1475 | if (macio_resource_count(mdev) >= 2) { | ||
1476 | if (macio_request_resource(mdev, 1, "ide-pmac (dma)")) | ||
1477 | printk(KERN_WARNING "ide%d: can't request DMA resource !\n", i); | ||
1478 | else | ||
1479 | pmif->dma_regs = ioremap(macio_resource_start(mdev, 1), 0x1000); | ||
1480 | } else | ||
1481 | pmif->dma_regs = NULL; | ||
1482 | #endif /* CONFIG_BLK_DEV_IDEDMA_PMAC */ | ||
1483 | dev_set_drvdata(&mdev->ofdev.dev, hwif); | ||
1484 | |||
1485 | rc = pmac_ide_setup_device(pmif, hwif); | ||
1486 | if (rc != 0) { | ||
1487 | /* The inteface is released to the common IDE layer */ | ||
1488 | dev_set_drvdata(&mdev->ofdev.dev, NULL); | ||
1489 | iounmap(base); | ||
1490 | if (pmif->dma_regs) | ||
1491 | iounmap(pmif->dma_regs); | ||
1492 | memset(pmif, 0, sizeof(*pmif)); | ||
1493 | macio_release_resource(mdev, 0); | ||
1494 | if (pmif->dma_regs) | ||
1495 | macio_release_resource(mdev, 1); | ||
1496 | } | ||
1497 | |||
1498 | return rc; | ||
1499 | } | ||
1500 | |||
1501 | static int | ||
1502 | pmac_ide_macio_suspend(struct macio_dev *mdev, u32 state) | ||
1503 | { | ||
1504 | ide_hwif_t *hwif = (ide_hwif_t *)dev_get_drvdata(&mdev->ofdev.dev); | ||
1505 | int rc = 0; | ||
1506 | |||
1507 | if (state != mdev->ofdev.dev.power.power_state && state >= 2) { | ||
1508 | rc = pmac_ide_do_suspend(hwif); | ||
1509 | if (rc == 0) | ||
1510 | mdev->ofdev.dev.power.power_state = state; | ||
1511 | } | ||
1512 | |||
1513 | return rc; | ||
1514 | } | ||
1515 | |||
1516 | static int | ||
1517 | pmac_ide_macio_resume(struct macio_dev *mdev) | ||
1518 | { | ||
1519 | ide_hwif_t *hwif = (ide_hwif_t *)dev_get_drvdata(&mdev->ofdev.dev); | ||
1520 | int rc = 0; | ||
1521 | |||
1522 | if (mdev->ofdev.dev.power.power_state != 0) { | ||
1523 | rc = pmac_ide_do_resume(hwif); | ||
1524 | if (rc == 0) | ||
1525 | mdev->ofdev.dev.power.power_state = 0; | ||
1526 | } | ||
1527 | |||
1528 | return rc; | ||
1529 | } | ||
1530 | |||
1531 | /* | ||
1532 | * Attach to a PCI probed interface | ||
1533 | */ | ||
1534 | static int __devinit | ||
1535 | pmac_ide_pci_attach(struct pci_dev *pdev, const struct pci_device_id *id) | ||
1536 | { | ||
1537 | ide_hwif_t *hwif; | ||
1538 | struct device_node *np; | ||
1539 | pmac_ide_hwif_t *pmif; | ||
1540 | void __iomem *base; | ||
1541 | unsigned long rbase, rlen; | ||
1542 | int i, rc; | ||
1543 | |||
1544 | np = pci_device_to_OF_node(pdev); | ||
1545 | if (np == NULL) { | ||
1546 | printk(KERN_ERR "ide-pmac: cannot find MacIO node for Kauai ATA interface\n"); | ||
1547 | return -ENODEV; | ||
1548 | } | ||
1549 | i = 0; | ||
1550 | while (i < MAX_HWIFS && (ide_hwifs[i].io_ports[IDE_DATA_OFFSET] != 0 | ||
1551 | || pmac_ide[i].node != NULL)) | ||
1552 | ++i; | ||
1553 | if (i >= MAX_HWIFS) { | ||
1554 | printk(KERN_ERR "ide-pmac: PCI interface attach with no slot\n"); | ||
1555 | printk(KERN_ERR " %s\n", np->full_name); | ||
1556 | return -ENODEV; | ||
1557 | } | ||
1558 | |||
1559 | pmif = &pmac_ide[i]; | ||
1560 | hwif = &ide_hwifs[i]; | ||
1561 | |||
1562 | if (pci_enable_device(pdev)) { | ||
1563 | printk(KERN_WARNING "ide%i: Can't enable PCI device for %s\n", | ||
1564 | i, np->full_name); | ||
1565 | return -ENXIO; | ||
1566 | } | ||
1567 | pci_set_master(pdev); | ||
1568 | |||
1569 | if (pci_request_regions(pdev, "Kauai ATA")) { | ||
1570 | printk(KERN_ERR "ide%d: Cannot obtain PCI resources for %s\n", | ||
1571 | i, np->full_name); | ||
1572 | return -ENXIO; | ||
1573 | } | ||
1574 | |||
1575 | hwif->pci_dev = pdev; | ||
1576 | hwif->gendev.parent = &pdev->dev; | ||
1577 | pmif->mdev = NULL; | ||
1578 | pmif->node = np; | ||
1579 | |||
1580 | rbase = pci_resource_start(pdev, 0); | ||
1581 | rlen = pci_resource_len(pdev, 0); | ||
1582 | |||
1583 | base = ioremap(rbase, rlen); | ||
1584 | pmif->regbase = (unsigned long) base + 0x2000; | ||
1585 | #ifdef CONFIG_BLK_DEV_IDEDMA_PMAC | ||
1586 | pmif->dma_regs = base + 0x1000; | ||
1587 | #endif /* CONFIG_BLK_DEV_IDEDMA_PMAC */ | ||
1588 | pmif->kauai_fcr = base; | ||
1589 | pmif->irq = pdev->irq; | ||
1590 | |||
1591 | pci_set_drvdata(pdev, hwif); | ||
1592 | |||
1593 | rc = pmac_ide_setup_device(pmif, hwif); | ||
1594 | if (rc != 0) { | ||
1595 | /* The inteface is released to the common IDE layer */ | ||
1596 | pci_set_drvdata(pdev, NULL); | ||
1597 | iounmap(base); | ||
1598 | memset(pmif, 0, sizeof(*pmif)); | ||
1599 | pci_release_regions(pdev); | ||
1600 | } | ||
1601 | |||
1602 | return rc; | ||
1603 | } | ||
1604 | |||
1605 | static int | ||
1606 | pmac_ide_pci_suspend(struct pci_dev *pdev, u32 state) | ||
1607 | { | ||
1608 | ide_hwif_t *hwif = (ide_hwif_t *)pci_get_drvdata(pdev); | ||
1609 | int rc = 0; | ||
1610 | |||
1611 | if (state != pdev->dev.power.power_state && state >= 2) { | ||
1612 | rc = pmac_ide_do_suspend(hwif); | ||
1613 | if (rc == 0) | ||
1614 | pdev->dev.power.power_state = state; | ||
1615 | } | ||
1616 | |||
1617 | return rc; | ||
1618 | } | ||
1619 | |||
1620 | static int | ||
1621 | pmac_ide_pci_resume(struct pci_dev *pdev) | ||
1622 | { | ||
1623 | ide_hwif_t *hwif = (ide_hwif_t *)pci_get_drvdata(pdev); | ||
1624 | int rc = 0; | ||
1625 | |||
1626 | if (pdev->dev.power.power_state != 0) { | ||
1627 | rc = pmac_ide_do_resume(hwif); | ||
1628 | if (rc == 0) | ||
1629 | pdev->dev.power.power_state = 0; | ||
1630 | } | ||
1631 | |||
1632 | return rc; | ||
1633 | } | ||
1634 | |||
1635 | static struct of_match pmac_ide_macio_match[] = | ||
1636 | { | ||
1637 | { | ||
1638 | .name = "IDE", | ||
1639 | .type = OF_ANY_MATCH, | ||
1640 | .compatible = OF_ANY_MATCH | ||
1641 | }, | ||
1642 | { | ||
1643 | .name = "ATA", | ||
1644 | .type = OF_ANY_MATCH, | ||
1645 | .compatible = OF_ANY_MATCH | ||
1646 | }, | ||
1647 | { | ||
1648 | .name = OF_ANY_MATCH, | ||
1649 | .type = "ide", | ||
1650 | .compatible = OF_ANY_MATCH | ||
1651 | }, | ||
1652 | { | ||
1653 | .name = OF_ANY_MATCH, | ||
1654 | .type = "ata", | ||
1655 | .compatible = OF_ANY_MATCH | ||
1656 | }, | ||
1657 | {}, | ||
1658 | }; | ||
1659 | |||
1660 | static struct macio_driver pmac_ide_macio_driver = | ||
1661 | { | ||
1662 | .name = "ide-pmac", | ||
1663 | .match_table = pmac_ide_macio_match, | ||
1664 | .probe = pmac_ide_macio_attach, | ||
1665 | .suspend = pmac_ide_macio_suspend, | ||
1666 | .resume = pmac_ide_macio_resume, | ||
1667 | }; | ||
1668 | |||
1669 | static struct pci_device_id pmac_ide_pci_match[] = { | ||
1670 | { PCI_VENDOR_ID_APPLE, PCI_DEVIEC_ID_APPLE_UNI_N_ATA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, | ||
1671 | { PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_IPID_ATA100, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, | ||
1672 | { PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_K2_ATA100, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, | ||
1673 | { PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_SH_ATA, | ||
1674 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, | ||
1675 | }; | ||
1676 | |||
1677 | static struct pci_driver pmac_ide_pci_driver = { | ||
1678 | .name = "ide-pmac", | ||
1679 | .id_table = pmac_ide_pci_match, | ||
1680 | .probe = pmac_ide_pci_attach, | ||
1681 | .suspend = pmac_ide_pci_suspend, | ||
1682 | .resume = pmac_ide_pci_resume, | ||
1683 | }; | ||
1684 | MODULE_DEVICE_TABLE(pci, pmac_ide_pci_match); | ||
1685 | |||
1686 | void __init | ||
1687 | pmac_ide_probe(void) | ||
1688 | { | ||
1689 | if (_machine != _MACH_Pmac) | ||
1690 | return; | ||
1691 | |||
1692 | #ifdef CONFIG_BLK_DEV_IDE_PMAC_ATA100FIRST | ||
1693 | pci_register_driver(&pmac_ide_pci_driver); | ||
1694 | macio_register_driver(&pmac_ide_macio_driver); | ||
1695 | #else | ||
1696 | macio_register_driver(&pmac_ide_macio_driver); | ||
1697 | pci_register_driver(&pmac_ide_pci_driver); | ||
1698 | #endif | ||
1699 | } | ||
1700 | |||
1701 | #ifdef CONFIG_BLK_DEV_IDEDMA_PMAC | ||
1702 | |||
1703 | /* | ||
1704 | * pmac_ide_build_dmatable builds the DBDMA command list | ||
1705 | * for a transfer and sets the DBDMA channel to point to it. | ||
1706 | */ | ||
1707 | static int __pmac | ||
1708 | pmac_ide_build_dmatable(ide_drive_t *drive, struct request *rq) | ||
1709 | { | ||
1710 | struct dbdma_cmd *table; | ||
1711 | int i, count = 0; | ||
1712 | ide_hwif_t *hwif = HWIF(drive); | ||
1713 | pmac_ide_hwif_t* pmif = (pmac_ide_hwif_t *)hwif->hwif_data; | ||
1714 | volatile struct dbdma_regs __iomem *dma = pmif->dma_regs; | ||
1715 | struct scatterlist *sg; | ||
1716 | int wr = (rq_data_dir(rq) == WRITE); | ||
1717 | |||
1718 | /* DMA table is already aligned */ | ||
1719 | table = (struct dbdma_cmd *) pmif->dma_table_cpu; | ||
1720 | |||
1721 | /* Make sure DMA controller is stopped (necessary ?) */ | ||
1722 | writel((RUN|PAUSE|FLUSH|WAKE|DEAD) << 16, &dma->control); | ||
1723 | while (readl(&dma->status) & RUN) | ||
1724 | udelay(1); | ||
1725 | |||
1726 | hwif->sg_nents = i = ide_build_sglist(drive, rq); | ||
1727 | |||
1728 | if (!i) | ||
1729 | return 0; | ||
1730 | |||
1731 | /* Build DBDMA commands list */ | ||
1732 | sg = hwif->sg_table; | ||
1733 | while (i && sg_dma_len(sg)) { | ||
1734 | u32 cur_addr; | ||
1735 | u32 cur_len; | ||
1736 | |||
1737 | cur_addr = sg_dma_address(sg); | ||
1738 | cur_len = sg_dma_len(sg); | ||
1739 | |||
1740 | if (pmif->broken_dma && cur_addr & (L1_CACHE_BYTES - 1)) { | ||
1741 | if (pmif->broken_dma_warn == 0) { | ||
1742 | printk(KERN_WARNING "%s: DMA on non aligned address," | ||
1743 | "switching to PIO on Ohare chipset\n", drive->name); | ||
1744 | pmif->broken_dma_warn = 1; | ||
1745 | } | ||
1746 | goto use_pio_instead; | ||
1747 | } | ||
1748 | while (cur_len) { | ||
1749 | unsigned int tc = (cur_len < 0xfe00)? cur_len: 0xfe00; | ||
1750 | |||
1751 | if (count++ >= MAX_DCMDS) { | ||
1752 | printk(KERN_WARNING "%s: DMA table too small\n", | ||
1753 | drive->name); | ||
1754 | goto use_pio_instead; | ||
1755 | } | ||
1756 | st_le16(&table->command, wr? OUTPUT_MORE: INPUT_MORE); | ||
1757 | st_le16(&table->req_count, tc); | ||
1758 | st_le32(&table->phy_addr, cur_addr); | ||
1759 | table->cmd_dep = 0; | ||
1760 | table->xfer_status = 0; | ||
1761 | table->res_count = 0; | ||
1762 | cur_addr += tc; | ||
1763 | cur_len -= tc; | ||
1764 | ++table; | ||
1765 | } | ||
1766 | sg++; | ||
1767 | i--; | ||
1768 | } | ||
1769 | |||
1770 | /* convert the last command to an input/output last command */ | ||
1771 | if (count) { | ||
1772 | st_le16(&table[-1].command, wr? OUTPUT_LAST: INPUT_LAST); | ||
1773 | /* add the stop command to the end of the list */ | ||
1774 | memset(table, 0, sizeof(struct dbdma_cmd)); | ||
1775 | st_le16(&table->command, DBDMA_STOP); | ||
1776 | mb(); | ||
1777 | writel(hwif->dmatable_dma, &dma->cmdptr); | ||
1778 | return 1; | ||
1779 | } | ||
1780 | |||
1781 | printk(KERN_DEBUG "%s: empty DMA table?\n", drive->name); | ||
1782 | use_pio_instead: | ||
1783 | pci_unmap_sg(hwif->pci_dev, | ||
1784 | hwif->sg_table, | ||
1785 | hwif->sg_nents, | ||
1786 | hwif->sg_dma_direction); | ||
1787 | return 0; /* revert to PIO for this request */ | ||
1788 | } | ||
1789 | |||
1790 | /* Teardown mappings after DMA has completed. */ | ||
1791 | static void __pmac | ||
1792 | pmac_ide_destroy_dmatable (ide_drive_t *drive) | ||
1793 | { | ||
1794 | ide_hwif_t *hwif = drive->hwif; | ||
1795 | struct pci_dev *dev = HWIF(drive)->pci_dev; | ||
1796 | struct scatterlist *sg = hwif->sg_table; | ||
1797 | int nents = hwif->sg_nents; | ||
1798 | |||
1799 | if (nents) { | ||
1800 | pci_unmap_sg(dev, sg, nents, hwif->sg_dma_direction); | ||
1801 | hwif->sg_nents = 0; | ||
1802 | } | ||
1803 | } | ||
1804 | |||
1805 | /* | ||
1806 | * Pick up best MDMA timing for the drive and apply it | ||
1807 | */ | ||
1808 | static int __pmac | ||
1809 | pmac_ide_mdma_enable(ide_drive_t *drive, u16 mode) | ||
1810 | { | ||
1811 | ide_hwif_t *hwif = HWIF(drive); | ||
1812 | pmac_ide_hwif_t* pmif = (pmac_ide_hwif_t *)hwif->hwif_data; | ||
1813 | int drive_cycle_time; | ||
1814 | struct hd_driveid *id = drive->id; | ||
1815 | u32 *timings, *timings2; | ||
1816 | u32 timing_local[2]; | ||
1817 | int ret; | ||
1818 | |||
1819 | /* which drive is it ? */ | ||
1820 | timings = &pmif->timings[drive->select.b.unit & 0x01]; | ||
1821 | timings2 = &pmif->timings[(drive->select.b.unit & 0x01) + 2]; | ||
1822 | |||
1823 | /* Check if drive provide explicit cycle time */ | ||
1824 | if ((id->field_valid & 2) && (id->eide_dma_time)) | ||
1825 | drive_cycle_time = id->eide_dma_time; | ||
1826 | else | ||
1827 | drive_cycle_time = 0; | ||
1828 | |||
1829 | /* Copy timings to local image */ | ||
1830 | timing_local[0] = *timings; | ||
1831 | timing_local[1] = *timings2; | ||
1832 | |||
1833 | /* Calculate controller timings */ | ||
1834 | ret = set_timings_mdma( drive, pmif->kind, | ||
1835 | &timing_local[0], | ||
1836 | &timing_local[1], | ||
1837 | mode, | ||
1838 | drive_cycle_time); | ||
1839 | if (ret) | ||
1840 | return 0; | ||
1841 | |||
1842 | /* Set feature on drive */ | ||
1843 | printk(KERN_INFO "%s: Enabling MultiWord DMA %d\n", drive->name, mode & 0xf); | ||
1844 | ret = pmac_ide_do_setfeature(drive, mode); | ||
1845 | if (ret) { | ||
1846 | printk(KERN_WARNING "%s: Failed !\n", drive->name); | ||
1847 | return 0; | ||
1848 | } | ||
1849 | |||
1850 | /* Apply timings to controller */ | ||
1851 | *timings = timing_local[0]; | ||
1852 | *timings2 = timing_local[1]; | ||
1853 | |||
1854 | /* Set speed info in drive */ | ||
1855 | drive->current_speed = mode; | ||
1856 | if (!drive->init_speed) | ||
1857 | drive->init_speed = mode; | ||
1858 | |||
1859 | return 1; | ||
1860 | } | ||
1861 | |||
1862 | /* | ||
1863 | * Pick up best UDMA timing for the drive and apply it | ||
1864 | */ | ||
1865 | static int __pmac | ||
1866 | pmac_ide_udma_enable(ide_drive_t *drive, u16 mode) | ||
1867 | { | ||
1868 | ide_hwif_t *hwif = HWIF(drive); | ||
1869 | pmac_ide_hwif_t* pmif = (pmac_ide_hwif_t *)hwif->hwif_data; | ||
1870 | u32 *timings, *timings2; | ||
1871 | u32 timing_local[2]; | ||
1872 | int ret; | ||
1873 | |||
1874 | /* which drive is it ? */ | ||
1875 | timings = &pmif->timings[drive->select.b.unit & 0x01]; | ||
1876 | timings2 = &pmif->timings[(drive->select.b.unit & 0x01) + 2]; | ||
1877 | |||
1878 | /* Copy timings to local image */ | ||
1879 | timing_local[0] = *timings; | ||
1880 | timing_local[1] = *timings2; | ||
1881 | |||
1882 | /* Calculate timings for interface */ | ||
1883 | if (pmif->kind == controller_un_ata6 | ||
1884 | || pmif->kind == controller_k2_ata6) | ||
1885 | ret = set_timings_udma_ata6( &timing_local[0], | ||
1886 | &timing_local[1], | ||
1887 | mode); | ||
1888 | else if (pmif->kind == controller_sh_ata6) | ||
1889 | ret = set_timings_udma_shasta( &timing_local[0], | ||
1890 | &timing_local[1], | ||
1891 | mode); | ||
1892 | else | ||
1893 | ret = set_timings_udma_ata4(&timing_local[0], mode); | ||
1894 | if (ret) | ||
1895 | return 0; | ||
1896 | |||
1897 | /* Set feature on drive */ | ||
1898 | printk(KERN_INFO "%s: Enabling Ultra DMA %d\n", drive->name, mode & 0x0f); | ||
1899 | ret = pmac_ide_do_setfeature(drive, mode); | ||
1900 | if (ret) { | ||
1901 | printk(KERN_WARNING "%s: Failed !\n", drive->name); | ||
1902 | return 0; | ||
1903 | } | ||
1904 | |||
1905 | /* Apply timings to controller */ | ||
1906 | *timings = timing_local[0]; | ||
1907 | *timings2 = timing_local[1]; | ||
1908 | |||
1909 | /* Set speed info in drive */ | ||
1910 | drive->current_speed = mode; | ||
1911 | if (!drive->init_speed) | ||
1912 | drive->init_speed = mode; | ||
1913 | |||
1914 | return 1; | ||
1915 | } | ||
1916 | |||
1917 | /* | ||
1918 | * Check what is the best DMA timing setting for the drive and | ||
1919 | * call appropriate functions to apply it. | ||
1920 | */ | ||
1921 | static int __pmac | ||
1922 | pmac_ide_dma_check(ide_drive_t *drive) | ||
1923 | { | ||
1924 | struct hd_driveid *id = drive->id; | ||
1925 | ide_hwif_t *hwif = HWIF(drive); | ||
1926 | pmac_ide_hwif_t* pmif = (pmac_ide_hwif_t *)hwif->hwif_data; | ||
1927 | int enable = 1; | ||
1928 | int map; | ||
1929 | drive->using_dma = 0; | ||
1930 | |||
1931 | if (drive->media == ide_floppy) | ||
1932 | enable = 0; | ||
1933 | if (((id->capability & 1) == 0) && !__ide_dma_good_drive(drive)) | ||
1934 | enable = 0; | ||
1935 | if (__ide_dma_bad_drive(drive)) | ||
1936 | enable = 0; | ||
1937 | |||
1938 | if (enable) { | ||
1939 | short mode; | ||
1940 | |||
1941 | map = XFER_MWDMA; | ||
1942 | if (pmif->kind == controller_kl_ata4 | ||
1943 | || pmif->kind == controller_un_ata6 | ||
1944 | || pmif->kind == controller_k2_ata6 | ||
1945 | || pmif->kind == controller_sh_ata6) { | ||
1946 | map |= XFER_UDMA; | ||
1947 | if (pmif->cable_80) { | ||
1948 | map |= XFER_UDMA_66; | ||
1949 | if (pmif->kind == controller_un_ata6 || | ||
1950 | pmif->kind == controller_k2_ata6 || | ||
1951 | pmif->kind == controller_sh_ata6) | ||
1952 | map |= XFER_UDMA_100; | ||
1953 | if (pmif->kind == controller_sh_ata6) | ||
1954 | map |= XFER_UDMA_133; | ||
1955 | } | ||
1956 | } | ||
1957 | mode = ide_find_best_mode(drive, map); | ||
1958 | if (mode & XFER_UDMA) | ||
1959 | drive->using_dma = pmac_ide_udma_enable(drive, mode); | ||
1960 | else if (mode & XFER_MWDMA) | ||
1961 | drive->using_dma = pmac_ide_mdma_enable(drive, mode); | ||
1962 | hwif->OUTB(0, IDE_CONTROL_REG); | ||
1963 | /* Apply settings to controller */ | ||
1964 | pmac_ide_do_update_timings(drive); | ||
1965 | } | ||
1966 | return 0; | ||
1967 | } | ||
1968 | |||
1969 | /* | ||
1970 | * Prepare a DMA transfer. We build the DMA table, adjust the timings for | ||
1971 | * a read on KeyLargo ATA/66 and mark us as waiting for DMA completion | ||
1972 | */ | ||
1973 | static int __pmac | ||
1974 | pmac_ide_dma_setup(ide_drive_t *drive) | ||
1975 | { | ||
1976 | ide_hwif_t *hwif = HWIF(drive); | ||
1977 | pmac_ide_hwif_t* pmif = (pmac_ide_hwif_t *)hwif->hwif_data; | ||
1978 | struct request *rq = HWGROUP(drive)->rq; | ||
1979 | u8 unit = (drive->select.b.unit & 0x01); | ||
1980 | u8 ata4; | ||
1981 | |||
1982 | if (pmif == NULL) | ||
1983 | return 1; | ||
1984 | ata4 = (pmif->kind == controller_kl_ata4); | ||
1985 | |||
1986 | if (!pmac_ide_build_dmatable(drive, rq)) { | ||
1987 | ide_map_sg(drive, rq); | ||
1988 | return 1; | ||
1989 | } | ||
1990 | |||
1991 | /* Apple adds 60ns to wrDataSetup on reads */ | ||
1992 | if (ata4 && (pmif->timings[unit] & TR_66_UDMA_EN)) { | ||
1993 | writel(pmif->timings[unit] + (!rq_data_dir(rq) ? 0x00800000UL : 0), | ||
1994 | PMAC_IDE_REG(IDE_TIMING_CONFIG)); | ||
1995 | (void)readl(PMAC_IDE_REG(IDE_TIMING_CONFIG)); | ||
1996 | } | ||
1997 | |||
1998 | drive->waiting_for_dma = 1; | ||
1999 | |||
2000 | return 0; | ||
2001 | } | ||
2002 | |||
2003 | static void __pmac | ||
2004 | pmac_ide_dma_exec_cmd(ide_drive_t *drive, u8 command) | ||
2005 | { | ||
2006 | /* issue cmd to drive */ | ||
2007 | ide_execute_command(drive, command, &ide_dma_intr, 2*WAIT_CMD, NULL); | ||
2008 | } | ||
2009 | |||
2010 | /* | ||
2011 | * Kick the DMA controller into life after the DMA command has been issued | ||
2012 | * to the drive. | ||
2013 | */ | ||
2014 | static void __pmac | ||
2015 | pmac_ide_dma_start(ide_drive_t *drive) | ||
2016 | { | ||
2017 | pmac_ide_hwif_t* pmif = (pmac_ide_hwif_t *)HWIF(drive)->hwif_data; | ||
2018 | volatile struct dbdma_regs __iomem *dma; | ||
2019 | |||
2020 | dma = pmif->dma_regs; | ||
2021 | |||
2022 | writel((RUN << 16) | RUN, &dma->control); | ||
2023 | /* Make sure it gets to the controller right now */ | ||
2024 | (void)readl(&dma->control); | ||
2025 | } | ||
2026 | |||
2027 | /* | ||
2028 | * After a DMA transfer, make sure the controller is stopped | ||
2029 | */ | ||
2030 | static int __pmac | ||
2031 | pmac_ide_dma_end (ide_drive_t *drive) | ||
2032 | { | ||
2033 | pmac_ide_hwif_t* pmif = (pmac_ide_hwif_t *)HWIF(drive)->hwif_data; | ||
2034 | volatile struct dbdma_regs __iomem *dma; | ||
2035 | u32 dstat; | ||
2036 | |||
2037 | if (pmif == NULL) | ||
2038 | return 0; | ||
2039 | dma = pmif->dma_regs; | ||
2040 | |||
2041 | drive->waiting_for_dma = 0; | ||
2042 | dstat = readl(&dma->status); | ||
2043 | writel(((RUN|WAKE|DEAD) << 16), &dma->control); | ||
2044 | pmac_ide_destroy_dmatable(drive); | ||
2045 | /* verify good dma status. we don't check for ACTIVE beeing 0. We should... | ||
2046 | * in theory, but with ATAPI decices doing buffer underruns, that would | ||
2047 | * cause us to disable DMA, which isn't what we want | ||
2048 | */ | ||
2049 | return (dstat & (RUN|DEAD)) != RUN; | ||
2050 | } | ||
2051 | |||
2052 | /* | ||
2053 | * Check out that the interrupt we got was for us. We can't always know this | ||
2054 | * for sure with those Apple interfaces (well, we could on the recent ones but | ||
2055 | * that's not implemented yet), on the other hand, we don't have shared interrupts | ||
2056 | * so it's not really a problem | ||
2057 | */ | ||
2058 | static int __pmac | ||
2059 | pmac_ide_dma_test_irq (ide_drive_t *drive) | ||
2060 | { | ||
2061 | pmac_ide_hwif_t* pmif = (pmac_ide_hwif_t *)HWIF(drive)->hwif_data; | ||
2062 | volatile struct dbdma_regs __iomem *dma; | ||
2063 | unsigned long status, timeout; | ||
2064 | |||
2065 | if (pmif == NULL) | ||
2066 | return 0; | ||
2067 | dma = pmif->dma_regs; | ||
2068 | |||
2069 | /* We have to things to deal with here: | ||
2070 | * | ||
2071 | * - The dbdma won't stop if the command was started | ||
2072 | * but completed with an error without transferring all | ||
2073 | * datas. This happens when bad blocks are met during | ||
2074 | * a multi-block transfer. | ||
2075 | * | ||
2076 | * - The dbdma fifo hasn't yet finished flushing to | ||
2077 | * to system memory when the disk interrupt occurs. | ||
2078 | * | ||
2079 | */ | ||
2080 | |||
2081 | /* If ACTIVE is cleared, the STOP command have passed and | ||
2082 | * transfer is complete. | ||
2083 | */ | ||
2084 | status = readl(&dma->status); | ||
2085 | if (!(status & ACTIVE)) | ||
2086 | return 1; | ||
2087 | if (!drive->waiting_for_dma) | ||
2088 | printk(KERN_WARNING "ide%d, ide_dma_test_irq \ | ||
2089 | called while not waiting\n", HWIF(drive)->index); | ||
2090 | |||
2091 | /* If dbdma didn't execute the STOP command yet, the | ||
2092 | * active bit is still set. We consider that we aren't | ||
2093 | * sharing interrupts (which is hopefully the case with | ||
2094 | * those controllers) and so we just try to flush the | ||
2095 | * channel for pending data in the fifo | ||
2096 | */ | ||
2097 | udelay(1); | ||
2098 | writel((FLUSH << 16) | FLUSH, &dma->control); | ||
2099 | timeout = 0; | ||
2100 | for (;;) { | ||
2101 | udelay(1); | ||
2102 | status = readl(&dma->status); | ||
2103 | if ((status & FLUSH) == 0) | ||
2104 | break; | ||
2105 | if (++timeout > 100) { | ||
2106 | printk(KERN_WARNING "ide%d, ide_dma_test_irq \ | ||
2107 | timeout flushing channel\n", HWIF(drive)->index); | ||
2108 | break; | ||
2109 | } | ||
2110 | } | ||
2111 | return 1; | ||
2112 | } | ||
2113 | |||
2114 | static int __pmac | ||
2115 | pmac_ide_dma_host_off (ide_drive_t *drive) | ||
2116 | { | ||
2117 | return 0; | ||
2118 | } | ||
2119 | |||
2120 | static int __pmac | ||
2121 | pmac_ide_dma_host_on (ide_drive_t *drive) | ||
2122 | { | ||
2123 | return 0; | ||
2124 | } | ||
2125 | |||
2126 | static int __pmac | ||
2127 | pmac_ide_dma_lostirq (ide_drive_t *drive) | ||
2128 | { | ||
2129 | pmac_ide_hwif_t* pmif = (pmac_ide_hwif_t *)HWIF(drive)->hwif_data; | ||
2130 | volatile struct dbdma_regs __iomem *dma; | ||
2131 | unsigned long status; | ||
2132 | |||
2133 | if (pmif == NULL) | ||
2134 | return 0; | ||
2135 | dma = pmif->dma_regs; | ||
2136 | |||
2137 | status = readl(&dma->status); | ||
2138 | printk(KERN_ERR "ide-pmac lost interrupt, dma status: %lx\n", status); | ||
2139 | return 0; | ||
2140 | } | ||
2141 | |||
2142 | /* | ||
2143 | * Allocate the data structures needed for using DMA with an interface | ||
2144 | * and fill the proper list of functions pointers | ||
2145 | */ | ||
2146 | static void __init | ||
2147 | pmac_ide_setup_dma(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif) | ||
2148 | { | ||
2149 | /* We won't need pci_dev if we switch to generic consistent | ||
2150 | * DMA routines ... | ||
2151 | */ | ||
2152 | if (hwif->pci_dev == NULL) | ||
2153 | return; | ||
2154 | /* | ||
2155 | * Allocate space for the DBDMA commands. | ||
2156 | * The +2 is +1 for the stop command and +1 to allow for | ||
2157 | * aligning the start address to a multiple of 16 bytes. | ||
2158 | */ | ||
2159 | pmif->dma_table_cpu = (struct dbdma_cmd*)pci_alloc_consistent( | ||
2160 | hwif->pci_dev, | ||
2161 | (MAX_DCMDS + 2) * sizeof(struct dbdma_cmd), | ||
2162 | &hwif->dmatable_dma); | ||
2163 | if (pmif->dma_table_cpu == NULL) { | ||
2164 | printk(KERN_ERR "%s: unable to allocate DMA command list\n", | ||
2165 | hwif->name); | ||
2166 | return; | ||
2167 | } | ||
2168 | |||
2169 | hwif->ide_dma_off_quietly = &__ide_dma_off_quietly; | ||
2170 | hwif->ide_dma_on = &__ide_dma_on; | ||
2171 | hwif->ide_dma_check = &pmac_ide_dma_check; | ||
2172 | hwif->dma_setup = &pmac_ide_dma_setup; | ||
2173 | hwif->dma_exec_cmd = &pmac_ide_dma_exec_cmd; | ||
2174 | hwif->dma_start = &pmac_ide_dma_start; | ||
2175 | hwif->ide_dma_end = &pmac_ide_dma_end; | ||
2176 | hwif->ide_dma_test_irq = &pmac_ide_dma_test_irq; | ||
2177 | hwif->ide_dma_host_off = &pmac_ide_dma_host_off; | ||
2178 | hwif->ide_dma_host_on = &pmac_ide_dma_host_on; | ||
2179 | hwif->ide_dma_timeout = &__ide_dma_timeout; | ||
2180 | hwif->ide_dma_lostirq = &pmac_ide_dma_lostirq; | ||
2181 | |||
2182 | hwif->atapi_dma = 1; | ||
2183 | switch(pmif->kind) { | ||
2184 | case controller_sh_ata6: | ||
2185 | hwif->ultra_mask = pmif->cable_80 ? 0x7f : 0x07; | ||
2186 | hwif->mwdma_mask = 0x07; | ||
2187 | hwif->swdma_mask = 0x00; | ||
2188 | break; | ||
2189 | case controller_un_ata6: | ||
2190 | case controller_k2_ata6: | ||
2191 | hwif->ultra_mask = pmif->cable_80 ? 0x3f : 0x07; | ||
2192 | hwif->mwdma_mask = 0x07; | ||
2193 | hwif->swdma_mask = 0x00; | ||
2194 | break; | ||
2195 | case controller_kl_ata4: | ||
2196 | hwif->ultra_mask = pmif->cable_80 ? 0x1f : 0x07; | ||
2197 | hwif->mwdma_mask = 0x07; | ||
2198 | hwif->swdma_mask = 0x00; | ||
2199 | break; | ||
2200 | default: | ||
2201 | hwif->ultra_mask = 0x00; | ||
2202 | hwif->mwdma_mask = 0x07; | ||
2203 | hwif->swdma_mask = 0x00; | ||
2204 | break; | ||
2205 | } | ||
2206 | } | ||
2207 | |||
2208 | #endif /* CONFIG_BLK_DEV_IDEDMA_PMAC */ | ||
diff --git a/drivers/ide/setup-pci.c b/drivers/ide/setup-pci.c new file mode 100644 index 000000000000..e501675ad72e --- /dev/null +++ b/drivers/ide/setup-pci.c | |||
@@ -0,0 +1,901 @@ | |||
1 | /* | ||
2 | * linux/drivers/ide/setup-pci.c Version 1.10 2002/08/19 | ||
3 | * | ||
4 | * Copyright (c) 1998-2000 Andre Hedrick <andre@linux-ide.org> | ||
5 | * | ||
6 | * Copyright (c) 1995-1998 Mark Lord | ||
7 | * May be copied or modified under the terms of the GNU General Public License | ||
8 | * | ||
9 | * Recent Changes | ||
10 | * Split the set up function into multiple functions | ||
11 | * Use pci_set_master | ||
12 | * Fix misreporting of I/O v MMIO problems | ||
13 | * Initial fixups for simplex devices | ||
14 | */ | ||
15 | |||
16 | /* | ||
17 | * This module provides support for automatic detection and | ||
18 | * configuration of all PCI IDE interfaces present in a system. | ||
19 | */ | ||
20 | |||
21 | #include <linux/config.h> | ||
22 | #include <linux/module.h> | ||
23 | #include <linux/types.h> | ||
24 | #include <linux/kernel.h> | ||
25 | #include <linux/pci.h> | ||
26 | #include <linux/init.h> | ||
27 | #include <linux/timer.h> | ||
28 | #include <linux/mm.h> | ||
29 | #include <linux/interrupt.h> | ||
30 | #include <linux/ide.h> | ||
31 | #include <linux/dma-mapping.h> | ||
32 | |||
33 | #include <asm/io.h> | ||
34 | #include <asm/irq.h> | ||
35 | |||
36 | |||
37 | /** | ||
38 | * ide_match_hwif - match a PCI IDE against an ide_hwif | ||
39 | * @io_base: I/O base of device | ||
40 | * @bootable: set if its bootable | ||
41 | * @name: name of device | ||
42 | * | ||
43 | * Match a PCI IDE port against an entry in ide_hwifs[], | ||
44 | * based on io_base port if possible. Return the matching hwif, | ||
45 | * or a new hwif. If we find an error (clashing, out of devices, etc) | ||
46 | * return NULL | ||
47 | * | ||
48 | * FIXME: we need to handle mmio matches here too | ||
49 | */ | ||
50 | |||
51 | static ide_hwif_t *ide_match_hwif(unsigned long io_base, u8 bootable, const char *name) | ||
52 | { | ||
53 | int h; | ||
54 | ide_hwif_t *hwif; | ||
55 | |||
56 | /* | ||
57 | * Look for a hwif with matching io_base specified using | ||
58 | * parameters to ide_setup(). | ||
59 | */ | ||
60 | for (h = 0; h < MAX_HWIFS; ++h) { | ||
61 | hwif = &ide_hwifs[h]; | ||
62 | if (hwif->io_ports[IDE_DATA_OFFSET] == io_base) { | ||
63 | if (hwif->chipset == ide_forced) | ||
64 | return hwif; /* a perfect match */ | ||
65 | } | ||
66 | } | ||
67 | /* | ||
68 | * Look for a hwif with matching io_base default value. | ||
69 | * If chipset is "ide_unknown", then claim that hwif slot. | ||
70 | * Otherwise, some other chipset has already claimed it.. :( | ||
71 | */ | ||
72 | for (h = 0; h < MAX_HWIFS; ++h) { | ||
73 | hwif = &ide_hwifs[h]; | ||
74 | if (hwif->io_ports[IDE_DATA_OFFSET] == io_base) { | ||
75 | if (hwif->chipset == ide_unknown) | ||
76 | return hwif; /* match */ | ||
77 | printk(KERN_ERR "%s: port 0x%04lx already claimed by %s\n", | ||
78 | name, io_base, hwif->name); | ||
79 | return NULL; /* already claimed */ | ||
80 | } | ||
81 | } | ||
82 | /* | ||
83 | * Okay, there is no hwif matching our io_base, | ||
84 | * so we'll just claim an unassigned slot. | ||
85 | * Give preference to claiming other slots before claiming ide0/ide1, | ||
86 | * just in case there's another interface yet-to-be-scanned | ||
87 | * which uses ports 1f0/170 (the ide0/ide1 defaults). | ||
88 | * | ||
89 | * Unless there is a bootable card that does not use the standard | ||
90 | * ports 1f0/170 (the ide0/ide1 defaults). The (bootable) flag. | ||
91 | */ | ||
92 | if (bootable) { | ||
93 | for (h = 0; h < MAX_HWIFS; ++h) { | ||
94 | hwif = &ide_hwifs[h]; | ||
95 | if (hwif->chipset == ide_unknown) | ||
96 | return hwif; /* pick an unused entry */ | ||
97 | } | ||
98 | } else { | ||
99 | for (h = 2; h < MAX_HWIFS; ++h) { | ||
100 | hwif = ide_hwifs + h; | ||
101 | if (hwif->chipset == ide_unknown) | ||
102 | return hwif; /* pick an unused entry */ | ||
103 | } | ||
104 | } | ||
105 | for (h = 0; h < 2; ++h) { | ||
106 | hwif = ide_hwifs + h; | ||
107 | if (hwif->chipset == ide_unknown) | ||
108 | return hwif; /* pick an unused entry */ | ||
109 | } | ||
110 | printk(KERN_ERR "%s: too many IDE interfaces, no room in table\n", name); | ||
111 | return NULL; | ||
112 | } | ||
113 | |||
114 | /** | ||
115 | * ide_setup_pci_baseregs - place a PCI IDE controller native | ||
116 | * @dev: PCI device of interface to switch native | ||
117 | * @name: Name of interface | ||
118 | * | ||
119 | * We attempt to place the PCI interface into PCI native mode. If | ||
120 | * we succeed the BARs are ok and the controller is in PCI mode. | ||
121 | * Returns 0 on success or an errno code. | ||
122 | * | ||
123 | * FIXME: if we program the interface and then fail to set the BARS | ||
124 | * we don't switch it back to legacy mode. Do we actually care ?? | ||
125 | */ | ||
126 | |||
127 | static int ide_setup_pci_baseregs (struct pci_dev *dev, const char *name) | ||
128 | { | ||
129 | u8 progif = 0; | ||
130 | |||
131 | /* | ||
132 | * Place both IDE interfaces into PCI "native" mode: | ||
133 | */ | ||
134 | if (pci_read_config_byte(dev, PCI_CLASS_PROG, &progif) || | ||
135 | (progif & 5) != 5) { | ||
136 | if ((progif & 0xa) != 0xa) { | ||
137 | printk(KERN_INFO "%s: device not capable of full " | ||
138 | "native PCI mode\n", name); | ||
139 | return -EOPNOTSUPP; | ||
140 | } | ||
141 | printk("%s: placing both ports into native PCI mode\n", name); | ||
142 | (void) pci_write_config_byte(dev, PCI_CLASS_PROG, progif|5); | ||
143 | if (pci_read_config_byte(dev, PCI_CLASS_PROG, &progif) || | ||
144 | (progif & 5) != 5) { | ||
145 | printk(KERN_ERR "%s: rewrite of PROGIF failed, wanted " | ||
146 | "0x%04x, got 0x%04x\n", | ||
147 | name, progif|5, progif); | ||
148 | return -EOPNOTSUPP; | ||
149 | } | ||
150 | } | ||
151 | return 0; | ||
152 | } | ||
153 | |||
154 | #ifdef CONFIG_BLK_DEV_IDEDMA_PCI | ||
155 | |||
156 | #ifdef CONFIG_BLK_DEV_IDEDMA_FORCED | ||
157 | /* | ||
158 | * Long lost data from 2.0.34 that is now in 2.0.39 | ||
159 | * | ||
160 | * This was used in ./drivers/block/triton.c to do DMA Base address setup | ||
161 | * when PnP failed. Oh the things we forget. I believe this was part | ||
162 | * of SFF-8038i that has been withdrawn from public access... :-(( | ||
163 | */ | ||
164 | #define DEFAULT_BMIBA 0xe800 /* in case BIOS did not init it */ | ||
165 | #define DEFAULT_BMCRBA 0xcc00 /* VIA's default value */ | ||
166 | #define DEFAULT_BMALIBA 0xd400 /* ALI's default value */ | ||
167 | #endif /* CONFIG_BLK_DEV_IDEDMA_FORCED */ | ||
168 | |||
169 | /** | ||
170 | * ide_get_or_set_dma_base - setup BMIBA | ||
171 | * @hwif: Interface | ||
172 | * | ||
173 | * Fetch the DMA Bus-Master-I/O-Base-Address (BMIBA) from PCI space: | ||
174 | * If need be we set up the DMA base. Where a device has a partner that | ||
175 | * is already in DMA mode we check and enforce IDE simplex rules. | ||
176 | */ | ||
177 | |||
178 | static unsigned long ide_get_or_set_dma_base (ide_hwif_t *hwif) | ||
179 | { | ||
180 | unsigned long dma_base = 0; | ||
181 | struct pci_dev *dev = hwif->pci_dev; | ||
182 | |||
183 | #ifdef CONFIG_BLK_DEV_IDEDMA_FORCED | ||
184 | int second_chance = 0; | ||
185 | |||
186 | second_chance_to_dma: | ||
187 | #endif /* CONFIG_BLK_DEV_IDEDMA_FORCED */ | ||
188 | |||
189 | if (hwif->mmio) | ||
190 | return hwif->dma_base; | ||
191 | |||
192 | if (hwif->mate && hwif->mate->dma_base) { | ||
193 | dma_base = hwif->mate->dma_base - (hwif->channel ? 0 : 8); | ||
194 | } else { | ||
195 | dma_base = pci_resource_start(dev, 4); | ||
196 | if (!dma_base) { | ||
197 | printk(KERN_ERR "%s: dma_base is invalid\n", | ||
198 | hwif->cds->name); | ||
199 | } | ||
200 | } | ||
201 | |||
202 | #ifdef CONFIG_BLK_DEV_IDEDMA_FORCED | ||
203 | /* FIXME - should use pci_assign_resource surely */ | ||
204 | if ((!dma_base) && (!second_chance)) { | ||
205 | unsigned long set_bmiba = 0; | ||
206 | second_chance++; | ||
207 | switch(dev->vendor) { | ||
208 | case PCI_VENDOR_ID_AL: | ||
209 | set_bmiba = DEFAULT_BMALIBA; break; | ||
210 | case PCI_VENDOR_ID_VIA: | ||
211 | set_bmiba = DEFAULT_BMCRBA; break; | ||
212 | case PCI_VENDOR_ID_INTEL: | ||
213 | set_bmiba = DEFAULT_BMIBA; break; | ||
214 | default: | ||
215 | return dma_base; | ||
216 | } | ||
217 | pci_write_config_dword(dev, 0x20, set_bmiba|1); | ||
218 | goto second_chance_to_dma; | ||
219 | } | ||
220 | #endif /* CONFIG_BLK_DEV_IDEDMA_FORCED */ | ||
221 | |||
222 | if (dma_base) { | ||
223 | u8 simplex_stat = 0; | ||
224 | dma_base += hwif->channel ? 8 : 0; | ||
225 | |||
226 | switch(dev->device) { | ||
227 | case PCI_DEVICE_ID_AL_M5219: | ||
228 | case PCI_DEVICE_ID_AL_M5229: | ||
229 | case PCI_DEVICE_ID_AMD_VIPER_7409: | ||
230 | case PCI_DEVICE_ID_CMD_643: | ||
231 | case PCI_DEVICE_ID_SERVERWORKS_CSB5IDE: | ||
232 | simplex_stat = hwif->INB(dma_base + 2); | ||
233 | hwif->OUTB((simplex_stat&0x60),(dma_base + 2)); | ||
234 | simplex_stat = hwif->INB(dma_base + 2); | ||
235 | if (simplex_stat & 0x80) { | ||
236 | printk(KERN_INFO "%s: simplex device: " | ||
237 | "DMA forced\n", | ||
238 | hwif->cds->name); | ||
239 | } | ||
240 | break; | ||
241 | default: | ||
242 | /* | ||
243 | * If the device claims "simplex" DMA, | ||
244 | * this means only one of the two interfaces | ||
245 | * can be trusted with DMA at any point in time. | ||
246 | * So we should enable DMA only on one of the | ||
247 | * two interfaces. | ||
248 | */ | ||
249 | simplex_stat = hwif->INB(dma_base + 2); | ||
250 | if (simplex_stat & 0x80) { | ||
251 | /* simplex device? */ | ||
252 | /* | ||
253 | * At this point we haven't probed the drives so we can't make the | ||
254 | * appropriate decision. Really we should defer this problem | ||
255 | * until we tune the drive then try to grab DMA ownership if we want | ||
256 | * to be the DMA end. This has to be become dynamic to handle hot | ||
257 | * plug. | ||
258 | */ | ||
259 | if (hwif->mate && hwif->mate->dma_base) { | ||
260 | printk(KERN_INFO "%s: simplex device: " | ||
261 | "DMA disabled\n", | ||
262 | hwif->cds->name); | ||
263 | dma_base = 0; | ||
264 | } | ||
265 | } | ||
266 | } | ||
267 | } | ||
268 | return dma_base; | ||
269 | } | ||
270 | #endif /* CONFIG_BLK_DEV_IDEDMA_PCI */ | ||
271 | |||
272 | void ide_setup_pci_noise (struct pci_dev *dev, ide_pci_device_t *d) | ||
273 | { | ||
274 | printk(KERN_INFO "%s: IDE controller at PCI slot %s\n", | ||
275 | d->name, pci_name(dev)); | ||
276 | } | ||
277 | |||
278 | EXPORT_SYMBOL_GPL(ide_setup_pci_noise); | ||
279 | |||
280 | |||
281 | /** | ||
282 | * ide_pci_enable - do PCI enables | ||
283 | * @dev: PCI device | ||
284 | * @d: IDE pci device data | ||
285 | * | ||
286 | * Enable the IDE PCI device. We attempt to enable the device in full | ||
287 | * but if that fails then we only need BAR4 so we will enable that. | ||
288 | * | ||
289 | * Returns zero on success or an error code | ||
290 | */ | ||
291 | |||
292 | static int ide_pci_enable(struct pci_dev *dev, ide_pci_device_t *d) | ||
293 | { | ||
294 | int ret; | ||
295 | |||
296 | if (pci_enable_device(dev)) { | ||
297 | ret = pci_enable_device_bars(dev, 1 << 4); | ||
298 | if (ret < 0) { | ||
299 | printk(KERN_WARNING "%s: (ide_setup_pci_device:) " | ||
300 | "Could not enable device.\n", d->name); | ||
301 | goto out; | ||
302 | } | ||
303 | printk(KERN_WARNING "%s: BIOS configuration fixed.\n", d->name); | ||
304 | } | ||
305 | |||
306 | /* | ||
307 | * assume all devices can do 32-bit dma for now. we can add a | ||
308 | * dma mask field to the ide_pci_device_t if we need it (or let | ||
309 | * lower level driver set the dma mask) | ||
310 | */ | ||
311 | ret = pci_set_dma_mask(dev, DMA_32BIT_MASK); | ||
312 | if (ret < 0) { | ||
313 | printk(KERN_ERR "%s: can't set dma mask\n", d->name); | ||
314 | goto out; | ||
315 | } | ||
316 | |||
317 | /* FIXME: Temporary - until we put in the hotplug interface logic | ||
318 | Check that the bits we want are not in use by someone else. */ | ||
319 | ret = pci_request_region(dev, 4, "ide_tmp"); | ||
320 | if (ret < 0) | ||
321 | goto out; | ||
322 | |||
323 | pci_release_region(dev, 4); | ||
324 | out: | ||
325 | return ret; | ||
326 | } | ||
327 | |||
328 | /** | ||
329 | * ide_pci_configure - configure an unconfigured device | ||
330 | * @dev: PCI device | ||
331 | * @d: IDE pci device data | ||
332 | * | ||
333 | * Enable and configure the PCI device we have been passed. | ||
334 | * Returns zero on success or an error code. | ||
335 | */ | ||
336 | |||
337 | static int ide_pci_configure(struct pci_dev *dev, ide_pci_device_t *d) | ||
338 | { | ||
339 | u16 pcicmd = 0; | ||
340 | /* | ||
341 | * PnP BIOS was *supposed* to have setup this device, but we | ||
342 | * can do it ourselves, so long as the BIOS has assigned an IRQ | ||
343 | * (or possibly the device is using a "legacy header" for IRQs). | ||
344 | * Maybe the user deliberately *disabled* the device, | ||
345 | * but we'll eventually ignore it again if no drives respond. | ||
346 | */ | ||
347 | if (ide_setup_pci_baseregs(dev, d->name) || pci_write_config_word(dev, PCI_COMMAND, pcicmd|PCI_COMMAND_IO)) | ||
348 | { | ||
349 | printk(KERN_INFO "%s: device disabled (BIOS)\n", d->name); | ||
350 | return -ENODEV; | ||
351 | } | ||
352 | if (pci_read_config_word(dev, PCI_COMMAND, &pcicmd)) { | ||
353 | printk(KERN_ERR "%s: error accessing PCI regs\n", d->name); | ||
354 | return -EIO; | ||
355 | } | ||
356 | if (!(pcicmd & PCI_COMMAND_IO)) { | ||
357 | printk(KERN_ERR "%s: unable to enable IDE controller\n", d->name); | ||
358 | return -ENXIO; | ||
359 | } | ||
360 | return 0; | ||
361 | } | ||
362 | |||
363 | /** | ||
364 | * ide_pci_check_iomem - check a register is I/O | ||
365 | * @dev: pci device | ||
366 | * @d: ide_pci_device | ||
367 | * @bar: bar number | ||
368 | * | ||
369 | * Checks if a BAR is configured and points to MMIO space. If so | ||
370 | * print an error and return an error code. Otherwise return 0 | ||
371 | */ | ||
372 | |||
373 | static int ide_pci_check_iomem(struct pci_dev *dev, ide_pci_device_t *d, int bar) | ||
374 | { | ||
375 | ulong flags = pci_resource_flags(dev, bar); | ||
376 | |||
377 | /* Unconfigured ? */ | ||
378 | if (!flags || pci_resource_len(dev, bar) == 0) | ||
379 | return 0; | ||
380 | |||
381 | /* I/O space */ | ||
382 | if(flags & PCI_BASE_ADDRESS_IO_MASK) | ||
383 | return 0; | ||
384 | |||
385 | /* Bad */ | ||
386 | printk(KERN_ERR "%s: IO baseregs (BIOS) are reported " | ||
387 | "as MEM, report to " | ||
388 | "<andre@linux-ide.org>.\n", d->name); | ||
389 | return -EINVAL; | ||
390 | } | ||
391 | |||
392 | /** | ||
393 | * ide_hwif_configure - configure an IDE interface | ||
394 | * @dev: PCI device holding interface | ||
395 | * @d: IDE pci data | ||
396 | * @mate: Paired interface if any | ||
397 | * | ||
398 | * Perform the initial set up for the hardware interface structure. This | ||
399 | * is done per interface port rather than per PCI device. There may be | ||
400 | * more than one port per device. | ||
401 | * | ||
402 | * Returns the new hardware interface structure, or NULL on a failure | ||
403 | */ | ||
404 | |||
405 | static ide_hwif_t *ide_hwif_configure(struct pci_dev *dev, ide_pci_device_t *d, ide_hwif_t *mate, int port, int irq) | ||
406 | { | ||
407 | unsigned long ctl = 0, base = 0; | ||
408 | ide_hwif_t *hwif; | ||
409 | |||
410 | if ((d->flags & IDEPCI_FLAG_ISA_PORTS) == 0) { | ||
411 | /* Possibly we should fail if these checks report true */ | ||
412 | ide_pci_check_iomem(dev, d, 2*port); | ||
413 | ide_pci_check_iomem(dev, d, 2*port+1); | ||
414 | |||
415 | ctl = pci_resource_start(dev, 2*port+1); | ||
416 | base = pci_resource_start(dev, 2*port); | ||
417 | if ((ctl && !base) || (base && !ctl)) { | ||
418 | printk(KERN_ERR "%s: inconsistent baseregs (BIOS) " | ||
419 | "for port %d, skipping\n", d->name, port); | ||
420 | return NULL; | ||
421 | } | ||
422 | } | ||
423 | if (!ctl) | ||
424 | { | ||
425 | /* Use default values */ | ||
426 | ctl = port ? 0x374 : 0x3f4; | ||
427 | base = port ? 0x170 : 0x1f0; | ||
428 | } | ||
429 | if ((hwif = ide_match_hwif(base, d->bootable, d->name)) == NULL) | ||
430 | return NULL; /* no room in ide_hwifs[] */ | ||
431 | if (hwif->io_ports[IDE_DATA_OFFSET] != base || | ||
432 | hwif->io_ports[IDE_CONTROL_OFFSET] != (ctl | 2)) { | ||
433 | memset(&hwif->hw, 0, sizeof(hwif->hw)); | ||
434 | #ifndef IDE_ARCH_OBSOLETE_INIT | ||
435 | ide_std_init_ports(&hwif->hw, base, (ctl | 2)); | ||
436 | hwif->hw.io_ports[IDE_IRQ_OFFSET] = 0; | ||
437 | #else | ||
438 | ide_init_hwif_ports(&hwif->hw, base, (ctl | 2), NULL); | ||
439 | #endif | ||
440 | memcpy(hwif->io_ports, hwif->hw.io_ports, sizeof(hwif->io_ports)); | ||
441 | hwif->noprobe = !hwif->io_ports[IDE_DATA_OFFSET]; | ||
442 | } | ||
443 | hwif->chipset = ide_pci; | ||
444 | hwif->pci_dev = dev; | ||
445 | hwif->cds = (struct ide_pci_device_s *) d; | ||
446 | hwif->channel = port; | ||
447 | |||
448 | if (!hwif->irq) | ||
449 | hwif->irq = irq; | ||
450 | if (mate) { | ||
451 | hwif->mate = mate; | ||
452 | mate->mate = hwif; | ||
453 | } | ||
454 | return hwif; | ||
455 | } | ||
456 | |||
457 | /** | ||
458 | * ide_hwif_setup_dma - configure DMA interface | ||
459 | * @dev: PCI device | ||
460 | * @d: IDE pci data | ||
461 | * @hwif: Hardware interface we are configuring | ||
462 | * | ||
463 | * Set up the DMA base for the interface. Enable the master bits as | ||
464 | * necessary and attempt to bring the device DMA into a ready to use | ||
465 | * state | ||
466 | */ | ||
467 | |||
468 | #ifndef CONFIG_BLK_DEV_IDEDMA_PCI | ||
469 | static void ide_hwif_setup_dma(struct pci_dev *dev, ide_pci_device_t *d, ide_hwif_t *hwif) | ||
470 | { | ||
471 | } | ||
472 | #else | ||
473 | static void ide_hwif_setup_dma(struct pci_dev *dev, ide_pci_device_t *d, ide_hwif_t *hwif) | ||
474 | { | ||
475 | u16 pcicmd; | ||
476 | pci_read_config_word(dev, PCI_COMMAND, &pcicmd); | ||
477 | |||
478 | if ((d->autodma == AUTODMA) || | ||
479 | ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE && | ||
480 | (dev->class & 0x80))) { | ||
481 | unsigned long dma_base = ide_get_or_set_dma_base(hwif); | ||
482 | if (dma_base && !(pcicmd & PCI_COMMAND_MASTER)) { | ||
483 | /* | ||
484 | * Set up BM-DMA capability | ||
485 | * (PnP BIOS should have done this) | ||
486 | */ | ||
487 | /* default DMA off if we had to configure it here */ | ||
488 | hwif->autodma = 0; | ||
489 | pci_set_master(dev); | ||
490 | if (pci_read_config_word(dev, PCI_COMMAND, &pcicmd) || !(pcicmd & PCI_COMMAND_MASTER)) { | ||
491 | printk(KERN_ERR "%s: %s error updating PCICMD\n", | ||
492 | hwif->name, d->name); | ||
493 | dma_base = 0; | ||
494 | } | ||
495 | } | ||
496 | if (dma_base) { | ||
497 | if (d->init_dma) { | ||
498 | d->init_dma(hwif, dma_base); | ||
499 | } else { | ||
500 | ide_setup_dma(hwif, dma_base, 8); | ||
501 | } | ||
502 | } else { | ||
503 | printk(KERN_INFO "%s: %s Bus-Master DMA disabled " | ||
504 | "(BIOS)\n", hwif->name, d->name); | ||
505 | } | ||
506 | } | ||
507 | } | ||
508 | |||
509 | #ifndef CONFIG_IDEDMA_PCI_AUTO | ||
510 | #warning CONFIG_IDEDMA_PCI_AUTO=n support is obsolete, and will be removed soon. | ||
511 | #endif | ||
512 | |||
513 | #endif /* CONFIG_BLK_DEV_IDEDMA_PCI*/ | ||
514 | |||
515 | /** | ||
516 | * ide_setup_pci_controller - set up IDE PCI | ||
517 | * @dev: PCI device | ||
518 | * @d: IDE PCI data | ||
519 | * @noisy: verbose flag | ||
520 | * @config: returned as 1 if we configured the hardware | ||
521 | * | ||
522 | * Set up the PCI and controller side of the IDE interface. This brings | ||
523 | * up the PCI side of the device, checks that the device is enabled | ||
524 | * and enables it if need be | ||
525 | */ | ||
526 | |||
527 | static int ide_setup_pci_controller(struct pci_dev *dev, ide_pci_device_t *d, int noisy, int *config) | ||
528 | { | ||
529 | int ret; | ||
530 | u32 class_rev; | ||
531 | u16 pcicmd; | ||
532 | |||
533 | if (noisy) | ||
534 | ide_setup_pci_noise(dev, d); | ||
535 | |||
536 | ret = ide_pci_enable(dev, d); | ||
537 | if (ret < 0) | ||
538 | goto out; | ||
539 | |||
540 | ret = pci_read_config_word(dev, PCI_COMMAND, &pcicmd); | ||
541 | if (ret < 0) { | ||
542 | printk(KERN_ERR "%s: error accessing PCI regs\n", d->name); | ||
543 | goto out; | ||
544 | } | ||
545 | if (!(pcicmd & PCI_COMMAND_IO)) { /* is device disabled? */ | ||
546 | ret = ide_pci_configure(dev, d); | ||
547 | if (ret < 0) | ||
548 | goto out; | ||
549 | *config = 1; | ||
550 | printk(KERN_INFO "%s: device enabled (Linux)\n", d->name); | ||
551 | } | ||
552 | |||
553 | pci_read_config_dword(dev, PCI_CLASS_REVISION, &class_rev); | ||
554 | class_rev &= 0xff; | ||
555 | if (noisy) | ||
556 | printk(KERN_INFO "%s: chipset revision %d\n", d->name, class_rev); | ||
557 | out: | ||
558 | return ret; | ||
559 | } | ||
560 | |||
561 | /** | ||
562 | * ide_pci_setup_ports - configure ports/devices on PCI IDE | ||
563 | * @dev: PCI device | ||
564 | * @d: IDE pci device info | ||
565 | * @pciirq: IRQ line | ||
566 | * @index: ata index to update | ||
567 | * | ||
568 | * Scan the interfaces attached to this device and do any | ||
569 | * necessary per port setup. Attach the devices and ask the | ||
570 | * generic DMA layer to do its work for us. | ||
571 | * | ||
572 | * Normally called automaticall from do_ide_pci_setup_device, | ||
573 | * but is also used directly as a helper function by some controllers | ||
574 | * where the chipset setup is not the default PCI IDE one. | ||
575 | */ | ||
576 | |||
577 | void ide_pci_setup_ports(struct pci_dev *dev, ide_pci_device_t *d, int pciirq, ata_index_t *index) | ||
578 | { | ||
579 | int port; | ||
580 | int at_least_one_hwif_enabled = 0; | ||
581 | ide_hwif_t *hwif, *mate = NULL; | ||
582 | static int secondpdc = 0; | ||
583 | u8 tmp; | ||
584 | |||
585 | index->all = 0xf0f0; | ||
586 | |||
587 | /* | ||
588 | * Set up the IDE ports | ||
589 | */ | ||
590 | |||
591 | for (port = 0; port <= 1; ++port) { | ||
592 | ide_pci_enablebit_t *e = &(d->enablebits[port]); | ||
593 | |||
594 | /* | ||
595 | * If this is a Promise FakeRaid controller, | ||
596 | * the 2nd controller will be marked as | ||
597 | * disabled while it is actually there and enabled | ||
598 | * by the bios for raid purposes. | ||
599 | * Skip the normal "is it enabled" test for those. | ||
600 | */ | ||
601 | if ((d->flags & IDEPCI_FLAG_FORCE_PDC) && | ||
602 | (secondpdc++==1) && (port==1)) | ||
603 | goto controller_ok; | ||
604 | |||
605 | if (e->reg && (pci_read_config_byte(dev, e->reg, &tmp) || | ||
606 | (tmp & e->mask) != e->val)) | ||
607 | continue; /* port not enabled */ | ||
608 | controller_ok: | ||
609 | |||
610 | if (d->channels <= port) | ||
611 | break; | ||
612 | |||
613 | if ((hwif = ide_hwif_configure(dev, d, mate, port, pciirq)) == NULL) | ||
614 | continue; | ||
615 | |||
616 | /* setup proper ancestral information */ | ||
617 | hwif->gendev.parent = &dev->dev; | ||
618 | |||
619 | if (hwif->channel) { | ||
620 | index->b.high = hwif->index; | ||
621 | } else { | ||
622 | index->b.low = hwif->index; | ||
623 | } | ||
624 | |||
625 | |||
626 | if (d->init_iops) | ||
627 | d->init_iops(hwif); | ||
628 | |||
629 | if (d->autodma == NODMA) | ||
630 | goto bypass_legacy_dma; | ||
631 | |||
632 | if(d->init_setup_dma) | ||
633 | d->init_setup_dma(dev, d, hwif); | ||
634 | else | ||
635 | ide_hwif_setup_dma(dev, d, hwif); | ||
636 | bypass_legacy_dma: | ||
637 | if (d->init_hwif) | ||
638 | /* Call chipset-specific routine | ||
639 | * for each enabled hwif | ||
640 | */ | ||
641 | d->init_hwif(hwif); | ||
642 | |||
643 | mate = hwif; | ||
644 | at_least_one_hwif_enabled = 1; | ||
645 | } | ||
646 | if (!at_least_one_hwif_enabled) | ||
647 | printk(KERN_INFO "%s: neither IDE port enabled (BIOS)\n", d->name); | ||
648 | } | ||
649 | |||
650 | EXPORT_SYMBOL_GPL(ide_pci_setup_ports); | ||
651 | |||
652 | /* | ||
653 | * ide_setup_pci_device() looks at the primary/secondary interfaces | ||
654 | * on a PCI IDE device and, if they are enabled, prepares the IDE driver | ||
655 | * for use with them. This generic code works for most PCI chipsets. | ||
656 | * | ||
657 | * One thing that is not standardized is the location of the | ||
658 | * primary/secondary interface "enable/disable" bits. For chipsets that | ||
659 | * we "know" about, this information is in the ide_pci_device_t struct; | ||
660 | * for all other chipsets, we just assume both interfaces are enabled. | ||
661 | */ | ||
662 | static int do_ide_setup_pci_device(struct pci_dev *dev, ide_pci_device_t *d, | ||
663 | ata_index_t *index, u8 noisy) | ||
664 | { | ||
665 | static ata_index_t ata_index = { .b = { .low = 0xff, .high = 0xff } }; | ||
666 | int tried_config = 0; | ||
667 | int pciirq, ret; | ||
668 | |||
669 | ret = ide_setup_pci_controller(dev, d, noisy, &tried_config); | ||
670 | if (ret < 0) | ||
671 | goto out; | ||
672 | |||
673 | /* | ||
674 | * Can we trust the reported IRQ? | ||
675 | */ | ||
676 | pciirq = dev->irq; | ||
677 | |||
678 | /* Is it an "IDE storage" device in non-PCI mode? */ | ||
679 | if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE && (dev->class & 5) != 5) { | ||
680 | if (noisy) | ||
681 | printk(KERN_INFO "%s: not 100%% native mode: " | ||
682 | "will probe irqs later\n", d->name); | ||
683 | /* | ||
684 | * This allows offboard ide-pci cards the enable a BIOS, | ||
685 | * verify interrupt settings of split-mirror pci-config | ||
686 | * space, place chipset into init-mode, and/or preserve | ||
687 | * an interrupt if the card is not native ide support. | ||
688 | */ | ||
689 | ret = d->init_chipset ? d->init_chipset(dev, d->name) : 0; | ||
690 | if (ret < 0) | ||
691 | goto out; | ||
692 | pciirq = ret; | ||
693 | } else if (tried_config) { | ||
694 | if (noisy) | ||
695 | printk(KERN_INFO "%s: will probe irqs later\n", d->name); | ||
696 | pciirq = 0; | ||
697 | } else if (!pciirq) { | ||
698 | if (noisy) | ||
699 | printk(KERN_WARNING "%s: bad irq (%d): will probe later\n", | ||
700 | d->name, pciirq); | ||
701 | pciirq = 0; | ||
702 | } else { | ||
703 | if (d->init_chipset) { | ||
704 | ret = d->init_chipset(dev, d->name); | ||
705 | if (ret < 0) | ||
706 | goto out; | ||
707 | } | ||
708 | if (noisy) | ||
709 | #ifdef __sparc__ | ||
710 | printk(KERN_INFO "%s: 100%% native mode on irq %s\n", | ||
711 | d->name, __irq_itoa(pciirq)); | ||
712 | #else | ||
713 | printk(KERN_INFO "%s: 100%% native mode on irq %d\n", | ||
714 | d->name, pciirq); | ||
715 | #endif | ||
716 | } | ||
717 | |||
718 | /* FIXME: silent failure can happen */ | ||
719 | |||
720 | *index = ata_index; | ||
721 | ide_pci_setup_ports(dev, d, pciirq, index); | ||
722 | out: | ||
723 | return ret; | ||
724 | } | ||
725 | |||
726 | int ide_setup_pci_device(struct pci_dev *dev, ide_pci_device_t *d) | ||
727 | { | ||
728 | ata_index_t index_list; | ||
729 | int ret; | ||
730 | |||
731 | ret = do_ide_setup_pci_device(dev, d, &index_list, 1); | ||
732 | if (ret < 0) | ||
733 | goto out; | ||
734 | |||
735 | if ((index_list.b.low & 0xf0) != 0xf0) | ||
736 | probe_hwif_init_with_fixup(&ide_hwifs[index_list.b.low], d->fixup); | ||
737 | if ((index_list.b.high & 0xf0) != 0xf0) | ||
738 | probe_hwif_init_with_fixup(&ide_hwifs[index_list.b.high], d->fixup); | ||
739 | |||
740 | create_proc_ide_interfaces(); | ||
741 | out: | ||
742 | return ret; | ||
743 | } | ||
744 | |||
745 | EXPORT_SYMBOL_GPL(ide_setup_pci_device); | ||
746 | |||
747 | int ide_setup_pci_devices(struct pci_dev *dev1, struct pci_dev *dev2, | ||
748 | ide_pci_device_t *d) | ||
749 | { | ||
750 | struct pci_dev *pdev[] = { dev1, dev2 }; | ||
751 | ata_index_t index_list[2]; | ||
752 | int ret, i; | ||
753 | |||
754 | for (i = 0; i < 2; i++) { | ||
755 | ret = do_ide_setup_pci_device(pdev[i], d, index_list + i, !i); | ||
756 | /* | ||
757 | * FIXME: Mom, mom, they stole me the helper function to undo | ||
758 | * do_ide_setup_pci_device() on the first device! | ||
759 | */ | ||
760 | if (ret < 0) | ||
761 | goto out; | ||
762 | } | ||
763 | |||
764 | for (i = 0; i < 2; i++) { | ||
765 | u8 idx[2] = { index_list[i].b.low, index_list[i].b.high }; | ||
766 | int j; | ||
767 | |||
768 | for (j = 0; j < 2; j++) { | ||
769 | if ((idx[j] & 0xf0) != 0xf0) | ||
770 | probe_hwif_init(ide_hwifs + idx[j]); | ||
771 | } | ||
772 | } | ||
773 | |||
774 | create_proc_ide_interfaces(); | ||
775 | out: | ||
776 | return ret; | ||
777 | } | ||
778 | |||
779 | EXPORT_SYMBOL_GPL(ide_setup_pci_devices); | ||
780 | |||
781 | /* | ||
782 | * Module interfaces | ||
783 | */ | ||
784 | |||
785 | static int pre_init = 1; /* Before first ordered IDE scan */ | ||
786 | static LIST_HEAD(ide_pci_drivers); | ||
787 | |||
788 | /* | ||
789 | * ide_register_pci_driver - attach IDE driver | ||
790 | * @driver: pci driver | ||
791 | * | ||
792 | * Registers a driver with the IDE layer. The IDE layer arranges that | ||
793 | * boot time setup is done in the expected device order and then | ||
794 | * hands the controllers off to the core PCI code to do the rest of | ||
795 | * the work. | ||
796 | * | ||
797 | * The driver_data of the driver table must point to an ide_pci_device_t | ||
798 | * describing the interface. | ||
799 | * | ||
800 | * Returns are the same as for pci_register_driver | ||
801 | */ | ||
802 | |||
803 | int ide_pci_register_driver(struct pci_driver *driver) | ||
804 | { | ||
805 | if(!pre_init) | ||
806 | return pci_module_init(driver); | ||
807 | list_add_tail(&driver->node, &ide_pci_drivers); | ||
808 | return 0; | ||
809 | } | ||
810 | |||
811 | EXPORT_SYMBOL_GPL(ide_pci_register_driver); | ||
812 | |||
813 | /** | ||
814 | * ide_unregister_pci_driver - unregister an IDE driver | ||
815 | * @driver: driver to remove | ||
816 | * | ||
817 | * Unregister a currently installed IDE driver. Returns are the same | ||
818 | * as for pci_unregister_driver | ||
819 | */ | ||
820 | |||
821 | void ide_pci_unregister_driver(struct pci_driver *driver) | ||
822 | { | ||
823 | if(!pre_init) | ||
824 | pci_unregister_driver(driver); | ||
825 | else | ||
826 | list_del(&driver->node); | ||
827 | } | ||
828 | |||
829 | EXPORT_SYMBOL_GPL(ide_pci_unregister_driver); | ||
830 | |||
831 | /** | ||
832 | * ide_scan_pcidev - find an IDE driver for a device | ||
833 | * @dev: PCI device to check | ||
834 | * | ||
835 | * Look for an IDE driver to handle the device we are considering. | ||
836 | * This is only used during boot up to get the ordering correct. After | ||
837 | * boot up the pci layer takes over the job. | ||
838 | */ | ||
839 | |||
840 | static int __init ide_scan_pcidev(struct pci_dev *dev) | ||
841 | { | ||
842 | struct list_head *l; | ||
843 | struct pci_driver *d; | ||
844 | |||
845 | list_for_each(l, &ide_pci_drivers) | ||
846 | { | ||
847 | d = list_entry(l, struct pci_driver, node); | ||
848 | if(d->id_table) | ||
849 | { | ||
850 | const struct pci_device_id *id = pci_match_device(d->id_table, dev); | ||
851 | if(id != NULL) | ||
852 | { | ||
853 | if(d->probe(dev, id) >= 0) | ||
854 | { | ||
855 | dev->driver = d; | ||
856 | return 1; | ||
857 | } | ||
858 | } | ||
859 | } | ||
860 | } | ||
861 | return 0; | ||
862 | } | ||
863 | |||
864 | /** | ||
865 | * ide_scan_pcibus - perform the initial IDE driver scan | ||
866 | * @scan_direction: set for reverse order scanning | ||
867 | * | ||
868 | * Perform the initial bus rather than driver ordered scan of the | ||
869 | * PCI drivers. After this all IDE pci handling becomes standard | ||
870 | * module ordering not traditionally ordered. | ||
871 | */ | ||
872 | |||
873 | void __init ide_scan_pcibus (int scan_direction) | ||
874 | { | ||
875 | struct pci_dev *dev = NULL; | ||
876 | struct pci_driver *d; | ||
877 | struct list_head *l, *n; | ||
878 | |||
879 | pre_init = 0; | ||
880 | if (!scan_direction) { | ||
881 | while ((dev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) { | ||
882 | ide_scan_pcidev(dev); | ||
883 | } | ||
884 | } else { | ||
885 | while ((dev = pci_find_device_reverse(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) { | ||
886 | ide_scan_pcidev(dev); | ||
887 | } | ||
888 | } | ||
889 | |||
890 | /* | ||
891 | * Hand the drivers over to the PCI layer now we | ||
892 | * are post init. | ||
893 | */ | ||
894 | |||
895 | list_for_each_safe(l, n, &ide_pci_drivers) | ||
896 | { | ||
897 | list_del(l); | ||
898 | d = list_entry(l, struct pci_driver, node); | ||
899 | pci_register_driver(d); | ||
900 | } | ||
901 | } | ||